wpa.h 9.7 KB

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