]>
Commit | Line | Data |
---|---|---|
36c7928c BZ |
1 | /* |
2 | ************************************************************************* | |
3 | * Ralink Tech Inc. | |
4 | * 5F., No.36, Taiyuan St., Jhubei City, | |
5 | * Hsinchu County 302, | |
6 | * Taiwan, R.O.C. | |
7 | * | |
8 | * (c) Copyright 2002-2007, Ralink Technology, Inc. | |
9 | * | |
10 | * This program is free software; you can redistribute it and/or modify * | |
11 | * it under the terms of the GNU General Public License as published by * | |
12 | * the Free Software Foundation; either version 2 of the License, or * | |
13 | * (at your option) any later version. * | |
14 | * * | |
15 | * This program is distributed in the hope that it will be useful, * | |
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
18 | * GNU General Public License for more details. * | |
19 | * * | |
20 | * You should have received a copy of the GNU General Public License * | |
21 | * along with this program; if not, write to the * | |
22 | * Free Software Foundation, Inc., * | |
23 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * | |
24 | * * | |
25 | ************************************************************************* | |
26 | ||
27 | Module Name: | |
28 | wpa.h | |
29 | ||
30 | Abstract: | |
31 | ||
32 | Revision History: | |
33 | Who When What | |
34 | -------- ---------- ---------------------------------------------- | |
35 | Name Date Modification logs | |
36 | */ | |
37 | ||
38 | #ifndef __WPA_H__ | |
39 | #define __WPA_H__ | |
40 | ||
41 | // EAPOL Key descripter frame format related length | |
42 | #define LEN_KEY_DESC_NONCE 32 | |
43 | #define LEN_KEY_DESC_IV 16 | |
44 | #define LEN_KEY_DESC_RSC 8 | |
45 | #define LEN_KEY_DESC_ID 8 | |
46 | #define LEN_KEY_DESC_REPLAY 8 | |
47 | #define LEN_KEY_DESC_MIC 16 | |
48 | ||
49 | // The length is the EAPoL-Key frame except key data field. | |
50 | // Please refer to 802.11i-2004 ,Figure 43u in p.78 | |
51 | #define LEN_EAPOL_KEY_MSG (sizeof(KEY_DESCRIPTER) - MAX_LEN_OF_RSNIE) | |
52 | ||
53 | // EAP Code Type. | |
54 | #define EAP_CODE_REQUEST 1 | |
55 | #define EAP_CODE_RESPONSE 2 | |
56 | #define EAP_CODE_SUCCESS 3 | |
57 | #define EAP_CODE_FAILURE 4 | |
58 | ||
59 | // EAPOL frame Protocol Version | |
60 | #define EAPOL_VER 1 | |
61 | #define EAPOL_VER2 2 | |
62 | ||
63 | // EAPOL-KEY Descriptor Type | |
64 | #define WPA1_KEY_DESC 0xfe | |
65 | #define WPA2_KEY_DESC 0x02 | |
66 | ||
67 | // Key Descriptor Version of Key Information | |
68 | #define DESC_TYPE_TKIP 1 | |
69 | #define DESC_TYPE_AES 2 | |
70 | ||
71 | #define LEN_MSG1_2WAY 0x7f | |
72 | #define MAX_LEN_OF_EAP_HS 256 | |
73 | ||
74 | #define LEN_MASTER_KEY 32 | |
75 | ||
76 | // EAPOL EK, MK | |
77 | #define LEN_EAP_EK 16 | |
78 | #define LEN_EAP_MICK 16 | |
79 | #define LEN_EAP_KEY ((LEN_EAP_EK)+(LEN_EAP_MICK)) | |
80 | // TKIP key related | |
81 | #define LEN_PMKID 16 | |
82 | #define LEN_TKIP_EK 16 | |
83 | #define LEN_TKIP_RXMICK 8 | |
84 | #define LEN_TKIP_TXMICK 8 | |
85 | #define LEN_AES_EK 16 | |
86 | #define LEN_AES_KEY LEN_AES_EK | |
87 | #define LEN_TKIP_KEY ((LEN_TKIP_EK)+(LEN_TKIP_RXMICK)+(LEN_TKIP_TXMICK)) | |
88 | #define TKIP_AP_TXMICK_OFFSET ((LEN_EAP_KEY)+(LEN_TKIP_EK)) | |
89 | #define TKIP_AP_RXMICK_OFFSET (TKIP_AP_TXMICK_OFFSET+LEN_TKIP_TXMICK) | |
90 | #define TKIP_GTK_LENGTH ((LEN_TKIP_EK)+(LEN_TKIP_RXMICK)+(LEN_TKIP_TXMICK)) | |
91 | #define LEN_PTK ((LEN_EAP_KEY)+(LEN_TKIP_KEY)) | |
92 | #define MIN_LEN_OF_GTK 5 | |
93 | #define LEN_PMK 32 | |
94 | #define LEN_PMK_NAME 16 | |
95 | #define LEN_NONCE 32 | |
96 | ||
97 | // RSN IE Length definition | |
98 | #define MAX_LEN_OF_RSNIE 255 | |
99 | #define MIN_LEN_OF_RSNIE 8 | |
100 | ||
101 | #define KEY_LIFETIME 3600 | |
102 | ||
103 | //EAP Packet Type | |
104 | #define EAPPacket 0 | |
105 | #define EAPOLStart 1 | |
106 | #define EAPOLLogoff 2 | |
107 | #define EAPOLKey 3 | |
108 | #define EAPOLASFAlert 4 | |
109 | #define EAPTtypeMax 5 | |
110 | ||
111 | #define EAPOL_MSG_INVALID 0 | |
112 | #define EAPOL_PAIR_MSG_1 1 | |
113 | #define EAPOL_PAIR_MSG_2 2 | |
114 | #define EAPOL_PAIR_MSG_3 3 | |
115 | #define EAPOL_PAIR_MSG_4 4 | |
116 | #define EAPOL_GROUP_MSG_1 5 | |
117 | #define EAPOL_GROUP_MSG_2 6 | |
118 | ||
119 | #define PAIRWISEKEY 1 | |
120 | #define GROUPKEY 0 | |
121 | ||
122 | // Retry timer counter initial value | |
123 | #define PEER_MSG1_RETRY_TIMER_CTR 0 | |
124 | #define PEER_MSG3_RETRY_TIMER_CTR 10 | |
125 | #define GROUP_MSG1_RETRY_TIMER_CTR 20 | |
126 | ||
127 | // WPA mechanism retry timer interval | |
128 | #define PEER_MSG1_RETRY_EXEC_INTV 1000 // 1 sec | |
129 | #define PEER_MSG3_RETRY_EXEC_INTV 3000 // 3 sec | |
130 | #define GROUP_KEY_UPDATE_EXEC_INTV 1000 // 1 sec | |
131 | #define PEER_GROUP_KEY_UPDATE_INIV 2000 // 2 sec | |
132 | ||
133 | #define ENQUEUE_EAPOL_START_TIMER 200 // 200 ms | |
134 | ||
135 | // group rekey interval | |
136 | #define TIME_REKEY 0 | |
137 | #define PKT_REKEY 1 | |
138 | #define DISABLE_REKEY 2 | |
139 | #define MAX_REKEY 2 | |
140 | ||
141 | #define MAX_REKEY_INTER 0x3ffffff | |
142 | ||
143 | #define GROUP_SUITE 0 | |
144 | #define PAIRWISE_SUITE 1 | |
145 | #define AKM_SUITE 2 | |
146 | #define PMKID_LIST 3 | |
147 | ||
148 | ||
149 | #define EAPOL_START_DISABLE 0 | |
150 | #define EAPOL_START_PSK 1 | |
151 | #define EAPOL_START_1X 2 | |
152 | ||
153 | #define MIX_CIPHER_WPA_TKIP_ON(x) (((x) & 0x08) != 0) | |
154 | #define MIX_CIPHER_WPA_AES_ON(x) (((x) & 0x04) != 0) | |
155 | #define MIX_CIPHER_WPA2_TKIP_ON(x) (((x) & 0x02) != 0) | |
156 | #define MIX_CIPHER_WPA2_AES_ON(x) (((x) & 0x01) != 0) | |
157 | ||
158 | #ifndef ROUND_UP | |
159 | #define ROUND_UP(__x, __y) \ | |
160 | (((ULONG)((__x)+((__y)-1))) & ((ULONG)~((__y)-1))) | |
161 | #endif | |
162 | ||
163 | #define SET_UINT16_TO_ARRARY(_V, _LEN) \ | |
164 | { \ | |
165 | _V[0] = (_LEN & 0xFF00) >> 8; \ | |
166 | _V[1] = (_LEN & 0xFF); \ | |
167 | } | |
168 | ||
169 | #define INC_UINT16_TO_ARRARY(_V, _LEN) \ | |
170 | { \ | |
171 | UINT16 var_len; \ | |
172 | \ | |
173 | var_len = (_V[0]<<8) | (_V[1]); \ | |
174 | var_len += _LEN; \ | |
175 | \ | |
176 | _V[0] = (var_len & 0xFF00) >> 8; \ | |
177 | _V[1] = (var_len & 0xFF); \ | |
178 | } | |
179 | ||
180 | #define CONV_ARRARY_TO_UINT16(_V) ((_V[0]<<8) | (_V[1])) | |
181 | ||
182 | ||
183 | #define ADD_ONE_To_64BIT_VAR(_V) \ | |
184 | { \ | |
185 | UCHAR cnt = LEN_KEY_DESC_REPLAY; \ | |
186 | do \ | |
187 | { \ | |
188 | cnt--; \ | |
189 | _V[cnt]++; \ | |
190 | if (cnt == 0) \ | |
191 | break; \ | |
192 | }while (_V[cnt] == 0); \ | |
193 | } | |
194 | ||
195 | #define IS_WPA_CAPABILITY(a) (((a) >= Ndis802_11AuthModeWPA) && ((a) <= Ndis802_11AuthModeWPA1PSKWPA2PSK)) | |
196 | ||
197 | // EAPOL Key Information definition within Key descriptor format | |
198 | typedef struct PACKED _KEY_INFO | |
199 | { | |
200 | #ifdef RT_BIG_ENDIAN | |
201 | UCHAR KeyAck:1; | |
202 | UCHAR Install:1; | |
203 | UCHAR KeyIndex:2; | |
204 | UCHAR KeyType:1; | |
205 | UCHAR KeyDescVer:3; | |
206 | UCHAR Rsvd:3; | |
207 | UCHAR EKD_DL:1; // EKD for AP; DL for STA | |
208 | UCHAR Request:1; | |
209 | UCHAR Error:1; | |
210 | UCHAR Secure:1; | |
211 | UCHAR KeyMic:1; | |
212 | #else | |
213 | UCHAR KeyMic:1; | |
214 | UCHAR Secure:1; | |
215 | UCHAR Error:1; | |
216 | UCHAR Request:1; | |
217 | UCHAR EKD_DL:1; // EKD for AP; DL for STA | |
218 | UCHAR Rsvd:3; | |
219 | UCHAR KeyDescVer:3; | |
220 | UCHAR KeyType:1; | |
221 | UCHAR KeyIndex:2; | |
222 | UCHAR Install:1; | |
223 | UCHAR KeyAck:1; | |
224 | #endif | |
225 | } KEY_INFO, *PKEY_INFO; | |
226 | ||
227 | // EAPOL Key descriptor format | |
228 | typedef struct PACKED _KEY_DESCRIPTER | |
229 | { | |
230 | UCHAR Type; | |
231 | KEY_INFO KeyInfo; | |
232 | UCHAR KeyLength[2]; | |
233 | UCHAR ReplayCounter[LEN_KEY_DESC_REPLAY]; | |
234 | UCHAR KeyNonce[LEN_KEY_DESC_NONCE]; | |
235 | UCHAR KeyIv[LEN_KEY_DESC_IV]; | |
236 | UCHAR KeyRsc[LEN_KEY_DESC_RSC]; | |
237 | UCHAR KeyId[LEN_KEY_DESC_ID]; | |
238 | UCHAR KeyMic[LEN_KEY_DESC_MIC]; | |
239 | UCHAR KeyDataLen[2]; | |
240 | UCHAR KeyData[MAX_LEN_OF_RSNIE]; | |
241 | } KEY_DESCRIPTER, *PKEY_DESCRIPTER; | |
242 | ||
243 | typedef struct PACKED _EAPOL_PACKET | |
244 | { | |
245 | UCHAR ProVer; | |
246 | UCHAR ProType; | |
247 | UCHAR Body_Len[2]; | |
248 | KEY_DESCRIPTER KeyDesc; | |
249 | } EAPOL_PACKET, *PEAPOL_PACKET; | |
250 | ||
251 | //802.11i D10 page 83 | |
252 | typedef struct PACKED _GTK_ENCAP | |
253 | { | |
254 | #ifndef RT_BIG_ENDIAN | |
255 | UCHAR Kid:2; | |
256 | UCHAR tx:1; | |
257 | UCHAR rsv:5; | |
258 | UCHAR rsv1; | |
259 | #else | |
260 | UCHAR rsv:5; | |
261 | UCHAR tx:1; | |
262 | UCHAR Kid:2; | |
263 | UCHAR rsv1; | |
264 | #endif | |
265 | UCHAR GTK[TKIP_GTK_LENGTH]; | |
266 | } GTK_ENCAP, *PGTK_ENCAP; | |
267 | ||
268 | typedef struct PACKED _KDE_ENCAP | |
269 | { | |
270 | UCHAR Type; | |
271 | UCHAR Len; | |
272 | UCHAR OUI[3]; | |
273 | UCHAR DataType; | |
274 | GTK_ENCAP GTKEncap; | |
275 | } KDE_ENCAP, *PKDE_ENCAP; | |
276 | ||
277 | // For WPA1 | |
278 | typedef struct PACKED _RSNIE { | |
279 | UCHAR oui[4]; | |
280 | USHORT version; | |
281 | UCHAR mcast[4]; | |
282 | USHORT ucount; | |
283 | struct PACKED { | |
284 | UCHAR oui[4]; | |
285 | }ucast[1]; | |
286 | } RSNIE, *PRSNIE; | |
287 | ||
288 | // For WPA2 | |
289 | typedef struct PACKED _RSNIE2 { | |
290 | USHORT version; | |
291 | UCHAR mcast[4]; | |
292 | USHORT ucount; | |
293 | struct PACKED { | |
294 | UCHAR oui[4]; | |
295 | }ucast[1]; | |
296 | } RSNIE2, *PRSNIE2; | |
297 | ||
298 | // AKM Suite | |
299 | typedef struct PACKED _RSNIE_AUTH { | |
300 | USHORT acount; | |
301 | struct PACKED { | |
302 | UCHAR oui[4]; | |
303 | }auth[1]; | |
304 | } RSNIE_AUTH,*PRSNIE_AUTH; | |
305 | ||
306 | typedef union PACKED _RSN_CAPABILITIES { | |
307 | struct PACKED { | |
308 | #ifdef RT_BIG_ENDIAN | |
309 | USHORT Rsvd:10; | |
310 | USHORT GTKSA_R_Counter:2; | |
311 | USHORT PTKSA_R_Counter:2; | |
312 | USHORT No_Pairwise:1; | |
313 | USHORT PreAuth:1; | |
314 | #else | |
315 | USHORT PreAuth:1; | |
316 | USHORT No_Pairwise:1; | |
317 | USHORT PTKSA_R_Counter:2; | |
318 | USHORT GTKSA_R_Counter:2; | |
319 | USHORT Rsvd:10; | |
320 | #endif | |
321 | } field; | |
322 | USHORT word; | |
323 | } RSN_CAPABILITIES, *PRSN_CAPABILITIES; | |
324 | ||
325 | typedef struct PACKED _EAP_HDR { | |
326 | UCHAR ProVer; | |
327 | UCHAR ProType; | |
328 | UCHAR Body_Len[2]; | |
329 | UCHAR code; | |
330 | UCHAR identifier; | |
331 | UCHAR length[2]; // including code and identifier, followed by length-2 octets of data | |
332 | } EAP_HDR, *PEAP_HDR; | |
333 | ||
334 | // For supplicant state machine states. 802.11i Draft 4.1, p. 97 | |
335 | // We simplified it | |
336 | typedef enum _WpaState | |
337 | { | |
338 | SS_NOTUSE, // 0 | |
339 | SS_START, // 1 | |
340 | SS_WAIT_MSG_3, // 2 | |
341 | SS_WAIT_GROUP, // 3 | |
342 | SS_FINISH, // 4 | |
343 | SS_KEYUPDATE, // 5 | |
344 | } WPA_STATE; | |
345 | ||
346 | // | |
347 | // The definition of the cipher combination | |
348 | // | |
349 | // bit3 bit2 bit1 bit0 | |
350 | // +------------+------------+ | |
351 | // | WPA | WPA2 | | |
352 | // +------+-----+------+-----+ | |
353 | // | TKIP | AES | TKIP | AES | | |
354 | // | 0 | 1 | 1 | 0 | -> 0x06 | |
355 | // | 0 | 1 | 1 | 1 | -> 0x07 | |
356 | // | 1 | 0 | 0 | 1 | -> 0x09 | |
357 | // | 1 | 0 | 1 | 1 | -> 0x0B | |
358 | // | 1 | 1 | 0 | 1 | -> 0x0D | |
359 | // | 1 | 1 | 1 | 0 | -> 0x0E | |
360 | // | 1 | 1 | 1 | 1 | -> 0x0F | |
361 | // +------+-----+------+-----+ | |
362 | // | |
363 | typedef enum _WpaMixPairCipher | |
364 | { | |
365 | MIX_CIPHER_NOTUSE = 0x00, | |
366 | WPA_NONE_WPA2_TKIPAES = 0x03, // WPA2-TKIPAES | |
367 | WPA_AES_WPA2_TKIP = 0x06, | |
368 | WPA_AES_WPA2_TKIPAES = 0x07, | |
369 | WPA_TKIP_WPA2_AES = 0x09, | |
370 | WPA_TKIP_WPA2_TKIPAES = 0x0B, | |
371 | WPA_TKIPAES_WPA2_NONE = 0x0C, // WPA-TKIPAES | |
372 | WPA_TKIPAES_WPA2_AES = 0x0D, | |
373 | WPA_TKIPAES_WPA2_TKIP = 0x0E, | |
374 | WPA_TKIPAES_WPA2_TKIPAES = 0x0F, | |
375 | } WPA_MIX_PAIR_CIPHER; | |
376 | ||
377 | typedef struct PACKED _RSN_IE_HEADER_STRUCT { | |
378 | UCHAR Eid; | |
379 | UCHAR Length; | |
380 | USHORT Version; // Little endian format | |
381 | } RSN_IE_HEADER_STRUCT, *PRSN_IE_HEADER_STRUCT; | |
382 | ||
383 | // Cipher suite selector types | |
384 | typedef struct PACKED _CIPHER_SUITE_STRUCT { | |
385 | UCHAR Oui[3]; | |
386 | UCHAR Type; | |
387 | } CIPHER_SUITE_STRUCT, *PCIPHER_SUITE_STRUCT; | |
388 | ||
389 | // Authentication and Key Management suite selector | |
390 | typedef struct PACKED _AKM_SUITE_STRUCT { | |
391 | UCHAR Oui[3]; | |
392 | UCHAR Type; | |
393 | } AKM_SUITE_STRUCT, *PAKM_SUITE_STRUCT; | |
394 | ||
395 | // RSN capability | |
396 | typedef struct PACKED _RSN_CAPABILITY { | |
397 | USHORT Rsv:10; | |
398 | USHORT GTKSAReplayCnt:2; | |
399 | USHORT PTKSAReplayCnt:2; | |
400 | USHORT NoPairwise:1; | |
401 | USHORT PreAuth:1; | |
402 | } RSN_CAPABILITY, *PRSN_CAPABILITY; | |
403 | ||
404 | ||
405 | /*======================================== | |
406 | The prototype is defined in cmm_wpa.c | |
407 | ========================================*/ | |
408 | BOOLEAN WpaMsgTypeSubst( | |
409 | IN UCHAR EAPType, | |
410 | OUT INT *MsgType); | |
411 | ||
412 | VOID PRF( | |
413 | IN UCHAR *key, | |
414 | IN INT key_len, | |
415 | IN UCHAR *prefix, | |
416 | IN INT prefix_len, | |
417 | IN UCHAR *data, | |
418 | IN INT data_len, | |
419 | OUT UCHAR *output, | |
420 | IN INT len); | |
421 | ||
422 | int PasswordHash( | |
423 | char *password, | |
424 | unsigned char *ssid, | |
425 | int ssidlength, | |
426 | unsigned char *output); | |
427 | ||
428 | PUINT8 GetSuiteFromRSNIE( | |
429 | IN PUINT8 rsnie, | |
430 | IN UINT rsnie_len, | |
431 | IN UINT8 type, | |
432 | OUT UINT8 *count); | |
433 | ||
434 | VOID WpaShowAllsuite( | |
435 | IN PUINT8 rsnie, | |
436 | IN UINT rsnie_len); | |
437 | ||
438 | VOID RTMPInsertRSNIE( | |
439 | IN PUCHAR pFrameBuf, | |
440 | OUT PULONG pFrameLen, | |
441 | IN PUINT8 rsnie_ptr, | |
442 | IN UINT8 rsnie_len, | |
443 | IN PUINT8 pmkid_ptr, | |
444 | IN UINT8 pmkid_len); | |
445 | ||
446 | ||
447 | #endif |