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