Home | History | Annotate | Line # | Download | only in wpa_supplicant
ap.c revision 1.1.1.6
      1      1.1  christos /*
      2      1.1  christos  * WPA Supplicant - Basic AP mode support routines
      3      1.1  christos  * Copyright (c) 2003-2009, Jouni Malinen <j (at) w1.fi>
      4      1.1  christos  * Copyright (c) 2009, Atheros Communications
      5      1.1  christos  *
      6  1.1.1.3  christos  * This software may be distributed under the terms of the BSD license.
      7  1.1.1.3  christos  * See README for more details.
      8      1.1  christos  */
      9      1.1  christos 
     10      1.1  christos #include "utils/includes.h"
     11      1.1  christos 
     12      1.1  christos #include "utils/common.h"
     13  1.1.1.2  christos #include "utils/eloop.h"
     14  1.1.1.2  christos #include "utils/uuid.h"
     15      1.1  christos #include "common/ieee802_11_defs.h"
     16  1.1.1.2  christos #include "common/wpa_ctrl.h"
     17  1.1.1.4  christos #include "eapol_supp/eapol_supp_sm.h"
     18  1.1.1.4  christos #include "crypto/dh_group5.h"
     19      1.1  christos #include "ap/hostapd.h"
     20      1.1  christos #include "ap/ap_config.h"
     21  1.1.1.2  christos #include "ap/ap_drv_ops.h"
     22      1.1  christos #ifdef NEED_AP_MLME
     23      1.1  christos #include "ap/ieee802_11.h"
     24      1.1  christos #endif /* NEED_AP_MLME */
     25  1.1.1.2  christos #include "ap/beacon.h"
     26      1.1  christos #include "ap/ieee802_1x.h"
     27      1.1  christos #include "ap/wps_hostapd.h"
     28      1.1  christos #include "ap/ctrl_iface_ap.h"
     29  1.1.1.5  christos #include "ap/dfs.h"
     30      1.1  christos #include "wps/wps.h"
     31  1.1.1.2  christos #include "common/ieee802_11_defs.h"
     32      1.1  christos #include "config_ssid.h"
     33      1.1  christos #include "config.h"
     34      1.1  christos #include "wpa_supplicant_i.h"
     35      1.1  christos #include "driver_i.h"
     36  1.1.1.2  christos #include "p2p_supplicant.h"
     37      1.1  christos #include "ap.h"
     38  1.1.1.2  christos #include "ap/sta_info.h"
     39  1.1.1.2  christos #include "notify.h"
     40  1.1.1.2  christos 
     41  1.1.1.2  christos 
     42  1.1.1.2  christos #ifdef CONFIG_WPS
     43  1.1.1.2  christos static void wpas_wps_ap_pin_timeout(void *eloop_data, void *user_ctx);
     44  1.1.1.2  christos #endif /* CONFIG_WPS */
     45      1.1  christos 
     46      1.1  christos 
     47  1.1.1.4  christos #ifdef CONFIG_IEEE80211N
     48  1.1.1.4  christos static void wpas_conf_ap_vht(struct wpa_supplicant *wpa_s,
     49  1.1.1.4  christos 			     struct hostapd_config *conf,
     50  1.1.1.4  christos 			     struct hostapd_hw_modes *mode)
     51  1.1.1.4  christos {
     52  1.1.1.4  christos #ifdef CONFIG_P2P
     53  1.1.1.4  christos 	u8 center_chan = 0;
     54  1.1.1.4  christos 	u8 channel = conf->channel;
     55  1.1.1.4  christos 
     56  1.1.1.4  christos 	if (!conf->secondary_channel)
     57  1.1.1.4  christos 		goto no_vht;
     58  1.1.1.4  christos 
     59  1.1.1.6  christos 	switch (conf->vht_oper_chwidth) {
     60  1.1.1.6  christos 	case VHT_CHANWIDTH_80MHZ:
     61  1.1.1.6  christos 	case VHT_CHANWIDTH_80P80MHZ:
     62  1.1.1.6  christos 		center_chan = wpas_p2p_get_vht80_center(wpa_s, mode, channel);
     63  1.1.1.6  christos 		break;
     64  1.1.1.6  christos 	case VHT_CHANWIDTH_160MHZ:
     65  1.1.1.6  christos 		center_chan = wpas_p2p_get_vht160_center(wpa_s, mode, channel);
     66  1.1.1.6  christos 		break;
     67  1.1.1.6  christos 	default:
     68  1.1.1.6  christos 		/*
     69  1.1.1.6  christos 		 * conf->vht_oper_chwidth might not be set for non-P2P GO cases,
     70  1.1.1.6  christos 		 * try oper_cwidth 160 MHz first then VHT 80 MHz, if 160 MHz is
     71  1.1.1.6  christos 		 * not supported.
     72  1.1.1.6  christos 		 */
     73  1.1.1.6  christos 		conf->vht_oper_chwidth = VHT_CHANWIDTH_160MHZ;
     74  1.1.1.6  christos 		center_chan = wpas_p2p_get_vht160_center(wpa_s, mode, channel);
     75  1.1.1.6  christos 		if (!center_chan) {
     76  1.1.1.6  christos 			conf->vht_oper_chwidth = VHT_CHANWIDTH_80MHZ;
     77  1.1.1.6  christos 			center_chan = wpas_p2p_get_vht80_center(wpa_s, mode,
     78  1.1.1.6  christos 								channel);
     79  1.1.1.6  christos 		}
     80  1.1.1.6  christos 		break;
     81  1.1.1.6  christos 	}
     82  1.1.1.4  christos 	if (!center_chan)
     83  1.1.1.4  christos 		goto no_vht;
     84  1.1.1.4  christos 
     85  1.1.1.4  christos 	conf->vht_oper_centr_freq_seg0_idx = center_chan;
     86  1.1.1.4  christos 	return;
     87  1.1.1.4  christos 
     88  1.1.1.4  christos no_vht:
     89  1.1.1.4  christos 	conf->vht_oper_centr_freq_seg0_idx =
     90  1.1.1.4  christos 		channel + conf->secondary_channel * 2;
     91  1.1.1.4  christos #else /* CONFIG_P2P */
     92  1.1.1.4  christos 	conf->vht_oper_centr_freq_seg0_idx =
     93  1.1.1.4  christos 		conf->channel + conf->secondary_channel * 2;
     94  1.1.1.4  christos #endif /* CONFIG_P2P */
     95  1.1.1.6  christos 	conf->vht_oper_chwidth = VHT_CHANWIDTH_USE_HT;
     96  1.1.1.4  christos }
     97  1.1.1.4  christos #endif /* CONFIG_IEEE80211N */
     98  1.1.1.4  christos 
     99  1.1.1.4  christos 
    100  1.1.1.6  christos int wpa_supplicant_conf_ap_ht(struct wpa_supplicant *wpa_s,
    101  1.1.1.6  christos 			      struct wpa_ssid *ssid,
    102  1.1.1.6  christos 			      struct hostapd_config *conf)
    103      1.1  christos {
    104  1.1.1.6  christos 	conf->hw_mode = ieee80211_freq_to_chan(ssid->frequency,
    105  1.1.1.6  christos 					       &conf->channel);
    106  1.1.1.6  christos 
    107  1.1.1.6  christos 	if (conf->hw_mode == NUM_HOSTAPD_MODES) {
    108  1.1.1.6  christos 		wpa_printf(MSG_ERROR, "Unsupported AP mode frequency: %d MHz",
    109  1.1.1.6  christos 			   ssid->frequency);
    110  1.1.1.6  christos 		return -1;
    111  1.1.1.6  christos 	}
    112  1.1.1.6  christos 
    113  1.1.1.2  christos 	/* TODO: enable HT40 if driver supports it;
    114      1.1  christos 	 * drop to 11b if driver does not support 11g */
    115      1.1  christos 
    116  1.1.1.2  christos #ifdef CONFIG_IEEE80211N
    117  1.1.1.2  christos 	/*
    118  1.1.1.3  christos 	 * Enable HT20 if the driver supports it, by setting conf->ieee80211n
    119  1.1.1.3  christos 	 * and a mask of allowed capabilities within conf->ht_capab.
    120  1.1.1.2  christos 	 * Using default config settings for: conf->ht_op_mode_fixed,
    121  1.1.1.3  christos 	 * conf->secondary_channel, conf->require_ht
    122  1.1.1.2  christos 	 */
    123  1.1.1.2  christos 	if (wpa_s->hw.modes) {
    124  1.1.1.2  christos 		struct hostapd_hw_modes *mode = NULL;
    125  1.1.1.3  christos 		int i, no_ht = 0;
    126  1.1.1.2  christos 		for (i = 0; i < wpa_s->hw.num_modes; i++) {
    127  1.1.1.2  christos 			if (wpa_s->hw.modes[i].mode == conf->hw_mode) {
    128  1.1.1.2  christos 				mode = &wpa_s->hw.modes[i];
    129  1.1.1.2  christos 				break;
    130  1.1.1.2  christos 			}
    131  1.1.1.2  christos 		}
    132  1.1.1.3  christos 
    133  1.1.1.3  christos #ifdef CONFIG_HT_OVERRIDES
    134  1.1.1.3  christos 		if (ssid->disable_ht) {
    135  1.1.1.3  christos 			conf->ieee80211n = 0;
    136  1.1.1.3  christos 			conf->ht_capab = 0;
    137  1.1.1.3  christos 			no_ht = 1;
    138  1.1.1.3  christos 		}
    139  1.1.1.3  christos #endif /* CONFIG_HT_OVERRIDES */
    140  1.1.1.3  christos 
    141  1.1.1.3  christos 		if (!no_ht && mode && mode->ht_capab) {
    142  1.1.1.2  christos 			conf->ieee80211n = 1;
    143  1.1.1.3  christos #ifdef CONFIG_P2P
    144  1.1.1.3  christos 			if (conf->hw_mode == HOSTAPD_MODE_IEEE80211A &&
    145  1.1.1.3  christos 			    (mode->ht_capab &
    146  1.1.1.3  christos 			     HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) &&
    147  1.1.1.3  christos 			    ssid->ht40)
    148  1.1.1.3  christos 				conf->secondary_channel =
    149  1.1.1.3  christos 					wpas_p2p_get_ht40_mode(wpa_s, mode,
    150  1.1.1.3  christos 							       conf->channel);
    151  1.1.1.3  christos 			if (conf->secondary_channel)
    152  1.1.1.3  christos 				conf->ht_capab |=
    153  1.1.1.3  christos 					HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
    154  1.1.1.3  christos #endif /* CONFIG_P2P */
    155  1.1.1.3  christos 
    156  1.1.1.3  christos 			/*
    157  1.1.1.3  christos 			 * white-list capabilities that won't cause issues
    158  1.1.1.3  christos 			 * to connecting stations, while leaving the current
    159  1.1.1.3  christos 			 * capabilities intact (currently disabled SMPS).
    160  1.1.1.3  christos 			 */
    161  1.1.1.3  christos 			conf->ht_capab |= mode->ht_capab &
    162  1.1.1.3  christos 				(HT_CAP_INFO_GREEN_FIELD |
    163  1.1.1.3  christos 				 HT_CAP_INFO_SHORT_GI20MHZ |
    164  1.1.1.3  christos 				 HT_CAP_INFO_SHORT_GI40MHZ |
    165  1.1.1.3  christos 				 HT_CAP_INFO_RX_STBC_MASK |
    166  1.1.1.5  christos 				 HT_CAP_INFO_TX_STBC |
    167  1.1.1.3  christos 				 HT_CAP_INFO_MAX_AMSDU_SIZE);
    168  1.1.1.4  christos 
    169  1.1.1.4  christos 			if (mode->vht_capab && ssid->vht) {
    170  1.1.1.4  christos 				conf->ieee80211ac = 1;
    171  1.1.1.4  christos 				wpas_conf_ap_vht(wpa_s, conf, mode);
    172  1.1.1.4  christos 			}
    173  1.1.1.3  christos 		}
    174  1.1.1.2  christos 	}
    175  1.1.1.6  christos 
    176  1.1.1.6  christos 	if (conf->secondary_channel) {
    177  1.1.1.6  christos 		struct wpa_supplicant *iface;
    178  1.1.1.6  christos 
    179  1.1.1.6  christos 		for (iface = wpa_s->global->ifaces; iface; iface = iface->next)
    180  1.1.1.6  christos 		{
    181  1.1.1.6  christos 			if (iface == wpa_s ||
    182  1.1.1.6  christos 			    iface->wpa_state < WPA_AUTHENTICATING ||
    183  1.1.1.6  christos 			    (int) iface->assoc_freq != ssid->frequency)
    184  1.1.1.6  christos 				continue;
    185  1.1.1.6  christos 
    186  1.1.1.6  christos 			/*
    187  1.1.1.6  christos 			 * Do not allow 40 MHz co-ex PRI/SEC switch to force us
    188  1.1.1.6  christos 			 * to change our PRI channel since we have an existing,
    189  1.1.1.6  christos 			 * concurrent connection on that channel and doing
    190  1.1.1.6  christos 			 * multi-channel concurrency is likely to cause more
    191  1.1.1.6  christos 			 * harm than using different PRI/SEC selection in
    192  1.1.1.6  christos 			 * environment with multiple BSSes on these two channels
    193  1.1.1.6  christos 			 * with mixed 20 MHz or PRI channel selection.
    194  1.1.1.6  christos 			 */
    195  1.1.1.6  christos 			conf->no_pri_sec_switch = 1;
    196  1.1.1.6  christos 		}
    197  1.1.1.6  christos 	}
    198  1.1.1.2  christos #endif /* CONFIG_IEEE80211N */
    199  1.1.1.6  christos 
    200  1.1.1.6  christos 	return 0;
    201  1.1.1.5  christos }
    202  1.1.1.5  christos 
    203  1.1.1.5  christos 
    204  1.1.1.5  christos static int wpa_supplicant_conf_ap(struct wpa_supplicant *wpa_s,
    205  1.1.1.5  christos 				  struct wpa_ssid *ssid,
    206  1.1.1.5  christos 				  struct hostapd_config *conf)
    207  1.1.1.5  christos {
    208  1.1.1.5  christos 	struct hostapd_bss_config *bss = conf->bss[0];
    209  1.1.1.5  christos 
    210  1.1.1.5  christos 	conf->driver = wpa_s->driver;
    211  1.1.1.5  christos 
    212  1.1.1.5  christos 	os_strlcpy(bss->iface, wpa_s->ifname, sizeof(bss->iface));
    213  1.1.1.5  christos 
    214  1.1.1.6  christos 	if (wpa_supplicant_conf_ap_ht(wpa_s, ssid, conf))
    215  1.1.1.6  christos 		return -1;
    216  1.1.1.6  christos 
    217  1.1.1.6  christos 	if (ssid->pbss > 1) {
    218  1.1.1.6  christos 		wpa_printf(MSG_ERROR, "Invalid pbss value(%d) for AP mode",
    219  1.1.1.6  christos 			   ssid->pbss);
    220  1.1.1.5  christos 		return -1;
    221  1.1.1.5  christos 	}
    222  1.1.1.6  christos 	bss->pbss = ssid->pbss;
    223  1.1.1.5  christos 
    224  1.1.1.6  christos #ifdef CONFIG_ACS
    225  1.1.1.6  christos 	if (ssid->acs) {
    226  1.1.1.6  christos 		/* Setting channel to 0 in order to enable ACS */
    227  1.1.1.6  christos 		conf->channel = 0;
    228  1.1.1.6  christos 		wpa_printf(MSG_DEBUG, "Use automatic channel selection");
    229  1.1.1.6  christos 	}
    230  1.1.1.6  christos #endif /* CONFIG_ACS */
    231  1.1.1.5  christos 
    232  1.1.1.5  christos 	if (ieee80211_is_dfs(ssid->frequency) && wpa_s->conf->country[0]) {
    233  1.1.1.5  christos 		conf->ieee80211h = 1;
    234  1.1.1.5  christos 		conf->ieee80211d = 1;
    235  1.1.1.5  christos 		conf->country[0] = wpa_s->conf->country[0];
    236  1.1.1.5  christos 		conf->country[1] = wpa_s->conf->country[1];
    237  1.1.1.5  christos 	}
    238  1.1.1.2  christos 
    239  1.1.1.2  christos #ifdef CONFIG_P2P
    240  1.1.1.4  christos 	if (conf->hw_mode == HOSTAPD_MODE_IEEE80211G &&
    241  1.1.1.4  christos 	    (ssid->mode == WPAS_MODE_P2P_GO ||
    242  1.1.1.4  christos 	     ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)) {
    243  1.1.1.2  christos 		/* Remove 802.11b rates from supported and basic rate sets */
    244  1.1.1.2  christos 		int *list = os_malloc(4 * sizeof(int));
    245  1.1.1.2  christos 		if (list) {
    246  1.1.1.2  christos 			list[0] = 60;
    247  1.1.1.2  christos 			list[1] = 120;
    248  1.1.1.2  christos 			list[2] = 240;
    249  1.1.1.2  christos 			list[3] = -1;
    250  1.1.1.2  christos 		}
    251  1.1.1.2  christos 		conf->basic_rates = list;
    252  1.1.1.2  christos 
    253  1.1.1.2  christos 		list = os_malloc(9 * sizeof(int));
    254  1.1.1.2  christos 		if (list) {
    255  1.1.1.2  christos 			list[0] = 60;
    256  1.1.1.2  christos 			list[1] = 90;
    257  1.1.1.2  christos 			list[2] = 120;
    258  1.1.1.2  christos 			list[3] = 180;
    259  1.1.1.2  christos 			list[4] = 240;
    260  1.1.1.2  christos 			list[5] = 360;
    261  1.1.1.2  christos 			list[6] = 480;
    262  1.1.1.2  christos 			list[7] = 540;
    263  1.1.1.2  christos 			list[8] = -1;
    264  1.1.1.2  christos 		}
    265  1.1.1.2  christos 		conf->supported_rates = list;
    266  1.1.1.2  christos 	}
    267  1.1.1.2  christos 
    268  1.1.1.2  christos 	bss->isolate = !wpa_s->conf->p2p_intra_bss;
    269  1.1.1.4  christos 	bss->force_per_enrollee_psk = wpa_s->global->p2p_per_sta_psk;
    270  1.1.1.4  christos 
    271  1.1.1.4  christos 	if (ssid->p2p_group) {
    272  1.1.1.6  christos 		os_memcpy(bss->ip_addr_go, wpa_s->p2pdev->conf->ip_addr_go, 4);
    273  1.1.1.6  christos 		os_memcpy(bss->ip_addr_mask, wpa_s->p2pdev->conf->ip_addr_mask,
    274  1.1.1.4  christos 			  4);
    275  1.1.1.4  christos 		os_memcpy(bss->ip_addr_start,
    276  1.1.1.6  christos 			  wpa_s->p2pdev->conf->ip_addr_start, 4);
    277  1.1.1.6  christos 		os_memcpy(bss->ip_addr_end, wpa_s->p2pdev->conf->ip_addr_end,
    278  1.1.1.4  christos 			  4);
    279  1.1.1.4  christos 	}
    280  1.1.1.2  christos #endif /* CONFIG_P2P */
    281  1.1.1.2  christos 
    282      1.1  christos 	if (ssid->ssid_len == 0) {
    283      1.1  christos 		wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
    284      1.1  christos 		return -1;
    285      1.1  christos 	}
    286      1.1  christos 	os_memcpy(bss->ssid.ssid, ssid->ssid, ssid->ssid_len);
    287      1.1  christos 	bss->ssid.ssid_len = ssid->ssid_len;
    288      1.1  christos 	bss->ssid.ssid_set = 1;
    289      1.1  christos 
    290  1.1.1.3  christos 	bss->ignore_broadcast_ssid = ssid->ignore_broadcast_ssid;
    291  1.1.1.3  christos 
    292  1.1.1.2  christos 	if (ssid->auth_alg)
    293  1.1.1.2  christos 		bss->auth_algs = ssid->auth_alg;
    294  1.1.1.2  christos 
    295      1.1  christos 	if (wpa_key_mgmt_wpa_psk(ssid->key_mgmt))
    296      1.1  christos 		bss->wpa = ssid->proto;
    297  1.1.1.6  christos 	if (ssid->key_mgmt == DEFAULT_KEY_MGMT)
    298  1.1.1.6  christos 		bss->wpa_key_mgmt = WPA_KEY_MGMT_PSK;
    299  1.1.1.6  christos 	else
    300  1.1.1.6  christos 		bss->wpa_key_mgmt = ssid->key_mgmt;
    301      1.1  christos 	bss->wpa_pairwise = ssid->pairwise_cipher;
    302  1.1.1.3  christos 	if (ssid->psk_set) {
    303  1.1.1.5  christos 		bin_clear_free(bss->ssid.wpa_psk, sizeof(*bss->ssid.wpa_psk));
    304      1.1  christos 		bss->ssid.wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
    305      1.1  christos 		if (bss->ssid.wpa_psk == NULL)
    306      1.1  christos 			return -1;
    307      1.1  christos 		os_memcpy(bss->ssid.wpa_psk->psk, ssid->psk, PMK_LEN);
    308      1.1  christos 		bss->ssid.wpa_psk->group = 1;
    309  1.1.1.6  christos 		bss->ssid.wpa_psk_set = 1;
    310  1.1.1.3  christos 	} else if (ssid->passphrase) {
    311  1.1.1.3  christos 		bss->ssid.wpa_passphrase = os_strdup(ssid->passphrase);
    312  1.1.1.2  christos 	} else if (ssid->wep_key_len[0] || ssid->wep_key_len[1] ||
    313  1.1.1.2  christos 		   ssid->wep_key_len[2] || ssid->wep_key_len[3]) {
    314  1.1.1.2  christos 		struct hostapd_wep_keys *wep = &bss->ssid.wep;
    315  1.1.1.2  christos 		int i;
    316  1.1.1.2  christos 		for (i = 0; i < NUM_WEP_KEYS; i++) {
    317  1.1.1.2  christos 			if (ssid->wep_key_len[i] == 0)
    318  1.1.1.2  christos 				continue;
    319  1.1.1.2  christos 			wep->key[i] = os_malloc(ssid->wep_key_len[i]);
    320  1.1.1.2  christos 			if (wep->key[i] == NULL)
    321  1.1.1.2  christos 				return -1;
    322  1.1.1.2  christos 			os_memcpy(wep->key[i], ssid->wep_key[i],
    323  1.1.1.2  christos 				  ssid->wep_key_len[i]);
    324  1.1.1.2  christos 			wep->len[i] = ssid->wep_key_len[i];
    325  1.1.1.2  christos 		}
    326  1.1.1.2  christos 		wep->idx = ssid->wep_tx_keyidx;
    327  1.1.1.2  christos 		wep->keys_set = 1;
    328      1.1  christos 	}
    329      1.1  christos 
    330  1.1.1.3  christos 	if (ssid->ap_max_inactivity)
    331  1.1.1.3  christos 		bss->ap_max_inactivity = ssid->ap_max_inactivity;
    332  1.1.1.3  christos 
    333  1.1.1.3  christos 	if (ssid->dtim_period)
    334  1.1.1.3  christos 		bss->dtim_period = ssid->dtim_period;
    335  1.1.1.4  christos 	else if (wpa_s->conf->dtim_period)
    336  1.1.1.4  christos 		bss->dtim_period = wpa_s->conf->dtim_period;
    337  1.1.1.3  christos 
    338  1.1.1.4  christos 	if (ssid->beacon_int)
    339  1.1.1.4  christos 		conf->beacon_int = ssid->beacon_int;
    340  1.1.1.4  christos 	else if (wpa_s->conf->beacon_int)
    341  1.1.1.4  christos 		conf->beacon_int = wpa_s->conf->beacon_int;
    342  1.1.1.4  christos 
    343  1.1.1.5  christos #ifdef CONFIG_P2P
    344  1.1.1.6  christos 	if (ssid->mode == WPAS_MODE_P2P_GO ||
    345  1.1.1.6  christos 	    ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION) {
    346  1.1.1.6  christos 		if (wpa_s->conf->p2p_go_ctwindow > conf->beacon_int) {
    347  1.1.1.6  christos 			wpa_printf(MSG_INFO,
    348  1.1.1.6  christos 				   "CTWindow (%d) is bigger than beacon interval (%d) - avoid configuring it",
    349  1.1.1.6  christos 				   wpa_s->conf->p2p_go_ctwindow,
    350  1.1.1.6  christos 				   conf->beacon_int);
    351  1.1.1.6  christos 			conf->p2p_go_ctwindow = 0;
    352  1.1.1.6  christos 		} else {
    353  1.1.1.6  christos 			conf->p2p_go_ctwindow = wpa_s->conf->p2p_go_ctwindow;
    354  1.1.1.6  christos 		}
    355  1.1.1.5  christos 	}
    356  1.1.1.5  christos #endif /* CONFIG_P2P */
    357  1.1.1.5  christos 
    358  1.1.1.4  christos 	if ((bss->wpa & 2) && bss->rsn_pairwise == 0)
    359  1.1.1.4  christos 		bss->rsn_pairwise = bss->wpa_pairwise;
    360  1.1.1.4  christos 	bss->wpa_group = wpa_select_ap_group_cipher(bss->wpa, bss->wpa_pairwise,
    361  1.1.1.4  christos 						    bss->rsn_pairwise);
    362      1.1  christos 
    363      1.1  christos 	if (bss->wpa && bss->ieee802_1x)
    364      1.1  christos 		bss->ssid.security_policy = SECURITY_WPA;
    365      1.1  christos 	else if (bss->wpa)
    366      1.1  christos 		bss->ssid.security_policy = SECURITY_WPA_PSK;
    367      1.1  christos 	else if (bss->ieee802_1x) {
    368  1.1.1.2  christos 		int cipher = WPA_CIPHER_NONE;
    369      1.1  christos 		bss->ssid.security_policy = SECURITY_IEEE_802_1X;
    370      1.1  christos 		bss->ssid.wep.default_len = bss->default_wep_key_len;
    371  1.1.1.2  christos 		if (bss->default_wep_key_len)
    372  1.1.1.2  christos 			cipher = bss->default_wep_key_len >= 13 ?
    373  1.1.1.2  christos 				WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
    374  1.1.1.2  christos 		bss->wpa_group = cipher;
    375  1.1.1.2  christos 		bss->wpa_pairwise = cipher;
    376  1.1.1.2  christos 		bss->rsn_pairwise = cipher;
    377  1.1.1.2  christos 	} else if (bss->ssid.wep.keys_set) {
    378  1.1.1.2  christos 		int cipher = WPA_CIPHER_WEP40;
    379  1.1.1.2  christos 		if (bss->ssid.wep.len[0] >= 13)
    380  1.1.1.2  christos 			cipher = WPA_CIPHER_WEP104;
    381      1.1  christos 		bss->ssid.security_policy = SECURITY_STATIC_WEP;
    382  1.1.1.2  christos 		bss->wpa_group = cipher;
    383  1.1.1.2  christos 		bss->wpa_pairwise = cipher;
    384  1.1.1.2  christos 		bss->rsn_pairwise = cipher;
    385  1.1.1.2  christos 	} else {
    386      1.1  christos 		bss->ssid.security_policy = SECURITY_PLAINTEXT;
    387  1.1.1.2  christos 		bss->wpa_group = WPA_CIPHER_NONE;
    388  1.1.1.2  christos 		bss->wpa_pairwise = WPA_CIPHER_NONE;
    389  1.1.1.2  christos 		bss->rsn_pairwise = WPA_CIPHER_NONE;
    390  1.1.1.2  christos 	}
    391      1.1  christos 
    392  1.1.1.4  christos 	if (bss->wpa_group_rekey < 86400 && (bss->wpa & 2) &&
    393  1.1.1.4  christos 	    (bss->wpa_group == WPA_CIPHER_CCMP ||
    394  1.1.1.4  christos 	     bss->wpa_group == WPA_CIPHER_GCMP ||
    395  1.1.1.4  christos 	     bss->wpa_group == WPA_CIPHER_CCMP_256 ||
    396  1.1.1.4  christos 	     bss->wpa_group == WPA_CIPHER_GCMP_256)) {
    397  1.1.1.4  christos 		/*
    398  1.1.1.4  christos 		 * Strong ciphers do not need frequent rekeying, so increase
    399  1.1.1.4  christos 		 * the default GTK rekeying period to 24 hours.
    400  1.1.1.4  christos 		 */
    401  1.1.1.4  christos 		bss->wpa_group_rekey = 86400;
    402  1.1.1.4  christos 	}
    403  1.1.1.4  christos 
    404  1.1.1.4  christos #ifdef CONFIG_IEEE80211W
    405  1.1.1.4  christos 	if (ssid->ieee80211w != MGMT_FRAME_PROTECTION_DEFAULT)
    406  1.1.1.4  christos 		bss->ieee80211w = ssid->ieee80211w;
    407  1.1.1.4  christos #endif /* CONFIG_IEEE80211W */
    408  1.1.1.4  christos 
    409      1.1  christos #ifdef CONFIG_WPS
    410      1.1  christos 	/*
    411  1.1.1.2  christos 	 * Enable WPS by default for open and WPA/WPA2-Personal network, but
    412  1.1.1.2  christos 	 * require user interaction to actually use it. Only the internal
    413  1.1.1.2  christos 	 * Registrar is supported.
    414      1.1  christos 	 */
    415  1.1.1.2  christos 	if (bss->ssid.security_policy != SECURITY_WPA_PSK &&
    416  1.1.1.2  christos 	    bss->ssid.security_policy != SECURITY_PLAINTEXT)
    417  1.1.1.2  christos 		goto no_wps;
    418  1.1.1.2  christos 	if (bss->ssid.security_policy == SECURITY_WPA_PSK &&
    419  1.1.1.5  christos 	    (!(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP)) ||
    420  1.1.1.5  christos 	     !(bss->wpa & 2)))
    421  1.1.1.2  christos 		goto no_wps; /* WPS2 does not allow WPA/TKIP-only
    422  1.1.1.2  christos 			      * configuration */
    423  1.1.1.6  christos 	if (ssid->wps_disabled)
    424  1.1.1.6  christos 		goto no_wps;
    425      1.1  christos 	bss->eap_server = 1;
    426  1.1.1.3  christos 
    427  1.1.1.3  christos 	if (!ssid->ignore_broadcast_ssid)
    428  1.1.1.3  christos 		bss->wps_state = 2;
    429  1.1.1.3  christos 
    430  1.1.1.2  christos 	bss->ap_setup_locked = 2;
    431      1.1  christos 	if (wpa_s->conf->config_methods)
    432      1.1  christos 		bss->config_methods = os_strdup(wpa_s->conf->config_methods);
    433  1.1.1.2  christos 	os_memcpy(bss->device_type, wpa_s->conf->device_type,
    434  1.1.1.2  christos 		  WPS_DEV_TYPE_LEN);
    435  1.1.1.2  christos 	if (wpa_s->conf->device_name) {
    436  1.1.1.2  christos 		bss->device_name = os_strdup(wpa_s->conf->device_name);
    437  1.1.1.2  christos 		bss->friendly_name = os_strdup(wpa_s->conf->device_name);
    438  1.1.1.2  christos 	}
    439  1.1.1.2  christos 	if (wpa_s->conf->manufacturer)
    440  1.1.1.2  christos 		bss->manufacturer = os_strdup(wpa_s->conf->manufacturer);
    441  1.1.1.2  christos 	if (wpa_s->conf->model_name)
    442  1.1.1.2  christos 		bss->model_name = os_strdup(wpa_s->conf->model_name);
    443  1.1.1.2  christos 	if (wpa_s->conf->model_number)
    444  1.1.1.2  christos 		bss->model_number = os_strdup(wpa_s->conf->model_number);
    445  1.1.1.2  christos 	if (wpa_s->conf->serial_number)
    446  1.1.1.2  christos 		bss->serial_number = os_strdup(wpa_s->conf->serial_number);
    447  1.1.1.2  christos 	if (is_nil_uuid(wpa_s->conf->uuid))
    448  1.1.1.2  christos 		os_memcpy(bss->uuid, wpa_s->wps->uuid, WPS_UUID_LEN);
    449  1.1.1.2  christos 	else
    450  1.1.1.2  christos 		os_memcpy(bss->uuid, wpa_s->conf->uuid, WPS_UUID_LEN);
    451  1.1.1.2  christos 	os_memcpy(bss->os_version, wpa_s->conf->os_version, 4);
    452  1.1.1.3  christos 	bss->pbc_in_m1 = wpa_s->conf->pbc_in_m1;
    453  1.1.1.6  christos 	if (ssid->eap.fragment_size != DEFAULT_FRAGMENT_SIZE)
    454  1.1.1.6  christos 		bss->fragment_size = ssid->eap.fragment_size;
    455  1.1.1.2  christos no_wps:
    456      1.1  christos #endif /* CONFIG_WPS */
    457      1.1  christos 
    458  1.1.1.2  christos 	if (wpa_s->max_stations &&
    459  1.1.1.2  christos 	    wpa_s->max_stations < wpa_s->conf->max_num_sta)
    460  1.1.1.2  christos 		bss->max_num_sta = wpa_s->max_stations;
    461  1.1.1.2  christos 	else
    462  1.1.1.2  christos 		bss->max_num_sta = wpa_s->conf->max_num_sta;
    463  1.1.1.2  christos 
    464  1.1.1.2  christos 	bss->disassoc_low_ack = wpa_s->conf->disassoc_low_ack;
    465  1.1.1.2  christos 
    466  1.1.1.4  christos 	if (wpa_s->conf->ap_vendor_elements) {
    467  1.1.1.4  christos 		bss->vendor_elements =
    468  1.1.1.4  christos 			wpabuf_dup(wpa_s->conf->ap_vendor_elements);
    469  1.1.1.4  christos 	}
    470  1.1.1.4  christos 
    471  1.1.1.6  christos 	bss->ftm_responder = wpa_s->conf->ftm_responder;
    472  1.1.1.6  christos 	bss->ftm_initiator = wpa_s->conf->ftm_initiator;
    473  1.1.1.6  christos 
    474      1.1  christos 	return 0;
    475      1.1  christos }
    476      1.1  christos 
    477      1.1  christos 
    478      1.1  christos static void ap_public_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
    479      1.1  christos {
    480  1.1.1.2  christos #ifdef CONFIG_P2P
    481  1.1.1.2  christos 	struct wpa_supplicant *wpa_s = ctx;
    482  1.1.1.2  christos 	const struct ieee80211_mgmt *mgmt;
    483  1.1.1.2  christos 
    484  1.1.1.2  christos 	mgmt = (const struct ieee80211_mgmt *) buf;
    485  1.1.1.4  christos 	if (len < IEEE80211_HDRLEN + 1)
    486  1.1.1.4  christos 		return;
    487  1.1.1.4  christos 	if (mgmt->u.action.category != WLAN_ACTION_PUBLIC)
    488  1.1.1.2  christos 		return;
    489  1.1.1.2  christos 	wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
    490  1.1.1.2  christos 			   mgmt->u.action.category,
    491  1.1.1.4  christos 			   buf + IEEE80211_HDRLEN + 1,
    492  1.1.1.4  christos 			   len - IEEE80211_HDRLEN - 1, freq);
    493  1.1.1.2  christos #endif /* CONFIG_P2P */
    494  1.1.1.2  christos }
    495  1.1.1.2  christos 
    496  1.1.1.2  christos 
    497  1.1.1.2  christos static void ap_wps_event_cb(void *ctx, enum wps_event event,
    498  1.1.1.2  christos 			    union wps_event_data *data)
    499  1.1.1.2  christos {
    500  1.1.1.2  christos #ifdef CONFIG_P2P
    501  1.1.1.2  christos 	struct wpa_supplicant *wpa_s = ctx;
    502  1.1.1.2  christos 
    503  1.1.1.2  christos 	if (event == WPS_EV_FAIL) {
    504  1.1.1.2  christos 		struct wps_event_fail *fail = &data->fail;
    505  1.1.1.2  christos 
    506  1.1.1.6  christos 		if (wpa_s->p2pdev && wpa_s->p2pdev != wpa_s &&
    507  1.1.1.2  christos 		    wpa_s == wpa_s->global->p2p_group_formation) {
    508  1.1.1.2  christos 			/*
    509  1.1.1.2  christos 			 * src/ap/wps_hostapd.c has already sent this on the
    510  1.1.1.2  christos 			 * main interface, so only send on the parent interface
    511  1.1.1.2  christos 			 * here if needed.
    512  1.1.1.2  christos 			 */
    513  1.1.1.6  christos 			wpa_msg(wpa_s->p2pdev, MSG_INFO, WPS_EVENT_FAIL
    514  1.1.1.2  christos 				"msg=%d config_error=%d",
    515  1.1.1.2  christos 				fail->msg, fail->config_error);
    516  1.1.1.2  christos 		}
    517  1.1.1.2  christos 		wpas_p2p_wps_failed(wpa_s, fail);
    518  1.1.1.2  christos 	}
    519  1.1.1.2  christos #endif /* CONFIG_P2P */
    520  1.1.1.2  christos }
    521  1.1.1.2  christos 
    522  1.1.1.2  christos 
    523  1.1.1.2  christos static void ap_sta_authorized_cb(void *ctx, const u8 *mac_addr,
    524  1.1.1.2  christos 				 int authorized, const u8 *p2p_dev_addr)
    525  1.1.1.2  christos {
    526  1.1.1.2  christos 	wpas_notify_sta_authorized(ctx, mac_addr, authorized, p2p_dev_addr);
    527  1.1.1.2  christos }
    528  1.1.1.2  christos 
    529  1.1.1.2  christos 
    530  1.1.1.4  christos #ifdef CONFIG_P2P
    531  1.1.1.4  christos static void ap_new_psk_cb(void *ctx, const u8 *mac_addr, const u8 *p2p_dev_addr,
    532  1.1.1.4  christos 			  const u8 *psk, size_t psk_len)
    533  1.1.1.4  christos {
    534  1.1.1.4  christos 
    535  1.1.1.4  christos 	struct wpa_supplicant *wpa_s = ctx;
    536  1.1.1.4  christos 	if (wpa_s->ap_iface == NULL || wpa_s->current_ssid == NULL)
    537  1.1.1.4  christos 		return;
    538  1.1.1.4  christos 	wpas_p2p_new_psk_cb(wpa_s, mac_addr, p2p_dev_addr, psk, psk_len);
    539  1.1.1.4  christos }
    540  1.1.1.4  christos #endif /* CONFIG_P2P */
    541  1.1.1.4  christos 
    542  1.1.1.4  christos 
    543  1.1.1.2  christos static int ap_vendor_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
    544  1.1.1.2  christos {
    545  1.1.1.2  christos #ifdef CONFIG_P2P
    546  1.1.1.2  christos 	struct wpa_supplicant *wpa_s = ctx;
    547  1.1.1.2  christos 	const struct ieee80211_mgmt *mgmt;
    548  1.1.1.2  christos 
    549  1.1.1.2  christos 	mgmt = (const struct ieee80211_mgmt *) buf;
    550  1.1.1.4  christos 	if (len < IEEE80211_HDRLEN + 1)
    551  1.1.1.2  christos 		return -1;
    552  1.1.1.2  christos 	wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
    553  1.1.1.2  christos 			   mgmt->u.action.category,
    554  1.1.1.4  christos 			   buf + IEEE80211_HDRLEN + 1,
    555  1.1.1.4  christos 			   len - IEEE80211_HDRLEN - 1, freq);
    556  1.1.1.2  christos #endif /* CONFIG_P2P */
    557  1.1.1.2  christos 	return 0;
    558      1.1  christos }
    559      1.1  christos 
    560      1.1  christos 
    561  1.1.1.2  christos static int ap_probe_req_rx(void *ctx, const u8 *sa, const u8 *da,
    562  1.1.1.3  christos 			   const u8 *bssid, const u8 *ie, size_t ie_len,
    563  1.1.1.3  christos 			   int ssi_signal)
    564      1.1  christos {
    565  1.1.1.2  christos 	struct wpa_supplicant *wpa_s = ctx;
    566  1.1.1.6  christos 	unsigned int freq = 0;
    567  1.1.1.6  christos 
    568  1.1.1.6  christos 	if (wpa_s->ap_iface)
    569  1.1.1.6  christos 		freq = wpa_s->ap_iface->freq;
    570  1.1.1.6  christos 
    571  1.1.1.3  christos 	return wpas_p2p_probe_req_rx(wpa_s, sa, da, bssid, ie, ie_len,
    572  1.1.1.6  christos 				     freq, ssi_signal);
    573      1.1  christos }
    574      1.1  christos 
    575      1.1  christos 
    576      1.1  christos static void ap_wps_reg_success_cb(void *ctx, const u8 *mac_addr,
    577      1.1  christos 				  const u8 *uuid_e)
    578      1.1  christos {
    579  1.1.1.2  christos 	struct wpa_supplicant *wpa_s = ctx;
    580  1.1.1.2  christos 	wpas_p2p_wps_success(wpa_s, mac_addr, 1);
    581  1.1.1.2  christos }
    582  1.1.1.2  christos 
    583  1.1.1.2  christos 
    584  1.1.1.2  christos static void wpas_ap_configured_cb(void *ctx)
    585  1.1.1.2  christos {
    586  1.1.1.2  christos 	struct wpa_supplicant *wpa_s = ctx;
    587  1.1.1.2  christos 
    588  1.1.1.6  christos #ifdef CONFIG_ACS
    589  1.1.1.6  christos 	if (wpa_s->current_ssid && wpa_s->current_ssid->acs)
    590  1.1.1.6  christos 		wpa_s->assoc_freq = wpa_s->ap_iface->freq;
    591  1.1.1.6  christos #endif /* CONFIG_ACS */
    592  1.1.1.6  christos 
    593  1.1.1.2  christos 	wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
    594  1.1.1.2  christos 
    595  1.1.1.2  christos 	if (wpa_s->ap_configured_cb)
    596  1.1.1.2  christos 		wpa_s->ap_configured_cb(wpa_s->ap_configured_cb_ctx,
    597  1.1.1.2  christos 					wpa_s->ap_configured_cb_data);
    598      1.1  christos }
    599      1.1  christos 
    600      1.1  christos 
    601      1.1  christos int wpa_supplicant_create_ap(struct wpa_supplicant *wpa_s,
    602      1.1  christos 			     struct wpa_ssid *ssid)
    603      1.1  christos {
    604      1.1  christos 	struct wpa_driver_associate_params params;
    605      1.1  christos 	struct hostapd_iface *hapd_iface;
    606      1.1  christos 	struct hostapd_config *conf;
    607      1.1  christos 	size_t i;
    608      1.1  christos 
    609      1.1  christos 	if (ssid->ssid == NULL || ssid->ssid_len == 0) {
    610      1.1  christos 		wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
    611      1.1  christos 		return -1;
    612      1.1  christos 	}
    613      1.1  christos 
    614      1.1  christos 	wpa_supplicant_ap_deinit(wpa_s);
    615      1.1  christos 
    616      1.1  christos 	wpa_printf(MSG_DEBUG, "Setting up AP (SSID='%s')",
    617      1.1  christos 		   wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
    618      1.1  christos 
    619      1.1  christos 	os_memset(&params, 0, sizeof(params));
    620      1.1  christos 	params.ssid = ssid->ssid;
    621      1.1  christos 	params.ssid_len = ssid->ssid_len;
    622      1.1  christos 	switch (ssid->mode) {
    623      1.1  christos 	case WPAS_MODE_AP:
    624  1.1.1.2  christos 	case WPAS_MODE_P2P_GO:
    625  1.1.1.2  christos 	case WPAS_MODE_P2P_GROUP_FORMATION:
    626      1.1  christos 		params.mode = IEEE80211_MODE_AP;
    627      1.1  christos 		break;
    628  1.1.1.4  christos 	default:
    629  1.1.1.4  christos 		return -1;
    630      1.1  christos 	}
    631  1.1.1.4  christos 	if (ssid->frequency == 0)
    632  1.1.1.4  christos 		ssid->frequency = 2462; /* default channel 11 */
    633  1.1.1.4  christos 	params.freq.freq = ssid->frequency;
    634      1.1  christos 
    635  1.1.1.2  christos 	params.wpa_proto = ssid->proto;
    636      1.1  christos 	if (ssid->key_mgmt & WPA_KEY_MGMT_PSK)
    637      1.1  christos 		wpa_s->key_mgmt = WPA_KEY_MGMT_PSK;
    638      1.1  christos 	else
    639      1.1  christos 		wpa_s->key_mgmt = WPA_KEY_MGMT_NONE;
    640  1.1.1.4  christos 	params.key_mgmt_suite = wpa_s->key_mgmt;
    641      1.1  christos 
    642  1.1.1.4  christos 	wpa_s->pairwise_cipher = wpa_pick_pairwise_cipher(ssid->pairwise_cipher,
    643  1.1.1.4  christos 							  1);
    644  1.1.1.4  christos 	if (wpa_s->pairwise_cipher < 0) {
    645      1.1  christos 		wpa_printf(MSG_WARNING, "WPA: Failed to select pairwise "
    646      1.1  christos 			   "cipher.");
    647      1.1  christos 		return -1;
    648      1.1  christos 	}
    649  1.1.1.4  christos 	params.pairwise_suite = wpa_s->pairwise_cipher;
    650      1.1  christos 	params.group_suite = params.pairwise_suite;
    651      1.1  christos 
    652  1.1.1.2  christos #ifdef CONFIG_P2P
    653  1.1.1.2  christos 	if (ssid->mode == WPAS_MODE_P2P_GO ||
    654  1.1.1.2  christos 	    ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
    655  1.1.1.2  christos 		params.p2p = 1;
    656  1.1.1.2  christos #endif /* CONFIG_P2P */
    657  1.1.1.2  christos 
    658  1.1.1.6  christos 	if (wpa_s->p2pdev->set_ap_uapsd)
    659  1.1.1.6  christos 		params.uapsd = wpa_s->p2pdev->ap_uapsd;
    660  1.1.1.4  christos 	else if (params.p2p && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP_UAPSD))
    661  1.1.1.4  christos 		params.uapsd = 1; /* mandatory for P2P GO */
    662  1.1.1.2  christos 	else
    663  1.1.1.2  christos 		params.uapsd = -1;
    664  1.1.1.2  christos 
    665  1.1.1.5  christos 	if (ieee80211_is_dfs(params.freq.freq))
    666  1.1.1.5  christos 		params.freq.freq = 0; /* set channel after CAC */
    667  1.1.1.5  christos 
    668  1.1.1.6  christos 	if (params.p2p)
    669  1.1.1.6  christos 		wpa_drv_get_ext_capa(wpa_s, WPA_IF_P2P_GO);
    670  1.1.1.6  christos 	else
    671  1.1.1.6  christos 		wpa_drv_get_ext_capa(wpa_s, WPA_IF_AP_BSS);
    672  1.1.1.6  christos 
    673      1.1  christos 	if (wpa_drv_associate(wpa_s, &params) < 0) {
    674      1.1  christos 		wpa_msg(wpa_s, MSG_INFO, "Failed to start AP functionality");
    675      1.1  christos 		return -1;
    676      1.1  christos 	}
    677      1.1  christos 
    678  1.1.1.6  christos 	wpa_s->ap_iface = hapd_iface = hostapd_alloc_iface();
    679      1.1  christos 	if (hapd_iface == NULL)
    680      1.1  christos 		return -1;
    681      1.1  christos 	hapd_iface->owner = wpa_s;
    682  1.1.1.2  christos 	hapd_iface->drv_flags = wpa_s->drv_flags;
    683  1.1.1.5  christos 	hapd_iface->smps_modes = wpa_s->drv_smps_modes;
    684  1.1.1.3  christos 	hapd_iface->probe_resp_offloads = wpa_s->probe_resp_offloads;
    685  1.1.1.4  christos 	hapd_iface->extended_capa = wpa_s->extended_capa;
    686  1.1.1.4  christos 	hapd_iface->extended_capa_mask = wpa_s->extended_capa_mask;
    687  1.1.1.4  christos 	hapd_iface->extended_capa_len = wpa_s->extended_capa_len;
    688      1.1  christos 
    689      1.1  christos 	wpa_s->ap_iface->conf = conf = hostapd_config_defaults();
    690      1.1  christos 	if (conf == NULL) {
    691      1.1  christos 		wpa_supplicant_ap_deinit(wpa_s);
    692      1.1  christos 		return -1;
    693      1.1  christos 	}
    694      1.1  christos 
    695  1.1.1.6  christos 	/* Use the maximum oper channel width if it's given. */
    696  1.1.1.6  christos 	if (ssid->max_oper_chwidth)
    697  1.1.1.6  christos 		conf->vht_oper_chwidth = ssid->max_oper_chwidth;
    698  1.1.1.6  christos 
    699  1.1.1.6  christos 	ieee80211_freq_to_chan(ssid->vht_center_freq2,
    700  1.1.1.6  christos 			       &conf->vht_oper_centr_freq_seg1_idx);
    701  1.1.1.6  christos 
    702  1.1.1.3  christos 	os_memcpy(wpa_s->ap_iface->conf->wmm_ac_params,
    703  1.1.1.3  christos 		  wpa_s->conf->wmm_ac_params,
    704  1.1.1.3  christos 		  sizeof(wpa_s->conf->wmm_ac_params));
    705  1.1.1.3  christos 
    706  1.1.1.2  christos 	if (params.uapsd > 0) {
    707  1.1.1.4  christos 		conf->bss[0]->wmm_enabled = 1;
    708  1.1.1.4  christos 		conf->bss[0]->wmm_uapsd = 1;
    709  1.1.1.2  christos 	}
    710  1.1.1.2  christos 
    711      1.1  christos 	if (wpa_supplicant_conf_ap(wpa_s, ssid, conf)) {
    712      1.1  christos 		wpa_printf(MSG_ERROR, "Failed to create AP configuration");
    713      1.1  christos 		wpa_supplicant_ap_deinit(wpa_s);
    714      1.1  christos 		return -1;
    715      1.1  christos 	}
    716      1.1  christos 
    717  1.1.1.2  christos #ifdef CONFIG_P2P
    718  1.1.1.2  christos 	if (ssid->mode == WPAS_MODE_P2P_GO)
    719  1.1.1.4  christos 		conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
    720  1.1.1.2  christos 	else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
    721  1.1.1.4  christos 		conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
    722  1.1.1.2  christos 			P2P_GROUP_FORMATION;
    723  1.1.1.2  christos #endif /* CONFIG_P2P */
    724  1.1.1.2  christos 
    725      1.1  christos 	hapd_iface->num_bss = conf->num_bss;
    726  1.1.1.3  christos 	hapd_iface->bss = os_calloc(conf->num_bss,
    727      1.1  christos 				    sizeof(struct hostapd_data *));
    728      1.1  christos 	if (hapd_iface->bss == NULL) {
    729      1.1  christos 		wpa_supplicant_ap_deinit(wpa_s);
    730      1.1  christos 		return -1;
    731      1.1  christos 	}
    732      1.1  christos 
    733      1.1  christos 	for (i = 0; i < conf->num_bss; i++) {
    734      1.1  christos 		hapd_iface->bss[i] =
    735      1.1  christos 			hostapd_alloc_bss_data(hapd_iface, conf,
    736  1.1.1.4  christos 					       conf->bss[i]);
    737      1.1  christos 		if (hapd_iface->bss[i] == NULL) {
    738      1.1  christos 			wpa_supplicant_ap_deinit(wpa_s);
    739      1.1  christos 			return -1;
    740      1.1  christos 		}
    741      1.1  christos 
    742      1.1  christos 		hapd_iface->bss[i]->msg_ctx = wpa_s;
    743  1.1.1.6  christos 		hapd_iface->bss[i]->msg_ctx_parent = wpa_s->p2pdev;
    744      1.1  christos 		hapd_iface->bss[i]->public_action_cb = ap_public_action_rx;
    745      1.1  christos 		hapd_iface->bss[i]->public_action_cb_ctx = wpa_s;
    746  1.1.1.2  christos 		hapd_iface->bss[i]->vendor_action_cb = ap_vendor_action_rx;
    747  1.1.1.2  christos 		hapd_iface->bss[i]->vendor_action_cb_ctx = wpa_s;
    748      1.1  christos 		hostapd_register_probereq_cb(hapd_iface->bss[i],
    749      1.1  christos 					     ap_probe_req_rx, wpa_s);
    750      1.1  christos 		hapd_iface->bss[i]->wps_reg_success_cb = ap_wps_reg_success_cb;
    751      1.1  christos 		hapd_iface->bss[i]->wps_reg_success_cb_ctx = wpa_s;
    752  1.1.1.2  christos 		hapd_iface->bss[i]->wps_event_cb = ap_wps_event_cb;
    753  1.1.1.2  christos 		hapd_iface->bss[i]->wps_event_cb_ctx = wpa_s;
    754  1.1.1.2  christos 		hapd_iface->bss[i]->sta_authorized_cb = ap_sta_authorized_cb;
    755  1.1.1.2  christos 		hapd_iface->bss[i]->sta_authorized_cb_ctx = wpa_s;
    756  1.1.1.2  christos #ifdef CONFIG_P2P
    757  1.1.1.4  christos 		hapd_iface->bss[i]->new_psk_cb = ap_new_psk_cb;
    758  1.1.1.4  christos 		hapd_iface->bss[i]->new_psk_cb_ctx = wpa_s;
    759  1.1.1.2  christos 		hapd_iface->bss[i]->p2p = wpa_s->global->p2p;
    760  1.1.1.3  christos 		hapd_iface->bss[i]->p2p_group = wpas_p2p_group_init(wpa_s,
    761  1.1.1.3  christos 								    ssid);
    762  1.1.1.2  christos #endif /* CONFIG_P2P */
    763  1.1.1.2  christos 		hapd_iface->bss[i]->setup_complete_cb = wpas_ap_configured_cb;
    764  1.1.1.2  christos 		hapd_iface->bss[i]->setup_complete_cb_ctx = wpa_s;
    765  1.1.1.5  christos #ifdef CONFIG_TESTING_OPTIONS
    766  1.1.1.5  christos 		hapd_iface->bss[i]->ext_eapol_frame_io =
    767  1.1.1.5  christos 			wpa_s->ext_eapol_frame_io;
    768  1.1.1.5  christos #endif /* CONFIG_TESTING_OPTIONS */
    769      1.1  christos 	}
    770      1.1  christos 
    771      1.1  christos 	os_memcpy(hapd_iface->bss[0]->own_addr, wpa_s->own_addr, ETH_ALEN);
    772      1.1  christos 	hapd_iface->bss[0]->driver = wpa_s->driver;
    773      1.1  christos 	hapd_iface->bss[0]->drv_priv = wpa_s->drv_priv;
    774      1.1  christos 
    775  1.1.1.2  christos 	wpa_s->current_ssid = ssid;
    776  1.1.1.4  christos 	eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
    777  1.1.1.2  christos 	os_memcpy(wpa_s->bssid, wpa_s->own_addr, ETH_ALEN);
    778  1.1.1.2  christos 	wpa_s->assoc_freq = ssid->frequency;
    779  1.1.1.2  christos 
    780      1.1  christos 	if (hostapd_setup_interface(wpa_s->ap_iface)) {
    781      1.1  christos 		wpa_printf(MSG_ERROR, "Failed to initialize AP interface");
    782      1.1  christos 		wpa_supplicant_ap_deinit(wpa_s);
    783      1.1  christos 		return -1;
    784      1.1  christos 	}
    785      1.1  christos 
    786      1.1  christos 	return 0;
    787      1.1  christos }
    788      1.1  christos 
    789      1.1  christos 
    790      1.1  christos void wpa_supplicant_ap_deinit(struct wpa_supplicant *wpa_s)
    791      1.1  christos {
    792  1.1.1.2  christos #ifdef CONFIG_WPS
    793  1.1.1.2  christos 	eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
    794  1.1.1.2  christos #endif /* CONFIG_WPS */
    795  1.1.1.2  christos 
    796      1.1  christos 	if (wpa_s->ap_iface == NULL)
    797      1.1  christos 		return;
    798      1.1  christos 
    799      1.1  christos 	wpa_s->current_ssid = NULL;
    800  1.1.1.4  christos 	eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
    801  1.1.1.2  christos 	wpa_s->assoc_freq = 0;
    802  1.1.1.4  christos 	wpas_p2p_ap_deinit(wpa_s);
    803  1.1.1.4  christos 	wpa_s->ap_iface->driver_ap_teardown =
    804  1.1.1.4  christos 		!!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT);
    805  1.1.1.4  christos 
    806      1.1  christos 	hostapd_interface_deinit(wpa_s->ap_iface);
    807      1.1  christos 	hostapd_interface_free(wpa_s->ap_iface);
    808      1.1  christos 	wpa_s->ap_iface = NULL;
    809      1.1  christos 	wpa_drv_deinit_ap(wpa_s);
    810  1.1.1.5  christos 	wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
    811  1.1.1.5  christos 		" reason=%d locally_generated=1",
    812  1.1.1.5  christos 		MAC2STR(wpa_s->own_addr), WLAN_REASON_DEAUTH_LEAVING);
    813      1.1  christos }
    814      1.1  christos 
    815      1.1  christos 
    816      1.1  christos void ap_tx_status(void *ctx, const u8 *addr,
    817      1.1  christos 		  const u8 *buf, size_t len, int ack)
    818      1.1  christos {
    819      1.1  christos #ifdef NEED_AP_MLME
    820      1.1  christos 	struct wpa_supplicant *wpa_s = ctx;
    821      1.1  christos 	hostapd_tx_status(wpa_s->ap_iface->bss[0], addr, buf, len, ack);
    822      1.1  christos #endif /* NEED_AP_MLME */
    823      1.1  christos }
    824      1.1  christos 
    825      1.1  christos 
    826  1.1.1.3  christos void ap_eapol_tx_status(void *ctx, const u8 *dst,
    827  1.1.1.3  christos 			const u8 *data, size_t len, int ack)
    828  1.1.1.3  christos {
    829  1.1.1.3  christos #ifdef NEED_AP_MLME
    830  1.1.1.3  christos 	struct wpa_supplicant *wpa_s = ctx;
    831  1.1.1.4  christos 	if (!wpa_s->ap_iface)
    832  1.1.1.4  christos 		return;
    833  1.1.1.3  christos 	hostapd_tx_status(wpa_s->ap_iface->bss[0], dst, data, len, ack);
    834  1.1.1.3  christos #endif /* NEED_AP_MLME */
    835  1.1.1.3  christos }
    836  1.1.1.3  christos 
    837  1.1.1.3  christos 
    838  1.1.1.2  christos void ap_client_poll_ok(void *ctx, const u8 *addr)
    839      1.1  christos {
    840      1.1  christos #ifdef NEED_AP_MLME
    841      1.1  christos 	struct wpa_supplicant *wpa_s = ctx;
    842  1.1.1.2  christos 	if (wpa_s->ap_iface)
    843  1.1.1.2  christos 		hostapd_client_poll_ok(wpa_s->ap_iface->bss[0], addr);
    844  1.1.1.2  christos #endif /* NEED_AP_MLME */
    845  1.1.1.2  christos }
    846  1.1.1.2  christos 
    847  1.1.1.2  christos 
    848  1.1.1.2  christos void ap_rx_from_unknown_sta(void *ctx, const u8 *addr, int wds)
    849  1.1.1.2  christos {
    850  1.1.1.2  christos #ifdef NEED_AP_MLME
    851  1.1.1.2  christos 	struct wpa_supplicant *wpa_s = ctx;
    852  1.1.1.2  christos 	ieee802_11_rx_from_unknown(wpa_s->ap_iface->bss[0], addr, wds);
    853      1.1  christos #endif /* NEED_AP_MLME */
    854      1.1  christos }
    855      1.1  christos 
    856      1.1  christos 
    857      1.1  christos void ap_mgmt_rx(void *ctx, struct rx_mgmt *rx_mgmt)
    858      1.1  christos {
    859      1.1  christos #ifdef NEED_AP_MLME
    860      1.1  christos 	struct wpa_supplicant *wpa_s = ctx;
    861      1.1  christos 	struct hostapd_frame_info fi;
    862      1.1  christos 	os_memset(&fi, 0, sizeof(fi));
    863      1.1  christos 	fi.datarate = rx_mgmt->datarate;
    864      1.1  christos 	fi.ssi_signal = rx_mgmt->ssi_signal;
    865      1.1  christos 	ieee802_11_mgmt(wpa_s->ap_iface->bss[0], rx_mgmt->frame,
    866      1.1  christos 			rx_mgmt->frame_len, &fi);
    867      1.1  christos #endif /* NEED_AP_MLME */
    868      1.1  christos }
    869      1.1  christos 
    870      1.1  christos 
    871      1.1  christos void ap_mgmt_tx_cb(void *ctx, const u8 *buf, size_t len, u16 stype, int ok)
    872      1.1  christos {
    873      1.1  christos #ifdef NEED_AP_MLME
    874      1.1  christos 	struct wpa_supplicant *wpa_s = ctx;
    875      1.1  christos 	ieee802_11_mgmt_cb(wpa_s->ap_iface->bss[0], buf, len, stype, ok);
    876      1.1  christos #endif /* NEED_AP_MLME */
    877      1.1  christos }
    878      1.1  christos 
    879      1.1  christos 
    880      1.1  christos void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant *wpa_s,
    881      1.1  christos 				const u8 *src_addr, const u8 *buf, size_t len)
    882      1.1  christos {
    883      1.1  christos 	ieee802_1x_receive(wpa_s->ap_iface->bss[0], src_addr, buf, len);
    884      1.1  christos }
    885      1.1  christos 
    886      1.1  christos 
    887      1.1  christos #ifdef CONFIG_WPS
    888      1.1  christos 
    889  1.1.1.2  christos int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid,
    890  1.1.1.2  christos 			      const u8 *p2p_dev_addr)
    891      1.1  christos {
    892      1.1  christos 	if (!wpa_s->ap_iface)
    893      1.1  christos 		return -1;
    894  1.1.1.2  christos 	return hostapd_wps_button_pushed(wpa_s->ap_iface->bss[0],
    895  1.1.1.2  christos 					 p2p_dev_addr);
    896  1.1.1.2  christos }
    897  1.1.1.2  christos 
    898  1.1.1.2  christos 
    899  1.1.1.2  christos int wpa_supplicant_ap_wps_cancel(struct wpa_supplicant *wpa_s)
    900  1.1.1.2  christos {
    901  1.1.1.2  christos 	struct wps_registrar *reg;
    902  1.1.1.2  christos 	int reg_sel = 0, wps_sta = 0;
    903  1.1.1.2  christos 
    904  1.1.1.2  christos 	if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0]->wps)
    905  1.1.1.2  christos 		return -1;
    906  1.1.1.2  christos 
    907  1.1.1.2  christos 	reg = wpa_s->ap_iface->bss[0]->wps->registrar;
    908  1.1.1.2  christos 	reg_sel = wps_registrar_wps_cancel(reg);
    909  1.1.1.2  christos 	wps_sta = ap_for_each_sta(wpa_s->ap_iface->bss[0],
    910  1.1.1.3  christos 				  ap_sta_wps_cancel, NULL);
    911  1.1.1.2  christos 
    912  1.1.1.2  christos 	if (!reg_sel && !wps_sta) {
    913  1.1.1.2  christos 		wpa_printf(MSG_DEBUG, "No WPS operation in progress at this "
    914  1.1.1.2  christos 			   "time");
    915  1.1.1.2  christos 		return -1;
    916  1.1.1.2  christos 	}
    917  1.1.1.2  christos 
    918  1.1.1.2  christos 	/*
    919  1.1.1.2  christos 	 * There are 2 cases to return wps cancel as success:
    920  1.1.1.2  christos 	 * 1. When wps cancel was initiated but no connection has been
    921  1.1.1.2  christos 	 *    established with client yet.
    922  1.1.1.2  christos 	 * 2. Client is in the middle of exchanging WPS messages.
    923  1.1.1.2  christos 	 */
    924  1.1.1.2  christos 
    925  1.1.1.2  christos 	return 0;
    926      1.1  christos }
    927      1.1  christos 
    928      1.1  christos 
    929      1.1  christos int wpa_supplicant_ap_wps_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
    930  1.1.1.3  christos 			      const char *pin, char *buf, size_t buflen,
    931  1.1.1.3  christos 			      int timeout)
    932      1.1  christos {
    933      1.1  christos 	int ret, ret_len = 0;
    934      1.1  christos 
    935      1.1  christos 	if (!wpa_s->ap_iface)
    936      1.1  christos 		return -1;
    937      1.1  christos 
    938      1.1  christos 	if (pin == NULL) {
    939  1.1.1.6  christos 		unsigned int rpin;
    940  1.1.1.6  christos 
    941  1.1.1.6  christos 		if (wps_generate_pin(&rpin) < 0)
    942  1.1.1.6  christos 			return -1;
    943  1.1.1.2  christos 		ret_len = os_snprintf(buf, buflen, "%08d", rpin);
    944  1.1.1.5  christos 		if (os_snprintf_error(buflen, ret_len))
    945  1.1.1.5  christos 			return -1;
    946      1.1  christos 		pin = buf;
    947  1.1.1.5  christos 	} else if (buf) {
    948  1.1.1.2  christos 		ret_len = os_snprintf(buf, buflen, "%s", pin);
    949  1.1.1.5  christos 		if (os_snprintf_error(buflen, ret_len))
    950  1.1.1.5  christos 			return -1;
    951  1.1.1.5  christos 	}
    952      1.1  christos 
    953  1.1.1.2  christos 	ret = hostapd_wps_add_pin(wpa_s->ap_iface->bss[0], bssid, "any", pin,
    954  1.1.1.3  christos 				  timeout);
    955      1.1  christos 	if (ret)
    956      1.1  christos 		return -1;
    957      1.1  christos 	return ret_len;
    958      1.1  christos }
    959      1.1  christos 
    960  1.1.1.2  christos 
    961  1.1.1.2  christos static void wpas_wps_ap_pin_timeout(void *eloop_data, void *user_ctx)
    962  1.1.1.2  christos {
    963  1.1.1.2  christos 	struct wpa_supplicant *wpa_s = eloop_data;
    964  1.1.1.2  christos 	wpa_printf(MSG_DEBUG, "WPS: AP PIN timed out");
    965  1.1.1.2  christos 	wpas_wps_ap_pin_disable(wpa_s);
    966  1.1.1.2  christos }
    967  1.1.1.2  christos 
    968  1.1.1.2  christos 
    969  1.1.1.2  christos static void wpas_wps_ap_pin_enable(struct wpa_supplicant *wpa_s, int timeout)
    970  1.1.1.2  christos {
    971  1.1.1.2  christos 	struct hostapd_data *hapd;
    972  1.1.1.2  christos 
    973  1.1.1.2  christos 	if (wpa_s->ap_iface == NULL)
    974  1.1.1.2  christos 		return;
    975  1.1.1.2  christos 	hapd = wpa_s->ap_iface->bss[0];
    976  1.1.1.2  christos 	wpa_printf(MSG_DEBUG, "WPS: Enabling AP PIN (timeout=%d)", timeout);
    977  1.1.1.2  christos 	hapd->ap_pin_failures = 0;
    978  1.1.1.2  christos 	eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
    979  1.1.1.2  christos 	if (timeout > 0)
    980  1.1.1.2  christos 		eloop_register_timeout(timeout, 0,
    981  1.1.1.2  christos 				       wpas_wps_ap_pin_timeout, wpa_s, NULL);
    982  1.1.1.2  christos }
    983  1.1.1.2  christos 
    984  1.1.1.2  christos 
    985  1.1.1.2  christos void wpas_wps_ap_pin_disable(struct wpa_supplicant *wpa_s)
    986  1.1.1.2  christos {
    987  1.1.1.2  christos 	struct hostapd_data *hapd;
    988  1.1.1.2  christos 
    989  1.1.1.2  christos 	if (wpa_s->ap_iface == NULL)
    990  1.1.1.2  christos 		return;
    991  1.1.1.2  christos 	wpa_printf(MSG_DEBUG, "WPS: Disabling AP PIN");
    992  1.1.1.2  christos 	hapd = wpa_s->ap_iface->bss[0];
    993  1.1.1.2  christos 	os_free(hapd->conf->ap_pin);
    994  1.1.1.2  christos 	hapd->conf->ap_pin = NULL;
    995  1.1.1.2  christos 	eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
    996  1.1.1.2  christos }
    997  1.1.1.2  christos 
    998  1.1.1.2  christos 
    999  1.1.1.2  christos const char * wpas_wps_ap_pin_random(struct wpa_supplicant *wpa_s, int timeout)
   1000  1.1.1.2  christos {
   1001  1.1.1.2  christos 	struct hostapd_data *hapd;
   1002  1.1.1.2  christos 	unsigned int pin;
   1003  1.1.1.2  christos 	char pin_txt[9];
   1004  1.1.1.2  christos 
   1005  1.1.1.2  christos 	if (wpa_s->ap_iface == NULL)
   1006  1.1.1.2  christos 		return NULL;
   1007  1.1.1.2  christos 	hapd = wpa_s->ap_iface->bss[0];
   1008  1.1.1.6  christos 	if (wps_generate_pin(&pin) < 0)
   1009  1.1.1.6  christos 		return NULL;
   1010  1.1.1.2  christos 	os_snprintf(pin_txt, sizeof(pin_txt), "%08u", pin);
   1011  1.1.1.2  christos 	os_free(hapd->conf->ap_pin);
   1012  1.1.1.2  christos 	hapd->conf->ap_pin = os_strdup(pin_txt);
   1013  1.1.1.2  christos 	if (hapd->conf->ap_pin == NULL)
   1014  1.1.1.2  christos 		return NULL;
   1015  1.1.1.2  christos 	wpas_wps_ap_pin_enable(wpa_s, timeout);
   1016  1.1.1.2  christos 
   1017  1.1.1.2  christos 	return hapd->conf->ap_pin;
   1018  1.1.1.2  christos }
   1019  1.1.1.2  christos 
   1020  1.1.1.2  christos 
   1021  1.1.1.2  christos const char * wpas_wps_ap_pin_get(struct wpa_supplicant *wpa_s)
   1022  1.1.1.2  christos {
   1023  1.1.1.2  christos 	struct hostapd_data *hapd;
   1024  1.1.1.2  christos 	if (wpa_s->ap_iface == NULL)
   1025  1.1.1.2  christos 		return NULL;
   1026  1.1.1.2  christos 	hapd = wpa_s->ap_iface->bss[0];
   1027  1.1.1.2  christos 	return hapd->conf->ap_pin;
   1028  1.1.1.2  christos }
   1029  1.1.1.2  christos 
   1030  1.1.1.2  christos 
   1031  1.1.1.2  christos int wpas_wps_ap_pin_set(struct wpa_supplicant *wpa_s, const char *pin,
   1032  1.1.1.2  christos 			int timeout)
   1033  1.1.1.2  christos {
   1034  1.1.1.2  christos 	struct hostapd_data *hapd;
   1035  1.1.1.2  christos 	char pin_txt[9];
   1036  1.1.1.2  christos 	int ret;
   1037  1.1.1.2  christos 
   1038  1.1.1.2  christos 	if (wpa_s->ap_iface == NULL)
   1039  1.1.1.2  christos 		return -1;
   1040  1.1.1.2  christos 	hapd = wpa_s->ap_iface->bss[0];
   1041  1.1.1.2  christos 	ret = os_snprintf(pin_txt, sizeof(pin_txt), "%s", pin);
   1042  1.1.1.5  christos 	if (os_snprintf_error(sizeof(pin_txt), ret))
   1043  1.1.1.2  christos 		return -1;
   1044  1.1.1.2  christos 	os_free(hapd->conf->ap_pin);
   1045  1.1.1.2  christos 	hapd->conf->ap_pin = os_strdup(pin_txt);
   1046  1.1.1.2  christos 	if (hapd->conf->ap_pin == NULL)
   1047  1.1.1.2  christos 		return -1;
   1048  1.1.1.2  christos 	wpas_wps_ap_pin_enable(wpa_s, timeout);
   1049  1.1.1.2  christos 
   1050  1.1.1.2  christos 	return 0;
   1051  1.1.1.2  christos }
   1052  1.1.1.2  christos 
   1053  1.1.1.2  christos 
   1054  1.1.1.2  christos void wpa_supplicant_ap_pwd_auth_fail(struct wpa_supplicant *wpa_s)
   1055  1.1.1.2  christos {
   1056  1.1.1.2  christos 	struct hostapd_data *hapd;
   1057  1.1.1.2  christos 
   1058  1.1.1.2  christos 	if (wpa_s->ap_iface == NULL)
   1059  1.1.1.2  christos 		return;
   1060  1.1.1.2  christos 	hapd = wpa_s->ap_iface->bss[0];
   1061  1.1.1.2  christos 
   1062  1.1.1.2  christos 	/*
   1063  1.1.1.2  christos 	 * Registrar failed to prove its knowledge of the AP PIN. Disable AP
   1064  1.1.1.2  christos 	 * PIN if this happens multiple times to slow down brute force attacks.
   1065  1.1.1.2  christos 	 */
   1066  1.1.1.2  christos 	hapd->ap_pin_failures++;
   1067  1.1.1.2  christos 	wpa_printf(MSG_DEBUG, "WPS: AP PIN authentication failure number %u",
   1068  1.1.1.2  christos 		   hapd->ap_pin_failures);
   1069  1.1.1.2  christos 	if (hapd->ap_pin_failures < 3)
   1070  1.1.1.2  christos 		return;
   1071  1.1.1.2  christos 
   1072  1.1.1.2  christos 	wpa_printf(MSG_DEBUG, "WPS: Disable AP PIN");
   1073  1.1.1.2  christos 	hapd->ap_pin_failures = 0;
   1074  1.1.1.2  christos 	os_free(hapd->conf->ap_pin);
   1075  1.1.1.2  christos 	hapd->conf->ap_pin = NULL;
   1076  1.1.1.2  christos }
   1077  1.1.1.2  christos 
   1078  1.1.1.4  christos 
   1079  1.1.1.4  christos #ifdef CONFIG_WPS_NFC
   1080  1.1.1.4  christos 
   1081  1.1.1.4  christos struct wpabuf * wpas_ap_wps_nfc_config_token(struct wpa_supplicant *wpa_s,
   1082  1.1.1.4  christos 					     int ndef)
   1083  1.1.1.4  christos {
   1084  1.1.1.4  christos 	struct hostapd_data *hapd;
   1085  1.1.1.4  christos 
   1086  1.1.1.4  christos 	if (wpa_s->ap_iface == NULL)
   1087  1.1.1.4  christos 		return NULL;
   1088  1.1.1.4  christos 	hapd = wpa_s->ap_iface->bss[0];
   1089  1.1.1.4  christos 	return hostapd_wps_nfc_config_token(hapd, ndef);
   1090  1.1.1.4  christos }
   1091  1.1.1.4  christos 
   1092  1.1.1.4  christos 
   1093  1.1.1.4  christos struct wpabuf * wpas_ap_wps_nfc_handover_sel(struct wpa_supplicant *wpa_s,
   1094  1.1.1.4  christos 					     int ndef)
   1095  1.1.1.4  christos {
   1096  1.1.1.4  christos 	struct hostapd_data *hapd;
   1097  1.1.1.4  christos 
   1098  1.1.1.4  christos 	if (wpa_s->ap_iface == NULL)
   1099  1.1.1.4  christos 		return NULL;
   1100  1.1.1.4  christos 	hapd = wpa_s->ap_iface->bss[0];
   1101  1.1.1.4  christos 	return hostapd_wps_nfc_hs_cr(hapd, ndef);
   1102  1.1.1.4  christos }
   1103  1.1.1.4  christos 
   1104  1.1.1.4  christos 
   1105  1.1.1.4  christos int wpas_ap_wps_nfc_report_handover(struct wpa_supplicant *wpa_s,
   1106  1.1.1.4  christos 				    const struct wpabuf *req,
   1107  1.1.1.4  christos 				    const struct wpabuf *sel)
   1108  1.1.1.4  christos {
   1109  1.1.1.4  christos 	struct hostapd_data *hapd;
   1110  1.1.1.4  christos 
   1111  1.1.1.4  christos 	if (wpa_s->ap_iface == NULL)
   1112  1.1.1.4  christos 		return -1;
   1113  1.1.1.4  christos 	hapd = wpa_s->ap_iface->bss[0];
   1114  1.1.1.4  christos 	return hostapd_wps_nfc_report_handover(hapd, req, sel);
   1115  1.1.1.4  christos }
   1116  1.1.1.4  christos 
   1117  1.1.1.4  christos #endif /* CONFIG_WPS_NFC */
   1118  1.1.1.4  christos 
   1119      1.1  christos #endif /* CONFIG_WPS */
   1120      1.1  christos 
   1121      1.1  christos 
   1122      1.1  christos #ifdef CONFIG_CTRL_IFACE
   1123      1.1  christos 
   1124      1.1  christos int ap_ctrl_iface_sta_first(struct wpa_supplicant *wpa_s,
   1125      1.1  christos 			    char *buf, size_t buflen)
   1126      1.1  christos {
   1127  1.1.1.5  christos 	struct hostapd_data *hapd;
   1128  1.1.1.5  christos 
   1129  1.1.1.5  christos 	if (wpa_s->ap_iface)
   1130  1.1.1.5  christos 		hapd = wpa_s->ap_iface->bss[0];
   1131  1.1.1.5  christos 	else if (wpa_s->ifmsh)
   1132  1.1.1.5  christos 		hapd = wpa_s->ifmsh->bss[0];
   1133  1.1.1.5  christos 	else
   1134      1.1  christos 		return -1;
   1135  1.1.1.5  christos 	return hostapd_ctrl_iface_sta_first(hapd, buf, buflen);
   1136      1.1  christos }
   1137      1.1  christos 
   1138      1.1  christos 
   1139      1.1  christos int ap_ctrl_iface_sta(struct wpa_supplicant *wpa_s, const char *txtaddr,
   1140      1.1  christos 		      char *buf, size_t buflen)
   1141      1.1  christos {
   1142  1.1.1.5  christos 	struct hostapd_data *hapd;
   1143  1.1.1.5  christos 
   1144  1.1.1.5  christos 	if (wpa_s->ap_iface)
   1145  1.1.1.5  christos 		hapd = wpa_s->ap_iface->bss[0];
   1146  1.1.1.5  christos 	else if (wpa_s->ifmsh)
   1147  1.1.1.5  christos 		hapd = wpa_s->ifmsh->bss[0];
   1148  1.1.1.5  christos 	else
   1149      1.1  christos 		return -1;
   1150  1.1.1.5  christos 	return hostapd_ctrl_iface_sta(hapd, txtaddr, buf, buflen);
   1151      1.1  christos }
   1152      1.1  christos 
   1153      1.1  christos 
   1154      1.1  christos int ap_ctrl_iface_sta_next(struct wpa_supplicant *wpa_s, const char *txtaddr,
   1155      1.1  christos 			   char *buf, size_t buflen)
   1156      1.1  christos {
   1157  1.1.1.5  christos 	struct hostapd_data *hapd;
   1158  1.1.1.5  christos 
   1159  1.1.1.5  christos 	if (wpa_s->ap_iface)
   1160  1.1.1.5  christos 		hapd = wpa_s->ap_iface->bss[0];
   1161  1.1.1.5  christos 	else if (wpa_s->ifmsh)
   1162  1.1.1.5  christos 		hapd = wpa_s->ifmsh->bss[0];
   1163  1.1.1.5  christos 	else
   1164      1.1  christos 		return -1;
   1165  1.1.1.5  christos 	return hostapd_ctrl_iface_sta_next(hapd, txtaddr, buf, buflen);
   1166      1.1  christos }
   1167      1.1  christos 
   1168      1.1  christos 
   1169  1.1.1.3  christos int ap_ctrl_iface_sta_disassociate(struct wpa_supplicant *wpa_s,
   1170  1.1.1.3  christos 				   const char *txtaddr)
   1171  1.1.1.3  christos {
   1172  1.1.1.3  christos 	if (wpa_s->ap_iface == NULL)
   1173  1.1.1.3  christos 		return -1;
   1174  1.1.1.3  christos 	return hostapd_ctrl_iface_disassociate(wpa_s->ap_iface->bss[0],
   1175  1.1.1.3  christos 					       txtaddr);
   1176  1.1.1.3  christos }
   1177  1.1.1.3  christos 
   1178  1.1.1.3  christos 
   1179  1.1.1.3  christos int ap_ctrl_iface_sta_deauthenticate(struct wpa_supplicant *wpa_s,
   1180  1.1.1.3  christos 				     const char *txtaddr)
   1181  1.1.1.3  christos {
   1182  1.1.1.3  christos 	if (wpa_s->ap_iface == NULL)
   1183  1.1.1.3  christos 		return -1;
   1184  1.1.1.3  christos 	return hostapd_ctrl_iface_deauthenticate(wpa_s->ap_iface->bss[0],
   1185  1.1.1.3  christos 						 txtaddr);
   1186  1.1.1.3  christos }
   1187  1.1.1.3  christos 
   1188  1.1.1.3  christos 
   1189      1.1  christos int ap_ctrl_iface_wpa_get_status(struct wpa_supplicant *wpa_s, char *buf,
   1190      1.1  christos 				 size_t buflen, int verbose)
   1191      1.1  christos {
   1192      1.1  christos 	char *pos = buf, *end = buf + buflen;
   1193      1.1  christos 	int ret;
   1194      1.1  christos 	struct hostapd_bss_config *conf;
   1195      1.1  christos 
   1196      1.1  christos 	if (wpa_s->ap_iface == NULL)
   1197      1.1  christos 		return -1;
   1198      1.1  christos 
   1199      1.1  christos 	conf = wpa_s->ap_iface->bss[0]->conf;
   1200      1.1  christos 	if (conf->wpa == 0)
   1201      1.1  christos 		return 0;
   1202      1.1  christos 
   1203      1.1  christos 	ret = os_snprintf(pos, end - pos,
   1204      1.1  christos 			  "pairwise_cipher=%s\n"
   1205      1.1  christos 			  "group_cipher=%s\n"
   1206      1.1  christos 			  "key_mgmt=%s\n",
   1207      1.1  christos 			  wpa_cipher_txt(conf->rsn_pairwise),
   1208      1.1  christos 			  wpa_cipher_txt(conf->wpa_group),
   1209      1.1  christos 			  wpa_key_mgmt_txt(conf->wpa_key_mgmt,
   1210      1.1  christos 					   conf->wpa));
   1211  1.1.1.5  christos 	if (os_snprintf_error(end - pos, ret))
   1212      1.1  christos 		return pos - buf;
   1213      1.1  christos 	pos += ret;
   1214      1.1  christos 	return pos - buf;
   1215      1.1  christos }
   1216      1.1  christos 
   1217      1.1  christos #endif /* CONFIG_CTRL_IFACE */
   1218      1.1  christos 
   1219      1.1  christos 
   1220  1.1.1.2  christos int wpa_supplicant_ap_update_beacon(struct wpa_supplicant *wpa_s)
   1221  1.1.1.2  christos {
   1222  1.1.1.2  christos 	struct hostapd_iface *iface = wpa_s->ap_iface;
   1223  1.1.1.2  christos 	struct wpa_ssid *ssid = wpa_s->current_ssid;
   1224  1.1.1.2  christos 	struct hostapd_data *hapd;
   1225  1.1.1.2  christos 
   1226  1.1.1.2  christos 	if (ssid == NULL || wpa_s->ap_iface == NULL ||
   1227  1.1.1.2  christos 	    ssid->mode == WPAS_MODE_INFRA ||
   1228  1.1.1.2  christos 	    ssid->mode == WPAS_MODE_IBSS)
   1229  1.1.1.2  christos 		return -1;
   1230  1.1.1.2  christos 
   1231  1.1.1.2  christos #ifdef CONFIG_P2P
   1232  1.1.1.2  christos 	if (ssid->mode == WPAS_MODE_P2P_GO)
   1233  1.1.1.4  christos 		iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
   1234  1.1.1.2  christos 	else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
   1235  1.1.1.4  christos 		iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
   1236  1.1.1.2  christos 			P2P_GROUP_FORMATION;
   1237  1.1.1.2  christos #endif /* CONFIG_P2P */
   1238  1.1.1.2  christos 
   1239  1.1.1.2  christos 	hapd = iface->bss[0];
   1240  1.1.1.2  christos 	if (hapd->drv_priv == NULL)
   1241  1.1.1.2  christos 		return -1;
   1242  1.1.1.2  christos 	ieee802_11_set_beacons(iface);
   1243  1.1.1.2  christos 	hostapd_set_ap_wps_ie(hapd);
   1244  1.1.1.2  christos 
   1245  1.1.1.2  christos 	return 0;
   1246  1.1.1.2  christos }
   1247  1.1.1.2  christos 
   1248  1.1.1.2  christos 
   1249  1.1.1.4  christos int ap_switch_channel(struct wpa_supplicant *wpa_s,
   1250  1.1.1.4  christos 		      struct csa_settings *settings)
   1251  1.1.1.4  christos {
   1252  1.1.1.4  christos #ifdef NEED_AP_MLME
   1253  1.1.1.4  christos 	if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0])
   1254  1.1.1.4  christos 		return -1;
   1255  1.1.1.4  christos 
   1256  1.1.1.4  christos 	return hostapd_switch_channel(wpa_s->ap_iface->bss[0], settings);
   1257  1.1.1.4  christos #else /* NEED_AP_MLME */
   1258  1.1.1.4  christos 	return -1;
   1259  1.1.1.4  christos #endif /* NEED_AP_MLME */
   1260  1.1.1.4  christos }
   1261  1.1.1.4  christos 
   1262  1.1.1.4  christos 
   1263  1.1.1.6  christos #ifdef CONFIG_CTRL_IFACE
   1264  1.1.1.4  christos int ap_ctrl_iface_chanswitch(struct wpa_supplicant *wpa_s, const char *pos)
   1265  1.1.1.4  christos {
   1266  1.1.1.4  christos 	struct csa_settings settings;
   1267  1.1.1.4  christos 	int ret = hostapd_parse_csa_settings(pos, &settings);
   1268  1.1.1.4  christos 
   1269  1.1.1.4  christos 	if (ret)
   1270  1.1.1.4  christos 		return ret;
   1271  1.1.1.4  christos 
   1272  1.1.1.4  christos 	return ap_switch_channel(wpa_s, &settings);
   1273  1.1.1.4  christos }
   1274  1.1.1.6  christos #endif /* CONFIG_CTRL_IFACE */
   1275  1.1.1.4  christos 
   1276  1.1.1.4  christos 
   1277  1.1.1.3  christos void wpas_ap_ch_switch(struct wpa_supplicant *wpa_s, int freq, int ht,
   1278  1.1.1.4  christos 		       int offset, int width, int cf1, int cf2)
   1279  1.1.1.3  christos {
   1280  1.1.1.3  christos 	if (!wpa_s->ap_iface)
   1281  1.1.1.3  christos 		return;
   1282  1.1.1.3  christos 
   1283  1.1.1.3  christos 	wpa_s->assoc_freq = freq;
   1284  1.1.1.6  christos 	if (wpa_s->current_ssid)
   1285  1.1.1.6  christos 		wpa_s->current_ssid->frequency = freq;
   1286  1.1.1.6  christos 	hostapd_event_ch_switch(wpa_s->ap_iface->bss[0], freq, ht,
   1287  1.1.1.6  christos 				offset, width, cf1, cf2);
   1288  1.1.1.3  christos }
   1289  1.1.1.3  christos 
   1290  1.1.1.3  christos 
   1291      1.1  christos int wpa_supplicant_ap_mac_addr_filter(struct wpa_supplicant *wpa_s,
   1292      1.1  christos 				      const u8 *addr)
   1293      1.1  christos {
   1294      1.1  christos 	struct hostapd_data *hapd;
   1295      1.1  christos 	struct hostapd_bss_config *conf;
   1296      1.1  christos 
   1297      1.1  christos 	if (!wpa_s->ap_iface)
   1298      1.1  christos 		return -1;
   1299      1.1  christos 
   1300      1.1  christos 	if (addr)
   1301      1.1  christos 		wpa_printf(MSG_DEBUG, "AP: Set MAC address filter: " MACSTR,
   1302      1.1  christos 			   MAC2STR(addr));
   1303      1.1  christos 	else
   1304      1.1  christos 		wpa_printf(MSG_DEBUG, "AP: Clear MAC address filter");
   1305      1.1  christos 
   1306      1.1  christos 	hapd = wpa_s->ap_iface->bss[0];
   1307      1.1  christos 	conf = hapd->conf;
   1308      1.1  christos 
   1309      1.1  christos 	os_free(conf->accept_mac);
   1310      1.1  christos 	conf->accept_mac = NULL;
   1311      1.1  christos 	conf->num_accept_mac = 0;
   1312      1.1  christos 	os_free(conf->deny_mac);
   1313      1.1  christos 	conf->deny_mac = NULL;
   1314      1.1  christos 	conf->num_deny_mac = 0;
   1315      1.1  christos 
   1316      1.1  christos 	if (addr == NULL) {
   1317      1.1  christos 		conf->macaddr_acl = ACCEPT_UNLESS_DENIED;
   1318      1.1  christos 		return 0;
   1319      1.1  christos 	}
   1320      1.1  christos 
   1321      1.1  christos 	conf->macaddr_acl = DENY_UNLESS_ACCEPTED;
   1322      1.1  christos 	conf->accept_mac = os_zalloc(sizeof(struct mac_acl_entry));
   1323      1.1  christos 	if (conf->accept_mac == NULL)
   1324      1.1  christos 		return -1;
   1325      1.1  christos 	os_memcpy(conf->accept_mac[0].addr, addr, ETH_ALEN);
   1326      1.1  christos 	conf->num_accept_mac = 1;
   1327      1.1  christos 
   1328      1.1  christos 	return 0;
   1329      1.1  christos }
   1330  1.1.1.4  christos 
   1331  1.1.1.4  christos 
   1332  1.1.1.4  christos #ifdef CONFIG_WPS_NFC
   1333  1.1.1.4  christos int wpas_ap_wps_add_nfc_pw(struct wpa_supplicant *wpa_s, u16 pw_id,
   1334  1.1.1.4  christos 			   const struct wpabuf *pw, const u8 *pubkey_hash)
   1335  1.1.1.4  christos {
   1336  1.1.1.4  christos 	struct hostapd_data *hapd;
   1337  1.1.1.4  christos 	struct wps_context *wps;
   1338  1.1.1.4  christos 
   1339  1.1.1.4  christos 	if (!wpa_s->ap_iface)
   1340  1.1.1.4  christos 		return -1;
   1341  1.1.1.4  christos 	hapd = wpa_s->ap_iface->bss[0];
   1342  1.1.1.4  christos 	wps = hapd->wps;
   1343  1.1.1.4  christos 
   1344  1.1.1.6  christos 	if (wpa_s->p2pdev->conf->wps_nfc_dh_pubkey == NULL ||
   1345  1.1.1.6  christos 	    wpa_s->p2pdev->conf->wps_nfc_dh_privkey == NULL) {
   1346  1.1.1.4  christos 		wpa_printf(MSG_DEBUG, "P2P: No NFC DH key known");
   1347  1.1.1.4  christos 		return -1;
   1348  1.1.1.4  christos 	}
   1349  1.1.1.4  christos 
   1350  1.1.1.4  christos 	dh5_free(wps->dh_ctx);
   1351  1.1.1.4  christos 	wpabuf_free(wps->dh_pubkey);
   1352  1.1.1.4  christos 	wpabuf_free(wps->dh_privkey);
   1353  1.1.1.4  christos 	wps->dh_privkey = wpabuf_dup(
   1354  1.1.1.6  christos 		wpa_s->p2pdev->conf->wps_nfc_dh_privkey);
   1355  1.1.1.4  christos 	wps->dh_pubkey = wpabuf_dup(
   1356  1.1.1.6  christos 		wpa_s->p2pdev->conf->wps_nfc_dh_pubkey);
   1357  1.1.1.4  christos 	if (wps->dh_privkey == NULL || wps->dh_pubkey == NULL) {
   1358  1.1.1.4  christos 		wps->dh_ctx = NULL;
   1359  1.1.1.4  christos 		wpabuf_free(wps->dh_pubkey);
   1360  1.1.1.4  christos 		wps->dh_pubkey = NULL;
   1361  1.1.1.4  christos 		wpabuf_free(wps->dh_privkey);
   1362  1.1.1.4  christos 		wps->dh_privkey = NULL;
   1363  1.1.1.4  christos 		return -1;
   1364  1.1.1.4  christos 	}
   1365  1.1.1.4  christos 	wps->dh_ctx = dh5_init_fixed(wps->dh_privkey, wps->dh_pubkey);
   1366  1.1.1.4  christos 	if (wps->dh_ctx == NULL)
   1367  1.1.1.4  christos 		return -1;
   1368  1.1.1.4  christos 
   1369  1.1.1.4  christos 	return wps_registrar_add_nfc_pw_token(hapd->wps->registrar, pubkey_hash,
   1370  1.1.1.4  christos 					      pw_id,
   1371  1.1.1.4  christos 					      pw ? wpabuf_head(pw) : NULL,
   1372  1.1.1.4  christos 					      pw ? wpabuf_len(pw) : 0, 1);
   1373  1.1.1.4  christos }
   1374  1.1.1.4  christos #endif /* CONFIG_WPS_NFC */
   1375  1.1.1.5  christos 
   1376  1.1.1.5  christos 
   1377  1.1.1.6  christos #ifdef CONFIG_CTRL_IFACE
   1378  1.1.1.5  christos int wpas_ap_stop_ap(struct wpa_supplicant *wpa_s)
   1379  1.1.1.5  christos {
   1380  1.1.1.5  christos 	struct hostapd_data *hapd;
   1381  1.1.1.5  christos 
   1382  1.1.1.5  christos 	if (!wpa_s->ap_iface)
   1383  1.1.1.5  christos 		return -1;
   1384  1.1.1.5  christos 	hapd = wpa_s->ap_iface->bss[0];
   1385  1.1.1.5  christos 	return hostapd_ctrl_iface_stop_ap(hapd);
   1386  1.1.1.5  christos }
   1387  1.1.1.5  christos 
   1388  1.1.1.5  christos 
   1389  1.1.1.6  christos int wpas_ap_pmksa_cache_list(struct wpa_supplicant *wpa_s, char *buf,
   1390  1.1.1.6  christos 			     size_t len)
   1391  1.1.1.6  christos {
   1392  1.1.1.6  christos 	size_t reply_len = 0, i;
   1393  1.1.1.6  christos 	char ap_delimiter[] = "---- AP ----\n";
   1394  1.1.1.6  christos 	char mesh_delimiter[] = "---- mesh ----\n";
   1395  1.1.1.6  christos 	size_t dlen;
   1396  1.1.1.6  christos 
   1397  1.1.1.6  christos 	if (wpa_s->ap_iface) {
   1398  1.1.1.6  christos 		dlen = os_strlen(ap_delimiter);
   1399  1.1.1.6  christos 		if (dlen > len - reply_len)
   1400  1.1.1.6  christos 			return reply_len;
   1401  1.1.1.6  christos 		os_memcpy(&buf[reply_len], ap_delimiter, dlen);
   1402  1.1.1.6  christos 		reply_len += dlen;
   1403  1.1.1.6  christos 
   1404  1.1.1.6  christos 		for (i = 0; i < wpa_s->ap_iface->num_bss; i++) {
   1405  1.1.1.6  christos 			reply_len += hostapd_ctrl_iface_pmksa_list(
   1406  1.1.1.6  christos 				wpa_s->ap_iface->bss[i],
   1407  1.1.1.6  christos 				&buf[reply_len], len - reply_len);
   1408  1.1.1.6  christos 		}
   1409  1.1.1.6  christos 	}
   1410  1.1.1.6  christos 
   1411  1.1.1.6  christos 	if (wpa_s->ifmsh) {
   1412  1.1.1.6  christos 		dlen = os_strlen(mesh_delimiter);
   1413  1.1.1.6  christos 		if (dlen > len - reply_len)
   1414  1.1.1.6  christos 			return reply_len;
   1415  1.1.1.6  christos 		os_memcpy(&buf[reply_len], mesh_delimiter, dlen);
   1416  1.1.1.6  christos 		reply_len += dlen;
   1417  1.1.1.6  christos 
   1418  1.1.1.6  christos 		reply_len += hostapd_ctrl_iface_pmksa_list(
   1419  1.1.1.6  christos 			wpa_s->ifmsh->bss[0], &buf[reply_len],
   1420  1.1.1.6  christos 			len - reply_len);
   1421  1.1.1.6  christos 	}
   1422  1.1.1.6  christos 
   1423  1.1.1.6  christos 	return reply_len;
   1424  1.1.1.6  christos }
   1425  1.1.1.6  christos 
   1426  1.1.1.6  christos 
   1427  1.1.1.6  christos void wpas_ap_pmksa_cache_flush(struct wpa_supplicant *wpa_s)
   1428  1.1.1.6  christos {
   1429  1.1.1.6  christos 	size_t i;
   1430  1.1.1.6  christos 
   1431  1.1.1.6  christos 	if (wpa_s->ap_iface) {
   1432  1.1.1.6  christos 		for (i = 0; i < wpa_s->ap_iface->num_bss; i++)
   1433  1.1.1.6  christos 			hostapd_ctrl_iface_pmksa_flush(wpa_s->ap_iface->bss[i]);
   1434  1.1.1.6  christos 	}
   1435  1.1.1.6  christos 
   1436  1.1.1.6  christos 	if (wpa_s->ifmsh)
   1437  1.1.1.6  christos 		hostapd_ctrl_iface_pmksa_flush(wpa_s->ifmsh->bss[0]);
   1438  1.1.1.6  christos }
   1439  1.1.1.6  christos #endif /* CONFIG_CTRL_IFACE */
   1440  1.1.1.6  christos 
   1441  1.1.1.6  christos 
   1442  1.1.1.5  christos #ifdef NEED_AP_MLME
   1443  1.1.1.5  christos void wpas_event_dfs_radar_detected(struct wpa_supplicant *wpa_s,
   1444  1.1.1.5  christos 				   struct dfs_event *radar)
   1445  1.1.1.5  christos {
   1446  1.1.1.5  christos 	if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0])
   1447  1.1.1.5  christos 		return;
   1448  1.1.1.5  christos 	wpa_printf(MSG_DEBUG, "DFS radar detected on %d MHz", radar->freq);
   1449  1.1.1.5  christos 	hostapd_dfs_radar_detected(wpa_s->ap_iface, radar->freq,
   1450  1.1.1.5  christos 				   radar->ht_enabled, radar->chan_offset,
   1451  1.1.1.5  christos 				   radar->chan_width,
   1452  1.1.1.5  christos 				   radar->cf1, radar->cf2);
   1453  1.1.1.5  christos }
   1454  1.1.1.5  christos 
   1455  1.1.1.5  christos 
   1456  1.1.1.5  christos void wpas_event_dfs_cac_started(struct wpa_supplicant *wpa_s,
   1457  1.1.1.5  christos 				struct dfs_event *radar)
   1458  1.1.1.5  christos {
   1459  1.1.1.5  christos 	if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0])
   1460  1.1.1.5  christos 		return;
   1461  1.1.1.5  christos 	wpa_printf(MSG_DEBUG, "DFS CAC started on %d MHz", radar->freq);
   1462  1.1.1.5  christos 	hostapd_dfs_start_cac(wpa_s->ap_iface, radar->freq,
   1463  1.1.1.5  christos 			      radar->ht_enabled, radar->chan_offset,
   1464  1.1.1.5  christos 			      radar->chan_width, radar->cf1, radar->cf2);
   1465  1.1.1.5  christos }
   1466  1.1.1.5  christos 
   1467  1.1.1.5  christos 
   1468  1.1.1.5  christos void wpas_event_dfs_cac_finished(struct wpa_supplicant *wpa_s,
   1469  1.1.1.5  christos 				 struct dfs_event *radar)
   1470  1.1.1.5  christos {
   1471  1.1.1.5  christos 	if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0])
   1472  1.1.1.5  christos 		return;
   1473  1.1.1.5  christos 	wpa_printf(MSG_DEBUG, "DFS CAC finished on %d MHz", radar->freq);
   1474  1.1.1.5  christos 	hostapd_dfs_complete_cac(wpa_s->ap_iface, 1, radar->freq,
   1475  1.1.1.5  christos 				 radar->ht_enabled, radar->chan_offset,
   1476  1.1.1.5  christos 				 radar->chan_width, radar->cf1, radar->cf2);
   1477  1.1.1.5  christos }
   1478  1.1.1.5  christos 
   1479  1.1.1.5  christos 
   1480  1.1.1.5  christos void wpas_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s,
   1481  1.1.1.5  christos 				struct dfs_event *radar)
   1482  1.1.1.5  christos {
   1483  1.1.1.5  christos 	if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0])
   1484  1.1.1.5  christos 		return;
   1485  1.1.1.5  christos 	wpa_printf(MSG_DEBUG, "DFS CAC aborted on %d MHz", radar->freq);
   1486  1.1.1.5  christos 	hostapd_dfs_complete_cac(wpa_s->ap_iface, 0, radar->freq,
   1487  1.1.1.5  christos 				 radar->ht_enabled, radar->chan_offset,
   1488  1.1.1.5  christos 				 radar->chan_width, radar->cf1, radar->cf2);
   1489  1.1.1.5  christos }
   1490  1.1.1.5  christos 
   1491  1.1.1.5  christos 
   1492  1.1.1.5  christos void wpas_event_dfs_cac_nop_finished(struct wpa_supplicant *wpa_s,
   1493  1.1.1.5  christos 				     struct dfs_event *radar)
   1494  1.1.1.5  christos {
   1495  1.1.1.5  christos 	if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0])
   1496  1.1.1.5  christos 		return;
   1497  1.1.1.5  christos 	wpa_printf(MSG_DEBUG, "DFS NOP finished on %d MHz", radar->freq);
   1498  1.1.1.5  christos 	hostapd_dfs_nop_finished(wpa_s->ap_iface, radar->freq,
   1499  1.1.1.5  christos 				 radar->ht_enabled, radar->chan_offset,
   1500  1.1.1.5  christos 				 radar->chan_width, radar->cf1, radar->cf2);
   1501  1.1.1.5  christos }
   1502  1.1.1.5  christos #endif /* NEED_AP_MLME */
   1503  1.1.1.6  christos 
   1504  1.1.1.6  christos 
   1505  1.1.1.6  christos void ap_periodic(struct wpa_supplicant *wpa_s)
   1506  1.1.1.6  christos {
   1507  1.1.1.6  christos 	if (wpa_s->ap_iface)
   1508  1.1.1.6  christos 		hostapd_periodic_iface(wpa_s->ap_iface);
   1509  1.1.1.6  christos }
   1510