wpa.h 9.4 KB

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