hostapd.h 7.8 KB

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