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