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
]));
259 if (rinfo
[NL80211_RATE_INFO_HE_RU_ALLOC
])
260 pos
+= snprintf(pos
, buflen
- (pos
- buf
),
261 " HE-RU-ALLOC %d", nla_get_u8(rinfo
[NL80211_RATE_INFO_HE_RU_ALLOC
]));
262 if (rinfo
[NL80211_RATE_INFO_320_MHZ_WIDTH
])
263 pos
+= snprintf(pos
, buflen
- (pos
- buf
), " 320MHz");
266 static char *get_chain_signal(struct nlattr
*attr_list
)
277 nla_for_each_nested(attr
, attr_list
, rem
) {
283 cur
+= snprintf(cur
, sizeof(buf
) - (cur
- buf
), "%s%d", prefix
,
284 (int8_t) nla_get_u8(attr
));
288 snprintf(cur
, sizeof(buf
) - (cur
- buf
), "] ");
293 static int print_sta_handler(struct nl_msg
*msg
, void *arg
)
295 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
296 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
297 struct nlattr
*sinfo
[NL80211_STA_INFO_MAX
+ 1];
298 char mac_addr
[20], state_name
[10], dev
[20];
299 struct nl80211_sta_flag_update
*sta_flags
;
300 static struct nla_policy stats_policy
[NL80211_STA_INFO_MAX
+ 1] = {
301 [NL80211_STA_INFO_INACTIVE_TIME
] = { .type
= NLA_U32
},
302 [NL80211_STA_INFO_RX_BYTES
] = { .type
= NLA_U32
},
303 [NL80211_STA_INFO_TX_BYTES
] = { .type
= NLA_U32
},
304 [NL80211_STA_INFO_RX_BYTES64
] = { .type
= NLA_U64
},
305 [NL80211_STA_INFO_TX_BYTES64
] = { .type
= NLA_U64
},
306 [NL80211_STA_INFO_RX_PACKETS
] = { .type
= NLA_U32
},
307 [NL80211_STA_INFO_TX_PACKETS
] = { .type
= NLA_U32
},
308 [NL80211_STA_INFO_BEACON_RX
] = { .type
= NLA_U64
},
309 [NL80211_STA_INFO_SIGNAL
] = { .type
= NLA_U8
},
310 [NL80211_STA_INFO_T_OFFSET
] = { .type
= NLA_U64
},
311 [NL80211_STA_INFO_TX_BITRATE
] = { .type
= NLA_NESTED
},
312 [NL80211_STA_INFO_RX_BITRATE
] = { .type
= NLA_NESTED
},
313 [NL80211_STA_INFO_LLID
] = { .type
= NLA_U16
},
314 [NL80211_STA_INFO_PLID
] = { .type
= NLA_U16
},
315 [NL80211_STA_INFO_PLINK_STATE
] = { .type
= NLA_U8
},
316 [NL80211_STA_INFO_TX_RETRIES
] = { .type
= NLA_U32
},
317 [NL80211_STA_INFO_TX_FAILED
] = { .type
= NLA_U32
},
318 [NL80211_STA_INFO_BEACON_LOSS
] = { .type
= NLA_U32
},
319 [NL80211_STA_INFO_RX_DROP_MISC
] = { .type
= NLA_U64
},
320 [NL80211_STA_INFO_STA_FLAGS
] =
321 { .minlen
= sizeof(struct nl80211_sta_flag_update
) },
322 [NL80211_STA_INFO_LOCAL_PM
] = { .type
= NLA_U32
},
323 [NL80211_STA_INFO_PEER_PM
] = { .type
= NLA_U32
},
324 [NL80211_STA_INFO_NONPEER_PM
] = { .type
= NLA_U32
},
325 [NL80211_STA_INFO_CHAIN_SIGNAL
] = { .type
= NLA_NESTED
},
326 [NL80211_STA_INFO_CHAIN_SIGNAL_AVG
] = { .type
= NLA_NESTED
},
327 [NL80211_STA_INFO_TID_STATS
] = { .type
= NLA_NESTED
},
328 [NL80211_STA_INFO_BSS_PARAM
] = { .type
= NLA_NESTED
},
329 [NL80211_STA_INFO_RX_DURATION
] = { .type
= NLA_U64
},
330 [NL80211_STA_INFO_TX_DURATION
] = { .type
= NLA_U64
},
331 [NL80211_STA_INFO_ACK_SIGNAL
] = {.type
= NLA_U8
},
332 [NL80211_STA_INFO_ACK_SIGNAL_AVG
] = { .type
= NLA_U8
},
333 [NL80211_STA_INFO_AIRTIME_LINK_METRIC
] = { .type
= NLA_U32
},
334 [NL80211_STA_INFO_CONNECTED_TO_AS
] = { .type
= NLA_U8
},
335 [NL80211_STA_INFO_CONNECTED_TO_GATE
] = { .type
= NLA_U8
},
339 unsigned long long now_ms
;
341 gettimeofday(&now
, NULL
);
342 now_ms
= now
.tv_sec
* 1000ULL;
343 now_ms
+= (now
.tv_usec
/ 1000);
345 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
346 genlmsg_attrlen(gnlh
, 0), NULL
);
349 * TODO: validate the interface and mac address!
350 * Otherwise, there's a race condition as soon as
351 * the kernel starts sending station notifications.
354 if (!tb
[NL80211_ATTR_STA_INFO
]) {
355 fprintf(stderr
, "sta stats missing!\n");
358 if (nla_parse_nested(sinfo
, NL80211_STA_INFO_MAX
,
359 tb
[NL80211_ATTR_STA_INFO
],
361 fprintf(stderr
, "failed to parse nested attributes!\n");
365 mac_addr_n2a(mac_addr
, nla_data(tb
[NL80211_ATTR_MAC
]));
366 if_indextoname(nla_get_u32(tb
[NL80211_ATTR_IFINDEX
]), dev
);
367 printf("Station %s (on %s)", mac_addr
, dev
);
369 if (sinfo
[NL80211_STA_INFO_INACTIVE_TIME
])
370 printf("\n\tinactive time:\t%u ms",
371 nla_get_u32(sinfo
[NL80211_STA_INFO_INACTIVE_TIME
]));
372 if (sinfo
[NL80211_STA_INFO_RX_BYTES64
])
373 printf("\n\trx bytes:\t%llu",
374 (unsigned long long)nla_get_u64(sinfo
[NL80211_STA_INFO_RX_BYTES64
]));
375 else if (sinfo
[NL80211_STA_INFO_RX_BYTES
])
376 printf("\n\trx bytes:\t%u",
377 nla_get_u32(sinfo
[NL80211_STA_INFO_RX_BYTES
]));
378 if (sinfo
[NL80211_STA_INFO_RX_PACKETS
])
379 printf("\n\trx packets:\t%u",
380 nla_get_u32(sinfo
[NL80211_STA_INFO_RX_PACKETS
]));
381 if (sinfo
[NL80211_STA_INFO_TX_BYTES64
])
382 printf("\n\ttx bytes:\t%llu",
383 (unsigned long long)nla_get_u64(sinfo
[NL80211_STA_INFO_TX_BYTES64
]));
384 else if (sinfo
[NL80211_STA_INFO_TX_BYTES
])
385 printf("\n\ttx bytes:\t%u",
386 nla_get_u32(sinfo
[NL80211_STA_INFO_TX_BYTES
]));
387 if (sinfo
[NL80211_STA_INFO_TX_PACKETS
])
388 printf("\n\ttx packets:\t%u",
389 nla_get_u32(sinfo
[NL80211_STA_INFO_TX_PACKETS
]));
390 if (sinfo
[NL80211_STA_INFO_TX_RETRIES
])
391 printf("\n\ttx retries:\t%u",
392 nla_get_u32(sinfo
[NL80211_STA_INFO_TX_RETRIES
]));
393 if (sinfo
[NL80211_STA_INFO_TX_FAILED
])
394 printf("\n\ttx failed:\t%u",
395 nla_get_u32(sinfo
[NL80211_STA_INFO_TX_FAILED
]));
396 if (sinfo
[NL80211_STA_INFO_BEACON_LOSS
])
397 printf("\n\tbeacon loss:\t%u",
398 nla_get_u32(sinfo
[NL80211_STA_INFO_BEACON_LOSS
]));
399 if (sinfo
[NL80211_STA_INFO_BEACON_RX
])
400 printf("\n\tbeacon rx:\t%llu",
401 (unsigned long long)nla_get_u64(sinfo
[NL80211_STA_INFO_BEACON_RX
]));
402 if (sinfo
[NL80211_STA_INFO_RX_DROP_MISC
])
403 printf("\n\trx drop misc:\t%llu",
404 (unsigned long long)nla_get_u64(sinfo
[NL80211_STA_INFO_RX_DROP_MISC
]));
406 chain
= get_chain_signal(sinfo
[NL80211_STA_INFO_CHAIN_SIGNAL
]);
407 if (sinfo
[NL80211_STA_INFO_SIGNAL
])
408 printf("\n\tsignal: \t%d %sdBm",
409 (int8_t)nla_get_u8(sinfo
[NL80211_STA_INFO_SIGNAL
]),
412 chain
= get_chain_signal(sinfo
[NL80211_STA_INFO_CHAIN_SIGNAL_AVG
]);
413 if (sinfo
[NL80211_STA_INFO_SIGNAL_AVG
])
414 printf("\n\tsignal avg:\t%d %sdBm",
415 (int8_t)nla_get_u8(sinfo
[NL80211_STA_INFO_SIGNAL_AVG
]),
418 if (sinfo
[NL80211_STA_INFO_BEACON_SIGNAL_AVG
])
419 printf("\n\tbeacon signal avg:\t%d dBm",
420 (int8_t)nla_get_u8(sinfo
[NL80211_STA_INFO_BEACON_SIGNAL_AVG
]));
421 if (sinfo
[NL80211_STA_INFO_T_OFFSET
])
422 printf("\n\tToffset:\t%llu us",
423 (unsigned long long)nla_get_u64(sinfo
[NL80211_STA_INFO_T_OFFSET
]));
425 if (sinfo
[NL80211_STA_INFO_TX_BITRATE
]) {
428 parse_bitrate(sinfo
[NL80211_STA_INFO_TX_BITRATE
], buf
, sizeof(buf
));
429 printf("\n\ttx bitrate:\t%s", buf
);
432 if (sinfo
[NL80211_STA_INFO_TX_DURATION
])
433 printf("\n\ttx duration:\t%lld us",
434 (unsigned long long)nla_get_u64(sinfo
[NL80211_STA_INFO_TX_DURATION
]));
436 if (sinfo
[NL80211_STA_INFO_RX_BITRATE
]) {
439 parse_bitrate(sinfo
[NL80211_STA_INFO_RX_BITRATE
], buf
, sizeof(buf
));
440 printf("\n\trx bitrate:\t%s", buf
);
443 if (sinfo
[NL80211_STA_INFO_RX_DURATION
])
444 printf("\n\trx duration:\t%lld us",
445 (unsigned long long)nla_get_u64(sinfo
[NL80211_STA_INFO_RX_DURATION
]));
447 if (sinfo
[NL80211_STA_INFO_ACK_SIGNAL
])
448 printf("\n\tlast ack signal:%d dBm",
449 (int8_t)nla_get_u8(sinfo
[NL80211_STA_INFO_ACK_SIGNAL
]));
451 if (sinfo
[NL80211_STA_INFO_ACK_SIGNAL_AVG
])
452 printf("\n\tavg ack signal:\t%d dBm",
453 (int8_t)nla_get_u8(sinfo
[NL80211_STA_INFO_ACK_SIGNAL_AVG
]));
455 if (sinfo
[NL80211_STA_INFO_AIRTIME_WEIGHT
]) {
456 printf("\n\tairtime weight: %d", nla_get_u16(sinfo
[NL80211_STA_INFO_AIRTIME_WEIGHT
]));
459 if (sinfo
[NL80211_STA_INFO_EXPECTED_THROUGHPUT
]) {
462 thr
= nla_get_u32(sinfo
[NL80211_STA_INFO_EXPECTED_THROUGHPUT
]);
463 /* convert in Mbps but scale by 1000 to save kbps units */
464 thr
= thr
* 1000 / 1024;
466 printf("\n\texpected throughput:\t%u.%uMbps",
467 thr
/ 1000, thr
% 1000);
470 if (sinfo
[NL80211_STA_INFO_LLID
])
471 printf("\n\tmesh llid:\t%d",
472 nla_get_u16(sinfo
[NL80211_STA_INFO_LLID
]));
473 if (sinfo
[NL80211_STA_INFO_PLID
])
474 printf("\n\tmesh plid:\t%d",
475 nla_get_u16(sinfo
[NL80211_STA_INFO_PLID
]));
476 if (sinfo
[NL80211_STA_INFO_PLINK_STATE
]) {
477 switch (nla_get_u8(sinfo
[NL80211_STA_INFO_PLINK_STATE
])) {
479 strcpy(state_name
, "LISTEN");
482 strcpy(state_name
, "OPN_SNT");
485 strcpy(state_name
, "OPN_RCVD");
488 strcpy(state_name
, "CNF_RCVD");
491 strcpy(state_name
, "ESTAB");
494 strcpy(state_name
, "HOLDING");
497 strcpy(state_name
, "BLOCKED");
500 strcpy(state_name
, "UNKNOWN");
503 printf("\n\tmesh plink:\t%s", state_name
);
505 if (sinfo
[NL80211_STA_INFO_AIRTIME_LINK_METRIC
])
506 printf("\n\tmesh airtime link metric: %d",
507 nla_get_u32(sinfo
[NL80211_STA_INFO_AIRTIME_LINK_METRIC
]));
508 if (sinfo
[NL80211_STA_INFO_CONNECTED_TO_GATE
])
509 printf("\n\tmesh connected to gate:\t%s",
510 nla_get_u8(sinfo
[NL80211_STA_INFO_CONNECTED_TO_GATE
]) ?
512 if (sinfo
[NL80211_STA_INFO_CONNECTED_TO_AS
])
513 printf("\n\tmesh connected to auth server:\t%s",
514 nla_get_u8(sinfo
[NL80211_STA_INFO_CONNECTED_TO_AS
]) ?
517 if (sinfo
[NL80211_STA_INFO_LOCAL_PM
]) {
518 printf("\n\tmesh local PS mode:\t");
519 print_power_mode(sinfo
[NL80211_STA_INFO_LOCAL_PM
]);
521 if (sinfo
[NL80211_STA_INFO_PEER_PM
]) {
522 printf("\n\tmesh peer PS mode:\t");
523 print_power_mode(sinfo
[NL80211_STA_INFO_PEER_PM
]);
525 if (sinfo
[NL80211_STA_INFO_NONPEER_PM
]) {
526 printf("\n\tmesh non-peer PS mode:\t");
527 print_power_mode(sinfo
[NL80211_STA_INFO_NONPEER_PM
]);
530 if (sinfo
[NL80211_STA_INFO_STA_FLAGS
]) {
531 sta_flags
= (struct nl80211_sta_flag_update
*)
532 nla_data(sinfo
[NL80211_STA_INFO_STA_FLAGS
]);
534 if (sta_flags
->mask
& BIT(NL80211_STA_FLAG_AUTHORIZED
)) {
535 printf("\n\tauthorized:\t");
536 if (sta_flags
->set
& BIT(NL80211_STA_FLAG_AUTHORIZED
))
542 if (sta_flags
->mask
& BIT(NL80211_STA_FLAG_AUTHENTICATED
)) {
543 printf("\n\tauthenticated:\t");
544 if (sta_flags
->set
& BIT(NL80211_STA_FLAG_AUTHENTICATED
))
550 if (sta_flags
->mask
& BIT(NL80211_STA_FLAG_ASSOCIATED
)) {
551 printf("\n\tassociated:\t");
552 if (sta_flags
->set
& BIT(NL80211_STA_FLAG_ASSOCIATED
))
558 if (sta_flags
->mask
& BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
)) {
559 printf("\n\tpreamble:\t");
560 if (sta_flags
->set
& BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
))
566 if (sta_flags
->mask
& BIT(NL80211_STA_FLAG_WME
)) {
567 printf("\n\tWMM/WME:\t");
568 if (sta_flags
->set
& BIT(NL80211_STA_FLAG_WME
))
574 if (sta_flags
->mask
& BIT(NL80211_STA_FLAG_MFP
)) {
575 printf("\n\tMFP:\t\t");
576 if (sta_flags
->set
& BIT(NL80211_STA_FLAG_MFP
))
582 if (sta_flags
->mask
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) {
583 printf("\n\tTDLS peer:\t");
584 if (sta_flags
->set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
591 if (sinfo
[NL80211_STA_INFO_TID_STATS
] && arg
!= NULL
&&
592 !strcmp((char *)arg
, "-v"))
593 parse_tid_stats(sinfo
[NL80211_STA_INFO_TID_STATS
]);
594 if (sinfo
[NL80211_STA_INFO_BSS_PARAM
])
595 parse_bss_param(sinfo
[NL80211_STA_INFO_BSS_PARAM
]);
596 if (sinfo
[NL80211_STA_INFO_CONNECTED_TIME
])
597 printf("\n\tconnected time:\t%u seconds",
598 nla_get_u32(sinfo
[NL80211_STA_INFO_CONNECTED_TIME
]));
599 if (sinfo
[NL80211_STA_INFO_ASSOC_AT_BOOTTIME
]) {
600 unsigned long long bt
;
601 struct timespec now_ts
;
602 unsigned long long boot_ns
;
603 unsigned long long assoc_at_ms
;
605 clock_gettime(CLOCK_BOOTTIME
, &now_ts
);
606 boot_ns
= now_ts
.tv_sec
* 1000000000ULL;
607 boot_ns
+= now_ts
.tv_nsec
;
609 bt
= (unsigned long long)nla_get_u64(sinfo
[NL80211_STA_INFO_ASSOC_AT_BOOTTIME
]);
610 printf("\n\tassociated at [boottime]:\t%llu.%.3llus",
611 bt
/1000000000, (bt
%1000000000)/1000000);
612 assoc_at_ms
= now_ms
- ((boot_ns
- bt
) / 1000000);
613 printf("\n\tassociated at:\t%llu ms", assoc_at_ms
);
616 printf("\n\tcurrent time:\t%llu ms\n", now_ms
);
620 static int handle_station_get(struct nl80211_state
*state
,
622 int argc
, char **argv
,
625 unsigned char mac_addr
[ETH_ALEN
];
630 if (mac_addr_a2n(mac_addr
, argv
[0])) {
631 fprintf(stderr
, "invalid mac address\n");
641 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
643 register_handler(print_sta_handler
, NULL
);
649 COMMAND(station
, get
, "<MAC address>",
650 NL80211_CMD_GET_STATION
, 0, CIB_NETDEV
, handle_station_get
,
651 "Get information for a specific station.");
653 static int handle_station_del(struct nl80211_state
*state
,
655 int argc
, char **argv
,
659 unsigned char mac_addr
[ETH_ALEN
];
666 if (mac_addr_a2n(mac_addr
, argv
[0])) {
667 fprintf(stderr
, "invalid mac address\n");
673 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
675 if (argc
> 1 && strcmp(argv
[0], "subtype") == 0) {
679 subtype
= strtod(argv
[0], &end
);
683 NLA_PUT_U8(msg
, NL80211_ATTR_MGMT_SUBTYPE
, subtype
);
688 if (argc
> 1 && strcmp(argv
[0], "reason-code") == 0) {
692 reason_code
= strtod(argv
[0], &end
);
696 NLA_PUT_U16(msg
, NL80211_ATTR_REASON_CODE
, reason_code
);
704 register_handler(print_sta_handler
, NULL
);
710 COMMAND(station
, del
, "<MAC address> [subtype <subtype>] [reason-code <code>]",
711 NL80211_CMD_DEL_STATION
, 0, CIB_NETDEV
, handle_station_del
,
712 "Remove the given station entry (use with caution!)\n"
713 "Example subtype values: 0xA (disassociation), 0xC (deauthentication)");
715 static const struct cmd
*station_set_plink
;
716 static const struct cmd
*station_set_vlan
;
717 static const struct cmd
*station_set_mesh_power_mode
;
718 static const struct cmd
*station_set_airtime_weight
;
719 static const struct cmd
*station_set_txpwr
;
721 static const struct cmd
*select_station_cmd(int argc
, char **argv
)
725 if (strcmp(argv
[1], "plink_action") == 0)
726 return station_set_plink
;
727 if (strcmp(argv
[1], "vlan") == 0)
728 return station_set_vlan
;
729 if (strcmp(argv
[1], "mesh_power_mode") == 0)
730 return station_set_mesh_power_mode
;
731 if (strcmp(argv
[1], "airtime_weight") == 0)
732 return station_set_airtime_weight
;
733 if (strcmp(argv
[1], "txpwr") == 0)
734 return station_set_txpwr
;
738 static int handle_station_set_plink(struct nl80211_state
*state
,
740 int argc
, char **argv
,
743 unsigned char plink_action
;
744 unsigned char mac_addr
[ETH_ALEN
];
749 if (mac_addr_a2n(mac_addr
, argv
[0])) {
750 fprintf(stderr
, "invalid mac address\n");
756 if (strcmp("plink_action", argv
[0]) != 0)
761 if (strcmp("open", argv
[0]) == 0)
762 plink_action
= NL80211_PLINK_ACTION_OPEN
;
763 else if (strcmp("block", argv
[0]) == 0)
764 plink_action
= NL80211_PLINK_ACTION_BLOCK
;
766 fprintf(stderr
, "plink action not supported\n");
775 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
776 NLA_PUT_U8(msg
, NL80211_ATTR_STA_PLINK_ACTION
, plink_action
);
782 COMMAND_ALIAS(station
, set
, "<MAC address> plink_action <open|block>",
783 NL80211_CMD_SET_STATION
, 0, CIB_NETDEV
, handle_station_set_plink
,
784 "Set mesh peer link action for this station (peer).",
785 select_station_cmd
, station_set_plink
);
787 static int handle_station_set_vlan(struct nl80211_state
*state
,
789 int argc
, char **argv
,
792 unsigned char mac_addr
[ETH_ALEN
];
793 unsigned long sta_vlan
= 0;
799 if (mac_addr_a2n(mac_addr
, argv
[0])) {
800 fprintf(stderr
, "invalid mac address\n");
806 if (strcmp("vlan", argv
[0]) != 0)
811 sta_vlan
= strtoul(argv
[0], &err
, 0);
813 fprintf(stderr
, "invalid vlan id\n");
822 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
823 NLA_PUT_U32(msg
, NL80211_ATTR_STA_VLAN
, sta_vlan
);
829 COMMAND_ALIAS(station
, set
, "<MAC address> vlan <ifindex>",
830 NL80211_CMD_SET_STATION
, 0, CIB_NETDEV
, handle_station_set_vlan
,
831 "Set an AP VLAN for this station.",
832 select_station_cmd
, station_set_vlan
);
834 static int handle_station_set_mesh_power_mode(struct nl80211_state
*state
,
836 int argc
, char **argv
,
839 unsigned char mesh_power_mode
;
840 unsigned char mac_addr
[ETH_ALEN
];
845 if (mac_addr_a2n(mac_addr
, argv
[0])) {
846 fprintf(stderr
, "invalid mac address\n");
852 if (strcmp("mesh_power_mode", argv
[0]) != 0)
857 if (strcmp("active", argv
[0]) == 0)
858 mesh_power_mode
= NL80211_MESH_POWER_ACTIVE
;
859 else if (strcmp("light", argv
[0]) == 0)
860 mesh_power_mode
= NL80211_MESH_POWER_LIGHT_SLEEP
;
861 else if (strcmp("deep", argv
[0]) == 0)
862 mesh_power_mode
= NL80211_MESH_POWER_DEEP_SLEEP
;
864 fprintf(stderr
, "unknown mesh power mode\n");
873 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
874 NLA_PUT_U32(msg
, NL80211_ATTR_LOCAL_MESH_POWER_MODE
, mesh_power_mode
);
880 COMMAND_ALIAS(station
, set
, "<MAC address> mesh_power_mode "
881 "<active|light|deep>", NL80211_CMD_SET_STATION
, 0, CIB_NETDEV
,
882 handle_station_set_mesh_power_mode
,
883 "Set link-specific mesh power mode for this station",
884 select_station_cmd
, station_set_mesh_power_mode
);
886 static int handle_station_set_airtime_weight(struct nl80211_state
*state
,
888 int argc
, char **argv
,
891 unsigned char mac_addr
[ETH_ALEN
];
892 unsigned long airtime_weight
= 0;
898 if (mac_addr_a2n(mac_addr
, argv
[0])) {
899 fprintf(stderr
, "invalid mac address\n");
905 if (strcmp("airtime_weight", argv
[0]) != 0)
910 airtime_weight
= strtoul(argv
[0], &err
, 0);
912 fprintf(stderr
, "invalid airtime weight\n");
921 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
922 NLA_PUT_U16(msg
, NL80211_ATTR_AIRTIME_WEIGHT
, airtime_weight
);
929 COMMAND_ALIAS(station
, set
, "<MAC address> airtime_weight <weight>",
930 NL80211_CMD_SET_STATION
, 0, CIB_NETDEV
, handle_station_set_airtime_weight
,
931 "Set airtime weight for this station.",
932 select_station_cmd
, station_set_airtime_weight
);
934 static int handle_station_set_txpwr(struct nl80211_state
*state
,
936 int argc
, char **argv
,
939 enum nl80211_tx_power_setting type
;
940 unsigned char mac_addr
[ETH_ALEN
];
944 if (argc
!= 3 && argc
!= 4)
947 if (mac_addr_a2n(mac_addr
, argv
[0])) {
948 fprintf(stderr
, "invalid mac address\n");
952 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
956 if (strcmp("txpwr", argv
[0]) != 0)
961 if (!strcmp(argv
[0], "auto"))
962 type
= NL80211_TX_POWER_AUTOMATIC
;
963 else if (!strcmp(argv
[0], "limit"))
964 type
= NL80211_TX_POWER_LIMITED
;
966 printf("Invalid parameter: %s\n", argv
[0]);
970 NLA_PUT_U8(msg
, NL80211_ATTR_STA_TX_POWER_SETTING
, type
);
972 if (type
!= NL80211_TX_POWER_AUTOMATIC
) {
974 printf("Missing TX power level argument.\n");
981 sta_txpwr
= strtoul(argv
[0], &err
, 0);
982 NLA_PUT_U16(msg
, NL80211_ATTR_STA_TX_POWER
, sta_txpwr
);
995 COMMAND_ALIAS(station
, set
, "<MAC address> txpwr <auto|limit> [<tx power dBm>]",
996 NL80211_CMD_SET_STATION
, 0, CIB_NETDEV
, handle_station_set_txpwr
,
997 "Set Tx power for this station.",
998 select_station_cmd
, station_set_txpwr
);
1000 static int handle_station_dump(struct nl80211_state
*state
,
1002 int argc
, char **argv
,
1005 register_handler(print_sta_handler
, *argv
);
1008 COMMAND(station
, dump
, "[-v]",
1009 NL80211_CMD_GET_STATION
, NLM_F_DUMP
, CIB_NETDEV
, handle_station_dump
,
1010 "List all stations known, e.g. the AP on managed interfaces");