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/wpa_supplicant/ctrl_iface.c b/wpa_supplicant/ctrl_iface.c
index 4aa602d..f32b7c9 100644
--- a/wpa_supplicant/ctrl_iface.c
+++ b/wpa_supplicant/ctrl_iface.c
@@ -2876,7 +2876,8 @@
 #endif /* CONFIG_SME */
 			wpa_sm_set_config(wpa_s->wpa, NULL);
 			eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
-			wpa_s->own_disconnect_req = 1;
+			if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
+				wpa_s->own_disconnect_req = 1;
 			wpa_supplicant_deauthenticate(
 				wpa_s, WLAN_REASON_DEAUTH_LEAVING);
 		}
@@ -2923,7 +2924,8 @@
 		wpa_sm_set_config(wpa_s->wpa, NULL);
 		eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
 
-		wpa_s->own_disconnect_req = 1;
+		if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
+			wpa_s->own_disconnect_req = 1;
 		wpa_supplicant_deauthenticate(wpa_s,
 					      WLAN_REASON_DEAUTH_LEAVING);
 	}
@@ -6982,6 +6984,8 @@
 	void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
 				 struct wpa_scan_results *scan_res);
 	int *manual_scan_freqs = NULL;
+	struct wpa_ssid_value *ssid = NULL, *ns;
+	unsigned int ssid_count = 0;
 
 	if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
 		*reply_len = -1;
@@ -7036,6 +7040,60 @@
 			*reply_len = -1;
 			goto done;
 		}
+
+		pos = params;
+		while (pos && *pos != '\0') {
+			if (os_strncmp(pos, "ssid ", 5) == 0) {
+				char *end;
+
+				pos += 5;
+				end = pos;
+				while (*end) {
+					if (*end == '\0' || *end == ' ')
+						break;
+					end++;
+				}
+
+				ns = os_realloc_array(
+					ssid, ssid_count + 1,
+					sizeof(struct wpa_ssid_value));
+				if (ns == NULL) {
+					*reply_len = -1;
+					goto done;
+				}
+				ssid = ns;
+
+				if ((end - pos) & 0x01 ||
+				    end - pos > 2 * SSID_MAX_LEN ||
+				    hexstr2bin(pos, ssid[ssid_count].ssid,
+					       (end - pos) / 2) < 0) {
+					wpa_printf(MSG_DEBUG,
+						   "Invalid SSID value '%s'",
+						   pos);
+					*reply_len = -1;
+					goto done;
+				}
+				ssid[ssid_count].ssid_len = (end - pos) / 2;
+				wpa_hexdump_ascii(MSG_DEBUG, "scan SSID",
+						  ssid[ssid_count].ssid,
+						  ssid[ssid_count].ssid_len);
+				ssid_count++;
+				pos = end;
+			}
+
+			pos = os_strchr(pos, ' ');
+			if (pos)
+				pos++;
+		}
+	}
+
+	wpa_s->num_ssids_from_scan_req = ssid_count;
+	os_free(wpa_s->ssids_from_scan_req);
+	if (ssid_count) {
+		wpa_s->ssids_from_scan_req = ssid;
+		ssid = NULL;
+	} else {
+		wpa_s->ssids_from_scan_req = NULL;
 	}
 
 	if (scan_only)
@@ -7099,6 +7157,7 @@
 
 done:
 	os_free(manual_scan_freqs);
+	os_free(ssid);
 }