wpa.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. /*
  2. * wpa_supplicant - WPA definitions
  3. * Copyright (c) 2003-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_H
  9. #define WPA_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. struct wpa_sm;
  15. struct eapol_sm;
  16. struct wpa_config_blob;
  17. struct hostapd_freq_params;
  18. struct wpa_sm_ctx {
  19. void *ctx; /* pointer to arbitrary upper level context */
  20. void *msg_ctx; /* upper level context for wpa_msg() calls */
  21. void (*set_state)(void *ctx, enum wpa_states state);
  22. enum wpa_states (*get_state)(void *ctx);
  23. void (*deauthenticate)(void * ctx, int reason_code);
  24. int (*set_key)(void *ctx, enum wpa_alg alg,
  25. const u8 *addr, int key_idx, int set_tx,
  26. const u8 *seq, size_t seq_len,
  27. const u8 *key, size_t key_len);
  28. void * (*get_network_ctx)(void *ctx);
  29. int (*get_bssid)(void *ctx, u8 *bssid);
  30. int (*ether_send)(void *ctx, const u8 *dest, u16 proto, const u8 *buf,
  31. size_t len);
  32. int (*get_beacon_ie)(void *ctx);
  33. void (*cancel_auth_timeout)(void *ctx);
  34. u8 * (*alloc_eapol)(void *ctx, u8 type, const void *data, u16 data_len,
  35. size_t *msg_len, void **data_pos);
  36. int (*add_pmkid)(void *ctx, const u8 *bssid, const u8 *pmkid);
  37. int (*remove_pmkid)(void *ctx, const u8 *bssid, const u8 *pmkid);
  38. void (*set_config_blob)(void *ctx, struct wpa_config_blob *blob);
  39. const struct wpa_config_blob * (*get_config_blob)(void *ctx,
  40. const char *name);
  41. int (*mlme_setprotection)(void *ctx, const u8 *addr,
  42. int protection_type, int key_type);
  43. int (*update_ft_ies)(void *ctx, const u8 *md, const u8 *ies,
  44. size_t ies_len);
  45. int (*send_ft_action)(void *ctx, u8 action, const u8 *target_ap,
  46. const u8 *ies, size_t ies_len);
  47. int (*mark_authenticated)(void *ctx, const u8 *target_ap);
  48. #ifdef CONFIG_TDLS
  49. int (*tdls_get_capa)(void *ctx, int *tdls_supported,
  50. int *tdls_ext_setup, int *tdls_chan_switch);
  51. int (*send_tdls_mgmt)(void *ctx, const u8 *dst,
  52. u8 action_code, u8 dialog_token,
  53. u16 status_code, u32 peer_capab,
  54. int initiator, const u8 *buf, size_t len);
  55. int (*tdls_oper)(void *ctx, int oper, const u8 *peer);
  56. int (*tdls_peer_addset)(void *ctx, const u8 *addr, int add, u16 aid,
  57. u16 capability, const u8 *supp_rates,
  58. size_t supp_rates_len,
  59. const struct ieee80211_ht_capabilities *ht_capab,
  60. const struct ieee80211_vht_capabilities *vht_capab,
  61. u8 qosinfo, int wmm, const u8 *ext_capab,
  62. size_t ext_capab_len, const u8 *supp_channels,
  63. size_t supp_channels_len,
  64. const u8 *supp_oper_classes,
  65. size_t supp_oper_classes_len);
  66. int (*tdls_enable_channel_switch)(
  67. void *ctx, const u8 *addr, u8 oper_class,
  68. const struct hostapd_freq_params *params);
  69. int (*tdls_disable_channel_switch)(void *ctx, const u8 *addr);
  70. #endif /* CONFIG_TDLS */
  71. void (*set_rekey_offload)(void *ctx, const u8 *kek, size_t kek_len,
  72. const u8 *kck, size_t kck_len,
  73. const u8 *replay_ctr);
  74. int (*key_mgmt_set_pmk)(void *ctx, const u8 *pmk, size_t pmk_len);
  75. };
  76. enum wpa_sm_conf_params {
  77. RSNA_PMK_LIFETIME /* dot11RSNAConfigPMKLifetime */,
  78. RSNA_PMK_REAUTH_THRESHOLD /* dot11RSNAConfigPMKReauthThreshold */,
  79. RSNA_SA_TIMEOUT /* dot11RSNAConfigSATimeout */,
  80. WPA_PARAM_PROTO,
  81. WPA_PARAM_PAIRWISE,
  82. WPA_PARAM_GROUP,
  83. WPA_PARAM_KEY_MGMT,
  84. WPA_PARAM_MGMT_GROUP,
  85. WPA_PARAM_RSN_ENABLED,
  86. WPA_PARAM_MFP
  87. };
  88. struct rsn_supp_config {
  89. void *network_ctx;
  90. int peerkey_enabled;
  91. int allowed_pairwise_cipher; /* bitfield of WPA_CIPHER_* */
  92. int proactive_key_caching;
  93. int eap_workaround;
  94. void *eap_conf_ctx;
  95. const u8 *ssid;
  96. size_t ssid_len;
  97. int wpa_ptk_rekey;
  98. int p2p;
  99. int wpa_rsc_relaxation;
  100. };
  101. #ifndef CONFIG_NO_WPA
  102. struct wpa_sm * wpa_sm_init(struct wpa_sm_ctx *ctx);
  103. void wpa_sm_deinit(struct wpa_sm *sm);
  104. void wpa_sm_notify_assoc(struct wpa_sm *sm, const u8 *bssid);
  105. void wpa_sm_notify_disassoc(struct wpa_sm *sm);
  106. void wpa_sm_set_pmk(struct wpa_sm *sm, const u8 *pmk, size_t pmk_len,
  107. const u8 *pmkid, const u8 *bssid);
  108. void wpa_sm_set_pmk_from_pmksa(struct wpa_sm *sm);
  109. void wpa_sm_set_fast_reauth(struct wpa_sm *sm, int fast_reauth);
  110. void wpa_sm_set_scard_ctx(struct wpa_sm *sm, void *scard_ctx);
  111. void wpa_sm_set_config(struct wpa_sm *sm, struct rsn_supp_config *config);
  112. void wpa_sm_set_own_addr(struct wpa_sm *sm, const u8 *addr);
  113. void wpa_sm_set_ifname(struct wpa_sm *sm, const char *ifname,
  114. const char *bridge_ifname);
  115. void wpa_sm_set_eapol(struct wpa_sm *sm, struct eapol_sm *eapol);
  116. int wpa_sm_set_assoc_wpa_ie(struct wpa_sm *sm, const u8 *ie, size_t len);
  117. int wpa_sm_set_assoc_wpa_ie_default(struct wpa_sm *sm, u8 *wpa_ie,
  118. size_t *wpa_ie_len);
  119. int wpa_sm_set_ap_wpa_ie(struct wpa_sm *sm, const u8 *ie, size_t len);
  120. int wpa_sm_set_ap_rsn_ie(struct wpa_sm *sm, const u8 *ie, size_t len);
  121. int wpa_sm_get_mib(struct wpa_sm *sm, char *buf, size_t buflen);
  122. int wpa_sm_set_param(struct wpa_sm *sm, enum wpa_sm_conf_params param,
  123. unsigned int value);
  124. int wpa_sm_get_status(struct wpa_sm *sm, char *buf, size_t buflen,
  125. int verbose);
  126. int wpa_sm_pmf_enabled(struct wpa_sm *sm);
  127. void wpa_sm_key_request(struct wpa_sm *sm, int error, int pairwise);
  128. int wpa_parse_wpa_ie(const u8 *wpa_ie, size_t wpa_ie_len,
  129. struct wpa_ie_data *data);
  130. void wpa_sm_aborted_cached(struct wpa_sm *sm);
  131. int wpa_sm_rx_eapol(struct wpa_sm *sm, const u8 *src_addr,
  132. const u8 *buf, size_t len);
  133. int wpa_sm_parse_own_wpa_ie(struct wpa_sm *sm, struct wpa_ie_data *data);
  134. int wpa_sm_pmksa_cache_list(struct wpa_sm *sm, char *buf, size_t len);
  135. void wpa_sm_drop_sa(struct wpa_sm *sm);
  136. int wpa_sm_has_ptk(struct wpa_sm *sm);
  137. void wpa_sm_update_replay_ctr(struct wpa_sm *sm, const u8 *replay_ctr);
  138. void wpa_sm_pmksa_cache_flush(struct wpa_sm *sm, void *network_ctx);
  139. int wpa_sm_get_p2p_ip_addr(struct wpa_sm *sm, u8 *buf);
  140. void wpa_sm_set_rx_replay_ctr(struct wpa_sm *sm, const u8 *rx_replay_counter);
  141. void wpa_sm_set_ptk_kck_kek(struct wpa_sm *sm,
  142. const u8 *ptk_kck, size_t ptk_kck_len,
  143. const u8 *ptk_kek, size_t ptk_kek_len);
  144. #else /* CONFIG_NO_WPA */
  145. static inline struct wpa_sm * wpa_sm_init(struct wpa_sm_ctx *ctx)
  146. {
  147. return (struct wpa_sm *) 1;
  148. }
  149. static inline void wpa_sm_deinit(struct wpa_sm *sm)
  150. {
  151. }
  152. static inline void wpa_sm_notify_assoc(struct wpa_sm *sm, const u8 *bssid)
  153. {
  154. }
  155. static inline void wpa_sm_notify_disassoc(struct wpa_sm *sm)
  156. {
  157. }
  158. static inline void wpa_sm_set_pmk(struct wpa_sm *sm, const u8 *pmk,
  159. size_t pmk_len, const u8 *pmkid,
  160. const u8 *bssid)
  161. {
  162. }
  163. static inline void wpa_sm_set_pmk_from_pmksa(struct wpa_sm *sm)
  164. {
  165. }
  166. static inline void wpa_sm_set_fast_reauth(struct wpa_sm *sm, int fast_reauth)
  167. {
  168. }
  169. static inline void wpa_sm_set_scard_ctx(struct wpa_sm *sm, void *scard_ctx)
  170. {
  171. }
  172. static inline void wpa_sm_set_config(struct wpa_sm *sm,
  173. struct rsn_supp_config *config)
  174. {
  175. }
  176. static inline void wpa_sm_set_own_addr(struct wpa_sm *sm, const u8 *addr)
  177. {
  178. }
  179. static inline void wpa_sm_set_ifname(struct wpa_sm *sm, const char *ifname,
  180. const char *bridge_ifname)
  181. {
  182. }
  183. static inline void wpa_sm_set_eapol(struct wpa_sm *sm, struct eapol_sm *eapol)
  184. {
  185. }
  186. static inline int wpa_sm_set_assoc_wpa_ie(struct wpa_sm *sm, const u8 *ie,
  187. size_t len)
  188. {
  189. return -1;
  190. }
  191. static inline int wpa_sm_set_assoc_wpa_ie_default(struct wpa_sm *sm,
  192. u8 *wpa_ie,
  193. size_t *wpa_ie_len)
  194. {
  195. return -1;
  196. }
  197. static inline int wpa_sm_set_ap_wpa_ie(struct wpa_sm *sm, const u8 *ie,
  198. size_t len)
  199. {
  200. return -1;
  201. }
  202. static inline int wpa_sm_set_ap_rsn_ie(struct wpa_sm *sm, const u8 *ie,
  203. size_t len)
  204. {
  205. return -1;
  206. }
  207. static inline int wpa_sm_get_mib(struct wpa_sm *sm, char *buf, size_t buflen)
  208. {
  209. return 0;
  210. }
  211. static inline int wpa_sm_set_param(struct wpa_sm *sm,
  212. enum wpa_sm_conf_params param,
  213. unsigned int value)
  214. {
  215. return -1;
  216. }
  217. static inline int wpa_sm_get_status(struct wpa_sm *sm, char *buf,
  218. size_t buflen, int verbose)
  219. {
  220. return 0;
  221. }
  222. static inline int wpa_sm_pmf_enabled(struct wpa_sm *sm)
  223. {
  224. return 0;
  225. }
  226. static inline void wpa_sm_key_request(struct wpa_sm *sm, int error,
  227. int pairwise)
  228. {
  229. }
  230. static inline int wpa_parse_wpa_ie(const u8 *wpa_ie, size_t wpa_ie_len,
  231. struct wpa_ie_data *data)
  232. {
  233. return -1;
  234. }
  235. static inline void wpa_sm_aborted_cached(struct wpa_sm *sm)
  236. {
  237. }
  238. static inline int wpa_sm_rx_eapol(struct wpa_sm *sm, const u8 *src_addr,
  239. const u8 *buf, size_t len)
  240. {
  241. return -1;
  242. }
  243. static inline int wpa_sm_parse_own_wpa_ie(struct wpa_sm *sm,
  244. struct wpa_ie_data *data)
  245. {
  246. return -1;
  247. }
  248. static inline int wpa_sm_pmksa_cache_list(struct wpa_sm *sm, char *buf,
  249. size_t len)
  250. {
  251. return -1;
  252. }
  253. static inline void wpa_sm_drop_sa(struct wpa_sm *sm)
  254. {
  255. }
  256. static inline int wpa_sm_has_ptk(struct wpa_sm *sm)
  257. {
  258. return 0;
  259. }
  260. static inline void wpa_sm_update_replay_ctr(struct wpa_sm *sm,
  261. const u8 *replay_ctr)
  262. {
  263. }
  264. static inline void wpa_sm_pmksa_cache_flush(struct wpa_sm *sm,
  265. void *network_ctx)
  266. {
  267. }
  268. static inline void wpa_sm_set_rx_replay_ctr(struct wpa_sm *sm,
  269. const u8 *rx_replay_counter)
  270. {
  271. }
  272. static inline void wpa_sm_set_ptk_kck_kek(struct wpa_sm *sm, const u8 *ptk_kck,
  273. size_t ptk_kck_len,
  274. const u8 *ptk_kek, size_t ptk_kek_len)
  275. {
  276. }
  277. #endif /* CONFIG_NO_WPA */
  278. #ifdef CONFIG_PEERKEY
  279. int wpa_sm_stkstart(struct wpa_sm *sm, const u8 *peer);
  280. int wpa_sm_rx_eapol_peerkey(struct wpa_sm *sm, const u8 *src_addr,
  281. const u8 *buf, size_t len);
  282. #else /* CONFIG_PEERKEY */
  283. static inline int wpa_sm_stkstart(struct wpa_sm *sm, const u8 *peer)
  284. {
  285. return -1;
  286. }
  287. static inline int wpa_sm_rx_eapol_peerkey(struct wpa_sm *sm, const u8 *src_addr,
  288. const u8 *buf, size_t len)
  289. {
  290. return 0;
  291. }
  292. #endif /* CONFIG_PEERKEY */
  293. #ifdef CONFIG_IEEE80211R
  294. int wpa_sm_set_ft_params(struct wpa_sm *sm, const u8 *ies, size_t ies_len);
  295. int wpa_ft_prepare_auth_request(struct wpa_sm *sm, const u8 *mdie);
  296. int wpa_ft_process_response(struct wpa_sm *sm, const u8 *ies, size_t ies_len,
  297. int ft_action, const u8 *target_ap,
  298. const u8 *ric_ies, size_t ric_ies_len);
  299. int wpa_ft_is_completed(struct wpa_sm *sm);
  300. void wpa_reset_ft_completed(struct wpa_sm *sm);
  301. int wpa_ft_validate_reassoc_resp(struct wpa_sm *sm, const u8 *ies,
  302. size_t ies_len, const u8 *src_addr);
  303. int wpa_ft_start_over_ds(struct wpa_sm *sm, const u8 *target_ap,
  304. const u8 *mdie);
  305. #else /* CONFIG_IEEE80211R */
  306. static inline int
  307. wpa_sm_set_ft_params(struct wpa_sm *sm, const u8 *ies, size_t ies_len)
  308. {
  309. return 0;
  310. }
  311. static inline int wpa_ft_prepare_auth_request(struct wpa_sm *sm,
  312. const u8 *mdie)
  313. {
  314. return 0;
  315. }
  316. static inline int
  317. wpa_ft_process_response(struct wpa_sm *sm, const u8 *ies, size_t ies_len,
  318. int ft_action, const u8 *target_ap)
  319. {
  320. return 0;
  321. }
  322. static inline int wpa_ft_is_completed(struct wpa_sm *sm)
  323. {
  324. return 0;
  325. }
  326. static inline void wpa_reset_ft_completed(struct wpa_sm *sm)
  327. {
  328. }
  329. static inline int
  330. wpa_ft_validate_reassoc_resp(struct wpa_sm *sm, const u8 *ies, size_t ies_len,
  331. const u8 *src_addr)
  332. {
  333. return -1;
  334. }
  335. #endif /* CONFIG_IEEE80211R */
  336. /* tdls.c */
  337. void wpa_tdls_ap_ies(struct wpa_sm *sm, const u8 *ies, size_t len);
  338. void wpa_tdls_assoc_resp_ies(struct wpa_sm *sm, const u8 *ies, size_t len);
  339. int wpa_tdls_start(struct wpa_sm *sm, const u8 *addr);
  340. void wpa_tdls_remove(struct wpa_sm *sm, const u8 *addr);
  341. int wpa_tdls_teardown_link(struct wpa_sm *sm, const u8 *addr, u16 reason_code);
  342. int wpa_tdls_send_discovery_request(struct wpa_sm *sm, const u8 *addr);
  343. int wpa_tdls_init(struct wpa_sm *sm);
  344. void wpa_tdls_teardown_peers(struct wpa_sm *sm);
  345. void wpa_tdls_deinit(struct wpa_sm *sm);
  346. void wpa_tdls_enable(struct wpa_sm *sm, int enabled);
  347. void wpa_tdls_disable_unreachable_link(struct wpa_sm *sm, const u8 *addr);
  348. const char * wpa_tdls_get_link_status(struct wpa_sm *sm, const u8 *addr);
  349. int wpa_tdls_is_external_setup(struct wpa_sm *sm);
  350. int wpa_tdls_enable_chan_switch(struct wpa_sm *sm, const u8 *addr,
  351. u8 oper_class,
  352. struct hostapd_freq_params *freq_params);
  353. int wpa_tdls_disable_chan_switch(struct wpa_sm *sm, const u8 *addr);
  354. int wpa_wnmsleep_install_key(struct wpa_sm *sm, u8 subelem_id, u8 *buf);
  355. void wpa_sm_set_test_assoc_ie(struct wpa_sm *sm, struct wpabuf *buf);
  356. #endif /* WPA_H */