Cumulative patch from commit 57e832de37ea0a82e650d8230457e0868a01b72e

57e832d GAS: Remove all radio works before calling gas_query_deinit()
661888b P2P: Fix persistent group profile on manual disabled=2 change
1a2f7ca D-Bus: Add WPS pbc-overlap Event
4f36965 P2P: Add ModelNumber and SerialNumber info into D-Bus peer interface
2899cba P2P: Add ModelName info into D-Bus peer interface
8bb5cfe doc: Add missing ListenChannel to P2P information
995a3a0 Document the wpa_msg_cb "global" parameter
e66bced Do not set own_disconnect_req flag if not connected
8d2ed87 wpa_gui: Port to Qt5
e1ede80 eapol_test: Support IPv6 for authentication server
e19c1d2 Fix pairwise cipher suite bitfields to the driver in mixed mode
ee120ff Remove [MU-BEAMFORMEE] option from hostapd vht_capab parameter
c5ee4dd Fix spelling of initialize in a comment and an error message
aa2b125 P2P: Add GO Intent of connecting device in GO Negotiation Request event
cf60962 doc: Fix a typo in D-Bus API document
f13e815 Set Acct-Session-Id from os_get_random() instead of os_get_time()
92f190a OpenSSL: Fix build iwth OpenSSL 0.9.8
a80651d Add support to request a scan with specific SSIDs
94687a0 WPS: Allow the priority for the WPS networks to be configured
09d57ce wpa_supplicant: Remove trailing whitespace
0980c7f hostapd: Make sure band selection does not result in NULL dereference

Change-Id: I32154fcf606169fc1e3e3a653e80c99f058f8e95
Signed-off-by: Dmitry Shmidt <dimitrysh@google.com>
diff --git a/src/ap/accounting.c b/src/ap/accounting.c
index 7c55146..a096de4 100644
--- a/src/ap/accounting.c
+++ b/src/ap/accounting.c
@@ -459,10 +459,14 @@
 {
 	struct os_time now;
 
-	/* Acct-Session-Id should be unique over reboots. If reliable clock is
-	 * not available, this could be replaced with reboot counter, etc. */
+	/* Acct-Session-Id should be unique over reboots. Using a random number
+	 * is preferred. If that is not available, take the current time. Mix
+	 * in microseconds to make this more likely to be unique. */
 	os_get_time(&now);
-	hapd->acct_session_id_hi = now.sec;
+	if (os_get_random((u8 *) &hapd->acct_session_id_hi,
+			  sizeof(hapd->acct_session_id_hi)) < 0)
+		hapd->acct_session_id_hi = now.sec;
+	hapd->acct_session_id_hi ^= now.usec;
 
 	if (radius_client_register(hapd->radius, RADIUS_ACCT,
 				   accounting_receive, hapd))
@@ -475,7 +479,7 @@
 
 
 /**
- * accounting_deinit: Deinitilize accounting
+ * accounting_deinit: Deinitialize accounting
  * @hapd: hostapd BSS data
  */
 void accounting_deinit(struct hostapd_data *hapd)
diff --git a/src/ap/ap_drv_ops.c b/src/ap/ap_drv_ops.c
index 9ee88b4..60c8f8c 100644
--- a/src/ap/ap_drv_ops.c
+++ b/src/ap/ap_drv_ops.c
@@ -290,8 +290,14 @@
 		params.wpa = hapd->conf->wpa;
 		params.ieee802_1x = hapd->conf->ieee802_1x;
 		params.wpa_group = hapd->conf->wpa_group;
-		params.wpa_pairwise = hapd->conf->wpa_pairwise |
-			hapd->conf->rsn_pairwise;
+		if ((hapd->conf->wpa & (WPA_PROTO_WPA | WPA_PROTO_RSN)) ==
+		    (WPA_PROTO_WPA | WPA_PROTO_RSN))
+			params.wpa_pairwise = hapd->conf->wpa_pairwise |
+				hapd->conf->rsn_pairwise;
+		else if (hapd->conf->wpa & WPA_PROTO_RSN)
+			params.wpa_pairwise = hapd->conf->rsn_pairwise;
+		else if (hapd->conf->wpa & WPA_PROTO_WPA)
+			params.wpa_pairwise = hapd->conf->wpa_pairwise;
 		params.wpa_key_mgmt = hapd->conf->wpa_key_mgmt;
 		params.rsn_preauth = hapd->conf->rsn_preauth;
 #ifdef CONFIG_IEEE80211W
diff --git a/src/ap/beacon.c b/src/ap/beacon.c
index 7009855..51d0c15 100644
--- a/src/ap/beacon.c
+++ b/src/ap/beacon.c
@@ -956,8 +956,14 @@
 	params->basic_rates = hapd->iface->basic_rates;
 	params->ssid = hapd->conf->ssid.ssid;
 	params->ssid_len = hapd->conf->ssid.ssid_len;
-	params->pairwise_ciphers = hapd->conf->wpa_pairwise |
-		hapd->conf->rsn_pairwise;
+	if ((hapd->conf->wpa & (WPA_PROTO_WPA | WPA_PROTO_RSN)) ==
+	    (WPA_PROTO_WPA | WPA_PROTO_RSN))
+		params->pairwise_ciphers = hapd->conf->wpa_pairwise |
+			hapd->conf->rsn_pairwise;
+	else if (hapd->conf->wpa & WPA_PROTO_RSN)
+		params->pairwise_ciphers = hapd->conf->rsn_pairwise;
+	else if (hapd->conf->wpa & WPA_PROTO_WPA)
+		params->pairwise_ciphers = hapd->conf->wpa_pairwise;
 	params->group_cipher = hapd->conf->wpa_group;
 	params->key_mgmt_suites = hapd->conf->wpa_key_mgmt;
 	params->auth_algs = hapd->conf->auth_algs;
diff --git a/src/ap/hw_features.c b/src/ap/hw_features.c
index 069d1ae..7c08e52 100644
--- a/src/ap/hw_features.c
+++ b/src/ap/hw_features.c
@@ -744,6 +744,9 @@
 	int i;
 	struct hostapd_channel_data *chan;
 
+	if (!iface->current_mode)
+		return 0;
+
 	for (i = 0; i < iface->current_mode->num_channels; i++) {
 		chan = &iface->current_mode->channels[i];
 		if (chan->chan != channel)
@@ -805,6 +808,12 @@
 
 static void hostapd_notify_bad_chans(struct hostapd_iface *iface)
 {
+	if (!iface->current_mode) {
+		hostapd_logger(iface->bss[0], NULL, HOSTAPD_MODULE_IEEE80211,
+			       HOSTAPD_LEVEL_WARNING,
+			       "Hardware does not support configured mode");
+		return;
+	}
 	hostapd_logger(iface->bss[0], NULL,
 		       HOSTAPD_MODULE_IEEE80211,
 		       HOSTAPD_LEVEL_WARNING,
diff --git a/src/crypto/tls_openssl.c b/src/crypto/tls_openssl.c
index ffcf83a..8f28ca8 100644
--- a/src/crypto/tls_openssl.c
+++ b/src/crypto/tls_openssl.c
@@ -2710,7 +2710,7 @@
 #if OPENSSL_VERSION_NUMBER >= 0x00909000L
 	h = EVP_MD_CTX_md(ssl->read_hash);
 #else
-	h = conn->ssl->read_hash;
+	h = ssl->read_hash;
 #endif
 	if (h)
 		md_size = EVP_MD_size(h);
diff --git a/src/p2p/p2p.h b/src/p2p/p2p.h
index da2446d..6b0ba80 100644
--- a/src/p2p/p2p.h
+++ b/src/p2p/p2p.h
@@ -705,6 +705,7 @@
 	 * @ctx: Callback context from cb_ctx
 	 * @src: Source address of the message triggering this notification
 	 * @dev_passwd_id: WPS Device Password ID
+	 * @go_intent: Peer's GO Intent
 	 *
 	 * This callback is used to notify that a P2P Device is requesting
 	 * group owner negotiation with us, but we do not have all the
@@ -713,7 +714,8 @@
 	 * PIN or PBC button press. This information can be provided with a
 	 * call to p2p_connect().
 	 */
-	void (*go_neg_req_rx)(void *ctx, const u8 *src, u16 dev_passwd_id);
+	void (*go_neg_req_rx)(void *ctx, const u8 *src, u16 dev_passwd_id,
+			      u8 go_intent);
 
 	/**
 	 * go_neg_completed - Notification of GO Negotiation results
diff --git a/src/p2p/p2p_go_neg.c b/src/p2p/p2p_go_neg.c
index 98abf9d..63837eb 100644
--- a/src/p2p/p2p_go_neg.c
+++ b/src/p2p/p2p_go_neg.c
@@ -668,7 +668,9 @@
 			MAC2STR(sa));
 		status = P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE;
 		p2p->cfg->go_neg_req_rx(p2p->cfg->cb_ctx, sa,
-					msg.dev_password_id);
+					msg.dev_password_id,
+					msg.go_intent ? (*msg.go_intent >> 1) :
+					0);
 	} else if (p2p->go_neg_peer && p2p->go_neg_peer != dev) {
 		p2p_dbg(p2p, "Already in Group Formation with another peer");
 		status = P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE;
diff --git a/src/utils/wpa_debug.c b/src/utils/wpa_debug.c
index 0d11905..82a8999 100644
--- a/src/utils/wpa_debug.c
+++ b/src/utils/wpa_debug.c
@@ -635,7 +635,7 @@
 	va_end(ap);
 	wpa_printf(level, "%s%s", prefix, buf);
 	if (wpa_msg_cb)
-		wpa_msg_cb(ctx, level, 0, buf, len);
+		wpa_msg_cb(ctx, level, WPA_MSG_PER_INTERFACE, buf, len);
 	os_free(buf);
 }
 
@@ -663,7 +663,7 @@
 	va_start(ap, fmt);
 	len = vsnprintf(buf, buflen, fmt, ap);
 	va_end(ap);
-	wpa_msg_cb(ctx, level, 0, buf, len);
+	wpa_msg_cb(ctx, level, WPA_MSG_PER_INTERFACE, buf, len);
 	os_free(buf);
 }
 
@@ -690,7 +690,7 @@
 	va_end(ap);
 	wpa_printf(level, "%s", buf);
 	if (wpa_msg_cb)
-		wpa_msg_cb(ctx, level, 1, buf, len);
+		wpa_msg_cb(ctx, level, WPA_MSG_GLOBAL, buf, len);
 	os_free(buf);
 }
 
@@ -718,7 +718,7 @@
 	va_start(ap, fmt);
 	len = vsnprintf(buf, buflen, fmt, ap);
 	va_end(ap);
-	wpa_msg_cb(ctx, level, 1, buf, len);
+	wpa_msg_cb(ctx, level, WPA_MSG_GLOBAL, buf, len);
 	os_free(buf);
 }
 
@@ -745,7 +745,7 @@
 	va_end(ap);
 	wpa_printf(level, "%s", buf);
 	if (wpa_msg_cb)
-		wpa_msg_cb(ctx, level, 2, buf, len);
+		wpa_msg_cb(ctx, level, WPA_MSG_NO_GLOBAL, buf, len);
 	os_free(buf);
 }
 
diff --git a/src/utils/wpa_debug.h b/src/utils/wpa_debug.h
index 400bea9..5fdc50e 100644
--- a/src/utils/wpa_debug.h
+++ b/src/utils/wpa_debug.h
@@ -243,7 +243,13 @@
 void wpa_msg_no_global(void *ctx, int level, const char *fmt, ...)
 PRINTF_FORMAT(3, 4);
 
-typedef void (*wpa_msg_cb_func)(void *ctx, int level, int global,
+enum wpa_msg_type {
+	WPA_MSG_PER_INTERFACE,
+	WPA_MSG_GLOBAL,
+	WPA_MSG_NO_GLOBAL,
+};
+
+typedef void (*wpa_msg_cb_func)(void *ctx, int level, enum wpa_msg_type type,
 				const char *txt, size_t len);
 
 /**