]> bbs.cooldavid.org Git - net-next-2.6.git/blame - drivers/staging/rt2860/wpa.h
Staging: rt28x0: run *.h files through Lindent
[net-next-2.6.git] / drivers / staging / rt2860 / wpa.h
CommitLineData
91980990
GKH
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
91980990
GKH
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))
ca97b838
BZ
92#define MIN_LEN_OF_GTK 5
93#define LEN_PMK 32
94#define LEN_PMK_NAME 16
95#define LEN_NONCE 32
91980990
GKH
96
97// RSN IE Length definition
ca97b838 98#define MAX_LEN_OF_RSNIE 255
91980990
GKH
99#define MIN_LEN_OF_RSNIE 8
100
ca97b838
BZ
101#define KEY_LIFETIME 3600
102
91980990
GKH
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
ca97b838
BZ
127//#ifdef CONFIG_AP_SUPPORT
128// WPA mechanism retry timer interval
52b81c89
BZ
129#define PEER_MSG1_RETRY_EXEC_INTV 1000 // 1 sec
130#define PEER_MSG3_RETRY_EXEC_INTV 3000 // 3 sec
131#define GROUP_KEY_UPDATE_EXEC_INTV 1000 // 1 sec
132#define PEER_GROUP_KEY_UPDATE_INIV 2000 // 2 sec
ca97b838 133
52b81c89 134#define ENQUEUE_EAPOL_START_TIMER 200 // 200 ms
ca97b838
BZ
135
136// group rekey interval
137#define TIME_REKEY 0
138#define PKT_REKEY 1
139#define DISABLE_REKEY 2
140#define MAX_REKEY 2
141
142#define MAX_REKEY_INTER 0x3ffffff
143//#endif // CONFIG_AP_SUPPORT //
144
145#define GROUP_SUITE 0
146#define PAIRWISE_SUITE 1
147#define AKM_SUITE 2
148#define PMKID_LIST 3
149
91980990
GKH
150#define EAPOL_START_DISABLE 0
151#define EAPOL_START_PSK 1
152#define EAPOL_START_1X 2
153
154#define MIX_CIPHER_WPA_TKIP_ON(x) (((x) & 0x08) != 0)
155#define MIX_CIPHER_WPA_AES_ON(x) (((x) & 0x04) != 0)
156#define MIX_CIPHER_WPA2_TKIP_ON(x) (((x) & 0x02) != 0)
157#define MIX_CIPHER_WPA2_AES_ON(x) (((x) & 0x01) != 0)
158
ca97b838 159#ifndef ROUND_UP
91980990
GKH
160#define ROUND_UP(__x, __y) \
161 (((ULONG)((__x)+((__y)-1))) & ((ULONG)~((__y)-1)))
ca97b838
BZ
162#endif
163
164#define SET_UINT16_TO_ARRARY(_V, _LEN) \
165{ \
166 _V[0] = (_LEN & 0xFF00) >> 8; \
167 _V[1] = (_LEN & 0xFF); \
168}
169
170#define INC_UINT16_TO_ARRARY(_V, _LEN) \
171{ \
172 UINT16 var_len; \
173 \
174 var_len = (_V[0]<<8) | (_V[1]); \
175 var_len += _LEN; \
176 \
177 _V[0] = (var_len & 0xFF00) >> 8; \
178 _V[1] = (var_len & 0xFF); \
179}
180
181#define CONV_ARRARY_TO_UINT16(_V) ((_V[0]<<8) | (_V[1]))
182
91980990
GKH
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
52b81c89
BZ
198typedef struct PACKED _KEY_INFO {
199 UCHAR KeyMic:1;
200 UCHAR Secure:1;
201 UCHAR Error:1;
202 UCHAR Request:1;
203 UCHAR EKD_DL:1; // EKD for AP; DL for STA
204 UCHAR Rsvd:3;
205 UCHAR KeyDescVer:3;
206 UCHAR KeyType:1;
207 UCHAR KeyIndex:2;
208 UCHAR Install:1;
209 UCHAR KeyAck:1;
210} KEY_INFO, *PKEY_INFO;
91980990
GKH
211
212// EAPOL Key descriptor format
52b81c89
BZ
213typedef struct PACKED _KEY_DESCRIPTER {
214 UCHAR Type;
215 KEY_INFO KeyInfo;
216 UCHAR KeyLength[2];
217 UCHAR ReplayCounter[LEN_KEY_DESC_REPLAY];
218 UCHAR KeyNonce[LEN_KEY_DESC_NONCE];
219 UCHAR KeyIv[LEN_KEY_DESC_IV];
220 UCHAR KeyRsc[LEN_KEY_DESC_RSC];
221 UCHAR KeyId[LEN_KEY_DESC_ID];
222 UCHAR KeyMic[LEN_KEY_DESC_MIC];
223 UCHAR KeyDataLen[2];
224 UCHAR KeyData[MAX_LEN_OF_RSNIE];
225} KEY_DESCRIPTER, *PKEY_DESCRIPTER;
226
227typedef struct PACKED _EAPOL_PACKET {
228 UCHAR ProVer;
229 UCHAR ProType;
230 UCHAR Body_Len[2];
231 KEY_DESCRIPTER KeyDesc;
232} EAPOL_PACKET, *PEAPOL_PACKET;
91980990
GKH
233
234//802.11i D10 page 83
52b81c89
BZ
235typedef struct PACKED _GTK_ENCAP {
236 UCHAR Kid:2;
237 UCHAR tx:1;
238 UCHAR rsv:5;
239 UCHAR rsv1;
240 UCHAR GTK[TKIP_GTK_LENGTH];
241} GTK_ENCAP, *PGTK_ENCAP;
242
243typedef struct PACKED _KDE_ENCAP {
244 UCHAR Type;
245 UCHAR Len;
246 UCHAR OUI[3];
247 UCHAR DataType;
248 GTK_ENCAP GTKEncap;
249} KDE_ENCAP, *PKDE_ENCAP;
91980990
GKH
250
251// For WPA1
252typedef struct PACKED _RSNIE {
52b81c89
BZ
253 UCHAR oui[4];
254 USHORT version;
255 UCHAR mcast[4];
256 USHORT ucount;
257 struct PACKED {
258 UCHAR oui[4];
259 } ucast[1];
91980990
GKH
260} RSNIE, *PRSNIE;
261
262// For WPA2
263typedef struct PACKED _RSNIE2 {
52b81c89
BZ
264 USHORT version;
265 UCHAR mcast[4];
266 USHORT ucount;
267 struct PACKED {
268 UCHAR oui[4];
269 } ucast[1];
91980990
GKH
270} RSNIE2, *PRSNIE2;
271
272// AKM Suite
273typedef struct PACKED _RSNIE_AUTH {
52b81c89
BZ
274 USHORT acount;
275 struct PACKED {
276 UCHAR oui[4];
277 } auth[1];
278} RSNIE_AUTH, *PRSNIE_AUTH;
279
280typedef union PACKED _RSN_CAPABILITIES {
281 struct PACKED {
282 USHORT PreAuth:1;
283 USHORT No_Pairwise:1;
284 USHORT PTKSA_R_Counter:2;
285 USHORT GTKSA_R_Counter:2;
286 USHORT Rsvd:10;
287 } field;
288 USHORT word;
289} RSN_CAPABILITIES, *PRSN_CAPABILITIES;
91980990
GKH
290
291typedef struct PACKED _EAP_HDR {
52b81c89
BZ
292 UCHAR ProVer;
293 UCHAR ProType;
294 UCHAR Body_Len[2];
295 UCHAR code;
296 UCHAR identifier;
297 UCHAR length[2]; // including code and identifier, followed by length-2 octets of data
91980990
GKH
298} EAP_HDR, *PEAP_HDR;
299
300// For supplicant state machine states. 802.11i Draft 4.1, p. 97
301// We simplified it
52b81c89
BZ
302typedef enum _WpaState {
303 SS_NOTUSE, // 0
304 SS_START, // 1
305 SS_WAIT_MSG_3, // 2
306 SS_WAIT_GROUP, // 3
307 SS_FINISH, // 4
308 SS_KEYUPDATE, // 5
309} WPA_STATE;
91980990
GKH
310
311//
52b81c89 312// The definition of the cipher combination
91980990 313//
52b81c89
BZ
314// bit3 bit2 bit1 bit0
315// +------------+------------+
316// | WPA | WPA2 |
317// +------+-----+------+-----+
318// | TKIP | AES | TKIP | AES |
319// | 0 | 1 | 1 | 0 | -> 0x06
320// | 0 | 1 | 1 | 1 | -> 0x07
321// | 1 | 0 | 0 | 1 | -> 0x09
322// | 1 | 0 | 1 | 1 | -> 0x0B
323// | 1 | 1 | 0 | 1 | -> 0x0D
324// | 1 | 1 | 1 | 0 | -> 0x0E
325// | 1 | 1 | 1 | 1 | -> 0x0F
326// +------+-----+------+-----+
91980990 327//
52b81c89
BZ
328typedef enum _WpaMixPairCipher {
329 MIX_CIPHER_NOTUSE = 0x00,
330 WPA_NONE_WPA2_TKIPAES = 0x03, // WPA2-TKIPAES
331 WPA_AES_WPA2_TKIP = 0x06,
332 WPA_AES_WPA2_TKIPAES = 0x07,
333 WPA_TKIP_WPA2_AES = 0x09,
334 WPA_TKIP_WPA2_TKIPAES = 0x0B,
335 WPA_TKIPAES_WPA2_NONE = 0x0C, // WPA-TKIPAES
336 WPA_TKIPAES_WPA2_AES = 0x0D,
337 WPA_TKIPAES_WPA2_TKIP = 0x0E,
338 WPA_TKIPAES_WPA2_TKIPAES = 0x0F,
339} WPA_MIX_PAIR_CIPHER;
340
341typedef struct PACKED _RSN_IE_HEADER_STRUCT {
342 UCHAR Eid;
343 UCHAR Length;
344 USHORT Version; // Little endian format
345} RSN_IE_HEADER_STRUCT, *PRSN_IE_HEADER_STRUCT;
91980990
GKH
346
347// Cipher suite selector types
52b81c89
BZ
348typedef struct PACKED _CIPHER_SUITE_STRUCT {
349 UCHAR Oui[3];
350 UCHAR Type;
351} CIPHER_SUITE_STRUCT, *PCIPHER_SUITE_STRUCT;
91980990
GKH
352
353// Authentication and Key Management suite selector
52b81c89
BZ
354typedef struct PACKED _AKM_SUITE_STRUCT {
355 UCHAR Oui[3];
356 UCHAR Type;
357} AKM_SUITE_STRUCT, *PAKM_SUITE_STRUCT;
91980990
GKH
358
359// RSN capability
52b81c89
BZ
360typedef struct PACKED _RSN_CAPABILITY {
361 USHORT Rsv:10;
362 USHORT GTKSAReplayCnt:2;
363 USHORT PTKSAReplayCnt:2;
364 USHORT NoPairwise:1;
365 USHORT PreAuth:1;
366} RSN_CAPABILITY, *PRSN_CAPABILITY;
ca97b838
BZ
367
368/*========================================
369 The prototype is defined in cmm_wpa.c
370 ========================================*/
52b81c89
BZ
371BOOLEAN WpaMsgTypeSubst(IN UCHAR EAPType, OUT INT * MsgType);
372
373VOID PRF(IN UCHAR * key,
374 IN INT key_len,
375 IN UCHAR * prefix,
376 IN INT prefix_len,
377 IN UCHAR * data, IN INT data_len, OUT UCHAR * output, IN INT len);
378
379int PasswordHash(char *password,
380 unsigned char *ssid, int ssidlength, unsigned char *output);
381
382PUINT8 GetSuiteFromRSNIE(IN PUINT8 rsnie,
383 IN UINT rsnie_len, IN UINT8 type, OUT UINT8 * count);
384
385VOID WpaShowAllsuite(IN PUINT8 rsnie, IN UINT rsnie_len);
ca97b838 386
52b81c89
BZ
387VOID RTMPInsertRSNIE(IN PUCHAR pFrameBuf,
388 OUT PULONG pFrameLen,
389 IN PUINT8 rsnie_ptr,
390 IN UINT8 rsnie_len,
391 IN PUINT8 pmkid_ptr, IN UINT8 pmkid_len);
ca97b838 392
91980990 393#endif