wpa_i.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /*
  2. * wpa_supplicant - Internal WPA state machine definitions
  3. * Copyright (c) 2004-2007, 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. struct rsn_pmksa_candidate;
  17. struct wpa_peerkey;
  18. struct wpa_eapol_key;
  19. /**
  20. * struct wpa_sm - Internal WPA state machine data
  21. */
  22. struct wpa_sm {
  23. u8 pmk[PMK_LEN];
  24. size_t pmk_len;
  25. struct wpa_ptk ptk, tptk;
  26. int ptk_set, tptk_set;
  27. u8 snonce[WPA_NONCE_LEN];
  28. u8 anonce[WPA_NONCE_LEN]; /* ANonce from the last 1/4 msg */
  29. int renew_snonce;
  30. u8 rx_replay_counter[WPA_REPLAY_COUNTER_LEN];
  31. int rx_replay_counter_set;
  32. u8 request_counter[WPA_REPLAY_COUNTER_LEN];
  33. struct eapol_sm *eapol; /* EAPOL state machine from upper level code */
  34. struct rsn_pmksa_cache *pmksa; /* PMKSA cache */
  35. struct rsn_pmksa_cache_entry *cur_pmksa; /* current PMKSA entry */
  36. struct rsn_pmksa_candidate *pmksa_candidates;
  37. struct l2_packet_data *l2_preauth;
  38. struct l2_packet_data *l2_preauth_br;
  39. u8 preauth_bssid[ETH_ALEN]; /* current RSN pre-auth peer or
  40. * 00:00:00:00:00:00 if no pre-auth is
  41. * in progress */
  42. struct eapol_sm *preauth_eapol;
  43. struct wpa_sm_ctx *ctx;
  44. void *scard_ctx; /* context for smartcard callbacks */
  45. int fast_reauth; /* whether EAP fast re-authentication is enabled */
  46. void *network_ctx;
  47. int peerkey_enabled;
  48. int allowed_pairwise_cipher; /* bitfield of WPA_CIPHER_* */
  49. int proactive_key_caching;
  50. int eap_workaround;
  51. void *eap_conf_ctx;
  52. u8 ssid[32];
  53. size_t ssid_len;
  54. int wpa_ptk_rekey;
  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. u8 *assoc_wpa_ie; /* Own WPA/RSN IE from (Re)AssocReq */
  71. size_t assoc_wpa_ie_len;
  72. u8 *ap_wpa_ie, *ap_rsn_ie;
  73. size_t ap_wpa_ie_len, ap_rsn_ie_len;
  74. #ifdef CONFIG_PEERKEY
  75. struct wpa_peerkey *peerkey;
  76. #endif /* CONFIG_PEERKEY */
  77. #ifdef CONFIG_IEEE80211R
  78. u8 xxkey[PMK_LEN]; /* PSK or the second 256 bits of MSK */
  79. size_t xxkey_len;
  80. u8 pmk_r0[PMK_LEN];
  81. u8 pmk_r0_name[WPA_PMK_NAME_LEN];
  82. u8 pmk_r1[PMK_LEN];
  83. u8 pmk_r1_name[WPA_PMK_NAME_LEN];
  84. u8 mobility_domain[MOBILITY_DOMAIN_ID_LEN];
  85. u8 r0kh_id[FT_R0KH_ID_MAX_LEN];
  86. size_t r0kh_id_len;
  87. u8 r1kh_id[FT_R1KH_ID_LEN];
  88. int ft_completed;
  89. int over_the_ds_in_progress;
  90. u8 target_ap[ETH_ALEN]; /* over-the-DS target AP */
  91. #endif /* CONFIG_IEEE80211R */
  92. };
  93. static inline void wpa_sm_set_state(struct wpa_sm *sm, wpa_states state)
  94. {
  95. WPA_ASSERT(sm->ctx->set_state);
  96. sm->ctx->set_state(sm->ctx->ctx, state);
  97. }
  98. static inline wpa_states wpa_sm_get_state(struct wpa_sm *sm)
  99. {
  100. WPA_ASSERT(sm->ctx->get_state);
  101. return sm->ctx->get_state(sm->ctx->ctx);
  102. }
  103. static inline void wpa_sm_deauthenticate(struct wpa_sm *sm, int reason_code)
  104. {
  105. WPA_ASSERT(sm->ctx->deauthenticate);
  106. sm->ctx->deauthenticate(sm->ctx->ctx, reason_code);
  107. }
  108. static inline void wpa_sm_disassociate(struct wpa_sm *sm, int reason_code)
  109. {
  110. WPA_ASSERT(sm->ctx->disassociate);
  111. sm->ctx->disassociate(sm->ctx->ctx, reason_code);
  112. }
  113. static inline int wpa_sm_set_key(struct wpa_sm *sm, wpa_alg alg,
  114. const u8 *addr, int key_idx, int set_tx,
  115. const u8 *seq, size_t seq_len,
  116. const u8 *key, size_t key_len)
  117. {
  118. WPA_ASSERT(sm->ctx->set_key);
  119. return sm->ctx->set_key(sm->ctx->ctx, alg, addr, key_idx, set_tx,
  120. seq, seq_len, key, key_len);
  121. }
  122. static inline void * wpa_sm_get_network_ctx(struct wpa_sm *sm)
  123. {
  124. WPA_ASSERT(sm->ctx->get_network_ctx);
  125. return sm->ctx->get_network_ctx(sm->ctx->ctx);
  126. }
  127. static inline int wpa_sm_get_bssid(struct wpa_sm *sm, u8 *bssid)
  128. {
  129. WPA_ASSERT(sm->ctx->get_bssid);
  130. return sm->ctx->get_bssid(sm->ctx->ctx, bssid);
  131. }
  132. static inline int wpa_sm_ether_send(struct wpa_sm *sm, const u8 *dest,
  133. u16 proto, const u8 *buf, size_t len)
  134. {
  135. WPA_ASSERT(sm->ctx->ether_send);
  136. return sm->ctx->ether_send(sm->ctx->ctx, dest, proto, buf, len);
  137. }
  138. static inline int wpa_sm_get_beacon_ie(struct wpa_sm *sm)
  139. {
  140. WPA_ASSERT(sm->ctx->get_beacon_ie);
  141. return sm->ctx->get_beacon_ie(sm->ctx->ctx);
  142. }
  143. static inline void wpa_sm_cancel_auth_timeout(struct wpa_sm *sm)
  144. {
  145. WPA_ASSERT(sm->ctx->cancel_auth_timeout);
  146. sm->ctx->cancel_auth_timeout(sm->ctx->ctx);
  147. }
  148. static inline u8 * wpa_sm_alloc_eapol(struct wpa_sm *sm, u8 type,
  149. const void *data, u16 data_len,
  150. size_t *msg_len, void **data_pos)
  151. {
  152. WPA_ASSERT(sm->ctx->alloc_eapol);
  153. return sm->ctx->alloc_eapol(sm->ctx->ctx, type, data, data_len,
  154. msg_len, data_pos);
  155. }
  156. static inline int wpa_sm_add_pmkid(struct wpa_sm *sm, const u8 *bssid,
  157. const u8 *pmkid)
  158. {
  159. WPA_ASSERT(sm->ctx->add_pmkid);
  160. return sm->ctx->add_pmkid(sm->ctx->ctx, bssid, pmkid);
  161. }
  162. static inline int wpa_sm_remove_pmkid(struct wpa_sm *sm, const u8 *bssid,
  163. const u8 *pmkid)
  164. {
  165. WPA_ASSERT(sm->ctx->remove_pmkid);
  166. return sm->ctx->remove_pmkid(sm->ctx->ctx, bssid, pmkid);
  167. }
  168. static inline int wpa_sm_mlme_setprotection(struct wpa_sm *sm, const u8 *addr,
  169. int protect_type, int key_type)
  170. {
  171. WPA_ASSERT(sm->ctx->mlme_setprotection);
  172. return sm->ctx->mlme_setprotection(sm->ctx->ctx, addr, protect_type,
  173. key_type);
  174. }
  175. static inline int wpa_sm_update_ft_ies(struct wpa_sm *sm, const u8 *md,
  176. const u8 *ies, size_t ies_len)
  177. {
  178. if (sm->ctx->update_ft_ies)
  179. return sm->ctx->update_ft_ies(sm->ctx->ctx, md, ies, ies_len);
  180. return -1;
  181. }
  182. static inline int wpa_sm_send_ft_action(struct wpa_sm *sm, u8 action,
  183. const u8 *target_ap,
  184. const u8 *ies, size_t ies_len)
  185. {
  186. if (sm->ctx->send_ft_action)
  187. return sm->ctx->send_ft_action(sm->ctx->ctx, action, target_ap,
  188. ies, ies_len);
  189. return -1;
  190. }
  191. void wpa_eapol_key_send(struct wpa_sm *sm, const u8 *kck,
  192. int ver, const u8 *dest, u16 proto,
  193. u8 *msg, size_t msg_len, u8 *key_mic);
  194. int wpa_supplicant_send_2_of_4(struct wpa_sm *sm, const unsigned char *dst,
  195. const struct wpa_eapol_key *key,
  196. int ver, const u8 *nonce,
  197. const u8 *wpa_ie, size_t wpa_ie_len,
  198. struct wpa_ptk *ptk);
  199. int wpa_supplicant_send_4_of_4(struct wpa_sm *sm, const unsigned char *dst,
  200. const struct wpa_eapol_key *key,
  201. u16 ver, u16 key_info,
  202. const u8 *kde, size_t kde_len,
  203. struct wpa_ptk *ptk);
  204. int wpa_derive_ptk_ft(struct wpa_sm *sm, const unsigned char *src_addr,
  205. const struct wpa_eapol_key *key,
  206. struct wpa_ptk *ptk, size_t ptk_len);
  207. #endif /* WPA_I_H */