hostapd.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  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. #ifdef CONFIG_MESH
  23. struct mesh_conf;
  24. #endif /* CONFIG_MESH */
  25. struct hostapd_iface;
  26. struct hapd_interfaces {
  27. int (*reload_config)(struct hostapd_iface *iface);
  28. struct hostapd_config * (*config_read_cb)(const char *config_fname);
  29. int (*ctrl_iface_init)(struct hostapd_data *hapd);
  30. void (*ctrl_iface_deinit)(struct hostapd_data *hapd);
  31. int (*for_each_interface)(struct hapd_interfaces *interfaces,
  32. int (*cb)(struct hostapd_iface *iface,
  33. void *ctx), void *ctx);
  34. int (*driver_init)(struct hostapd_iface *iface);
  35. size_t count;
  36. int global_ctrl_sock;
  37. char *global_iface_path;
  38. char *global_iface_name;
  39. #ifndef CONFIG_NATIVE_WINDOWS
  40. gid_t ctrl_iface_group;
  41. #endif /* CONFIG_NATIVE_WINDOWS */
  42. struct hostapd_iface **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. /* channel switch parameters */
  172. struct hostapd_freq_params cs_freq_params;
  173. u8 cs_count;
  174. int cs_block_tx;
  175. unsigned int cs_c_off_beacon;
  176. unsigned int cs_c_off_proberesp;
  177. int csa_in_progress;
  178. /* BSS Load */
  179. unsigned int bss_load_update_timeout;
  180. #ifdef CONFIG_P2P
  181. struct p2p_data *p2p;
  182. struct p2p_group *p2p_group;
  183. struct wpabuf *p2p_beacon_ie;
  184. struct wpabuf *p2p_probe_resp_ie;
  185. /* Number of non-P2P association stations */
  186. int num_sta_no_p2p;
  187. /* Periodic NoA (used only when no non-P2P clients in the group) */
  188. int noa_enabled;
  189. int noa_start;
  190. int noa_duration;
  191. #endif /* CONFIG_P2P */
  192. #ifdef CONFIG_INTERWORKING
  193. size_t gas_frag_limit;
  194. #endif /* CONFIG_INTERWORKING */
  195. #ifdef CONFIG_SQLITE
  196. struct hostapd_eap_user tmp_eap_user;
  197. #endif /* CONFIG_SQLITE */
  198. #ifdef CONFIG_SAE
  199. /** Key used for generating SAE anti-clogging tokens */
  200. u8 sae_token_key[8];
  201. struct os_reltime last_sae_token_key_update;
  202. #endif /* CONFIG_SAE */
  203. #ifdef CONFIG_TESTING_OPTIONS
  204. unsigned int ext_mgmt_frame_handling:1;
  205. unsigned int ext_eapol_frame_io:1;
  206. struct l2_packet_data *l2_test;
  207. #endif /* CONFIG_TESTING_OPTIONS */
  208. };
  209. /**
  210. * struct hostapd_iface - hostapd per-interface data structure
  211. */
  212. struct hostapd_iface {
  213. struct hapd_interfaces *interfaces;
  214. void *owner;
  215. char *config_fname;
  216. struct hostapd_config *conf;
  217. char phy[16]; /* Name of the PHY (radio) */
  218. enum hostapd_iface_state {
  219. HAPD_IFACE_UNINITIALIZED,
  220. HAPD_IFACE_DISABLED,
  221. HAPD_IFACE_COUNTRY_UPDATE,
  222. HAPD_IFACE_ACS,
  223. HAPD_IFACE_HT_SCAN,
  224. HAPD_IFACE_DFS,
  225. HAPD_IFACE_ENABLED
  226. } state;
  227. #ifdef CONFIG_MESH
  228. struct mesh_conf *mconf;
  229. #endif /* CONFIG_MESH */
  230. size_t num_bss;
  231. struct hostapd_data **bss;
  232. unsigned int wait_channel_update:1;
  233. unsigned int cac_started:1;
  234. /*
  235. * When set, indicates that the driver will handle the AP
  236. * teardown: delete global keys, station keys, and stations.
  237. */
  238. unsigned int driver_ap_teardown:1;
  239. int num_ap; /* number of entries in ap_list */
  240. struct ap_info *ap_list; /* AP info list head */
  241. struct ap_info *ap_hash[STA_HASH_SIZE];
  242. unsigned int drv_flags;
  243. /* SMPS modes supported by the driver (WPA_DRIVER_SMPS_MODE_*) */
  244. unsigned int smps_modes;
  245. /*
  246. * A bitmap of supported protocols for probe response offload. See
  247. * struct wpa_driver_capa in driver.h
  248. */
  249. unsigned int probe_resp_offloads;
  250. /* extended capabilities supported by the driver */
  251. const u8 *extended_capa, *extended_capa_mask;
  252. unsigned int extended_capa_len;
  253. unsigned int drv_max_acl_mac_addrs;
  254. struct hostapd_hw_modes *hw_features;
  255. int num_hw_features;
  256. struct hostapd_hw_modes *current_mode;
  257. /* Rates that are currently used (i.e., filtered copy of
  258. * current_mode->channels */
  259. int num_rates;
  260. struct hostapd_rate_data *current_rates;
  261. int *basic_rates;
  262. int freq;
  263. u16 hw_flags;
  264. /* Number of associated Non-ERP stations (i.e., stations using 802.11b
  265. * in 802.11g BSS) */
  266. int num_sta_non_erp;
  267. /* Number of associated stations that do not support Short Slot Time */
  268. int num_sta_no_short_slot_time;
  269. /* Number of associated stations that do not support Short Preamble */
  270. int num_sta_no_short_preamble;
  271. int olbc; /* Overlapping Legacy BSS Condition */
  272. /* Number of HT associated stations that do not support greenfield */
  273. int num_sta_ht_no_gf;
  274. /* Number of associated non-HT stations */
  275. int num_sta_no_ht;
  276. /* Number of HT associated stations 20 MHz */
  277. int num_sta_ht_20mhz;
  278. /* Number of HT40 intolerant stations */
  279. int num_sta_ht40_intolerant;
  280. /* Overlapping BSS information */
  281. int olbc_ht;
  282. u16 ht_op_mode;
  283. /* surveying helpers */
  284. /* number of channels surveyed */
  285. unsigned int chans_surveyed;
  286. /* lowest observed noise floor in dBm */
  287. s8 lowest_nf;
  288. /* channel utilization calculation */
  289. u64 last_channel_time;
  290. u64 last_channel_time_busy;
  291. u8 channel_utilization;
  292. unsigned int dfs_cac_ms;
  293. struct os_reltime dfs_cac_start;
  294. /* Latched with the actual secondary channel information and will be
  295. * used while juggling between HT20 and HT40 modes. */
  296. int secondary_ch;
  297. #ifdef CONFIG_ACS
  298. unsigned int acs_num_completed_scans;
  299. #endif /* CONFIG_ACS */
  300. void (*scan_cb)(struct hostapd_iface *iface);
  301. int num_ht40_scan_tries;
  302. };
  303. /* hostapd.c */
  304. int hostapd_for_each_interface(struct hapd_interfaces *interfaces,
  305. int (*cb)(struct hostapd_iface *iface,
  306. void *ctx), void *ctx);
  307. int hostapd_reload_config(struct hostapd_iface *iface);
  308. struct hostapd_data *
  309. hostapd_alloc_bss_data(struct hostapd_iface *hapd_iface,
  310. struct hostapd_config *conf,
  311. struct hostapd_bss_config *bss);
  312. int hostapd_setup_interface(struct hostapd_iface *iface);
  313. int hostapd_setup_interface_complete(struct hostapd_iface *iface, int err);
  314. void hostapd_interface_deinit(struct hostapd_iface *iface);
  315. void hostapd_interface_free(struct hostapd_iface *iface);
  316. struct hostapd_iface * hostapd_init(struct hapd_interfaces *interfaces,
  317. const char *config_file);
  318. struct hostapd_iface *
  319. hostapd_interface_init_bss(struct hapd_interfaces *interfaces, const char *phy,
  320. const char *config_fname, int debug);
  321. void hostapd_new_assoc_sta(struct hostapd_data *hapd, struct sta_info *sta,
  322. int reassoc);
  323. void hostapd_interface_deinit_free(struct hostapd_iface *iface);
  324. int hostapd_enable_iface(struct hostapd_iface *hapd_iface);
  325. int hostapd_reload_iface(struct hostapd_iface *hapd_iface);
  326. int hostapd_disable_iface(struct hostapd_iface *hapd_iface);
  327. int hostapd_add_iface(struct hapd_interfaces *ifaces, char *buf);
  328. int hostapd_remove_iface(struct hapd_interfaces *ifaces, char *buf);
  329. void hostapd_channel_list_updated(struct hostapd_iface *iface, int initiator);
  330. void hostapd_set_state(struct hostapd_iface *iface, enum hostapd_iface_state s);
  331. const char * hostapd_state_text(enum hostapd_iface_state s);
  332. int hostapd_switch_channel(struct hostapd_data *hapd,
  333. struct csa_settings *settings);
  334. void
  335. hostapd_switch_channel_fallback(struct hostapd_iface *iface,
  336. const struct hostapd_freq_params *freq_params);
  337. void hostapd_cleanup_cs_params(struct hostapd_data *hapd);
  338. /* utils.c */
  339. int hostapd_register_probereq_cb(struct hostapd_data *hapd,
  340. int (*cb)(void *ctx, const u8 *sa,
  341. const u8 *da, const u8 *bssid,
  342. const u8 *ie, size_t ie_len,
  343. int ssi_signal),
  344. void *ctx);
  345. void hostapd_prune_associations(struct hostapd_data *hapd, const u8 *addr);
  346. /* drv_callbacks.c (TODO: move to somewhere else?) */
  347. int hostapd_notif_assoc(struct hostapd_data *hapd, const u8 *addr,
  348. const u8 *ie, size_t ielen, int reassoc);
  349. void hostapd_notif_disassoc(struct hostapd_data *hapd, const u8 *addr);
  350. void hostapd_event_sta_low_ack(struct hostapd_data *hapd, const u8 *addr);
  351. void hostapd_event_connect_failed_reason(struct hostapd_data *hapd,
  352. const u8 *addr, int reason_code);
  353. int hostapd_probe_req_rx(struct hostapd_data *hapd, const u8 *sa, const u8 *da,
  354. const u8 *bssid, const u8 *ie, size_t ie_len,
  355. int ssi_signal);
  356. void hostapd_event_ch_switch(struct hostapd_data *hapd, int freq, int ht,
  357. int offset, int width, int cf1, int cf2);
  358. const struct hostapd_eap_user *
  359. hostapd_get_eap_user(struct hostapd_data *hapd, const u8 *identity,
  360. size_t identity_len, int phase2);
  361. #endif /* HOSTAPD_H */