OSDN Git Service

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