cbf6b69617d085bedbf0e7aaae8049b7ed8bfed0
[openwrt.git] / package / broadcom-wl / src / driver / 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 (C) 2002 Broadcom Corporation
9  *
10  */
11
12 #ifndef _eapol_h_
13 #define _eapol_h_
14
15 /* enable structure packing */
16 #if defined(__GNUC__)
17 #define PACKED  __attribute__((packed))
18 #else
19 #pragma pack(1)
20 #define PACKED
21 #endif
22
23 #include <bcmcrypto/aeskeywrap.h>
24
25 /* EAPOL for 802.3/Ethernet */
26 typedef 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 } eapol_header_t;
33
34 #define EAPOL_HEADER_LEN 18
35
36 /* EAPOL version */
37 #define WPA2_EAPOL_VERSION      2
38 #define WPA_EAPOL_VERSION       1
39 #define LEAP_EAPOL_VERSION      1
40 #define SES_EAPOL_VERSION       1
41
42 /* EAPOL types */
43 #define EAP_PACKET              0
44 #define EAPOL_START             1
45 #define EAPOL_LOGOFF            2
46 #define EAPOL_KEY               3
47 #define EAPOL_ASF               4
48
49 /* EAPOL-Key types */
50 #define EAPOL_RC4_KEY           1
51 #ifdef BCMWPA2
52 #define EAPOL_WPA2_KEY          2       /* 802.11i/WPA2 */
53 #endif
54 #define EAPOL_WPA_KEY           254     /* WPA */
55
56 /* RC4 EAPOL-Key header field sizes */
57 #define EAPOL_KEY_REPLAY_LEN    8
58 #define EAPOL_KEY_IV_LEN        16
59 #define EAPOL_KEY_SIG_LEN       16
60
61 /* RC4 EAPOL-Key */
62 typedef struct {
63         unsigned char type;                     /* Key Descriptor Type */
64         unsigned short length;                  /* Key Length (unaligned) */
65         unsigned char replay[EAPOL_KEY_REPLAY_LEN];     /* Replay Counter */
66         unsigned char iv[EAPOL_KEY_IV_LEN];             /* Key IV */
67         unsigned char index;                            /* Key Flags & Index */
68         unsigned char signature[EAPOL_KEY_SIG_LEN];     /* Key Signature */
69         unsigned char key[1];                           /* Key (optional) */
70 } PACKED eapol_key_header_t;
71
72 #define EAPOL_KEY_HEADER_LEN    44
73
74 /* RC4 EAPOL-Key flags */
75 #define EAPOL_KEY_FLAGS_MASK    0x80
76 #define EAPOL_KEY_BROADCAST     0
77 #define EAPOL_KEY_UNICAST       0x80
78
79 /* RC4 EAPOL-Key index */
80 #define EAPOL_KEY_INDEX_MASK    0x7f
81
82 /* WPA/802.11i/WPA2 EAPOL-Key header field sizes */
83 #define EAPOL_WPA_KEY_REPLAY_LEN        8
84 #define EAPOL_WPA_KEY_NONCE_LEN         32
85 #define EAPOL_WPA_KEY_IV_LEN            16
86 #define EAPOL_WPA_KEY_RSC_LEN           8
87 #define EAPOL_WPA_KEY_ID_LEN            8
88 #define EAPOL_WPA_KEY_MIC_LEN           16
89 #define EAPOL_WPA_KEY_DATA_LEN          (EAPOL_WPA_MAX_KEY_SIZE + AKW_BLOCK_LEN)
90 #define EAPOL_WPA_MAX_KEY_SIZE          32
91
92 /* WPA EAPOL-Key */
93 typedef struct {
94         unsigned char type;             /* Key Descriptor Type */
95         unsigned short key_info;        /* Key Information (unaligned) */
96         unsigned short key_len;         /* Key Length (unaligned) */
97         unsigned char replay[EAPOL_WPA_KEY_REPLAY_LEN]; /* Replay Counter */
98         unsigned char nonce[EAPOL_WPA_KEY_NONCE_LEN];   /* Nonce */
99         unsigned char iv[EAPOL_WPA_KEY_IV_LEN];         /* Key IV */
100         unsigned char rsc[EAPOL_WPA_KEY_RSC_LEN];       /* Key RSC */
101         unsigned char id[EAPOL_WPA_KEY_ID_LEN];         /* WPA:Key ID, 802.11i/WPA2: Reserved */
102         unsigned char mic[EAPOL_WPA_KEY_MIC_LEN];       /* Key MIC */
103         unsigned short data_len;                        /* Key Data Length */
104         unsigned char data[EAPOL_WPA_KEY_DATA_LEN];     /* Key data */
105 } PACKED eapol_wpa_key_header_t;
106
107 #define EAPOL_WPA_KEY_LEN               95
108
109 /* WPA/802.11i/WPA2 KEY KEY_INFO bits */
110 #define WPA_KEY_DESC_V1         0x01
111 #define WPA_KEY_DESC_V2         0x02
112 #define WPA_KEY_PAIRWISE        0x08
113 #define WPA_KEY_INSTALL         0x40
114 #define WPA_KEY_ACK             0x80
115 #define WPA_KEY_MIC             0x100
116 #define WPA_KEY_SECURE          0x200
117 #define WPA_KEY_ERROR           0x400
118 #define WPA_KEY_REQ             0x800
119
120 /* WPA-only KEY KEY_INFO bits */
121 #define WPA_KEY_INDEX_0         0x00
122 #define WPA_KEY_INDEX_1         0x10
123 #define WPA_KEY_INDEX_2         0x20
124 #define WPA_KEY_INDEX_3         0x30
125 #define WPA_KEY_INDEX_MASK      0x30
126 #define WPA_KEY_INDEX_SHIFT     0x04
127
128 #ifdef BCMWPA2
129 /* 802.11i/WPA2-only KEY KEY_INFO bits */
130 #define WPA_KEY_ENCRYPTED_DATA  0x1000
131
132 /* Key Data encapsulation */
133 typedef struct {
134         uint8 type;
135         uint8 length;
136         uint8 oui[3];
137         uint8 subtype;
138         uint8 data[1];
139 } PACKED eapol_wpa2_encap_data_t;
140
141 #define EAPOL_WPA2_ENCAP_DATA_HDR_LEN   6
142
143 #define WPA2_KEY_DATA_SUBTYPE_GTK       1
144 #define WPA2_KEY_DATA_SUBTYPE_STAKEY    2
145 #define WPA2_KEY_DATA_SUBTYPE_MAC       3
146 #define WPA2_KEY_DATA_SUBTYPE_PMKID     4
147
148 /* GTK encapsulation */
149 typedef struct {
150         uint8   flags;
151         uint8   reserved;
152         uint8   gtk[EAPOL_WPA_MAX_KEY_SIZE];
153 } PACKED eapol_wpa2_key_gtk_encap_t;
154
155 #define EAPOL_WPA2_KEY_GTK_ENCAP_HDR_LEN        2
156
157 #define WPA2_GTK_INDEX_MASK     0x03
158 #define WPA2_GTK_INDEX_SHIFT    0x00
159
160 #define WPA2_GTK_TRANSMIT       0x04
161
162 /* STAKey encapsulation */
163 typedef struct {
164         uint8   reserved[2];
165         uint8   mac[ETHER_ADDR_LEN];
166         uint8   stakey[EAPOL_WPA_MAX_KEY_SIZE];
167 } PACKED eapol_wpa2_key_stakey_encap_t;
168
169 #define WPA2_KEY_DATA_PAD       0xdd
170
171 #endif /* BCMWPA2 */
172
173 #undef PACKED
174 #if !defined(__GNUC__)
175 #pragma pack()
176 #endif
177
178 #endif /* _eapol_h_ */