Accumulative patch from commit c6ccf12d3f6f35e295f9522dded535da8af6ab98

c6ccf12 P2P: Use preferred channel list during GO creation
6d956c4 P2P: Re-select channel in invitation case with peer info
010b5f9 P2P: Fix p2p_pref_chan setting from configuration file
d7692b8 dbus: Terminate cleanly on messagebus shutdown
e2396a6 WNM: Enable CONFIG_WNM in Android.mk
65bcd0a WNM: Add sending of BSS Transition Management Query
e27d20b WNM: Add neighbor report processing for BSS Transition Management
f3e907a WPS: Clear connection failure counts on WPS success
170f566 NFC: Connect using learnt credential after NFC Tag read
0af2db7 edit: Fix libreadline history clearing with WPA_TRACE

Change-Id: I0599ea2179869ae8c250ff6b887bb16324fc02f4
Signed-off-by: Dmitry Shmidt <dimitrysh@google.com>
diff --git a/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant/p2p_supplicant.c
index f1e15ff..b760e7f 100644
--- a/wpa_supplicant/p2p_supplicant.c
+++ b/wpa_supplicant/p2p_supplicant.c
@@ -3103,6 +3103,12 @@
 		wpa_printf(MSG_DEBUG, "P2P: Random operating channel: "
 			   "%d:%d", p2p.op_reg_class, p2p.op_channel);
 	}
+
+	if (wpa_s->conf->p2p_pref_chan && wpa_s->conf->num_p2p_pref_chan) {
+		p2p.pref_chan = wpa_s->conf->p2p_pref_chan;
+		p2p.num_pref_chan = wpa_s->conf->num_p2p_pref_chan;
+	}
+
 	if (wpa_s->conf->country[0] && wpa_s->conf->country[1]) {
 		os_memcpy(p2p.country, wpa_s->conf->country, 2);
 		p2p.country[2] = 0x04;
@@ -4084,6 +4090,7 @@
 {
 	u8 bssid[ETH_ALEN];
 	int res;
+	unsigned int pref_freq;
 
 	os_memset(params, 0, sizeof(*params));
 	params->role_go = 1;
@@ -4140,6 +4147,11 @@
 		params->freq = wpa_s->best_5_freq;
 		wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on best 5 GHz "
 			   "channel %d MHz", params->freq);
+	} else if ((pref_freq = p2p_get_pref_freq(wpa_s->global->p2p,
+						  channels))) {
+		params->freq = pref_freq;
+		wpa_printf(MSG_DEBUG, "P2P: Set GO freq %d MHz from preferred "
+			   "channels", params->freq);
 	} else {
 		int chan;
 		for (chan = 0; chan < 11; chan++) {