hostapd.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. /*
  2. * hostapd / Initialization and configuration
  3. * Copyright (c) 2002-2009, 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 HOSTAPD_H
  15. #define HOSTAPD_H
  16. #include "common/defs.h"
  17. struct wpa_driver_ops;
  18. struct wpa_ctrl_dst;
  19. struct radius_server_data;
  20. struct upnp_wps_device_sm;
  21. struct hapd_interfaces;
  22. struct hostapd_data;
  23. struct sta_info;
  24. struct hostap_sta_driver_data;
  25. struct ieee80211_ht_capabilities;
  26. struct full_dynamic_vlan;
  27. enum wps_event;
  28. union wps_event_data;
  29. struct hostapd_probereq_cb {
  30. int (*cb)(void *ctx, const u8 *sa, const u8 *ie, size_t ie_len);
  31. void *ctx;
  32. };
  33. #define HOSTAPD_RATE_BASIC 0x00000001
  34. struct hostapd_rate_data {
  35. int rate; /* rate in 100 kbps */
  36. int flags; /* HOSTAPD_RATE_ flags */
  37. };
  38. struct hostapd_frame_info {
  39. u32 channel;
  40. u32 datarate;
  41. u32 ssi_signal;
  42. };
  43. struct hostapd_driver_ops {
  44. int (*set_ap_wps_ie)(struct hostapd_data *hapd);
  45. int (*send_eapol)(struct hostapd_data *hapd, const u8 *addr,
  46. const u8 *data, size_t data_len, int encrypt);
  47. int (*set_authorized)(struct hostapd_data *hapd, struct sta_info *sta,
  48. int authorized);
  49. int (*set_key)(const char *ifname, struct hostapd_data *hapd,
  50. enum wpa_alg alg, const u8 *addr, int key_idx,
  51. int set_tx, const u8 *seq, size_t seq_len,
  52. const u8 *key, size_t key_len);
  53. int (*read_sta_data)(struct hostapd_data *hapd,
  54. struct hostap_sta_driver_data *data,
  55. const u8 *addr);
  56. int (*sta_clear_stats)(struct hostapd_data *hapd, const u8 *addr);
  57. int (*set_sta_flags)(struct hostapd_data *hapd, struct sta_info *sta);
  58. int (*set_drv_ieee8021x)(struct hostapd_data *hapd, const char *ifname,
  59. int enabled);
  60. int (*set_radius_acl_auth)(struct hostapd_data *hapd,
  61. const u8 *mac, int accepted,
  62. u32 session_timeout);
  63. int (*set_radius_acl_expire)(struct hostapd_data *hapd,
  64. const u8 *mac);
  65. int (*set_bss_params)(struct hostapd_data *hapd, int use_protection);
  66. int (*set_beacon)(struct hostapd_data *hapd,
  67. const u8 *head, size_t head_len,
  68. const u8 *tail, size_t tail_len, int dtim_period,
  69. int beacon_int);
  70. int (*vlan_if_add)(struct hostapd_data *hapd, const char *ifname);
  71. int (*vlan_if_remove)(struct hostapd_data *hapd, const char *ifname);
  72. int (*set_wds_sta)(struct hostapd_data *hapd, const u8 *addr, int aid,
  73. int val);
  74. int (*set_sta_vlan)(const char *ifname, struct hostapd_data *hapd,
  75. const u8 *addr, int vlan_id);
  76. int (*get_inact_sec)(struct hostapd_data *hapd, const u8 *addr);
  77. int (*sta_deauth)(struct hostapd_data *hapd, const u8 *addr,
  78. int reason);
  79. int (*sta_disassoc)(struct hostapd_data *hapd, const u8 *addr,
  80. int reason);
  81. int (*sta_add)(struct hostapd_data *hapd,
  82. const u8 *addr, u16 aid, u16 capability,
  83. const u8 *supp_rates, size_t supp_rates_len,
  84. u16 listen_interval,
  85. const struct ieee80211_ht_capabilities *ht_capab);
  86. int (*sta_remove)(struct hostapd_data *hapd, const u8 *addr);
  87. int (*set_countermeasures)(struct hostapd_data *hapd, int enabled);
  88. };
  89. /**
  90. * struct hostapd_data - hostapd per-BSS data structure
  91. */
  92. struct hostapd_data {
  93. struct hostapd_iface *iface;
  94. struct hostapd_config *iconf;
  95. struct hostapd_bss_config *conf;
  96. int interface_added; /* virtual interface added for this BSS */
  97. u8 own_addr[ETH_ALEN];
  98. int num_sta; /* number of entries in sta_list */
  99. struct sta_info *sta_list; /* STA info list head */
  100. #define STA_HASH_SIZE 256
  101. #define STA_HASH(sta) (sta[5])
  102. struct sta_info *sta_hash[STA_HASH_SIZE];
  103. /*
  104. * Bitfield for indicating which AIDs are allocated. Only AID values
  105. * 1-2007 are used and as such, the bit at index 0 corresponds to AID
  106. * 1.
  107. */
  108. #define AID_WORDS ((2008 + 31) / 32)
  109. u32 sta_aid[AID_WORDS];
  110. const struct wpa_driver_ops *driver;
  111. void *drv_priv;
  112. struct hostapd_driver_ops drv;
  113. void (*new_assoc_sta_cb)(struct hostapd_data *hapd,
  114. struct sta_info *sta, int reassoc);
  115. void *msg_ctx; /* ctx for wpa_msg() calls */
  116. struct radius_client_data *radius;
  117. u32 acct_session_id_hi, acct_session_id_lo;
  118. struct iapp_data *iapp;
  119. struct hostapd_cached_radius_acl *acl_cache;
  120. struct hostapd_acl_query_data *acl_queries;
  121. struct wpa_authenticator *wpa_auth;
  122. struct eapol_authenticator *eapol_auth;
  123. struct rsn_preauth_interface *preauth_iface;
  124. time_t michael_mic_failure;
  125. int michael_mic_failures;
  126. int tkip_countermeasures;
  127. int ctrl_sock;
  128. struct wpa_ctrl_dst *ctrl_dst;
  129. void *ssl_ctx;
  130. void *eap_sim_db_priv;
  131. struct radius_server_data *radius_srv;
  132. int parameter_set_count;
  133. #ifdef CONFIG_FULL_DYNAMIC_VLAN
  134. struct full_dynamic_vlan *full_dynamic_vlan;
  135. #endif /* CONFIG_FULL_DYNAMIC_VLAN */
  136. struct l2_packet_data *l2;
  137. struct wps_context *wps;
  138. struct wpabuf *wps_beacon_ie;
  139. struct wpabuf *wps_probe_resp_ie;
  140. #ifdef CONFIG_WPS
  141. unsigned int ap_pin_failures;
  142. struct upnp_wps_device_sm *wps_upnp;
  143. unsigned int ap_pin_lockout_time;
  144. #endif /* CONFIG_WPS */
  145. struct hostapd_probereq_cb *probereq_cb;
  146. size_t num_probereq_cb;
  147. void (*public_action_cb)(void *ctx, const u8 *buf, size_t len,
  148. int freq);
  149. void *public_action_cb_ctx;
  150. int (*vendor_action_cb)(void *ctx, const u8 *buf, size_t len,
  151. int freq);
  152. void *vendor_action_cb_ctx;
  153. void (*wps_reg_success_cb)(void *ctx, const u8 *mac_addr,
  154. const u8 *uuid_e);
  155. void *wps_reg_success_cb_ctx;
  156. void (*wps_event_cb)(void *ctx, enum wps_event event,
  157. union wps_event_data *data);
  158. void *wps_event_cb_ctx;
  159. #ifdef CONFIG_P2P
  160. struct p2p_data *p2p;
  161. struct p2p_group *p2p_group;
  162. struct wpabuf *p2p_beacon_ie;
  163. struct wpabuf *p2p_probe_resp_ie;
  164. /* Number of non-P2P association stations */
  165. int num_sta_no_p2p;
  166. /* Periodic NoA (used only when no non-P2P clients in the group) */
  167. int noa_enabled;
  168. int noa_start;
  169. int noa_duration;
  170. #endif /* CONFIG_P2P */
  171. };
  172. /**
  173. * struct hostapd_iface - hostapd per-interface data structure
  174. */
  175. struct hostapd_iface {
  176. struct hapd_interfaces *interfaces;
  177. void *owner;
  178. int (*reload_config)(struct hostapd_iface *iface);
  179. struct hostapd_config * (*config_read_cb)(const char *config_fname);
  180. char *config_fname;
  181. struct hostapd_config *conf;
  182. size_t num_bss;
  183. struct hostapd_data **bss;
  184. int num_ap; /* number of entries in ap_list */
  185. struct ap_info *ap_list; /* AP info list head */
  186. struct ap_info *ap_hash[STA_HASH_SIZE];
  187. struct ap_info *ap_iter_list;
  188. struct hostapd_hw_modes *hw_features;
  189. int num_hw_features;
  190. struct hostapd_hw_modes *current_mode;
  191. /* Rates that are currently used (i.e., filtered copy of
  192. * current_mode->channels */
  193. int num_rates;
  194. struct hostapd_rate_data *current_rates;
  195. int freq;
  196. u16 hw_flags;
  197. /* Number of associated Non-ERP stations (i.e., stations using 802.11b
  198. * in 802.11g BSS) */
  199. int num_sta_non_erp;
  200. /* Number of associated stations that do not support Short Slot Time */
  201. int num_sta_no_short_slot_time;
  202. /* Number of associated stations that do not support Short Preamble */
  203. int num_sta_no_short_preamble;
  204. int olbc; /* Overlapping Legacy BSS Condition */
  205. /* Number of HT associated stations that do not support greenfield */
  206. int num_sta_ht_no_gf;
  207. /* Number of associated non-HT stations */
  208. int num_sta_no_ht;
  209. /* Number of HT associated stations 20 MHz */
  210. int num_sta_ht_20mhz;
  211. /* Overlapping BSS information */
  212. int olbc_ht;
  213. u16 ht_op_mode;
  214. void (*scan_cb)(struct hostapd_iface *iface);
  215. int (*ctrl_iface_init)(struct hostapd_data *hapd);
  216. void (*ctrl_iface_deinit)(struct hostapd_data *hapd);
  217. int (*for_each_interface)(struct hapd_interfaces *interfaces,
  218. int (*cb)(struct hostapd_iface *iface,
  219. void *ctx), void *ctx);
  220. };
  221. /* hostapd.c */
  222. int hostapd_reload_config(struct hostapd_iface *iface);
  223. struct hostapd_data *
  224. hostapd_alloc_bss_data(struct hostapd_iface *hapd_iface,
  225. struct hostapd_config *conf,
  226. struct hostapd_bss_config *bss);
  227. int hostapd_setup_interface(struct hostapd_iface *iface);
  228. int hostapd_setup_interface_complete(struct hostapd_iface *iface, int err);
  229. void hostapd_interface_deinit(struct hostapd_iface *iface);
  230. void hostapd_interface_free(struct hostapd_iface *iface);
  231. void hostapd_new_assoc_sta(struct hostapd_data *hapd, struct sta_info *sta,
  232. int reassoc);
  233. /* utils.c */
  234. int hostapd_register_probereq_cb(struct hostapd_data *hapd,
  235. int (*cb)(void *ctx, const u8 *sa,
  236. const u8 *ie, size_t ie_len),
  237. void *ctx);
  238. void hostapd_prune_associations(struct hostapd_data *hapd, const u8 *addr);
  239. /* drv_callbacks.c (TODO: move to somewhere else?) */
  240. int hostapd_notif_assoc(struct hostapd_data *hapd, const u8 *addr,
  241. const u8 *ie, size_t ielen);
  242. void hostapd_notif_disassoc(struct hostapd_data *hapd, const u8 *addr);
  243. #endif /* HOSTAPD_H */