wpa_auth.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. /*
  2. * hostapd - IEEE 802.11i-2004 / WPA Authenticator
  3. * Copyright (c) 2004-2007, 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_AUTH_H
  9. #define WPA_AUTH_H
  10. #include "common/defs.h"
  11. #include "common/eapol_common.h"
  12. #include "common/wpa_common.h"
  13. #ifdef _MSC_VER
  14. #pragma pack(push, 1)
  15. #endif /* _MSC_VER */
  16. /* IEEE Std 802.11r-2008, 11A.10.3 - Remote request/response frame definition
  17. */
  18. struct ft_rrb_frame {
  19. u8 frame_type; /* RSN_REMOTE_FRAME_TYPE_FT_RRB */
  20. u8 packet_type; /* FT_PACKET_REQUEST/FT_PACKET_RESPONSE */
  21. le16 action_length; /* little endian length of action_frame */
  22. u8 ap_address[ETH_ALEN];
  23. /*
  24. * Followed by action_length bytes of FT Action frame (from Category
  25. * field to the end of Action Frame body.
  26. */
  27. } STRUCT_PACKED;
  28. #define RSN_REMOTE_FRAME_TYPE_FT_RRB 1
  29. #define FT_PACKET_REQUEST 0
  30. #define FT_PACKET_RESPONSE 1
  31. /* Vendor-specific types for R0KH-R1KH protocol; not defined in 802.11r */
  32. #define FT_PACKET_R0KH_R1KH_PULL 200
  33. #define FT_PACKET_R0KH_R1KH_RESP 201
  34. #define FT_PACKET_R0KH_R1KH_PUSH 202
  35. #define FT_R0KH_R1KH_PULL_DATA_LEN 44
  36. #define FT_R0KH_R1KH_RESP_DATA_LEN 76
  37. #define FT_R0KH_R1KH_PUSH_DATA_LEN 88
  38. #define FT_R0KH_R1KH_PULL_NONCE_LEN 16
  39. struct ft_r0kh_r1kh_pull_frame {
  40. u8 frame_type; /* RSN_REMOTE_FRAME_TYPE_FT_RRB */
  41. u8 packet_type; /* FT_PACKET_R0KH_R1KH_PULL */
  42. le16 data_length; /* little endian length of data (44) */
  43. u8 ap_address[ETH_ALEN];
  44. u8 nonce[FT_R0KH_R1KH_PULL_NONCE_LEN];
  45. u8 pmk_r0_name[WPA_PMK_NAME_LEN];
  46. u8 r1kh_id[FT_R1KH_ID_LEN];
  47. u8 s1kh_id[ETH_ALEN];
  48. u8 pad[4]; /* 8-octet boundary for AES key wrap */
  49. u8 key_wrap_extra[8];
  50. } STRUCT_PACKED;
  51. struct ft_r0kh_r1kh_resp_frame {
  52. u8 frame_type; /* RSN_REMOTE_FRAME_TYPE_FT_RRB */
  53. u8 packet_type; /* FT_PACKET_R0KH_R1KH_RESP */
  54. le16 data_length; /* little endian length of data (76) */
  55. u8 ap_address[ETH_ALEN];
  56. u8 nonce[FT_R0KH_R1KH_PULL_NONCE_LEN]; /* copied from pull */
  57. u8 r1kh_id[FT_R1KH_ID_LEN]; /* copied from pull */
  58. u8 s1kh_id[ETH_ALEN]; /* copied from pull */
  59. u8 pmk_r1[PMK_LEN];
  60. u8 pmk_r1_name[WPA_PMK_NAME_LEN];
  61. le16 pairwise;
  62. u8 pad[2]; /* 8-octet boundary for AES key wrap */
  63. u8 key_wrap_extra[8];
  64. } STRUCT_PACKED;
  65. struct ft_r0kh_r1kh_push_frame {
  66. u8 frame_type; /* RSN_REMOTE_FRAME_TYPE_FT_RRB */
  67. u8 packet_type; /* FT_PACKET_R0KH_R1KH_PUSH */
  68. le16 data_length; /* little endian length of data (88) */
  69. u8 ap_address[ETH_ALEN];
  70. /* Encrypted with AES key-wrap */
  71. u8 timestamp[4]; /* current time in seconds since unix epoch, little
  72. * endian */
  73. u8 r1kh_id[FT_R1KH_ID_LEN];
  74. u8 s1kh_id[ETH_ALEN];
  75. u8 pmk_r0_name[WPA_PMK_NAME_LEN];
  76. u8 pmk_r1[PMK_LEN];
  77. u8 pmk_r1_name[WPA_PMK_NAME_LEN];
  78. le16 pairwise;
  79. u8 pad[6]; /* 8-octet boundary for AES key wrap */
  80. u8 key_wrap_extra[8];
  81. } STRUCT_PACKED;
  82. #ifdef _MSC_VER
  83. #pragma pack(pop)
  84. #endif /* _MSC_VER */
  85. /* per STA state machine data */
  86. struct wpa_authenticator;
  87. struct wpa_state_machine;
  88. struct rsn_pmksa_cache_entry;
  89. struct eapol_state_machine;
  90. struct ft_remote_r0kh {
  91. struct ft_remote_r0kh *next;
  92. u8 addr[ETH_ALEN];
  93. u8 id[FT_R0KH_ID_MAX_LEN];
  94. size_t id_len;
  95. u8 key[16];
  96. };
  97. struct ft_remote_r1kh {
  98. struct ft_remote_r1kh *next;
  99. u8 addr[ETH_ALEN];
  100. u8 id[FT_R1KH_ID_LEN];
  101. u8 key[16];
  102. };
  103. struct wpa_auth_config {
  104. int wpa;
  105. int wpa_key_mgmt;
  106. int wpa_pairwise;
  107. int wpa_group;
  108. int wpa_group_rekey;
  109. int wpa_strict_rekey;
  110. int wpa_gmk_rekey;
  111. int wpa_ptk_rekey;
  112. int rsn_pairwise;
  113. int rsn_preauth;
  114. int eapol_version;
  115. int peerkey;
  116. int wmm_enabled;
  117. int wmm_uapsd;
  118. int disable_pmksa_caching;
  119. int okc;
  120. int tx_status;
  121. #ifdef CONFIG_IEEE80211W
  122. enum mfp_options ieee80211w;
  123. int group_mgmt_cipher;
  124. #endif /* CONFIG_IEEE80211W */
  125. #ifdef CONFIG_IEEE80211R
  126. #define SSID_LEN 32
  127. u8 ssid[SSID_LEN];
  128. size_t ssid_len;
  129. u8 mobility_domain[MOBILITY_DOMAIN_ID_LEN];
  130. u8 r0_key_holder[FT_R0KH_ID_MAX_LEN];
  131. size_t r0_key_holder_len;
  132. u8 r1_key_holder[FT_R1KH_ID_LEN];
  133. u32 r0_key_lifetime;
  134. u32 reassociation_deadline;
  135. struct ft_remote_r0kh *r0kh_list;
  136. struct ft_remote_r1kh *r1kh_list;
  137. int pmk_r1_push;
  138. int ft_over_ds;
  139. #endif /* CONFIG_IEEE80211R */
  140. int disable_gtk;
  141. int ap_mlme;
  142. #ifdef CONFIG_TESTING_OPTIONS
  143. double corrupt_gtk_rekey_mic_probability;
  144. #endif /* CONFIG_TESTING_OPTIONS */
  145. #ifdef CONFIG_P2P
  146. u8 ip_addr_go[4];
  147. u8 ip_addr_mask[4];
  148. u8 ip_addr_start[4];
  149. u8 ip_addr_end[4];
  150. #endif /* CONFIG_P2P */
  151. };
  152. typedef enum {
  153. LOGGER_DEBUG, LOGGER_INFO, LOGGER_WARNING
  154. } logger_level;
  155. typedef enum {
  156. WPA_EAPOL_portEnabled, WPA_EAPOL_portValid, WPA_EAPOL_authorized,
  157. WPA_EAPOL_portControl_Auto, WPA_EAPOL_keyRun, WPA_EAPOL_keyAvailable,
  158. WPA_EAPOL_keyDone, WPA_EAPOL_inc_EapolFramesTx
  159. } wpa_eapol_variable;
  160. struct wpa_auth_callbacks {
  161. void *ctx;
  162. void (*logger)(void *ctx, const u8 *addr, logger_level level,
  163. const char *txt);
  164. void (*disconnect)(void *ctx, const u8 *addr, u16 reason);
  165. int (*mic_failure_report)(void *ctx, const u8 *addr);
  166. void (*set_eapol)(void *ctx, const u8 *addr, wpa_eapol_variable var,
  167. int value);
  168. int (*get_eapol)(void *ctx, const u8 *addr, wpa_eapol_variable var);
  169. const u8 * (*get_psk)(void *ctx, const u8 *addr, const u8 *p2p_dev_addr,
  170. const u8 *prev_psk);
  171. int (*get_msk)(void *ctx, const u8 *addr, u8 *msk, size_t *len);
  172. int (*set_key)(void *ctx, int vlan_id, enum wpa_alg alg,
  173. const u8 *addr, int idx, u8 *key, size_t key_len);
  174. int (*get_seqnum)(void *ctx, const u8 *addr, int idx, u8 *seq);
  175. int (*send_eapol)(void *ctx, const u8 *addr, const u8 *data,
  176. size_t data_len, int encrypt);
  177. int (*for_each_sta)(void *ctx, int (*cb)(struct wpa_state_machine *sm,
  178. void *ctx), void *cb_ctx);
  179. int (*for_each_auth)(void *ctx, int (*cb)(struct wpa_authenticator *a,
  180. void *ctx), void *cb_ctx);
  181. int (*send_ether)(void *ctx, const u8 *dst, u16 proto, const u8 *data,
  182. size_t data_len);
  183. #ifdef CONFIG_IEEE80211R
  184. struct wpa_state_machine * (*add_sta)(void *ctx, const u8 *sta_addr);
  185. int (*send_ft_action)(void *ctx, const u8 *dst,
  186. const u8 *data, size_t data_len);
  187. int (*add_tspec)(void *ctx, const u8 *sta_addr, u8 *tspec_ie,
  188. size_t tspec_ielen);
  189. #endif /* CONFIG_IEEE80211R */
  190. #ifdef CONFIG_MESH
  191. int (*start_ampe)(void *ctx, const u8 *sta_addr);
  192. #endif /* CONFIG_MESH */
  193. };
  194. struct wpa_authenticator * wpa_init(const u8 *addr,
  195. struct wpa_auth_config *conf,
  196. struct wpa_auth_callbacks *cb);
  197. int wpa_init_keys(struct wpa_authenticator *wpa_auth);
  198. void wpa_deinit(struct wpa_authenticator *wpa_auth);
  199. int wpa_reconfig(struct wpa_authenticator *wpa_auth,
  200. struct wpa_auth_config *conf);
  201. enum {
  202. WPA_IE_OK, WPA_INVALID_IE, WPA_INVALID_GROUP, WPA_INVALID_PAIRWISE,
  203. WPA_INVALID_AKMP, WPA_NOT_ENABLED, WPA_ALLOC_FAIL,
  204. WPA_MGMT_FRAME_PROTECTION_VIOLATION, WPA_INVALID_MGMT_GROUP_CIPHER,
  205. WPA_INVALID_MDIE, WPA_INVALID_PROTO
  206. };
  207. int wpa_validate_wpa_ie(struct wpa_authenticator *wpa_auth,
  208. struct wpa_state_machine *sm,
  209. const u8 *wpa_ie, size_t wpa_ie_len,
  210. const u8 *mdie, size_t mdie_len);
  211. int wpa_validate_osen(struct wpa_authenticator *wpa_auth,
  212. struct wpa_state_machine *sm,
  213. const u8 *osen_ie, size_t osen_ie_len);
  214. int wpa_auth_uses_mfp(struct wpa_state_machine *sm);
  215. struct wpa_state_machine *
  216. wpa_auth_sta_init(struct wpa_authenticator *wpa_auth, const u8 *addr,
  217. const u8 *p2p_dev_addr);
  218. int wpa_auth_sta_associated(struct wpa_authenticator *wpa_auth,
  219. struct wpa_state_machine *sm);
  220. void wpa_auth_sta_no_wpa(struct wpa_state_machine *sm);
  221. void wpa_auth_sta_deinit(struct wpa_state_machine *sm);
  222. void wpa_receive(struct wpa_authenticator *wpa_auth,
  223. struct wpa_state_machine *sm,
  224. u8 *data, size_t data_len);
  225. typedef enum {
  226. WPA_AUTH, WPA_ASSOC, WPA_DISASSOC, WPA_DEAUTH, WPA_REAUTH,
  227. WPA_REAUTH_EAPOL, WPA_ASSOC_FT
  228. } wpa_event;
  229. void wpa_remove_ptk(struct wpa_state_machine *sm);
  230. int wpa_auth_sm_event(struct wpa_state_machine *sm, wpa_event event);
  231. void wpa_auth_sm_notify(struct wpa_state_machine *sm);
  232. void wpa_gtk_rekey(struct wpa_authenticator *wpa_auth);
  233. int wpa_get_mib(struct wpa_authenticator *wpa_auth, char *buf, size_t buflen);
  234. int wpa_get_mib_sta(struct wpa_state_machine *sm, char *buf, size_t buflen);
  235. void wpa_auth_countermeasures_start(struct wpa_authenticator *wpa_auth);
  236. int wpa_auth_pairwise_set(struct wpa_state_machine *sm);
  237. int wpa_auth_get_pairwise(struct wpa_state_machine *sm);
  238. int wpa_auth_sta_key_mgmt(struct wpa_state_machine *sm);
  239. int wpa_auth_sta_wpa_version(struct wpa_state_machine *sm);
  240. int wpa_auth_sta_clear_pmksa(struct wpa_state_machine *sm,
  241. struct rsn_pmksa_cache_entry *entry);
  242. struct rsn_pmksa_cache_entry *
  243. wpa_auth_sta_get_pmksa(struct wpa_state_machine *sm);
  244. void wpa_auth_sta_local_mic_failure_report(struct wpa_state_machine *sm);
  245. const u8 * wpa_auth_get_wpa_ie(struct wpa_authenticator *wpa_auth,
  246. size_t *len);
  247. int wpa_auth_pmksa_add(struct wpa_state_machine *sm, const u8 *pmk,
  248. int session_timeout, struct eapol_state_machine *eapol);
  249. int wpa_auth_pmksa_add_preauth(struct wpa_authenticator *wpa_auth,
  250. const u8 *pmk, size_t len, const u8 *sta_addr,
  251. int session_timeout,
  252. struct eapol_state_machine *eapol);
  253. int wpa_auth_pmksa_add_sae(struct wpa_authenticator *wpa_auth, const u8 *addr,
  254. const u8 *pmk);
  255. void wpa_auth_pmksa_remove(struct wpa_authenticator *wpa_auth,
  256. const u8 *sta_addr);
  257. int wpa_auth_sta_set_vlan(struct wpa_state_machine *sm, int vlan_id);
  258. void wpa_auth_eapol_key_tx_status(struct wpa_authenticator *wpa_auth,
  259. struct wpa_state_machine *sm, int ack);
  260. #ifdef CONFIG_IEEE80211R
  261. u8 * wpa_sm_write_assoc_resp_ies(struct wpa_state_machine *sm, u8 *pos,
  262. size_t max_len, int auth_alg,
  263. const u8 *req_ies, size_t req_ies_len);
  264. void wpa_ft_process_auth(struct wpa_state_machine *sm, const u8 *bssid,
  265. u16 auth_transaction, const u8 *ies, size_t ies_len,
  266. void (*cb)(void *ctx, const u8 *dst, const u8 *bssid,
  267. u16 auth_transaction, u16 resp,
  268. const u8 *ies, size_t ies_len),
  269. void *ctx);
  270. u16 wpa_ft_validate_reassoc(struct wpa_state_machine *sm, const u8 *ies,
  271. size_t ies_len);
  272. int wpa_ft_action_rx(struct wpa_state_machine *sm, const u8 *data, size_t len);
  273. int wpa_ft_rrb_rx(struct wpa_authenticator *wpa_auth, const u8 *src_addr,
  274. const u8 *data, size_t data_len);
  275. void wpa_ft_push_pmk_r1(struct wpa_authenticator *wpa_auth, const u8 *addr);
  276. #endif /* CONFIG_IEEE80211R */
  277. void wpa_wnmsleep_rekey_gtk(struct wpa_state_machine *sm);
  278. void wpa_set_wnmsleep(struct wpa_state_machine *sm, int flag);
  279. int wpa_wnmsleep_gtk_subelem(struct wpa_state_machine *sm, u8 *pos);
  280. int wpa_wnmsleep_igtk_subelem(struct wpa_state_machine *sm, u8 *pos);
  281. int wpa_auth_uses_sae(struct wpa_state_machine *sm);
  282. int wpa_auth_uses_ft_sae(struct wpa_state_machine *sm);
  283. int wpa_auth_get_ip_addr(struct wpa_state_machine *sm, u8 *addr);
  284. struct radius_das_attrs;
  285. int wpa_auth_radius_das_disconnect_pmksa(struct wpa_authenticator *wpa_auth,
  286. struct radius_das_attrs *attr);
  287. void wpa_auth_reconfig_group_keys(struct wpa_authenticator *wpa_auth);
  288. #endif /* WPA_AUTH_H */