From 00043740251716e83ca8a01b5b8a2bed1ed02db9 Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Tue, 19 Nov 2013 13:04:21 +0200 Subject: [PATCH] P2P: Prefer U-NII-3 over U-NII-1 during channel selection Some devices disable use of U-NII-1 (channels 36-48) for P2P due to it being indoor use only in number of locations. If U-NII-3 (channels 149-161) is available, try to pick a channel from that range first during random channel selection to reduce likelihood of interoperability issues. Signed-hostap: Jouni Malinen --- src/p2p/p2p.c | 4 ++-- src/p2p/p2p_go_neg.c | 4 ++-- src/p2p/p2p_utils.c | 35 ++++++++++++++++------------------- 3 files changed, 20 insertions(+), 23 deletions(-) diff --git a/src/p2p/p2p.c b/src/p2p/p2p.c index ee25bbc4c..e52822de5 100644 --- a/src/p2p/p2p.c +++ b/src/p2p/p2p.c @@ -1180,8 +1180,8 @@ static int p2p_prepare_channel_pref(struct p2p_data *p2p, static void p2p_prepare_channel_best(struct p2p_data *p2p) { u8 op_class, op_channel; - const int op_classes_5ghz[] = { 115, 124, 0 }; - const int op_classes_ht40[] = { 116, 117, 126, 127, 0 }; + const int op_classes_5ghz[] = { 124, 115, 0 }; + const int op_classes_ht40[] = { 126, 127, 116, 117, 0 }; const int op_classes_vht[] = { 128, 0 }; p2p_dbg(p2p, "Prepare channel best"); diff --git a/src/p2p/p2p_go_neg.c b/src/p2p/p2p_go_neg.c index 325b83256..008651e47 100644 --- a/src/p2p/p2p_go_neg.c +++ b/src/p2p/p2p_go_neg.c @@ -348,8 +348,8 @@ void p2p_reselect_channel(struct p2p_data *p2p, int freq; u8 op_reg_class, op_channel; unsigned int i; - const int op_classes_5ghz[] = { 115, 124, 0 }; - const int op_classes_ht40[] = { 116, 117, 126, 127, 0 }; + const int op_classes_5ghz[] = { 124, 115, 0 }; + const int op_classes_ht40[] = { 126, 127, 116, 117, 0 }; const int op_classes_vht[] = { 128, 0 }; if (p2p->own_freq_preference > 0 && diff --git a/src/p2p/p2p_utils.c b/src/p2p/p2p_utils.c index a579509ae..161a402ef 100644 --- a/src/p2p/p2p_utils.c +++ b/src/p2p/p2p_utils.c @@ -446,28 +446,25 @@ int p2p_channel_select(struct p2p_channels *chans, const int *classes, { unsigned int i, j, r; - for (i = 0; i < chans->reg_classes; i++) { - struct p2p_reg_class *c = &chans->reg_class[i]; + for (j = 0; classes[j]; j++) { + for (i = 0; i < chans->reg_classes; i++) { + struct p2p_reg_class *c = &chans->reg_class[i]; - if (c->channels == 0) - continue; + if (c->channels == 0) + continue; - for (j = 0; classes[j]; j++) { - if (c->reg_class == classes[j]) - break; + if (c->reg_class == classes[j]) { + /* + * Pick one of the available channels in the + * operating class at random. + */ + os_get_random((u8 *) &r, sizeof(r)); + r %= c->channels; + *op_class = c->reg_class; + *op_channel = c->channel[r]; + return 0; + } } - if (!classes[j]) - continue; - - /* - * Pick one of the available channels in the operating class at - * random. - */ - os_get_random((u8 *) &r, sizeof(r)); - r %= c->channels; - *op_class = c->reg_class; - *op_channel = c->channel[r]; - return 0; } return -1;