2014-08-27 07:58:50

by Janusz Dziedzic

[permalink] [raw]
Subject: [PATCH 1/2] iw: print hexdump when vendor event

print hexdump when vendor event and -f requested

Signed-off-by: Janusz Dziedzic <[email protected]>
---
event.c | 4 ++++
iw.h | 1 +
util.c | 13 +++++++++++++
3 files changed, 18 insertions(+)

diff --git a/event.c b/event.c
index 6775eb2..d903f9e 100644
--- a/event.c
+++ b/event.c
@@ -535,6 +535,10 @@ static int print_event(struct nl_msg *msg, void *arg)
printf("vendor event %.6x:%d\n",
nla_get_u32(tb[NL80211_ATTR_VENDOR_ID]),
nla_get_u32(tb[NL80211_ATTR_VENDOR_SUBCMD]));
+ if (args->frame && tb[NL80211_ATTR_VENDOR_DATA])
+ iw_hexdump("vendor event",
+ nla_data(tb[NL80211_ATTR_VENDOR_DATA]),
+ nla_len(tb[NL80211_ATTR_VENDOR_DATA]));
break;
default:
printf("unknown event %d (%s)\n",
diff --git a/iw.h b/iw.h
index 317f0a6..db88a86 100644
--- a/iw.h
+++ b/iw.h
@@ -171,6 +171,7 @@ void print_ies(unsigned char *ie, int ielen, bool unknown,
enum print_ie_type ptype);

void parse_bitrate(struct nlattr *bitrate_attr, char *buf, int buflen);
+void iw_hexdump(const char *prefix, const __u8 *data, size_t len);

DECLARE_SECTION(set);
DECLARE_SECTION(get);
diff --git a/util.c b/util.c
index 97307ec..ce4b0ac 100644
--- a/util.c
+++ b/util.c
@@ -702,3 +702,16 @@ void print_vht_info(__u32 capa, const __u8 *mcs)
tmp = mcs[6] | (mcs[7] << 8);
printf("\t\tVHT TX highest supported: %d Mbps\n", tmp & 0x1fff);
}
+
+void iw_hexdump(const char *prefix, const __u8 *buf, size_t size)
+{
+ int i;
+
+ printf("%s: ", prefix);
+ for (i = 0; i < size; i++) {
+ if (i && i % 16 == 0)
+ printf("\n%s: ", prefix);
+ printf("%02x ", buf[i]);
+ }
+ printf("\n\n");
+}
--
1.7.9.5



2014-08-27 07:58:51

by Janusz Dziedzic

[permalink] [raw]
Subject: [PATCH 2/2] iw: add vendor send command

This allow to send vendor data to the driver.
This command required OUI and SUBCMD parameters.

Also optional DATA parameter could be used:

cat data.bin | iw wlan0 send oui subcmd

Signed-off-by: Janusz Dziedzic <[email protected]>
---
Makefile | 2 +-
vendor.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 57 insertions(+), 1 deletion(-)
create mode 100644 vendor.c

diff --git a/Makefile b/Makefile
index f042e30..802f87a 100644
--- a/Makefile
+++ b/Makefile
@@ -16,7 +16,7 @@ OBJS = iw.o genl.o event.o info.o phy.o \
interface.o ibss.o station.o survey.o util.o \
mesh.o mpath.o scan.o reg.o version.o \
reason.o status.o connect.o link.o offch.o ps.o cqm.o \
- bitrate.o wowlan.o coalesce.o roc.o p2p.o
+ bitrate.o wowlan.o coalesce.o roc.o p2p.o vendor.o
OBJS += sections.o

OBJS-$(HWSIM) += hwsim.o
diff --git a/vendor.c b/vendor.c
new file mode 100644
index 0000000..9c51cb9
--- /dev/null
+++ b/vendor.c
@@ -0,0 +1,56 @@
+#include <net/if.h>
+#include <errno.h>
+#include <string.h>
+
+#include <netlink/genl/genl.h>
+#include <netlink/genl/family.h>
+#include <netlink/genl/ctrl.h>
+#include <netlink/msg.h>
+#include <netlink/attr.h>
+
+#include "nl80211.h"
+#include "iw.h"
+
+SECTION(vendor);
+
+static int handle_vendor(struct nl80211_state *state, struct nl_cb *cb,
+ struct nl_msg *msg, int argc, char **argv,
+ enum id_input id)
+{
+ unsigned int oui;
+ unsigned int subcmd;
+ char buf[2048] = {};
+ int res, count = 0;
+
+ if (argc < 2)
+ return -EINVAL;
+
+ res = sscanf(argv[0], "0x%x", &oui);
+ if (res != 1)
+ return -EINVAL;
+
+ res = sscanf(argv[1], "0x%x", &subcmd);
+ if (res != 1)
+ return -EINVAL;
+
+ NLA_PUT_U32(msg, NL80211_ATTR_VENDOR_ID, oui);
+ NLA_PUT_U32(msg, NL80211_ATTR_VENDOR_SUBCMD, subcmd);
+
+ while ((res = fgetc(stdin)) != EOF) {
+ if (count >= sizeof(buf))
+ return -EINVAL;
+
+ buf[count] = res;
+ count++;
+ }
+
+ if (count > 0)
+ NLA_PUT(msg, NL80211_ATTR_VENDOR_DATA, count, buf);
+
+ return 0;
+
+ nla_put_failure:
+ return -ENOBUFS;
+}
+
+COMMAND(vendor, send, "<oui> <subcmd> [stdin data]", NL80211_CMD_VENDOR, 0, CIB_NETDEV, handle_vendor, "");
--
1.7.9.5


2014-08-29 11:14:23

by Johannes Berg

[permalink] [raw]
Subject: Re: [PATCH 2/2] iw: add vendor send command

On Wed, 2014-08-27 at 09:58 +0200, Janusz Dziedzic wrote:

> cat data.bin | iw wlan0 send oui subcmd

Interesting approach, but I'm not sure I like the stdin? Maybe you could
make it an optional <filename|-|hex string> argument instead (- for
stdin)?

johannes


2014-09-03 11:44:21

by Johannes Berg

[permalink] [raw]
Subject: Re: [PATCH 1/2] iw: print hexdump when vendor event

On Wed, 2014-08-27 at 09:58 +0200, Janusz Dziedzic wrote:
> print hexdump when vendor event and -f requested

Applied this patch.

johannes