Cumulative patch from commit c16a7590cfe76d5895ac70ef711e5b0b384f7aa6

c16a759 wpa_supplicant: Add a configuration file for the P2P_DEVICE parameters
185677b Disable interface if ACS fails
8f05577 Configure beacon interval for IBSS command
95faa36 HS 2.0R2: Check for OSEN when determining whether to authorize STA
113318a Set the station to authorized on assoc event for open authentication

Change-Id: Id8111b6475bf93a0600a431708cb16120d380e24
Signed-off-by: Dmitry Shmidt <dimitrysh@google.com>
diff --git a/src/ap/acs.c b/src/ap/acs.c
index 60b7580..3e0155c 100644
--- a/src/ap/acs.c
+++ b/src/ap/acs.c
@@ -284,6 +284,7 @@
 {
 	wpa_printf(MSG_ERROR, "ACS: Failed to start");
 	acs_cleanup(iface);
+	hostapd_disable_iface(iface);
 }
 
 
diff --git a/src/ap/hostapd.c b/src/ap/hostapd.c
index 6ba6f98..bfa3c49 100644
--- a/src/ap/hostapd.c
+++ b/src/ap/hostapd.c
@@ -2026,7 +2026,8 @@
 	/* Start accounting here, if IEEE 802.1X and WPA are not used.
 	 * IEEE 802.1X/WPA code will start accounting after the station has
 	 * been authorized. */
-	if (!hapd->conf->ieee802_1x && !hapd->conf->wpa) {
+	if (!hapd->conf->ieee802_1x && !hapd->conf->wpa && !hapd->conf->osen) {
+		ap_sta_set_authorized(hapd, sta, 1);
 		os_get_reltime(&sta->connected_time);
 		accounting_sta_start(hapd, sta);
 	}
diff --git a/src/drivers/driver.h b/src/drivers/driver.h
index 6b6c0ef..a92de56 100644
--- a/src/drivers/driver.h
+++ b/src/drivers/driver.h
@@ -448,6 +448,11 @@
 	int bg_scan_period;
 
 	/**
+	 * beacon_int - Beacon interval for IBSS or 0 to use driver default
+	 */
+	int beacon_int;
+
+	/**
 	 * wpa_ie - WPA information element for (Re)Association Request
 	 * WPA information element to be included in (Re)Association
 	 * Request (including information element id and length). Use
diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c
index 87c9661..9b9e66c 100644
--- a/src/drivers/driver_nl80211.c
+++ b/src/drivers/driver_nl80211.c
@@ -8377,6 +8377,12 @@
 	wpa_printf(MSG_DEBUG, "  * freq=%d", params->freq);
 	NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq);
 
+	if (params->beacon_int > 0) {
+		wpa_printf(MSG_DEBUG, "  * beacon_int=%d", params->beacon_int);
+		NLA_PUT_U32(msg, NL80211_ATTR_BEACON_INTERVAL,
+			    params->beacon_int);
+	}
+
 	ret = nl80211_set_conn_keys(params, msg);
 	if (ret)
 		goto nla_put_failure;
diff --git a/wpa_supplicant/README b/wpa_supplicant/README
index 7f88cd6..653848e 100644
--- a/wpa_supplicant/README
+++ b/wpa_supplicant/README
@@ -413,7 +413,7 @@
         [-G<group>] \
         -i<ifname> -c<config file> [-C<ctrl>] [-D<driver>] [-p<driver_param>] \
         [-b<br_ifname> [-N -i<ifname> -c<conf> [-C<ctrl>] [-D<driver>] \
-        [-p<driver_param>] [-b<br_ifname>] ...]
+        [-p<driver_param>] [-b<br_ifname>] [-m<P2P Device config file>] ...
 
 options:
   -b = optional bridge interface name
@@ -438,6 +438,7 @@
   -w = wait for interface to be added, if needed
   -W = wait for a control interface monitor before starting
   -N = start describing new interface
+  -m = Configuration file for the P2P Device
 
 drivers:
   nl80211 = Linux nl80211/cfg80211
diff --git a/wpa_supplicant/main.c b/wpa_supplicant/main.c
index d56935d..d2e839d 100644
--- a/wpa_supplicant/main.c
+++ b/wpa_supplicant/main.c
@@ -43,6 +43,9 @@
 	       "        [-o<override driver>] [-O<override ctrl>] \\\n"
 	       "        [-N -i<ifname> -c<conf> [-C<ctrl>] "
 	       "[-D<driver>] \\\n"
+#ifdef CONFIG_P2P
+	       "        [-m<P2P Device config file>] \\\n"
+#endif /* CONFIG_P2P */
 	       "        [-p<driver_param>] [-b<br_ifname>] [-I<config file>] "
 	       "...]\n"
 	       "\n"
@@ -92,6 +95,9 @@
 #endif /* CONFIG_DBUS */
 	printf("  -v = show version\n"
 	       "  -W = wait for a control interface monitor before starting\n"
+#ifdef CONFIG_P2P
+	       "  -m = Configuration file for the P2P Device interface\n"
+#endif /* CONFIG_P2P */
 	       "  -N = start describing new interface\n");
 
 	printf("example:\n"
@@ -169,7 +175,7 @@
 
 	for (;;) {
 		c = getopt(argc, argv,
-			   "b:Bc:C:D:de:f:g:G:hi:I:KLNo:O:p:P:qsTtuvW");
+			   "b:Bc:C:D:de:f:g:G:hi:I:KLm:No:O:p:P:qsTtuvW");
 		if (c < 0)
 			break;
 		switch (c) {
@@ -229,6 +235,11 @@
 			license();
 			exitcode = 0;
 			goto out;
+#ifdef CONFIG_P2P
+		case 'm':
+			iface->conf_p2p_dev = optarg;
+			break;
+#endif /* CONFIG_P2P */
 		case 'o':
 			params.override_driver = optarg;
 			break;
diff --git a/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant/p2p_supplicant.c
index b878198..09f98a3 100644
--- a/wpa_supplicant/p2p_supplicant.c
+++ b/wpa_supplicant/p2p_supplicant.c
@@ -3680,7 +3680,20 @@
 	iface.ifname = wpa_s->pending_interface_name;
 	iface.driver = wpa_s->driver->name;
 	iface.driver_param = wpa_s->conf->driver_param;
-	iface.confname = wpa_s->confname;
+
+	/*
+	 * If a P2P Device configuration file was given, use it as the interface
+	 * configuration file (instead of using parent's configuration file.
+	 */
+	if (wpa_s->conf_p2p_dev) {
+		iface.confname = wpa_s->conf_p2p_dev;
+		iface.ctrl_interface = NULL;
+	} else {
+		iface.confname = wpa_s->confname;
+		iface.ctrl_interface = wpa_s->conf->ctrl_interface;
+	}
+	iface.conf_p2p_dev = NULL;
+
 	p2pdev_wpa_s = wpa_supplicant_add_iface(wpa_s->global, &iface);
 	if (!p2pdev_wpa_s) {
 		wpa_printf(MSG_DEBUG, "P2P: Failed to add P2P Device interface");
diff --git a/wpa_supplicant/wpa_supplicant.c b/wpa_supplicant/wpa_supplicant.c
index 46195b1..561099c 100644
--- a/wpa_supplicant/wpa_supplicant.c
+++ b/wpa_supplicant/wpa_supplicant.c
@@ -397,6 +397,11 @@
 	os_free(wpa_s->confanother);
 	wpa_s->confanother = NULL;
 
+#ifdef CONFIG_P2P
+	os_free(wpa_s->conf_p2p_dev);
+	wpa_s->conf_p2p_dev = NULL;
+#endif /* CONFIG_P2P */
+
 	wpa_sm_set_eapol(wpa_s->wpa, NULL);
 	eapol_sm_deinit(wpa_s->eapol);
 	wpa_s->eapol = NULL;
@@ -1714,6 +1719,14 @@
 	if (ssid->mode == WPAS_MODE_IBSS && ssid->frequency > 0 &&
 	    params.freq == 0)
 		params.freq = ssid->frequency; /* Initial channel for IBSS */
+
+	if (ssid->mode == WPAS_MODE_IBSS) {
+		if (ssid->beacon_int)
+			params.beacon_int = ssid->beacon_int;
+		else
+			params.beacon_int = wpa_s->conf->beacon_int;
+	}
+
 	params.wpa_ie = wpa_ie;
 	params.wpa_ie_len = wpa_ie_len;
 	params.pairwise_suite = cipher_pairwise;
@@ -3374,6 +3387,11 @@
 		wpa_s->confanother = os_rel2abs_path(iface->confanother);
 		wpa_config_read(wpa_s->confanother, wpa_s->conf);
 
+#ifdef CONFIG_P2P
+		wpa_s->conf_p2p_dev = os_rel2abs_path(iface->conf_p2p_dev);
+		wpa_config_read(wpa_s->conf_p2p_dev, wpa_s->conf);
+#endif /* CONFIG_P2P */
+
 		/*
 		 * Override ctrl_interface and driver_param if set on command
 		 * line.
diff --git a/wpa_supplicant/wpa_supplicant_i.h b/wpa_supplicant/wpa_supplicant_i.h
index 1314734..376a250 100644
--- a/wpa_supplicant/wpa_supplicant_i.h
+++ b/wpa_supplicant/wpa_supplicant_i.h
@@ -64,6 +64,17 @@
 	 */
 	const char *confanother;
 
+#ifdef CONFIG_P2P
+	/**
+	 * conf_p2p_dev - Additional configuration file used to hold the
+	 * P2P Device configuration parameters.
+	 *
+	 * This can also be %NULL. In such a case, if a P2P Device dedicated
+	 * interfaces is created, the main configuration file will be used.
+	 */
+	const char *conf_p2p_dev;
+#endif /* CONFIG_P2P */
+
 	/**
 	 * ctrl_interface - Control interface parameter
 	 *
@@ -386,6 +397,11 @@
 
 	char *confname;
 	char *confanother;
+
+#ifdef CONFIG_P2P
+	char *conf_p2p_dev;
+#endif /* CONFIG_P2P */
+
 	struct wpa_config *conf;
 	int countermeasures;
 	struct os_reltime last_michael_mic_error;