wpa_i.h 10 KB

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