]> git.ipfire.org Git - thirdparty/iw.git/commitdiff
push info to new framework
authorJohannes Berg <johannes@sipsolutions.net>
Tue, 16 Sep 2008 15:05:33 +0000 (17:05 +0200)
committerJohannes Berg <johannes@sipsolutions.net>
Tue, 16 Sep 2008 15:05:33 +0000 (17:05 +0200)
info.c
iw.c

diff --git a/info.c b/info.c
index fa2a69622ad1699a552a48a9161b9cd67ed7daab..0b3973cac0b80d9101a1d2530177f0550d24e1c6 100644 (file)
--- a/info.c
+++ b/info.c
@@ -56,21 +56,24 @@ static int print_phy_handler(struct nl_msg *msg, void *arg)
        if (!tb_msg[NL80211_ATTR_WIPHY_BANDS])
                return NL_SKIP;
 
+       if (tb_msg[NL80211_ATTR_WIPHY_NAME])
+               printf("Wiphy %s\n", nla_get_string(tb_msg[NL80211_ATTR_WIPHY_NAME]));
+
        nla_for_each_nested(nl_band, tb_msg[NL80211_ATTR_WIPHY_BANDS], rem_band) {
-               printf("Band %d:\n", bandidx);
+               printf("\tBand %d:\n", bandidx);
                bandidx++;
 
                nla_parse(tb_band, NL80211_BAND_ATTR_MAX, nla_data(nl_band),
                          nla_len(nl_band), NULL);
 
-               printf("\tFrequencies:\n");
+               printf("\t\tFrequencies:\n");
 
                nla_for_each_nested(nl_freq, tb_band[NL80211_BAND_ATTR_FREQS], rem_freq) {
                        nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX, nla_data(nl_freq),
                                  nla_len(nl_freq), freq_policy);
                        if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ])
                                continue;
-                       printf("\t\t* %d MHz", nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_FREQ]));
+                       printf("\t\t\t* %d MHz", nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_FREQ]));
                        open = 0;
                        if (tb_freq[NL80211_FREQUENCY_ATTR_DISABLED])
                                print_flag("disabled", &open);
@@ -85,14 +88,14 @@ static int print_phy_handler(struct nl_msg *msg, void *arg)
                        printf("\n");
                }
 
-               printf("\tBitrates:\n");
+               printf("\t\tBitrates:\n");
 
                nla_for_each_nested(nl_rate, tb_band[NL80211_BAND_ATTR_RATES], rem_rate) {
                        nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX, nla_data(nl_rate),
                                  nla_len(nl_rate), rate_policy);
                        if (!tb_rate[NL80211_BITRATE_ATTR_RATE])
                                continue;
-                       printf("\t\t* %2.1f Mbps", 0.1 * nla_get_u32(tb_rate[NL80211_BITRATE_ATTR_RATE]));
+                       printf("\t\t\t* %2.1f Mbps", 0.1 * nla_get_u32(tb_rate[NL80211_BITRATE_ATTR_RATE]));
                        open = 0;
                        if (tb_rate[NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE])
                                print_flag("short preamble supported", &open);
@@ -105,9 +108,9 @@ static int print_phy_handler(struct nl_msg *msg, void *arg)
        if (!tb_msg[NL80211_ATTR_SUPPORTED_IFTYPES])
                return NL_SKIP;
 
-       printf("Supported interface modes:\n");
+       printf("\tSupported interface modes:\n");
        nla_for_each_nested(nl_mode, tb_msg[NL80211_ATTR_SUPPORTED_IFTYPES], rem_mode)
-               printf("\t * %s\n", iftype_name(nl_mode->nla_type));
+               printf("\t\t * %s\n", iftype_name(nl_mode->nla_type));
 
        return NL_SKIP;
 }
@@ -122,26 +125,14 @@ static int ack_wait_handler(struct nl_msg *msg, void *arg)
        return NL_STOP;
 }
 
-int handle_info(struct nl80211_state *state, char *phy, char *dev)
+static int handle_info(struct nl80211_state *state,
+                      struct nl_msg *msg,
+                      int argc, char **argv)
 {
-       struct nl_msg *msg;
        int err = -1;
        struct nl_cb *cb;
        int finished;
 
-       msg = nlmsg_alloc();
-       if (!msg) {
-               fprintf(stderr, "failed to allocate netlink msg\n");
-               return -1;
-       }
-
-       genlmsg_put(msg, 0, 0, genl_family_get_id(state->nl80211), 0,
-                   0, NL80211_CMD_GET_WIPHY, 0);
-       if (dev)
-               NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(dev));
-       if (phy)
-               return -1;      /* XXX TODO */
-
        cb = nl_cb_alloc(NL_CB_CUSTOM);
        if (!cb)
                goto out;
@@ -163,9 +154,9 @@ int handle_info(struct nl80211_state *state, char *phy, char *dev)
 
  out:
        nl_cb_put(cb);
- nla_put_failure:
        if (err)
                fprintf(stderr, "failed to get information: %d\n", err);
-       nlmsg_free(msg);
        return err;
 }
+TOPLEVEL(info, NULL, NL80211_CMD_GET_WIPHY, 0, CIB_PHY, handle_info);
+TOPLEVEL(list, NULL, NL80211_CMD_GET_WIPHY, NLM_F_DUMP, CIB_NONE, handle_info);
diff --git a/iw.c b/iw.c
index 35cb306d3f5025c3ef395dd758b8633c936d7347..72c79835843d409458d8d3c44a85ed1b2d0aebf9 100644 (file)
--- a/iw.c
+++ b/iw.c
@@ -77,10 +77,11 @@ static void usage(const char *argv0)
        for (cmd = &__start___cmd; cmd < &__stop___cmd; cmd++) {
                switch (cmd->idby) {
                case CIB_NONE:
-                       fprintf(stderr, "\t%s %s %s\n", argv0, cmd->section, cmd->name);
-                       break;
+                       fprintf(stderr, "\t%s ", argv0);
+                       /* fall through */
                case CIB_PHY:
-                       fprintf(stderr, "\t%s phy <phyname> ", argv0);
+                       if (cmd->idby == CIB_PHY)
+                               fprintf(stderr, "\t%s phy <phyname> ", argv0);
                        /* fall through */
                case CIB_NETDEV:
                        if (cmd->idby == CIB_NETDEV)
@@ -111,16 +112,16 @@ static int phy_lookup(char *name)
        return atoi(buf);
 }
 
-static int handle_phydev_cmd(struct nl80211_state *state,
-                            enum command_identify_by idby,
-                            int argc, char **argv)
+static int handle_cmd(struct nl80211_state *state,
+                     enum command_identify_by idby,
+                     int argc, char **argv)
 {
        struct cmd *cmd;
        struct nl_msg *msg;
        int devidx = 0;
        const char *command, *section;
 
-       if (argc <= 1)
+       if (argc <= 1 && idby != CIB_NONE)
                return -1;
 
        switch (idby) {
@@ -195,11 +196,6 @@ static int handle_phydev_cmd(struct nl80211_state *state,
        return 1;
 }
 
-static int handle_other_cmd(struct nl80211_state *state, int argc, char **argv)
-{
-       return -1;
-}
-
 int main(int argc, char **argv)
 {
        struct nl80211_state nlstate;
@@ -222,13 +218,13 @@ int main(int argc, char **argv)
        if (strcmp(*argv, "dev") == 0) {
                argc--;
                argv++;
-               err = handle_phydev_cmd(&nlstate, CIB_NETDEV, argc, argv);
+               err = handle_cmd(&nlstate, CIB_NETDEV, argc, argv);
        } else if (strcmp(*argv, "phy") == 0) {
                argc--;
                argv++;
-               err = handle_phydev_cmd(&nlstate, CIB_PHY, argc, argv);
+               err = handle_cmd(&nlstate, CIB_PHY, argc, argv);
        } else
-               err = handle_other_cmd(&nlstate, argc, argv);
+               err = handle_cmd(&nlstate, CIB_NONE, argc, argv);
 
        if (err < 0)
                usage(argv0);