Cumulative patch from commit 2b6623ab134fff6d96114f5fe329a2f87d5e893a

2b6623a hostapd: Do not terminate process on dynamic interface add failure
217cf49 P2P: Add more debug prints for frequency selection
4dd3f86 P2P: Fix bug in GO frequency selection
9804873 wpa_supplicant: Fix bug in get_shared_radio_freqs
3342c26 wpa_supplicant: Fix updating GO beacons on WFD subelements change
72c12c1 EAPOL: Fix static analyzer warnings for pac_opaque_encr_key
3139270 bgscan: Add global bgscan configuration
efc58df eap_proxy: Re-read IMSI from proxy in Interworking functionality

Change-Id: I006abd3b52fbbd1a7b97059364c72ab0386d5f63
Signed-off-by: Dmitry Shmidt <dimitrysh@google.com>
diff --git a/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant/p2p_supplicant.c
index 4f34b75..a8e003c 100644
--- a/wpa_supplicant/p2p_supplicant.c
+++ b/wpa_supplicant/p2p_supplicant.c
@@ -134,7 +134,7 @@
 static int wpas_p2p_num_unused_channels(struct wpa_supplicant *wpa_s)
 {
 	int *freqs;
-	int num;
+	int num, unused;
 
 	freqs = os_calloc(wpa_s->num_multichan_concurrent, sizeof(int));
 	if (!freqs)
@@ -144,7 +144,9 @@
 				     wpa_s->num_multichan_concurrent);
 	os_free(freqs);
 
-	return wpa_s->num_multichan_concurrent - num;
+	unused = wpa_s->num_multichan_concurrent - num;
+	wpa_dbg(wpa_s, MSG_DEBUG, "P2P: num_unused_channels: %d", unused);
+	return unused;
 }
 
 
@@ -174,6 +176,8 @@
 
 	os_free(freqs);
 
+	dump_freq_array(wpa_s, "valid for P2P", p2p_freqs, j);
+
 	return j;
 }
 
@@ -4667,7 +4671,7 @@
 		}
 
 		if (i == num) {
-			if (num == wpa_s->num_multichan_concurrent) {
+			if (wpas_p2p_num_unused_channels(wpa_s) <= 0) {
 				wpa_printf(MSG_DEBUG, "P2P: Cannot force GO on any of the channels we are already using");
 				os_free(freqs);
 				return -1;
@@ -4682,7 +4686,7 @@
 		}
 
 		if (i == num) {
-			if (num == wpa_s->num_multichan_concurrent) {
+			if (wpas_p2p_num_unused_channels(wpa_s) <= 0) {
 				wpa_printf(MSG_DEBUG, "P2P: Cannot force GO on freq (%u MHz) as all the channels are in use", freq);
 				os_free(freqs);
 				return -1;