]>
Commit | Line | Data |
---|---|---|
2ef1be68 | 1 | #include <net/if.h> |
3d1e8704 | 2 | #include <errno.h> |
d5ac8ad3 | 3 | #include <string.h> |
2ef1be68 | 4 | |
3d1e8704 LCC |
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> | |
3d1e8704 | 10 | |
f408e01b | 11 | #include "nl80211.h" |
3d1e8704 LCC |
12 | #include "iw.h" |
13 | ||
4698bfc2 JB |
14 | SECTION(station); |
15 | ||
3d1e8704 LCC |
16 | enum plink_state { |
17 | LISTEN, | |
18 | OPN_SNT, | |
19 | OPN_RCVD, | |
20 | CNF_RCVD, | |
21 | ESTAB, | |
22 | HOLDING, | |
23 | BLOCKED | |
24 | }; | |
25 | ||
8012ad28 MP |
26 | static void print_power_mode(struct nlattr *a) |
27 | { | |
28 | enum nl80211_mesh_power_mode pm = nla_get_u32(a); | |
29 | ||
30 | switch (pm) { | |
31 | case NL80211_MESH_POWER_ACTIVE: | |
32 | printf("ACTIVE"); | |
33 | break; | |
34 | case NL80211_MESH_POWER_LIGHT_SLEEP: | |
35 | printf("LIGHT SLEEP"); | |
36 | break; | |
37 | case NL80211_MESH_POWER_DEEP_SLEEP: | |
38 | printf("DEEP SLEEP"); | |
39 | break; | |
40 | default: | |
41 | printf("UNKNOWN"); | |
42 | break; | |
43 | } | |
44 | } | |
3d1e8704 | 45 | |
e94f0201 | 46 | void parse_bitrate(struct nlattr *bitrate_attr, char *buf, int buflen) |
64179590 JB |
47 | { |
48 | int rate = 0; | |
49 | char *pos = buf; | |
50 | struct nlattr *rinfo[NL80211_RATE_INFO_MAX + 1]; | |
51 | static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = { | |
52 | [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 }, | |
53 | [NL80211_RATE_INFO_BITRATE32] = { .type = NLA_U32 }, | |
54 | [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 }, | |
55 | [NL80211_RATE_INFO_40_MHZ_WIDTH] = { .type = NLA_FLAG }, | |
56 | [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG }, | |
57 | }; | |
58 | ||
59 | if (nla_parse_nested(rinfo, NL80211_RATE_INFO_MAX, | |
60 | bitrate_attr, rate_policy)) { | |
61 | snprintf(buf, buflen, "failed to parse nested rate attributes!"); | |
62 | return; | |
63 | } | |
64 | ||
65 | if (rinfo[NL80211_RATE_INFO_BITRATE32]) | |
66 | rate = nla_get_u32(rinfo[NL80211_RATE_INFO_BITRATE32]); | |
67 | else if (rinfo[NL80211_RATE_INFO_BITRATE]) | |
68 | rate = nla_get_u16(rinfo[NL80211_RATE_INFO_BITRATE]); | |
69 | if (rate > 0) | |
70 | pos += snprintf(pos, buflen - (pos - buf), | |
71 | "%d.%d MBit/s", rate / 10, rate % 10); | |
72 | ||
73 | if (rinfo[NL80211_RATE_INFO_MCS]) | |
74 | pos += snprintf(pos, buflen - (pos - buf), | |
75 | " MCS %d", nla_get_u8(rinfo[NL80211_RATE_INFO_MCS])); | |
76 | if (rinfo[NL80211_RATE_INFO_VHT_MCS]) | |
77 | pos += snprintf(pos, buflen - (pos - buf), | |
78 | " VHT-MCS %d", nla_get_u8(rinfo[NL80211_RATE_INFO_VHT_MCS])); | |
79 | if (rinfo[NL80211_RATE_INFO_40_MHZ_WIDTH]) | |
80 | pos += snprintf(pos, buflen - (pos - buf), " 40MHz"); | |
81 | if (rinfo[NL80211_RATE_INFO_80_MHZ_WIDTH]) | |
82 | pos += snprintf(pos, buflen - (pos - buf), " 80MHz"); | |
83 | if (rinfo[NL80211_RATE_INFO_80P80_MHZ_WIDTH]) | |
84 | pos += snprintf(pos, buflen - (pos - buf), " 80P80MHz"); | |
85 | if (rinfo[NL80211_RATE_INFO_160_MHZ_WIDTH]) | |
86 | pos += snprintf(pos, buflen - (pos - buf), " 160MHz"); | |
87 | if (rinfo[NL80211_RATE_INFO_SHORT_GI]) | |
88 | pos += snprintf(pos, buflen - (pos - buf), " short GI"); | |
89 | if (rinfo[NL80211_RATE_INFO_VHT_NSS]) | |
90 | pos += snprintf(pos, buflen - (pos - buf), | |
91 | " VHT-NSS %d", nla_get_u8(rinfo[NL80211_RATE_INFO_VHT_NSS])); | |
92 | } | |
93 | ||
3d1e8704 LCC |
94 | static int print_sta_handler(struct nl_msg *msg, void *arg) |
95 | { | |
96 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
97 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
98 | struct nlattr *sinfo[NL80211_STA_INFO_MAX + 1]; | |
99 | char mac_addr[20], state_name[10], dev[20]; | |
b638215d | 100 | struct nl80211_sta_flag_update *sta_flags; |
3d1e8704 LCC |
101 | static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = { |
102 | [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 }, | |
103 | [NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 }, | |
104 | [NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 }, | |
859677cb JB |
105 | [NL80211_STA_INFO_RX_PACKETS] = { .type = NLA_U32 }, |
106 | [NL80211_STA_INFO_TX_PACKETS] = { .type = NLA_U32 }, | |
9cd3f1c1 | 107 | [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 }, |
ea3ade85 | 108 | [NL80211_STA_INFO_T_OFFSET] = { .type = NLA_U64 }, |
9cd3f1c1 | 109 | [NL80211_STA_INFO_TX_BITRATE] = { .type = NLA_NESTED }, |
e94f0201 | 110 | [NL80211_STA_INFO_RX_BITRATE] = { .type = NLA_NESTED }, |
3d1e8704 LCC |
111 | [NL80211_STA_INFO_LLID] = { .type = NLA_U16 }, |
112 | [NL80211_STA_INFO_PLID] = { .type = NLA_U16 }, | |
113 | [NL80211_STA_INFO_PLINK_STATE] = { .type = NLA_U8 }, | |
0f5868ee BR |
114 | [NL80211_STA_INFO_TX_RETRIES] = { .type = NLA_U32 }, |
115 | [NL80211_STA_INFO_TX_FAILED] = { .type = NLA_U32 }, | |
b638215d HS |
116 | [NL80211_STA_INFO_STA_FLAGS] = |
117 | { .minlen = sizeof(struct nl80211_sta_flag_update) }, | |
8012ad28 MP |
118 | [NL80211_STA_INFO_LOCAL_PM] = { .type = NLA_U32}, |
119 | [NL80211_STA_INFO_PEER_PM] = { .type = NLA_U32}, | |
120 | [NL80211_STA_INFO_NONPEER_PM] = { .type = NLA_U32}, | |
3d1e8704 LCC |
121 | }; |
122 | ||
123 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
124 | genlmsg_attrlen(gnlh, 0), NULL); | |
125 | ||
126 | /* | |
127 | * TODO: validate the interface and mac address! | |
128 | * Otherwise, there's a race condition as soon as | |
129 | * the kernel starts sending station notifications. | |
130 | */ | |
131 | ||
132 | if (!tb[NL80211_ATTR_STA_INFO]) { | |
5fe70c0e | 133 | fprintf(stderr, "sta stats missing!\n"); |
3d1e8704 LCC |
134 | return NL_SKIP; |
135 | } | |
136 | if (nla_parse_nested(sinfo, NL80211_STA_INFO_MAX, | |
137 | tb[NL80211_ATTR_STA_INFO], | |
138 | stats_policy)) { | |
5fe70c0e | 139 | fprintf(stderr, "failed to parse nested attributes!\n"); |
3d1e8704 LCC |
140 | return NL_SKIP; |
141 | } | |
142 | ||
143 | mac_addr_n2a(mac_addr, nla_data(tb[NL80211_ATTR_MAC])); | |
144 | if_indextoname(nla_get_u32(tb[NL80211_ATTR_IFINDEX]), dev); | |
fbb181fa | 145 | printf("Station %s (on %s)", mac_addr, dev); |
3d1e8704 LCC |
146 | |
147 | if (sinfo[NL80211_STA_INFO_INACTIVE_TIME]) | |
f5c9799c | 148 | printf("\n\tinactive time:\t%u ms", |
3d1e8704 LCC |
149 | nla_get_u32(sinfo[NL80211_STA_INFO_INACTIVE_TIME])); |
150 | if (sinfo[NL80211_STA_INFO_RX_BYTES]) | |
f5c9799c | 151 | printf("\n\trx bytes:\t%u", |
3d1e8704 | 152 | nla_get_u32(sinfo[NL80211_STA_INFO_RX_BYTES])); |
859677cb | 153 | if (sinfo[NL80211_STA_INFO_RX_PACKETS]) |
f5c9799c | 154 | printf("\n\trx packets:\t%u", |
859677cb | 155 | nla_get_u32(sinfo[NL80211_STA_INFO_RX_PACKETS])); |
3d1e8704 | 156 | if (sinfo[NL80211_STA_INFO_TX_BYTES]) |
f5c9799c | 157 | printf("\n\ttx bytes:\t%u", |
3d1e8704 | 158 | nla_get_u32(sinfo[NL80211_STA_INFO_TX_BYTES])); |
859677cb | 159 | if (sinfo[NL80211_STA_INFO_TX_PACKETS]) |
f5c9799c | 160 | printf("\n\ttx packets:\t%u", |
859677cb | 161 | nla_get_u32(sinfo[NL80211_STA_INFO_TX_PACKETS])); |
0f5868ee BR |
162 | if (sinfo[NL80211_STA_INFO_TX_RETRIES]) |
163 | printf("\n\ttx retries:\t%u", | |
164 | nla_get_u32(sinfo[NL80211_STA_INFO_TX_RETRIES])); | |
165 | if (sinfo[NL80211_STA_INFO_TX_FAILED]) | |
166 | printf("\n\ttx failed:\t%u", | |
167 | nla_get_u32(sinfo[NL80211_STA_INFO_TX_FAILED])); | |
9cd3f1c1 HR |
168 | if (sinfo[NL80211_STA_INFO_SIGNAL]) |
169 | printf("\n\tsignal: \t%d dBm", | |
170 | (int8_t)nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL])); | |
ba292ae9 BR |
171 | if (sinfo[NL80211_STA_INFO_SIGNAL_AVG]) |
172 | printf("\n\tsignal avg:\t%d dBm", | |
173 | (int8_t)nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL_AVG])); | |
ea3ade85 AN |
174 | if (sinfo[NL80211_STA_INFO_T_OFFSET]) |
175 | printf("\n\tToffset:\t%lld us", | |
176 | (unsigned long long)nla_get_u64(sinfo[NL80211_STA_INFO_T_OFFSET])); | |
9cd3f1c1 HR |
177 | |
178 | if (sinfo[NL80211_STA_INFO_TX_BITRATE]) { | |
64179590 JB |
179 | char buf[100]; |
180 | ||
e94f0201 | 181 | parse_bitrate(sinfo[NL80211_STA_INFO_TX_BITRATE], buf, sizeof(buf)); |
64179590 | 182 | printf("\n\ttx bitrate:\t%s", buf); |
9cd3f1c1 HR |
183 | } |
184 | ||
e94f0201 FF |
185 | if (sinfo[NL80211_STA_INFO_RX_BITRATE]) { |
186 | char buf[100]; | |
187 | ||
188 | parse_bitrate(sinfo[NL80211_STA_INFO_RX_BITRATE], buf, sizeof(buf)); | |
189 | printf("\n\trx bitrate:\t%s", buf); | |
190 | } | |
191 | ||
3d1e8704 | 192 | if (sinfo[NL80211_STA_INFO_LLID]) |
fbb181fa | 193 | printf("\n\tmesh llid:\t%d", |
3d1e8704 LCC |
194 | nla_get_u16(sinfo[NL80211_STA_INFO_LLID])); |
195 | if (sinfo[NL80211_STA_INFO_PLID]) | |
fbb181fa | 196 | printf("\n\tmesh plid:\t%d", |
3d1e8704 LCC |
197 | nla_get_u16(sinfo[NL80211_STA_INFO_PLID])); |
198 | if (sinfo[NL80211_STA_INFO_PLINK_STATE]) { | |
dbaabba1 | 199 | switch (nla_get_u8(sinfo[NL80211_STA_INFO_PLINK_STATE])) { |
3d1e8704 LCC |
200 | case LISTEN: |
201 | strcpy(state_name, "LISTEN"); | |
202 | break; | |
203 | case OPN_SNT: | |
204 | strcpy(state_name, "OPN_SNT"); | |
205 | break; | |
206 | case OPN_RCVD: | |
207 | strcpy(state_name, "OPN_RCVD"); | |
208 | break; | |
209 | case CNF_RCVD: | |
210 | strcpy(state_name, "CNF_RCVD"); | |
211 | break; | |
212 | case ESTAB: | |
213 | strcpy(state_name, "ESTAB"); | |
214 | break; | |
215 | case HOLDING: | |
216 | strcpy(state_name, "HOLDING"); | |
217 | break; | |
218 | case BLOCKED: | |
219 | strcpy(state_name, "BLOCKED"); | |
220 | break; | |
221 | default: | |
222 | strcpy(state_name, "UNKNOWN"); | |
223 | break; | |
224 | } | |
fbb181fa | 225 | printf("\n\tmesh plink:\t%s", state_name); |
3d1e8704 | 226 | } |
8012ad28 MP |
227 | if (sinfo[NL80211_STA_INFO_LOCAL_PM]) { |
228 | printf("\n\tmesh local PS mode:\t"); | |
229 | print_power_mode(sinfo[NL80211_STA_INFO_LOCAL_PM]); | |
230 | } | |
231 | if (sinfo[NL80211_STA_INFO_PEER_PM]) { | |
232 | printf("\n\tmesh peer PS mode:\t"); | |
233 | print_power_mode(sinfo[NL80211_STA_INFO_PEER_PM]); | |
234 | } | |
235 | if (sinfo[NL80211_STA_INFO_NONPEER_PM]) { | |
236 | printf("\n\tmesh non-peer PS mode:\t"); | |
237 | print_power_mode(sinfo[NL80211_STA_INFO_NONPEER_PM]); | |
238 | } | |
3d1e8704 | 239 | |
b638215d HS |
240 | if (sinfo[NL80211_STA_INFO_STA_FLAGS]) { |
241 | sta_flags = (struct nl80211_sta_flag_update *) | |
242 | nla_data(sinfo[NL80211_STA_INFO_STA_FLAGS]); | |
243 | ||
244 | if (sta_flags->mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) { | |
245 | printf("\n\tauthorized:\t"); | |
246 | if (sta_flags->set & BIT(NL80211_STA_FLAG_AUTHORIZED)) | |
247 | printf("yes"); | |
248 | else | |
249 | printf("no"); | |
250 | } | |
251 | ||
252 | if (sta_flags->mask & BIT(NL80211_STA_FLAG_AUTHENTICATED)) { | |
253 | printf("\n\tauthenticated:\t"); | |
254 | if (sta_flags->set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) | |
255 | printf("yes"); | |
256 | else | |
257 | printf("no"); | |
258 | } | |
259 | ||
260 | if (sta_flags->mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) { | |
261 | printf("\n\tpreamble:\t"); | |
262 | if (sta_flags->set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) | |
263 | printf("short"); | |
264 | else | |
265 | printf("long"); | |
266 | } | |
267 | ||
268 | if (sta_flags->mask & BIT(NL80211_STA_FLAG_WME)) { | |
269 | printf("\n\tWMM/WME:\t"); | |
270 | if (sta_flags->set & BIT(NL80211_STA_FLAG_WME)) | |
271 | printf("yes"); | |
272 | else | |
273 | printf("no"); | |
274 | } | |
275 | ||
276 | if (sta_flags->mask & BIT(NL80211_STA_FLAG_MFP)) { | |
277 | printf("\n\tMFP:\t\t"); | |
278 | if (sta_flags->set & BIT(NL80211_STA_FLAG_MFP)) | |
279 | printf("yes"); | |
280 | else | |
281 | printf("no"); | |
282 | } | |
283 | ||
284 | if (sta_flags->mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) { | |
1a463ae3 | 285 | printf("\n\tTDLS peer:\t"); |
b638215d HS |
286 | if (sta_flags->set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
287 | printf("yes"); | |
288 | else | |
289 | printf("no"); | |
290 | } | |
291 | } | |
292 | ||
3d1e8704 LCC |
293 | printf("\n"); |
294 | return NL_SKIP; | |
295 | } | |
296 | ||
7c37a24d JB |
297 | static int handle_station_get(struct nl80211_state *state, |
298 | struct nl_cb *cb, | |
b1ca19a8 | 299 | struct nl_msg *msg, |
05514f95 JB |
300 | int argc, char **argv, |
301 | enum id_input id) | |
3d1e8704 | 302 | { |
3d1e8704 LCC |
303 | unsigned char mac_addr[ETH_ALEN]; |
304 | ||
b1ca19a8 | 305 | if (argc < 1) |
5e75fd04 | 306 | return 1; |
3d1e8704 LCC |
307 | |
308 | if (mac_addr_a2n(mac_addr, argv[0])) { | |
309 | fprintf(stderr, "invalid mac address\n"); | |
5e75fd04 | 310 | return 2; |
3d1e8704 LCC |
311 | } |
312 | ||
313 | argc--; | |
314 | argv++; | |
315 | ||
b1ca19a8 | 316 | if (argc) |
5e75fd04 | 317 | return 1; |
3d1e8704 LCC |
318 | |
319 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
3d1e8704 | 320 | |
3d1e8704 | 321 | nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, print_sta_handler, NULL); |
3d1e8704 | 322 | |
70391ccf | 323 | return 0; |
3d1e8704 | 324 | nla_put_failure: |
70391ccf | 325 | return -ENOBUFS; |
3d1e8704 | 326 | } |
b1ca19a8 | 327 | COMMAND(station, get, "<MAC address>", |
70cf4544 JB |
328 | NL80211_CMD_GET_STATION, 0, CIB_NETDEV, handle_station_get, |
329 | "Get information for a specific station."); | |
b1ca19a8 | 330 | COMMAND(station, del, "<MAC address>", |
70cf4544 JB |
331 | NL80211_CMD_DEL_STATION, 0, CIB_NETDEV, handle_station_get, |
332 | "Remove the given station entry (use with caution!)"); | |
3d1e8704 | 333 | |
1633ddf7 JB |
334 | static const struct cmd *station_set_plink; |
335 | static const struct cmd *station_set_vlan; | |
8012ad28 | 336 | static const struct cmd *station_set_mesh_power_mode; |
1633ddf7 JB |
337 | |
338 | static const struct cmd *select_station_cmd(int argc, char **argv) | |
339 | { | |
340 | if (argc < 2) | |
341 | return NULL; | |
342 | if (strcmp(argv[1], "plink_action") == 0) | |
343 | return station_set_plink; | |
344 | if (strcmp(argv[1], "vlan") == 0) | |
345 | return station_set_vlan; | |
8012ad28 MP |
346 | if (strcmp(argv[1], "mesh_power_mode") == 0) |
347 | return station_set_mesh_power_mode; | |
1633ddf7 JB |
348 | return NULL; |
349 | } | |
350 | ||
ce0fc33a | 351 | static int handle_station_set_plink(struct nl80211_state *state, |
7c37a24d | 352 | struct nl_cb *cb, |
b1ca19a8 | 353 | struct nl_msg *msg, |
05514f95 JB |
354 | int argc, char **argv, |
355 | enum id_input id) | |
3d1e8704 | 356 | { |
3d1e8704 LCC |
357 | unsigned char plink_action; |
358 | unsigned char mac_addr[ETH_ALEN]; | |
359 | ||
b1ca19a8 | 360 | if (argc < 3) |
5e75fd04 | 361 | return 1; |
3d1e8704 LCC |
362 | |
363 | if (mac_addr_a2n(mac_addr, argv[0])) { | |
364 | fprintf(stderr, "invalid mac address\n"); | |
5e75fd04 | 365 | return 2; |
3d1e8704 LCC |
366 | } |
367 | argc--; | |
368 | argv++; | |
369 | ||
b1ca19a8 JB |
370 | if (strcmp("plink_action", argv[0]) != 0) |
371 | return 1; | |
3d1e8704 LCC |
372 | argc--; |
373 | argv++; | |
374 | ||
375 | if (strcmp("open", argv[0]) == 0) | |
ac38f8ad | 376 | plink_action = NL80211_PLINK_ACTION_OPEN; |
3d1e8704 | 377 | else if (strcmp("block", argv[0]) == 0) |
ac38f8ad | 378 | plink_action = NL80211_PLINK_ACTION_BLOCK; |
3d1e8704 LCC |
379 | else { |
380 | fprintf(stderr, "plink action not supported\n"); | |
5e75fd04 | 381 | return 2; |
3d1e8704 LCC |
382 | } |
383 | argc--; | |
384 | argv++; | |
385 | ||
b1ca19a8 | 386 | if (argc) |
5e75fd04 | 387 | return 1; |
3d1e8704 LCC |
388 | |
389 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
3d1e8704 LCC |
390 | NLA_PUT_U8(msg, NL80211_ATTR_STA_PLINK_ACTION, plink_action); |
391 | ||
70391ccf | 392 | return 0; |
3d1e8704 | 393 | nla_put_failure: |
70391ccf | 394 | return -ENOBUFS; |
3d1e8704 | 395 | } |
1633ddf7 | 396 | COMMAND_ALIAS(station, set, "<MAC address> plink_action <open|block>", |
ce0fc33a | 397 | NL80211_CMD_SET_STATION, 0, CIB_NETDEV, handle_station_set_plink, |
1633ddf7 JB |
398 | "Set mesh peer link action for this station (peer).", |
399 | select_station_cmd, station_set_plink); | |
b1ca19a8 | 400 | |
ce0fc33a | 401 | static int handle_station_set_vlan(struct nl80211_state *state, |
05514f95 JB |
402 | struct nl_cb *cb, |
403 | struct nl_msg *msg, | |
404 | int argc, char **argv, | |
405 | enum id_input id) | |
ce0fc33a FF |
406 | { |
407 | unsigned char mac_addr[ETH_ALEN]; | |
408 | unsigned long sta_vlan = 0; | |
409 | char *err = NULL; | |
410 | ||
411 | if (argc < 3) | |
412 | return 1; | |
413 | ||
414 | if (mac_addr_a2n(mac_addr, argv[0])) { | |
415 | fprintf(stderr, "invalid mac address\n"); | |
416 | return 2; | |
417 | } | |
418 | argc--; | |
419 | argv++; | |
420 | ||
421 | if (strcmp("vlan", argv[0]) != 0) | |
422 | return 1; | |
423 | argc--; | |
424 | argv++; | |
425 | ||
426 | sta_vlan = strtoul(argv[0], &err, 0); | |
427 | if (err && *err) { | |
428 | fprintf(stderr, "invalid vlan id\n"); | |
429 | return 2; | |
430 | } | |
431 | argc--; | |
432 | argv++; | |
433 | ||
434 | if (argc) | |
435 | return 1; | |
436 | ||
437 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
438 | NLA_PUT_U32(msg, NL80211_ATTR_STA_VLAN, sta_vlan); | |
439 | ||
440 | return 0; | |
441 | nla_put_failure: | |
442 | return -ENOBUFS; | |
443 | } | |
1633ddf7 | 444 | COMMAND_ALIAS(station, set, "<MAC address> vlan <ifindex>", |
ce0fc33a | 445 | NL80211_CMD_SET_STATION, 0, CIB_NETDEV, handle_station_set_vlan, |
1633ddf7 JB |
446 | "Set an AP VLAN for this station.", |
447 | select_station_cmd, station_set_vlan); | |
ce0fc33a | 448 | |
8012ad28 MP |
449 | static int handle_station_set_mesh_power_mode(struct nl80211_state *state, |
450 | struct nl_cb *cb, | |
451 | struct nl_msg *msg, | |
452 | int argc, char **argv, | |
453 | enum id_input id) | |
454 | { | |
455 | unsigned char mesh_power_mode; | |
456 | unsigned char mac_addr[ETH_ALEN]; | |
457 | ||
458 | if (argc < 3) | |
459 | return 1; | |
460 | ||
461 | if (mac_addr_a2n(mac_addr, argv[0])) { | |
462 | fprintf(stderr, "invalid mac address\n"); | |
463 | return 2; | |
464 | } | |
465 | argc--; | |
466 | argv++; | |
467 | ||
468 | if (strcmp("mesh_power_mode", argv[0]) != 0) | |
469 | return 1; | |
470 | argc--; | |
471 | argv++; | |
472 | ||
473 | if (strcmp("active", argv[0]) == 0) | |
474 | mesh_power_mode = NL80211_MESH_POWER_ACTIVE; | |
475 | else if (strcmp("light", argv[0]) == 0) | |
476 | mesh_power_mode = NL80211_MESH_POWER_LIGHT_SLEEP; | |
477 | else if (strcmp("deep", argv[0]) == 0) | |
478 | mesh_power_mode = NL80211_MESH_POWER_DEEP_SLEEP; | |
479 | else { | |
480 | fprintf(stderr, "unknown mesh power mode\n"); | |
481 | return 2; | |
482 | } | |
483 | argc--; | |
484 | argv++; | |
485 | ||
486 | if (argc) | |
487 | return 1; | |
488 | ||
489 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
490 | NLA_PUT_U32(msg, NL80211_ATTR_LOCAL_MESH_POWER_MODE, mesh_power_mode); | |
491 | ||
492 | return 0; | |
493 | nla_put_failure: | |
494 | return -ENOBUFS; | |
495 | } | |
496 | COMMAND_ALIAS(station, set, "<MAC address> mesh_power_mode " | |
497 | "<active|light|deep>", NL80211_CMD_SET_STATION, 0, CIB_NETDEV, | |
498 | handle_station_set_mesh_power_mode, | |
499 | "Set link-specific mesh power mode for this station", | |
500 | select_station_cmd, station_set_mesh_power_mode); | |
ce0fc33a | 501 | |
7c37a24d JB |
502 | static int handle_station_dump(struct nl80211_state *state, |
503 | struct nl_cb *cb, | |
b1ca19a8 | 504 | struct nl_msg *msg, |
05514f95 JB |
505 | int argc, char **argv, |
506 | enum id_input id) | |
3d1e8704 | 507 | { |
3d1e8704 | 508 | nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, print_sta_handler, NULL); |
70391ccf | 509 | return 0; |
3d1e8704 | 510 | } |
b1ca19a8 | 511 | COMMAND(station, dump, NULL, |
70cf4544 JB |
512 | NL80211_CMD_GET_STATION, NLM_F_DUMP, CIB_NETDEV, handle_station_dump, |
513 | "List all stations known, e.g. the AP on managed interfaces"); |