wpa_i.h 8.7 KB

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