]>
Commit | Line | Data |
---|---|---|
45c7212c | 1 | #include <errno.h> |
d5ac8ad3 | 2 | #include <string.h> |
d17fe27e | 3 | #include <stdbool.h> |
2ef1be68 | 4 | |
45c7212c JB |
5 | #include <netlink/genl/genl.h> |
6 | #include <netlink/genl/family.h> | |
7 | #include <netlink/genl/ctrl.h> | |
8 | #include <netlink/msg.h> | |
9 | #include <netlink/attr.h> | |
45c7212c | 10 | |
f408e01b | 11 | #include "nl80211.h" |
45c7212c JB |
12 | #include "iw.h" |
13 | ||
1ae3d621 JB |
14 | #define VALID_FLAGS "none: no special flags\n"\ |
15 | "fcsfail: show frames with FCS errors\n"\ | |
16 | "control: show control frames\n"\ | |
17 | "otherbss: show frames from other BSSes\n"\ | |
068ee232 | 18 | "cook: use cooked mode\n"\ |
386bacb2 AE |
19 | "active: use active mode (ACK incoming unicast packets)\n"\ |
20 | "mumimo-groupid <GROUP_ID>: use MUMIMO according to a group id\n"\ | |
21 | "mumimo-follow-mac <MAC_ADDRESS>: use MUMIMO according to a MAC address" | |
1ae3d621 | 22 | |
4698bfc2 JB |
23 | SECTION(interface); |
24 | ||
cd293761 | 25 | static char *mntr_flags[NL80211_MNTR_FLAG_MAX + 1] = { |
dd65496b | 26 | "none", |
cd293761 JB |
27 | "fcsfail", |
28 | "plcpfail", | |
29 | "control", | |
30 | "otherbss", | |
31 | "cook", | |
068ee232 | 32 | "active", |
cd293761 JB |
33 | }; |
34 | ||
386bacb2 AE |
35 | static int parse_mumimo_options(int *_argc, char ***_argv, struct nl_msg *msg) |
36 | { | |
37 | uint8_t mumimo_group[VHT_MUMIMO_GROUP_LEN]; | |
38 | unsigned char mac_addr[ETH_ALEN]; | |
39 | char **argv = *_argv; | |
40 | int argc = *_argc; | |
41 | int i; | |
42 | unsigned int val; | |
43 | ||
44 | if (strcmp(*argv, "mumimo-groupid") == 0) { | |
45 | argc--; | |
46 | argv++; | |
47 | if (!argc || strlen(*argv) != VHT_MUMIMO_GROUP_LEN*2) { | |
48 | fprintf(stderr, "Invalid groupID: %s\n", *argv); | |
49 | return 1; | |
50 | } | |
51 | ||
52 | for (i = 0; i < VHT_MUMIMO_GROUP_LEN; i++) { | |
53 | if (sscanf((*argv) + i*2, "%2x", &val) != 1) { | |
54 | fprintf(stderr, "Failed reading groupID\n"); | |
55 | return 1; | |
56 | } | |
57 | mumimo_group[i] = val; | |
58 | } | |
59 | ||
60 | NLA_PUT(msg, | |
61 | NL80211_ATTR_MU_MIMO_GROUP_DATA, | |
62 | VHT_MUMIMO_GROUP_LEN, | |
63 | mumimo_group); | |
64 | argc--; | |
65 | argv++; | |
66 | } else if (strcmp(*argv, "mumimo-follow-mac") == 0) { | |
67 | argc--; | |
68 | argv++; | |
69 | if (!argc || mac_addr_a2n(mac_addr, *argv)) { | |
70 | fprintf(stderr, "Invalid MAC address\n"); | |
71 | return 1; | |
72 | } | |
73 | NLA_PUT(msg, NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR, | |
74 | ETH_ALEN, mac_addr); | |
75 | argc--; | |
76 | argv++; | |
77 | } | |
78 | nla_put_failure: | |
79 | *_argc = argc; | |
80 | *_argv = argv; | |
81 | return 0; | |
82 | } | |
83 | ||
dd65496b JB |
84 | static int parse_mntr_flags(int *_argc, char ***_argv, |
85 | struct nl_msg *msg) | |
86 | { | |
87 | struct nl_msg *flags; | |
88 | int err = -ENOBUFS; | |
89 | enum nl80211_mntr_flags flag; | |
90 | int argc = *_argc; | |
91 | char **argv = *_argv; | |
92 | ||
93 | flags = nlmsg_alloc(); | |
94 | if (!flags) | |
95 | return -ENOMEM; | |
96 | ||
97 | while (argc) { | |
98 | int ok = 0; | |
386bacb2 AE |
99 | |
100 | /* parse MU-MIMO options */ | |
101 | err = parse_mumimo_options(&argc, &argv, msg); | |
102 | if (err) | |
103 | goto out; | |
104 | else if (!argc) | |
105 | break; | |
106 | ||
107 | /* parse monitor flags */ | |
dd65496b | 108 | for (flag = __NL80211_MNTR_FLAG_INVALID; |
e14cc99e | 109 | flag <= NL80211_MNTR_FLAG_MAX; flag++) { |
dd65496b JB |
110 | if (strcmp(*argv, mntr_flags[flag]) == 0) { |
111 | ok = 1; | |
4a3bf753 JB |
112 | /* |
113 | * This shouldn't be adding "flag" if that is | |
114 | * zero, but due to a problem in the kernel's | |
115 | * nl80211 code (using NLA_NESTED policy) it | |
116 | * will reject an empty nested attribute but | |
117 | * not one that contains an invalid attribute | |
118 | */ | |
dd65496b JB |
119 | NLA_PUT_FLAG(flags, flag); |
120 | break; | |
121 | } | |
122 | } | |
123 | if (!ok) { | |
124 | err = -EINVAL; | |
125 | goto out; | |
126 | } | |
127 | argc--; | |
128 | argv++; | |
129 | } | |
130 | ||
131 | nla_put_nested(msg, NL80211_ATTR_MNTR_FLAGS, flags); | |
132 | err = 0; | |
133 | nla_put_failure: | |
134 | out: | |
135 | nlmsg_free(flags); | |
136 | ||
137 | *_argc = argc; | |
138 | *_argv = argv; | |
139 | ||
140 | return err; | |
141 | } | |
142 | ||
1ae3d621 JB |
143 | /* for help */ |
144 | #define IFACE_TYPES "Valid interface types are: managed, ibss, monitor, mesh, wds." | |
145 | ||
d17fe27e JB |
146 | /* return 0 if ok, internal error otherwise */ |
147 | static int get_if_type(int *argc, char ***argv, enum nl80211_iftype *type, | |
148 | bool need_type) | |
45c7212c JB |
149 | { |
150 | char *tpstr; | |
151 | ||
d17fe27e JB |
152 | if (*argc < 1 + !!need_type) |
153 | return 1; | |
45c7212c | 154 | |
d17fe27e JB |
155 | if (need_type && strcmp((*argv)[0], "type")) |
156 | return 1; | |
45c7212c | 157 | |
d17fe27e JB |
158 | tpstr = (*argv)[!!need_type]; |
159 | *argc -= 1 + !!need_type; | |
160 | *argv += 1 + !!need_type; | |
45c7212c JB |
161 | |
162 | if (strcmp(tpstr, "adhoc") == 0 || | |
163 | strcmp(tpstr, "ibss") == 0) { | |
164 | *type = NL80211_IFTYPE_ADHOC; | |
d17fe27e | 165 | return 0; |
3955e524 RL |
166 | } else if (strcmp(tpstr, "ocb") == 0) { |
167 | *type = NL80211_IFTYPE_OCB; | |
168 | return 0; | |
45c7212c JB |
169 | } else if (strcmp(tpstr, "monitor") == 0) { |
170 | *type = NL80211_IFTYPE_MONITOR; | |
d17fe27e | 171 | return 0; |
e08b5488 JB |
172 | } else if (strcmp(tpstr, "master") == 0 || |
173 | strcmp(tpstr, "ap") == 0) { | |
c1d44a6c | 174 | *type = NL80211_IFTYPE_UNSPECIFIED; |
e08b5488 JB |
175 | fprintf(stderr, "You need to run a management daemon, e.g. hostapd,\n"); |
176 | fprintf(stderr, "see http://wireless.kernel.org/en/users/Documentation/hostapd\n"); | |
177 | fprintf(stderr, "for more information on how to do that.\n"); | |
c1d44a6c | 178 | return 2; |
4d3a72da | 179 | } else if (strcmp(tpstr, "__ap") == 0) { |
45c7212c | 180 | *type = NL80211_IFTYPE_AP; |
d17fe27e | 181 | return 0; |
4d3a72da | 182 | } else if (strcmp(tpstr, "__ap_vlan") == 0) { |
45c7212c | 183 | *type = NL80211_IFTYPE_AP_VLAN; |
d17fe27e | 184 | return 0; |
45c7212c JB |
185 | } else if (strcmp(tpstr, "wds") == 0) { |
186 | *type = NL80211_IFTYPE_WDS; | |
d17fe27e | 187 | return 0; |
a65df165 JB |
188 | } else if (strcmp(tpstr, "managed") == 0 || |
189 | strcmp(tpstr, "mgd") == 0 || | |
190 | strcmp(tpstr, "station") == 0) { | |
45c7212c | 191 | *type = NL80211_IFTYPE_STATION; |
d17fe27e | 192 | return 0; |
3d1e8704 | 193 | } else if (strcmp(tpstr, "mp") == 0 || |
a65df165 | 194 | strcmp(tpstr, "mesh") == 0) { |
3d1e8704 | 195 | *type = NL80211_IFTYPE_MESH_POINT; |
d17fe27e | 196 | return 0; |
a4464243 JB |
197 | } else if (strcmp(tpstr, "__p2pcl") == 0) { |
198 | *type = NL80211_IFTYPE_P2P_CLIENT; | |
199 | return 0; | |
8d5d7ba7 JB |
200 | } else if (strcmp(tpstr, "__p2pdev") == 0) { |
201 | *type = NL80211_IFTYPE_P2P_DEVICE; | |
202 | return 0; | |
a4464243 JB |
203 | } else if (strcmp(tpstr, "__p2pgo") == 0) { |
204 | *type = NL80211_IFTYPE_P2P_GO; | |
205 | return 0; | |
ed9b77ec AO |
206 | } else if (strcmp(tpstr, "__nan") == 0) { |
207 | *type = NL80211_IFTYPE_NAN; | |
208 | return 0; | |
45c7212c JB |
209 | } |
210 | ||
45c7212c | 211 | fprintf(stderr, "invalid interface type %s\n", tpstr); |
d17fe27e | 212 | return 2; |
45c7212c JB |
213 | } |
214 | ||
39566cca FF |
215 | static int parse_4addr_flag(const char *value, struct nl_msg *msg) |
216 | { | |
217 | if (strcmp(value, "on") == 0) | |
218 | NLA_PUT_U8(msg, NL80211_ATTR_4ADDR, 1); | |
219 | else if (strcmp(value, "off") == 0) | |
220 | NLA_PUT_U8(msg, NL80211_ATTR_4ADDR, 0); | |
221 | else | |
222 | return 1; | |
223 | return 0; | |
224 | ||
225 | nla_put_failure: | |
226 | return 1; | |
227 | } | |
228 | ||
7c37a24d | 229 | static int handle_interface_add(struct nl80211_state *state, |
bd396f2a | 230 | struct nl_msg *msg, |
05514f95 JB |
231 | int argc, char **argv, |
232 | enum id_input id) | |
45c7212c | 233 | { |
2dfd6bfa | 234 | char *name; |
3d1e8704 | 235 | char *mesh_id = NULL; |
45c7212c | 236 | enum nl80211_iftype type; |
70391ccf | 237 | int tpset; |
ced5522d BG |
238 | unsigned char mac_addr[ETH_ALEN]; |
239 | int found_mac = 0; | |
45c7212c | 240 | |
bd396f2a | 241 | if (argc < 1) |
5e75fd04 | 242 | return 1; |
45c7212c | 243 | |
2dfd6bfa | 244 | name = argv[0]; |
45c7212c JB |
245 | argc--; |
246 | argv++; | |
247 | ||
d17fe27e JB |
248 | tpset = get_if_type(&argc, &argv, &type, true); |
249 | if (tpset) | |
c1d44a6c | 250 | return tpset; |
45c7212c | 251 | |
ced5522d | 252 | try_another: |
3d1e8704 | 253 | if (argc) { |
dd65496b JB |
254 | if (strcmp(argv[0], "mesh_id") == 0) { |
255 | argc--; | |
256 | argv++; | |
257 | ||
258 | if (!argc) | |
259 | return 1; | |
260 | mesh_id = argv[0]; | |
261 | argc--; | |
262 | argv++; | |
ced5522d BG |
263 | } else if (strcmp(argv[0], "addr") == 0) { |
264 | argc--; | |
265 | argv++; | |
266 | if (mac_addr_a2n(mac_addr, argv[0])) { | |
267 | fprintf(stderr, "Invalid MAC address\n"); | |
268 | return 2; | |
269 | } | |
270 | argc--; | |
271 | argv++; | |
272 | found_mac = 1; | |
273 | goto try_another; | |
39566cca FF |
274 | } else if (strcmp(argv[0], "4addr") == 0) { |
275 | argc--; | |
276 | argv++; | |
277 | if (parse_4addr_flag(argv[0], msg)) { | |
278 | fprintf(stderr, "4addr error\n"); | |
279 | return 2; | |
280 | } | |
281 | argc--; | |
282 | argv++; | |
dd65496b JB |
283 | } else if (strcmp(argv[0], "flags") == 0) { |
284 | argc--; | |
285 | argv++; | |
286 | if (parse_mntr_flags(&argc, &argv, msg)) { | |
287 | fprintf(stderr, "flags error\n"); | |
288 | return 2; | |
289 | } | |
290 | } else { | |
5e75fd04 | 291 | return 1; |
dd65496b | 292 | } |
3d1e8704 LCC |
293 | } |
294 | ||
5e75fd04 JB |
295 | if (argc) |
296 | return 1; | |
45c7212c | 297 | |
45c7212c | 298 | NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, name); |
6d28ce25 | 299 | NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, type); |
3d1e8704 LCC |
300 | if (mesh_id) |
301 | NLA_PUT(msg, NL80211_ATTR_MESH_ID, strlen(mesh_id), mesh_id); | |
ced5522d BG |
302 | if (found_mac) |
303 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
45c7212c | 304 | |
70391ccf | 305 | return 0; |
5e75fd04 | 306 | nla_put_failure: |
70391ccf | 307 | return -ENOBUFS; |
45c7212c | 308 | } |
ced5522d | 309 | COMMAND(interface, add, "<name> type <type> [mesh_id <meshid>] [4addr on|off] [flags <flag>*] [addr <mac-addr>]", |
1ae3d621 JB |
310 | NL80211_CMD_NEW_INTERFACE, 0, CIB_PHY, handle_interface_add, |
311 | "Add a new virtual interface with the given configuration.\n" | |
312 | IFACE_TYPES "\n\n" | |
313 | "The flags are only used for monitor interfaces, valid flags are:\n" | |
314 | VALID_FLAGS "\n\n" | |
315 | "The mesh_id is used only for mesh mode."); | |
ced5522d | 316 | COMMAND(interface, add, "<name> type <type> [mesh_id <meshid>] [4addr on|off] [flags <flag>*] [addr <mac-addr>]", |
01ae06f9 | 317 | NL80211_CMD_NEW_INTERFACE, 0, CIB_NETDEV, handle_interface_add, NULL); |
45c7212c | 318 | |
7c37a24d | 319 | static int handle_interface_del(struct nl80211_state *state, |
bd396f2a | 320 | struct nl_msg *msg, |
05514f95 JB |
321 | int argc, char **argv, |
322 | enum id_input id) | |
3fcfe40e | 323 | { |
70391ccf | 324 | return 0; |
3fcfe40e | 325 | } |
1ae3d621 JB |
326 | TOPLEVEL(del, NULL, NL80211_CMD_DEL_INTERFACE, 0, CIB_NETDEV, handle_interface_del, |
327 | "Remove this virtual interface"); | |
ce5af55c | 328 | HIDDEN(interface, del, NULL, NL80211_CMD_DEL_INTERFACE, 0, CIB_NETDEV, handle_interface_del); |
3fcfe40e | 329 | |
3adcc1f4 PF |
330 | static char *channel_type_name(enum nl80211_channel_type channel_type) |
331 | { | |
332 | switch (channel_type) { | |
333 | case NL80211_CHAN_NO_HT: | |
334 | return "NO HT"; | |
335 | case NL80211_CHAN_HT20: | |
336 | return "HT20"; | |
337 | case NL80211_CHAN_HT40MINUS: | |
338 | return "HT40-"; | |
339 | case NL80211_CHAN_HT40PLUS: | |
340 | return "HT40+"; | |
341 | default: | |
342 | return "unknown"; | |
343 | } | |
344 | } | |
345 | ||
c5df9eb6 | 346 | char *channel_width_name(enum nl80211_chan_width width) |
7c60bb76 JB |
347 | { |
348 | switch (width) { | |
349 | case NL80211_CHAN_WIDTH_20_NOHT: | |
350 | return "20 MHz (no HT)"; | |
351 | case NL80211_CHAN_WIDTH_20: | |
352 | return "20 MHz"; | |
353 | case NL80211_CHAN_WIDTH_40: | |
354 | return "40 MHz"; | |
355 | case NL80211_CHAN_WIDTH_80: | |
356 | return "80 MHz"; | |
357 | case NL80211_CHAN_WIDTH_80P80: | |
358 | return "80+80 MHz"; | |
359 | case NL80211_CHAN_WIDTH_160: | |
360 | return "160 MHz"; | |
432b5ae2 BC |
361 | case NL80211_CHAN_WIDTH_5: |
362 | return "5 MHz"; | |
363 | case NL80211_CHAN_WIDTH_10: | |
364 | return "10 MHz"; | |
7c60bb76 JB |
365 | default: |
366 | return "unknown"; | |
367 | } | |
368 | } | |
369 | ||
541ef425 JB |
370 | static int print_iface_handler(struct nl_msg *msg, void *arg) |
371 | { | |
372 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
373 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; | |
674567b8 JB |
374 | unsigned int *wiphy = arg; |
375 | const char *indent = ""; | |
541ef425 JB |
376 | |
377 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
378 | genlmsg_attrlen(gnlh, 0), NULL); | |
379 | ||
674567b8 JB |
380 | if (wiphy && tb_msg[NL80211_ATTR_WIPHY]) { |
381 | unsigned int thiswiphy = nla_get_u32(tb_msg[NL80211_ATTR_WIPHY]); | |
382 | indent = "\t"; | |
383 | if (*wiphy != thiswiphy) | |
384 | printf("phy#%d\n", thiswiphy); | |
385 | *wiphy = thiswiphy; | |
386 | } | |
387 | ||
541ef425 | 388 | if (tb_msg[NL80211_ATTR_IFNAME]) |
674567b8 | 389 | printf("%sInterface %s\n", indent, nla_get_string(tb_msg[NL80211_ATTR_IFNAME])); |
3508c5c9 JB |
390 | else |
391 | printf("%sUnnamed/non-netdev interface\n", indent); | |
541ef425 | 392 | if (tb_msg[NL80211_ATTR_IFINDEX]) |
674567b8 | 393 | printf("%s\tifindex %d\n", indent, nla_get_u32(tb_msg[NL80211_ATTR_IFINDEX])); |
3508c5c9 JB |
394 | if (tb_msg[NL80211_ATTR_WDEV]) |
395 | printf("%s\twdev 0x%llx\n", indent, | |
396 | (unsigned long long)nla_get_u64(tb_msg[NL80211_ATTR_WDEV])); | |
397 | if (tb_msg[NL80211_ATTR_MAC]) { | |
398 | char mac_addr[20]; | |
399 | mac_addr_n2a(mac_addr, nla_data(tb_msg[NL80211_ATTR_MAC])); | |
400 | printf("%s\taddr %s\n", indent, mac_addr); | |
401 | } | |
01009c3d AQ |
402 | if (tb_msg[NL80211_ATTR_SSID]) { |
403 | printf("%s\tssid ", indent); | |
404 | print_ssid_escaped(nla_len(tb_msg[NL80211_ATTR_SSID]), | |
405 | nla_data(tb_msg[NL80211_ATTR_SSID])); | |
406 | printf("\n"); | |
407 | } | |
541ef425 | 408 | if (tb_msg[NL80211_ATTR_IFTYPE]) |
674567b8 | 409 | printf("%s\ttype %s\n", indent, iftype_name(nla_get_u32(tb_msg[NL80211_ATTR_IFTYPE]))); |
47b76de4 | 410 | if (!wiphy && tb_msg[NL80211_ATTR_WIPHY]) |
5b050af4 | 411 | printf("%s\twiphy %d\n", indent, nla_get_u32(tb_msg[NL80211_ATTR_WIPHY])); |
3adcc1f4 PF |
412 | if (tb_msg[NL80211_ATTR_WIPHY_FREQ]) { |
413 | uint32_t freq = nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_FREQ]); | |
3adcc1f4 | 414 | |
7c60bb76 JB |
415 | printf("%s\tchannel %d (%d MHz)", indent, |
416 | ieee80211_frequency_to_channel(freq), freq); | |
417 | ||
418 | if (tb_msg[NL80211_ATTR_CHANNEL_WIDTH]) { | |
419 | printf(", width: %s", | |
420 | channel_width_name(nla_get_u32(tb_msg[NL80211_ATTR_CHANNEL_WIDTH]))); | |
421 | if (tb_msg[NL80211_ATTR_CENTER_FREQ1]) | |
422 | printf(", center1: %d MHz", | |
423 | nla_get_u32(tb_msg[NL80211_ATTR_CENTER_FREQ1])); | |
424 | if (tb_msg[NL80211_ATTR_CENTER_FREQ2]) | |
425 | printf(", center2: %d MHz", | |
426 | nla_get_u32(tb_msg[NL80211_ATTR_CENTER_FREQ2])); | |
427 | } else if (tb_msg[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { | |
428 | enum nl80211_channel_type channel_type; | |
429 | ||
3adcc1f4 | 430 | channel_type = nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
7c60bb76 JB |
431 | printf(" %s", channel_type_name(channel_type)); |
432 | } | |
3adcc1f4 | 433 | |
7c60bb76 | 434 | printf("\n"); |
3adcc1f4 | 435 | } |
541ef425 | 436 | |
619d28ab | 437 | if (tb_msg[NL80211_ATTR_WIPHY_TX_POWER_LEVEL]) { |
71340cdc | 438 | int32_t txp = nla_get_u32(tb_msg[NL80211_ATTR_WIPHY_TX_POWER_LEVEL]); |
619d28ab RM |
439 | |
440 | printf("%s\ttxpower %d.%.2d dBm\n", | |
441 | indent, txp / 100, txp % 100); | |
442 | } | |
443 | ||
910792c0 THJ |
444 | if (tb_msg[NL80211_ATTR_TXQ_STATS]) { |
445 | char buf[150]; | |
446 | parse_txq_stats(buf, sizeof(buf), tb_msg[NL80211_ATTR_TXQ_STATS], 1, -1, indent); | |
447 | printf("%s\tmulticast TXQ:%s\n", indent, buf); | |
448 | } | |
449 | ||
e99bc38e AQ |
450 | if (tb_msg[NL80211_ATTR_4ADDR]) { |
451 | uint8_t use_4addr = nla_get_u8(tb_msg[NL80211_ATTR_4ADDR]); | |
452 | if (use_4addr) | |
453 | printf("%s\t4addr: on\n", indent); | |
454 | } | |
455 | ||
541ef425 JB |
456 | return NL_SKIP; |
457 | } | |
458 | ||
7c37a24d | 459 | static int handle_interface_info(struct nl80211_state *state, |
bd396f2a | 460 | struct nl_msg *msg, |
05514f95 JB |
461 | int argc, char **argv, |
462 | enum id_input id) | |
541ef425 | 463 | { |
34b23014 | 464 | register_handler(print_iface_handler, NULL); |
70391ccf | 465 | return 0; |
541ef425 | 466 | } |
1ae3d621 JB |
467 | TOPLEVEL(info, NULL, NL80211_CMD_GET_INTERFACE, 0, CIB_NETDEV, handle_interface_info, |
468 | "Show information for this interface."); | |
cd293761 | 469 | |
7c37a24d | 470 | static int handle_interface_set(struct nl80211_state *state, |
cd293761 | 471 | struct nl_msg *msg, |
05514f95 JB |
472 | int argc, char **argv, |
473 | enum id_input id) | |
cd293761 | 474 | { |
cd293761 JB |
475 | if (!argc) |
476 | return 1; | |
477 | ||
cd293761 JB |
478 | NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, NL80211_IFTYPE_MONITOR); |
479 | ||
dd65496b JB |
480 | switch (parse_mntr_flags(&argc, &argv, msg)) { |
481 | case 0: | |
482 | return 0; | |
386bacb2 AE |
483 | case 1: |
484 | return 1; | |
dd65496b JB |
485 | case -ENOMEM: |
486 | fprintf(stderr, "failed to allocate flags\n"); | |
487 | return 2; | |
488 | case -EINVAL: | |
489 | fprintf(stderr, "unknown flag %s\n", *argv); | |
490 | return 2; | |
491 | default: | |
492 | return 2; | |
cd293761 | 493 | } |
cd293761 | 494 | nla_put_failure: |
dd65496b | 495 | return -ENOBUFS; |
cd293761 | 496 | } |
1ae3d621 JB |
497 | COMMAND(set, monitor, "<flag>*", |
498 | NL80211_CMD_SET_INTERFACE, 0, CIB_NETDEV, handle_interface_set, | |
499 | "Set monitor flags. Valid flags are:\n" | |
500 | VALID_FLAGS); | |
82d028d0 | 501 | |
7c37a24d | 502 | static int handle_interface_meshid(struct nl80211_state *state, |
82d028d0 | 503 | struct nl_msg *msg, |
05514f95 JB |
504 | int argc, char **argv, |
505 | enum id_input id) | |
82d028d0 JB |
506 | { |
507 | char *mesh_id = NULL; | |
508 | ||
509 | if (argc != 1) | |
510 | return 1; | |
511 | ||
512 | mesh_id = argv[0]; | |
513 | ||
514 | NLA_PUT(msg, NL80211_ATTR_MESH_ID, strlen(mesh_id), mesh_id); | |
515 | ||
516 | return 0; | |
517 | nla_put_failure: | |
518 | return -ENOBUFS; | |
519 | } | |
520 | COMMAND(set, meshid, "<meshid>", | |
01ae06f9 | 521 | NL80211_CMD_SET_INTERFACE, 0, CIB_NETDEV, handle_interface_meshid, NULL); |
674567b8 JB |
522 | |
523 | static unsigned int dev_dump_wiphy; | |
524 | ||
525 | static int handle_dev_dump(struct nl80211_state *state, | |
674567b8 | 526 | struct nl_msg *msg, |
05514f95 JB |
527 | int argc, char **argv, |
528 | enum id_input id) | |
674567b8 JB |
529 | { |
530 | dev_dump_wiphy = -1; | |
34b23014 | 531 | register_handler(print_iface_handler, &dev_dump_wiphy); |
674567b8 JB |
532 | return 0; |
533 | } | |
1ae3d621 JB |
534 | TOPLEVEL(dev, NULL, NL80211_CMD_GET_INTERFACE, NLM_F_DUMP, CIB_NONE, handle_dev_dump, |
535 | "List all network interfaces for wireless hardware."); | |
d17fe27e JB |
536 | |
537 | static int handle_interface_type(struct nl80211_state *state, | |
d17fe27e | 538 | struct nl_msg *msg, |
05514f95 JB |
539 | int argc, char **argv, |
540 | enum id_input id) | |
d17fe27e JB |
541 | { |
542 | enum nl80211_iftype type; | |
543 | int tpset; | |
544 | ||
545 | tpset = get_if_type(&argc, &argv, &type, false); | |
546 | if (tpset) | |
547 | return tpset; | |
548 | ||
549 | if (argc) | |
550 | return 1; | |
551 | ||
552 | NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, type); | |
553 | ||
554 | return 0; | |
555 | nla_put_failure: | |
556 | return -ENOBUFS; | |
557 | } | |
558 | COMMAND(set, type, "<type>", | |
1ae3d621 JB |
559 | NL80211_CMD_SET_INTERFACE, 0, CIB_NETDEV, handle_interface_type, |
560 | "Set interface type/mode.\n" | |
561 | IFACE_TYPES); | |
20e4ff8a JF |
562 | |
563 | static int handle_interface_4addr(struct nl80211_state *state, | |
05514f95 JB |
564 | struct nl_msg *msg, |
565 | int argc, char **argv, | |
566 | enum id_input id) | |
20e4ff8a JF |
567 | { |
568 | if (argc != 1) | |
569 | return 1; | |
570 | return parse_4addr_flag(argv[0], msg); | |
571 | } | |
572 | COMMAND(set, 4addr, "<on|off>", | |
573 | NL80211_CMD_SET_INTERFACE, 0, CIB_NETDEV, handle_interface_4addr, | |
5548dfd7 | 574 | "Set interface 4addr (WDS) mode."); |
88c06599 | 575 | |
83a7bd0d | 576 | static int handle_interface_noack_map(struct nl80211_state *state, |
83a7bd0d | 577 | struct nl_msg *msg, |
05514f95 JB |
578 | int argc, char **argv, |
579 | enum id_input id) | |
83a7bd0d SW |
580 | { |
581 | uint16_t noack_map; | |
582 | char *end; | |
583 | ||
584 | if (argc != 1) | |
585 | return 1; | |
586 | ||
587 | noack_map = strtoul(argv[0], &end, 16); | |
588 | if (*end) | |
589 | return 1; | |
590 | ||
591 | NLA_PUT_U16(msg, NL80211_ATTR_NOACK_MAP, noack_map); | |
592 | ||
593 | return 0; | |
594 | nla_put_failure: | |
595 | return -ENOBUFS; | |
596 | ||
597 | } | |
598 | COMMAND(set, noack_map, "<map>", | |
599 | NL80211_CMD_SET_NOACK_MAP, 0, CIB_NETDEV, handle_interface_noack_map, | |
600 | "Set the NoAck map for the TIDs. (0x0009 = BE, 0x0006 = BK, 0x0030 = VI, 0x00C0 = VO)"); | |
601 | ||
602 | ||
88c06599 | 603 | static int handle_interface_wds_peer(struct nl80211_state *state, |
88c06599 | 604 | struct nl_msg *msg, |
05514f95 JB |
605 | int argc, char **argv, |
606 | enum id_input id) | |
88c06599 BJ |
607 | { |
608 | unsigned char mac_addr[ETH_ALEN]; | |
609 | ||
610 | if (argc < 1) | |
611 | return 1; | |
612 | ||
613 | if (mac_addr_a2n(mac_addr, argv[0])) { | |
5548dfd7 | 614 | fprintf(stderr, "Invalid MAC address\n"); |
88c06599 BJ |
615 | return 2; |
616 | } | |
617 | ||
618 | argc--; | |
619 | argv++; | |
620 | ||
621 | if (argc) | |
622 | return 1; | |
623 | ||
624 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
625 | ||
626 | return 0; | |
627 | nla_put_failure: | |
628 | return -ENOBUFS; | |
629 | } | |
630 | COMMAND(set, peer, "<MAC address>", | |
631 | NL80211_CMD_SET_WDS_PEER, 0, CIB_NETDEV, handle_interface_wds_peer, | |
5548dfd7 | 632 | "Set interface WDS peer."); |
ffaac0f7 AQ |
633 | |
634 | static int set_mcast_rate(struct nl80211_state *state, | |
ffaac0f7 AQ |
635 | struct nl_msg *msg, |
636 | int argc, char **argv, | |
637 | enum id_input id) | |
638 | { | |
639 | float rate; | |
640 | char *end; | |
641 | ||
86a9801f OO |
642 | if (argc != 1) |
643 | return 1; | |
ffaac0f7 AQ |
644 | |
645 | rate = strtod(argv[0], &end); | |
646 | if (*end != '\0') | |
647 | return 1; | |
648 | ||
649 | NLA_PUT_U32(msg, NL80211_ATTR_MCAST_RATE, (int)(rate * 10)); | |
650 | ||
651 | return 0; | |
652 | nla_put_failure: | |
653 | return -ENOBUFS; | |
654 | } | |
655 | ||
656 | COMMAND(set, mcast_rate, "<rate in Mbps>", | |
657 | NL80211_CMD_SET_MCAST_RATE, 0, CIB_NETDEV, set_mcast_rate, | |
658 | "Set the multicast bitrate."); | |
444674c8 BB |
659 | |
660 | ||
661 | static int handle_chanfreq(struct nl80211_state *state, struct nl_msg *msg, | |
662 | bool chan, int argc, char **argv, | |
663 | enum id_input id) | |
664 | { | |
665 | struct chandef chandef; | |
666 | int res; | |
667 | int parsed; | |
668 | char *end; | |
669 | ||
670 | res = parse_freqchan(&chandef, chan, argc, argv, &parsed); | |
671 | if (res) | |
672 | return res; | |
673 | ||
674 | argc -= parsed; | |
675 | argv += parsed; | |
676 | ||
677 | while (argc) { | |
678 | unsigned int beacons = 10; | |
679 | ||
680 | if (strcmp(argv[0], "beacons") == 0) { | |
681 | if (argc < 2) | |
682 | return 1; | |
683 | ||
684 | beacons = strtol(argv[1], &end, 10); | |
685 | if (*end) | |
686 | return 1; | |
687 | ||
688 | argc -= 2; | |
689 | argv += 2; | |
690 | ||
691 | NLA_PUT_U32(msg, NL80211_ATTR_CH_SWITCH_COUNT, beacons); | |
692 | } else if (strcmp(argv[0], "block-tx") == 0) { | |
693 | argc -= 1; | |
694 | argv += 1; | |
695 | ||
696 | NLA_PUT_FLAG(msg, NL80211_ATTR_CH_SWITCH_BLOCK_TX); | |
697 | } else { | |
698 | return 1; | |
699 | } | |
700 | } | |
701 | ||
702 | return put_chandef(msg, &chandef); | |
703 | ||
704 | nla_put_failure: | |
705 | return -ENOBUFS; | |
706 | } | |
707 | ||
708 | static int handle_freq(struct nl80211_state *state, struct nl_msg *msg, | |
709 | int argc, char **argv, | |
710 | enum id_input id) | |
711 | { | |
712 | return handle_chanfreq(state, msg, false, argc, argv, id); | |
713 | } | |
714 | ||
715 | static int handle_chan(struct nl80211_state *state, struct nl_msg *msg, | |
716 | int argc, char **argv, | |
717 | enum id_input id) | |
718 | { | |
719 | return handle_chanfreq(state, msg, true, argc, argv, id); | |
720 | } | |
721 | ||
722 | SECTION(switch); | |
723 | COMMAND(switch, freq, | |
724 | "<freq> [NOHT|HT20|HT40+|HT40-|5MHz|10MHz|80MHz] [beacons <count>] [block-tx]\n" | |
725 | "<control freq> [5|10|20|40|80|80+80|160] [<center1_freq> [<center2_freq>]] [beacons <count>] [block-tx]", | |
726 | NL80211_CMD_CHANNEL_SWITCH, 0, CIB_NETDEV, handle_freq, | |
727 | "Switch the operating channel by sending a channel switch announcement (CSA)."); | |
728 | COMMAND(switch, channel, "<channel> [NOHT|HT20|HT40+|HT40-|5MHz|10MHz|80MHz] [beacons <count>] [block-tx]", | |
729 | NL80211_CMD_CHANNEL_SWITCH, 0, CIB_NETDEV, handle_chan, NULL); |