]> git.ipfire.org Git - thirdparty/iw.git/commitdiff
iw: prepare get_cf1 for use in join_* functions
authorSven Eckelmann <sven@open-mesh.com>
Wed, 25 Nov 2015 13:59:15 +0000 (14:59 +0100)
committerJohannes Berg <johannes.berg@intel.com>
Wed, 6 Jan 2016 11:02:33 +0000 (12:02 +0100)
The chanmode structure and the function get_cf1 to calculate the center
frequency one can be used by not only the ibss join code but also by the
mesh and ocb join code.

Signed-off-by: Sven Eckelmann <sven@open-mesh.com>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
ibss.c
iw.h
mesh.c
util.c

diff --git a/ibss.c b/ibss.c
index 024981af7af1a853041de5a9f2578f3972d798ba..a7617940ae802e64fabca13b283e200c758c4f55 100644 (file)
--- a/ibss.c
+++ b/ibss.c
 
 SECTION(ibss);
 
-struct chanmode {
-       const char *name;
-       unsigned int width;
-       int freq1_diff;
-       int chantype; /* for older kernel */
-};
-
-static int get_cf1(const struct chanmode *chanmode, unsigned long freq)
-{
-       unsigned int cf1 = freq, j;
-       unsigned int vht80[] = { 5180, 5260, 5500, 5580, 5660, 5745 };
-
-       switch (chanmode->width) {
-       case NL80211_CHAN_WIDTH_80:
-               /* setup center_freq1 */
-               for (j = 0; j < ARRAY_SIZE(vht80); j++) {
-                       if (freq >= vht80[j] && freq < vht80[j] + 80)
-                               break;
-               }
-
-               if (j == ARRAY_SIZE(vht80))
-                       break;
-
-               cf1 = vht80[j] + 30;
-               break;
-       default:
-               cf1 = freq + chanmode->freq1_diff;
-               break;
-       }
-
-       return cf1;
-}
-
 static int join_ibss(struct nl80211_state *state,
                     struct nl_msg *msg,
                     int argc, char **argv,
diff --git a/iw.h b/iw.h
index 263e8b1e9537b0afbb015db5482fa751d8c343b2..d91a33ec1f3c65bfa8781dae25c3d8b8b69dbb70 100644 (file)
--- a/iw.h
+++ b/iw.h
@@ -59,6 +59,13 @@ struct cmd {
        const struct cmd *parent;
 };
 
+struct chanmode {
+       const char *name;
+       unsigned int width;
+       int freq1_diff;
+       int chantype; /* for older kernel */
+};
+
 #define ARRAY_SIZE(ar) (sizeof(ar)/sizeof(ar[0]))
 #define DIV_ROUND_UP(x, y) (((x) + (y - 1)) / (y))
 
@@ -174,6 +181,8 @@ void print_ies(unsigned char *ie, int ielen, bool unknown,
 void parse_bitrate(struct nlattr *bitrate_attr, char *buf, int buflen);
 void iw_hexdump(const char *prefix, const __u8 *data, size_t len);
 
+int get_cf1(const struct chanmode *chanmode, unsigned long freq);
+
 #define SCHED_SCAN_OPTIONS "interval <in_msecs> [delay <in_secs>] " \
        "[freqs <freq>+] [matches [ssid <ssid>]+]] [active [ssid <ssid>]+|passive] [randomise[=<addr>/<mask>]]"
 int parse_sched_scan(struct nl_msg *msg, int *argc, char ***argv);
diff --git a/mesh.c b/mesh.c
index f2415f33a8e921aaa80c3f6c99ff0e218be78ed1..593ab7a8f05455928c455211fca2edeb2193b475 100644 (file)
--- a/mesh.c
+++ b/mesh.c
@@ -448,12 +448,8 @@ static int join_mesh(struct nl80211_state *state,
        char *end, *value = NULL, *sptr = NULL;
        unsigned int i;
        unsigned long freq = 0;
-       static const struct {
-               const char *name;
-               unsigned int width;
-               int freq1_diff;
-               int chantype; /* for older kernel */
-       } *chanmode_selected = NULL, chanmode[] = {
+       const struct chanmode *chanmode_selected = NULL;
+       static const struct chanmode chanmode[] = {
                { .name = "HT20",
                  .width = NL80211_CHAN_WIDTH_20,
                  .freq1_diff = 0,
@@ -506,7 +502,7 @@ static int join_mesh(struct nl80211_state *state,
                        NLA_PUT_U32(msg, NL80211_ATTR_CHANNEL_WIDTH,
                                    chanmode_selected->width);
                        NLA_PUT_U32(msg, NL80211_ATTR_CENTER_FREQ1,
-                                   freq + chanmode_selected->freq1_diff);
+                                   get_cf1(chanmode_selected, freq));
                        if (chanmode_selected->chantype != -1)
                                NLA_PUT_U32(msg,
                                            NL80211_ATTR_WIPHY_CHANNEL_TYPE,
diff --git a/util.c b/util.c
index 55e1e26366edc83dfd1f8e28350a17e20843601b..da3be3260789aa8419a0851152a3a15bc97ff793 100644 (file)
--- a/util.c
+++ b/util.c
@@ -726,3 +726,29 @@ void iw_hexdump(const char *prefix, const __u8 *buf, size_t size)
        }
        printf("\n\n");
 }
+
+int get_cf1(const struct chanmode *chanmode, unsigned long freq)
+{
+       unsigned int cf1 = freq, j;
+       unsigned int vht80[] = { 5180, 5260, 5500, 5580, 5660, 5745 };
+
+       switch (chanmode->width) {
+       case NL80211_CHAN_WIDTH_80:
+               /* setup center_freq1 */
+               for (j = 0; j < ARRAY_SIZE(vht80); j++) {
+                       if (freq >= vht80[j] && freq < vht80[j] + 80)
+                               break;
+               }
+
+               if (j == ARRAY_SIZE(vht80))
+                       break;
+
+               cf1 = vht80[j] + 30;
+               break;
+       default:
+               cf1 = freq + chanmode->freq1_diff;
+               break;
+       }
+
+       return cf1;
+}