ath9k: Set IEEE80211_TX_CTL_RATE_CTRL_PROBE in rate control for probe rate
[linux-2.6/cjktty.git] / drivers / staging / rt2860 / wpa.h
blob88c7c8bf3fcd0b03a8b862e8700159591b33c7ea
1 /*
2 *************************************************************************
3 * Ralink Tech Inc.
4 * 5F., No.36, Taiyuan St., Jhubei City,
5 * Hsinchu County 302,
6 * Taiwan, R.O.C.
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. *
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 *************************************************************************
27 Module Name:
28 wpa.h
30 Abstract:
32 Revision History:
33 Who When What
34 -------- ---------- ----------------------------------------------
35 Name Date Modification logs
38 #ifndef __WPA_H__
39 #define __WPA_H__
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)
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
59 // EAPOL frame Protocol Version
60 #define EAPOL_VER 1
61 #define EAPOL_VER2 2
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
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))
94 // RSN IE Length definition
95 #define MAX_LEN_OF_RSNIE 90
96 #define MIN_LEN_OF_RSNIE 8
98 //EAP Packet Type
99 #define EAPPacket 0
100 #define EAPOLStart 1
101 #define EAPOLLogoff 2
102 #define EAPOLKey 3
103 #define EAPOLASFAlert 4
104 #define EAPTtypeMax 5
106 #define EAPOL_MSG_INVALID 0
107 #define EAPOL_PAIR_MSG_1 1
108 #define EAPOL_PAIR_MSG_2 2
109 #define EAPOL_PAIR_MSG_3 3
110 #define EAPOL_PAIR_MSG_4 4
111 #define EAPOL_GROUP_MSG_1 5
112 #define EAPOL_GROUP_MSG_2 6
114 #define PAIRWISEKEY 1
115 #define GROUPKEY 0
117 // Retry timer counter initial value
118 #define PEER_MSG1_RETRY_TIMER_CTR 0
119 #define PEER_MSG3_RETRY_TIMER_CTR 10
120 #define GROUP_MSG1_RETRY_TIMER_CTR 20
123 #define EAPOL_START_DISABLE 0
124 #define EAPOL_START_PSK 1
125 #define EAPOL_START_1X 2
127 #define MIX_CIPHER_WPA_TKIP_ON(x) (((x) & 0x08) != 0)
128 #define MIX_CIPHER_WPA_AES_ON(x) (((x) & 0x04) != 0)
129 #define MIX_CIPHER_WPA2_TKIP_ON(x) (((x) & 0x02) != 0)
130 #define MIX_CIPHER_WPA2_AES_ON(x) (((x) & 0x01) != 0)
132 #define ROUND_UP(__x, __y) \
133 (((ULONG)((__x)+((__y)-1))) & ((ULONG)~((__y)-1)))
135 #define ADD_ONE_To_64BIT_VAR(_V) \
137 UCHAR cnt = LEN_KEY_DESC_REPLAY; \
138 do \
140 cnt--; \
141 _V[cnt]++; \
142 if (cnt == 0) \
143 break; \
144 }while (_V[cnt] == 0); \
147 #define IS_WPA_CAPABILITY(a) (((a) >= Ndis802_11AuthModeWPA) && ((a) <= Ndis802_11AuthModeWPA1PSKWPA2PSK))
149 // EAPOL Key Information definition within Key descriptor format
150 typedef struct PACKED _KEY_INFO
152 #ifdef RT_BIG_ENDIAN
153 UCHAR KeyAck:1;
154 UCHAR Install:1;
155 UCHAR KeyIndex:2;
156 UCHAR KeyType:1;
157 UCHAR KeyDescVer:3;
158 UCHAR Rsvd:3;
159 UCHAR EKD_DL:1; // EKD for AP; DL for STA
160 UCHAR Request:1;
161 UCHAR Error:1;
162 UCHAR Secure:1;
163 UCHAR KeyMic:1;
164 #else
165 UCHAR KeyMic:1;
166 UCHAR Secure:1;
167 UCHAR Error:1;
168 UCHAR Request:1;
169 UCHAR EKD_DL:1; // EKD for AP; DL for STA
170 UCHAR Rsvd:3;
171 UCHAR KeyDescVer:3;
172 UCHAR KeyType:1;
173 UCHAR KeyIndex:2;
174 UCHAR Install:1;
175 UCHAR KeyAck:1;
176 #endif
177 } KEY_INFO, *PKEY_INFO;
179 // EAPOL Key descriptor format
180 typedef struct PACKED _KEY_DESCRIPTER
182 UCHAR Type;
183 KEY_INFO KeyInfo;
184 UCHAR KeyLength[2];
185 UCHAR ReplayCounter[LEN_KEY_DESC_REPLAY];
186 UCHAR KeyNonce[LEN_KEY_DESC_NONCE];
187 UCHAR KeyIv[LEN_KEY_DESC_IV];
188 UCHAR KeyRsc[LEN_KEY_DESC_RSC];
189 UCHAR KeyId[LEN_KEY_DESC_ID];
190 UCHAR KeyMic[LEN_KEY_DESC_MIC];
191 UCHAR KeyDataLen[2];
192 UCHAR KeyData[MAX_LEN_OF_RSNIE];
193 } KEY_DESCRIPTER, *PKEY_DESCRIPTER;
195 typedef struct PACKED _EAPOL_PACKET
197 UCHAR ProVer;
198 UCHAR ProType;
199 UCHAR Body_Len[2];
200 KEY_DESCRIPTER KeyDesc;
201 } EAPOL_PACKET, *PEAPOL_PACKET;
203 //802.11i D10 page 83
204 typedef struct PACKED _GTK_ENCAP
206 #ifndef RT_BIG_ENDIAN
207 UCHAR Kid:2;
208 UCHAR tx:1;
209 UCHAR rsv:5;
210 UCHAR rsv1;
211 #else
212 UCHAR rsv:5;
213 UCHAR tx:1;
214 UCHAR Kid:2;
215 UCHAR rsv1;
216 #endif
217 UCHAR GTK[TKIP_GTK_LENGTH];
218 } GTK_ENCAP, *PGTK_ENCAP;
220 typedef struct PACKED _KDE_ENCAP
222 UCHAR Type;
223 UCHAR Len;
224 UCHAR OUI[3];
225 UCHAR DataType;
226 GTK_ENCAP GTKEncap;
227 } KDE_ENCAP, *PKDE_ENCAP;
229 // For WPA1
230 typedef struct PACKED _RSNIE {
231 UCHAR oui[4];
232 USHORT version;
233 UCHAR mcast[4];
234 USHORT ucount;
235 struct PACKED {
236 UCHAR oui[4];
237 }ucast[1];
238 } RSNIE, *PRSNIE;
240 // For WPA2
241 typedef struct PACKED _RSNIE2 {
242 USHORT version;
243 UCHAR mcast[4];
244 USHORT ucount;
245 struct PACKED {
246 UCHAR oui[4];
247 }ucast[1];
248 } RSNIE2, *PRSNIE2;
250 // AKM Suite
251 typedef struct PACKED _RSNIE_AUTH {
252 USHORT acount;
253 struct PACKED {
254 UCHAR oui[4];
255 }auth[1];
256 } RSNIE_AUTH,*PRSNIE_AUTH;
258 typedef union PACKED _RSN_CAPABILITIES {
259 struct PACKED {
260 #ifdef RT_BIG_ENDIAN
261 USHORT Rsvd:10;
262 USHORT GTKSA_R_Counter:2;
263 USHORT PTKSA_R_Counter:2;
264 USHORT No_Pairwise:1;
265 USHORT PreAuth:1;
266 #else
267 USHORT PreAuth:1;
268 USHORT No_Pairwise:1;
269 USHORT PTKSA_R_Counter:2;
270 USHORT GTKSA_R_Counter:2;
271 USHORT Rsvd:10;
272 #endif
273 } field;
274 USHORT word;
275 } RSN_CAPABILITIES, *PRSN_CAPABILITIES;
277 typedef struct PACKED _EAP_HDR {
278 UCHAR ProVer;
279 UCHAR ProType;
280 UCHAR Body_Len[2];
281 UCHAR code;
282 UCHAR identifier;
283 UCHAR length[2]; // including code and identifier, followed by length-2 octets of data
284 } EAP_HDR, *PEAP_HDR;
286 // For supplicant state machine states. 802.11i Draft 4.1, p. 97
287 // We simplified it
288 typedef enum _WpaState
290 SS_NOTUSE, // 0
291 SS_START, // 1
292 SS_WAIT_MSG_3, // 2
293 SS_WAIT_GROUP, // 3
294 SS_FINISH, // 4
295 SS_KEYUPDATE, // 5
296 } WPA_STATE;
299 // The definition of the cipher combination
301 // bit3 bit2 bit1 bit0
302 // +------------+------------+
303 // | WPA | WPA2 |
304 // +------+-----+------+-----+
305 // | TKIP | AES | TKIP | AES |
306 // | 0 | 1 | 1 | 0 | -> 0x06
307 // | 0 | 1 | 1 | 1 | -> 0x07
308 // | 1 | 0 | 0 | 1 | -> 0x09
309 // | 1 | 0 | 1 | 1 | -> 0x0B
310 // | 1 | 1 | 0 | 1 | -> 0x0D
311 // | 1 | 1 | 1 | 0 | -> 0x0E
312 // | 1 | 1 | 1 | 1 | -> 0x0F
313 // +------+-----+------+-----+
315 typedef enum _WpaMixPairCipher
317 MIX_CIPHER_NOTUSE = 0x00,
318 WPA_NONE_WPA2_TKIPAES = 0x03, // WPA2-TKIPAES
319 WPA_AES_WPA2_TKIP = 0x06,
320 WPA_AES_WPA2_TKIPAES = 0x07,
321 WPA_TKIP_WPA2_AES = 0x09,
322 WPA_TKIP_WPA2_TKIPAES = 0x0B,
323 WPA_TKIPAES_WPA2_NONE = 0x0C, // WPA-TKIPAES
324 WPA_TKIPAES_WPA2_AES = 0x0D,
325 WPA_TKIPAES_WPA2_TKIP = 0x0E,
326 WPA_TKIPAES_WPA2_TKIPAES = 0x0F,
327 } WPA_MIX_PAIR_CIPHER;
329 typedef struct PACKED _RSN_IE_HEADER_STRUCT {
330 UCHAR Eid;
331 UCHAR Length;
332 USHORT Version; // Little endian format
333 } RSN_IE_HEADER_STRUCT, *PRSN_IE_HEADER_STRUCT;
335 // Cipher suite selector types
336 typedef struct PACKED _CIPHER_SUITE_STRUCT {
337 UCHAR Oui[3];
338 UCHAR Type;
339 } CIPHER_SUITE_STRUCT, *PCIPHER_SUITE_STRUCT;
341 // Authentication and Key Management suite selector
342 typedef struct PACKED _AKM_SUITE_STRUCT {
343 UCHAR Oui[3];
344 UCHAR Type;
345 } AKM_SUITE_STRUCT, *PAKM_SUITE_STRUCT;
347 // RSN capability
348 typedef struct PACKED _RSN_CAPABILITY {
349 USHORT Rsv:10;
350 USHORT GTKSAReplayCnt:2;
351 USHORT PTKSAReplayCnt:2;
352 USHORT NoPairwise:1;
353 USHORT PreAuth:1;
354 } RSN_CAPABILITY, *PRSN_CAPABILITY;
356 #endif