]>
Commit | Line | Data |
---|---|---|
2ef1be68 | 1 | #include <net/if.h> |
3d1e8704 | 2 | #include <errno.h> |
d5ac8ad3 | 3 | #include <string.h> |
2ef1be68 | 4 | |
3d1e8704 LCC |
5 | #include <netlink/genl/genl.h> |
6 | #include <netlink/genl/family.h> | |
7 | #include <netlink/genl/ctrl.h> | |
8 | #include <netlink/msg.h> | |
9 | #include <netlink/attr.h> | |
3708f614 | 10 | #include <time.h> |
3d1e8704 | 11 | |
f408e01b | 12 | #include "nl80211.h" |
3d1e8704 LCC |
13 | #include "iw.h" |
14 | ||
4698bfc2 JB |
15 | SECTION(station); |
16 | ||
3d1e8704 LCC |
17 | enum plink_state { |
18 | LISTEN, | |
19 | OPN_SNT, | |
20 | OPN_RCVD, | |
21 | CNF_RCVD, | |
22 | ESTAB, | |
23 | HOLDING, | |
24 | BLOCKED | |
25 | }; | |
26 | ||
8012ad28 MP |
27 | static void print_power_mode(struct nlattr *a) |
28 | { | |
29 | enum nl80211_mesh_power_mode pm = nla_get_u32(a); | |
30 | ||
31 | switch (pm) { | |
32 | case NL80211_MESH_POWER_ACTIVE: | |
33 | printf("ACTIVE"); | |
34 | break; | |
35 | case NL80211_MESH_POWER_LIGHT_SLEEP: | |
36 | printf("LIGHT SLEEP"); | |
37 | break; | |
38 | case NL80211_MESH_POWER_DEEP_SLEEP: | |
39 | printf("DEEP SLEEP"); | |
40 | break; | |
41 | default: | |
42 | printf("UNKNOWN"); | |
43 | break; | |
44 | } | |
45 | } | |
3d1e8704 | 46 | |
910792c0 THJ |
47 | int parse_txq_stats(char *buf, int buflen, struct nlattr *tid_stats_attr, int header, |
48 | int tid, const char *indent) | |
49 | { | |
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 }, | |
61 | }; | |
62 | char *pos = buf; | |
63 | if (nla_parse_nested(txqstats_info, NL80211_TXQ_STATS_MAX, tid_stats_attr, | |
64 | txqstats_policy)) { | |
65 | printf("failed to parse nested TXQ stats attributes!"); | |
66 | return 0; | |
67 | } | |
68 | ||
69 | if (header) | |
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" : ""); | |
74 | ||
75 | pos += snprintf(pos, buflen - (pos - buf), "\n%s\t", indent); | |
76 | if (tid >= 0) | |
77 | pos += snprintf(pos, buflen - (pos - buf), "%d", tid); | |
78 | ||
79 | #define PRINT_STAT(key, spacer) do { \ | |
80 | txqinfo = txqstats_info[NL80211_TXQ_STATS_ ## key]; \ | |
81 | pos += snprintf(pos, buflen - (pos - buf), spacer); \ | |
82 | if (txqinfo) \ | |
83 | pos += snprintf(pos, buflen - (pos - buf), "%u", \ | |
84 | nla_get_u32(txqinfo)); \ | |
85 | } while (0) | |
86 | ||
87 | ||
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"); | |
97 | ||
98 | #undef PRINT_STAT | |
99 | ||
100 | return pos - buf; | |
101 | ||
102 | } | |
bcdceae1 | 103 | |
c5bfa2a3 | 104 | static void parse_tid_stats(struct nlattr *tid_stats_attr, const char *indent) |
568c7057 AE |
105 | { |
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 }, | |
910792c0 | 112 | [NL80211_TID_STATS_TXQ_STATS] = { .type = NLA_NESTED }, |
568c7057 AE |
113 | }; |
114 | int rem, i = 0; | |
910792c0 THJ |
115 | char txqbuf[2000] = {}, *pos = txqbuf; |
116 | int buflen = sizeof(txqbuf), foundtxq = 0; | |
568c7057 | 117 | |
c5bfa2a3 | 118 | printf("%sMSDU:%sTID\trx\ttx\ttx retries\ttx failed", indent, indent); |
568c7057 AE |
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!"); | |
123 | return; | |
124 | } | |
c5bfa2a3 | 125 | printf("%s%d", indent, i); |
568c7057 AE |
126 | info = stats_info[NL80211_TID_STATS_RX_MSDU]; |
127 | if (info) | |
128 | printf("\t%llu", (unsigned long long)nla_get_u64(info)); | |
129 | info = stats_info[NL80211_TID_STATS_TX_MSDU]; | |
130 | if (info) | |
131 | printf("\t%llu", (unsigned long long)nla_get_u64(info)); | |
132 | info = stats_info[NL80211_TID_STATS_TX_MSDU_RETRIES]; | |
133 | if (info) | |
134 | printf("\t%llu", (unsigned long long)nla_get_u64(info)); | |
135 | info = stats_info[NL80211_TID_STATS_TX_MSDU_FAILED]; | |
136 | if (info) | |
137 | printf("\t\t%llu", (unsigned long long)nla_get_u64(info)); | |
910792c0 THJ |
138 | info = stats_info[NL80211_TID_STATS_TXQ_STATS]; |
139 | if (info) { | |
140 | pos += parse_txq_stats(pos, buflen - (pos - txqbuf), info, !foundtxq, i, "\t"); | |
141 | foundtxq = 1; | |
142 | } | |
143 | ||
144 | i++; | |
568c7057 | 145 | } |
910792c0 THJ |
146 | |
147 | if (foundtxq) | |
c5bfa2a3 | 148 | printf("%sTXQs:%s", indent, txqbuf); |
568c7057 AE |
149 | } |
150 | ||
c5bfa2a3 | 151 | static void parse_bss_param(struct nlattr *bss_param_attr, const char *indent) |
568c7057 AE |
152 | { |
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 }, | |
160 | }; | |
161 | ||
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!"); | |
165 | } | |
166 | ||
167 | info = bss_param_info[NL80211_STA_BSS_PARAM_DTIM_PERIOD]; | |
168 | if (info) | |
c5bfa2a3 | 169 | printf("%sDTIM period:\t%u", indent, nla_get_u8(info)); |
568c7057 AE |
170 | info = bss_param_info[NL80211_STA_BSS_PARAM_BEACON_INTERVAL]; |
171 | if (info) | |
c5bfa2a3 | 172 | printf("%sbeacon interval:%u", indent, nla_get_u16(info)); |
568c7057 AE |
173 | info = bss_param_info[NL80211_STA_BSS_PARAM_CTS_PROT]; |
174 | if (info) { | |
c5bfa2a3 | 175 | printf("%sCTS protection:", indent); |
568c7057 AE |
176 | if (nla_get_u16(info)) |
177 | printf("\tyes"); | |
178 | else | |
179 | printf("\tno"); | |
180 | } | |
181 | info = bss_param_info[NL80211_STA_BSS_PARAM_SHORT_PREAMBLE]; | |
182 | if (info) { | |
c5bfa2a3 | 183 | printf("%sshort preamble:", indent); |
568c7057 AE |
184 | if (nla_get_u16(info)) |
185 | printf("\tyes"); | |
186 | else | |
187 | printf("\tno"); | |
188 | } | |
189 | info = bss_param_info[NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME]; | |
190 | if (info) { | |
c5bfa2a3 | 191 | printf("%sshort slot time:", indent); |
568c7057 AE |
192 | if (nla_get_u16(info)) |
193 | printf("yes"); | |
194 | else | |
195 | printf("no"); | |
196 | } | |
197 | } | |
198 | ||
e94f0201 | 199 | void parse_bitrate(struct nlattr *bitrate_attr, char *buf, int buflen) |
64179590 JB |
200 | { |
201 | int rate = 0; | |
202 | char *pos = buf; | |
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 }, | |
210 | }; | |
211 | ||
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!"); | |
215 | return; | |
216 | } | |
217 | ||
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]); | |
222 | if (rate > 0) | |
223 | pos += snprintf(pos, buflen - (pos - buf), | |
224 | "%d.%d MBit/s", rate / 10, rate % 10); | |
5ce1f6c7 MH |
225 | else |
226 | pos += snprintf(pos, buflen - (pos - buf), "(unknown)"); | |
64179590 JB |
227 | |
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"); | |
e3287a1f JB |
242 | if (rinfo[NL80211_RATE_INFO_320_MHZ_WIDTH]) |
243 | pos += snprintf(pos, buflen - (pos - buf), " 320MHz"); | |
e2224c72 BD |
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"); | |
64179590 JB |
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])); | |
848d97d9 JC |
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])); | |
97dd4dad JC |
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])); | |
e3287a1f JB |
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])); | |
64179590 JB |
286 | } |
287 | ||
7d23bc2d FF |
288 | static char *get_chain_signal(struct nlattr *attr_list) |
289 | { | |
290 | struct nlattr *attr; | |
291 | static char buf[64]; | |
292 | char *cur = buf; | |
293 | int i = 0, rem; | |
294 | const char *prefix; | |
295 | ||
296 | if (!attr_list) | |
297 | return ""; | |
298 | ||
299 | nla_for_each_nested(attr, attr_list, rem) { | |
300 | if (i++ > 0) | |
301 | prefix = ", "; | |
302 | else | |
303 | prefix = "["; | |
304 | ||
305 | cur += snprintf(cur, sizeof(buf) - (cur - buf), "%s%d", prefix, | |
306 | (int8_t) nla_get_u8(attr)); | |
307 | } | |
308 | ||
309 | if (i) | |
310 | snprintf(cur, sizeof(buf) - (cur - buf), "] "); | |
311 | ||
312 | return buf; | |
313 | } | |
314 | ||
c5bfa2a3 SS |
315 | static void print_nested_sta_handler(struct nlattr *link_sinfo[NL80211_STA_INFO_MAX + 1], |
316 | void *arg, const char *indent) | |
317 | { | |
318 | char *chain; | |
319 | struct timeval now; | |
320 | unsigned long long now_ms; | |
321 | ||
322 | gettimeofday(&now, NULL); | |
323 | now_ms = now.tv_sec * 1000ULL; | |
324 | now_ms += (now.tv_usec / 1000); | |
325 | ||
326 | if (link_sinfo[NL80211_STA_INFO_INACTIVE_TIME]) | |
327 | printf("%sinactive time:\t%u ms", indent, | |
328 | nla_get_u32(link_sinfo[NL80211_STA_INFO_INACTIVE_TIME])); | |
329 | if (link_sinfo[NL80211_STA_INFO_RX_BYTES64]) | |
330 | printf("%srx bytes:\t%llu", indent, | |
331 | (unsigned long long)nla_get_u64(link_sinfo[NL80211_STA_INFO_RX_BYTES64])); | |
332 | else if (link_sinfo[NL80211_STA_INFO_RX_BYTES]) | |
333 | printf("%srx bytes:\t%u", indent, | |
334 | nla_get_u32(link_sinfo[NL80211_STA_INFO_RX_BYTES])); | |
335 | if (link_sinfo[NL80211_STA_INFO_RX_PACKETS]) | |
336 | printf("%srx packets:\t%u", indent, | |
337 | nla_get_u32(link_sinfo[NL80211_STA_INFO_RX_PACKETS])); | |
338 | if (link_sinfo[NL80211_STA_INFO_TX_BYTES64]) | |
339 | printf("%stx bytes:\t%llu", indent, | |
340 | (unsigned long long)nla_get_u64(link_sinfo[NL80211_STA_INFO_TX_BYTES64])); | |
341 | else if (link_sinfo[NL80211_STA_INFO_TX_BYTES]) | |
342 | printf("%stx bytes:\t%u", indent, | |
343 | nla_get_u32(link_sinfo[NL80211_STA_INFO_TX_BYTES])); | |
344 | if (link_sinfo[NL80211_STA_INFO_TX_PACKETS]) | |
345 | printf("%stx packets:\t%u", indent, | |
346 | nla_get_u32(link_sinfo[NL80211_STA_INFO_TX_PACKETS])); | |
347 | if (link_sinfo[NL80211_STA_INFO_TX_RETRIES]) | |
348 | printf("%stx retries:\t%u", indent, | |
349 | nla_get_u32(link_sinfo[NL80211_STA_INFO_TX_RETRIES])); | |
350 | if (link_sinfo[NL80211_STA_INFO_TX_FAILED]) | |
351 | printf("%stx failed:\t%u", indent, | |
352 | nla_get_u32(link_sinfo[NL80211_STA_INFO_TX_FAILED])); | |
353 | if (link_sinfo[NL80211_STA_INFO_BEACON_LOSS]) | |
354 | printf("%sbeacon loss:\t%u", indent, | |
355 | nla_get_u32(link_sinfo[NL80211_STA_INFO_BEACON_LOSS])); | |
356 | if (link_sinfo[NL80211_STA_INFO_BEACON_RX]) | |
357 | printf("\n\t\tbeacon rx:\t%llu", | |
358 | (unsigned long long)nla_get_u64(link_sinfo[NL80211_STA_INFO_BEACON_RX])); | |
359 | if (link_sinfo[NL80211_STA_INFO_RX_DROP_MISC]) | |
360 | printf("%srx drop misc:\t%llu", indent, | |
361 | (unsigned long long)nla_get_u64(link_sinfo[NL80211_STA_INFO_RX_DROP_MISC])); | |
362 | ||
363 | chain = get_chain_signal(link_sinfo[NL80211_STA_INFO_CHAIN_SIGNAL]); | |
364 | if (link_sinfo[NL80211_STA_INFO_SIGNAL]) | |
365 | printf("%ssignal: \t%d %sdBm", indent, | |
366 | (int8_t)nla_get_u8(link_sinfo[NL80211_STA_INFO_SIGNAL]), | |
367 | chain); | |
368 | ||
369 | chain = get_chain_signal(link_sinfo[NL80211_STA_INFO_CHAIN_SIGNAL_AVG]); | |
370 | if (link_sinfo[NL80211_STA_INFO_SIGNAL_AVG]) | |
371 | printf("%ssignal avg:\t%d %sdBm", indent, | |
372 | (int8_t)nla_get_u8(link_sinfo[NL80211_STA_INFO_SIGNAL_AVG]), | |
373 | chain); | |
374 | ||
375 | if (link_sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG]) | |
376 | printf("%sbeacon signal avg:\t%d dBm", indent, | |
377 | (int8_t)nla_get_u8(link_sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG])); | |
378 | if (link_sinfo[NL80211_STA_INFO_T_OFFSET]) | |
379 | printf("%sToffset:\t%llu us", indent, | |
380 | (unsigned long long)nla_get_u64(link_sinfo[NL80211_STA_INFO_T_OFFSET])); | |
381 | ||
382 | if (link_sinfo[NL80211_STA_INFO_TX_BITRATE]) { | |
383 | char buf[100]; | |
384 | ||
385 | parse_bitrate(link_sinfo[NL80211_STA_INFO_TX_BITRATE], buf, sizeof(buf)); | |
386 | printf("%stx bitrate:\t%s", indent, buf); | |
387 | } | |
388 | ||
389 | if (link_sinfo[NL80211_STA_INFO_TX_DURATION]) | |
390 | printf("%stx duration:\t%lld us", indent, | |
391 | (unsigned long long)nla_get_u64(link_sinfo[NL80211_STA_INFO_TX_DURATION])); | |
392 | ||
393 | if (link_sinfo[NL80211_STA_INFO_RX_BITRATE]) { | |
394 | char buf[100]; | |
395 | ||
396 | parse_bitrate(link_sinfo[NL80211_STA_INFO_RX_BITRATE], buf, sizeof(buf)); | |
397 | printf("%srx bitrate:\t%s", indent, buf); | |
398 | } | |
399 | ||
400 | if (link_sinfo[NL80211_STA_INFO_RX_DURATION]) | |
401 | printf("%srx duration:\t%lld us", indent, | |
402 | (unsigned long long)nla_get_u64(link_sinfo[NL80211_STA_INFO_RX_DURATION])); | |
403 | ||
404 | if (link_sinfo[NL80211_STA_INFO_ACK_SIGNAL]) | |
405 | printf("%slast ack signal:%d dBm", indent, | |
406 | (int8_t)nla_get_u8(link_sinfo[NL80211_STA_INFO_ACK_SIGNAL])); | |
407 | ||
408 | if (link_sinfo[NL80211_STA_INFO_ACK_SIGNAL_AVG]) | |
409 | printf("%savg ack signal:\t%d dBm", indent, | |
410 | (int8_t)nla_get_u8(link_sinfo[NL80211_STA_INFO_ACK_SIGNAL_AVG])); | |
411 | ||
412 | if (link_sinfo[NL80211_STA_INFO_AIRTIME_WEIGHT]) { | |
413 | printf("%sairtime weight: %d", indent, | |
414 | nla_get_u16(link_sinfo[NL80211_STA_INFO_AIRTIME_WEIGHT])); | |
415 | } | |
416 | ||
417 | if (link_sinfo[NL80211_STA_INFO_EXPECTED_THROUGHPUT]) { | |
418 | uint32_t thr; | |
419 | ||
420 | thr = nla_get_u32(link_sinfo[NL80211_STA_INFO_EXPECTED_THROUGHPUT]); | |
421 | /* convert in Mbps but scale by 1000 to save kbps units */ | |
422 | thr = thr * 1000 / 1024; | |
423 | ||
424 | printf("%sexpected throughput:\t%u.%uMbps", indent, | |
425 | thr / 1000, thr % 1000); | |
426 | } | |
427 | ||
428 | if (link_sinfo[NL80211_STA_INFO_TID_STATS] && arg != NULL && | |
429 | !strcmp((char *)arg, "-v")) | |
430 | parse_tid_stats(link_sinfo[NL80211_STA_INFO_TID_STATS], indent); | |
431 | if (link_sinfo[NL80211_STA_INFO_BSS_PARAM]) | |
432 | parse_bss_param(link_sinfo[NL80211_STA_INFO_BSS_PARAM], indent); | |
433 | if (link_sinfo[NL80211_STA_INFO_CONNECTED_TIME]) | |
434 | printf("%sconnected time:\t%u seconds", indent, | |
435 | nla_get_u32(link_sinfo[NL80211_STA_INFO_CONNECTED_TIME])); | |
436 | if (link_sinfo[NL80211_STA_INFO_ASSOC_AT_BOOTTIME]) { | |
437 | unsigned long long bt; | |
438 | struct timespec now_ts; | |
439 | unsigned long long boot_ns; | |
440 | unsigned long long assoc_at_ms; | |
441 | ||
442 | clock_gettime(CLOCK_BOOTTIME, &now_ts); | |
443 | boot_ns = now_ts.tv_sec * 1000000000ULL; | |
444 | boot_ns += now_ts.tv_nsec; | |
445 | ||
446 | bt = (unsigned long long)nla_get_u64(link_sinfo[NL80211_STA_INFO_ASSOC_AT_BOOTTIME]); | |
447 | printf("%sassociated at [boottime]:\t%llu.%.3llus", | |
448 | indent, bt/1000000000, (bt%1000000000)/1000000); | |
449 | assoc_at_ms = now_ms - ((boot_ns - bt) / 1000000); | |
450 | printf("%sassociated at:\t%llu ms", indent, assoc_at_ms); | |
451 | } | |
452 | } | |
453 | ||
3d1e8704 LCC |
454 | static int print_sta_handler(struct nl_msg *msg, void *arg) |
455 | { | |
456 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
457 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
458 | struct nlattr *sinfo[NL80211_STA_INFO_MAX + 1]; | |
c5bfa2a3 SS |
459 | struct nlattr *link_sinfo[NL80211_STA_INFO_MAX + 1]; |
460 | struct nlattr *attrs, *link[NL80211_ATTR_MAX + 1]; | |
3d1e8704 | 461 | char mac_addr[20], state_name[10], dev[20]; |
b638215d | 462 | struct nl80211_sta_flag_update *sta_flags; |
3d1e8704 LCC |
463 | static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = { |
464 | [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 }, | |
465 | [NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 }, | |
466 | [NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 }, | |
568c7057 AE |
467 | [NL80211_STA_INFO_RX_BYTES64] = { .type = NLA_U64 }, |
468 | [NL80211_STA_INFO_TX_BYTES64] = { .type = NLA_U64 }, | |
859677cb JB |
469 | [NL80211_STA_INFO_RX_PACKETS] = { .type = NLA_U32 }, |
470 | [NL80211_STA_INFO_TX_PACKETS] = { .type = NLA_U32 }, | |
568c7057 | 471 | [NL80211_STA_INFO_BEACON_RX] = { .type = NLA_U64}, |
9cd3f1c1 | 472 | [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 }, |
ea3ade85 | 473 | [NL80211_STA_INFO_T_OFFSET] = { .type = NLA_U64 }, |
9cd3f1c1 | 474 | [NL80211_STA_INFO_TX_BITRATE] = { .type = NLA_NESTED }, |
e94f0201 | 475 | [NL80211_STA_INFO_RX_BITRATE] = { .type = NLA_NESTED }, |
3d1e8704 LCC |
476 | [NL80211_STA_INFO_LLID] = { .type = NLA_U16 }, |
477 | [NL80211_STA_INFO_PLID] = { .type = NLA_U16 }, | |
478 | [NL80211_STA_INFO_PLINK_STATE] = { .type = NLA_U8 }, | |
0f5868ee BR |
479 | [NL80211_STA_INFO_TX_RETRIES] = { .type = NLA_U32 }, |
480 | [NL80211_STA_INFO_TX_FAILED] = { .type = NLA_U32 }, | |
568c7057 AE |
481 | [NL80211_STA_INFO_BEACON_LOSS] = { .type = NLA_U32}, |
482 | [NL80211_STA_INFO_RX_DROP_MISC] = { .type = NLA_U64}, | |
b638215d HS |
483 | [NL80211_STA_INFO_STA_FLAGS] = |
484 | { .minlen = sizeof(struct nl80211_sta_flag_update) }, | |
8012ad28 MP |
485 | [NL80211_STA_INFO_LOCAL_PM] = { .type = NLA_U32}, |
486 | [NL80211_STA_INFO_PEER_PM] = { .type = NLA_U32}, | |
487 | [NL80211_STA_INFO_NONPEER_PM] = { .type = NLA_U32}, | |
7d23bc2d FF |
488 | [NL80211_STA_INFO_CHAIN_SIGNAL] = { .type = NLA_NESTED }, |
489 | [NL80211_STA_INFO_CHAIN_SIGNAL_AVG] = { .type = NLA_NESTED }, | |
568c7057 AE |
490 | [NL80211_STA_INFO_TID_STATS] = { .type = NLA_NESTED }, |
491 | [NL80211_STA_INFO_BSS_PARAM] = { .type = NLA_NESTED }, | |
045c1c6f | 492 | [NL80211_STA_INFO_RX_DURATION] = { .type = NLA_U64 }, |
a85d693f | 493 | [NL80211_STA_INFO_TX_DURATION] = { .type = NLA_U64 }, |
d2272671 BP |
494 | [NL80211_STA_INFO_ACK_SIGNAL] = {.type = NLA_U8 }, |
495 | [NL80211_STA_INFO_ACK_SIGNAL_AVG] = { .type = NLA_U8 }, | |
700f7d95 | 496 | [NL80211_STA_INFO_AIRTIME_LINK_METRIC] = { .type = NLA_U32 }, |
0ba98b90 MT |
497 | [NL80211_STA_INFO_CONNECTED_TO_AS] = { .type = NLA_U8 }, |
498 | [NL80211_STA_INFO_CONNECTED_TO_GATE] = { .type = NLA_U8 }, | |
3d1e8704 | 499 | }; |
3708f614 BG |
500 | struct timeval now; |
501 | unsigned long long now_ms; | |
502 | ||
503 | gettimeofday(&now, NULL); | |
5d9d1b86 | 504 | now_ms = now.tv_sec * 1000ULL; |
3708f614 | 505 | now_ms += (now.tv_usec / 1000); |
3d1e8704 LCC |
506 | |
507 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
508 | genlmsg_attrlen(gnlh, 0), NULL); | |
509 | ||
510 | /* | |
511 | * TODO: validate the interface and mac address! | |
512 | * Otherwise, there's a race condition as soon as | |
513 | * the kernel starts sending station notifications. | |
514 | */ | |
515 | ||
516 | if (!tb[NL80211_ATTR_STA_INFO]) { | |
5fe70c0e | 517 | fprintf(stderr, "sta stats missing!\n"); |
3d1e8704 LCC |
518 | return NL_SKIP; |
519 | } | |
520 | if (nla_parse_nested(sinfo, NL80211_STA_INFO_MAX, | |
521 | tb[NL80211_ATTR_STA_INFO], | |
522 | stats_policy)) { | |
5fe70c0e | 523 | fprintf(stderr, "failed to parse nested attributes!\n"); |
3d1e8704 LCC |
524 | return NL_SKIP; |
525 | } | |
526 | ||
527 | mac_addr_n2a(mac_addr, nla_data(tb[NL80211_ATTR_MAC])); | |
528 | if_indextoname(nla_get_u32(tb[NL80211_ATTR_IFINDEX]), dev); | |
fbb181fa | 529 | printf("Station %s (on %s)", mac_addr, dev); |
3d1e8704 | 530 | |
3d1e8704 | 531 | if (sinfo[NL80211_STA_INFO_LLID]) |
fbb181fa | 532 | printf("\n\tmesh llid:\t%d", |
3d1e8704 LCC |
533 | nla_get_u16(sinfo[NL80211_STA_INFO_LLID])); |
534 | if (sinfo[NL80211_STA_INFO_PLID]) | |
fbb181fa | 535 | printf("\n\tmesh plid:\t%d", |
3d1e8704 LCC |
536 | nla_get_u16(sinfo[NL80211_STA_INFO_PLID])); |
537 | if (sinfo[NL80211_STA_INFO_PLINK_STATE]) { | |
dbaabba1 | 538 | switch (nla_get_u8(sinfo[NL80211_STA_INFO_PLINK_STATE])) { |
3d1e8704 LCC |
539 | case LISTEN: |
540 | strcpy(state_name, "LISTEN"); | |
541 | break; | |
542 | case OPN_SNT: | |
543 | strcpy(state_name, "OPN_SNT"); | |
544 | break; | |
545 | case OPN_RCVD: | |
546 | strcpy(state_name, "OPN_RCVD"); | |
547 | break; | |
548 | case CNF_RCVD: | |
549 | strcpy(state_name, "CNF_RCVD"); | |
550 | break; | |
551 | case ESTAB: | |
552 | strcpy(state_name, "ESTAB"); | |
553 | break; | |
554 | case HOLDING: | |
555 | strcpy(state_name, "HOLDING"); | |
556 | break; | |
557 | case BLOCKED: | |
558 | strcpy(state_name, "BLOCKED"); | |
559 | break; | |
560 | default: | |
561 | strcpy(state_name, "UNKNOWN"); | |
562 | break; | |
563 | } | |
fbb181fa | 564 | printf("\n\tmesh plink:\t%s", state_name); |
3d1e8704 | 565 | } |
700f7d95 MT |
566 | if (sinfo[NL80211_STA_INFO_AIRTIME_LINK_METRIC]) |
567 | printf("\n\tmesh airtime link metric: %d", | |
568 | nla_get_u32(sinfo[NL80211_STA_INFO_AIRTIME_LINK_METRIC])); | |
569 | if (sinfo[NL80211_STA_INFO_CONNECTED_TO_GATE]) | |
570 | printf("\n\tmesh connected to gate:\t%s", | |
571 | nla_get_u8(sinfo[NL80211_STA_INFO_CONNECTED_TO_GATE]) ? | |
572 | "yes" : "no"); | |
573 | if (sinfo[NL80211_STA_INFO_CONNECTED_TO_AS]) | |
574 | printf("\n\tmesh connected to auth server:\t%s", | |
575 | nla_get_u8(sinfo[NL80211_STA_INFO_CONNECTED_TO_AS]) ? | |
576 | "yes" : "no"); | |
577 | ||
8012ad28 MP |
578 | if (sinfo[NL80211_STA_INFO_LOCAL_PM]) { |
579 | printf("\n\tmesh local PS mode:\t"); | |
580 | print_power_mode(sinfo[NL80211_STA_INFO_LOCAL_PM]); | |
581 | } | |
582 | if (sinfo[NL80211_STA_INFO_PEER_PM]) { | |
583 | printf("\n\tmesh peer PS mode:\t"); | |
584 | print_power_mode(sinfo[NL80211_STA_INFO_PEER_PM]); | |
585 | } | |
586 | if (sinfo[NL80211_STA_INFO_NONPEER_PM]) { | |
587 | printf("\n\tmesh non-peer PS mode:\t"); | |
588 | print_power_mode(sinfo[NL80211_STA_INFO_NONPEER_PM]); | |
589 | } | |
3d1e8704 | 590 | |
b638215d HS |
591 | if (sinfo[NL80211_STA_INFO_STA_FLAGS]) { |
592 | sta_flags = (struct nl80211_sta_flag_update *) | |
593 | nla_data(sinfo[NL80211_STA_INFO_STA_FLAGS]); | |
594 | ||
595 | if (sta_flags->mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) { | |
596 | printf("\n\tauthorized:\t"); | |
597 | if (sta_flags->set & BIT(NL80211_STA_FLAG_AUTHORIZED)) | |
598 | printf("yes"); | |
599 | else | |
600 | printf("no"); | |
601 | } | |
602 | ||
603 | if (sta_flags->mask & BIT(NL80211_STA_FLAG_AUTHENTICATED)) { | |
604 | printf("\n\tauthenticated:\t"); | |
605 | if (sta_flags->set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) | |
606 | printf("yes"); | |
607 | else | |
608 | printf("no"); | |
609 | } | |
610 | ||
568c7057 AE |
611 | if (sta_flags->mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) { |
612 | printf("\n\tassociated:\t"); | |
613 | if (sta_flags->set & BIT(NL80211_STA_FLAG_ASSOCIATED)) | |
614 | printf("yes"); | |
615 | else | |
616 | printf("no"); | |
617 | } | |
618 | ||
b638215d HS |
619 | if (sta_flags->mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) { |
620 | printf("\n\tpreamble:\t"); | |
621 | if (sta_flags->set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) | |
622 | printf("short"); | |
623 | else | |
624 | printf("long"); | |
625 | } | |
626 | ||
627 | if (sta_flags->mask & BIT(NL80211_STA_FLAG_WME)) { | |
628 | printf("\n\tWMM/WME:\t"); | |
629 | if (sta_flags->set & BIT(NL80211_STA_FLAG_WME)) | |
630 | printf("yes"); | |
631 | else | |
632 | printf("no"); | |
633 | } | |
634 | ||
635 | if (sta_flags->mask & BIT(NL80211_STA_FLAG_MFP)) { | |
636 | printf("\n\tMFP:\t\t"); | |
637 | if (sta_flags->set & BIT(NL80211_STA_FLAG_MFP)) | |
638 | printf("yes"); | |
639 | else | |
640 | printf("no"); | |
641 | } | |
642 | ||
643 | if (sta_flags->mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) { | |
1a463ae3 | 644 | printf("\n\tTDLS peer:\t"); |
b638215d HS |
645 | if (sta_flags->set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
646 | printf("yes"); | |
647 | else | |
648 | printf("no"); | |
649 | } | |
650 | } | |
651 | ||
c5bfa2a3 SS |
652 | /* print non-MLO/MLO specific fields */ |
653 | print_nested_sta_handler(sinfo, arg, "\n\t"); | |
3708f614 | 654 | |
c5bfa2a3 | 655 | printf("\n\tcurrent time:\t%llu ms\n", now_ms); |
3708f614 | 656 | |
c5bfa2a3 SS |
657 | /* print link specific fields */ |
658 | if (tb[NL80211_ATTR_MLO_LINKS]) { | |
659 | int ret = 0; | |
660 | ||
661 | nla_for_each_nested(attrs, tb[NL80211_ATTR_MLO_LINKS], ret) { | |
662 | nla_parse_nested(link, NL80211_ATTR_MAX, attrs, NULL); | |
663 | if (link[NL80211_ATTR_MLO_LINK_ID]) { | |
664 | printf("\n\tLink %u:", nla_get_u8(link[NL80211_ATTR_MLO_LINK_ID])); | |
665 | if (link[NL80211_ATTR_MAC]) { | |
666 | mac_addr_n2a(mac_addr, nla_data(link[NL80211_ATTR_MAC])); | |
667 | printf("\n\t\taddress: %s", mac_addr); | |
668 | } | |
669 | if (!link[NL80211_ATTR_STA_INFO]) { | |
670 | fprintf(stderr, "link sta stats missing!\n"); | |
671 | return NL_SKIP; | |
672 | } | |
673 | ||
674 | if (nla_parse_nested(link_sinfo, NL80211_STA_INFO_MAX, | |
675 | link[NL80211_ATTR_STA_INFO], | |
676 | stats_policy)) { | |
677 | fprintf(stderr, "failed to parse nested attributes!\n"); | |
678 | return NL_SKIP; | |
679 | } | |
680 | print_nested_sta_handler(link_sinfo, arg, "\n\t\t"); | |
681 | } | |
682 | } | |
0b39c408 | 683 | } |
c5bfa2a3 | 684 | printf("\n"); |
3d1e8704 LCC |
685 | return NL_SKIP; |
686 | } | |
687 | ||
7c37a24d | 688 | static int handle_station_get(struct nl80211_state *state, |
b1ca19a8 | 689 | struct nl_msg *msg, |
05514f95 JB |
690 | int argc, char **argv, |
691 | enum id_input id) | |
3d1e8704 | 692 | { |
3d1e8704 LCC |
693 | unsigned char mac_addr[ETH_ALEN]; |
694 | ||
b1ca19a8 | 695 | if (argc < 1) |
5e75fd04 | 696 | return 1; |
3d1e8704 LCC |
697 | |
698 | if (mac_addr_a2n(mac_addr, argv[0])) { | |
699 | fprintf(stderr, "invalid mac address\n"); | |
5e75fd04 | 700 | return 2; |
3d1e8704 LCC |
701 | } |
702 | ||
703 | argc--; | |
704 | argv++; | |
705 | ||
b1ca19a8 | 706 | if (argc) |
5e75fd04 | 707 | return 1; |
3d1e8704 LCC |
708 | |
709 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
3d1e8704 | 710 | |
34b23014 | 711 | register_handler(print_sta_handler, NULL); |
3d1e8704 | 712 | |
70391ccf | 713 | return 0; |
3d1e8704 | 714 | nla_put_failure: |
70391ccf | 715 | return -ENOBUFS; |
3d1e8704 | 716 | } |
b1ca19a8 | 717 | COMMAND(station, get, "<MAC address>", |
70cf4544 JB |
718 | NL80211_CMD_GET_STATION, 0, CIB_NETDEV, handle_station_get, |
719 | "Get information for a specific station."); | |
d738686c RM |
720 | |
721 | static int handle_station_del(struct nl80211_state *state, | |
722 | struct nl_msg *msg, | |
723 | int argc, char **argv, | |
724 | enum id_input id) | |
725 | { | |
726 | char *end; | |
727 | unsigned char mac_addr[ETH_ALEN]; | |
728 | int subtype; | |
729 | int reason_code; | |
730 | ||
731 | if (argc < 1) | |
732 | return 1; | |
733 | ||
734 | if (mac_addr_a2n(mac_addr, argv[0])) { | |
735 | fprintf(stderr, "invalid mac address\n"); | |
736 | return 2; | |
737 | } | |
738 | ||
739 | argc--; | |
740 | argv++; | |
741 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
742 | ||
743 | if (argc > 1 && strcmp(argv[0], "subtype") == 0) { | |
744 | argv++; | |
745 | argc--; | |
746 | ||
747 | subtype = strtod(argv[0], &end); | |
748 | if (*end != '\0') | |
749 | return 1; | |
750 | ||
751 | NLA_PUT_U8(msg, NL80211_ATTR_MGMT_SUBTYPE, subtype); | |
752 | argv++; | |
753 | argc--; | |
754 | } | |
755 | ||
756 | if (argc > 1 && strcmp(argv[0], "reason-code") == 0) { | |
757 | argv++; | |
758 | argc--; | |
759 | ||
760 | reason_code = strtod(argv[0], &end); | |
761 | if (*end != '\0') | |
762 | return 1; | |
763 | ||
764 | NLA_PUT_U16(msg, NL80211_ATTR_REASON_CODE, reason_code); | |
765 | argv++; | |
766 | argc--; | |
767 | } | |
768 | ||
769 | if (argc) | |
770 | return 1; | |
771 | ||
772 | register_handler(print_sta_handler, NULL); | |
773 | ||
774 | return 0; | |
775 | nla_put_failure: | |
776 | return -ENOBUFS; | |
777 | } | |
778 | COMMAND(station, del, "<MAC address> [subtype <subtype>] [reason-code <code>]", | |
779 | NL80211_CMD_DEL_STATION, 0, CIB_NETDEV, handle_station_del, | |
780 | "Remove the given station entry (use with caution!)\n" | |
781 | "Example subtype values: 0xA (disassociation), 0xC (deauthentication)"); | |
3d1e8704 | 782 | |
1633ddf7 JB |
783 | static const struct cmd *station_set_plink; |
784 | static const struct cmd *station_set_vlan; | |
8012ad28 | 785 | static const struct cmd *station_set_mesh_power_mode; |
82903243 | 786 | static const struct cmd *station_set_airtime_weight; |
5bdf11e3 | 787 | static const struct cmd *station_set_txpwr; |
1633ddf7 JB |
788 | |
789 | static const struct cmd *select_station_cmd(int argc, char **argv) | |
790 | { | |
791 | if (argc < 2) | |
792 | return NULL; | |
793 | if (strcmp(argv[1], "plink_action") == 0) | |
794 | return station_set_plink; | |
795 | if (strcmp(argv[1], "vlan") == 0) | |
796 | return station_set_vlan; | |
8012ad28 MP |
797 | if (strcmp(argv[1], "mesh_power_mode") == 0) |
798 | return station_set_mesh_power_mode; | |
82903243 THJ |
799 | if (strcmp(argv[1], "airtime_weight") == 0) |
800 | return station_set_airtime_weight; | |
5bdf11e3 ARN |
801 | if (strcmp(argv[1], "txpwr") == 0) |
802 | return station_set_txpwr; | |
1633ddf7 JB |
803 | return NULL; |
804 | } | |
805 | ||
ce0fc33a | 806 | static int handle_station_set_plink(struct nl80211_state *state, |
b1ca19a8 | 807 | struct nl_msg *msg, |
05514f95 JB |
808 | int argc, char **argv, |
809 | enum id_input id) | |
3d1e8704 | 810 | { |
3d1e8704 LCC |
811 | unsigned char plink_action; |
812 | unsigned char mac_addr[ETH_ALEN]; | |
813 | ||
b1ca19a8 | 814 | if (argc < 3) |
5e75fd04 | 815 | return 1; |
3d1e8704 LCC |
816 | |
817 | if (mac_addr_a2n(mac_addr, argv[0])) { | |
818 | fprintf(stderr, "invalid mac address\n"); | |
5e75fd04 | 819 | return 2; |
3d1e8704 LCC |
820 | } |
821 | argc--; | |
822 | argv++; | |
823 | ||
b1ca19a8 JB |
824 | if (strcmp("plink_action", argv[0]) != 0) |
825 | return 1; | |
3d1e8704 LCC |
826 | argc--; |
827 | argv++; | |
828 | ||
829 | if (strcmp("open", argv[0]) == 0) | |
ac38f8ad | 830 | plink_action = NL80211_PLINK_ACTION_OPEN; |
3d1e8704 | 831 | else if (strcmp("block", argv[0]) == 0) |
ac38f8ad | 832 | plink_action = NL80211_PLINK_ACTION_BLOCK; |
3d1e8704 LCC |
833 | else { |
834 | fprintf(stderr, "plink action not supported\n"); | |
5e75fd04 | 835 | return 2; |
3d1e8704 LCC |
836 | } |
837 | argc--; | |
838 | argv++; | |
839 | ||
b1ca19a8 | 840 | if (argc) |
5e75fd04 | 841 | return 1; |
3d1e8704 LCC |
842 | |
843 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
3d1e8704 LCC |
844 | NLA_PUT_U8(msg, NL80211_ATTR_STA_PLINK_ACTION, plink_action); |
845 | ||
70391ccf | 846 | return 0; |
3d1e8704 | 847 | nla_put_failure: |
70391ccf | 848 | return -ENOBUFS; |
3d1e8704 | 849 | } |
1633ddf7 | 850 | COMMAND_ALIAS(station, set, "<MAC address> plink_action <open|block>", |
ce0fc33a | 851 | NL80211_CMD_SET_STATION, 0, CIB_NETDEV, handle_station_set_plink, |
1633ddf7 JB |
852 | "Set mesh peer link action for this station (peer).", |
853 | select_station_cmd, station_set_plink); | |
b1ca19a8 | 854 | |
ce0fc33a | 855 | static int handle_station_set_vlan(struct nl80211_state *state, |
05514f95 JB |
856 | struct nl_msg *msg, |
857 | int argc, char **argv, | |
858 | enum id_input id) | |
ce0fc33a FF |
859 | { |
860 | unsigned char mac_addr[ETH_ALEN]; | |
861 | unsigned long sta_vlan = 0; | |
862 | char *err = NULL; | |
863 | ||
864 | if (argc < 3) | |
865 | return 1; | |
866 | ||
867 | if (mac_addr_a2n(mac_addr, argv[0])) { | |
868 | fprintf(stderr, "invalid mac address\n"); | |
869 | return 2; | |
870 | } | |
871 | argc--; | |
872 | argv++; | |
873 | ||
874 | if (strcmp("vlan", argv[0]) != 0) | |
875 | return 1; | |
876 | argc--; | |
877 | argv++; | |
878 | ||
879 | sta_vlan = strtoul(argv[0], &err, 0); | |
880 | if (err && *err) { | |
881 | fprintf(stderr, "invalid vlan id\n"); | |
882 | return 2; | |
883 | } | |
884 | argc--; | |
885 | argv++; | |
886 | ||
887 | if (argc) | |
888 | return 1; | |
889 | ||
890 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
891 | NLA_PUT_U32(msg, NL80211_ATTR_STA_VLAN, sta_vlan); | |
892 | ||
893 | return 0; | |
894 | nla_put_failure: | |
895 | return -ENOBUFS; | |
896 | } | |
1633ddf7 | 897 | COMMAND_ALIAS(station, set, "<MAC address> vlan <ifindex>", |
ce0fc33a | 898 | NL80211_CMD_SET_STATION, 0, CIB_NETDEV, handle_station_set_vlan, |
1633ddf7 JB |
899 | "Set an AP VLAN for this station.", |
900 | select_station_cmd, station_set_vlan); | |
ce0fc33a | 901 | |
8012ad28 | 902 | static int handle_station_set_mesh_power_mode(struct nl80211_state *state, |
8012ad28 MP |
903 | struct nl_msg *msg, |
904 | int argc, char **argv, | |
905 | enum id_input id) | |
906 | { | |
907 | unsigned char mesh_power_mode; | |
908 | unsigned char mac_addr[ETH_ALEN]; | |
909 | ||
910 | if (argc < 3) | |
911 | return 1; | |
912 | ||
913 | if (mac_addr_a2n(mac_addr, argv[0])) { | |
914 | fprintf(stderr, "invalid mac address\n"); | |
915 | return 2; | |
916 | } | |
917 | argc--; | |
918 | argv++; | |
919 | ||
920 | if (strcmp("mesh_power_mode", argv[0]) != 0) | |
921 | return 1; | |
922 | argc--; | |
923 | argv++; | |
924 | ||
925 | if (strcmp("active", argv[0]) == 0) | |
926 | mesh_power_mode = NL80211_MESH_POWER_ACTIVE; | |
927 | else if (strcmp("light", argv[0]) == 0) | |
928 | mesh_power_mode = NL80211_MESH_POWER_LIGHT_SLEEP; | |
929 | else if (strcmp("deep", argv[0]) == 0) | |
930 | mesh_power_mode = NL80211_MESH_POWER_DEEP_SLEEP; | |
931 | else { | |
932 | fprintf(stderr, "unknown mesh power mode\n"); | |
933 | return 2; | |
934 | } | |
935 | argc--; | |
936 | argv++; | |
937 | ||
938 | if (argc) | |
939 | return 1; | |
940 | ||
941 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
942 | NLA_PUT_U32(msg, NL80211_ATTR_LOCAL_MESH_POWER_MODE, mesh_power_mode); | |
943 | ||
944 | return 0; | |
945 | nla_put_failure: | |
946 | return -ENOBUFS; | |
947 | } | |
948 | COMMAND_ALIAS(station, set, "<MAC address> mesh_power_mode " | |
949 | "<active|light|deep>", NL80211_CMD_SET_STATION, 0, CIB_NETDEV, | |
950 | handle_station_set_mesh_power_mode, | |
951 | "Set link-specific mesh power mode for this station", | |
952 | select_station_cmd, station_set_mesh_power_mode); | |
ce0fc33a | 953 | |
82903243 THJ |
954 | static int handle_station_set_airtime_weight(struct nl80211_state *state, |
955 | struct nl_msg *msg, | |
956 | int argc, char **argv, | |
957 | enum id_input id) | |
958 | { | |
959 | unsigned char mac_addr[ETH_ALEN]; | |
960 | unsigned long airtime_weight = 0; | |
961 | char *err = NULL; | |
962 | ||
963 | if (argc < 3) | |
964 | return 1; | |
965 | ||
966 | if (mac_addr_a2n(mac_addr, argv[0])) { | |
967 | fprintf(stderr, "invalid mac address\n"); | |
968 | return 2; | |
969 | } | |
970 | argc--; | |
971 | argv++; | |
972 | ||
973 | if (strcmp("airtime_weight", argv[0]) != 0) | |
974 | return 1; | |
975 | argc--; | |
976 | argv++; | |
977 | ||
978 | airtime_weight = strtoul(argv[0], &err, 0); | |
979 | if (err && *err) { | |
980 | fprintf(stderr, "invalid airtime weight\n"); | |
981 | return 2; | |
982 | } | |
983 | argc--; | |
984 | argv++; | |
985 | ||
986 | if (argc) | |
987 | return 1; | |
988 | ||
989 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
990 | NLA_PUT_U16(msg, NL80211_ATTR_AIRTIME_WEIGHT, airtime_weight); | |
991 | ||
992 | return 0; | |
993 | nla_put_failure: | |
994 | return -ENOBUFS; | |
995 | ||
996 | } | |
997 | COMMAND_ALIAS(station, set, "<MAC address> airtime_weight <weight>", | |
998 | NL80211_CMD_SET_STATION, 0, CIB_NETDEV, handle_station_set_airtime_weight, | |
999 | "Set airtime weight for this station.", | |
1000 | select_station_cmd, station_set_airtime_weight); | |
1001 | ||
5bdf11e3 ARN |
1002 | static int handle_station_set_txpwr(struct nl80211_state *state, |
1003 | struct nl_msg *msg, | |
1004 | int argc, char **argv, | |
1005 | enum id_input id) | |
1006 | { | |
1007 | enum nl80211_tx_power_setting type; | |
1008 | unsigned char mac_addr[ETH_ALEN]; | |
1009 | int sta_txpwr = 0; | |
1010 | char *err = NULL; | |
1011 | ||
1012 | if (argc != 3 && argc != 4) | |
1013 | return 1; | |
1014 | ||
1015 | if (mac_addr_a2n(mac_addr, argv[0])) { | |
1016 | fprintf(stderr, "invalid mac address\n"); | |
1017 | return 2; | |
1018 | } | |
1019 | ||
1020 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
1021 | argc--; | |
1022 | argv++; | |
1023 | ||
1024 | if (strcmp("txpwr", argv[0]) != 0) | |
1025 | return 1; | |
1026 | argc--; | |
1027 | argv++; | |
1028 | ||
1029 | if (!strcmp(argv[0], "auto")) | |
1030 | type = NL80211_TX_POWER_AUTOMATIC; | |
1031 | else if (!strcmp(argv[0], "limit")) | |
1032 | type = NL80211_TX_POWER_LIMITED; | |
1033 | else { | |
1034 | printf("Invalid parameter: %s\n", argv[0]); | |
1035 | return 2; | |
1036 | } | |
1037 | ||
1038 | NLA_PUT_U8(msg, NL80211_ATTR_STA_TX_POWER_SETTING, type); | |
1039 | ||
1040 | if (type != NL80211_TX_POWER_AUTOMATIC) { | |
1041 | if (argc != 2) { | |
1042 | printf("Missing TX power level argument.\n"); | |
1043 | return 2; | |
1044 | } | |
1045 | ||
1046 | argc--; | |
1047 | argv++; | |
1048 | ||
1049 | sta_txpwr = strtoul(argv[0], &err, 0); | |
1050 | NLA_PUT_U16(msg, NL80211_ATTR_STA_TX_POWER, sta_txpwr); | |
1051 | } | |
1052 | ||
1053 | argc--; | |
1054 | argv++; | |
1055 | ||
1056 | if (argc) | |
1057 | return 1; | |
1058 | ||
1059 | return 0; | |
1060 | nla_put_failure: | |
1061 | return -ENOBUFS; | |
1062 | } | |
1063 | COMMAND_ALIAS(station, set, "<MAC address> txpwr <auto|limit> [<tx power dBm>]", | |
1064 | NL80211_CMD_SET_STATION, 0, CIB_NETDEV, handle_station_set_txpwr, | |
1065 | "Set Tx power for this station.", | |
1066 | select_station_cmd, station_set_txpwr); | |
1067 | ||
7c37a24d | 1068 | static int handle_station_dump(struct nl80211_state *state, |
b1ca19a8 | 1069 | struct nl_msg *msg, |
05514f95 JB |
1070 | int argc, char **argv, |
1071 | enum id_input id) | |
3d1e8704 | 1072 | { |
568c7057 | 1073 | register_handler(print_sta_handler, *argv); |
70391ccf | 1074 | return 0; |
3d1e8704 | 1075 | } |
568c7057 | 1076 | COMMAND(station, dump, "[-v]", |
70cf4544 JB |
1077 | NL80211_CMD_GET_STATION, NLM_F_DUMP, CIB_NETDEV, handle_station_dump, |
1078 | "List all stations known, e.g. the AP on managed interfaces"); |