wpa.h 10 KB

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