wpa_i.h 12 KB

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