hostapd.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  1. /*
  2. * hostapd / Initialization and configuration
  3. * Copyright (c) 2002-2014, 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 "utils/list.h"
  12. #include "ap_config.h"
  13. #include "drivers/driver.h"
  14. struct wpa_ctrl_dst;
  15. struct radius_server_data;
  16. struct upnp_wps_device_sm;
  17. struct hostapd_data;
  18. struct sta_info;
  19. struct ieee80211_ht_capabilities;
  20. struct full_dynamic_vlan;
  21. enum wps_event;
  22. union wps_event_data;
  23. #ifdef CONFIG_MESH
  24. struct mesh_conf;
  25. #endif /* CONFIG_MESH */
  26. struct hostapd_iface;
  27. struct hapd_interfaces {
  28. int (*reload_config)(struct hostapd_iface *iface);
  29. struct hostapd_config * (*config_read_cb)(const char *config_fname);
  30. int (*ctrl_iface_init)(struct hostapd_data *hapd);
  31. void (*ctrl_iface_deinit)(struct hostapd_data *hapd);
  32. int (*for_each_interface)(struct hapd_interfaces *interfaces,
  33. int (*cb)(struct hostapd_iface *iface,
  34. void *ctx), void *ctx);
  35. int (*driver_init)(struct hostapd_iface *iface);
  36. size_t count;
  37. int global_ctrl_sock;
  38. struct dl_list global_ctrl_dst;
  39. char *global_iface_path;
  40. char *global_iface_name;
  41. #ifndef CONFIG_NATIVE_WINDOWS
  42. gid_t ctrl_iface_group;
  43. #endif /* CONFIG_NATIVE_WINDOWS */
  44. struct hostapd_iface **iface;
  45. size_t terminate_on_error;
  46. #ifndef CONFIG_NO_VLAN
  47. struct dynamic_iface *vlan_priv;
  48. #endif /* CONFIG_NO_VLAN */
  49. int eloop_initialized;
  50. };
  51. enum hostapd_chan_status {
  52. HOSTAPD_CHAN_VALID = 0, /* channel is ready */
  53. HOSTAPD_CHAN_INVALID = 1, /* no usable channel found */
  54. HOSTAPD_CHAN_ACS = 2, /* ACS work being performed */
  55. };
  56. struct hostapd_probereq_cb {
  57. int (*cb)(void *ctx, const u8 *sa, const u8 *da, const u8 *bssid,
  58. const u8 *ie, size_t ie_len, int ssi_signal);
  59. void *ctx;
  60. };
  61. #define HOSTAPD_RATE_BASIC 0x00000001
  62. struct hostapd_rate_data {
  63. int rate; /* rate in 100 kbps */
  64. int flags; /* HOSTAPD_RATE_ flags */
  65. };
  66. struct hostapd_frame_info {
  67. u32 channel;
  68. u32 datarate;
  69. int ssi_signal; /* dBm */
  70. };
  71. enum wps_status {
  72. WPS_STATUS_SUCCESS = 1,
  73. WPS_STATUS_FAILURE
  74. };
  75. enum pbc_status {
  76. WPS_PBC_STATUS_DISABLE,
  77. WPS_PBC_STATUS_ACTIVE,
  78. WPS_PBC_STATUS_TIMEOUT,
  79. WPS_PBC_STATUS_OVERLAP
  80. };
  81. struct wps_stat {
  82. enum wps_status status;
  83. enum wps_error_indication failure_reason;
  84. enum pbc_status pbc_status;
  85. u8 peer_addr[ETH_ALEN];
  86. };
  87. struct hostapd_neighbor_entry {
  88. struct dl_list list;
  89. u8 bssid[ETH_ALEN];
  90. struct wpa_ssid_value ssid;
  91. struct wpabuf *nr;
  92. struct wpabuf *lci;
  93. struct wpabuf *civic;
  94. /* LCI update time */
  95. struct os_time lci_date;
  96. };
  97. /**
  98. * struct hostapd_data - hostapd per-BSS data structure
  99. */
  100. struct hostapd_data {
  101. struct hostapd_iface *iface;
  102. struct hostapd_config *iconf;
  103. struct hostapd_bss_config *conf;
  104. int interface_added; /* virtual interface added for this BSS */
  105. unsigned int started:1;
  106. unsigned int disabled:1;
  107. unsigned int reenable_beacon:1;
  108. u8 own_addr[ETH_ALEN];
  109. int num_sta; /* number of entries in sta_list */
  110. struct sta_info *sta_list; /* STA info list head */
  111. #define STA_HASH_SIZE 256
  112. #define STA_HASH(sta) (sta[5])
  113. struct sta_info *sta_hash[STA_HASH_SIZE];
  114. /*
  115. * Bitfield for indicating which AIDs are allocated. Only AID values
  116. * 1-2007 are used and as such, the bit at index 0 corresponds to AID
  117. * 1.
  118. */
  119. #define AID_WORDS ((2008 + 31) / 32)
  120. u32 sta_aid[AID_WORDS];
  121. const struct wpa_driver_ops *driver;
  122. void *drv_priv;
  123. void (*new_assoc_sta_cb)(struct hostapd_data *hapd,
  124. struct sta_info *sta, int reassoc);
  125. void *msg_ctx; /* ctx for wpa_msg() calls */
  126. void *msg_ctx_parent; /* parent interface ctx for wpa_msg() calls */
  127. struct radius_client_data *radius;
  128. u64 acct_session_id;
  129. struct radius_das_data *radius_das;
  130. struct iapp_data *iapp;
  131. struct hostapd_cached_radius_acl *acl_cache;
  132. struct hostapd_acl_query_data *acl_queries;
  133. struct wpa_authenticator *wpa_auth;
  134. struct eapol_authenticator *eapol_auth;
  135. struct rsn_preauth_interface *preauth_iface;
  136. struct os_reltime michael_mic_failure;
  137. int michael_mic_failures;
  138. int tkip_countermeasures;
  139. int ctrl_sock;
  140. struct dl_list ctrl_dst;
  141. void *ssl_ctx;
  142. void *eap_sim_db_priv;
  143. struct radius_server_data *radius_srv;
  144. struct dl_list erp_keys; /* struct eap_server_erp_key */
  145. int parameter_set_count;
  146. /* Time Advertisement */
  147. u8 time_update_counter;
  148. struct wpabuf *time_adv;
  149. #ifdef CONFIG_FULL_DYNAMIC_VLAN
  150. struct full_dynamic_vlan *full_dynamic_vlan;
  151. #endif /* CONFIG_FULL_DYNAMIC_VLAN */
  152. struct l2_packet_data *l2;
  153. struct wps_context *wps;
  154. int beacon_set_done;
  155. struct wpabuf *wps_beacon_ie;
  156. struct wpabuf *wps_probe_resp_ie;
  157. #ifdef CONFIG_WPS
  158. unsigned int ap_pin_failures;
  159. unsigned int ap_pin_failures_consecutive;
  160. struct upnp_wps_device_sm *wps_upnp;
  161. unsigned int ap_pin_lockout_time;
  162. struct wps_stat wps_stats;
  163. #endif /* CONFIG_WPS */
  164. struct hostapd_probereq_cb *probereq_cb;
  165. size_t num_probereq_cb;
  166. void (*public_action_cb)(void *ctx, const u8 *buf, size_t len,
  167. int freq);
  168. void *public_action_cb_ctx;
  169. void (*public_action_cb2)(void *ctx, const u8 *buf, size_t len,
  170. int freq);
  171. void *public_action_cb2_ctx;
  172. int (*vendor_action_cb)(void *ctx, const u8 *buf, size_t len,
  173. int freq);
  174. void *vendor_action_cb_ctx;
  175. void (*wps_reg_success_cb)(void *ctx, const u8 *mac_addr,
  176. const u8 *uuid_e);
  177. void *wps_reg_success_cb_ctx;
  178. void (*wps_event_cb)(void *ctx, enum wps_event event,
  179. union wps_event_data *data);
  180. void *wps_event_cb_ctx;
  181. void (*sta_authorized_cb)(void *ctx, const u8 *mac_addr,
  182. int authorized, const u8 *p2p_dev_addr);
  183. void *sta_authorized_cb_ctx;
  184. void (*setup_complete_cb)(void *ctx);
  185. void *setup_complete_cb_ctx;
  186. void (*new_psk_cb)(void *ctx, const u8 *mac_addr,
  187. const u8 *p2p_dev_addr, const u8 *psk,
  188. size_t psk_len);
  189. void *new_psk_cb_ctx;
  190. /* channel switch parameters */
  191. struct hostapd_freq_params cs_freq_params;
  192. u8 cs_count;
  193. int cs_block_tx;
  194. unsigned int cs_c_off_beacon;
  195. unsigned int cs_c_off_proberesp;
  196. int csa_in_progress;
  197. unsigned int cs_c_off_ecsa_beacon;
  198. unsigned int cs_c_off_ecsa_proberesp;
  199. /* BSS Load */
  200. unsigned int bss_load_update_timeout;
  201. #ifdef CONFIG_P2P
  202. struct p2p_data *p2p;
  203. struct p2p_group *p2p_group;
  204. struct wpabuf *p2p_beacon_ie;
  205. struct wpabuf *p2p_probe_resp_ie;
  206. /* Number of non-P2P association stations */
  207. int num_sta_no_p2p;
  208. /* Periodic NoA (used only when no non-P2P clients in the group) */
  209. int noa_enabled;
  210. int noa_start;
  211. int noa_duration;
  212. #endif /* CONFIG_P2P */
  213. #ifdef CONFIG_INTERWORKING
  214. size_t gas_frag_limit;
  215. #endif /* CONFIG_INTERWORKING */
  216. #ifdef CONFIG_PROXYARP
  217. struct l2_packet_data *sock_dhcp;
  218. struct l2_packet_data *sock_ndisc;
  219. #endif /* CONFIG_PROXYARP */
  220. #ifdef CONFIG_MESH
  221. int num_plinks;
  222. int max_plinks;
  223. void (*mesh_sta_free_cb)(struct hostapd_data *hapd,
  224. struct sta_info *sta);
  225. struct wpabuf *mesh_pending_auth;
  226. struct os_reltime mesh_pending_auth_time;
  227. u8 mesh_required_peer[ETH_ALEN];
  228. #endif /* CONFIG_MESH */
  229. #ifdef CONFIG_SQLITE
  230. struct hostapd_eap_user tmp_eap_user;
  231. #endif /* CONFIG_SQLITE */
  232. #ifdef CONFIG_SAE
  233. /** Key used for generating SAE anti-clogging tokens */
  234. u8 sae_token_key[8];
  235. struct os_reltime last_sae_token_key_update;
  236. int dot11RSNASAERetransPeriod; /* msec */
  237. #endif /* CONFIG_SAE */
  238. #ifdef CONFIG_TESTING_OPTIONS
  239. unsigned int ext_mgmt_frame_handling:1;
  240. unsigned int ext_eapol_frame_io:1;
  241. struct l2_packet_data *l2_test;
  242. #endif /* CONFIG_TESTING_OPTIONS */
  243. #ifdef CONFIG_MBO
  244. unsigned int mbo_assoc_disallow;
  245. #endif /* CONFIG_MBO */
  246. struct dl_list nr_db;
  247. u8 lci_req_token;
  248. u8 range_req_token;
  249. unsigned int lci_req_active:1;
  250. unsigned int range_req_active:1;
  251. };
  252. struct hostapd_sta_info {
  253. struct dl_list list;
  254. u8 addr[ETH_ALEN];
  255. struct os_reltime last_seen;
  256. #ifdef CONFIG_TAXONOMY
  257. struct wpabuf *probe_ie_taxonomy;
  258. #endif /* CONFIG_TAXONOMY */
  259. };
  260. /**
  261. * struct hostapd_iface - hostapd per-interface data structure
  262. */
  263. struct hostapd_iface {
  264. struct hapd_interfaces *interfaces;
  265. void *owner;
  266. char *config_fname;
  267. struct hostapd_config *conf;
  268. char phy[16]; /* Name of the PHY (radio) */
  269. enum hostapd_iface_state {
  270. HAPD_IFACE_UNINITIALIZED,
  271. HAPD_IFACE_DISABLED,
  272. HAPD_IFACE_COUNTRY_UPDATE,
  273. HAPD_IFACE_ACS,
  274. HAPD_IFACE_HT_SCAN,
  275. HAPD_IFACE_DFS,
  276. HAPD_IFACE_ENABLED
  277. } state;
  278. #ifdef CONFIG_MESH
  279. struct mesh_conf *mconf;
  280. #endif /* CONFIG_MESH */
  281. size_t num_bss;
  282. struct hostapd_data **bss;
  283. unsigned int wait_channel_update:1;
  284. unsigned int cac_started:1;
  285. #ifdef CONFIG_FST
  286. struct fst_iface *fst;
  287. const struct wpabuf *fst_ies;
  288. #endif /* CONFIG_FST */
  289. /*
  290. * When set, indicates that the driver will handle the AP
  291. * teardown: delete global keys, station keys, and stations.
  292. */
  293. unsigned int driver_ap_teardown:1;
  294. /*
  295. * When set, indicates that this interface is part of list of
  296. * interfaces that need to be started together (synchronously).
  297. */
  298. unsigned int need_to_start_in_sync:1;
  299. /* Ready to start but waiting for other interfaces to become ready. */
  300. unsigned int ready_to_start_in_sync:1;
  301. int num_ap; /* number of entries in ap_list */
  302. struct ap_info *ap_list; /* AP info list head */
  303. struct ap_info *ap_hash[STA_HASH_SIZE];
  304. u64 drv_flags;
  305. /* SMPS modes supported by the driver (WPA_DRIVER_SMPS_MODE_*) */
  306. unsigned int smps_modes;
  307. /*
  308. * A bitmap of supported protocols for probe response offload. See
  309. * struct wpa_driver_capa in driver.h
  310. */
  311. unsigned int probe_resp_offloads;
  312. /* extended capabilities supported by the driver */
  313. const u8 *extended_capa, *extended_capa_mask;
  314. unsigned int extended_capa_len;
  315. unsigned int drv_max_acl_mac_addrs;
  316. struct hostapd_hw_modes *hw_features;
  317. int num_hw_features;
  318. struct hostapd_hw_modes *current_mode;
  319. /* Rates that are currently used (i.e., filtered copy of
  320. * current_mode->channels */
  321. int num_rates;
  322. struct hostapd_rate_data *current_rates;
  323. int *basic_rates;
  324. int freq;
  325. u16 hw_flags;
  326. /* Number of associated Non-ERP stations (i.e., stations using 802.11b
  327. * in 802.11g BSS) */
  328. int num_sta_non_erp;
  329. /* Number of associated stations that do not support Short Slot Time */
  330. int num_sta_no_short_slot_time;
  331. /* Number of associated stations that do not support Short Preamble */
  332. int num_sta_no_short_preamble;
  333. int olbc; /* Overlapping Legacy BSS Condition */
  334. /* Number of HT associated stations that do not support greenfield */
  335. int num_sta_ht_no_gf;
  336. /* Number of associated non-HT stations */
  337. int num_sta_no_ht;
  338. /* Number of HT associated stations 20 MHz */
  339. int num_sta_ht_20mhz;
  340. /* Number of HT40 intolerant stations */
  341. int num_sta_ht40_intolerant;
  342. /* Overlapping BSS information */
  343. int olbc_ht;
  344. u16 ht_op_mode;
  345. /* surveying helpers */
  346. /* number of channels surveyed */
  347. unsigned int chans_surveyed;
  348. /* lowest observed noise floor in dBm */
  349. s8 lowest_nf;
  350. /* channel utilization calculation */
  351. u64 last_channel_time;
  352. u64 last_channel_time_busy;
  353. u8 channel_utilization;
  354. /* eCSA IE will be added only if operating class is specified */
  355. u8 cs_oper_class;
  356. unsigned int dfs_cac_ms;
  357. struct os_reltime dfs_cac_start;
  358. /* Latched with the actual secondary channel information and will be
  359. * used while juggling between HT20 and HT40 modes. */
  360. int secondary_ch;
  361. #ifdef CONFIG_ACS
  362. unsigned int acs_num_completed_scans;
  363. #endif /* CONFIG_ACS */
  364. void (*scan_cb)(struct hostapd_iface *iface);
  365. int num_ht40_scan_tries;
  366. struct dl_list sta_seen; /* struct hostapd_sta_info */
  367. unsigned int num_sta_seen;
  368. };
  369. /* hostapd.c */
  370. int hostapd_for_each_interface(struct hapd_interfaces *interfaces,
  371. int (*cb)(struct hostapd_iface *iface,
  372. void *ctx), void *ctx);
  373. int hostapd_reload_config(struct hostapd_iface *iface);
  374. struct hostapd_data *
  375. hostapd_alloc_bss_data(struct hostapd_iface *hapd_iface,
  376. struct hostapd_config *conf,
  377. struct hostapd_bss_config *bss);
  378. int hostapd_setup_interface(struct hostapd_iface *iface);
  379. int hostapd_setup_interface_complete(struct hostapd_iface *iface, int err);
  380. void hostapd_interface_deinit(struct hostapd_iface *iface);
  381. void hostapd_interface_free(struct hostapd_iface *iface);
  382. struct hostapd_iface * hostapd_alloc_iface(void);
  383. struct hostapd_iface * hostapd_init(struct hapd_interfaces *interfaces,
  384. const char *config_file);
  385. struct hostapd_iface *
  386. hostapd_interface_init_bss(struct hapd_interfaces *interfaces, const char *phy,
  387. const char *config_fname, int debug);
  388. void hostapd_new_assoc_sta(struct hostapd_data *hapd, struct sta_info *sta,
  389. int reassoc);
  390. void hostapd_interface_deinit_free(struct hostapd_iface *iface);
  391. int hostapd_enable_iface(struct hostapd_iface *hapd_iface);
  392. int hostapd_reload_iface(struct hostapd_iface *hapd_iface);
  393. int hostapd_disable_iface(struct hostapd_iface *hapd_iface);
  394. int hostapd_add_iface(struct hapd_interfaces *ifaces, char *buf);
  395. int hostapd_remove_iface(struct hapd_interfaces *ifaces, char *buf);
  396. void hostapd_channel_list_updated(struct hostapd_iface *iface, int initiator);
  397. void hostapd_set_state(struct hostapd_iface *iface, enum hostapd_iface_state s);
  398. const char * hostapd_state_text(enum hostapd_iface_state s);
  399. int hostapd_csa_in_progress(struct hostapd_iface *iface);
  400. int hostapd_switch_channel(struct hostapd_data *hapd,
  401. struct csa_settings *settings);
  402. void
  403. hostapd_switch_channel_fallback(struct hostapd_iface *iface,
  404. const struct hostapd_freq_params *freq_params);
  405. void hostapd_cleanup_cs_params(struct hostapd_data *hapd);
  406. void hostapd_periodic_iface(struct hostapd_iface *iface);
  407. /* utils.c */
  408. int hostapd_register_probereq_cb(struct hostapd_data *hapd,
  409. int (*cb)(void *ctx, const u8 *sa,
  410. const u8 *da, const u8 *bssid,
  411. const u8 *ie, size_t ie_len,
  412. int ssi_signal),
  413. void *ctx);
  414. void hostapd_prune_associations(struct hostapd_data *hapd, const u8 *addr);
  415. /* drv_callbacks.c (TODO: move to somewhere else?) */
  416. int hostapd_notif_assoc(struct hostapd_data *hapd, const u8 *addr,
  417. const u8 *ie, size_t ielen, int reassoc);
  418. void hostapd_notif_disassoc(struct hostapd_data *hapd, const u8 *addr);
  419. void hostapd_event_sta_low_ack(struct hostapd_data *hapd, const u8 *addr);
  420. void hostapd_event_connect_failed_reason(struct hostapd_data *hapd,
  421. const u8 *addr, int reason_code);
  422. int hostapd_probe_req_rx(struct hostapd_data *hapd, const u8 *sa, const u8 *da,
  423. const u8 *bssid, const u8 *ie, size_t ie_len,
  424. int ssi_signal);
  425. void hostapd_event_ch_switch(struct hostapd_data *hapd, int freq, int ht,
  426. int offset, int width, int cf1, int cf2);
  427. struct survey_results;
  428. void hostapd_event_get_survey(struct hostapd_iface *iface,
  429. struct survey_results *survey_results);
  430. void hostapd_acs_channel_selected(struct hostapd_data *hapd,
  431. struct acs_selected_channels *acs_res);
  432. const struct hostapd_eap_user *
  433. hostapd_get_eap_user(struct hostapd_data *hapd, const u8 *identity,
  434. size_t identity_len, int phase2);
  435. struct hostapd_data * hostapd_get_iface(struct hapd_interfaces *interfaces,
  436. const char *ifname);
  437. #ifdef CONFIG_FST
  438. void fst_hostapd_fill_iface_obj(struct hostapd_data *hapd,
  439. struct fst_wpa_obj *iface_obj);
  440. #endif /* CONFIG_FST */
  441. #endif /* HOSTAPD_H */