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 print_vendor_response(struct nl_msg
*msg
, void *arg
)
18 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
19 bool print_ascii
= (bool) arg
;
23 attr
= nla_find(genlmsg_attrdata(gnlh
, 0),
24 genlmsg_attrlen(gnlh
, 0),
25 NL80211_ATTR_VENDOR_DATA
);
27 fprintf(stderr
, "vendor data attribute missing!\n");
31 data
= (uint8_t *) nla_data(attr
);
35 iw_hexdump("vendor response", data
, len
);
37 fwrite(data
, 1, len
, stdout
);
42 static int read_file(FILE *file
, char *buf
, size_t size
)
47 while ((data
= fgetc(file
)) != EOF
) {
57 static int read_hex(unsigned int argc
, char **argv
, char *buf
, size_t size
)
65 for (i
= 0; i
< argc
; i
++) {
66 res
= sscanf(argv
[i
], "0x%x", &data
);
67 if (res
!= 1 || data
> 0xff)
75 static int handle_vendor(struct nl80211_state
*state
,
76 struct nl_msg
*msg
, int argc
, char **argv
,
88 res
= sscanf(argv
[0], "0x%x", &oui
);
90 printf("Vendor command must start with 0x\n");
94 res
= sscanf(argv
[1], "0x%x", &subcmd
);
96 printf("Sub command must start with 0x\n");
100 if (!strcmp(argv
[2], "-"))
103 file
= fopen(argv
[2], "r");
105 NLA_PUT_U32(msg
, NL80211_ATTR_VENDOR_ID
, oui
);
106 NLA_PUT_U32(msg
, NL80211_ATTR_VENDOR_SUBCMD
, subcmd
);
109 count
= read_file(file
, buf
, sizeof(buf
));
113 count
= read_hex(argc
- 2, &argv
[2], buf
, sizeof(buf
));
119 NLA_PUT(msg
, NL80211_ATTR_VENDOR_DATA
, count
, buf
);
124 if (file
&& file
!= stdin
)
129 static int handle_vendor_recv(struct nl80211_state
*state
,
130 struct nl_msg
*msg
, int argc
,
131 char **argv
, enum id_input id
)
133 register_handler(print_vendor_response
, (void *) true);
134 return handle_vendor(state
, msg
, argc
, argv
, id
);
137 static int handle_vendor_recv_bin(struct nl80211_state
*state
,
138 struct nl_msg
*msg
, int argc
,
139 char **argv
, enum id_input id
)
141 register_handler(print_vendor_response
, (void *) false);
142 return handle_vendor(state
, msg
, argc
, argv
, id
);
145 COMMAND(vendor
, send
, "<oui> <subcmd> <filename|-|hex data>", NL80211_CMD_VENDOR
, 0, CIB_NETDEV
, handle_vendor
, "");
146 COMMAND(vendor
, recv
, "<oui> <subcmd> <filename|-|hex data>", NL80211_CMD_VENDOR
, 0, CIB_NETDEV
, handle_vendor_recv
, "");
147 COMMAND(vendor
, recvbin
, "<oui> <subcmd> <filename|-|hex data>", NL80211_CMD_VENDOR
, 0, CIB_NETDEV
, handle_vendor_recv_bin
, "");