ReactOS  0.4.14-dev-552-g2fad488
routines.c
Go to the documentation of this file.
1 #include "precomp.h"
2 
5 
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 }
18 
22 }
23 
24 __inline INT SkipToOffset(
26  UINT Offset,
27  PCHAR *Data,
28  PUINT Size)
29 /*
30  * FUNCTION: Skip Offset bytes into a buffer chain
31  * ARGUMENTS:
32  * Buffer = Pointer to NDIS buffer
33  * Offset = Number of bytes to skip
34  * Data = Address of a pointer that on return will contain the
35  * address of the offset in the buffer
36  * Size = Address of a pointer that on return will contain the
37  * size of the destination buffer
38  * RETURNS:
39  * Offset into buffer, -1 if buffer chain was smaller than Offset bytes
40  * NOTES:
41  * Buffer may be NULL
42  */
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 }
64 
66  UINT Offset,
67  PCHAR *DataOut,
68  PUINT Size ) {
70 
72  if( !Buffer ) return;
73  SkipToOffset( Buffer, Offset, DataOut, Size );
74 }
75 
76 
77 #undef NdisAllocatePacket
78 #undef NdisAllocateBuffer
79 #undef NdisFreeBuffer
80 #undef NdisFreePacket
81 
83  PCHAR Data, UINT Len,
84  PCHAR File, UINT Line ) {
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 }
115 
116 
119  PCHAR File,
120  UINT Line )
121 /*
122  * FUNCTION: Frees an NDIS packet
123  * ARGUMENTS:
124  * Packet = Pointer to NDIS packet to be freed
125  */
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 }
signed char * PCHAR
Definition: retypes.h:7
VOID EXPORT NdisAllocatePacketPool(OUT PNDIS_STATUS Status, OUT PNDIS_HANDLE PoolHandle, IN UINT NumberOfDescriptors, IN UINT ProtocolReservedLength)
Definition: buffer.c:419
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
VOID EXPORT NdisFreeBuffer(IN PNDIS_BUFFER Buffer)
Definition: buffer.c:809
#define exFreePool(x)
Definition: memtrack.h:18
#define NdisChainBufferAtFront(Packet, Buffer)
Definition: ndis.h:3106
int32_t INT
Definition: typedefs.h:56
#define NDIS_BUFFER_TAG
Definition: lan.h:22
#define NdisGetNextBuffer(CurrentBuffer, NextBuffer)
Definition: ndis.h:3386
int NDIS_STATUS
Definition: ntddndis.h:471
#define UntrackFL(x, y, z)
Definition: memtrack.h:20
uint32_t ULONG_PTR
Definition: typedefs.h:63
VOID CloseNdisPools()
Definition: routines.c:19
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
smooth NULL
Definition: ftsmooth.c:416
_In_ LPGUID _In_ PVOID Data
Definition: classpnp.h:778
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 PCHAR
Definition: match.c:90
#define LA_DbgPrint(_t_, _x_)
Definition: debug.h:66
VOID EXPORT NdisFreePacket(IN PNDIS_PACKET Packet)
Definition: buffer.c:826
#define NDIS_STATUS_NOT_ACCEPTED
Definition: ndis.h:350
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
VOID FreeNdisPacketX(PNDIS_PACKET Packet, PCHAR File, UINT Line)
Definition: routines.c:118
#define Len
Definition: deflate.h:82
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define DEBUG_PBUFFER
Definition: debug.h:20
Definition: ncftp.h:79
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
#define TrackWithTag(w, x, y, z)
Definition: memtrack.h:19
__inline INT SkipToOffset(PNDIS_BUFFER Buffer, UINT Offset, PCHAR *Data, PUINT Size)
Definition: routines.c:24
#define exAllocatePool(x, y)
Definition: memtrack.h:17
NDIS_HANDLE GlobalBufferPool
Definition: routines.c:4
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
Status
Definition: gdiplustypes.h:24
VOID EXPORT NdisFreeBufferPool(IN NDIS_HANDLE PoolHandle)
Definition: buffer.c:775
unsigned int UINT
Definition: ndis.h:50
VOID EXPORT NdisFreePacketPool(IN NDIS_HANDLE PoolHandle)
Definition: buffer.c:791
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
#define NDIS_PACKET_TAG
Definition: lan.h:23
NDIS_HANDLE GlobalPacketPool
Definition: routines.c:3
void GetDataPtr(PNDIS_PACKET Packet, UINT Offset, PCHAR *DataOut, PUINT Size)
Definition: routines.c:65
NDIS_STATUS InitNdisPools()
Definition: routines.c:6
NDIS_STATUS AllocatePacketWithBufferX(PNDIS_PACKET *NdisPacket, PCHAR Data, UINT Len, PCHAR File, UINT Line)
Definition: routines.c:82
Definition: File.h:15
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
VOID EXPORT NdisAllocateBufferPool(OUT PNDIS_STATUS Status, OUT PNDIS_HANDLE PoolHandle, IN UINT NumberOfDescriptors)
Definition: buffer.c:370
unsigned int * PUINT
Definition: ndis.h:50