hostapd.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. /*
  2. * hostapd / Initialization and configuration
  3. * Copyright (c) 2002-2013, Jouni Malinen <j@w1.fi>
  4. *
  5. * This software may be distributed under the terms of the BSD license.
  6. * See README for more details.
  7. */
  8. #ifndef HOSTAPD_H
  9. #define HOSTAPD_H
  10. #include "common/defs.h"
  11. #include "ap_config.h"
  12. #include "drivers/driver.h"
  13. struct wpa_ctrl_dst;
  14. struct radius_server_data;
  15. struct upnp_wps_device_sm;
  16. struct hostapd_data;
  17. struct sta_info;
  18. struct ieee80211_ht_capabilities;
  19. struct full_dynamic_vlan;
  20. enum wps_event;
  21. union wps_event_data;
  22. struct hostapd_iface;
  23. struct hostapd_dynamic_iface;
  24. struct hapd_interfaces {
  25. int (*reload_config)(struct hostapd_iface *iface);
  26. struct hostapd_config * (*config_read_cb)(const char *config_fname);
  27. int (*ctrl_iface_init)(struct hostapd_data *hapd);
  28. void (*ctrl_iface_deinit)(struct hostapd_data *hapd);
  29. int (*for_each_interface)(struct hapd_interfaces *interfaces,
  30. int (*cb)(struct hostapd_iface *iface,
  31. void *ctx), void *ctx);
  32. int (*driver_init)(struct hostapd_iface *iface);
  33. size_t count;
  34. size_t count_dynamic;
  35. int global_ctrl_sock;
  36. char *global_iface_path;
  37. char *global_iface_name;
  38. #ifndef CONFIG_NATIVE_WINDOWS
  39. gid_t ctrl_iface_group;
  40. #endif /* CONFIG_NATIVE_WINDOWS */
  41. struct hostapd_iface **iface;
  42. struct hostapd_dynamic_iface **dynamic_iface;
  43. size_t terminate_on_error;
  44. };
  45. enum hostapd_chan_status {
  46. HOSTAPD_CHAN_VALID = 0, /* channel is ready */
  47. HOSTAPD_CHAN_INVALID = 1, /* no usable channel found */
  48. HOSTAPD_CHAN_ACS = 2, /* ACS work being performed */
  49. };
  50. struct hostapd_probereq_cb {
  51. int (*cb)(void *ctx, const u8 *sa, const u8 *da, const u8 *bssid,
  52. const u8 *ie, size_t ie_len, int ssi_signal);
  53. void *ctx;
  54. };
  55. #define HOSTAPD_RATE_BASIC 0x00000001
  56. struct hostapd_rate_data {
  57. int rate; /* rate in 100 kbps */
  58. int flags; /* HOSTAPD_RATE_ flags */
  59. };
  60. struct hostapd_frame_info {
  61. u32 channel;
  62. u32 datarate;
  63. int ssi_signal; /* dBm */
  64. };
  65. enum wps_status {
  66. WPS_STATUS_SUCCESS = 1,
  67. WPS_STATUS_FAILURE
  68. };
  69. enum pbc_status {
  70. WPS_PBC_STATUS_DISABLE,
  71. WPS_PBC_STATUS_ACTIVE,
  72. WPS_PBC_STATUS_TIMEOUT,
  73. WPS_PBC_STATUS_OVERLAP
  74. };
  75. struct wps_stat {
  76. enum wps_status status;
  77. enum wps_error_indication failure_reason;
  78. enum pbc_status pbc_status;
  79. u8 peer_addr[ETH_ALEN];
  80. };
  81. /**
  82. * struct hostapd_data - hostapd per-BSS data structure
  83. */
  84. struct hostapd_data {
  85. struct hostapd_iface *iface;
  86. struct hostapd_config *iconf;
  87. struct hostapd_bss_config *conf;
  88. int interface_added; /* virtual interface added for this BSS */
  89. unsigned int started:1;
  90. u8 own_addr[ETH_ALEN];
  91. int num_sta; /* number of entries in sta_list */
  92. struct sta_info *sta_list; /* STA info list head */
  93. #define STA_HASH_SIZE 256
  94. #define STA_HASH(sta) (sta[5])
  95. struct sta_info *sta_hash[STA_HASH_SIZE];
  96. /*
  97. * Bitfield for indicating which AIDs are allocated. Only AID values
  98. * 1-2007 are used and as such, the bit at index 0 corresponds to AID
  99. * 1.
  100. */
  101. #define AID_WORDS ((2008 + 31) / 32)
  102. u32 sta_aid[AID_WORDS];
  103. const struct wpa_driver_ops *driver;
  104. void *drv_priv;
  105. void (*new_assoc_sta_cb)(struct hostapd_data *hapd,
  106. struct sta_info *sta, int reassoc);
  107. void *msg_ctx; /* ctx for wpa_msg() calls */
  108. void *msg_ctx_parent; /* parent interface ctx for wpa_msg() calls */
  109. struct radius_client_data *radius;
  110. u32 acct_session_id_hi, acct_session_id_lo;
  111. struct radius_das_data *radius_das;
  112. struct iapp_data *iapp;
  113. struct hostapd_cached_radius_acl *acl_cache;
  114. struct hostapd_acl_query_data *acl_queries;
  115. struct wpa_authenticator *wpa_auth;
  116. struct eapol_authenticator *eapol_auth;
  117. struct rsn_preauth_interface *preauth_iface;
  118. struct os_reltime michael_mic_failure;
  119. int michael_mic_failures;
  120. int tkip_countermeasures;
  121. int ctrl_sock;
  122. struct wpa_ctrl_dst *ctrl_dst;
  123. void *ssl_ctx;
  124. void *eap_sim_db_priv;
  125. struct radius_server_data *radius_srv;
  126. int parameter_set_count;
  127. /* Time Advertisement */
  128. u8 time_update_counter;
  129. struct wpabuf *time_adv;
  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. int beacon_set_done;
  136. struct wpabuf *wps_beacon_ie;
  137. struct wpabuf *wps_probe_resp_ie;
  138. #ifdef CONFIG_WPS
  139. unsigned int ap_pin_failures;
  140. unsigned int ap_pin_failures_consecutive;
  141. struct upnp_wps_device_sm *wps_upnp;
  142. unsigned int ap_pin_lockout_time;
  143. struct wps_stat wps_stats;
  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. void (*public_action_cb2)(void *ctx, const u8 *buf, size_t len,
  151. int freq);
  152. void *public_action_cb2_ctx;
  153. int (*vendor_action_cb)(void *ctx, const u8 *buf, size_t len,
  154. int freq);
  155. void *vendor_action_cb_ctx;
  156. void (*wps_reg_success_cb)(void *ctx, const u8 *mac_addr,
  157. const u8 *uuid_e);
  158. void *wps_reg_success_cb_ctx;
  159. void (*wps_event_cb)(void *ctx, enum wps_event event,
  160. union wps_event_data *data);
  161. void *wps_event_cb_ctx;
  162. void (*sta_authorized_cb)(void *ctx, const u8 *mac_addr,
  163. int authorized, const u8 *p2p_dev_addr);
  164. void *sta_authorized_cb_ctx;
  165. void (*setup_complete_cb)(void *ctx);
  166. void *setup_complete_cb_ctx;
  167. void (*new_psk_cb)(void *ctx, const u8 *mac_addr,
  168. const u8 *p2p_dev_addr, const u8 *psk,
  169. size_t psk_len);
  170. void *new_psk_cb_ctx;
  171. #ifdef CONFIG_P2P
  172. struct p2p_data *p2p;
  173. struct p2p_group *p2p_group;
  174. struct wpabuf *p2p_beacon_ie;
  175. struct wpabuf *p2p_probe_resp_ie;
  176. /* Number of non-P2P association stations */
  177. int num_sta_no_p2p;
  178. /* Periodic NoA (used only when no non-P2P clients in the group) */
  179. int noa_enabled;
  180. int noa_start;
  181. int noa_duration;
  182. #endif /* CONFIG_P2P */
  183. #ifdef CONFIG_INTERWORKING
  184. size_t gas_frag_limit;
  185. #endif /* CONFIG_INTERWORKING */
  186. #ifdef CONFIG_SQLITE
  187. struct hostapd_eap_user tmp_eap_user;
  188. #endif /* CONFIG_SQLITE */
  189. #ifdef CONFIG_SAE
  190. /** Key used for generating SAE anti-clogging tokens */
  191. u8 sae_token_key[8];
  192. struct os_reltime last_sae_token_key_update;
  193. #endif /* CONFIG_SAE */
  194. };
  195. /**
  196. * struct hostapd_iface - hostapd per-interface data structure
  197. */
  198. struct hostapd_iface {
  199. struct hapd_interfaces *interfaces;
  200. void *owner;
  201. char *config_fname;
  202. struct hostapd_config *conf;
  203. char phy[16]; /* Name of the PHY (radio) */
  204. enum hostapd_iface_state {
  205. HAPD_IFACE_UNINITIALIZED,
  206. HAPD_IFACE_DISABLED,
  207. HAPD_IFACE_COUNTRY_UPDATE,
  208. HAPD_IFACE_ACS,
  209. HAPD_IFACE_HT_SCAN,
  210. HAPD_IFACE_DFS,
  211. HAPD_IFACE_ENABLED
  212. } state;
  213. size_t num_bss;
  214. struct hostapd_data **bss;
  215. unsigned int wait_channel_update:1;
  216. unsigned int cac_started:1;
  217. int num_ap; /* number of entries in ap_list */
  218. struct ap_info *ap_list; /* AP info list head */
  219. struct ap_info *ap_hash[STA_HASH_SIZE];
  220. unsigned int drv_flags;
  221. /*
  222. * A bitmap of supported protocols for probe response offload. See
  223. * struct wpa_driver_capa in driver.h
  224. */
  225. unsigned int probe_resp_offloads;
  226. /* extended capabilities supported by the driver */
  227. const u8 *extended_capa, *extended_capa_mask;
  228. unsigned int extended_capa_len;
  229. unsigned int drv_max_acl_mac_addrs;
  230. struct hostapd_hw_modes *hw_features;
  231. int num_hw_features;
  232. struct hostapd_hw_modes *current_mode;
  233. /* Rates that are currently used (i.e., filtered copy of
  234. * current_mode->channels */
  235. int num_rates;
  236. struct hostapd_rate_data *current_rates;
  237. int *basic_rates;
  238. int freq;
  239. u16 hw_flags;
  240. /* Number of associated Non-ERP stations (i.e., stations using 802.11b
  241. * in 802.11g BSS) */
  242. int num_sta_non_erp;
  243. /* Number of associated stations that do not support Short Slot Time */
  244. int num_sta_no_short_slot_time;
  245. /* Number of associated stations that do not support Short Preamble */
  246. int num_sta_no_short_preamble;
  247. int olbc; /* Overlapping Legacy BSS Condition */
  248. /* Number of HT associated stations that do not support greenfield */
  249. int num_sta_ht_no_gf;
  250. /* Number of associated non-HT stations */
  251. int num_sta_no_ht;
  252. /* Number of HT associated stations 20 MHz */
  253. int num_sta_ht_20mhz;
  254. /* Overlapping BSS information */
  255. int olbc_ht;
  256. u16 ht_op_mode;
  257. /* surveying helpers */
  258. /* number of channels surveyed */
  259. unsigned int chans_surveyed;
  260. /* lowest observed noise floor in dBm */
  261. s8 lowest_nf;
  262. /* channel switch parameters */
  263. int cs_freq;
  264. u8 cs_count;
  265. int cs_block_tx;
  266. unsigned int cs_c_off_beacon;
  267. unsigned int cs_c_off_proberesp;
  268. int csa_in_progress;
  269. #ifdef CONFIG_ACS
  270. unsigned int acs_num_completed_scans;
  271. #endif /* CONFIG_ACS */
  272. void (*scan_cb)(struct hostapd_iface *iface);
  273. };
  274. /**
  275. * struct hostapd_dynamic_iface - hostapd per dynamically allocated
  276. * or added interface data structure
  277. */
  278. struct hostapd_dynamic_iface {
  279. char parent[IFNAMSIZ + 1];
  280. char iface[IFNAMSIZ + 1];
  281. unsigned int usage;
  282. };
  283. /* hostapd.c */
  284. int hostapd_for_each_interface(struct hapd_interfaces *interfaces,
  285. int (*cb)(struct hostapd_iface *iface,
  286. void *ctx), void *ctx);
  287. int hostapd_reload_config(struct hostapd_iface *iface);
  288. struct hostapd_data *
  289. hostapd_alloc_bss_data(struct hostapd_iface *hapd_iface,
  290. struct hostapd_config *conf,
  291. struct hostapd_bss_config *bss);
  292. int hostapd_setup_interface(struct hostapd_iface *iface);
  293. int hostapd_setup_interface_complete(struct hostapd_iface *iface, int err);
  294. void hostapd_interface_deinit(struct hostapd_iface *iface);
  295. void hostapd_interface_free(struct hostapd_iface *iface);
  296. struct hostapd_iface * hostapd_init(struct hapd_interfaces *interfaces,
  297. const char *config_file);
  298. struct hostapd_iface *
  299. hostapd_interface_init_bss(struct hapd_interfaces *interfaces, const char *phy,
  300. const char *config_fname, int debug);
  301. void hostapd_new_assoc_sta(struct hostapd_data *hapd, struct sta_info *sta,
  302. int reassoc);
  303. void hostapd_interface_deinit_free(struct hostapd_iface *iface);
  304. int hostapd_enable_iface(struct hostapd_iface *hapd_iface);
  305. int hostapd_reload_iface(struct hostapd_iface *hapd_iface);
  306. int hostapd_disable_iface(struct hostapd_iface *hapd_iface);
  307. int hostapd_add_iface(struct hapd_interfaces *ifaces, char *buf);
  308. int hostapd_remove_iface(struct hapd_interfaces *ifaces, char *buf);
  309. void hostapd_channel_list_updated(struct hostapd_iface *iface, int initiator);
  310. void hostapd_set_state(struct hostapd_iface *iface, enum hostapd_iface_state s);
  311. const char * hostapd_state_text(enum hostapd_iface_state s);
  312. int hostapd_switch_channel(struct hostapd_data *hapd,
  313. struct csa_settings *settings);
  314. void hostapd_cleanup_cs_params(struct hostapd_data *hapd);
  315. /* utils.c */
  316. int hostapd_register_probereq_cb(struct hostapd_data *hapd,
  317. int (*cb)(void *ctx, const u8 *sa,
  318. const u8 *da, const u8 *bssid,
  319. const u8 *ie, size_t ie_len,
  320. int ssi_signal),
  321. void *ctx);
  322. void hostapd_prune_associations(struct hostapd_data *hapd, const u8 *addr);
  323. /* drv_callbacks.c (TODO: move to somewhere else?) */
  324. int hostapd_notif_assoc(struct hostapd_data *hapd, const u8 *addr,
  325. const u8 *ie, size_t ielen, int reassoc);
  326. void hostapd_notif_disassoc(struct hostapd_data *hapd, const u8 *addr);
  327. void hostapd_event_sta_low_ack(struct hostapd_data *hapd, const u8 *addr);
  328. void hostapd_event_connect_failed_reason(struct hostapd_data *hapd,
  329. const u8 *addr, int reason_code);
  330. int hostapd_probe_req_rx(struct hostapd_data *hapd, const u8 *sa, const u8 *da,
  331. const u8 *bssid, const u8 *ie, size_t ie_len,
  332. int ssi_signal);
  333. void hostapd_event_ch_switch(struct hostapd_data *hapd, int freq, int ht,
  334. int offset, int width, int cf1, int cf2);
  335. const struct hostapd_eap_user *
  336. hostapd_get_eap_user(struct hostapd_data *hapd, const u8 *identity,
  337. size_t identity_len, int phase2);
  338. #endif /* HOSTAPD_H */