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 * hostapd_cleanup - Per-BSS cleanup (deinitialization)
232 * @hapd: Pointer to BSS data
234 * This function is used to free all per-BSS data structures and resources.
235 * This gets called in a loop for each BSS between calls to
236 * hostapd_cleanup_iface_pre() and hostapd_cleanup_iface() when an interface
237 * is deinitialized. Most of the modules that are initialized in
238 * hostapd_setup_bss() are deinitialized here.
240 static void hostapd_cleanup(struct hostapd_data *hapd)
242 if (hapd->iface->ctrl_iface_deinit)
243 hapd->iface->ctrl_iface_deinit(hapd);
245 iapp_deinit(hapd->iapp);
247 accounting_deinit(hapd);
248 hostapd_deinit_wpa(hapd);
250 hostapd_acl_deinit(hapd);
251 #ifndef CONFIG_NO_RADIUS
252 radius_client_deinit(hapd->radius);
254 #endif /* CONFIG_NO_RADIUS */
256 hostapd_deinit_wps(hapd);
258 authsrv_deinit(hapd);
260 if (hapd->interface_added &&
261 hostapd_if_remove(hapd, WPA_IF_AP_BSS, hapd->conf->iface)) {
262 wpa_printf(MSG_WARNING, "Failed to remove BSS interface %s",
266 os_free(hapd->probereq_cb);
267 hapd->probereq_cb = NULL;
270 wpabuf_free(hapd->p2p_beacon_ie);
271 hapd->p2p_beacon_ie = NULL;
272 wpabuf_free(hapd->p2p_probe_resp_ie);
273 hapd->p2p_probe_resp_ie = NULL;
274 #endif /* CONFIG_P2P */
276 wpabuf_free(hapd->time_adv);
281 * hostapd_cleanup_iface_pre - Preliminary per-interface cleanup
282 * @iface: Pointer to interface data
284 * This function is called before per-BSS data structures are deinitialized
285 * with hostapd_cleanup().
287 static void hostapd_cleanup_iface_pre(struct hostapd_iface *iface)
293 * hostapd_cleanup_iface - Complete per-interface cleanup
294 * @iface: Pointer to interface data
296 * This function is called after per-BSS data structures are deinitialized
297 * with hostapd_cleanup().
299 static void hostapd_cleanup_iface(struct hostapd_iface *iface)
301 hostapd_free_hw_features(iface->hw_features, iface->num_hw_features);
302 iface->hw_features = NULL;
303 os_free(iface->current_rates);
304 iface->current_rates = NULL;
305 os_free(iface->basic_rates);
306 iface->basic_rates = NULL;
307 ap_list_deinit(iface);
308 hostapd_config_free(iface->conf);
311 os_free(iface->config_fname);
317 static int hostapd_setup_encryption(char *iface, struct hostapd_data *hapd)
321 hostapd_broadcast_wep_set(hapd);
323 if (hapd->conf->ssid.wep.default_len) {
324 hostapd_set_privacy(hapd, 1);
329 * When IEEE 802.1X is not enabled, the driver may need to know how to
330 * set authentication algorithms for static WEP.
332 hostapd_drv_set_authmode(hapd, hapd->conf->auth_algs);
334 for (i = 0; i < 4; i++) {
335 if (hapd->conf->ssid.wep.key[i] &&
336 hostapd_drv_set_key(iface, hapd, WPA_ALG_WEP, NULL, i,
337 i == hapd->conf->ssid.wep.idx, NULL, 0,
338 hapd->conf->ssid.wep.key[i],
339 hapd->conf->ssid.wep.len[i])) {
340 wpa_printf(MSG_WARNING, "Could not set WEP "
344 if (hapd->conf->ssid.wep.key[i] &&
345 i == hapd->conf->ssid.wep.idx)
346 hostapd_set_privacy(hapd, 1);
353 static int hostapd_flush_old_stations(struct hostapd_data *hapd)
358 if (hostapd_drv_none(hapd) || hapd->drv_priv == NULL)
361 wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "Flushing old station entries");
362 if (hostapd_flush(hapd)) {
363 wpa_msg(hapd->msg_ctx, MSG_WARNING, "Could not connect to "
367 wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "Deauthenticate all stations");
368 os_memset(addr, 0xff, ETH_ALEN);
369 hostapd_drv_sta_deauth(hapd, addr, WLAN_REASON_PREV_AUTH_NOT_VALID);
370 hostapd_free_stas(hapd);
377 * hostapd_validate_bssid_configuration - Validate BSSID configuration
378 * @iface: Pointer to interface data
379 * Returns: 0 on success, -1 on failure
381 * This function is used to validate that the configured BSSIDs are valid.
383 static int hostapd_validate_bssid_configuration(struct hostapd_iface *iface)
385 u8 mask[ETH_ALEN] = { 0 };
386 struct hostapd_data *hapd = iface->bss[0];
387 unsigned int i = iface->conf->num_bss, bits = 0, j;
390 if (hostapd_drv_none(hapd))
393 /* Generate BSSID mask that is large enough to cover the BSSIDs. */
395 /* Determine the bits necessary to cover the number of BSSIDs. */
396 for (i--; i; i >>= 1)
399 /* Determine the bits necessary to any configured BSSIDs,
400 if they are higher than the number of BSSIDs. */
401 for (j = 0; j < iface->conf->num_bss; j++) {
402 if (hostapd_mac_comp_empty(iface->conf->bss[j].bssid) == 0) {
408 for (i = 0; i < ETH_ALEN; i++) {
410 iface->conf->bss[j].bssid[i] ^
418 for (i = 0; i < ETH_ALEN && mask[i] == 0; i++)
424 while (mask[i] != 0) {
434 wpa_printf(MSG_ERROR, "Too many bits in the BSSID mask (%u)",
439 os_memset(mask, 0xff, ETH_ALEN);
441 for (i = 5; i > 5 - j; i--)
448 wpa_printf(MSG_DEBUG, "BSS count %lu, BSSID mask " MACSTR " (%d bits)",
449 (unsigned long) iface->conf->num_bss, MAC2STR(mask), bits);
454 for (i = 0; i < ETH_ALEN; i++) {
455 if ((hapd->own_addr[i] & mask[i]) != hapd->own_addr[i]) {
456 wpa_printf(MSG_ERROR, "Invalid BSSID mask " MACSTR
457 " for start address " MACSTR ".",
458 MAC2STR(mask), MAC2STR(hapd->own_addr));
459 wpa_printf(MSG_ERROR, "Start address must be the "
460 "first address in the block (i.e., addr "
461 "AND mask == addr).");
470 static int mac_in_conf(struct hostapd_config *conf, const void *a)
474 for (i = 0; i < conf->num_bss; i++) {
475 if (hostapd_mac_comp(conf->bss[i].bssid, a) == 0) {
487 * hostapd_setup_bss - Per-BSS setup (initialization)
488 * @hapd: Pointer to BSS data
489 * @first: Whether this BSS is the first BSS of an interface
491 * This function is used to initialize all per-BSS data structures and
492 * resources. This gets called in a loop for each BSS when an interface is
493 * initialized. Most of the modules that are initialized here will be
494 * deinitialized in hostapd_cleanup().
496 static int hostapd_setup_bss(struct hostapd_data *hapd, int first)
498 struct hostapd_bss_config *conf = hapd->conf;
499 u8 ssid[HOSTAPD_MAX_SSID_LEN + 1];
500 int ssid_len, set_ssid;
501 char force_ifname[IFNAMSIZ];
502 u8 if_addr[ETH_ALEN];
505 if (hostapd_mac_comp_empty(hapd->conf->bssid) == 0) {
506 /* Allocate the next available BSSID. */
508 inc_byte_array(hapd->own_addr, ETH_ALEN);
509 } while (mac_in_conf(hapd->iconf, hapd->own_addr));
511 /* Allocate the configured BSSID. */
512 os_memcpy(hapd->own_addr, hapd->conf->bssid, ETH_ALEN);
514 if (hostapd_mac_comp(hapd->own_addr,
515 hapd->iface->bss[0]->own_addr) ==
517 wpa_printf(MSG_ERROR, "BSS '%s' may not have "
518 "BSSID set to the MAC address of "
519 "the radio", hapd->conf->iface);
524 hapd->interface_added = 1;
525 if (hostapd_if_add(hapd->iface->bss[0], WPA_IF_AP_BSS,
526 hapd->conf->iface, hapd->own_addr, hapd,
527 &hapd->drv_priv, force_ifname, if_addr,
528 hapd->conf->bridge[0] ? hapd->conf->bridge :
530 wpa_printf(MSG_ERROR, "Failed to add BSS (BSSID="
531 MACSTR ")", MAC2STR(hapd->own_addr));
536 if (conf->wmm_enabled < 0)
537 conf->wmm_enabled = hapd->iconf->ieee80211n;
539 hostapd_flush_old_stations(hapd);
540 hostapd_set_privacy(hapd, 0);
542 hostapd_broadcast_wep_clear(hapd);
543 if (hostapd_setup_encryption(hapd->conf->iface, hapd))
547 * Fetch the SSID from the system and use it or,
548 * if one was specified in the config file, verify they
551 ssid_len = hostapd_get_ssid(hapd, ssid, sizeof(ssid));
553 wpa_printf(MSG_ERROR, "Could not read SSID from system");
556 if (conf->ssid.ssid_set) {
558 * If SSID is specified in the config file and it differs
559 * from what is being used then force installation of the
562 set_ssid = (conf->ssid.ssid_len != (size_t) ssid_len ||
563 os_memcmp(conf->ssid.ssid, ssid, ssid_len) != 0);
566 * No SSID in the config file; just use the one we got
570 conf->ssid.ssid_len = ssid_len;
571 os_memcpy(conf->ssid.ssid, ssid, conf->ssid.ssid_len);
572 conf->ssid.ssid[conf->ssid.ssid_len] = '\0';
575 if (!hostapd_drv_none(hapd)) {
576 wpa_printf(MSG_ERROR, "Using interface %s with hwaddr " MACSTR
578 hapd->conf->iface, MAC2STR(hapd->own_addr),
579 hapd->conf->ssid.ssid);
582 if (hostapd_setup_wpa_psk(conf)) {
583 wpa_printf(MSG_ERROR, "WPA-PSK setup failed.");
587 /* Set SSID for the kernel driver (to be used in beacon and probe
588 * response frames) */
589 if (set_ssid && hostapd_set_ssid(hapd, (u8 *) conf->ssid.ssid,
590 conf->ssid.ssid_len)) {
591 wpa_printf(MSG_ERROR, "Could not set SSID for kernel driver");
595 if (wpa_debug_level == MSG_MSGDUMP)
596 conf->radius->msg_dumps = 1;
597 #ifndef CONFIG_NO_RADIUS
598 hapd->radius = radius_client_init(hapd, conf->radius);
599 if (hapd->radius == NULL) {
600 wpa_printf(MSG_ERROR, "RADIUS client initialization failed.");
603 #endif /* CONFIG_NO_RADIUS */
605 if (hostapd_acl_init(hapd)) {
606 wpa_printf(MSG_ERROR, "ACL initialization failed.");
609 if (hostapd_init_wps(hapd, conf))
612 if (authsrv_init(hapd) < 0)
615 if (ieee802_1x_init(hapd)) {
616 wpa_printf(MSG_ERROR, "IEEE 802.1X initialization failed.");
620 if (hapd->conf->wpa && hostapd_setup_wpa(hapd))
623 if (accounting_init(hapd)) {
624 wpa_printf(MSG_ERROR, "Accounting initialization failed.");
628 if (hapd->conf->ieee802_11f &&
629 (hapd->iapp = iapp_init(hapd, hapd->conf->iapp_iface)) == NULL) {
630 wpa_printf(MSG_ERROR, "IEEE 802.11F (IAPP) initialization "
635 if (hapd->iface->ctrl_iface_init &&
636 hapd->iface->ctrl_iface_init(hapd)) {
637 wpa_printf(MSG_ERROR, "Failed to setup control interface");
641 if (!hostapd_drv_none(hapd) && vlan_init(hapd)) {
642 wpa_printf(MSG_ERROR, "VLAN initialization failed.");
646 ieee802_11_set_beacon(hapd);
648 if (hapd->wpa_auth && wpa_init_keys(hapd->wpa_auth) < 0)
651 if (hapd->driver && hapd->driver->set_operstate)
652 hapd->driver->set_operstate(hapd->drv_priv, 1);
658 static void hostapd_tx_queue_params(struct hostapd_iface *iface)
660 struct hostapd_data *hapd = iface->bss[0];
662 struct hostapd_tx_queue_params *p;
664 for (i = 0; i < NUM_TX_QUEUES; i++) {
665 p = &iface->conf->tx_queue[i];
667 if (hostapd_set_tx_queue_params(hapd, i, p->aifs, p->cwmin,
668 p->cwmax, p->burst)) {
669 wpa_printf(MSG_DEBUG, "Failed to set TX queue "
670 "parameters for queue %d.", i);
671 /* Continue anyway */
677 static int setup_interface(struct hostapd_iface *iface)
679 struct hostapd_data *hapd = iface->bss[0];
684 * Make sure that all BSSes get configured with a pointer to the same
687 for (i = 1; i < iface->num_bss; i++) {
688 iface->bss[i]->driver = hapd->driver;
689 iface->bss[i]->drv_priv = hapd->drv_priv;
692 if (hostapd_validate_bssid_configuration(iface))
695 if (hapd->iconf->country[0] && hapd->iconf->country[1]) {
696 os_memcpy(country, hapd->iconf->country, 3);
698 if (hostapd_set_country(hapd, country) < 0) {
699 wpa_printf(MSG_ERROR, "Failed to set country code");
704 if (hostapd_get_hw_features(iface)) {
705 /* Not all drivers support this yet, so continue without hw
708 int ret = hostapd_select_hw_mode(iface);
710 wpa_printf(MSG_ERROR, "Could not select hw_mode and "
711 "channel. (%d)", ret);
714 ret = hostapd_check_ht_capab(iface);
718 wpa_printf(MSG_DEBUG, "Interface initialization will "
719 "be completed in a callback");
723 return hostapd_setup_interface_complete(iface, 0);
727 int hostapd_setup_interface_complete(struct hostapd_iface *iface, int err)
729 struct hostapd_data *hapd = iface->bss[0];
734 wpa_printf(MSG_ERROR, "Interface initialization failed");
739 wpa_printf(MSG_DEBUG, "Completing interface initialization");
740 if (hapd->iconf->channel) {
741 iface->freq = hostapd_hw_get_freq(hapd, hapd->iconf->channel);
742 wpa_printf(MSG_DEBUG, "Mode: %s Channel: %d "
744 hostapd_hw_mode_txt(hapd->iconf->hw_mode),
745 hapd->iconf->channel, iface->freq);
747 if (hostapd_set_freq(hapd, hapd->iconf->hw_mode, iface->freq,
748 hapd->iconf->channel,
749 hapd->iconf->ieee80211n,
750 hapd->iconf->secondary_channel)) {
751 wpa_printf(MSG_ERROR, "Could not set channel for "
757 if (iface->current_mode) {
758 if (hostapd_prepare_rates(iface, iface->current_mode)) {
759 wpa_printf(MSG_ERROR, "Failed to prepare rates "
761 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
762 HOSTAPD_LEVEL_WARNING,
763 "Failed to prepare rates table.");
768 if (hapd->iconf->rts_threshold > -1 &&
769 hostapd_set_rts(hapd, hapd->iconf->rts_threshold)) {
770 wpa_printf(MSG_ERROR, "Could not set RTS threshold for "
775 if (hapd->iconf->fragm_threshold > -1 &&
776 hostapd_set_frag(hapd, hapd->iconf->fragm_threshold)) {
777 wpa_printf(MSG_ERROR, "Could not set fragmentation threshold "
778 "for kernel driver");
782 prev_addr = hapd->own_addr;
784 for (j = 0; j < iface->num_bss; j++) {
785 hapd = iface->bss[j];
787 os_memcpy(hapd->own_addr, prev_addr, ETH_ALEN);
788 if (hostapd_setup_bss(hapd, j == 0))
790 if (hostapd_mac_comp_empty(hapd->conf->bssid) == 0)
791 prev_addr = hapd->own_addr;
794 hostapd_tx_queue_params(iface);
798 if (hostapd_driver_commit(hapd) < 0) {
799 wpa_printf(MSG_ERROR, "%s: Failed to commit driver "
800 "configuration", __func__);
805 * WPS UPnP module can be initialized only when the "upnp_iface" is up.
806 * If "interface" and "upnp_iface" are the same (e.g., non-bridge
807 * mode), the interface is up only after driver_commit, so initialize
808 * WPS after driver_commit.
810 for (j = 0; j < iface->num_bss; j++) {
811 if (hostapd_init_wps_complete(iface->bss[j]))
815 if (hapd->setup_complete_cb)
816 hapd->setup_complete_cb(hapd->setup_complete_cb_ctx);
818 wpa_printf(MSG_DEBUG, "%s: Setup of interface done.",
819 iface->bss[0]->conf->iface);
826 * hostapd_setup_interface - Setup of an interface
827 * @iface: Pointer to interface data.
828 * Returns: 0 on success, -1 on failure
830 * Initializes the driver interface, validates the configuration,
831 * and sets driver parameters based on the configuration.
832 * Flushes old stations, sets the channel, encryption,
833 * beacons, and WDS links based on the configuration.
835 int hostapd_setup_interface(struct hostapd_iface *iface)
839 ret = setup_interface(iface);
841 wpa_printf(MSG_ERROR, "%s: Unable to setup interface.",
842 iface->bss[0]->conf->iface);
851 * hostapd_alloc_bss_data - Allocate and initialize per-BSS data
852 * @hapd_iface: Pointer to interface data
853 * @conf: Pointer to per-interface configuration
854 * @bss: Pointer to per-BSS configuration for this BSS
855 * Returns: Pointer to allocated BSS data
857 * This function is used to allocate per-BSS data structure. This data will be
858 * freed after hostapd_cleanup() is called for it during interface
861 struct hostapd_data *
862 hostapd_alloc_bss_data(struct hostapd_iface *hapd_iface,
863 struct hostapd_config *conf,
864 struct hostapd_bss_config *bss)
866 struct hostapd_data *hapd;
868 hapd = os_zalloc(sizeof(*hapd));
872 hapd->new_assoc_sta_cb = hostapd_new_assoc_sta;
875 hapd->iface = hapd_iface;
876 hapd->driver = hapd->iconf->driver;
877 hapd->ctrl_sock = -1;
883 void hostapd_interface_deinit(struct hostapd_iface *iface)
890 hostapd_cleanup_iface_pre(iface);
891 for (j = 0; j < iface->num_bss; j++) {
892 struct hostapd_data *hapd = iface->bss[j];
893 hostapd_free_stas(hapd);
894 hostapd_flush_old_stations(hapd);
895 hostapd_cleanup(hapd);
900 void hostapd_interface_free(struct hostapd_iface *iface)
903 for (j = 0; j < iface->num_bss; j++)
904 os_free(iface->bss[j]);
905 hostapd_cleanup_iface(iface);
910 * hostapd_new_assoc_sta - Notify that a new station associated with the AP
911 * @hapd: Pointer to BSS data
912 * @sta: Pointer to the associated STA data
913 * @reassoc: 1 to indicate this was a re-association; 0 = first association
915 * This function will be called whenever a station associates with the AP. It
916 * can be called from ieee802_11.c for drivers that export MLME to hostapd and
917 * from drv_callbacks.c based on driver events for drivers that take care of
918 * management frames (IEEE 802.11 authentication and association) internally.
920 void hostapd_new_assoc_sta(struct hostapd_data *hapd, struct sta_info *sta,
923 if (hapd->tkip_countermeasures) {
924 hostapd_drv_sta_deauth(hapd, sta->addr,
925 WLAN_REASON_MICHAEL_MIC_FAILURE);
929 hostapd_prune_associations(hapd, sta->addr);
931 /* IEEE 802.11F (IAPP) */
932 if (hapd->conf->ieee802_11f)
933 iapp_new_station(hapd->iapp, sta);
936 if (sta->p2p_ie == NULL && !sta->no_p2p_set) {
938 hapd->num_sta_no_p2p++;
939 if (hapd->num_sta_no_p2p == 1)
940 hostapd_p2p_non_p2p_sta_connected(hapd);
942 #endif /* CONFIG_P2P */
944 /* Start accounting here, if IEEE 802.1X and WPA are not used.
945 * IEEE 802.1X/WPA code will start accounting after the station has
946 * been authorized. */
947 if (!hapd->conf->ieee802_1x && !hapd->conf->wpa)
948 accounting_sta_start(hapd, sta);
950 /* Start IEEE 802.1X authentication process for new stations */
951 ieee802_1x_new_station(hapd, sta);
953 if (sta->auth_alg != WLAN_AUTH_FT &&
954 !(sta->flags & (WLAN_STA_WPS | WLAN_STA_MAYBE_WPS)))
955 wpa_auth_sm_event(sta->wpa_sm, WPA_REAUTH);
957 wpa_auth_sta_associated(hapd->wpa_auth, sta->wpa_sm);