wpa_i.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. /*
  2. * Internal WPA/RSN supplicant state machine definitions
  3. * Copyright (c) 2004-2010, Jouni Malinen <j@w1.fi>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. *
  9. * Alternatively, this software may be distributed under the terms of BSD
  10. * license.
  11. *
  12. * See README and COPYING for more details.
  13. */
  14. #ifndef WPA_I_H
  15. #define WPA_I_H
  16. #include "utils/list.h"
  17. struct wpa_peerkey;
  18. struct wpa_tdls_peer;
  19. struct wpa_eapol_key;
  20. /**
  21. * struct wpa_sm - Internal WPA state machine data
  22. */
  23. struct wpa_sm {
  24. u8 pmk[PMK_LEN];
  25. size_t pmk_len;
  26. struct wpa_ptk ptk, tptk;
  27. int ptk_set, tptk_set;
  28. u8 snonce[WPA_NONCE_LEN];
  29. u8 anonce[WPA_NONCE_LEN]; /* ANonce from the last 1/4 msg */
  30. int renew_snonce;
  31. u8 rx_replay_counter[WPA_REPLAY_COUNTER_LEN];
  32. int rx_replay_counter_set;
  33. u8 request_counter[WPA_REPLAY_COUNTER_LEN];
  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. u8 own_addr[ETH_ALEN];
  58. const char *ifname;
  59. const char *bridge_ifname;
  60. u8 bssid[ETH_ALEN];
  61. unsigned int dot11RSNAConfigPMKLifetime;
  62. unsigned int dot11RSNAConfigPMKReauthThreshold;
  63. unsigned int dot11RSNAConfigSATimeout;
  64. unsigned int dot11RSNA4WayHandshakeFailures;
  65. /* Selected configuration (based on Beacon/ProbeResp WPA IE) */
  66. unsigned int proto;
  67. unsigned int pairwise_cipher;
  68. unsigned int group_cipher;
  69. unsigned int key_mgmt;
  70. unsigned int mgmt_group_cipher;
  71. int rsn_enabled; /* Whether RSN is enabled in configuration */
  72. int mfp; /* 0 = disabled, 1 = optional, 2 = mandatory */
  73. u8 *assoc_wpa_ie; /* Own WPA/RSN IE from (Re)AssocReq */
  74. size_t assoc_wpa_ie_len;
  75. u8 *ap_wpa_ie, *ap_rsn_ie;
  76. size_t ap_wpa_ie_len, ap_rsn_ie_len;
  77. #ifdef CONFIG_PEERKEY
  78. struct wpa_peerkey *peerkey;
  79. #endif /* CONFIG_PEERKEY */
  80. #ifdef CONFIG_TDLS
  81. struct wpa_tdls_peer *tdls;
  82. int tdls_prohibited;
  83. int tdls_disabled;
  84. #endif /* CONFIG_TDLS */
  85. #ifdef CONFIG_IEEE80211R
  86. u8 xxkey[PMK_LEN]; /* PSK or the second 256 bits of MSK */
  87. size_t xxkey_len;
  88. u8 pmk_r0[PMK_LEN];
  89. u8 pmk_r0_name[WPA_PMK_NAME_LEN];
  90. u8 pmk_r1[PMK_LEN];
  91. u8 pmk_r1_name[WPA_PMK_NAME_LEN];
  92. u8 mobility_domain[MOBILITY_DOMAIN_ID_LEN];
  93. u8 r0kh_id[FT_R0KH_ID_MAX_LEN];
  94. size_t r0kh_id_len;
  95. u8 r1kh_id[FT_R1KH_ID_LEN];
  96. int ft_completed;
  97. int over_the_ds_in_progress;
  98. u8 target_ap[ETH_ALEN]; /* over-the-DS target AP */
  99. int set_ptk_after_assoc;
  100. u8 mdie_ft_capab; /* FT Capability and Policy from target AP MDIE */
  101. u8 *assoc_resp_ies; /* MDIE and FTIE from (Re)Association Response */
  102. size_t assoc_resp_ies_len;
  103. #endif /* CONFIG_IEEE80211R */
  104. };
  105. static inline void wpa_sm_set_state(struct wpa_sm *sm, enum wpa_states state)
  106. {
  107. WPA_ASSERT(sm->ctx->set_state);
  108. sm->ctx->set_state(sm->ctx->ctx, state);
  109. }
  110. static inline enum wpa_states wpa_sm_get_state(struct wpa_sm *sm)
  111. {
  112. WPA_ASSERT(sm->ctx->get_state);
  113. return sm->ctx->get_state(sm->ctx->ctx);
  114. }
  115. static inline void wpa_sm_deauthenticate(struct wpa_sm *sm, int reason_code)
  116. {
  117. WPA_ASSERT(sm->ctx->deauthenticate);
  118. sm->ctx->deauthenticate(sm->ctx->ctx, reason_code);
  119. }
  120. static inline void wpa_sm_disassociate(struct wpa_sm *sm, int reason_code)
  121. {
  122. WPA_ASSERT(sm->ctx->disassociate);
  123. sm->ctx->disassociate(sm->ctx->ctx, reason_code);
  124. }
  125. static inline int wpa_sm_set_key(struct wpa_sm *sm, enum wpa_alg alg,
  126. const u8 *addr, int key_idx, int set_tx,
  127. const u8 *seq, size_t seq_len,
  128. const u8 *key, size_t key_len)
  129. {
  130. WPA_ASSERT(sm->ctx->set_key);
  131. return sm->ctx->set_key(sm->ctx->ctx, alg, addr, key_idx, set_tx,
  132. seq, seq_len, key, key_len);
  133. }
  134. static inline void * wpa_sm_get_network_ctx(struct wpa_sm *sm)
  135. {
  136. WPA_ASSERT(sm->ctx->get_network_ctx);
  137. return sm->ctx->get_network_ctx(sm->ctx->ctx);
  138. }
  139. static inline int wpa_sm_get_bssid(struct wpa_sm *sm, u8 *bssid)
  140. {
  141. WPA_ASSERT(sm->ctx->get_bssid);
  142. return sm->ctx->get_bssid(sm->ctx->ctx, bssid);
  143. }
  144. static inline int wpa_sm_ether_send(struct wpa_sm *sm, const u8 *dest,
  145. u16 proto, const u8 *buf, size_t len)
  146. {
  147. WPA_ASSERT(sm->ctx->ether_send);
  148. return sm->ctx->ether_send(sm->ctx->ctx, dest, proto, buf, len);
  149. }
  150. static inline int wpa_sm_get_beacon_ie(struct wpa_sm *sm)
  151. {
  152. WPA_ASSERT(sm->ctx->get_beacon_ie);
  153. return sm->ctx->get_beacon_ie(sm->ctx->ctx);
  154. }
  155. static inline void wpa_sm_cancel_auth_timeout(struct wpa_sm *sm)
  156. {
  157. WPA_ASSERT(sm->ctx->cancel_auth_timeout);
  158. sm->ctx->cancel_auth_timeout(sm->ctx->ctx);
  159. }
  160. static inline u8 * wpa_sm_alloc_eapol(struct wpa_sm *sm, u8 type,
  161. const void *data, u16 data_len,
  162. size_t *msg_len, void **data_pos)
  163. {
  164. WPA_ASSERT(sm->ctx->alloc_eapol);
  165. return sm->ctx->alloc_eapol(sm->ctx->ctx, type, data, data_len,
  166. msg_len, data_pos);
  167. }
  168. static inline int wpa_sm_add_pmkid(struct wpa_sm *sm, const u8 *bssid,
  169. const u8 *pmkid)
  170. {
  171. WPA_ASSERT(sm->ctx->add_pmkid);
  172. return sm->ctx->add_pmkid(sm->ctx->ctx, bssid, pmkid);
  173. }
  174. static inline int wpa_sm_remove_pmkid(struct wpa_sm *sm, const u8 *bssid,
  175. const u8 *pmkid)
  176. {
  177. WPA_ASSERT(sm->ctx->remove_pmkid);
  178. return sm->ctx->remove_pmkid(sm->ctx->ctx, bssid, pmkid);
  179. }
  180. static inline int wpa_sm_mlme_setprotection(struct wpa_sm *sm, const u8 *addr,
  181. int protect_type, int key_type)
  182. {
  183. WPA_ASSERT(sm->ctx->mlme_setprotection);
  184. return sm->ctx->mlme_setprotection(sm->ctx->ctx, addr, protect_type,
  185. key_type);
  186. }
  187. static inline int wpa_sm_update_ft_ies(struct wpa_sm *sm, const u8 *md,
  188. const u8 *ies, size_t ies_len)
  189. {
  190. if (sm->ctx->update_ft_ies)
  191. return sm->ctx->update_ft_ies(sm->ctx->ctx, md, ies, ies_len);
  192. return -1;
  193. }
  194. static inline int wpa_sm_send_ft_action(struct wpa_sm *sm, u8 action,
  195. const u8 *target_ap,
  196. const u8 *ies, size_t ies_len)
  197. {
  198. if (sm->ctx->send_ft_action)
  199. return sm->ctx->send_ft_action(sm->ctx->ctx, action, target_ap,
  200. ies, ies_len);
  201. return -1;
  202. }
  203. static inline int wpa_sm_mark_authenticated(struct wpa_sm *sm,
  204. const u8 *target_ap)
  205. {
  206. if (sm->ctx->mark_authenticated)
  207. return sm->ctx->mark_authenticated(sm->ctx->ctx, target_ap);
  208. return -1;
  209. }
  210. #ifdef CONFIG_TDLS
  211. static inline int wpa_sm_send_tdls_mgmt(struct wpa_sm *sm, const u8 *dst,
  212. u8 action_code, u8 dialog_token,
  213. u16 status_code, const u8 *buf,
  214. size_t len)
  215. {
  216. if (sm->ctx->send_tdls_mgmt)
  217. return sm->ctx->send_tdls_mgmt(sm->ctx->ctx, dst, action_code,
  218. dialog_token, status_code,
  219. buf, len);
  220. return -1;
  221. }
  222. static inline int wpa_sm_tdls_oper(struct wpa_sm *sm, int oper,
  223. const u8 *peer)
  224. {
  225. if (sm->ctx->tdls_oper)
  226. return sm->ctx->tdls_oper(sm->ctx->ctx, oper, peer);
  227. return -1;
  228. }
  229. #endif /* CONFIG_TDLS */
  230. void wpa_eapol_key_send(struct wpa_sm *sm, const u8 *kck,
  231. int ver, const u8 *dest, u16 proto,
  232. u8 *msg, size_t msg_len, u8 *key_mic);
  233. int wpa_supplicant_send_2_of_4(struct wpa_sm *sm, const unsigned char *dst,
  234. const struct wpa_eapol_key *key,
  235. int ver, const u8 *nonce,
  236. const u8 *wpa_ie, size_t wpa_ie_len,
  237. struct wpa_ptk *ptk);
  238. int wpa_supplicant_send_4_of_4(struct wpa_sm *sm, const unsigned char *dst,
  239. const struct wpa_eapol_key *key,
  240. u16 ver, u16 key_info,
  241. const u8 *kde, size_t kde_len,
  242. struct wpa_ptk *ptk);
  243. int wpa_derive_ptk_ft(struct wpa_sm *sm, const unsigned char *src_addr,
  244. const struct wpa_eapol_key *key,
  245. struct wpa_ptk *ptk, size_t ptk_len);
  246. void wpa_tdls_assoc(struct wpa_sm *sm);
  247. void wpa_tdls_disassoc(struct wpa_sm *sm);
  248. #endif /* WPA_I_H */