summaryrefslogtreecommitdiffstats
path: root/private/ntos/ndis/pc586e/filter.h
blob: 54d01a9de43c66918e7a441db2e13d8f240961ec (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
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
/*++

Copyright (c) 1990  Microsoft Corporation

Module Name:

    filter.h

Abstract:

    Header file for the address filtering library for NDIS MAC's.

Author:

    Anthony V. Ercolano (tonye) creation-date 3-Aug-1990

Environment:

    Runs in the context of a single MAC driver.

Notes:

    None.

Revision History:


--*/

#ifndef _MAC_FILTER_DEFS_
#define _MAC_FILTER_DEFS_

#define MAC_LENGTH_OF_ADDRESS 6


//
// ZZZ This is a little indian specific check.
//
#define MAC_IS_MULTICAST(Address,Result) \
{ \
    PUCHAR _A = Address; \
    *Result = ((_A[0] & ((UCHAR)0x01))?(TRUE):(FALSE)); \
}


//
// Check whether an address is broadcast.
//
#define MAC_IS_BROADCAST(Address,Result) \
{ \
    PUCHAR _A = Address; \
    *Result = (((_A[0] == ((UCHAR)0xff)) && \
                (_A[1] == ((UCHAR)0xff)) && \
                (_A[2] == ((UCHAR)0xff)) && \
                (_A[3] == ((UCHAR)0xff)) && \
                (_A[4] == ((UCHAR)0xff)) && \
                (_A[5] == ((UCHAR)0xff)))?(TRUE):(FALSE)); \
}


//
// This macro will compare network addresses.
//
//  A - Is a network address.
//
//  B - Is a network address.
//
//  Result - The result of comparing two network address.
//
//  Result < 0 Implies the B address is greater.
//  Result > 0 Implies the A element is greater.
//  Result = 0 Implies equality.
//
// Note that this is an arbitrary ordering.  There is not
// defined relation on network addresses.  This is ad-hoc!
//
//
#define MAC_COMPARE_NETWORK_ADDRESSES(A,B,Result) \
{ \
    PCHAR _A = A; \
    PCHAR _B = B; \
    INT _LocalResult = 0; \
    UINT _i; \
    for ( \
        _i = 0; \
        _i <= 5 && !_LocalResult; \
        _i++ \
        ) { \
        _LocalResult = _A[_i] - _B[_i]; \
    } \
    *Result = _LocalResult; \
}


//
// This macro is used to copy from one network address to
// another.
//
#define MAC_COPY_NETWORK_ADDRESS(D,S) \
{ \
    PCHAR _D = (D); \
    PCHAR _S = (S); \
    _D[0] = _S[0]; \
    _D[1] = _S[1]; \
    _D[2] = _S[2]; \
    _D[3] = _S[3]; \
    _D[4] = _S[4]; \
    _D[5] = _S[5]; \
}


//
//UINT
//MAC_QUERY_FILTER_CLASSES(
//    IN PMAC_FILTER Filter
//    )
//
// This macro returns the currently enabled filter classes.
//
// NOTE: THIS MACRO ASSUMES THAT THE FILTER LOCK IS HELD.
//
#define MAC_QUERY_FILTER_CLASSES(Filter) ((Filter)->CombinedPacketFilter)


//
//UINT
//MAC_NUMBER_OF_FILTER_ADDRESSES(
//    IN PMAC_FILTER Filter
//    )
//
// This macro returns the number of multicast addresses in the
// multicast address list.
//
// NOTE: THIS MACRO ASSUMES THAT THE FILTER LOCK IS HELD.
//
#define MAC_NUMBER_OF_FILTER_ADDRESSES(Filter) ((Filter)->NumberOfAddresses)


//
// An action routine type.  The routines are called
// when a filter type is set for the first time or
// no more bindings require a particular type of filter.
//
// NOTE: THIS ROUTINE SHOULD ASSUME THAT THE LOCK IS ACQUIRED.
//
typedef
NDIS_STATUS
(*MAC_FILTER_CHANGE)(
    IN UINT OldFilterClasses,
    IN UINT NewFilterClasses,
    IN NDIS_HANDLE MacBindingHandle,
    IN NDIS_HANDLE RequestHandle,
    IN BOOLEAN Set
    );

//
// This action routine is called when a unique multicast address
// is added to the filter.  The action routine is passed an array
// filled with all of the addresses that are being filtered, as
// well as the index into this array of the unique address just
// added.
//
// NOTE: THIS ROUTINE SHOULD ASSUME THAT THE LOCK IS ACQUIRED.
//
typedef
NDIS_STATUS
(*MAC_ADDRESS_ADD)(
    IN UINT CurrentAddressCount,
    IN CHAR CurrentAddresses[][MAC_LENGTH_OF_ADDRESS],
    IN UINT NewAddress,
    IN NDIS_HANDLE MacBindingHandle,
    IN NDIS_HANDLE RequestHandle
    );

//
// This action routine is called when a unique multicast address
// is no longer requested for filtering by any binding.  The
// action routine is passed an array filled with the all of the
// addresses that are *still* being used for multicast filtering.
// The routine is also passed the address of the address being deleted.
//
// NOTE: THIS ROUTINE SHOULD ASSUME THAT THE LOCK IS ACQUIRED.
//
typedef
NDIS_STATUS
(*MAC_ADDRESS_DELETE)(
    IN UINT CurrentAddressCount,
    IN CHAR CurrentAddresses[][MAC_LENGTH_OF_ADDRESS],
    IN CHAR OldAddress[MAC_LENGTH_OF_ADDRESS],
    IN NDIS_HANDLE MacBindingHandle,
    IN NDIS_HANDLE RequestHandle
    );

//
// This action routine is called when the mac requests a close for
// a particular binding *WHILE THE BINDING IS BEING INDICATED TO
// THE PROTOCOL*.  The filtering package can't get rid of the open
// right away.  So this routine will be called as soon as the
// NdisIndicateReceive returns.
//
// NOTE: THIS ROUTINE SHOULD ASSUME THAT THE LOCK IS ACQUIRED.
//
typedef
VOID
(*MAC_DEFERRED_CLOSE)(
    IN NDIS_HANDLE MacBindingHandle
    );

typedef ULONG MASK,*PMASK;

//
// The binding info is threaded on two lists.  When
// the binding is free it is on a single freelist.
//
// When the binding is being used it is on a doubly linked
// index list.
//
typedef struct _BINDING_INFO {
    NDIS_HANDLE MacBindingHandle;
    NDIS_HANDLE NdisBindingContext;
    UINT PacketFilters;
    INT FreeNext;
    INT OpenNext;
    INT OpenPrev;
} BINDING_INFO,*PBINDING_INFO;

//
// An opaque type that contains a filter database.
// The MAC need not know how it is structured.
//
typedef struct _MAC_FILTER {

    //
    // Spin lock used to protect the filter from multiple accesses.
    //
    PNDIS_SPIN_LOCK Lock;

    //
    // Pointer to an array of 6 character arrays holding the
    // multicast addresses requested for filtering.
    //
    CHAR (*MulticastAddresses)[MAC_LENGTH_OF_ADDRESS];

    //
    // Pointer to an array of MASKS that work in conjuction with
    // the MulticastAddress array.  In the masks, a bit being enabled
    // indicates that the binding with the given FilterIndex is using
    // the corresponding address.
    //
    MASK *BindingsUsingAddress;

    //
    // Combination of all the filters of all the open bindings.
    //
    UINT CombinedPacketFilter;

    //
    // Array indexed by FilterIndex giving the Handle and context
    // for a particular binding.
    //
    PBINDING_INFO BindingInfo;

    //
    // Action routines to be invoked on notable changes in the filter.
    //
    MAC_ADDRESS_DELETE DeleteAction;
    MAC_ADDRESS_ADD AddAction;
    MAC_FILTER_CHANGE ChangeAction;
    MAC_DEFERRED_CLOSE CloseAction;

    //
    // The maximum number of addresses used for filtering.
    //
    UINT MaximumMulticastAddresses;

    //
    // The current number of addresses in the address filter.
    //
    UINT NumberOfAddresses;

    //
    // Listhead of the free list of bindings that are available.
    //
    // Can only be accessed when the lock is held.
    //
    INT FirstFreeBinding;

    //
    // Index of the first element of the open binding list.
    //
    // Can only be accessed when the lock is held.
    //
    INT OpenStart;

    //
    // Index of the last element of the open binding list.
    //
    // Can only be accessed when the lock is held.
    //
    INT OpenEnd;

    //
    // Holds the value of the open binding that is currently
    // being indicated.
    //
    // If this value is -1 then no bindings are currently being
    // indicated.
    //
    // This value can only be accessed when the lock is held.
    //
    INT IndicatingBinding;

    //
    // This is set to true when the DeleteFilterOpenAdapter routine
    // notices that the FilterIndex being shut down is the same one
    // that is being indicated.
    //
    BOOLEAN CurrentBindingShuttingDown;

} MAC_FILTER,*PMAC_FILTER;

BOOLEAN
MacCreateFilter(
    IN UINT MaximumMulticastAddresses,
    IN UINT MaximumOpenAdapters,
    IN MAC_ADDRESS_DELETE DeleteAction,
    IN MAC_ADDRESS_ADD AddAction,
    IN MAC_FILTER_CHANGE ChangeAction,
    IN MAC_DEFERRED_CLOSE CloseAction,
    IN PNDIS_SPIN_LOCK Lock,
    OUT PMAC_FILTER *Filter
    );

VOID
MacDeleteFilter(
    IN PMAC_FILTER Filter
    );

BOOLEAN
MacNoteFilterOpenAdapter(
    IN PMAC_FILTER Filter,
    IN NDIS_HANDLE MacBindingHandle,
    IN NDIS_HANDLE NdisBindingContext,
    OUT PUINT FilterIndex
    );

NDIS_STATUS
MacDeleteFilterOpenAdapter(
    IN PMAC_FILTER Filter,
    IN UINT FilterIndex,
    IN NDIS_HANDLE RequestHandle
    );

NDIS_STATUS
MacAddFilterAddress(
    IN PMAC_FILTER Filter,
    IN UINT FilterIndex,
    IN NDIS_HANDLE RequestHandle,
    IN CHAR MulticastAddress[MAC_LENGTH_OF_ADDRESS]
    );

NDIS_STATUS
MacDeleteFilterAddress(
    IN PMAC_FILTER Filter,
    IN UINT FilterIndex,
    IN NDIS_HANDLE RequestHandle,
    IN CHAR MulticastAddress[MAC_LENGTH_OF_ADDRESS]
    );

BOOLEAN
MacShouldAddressLoopBack(
    IN PMAC_FILTER Filter,
    IN CHAR Address[MAC_LENGTH_OF_ADDRESS]
    );

NDIS_STATUS
MacFilterAdjust(
    IN PMAC_FILTER Filter,
    IN UINT FilterIndex,
    IN NDIS_HANDLE RequestHandle,
    IN UINT FilterClasses,
    IN BOOLEAN Set
    );

VOID
MacQueryFilterAddresses(
    IN PMAC_FILTER Filter,
    OUT PUINT NumberOfAddresses,
    IN OUT CHAR AddressArray[][MAC_LENGTH_OF_ADDRESS]
    );

VOID
MacFilterIndicateReceive(
    IN PMAC_FILTER Filter,
    IN NDIS_HANDLE MacReceiveContext,
    IN PCHAR Address,
    IN PVOID LookaheadBuffer,
    IN UINT LookaheadBufferSize,
    IN UINT PacketSize
    );

#endif // _MAC_FILTER_DEFS_