ReactOS 0.4.15-dev-8135-g1bc6c90
routines.c
Go to the documentation of this file.
1#include "precomp.h"
2
5
7 NDIS_STATUS NdisStatus;
8 /* Last argument is extra space size */
9 NdisAllocatePacketPool( &NdisStatus, &GlobalPacketPool, 100, 0 );
10 if( !NT_SUCCESS(NdisStatus) ) return NdisStatus;
11
12 NdisAllocateBufferPool( &NdisStatus, &GlobalBufferPool, 100 );
13 if( !NT_SUCCESS(NdisStatus) )
15
16 return NdisStatus;
17}
18
22}
23
27 PCHAR *Data,
28 PUINT Size)
29/*
30 * FUNCTION: Skip Offset bytes into a buffer chain
31 * ARGUMENTS:
32 * Buffer = Pointer to NDIS buffer
33 * Offset = Number of bytes to skip
34 * Data = Address of a pointer that on return will contain the
35 * address of the offset in the buffer
36 * Size = Address of a pointer that on return will contain the
37 * size of the destination buffer
38 * RETURNS:
39 * Offset into buffer, -1 if buffer chain was smaller than Offset bytes
40 * NOTES:
41 * Buffer may be NULL
42 */
43{
44 for (;;) {
45
46 if (!Buffer)
47 return -1;
48
50
51 if (Offset < *Size) {
52 *Data = (PCHAR)((ULONG_PTR) *Data + Offset);
53 *Size -= Offset;
54 break;
55 }
56
57 Offset -= *Size;
58
60 }
61
62 return Offset;
63}
64
67 PCHAR *DataOut,
68 PUINT Size ) {
70
72 if( !Buffer ) return;
73 SkipToOffset( Buffer, Offset, DataOut, Size );
74}
75
76
77#undef NdisAllocatePacket
78#undef NdisAllocateBuffer
79#undef NdisFreeBuffer
80#undef NdisFreePacket
81
84 PCHAR File, UINT Line ) {
88 PCHAR NewData;
89
90 NewData = exAllocatePool( NonPagedPool, Len );
91 if( !NewData ) return NDIS_STATUS_NOT_ACCEPTED; // XXX
92
93 if( Data )
94 RtlCopyMemory(NewData, Data, Len);
95
98 exFreePool( NewData );
99 return Status;
100 }
102
104 if( Status != NDIS_STATUS_SUCCESS ) {
105 exFreePool( NewData );
107 }
109
111 *NdisPacket = Packet;
112
113 return NDIS_STATUS_SUCCESS;
114}
115
116
119 PCHAR File,
120 UINT Line )
121/*
122 * FUNCTION: Frees an NDIS packet
123 * ARGUMENTS:
124 * Packet = Pointer to NDIS packet to be freed
125 */
126{
127 PNDIS_BUFFER Buffer, NextBuffer;
128
129 LA_DbgPrint(DEBUG_PBUFFER, ("Packet (0x%X)\n", Packet));
130
131 /* Free all the buffers in the packet first */
133 for (; Buffer != NULL; Buffer = NextBuffer) {
134 PVOID Data;
135 UINT Length;
136
137 NdisGetNextBuffer(Buffer, &NextBuffer);
142 }
143
144 /* Finally free the NDIS packet descriptor */
147}
Definition: bufpool.h:45
Definition: File.h:16
#define Len
Definition: deflate.h:82
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define DEBUG_PBUFFER
Definition: debug.h:20
#define LA_DbgPrint(_t_, _x_)
Definition: debug.h:66
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 NdisFreePacket(IN PNDIS_PACKET Packet)
Definition: buffer.c:828
VOID EXPORT NdisAllocateBufferPool(OUT PNDIS_STATUS Status, OUT PNDIS_HANDLE PoolHandle, IN UINT NumberOfDescriptors)
Definition: buffer.c:372
VOID EXPORT NdisFreeBufferPool(IN NDIS_HANDLE PoolHandle)
Definition: buffer.c:777
VOID EXPORT NdisAllocatePacket(OUT PNDIS_STATUS Status, OUT PNDIS_PACKET *Packet, IN NDIS_HANDLE PoolHandle)
Definition: buffer.c:394
VOID EXPORT NdisFreePacketPool(IN NDIS_HANDLE PoolHandle)
Definition: buffer.c:793
VOID EXPORT NdisAllocatePacketPool(OUT PNDIS_STATUS Status, OUT PNDIS_HANDLE PoolHandle, IN UINT NumberOfDescriptors, IN UINT ProtocolReservedLength)
Definition: buffer.c:421
#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
void GetDataPtr(PNDIS_PACKET Packet, UINT Offset, PCHAR *DataOut, PUINT Size)
Definition: routines.c:65
NDIS_STATUS AllocatePacketWithBufferX(PNDIS_PACKET *NdisPacket, PCHAR Data, UINT Len, PCHAR File, UINT Line)
Definition: routines.c:82
NDIS_HANDLE GlobalPacketPool
Definition: routines.c:3
NDIS_STATUS InitNdisPools()
Definition: routines.c:6
VOID CloseNdisPools()
Definition: routines.c:19
__inline INT SkipToOffset(PNDIS_BUFFER Buffer, UINT Offset, PCHAR *Data, PUINT Size)
Definition: routines.c:24
VOID FreeNdisPacketX(PNDIS_PACKET Packet, PCHAR File, UINT Line)
Definition: routines.c:118
#define exAllocatePool(x, y)
Definition: memtrack.h:17
#define UntrackFL(x, y, z)
Definition: memtrack.h:20
#define exFreePool(x)
Definition: memtrack.h:18
#define TrackWithTag(w, x, y, z)
Definition: memtrack.h:19
#define FreeNdisPacket(x)
Definition: memtrack.h:8
#define PCHAR
Definition: match.c:90
#define NdisGetNextBuffer(CurrentBuffer, NextBuffer)
Definition: ndis.h:3386
_In_ NDIS_HANDLE _In_ PNDIS_PACKET Packet
Definition: ndis.h:1549
unsigned int * PUINT
Definition: ndis.h:50
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 NDIS_STATUS_SUCCESS
Definition: ndis.h:346
MDL * PNDIS_BUFFER
Definition: ndis.h:343
#define NdisFreeBuffer
Definition: ndis.h:2895
#define NdisQueryBuffer(_Buffer, _VirtualAddress, _Length)
Definition: ndis.h:3029
#define NDIS_STATUS_NOT_ACCEPTED
Definition: ndis.h:350
#define NdisChainBufferAtFront(Packet, Buffer)
Definition: ndis.h:3106
int NDIS_STATUS
Definition: ntddndis.h:475
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
Definition: ncftp.h:79
int32_t INT
Definition: typedefs.h:58
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
uint32_t ULONG_PTR
Definition: typedefs.h:65
char * PCHAR
Definition: typedefs.h:51
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533