]> git.ipfire.org Git - thirdparty/iw.git/commitdiff
iw: unify interface type list printing
authorJohannes Berg <johannes.berg@intel.com>
Wed, 18 Aug 2021 12:22:57 +0000 (14:22 +0200)
committerJohannes Berg <johannes.berg@intel.com>
Fri, 20 Aug 2021 08:28:14 +0000 (10:28 +0200)
Add two new functions print_iftype_list() and print_iftype_line()
to print interface lists, and use them where applicable.

Link: https://lore.kernel.org/r/20210818142256.3325c72c65e4.I844f8e382b0ecee00c21886342d0bfd70e246a9f@changeid
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
info.c
iw.h
util.c

diff --git a/info.c b/info.c
index ee2faebc2881eef905556de5b6e93ecd33d8da6e..488466813a4105f1e024d98674bfef1aeb7a66d6 100644 (file)
--- a/info.c
+++ b/info.c
@@ -105,10 +105,9 @@ static int print_phy_handler(struct nl_msg *msg, void *arg)
        struct nlattr *nl_band;
        struct nlattr *nl_freq;
        struct nlattr *nl_rate;
-       struct nlattr *nl_mode;
        struct nlattr *nl_cmd;
        struct nlattr *nl_if, *nl_ftype;
-       int rem_band, rem_freq, rem_rate, rem_mode, rem_cmd, rem_ftype, rem_if;
+       int rem_band, rem_freq, rem_rate, rem_cmd, rem_ftype, rem_if;
        int open;
        /*
         * static variables only work here, other applications need to use the
@@ -321,17 +320,13 @@ next:
                       nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_ANTENNA_TX]),
                       nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_ANTENNA_RX]));
 
-       if (tb_msg[NL80211_ATTR_SUPPORTED_IFTYPES]) {
-               printf("\tSupported interface modes:\n");
-               nla_for_each_nested(nl_mode, tb_msg[NL80211_ATTR_SUPPORTED_IFTYPES], rem_mode)
-                       printf("\t\t * %s\n", iftype_name(nla_type(nl_mode)));
-       }
+       if (tb_msg[NL80211_ATTR_SUPPORTED_IFTYPES])
+               print_iftype_list("\tSupported interface modes", "\t\t",
+                                 tb_msg[NL80211_ATTR_SUPPORTED_IFTYPES]);
 
-       if (tb_msg[NL80211_ATTR_SOFTWARE_IFTYPES]) {
-               printf("\tsoftware interface modes (can always be added):\n");
-               nla_for_each_nested(nl_mode, tb_msg[NL80211_ATTR_SOFTWARE_IFTYPES], rem_mode)
-                       printf("\t\t * %s\n", iftype_name(nla_type(nl_mode)));
-       }
+       if (tb_msg[NL80211_ATTR_SOFTWARE_IFTYPES])
+               print_iftype_list("\tsoftware interface modes (can always be added)",
+                                 "\t\t", tb_msg[NL80211_ATTR_SOFTWARE_IFTYPES]);
 
        if (tb_msg[NL80211_ATTR_INTERFACE_COMBINATIONS]) {
                struct nlattr *nl_combi;
@@ -373,8 +368,6 @@ next:
                        }
 
                        nla_for_each_nested(nl_limit, tb_comb[NL80211_IFACE_COMB_LIMITS], rem_limit) {
-                               bool ift_comma = false;
-
                                err = nla_parse_nested(tb_limit, MAX_NL80211_IFACE_LIMIT,
                                                       nl_limit, iface_limit_policy);
                                if (err || !tb_limit[NL80211_IFACE_LIMIT_TYPES]) {
@@ -385,13 +378,8 @@ next:
                                if (comma)
                                        printf(", ");
                                comma = true;
-                               printf("#{");
-
-                               nla_for_each_nested(nl_mode, tb_limit[NL80211_IFACE_LIMIT_TYPES], rem_mode) {
-                                       printf("%s %s", ift_comma ? "," : "",
-                                               iftype_name(nla_type(nl_mode)));
-                                       ift_comma = true;
-                               }
+                               printf("#{ ");
+                               print_iftype_line(tb_limit[NL80211_IFACE_LIMIT_TYPES]);
                                printf(" } <= %u", nla_get_u32(tb_limit[NL80211_IFACE_LIMIT_MAX]));
                        }
                        printf(",\n\t\t   ");
diff --git a/iw.h b/iw.h
index 7f7f4fcabb8d519414aa02eebe1df7bc4ee8e025..f8a49697bc8bc71a018b00173884640f5b0eafa2 100644 (file)
--- a/iw.h
+++ b/iw.h
@@ -218,6 +218,8 @@ void print_he_info(struct nlattr *nl_iftype);
 
 char *channel_width_name(enum nl80211_chan_width width);
 const char *iftype_name(enum nl80211_iftype iftype);
+void print_iftype_list(const char *name, const char *pfx, struct nlattr *attr);
+void print_iftype_line(struct nlattr *attr);
 const char *command_name(enum nl80211_commands cmd);
 int ieee80211_channel_to_frequency(int chan, enum nl80211_band band);
 int ieee80211_frequency_to_channel(int freq);
diff --git a/util.c b/util.c
index 9f21f5fba18e9342093b14aac7fa9fb79f95f238..3e3207b5c7261d9d400fb7089ef25da1b71027b6 100644 (file)
--- a/util.c
+++ b/util.c
@@ -1176,20 +1176,39 @@ static void __print_he_capa(const __u16 *mac_cap,
        }
 }
 
+void print_iftype_list(const char *name, const char *pfx, struct nlattr *attr)
+{
+       struct nlattr *ift;
+       int rem;
+
+       printf("%s:\n", name);
+       nla_for_each_nested(ift, attr, rem)
+               printf("%s * %s\n", pfx, iftype_name(nla_type(ift)));
+}
+
+void print_iftype_line(struct nlattr *attr)
+{
+       struct nlattr *ift;
+       bool first = true;
+       int rem;
+
+       nla_for_each_nested(ift, attr, rem) {
+               if (first)
+                       first = false;
+               else
+                       printf(", ");
+               printf("%s", iftype_name(nla_type(ift)));
+       }
+}
+
 void print_he_info(struct nlattr *nl_iftype)
 {
        struct nlattr *tb[NL80211_BAND_IFTYPE_ATTR_MAX + 1];
-       struct nlattr *tb_flags[NL80211_IFTYPE_MAX + 1];
-       char *iftypes[NUM_NL80211_IFTYPES] = {
-               "Unspec", "Adhoc", "Station", "AP", "AP/VLAN", "WDS", "Monitor",
-               "Mesh", "P2P/Client", "P2P/Go", "P2P/Device", "OCB", "NAN",
-       };
        __u16 mac_cap[3] = { 0 };
        __u16 phy_cap[6] = { 0 };
        __u16 mcs_set[6] = { 0 };
        __u8 ppet[25] = { 0 };
        size_t len;
-       int i;
        int mcs_len = 0, ppet_len = 0;
 
        nla_parse(tb, NL80211_BAND_IFTYPE_ATTR_MAX,
@@ -1198,14 +1217,8 @@ void print_he_info(struct nlattr *nl_iftype)
        if (!tb[NL80211_BAND_IFTYPE_ATTR_IFTYPES])
                return;
 
-       if (nla_parse_nested(tb_flags, NL80211_IFTYPE_MAX,
-                            tb[NL80211_BAND_IFTYPE_ATTR_IFTYPES], NULL))
-               return;
-
-       printf("\t\tHE Iftypes:");
-       for (i = 0; i < NUM_NL80211_IFTYPES; i++)
-               if (nla_get_flag(tb_flags[i]) && iftypes[i])
-                       printf(" %s", iftypes[i]);
+       printf("\t\tHE Iftypes: ");
+       print_iftype_line(tb[NL80211_BAND_IFTYPE_ATTR_IFTYPES]);
        printf("\n");
 
        if (tb[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC]) {