wpa_i.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  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. #endif /* CONFIG_FILS */
  134. #ifdef CONFIG_OWE
  135. struct crypto_ecdh *owe_ecdh;
  136. #endif /* CONFIG_OWE */
  137. };
  138. static inline void wpa_sm_set_state(struct wpa_sm *sm, enum wpa_states state)
  139. {
  140. WPA_ASSERT(sm->ctx->set_state);
  141. sm->ctx->set_state(sm->ctx->ctx, state);
  142. }
  143. static inline enum wpa_states wpa_sm_get_state(struct wpa_sm *sm)
  144. {
  145. WPA_ASSERT(sm->ctx->get_state);
  146. return sm->ctx->get_state(sm->ctx->ctx);
  147. }
  148. static inline void wpa_sm_deauthenticate(struct wpa_sm *sm, int reason_code)
  149. {
  150. WPA_ASSERT(sm->ctx->deauthenticate);
  151. sm->ctx->deauthenticate(sm->ctx->ctx, reason_code);
  152. }
  153. static inline int wpa_sm_set_key(struct wpa_sm *sm, enum wpa_alg alg,
  154. const u8 *addr, int key_idx, int set_tx,
  155. const u8 *seq, size_t seq_len,
  156. const u8 *key, size_t key_len)
  157. {
  158. WPA_ASSERT(sm->ctx->set_key);
  159. return sm->ctx->set_key(sm->ctx->ctx, alg, addr, key_idx, set_tx,
  160. seq, seq_len, key, key_len);
  161. }
  162. static inline void * wpa_sm_get_network_ctx(struct wpa_sm *sm)
  163. {
  164. WPA_ASSERT(sm->ctx->get_network_ctx);
  165. return sm->ctx->get_network_ctx(sm->ctx->ctx);
  166. }
  167. static inline int wpa_sm_get_bssid(struct wpa_sm *sm, u8 *bssid)
  168. {
  169. WPA_ASSERT(sm->ctx->get_bssid);
  170. return sm->ctx->get_bssid(sm->ctx->ctx, bssid);
  171. }
  172. static inline int wpa_sm_ether_send(struct wpa_sm *sm, const u8 *dest,
  173. u16 proto, const u8 *buf, size_t len)
  174. {
  175. WPA_ASSERT(sm->ctx->ether_send);
  176. return sm->ctx->ether_send(sm->ctx->ctx, dest, proto, buf, len);
  177. }
  178. static inline int wpa_sm_get_beacon_ie(struct wpa_sm *sm)
  179. {
  180. WPA_ASSERT(sm->ctx->get_beacon_ie);
  181. return sm->ctx->get_beacon_ie(sm->ctx->ctx);
  182. }
  183. static inline void wpa_sm_cancel_auth_timeout(struct wpa_sm *sm)
  184. {
  185. WPA_ASSERT(sm->ctx->cancel_auth_timeout);
  186. sm->ctx->cancel_auth_timeout(sm->ctx->ctx);
  187. }
  188. static inline u8 * wpa_sm_alloc_eapol(struct wpa_sm *sm, u8 type,
  189. const void *data, u16 data_len,
  190. size_t *msg_len, void **data_pos)
  191. {
  192. WPA_ASSERT(sm->ctx->alloc_eapol);
  193. return sm->ctx->alloc_eapol(sm->ctx->ctx, type, data, data_len,
  194. msg_len, data_pos);
  195. }
  196. static inline int wpa_sm_add_pmkid(struct wpa_sm *sm, void *network_ctx,
  197. const u8 *bssid, const u8 *pmkid,
  198. const u8 *cache_id, const u8 *pmk,
  199. size_t pmk_len)
  200. {
  201. WPA_ASSERT(sm->ctx->add_pmkid);
  202. return sm->ctx->add_pmkid(sm->ctx->ctx, network_ctx, bssid, pmkid,
  203. cache_id, pmk, pmk_len);
  204. }
  205. static inline int wpa_sm_remove_pmkid(struct wpa_sm *sm, void *network_ctx,
  206. const u8 *bssid, const u8 *pmkid,
  207. const u8 *cache_id)
  208. {
  209. WPA_ASSERT(sm->ctx->remove_pmkid);
  210. return sm->ctx->remove_pmkid(sm->ctx->ctx, network_ctx, bssid, pmkid,
  211. cache_id);
  212. }
  213. static inline int wpa_sm_mlme_setprotection(struct wpa_sm *sm, const u8 *addr,
  214. int protect_type, int key_type)
  215. {
  216. WPA_ASSERT(sm->ctx->mlme_setprotection);
  217. return sm->ctx->mlme_setprotection(sm->ctx->ctx, addr, protect_type,
  218. key_type);
  219. }
  220. static inline int wpa_sm_update_ft_ies(struct wpa_sm *sm, const u8 *md,
  221. const u8 *ies, size_t ies_len)
  222. {
  223. if (sm->ctx->update_ft_ies)
  224. return sm->ctx->update_ft_ies(sm->ctx->ctx, md, ies, ies_len);
  225. return -1;
  226. }
  227. static inline int wpa_sm_send_ft_action(struct wpa_sm *sm, u8 action,
  228. const u8 *target_ap,
  229. const u8 *ies, size_t ies_len)
  230. {
  231. if (sm->ctx->send_ft_action)
  232. return sm->ctx->send_ft_action(sm->ctx->ctx, action, target_ap,
  233. ies, ies_len);
  234. return -1;
  235. }
  236. static inline int wpa_sm_mark_authenticated(struct wpa_sm *sm,
  237. const u8 *target_ap)
  238. {
  239. if (sm->ctx->mark_authenticated)
  240. return sm->ctx->mark_authenticated(sm->ctx->ctx, target_ap);
  241. return -1;
  242. }
  243. static inline void wpa_sm_set_rekey_offload(struct wpa_sm *sm)
  244. {
  245. if (!sm->ctx->set_rekey_offload)
  246. return;
  247. sm->ctx->set_rekey_offload(sm->ctx->ctx, sm->ptk.kek, sm->ptk.kek_len,
  248. sm->ptk.kck, sm->ptk.kck_len,
  249. sm->rx_replay_counter);
  250. }
  251. #ifdef CONFIG_TDLS
  252. static inline int wpa_sm_tdls_get_capa(struct wpa_sm *sm,
  253. int *tdls_supported,
  254. int *tdls_ext_setup,
  255. int *tdls_chan_switch)
  256. {
  257. if (sm->ctx->tdls_get_capa)
  258. return sm->ctx->tdls_get_capa(sm->ctx->ctx, tdls_supported,
  259. tdls_ext_setup, tdls_chan_switch);
  260. return -1;
  261. }
  262. static inline int wpa_sm_send_tdls_mgmt(struct wpa_sm *sm, const u8 *dst,
  263. u8 action_code, u8 dialog_token,
  264. u16 status_code, u32 peer_capab,
  265. int initiator, const u8 *buf,
  266. size_t len)
  267. {
  268. if (sm->ctx->send_tdls_mgmt)
  269. return sm->ctx->send_tdls_mgmt(sm->ctx->ctx, dst, action_code,
  270. dialog_token, status_code,
  271. peer_capab, initiator, buf,
  272. len);
  273. return -1;
  274. }
  275. static inline int wpa_sm_tdls_oper(struct wpa_sm *sm, int oper,
  276. const u8 *peer)
  277. {
  278. if (sm->ctx->tdls_oper)
  279. return sm->ctx->tdls_oper(sm->ctx->ctx, oper, peer);
  280. return -1;
  281. }
  282. static inline int
  283. wpa_sm_tdls_peer_addset(struct wpa_sm *sm, const u8 *addr, int add,
  284. u16 aid, u16 capability, const u8 *supp_rates,
  285. size_t supp_rates_len,
  286. const struct ieee80211_ht_capabilities *ht_capab,
  287. const struct ieee80211_vht_capabilities *vht_capab,
  288. u8 qosinfo, int wmm, const u8 *ext_capab,
  289. size_t ext_capab_len, const u8 *supp_channels,
  290. size_t supp_channels_len, const u8 *supp_oper_classes,
  291. size_t supp_oper_classes_len)
  292. {
  293. if (sm->ctx->tdls_peer_addset)
  294. return sm->ctx->tdls_peer_addset(sm->ctx->ctx, addr, add,
  295. aid, capability, supp_rates,
  296. supp_rates_len, ht_capab,
  297. vht_capab, qosinfo, wmm,
  298. ext_capab, ext_capab_len,
  299. supp_channels,
  300. supp_channels_len,
  301. supp_oper_classes,
  302. supp_oper_classes_len);
  303. return -1;
  304. }
  305. static inline int
  306. wpa_sm_tdls_enable_channel_switch(struct wpa_sm *sm, const u8 *addr,
  307. u8 oper_class,
  308. const struct hostapd_freq_params *freq_params)
  309. {
  310. if (sm->ctx->tdls_enable_channel_switch)
  311. return sm->ctx->tdls_enable_channel_switch(sm->ctx->ctx, addr,
  312. oper_class,
  313. freq_params);
  314. return -1;
  315. }
  316. static inline int
  317. wpa_sm_tdls_disable_channel_switch(struct wpa_sm *sm, const u8 *addr)
  318. {
  319. if (sm->ctx->tdls_disable_channel_switch)
  320. return sm->ctx->tdls_disable_channel_switch(sm->ctx->ctx, addr);
  321. return -1;
  322. }
  323. #endif /* CONFIG_TDLS */
  324. static inline int wpa_sm_key_mgmt_set_pmk(struct wpa_sm *sm,
  325. const u8 *pmk, size_t pmk_len)
  326. {
  327. if (!sm->ctx->key_mgmt_set_pmk)
  328. return -1;
  329. return sm->ctx->key_mgmt_set_pmk(sm->ctx->ctx, pmk, pmk_len);
  330. }
  331. static inline void wpa_sm_fils_hlp_rx(struct wpa_sm *sm,
  332. const u8 *dst, const u8 *src,
  333. const u8 *pkt, size_t pkt_len)
  334. {
  335. if (sm->ctx->fils_hlp_rx)
  336. sm->ctx->fils_hlp_rx(sm->ctx->ctx, dst, src, pkt, pkt_len);
  337. }
  338. int wpa_eapol_key_send(struct wpa_sm *sm, struct wpa_ptk *ptk,
  339. int ver, const u8 *dest, u16 proto,
  340. u8 *msg, size_t msg_len, u8 *key_mic);
  341. int wpa_supplicant_send_2_of_4(struct wpa_sm *sm, const unsigned char *dst,
  342. const struct wpa_eapol_key *key,
  343. int ver, const u8 *nonce,
  344. const u8 *wpa_ie, size_t wpa_ie_len,
  345. struct wpa_ptk *ptk);
  346. int wpa_supplicant_send_4_of_4(struct wpa_sm *sm, const unsigned char *dst,
  347. const struct wpa_eapol_key *key,
  348. u16 ver, u16 key_info,
  349. struct wpa_ptk *ptk);
  350. int wpa_derive_ptk_ft(struct wpa_sm *sm, const unsigned char *src_addr,
  351. const struct wpa_eapol_key *key, struct wpa_ptk *ptk);
  352. void wpa_tdls_assoc(struct wpa_sm *sm);
  353. void wpa_tdls_disassoc(struct wpa_sm *sm);
  354. #endif /* WPA_I_H */