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