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 int hostapd_for_each_interface(struct hapd_interfaces *interfaces,
43 int (*cb)(struct hostapd_iface *iface,
44 void *ctx), void *ctx)
49 for (i = 0; i < interfaces->count; i++) {
50 ret = cb(interfaces->iface[i], ctx);
59 static void hostapd_reload_bss(struct hostapd_data *hapd)
61 #ifndef CONFIG_NO_RADIUS
62 radius_client_reconfig(hapd->radius, hapd->conf->radius);
63 #endif /* CONFIG_NO_RADIUS */
65 if (hostapd_setup_wpa_psk(hapd->conf)) {
66 wpa_printf(MSG_ERROR, "Failed to re-configure WPA PSK "
67 "after reloading configuration");
70 if (hapd->conf->ieee802_1x || hapd->conf->wpa)
71 hostapd_set_drv_ieee8021x(hapd, hapd->conf->iface, 1);
73 hostapd_set_drv_ieee8021x(hapd, hapd->conf->iface, 0);
75 if (hapd->conf->wpa && hapd->wpa_auth == NULL) {
76 hostapd_setup_wpa(hapd);
78 wpa_init_keys(hapd->wpa_auth);
79 } else if (hapd->conf->wpa) {
82 hostapd_reconfig_wpa(hapd);
83 wpa_ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &wpa_ie_len);
84 if (hostapd_set_generic_elem(hapd, wpa_ie, wpa_ie_len))
85 wpa_printf(MSG_ERROR, "Failed to configure WPA IE for "
86 "the kernel driver.");
87 } else if (hapd->wpa_auth) {
88 wpa_deinit(hapd->wpa_auth);
89 hapd->wpa_auth = NULL;
90 hostapd_set_privacy(hapd, 0);
91 hostapd_setup_encryption(hapd->conf->iface, hapd);
92 hostapd_set_generic_elem(hapd, (u8 *) "", 0);
95 ieee802_11_set_beacon(hapd);
96 hostapd_update_wps(hapd);
98 if (hapd->conf->ssid.ssid_set &&
99 hostapd_set_ssid(hapd, (u8 *) hapd->conf->ssid.ssid,
100 hapd->conf->ssid.ssid_len)) {
101 wpa_printf(MSG_ERROR, "Could not set SSID for kernel driver");
102 /* try to continue */
104 wpa_printf(MSG_DEBUG, "Reconfigured interface %s", hapd->conf->iface);
108 int hostapd_reload_config(struct hostapd_iface *iface)
110 struct hostapd_data *hapd = iface->bss[0];
111 struct hostapd_config *newconf, *oldconf;
114 if (iface->config_read_cb == NULL)
116 newconf = iface->config_read_cb(iface->config_fname);
121 * Deauthenticate all stations since the new configuration may not
122 * allow them to use the BSS anymore.
124 for (j = 0; j < iface->num_bss; j++) {
125 hostapd_flush_old_stations(iface->bss[j]);
126 hostapd_broadcast_wep_clear(iface->bss[j]);
128 #ifndef CONFIG_NO_RADIUS
129 /* TODO: update dynamic data based on changed configuration
130 * items (e.g., open/close sockets, etc.) */
131 radius_client_flush(iface->bss[j]->radius, 0);
132 #endif /* CONFIG_NO_RADIUS */
135 oldconf = hapd->iconf;
136 iface->conf = newconf;
138 for (j = 0; j < iface->num_bss; j++) {
139 hapd = iface->bss[j];
140 hapd->iconf = newconf;
141 hapd->conf = &newconf->bss[j];
142 hostapd_reload_bss(hapd);
145 hostapd_config_free(oldconf);
152 static void hostapd_broadcast_key_clear_iface(struct hostapd_data *hapd,
157 for (i = 0; i < NUM_WEP_KEYS; i++) {
158 if (hostapd_drv_set_key(ifname, hapd, WPA_ALG_NONE, NULL, i,
159 0, NULL, 0, NULL, 0)) {
160 wpa_printf(MSG_DEBUG, "Failed to clear default "
161 "encryption keys (ifname=%s keyidx=%d)",
165 #ifdef CONFIG_IEEE80211W
166 if (hapd->conf->ieee80211w) {
167 for (i = NUM_WEP_KEYS; i < NUM_WEP_KEYS + 2; i++) {
168 if (hostapd_drv_set_key(ifname, hapd, WPA_ALG_NONE,
171 wpa_printf(MSG_DEBUG, "Failed to clear "
172 "default mgmt encryption keys "
173 "(ifname=%s keyidx=%d)", ifname, i);
177 #endif /* CONFIG_IEEE80211W */
181 static int hostapd_broadcast_wep_clear(struct hostapd_data *hapd)
183 hostapd_broadcast_key_clear_iface(hapd, hapd->conf->iface);
188 static int hostapd_broadcast_wep_set(struct hostapd_data *hapd)
191 struct hostapd_ssid *ssid = &hapd->conf->ssid;
194 if (ssid->wep.default_len &&
195 hostapd_drv_set_key(hapd->conf->iface,
196 hapd, WPA_ALG_WEP, broadcast_ether_addr, idx,
197 1, NULL, 0, ssid->wep.key[idx],
198 ssid->wep.len[idx])) {
199 wpa_printf(MSG_WARNING, "Could not set WEP encryption.");
203 if (ssid->dyn_vlan_keys) {
205 for (i = 0; i <= ssid->max_dyn_vlan_keys; i++) {
207 struct hostapd_wep_keys *key = ssid->dyn_vlan_keys[i];
210 ifname = hostapd_get_vlan_id_ifname(hapd->conf->vlan,
216 if (hostapd_drv_set_key(ifname, hapd, WPA_ALG_WEP,
217 broadcast_ether_addr, idx, 1,
218 NULL, 0, key->key[idx],
220 wpa_printf(MSG_WARNING, "Could not set "
221 "dynamic VLAN WEP encryption.");
231 static void hostapd_free_hapd_data(struct hostapd_data *hapd)
233 iapp_deinit(hapd->iapp);
235 accounting_deinit(hapd);
236 hostapd_deinit_wpa(hapd);
238 hostapd_acl_deinit(hapd);
239 #ifndef CONFIG_NO_RADIUS
240 radius_client_deinit(hapd->radius);
242 #endif /* CONFIG_NO_RADIUS */
244 hostapd_deinit_wps(hapd);
246 authsrv_deinit(hapd);
248 if (hapd->interface_added &&
249 hostapd_if_remove(hapd, WPA_IF_AP_BSS, hapd->conf->iface)) {
250 wpa_printf(MSG_WARNING, "Failed to remove BSS interface %s",
254 os_free(hapd->probereq_cb);
255 hapd->probereq_cb = NULL;
258 wpabuf_free(hapd->p2p_beacon_ie);
259 hapd->p2p_beacon_ie = NULL;
260 wpabuf_free(hapd->p2p_probe_resp_ie);
261 hapd->p2p_probe_resp_ie = NULL;
262 #endif /* CONFIG_P2P */
264 wpabuf_free(hapd->time_adv);
269 * hostapd_cleanup - Per-BSS cleanup (deinitialization)
270 * @hapd: Pointer to BSS data
272 * This function is used to free all per-BSS data structures and resources.
273 * This gets called in a loop for each BSS between calls to
274 * hostapd_cleanup_iface_pre() and hostapd_cleanup_iface() when an interface
275 * is deinitialized. Most of the modules that are initialized in
276 * hostapd_setup_bss() are deinitialized here.
278 static void hostapd_cleanup(struct hostapd_data *hapd)
280 if (hapd->iface->ctrl_iface_deinit)
281 hapd->iface->ctrl_iface_deinit(hapd);
282 hostapd_free_hapd_data(hapd);
287 * hostapd_cleanup_iface_pre - Preliminary per-interface cleanup
288 * @iface: Pointer to interface data
290 * This function is called before per-BSS data structures are deinitialized
291 * with hostapd_cleanup().
293 static void hostapd_cleanup_iface_pre(struct hostapd_iface *iface)
298 static void hostapd_cleanup_iface_partial(struct hostapd_iface *iface)
300 hostapd_free_hw_features(iface->hw_features, iface->num_hw_features);
301 iface->hw_features = NULL;
302 os_free(iface->current_rates);
303 iface->current_rates = NULL;
304 os_free(iface->basic_rates);
305 iface->basic_rates = NULL;
306 ap_list_deinit(iface);
311 * hostapd_cleanup_iface - Complete per-interface cleanup
312 * @iface: Pointer to interface data
314 * This function is called after per-BSS data structures are deinitialized
315 * with hostapd_cleanup().
317 static void hostapd_cleanup_iface(struct hostapd_iface *iface)
319 hostapd_cleanup_iface_partial(iface);
320 hostapd_config_free(iface->conf);
323 os_free(iface->config_fname);
329 static void hostapd_clear_wep(struct hostapd_data *hapd)
331 if (hapd->drv_priv) {
332 hostapd_set_privacy(hapd, 0);
333 hostapd_broadcast_wep_clear(hapd);
338 static int hostapd_setup_encryption(char *iface, struct hostapd_data *hapd)
342 hostapd_broadcast_wep_set(hapd);
344 if (hapd->conf->ssid.wep.default_len) {
345 hostapd_set_privacy(hapd, 1);
350 * When IEEE 802.1X is not enabled, the driver may need to know how to
351 * set authentication algorithms for static WEP.
353 hostapd_drv_set_authmode(hapd, hapd->conf->auth_algs);
355 for (i = 0; i < 4; i++) {
356 if (hapd->conf->ssid.wep.key[i] &&
357 hostapd_drv_set_key(iface, hapd, WPA_ALG_WEP, NULL, i,
358 i == hapd->conf->ssid.wep.idx, NULL, 0,
359 hapd->conf->ssid.wep.key[i],
360 hapd->conf->ssid.wep.len[i])) {
361 wpa_printf(MSG_WARNING, "Could not set WEP "
365 if (hapd->conf->ssid.wep.key[i] &&
366 i == hapd->conf->ssid.wep.idx)
367 hostapd_set_privacy(hapd, 1);
374 static int hostapd_flush_old_stations(struct hostapd_data *hapd)
379 if (hostapd_drv_none(hapd) || hapd->drv_priv == NULL)
382 wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "Flushing old station entries");
383 if (hostapd_flush(hapd)) {
384 wpa_msg(hapd->msg_ctx, MSG_WARNING, "Could not connect to "
388 wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "Deauthenticate all stations");
389 os_memset(addr, 0xff, ETH_ALEN);
390 hostapd_drv_sta_deauth(hapd, addr, WLAN_REASON_PREV_AUTH_NOT_VALID);
391 hostapd_free_stas(hapd);
398 * hostapd_validate_bssid_configuration - Validate BSSID configuration
399 * @iface: Pointer to interface data
400 * Returns: 0 on success, -1 on failure
402 * This function is used to validate that the configured BSSIDs are valid.
404 static int hostapd_validate_bssid_configuration(struct hostapd_iface *iface)
406 u8 mask[ETH_ALEN] = { 0 };
407 struct hostapd_data *hapd = iface->bss[0];
408 unsigned int i = iface->conf->num_bss, bits = 0, j;
411 if (hostapd_drv_none(hapd))
414 /* Generate BSSID mask that is large enough to cover the BSSIDs. */
416 /* Determine the bits necessary to cover the number of BSSIDs. */
417 for (i--; i; i >>= 1)
420 /* Determine the bits necessary to any configured BSSIDs,
421 if they are higher than the number of BSSIDs. */
422 for (j = 0; j < iface->conf->num_bss; j++) {
423 if (hostapd_mac_comp_empty(iface->conf->bss[j].bssid) == 0) {
429 for (i = 0; i < ETH_ALEN; i++) {
431 iface->conf->bss[j].bssid[i] ^
439 for (i = 0; i < ETH_ALEN && mask[i] == 0; i++)
445 while (mask[i] != 0) {
455 wpa_printf(MSG_ERROR, "Too many bits in the BSSID mask (%u)",
460 os_memset(mask, 0xff, ETH_ALEN);
462 for (i = 5; i > 5 - j; i--)
469 wpa_printf(MSG_DEBUG, "BSS count %lu, BSSID mask " MACSTR " (%d bits)",
470 (unsigned long) iface->conf->num_bss, MAC2STR(mask), bits);
475 for (i = 0; i < ETH_ALEN; i++) {
476 if ((hapd->own_addr[i] & mask[i]) != hapd->own_addr[i]) {
477 wpa_printf(MSG_ERROR, "Invalid BSSID mask " MACSTR
478 " for start address " MACSTR ".",
479 MAC2STR(mask), MAC2STR(hapd->own_addr));
480 wpa_printf(MSG_ERROR, "Start address must be the "
481 "first address in the block (i.e., addr "
482 "AND mask == addr).");
491 static int mac_in_conf(struct hostapd_config *conf, const void *a)
495 for (i = 0; i < conf->num_bss; i++) {
496 if (hostapd_mac_comp(conf->bss[i].bssid, a) == 0) {
508 * hostapd_setup_bss - Per-BSS setup (initialization)
509 * @hapd: Pointer to BSS data
510 * @first: Whether this BSS is the first BSS of an interface
512 * This function is used to initialize all per-BSS data structures and
513 * resources. This gets called in a loop for each BSS when an interface is
514 * initialized. Most of the modules that are initialized here will be
515 * deinitialized in hostapd_cleanup().
517 static int hostapd_setup_bss(struct hostapd_data *hapd, int first)
519 struct hostapd_bss_config *conf = hapd->conf;
520 u8 ssid[HOSTAPD_MAX_SSID_LEN + 1];
521 int ssid_len, set_ssid;
522 char force_ifname[IFNAMSIZ];
523 u8 if_addr[ETH_ALEN];
526 if (hostapd_mac_comp_empty(hapd->conf->bssid) == 0) {
527 /* Allocate the next available BSSID. */
529 inc_byte_array(hapd->own_addr, ETH_ALEN);
530 } while (mac_in_conf(hapd->iconf, hapd->own_addr));
532 /* Allocate the configured BSSID. */
533 os_memcpy(hapd->own_addr, hapd->conf->bssid, ETH_ALEN);
535 if (hostapd_mac_comp(hapd->own_addr,
536 hapd->iface->bss[0]->own_addr) ==
538 wpa_printf(MSG_ERROR, "BSS '%s' may not have "
539 "BSSID set to the MAC address of "
540 "the radio", hapd->conf->iface);
545 hapd->interface_added = 1;
546 if (hostapd_if_add(hapd->iface->bss[0], WPA_IF_AP_BSS,
547 hapd->conf->iface, hapd->own_addr, hapd,
548 &hapd->drv_priv, force_ifname, if_addr,
549 hapd->conf->bridge[0] ? hapd->conf->bridge :
551 wpa_printf(MSG_ERROR, "Failed to add BSS (BSSID="
552 MACSTR ")", MAC2STR(hapd->own_addr));
557 if (conf->wmm_enabled < 0)
558 conf->wmm_enabled = hapd->iconf->ieee80211n;
560 hostapd_flush_old_stations(hapd);
561 hostapd_set_privacy(hapd, 0);
563 hostapd_broadcast_wep_clear(hapd);
564 if (hostapd_setup_encryption(hapd->conf->iface, hapd))
568 * Fetch the SSID from the system and use it or,
569 * if one was specified in the config file, verify they
572 ssid_len = hostapd_get_ssid(hapd, ssid, sizeof(ssid));
574 wpa_printf(MSG_ERROR, "Could not read SSID from system");
577 if (conf->ssid.ssid_set) {
579 * If SSID is specified in the config file and it differs
580 * from what is being used then force installation of the
583 set_ssid = (conf->ssid.ssid_len != (size_t) ssid_len ||
584 os_memcmp(conf->ssid.ssid, ssid, ssid_len) != 0);
587 * No SSID in the config file; just use the one we got
591 conf->ssid.ssid_len = ssid_len;
592 os_memcpy(conf->ssid.ssid, ssid, conf->ssid.ssid_len);
593 conf->ssid.ssid[conf->ssid.ssid_len] = '\0';
596 if (!hostapd_drv_none(hapd)) {
597 wpa_printf(MSG_ERROR, "Using interface %s with hwaddr " MACSTR
599 hapd->conf->iface, MAC2STR(hapd->own_addr),
600 hapd->conf->ssid.ssid);
603 if (hostapd_setup_wpa_psk(conf)) {
604 wpa_printf(MSG_ERROR, "WPA-PSK setup failed.");
608 /* Set SSID for the kernel driver (to be used in beacon and probe
609 * response frames) */
610 if (set_ssid && hostapd_set_ssid(hapd, (u8 *) conf->ssid.ssid,
611 conf->ssid.ssid_len)) {
612 wpa_printf(MSG_ERROR, "Could not set SSID for kernel driver");
616 if (wpa_debug_level == MSG_MSGDUMP)
617 conf->radius->msg_dumps = 1;
618 #ifndef CONFIG_NO_RADIUS
619 hapd->radius = radius_client_init(hapd, conf->radius);
620 if (hapd->radius == NULL) {
621 wpa_printf(MSG_ERROR, "RADIUS client initialization failed.");
624 #endif /* CONFIG_NO_RADIUS */
626 if (hostapd_acl_init(hapd)) {
627 wpa_printf(MSG_ERROR, "ACL initialization failed.");
630 if (hostapd_init_wps(hapd, conf))
633 if (authsrv_init(hapd) < 0)
636 if (ieee802_1x_init(hapd)) {
637 wpa_printf(MSG_ERROR, "IEEE 802.1X initialization failed.");
641 if (hapd->conf->wpa && hostapd_setup_wpa(hapd))
644 if (accounting_init(hapd)) {
645 wpa_printf(MSG_ERROR, "Accounting initialization failed.");
649 if (hapd->conf->ieee802_11f &&
650 (hapd->iapp = iapp_init(hapd, hapd->conf->iapp_iface)) == NULL) {
651 wpa_printf(MSG_ERROR, "IEEE 802.11F (IAPP) initialization "
656 if (hapd->iface->ctrl_iface_init &&
657 hapd->iface->ctrl_iface_init(hapd)) {
658 wpa_printf(MSG_ERROR, "Failed to setup control interface");
662 if (!hostapd_drv_none(hapd) && vlan_init(hapd)) {
663 wpa_printf(MSG_ERROR, "VLAN initialization failed.");
667 ieee802_11_set_beacon(hapd);
669 if (hapd->wpa_auth && wpa_init_keys(hapd->wpa_auth) < 0)
672 if (hapd->driver && hapd->driver->set_operstate)
673 hapd->driver->set_operstate(hapd->drv_priv, 1);
679 static void hostapd_tx_queue_params(struct hostapd_iface *iface)
681 struct hostapd_data *hapd = iface->bss[0];
683 struct hostapd_tx_queue_params *p;
685 for (i = 0; i < NUM_TX_QUEUES; i++) {
686 p = &iface->conf->tx_queue[i];
688 if (hostapd_set_tx_queue_params(hapd, i, p->aifs, p->cwmin,
689 p->cwmax, p->burst)) {
690 wpa_printf(MSG_DEBUG, "Failed to set TX queue "
691 "parameters for queue %d.", i);
692 /* Continue anyway */
698 static int setup_interface(struct hostapd_iface *iface)
700 struct hostapd_data *hapd = iface->bss[0];
705 * Make sure that all BSSes get configured with a pointer to the same
708 for (i = 1; i < iface->num_bss; i++) {
709 iface->bss[i]->driver = hapd->driver;
710 iface->bss[i]->drv_priv = hapd->drv_priv;
713 if (hostapd_validate_bssid_configuration(iface))
716 if (hapd->iconf->country[0] && hapd->iconf->country[1]) {
717 os_memcpy(country, hapd->iconf->country, 3);
719 if (hostapd_set_country(hapd, country) < 0) {
720 wpa_printf(MSG_ERROR, "Failed to set country code");
725 if (hostapd_get_hw_features(iface)) {
726 /* Not all drivers support this yet, so continue without hw
729 int ret = hostapd_select_hw_mode(iface);
731 wpa_printf(MSG_ERROR, "Could not select hw_mode and "
732 "channel. (%d)", ret);
735 ret = hostapd_check_ht_capab(iface);
739 wpa_printf(MSG_DEBUG, "Interface initialization will "
740 "be completed in a callback");
744 return hostapd_setup_interface_complete(iface, 0);
748 int hostapd_setup_interface_complete(struct hostapd_iface *iface, int err)
750 struct hostapd_data *hapd = iface->bss[0];
755 wpa_printf(MSG_ERROR, "Interface initialization failed");
760 wpa_printf(MSG_DEBUG, "Completing interface initialization");
761 if (hapd->iconf->channel) {
762 iface->freq = hostapd_hw_get_freq(hapd, hapd->iconf->channel);
763 wpa_printf(MSG_DEBUG, "Mode: %s Channel: %d "
765 hostapd_hw_mode_txt(hapd->iconf->hw_mode),
766 hapd->iconf->channel, iface->freq);
768 if (hostapd_set_freq(hapd, hapd->iconf->hw_mode, iface->freq,
769 hapd->iconf->channel,
770 hapd->iconf->ieee80211n,
771 hapd->iconf->secondary_channel)) {
772 wpa_printf(MSG_ERROR, "Could not set channel for "
778 if (iface->current_mode) {
779 if (hostapd_prepare_rates(iface, iface->current_mode)) {
780 wpa_printf(MSG_ERROR, "Failed to prepare rates "
782 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
783 HOSTAPD_LEVEL_WARNING,
784 "Failed to prepare rates table.");
789 if (hapd->iconf->rts_threshold > -1 &&
790 hostapd_set_rts(hapd, hapd->iconf->rts_threshold)) {
791 wpa_printf(MSG_ERROR, "Could not set RTS threshold for "
796 if (hapd->iconf->fragm_threshold > -1 &&
797 hostapd_set_frag(hapd, hapd->iconf->fragm_threshold)) {
798 wpa_printf(MSG_ERROR, "Could not set fragmentation threshold "
799 "for kernel driver");
803 prev_addr = hapd->own_addr;
805 for (j = 0; j < iface->num_bss; j++) {
806 hapd = iface->bss[j];
808 os_memcpy(hapd->own_addr, prev_addr, ETH_ALEN);
809 if (hostapd_setup_bss(hapd, j == 0))
811 if (hostapd_mac_comp_empty(hapd->conf->bssid) == 0)
812 prev_addr = hapd->own_addr;
815 hostapd_tx_queue_params(iface);
819 if (hostapd_driver_commit(hapd) < 0) {
820 wpa_printf(MSG_ERROR, "%s: Failed to commit driver "
821 "configuration", __func__);
826 * WPS UPnP module can be initialized only when the "upnp_iface" is up.
827 * If "interface" and "upnp_iface" are the same (e.g., non-bridge
828 * mode), the interface is up only after driver_commit, so initialize
829 * WPS after driver_commit.
831 for (j = 0; j < iface->num_bss; j++) {
832 if (hostapd_init_wps_complete(iface->bss[j]))
836 if (hapd->setup_complete_cb)
837 hapd->setup_complete_cb(hapd->setup_complete_cb_ctx);
839 wpa_printf(MSG_DEBUG, "%s: Setup of interface done.",
840 iface->bss[0]->conf->iface);
847 * hostapd_setup_interface - Setup of an interface
848 * @iface: Pointer to interface data.
849 * Returns: 0 on success, -1 on failure
851 * Initializes the driver interface, validates the configuration,
852 * and sets driver parameters based on the configuration.
853 * Flushes old stations, sets the channel, encryption,
854 * beacons, and WDS links based on the configuration.
856 int hostapd_setup_interface(struct hostapd_iface *iface)
860 ret = setup_interface(iface);
862 wpa_printf(MSG_ERROR, "%s: Unable to setup interface.",
863 iface->bss[0]->conf->iface);
872 * hostapd_alloc_bss_data - Allocate and initialize per-BSS data
873 * @hapd_iface: Pointer to interface data
874 * @conf: Pointer to per-interface configuration
875 * @bss: Pointer to per-BSS configuration for this BSS
876 * Returns: Pointer to allocated BSS data
878 * This function is used to allocate per-BSS data structure. This data will be
879 * freed after hostapd_cleanup() is called for it during interface
882 struct hostapd_data *
883 hostapd_alloc_bss_data(struct hostapd_iface *hapd_iface,
884 struct hostapd_config *conf,
885 struct hostapd_bss_config *bss)
887 struct hostapd_data *hapd;
889 hapd = os_zalloc(sizeof(*hapd));
893 hapd->new_assoc_sta_cb = hostapd_new_assoc_sta;
896 hapd->iface = hapd_iface;
897 hapd->driver = hapd->iconf->driver;
898 hapd->ctrl_sock = -1;
904 void hostapd_interface_deinit(struct hostapd_iface *iface)
911 hostapd_cleanup_iface_pre(iface);
912 for (j = 0; j < iface->num_bss; j++) {
913 struct hostapd_data *hapd = iface->bss[j];
914 hostapd_free_stas(hapd);
915 hostapd_flush_old_stations(hapd);
916 hostapd_clear_wep(hapd);
917 hostapd_cleanup(hapd);
922 void hostapd_interface_free(struct hostapd_iface *iface)
925 for (j = 0; j < iface->num_bss; j++)
926 os_free(iface->bss[j]);
927 hostapd_cleanup_iface(iface);
932 * hostapd_new_assoc_sta - Notify that a new station associated with the AP
933 * @hapd: Pointer to BSS data
934 * @sta: Pointer to the associated STA data
935 * @reassoc: 1 to indicate this was a re-association; 0 = first association
937 * This function will be called whenever a station associates with the AP. It
938 * can be called from ieee802_11.c for drivers that export MLME to hostapd and
939 * from drv_callbacks.c based on driver events for drivers that take care of
940 * management frames (IEEE 802.11 authentication and association) internally.
942 void hostapd_new_assoc_sta(struct hostapd_data *hapd, struct sta_info *sta,
945 if (hapd->tkip_countermeasures) {
946 hostapd_drv_sta_deauth(hapd, sta->addr,
947 WLAN_REASON_MICHAEL_MIC_FAILURE);
951 hostapd_prune_associations(hapd, sta->addr);
953 /* IEEE 802.11F (IAPP) */
954 if (hapd->conf->ieee802_11f)
955 iapp_new_station(hapd->iapp, sta);
958 if (sta->p2p_ie == NULL && !sta->no_p2p_set) {
960 hapd->num_sta_no_p2p++;
961 if (hapd->num_sta_no_p2p == 1)
962 hostapd_p2p_non_p2p_sta_connected(hapd);
964 #endif /* CONFIG_P2P */
966 /* Start accounting here, if IEEE 802.1X and WPA are not used.
967 * IEEE 802.1X/WPA code will start accounting after the station has
968 * been authorized. */
969 if (!hapd->conf->ieee802_1x && !hapd->conf->wpa)
970 accounting_sta_start(hapd, sta);
972 /* Start IEEE 802.1X authentication process for new stations */
973 ieee802_1x_new_station(hapd, sta);
975 if (sta->auth_alg != WLAN_AUTH_FT &&
976 !(sta->flags & (WLAN_STA_WPS | WLAN_STA_MAYBE_WPS)))
977 wpa_auth_sm_event(sta->wpa_sm, WPA_REAUTH);
979 wpa_auth_sta_associated(hapd->wpa_auth, sta->wpa_sm);