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"
35 static int hostapd_flush_old_stations(struct hostapd_data *hapd);
36 static int hostapd_setup_encryption(char *iface, struct hostapd_data *hapd);
37 static int hostapd_broadcast_wep_clear(struct hostapd_data *hapd);
39 extern int wpa_debug_level;
42 static void hostapd_reload_bss(struct hostapd_data *hapd)
44 #ifndef CONFIG_NO_RADIUS
45 radius_client_reconfig(hapd->radius, hapd->conf->radius);
46 #endif /* CONFIG_NO_RADIUS */
48 if (hostapd_setup_wpa_psk(hapd->conf)) {
49 wpa_printf(MSG_ERROR, "Failed to re-configure WPA PSK "
50 "after reloading configuration");
53 if (hapd->conf->ieee802_1x || hapd->conf->wpa)
54 hostapd_set_drv_ieee8021x(hapd, hapd->conf->iface, 1);
56 hostapd_set_drv_ieee8021x(hapd, hapd->conf->iface, 0);
58 if (hapd->conf->wpa && hapd->wpa_auth == NULL) {
59 hostapd_setup_wpa(hapd);
61 wpa_init_keys(hapd->wpa_auth);
62 } else if (hapd->conf->wpa) {
65 hostapd_reconfig_wpa(hapd);
66 wpa_ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &wpa_ie_len);
67 if (hostapd_set_generic_elem(hapd, wpa_ie, wpa_ie_len))
68 wpa_printf(MSG_ERROR, "Failed to configure WPA IE for "
69 "the kernel driver.");
70 } else if (hapd->wpa_auth) {
71 wpa_deinit(hapd->wpa_auth);
72 hapd->wpa_auth = NULL;
73 hostapd_set_privacy(hapd, 0);
74 hostapd_setup_encryption(hapd->conf->iface, hapd);
75 hostapd_set_generic_elem(hapd, (u8 *) "", 0);
78 ieee802_11_set_beacon(hapd);
79 hostapd_update_wps(hapd);
81 if (hapd->conf->ssid.ssid_set &&
82 hostapd_set_ssid(hapd, (u8 *) hapd->conf->ssid.ssid,
83 hapd->conf->ssid.ssid_len)) {
84 wpa_printf(MSG_ERROR, "Could not set SSID for kernel driver");
87 wpa_printf(MSG_DEBUG, "Reconfigured interface %s", hapd->conf->iface);
91 int hostapd_reload_config(struct hostapd_iface *iface)
93 struct hostapd_data *hapd = iface->bss[0];
94 struct hostapd_config *newconf, *oldconf;
97 if (iface->config_read_cb == NULL)
99 newconf = iface->config_read_cb(iface->config_fname);
104 * Deauthenticate all stations since the new configuration may not
105 * allow them to use the BSS anymore.
107 for (j = 0; j < iface->num_bss; j++) {
108 hostapd_flush_old_stations(iface->bss[j]);
109 hostapd_broadcast_wep_clear(iface->bss[j]);
111 #ifndef CONFIG_NO_RADIUS
112 /* TODO: update dynamic data based on changed configuration
113 * items (e.g., open/close sockets, etc.) */
114 radius_client_flush(iface->bss[j]->radius, 0);
115 #endif /* CONFIG_NO_RADIUS */
118 oldconf = hapd->iconf;
119 iface->conf = newconf;
121 for (j = 0; j < iface->num_bss; j++) {
122 hapd = iface->bss[j];
123 hapd->iconf = newconf;
124 hapd->conf = &newconf->bss[j];
125 hostapd_reload_bss(hapd);
128 hostapd_config_free(oldconf);
135 static void hostapd_broadcast_key_clear_iface(struct hostapd_data *hapd,
140 for (i = 0; i < NUM_WEP_KEYS; i++) {
141 if (hostapd_drv_set_key(ifname, hapd, WPA_ALG_NONE, NULL, i,
142 0, NULL, 0, NULL, 0)) {
143 wpa_printf(MSG_DEBUG, "Failed to clear default "
144 "encryption keys (ifname=%s keyidx=%d)",
148 #ifdef CONFIG_IEEE80211W
149 if (hapd->conf->ieee80211w) {
150 for (i = NUM_WEP_KEYS; i < NUM_WEP_KEYS + 2; i++) {
151 if (hostapd_drv_set_key(ifname, hapd, WPA_ALG_NONE,
154 wpa_printf(MSG_DEBUG, "Failed to clear "
155 "default mgmt encryption keys "
156 "(ifname=%s keyidx=%d)", ifname, i);
160 #endif /* CONFIG_IEEE80211W */
164 static int hostapd_broadcast_wep_clear(struct hostapd_data *hapd)
166 hostapd_broadcast_key_clear_iface(hapd, hapd->conf->iface);
171 static int hostapd_broadcast_wep_set(struct hostapd_data *hapd)
174 struct hostapd_ssid *ssid = &hapd->conf->ssid;
177 if (ssid->wep.default_len &&
178 hostapd_drv_set_key(hapd->conf->iface,
179 hapd, WPA_ALG_WEP, broadcast_ether_addr, idx,
180 1, NULL, 0, ssid->wep.key[idx],
181 ssid->wep.len[idx])) {
182 wpa_printf(MSG_WARNING, "Could not set WEP encryption.");
186 if (ssid->dyn_vlan_keys) {
188 for (i = 0; i <= ssid->max_dyn_vlan_keys; i++) {
190 struct hostapd_wep_keys *key = ssid->dyn_vlan_keys[i];
193 ifname = hostapd_get_vlan_id_ifname(hapd->conf->vlan,
199 if (hostapd_drv_set_key(ifname, hapd, WPA_ALG_WEP,
200 broadcast_ether_addr, idx, 1,
201 NULL, 0, key->key[idx],
203 wpa_printf(MSG_WARNING, "Could not set "
204 "dynamic VLAN WEP encryption.");
214 * hostapd_cleanup - Per-BSS cleanup (deinitialization)
215 * @hapd: Pointer to BSS data
217 * This function is used to free all per-BSS data structures and resources.
218 * This gets called in a loop for each BSS between calls to
219 * hostapd_cleanup_iface_pre() and hostapd_cleanup_iface() when an interface
220 * is deinitialized. Most of the modules that are initialized in
221 * hostapd_setup_bss() are deinitialized here.
223 static void hostapd_cleanup(struct hostapd_data *hapd)
225 if (hapd->iface->ctrl_iface_deinit)
226 hapd->iface->ctrl_iface_deinit(hapd);
228 iapp_deinit(hapd->iapp);
230 accounting_deinit(hapd);
231 hostapd_deinit_wpa(hapd);
233 hostapd_acl_deinit(hapd);
234 #ifndef CONFIG_NO_RADIUS
235 radius_client_deinit(hapd->radius);
237 #endif /* CONFIG_NO_RADIUS */
239 hostapd_deinit_wps(hapd);
241 authsrv_deinit(hapd);
243 if (hapd->interface_added &&
244 hostapd_if_remove(hapd, WPA_IF_AP_BSS, hapd->conf->iface)) {
245 wpa_printf(MSG_WARNING, "Failed to remove BSS interface %s",
249 os_free(hapd->probereq_cb);
250 hapd->probereq_cb = NULL;
253 wpabuf_free(hapd->p2p_beacon_ie);
254 hapd->p2p_beacon_ie = NULL;
255 wpabuf_free(hapd->p2p_probe_resp_ie);
256 hapd->p2p_probe_resp_ie = NULL;
257 #endif /* CONFIG_P2P */
259 wpabuf_free(hapd->time_adv);
264 * hostapd_cleanup_iface_pre - Preliminary per-interface cleanup
265 * @iface: Pointer to interface data
267 * This function is called before per-BSS data structures are deinitialized
268 * with hostapd_cleanup().
270 static void hostapd_cleanup_iface_pre(struct hostapd_iface *iface)
276 * hostapd_cleanup_iface - Complete per-interface cleanup
277 * @iface: Pointer to interface data
279 * This function is called after per-BSS data structures are deinitialized
280 * with hostapd_cleanup().
282 static void hostapd_cleanup_iface(struct hostapd_iface *iface)
284 hostapd_free_hw_features(iface->hw_features, iface->num_hw_features);
285 iface->hw_features = NULL;
286 os_free(iface->current_rates);
287 iface->current_rates = NULL;
288 os_free(iface->basic_rates);
289 iface->basic_rates = NULL;
290 ap_list_deinit(iface);
291 hostapd_config_free(iface->conf);
294 os_free(iface->config_fname);
300 static int hostapd_setup_encryption(char *iface, struct hostapd_data *hapd)
304 hostapd_broadcast_wep_set(hapd);
306 if (hapd->conf->ssid.wep.default_len) {
307 hostapd_set_privacy(hapd, 1);
312 * When IEEE 802.1X is not enabled, the driver may need to know how to
313 * set authentication algorithms for static WEP.
315 hostapd_drv_set_authmode(hapd, hapd->conf->auth_algs);
317 for (i = 0; i < 4; i++) {
318 if (hapd->conf->ssid.wep.key[i] &&
319 hostapd_drv_set_key(iface, hapd, WPA_ALG_WEP, NULL, i,
320 i == hapd->conf->ssid.wep.idx, NULL, 0,
321 hapd->conf->ssid.wep.key[i],
322 hapd->conf->ssid.wep.len[i])) {
323 wpa_printf(MSG_WARNING, "Could not set WEP "
327 if (hapd->conf->ssid.wep.key[i] &&
328 i == hapd->conf->ssid.wep.idx)
329 hostapd_set_privacy(hapd, 1);
336 static int hostapd_flush_old_stations(struct hostapd_data *hapd)
341 if (hostapd_drv_none(hapd) || hapd->drv_priv == NULL)
344 wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "Flushing old station entries");
345 if (hostapd_flush(hapd)) {
346 wpa_msg(hapd->msg_ctx, MSG_WARNING, "Could not connect to "
350 wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "Deauthenticate all stations");
351 os_memset(addr, 0xff, ETH_ALEN);
352 hostapd_drv_sta_deauth(hapd, addr, WLAN_REASON_PREV_AUTH_NOT_VALID);
353 hostapd_free_stas(hapd);
360 * hostapd_validate_bssid_configuration - Validate BSSID configuration
361 * @iface: Pointer to interface data
362 * Returns: 0 on success, -1 on failure
364 * This function is used to validate that the configured BSSIDs are valid.
366 static int hostapd_validate_bssid_configuration(struct hostapd_iface *iface)
368 u8 mask[ETH_ALEN] = { 0 };
369 struct hostapd_data *hapd = iface->bss[0];
370 unsigned int i = iface->conf->num_bss, bits = 0, j;
373 if (hostapd_drv_none(hapd))
376 /* Generate BSSID mask that is large enough to cover the BSSIDs. */
378 /* Determine the bits necessary to cover the number of BSSIDs. */
379 for (i--; i; i >>= 1)
382 /* Determine the bits necessary to any configured BSSIDs,
383 if they are higher than the number of BSSIDs. */
384 for (j = 0; j < iface->conf->num_bss; j++) {
385 if (hostapd_mac_comp_empty(iface->conf->bss[j].bssid) == 0) {
391 for (i = 0; i < ETH_ALEN; i++) {
393 iface->conf->bss[j].bssid[i] ^
401 for (i = 0; i < ETH_ALEN && mask[i] == 0; i++)
407 while (mask[i] != 0) {
417 wpa_printf(MSG_ERROR, "Too many bits in the BSSID mask (%u)",
422 os_memset(mask, 0xff, ETH_ALEN);
424 for (i = 5; i > 5 - j; i--)
431 wpa_printf(MSG_DEBUG, "BSS count %lu, BSSID mask " MACSTR " (%d bits)",
432 (unsigned long) iface->conf->num_bss, MAC2STR(mask), bits);
437 for (i = 0; i < ETH_ALEN; i++) {
438 if ((hapd->own_addr[i] & mask[i]) != hapd->own_addr[i]) {
439 wpa_printf(MSG_ERROR, "Invalid BSSID mask " MACSTR
440 " for start address " MACSTR ".",
441 MAC2STR(mask), MAC2STR(hapd->own_addr));
442 wpa_printf(MSG_ERROR, "Start address must be the "
443 "first address in the block (i.e., addr "
444 "AND mask == addr).");
453 static int mac_in_conf(struct hostapd_config *conf, const void *a)
457 for (i = 0; i < conf->num_bss; i++) {
458 if (hostapd_mac_comp(conf->bss[i].bssid, a) == 0) {
470 * hostapd_setup_bss - Per-BSS setup (initialization)
471 * @hapd: Pointer to BSS data
472 * @first: Whether this BSS is the first BSS of an interface
474 * This function is used to initialize all per-BSS data structures and
475 * resources. This gets called in a loop for each BSS when an interface is
476 * initialized. Most of the modules that are initialized here will be
477 * deinitialized in hostapd_cleanup().
479 static int hostapd_setup_bss(struct hostapd_data *hapd, int first)
481 struct hostapd_bss_config *conf = hapd->conf;
482 u8 ssid[HOSTAPD_MAX_SSID_LEN + 1];
483 int ssid_len, set_ssid;
484 char force_ifname[IFNAMSIZ];
485 u8 if_addr[ETH_ALEN];
488 if (hostapd_mac_comp_empty(hapd->conf->bssid) == 0) {
489 /* Allocate the next available BSSID. */
491 inc_byte_array(hapd->own_addr, ETH_ALEN);
492 } while (mac_in_conf(hapd->iconf, hapd->own_addr));
494 /* Allocate the configured BSSID. */
495 os_memcpy(hapd->own_addr, hapd->conf->bssid, ETH_ALEN);
497 if (hostapd_mac_comp(hapd->own_addr,
498 hapd->iface->bss[0]->own_addr) ==
500 wpa_printf(MSG_ERROR, "BSS '%s' may not have "
501 "BSSID set to the MAC address of "
502 "the radio", hapd->conf->iface);
507 hapd->interface_added = 1;
508 if (hostapd_if_add(hapd->iface->bss[0], WPA_IF_AP_BSS,
509 hapd->conf->iface, hapd->own_addr, hapd,
510 &hapd->drv_priv, force_ifname, if_addr,
511 hapd->conf->bridge[0] ? hapd->conf->bridge :
513 wpa_printf(MSG_ERROR, "Failed to add BSS (BSSID="
514 MACSTR ")", MAC2STR(hapd->own_addr));
519 if (conf->wmm_enabled < 0)
520 conf->wmm_enabled = hapd->iconf->ieee80211n;
522 hostapd_flush_old_stations(hapd);
523 hostapd_set_privacy(hapd, 0);
525 hostapd_broadcast_wep_clear(hapd);
526 if (hostapd_setup_encryption(hapd->conf->iface, hapd))
530 * Fetch the SSID from the system and use it or,
531 * if one was specified in the config file, verify they
534 ssid_len = hostapd_get_ssid(hapd, ssid, sizeof(ssid));
536 wpa_printf(MSG_ERROR, "Could not read SSID from system");
539 if (conf->ssid.ssid_set) {
541 * If SSID is specified in the config file and it differs
542 * from what is being used then force installation of the
545 set_ssid = (conf->ssid.ssid_len != (size_t) ssid_len ||
546 os_memcmp(conf->ssid.ssid, ssid, ssid_len) != 0);
549 * No SSID in the config file; just use the one we got
553 conf->ssid.ssid_len = ssid_len;
554 os_memcpy(conf->ssid.ssid, ssid, conf->ssid.ssid_len);
555 conf->ssid.ssid[conf->ssid.ssid_len] = '\0';
558 if (!hostapd_drv_none(hapd)) {
559 wpa_printf(MSG_ERROR, "Using interface %s with hwaddr " MACSTR
561 hapd->conf->iface, MAC2STR(hapd->own_addr),
562 hapd->conf->ssid.ssid);
565 if (hostapd_setup_wpa_psk(conf)) {
566 wpa_printf(MSG_ERROR, "WPA-PSK setup failed.");
570 /* Set SSID for the kernel driver (to be used in beacon and probe
571 * response frames) */
572 if (set_ssid && hostapd_set_ssid(hapd, (u8 *) conf->ssid.ssid,
573 conf->ssid.ssid_len)) {
574 wpa_printf(MSG_ERROR, "Could not set SSID for kernel driver");
578 if (wpa_debug_level == MSG_MSGDUMP)
579 conf->radius->msg_dumps = 1;
580 #ifndef CONFIG_NO_RADIUS
581 hapd->radius = radius_client_init(hapd, conf->radius);
582 if (hapd->radius == NULL) {
583 wpa_printf(MSG_ERROR, "RADIUS client initialization failed.");
586 #endif /* CONFIG_NO_RADIUS */
588 if (hostapd_acl_init(hapd)) {
589 wpa_printf(MSG_ERROR, "ACL initialization failed.");
592 if (hostapd_init_wps(hapd, conf))
595 if (authsrv_init(hapd) < 0)
598 if (ieee802_1x_init(hapd)) {
599 wpa_printf(MSG_ERROR, "IEEE 802.1X initialization failed.");
603 if (hapd->conf->wpa && hostapd_setup_wpa(hapd))
606 if (accounting_init(hapd)) {
607 wpa_printf(MSG_ERROR, "Accounting initialization failed.");
611 if (hapd->conf->ieee802_11f &&
612 (hapd->iapp = iapp_init(hapd, hapd->conf->iapp_iface)) == NULL) {
613 wpa_printf(MSG_ERROR, "IEEE 802.11F (IAPP) initialization "
618 if (hapd->iface->ctrl_iface_init &&
619 hapd->iface->ctrl_iface_init(hapd)) {
620 wpa_printf(MSG_ERROR, "Failed to setup control interface");
624 if (!hostapd_drv_none(hapd) && vlan_init(hapd)) {
625 wpa_printf(MSG_ERROR, "VLAN initialization failed.");
629 ieee802_11_set_beacon(hapd);
631 if (hapd->wpa_auth && wpa_init_keys(hapd->wpa_auth) < 0)
634 if (hapd->driver && hapd->driver->set_operstate)
635 hapd->driver->set_operstate(hapd->drv_priv, 1);
641 static void hostapd_tx_queue_params(struct hostapd_iface *iface)
643 struct hostapd_data *hapd = iface->bss[0];
645 struct hostapd_tx_queue_params *p;
647 for (i = 0; i < NUM_TX_QUEUES; i++) {
648 p = &iface->conf->tx_queue[i];
650 if (hostapd_set_tx_queue_params(hapd, i, p->aifs, p->cwmin,
651 p->cwmax, p->burst)) {
652 wpa_printf(MSG_DEBUG, "Failed to set TX queue "
653 "parameters for queue %d.", i);
654 /* Continue anyway */
660 static int setup_interface(struct hostapd_iface *iface)
662 struct hostapd_data *hapd = iface->bss[0];
667 * Make sure that all BSSes get configured with a pointer to the same
670 for (i = 1; i < iface->num_bss; i++) {
671 iface->bss[i]->driver = hapd->driver;
672 iface->bss[i]->drv_priv = hapd->drv_priv;
675 if (hostapd_validate_bssid_configuration(iface))
678 if (hapd->iconf->country[0] && hapd->iconf->country[1]) {
679 os_memcpy(country, hapd->iconf->country, 3);
681 if (hostapd_set_country(hapd, country) < 0) {
682 wpa_printf(MSG_ERROR, "Failed to set country code");
687 if (hostapd_get_hw_features(iface)) {
688 /* Not all drivers support this yet, so continue without hw
691 int ret = hostapd_select_hw_mode(iface);
693 wpa_printf(MSG_ERROR, "Could not select hw_mode and "
694 "channel. (%d)", ret);
697 ret = hostapd_check_ht_capab(iface);
701 wpa_printf(MSG_DEBUG, "Interface initialization will "
702 "be completed in a callback");
706 return hostapd_setup_interface_complete(iface, 0);
710 int hostapd_setup_interface_complete(struct hostapd_iface *iface, int err)
712 struct hostapd_data *hapd = iface->bss[0];
717 wpa_printf(MSG_ERROR, "Interface initialization failed");
722 wpa_printf(MSG_DEBUG, "Completing interface initialization");
723 if (hapd->iconf->channel) {
724 iface->freq = hostapd_hw_get_freq(hapd, hapd->iconf->channel);
725 wpa_printf(MSG_DEBUG, "Mode: %s Channel: %d "
727 hostapd_hw_mode_txt(hapd->iconf->hw_mode),
728 hapd->iconf->channel, iface->freq);
730 if (hostapd_set_freq(hapd, hapd->iconf->hw_mode, iface->freq,
731 hapd->iconf->channel,
732 hapd->iconf->ieee80211n,
733 hapd->iconf->secondary_channel)) {
734 wpa_printf(MSG_ERROR, "Could not set channel for "
740 if (iface->current_mode) {
741 if (hostapd_prepare_rates(iface, iface->current_mode)) {
742 wpa_printf(MSG_ERROR, "Failed to prepare rates "
744 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
745 HOSTAPD_LEVEL_WARNING,
746 "Failed to prepare rates table.");
751 if (hapd->iconf->rts_threshold > -1 &&
752 hostapd_set_rts(hapd, hapd->iconf->rts_threshold)) {
753 wpa_printf(MSG_ERROR, "Could not set RTS threshold for "
758 if (hapd->iconf->fragm_threshold > -1 &&
759 hostapd_set_frag(hapd, hapd->iconf->fragm_threshold)) {
760 wpa_printf(MSG_ERROR, "Could not set fragmentation threshold "
761 "for kernel driver");
765 prev_addr = hapd->own_addr;
767 for (j = 0; j < iface->num_bss; j++) {
768 hapd = iface->bss[j];
770 os_memcpy(hapd->own_addr, prev_addr, ETH_ALEN);
771 if (hostapd_setup_bss(hapd, j == 0))
773 if (hostapd_mac_comp_empty(hapd->conf->bssid) == 0)
774 prev_addr = hapd->own_addr;
777 hostapd_tx_queue_params(iface);
781 if (hostapd_driver_commit(hapd) < 0) {
782 wpa_printf(MSG_ERROR, "%s: Failed to commit driver "
783 "configuration", __func__);
788 * WPS UPnP module can be initialized only when the "upnp_iface" is up.
789 * If "interface" and "upnp_iface" are the same (e.g., non-bridge
790 * mode), the interface is up only after driver_commit, so initialize
791 * WPS after driver_commit.
793 for (j = 0; j < iface->num_bss; j++) {
794 if (hostapd_init_wps_complete(iface->bss[j]))
798 if (hapd->setup_complete_cb)
799 hapd->setup_complete_cb(hapd->setup_complete_cb_ctx);
801 wpa_printf(MSG_DEBUG, "%s: Setup of interface done.",
802 iface->bss[0]->conf->iface);
809 * hostapd_setup_interface - Setup of an interface
810 * @iface: Pointer to interface data.
811 * Returns: 0 on success, -1 on failure
813 * Initializes the driver interface, validates the configuration,
814 * and sets driver parameters based on the configuration.
815 * Flushes old stations, sets the channel, encryption,
816 * beacons, and WDS links based on the configuration.
818 int hostapd_setup_interface(struct hostapd_iface *iface)
822 ret = setup_interface(iface);
824 wpa_printf(MSG_ERROR, "%s: Unable to setup interface.",
825 iface->bss[0]->conf->iface);
834 * hostapd_alloc_bss_data - Allocate and initialize per-BSS data
835 * @hapd_iface: Pointer to interface data
836 * @conf: Pointer to per-interface configuration
837 * @bss: Pointer to per-BSS configuration for this BSS
838 * Returns: Pointer to allocated BSS data
840 * This function is used to allocate per-BSS data structure. This data will be
841 * freed after hostapd_cleanup() is called for it during interface
844 struct hostapd_data *
845 hostapd_alloc_bss_data(struct hostapd_iface *hapd_iface,
846 struct hostapd_config *conf,
847 struct hostapd_bss_config *bss)
849 struct hostapd_data *hapd;
851 hapd = os_zalloc(sizeof(*hapd));
855 hapd->new_assoc_sta_cb = hostapd_new_assoc_sta;
858 hapd->iface = hapd_iface;
859 hapd->driver = hapd->iconf->driver;
860 hapd->ctrl_sock = -1;
866 void hostapd_interface_deinit(struct hostapd_iface *iface)
873 hostapd_cleanup_iface_pre(iface);
874 for (j = 0; j < iface->num_bss; j++) {
875 struct hostapd_data *hapd = iface->bss[j];
876 hostapd_free_stas(hapd);
877 hostapd_flush_old_stations(hapd);
878 hostapd_cleanup(hapd);
883 void hostapd_interface_free(struct hostapd_iface *iface)
886 for (j = 0; j < iface->num_bss; j++)
887 os_free(iface->bss[j]);
888 hostapd_cleanup_iface(iface);
893 * hostapd_new_assoc_sta - Notify that a new station associated with the AP
894 * @hapd: Pointer to BSS data
895 * @sta: Pointer to the associated STA data
896 * @reassoc: 1 to indicate this was a re-association; 0 = first association
898 * This function will be called whenever a station associates with the AP. It
899 * can be called from ieee802_11.c for drivers that export MLME to hostapd and
900 * from drv_callbacks.c based on driver events for drivers that take care of
901 * management frames (IEEE 802.11 authentication and association) internally.
903 void hostapd_new_assoc_sta(struct hostapd_data *hapd, struct sta_info *sta,
906 if (hapd->tkip_countermeasures) {
907 hostapd_drv_sta_deauth(hapd, sta->addr,
908 WLAN_REASON_MICHAEL_MIC_FAILURE);
912 hostapd_prune_associations(hapd, sta->addr);
914 /* IEEE 802.11F (IAPP) */
915 if (hapd->conf->ieee802_11f)
916 iapp_new_station(hapd->iapp, sta);
919 if (sta->p2p_ie == NULL && !sta->no_p2p_set) {
921 hapd->num_sta_no_p2p++;
922 if (hapd->num_sta_no_p2p == 1)
923 hostapd_p2p_non_p2p_sta_connected(hapd);
925 #endif /* CONFIG_P2P */
927 /* Start accounting here, if IEEE 802.1X and WPA are not used.
928 * IEEE 802.1X/WPA code will start accounting after the station has
929 * been authorized. */
930 if (!hapd->conf->ieee802_1x && !hapd->conf->wpa)
931 accounting_sta_start(hapd, sta);
933 /* Start IEEE 802.1X authentication process for new stations */
934 ieee802_1x_new_station(hapd, sta);
936 if (sta->auth_alg != WLAN_AUTH_FT &&
937 !(sta->flags & (WLAN_STA_WPS | WLAN_STA_MAYBE_WPS)))
938 wpa_auth_sm_event(sta->wpa_sm, WPA_REAUTH);
940 wpa_auth_sta_associated(hapd->wpa_auth, sta->wpa_sm);