ReactOS  0.4.14-dev-57-g333b8f1
buffer.c File Reference
#include <ndissys.h>
Include dependency graph for buffer.c:

Go to the source code of this file.

Functions

__inline ULONG SkipToOffset (IN PNDIS_BUFFER Buffer, IN UINT Offset, IN OUT PUCHAR *Data, IN OUT PUINT Size)
 
UINT CopyBufferToBufferChain (PNDIS_BUFFER DstBuffer, UINT DstOffset, PUCHAR SrcData, UINT Length)
 
UINT CopyBufferChainToBuffer (PUCHAR DstData, PNDIS_BUFFER SrcBuffer, UINT SrcOffset, UINT Length)
 
UINT CopyPacketToBuffer (PUCHAR DstData, PNDIS_PACKET SrcPacket, UINT SrcOffset, UINT Length)
 
UINT CopyPacketToBufferChain (PNDIS_BUFFER DstBuffer, UINT DstOffset, PNDIS_PACKET SrcPacket, UINT SrcOffset, UINT Length)
 
VOID EXPORT NdisAdjustBufferLength (IN PNDIS_BUFFER Buffer, IN UINT Length)
 
ULONG EXPORT NDIS_BUFFER_TO_SPAN_PAGES (IN PNDIS_BUFFER Buffer)
 
VOID EXPORT NdisAllocateBuffer (OUT PNDIS_STATUS Status, OUT PNDIS_BUFFER *Buffer, IN NDIS_HANDLE PoolHandle, IN PVOID VirtualAddress, IN UINT Length)
 
VOID EXPORT NdisAllocateBufferPool (OUT PNDIS_STATUS Status, OUT PNDIS_HANDLE PoolHandle, IN UINT NumberOfDescriptors)
 
VOID EXPORT NdisAllocatePacket (OUT PNDIS_STATUS Status, OUT PNDIS_PACKET *Packet, IN NDIS_HANDLE PoolHandle)
 
VOID EXPORT NdisAllocatePacketPool (OUT PNDIS_STATUS Status, OUT PNDIS_HANDLE PoolHandle, IN UINT NumberOfDescriptors, IN UINT ProtocolReservedLength)
 
VOID EXPORT NdisAllocatePacketPoolEx (OUT PNDIS_STATUS Status, OUT PNDIS_HANDLE PoolHandle, IN UINT NumberOfDescriptors, IN UINT NumberOfOverflowDescriptors, IN UINT ProtocolReservedLength)
 
ULONG EXPORT NdisBufferLength (IN PNDIS_BUFFER Buffer)
 
PVOID EXPORT NdisBufferVirtualAddress (IN PNDIS_BUFFER Buffer)
 
VOID EXPORT NdisCopyFromPacketToPacket (IN PNDIS_PACKET Destination, IN UINT DestinationOffset, IN UINT BytesToCopy, IN PNDIS_PACKET Source, IN UINT SourceOffset, OUT PUINT BytesCopied)
 
VOID EXPORT NdisDprAllocatePacket (OUT PNDIS_STATUS Status, OUT PNDIS_PACKET *Packet, IN NDIS_HANDLE PoolHandle)
 
VOID EXPORT NdisDprAllocatePacketNonInterlocked (OUT PNDIS_STATUS Status, OUT PNDIS_PACKET *Packet, IN NDIS_HANDLE PoolHandle)
 
VOID EXPORT NdisDprFreePacket (IN PNDIS_PACKET Packet)
 
VOID EXPORT NdisDprFreePacketNonInterlocked (IN PNDIS_PACKET Packet)
 
VOID EXPORT NdisFreeBufferPool (IN NDIS_HANDLE PoolHandle)
 
VOID EXPORT NdisFreePacketPool (IN NDIS_HANDLE PoolHandle)
 
VOID EXPORT NdisFreeBuffer (IN PNDIS_BUFFER Buffer)
 
VOID EXPORT NdisFreePacket (IN PNDIS_PACKET Packet)
 
VOID EXPORT NdisGetBufferPhysicalArraySize (IN PNDIS_BUFFER Buffer, OUT PUINT ArraySize)
 
VOID EXPORT NdisGetFirstBufferFromPacket (IN PNDIS_PACKET _Packet, OUT PNDIS_BUFFER *_FirstBuffer, OUT PVOID *_FirstBufferVA, OUT PUINT _FirstBufferLength, OUT PUINT _TotalBufferLength)
 
VOID EXPORT NdisGetFirstBufferFromPacketSafe (IN PNDIS_PACKET _Packet, OUT PNDIS_BUFFER *_FirstBuffer, OUT PVOID *_FirstBufferVA, OUT PUINT _FirstBufferLength, OUT PUINT _TotalBufferLength, IN MM_PAGE_PRIORITY Priority)
 
VOID EXPORT NdisQueryBuffer (IN PNDIS_BUFFER Buffer, OUT PVOID *VirtualAddress OPTIONAL, OUT PUINT Length)
 
VOID EXPORT NdisQueryBufferSafe (IN PNDIS_BUFFER Buffer, OUT PVOID *VirtualAddress OPTIONAL, OUT PUINT Length, IN UINT Priority)
 
VOID EXPORT NdisQueryBufferOffset (IN PNDIS_BUFFER Buffer, OUT PUINT Offset, OUT PUINT Length)
 
VOID EXPORT NdisUnchainBufferAtBack (IN OUT PNDIS_PACKET Packet, OUT PNDIS_BUFFER *Buffer)
 
VOID EXPORT NdisUnchainBufferAtFront (IN OUT PNDIS_PACKET Packet, OUT PNDIS_BUFFER *Buffer)
 
VOID EXPORT NdisCopyBuffer (OUT PNDIS_STATUS Status, OUT PNDIS_BUFFER *Buffer, IN NDIS_HANDLE PoolHandle, IN PVOID MemoryDescriptor, IN UINT Offset, IN UINT Length)
 
NDIS_HANDLE EXPORT NdisGetPoolFromPacket (IN PNDIS_PACKET Packet)
 
UINT EXPORT NdisPacketSize (IN UINT ProtocolReservedSize)
 
PVOID EXPORT NdisGetPacketCancelId (IN PNDIS_PACKET Packet)
 
VOID EXPORT NdisSetPacketCancelId (IN PNDIS_PACKET Packet, IN PVOID CancelId)
 
VOID EXPORT NdisCopyFromPacketToPacketSafe (IN PNDIS_PACKET Destination, IN UINT DestinationOffset, IN UINT BytesToCopy, IN PNDIS_PACKET Source, IN UINT SourceOffset, OUT PUINT BytesCopied, IN MM_PAGE_PRIORITY Priority)
 
VOID EXPORT NdisIMCopySendCompletePerPacketInfo (IN PNDIS_PACKET DstPacket, IN PNDIS_PACKET SrcPacket)
 
VOID EXPORT NdisIMCopySendPerPacketInfo (IN PNDIS_PACKET DstPacket, IN PNDIS_PACKET SrcPacket)
 

Function Documentation

◆ CopyBufferChainToBuffer()

UINT CopyBufferChainToBuffer ( PUCHAR  DstData,
PNDIS_BUFFER  SrcBuffer,
UINT  SrcOffset,
UINT  Length 
)

Definition at line 111 of file buffer.c.

129 {
130  UINT BytesCopied, BytesToCopy, SrcSize;
131  PUCHAR SrcData;
132 
133  NDIS_DbgPrint(MAX_TRACE, ("DstData 0x%X SrcBuffer 0x%X SrcOffset 0x%X Length %d\n",DstData,SrcBuffer, SrcOffset, Length));
134 
135  /* Skip SrcOffset bytes in the source buffer chain */
136  if (SkipToOffset(SrcBuffer, SrcOffset, &SrcData, &SrcSize) == 0xFFFFFFFF)
137  return 0;
138 
139  /* Start copying the data */
140  BytesCopied = 0;
141  for (;;) {
142  BytesToCopy = MIN(SrcSize, Length);
143 
144  NDIS_DbgPrint(MAX_TRACE, ("Copying (%d) bytes from 0x%X to 0x%X\n", BytesToCopy, SrcData, DstData));
145 
146  RtlCopyMemory((PVOID)DstData, (PVOID)SrcData, BytesToCopy);
148  DstData = (PUCHAR)((ULONG_PTR) DstData + BytesToCopy);
149 
150  Length -= BytesToCopy;
151  if (Length == 0)
152  break;
153 
154  SrcSize -= BytesToCopy;
155  if (SrcSize == 0) {
156  /* No more bytes in source buffer. Proceed to
157  the next buffer in the source buffer chain */
158  NdisGetNextBuffer(SrcBuffer, &SrcBuffer);
159  if (!SrcBuffer)
160  break;
161 
162  NdisQueryBuffer(SrcBuffer, (PVOID)&SrcData, &SrcSize);
163  }
164  }
165 
166  return BytesCopied;
167 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
unsigned char * PUCHAR
Definition: retypes.h:3
_In_ UINT _In_ UINT BytesToCopy
Definition: ndis.h:3167
#define NdisGetNextBuffer(CurrentBuffer, NextBuffer)
Definition: ndis.h:3386
uint32_t ULONG_PTR
Definition: typedefs.h:63
T MIN(T a, T b)
Definition: polytest.cpp:79
_In_ UINT _In_ UINT _In_ PNDIS_PACKET _In_ UINT _Out_ PUINT BytesCopied
Definition: ndis.h:3167
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
__inline ULONG SkipToOffset(IN PNDIS_BUFFER Buffer, IN UINT Offset, IN OUT PUCHAR *Data, IN OUT PUINT Size)
Definition: buffer.c:13
#define MAX_TRACE
Definition: debug.h:16
unsigned int UINT
Definition: ndis.h:50
#define NDIS_DbgPrint(_t_, _x_)
Definition: debug.h:40
VOID EXPORT NdisQueryBuffer(IN PNDIS_BUFFER Buffer, OUT PVOID *VirtualAddress OPTIONAL, OUT PUINT Length)
Definition: buffer.c:953

Referenced by CopyPacketToBuffer(), and MiniIndicateReceivePacket().

◆ CopyBufferToBufferChain()

UINT CopyBufferToBufferChain ( PNDIS_BUFFER  DstBuffer,
UINT  DstOffset,
PUCHAR  SrcData,
UINT  Length 
)

Definition at line 54 of file buffer.c.

72 {
73  UINT BytesCopied, BytesToCopy, DstSize;
74  PUCHAR DstData;
75 
76  NDIS_DbgPrint(MAX_TRACE, ("DstBuffer (0x%X) DstOffset (0x%X) SrcData (0x%X) Length (%d)\n", DstBuffer, DstOffset, SrcData, Length));
77 
78  /* Skip DstOffset bytes in the destination buffer chain */
79  if (SkipToOffset(DstBuffer, DstOffset, &DstData, &DstSize) == 0xFFFFFFFF)
80  return 0;
81 
82  /* Start copying the data */
83  BytesCopied = 0;
84  for (;;) {
85  BytesToCopy = MIN(DstSize, Length);
86 
87  RtlCopyMemory((PVOID)DstData, (PVOID)SrcData, BytesToCopy);
89  SrcData = (PUCHAR) ((ULONG_PTR) SrcData + BytesToCopy);
90 
92  if (Length == 0)
93  break;
94 
95  DstSize -= BytesToCopy;
96  if (DstSize == 0) {
97  /* No more bytes in destination buffer. Proceed to
98  the next buffer in the destination buffer chain */
99  NdisGetNextBuffer(DstBuffer, &DstBuffer);
100  if (!DstBuffer)
101  break;
102 
103  NdisQueryBuffer(DstBuffer, (PVOID)&DstData, &DstSize);
104  }
105  }
106 
107  return BytesCopied;
108 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
unsigned char * PUCHAR
Definition: retypes.h:3
_In_ UINT _In_ UINT BytesToCopy
Definition: ndis.h:3167
#define NdisGetNextBuffer(CurrentBuffer, NextBuffer)
Definition: ndis.h:3386
uint32_t ULONG_PTR
Definition: typedefs.h:63
T MIN(T a, T b)
Definition: polytest.cpp:79
_In_ UINT _In_ UINT _In_ PNDIS_PACKET _In_ UINT _Out_ PUINT BytesCopied
Definition: ndis.h:3167
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
__inline ULONG SkipToOffset(IN PNDIS_BUFFER Buffer, IN UINT Offset, IN OUT PUCHAR *Data, IN OUT PUINT Size)
Definition: buffer.c:13
#define MAX_TRACE
Definition: debug.h:16
unsigned int UINT
Definition: ndis.h:50
#define NDIS_DbgPrint(_t_, _x_)
Definition: debug.h:40
VOID EXPORT NdisQueryBuffer(IN PNDIS_BUFFER Buffer, OUT PVOID *VirtualAddress OPTIONAL, OUT PUINT Length)
Definition: buffer.c:953

Referenced by DispTdiQueryInformationExComplete(), InfoCopyOut(), and InfoTdiQueryListEntities().

◆ CopyPacketToBuffer()

UINT CopyPacketToBuffer ( PUCHAR  DstData,
PNDIS_PACKET  SrcPacket,
UINT  SrcOffset,
UINT  Length 
)

Definition at line 170 of file buffer.c.

188 {
189  PNDIS_BUFFER FirstBuffer;
190  PVOID Address;
191  UINT FirstLength;
193 
194  NDIS_DbgPrint(MAX_TRACE, ("DstData (0x%X) SrcPacket (0x%X) SrcOffset (0x%X) Length (%d)\n", DstData, SrcPacket, SrcOffset, Length));
195 
197  &FirstBuffer,
198  &Address,
199  &FirstLength,
200  &TotalLength);
201 
202  return CopyBufferChainToBuffer(DstData, FirstBuffer, SrcOffset, Length);
203 }
MDL * PNDIS_BUFFER
Definition: ndis.h:343
_In_ ULONG TotalLength
Definition: usbdlib.h:145
static WCHAR Address[46]
Definition: ping.c:68
VOID EXPORT NdisGetFirstBufferFromPacket(IN PNDIS_PACKET _Packet, OUT PNDIS_BUFFER *_FirstBuffer, OUT PVOID *_FirstBufferVA, OUT PUINT _FirstBufferLength, OUT PUINT _TotalBufferLength)
Definition: buffer.c:871
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define MAX_TRACE
Definition: debug.h:16
unsigned int UINT
Definition: ndis.h:50
#define NDIS_DbgPrint(_t_, _x_)
Definition: debug.h:40
UINT CopyBufferChainToBuffer(PUCHAR DstData, PNDIS_BUFFER SrcBuffer, UINT SrcOffset, UINT Length)
Definition: buffer.c:111

Referenced by ARPReceive(), GetPacketTypeFromNdisPacket(), IPReceive(), IPv4Receive(), ProIndicatePacket(), and ReassembleDatagram().

◆ CopyPacketToBufferChain()

UINT CopyPacketToBufferChain ( PNDIS_BUFFER  DstBuffer,
UINT  DstOffset,
PNDIS_PACKET  SrcPacket,
UINT  SrcOffset,
UINT  Length 
)

Definition at line 206 of file buffer.c.

226 {
227  PNDIS_BUFFER SrcBuffer;
228  PUCHAR DstData, SrcData;
229  UINT DstSize, SrcSize;
230  UINT Count, Total;
231 
232  NDIS_DbgPrint(MAX_TRACE, ("DstBuffer (0x%X) DstOffset (0x%X) SrcPacket (0x%X) SrcOffset (0x%X) Length (%d)\n", DstBuffer, DstOffset, SrcPacket, SrcOffset, Length));
233 
234  /* Skip DstOffset bytes in the destination buffer chain */
235  NdisQueryBuffer(DstBuffer, (PVOID)&DstData, &DstSize);
236  if (SkipToOffset(DstBuffer, DstOffset, &DstData, &DstSize) == 0xFFFFFFFF)
237  return 0;
238  /* Skip SrcOffset bytes in the source packet */
239  NdisGetFirstBufferFromPacket(SrcPacket, &SrcBuffer, (PVOID*)&SrcData, &SrcSize, &Total);
240  if (SkipToOffset(SrcBuffer, SrcOffset, &SrcData, &SrcSize) == 0xFFFFFFFF)
241  return 0;
242  /* Copy the data */
243  for (Total = 0;;) {
244  /* Find out how many bytes we can copy at one time */
245  if (Length < SrcSize)
246  Count = Length;
247  else
248  Count = SrcSize;
249  if (DstSize < Count)
250  Count = DstSize;
251 
252  RtlCopyMemory((PVOID)DstData, (PVOID)SrcData, Count);
253 
254  Total += Count;
255  Length -= Count;
256  if (Length == 0)
257  break;
258 
259  DstSize -= Count;
260  if (DstSize == 0) {
261  /* No more bytes in destination buffer. Proceed to
262  the next buffer in the destination buffer chain */
263  NdisGetNextBuffer(DstBuffer, &DstBuffer);
264  if (!DstBuffer)
265  break;
266 
267  NdisQueryBuffer(DstBuffer, (PVOID)&DstData, &DstSize);
268  }
269 
270  SrcSize -= Count;
271  if (SrcSize == 0) {
272  /* No more bytes in source buffer. Proceed to
273  the next buffer in the source buffer chain */
274  NdisGetNextBuffer(SrcBuffer, &SrcBuffer);
275  if (!SrcBuffer)
276  break;
277 
278  NdisQueryBuffer(SrcBuffer, (PVOID)&SrcData, &SrcSize);
279  }
280  }
281 
282  return Total;
283 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
MDL * PNDIS_BUFFER
Definition: ndis.h:343
unsigned char * PUCHAR
Definition: retypes.h:3
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
#define NdisGetNextBuffer(CurrentBuffer, NextBuffer)
Definition: ndis.h:3386
VOID EXPORT NdisGetFirstBufferFromPacket(IN PNDIS_PACKET _Packet, OUT PNDIS_BUFFER *_FirstBuffer, OUT PVOID *_FirstBufferVA, OUT PUINT _FirstBufferLength, OUT PUINT _TotalBufferLength)
Definition: buffer.c:871
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
__inline ULONG SkipToOffset(IN PNDIS_BUFFER Buffer, IN UINT Offset, IN OUT PUCHAR *Data, IN OUT PUINT Size)
Definition: buffer.c:13
#define MAX_TRACE
Definition: debug.h:16
unsigned int UINT
Definition: ndis.h:50
#define NDIS_DbgPrint(_t_, _x_)
Definition: debug.h:40
VOID EXPORT NdisQueryBuffer(IN PNDIS_BUFFER Buffer, OUT PVOID *VirtualAddress OPTIONAL, OUT PUINT Length)
Definition: buffer.c:953

◆ NDIS_BUFFER_TO_SPAN_PAGES()

ULONG EXPORT NDIS_BUFFER_TO_SPAN_PAGES ( IN PNDIS_BUFFER  Buffer)

Definition at line 312 of file buffer.c.

319 {
320  if (MmGetMdlByteCount(Buffer) == 0)
321  return 1;
322 
326 }
#define MmGetMdlVirtualAddress(_Mdl)
Definition: bufpool.h:45
#define ADDRESS_AND_SIZE_TO_SPAN_PAGES(_Va, _Size)
#define MmGetMdlByteCount(_Mdl)

Referenced by NdisGetBufferPhysicalArraySize(), and NdisQueryPacket().

◆ NdisAdjustBufferLength()

VOID EXPORT NdisAdjustBufferLength ( IN PNDIS_BUFFER  Buffer,
IN UINT  Length 
)

Definition at line 292 of file buffer.c.

301 {
302  Buffer->ByteCount = Length;
303 }
Definition: bufpool.h:45
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101

◆ NdisAllocateBuffer()

VOID EXPORT NdisAllocateBuffer ( OUT PNDIS_STATUS  Status,
OUT PNDIS_BUFFER Buffer,
IN NDIS_HANDLE  PoolHandle,
IN PVOID  VirtualAddress,
IN UINT  Length 
)

Definition at line 334 of file buffer.c.

349 {
351  ASSERT(Length > 0);
352 
354  if (*Buffer != NULL) {
356  (*Buffer)->Next = NULL;
358  } else {
359  NDIS_DbgPrint(MIN_TRACE, ("IoAllocateMdl failed (%x, %lx)\n", VirtualAddress, Length));
361  }
362 }
VOID NTAPI MmBuildMdlForNonPagedPool(IN PMDL Mdl)
Definition: mdlsup.c:428
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
_In_ ULONG _In_ BOOLEAN _Must_inspect_result_ PVOID * VirtualAddress
Definition: ndis.h:3791
Status
Definition: gdiplustypes.h:24
PMDL NTAPI IoAllocateMdl(IN PVOID VirtualAddress, IN ULONG Length, IN BOOLEAN SecondaryBuffer, IN BOOLEAN ChargeQuota, IN PIRP Irp)
Definition: iomdl.c:22
#define NDIS_DbgPrint(_t_, _x_)
Definition: debug.h:40
#define MIN_TRACE
Definition: debug.h:14
#define NDIS_STATUS_FAILURE
Definition: ndis.h:465

Referenced by AllocateAndChainBuffer(), AllocatePacketWithBuffer(), AllocatePacketWithBufferX(), and PrependPacket().

◆ NdisAllocateBufferPool()

VOID EXPORT NdisAllocateBufferPool ( OUT PNDIS_STATUS  Status,
OUT PNDIS_HANDLE  PoolHandle,
IN UINT  NumberOfDescriptors 
)

Definition at line 370 of file buffer.c.

381 {
383  *PoolHandle = 0;
384 }
_Out_ PNDIS_BUFFER _In_opt_ NDIS_HANDLE PoolHandle
Definition: ndis.h:2867
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
Status
Definition: gdiplustypes.h:24

Referenced by BindAdapterByName(), DriverEntry(), and InitNdisPools().

◆ NdisAllocatePacket()

VOID EXPORT NdisAllocatePacket ( OUT PNDIS_STATUS  Status,
OUT PNDIS_PACKET Packet,
IN NDIS_HANDLE  PoolHandle 
)

Definition at line 392 of file buffer.c.

403 {
405 
406  KeAcquireSpinLock(&Pool->SpinLock.SpinLock, &Pool->SpinLock.OldIrql);
408  Packet,
409  PoolHandle);
410  KeReleaseSpinLock(&Pool->SpinLock.SpinLock, Pool->SpinLock.OldIrql);
411 }
VOID EXPORT NdisDprAllocatePacketNonInterlocked(OUT PNDIS_STATUS Status, OUT PNDIS_PACKET *Packet, IN NDIS_HANDLE PoolHandle)
Definition: buffer.c:681
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
_Out_ PNDIS_BUFFER _In_opt_ NDIS_HANDLE PoolHandle
Definition: ndis.h:2867
struct _NDISI_PACKET_POOL * PNDISI_PACKET_POOL
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
Definition: bufpool.h:50
Status
Definition: gdiplustypes.h:24
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627

Referenced by AllocatePacketWithBuffer(), AllocatePacketWithBufferX(), and CreatePacketFromPoolBuffer().

◆ NdisAllocatePacketPool()

VOID EXPORT NdisAllocatePacketPool ( OUT PNDIS_STATUS  Status,
OUT PNDIS_HANDLE  PoolHandle,
IN UINT  NumberOfDescriptors,
IN UINT  ProtocolReservedLength 
)

Definition at line 419 of file buffer.c.

432 {
434  Status,
435  PoolHandle,
437  0,
439 }
_Out_ PNDIS_HANDLE _In_ UINT _In_ UINT ProtocolReservedLength
Definition: ndis.h:2903
_Out_ PNDIS_HANDLE _In_ UINT NumberOfDescriptors
Definition: ndis.h:2878
_Out_ PNDIS_BUFFER _In_opt_ NDIS_HANDLE PoolHandle
Definition: ndis.h:2867
Status
Definition: gdiplustypes.h:24
VOID EXPORT NdisAllocatePacketPoolEx(OUT PNDIS_STATUS Status, OUT PNDIS_HANDLE PoolHandle, IN UINT NumberOfDescriptors, IN UINT NumberOfOverflowDescriptors, IN UINT ProtocolReservedLength)
Definition: buffer.c:447

Referenced by BindAdapterByName(), and InitNdisPools().

◆ NdisAllocatePacketPoolEx()

VOID EXPORT NdisAllocatePacketPoolEx ( OUT PNDIS_STATUS  Status,
OUT PNDIS_HANDLE  PoolHandle,
IN UINT  NumberOfDescriptors,
IN UINT  NumberOfOverflowDescriptors,
IN UINT  ProtocolReservedLength 
)

Definition at line 447 of file buffer.c.

459 {
461  UINT Size, Length, i;
462  PNDIS_PACKET Packet, NextPacket;
463 
464  NDIS_DbgPrint(MAX_TRACE, ("Status (0x%X) PoolHandle (0x%X) "
465  "NumberOfDescriptors (%d) ProtocolReservedLength (%d).\n",
467 
468  *PoolHandle = NULL;
469 
470  if (NumberOfDescriptors > 0xffff)
471  {
472  NDIS_DbgPrint(MIN_TRACE, ("Invalid number of descriptors (%lx)\n", NumberOfDescriptors))
474  }
475  else
476  {
478  if (NumberOfDescriptors > 0xffff)
479  {
480  NDIS_DbgPrint(MIN_TRACE, ("Total number of descriptors > 0xffff (%lx)\n", NumberOfDescriptors));
481  NumberOfDescriptors = 0xffff;
482  }
483 
484  Length = sizeof(NDIS_PACKET) + sizeof(NDIS_PACKET_OOB_DATA) +
487 
489  if (Pool)
490  {
491  KeInitializeSpinLock(&Pool->SpinLock.SpinLock);
492  Pool->PacketLength = Length;
493 
494  if (NumberOfDescriptors > 0)
495  {
496  Packet = (PNDIS_PACKET)&Pool->Buffer;
497  Pool->FreeList = Packet;
498 
499  NextPacket = (PNDIS_PACKET)((ULONG_PTR)Packet + Length);
500  for (i = 1; i < NumberOfDescriptors; i++)
501  {
502  Packet->Reserved[0] = (ULONG_PTR)NextPacket;
503  Packet = NextPacket;
504  NextPacket = (PNDIS_PACKET)((ULONG_PTR)Packet + Length);
505  }
506  Packet->Reserved[0] = 0;
507  }
508  else {
509  NDIS_DbgPrint(MIN_TRACE, ("Attempted to allocate a packet pool with 0 descriptors\n"));
510  Pool->FreeList = NULL;
511  }
512 
515  } else {
517  }
518  }
519 }
_Out_ PNDIS_HANDLE _In_ UINT _In_ UINT ProtocolReservedLength
Definition: ndis.h:2903
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
_Out_ PNDIS_HANDLE _In_ UINT _In_ UINT NumberOfOverflowDescriptors
Definition: ndis.h:2913
_Out_ PNDIS_HANDLE _In_ UINT NumberOfDescriptors
Definition: ndis.h:2878
uint32_t ULONG_PTR
Definition: typedefs.h:63
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_Out_ PNDIS_BUFFER _In_opt_ NDIS_HANDLE PoolHandle
Definition: ndis.h:2867
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:251
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:50
struct _NDIS_PACKET_EXTENSION NDIS_PACKET_EXTENSION
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
struct _NDIS_PACKET NDIS_PACKET
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
Status
Definition: gdiplustypes.h:24
#define MAX_TRACE
Definition: debug.h:16
unsigned int UINT
Definition: ndis.h:50
#define NDIS_DbgPrint(_t_, _x_)
Definition: debug.h:40
struct _NDIS_PACKET * PNDIS_PACKET
struct _NDISI_PACKET_POOL NDISI_PACKET_POOL
#define NDIS_STATUS_RESOURCES
Definition: ndis.h:466
PVOID * PNDIS_HANDLE
Definition: ndis.h:338
#define MIN_TRACE
Definition: debug.h:14
#define ULONG_PTR
Definition: config.h:101

Referenced by DriverEntry(), and NdisAllocatePacketPool().

◆ NdisBufferLength()

ULONG EXPORT NdisBufferLength ( IN PNDIS_BUFFER  Buffer)

Definition at line 528 of file buffer.c.

540 {
541  return MmGetMdlByteCount(Buffer);
542 }
Definition: bufpool.h:45
#define MmGetMdlByteCount(_Mdl)

◆ NdisBufferVirtualAddress()

PVOID EXPORT NdisBufferVirtualAddress ( IN PNDIS_BUFFER  Buffer)

Definition at line 551 of file buffer.c.

559 {
561 }
Definition: bufpool.h:45
#define MmGetSystemAddressForMdl(Mdl)

◆ NdisCopyBuffer()

VOID EXPORT NdisCopyBuffer ( OUT PNDIS_STATUS  Status,
OUT PNDIS_BUFFER Buffer,
IN NDIS_HANDLE  PoolHandle,
IN PVOID  MemoryDescriptor,
IN UINT  Offset,
IN UINT  Length 
)

Definition at line 1108 of file buffer.c.

1125 {
1127 
1128  NDIS_DbgPrint(MAX_TRACE, ("Called\n"));
1129 
1130  *Buffer = IoAllocateMdl(CurrentVa, Length, FALSE, FALSE, NULL);
1131  if (!*Buffer)
1132  {
1133  NDIS_DbgPrint(MIN_TRACE, ("IoAllocateMdl failed (%x, %lx)\n", CurrentVa, Length));
1135  return;
1136  }
1137 
1139  *Buffer,
1140  CurrentVa,
1141  Length);
1142 
1143  (*Buffer)->Next = NULL;
1145 }
_Out_ PNDIS_BUFFER _In_ NDIS_HANDLE _In_ PVOID MemoryDescriptor
Definition: ndis.h:3270
#define MmGetMdlVirtualAddress(_Mdl)
MDL * PNDIS_BUFFER
Definition: ndis.h:343
unsigned char * PUCHAR
Definition: retypes.h:3
VOID NTAPI IoBuildPartialMdl(IN PMDL SourceMdl, IN PMDL TargetMdl, IN PVOID VirtualAddress, IN ULONG Length)
Definition: iomdl.c:96
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
Status
Definition: gdiplustypes.h:24
PMDL NTAPI IoAllocateMdl(IN PVOID VirtualAddress, IN ULONG Length, IN BOOLEAN SecondaryBuffer, IN BOOLEAN ChargeQuota, IN PIRP Irp)
Definition: iomdl.c:22
#define MAX_TRACE
Definition: debug.h:16
#define NDIS_DbgPrint(_t_, _x_)
Definition: debug.h:40
#define MIN_TRACE
Definition: debug.h:14
#define NDIS_STATUS_FAILURE
Definition: ndis.h:465

◆ NdisCopyFromPacketToPacket()

VOID EXPORT NdisCopyFromPacketToPacket ( IN PNDIS_PACKET  Destination,
IN UINT  DestinationOffset,
IN UINT  BytesToCopy,
IN PNDIS_PACKET  Source,
IN UINT  SourceOffset,
OUT PUINT  BytesCopied 
)

Definition at line 569 of file buffer.c.

586 {
587  PNDIS_BUFFER SrcBuffer;
588  PNDIS_BUFFER DstBuffer;
589  PUCHAR DstData, SrcData;
590  UINT DstSize, SrcSize;
591  UINT Count, Total;
592 
593  *BytesCopied = 0;
594 
595  /* Skip DestinationOffset bytes in the destination packet */
596  NdisGetFirstBufferFromPacket(Destination, &DstBuffer, (PVOID*)&DstData, &DstSize, &Total);
597  if (SkipToOffset(DstBuffer, DestinationOffset, &DstData, &DstSize) == 0xFFFFFFFF)
598  return;
599 
600  /* Skip SourceOffset bytes in the source packet */
601  NdisGetFirstBufferFromPacket(Source, &SrcBuffer, (PVOID*)&SrcData, &SrcSize, &Total);
602  if (SkipToOffset(SrcBuffer, SourceOffset, &SrcData, &SrcSize) == 0xFFFFFFFF)
603  return;
604 
605  /* Copy the data */
606  for (Total = 0;;) {
607  /* Find out how many bytes we can copy at one time */
608  if (BytesToCopy < SrcSize)
609  Count = BytesToCopy;
610  else
611  Count = SrcSize;
612  if (DstSize < Count)
613  Count = DstSize;
614 
615  RtlCopyMemory(DstData, SrcData, Count);
616 
617  Total += Count;
618  BytesToCopy -= Count;
619  if (BytesToCopy == 0)
620  break;
621 
622  DstSize -= Count;
623  if (DstSize == 0) {
624  /* No more bytes in destination buffer. Proceed to
625  the next buffer in the destination buffer chain */
626  NdisGetNextBuffer(DstBuffer, &DstBuffer);
627  if (!DstBuffer)
628  break;
629 
630  NdisQueryBuffer(DstBuffer, (PVOID)&DstData, &DstSize);
631  }
632 
633  SrcSize -= Count;
634  if (SrcSize == 0) {
635  /* No more bytes in source buffer. Proceed to
636  the next buffer in the source buffer chain */
637  NdisGetNextBuffer(SrcBuffer, &SrcBuffer);
638  if (!SrcBuffer)
639  break;
640 
641  NdisQueryBuffer(SrcBuffer, (PVOID)&SrcData, &SrcSize);
642  }
643  }
644 
645  *BytesCopied = Total;
646 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
MDL * PNDIS_BUFFER
Definition: ndis.h:343
unsigned char * PUCHAR
Definition: retypes.h:3
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
_In_ UINT _In_ UINT BytesToCopy
Definition: ndis.h:3167
#define NdisGetNextBuffer(CurrentBuffer, NextBuffer)
Definition: ndis.h:3386
_In_ UINT _In_ UINT _In_ PNDIS_PACKET _In_ UINT _Out_ PUINT BytesCopied
Definition: ndis.h:3167
VOID EXPORT NdisGetFirstBufferFromPacket(IN PNDIS_PACKET _Packet, OUT PNDIS_BUFFER *_FirstBuffer, OUT PVOID *_FirstBufferVA, OUT PUINT _FirstBufferLength, OUT PUINT _TotalBufferLength)
Definition: buffer.c:871
_In_ PUNICODE_STRING _Inout_ PUNICODE_STRING Destination
Definition: rtlfuncs.h:2891
__inline ULONG SkipToOffset(IN PNDIS_BUFFER Buffer, IN UINT Offset, IN OUT PUCHAR *Data, IN OUT PUINT Size)
Definition: buffer.c:13
_In_ UINT _In_ UINT _In_ PNDIS_PACKET _In_ UINT SourceOffset
Definition: ndis.h:3167
_In_ UINT DestinationOffset
Definition: ndis.h:3167
unsigned int UINT
Definition: ndis.h:50
VOID EXPORT NdisQueryBuffer(IN PNDIS_BUFFER Buffer, OUT PVOID *VirtualAddress OPTIONAL, OUT PUINT Length)
Definition: buffer.c:953
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3167

Referenced by ProTransferData().

◆ NdisCopyFromPacketToPacketSafe()

VOID EXPORT NdisCopyFromPacketToPacketSafe ( IN PNDIS_PACKET  Destination,
IN UINT  DestinationOffset,
IN UINT  BytesToCopy,
IN PNDIS_PACKET  Source,
IN UINT  SourceOffset,
OUT PUINT  BytesCopied,
IN MM_PAGE_PRIORITY  Priority 
)

Definition at line 1200 of file buffer.c.

1208 {
1209  PNDIS_BUFFER SrcBuffer;
1210  PNDIS_BUFFER DstBuffer;
1211  PUCHAR DstData, SrcData;
1212  UINT DstSize, SrcSize;
1213  UINT Count, Total;
1214 
1215  *BytesCopied = 0;
1216 
1217  /* Skip DestinationOffset bytes in the destination packet */
1218  NdisGetFirstBufferFromPacketSafe(Destination, &DstBuffer, (PVOID*)&DstData, &DstSize, &Total, Priority);
1219  if (!DstData || SkipToOffset(DstBuffer, DestinationOffset, &DstData, &DstSize) == 0xFFFFFFFF)
1220  return;
1221 
1222  /* Skip SourceOffset bytes in the source packet */
1223  NdisGetFirstBufferFromPacketSafe(Source, &SrcBuffer, (PVOID*)&SrcData, &SrcSize, &Total, Priority);
1224  if (!SrcData || SkipToOffset(SrcBuffer, SourceOffset, &SrcData, &SrcSize) == 0xFFFFFFFF)
1225  return;
1226 
1227  /* Copy the data */
1228  for (Total = 0;;) {
1229  /* Find out how many bytes we can copy at one time */
1230  if (BytesToCopy < SrcSize)
1231  Count = BytesToCopy;
1232  else
1233  Count = SrcSize;
1234  if (DstSize < Count)
1235  Count = DstSize;
1236 
1237  RtlCopyMemory(DstData, SrcData, Count);
1238 
1239  Total += Count;
1240  BytesToCopy -= Count;
1241  if (BytesToCopy == 0)
1242  break;
1243 
1244  DstSize -= Count;
1245  if (DstSize == 0) {
1246  /* No more bytes in destination buffer. Proceed to
1247  the next buffer in the destination buffer chain */
1248  NdisGetNextBuffer(DstBuffer, &DstBuffer);
1249  if (!DstBuffer)
1250  break;
1251 
1252  NdisQueryBufferSafe(DstBuffer, (PVOID)&DstData, &DstSize, Priority);
1253  if (!DstData)
1254  break;
1255  }
1256 
1257  SrcSize -= Count;
1258  if (SrcSize == 0) {
1259  /* No more bytes in source buffer. Proceed to
1260  the next buffer in the source buffer chain */
1261  NdisGetNextBuffer(SrcBuffer, &SrcBuffer);
1262  if (!SrcBuffer)
1263  break;
1264 
1265  NdisQueryBufferSafe(SrcBuffer, (PVOID)&SrcData, &SrcSize, Priority);
1266  if (!SrcData)
1267  break;
1268  }
1269  }
1270 
1271  *BytesCopied = Total;
1272 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
MDL * PNDIS_BUFFER
Definition: ndis.h:343
unsigned char * PUCHAR
Definition: retypes.h:3
_In_ KPRIORITY Priority
Definition: kefuncs.h:516
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
_In_ UINT _In_ UINT BytesToCopy
Definition: ndis.h:3167
#define NdisGetNextBuffer(CurrentBuffer, NextBuffer)
Definition: ndis.h:3386
_In_ UINT _In_ UINT _In_ PNDIS_PACKET _In_ UINT _Out_ PUINT BytesCopied
Definition: ndis.h:3167
VOID EXPORT NdisGetFirstBufferFromPacketSafe(IN PNDIS_PACKET _Packet, OUT PNDIS_BUFFER *_FirstBuffer, OUT PVOID *_FirstBufferVA, OUT PUINT _FirstBufferLength, OUT PUINT _TotalBufferLength, IN MM_PAGE_PRIORITY Priority)
Definition: buffer.c:916
_In_ PUNICODE_STRING _Inout_ PUNICODE_STRING Destination
Definition: rtlfuncs.h:2891
VOID EXPORT NdisQueryBufferSafe(IN PNDIS_BUFFER Buffer, OUT PVOID *VirtualAddress OPTIONAL, OUT PUINT Length, IN UINT Priority)
Definition: buffer.c:979
__inline ULONG SkipToOffset(IN PNDIS_BUFFER Buffer, IN UINT Offset, IN OUT PUCHAR *Data, IN OUT PUINT Size)
Definition: buffer.c:13
_In_ UINT _In_ UINT _In_ PNDIS_PACKET _In_ UINT SourceOffset
Definition: ndis.h:3167
_In_ UINT DestinationOffset
Definition: ndis.h:3167
unsigned int UINT
Definition: ndis.h:50
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3167

◆ NdisDprAllocatePacket()

VOID EXPORT NdisDprAllocatePacket ( OUT PNDIS_STATUS  Status,
OUT PNDIS_PACKET Packet,
IN NDIS_HANDLE  PoolHandle 
)

Definition at line 654 of file buffer.c.

665 {
667 
668  KeAcquireSpinLockAtDpcLevel(&Pool->SpinLock.SpinLock);
670  Packet,
671  PoolHandle);
672  KeReleaseSpinLockFromDpcLevel(&Pool->SpinLock.SpinLock);
673 }
VOID EXPORT NdisDprAllocatePacketNonInterlocked(OUT PNDIS_STATUS Status, OUT PNDIS_PACKET *Packet, IN NDIS_HANDLE PoolHandle)
Definition: buffer.c:681
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
VOID NTAPI KeAcquireSpinLockAtDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:192
_Out_ PNDIS_BUFFER _In_opt_ NDIS_HANDLE PoolHandle
Definition: ndis.h:2867
struct _NDISI_PACKET_POOL * PNDISI_PACKET_POOL
VOID NTAPI KeReleaseSpinLockFromDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:215
Definition: bufpool.h:50
Status
Definition: gdiplustypes.h:24

◆ NdisDprAllocatePacketNonInterlocked()

VOID EXPORT NdisDprAllocatePacketNonInterlocked ( OUT PNDIS_STATUS  Status,
OUT PNDIS_PACKET Packet,
IN NDIS_HANDLE  PoolHandle 
)

Definition at line 681 of file buffer.c.

692 {
693  PNDIS_PACKET Temp;
695 
696  NDIS_DbgPrint(MAX_TRACE, ("Status (0x%X) Packet (0x%X) PoolHandle (0x%X).\n",
698 
699  *Packet = NULL;
700 
701  if (Pool == NULL)
702  {
704  NDIS_DbgPrint(MIN_TRACE, ("Called passed a bad pool handle\n"));
705  return;
706  }
707 
708  if (Pool->FreeList) {
709  Temp = Pool->FreeList;
710  Pool->FreeList = (PNDIS_PACKET)Temp->Reserved[0];
711 
712  RtlZeroMemory(Temp, Pool->PacketLength);
713  Temp->Private.Pool = Pool;
714  Temp->Private.ValidCounts = TRUE;
716  Temp->Private.NdisPacketOobOffset = Pool->PacketLength -
717  (sizeof(NDIS_PACKET_OOB_DATA) +
718  sizeof(NDIS_PACKET_EXTENSION));
719 
720  *Packet = Temp;
722  } else {
723  NDIS_DbgPrint(MIN_TRACE, ("No more free descriptors\n"));
725  }
726 }
#define TRUE
Definition: types.h:120
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
BOOLEAN ValidCounts
Definition: ndis.h:729
struct _NDIS_PACKET_OOB_DATA NDIS_PACKET_OOB_DATA
NDIS_PACKET_PRIVATE Private
Definition: ndis.h:735
_Out_ PNDIS_BUFFER _In_opt_ NDIS_HANDLE PoolHandle
Definition: ndis.h:2867
USHORT NdisPacketOobOffset
Definition: ndis.h:731
struct _NDISI_PACKET_POOL * PNDISI_PACKET_POOL
smooth NULL
Definition: ftsmooth.c:416
PNDIS_PACKET_POOL Pool
Definition: ndis.h:726
Definition: bufpool.h:50
#define fPACKET_ALLOCATED_BY_NDIS
Definition: ndis.h:702
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
ULONG_PTR Reserved[2]
Definition: ndis.h:749
UCHAR NdisPacketFlags
Definition: ndis.h:730
Status
Definition: gdiplustypes.h:24
#define MAX_TRACE
Definition: debug.h:16
#define NDIS_DbgPrint(_t_, _x_)
Definition: debug.h:40
struct _NDIS_PACKET * PNDIS_PACKET
#define NDIS_STATUS_RESOURCES
Definition: ndis.h:466
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define MIN_TRACE
Definition: debug.h:14
#define NDIS_STATUS_FAILURE
Definition: ndis.h:465

Referenced by NdisAllocatePacket(), and NdisDprAllocatePacket().

◆ NdisDprFreePacket()

VOID EXPORT NdisDprFreePacket ( IN PNDIS_PACKET  Packet)

Definition at line 734 of file buffer.c.

741 {
743 
744  KeAcquireSpinLockAtDpcLevel(&Pool->SpinLock.SpinLock);
746  KeReleaseSpinLockFromDpcLevel(&Pool->SpinLock.SpinLock);
747 }
VOID EXPORT NdisDprFreePacketNonInterlocked(IN PNDIS_PACKET Packet)
Definition: buffer.c:755
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
VOID NTAPI KeAcquireSpinLockAtDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:192
struct _NDISI_PACKET_POOL * PNDISI_PACKET_POOL
VOID NTAPI KeReleaseSpinLockFromDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:215
Definition: bufpool.h:50

◆ NdisDprFreePacketNonInterlocked()

VOID EXPORT NdisDprFreePacketNonInterlocked ( IN PNDIS_PACKET  Packet)

Definition at line 755 of file buffer.c.

762 {
763  NDIS_DbgPrint(MAX_TRACE, ("Packet (0x%X).\n", Packet));
764 
765  Packet->Reserved[0] = (ULONG_PTR)((NDISI_PACKET_POOL*)Packet->Private.Pool)->FreeList;
766  ((NDISI_PACKET_POOL*)Packet->Private.Pool)->FreeList = Packet;
767 }
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
MmuFreePage * FreeList
Definition: mmuobject.c:60
#define MAX_TRACE
Definition: debug.h:16
#define NDIS_DbgPrint(_t_, _x_)
Definition: debug.h:40
#define ULONG_PTR
Definition: config.h:101

Referenced by NdisDprFreePacket(), and NdisFreePacket().

◆ NdisFreeBuffer()

VOID EXPORT NdisFreeBuffer ( IN PNDIS_BUFFER  Buffer)

Definition at line 809 of file buffer.c.

816 {
817  IoFreeMdl(Buffer);
818 }
Definition: bufpool.h:45
VOID NTAPI IoFreeMdl(PMDL Mdl)
Definition: iomdl.c:146

Referenced by CleanupAndFreePacket(), FreeNdisPacket(), and FreeNdisPacketX().

◆ NdisFreeBufferPool()

VOID EXPORT NdisFreeBufferPool ( IN NDIS_HANDLE  PoolHandle)

Definition at line 775 of file buffer.c.

782 {
783 }

Referenced by BindAdapterByName(), CloseNdisPools(), and TiUnload().

◆ NdisFreePacket()

VOID EXPORT NdisFreePacket ( IN PNDIS_PACKET  Packet)

Definition at line 826 of file buffer.c.

833 {
835 
836  KeAcquireSpinLock(&Pool->SpinLock.SpinLock, &Pool->SpinLock.OldIrql);
838  KeReleaseSpinLock(&Pool->SpinLock.SpinLock, Pool->SpinLock.OldIrql);
839 }
VOID EXPORT NdisDprFreePacketNonInterlocked(IN PNDIS_PACKET Packet)
Definition: buffer.c:755
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
struct _NDISI_PACKET_POOL * PNDISI_PACKET_POOL
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
Definition: bufpool.h:50
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627

Referenced by CleanupAndFreePacket(), CreatePacketFromPoolBuffer(), FreeNdisPacket(), and FreeNdisPacketX().

◆ NdisFreePacketPool()

VOID EXPORT NdisFreePacketPool ( IN NDIS_HANDLE  PoolHandle)

Definition at line 791 of file buffer.c.

798 {
800 }
_Out_ PNDIS_BUFFER _In_opt_ NDIS_HANDLE PoolHandle
Definition: ndis.h:2867
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by BindAdapterByName(), CloseNdisPools(), InitNdisPools(), and TiUnload().

◆ NdisGetBufferPhysicalArraySize()

VOID EXPORT NdisGetBufferPhysicalArraySize ( IN PNDIS_BUFFER  Buffer,
OUT PUINT  ArraySize 
)

Definition at line 848 of file buffer.c.

857 {
859  ASSERT(Buffer && ArraySize);
860 
861  *ArraySize = NDIS_BUFFER_TO_SPAN_PAGES(Buffer);
862 }
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
Definition: bufpool.h:45
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
ULONG EXPORT NDIS_BUFFER_TO_SPAN_PAGES(IN PNDIS_BUFFER Buffer)
Definition: buffer.c:312

◆ NdisGetFirstBufferFromPacket()

VOID EXPORT NdisGetFirstBufferFromPacket ( IN PNDIS_PACKET  _Packet,
OUT PNDIS_BUFFER _FirstBuffer,
OUT PVOID _FirstBufferVA,
OUT PUINT  _FirstBufferLength,
OUT PUINT  _TotalBufferLength 
)

Definition at line 871 of file buffer.c.

886 {
888 
889  Buffer = _Packet->Private.Head;
890  *_FirstBuffer = Buffer;
891 
892  if (Buffer != NULL) {
893  *_FirstBufferLength = MmGetMdlByteCount(Buffer);
894  *_FirstBufferVA = MmGetSystemAddressForMdl(Buffer);
895  Buffer = Buffer->Next;
896  } else {
897  NDIS_DbgPrint(MID_TRACE, ("No buffers linked to this packet\n"));
898  *_FirstBufferLength = 0;
899  *_FirstBufferVA = NULL;
900  }
901 
902  *_TotalBufferLength = *_FirstBufferLength;
903 
904  while (Buffer != NULL) {
905  *_TotalBufferLength += MmGetMdlByteCount(Buffer);
906  Buffer = Buffer->Next;
907  }
908 }
#define MID_TRACE
Definition: debug.h:15
MDL * PNDIS_BUFFER
Definition: ndis.h:343
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
static UCHAR _Packet[1024]
Definition: pxe.c:34
#define MmGetMdlByteCount(_Mdl)
#define NDIS_DbgPrint(_t_, _x_)
Definition: debug.h:40
#define MmGetSystemAddressForMdl(Mdl)
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34

Referenced by CopyPacketToBuffer(), CopyPacketToBufferChain(), MiniIndicateReceivePacket(), NdisCopyFromPacketToPacket(), and ProtocolTransferDataComplete().

◆ NdisGetFirstBufferFromPacketSafe()

VOID EXPORT NdisGetFirstBufferFromPacketSafe ( IN PNDIS_PACKET  _Packet,
OUT PNDIS_BUFFER _FirstBuffer,
OUT PVOID _FirstBufferVA,
OUT PUINT  _FirstBufferLength,
OUT PUINT  _TotalBufferLength,
IN MM_PAGE_PRIORITY  Priority 
)

Definition at line 916 of file buffer.c.

923 {
925 
926  Buffer = _Packet->Private.Head;
927  *_FirstBuffer = Buffer;
928 
929  if (Buffer != NULL) {
930  *_FirstBufferLength = MmGetMdlByteCount(Buffer);
931  *_FirstBufferVA = MmGetSystemAddressForMdlSafe(Buffer, Priority);
932  Buffer = Buffer->Next;
933  } else {
934  NDIS_DbgPrint(MID_TRACE, ("No buffers linked to this packet\n"));
935  *_FirstBufferLength = 0;
936  *_FirstBufferVA = NULL;
937  }
938 
939  *_TotalBufferLength = *_FirstBufferLength;
940 
941  while (Buffer != NULL) {
942  *_TotalBufferLength += MmGetMdlByteCount(Buffer);
943  Buffer = Buffer->Next;
944  }
945 }
#define MID_TRACE
Definition: debug.h:15
MDL * PNDIS_BUFFER
Definition: ndis.h:343
_In_ KPRIORITY Priority
Definition: kefuncs.h:516
#define MmGetSystemAddressForMdlSafe(_Mdl, _Priority)
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
static UCHAR _Packet[1024]
Definition: pxe.c:34
#define MmGetMdlByteCount(_Mdl)
#define NDIS_DbgPrint(_t_, _x_)
Definition: debug.h:40
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34

Referenced by MiniportSend(), and NdisCopyFromPacketToPacketSafe().

◆ NdisGetPacketCancelId()

PVOID EXPORT NdisGetPacketCancelId ( IN PNDIS_PACKET  Packet)

Definition at line 1176 of file buffer.c.

1178 {
1180 }
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
#define NDIS_GET_PACKET_CANCEL_ID(Packet)
Definition: ndis.h:1333

◆ NdisGetPoolFromPacket()

NDIS_HANDLE EXPORT NdisGetPoolFromPacket ( IN PNDIS_PACKET  Packet)

Definition at line 1152 of file buffer.c.

1154 {
1155  return Packet->Private.Pool;
1156 }
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548

◆ NdisIMCopySendCompletePerPacketInfo()

VOID EXPORT NdisIMCopySendCompletePerPacketInfo ( IN PNDIS_PACKET  DstPacket,
IN PNDIS_PACKET  SrcPacket 
)

Definition at line 1279 of file buffer.c.

1288 {
1289  /* FIXME: What is the difference between NdisIMCopySendPerPacketInfo and
1290  * NdisIMCopySendCompletePerPacketInfo?
1291  */
1292 
1293  NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
1294 
1297  sizeof(NDIS_PACKET_EXTENSION));
1298 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define MAX_TRACE
Definition: debug.h:16
#define NDIS_DbgPrint(_t_, _x_)
Definition: debug.h:40
#define NDIS_PACKET_EXTENSION_FROM_PACKET(Packet)
Definition: ndis.h:1341

◆ NdisIMCopySendPerPacketInfo()

VOID EXPORT NdisIMCopySendPerPacketInfo ( IN PNDIS_PACKET  DstPacket,
IN PNDIS_PACKET  SrcPacket 
)

Definition at line 1306 of file buffer.c.

1315 {
1316  /* FIXME: What is the difference between NdisIMCopySendPerPacketInfo and
1317  * NdisIMCopySendCompletePerPacketInfo?
1318  */
1319 
1320  NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
1321 
1324  sizeof(NDIS_PACKET_EXTENSION));
1325 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define MAX_TRACE
Definition: debug.h:16
#define NDIS_DbgPrint(_t_, _x_)
Definition: debug.h:40
#define NDIS_PACKET_EXTENSION_FROM_PACKET(Packet)
Definition: ndis.h:1341

◆ NdisPacketSize()

UINT EXPORT NdisPacketSize ( IN UINT  ProtocolReservedSize)

Definition at line 1163 of file buffer.c.

1165 {
1166  return sizeof(NDIS_PACKET) + sizeof(NDIS_PACKET_OOB_DATA) +
1167  sizeof(NDIS_PACKET_EXTENSION) + ProtocolReservedSize;
1168 }
struct _NDIS_PACKET_EXTENSION NDIS_PACKET_EXTENSION
struct _NDIS_PACKET NDIS_PACKET

◆ NdisQueryBuffer()

VOID EXPORT NdisQueryBuffer ( IN PNDIS_BUFFER  Buffer,
OUT PVOID *VirtualAddress  OPTIONAL,
OUT PUINT  Length 
)

◆ NdisQueryBufferOffset()

VOID EXPORT NdisQueryBufferOffset ( IN PNDIS_BUFFER  Buffer,
OUT PUINT  Offset,
OUT PUINT  Length 
)

Definition at line 1003 of file buffer.c.

1007 {
1010 }
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
Definition: bufpool.h:45
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define MmGetMdlByteCount(_Mdl)
#define MmGetMdlByteOffset(_Mdl)
unsigned int * PUINT
Definition: ndis.h:50

◆ NdisQueryBufferSafe()

VOID EXPORT NdisQueryBufferSafe ( IN PNDIS_BUFFER  Buffer,
OUT PVOID *VirtualAddress  OPTIONAL,
OUT PUINT  Length,
IN UINT  Priority 
)

Definition at line 979 of file buffer.c.

990 {
991  if (VirtualAddress != NULL)
994 }
_In_ KPRIORITY Priority
Definition: kefuncs.h:516
#define MmGetSystemAddressForMdlSafe(_Mdl, _Priority)
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
_In_ ULONG _In_ BOOLEAN _Must_inspect_result_ PVOID * VirtualAddress
Definition: ndis.h:3791
#define MmGetMdlByteCount(_Mdl)

Referenced by NdisCopyFromPacketToPacketSafe().

◆ NdisSetPacketCancelId()

VOID EXPORT NdisSetPacketCancelId ( IN PNDIS_PACKET  Packet,
IN PVOID  CancelId 
)

Definition at line 1188 of file buffer.c.

1191 {
1193 }
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
LONG CancelId
Definition: main.c:23
#define NDIS_SET_PACKET_CANCEL_ID(Packet, CancelId)
Definition: ndis.h:1370

◆ NdisUnchainBufferAtBack()

VOID EXPORT NdisUnchainBufferAtBack ( IN OUT PNDIS_PACKET  Packet,
OUT PNDIS_BUFFER Buffer 
)

Definition at line 1018 of file buffer.c.

1028 {
1029  PNDIS_BUFFER NdisBuffer, Previous;
1030 
1032  NULL,
1033  NULL,
1034  &NdisBuffer,
1035  NULL);
1036  if (!NdisBuffer) {
1037  NDIS_DbgPrint(MID_TRACE, ("No buffer to unchain\n"));
1038  *Buffer = NULL;
1039  return;
1040  }
1041 
1042  Previous = NULL;
1043  while (NdisBuffer->Next) {
1044  Previous = NdisBuffer;
1045  NdisBuffer = NdisBuffer->Next;
1046  }
1047 
1048  if (Previous) {
1049  Previous->Next = NULL;
1050  Packet->Private.Tail = Previous;
1051  } else {
1052  Packet->Private.Head = NULL;
1053  Packet->Private.Tail = NULL;
1054  }
1055 
1056  Packet->Private.ValidCounts = FALSE;
1057 
1058  *Buffer = NdisBuffer;
1059 }
#define MID_TRACE
Definition: debug.h:15
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
MDL * PNDIS_BUFFER
Definition: ndis.h:343
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
#define NDIS_DbgPrint(_t_, _x_)
Definition: debug.h:40
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

◆ NdisUnchainBufferAtFront()

VOID EXPORT NdisUnchainBufferAtFront ( IN OUT PNDIS_PACKET  Packet,
OUT PNDIS_BUFFER Buffer 
)

Definition at line 1067 of file buffer.c.

1077 {
1078  PNDIS_BUFFER NdisBuffer;
1079 
1081  NULL,
1082  NULL,
1083  &NdisBuffer,
1084  NULL);
1085  if (!NdisBuffer) {
1086  NDIS_DbgPrint(MID_TRACE, ("No buffer to unchain\n"));
1087  *Buffer = NULL;
1088  return;
1089  }
1090 
1091  Packet->Private.Head = NdisBuffer->Next;
1092 
1093  if (!NdisBuffer->Next)
1094  Packet->Private.Tail = NULL;
1095 
1096  NdisBuffer->Next = NULL;
1097 
1098  Packet->Private.ValidCounts = FALSE;
1099 
1100  *Buffer = NdisBuffer;
1101 }
#define MID_TRACE
Definition: debug.h:15
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
MDL * PNDIS_BUFFER
Definition: ndis.h:343
smooth NULL
Definition: ftsmooth.c:416
Definition: bufpool.h:45
#define NDIS_DbgPrint(_t_, _x_)
Definition: debug.h:40
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

Referenced by CleanupAndFreePacket().

◆ SkipToOffset()

__inline ULONG SkipToOffset ( IN PNDIS_BUFFER  Buffer,
IN UINT  Offset,
IN OUT PUCHAR Data,
IN OUT PUINT  Size 
)

Definition at line 13 of file buffer.c.

32 {
33  for (;;) {
34 
35  if (!Buffer)
36  return 0xFFFFFFFF;
37 
39 
40  if (Offset < *Size) {
41  *Data = (PUCHAR) ((ULONG_PTR) *Data + Offset);
42  *Size -= Offset;
43  break;
44  }
45 
46  Offset -= *Size;
47 
49  }
50 
51  return Offset;
52 }
unsigned char * PUCHAR
Definition: retypes.h:3
#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
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 CopyBufferChainToBuffer(), CopyBufferToBufferChain(), CopyPacketToBufferChain(), GetDataPtr(), NdisCopyFromPacketToPacket(), and NdisCopyFromPacketToPacketSafe().