P2P: Iterate through full pref_chan list in search of a valid channel
authorJouni Malinen <jouni@qca.qualcomm.com>
Fri, 16 May 2014 13:49:17 +0000 (16:49 +0300)
committerJouni Malinen <j@w1.fi>
Fri, 16 May 2014 13:49:17 +0000 (16:49 +0300)
p2p_get_pref_freq() went through the full list only if the channels
arguments was provided. If no channel list contraint was in place, the
first pref_chan item was picked regardless of whether it is valid
channel and as such, a later valid entry could have been ignored. Allow
this to loop through all the entries until a valid channel is found or
the end of the pref_chan list is reached. As an extra bonus, this
simplifies the p2p_get_pref_freq() implementation quite a bit.

Signed-off-by: Jouni Malinen <jouni@qca.qualcomm.com>
src/p2p/p2p_utils.c

index de47c12..06cb646 100644 (file)
@@ -384,23 +384,14 @@ 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;
-       }
+       int 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))
+               if (freq <= 0)
+                       continue;
+               if (!channels || p2p_channels_includes_freq(channels, freq))
                        return freq;
        }