Home | History | Annotate | Line # | Download | only in wpa_supplicant
ap.c revision 1.1.1.1.6.2
      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.1.6.2      yamt  * This software may be distributed under the terms of the BSD license.
      7  1.1.1.1.6.2      yamt  * 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.1.6.1      yamt #include "utils/eloop.h"
     14  1.1.1.1.6.1      yamt #include "utils/uuid.h"
     15          1.1  christos #include "common/ieee802_11_defs.h"
     16  1.1.1.1.6.1      yamt #include "common/wpa_ctrl.h"
     17          1.1  christos #include "ap/hostapd.h"
     18          1.1  christos #include "ap/ap_config.h"
     19  1.1.1.1.6.1      yamt #include "ap/ap_drv_ops.h"
     20          1.1  christos #ifdef NEED_AP_MLME
     21          1.1  christos #include "ap/ieee802_11.h"
     22          1.1  christos #endif /* NEED_AP_MLME */
     23  1.1.1.1.6.1      yamt #include "ap/beacon.h"
     24          1.1  christos #include "ap/ieee802_1x.h"
     25          1.1  christos #include "ap/wps_hostapd.h"
     26          1.1  christos #include "ap/ctrl_iface_ap.h"
     27          1.1  christos #include "wps/wps.h"
     28  1.1.1.1.6.1      yamt #include "common/ieee802_11_defs.h"
     29          1.1  christos #include "config_ssid.h"
     30          1.1  christos #include "config.h"
     31          1.1  christos #include "wpa_supplicant_i.h"
     32          1.1  christos #include "driver_i.h"
     33  1.1.1.1.6.1      yamt #include "p2p_supplicant.h"
     34          1.1  christos #include "ap.h"
     35  1.1.1.1.6.1      yamt #include "ap/sta_info.h"
     36  1.1.1.1.6.1      yamt #include "notify.h"
     37  1.1.1.1.6.1      yamt 
     38  1.1.1.1.6.1      yamt 
     39  1.1.1.1.6.1      yamt #ifdef CONFIG_WPS
     40  1.1.1.1.6.1      yamt static void wpas_wps_ap_pin_timeout(void *eloop_data, void *user_ctx);
     41  1.1.1.1.6.1      yamt #endif /* CONFIG_WPS */
     42          1.1  christos 
     43          1.1  christos 
     44          1.1  christos static int wpa_supplicant_conf_ap(struct wpa_supplicant *wpa_s,
     45          1.1  christos 				  struct wpa_ssid *ssid,
     46          1.1  christos 				  struct hostapd_config *conf)
     47          1.1  christos {
     48          1.1  christos 	struct hostapd_bss_config *bss = &conf->bss[0];
     49          1.1  christos 	int pairwise;
     50          1.1  christos 
     51          1.1  christos 	conf->driver = wpa_s->driver;
     52          1.1  christos 
     53          1.1  christos 	os_strlcpy(bss->iface, wpa_s->ifname, sizeof(bss->iface));
     54          1.1  christos 
     55          1.1  christos 	if (ssid->frequency == 0) {
     56          1.1  christos 		/* default channel 11 */
     57          1.1  christos 		conf->hw_mode = HOSTAPD_MODE_IEEE80211G;
     58          1.1  christos 		conf->channel = 11;
     59          1.1  christos 	} else if (ssid->frequency >= 2412 && ssid->frequency <= 2472) {
     60          1.1  christos 		conf->hw_mode = HOSTAPD_MODE_IEEE80211G;
     61          1.1  christos 		conf->channel = (ssid->frequency - 2407) / 5;
     62          1.1  christos 	} else if ((ssid->frequency >= 5180 && ssid->frequency <= 5240) ||
     63          1.1  christos 		   (ssid->frequency >= 5745 && ssid->frequency <= 5825)) {
     64          1.1  christos 		conf->hw_mode = HOSTAPD_MODE_IEEE80211A;
     65          1.1  christos 		conf->channel = (ssid->frequency - 5000) / 5;
     66  1.1.1.1.6.2      yamt 	} else if (ssid->frequency >= 56160 + 2160 * 1 &&
     67  1.1.1.1.6.2      yamt 		   ssid->frequency <= 56160 + 2160 * 4) {
     68  1.1.1.1.6.2      yamt 		conf->hw_mode = HOSTAPD_MODE_IEEE80211AD;
     69  1.1.1.1.6.2      yamt 		conf->channel = (ssid->frequency - 56160) / 2160;
     70          1.1  christos 	} else {
     71          1.1  christos 		wpa_printf(MSG_ERROR, "Unsupported AP mode frequency: %d MHz",
     72          1.1  christos 			   ssid->frequency);
     73          1.1  christos 		return -1;
     74          1.1  christos 	}
     75          1.1  christos 
     76  1.1.1.1.6.1      yamt 	/* TODO: enable HT40 if driver supports it;
     77          1.1  christos 	 * drop to 11b if driver does not support 11g */
     78          1.1  christos 
     79  1.1.1.1.6.1      yamt #ifdef CONFIG_IEEE80211N
     80  1.1.1.1.6.1      yamt 	/*
     81  1.1.1.1.6.2      yamt 	 * Enable HT20 if the driver supports it, by setting conf->ieee80211n
     82  1.1.1.1.6.2      yamt 	 * and a mask of allowed capabilities within conf->ht_capab.
     83  1.1.1.1.6.1      yamt 	 * Using default config settings for: conf->ht_op_mode_fixed,
     84  1.1.1.1.6.2      yamt 	 * conf->secondary_channel, conf->require_ht
     85  1.1.1.1.6.1      yamt 	 */
     86  1.1.1.1.6.1      yamt 	if (wpa_s->hw.modes) {
     87  1.1.1.1.6.1      yamt 		struct hostapd_hw_modes *mode = NULL;
     88  1.1.1.1.6.2      yamt 		int i, no_ht = 0;
     89  1.1.1.1.6.1      yamt 		for (i = 0; i < wpa_s->hw.num_modes; i++) {
     90  1.1.1.1.6.1      yamt 			if (wpa_s->hw.modes[i].mode == conf->hw_mode) {
     91  1.1.1.1.6.1      yamt 				mode = &wpa_s->hw.modes[i];
     92  1.1.1.1.6.1      yamt 				break;
     93  1.1.1.1.6.1      yamt 			}
     94  1.1.1.1.6.1      yamt 		}
     95  1.1.1.1.6.2      yamt 
     96  1.1.1.1.6.2      yamt #ifdef CONFIG_HT_OVERRIDES
     97  1.1.1.1.6.2      yamt 		if (ssid->disable_ht) {
     98  1.1.1.1.6.2      yamt 			conf->ieee80211n = 0;
     99  1.1.1.1.6.2      yamt 			conf->ht_capab = 0;
    100  1.1.1.1.6.2      yamt 			no_ht = 1;
    101  1.1.1.1.6.2      yamt 		}
    102  1.1.1.1.6.2      yamt #endif /* CONFIG_HT_OVERRIDES */
    103  1.1.1.1.6.2      yamt 
    104  1.1.1.1.6.2      yamt 		if (!no_ht && mode && mode->ht_capab) {
    105  1.1.1.1.6.1      yamt 			conf->ieee80211n = 1;
    106  1.1.1.1.6.2      yamt #ifdef CONFIG_P2P
    107  1.1.1.1.6.2      yamt 			if (conf->hw_mode == HOSTAPD_MODE_IEEE80211A &&
    108  1.1.1.1.6.2      yamt 			    (mode->ht_capab &
    109  1.1.1.1.6.2      yamt 			     HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) &&
    110  1.1.1.1.6.2      yamt 			    ssid->ht40)
    111  1.1.1.1.6.2      yamt 				conf->secondary_channel =
    112  1.1.1.1.6.2      yamt 					wpas_p2p_get_ht40_mode(wpa_s, mode,
    113  1.1.1.1.6.2      yamt 							       conf->channel);
    114  1.1.1.1.6.2      yamt 			if (conf->secondary_channel)
    115  1.1.1.1.6.2      yamt 				conf->ht_capab |=
    116  1.1.1.1.6.2      yamt 					HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
    117  1.1.1.1.6.2      yamt #endif /* CONFIG_P2P */
    118  1.1.1.1.6.2      yamt 
    119  1.1.1.1.6.2      yamt 			/*
    120  1.1.1.1.6.2      yamt 			 * white-list capabilities that won't cause issues
    121  1.1.1.1.6.2      yamt 			 * to connecting stations, while leaving the current
    122  1.1.1.1.6.2      yamt 			 * capabilities intact (currently disabled SMPS).
    123  1.1.1.1.6.2      yamt 			 */
    124  1.1.1.1.6.2      yamt 			conf->ht_capab |= mode->ht_capab &
    125  1.1.1.1.6.2      yamt 				(HT_CAP_INFO_GREEN_FIELD |
    126  1.1.1.1.6.2      yamt 				 HT_CAP_INFO_SHORT_GI20MHZ |
    127  1.1.1.1.6.2      yamt 				 HT_CAP_INFO_SHORT_GI40MHZ |
    128  1.1.1.1.6.2      yamt 				 HT_CAP_INFO_RX_STBC_MASK |
    129  1.1.1.1.6.2      yamt 				 HT_CAP_INFO_MAX_AMSDU_SIZE);
    130  1.1.1.1.6.2      yamt 		}
    131  1.1.1.1.6.1      yamt 	}
    132  1.1.1.1.6.1      yamt #endif /* CONFIG_IEEE80211N */
    133  1.1.1.1.6.1      yamt 
    134  1.1.1.1.6.1      yamt #ifdef CONFIG_P2P
    135  1.1.1.1.6.1      yamt 	if (conf->hw_mode == HOSTAPD_MODE_IEEE80211G) {
    136  1.1.1.1.6.1      yamt 		/* Remove 802.11b rates from supported and basic rate sets */
    137  1.1.1.1.6.1      yamt 		int *list = os_malloc(4 * sizeof(int));
    138  1.1.1.1.6.1      yamt 		if (list) {
    139  1.1.1.1.6.1      yamt 			list[0] = 60;
    140  1.1.1.1.6.1      yamt 			list[1] = 120;
    141  1.1.1.1.6.1      yamt 			list[2] = 240;
    142  1.1.1.1.6.1      yamt 			list[3] = -1;
    143  1.1.1.1.6.1      yamt 		}
    144  1.1.1.1.6.1      yamt 		conf->basic_rates = list;
    145  1.1.1.1.6.1      yamt 
    146  1.1.1.1.6.1      yamt 		list = os_malloc(9 * sizeof(int));
    147  1.1.1.1.6.1      yamt 		if (list) {
    148  1.1.1.1.6.1      yamt 			list[0] = 60;
    149  1.1.1.1.6.1      yamt 			list[1] = 90;
    150  1.1.1.1.6.1      yamt 			list[2] = 120;
    151  1.1.1.1.6.1      yamt 			list[3] = 180;
    152  1.1.1.1.6.1      yamt 			list[4] = 240;
    153  1.1.1.1.6.1      yamt 			list[5] = 360;
    154  1.1.1.1.6.1      yamt 			list[6] = 480;
    155  1.1.1.1.6.1      yamt 			list[7] = 540;
    156  1.1.1.1.6.1      yamt 			list[8] = -1;
    157  1.1.1.1.6.1      yamt 		}
    158  1.1.1.1.6.1      yamt 		conf->supported_rates = list;
    159  1.1.1.1.6.1      yamt 	}
    160  1.1.1.1.6.1      yamt 
    161  1.1.1.1.6.1      yamt 	bss->isolate = !wpa_s->conf->p2p_intra_bss;
    162  1.1.1.1.6.1      yamt #endif /* CONFIG_P2P */
    163  1.1.1.1.6.1      yamt 
    164          1.1  christos 	if (ssid->ssid_len == 0) {
    165          1.1  christos 		wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
    166          1.1  christos 		return -1;
    167          1.1  christos 	}
    168          1.1  christos 	os_memcpy(bss->ssid.ssid, ssid->ssid, ssid->ssid_len);
    169          1.1  christos 	bss->ssid.ssid_len = ssid->ssid_len;
    170          1.1  christos 	bss->ssid.ssid_set = 1;
    171          1.1  christos 
    172  1.1.1.1.6.2      yamt 	bss->ignore_broadcast_ssid = ssid->ignore_broadcast_ssid;
    173  1.1.1.1.6.2      yamt 
    174  1.1.1.1.6.1      yamt 	if (ssid->auth_alg)
    175  1.1.1.1.6.1      yamt 		bss->auth_algs = ssid->auth_alg;
    176  1.1.1.1.6.1      yamt 
    177          1.1  christos 	if (wpa_key_mgmt_wpa_psk(ssid->key_mgmt))
    178          1.1  christos 		bss->wpa = ssid->proto;
    179          1.1  christos 	bss->wpa_key_mgmt = ssid->key_mgmt;
    180          1.1  christos 	bss->wpa_pairwise = ssid->pairwise_cipher;
    181  1.1.1.1.6.2      yamt 	if (ssid->psk_set) {
    182          1.1  christos 		os_free(bss->ssid.wpa_psk);
    183          1.1  christos 		bss->ssid.wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
    184          1.1  christos 		if (bss->ssid.wpa_psk == NULL)
    185          1.1  christos 			return -1;
    186          1.1  christos 		os_memcpy(bss->ssid.wpa_psk->psk, ssid->psk, PMK_LEN);
    187          1.1  christos 		bss->ssid.wpa_psk->group = 1;
    188  1.1.1.1.6.2      yamt 	} else if (ssid->passphrase) {
    189  1.1.1.1.6.2      yamt 		bss->ssid.wpa_passphrase = os_strdup(ssid->passphrase);
    190  1.1.1.1.6.1      yamt 	} else if (ssid->wep_key_len[0] || ssid->wep_key_len[1] ||
    191  1.1.1.1.6.1      yamt 		   ssid->wep_key_len[2] || ssid->wep_key_len[3]) {
    192  1.1.1.1.6.1      yamt 		struct hostapd_wep_keys *wep = &bss->ssid.wep;
    193  1.1.1.1.6.1      yamt 		int i;
    194  1.1.1.1.6.1      yamt 		for (i = 0; i < NUM_WEP_KEYS; i++) {
    195  1.1.1.1.6.1      yamt 			if (ssid->wep_key_len[i] == 0)
    196  1.1.1.1.6.1      yamt 				continue;
    197  1.1.1.1.6.1      yamt 			wep->key[i] = os_malloc(ssid->wep_key_len[i]);
    198  1.1.1.1.6.1      yamt 			if (wep->key[i] == NULL)
    199  1.1.1.1.6.1      yamt 				return -1;
    200  1.1.1.1.6.1      yamt 			os_memcpy(wep->key[i], ssid->wep_key[i],
    201  1.1.1.1.6.1      yamt 				  ssid->wep_key_len[i]);
    202  1.1.1.1.6.1      yamt 			wep->len[i] = ssid->wep_key_len[i];
    203  1.1.1.1.6.1      yamt 		}
    204  1.1.1.1.6.1      yamt 		wep->idx = ssid->wep_tx_keyidx;
    205  1.1.1.1.6.1      yamt 		wep->keys_set = 1;
    206          1.1  christos 	}
    207          1.1  christos 
    208  1.1.1.1.6.2      yamt 	if (ssid->ap_max_inactivity)
    209  1.1.1.1.6.2      yamt 		bss->ap_max_inactivity = ssid->ap_max_inactivity;
    210  1.1.1.1.6.2      yamt 
    211  1.1.1.1.6.2      yamt 	if (ssid->dtim_period)
    212  1.1.1.1.6.2      yamt 		bss->dtim_period = ssid->dtim_period;
    213  1.1.1.1.6.2      yamt 
    214          1.1  christos 	/* Select group cipher based on the enabled pairwise cipher suites */
    215          1.1  christos 	pairwise = 0;
    216          1.1  christos 	if (bss->wpa & 1)
    217          1.1  christos 		pairwise |= bss->wpa_pairwise;
    218          1.1  christos 	if (bss->wpa & 2) {
    219          1.1  christos 		if (bss->rsn_pairwise == 0)
    220          1.1  christos 			bss->rsn_pairwise = bss->wpa_pairwise;
    221          1.1  christos 		pairwise |= bss->rsn_pairwise;
    222          1.1  christos 	}
    223          1.1  christos 	if (pairwise & WPA_CIPHER_TKIP)
    224          1.1  christos 		bss->wpa_group = WPA_CIPHER_TKIP;
    225  1.1.1.1.6.2      yamt 	else if ((pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP)) ==
    226  1.1.1.1.6.2      yamt 		 WPA_CIPHER_GCMP)
    227  1.1.1.1.6.2      yamt 		bss->wpa_group = WPA_CIPHER_GCMP;
    228          1.1  christos 	else
    229          1.1  christos 		bss->wpa_group = WPA_CIPHER_CCMP;
    230          1.1  christos 
    231          1.1  christos 	if (bss->wpa && bss->ieee802_1x)
    232          1.1  christos 		bss->ssid.security_policy = SECURITY_WPA;
    233          1.1  christos 	else if (bss->wpa)
    234          1.1  christos 		bss->ssid.security_policy = SECURITY_WPA_PSK;
    235          1.1  christos 	else if (bss->ieee802_1x) {
    236  1.1.1.1.6.1      yamt 		int cipher = WPA_CIPHER_NONE;
    237          1.1  christos 		bss->ssid.security_policy = SECURITY_IEEE_802_1X;
    238          1.1  christos 		bss->ssid.wep.default_len = bss->default_wep_key_len;
    239  1.1.1.1.6.1      yamt 		if (bss->default_wep_key_len)
    240  1.1.1.1.6.1      yamt 			cipher = bss->default_wep_key_len >= 13 ?
    241  1.1.1.1.6.1      yamt 				WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
    242  1.1.1.1.6.1      yamt 		bss->wpa_group = cipher;
    243  1.1.1.1.6.1      yamt 		bss->wpa_pairwise = cipher;
    244  1.1.1.1.6.1      yamt 		bss->rsn_pairwise = cipher;
    245  1.1.1.1.6.1      yamt 	} else if (bss->ssid.wep.keys_set) {
    246  1.1.1.1.6.1      yamt 		int cipher = WPA_CIPHER_WEP40;
    247  1.1.1.1.6.1      yamt 		if (bss->ssid.wep.len[0] >= 13)
    248  1.1.1.1.6.1      yamt 			cipher = WPA_CIPHER_WEP104;
    249          1.1  christos 		bss->ssid.security_policy = SECURITY_STATIC_WEP;
    250  1.1.1.1.6.1      yamt 		bss->wpa_group = cipher;
    251  1.1.1.1.6.1      yamt 		bss->wpa_pairwise = cipher;
    252  1.1.1.1.6.1      yamt 		bss->rsn_pairwise = cipher;
    253  1.1.1.1.6.1      yamt 	} else {
    254          1.1  christos 		bss->ssid.security_policy = SECURITY_PLAINTEXT;
    255  1.1.1.1.6.1      yamt 		bss->wpa_group = WPA_CIPHER_NONE;
    256  1.1.1.1.6.1      yamt 		bss->wpa_pairwise = WPA_CIPHER_NONE;
    257  1.1.1.1.6.1      yamt 		bss->rsn_pairwise = WPA_CIPHER_NONE;
    258  1.1.1.1.6.1      yamt 	}
    259          1.1  christos 
    260          1.1  christos #ifdef CONFIG_WPS
    261          1.1  christos 	/*
    262  1.1.1.1.6.1      yamt 	 * Enable WPS by default for open and WPA/WPA2-Personal network, but
    263  1.1.1.1.6.1      yamt 	 * require user interaction to actually use it. Only the internal
    264  1.1.1.1.6.1      yamt 	 * Registrar is supported.
    265          1.1  christos 	 */
    266  1.1.1.1.6.1      yamt 	if (bss->ssid.security_policy != SECURITY_WPA_PSK &&
    267  1.1.1.1.6.1      yamt 	    bss->ssid.security_policy != SECURITY_PLAINTEXT)
    268  1.1.1.1.6.1      yamt 		goto no_wps;
    269  1.1.1.1.6.1      yamt #ifdef CONFIG_WPS2
    270  1.1.1.1.6.1      yamt 	if (bss->ssid.security_policy == SECURITY_WPA_PSK &&
    271  1.1.1.1.6.1      yamt 	    (!(pairwise & WPA_CIPHER_CCMP) || !(bss->wpa & 2)))
    272  1.1.1.1.6.1      yamt 		goto no_wps; /* WPS2 does not allow WPA/TKIP-only
    273  1.1.1.1.6.1      yamt 			      * configuration */
    274  1.1.1.1.6.1      yamt #endif /* CONFIG_WPS2 */
    275          1.1  christos 	bss->eap_server = 1;
    276  1.1.1.1.6.2      yamt 
    277  1.1.1.1.6.2      yamt 	if (!ssid->ignore_broadcast_ssid)
    278  1.1.1.1.6.2      yamt 		bss->wps_state = 2;
    279  1.1.1.1.6.2      yamt 
    280  1.1.1.1.6.1      yamt 	bss->ap_setup_locked = 2;
    281          1.1  christos 	if (wpa_s->conf->config_methods)
    282          1.1  christos 		bss->config_methods = os_strdup(wpa_s->conf->config_methods);
    283  1.1.1.1.6.1      yamt 	os_memcpy(bss->device_type, wpa_s->conf->device_type,
    284  1.1.1.1.6.1      yamt 		  WPS_DEV_TYPE_LEN);
    285  1.1.1.1.6.1      yamt 	if (wpa_s->conf->device_name) {
    286  1.1.1.1.6.1      yamt 		bss->device_name = os_strdup(wpa_s->conf->device_name);
    287  1.1.1.1.6.1      yamt 		bss->friendly_name = os_strdup(wpa_s->conf->device_name);
    288  1.1.1.1.6.1      yamt 	}
    289  1.1.1.1.6.1      yamt 	if (wpa_s->conf->manufacturer)
    290  1.1.1.1.6.1      yamt 		bss->manufacturer = os_strdup(wpa_s->conf->manufacturer);
    291  1.1.1.1.6.1      yamt 	if (wpa_s->conf->model_name)
    292  1.1.1.1.6.1      yamt 		bss->model_name = os_strdup(wpa_s->conf->model_name);
    293  1.1.1.1.6.1      yamt 	if (wpa_s->conf->model_number)
    294  1.1.1.1.6.1      yamt 		bss->model_number = os_strdup(wpa_s->conf->model_number);
    295  1.1.1.1.6.1      yamt 	if (wpa_s->conf->serial_number)
    296  1.1.1.1.6.1      yamt 		bss->serial_number = os_strdup(wpa_s->conf->serial_number);
    297  1.1.1.1.6.1      yamt 	if (is_nil_uuid(wpa_s->conf->uuid))
    298  1.1.1.1.6.1      yamt 		os_memcpy(bss->uuid, wpa_s->wps->uuid, WPS_UUID_LEN);
    299  1.1.1.1.6.1      yamt 	else
    300  1.1.1.1.6.1      yamt 		os_memcpy(bss->uuid, wpa_s->conf->uuid, WPS_UUID_LEN);
    301  1.1.1.1.6.1      yamt 	os_memcpy(bss->os_version, wpa_s->conf->os_version, 4);
    302  1.1.1.1.6.2      yamt 	bss->pbc_in_m1 = wpa_s->conf->pbc_in_m1;
    303  1.1.1.1.6.1      yamt no_wps:
    304          1.1  christos #endif /* CONFIG_WPS */
    305          1.1  christos 
    306  1.1.1.1.6.1      yamt 	if (wpa_s->max_stations &&
    307  1.1.1.1.6.1      yamt 	    wpa_s->max_stations < wpa_s->conf->max_num_sta)
    308  1.1.1.1.6.1      yamt 		bss->max_num_sta = wpa_s->max_stations;
    309  1.1.1.1.6.1      yamt 	else
    310  1.1.1.1.6.1      yamt 		bss->max_num_sta = wpa_s->conf->max_num_sta;
    311  1.1.1.1.6.1      yamt 
    312  1.1.1.1.6.1      yamt 	bss->disassoc_low_ack = wpa_s->conf->disassoc_low_ack;
    313  1.1.1.1.6.1      yamt 
    314          1.1  christos 	return 0;
    315          1.1  christos }
    316          1.1  christos 
    317          1.1  christos 
    318          1.1  christos static void ap_public_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
    319          1.1  christos {
    320  1.1.1.1.6.1      yamt #ifdef CONFIG_P2P
    321  1.1.1.1.6.1      yamt 	struct wpa_supplicant *wpa_s = ctx;
    322  1.1.1.1.6.1      yamt 	const struct ieee80211_mgmt *mgmt;
    323  1.1.1.1.6.1      yamt 	size_t hdr_len;
    324  1.1.1.1.6.1      yamt 
    325  1.1.1.1.6.1      yamt 	mgmt = (const struct ieee80211_mgmt *) buf;
    326  1.1.1.1.6.1      yamt 	hdr_len = (const u8 *) &mgmt->u.action.u.vs_public_action.action - buf;
    327  1.1.1.1.6.1      yamt 	if (hdr_len > len)
    328  1.1.1.1.6.1      yamt 		return;
    329  1.1.1.1.6.1      yamt 	wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
    330  1.1.1.1.6.1      yamt 			   mgmt->u.action.category,
    331  1.1.1.1.6.1      yamt 			   &mgmt->u.action.u.vs_public_action.action,
    332  1.1.1.1.6.1      yamt 			   len - hdr_len, freq);
    333  1.1.1.1.6.1      yamt #endif /* CONFIG_P2P */
    334  1.1.1.1.6.1      yamt }
    335  1.1.1.1.6.1      yamt 
    336  1.1.1.1.6.1      yamt 
    337  1.1.1.1.6.1      yamt static void ap_wps_event_cb(void *ctx, enum wps_event event,
    338  1.1.1.1.6.1      yamt 			    union wps_event_data *data)
    339  1.1.1.1.6.1      yamt {
    340  1.1.1.1.6.1      yamt #ifdef CONFIG_P2P
    341  1.1.1.1.6.1      yamt 	struct wpa_supplicant *wpa_s = ctx;
    342  1.1.1.1.6.1      yamt 
    343  1.1.1.1.6.1      yamt 	if (event == WPS_EV_FAIL) {
    344  1.1.1.1.6.1      yamt 		struct wps_event_fail *fail = &data->fail;
    345  1.1.1.1.6.1      yamt 
    346  1.1.1.1.6.1      yamt 		if (wpa_s->parent && wpa_s->parent != wpa_s &&
    347  1.1.1.1.6.1      yamt 		    wpa_s == wpa_s->global->p2p_group_formation) {
    348  1.1.1.1.6.1      yamt 			/*
    349  1.1.1.1.6.1      yamt 			 * src/ap/wps_hostapd.c has already sent this on the
    350  1.1.1.1.6.1      yamt 			 * main interface, so only send on the parent interface
    351  1.1.1.1.6.1      yamt 			 * here if needed.
    352  1.1.1.1.6.1      yamt 			 */
    353  1.1.1.1.6.1      yamt 			wpa_msg(wpa_s->parent, MSG_INFO, WPS_EVENT_FAIL
    354  1.1.1.1.6.1      yamt 				"msg=%d config_error=%d",
    355  1.1.1.1.6.1      yamt 				fail->msg, fail->config_error);
    356  1.1.1.1.6.1      yamt 		}
    357  1.1.1.1.6.1      yamt 		wpas_p2p_wps_failed(wpa_s, fail);
    358  1.1.1.1.6.1      yamt 	}
    359  1.1.1.1.6.1      yamt #endif /* CONFIG_P2P */
    360  1.1.1.1.6.1      yamt }
    361  1.1.1.1.6.1      yamt 
    362  1.1.1.1.6.1      yamt 
    363  1.1.1.1.6.1      yamt static void ap_sta_authorized_cb(void *ctx, const u8 *mac_addr,
    364  1.1.1.1.6.1      yamt 				 int authorized, const u8 *p2p_dev_addr)
    365  1.1.1.1.6.1      yamt {
    366  1.1.1.1.6.1      yamt 	wpas_notify_sta_authorized(ctx, mac_addr, authorized, p2p_dev_addr);
    367  1.1.1.1.6.1      yamt }
    368  1.1.1.1.6.1      yamt 
    369  1.1.1.1.6.1      yamt 
    370  1.1.1.1.6.1      yamt static int ap_vendor_action_rx(void *ctx, const u8 *buf, size_t len, int freq)
    371  1.1.1.1.6.1      yamt {
    372  1.1.1.1.6.1      yamt #ifdef CONFIG_P2P
    373  1.1.1.1.6.1      yamt 	struct wpa_supplicant *wpa_s = ctx;
    374  1.1.1.1.6.1      yamt 	const struct ieee80211_mgmt *mgmt;
    375  1.1.1.1.6.1      yamt 	size_t hdr_len;
    376  1.1.1.1.6.1      yamt 
    377  1.1.1.1.6.1      yamt 	mgmt = (const struct ieee80211_mgmt *) buf;
    378  1.1.1.1.6.1      yamt 	hdr_len = (const u8 *) &mgmt->u.action.u.vs_public_action.action - buf;
    379  1.1.1.1.6.1      yamt 	if (hdr_len > len)
    380  1.1.1.1.6.1      yamt 		return -1;
    381  1.1.1.1.6.1      yamt 	wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid,
    382  1.1.1.1.6.1      yamt 			   mgmt->u.action.category,
    383  1.1.1.1.6.1      yamt 			   &mgmt->u.action.u.vs_public_action.action,
    384  1.1.1.1.6.1      yamt 			   len - hdr_len, freq);
    385  1.1.1.1.6.1      yamt #endif /* CONFIG_P2P */
    386  1.1.1.1.6.1      yamt 	return 0;
    387          1.1  christos }
    388          1.1  christos 
    389          1.1  christos 
    390  1.1.1.1.6.1      yamt static int ap_probe_req_rx(void *ctx, const u8 *sa, const u8 *da,
    391  1.1.1.1.6.2      yamt 			   const u8 *bssid, const u8 *ie, size_t ie_len,
    392  1.1.1.1.6.2      yamt 			   int ssi_signal)
    393          1.1  christos {
    394  1.1.1.1.6.1      yamt #ifdef CONFIG_P2P
    395  1.1.1.1.6.1      yamt 	struct wpa_supplicant *wpa_s = ctx;
    396  1.1.1.1.6.2      yamt 	return wpas_p2p_probe_req_rx(wpa_s, sa, da, bssid, ie, ie_len,
    397  1.1.1.1.6.2      yamt 				     ssi_signal);
    398  1.1.1.1.6.1      yamt #else /* CONFIG_P2P */
    399          1.1  christos 	return 0;
    400  1.1.1.1.6.1      yamt #endif /* CONFIG_P2P */
    401          1.1  christos }
    402          1.1  christos 
    403          1.1  christos 
    404          1.1  christos static void ap_wps_reg_success_cb(void *ctx, const u8 *mac_addr,
    405          1.1  christos 				  const u8 *uuid_e)
    406          1.1  christos {
    407  1.1.1.1.6.1      yamt #ifdef CONFIG_P2P
    408  1.1.1.1.6.1      yamt 	struct wpa_supplicant *wpa_s = ctx;
    409  1.1.1.1.6.1      yamt 	wpas_p2p_wps_success(wpa_s, mac_addr, 1);
    410  1.1.1.1.6.1      yamt #endif /* CONFIG_P2P */
    411  1.1.1.1.6.1      yamt }
    412  1.1.1.1.6.1      yamt 
    413  1.1.1.1.6.1      yamt 
    414  1.1.1.1.6.1      yamt static void wpas_ap_configured_cb(void *ctx)
    415  1.1.1.1.6.1      yamt {
    416  1.1.1.1.6.1      yamt 	struct wpa_supplicant *wpa_s = ctx;
    417  1.1.1.1.6.1      yamt 
    418  1.1.1.1.6.1      yamt 	wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
    419  1.1.1.1.6.1      yamt 
    420  1.1.1.1.6.1      yamt 	if (wpa_s->ap_configured_cb)
    421  1.1.1.1.6.1      yamt 		wpa_s->ap_configured_cb(wpa_s->ap_configured_cb_ctx,
    422  1.1.1.1.6.1      yamt 					wpa_s->ap_configured_cb_data);
    423          1.1  christos }
    424          1.1  christos 
    425          1.1  christos 
    426          1.1  christos int wpa_supplicant_create_ap(struct wpa_supplicant *wpa_s,
    427          1.1  christos 			     struct wpa_ssid *ssid)
    428          1.1  christos {
    429          1.1  christos 	struct wpa_driver_associate_params params;
    430          1.1  christos 	struct hostapd_iface *hapd_iface;
    431          1.1  christos 	struct hostapd_config *conf;
    432          1.1  christos 	size_t i;
    433          1.1  christos 
    434          1.1  christos 	if (ssid->ssid == NULL || ssid->ssid_len == 0) {
    435          1.1  christos 		wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
    436          1.1  christos 		return -1;
    437          1.1  christos 	}
    438          1.1  christos 
    439          1.1  christos 	wpa_supplicant_ap_deinit(wpa_s);
    440          1.1  christos 
    441          1.1  christos 	wpa_printf(MSG_DEBUG, "Setting up AP (SSID='%s')",
    442          1.1  christos 		   wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
    443          1.1  christos 
    444          1.1  christos 	os_memset(&params, 0, sizeof(params));
    445          1.1  christos 	params.ssid = ssid->ssid;
    446          1.1  christos 	params.ssid_len = ssid->ssid_len;
    447          1.1  christos 	switch (ssid->mode) {
    448          1.1  christos 	case WPAS_MODE_INFRA:
    449          1.1  christos 		params.mode = IEEE80211_MODE_INFRA;
    450          1.1  christos 		break;
    451          1.1  christos 	case WPAS_MODE_IBSS:
    452          1.1  christos 		params.mode = IEEE80211_MODE_IBSS;
    453          1.1  christos 		break;
    454          1.1  christos 	case WPAS_MODE_AP:
    455  1.1.1.1.6.1      yamt 	case WPAS_MODE_P2P_GO:
    456  1.1.1.1.6.1      yamt 	case WPAS_MODE_P2P_GROUP_FORMATION:
    457          1.1  christos 		params.mode = IEEE80211_MODE_AP;
    458          1.1  christos 		break;
    459          1.1  christos 	}
    460          1.1  christos 	params.freq = ssid->frequency;
    461          1.1  christos 
    462  1.1.1.1.6.1      yamt 	params.wpa_proto = ssid->proto;
    463          1.1  christos 	if (ssid->key_mgmt & WPA_KEY_MGMT_PSK)
    464          1.1  christos 		wpa_s->key_mgmt = WPA_KEY_MGMT_PSK;
    465          1.1  christos 	else
    466          1.1  christos 		wpa_s->key_mgmt = WPA_KEY_MGMT_NONE;
    467          1.1  christos 	params.key_mgmt_suite = key_mgmt2driver(wpa_s->key_mgmt);
    468          1.1  christos 
    469          1.1  christos 	if (ssid->pairwise_cipher & WPA_CIPHER_CCMP)
    470          1.1  christos 		wpa_s->pairwise_cipher = WPA_CIPHER_CCMP;
    471  1.1.1.1.6.2      yamt 	else if (ssid->pairwise_cipher & WPA_CIPHER_GCMP)
    472  1.1.1.1.6.2      yamt 		wpa_s->pairwise_cipher = WPA_CIPHER_GCMP;
    473          1.1  christos 	else if (ssid->pairwise_cipher & WPA_CIPHER_TKIP)
    474          1.1  christos 		wpa_s->pairwise_cipher = WPA_CIPHER_TKIP;
    475          1.1  christos 	else if (ssid->pairwise_cipher & WPA_CIPHER_NONE)
    476          1.1  christos 		wpa_s->pairwise_cipher = WPA_CIPHER_NONE;
    477          1.1  christos 	else {
    478          1.1  christos 		wpa_printf(MSG_WARNING, "WPA: Failed to select pairwise "
    479          1.1  christos 			   "cipher.");
    480          1.1  christos 		return -1;
    481          1.1  christos 	}
    482          1.1  christos 	params.pairwise_suite = cipher_suite2driver(wpa_s->pairwise_cipher);
    483          1.1  christos 	params.group_suite = params.pairwise_suite;
    484          1.1  christos 
    485  1.1.1.1.6.1      yamt #ifdef CONFIG_P2P
    486  1.1.1.1.6.1      yamt 	if (ssid->mode == WPAS_MODE_P2P_GO ||
    487  1.1.1.1.6.1      yamt 	    ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
    488  1.1.1.1.6.1      yamt 		params.p2p = 1;
    489  1.1.1.1.6.1      yamt #endif /* CONFIG_P2P */
    490  1.1.1.1.6.1      yamt 
    491  1.1.1.1.6.1      yamt 	if (wpa_s->parent->set_ap_uapsd)
    492  1.1.1.1.6.1      yamt 		params.uapsd = wpa_s->parent->ap_uapsd;
    493  1.1.1.1.6.1      yamt 	else
    494  1.1.1.1.6.1      yamt 		params.uapsd = -1;
    495  1.1.1.1.6.1      yamt 
    496          1.1  christos 	if (wpa_drv_associate(wpa_s, &params) < 0) {
    497          1.1  christos 		wpa_msg(wpa_s, MSG_INFO, "Failed to start AP functionality");
    498          1.1  christos 		return -1;
    499          1.1  christos 	}
    500          1.1  christos 
    501          1.1  christos 	wpa_s->ap_iface = hapd_iface = os_zalloc(sizeof(*wpa_s->ap_iface));
    502          1.1  christos 	if (hapd_iface == NULL)
    503          1.1  christos 		return -1;
    504          1.1  christos 	hapd_iface->owner = wpa_s;
    505  1.1.1.1.6.1      yamt 	hapd_iface->drv_flags = wpa_s->drv_flags;
    506  1.1.1.1.6.2      yamt 	hapd_iface->probe_resp_offloads = wpa_s->probe_resp_offloads;
    507          1.1  christos 
    508          1.1  christos 	wpa_s->ap_iface->conf = conf = hostapd_config_defaults();
    509          1.1  christos 	if (conf == NULL) {
    510          1.1  christos 		wpa_supplicant_ap_deinit(wpa_s);
    511          1.1  christos 		return -1;
    512          1.1  christos 	}
    513          1.1  christos 
    514  1.1.1.1.6.2      yamt 	os_memcpy(wpa_s->ap_iface->conf->wmm_ac_params,
    515  1.1.1.1.6.2      yamt 		  wpa_s->conf->wmm_ac_params,
    516  1.1.1.1.6.2      yamt 		  sizeof(wpa_s->conf->wmm_ac_params));
    517  1.1.1.1.6.2      yamt 
    518  1.1.1.1.6.1      yamt 	if (params.uapsd > 0) {
    519  1.1.1.1.6.1      yamt 		conf->bss->wmm_enabled = 1;
    520  1.1.1.1.6.1      yamt 		conf->bss->wmm_uapsd = 1;
    521  1.1.1.1.6.1      yamt 	}
    522  1.1.1.1.6.1      yamt 
    523          1.1  christos 	if (wpa_supplicant_conf_ap(wpa_s, ssid, conf)) {
    524          1.1  christos 		wpa_printf(MSG_ERROR, "Failed to create AP configuration");
    525          1.1  christos 		wpa_supplicant_ap_deinit(wpa_s);
    526          1.1  christos 		return -1;
    527          1.1  christos 	}
    528          1.1  christos 
    529  1.1.1.1.6.1      yamt #ifdef CONFIG_P2P
    530  1.1.1.1.6.1      yamt 	if (ssid->mode == WPAS_MODE_P2P_GO)
    531  1.1.1.1.6.1      yamt 		conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER;
    532  1.1.1.1.6.1      yamt 	else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
    533  1.1.1.1.6.1      yamt 		conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER |
    534  1.1.1.1.6.1      yamt 			P2P_GROUP_FORMATION;
    535  1.1.1.1.6.1      yamt #endif /* CONFIG_P2P */
    536  1.1.1.1.6.1      yamt 
    537          1.1  christos 	hapd_iface->num_bss = conf->num_bss;
    538  1.1.1.1.6.2      yamt 	hapd_iface->bss = os_calloc(conf->num_bss,
    539          1.1  christos 				    sizeof(struct hostapd_data *));
    540          1.1  christos 	if (hapd_iface->bss == NULL) {
    541          1.1  christos 		wpa_supplicant_ap_deinit(wpa_s);
    542          1.1  christos 		return -1;
    543          1.1  christos 	}
    544          1.1  christos 
    545          1.1  christos 	for (i = 0; i < conf->num_bss; i++) {
    546          1.1  christos 		hapd_iface->bss[i] =
    547          1.1  christos 			hostapd_alloc_bss_data(hapd_iface, conf,
    548          1.1  christos 					       &conf->bss[i]);
    549          1.1  christos 		if (hapd_iface->bss[i] == NULL) {
    550          1.1  christos 			wpa_supplicant_ap_deinit(wpa_s);
    551          1.1  christos 			return -1;
    552          1.1  christos 		}
    553          1.1  christos 
    554          1.1  christos 		hapd_iface->bss[i]->msg_ctx = wpa_s;
    555  1.1.1.1.6.1      yamt 		hapd_iface->bss[i]->msg_ctx_parent = wpa_s->parent;
    556          1.1  christos 		hapd_iface->bss[i]->public_action_cb = ap_public_action_rx;
    557          1.1  christos 		hapd_iface->bss[i]->public_action_cb_ctx = wpa_s;
    558  1.1.1.1.6.1      yamt 		hapd_iface->bss[i]->vendor_action_cb = ap_vendor_action_rx;
    559  1.1.1.1.6.1      yamt 		hapd_iface->bss[i]->vendor_action_cb_ctx = wpa_s;
    560          1.1  christos 		hostapd_register_probereq_cb(hapd_iface->bss[i],
    561          1.1  christos 					     ap_probe_req_rx, wpa_s);
    562          1.1  christos 		hapd_iface->bss[i]->wps_reg_success_cb = ap_wps_reg_success_cb;
    563          1.1  christos 		hapd_iface->bss[i]->wps_reg_success_cb_ctx = wpa_s;
    564  1.1.1.1.6.1      yamt 		hapd_iface->bss[i]->wps_event_cb = ap_wps_event_cb;
    565  1.1.1.1.6.1      yamt 		hapd_iface->bss[i]->wps_event_cb_ctx = wpa_s;
    566  1.1.1.1.6.1      yamt 		hapd_iface->bss[i]->sta_authorized_cb = ap_sta_authorized_cb;
    567  1.1.1.1.6.1      yamt 		hapd_iface->bss[i]->sta_authorized_cb_ctx = wpa_s;
    568  1.1.1.1.6.1      yamt #ifdef CONFIG_P2P
    569  1.1.1.1.6.1      yamt 		hapd_iface->bss[i]->p2p = wpa_s->global->p2p;
    570  1.1.1.1.6.2      yamt 		hapd_iface->bss[i]->p2p_group = wpas_p2p_group_init(wpa_s,
    571  1.1.1.1.6.2      yamt 								    ssid);
    572  1.1.1.1.6.1      yamt #endif /* CONFIG_P2P */
    573  1.1.1.1.6.1      yamt 		hapd_iface->bss[i]->setup_complete_cb = wpas_ap_configured_cb;
    574  1.1.1.1.6.1      yamt 		hapd_iface->bss[i]->setup_complete_cb_ctx = wpa_s;
    575          1.1  christos 	}
    576          1.1  christos 
    577          1.1  christos 	os_memcpy(hapd_iface->bss[0]->own_addr, wpa_s->own_addr, ETH_ALEN);
    578          1.1  christos 	hapd_iface->bss[0]->driver = wpa_s->driver;
    579          1.1  christos 	hapd_iface->bss[0]->drv_priv = wpa_s->drv_priv;
    580          1.1  christos 
    581  1.1.1.1.6.1      yamt 	wpa_s->current_ssid = ssid;
    582  1.1.1.1.6.1      yamt 	os_memcpy(wpa_s->bssid, wpa_s->own_addr, ETH_ALEN);
    583  1.1.1.1.6.1      yamt 	wpa_s->assoc_freq = ssid->frequency;
    584  1.1.1.1.6.1      yamt 
    585          1.1  christos 	if (hostapd_setup_interface(wpa_s->ap_iface)) {
    586          1.1  christos 		wpa_printf(MSG_ERROR, "Failed to initialize AP interface");
    587          1.1  christos 		wpa_supplicant_ap_deinit(wpa_s);
    588          1.1  christos 		return -1;
    589          1.1  christos 	}
    590          1.1  christos 
    591          1.1  christos 	return 0;
    592          1.1  christos }
    593          1.1  christos 
    594          1.1  christos 
    595          1.1  christos void wpa_supplicant_ap_deinit(struct wpa_supplicant *wpa_s)
    596          1.1  christos {
    597  1.1.1.1.6.1      yamt #ifdef CONFIG_WPS
    598  1.1.1.1.6.1      yamt 	eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
    599  1.1.1.1.6.1      yamt #endif /* CONFIG_WPS */
    600  1.1.1.1.6.1      yamt 
    601          1.1  christos 	if (wpa_s->ap_iface == NULL)
    602          1.1  christos 		return;
    603          1.1  christos 
    604          1.1  christos 	wpa_s->current_ssid = NULL;
    605  1.1.1.1.6.1      yamt 	wpa_s->assoc_freq = 0;
    606  1.1.1.1.6.1      yamt #ifdef CONFIG_P2P
    607  1.1.1.1.6.1      yamt 	if (wpa_s->ap_iface->bss)
    608  1.1.1.1.6.1      yamt 		wpa_s->ap_iface->bss[0]->p2p_group = NULL;
    609  1.1.1.1.6.1      yamt 	wpas_p2p_group_deinit(wpa_s);
    610  1.1.1.1.6.1      yamt #endif /* CONFIG_P2P */
    611          1.1  christos 	hostapd_interface_deinit(wpa_s->ap_iface);
    612          1.1  christos 	hostapd_interface_free(wpa_s->ap_iface);
    613          1.1  christos 	wpa_s->ap_iface = NULL;
    614          1.1  christos 	wpa_drv_deinit_ap(wpa_s);
    615          1.1  christos }
    616          1.1  christos 
    617          1.1  christos 
    618          1.1  christos void ap_tx_status(void *ctx, const u8 *addr,
    619          1.1  christos 		  const u8 *buf, size_t len, int ack)
    620          1.1  christos {
    621          1.1  christos #ifdef NEED_AP_MLME
    622          1.1  christos 	struct wpa_supplicant *wpa_s = ctx;
    623          1.1  christos 	hostapd_tx_status(wpa_s->ap_iface->bss[0], addr, buf, len, ack);
    624          1.1  christos #endif /* NEED_AP_MLME */
    625          1.1  christos }
    626          1.1  christos 
    627          1.1  christos 
    628  1.1.1.1.6.2      yamt void ap_eapol_tx_status(void *ctx, const u8 *dst,
    629  1.1.1.1.6.2      yamt 			const u8 *data, size_t len, int ack)
    630  1.1.1.1.6.2      yamt {
    631  1.1.1.1.6.2      yamt #ifdef NEED_AP_MLME
    632  1.1.1.1.6.2      yamt 	struct wpa_supplicant *wpa_s = ctx;
    633  1.1.1.1.6.2      yamt 	hostapd_tx_status(wpa_s->ap_iface->bss[0], dst, data, len, ack);
    634  1.1.1.1.6.2      yamt #endif /* NEED_AP_MLME */
    635  1.1.1.1.6.2      yamt }
    636  1.1.1.1.6.2      yamt 
    637  1.1.1.1.6.2      yamt 
    638  1.1.1.1.6.1      yamt void ap_client_poll_ok(void *ctx, const u8 *addr)
    639          1.1  christos {
    640          1.1  christos #ifdef NEED_AP_MLME
    641          1.1  christos 	struct wpa_supplicant *wpa_s = ctx;
    642  1.1.1.1.6.1      yamt 	if (wpa_s->ap_iface)
    643  1.1.1.1.6.1      yamt 		hostapd_client_poll_ok(wpa_s->ap_iface->bss[0], addr);
    644  1.1.1.1.6.1      yamt #endif /* NEED_AP_MLME */
    645  1.1.1.1.6.1      yamt }
    646  1.1.1.1.6.1      yamt 
    647  1.1.1.1.6.1      yamt 
    648  1.1.1.1.6.1      yamt void ap_rx_from_unknown_sta(void *ctx, const u8 *addr, int wds)
    649  1.1.1.1.6.1      yamt {
    650  1.1.1.1.6.1      yamt #ifdef NEED_AP_MLME
    651  1.1.1.1.6.1      yamt 	struct wpa_supplicant *wpa_s = ctx;
    652  1.1.1.1.6.1      yamt 	ieee802_11_rx_from_unknown(wpa_s->ap_iface->bss[0], addr, wds);
    653          1.1  christos #endif /* NEED_AP_MLME */
    654          1.1  christos }
    655          1.1  christos 
    656          1.1  christos 
    657          1.1  christos void ap_mgmt_rx(void *ctx, struct rx_mgmt *rx_mgmt)
    658          1.1  christos {
    659          1.1  christos #ifdef NEED_AP_MLME
    660          1.1  christos 	struct wpa_supplicant *wpa_s = ctx;
    661          1.1  christos 	struct hostapd_frame_info fi;
    662          1.1  christos 	os_memset(&fi, 0, sizeof(fi));
    663          1.1  christos 	fi.datarate = rx_mgmt->datarate;
    664          1.1  christos 	fi.ssi_signal = rx_mgmt->ssi_signal;
    665          1.1  christos 	ieee802_11_mgmt(wpa_s->ap_iface->bss[0], rx_mgmt->frame,
    666          1.1  christos 			rx_mgmt->frame_len, &fi);
    667          1.1  christos #endif /* NEED_AP_MLME */
    668          1.1  christos }
    669          1.1  christos 
    670          1.1  christos 
    671          1.1  christos void ap_mgmt_tx_cb(void *ctx, const u8 *buf, size_t len, u16 stype, int ok)
    672          1.1  christos {
    673          1.1  christos #ifdef NEED_AP_MLME
    674          1.1  christos 	struct wpa_supplicant *wpa_s = ctx;
    675          1.1  christos 	ieee802_11_mgmt_cb(wpa_s->ap_iface->bss[0], buf, len, stype, ok);
    676          1.1  christos #endif /* NEED_AP_MLME */
    677          1.1  christos }
    678          1.1  christos 
    679          1.1  christos 
    680          1.1  christos void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant *wpa_s,
    681          1.1  christos 				const u8 *src_addr, const u8 *buf, size_t len)
    682          1.1  christos {
    683          1.1  christos 	ieee802_1x_receive(wpa_s->ap_iface->bss[0], src_addr, buf, len);
    684          1.1  christos }
    685          1.1  christos 
    686          1.1  christos 
    687          1.1  christos #ifdef CONFIG_WPS
    688          1.1  christos 
    689  1.1.1.1.6.1      yamt int wpa_supplicant_ap_wps_pbc(struct wpa_supplicant *wpa_s, const u8 *bssid,
    690  1.1.1.1.6.1      yamt 			      const u8 *p2p_dev_addr)
    691          1.1  christos {
    692          1.1  christos 	if (!wpa_s->ap_iface)
    693          1.1  christos 		return -1;
    694  1.1.1.1.6.1      yamt 	return hostapd_wps_button_pushed(wpa_s->ap_iface->bss[0],
    695  1.1.1.1.6.1      yamt 					 p2p_dev_addr);
    696  1.1.1.1.6.1      yamt }
    697  1.1.1.1.6.1      yamt 
    698  1.1.1.1.6.1      yamt 
    699  1.1.1.1.6.1      yamt int wpa_supplicant_ap_wps_cancel(struct wpa_supplicant *wpa_s)
    700  1.1.1.1.6.1      yamt {
    701  1.1.1.1.6.1      yamt 	struct wps_registrar *reg;
    702  1.1.1.1.6.1      yamt 	int reg_sel = 0, wps_sta = 0;
    703  1.1.1.1.6.1      yamt 
    704  1.1.1.1.6.1      yamt 	if (!wpa_s->ap_iface || !wpa_s->ap_iface->bss[0]->wps)
    705  1.1.1.1.6.1      yamt 		return -1;
    706  1.1.1.1.6.1      yamt 
    707  1.1.1.1.6.1      yamt 	reg = wpa_s->ap_iface->bss[0]->wps->registrar;
    708  1.1.1.1.6.1      yamt 	reg_sel = wps_registrar_wps_cancel(reg);
    709  1.1.1.1.6.1      yamt 	wps_sta = ap_for_each_sta(wpa_s->ap_iface->bss[0],
    710  1.1.1.1.6.2      yamt 				  ap_sta_wps_cancel, NULL);
    711  1.1.1.1.6.1      yamt 
    712  1.1.1.1.6.1      yamt 	if (!reg_sel && !wps_sta) {
    713  1.1.1.1.6.1      yamt 		wpa_printf(MSG_DEBUG, "No WPS operation in progress at this "
    714  1.1.1.1.6.1      yamt 			   "time");
    715  1.1.1.1.6.1      yamt 		return -1;
    716  1.1.1.1.6.1      yamt 	}
    717  1.1.1.1.6.1      yamt 
    718  1.1.1.1.6.1      yamt 	/*
    719  1.1.1.1.6.1      yamt 	 * There are 2 cases to return wps cancel as success:
    720  1.1.1.1.6.1      yamt 	 * 1. When wps cancel was initiated but no connection has been
    721  1.1.1.1.6.1      yamt 	 *    established with client yet.
    722  1.1.1.1.6.1      yamt 	 * 2. Client is in the middle of exchanging WPS messages.
    723  1.1.1.1.6.1      yamt 	 */
    724  1.1.1.1.6.1      yamt 
    725  1.1.1.1.6.1      yamt 	return 0;
    726          1.1  christos }
    727          1.1  christos 
    728          1.1  christos 
    729          1.1  christos int wpa_supplicant_ap_wps_pin(struct wpa_supplicant *wpa_s, const u8 *bssid,
    730  1.1.1.1.6.2      yamt 			      const char *pin, char *buf, size_t buflen,
    731  1.1.1.1.6.2      yamt 			      int timeout)
    732          1.1  christos {
    733          1.1  christos 	int ret, ret_len = 0;
    734          1.1  christos 
    735          1.1  christos 	if (!wpa_s->ap_iface)
    736          1.1  christos 		return -1;
    737          1.1  christos 
    738          1.1  christos 	if (pin == NULL) {
    739          1.1  christos 		unsigned int rpin = wps_generate_pin();
    740  1.1.1.1.6.1      yamt 		ret_len = os_snprintf(buf, buflen, "%08d", rpin);
    741          1.1  christos 		pin = buf;
    742  1.1.1.1.6.1      yamt 	} else
    743  1.1.1.1.6.1      yamt 		ret_len = os_snprintf(buf, buflen, "%s", pin);
    744          1.1  christos 
    745  1.1.1.1.6.1      yamt 	ret = hostapd_wps_add_pin(wpa_s->ap_iface->bss[0], bssid, "any", pin,
    746  1.1.1.1.6.2      yamt 				  timeout);
    747          1.1  christos 	if (ret)
    748          1.1  christos 		return -1;
    749          1.1  christos 	return ret_len;
    750          1.1  christos }
    751          1.1  christos 
    752  1.1.1.1.6.1      yamt 
    753  1.1.1.1.6.1      yamt static void wpas_wps_ap_pin_timeout(void *eloop_data, void *user_ctx)
    754  1.1.1.1.6.1      yamt {
    755  1.1.1.1.6.1      yamt 	struct wpa_supplicant *wpa_s = eloop_data;
    756  1.1.1.1.6.1      yamt 	wpa_printf(MSG_DEBUG, "WPS: AP PIN timed out");
    757  1.1.1.1.6.1      yamt 	wpas_wps_ap_pin_disable(wpa_s);
    758  1.1.1.1.6.1      yamt }
    759  1.1.1.1.6.1      yamt 
    760  1.1.1.1.6.1      yamt 
    761  1.1.1.1.6.1      yamt static void wpas_wps_ap_pin_enable(struct wpa_supplicant *wpa_s, int timeout)
    762  1.1.1.1.6.1      yamt {
    763  1.1.1.1.6.1      yamt 	struct hostapd_data *hapd;
    764  1.1.1.1.6.1      yamt 
    765  1.1.1.1.6.1      yamt 	if (wpa_s->ap_iface == NULL)
    766  1.1.1.1.6.1      yamt 		return;
    767  1.1.1.1.6.1      yamt 	hapd = wpa_s->ap_iface->bss[0];
    768  1.1.1.1.6.1      yamt 	wpa_printf(MSG_DEBUG, "WPS: Enabling AP PIN (timeout=%d)", timeout);
    769  1.1.1.1.6.1      yamt 	hapd->ap_pin_failures = 0;
    770  1.1.1.1.6.1      yamt 	eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
    771  1.1.1.1.6.1      yamt 	if (timeout > 0)
    772  1.1.1.1.6.1      yamt 		eloop_register_timeout(timeout, 0,
    773  1.1.1.1.6.1      yamt 				       wpas_wps_ap_pin_timeout, wpa_s, NULL);
    774  1.1.1.1.6.1      yamt }
    775  1.1.1.1.6.1      yamt 
    776  1.1.1.1.6.1      yamt 
    777  1.1.1.1.6.1      yamt void wpas_wps_ap_pin_disable(struct wpa_supplicant *wpa_s)
    778  1.1.1.1.6.1      yamt {
    779  1.1.1.1.6.1      yamt 	struct hostapd_data *hapd;
    780  1.1.1.1.6.1      yamt 
    781  1.1.1.1.6.1      yamt 	if (wpa_s->ap_iface == NULL)
    782  1.1.1.1.6.1      yamt 		return;
    783  1.1.1.1.6.1      yamt 	wpa_printf(MSG_DEBUG, "WPS: Disabling AP PIN");
    784  1.1.1.1.6.1      yamt 	hapd = wpa_s->ap_iface->bss[0];
    785  1.1.1.1.6.1      yamt 	os_free(hapd->conf->ap_pin);
    786  1.1.1.1.6.1      yamt 	hapd->conf->ap_pin = NULL;
    787  1.1.1.1.6.1      yamt 	eloop_cancel_timeout(wpas_wps_ap_pin_timeout, wpa_s, NULL);
    788  1.1.1.1.6.1      yamt }
    789  1.1.1.1.6.1      yamt 
    790  1.1.1.1.6.1      yamt 
    791  1.1.1.1.6.1      yamt const char * wpas_wps_ap_pin_random(struct wpa_supplicant *wpa_s, int timeout)
    792  1.1.1.1.6.1      yamt {
    793  1.1.1.1.6.1      yamt 	struct hostapd_data *hapd;
    794  1.1.1.1.6.1      yamt 	unsigned int pin;
    795  1.1.1.1.6.1      yamt 	char pin_txt[9];
    796  1.1.1.1.6.1      yamt 
    797  1.1.1.1.6.1      yamt 	if (wpa_s->ap_iface == NULL)
    798  1.1.1.1.6.1      yamt 		return NULL;
    799  1.1.1.1.6.1      yamt 	hapd = wpa_s->ap_iface->bss[0];
    800  1.1.1.1.6.1      yamt 	pin = wps_generate_pin();
    801  1.1.1.1.6.1      yamt 	os_snprintf(pin_txt, sizeof(pin_txt), "%08u", pin);
    802  1.1.1.1.6.1      yamt 	os_free(hapd->conf->ap_pin);
    803  1.1.1.1.6.1      yamt 	hapd->conf->ap_pin = os_strdup(pin_txt);
    804  1.1.1.1.6.1      yamt 	if (hapd->conf->ap_pin == NULL)
    805  1.1.1.1.6.1      yamt 		return NULL;
    806  1.1.1.1.6.1      yamt 	wpas_wps_ap_pin_enable(wpa_s, timeout);
    807  1.1.1.1.6.1      yamt 
    808  1.1.1.1.6.1      yamt 	return hapd->conf->ap_pin;
    809  1.1.1.1.6.1      yamt }
    810  1.1.1.1.6.1      yamt 
    811  1.1.1.1.6.1      yamt 
    812  1.1.1.1.6.1      yamt const char * wpas_wps_ap_pin_get(struct wpa_supplicant *wpa_s)
    813  1.1.1.1.6.1      yamt {
    814  1.1.1.1.6.1      yamt 	struct hostapd_data *hapd;
    815  1.1.1.1.6.1      yamt 	if (wpa_s->ap_iface == NULL)
    816  1.1.1.1.6.1      yamt 		return NULL;
    817  1.1.1.1.6.1      yamt 	hapd = wpa_s->ap_iface->bss[0];
    818  1.1.1.1.6.1      yamt 	return hapd->conf->ap_pin;
    819  1.1.1.1.6.1      yamt }
    820  1.1.1.1.6.1      yamt 
    821  1.1.1.1.6.1      yamt 
    822  1.1.1.1.6.1      yamt int wpas_wps_ap_pin_set(struct wpa_supplicant *wpa_s, const char *pin,
    823  1.1.1.1.6.1      yamt 			int timeout)
    824  1.1.1.1.6.1      yamt {
    825  1.1.1.1.6.1      yamt 	struct hostapd_data *hapd;
    826  1.1.1.1.6.1      yamt 	char pin_txt[9];
    827  1.1.1.1.6.1      yamt 	int ret;
    828  1.1.1.1.6.1      yamt 
    829  1.1.1.1.6.1      yamt 	if (wpa_s->ap_iface == NULL)
    830  1.1.1.1.6.1      yamt 		return -1;
    831  1.1.1.1.6.1      yamt 	hapd = wpa_s->ap_iface->bss[0];
    832  1.1.1.1.6.1      yamt 	ret = os_snprintf(pin_txt, sizeof(pin_txt), "%s", pin);
    833  1.1.1.1.6.1      yamt 	if (ret < 0 || ret >= (int) sizeof(pin_txt))
    834  1.1.1.1.6.1      yamt 		return -1;
    835  1.1.1.1.6.1      yamt 	os_free(hapd->conf->ap_pin);
    836  1.1.1.1.6.1      yamt 	hapd->conf->ap_pin = os_strdup(pin_txt);
    837  1.1.1.1.6.1      yamt 	if (hapd->conf->ap_pin == NULL)
    838  1.1.1.1.6.1      yamt 		return -1;
    839  1.1.1.1.6.1      yamt 	wpas_wps_ap_pin_enable(wpa_s, timeout);
    840  1.1.1.1.6.1      yamt 
    841  1.1.1.1.6.1      yamt 	return 0;
    842  1.1.1.1.6.1      yamt }
    843  1.1.1.1.6.1      yamt 
    844  1.1.1.1.6.1      yamt 
    845  1.1.1.1.6.1      yamt void wpa_supplicant_ap_pwd_auth_fail(struct wpa_supplicant *wpa_s)
    846  1.1.1.1.6.1      yamt {
    847  1.1.1.1.6.1      yamt 	struct hostapd_data *hapd;
    848  1.1.1.1.6.1      yamt 
    849  1.1.1.1.6.1      yamt 	if (wpa_s->ap_iface == NULL)
    850  1.1.1.1.6.1      yamt 		return;
    851  1.1.1.1.6.1      yamt 	hapd = wpa_s->ap_iface->bss[0];
    852  1.1.1.1.6.1      yamt 
    853  1.1.1.1.6.1      yamt 	/*
    854  1.1.1.1.6.1      yamt 	 * Registrar failed to prove its knowledge of the AP PIN. Disable AP
    855  1.1.1.1.6.1      yamt 	 * PIN if this happens multiple times to slow down brute force attacks.
    856  1.1.1.1.6.1      yamt 	 */
    857  1.1.1.1.6.1      yamt 	hapd->ap_pin_failures++;
    858  1.1.1.1.6.1      yamt 	wpa_printf(MSG_DEBUG, "WPS: AP PIN authentication failure number %u",
    859  1.1.1.1.6.1      yamt 		   hapd->ap_pin_failures);
    860  1.1.1.1.6.1      yamt 	if (hapd->ap_pin_failures < 3)
    861  1.1.1.1.6.1      yamt 		return;
    862  1.1.1.1.6.1      yamt 
    863  1.1.1.1.6.1      yamt 	wpa_printf(MSG_DEBUG, "WPS: Disable AP PIN");
    864  1.1.1.1.6.1      yamt 	hapd->ap_pin_failures = 0;
    865  1.1.1.1.6.1      yamt 	os_free(hapd->conf->ap_pin);
    866  1.1.1.1.6.1      yamt 	hapd->conf->ap_pin = NULL;
    867  1.1.1.1.6.1      yamt }
    868  1.1.1.1.6.1      yamt 
    869          1.1  christos #endif /* CONFIG_WPS */
    870          1.1  christos 
    871          1.1  christos 
    872          1.1  christos #ifdef CONFIG_CTRL_IFACE
    873          1.1  christos 
    874          1.1  christos int ap_ctrl_iface_sta_first(struct wpa_supplicant *wpa_s,
    875          1.1  christos 			    char *buf, size_t buflen)
    876          1.1  christos {
    877          1.1  christos 	if (wpa_s->ap_iface == NULL)
    878          1.1  christos 		return -1;
    879          1.1  christos 	return hostapd_ctrl_iface_sta_first(wpa_s->ap_iface->bss[0],
    880          1.1  christos 					    buf, buflen);
    881          1.1  christos }
    882          1.1  christos 
    883          1.1  christos 
    884          1.1  christos int ap_ctrl_iface_sta(struct wpa_supplicant *wpa_s, const char *txtaddr,
    885          1.1  christos 		      char *buf, size_t buflen)
    886          1.1  christos {
    887          1.1  christos 	if (wpa_s->ap_iface == NULL)
    888          1.1  christos 		return -1;
    889          1.1  christos 	return hostapd_ctrl_iface_sta(wpa_s->ap_iface->bss[0], txtaddr,
    890          1.1  christos 				      buf, buflen);
    891          1.1  christos }
    892          1.1  christos 
    893          1.1  christos 
    894          1.1  christos int ap_ctrl_iface_sta_next(struct wpa_supplicant *wpa_s, const char *txtaddr,
    895          1.1  christos 			   char *buf, size_t buflen)
    896          1.1  christos {
    897          1.1  christos 	if (wpa_s->ap_iface == NULL)
    898          1.1  christos 		return -1;
    899          1.1  christos 	return hostapd_ctrl_iface_sta_next(wpa_s->ap_iface->bss[0], txtaddr,
    900          1.1  christos 					   buf, buflen);
    901          1.1  christos }
    902          1.1  christos 
    903          1.1  christos 
    904  1.1.1.1.6.2      yamt int ap_ctrl_iface_sta_disassociate(struct wpa_supplicant *wpa_s,
    905  1.1.1.1.6.2      yamt 				   const char *txtaddr)
    906  1.1.1.1.6.2      yamt {
    907  1.1.1.1.6.2      yamt 	if (wpa_s->ap_iface == NULL)
    908  1.1.1.1.6.2      yamt 		return -1;
    909  1.1.1.1.6.2      yamt 	return hostapd_ctrl_iface_disassociate(wpa_s->ap_iface->bss[0],
    910  1.1.1.1.6.2      yamt 					       txtaddr);
    911  1.1.1.1.6.2      yamt }
    912  1.1.1.1.6.2      yamt 
    913  1.1.1.1.6.2      yamt 
    914  1.1.1.1.6.2      yamt int ap_ctrl_iface_sta_deauthenticate(struct wpa_supplicant *wpa_s,
    915  1.1.1.1.6.2      yamt 				     const char *txtaddr)
    916  1.1.1.1.6.2      yamt {
    917  1.1.1.1.6.2      yamt 	if (wpa_s->ap_iface == NULL)
    918  1.1.1.1.6.2      yamt 		return -1;
    919  1.1.1.1.6.2      yamt 	return hostapd_ctrl_iface_deauthenticate(wpa_s->ap_iface->bss[0],
    920  1.1.1.1.6.2      yamt 						 txtaddr);
    921  1.1.1.1.6.2      yamt }
    922  1.1.1.1.6.2      yamt 
    923  1.1.1.1.6.2      yamt 
    924          1.1  christos int ap_ctrl_iface_wpa_get_status(struct wpa_supplicant *wpa_s, char *buf,
    925          1.1  christos 				 size_t buflen, int verbose)
    926          1.1  christos {
    927          1.1  christos 	char *pos = buf, *end = buf + buflen;
    928          1.1  christos 	int ret;
    929          1.1  christos 	struct hostapd_bss_config *conf;
    930          1.1  christos 
    931          1.1  christos 	if (wpa_s->ap_iface == NULL)
    932          1.1  christos 		return -1;
    933          1.1  christos 
    934          1.1  christos 	conf = wpa_s->ap_iface->bss[0]->conf;
    935          1.1  christos 	if (conf->wpa == 0)
    936          1.1  christos 		return 0;
    937          1.1  christos 
    938          1.1  christos 	ret = os_snprintf(pos, end - pos,
    939          1.1  christos 			  "pairwise_cipher=%s\n"
    940          1.1  christos 			  "group_cipher=%s\n"
    941          1.1  christos 			  "key_mgmt=%s\n",
    942          1.1  christos 			  wpa_cipher_txt(conf->rsn_pairwise),
    943          1.1  christos 			  wpa_cipher_txt(conf->wpa_group),
    944          1.1  christos 			  wpa_key_mgmt_txt(conf->wpa_key_mgmt,
    945          1.1  christos 					   conf->wpa));
    946          1.1  christos 	if (ret < 0 || ret >= end - pos)
    947          1.1  christos 		return pos - buf;
    948          1.1  christos 	pos += ret;
    949          1.1  christos 	return pos - buf;
    950          1.1  christos }
    951          1.1  christos 
    952          1.1  christos #endif /* CONFIG_CTRL_IFACE */
    953          1.1  christos 
    954          1.1  christos 
    955  1.1.1.1.6.1      yamt int wpa_supplicant_ap_update_beacon(struct wpa_supplicant *wpa_s)
    956  1.1.1.1.6.1      yamt {
    957  1.1.1.1.6.1      yamt 	struct hostapd_iface *iface = wpa_s->ap_iface;
    958  1.1.1.1.6.1      yamt 	struct wpa_ssid *ssid = wpa_s->current_ssid;
    959  1.1.1.1.6.1      yamt 	struct hostapd_data *hapd;
    960  1.1.1.1.6.1      yamt 
    961  1.1.1.1.6.1      yamt 	if (ssid == NULL || wpa_s->ap_iface == NULL ||
    962  1.1.1.1.6.1      yamt 	    ssid->mode == WPAS_MODE_INFRA ||
    963  1.1.1.1.6.1      yamt 	    ssid->mode == WPAS_MODE_IBSS)
    964  1.1.1.1.6.1      yamt 		return -1;
    965  1.1.1.1.6.1      yamt 
    966  1.1.1.1.6.1      yamt #ifdef CONFIG_P2P
    967  1.1.1.1.6.1      yamt 	if (ssid->mode == WPAS_MODE_P2P_GO)
    968  1.1.1.1.6.1      yamt 		iface->conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER;
    969  1.1.1.1.6.1      yamt 	else if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)
    970  1.1.1.1.6.1      yamt 		iface->conf->bss[0].p2p = P2P_ENABLED | P2P_GROUP_OWNER |
    971  1.1.1.1.6.1      yamt 			P2P_GROUP_FORMATION;
    972  1.1.1.1.6.1      yamt #endif /* CONFIG_P2P */
    973  1.1.1.1.6.1      yamt 
    974  1.1.1.1.6.1      yamt 	hapd = iface->bss[0];
    975  1.1.1.1.6.1      yamt 	if (hapd->drv_priv == NULL)
    976  1.1.1.1.6.1      yamt 		return -1;
    977  1.1.1.1.6.1      yamt 	ieee802_11_set_beacons(iface);
    978  1.1.1.1.6.1      yamt 	hostapd_set_ap_wps_ie(hapd);
    979  1.1.1.1.6.1      yamt 
    980  1.1.1.1.6.1      yamt 	return 0;
    981  1.1.1.1.6.1      yamt }
    982  1.1.1.1.6.1      yamt 
    983  1.1.1.1.6.1      yamt 
    984  1.1.1.1.6.2      yamt void wpas_ap_ch_switch(struct wpa_supplicant *wpa_s, int freq, int ht,
    985  1.1.1.1.6.2      yamt 		       int offset)
    986  1.1.1.1.6.2      yamt {
    987  1.1.1.1.6.2      yamt 	if (!wpa_s->ap_iface)
    988  1.1.1.1.6.2      yamt 		return;
    989  1.1.1.1.6.2      yamt 
    990  1.1.1.1.6.2      yamt 	wpa_s->assoc_freq = freq;
    991  1.1.1.1.6.2      yamt 	hostapd_event_ch_switch(wpa_s->ap_iface->bss[0], freq, ht, offset);
    992  1.1.1.1.6.2      yamt }
    993  1.1.1.1.6.2      yamt 
    994  1.1.1.1.6.2      yamt 
    995          1.1  christos int wpa_supplicant_ap_mac_addr_filter(struct wpa_supplicant *wpa_s,
    996          1.1  christos 				      const u8 *addr)
    997          1.1  christos {
    998          1.1  christos 	struct hostapd_data *hapd;
    999          1.1  christos 	struct hostapd_bss_config *conf;
   1000          1.1  christos 
   1001          1.1  christos 	if (!wpa_s->ap_iface)
   1002          1.1  christos 		return -1;
   1003          1.1  christos 
   1004          1.1  christos 	if (addr)
   1005          1.1  christos 		wpa_printf(MSG_DEBUG, "AP: Set MAC address filter: " MACSTR,
   1006          1.1  christos 			   MAC2STR(addr));
   1007          1.1  christos 	else
   1008          1.1  christos 		wpa_printf(MSG_DEBUG, "AP: Clear MAC address filter");
   1009          1.1  christos 
   1010          1.1  christos 	hapd = wpa_s->ap_iface->bss[0];
   1011          1.1  christos 	conf = hapd->conf;
   1012          1.1  christos 
   1013          1.1  christos 	os_free(conf->accept_mac);
   1014          1.1  christos 	conf->accept_mac = NULL;
   1015          1.1  christos 	conf->num_accept_mac = 0;
   1016          1.1  christos 	os_free(conf->deny_mac);
   1017          1.1  christos 	conf->deny_mac = NULL;
   1018          1.1  christos 	conf->num_deny_mac = 0;
   1019          1.1  christos 
   1020          1.1  christos 	if (addr == NULL) {
   1021          1.1  christos 		conf->macaddr_acl = ACCEPT_UNLESS_DENIED;
   1022          1.1  christos 		return 0;
   1023          1.1  christos 	}
   1024          1.1  christos 
   1025          1.1  christos 	conf->macaddr_acl = DENY_UNLESS_ACCEPTED;
   1026          1.1  christos 	conf->accept_mac = os_zalloc(sizeof(struct mac_acl_entry));
   1027          1.1  christos 	if (conf->accept_mac == NULL)
   1028          1.1  christos 		return -1;
   1029          1.1  christos 	os_memcpy(conf->accept_mac[0].addr, addr, ETH_ALEN);
   1030          1.1  christos 	conf->num_accept_mac = 1;
   1031          1.1  christos 
   1032          1.1  christos 	return 0;
   1033          1.1  christos }
   1034