ReactOS 0.4.15-dev-7674-gc0b4db1
routines.c File Reference
#include "precomp.h"
Include dependency graph for routines.c:

Go to the source code of this file.

Functions

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

Variables

NDIS_HANDLE GlobalPacketPool = NULL
 
NDIS_HANDLE GlobalBufferPool = NULL
 

Function Documentation

◆ AllocatePacketWithBufferX()

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

Definition at line 82 of file routines.c.

84 {
88 PCHAR NewData;
89
90 NewData = exAllocatePool( NonPagedPool, Len );
91 if( !NewData ) return NDIS_STATUS_NOT_ACCEPTED; // XXX
92
93 if( Data )
94 RtlCopyMemory(NewData, Data, Len);
95
98 exFreePool( NewData );
99 return Status;
100 }
102
104 if( Status != NDIS_STATUS_SUCCESS ) {
105 exFreePool( NewData );
107 }
109
111 *NdisPacket = Packet;
112
113 return NDIS_STATUS_SUCCESS;
114}
Definition: bufpool.h:45
Definition: File.h:16
#define Len
Definition: deflate.h:82
VOID EXPORT NdisAllocateBuffer(OUT PNDIS_STATUS Status, OUT PNDIS_BUFFER *Buffer, IN NDIS_HANDLE PoolHandle, IN PVOID VirtualAddress, IN UINT Length)
Definition: buffer.c:336
VOID EXPORT NdisAllocatePacket(OUT PNDIS_STATUS Status, OUT PNDIS_PACKET *Packet, IN NDIS_HANDLE PoolHandle)
Definition: buffer.c:394
#define NonPagedPool
Definition: env_spec_w32.h:307
Status
Definition: gdiplustypes.h:25
#define NDIS_BUFFER_TAG
Definition: lan.h:22
#define NDIS_PACKET_TAG
Definition: lan.h:23
NDIS_HANDLE GlobalBufferPool
Definition: routines.c:4
NDIS_HANDLE GlobalPacketPool
Definition: routines.c:3
#define exAllocatePool(x, y)
Definition: memtrack.h:17
#define exFreePool(x)
Definition: memtrack.h:18
#define TrackWithTag(w, x, y, z)
Definition: memtrack.h:19
#define FreeNdisPacket(x)
Definition: memtrack.h:8
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1549
#define NDIS_STATUS_SUCCESS
Definition: ndis.h:346
MDL * PNDIS_BUFFER
Definition: ndis.h:343
#define NDIS_STATUS_NOT_ACCEPTED
Definition: ndis.h:350
#define NdisChainBufferAtFront(Packet, Buffer)
Definition: ndis.h:3106
int NDIS_STATUS
Definition: ntddndis.h:475
Definition: ncftp.h:79
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
char * PCHAR
Definition: typedefs.h:51

◆ CloseNdisPools()

VOID CloseNdisPools ( )

Definition at line 19 of file routines.c.

19 {
22}
VOID EXPORT NdisFreeBufferPool(IN NDIS_HANDLE PoolHandle)
Definition: buffer.c:777
VOID EXPORT NdisFreePacketPool(IN NDIS_HANDLE PoolHandle)
Definition: buffer.c:793

Referenced by LanUnload().

◆ FreeNdisPacketX()

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

Definition at line 117 of file routines.c.

126{
127 PNDIS_BUFFER Buffer, NextBuffer;
128
129 LA_DbgPrint(DEBUG_PBUFFER, ("Packet (0x%X)\n", Packet));
130
131 /* Free all the buffers in the packet first */
133 for (; Buffer != NULL; Buffer = NextBuffer) {
134 PVOID Data;
135 UINT Length;
136
137 NdisGetNextBuffer(Buffer, &NextBuffer);
142 }
143
144 /* Finally free the NDIS packet descriptor */
147}
#define NULL
Definition: types.h:112
#define DEBUG_PBUFFER
Definition: debug.h:20
#define LA_DbgPrint(_t_, _x_)
Definition: debug.h:66
VOID EXPORT NdisFreePacket(IN PNDIS_PACKET Packet)
Definition: buffer.c:828
#define UntrackFL(x, y, z)
Definition: memtrack.h:20
#define NdisGetNextBuffer(CurrentBuffer, NextBuffer)
Definition: ndis.h:3386
unsigned int UINT
Definition: ndis.h:50
static __inline VOID NdisQueryPacket(IN PNDIS_PACKET Packet, OUT PUINT PhysicalBufferCount OPTIONAL, OUT PUINT BufferCount OPTIONAL, OUT PNDIS_BUFFER *FirstBuffer OPTIONAL, OUT PUINT TotalPacketLength OPTIONAL)
Definition: ndis.h:3593
#define NdisFreeBuffer
Definition: ndis.h:2895
#define NdisQueryBuffer(_Buffer, _VirtualAddress, _Length)
Definition: ndis.h:3029
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102

◆ GetDataPtr()

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

Definition at line 65 of file routines.c.

68 {
70
72 if( !Buffer ) return;
73 SkipToOffset( Buffer, Offset, DataOut, Size );
74}
__inline INT SkipToOffset(PNDIS_BUFFER Buffer, UINT Offset, PCHAR *Data, PUINT Size)
Definition: routines.c:24
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533

◆ InitNdisPools()

NDIS_STATUS InitNdisPools ( )

Definition at line 6 of file routines.c.

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

Referenced by DriverEntry().

◆ SkipToOffset()

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

Definition at line 24 of file routines.c.

43{
44 for (;;) {
45
46 if (!Buffer)
47 return -1;
48
50
51 if (Offset < *Size) {
52 *Data = (PCHAR)((ULONG_PTR) *Data + Offset);
53 *Size -= Offset;
54 break;
55 }
56
57 Offset -= *Size;
58
60 }
61
62 return Offset;
63}
#define PCHAR
Definition: match.c:90
uint32_t ULONG_PTR
Definition: typedefs.h:65

Referenced by GetDataPtr().

Variable Documentation

◆ GlobalBufferPool

◆ GlobalPacketPool

NDIS_HANDLE GlobalPacketPool = NULL