Home | History | Annotate | Line # | Download | only in wpa_supplicant
ap.c revision 1.1.1.8.8.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.8.8.1  perseant #ifdef CONFIG_P2P
     48  1.1.1.8.8.1  perseant static bool is_chanwidth160_supported(struct hostapd_hw_modes *mode,
     49  1.1.1.8.8.1  perseant 				      struct hostapd_config *conf)
     50  1.1.1.8.8.1  perseant {
     51  1.1.1.8.8.1  perseant #ifdef CONFIG_IEEE80211AX
     52  1.1.1.8.8.1  perseant 	if (conf->ieee80211ax) {
     53  1.1.1.8.8.1  perseant 		struct he_capabilities *he_cap;
     54  1.1.1.8.8.1  perseant 
     55  1.1.1.8.8.1  perseant 		he_cap = &mode->he_capab[IEEE80211_MODE_AP];
     56  1.1.1.8.8.1  perseant 		if (he_cap->phy_cap[HE_PHYCAP_CHANNEL_WIDTH_SET_IDX] &
     57  1.1.1.8.8.1  perseant 		    (HE_PHYCAP_CHANNEL_WIDTH_SET_80PLUS80MHZ_IN_5G |
     58  1.1.1.8.8.1  perseant 		     HE_PHYCAP_CHANNEL_WIDTH_SET_160MHZ_IN_5G))
     59  1.1.1.8.8.1  perseant 			return true;
     60  1.1.1.8.8.1  perseant 	}
     61  1.1.1.8.8.1  perseant #endif /* CONFIG_IEEE80211AX */
     62  1.1.1.8.8.1  perseant 	if (mode->vht_capab & (VHT_CAP_SUPP_CHAN_WIDTH_160MHZ |
     63  1.1.1.8.8.1  perseant 			       VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ))
     64  1.1.1.8.8.1  perseant 		return true;
     65  1.1.1.8.8.1  perseant 	return false;
     66  1.1.1.8.8.1  perseant }
     67  1.1.1.8.8.1  perseant #endif /* CONFIG_P2P */
     68  1.1.1.8.8.1  perseant 
     69  1.1.1.8.8.1  perseant 
     70      1.1.1.4  christos static void wpas_conf_ap_vht(struct wpa_supplicant *wpa_s,
     71      1.1.1.7  christos 			     struct wpa_ssid *ssid,
     72      1.1.1.4  christos 			     struct hostapd_config *conf,
     73      1.1.1.4  christos 			     struct hostapd_hw_modes *mode)
     74      1.1.1.4  christos {
     75      1.1.1.4  christos #ifdef CONFIG_P2P
     76      1.1.1.4  christos 	u8 center_chan = 0;
     77      1.1.1.4  christos 	u8 channel = conf->channel;
     78      1.1.1.7  christos #endif /* CONFIG_P2P */
     79  1.1.1.8.8.1  perseant 	u8 freq_seg_idx;
     80      1.1.1.4  christos 
     81      1.1.1.4  christos 	if (!conf->secondary_channel)
     82      1.1.1.4  christos 		goto no_vht;
     83      1.1.1.4  christos 
     84      1.1.1.7  christos 	/* Use the maximum oper channel width if it's given. */
     85      1.1.1.7  christos 	if (ssid->max_oper_chwidth)
     86  1.1.1.8.8.1  perseant 		hostapd_set_oper_chwidth(conf, ssid->max_oper_chwidth);
     87  1.1.1.8.8.1  perseant 	if (hostapd_get_oper_chwidth(conf))
     88  1.1.1.8.8.1  perseant 		ieee80211_freq_to_channel_ext(ssid->frequency, 0,
     89  1.1.1.8.8.1  perseant 					      hostapd_get_oper_chwidth(conf),
     90  1.1.1.8.8.1  perseant 					      &conf->op_class,
     91  1.1.1.8.8.1  perseant 					      &conf->channel);
     92  1.1.1.8.8.1  perseant 
     93  1.1.1.8.8.1  perseant 	if (hostapd_get_oper_chwidth(conf) == CONF_OPER_CHWIDTH_80P80MHZ) {
     94  1.1.1.8.8.1  perseant 		ieee80211_freq_to_chan(ssid->vht_center_freq2,
     95  1.1.1.8.8.1  perseant 				       &freq_seg_idx);
     96  1.1.1.8.8.1  perseant 		hostapd_set_oper_centr_freq_seg1_idx(conf, freq_seg_idx);
     97  1.1.1.8.8.1  perseant 	}
     98      1.1.1.7  christos 
     99      1.1.1.7  christos 	if (!ssid->p2p_group) {
    100  1.1.1.8.8.1  perseant 		if (!ssid->vht_center_freq1)
    101      1.1.1.7  christos 			goto no_vht;
    102      1.1.1.7  christos 		ieee80211_freq_to_chan(ssid->vht_center_freq1,
    103  1.1.1.8.8.1  perseant 				       &freq_seg_idx);
    104  1.1.1.8.8.1  perseant 		hostapd_set_oper_centr_freq_seg0_idx(conf, freq_seg_idx);
    105  1.1.1.8.8.1  perseant 
    106  1.1.1.8.8.1  perseant 		wpa_printf(MSG_DEBUG,
    107  1.1.1.8.8.1  perseant 			   "VHT seg0 index %d and seg1 index %d for AP",
    108  1.1.1.8.8.1  perseant 			   hostapd_get_oper_centr_freq_seg0_idx(conf),
    109  1.1.1.8.8.1  perseant 			   hostapd_get_oper_centr_freq_seg1_idx(conf));
    110      1.1.1.7  christos 		return;
    111      1.1.1.7  christos 	}
    112      1.1.1.7  christos 
    113      1.1.1.7  christos #ifdef CONFIG_P2P
    114  1.1.1.8.8.1  perseant 	switch (hostapd_get_oper_chwidth(conf)) {
    115  1.1.1.8.8.1  perseant 	case CONF_OPER_CHWIDTH_80MHZ:
    116  1.1.1.8.8.1  perseant 	case CONF_OPER_CHWIDTH_80P80MHZ:
    117  1.1.1.8.8.1  perseant 		center_chan = wpas_p2p_get_vht80_center(wpa_s, mode, channel,
    118  1.1.1.8.8.1  perseant 							conf->op_class);
    119      1.1.1.7  christos 		wpa_printf(MSG_DEBUG,
    120      1.1.1.7  christos 			   "VHT center channel %u for 80 or 80+80 MHz bandwidth",
    121      1.1.1.7  christos 			   center_chan);
    122      1.1.1.6  christos 		break;
    123  1.1.1.8.8.1  perseant 	case CONF_OPER_CHWIDTH_160MHZ:
    124  1.1.1.8.8.1  perseant 		center_chan = wpas_p2p_get_vht160_center(wpa_s, mode, channel,
    125  1.1.1.8.8.1  perseant 							 conf->op_class);
    126      1.1.1.7  christos 		wpa_printf(MSG_DEBUG,
    127      1.1.1.7  christos 			   "VHT center channel %u for 160 MHz bandwidth",
    128      1.1.1.7  christos 			   center_chan);
    129      1.1.1.6  christos 		break;
    130      1.1.1.6  christos 	default:
    131      1.1.1.6  christos 		/*
    132      1.1.1.6  christos 		 * conf->vht_oper_chwidth might not be set for non-P2P GO cases,
    133      1.1.1.6  christos 		 * try oper_cwidth 160 MHz first then VHT 80 MHz, if 160 MHz is
    134      1.1.1.6  christos 		 * not supported.
    135      1.1.1.6  christos 		 */
    136  1.1.1.8.8.1  perseant 		hostapd_set_oper_chwidth(conf, CONF_OPER_CHWIDTH_160MHZ);
    137  1.1.1.8.8.1  perseant 		ieee80211_freq_to_channel_ext(ssid->frequency, 0,
    138  1.1.1.8.8.1  perseant 					      conf->vht_oper_chwidth,
    139  1.1.1.8.8.1  perseant 					      &conf->op_class,
    140  1.1.1.8.8.1  perseant 					      &conf->channel);
    141  1.1.1.8.8.1  perseant 		center_chan = wpas_p2p_get_vht160_center(wpa_s, mode, channel,
    142  1.1.1.8.8.1  perseant 							 conf->op_class);
    143  1.1.1.8.8.1  perseant 		if (center_chan && is_chanwidth160_supported(mode, conf)) {
    144      1.1.1.7  christos 			wpa_printf(MSG_DEBUG,
    145      1.1.1.7  christos 				   "VHT center channel %u for auto-selected 160 MHz bandwidth",
    146      1.1.1.7  christos 				   center_chan);
    147      1.1.1.7  christos 		} else {
    148  1.1.1.8.8.1  perseant 			hostapd_set_oper_chwidth(conf, CONF_OPER_CHWIDTH_80MHZ);
    149  1.1.1.8.8.1  perseant 			ieee80211_freq_to_channel_ext(ssid->frequency, 0,
    150  1.1.1.8.8.1  perseant 						      conf->vht_oper_chwidth,
    151  1.1.1.8.8.1  perseant 						      &conf->op_class,
    152  1.1.1.8.8.1  perseant 						      &conf->channel);
    153      1.1.1.6  christos 			center_chan = wpas_p2p_get_vht80_center(wpa_s, mode,
    154  1.1.1.8.8.1  perseant 								channel,
    155  1.1.1.8.8.1  perseant 								conf->op_class);
    156      1.1.1.7  christos 			wpa_printf(MSG_DEBUG,
    157      1.1.1.7  christos 				   "VHT center channel %u for auto-selected 80 MHz bandwidth",
    158      1.1.1.7  christos 				   center_chan);
    159      1.1.1.6  christos 		}
    160      1.1.1.6  christos 		break;
    161      1.1.1.6  christos 	}
    162      1.1.1.4  christos 	if (!center_chan)
    163      1.1.1.4  christos 		goto no_vht;
    164      1.1.1.4  christos 
    165  1.1.1.8.8.1  perseant 	hostapd_set_oper_centr_freq_seg0_idx(conf, center_chan);
    166      1.1.1.7  christos 	wpa_printf(MSG_DEBUG, "VHT seg0 index %d for P2P GO",
    167  1.1.1.8.8.1  perseant 		   hostapd_get_oper_centr_freq_seg0_idx(conf));
    168      1.1.1.4  christos 	return;
    169      1.1.1.7  christos #endif /* CONFIG_P2P */
    170      1.1.1.4  christos 
    171      1.1.1.4  christos no_vht:
    172      1.1.1.7  christos 	wpa_printf(MSG_DEBUG,
    173      1.1.1.7  christos 		   "No VHT higher bandwidth support for the selected channel %d",
    174      1.1.1.7  christos 		   conf->channel);
    175  1.1.1.8.8.1  perseant 	hostapd_set_oper_centr_freq_seg0_idx(
    176  1.1.1.8.8.1  perseant 		conf, conf->channel + conf->secondary_channel * 2);
    177  1.1.1.8.8.1  perseant 	hostapd_set_oper_chwidth(conf, CONF_OPER_CHWIDTH_USE_HT);
    178  1.1.1.8.8.1  perseant 	ieee80211_freq_to_channel_ext(ssid->frequency, 0,
    179  1.1.1.8.8.1  perseant 				      conf->vht_oper_chwidth,
    180  1.1.1.8.8.1  perseant 				      &conf->op_class, &conf->channel);
    181  1.1.1.8.8.1  perseant }
    182  1.1.1.8.8.1  perseant 
    183  1.1.1.8.8.1  perseant 
    184  1.1.1.8.8.1  perseant static struct hostapd_hw_modes *
    185  1.1.1.8.8.1  perseant wpa_supplicant_find_hw_mode(struct wpa_supplicant *wpa_s,
    186  1.1.1.8.8.1  perseant 			    enum hostapd_hw_mode hw_mode)
    187  1.1.1.8.8.1  perseant {
    188  1.1.1.8.8.1  perseant 	struct hostapd_hw_modes *mode = NULL;
    189  1.1.1.8.8.1  perseant 	int i;
    190  1.1.1.8.8.1  perseant 
    191  1.1.1.8.8.1  perseant 	for (i = 0; i < wpa_s->hw.num_modes; i++) {
    192  1.1.1.8.8.1  perseant 		if (wpa_s->hw.modes[i].mode == hw_mode) {
    193  1.1.1.8.8.1  perseant 			mode = &wpa_s->hw.modes[i];
    194  1.1.1.8.8.1  perseant 			break;
    195  1.1.1.8.8.1  perseant 		}
    196  1.1.1.8.8.1  perseant 	}
    197  1.1.1.8.8.1  perseant 
    198  1.1.1.8.8.1  perseant 	return mode;
    199  1.1.1.8.8.1  perseant }
    200  1.1.1.8.8.1  perseant 
    201  1.1.1.8.8.1  perseant 
    202  1.1.1.8.8.1  perseant #ifdef CONFIG_P2P
    203  1.1.1.8.8.1  perseant 
    204  1.1.1.8.8.1  perseant static int get_max_oper_chwidth_6ghz(int chwidth)
    205  1.1.1.8.8.1  perseant {
    206  1.1.1.8.8.1  perseant 	switch (chwidth) {
    207  1.1.1.8.8.1  perseant 	case CONF_OPER_CHWIDTH_USE_HT:
    208  1.1.1.8.8.1  perseant 		return 20;
    209  1.1.1.8.8.1  perseant 	case CONF_OPER_CHWIDTH_40MHZ_6GHZ:
    210  1.1.1.8.8.1  perseant 		return 40;
    211  1.1.1.8.8.1  perseant 	case CONF_OPER_CHWIDTH_80MHZ:
    212  1.1.1.8.8.1  perseant 		return 80;
    213  1.1.1.8.8.1  perseant 	case CONF_OPER_CHWIDTH_80P80MHZ:
    214  1.1.1.8.8.1  perseant 	case CONF_OPER_CHWIDTH_160MHZ:
    215  1.1.1.8.8.1  perseant 		return 160;
    216  1.1.1.8.8.1  perseant 	default:
    217  1.1.1.8.8.1  perseant 		return 0;
    218  1.1.1.8.8.1  perseant 	}
    219  1.1.1.8.8.1  perseant }
    220  1.1.1.8.8.1  perseant 
    221  1.1.1.8.8.1  perseant 
    222  1.1.1.8.8.1  perseant static void wpas_conf_ap_he_6ghz(struct wpa_supplicant *wpa_s,
    223  1.1.1.8.8.1  perseant 				 struct hostapd_hw_modes *mode,
    224  1.1.1.8.8.1  perseant 				 struct wpa_ssid *ssid,
    225  1.1.1.8.8.1  perseant 				 struct hostapd_config *conf)
    226  1.1.1.8.8.1  perseant {
    227  1.1.1.8.8.1  perseant 	bool is_chanwidth_40_80, is_chanwidth_160;
    228  1.1.1.8.8.1  perseant 	int he_chanwidth;
    229  1.1.1.8.8.1  perseant 
    230  1.1.1.8.8.1  perseant 	he_chanwidth =
    231  1.1.1.8.8.1  perseant 		mode->he_capab[wpas_mode_to_ieee80211_mode(
    232  1.1.1.8.8.1  perseant 			ssid->mode)].phy_cap[HE_PHYCAP_CHANNEL_WIDTH_SET_IDX];
    233  1.1.1.8.8.1  perseant 	is_chanwidth_40_80 = he_chanwidth &
    234  1.1.1.8.8.1  perseant 		HE_PHYCAP_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G;
    235  1.1.1.8.8.1  perseant 	is_chanwidth_160 = he_chanwidth &
    236  1.1.1.8.8.1  perseant 		HE_PHYCAP_CHANNEL_WIDTH_SET_160MHZ_IN_5G;
    237  1.1.1.8.8.1  perseant 
    238  1.1.1.8.8.1  perseant 	wpa_printf(MSG_DEBUG,
    239  1.1.1.8.8.1  perseant 		   "Enable HE support (p2p_group=%d he_chwidth_cap=%d)",
    240  1.1.1.8.8.1  perseant 		   ssid->p2p_group, he_chanwidth);
    241  1.1.1.8.8.1  perseant 
    242  1.1.1.8.8.1  perseant 	if (mode->he_capab[wpas_mode_to_ieee80211_mode(
    243  1.1.1.8.8.1  perseant 			    ssid->mode)].he_supported &&
    244  1.1.1.8.8.1  perseant 	    ssid->he)
    245  1.1.1.8.8.1  perseant 		conf->ieee80211ax = 1;
    246  1.1.1.8.8.1  perseant 
    247  1.1.1.8.8.1  perseant 	if (is_chanwidth_40_80 && ssid->p2p_group &&
    248  1.1.1.8.8.1  perseant 	    get_max_oper_chwidth_6ghz(ssid->max_oper_chwidth) >= 40) {
    249  1.1.1.8.8.1  perseant 		conf->secondary_channel =
    250  1.1.1.8.8.1  perseant 			wpas_p2p_get_sec_channel_offset_40mhz(
    251  1.1.1.8.8.1  perseant 				wpa_s, mode, conf->channel);
    252  1.1.1.8.8.1  perseant 		wpa_printf(MSG_DEBUG,
    253  1.1.1.8.8.1  perseant 			   "Secondary channel offset %d for P2P group",
    254  1.1.1.8.8.1  perseant 			   conf->secondary_channel);
    255  1.1.1.8.8.1  perseant 		if (ssid->max_oper_chwidth == CONF_OPER_CHWIDTH_40MHZ_6GHZ)
    256  1.1.1.8.8.1  perseant 			ssid->max_oper_chwidth = CONF_OPER_CHWIDTH_USE_HT;
    257  1.1.1.8.8.1  perseant 	}
    258  1.1.1.8.8.1  perseant 
    259  1.1.1.8.8.1  perseant 	if ((is_chanwidth_40_80 || is_chanwidth_160) && ssid->p2p_group &&
    260  1.1.1.8.8.1  perseant 	    get_max_oper_chwidth_6ghz(ssid->max_oper_chwidth) >= 80)
    261  1.1.1.8.8.1  perseant 		wpas_conf_ap_vht(wpa_s, ssid, conf, mode);
    262      1.1.1.4  christos }
    263  1.1.1.8.8.1  perseant 
    264  1.1.1.8.8.1  perseant #endif /* CONFIG_P2P */
    265      1.1.1.4  christos 
    266      1.1.1.4  christos 
    267      1.1.1.6  christos int wpa_supplicant_conf_ap_ht(struct wpa_supplicant *wpa_s,
    268      1.1.1.6  christos 			      struct wpa_ssid *ssid,
    269      1.1.1.6  christos 			      struct hostapd_config *conf)
    270          1.1  christos {
    271  1.1.1.8.8.1  perseant 	conf->hw_mode = ieee80211_freq_to_channel_ext(ssid->frequency, 0,
    272  1.1.1.8.8.1  perseant 						      CONF_OPER_CHWIDTH_USE_HT,
    273  1.1.1.8.8.1  perseant 						      &conf->op_class,
    274  1.1.1.8.8.1  perseant 						      &conf->channel);
    275      1.1.1.6  christos 	if (conf->hw_mode == NUM_HOSTAPD_MODES) {
    276      1.1.1.6  christos 		wpa_printf(MSG_ERROR, "Unsupported AP mode frequency: %d MHz",
    277      1.1.1.6  christos 			   ssid->frequency);
    278      1.1.1.6  christos 		return -1;
    279      1.1.1.6  christos 	}
    280      1.1.1.6  christos 
    281      1.1.1.2  christos 	/*
    282      1.1.1.3  christos 	 * Enable HT20 if the driver supports it, by setting conf->ieee80211n
    283      1.1.1.3  christos 	 * and a mask of allowed capabilities within conf->ht_capab.
    284      1.1.1.2  christos 	 * Using default config settings for: conf->ht_op_mode_fixed,
    285      1.1.1.3  christos 	 * conf->secondary_channel, conf->require_ht
    286      1.1.1.2  christos 	 */
    287      1.1.1.2  christos 	if (wpa_s->hw.modes) {
    288      1.1.1.2  christos 		struct hostapd_hw_modes *mode = NULL;
    289  1.1.1.8.8.1  perseant 		int no_ht = 0;
    290      1.1.1.7  christos 
    291      1.1.1.7  christos 		wpa_printf(MSG_DEBUG,
    292      1.1.1.7  christos 			   "Determining HT/VHT options based on driver capabilities (freq=%u chan=%u)",
    293      1.1.1.7  christos 			   ssid->frequency, conf->channel);
    294      1.1.1.7  christos 
    295  1.1.1.8.8.1  perseant 		mode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes,
    296  1.1.1.8.8.1  perseant 				conf->hw_mode, is_6ghz_freq(ssid->frequency));
    297  1.1.1.8.8.1  perseant 
    298  1.1.1.8.8.1  perseant 		/* May drop to IEEE 802.11b if the driver does not support IEEE
    299  1.1.1.8.8.1  perseant 		 * 802.11g */
    300  1.1.1.8.8.1  perseant 		if (!mode && conf->hw_mode == HOSTAPD_MODE_IEEE80211G) {
    301  1.1.1.8.8.1  perseant 			conf->hw_mode = HOSTAPD_MODE_IEEE80211B;
    302  1.1.1.8.8.1  perseant 			wpa_printf(MSG_INFO,
    303  1.1.1.8.8.1  perseant 				   "Try downgrade to IEEE 802.11b as 802.11g is not supported by the current hardware");
    304  1.1.1.8.8.1  perseant 			mode = wpa_supplicant_find_hw_mode(wpa_s,
    305  1.1.1.8.8.1  perseant 							   conf->hw_mode);
    306  1.1.1.8.8.1  perseant 		}
    307  1.1.1.8.8.1  perseant 
    308  1.1.1.8.8.1  perseant 		if (!mode) {
    309  1.1.1.8.8.1  perseant 			wpa_printf(MSG_ERROR,
    310  1.1.1.8.8.1  perseant 				   "No match between requested and supported hw modes found");
    311  1.1.1.8.8.1  perseant 			return -1;
    312      1.1.1.2  christos 		}
    313      1.1.1.3  christos 
    314      1.1.1.3  christos #ifdef CONFIG_HT_OVERRIDES
    315      1.1.1.7  christos 		if (ssid->disable_ht)
    316      1.1.1.7  christos 			ssid->ht = 0;
    317  1.1.1.8.8.1  perseant 		if (ssid->disable_ht40)
    318  1.1.1.8.8.1  perseant 			ssid->ht40 = 0;
    319      1.1.1.7  christos #endif /* CONFIG_HT_OVERRIDES */
    320      1.1.1.7  christos 
    321  1.1.1.8.8.1  perseant #ifdef CONFIG_VHT_OVERRIDES
    322  1.1.1.8.8.1  perseant 		if (ssid->disable_vht)
    323  1.1.1.8.8.1  perseant 			ssid->vht = 0;
    324  1.1.1.8.8.1  perseant #endif /* CONFIG_VHT_OVERRIDES */
    325  1.1.1.8.8.1  perseant 
    326  1.1.1.8.8.1  perseant #ifdef CONFIG_HE_OVERRIDES
    327  1.1.1.8.8.1  perseant 		if (ssid->disable_he)
    328  1.1.1.8.8.1  perseant 			ssid->he = 0;
    329  1.1.1.8.8.1  perseant #endif /* CONFIG_HE_OVERRIDES */
    330  1.1.1.8.8.1  perseant 
    331      1.1.1.7  christos 		if (!ssid->ht) {
    332      1.1.1.7  christos 			wpa_printf(MSG_DEBUG,
    333      1.1.1.7  christos 				   "HT not enabled in network profile");
    334      1.1.1.3  christos 			conf->ieee80211n = 0;
    335      1.1.1.3  christos 			conf->ht_capab = 0;
    336      1.1.1.3  christos 			no_ht = 1;
    337      1.1.1.3  christos 		}
    338      1.1.1.3  christos 
    339  1.1.1.8.8.1  perseant 		if (mode && is_6ghz_freq(ssid->frequency) &&
    340  1.1.1.8.8.1  perseant 		    conf->hw_mode == HOSTAPD_MODE_IEEE80211A) {
    341  1.1.1.8.8.1  perseant 			if (mode->eht_capab[wpas_mode_to_ieee80211_mode(
    342  1.1.1.8.8.1  perseant 					    ssid->mode)].eht_supported &&
    343  1.1.1.8.8.1  perseant 			    ssid->eht)
    344  1.1.1.8.8.1  perseant 				conf->ieee80211be = 1;
    345  1.1.1.8.8.1  perseant 
    346  1.1.1.8.8.1  perseant 			if (mode->he_capab[wpas_mode_to_ieee80211_mode(
    347  1.1.1.8.8.1  perseant 					    ssid->mode)].he_supported &&
    348  1.1.1.8.8.1  perseant 			    ssid->he)
    349  1.1.1.8.8.1  perseant 				conf->ieee80211ax = 1;
    350  1.1.1.8.8.1  perseant 
    351  1.1.1.8.8.1  perseant #ifdef CONFIG_P2P
    352  1.1.1.8.8.1  perseant 			wpas_conf_ap_he_6ghz(wpa_s, mode, ssid, conf);
    353  1.1.1.8.8.1  perseant #endif /* CONFIG_P2P */
    354  1.1.1.8.8.1  perseant 		} else if (!no_ht && mode && mode->ht_capab) {
    355      1.1.1.7  christos 			wpa_printf(MSG_DEBUG,
    356      1.1.1.7  christos 				   "Enable HT support (p2p_group=%d 11a=%d ht40_hw_capab=%d ssid->ht40=%d)",
    357      1.1.1.7  christos 				   ssid->p2p_group,
    358      1.1.1.7  christos 				   conf->hw_mode == HOSTAPD_MODE_IEEE80211A,
    359      1.1.1.7  christos 				   !!(mode->ht_capab &
    360      1.1.1.7  christos 				      HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET),
    361      1.1.1.7  christos 				   ssid->ht40);
    362      1.1.1.2  christos 			conf->ieee80211n = 1;
    363  1.1.1.8.8.1  perseant 
    364  1.1.1.8.8.1  perseant 			if (ssid->ht40 &&
    365  1.1.1.8.8.1  perseant 			    (mode->ht_capab &
    366  1.1.1.8.8.1  perseant 			     HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET))
    367  1.1.1.8.8.1  perseant 				conf->secondary_channel = ssid->ht40;
    368  1.1.1.8.8.1  perseant 			else
    369  1.1.1.8.8.1  perseant 				conf->secondary_channel = 0;
    370  1.1.1.8.8.1  perseant 
    371      1.1.1.3  christos #ifdef CONFIG_P2P
    372      1.1.1.7  christos 			if (ssid->p2p_group &&
    373      1.1.1.7  christos 			    conf->hw_mode == HOSTAPD_MODE_IEEE80211A &&
    374      1.1.1.3  christos 			    (mode->ht_capab &
    375      1.1.1.3  christos 			     HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) &&
    376      1.1.1.7  christos 			    ssid->ht40) {
    377      1.1.1.3  christos 				conf->secondary_channel =
    378  1.1.1.8.8.1  perseant 					wpas_p2p_get_sec_channel_offset_40mhz(
    379  1.1.1.8.8.1  perseant 						wpa_s, mode, conf->channel);
    380      1.1.1.7  christos 				wpa_printf(MSG_DEBUG,
    381      1.1.1.7  christos 					   "HT secondary channel offset %d for P2P group",
    382      1.1.1.7  christos 					   conf->secondary_channel);
    383  1.1.1.8.8.1  perseant 			} else if (ssid->p2p_group && conf->secondary_channel &&
    384  1.1.1.8.8.1  perseant 				   conf->hw_mode != HOSTAPD_MODE_IEEE80211A) {
    385  1.1.1.8.8.1  perseant 				/* This ended up trying to configure invalid
    386  1.1.1.8.8.1  perseant 				 * 2.4 GHz channels (e.g., HT40+ on channel 11)
    387  1.1.1.8.8.1  perseant 				 * in some cases, so clear the secondary channel
    388  1.1.1.8.8.1  perseant 				 * configuration now to avoid such cases that
    389  1.1.1.8.8.1  perseant 				 * would lead to group formation failures. */
    390  1.1.1.8.8.1  perseant 				wpa_printf(MSG_DEBUG,
    391  1.1.1.8.8.1  perseant 					   "Disable HT secondary channel for P2P group on 2.4 GHz");
    392  1.1.1.8.8.1  perseant 				conf->secondary_channel = 0;
    393      1.1.1.7  christos 			}
    394      1.1.1.7  christos #endif /* CONFIG_P2P */
    395      1.1.1.7  christos 
    396      1.1.1.7  christos 			if (!ssid->p2p_group &&
    397      1.1.1.7  christos 			    (mode->ht_capab &
    398      1.1.1.7  christos 			     HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) {
    399      1.1.1.7  christos 				conf->secondary_channel = ssid->ht40;
    400      1.1.1.7  christos 				wpa_printf(MSG_DEBUG,
    401      1.1.1.7  christos 					   "HT secondary channel offset %d for AP",
    402      1.1.1.7  christos 					   conf->secondary_channel);
    403      1.1.1.7  christos 			}
    404      1.1.1.7  christos 
    405      1.1.1.3  christos 			if (conf->secondary_channel)
    406      1.1.1.3  christos 				conf->ht_capab |=
    407      1.1.1.3  christos 					HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
    408      1.1.1.3  christos 
    409      1.1.1.3  christos 			/*
    410  1.1.1.8.8.1  perseant 			 * include capabilities that won't cause issues
    411      1.1.1.3  christos 			 * to connecting stations, while leaving the current
    412      1.1.1.3  christos 			 * capabilities intact (currently disabled SMPS).
    413      1.1.1.3  christos 			 */
    414      1.1.1.3  christos 			conf->ht_capab |= mode->ht_capab &
    415      1.1.1.3  christos 				(HT_CAP_INFO_GREEN_FIELD |
    416      1.1.1.3  christos 				 HT_CAP_INFO_SHORT_GI20MHZ |
    417      1.1.1.3  christos 				 HT_CAP_INFO_SHORT_GI40MHZ |
    418      1.1.1.3  christos 				 HT_CAP_INFO_RX_STBC_MASK |
    419      1.1.1.5  christos 				 HT_CAP_INFO_TX_STBC |
    420      1.1.1.3  christos 				 HT_CAP_INFO_MAX_AMSDU_SIZE);
    421      1.1.1.4  christos 
    422  1.1.1.8.8.1  perseant 			/* check this before VHT, because setting oper chan
    423  1.1.1.8.8.1  perseant 			 * width and friends is the same call for HE and VHT
    424  1.1.1.8.8.1  perseant 			 * and checks if conf->ieee8021ax == 1 */
    425  1.1.1.8.8.1  perseant 			if (mode->eht_capab[wpas_mode_to_ieee80211_mode(
    426  1.1.1.8.8.1  perseant 					    ssid->mode)].eht_supported &&
    427  1.1.1.8.8.1  perseant 			    ssid->eht)
    428  1.1.1.8.8.1  perseant 				conf->ieee80211be = 1;
    429      1.1.1.8  christos 
    430      1.1.1.8  christos 			if (mode->he_capab[wpas_mode_to_ieee80211_mode(
    431      1.1.1.8  christos 					    ssid->mode)].he_supported &&
    432      1.1.1.8  christos 			    ssid->he)
    433      1.1.1.8  christos 				conf->ieee80211ax = 1;
    434  1.1.1.8.8.1  perseant 
    435  1.1.1.8.8.1  perseant 			if (mode->vht_capab && ssid->vht) {
    436  1.1.1.8.8.1  perseant 				conf->ieee80211ac = 1;
    437  1.1.1.8.8.1  perseant 				conf->vht_capab |= mode->vht_capab;
    438  1.1.1.8.8.1  perseant 				wpas_conf_ap_vht(wpa_s, ssid, conf, mode);
    439  1.1.1.8.8.1  perseant 			}
    440      1.1.1.3  christos 		}
    441      1.1.1.2  christos 	}
    442      1.1.1.6  christos 
    443  1.1.1.8.8.1  perseant #ifdef CONFIG_P2P
    444  1.1.1.8.8.1  perseant 	if (ssid->p2p_group && wpa_s->p2p_go_no_pri_sec_switch) {
    445  1.1.1.8.8.1  perseant 		conf->no_pri_sec_switch = 1;
    446  1.1.1.8.8.1  perseant 		return 0;
    447  1.1.1.8.8.1  perseant 	}
    448  1.1.1.8.8.1  perseant #endif /* CONFIG_P2P */
    449  1.1.1.8.8.1  perseant 
    450      1.1.1.6  christos 	if (conf->secondary_channel) {
    451      1.1.1.6  christos 		struct wpa_supplicant *iface;
    452      1.1.1.6  christos 
    453      1.1.1.6  christos 		for (iface = wpa_s->global->ifaces; iface; iface = iface->next)
    454      1.1.1.6  christos 		{
    455      1.1.1.6  christos 			if (iface == wpa_s ||
    456      1.1.1.6  christos 			    iface->wpa_state < WPA_AUTHENTICATING ||
    457      1.1.1.6  christos 			    (int) iface->assoc_freq != ssid->frequency)
    458      1.1.1.6  christos 				continue;
    459      1.1.1.6  christos 
    460      1.1.1.6  christos 			/*
    461      1.1.1.6  christos 			 * Do not allow 40 MHz co-ex PRI/SEC switch to force us
    462      1.1.1.6  christos 			 * to change our PRI channel since we have an existing,
    463      1.1.1.6  christos 			 * concurrent connection on that channel and doing
    464      1.1.1.6  christos 			 * multi-channel concurrency is likely to cause more
    465      1.1.1.6  christos 			 * harm than using different PRI/SEC selection in
    466      1.1.1.6  christos 			 * environment with multiple BSSes on these two channels
    467      1.1.1.6  christos 			 * with mixed 20 MHz or PRI channel selection.
    468      1.1.1.6  christos 			 */
    469      1.1.1.6  christos 			conf->no_pri_sec_switch = 1;
    470      1.1.1.6  christos 		}
    471      1.1.1.6  christos 	}
    472      1.1.1.6  christos 
    473      1.1.1.6  christos 	return 0;
    474      1.1.1.5  christos }
    475      1.1.1.5  christos 
    476      1.1.1.5  christos 
    477      1.1.1.5  christos static int wpa_supplicant_conf_ap(struct wpa_supplicant *wpa_s,
    478      1.1.1.5  christos 				  struct wpa_ssid *ssid,
    479      1.1.1.5  christos 				  struct hostapd_config *conf)
    480      1.1.1.5  christos {
    481      1.1.1.5  christos 	struct hostapd_bss_config *bss = conf->bss[0];
    482      1.1.1.5  christos 
    483      1.1.1.5  christos 	conf->driver = wpa_s->driver;
    484      1.1.1.5  christos 
    485      1.1.1.5  christos 	os_strlcpy(bss->iface, wpa_s->ifname, sizeof(bss->iface));
    486      1.1.1.5  christos 
    487      1.1.1.6  christos 	if (wpa_supplicant_conf_ap_ht(wpa_s, ssid, conf))
    488      1.1.1.6  christos 		return -1;
    489      1.1.1.6  christos 
    490      1.1.1.6  christos 	if (ssid->pbss > 1) {
    491      1.1.1.6  christos 		wpa_printf(MSG_ERROR, "Invalid pbss value(%d) for AP mode",
    492      1.1.1.6  christos 			   ssid->pbss);
    493      1.1.1.5  christos 		return -1;
    494      1.1.1.5  christos 	}
    495      1.1.1.6  christos 	bss->pbss = ssid->pbss;
    496      1.1.1.5  christos 
    497      1.1.1.6  christos #ifdef CONFIG_ACS
    498      1.1.1.6  christos 	if (ssid->acs) {
    499      1.1.1.6  christos 		/* Setting channel to 0 in order to enable ACS */
    500      1.1.1.6  christos 		conf->channel = 0;
    501      1.1.1.6  christos 		wpa_printf(MSG_DEBUG, "Use automatic channel selection");
    502      1.1.1.6  christos 	}
    503      1.1.1.6  christos #endif /* CONFIG_ACS */
    504      1.1.1.5  christos 
    505      1.1.1.7  christos 	if (ieee80211_is_dfs(ssid->frequency, wpa_s->hw.modes,
    506      1.1.1.7  christos 			     wpa_s->hw.num_modes) && wpa_s->conf->country[0]) {
    507      1.1.1.5  christos 		conf->ieee80211h = 1;
    508      1.1.1.5  christos 		conf->ieee80211d = 1;
    509      1.1.1.5  christos 		conf->country[0] = wpa_s->conf->country[0];
    510      1.1.1.5  christos 		conf->country[1] = wpa_s->conf->country[1];
    511      1.1.1.7  christos 		conf->country[2] = ' ';
    512      1.1.1.5  christos 	}
    513      1.1.1.2  christos 
    514      1.1.1.2  christos #ifdef CONFIG_P2P
    515      1.1.1.4  christos 	if (conf->hw_mode == HOSTAPD_MODE_IEEE80211G &&
    516      1.1.1.4  christos 	    (ssid->mode == WPAS_MODE_P2P_GO ||
    517      1.1.1.4  christos 	     ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)) {
    518      1.1.1.2  christos 		/* Remove 802.11b rates from supported and basic rate sets */
    519      1.1.1.2  christos 		int *list = os_malloc(4 * sizeof(int));
    520      1.1.1.2  christos 		if (list) {
    521      1.1.1.2  christos 			list[0] = 60;
    522      1.1.1.2  christos 			list[1] = 120;
    523      1.1.1.2  christos 			list[2] = 240;
    524      1.1.1.2  christos 			list[3] = -1;
    525      1.1.1.2  christos 		}
    526      1.1.1.2  christos 		conf->basic_rates = list;
    527      1.1.1.2  christos 
    528      1.1.1.2  christos 		list = os_malloc(9 * sizeof(int));
    529      1.1.1.2  christos 		if (list) {
    530      1.1.1.2  christos 			list[0] = 60;
    531      1.1.1.2  christos 			list[1] = 90;
    532      1.1.1.2  christos 			list[2] = 120;
    533      1.1.1.2  christos 			list[3] = 180;
    534      1.1.1.2  christos 			list[4] = 240;
    535      1.1.1.2  christos 			list[5] = 360;
    536      1.1.1.2  christos 			list[6] = 480;
    537      1.1.1.2  christos 			list[7] = 540;
    538      1.1.1.2  christos 			list[8] = -1;
    539      1.1.1.2  christos 		}
    540      1.1.1.2  christos 		conf->supported_rates = list;
    541      1.1.1.2  christos 	}
    542      1.1.1.2  christos 
    543      1.1.1.8  christos #ifdef CONFIG_IEEE80211AX
    544      1.1.1.8  christos 	if (ssid->mode == WPAS_MODE_P2P_GO ||
    545      1.1.1.8  christos 	    ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
    546      1.1.1.8  christos 		conf->ieee80211ax = ssid->he;
    547      1.1.1.8  christos #endif /* CONFIG_IEEE80211AX */
    548      1.1.1.8  christos 
    549      1.1.1.2  christos 	bss->isolate = !wpa_s->conf->p2p_intra_bss;
    550  1.1.1.8.8.1  perseant 	bss->extended_key_id = wpa_s->conf->extended_key_id;
    551      1.1.1.4  christos 	bss->force_per_enrollee_psk = wpa_s->global->p2p_per_sta_psk;
    552  1.1.1.8.8.1  perseant 	bss->wpa_deny_ptk0_rekey = ssid->wpa_deny_ptk0_rekey;
    553      1.1.1.4  christos 
    554      1.1.1.4  christos 	if (ssid->p2p_group) {
    555      1.1.1.6  christos 		os_memcpy(bss->ip_addr_go, wpa_s->p2pdev->conf->ip_addr_go, 4);
    556      1.1.1.6  christos 		os_memcpy(bss->ip_addr_mask, wpa_s->p2pdev->conf->ip_addr_mask,
    557      1.1.1.4  christos 			  4);
    558      1.1.1.4  christos 		os_memcpy(bss->ip_addr_start,
    559      1.1.1.6  christos 			  wpa_s->p2pdev->conf->ip_addr_start, 4);
    560      1.1.1.6  christos 		os_memcpy(bss->ip_addr_end, wpa_s->p2pdev->conf->ip_addr_end,
    561      1.1.1.4  christos 			  4);
    562      1.1.1.4  christos 	}
    563      1.1.1.2  christos #endif /* CONFIG_P2P */
    564      1.1.1.2  christos 
    565          1.1  christos 	if (ssid->ssid_len == 0) {
    566          1.1  christos 		wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
    567          1.1  christos 		return -1;
    568          1.1  christos 	}
    569          1.1  christos 	os_memcpy(bss->ssid.ssid, ssid->ssid, ssid->ssid_len);
    570          1.1  christos 	bss->ssid.ssid_len = ssid->ssid_len;
    571          1.1  christos 	bss->ssid.ssid_set = 1;
    572          1.1  christos 
    573      1.1.1.3  christos 	bss->ignore_broadcast_ssid = ssid->ignore_broadcast_ssid;
    574      1.1.1.3  christos 
    575      1.1.1.2  christos 	if (ssid->auth_alg)
    576      1.1.1.2  christos 		bss->auth_algs = ssid->auth_alg;
    577      1.1.1.2  christos 
    578          1.1  christos 	if (wpa_key_mgmt_wpa_psk(ssid->key_mgmt))
    579          1.1  christos 		bss->wpa = ssid->proto;
    580      1.1.1.6  christos 	if (ssid->key_mgmt == DEFAULT_KEY_MGMT)
    581      1.1.1.6  christos 		bss->wpa_key_mgmt = WPA_KEY_MGMT_PSK;
    582      1.1.1.6  christos 	else
    583      1.1.1.6  christos 		bss->wpa_key_mgmt = ssid->key_mgmt;
    584          1.1  christos 	bss->wpa_pairwise = ssid->pairwise_cipher;
    585  1.1.1.8.8.1  perseant 	if (wpa_key_mgmt_sae(bss->wpa_key_mgmt) && ssid->passphrase) {
    586  1.1.1.8.8.1  perseant 		bss->ssid.wpa_passphrase = os_strdup(ssid->passphrase);
    587  1.1.1.8.8.1  perseant 	} else if (ssid->psk_set) {
    588      1.1.1.5  christos 		bin_clear_free(bss->ssid.wpa_psk, sizeof(*bss->ssid.wpa_psk));
    589          1.1  christos 		bss->ssid.wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
    590          1.1  christos 		if (bss->ssid.wpa_psk == NULL)
    591          1.1  christos 			return -1;
    592          1.1  christos 		os_memcpy(bss->ssid.wpa_psk->psk, ssid->psk, PMK_LEN);
    593          1.1  christos 		bss->ssid.wpa_psk->group = 1;
    594      1.1.1.6  christos 		bss->ssid.wpa_psk_set = 1;
    595      1.1.1.3  christos 	} else if (ssid->passphrase) {
    596      1.1.1.3  christos 		bss->ssid.wpa_passphrase = os_strdup(ssid->passphrase);
    597  1.1.1.8.8.1  perseant #ifdef CONFIG_WEP
    598      1.1.1.2  christos 	} else if (ssid->wep_key_len[0] || ssid->wep_key_len[1] ||
    599      1.1.1.2  christos 		   ssid->wep_key_len[2] || ssid->wep_key_len[3]) {
    600      1.1.1.2  christos 		struct hostapd_wep_keys *wep = &bss->ssid.wep;
    601      1.1.1.2  christos 		int i;
    602      1.1.1.2  christos 		for (i = 0; i < NUM_WEP_KEYS; i++) {
    603      1.1.1.2  christos 			if (ssid->wep_key_len[i] == 0)
    604      1.1.1.2  christos 				continue;
    605      1.1.1.7  christos 			wep->key[i] = os_memdup(ssid->wep_key[i],
    606      1.1.1.7  christos 						ssid->wep_key_len[i]);
    607      1.1.1.2  christos 			if (wep->key[i] == NULL)
    608      1.1.1.2  christos 				return -1;
    609      1.1.1.2  christos 			wep->len[i] = ssid->wep_key_len[i];
    610      1.1.1.2  christos 		}
    611      1.1.1.2  christos 		wep->idx = ssid->wep_tx_keyidx;
    612      1.1.1.2  christos 		wep->keys_set = 1;
    613  1.1.1.8.8.1  perseant #endif /* CONFIG_WEP */
    614          1.1  christos 	}
    615  1.1.1.8.8.1  perseant #ifdef CONFIG_SAE
    616  1.1.1.8.8.1  perseant 	if (ssid->sae_password) {
    617  1.1.1.8.8.1  perseant 		struct sae_password_entry *pw;
    618  1.1.1.8.8.1  perseant 
    619  1.1.1.8.8.1  perseant 		pw = os_zalloc(sizeof(*pw));
    620  1.1.1.8.8.1  perseant 		if (!pw)
    621  1.1.1.8.8.1  perseant 			return -1;
    622  1.1.1.8.8.1  perseant 		os_memset(pw->peer_addr, 0xff, ETH_ALEN);
    623  1.1.1.8.8.1  perseant 		pw->password = os_strdup(ssid->sae_password);
    624  1.1.1.8.8.1  perseant 		if (!pw->password) {
    625  1.1.1.8.8.1  perseant 			os_free(pw);
    626  1.1.1.8.8.1  perseant 			return -1;
    627  1.1.1.8.8.1  perseant 		}
    628  1.1.1.8.8.1  perseant 		if (ssid->sae_password_id) {
    629  1.1.1.8.8.1  perseant 			pw->identifier = os_strdup(ssid->sae_password_id);
    630  1.1.1.8.8.1  perseant 			if (!pw->identifier) {
    631  1.1.1.8.8.1  perseant 				str_clear_free(pw->password);
    632  1.1.1.8.8.1  perseant 				os_free(pw);
    633  1.1.1.8.8.1  perseant 				return -1;
    634  1.1.1.8.8.1  perseant 			}
    635  1.1.1.8.8.1  perseant 		}
    636  1.1.1.8.8.1  perseant 
    637  1.1.1.8.8.1  perseant 		pw->next = bss->sae_passwords;
    638  1.1.1.8.8.1  perseant 		bss->sae_passwords = pw;
    639  1.1.1.8.8.1  perseant 	}
    640  1.1.1.8.8.1  perseant 
    641  1.1.1.8.8.1  perseant 	if (ssid->sae_pwe != DEFAULT_SAE_PWE)
    642  1.1.1.8.8.1  perseant 		bss->sae_pwe = ssid->sae_pwe;
    643  1.1.1.8.8.1  perseant 	else
    644  1.1.1.8.8.1  perseant 		bss->sae_pwe = wpa_s->conf->sae_pwe;
    645  1.1.1.8.8.1  perseant #endif /* CONFIG_SAE */
    646          1.1  christos 
    647      1.1.1.7  christos 	if (wpa_s->conf->go_interworking) {
    648      1.1.1.7  christos 		wpa_printf(MSG_DEBUG,
    649      1.1.1.7  christos 			   "P2P: Enable Interworking with access_network_type: %d",
    650      1.1.1.7  christos 			   wpa_s->conf->go_access_network_type);
    651      1.1.1.7  christos 		bss->interworking = wpa_s->conf->go_interworking;
    652      1.1.1.7  christos 		bss->access_network_type = wpa_s->conf->go_access_network_type;
    653      1.1.1.7  christos 		bss->internet = wpa_s->conf->go_internet;
    654      1.1.1.7  christos 		if (wpa_s->conf->go_venue_group) {
    655      1.1.1.7  christos 			wpa_printf(MSG_DEBUG,
    656      1.1.1.7  christos 				   "P2P: Venue group: %d  Venue type: %d",
    657      1.1.1.7  christos 				   wpa_s->conf->go_venue_group,
    658      1.1.1.7  christos 				   wpa_s->conf->go_venue_type);
    659      1.1.1.7  christos 			bss->venue_group = wpa_s->conf->go_venue_group;
    660      1.1.1.7  christos 			bss->venue_type = wpa_s->conf->go_venue_type;
    661      1.1.1.7  christos 			bss->venue_info_set = 1;
    662      1.1.1.7  christos 		}
    663      1.1.1.7  christos 	}
    664      1.1.1.7  christos 
    665      1.1.1.3  christos 	if (ssid->ap_max_inactivity)
    666      1.1.1.3  christos 		bss->ap_max_inactivity = ssid->ap_max_inactivity;
    667      1.1.1.3  christos 
    668      1.1.1.3  christos 	if (ssid->dtim_period)
    669      1.1.1.3  christos 		bss->dtim_period = ssid->dtim_period;
    670      1.1.1.4  christos 	else if (wpa_s->conf->dtim_period)
    671      1.1.1.4  christos 		bss->dtim_period = wpa_s->conf->dtim_period;
    672      1.1.1.3  christos 
    673      1.1.1.4  christos 	if (ssid->beacon_int)
    674      1.1.1.4  christos 		conf->beacon_int = ssid->beacon_int;
    675      1.1.1.4  christos 	else if (wpa_s->conf->beacon_int)
    676      1.1.1.4  christos 		conf->beacon_int = wpa_s->conf->beacon_int;
    677      1.1.1.4  christos 
    678      1.1.1.5  christos #ifdef CONFIG_P2P
    679      1.1.1.6  christos 	if (ssid->mode == WPAS_MODE_P2P_GO ||
    680      1.1.1.6  christos 	    ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION) {
    681      1.1.1.6  christos 		if (wpa_s->conf->p2p_go_ctwindow > conf->beacon_int) {
    682      1.1.1.6  christos 			wpa_printf(MSG_INFO,
    683      1.1.1.6  christos 				   "CTWindow (%d) is bigger than beacon interval (%d) - avoid configuring it",
    684      1.1.1.6  christos 				   wpa_s->conf->p2p_go_ctwindow,
    685      1.1.1.6  christos 				   conf->beacon_int);
    686      1.1.1.6  christos 			conf->p2p_go_ctwindow = 0;
    687      1.1.1.6  christos 		} else {
    688      1.1.1.6  christos 			conf->p2p_go_ctwindow = wpa_s->conf->p2p_go_ctwindow;
    689      1.1.1.6  christos 		}
    690      1.1.1.5  christos 	}
    691      1.1.1.5  christos #endif /* CONFIG_P2P */
    692      1.1.1.5  christos 
    693      1.1.1.4  christos 	if ((bss->wpa & 2) && bss->rsn_pairwise == 0)
    694      1.1.1.4  christos 		bss->rsn_pairwise = bss->wpa_pairwise;
    695      1.1.1.4  christos 	bss->wpa_group = wpa_select_ap_group_cipher(bss->wpa, bss->wpa_pairwise,
    696      1.1.1.4  christos 						    bss->rsn_pairwise);
    697          1.1  christos 
    698  1.1.1.8.8.1  perseant 	if (bss->wpa && bss->ieee802_1x) {
    699          1.1  christos 		bss->ssid.security_policy = SECURITY_WPA;
    700  1.1.1.8.8.1  perseant 	} else if (bss->wpa) {
    701          1.1  christos 		bss->ssid.security_policy = SECURITY_WPA_PSK;
    702  1.1.1.8.8.1  perseant #ifdef CONFIG_WEP
    703  1.1.1.8.8.1  perseant 	} else if (bss->ieee802_1x) {
    704      1.1.1.2  christos 		int cipher = WPA_CIPHER_NONE;
    705          1.1  christos 		bss->ssid.security_policy = SECURITY_IEEE_802_1X;
    706          1.1  christos 		bss->ssid.wep.default_len = bss->default_wep_key_len;
    707      1.1.1.2  christos 		if (bss->default_wep_key_len)
    708      1.1.1.2  christos 			cipher = bss->default_wep_key_len >= 13 ?
    709      1.1.1.2  christos 				WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
    710      1.1.1.2  christos 		bss->wpa_group = cipher;
    711      1.1.1.2  christos 		bss->wpa_pairwise = cipher;
    712      1.1.1.2  christos 		bss->rsn_pairwise = cipher;
    713      1.1.1.2  christos 	} else if (bss->ssid.wep.keys_set) {
    714      1.1.1.2  christos 		int cipher = WPA_CIPHER_WEP40;
    715      1.1.1.2  christos 		if (bss->ssid.wep.len[0] >= 13)
    716      1.1.1.2  christos 			cipher = WPA_CIPHER_WEP104;
    717          1.1  christos 		bss->ssid.security_policy = SECURITY_STATIC_WEP;
    718      1.1.1.2  christos 		bss->wpa_group = cipher;
    719      1.1.1.2  christos 		bss->wpa_pairwise = cipher;
    720      1.1.1.2  christos 		bss->rsn_pairwise = cipher;
    721  1.1.1.8.8.1  perseant #endif /* CONFIG_WEP */
    722      1.1.1.2  christos 	} else {
    723          1.1  christos 		bss->ssid.security_policy = SECURITY_PLAINTEXT;
    724      1.1.1.2  christos 		bss->wpa_group = WPA_CIPHER_NONE;
    725      1.1.1.2  christos 		bss->wpa_pairwise = WPA_CIPHER_NONE;
    726      1.1.1.2  christos 		bss->rsn_pairwise = WPA_CIPHER_NONE;
    727      1.1.1.2  christos 	}
    728          1.1  christos 
    729      1.1.1.4  christos 	if (bss->wpa_group_rekey < 86400 && (bss->wpa & 2) &&
    730      1.1.1.4  christos 	    (bss->wpa_group == WPA_CIPHER_CCMP ||
    731      1.1.1.4  christos 	     bss->wpa_group == WPA_CIPHER_GCMP ||
    732      1.1.1.4  christos 	     bss->wpa_group == WPA_CIPHER_CCMP_256 ||
    733      1.1.1.4  christos 	     bss->wpa_group == WPA_CIPHER_GCMP_256)) {
    734      1.1.1.4  christos 		/*
    735      1.1.1.4  christos 		 * Strong ciphers do not need frequent rekeying, so increase
    736      1.1.1.4  christos 		 * the default GTK rekeying period to 24 hours.
    737      1.1.1.4  christos 		 */
    738      1.1.1.4  christos 		bss->wpa_group_rekey = 86400;
    739      1.1.1.4  christos 	}
    740      1.1.1.4  christos 
    741  1.1.1.8.8.1  perseant 	if (ssid->ieee80211w != MGMT_FRAME_PROTECTION_DEFAULT) {
    742      1.1.1.4  christos 		bss->ieee80211w = ssid->ieee80211w;
    743  1.1.1.8.8.1  perseant 	} else if (wpa_s->conf->pmf != MGMT_FRAME_PROTECTION_DEFAULT) {
    744  1.1.1.8.8.1  perseant 		if (ssid->mode == WPAS_MODE_AP)
    745  1.1.1.8.8.1  perseant 			bss->ieee80211w = wpa_s->conf->pmf;
    746  1.1.1.8.8.1  perseant 	}
    747      1.1.1.4  christos 
    748      1.1.1.8  christos #ifdef CONFIG_OCV
    749      1.1.1.8  christos 	bss->ocv = ssid->ocv;
    750      1.1.1.8  christos #endif /* CONFIG_OCV */
    751      1.1.1.8  christos 
    752          1.1  christos #ifdef CONFIG_WPS
    753          1.1  christos 	/*
    754      1.1.1.2  christos 	 * Enable WPS by default for open and WPA/WPA2-Personal network, but
    755      1.1.1.2  christos 	 * require user interaction to actually use it. Only the internal
    756      1.1.1.2  christos 	 * Registrar is supported.
    757          1.1  christos 	 */
    758      1.1.1.2  christos 	if (bss->ssid.security_policy != SECURITY_WPA_PSK &&
    759      1.1.1.2  christos 	    bss->ssid.security_policy != SECURITY_PLAINTEXT)
    760      1.1.1.2  christos 		goto no_wps;
    761      1.1.1.2  christos 	if (bss->ssid.security_policy == SECURITY_WPA_PSK &&
    762      1.1.1.5  christos 	    (!(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP)) ||
    763      1.1.1.5  christos 	     !(bss->wpa & 2)))
    764      1.1.1.2  christos 		goto no_wps; /* WPS2 does not allow WPA/TKIP-only
    765      1.1.1.2  christos 			      * configuration */
    766      1.1.1.6  christos 	if (ssid->wps_disabled)
    767      1.1.1.6  christos 		goto no_wps;
    768          1.1  christos 	bss->eap_server = 1;
    769      1.1.1.3  christos 
    770      1.1.1.3  christos 	if (!ssid->ignore_broadcast_ssid)
    771      1.1.1.3  christos 		bss->wps_state = 2;
    772      1.1.1.3  christos 
    773      1.1.1.2  christos 	bss->ap_setup_locked = 2;
    774          1.1  christos 	if (wpa_s->conf->config_methods)
    775          1.1  christos 		bss->config_methods = os_strdup(wpa_s->conf->config_methods);
    776      1.1.1.2  christos 	os_memcpy(bss->device_type, wpa_s->conf->device_type,
    777      1.1.1.2  christos 		  WPS_DEV_TYPE_LEN);
    778      1.1.1.2  christos 	if (wpa_s->conf->device_name) {
    779      1.1.1.2  christos 		bss->device_name = os_strdup(wpa_s->conf->device_name);
    780      1.1.1.2  christos 		bss->friendly_name = os_strdup(wpa_s->conf->device_name);
    781      1.1.1.2  christos 	}
    782      1.1.1.2  christos 	if (wpa_s->conf->manufacturer)
    783      1.1.1.2  christos 		bss->manufacturer = os_strdup(wpa_s->conf->manufacturer);
    784      1.1.1.2  christos 	if (wpa_s->conf->model_name)
    785      1.1.1.2  christos 		bss->model_name = os_strdup(wpa_s->conf->model_name);
    786      1.1.1.2  christos 	if (wpa_s->conf->model_number)
    787      1.1.1.2  christos 		bss->model_number = os_strdup(wpa_s->conf->model_number);
    788      1.1.1.2  christos 	if (wpa_s->conf->serial_number)
    789      1.1.1.2  christos 		bss->serial_number = os_strdup(wpa_s->conf->serial_number);
    790      1.1.1.2  christos 	if (is_nil_uuid(wpa_s->conf->uuid))
    791      1.1.1.2  christos 		os_memcpy(bss->uuid, wpa_s->wps->uuid, WPS_UUID_LEN);
    792      1.1.1.2  christos 	else
    793      1.1.1.2  christos 		os_memcpy(bss->uuid, wpa_s->conf->uuid, WPS_UUID_LEN);
    794      1.1.1.2  christos 	os_memcpy(bss->os_version, wpa_s->conf->os_version, 4);
    795      1.1.1.3  christos 	bss->pbc_in_m1 = wpa_s->conf->pbc_in_m1;
    796      1.1.1.6  christos 	if (ssid->eap.fragment_size != DEFAULT_FRAGMENT_SIZE)
    797      1.1.1.6  christos 		bss->fragment_size = ssid->eap.fragment_size;
    798      1.1.1.2  christos no_wps:
    799          1.1  christos #endif /* CONFIG_WPS */
    800          1.1  christos 
    801      1.1.1.2  christos 	if (wpa_s->max_stations &&
    802      1.1.1.2  christos 	    wpa_s->max_stations < wpa_s->conf->max_num_sta)
    803      1.1.1.2  christos 		bss->max_num_sta = wpa_s->max_stations;
    804      1.1.1.2  christos 	else
    805      1.1.1.2  christos 		bss->max_num_sta = wpa_s->conf->max_num_sta;
    806      1.1.1.2  christos 
    807      1.1.1.7  christos 	if (!bss->isolate)
    808      1.1.1.7  christos 		bss->isolate = wpa_s->conf->ap_isolate;
    809      1.1.1.7  christos 
    810      1.1.1.2  christos 	bss->disassoc_low_ack = wpa_s->conf->disassoc_low_ack;
    811      1.1.1.2  christos 
    812      1.1.1.4  christos 	if (wpa_s->conf->ap_vendor_elements) {
    813      1.1.1.4  christos 		bss->vendor_elements =
    814      1.1.1.4  christos 			wpabuf_dup(wpa_s->conf->ap_vendor_elements);
    815      1.1.1.4  christos 	}
    816  1.1.1.8.8.1  perseant 	if (wpa_s->conf->ap_assocresp_elements) {
    817  1.1.1.8.8.1  perseant 		bss->assocresp_elements =
    818  1.1.1.8.8.1  perseant 			wpabuf_dup(wpa_s->conf->ap_assocresp_elements);
    819  1.1.1.8.8.1  perseant 	}
    820      1.1.1.4  christos 
    821      1.1.1.6  christos 	bss->ftm_responder = wpa_s->conf->ftm_responder;
    822      1.1.1.6  christos 	bss->ftm_initiator = wpa_s->conf->ftm_initiator;
    823      1.1.1.6  christos 
    824  1.1.1.8.8.1  perseant 	bss->transition_disable = ssid->transition_disable;
    825  1.1.1.8.8.1  perseant 
    826          1.1  christos 	return 0;
    827          1.1  christos }
    828          1.1  christos 
    829          1.1  christos 
    830          1.1  christos static void ap_public_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
    831          1.1  christos {
    832      1.1.1.2  christos #ifdef CONFIG_P2P
    833      1.1.1.2  christos 	struct wpa_supplicant *wpa_s = ctx;
    834      1.1.1.2  christos 	const struct ieee80211_mgmt *mgmt;
    835      1.1.1.2  christos 
    836      1.1.1.2  christos 	mgmt = (const struct ieee80211_mgmt *) buf;
    837      1.1.1.4  christos 	if (len < IEEE80211_HDRLEN + 1)
    838      1.1.1.4  christos 		return;
    839      1.1.1.4  christos 	if (mgmt->u.action.category != WLAN_ACTION_PUBLIC)
    840      1.1.1.2  christos 		return;
    841      1.1.1.2  christos 	wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
    842      1.1.1.2  christos 			   mgmt->u.action.category,
    843      1.1.1.4  christos 			   buf + IEEE80211_HDRLEN + 1,
    844      1.1.1.4  christos 			   len - IEEE80211_HDRLEN - 1, freq);
    845      1.1.1.2  christos #endif /* CONFIG_P2P */
    846      1.1.1.2  christos }
    847      1.1.1.2  christos 
    848      1.1.1.2  christos 
    849      1.1.1.2  christos static void ap_wps_event_cb(void *ctx, enum wps_event event,
    850      1.1.1.2  christos 			    union wps_event_data *data)
    851      1.1.1.2  christos {
    852      1.1.1.2  christos #ifdef CONFIG_P2P
    853      1.1.1.2  christos 	struct wpa_supplicant *wpa_s = ctx;
    854      1.1.1.2  christos 
    855      1.1.1.2  christos 	if (event == WPS_EV_FAIL) {
    856      1.1.1.2  christos 		struct wps_event_fail *fail = &data->fail;
    857      1.1.1.2  christos 
    858      1.1.1.6  christos 		if (wpa_s->p2pdev && wpa_s->p2pdev != wpa_s &&
    859      1.1.1.2  christos 		    wpa_s == wpa_s->global->p2p_group_formation) {
    860      1.1.1.2  christos 			/*
    861      1.1.1.2  christos 			 * src/ap/wps_hostapd.c has already sent this on the
    862      1.1.1.2  christos 			 * main interface, so only send on the parent interface
    863      1.1.1.2  christos 			 * here if needed.
    864      1.1.1.2  christos 			 */
    865      1.1.1.6  christos 			wpa_msg(wpa_s->p2pdev, MSG_INFO, WPS_EVENT_FAIL
    866      1.1.1.2  christos 				"msg=%d config_error=%d",
    867      1.1.1.2  christos 				fail->msg, fail->config_error);
    868      1.1.1.2  christos 		}
    869      1.1.1.2  christos 		wpas_p2p_wps_failed(wpa_s, fail);
    870      1.1.1.2  christos 	}
    871      1.1.1.2  christos #endif /* CONFIG_P2P */
    872      1.1.1.2  christos }
    873      1.1.1.2  christos 
    874      1.1.1.2  christos 
    875      1.1.1.2  christos static void ap_sta_authorized_cb(void *ctx, const u8 *mac_addr,
    876  1.1.1.8.8.1  perseant 				 int authorized, const u8 *p2p_dev_addr,
    877  1.1.1.8.8.1  perseant 				 const u8 *ip)
    878      1.1.1.2  christos {
    879  1.1.1.8.8.1  perseant 	wpas_notify_sta_authorized(ctx, mac_addr, authorized, p2p_dev_addr, ip);
    880      1.1.1.2  christos }
    881      1.1.1.2  christos 
    882      1.1.1.2  christos 
    883      1.1.1.4  christos #ifdef CONFIG_P2P
    884      1.1.1.4  christos static void ap_new_psk_cb(void *ctx, const u8 *mac_addr, const u8 *p2p_dev_addr,
    885      1.1.1.4  christos 			  const u8 *psk, size_t psk_len)
    886      1.1.1.4  christos {
    887      1.1.1.4  christos 
    888      1.1.1.4  christos 	struct wpa_supplicant *wpa_s = ctx;
    889      1.1.1.4  christos 	if (wpa_s->ap_iface == NULL || wpa_s->current_ssid == NULL)
    890      1.1.1.4  christos 		return;
    891      1.1.1.4  christos 	wpas_p2p_new_psk_cb(wpa_s, mac_addr, p2p_dev_addr, psk, psk_len);
    892      1.1.1.4  christos }
    893      1.1.1.4  christos #endif /* CONFIG_P2P */
    894      1.1.1.4  christos 
    895      1.1.1.4  christos 
    896      1.1.1.2  christos static int ap_vendor_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
    897      1.1.1.2  christos {
    898      1.1.1.2  christos #ifdef CONFIG_P2P
    899      1.1.1.2  christos 	struct wpa_supplicant *wpa_s = ctx;
    900      1.1.1.2  christos 	const struct ieee80211_mgmt *mgmt;
    901      1.1.1.2  christos 
    902      1.1.1.2  christos 	mgmt = (const struct ieee80211_mgmt *) buf;
    903      1.1.1.4  christos 	if (len < IEEE80211_HDRLEN + 1)
    904      1.1.1.2  christos 		return -1;
    905      1.1.1.2  christos 	wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
    906      1.1.1.2  christos 			   mgmt->u.action.category,
    907      1.1.1.4  christos 			   buf + IEEE80211_HDRLEN + 1,
    908      1.1.1.4  christos 			   len - IEEE80211_HDRLEN - 1, freq);
    909      1.1.1.2  christos #endif /* CONFIG_P2P */
    910      1.1.1.2  christos 	return 0;
    911          1.1  christos }
    912          1.1  christos 
    913          1.1  christos 
    914      1.1.1.2  christos static int ap_probe_req_rx(void *ctx, const u8 *sa, const u8 *da,
    915      1.1.1.3  christos 			   const u8 *bssid, const u8 *ie, size_t ie_len,
    916      1.1.1.3  christos 			   int ssi_signal)
    917          1.1  christos {
    918      1.1.1.2  christos 	struct wpa_supplicant *wpa_s = ctx;
    919      1.1.1.6  christos 	unsigned int freq = 0;
    920      1.1.1.6  christos 
    921      1.1.1.6  christos 	if (wpa_s->ap_iface)
    922      1.1.1.6  christos 		freq = wpa_s->ap_iface->freq;
    923      1.1.1.6  christos 
    924      1.1.1.3  christos 	return wpas_p2p_probe_req_rx(wpa_s, sa, da, bssid, ie, ie_len,
    925      1.1.1.6  christos 				     freq, ssi_signal);
    926          1.1  christos }
    927          1.1  christos 
    928          1.1  christos 
    929          1.1  christos static void ap_wps_reg_success_cb(void *ctx, const u8 *mac_addr,
    930          1.1  christos 				  const u8 *uuid_e)
    931          1.1  christos {
    932      1.1.1.2  christos 	struct wpa_supplicant *wpa_s = ctx;
    933      1.1.1.2  christos 	wpas_p2p_wps_success(wpa_s, mac_addr, 1);
    934      1.1.1.2  christos }
    935      1.1.1.2  christos 
    936      1.1.1.2  christos 
    937      1.1.1.2  christos static void wpas_ap_configured_cb(void *ctx)
    938      1.1.1.2  christos {
    939      1.1.1.2  christos 	struct wpa_supplicant *wpa_s = ctx;
    940      1.1.1.2  christos 
    941      1.1.1.7  christos 	wpa_printf(MSG_DEBUG, "AP interface setup completed - state %s",
    942      1.1.1.7  christos 		   hostapd_state_text(wpa_s->ap_iface->state));
    943      1.1.1.7  christos 	if (wpa_s->ap_iface->state == HAPD_IFACE_DISABLED) {
    944      1.1.1.7  christos 		wpa_supplicant_ap_deinit(wpa_s);
    945      1.1.1.7  christos 		return;
    946      1.1.1.7  christos 	}
    947      1.1.1.7  christos 
    948  1.1.1.8.8.1  perseant 	if (wpa_s->current_ssid) {
    949  1.1.1.8.8.1  perseant 		int acs = 0;
    950  1.1.1.8.8.1  perseant 
    951      1.1.1.6  christos #ifdef CONFIG_ACS
    952  1.1.1.8.8.1  perseant 		acs = wpa_s->current_ssid->acs;
    953      1.1.1.6  christos #endif /* CONFIG_ACS */
    954  1.1.1.8.8.1  perseant 		if (acs || (wpa_s->assoc_freq && wpa_s->ap_iface->freq &&
    955  1.1.1.8.8.1  perseant 			    (int) wpa_s->assoc_freq != wpa_s->ap_iface->freq)) {
    956  1.1.1.8.8.1  perseant 			wpa_s->assoc_freq = wpa_s->ap_iface->freq;
    957  1.1.1.8.8.1  perseant 			wpa_s->current_ssid->frequency = wpa_s->ap_iface->freq;
    958  1.1.1.8.8.1  perseant 		}
    959  1.1.1.8.8.1  perseant 	}
    960      1.1.1.6  christos 
    961      1.1.1.2  christos 	wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
    962      1.1.1.2  christos 
    963      1.1.1.2  christos 	if (wpa_s->ap_configured_cb)
    964      1.1.1.2  christos 		wpa_s->ap_configured_cb(wpa_s->ap_configured_cb_ctx,
    965      1.1.1.2  christos 					wpa_s->ap_configured_cb_data);
    966          1.1  christos }
    967          1.1  christos 
    968          1.1  christos 
    969          1.1  christos int wpa_supplicant_create_ap(struct wpa_supplicant *wpa_s,
    970          1.1  christos 			     struct wpa_ssid *ssid)
    971          1.1  christos {
    972          1.1  christos 	struct wpa_driver_associate_params params;
    973          1.1  christos 	struct hostapd_iface *hapd_iface;
    974          1.1  christos 	struct hostapd_config *conf;
    975          1.1  christos 	size_t i;
    976          1.1  christos 
    977          1.1  christos 	if (ssid->ssid == NULL || ssid->ssid_len == 0) {
    978          1.1  christos 		wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
    979          1.1  christos 		return -1;
    980          1.1  christos 	}
    981          1.1  christos 
    982          1.1  christos 	wpa_supplicant_ap_deinit(wpa_s);
    983          1.1  christos 
    984          1.1  christos 	wpa_printf(MSG_DEBUG, "Setting up AP (SSID='%s')",
    985          1.1  christos 		   wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
    986          1.1  christos 
    987          1.1  christos 	os_memset(&params, 0, sizeof(params));
    988          1.1  christos 	params.ssid = ssid->ssid;
    989          1.1  christos 	params.ssid_len = ssid->ssid_len;
    990          1.1  christos 	switch (ssid->mode) {
    991          1.1  christos 	case WPAS_MODE_AP:
    992      1.1.1.2  christos 	case WPAS_MODE_P2P_GO:
    993      1.1.1.2  christos 	case WPAS_MODE_P2P_GROUP_FORMATION:
    994          1.1  christos 		params.mode = IEEE80211_MODE_AP;
    995          1.1  christos 		break;
    996      1.1.1.4  christos 	default:
    997      1.1.1.4  christos 		return -1;
    998          1.1  christos 	}
    999      1.1.1.4  christos 	if (ssid->frequency == 0)
   1000      1.1.1.4  christos 		ssid->frequency = 2462; /* default channel 11 */
   1001      1.1.1.4  christos 	params.freq.freq = ssid->frequency;
   1002          1.1  christos 
   1003  1.1.1.8.8.1  perseant 	if ((ssid->mode == WPAS_MODE_AP || ssid->mode == WPAS_MODE_P2P_GO) &&
   1004  1.1.1.8.8.1  perseant 	    ssid->enable_edmg) {
   1005  1.1.1.8.8.1  perseant 		u8 primary_channel;
   1006  1.1.1.8.8.1  perseant 
   1007  1.1.1.8.8.1  perseant 		if (ieee80211_freq_to_chan(ssid->frequency, &primary_channel) ==
   1008  1.1.1.8.8.1  perseant 		    NUM_HOSTAPD_MODES) {
   1009  1.1.1.8.8.1  perseant 			wpa_printf(MSG_WARNING,
   1010  1.1.1.8.8.1  perseant 				   "EDMG: Failed to get the primary channel");
   1011  1.1.1.8.8.1  perseant 			return -1;
   1012  1.1.1.8.8.1  perseant 		}
   1013  1.1.1.8.8.1  perseant 
   1014  1.1.1.8.8.1  perseant 		hostapd_encode_edmg_chan(ssid->enable_edmg, ssid->edmg_channel,
   1015  1.1.1.8.8.1  perseant 					 primary_channel, &params.freq.edmg);
   1016  1.1.1.8.8.1  perseant 	}
   1017  1.1.1.8.8.1  perseant 
   1018      1.1.1.2  christos 	params.wpa_proto = ssid->proto;
   1019          1.1  christos 	if (ssid->key_mgmt & WPA_KEY_MGMT_PSK)
   1020          1.1  christos 		wpa_s->key_mgmt = WPA_KEY_MGMT_PSK;
   1021  1.1.1.8.8.1  perseant 	else if (ssid->key_mgmt & WPA_KEY_MGMT_SAE)
   1022  1.1.1.8.8.1  perseant 		wpa_s->key_mgmt = WPA_KEY_MGMT_SAE;
   1023          1.1  christos 	else
   1024          1.1  christos 		wpa_s->key_mgmt = WPA_KEY_MGMT_NONE;
   1025      1.1.1.4  christos 	params.key_mgmt_suite = wpa_s->key_mgmt;
   1026          1.1  christos 
   1027      1.1.1.4  christos 	wpa_s->pairwise_cipher = wpa_pick_pairwise_cipher(ssid->pairwise_cipher,
   1028      1.1.1.4  christos 							  1);
   1029      1.1.1.4  christos 	if (wpa_s->pairwise_cipher < 0) {
   1030          1.1  christos 		wpa_printf(MSG_WARNING, "WPA: Failed to select pairwise "
   1031          1.1  christos 			   "cipher.");
   1032          1.1  christos 		return -1;
   1033          1.1  christos 	}
   1034      1.1.1.4  christos 	params.pairwise_suite = wpa_s->pairwise_cipher;
   1035          1.1  christos 	params.group_suite = params.pairwise_suite;
   1036          1.1  christos 
   1037      1.1.1.2  christos #ifdef CONFIG_P2P
   1038      1.1.1.2  christos 	if (ssid->mode == WPAS_MODE_P2P_GO ||
   1039      1.1.1.2  christos 	    ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
   1040      1.1.1.2  christos 		params.p2p = 1;
   1041      1.1.1.2  christos #endif /* CONFIG_P2P */
   1042      1.1.1.2  christos 
   1043      1.1.1.6  christos 	if (wpa_s->p2pdev->set_ap_uapsd)
   1044      1.1.1.6  christos 		params.uapsd = wpa_s->p2pdev->ap_uapsd;
   1045      1.1.1.4  christos 	else if (params.p2p && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP_UAPSD))
   1046      1.1.1.4  christos 		params.uapsd = 1; /* mandatory for P2P GO */
   1047      1.1.1.2  christos 	else
   1048      1.1.1.2  christos 		params.uapsd = -1;
   1049      1.1.1.2  christos 
   1050      1.1.1.7  christos 	if (ieee80211_is_dfs(params.freq.freq, wpa_s->hw.modes,
   1051      1.1.1.7  christos 			     wpa_s->hw.num_modes))
   1052      1.1.1.5  christos 		params.freq.freq = 0; /* set channel after CAC */
   1053      1.1.1.5  christos 
   1054      1.1.1.6  christos 	if (params.p2p)
   1055      1.1.1.6  christos 		wpa_drv_get_ext_capa(wpa_s, WPA_IF_P2P_GO);
   1056      1.1.1.6  christos 	else
   1057      1.1.1.6  christos 		wpa_drv_get_ext_capa(wpa_s, WPA_IF_AP_BSS);
   1058      1.1.1.6  christos 
   1059          1.1  christos 	if (wpa_drv_associate(wpa_s, &params) < 0) {
   1060          1.1  christos 		wpa_msg(wpa_s, MSG_INFO, "Failed to start AP functionality");
   1061          1.1  christos 		return -1;
   1062          1.1  christos 	}
   1063          1.1  christos 
   1064      1.1.1.6  christos 	wpa_s->ap_iface = hapd_iface = hostapd_alloc_iface();
   1065          1.1  christos 	if (hapd_iface == NULL)
   1066          1.1  christos 		return -1;
   1067          1.1  christos 	hapd_iface->owner = wpa_s;
   1068      1.1.1.2  christos 	hapd_iface->drv_flags = wpa_s->drv_flags;
   1069  1.1.1.8.8.1  perseant 	hapd_iface->drv_flags2 = wpa_s->drv_flags2;
   1070      1.1.1.3  christos 	hapd_iface->probe_resp_offloads = wpa_s->probe_resp_offloads;
   1071      1.1.1.4  christos 	hapd_iface->extended_capa = wpa_s->extended_capa;
   1072      1.1.1.4  christos 	hapd_iface->extended_capa_mask = wpa_s->extended_capa_mask;
   1073      1.1.1.4  christos 	hapd_iface->extended_capa_len = wpa_s->extended_capa_len;
   1074  1.1.1.8.8.1  perseant 	hapd_iface->drv_max_acl_mac_addrs = wpa_s->drv_max_acl_mac_addrs;
   1075          1.1  christos 
   1076          1.1  christos 	wpa_s->ap_iface->conf = conf = hostapd_config_defaults();
   1077          1.1  christos 	if (conf == NULL) {
   1078          1.1  christos 		wpa_supplicant_ap_deinit(wpa_s);
   1079          1.1  christos 		return -1;
   1080          1.1  christos 	}
   1081          1.1  christos 
   1082      1.1.1.3  christos 	os_memcpy(wpa_s->ap_iface->conf->wmm_ac_params,
   1083      1.1.1.3  christos 		  wpa_s->conf->wmm_ac_params,
   1084      1.1.1.3  christos 		  sizeof(wpa_s->conf->wmm_ac_params));
   1085      1.1.1.3  christos 
   1086  1.1.1.8.8.1  perseant 	os_memcpy(wpa_s->ap_iface->conf->tx_queue, wpa_s->conf->tx_queue,
   1087  1.1.1.8.8.1  perseant 		  sizeof(wpa_s->conf->tx_queue));
   1088  1.1.1.8.8.1  perseant 
   1089      1.1.1.2  christos 	if (params.uapsd > 0) {
   1090      1.1.1.4  christos 		conf->bss[0]->wmm_enabled = 1;
   1091      1.1.1.4  christos 		conf->bss[0]->wmm_uapsd = 1;
   1092      1.1.1.2  christos 	}
   1093      1.1.1.2  christos 
   1094          1.1  christos 	if (wpa_supplicant_conf_ap(wpa_s, ssid, conf)) {
   1095          1.1  christos 		wpa_printf(MSG_ERROR, "Failed to create AP configuration");
   1096          1.1  christos 		wpa_supplicant_ap_deinit(wpa_s);
   1097          1.1  christos 		return -1;
   1098          1.1  christos 	}
   1099          1.1  christos 
   1100      1.1.1.2  christos #ifdef CONFIG_P2P
   1101      1.1.1.2  christos 	if (ssid->mode == WPAS_MODE_P2P_GO)
   1102      1.1.1.4  christos 		conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
   1103      1.1.1.2  christos 	else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
   1104      1.1.1.4  christos 		conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
   1105      1.1.1.2  christos 			P2P_GROUP_FORMATION;
   1106      1.1.1.2  christos #endif /* CONFIG_P2P */
   1107      1.1.1.2  christos 
   1108          1.1  christos 	hapd_iface->num_bss = conf->num_bss;
   1109      1.1.1.3  christos 	hapd_iface->bss = os_calloc(conf->num_bss,
   1110          1.1  christos 				    sizeof(struct hostapd_data *));
   1111          1.1  christos 	if (hapd_iface->bss == NULL) {
   1112          1.1  christos 		wpa_supplicant_ap_deinit(wpa_s);
   1113          1.1  christos 		return -1;
   1114          1.1  christos 	}
   1115          1.1  christos 
   1116          1.1  christos 	for (i = 0; i < conf->num_bss; i++) {
   1117          1.1  christos 		hapd_iface->bss[i] =
   1118          1.1  christos 			hostapd_alloc_bss_data(hapd_iface, conf,
   1119      1.1.1.4  christos 					       conf->bss[i]);
   1120          1.1  christos 		if (hapd_iface->bss[i] == NULL) {
   1121          1.1  christos 			wpa_supplicant_ap_deinit(wpa_s);
   1122          1.1  christos 			return -1;
   1123          1.1  christos 		}
   1124          1.1  christos 
   1125          1.1  christos 		hapd_iface->bss[i]->msg_ctx = wpa_s;
   1126      1.1.1.6  christos 		hapd_iface->bss[i]->msg_ctx_parent = wpa_s->p2pdev;
   1127          1.1  christos 		hapd_iface->bss[i]->public_action_cb = ap_public_action_rx;
   1128          1.1  christos 		hapd_iface->bss[i]->public_action_cb_ctx = wpa_s;
   1129      1.1.1.2  christos 		hapd_iface->bss[i]->vendor_action_cb = ap_vendor_action_rx;
   1130      1.1.1.2  christos 		hapd_iface->bss[i]->vendor_action_cb_ctx = wpa_s;
   1131          1.1  christos 		hostapd_register_probereq_cb(hapd_iface->bss[i],
   1132          1.1  christos 					     ap_probe_req_rx, wpa_s);
   1133          1.1  christos 		hapd_iface->bss[i]->wps_reg_success_cb = ap_wps_reg_success_cb;
   1134          1.1  christos 		hapd_iface->bss[i]->wps_reg_success_cb_ctx = wpa_s;
   1135      1.1.1.2  christos 		hapd_iface->bss[i]->wps_event_cb = ap_wps_event_cb;
   1136      1.1.1.2  christos 		hapd_iface->bss[i]->wps_event_cb_ctx = wpa_s;
   1137      1.1.1.2  christos 		hapd_iface->bss[i]->sta_authorized_cb = ap_sta_authorized_cb;
   1138      1.1.1.2  christos 		hapd_iface->bss[i]->sta_authorized_cb_ctx = wpa_s;
   1139      1.1.1.2  christos #ifdef CONFIG_P2P
   1140      1.1.1.4  christos 		hapd_iface->bss[i]->new_psk_cb = ap_new_psk_cb;
   1141      1.1.1.4  christos 		hapd_iface->bss[i]->new_psk_cb_ctx = wpa_s;
   1142      1.1.1.2  christos 		hapd_iface->bss[i]->p2p = wpa_s->global->p2p;
   1143      1.1.1.3  christos 		hapd_iface->bss[i]->p2p_group = wpas_p2p_group_init(wpa_s,
   1144      1.1.1.3  christos 								    ssid);
   1145      1.1.1.2  christos #endif /* CONFIG_P2P */
   1146      1.1.1.2  christos 		hapd_iface->bss[i]->setup_complete_cb = wpas_ap_configured_cb;
   1147      1.1.1.2  christos 		hapd_iface->bss[i]->setup_complete_cb_ctx = wpa_s;
   1148      1.1.1.5  christos #ifdef CONFIG_TESTING_OPTIONS
   1149      1.1.1.5  christos 		hapd_iface->bss[i]->ext_eapol_frame_io =
   1150      1.1.1.5  christos 			wpa_s->ext_eapol_frame_io;
   1151      1.1.1.5  christos #endif /* CONFIG_TESTING_OPTIONS */
   1152  1.1.1.8.8.1  perseant 
   1153  1.1.1.8.8.1  perseant #ifdef CONFIG_WNM_AP
   1154  1.1.1.8.8.1  perseant 		if (ssid->mode == WPAS_MODE_AP)
   1155  1.1.1.8.8.1  perseant 			hapd_iface->bss[i]->conf->bss_transition = 1;
   1156  1.1.1.8.8.1  perseant #endif /* CONFIG_WNM_AP */
   1157          1.1  christos 	}
   1158          1.1  christos 
   1159          1.1  christos 	os_memcpy(hapd_iface->bss[0]->own_addr, wpa_s->own_addr, ETH_ALEN);
   1160          1.1  christos 	hapd_iface->bss[0]->driver = wpa_s->driver;
   1161          1.1  christos 	hapd_iface->bss[0]->drv_priv = wpa_s->drv_priv;
   1162          1.1  christos 
   1163      1.1.1.2  christos 	wpa_s->current_ssid = ssid;
   1164      1.1.1.4  christos 	eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
   1165      1.1.1.2  christos 	os_memcpy(wpa_s->bssid, wpa_s->own_addr, ETH_ALEN);
   1166      1.1.1.2  christos 	wpa_s->assoc_freq = ssid->frequency;
   1167  1.1.1.8.8.1  perseant 	wpa_s->ap_iface->conf->enable_edmg = ssid->enable_edmg;
   1168  1.1.1.8.8.1  perseant 	wpa_s->ap_iface->conf->edmg_channel = ssid->edmg_channel;
   1169      1.1.1.2  christos 
   1170      1.1.1.7  christos #if defined(CONFIG_P2P) && defined(CONFIG_ACS)
   1171      1.1.1.7  christos 	if (wpa_s->p2p_go_do_acs) {
   1172      1.1.1.7  christos 		wpa_s->ap_iface->conf->channel = 0;
   1173      1.1.1.7  christos 		wpa_s->ap_iface->conf->hw_mode = wpa_s->p2p_go_acs_band;
   1174      1.1.1.7  christos 		ssid->acs = 1;
   1175      1.1.1.7  christos 	}
   1176      1.1.1.7  christos #endif /* CONFIG_P2P && CONFIG_ACS */
   1177      1.1.1.7  christos 
   1178          1.1  christos 	if (hostapd_setup_interface(wpa_s->ap_iface)) {
   1179          1.1  christos 		wpa_printf(MSG_ERROR, "Failed to initialize AP interface");
   1180          1.1  christos 		wpa_supplicant_ap_deinit(wpa_s);
   1181          1.1  christos 		return -1;
   1182          1.1  christos 	}
   1183          1.1  christos 
   1184          1.1  christos 	return 0;
   1185          1.1  christos }
   1186          1.1  christos 
   1187          1.1  christos 
   1188          1.1  christos void wpa_supplicant_ap_deinit(struct wpa_supplicant *wpa_s)
   1189          1.1  christos {
   1190      1.1.1.2  christos #ifdef CONFIG_WPS
   1191      1.1.1.2  christos 	eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
   1192      1.1.1.2  christos #endif /* CONFIG_WPS */
   1193      1.1.1.2  christos 
   1194          1.1  christos 	if (wpa_s->ap_iface == NULL)
   1195          1.1  christos 		return;
   1196          1.1  christos 
   1197          1.1  christos 	wpa_s->current_ssid = NULL;
   1198      1.1.1.4  christos 	eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
   1199      1.1.1.2  christos 	wpa_s->assoc_freq = 0;
   1200      1.1.1.4  christos 	wpas_p2p_ap_deinit(wpa_s);
   1201      1.1.1.4  christos 	wpa_s->ap_iface->driver_ap_teardown =
   1202      1.1.1.4  christos 		!!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP_TEARDOWN_SUPPORT);
   1203      1.1.1.4  christos 
   1204          1.1  christos 	hostapd_interface_deinit(wpa_s->ap_iface);
   1205          1.1  christos 	hostapd_interface_free(wpa_s->ap_iface);
   1206          1.1  christos 	wpa_s->ap_iface = NULL;
   1207          1.1  christos 	wpa_drv_deinit_ap(wpa_s);
   1208      1.1.1.5  christos 	wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR
   1209      1.1.1.5  christos 		" reason=%d locally_generated=1",
   1210      1.1.1.5  christos 		MAC2STR(wpa_s->own_addr), WLAN_REASON_DEAUTH_LEAVING);
   1211          1.1  christos }
   1212          1.1  christos 
   1213          1.1  christos 
   1214          1.1  christos void ap_tx_status(void *ctx, const u8 *addr,
   1215          1.1  christos 		  const u8 *buf, size_t len, int ack)
   1216          1.1  christos {
   1217          1.1  christos #ifdef NEED_AP_MLME
   1218          1.1  christos 	struct wpa_supplicant *wpa_s = ctx;
   1219          1.1  christos 	hostapd_tx_status(wpa_s->ap_iface->bss[0], addr, buf, len, ack);
   1220          1.1  christos #endif /* NEED_AP_MLME */
   1221          1.1  christos }
   1222          1.1  christos 
   1223          1.1  christos 
   1224      1.1.1.3  christos void ap_eapol_tx_status(void *ctx, const u8 *dst,
   1225      1.1.1.3  christos 			const u8 *data, size_t len, int ack)
   1226      1.1.1.3  christos {
   1227      1.1.1.3  christos #ifdef NEED_AP_MLME
   1228      1.1.1.3  christos 	struct wpa_supplicant *wpa_s = ctx;
   1229      1.1.1.4  christos 	if (!wpa_s->ap_iface)
   1230      1.1.1.4  christos 		return;
   1231      1.1.1.3  christos 	hostapd_tx_status(wpa_s->ap_iface->bss[0], dst, data, len, ack);
   1232      1.1.1.3  christos #endif /* NEED_AP_MLME */
   1233      1.1.1.3  christos }
   1234      1.1.1.3  christos 
   1235      1.1.1.3  christos 
   1236      1.1.1.2  christos void ap_client_poll_ok(void *ctx, const u8 *addr)
   1237          1.1  christos {
   1238          1.1  christos #ifdef NEED_AP_MLME
   1239          1.1  christos 	struct wpa_supplicant *wpa_s = ctx;
   1240      1.1.1.2  christos 	if (wpa_s->ap_iface)
   1241      1.1.1.2  christos 		hostapd_client_poll_ok(wpa_s->ap_iface->bss[0], addr);
   1242      1.1.1.2  christos #endif /* NEED_AP_MLME */
   1243      1.1.1.2  christos }
   1244      1.1.1.2  christos 
   1245      1.1.1.2  christos 
   1246      1.1.1.2  christos void ap_rx_from_unknown_sta(void *ctx, const u8 *addr, int wds)
   1247      1.1.1.2  christos {
   1248      1.1.1.2  christos #ifdef NEED_AP_MLME
   1249      1.1.1.2  christos 	struct wpa_supplicant *wpa_s = ctx;
   1250      1.1.1.2  christos 	ieee802_11_rx_from_unknown(wpa_s->ap_iface->bss[0], addr, wds);
   1251          1.1  christos #endif /* NEED_AP_MLME */
   1252          1.1  christos }
   1253          1.1  christos 
   1254          1.1  christos 
   1255          1.1  christos void ap_mgmt_rx(void *ctx, struct rx_mgmt *rx_mgmt)
   1256          1.1  christos {
   1257          1.1  christos #ifdef NEED_AP_MLME
   1258          1.1  christos 	struct wpa_supplicant *wpa_s = ctx;
   1259          1.1  christos 	struct hostapd_frame_info fi;
   1260          1.1  christos 	os_memset(&fi, 0, sizeof(fi));
   1261  1.1.1.8.8.1  perseant 	fi.freq = rx_mgmt->freq;
   1262          1.1  christos 	fi.datarate = rx_mgmt->datarate;
   1263          1.1  christos 	fi.ssi_signal = rx_mgmt->ssi_signal;
   1264          1.1  christos 	ieee802_11_mgmt(wpa_s->ap_iface->bss[0], rx_mgmt->frame,
   1265          1.1  christos 			rx_mgmt->frame_len, &fi);
   1266          1.1  christos #endif /* NEED_AP_MLME */
   1267          1.1  christos }
   1268          1.1  christos 
   1269          1.1  christos 
   1270          1.1  christos void ap_mgmt_tx_cb(void *ctx, const u8 *buf, size_t len, u16 stype, int ok)
   1271          1.1  christos {
   1272          1.1  christos #ifdef NEED_AP_MLME
   1273          1.1  christos 	struct wpa_supplicant *wpa_s = ctx;
   1274          1.1  christos 	ieee802_11_mgmt_cb(wpa_s->ap_iface->bss[0], buf, len, stype, ok);
   1275          1.1  christos #endif /* NEED_AP_MLME */
   1276          1.1  christos }
   1277          1.1  christos 
   1278          1.1  christos 
   1279          1.1  christos void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant *wpa_s,
   1280  1.1.1.8.8.1  perseant 				const u8 *src_addr, const u8 *buf, size_t len,
   1281  1.1.1.8.8.1  perseant 				enum frame_encryption encrypted)
   1282          1.1  christos {
   1283  1.1.1.8.8.1  perseant 	ieee802_1x_receive(wpa_s->ap_iface->bss[0], src_addr, buf, len,
   1284  1.1.1.8.8.1  perseant 			   encrypted);
   1285          1.1  christos }
   1286          1.1  christos 
   1287          1.1  christos 
   1288          1.1  christos #ifdef CONFIG_WPS
   1289          1.1  christos 
   1290      1.1.1.2  christos int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid,
   1291      1.1.1.2  christos 			      const u8 *p2p_dev_addr)
   1292          1.1  christos {
   1293          1.1  christos 	if (!wpa_s->ap_iface)
   1294          1.1  christos 		return -1;
   1295      1.1.1.2  christos 	return hostapd_wps_button_pushed(wpa_s->ap_iface->bss[0],
   1296      1.1.1.2  christos 					 p2p_dev_addr);
   1297      1.1.1.2  christos }
   1298      1.1.1.2  christos 
   1299      1.1.1.2  christos 
   1300      1.1.1.2  christos int wpa_supplicant_ap_wps_cancel(struct wpa_supplicant *wpa_s)
   1301      1.1.1.2  christos {
   1302      1.1.1.2  christos 	struct wps_registrar *reg;
   1303      1.1.1.2  christos 	int reg_sel = 0, wps_sta = 0;
   1304      1.1.1.2  christos 
   1305      1.1.1.2  christos 	if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0]->wps)
   1306      1.1.1.2  christos 		return -1;
   1307      1.1.1.2  christos 
   1308      1.1.1.2  christos 	reg = wpa_s->ap_iface->bss[0]->wps->registrar;
   1309      1.1.1.2  christos 	reg_sel = wps_registrar_wps_cancel(reg);
   1310      1.1.1.2  christos 	wps_sta = ap_for_each_sta(wpa_s->ap_iface->bss[0],
   1311      1.1.1.3  christos 				  ap_sta_wps_cancel, NULL);
   1312      1.1.1.2  christos 
   1313      1.1.1.2  christos 	if (!reg_sel && !wps_sta) {
   1314      1.1.1.2  christos 		wpa_printf(MSG_DEBUG, "No WPS operation in progress at this "
   1315      1.1.1.2  christos 			   "time");
   1316      1.1.1.2  christos 		return -1;
   1317      1.1.1.2  christos 	}
   1318      1.1.1.2  christos 
   1319      1.1.1.2  christos 	/*
   1320      1.1.1.2  christos 	 * There are 2 cases to return wps cancel as success:
   1321      1.1.1.2  christos 	 * 1. When wps cancel was initiated but no connection has been
   1322      1.1.1.2  christos 	 *    established with client yet.
   1323      1.1.1.2  christos 	 * 2. Client is in the middle of exchanging WPS messages.
   1324      1.1.1.2  christos 	 */
   1325      1.1.1.2  christos 
   1326      1.1.1.2  christos 	return 0;
   1327          1.1  christos }
   1328          1.1  christos 
   1329          1.1  christos 
   1330          1.1  christos int wpa_supplicant_ap_wps_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
   1331      1.1.1.3  christos 			      const char *pin, char *buf, size_t buflen,
   1332      1.1.1.3  christos 			      int timeout)
   1333          1.1  christos {
   1334          1.1  christos 	int ret, ret_len = 0;
   1335          1.1  christos 
   1336          1.1  christos 	if (!wpa_s->ap_iface)
   1337          1.1  christos 		return -1;
   1338          1.1  christos 
   1339          1.1  christos 	if (pin == NULL) {
   1340      1.1.1.6  christos 		unsigned int rpin;
   1341      1.1.1.6  christos 
   1342      1.1.1.6  christos 		if (wps_generate_pin(&rpin) < 0)
   1343      1.1.1.6  christos 			return -1;
   1344      1.1.1.2  christos 		ret_len = os_snprintf(buf, buflen, "%08d", rpin);
   1345      1.1.1.5  christos 		if (os_snprintf_error(buflen, ret_len))
   1346      1.1.1.5  christos 			return -1;
   1347          1.1  christos 		pin = buf;
   1348      1.1.1.5  christos 	} else if (buf) {
   1349      1.1.1.2  christos 		ret_len = os_snprintf(buf, buflen, "%s", pin);
   1350      1.1.1.5  christos 		if (os_snprintf_error(buflen, ret_len))
   1351      1.1.1.5  christos 			return -1;
   1352      1.1.1.5  christos 	}
   1353          1.1  christos 
   1354      1.1.1.2  christos 	ret = hostapd_wps_add_pin(wpa_s->ap_iface->bss[0], bssid, "any", pin,
   1355      1.1.1.3  christos 				  timeout);
   1356          1.1  christos 	if (ret)
   1357          1.1  christos 		return -1;
   1358          1.1  christos 	return ret_len;
   1359          1.1  christos }
   1360          1.1  christos 
   1361      1.1.1.2  christos 
   1362      1.1.1.2  christos static void wpas_wps_ap_pin_timeout(void *eloop_data, void *user_ctx)
   1363      1.1.1.2  christos {
   1364      1.1.1.2  christos 	struct wpa_supplicant *wpa_s = eloop_data;
   1365      1.1.1.2  christos 	wpa_printf(MSG_DEBUG, "WPS: AP PIN timed out");
   1366      1.1.1.2  christos 	wpas_wps_ap_pin_disable(wpa_s);
   1367      1.1.1.2  christos }
   1368      1.1.1.2  christos 
   1369      1.1.1.2  christos 
   1370      1.1.1.2  christos static void wpas_wps_ap_pin_enable(struct wpa_supplicant *wpa_s, int timeout)
   1371      1.1.1.2  christos {
   1372      1.1.1.2  christos 	struct hostapd_data *hapd;
   1373      1.1.1.2  christos 
   1374      1.1.1.2  christos 	if (wpa_s->ap_iface == NULL)
   1375      1.1.1.2  christos 		return;
   1376      1.1.1.2  christos 	hapd = wpa_s->ap_iface->bss[0];
   1377      1.1.1.2  christos 	wpa_printf(MSG_DEBUG, "WPS: Enabling AP PIN (timeout=%d)", timeout);
   1378      1.1.1.2  christos 	hapd->ap_pin_failures = 0;
   1379      1.1.1.2  christos 	eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
   1380      1.1.1.2  christos 	if (timeout > 0)
   1381      1.1.1.2  christos 		eloop_register_timeout(timeout, 0,
   1382      1.1.1.2  christos 				       wpas_wps_ap_pin_timeout, wpa_s, NULL);
   1383      1.1.1.2  christos }
   1384      1.1.1.2  christos 
   1385      1.1.1.2  christos 
   1386      1.1.1.2  christos void wpas_wps_ap_pin_disable(struct wpa_supplicant *wpa_s)
   1387      1.1.1.2  christos {
   1388      1.1.1.2  christos 	struct hostapd_data *hapd;
   1389      1.1.1.2  christos 
   1390      1.1.1.2  christos 	if (wpa_s->ap_iface == NULL)
   1391      1.1.1.2  christos 		return;
   1392      1.1.1.2  christos 	wpa_printf(MSG_DEBUG, "WPS: Disabling AP PIN");
   1393      1.1.1.2  christos 	hapd = wpa_s->ap_iface->bss[0];
   1394      1.1.1.2  christos 	os_free(hapd->conf->ap_pin);
   1395      1.1.1.2  christos 	hapd->conf->ap_pin = NULL;
   1396      1.1.1.2  christos 	eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
   1397      1.1.1.2  christos }
   1398      1.1.1.2  christos 
   1399      1.1.1.2  christos 
   1400      1.1.1.2  christos const char * wpas_wps_ap_pin_random(struct wpa_supplicant *wpa_s, int timeout)
   1401      1.1.1.2  christos {
   1402      1.1.1.2  christos 	struct hostapd_data *hapd;
   1403      1.1.1.2  christos 	unsigned int pin;
   1404      1.1.1.2  christos 	char pin_txt[9];
   1405      1.1.1.2  christos 
   1406      1.1.1.2  christos 	if (wpa_s->ap_iface == NULL)
   1407      1.1.1.2  christos 		return NULL;
   1408      1.1.1.2  christos 	hapd = wpa_s->ap_iface->bss[0];
   1409      1.1.1.6  christos 	if (wps_generate_pin(&pin) < 0)
   1410      1.1.1.6  christos 		return NULL;
   1411      1.1.1.2  christos 	os_snprintf(pin_txt, sizeof(pin_txt), "%08u", pin);
   1412      1.1.1.2  christos 	os_free(hapd->conf->ap_pin);
   1413      1.1.1.2  christos 	hapd->conf->ap_pin = os_strdup(pin_txt);
   1414      1.1.1.2  christos 	if (hapd->conf->ap_pin == NULL)
   1415      1.1.1.2  christos 		return NULL;
   1416      1.1.1.2  christos 	wpas_wps_ap_pin_enable(wpa_s, timeout);
   1417      1.1.1.2  christos 
   1418      1.1.1.2  christos 	return hapd->conf->ap_pin;
   1419      1.1.1.2  christos }
   1420      1.1.1.2  christos 
   1421      1.1.1.2  christos 
   1422      1.1.1.2  christos const char * wpas_wps_ap_pin_get(struct wpa_supplicant *wpa_s)
   1423      1.1.1.2  christos {
   1424      1.1.1.2  christos 	struct hostapd_data *hapd;
   1425      1.1.1.2  christos 	if (wpa_s->ap_iface == NULL)
   1426      1.1.1.2  christos 		return NULL;
   1427      1.1.1.2  christos 	hapd = wpa_s->ap_iface->bss[0];
   1428      1.1.1.2  christos 	return hapd->conf->ap_pin;
   1429      1.1.1.2  christos }
   1430      1.1.1.2  christos 
   1431      1.1.1.2  christos 
   1432      1.1.1.2  christos int wpas_wps_ap_pin_set(struct wpa_supplicant *wpa_s, const char *pin,
   1433      1.1.1.2  christos 			int timeout)
   1434      1.1.1.2  christos {
   1435      1.1.1.2  christos 	struct hostapd_data *hapd;
   1436      1.1.1.2  christos 	char pin_txt[9];
   1437      1.1.1.2  christos 	int ret;
   1438      1.1.1.2  christos 
   1439      1.1.1.2  christos 	if (wpa_s->ap_iface == NULL)
   1440      1.1.1.2  christos 		return -1;
   1441      1.1.1.2  christos 	hapd = wpa_s->ap_iface->bss[0];
   1442      1.1.1.2  christos 	ret = os_snprintf(pin_txt, sizeof(pin_txt), "%s", pin);
   1443      1.1.1.5  christos 	if (os_snprintf_error(sizeof(pin_txt), ret))
   1444      1.1.1.2  christos 		return -1;
   1445      1.1.1.2  christos 	os_free(hapd->conf->ap_pin);
   1446      1.1.1.2  christos 	hapd->conf->ap_pin = os_strdup(pin_txt);
   1447      1.1.1.2  christos 	if (hapd->conf->ap_pin == NULL)
   1448      1.1.1.2  christos 		return -1;
   1449      1.1.1.2  christos 	wpas_wps_ap_pin_enable(wpa_s, timeout);
   1450      1.1.1.2  christos 
   1451      1.1.1.2  christos 	return 0;
   1452      1.1.1.2  christos }
   1453      1.1.1.2  christos 
   1454      1.1.1.2  christos 
   1455      1.1.1.2  christos void wpa_supplicant_ap_pwd_auth_fail(struct wpa_supplicant *wpa_s)
   1456      1.1.1.2  christos {
   1457      1.1.1.2  christos 	struct hostapd_data *hapd;
   1458      1.1.1.2  christos 
   1459      1.1.1.2  christos 	if (wpa_s->ap_iface == NULL)
   1460      1.1.1.2  christos 		return;
   1461      1.1.1.2  christos 	hapd = wpa_s->ap_iface->bss[0];
   1462      1.1.1.2  christos 
   1463      1.1.1.2  christos 	/*
   1464      1.1.1.2  christos 	 * Registrar failed to prove its knowledge of the AP PIN. Disable AP
   1465      1.1.1.2  christos 	 * PIN if this happens multiple times to slow down brute force attacks.
   1466      1.1.1.2  christos 	 */
   1467      1.1.1.2  christos 	hapd->ap_pin_failures++;
   1468      1.1.1.2  christos 	wpa_printf(MSG_DEBUG, "WPS: AP PIN authentication failure number %u",
   1469      1.1.1.2  christos 		   hapd->ap_pin_failures);
   1470      1.1.1.2  christos 	if (hapd->ap_pin_failures < 3)
   1471      1.1.1.2  christos 		return;
   1472      1.1.1.2  christos 
   1473      1.1.1.2  christos 	wpa_printf(MSG_DEBUG, "WPS: Disable AP PIN");
   1474      1.1.1.2  christos 	hapd->ap_pin_failures = 0;
   1475      1.1.1.2  christos 	os_free(hapd->conf->ap_pin);
   1476      1.1.1.2  christos 	hapd->conf->ap_pin = NULL;
   1477      1.1.1.2  christos }
   1478      1.1.1.2  christos 
   1479      1.1.1.4  christos 
   1480      1.1.1.4  christos #ifdef CONFIG_WPS_NFC
   1481      1.1.1.4  christos 
   1482      1.1.1.4  christos struct wpabuf * wpas_ap_wps_nfc_config_token(struct wpa_supplicant *wpa_s,
   1483      1.1.1.4  christos 					     int ndef)
   1484      1.1.1.4  christos {
   1485      1.1.1.4  christos 	struct hostapd_data *hapd;
   1486      1.1.1.4  christos 
   1487      1.1.1.4  christos 	if (wpa_s->ap_iface == NULL)
   1488      1.1.1.4  christos 		return NULL;
   1489      1.1.1.4  christos 	hapd = wpa_s->ap_iface->bss[0];
   1490      1.1.1.4  christos 	return hostapd_wps_nfc_config_token(hapd, ndef);
   1491      1.1.1.4  christos }
   1492      1.1.1.4  christos 
   1493      1.1.1.4  christos 
   1494      1.1.1.4  christos struct wpabuf * wpas_ap_wps_nfc_handover_sel(struct wpa_supplicant *wpa_s,
   1495      1.1.1.4  christos 					     int ndef)
   1496      1.1.1.4  christos {
   1497      1.1.1.4  christos 	struct hostapd_data *hapd;
   1498      1.1.1.4  christos 
   1499      1.1.1.4  christos 	if (wpa_s->ap_iface == NULL)
   1500      1.1.1.4  christos 		return NULL;
   1501      1.1.1.4  christos 	hapd = wpa_s->ap_iface->bss[0];
   1502      1.1.1.4  christos 	return hostapd_wps_nfc_hs_cr(hapd, ndef);
   1503      1.1.1.4  christos }
   1504      1.1.1.4  christos 
   1505      1.1.1.4  christos 
   1506      1.1.1.4  christos int wpas_ap_wps_nfc_report_handover(struct wpa_supplicant *wpa_s,
   1507      1.1.1.4  christos 				    const struct wpabuf *req,
   1508      1.1.1.4  christos 				    const struct wpabuf *sel)
   1509      1.1.1.4  christos {
   1510      1.1.1.4  christos 	struct hostapd_data *hapd;
   1511      1.1.1.4  christos 
   1512      1.1.1.4  christos 	if (wpa_s->ap_iface == NULL)
   1513      1.1.1.4  christos 		return -1;
   1514      1.1.1.4  christos 	hapd = wpa_s->ap_iface->bss[0];
   1515      1.1.1.4  christos 	return hostapd_wps_nfc_report_handover(hapd, req, sel);
   1516      1.1.1.4  christos }
   1517      1.1.1.4  christos 
   1518      1.1.1.4  christos #endif /* CONFIG_WPS_NFC */
   1519      1.1.1.4  christos 
   1520          1.1  christos #endif /* CONFIG_WPS */
   1521          1.1  christos 
   1522          1.1  christos 
   1523          1.1  christos #ifdef CONFIG_CTRL_IFACE
   1524          1.1  christos 
   1525          1.1  christos int ap_ctrl_iface_sta_first(struct wpa_supplicant *wpa_s,
   1526          1.1  christos 			    char *buf, size_t buflen)
   1527          1.1  christos {
   1528      1.1.1.5  christos 	struct hostapd_data *hapd;
   1529      1.1.1.5  christos 
   1530      1.1.1.5  christos 	if (wpa_s->ap_iface)
   1531      1.1.1.5  christos 		hapd = wpa_s->ap_iface->bss[0];
   1532      1.1.1.5  christos 	else if (wpa_s->ifmsh)
   1533      1.1.1.5  christos 		hapd = wpa_s->ifmsh->bss[0];
   1534      1.1.1.5  christos 	else
   1535          1.1  christos 		return -1;
   1536      1.1.1.5  christos 	return hostapd_ctrl_iface_sta_first(hapd, buf, buflen);
   1537          1.1  christos }
   1538          1.1  christos 
   1539          1.1  christos 
   1540          1.1  christos int ap_ctrl_iface_sta(struct wpa_supplicant *wpa_s, const char *txtaddr,
   1541          1.1  christos 		      char *buf, size_t buflen)
   1542          1.1  christos {
   1543      1.1.1.5  christos 	struct hostapd_data *hapd;
   1544      1.1.1.5  christos 
   1545      1.1.1.5  christos 	if (wpa_s->ap_iface)
   1546      1.1.1.5  christos 		hapd = wpa_s->ap_iface->bss[0];
   1547      1.1.1.5  christos 	else if (wpa_s->ifmsh)
   1548      1.1.1.5  christos 		hapd = wpa_s->ifmsh->bss[0];
   1549      1.1.1.5  christos 	else
   1550          1.1  christos 		return -1;
   1551      1.1.1.5  christos 	return hostapd_ctrl_iface_sta(hapd, txtaddr, buf, buflen);
   1552          1.1  christos }
   1553          1.1  christos 
   1554          1.1  christos 
   1555          1.1  christos int ap_ctrl_iface_sta_next(struct wpa_supplicant *wpa_s, const char *txtaddr,
   1556          1.1  christos 			   char *buf, size_t buflen)
   1557          1.1  christos {
   1558      1.1.1.5  christos 	struct hostapd_data *hapd;
   1559      1.1.1.5  christos 
   1560      1.1.1.5  christos 	if (wpa_s->ap_iface)
   1561      1.1.1.5  christos 		hapd = wpa_s->ap_iface->bss[0];
   1562      1.1.1.5  christos 	else if (wpa_s->ifmsh)
   1563      1.1.1.5  christos 		hapd = wpa_s->ifmsh->bss[0];
   1564      1.1.1.5  christos 	else
   1565          1.1  christos 		return -1;
   1566      1.1.1.5  christos 	return hostapd_ctrl_iface_sta_next(hapd, txtaddr, buf, buflen);
   1567          1.1  christos }
   1568          1.1  christos 
   1569          1.1  christos 
   1570      1.1.1.3  christos int ap_ctrl_iface_sta_disassociate(struct wpa_supplicant *wpa_s,
   1571      1.1.1.3  christos 				   const char *txtaddr)
   1572      1.1.1.3  christos {
   1573      1.1.1.3  christos 	if (wpa_s->ap_iface == NULL)
   1574      1.1.1.3  christos 		return -1;
   1575      1.1.1.3  christos 	return hostapd_ctrl_iface_disassociate(wpa_s->ap_iface->bss[0],
   1576      1.1.1.3  christos 					       txtaddr);
   1577      1.1.1.3  christos }
   1578      1.1.1.3  christos 
   1579      1.1.1.3  christos 
   1580      1.1.1.3  christos int ap_ctrl_iface_sta_deauthenticate(struct wpa_supplicant *wpa_s,
   1581      1.1.1.3  christos 				     const char *txtaddr)
   1582      1.1.1.3  christos {
   1583      1.1.1.3  christos 	if (wpa_s->ap_iface == NULL)
   1584      1.1.1.3  christos 		return -1;
   1585      1.1.1.3  christos 	return hostapd_ctrl_iface_deauthenticate(wpa_s->ap_iface->bss[0],
   1586      1.1.1.3  christos 						 txtaddr);
   1587      1.1.1.3  christos }
   1588      1.1.1.3  christos 
   1589      1.1.1.3  christos 
   1590          1.1  christos int ap_ctrl_iface_wpa_get_status(struct wpa_supplicant *wpa_s, char *buf,
   1591          1.1  christos 				 size_t buflen, int verbose)
   1592          1.1  christos {
   1593          1.1  christos 	char *pos = buf, *end = buf + buflen;
   1594          1.1  christos 	int ret;
   1595          1.1  christos 	struct hostapd_bss_config *conf;
   1596          1.1  christos 
   1597          1.1  christos 	if (wpa_s->ap_iface == NULL)
   1598          1.1  christos 		return -1;
   1599          1.1  christos 
   1600          1.1  christos 	conf = wpa_s->ap_iface->bss[0]->conf;
   1601          1.1  christos 	if (conf->wpa == 0)
   1602          1.1  christos 		return 0;
   1603          1.1  christos 
   1604          1.1  christos 	ret = os_snprintf(pos, end - pos,
   1605          1.1  christos 			  "pairwise_cipher=%s\n"
   1606          1.1  christos 			  "group_cipher=%s\n"
   1607          1.1  christos 			  "key_mgmt=%s\n",
   1608          1.1  christos 			  wpa_cipher_txt(conf->rsn_pairwise),
   1609          1.1  christos 			  wpa_cipher_txt(conf->wpa_group),
   1610          1.1  christos 			  wpa_key_mgmt_txt(conf->wpa_key_mgmt,
   1611          1.1  christos 					   conf->wpa));
   1612      1.1.1.5  christos 	if (os_snprintf_error(end - pos, ret))
   1613          1.1  christos 		return pos - buf;
   1614          1.1  christos 	pos += ret;
   1615          1.1  christos 	return pos - buf;
   1616          1.1  christos }
   1617          1.1  christos 
   1618  1.1.1.8.8.1  perseant 
   1619  1.1.1.8.8.1  perseant #ifdef CONFIG_WNM_AP
   1620  1.1.1.8.8.1  perseant 
   1621  1.1.1.8.8.1  perseant int ap_ctrl_iface_disassoc_imminent(struct wpa_supplicant *wpa_s,
   1622  1.1.1.8.8.1  perseant 				    const char *buf)
   1623  1.1.1.8.8.1  perseant {
   1624  1.1.1.8.8.1  perseant 	struct hostapd_data *hapd;
   1625  1.1.1.8.8.1  perseant 
   1626  1.1.1.8.8.1  perseant 	if (wpa_s->ap_iface)
   1627  1.1.1.8.8.1  perseant 		hapd = wpa_s->ap_iface->bss[0];
   1628  1.1.1.8.8.1  perseant 	else
   1629  1.1.1.8.8.1  perseant 		return -1;
   1630  1.1.1.8.8.1  perseant 	return hostapd_ctrl_iface_disassoc_imminent(hapd, buf);
   1631  1.1.1.8.8.1  perseant }
   1632  1.1.1.8.8.1  perseant 
   1633  1.1.1.8.8.1  perseant 
   1634  1.1.1.8.8.1  perseant int ap_ctrl_iface_ess_disassoc(struct wpa_supplicant *wpa_s, const char *buf)
   1635  1.1.1.8.8.1  perseant {
   1636  1.1.1.8.8.1  perseant 	struct hostapd_data *hapd;
   1637  1.1.1.8.8.1  perseant 
   1638  1.1.1.8.8.1  perseant 	if (wpa_s->ap_iface)
   1639  1.1.1.8.8.1  perseant 		hapd = wpa_s->ap_iface->bss[0];
   1640  1.1.1.8.8.1  perseant 	else
   1641  1.1.1.8.8.1  perseant 		return -1;
   1642  1.1.1.8.8.1  perseant 	return hostapd_ctrl_iface_ess_disassoc(hapd, buf);
   1643  1.1.1.8.8.1  perseant }
   1644  1.1.1.8.8.1  perseant 
   1645  1.1.1.8.8.1  perseant 
   1646  1.1.1.8.8.1  perseant int ap_ctrl_iface_bss_tm_req(struct wpa_supplicant *wpa_s, const char *buf)
   1647  1.1.1.8.8.1  perseant {
   1648  1.1.1.8.8.1  perseant 	struct hostapd_data *hapd;
   1649  1.1.1.8.8.1  perseant 
   1650  1.1.1.8.8.1  perseant 	if (wpa_s->ap_iface)
   1651  1.1.1.8.8.1  perseant 		hapd = wpa_s->ap_iface->bss[0];
   1652  1.1.1.8.8.1  perseant 	else
   1653  1.1.1.8.8.1  perseant 		return -1;
   1654  1.1.1.8.8.1  perseant 	return hostapd_ctrl_iface_bss_tm_req(hapd, buf);
   1655  1.1.1.8.8.1  perseant }
   1656  1.1.1.8.8.1  perseant 
   1657  1.1.1.8.8.1  perseant #endif /* CONFIG_WNM_AP */
   1658  1.1.1.8.8.1  perseant 
   1659  1.1.1.8.8.1  perseant 
   1660  1.1.1.8.8.1  perseant int ap_ctrl_iface_acl_add_mac(struct wpa_supplicant *wpa_s,
   1661  1.1.1.8.8.1  perseant 			      enum macaddr_acl acl_type,
   1662  1.1.1.8.8.1  perseant 			      const char *buf)
   1663  1.1.1.8.8.1  perseant {
   1664  1.1.1.8.8.1  perseant 	struct hostapd_data *hapd;
   1665  1.1.1.8.8.1  perseant 
   1666  1.1.1.8.8.1  perseant 	if (wpa_s->ap_iface)
   1667  1.1.1.8.8.1  perseant 		hapd = wpa_s->ap_iface->bss[0];
   1668  1.1.1.8.8.1  perseant 	else
   1669  1.1.1.8.8.1  perseant 		return -1;
   1670  1.1.1.8.8.1  perseant 
   1671  1.1.1.8.8.1  perseant 	hapd->conf->macaddr_acl = acl_type;
   1672  1.1.1.8.8.1  perseant 
   1673  1.1.1.8.8.1  perseant 	if (acl_type == ACCEPT_UNLESS_DENIED)
   1674  1.1.1.8.8.1  perseant 		return hostapd_ctrl_iface_acl_add_mac(&hapd->conf->deny_mac,
   1675  1.1.1.8.8.1  perseant 						      &hapd->conf->num_deny_mac,
   1676  1.1.1.8.8.1  perseant 						      buf);
   1677  1.1.1.8.8.1  perseant 	if (acl_type == DENY_UNLESS_ACCEPTED)
   1678  1.1.1.8.8.1  perseant 		return hostapd_ctrl_iface_acl_add_mac(
   1679  1.1.1.8.8.1  perseant 			&hapd->conf->accept_mac,
   1680  1.1.1.8.8.1  perseant 			&hapd->conf->num_accept_mac, buf);
   1681  1.1.1.8.8.1  perseant 
   1682  1.1.1.8.8.1  perseant 	return -1;
   1683  1.1.1.8.8.1  perseant }
   1684  1.1.1.8.8.1  perseant 
   1685  1.1.1.8.8.1  perseant 
   1686  1.1.1.8.8.1  perseant int ap_ctrl_iface_acl_del_mac(struct wpa_supplicant *wpa_s,
   1687  1.1.1.8.8.1  perseant 			      enum macaddr_acl acl_type,
   1688  1.1.1.8.8.1  perseant 			      const char *buf)
   1689  1.1.1.8.8.1  perseant {
   1690  1.1.1.8.8.1  perseant 	struct hostapd_data *hapd;
   1691  1.1.1.8.8.1  perseant 
   1692  1.1.1.8.8.1  perseant 	if (wpa_s->ap_iface)
   1693  1.1.1.8.8.1  perseant 		hapd = wpa_s->ap_iface->bss[0];
   1694  1.1.1.8.8.1  perseant 	else
   1695  1.1.1.8.8.1  perseant 		return -1;
   1696  1.1.1.8.8.1  perseant 
   1697  1.1.1.8.8.1  perseant 	hapd->conf->macaddr_acl = acl_type;
   1698  1.1.1.8.8.1  perseant 
   1699  1.1.1.8.8.1  perseant 	if (acl_type == ACCEPT_UNLESS_DENIED)
   1700  1.1.1.8.8.1  perseant 		return hostapd_ctrl_iface_acl_del_mac(&hapd->conf->deny_mac,
   1701  1.1.1.8.8.1  perseant 						      &hapd->conf->num_deny_mac,
   1702  1.1.1.8.8.1  perseant 						      buf);
   1703  1.1.1.8.8.1  perseant 	if (acl_type == DENY_UNLESS_ACCEPTED)
   1704  1.1.1.8.8.1  perseant 		return hostapd_ctrl_iface_acl_del_mac(
   1705  1.1.1.8.8.1  perseant 			&hapd->conf->accept_mac, &hapd->conf->num_accept_mac,
   1706  1.1.1.8.8.1  perseant 			buf);
   1707  1.1.1.8.8.1  perseant 
   1708  1.1.1.8.8.1  perseant 	return -1;
   1709  1.1.1.8.8.1  perseant }
   1710  1.1.1.8.8.1  perseant 
   1711  1.1.1.8.8.1  perseant 
   1712  1.1.1.8.8.1  perseant int ap_ctrl_iface_acl_show_mac(struct wpa_supplicant *wpa_s,
   1713  1.1.1.8.8.1  perseant 			       enum macaddr_acl acl_type, char *buf,
   1714  1.1.1.8.8.1  perseant 			       size_t buflen)
   1715  1.1.1.8.8.1  perseant {
   1716  1.1.1.8.8.1  perseant 	struct hostapd_data *hapd;
   1717  1.1.1.8.8.1  perseant 
   1718  1.1.1.8.8.1  perseant 	if (wpa_s->ap_iface)
   1719  1.1.1.8.8.1  perseant 		hapd = wpa_s->ap_iface->bss[0];
   1720  1.1.1.8.8.1  perseant 	else
   1721  1.1.1.8.8.1  perseant 		return -1;
   1722  1.1.1.8.8.1  perseant 
   1723  1.1.1.8.8.1  perseant 	if (acl_type == ACCEPT_UNLESS_DENIED)
   1724  1.1.1.8.8.1  perseant 		return hostapd_ctrl_iface_acl_show_mac(hapd->conf->deny_mac,
   1725  1.1.1.8.8.1  perseant 						       hapd->conf->num_deny_mac,
   1726  1.1.1.8.8.1  perseant 						       buf, buflen);
   1727  1.1.1.8.8.1  perseant 	if (acl_type == DENY_UNLESS_ACCEPTED)
   1728  1.1.1.8.8.1  perseant 		return hostapd_ctrl_iface_acl_show_mac(
   1729  1.1.1.8.8.1  perseant 			hapd->conf->accept_mac,	hapd->conf->num_accept_mac,
   1730  1.1.1.8.8.1  perseant 			buf, buflen);
   1731  1.1.1.8.8.1  perseant 
   1732  1.1.1.8.8.1  perseant 	return -1;
   1733  1.1.1.8.8.1  perseant }
   1734  1.1.1.8.8.1  perseant 
   1735  1.1.1.8.8.1  perseant 
   1736  1.1.1.8.8.1  perseant void ap_ctrl_iface_acl_clear_list(struct wpa_supplicant *wpa_s,
   1737  1.1.1.8.8.1  perseant 				  enum macaddr_acl acl_type)
   1738  1.1.1.8.8.1  perseant {
   1739  1.1.1.8.8.1  perseant 	struct hostapd_data *hapd;
   1740  1.1.1.8.8.1  perseant 
   1741  1.1.1.8.8.1  perseant 	if (wpa_s->ap_iface)
   1742  1.1.1.8.8.1  perseant 		hapd = wpa_s->ap_iface->bss[0];
   1743  1.1.1.8.8.1  perseant 	else
   1744  1.1.1.8.8.1  perseant 		return;
   1745  1.1.1.8.8.1  perseant 
   1746  1.1.1.8.8.1  perseant 	hapd->conf->macaddr_acl = acl_type;
   1747  1.1.1.8.8.1  perseant 
   1748  1.1.1.8.8.1  perseant 	if (acl_type == ACCEPT_UNLESS_DENIED)
   1749  1.1.1.8.8.1  perseant 		hostapd_ctrl_iface_acl_clear_list(&hapd->conf->deny_mac,
   1750  1.1.1.8.8.1  perseant 						  &hapd->conf->num_deny_mac);
   1751  1.1.1.8.8.1  perseant 	else if (acl_type == DENY_UNLESS_ACCEPTED)
   1752  1.1.1.8.8.1  perseant 		hostapd_ctrl_iface_acl_clear_list(&hapd->conf->accept_mac,
   1753  1.1.1.8.8.1  perseant 						  &hapd->conf->num_accept_mac);
   1754  1.1.1.8.8.1  perseant }
   1755  1.1.1.8.8.1  perseant 
   1756  1.1.1.8.8.1  perseant 
   1757  1.1.1.8.8.1  perseant int ap_ctrl_iface_disassoc_deny_mac(struct wpa_supplicant *wpa_s)
   1758  1.1.1.8.8.1  perseant {
   1759  1.1.1.8.8.1  perseant 	struct hostapd_data *hapd;
   1760  1.1.1.8.8.1  perseant 
   1761  1.1.1.8.8.1  perseant 	if (wpa_s->ap_iface)
   1762  1.1.1.8.8.1  perseant 		hapd = wpa_s->ap_iface->bss[0];
   1763  1.1.1.8.8.1  perseant 	else
   1764  1.1.1.8.8.1  perseant 		return -1;
   1765  1.1.1.8.8.1  perseant 
   1766  1.1.1.8.8.1  perseant 	return hostapd_disassoc_deny_mac(hapd);
   1767  1.1.1.8.8.1  perseant }
   1768  1.1.1.8.8.1  perseant 
   1769  1.1.1.8.8.1  perseant 
   1770  1.1.1.8.8.1  perseant int ap_ctrl_iface_disassoc_accept_mac(struct wpa_supplicant *wpa_s)
   1771  1.1.1.8.8.1  perseant {
   1772  1.1.1.8.8.1  perseant 	struct hostapd_data *hapd;
   1773  1.1.1.8.8.1  perseant 
   1774  1.1.1.8.8.1  perseant 	if (wpa_s->ap_iface)
   1775  1.1.1.8.8.1  perseant 		hapd = wpa_s->ap_iface->bss[0];
   1776  1.1.1.8.8.1  perseant 	else
   1777  1.1.1.8.8.1  perseant 		return -1;
   1778  1.1.1.8.8.1  perseant 
   1779  1.1.1.8.8.1  perseant 	return hostapd_disassoc_accept_mac(hapd);
   1780  1.1.1.8.8.1  perseant }
   1781  1.1.1.8.8.1  perseant 
   1782  1.1.1.8.8.1  perseant 
   1783  1.1.1.8.8.1  perseant int ap_ctrl_iface_set_acl(struct wpa_supplicant *wpa_s)
   1784  1.1.1.8.8.1  perseant {
   1785  1.1.1.8.8.1  perseant 	struct hostapd_data *hapd;
   1786  1.1.1.8.8.1  perseant 
   1787  1.1.1.8.8.1  perseant 	if (wpa_s->ap_iface)
   1788  1.1.1.8.8.1  perseant 		hapd = wpa_s->ap_iface->bss[0];
   1789  1.1.1.8.8.1  perseant 	else
   1790  1.1.1.8.8.1  perseant 		return -1;
   1791  1.1.1.8.8.1  perseant 
   1792  1.1.1.8.8.1  perseant 	return hostapd_set_acl(hapd);
   1793  1.1.1.8.8.1  perseant }
   1794  1.1.1.8.8.1  perseant 
   1795          1.1  christos #endif /* CONFIG_CTRL_IFACE */
   1796          1.1  christos 
   1797          1.1  christos 
   1798      1.1.1.2  christos int wpa_supplicant_ap_update_beacon(struct wpa_supplicant *wpa_s)
   1799      1.1.1.2  christos {
   1800      1.1.1.2  christos 	struct hostapd_iface *iface = wpa_s->ap_iface;
   1801      1.1.1.2  christos 	struct wpa_ssid *ssid = wpa_s->current_ssid;
   1802      1.1.1.2  christos 	struct hostapd_data *hapd;
   1803      1.1.1.2  christos 
   1804      1.1.1.2  christos 	if (ssid == NULL || wpa_s->ap_iface == NULL ||
   1805      1.1.1.2  christos 	    ssid->mode == WPAS_MODE_INFRA ||
   1806      1.1.1.2  christos 	    ssid->mode == WPAS_MODE_IBSS)
   1807      1.1.1.2  christos 		return -1;
   1808      1.1.1.2  christos 
   1809      1.1.1.2  christos #ifdef CONFIG_P2P
   1810      1.1.1.2  christos 	if (ssid->mode == WPAS_MODE_P2P_GO)
   1811      1.1.1.4  christos 		iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER;
   1812      1.1.1.2  christos 	else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
   1813      1.1.1.4  christos 		iface->conf->bss[0]->p2p = P2P_ENABLED | P2P_GROUP_OWNER |
   1814      1.1.1.2  christos 			P2P_GROUP_FORMATION;
   1815      1.1.1.2  christos #endif /* CONFIG_P2P */
   1816      1.1.1.2  christos 
   1817      1.1.1.2  christos 	hapd = iface->bss[0];
   1818      1.1.1.2  christos 	if (hapd->drv_priv == NULL)
   1819      1.1.1.2  christos 		return -1;
   1820      1.1.1.2  christos 	ieee802_11_set_beacons(iface);
   1821      1.1.1.2  christos 	hostapd_set_ap_wps_ie(hapd);
   1822      1.1.1.2  christos 
   1823      1.1.1.2  christos 	return 0;
   1824      1.1.1.2  christos }
   1825      1.1.1.2  christos 
   1826      1.1.1.2  christos 
   1827      1.1.1.4  christos int ap_switch_channel(struct wpa_supplicant *wpa_s,
   1828      1.1.1.4  christos 		      struct csa_settings *settings)
   1829      1.1.1.4  christos {
   1830      1.1.1.4  christos #ifdef NEED_AP_MLME
   1831  1.1.1.8.8.1  perseant 	struct hostapd_iface *iface = NULL;
   1832  1.1.1.8.8.1  perseant 
   1833  1.1.1.8.8.1  perseant 	if (wpa_s->ap_iface)
   1834  1.1.1.8.8.1  perseant 		iface = wpa_s->ap_iface;
   1835  1.1.1.8.8.1  perseant 	else if (wpa_s->ifmsh)
   1836  1.1.1.8.8.1  perseant 		iface = wpa_s->ifmsh;
   1837  1.1.1.8.8.1  perseant 
   1838  1.1.1.8.8.1  perseant 	if (!iface || !iface->bss[0])
   1839      1.1.1.4  christos 		return -1;
   1840      1.1.1.4  christos 
   1841  1.1.1.8.8.1  perseant 	return hostapd_switch_channel(iface->bss[0], settings);
   1842      1.1.1.4  christos #else /* NEED_AP_MLME */
   1843      1.1.1.4  christos 	return -1;
   1844      1.1.1.4  christos #endif /* NEED_AP_MLME */
   1845      1.1.1.4  christos }
   1846      1.1.1.4  christos 
   1847      1.1.1.4  christos 
   1848      1.1.1.6  christos #ifdef CONFIG_CTRL_IFACE
   1849      1.1.1.4  christos int ap_ctrl_iface_chanswitch(struct wpa_supplicant *wpa_s, const char *pos)
   1850      1.1.1.4  christos {
   1851      1.1.1.4  christos 	struct csa_settings settings;
   1852      1.1.1.4  christos 	int ret = hostapd_parse_csa_settings(pos, &settings);
   1853      1.1.1.4  christos 
   1854      1.1.1.4  christos 	if (ret)
   1855      1.1.1.4  christos 		return ret;
   1856      1.1.1.4  christos 
   1857  1.1.1.8.8.1  perseant 	settings.link_id = -1;
   1858  1.1.1.8.8.1  perseant 
   1859      1.1.1.4  christos 	return ap_switch_channel(wpa_s, &settings);
   1860      1.1.1.4  christos }
   1861      1.1.1.6  christos #endif /* CONFIG_CTRL_IFACE */
   1862      1.1.1.4  christos 
   1863      1.1.1.4  christos 
   1864      1.1.1.3  christos void wpas_ap_ch_switch(struct wpa_supplicant *wpa_s, int freq, int ht,
   1865  1.1.1.8.8.1  perseant 		       int offset, int width, int cf1, int cf2,
   1866  1.1.1.8.8.1  perseant 		       u16 punct_bitmap, int finished)
   1867      1.1.1.3  christos {
   1868      1.1.1.8  christos 	struct hostapd_iface *iface = wpa_s->ap_iface;
   1869      1.1.1.3  christos 
   1870      1.1.1.8  christos 	if (!iface)
   1871      1.1.1.8  christos 		iface = wpa_s->ifmsh;
   1872      1.1.1.8  christos 	if (!iface)
   1873      1.1.1.8  christos 		return;
   1874      1.1.1.3  christos 	wpa_s->assoc_freq = freq;
   1875      1.1.1.6  christos 	if (wpa_s->current_ssid)
   1876      1.1.1.6  christos 		wpa_s->current_ssid->frequency = freq;
   1877      1.1.1.8  christos 	hostapd_event_ch_switch(iface->bss[0], freq, ht,
   1878  1.1.1.8.8.1  perseant 				offset, width, cf1, cf2, punct_bitmap,
   1879  1.1.1.8.8.1  perseant 				finished);
   1880      1.1.1.3  christos }
   1881      1.1.1.3  christos 
   1882      1.1.1.3  christos 
   1883          1.1  christos int wpa_supplicant_ap_mac_addr_filter(struct wpa_supplicant *wpa_s,
   1884          1.1  christos 				      const u8 *addr)
   1885          1.1  christos {
   1886          1.1  christos 	struct hostapd_data *hapd;
   1887          1.1  christos 	struct hostapd_bss_config *conf;
   1888          1.1  christos 
   1889          1.1  christos 	if (!wpa_s->ap_iface)
   1890          1.1  christos 		return -1;
   1891          1.1  christos 
   1892          1.1  christos 	if (addr)
   1893          1.1  christos 		wpa_printf(MSG_DEBUG, "AP: Set MAC address filter: " MACSTR,
   1894          1.1  christos 			   MAC2STR(addr));
   1895          1.1  christos 	else
   1896          1.1  christos 		wpa_printf(MSG_DEBUG, "AP: Clear MAC address filter");
   1897          1.1  christos 
   1898          1.1  christos 	hapd = wpa_s->ap_iface->bss[0];
   1899          1.1  christos 	conf = hapd->conf;
   1900          1.1  christos 
   1901          1.1  christos 	os_free(conf->accept_mac);
   1902          1.1  christos 	conf->accept_mac = NULL;
   1903          1.1  christos 	conf->num_accept_mac = 0;
   1904          1.1  christos 	os_free(conf->deny_mac);
   1905          1.1  christos 	conf->deny_mac = NULL;
   1906          1.1  christos 	conf->num_deny_mac = 0;
   1907          1.1  christos 
   1908          1.1  christos 	if (addr == NULL) {
   1909          1.1  christos 		conf->macaddr_acl = ACCEPT_UNLESS_DENIED;
   1910          1.1  christos 		return 0;
   1911          1.1  christos 	}
   1912          1.1  christos 
   1913          1.1  christos 	conf->macaddr_acl = DENY_UNLESS_ACCEPTED;
   1914          1.1  christos 	conf->accept_mac = os_zalloc(sizeof(struct mac_acl_entry));
   1915          1.1  christos 	if (conf->accept_mac == NULL)
   1916          1.1  christos 		return -1;
   1917          1.1  christos 	os_memcpy(conf->accept_mac[0].addr, addr, ETH_ALEN);
   1918          1.1  christos 	conf->num_accept_mac = 1;
   1919          1.1  christos 
   1920          1.1  christos 	return 0;
   1921          1.1  christos }
   1922      1.1.1.4  christos 
   1923      1.1.1.4  christos 
   1924      1.1.1.4  christos #ifdef CONFIG_WPS_NFC
   1925      1.1.1.4  christos int wpas_ap_wps_add_nfc_pw(struct wpa_supplicant *wpa_s, u16 pw_id,
   1926      1.1.1.4  christos 			   const struct wpabuf *pw, const u8 *pubkey_hash)
   1927      1.1.1.4  christos {
   1928      1.1.1.4  christos 	struct hostapd_data *hapd;
   1929      1.1.1.4  christos 	struct wps_context *wps;
   1930      1.1.1.4  christos 
   1931      1.1.1.4  christos 	if (!wpa_s->ap_iface)
   1932      1.1.1.4  christos 		return -1;
   1933      1.1.1.4  christos 	hapd = wpa_s->ap_iface->bss[0];
   1934      1.1.1.4  christos 	wps = hapd->wps;
   1935      1.1.1.4  christos 
   1936      1.1.1.6  christos 	if (wpa_s->p2pdev->conf->wps_nfc_dh_pubkey == NULL ||
   1937      1.1.1.6  christos 	    wpa_s->p2pdev->conf->wps_nfc_dh_privkey == NULL) {
   1938      1.1.1.4  christos 		wpa_printf(MSG_DEBUG, "P2P: No NFC DH key known");
   1939      1.1.1.4  christos 		return -1;
   1940      1.1.1.4  christos 	}
   1941      1.1.1.4  christos 
   1942      1.1.1.4  christos 	dh5_free(wps->dh_ctx);
   1943      1.1.1.4  christos 	wpabuf_free(wps->dh_pubkey);
   1944      1.1.1.4  christos 	wpabuf_free(wps->dh_privkey);
   1945      1.1.1.4  christos 	wps->dh_privkey = wpabuf_dup(
   1946      1.1.1.6  christos 		wpa_s->p2pdev->conf->wps_nfc_dh_privkey);
   1947      1.1.1.4  christos 	wps->dh_pubkey = wpabuf_dup(
   1948      1.1.1.6  christos 		wpa_s->p2pdev->conf->wps_nfc_dh_pubkey);
   1949      1.1.1.4  christos 	if (wps->dh_privkey == NULL || wps->dh_pubkey == NULL) {
   1950      1.1.1.4  christos 		wps->dh_ctx = NULL;
   1951      1.1.1.4  christos 		wpabuf_free(wps->dh_pubkey);
   1952      1.1.1.4  christos 		wps->dh_pubkey = NULL;
   1953      1.1.1.4  christos 		wpabuf_free(wps->dh_privkey);
   1954      1.1.1.4  christos 		wps->dh_privkey = NULL;
   1955      1.1.1.4  christos 		return -1;
   1956      1.1.1.4  christos 	}
   1957      1.1.1.4  christos 	wps->dh_ctx = dh5_init_fixed(wps->dh_privkey, wps->dh_pubkey);
   1958      1.1.1.4  christos 	if (wps->dh_ctx == NULL)
   1959      1.1.1.4  christos 		return -1;
   1960      1.1.1.4  christos 
   1961      1.1.1.4  christos 	return wps_registrar_add_nfc_pw_token(hapd->wps->registrar, pubkey_hash,
   1962      1.1.1.4  christos 					      pw_id,
   1963      1.1.1.4  christos 					      pw ? wpabuf_head(pw) : NULL,
   1964      1.1.1.4  christos 					      pw ? wpabuf_len(pw) : 0, 1);
   1965      1.1.1.4  christos }
   1966      1.1.1.4  christos #endif /* CONFIG_WPS_NFC */
   1967      1.1.1.5  christos 
   1968      1.1.1.5  christos 
   1969      1.1.1.6  christos #ifdef CONFIG_CTRL_IFACE
   1970      1.1.1.5  christos int wpas_ap_stop_ap(struct wpa_supplicant *wpa_s)
   1971      1.1.1.5  christos {
   1972      1.1.1.5  christos 	struct hostapd_data *hapd;
   1973      1.1.1.5  christos 
   1974      1.1.1.5  christos 	if (!wpa_s->ap_iface)
   1975      1.1.1.5  christos 		return -1;
   1976      1.1.1.5  christos 	hapd = wpa_s->ap_iface->bss[0];
   1977      1.1.1.5  christos 	return hostapd_ctrl_iface_stop_ap(hapd);
   1978      1.1.1.5  christos }
   1979      1.1.1.5  christos 
   1980      1.1.1.5  christos 
   1981      1.1.1.6  christos int wpas_ap_pmksa_cache_list(struct wpa_supplicant *wpa_s, char *buf,
   1982      1.1.1.6  christos 			     size_t len)
   1983      1.1.1.6  christos {
   1984      1.1.1.6  christos 	size_t reply_len = 0, i;
   1985      1.1.1.6  christos 	char ap_delimiter[] = "---- AP ----\n";
   1986      1.1.1.6  christos 	char mesh_delimiter[] = "---- mesh ----\n";
   1987      1.1.1.6  christos 	size_t dlen;
   1988      1.1.1.6  christos 
   1989      1.1.1.6  christos 	if (wpa_s->ap_iface) {
   1990      1.1.1.6  christos 		dlen = os_strlen(ap_delimiter);
   1991      1.1.1.6  christos 		if (dlen > len - reply_len)
   1992      1.1.1.6  christos 			return reply_len;
   1993      1.1.1.6  christos 		os_memcpy(&buf[reply_len], ap_delimiter, dlen);
   1994      1.1.1.6  christos 		reply_len += dlen;
   1995      1.1.1.6  christos 
   1996      1.1.1.6  christos 		for (i = 0; i < wpa_s->ap_iface->num_bss; i++) {
   1997      1.1.1.6  christos 			reply_len += hostapd_ctrl_iface_pmksa_list(
   1998      1.1.1.6  christos 				wpa_s->ap_iface->bss[i],
   1999      1.1.1.6  christos 				&buf[reply_len], len - reply_len);
   2000      1.1.1.6  christos 		}
   2001      1.1.1.6  christos 	}
   2002      1.1.1.6  christos 
   2003      1.1.1.6  christos 	if (wpa_s->ifmsh) {
   2004      1.1.1.6  christos 		dlen = os_strlen(mesh_delimiter);
   2005      1.1.1.6  christos 		if (dlen > len - reply_len)
   2006      1.1.1.6  christos 			return reply_len;
   2007      1.1.1.6  christos 		os_memcpy(&buf[reply_len], mesh_delimiter, dlen);
   2008      1.1.1.6  christos 		reply_len += dlen;
   2009      1.1.1.6  christos 
   2010      1.1.1.6  christos 		reply_len += hostapd_ctrl_iface_pmksa_list(
   2011      1.1.1.6  christos 			wpa_s->ifmsh->bss[0], &buf[reply_len],
   2012      1.1.1.6  christos 			len - reply_len);
   2013      1.1.1.6  christos 	}
   2014      1.1.1.6  christos 
   2015      1.1.1.6  christos 	return reply_len;
   2016      1.1.1.6  christos }
   2017      1.1.1.6  christos 
   2018      1.1.1.6  christos 
   2019      1.1.1.6  christos void wpas_ap_pmksa_cache_flush(struct wpa_supplicant *wpa_s)
   2020      1.1.1.6  christos {
   2021      1.1.1.6  christos 	size_t i;
   2022      1.1.1.6  christos 
   2023      1.1.1.6  christos 	if (wpa_s->ap_iface) {
   2024      1.1.1.6  christos 		for (i = 0; i < wpa_s->ap_iface->num_bss; i++)
   2025      1.1.1.6  christos 			hostapd_ctrl_iface_pmksa_flush(wpa_s->ap_iface->bss[i]);
   2026      1.1.1.6  christos 	}
   2027      1.1.1.6  christos 
   2028      1.1.1.6  christos 	if (wpa_s->ifmsh)
   2029      1.1.1.6  christos 		hostapd_ctrl_iface_pmksa_flush(wpa_s->ifmsh->bss[0]);
   2030      1.1.1.6  christos }
   2031      1.1.1.7  christos 
   2032      1.1.1.7  christos 
   2033      1.1.1.7  christos #ifdef CONFIG_PMKSA_CACHE_EXTERNAL
   2034      1.1.1.7  christos #ifdef CONFIG_MESH
   2035      1.1.1.7  christos 
   2036      1.1.1.7  christos int wpas_ap_pmksa_cache_list_mesh(struct wpa_supplicant *wpa_s, const u8 *addr,
   2037      1.1.1.7  christos 				  char *buf, size_t len)
   2038      1.1.1.7  christos {
   2039      1.1.1.7  christos 	return hostapd_ctrl_iface_pmksa_list_mesh(wpa_s->ifmsh->bss[0], addr,
   2040      1.1.1.7  christos 						  &buf[0], len);
   2041      1.1.1.7  christos }
   2042      1.1.1.7  christos 
   2043      1.1.1.7  christos 
   2044      1.1.1.7  christos int wpas_ap_pmksa_cache_add_external(struct wpa_supplicant *wpa_s, char *cmd)
   2045      1.1.1.7  christos {
   2046      1.1.1.7  christos 	struct external_pmksa_cache *entry;
   2047      1.1.1.7  christos 	void *pmksa_cache;
   2048      1.1.1.7  christos 
   2049      1.1.1.7  christos 	pmksa_cache = hostapd_ctrl_iface_pmksa_create_entry(wpa_s->own_addr,
   2050      1.1.1.7  christos 							    cmd);
   2051      1.1.1.7  christos 	if (!pmksa_cache)
   2052      1.1.1.7  christos 		return -1;
   2053      1.1.1.7  christos 
   2054      1.1.1.7  christos 	entry = os_zalloc(sizeof(struct external_pmksa_cache));
   2055      1.1.1.7  christos 	if (!entry)
   2056      1.1.1.7  christos 		return -1;
   2057      1.1.1.7  christos 
   2058      1.1.1.7  christos 	entry->pmksa_cache = pmksa_cache;
   2059      1.1.1.7  christos 
   2060      1.1.1.7  christos 	dl_list_add(&wpa_s->mesh_external_pmksa_cache, &entry->list);
   2061      1.1.1.7  christos 
   2062      1.1.1.7  christos 	return 0;
   2063      1.1.1.7  christos }
   2064      1.1.1.7  christos 
   2065      1.1.1.7  christos #endif /* CONFIG_MESH */
   2066      1.1.1.7  christos #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
   2067      1.1.1.7  christos 
   2068  1.1.1.8.8.1  perseant 
   2069  1.1.1.8.8.1  perseant int wpas_ap_update_beacon(struct wpa_supplicant *wpa_s)
   2070  1.1.1.8.8.1  perseant {
   2071  1.1.1.8.8.1  perseant 	struct hostapd_data *hapd;
   2072  1.1.1.8.8.1  perseant 
   2073  1.1.1.8.8.1  perseant 	if (!wpa_s->ap_iface)
   2074  1.1.1.8.8.1  perseant 		return -1;
   2075  1.1.1.8.8.1  perseant 	hapd = wpa_s->ap_iface->bss[0];
   2076  1.1.1.8.8.1  perseant 
   2077  1.1.1.8.8.1  perseant 	wpabuf_free(hapd->conf->assocresp_elements);
   2078  1.1.1.8.8.1  perseant 	hapd->conf->assocresp_elements = NULL;
   2079  1.1.1.8.8.1  perseant 	if (wpa_s->conf->ap_assocresp_elements) {
   2080  1.1.1.8.8.1  perseant 		hapd->conf->assocresp_elements =
   2081  1.1.1.8.8.1  perseant 			wpabuf_dup(wpa_s->conf->ap_assocresp_elements);
   2082  1.1.1.8.8.1  perseant 	}
   2083  1.1.1.8.8.1  perseant 
   2084  1.1.1.8.8.1  perseant 	wpabuf_free(hapd->conf->vendor_elements);
   2085  1.1.1.8.8.1  perseant 	hapd->conf->vendor_elements = NULL;
   2086  1.1.1.8.8.1  perseant 	if (wpa_s->conf->ap_vendor_elements) {
   2087  1.1.1.8.8.1  perseant 		hapd->conf->vendor_elements =
   2088  1.1.1.8.8.1  perseant 			wpabuf_dup(wpa_s->conf->ap_vendor_elements);
   2089  1.1.1.8.8.1  perseant 	}
   2090  1.1.1.8.8.1  perseant 
   2091  1.1.1.8.8.1  perseant 	return ieee802_11_set_beacon(hapd);
   2092  1.1.1.8.8.1  perseant }
   2093  1.1.1.8.8.1  perseant 
   2094      1.1.1.6  christos #endif /* CONFIG_CTRL_IFACE */
   2095      1.1.1.6  christos 
   2096      1.1.1.6  christos 
   2097      1.1.1.5  christos #ifdef NEED_AP_MLME
   2098      1.1.1.7  christos void wpas_ap_event_dfs_radar_detected(struct wpa_supplicant *wpa_s,
   2099      1.1.1.7  christos 				      struct dfs_event *radar)
   2100      1.1.1.5  christos {
   2101      1.1.1.8  christos 	struct hostapd_iface *iface = wpa_s->ap_iface;
   2102      1.1.1.8  christos 
   2103      1.1.1.8  christos 	if (!iface)
   2104      1.1.1.8  christos 		iface = wpa_s->ifmsh;
   2105      1.1.1.8  christos 	if (!iface || !iface->bss[0])
   2106      1.1.1.5  christos 		return;
   2107      1.1.1.5  christos 	wpa_printf(MSG_DEBUG, "DFS radar detected on %d MHz", radar->freq);
   2108      1.1.1.8  christos 	hostapd_dfs_radar_detected(iface, radar->freq,
   2109      1.1.1.5  christos 				   radar->ht_enabled, radar->chan_offset,
   2110      1.1.1.5  christos 				   radar->chan_width,
   2111      1.1.1.5  christos 				   radar->cf1, radar->cf2);
   2112      1.1.1.5  christos }
   2113      1.1.1.5  christos 
   2114      1.1.1.5  christos 
   2115      1.1.1.7  christos void wpas_ap_event_dfs_cac_started(struct wpa_supplicant *wpa_s,
   2116      1.1.1.7  christos 				   struct dfs_event *radar)
   2117      1.1.1.5  christos {
   2118      1.1.1.8  christos 	struct hostapd_iface *iface = wpa_s->ap_iface;
   2119      1.1.1.8  christos 
   2120      1.1.1.8  christos 	if (!iface)
   2121      1.1.1.8  christos 		iface = wpa_s->ifmsh;
   2122      1.1.1.8  christos 	if (!iface || !iface->bss[0])
   2123      1.1.1.5  christos 		return;
   2124      1.1.1.5  christos 	wpa_printf(MSG_DEBUG, "DFS CAC started on %d MHz", radar->freq);
   2125      1.1.1.8  christos 	hostapd_dfs_start_cac(iface, radar->freq,
   2126      1.1.1.5  christos 			      radar->ht_enabled, radar->chan_offset,
   2127      1.1.1.5  christos 			      radar->chan_width, radar->cf1, radar->cf2);
   2128      1.1.1.5  christos }
   2129      1.1.1.5  christos 
   2130      1.1.1.5  christos 
   2131      1.1.1.7  christos void wpas_ap_event_dfs_cac_finished(struct wpa_supplicant *wpa_s,
   2132      1.1.1.7  christos 				    struct dfs_event *radar)
   2133      1.1.1.5  christos {
   2134      1.1.1.8  christos 	struct hostapd_iface *iface = wpa_s->ap_iface;
   2135      1.1.1.8  christos 
   2136      1.1.1.8  christos 	if (!iface)
   2137      1.1.1.8  christos 		iface = wpa_s->ifmsh;
   2138      1.1.1.8  christos 	if (!iface || !iface->bss[0])
   2139      1.1.1.5  christos 		return;
   2140      1.1.1.5  christos 	wpa_printf(MSG_DEBUG, "DFS CAC finished on %d MHz", radar->freq);
   2141      1.1.1.8  christos 	hostapd_dfs_complete_cac(iface, 1, radar->freq,
   2142      1.1.1.5  christos 				 radar->ht_enabled, radar->chan_offset,
   2143      1.1.1.5  christos 				 radar->chan_width, radar->cf1, radar->cf2);
   2144      1.1.1.5  christos }
   2145      1.1.1.5  christos 
   2146      1.1.1.5  christos 
   2147      1.1.1.7  christos void wpas_ap_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s,
   2148      1.1.1.7  christos 				   struct dfs_event *radar)
   2149      1.1.1.5  christos {
   2150      1.1.1.8  christos 	struct hostapd_iface *iface = wpa_s->ap_iface;
   2151      1.1.1.8  christos 
   2152      1.1.1.8  christos 	if (!iface)
   2153      1.1.1.8  christos 		iface = wpa_s->ifmsh;
   2154      1.1.1.8  christos 	if (!iface || !iface->bss[0])
   2155      1.1.1.5  christos 		return;
   2156      1.1.1.5  christos 	wpa_printf(MSG_DEBUG, "DFS CAC aborted on %d MHz", radar->freq);
   2157      1.1.1.8  christos 	hostapd_dfs_complete_cac(iface, 0, radar->freq,
   2158      1.1.1.5  christos 				 radar->ht_enabled, radar->chan_offset,
   2159      1.1.1.5  christos 				 radar->chan_width, radar->cf1, radar->cf2);
   2160      1.1.1.5  christos }
   2161      1.1.1.5  christos 
   2162      1.1.1.5  christos 
   2163      1.1.1.7  christos void wpas_ap_event_dfs_cac_nop_finished(struct wpa_supplicant *wpa_s,
   2164      1.1.1.7  christos 					struct dfs_event *radar)
   2165      1.1.1.5  christos {
   2166      1.1.1.8  christos 	struct hostapd_iface *iface = wpa_s->ap_iface;
   2167      1.1.1.8  christos 
   2168      1.1.1.8  christos 	if (!iface)
   2169      1.1.1.8  christos 		iface = wpa_s->ifmsh;
   2170      1.1.1.8  christos 	if (!iface || !iface->bss[0])
   2171      1.1.1.5  christos 		return;
   2172      1.1.1.5  christos 	wpa_printf(MSG_DEBUG, "DFS NOP finished on %d MHz", radar->freq);
   2173      1.1.1.8  christos 	hostapd_dfs_nop_finished(iface, radar->freq,
   2174      1.1.1.5  christos 				 radar->ht_enabled, radar->chan_offset,
   2175      1.1.1.5  christos 				 radar->chan_width, radar->cf1, radar->cf2);
   2176      1.1.1.5  christos }
   2177      1.1.1.5  christos #endif /* NEED_AP_MLME */
   2178      1.1.1.6  christos 
   2179      1.1.1.6  christos 
   2180      1.1.1.6  christos void ap_periodic(struct wpa_supplicant *wpa_s)
   2181      1.1.1.6  christos {
   2182      1.1.1.6  christos 	if (wpa_s->ap_iface)
   2183      1.1.1.6  christos 		hostapd_periodic_iface(wpa_s->ap_iface);
   2184      1.1.1.6  christos }
   2185