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