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