1 /*
2 * Internal WPA/RSN supplicant state machine definitions
3 * Copyright (c) 2004-2018, 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_I_H
10 #define WPA_I_H
11
12 #include "utils/list.h"
13
14 struct wpa_tdls_peer;
15 struct wpa_eapol_key;
16
17 /**
18 * struct wpa_sm - Internal WPA state machine data
19 */
20 struct wpa_sm {
21 u8 pmk[PMK_LEN_MAX];
22 size_t pmk_len;
23 struct wpa_ptk ptk, tptk;
24 int ptk_set, tptk_set;
25 unsigned int msg_3_of_4_ok:1;
26 u8 snonce[WPA_NONCE_LEN];
27 u8 anonce[WPA_NONCE_LEN]; /* ANonce from the last 1/4 msg */
28 int renew_snonce;
29 u8 rx_replay_counter[WPA_REPLAY_COUNTER_LEN];
30 int rx_replay_counter_set;
31 u8 request_counter[WPA_REPLAY_COUNTER_LEN];
32 struct wpa_gtk gtk;
33 struct wpa_gtk gtk_wnm_sleep;
34 struct wpa_igtk igtk;
35 struct wpa_igtk igtk_wnm_sleep;
36 struct wpa_bigtk bigtk;
37 struct wpa_bigtk bigtk_wnm_sleep;
38
39 struct eapol_sm *eapol; /* EAPOL state machine from upper level code */
40
41 struct rsn_pmksa_cache *pmksa; /* PMKSA cache */
42 struct rsn_pmksa_cache_entry *cur_pmksa; /* current PMKSA entry */
43 struct dl_list pmksa_candidates;
44
45 struct l2_packet_data *l2_preauth;
46 struct l2_packet_data *l2_preauth_br;
47 struct l2_packet_data *l2_tdls;
48 u8 preauth_bssid[ETH_ALEN]; /* current RSN pre-auth peer or
49 * 00:00:00:00:00:00 if no pre-auth is
50 * in progress */
51 struct eapol_sm *preauth_eapol;
52
53 struct wpa_sm_ctx *ctx;
54
55 void *scard_ctx; /* context for smartcard callbacks */
56 int fast_reauth; /* whether EAP fast re-authentication is enabled */
57
58 void *network_ctx;
59 int allowed_pairwise_cipher; /* bitfield of WPA_CIPHER_* */
60 int proactive_key_caching;
61 int eap_workaround;
62 void *eap_conf_ctx;
63 u8 ssid[32];
64 size_t ssid_len;
65 int wpa_ptk_rekey;
66 int wpa_deny_ptk0_rekey:1;
67 int p2p;
68 int wpa_rsc_relaxation;
69 int owe_ptk_workaround;
70 int beacon_prot;
71 int ext_key_id; /* whether Extended Key ID is enabled */
72 int use_ext_key_id; /* whether Extended Key ID has been detected
73 * to be used */
74 int keyidx_active; /* Key ID for the active TK */
75
76 u8 own_addr[ETH_ALEN];
77 const char *ifname;
78 const char *bridge_ifname;
79 u8 bssid[ETH_ALEN];
80
81 unsigned int dot11RSNAConfigPMKLifetime;
82 unsigned int dot11RSNAConfigPMKReauthThreshold;
83 unsigned int dot11RSNAConfigSATimeout;
84
85 unsigned int dot11RSNA4WayHandshakeFailures;
86
87 /* Selected configuration (based on Beacon/ProbeResp WPA IE) */
88 unsigned int proto;
89 unsigned int pairwise_cipher;
90 unsigned int group_cipher;
91 unsigned int key_mgmt;
92 unsigned int mgmt_group_cipher;
93
94 int rsn_enabled; /* Whether RSN is enabled in configuration */
95 int mfp; /* 0 = disabled, 1 = optional, 2 = mandatory */
96 int ocv; /* Operating Channel Validation */
97 int sae_pwe; /* SAE PWE generation options */
98
99 u8 *assoc_wpa_ie; /* Own WPA/RSN IE from (Re)AssocReq */
100 size_t assoc_wpa_ie_len;
101 u8 *assoc_rsnxe; /* Own RSNXE from (Re)AssocReq */
102 size_t assoc_rsnxe_len;
103 u8 *ap_wpa_ie, *ap_rsn_ie, *ap_rsnxe;
104 size_t ap_wpa_ie_len, ap_rsn_ie_len, ap_rsnxe_len;
105
106 #ifdef CONFIG_TDLS
107 struct wpa_tdls_peer *tdls;
108 int tdls_prohibited;
109 int tdls_chan_switch_prohibited;
110 int tdls_disabled;
111
112 /* The driver supports TDLS */
113 int tdls_supported;
114
115 /*
116 * The driver requires explicit discovery/setup/teardown frames sent
117 * to it via tdls_mgmt.
118 */
119 int tdls_external_setup;
120
121 /* The driver supports TDLS channel switching */
122 int tdls_chan_switch;
123 #endif /* CONFIG_TDLS */
124
125 #ifdef CONFIG_IEEE80211R
126 u8 xxkey[PMK_LEN_MAX]; /* PSK or the second 256 bits of MSK, or the
127 * first 384 bits of MSK */
128 size_t xxkey_len;
129 u8 pmk_r0[PMK_LEN_MAX];
130 size_t pmk_r0_len;
131 u8 pmk_r0_name[WPA_PMK_NAME_LEN];
132 u8 pmk_r1[PMK_LEN_MAX];
133 size_t pmk_r1_len;
134 u8 pmk_r1_name[WPA_PMK_NAME_LEN];
135 u8 mobility_domain[MOBILITY_DOMAIN_ID_LEN];
136 u8 r0kh_id[FT_R0KH_ID_MAX_LEN];
137 size_t r0kh_id_len;
138 u8 r1kh_id[FT_R1KH_ID_LEN];
139 unsigned int ft_completed:1;
140 unsigned int ft_reassoc_completed:1;
141 unsigned int ft_protocol:1;
142 int over_the_ds_in_progress;
143 u8 target_ap[ETH_ALEN]; /* over-the-DS target AP */
144 int set_ptk_after_assoc;
145 u8 mdie_ft_capab; /* FT Capability and Policy from target AP MDIE */
146 u8 *assoc_resp_ies; /* MDIE and FTIE from (Re)Association Response */
147 size_t assoc_resp_ies_len;
148 #endif /* CONFIG_IEEE80211R */
149
150 #ifdef CONFIG_P2P
151 u8 p2p_ip_addr[3 * 4];
152 #endif /* CONFIG_P2P */
153
154 #ifdef CONFIG_TESTING_OPTIONS
155 struct wpabuf *test_assoc_ie;
156 int ft_rsnxe_used;
157 #endif /* CONFIG_TESTING_OPTIONS */
158
159 #ifdef CONFIG_FILS
160 u8 fils_nonce[FILS_NONCE_LEN];
161 u8 fils_session[FILS_SESSION_LEN];
162 u8 fils_anonce[FILS_NONCE_LEN];
163 u8 fils_key_auth_ap[FILS_MAX_KEY_AUTH_LEN];
164 u8 fils_key_auth_sta[FILS_MAX_KEY_AUTH_LEN];
165 size_t fils_key_auth_len;
166 unsigned int fils_completed:1;
167 unsigned int fils_erp_pmkid_set:1;
168 unsigned int fils_cache_id_set:1;
169 u8 fils_erp_pmkid[PMKID_LEN];
170 u8 fils_cache_id[FILS_CACHE_ID_LEN];
171 struct crypto_ecdh *fils_ecdh;
172 int fils_dh_group;
173 size_t fils_dh_elem_len;
174 struct wpabuf *fils_ft_ies;
175 u8 fils_ft[FILS_FT_MAX_LEN];
176 size_t fils_ft_len;
177 #endif /* CONFIG_FILS */
178
179 #ifdef CONFIG_OWE
180 struct crypto_ecdh *owe_ecdh;
181 u16 owe_group;
182 #endif /* CONFIG_OWE */
183
184 #ifdef CONFIG_DPP2
185 struct wpabuf *dpp_z;
186 int dpp_pfs;
187 #endif /* CONFIG_DPP2 */
188 };
189
190
wpa_sm_set_state(struct wpa_sm * sm,enum wpa_states state)191 static inline void wpa_sm_set_state(struct wpa_sm *sm, enum wpa_states state)
192 {
193 WPA_ASSERT(sm->ctx->set_state);
194 sm->ctx->set_state(sm->ctx->ctx, state);
195 }
196
wpa_sm_get_state(struct wpa_sm * sm)197 static inline enum wpa_states wpa_sm_get_state(struct wpa_sm *sm)
198 {
199 WPA_ASSERT(sm->ctx->get_state);
200 return sm->ctx->get_state(sm->ctx->ctx);
201 }
202
wpa_sm_deauthenticate(struct wpa_sm * sm,u16 reason_code)203 static inline void wpa_sm_deauthenticate(struct wpa_sm *sm, u16 reason_code)
204 {
205 WPA_ASSERT(sm->ctx->deauthenticate);
206 sm->ctx->deauthenticate(sm->ctx->ctx, reason_code);
207 }
208
wpa_sm_set_key(struct wpa_sm * sm,enum wpa_alg alg,const u8 * addr,int key_idx,int set_tx,const u8 * seq,size_t seq_len,const u8 * key,size_t key_len,enum key_flag key_flag)209 static inline int wpa_sm_set_key(struct wpa_sm *sm, enum wpa_alg alg,
210 const u8 *addr, int key_idx, int set_tx,
211 const u8 *seq, size_t seq_len,
212 const u8 *key, size_t key_len,
213 enum key_flag key_flag)
214 {
215 WPA_ASSERT(sm->ctx->set_key);
216 return sm->ctx->set_key(sm->ctx->ctx, alg, addr, key_idx, set_tx,
217 seq, seq_len, key, key_len, key_flag);
218 }
219
wpa_sm_reconnect(struct wpa_sm * sm)220 static inline void wpa_sm_reconnect(struct wpa_sm *sm)
221 {
222 WPA_ASSERT(sm->ctx->reconnect);
223 sm->ctx->reconnect(sm->ctx->ctx);
224 }
225
wpa_sm_get_network_ctx(struct wpa_sm * sm)226 static inline void * wpa_sm_get_network_ctx(struct wpa_sm *sm)
227 {
228 WPA_ASSERT(sm->ctx->get_network_ctx);
229 return sm->ctx->get_network_ctx(sm->ctx->ctx);
230 }
231
wpa_sm_get_bssid(struct wpa_sm * sm,u8 * bssid)232 static inline int wpa_sm_get_bssid(struct wpa_sm *sm, u8 *bssid)
233 {
234 WPA_ASSERT(sm->ctx->get_bssid);
235 return sm->ctx->get_bssid(sm->ctx->ctx, bssid);
236 }
237
wpa_sm_ether_send(struct wpa_sm * sm,const u8 * dest,u16 proto,const u8 * buf,size_t len)238 static inline int wpa_sm_ether_send(struct wpa_sm *sm, const u8 *dest,
239 u16 proto, const u8 *buf, size_t len)
240 {
241 WPA_ASSERT(sm->ctx->ether_send);
242 return sm->ctx->ether_send(sm->ctx->ctx, dest, proto, buf, len);
243 }
244
wpa_sm_get_beacon_ie(struct wpa_sm * sm)245 static inline int wpa_sm_get_beacon_ie(struct wpa_sm *sm)
246 {
247 WPA_ASSERT(sm->ctx->get_beacon_ie);
248 return sm->ctx->get_beacon_ie(sm->ctx->ctx);
249 }
250
wpa_sm_cancel_auth_timeout(struct wpa_sm * sm)251 static inline void wpa_sm_cancel_auth_timeout(struct wpa_sm *sm)
252 {
253 WPA_ASSERT(sm->ctx->cancel_auth_timeout);
254 sm->ctx->cancel_auth_timeout(sm->ctx->ctx);
255 }
256
wpa_sm_alloc_eapol(struct wpa_sm * sm,u8 type,const void * data,u16 data_len,size_t * msg_len,void ** data_pos)257 static inline u8 * wpa_sm_alloc_eapol(struct wpa_sm *sm, u8 type,
258 const void *data, u16 data_len,
259 size_t *msg_len, void **data_pos)
260 {
261 WPA_ASSERT(sm->ctx->alloc_eapol);
262 return sm->ctx->alloc_eapol(sm->ctx->ctx, type, data, data_len,
263 msg_len, data_pos);
264 }
265
wpa_sm_add_pmkid(struct wpa_sm * sm,void * network_ctx,const u8 * bssid,const u8 * pmkid,const u8 * cache_id,const u8 * pmk,size_t pmk_len,u32 pmk_lifetime,u8 pmk_reauth_threshold)266 static inline int wpa_sm_add_pmkid(struct wpa_sm *sm, void *network_ctx,
267 const u8 *bssid, const u8 *pmkid,
268 const u8 *cache_id, const u8 *pmk,
269 size_t pmk_len, u32 pmk_lifetime,
270 u8 pmk_reauth_threshold)
271 {
272 WPA_ASSERT(sm->ctx->add_pmkid);
273 return sm->ctx->add_pmkid(sm->ctx->ctx, network_ctx, bssid, pmkid,
274 cache_id, pmk, pmk_len, pmk_lifetime,
275 pmk_reauth_threshold);
276 }
277
wpa_sm_remove_pmkid(struct wpa_sm * sm,void * network_ctx,const u8 * bssid,const u8 * pmkid,const u8 * cache_id)278 static inline int wpa_sm_remove_pmkid(struct wpa_sm *sm, void *network_ctx,
279 const u8 *bssid, const u8 *pmkid,
280 const u8 *cache_id)
281 {
282 WPA_ASSERT(sm->ctx->remove_pmkid);
283 return sm->ctx->remove_pmkid(sm->ctx->ctx, network_ctx, bssid, pmkid,
284 cache_id);
285 }
286
wpa_sm_mlme_setprotection(struct wpa_sm * sm,const u8 * addr,int protect_type,int key_type)287 static inline int wpa_sm_mlme_setprotection(struct wpa_sm *sm, const u8 *addr,
288 int protect_type, int key_type)
289 {
290 WPA_ASSERT(sm->ctx->mlme_setprotection);
291 return sm->ctx->mlme_setprotection(sm->ctx->ctx, addr, protect_type,
292 key_type);
293 }
294
wpa_sm_update_ft_ies(struct wpa_sm * sm,const u8 * md,const u8 * ies,size_t ies_len)295 static inline int wpa_sm_update_ft_ies(struct wpa_sm *sm, const u8 *md,
296 const u8 *ies, size_t ies_len)
297 {
298 if (sm->ctx->update_ft_ies)
299 return sm->ctx->update_ft_ies(sm->ctx->ctx, md, ies, ies_len);
300 return -1;
301 }
302
wpa_sm_send_ft_action(struct wpa_sm * sm,u8 action,const u8 * target_ap,const u8 * ies,size_t ies_len)303 static inline int wpa_sm_send_ft_action(struct wpa_sm *sm, u8 action,
304 const u8 *target_ap,
305 const u8 *ies, size_t ies_len)
306 {
307 if (sm->ctx->send_ft_action)
308 return sm->ctx->send_ft_action(sm->ctx->ctx, action, target_ap,
309 ies, ies_len);
310 return -1;
311 }
312
wpa_sm_mark_authenticated(struct wpa_sm * sm,const u8 * target_ap)313 static inline int wpa_sm_mark_authenticated(struct wpa_sm *sm,
314 const u8 *target_ap)
315 {
316 if (sm->ctx->mark_authenticated)
317 return sm->ctx->mark_authenticated(sm->ctx->ctx, target_ap);
318 return -1;
319 }
320
wpa_sm_set_rekey_offload(struct wpa_sm * sm)321 static inline void wpa_sm_set_rekey_offload(struct wpa_sm *sm)
322 {
323 if (!sm->ctx->set_rekey_offload)
324 return;
325 sm->ctx->set_rekey_offload(sm->ctx->ctx, sm->ptk.kek, sm->ptk.kek_len,
326 sm->ptk.kck, sm->ptk.kck_len,
327 sm->rx_replay_counter);
328 }
329
330 #ifdef CONFIG_TDLS
wpa_sm_tdls_get_capa(struct wpa_sm * sm,int * tdls_supported,int * tdls_ext_setup,int * tdls_chan_switch)331 static inline int wpa_sm_tdls_get_capa(struct wpa_sm *sm,
332 int *tdls_supported,
333 int *tdls_ext_setup,
334 int *tdls_chan_switch)
335 {
336 if (sm->ctx->tdls_get_capa)
337 return sm->ctx->tdls_get_capa(sm->ctx->ctx, tdls_supported,
338 tdls_ext_setup, tdls_chan_switch);
339 return -1;
340 }
341
wpa_sm_send_tdls_mgmt(struct wpa_sm * sm,const u8 * dst,u8 action_code,u8 dialog_token,u16 status_code,u32 peer_capab,int initiator,const u8 * buf,size_t len)342 static inline int wpa_sm_send_tdls_mgmt(struct wpa_sm *sm, const u8 *dst,
343 u8 action_code, u8 dialog_token,
344 u16 status_code, u32 peer_capab,
345 int initiator, const u8 *buf,
346 size_t len)
347 {
348 if (sm->ctx->send_tdls_mgmt)
349 return sm->ctx->send_tdls_mgmt(sm->ctx->ctx, dst, action_code,
350 dialog_token, status_code,
351 peer_capab, initiator, buf,
352 len);
353 return -1;
354 }
355
wpa_sm_tdls_oper(struct wpa_sm * sm,int oper,const u8 * peer)356 static inline int wpa_sm_tdls_oper(struct wpa_sm *sm, int oper,
357 const u8 *peer)
358 {
359 if (sm->ctx->tdls_oper)
360 return sm->ctx->tdls_oper(sm->ctx->ctx, oper, peer);
361 return -1;
362 }
363
364 static inline int
wpa_sm_tdls_peer_addset(struct wpa_sm * sm,const u8 * addr,int add,u16 aid,u16 capability,const u8 * supp_rates,size_t supp_rates_len,const struct ieee80211_ht_capabilities * ht_capab,const struct ieee80211_vht_capabilities * vht_capab,u8 qosinfo,int wmm,const u8 * ext_capab,size_t ext_capab_len,const u8 * supp_channels,size_t supp_channels_len,const u8 * supp_oper_classes,size_t supp_oper_classes_len)365 wpa_sm_tdls_peer_addset(struct wpa_sm *sm, const u8 *addr, int add,
366 u16 aid, u16 capability, const u8 *supp_rates,
367 size_t supp_rates_len,
368 const struct ieee80211_ht_capabilities *ht_capab,
369 const struct ieee80211_vht_capabilities *vht_capab,
370 u8 qosinfo, int wmm, const u8 *ext_capab,
371 size_t ext_capab_len, const u8 *supp_channels,
372 size_t supp_channels_len, const u8 *supp_oper_classes,
373 size_t supp_oper_classes_len)
374 {
375 if (sm->ctx->tdls_peer_addset)
376 return sm->ctx->tdls_peer_addset(sm->ctx->ctx, addr, add,
377 aid, capability, supp_rates,
378 supp_rates_len, ht_capab,
379 vht_capab, qosinfo, wmm,
380 ext_capab, ext_capab_len,
381 supp_channels,
382 supp_channels_len,
383 supp_oper_classes,
384 supp_oper_classes_len);
385 return -1;
386 }
387
388 static inline int
wpa_sm_tdls_enable_channel_switch(struct wpa_sm * sm,const u8 * addr,u8 oper_class,const struct hostapd_freq_params * freq_params)389 wpa_sm_tdls_enable_channel_switch(struct wpa_sm *sm, const u8 *addr,
390 u8 oper_class,
391 const struct hostapd_freq_params *freq_params)
392 {
393 if (sm->ctx->tdls_enable_channel_switch)
394 return sm->ctx->tdls_enable_channel_switch(sm->ctx->ctx, addr,
395 oper_class,
396 freq_params);
397 return -1;
398 }
399
400 static inline int
wpa_sm_tdls_disable_channel_switch(struct wpa_sm * sm,const u8 * addr)401 wpa_sm_tdls_disable_channel_switch(struct wpa_sm *sm, const u8 *addr)
402 {
403 if (sm->ctx->tdls_disable_channel_switch)
404 return sm->ctx->tdls_disable_channel_switch(sm->ctx->ctx, addr);
405 return -1;
406 }
407 #endif /* CONFIG_TDLS */
408
wpa_sm_key_mgmt_set_pmk(struct wpa_sm * sm,const u8 * pmk,size_t pmk_len)409 static inline int wpa_sm_key_mgmt_set_pmk(struct wpa_sm *sm,
410 const u8 *pmk, size_t pmk_len)
411 {
412 if (!sm->ctx->key_mgmt_set_pmk)
413 return -1;
414 return sm->ctx->key_mgmt_set_pmk(sm->ctx->ctx, pmk, pmk_len);
415 }
416
wpa_sm_fils_hlp_rx(struct wpa_sm * sm,const u8 * dst,const u8 * src,const u8 * pkt,size_t pkt_len)417 static inline void wpa_sm_fils_hlp_rx(struct wpa_sm *sm,
418 const u8 *dst, const u8 *src,
419 const u8 *pkt, size_t pkt_len)
420 {
421 if (sm->ctx->fils_hlp_rx)
422 sm->ctx->fils_hlp_rx(sm->ctx->ctx, dst, src, pkt, pkt_len);
423 }
424
wpa_sm_channel_info(struct wpa_sm * sm,struct wpa_channel_info * ci)425 static inline int wpa_sm_channel_info(struct wpa_sm *sm,
426 struct wpa_channel_info *ci)
427 {
428 if (!sm->ctx->channel_info)
429 return -1;
430 return sm->ctx->channel_info(sm->ctx->ctx, ci);
431 }
432
wpa_sm_transition_disable(struct wpa_sm * sm,u8 bitmap)433 static inline void wpa_sm_transition_disable(struct wpa_sm *sm, u8 bitmap)
434 {
435 if (sm->ctx->transition_disable)
436 sm->ctx->transition_disable(sm->ctx->ctx, bitmap);
437 }
438
439
440 int wpa_eapol_key_send(struct wpa_sm *sm, struct wpa_ptk *ptk,
441 int ver, const u8 *dest, u16 proto,
442 u8 *msg, size_t msg_len, u8 *key_mic);
443 int wpa_supplicant_send_2_of_4(struct wpa_sm *sm, const unsigned char *dst,
444 const struct wpa_eapol_key *key,
445 int ver, const u8 *nonce,
446 const u8 *wpa_ie, size_t wpa_ie_len,
447 struct wpa_ptk *ptk);
448 int wpa_supplicant_send_4_of_4(struct wpa_sm *sm, const unsigned char *dst,
449 const struct wpa_eapol_key *key,
450 u16 ver, u16 key_info,
451 struct wpa_ptk *ptk);
452
453 int wpa_derive_ptk_ft(struct wpa_sm *sm, const unsigned char *src_addr,
454 const struct wpa_eapol_key *key, struct wpa_ptk *ptk);
455
456 void wpa_tdls_assoc(struct wpa_sm *sm);
457 void wpa_tdls_disassoc(struct wpa_sm *sm);
458
459 #endif /* WPA_I_H */
460