d3bff33ab8b7b8f8530e0b8ae3ed44d0e0e711c0
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / rkwifi / bcmdhd / include / proto / eapol.h
1 /*
2  * 802.1x EAPOL definitions
3  *
4  * See
5  * IEEE Std 802.1X-2001
6  * IEEE 802.1X RADIUS Usage Guidelines
7  *
8  * Copyright Open Broadcom Corporation
9  *
10  * $Id: eapol.h 452703 2014-01-31 20:33:06Z $
11  */
12
13 #ifndef _eapol_h_
14 #define _eapol_h_
15
16 #ifndef _TYPEDEFS_H_
17 #include <typedefs.h>
18 #endif
19
20 /* This marks the start of a packed structure section. */
21 #include <packed_section_start.h>
22
23 #include <bcmcrypto/aeskeywrap.h>
24
25 /* EAPOL for 802.3/Ethernet */
26 typedef BWL_PRE_PACKED_STRUCT struct {
27         struct ether_header eth;        /* 802.3/Ethernet header */
28         unsigned char version;          /* EAPOL protocol version */
29         unsigned char type;             /* EAPOL type */
30         unsigned short length;          /* Length of body */
31         unsigned char body[1];          /* Body (optional) */
32 } BWL_POST_PACKED_STRUCT eapol_header_t;
33
34 #define EAPOL_HEADER_LEN 18
35
36 typedef struct {
37         unsigned char version;          /* EAPOL protocol version */
38         unsigned char type;             /* EAPOL type */
39         unsigned short length;          /* Length of body */
40 } eapol_hdr_t;
41
42 #define EAPOL_HDR_LEN 4
43
44 /* EAPOL version */
45 #define WPA2_EAPOL_VERSION      2
46 #define WPA_EAPOL_VERSION       1
47 #define LEAP_EAPOL_VERSION      1
48 #define SES_EAPOL_VERSION       1
49
50 /* EAPOL types */
51 #define EAP_PACKET              0
52 #define EAPOL_START             1
53 #define EAPOL_LOGOFF            2
54 #define EAPOL_KEY               3
55 #define EAPOL_ASF               4
56
57 /* EAPOL-Key types */
58 #define EAPOL_RC4_KEY           1
59 #define EAPOL_WPA2_KEY          2       /* 802.11i/WPA2 */
60 #define EAPOL_WPA_KEY           254     /* WPA */
61
62 /* RC4 EAPOL-Key header field sizes */
63 #define EAPOL_KEY_REPLAY_LEN    8
64 #define EAPOL_KEY_IV_LEN        16
65 #define EAPOL_KEY_SIG_LEN       16
66
67 /* RC4 EAPOL-Key */
68 typedef BWL_PRE_PACKED_STRUCT struct {
69         unsigned char type;                     /* Key Descriptor Type */
70         unsigned short length;                  /* Key Length (unaligned) */
71         unsigned char replay[EAPOL_KEY_REPLAY_LEN];     /* Replay Counter */
72         unsigned char iv[EAPOL_KEY_IV_LEN];             /* Key IV */
73         unsigned char index;                            /* Key Flags & Index */
74         unsigned char signature[EAPOL_KEY_SIG_LEN];     /* Key Signature */
75         unsigned char key[1];                           /* Key (optional) */
76 } BWL_POST_PACKED_STRUCT eapol_key_header_t;
77
78 #define EAPOL_KEY_HEADER_LEN    44
79
80 /* RC4 EAPOL-Key flags */
81 #define EAPOL_KEY_FLAGS_MASK    0x80
82 #define EAPOL_KEY_BROADCAST     0
83 #define EAPOL_KEY_UNICAST       0x80
84
85 /* RC4 EAPOL-Key index */
86 #define EAPOL_KEY_INDEX_MASK    0x7f
87
88 /* WPA/802.11i/WPA2 EAPOL-Key header field sizes */
89 #define EAPOL_WPA_KEY_REPLAY_LEN        8
90 #define EAPOL_WPA_KEY_NONCE_LEN         32
91 #define EAPOL_WPA_KEY_IV_LEN            16
92 #define EAPOL_WPA_KEY_RSC_LEN           8
93 #define EAPOL_WPA_KEY_ID_LEN            8
94 #define EAPOL_WPA_KEY_MIC_LEN           16
95 #define EAPOL_WPA_KEY_DATA_LEN          (EAPOL_WPA_MAX_KEY_SIZE + AKW_BLOCK_LEN)
96 #define EAPOL_WPA_MAX_KEY_SIZE          32
97
98 /* WPA EAPOL-Key */
99 typedef BWL_PRE_PACKED_STRUCT struct {
100         unsigned char type;             /* Key Descriptor Type */
101         unsigned short key_info;        /* Key Information (unaligned) */
102         unsigned short key_len;         /* Key Length (unaligned) */
103         unsigned char replay[EAPOL_WPA_KEY_REPLAY_LEN]; /* Replay Counter */
104         unsigned char nonce[EAPOL_WPA_KEY_NONCE_LEN];   /* Nonce */
105         unsigned char iv[EAPOL_WPA_KEY_IV_LEN];         /* Key IV */
106         unsigned char rsc[EAPOL_WPA_KEY_RSC_LEN];       /* Key RSC */
107         unsigned char id[EAPOL_WPA_KEY_ID_LEN];         /* WPA:Key ID, 802.11i/WPA2: Reserved */
108         unsigned char mic[EAPOL_WPA_KEY_MIC_LEN];       /* Key MIC */
109         unsigned short data_len;                        /* Key Data Length */
110         unsigned char data[EAPOL_WPA_KEY_DATA_LEN];     /* Key data */
111 } BWL_POST_PACKED_STRUCT eapol_wpa_key_header_t;
112
113 #define EAPOL_WPA_KEY_LEN               95
114
115 /* WPA/802.11i/WPA2 KEY KEY_INFO bits */
116 #define WPA_KEY_DESC_OSEN       0x0
117 #define WPA_KEY_DESC_V1         0x01
118 #define WPA_KEY_DESC_V2         0x02
119 #define WPA_KEY_DESC_V3         0x03
120 #define WPA_KEY_PAIRWISE        0x08
121 #define WPA_KEY_INSTALL         0x40
122 #define WPA_KEY_ACK             0x80
123 #define WPA_KEY_MIC             0x100
124 #define WPA_KEY_SECURE          0x200
125 #define WPA_KEY_ERROR           0x400
126 #define WPA_KEY_REQ             0x800
127
128 #define WPA_KEY_DESC_V2_OR_V3 WPA_KEY_DESC_V2
129
130 /* WPA-only KEY KEY_INFO bits */
131 #define WPA_KEY_INDEX_0         0x00
132 #define WPA_KEY_INDEX_1         0x10
133 #define WPA_KEY_INDEX_2         0x20
134 #define WPA_KEY_INDEX_3         0x30
135 #define WPA_KEY_INDEX_MASK      0x30
136 #define WPA_KEY_INDEX_SHIFT     0x04
137
138 /* 802.11i/WPA2-only KEY KEY_INFO bits */
139 #define WPA_KEY_ENCRYPTED_DATA  0x1000
140
141 /* Key Data encapsulation */
142 typedef BWL_PRE_PACKED_STRUCT struct {
143         uint8 type;
144         uint8 length;
145         uint8 oui[3];
146         uint8 subtype;
147         uint8 data[1];
148 } BWL_POST_PACKED_STRUCT eapol_wpa2_encap_data_t;
149
150 #define EAPOL_WPA2_ENCAP_DATA_HDR_LEN   6
151
152 #define WPA2_KEY_DATA_SUBTYPE_GTK       1
153 #define WPA2_KEY_DATA_SUBTYPE_STAKEY    2
154 #define WPA2_KEY_DATA_SUBTYPE_MAC       3
155 #define WPA2_KEY_DATA_SUBTYPE_PMKID     4
156 #define WPA2_KEY_DATA_SUBTYPE_IGTK      9
157
158 /* GTK encapsulation */
159 typedef BWL_PRE_PACKED_STRUCT struct {
160         uint8   flags;
161         uint8   reserved;
162         uint8   gtk[EAPOL_WPA_MAX_KEY_SIZE];
163 } BWL_POST_PACKED_STRUCT eapol_wpa2_key_gtk_encap_t;
164
165 #define EAPOL_WPA2_KEY_GTK_ENCAP_HDR_LEN        2
166
167 #define WPA2_GTK_INDEX_MASK     0x03
168 #define WPA2_GTK_INDEX_SHIFT    0x00
169
170 #define WPA2_GTK_TRANSMIT       0x04
171
172 /* IGTK encapsulation */
173 typedef BWL_PRE_PACKED_STRUCT struct {
174         uint16  key_id;
175         uint8   ipn[6];
176         uint8   key[EAPOL_WPA_MAX_KEY_SIZE];
177 } BWL_POST_PACKED_STRUCT eapol_wpa2_key_igtk_encap_t;
178
179 #define EAPOL_WPA2_KEY_IGTK_ENCAP_HDR_LEN       8
180
181 /* STAKey encapsulation */
182 typedef BWL_PRE_PACKED_STRUCT struct {
183         uint8   reserved[2];
184         uint8   mac[ETHER_ADDR_LEN];
185         uint8   stakey[EAPOL_WPA_MAX_KEY_SIZE];
186 } BWL_POST_PACKED_STRUCT eapol_wpa2_key_stakey_encap_t;
187
188 #define WPA2_KEY_DATA_PAD       0xdd
189
190
191 /* This marks the end of a packed structure section. */
192 #include <packed_section_end.h>
193
194 #endif /* _eapol_h_ */