2 *************************************************************************
4 * 5F., No.36, Taiyuan St., Jhubei City,
8 * (c) Copyright 2002-2007, Ralink Technology, Inc.
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. *
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. *
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. *
25 *************************************************************************
34 -------- ---------- ----------------------------------------------
35 Name Date Modification logs
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
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)
54 #define EAP_CODE_REQUEST 1
55 #define EAP_CODE_RESPONSE 2
56 #define EAP_CODE_SUCCESS 3
57 #define EAP_CODE_FAILURE 4
59 // EAPOL frame Protocol Version
63 // EAPOL-KEY Descriptor Type
64 #define WPA1_KEY_DESC 0xfe
65 #define WPA2_KEY_DESC 0x02
67 // Key Descriptor Version of Key Information
68 #define DESC_TYPE_TKIP 1
69 #define DESC_TYPE_AES 2
70 #define DESC_TYPE_MESH 3
72 #define LEN_MSG1_2WAY 0x7f
73 #define MAX_LEN_OF_EAP_HS 256
75 #define LEN_MASTER_KEY 32
79 #define LEN_EAP_MICK 16
80 #define LEN_EAP_KEY ((LEN_EAP_EK)+(LEN_EAP_MICK))
83 #define LEN_TKIP_EK 16
84 #define LEN_TKIP_RXMICK 8
85 #define LEN_TKIP_TXMICK 8
87 #define LEN_AES_KEY LEN_AES_EK
88 #define LEN_TKIP_KEY ((LEN_TKIP_EK)+(LEN_TKIP_RXMICK)+(LEN_TKIP_TXMICK))
89 #define TKIP_AP_TXMICK_OFFSET ((LEN_EAP_KEY)+(LEN_TKIP_EK))
90 #define TKIP_AP_RXMICK_OFFSET (TKIP_AP_TXMICK_OFFSET+LEN_TKIP_TXMICK)
91 #define TKIP_GTK_LENGTH ((LEN_TKIP_EK)+(LEN_TKIP_RXMICK)+(LEN_TKIP_TXMICK))
92 #define LEN_PTK ((LEN_EAP_KEY)+(LEN_TKIP_KEY))
93 #define MIN_LEN_OF_GTK 5
95 // RSN IE Length definition
96 #define MAX_LEN_OF_RSNIE 90
97 #define MIN_LEN_OF_RSNIE 8
102 #define EAPOLLogoff 2
104 #define EAPOLASFAlert 4
105 #define EAPTtypeMax 5
107 #define EAPOL_MSG_INVALID 0
108 #define EAPOL_PAIR_MSG_1 1
109 #define EAPOL_PAIR_MSG_2 2
110 #define EAPOL_PAIR_MSG_3 3
111 #define EAPOL_PAIR_MSG_4 4
112 #define EAPOL_GROUP_MSG_1 5
113 #define EAPOL_GROUP_MSG_2 6
115 #define PAIRWISEKEY 1
118 // Retry timer counter initial value
119 #define PEER_MSG1_RETRY_TIMER_CTR 0
120 #define PEER_MSG3_RETRY_TIMER_CTR 10
121 #define GROUP_MSG1_RETRY_TIMER_CTR 20
124 #define EAPOL_START_DISABLE 0
125 #define EAPOL_START_PSK 1
126 #define EAPOL_START_1X 2
128 #define MIX_CIPHER_WPA_TKIP_ON(x) (((x) & 0x08) != 0)
129 #define MIX_CIPHER_WPA_AES_ON(x) (((x) & 0x04) != 0)
130 #define MIX_CIPHER_WPA2_TKIP_ON(x) (((x) & 0x02) != 0)
131 #define MIX_CIPHER_WPA2_AES_ON(x) (((x) & 0x01) != 0)
133 #define ROUND_UP(__x, __y) \
134 (((ULONG)((__x)+((__y)-1))) & ((ULONG)~((__y)-1)))
136 #define ADD_ONE_To_64BIT_VAR(_V) \
138 UCHAR cnt = LEN_KEY_DESC_REPLAY; \
145 }while (_V[cnt] == 0); \
148 #define IS_WPA_CAPABILITY(a) (((a) >= Ndis802_11AuthModeWPA) && ((a) <= Ndis802_11AuthModeWPA1PSKWPA2PSK))
150 // EAPOL Key Information definition within Key descriptor format
151 typedef struct PACKED _KEY_INFO
157 UCHAR EKD_DL:1; // EKD for AP; DL for STA
164 } KEY_INFO, *PKEY_INFO;
166 // EAPOL Key descriptor format
167 typedef struct PACKED _KEY_DESCRIPTER
172 UCHAR ReplayCounter[LEN_KEY_DESC_REPLAY];
173 UCHAR KeyNonce[LEN_KEY_DESC_NONCE];
174 UCHAR KeyIv[LEN_KEY_DESC_IV];
175 UCHAR KeyRsc[LEN_KEY_DESC_RSC];
176 UCHAR KeyId[LEN_KEY_DESC_ID];
177 UCHAR KeyMic[LEN_KEY_DESC_MIC];
179 UCHAR KeyData[MAX_LEN_OF_RSNIE];
180 } KEY_DESCRIPTER, *PKEY_DESCRIPTER;
182 typedef struct PACKED _EAPOL_PACKET
187 KEY_DESCRIPTER KeyDesc;
188 } EAPOL_PACKET, *PEAPOL_PACKET;
190 //802.11i D10 page 83
191 typedef struct PACKED _GTK_ENCAP
197 UCHAR GTK[TKIP_GTK_LENGTH];
198 } GTK_ENCAP, *PGTK_ENCAP;
200 typedef struct PACKED _KDE_ENCAP
207 } KDE_ENCAP, *PKDE_ENCAP;
210 typedef struct PACKED _RSNIE {
221 typedef struct PACKED _RSNIE2 {
231 typedef struct PACKED _RSNIE_AUTH {
236 } RSNIE_AUTH,*PRSNIE_AUTH;
238 typedef union PACKED _RSN_CAPABILITIES {
241 USHORT No_Pairwise:1;
242 USHORT PTKSA_R_Counter:2;
243 USHORT GTKSA_R_Counter:2;
247 } RSN_CAPABILITIES, *PRSN_CAPABILITIES;
249 typedef struct PACKED _EAP_HDR {
255 UCHAR length[2]; // including code and identifier, followed by length-2 octets of data
256 } EAP_HDR, *PEAP_HDR;
258 // For supplicant state machine states. 802.11i Draft 4.1, p. 97
260 typedef enum _WpaState
271 // The definition of the cipher combination
273 // bit3 bit2 bit1 bit0
274 // +------------+------------+
276 // +------+-----+------+-----+
277 // | TKIP | AES | TKIP | AES |
278 // | 0 | 1 | 1 | 0 | -> 0x06
279 // | 0 | 1 | 1 | 1 | -> 0x07
280 // | 1 | 0 | 0 | 1 | -> 0x09
281 // | 1 | 0 | 1 | 1 | -> 0x0B
282 // | 1 | 1 | 0 | 1 | -> 0x0D
283 // | 1 | 1 | 1 | 0 | -> 0x0E
284 // | 1 | 1 | 1 | 1 | -> 0x0F
285 // +------+-----+------+-----+
287 typedef enum _WpaMixPairCipher
289 MIX_CIPHER_NOTUSE = 0x00,
290 WPA_NONE_WPA2_TKIPAES = 0x03, // WPA2-TKIPAES
291 WPA_AES_WPA2_TKIP = 0x06,
292 WPA_AES_WPA2_TKIPAES = 0x07,
293 WPA_TKIP_WPA2_AES = 0x09,
294 WPA_TKIP_WPA2_TKIPAES = 0x0B,
295 WPA_TKIPAES_WPA2_NONE = 0x0C, // WPA-TKIPAES
296 WPA_TKIPAES_WPA2_AES = 0x0D,
297 WPA_TKIPAES_WPA2_TKIP = 0x0E,
298 WPA_TKIPAES_WPA2_TKIPAES = 0x0F,
299 } WPA_MIX_PAIR_CIPHER;
301 typedef struct PACKED _RSN_IE_HEADER_STRUCT {
304 USHORT Version; // Little endian format
305 } RSN_IE_HEADER_STRUCT, *PRSN_IE_HEADER_STRUCT;
307 // Cipher suite selector types
308 typedef struct PACKED _CIPHER_SUITE_STRUCT {
311 } CIPHER_SUITE_STRUCT, *PCIPHER_SUITE_STRUCT;
313 // Authentication and Key Management suite selector
314 typedef struct PACKED _AKM_SUITE_STRUCT {
317 } AKM_SUITE_STRUCT, *PAKM_SUITE_STRUCT;
320 typedef struct PACKED _RSN_CAPABILITY {
322 USHORT GTKSAReplayCnt:2;
323 USHORT PTKSAReplayCnt:2;
326 } RSN_CAPABILITY, *PRSN_CAPABILITY;