]> git.ipfire.org Git - thirdparty/iw.git/commitdiff
prepare for more generic commands
authorJohannes Berg <johannes@sipsolutions.net>
Wed, 8 Apr 2009 11:13:28 +0000 (13:13 +0200)
committerJohannes Berg <johannes@sipsolutions.net>
Wed, 8 Apr 2009 12:12:41 +0000 (14:12 +0200)
info.c
interface.c
iw.c
iw.h
mesh.c
mpath.c
phy.c
reg.c
scan.c
station.c

diff --git a/info.c b/info.c
index ed135a99c2f7f69915f8a17888c6f8a630ede0be..3939c5e3a4d92f0323b763edb611ff51d8b3acec 100644 (file)
--- a/info.c
+++ b/info.c
@@ -257,7 +257,8 @@ static int print_phy_handler(struct nl_msg *msg, void *arg)
        return NL_SKIP;
 }
 
-static int handle_info(struct nl_cb *cb,
+static int handle_info(struct nl80211_state *state,
+                      struct nl_cb *cb,
                       struct nl_msg *msg,
                       int argc, char **argv)
 {
index 01659d8cd9eca9a79a8a5808f7ec753fd83c56d8..971c3b64184f795b866c837771e2e497b027fe48 100644 (file)
@@ -123,7 +123,8 @@ static int get_if_type(int *argc, char ***argv, enum nl80211_iftype *type)
        return -1;
 }
 
-static int handle_interface_add(struct nl_cb *cb,
+static int handle_interface_add(struct nl80211_state *state,
+                               struct nl_cb *cb,
                                struct nl_msg *msg,
                                int argc, char **argv)
 {
@@ -183,7 +184,8 @@ COMMAND(interface, add, "<name> type <type> [mesh_id <meshid>] [flags ...]",
 COMMAND(interface, add, "<name> type <type> [mesh_id <meshid>] [flags ...]",
        NL80211_CMD_NEW_INTERFACE, 0, CIB_NETDEV, handle_interface_add);
 
-static int handle_interface_del(struct nl_cb *cb,
+static int handle_interface_del(struct nl80211_state *state,
+                               struct nl_cb *cb,
                                struct nl_msg *msg,
                                int argc, char **argv)
 {
@@ -210,7 +212,8 @@ static int print_iface_handler(struct nl_msg *msg, void *arg)
        return NL_SKIP;
 }
 
-static int handle_interface_info(struct nl_cb *cb,
+static int handle_interface_info(struct nl80211_state *state,
+                                struct nl_cb *cb,
                                 struct nl_msg *msg,
                                 int argc, char **argv)
 {
@@ -219,7 +222,8 @@ static int handle_interface_info(struct nl_cb *cb,
 }
 TOPLEVEL(info, NULL, NL80211_CMD_GET_INTERFACE, 0, CIB_NETDEV, handle_interface_info);
 
-static int handle_interface_set(struct nl_cb *cb,
+static int handle_interface_set(struct nl80211_state *state,
+                               struct nl_cb *cb,
                                struct nl_msg *msg,
                                int argc, char **argv)
 {
@@ -246,7 +250,8 @@ static int handle_interface_set(struct nl_cb *cb,
 COMMAND(set, monitor, "<flag> [...]",
        NL80211_CMD_SET_INTERFACE, 0, CIB_NETDEV, handle_interface_set);
 
-static int handle_interface_meshid(struct nl_cb *cb,
+static int handle_interface_meshid(struct nl80211_state *state,
+                                  struct nl_cb *cb,
                                   struct nl_msg *msg,
                                   int argc, char **argv)
 {
diff --git a/iw.c b/iw.c
index ac109b6922bb8d8a23a3c3106a8f04c8fbdb8d6d..fce634fa524c93aba3726fd13adf2017af72537c 100644 (file)
--- a/iw.c
+++ b/iw.c
@@ -122,6 +122,7 @@ static void usage(const char *argv0)
                        fprintf(stderr, "\tphy <phyname> ");
                        break;
                case CIB_NETDEV:
+               case CIB_NETDEV_RAW:
                        fprintf(stderr, "\tdev <devname> ");
                        break;
                }
@@ -178,19 +179,11 @@ static int ack_handler(struct nl_msg *msg, void *arg)
        return NL_STOP;
 }
 
-enum id_input {
-       II_NONE,
-       II_NETDEV,
-       II_PHY_NAME,
-       II_PHY_IDX,
-};
-
-static int handle_cmd(struct nl80211_state *state,
-                     enum id_input idby,
-                     int argc, char **argv)
+int handle_cmd(struct nl80211_state *state, enum id_input idby,
+              int argc, char **argv)
 {
        struct cmd *cmd;
-       struct nl_cb *cb = NULL;
+       struct nl_cb *cb;
        struct nl_msg *msg;
        int devidx = 0;
        int err;
@@ -264,6 +257,12 @@ static int handle_cmd(struct nl80211_state *state,
        if (cmd >= &__stop___cmd)
                return 1;
 
+       if (cmd->idby == CIB_NETDEV_RAW) {
+               argc++;
+               argv--;
+               return cmd->handler(state, NULL, NULL, argc, argv);
+       }
+
        msg = nlmsg_alloc();
        if (!msg) {
                fprintf(stderr, "failed to allocate netlink message\n");
@@ -291,7 +290,7 @@ static int handle_cmd(struct nl80211_state *state,
                break;
        }
 
-       err = cmd->handler(cb, msg, argc, argv);
+       err = cmd->handler(state, cb, msg, argc, argv);
        if (err)
                goto out;
 
diff --git a/iw.h b/iw.h
index be35bd795f295e40d42f5ab8a4e30090a9c9943c..315a145728a3cdd781f70a74bbaad4ab27fbb206 100644 (file)
--- a/iw.h
+++ b/iw.h
@@ -24,6 +24,14 @@ enum command_identify_by {
        CIB_NONE,
        CIB_PHY,
        CIB_NETDEV,
+       CIB_NETDEV_RAW,
+};
+
+enum id_input {
+       II_NONE,
+       II_NETDEV,
+       II_PHY_NAME,
+       II_PHY_IDX,
 };
 
 struct cmd {
@@ -39,7 +47,8 @@ struct cmd {
         * zero on success, 1 if the arguments were wrong
         * and the usage message should and 2 otherwise.
         */
-       int (*handler)(struct nl_cb *cb,
+       int (*handler)(struct nl80211_state *state,
+                      struct nl_cb *cb,
                       struct nl_msg *msg,
                       int argc, char **argv);
 };
@@ -60,6 +69,11 @@ struct cmd {
 extern struct cmd __start___cmd;
 extern struct cmd __stop___cmd;
 
+
+int handle_cmd(struct nl80211_state *state, enum id_input idby,
+              int argc, char **argv);
+
+
 int mac_addr_a2n(unsigned char *mac_addr, char *arg);
 int mac_addr_n2a(char *mac_addr, unsigned char *arg);
 
diff --git a/mesh.c b/mesh.c
index 932196e82fccd35383fa53f3718e62c7d659351a..39a24b156c922234b84d6cbc49c5acdc82f256b2 100644 (file)
--- a/mesh.c
+++ b/mesh.c
@@ -205,9 +205,10 @@ static const struct mesh_param_descr* find_mesh_param(int argc, char **argv,
 }
 
 /* Setter */
-static int set_interface_meshparam(struct nl_cb *cb,
-                               struct nl_msg *msg,
-                               int argc, char **argv)
+static int set_interface_meshparam(struct nl80211_state *state,
+                                  struct nl_cb *cb,
+                                  struct nl_msg *msg,
+                                  int argc, char **argv)
 {
        int err;
        uint32_t ret;
@@ -272,9 +273,10 @@ static int print_mesh_param_handler(struct nl_msg *msg, void *arg)
        return NL_SKIP;
 }
 
-static int get_interface_meshparam(struct nl_cb *cb,
-                               struct nl_msg *msg,
-                               int argc, char **argv)
+static int get_interface_meshparam(struct nl80211_state *state,
+                                  struct nl_cb *cb,
+                                  struct nl_msg *msg,
+                                  int argc, char **argv)
 {
        const struct mesh_param_descr *mdescr;
 
diff --git a/mpath.c b/mpath.c
index 4db5b9e23ed9b4902c8a1494290b148e03b375dc..e4bc8b695d720330e8f3830e9013b06931f4ae80 100644 (file)
--- a/mpath.c
+++ b/mpath.c
@@ -94,7 +94,8 @@ static int print_mpath_handler(struct nl_msg *msg, void *arg)
        return NL_SKIP;
 }
 
-static int handle_mpath_get(struct nl_cb *cb,
+static int handle_mpath_get(struct nl80211_state *state,
+                           struct nl_cb *cb,
                            struct nl_msg *msg,
                            int argc, char **argv)
 {
@@ -126,7 +127,8 @@ COMMAND(mpath, get, "<MAC address>",
 COMMAND(mpath, del, "<MAC address>",
        NL80211_CMD_DEL_MPATH, 0, CIB_NETDEV, handle_mpath_get);
 
-static int handle_mpath_set(struct nl_cb *cb,
+static int handle_mpath_set(struct nl80211_state *state,
+                           struct nl_cb *cb,
                            struct nl_msg *msg,
                            int argc, char **argv)
 {
@@ -171,7 +173,8 @@ COMMAND(mpath, new, "<destination MAC address> next_hop <next hop MAC address>",
 COMMAND(mpath, set, "<destination MAC address> next_hop <next hop MAC address>",
        NL80211_CMD_SET_MPATH, 0, CIB_NETDEV, handle_mpath_set);
 
-static int handle_mpath_dump(struct nl_cb *cb,
+static int handle_mpath_dump(struct nl80211_state *state,
+                            struct nl_cb *cb,
                             struct nl_msg *msg,
                             int argc, char **argv)
 {
diff --git a/phy.c b/phy.c
index f5850dc167d528b1f1b0d62774f36695ad735648..341e5a4649e3d50cb51dc99ad877d58ca168059a 100644 (file)
--- a/phy.c
+++ b/phy.c
@@ -11,7 +11,8 @@
 #include "nl80211.h"
 #include "iw.h"
 
-static int handle_name(struct nl_cb *cb,
+static int handle_name(struct nl80211_state *state,
+                      struct nl_cb *cb,
                       struct nl_msg *msg,
                       int argc, char **argv)
 {
@@ -67,7 +68,8 @@ static int handle_freqchan(struct nl_msg *msg, bool chan,
        return -ENOBUFS;
 }
 
-static int handle_freq(struct nl_cb *cb, struct nl_msg *msg,
+static int handle_freq(struct nl80211_state *state,
+                      struct nl_cb *cb, struct nl_msg *msg,
                       int argc, char **argv)
 {
        return handle_freqchan(msg, false, argc, argv);
@@ -77,7 +79,8 @@ COMMAND(set, freq, "<freq> [HT20|HT40+|HT40-]",
 COMMAND(set, freq, "<freq> [HT20|HT40+|HT40-]",
        NL80211_CMD_SET_WIPHY, 0, CIB_NETDEV, handle_freq);
 
-static int handle_chan(struct nl_cb *cb, struct nl_msg *msg,
+static int handle_chan(struct nl80211_state *state,
+                      struct nl_cb *cb, struct nl_msg *msg,
                       int argc, char **argv)
 {
        return handle_freqchan(msg, true, argc, argv);
diff --git a/reg.c b/reg.c
index 625d6953be4625b1ae9bbb0b37b2ad261af6a3a1..796379ab50b9dd8891f199259551c7e797eee17f 100644 (file)
--- a/reg.c
+++ b/reg.c
@@ -57,7 +57,8 @@ char *reg_initiator_to_string(__u8 initiator)
        }
 }
 
-static int handle_reg_set(struct nl_cb *cb,
+static int handle_reg_set(struct nl80211_state *state,
+                         struct nl_cb *cb,
                          struct nl_msg *msg,
                          int argc, char **argv)
 {
@@ -175,7 +176,8 @@ static int print_reg_handler(struct nl_msg *msg, void *arg)
 #undef PARSE_FLAG
 }
 
-static int handle_reg_get(struct nl_cb *cb,
+static int handle_reg_get(struct nl80211_state *state,
+                         struct nl_cb *cb,
                          struct nl_msg *msg,
                          int argc, char **argv)
 {
diff --git a/scan.c b/scan.c
index db3aed325f03b908c74ce57af11d3afc02fc0bba..3e56bf66b782ff5878aeb22d3a254ea1626e0c8d 100644 (file)
--- a/scan.c
+++ b/scan.c
@@ -17,7 +17,8 @@ struct scan_params {
        bool unknown;
 };
 
-static int handle_scan(struct nl_cb *cb,
+static int handle_scan(struct nl80211_state *state,
+                      struct nl_cb *cb,
                       struct nl_msg *msg,
                       int argc, char **argv)
 {
@@ -195,7 +196,8 @@ static int print_bss_handler(struct nl_msg *msg, void *arg)
 
 static struct scan_params scan_params;
 
-static int handle_scan_dump(struct nl_cb *cb,
+static int handle_scan_dump(struct nl80211_state *state,
+                           struct nl_cb *cb,
                            struct nl_msg *msg,
                            int argc, char **argv)
 {
index 97f09d9677464ec273afb6faf3f303836c049442..638e44f329ddf2d7c4e93773f865f09ca9b94b41 100644 (file)
--- a/station.c
+++ b/station.c
@@ -158,7 +158,8 @@ static int print_sta_handler(struct nl_msg *msg, void *arg)
        return NL_SKIP;
 }
 
-static int handle_station_get(struct nl_cb *cb,
+static int handle_station_get(struct nl80211_state *state,
+                             struct nl_cb *cb,
                              struct nl_msg *msg,
                              int argc, char **argv)
 {
@@ -191,7 +192,8 @@ COMMAND(station, get, "<MAC address>",
 COMMAND(station, del, "<MAC address>",
        NL80211_CMD_DEL_STATION, 0, CIB_NETDEV, handle_station_get);
 
-static int handle_station_set(struct nl_cb *cb,
+static int handle_station_set(struct nl80211_state *state,
+                             struct nl_cb *cb,
                              struct nl_msg *msg,
                              int argc, char **argv)
 {
@@ -237,7 +239,8 @@ static int handle_station_set(struct nl_cb *cb,
 COMMAND(station, set, "<MAC address> plink_action <open|block>",
        NL80211_CMD_SET_STATION, 0, CIB_NETDEV, handle_station_set);
 
-static int handle_station_dump(struct nl_cb *cb,
+static int handle_station_dump(struct nl80211_state *state,
+                              struct nl_cb *cb,
                               struct nl_msg *msg,
                               int argc, char **argv)
 {