wpa_auth.h 13 KB

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