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 9 #ifndef HOSTAPD_H 10 #define HOSTAPD_H 11 12 #include "common/defs.h" 13 #include "utils/list.h" 14 #include "ap_config.h" 15 #include "drivers/driver.h" 16 17 #define OCE_STA_CFON_ENABLED(hapd) \ 18 ((hapd->conf->oce & OCE_STA_CFON) && \ 19 (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_OCE_STA_CFON)) 20 #define OCE_AP_ENABLED(hapd) \ 21 ((hapd->conf->oce & OCE_AP) && \ 22 (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_OCE_AP)) 23 24 struct wpa_ctrl_dst; 25 struct radius_server_data; 26 struct upnp_wps_device_sm; 27 struct hostapd_data; 28 struct sta_info; 29 struct ieee80211_ht_capabilities; 30 struct full_dynamic_vlan; 31 enum wps_event; 32 union wps_event_data; 33 #ifdef CONFIG_MESH 34 struct mesh_conf; 35 #endif /* CONFIG_MESH */ 36 37 struct hostapd_iface; 38 39 struct hapd_interfaces { 40 int (*reload_config)(struct hostapd_iface *iface); 41 struct hostapd_config * (*config_read_cb)(const char *config_fname); 42 int (*ctrl_iface_init)(struct hostapd_data *hapd); 43 void (*ctrl_iface_deinit)(struct hostapd_data *hapd); 44 int (*for_each_interface)(struct hapd_interfaces *interfaces, 45 int (*cb)(struct hostapd_iface *iface, 46 void *ctx), void *ctx); 47 int (*driver_init)(struct hostapd_iface *iface); 48 49 size_t count; 50 int global_ctrl_sock; 51 struct dl_list global_ctrl_dst; 52 char *global_iface_path; 53 char *global_iface_name; 54 #ifndef CONFIG_NATIVE_WINDOWS 55 gid_t ctrl_iface_group; 56 #endif /* CONFIG_NATIVE_WINDOWS */ 57 struct hostapd_iface **iface; 58 59 size_t terminate_on_error; 60 #ifndef CONFIG_NO_VLAN 61 struct dynamic_iface *vlan_priv; 62 #endif /* CONFIG_NO_VLAN */ 63 #ifdef CONFIG_ETH_P_OUI 64 struct dl_list eth_p_oui; /* OUI Extended EtherType handlers */ 65 #endif /* CONFIG_ETH_P_OUI */ 66 int eloop_initialized; 67 68 #ifdef CONFIG_DPP 69 int dpp_init_done; 70 struct dl_list dpp_bootstrap; /* struct dpp_bootstrap_info */ 71 struct dl_list dpp_configurator; /* struct dpp_configurator */ 72 #endif /* CONFIG_DPP */ 73 }; 74 75 enum hostapd_chan_status { 76 HOSTAPD_CHAN_VALID = 0, /* channel is ready */ 77 HOSTAPD_CHAN_INVALID = 1, /* no usable channel found */ 78 HOSTAPD_CHAN_ACS = 2, /* ACS work being performed */ 79 }; 80 81 struct hostapd_probereq_cb { 82 int (*cb)(void *ctx, const u8 *sa, const u8 *da, const u8 *bssid, 83 const u8 *ie, size_t ie_len, int ssi_signal); 84 void *ctx; 85 }; 86 87 #define HOSTAPD_RATE_BASIC 0x00000001 88 89 struct hostapd_rate_data { 90 int rate; /* rate in 100 kbps */ 91 int flags; /* HOSTAPD_RATE_ flags */ 92 }; 93 94 struct hostapd_frame_info { 95 unsigned int freq; 96 u32 channel; 97 u32 datarate; 98 int ssi_signal; /* dBm */ 99 }; 100 101 enum wps_status { 102 WPS_STATUS_SUCCESS = 1, 103 WPS_STATUS_FAILURE 104 }; 105 106 enum pbc_status { 107 WPS_PBC_STATUS_DISABLE, 108 WPS_PBC_STATUS_ACTIVE, 109 WPS_PBC_STATUS_TIMEOUT, 110 WPS_PBC_STATUS_OVERLAP 111 }; 112 113 struct wps_stat { 114 enum wps_status status; 115 enum wps_error_indication failure_reason; 116 enum pbc_status pbc_status; 117 u8 peer_addr[ETH_ALEN]; 118 }; 119 120 struct hostapd_neighbor_entry { 121 struct dl_list list; 122 u8 bssid[ETH_ALEN]; 123 struct wpa_ssid_value ssid; 124 struct wpabuf *nr; 125 struct wpabuf *lci; 126 struct wpabuf *civic; 127 /* LCI update time */ 128 struct os_time lci_date; 129 int stationary; 130 }; 131 132 /** 133 * struct hostapd_data - hostapd per-BSS data structure 134 */ 135 struct hostapd_data { 136 struct hostapd_iface *iface; 137 struct hostapd_config *iconf; 138 struct hostapd_bss_config *conf; 139 int interface_added; /* virtual interface added for this BSS */ 140 unsigned int started:1; 141 unsigned int disabled:1; 142 unsigned int reenable_beacon:1; 143 144 u8 own_addr[ETH_ALEN]; 145 146 int num_sta; /* number of entries in sta_list */ 147 struct sta_info *sta_list; /* STA info list head */ 148 #define STA_HASH_SIZE 256 149 #define STA_HASH(sta) (sta[5]) 150 struct sta_info *sta_hash[STA_HASH_SIZE]; 151 152 /* 153 * Bitfield for indicating which AIDs are allocated. Only AID values 154 * 1-2007 are used and as such, the bit at index 0 corresponds to AID 155 * 1. 156 */ 157 #define AID_WORDS ((2008 + 31) / 32) 158 u32 sta_aid[AID_WORDS]; 159 160 const struct wpa_driver_ops *driver; 161 void *drv_priv; 162 163 void (*new_assoc_sta_cb)(struct hostapd_data *hapd, 164 struct sta_info *sta, int reassoc); 165 166 void *msg_ctx; /* ctx for wpa_msg() calls */ 167 void *msg_ctx_parent; /* parent interface ctx for wpa_msg() calls */ 168 169 struct radius_client_data *radius; 170 u64 acct_session_id; 171 struct radius_das_data *radius_das; 172 173 struct iapp_data *iapp; 174 175 struct hostapd_cached_radius_acl *acl_cache; 176 struct hostapd_acl_query_data *acl_queries; 177 178 struct wpa_authenticator *wpa_auth; 179 struct eapol_authenticator *eapol_auth; 180 181 struct rsn_preauth_interface *preauth_iface; 182 struct os_reltime michael_mic_failure; 183 int michael_mic_failures; 184 int tkip_countermeasures; 185 186 int ctrl_sock; 187 struct dl_list ctrl_dst; 188 189 void *ssl_ctx; 190 void *eap_sim_db_priv; 191 struct radius_server_data *radius_srv; 192 struct dl_list erp_keys; /* struct eap_server_erp_key */ 193 194 int parameter_set_count; 195 196 /* Time Advertisement */ 197 u8 time_update_counter; 198 struct wpabuf *time_adv; 199 200 #ifdef CONFIG_FULL_DYNAMIC_VLAN 201 struct full_dynamic_vlan *full_dynamic_vlan; 202 #endif /* CONFIG_FULL_DYNAMIC_VLAN */ 203 204 struct l2_packet_data *l2; 205 206 #ifdef CONFIG_IEEE80211R_AP 207 struct dl_list l2_queue; 208 struct dl_list l2_oui_queue; 209 struct eth_p_oui_ctx *oui_pull; 210 struct eth_p_oui_ctx *oui_resp; 211 struct eth_p_oui_ctx *oui_push; 212 struct eth_p_oui_ctx *oui_sreq; 213 struct eth_p_oui_ctx *oui_sresp; 214 #endif /* CONFIG_IEEE80211R_AP */ 215 216 struct wps_context *wps; 217 218 int beacon_set_done; 219 struct wpabuf *wps_beacon_ie; 220 struct wpabuf *wps_probe_resp_ie; 221 #ifdef CONFIG_WPS 222 unsigned int ap_pin_failures; 223 unsigned int ap_pin_failures_consecutive; 224 struct upnp_wps_device_sm *wps_upnp; 225 unsigned int ap_pin_lockout_time; 226 227 struct wps_stat wps_stats; 228 #endif /* CONFIG_WPS */ 229 230 struct hostapd_probereq_cb *probereq_cb; 231 size_t num_probereq_cb; 232 233 void (*public_action_cb)(void *ctx, const u8 *buf, size_t len, 234 int freq); 235 void *public_action_cb_ctx; 236 void (*public_action_cb2)(void *ctx, const u8 *buf, size_t len, 237 int freq); 238 void *public_action_cb2_ctx; 239 240 int (*vendor_action_cb)(void *ctx, const u8 *buf, size_t len, 241 int freq); 242 void *vendor_action_cb_ctx; 243 244 void (*wps_reg_success_cb)(void *ctx, const u8 *mac_addr, 245 const u8 *uuid_e); 246 void *wps_reg_success_cb_ctx; 247 248 void (*wps_event_cb)(void *ctx, enum wps_event event, 249 union wps_event_data *data); 250 void *wps_event_cb_ctx; 251 252 void (*sta_authorized_cb)(void *ctx, const u8 *mac_addr, 253 int authorized, const u8 *p2p_dev_addr); 254 void *sta_authorized_cb_ctx; 255 256 void (*setup_complete_cb)(void *ctx); 257 void *setup_complete_cb_ctx; 258 259 void (*new_psk_cb)(void *ctx, const u8 *mac_addr, 260 const u8 *p2p_dev_addr, const u8 *psk, 261 size_t psk_len); 262 void *new_psk_cb_ctx; 263 264 /* channel switch parameters */ 265 struct hostapd_freq_params cs_freq_params; 266 u8 cs_count; 267 int cs_block_tx; 268 unsigned int cs_c_off_beacon; 269 unsigned int cs_c_off_proberesp; 270 int csa_in_progress; 271 unsigned int cs_c_off_ecsa_beacon; 272 unsigned int cs_c_off_ecsa_proberesp; 273 274 #ifdef CONFIG_P2P 275 struct p2p_data *p2p; 276 struct p2p_group *p2p_group; 277 struct wpabuf *p2p_beacon_ie; 278 struct wpabuf *p2p_probe_resp_ie; 279 280 /* Number of non-P2P association stations */ 281 int num_sta_no_p2p; 282 283 /* Periodic NoA (used only when no non-P2P clients in the group) */ 284 int noa_enabled; 285 int noa_start; 286 int noa_duration; 287 #endif /* CONFIG_P2P */ 288 #ifdef CONFIG_PROXYARP 289 struct l2_packet_data *sock_dhcp; 290 struct l2_packet_data *sock_ndisc; 291 #endif /* CONFIG_PROXYARP */ 292 #ifdef CONFIG_MESH 293 int num_plinks; 294 int max_plinks; 295 void (*mesh_sta_free_cb)(struct hostapd_data *hapd, 296 struct sta_info *sta); 297 struct wpabuf *mesh_pending_auth; 298 struct os_reltime mesh_pending_auth_time; 299 u8 mesh_required_peer[ETH_ALEN]; 300 #endif /* CONFIG_MESH */ 301 302 #ifdef CONFIG_SQLITE 303 struct hostapd_eap_user tmp_eap_user; 304 #endif /* CONFIG_SQLITE */ 305 306 #ifdef CONFIG_SAE 307 /** Key used for generating SAE anti-clogging tokens */ 308 u8 sae_token_key[8]; 309 struct os_reltime last_sae_token_key_update; 310 int dot11RSNASAERetransPeriod; /* msec */ 311 #endif /* CONFIG_SAE */ 312 313 #ifdef CONFIG_TESTING_OPTIONS 314 unsigned int ext_mgmt_frame_handling:1; 315 unsigned int ext_eapol_frame_io:1; 316 317 struct l2_packet_data *l2_test; 318 319 enum wpa_alg last_gtk_alg; 320 int last_gtk_key_idx; 321 u8 last_gtk[WPA_GTK_MAX_LEN]; 322 size_t last_gtk_len; 323 324 #ifdef CONFIG_IEEE80211W 325 enum wpa_alg last_igtk_alg; 326 int last_igtk_key_idx; 327 u8 last_igtk[WPA_IGTK_MAX_LEN]; 328 size_t last_igtk_len; 329 #endif /* CONFIG_IEEE80211W */ 330 #endif /* CONFIG_TESTING_OPTIONS */ 331 332 #ifdef CONFIG_MBO 333 unsigned int mbo_assoc_disallow; 334 #endif /* CONFIG_MBO */ 335 336 struct dl_list nr_db; 337 338 u8 beacon_req_token; 339 u8 lci_req_token; 340 u8 range_req_token; 341 unsigned int lci_req_active:1; 342 unsigned int range_req_active:1; 343 344 int dhcp_sock; /* UDP socket used with the DHCP server */ 345 346 #ifdef CONFIG_DPP 347 int dpp_init_done; 348 struct dpp_authentication *dpp_auth; 349 u8 dpp_allowed_roles; 350 int dpp_qr_mutual; 351 int dpp_auth_ok_on_ack; 352 int dpp_in_response_listen; 353 struct gas_query_ap *gas; 354 struct dpp_pkex *dpp_pkex; 355 struct dpp_bootstrap_info *dpp_pkex_bi; 356 char *dpp_pkex_code; 357 char *dpp_pkex_identifier; 358 char *dpp_pkex_auth_cmd; 359 char *dpp_configurator_params; 360 struct os_reltime dpp_last_init; 361 struct os_reltime dpp_init_iter_start; 362 unsigned int dpp_init_max_tries; 363 unsigned int dpp_init_retry_time; 364 unsigned int dpp_resp_wait_time; 365 unsigned int dpp_resp_max_tries; 366 unsigned int dpp_resp_retry_time; 367 #ifdef CONFIG_TESTING_OPTIONS 368 char *dpp_config_obj_override; 369 char *dpp_discovery_override; 370 char *dpp_groups_override; 371 unsigned int dpp_ignore_netaccesskey_mismatch:1; 372 #endif /* CONFIG_TESTING_OPTIONS */ 373 #endif /* CONFIG_DPP */ 374 }; 375 376 377 struct hostapd_sta_info { 378 struct dl_list list; 379 u8 addr[ETH_ALEN]; 380 struct os_reltime last_seen; 381 int ssi_signal; 382 #ifdef CONFIG_TAXONOMY 383 struct wpabuf *probe_ie_taxonomy; 384 #endif /* CONFIG_TAXONOMY */ 385 }; 386 387 /** 388 * struct hostapd_iface - hostapd per-interface data structure 389 */ 390 struct hostapd_iface { 391 struct hapd_interfaces *interfaces; 392 void *owner; 393 char *config_fname; 394 struct hostapd_config *conf; 395 char phy[16]; /* Name of the PHY (radio) */ 396 397 enum hostapd_iface_state { 398 HAPD_IFACE_UNINITIALIZED, 399 HAPD_IFACE_DISABLED, 400 HAPD_IFACE_COUNTRY_UPDATE, 401 HAPD_IFACE_ACS, 402 HAPD_IFACE_HT_SCAN, 403 HAPD_IFACE_DFS, 404 HAPD_IFACE_ENABLED 405 } state; 406 407 #ifdef CONFIG_MESH 408 struct mesh_conf *mconf; 409 #endif /* CONFIG_MESH */ 410 411 size_t num_bss; 412 struct hostapd_data **bss; 413 414 unsigned int wait_channel_update:1; 415 unsigned int cac_started:1; 416 #ifdef CONFIG_FST 417 struct fst_iface *fst; 418 const struct wpabuf *fst_ies; 419 #endif /* CONFIG_FST */ 420 421 /* 422 * When set, indicates that the driver will handle the AP 423 * teardown: delete global keys, station keys, and stations. 424 */ 425 unsigned int driver_ap_teardown:1; 426 427 /* 428 * When set, indicates that this interface is part of list of 429 * interfaces that need to be started together (synchronously). 430 */ 431 unsigned int need_to_start_in_sync:1; 432 433 /* Ready to start but waiting for other interfaces to become ready. */ 434 unsigned int ready_to_start_in_sync:1; 435 436 int num_ap; /* number of entries in ap_list */ 437 struct ap_info *ap_list; /* AP info list head */ 438 struct ap_info *ap_hash[STA_HASH_SIZE]; 439 440 u64 drv_flags; 441 442 /* SMPS modes supported by the driver (WPA_DRIVER_SMPS_MODE_*) */ 443 unsigned int smps_modes; 444 445 /* 446 * A bitmap of supported protocols for probe response offload. See 447 * struct wpa_driver_capa in driver.h 448 */ 449 unsigned int probe_resp_offloads; 450 451 /* extended capabilities supported by the driver */ 452 const u8 *extended_capa, *extended_capa_mask; 453 unsigned int extended_capa_len; 454 455 unsigned int drv_max_acl_mac_addrs; 456 457 struct hostapd_hw_modes *hw_features; 458 int num_hw_features; 459 struct hostapd_hw_modes *current_mode; 460 /* Rates that are currently used (i.e., filtered copy of 461 * current_mode->channels */ 462 int num_rates; 463 struct hostapd_rate_data *current_rates; 464 int *basic_rates; 465 int freq; 466 467 u16 hw_flags; 468 469 /* Number of associated Non-ERP stations (i.e., stations using 802.11b 470 * in 802.11g BSS) */ 471 int num_sta_non_erp; 472 473 /* Number of associated stations that do not support Short Slot Time */ 474 int num_sta_no_short_slot_time; 475 476 /* Number of associated stations that do not support Short Preamble */ 477 int num_sta_no_short_preamble; 478 479 int olbc; /* Overlapping Legacy BSS Condition */ 480 481 /* Number of HT associated stations that do not support greenfield */ 482 int num_sta_ht_no_gf; 483 484 /* Number of associated non-HT stations */ 485 int num_sta_no_ht; 486 487 /* Number of HT associated stations 20 MHz */ 488 int num_sta_ht_20mhz; 489 490 /* Number of HT40 intolerant stations */ 491 int num_sta_ht40_intolerant; 492 493 /* Overlapping BSS information */ 494 int olbc_ht; 495 496 u16 ht_op_mode; 497 498 /* surveying helpers */ 499 500 /* number of channels surveyed */ 501 unsigned int chans_surveyed; 502 503 /* lowest observed noise floor in dBm */ 504 s8 lowest_nf; 505 506 /* channel utilization calculation */ 507 u64 last_channel_time; 508 u64 last_channel_time_busy; 509 u8 channel_utilization; 510 511 unsigned int chan_util_samples_sum; 512 unsigned int chan_util_num_sample_periods; 513 unsigned int chan_util_average; 514 515 /* eCSA IE will be added only if operating class is specified */ 516 u8 cs_oper_class; 517 518 unsigned int dfs_cac_ms; 519 struct os_reltime dfs_cac_start; 520 521 /* Latched with the actual secondary channel information and will be 522 * used while juggling between HT20 and HT40 modes. */ 523 int secondary_ch; 524 525 #ifdef CONFIG_ACS 526 unsigned int acs_num_completed_scans; 527 #endif /* CONFIG_ACS */ 528 529 void (*scan_cb)(struct hostapd_iface *iface); 530 int num_ht40_scan_tries; 531 532 struct dl_list sta_seen; /* struct hostapd_sta_info */ 533 unsigned int num_sta_seen; 534 535 u8 dfs_domain; 536 }; 537 538 /* hostapd.c */ 539 int hostapd_for_each_interface(struct hapd_interfaces *interfaces, 540 int (*cb)(struct hostapd_iface *iface, 541 void *ctx), void *ctx); 542 int hostapd_reload_config(struct hostapd_iface *iface); 543 void hostapd_reconfig_encryption(struct hostapd_data *hapd); 544 struct hostapd_data * 545 hostapd_alloc_bss_data(struct hostapd_iface *hapd_iface, 546 struct hostapd_config *conf, 547 struct hostapd_bss_config *bss); 548 int hostapd_setup_interface(struct hostapd_iface *iface); 549 int hostapd_setup_interface_complete(struct hostapd_iface *iface, int err); 550 void hostapd_interface_deinit(struct hostapd_iface *iface); 551 void hostapd_interface_free(struct hostapd_iface *iface); 552 struct hostapd_iface * hostapd_alloc_iface(void); 553 struct hostapd_iface * hostapd_init(struct hapd_interfaces *interfaces, 554 const char *config_file); 555 struct hostapd_iface * 556 hostapd_interface_init_bss(struct hapd_interfaces *interfaces, const char *phy, 557 const char *config_fname, int debug); 558 void hostapd_new_assoc_sta(struct hostapd_data *hapd, struct sta_info *sta, 559 int reassoc); 560 void hostapd_interface_deinit_free(struct hostapd_iface *iface); 561 int hostapd_enable_iface(struct hostapd_iface *hapd_iface); 562 int hostapd_reload_iface(struct hostapd_iface *hapd_iface); 563 int hostapd_disable_iface(struct hostapd_iface *hapd_iface); 564 int hostapd_add_iface(struct hapd_interfaces *ifaces, char *buf); 565 int hostapd_remove_iface(struct hapd_interfaces *ifaces, char *buf); 566 void hostapd_channel_list_updated(struct hostapd_iface *iface, int initiator); 567 void hostapd_set_state(struct hostapd_iface *iface, enum hostapd_iface_state s); 568 const char * hostapd_state_text(enum hostapd_iface_state s); 569 int hostapd_csa_in_progress(struct hostapd_iface *iface); 570 void hostapd_chan_switch_vht_config(struct hostapd_data *hapd, int vht_enabled); 571 int hostapd_switch_channel(struct hostapd_data *hapd, 572 struct csa_settings *settings); 573 void 574 hostapd_switch_channel_fallback(struct hostapd_iface *iface, 575 const struct hostapd_freq_params *freq_params); 576 void hostapd_cleanup_cs_params(struct hostapd_data *hapd); 577 void hostapd_periodic_iface(struct hostapd_iface *iface); 578 int hostapd_owe_trans_get_info(struct hostapd_data *hapd); 579 580 /* utils.c */ 581 int hostapd_register_probereq_cb(struct hostapd_data *hapd, 582 int (*cb)(void *ctx, const u8 *sa, 583 const u8 *da, const u8 *bssid, 584 const u8 *ie, size_t ie_len, 585 int ssi_signal), 586 void *ctx); 587 void hostapd_prune_associations(struct hostapd_data *hapd, const u8 *addr); 588 589 /* drv_callbacks.c (TODO: move to somewhere else?) */ 590 void hostapd_notify_assoc_fils_finish(struct hostapd_data *hapd, 591 struct sta_info *sta); 592 int hostapd_notif_assoc(struct hostapd_data *hapd, const u8 *addr, 593 const u8 *ie, size_t ielen, int reassoc); 594 void hostapd_notif_disassoc(struct hostapd_data *hapd, const u8 *addr); 595 void hostapd_event_sta_low_ack(struct hostapd_data *hapd, const u8 *addr); 596 void hostapd_event_connect_failed_reason(struct hostapd_data *hapd, 597 const u8 *addr, int reason_code); 598 int hostapd_probe_req_rx(struct hostapd_data *hapd, const u8 *sa, const u8 *da, 599 const u8 *bssid, const u8 *ie, size_t ie_len, 600 int ssi_signal); 601 void hostapd_event_ch_switch(struct hostapd_data *hapd, int freq, int ht, 602 int offset, int width, int cf1, int cf2); 603 struct survey_results; 604 void hostapd_event_get_survey(struct hostapd_iface *iface, 605 struct survey_results *survey_results); 606 void hostapd_acs_channel_selected(struct hostapd_data *hapd, 607 struct acs_selected_channels *acs_res); 608 609 const struct hostapd_eap_user * 610 hostapd_get_eap_user(struct hostapd_data *hapd, const u8 *identity, 611 size_t identity_len, int phase2); 612 613 struct hostapd_data * hostapd_get_iface(struct hapd_interfaces *interfaces, 614 const char *ifname); 615 void hostapd_event_sta_opmode_changed(struct hostapd_data *hapd, const u8 *addr, 616 enum smps_mode smps_mode, 617 enum chan_width chan_width, u8 rx_nss); 618 619 #ifdef CONFIG_FST 620 void fst_hostapd_fill_iface_obj(struct hostapd_data *hapd, 621 struct fst_wpa_obj *iface_obj); 622 #endif /* CONFIG_FST */ 623 624 #endif /* HOSTAPD_H */ 625