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