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