ReactOS  0.4.13-dev-235-g7373cb3
routines.c File Reference
#include "precomp.h"
Include dependency graph for routines.c:

Go to the source code of this file.

Functions

NDIS_STATUS InitNdisPools ()
 
VOID CloseNdisPools ()
 
__inline INT SkipToOffset (PNDIS_BUFFER Buffer, UINT Offset, PCHAR *Data, PUINT Size)
 
void GetDataPtr (PNDIS_PACKET Packet, UINT Offset, PCHAR *DataOut, PUINT Size)
 
NDIS_STATUS AllocatePacketWithBufferX (PNDIS_PACKET *NdisPacket, PCHAR Data, UINT Len, PCHAR File, UINT Line)
 
VOID FreeNdisPacketX (PNDIS_PACKET Packet, PCHAR File, UINT Line)
 

Variables

NDIS_HANDLE GlobalPacketPool = NULL
 
NDIS_HANDLE GlobalBufferPool = NULL
 

Function Documentation

◆ AllocatePacketWithBufferX()

NDIS_STATUS AllocatePacketWithBufferX ( PNDIS_PACKET NdisPacket,
PCHAR  Data,
UINT  Len,
PCHAR  File,
UINT  Line 
)

Definition at line 82 of file routines.c.

84  {
88  PCHAR NewData;
89 
90  NewData = exAllocatePool( NonPagedPool, Len );
91  if( !NewData ) return NDIS_STATUS_NOT_ACCEPTED; // XXX
92 
93  if( Data )
94  RtlCopyMemory(NewData, Data, Len);
95 
97  if( Status != NDIS_STATUS_SUCCESS ) {
98  exFreePool( NewData );
99  return Status;
100  }
102 
104  if( Status != NDIS_STATUS_SUCCESS ) {
105  exFreePool( NewData );
107  }
109 
111  *NdisPacket = Packet;
112 
113  return NDIS_STATUS_SUCCESS;
114 }
signed char * PCHAR
Definition: retypes.h:7
VOID EXPORT NdisAllocatePacket(OUT PNDIS_STATUS Status, OUT PNDIS_PACKET *Packet, IN NDIS_HANDLE PoolHandle)
Definition: buffer.c:392
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
MDL * PNDIS_BUFFER
Definition: ndis.h:343
#define FreeNdisPacket(x)
Definition: memtrack.h:8
#define exFreePool(x)
Definition: memtrack.h:18
#define NdisChainBufferAtFront(Packet, Buffer)
Definition: ndis.h:3106
#define NDIS_BUFFER_TAG
Definition: lan.h:22
int NDIS_STATUS
Definition: ntddndis.h:445
Definition: bufpool.h:45
VOID EXPORT NdisAllocateBuffer(OUT PNDIS_STATUS Status, OUT PNDIS_BUFFER *Buffer, IN NDIS_HANDLE PoolHandle, IN PVOID VirtualAddress, IN UINT Length)
Definition: buffer.c:334
#define NDIS_STATUS_NOT_ACCEPTED
Definition: ndis.h:350
#define Len
Definition: deflate.h:82
Definition: ncftp.h:79
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
#define TrackWithTag(w, x, y, z)
Definition: memtrack.h:19
#define exAllocatePool(x, y)
Definition: memtrack.h:17
NDIS_HANDLE GlobalBufferPool
Definition: routines.c:4
Status
Definition: gdiplustypes.h:24
#define NDIS_PACKET_TAG
Definition: lan.h:23
NDIS_HANDLE GlobalPacketPool
Definition: routines.c:3
Definition: File.h:15
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34

◆ CloseNdisPools()

VOID CloseNdisPools ( )

Definition at line 19 of file routines.c.

19  {
22 }
NDIS_HANDLE GlobalBufferPool
Definition: routines.c:4
VOID EXPORT NdisFreeBufferPool(IN NDIS_HANDLE PoolHandle)
Definition: buffer.c:775
VOID EXPORT NdisFreePacketPool(IN NDIS_HANDLE PoolHandle)
Definition: buffer.c:791
NDIS_HANDLE GlobalPacketPool
Definition: routines.c:3

◆ FreeNdisPacketX()

VOID FreeNdisPacketX ( PNDIS_PACKET  Packet,
PCHAR  File,
UINT  Line 
)

Definition at line 118 of file routines.c.

126 {
127  PNDIS_BUFFER Buffer, NextBuffer;
128 
129  LA_DbgPrint(DEBUG_PBUFFER, ("Packet (0x%X)\n", Packet));
130 
131  /* Free all the buffers in the packet first */
133  for (; Buffer != NULL; Buffer = NextBuffer) {
134  PVOID Data;
135  UINT Length;
136 
137  NdisGetNextBuffer(Buffer, &NextBuffer);
141  exFreePool(Data);
142  }
143 
144  /* Finally free the NDIS packet descriptor */
147 }
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
MDL * PNDIS_BUFFER
Definition: ndis.h:343
VOID EXPORT NdisFreeBuffer(IN PNDIS_BUFFER Buffer)
Definition: buffer.c:809
#define exFreePool(x)
Definition: memtrack.h:18
#define NdisGetNextBuffer(CurrentBuffer, NextBuffer)
Definition: ndis.h:3386
#define UntrackFL(x, y, z)
Definition: memtrack.h:20
smooth NULL
Definition: ftsmooth.c:416
_In_ LPGUID _In_ PVOID Data
Definition: classpnp.h:778
Definition: bufpool.h:45
#define LA_DbgPrint(_t_, _x_)
Definition: debug.h:66
VOID EXPORT NdisFreePacket(IN PNDIS_PACKET Packet)
Definition: buffer.c:826
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define DEBUG_PBUFFER
Definition: debug.h:20
Definition: ncftp.h:79
unsigned int UINT
Definition: ndis.h:50
static __inline VOID NdisQueryPacket(IN PNDIS_PACKET Packet, OUT PUINT PhysicalBufferCount OPTIONAL, OUT PUINT BufferCount OPTIONAL, OUT PNDIS_BUFFER *FirstBuffer OPTIONAL, OUT PUINT TotalPacketLength OPTIONAL)
Definition: ndis.h:3593
VOID EXPORT NdisQueryBuffer(IN PNDIS_BUFFER Buffer, OUT PVOID *VirtualAddress OPTIONAL, OUT PUINT Length)
Definition: buffer.c:953
Definition: File.h:15
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34

◆ GetDataPtr()

void GetDataPtr ( PNDIS_PACKET  Packet,
UINT  Offset,
PCHAR DataOut,
PUINT  Size 
)

Definition at line 65 of file routines.c.

68  {
70 
72  if( !Buffer ) return;
73  SkipToOffset( Buffer, Offset, DataOut, Size );
74 }
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
MDL * PNDIS_BUFFER
Definition: ndis.h:343
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
__inline INT SkipToOffset(PNDIS_BUFFER Buffer, UINT Offset, PCHAR *Data, PUINT Size)
Definition: routines.c:24
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
static __inline VOID NdisQueryPacket(IN PNDIS_PACKET Packet, OUT PUINT PhysicalBufferCount OPTIONAL, OUT PUINT BufferCount OPTIONAL, OUT PNDIS_BUFFER *FirstBuffer OPTIONAL, OUT PUINT TotalPacketLength OPTIONAL)
Definition: ndis.h:3593
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34

◆ InitNdisPools()

NDIS_STATUS InitNdisPools ( )

Definition at line 6 of file routines.c.

6  {
7  NDIS_STATUS NdisStatus;
8  /* Last argument is extra space size */
9  NdisAllocatePacketPool( &NdisStatus, &GlobalPacketPool, 100, 0 );
10  if( !NT_SUCCESS(NdisStatus) ) return NdisStatus;
11 
12  NdisAllocateBufferPool( &NdisStatus, &GlobalBufferPool, 100 );
13  if( !NT_SUCCESS(NdisStatus) )
15 
16  return NdisStatus;
17 }
VOID EXPORT NdisAllocatePacketPool(OUT PNDIS_STATUS Status, OUT PNDIS_HANDLE PoolHandle, IN UINT NumberOfDescriptors, IN UINT ProtocolReservedLength)
Definition: buffer.c:419
int NDIS_STATUS
Definition: ntddndis.h:445
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NDIS_HANDLE GlobalBufferPool
Definition: routines.c:4
VOID EXPORT NdisFreePacketPool(IN NDIS_HANDLE PoolHandle)
Definition: buffer.c:791
NDIS_HANDLE GlobalPacketPool
Definition: routines.c:3
VOID EXPORT NdisAllocateBufferPool(OUT PNDIS_STATUS Status, OUT PNDIS_HANDLE PoolHandle, IN UINT NumberOfDescriptors)
Definition: buffer.c:370

◆ SkipToOffset()

__inline INT SkipToOffset ( PNDIS_BUFFER  Buffer,
UINT  Offset,
PCHAR Data,
PUINT  Size 
)

Definition at line 24 of file routines.c.

43 {
44  for (;;) {
45 
46  if (!Buffer)
47  return -1;
48 
50 
51  if (Offset < *Size) {
52  *Data = (PCHAR)((ULONG_PTR) *Data + Offset);
53  *Size -= Offset;
54  break;
55  }
56 
57  Offset -= *Size;
58 
60  }
61 
62  return Offset;
63 }
#define NdisGetNextBuffer(CurrentBuffer, NextBuffer)
Definition: ndis.h:3386
uint32_t ULONG_PTR
Definition: typedefs.h:63
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
Definition: bufpool.h:45
#define PCHAR
Definition: match.c:90
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
VOID EXPORT NdisQueryBuffer(IN PNDIS_BUFFER Buffer, OUT PVOID *VirtualAddress OPTIONAL, OUT PUINT Length)
Definition: buffer.c:953

Referenced by GetDataPtr().

Variable Documentation

◆ GlobalBufferPool

◆ GlobalPacketPool

NDIS_HANDLE GlobalPacketPool = NULL