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_SHORT_GI
])
243 pos
+= snprintf(pos
, buflen
- (pos
- buf
), " short GI");
244 if (rinfo
[NL80211_RATE_INFO_VHT_NSS
])
245 pos
+= snprintf(pos
, buflen
- (pos
- buf
),
246 " VHT-NSS %d", nla_get_u8(rinfo
[NL80211_RATE_INFO_VHT_NSS
]));
247 if (rinfo
[NL80211_RATE_INFO_HE_MCS
])
248 pos
+= snprintf(pos
, buflen
- (pos
- buf
),
249 " HE-MCS %d", nla_get_u8(rinfo
[NL80211_RATE_INFO_HE_MCS
]));
250 if (rinfo
[NL80211_RATE_INFO_HE_NSS
])
251 pos
+= snprintf(pos
, buflen
- (pos
- buf
),
252 " HE-NSS %d", nla_get_u8(rinfo
[NL80211_RATE_INFO_HE_NSS
]));
253 if (rinfo
[NL80211_RATE_INFO_HE_GI
])
254 pos
+= snprintf(pos
, buflen
- (pos
- buf
),
255 " HE-GI %d", nla_get_u8(rinfo
[NL80211_RATE_INFO_HE_GI
]));
256 if (rinfo
[NL80211_RATE_INFO_HE_DCM
])
257 pos
+= snprintf(pos
, buflen
- (pos
- buf
),
258 " HE-DCM %d", nla_get_u8(rinfo
[NL80211_RATE_INFO_HE_DCM
]));
261 static char *get_chain_signal(struct nlattr
*attr_list
)
272 nla_for_each_nested(attr
, attr_list
, rem
) {
278 cur
+= snprintf(cur
, sizeof(buf
) - (cur
- buf
), "%s%d", prefix
,
279 (int8_t) nla_get_u8(attr
));
283 snprintf(cur
, sizeof(buf
) - (cur
- buf
), "] ");
288 static int print_sta_handler(struct nl_msg
*msg
, void *arg
)
290 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
291 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
292 struct nlattr
*sinfo
[NL80211_STA_INFO_MAX
+ 1];
293 char mac_addr
[20], state_name
[10], dev
[20];
294 struct nl80211_sta_flag_update
*sta_flags
;
295 static struct nla_policy stats_policy
[NL80211_STA_INFO_MAX
+ 1] = {
296 [NL80211_STA_INFO_INACTIVE_TIME
] = { .type
= NLA_U32
},
297 [NL80211_STA_INFO_RX_BYTES
] = { .type
= NLA_U32
},
298 [NL80211_STA_INFO_TX_BYTES
] = { .type
= NLA_U32
},
299 [NL80211_STA_INFO_RX_BYTES64
] = { .type
= NLA_U64
},
300 [NL80211_STA_INFO_TX_BYTES64
] = { .type
= NLA_U64
},
301 [NL80211_STA_INFO_RX_PACKETS
] = { .type
= NLA_U32
},
302 [NL80211_STA_INFO_TX_PACKETS
] = { .type
= NLA_U32
},
303 [NL80211_STA_INFO_BEACON_RX
] = { .type
= NLA_U64
},
304 [NL80211_STA_INFO_SIGNAL
] = { .type
= NLA_U8
},
305 [NL80211_STA_INFO_T_OFFSET
] = { .type
= NLA_U64
},
306 [NL80211_STA_INFO_TX_BITRATE
] = { .type
= NLA_NESTED
},
307 [NL80211_STA_INFO_RX_BITRATE
] = { .type
= NLA_NESTED
},
308 [NL80211_STA_INFO_LLID
] = { .type
= NLA_U16
},
309 [NL80211_STA_INFO_PLID
] = { .type
= NLA_U16
},
310 [NL80211_STA_INFO_PLINK_STATE
] = { .type
= NLA_U8
},
311 [NL80211_STA_INFO_TX_RETRIES
] = { .type
= NLA_U32
},
312 [NL80211_STA_INFO_TX_FAILED
] = { .type
= NLA_U32
},
313 [NL80211_STA_INFO_BEACON_LOSS
] = { .type
= NLA_U32
},
314 [NL80211_STA_INFO_RX_DROP_MISC
] = { .type
= NLA_U64
},
315 [NL80211_STA_INFO_STA_FLAGS
] =
316 { .minlen
= sizeof(struct nl80211_sta_flag_update
) },
317 [NL80211_STA_INFO_LOCAL_PM
] = { .type
= NLA_U32
},
318 [NL80211_STA_INFO_PEER_PM
] = { .type
= NLA_U32
},
319 [NL80211_STA_INFO_NONPEER_PM
] = { .type
= NLA_U32
},
320 [NL80211_STA_INFO_CHAIN_SIGNAL
] = { .type
= NLA_NESTED
},
321 [NL80211_STA_INFO_CHAIN_SIGNAL_AVG
] = { .type
= NLA_NESTED
},
322 [NL80211_STA_INFO_TID_STATS
] = { .type
= NLA_NESTED
},
323 [NL80211_STA_INFO_BSS_PARAM
] = { .type
= NLA_NESTED
},
324 [NL80211_STA_INFO_RX_DURATION
] = { .type
= NLA_U64
},
325 [NL80211_STA_INFO_TX_DURATION
] = { .type
= NLA_U64
},
326 [NL80211_STA_INFO_ACK_SIGNAL
] = {.type
= NLA_U8
},
327 [NL80211_STA_INFO_ACK_SIGNAL_AVG
] = { .type
= NLA_U8
},
331 unsigned long long now_ms
;
333 gettimeofday(&now
, NULL
);
334 now_ms
= now
.tv_sec
* 1000;
335 now_ms
+= (now
.tv_usec
/ 1000);
337 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
338 genlmsg_attrlen(gnlh
, 0), NULL
);
341 * TODO: validate the interface and mac address!
342 * Otherwise, there's a race condition as soon as
343 * the kernel starts sending station notifications.
346 if (!tb
[NL80211_ATTR_STA_INFO
]) {
347 fprintf(stderr
, "sta stats missing!\n");
350 if (nla_parse_nested(sinfo
, NL80211_STA_INFO_MAX
,
351 tb
[NL80211_ATTR_STA_INFO
],
353 fprintf(stderr
, "failed to parse nested attributes!\n");
357 mac_addr_n2a(mac_addr
, nla_data(tb
[NL80211_ATTR_MAC
]));
358 if_indextoname(nla_get_u32(tb
[NL80211_ATTR_IFINDEX
]), dev
);
359 printf("Station %s (on %s)", mac_addr
, dev
);
361 if (sinfo
[NL80211_STA_INFO_INACTIVE_TIME
])
362 printf("\n\tinactive time:\t%u ms",
363 nla_get_u32(sinfo
[NL80211_STA_INFO_INACTIVE_TIME
]));
364 if (sinfo
[NL80211_STA_INFO_RX_BYTES64
])
365 printf("\n\trx bytes:\t%llu",
366 (unsigned long long)nla_get_u64(sinfo
[NL80211_STA_INFO_RX_BYTES64
]));
367 else if (sinfo
[NL80211_STA_INFO_RX_BYTES
])
368 printf("\n\trx bytes:\t%u",
369 nla_get_u32(sinfo
[NL80211_STA_INFO_RX_BYTES
]));
370 if (sinfo
[NL80211_STA_INFO_RX_PACKETS
])
371 printf("\n\trx packets:\t%u",
372 nla_get_u32(sinfo
[NL80211_STA_INFO_RX_PACKETS
]));
373 if (sinfo
[NL80211_STA_INFO_TX_BYTES64
])
374 printf("\n\ttx bytes:\t%llu",
375 (unsigned long long)nla_get_u64(sinfo
[NL80211_STA_INFO_TX_BYTES64
]));
376 else if (sinfo
[NL80211_STA_INFO_TX_BYTES
])
377 printf("\n\ttx bytes:\t%u",
378 nla_get_u32(sinfo
[NL80211_STA_INFO_TX_BYTES
]));
379 if (sinfo
[NL80211_STA_INFO_TX_PACKETS
])
380 printf("\n\ttx packets:\t%u",
381 nla_get_u32(sinfo
[NL80211_STA_INFO_TX_PACKETS
]));
382 if (sinfo
[NL80211_STA_INFO_TX_RETRIES
])
383 printf("\n\ttx retries:\t%u",
384 nla_get_u32(sinfo
[NL80211_STA_INFO_TX_RETRIES
]));
385 if (sinfo
[NL80211_STA_INFO_TX_FAILED
])
386 printf("\n\ttx failed:\t%u",
387 nla_get_u32(sinfo
[NL80211_STA_INFO_TX_FAILED
]));
388 if (sinfo
[NL80211_STA_INFO_BEACON_LOSS
])
389 printf("\n\tbeacon loss:\t%u",
390 nla_get_u32(sinfo
[NL80211_STA_INFO_BEACON_LOSS
]));
391 if (sinfo
[NL80211_STA_INFO_BEACON_RX
])
392 printf("\n\tbeacon rx:\t%llu",
393 (unsigned long long)nla_get_u64(sinfo
[NL80211_STA_INFO_BEACON_RX
]));
394 if (sinfo
[NL80211_STA_INFO_RX_DROP_MISC
])
395 printf("\n\trx drop misc:\t%llu",
396 (unsigned long long)nla_get_u64(sinfo
[NL80211_STA_INFO_RX_DROP_MISC
]));
398 chain
= get_chain_signal(sinfo
[NL80211_STA_INFO_CHAIN_SIGNAL
]);
399 if (sinfo
[NL80211_STA_INFO_SIGNAL
])
400 printf("\n\tsignal: \t%d %sdBm",
401 (int8_t)nla_get_u8(sinfo
[NL80211_STA_INFO_SIGNAL
]),
404 chain
= get_chain_signal(sinfo
[NL80211_STA_INFO_CHAIN_SIGNAL_AVG
]);
405 if (sinfo
[NL80211_STA_INFO_SIGNAL_AVG
])
406 printf("\n\tsignal avg:\t%d %sdBm",
407 (int8_t)nla_get_u8(sinfo
[NL80211_STA_INFO_SIGNAL_AVG
]),
410 if (sinfo
[NL80211_STA_INFO_BEACON_SIGNAL_AVG
])
411 printf("\n\tbeacon signal avg:\t%d dBm",
412 (int8_t)nla_get_u8(sinfo
[NL80211_STA_INFO_BEACON_SIGNAL_AVG
]));
413 if (sinfo
[NL80211_STA_INFO_T_OFFSET
])
414 printf("\n\tToffset:\t%llu us",
415 (unsigned long long)nla_get_u64(sinfo
[NL80211_STA_INFO_T_OFFSET
]));
417 if (sinfo
[NL80211_STA_INFO_TX_BITRATE
]) {
420 parse_bitrate(sinfo
[NL80211_STA_INFO_TX_BITRATE
], buf
, sizeof(buf
));
421 printf("\n\ttx bitrate:\t%s", buf
);
424 if (sinfo
[NL80211_STA_INFO_TX_DURATION
])
425 printf("\n\ttx duration:\t%lld us",
426 (unsigned long long)nla_get_u64(sinfo
[NL80211_STA_INFO_TX_DURATION
]));
428 if (sinfo
[NL80211_STA_INFO_RX_BITRATE
]) {
431 parse_bitrate(sinfo
[NL80211_STA_INFO_RX_BITRATE
], buf
, sizeof(buf
));
432 printf("\n\trx bitrate:\t%s", buf
);
435 if (sinfo
[NL80211_STA_INFO_RX_DURATION
])
436 printf("\n\trx duration:\t%lld us",
437 (unsigned long long)nla_get_u64(sinfo
[NL80211_STA_INFO_RX_DURATION
]));
439 if (sinfo
[NL80211_STA_INFO_ACK_SIGNAL
])
440 printf("\n\tlast ack signal:%d dBm",
441 (int8_t)nla_get_u8(sinfo
[NL80211_STA_INFO_ACK_SIGNAL
]));
443 if (sinfo
[NL80211_STA_INFO_ACK_SIGNAL_AVG
])
444 printf("\n\tavg ack signal:\t%d dBm",
445 (int8_t)nla_get_u8(sinfo
[NL80211_STA_INFO_ACK_SIGNAL_AVG
]));
447 if (sinfo
[NL80211_STA_INFO_AIRTIME_WEIGHT
]) {
448 printf("\n\tairtime weight: %d", nla_get_u16(sinfo
[NL80211_STA_INFO_AIRTIME_WEIGHT
]));
451 if (sinfo
[NL80211_STA_INFO_EXPECTED_THROUGHPUT
]) {
454 thr
= nla_get_u32(sinfo
[NL80211_STA_INFO_EXPECTED_THROUGHPUT
]);
455 /* convert in Mbps but scale by 1000 to save kbps units */
456 thr
= thr
* 1000 / 1024;
458 printf("\n\texpected throughput:\t%u.%uMbps",
459 thr
/ 1000, thr
% 1000);
462 if (sinfo
[NL80211_STA_INFO_LLID
])
463 printf("\n\tmesh llid:\t%d",
464 nla_get_u16(sinfo
[NL80211_STA_INFO_LLID
]));
465 if (sinfo
[NL80211_STA_INFO_PLID
])
466 printf("\n\tmesh plid:\t%d",
467 nla_get_u16(sinfo
[NL80211_STA_INFO_PLID
]));
468 if (sinfo
[NL80211_STA_INFO_PLINK_STATE
]) {
469 switch (nla_get_u8(sinfo
[NL80211_STA_INFO_PLINK_STATE
])) {
471 strcpy(state_name
, "LISTEN");
474 strcpy(state_name
, "OPN_SNT");
477 strcpy(state_name
, "OPN_RCVD");
480 strcpy(state_name
, "CNF_RCVD");
483 strcpy(state_name
, "ESTAB");
486 strcpy(state_name
, "HOLDING");
489 strcpy(state_name
, "BLOCKED");
492 strcpy(state_name
, "UNKNOWN");
495 printf("\n\tmesh plink:\t%s", state_name
);
497 if (sinfo
[NL80211_STA_INFO_LOCAL_PM
]) {
498 printf("\n\tmesh local PS mode:\t");
499 print_power_mode(sinfo
[NL80211_STA_INFO_LOCAL_PM
]);
501 if (sinfo
[NL80211_STA_INFO_PEER_PM
]) {
502 printf("\n\tmesh peer PS mode:\t");
503 print_power_mode(sinfo
[NL80211_STA_INFO_PEER_PM
]);
505 if (sinfo
[NL80211_STA_INFO_NONPEER_PM
]) {
506 printf("\n\tmesh non-peer PS mode:\t");
507 print_power_mode(sinfo
[NL80211_STA_INFO_NONPEER_PM
]);
510 if (sinfo
[NL80211_STA_INFO_STA_FLAGS
]) {
511 sta_flags
= (struct nl80211_sta_flag_update
*)
512 nla_data(sinfo
[NL80211_STA_INFO_STA_FLAGS
]);
514 if (sta_flags
->mask
& BIT(NL80211_STA_FLAG_AUTHORIZED
)) {
515 printf("\n\tauthorized:\t");
516 if (sta_flags
->set
& BIT(NL80211_STA_FLAG_AUTHORIZED
))
522 if (sta_flags
->mask
& BIT(NL80211_STA_FLAG_AUTHENTICATED
)) {
523 printf("\n\tauthenticated:\t");
524 if (sta_flags
->set
& BIT(NL80211_STA_FLAG_AUTHENTICATED
))
530 if (sta_flags
->mask
& BIT(NL80211_STA_FLAG_ASSOCIATED
)) {
531 printf("\n\tassociated:\t");
532 if (sta_flags
->set
& BIT(NL80211_STA_FLAG_ASSOCIATED
))
538 if (sta_flags
->mask
& BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
)) {
539 printf("\n\tpreamble:\t");
540 if (sta_flags
->set
& BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
))
546 if (sta_flags
->mask
& BIT(NL80211_STA_FLAG_WME
)) {
547 printf("\n\tWMM/WME:\t");
548 if (sta_flags
->set
& BIT(NL80211_STA_FLAG_WME
))
554 if (sta_flags
->mask
& BIT(NL80211_STA_FLAG_MFP
)) {
555 printf("\n\tMFP:\t\t");
556 if (sta_flags
->set
& BIT(NL80211_STA_FLAG_MFP
))
562 if (sta_flags
->mask
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) {
563 printf("\n\tTDLS peer:\t");
564 if (sta_flags
->set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
571 if (sinfo
[NL80211_STA_INFO_TID_STATS
] && arg
!= NULL
&&
572 !strcmp((char *)arg
, "-v"))
573 parse_tid_stats(sinfo
[NL80211_STA_INFO_TID_STATS
]);
574 if (sinfo
[NL80211_STA_INFO_BSS_PARAM
])
575 parse_bss_param(sinfo
[NL80211_STA_INFO_BSS_PARAM
]);
576 if (sinfo
[NL80211_STA_INFO_CONNECTED_TIME
])
577 printf("\n\tconnected time:\t%u seconds",
578 nla_get_u32(sinfo
[NL80211_STA_INFO_CONNECTED_TIME
]));
579 if (sinfo
[NL80211_STA_INFO_ASSOC_AT_BOOTTIME
]) {
580 unsigned long long bt
;
581 struct timespec now_ts
;
582 unsigned long long boot_ns
;
583 unsigned long long assoc_at_ms
;
585 clock_gettime(CLOCK_BOOTTIME
, &now_ts
);
586 boot_ns
= now_ts
.tv_sec
* 1000000000;
587 boot_ns
+= now_ts
.tv_nsec
;
589 bt
= (unsigned long long)nla_get_u64(sinfo
[NL80211_STA_INFO_ASSOC_AT_BOOTTIME
]);
590 printf("\n\tassociated at [boottime]:\t%llu.%.3llus",
591 bt
/1000000000, (bt
%1000000000)/1000000);
592 assoc_at_ms
= now_ms
- ((boot_ns
- bt
) / 1000000);
593 printf("\n\tassociated at:\t%llu ms", assoc_at_ms
);
596 printf("\n\tcurrent time:\t%llu ms\n", now_ms
);
600 static int handle_station_get(struct nl80211_state
*state
,
602 int argc
, char **argv
,
605 unsigned char mac_addr
[ETH_ALEN
];
610 if (mac_addr_a2n(mac_addr
, argv
[0])) {
611 fprintf(stderr
, "invalid mac address\n");
621 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
623 register_handler(print_sta_handler
, NULL
);
629 COMMAND(station
, get
, "<MAC address>",
630 NL80211_CMD_GET_STATION
, 0, CIB_NETDEV
, handle_station_get
,
631 "Get information for a specific station.");
633 static int handle_station_del(struct nl80211_state
*state
,
635 int argc
, char **argv
,
639 unsigned char mac_addr
[ETH_ALEN
];
646 if (mac_addr_a2n(mac_addr
, argv
[0])) {
647 fprintf(stderr
, "invalid mac address\n");
653 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
655 if (argc
> 1 && strcmp(argv
[0], "subtype") == 0) {
659 subtype
= strtod(argv
[0], &end
);
663 NLA_PUT_U8(msg
, NL80211_ATTR_MGMT_SUBTYPE
, subtype
);
668 if (argc
> 1 && strcmp(argv
[0], "reason-code") == 0) {
672 reason_code
= strtod(argv
[0], &end
);
676 NLA_PUT_U16(msg
, NL80211_ATTR_REASON_CODE
, reason_code
);
684 register_handler(print_sta_handler
, NULL
);
690 COMMAND(station
, del
, "<MAC address> [subtype <subtype>] [reason-code <code>]",
691 NL80211_CMD_DEL_STATION
, 0, CIB_NETDEV
, handle_station_del
,
692 "Remove the given station entry (use with caution!)\n"
693 "Example subtype values: 0xA (disassociation), 0xC (deauthentication)");
695 static const struct cmd
*station_set_plink
;
696 static const struct cmd
*station_set_vlan
;
697 static const struct cmd
*station_set_mesh_power_mode
;
698 static const struct cmd
*station_set_airtime_weight
;
699 static const struct cmd
*station_set_txpwr
;
701 static const struct cmd
*select_station_cmd(int argc
, char **argv
)
705 if (strcmp(argv
[1], "plink_action") == 0)
706 return station_set_plink
;
707 if (strcmp(argv
[1], "vlan") == 0)
708 return station_set_vlan
;
709 if (strcmp(argv
[1], "mesh_power_mode") == 0)
710 return station_set_mesh_power_mode
;
711 if (strcmp(argv
[1], "airtime_weight") == 0)
712 return station_set_airtime_weight
;
713 if (strcmp(argv
[1], "txpwr") == 0)
714 return station_set_txpwr
;
718 static int handle_station_set_plink(struct nl80211_state
*state
,
720 int argc
, char **argv
,
723 unsigned char plink_action
;
724 unsigned char mac_addr
[ETH_ALEN
];
729 if (mac_addr_a2n(mac_addr
, argv
[0])) {
730 fprintf(stderr
, "invalid mac address\n");
736 if (strcmp("plink_action", argv
[0]) != 0)
741 if (strcmp("open", argv
[0]) == 0)
742 plink_action
= NL80211_PLINK_ACTION_OPEN
;
743 else if (strcmp("block", argv
[0]) == 0)
744 plink_action
= NL80211_PLINK_ACTION_BLOCK
;
746 fprintf(stderr
, "plink action not supported\n");
755 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
756 NLA_PUT_U8(msg
, NL80211_ATTR_STA_PLINK_ACTION
, plink_action
);
762 COMMAND_ALIAS(station
, set
, "<MAC address> plink_action <open|block>",
763 NL80211_CMD_SET_STATION
, 0, CIB_NETDEV
, handle_station_set_plink
,
764 "Set mesh peer link action for this station (peer).",
765 select_station_cmd
, station_set_plink
);
767 static int handle_station_set_vlan(struct nl80211_state
*state
,
769 int argc
, char **argv
,
772 unsigned char mac_addr
[ETH_ALEN
];
773 unsigned long sta_vlan
= 0;
779 if (mac_addr_a2n(mac_addr
, argv
[0])) {
780 fprintf(stderr
, "invalid mac address\n");
786 if (strcmp("vlan", argv
[0]) != 0)
791 sta_vlan
= strtoul(argv
[0], &err
, 0);
793 fprintf(stderr
, "invalid vlan id\n");
802 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
803 NLA_PUT_U32(msg
, NL80211_ATTR_STA_VLAN
, sta_vlan
);
809 COMMAND_ALIAS(station
, set
, "<MAC address> vlan <ifindex>",
810 NL80211_CMD_SET_STATION
, 0, CIB_NETDEV
, handle_station_set_vlan
,
811 "Set an AP VLAN for this station.",
812 select_station_cmd
, station_set_vlan
);
814 static int handle_station_set_mesh_power_mode(struct nl80211_state
*state
,
816 int argc
, char **argv
,
819 unsigned char mesh_power_mode
;
820 unsigned char mac_addr
[ETH_ALEN
];
825 if (mac_addr_a2n(mac_addr
, argv
[0])) {
826 fprintf(stderr
, "invalid mac address\n");
832 if (strcmp("mesh_power_mode", argv
[0]) != 0)
837 if (strcmp("active", argv
[0]) == 0)
838 mesh_power_mode
= NL80211_MESH_POWER_ACTIVE
;
839 else if (strcmp("light", argv
[0]) == 0)
840 mesh_power_mode
= NL80211_MESH_POWER_LIGHT_SLEEP
;
841 else if (strcmp("deep", argv
[0]) == 0)
842 mesh_power_mode
= NL80211_MESH_POWER_DEEP_SLEEP
;
844 fprintf(stderr
, "unknown mesh power mode\n");
853 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
854 NLA_PUT_U32(msg
, NL80211_ATTR_LOCAL_MESH_POWER_MODE
, mesh_power_mode
);
860 COMMAND_ALIAS(station
, set
, "<MAC address> mesh_power_mode "
861 "<active|light|deep>", NL80211_CMD_SET_STATION
, 0, CIB_NETDEV
,
862 handle_station_set_mesh_power_mode
,
863 "Set link-specific mesh power mode for this station",
864 select_station_cmd
, station_set_mesh_power_mode
);
866 static int handle_station_set_airtime_weight(struct nl80211_state
*state
,
868 int argc
, char **argv
,
871 unsigned char mac_addr
[ETH_ALEN
];
872 unsigned long airtime_weight
= 0;
878 if (mac_addr_a2n(mac_addr
, argv
[0])) {
879 fprintf(stderr
, "invalid mac address\n");
885 if (strcmp("airtime_weight", argv
[0]) != 0)
890 airtime_weight
= strtoul(argv
[0], &err
, 0);
892 fprintf(stderr
, "invalid airtime weight\n");
901 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
902 NLA_PUT_U16(msg
, NL80211_ATTR_AIRTIME_WEIGHT
, airtime_weight
);
909 COMMAND_ALIAS(station
, set
, "<MAC address> airtime_weight <weight>",
910 NL80211_CMD_SET_STATION
, 0, CIB_NETDEV
, handle_station_set_airtime_weight
,
911 "Set airtime weight for this station.",
912 select_station_cmd
, station_set_airtime_weight
);
914 static int handle_station_set_txpwr(struct nl80211_state
*state
,
916 int argc
, char **argv
,
919 enum nl80211_tx_power_setting type
;
920 unsigned char mac_addr
[ETH_ALEN
];
924 if (argc
!= 3 && argc
!= 4)
927 if (mac_addr_a2n(mac_addr
, argv
[0])) {
928 fprintf(stderr
, "invalid mac address\n");
932 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
936 if (strcmp("txpwr", argv
[0]) != 0)
941 if (!strcmp(argv
[0], "auto"))
942 type
= NL80211_TX_POWER_AUTOMATIC
;
943 else if (!strcmp(argv
[0], "limit"))
944 type
= NL80211_TX_POWER_LIMITED
;
946 printf("Invalid parameter: %s\n", argv
[0]);
950 NLA_PUT_U8(msg
, NL80211_ATTR_STA_TX_POWER_SETTING
, type
);
952 if (type
!= NL80211_TX_POWER_AUTOMATIC
) {
954 printf("Missing TX power level argument.\n");
961 sta_txpwr
= strtoul(argv
[0], &err
, 0);
962 NLA_PUT_U16(msg
, NL80211_ATTR_STA_TX_POWER
, sta_txpwr
);
975 COMMAND_ALIAS(station
, set
, "<MAC address> txpwr <auto|limit> [<tx power dBm>]",
976 NL80211_CMD_SET_STATION
, 0, CIB_NETDEV
, handle_station_set_txpwr
,
977 "Set Tx power for this station.",
978 select_station_cmd
, station_set_txpwr
);
980 static int handle_station_dump(struct nl80211_state
*state
,
982 int argc
, char **argv
,
985 register_handler(print_sta_handler
, *argv
);
988 COMMAND(station
, dump
, "[-v]",
989 NL80211_CMD_GET_STATION
, NLM_F_DUMP
, CIB_NETDEV
, handle_station_dump
,
990 "List all stations known, e.g. the AP on managed interfaces");