]> git.ipfire.org Git - thirdparty/iw.git/commitdiff
iw: add vendor command response support
authorErik Stromdahl <erik.stromdahl@gmail.com>
Mon, 2 May 2016 19:55:30 +0000 (21:55 +0200)
committerJohannes Berg <johannes.berg@intel.com>
Tue, 31 May 2016 09:41:43 +0000 (11:41 +0200)
Introduced two new commands for reading vendor command responses:
recv and recvbin
Both will send a vendor command (typically some kind of GET request)
in the same way as the current send command and print the received
response in ASCII or binary.

Signed-off-by: Erik Stromdahl <erik.stromdahl@gmail.com>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
vendor.c

index 279aac50727d941c5c0afe14aff4792c49604d7a..860cd48a2b7da0613d58f63b601e4ea32e55afc6 100644 (file)
--- a/vendor.c
+++ b/vendor.c
 
 SECTION(vendor);
 
+static int print_vendor_response(struct nl_msg *msg, void *arg)
+{
+       struct nlattr *attr;
+       struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
+       bool print_ascii = (bool) arg;
+       uint8_t *data;
+       int len;
+
+       attr = nla_find(genlmsg_attrdata(gnlh, 0),
+                       genlmsg_attrlen(gnlh, 0),
+                       NL80211_ATTR_VENDOR_DATA);
+       if (!attr) {
+               fprintf(stderr, "vendor data attribute missing!\n");
+               return NL_SKIP;
+       }
+
+       data = (uint8_t *) nla_data(attr);
+       len = nla_len(attr);
+
+       if (print_ascii)
+               iw_hexdump("vendor response", data, len);
+       else
+               fwrite(data, 1, len, stdout);
+
+       return NL_OK;
+}
+
 static int read_file(FILE *file, char *buf, size_t size)
 {
        size_t count = 0;
@@ -96,4 +123,22 @@ nla_put_failure:
        return -ENOBUFS;
 }
 
+static int handle_vendor_recv(struct nl80211_state *state,
+                             struct nl_msg *msg, int argc,
+                             char **argv, enum id_input id)
+{
+       register_handler(print_vendor_response, (void *) true);
+       return handle_vendor(state, msg, argc, argv, id);
+}
+
+static int handle_vendor_recv_bin(struct nl80211_state *state,
+                                 struct nl_msg *msg, int argc,
+                                 char **argv, enum id_input id)
+{
+       register_handler(print_vendor_response, (void *) false);
+       return handle_vendor(state, msg, argc, argv, id);
+}
+
 COMMAND(vendor, send, "<oui> <subcmd> <filename|-|hex data>", NL80211_CMD_VENDOR, 0, CIB_NETDEV, handle_vendor, "");
+COMMAND(vendor, recv, "<oui> <subcmd> <filename|-|hex data>", NL80211_CMD_VENDOR, 0, CIB_NETDEV, handle_vendor_recv, "");
+COMMAND(vendor, recvbin, "<oui> <subcmd> <filename|-|hex data>", NL80211_CMD_VENDOR, 0, CIB_NETDEV, handle_vendor_recv_bin, "");