]> git.ipfire.org Git - thirdparty/iw.git/blobdiff - iw.c
update nl80211.h
[thirdparty/iw.git] / iw.c
diff --git a/iw.c b/iw.c
index cdfd00e4b915a10ee79e608a10eaaf550a4fd3d5..dc99566653cadbd2c3f98b78b0b13b93e97510f0 100644 (file)
--- a/iw.c
+++ b/iw.c
@@ -34,6 +34,12 @@ static inline void nl_socket_free(struct nl_sock *h)
 {
        nl_handle_destroy(h);
 }
+
+static inline int nl_socket_set_buffer_size(struct nl_sock *sk,
+                                           int rxbuf, int txbuf)
+{
+       return nl_set_buffer_size(sk, rxbuf, txbuf);
+}
 #endif /* CONFIG_LIBNL20 && CONFIG_LIBNL30 */
 
 int iw_debug = 0;
@@ -48,6 +54,8 @@ static int nl80211_init(struct nl80211_state *state)
                return -ENOMEM;
        }
 
+       nl_socket_set_buffer_size(state->nl_sock, 8192, 8192);
+
        if (genl_connect(state->nl_sock)) {
                fprintf(stderr, "Failed to connect to generic netlink.\n");
                err = -ENOLINK;
@@ -105,9 +113,40 @@ static void __usage_cmd(const struct cmd *cmd, char *indent, bool full)
        if (cmd->parent && cmd->parent->name)
                printf("%s ", cmd->parent->name);
        printf("%s", cmd->name);
-       if (cmd->args)
-               printf(" %s", cmd->args);
-       printf("\n");
+
+       if (cmd->args) {
+               /* print line by line */
+               start = cmd->args;
+               end = strchr(start, '\0');
+               printf(" ");
+               do {
+                       lend = strchr(start, '\n');
+                       if (!lend)
+                               lend = end;
+                       if (start != cmd->args) {
+                               printf("\t");
+                               switch (cmd->idby) {
+                               case CIB_NONE:
+                                       break;
+                               case CIB_PHY:
+                                       printf("phy <phyname> ");
+                                       break;
+                               case CIB_NETDEV:
+                                       printf("dev <devname> ");
+                                       break;
+                               case CIB_WDEV:
+                                       printf("wdev <idx> ");
+                                       break;
+                               }
+                               if (cmd->parent && cmd->parent->name)
+                                       printf("%s ", cmd->parent->name);
+                               printf("%s ", cmd->name);
+                       }
+                       printf("%.*s\n", (int)(lend - start), start);
+                       start = lend + 1;
+               } while (end != lend);
+       } else
+               printf("\n");
 
        if (!full || !cmd->help)
                return;
@@ -178,6 +217,8 @@ static void usage(int argc, char **argv)
                        __usage_cmd(cmd, "\t", full);
                }
        }
+       printf("\nCommands that use the netdev ('dev') can also be given the\n"
+              "'wdev' instead to identify the device.\n");
        printf("\nYou can omit the 'phy' or 'dev' if "
                        "the identification is unique,\n"
                        "e.g. \"iw wlan0 info\" or \"iw phy0 info\". "
@@ -189,7 +230,8 @@ static void usage(int argc, char **argv)
 static int print_help(struct nl80211_state *state,
                      struct nl_cb *cb,
                      struct nl_msg *msg,
-                     int argc, char **argv)
+                     int argc, char **argv,
+                     enum id_input id)
 {
        exit(3);
 }
@@ -334,7 +376,13 @@ static int __handle_cmd(struct nl80211_state *state, enum id_input idby,
                                continue;
                        if (cmd->parent != sectcmd)
                                continue;
-                       if (cmd->idby != command_idby)
+                       /*
+                        * ignore mismatch id by, but allow WDEV
+                        * in place of NETDEV
+                        */
+                       if (cmd->idby != command_idby &&
+                           !(cmd->idby == CIB_NETDEV &&
+                             command_idby == CIB_WDEV))
                                continue;
                        if (strcmp(cmd->name, command))
                                continue;
@@ -357,7 +405,8 @@ static int __handle_cmd(struct nl80211_state *state, enum id_input idby,
                cmd = sectcmd;
                if (argc && !cmd->args)
                        return 1;
-               if (cmd->idby != command_idby)
+               if (cmd->idby != command_idby &&
+                   !(cmd->idby == CIB_NETDEV && command_idby == CIB_WDEV))
                        return 1;
                if (!cmd->handler)
                        return 1;
@@ -375,7 +424,7 @@ static int __handle_cmd(struct nl80211_state *state, enum id_input idby,
        if (!cmd->cmd) {
                argc = o_argc;
                argv = o_argv;
-               return cmd->handler(state, NULL, NULL, argc, argv);
+               return cmd->handler(state, NULL, NULL, argc, argv, idby);
        }
 
        msg = nlmsg_alloc();
@@ -409,7 +458,7 @@ static int __handle_cmd(struct nl80211_state *state, enum id_input idby,
                break;
        }
 
-       err = cmd->handler(state, cb, msg, argc, argv);
+       err = cmd->handler(state, cb, msg, argc, argv, idby);
        if (err)
                goto out;