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>
27 static void print_power_mode(struct nlattr
*a
)
29 enum nl80211_mesh_power_mode pm
= nla_get_u32(a
);
32 case NL80211_MESH_POWER_ACTIVE
:
35 case NL80211_MESH_POWER_LIGHT_SLEEP
:
36 printf("LIGHT SLEEP");
38 case NL80211_MESH_POWER_DEEP_SLEEP
:
47 int parse_txq_stats(char *buf
, int buflen
, struct nlattr
*tid_stats_attr
, int header
,
48 int tid
, const char *indent
)
50 struct nlattr
*txqstats_info
[NL80211_TXQ_STATS_MAX
+ 1], *txqinfo
;
51 static struct nla_policy txqstats_policy
[NL80211_TXQ_STATS_MAX
+ 1] = {
52 [NL80211_TXQ_STATS_BACKLOG_BYTES
] = { .type
= NLA_U32
},
53 [NL80211_TXQ_STATS_BACKLOG_PACKETS
] = { .type
= NLA_U32
},
54 [NL80211_TXQ_STATS_FLOWS
] = { .type
= NLA_U32
},
55 [NL80211_TXQ_STATS_DROPS
] = { .type
= NLA_U32
},
56 [NL80211_TXQ_STATS_ECN_MARKS
] = { .type
= NLA_U32
},
57 [NL80211_TXQ_STATS_OVERLIMIT
] = { .type
= NLA_U32
},
58 [NL80211_TXQ_STATS_COLLISIONS
] = { .type
= NLA_U32
},
59 [NL80211_TXQ_STATS_TX_BYTES
] = { .type
= NLA_U32
},
60 [NL80211_TXQ_STATS_TX_PACKETS
] = { .type
= NLA_U32
},
63 if (nla_parse_nested(txqstats_info
, NL80211_TXQ_STATS_MAX
, tid_stats_attr
,
65 printf("failed to parse nested TXQ stats attributes!");
70 pos
+= snprintf(buf
, buflen
, "\n%s\t%s\tqsz-byt\t"
71 "qsz-pkt\tflows\tdrops\tmarks\toverlmt\t"
72 "hashcol\ttx-bytes\ttx-packets", indent
,
73 tid
>= 0 ? "TID" : "");
75 pos
+= snprintf(pos
, buflen
- (pos
- buf
), "\n%s\t", indent
);
77 pos
+= snprintf(pos
, buflen
- (pos
- buf
), "%d", tid
);
79 #define PRINT_STAT(key, spacer) do { \
80 txqinfo = txqstats_info[NL80211_TXQ_STATS_ ## key]; \
81 pos += snprintf(pos, buflen - (pos - buf), spacer); \
83 pos += snprintf(pos, buflen - (pos - buf), "%u", \
84 nla_get_u32(txqinfo)); \
88 PRINT_STAT(BACKLOG_BYTES
, "\t");
89 PRINT_STAT(BACKLOG_PACKETS
, "\t");
90 PRINT_STAT(FLOWS
, "\t");
91 PRINT_STAT(DROPS
, "\t");
92 PRINT_STAT(ECN_MARKS
, "\t");
93 PRINT_STAT(OVERLIMIT
, "\t");
94 PRINT_STAT(COLLISIONS
, "\t");
95 PRINT_STAT(TX_BYTES
, "\t");
96 PRINT_STAT(TX_PACKETS
, "\t\t");
104 static void parse_tid_stats(struct nlattr
*tid_stats_attr
)
106 struct nlattr
*stats_info
[NL80211_TID_STATS_MAX
+ 1], *tidattr
, *info
;
107 static struct nla_policy stats_policy
[NL80211_TID_STATS_MAX
+ 1] = {
108 [NL80211_TID_STATS_RX_MSDU
] = { .type
= NLA_U64
},
109 [NL80211_TID_STATS_TX_MSDU
] = { .type
= NLA_U64
},
110 [NL80211_TID_STATS_TX_MSDU_RETRIES
] = { .type
= NLA_U64
},
111 [NL80211_TID_STATS_TX_MSDU_FAILED
] = { .type
= NLA_U64
},
112 [NL80211_TID_STATS_TXQ_STATS
] = { .type
= NLA_NESTED
},
115 char txqbuf
[2000] = {}, *pos
= txqbuf
;
116 int buflen
= sizeof(txqbuf
), foundtxq
= 0;
118 printf("\n\tMSDU:\n\t\tTID\trx\ttx\ttx retries\ttx failed");
119 nla_for_each_nested(tidattr
, tid_stats_attr
, rem
) {
120 if (nla_parse_nested(stats_info
, NL80211_TID_STATS_MAX
,
121 tidattr
, stats_policy
)) {
122 printf("failed to parse nested stats attributes!");
125 printf("\n\t\t%d", i
);
126 info
= stats_info
[NL80211_TID_STATS_RX_MSDU
];
128 printf("\t%llu", (unsigned long long)nla_get_u64(info
));
129 info
= stats_info
[NL80211_TID_STATS_TX_MSDU
];
131 printf("\t%llu", (unsigned long long)nla_get_u64(info
));
132 info
= stats_info
[NL80211_TID_STATS_TX_MSDU_RETRIES
];
134 printf("\t%llu", (unsigned long long)nla_get_u64(info
));
135 info
= stats_info
[NL80211_TID_STATS_TX_MSDU_FAILED
];
137 printf("\t\t%llu", (unsigned long long)nla_get_u64(info
));
138 info
= stats_info
[NL80211_TID_STATS_TXQ_STATS
];
140 pos
+= parse_txq_stats(pos
, buflen
- (pos
- txqbuf
), info
, !foundtxq
, i
, "\t");
148 printf("\n\tTXQs:%s", txqbuf
);
151 static void parse_bss_param(struct nlattr
*bss_param_attr
)
153 struct nlattr
*bss_param_info
[NL80211_STA_BSS_PARAM_MAX
+ 1], *info
;
154 static struct nla_policy bss_poilcy
[NL80211_STA_BSS_PARAM_MAX
+ 1] = {
155 [NL80211_STA_BSS_PARAM_CTS_PROT
] = { .type
= NLA_FLAG
},
156 [NL80211_STA_BSS_PARAM_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
157 [NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME
] = { .type
= NLA_FLAG
},
158 [NL80211_STA_BSS_PARAM_DTIM_PERIOD
] = { .type
= NLA_U8
},
159 [NL80211_STA_BSS_PARAM_BEACON_INTERVAL
] = { .type
= NLA_U16
},
162 if (nla_parse_nested(bss_param_info
, NL80211_STA_BSS_PARAM_MAX
,
163 bss_param_attr
, bss_poilcy
)) {
164 printf("failed to parse nested bss param attributes!");
167 info
= bss_param_info
[NL80211_STA_BSS_PARAM_DTIM_PERIOD
];
169 printf("\n\tDTIM period:\t%u", nla_get_u8(info
));
170 info
= bss_param_info
[NL80211_STA_BSS_PARAM_BEACON_INTERVAL
];
172 printf("\n\tbeacon interval:%u", nla_get_u16(info
));
173 info
= bss_param_info
[NL80211_STA_BSS_PARAM_CTS_PROT
];
175 printf("\n\tCTS protection:");
176 if (nla_get_u16(info
))
181 info
= bss_param_info
[NL80211_STA_BSS_PARAM_SHORT_PREAMBLE
];
183 printf("\n\tshort preamble:");
184 if (nla_get_u16(info
))
189 info
= bss_param_info
[NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME
];
191 printf("\n\tshort slot time:");
192 if (nla_get_u16(info
))
199 void parse_bitrate(struct nlattr
*bitrate_attr
, char *buf
, int buflen
)
203 struct nlattr
*rinfo
[NL80211_RATE_INFO_MAX
+ 1];
204 static struct nla_policy rate_policy
[NL80211_RATE_INFO_MAX
+ 1] = {
205 [NL80211_RATE_INFO_BITRATE
] = { .type
= NLA_U16
},
206 [NL80211_RATE_INFO_BITRATE32
] = { .type
= NLA_U32
},
207 [NL80211_RATE_INFO_MCS
] = { .type
= NLA_U8
},
208 [NL80211_RATE_INFO_40_MHZ_WIDTH
] = { .type
= NLA_FLAG
},
209 [NL80211_RATE_INFO_SHORT_GI
] = { .type
= NLA_FLAG
},
212 if (nla_parse_nested(rinfo
, NL80211_RATE_INFO_MAX
,
213 bitrate_attr
, rate_policy
)) {
214 snprintf(buf
, buflen
, "failed to parse nested rate attributes!");
218 if (rinfo
[NL80211_RATE_INFO_BITRATE32
])
219 rate
= nla_get_u32(rinfo
[NL80211_RATE_INFO_BITRATE32
]);
220 else if (rinfo
[NL80211_RATE_INFO_BITRATE
])
221 rate
= nla_get_u16(rinfo
[NL80211_RATE_INFO_BITRATE
]);
223 pos
+= snprintf(pos
, buflen
- (pos
- buf
),
224 "%d.%d MBit/s", rate
/ 10, rate
% 10);
226 pos
+= snprintf(pos
, buflen
- (pos
- buf
), "(unknown)");
228 if (rinfo
[NL80211_RATE_INFO_MCS
])
229 pos
+= snprintf(pos
, buflen
- (pos
- buf
),
230 " MCS %d", nla_get_u8(rinfo
[NL80211_RATE_INFO_MCS
]));
231 if (rinfo
[NL80211_RATE_INFO_VHT_MCS
])
232 pos
+= snprintf(pos
, buflen
- (pos
- buf
),
233 " VHT-MCS %d", nla_get_u8(rinfo
[NL80211_RATE_INFO_VHT_MCS
]));
234 if (rinfo
[NL80211_RATE_INFO_40_MHZ_WIDTH
])
235 pos
+= snprintf(pos
, buflen
- (pos
- buf
), " 40MHz");
236 if (rinfo
[NL80211_RATE_INFO_80_MHZ_WIDTH
])
237 pos
+= snprintf(pos
, buflen
- (pos
- buf
), " 80MHz");
238 if (rinfo
[NL80211_RATE_INFO_80P80_MHZ_WIDTH
])
239 pos
+= snprintf(pos
, buflen
- (pos
- buf
), " 80P80MHz");
240 if (rinfo
[NL80211_RATE_INFO_160_MHZ_WIDTH
])
241 pos
+= snprintf(pos
, buflen
- (pos
- buf
), " 160MHz");
242 if (rinfo
[NL80211_RATE_INFO_320_MHZ_WIDTH
])
243 pos
+= snprintf(pos
, buflen
- (pos
- buf
), " 320MHz");
244 if (rinfo
[NL80211_RATE_INFO_1_MHZ_WIDTH
])
245 pos
+= snprintf(pos
, buflen
- (pos
- buf
), " 1MHz");
246 if (rinfo
[NL80211_RATE_INFO_2_MHZ_WIDTH
])
247 pos
+= snprintf(pos
, buflen
- (pos
- buf
), " 2MHz");
248 if (rinfo
[NL80211_RATE_INFO_4_MHZ_WIDTH
])
249 pos
+= snprintf(pos
, buflen
- (pos
- buf
), " 4MHz");
250 if (rinfo
[NL80211_RATE_INFO_8_MHZ_WIDTH
])
251 pos
+= snprintf(pos
, buflen
- (pos
- buf
), " 8MHz");
252 if (rinfo
[NL80211_RATE_INFO_16_MHZ_WIDTH
])
253 pos
+= snprintf(pos
, buflen
- (pos
- buf
), " 16MHz");
254 if (rinfo
[NL80211_RATE_INFO_SHORT_GI
])
255 pos
+= snprintf(pos
, buflen
- (pos
- buf
), " short GI");
256 if (rinfo
[NL80211_RATE_INFO_VHT_NSS
])
257 pos
+= snprintf(pos
, buflen
- (pos
- buf
),
258 " VHT-NSS %d", nla_get_u8(rinfo
[NL80211_RATE_INFO_VHT_NSS
]));
259 if (rinfo
[NL80211_RATE_INFO_HE_MCS
])
260 pos
+= snprintf(pos
, buflen
- (pos
- buf
),
261 " HE-MCS %d", nla_get_u8(rinfo
[NL80211_RATE_INFO_HE_MCS
]));
262 if (rinfo
[NL80211_RATE_INFO_HE_NSS
])
263 pos
+= snprintf(pos
, buflen
- (pos
- buf
),
264 " HE-NSS %d", nla_get_u8(rinfo
[NL80211_RATE_INFO_HE_NSS
]));
265 if (rinfo
[NL80211_RATE_INFO_HE_GI
])
266 pos
+= snprintf(pos
, buflen
- (pos
- buf
),
267 " HE-GI %d", nla_get_u8(rinfo
[NL80211_RATE_INFO_HE_GI
]));
268 if (rinfo
[NL80211_RATE_INFO_HE_DCM
])
269 pos
+= snprintf(pos
, buflen
- (pos
- buf
),
270 " HE-DCM %d", nla_get_u8(rinfo
[NL80211_RATE_INFO_HE_DCM
]));
271 if (rinfo
[NL80211_RATE_INFO_HE_RU_ALLOC
])
272 pos
+= snprintf(pos
, buflen
- (pos
- buf
),
273 " HE-RU-ALLOC %d", nla_get_u8(rinfo
[NL80211_RATE_INFO_HE_RU_ALLOC
]));
274 if (rinfo
[NL80211_RATE_INFO_EHT_MCS
])
275 pos
+= snprintf(pos
, buflen
- (pos
- buf
),
276 " EHT-MCS %d", nla_get_u8(rinfo
[NL80211_RATE_INFO_EHT_MCS
]));
277 if (rinfo
[NL80211_RATE_INFO_EHT_NSS
])
278 pos
+= snprintf(pos
, buflen
- (pos
- buf
),
279 " EHT-NSS %d", nla_get_u8(rinfo
[NL80211_RATE_INFO_EHT_NSS
]));
280 if (rinfo
[NL80211_RATE_INFO_EHT_GI
])
281 pos
+= snprintf(pos
, buflen
- (pos
- buf
),
282 " EHT-GI %d", nla_get_u8(rinfo
[NL80211_RATE_INFO_EHT_GI
]));
283 if (rinfo
[NL80211_RATE_INFO_EHT_RU_ALLOC
])
284 pos
+= snprintf(pos
, buflen
- (pos
- buf
),
285 " EHT-RU-ALLOC %d", nla_get_u8(rinfo
[NL80211_RATE_INFO_EHT_RU_ALLOC
]));
288 static char *get_chain_signal(struct nlattr
*attr_list
)
299 nla_for_each_nested(attr
, attr_list
, rem
) {
305 cur
+= snprintf(cur
, sizeof(buf
) - (cur
- buf
), "%s%d", prefix
,
306 (int8_t) nla_get_u8(attr
));
310 snprintf(cur
, sizeof(buf
) - (cur
- buf
), "] ");
315 static int print_sta_handler(struct nl_msg
*msg
, void *arg
)
317 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
318 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
319 struct nlattr
*sinfo
[NL80211_STA_INFO_MAX
+ 1];
320 char mac_addr
[20], state_name
[10], dev
[20];
321 struct nl80211_sta_flag_update
*sta_flags
;
322 static struct nla_policy stats_policy
[NL80211_STA_INFO_MAX
+ 1] = {
323 [NL80211_STA_INFO_INACTIVE_TIME
] = { .type
= NLA_U32
},
324 [NL80211_STA_INFO_RX_BYTES
] = { .type
= NLA_U32
},
325 [NL80211_STA_INFO_TX_BYTES
] = { .type
= NLA_U32
},
326 [NL80211_STA_INFO_RX_BYTES64
] = { .type
= NLA_U64
},
327 [NL80211_STA_INFO_TX_BYTES64
] = { .type
= NLA_U64
},
328 [NL80211_STA_INFO_RX_PACKETS
] = { .type
= NLA_U32
},
329 [NL80211_STA_INFO_TX_PACKETS
] = { .type
= NLA_U32
},
330 [NL80211_STA_INFO_BEACON_RX
] = { .type
= NLA_U64
},
331 [NL80211_STA_INFO_SIGNAL
] = { .type
= NLA_U8
},
332 [NL80211_STA_INFO_T_OFFSET
] = { .type
= NLA_U64
},
333 [NL80211_STA_INFO_TX_BITRATE
] = { .type
= NLA_NESTED
},
334 [NL80211_STA_INFO_RX_BITRATE
] = { .type
= NLA_NESTED
},
335 [NL80211_STA_INFO_LLID
] = { .type
= NLA_U16
},
336 [NL80211_STA_INFO_PLID
] = { .type
= NLA_U16
},
337 [NL80211_STA_INFO_PLINK_STATE
] = { .type
= NLA_U8
},
338 [NL80211_STA_INFO_TX_RETRIES
] = { .type
= NLA_U32
},
339 [NL80211_STA_INFO_TX_FAILED
] = { .type
= NLA_U32
},
340 [NL80211_STA_INFO_BEACON_LOSS
] = { .type
= NLA_U32
},
341 [NL80211_STA_INFO_RX_DROP_MISC
] = { .type
= NLA_U64
},
342 [NL80211_STA_INFO_STA_FLAGS
] =
343 { .minlen
= sizeof(struct nl80211_sta_flag_update
) },
344 [NL80211_STA_INFO_LOCAL_PM
] = { .type
= NLA_U32
},
345 [NL80211_STA_INFO_PEER_PM
] = { .type
= NLA_U32
},
346 [NL80211_STA_INFO_NONPEER_PM
] = { .type
= NLA_U32
},
347 [NL80211_STA_INFO_CHAIN_SIGNAL
] = { .type
= NLA_NESTED
},
348 [NL80211_STA_INFO_CHAIN_SIGNAL_AVG
] = { .type
= NLA_NESTED
},
349 [NL80211_STA_INFO_TID_STATS
] = { .type
= NLA_NESTED
},
350 [NL80211_STA_INFO_BSS_PARAM
] = { .type
= NLA_NESTED
},
351 [NL80211_STA_INFO_RX_DURATION
] = { .type
= NLA_U64
},
352 [NL80211_STA_INFO_TX_DURATION
] = { .type
= NLA_U64
},
353 [NL80211_STA_INFO_ACK_SIGNAL
] = {.type
= NLA_U8
},
354 [NL80211_STA_INFO_ACK_SIGNAL_AVG
] = { .type
= NLA_U8
},
355 [NL80211_STA_INFO_AIRTIME_LINK_METRIC
] = { .type
= NLA_U32
},
356 [NL80211_STA_INFO_CONNECTED_TO_AS
] = { .type
= NLA_U8
},
357 [NL80211_STA_INFO_CONNECTED_TO_GATE
] = { .type
= NLA_U8
},
361 unsigned long long now_ms
;
363 gettimeofday(&now
, NULL
);
364 now_ms
= now
.tv_sec
* 1000ULL;
365 now_ms
+= (now
.tv_usec
/ 1000);
367 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
368 genlmsg_attrlen(gnlh
, 0), NULL
);
371 * TODO: validate the interface and mac address!
372 * Otherwise, there's a race condition as soon as
373 * the kernel starts sending station notifications.
376 if (!tb
[NL80211_ATTR_STA_INFO
]) {
377 fprintf(stderr
, "sta stats missing!\n");
380 if (nla_parse_nested(sinfo
, NL80211_STA_INFO_MAX
,
381 tb
[NL80211_ATTR_STA_INFO
],
383 fprintf(stderr
, "failed to parse nested attributes!\n");
387 mac_addr_n2a(mac_addr
, nla_data(tb
[NL80211_ATTR_MAC
]));
388 if_indextoname(nla_get_u32(tb
[NL80211_ATTR_IFINDEX
]), dev
);
389 printf("Station %s (on %s)", mac_addr
, dev
);
391 if (sinfo
[NL80211_STA_INFO_INACTIVE_TIME
])
392 printf("\n\tinactive time:\t%u ms",
393 nla_get_u32(sinfo
[NL80211_STA_INFO_INACTIVE_TIME
]));
394 if (sinfo
[NL80211_STA_INFO_RX_BYTES64
])
395 printf("\n\trx bytes:\t%llu",
396 (unsigned long long)nla_get_u64(sinfo
[NL80211_STA_INFO_RX_BYTES64
]));
397 else if (sinfo
[NL80211_STA_INFO_RX_BYTES
])
398 printf("\n\trx bytes:\t%u",
399 nla_get_u32(sinfo
[NL80211_STA_INFO_RX_BYTES
]));
400 if (sinfo
[NL80211_STA_INFO_RX_PACKETS
])
401 printf("\n\trx packets:\t%u",
402 nla_get_u32(sinfo
[NL80211_STA_INFO_RX_PACKETS
]));
403 if (sinfo
[NL80211_STA_INFO_TX_BYTES64
])
404 printf("\n\ttx bytes:\t%llu",
405 (unsigned long long)nla_get_u64(sinfo
[NL80211_STA_INFO_TX_BYTES64
]));
406 else if (sinfo
[NL80211_STA_INFO_TX_BYTES
])
407 printf("\n\ttx bytes:\t%u",
408 nla_get_u32(sinfo
[NL80211_STA_INFO_TX_BYTES
]));
409 if (sinfo
[NL80211_STA_INFO_TX_PACKETS
])
410 printf("\n\ttx packets:\t%u",
411 nla_get_u32(sinfo
[NL80211_STA_INFO_TX_PACKETS
]));
412 if (sinfo
[NL80211_STA_INFO_TX_RETRIES
])
413 printf("\n\ttx retries:\t%u",
414 nla_get_u32(sinfo
[NL80211_STA_INFO_TX_RETRIES
]));
415 if (sinfo
[NL80211_STA_INFO_TX_FAILED
])
416 printf("\n\ttx failed:\t%u",
417 nla_get_u32(sinfo
[NL80211_STA_INFO_TX_FAILED
]));
418 if (sinfo
[NL80211_STA_INFO_BEACON_LOSS
])
419 printf("\n\tbeacon loss:\t%u",
420 nla_get_u32(sinfo
[NL80211_STA_INFO_BEACON_LOSS
]));
421 if (sinfo
[NL80211_STA_INFO_BEACON_RX
])
422 printf("\n\tbeacon rx:\t%llu",
423 (unsigned long long)nla_get_u64(sinfo
[NL80211_STA_INFO_BEACON_RX
]));
424 if (sinfo
[NL80211_STA_INFO_RX_DROP_MISC
])
425 printf("\n\trx drop misc:\t%llu",
426 (unsigned long long)nla_get_u64(sinfo
[NL80211_STA_INFO_RX_DROP_MISC
]));
428 chain
= get_chain_signal(sinfo
[NL80211_STA_INFO_CHAIN_SIGNAL
]);
429 if (sinfo
[NL80211_STA_INFO_SIGNAL
])
430 printf("\n\tsignal: \t%d %sdBm",
431 (int8_t)nla_get_u8(sinfo
[NL80211_STA_INFO_SIGNAL
]),
434 chain
= get_chain_signal(sinfo
[NL80211_STA_INFO_CHAIN_SIGNAL_AVG
]);
435 if (sinfo
[NL80211_STA_INFO_SIGNAL_AVG
])
436 printf("\n\tsignal avg:\t%d %sdBm",
437 (int8_t)nla_get_u8(sinfo
[NL80211_STA_INFO_SIGNAL_AVG
]),
440 if (sinfo
[NL80211_STA_INFO_BEACON_SIGNAL_AVG
])
441 printf("\n\tbeacon signal avg:\t%d dBm",
442 (int8_t)nla_get_u8(sinfo
[NL80211_STA_INFO_BEACON_SIGNAL_AVG
]));
443 if (sinfo
[NL80211_STA_INFO_T_OFFSET
])
444 printf("\n\tToffset:\t%llu us",
445 (unsigned long long)nla_get_u64(sinfo
[NL80211_STA_INFO_T_OFFSET
]));
447 if (sinfo
[NL80211_STA_INFO_TX_BITRATE
]) {
450 parse_bitrate(sinfo
[NL80211_STA_INFO_TX_BITRATE
], buf
, sizeof(buf
));
451 printf("\n\ttx bitrate:\t%s", buf
);
454 if (sinfo
[NL80211_STA_INFO_TX_DURATION
])
455 printf("\n\ttx duration:\t%lld us",
456 (unsigned long long)nla_get_u64(sinfo
[NL80211_STA_INFO_TX_DURATION
]));
458 if (sinfo
[NL80211_STA_INFO_RX_BITRATE
]) {
461 parse_bitrate(sinfo
[NL80211_STA_INFO_RX_BITRATE
], buf
, sizeof(buf
));
462 printf("\n\trx bitrate:\t%s", buf
);
465 if (sinfo
[NL80211_STA_INFO_RX_DURATION
])
466 printf("\n\trx duration:\t%lld us",
467 (unsigned long long)nla_get_u64(sinfo
[NL80211_STA_INFO_RX_DURATION
]));
469 if (sinfo
[NL80211_STA_INFO_ACK_SIGNAL
])
470 printf("\n\tlast ack signal:%d dBm",
471 (int8_t)nla_get_u8(sinfo
[NL80211_STA_INFO_ACK_SIGNAL
]));
473 if (sinfo
[NL80211_STA_INFO_ACK_SIGNAL_AVG
])
474 printf("\n\tavg ack signal:\t%d dBm",
475 (int8_t)nla_get_u8(sinfo
[NL80211_STA_INFO_ACK_SIGNAL_AVG
]));
477 if (sinfo
[NL80211_STA_INFO_AIRTIME_WEIGHT
]) {
478 printf("\n\tairtime weight: %d", nla_get_u16(sinfo
[NL80211_STA_INFO_AIRTIME_WEIGHT
]));
481 if (sinfo
[NL80211_STA_INFO_EXPECTED_THROUGHPUT
]) {
484 thr
= nla_get_u32(sinfo
[NL80211_STA_INFO_EXPECTED_THROUGHPUT
]);
485 /* convert in Mbps but scale by 1000 to save kbps units */
486 thr
= thr
* 1000 / 1024;
488 printf("\n\texpected throughput:\t%u.%uMbps",
489 thr
/ 1000, thr
% 1000);
492 if (sinfo
[NL80211_STA_INFO_LLID
])
493 printf("\n\tmesh llid:\t%d",
494 nla_get_u16(sinfo
[NL80211_STA_INFO_LLID
]));
495 if (sinfo
[NL80211_STA_INFO_PLID
])
496 printf("\n\tmesh plid:\t%d",
497 nla_get_u16(sinfo
[NL80211_STA_INFO_PLID
]));
498 if (sinfo
[NL80211_STA_INFO_PLINK_STATE
]) {
499 switch (nla_get_u8(sinfo
[NL80211_STA_INFO_PLINK_STATE
])) {
501 strcpy(state_name
, "LISTEN");
504 strcpy(state_name
, "OPN_SNT");
507 strcpy(state_name
, "OPN_RCVD");
510 strcpy(state_name
, "CNF_RCVD");
513 strcpy(state_name
, "ESTAB");
516 strcpy(state_name
, "HOLDING");
519 strcpy(state_name
, "BLOCKED");
522 strcpy(state_name
, "UNKNOWN");
525 printf("\n\tmesh plink:\t%s", state_name
);
527 if (sinfo
[NL80211_STA_INFO_AIRTIME_LINK_METRIC
])
528 printf("\n\tmesh airtime link metric: %d",
529 nla_get_u32(sinfo
[NL80211_STA_INFO_AIRTIME_LINK_METRIC
]));
530 if (sinfo
[NL80211_STA_INFO_CONNECTED_TO_GATE
])
531 printf("\n\tmesh connected to gate:\t%s",
532 nla_get_u8(sinfo
[NL80211_STA_INFO_CONNECTED_TO_GATE
]) ?
534 if (sinfo
[NL80211_STA_INFO_CONNECTED_TO_AS
])
535 printf("\n\tmesh connected to auth server:\t%s",
536 nla_get_u8(sinfo
[NL80211_STA_INFO_CONNECTED_TO_AS
]) ?
539 if (sinfo
[NL80211_STA_INFO_LOCAL_PM
]) {
540 printf("\n\tmesh local PS mode:\t");
541 print_power_mode(sinfo
[NL80211_STA_INFO_LOCAL_PM
]);
543 if (sinfo
[NL80211_STA_INFO_PEER_PM
]) {
544 printf("\n\tmesh peer PS mode:\t");
545 print_power_mode(sinfo
[NL80211_STA_INFO_PEER_PM
]);
547 if (sinfo
[NL80211_STA_INFO_NONPEER_PM
]) {
548 printf("\n\tmesh non-peer PS mode:\t");
549 print_power_mode(sinfo
[NL80211_STA_INFO_NONPEER_PM
]);
552 if (sinfo
[NL80211_STA_INFO_STA_FLAGS
]) {
553 sta_flags
= (struct nl80211_sta_flag_update
*)
554 nla_data(sinfo
[NL80211_STA_INFO_STA_FLAGS
]);
556 if (sta_flags
->mask
& BIT(NL80211_STA_FLAG_AUTHORIZED
)) {
557 printf("\n\tauthorized:\t");
558 if (sta_flags
->set
& BIT(NL80211_STA_FLAG_AUTHORIZED
))
564 if (sta_flags
->mask
& BIT(NL80211_STA_FLAG_AUTHENTICATED
)) {
565 printf("\n\tauthenticated:\t");
566 if (sta_flags
->set
& BIT(NL80211_STA_FLAG_AUTHENTICATED
))
572 if (sta_flags
->mask
& BIT(NL80211_STA_FLAG_ASSOCIATED
)) {
573 printf("\n\tassociated:\t");
574 if (sta_flags
->set
& BIT(NL80211_STA_FLAG_ASSOCIATED
))
580 if (sta_flags
->mask
& BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
)) {
581 printf("\n\tpreamble:\t");
582 if (sta_flags
->set
& BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
))
588 if (sta_flags
->mask
& BIT(NL80211_STA_FLAG_WME
)) {
589 printf("\n\tWMM/WME:\t");
590 if (sta_flags
->set
& BIT(NL80211_STA_FLAG_WME
))
596 if (sta_flags
->mask
& BIT(NL80211_STA_FLAG_MFP
)) {
597 printf("\n\tMFP:\t\t");
598 if (sta_flags
->set
& BIT(NL80211_STA_FLAG_MFP
))
604 if (sta_flags
->mask
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) {
605 printf("\n\tTDLS peer:\t");
606 if (sta_flags
->set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
613 if (sinfo
[NL80211_STA_INFO_TID_STATS
] && arg
!= NULL
&&
614 !strcmp((char *)arg
, "-v"))
615 parse_tid_stats(sinfo
[NL80211_STA_INFO_TID_STATS
]);
616 if (sinfo
[NL80211_STA_INFO_BSS_PARAM
])
617 parse_bss_param(sinfo
[NL80211_STA_INFO_BSS_PARAM
]);
618 if (sinfo
[NL80211_STA_INFO_CONNECTED_TIME
])
619 printf("\n\tconnected time:\t%u seconds",
620 nla_get_u32(sinfo
[NL80211_STA_INFO_CONNECTED_TIME
]));
621 if (sinfo
[NL80211_STA_INFO_ASSOC_AT_BOOTTIME
]) {
622 unsigned long long bt
;
623 struct timespec now_ts
;
624 unsigned long long boot_ns
;
625 unsigned long long assoc_at_ms
;
627 clock_gettime(CLOCK_BOOTTIME
, &now_ts
);
628 boot_ns
= now_ts
.tv_sec
* 1000000000ULL;
629 boot_ns
+= now_ts
.tv_nsec
;
631 bt
= (unsigned long long)nla_get_u64(sinfo
[NL80211_STA_INFO_ASSOC_AT_BOOTTIME
]);
632 printf("\n\tassociated at [boottime]:\t%llu.%.3llus",
633 bt
/1000000000, (bt
%1000000000)/1000000);
634 assoc_at_ms
= now_ms
- ((boot_ns
- bt
) / 1000000);
635 printf("\n\tassociated at:\t%llu ms", assoc_at_ms
);
638 printf("\n\tcurrent time:\t%llu ms\n", now_ms
);
642 static int handle_station_get(struct nl80211_state
*state
,
644 int argc
, char **argv
,
647 unsigned char mac_addr
[ETH_ALEN
];
652 if (mac_addr_a2n(mac_addr
, argv
[0])) {
653 fprintf(stderr
, "invalid mac address\n");
663 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
665 register_handler(print_sta_handler
, NULL
);
671 COMMAND(station
, get
, "<MAC address>",
672 NL80211_CMD_GET_STATION
, 0, CIB_NETDEV
, handle_station_get
,
673 "Get information for a specific station.");
675 static int handle_station_del(struct nl80211_state
*state
,
677 int argc
, char **argv
,
681 unsigned char mac_addr
[ETH_ALEN
];
688 if (mac_addr_a2n(mac_addr
, argv
[0])) {
689 fprintf(stderr
, "invalid mac address\n");
695 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
697 if (argc
> 1 && strcmp(argv
[0], "subtype") == 0) {
701 subtype
= strtod(argv
[0], &end
);
705 NLA_PUT_U8(msg
, NL80211_ATTR_MGMT_SUBTYPE
, subtype
);
710 if (argc
> 1 && strcmp(argv
[0], "reason-code") == 0) {
714 reason_code
= strtod(argv
[0], &end
);
718 NLA_PUT_U16(msg
, NL80211_ATTR_REASON_CODE
, reason_code
);
726 register_handler(print_sta_handler
, NULL
);
732 COMMAND(station
, del
, "<MAC address> [subtype <subtype>] [reason-code <code>]",
733 NL80211_CMD_DEL_STATION
, 0, CIB_NETDEV
, handle_station_del
,
734 "Remove the given station entry (use with caution!)\n"
735 "Example subtype values: 0xA (disassociation), 0xC (deauthentication)");
737 static const struct cmd
*station_set_plink
;
738 static const struct cmd
*station_set_vlan
;
739 static const struct cmd
*station_set_mesh_power_mode
;
740 static const struct cmd
*station_set_airtime_weight
;
741 static const struct cmd
*station_set_txpwr
;
743 static const struct cmd
*select_station_cmd(int argc
, char **argv
)
747 if (strcmp(argv
[1], "plink_action") == 0)
748 return station_set_plink
;
749 if (strcmp(argv
[1], "vlan") == 0)
750 return station_set_vlan
;
751 if (strcmp(argv
[1], "mesh_power_mode") == 0)
752 return station_set_mesh_power_mode
;
753 if (strcmp(argv
[1], "airtime_weight") == 0)
754 return station_set_airtime_weight
;
755 if (strcmp(argv
[1], "txpwr") == 0)
756 return station_set_txpwr
;
760 static int handle_station_set_plink(struct nl80211_state
*state
,
762 int argc
, char **argv
,
765 unsigned char plink_action
;
766 unsigned char mac_addr
[ETH_ALEN
];
771 if (mac_addr_a2n(mac_addr
, argv
[0])) {
772 fprintf(stderr
, "invalid mac address\n");
778 if (strcmp("plink_action", argv
[0]) != 0)
783 if (strcmp("open", argv
[0]) == 0)
784 plink_action
= NL80211_PLINK_ACTION_OPEN
;
785 else if (strcmp("block", argv
[0]) == 0)
786 plink_action
= NL80211_PLINK_ACTION_BLOCK
;
788 fprintf(stderr
, "plink action not supported\n");
797 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
798 NLA_PUT_U8(msg
, NL80211_ATTR_STA_PLINK_ACTION
, plink_action
);
804 COMMAND_ALIAS(station
, set
, "<MAC address> plink_action <open|block>",
805 NL80211_CMD_SET_STATION
, 0, CIB_NETDEV
, handle_station_set_plink
,
806 "Set mesh peer link action for this station (peer).",
807 select_station_cmd
, station_set_plink
);
809 static int handle_station_set_vlan(struct nl80211_state
*state
,
811 int argc
, char **argv
,
814 unsigned char mac_addr
[ETH_ALEN
];
815 unsigned long sta_vlan
= 0;
821 if (mac_addr_a2n(mac_addr
, argv
[0])) {
822 fprintf(stderr
, "invalid mac address\n");
828 if (strcmp("vlan", argv
[0]) != 0)
833 sta_vlan
= strtoul(argv
[0], &err
, 0);
835 fprintf(stderr
, "invalid vlan id\n");
844 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
845 NLA_PUT_U32(msg
, NL80211_ATTR_STA_VLAN
, sta_vlan
);
851 COMMAND_ALIAS(station
, set
, "<MAC address> vlan <ifindex>",
852 NL80211_CMD_SET_STATION
, 0, CIB_NETDEV
, handle_station_set_vlan
,
853 "Set an AP VLAN for this station.",
854 select_station_cmd
, station_set_vlan
);
856 static int handle_station_set_mesh_power_mode(struct nl80211_state
*state
,
858 int argc
, char **argv
,
861 unsigned char mesh_power_mode
;
862 unsigned char mac_addr
[ETH_ALEN
];
867 if (mac_addr_a2n(mac_addr
, argv
[0])) {
868 fprintf(stderr
, "invalid mac address\n");
874 if (strcmp("mesh_power_mode", argv
[0]) != 0)
879 if (strcmp("active", argv
[0]) == 0)
880 mesh_power_mode
= NL80211_MESH_POWER_ACTIVE
;
881 else if (strcmp("light", argv
[0]) == 0)
882 mesh_power_mode
= NL80211_MESH_POWER_LIGHT_SLEEP
;
883 else if (strcmp("deep", argv
[0]) == 0)
884 mesh_power_mode
= NL80211_MESH_POWER_DEEP_SLEEP
;
886 fprintf(stderr
, "unknown mesh power mode\n");
895 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
896 NLA_PUT_U32(msg
, NL80211_ATTR_LOCAL_MESH_POWER_MODE
, mesh_power_mode
);
902 COMMAND_ALIAS(station
, set
, "<MAC address> mesh_power_mode "
903 "<active|light|deep>", NL80211_CMD_SET_STATION
, 0, CIB_NETDEV
,
904 handle_station_set_mesh_power_mode
,
905 "Set link-specific mesh power mode for this station",
906 select_station_cmd
, station_set_mesh_power_mode
);
908 static int handle_station_set_airtime_weight(struct nl80211_state
*state
,
910 int argc
, char **argv
,
913 unsigned char mac_addr
[ETH_ALEN
];
914 unsigned long airtime_weight
= 0;
920 if (mac_addr_a2n(mac_addr
, argv
[0])) {
921 fprintf(stderr
, "invalid mac address\n");
927 if (strcmp("airtime_weight", argv
[0]) != 0)
932 airtime_weight
= strtoul(argv
[0], &err
, 0);
934 fprintf(stderr
, "invalid airtime weight\n");
943 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
944 NLA_PUT_U16(msg
, NL80211_ATTR_AIRTIME_WEIGHT
, airtime_weight
);
951 COMMAND_ALIAS(station
, set
, "<MAC address> airtime_weight <weight>",
952 NL80211_CMD_SET_STATION
, 0, CIB_NETDEV
, handle_station_set_airtime_weight
,
953 "Set airtime weight for this station.",
954 select_station_cmd
, station_set_airtime_weight
);
956 static int handle_station_set_txpwr(struct nl80211_state
*state
,
958 int argc
, char **argv
,
961 enum nl80211_tx_power_setting type
;
962 unsigned char mac_addr
[ETH_ALEN
];
966 if (argc
!= 3 && argc
!= 4)
969 if (mac_addr_a2n(mac_addr
, argv
[0])) {
970 fprintf(stderr
, "invalid mac address\n");
974 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
978 if (strcmp("txpwr", argv
[0]) != 0)
983 if (!strcmp(argv
[0], "auto"))
984 type
= NL80211_TX_POWER_AUTOMATIC
;
985 else if (!strcmp(argv
[0], "limit"))
986 type
= NL80211_TX_POWER_LIMITED
;
988 printf("Invalid parameter: %s\n", argv
[0]);
992 NLA_PUT_U8(msg
, NL80211_ATTR_STA_TX_POWER_SETTING
, type
);
994 if (type
!= NL80211_TX_POWER_AUTOMATIC
) {
996 printf("Missing TX power level argument.\n");
1003 sta_txpwr
= strtoul(argv
[0], &err
, 0);
1004 NLA_PUT_U16(msg
, NL80211_ATTR_STA_TX_POWER
, sta_txpwr
);
1017 COMMAND_ALIAS(station
, set
, "<MAC address> txpwr <auto|limit> [<tx power dBm>]",
1018 NL80211_CMD_SET_STATION
, 0, CIB_NETDEV
, handle_station_set_txpwr
,
1019 "Set Tx power for this station.",
1020 select_station_cmd
, station_set_txpwr
);
1022 static int handle_station_dump(struct nl80211_state
*state
,
1024 int argc
, char **argv
,
1027 register_handler(print_sta_handler
, *argv
);
1030 COMMAND(station
, dump
, "[-v]",
1031 NL80211_CMD_GET_STATION
, NLM_F_DUMP
, CIB_NETDEV
, handle_station_dump
,
1032 "List all stations known, e.g. the AP on managed interfaces");