hostapd.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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. };
  88. /**
  89. * struct hostapd_data - hostapd per-BSS data structure
  90. */
  91. struct hostapd_data {
  92. struct hostapd_iface *iface;
  93. struct hostapd_config *iconf;
  94. struct hostapd_bss_config *conf;
  95. int interface_added; /* virtual interface added for this BSS */
  96. u8 own_addr[ETH_ALEN];
  97. int num_sta; /* number of entries in sta_list */
  98. struct sta_info *sta_list; /* STA info list head */
  99. #define STA_HASH_SIZE 256
  100. #define STA_HASH(sta) (sta[5])
  101. struct sta_info *sta_hash[STA_HASH_SIZE];
  102. /*
  103. * Bitfield for indicating which AIDs are allocated. Only AID values
  104. * 1-2007 are used and as such, the bit at index 0 corresponds to AID
  105. * 1.
  106. */
  107. #define AID_WORDS ((2008 + 31) / 32)
  108. u32 sta_aid[AID_WORDS];
  109. const struct wpa_driver_ops *driver;
  110. void *drv_priv;
  111. struct hostapd_driver_ops drv;
  112. void (*new_assoc_sta_cb)(struct hostapd_data *hapd,
  113. struct sta_info *sta, int reassoc);
  114. void *msg_ctx; /* ctx for wpa_msg() calls */
  115. struct radius_client_data *radius;
  116. u32 acct_session_id_hi, acct_session_id_lo;
  117. struct iapp_data *iapp;
  118. struct hostapd_cached_radius_acl *acl_cache;
  119. struct hostapd_acl_query_data *acl_queries;
  120. struct wpa_authenticator *wpa_auth;
  121. struct eapol_authenticator *eapol_auth;
  122. struct rsn_preauth_interface *preauth_iface;
  123. time_t michael_mic_failure;
  124. int michael_mic_failures;
  125. int tkip_countermeasures;
  126. int ctrl_sock;
  127. struct wpa_ctrl_dst *ctrl_dst;
  128. void *ssl_ctx;
  129. void *eap_sim_db_priv;
  130. struct radius_server_data *radius_srv;
  131. int parameter_set_count;
  132. #ifdef CONFIG_FULL_DYNAMIC_VLAN
  133. struct full_dynamic_vlan *full_dynamic_vlan;
  134. #endif /* CONFIG_FULL_DYNAMIC_VLAN */
  135. struct l2_packet_data *l2;
  136. struct wps_context *wps;
  137. struct wpabuf *wps_beacon_ie;
  138. struct wpabuf *wps_probe_resp_ie;
  139. #ifdef CONFIG_WPS
  140. unsigned int ap_pin_failures;
  141. struct upnp_wps_device_sm *wps_upnp;
  142. unsigned int ap_pin_lockout_time;
  143. #endif /* CONFIG_WPS */
  144. struct hostapd_probereq_cb *probereq_cb;
  145. size_t num_probereq_cb;
  146. void (*public_action_cb)(void *ctx, const u8 *buf, size_t len,
  147. int freq);
  148. void *public_action_cb_ctx;
  149. int (*vendor_action_cb)(void *ctx, const u8 *buf, size_t len,
  150. int freq);
  151. void *vendor_action_cb_ctx;
  152. void (*wps_reg_success_cb)(void *ctx, const u8 *mac_addr,
  153. const u8 *uuid_e);
  154. void *wps_reg_success_cb_ctx;
  155. void (*wps_event_cb)(void *ctx, enum wps_event event,
  156. union wps_event_data *data);
  157. void *wps_event_cb_ctx;
  158. #ifdef CONFIG_P2P
  159. struct p2p_data *p2p;
  160. struct p2p_group *p2p_group;
  161. struct wpabuf *p2p_beacon_ie;
  162. struct wpabuf *p2p_probe_resp_ie;
  163. /* Number of non-P2P association stations */
  164. int num_sta_no_p2p;
  165. /* Periodic NoA (used only when no non-P2P clients in the group) */
  166. int noa_enabled;
  167. int noa_start;
  168. int noa_duration;
  169. #endif /* CONFIG_P2P */
  170. };
  171. /**
  172. * struct hostapd_iface - hostapd per-interface data structure
  173. */
  174. struct hostapd_iface {
  175. struct hapd_interfaces *interfaces;
  176. void *owner;
  177. int (*reload_config)(struct hostapd_iface *iface);
  178. struct hostapd_config * (*config_read_cb)(const char *config_fname);
  179. char *config_fname;
  180. struct hostapd_config *conf;
  181. size_t num_bss;
  182. struct hostapd_data **bss;
  183. int num_ap; /* number of entries in ap_list */
  184. struct ap_info *ap_list; /* AP info list head */
  185. struct ap_info *ap_hash[STA_HASH_SIZE];
  186. struct ap_info *ap_iter_list;
  187. struct hostapd_hw_modes *hw_features;
  188. int num_hw_features;
  189. struct hostapd_hw_modes *current_mode;
  190. /* Rates that are currently used (i.e., filtered copy of
  191. * current_mode->channels */
  192. int num_rates;
  193. struct hostapd_rate_data *current_rates;
  194. int freq;
  195. u16 hw_flags;
  196. /* Number of associated Non-ERP stations (i.e., stations using 802.11b
  197. * in 802.11g BSS) */
  198. int num_sta_non_erp;
  199. /* Number of associated stations that do not support Short Slot Time */
  200. int num_sta_no_short_slot_time;
  201. /* Number of associated stations that do not support Short Preamble */
  202. int num_sta_no_short_preamble;
  203. int olbc; /* Overlapping Legacy BSS Condition */
  204. /* Number of HT associated stations that do not support greenfield */
  205. int num_sta_ht_no_gf;
  206. /* Number of associated non-HT stations */
  207. int num_sta_no_ht;
  208. /* Number of HT associated stations 20 MHz */
  209. int num_sta_ht_20mhz;
  210. /* Overlapping BSS information */
  211. int olbc_ht;
  212. u16 ht_op_mode;
  213. void (*scan_cb)(struct hostapd_iface *iface);
  214. int (*ctrl_iface_init)(struct hostapd_data *hapd);
  215. void (*ctrl_iface_deinit)(struct hostapd_data *hapd);
  216. int (*for_each_interface)(struct hapd_interfaces *interfaces,
  217. int (*cb)(struct hostapd_iface *iface,
  218. void *ctx), void *ctx);
  219. };
  220. /* hostapd.c */
  221. int hostapd_reload_config(struct hostapd_iface *iface);
  222. struct hostapd_data *
  223. hostapd_alloc_bss_data(struct hostapd_iface *hapd_iface,
  224. struct hostapd_config *conf,
  225. struct hostapd_bss_config *bss);
  226. int hostapd_setup_interface(struct hostapd_iface *iface);
  227. int hostapd_setup_interface_complete(struct hostapd_iface *iface, int err);
  228. void hostapd_interface_deinit(struct hostapd_iface *iface);
  229. void hostapd_interface_free(struct hostapd_iface *iface);
  230. void hostapd_new_assoc_sta(struct hostapd_data *hapd, struct sta_info *sta,
  231. int reassoc);
  232. /* utils.c */
  233. int hostapd_register_probereq_cb(struct hostapd_data *hapd,
  234. int (*cb)(void *ctx, const u8 *sa,
  235. const u8 *ie, size_t ie_len),
  236. void *ctx);
  237. void hostapd_prune_associations(struct hostapd_data *hapd, const u8 *addr);
  238. /* drv_callbacks.c (TODO: move to somewhere else?) */
  239. int hostapd_notif_assoc(struct hostapd_data *hapd, const u8 *addr,
  240. const u8 *ie, size_t ielen);
  241. void hostapd_notif_disassoc(struct hostapd_data *hapd, const u8 *addr);
  242. #endif /* HOSTAPD_H */