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
)
20 while ((data
= fgetc(file
)) != EOF
) {
30 static int read_hex(unsigned int argc
, char **argv
, char *buf
, size_t size
)
38 for (i
= 0; i
< argc
; i
++) {
39 res
= sscanf(argv
[i
], "0x%x", &data
);
40 if (res
!= 1 || data
> 0xff)
48 static int handle_vendor(struct nl80211_state
*state
,
49 struct nl_msg
*msg
, int argc
, char **argv
,
61 res
= sscanf(argv
[0], "0x%x", &oui
);
63 printf("Vendor command must start with 0x\n");
67 res
= sscanf(argv
[1], "0x%x", &subcmd
);
69 printf("Sub command must start with 0x\n");
73 if (!strcmp(argv
[2], "-"))
76 file
= fopen(argv
[2], "r");
78 NLA_PUT_U32(msg
, NL80211_ATTR_VENDOR_ID
, oui
);
79 NLA_PUT_U32(msg
, NL80211_ATTR_VENDOR_SUBCMD
, subcmd
);
82 count
= read_file(file
, buf
, sizeof(buf
));
85 count
= read_hex(argc
- 2, &argv
[2], buf
, sizeof(buf
));
91 NLA_PUT(msg
, NL80211_ATTR_VENDOR_DATA
, count
, buf
);
99 COMMAND(vendor
, send
, "<oui> <subcmd> <filename|-|hex data>", NL80211_CMD_VENDOR
, 0, CIB_NETDEV
, handle_vendor
, "");