]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
wpa_supplicant: Extend verify_channel() and make it global
authorAvraham Stern <avraham.stern@intel.com>
Wed, 28 Dec 2016 13:06:44 +0000 (15:06 +0200)
committerJouni Malinen <j@w1.fi>
Tue, 3 Jan 2017 13:18:29 +0000 (15:18 +0200)
Extend verify_channel() to return whether IR is allowed on the channel
or not, and make it a global function so it can be used in other files,
too. This makes this function useful for checking not only if a channel
is supported but also if it is allowed for active and passive scan.

Signed-off-by: Avraham Stern <avraham.stern@intel.com>
wpa_supplicant/op_classes.c
wpa_supplicant/p2p_supplicant.c
wpa_supplicant/wpa_supplicant_i.h

index c463de3e087d814a25651fd99babdc292cf47571..d23b0094c440d2f31cbc64a37c8e3ae5e8a7d7a9 100644 (file)
 #include "wpa_supplicant_i.h"
 
 
-enum chan_allowed {
-       NOT_ALLOWED, ALLOWED
-};
-
 static enum chan_allowed allow_channel(struct hostapd_hw_modes *mode, u8 chan,
                                       unsigned int *flags)
 {
@@ -37,6 +33,9 @@ static enum chan_allowed allow_channel(struct hostapd_hw_modes *mode, u8 chan,
        if (flags)
                *flags = mode->channels[i].flag;
 
+       if (mode->channels[i].flag & HOSTAPD_CHAN_NO_IR)
+               return NO_IR;
+
        return ALLOWED;
 }
 
@@ -67,6 +66,7 @@ static enum chan_allowed verify_80mhz(struct hostapd_hw_modes *mode, u8 channel)
 {
        u8 center_chan;
        unsigned int i;
+       unsigned int no_ir = 0;
 
        center_chan = get_center_80mhz(mode, channel);
        if (!center_chan)
@@ -85,8 +85,14 @@ static enum chan_allowed verify_80mhz(struct hostapd_hw_modes *mode, u8 channel)
                    (i == 2 && !(flags & HOSTAPD_CHAN_VHT_50_30)) ||
                    (i == 3 && !(flags & HOSTAPD_CHAN_VHT_70_10)))
                        return NOT_ALLOWED;
+
+               if (flags & HOSTAPD_CHAN_NO_IR)
+                       no_ir = 1;
        }
 
+       if (no_ir)
+               return NO_IR;
+
        return ALLOWED;
 }
 
@@ -118,6 +124,7 @@ static enum chan_allowed verify_160mhz(struct hostapd_hw_modes *mode,
 {
        u8 center_chan;
        unsigned int i;
+       unsigned int no_ir = 0;
 
        center_chan = get_center_160mhz(mode, channel);
        if (!center_chan)
@@ -140,14 +147,20 @@ static enum chan_allowed verify_160mhz(struct hostapd_hw_modes *mode,
                    (i == 6 && !(flags & HOSTAPD_CHAN_VHT_130_30)) ||
                    (i == 7 && !(flags & HOSTAPD_CHAN_VHT_150_10)))
                        return NOT_ALLOWED;
+
+               if (flags & HOSTAPD_CHAN_NO_IR)
+                       no_ir = 1;
        }
 
+       if (no_ir)
+               return NO_IR;
+
        return ALLOWED;
 }
 
 
-static enum chan_allowed verify_channel(struct hostapd_hw_modes *mode,
-                                       u8 channel, u8 bw)
+enum chan_allowed verify_channel(struct hostapd_hw_modes *mode, u8 channel,
+                                u8 bw)
 {
        unsigned int flag = 0;
        enum chan_allowed res, res2;
@@ -187,6 +200,9 @@ static enum chan_allowed verify_channel(struct hostapd_hw_modes *mode,
        if (res == NOT_ALLOWED || res2 == NOT_ALLOWED)
                return NOT_ALLOWED;
 
+       if (res == NO_IR || res2 == NO_IR)
+               return NO_IR;
+
        return ALLOWED;
 }
 
@@ -207,8 +223,8 @@ static int wpas_op_class_supported(struct wpa_supplicant *wpa_s,
                u8 channels[] = { 42, 58, 106, 122, 138, 155 };
 
                for (i = 0; i < ARRAY_SIZE(channels); i++) {
-                       if (verify_channel(mode, channels[i], op_class->bw) ==
-                           ALLOWED)
+                       if (verify_channel(mode, channels[i], op_class->bw) !=
+                           NOT_ALLOWED)
                                return 1;
                }
 
@@ -217,25 +233,25 @@ static int wpas_op_class_supported(struct wpa_supplicant *wpa_s,
 
        if (op_class->op_class == 129) {
                /* Check if either 160 MHz channels is allowed */
-               return verify_channel(mode, 50, op_class->bw) == ALLOWED ||
-                       verify_channel(mode, 114, op_class->bw) == ALLOWED;
+               return verify_channel(mode, 50, op_class->bw) != NOT_ALLOWED ||
+                       verify_channel(mode, 114, op_class->bw) != NOT_ALLOWED;
        }
 
        if (op_class->op_class == 130) {
                /* Need at least two non-contiguous 80 MHz segments */
                found = 0;
 
-               if (verify_channel(mode, 42, op_class->bw) == ALLOWED ||
-                   verify_channel(mode, 58, op_class->bw) == ALLOWED)
+               if (verify_channel(mode, 42, op_class->bw) != NOT_ALLOWED ||
+                   verify_channel(mode, 58, op_class->bw) != NOT_ALLOWED)
                        found++;
-               if (verify_channel(mode, 106, op_class->bw) == ALLOWED ||
-                   verify_channel(mode, 122, op_class->bw) == ALLOWED ||
-                   verify_channel(mode, 138, op_class->bw) == ALLOWED)
+               if (verify_channel(mode, 106, op_class->bw) != NOT_ALLOWED ||
+                   verify_channel(mode, 122, op_class->bw) != NOT_ALLOWED ||
+                   verify_channel(mode, 138, op_class->bw) != NOT_ALLOWED)
                        found++;
-               if (verify_channel(mode, 106, op_class->bw) == ALLOWED &&
-                   verify_channel(mode, 138, op_class->bw) == ALLOWED)
+               if (verify_channel(mode, 106, op_class->bw) != NOT_ALLOWED &&
+                   verify_channel(mode, 138, op_class->bw) != NOT_ALLOWED)
                        found++;
-               if (verify_channel(mode, 155, op_class->bw) == ALLOWED)
+               if (verify_channel(mode, 155, op_class->bw) != NOT_ALLOWED)
                        found++;
 
                if (found >= 2)
@@ -247,7 +263,7 @@ static int wpas_op_class_supported(struct wpa_supplicant *wpa_s,
        found = 0;
        for (chan = op_class->min_chan; chan <= op_class->max_chan;
             chan += op_class->inc) {
-               if (verify_channel(mode, chan, op_class->bw) == ALLOWED) {
+               if (verify_channel(mode, chan, op_class->bw) != NOT_ALLOWED) {
                        found = 1;
                        break;
                }
index 6dc08fabdd4de92b148ee3347acef2321c2eb067..c7e8ef4d9620182eef674e582667adc5bd2823bd 100644 (file)
@@ -3334,10 +3334,6 @@ static int wpas_p2p_default_channels(struct wpa_supplicant *wpa_s,
 }
 
 
-enum chan_allowed {
-       NOT_ALLOWED, NO_IR, ALLOWED
-};
-
 static int has_channel(struct wpa_global *global,
                       struct hostapd_hw_modes *mode, u8 chan, int *flags)
 {
index b182ddaebbbe69c457b0e2cbf40bcc6b6a476deb..b5b7d7e347cf8e21cda68132e4dc0328fd9890cc 100644 (file)
@@ -1217,6 +1217,12 @@ struct wpabuf * mbo_build_anqp_buf(struct wpa_supplicant *wpa_s,
                                   struct wpa_bss *bss);
 
 /* op_classes.c */
+enum chan_allowed {
+       NOT_ALLOWED, NO_IR, ALLOWED
+};
+
+enum chan_allowed verify_channel(struct hostapd_hw_modes *mode, u8 channel,
+                                u8 bw);
 size_t wpas_supp_op_class_ie(struct wpa_supplicant *wpa_s, int freq, u8 *pos,
                              size_t len);