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