wpa.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  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. };
  60. enum wpa_sm_conf_params {
  61. RSNA_PMK_LIFETIME /* dot11RSNAConfigPMKLifetime */,
  62. RSNA_PMK_REAUTH_THRESHOLD /* dot11RSNAConfigPMKReauthThreshold */,
  63. RSNA_SA_TIMEOUT /* dot11RSNAConfigSATimeout */,
  64. WPA_PARAM_PROTO,
  65. WPA_PARAM_PAIRWISE,
  66. WPA_PARAM_GROUP,
  67. WPA_PARAM_KEY_MGMT,
  68. WPA_PARAM_MGMT_GROUP,
  69. WPA_PARAM_RSN_ENABLED,
  70. WPA_PARAM_MFP
  71. };
  72. struct rsn_supp_config {
  73. void *network_ctx;
  74. int peerkey_enabled;
  75. int allowed_pairwise_cipher; /* bitfield of WPA_CIPHER_* */
  76. int proactive_key_caching;
  77. int eap_workaround;
  78. void *eap_conf_ctx;
  79. const u8 *ssid;
  80. size_t ssid_len;
  81. int wpa_ptk_rekey;
  82. };
  83. #ifndef CONFIG_NO_WPA
  84. struct wpa_sm * wpa_sm_init(struct wpa_sm_ctx *ctx);
  85. void wpa_sm_deinit(struct wpa_sm *sm);
  86. void wpa_sm_notify_assoc(struct wpa_sm *sm, const u8 *bssid);
  87. void wpa_sm_notify_disassoc(struct wpa_sm *sm);
  88. void wpa_sm_set_pmk(struct wpa_sm *sm, const u8 *pmk, size_t pmk_len);
  89. void wpa_sm_set_pmk_from_pmksa(struct wpa_sm *sm);
  90. void wpa_sm_set_fast_reauth(struct wpa_sm *sm, int fast_reauth);
  91. void wpa_sm_set_scard_ctx(struct wpa_sm *sm, void *scard_ctx);
  92. void wpa_sm_set_config(struct wpa_sm *sm, struct rsn_supp_config *config);
  93. void wpa_sm_set_own_addr(struct wpa_sm *sm, const u8 *addr);
  94. void wpa_sm_set_ifname(struct wpa_sm *sm, const char *ifname,
  95. const char *bridge_ifname);
  96. void wpa_sm_set_eapol(struct wpa_sm *sm, struct eapol_sm *eapol);
  97. int wpa_sm_set_assoc_wpa_ie(struct wpa_sm *sm, const u8 *ie, size_t len);
  98. int wpa_sm_set_assoc_wpa_ie_default(struct wpa_sm *sm, u8 *wpa_ie,
  99. size_t *wpa_ie_len);
  100. int wpa_sm_set_ap_wpa_ie(struct wpa_sm *sm, const u8 *ie, size_t len);
  101. int wpa_sm_set_ap_rsn_ie(struct wpa_sm *sm, const u8 *ie, size_t len);
  102. int wpa_sm_get_mib(struct wpa_sm *sm, char *buf, size_t buflen);
  103. int wpa_sm_set_param(struct wpa_sm *sm, enum wpa_sm_conf_params param,
  104. unsigned int value);
  105. unsigned int wpa_sm_get_param(struct wpa_sm *sm,
  106. enum wpa_sm_conf_params param);
  107. int wpa_sm_get_status(struct wpa_sm *sm, char *buf, size_t buflen,
  108. int verbose);
  109. void wpa_sm_key_request(struct wpa_sm *sm, int error, int pairwise);
  110. int wpa_parse_wpa_ie(const u8 *wpa_ie, size_t wpa_ie_len,
  111. struct wpa_ie_data *data);
  112. void wpa_sm_aborted_cached(struct wpa_sm *sm);
  113. int wpa_sm_rx_eapol(struct wpa_sm *sm, const u8 *src_addr,
  114. const u8 *buf, size_t len);
  115. int wpa_sm_parse_own_wpa_ie(struct wpa_sm *sm, struct wpa_ie_data *data);
  116. int wpa_sm_pmksa_cache_list(struct wpa_sm *sm, char *buf, size_t len);
  117. void wpa_sm_drop_sa(struct wpa_sm *sm);
  118. int wpa_sm_has_ptk(struct wpa_sm *sm);
  119. #else /* CONFIG_NO_WPA */
  120. static inline struct wpa_sm * wpa_sm_init(struct wpa_sm_ctx *ctx)
  121. {
  122. return (struct wpa_sm *) 1;
  123. }
  124. static inline void wpa_sm_deinit(struct wpa_sm *sm)
  125. {
  126. }
  127. static inline void wpa_sm_notify_assoc(struct wpa_sm *sm, const u8 *bssid)
  128. {
  129. }
  130. static inline void wpa_sm_notify_disassoc(struct wpa_sm *sm)
  131. {
  132. }
  133. static inline void wpa_sm_set_pmk(struct wpa_sm *sm, const u8 *pmk,
  134. size_t pmk_len)
  135. {
  136. }
  137. static inline void wpa_sm_set_pmk_from_pmksa(struct wpa_sm *sm)
  138. {
  139. }
  140. static inline void wpa_sm_set_fast_reauth(struct wpa_sm *sm, int fast_reauth)
  141. {
  142. }
  143. static inline void wpa_sm_set_scard_ctx(struct wpa_sm *sm, void *scard_ctx)
  144. {
  145. }
  146. static inline void wpa_sm_set_config(struct wpa_sm *sm,
  147. struct rsn_supp_config *config)
  148. {
  149. }
  150. static inline void wpa_sm_set_own_addr(struct wpa_sm *sm, const u8 *addr)
  151. {
  152. }
  153. static inline void wpa_sm_set_ifname(struct wpa_sm *sm, const char *ifname,
  154. const char *bridge_ifname)
  155. {
  156. }
  157. static inline void wpa_sm_set_eapol(struct wpa_sm *sm, struct eapol_sm *eapol)
  158. {
  159. }
  160. static inline int wpa_sm_set_assoc_wpa_ie(struct wpa_sm *sm, const u8 *ie,
  161. size_t len)
  162. {
  163. return -1;
  164. }
  165. static inline int wpa_sm_set_assoc_wpa_ie_default(struct wpa_sm *sm,
  166. u8 *wpa_ie,
  167. size_t *wpa_ie_len)
  168. {
  169. return -1;
  170. }
  171. static inline int wpa_sm_set_ap_wpa_ie(struct wpa_sm *sm, const u8 *ie,
  172. size_t len)
  173. {
  174. return -1;
  175. }
  176. static inline int wpa_sm_set_ap_rsn_ie(struct wpa_sm *sm, const u8 *ie,
  177. size_t len)
  178. {
  179. return -1;
  180. }
  181. static inline int wpa_sm_get_mib(struct wpa_sm *sm, char *buf, size_t buflen)
  182. {
  183. return 0;
  184. }
  185. static inline int wpa_sm_set_param(struct wpa_sm *sm,
  186. enum wpa_sm_conf_params param,
  187. unsigned int value)
  188. {
  189. return -1;
  190. }
  191. static inline unsigned int wpa_sm_get_param(struct wpa_sm *sm,
  192. enum wpa_sm_conf_params param)
  193. {
  194. return 0;
  195. }
  196. static inline int wpa_sm_get_status(struct wpa_sm *sm, char *buf,
  197. size_t buflen, int verbose)
  198. {
  199. return 0;
  200. }
  201. static inline void wpa_sm_key_request(struct wpa_sm *sm, int error,
  202. int pairwise)
  203. {
  204. }
  205. static inline int wpa_parse_wpa_ie(const u8 *wpa_ie, size_t wpa_ie_len,
  206. struct wpa_ie_data *data)
  207. {
  208. return -1;
  209. }
  210. static inline void wpa_sm_aborted_cached(struct wpa_sm *sm)
  211. {
  212. }
  213. static inline int wpa_sm_rx_eapol(struct wpa_sm *sm, const u8 *src_addr,
  214. const u8 *buf, size_t len)
  215. {
  216. return -1;
  217. }
  218. static inline int wpa_sm_parse_own_wpa_ie(struct wpa_sm *sm,
  219. struct wpa_ie_data *data)
  220. {
  221. return -1;
  222. }
  223. static inline int wpa_sm_pmksa_cache_list(struct wpa_sm *sm, char *buf,
  224. size_t len)
  225. {
  226. return -1;
  227. }
  228. static inline void wpa_sm_drop_sa(struct wpa_sm *sm)
  229. {
  230. }
  231. static inline int wpa_sm_has_ptk(struct wpa_sm *sm)
  232. {
  233. return 0;
  234. }
  235. #endif /* CONFIG_NO_WPA */
  236. #ifdef CONFIG_PEERKEY
  237. int wpa_sm_stkstart(struct wpa_sm *sm, const u8 *peer);
  238. #else /* CONFIG_PEERKEY */
  239. static inline int wpa_sm_stkstart(struct wpa_sm *sm, const u8 *peer)
  240. {
  241. return -1;
  242. }
  243. #endif /* CONFIG_PEERKEY */
  244. #ifdef CONFIG_IEEE80211R
  245. int wpa_sm_set_ft_params(struct wpa_sm *sm, const u8 *ies, size_t ies_len);
  246. int wpa_ft_prepare_auth_request(struct wpa_sm *sm, const u8 *mdie);
  247. int wpa_ft_process_response(struct wpa_sm *sm, const u8 *ies, size_t ies_len,
  248. int ft_action, const u8 *target_ap,
  249. const u8 *ric_ies, size_t ric_ies_len);
  250. int wpa_ft_is_completed(struct wpa_sm *sm);
  251. int wpa_ft_validate_reassoc_resp(struct wpa_sm *sm, const u8 *ies,
  252. size_t ies_len, const u8 *src_addr);
  253. int wpa_ft_start_over_ds(struct wpa_sm *sm, const u8 *target_ap,
  254. const u8 *mdie);
  255. #else /* CONFIG_IEEE80211R */
  256. static inline int
  257. wpa_sm_set_ft_params(struct wpa_sm *sm, const u8 *ies, size_t ies_len)
  258. {
  259. return 0;
  260. }
  261. static inline int wpa_ft_prepare_auth_request(struct wpa_sm *sm,
  262. const u8 *mdie)
  263. {
  264. return 0;
  265. }
  266. static inline int
  267. wpa_ft_process_response(struct wpa_sm *sm, const u8 *ies, size_t ies_len,
  268. int ft_action, const u8 *target_ap)
  269. {
  270. return 0;
  271. }
  272. static inline int wpa_ft_is_completed(struct wpa_sm *sm)
  273. {
  274. return 0;
  275. }
  276. static inline int
  277. wpa_ft_validate_reassoc_resp(struct wpa_sm *sm, const u8 *ies, size_t ies_len,
  278. const u8 *src_addr)
  279. {
  280. return -1;
  281. }
  282. #endif /* CONFIG_IEEE80211R */
  283. /* tdls.c */
  284. int wpa_tdls_start(struct wpa_sm *sm, const u8 *addr);
  285. int wpa_tdls_recv_teardown_notify(struct wpa_sm *sm, const u8 *addr,
  286. u16 reason_code);
  287. int wpa_tdls_init(struct wpa_sm *sm);
  288. void wpa_tdls_deinit(struct wpa_sm *sm);
  289. #endif /* WPA_H */