ReactOS  0.4.15-dev-3181-g4acf100
buffer.c File Reference
#include <ndissys.h>
Include dependency graph for buffer.c:

Go to the source code of this file.

Functions

FORCEINLINE 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 113 of file buffer.c.

131 {
132  UINT BytesCopied, BytesToCopy, SrcSize;
133  PUCHAR SrcData;
134 
135  NDIS_DbgPrint(MAX_TRACE, ("DstData 0x%X SrcBuffer 0x%X SrcOffset 0x%X Length %d\n",DstData,SrcBuffer, SrcOffset, Length));
136 
137  /* Skip SrcOffset bytes in the source buffer chain */
138  if (SkipToOffset(SrcBuffer, SrcOffset, &SrcData, &SrcSize) == 0xFFFFFFFF)
139  return 0;
140 
141  /* Start copying the data */
142  BytesCopied = 0;
143  for (;;) {
144  BytesToCopy = MIN(SrcSize, Length);
145 
146  NDIS_DbgPrint(MAX_TRACE, ("Copying (%d) bytes from 0x%X to 0x%X\n", BytesToCopy, SrcData, DstData));
147 
148  RtlCopyMemory((PVOID)DstData, (PVOID)SrcData, BytesToCopy);
150  DstData = (PUCHAR)((ULONG_PTR) DstData + BytesToCopy);
151 
152  Length -= BytesToCopy;
153  if (Length == 0)
154  break;
155 
156  SrcSize -= BytesToCopy;
157  if (SrcSize == 0) {
158  /* No more bytes in source buffer. Proceed to
159  the next buffer in the source buffer chain */
160  NdisGetNextBuffer(SrcBuffer, &SrcBuffer);
161  if (!SrcBuffer)
162  break;
163 
164  NdisQueryBuffer(SrcBuffer, (PVOID)&SrcData, &SrcSize);
165  }
166  }
167 
168  return BytesCopied;
169 }
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
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:65
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
#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:955
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
FORCEINLINE ULONG SkipToOffset(IN PNDIS_BUFFER Buffer, IN UINT Offset, IN OUT PUCHAR *Data, IN OUT PUINT Size)
Definition: buffer.c:15

Referenced by CopyPacketToBuffer(), and MiniIndicateReceivePacket().

◆ CopyBufferToBufferChain()

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

Definition at line 56 of file buffer.c.

74 {
75  UINT BytesCopied, BytesToCopy, DstSize;
76  PUCHAR DstData;
77 
78  NDIS_DbgPrint(MAX_TRACE, ("DstBuffer (0x%X) DstOffset (0x%X) SrcData (0x%X) Length (%d)\n", DstBuffer, DstOffset, SrcData, Length));
79 
80  /* Skip DstOffset bytes in the destination buffer chain */
81  if (SkipToOffset(DstBuffer, DstOffset, &DstData, &DstSize) == 0xFFFFFFFF)
82  return 0;
83 
84  /* Start copying the data */
85  BytesCopied = 0;
86  for (;;) {
87  BytesToCopy = MIN(DstSize, Length);
88 
89  RtlCopyMemory((PVOID)DstData, (PVOID)SrcData, BytesToCopy);
91  SrcData = (PUCHAR) ((ULONG_PTR) SrcData + BytesToCopy);
92 
94  if (Length == 0)
95  break;
96 
97  DstSize -= BytesToCopy;
98  if (DstSize == 0) {
99  /* No more bytes in destination buffer. Proceed to
100  the next buffer in the destination buffer chain */
101  NdisGetNextBuffer(DstBuffer, &DstBuffer);
102  if (!DstBuffer)
103  break;
104 
105  NdisQueryBuffer(DstBuffer, (PVOID)&DstData, &DstSize);
106  }
107  }
108 
109  return BytesCopied;
110 }
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
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:65
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
#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:955
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
FORCEINLINE ULONG SkipToOffset(IN PNDIS_BUFFER Buffer, IN UINT Offset, IN OUT PUCHAR *Data, IN OUT PUINT Size)
Definition: buffer.c:15

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

◆ CopyPacketToBuffer()

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

Definition at line 172 of file buffer.c.

190 {
191  PNDIS_BUFFER FirstBuffer;
192  PVOID Address;
193  UINT FirstLength;
195 
196  NDIS_DbgPrint(MAX_TRACE, ("DstData (0x%X) SrcPacket (0x%X) SrcOffset (0x%X) Length (%d)\n", DstData, SrcPacket, SrcOffset, Length));
197 
199  &FirstBuffer,
200  &Address,
201  &FirstLength,
202  &TotalLength);
203 
204  return CopyBufferChainToBuffer(DstData, FirstBuffer, SrcOffset, Length);
205 }
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
MDL * PNDIS_BUFFER
Definition: ndis.h:343
_In_ ULONG TotalLength
Definition: usbdlib.h:158
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:873
#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:113

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 208 of file buffer.c.

228 {
229  PNDIS_BUFFER SrcBuffer;
230  PUCHAR DstData, SrcData;
231  UINT DstSize, SrcSize;
232  UINT Count, Total;
233 
234  NDIS_DbgPrint(MAX_TRACE, ("DstBuffer (0x%X) DstOffset (0x%X) SrcPacket (0x%X) SrcOffset (0x%X) Length (%d)\n", DstBuffer, DstOffset, SrcPacket, SrcOffset, Length));
235 
236  /* Skip DstOffset bytes in the destination buffer chain */
237  NdisQueryBuffer(DstBuffer, (PVOID)&DstData, &DstSize);
238  if (SkipToOffset(DstBuffer, DstOffset, &DstData, &DstSize) == 0xFFFFFFFF)
239  return 0;
240  /* Skip SrcOffset bytes in the source packet */
241  NdisGetFirstBufferFromPacket(SrcPacket, &SrcBuffer, (PVOID*)&SrcData, &SrcSize, &Total);
242  if (SkipToOffset(SrcBuffer, SrcOffset, &SrcData, &SrcSize) == 0xFFFFFFFF)
243  return 0;
244  /* Copy the data */
245  for (Total = 0;;) {
246  /* Find out how many bytes we can copy at one time */
247  if (Length < SrcSize)
248  Count = Length;
249  else
250  Count = SrcSize;
251  if (DstSize < Count)
252  Count = DstSize;
253 
254  RtlCopyMemory((PVOID)DstData, (PVOID)SrcData, Count);
255 
256  Total += Count;
257  Length -= Count;
258  if (Length == 0)
259  break;
260 
261  DstSize -= Count;
262  if (DstSize == 0) {
263  /* No more bytes in destination buffer. Proceed to
264  the next buffer in the destination buffer chain */
265  NdisGetNextBuffer(DstBuffer, &DstBuffer);
266  if (!DstBuffer)
267  break;
268 
269  NdisQueryBuffer(DstBuffer, (PVOID)&DstData, &DstSize);
270  }
271 
272  SrcSize -= Count;
273  if (SrcSize == 0) {
274  /* No more bytes in source buffer. Proceed to
275  the next buffer in the source buffer chain */
276  NdisGetNextBuffer(SrcBuffer, &SrcBuffer);
277  if (!SrcBuffer)
278  break;
279 
280  NdisQueryBuffer(SrcBuffer, (PVOID)&SrcData, &SrcSize);
281  }
282  }
283 
284  return Total;
285 }
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
MDL * PNDIS_BUFFER
Definition: ndis.h:343
unsigned char * PUCHAR
Definition: retypes.h:3
#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:873
int Count
Definition: noreturn.cpp:7
#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:955
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
FORCEINLINE ULONG SkipToOffset(IN PNDIS_BUFFER Buffer, IN UINT Offset, IN OUT PUCHAR *Data, IN OUT PUINT Size)
Definition: buffer.c:15

◆ NDIS_BUFFER_TO_SPAN_PAGES()

ULONG EXPORT NDIS_BUFFER_TO_SPAN_PAGES ( IN PNDIS_BUFFER  Buffer)

Definition at line 314 of file buffer.c.

321 {
322  if (MmGetMdlByteCount(Buffer) == 0)
323  return 1;
324 
328 }
#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 294 of file buffer.c.

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

Referenced by ParaNdis_IndicateReceivedPacket(), and ParaNdis_UnbindBufferFromPacket().

◆ 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 336 of file buffer.c.

351 {
353  ASSERT(Length > 0);
354 
356  if (*Buffer != NULL) {
358  (*Buffer)->Next = NULL;
360  } else {
361  NDIS_DbgPrint(MIN_TRACE, ("IoAllocateMdl failed (%x, %lx)\n", VirtualAddress, Length));
363  }
364 }
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
VOID NTAPI MmBuildMdlForNonPagedPool(IN PMDL Mdl)
Definition: mdlsup.c:415
#define FALSE
Definition: types.h:117
Definition: bufpool.h:45
_Must_inspect_result_ _In_ WDFDMATRANSACTION _In_ PFN_WDF_PROGRAM_DMA _In_ WDF_DMA_DIRECTION _In_ PMDL _In_ PVOID VirtualAddress
Status
Definition: gdiplustypes.h:24
#define ASSERT(a)
Definition: mode.c:44
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
PMDL NTAPI IoAllocateMdl(IN PVOID VirtualAddress, IN ULONG Length, IN BOOLEAN SecondaryBuffer, IN BOOLEAN ChargeQuota, IN PIRP Irp)
Definition: iomdl.c:22
#define NULL
Definition: types.h:112
#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(), ParaNdis_BindBufferToPacket(), and PrependPacket().

◆ NdisAllocateBufferPool()

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

Definition at line 372 of file buffer.c.

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

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

◆ NdisAllocatePacket()

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

Definition at line 394 of file buffer.c.

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

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

◆ NdisAllocatePacketPool()

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

Definition at line 421 of file buffer.c.

434 {
436  Status,
437  PoolHandle,
439  0,
441 }
_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:449

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

◆ NdisAllocatePacketPoolEx()

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

Definition at line 449 of file buffer.c.

461 {
463  UINT Size, Length, i;
464  PNDIS_PACKET Packet, NextPacket;
465 
466  NDIS_DbgPrint(MAX_TRACE, ("Status (0x%X) PoolHandle (0x%X) "
467  "NumberOfDescriptors (%d) ProtocolReservedLength (%d).\n",
469 
470  *PoolHandle = NULL;
471 
472  if (NumberOfDescriptors > 0xffff)
473  {
474  NDIS_DbgPrint(MIN_TRACE, ("Invalid number of descriptors (%lx)\n", NumberOfDescriptors))
476  }
477  else
478  {
480  if (NumberOfDescriptors > 0xffff)
481  {
482  NDIS_DbgPrint(MIN_TRACE, ("Total number of descriptors > 0xffff (%lx)\n", NumberOfDescriptors));
483  NumberOfDescriptors = 0xffff;
484  }
485 
486  Length = sizeof(NDIS_PACKET) + sizeof(NDIS_PACKET_OOB_DATA) +
489 
491  if (Pool)
492  {
493  KeInitializeSpinLock(&Pool->SpinLock.SpinLock);
494  Pool->PacketLength = Length;
495 
496  if (NumberOfDescriptors > 0)
497  {
498  Packet = (PNDIS_PACKET)&Pool->Buffer;
499  Pool->FreeList = Packet;
500 
501  NextPacket = (PNDIS_PACKET)((ULONG_PTR)Packet + Length);
502  for (i = 1; i < NumberOfDescriptors; i++)
503  {
504  Packet->Reserved[0] = (ULONG_PTR)NextPacket;
505  Packet = NextPacket;
506  NextPacket = (PNDIS_PACKET)((ULONG_PTR)Packet + Length);
507  }
508  Packet->Reserved[0] = 0;
509  }
510  else {
511  NDIS_DbgPrint(MIN_TRACE, ("Attempted to allocate a packet pool with 0 descriptors\n"));
512  Pool->FreeList = NULL;
513  }
514 
517  } else {
519  }
520  }
521 }
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
_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
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
_Out_ PNDIS_HANDLE _In_ UINT NumberOfDescriptors
Definition: ndis.h:2878
uint32_t ULONG_PTR
Definition: typedefs.h:65
_Out_ PNDIS_BUFFER _In_opt_ NDIS_HANDLE PoolHandle
Definition: ndis.h:2867
FORCEINLINE VOID KeInitializeSpinLock(_Out_ PKSPIN_LOCK SpinLock)
Definition: kefuncs.h:238
Status
Definition: gdiplustypes.h:24
Definition: bufpool.h:50
struct _NDIS_PACKET_EXTENSION NDIS_PACKET_EXTENSION
struct _NDIS_PACKET NDIS_PACKET
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
#define MAX_TRACE
Definition: debug.h:16
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
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
#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 530 of file buffer.c.

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

◆ NdisBufferVirtualAddress()

PVOID EXPORT NdisBufferVirtualAddress ( IN PNDIS_BUFFER  Buffer)

Definition at line 553 of file buffer.c.

561 {
563 }
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 1110 of file buffer.c.

1127 {
1129 
1130  NDIS_DbgPrint(MAX_TRACE, ("Called\n"));
1131 
1132  *Buffer = IoAllocateMdl(CurrentVa, Length, FALSE, FALSE, NULL);
1133  if (!*Buffer)
1134  {
1135  NDIS_DbgPrint(MIN_TRACE, ("IoAllocateMdl failed (%x, %lx)\n", CurrentVa, Length));
1137  return;
1138  }
1139 
1141  *Buffer,
1142  CurrentVa,
1143  Length);
1144 
1145  (*Buffer)->Next = NULL;
1147 }
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define MmGetMdlVirtualAddress(_Mdl)
MDL * PNDIS_BUFFER
Definition: ndis.h:343
unsigned char * PUCHAR
Definition: retypes.h:3
_Must_inspect_result_ _In_ WDFUSBDEVICE _In_opt_ WDFREQUEST _In_opt_ PWDF_REQUEST_SEND_OPTIONS _In_ PWDF_USB_CONTROL_SETUP_PACKET _In_opt_ PWDF_MEMORY_DESCRIPTOR MemoryDescriptor
Definition: wdfusb.h:1331
VOID NTAPI IoBuildPartialMdl(IN PMDL SourceMdl, IN PMDL TargetMdl, IN PVOID VirtualAddress, IN ULONG Length)
Definition: iomdl.c:96
#define FALSE
Definition: types.h:117
Definition: bufpool.h:45
Status
Definition: gdiplustypes.h:24
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
PMDL NTAPI IoAllocateMdl(IN PVOID VirtualAddress, IN ULONG Length, IN BOOLEAN SecondaryBuffer, IN BOOLEAN ChargeQuota, IN PIRP Irp)
Definition: iomdl.c:22
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define MAX_TRACE
Definition: debug.h:16
#define NULL
Definition: types.h:112
#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 571 of file buffer.c.

588 {
589  PNDIS_BUFFER SrcBuffer;
590  PNDIS_BUFFER DstBuffer;
591  PUCHAR DstData, SrcData;
592  UINT DstSize, SrcSize;
593  UINT Count, Total;
594 
595  *BytesCopied = 0;
596 
597  /* Skip DestinationOffset bytes in the destination packet */
598  NdisGetFirstBufferFromPacket(Destination, &DstBuffer, (PVOID*)&DstData, &DstSize, &Total);
599  if (SkipToOffset(DstBuffer, DestinationOffset, &DstData, &DstSize) == 0xFFFFFFFF)
600  return;
601 
602  /* Skip SourceOffset bytes in the source packet */
603  NdisGetFirstBufferFromPacket(Source, &SrcBuffer, (PVOID*)&SrcData, &SrcSize, &Total);
604  if (SkipToOffset(SrcBuffer, SourceOffset, &SrcData, &SrcSize) == 0xFFFFFFFF)
605  return;
606 
607  /* Copy the data */
608  for (Total = 0;;) {
609  /* Find out how many bytes we can copy at one time */
610  if (BytesToCopy < SrcSize)
611  Count = BytesToCopy;
612  else
613  Count = SrcSize;
614  if (DstSize < Count)
615  Count = DstSize;
616 
617  RtlCopyMemory(DstData, SrcData, Count);
618 
619  Total += Count;
620  BytesToCopy -= Count;
621  if (BytesToCopy == 0)
622  break;
623 
624  DstSize -= Count;
625  if (DstSize == 0) {
626  /* No more bytes in destination buffer. Proceed to
627  the next buffer in the destination buffer chain */
628  NdisGetNextBuffer(DstBuffer, &DstBuffer);
629  if (!DstBuffer)
630  break;
631 
632  NdisQueryBuffer(DstBuffer, (PVOID)&DstData, &DstSize);
633  }
634 
635  SrcSize -= Count;
636  if (SrcSize == 0) {
637  /* No more bytes in source buffer. Proceed to
638  the next buffer in the source buffer chain */
639  NdisGetNextBuffer(SrcBuffer, &SrcBuffer);
640  if (!SrcBuffer)
641  break;
642 
643  NdisQueryBuffer(SrcBuffer, (PVOID)&SrcData, &SrcSize);
644  }
645  }
646 
647  *BytesCopied = Total;
648 }
MDL * PNDIS_BUFFER
Definition: ndis.h:343
unsigned char * PUCHAR
Definition: retypes.h:3
_Must_inspect_result_ _In_ WDFMEMORY _In_ size_t SourceOffset
Definition: wdfmemory.h:318
_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:873
int Count
Definition: noreturn.cpp:7
_In_ PUNICODE_STRING _Inout_ PUNICODE_STRING Destination
Definition: rtlfuncs.h:2950
unsigned int UINT
Definition: ndis.h:50
_Must_inspect_result_ _In_ WDFMEMORY _In_ size_t DestinationOffset
Definition: wdfmemory.h:359
VOID EXPORT NdisQueryBuffer(IN PNDIS_BUFFER Buffer, OUT PVOID *VirtualAddress OPTIONAL, OUT PUINT Length)
Definition: buffer.c:955
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3167
FORCEINLINE ULONG SkipToOffset(IN PNDIS_BUFFER Buffer, IN UINT Offset, IN OUT PUCHAR *Data, IN OUT PUINT Size)
Definition: buffer.c:15

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 1202 of file buffer.c.

1210 {
1211  PNDIS_BUFFER SrcBuffer;
1212  PNDIS_BUFFER DstBuffer;
1213  PUCHAR DstData, SrcData;
1214  UINT DstSize, SrcSize;
1215  UINT Count, Total;
1216 
1217  *BytesCopied = 0;
1218 
1219  /* Skip DestinationOffset bytes in the destination packet */
1220  NdisGetFirstBufferFromPacketSafe(Destination, &DstBuffer, (PVOID*)&DstData, &DstSize, &Total, Priority);
1221  if (!DstData || SkipToOffset(DstBuffer, DestinationOffset, &DstData, &DstSize) == 0xFFFFFFFF)
1222  return;
1223 
1224  /* Skip SourceOffset bytes in the source packet */
1225  NdisGetFirstBufferFromPacketSafe(Source, &SrcBuffer, (PVOID*)&SrcData, &SrcSize, &Total, Priority);
1226  if (!SrcData || SkipToOffset(SrcBuffer, SourceOffset, &SrcData, &SrcSize) == 0xFFFFFFFF)
1227  return;
1228 
1229  /* Copy the data */
1230  for (Total = 0;;) {
1231  /* Find out how many bytes we can copy at one time */
1232  if (BytesToCopy < SrcSize)
1233  Count = BytesToCopy;
1234  else
1235  Count = SrcSize;
1236  if (DstSize < Count)
1237  Count = DstSize;
1238 
1239  RtlCopyMemory(DstData, SrcData, Count);
1240 
1241  Total += Count;
1242  BytesToCopy -= Count;
1243  if (BytesToCopy == 0)
1244  break;
1245 
1246  DstSize -= Count;
1247  if (DstSize == 0) {
1248  /* No more bytes in destination buffer. Proceed to
1249  the next buffer in the destination buffer chain */
1250  NdisGetNextBuffer(DstBuffer, &DstBuffer);
1251  if (!DstBuffer)
1252  break;
1253 
1254  NdisQueryBufferSafe(DstBuffer, (PVOID)&DstData, &DstSize, Priority);
1255  if (!DstData)
1256  break;
1257  }
1258 
1259  SrcSize -= Count;
1260  if (SrcSize == 0) {
1261  /* No more bytes in source buffer. Proceed to
1262  the next buffer in the source buffer chain */
1263  NdisGetNextBuffer(SrcBuffer, &SrcBuffer);
1264  if (!SrcBuffer)
1265  break;
1266 
1267  NdisQueryBufferSafe(SrcBuffer, (PVOID)&SrcData, &SrcSize, Priority);
1268  if (!SrcData)
1269  break;
1270  }
1271  }
1272 
1273  *BytesCopied = Total;
1274 }
MDL * PNDIS_BUFFER
Definition: ndis.h:343
unsigned char * PUCHAR
Definition: retypes.h:3
_Must_inspect_result_ _In_ WDFMEMORY _In_ size_t SourceOffset
Definition: wdfmemory.h:318
_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:918
int Count
Definition: noreturn.cpp:7
_In_ PUNICODE_STRING _Inout_ PUNICODE_STRING Destination
Definition: rtlfuncs.h:2950
_In_ WDFINTERRUPT _In_ WDF_INTERRUPT_POLICY _In_ WDF_INTERRUPT_PRIORITY Priority
Definition: wdfinterrupt.h:651
VOID EXPORT NdisQueryBufferSafe(IN PNDIS_BUFFER Buffer, OUT PVOID *VirtualAddress OPTIONAL, OUT PUINT Length, IN UINT Priority)
Definition: buffer.c:981
unsigned int UINT
Definition: ndis.h:50
_Must_inspect_result_ _In_ WDFMEMORY _In_ size_t DestinationOffset
Definition: wdfmemory.h:359
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3167
FORCEINLINE ULONG SkipToOffset(IN PNDIS_BUFFER Buffer, IN UINT Offset, IN OUT PUCHAR *Data, IN OUT PUINT Size)
Definition: buffer.c:15

◆ NdisDprAllocatePacket()

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

Definition at line 656 of file buffer.c.

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

◆ NdisDprAllocatePacketNonInterlocked()

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

Definition at line 683 of file buffer.c.

694 {
695  PNDIS_PACKET Temp;
697 
698  NDIS_DbgPrint(MAX_TRACE, ("Status (0x%X) Packet (0x%X) PoolHandle (0x%X).\n",
700 
701  *Packet = NULL;
702 
703  if (Pool == NULL)
704  {
706  NDIS_DbgPrint(MIN_TRACE, ("Called passed a bad pool handle\n"));
707  return;
708  }
709 
710  if (Pool->FreeList) {
711  Temp = Pool->FreeList;
712  Pool->FreeList = (PNDIS_PACKET)Temp->Reserved[0];
713 
714  RtlZeroMemory(Temp, Pool->PacketLength);
715  Temp->Private.Pool = Pool;
716  Temp->Private.ValidCounts = TRUE;
718  Temp->Private.NdisPacketOobOffset = Pool->PacketLength -
719  (sizeof(NDIS_PACKET_OOB_DATA) +
720  sizeof(NDIS_PACKET_EXTENSION));
721 
722  *Packet = Temp;
724  } else {
725  NDIS_DbgPrint(MIN_TRACE, ("No more free descriptors\n"));
727  }
728 }
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
#define TRUE
Definition: types.h:120
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
PNDIS_PACKET_POOL Pool
Definition: ndis.h:726
Status
Definition: gdiplustypes.h:24
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
#define MAX_TRACE
Definition: debug.h:16
#define NULL
Definition: types.h:112
#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:262
#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 736 of file buffer.c.

743 {
745 
746  KeAcquireSpinLockAtDpcLevel(&Pool->SpinLock.SpinLock);
748  KeReleaseSpinLockFromDpcLevel(&Pool->SpinLock.SpinLock);
749 }
VOID EXPORT NdisDprFreePacketNonInterlocked(IN PNDIS_PACKET Packet)
Definition: buffer.c:757
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
VOID NTAPI KeAcquireSpinLockAtDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:198
struct _NDISI_PACKET_POOL * PNDISI_PACKET_POOL
VOID NTAPI KeReleaseSpinLockFromDpcLevel(IN PKSPIN_LOCK SpinLock)
Definition: spinlock.c:221
Definition: bufpool.h:50

◆ NdisDprFreePacketNonInterlocked()

VOID EXPORT NdisDprFreePacketNonInterlocked ( IN PNDIS_PACKET  Packet)

Definition at line 757 of file buffer.c.

764 {
765  NDIS_DbgPrint(MAX_TRACE, ("Packet (0x%X).\n", Packet));
766 
767  Packet->Reserved[0] = (ULONG_PTR)((NDISI_PACKET_POOL*)Packet->Private.Pool)->FreeList;
768  ((NDISI_PACKET_POOL*)Packet->Private.Pool)->FreeList = Packet;
769 }
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
#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 811 of file buffer.c.

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

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

◆ NdisFreeBufferPool()

VOID EXPORT NdisFreeBufferPool ( IN NDIS_HANDLE  PoolHandle)

Definition at line 777 of file buffer.c.

784 {
785 }

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

◆ NdisFreePacket()

VOID EXPORT NdisFreePacket ( IN PNDIS_PACKET  Packet)

Definition at line 828 of file buffer.c.

835 {
837 
838  KeAcquireSpinLock(&Pool->SpinLock.SpinLock, &Pool->SpinLock.OldIrql);
840  KeReleaseSpinLock(&Pool->SpinLock.SpinLock, Pool->SpinLock.OldIrql);
841 }
VOID EXPORT NdisDprFreePacketNonInterlocked(IN PNDIS_PACKET Packet)
Definition: buffer.c:757
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1548
VOID NTAPI KeAcquireSpinLock(PKSPIN_LOCK SpinLock, PKIRQL OldIrql)
Definition: spinlock.c:50
struct _NDISI_PACKET_POOL * PNDISI_PACKET_POOL
Definition: bufpool.h:50
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627

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

◆ NdisFreePacketPool()

VOID EXPORT NdisFreePacketPool ( IN NDIS_HANDLE  PoolHandle)

Definition at line 793 of file buffer.c.

800 {
802 }
_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(), ParaNdis_FinalizeCleanup(), and TiUnload().

◆ NdisGetBufferPhysicalArraySize()

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

Definition at line 850 of file buffer.c.

859 {
861  ASSERT(Buffer && ArraySize);
862 
863  *ArraySize = NDIS_BUFFER_TO_SPAN_PAGES(Buffer);
864 }
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
Definition: bufpool.h:45
#define ASSERT(a)
Definition: mode.c:44
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
ULONG EXPORT NDIS_BUFFER_TO_SPAN_PAGES(IN PNDIS_BUFFER Buffer)
Definition: buffer.c:314

◆ NdisGetFirstBufferFromPacket()

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

Definition at line 873 of file buffer.c.

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

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 918 of file buffer.c.

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

Referenced by MiniportSend(), and NdisCopyFromPacketToPacketSafe().

◆ NdisGetPacketCancelId()

PVOID EXPORT NdisGetPacketCancelId ( IN PNDIS_PACKET  Packet)

Definition at line 1178 of file buffer.c.

1180 {
1182 }
_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 1154 of file buffer.c.

1156 {
1157  return Packet->Private.Pool;
1158 }
_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 1281 of file buffer.c.

1290 {
1291  /* FIXME: What is the difference between NdisIMCopySendPerPacketInfo and
1292  * NdisIMCopySendCompletePerPacketInfo?
1293  */
1294 
1295  NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
1296 
1299  sizeof(NDIS_PACKET_EXTENSION));
1300 }
#define MAX_TRACE
Definition: debug.h:16
#define NDIS_DbgPrint(_t_, _x_)
Definition: debug.h:40
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#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 1308 of file buffer.c.

1317 {
1318  /* FIXME: What is the difference between NdisIMCopySendPerPacketInfo and
1319  * NdisIMCopySendCompletePerPacketInfo?
1320  */
1321 
1322  NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
1323 
1326  sizeof(NDIS_PACKET_EXTENSION));
1327 }
#define MAX_TRACE
Definition: debug.h:16
#define NDIS_DbgPrint(_t_, _x_)
Definition: debug.h:40
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define NDIS_PACKET_EXTENSION_FROM_PACKET(Packet)
Definition: ndis.h:1341

◆ NdisPacketSize()

UINT EXPORT NdisPacketSize ( IN UINT  ProtocolReservedSize)

Definition at line 1165 of file buffer.c.

1167 {
1168  return sizeof(NDIS_PACKET) + sizeof(NDIS_PACKET_OOB_DATA) +
1169  sizeof(NDIS_PACKET_EXTENSION) + ProtocolReservedSize;
1170 }
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 
)

Definition at line 955 of file buffer.c.

967 {
968  if (VirtualAddress != NULL)
970 
972 }
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
Definition: bufpool.h:45
_Must_inspect_result_ _In_ WDFDMATRANSACTION _In_ PFN_WDF_PROGRAM_DMA _In_ WDF_DMA_DIRECTION _In_ PMDL _In_ PVOID VirtualAddress
#define MmGetMdlByteCount(_Mdl)
#define NULL
Definition: types.h:112
#define MmGetSystemAddressForMdl(Mdl)

Referenced by CleanupAndFreePacket(), CopyBufferChainToBuffer(), CopyBufferToBufferChain(), CopyPacketToBufferChain(), DispTdiReceiveDatagram(), DispTdiSend(), DispTdiSendDatagram(), FreeNdisPacket(), FreeNdisPacketX(), MiniAdapterHasAddress(), MiniportSend(), MiniportTransferData(), NdisCopyFromPacketToPacket(), NICWritePacket(), SkipToOffset(), TCPReceiveData(), TCPRecvEventHandler(), and TCPSendEventHandler().

◆ NdisQueryBufferOffset()

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

Definition at line 1005 of file buffer.c.

1009 {
1012 }
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
Definition: bufpool.h:45
_In_ ULONG _In_ ULONG Offset
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 981 of file buffer.c.

992 {
993  if (VirtualAddress != NULL)
996 }
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define MmGetSystemAddressForMdlSafe(_Mdl, _Priority)
Definition: bufpool.h:45
_Must_inspect_result_ _In_ WDFDMATRANSACTION _In_ PFN_WDF_PROGRAM_DMA _In_ WDF_DMA_DIRECTION _In_ PMDL _In_ PVOID VirtualAddress
_In_ WDFINTERRUPT _In_ WDF_INTERRUPT_POLICY _In_ WDF_INTERRUPT_PRIORITY Priority
Definition: wdfinterrupt.h:651
#define MmGetMdlByteCount(_Mdl)
#define NULL
Definition: types.h:112

Referenced by NdisCopyFromPacketToPacketSafe(), and ParaNdis_PacketCopier().

◆ NdisSetPacketCancelId()

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

Definition at line 1190 of file buffer.c.

1193 {
1195 }
_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 1020 of file buffer.c.

1030 {
1031  PNDIS_BUFFER NdisBuffer, Previous;
1032 
1034  NULL,
1035  NULL,
1036  &NdisBuffer,
1037  NULL);
1038  if (!NdisBuffer) {
1039  NDIS_DbgPrint(MID_TRACE, ("No buffer to unchain\n"));
1040  *Buffer = NULL;
1041  return;
1042  }
1043 
1044  Previous = NULL;
1045  while (NdisBuffer->Next) {
1046  Previous = NdisBuffer;
1047  NdisBuffer = NdisBuffer->Next;
1048  }
1049 
1050  if (Previous) {
1051  Previous->Next = NULL;
1052  Packet->Private.Tail = Previous;
1053  } else {
1054  Packet->Private.Head = NULL;
1055  Packet->Private.Tail = NULL;
1056  }
1057 
1058  Packet->Private.ValidCounts = FALSE;
1059 
1060  *Buffer = NdisBuffer;
1061 }
#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
#define FALSE
Definition: types.h:117
Definition: bufpool.h:45
#define NULL
Definition: types.h:112
#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 1069 of file buffer.c.

1079 {
1080  PNDIS_BUFFER NdisBuffer;
1081 
1083  NULL,
1084  NULL,
1085  &NdisBuffer,
1086  NULL);
1087  if (!NdisBuffer) {
1088  NDIS_DbgPrint(MID_TRACE, ("No buffer to unchain\n"));
1089  *Buffer = NULL;
1090  return;
1091  }
1092 
1093  Packet->Private.Head = NdisBuffer->Next;
1094 
1095  if (!NdisBuffer->Next)
1096  Packet->Private.Tail = NULL;
1097 
1098  NdisBuffer->Next = NULL;
1099 
1100  Packet->Private.ValidCounts = FALSE;
1101 
1102  *Buffer = NdisBuffer;
1103 }
#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
#define FALSE
Definition: types.h:117
Definition: bufpool.h:45
#define NULL
Definition: types.h:112
#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(), ParaNdis_IndicateReceivedPacket(), and ParaNdis_UnbindBufferFromPacket().

◆ SkipToOffset()

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

Definition at line 15 of file buffer.c.

34 {
35  for (;;) {
36 
37  if (!Buffer)
38  return 0xFFFFFFFF;
39 
41 
42  if (Offset < *Size) {
43  *Data = (PUCHAR) ((ULONG_PTR) *Data + Offset);
44  *Size -= Offset;
45  break;
46  }
47 
48  Offset -= *Size;
49 
51  }
52 
53  return Offset;
54 }
unsigned char * PUCHAR
Definition: retypes.h:3
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
#define NdisGetNextBuffer(CurrentBuffer, NextBuffer)
Definition: ndis.h:3386
uint32_t ULONG_PTR
Definition: typedefs.h:65
Definition: bufpool.h:45
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
VOID EXPORT NdisQueryBuffer(IN PNDIS_BUFFER Buffer, OUT PVOID *VirtualAddress OPTIONAL, OUT PUINT Length)
Definition: buffer.c:955

Referenced by CopyBufferChainToBuffer(), CopyBufferToBufferChain(), CopyPacketToBufferChain(), GetDataPtr(), NdisCopyFromPacketToPacket(), and NdisCopyFromPacketToPacketSafe().