wpa.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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 "eapol_common.h"
  17. #include "wpa_common.h"
  18. #ifdef _MSC_VER
  19. #pragma pack(push, 1)
  20. #endif /* _MSC_VER */
  21. /* IEEE 802.11r/D8.0, 11A.10.3 - Remote request/response frame definition */
  22. struct ft_rrb_frame {
  23. u8 frame_type; /* RSN_REMOTE_FRAME_TYPE_FT_RRB */
  24. u8 packet_type; /* FT_PACKET_REQUEST/FT_PACKET_RESPONSE */
  25. u16 action_length; /* little endian length of action_frame */
  26. u8 ap_address[ETH_ALEN];
  27. /*
  28. * Followed by action_length bytes of FT Action frame (from Category
  29. * field to the end of Action Frame body.
  30. */
  31. } STRUCT_PACKED;
  32. #define RSN_REMOTE_FRAME_TYPE_FT_RRB 1
  33. #define FT_PACKET_REQUEST 0
  34. #define FT_PACKET_RESPONSE 1
  35. /* Vendor-specific types for R0KH-R1KH protocol; not defined in 802.11r */
  36. #define FT_PACKET_R0KH_R1KH_PULL 200
  37. #define FT_PACKET_R0KH_R1KH_RESP 201
  38. #define FT_PACKET_R0KH_R1KH_PUSH 202
  39. #ifndef ETH_P_RRB
  40. #define ETH_P_RRB 0x890D
  41. #endif /* ETH_P_RRB */
  42. #define FT_R0KH_R1KH_PULL_DATA_LEN 44
  43. #define FT_R0KH_R1KH_RESP_DATA_LEN 76
  44. #define FT_R0KH_R1KH_PUSH_DATA_LEN 80
  45. struct ft_r0kh_r1kh_pull_frame {
  46. u8 frame_type; /* RSN_REMOTE_FRAME_TYPE_FT_RRB */
  47. u8 packet_type; /* FT_PACKET_R0KH_R1KH_PULL */
  48. u16 data_length; /* little endian length of data (44) */
  49. u8 ap_address[ETH_ALEN];
  50. u8 nonce[16];
  51. u8 pmk_r0_name[WPA_PMK_NAME_LEN];
  52. u8 r1kh_id[FT_R1KH_ID_LEN];
  53. u8 s1kh_id[ETH_ALEN];
  54. u8 pad[4]; /* 8-octet boundary for AES key wrap */
  55. u8 key_wrap_extra[8];
  56. } STRUCT_PACKED;
  57. struct ft_r0kh_r1kh_resp_frame {
  58. u8 frame_type; /* RSN_REMOTE_FRAME_TYPE_FT_RRB */
  59. u8 packet_type; /* FT_PACKET_R0KH_R1KH_RESP */
  60. u16 data_length; /* little endian length of data (76) */
  61. u8 ap_address[ETH_ALEN];
  62. u8 nonce[16]; /* copied from pull */
  63. u8 r1kh_id[FT_R1KH_ID_LEN]; /* copied from pull */
  64. u8 s1kh_id[ETH_ALEN]; /* copied from pull */
  65. u8 pmk_r1[PMK_LEN];
  66. u8 pmk_r1_name[WPA_PMK_NAME_LEN];
  67. u8 pad[4]; /* 8-octet boundary for AES key wrap */
  68. u8 key_wrap_extra[8];
  69. } STRUCT_PACKED;
  70. struct ft_r0kh_r1kh_push_frame {
  71. u8 frame_type; /* RSN_REMOTE_FRAME_TYPE_FT_RRB */
  72. u8 packet_type; /* FT_PACKET_R0KH_R1KH_PUSH */
  73. u16 data_length; /* little endian length of data (80) */
  74. u8 ap_address[ETH_ALEN];
  75. /* Encrypted with AES key-wrap */
  76. u8 timestamp[4]; /* current time in seconds since unix epoch, little
  77. * endian */
  78. u8 r1kh_id[FT_R1KH_ID_LEN];
  79. u8 s1kh_id[ETH_ALEN];
  80. u8 pmk_r0_name[WPA_PMK_NAME_LEN];
  81. u8 pmk_r1[PMK_LEN];
  82. u8 pmk_r1_name[WPA_PMK_NAME_LEN];
  83. u8 key_wrap_extra[8];
  84. } STRUCT_PACKED;
  85. #ifdef _MSC_VER
  86. #pragma pack(pop)
  87. #endif /* _MSC_VER */
  88. /* per STA state machine data */
  89. struct wpa_authenticator;
  90. struct wpa_state_machine;
  91. struct rsn_pmksa_cache_entry;
  92. struct eapol_state_machine;
  93. struct ft_remote_r0kh {
  94. struct ft_remote_r0kh *next;
  95. u8 addr[ETH_ALEN];
  96. u8 id[FT_R0KH_ID_MAX_LEN];
  97. size_t id_len;
  98. u8 key[16];
  99. };
  100. struct ft_remote_r1kh {
  101. struct ft_remote_r1kh *next;
  102. u8 addr[ETH_ALEN];
  103. u8 id[FT_R1KH_ID_LEN];
  104. u8 key[16];
  105. };
  106. struct wpa_auth_config {
  107. int wpa;
  108. int wpa_key_mgmt;
  109. int wpa_pairwise;
  110. int wpa_group;
  111. int wpa_group_rekey;
  112. int wpa_strict_rekey;
  113. int wpa_gmk_rekey;
  114. int rsn_pairwise;
  115. int rsn_preauth;
  116. int eapol_version;
  117. int peerkey;
  118. int wme_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, const char *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
  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_deinit(struct wpa_state_machine *sm);
  201. void wpa_receive(struct wpa_authenticator *wpa_auth,
  202. struct wpa_state_machine *sm,
  203. u8 *data, size_t data_len);
  204. typedef enum {
  205. WPA_AUTH, WPA_ASSOC, WPA_DISASSOC, WPA_DEAUTH, WPA_REAUTH,
  206. WPA_REAUTH_EAPOL, WPA_ASSOC_FT
  207. } wpa_event;
  208. void wpa_remove_ptk(struct wpa_state_machine *sm);
  209. void wpa_auth_sm_event(struct wpa_state_machine *sm, wpa_event event);
  210. void wpa_auth_sm_notify(struct wpa_state_machine *sm);
  211. void wpa_gtk_rekey(struct wpa_authenticator *wpa_auth);
  212. int wpa_get_mib(struct wpa_authenticator *wpa_auth, char *buf, size_t buflen);
  213. int wpa_get_mib_sta(struct wpa_state_machine *sm, char *buf, size_t buflen);
  214. void wpa_auth_countermeasures_start(struct wpa_authenticator *wpa_auth);
  215. int wpa_auth_pairwise_set(struct wpa_state_machine *sm);
  216. int wpa_auth_sta_key_mgmt(struct wpa_state_machine *sm);
  217. int wpa_auth_sta_wpa_version(struct wpa_state_machine *sm);
  218. int wpa_auth_sta_clear_pmksa(struct wpa_state_machine *sm,
  219. struct rsn_pmksa_cache_entry *entry);
  220. struct rsn_pmksa_cache_entry *
  221. wpa_auth_sta_get_pmksa(struct wpa_state_machine *sm);
  222. void wpa_auth_sta_local_mic_failure_report(struct wpa_state_machine *sm);
  223. const u8 * wpa_auth_get_wpa_ie(struct wpa_authenticator *wpa_auth,
  224. size_t *len);
  225. int wpa_auth_pmksa_add(struct wpa_state_machine *sm, const u8 *pmk,
  226. int session_timeout, struct eapol_state_machine *eapol);
  227. int wpa_auth_pmksa_add_preauth(struct wpa_authenticator *wpa_auth,
  228. const u8 *pmk, size_t len, const u8 *sta_addr,
  229. int session_timeout,
  230. struct eapol_state_machine *eapol);
  231. int wpa_auth_sta_set_vlan(struct wpa_state_machine *sm, int vlan_id);
  232. #ifdef CONFIG_IEEE80211R
  233. u8 * wpa_sm_write_assoc_resp_ies(struct wpa_state_machine *sm, u8 *pos,
  234. size_t max_len, int auth_alg);
  235. void wpa_ft_process_auth(struct wpa_state_machine *sm, const u8 *bssid,
  236. u16 auth_transaction, const u8 *ies, size_t ies_len,
  237. void (*cb)(void *ctx, const u8 *dst, const u8 *bssid,
  238. u16 auth_transaction, u16 resp,
  239. const u8 *ies, size_t ies_len),
  240. void *ctx);
  241. u16 wpa_ft_validate_reassoc(struct wpa_state_machine *sm, const u8 *ies,
  242. size_t ies_len);
  243. int wpa_ft_action_rx(struct wpa_state_machine *sm, const u8 *data, size_t len);
  244. int wpa_ft_rrb_rx(struct wpa_authenticator *wpa_auth, const u8 *src_addr,
  245. const u8 *data, size_t data_len);
  246. void wpa_ft_push_pmk_r1(struct wpa_authenticator *wpa_auth, const u8 *addr);
  247. #endif /* CONFIG_IEEE80211R */
  248. #endif /* WPA_AUTH_H */