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