OSDN Git Service

Manual resolution for LICENSE for files already containing a file
[mingw/mingw-org-wsl.git] / include / ddk / xfilter.h
1 /**
2  * @file xfilter.h
3  * @copy 2012 MinGW.org project
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  * 
12  * The above copyright notice and this permission notice (including the next
13  * paragraph) shall be included in all copies or substantial portions of the
14  * Software.
15  * 
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  * DEALINGS IN THE SOFTWARE.
23  */
24
25 /*
26  * Address filtering for NDIS MACs
27  */
28
29 #ifndef __XFILTER_H
30 #define __XFILTER_H
31 #pragma GCC system_header
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37 #include "ntddk.h"
38
39
40 #define ETH_LENGTH_OF_ADDRESS             6
41
42 #define ETH_IS_BROADCAST(Address) \
43   ((((PUCHAR)(Address))[0] == ((UCHAR)0xff)) && (((PUCHAR)(Address))[1] == ((UCHAR)0xff)))
44
45 #define ETH_IS_MULTICAST(Address) \
46   (BOOLEAN)(((PUCHAR)(Address))[0] & ((UCHAR)0x01))
47
48 #define ETH_COMPARE_NETWORK_ADDRESSES(_A, _B, _Result) \
49 { \
50         if (*(ULONG UNALIGNED *)&(_A)[2] > *(ULONG UNALIGNED *)&(_B)[2]) \
51         { \
52     *(_Result) = 1; \
53         } \
54         else if (*(ULONG UNALIGNED *)&(_A)[2] < *(ULONG UNALIGNED *)&(_B)[2]) \
55         { \
56     *(_Result) = (UINT)-1; \
57         } \
58         else if (*(USHORT UNALIGNED *)(_A) > *(USHORT UNALIGNED *)(_B)) \
59         { \
60     *(_Result) = 1; \
61         } \
62         else if (*(USHORT UNALIGNED *)(_A) < *(USHORT UNALIGNED *)(_B)) \
63         { \
64           *(_Result) = (UINT)-1; \
65         } \
66         else \
67         { \
68           *(_Result) = 0; \
69         } \
70 }
71
72 #define ETH_COMPARE_NETWORK_ADDRESSES_EQ(_A,_B, _Result) \
73 { \
74         if ((*(ULONG UNALIGNED *)&(_A)[2] == *(ULONG UNALIGNED *)&(_B)[2]) && \
75     (*(USHORT UNALIGNED *)(_A) == *(USHORT UNALIGNED *)(_B))) \
76         { \
77     *(_Result) = 0; \
78         } \
79         else \
80         { \
81     *(_Result) = 1; \
82         } \
83 }
84
85 #define ETH_COPY_NETWORK_ADDRESS(_D, _S) \
86 { \
87         *((ULONG UNALIGNED *)(_D)) = *((ULONG UNALIGNED *)(_S)); \
88         *((USHORT UNALIGNED *)((UCHAR *)(_D) + 4)) = *((USHORT UNALIGNED *)((UCHAR *)(_S) + 4)); \
89 }
90
91 #define FDDI_LENGTH_OF_LONG_ADDRESS       6
92 #define FDDI_LENGTH_OF_SHORT_ADDRESS      2
93
94 #define FDDI_IS_BROADCAST(Address, AddressLength, Result)   \
95   *Result = ((*(PUCHAR)(Address) == (UCHAR)0xFF) && \
96   (*((PUCHAR)(Address) + 1) == (UCHAR)0xFF))
97
98 #define FDDI_IS_MULTICAST(Address, AddressLength, Result) \
99   *Result = (BOOLEAN)(*(UCHAR *)(Address) & (UCHAR)0x01)
100
101 #define FDDI_IS_SMT(FcByte, Result) \
102 { \
103   *Result = ((FcByte & ((UCHAR)0xf0)) == 0x40); \
104 }
105
106
107 #define FDDI_COMPARE_NETWORK_ADDRESSES(_A, _B, _Length, _Result) \
108 { \
109         if (*(USHORT UNALIGNED *)(_A) > *(USHORT UNALIGNED *)(_B)) \
110         { \
111           *(_Result) = 1; \
112         } \
113         else if (*(USHORT UNALIGNED *)(_A) < *(USHORT UNALIGNED *)(_B)) \
114         { \
115           *(_Result) = (UINT)-1; \
116         } \
117         else if (_Length == 2) \
118         { \
119           *(_Result) = 0; \
120         } \
121         else if (*(ULONG UNALIGNED *)((PUCHAR)(_A) + 2) > *(ULONG UNALIGNED *)((PUCHAR)(_B) + 2)) \
122         { \
123           *(_Result) = 1; \
124         } \
125         else if (*(ULONG UNALIGNED *)((PUCHAR)(_A) + 2) < *(ULONG UNALIGNED *)((PUCHAR)(_B) + 2)) \
126         { \
127           *(_Result) = (UINT)-1; \
128         } \
129         else \
130         { \
131           *(_Result) = 0; \
132         } \
133 }
134
135 #define FDDI_COMPARE_NETWORK_ADDRESSES_EQ(_A, _B, _Length, _Result) \
136 {                                                                   \
137         if ((*(USHORT UNALIGNED *)(_A) == *(USHORT UNALIGNED *)(_B)) && \
138           (((_Length) == 2) || \
139             (*(ULONG UNALIGNED *)((PUCHAR)(_A) + 2) == *(ULONG UNALIGNED *)((PUCHAR)(_B) + 2)))) \
140         { \
141           *(_Result) = 0; \
142         } \
143         else \
144         { \
145           *(_Result) = 1; \
146         } \
147 }
148
149 #define FDDI_COPY_NETWORK_ADDRESS(D, S, AddressLength) \
150 { \
151         PCHAR _D = (D); \
152         PCHAR _S = (S); \
153         UINT _C = (AddressLength); \
154         for ( ; _C > 0 ; _D++, _S++, _C--) \
155         { \
156           *_D = *_S; \
157         } \
158 }
159
160 #define TR_LENGTH_OF_FUNCTIONAL           4
161 #define TR_LENGTH_OF_ADDRESS              6
162
163 typedef ULONG TR_FUNCTIONAL_ADDRESS;
164 typedef ULONG TR_GROUP_ADDRESS;
165
166 #define TR_IS_NOT_DIRECTED(_Address, _Result) \
167 { \
168   *(_Result) = (BOOLEAN)((_Address)[0] & 0x80); \
169 }
170
171 #define TR_IS_FUNCTIONAL(_Address, _Result) \
172 { \
173         *(_Result) = (BOOLEAN)(((_Address)[0] & 0x80) && !((_Address)[2] & 0x80)); \
174 }
175
176 #define TR_IS_GROUP(_Address, _Result) \
177 { \
178   *(_Result) = (BOOLEAN)((_Address)[0] & (_Address)[2] & 0x80); \
179 }
180
181 #define TR_IS_SOURCE_ROUTING(_Address, _Result) \
182 { \
183   *(_Result) = (BOOLEAN)((_Address)[0] & 0x80); \
184 }
185
186 #define TR_IS_MAC_FRAME(_PacketHeader) ((((PUCHAR)_PacketHeader)[1] & 0xFC) == 0)
187
188 #define TR_IS_BROADCAST(_Address, _Result) \
189 { \
190         *(_Result) = (BOOLEAN)(((*(UNALIGNED USHORT *)&(_Address)[0] == 0xFFFF) || \
191                 (*(UNALIGNED USHORT *)&(_Address)[0] == 0x00C0)) && \
192                 (*(UNALIGNED ULONG  *)&(_Address)[2] == 0xFFFFFFFF)); \
193 }
194
195 #define TR_COMPARE_NETWORK_ADDRESSES(_A, _B, _Result) \
196 { \
197         if (*(ULONG UNALIGNED *)&(_A)[2] > *(ULONG UNALIGNED *)&(_B)[2]) \
198         { \
199           *(_Result) = 1; \
200         } \
201         else if (*(ULONG UNALIGNED *)&(_A)[2] < *(ULONG UNALIGNED *)&(_B)[2]) \
202         { \
203           *(_Result) = (UINT)-1; \
204         } \
205         else if (*(USHORT UNALIGNED *)(_A) > *(USHORT UNALIGNED *)(_B)) \
206         { \
207           *(_Result) = 1; \
208         } \
209         else if (*(USHORT UNALIGNED *)(_A) < *(USHORT UNALIGNED *)(_B)) \
210         { \
211           *(_Result) = (UINT)-1; \
212         } \
213         else \
214         { \
215           *(_Result) = 0; \
216         } \
217 }
218
219 #define TR_COPY_NETWORK_ADDRESS(_D, _S) \
220 { \
221         *((ULONG UNALIGNED *)(_D)) = *((ULONG UNALIGNED *)(_S)); \
222         *((USHORT UNALIGNED *)((UCHAR *)(_D)+4)) = *((USHORT UNALIGNED *)((UCHAR *)(_S) + 4)); \
223 }
224
225 #define TR_COMPARE_NETWORK_ADDRESSES_EQ(_A, _B, _Result) \
226 { \
227         if ((*(ULONG UNALIGNED  *)&(_A)[2] == *(ULONG UNALIGNED  *)&(_B)[2]) && \
228             (*(USHORT UNALIGNED *)&(_A)[0] == *(USHORT UNALIGNED *)&(_B)[0])) \
229         { \
230     *(_Result) = 0; \
231         } \
232         else \
233         { \
234     *(_Result) = 1; \
235         } \
236 }
237
238 #ifdef __cplusplus
239 }
240 #endif
241
242 #endif /* __XFILTER_H */