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