]> git.ipfire.org Git - thirdparty/iw.git/blame - station.c
iw: add extack support
[thirdparty/iw.git] / station.c
CommitLineData
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
14SECTION(station);
15
3d1e8704
LCC
16enum plink_state {
17 LISTEN,
18 OPN_SNT,
19 OPN_RCVD,
20 CNF_RCVD,
21 ESTAB,
22 HOLDING,
23 BLOCKED
24};
25
8012ad28
MP
26static 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
568c7057
AE
46void parse_tid_stats(struct nlattr *tid_stats_attr)
47{
48 struct nlattr *stats_info[NL80211_TID_STATS_MAX + 1], *tidattr, *info;
49 static struct nla_policy stats_policy[NL80211_TID_STATS_MAX + 1] = {
50 [NL80211_TID_STATS_RX_MSDU] = { .type = NLA_U64 },
51 [NL80211_TID_STATS_TX_MSDU] = { .type = NLA_U64 },
52 [NL80211_TID_STATS_TX_MSDU_RETRIES] = { .type = NLA_U64 },
53 [NL80211_TID_STATS_TX_MSDU_FAILED] = { .type = NLA_U64 },
54 };
55 int rem, i = 0;
56
57 printf("\n\tMSDU:\n\t\tTID\trx\ttx\ttx retries\ttx failed");
58 nla_for_each_nested(tidattr, tid_stats_attr, rem) {
59 if (nla_parse_nested(stats_info, NL80211_TID_STATS_MAX,
60 tidattr, stats_policy)) {
61 printf("failed to parse nested stats attributes!");
62 return;
63 }
64 printf("\n\t\t%d", i++);
65 info = stats_info[NL80211_TID_STATS_RX_MSDU];
66 if (info)
67 printf("\t%llu", (unsigned long long)nla_get_u64(info));
68 info = stats_info[NL80211_TID_STATS_TX_MSDU];
69 if (info)
70 printf("\t%llu", (unsigned long long)nla_get_u64(info));
71 info = stats_info[NL80211_TID_STATS_TX_MSDU_RETRIES];
72 if (info)
73 printf("\t%llu", (unsigned long long)nla_get_u64(info));
74 info = stats_info[NL80211_TID_STATS_TX_MSDU_FAILED];
75 if (info)
76 printf("\t\t%llu", (unsigned long long)nla_get_u64(info));
77 }
78}
79
80void parse_bss_param(struct nlattr *bss_param_attr)
81{
82 struct nlattr *bss_param_info[NL80211_STA_BSS_PARAM_MAX + 1], *info;
83 static struct nla_policy bss_poilcy[NL80211_STA_BSS_PARAM_MAX + 1] = {
84 [NL80211_STA_BSS_PARAM_CTS_PROT] = { .type = NLA_FLAG },
85 [NL80211_STA_BSS_PARAM_SHORT_PREAMBLE] = { .type = NLA_FLAG },
86 [NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME] = { .type = NLA_FLAG },
87 [NL80211_STA_BSS_PARAM_DTIM_PERIOD] = { .type = NLA_U8 },
88 [NL80211_STA_BSS_PARAM_BEACON_INTERVAL] = { .type = NLA_U16 },
89 };
90
91 if (nla_parse_nested(bss_param_info, NL80211_STA_BSS_PARAM_MAX,
92 bss_param_attr, bss_poilcy)) {
93 printf("failed to parse nested bss param attributes!");
94 }
95
96 info = bss_param_info[NL80211_STA_BSS_PARAM_DTIM_PERIOD];
97 if (info)
98 printf("\n\tDTIM period:\t%u", nla_get_u8(info));
99 info = bss_param_info[NL80211_STA_BSS_PARAM_BEACON_INTERVAL];
100 if (info)
101 printf("\n\tbeacon interval:%u", nla_get_u16(info));
102 info = bss_param_info[NL80211_STA_BSS_PARAM_CTS_PROT];
103 if (info) {
104 printf("\n\tCTS protection:");
105 if (nla_get_u16(info))
106 printf("\tyes");
107 else
108 printf("\tno");
109 }
110 info = bss_param_info[NL80211_STA_BSS_PARAM_SHORT_PREAMBLE];
111 if (info) {
112 printf("\n\tshort preamble:");
113 if (nla_get_u16(info))
114 printf("\tyes");
115 else
116 printf("\tno");
117 }
118 info = bss_param_info[NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME];
119 if (info) {
120 printf("\n\tshort slot time:");
121 if (nla_get_u16(info))
122 printf("yes");
123 else
124 printf("no");
125 }
126}
127
e94f0201 128void parse_bitrate(struct nlattr *bitrate_attr, char *buf, int buflen)
64179590
JB
129{
130 int rate = 0;
131 char *pos = buf;
132 struct nlattr *rinfo[NL80211_RATE_INFO_MAX + 1];
133 static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = {
134 [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 },
135 [NL80211_RATE_INFO_BITRATE32] = { .type = NLA_U32 },
136 [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 },
137 [NL80211_RATE_INFO_40_MHZ_WIDTH] = { .type = NLA_FLAG },
138 [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG },
139 };
140
141 if (nla_parse_nested(rinfo, NL80211_RATE_INFO_MAX,
142 bitrate_attr, rate_policy)) {
143 snprintf(buf, buflen, "failed to parse nested rate attributes!");
144 return;
145 }
146
147 if (rinfo[NL80211_RATE_INFO_BITRATE32])
148 rate = nla_get_u32(rinfo[NL80211_RATE_INFO_BITRATE32]);
149 else if (rinfo[NL80211_RATE_INFO_BITRATE])
150 rate = nla_get_u16(rinfo[NL80211_RATE_INFO_BITRATE]);
151 if (rate > 0)
152 pos += snprintf(pos, buflen - (pos - buf),
153 "%d.%d MBit/s", rate / 10, rate % 10);
5ce1f6c7
MH
154 else
155 pos += snprintf(pos, buflen - (pos - buf), "(unknown)");
64179590
JB
156
157 if (rinfo[NL80211_RATE_INFO_MCS])
158 pos += snprintf(pos, buflen - (pos - buf),
159 " MCS %d", nla_get_u8(rinfo[NL80211_RATE_INFO_MCS]));
160 if (rinfo[NL80211_RATE_INFO_VHT_MCS])
161 pos += snprintf(pos, buflen - (pos - buf),
162 " VHT-MCS %d", nla_get_u8(rinfo[NL80211_RATE_INFO_VHT_MCS]));
163 if (rinfo[NL80211_RATE_INFO_40_MHZ_WIDTH])
164 pos += snprintf(pos, buflen - (pos - buf), " 40MHz");
165 if (rinfo[NL80211_RATE_INFO_80_MHZ_WIDTH])
166 pos += snprintf(pos, buflen - (pos - buf), " 80MHz");
167 if (rinfo[NL80211_RATE_INFO_80P80_MHZ_WIDTH])
168 pos += snprintf(pos, buflen - (pos - buf), " 80P80MHz");
169 if (rinfo[NL80211_RATE_INFO_160_MHZ_WIDTH])
170 pos += snprintf(pos, buflen - (pos - buf), " 160MHz");
171 if (rinfo[NL80211_RATE_INFO_SHORT_GI])
172 pos += snprintf(pos, buflen - (pos - buf), " short GI");
173 if (rinfo[NL80211_RATE_INFO_VHT_NSS])
174 pos += snprintf(pos, buflen - (pos - buf),
175 " VHT-NSS %d", nla_get_u8(rinfo[NL80211_RATE_INFO_VHT_NSS]));
176}
177
7d23bc2d
FF
178static char *get_chain_signal(struct nlattr *attr_list)
179{
180 struct nlattr *attr;
181 static char buf[64];
182 char *cur = buf;
183 int i = 0, rem;
184 const char *prefix;
185
186 if (!attr_list)
187 return "";
188
189 nla_for_each_nested(attr, attr_list, rem) {
190 if (i++ > 0)
191 prefix = ", ";
192 else
193 prefix = "[";
194
195 cur += snprintf(cur, sizeof(buf) - (cur - buf), "%s%d", prefix,
196 (int8_t) nla_get_u8(attr));
197 }
198
199 if (i)
200 snprintf(cur, sizeof(buf) - (cur - buf), "] ");
201
202 return buf;
203}
204
3d1e8704
LCC
205static int print_sta_handler(struct nl_msg *msg, void *arg)
206{
207 struct nlattr *tb[NL80211_ATTR_MAX + 1];
208 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
209 struct nlattr *sinfo[NL80211_STA_INFO_MAX + 1];
210 char mac_addr[20], state_name[10], dev[20];
b638215d 211 struct nl80211_sta_flag_update *sta_flags;
3d1e8704
LCC
212 static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = {
213 [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 },
214 [NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 },
215 [NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 },
568c7057
AE
216 [NL80211_STA_INFO_RX_BYTES64] = { .type = NLA_U64 },
217 [NL80211_STA_INFO_TX_BYTES64] = { .type = NLA_U64 },
859677cb
JB
218 [NL80211_STA_INFO_RX_PACKETS] = { .type = NLA_U32 },
219 [NL80211_STA_INFO_TX_PACKETS] = { .type = NLA_U32 },
568c7057 220 [NL80211_STA_INFO_BEACON_RX] = { .type = NLA_U64},
9cd3f1c1 221 [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 },
ea3ade85 222 [NL80211_STA_INFO_T_OFFSET] = { .type = NLA_U64 },
9cd3f1c1 223 [NL80211_STA_INFO_TX_BITRATE] = { .type = NLA_NESTED },
e94f0201 224 [NL80211_STA_INFO_RX_BITRATE] = { .type = NLA_NESTED },
3d1e8704
LCC
225 [NL80211_STA_INFO_LLID] = { .type = NLA_U16 },
226 [NL80211_STA_INFO_PLID] = { .type = NLA_U16 },
227 [NL80211_STA_INFO_PLINK_STATE] = { .type = NLA_U8 },
0f5868ee
BR
228 [NL80211_STA_INFO_TX_RETRIES] = { .type = NLA_U32 },
229 [NL80211_STA_INFO_TX_FAILED] = { .type = NLA_U32 },
568c7057
AE
230 [NL80211_STA_INFO_BEACON_LOSS] = { .type = NLA_U32},
231 [NL80211_STA_INFO_RX_DROP_MISC] = { .type = NLA_U64},
b638215d
HS
232 [NL80211_STA_INFO_STA_FLAGS] =
233 { .minlen = sizeof(struct nl80211_sta_flag_update) },
8012ad28
MP
234 [NL80211_STA_INFO_LOCAL_PM] = { .type = NLA_U32},
235 [NL80211_STA_INFO_PEER_PM] = { .type = NLA_U32},
236 [NL80211_STA_INFO_NONPEER_PM] = { .type = NLA_U32},
7d23bc2d
FF
237 [NL80211_STA_INFO_CHAIN_SIGNAL] = { .type = NLA_NESTED },
238 [NL80211_STA_INFO_CHAIN_SIGNAL_AVG] = { .type = NLA_NESTED },
568c7057
AE
239 [NL80211_STA_INFO_TID_STATS] = { .type = NLA_NESTED },
240 [NL80211_STA_INFO_BSS_PARAM] = { .type = NLA_NESTED },
045c1c6f 241 [NL80211_STA_INFO_RX_DURATION] = { .type = NLA_U64 },
3d1e8704 242 };
7d23bc2d 243 char *chain;
3d1e8704
LCC
244
245 nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
246 genlmsg_attrlen(gnlh, 0), NULL);
247
248 /*
249 * TODO: validate the interface and mac address!
250 * Otherwise, there's a race condition as soon as
251 * the kernel starts sending station notifications.
252 */
253
254 if (!tb[NL80211_ATTR_STA_INFO]) {
5fe70c0e 255 fprintf(stderr, "sta stats missing!\n");
3d1e8704
LCC
256 return NL_SKIP;
257 }
258 if (nla_parse_nested(sinfo, NL80211_STA_INFO_MAX,
259 tb[NL80211_ATTR_STA_INFO],
260 stats_policy)) {
5fe70c0e 261 fprintf(stderr, "failed to parse nested attributes!\n");
3d1e8704
LCC
262 return NL_SKIP;
263 }
264
265 mac_addr_n2a(mac_addr, nla_data(tb[NL80211_ATTR_MAC]));
266 if_indextoname(nla_get_u32(tb[NL80211_ATTR_IFINDEX]), dev);
fbb181fa 267 printf("Station %s (on %s)", mac_addr, dev);
3d1e8704
LCC
268
269 if (sinfo[NL80211_STA_INFO_INACTIVE_TIME])
f5c9799c 270 printf("\n\tinactive time:\t%u ms",
3d1e8704 271 nla_get_u32(sinfo[NL80211_STA_INFO_INACTIVE_TIME]));
568c7057
AE
272 if (sinfo[NL80211_STA_INFO_RX_BYTES64])
273 printf("\n\trx bytes:\t%llu",
274 (unsigned long long)nla_get_u64(sinfo[NL80211_STA_INFO_RX_BYTES64]));
275 else if (sinfo[NL80211_STA_INFO_RX_BYTES])
f5c9799c 276 printf("\n\trx bytes:\t%u",
568c7057 277 nla_get_u32(sinfo[NL80211_STA_INFO_RX_BYTES]));
859677cb 278 if (sinfo[NL80211_STA_INFO_RX_PACKETS])
f5c9799c 279 printf("\n\trx packets:\t%u",
859677cb 280 nla_get_u32(sinfo[NL80211_STA_INFO_RX_PACKETS]));
568c7057
AE
281 if (sinfo[NL80211_STA_INFO_TX_BYTES64])
282 printf("\n\ttx bytes:\t%llu",
283 (unsigned long long)nla_get_u64(sinfo[NL80211_STA_INFO_TX_BYTES64]));
284 else if (sinfo[NL80211_STA_INFO_TX_BYTES])
f5c9799c 285 printf("\n\ttx bytes:\t%u",
568c7057 286 nla_get_u32(sinfo[NL80211_STA_INFO_TX_BYTES]));
859677cb 287 if (sinfo[NL80211_STA_INFO_TX_PACKETS])
f5c9799c 288 printf("\n\ttx packets:\t%u",
859677cb 289 nla_get_u32(sinfo[NL80211_STA_INFO_TX_PACKETS]));
0f5868ee
BR
290 if (sinfo[NL80211_STA_INFO_TX_RETRIES])
291 printf("\n\ttx retries:\t%u",
292 nla_get_u32(sinfo[NL80211_STA_INFO_TX_RETRIES]));
293 if (sinfo[NL80211_STA_INFO_TX_FAILED])
294 printf("\n\ttx failed:\t%u",
295 nla_get_u32(sinfo[NL80211_STA_INFO_TX_FAILED]));
568c7057
AE
296 if (sinfo[NL80211_STA_INFO_BEACON_LOSS])
297 printf("\n\tbeacon loss:\t%u",
298 nla_get_u32(sinfo[NL80211_STA_INFO_BEACON_LOSS]));
299 if (sinfo[NL80211_STA_INFO_BEACON_RX])
300 printf("\n\tbeacon rx:\t%llu",
301 (unsigned long long)nla_get_u64(sinfo[NL80211_STA_INFO_BEACON_RX]));
302 if (sinfo[NL80211_STA_INFO_RX_DROP_MISC])
303 printf("\n\trx drop misc:\t%llu",
304 (unsigned long long)nla_get_u64(sinfo[NL80211_STA_INFO_RX_DROP_MISC]));
7d23bc2d
FF
305
306 chain = get_chain_signal(sinfo[NL80211_STA_INFO_CHAIN_SIGNAL]);
9cd3f1c1 307 if (sinfo[NL80211_STA_INFO_SIGNAL])
7d23bc2d
FF
308 printf("\n\tsignal: \t%d %sdBm",
309 (int8_t)nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL]),
310 chain);
311
312 chain = get_chain_signal(sinfo[NL80211_STA_INFO_CHAIN_SIGNAL_AVG]);
ba292ae9 313 if (sinfo[NL80211_STA_INFO_SIGNAL_AVG])
7d23bc2d
FF
314 printf("\n\tsignal avg:\t%d %sdBm",
315 (int8_t)nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL_AVG]),
316 chain);
317
568c7057
AE
318 if (sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG])
319 printf("\n\tbeacon signal avg:\t%d dBm",
320 nla_get_u8(sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG]));
ea3ade85 321 if (sinfo[NL80211_STA_INFO_T_OFFSET])
568c7057
AE
322 printf("\n\tToffset:\t%llu us",
323 (unsigned long long)nla_get_u64(sinfo[NL80211_STA_INFO_T_OFFSET]));
9cd3f1c1
HR
324
325 if (sinfo[NL80211_STA_INFO_TX_BITRATE]) {
64179590
JB
326 char buf[100];
327
e94f0201 328 parse_bitrate(sinfo[NL80211_STA_INFO_TX_BITRATE], buf, sizeof(buf));
64179590 329 printf("\n\ttx bitrate:\t%s", buf);
9cd3f1c1
HR
330 }
331
e94f0201
FF
332 if (sinfo[NL80211_STA_INFO_RX_BITRATE]) {
333 char buf[100];
334
335 parse_bitrate(sinfo[NL80211_STA_INFO_RX_BITRATE], buf, sizeof(buf));
336 printf("\n\trx bitrate:\t%s", buf);
337 }
338
045c1c6f
MSS
339 if (sinfo[NL80211_STA_INFO_RX_DURATION])
340 printf("\n\trx duration:\t%lld us",
341 (unsigned long long)nla_get_u64(sinfo[NL80211_STA_INFO_RX_DURATION]));
342
cf8a2aab
AQ
343 if (sinfo[NL80211_STA_INFO_EXPECTED_THROUGHPUT]) {
344 uint32_t thr;
345
346 thr = nla_get_u32(sinfo[NL80211_STA_INFO_EXPECTED_THROUGHPUT]);
347 /* convert in Mbps but scale by 1000 to save kbps units */
348 thr = thr * 1000 / 1024;
349
350 printf("\n\texpected throughput:\t%u.%uMbps",
351 thr / 1000, thr % 1000);
352 }
353
3d1e8704 354 if (sinfo[NL80211_STA_INFO_LLID])
fbb181fa 355 printf("\n\tmesh llid:\t%d",
3d1e8704
LCC
356 nla_get_u16(sinfo[NL80211_STA_INFO_LLID]));
357 if (sinfo[NL80211_STA_INFO_PLID])
fbb181fa 358 printf("\n\tmesh plid:\t%d",
3d1e8704
LCC
359 nla_get_u16(sinfo[NL80211_STA_INFO_PLID]));
360 if (sinfo[NL80211_STA_INFO_PLINK_STATE]) {
dbaabba1 361 switch (nla_get_u8(sinfo[NL80211_STA_INFO_PLINK_STATE])) {
3d1e8704
LCC
362 case LISTEN:
363 strcpy(state_name, "LISTEN");
364 break;
365 case OPN_SNT:
366 strcpy(state_name, "OPN_SNT");
367 break;
368 case OPN_RCVD:
369 strcpy(state_name, "OPN_RCVD");
370 break;
371 case CNF_RCVD:
372 strcpy(state_name, "CNF_RCVD");
373 break;
374 case ESTAB:
375 strcpy(state_name, "ESTAB");
376 break;
377 case HOLDING:
378 strcpy(state_name, "HOLDING");
379 break;
380 case BLOCKED:
381 strcpy(state_name, "BLOCKED");
382 break;
383 default:
384 strcpy(state_name, "UNKNOWN");
385 break;
386 }
fbb181fa 387 printf("\n\tmesh plink:\t%s", state_name);
3d1e8704 388 }
8012ad28
MP
389 if (sinfo[NL80211_STA_INFO_LOCAL_PM]) {
390 printf("\n\tmesh local PS mode:\t");
391 print_power_mode(sinfo[NL80211_STA_INFO_LOCAL_PM]);
392 }
393 if (sinfo[NL80211_STA_INFO_PEER_PM]) {
394 printf("\n\tmesh peer PS mode:\t");
395 print_power_mode(sinfo[NL80211_STA_INFO_PEER_PM]);
396 }
397 if (sinfo[NL80211_STA_INFO_NONPEER_PM]) {
398 printf("\n\tmesh non-peer PS mode:\t");
399 print_power_mode(sinfo[NL80211_STA_INFO_NONPEER_PM]);
400 }
3d1e8704 401
b638215d
HS
402 if (sinfo[NL80211_STA_INFO_STA_FLAGS]) {
403 sta_flags = (struct nl80211_sta_flag_update *)
404 nla_data(sinfo[NL80211_STA_INFO_STA_FLAGS]);
405
406 if (sta_flags->mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
407 printf("\n\tauthorized:\t");
408 if (sta_flags->set & BIT(NL80211_STA_FLAG_AUTHORIZED))
409 printf("yes");
410 else
411 printf("no");
412 }
413
414 if (sta_flags->mask & BIT(NL80211_STA_FLAG_AUTHENTICATED)) {
415 printf("\n\tauthenticated:\t");
416 if (sta_flags->set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
417 printf("yes");
418 else
419 printf("no");
420 }
421
568c7057
AE
422 if (sta_flags->mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) {
423 printf("\n\tassociated:\t");
424 if (sta_flags->set & BIT(NL80211_STA_FLAG_ASSOCIATED))
425 printf("yes");
426 else
427 printf("no");
428 }
429
b638215d
HS
430 if (sta_flags->mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
431 printf("\n\tpreamble:\t");
432 if (sta_flags->set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
433 printf("short");
434 else
435 printf("long");
436 }
437
438 if (sta_flags->mask & BIT(NL80211_STA_FLAG_WME)) {
439 printf("\n\tWMM/WME:\t");
440 if (sta_flags->set & BIT(NL80211_STA_FLAG_WME))
441 printf("yes");
442 else
443 printf("no");
444 }
445
446 if (sta_flags->mask & BIT(NL80211_STA_FLAG_MFP)) {
447 printf("\n\tMFP:\t\t");
448 if (sta_flags->set & BIT(NL80211_STA_FLAG_MFP))
449 printf("yes");
450 else
451 printf("no");
452 }
453
454 if (sta_flags->mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
1a463ae3 455 printf("\n\tTDLS peer:\t");
b638215d
HS
456 if (sta_flags->set & BIT(NL80211_STA_FLAG_TDLS_PEER))
457 printf("yes");
458 else
459 printf("no");
460 }
461 }
462
568c7057
AE
463 if (sinfo[NL80211_STA_INFO_TID_STATS] && arg != NULL &&
464 !strcmp((char *)arg, "-v"))
465 parse_tid_stats(sinfo[NL80211_STA_INFO_TID_STATS]);
466 if (sinfo[NL80211_STA_INFO_BSS_PARAM])
467 parse_bss_param(sinfo[NL80211_STA_INFO_BSS_PARAM]);
087d778f
AN
468 if (sinfo[NL80211_STA_INFO_CONNECTED_TIME])
469 printf("\n\tconnected time:\t%u seconds",
470 nla_get_u32(sinfo[NL80211_STA_INFO_CONNECTED_TIME]));
471
3d1e8704
LCC
472 printf("\n");
473 return NL_SKIP;
474}
475
7c37a24d 476static int handle_station_get(struct nl80211_state *state,
b1ca19a8 477 struct nl_msg *msg,
05514f95
JB
478 int argc, char **argv,
479 enum id_input id)
3d1e8704 480{
3d1e8704
LCC
481 unsigned char mac_addr[ETH_ALEN];
482
b1ca19a8 483 if (argc < 1)
5e75fd04 484 return 1;
3d1e8704
LCC
485
486 if (mac_addr_a2n(mac_addr, argv[0])) {
487 fprintf(stderr, "invalid mac address\n");
5e75fd04 488 return 2;
3d1e8704
LCC
489 }
490
491 argc--;
492 argv++;
493
b1ca19a8 494 if (argc)
5e75fd04 495 return 1;
3d1e8704
LCC
496
497 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
3d1e8704 498
34b23014 499 register_handler(print_sta_handler, NULL);
3d1e8704 500
70391ccf 501 return 0;
3d1e8704 502 nla_put_failure:
70391ccf 503 return -ENOBUFS;
3d1e8704 504}
b1ca19a8 505COMMAND(station, get, "<MAC address>",
70cf4544
JB
506 NL80211_CMD_GET_STATION, 0, CIB_NETDEV, handle_station_get,
507 "Get information for a specific station.");
d738686c
RM
508
509static int handle_station_del(struct nl80211_state *state,
510 struct nl_msg *msg,
511 int argc, char **argv,
512 enum id_input id)
513{
514 char *end;
515 unsigned char mac_addr[ETH_ALEN];
516 int subtype;
517 int reason_code;
518
519 if (argc < 1)
520 return 1;
521
522 if (mac_addr_a2n(mac_addr, argv[0])) {
523 fprintf(stderr, "invalid mac address\n");
524 return 2;
525 }
526
527 argc--;
528 argv++;
529 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
530
531 if (argc > 1 && strcmp(argv[0], "subtype") == 0) {
532 argv++;
533 argc--;
534
535 subtype = strtod(argv[0], &end);
536 if (*end != '\0')
537 return 1;
538
539 NLA_PUT_U8(msg, NL80211_ATTR_MGMT_SUBTYPE, subtype);
540 argv++;
541 argc--;
542 }
543
544 if (argc > 1 && strcmp(argv[0], "reason-code") == 0) {
545 argv++;
546 argc--;
547
548 reason_code = strtod(argv[0], &end);
549 if (*end != '\0')
550 return 1;
551
552 NLA_PUT_U16(msg, NL80211_ATTR_REASON_CODE, reason_code);
553 argv++;
554 argc--;
555 }
556
557 if (argc)
558 return 1;
559
560 register_handler(print_sta_handler, NULL);
561
562 return 0;
563 nla_put_failure:
564 return -ENOBUFS;
565}
566COMMAND(station, del, "<MAC address> [subtype <subtype>] [reason-code <code>]",
567 NL80211_CMD_DEL_STATION, 0, CIB_NETDEV, handle_station_del,
568 "Remove the given station entry (use with caution!)\n"
569 "Example subtype values: 0xA (disassociation), 0xC (deauthentication)");
3d1e8704 570
1633ddf7
JB
571static const struct cmd *station_set_plink;
572static const struct cmd *station_set_vlan;
8012ad28 573static const struct cmd *station_set_mesh_power_mode;
1633ddf7
JB
574
575static const struct cmd *select_station_cmd(int argc, char **argv)
576{
577 if (argc < 2)
578 return NULL;
579 if (strcmp(argv[1], "plink_action") == 0)
580 return station_set_plink;
581 if (strcmp(argv[1], "vlan") == 0)
582 return station_set_vlan;
8012ad28
MP
583 if (strcmp(argv[1], "mesh_power_mode") == 0)
584 return station_set_mesh_power_mode;
1633ddf7
JB
585 return NULL;
586}
587
ce0fc33a 588static int handle_station_set_plink(struct nl80211_state *state,
b1ca19a8 589 struct nl_msg *msg,
05514f95
JB
590 int argc, char **argv,
591 enum id_input id)
3d1e8704 592{
3d1e8704
LCC
593 unsigned char plink_action;
594 unsigned char mac_addr[ETH_ALEN];
595
b1ca19a8 596 if (argc < 3)
5e75fd04 597 return 1;
3d1e8704
LCC
598
599 if (mac_addr_a2n(mac_addr, argv[0])) {
600 fprintf(stderr, "invalid mac address\n");
5e75fd04 601 return 2;
3d1e8704
LCC
602 }
603 argc--;
604 argv++;
605
b1ca19a8
JB
606 if (strcmp("plink_action", argv[0]) != 0)
607 return 1;
3d1e8704
LCC
608 argc--;
609 argv++;
610
611 if (strcmp("open", argv[0]) == 0)
ac38f8ad 612 plink_action = NL80211_PLINK_ACTION_OPEN;
3d1e8704 613 else if (strcmp("block", argv[0]) == 0)
ac38f8ad 614 plink_action = NL80211_PLINK_ACTION_BLOCK;
3d1e8704
LCC
615 else {
616 fprintf(stderr, "plink action not supported\n");
5e75fd04 617 return 2;
3d1e8704
LCC
618 }
619 argc--;
620 argv++;
621
b1ca19a8 622 if (argc)
5e75fd04 623 return 1;
3d1e8704
LCC
624
625 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
3d1e8704
LCC
626 NLA_PUT_U8(msg, NL80211_ATTR_STA_PLINK_ACTION, plink_action);
627
70391ccf 628 return 0;
3d1e8704 629 nla_put_failure:
70391ccf 630 return -ENOBUFS;
3d1e8704 631}
1633ddf7 632COMMAND_ALIAS(station, set, "<MAC address> plink_action <open|block>",
ce0fc33a 633 NL80211_CMD_SET_STATION, 0, CIB_NETDEV, handle_station_set_plink,
1633ddf7
JB
634 "Set mesh peer link action for this station (peer).",
635 select_station_cmd, station_set_plink);
b1ca19a8 636
ce0fc33a 637static int handle_station_set_vlan(struct nl80211_state *state,
05514f95
JB
638 struct nl_msg *msg,
639 int argc, char **argv,
640 enum id_input id)
ce0fc33a
FF
641{
642 unsigned char mac_addr[ETH_ALEN];
643 unsigned long sta_vlan = 0;
644 char *err = NULL;
645
646 if (argc < 3)
647 return 1;
648
649 if (mac_addr_a2n(mac_addr, argv[0])) {
650 fprintf(stderr, "invalid mac address\n");
651 return 2;
652 }
653 argc--;
654 argv++;
655
656 if (strcmp("vlan", argv[0]) != 0)
657 return 1;
658 argc--;
659 argv++;
660
661 sta_vlan = strtoul(argv[0], &err, 0);
662 if (err && *err) {
663 fprintf(stderr, "invalid vlan id\n");
664 return 2;
665 }
666 argc--;
667 argv++;
668
669 if (argc)
670 return 1;
671
672 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
673 NLA_PUT_U32(msg, NL80211_ATTR_STA_VLAN, sta_vlan);
674
675 return 0;
676 nla_put_failure:
677 return -ENOBUFS;
678}
1633ddf7 679COMMAND_ALIAS(station, set, "<MAC address> vlan <ifindex>",
ce0fc33a 680 NL80211_CMD_SET_STATION, 0, CIB_NETDEV, handle_station_set_vlan,
1633ddf7
JB
681 "Set an AP VLAN for this station.",
682 select_station_cmd, station_set_vlan);
ce0fc33a 683
8012ad28 684static int handle_station_set_mesh_power_mode(struct nl80211_state *state,
8012ad28
MP
685 struct nl_msg *msg,
686 int argc, char **argv,
687 enum id_input id)
688{
689 unsigned char mesh_power_mode;
690 unsigned char mac_addr[ETH_ALEN];
691
692 if (argc < 3)
693 return 1;
694
695 if (mac_addr_a2n(mac_addr, argv[0])) {
696 fprintf(stderr, "invalid mac address\n");
697 return 2;
698 }
699 argc--;
700 argv++;
701
702 if (strcmp("mesh_power_mode", argv[0]) != 0)
703 return 1;
704 argc--;
705 argv++;
706
707 if (strcmp("active", argv[0]) == 0)
708 mesh_power_mode = NL80211_MESH_POWER_ACTIVE;
709 else if (strcmp("light", argv[0]) == 0)
710 mesh_power_mode = NL80211_MESH_POWER_LIGHT_SLEEP;
711 else if (strcmp("deep", argv[0]) == 0)
712 mesh_power_mode = NL80211_MESH_POWER_DEEP_SLEEP;
713 else {
714 fprintf(stderr, "unknown mesh power mode\n");
715 return 2;
716 }
717 argc--;
718 argv++;
719
720 if (argc)
721 return 1;
722
723 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
724 NLA_PUT_U32(msg, NL80211_ATTR_LOCAL_MESH_POWER_MODE, mesh_power_mode);
725
726 return 0;
727nla_put_failure:
728 return -ENOBUFS;
729}
730COMMAND_ALIAS(station, set, "<MAC address> mesh_power_mode "
731 "<active|light|deep>", NL80211_CMD_SET_STATION, 0, CIB_NETDEV,
732 handle_station_set_mesh_power_mode,
733 "Set link-specific mesh power mode for this station",
734 select_station_cmd, station_set_mesh_power_mode);
ce0fc33a 735
7c37a24d 736static int handle_station_dump(struct nl80211_state *state,
b1ca19a8 737 struct nl_msg *msg,
05514f95
JB
738 int argc, char **argv,
739 enum id_input id)
3d1e8704 740{
568c7057 741 register_handler(print_sta_handler, *argv);
70391ccf 742 return 0;
3d1e8704 743}
568c7057 744COMMAND(station, dump, "[-v]",
70cf4544
JB
745 NL80211_CMD_GET_STATION, NLM_F_DUMP, CIB_NETDEV, handle_station_dump,
746 "List all stations known, e.g. the AP on managed interfaces");