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>
26 static void print_power_mode(struct nlattr
*a
)
28 enum nl80211_mesh_power_mode pm
= nla_get_u32(a
);
31 case NL80211_MESH_POWER_ACTIVE
:
34 case NL80211_MESH_POWER_LIGHT_SLEEP
:
35 printf("LIGHT SLEEP");
37 case NL80211_MESH_POWER_DEEP_SLEEP
:
46 int parse_txq_stats(char *buf
, int buflen
, struct nlattr
*tid_stats_attr
, int header
,
47 int tid
, const char *indent
)
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
},
62 if (nla_parse_nested(txqstats_info
, NL80211_TXQ_STATS_MAX
, tid_stats_attr
,
64 printf("failed to parse nested TXQ stats attributes!");
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" : "");
74 pos
+= snprintf(pos
, buflen
- (pos
- buf
), "\n%s\t", indent
);
76 pos
+= snprintf(pos
, buflen
- (pos
- buf
), "%d", tid
);
78 #define PRINT_STAT(key, spacer) do { \
79 txqinfo = txqstats_info[NL80211_TXQ_STATS_ ## key]; \
80 pos += snprintf(pos, buflen - (pos - buf), spacer); \
82 pos += snprintf(pos, buflen - (pos - buf), "%u", \
83 nla_get_u32(txqinfo)); \
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");
102 void parse_tid_stats(struct nlattr
*tid_stats_attr
)
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
},
110 [NL80211_TID_STATS_TXQ_STATS
] = { .type
= NLA_NESTED
},
113 char txqbuf
[2000] = {}, *pos
= txqbuf
;
114 int buflen
= sizeof(txqbuf
), foundtxq
= 0;
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!");
123 printf("\n\t\t%d", i
);
124 info
= stats_info
[NL80211_TID_STATS_RX_MSDU
];
126 printf("\t%llu", (unsigned long long)nla_get_u64(info
));
127 info
= stats_info
[NL80211_TID_STATS_TX_MSDU
];
129 printf("\t%llu", (unsigned long long)nla_get_u64(info
));
130 info
= stats_info
[NL80211_TID_STATS_TX_MSDU_RETRIES
];
132 printf("\t%llu", (unsigned long long)nla_get_u64(info
));
133 info
= stats_info
[NL80211_TID_STATS_TX_MSDU_FAILED
];
135 printf("\t\t%llu", (unsigned long long)nla_get_u64(info
));
136 info
= stats_info
[NL80211_TID_STATS_TXQ_STATS
];
138 pos
+= parse_txq_stats(pos
, buflen
- (pos
- txqbuf
), info
, !foundtxq
, i
, "\t");
146 printf("\n\tTXQs:%s", txqbuf
);
149 void parse_bss_param(struct nlattr
*bss_param_attr
)
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
},
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!");
165 info
= bss_param_info
[NL80211_STA_BSS_PARAM_DTIM_PERIOD
];
167 printf("\n\tDTIM period:\t%u", nla_get_u8(info
));
168 info
= bss_param_info
[NL80211_STA_BSS_PARAM_BEACON_INTERVAL
];
170 printf("\n\tbeacon interval:%u", nla_get_u16(info
));
171 info
= bss_param_info
[NL80211_STA_BSS_PARAM_CTS_PROT
];
173 printf("\n\tCTS protection:");
174 if (nla_get_u16(info
))
179 info
= bss_param_info
[NL80211_STA_BSS_PARAM_SHORT_PREAMBLE
];
181 printf("\n\tshort preamble:");
182 if (nla_get_u16(info
))
187 info
= bss_param_info
[NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME
];
189 printf("\n\tshort slot time:");
190 if (nla_get_u16(info
))
197 void parse_bitrate(struct nlattr
*bitrate_attr
, char *buf
, int buflen
)
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
},
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!");
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
]);
221 pos
+= snprintf(pos
, buflen
- (pos
- buf
),
222 "%d.%d MBit/s", rate
/ 10, rate
% 10);
224 pos
+= snprintf(pos
, buflen
- (pos
- buf
), "(unknown)");
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
]));
247 static char *get_chain_signal(struct nlattr
*attr_list
)
258 nla_for_each_nested(attr
, attr_list
, rem
) {
264 cur
+= snprintf(cur
, sizeof(buf
) - (cur
- buf
), "%s%d", prefix
,
265 (int8_t) nla_get_u8(attr
));
269 snprintf(cur
, sizeof(buf
) - (cur
- buf
), "] ");
274 static int print_sta_handler(struct nl_msg
*msg
, void *arg
)
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];
280 struct nl80211_sta_flag_update
*sta_flags
;
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
},
285 [NL80211_STA_INFO_RX_BYTES64
] = { .type
= NLA_U64
},
286 [NL80211_STA_INFO_TX_BYTES64
] = { .type
= NLA_U64
},
287 [NL80211_STA_INFO_RX_PACKETS
] = { .type
= NLA_U32
},
288 [NL80211_STA_INFO_TX_PACKETS
] = { .type
= NLA_U32
},
289 [NL80211_STA_INFO_BEACON_RX
] = { .type
= NLA_U64
},
290 [NL80211_STA_INFO_SIGNAL
] = { .type
= NLA_U8
},
291 [NL80211_STA_INFO_T_OFFSET
] = { .type
= NLA_U64
},
292 [NL80211_STA_INFO_TX_BITRATE
] = { .type
= NLA_NESTED
},
293 [NL80211_STA_INFO_RX_BITRATE
] = { .type
= NLA_NESTED
},
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
},
297 [NL80211_STA_INFO_TX_RETRIES
] = { .type
= NLA_U32
},
298 [NL80211_STA_INFO_TX_FAILED
] = { .type
= NLA_U32
},
299 [NL80211_STA_INFO_BEACON_LOSS
] = { .type
= NLA_U32
},
300 [NL80211_STA_INFO_RX_DROP_MISC
] = { .type
= NLA_U64
},
301 [NL80211_STA_INFO_STA_FLAGS
] =
302 { .minlen
= sizeof(struct nl80211_sta_flag_update
) },
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
},
306 [NL80211_STA_INFO_CHAIN_SIGNAL
] = { .type
= NLA_NESTED
},
307 [NL80211_STA_INFO_CHAIN_SIGNAL_AVG
] = { .type
= NLA_NESTED
},
308 [NL80211_STA_INFO_TID_STATS
] = { .type
= NLA_NESTED
},
309 [NL80211_STA_INFO_BSS_PARAM
] = { .type
= NLA_NESTED
},
310 [NL80211_STA_INFO_RX_DURATION
] = { .type
= NLA_U64
},
314 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
315 genlmsg_attrlen(gnlh
, 0), NULL
);
318 * TODO: validate the interface and mac address!
319 * Otherwise, there's a race condition as soon as
320 * the kernel starts sending station notifications.
323 if (!tb
[NL80211_ATTR_STA_INFO
]) {
324 fprintf(stderr
, "sta stats missing!\n");
327 if (nla_parse_nested(sinfo
, NL80211_STA_INFO_MAX
,
328 tb
[NL80211_ATTR_STA_INFO
],
330 fprintf(stderr
, "failed to parse nested attributes!\n");
334 mac_addr_n2a(mac_addr
, nla_data(tb
[NL80211_ATTR_MAC
]));
335 if_indextoname(nla_get_u32(tb
[NL80211_ATTR_IFINDEX
]), dev
);
336 printf("Station %s (on %s)", mac_addr
, dev
);
338 if (sinfo
[NL80211_STA_INFO_INACTIVE_TIME
])
339 printf("\n\tinactive time:\t%u ms",
340 nla_get_u32(sinfo
[NL80211_STA_INFO_INACTIVE_TIME
]));
341 if (sinfo
[NL80211_STA_INFO_RX_BYTES64
])
342 printf("\n\trx bytes:\t%llu",
343 (unsigned long long)nla_get_u64(sinfo
[NL80211_STA_INFO_RX_BYTES64
]));
344 else if (sinfo
[NL80211_STA_INFO_RX_BYTES
])
345 printf("\n\trx bytes:\t%u",
346 nla_get_u32(sinfo
[NL80211_STA_INFO_RX_BYTES
]));
347 if (sinfo
[NL80211_STA_INFO_RX_PACKETS
])
348 printf("\n\trx packets:\t%u",
349 nla_get_u32(sinfo
[NL80211_STA_INFO_RX_PACKETS
]));
350 if (sinfo
[NL80211_STA_INFO_TX_BYTES64
])
351 printf("\n\ttx bytes:\t%llu",
352 (unsigned long long)nla_get_u64(sinfo
[NL80211_STA_INFO_TX_BYTES64
]));
353 else if (sinfo
[NL80211_STA_INFO_TX_BYTES
])
354 printf("\n\ttx bytes:\t%u",
355 nla_get_u32(sinfo
[NL80211_STA_INFO_TX_BYTES
]));
356 if (sinfo
[NL80211_STA_INFO_TX_PACKETS
])
357 printf("\n\ttx packets:\t%u",
358 nla_get_u32(sinfo
[NL80211_STA_INFO_TX_PACKETS
]));
359 if (sinfo
[NL80211_STA_INFO_TX_RETRIES
])
360 printf("\n\ttx retries:\t%u",
361 nla_get_u32(sinfo
[NL80211_STA_INFO_TX_RETRIES
]));
362 if (sinfo
[NL80211_STA_INFO_TX_FAILED
])
363 printf("\n\ttx failed:\t%u",
364 nla_get_u32(sinfo
[NL80211_STA_INFO_TX_FAILED
]));
365 if (sinfo
[NL80211_STA_INFO_BEACON_LOSS
])
366 printf("\n\tbeacon loss:\t%u",
367 nla_get_u32(sinfo
[NL80211_STA_INFO_BEACON_LOSS
]));
368 if (sinfo
[NL80211_STA_INFO_BEACON_RX
])
369 printf("\n\tbeacon rx:\t%llu",
370 (unsigned long long)nla_get_u64(sinfo
[NL80211_STA_INFO_BEACON_RX
]));
371 if (sinfo
[NL80211_STA_INFO_RX_DROP_MISC
])
372 printf("\n\trx drop misc:\t%llu",
373 (unsigned long long)nla_get_u64(sinfo
[NL80211_STA_INFO_RX_DROP_MISC
]));
375 chain
= get_chain_signal(sinfo
[NL80211_STA_INFO_CHAIN_SIGNAL
]);
376 if (sinfo
[NL80211_STA_INFO_SIGNAL
])
377 printf("\n\tsignal: \t%d %sdBm",
378 (int8_t)nla_get_u8(sinfo
[NL80211_STA_INFO_SIGNAL
]),
381 chain
= get_chain_signal(sinfo
[NL80211_STA_INFO_CHAIN_SIGNAL_AVG
]);
382 if (sinfo
[NL80211_STA_INFO_SIGNAL_AVG
])
383 printf("\n\tsignal avg:\t%d %sdBm",
384 (int8_t)nla_get_u8(sinfo
[NL80211_STA_INFO_SIGNAL_AVG
]),
387 if (sinfo
[NL80211_STA_INFO_BEACON_SIGNAL_AVG
])
388 printf("\n\tbeacon signal avg:\t%d dBm",
389 nla_get_u8(sinfo
[NL80211_STA_INFO_BEACON_SIGNAL_AVG
]));
390 if (sinfo
[NL80211_STA_INFO_T_OFFSET
])
391 printf("\n\tToffset:\t%llu us",
392 (unsigned long long)nla_get_u64(sinfo
[NL80211_STA_INFO_T_OFFSET
]));
394 if (sinfo
[NL80211_STA_INFO_TX_BITRATE
]) {
397 parse_bitrate(sinfo
[NL80211_STA_INFO_TX_BITRATE
], buf
, sizeof(buf
));
398 printf("\n\ttx bitrate:\t%s", buf
);
401 if (sinfo
[NL80211_STA_INFO_RX_BITRATE
]) {
404 parse_bitrate(sinfo
[NL80211_STA_INFO_RX_BITRATE
], buf
, sizeof(buf
));
405 printf("\n\trx bitrate:\t%s", buf
);
408 if (sinfo
[NL80211_STA_INFO_RX_DURATION
])
409 printf("\n\trx duration:\t%lld us",
410 (unsigned long long)nla_get_u64(sinfo
[NL80211_STA_INFO_RX_DURATION
]));
412 if (sinfo
[NL80211_STA_INFO_EXPECTED_THROUGHPUT
]) {
415 thr
= nla_get_u32(sinfo
[NL80211_STA_INFO_EXPECTED_THROUGHPUT
]);
416 /* convert in Mbps but scale by 1000 to save kbps units */
417 thr
= thr
* 1000 / 1024;
419 printf("\n\texpected throughput:\t%u.%uMbps",
420 thr
/ 1000, thr
% 1000);
423 if (sinfo
[NL80211_STA_INFO_LLID
])
424 printf("\n\tmesh llid:\t%d",
425 nla_get_u16(sinfo
[NL80211_STA_INFO_LLID
]));
426 if (sinfo
[NL80211_STA_INFO_PLID
])
427 printf("\n\tmesh plid:\t%d",
428 nla_get_u16(sinfo
[NL80211_STA_INFO_PLID
]));
429 if (sinfo
[NL80211_STA_INFO_PLINK_STATE
]) {
430 switch (nla_get_u8(sinfo
[NL80211_STA_INFO_PLINK_STATE
])) {
432 strcpy(state_name
, "LISTEN");
435 strcpy(state_name
, "OPN_SNT");
438 strcpy(state_name
, "OPN_RCVD");
441 strcpy(state_name
, "CNF_RCVD");
444 strcpy(state_name
, "ESTAB");
447 strcpy(state_name
, "HOLDING");
450 strcpy(state_name
, "BLOCKED");
453 strcpy(state_name
, "UNKNOWN");
456 printf("\n\tmesh plink:\t%s", state_name
);
458 if (sinfo
[NL80211_STA_INFO_LOCAL_PM
]) {
459 printf("\n\tmesh local PS mode:\t");
460 print_power_mode(sinfo
[NL80211_STA_INFO_LOCAL_PM
]);
462 if (sinfo
[NL80211_STA_INFO_PEER_PM
]) {
463 printf("\n\tmesh peer PS mode:\t");
464 print_power_mode(sinfo
[NL80211_STA_INFO_PEER_PM
]);
466 if (sinfo
[NL80211_STA_INFO_NONPEER_PM
]) {
467 printf("\n\tmesh non-peer PS mode:\t");
468 print_power_mode(sinfo
[NL80211_STA_INFO_NONPEER_PM
]);
471 if (sinfo
[NL80211_STA_INFO_STA_FLAGS
]) {
472 sta_flags
= (struct nl80211_sta_flag_update
*)
473 nla_data(sinfo
[NL80211_STA_INFO_STA_FLAGS
]);
475 if (sta_flags
->mask
& BIT(NL80211_STA_FLAG_AUTHORIZED
)) {
476 printf("\n\tauthorized:\t");
477 if (sta_flags
->set
& BIT(NL80211_STA_FLAG_AUTHORIZED
))
483 if (sta_flags
->mask
& BIT(NL80211_STA_FLAG_AUTHENTICATED
)) {
484 printf("\n\tauthenticated:\t");
485 if (sta_flags
->set
& BIT(NL80211_STA_FLAG_AUTHENTICATED
))
491 if (sta_flags
->mask
& BIT(NL80211_STA_FLAG_ASSOCIATED
)) {
492 printf("\n\tassociated:\t");
493 if (sta_flags
->set
& BIT(NL80211_STA_FLAG_ASSOCIATED
))
499 if (sta_flags
->mask
& BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
)) {
500 printf("\n\tpreamble:\t");
501 if (sta_flags
->set
& BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
))
507 if (sta_flags
->mask
& BIT(NL80211_STA_FLAG_WME
)) {
508 printf("\n\tWMM/WME:\t");
509 if (sta_flags
->set
& BIT(NL80211_STA_FLAG_WME
))
515 if (sta_flags
->mask
& BIT(NL80211_STA_FLAG_MFP
)) {
516 printf("\n\tMFP:\t\t");
517 if (sta_flags
->set
& BIT(NL80211_STA_FLAG_MFP
))
523 if (sta_flags
->mask
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) {
524 printf("\n\tTDLS peer:\t");
525 if (sta_flags
->set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
532 if (sinfo
[NL80211_STA_INFO_TID_STATS
] && arg
!= NULL
&&
533 !strcmp((char *)arg
, "-v"))
534 parse_tid_stats(sinfo
[NL80211_STA_INFO_TID_STATS
]);
535 if (sinfo
[NL80211_STA_INFO_BSS_PARAM
])
536 parse_bss_param(sinfo
[NL80211_STA_INFO_BSS_PARAM
]);
537 if (sinfo
[NL80211_STA_INFO_CONNECTED_TIME
])
538 printf("\n\tconnected time:\t%u seconds",
539 nla_get_u32(sinfo
[NL80211_STA_INFO_CONNECTED_TIME
]));
545 static int handle_station_get(struct nl80211_state
*state
,
547 int argc
, char **argv
,
550 unsigned char mac_addr
[ETH_ALEN
];
555 if (mac_addr_a2n(mac_addr
, argv
[0])) {
556 fprintf(stderr
, "invalid mac address\n");
566 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
568 register_handler(print_sta_handler
, NULL
);
574 COMMAND(station
, get
, "<MAC address>",
575 NL80211_CMD_GET_STATION
, 0, CIB_NETDEV
, handle_station_get
,
576 "Get information for a specific station.");
578 static int handle_station_del(struct nl80211_state
*state
,
580 int argc
, char **argv
,
584 unsigned char mac_addr
[ETH_ALEN
];
591 if (mac_addr_a2n(mac_addr
, argv
[0])) {
592 fprintf(stderr
, "invalid mac address\n");
598 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
600 if (argc
> 1 && strcmp(argv
[0], "subtype") == 0) {
604 subtype
= strtod(argv
[0], &end
);
608 NLA_PUT_U8(msg
, NL80211_ATTR_MGMT_SUBTYPE
, subtype
);
613 if (argc
> 1 && strcmp(argv
[0], "reason-code") == 0) {
617 reason_code
= strtod(argv
[0], &end
);
621 NLA_PUT_U16(msg
, NL80211_ATTR_REASON_CODE
, reason_code
);
629 register_handler(print_sta_handler
, NULL
);
635 COMMAND(station
, del
, "<MAC address> [subtype <subtype>] [reason-code <code>]",
636 NL80211_CMD_DEL_STATION
, 0, CIB_NETDEV
, handle_station_del
,
637 "Remove the given station entry (use with caution!)\n"
638 "Example subtype values: 0xA (disassociation), 0xC (deauthentication)");
640 static const struct cmd
*station_set_plink
;
641 static const struct cmd
*station_set_vlan
;
642 static const struct cmd
*station_set_mesh_power_mode
;
644 static const struct cmd
*select_station_cmd(int argc
, char **argv
)
648 if (strcmp(argv
[1], "plink_action") == 0)
649 return station_set_plink
;
650 if (strcmp(argv
[1], "vlan") == 0)
651 return station_set_vlan
;
652 if (strcmp(argv
[1], "mesh_power_mode") == 0)
653 return station_set_mesh_power_mode
;
657 static int handle_station_set_plink(struct nl80211_state
*state
,
659 int argc
, char **argv
,
662 unsigned char plink_action
;
663 unsigned char mac_addr
[ETH_ALEN
];
668 if (mac_addr_a2n(mac_addr
, argv
[0])) {
669 fprintf(stderr
, "invalid mac address\n");
675 if (strcmp("plink_action", argv
[0]) != 0)
680 if (strcmp("open", argv
[0]) == 0)
681 plink_action
= NL80211_PLINK_ACTION_OPEN
;
682 else if (strcmp("block", argv
[0]) == 0)
683 plink_action
= NL80211_PLINK_ACTION_BLOCK
;
685 fprintf(stderr
, "plink action not supported\n");
694 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
695 NLA_PUT_U8(msg
, NL80211_ATTR_STA_PLINK_ACTION
, plink_action
);
701 COMMAND_ALIAS(station
, set
, "<MAC address> plink_action <open|block>",
702 NL80211_CMD_SET_STATION
, 0, CIB_NETDEV
, handle_station_set_plink
,
703 "Set mesh peer link action for this station (peer).",
704 select_station_cmd
, station_set_plink
);
706 static int handle_station_set_vlan(struct nl80211_state
*state
,
708 int argc
, char **argv
,
711 unsigned char mac_addr
[ETH_ALEN
];
712 unsigned long sta_vlan
= 0;
718 if (mac_addr_a2n(mac_addr
, argv
[0])) {
719 fprintf(stderr
, "invalid mac address\n");
725 if (strcmp("vlan", argv
[0]) != 0)
730 sta_vlan
= strtoul(argv
[0], &err
, 0);
732 fprintf(stderr
, "invalid vlan id\n");
741 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
742 NLA_PUT_U32(msg
, NL80211_ATTR_STA_VLAN
, sta_vlan
);
748 COMMAND_ALIAS(station
, set
, "<MAC address> vlan <ifindex>",
749 NL80211_CMD_SET_STATION
, 0, CIB_NETDEV
, handle_station_set_vlan
,
750 "Set an AP VLAN for this station.",
751 select_station_cmd
, station_set_vlan
);
753 static int handle_station_set_mesh_power_mode(struct nl80211_state
*state
,
755 int argc
, char **argv
,
758 unsigned char mesh_power_mode
;
759 unsigned char mac_addr
[ETH_ALEN
];
764 if (mac_addr_a2n(mac_addr
, argv
[0])) {
765 fprintf(stderr
, "invalid mac address\n");
771 if (strcmp("mesh_power_mode", argv
[0]) != 0)
776 if (strcmp("active", argv
[0]) == 0)
777 mesh_power_mode
= NL80211_MESH_POWER_ACTIVE
;
778 else if (strcmp("light", argv
[0]) == 0)
779 mesh_power_mode
= NL80211_MESH_POWER_LIGHT_SLEEP
;
780 else if (strcmp("deep", argv
[0]) == 0)
781 mesh_power_mode
= NL80211_MESH_POWER_DEEP_SLEEP
;
783 fprintf(stderr
, "unknown mesh power mode\n");
792 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
793 NLA_PUT_U32(msg
, NL80211_ATTR_LOCAL_MESH_POWER_MODE
, mesh_power_mode
);
799 COMMAND_ALIAS(station
, set
, "<MAC address> mesh_power_mode "
800 "<active|light|deep>", NL80211_CMD_SET_STATION
, 0, CIB_NETDEV
,
801 handle_station_set_mesh_power_mode
,
802 "Set link-specific mesh power mode for this station",
803 select_station_cmd
, station_set_mesh_power_mode
);
805 static int handle_station_dump(struct nl80211_state
*state
,
807 int argc
, char **argv
,
810 register_handler(print_sta_handler
, *argv
);
813 COMMAND(station
, dump
, "[-v]",
814 NL80211_CMD_GET_STATION
, NLM_F_DUMP
, CIB_NETDEV
, handle_station_dump
,
815 "List all stations known, e.g. the AP on managed interfaces");