• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #define DESC_TYPE_MESH				3
71 
72 #define LEN_MSG1_2WAY               0x7f
73 #define MAX_LEN_OF_EAP_HS           256
74 
75 #define LEN_MASTER_KEY				32
76 
77 // EAPOL EK, MK
78 #define LEN_EAP_EK					16
79 #define LEN_EAP_MICK				16
80 #define LEN_EAP_KEY					((LEN_EAP_EK)+(LEN_EAP_MICK))
81 // TKIP key related
82 #define LEN_PMKID					16
83 #define LEN_TKIP_EK					16
84 #define LEN_TKIP_RXMICK				8
85 #define LEN_TKIP_TXMICK				8
86 #define LEN_AES_EK					16
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
94 
95 // RSN IE Length definition
96 #define MAX_LEN_OF_RSNIE         	90
97 #define MIN_LEN_OF_RSNIE         	8
98 
99 //EAP Packet Type
100 #define	EAPPacket		0
101 #define	EAPOLStart		1
102 #define	EAPOLLogoff		2
103 #define	EAPOLKey		3
104 #define	EAPOLASFAlert	4
105 #define	EAPTtypeMax		5
106 
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
114 
115 #define PAIRWISEKEY					1
116 #define GROUPKEY					0
117 
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
122 
123 
124 #define EAPOL_START_DISABLE					0
125 #define EAPOL_START_PSK						1
126 #define EAPOL_START_1X						2
127 
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)
132 
133 #define ROUND_UP(__x, __y) \
134 	(((ULONG)((__x)+((__y)-1))) & ((ULONG)~((__y)-1)))
135 
136 #define	ADD_ONE_To_64BIT_VAR(_V)		\
137 {										\
138 	UCHAR	cnt = LEN_KEY_DESC_REPLAY;	\
139 	do									\
140 	{									\
141 		cnt--;							\
142 		_V[cnt]++;						\
143 		if (cnt == 0)					\
144 			break;						\
145 	}while (_V[cnt] == 0);				\
146 }
147 
148 #define IS_WPA_CAPABILITY(a)       (((a) >= Ndis802_11AuthModeWPA) && ((a) <= Ndis802_11AuthModeWPA1PSKWPA2PSK))
149 
150 // EAPOL Key Information definition within Key descriptor format
151 typedef	struct PACKED _KEY_INFO
152 {
153 #ifdef RT_BIG_ENDIAN
154 	UCHAR	KeyAck:1;
155     UCHAR	Install:1;
156     UCHAR	KeyIndex:2;
157     UCHAR	KeyType:1;
158     UCHAR	KeyDescVer:3;
159     UCHAR	Rsvd:3;
160     UCHAR	EKD_DL:1;		// EKD for AP; DL for STA
161     UCHAR	Request:1;
162     UCHAR	Error:1;
163     UCHAR	Secure:1;
164     UCHAR	KeyMic:1;
165 #else
166 	UCHAR	KeyMic:1;
167 	UCHAR	Secure:1;
168 	UCHAR	Error:1;
169 	UCHAR	Request:1;
170 	UCHAR	EKD_DL:1;       // EKD for AP; DL for STA
171 	UCHAR	Rsvd:3;
172 	UCHAR	KeyDescVer:3;
173 	UCHAR	KeyType:1;
174 	UCHAR	KeyIndex:2;
175 	UCHAR	Install:1;
176 	UCHAR	KeyAck:1;
177 #endif
178 }	KEY_INFO, *PKEY_INFO;
179 
180 // EAPOL Key descriptor format
181 typedef	struct PACKED _KEY_DESCRIPTER
182 {
183 	UCHAR		Type;
184 	KEY_INFO	KeyInfo;
185 	UCHAR		KeyLength[2];
186 	UCHAR		ReplayCounter[LEN_KEY_DESC_REPLAY];
187 	UCHAR		KeyNonce[LEN_KEY_DESC_NONCE];
188 	UCHAR		KeyIv[LEN_KEY_DESC_IV];
189 	UCHAR		KeyRsc[LEN_KEY_DESC_RSC];
190 	UCHAR		KeyId[LEN_KEY_DESC_ID];
191 	UCHAR		KeyMic[LEN_KEY_DESC_MIC];
192 	UCHAR		KeyDataLen[2];
193 	UCHAR		KeyData[MAX_LEN_OF_RSNIE];
194 }	KEY_DESCRIPTER, *PKEY_DESCRIPTER;
195 
196 typedef	struct PACKED _EAPOL_PACKET
197 {
198 	UCHAR	 			ProVer;
199 	UCHAR	 			ProType;
200 	UCHAR	 			Body_Len[2];
201 	KEY_DESCRIPTER		KeyDesc;
202 }	EAPOL_PACKET, *PEAPOL_PACKET;
203 
204 //802.11i D10 page 83
205 typedef struct PACKED _GTK_ENCAP
206 {
207 #ifndef RT_BIG_ENDIAN
208     UCHAR               Kid:2;
209     UCHAR               tx:1;
210     UCHAR               rsv:5;
211     UCHAR               rsv1;
212 #else
213     UCHAR               rsv:5;
214     UCHAR               tx:1;
215     UCHAR               Kid:2;
216     UCHAR               rsv1;
217 #endif
218     UCHAR               GTK[TKIP_GTK_LENGTH];
219 }   GTK_ENCAP, *PGTK_ENCAP;
220 
221 typedef struct PACKED _KDE_ENCAP
222 {
223     UCHAR               Type;
224     UCHAR               Len;
225     UCHAR               OUI[3];
226     UCHAR               DataType;
227     GTK_ENCAP      GTKEncap;
228 }   KDE_ENCAP, *PKDE_ENCAP;
229 
230 // For WPA1
231 typedef struct PACKED _RSNIE {
232     UCHAR   oui[4];
233     USHORT  version;
234     UCHAR   mcast[4];
235     USHORT  ucount;
236     struct PACKED {
237         UCHAR oui[4];
238     }ucast[1];
239 } RSNIE, *PRSNIE;
240 
241 // For WPA2
242 typedef struct PACKED _RSNIE2 {
243     USHORT  version;
244     UCHAR   mcast[4];
245     USHORT  ucount;
246     struct PACKED {
247         UCHAR oui[4];
248     }ucast[1];
249 } RSNIE2, *PRSNIE2;
250 
251 // AKM Suite
252 typedef struct PACKED _RSNIE_AUTH {
253     USHORT acount;
254     struct PACKED {
255         UCHAR oui[4];
256     }auth[1];
257 } RSNIE_AUTH,*PRSNIE_AUTH;
258 
259 typedef	union PACKED _RSN_CAPABILITIES	{
260 	struct	PACKED {
261 #ifdef RT_BIG_ENDIAN
262         USHORT		Rsvd:10;
263         USHORT		GTKSA_R_Counter:2;
264         USHORT		PTKSA_R_Counter:2;
265         USHORT		No_Pairwise:1;
266 		USHORT		PreAuth:1;
267 #else
268         USHORT		PreAuth:1;
269 		USHORT		No_Pairwise:1;
270 		USHORT		PTKSA_R_Counter:2;
271 		USHORT		GTKSA_R_Counter:2;
272 		USHORT		Rsvd:10;
273 #endif
274 	}	field;
275 	USHORT			word;
276 }	RSN_CAPABILITIES, *PRSN_CAPABILITIES;
277 
278 typedef struct PACKED _EAP_HDR {
279     UCHAR   ProVer;
280     UCHAR   ProType;
281     UCHAR   Body_Len[2];
282     UCHAR   code;
283     UCHAR   identifier;
284     UCHAR   length[2]; // including code and identifier, followed by length-2 octets of data
285 } EAP_HDR, *PEAP_HDR;
286 
287 // For supplicant state machine states. 802.11i Draft 4.1, p. 97
288 // We simplified it
289 typedef	enum	_WpaState
290 {
291 	SS_NOTUSE,				// 0
292 	SS_START,				// 1
293 	SS_WAIT_MSG_3,			// 2
294 	SS_WAIT_GROUP,			// 3
295 	SS_FINISH,  			// 4
296 	SS_KEYUPDATE,			// 5
297 }	WPA_STATE;
298 
299 //
300 //	The definition of the cipher combination
301 //
302 // 	 bit3	bit2  bit1   bit0
303 //	+------------+------------+
304 // 	|	  WPA	 |	   WPA2   |
305 //	+------+-----+------+-----+
306 //	| TKIP | AES | TKIP | AES |
307 //	|	0  |  1  |   1  |  0  | -> 0x06
308 //	|	0  |  1  |   1  |  1  | -> 0x07
309 //	|	1  |  0  |   0  |  1  | -> 0x09
310 //	|	1  |  0  |   1  |  1  | -> 0x0B
311 //	|	1  |  1  |   0  |  1  | -> 0x0D
312 //	|	1  |  1  |   1  |  0  | -> 0x0E
313 //	|	1  |  1  |   1  |  1  |	-> 0x0F
314 //	+------+-----+------+-----+
315 //
316 typedef	enum	_WpaMixPairCipher
317 {
318 	MIX_CIPHER_NOTUSE 			= 0x00,
319 	WPA_NONE_WPA2_TKIPAES		= 0x03,		// WPA2-TKIPAES
320 	WPA_AES_WPA2_TKIP 			= 0x06,
321 	WPA_AES_WPA2_TKIPAES		= 0x07,
322 	WPA_TKIP_WPA2_AES			= 0x09,
323 	WPA_TKIP_WPA2_TKIPAES		= 0x0B,
324 	WPA_TKIPAES_WPA2_NONE		= 0x0C,		// WPA-TKIPAES
325 	WPA_TKIPAES_WPA2_AES		= 0x0D,
326 	WPA_TKIPAES_WPA2_TKIP		= 0x0E,
327 	WPA_TKIPAES_WPA2_TKIPAES	= 0x0F,
328 }	WPA_MIX_PAIR_CIPHER;
329 
330 typedef struct PACKED _RSN_IE_HEADER_STRUCT	{
331 	UCHAR		Eid;
332 	UCHAR		Length;
333 	USHORT		Version;	// Little endian format
334 }	RSN_IE_HEADER_STRUCT, *PRSN_IE_HEADER_STRUCT;
335 
336 // Cipher suite selector types
337 typedef struct PACKED _CIPHER_SUITE_STRUCT	{
338 	UCHAR		Oui[3];
339 	UCHAR		Type;
340 }	CIPHER_SUITE_STRUCT, *PCIPHER_SUITE_STRUCT;
341 
342 // Authentication and Key Management suite selector
343 typedef struct PACKED _AKM_SUITE_STRUCT	{
344 	UCHAR		Oui[3];
345 	UCHAR		Type;
346 }	AKM_SUITE_STRUCT, *PAKM_SUITE_STRUCT;
347 
348 // RSN capability
349 typedef struct	PACKED _RSN_CAPABILITY	{
350 	USHORT		Rsv:10;
351 	USHORT		GTKSAReplayCnt:2;
352 	USHORT		PTKSAReplayCnt:2;
353 	USHORT		NoPairwise:1;
354 	USHORT		PreAuth:1;
355 }	RSN_CAPABILITY, *PRSN_CAPABILITY;
356 
357 #endif
358