From 28812a898381d73add08f4e82b5e54cd36616a9b Mon Sep 17 00:00:00 2001 From: Ilan Peer Date: Mon, 19 May 2014 10:05:38 +0300 Subject: [PATCH] P2P: Try using one of the social channels for GO In case there is no preference for the GO operating channel, try using one of 1, 6, 11 (randomly), and only if the random selection is not suitable traverse all the channels 1..11. Signed-off-by: Ilan Peer --- wpa_supplicant/p2p_supplicant.c | 49 +++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant/p2p_supplicant.c index d2cb7af32..9eeda94ab 100644 --- a/wpa_supplicant/p2p_supplicant.c +++ b/wpa_supplicant/p2p_supplicant.c @@ -5014,6 +5014,39 @@ static int wpas_p2p_select_go_freq(struct wpa_supplicant *wpa_s, int freq) } +static int wpas_p2p_select_freq_no_pref(struct wpa_supplicant *wpa_s, + struct p2p_go_neg_results *params, + const struct p2p_channels *channels) +{ + unsigned int i, r; + + /* first try some random selection of the social channels */ + os_get_random((u8 *) &r, sizeof(r)); + + for (i = 0; i < 3; i++) { + params->freq = 2412 + ((r + i) % 3) * 25; + if (!wpas_p2p_disallowed_freq(wpa_s->global, params->freq) && + freq_included(channels, params->freq)) + goto out; + } + + /* try all channels in reg. class 81 */ + for (i = 0; i < 11; i++) { + params->freq = 2412 + i * 5; + if (!wpas_p2p_disallowed_freq(wpa_s->global, params->freq) && + freq_included(channels, params->freq)) + goto out; + } + + wpa_printf(MSG_DEBUG, "P2P: No 2.4 GHz channel allowed"); + return -1; +out: + wpa_printf(MSG_DEBUG, "P2P: Set GO freq %d MHz (no preference known)", + params->freq); + return 0; +} + + static int wpas_p2p_init_go_params(struct wpa_supplicant *wpa_s, struct p2p_go_neg_results *params, int freq, int ht40, int vht, @@ -5085,21 +5118,9 @@ static int wpas_p2p_init_go_params(struct wpa_supplicant *wpa_s, wpa_printf(MSG_DEBUG, "P2P: Set GO freq %d MHz from preferred " "channels", params->freq); } else { - int chan; - for (chan = 0; chan < 11; chan++) { - params->freq = 2412 + chan * 5; - if (!wpas_p2p_disallowed_freq(wpa_s->global, - params->freq) && - freq_included(channels, params->freq)) - break; - } - if (chan == 11) { - wpa_printf(MSG_DEBUG, "P2P: No 2.4 GHz channel " - "allowed"); + /* no preference, select some channel */ + if (wpas_p2p_select_freq_no_pref(wpa_s, params, channels) < 0) return -1; - } - wpa_printf(MSG_DEBUG, "P2P: Set GO freq %d MHz (no preference " - "known)", params->freq); } freqs = os_calloc(wpa_s->num_multichan_concurrent,