* [PATCH v2 2/2] iw: add vendor send command
@ 2014-09-15 10:47 Janusz Dziedzic
2014-10-09 8:36 ` Johannes Berg
2014-10-24 9:53 ` Johannes Berg
0 siblings, 2 replies; 4+ messages in thread
From: Janusz Dziedzic @ 2014-09-15 10:47 UTC (permalink / raw)
To: linux-wireless; +Cc: johannes, Janusz Dziedzic
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 -
iw wlan0 send oui subcmd file.bin
iw wlan0 vendor send oui subcmd 0x00 0x00 0x00 0x1f
echo EOF | iw wlan0 vendor send oui subcmd -
Signed-off-by: Janusz Dziedzic <janusz.dziedzic@tieto.com>
---
Makefile | 2 +-
vendor.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 96 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..f32c00b
--- /dev/null
+++ b/vendor.c
@@ -0,0 +1,95 @@
+#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 read_file(FILE *file, char *buf, size_t size)
+{
+ int data, count = 0;
+
+ while ((data = fgetc(file)) != EOF) {
+ if (count >= size)
+ return -EINVAL;
+ buf[count] = data;
+ count++;
+ }
+
+ return count;
+}
+
+static int read_hex(int argc, char **argv, char *buf, size_t size)
+{
+ int i, res;
+ unsigned int data;
+
+ if (argc > size)
+ return -EINVAL;
+
+ for (i = 0; i < argc; i++) {
+ res = sscanf(argv[i], "0x%x", &data);
+ if (res != 1 || data > 0xff)
+ return -EINVAL;
+ buf[i] = data;
+ }
+
+ return argc;
+}
+
+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;
+ FILE *file = NULL;
+
+ if (argc < 3)
+ 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;
+
+ if (!strcmp(argv[2], "-"))
+ file = stdin;
+ else
+ file = fopen(argv[2], "r");
+
+ NLA_PUT_U32(msg, NL80211_ATTR_VENDOR_ID, oui);
+ NLA_PUT_U32(msg, NL80211_ATTR_VENDOR_SUBCMD, subcmd);
+
+ if (file) {
+ count = read_file(file, buf, sizeof(buf));
+ fclose(file);
+ } else
+ count = read_hex(argc - 2, &argv[2], buf, sizeof(buf));
+
+ if (count < 0)
+ return -EINVAL;
+
+ if (count > 0)
+ NLA_PUT(msg, NL80211_ATTR_VENDOR_DATA, count, buf);
+
+ return 0;
+
+nla_put_failure:
+ return -ENOBUFS;
+}
+
+COMMAND(vendor, send, "<oui> <subcmd> <filename|-|hex data>", NL80211_CMD_VENDOR, 0, CIB_NETDEV, handle_vendor, "");
--
1.9.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2 2/2] iw: add vendor send command
2014-09-15 10:47 [PATCH v2 2/2] iw: add vendor send command Janusz Dziedzic
@ 2014-10-09 8:36 ` Johannes Berg
2014-10-10 6:12 ` Janusz Dziedzic
2014-10-24 9:53 ` Johannes Berg
1 sibling, 1 reply; 4+ messages in thread
From: Johannes Berg @ 2014-10-09 8:36 UTC (permalink / raw)
To: Janusz Dziedzic; +Cc: linux-wireless
On Mon, 2014-09-15 at 12:47 +0200, Janusz Dziedzic wrote:
> + while ((data = fgetc(file)) != EOF) {
Why are you using fgetc() rather than just fread() or read()?
johannes
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2 2/2] iw: add vendor send command
2014-10-09 8:36 ` Johannes Berg
@ 2014-10-10 6:12 ` Janusz Dziedzic
0 siblings, 0 replies; 4+ messages in thread
From: Janusz Dziedzic @ 2014-10-10 6:12 UTC (permalink / raw)
To: Johannes Berg; +Cc: linux-wireless
On 9 October 2014 10:36, Johannes Berg <johannes@sipsolutions.net> wrote:
> On Mon, 2014-09-15 at 12:47 +0200, Janusz Dziedzic wrote:
>
>> + while ((data = fgetc(file)) != EOF) {
>
> Why are you using fgetc() rather than just fread() or read()?
>
No special reason. Code looks simpler I think than in case of using
fread() and feof() functions.
BR
Janusz
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2 2/2] iw: add vendor send command
2014-09-15 10:47 [PATCH v2 2/2] iw: add vendor send command Janusz Dziedzic
2014-10-09 8:36 ` Johannes Berg
@ 2014-10-24 9:53 ` Johannes Berg
1 sibling, 0 replies; 4+ messages in thread
From: Johannes Berg @ 2014-10-24 9:53 UTC (permalink / raw)
To: Janusz Dziedzic; +Cc: linux-wireless
On Mon, 2014-09-15 at 12:47 +0200, Janusz Dziedzic wrote:
> This allow to send vendor data to the driver.
> This command required OUI and SUBCMD parameters.
>
> Also optional DATA parameter could be used:
Applied, sorry for the delay.
johannes
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-10-24 9:53 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-15 10:47 [PATCH v2 2/2] iw: add vendor send command Janusz Dziedzic
2014-10-09 8:36 ` Johannes Berg
2014-10-10 6:12 ` Janusz Dziedzic
2014-10-24 9:53 ` Johannes Berg
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.