wpa_i.h 11 KB

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