wpa.h 9.3 KB

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