18d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt/*
28d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * WPA Supplicant - Basic AP mode support routines
38d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * Copyright (c) 2003-2009, Jouni Malinen <j@w1.fi>
48d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt * Copyright (c) 2009, Atheros Communications
58d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt *
6c5ec7f57ead87efa365800228aa0b09a12d9e6c4Dmitry Shmidt * This software may be distributed under the terms of the BSD license.
7c5ec7f57ead87efa365800228aa0b09a12d9e6c4Dmitry Shmidt * See README for more details.
88d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt */
98d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt
108d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#include "utils/includes.h"
118d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt
128d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#include "utils/common.h"
138d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#include "utils/eloop.h"
148d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#include "utils/uuid.h"
158d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#include "common/ieee802_11_defs.h"
168d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#include "common/wpa_ctrl.h"
17b7b4d0ec07161a6d76c40ba7ef1306e82fbb7e15Dmitry Shmidt#include "eapol_supp/eapol_supp_sm.h"
18cf32e60fa7e0d33fe1551a6dba8dcbbec47ea50eDmitry Shmidt#include "crypto/dh_group5.h"
198d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#include "ap/hostapd.h"
208d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#include "ap/ap_config.h"
218d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#include "ap/ap_drv_ops.h"
221f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt#ifdef NEED_AP_MLME
238d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#include "ap/ieee802_11.h"
248d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#endif /* NEED_AP_MLME */
258d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#include "ap/beacon.h"
268d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#include "ap/ieee802_1x.h"
278d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#include "ap/wps_hostapd.h"
288d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#include "ap/ctrl_iface_ap.h"
298d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#include "wps/wps.h"
308d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#include "common/ieee802_11_defs.h"
318d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#include "config_ssid.h"
328d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#include "config.h"
338d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#include "wpa_supplicant_i.h"
348d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#include "driver_i.h"
358d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#include "p2p_supplicant.h"
368d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#include "ap.h"
378d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#include "ap/sta_info.h"
388d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#include "notify.h"
398d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt
408d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt
418d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#ifdef CONFIG_WPS
428d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic void wpas_wps_ap_pin_timeout(void *eloop_data, void *user_ctx);
438d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#endif /* CONFIG_WPS */
448d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt
458d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt
4668d0e3ed07847339aedfac8e02f50db68c702e52Dmitry Shmidt#ifdef CONFIG_IEEE80211N
4768d0e3ed07847339aedfac8e02f50db68c702e52Dmitry Shmidtstatic void wpas_conf_ap_vht(struct wpa_supplicant *wpa_s,
4868d0e3ed07847339aedfac8e02f50db68c702e52Dmitry Shmidt			     struct hostapd_config *conf,
4968d0e3ed07847339aedfac8e02f50db68c702e52Dmitry Shmidt			     struct hostapd_hw_modes *mode)
5068d0e3ed07847339aedfac8e02f50db68c702e52Dmitry Shmidt{
5121de214b4ba4271ca20843f3b8fba9f1501b2a89Dmitry Shmidt#ifdef CONFIG_P2P
5268d0e3ed07847339aedfac8e02f50db68c702e52Dmitry Shmidt	u8 center_chan = 0;
5368d0e3ed07847339aedfac8e02f50db68c702e52Dmitry Shmidt	u8 channel = conf->channel;
5468d0e3ed07847339aedfac8e02f50db68c702e52Dmitry Shmidt
5568d0e3ed07847339aedfac8e02f50db68c702e52Dmitry Shmidt	if (!conf->secondary_channel)
5668d0e3ed07847339aedfac8e02f50db68c702e52Dmitry Shmidt		goto no_vht;
5768d0e3ed07847339aedfac8e02f50db68c702e52Dmitry Shmidt
5868d0e3ed07847339aedfac8e02f50db68c702e52Dmitry Shmidt	center_chan = wpas_p2p_get_vht80_center(wpa_s, mode, channel);
5968d0e3ed07847339aedfac8e02f50db68c702e52Dmitry Shmidt	if (!center_chan)
6068d0e3ed07847339aedfac8e02f50db68c702e52Dmitry Shmidt		goto no_vht;
6168d0e3ed07847339aedfac8e02f50db68c702e52Dmitry Shmidt
6268d0e3ed07847339aedfac8e02f50db68c702e52Dmitry Shmidt	/* Use 80 MHz channel */
6368d0e3ed07847339aedfac8e02f50db68c702e52Dmitry Shmidt	conf->vht_oper_chwidth = 1;
6468d0e3ed07847339aedfac8e02f50db68c702e52Dmitry Shmidt	conf->vht_oper_centr_freq_seg0_idx = center_chan;
6568d0e3ed07847339aedfac8e02f50db68c702e52Dmitry Shmidt	return;
6668d0e3ed07847339aedfac8e02f50db68c702e52Dmitry Shmidt
6768d0e3ed07847339aedfac8e02f50db68c702e52Dmitry Shmidtno_vht:
6868d0e3ed07847339aedfac8e02f50db68c702e52Dmitry Shmidt	conf->vht_oper_centr_freq_seg0_idx =
6968d0e3ed07847339aedfac8e02f50db68c702e52Dmitry Shmidt		channel + conf->secondary_channel * 2;
7021de214b4ba4271ca20843f3b8fba9f1501b2a89Dmitry Shmidt#else /* CONFIG_P2P */
7121de214b4ba4271ca20843f3b8fba9f1501b2a89Dmitry Shmidt	conf->vht_oper_centr_freq_seg0_idx =
7221de214b4ba4271ca20843f3b8fba9f1501b2a89Dmitry Shmidt		conf->channel + conf->secondary_channel * 2;
7321de214b4ba4271ca20843f3b8fba9f1501b2a89Dmitry Shmidt#endif /* CONFIG_P2P */
7468d0e3ed07847339aedfac8e02f50db68c702e52Dmitry Shmidt}
7568d0e3ed07847339aedfac8e02f50db68c702e52Dmitry Shmidt#endif /* CONFIG_IEEE80211N */
7668d0e3ed07847339aedfac8e02f50db68c702e52Dmitry Shmidt
7768d0e3ed07847339aedfac8e02f50db68c702e52Dmitry Shmidt
788d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidtstatic int wpa_supplicant_conf_ap(struct wpa_supplicant *wpa_s,
798d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt				  struct wpa_ssid *ssid,
808d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt				  struct hostapd_config *conf)
818d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt{
82cce06667447b5aec83452adb0c15100ada531095Dmitry Shmidt	struct hostapd_bss_config *bss = conf->bss[0];
838d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt
848d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt	conf->driver = wpa_s->driver;
858d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt
868d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt	os_strlcpy(bss->iface, wpa_s->ifname, sizeof(bss->iface));
878d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt
88b7b4d0ec07161a6d76c40ba7ef1306e82fbb7e15Dmitry Shmidt	conf->hw_mode = ieee80211_freq_to_chan(ssid->frequency,
89b7b4d0ec07161a6d76c40ba7ef1306e82fbb7e15Dmitry Shmidt					       &conf->channel);
90b7b4d0ec07161a6d76c40ba7ef1306e82fbb7e15Dmitry Shmidt	if (conf->hw_mode == NUM_HOSTAPD_MODES) {
91b7b4d0ec07161a6d76c40ba7ef1306e82fbb7e15Dmitry Shmidt		wpa_printf(MSG_ERROR, "Unsupported AP mode frequency: %d MHz",
92b7b4d0ec07161a6d76c40ba7ef1306e82fbb7e15Dmitry Shmidt			   ssid->frequency);
93b7b4d0ec07161a6d76c40ba7ef1306e82fbb7e15Dmitry Shmidt		return -1;
948d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt	}
958d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt
96c55524ad84d13014e8019491c2b17e5dcf13545aDmitry Shmidt	/* TODO: enable HT40 if driver supports it;
978d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt	 * drop to 11b if driver does not support 11g */
988d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt
99c55524ad84d13014e8019491c2b17e5dcf13545aDmitry Shmidt#ifdef CONFIG_IEEE80211N
100c55524ad84d13014e8019491c2b17e5dcf13545aDmitry Shmidt	/*
1011f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt	 * Enable HT20 if the driver supports it, by setting conf->ieee80211n
1021f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt	 * and a mask of allowed capabilities within conf->ht_capab.
103c55524ad84d13014e8019491c2b17e5dcf13545aDmitry Shmidt	 * Using default config settings for: conf->ht_op_mode_fixed,
1041f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt	 * conf->secondary_channel, conf->require_ht
105c55524ad84d13014e8019491c2b17e5dcf13545aDmitry Shmidt	 */
1061f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt	if (wpa_s->hw.modes) {
107c55524ad84d13014e8019491c2b17e5dcf13545aDmitry Shmidt		struct hostapd_hw_modes *mode = NULL;
10804949598a23f501be6eec21697465fd46a28840aDmitry Shmidt		int i, no_ht = 0;
1091f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt		for (i = 0; i < wpa_s->hw.num_modes; i++) {
1101f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt			if (wpa_s->hw.modes[i].mode == conf->hw_mode) {
1111f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt				mode = &wpa_s->hw.modes[i];
112c55524ad84d13014e8019491c2b17e5dcf13545aDmitry Shmidt				break;
113c55524ad84d13014e8019491c2b17e5dcf13545aDmitry Shmidt			}
114c55524ad84d13014e8019491c2b17e5dcf13545aDmitry Shmidt		}
11504949598a23f501be6eec21697465fd46a28840aDmitry Shmidt
11604949598a23f501be6eec21697465fd46a28840aDmitry Shmidt#ifdef CONFIG_HT_OVERRIDES
11704949598a23f501be6eec21697465fd46a28840aDmitry Shmidt		if (ssid->disable_ht) {
11804949598a23f501be6eec21697465fd46a28840aDmitry Shmidt			conf->ieee80211n = 0;
11904949598a23f501be6eec21697465fd46a28840aDmitry Shmidt			conf->ht_capab = 0;
12004949598a23f501be6eec21697465fd46a28840aDmitry Shmidt			no_ht = 1;
12104949598a23f501be6eec21697465fd46a28840aDmitry Shmidt		}
12204949598a23f501be6eec21697465fd46a28840aDmitry Shmidt#endif /* CONFIG_HT_OVERRIDES */
12304949598a23f501be6eec21697465fd46a28840aDmitry Shmidt
12404949598a23f501be6eec21697465fd46a28840aDmitry Shmidt		if (!no_ht && mode && mode->ht_capab) {
125c55524ad84d13014e8019491c2b17e5dcf13545aDmitry Shmidt			conf->ieee80211n = 1;
12661d9df3e62aaa0e87ad05452fcb95142159a17b6Dmitry Shmidt#ifdef CONFIG_P2P
12761d9df3e62aaa0e87ad05452fcb95142159a17b6Dmitry Shmidt			if (conf->hw_mode == HOSTAPD_MODE_IEEE80211A &&
12861d9df3e62aaa0e87ad05452fcb95142159a17b6Dmitry Shmidt			    (mode->ht_capab &
12961d9df3e62aaa0e87ad05452fcb95142159a17b6Dmitry Shmidt			     HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) &&
13061d9df3e62aaa0e87ad05452fcb95142159a17b6Dmitry Shmidt			    ssid->ht40)
13161d9df3e62aaa0e87ad05452fcb95142159a17b6Dmitry Shmidt				conf->secondary_channel =
13261d9df3e62aaa0e87ad05452fcb95142159a17b6Dmitry Shmidt					wpas_p2p_get_ht40_mode(wpa_s, mode,
13361d9df3e62aaa0e87ad05452fcb95142159a17b6Dmitry Shmidt							       conf->channel);
13461d9df3e62aaa0e87ad05452fcb95142159a17b6Dmitry Shmidt			if (conf->secondary_channel)
13561d9df3e62aaa0e87ad05452fcb95142159a17b6Dmitry Shmidt				conf->ht_capab |=
13661d9df3e62aaa0e87ad05452fcb95142159a17b6Dmitry Shmidt					HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
13761d9df3e62aaa0e87ad05452fcb95142159a17b6Dmitry Shmidt#endif /* CONFIG_P2P */
1381f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt
1391f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt			/*
1401f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt			 * white-list capabilities that won't cause issues
1411f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt			 * to connecting stations, while leaving the current
1421f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt			 * capabilities intact (currently disabled SMPS).
1431f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt			 */
1441f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt			conf->ht_capab |= mode->ht_capab &
1451f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt				(HT_CAP_INFO_GREEN_FIELD |
1461f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt				 HT_CAP_INFO_SHORT_GI20MHZ |
1471f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt				 HT_CAP_INFO_SHORT_GI40MHZ |
1481f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt				 HT_CAP_INFO_RX_STBC_MASK |
1491f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt				 HT_CAP_INFO_MAX_AMSDU_SIZE);
15068d0e3ed07847339aedfac8e02f50db68c702e52Dmitry Shmidt
15168d0e3ed07847339aedfac8e02f50db68c702e52Dmitry Shmidt			if (mode->vht_capab && ssid->vht) {
15268d0e3ed07847339aedfac8e02f50db68c702e52Dmitry Shmidt				conf->ieee80211ac = 1;
15368d0e3ed07847339aedfac8e02f50db68c702e52Dmitry Shmidt				wpas_conf_ap_vht(wpa_s, conf, mode);
15468d0e3ed07847339aedfac8e02f50db68c702e52Dmitry Shmidt			}
1551f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt		}
156c55524ad84d13014e8019491c2b17e5dcf13545aDmitry Shmidt	}
157c55524ad84d13014e8019491c2b17e5dcf13545aDmitry Shmidt#endif /* CONFIG_IEEE80211N */
158c55524ad84d13014e8019491c2b17e5dcf13545aDmitry Shmidt
1598d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#ifdef CONFIG_P2P
16034af306c42b7ccf956508e7cd23f0ba90606e360Dmitry Shmidt	if (conf->hw_mode == HOSTAPD_MODE_IEEE80211G &&
16134af306c42b7ccf956508e7cd23f0ba90606e360Dmitry Shmidt	    (ssid->mode == WPAS_MODE_P2P_GO ||
16234af306c42b7ccf956508e7cd23f0ba90606e360Dmitry Shmidt	     ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION)) {
1638d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt		/* Remove 802.11b rates from supported and basic rate sets */
1648d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt		int *list = os_malloc(4 * sizeof(int));
1658d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt		if (list) {
1668d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt			list[0] = 60;
1678d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt			list[1] = 120;
1688d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt			list[2] = 240;
1698d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt			list[3] = -1;
1708d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt		}
1718d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt		conf->basic_rates = list;
1728d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt
1738d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt		list = os_malloc(9 * sizeof(int));
1748d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt		if (list) {
1758d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt			list[0] = 60;
1768d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt			list[1] = 90;
1778d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt			list[2] = 120;
1788d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt			list[3] = 180;
1798d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt			list[4] = 240;
1808d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt			list[5] = 360;
1818d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt			list[6] = 480;
1828d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt			list[7] = 540;
1838d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt			list[8] = -1;
1848d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt		}
1858d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt		conf->supported_rates = list;
1868d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt	}
1871f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt
1881f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt	bss->isolate = !wpa_s->conf->p2p_intra_bss;
189391c59f0632df8db1c325da1d31d479b2eedce45Dmitry Shmidt	bss->force_per_enrollee_psk = wpa_s->global->p2p_per_sta_psk;
190cf32e60fa7e0d33fe1551a6dba8dcbbec47ea50eDmitry Shmidt
191cf32e60fa7e0d33fe1551a6dba8dcbbec47ea50eDmitry Shmidt	if (ssid->p2p_group) {
192cf32e60fa7e0d33fe1551a6dba8dcbbec47ea50eDmitry Shmidt		os_memcpy(bss->ip_addr_go, wpa_s->parent->conf->ip_addr_go, 4);
193cf32e60fa7e0d33fe1551a6dba8dcbbec47ea50eDmitry Shmidt		os_memcpy(bss->ip_addr_mask, wpa_s->parent->conf->ip_addr_mask,
194cf32e60fa7e0d33fe1551a6dba8dcbbec47ea50eDmitry Shmidt			  4);
195cf32e60fa7e0d33fe1551a6dba8dcbbec47ea50eDmitry Shmidt		os_memcpy(bss->ip_addr_start,
196cf32e60fa7e0d33fe1551a6dba8dcbbec47ea50eDmitry Shmidt			  wpa_s->parent->conf->ip_addr_start, 4);
197cf32e60fa7e0d33fe1551a6dba8dcbbec47ea50eDmitry Shmidt		os_memcpy(bss->ip_addr_end, wpa_s->parent->conf->ip_addr_end,
198cf32e60fa7e0d33fe1551a6dba8dcbbec47ea50eDmitry Shmidt			  4);
199cf32e60fa7e0d33fe1551a6dba8dcbbec47ea50eDmitry Shmidt	}
2008d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#endif /* CONFIG_P2P */
2018d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt
2028d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt	if (ssid->ssid_len == 0) {
2038d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt		wpa_printf(MSG_ERROR, "No SSID configured for AP mode");
2048d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt		return -1;
2058d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt	}
2068d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt	os_memcpy(bss->ssid.ssid, ssid->ssid, ssid->ssid_len);
2078d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt	bss->ssid.ssid_len = ssid->ssid_len;
2088d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt	bss->ssid.ssid_set = 1;
2098d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt
21004949598a23f501be6eec21697465fd46a28840aDmitry Shmidt	bss->ignore_broadcast_ssid = ssid->ignore_broadcast_ssid;
21104949598a23f501be6eec21697465fd46a28840aDmitry Shmidt
2121f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt	if (ssid->auth_alg)
2131f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt		bss->auth_algs = ssid->auth_alg;
2141f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt
2158d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt	if (wpa_key_mgmt_wpa_psk(ssid->key_mgmt))
2168d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt		bss->wpa = ssid->proto;
2178d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt	bss->wpa_key_mgmt = ssid->key_mgmt;
2188d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt	bss->wpa_pairwise = ssid->pairwise_cipher;
219d5e4923d04122f81300fa68fb07d64ede28fd44dDmitry Shmidt	if (ssid->psk_set) {
2208d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt		os_free(bss->ssid.wpa_psk);
2218d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt		bss->ssid.wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
2228d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt		if (bss->ssid.wpa_psk == NULL)
2238d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt			return -1;
2248d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt		os_memcpy(bss->ssid.wpa_psk->psk, ssid->psk, PMK_LEN);
2258d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt		bss->ssid.wpa_psk->group = 1;
226d5e4923d04122f81300fa68fb07d64ede28fd44dDmitry Shmidt	} else if (ssid->passphrase) {
227d5e4923d04122f81300fa68fb07d64ede28fd44dDmitry Shmidt		bss->ssid.wpa_passphrase = os_strdup(ssid->passphrase);
2281f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt	} else if (ssid->wep_key_len[0] || ssid->wep_key_len[1] ||
2291f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt		   ssid->wep_key_len[2] || ssid->wep_key_len[3]) {
2301f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt		struct hostapd_wep_keys *wep = &bss->ssid.wep;
2311f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt		int i;
2321f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt		for (i = 0; i < NUM_WEP_KEYS; i++) {
2331f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt			if (ssid->wep_key_len[i] == 0)
2341f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt				continue;
2351f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt			wep->key[i] = os_malloc(ssid->wep_key_len[i]);
2361f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt			if (wep->key[i] == NULL)
2371f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt				return -1;
2381f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt			os_memcpy(wep->key[i], ssid->wep_key[i],
2391f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt				  ssid->wep_key_len[i]);
2401f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt			wep->len[i] = ssid->wep_key_len[i];
2411f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt		}
2421f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt		wep->idx = ssid->wep_tx_keyidx;
2431f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt		wep->keys_set = 1;
2448d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt	}
2458d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt
24604949598a23f501be6eec21697465fd46a28840aDmitry Shmidt	if (ssid->ap_max_inactivity)
24704949598a23f501be6eec21697465fd46a28840aDmitry Shmidt		bss->ap_max_inactivity = ssid->ap_max_inactivity;
24804949598a23f501be6eec21697465fd46a28840aDmitry Shmidt
24904949598a23f501be6eec21697465fd46a28840aDmitry Shmidt	if (ssid->dtim_period)
25004949598a23f501be6eec21697465fd46a28840aDmitry Shmidt		bss->dtim_period = ssid->dtim_period;
2517a5e50a0554bee77a9da492ea3d86f46147f1671Dmitry Shmidt	else if (wpa_s->conf->dtim_period)
2527a5e50a0554bee77a9da492ea3d86f46147f1671Dmitry Shmidt		bss->dtim_period = wpa_s->conf->dtim_period;
2537a5e50a0554bee77a9da492ea3d86f46147f1671Dmitry Shmidt
2547a5e50a0554bee77a9da492ea3d86f46147f1671Dmitry Shmidt	if (ssid->beacon_int)
2557a5e50a0554bee77a9da492ea3d86f46147f1671Dmitry Shmidt		conf->beacon_int = ssid->beacon_int;
2567a5e50a0554bee77a9da492ea3d86f46147f1671Dmitry Shmidt	else if (wpa_s->conf->beacon_int)
2577a5e50a0554bee77a9da492ea3d86f46147f1671Dmitry Shmidt		conf->beacon_int = wpa_s->conf->beacon_int;
25804949598a23f501be6eec21697465fd46a28840aDmitry Shmidt
259a54fa5fb807eaeff45464139b5a7759f060cec68Dmitry Shmidt	if ((bss->wpa & 2) && bss->rsn_pairwise == 0)
260a54fa5fb807eaeff45464139b5a7759f060cec68Dmitry Shmidt		bss->rsn_pairwise = bss->wpa_pairwise;
261a54fa5fb807eaeff45464139b5a7759f060cec68Dmitry Shmidt	bss->wpa_group = wpa_select_ap_group_cipher(bss->wpa, bss->wpa_pairwise,
262a54fa5fb807eaeff45464139b5a7759f060cec68Dmitry Shmidt						    bss->rsn_pairwise);
2638d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt
2648d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt	if (bss->wpa && bss->ieee802_1x)
2658d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt		bss->ssid.security_policy = SECURITY_WPA;
2668d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt	else if (bss->wpa)
2678d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt		bss->ssid.security_policy = SECURITY_WPA_PSK;
2688d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt	else if (bss->ieee802_1x) {
2691f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt		int cipher = WPA_CIPHER_NONE;
2708d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt		bss->ssid.security_policy = SECURITY_IEEE_802_1X;
2718d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt		bss->ssid.wep.default_len = bss->default_wep_key_len;
2721f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt		if (bss->default_wep_key_len)
2731f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt			cipher = bss->default_wep_key_len >= 13 ?
2741f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt				WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
2751f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt		bss->wpa_group = cipher;
2761f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt		bss->wpa_pairwise = cipher;
2771f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt		bss->rsn_pairwise = cipher;
2781f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt	} else if (bss->ssid.wep.keys_set) {
2791f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt		int cipher = WPA_CIPHER_WEP40;
2801f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt		if (bss->ssid.wep.len[0] >= 13)
2811f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt			cipher = WPA_CIPHER_WEP104;
2828d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt		bss->ssid.security_policy = SECURITY_STATIC_WEP;
2831f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt		bss->wpa_group = cipher;
2841f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt		bss->wpa_pairwise = cipher;
2851f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt		bss->rsn_pairwise = cipher;
2861f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt	} else {
2878d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt		bss->ssid.security_policy = SECURITY_PLAINTEXT;
2881f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt		bss->wpa_group = WPA_CIPHER_NONE;
2891f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt		bss->wpa_pairwise = WPA_CIPHER_NONE;
2901f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt		bss->rsn_pairwise = WPA_CIPHER_NONE;
2911f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt	}
2928d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt
2938da800a193fb6f8832218715f82a7b4e2d2ad338Dmitry Shmidt	if (bss->wpa_group_rekey < 86400 && (bss->wpa & 2) &&
2948da800a193fb6f8832218715f82a7b4e2d2ad338Dmitry Shmidt	    (bss->wpa_group == WPA_CIPHER_CCMP ||
295fb79edc9df1f20461e90e478363d207348213d35Dmitry Shmidt	     bss->wpa_group == WPA_CIPHER_GCMP ||
296fb79edc9df1f20461e90e478363d207348213d35Dmitry Shmidt	     bss->wpa_group == WPA_CIPHER_CCMP_256 ||
297fb79edc9df1f20461e90e478363d207348213d35Dmitry Shmidt	     bss->wpa_group == WPA_CIPHER_GCMP_256)) {
2988da800a193fb6f8832218715f82a7b4e2d2ad338Dmitry Shmidt		/*
2998da800a193fb6f8832218715f82a7b4e2d2ad338Dmitry Shmidt		 * Strong ciphers do not need frequent rekeying, so increase
3008da800a193fb6f8832218715f82a7b4e2d2ad338Dmitry Shmidt		 * the default GTK rekeying period to 24 hours.
3018da800a193fb6f8832218715f82a7b4e2d2ad338Dmitry Shmidt		 */
3028da800a193fb6f8832218715f82a7b4e2d2ad338Dmitry Shmidt		bss->wpa_group_rekey = 86400;
3038da800a193fb6f8832218715f82a7b4e2d2ad338Dmitry Shmidt	}
3048da800a193fb6f8832218715f82a7b4e2d2ad338Dmitry Shmidt
305b36ed7cd946148d829f311de8fe53ea3ffaaffe3Dmitry Shmidt#ifdef CONFIG_IEEE80211W
306b36ed7cd946148d829f311de8fe53ea3ffaaffe3Dmitry Shmidt	if (ssid->ieee80211w != MGMT_FRAME_PROTECTION_DEFAULT)
307b36ed7cd946148d829f311de8fe53ea3ffaaffe3Dmitry Shmidt		bss->ieee80211w = ssid->ieee80211w;
308b36ed7cd946148d829f311de8fe53ea3ffaaffe3Dmitry Shmidt#endif /* CONFIG_IEEE80211W */
309b36ed7cd946148d829f311de8fe53ea3ffaaffe3Dmitry Shmidt
3108d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#ifdef CONFIG_WPS
3118d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt	/*
3121f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt	 * Enable WPS by default for open and WPA/WPA2-Personal network, but
3131f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt	 * require user interaction to actually use it. Only the internal
3141f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt	 * Registrar is supported.
3158d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt	 */
3161f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt	if (bss->ssid.security_policy != SECURITY_WPA_PSK &&
3171f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt	    bss->ssid.security_policy != SECURITY_PLAINTEXT)
3181f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt		goto no_wps;
3191f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt	if (bss->ssid.security_policy == SECURITY_WPA_PSK &&
320a54fa5fb807eaeff45464139b5a7759f060cec68Dmitry Shmidt	    (!(bss->rsn_pairwise & WPA_CIPHER_CCMP) || !(bss->wpa & 2)))
3211f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt		goto no_wps; /* WPS2 does not allow WPA/TKIP-only
3221f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidt			      * configuration */
3238d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt	bss->eap_server = 1;
32404949598a23f501be6eec21697465fd46a28840aDmitry Shmidt
32504949598a23f501be6eec21697465fd46a28840aDmitry Shmidt	if (!ssid->ignore_broadcast_ssid)
32604949598a23f501be6eec21697465fd46a28840aDmitry Shmidt		bss->wps_state = 2;
32704949598a23f501be6eec21697465fd46a28840aDmitry Shmidt
3288d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt	bss->ap_setup_locked = 2;
3298d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt	if (wpa_s->conf->config_methods)
3308d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt		bss->config_methods = os_strdup(wpa_s->conf->config_methods);
3318d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt	os_memcpy(bss->device_type, wpa_s->conf->device_type,
3328d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt		  WPS_DEV_TYPE_LEN);
3338d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt	if (wpa_s->conf->device_name) {
3348d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt		bss->device_name = os_strdup(wpa_s->conf->device_name);
3358d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt		bss->friendly_name = os_strdup(wpa_s->conf->device_name);
3368d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt	}
3378d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt	if (wpa_s->conf->manufacturer)
3388d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt		bss->manufacturer = os_strdup(wpa_s->conf->manufacturer);
3398d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt	if (wpa_s->conf->model_name)
3408d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt		bss->model_name = os_strdup(wpa_s->conf->model_name);
3418d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt	if (wpa_s->conf->model_number)
3428d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt		bss->model_number = os_strdup(wpa_s->conf->model_number);
3438d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt	if (wpa_s->conf->serial_number)
3448d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt		bss->serial_number = os_strdup(wpa_s->conf->serial_number);
3458d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt	if (is_nil_uuid(wpa_s->conf->uuid))
3468d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt		os_memcpy(bss->uuid, wpa_s->wps->uuid, WPS_UUID_LEN);
3478d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt	else
3488d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt		os_memcpy(bss->uuid, wpa_s->conf->uuid, WPS_UUID_LEN);
3498d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt	os_memcpy(bss->os_version, wpa_s->conf->os_version, 4);
35004949598a23f501be6eec21697465fd46a28840aDmitry Shmidt	bss->pbc_in_m1 = wpa_s->conf->pbc_in_m1;
3511f69aa52ea2e0a73ac502565df8c666ee49cab6aDmitry Shmidtno_wps:
3528d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt#endif /* CONFIG_WPS */
3538d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt
3548d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt	if (wpa_s->max_stations &&
3558d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt	    wpa_s->max_stations < wpa_s->conf->max_num_sta)
3568d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt		bss->max_num_sta = wpa_s->max_stations;
3578d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt	else
3588d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt		bss->max_num_sta = wpa_s->conf->max_num_sta;
3598d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt
3608d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt	bss->disassoc_low_ack = wpa_s->conf->disassoc_low_ack;
3618d520ff1dc2da35cdca849e982051b86468016d8Dmitry Shmidt
3620ccb66edb8d2a0a397320ace3ec2a03fb0d00d5fDmitry Shmidt	if (wpa_s->conf->ap_vendor_elements) {
363