Import of WPA supplicant 0.4.9
[dragonfly.git] / contrib / wpa_supplicant-0.4.9 / wpa.h
1 /*
2  * wpa_supplicant - WPA definitions
3  * Copyright (c) 2003-2005, Jouni Malinen <jkmaline@cc.hut.fi>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation.
8  *
9  * Alternatively, this software may be distributed under the terms of BSD
10  * license.
11  *
12  * See README and COPYING for more details.
13  */
14
15 #ifndef WPA_H
16 #define WPA_H
17
18 #include "defs.h"
19
20 #define BIT(n) (1 << (n))
21
22 struct ieee802_1x_hdr {
23         u8 version;
24         u8 type;
25         u16 length;
26         /* followed by length octets of data */
27 } __attribute__ ((packed));
28
29 #define EAPOL_VERSION 2
30
31 enum { IEEE802_1X_TYPE_EAP_PACKET = 0,
32        IEEE802_1X_TYPE_EAPOL_START = 1,
33        IEEE802_1X_TYPE_EAPOL_LOGOFF = 2,
34        IEEE802_1X_TYPE_EAPOL_KEY = 3,
35        IEEE802_1X_TYPE_EAPOL_ENCAPSULATED_ASF_ALERT = 4
36 };
37
38 enum { EAPOL_KEY_TYPE_RC4 = 1, EAPOL_KEY_TYPE_RSN = 2,
39        EAPOL_KEY_TYPE_WPA = 254 };
40
41
42 #define WPA_CAPABILITY_PREAUTH BIT(0)
43
44 #define GENERIC_INFO_ELEM 0xdd
45 #define RSN_INFO_ELEM 0x30
46
47 enum {
48         REASON_UNSPECIFIED = 1,
49         REASON_DEAUTH_LEAVING = 3,
50         REASON_INVALID_IE = 13,
51         REASON_MICHAEL_MIC_FAILURE = 14,
52         REASON_4WAY_HANDSHAKE_TIMEOUT = 15,
53         REASON_GROUP_KEY_UPDATE_TIMEOUT = 16,
54         REASON_IE_IN_4WAY_DIFFERS = 17,
55         REASON_GROUP_CIPHER_NOT_VALID = 18,
56         REASON_PAIRWISE_CIPHER_NOT_VALID = 19,
57         REASON_AKMP_NOT_VALID = 20,
58         REASON_UNSUPPORTED_RSN_IE_VERSION = 21,
59         REASON_INVALID_RSN_IE_CAPAB = 22,
60         REASON_IEEE_802_1X_AUTH_FAILED = 23,
61         REASON_CIPHER_SUITE_REJECTED = 24
62 };
63
64 #define PMKID_LEN 16
65
66
67 struct wpa_sm;
68 struct wpa_ssid;
69 struct eapol_sm;
70 struct wpa_config_blob;
71
72 struct wpa_sm_ctx {
73         void *ctx; /* pointer to arbitrary upper level context */
74
75         void (*set_state)(void *ctx, wpa_states state);
76         wpa_states (*get_state)(void *ctx);
77         void (*req_scan)(void *ctx, int sec, int usec);
78         void (*deauthenticate)(void * ctx, int reason_code); 
79         void (*disassociate)(void *ctx, int reason_code);
80         int (*set_key)(void *ctx, wpa_alg alg,
81                        const u8 *addr, int key_idx, int set_tx,
82                        const u8 *seq, size_t seq_len,
83                        const u8 *key, size_t key_len);
84         void (*scan)(void *eloop_ctx, void *timeout_ctx);
85         struct wpa_ssid * (*get_ssid)(void *ctx);
86         int (*get_bssid)(void *ctx, u8 *bssid);
87         int (*ether_send)(void *ctx, const u8 *dest, u16 proto, const u8 *buf,
88                           size_t len);
89         int (*get_beacon_ie)(void *ctx);
90         void (*cancel_auth_timeout)(void *ctx);
91         u8 * (*alloc_eapol)(void *ctx, u8 type, const void *data, u16 data_len,
92                             size_t *msg_len, void **data_pos);
93         int (*add_pmkid)(void *ctx, const u8 *bssid, const u8 *pmkid);
94         int (*remove_pmkid)(void *ctx, const u8 *bssid, const u8 *pmkid);
95         void (*set_config_blob)(void *ctx, struct wpa_config_blob *blob);
96         const struct wpa_config_blob * (*get_config_blob)(void *ctx,
97                                                           const char *name);
98 };
99
100
101 enum wpa_sm_conf_params {
102         RSNA_PMK_LIFETIME /* dot11RSNAConfigPMKLifetime */,
103         RSNA_PMK_REAUTH_THRESHOLD /* dot11RSNAConfigPMKReauthThreshold */,
104         RSNA_SA_TIMEOUT /* dot11RSNAConfigSATimeout */,
105         WPA_PARAM_PROTO,
106         WPA_PARAM_PAIRWISE,
107         WPA_PARAM_GROUP,
108         WPA_PARAM_KEY_MGMT
109 };
110
111 struct wpa_ie_data {
112         int proto;
113         int pairwise_cipher;
114         int group_cipher;
115         int key_mgmt;
116         int capabilities;
117         int num_pmkid;
118         const u8 *pmkid;
119 };
120
121 #ifndef CONFIG_NO_WPA
122
123 struct wpa_sm * wpa_sm_init(struct wpa_sm_ctx *ctx);
124 void wpa_sm_deinit(struct wpa_sm *sm);
125 void wpa_sm_notify_assoc(struct wpa_sm *sm, const u8 *bssid);
126 void wpa_sm_notify_disassoc(struct wpa_sm *sm);
127 void wpa_sm_set_pmk(struct wpa_sm *sm, const u8 *pmk, size_t pmk_len);
128 void wpa_sm_set_pmk_from_pmksa(struct wpa_sm *sm);
129 void wpa_sm_set_fast_reauth(struct wpa_sm *sm, int fast_reauth);
130 void wpa_sm_set_scard_ctx(struct wpa_sm *sm, void *scard_ctx);
131 void wpa_sm_set_config(struct wpa_sm *sm, struct wpa_ssid *config);
132 void wpa_sm_set_own_addr(struct wpa_sm *sm, const u8 *addr);
133 void wpa_sm_set_ifname(struct wpa_sm *sm, const char *ifname);
134 void wpa_sm_set_eapol(struct wpa_sm *sm, struct eapol_sm *eapol);
135 int wpa_sm_set_assoc_wpa_ie(struct wpa_sm *sm, const u8 *ie, size_t len);
136 int wpa_sm_set_assoc_wpa_ie_default(struct wpa_sm *sm, u8 *wpa_ie,
137                                     size_t *wpa_ie_len);
138 int wpa_sm_set_ap_wpa_ie(struct wpa_sm *sm, const u8 *ie, size_t len);
139 int wpa_sm_set_ap_rsn_ie(struct wpa_sm *sm, const u8 *ie, size_t len);
140 int wpa_sm_get_mib(struct wpa_sm *sm, char *buf, size_t buflen);
141
142 int wpa_sm_set_param(struct wpa_sm *sm, enum wpa_sm_conf_params param,
143                      unsigned int value);
144 unsigned int wpa_sm_get_param(struct wpa_sm *sm,
145                               enum wpa_sm_conf_params param);
146
147 int wpa_sm_get_status(struct wpa_sm *sm, char *buf, size_t buflen,
148                       int verbose);
149
150 void wpa_sm_key_request(struct wpa_sm *sm, int error, int pairwise);
151
152 int wpa_parse_wpa_ie(const u8 *wpa_ie, size_t wpa_ie_len,
153                      struct wpa_ie_data *data);
154
155 void wpa_sm_aborted_cached(struct wpa_sm *sm);
156 int wpa_sm_rx_eapol(struct wpa_sm *sm, const u8 *src_addr,
157                     const u8 *buf, size_t len);
158 int wpa_sm_parse_own_wpa_ie(struct wpa_sm *sm, struct wpa_ie_data *data);
159
160 #else /* CONFIG_NO_WPA */
161
162 static inline struct wpa_sm * wpa_sm_init(struct wpa_sm_ctx *ctx)
163 {
164         return (struct wpa_sm *) 1;
165 }
166
167 static inline void wpa_sm_deinit(struct wpa_sm *sm)
168 {
169 }
170
171 static inline void wpa_sm_notify_assoc(struct wpa_sm *sm, const u8 *bssid)
172 {
173 }
174
175 static inline void wpa_sm_notify_disassoc(struct wpa_sm *sm)
176 {
177 }
178
179 static inline void wpa_sm_set_pmk(struct wpa_sm *sm, const u8 *pmk,
180                                   size_t pmk_len)
181 {
182 }
183
184 static inline void wpa_sm_set_pmk_from_pmksa(struct wpa_sm *sm)
185 {
186 }
187
188 static inline void wpa_sm_set_fast_reauth(struct wpa_sm *sm, int fast_reauth)
189 {
190 }
191
192 static inline void wpa_sm_set_scard_ctx(struct wpa_sm *sm, void *scard_ctx)
193 {
194 }
195
196 static inline void wpa_sm_set_config(struct wpa_sm *sm,
197                                      struct wpa_ssid *config)
198 {
199 }
200
201 static inline void wpa_sm_set_own_addr(struct wpa_sm *sm, const u8 *addr)
202 {
203 }
204
205 static inline void wpa_sm_set_ifname(struct wpa_sm *sm, const char *ifname)
206 {
207 }
208
209 static inline void wpa_sm_set_eapol(struct wpa_sm *sm, struct eapol_sm *eapol)
210 {
211 }
212
213 static inline int wpa_sm_set_assoc_wpa_ie(struct wpa_sm *sm, const u8 *ie,
214                                           size_t len)
215 {
216         return -1;
217 }
218
219 static inline int wpa_sm_set_assoc_wpa_ie_default(struct wpa_sm *sm,
220                                                   u8 *wpa_ie,
221                                                   size_t *wpa_ie_len)
222 {
223         return -1;
224 }
225
226 static inline int wpa_sm_set_ap_wpa_ie(struct wpa_sm *sm, const u8 *ie,
227                                        size_t len)
228 {
229         return -1;
230 }
231
232 static inline int wpa_sm_set_ap_rsn_ie(struct wpa_sm *sm, const u8 *ie,
233                                        size_t len)
234 {
235         return -1;
236 }
237
238 static inline int wpa_sm_get_mib(struct wpa_sm *sm, char *buf, size_t buflen)
239 {
240         return 0;
241 }
242
243 static inline int wpa_sm_set_param(struct wpa_sm *sm,
244                                    enum wpa_sm_conf_params param,
245                                    unsigned int value)
246 {
247         return -1;
248 }
249
250 static inline unsigned int wpa_sm_get_param(struct wpa_sm *sm,
251                                             enum wpa_sm_conf_params param)
252 {
253         return 0;
254 }
255
256 static inline int wpa_sm_get_status(struct wpa_sm *sm, char *buf,
257                                     size_t buflen, int verbose)
258 {
259         return 0;
260 }
261
262 static inline void wpa_sm_key_request(struct wpa_sm *sm, int error,
263                                       int pairwise)
264 {
265 }
266
267 static inline int wpa_parse_wpa_ie(const u8 *wpa_ie, size_t wpa_ie_len,
268                                    struct wpa_ie_data *data)
269 {
270         return -1;
271 }
272
273 static inline void wpa_sm_aborted_cached(struct wpa_sm *sm)
274 {
275 }
276
277 static inline int wpa_sm_rx_eapol(struct wpa_sm *sm, const u8 *src_addr,
278                                   const u8 *buf, size_t len)
279 {
280         return -1;
281 }
282
283 static inline int wpa_sm_parse_own_wpa_ie(struct wpa_sm *sm,
284                                           struct wpa_ie_data *data)
285 {
286         return -1;
287 }
288
289 #endif /* CONFIG_NO_WPA */
290
291 #endif /* WPA_H */