]> git.ipfire.org Git - thirdparty/iw.git/commitdiff
iw: split str_to_bw() from parse_freqs()
authorJohannes Berg <johannes.berg@intel.com>
Wed, 25 Jan 2017 15:57:43 +0000 (16:57 +0100)
committerJohannes Berg <johannes.berg@intel.com>
Wed, 25 Jan 2017 16:03:12 +0000 (17:03 +0100)
This may be needed separately later, split it out now.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
iw.h
util.c

diff --git a/iw.h b/iw.h
index 0857baf9d7fe401cf06dc5fae554d62183c0de92..df5fb9b8265a004b0ea56eee58f7ffafed0d08d1 100644 (file)
--- a/iw.h
+++ b/iw.h
@@ -159,6 +159,7 @@ unsigned char *parse_hex(char *hex, size_t *outlen);
 
 int parse_keys(struct nl_msg *msg, char **argv, int argc);
 int parse_freqchan(struct chandef *chandef, bool chan, int argc, char **argv, int *parsed);
+enum nl80211_chan_width str_to_bw(const char *str);
 int put_chandef(struct nl_msg *msg, struct chandef *chandef);
 
 void print_ht_mcs(const __u8 *mcs);
diff --git a/util.c b/util.c
index 833b1ce086f17a84e1df844e6c1e9e64dcbc4625..81299d46448766e581ff4a025c1d76c23008f3b1 100644 (file)
--- a/util.c
+++ b/util.c
@@ -469,8 +469,7 @@ int parse_keys(struct nl_msg *msg, char **argv, int argc)
        return 2;
 }
 
-static int parse_freqs(struct chandef *chandef, int argc, char **argv,
-                      int *parsed)
+enum nl80211_chan_width str_to_bw(const char *str)
 {
        static const struct {
                const char *name;
@@ -484,26 +483,33 @@ static int parse_freqs(struct chandef *chandef, int argc, char **argv,
                { .name = "80+80", .val = NL80211_CHAN_WIDTH_80P80, },
                { .name = "160", .val = NL80211_CHAN_WIDTH_160, },
        };
+       unsigned int i;
+
+       for (i = 0; i < ARRAY_SIZE(bwmap); i++) {
+               if (strcasecmp(bwmap[i].name, str) == 0)
+                       return bwmap[i].val;
+       }
+
+       return NL80211_CHAN_WIDTH_20_NOHT;
+}
+
+static int parse_freqs(struct chandef *chandef, int argc, char **argv,
+                      int *parsed)
+{
        uint32_t freq;
-       unsigned int i, bwval = NL80211_CHAN_WIDTH_20_NOHT;
        char *end;
 
        if (argc < 1)
                return 0;
 
-       for (i = 0; i < ARRAY_SIZE(bwmap); i++) {
-               if (strcasecmp(bwmap[i].name, argv[0]) == 0) {
-                       bwval = bwmap[i].val;
-                       *parsed += 1;
-                       break;
-               }
-       }
-       chandef->width = bwval;
+       chandef->width = str_to_bw(argv[0]);
 
        /* First argument was not understood, give up gracefully. */
-       if (bwval == NL80211_CHAN_WIDTH_20_NOHT)
+       if (chandef->width == NL80211_CHAN_WIDTH_20_NOHT)
                return 0;
 
+       *parsed += 1;
+
        if (argc < 2)
                return 0;