From c6ccf12d3f6f35e295f9522dded535da8af6ab98 Mon Sep 17 00:00:00 2001 From: Suryadevara Sudheer Date: Fri, 17 May 2013 11:27:02 +0300 Subject: [PATCH] P2P: Use preferred channel list during GO creation This extends support for p2p_pref_Chan configuration parameter for autonomous GO creation. Signed-hostap: Jouni Malinen --- src/p2p/p2p.h | 9 +++++++++ src/p2p/p2p_utils.c | 28 ++++++++++++++++++++++++++++ wpa_supplicant/p2p_supplicant.c | 6 ++++++ 3 files changed, 43 insertions(+) diff --git a/src/p2p/p2p.h b/src/p2p/p2p.h index d2fa68c5a..eeaa14989 100644 --- a/src/p2p/p2p.h +++ b/src/p2p/p2p.h @@ -1631,6 +1631,15 @@ int p2p_channels_includes_freq(const struct p2p_channels *channels, */ int p2p_supported_freq(struct p2p_data *p2p, unsigned int freq); +/** + * p2p_get_pref_freq - Get channel from preferred channel list + * @p2p: P2P module context from p2p_init() + * @channels: List of channels + * Returns: Preferred channel + */ +unsigned int p2p_get_pref_freq(struct p2p_data *p2p, + const struct p2p_channels *channels); + void p2p_update_channel_list(struct p2p_data *p2p, struct p2p_channels *chan); /** diff --git a/src/p2p/p2p_utils.c b/src/p2p/p2p_utils.c index 69bd14b4e..0da268271 100644 --- a/src/p2p/p2p_utils.c +++ b/src/p2p/p2p_utils.c @@ -243,3 +243,31 @@ int p2p_supported_freq(struct p2p_data *p2p, unsigned int freq) return p2p_channels_includes(&p2p->cfg->channels, op_reg_class, op_channel); } + + +unsigned int p2p_get_pref_freq(struct p2p_data *p2p, + const struct p2p_channels *channels) +{ + unsigned int i; + int freq = 0; + + if (channels == NULL) { + if (p2p->cfg->num_pref_chan) { + freq = p2p_channel_to_freq( + p2p->cfg->pref_chan[0].op_class, + p2p->cfg->pref_chan[0].chan); + if (freq < 0) + freq = 0; + } + return freq; + } + + for (i = 0; p2p->cfg->pref_chan && i < p2p->cfg->num_pref_chan; i++) { + freq = p2p_channel_to_freq(p2p->cfg->pref_chan[i].op_class, + p2p->cfg->pref_chan[i].chan); + if (p2p_channels_includes_freq(channels, freq)) + return freq; + } + + return 0; +} diff --git a/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant/p2p_supplicant.c index 090168a78..db199bdd2 100644 --- a/wpa_supplicant/p2p_supplicant.c +++ b/wpa_supplicant/p2p_supplicant.c @@ -3993,6 +3993,7 @@ static int wpas_p2p_init_go_params(struct wpa_supplicant *wpa_s, { u8 bssid[ETH_ALEN]; int res; + unsigned int pref_freq; os_memset(params, 0, sizeof(*params)); params->role_go = 1; @@ -4049,6 +4050,11 @@ static int wpas_p2p_init_go_params(struct wpa_supplicant *wpa_s, 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++) {