2 * hostapd / Initialization and configuration
3 * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
9 #include "utils/includes.h"
11 #include "utils/common.h"
12 #include "utils/eloop.h"
13 #include "common/ieee802_11_defs.h"
14 #include "radius/radius_client.h"
15 #include "drivers/driver.h"
19 #include "accounting.h"
23 #include "ieee802_1x.h"
24 #include "ieee802_11_auth.h"
25 #include "vlan_init.h"
27 #include "wps_hostapd.h"
28 #include "hw_features.h"
29 #include "wpa_auth_glue.h"
30 #include "ap_drv_ops.h"
31 #include "ap_config.h"
32 #include "p2p_hostapd.h"
36 static int hostapd_flush_old_stations(struct hostapd_data *hapd);
37 static int hostapd_setup_encryption(char *iface, struct hostapd_data *hapd);
38 static int hostapd_broadcast_wep_clear(struct hostapd_data *hapd);
40 extern int wpa_debug_level;
43 int hostapd_for_each_interface(struct hapd_interfaces *interfaces,
44 int (*cb)(struct hostapd_iface *iface,
45 void *ctx), void *ctx)
50 for (i = 0; i < interfaces->count; i++) {
51 ret = cb(interfaces->iface[i], ctx);
60 static void hostapd_reload_bss(struct hostapd_data *hapd)
62 #ifndef CONFIG_NO_RADIUS
63 radius_client_reconfig(hapd->radius, hapd->conf->radius);
64 #endif /* CONFIG_NO_RADIUS */
66 if (hostapd_setup_wpa_psk(hapd->conf)) {
67 wpa_printf(MSG_ERROR, "Failed to re-configure WPA PSK "
68 "after reloading configuration");
71 if (hapd->conf->ieee802_1x || hapd->conf->wpa)
72 hostapd_set_drv_ieee8021x(hapd, hapd->conf->iface, 1);
74 hostapd_set_drv_ieee8021x(hapd, hapd->conf->iface, 0);
76 if (hapd->conf->wpa && hapd->wpa_auth == NULL) {
77 hostapd_setup_wpa(hapd);
79 wpa_init_keys(hapd->wpa_auth);
80 } else if (hapd->conf->wpa) {
83 hostapd_reconfig_wpa(hapd);
84 wpa_ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &wpa_ie_len);
85 if (hostapd_set_generic_elem(hapd, wpa_ie, wpa_ie_len))
86 wpa_printf(MSG_ERROR, "Failed to configure WPA IE for "
87 "the kernel driver.");
88 } else if (hapd->wpa_auth) {
89 wpa_deinit(hapd->wpa_auth);
90 hapd->wpa_auth = NULL;
91 hostapd_set_privacy(hapd, 0);
92 hostapd_setup_encryption(hapd->conf->iface, hapd);
93 hostapd_set_generic_elem(hapd, (u8 *) "", 0);
96 ieee802_11_set_beacon(hapd);
97 hostapd_update_wps(hapd);
99 if (hapd->conf->ssid.ssid_set &&
100 hostapd_set_ssid(hapd, (u8 *) hapd->conf->ssid.ssid,
101 hapd->conf->ssid.ssid_len)) {
102 wpa_printf(MSG_ERROR, "Could not set SSID for kernel driver");
103 /* try to continue */
105 wpa_printf(MSG_DEBUG, "Reconfigured interface %s", hapd->conf->iface);
109 int hostapd_reload_config(struct hostapd_iface *iface)
111 struct hostapd_data *hapd = iface->bss[0];
112 struct hostapd_config *newconf, *oldconf;
115 if (iface->config_read_cb == NULL)
117 newconf = iface->config_read_cb(iface->config_fname);
122 * Deauthenticate all stations since the new configuration may not
123 * allow them to use the BSS anymore.
125 for (j = 0; j < iface->num_bss; j++) {
126 hostapd_flush_old_stations(iface->bss[j]);
127 hostapd_broadcast_wep_clear(iface->bss[j]);
129 #ifndef CONFIG_NO_RADIUS
130 /* TODO: update dynamic data based on changed configuration
131 * items (e.g., open/close sockets, etc.) */
132 radius_client_flush(iface->bss[j]->radius, 0);
133 #endif /* CONFIG_NO_RADIUS */
136 oldconf = hapd->iconf;
137 iface->conf = newconf;
139 for (j = 0; j < iface->num_bss; j++) {
140 hapd = iface->bss[j];
141 hapd->iconf = newconf;
142 hapd->conf = &newconf->bss[j];
143 hostapd_reload_bss(hapd);
146 hostapd_config_free(oldconf);
153 static void hostapd_broadcast_key_clear_iface(struct hostapd_data *hapd,
158 for (i = 0; i < NUM_WEP_KEYS; i++) {
159 if (hostapd_drv_set_key(ifname, hapd, WPA_ALG_NONE, NULL, i,
160 0, NULL, 0, NULL, 0)) {
161 wpa_printf(MSG_DEBUG, "Failed to clear default "
162 "encryption keys (ifname=%s keyidx=%d)",
166 #ifdef CONFIG_IEEE80211W
167 if (hapd->conf->ieee80211w) {
168 for (i = NUM_WEP_KEYS; i < NUM_WEP_KEYS + 2; i++) {
169 if (hostapd_drv_set_key(ifname, hapd, WPA_ALG_NONE,
172 wpa_printf(MSG_DEBUG, "Failed to clear "
173 "default mgmt encryption keys "
174 "(ifname=%s keyidx=%d)", ifname, i);
178 #endif /* CONFIG_IEEE80211W */
182 static int hostapd_broadcast_wep_clear(struct hostapd_data *hapd)
184 hostapd_broadcast_key_clear_iface(hapd, hapd->conf->iface);
189 static int hostapd_broadcast_wep_set(struct hostapd_data *hapd)
192 struct hostapd_ssid *ssid = &hapd->conf->ssid;
195 if (ssid->wep.default_len &&
196 hostapd_drv_set_key(hapd->conf->iface,
197 hapd, WPA_ALG_WEP, broadcast_ether_addr, idx,
198 1, NULL, 0, ssid->wep.key[idx],
199 ssid->wep.len[idx])) {
200 wpa_printf(MSG_WARNING, "Could not set WEP encryption.");
204 if (ssid->dyn_vlan_keys) {
206 for (i = 0; i <= ssid->max_dyn_vlan_keys; i++) {
208 struct hostapd_wep_keys *key = ssid->dyn_vlan_keys[i];
211 ifname = hostapd_get_vlan_id_ifname(hapd->conf->vlan,
217 if (hostapd_drv_set_key(ifname, hapd, WPA_ALG_WEP,
218 broadcast_ether_addr, idx, 1,
219 NULL, 0, key->key[idx],
221 wpa_printf(MSG_WARNING, "Could not set "
222 "dynamic VLAN WEP encryption.");
232 static void hostapd_free_hapd_data(struct hostapd_data *hapd)
234 iapp_deinit(hapd->iapp);
236 accounting_deinit(hapd);
237 hostapd_deinit_wpa(hapd);
239 hostapd_acl_deinit(hapd);
240 #ifndef CONFIG_NO_RADIUS
241 radius_client_deinit(hapd->radius);
243 #endif /* CONFIG_NO_RADIUS */
245 hostapd_deinit_wps(hapd);
247 authsrv_deinit(hapd);
249 if (hapd->interface_added &&
250 hostapd_if_remove(hapd, WPA_IF_AP_BSS, hapd->conf->iface)) {
251 wpa_printf(MSG_WARNING, "Failed to remove BSS interface %s",
255 os_free(hapd->probereq_cb);
256 hapd->probereq_cb = NULL;
259 wpabuf_free(hapd->p2p_beacon_ie);
260 hapd->p2p_beacon_ie = NULL;
261 wpabuf_free(hapd->p2p_probe_resp_ie);
262 hapd->p2p_probe_resp_ie = NULL;
263 #endif /* CONFIG_P2P */
265 wpabuf_free(hapd->time_adv);
267 #ifdef CONFIG_INTERWORKING
268 gas_serv_deinit(hapd);
269 #endif /* CONFIG_INTERWORKING */
274 * hostapd_cleanup - Per-BSS cleanup (deinitialization)
275 * @hapd: Pointer to BSS data
277 * This function is used to free all per-BSS data structures and resources.
278 * This gets called in a loop for each BSS between calls to
279 * hostapd_cleanup_iface_pre() and hostapd_cleanup_iface() when an interface
280 * is deinitialized. Most of the modules that are initialized in
281 * hostapd_setup_bss() are deinitialized here.
283 static void hostapd_cleanup(struct hostapd_data *hapd)
285 if (hapd->iface->ctrl_iface_deinit)
286 hapd->iface->ctrl_iface_deinit(hapd);
287 hostapd_free_hapd_data(hapd);
292 * hostapd_cleanup_iface_pre - Preliminary per-interface cleanup
293 * @iface: Pointer to interface data
295 * This function is called before per-BSS data structures are deinitialized
296 * with hostapd_cleanup().
298 static void hostapd_cleanup_iface_pre(struct hostapd_iface *iface)
303 static void hostapd_cleanup_iface_partial(struct hostapd_iface *iface)
305 hostapd_free_hw_features(iface->hw_features, iface->num_hw_features);
306 iface->hw_features = NULL;
307 os_free(iface->current_rates);
308 iface->current_rates = NULL;
309 os_free(iface->basic_rates);
310 iface->basic_rates = NULL;
311 ap_list_deinit(iface);
316 * hostapd_cleanup_iface - Complete per-interface cleanup
317 * @iface: Pointer to interface data
319 * This function is called after per-BSS data structures are deinitialized
320 * with hostapd_cleanup().
322 static void hostapd_cleanup_iface(struct hostapd_iface *iface)
324 hostapd_cleanup_iface_partial(iface);
325 hostapd_config_free(iface->conf);
328 os_free(iface->config_fname);
334 static void hostapd_clear_wep(struct hostapd_data *hapd)
336 if (hapd->drv_priv) {
337 hostapd_set_privacy(hapd, 0);
338 hostapd_broadcast_wep_clear(hapd);
343 static int hostapd_setup_encryption(char *iface, struct hostapd_data *hapd)
347 hostapd_broadcast_wep_set(hapd);
349 if (hapd->conf->ssid.wep.default_len) {
350 hostapd_set_privacy(hapd, 1);
355 * When IEEE 802.1X is not enabled, the driver may need to know how to
356 * set authentication algorithms for static WEP.
358 hostapd_drv_set_authmode(hapd, hapd->conf->auth_algs);
360 for (i = 0; i < 4; i++) {
361 if (hapd->conf->ssid.wep.key[i] &&
362 hostapd_drv_set_key(iface, hapd, WPA_ALG_WEP, NULL, i,
363 i == hapd->conf->ssid.wep.idx, NULL, 0,
364 hapd->conf->ssid.wep.key[i],
365 hapd->conf->ssid.wep.len[i])) {
366 wpa_printf(MSG_WARNING, "Could not set WEP "
370 if (hapd->conf->ssid.wep.key[i] &&
371 i == hapd->conf->ssid.wep.idx)
372 hostapd_set_privacy(hapd, 1);
379 static int hostapd_flush_old_stations(struct hostapd_data *hapd)
384 if (hostapd_drv_none(hapd) || hapd->drv_priv == NULL)
387 wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "Flushing old station entries");
388 if (hostapd_flush(hapd)) {
389 wpa_msg(hapd->msg_ctx, MSG_WARNING, "Could not connect to "
393 wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "Deauthenticate all stations");
394 os_memset(addr, 0xff, ETH_ALEN);
395 hostapd_drv_sta_deauth(hapd, addr, WLAN_REASON_PREV_AUTH_NOT_VALID);
396 hostapd_free_stas(hapd);
403 * hostapd_validate_bssid_configuration - Validate BSSID configuration
404 * @iface: Pointer to interface data
405 * Returns: 0 on success, -1 on failure
407 * This function is used to validate that the configured BSSIDs are valid.
409 static int hostapd_validate_bssid_configuration(struct hostapd_iface *iface)
411 u8 mask[ETH_ALEN] = { 0 };
412 struct hostapd_data *hapd = iface->bss[0];
413 unsigned int i = iface->conf->num_bss, bits = 0, j;
416 if (hostapd_drv_none(hapd))
419 /* Generate BSSID mask that is large enough to cover the BSSIDs. */
421 /* Determine the bits necessary to cover the number of BSSIDs. */
422 for (i--; i; i >>= 1)
425 /* Determine the bits necessary to any configured BSSIDs,
426 if they are higher than the number of BSSIDs. */
427 for (j = 0; j < iface->conf->num_bss; j++) {
428 if (hostapd_mac_comp_empty(iface->conf->bss[j].bssid) == 0) {
434 for (i = 0; i < ETH_ALEN; i++) {
436 iface->conf->bss[j].bssid[i] ^
444 for (i = 0; i < ETH_ALEN && mask[i] == 0; i++)
450 while (mask[i] != 0) {
460 wpa_printf(MSG_ERROR, "Too many bits in the BSSID mask (%u)",
465 os_memset(mask, 0xff, ETH_ALEN);
467 for (i = 5; i > 5 - j; i--)
474 wpa_printf(MSG_DEBUG, "BSS count %lu, BSSID mask " MACSTR " (%d bits)",
475 (unsigned long) iface->conf->num_bss, MAC2STR(mask), bits);
480 for (i = 0; i < ETH_ALEN; i++) {
481 if ((hapd->own_addr[i] & mask[i]) != hapd->own_addr[i]) {
482 wpa_printf(MSG_ERROR, "Invalid BSSID mask " MACSTR
483 " for start address " MACSTR ".",
484 MAC2STR(mask), MAC2STR(hapd->own_addr));
485 wpa_printf(MSG_ERROR, "Start address must be the "
486 "first address in the block (i.e., addr "
487 "AND mask == addr).");
496 static int mac_in_conf(struct hostapd_config *conf, const void *a)
500 for (i = 0; i < conf->num_bss; i++) {
501 if (hostapd_mac_comp(conf->bss[i].bssid, a) == 0) {
513 * hostapd_setup_bss - Per-BSS setup (initialization)
514 * @hapd: Pointer to BSS data
515 * @first: Whether this BSS is the first BSS of an interface
517 * This function is used to initialize all per-BSS data structures and
518 * resources. This gets called in a loop for each BSS when an interface is
519 * initialized. Most of the modules that are initialized here will be
520 * deinitialized in hostapd_cleanup().
522 static int hostapd_setup_bss(struct hostapd_data *hapd, int first)
524 struct hostapd_bss_config *conf = hapd->conf;
525 u8 ssid[HOSTAPD_MAX_SSID_LEN + 1];
526 int ssid_len, set_ssid;
527 char force_ifname[IFNAMSIZ];
528 u8 if_addr[ETH_ALEN];
531 if (hostapd_mac_comp_empty(hapd->conf->bssid) == 0) {
532 /* Allocate the next available BSSID. */
534 inc_byte_array(hapd->own_addr, ETH_ALEN);
535 } while (mac_in_conf(hapd->iconf, hapd->own_addr));
537 /* Allocate the configured BSSID. */
538 os_memcpy(hapd->own_addr, hapd->conf->bssid, ETH_ALEN);
540 if (hostapd_mac_comp(hapd->own_addr,
541 hapd->iface->bss[0]->own_addr) ==
543 wpa_printf(MSG_ERROR, "BSS '%s' may not have "
544 "BSSID set to the MAC address of "
545 "the radio", hapd->conf->iface);
550 hapd->interface_added = 1;
551 if (hostapd_if_add(hapd->iface->bss[0], WPA_IF_AP_BSS,
552 hapd->conf->iface, hapd->own_addr, hapd,
553 &hapd->drv_priv, force_ifname, if_addr,
554 hapd->conf->bridge[0] ? hapd->conf->bridge :
556 wpa_printf(MSG_ERROR, "Failed to add BSS (BSSID="
557 MACSTR ")", MAC2STR(hapd->own_addr));
562 if (conf->wmm_enabled < 0)
563 conf->wmm_enabled = hapd->iconf->ieee80211n;
565 hostapd_flush_old_stations(hapd);
566 hostapd_set_privacy(hapd, 0);
568 hostapd_broadcast_wep_clear(hapd);
569 if (hostapd_setup_encryption(hapd->conf->iface, hapd))
573 * Fetch the SSID from the system and use it or,
574 * if one was specified in the config file, verify they
577 ssid_len = hostapd_get_ssid(hapd, ssid, sizeof(ssid));
579 wpa_printf(MSG_ERROR, "Could not read SSID from system");
582 if (conf->ssid.ssid_set) {
584 * If SSID is specified in the config file and it differs
585 * from what is being used then force installation of the
588 set_ssid = (conf->ssid.ssid_len != (size_t) ssid_len ||
589 os_memcmp(conf->ssid.ssid, ssid, ssid_len) != 0);
592 * No SSID in the config file; just use the one we got
596 conf->ssid.ssid_len = ssid_len;
597 os_memcpy(conf->ssid.ssid, ssid, conf->ssid.ssid_len);
598 conf->ssid.ssid[conf->ssid.ssid_len] = '\0';
601 if (!hostapd_drv_none(hapd)) {
602 wpa_printf(MSG_ERROR, "Using interface %s with hwaddr " MACSTR
604 hapd->conf->iface, MAC2STR(hapd->own_addr),
605 hapd->conf->ssid.ssid);
608 if (hostapd_setup_wpa_psk(conf)) {
609 wpa_printf(MSG_ERROR, "WPA-PSK setup failed.");
613 /* Set SSID for the kernel driver (to be used in beacon and probe
614 * response frames) */
615 if (set_ssid && hostapd_set_ssid(hapd, (u8 *) conf->ssid.ssid,
616 conf->ssid.ssid_len)) {
617 wpa_printf(MSG_ERROR, "Could not set SSID for kernel driver");
621 if (wpa_debug_level == MSG_MSGDUMP)
622 conf->radius->msg_dumps = 1;
623 #ifndef CONFIG_NO_RADIUS
624 hapd->radius = radius_client_init(hapd, conf->radius);
625 if (hapd->radius == NULL) {
626 wpa_printf(MSG_ERROR, "RADIUS client initialization failed.");
629 #endif /* CONFIG_NO_RADIUS */
631 if (hostapd_acl_init(hapd)) {
632 wpa_printf(MSG_ERROR, "ACL initialization failed.");
635 if (hostapd_init_wps(hapd, conf))
638 if (authsrv_init(hapd) < 0)
641 if (ieee802_1x_init(hapd)) {
642 wpa_printf(MSG_ERROR, "IEEE 802.1X initialization failed.");
646 if (hapd->conf->wpa && hostapd_setup_wpa(hapd))
649 if (accounting_init(hapd)) {
650 wpa_printf(MSG_ERROR, "Accounting initialization failed.");
654 if (hapd->conf->ieee802_11f &&
655 (hapd->iapp = iapp_init(hapd, hapd->conf->iapp_iface)) == NULL) {
656 wpa_printf(MSG_ERROR, "IEEE 802.11F (IAPP) initialization "
661 #ifdef CONFIG_INTERWORKING
662 if (gas_serv_init(hapd)) {
663 wpa_printf(MSG_ERROR, "GAS server initialization failed");
666 #endif /* CONFIG_INTERWORKING */
668 if (hapd->iface->ctrl_iface_init &&
669 hapd->iface->ctrl_iface_init(hapd)) {
670 wpa_printf(MSG_ERROR, "Failed to setup control interface");
674 if (!hostapd_drv_none(hapd) && vlan_init(hapd)) {
675 wpa_printf(MSG_ERROR, "VLAN initialization failed.");
679 ieee802_11_set_beacon(hapd);
681 if (hapd->wpa_auth && wpa_init_keys(hapd->wpa_auth) < 0)
684 if (hapd->driver && hapd->driver->set_operstate)
685 hapd->driver->set_operstate(hapd->drv_priv, 1);
691 static void hostapd_tx_queue_params(struct hostapd_iface *iface)
693 struct hostapd_data *hapd = iface->bss[0];
695 struct hostapd_tx_queue_params *p;
697 for (i = 0; i < NUM_TX_QUEUES; i++) {
698 p = &iface->conf->tx_queue[i];
700 if (hostapd_set_tx_queue_params(hapd, i, p->aifs, p->cwmin,
701 p->cwmax, p->burst)) {
702 wpa_printf(MSG_DEBUG, "Failed to set TX queue "
703 "parameters for queue %d.", i);
704 /* Continue anyway */
710 static int setup_interface(struct hostapd_iface *iface)
712 struct hostapd_data *hapd = iface->bss[0];
717 * Make sure that all BSSes get configured with a pointer to the same
720 for (i = 1; i < iface->num_bss; i++) {
721 iface->bss[i]->driver = hapd->driver;
722 iface->bss[i]->drv_priv = hapd->drv_priv;
725 if (hostapd_validate_bssid_configuration(iface))
728 if (hapd->iconf->country[0] && hapd->iconf->country[1]) {
729 os_memcpy(country, hapd->iconf->country, 3);
731 if (hostapd_set_country(hapd, country) < 0) {
732 wpa_printf(MSG_ERROR, "Failed to set country code");
737 if (hostapd_get_hw_features(iface)) {
738 /* Not all drivers support this yet, so continue without hw
741 int ret = hostapd_select_hw_mode(iface);
743 wpa_printf(MSG_ERROR, "Could not select hw_mode and "
744 "channel. (%d)", ret);
747 ret = hostapd_check_ht_capab(iface);
751 wpa_printf(MSG_DEBUG, "Interface initialization will "
752 "be completed in a callback");
756 return hostapd_setup_interface_complete(iface, 0);
760 int hostapd_setup_interface_complete(struct hostapd_iface *iface, int err)
762 struct hostapd_data *hapd = iface->bss[0];
767 wpa_printf(MSG_ERROR, "Interface initialization failed");
772 wpa_printf(MSG_DEBUG, "Completing interface initialization");
773 if (hapd->iconf->channel) {
774 iface->freq = hostapd_hw_get_freq(hapd, hapd->iconf->channel);
775 wpa_printf(MSG_DEBUG, "Mode: %s Channel: %d "
777 hostapd_hw_mode_txt(hapd->iconf->hw_mode),
778 hapd->iconf->channel, iface->freq);
780 if (hostapd_set_freq(hapd, hapd->iconf->hw_mode, iface->freq,
781 hapd->iconf->channel,
782 hapd->iconf->ieee80211n,
783 hapd->iconf->secondary_channel)) {
784 wpa_printf(MSG_ERROR, "Could not set channel for "
790 if (iface->current_mode) {
791 if (hostapd_prepare_rates(iface, iface->current_mode)) {
792 wpa_printf(MSG_ERROR, "Failed to prepare rates "
794 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
795 HOSTAPD_LEVEL_WARNING,
796 "Failed to prepare rates table.");
801 if (hapd->iconf->rts_threshold > -1 &&
802 hostapd_set_rts(hapd, hapd->iconf->rts_threshold)) {
803 wpa_printf(MSG_ERROR, "Could not set RTS threshold for "
808 if (hapd->iconf->fragm_threshold > -1 &&
809 hostapd_set_frag(hapd, hapd->iconf->fragm_threshold)) {
810 wpa_printf(MSG_ERROR, "Could not set fragmentation threshold "
811 "for kernel driver");
815 prev_addr = hapd->own_addr;
817 for (j = 0; j < iface->num_bss; j++) {
818 hapd = iface->bss[j];
820 os_memcpy(hapd->own_addr, prev_addr, ETH_ALEN);
821 if (hostapd_setup_bss(hapd, j == 0))
823 if (hostapd_mac_comp_empty(hapd->conf->bssid) == 0)
824 prev_addr = hapd->own_addr;
827 hostapd_tx_queue_params(iface);
831 if (hostapd_driver_commit(hapd) < 0) {
832 wpa_printf(MSG_ERROR, "%s: Failed to commit driver "
833 "configuration", __func__);
838 * WPS UPnP module can be initialized only when the "upnp_iface" is up.
839 * If "interface" and "upnp_iface" are the same (e.g., non-bridge
840 * mode), the interface is up only after driver_commit, so initialize
841 * WPS after driver_commit.
843 for (j = 0; j < iface->num_bss; j++) {
844 if (hostapd_init_wps_complete(iface->bss[j]))
848 if (hapd->setup_complete_cb)
849 hapd->setup_complete_cb(hapd->setup_complete_cb_ctx);
851 wpa_printf(MSG_DEBUG, "%s: Setup of interface done.",
852 iface->bss[0]->conf->iface);
859 * hostapd_setup_interface - Setup of an interface
860 * @iface: Pointer to interface data.
861 * Returns: 0 on success, -1 on failure
863 * Initializes the driver interface, validates the configuration,
864 * and sets driver parameters based on the configuration.
865 * Flushes old stations, sets the channel, encryption,
866 * beacons, and WDS links based on the configuration.
868 int hostapd_setup_interface(struct hostapd_iface *iface)
872 ret = setup_interface(iface);
874 wpa_printf(MSG_ERROR, "%s: Unable to setup interface.",
875 iface->bss[0]->conf->iface);
884 * hostapd_alloc_bss_data - Allocate and initialize per-BSS data
885 * @hapd_iface: Pointer to interface data
886 * @conf: Pointer to per-interface configuration
887 * @bss: Pointer to per-BSS configuration for this BSS
888 * Returns: Pointer to allocated BSS data
890 * This function is used to allocate per-BSS data structure. This data will be
891 * freed after hostapd_cleanup() is called for it during interface
894 struct hostapd_data *
895 hostapd_alloc_bss_data(struct hostapd_iface *hapd_iface,
896 struct hostapd_config *conf,
897 struct hostapd_bss_config *bss)
899 struct hostapd_data *hapd;
901 hapd = os_zalloc(sizeof(*hapd));
905 hapd->new_assoc_sta_cb = hostapd_new_assoc_sta;
908 hapd->iface = hapd_iface;
909 hapd->driver = hapd->iconf->driver;
910 hapd->ctrl_sock = -1;
916 void hostapd_interface_deinit(struct hostapd_iface *iface)
923 hostapd_cleanup_iface_pre(iface);
924 for (j = 0; j < iface->num_bss; j++) {
925 struct hostapd_data *hapd = iface->bss[j];
926 hostapd_free_stas(hapd);
927 hostapd_flush_old_stations(hapd);
928 hostapd_clear_wep(hapd);
929 hostapd_cleanup(hapd);
934 void hostapd_interface_free(struct hostapd_iface *iface)
937 for (j = 0; j < iface->num_bss; j++)
938 os_free(iface->bss[j]);
939 hostapd_cleanup_iface(iface);
944 * hostapd_new_assoc_sta - Notify that a new station associated with the AP
945 * @hapd: Pointer to BSS data
946 * @sta: Pointer to the associated STA data
947 * @reassoc: 1 to indicate this was a re-association; 0 = first association
949 * This function will be called whenever a station associates with the AP. It
950 * can be called from ieee802_11.c for drivers that export MLME to hostapd and
951 * from drv_callbacks.c based on driver events for drivers that take care of
952 * management frames (IEEE 802.11 authentication and association) internally.
954 void hostapd_new_assoc_sta(struct hostapd_data *hapd, struct sta_info *sta,
957 if (hapd->tkip_countermeasures) {
958 hostapd_drv_sta_deauth(hapd, sta->addr,
959 WLAN_REASON_MICHAEL_MIC_FAILURE);
963 hostapd_prune_associations(hapd, sta->addr);
965 /* IEEE 802.11F (IAPP) */
966 if (hapd->conf->ieee802_11f)
967 iapp_new_station(hapd->iapp, sta);
970 if (sta->p2p_ie == NULL && !sta->no_p2p_set) {
972 hapd->num_sta_no_p2p++;
973 if (hapd->num_sta_no_p2p == 1)
974 hostapd_p2p_non_p2p_sta_connected(hapd);
976 #endif /* CONFIG_P2P */
978 /* Start accounting here, if IEEE 802.1X and WPA are not used.
979 * IEEE 802.1X/WPA code will start accounting after the station has
980 * been authorized. */
981 if (!hapd->conf->ieee802_1x && !hapd->conf->wpa)
982 accounting_sta_start(hapd, sta);
984 /* Start IEEE 802.1X authentication process for new stations */
985 ieee802_1x_new_station(hapd, sta);
987 if (sta->auth_alg != WLAN_AUTH_FT &&
988 !(sta->flags & (WLAN_STA_WPS | WLAN_STA_MAYBE_WPS)))
989 wpa_auth_sm_event(sta->wpa_sm, WPA_REAUTH);
991 wpa_auth_sta_associated(hapd->wpa_auth, sta->wpa_sm);