OSDN Git Service

More on assuming GCC is greater than or equal to version 3.5.4 and that
[mingw/mingw-org-wsl.git] / include / ddk / xfilter.h
1 /*
2  * xfilter.h
3  *
4  * Address filtering for NDIS MACs
5  *
6  * This file is part of the w32api package.
7  *
8  * Contributors:
9  *   Created by Casper S. Hornstrup <chorns@users.sourceforge.net>
10  *
11  * THIS SOFTWARE IS NOT COPYRIGHTED
12  *
13  * This source code is offered for use in the public domain. You may
14  * use, modify or distribute it freely.
15  *
16  * This code is distributed in the hope that it will be useful but
17  * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
18  * DISCLAIMED. This includes but is not limited to warranties of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20  *
21  */
22
23 #ifndef __XFILTER_H
24 #define __XFILTER_H
25 #pragma GCC system_header
26
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30
31 #include "ntddk.h"
32
33
34 #define ETH_LENGTH_OF_ADDRESS             6
35
36 #define ETH_IS_BROADCAST(Address) \
37   ((((PUCHAR)(Address))[0] == ((UCHAR)0xff)) && (((PUCHAR)(Address))[1] == ((UCHAR)0xff)))
38
39 #define ETH_IS_MULTICAST(Address) \
40   (BOOLEAN)(((PUCHAR)(Address))[0] & ((UCHAR)0x01))
41
42 #define ETH_COMPARE_NETWORK_ADDRESSES(_A, _B, _Result) \
43 { \
44         if (*(ULONG UNALIGNED *)&(_A)[2] > *(ULONG UNALIGNED *)&(_B)[2]) \
45         { \
46     *(_Result) = 1; \
47         } \
48         else if (*(ULONG UNALIGNED *)&(_A)[2] < *(ULONG UNALIGNED *)&(_B)[2]) \
49         { \
50     *(_Result) = (UINT)-1; \
51         } \
52         else if (*(USHORT UNALIGNED *)(_A) > *(USHORT UNALIGNED *)(_B)) \
53         { \
54     *(_Result) = 1; \
55         } \
56         else if (*(USHORT UNALIGNED *)(_A) < *(USHORT UNALIGNED *)(_B)) \
57         { \
58           *(_Result) = (UINT)-1; \
59         } \
60         else \
61         { \
62           *(_Result) = 0; \
63         } \
64 }
65
66 #define ETH_COMPARE_NETWORK_ADDRESSES_EQ(_A,_B, _Result) \
67 { \
68         if ((*(ULONG UNALIGNED *)&(_A)[2] == *(ULONG UNALIGNED *)&(_B)[2]) && \
69     (*(USHORT UNALIGNED *)(_A) == *(USHORT UNALIGNED *)(_B))) \
70         { \
71     *(_Result) = 0; \
72         } \
73         else \
74         { \
75     *(_Result) = 1; \
76         } \
77 }
78
79 #define ETH_COPY_NETWORK_ADDRESS(_D, _S) \
80 { \
81         *((ULONG UNALIGNED *)(_D)) = *((ULONG UNALIGNED *)(_S)); \
82         *((USHORT UNALIGNED *)((UCHAR *)(_D) + 4)) = *((USHORT UNALIGNED *)((UCHAR *)(_S) + 4)); \
83 }
84
85 #define FDDI_LENGTH_OF_LONG_ADDRESS       6
86 #define FDDI_LENGTH_OF_SHORT_ADDRESS      2
87
88 #define FDDI_IS_BROADCAST(Address, AddressLength, Result)   \
89   *Result = ((*(PUCHAR)(Address) == (UCHAR)0xFF) && \
90   (*((PUCHAR)(Address) + 1) == (UCHAR)0xFF))
91
92 #define FDDI_IS_MULTICAST(Address, AddressLength, Result) \
93   *Result = (BOOLEAN)(*(UCHAR *)(Address) & (UCHAR)0x01)
94
95 #define FDDI_IS_SMT(FcByte, Result) \
96 { \
97   *Result = ((FcByte & ((UCHAR)0xf0)) == 0x40); \
98 }
99
100
101 #define FDDI_COMPARE_NETWORK_ADDRESSES(_A, _B, _Length, _Result) \
102 { \
103         if (*(USHORT UNALIGNED *)(_A) > *(USHORT UNALIGNED *)(_B)) \
104         { \
105           *(_Result) = 1; \
106         } \
107         else if (*(USHORT UNALIGNED *)(_A) < *(USHORT UNALIGNED *)(_B)) \
108         { \
109           *(_Result) = (UINT)-1; \
110         } \
111         else if (_Length == 2) \
112         { \
113           *(_Result) = 0; \
114         } \
115         else if (*(ULONG UNALIGNED *)((PUCHAR)(_A) + 2) > *(ULONG UNALIGNED *)((PUCHAR)(_B) + 2)) \
116         { \
117           *(_Result) = 1; \
118         } \
119         else if (*(ULONG UNALIGNED *)((PUCHAR)(_A) + 2) < *(ULONG UNALIGNED *)((PUCHAR)(_B) + 2)) \
120         { \
121           *(_Result) = (UINT)-1; \
122         } \
123         else \
124         { \
125           *(_Result) = 0; \
126         } \
127 }
128
129 #define FDDI_COMPARE_NETWORK_ADDRESSES_EQ(_A, _B, _Length, _Result) \
130 {                                                                   \
131         if ((*(USHORT UNALIGNED *)(_A) == *(USHORT UNALIGNED *)(_B)) && \
132           (((_Length) == 2) || \
133             (*(ULONG UNALIGNED *)((PUCHAR)(_A) + 2) == *(ULONG UNALIGNED *)((PUCHAR)(_B) + 2)))) \
134         { \
135           *(_Result) = 0; \
136         } \
137         else \
138         { \
139           *(_Result) = 1; \
140         } \
141 }
142
143 #define FDDI_COPY_NETWORK_ADDRESS(D, S, AddressLength) \
144 { \
145         PCHAR _D = (D); \
146         PCHAR _S = (S); \
147         UINT _C = (AddressLength); \
148         for ( ; _C > 0 ; _D++, _S++, _C--) \
149         { \
150           *_D = *_S; \
151         } \
152 }
153
154 #define TR_LENGTH_OF_FUNCTIONAL           4
155 #define TR_LENGTH_OF_ADDRESS              6
156
157 typedef ULONG TR_FUNCTIONAL_ADDRESS;
158 typedef ULONG TR_GROUP_ADDRESS;
159
160 #define TR_IS_NOT_DIRECTED(_Address, _Result) \
161 { \
162   *(_Result) = (BOOLEAN)((_Address)[0] & 0x80); \
163 }
164
165 #define TR_IS_FUNCTIONAL(_Address, _Result) \
166 { \
167         *(_Result) = (BOOLEAN)(((_Address)[0] & 0x80) && !((_Address)[2] & 0x80)); \
168 }
169
170 #define TR_IS_GROUP(_Address, _Result) \
171 { \
172   *(_Result) = (BOOLEAN)((_Address)[0] & (_Address)[2] & 0x80); \
173 }
174
175 #define TR_IS_SOURCE_ROUTING(_Address, _Result) \
176 { \
177   *(_Result) = (BOOLEAN)((_Address)[0] & 0x80); \
178 }
179
180 #define TR_IS_MAC_FRAME(_PacketHeader) ((((PUCHAR)_PacketHeader)[1] & 0xFC) == 0)
181
182 #define TR_IS_BROADCAST(_Address, _Result) \
183 { \
184         *(_Result) = (BOOLEAN)(((*(UNALIGNED USHORT *)&(_Address)[0] == 0xFFFF) || \
185                 (*(UNALIGNED USHORT *)&(_Address)[0] == 0x00C0)) && \
186                 (*(UNALIGNED ULONG  *)&(_Address)[2] == 0xFFFFFFFF)); \
187 }
188
189 #define TR_COMPARE_NETWORK_ADDRESSES(_A, _B, _Result) \
190 { \
191         if (*(ULONG UNALIGNED *)&(_A)[2] > *(ULONG UNALIGNED *)&(_B)[2]) \
192         { \
193           *(_Result) = 1; \
194         } \
195         else if (*(ULONG UNALIGNED *)&(_A)[2] < *(ULONG UNALIGNED *)&(_B)[2]) \
196         { \
197           *(_Result) = (UINT)-1; \
198         } \
199         else if (*(USHORT UNALIGNED *)(_A) > *(USHORT UNALIGNED *)(_B)) \
200         { \
201           *(_Result) = 1; \
202         } \
203         else if (*(USHORT UNALIGNED *)(_A) < *(USHORT UNALIGNED *)(_B)) \
204         { \
205           *(_Result) = (UINT)-1; \
206         } \
207         else \
208         { \
209           *(_Result) = 0; \
210         } \
211 }
212
213 #define TR_COPY_NETWORK_ADDRESS(_D, _S) \
214 { \
215         *((ULONG UNALIGNED *)(_D)) = *((ULONG UNALIGNED *)(_S)); \
216         *((USHORT UNALIGNED *)((UCHAR *)(_D)+4)) = *((USHORT UNALIGNED *)((UCHAR *)(_S) + 4)); \
217 }
218
219 #define TR_COMPARE_NETWORK_ADDRESSES_EQ(_A, _B, _Result) \
220 { \
221         if ((*(ULONG UNALIGNED  *)&(_A)[2] == *(ULONG UNALIGNED  *)&(_B)[2]) && \
222             (*(USHORT UNALIGNED *)&(_A)[0] == *(USHORT UNALIGNED *)&(_B)[0])) \
223         { \
224     *(_Result) = 0; \
225         } \
226         else \
227         { \
228     *(_Result) = 1; \
229         } \
230 }
231
232 #ifdef __cplusplus
233 }
234 #endif
235
236 #endif /* __XFILTER_H */