f9c89b3678cdebd5cc2b3da2526ab46c0ca2b2d6
[mech_eap.git] / src / rsn_supp / wpa.h
1 /*
2  * wpa_supplicant - WPA definitions
3  * Copyright (c) 2003-2015, Jouni Malinen <j@w1.fi>
4  *
5  * This software may be distributed under the terms of the BSD license.
6  * See README for more details.
7  */
8
9 #ifndef WPA_H
10 #define WPA_H
11
12 #include "common/defs.h"
13 #include "common/eapol_common.h"
14 #include "common/wpa_common.h"
15 #include "common/ieee802_11_defs.h"
16
17 struct wpa_sm;
18 struct eapol_sm;
19 struct wpa_config_blob;
20 struct hostapd_freq_params;
21
22 struct wpa_sm_ctx {
23         void *ctx; /* pointer to arbitrary upper level context */
24         void *msg_ctx; /* upper level context for wpa_msg() calls */
25
26         void (*set_state)(void *ctx, enum wpa_states state);
27         enum wpa_states (*get_state)(void *ctx);
28         void (*deauthenticate)(void * ctx, int reason_code); 
29         int (*set_key)(void *ctx, enum wpa_alg alg,
30                        const u8 *addr, int key_idx, int set_tx,
31                        const u8 *seq, size_t seq_len,
32                        const u8 *key, size_t key_len);
33         void * (*get_network_ctx)(void *ctx);
34         int (*get_bssid)(void *ctx, u8 *bssid);
35         int (*ether_send)(void *ctx, const u8 *dest, u16 proto, const u8 *buf,
36                           size_t len);
37         int (*get_beacon_ie)(void *ctx);
38         void (*cancel_auth_timeout)(void *ctx);
39         u8 * (*alloc_eapol)(void *ctx, u8 type, const void *data, u16 data_len,
40                             size_t *msg_len, void **data_pos);
41         int (*add_pmkid)(void *ctx, const u8 *bssid, const u8 *pmkid);
42         int (*remove_pmkid)(void *ctx, const u8 *bssid, const u8 *pmkid);
43         void (*set_config_blob)(void *ctx, struct wpa_config_blob *blob);
44         const struct wpa_config_blob * (*get_config_blob)(void *ctx,
45                                                           const char *name);
46         int (*mlme_setprotection)(void *ctx, const u8 *addr,
47                                   int protection_type, int key_type);
48         int (*update_ft_ies)(void *ctx, const u8 *md, const u8 *ies,
49                              size_t ies_len);
50         int (*send_ft_action)(void *ctx, u8 action, const u8 *target_ap,
51                               const u8 *ies, size_t ies_len);
52         int (*mark_authenticated)(void *ctx, const u8 *target_ap);
53 #ifdef CONFIG_TDLS
54         int (*tdls_get_capa)(void *ctx, int *tdls_supported,
55                              int *tdls_ext_setup, int *tdls_chan_switch);
56         int (*send_tdls_mgmt)(void *ctx, const u8 *dst,
57                               u8 action_code, u8 dialog_token,
58                               u16 status_code, u32 peer_capab,
59                               int initiator, const u8 *buf, size_t len);
60         int (*tdls_oper)(void *ctx, int oper, const u8 *peer);
61         int (*tdls_peer_addset)(void *ctx, const u8 *addr, int add, u16 aid,
62                                 u16 capability, const u8 *supp_rates,
63                                 size_t supp_rates_len,
64                                 const struct ieee80211_ht_capabilities *ht_capab,
65                                 const struct ieee80211_vht_capabilities *vht_capab,
66                                 u8 qosinfo, int wmm, const u8 *ext_capab,
67                                 size_t ext_capab_len, const u8 *supp_channels,
68                                 size_t supp_channels_len,
69                                 const u8 *supp_oper_classes,
70                                 size_t supp_oper_classes_len);
71         int (*tdls_enable_channel_switch)(
72                 void *ctx, const u8 *addr, u8 oper_class,
73                 const struct hostapd_freq_params *params);
74         int (*tdls_disable_channel_switch)(void *ctx, const u8 *addr);
75 #endif /* CONFIG_TDLS */
76         void (*set_rekey_offload)(void *ctx, const u8 *kek, size_t kek_len,
77                                   const u8 *kck, size_t kck_len,
78                                   const u8 *replay_ctr);
79         int (*key_mgmt_set_pmk)(void *ctx, const u8 *pmk, size_t pmk_len);
80 };
81
82
83 enum wpa_sm_conf_params {
84         RSNA_PMK_LIFETIME /* dot11RSNAConfigPMKLifetime */,
85         RSNA_PMK_REAUTH_THRESHOLD /* dot11RSNAConfigPMKReauthThreshold */,
86         RSNA_SA_TIMEOUT /* dot11RSNAConfigSATimeout */,
87         WPA_PARAM_PROTO,
88         WPA_PARAM_PAIRWISE,
89         WPA_PARAM_GROUP,
90         WPA_PARAM_KEY_MGMT,
91         WPA_PARAM_MGMT_GROUP,
92         WPA_PARAM_RSN_ENABLED,
93         WPA_PARAM_MFP
94 };
95
96 struct rsn_supp_config {
97         void *network_ctx;
98         int peerkey_enabled;
99         int allowed_pairwise_cipher; /* bitfield of WPA_CIPHER_* */
100         int proactive_key_caching;
101         int eap_workaround;
102         void *eap_conf_ctx;
103         const u8 *ssid;
104         size_t ssid_len;
105         int wpa_ptk_rekey;
106         int p2p;
107         int wpa_rsc_relaxation;
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                     const u8 *bssid);
118 void wpa_sm_set_pmk_from_pmksa(struct wpa_sm *sm);
119 void wpa_sm_set_fast_reauth(struct wpa_sm *sm, int fast_reauth);
120 void wpa_sm_set_scard_ctx(struct wpa_sm *sm, void *scard_ctx);
121 void wpa_sm_set_config(struct wpa_sm *sm, struct rsn_supp_config *config);
122 void wpa_sm_set_own_addr(struct wpa_sm *sm, const u8 *addr);
123 void wpa_sm_set_ifname(struct wpa_sm *sm, const char *ifname,
124                        const char *bridge_ifname);
125 void wpa_sm_set_eapol(struct wpa_sm *sm, struct eapol_sm *eapol);
126 int wpa_sm_set_assoc_wpa_ie(struct wpa_sm *sm, const u8 *ie, size_t len);
127 int wpa_sm_set_assoc_wpa_ie_default(struct wpa_sm *sm, u8 *wpa_ie,
128                                     size_t *wpa_ie_len);
129 int wpa_sm_set_ap_wpa_ie(struct wpa_sm *sm, const u8 *ie, size_t len);
130 int wpa_sm_set_ap_rsn_ie(struct wpa_sm *sm, const u8 *ie, size_t len);
131 int wpa_sm_get_mib(struct wpa_sm *sm, char *buf, size_t buflen);
132
133 int wpa_sm_set_param(struct wpa_sm *sm, enum wpa_sm_conf_params param,
134                      unsigned int value);
135
136 int wpa_sm_get_status(struct wpa_sm *sm, char *buf, size_t buflen,
137                       int verbose);
138 int wpa_sm_pmf_enabled(struct wpa_sm *sm);
139
140 void wpa_sm_key_request(struct wpa_sm *sm, int error, int pairwise);
141
142 int wpa_parse_wpa_ie(const u8 *wpa_ie, size_t wpa_ie_len,
143                      struct wpa_ie_data *data);
144
145 void wpa_sm_aborted_cached(struct wpa_sm *sm);
146 int wpa_sm_rx_eapol(struct wpa_sm *sm, const u8 *src_addr,
147                     const u8 *buf, size_t len);
148 int wpa_sm_parse_own_wpa_ie(struct wpa_sm *sm, struct wpa_ie_data *data);
149 int wpa_sm_pmksa_cache_list(struct wpa_sm *sm, char *buf, size_t len);
150 void wpa_sm_drop_sa(struct wpa_sm *sm);
151 int wpa_sm_has_ptk(struct wpa_sm *sm);
152
153 void wpa_sm_update_replay_ctr(struct wpa_sm *sm, const u8 *replay_ctr);
154
155 void wpa_sm_pmksa_cache_flush(struct wpa_sm *sm, void *network_ctx);
156
157 int wpa_sm_get_p2p_ip_addr(struct wpa_sm *sm, u8 *buf);
158
159 void wpa_sm_set_rx_replay_ctr(struct wpa_sm *sm, const u8 *rx_replay_counter);
160 void wpa_sm_set_ptk_kck_kek(struct wpa_sm *sm,
161                             const u8 *ptk_kck, size_t ptk_kck_len,
162                             const u8 *ptk_kek, size_t ptk_kek_len);
163
164 #else /* CONFIG_NO_WPA */
165
166 static inline struct wpa_sm * wpa_sm_init(struct wpa_sm_ctx *ctx)
167 {
168         return (struct wpa_sm *) 1;
169 }
170
171 static inline void wpa_sm_deinit(struct wpa_sm *sm)
172 {
173 }
174
175 static inline void wpa_sm_notify_assoc(struct wpa_sm *sm, const u8 *bssid)
176 {
177 }
178
179 static inline void wpa_sm_notify_disassoc(struct wpa_sm *sm)
180 {
181 }
182
183 static inline void wpa_sm_set_pmk(struct wpa_sm *sm, const u8 *pmk,
184                                   size_t pmk_len, const u8 *bssid)
185 {
186 }
187
188 static inline void wpa_sm_set_pmk_from_pmksa(struct wpa_sm *sm)
189 {
190 }
191
192 static inline void wpa_sm_set_fast_reauth(struct wpa_sm *sm, int fast_reauth)
193 {
194 }
195
196 static inline void wpa_sm_set_scard_ctx(struct wpa_sm *sm, void *scard_ctx)
197 {
198 }
199
200 static inline void wpa_sm_set_config(struct wpa_sm *sm,
201                                      struct rsn_supp_config *config)
202 {
203 }
204
205 static inline void wpa_sm_set_own_addr(struct wpa_sm *sm, const u8 *addr)
206 {
207 }
208
209 static inline void wpa_sm_set_ifname(struct wpa_sm *sm, const char *ifname,
210                                      const char *bridge_ifname)
211 {
212 }
213
214 static inline void wpa_sm_set_eapol(struct wpa_sm *sm, struct eapol_sm *eapol)
215 {
216 }
217
218 static inline int wpa_sm_set_assoc_wpa_ie(struct wpa_sm *sm, const u8 *ie,
219                                           size_t len)
220 {
221         return -1;
222 }
223
224 static inline int wpa_sm_set_assoc_wpa_ie_default(struct wpa_sm *sm,
225                                                   u8 *wpa_ie,
226                                                   size_t *wpa_ie_len)
227 {
228         return -1;
229 }
230
231 static inline int wpa_sm_set_ap_wpa_ie(struct wpa_sm *sm, const u8 *ie,
232                                        size_t len)
233 {
234         return -1;
235 }
236
237 static inline int wpa_sm_set_ap_rsn_ie(struct wpa_sm *sm, const u8 *ie,
238                                        size_t len)
239 {
240         return -1;
241 }
242
243 static inline int wpa_sm_get_mib(struct wpa_sm *sm, char *buf, size_t buflen)
244 {
245         return 0;
246 }
247
248 static inline int wpa_sm_set_param(struct wpa_sm *sm,
249                                    enum wpa_sm_conf_params param,
250                                    unsigned int value)
251 {
252         return -1;
253 }
254
255 static inline int wpa_sm_get_status(struct wpa_sm *sm, char *buf,
256                                     size_t buflen, int verbose)
257 {
258         return 0;
259 }
260
261 static inline int wpa_sm_pmf_enabled(struct wpa_sm *sm)
262 {
263         return 0;
264 }
265
266 static inline void wpa_sm_key_request(struct wpa_sm *sm, int error,
267                                       int pairwise)
268 {
269 }
270
271 static inline int wpa_parse_wpa_ie(const u8 *wpa_ie, size_t wpa_ie_len,
272                                    struct wpa_ie_data *data)
273 {
274         return -1;
275 }
276
277 static inline void wpa_sm_aborted_cached(struct wpa_sm *sm)
278 {
279 }
280
281 static inline int wpa_sm_rx_eapol(struct wpa_sm *sm, const u8 *src_addr,
282                                   const u8 *buf, size_t len)
283 {
284         return -1;
285 }
286
287 static inline int wpa_sm_parse_own_wpa_ie(struct wpa_sm *sm,
288                                           struct wpa_ie_data *data)
289 {
290         return -1;
291 }
292
293 static inline int wpa_sm_pmksa_cache_list(struct wpa_sm *sm, char *buf,
294                                           size_t len)
295 {
296         return -1;
297 }
298
299 static inline void wpa_sm_drop_sa(struct wpa_sm *sm)
300 {
301 }
302
303 static inline int wpa_sm_has_ptk(struct wpa_sm *sm)
304 {
305         return 0;
306 }
307
308 static inline void wpa_sm_update_replay_ctr(struct wpa_sm *sm,
309                                             const u8 *replay_ctr)
310 {
311 }
312
313 static inline void wpa_sm_pmksa_cache_flush(struct wpa_sm *sm,
314                                             void *network_ctx)
315 {
316 }
317
318 static inline void wpa_sm_set_rx_replay_ctr(struct wpa_sm *sm,
319                                             const u8 *rx_replay_counter)
320 {
321 }
322
323 static inline void wpa_sm_set_ptk_kck_kek(struct wpa_sm *sm, const u8 *ptk_kck,
324                                           size_t ptk_kck_len,
325                                           const u8 *ptk_kek, size_t ptk_kek_len)
326 {
327 }
328
329 #endif /* CONFIG_NO_WPA */
330
331 #ifdef CONFIG_PEERKEY
332 int wpa_sm_stkstart(struct wpa_sm *sm, const u8 *peer);
333 int wpa_sm_rx_eapol_peerkey(struct wpa_sm *sm, const u8 *src_addr,
334                             const u8 *buf, size_t len);
335 #else /* CONFIG_PEERKEY */
336 static inline int wpa_sm_stkstart(struct wpa_sm *sm, const u8 *peer)
337 {
338         return -1;
339 }
340
341 static inline int wpa_sm_rx_eapol_peerkey(struct wpa_sm *sm, const u8 *src_addr,
342                                           const u8 *buf, size_t len)
343 {
344         return 0;
345 }
346 #endif /* CONFIG_PEERKEY */
347
348 #ifdef CONFIG_IEEE80211R
349
350 int wpa_sm_set_ft_params(struct wpa_sm *sm, const u8 *ies, size_t ies_len);
351 int wpa_ft_prepare_auth_request(struct wpa_sm *sm, const u8 *mdie);
352 int wpa_ft_process_response(struct wpa_sm *sm, const u8 *ies, size_t ies_len,
353                             int ft_action, const u8 *target_ap,
354                             const u8 *ric_ies, size_t ric_ies_len);
355 int wpa_ft_is_completed(struct wpa_sm *sm);
356 void wpa_reset_ft_completed(struct wpa_sm *sm);
357 int wpa_ft_validate_reassoc_resp(struct wpa_sm *sm, const u8 *ies,
358                                  size_t ies_len, const u8 *src_addr);
359 int wpa_ft_start_over_ds(struct wpa_sm *sm, const u8 *target_ap,
360                          const u8 *mdie);
361
362 #else /* CONFIG_IEEE80211R */
363
364 static inline int
365 wpa_sm_set_ft_params(struct wpa_sm *sm, const u8 *ies, size_t ies_len)
366 {
367         return 0;
368 }
369
370 static inline int wpa_ft_prepare_auth_request(struct wpa_sm *sm,
371                                               const u8 *mdie)
372 {
373         return 0;
374 }
375
376 static inline int
377 wpa_ft_process_response(struct wpa_sm *sm, const u8 *ies, size_t ies_len,
378                         int ft_action, const u8 *target_ap)
379 {
380         return 0;
381 }
382
383 static inline int wpa_ft_is_completed(struct wpa_sm *sm)
384 {
385         return 0;
386 }
387
388 static inline void wpa_reset_ft_completed(struct wpa_sm *sm)
389 {
390 }
391
392 static inline int
393 wpa_ft_validate_reassoc_resp(struct wpa_sm *sm, const u8 *ies, size_t ies_len,
394                              const u8 *src_addr)
395 {
396         return -1;
397 }
398
399 #endif /* CONFIG_IEEE80211R */
400
401
402 /* tdls.c */
403 void wpa_tdls_ap_ies(struct wpa_sm *sm, const u8 *ies, size_t len);
404 void wpa_tdls_assoc_resp_ies(struct wpa_sm *sm, const u8 *ies, size_t len);
405 int wpa_tdls_start(struct wpa_sm *sm, const u8 *addr);
406 void wpa_tdls_remove(struct wpa_sm *sm, const u8 *addr);
407 int wpa_tdls_teardown_link(struct wpa_sm *sm, const u8 *addr, u16 reason_code);
408 int wpa_tdls_send_discovery_request(struct wpa_sm *sm, const u8 *addr);
409 int wpa_tdls_init(struct wpa_sm *sm);
410 void wpa_tdls_teardown_peers(struct wpa_sm *sm);
411 void wpa_tdls_deinit(struct wpa_sm *sm);
412 void wpa_tdls_enable(struct wpa_sm *sm, int enabled);
413 void wpa_tdls_disable_unreachable_link(struct wpa_sm *sm, const u8 *addr);
414 const char * wpa_tdls_get_link_status(struct wpa_sm *sm, const u8 *addr);
415 int wpa_tdls_is_external_setup(struct wpa_sm *sm);
416 int wpa_tdls_enable_chan_switch(struct wpa_sm *sm, const u8 *addr,
417                                 u8 oper_class,
418                                 struct hostapd_freq_params *freq_params);
419 int wpa_tdls_disable_chan_switch(struct wpa_sm *sm, const u8 *addr);
420
421 int wpa_wnmsleep_install_key(struct wpa_sm *sm, u8 subelem_id, u8 *buf);
422 void wpa_sm_set_test_assoc_ie(struct wpa_sm *sm, struct wpabuf *buf);
423
424 #endif /* WPA_H */