wpa_auth.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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. int rsn_pairwise;
  124. int rsn_preauth;
  125. int eapol_version;
  126. int peerkey;
  127. int wmm_enabled;
  128. int wmm_uapsd;
  129. int disable_pmksa_caching;
  130. int okc;
  131. int tx_status;
  132. #ifdef CONFIG_IEEE80211W
  133. enum mfp_options ieee80211w;
  134. int group_mgmt_cipher;
  135. #endif /* CONFIG_IEEE80211W */
  136. #ifdef CONFIG_IEEE80211R_AP
  137. u8 ssid[SSID_MAX_LEN];
  138. size_t ssid_len;
  139. u8 mobility_domain[MOBILITY_DOMAIN_ID_LEN];
  140. u8 r0_key_holder[FT_R0KH_ID_MAX_LEN];
  141. size_t r0_key_holder_len;
  142. u8 r1_key_holder[FT_R1KH_ID_LEN];
  143. u32 r0_key_lifetime;
  144. u32 reassociation_deadline;
  145. struct ft_remote_r0kh *r0kh_list;
  146. struct ft_remote_r1kh *r1kh_list;
  147. int pmk_r1_push;
  148. int ft_over_ds;
  149. int ft_psk_generate_local;
  150. #endif /* CONFIG_IEEE80211R_AP */
  151. int disable_gtk;
  152. int ap_mlme;
  153. #ifdef CONFIG_TESTING_OPTIONS
  154. double corrupt_gtk_rekey_mic_probability;
  155. u8 own_ie_override[MAX_OWN_IE_OVERRIDE];
  156. size_t own_ie_override_len;
  157. #endif /* CONFIG_TESTING_OPTIONS */
  158. #ifdef CONFIG_P2P
  159. u8 ip_addr_go[4];
  160. u8 ip_addr_mask[4];
  161. u8 ip_addr_start[4];
  162. u8 ip_addr_end[4];
  163. #endif /* CONFIG_P2P */
  164. };
  165. typedef enum {
  166. LOGGER_DEBUG, LOGGER_INFO, LOGGER_WARNING
  167. } logger_level;
  168. typedef enum {
  169. WPA_EAPOL_portEnabled, WPA_EAPOL_portValid, WPA_EAPOL_authorized,
  170. WPA_EAPOL_portControl_Auto, WPA_EAPOL_keyRun, WPA_EAPOL_keyAvailable,
  171. WPA_EAPOL_keyDone, WPA_EAPOL_inc_EapolFramesTx
  172. } wpa_eapol_variable;
  173. struct wpa_auth_callbacks {
  174. void *ctx;
  175. void (*logger)(void *ctx, const u8 *addr, logger_level level,
  176. const char *txt);
  177. void (*disconnect)(void *ctx, const u8 *addr, u16 reason);
  178. int (*mic_failure_report)(void *ctx, const u8 *addr);
  179. void (*psk_failure_report)(void *ctx, const u8 *addr);
  180. void (*set_eapol)(void *ctx, const u8 *addr, wpa_eapol_variable var,
  181. int value);
  182. int (*get_eapol)(void *ctx, const u8 *addr, wpa_eapol_variable var);
  183. const u8 * (*get_psk)(void *ctx, const u8 *addr, const u8 *p2p_dev_addr,
  184. const u8 *prev_psk);
  185. int (*get_msk)(void *ctx, const u8 *addr, u8 *msk, size_t *len);
  186. int (*set_key)(void *ctx, int vlan_id, enum wpa_alg alg,
  187. const u8 *addr, int idx, u8 *key, size_t key_len);
  188. int (*get_seqnum)(void *ctx, const u8 *addr, int idx, u8 *seq);
  189. int (*send_eapol)(void *ctx, const u8 *addr, const u8 *data,
  190. size_t data_len, int encrypt);
  191. int (*for_each_sta)(void *ctx, int (*cb)(struct wpa_state_machine *sm,
  192. void *ctx), void *cb_ctx);
  193. int (*for_each_auth)(void *ctx, int (*cb)(struct wpa_authenticator *a,
  194. void *ctx), void *cb_ctx);
  195. int (*send_ether)(void *ctx, const u8 *dst, u16 proto, const u8 *data,
  196. size_t data_len);
  197. #ifdef CONFIG_IEEE80211R_AP
  198. struct wpa_state_machine * (*add_sta)(void *ctx, const u8 *sta_addr);
  199. int (*send_ft_action)(void *ctx, const u8 *dst,
  200. const u8 *data, size_t data_len);
  201. int (*add_tspec)(void *ctx, const u8 *sta_addr, u8 *tspec_ie,
  202. size_t tspec_ielen);
  203. #endif /* CONFIG_IEEE80211R_AP */
  204. #ifdef CONFIG_MESH
  205. int (*start_ampe)(void *ctx, const u8 *sta_addr);
  206. #endif /* CONFIG_MESH */
  207. };
  208. struct wpa_authenticator * wpa_init(const u8 *addr,
  209. struct wpa_auth_config *conf,
  210. struct wpa_auth_callbacks *cb);
  211. int wpa_init_keys(struct wpa_authenticator *wpa_auth);
  212. void wpa_deinit(struct wpa_authenticator *wpa_auth);
  213. int wpa_reconfig(struct wpa_authenticator *wpa_auth,
  214. struct wpa_auth_config *conf);
  215. enum {
  216. WPA_IE_OK, WPA_INVALID_IE, WPA_INVALID_GROUP, WPA_INVALID_PAIRWISE,
  217. WPA_INVALID_AKMP, WPA_NOT_ENABLED, WPA_ALLOC_FAIL,
  218. WPA_MGMT_FRAME_PROTECTION_VIOLATION, WPA_INVALID_MGMT_GROUP_CIPHER,
  219. WPA_INVALID_MDIE, WPA_INVALID_PROTO
  220. };
  221. int wpa_validate_wpa_ie(struct wpa_authenticator *wpa_auth,
  222. struct wpa_state_machine *sm,
  223. const u8 *wpa_ie, size_t wpa_ie_len,
  224. const u8 *mdie, size_t mdie_len);
  225. int wpa_validate_osen(struct wpa_authenticator *wpa_auth,
  226. struct wpa_state_machine *sm,
  227. const u8 *osen_ie, size_t osen_ie_len);
  228. int wpa_auth_uses_mfp(struct wpa_state_machine *sm);
  229. struct wpa_state_machine *
  230. wpa_auth_sta_init(struct wpa_authenticator *wpa_auth, const u8 *addr,
  231. const u8 *p2p_dev_addr);
  232. int wpa_auth_sta_associated(struct wpa_authenticator *wpa_auth,
  233. struct wpa_state_machine *sm);
  234. void wpa_auth_sta_no_wpa(struct wpa_state_machine *sm);
  235. void wpa_auth_sta_deinit(struct wpa_state_machine *sm);
  236. void wpa_receive(struct wpa_authenticator *wpa_auth,
  237. struct wpa_state_machine *sm,
  238. u8 *data, size_t data_len);
  239. enum wpa_event {
  240. WPA_AUTH, WPA_ASSOC, WPA_DISASSOC, WPA_DEAUTH, WPA_REAUTH,
  241. WPA_REAUTH_EAPOL, WPA_ASSOC_FT
  242. };
  243. void wpa_remove_ptk(struct wpa_state_machine *sm);
  244. int wpa_auth_sm_event(struct wpa_state_machine *sm, enum wpa_event event);
  245. void wpa_auth_sm_notify(struct wpa_state_machine *sm);
  246. void wpa_gtk_rekey(struct wpa_authenticator *wpa_auth);
  247. int wpa_get_mib(struct wpa_authenticator *wpa_auth, char *buf, size_t buflen);
  248. int wpa_get_mib_sta(struct wpa_state_machine *sm, char *buf, size_t buflen);
  249. void wpa_auth_countermeasures_start(struct wpa_authenticator *wpa_auth);
  250. int wpa_auth_pairwise_set(struct wpa_state_machine *sm);
  251. int wpa_auth_get_pairwise(struct wpa_state_machine *sm);
  252. int wpa_auth_sta_key_mgmt(struct wpa_state_machine *sm);
  253. int wpa_auth_sta_wpa_version(struct wpa_state_machine *sm);
  254. int wpa_auth_sta_clear_pmksa(struct wpa_state_machine *sm,
  255. struct rsn_pmksa_cache_entry *entry);
  256. struct rsn_pmksa_cache_entry *
  257. wpa_auth_sta_get_pmksa(struct wpa_state_machine *sm);
  258. void wpa_auth_sta_local_mic_failure_report(struct wpa_state_machine *sm);
  259. const u8 * wpa_auth_get_wpa_ie(struct wpa_authenticator *wpa_auth,
  260. size_t *len);
  261. int wpa_auth_pmksa_add(struct wpa_state_machine *sm, const u8 *pmk,
  262. unsigned int pmk_len,
  263. int session_timeout, struct eapol_state_machine *eapol);
  264. int wpa_auth_pmksa_add_preauth(struct wpa_authenticator *wpa_auth,
  265. const u8 *pmk, size_t len, const u8 *sta_addr,
  266. int session_timeout,
  267. struct eapol_state_machine *eapol);
  268. int wpa_auth_pmksa_add_sae(struct wpa_authenticator *wpa_auth, const u8 *addr,
  269. const u8 *pmk, const u8 *pmkid);
  270. void wpa_auth_pmksa_remove(struct wpa_authenticator *wpa_auth,
  271. const u8 *sta_addr);
  272. int wpa_auth_pmksa_list(struct wpa_authenticator *wpa_auth, char *buf,
  273. size_t len);
  274. void wpa_auth_pmksa_flush(struct wpa_authenticator *wpa_auth);
  275. int wpa_auth_pmksa_list_mesh(struct wpa_authenticator *wpa_auth, const u8 *addr,
  276. char *buf, size_t len);
  277. struct rsn_pmksa_cache_entry *
  278. wpa_auth_pmksa_create_entry(const u8 *aa, const u8 *spa, const u8 *pmk,
  279. const u8 *pmkid, int expiration);
  280. int wpa_auth_pmksa_add_entry(struct wpa_authenticator *wpa_auth,
  281. struct rsn_pmksa_cache_entry *entry);
  282. struct rsn_pmksa_cache_entry *
  283. wpa_auth_pmksa_get(struct wpa_authenticator *wpa_auth, const u8 *sta_addr,
  284. const u8 *pmkid);
  285. void wpa_auth_pmksa_set_to_sm(struct rsn_pmksa_cache_entry *pmksa,
  286. struct wpa_state_machine *sm,
  287. struct wpa_authenticator *wpa_auth,
  288. u8 *pmkid, u8 *pmk);
  289. int wpa_auth_sta_set_vlan(struct wpa_state_machine *sm, int vlan_id);
  290. void wpa_auth_eapol_key_tx_status(struct wpa_authenticator *wpa_auth,
  291. struct wpa_state_machine *sm, int ack);
  292. #ifdef CONFIG_IEEE80211R_AP
  293. u8 * wpa_sm_write_assoc_resp_ies(struct wpa_state_machine *sm, u8 *pos,
  294. size_t max_len, int auth_alg,
  295. const u8 *req_ies, size_t req_ies_len);
  296. void wpa_ft_process_auth(struct wpa_state_machine *sm, const u8 *bssid,
  297. u16 auth_transaction, const u8 *ies, size_t ies_len,
  298. void (*cb)(void *ctx, const u8 *dst, const u8 *bssid,
  299. u16 auth_transaction, u16 resp,
  300. const u8 *ies, size_t ies_len),
  301. void *ctx);
  302. u16 wpa_ft_validate_reassoc(struct wpa_state_machine *sm, const u8 *ies,
  303. size_t ies_len);
  304. int wpa_ft_action_rx(struct wpa_state_machine *sm, const u8 *data, size_t len);
  305. int wpa_ft_rrb_rx(struct wpa_authenticator *wpa_auth, const u8 *src_addr,
  306. const u8 *data, size_t data_len);
  307. void wpa_ft_push_pmk_r1(struct wpa_authenticator *wpa_auth, const u8 *addr);
  308. #endif /* CONFIG_IEEE80211R_AP */
  309. void wpa_wnmsleep_rekey_gtk(struct wpa_state_machine *sm);
  310. void wpa_set_wnmsleep(struct wpa_state_machine *sm, int flag);
  311. int wpa_wnmsleep_gtk_subelem(struct wpa_state_machine *sm, u8 *pos);
  312. int wpa_wnmsleep_igtk_subelem(struct wpa_state_machine *sm, u8 *pos);
  313. int wpa_auth_uses_sae(struct wpa_state_machine *sm);
  314. int wpa_auth_uses_ft_sae(struct wpa_state_machine *sm);
  315. int wpa_auth_get_ip_addr(struct wpa_state_machine *sm, u8 *addr);
  316. struct radius_das_attrs;
  317. int wpa_auth_radius_das_disconnect_pmksa(struct wpa_authenticator *wpa_auth,
  318. struct radius_das_attrs *attr);
  319. void wpa_auth_reconfig_group_keys(struct wpa_authenticator *wpa_auth);
  320. int wpa_auth_ensure_group(struct wpa_authenticator *wpa_auth, int vlan_id);
  321. int wpa_auth_release_group(struct wpa_authenticator *wpa_auth, int vlan_id);
  322. int fils_auth_pmk_to_ptk(struct wpa_state_machine *sm, const u8 *pmk,
  323. size_t pmk_len, const u8 *snonce, const u8 *anonce);
  324. int fils_decrypt_assoc(struct wpa_state_machine *sm, const u8 *fils_session,
  325. const struct ieee80211_mgmt *mgmt, size_t frame_len,
  326. u8 *pos, size_t left);
  327. int fils_encrypt_assoc(struct wpa_state_machine *sm, u8 *buf,
  328. size_t current_len, size_t max_len);
  329. int fils_set_tk(struct wpa_state_machine *sm);
  330. #endif /* WPA_AUTH_H */