2 * hostapd / Initialization and configuration
3 * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
15 #include "utils/includes.h"
17 #include "utils/common.h"
18 #include "utils/eloop.h"
19 #include "common/ieee802_11_defs.h"
20 #include "radius/radius_client.h"
21 #include "drivers/driver.h"
25 #include "accounting.h"
29 #include "ieee802_1x.h"
30 #include "ieee802_11_auth.h"
31 #include "vlan_init.h"
33 #include "wps_hostapd.h"
34 #include "hw_features.h"
35 #include "wpa_auth_glue.h"
36 #include "ap_drv_ops.h"
37 #include "ap_config.h"
38 #include "p2p_hostapd.h"
41 static int hostapd_flush_old_stations(struct hostapd_data *hapd);
42 static int hostapd_setup_encryption(char *iface, struct hostapd_data *hapd);
43 static int hostapd_broadcast_wep_clear(struct hostapd_data *hapd);
45 extern int wpa_debug_level;
48 static void hostapd_reload_bss(struct hostapd_data *hapd)
50 #ifndef CONFIG_NO_RADIUS
51 radius_client_reconfig(hapd->radius, hapd->conf->radius);
52 #endif /* CONFIG_NO_RADIUS */
54 if (hostapd_setup_wpa_psk(hapd->conf)) {
55 wpa_printf(MSG_ERROR, "Failed to re-configure WPA PSK "
56 "after reloading configuration");
59 if (hapd->conf->ieee802_1x || hapd->conf->wpa)
60 hostapd_set_drv_ieee8021x(hapd, hapd->conf->iface, 1);
62 hostapd_set_drv_ieee8021x(hapd, hapd->conf->iface, 0);
64 if (hapd->conf->wpa && hapd->wpa_auth == NULL) {
65 hostapd_setup_wpa(hapd);
67 wpa_init_keys(hapd->wpa_auth);
68 } else if (hapd->conf->wpa) {
71 hostapd_reconfig_wpa(hapd);
72 wpa_ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &wpa_ie_len);
73 if (hostapd_set_generic_elem(hapd, wpa_ie, wpa_ie_len))
74 wpa_printf(MSG_ERROR, "Failed to configure WPA IE for "
75 "the kernel driver.");
76 } else if (hapd->wpa_auth) {
77 wpa_deinit(hapd->wpa_auth);
78 hapd->wpa_auth = NULL;
79 hostapd_set_privacy(hapd, 0);
80 hostapd_setup_encryption(hapd->conf->iface, hapd);
81 hostapd_set_generic_elem(hapd, (u8 *) "", 0);
84 ieee802_11_set_beacon(hapd);
85 hostapd_update_wps(hapd);
87 if (hapd->conf->ssid.ssid_set &&
88 hostapd_set_ssid(hapd, (u8 *) hapd->conf->ssid.ssid,
89 hapd->conf->ssid.ssid_len)) {
90 wpa_printf(MSG_ERROR, "Could not set SSID for kernel driver");
93 wpa_printf(MSG_DEBUG, "Reconfigured interface %s", hapd->conf->iface);
97 int hostapd_reload_config(struct hostapd_iface *iface)
99 struct hostapd_data *hapd = iface->bss[0];
100 struct hostapd_config *newconf, *oldconf;
103 if (iface->config_read_cb == NULL)
105 newconf = iface->config_read_cb(iface->config_fname);
110 * Deauthenticate all stations since the new configuration may not
111 * allow them to use the BSS anymore.
113 for (j = 0; j < iface->num_bss; j++) {
114 hostapd_flush_old_stations(iface->bss[j]);
115 hostapd_broadcast_wep_clear(iface->bss[j]);
117 #ifndef CONFIG_NO_RADIUS
118 /* TODO: update dynamic data based on changed configuration
119 * items (e.g., open/close sockets, etc.) */
120 radius_client_flush(iface->bss[j]->radius, 0);
121 #endif /* CONFIG_NO_RADIUS */
124 oldconf = hapd->iconf;
125 iface->conf = newconf;
127 for (j = 0; j < iface->num_bss; j++) {
128 hapd = iface->bss[j];
129 hapd->iconf = newconf;
130 hapd->conf = &newconf->bss[j];
131 hostapd_reload_bss(hapd);
134 hostapd_config_free(oldconf);
141 static void hostapd_broadcast_key_clear_iface(struct hostapd_data *hapd,
146 for (i = 0; i < NUM_WEP_KEYS; i++) {
147 if (hostapd_drv_set_key(ifname, hapd, WPA_ALG_NONE, NULL, i,
148 0, NULL, 0, NULL, 0)) {
149 wpa_printf(MSG_DEBUG, "Failed to clear default "
150 "encryption keys (ifname=%s keyidx=%d)",
154 #ifdef CONFIG_IEEE80211W
155 if (hapd->conf->ieee80211w) {
156 for (i = NUM_WEP_KEYS; i < NUM_WEP_KEYS + 2; i++) {
157 if (hostapd_drv_set_key(ifname, hapd, WPA_ALG_NONE,
160 wpa_printf(MSG_DEBUG, "Failed to clear "
161 "default mgmt encryption keys "
162 "(ifname=%s keyidx=%d)", ifname, i);
166 #endif /* CONFIG_IEEE80211W */
170 static int hostapd_broadcast_wep_clear(struct hostapd_data *hapd)
172 hostapd_broadcast_key_clear_iface(hapd, hapd->conf->iface);
177 static int hostapd_broadcast_wep_set(struct hostapd_data *hapd)
180 struct hostapd_ssid *ssid = &hapd->conf->ssid;
183 if (ssid->wep.default_len &&
184 hostapd_drv_set_key(hapd->conf->iface,
185 hapd, WPA_ALG_WEP, broadcast_ether_addr, idx,
186 1, NULL, 0, ssid->wep.key[idx],
187 ssid->wep.len[idx])) {
188 wpa_printf(MSG_WARNING, "Could not set WEP encryption.");
192 if (ssid->dyn_vlan_keys) {
194 for (i = 0; i <= ssid->max_dyn_vlan_keys; i++) {
196 struct hostapd_wep_keys *key = ssid->dyn_vlan_keys[i];
199 ifname = hostapd_get_vlan_id_ifname(hapd->conf->vlan,
205 if (hostapd_drv_set_key(ifname, hapd, WPA_ALG_WEP,
206 broadcast_ether_addr, idx, 1,
207 NULL, 0, key->key[idx],
209 wpa_printf(MSG_WARNING, "Could not set "
210 "dynamic VLAN WEP encryption.");
220 * hostapd_cleanup - Per-BSS cleanup (deinitialization)
221 * @hapd: Pointer to BSS data
223 * This function is used to free all per-BSS data structures and resources.
224 * This gets called in a loop for each BSS between calls to
225 * hostapd_cleanup_iface_pre() and hostapd_cleanup_iface() when an interface
226 * is deinitialized. Most of the modules that are initialized in
227 * hostapd_setup_bss() are deinitialized here.
229 static void hostapd_cleanup(struct hostapd_data *hapd)
231 if (hapd->iface->ctrl_iface_deinit)
232 hapd->iface->ctrl_iface_deinit(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);
270 * hostapd_cleanup_iface_pre - Preliminary per-interface cleanup
271 * @iface: Pointer to interface data
273 * This function is called before per-BSS data structures are deinitialized
274 * with hostapd_cleanup().
276 static void hostapd_cleanup_iface_pre(struct hostapd_iface *iface)
282 * hostapd_cleanup_iface - Complete per-interface cleanup
283 * @iface: Pointer to interface data
285 * This function is called after per-BSS data structures are deinitialized
286 * with hostapd_cleanup().
288 static void hostapd_cleanup_iface(struct hostapd_iface *iface)
290 hostapd_free_hw_features(iface->hw_features, iface->num_hw_features);
291 iface->hw_features = NULL;
292 os_free(iface->current_rates);
293 iface->current_rates = NULL;
294 ap_list_deinit(iface);
295 hostapd_config_free(iface->conf);
298 os_free(iface->config_fname);
304 static int hostapd_setup_encryption(char *iface, struct hostapd_data *hapd)
308 hostapd_broadcast_wep_set(hapd);
310 if (hapd->conf->ssid.wep.default_len) {
311 hostapd_set_privacy(hapd, 1);
316 * When IEEE 802.1X is not enabled, the driver may need to know how to
317 * set authentication algorithms for static WEP.
319 hostapd_drv_set_authmode(hapd, hapd->conf->auth_algs);
321 for (i = 0; i < 4; i++) {
322 if (hapd->conf->ssid.wep.key[i] &&
323 hostapd_drv_set_key(iface, hapd, WPA_ALG_WEP, NULL, i,
324 i == hapd->conf->ssid.wep.idx, NULL, 0,
325 hapd->conf->ssid.wep.key[i],
326 hapd->conf->ssid.wep.len[i])) {
327 wpa_printf(MSG_WARNING, "Could not set WEP "
331 if (hapd->conf->ssid.wep.key[i] &&
332 i == hapd->conf->ssid.wep.idx)
333 hostapd_set_privacy(hapd, 1);
340 static int hostapd_flush_old_stations(struct hostapd_data *hapd)
345 if (hostapd_drv_none(hapd) || hapd->drv_priv == NULL)
348 wpa_printf(MSG_DEBUG, "Flushing old station entries");
349 if (hostapd_flush(hapd)) {
350 wpa_printf(MSG_WARNING, "Could not connect to kernel driver.");
353 wpa_printf(MSG_DEBUG, "Deauthenticate all stations");
354 os_memset(addr, 0xff, ETH_ALEN);
355 hostapd_drv_sta_deauth(hapd, addr, WLAN_REASON_PREV_AUTH_NOT_VALID);
356 hostapd_free_stas(hapd);
363 * hostapd_validate_bssid_configuration - Validate BSSID configuration
364 * @iface: Pointer to interface data
365 * Returns: 0 on success, -1 on failure
367 * This function is used to validate that the configured BSSIDs are valid.
369 static int hostapd_validate_bssid_configuration(struct hostapd_iface *iface)
371 u8 mask[ETH_ALEN] = { 0 };
372 struct hostapd_data *hapd = iface->bss[0];
373 unsigned int i = iface->conf->num_bss, bits = 0, j;
376 if (hostapd_drv_none(hapd))
379 /* Generate BSSID mask that is large enough to cover the BSSIDs. */
381 /* Determine the bits necessary to cover the number of BSSIDs. */
382 for (i--; i; i >>= 1)
385 /* Determine the bits necessary to any configured BSSIDs,
386 if they are higher than the number of BSSIDs. */
387 for (j = 0; j < iface->conf->num_bss; j++) {
388 if (hostapd_mac_comp_empty(iface->conf->bss[j].bssid) == 0) {
394 for (i = 0; i < ETH_ALEN; i++) {
396 iface->conf->bss[j].bssid[i] ^
404 for (i = 0; i < ETH_ALEN && mask[i] == 0; i++)
410 while (mask[i] != 0) {
420 wpa_printf(MSG_ERROR, "Too many bits in the BSSID mask (%u)",
425 os_memset(mask, 0xff, ETH_ALEN);
427 for (i = 5; i > 5 - j; i--)
434 wpa_printf(MSG_DEBUG, "BSS count %lu, BSSID mask " MACSTR " (%d bits)",
435 (unsigned long) iface->conf->num_bss, MAC2STR(mask), bits);
440 for (i = 0; i < ETH_ALEN; i++) {
441 if ((hapd->own_addr[i] & mask[i]) != hapd->own_addr[i]) {
442 wpa_printf(MSG_ERROR, "Invalid BSSID mask " MACSTR
443 " for start address " MACSTR ".",
444 MAC2STR(mask), MAC2STR(hapd->own_addr));
445 wpa_printf(MSG_ERROR, "Start address must be the "
446 "first address in the block (i.e., addr "
447 "AND mask == addr).");
456 static int mac_in_conf(struct hostapd_config *conf, const void *a)
460 for (i = 0; i < conf->num_bss; i++) {
461 if (hostapd_mac_comp(conf->bss[i].bssid, a) == 0) {
473 * hostapd_setup_bss - Per-BSS setup (initialization)
474 * @hapd: Pointer to BSS data
475 * @first: Whether this BSS is the first BSS of an interface
477 * This function is used to initialize all per-BSS data structures and
478 * resources. This gets called in a loop for each BSS when an interface is
479 * initialized. Most of the modules that are initialized here will be
480 * deinitialized in hostapd_cleanup().
482 static int hostapd_setup_bss(struct hostapd_data *hapd, int first)
484 struct hostapd_bss_config *conf = hapd->conf;
485 u8 ssid[HOSTAPD_MAX_SSID_LEN + 1];
486 int ssid_len, set_ssid;
487 char force_ifname[IFNAMSIZ];
488 u8 if_addr[ETH_ALEN];
491 if (hostapd_mac_comp_empty(hapd->conf->bssid) == 0) {
492 /* Allocate the next available BSSID. */
494 inc_byte_array(hapd->own_addr, ETH_ALEN);
495 } while (mac_in_conf(hapd->iconf, hapd->own_addr));
497 /* Allocate the configured BSSID. */
498 os_memcpy(hapd->own_addr, hapd->conf->bssid, ETH_ALEN);
500 if (hostapd_mac_comp(hapd->own_addr,
501 hapd->iface->bss[0]->own_addr) ==
503 wpa_printf(MSG_ERROR, "BSS '%s' may not have "
504 "BSSID set to the MAC address of "
505 "the radio", hapd->conf->iface);
510 hapd->interface_added = 1;
511 if (hostapd_if_add(hapd->iface->bss[0], WPA_IF_AP_BSS,
512 hapd->conf->iface, hapd->own_addr, hapd,
513 &hapd->drv_priv, force_ifname, if_addr,
514 hapd->conf->bridge[0] ? hapd->conf->bridge :
516 wpa_printf(MSG_ERROR, "Failed to add BSS (BSSID="
517 MACSTR ")", MAC2STR(hapd->own_addr));
522 if (conf->wmm_enabled < 0)
523 conf->wmm_enabled = hapd->iconf->ieee80211n;
525 hostapd_flush_old_stations(hapd);
526 hostapd_set_privacy(hapd, 0);
528 hostapd_broadcast_wep_clear(hapd);
529 if (hostapd_setup_encryption(hapd->conf->iface, hapd))
533 * Fetch the SSID from the system and use it or,
534 * if one was specified in the config file, verify they
537 ssid_len = hostapd_get_ssid(hapd, ssid, sizeof(ssid));
539 wpa_printf(MSG_ERROR, "Could not read SSID from system");
542 if (conf->ssid.ssid_set) {
544 * If SSID is specified in the config file and it differs
545 * from what is being used then force installation of the
548 set_ssid = (conf->ssid.ssid_len != (size_t) ssid_len ||
549 os_memcmp(conf->ssid.ssid, ssid, ssid_len) != 0);
552 * No SSID in the config file; just use the one we got
556 conf->ssid.ssid_len = ssid_len;
557 os_memcpy(conf->ssid.ssid, ssid, conf->ssid.ssid_len);
558 conf->ssid.ssid[conf->ssid.ssid_len] = '\0';
561 if (!hostapd_drv_none(hapd)) {
562 wpa_printf(MSG_ERROR, "Using interface %s with hwaddr " MACSTR
564 hapd->conf->iface, MAC2STR(hapd->own_addr),
565 hapd->conf->ssid.ssid);
568 if (hostapd_setup_wpa_psk(conf)) {
569 wpa_printf(MSG_ERROR, "WPA-PSK setup failed.");
573 /* Set SSID for the kernel driver (to be used in beacon and probe
574 * response frames) */
575 if (set_ssid && hostapd_set_ssid(hapd, (u8 *) conf->ssid.ssid,
576 conf->ssid.ssid_len)) {
577 wpa_printf(MSG_ERROR, "Could not set SSID for kernel driver");
581 if (wpa_debug_level == MSG_MSGDUMP)
582 conf->radius->msg_dumps = 1;
583 #ifndef CONFIG_NO_RADIUS
584 hapd->radius = radius_client_init(hapd, conf->radius);
585 if (hapd->radius == NULL) {
586 wpa_printf(MSG_ERROR, "RADIUS client initialization failed.");
589 #endif /* CONFIG_NO_RADIUS */
591 if (hostapd_acl_init(hapd)) {
592 wpa_printf(MSG_ERROR, "ACL initialization failed.");
595 if (hostapd_init_wps(hapd, conf))
598 if (authsrv_init(hapd) < 0)
601 if (ieee802_1x_init(hapd)) {
602 wpa_printf(MSG_ERROR, "IEEE 802.1X initialization failed.");
606 if (hapd->conf->wpa && hostapd_setup_wpa(hapd))
609 if (accounting_init(hapd)) {
610 wpa_printf(MSG_ERROR, "Accounting initialization failed.");
614 if (hapd->conf->ieee802_11f &&
615 (hapd->iapp = iapp_init(hapd, hapd->conf->iapp_iface)) == NULL) {
616 wpa_printf(MSG_ERROR, "IEEE 802.11F (IAPP) initialization "
621 if (hapd->iface->ctrl_iface_init &&
622 hapd->iface->ctrl_iface_init(hapd)) {
623 wpa_printf(MSG_ERROR, "Failed to setup control interface");
627 if (!hostapd_drv_none(hapd) && vlan_init(hapd)) {
628 wpa_printf(MSG_ERROR, "VLAN initialization failed.");
632 ieee802_11_set_beacon(hapd);
634 if (hapd->wpa_auth && wpa_init_keys(hapd->wpa_auth) < 0)
637 if (hapd->driver && hapd->driver->set_operstate)
638 hapd->driver->set_operstate(hapd->drv_priv, 1);
644 static void hostapd_tx_queue_params(struct hostapd_iface *iface)
646 struct hostapd_data *hapd = iface->bss[0];
648 struct hostapd_tx_queue_params *p;
650 for (i = 0; i < NUM_TX_QUEUES; i++) {
651 p = &iface->conf->tx_queue[i];
653 if (hostapd_set_tx_queue_params(hapd, i, p->aifs, p->cwmin,
654 p->cwmax, p->burst)) {
655 wpa_printf(MSG_DEBUG, "Failed to set TX queue "
656 "parameters for queue %d.", i);
657 /* Continue anyway */
663 static int setup_interface(struct hostapd_iface *iface)
665 struct hostapd_data *hapd = iface->bss[0];
670 * Make sure that all BSSes get configured with a pointer to the same
673 for (i = 1; i < iface->num_bss; i++) {
674 iface->bss[i]->driver = hapd->driver;
675 iface->bss[i]->drv_priv = hapd->drv_priv;
678 if (hostapd_validate_bssid_configuration(iface))
681 if (hapd->iconf->country[0] && hapd->iconf->country[1]) {
682 os_memcpy(country, hapd->iconf->country, 3);
684 if (hostapd_set_country(hapd, country) < 0) {
685 wpa_printf(MSG_ERROR, "Failed to set country code");
690 if (hostapd_get_hw_features(iface)) {
691 /* Not all drivers support this yet, so continue without hw
694 int ret = hostapd_select_hw_mode(iface);
696 wpa_printf(MSG_ERROR, "Could not select hw_mode and "
697 "channel. (%d)", ret);
700 ret = hostapd_check_ht_capab(iface);
704 wpa_printf(MSG_DEBUG, "Interface initialization will "
705 "be completed in a callback");
709 return hostapd_setup_interface_complete(iface, 0);
713 int hostapd_setup_interface_complete(struct hostapd_iface *iface, int err)
715 struct hostapd_data *hapd = iface->bss[0];
720 wpa_printf(MSG_ERROR, "Interface initialization failed");
725 wpa_printf(MSG_DEBUG, "Completing interface initialization");
726 if (hapd->iconf->channel) {
727 iface->freq = hostapd_hw_get_freq(hapd, hapd->iconf->channel);
728 wpa_printf(MSG_DEBUG, "Mode: %s Channel: %d "
730 hostapd_hw_mode_txt(hapd->iconf->hw_mode),
731 hapd->iconf->channel, iface->freq);
733 if (hostapd_set_freq(hapd, hapd->iconf->hw_mode, iface->freq,
734 hapd->iconf->channel,
735 hapd->iconf->ieee80211n,
736 hapd->iconf->secondary_channel)) {
737 wpa_printf(MSG_ERROR, "Could not set channel for "
743 if (iface->current_mode) {
744 if (hostapd_prepare_rates(hapd, iface->current_mode)) {
745 wpa_printf(MSG_ERROR, "Failed to prepare rates "
747 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
748 HOSTAPD_LEVEL_WARNING,
749 "Failed to prepare rates table.");
754 if (hapd->iconf->rts_threshold > -1 &&
755 hostapd_set_rts(hapd, hapd->iconf->rts_threshold)) {
756 wpa_printf(MSG_ERROR, "Could not set RTS threshold for "
761 if (hapd->iconf->fragm_threshold > -1 &&
762 hostapd_set_frag(hapd, hapd->iconf->fragm_threshold)) {
763 wpa_printf(MSG_ERROR, "Could not set fragmentation threshold "
764 "for kernel driver");
768 prev_addr = hapd->own_addr;
770 for (j = 0; j < iface->num_bss; j++) {
771 hapd = iface->bss[j];
773 os_memcpy(hapd->own_addr, prev_addr, ETH_ALEN);
774 if (hostapd_setup_bss(hapd, j == 0))
776 if (hostapd_mac_comp_empty(hapd->conf->bssid) == 0)
777 prev_addr = hapd->own_addr;
780 hostapd_tx_queue_params(iface);
784 if (hostapd_driver_commit(hapd) < 0) {
785 wpa_printf(MSG_ERROR, "%s: Failed to commit driver "
786 "configuration", __func__);
791 * WPS UPnP module can be initialized only when the "upnp_iface" is up.
792 * If "interface" and "upnp_iface" are the same (e.g., non-bridge
793 * mode), the interface is up only after driver_commit, so initialize
794 * WPS after driver_commit.
796 for (j = 0; j < iface->num_bss; j++) {
797 if (hostapd_init_wps_complete(iface->bss[j]))
801 if (hapd->setup_complete_cb)
802 hapd->setup_complete_cb(hapd->setup_complete_cb_ctx);
804 wpa_printf(MSG_DEBUG, "%s: Setup of interface done.",
805 iface->bss[0]->conf->iface);
812 * hostapd_setup_interface - Setup of an interface
813 * @iface: Pointer to interface data.
814 * Returns: 0 on success, -1 on failure
816 * Initializes the driver interface, validates the configuration,
817 * and sets driver parameters based on the configuration.
818 * Flushes old stations, sets the channel, encryption,
819 * beacons, and WDS links based on the configuration.
821 int hostapd_setup_interface(struct hostapd_iface *iface)
825 ret = setup_interface(iface);
827 wpa_printf(MSG_ERROR, "%s: Unable to setup interface.",
828 iface->bss[0]->conf->iface);
837 * hostapd_alloc_bss_data - Allocate and initialize per-BSS data
838 * @hapd_iface: Pointer to interface data
839 * @conf: Pointer to per-interface configuration
840 * @bss: Pointer to per-BSS configuration for this BSS
841 * Returns: Pointer to allocated BSS data
843 * This function is used to allocate per-BSS data structure. This data will be
844 * freed after hostapd_cleanup() is called for it during interface
847 struct hostapd_data *
848 hostapd_alloc_bss_data(struct hostapd_iface *hapd_iface,
849 struct hostapd_config *conf,
850 struct hostapd_bss_config *bss)
852 struct hostapd_data *hapd;
854 hapd = os_zalloc(sizeof(*hapd));
858 hapd->new_assoc_sta_cb = hostapd_new_assoc_sta;
861 hapd->iface = hapd_iface;
862 hapd->driver = hapd->iconf->driver;
868 void hostapd_interface_deinit(struct hostapd_iface *iface)
875 hostapd_cleanup_iface_pre(iface);
876 for (j = 0; j < iface->num_bss; j++) {
877 struct hostapd_data *hapd = iface->bss[j];
878 hostapd_free_stas(hapd);
879 hostapd_flush_old_stations(hapd);
880 hostapd_cleanup(hapd);
885 void hostapd_interface_free(struct hostapd_iface *iface)
888 for (j = 0; j < iface->num_bss; j++)
889 os_free(iface->bss[j]);
890 hostapd_cleanup_iface(iface);
895 * hostapd_new_assoc_sta - Notify that a new station associated with the AP
896 * @hapd: Pointer to BSS data
897 * @sta: Pointer to the associated STA data
898 * @reassoc: 1 to indicate this was a re-association; 0 = first association
900 * This function will be called whenever a station associates with the AP. It
901 * can be called from ieee802_11.c for drivers that export MLME to hostapd and
902 * from drv_callbacks.c based on driver events for drivers that take care of
903 * management frames (IEEE 802.11 authentication and association) internally.
905 void hostapd_new_assoc_sta(struct hostapd_data *hapd, struct sta_info *sta,
908 if (hapd->tkip_countermeasures) {
909 hostapd_drv_sta_deauth(hapd, sta->addr,
910 WLAN_REASON_MICHAEL_MIC_FAILURE);
914 hostapd_prune_associations(hapd, sta->addr);
916 /* IEEE 802.11F (IAPP) */
917 if (hapd->conf->ieee802_11f)
918 iapp_new_station(hapd->iapp, sta);
921 if (sta->p2p_ie == NULL && !sta->no_p2p_set) {
923 hapd->num_sta_no_p2p++;
924 if (hapd->num_sta_no_p2p == 1)
925 hostapd_p2p_non_p2p_sta_connected(hapd);
927 #endif /* CONFIG_P2P */
929 /* Start accounting here, if IEEE 802.1X and WPA are not used.
930 * IEEE 802.1X/WPA code will start accounting after the station has
931 * been authorized. */
932 if (!hapd->conf->ieee802_1x && !hapd->conf->wpa)
933 accounting_sta_start(hapd, sta);
935 /* Start IEEE 802.1X authentication process for new stations */
936 ieee802_1x_new_station(hapd, sta);
938 if (sta->auth_alg != WLAN_AUTH_FT &&
939 !(sta->flags & (WLAN_STA_WPS | WLAN_STA_MAYBE_WPS)))
940 wpa_auth_sm_event(sta->wpa_sm, WPA_REAUTH);
942 wpa_auth_sta_associated(hapd->wpa_auth, sta->wpa_sm);