summaryrefslogtreecommitdiffstats
path: root/private/ntos/ndis/testmac/testmac.h
blob: 750bb213ed8b4e80c63ae8d288e58c27b1836575 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349

/*++

Copyright (c) 1990  Microsoft Corporation

Module Name:

   testmac.h

Abstract:

    Definitions for test MAC.
    Motsly taken from the Elnkii code spec.

Author:

    Adam Barr (adamba)    16-Jul-1990

Revision History:

--*/

#define AllocPhys(s)   ExAllocatePool(NonPagedPool, s)
#define FreePhys(s)    ExFreePool(s)

#define ADDRESS_LEN 6

typedef ULONG MASK;

UCHAR BroadcastAddress[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };


// only have one of these structures

typedef struct _MAC_BLOCK {
    // NDIS information
    NDIS_HANDLE NdisMacHandle;		// returned from NdisRegisterMac
    NDIS_MAC_CHARACTERISTICS MacCharacteristics;
    UCHAR MacName[8];
    // adapters registered for us
    UINT NumAdapters;
    struct _ADAPTER_BLOCK * AdapterQueue;
    // should we be verbose
    BOOLEAN Debug;
    // NT specific
    PDRIVER_OBJECT DriverObject;
    KPOWER_STATUS PowerStatus;
    BOOLEAN PowerBoolean;
    NDIS_SPIN_LOCK SpinLock;		// guards NumAdapter and AdapterQueue
} MAC_BLOCK, * PMAC_BLOCK;


// the multicast address list consists of these
typedef struct _MULTICAST_ENTRY {
    UCHAR Address[ADDRESS_LEN];
    MASK ProtocolMask;		// determines which opens it applies to
} MULTICAST_ENTRY, * PMULTICAST_ENTRY;

// one of these per adapter registered

typedef struct _ADAPTER_BLOCK {
    // NDIS information
    NDIS_HANDLE NdisAdapterHandle;	// returned from NdisRegisterAdapter
    PSTRING AdapterName;
    // used to mark us
    UINT AdapterNumber;
    // links with our MAC
    PMAC_BLOCK MacBlock;
    struct _ADAPTER_BLOCK * NextAdapter;  // used by MacBlock->OpenQueue
    // opens for this adapter
    UINT MaxOpens;			// maximum number
    struct _OPEN_BLOCK * OpenBlocks;    // storage for MaxOpens OPEN_BLOCKs
    UINT NumOpens;
    struct _OPEN_BLOCK * OpenQueue;
    struct _OPEN_BLOCK * FreeOpenQueue;
    // should we be verbose
    BOOLEAN Debug;
    // PROTOCOL.INI information
    UINT MulticastListMax;
    // these are for the current packet
    UCHAR PacketHeader[4];
    UCHAR Lookahead[256];
    UINT PacketLen;
    // receive information
    UINT MulticastListSize;		// current size
    PMULTICAST_ENTRY MulticastList;
    NDIS_SPIN_LOCK MulticastSpinLock;	// guards all data in this section
    BOOLEAN MulticastDontModify;	// an extended spinlock
    MASK MulticastFilter;		// these filters work as explained
    MASK DirectedFilter;		//  in the design note
    MASK BroadcastFilter;
    MASK PromiscuousFilter;
    MASK AllMulticastFilter;
    // loopback information
    PNDIS_PACKET LoopbackQueue;
    PNDIS_PACKET LoopbackQTail;
    NDIS_SPIN_LOCK LoopbackSpinLock;
    PNDIS_PACKET LoopbackPacket;
    // NT specific
    PKINTERRUPT Interrupt;
	KDPC IndicateDpc;
	BOOLEAN DpcQueued;
} ADAPTER_BLOCK, * PADAPTER_BLOCK;

// general macros
#define MSB(value) ((UCHAR)((value) << 8))
#define LSB(value) ((UCHAR)((value) && 0xff))

// one of these per open on the adapter

typedef struct _OPEN_BLOCK {
    // NDIS information
    NDIS_HANDLE NdisBindingContext;	// passed to MacOpenAdapter
    PSTRING AddressingInformation;	// not used currently
    // links to our adapter
    PADAPTER_BLOCK AdapterBlock;
    struct _OPEN_BLOCK * NextOpen;
    // links to our MAC
    PMAC_BLOCK MacBlock;	    // faster than using AdapterBlock->MacBlock
    // should we be verbose
    BOOLEAN Debug;
    // used for multicast addresses
    MASK MulticastBit;
} OPEN_BLOCK, * POPEN_BLOCK;



// the reserved section of a packet

typedef struct _MAC_RESERVED {     // can't be more than 16 bytes
    PNDIS_PACKET NextPacket;	// used to in the transmit queue (4 bytes)
    NDIS_HANDLE RequestHandle;	// for async send completion (4 bytes)
    POPEN_BLOCK OpenBlock;	// so we know who to complete to (4 bytes)
    USHORT Status;		// completion status (2 bytes)
    BOOLEAN Loopback;		// is this a loopback packet (1 byte)
    BOOLEAN ReadyToComplete;	// is one out of xmit or loopback done (1 byte)
} MAC_RESERVED, * PMAC_RESERVED;

// macro to retrieve the MAC_RESERVED structure from a packet
#define RESERVED(Packet) ((PMAC_RESERVED)((Packet)->MacReserved))

extern MAC_BLOCK GlobalMacBlock;


//
// function prototypes
//


NTSTATUS
TestMacInitialize(
    IN PDRIVER_OBJECT DriverObject
    );


static
NTSTATUS
TestMacDispatch(
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP Irp
    );


static
NDIS_STATUS
TestMacRegisterAdapter(
    IN PSTRING AdapterName,
    IN UINT AdapterNumber
    );


static
NDIS_STATUS
TestMacOpenAdapter(
    OUT NDIS_HANDLE * MacBindingHandle,
    IN NDIS_HANDLE RequestHandle,
    IN NDIS_HANDLE NdisBindingContext,
    IN NDIS_HANDLE MacAdapterContext,
    IN PSTRING AddressingInformation OPTIONAL
    );


static
NDIS_STATUS
TestMacCloseAdapter(
    IN NDIS_HANDLE MacBindingHandle,
    IN NDIS_HANDLE RequestHandle
    );


static
NDIS_STATUS
TestMacSetPacketFilter(
    IN NDIS_HANDLE MacBindingHandle,
    IN NDIS_HANDLE RequestHandle,
    IN UINT PacketFilter
    );


static
NDIS_STATUS
TestMacAddMulticastAddress(
    IN NDIS_HANDLE MacBindingHandle,
    IN NDIS_HANDLE RequestHandle,
    IN PSTRING MulticastAddress
    );


static
VOID
TestMacGetMulticastAccess(
    IN PADAPTER_BLOCK AdaptP
    );


static
PMULTICAST_ENTRY
TestMacFindMulticastAddress(
    IN PMULTICAST_ENTRY List,
    IN UINT Size,
    IN PUCHAR MulticastAddress
    );


static
VOID
TestMacKillMulticastAddresses(
    IN PADAPTER_BLOCK AdaptP,
    IN MASK MulticastBit
    );


static
NDIS_STATUS
TestMacDeleteMulticastAddress(
    IN NDIS_HANDLE MacBindingHandle,
    IN NDIS_HANDLE RequestHandle,
    IN PSTRING MulticastAddress
    );


static
NDIS_STATUS
TestMacSend(
    IN NDIS_HANDLE MacBindingHandle,
    IN NDIS_HANDLE RequestHandle,
    IN PNDIS_PACKET Packet
    );


static
VOID
TestMacSetLoopbackFlag(
    IN OUT PNDIS_PACKET Packet
    );


static
VOID
TestMacLoopbackPacket(
    IN PADAPTER_BLOCK AdaptP,
    IN OUT PNDIS_PACKET Packet
    );


static
VOID
TestMacIndicateLoopbackPacket(
    IN PADAPTER_BLOCK AdaptP,
    IN PNDIS_PACKET Packet
    );


static
UINT
TestMacPacketSize(
    IN PNDIS_PACKET Packet
    );


static
UINT
TestMacCopyOver(
    OUT PUCHAR Buf,
    IN PNDIS_PACKET Packet,
    IN UINT Offset,
    IN UINT Length
    );


static
NDIS_STATUS
TestMacTransferData(
    IN NDIS_HANDLE MacBindingHandle,
    IN NDIS_HANDLE RequestHandle,
    IN NDIS_HANDLE MacReceiveContext,
    IN UINT ByteOffset,
    IN UINT BytesToTransfer,
    OUT PNDIS_PACKET Packet,
    OUT PUINT BytesTransferred
    );


static
NDIS_STATUS
TestMacQueryInformation(
    IN NDIS_HANDLE MacBindingHandle,
    IN NDIS_HANDLE RequestHandle,
    IN NDIS_INFORMATION_CLASS InformationClass,
    OUT PVOID Buffer,
    IN UINT BufferLength
    );


static
NDIS_STATUS
TestMacSetInformation(
    IN NDIS_HANDLE MacBindingHandle,
    IN NDIS_HANDLE RequestHandle,
    IN NDIS_INFORMATION_CLASS InformationClass,
    IN PVOID Buffer,
    IN UINT BufferLength
    );


static
NDIS_STATUS
TestMacReset(
    IN NDIS_HANDLE MacBindingHandle,
    IN NDIS_HANDLE RequestHandle
    );


static
NDIS_STATUS
TestMacTest(
    IN NDIS_HANDLE MacBindingHandle,
    IN NDIS_HANDLE RequestHandle
    );


static
VOID
TestMacIndicateDpc(
	IN PKDPC Dpc,
    IN PVOID DeferredContext,
    IN PVOID SystemArgument1,
    IN PVOID SystemArgument2
    );