4 #include <netlink/genl/genl.h>
5 #include <netlink/genl/family.h>
6 #include <netlink/genl/ctrl.h>
7 #include <netlink/msg.h>
8 #include <netlink/attr.h>
15 static int read_file(FILE *file
, char *buf
, size_t size
)
19 while ((data
= fgetc(file
)) != EOF
) {
29 static int read_hex(int argc
, char **argv
, char *buf
, size_t size
)
37 for (i
= 0; i
< argc
; i
++) {
38 res
= sscanf(argv
[i
], "0x%x", &data
);
39 if (res
!= 1 || data
> 0xff)
47 static int handle_vendor(struct nl80211_state
*state
,
48 struct nl_msg
*msg
, int argc
, char **argv
,
60 res
= sscanf(argv
[0], "0x%x", &oui
);
62 printf("Vendor command must start with 0x\n");
66 res
= sscanf(argv
[1], "0x%x", &subcmd
);
68 printf("Sub command must start with 0x\n");
72 if (!strcmp(argv
[2], "-"))
75 file
= fopen(argv
[2], "r");
77 NLA_PUT_U32(msg
, NL80211_ATTR_VENDOR_ID
, oui
);
78 NLA_PUT_U32(msg
, NL80211_ATTR_VENDOR_SUBCMD
, subcmd
);
81 count
= read_file(file
, buf
, sizeof(buf
));
84 count
= read_hex(argc
- 2, &argv
[2], buf
, sizeof(buf
));
90 NLA_PUT(msg
, NL80211_ATTR_VENDOR_DATA
, count
, buf
);
98 COMMAND(vendor
, send
, "<oui> <subcmd> <filename|-|hex data>", NL80211_CMD_VENDOR
, 0, CIB_NETDEV
, handle_vendor
, "");