]>
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> | |
3d1e8704 | 10 | |
f408e01b | 11 | #include "nl80211.h" |
3d1e8704 LCC |
12 | #include "iw.h" |
13 | ||
4698bfc2 JB |
14 | SECTION(station); |
15 | ||
3d1e8704 LCC |
16 | enum plink_state { |
17 | LISTEN, | |
18 | OPN_SNT, | |
19 | OPN_RCVD, | |
20 | CNF_RCVD, | |
21 | ESTAB, | |
22 | HOLDING, | |
23 | BLOCKED | |
24 | }; | |
25 | ||
8012ad28 MP |
26 | static void print_power_mode(struct nlattr *a) |
27 | { | |
28 | enum nl80211_mesh_power_mode pm = nla_get_u32(a); | |
29 | ||
30 | switch (pm) { | |
31 | case NL80211_MESH_POWER_ACTIVE: | |
32 | printf("ACTIVE"); | |
33 | break; | |
34 | case NL80211_MESH_POWER_LIGHT_SLEEP: | |
35 | printf("LIGHT SLEEP"); | |
36 | break; | |
37 | case NL80211_MESH_POWER_DEEP_SLEEP: | |
38 | printf("DEEP SLEEP"); | |
39 | break; | |
40 | default: | |
41 | printf("UNKNOWN"); | |
42 | break; | |
43 | } | |
44 | } | |
3d1e8704 | 45 | |
910792c0 THJ |
46 | int parse_txq_stats(char *buf, int buflen, struct nlattr *tid_stats_attr, int header, |
47 | int tid, const char *indent) | |
48 | { | |
49 | struct nlattr *txqstats_info[NL80211_TXQ_STATS_MAX + 1], *txqinfo; | |
50 | static struct nla_policy txqstats_policy[NL80211_TXQ_STATS_MAX + 1] = { | |
51 | [NL80211_TXQ_STATS_BACKLOG_BYTES] = { .type = NLA_U32 }, | |
52 | [NL80211_TXQ_STATS_BACKLOG_PACKETS] = { .type = NLA_U32 }, | |
53 | [NL80211_TXQ_STATS_FLOWS] = { .type = NLA_U32 }, | |
54 | [NL80211_TXQ_STATS_DROPS] = { .type = NLA_U32 }, | |
55 | [NL80211_TXQ_STATS_ECN_MARKS] = { .type = NLA_U32 }, | |
56 | [NL80211_TXQ_STATS_OVERLIMIT] = { .type = NLA_U32 }, | |
57 | [NL80211_TXQ_STATS_COLLISIONS] = { .type = NLA_U32 }, | |
58 | [NL80211_TXQ_STATS_TX_BYTES] = { .type = NLA_U32 }, | |
59 | [NL80211_TXQ_STATS_TX_PACKETS] = { .type = NLA_U32 }, | |
60 | }; | |
61 | char *pos = buf; | |
62 | if (nla_parse_nested(txqstats_info, NL80211_TXQ_STATS_MAX, tid_stats_attr, | |
63 | txqstats_policy)) { | |
64 | printf("failed to parse nested TXQ stats attributes!"); | |
65 | return 0; | |
66 | } | |
67 | ||
68 | if (header) | |
69 | pos += snprintf(buf, buflen, "\n%s\t%s\tqsz-byt\t" | |
70 | "qsz-pkt\tflows\tdrops\tmarks\toverlmt\t" | |
71 | "hashcol\ttx-bytes\ttx-packets", indent, | |
72 | tid >= 0 ? "TID" : ""); | |
73 | ||
74 | pos += snprintf(pos, buflen - (pos - buf), "\n%s\t", indent); | |
75 | if (tid >= 0) | |
76 | pos += snprintf(pos, buflen - (pos - buf), "%d", tid); | |
77 | ||
78 | #define PRINT_STAT(key, spacer) do { \ | |
79 | txqinfo = txqstats_info[NL80211_TXQ_STATS_ ## key]; \ | |
80 | pos += snprintf(pos, buflen - (pos - buf), spacer); \ | |
81 | if (txqinfo) \ | |
82 | pos += snprintf(pos, buflen - (pos - buf), "%u", \ | |
83 | nla_get_u32(txqinfo)); \ | |
84 | } while (0) | |
85 | ||
86 | ||
87 | PRINT_STAT(BACKLOG_BYTES, "\t"); | |
88 | PRINT_STAT(BACKLOG_PACKETS, "\t"); | |
89 | PRINT_STAT(FLOWS, "\t"); | |
90 | PRINT_STAT(DROPS, "\t"); | |
91 | PRINT_STAT(ECN_MARKS, "\t"); | |
92 | PRINT_STAT(OVERLIMIT, "\t"); | |
93 | PRINT_STAT(COLLISIONS, "\t"); | |
94 | PRINT_STAT(TX_BYTES, "\t"); | |
95 | PRINT_STAT(TX_PACKETS, "\t\t"); | |
96 | ||
97 | #undef PRINT_STAT | |
98 | ||
99 | return pos - buf; | |
100 | ||
101 | } | |
bcdceae1 JB |
102 | |
103 | static void parse_tid_stats(struct nlattr *tid_stats_attr) | |
568c7057 AE |
104 | { |
105 | struct nlattr *stats_info[NL80211_TID_STATS_MAX + 1], *tidattr, *info; | |
106 | static struct nla_policy stats_policy[NL80211_TID_STATS_MAX + 1] = { | |
107 | [NL80211_TID_STATS_RX_MSDU] = { .type = NLA_U64 }, | |
108 | [NL80211_TID_STATS_TX_MSDU] = { .type = NLA_U64 }, | |
109 | [NL80211_TID_STATS_TX_MSDU_RETRIES] = { .type = NLA_U64 }, | |
110 | [NL80211_TID_STATS_TX_MSDU_FAILED] = { .type = NLA_U64 }, | |
910792c0 | 111 | [NL80211_TID_STATS_TXQ_STATS] = { .type = NLA_NESTED }, |
568c7057 AE |
112 | }; |
113 | int rem, i = 0; | |
910792c0 THJ |
114 | char txqbuf[2000] = {}, *pos = txqbuf; |
115 | int buflen = sizeof(txqbuf), foundtxq = 0; | |
568c7057 AE |
116 | |
117 | printf("\n\tMSDU:\n\t\tTID\trx\ttx\ttx retries\ttx failed"); | |
118 | nla_for_each_nested(tidattr, tid_stats_attr, rem) { | |
119 | if (nla_parse_nested(stats_info, NL80211_TID_STATS_MAX, | |
120 | tidattr, stats_policy)) { | |
121 | printf("failed to parse nested stats attributes!"); | |
122 | return; | |
123 | } | |
910792c0 | 124 | printf("\n\t\t%d", i); |
568c7057 AE |
125 | info = stats_info[NL80211_TID_STATS_RX_MSDU]; |
126 | if (info) | |
127 | printf("\t%llu", (unsigned long long)nla_get_u64(info)); | |
128 | info = stats_info[NL80211_TID_STATS_TX_MSDU]; | |
129 | if (info) | |
130 | printf("\t%llu", (unsigned long long)nla_get_u64(info)); | |
131 | info = stats_info[NL80211_TID_STATS_TX_MSDU_RETRIES]; | |
132 | if (info) | |
133 | printf("\t%llu", (unsigned long long)nla_get_u64(info)); | |
134 | info = stats_info[NL80211_TID_STATS_TX_MSDU_FAILED]; | |
135 | if (info) | |
136 | printf("\t\t%llu", (unsigned long long)nla_get_u64(info)); | |
910792c0 THJ |
137 | info = stats_info[NL80211_TID_STATS_TXQ_STATS]; |
138 | if (info) { | |
139 | pos += parse_txq_stats(pos, buflen - (pos - txqbuf), info, !foundtxq, i, "\t"); | |
140 | foundtxq = 1; | |
141 | } | |
142 | ||
143 | i++; | |
568c7057 | 144 | } |
910792c0 THJ |
145 | |
146 | if (foundtxq) | |
147 | printf("\n\tTXQs:%s", txqbuf); | |
568c7057 AE |
148 | } |
149 | ||
bcdceae1 | 150 | static void parse_bss_param(struct nlattr *bss_param_attr) |
568c7057 AE |
151 | { |
152 | struct nlattr *bss_param_info[NL80211_STA_BSS_PARAM_MAX + 1], *info; | |
153 | static struct nla_policy bss_poilcy[NL80211_STA_BSS_PARAM_MAX + 1] = { | |
154 | [NL80211_STA_BSS_PARAM_CTS_PROT] = { .type = NLA_FLAG }, | |
155 | [NL80211_STA_BSS_PARAM_SHORT_PREAMBLE] = { .type = NLA_FLAG }, | |
156 | [NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME] = { .type = NLA_FLAG }, | |
157 | [NL80211_STA_BSS_PARAM_DTIM_PERIOD] = { .type = NLA_U8 }, | |
158 | [NL80211_STA_BSS_PARAM_BEACON_INTERVAL] = { .type = NLA_U16 }, | |
159 | }; | |
160 | ||
161 | if (nla_parse_nested(bss_param_info, NL80211_STA_BSS_PARAM_MAX, | |
162 | bss_param_attr, bss_poilcy)) { | |
163 | printf("failed to parse nested bss param attributes!"); | |
164 | } | |
165 | ||
166 | info = bss_param_info[NL80211_STA_BSS_PARAM_DTIM_PERIOD]; | |
167 | if (info) | |
168 | printf("\n\tDTIM period:\t%u", nla_get_u8(info)); | |
169 | info = bss_param_info[NL80211_STA_BSS_PARAM_BEACON_INTERVAL]; | |
170 | if (info) | |
171 | printf("\n\tbeacon interval:%u", nla_get_u16(info)); | |
172 | info = bss_param_info[NL80211_STA_BSS_PARAM_CTS_PROT]; | |
173 | if (info) { | |
174 | printf("\n\tCTS protection:"); | |
175 | if (nla_get_u16(info)) | |
176 | printf("\tyes"); | |
177 | else | |
178 | printf("\tno"); | |
179 | } | |
180 | info = bss_param_info[NL80211_STA_BSS_PARAM_SHORT_PREAMBLE]; | |
181 | if (info) { | |
182 | printf("\n\tshort preamble:"); | |
183 | if (nla_get_u16(info)) | |
184 | printf("\tyes"); | |
185 | else | |
186 | printf("\tno"); | |
187 | } | |
188 | info = bss_param_info[NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME]; | |
189 | if (info) { | |
190 | printf("\n\tshort slot time:"); | |
191 | if (nla_get_u16(info)) | |
192 | printf("yes"); | |
193 | else | |
194 | printf("no"); | |
195 | } | |
196 | } | |
197 | ||
e94f0201 | 198 | void parse_bitrate(struct nlattr *bitrate_attr, char *buf, int buflen) |
64179590 JB |
199 | { |
200 | int rate = 0; | |
201 | char *pos = buf; | |
202 | struct nlattr *rinfo[NL80211_RATE_INFO_MAX + 1]; | |
203 | static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = { | |
204 | [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 }, | |
205 | [NL80211_RATE_INFO_BITRATE32] = { .type = NLA_U32 }, | |
206 | [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 }, | |
207 | [NL80211_RATE_INFO_40_MHZ_WIDTH] = { .type = NLA_FLAG }, | |
208 | [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG }, | |
209 | }; | |
210 | ||
211 | if (nla_parse_nested(rinfo, NL80211_RATE_INFO_MAX, | |
212 | bitrate_attr, rate_policy)) { | |
213 | snprintf(buf, buflen, "failed to parse nested rate attributes!"); | |
214 | return; | |
215 | } | |
216 | ||
217 | if (rinfo[NL80211_RATE_INFO_BITRATE32]) | |
218 | rate = nla_get_u32(rinfo[NL80211_RATE_INFO_BITRATE32]); | |
219 | else if (rinfo[NL80211_RATE_INFO_BITRATE]) | |
220 | rate = nla_get_u16(rinfo[NL80211_RATE_INFO_BITRATE]); | |
221 | if (rate > 0) | |
222 | pos += snprintf(pos, buflen - (pos - buf), | |
223 | "%d.%d MBit/s", rate / 10, rate % 10); | |
5ce1f6c7 MH |
224 | else |
225 | pos += snprintf(pos, buflen - (pos - buf), "(unknown)"); | |
64179590 JB |
226 | |
227 | if (rinfo[NL80211_RATE_INFO_MCS]) | |
228 | pos += snprintf(pos, buflen - (pos - buf), | |
229 | " MCS %d", nla_get_u8(rinfo[NL80211_RATE_INFO_MCS])); | |
230 | if (rinfo[NL80211_RATE_INFO_VHT_MCS]) | |
231 | pos += snprintf(pos, buflen - (pos - buf), | |
232 | " VHT-MCS %d", nla_get_u8(rinfo[NL80211_RATE_INFO_VHT_MCS])); | |
233 | if (rinfo[NL80211_RATE_INFO_40_MHZ_WIDTH]) | |
234 | pos += snprintf(pos, buflen - (pos - buf), " 40MHz"); | |
235 | if (rinfo[NL80211_RATE_INFO_80_MHZ_WIDTH]) | |
236 | pos += snprintf(pos, buflen - (pos - buf), " 80MHz"); | |
237 | if (rinfo[NL80211_RATE_INFO_80P80_MHZ_WIDTH]) | |
238 | pos += snprintf(pos, buflen - (pos - buf), " 80P80MHz"); | |
239 | if (rinfo[NL80211_RATE_INFO_160_MHZ_WIDTH]) | |
240 | pos += snprintf(pos, buflen - (pos - buf), " 160MHz"); | |
241 | if (rinfo[NL80211_RATE_INFO_SHORT_GI]) | |
242 | pos += snprintf(pos, buflen - (pos - buf), " short GI"); | |
243 | if (rinfo[NL80211_RATE_INFO_VHT_NSS]) | |
244 | pos += snprintf(pos, buflen - (pos - buf), | |
245 | " VHT-NSS %d", nla_get_u8(rinfo[NL80211_RATE_INFO_VHT_NSS])); | |
848d97d9 JC |
246 | if (rinfo[NL80211_RATE_INFO_HE_MCS]) |
247 | pos += snprintf(pos, buflen - (pos - buf), | |
248 | " HE-MCS %d", nla_get_u8(rinfo[NL80211_RATE_INFO_HE_MCS])); | |
249 | if (rinfo[NL80211_RATE_INFO_HE_NSS]) | |
250 | pos += snprintf(pos, buflen - (pos - buf), | |
251 | " HE-NSS %d", nla_get_u8(rinfo[NL80211_RATE_INFO_HE_NSS])); | |
252 | if (rinfo[NL80211_RATE_INFO_HE_GI]) | |
253 | pos += snprintf(pos, buflen - (pos - buf), | |
254 | " HE-GI %d", nla_get_u8(rinfo[NL80211_RATE_INFO_HE_GI])); | |
255 | if (rinfo[NL80211_RATE_INFO_HE_DCM]) | |
256 | pos += snprintf(pos, buflen - (pos - buf), | |
257 | " HE-DCM %d", nla_get_u8(rinfo[NL80211_RATE_INFO_HE_DCM])); | |
64179590 JB |
258 | } |
259 | ||
7d23bc2d FF |
260 | static char *get_chain_signal(struct nlattr *attr_list) |
261 | { | |
262 | struct nlattr *attr; | |
263 | static char buf[64]; | |
264 | char *cur = buf; | |
265 | int i = 0, rem; | |
266 | const char *prefix; | |
267 | ||
268 | if (!attr_list) | |
269 | return ""; | |
270 | ||
271 | nla_for_each_nested(attr, attr_list, rem) { | |
272 | if (i++ > 0) | |
273 | prefix = ", "; | |
274 | else | |
275 | prefix = "["; | |
276 | ||
277 | cur += snprintf(cur, sizeof(buf) - (cur - buf), "%s%d", prefix, | |
278 | (int8_t) nla_get_u8(attr)); | |
279 | } | |
280 | ||
281 | if (i) | |
282 | snprintf(cur, sizeof(buf) - (cur - buf), "] "); | |
283 | ||
284 | return buf; | |
285 | } | |
286 | ||
3d1e8704 LCC |
287 | static int print_sta_handler(struct nl_msg *msg, void *arg) |
288 | { | |
289 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
290 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
291 | struct nlattr *sinfo[NL80211_STA_INFO_MAX + 1]; | |
292 | char mac_addr[20], state_name[10], dev[20]; | |
b638215d | 293 | struct nl80211_sta_flag_update *sta_flags; |
3d1e8704 LCC |
294 | static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = { |
295 | [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 }, | |
296 | [NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 }, | |
297 | [NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 }, | |
568c7057 AE |
298 | [NL80211_STA_INFO_RX_BYTES64] = { .type = NLA_U64 }, |
299 | [NL80211_STA_INFO_TX_BYTES64] = { .type = NLA_U64 }, | |
859677cb JB |
300 | [NL80211_STA_INFO_RX_PACKETS] = { .type = NLA_U32 }, |
301 | [NL80211_STA_INFO_TX_PACKETS] = { .type = NLA_U32 }, | |
568c7057 | 302 | [NL80211_STA_INFO_BEACON_RX] = { .type = NLA_U64}, |
9cd3f1c1 | 303 | [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 }, |
ea3ade85 | 304 | [NL80211_STA_INFO_T_OFFSET] = { .type = NLA_U64 }, |
9cd3f1c1 | 305 | [NL80211_STA_INFO_TX_BITRATE] = { .type = NLA_NESTED }, |
e94f0201 | 306 | [NL80211_STA_INFO_RX_BITRATE] = { .type = NLA_NESTED }, |
3d1e8704 LCC |
307 | [NL80211_STA_INFO_LLID] = { .type = NLA_U16 }, |
308 | [NL80211_STA_INFO_PLID] = { .type = NLA_U16 }, | |
309 | [NL80211_STA_INFO_PLINK_STATE] = { .type = NLA_U8 }, | |
0f5868ee BR |
310 | [NL80211_STA_INFO_TX_RETRIES] = { .type = NLA_U32 }, |
311 | [NL80211_STA_INFO_TX_FAILED] = { .type = NLA_U32 }, | |
568c7057 AE |
312 | [NL80211_STA_INFO_BEACON_LOSS] = { .type = NLA_U32}, |
313 | [NL80211_STA_INFO_RX_DROP_MISC] = { .type = NLA_U64}, | |
b638215d HS |
314 | [NL80211_STA_INFO_STA_FLAGS] = |
315 | { .minlen = sizeof(struct nl80211_sta_flag_update) }, | |
8012ad28 MP |
316 | [NL80211_STA_INFO_LOCAL_PM] = { .type = NLA_U32}, |
317 | [NL80211_STA_INFO_PEER_PM] = { .type = NLA_U32}, | |
318 | [NL80211_STA_INFO_NONPEER_PM] = { .type = NLA_U32}, | |
7d23bc2d FF |
319 | [NL80211_STA_INFO_CHAIN_SIGNAL] = { .type = NLA_NESTED }, |
320 | [NL80211_STA_INFO_CHAIN_SIGNAL_AVG] = { .type = NLA_NESTED }, | |
568c7057 AE |
321 | [NL80211_STA_INFO_TID_STATS] = { .type = NLA_NESTED }, |
322 | [NL80211_STA_INFO_BSS_PARAM] = { .type = NLA_NESTED }, | |
045c1c6f | 323 | [NL80211_STA_INFO_RX_DURATION] = { .type = NLA_U64 }, |
a85d693f | 324 | [NL80211_STA_INFO_TX_DURATION] = { .type = NLA_U64 }, |
d2272671 BP |
325 | [NL80211_STA_INFO_ACK_SIGNAL] = {.type = NLA_U8 }, |
326 | [NL80211_STA_INFO_ACK_SIGNAL_AVG] = { .type = NLA_U8 }, | |
3d1e8704 | 327 | }; |
7d23bc2d | 328 | char *chain; |
3d1e8704 LCC |
329 | |
330 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
331 | genlmsg_attrlen(gnlh, 0), NULL); | |
332 | ||
333 | /* | |
334 | * TODO: validate the interface and mac address! | |
335 | * Otherwise, there's a race condition as soon as | |
336 | * the kernel starts sending station notifications. | |
337 | */ | |
338 | ||
339 | if (!tb[NL80211_ATTR_STA_INFO]) { | |
5fe70c0e | 340 | fprintf(stderr, "sta stats missing!\n"); |
3d1e8704 LCC |
341 | return NL_SKIP; |
342 | } | |
343 | if (nla_parse_nested(sinfo, NL80211_STA_INFO_MAX, | |
344 | tb[NL80211_ATTR_STA_INFO], | |
345 | stats_policy)) { | |
5fe70c0e | 346 | fprintf(stderr, "failed to parse nested attributes!\n"); |
3d1e8704 LCC |
347 | return NL_SKIP; |
348 | } | |
349 | ||
350 | mac_addr_n2a(mac_addr, nla_data(tb[NL80211_ATTR_MAC])); | |
351 | if_indextoname(nla_get_u32(tb[NL80211_ATTR_IFINDEX]), dev); | |
fbb181fa | 352 | printf("Station %s (on %s)", mac_addr, dev); |
3d1e8704 LCC |
353 | |
354 | if (sinfo[NL80211_STA_INFO_INACTIVE_TIME]) | |
f5c9799c | 355 | printf("\n\tinactive time:\t%u ms", |
3d1e8704 | 356 | nla_get_u32(sinfo[NL80211_STA_INFO_INACTIVE_TIME])); |
568c7057 AE |
357 | if (sinfo[NL80211_STA_INFO_RX_BYTES64]) |
358 | printf("\n\trx bytes:\t%llu", | |
359 | (unsigned long long)nla_get_u64(sinfo[NL80211_STA_INFO_RX_BYTES64])); | |
360 | else if (sinfo[NL80211_STA_INFO_RX_BYTES]) | |
f5c9799c | 361 | printf("\n\trx bytes:\t%u", |
568c7057 | 362 | nla_get_u32(sinfo[NL80211_STA_INFO_RX_BYTES])); |
859677cb | 363 | if (sinfo[NL80211_STA_INFO_RX_PACKETS]) |
f5c9799c | 364 | printf("\n\trx packets:\t%u", |
859677cb | 365 | nla_get_u32(sinfo[NL80211_STA_INFO_RX_PACKETS])); |
568c7057 AE |
366 | if (sinfo[NL80211_STA_INFO_TX_BYTES64]) |
367 | printf("\n\ttx bytes:\t%llu", | |
368 | (unsigned long long)nla_get_u64(sinfo[NL80211_STA_INFO_TX_BYTES64])); | |
369 | else if (sinfo[NL80211_STA_INFO_TX_BYTES]) | |
f5c9799c | 370 | printf("\n\ttx bytes:\t%u", |
568c7057 | 371 | nla_get_u32(sinfo[NL80211_STA_INFO_TX_BYTES])); |
859677cb | 372 | if (sinfo[NL80211_STA_INFO_TX_PACKETS]) |
f5c9799c | 373 | printf("\n\ttx packets:\t%u", |
859677cb | 374 | nla_get_u32(sinfo[NL80211_STA_INFO_TX_PACKETS])); |
0f5868ee BR |
375 | if (sinfo[NL80211_STA_INFO_TX_RETRIES]) |
376 | printf("\n\ttx retries:\t%u", | |
377 | nla_get_u32(sinfo[NL80211_STA_INFO_TX_RETRIES])); | |
378 | if (sinfo[NL80211_STA_INFO_TX_FAILED]) | |
379 | printf("\n\ttx failed:\t%u", | |
380 | nla_get_u32(sinfo[NL80211_STA_INFO_TX_FAILED])); | |
568c7057 AE |
381 | if (sinfo[NL80211_STA_INFO_BEACON_LOSS]) |
382 | printf("\n\tbeacon loss:\t%u", | |
383 | nla_get_u32(sinfo[NL80211_STA_INFO_BEACON_LOSS])); | |
384 | if (sinfo[NL80211_STA_INFO_BEACON_RX]) | |
385 | printf("\n\tbeacon rx:\t%llu", | |
386 | (unsigned long long)nla_get_u64(sinfo[NL80211_STA_INFO_BEACON_RX])); | |
387 | if (sinfo[NL80211_STA_INFO_RX_DROP_MISC]) | |
388 | printf("\n\trx drop misc:\t%llu", | |
389 | (unsigned long long)nla_get_u64(sinfo[NL80211_STA_INFO_RX_DROP_MISC])); | |
7d23bc2d FF |
390 | |
391 | chain = get_chain_signal(sinfo[NL80211_STA_INFO_CHAIN_SIGNAL]); | |
9cd3f1c1 | 392 | if (sinfo[NL80211_STA_INFO_SIGNAL]) |
7d23bc2d FF |
393 | printf("\n\tsignal: \t%d %sdBm", |
394 | (int8_t)nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL]), | |
395 | chain); | |
396 | ||
397 | chain = get_chain_signal(sinfo[NL80211_STA_INFO_CHAIN_SIGNAL_AVG]); | |
ba292ae9 | 398 | if (sinfo[NL80211_STA_INFO_SIGNAL_AVG]) |
7d23bc2d FF |
399 | printf("\n\tsignal avg:\t%d %sdBm", |
400 | (int8_t)nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL_AVG]), | |
401 | chain); | |
402 | ||
568c7057 AE |
403 | if (sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG]) |
404 | printf("\n\tbeacon signal avg:\t%d dBm", | |
0fc92835 | 405 | (int8_t)nla_get_u8(sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG])); |
ea3ade85 | 406 | if (sinfo[NL80211_STA_INFO_T_OFFSET]) |
568c7057 AE |
407 | printf("\n\tToffset:\t%llu us", |
408 | (unsigned long long)nla_get_u64(sinfo[NL80211_STA_INFO_T_OFFSET])); | |
9cd3f1c1 HR |
409 | |
410 | if (sinfo[NL80211_STA_INFO_TX_BITRATE]) { | |
64179590 JB |
411 | char buf[100]; |
412 | ||
e94f0201 | 413 | parse_bitrate(sinfo[NL80211_STA_INFO_TX_BITRATE], buf, sizeof(buf)); |
64179590 | 414 | printf("\n\ttx bitrate:\t%s", buf); |
9cd3f1c1 HR |
415 | } |
416 | ||
a85d693f THJ |
417 | if (sinfo[NL80211_STA_INFO_TX_DURATION]) |
418 | printf("\n\ttx duration:\t%lld us", | |
419 | (unsigned long long)nla_get_u64(sinfo[NL80211_STA_INFO_TX_DURATION])); | |
420 | ||
e94f0201 FF |
421 | if (sinfo[NL80211_STA_INFO_RX_BITRATE]) { |
422 | char buf[100]; | |
423 | ||
424 | parse_bitrate(sinfo[NL80211_STA_INFO_RX_BITRATE], buf, sizeof(buf)); | |
425 | printf("\n\trx bitrate:\t%s", buf); | |
426 | } | |
427 | ||
045c1c6f MSS |
428 | if (sinfo[NL80211_STA_INFO_RX_DURATION]) |
429 | printf("\n\trx duration:\t%lld us", | |
430 | (unsigned long long)nla_get_u64(sinfo[NL80211_STA_INFO_RX_DURATION])); | |
431 | ||
d2272671 BP |
432 | if (sinfo[NL80211_STA_INFO_ACK_SIGNAL]) |
433 | printf("\n\tlast ack signal:%d dBm", | |
434 | (int8_t)nla_get_u8(sinfo[NL80211_STA_INFO_ACK_SIGNAL])); | |
435 | ||
436 | if (sinfo[NL80211_STA_INFO_ACK_SIGNAL_AVG]) | |
437 | printf("\n\tavg ack signal:\t%d dBm", | |
438 | (int8_t)nla_get_u8(sinfo[NL80211_STA_INFO_ACK_SIGNAL_AVG])); | |
439 | ||
a85d693f THJ |
440 | if (sinfo[NL80211_STA_INFO_AIRTIME_WEIGHT]) { |
441 | printf("\n\tairtime weight: %d", nla_get_u16(sinfo[NL80211_STA_INFO_AIRTIME_WEIGHT])); | |
442 | } | |
443 | ||
cf8a2aab AQ |
444 | if (sinfo[NL80211_STA_INFO_EXPECTED_THROUGHPUT]) { |
445 | uint32_t thr; | |
446 | ||
447 | thr = nla_get_u32(sinfo[NL80211_STA_INFO_EXPECTED_THROUGHPUT]); | |
448 | /* convert in Mbps but scale by 1000 to save kbps units */ | |
449 | thr = thr * 1000 / 1024; | |
450 | ||
451 | printf("\n\texpected throughput:\t%u.%uMbps", | |
452 | thr / 1000, thr % 1000); | |
453 | } | |
454 | ||
3d1e8704 | 455 | if (sinfo[NL80211_STA_INFO_LLID]) |
fbb181fa | 456 | printf("\n\tmesh llid:\t%d", |
3d1e8704 LCC |
457 | nla_get_u16(sinfo[NL80211_STA_INFO_LLID])); |
458 | if (sinfo[NL80211_STA_INFO_PLID]) | |
fbb181fa | 459 | printf("\n\tmesh plid:\t%d", |
3d1e8704 LCC |
460 | nla_get_u16(sinfo[NL80211_STA_INFO_PLID])); |
461 | if (sinfo[NL80211_STA_INFO_PLINK_STATE]) { | |
dbaabba1 | 462 | switch (nla_get_u8(sinfo[NL80211_STA_INFO_PLINK_STATE])) { |
3d1e8704 LCC |
463 | case LISTEN: |
464 | strcpy(state_name, "LISTEN"); | |
465 | break; | |
466 | case OPN_SNT: | |
467 | strcpy(state_name, "OPN_SNT"); | |
468 | break; | |
469 | case OPN_RCVD: | |
470 | strcpy(state_name, "OPN_RCVD"); | |
471 | break; | |
472 | case CNF_RCVD: | |
473 | strcpy(state_name, "CNF_RCVD"); | |
474 | break; | |
475 | case ESTAB: | |
476 | strcpy(state_name, "ESTAB"); | |
477 | break; | |
478 | case HOLDING: | |
479 | strcpy(state_name, "HOLDING"); | |
480 | break; | |
481 | case BLOCKED: | |
482 | strcpy(state_name, "BLOCKED"); | |
483 | break; | |
484 | default: | |
485 | strcpy(state_name, "UNKNOWN"); | |
486 | break; | |
487 | } | |
fbb181fa | 488 | printf("\n\tmesh plink:\t%s", state_name); |
3d1e8704 | 489 | } |
8012ad28 MP |
490 | if (sinfo[NL80211_STA_INFO_LOCAL_PM]) { |
491 | printf("\n\tmesh local PS mode:\t"); | |
492 | print_power_mode(sinfo[NL80211_STA_INFO_LOCAL_PM]); | |
493 | } | |
494 | if (sinfo[NL80211_STA_INFO_PEER_PM]) { | |
495 | printf("\n\tmesh peer PS mode:\t"); | |
496 | print_power_mode(sinfo[NL80211_STA_INFO_PEER_PM]); | |
497 | } | |
498 | if (sinfo[NL80211_STA_INFO_NONPEER_PM]) { | |
499 | printf("\n\tmesh non-peer PS mode:\t"); | |
500 | print_power_mode(sinfo[NL80211_STA_INFO_NONPEER_PM]); | |
501 | } | |
3d1e8704 | 502 | |
b638215d HS |
503 | if (sinfo[NL80211_STA_INFO_STA_FLAGS]) { |
504 | sta_flags = (struct nl80211_sta_flag_update *) | |
505 | nla_data(sinfo[NL80211_STA_INFO_STA_FLAGS]); | |
506 | ||
507 | if (sta_flags->mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) { | |
508 | printf("\n\tauthorized:\t"); | |
509 | if (sta_flags->set & BIT(NL80211_STA_FLAG_AUTHORIZED)) | |
510 | printf("yes"); | |
511 | else | |
512 | printf("no"); | |
513 | } | |
514 | ||
515 | if (sta_flags->mask & BIT(NL80211_STA_FLAG_AUTHENTICATED)) { | |
516 | printf("\n\tauthenticated:\t"); | |
517 | if (sta_flags->set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) | |
518 | printf("yes"); | |
519 | else | |
520 | printf("no"); | |
521 | } | |
522 | ||
568c7057 AE |
523 | if (sta_flags->mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) { |
524 | printf("\n\tassociated:\t"); | |
525 | if (sta_flags->set & BIT(NL80211_STA_FLAG_ASSOCIATED)) | |
526 | printf("yes"); | |
527 | else | |
528 | printf("no"); | |
529 | } | |
530 | ||
b638215d HS |
531 | if (sta_flags->mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) { |
532 | printf("\n\tpreamble:\t"); | |
533 | if (sta_flags->set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) | |
534 | printf("short"); | |
535 | else | |
536 | printf("long"); | |
537 | } | |
538 | ||
539 | if (sta_flags->mask & BIT(NL80211_STA_FLAG_WME)) { | |
540 | printf("\n\tWMM/WME:\t"); | |
541 | if (sta_flags->set & BIT(NL80211_STA_FLAG_WME)) | |
542 | printf("yes"); | |
543 | else | |
544 | printf("no"); | |
545 | } | |
546 | ||
547 | if (sta_flags->mask & BIT(NL80211_STA_FLAG_MFP)) { | |
548 | printf("\n\tMFP:\t\t"); | |
549 | if (sta_flags->set & BIT(NL80211_STA_FLAG_MFP)) | |
550 | printf("yes"); | |
551 | else | |
552 | printf("no"); | |
553 | } | |
554 | ||
555 | if (sta_flags->mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) { | |
1a463ae3 | 556 | printf("\n\tTDLS peer:\t"); |
b638215d HS |
557 | if (sta_flags->set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
558 | printf("yes"); | |
559 | else | |
560 | printf("no"); | |
561 | } | |
562 | } | |
563 | ||
568c7057 AE |
564 | if (sinfo[NL80211_STA_INFO_TID_STATS] && arg != NULL && |
565 | !strcmp((char *)arg, "-v")) | |
566 | parse_tid_stats(sinfo[NL80211_STA_INFO_TID_STATS]); | |
567 | if (sinfo[NL80211_STA_INFO_BSS_PARAM]) | |
568 | parse_bss_param(sinfo[NL80211_STA_INFO_BSS_PARAM]); | |
087d778f AN |
569 | if (sinfo[NL80211_STA_INFO_CONNECTED_TIME]) |
570 | printf("\n\tconnected time:\t%u seconds", | |
571 | nla_get_u32(sinfo[NL80211_STA_INFO_CONNECTED_TIME])); | |
0b39c408 BG |
572 | if (sinfo[NL80211_STA_INFO_ASSOC_AT_BOOTTIME]) { |
573 | unsigned long long bt; | |
574 | bt = (unsigned long long)nla_get_u64(sinfo[NL80211_STA_INFO_ASSOC_AT_BOOTTIME]); | |
575 | printf("\n\tassociated at:\t%llu.%.3llus [boottime]", | |
576 | bt/1000000000, (bt%1000000000)/1000000); | |
577 | } | |
087d778f | 578 | |
3d1e8704 LCC |
579 | printf("\n"); |
580 | return NL_SKIP; | |
581 | } | |
582 | ||
7c37a24d | 583 | static int handle_station_get(struct nl80211_state *state, |
b1ca19a8 | 584 | struct nl_msg *msg, |
05514f95 JB |
585 | int argc, char **argv, |
586 | enum id_input id) | |
3d1e8704 | 587 | { |
3d1e8704 LCC |
588 | unsigned char mac_addr[ETH_ALEN]; |
589 | ||
b1ca19a8 | 590 | if (argc < 1) |
5e75fd04 | 591 | return 1; |
3d1e8704 LCC |
592 | |
593 | if (mac_addr_a2n(mac_addr, argv[0])) { | |
594 | fprintf(stderr, "invalid mac address\n"); | |
5e75fd04 | 595 | return 2; |
3d1e8704 LCC |
596 | } |
597 | ||
598 | argc--; | |
599 | argv++; | |
600 | ||
b1ca19a8 | 601 | if (argc) |
5e75fd04 | 602 | return 1; |
3d1e8704 LCC |
603 | |
604 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
3d1e8704 | 605 | |
34b23014 | 606 | register_handler(print_sta_handler, NULL); |
3d1e8704 | 607 | |
70391ccf | 608 | return 0; |
3d1e8704 | 609 | nla_put_failure: |
70391ccf | 610 | return -ENOBUFS; |
3d1e8704 | 611 | } |
b1ca19a8 | 612 | COMMAND(station, get, "<MAC address>", |
70cf4544 JB |
613 | NL80211_CMD_GET_STATION, 0, CIB_NETDEV, handle_station_get, |
614 | "Get information for a specific station."); | |
d738686c RM |
615 | |
616 | static int handle_station_del(struct nl80211_state *state, | |
617 | struct nl_msg *msg, | |
618 | int argc, char **argv, | |
619 | enum id_input id) | |
620 | { | |
621 | char *end; | |
622 | unsigned char mac_addr[ETH_ALEN]; | |
623 | int subtype; | |
624 | int reason_code; | |
625 | ||
626 | if (argc < 1) | |
627 | return 1; | |
628 | ||
629 | if (mac_addr_a2n(mac_addr, argv[0])) { | |
630 | fprintf(stderr, "invalid mac address\n"); | |
631 | return 2; | |
632 | } | |
633 | ||
634 | argc--; | |
635 | argv++; | |
636 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
637 | ||
638 | if (argc > 1 && strcmp(argv[0], "subtype") == 0) { | |
639 | argv++; | |
640 | argc--; | |
641 | ||
642 | subtype = strtod(argv[0], &end); | |
643 | if (*end != '\0') | |
644 | return 1; | |
645 | ||
646 | NLA_PUT_U8(msg, NL80211_ATTR_MGMT_SUBTYPE, subtype); | |
647 | argv++; | |
648 | argc--; | |
649 | } | |
650 | ||
651 | if (argc > 1 && strcmp(argv[0], "reason-code") == 0) { | |
652 | argv++; | |
653 | argc--; | |
654 | ||
655 | reason_code = strtod(argv[0], &end); | |
656 | if (*end != '\0') | |
657 | return 1; | |
658 | ||
659 | NLA_PUT_U16(msg, NL80211_ATTR_REASON_CODE, reason_code); | |
660 | argv++; | |
661 | argc--; | |
662 | } | |
663 | ||
664 | if (argc) | |
665 | return 1; | |
666 | ||
667 | register_handler(print_sta_handler, NULL); | |
668 | ||
669 | return 0; | |
670 | nla_put_failure: | |
671 | return -ENOBUFS; | |
672 | } | |
673 | COMMAND(station, del, "<MAC address> [subtype <subtype>] [reason-code <code>]", | |
674 | NL80211_CMD_DEL_STATION, 0, CIB_NETDEV, handle_station_del, | |
675 | "Remove the given station entry (use with caution!)\n" | |
676 | "Example subtype values: 0xA (disassociation), 0xC (deauthentication)"); | |
3d1e8704 | 677 | |
1633ddf7 JB |
678 | static const struct cmd *station_set_plink; |
679 | static const struct cmd *station_set_vlan; | |
8012ad28 | 680 | static const struct cmd *station_set_mesh_power_mode; |
82903243 | 681 | static const struct cmd *station_set_airtime_weight; |
5bdf11e3 | 682 | static const struct cmd *station_set_txpwr; |
1633ddf7 JB |
683 | |
684 | static const struct cmd *select_station_cmd(int argc, char **argv) | |
685 | { | |
686 | if (argc < 2) | |
687 | return NULL; | |
688 | if (strcmp(argv[1], "plink_action") == 0) | |
689 | return station_set_plink; | |
690 | if (strcmp(argv[1], "vlan") == 0) | |
691 | return station_set_vlan; | |
8012ad28 MP |
692 | if (strcmp(argv[1], "mesh_power_mode") == 0) |
693 | return station_set_mesh_power_mode; | |
82903243 THJ |
694 | if (strcmp(argv[1], "airtime_weight") == 0) |
695 | return station_set_airtime_weight; | |
5bdf11e3 ARN |
696 | if (strcmp(argv[1], "txpwr") == 0) |
697 | return station_set_txpwr; | |
1633ddf7 JB |
698 | return NULL; |
699 | } | |
700 | ||
ce0fc33a | 701 | static int handle_station_set_plink(struct nl80211_state *state, |
b1ca19a8 | 702 | struct nl_msg *msg, |
05514f95 JB |
703 | int argc, char **argv, |
704 | enum id_input id) | |
3d1e8704 | 705 | { |
3d1e8704 LCC |
706 | unsigned char plink_action; |
707 | unsigned char mac_addr[ETH_ALEN]; | |
708 | ||
b1ca19a8 | 709 | if (argc < 3) |
5e75fd04 | 710 | return 1; |
3d1e8704 LCC |
711 | |
712 | if (mac_addr_a2n(mac_addr, argv[0])) { | |
713 | fprintf(stderr, "invalid mac address\n"); | |
5e75fd04 | 714 | return 2; |
3d1e8704 LCC |
715 | } |
716 | argc--; | |
717 | argv++; | |
718 | ||
b1ca19a8 JB |
719 | if (strcmp("plink_action", argv[0]) != 0) |
720 | return 1; | |
3d1e8704 LCC |
721 | argc--; |
722 | argv++; | |
723 | ||
724 | if (strcmp("open", argv[0]) == 0) | |
ac38f8ad | 725 | plink_action = NL80211_PLINK_ACTION_OPEN; |
3d1e8704 | 726 | else if (strcmp("block", argv[0]) == 0) |
ac38f8ad | 727 | plink_action = NL80211_PLINK_ACTION_BLOCK; |
3d1e8704 LCC |
728 | else { |
729 | fprintf(stderr, "plink action not supported\n"); | |
5e75fd04 | 730 | return 2; |
3d1e8704 LCC |
731 | } |
732 | argc--; | |
733 | argv++; | |
734 | ||
b1ca19a8 | 735 | if (argc) |
5e75fd04 | 736 | return 1; |
3d1e8704 LCC |
737 | |
738 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
3d1e8704 LCC |
739 | NLA_PUT_U8(msg, NL80211_ATTR_STA_PLINK_ACTION, plink_action); |
740 | ||
70391ccf | 741 | return 0; |
3d1e8704 | 742 | nla_put_failure: |
70391ccf | 743 | return -ENOBUFS; |
3d1e8704 | 744 | } |
1633ddf7 | 745 | COMMAND_ALIAS(station, set, "<MAC address> plink_action <open|block>", |
ce0fc33a | 746 | NL80211_CMD_SET_STATION, 0, CIB_NETDEV, handle_station_set_plink, |
1633ddf7 JB |
747 | "Set mesh peer link action for this station (peer).", |
748 | select_station_cmd, station_set_plink); | |
b1ca19a8 | 749 | |
ce0fc33a | 750 | static int handle_station_set_vlan(struct nl80211_state *state, |
05514f95 JB |
751 | struct nl_msg *msg, |
752 | int argc, char **argv, | |
753 | enum id_input id) | |
ce0fc33a FF |
754 | { |
755 | unsigned char mac_addr[ETH_ALEN]; | |
756 | unsigned long sta_vlan = 0; | |
757 | char *err = NULL; | |
758 | ||
759 | if (argc < 3) | |
760 | return 1; | |
761 | ||
762 | if (mac_addr_a2n(mac_addr, argv[0])) { | |
763 | fprintf(stderr, "invalid mac address\n"); | |
764 | return 2; | |
765 | } | |
766 | argc--; | |
767 | argv++; | |
768 | ||
769 | if (strcmp("vlan", argv[0]) != 0) | |
770 | return 1; | |
771 | argc--; | |
772 | argv++; | |
773 | ||
774 | sta_vlan = strtoul(argv[0], &err, 0); | |
775 | if (err && *err) { | |
776 | fprintf(stderr, "invalid vlan id\n"); | |
777 | return 2; | |
778 | } | |
779 | argc--; | |
780 | argv++; | |
781 | ||
782 | if (argc) | |
783 | return 1; | |
784 | ||
785 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
786 | NLA_PUT_U32(msg, NL80211_ATTR_STA_VLAN, sta_vlan); | |
787 | ||
788 | return 0; | |
789 | nla_put_failure: | |
790 | return -ENOBUFS; | |
791 | } | |
1633ddf7 | 792 | COMMAND_ALIAS(station, set, "<MAC address> vlan <ifindex>", |
ce0fc33a | 793 | NL80211_CMD_SET_STATION, 0, CIB_NETDEV, handle_station_set_vlan, |
1633ddf7 JB |
794 | "Set an AP VLAN for this station.", |
795 | select_station_cmd, station_set_vlan); | |
ce0fc33a | 796 | |
8012ad28 | 797 | static int handle_station_set_mesh_power_mode(struct nl80211_state *state, |
8012ad28 MP |
798 | struct nl_msg *msg, |
799 | int argc, char **argv, | |
800 | enum id_input id) | |
801 | { | |
802 | unsigned char mesh_power_mode; | |
803 | unsigned char mac_addr[ETH_ALEN]; | |
804 | ||
805 | if (argc < 3) | |
806 | return 1; | |
807 | ||
808 | if (mac_addr_a2n(mac_addr, argv[0])) { | |
809 | fprintf(stderr, "invalid mac address\n"); | |
810 | return 2; | |
811 | } | |
812 | argc--; | |
813 | argv++; | |
814 | ||
815 | if (strcmp("mesh_power_mode", argv[0]) != 0) | |
816 | return 1; | |
817 | argc--; | |
818 | argv++; | |
819 | ||
820 | if (strcmp("active", argv[0]) == 0) | |
821 | mesh_power_mode = NL80211_MESH_POWER_ACTIVE; | |
822 | else if (strcmp("light", argv[0]) == 0) | |
823 | mesh_power_mode = NL80211_MESH_POWER_LIGHT_SLEEP; | |
824 | else if (strcmp("deep", argv[0]) == 0) | |
825 | mesh_power_mode = NL80211_MESH_POWER_DEEP_SLEEP; | |
826 | else { | |
827 | fprintf(stderr, "unknown mesh power mode\n"); | |
828 | return 2; | |
829 | } | |
830 | argc--; | |
831 | argv++; | |
832 | ||
833 | if (argc) | |
834 | return 1; | |
835 | ||
836 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
837 | NLA_PUT_U32(msg, NL80211_ATTR_LOCAL_MESH_POWER_MODE, mesh_power_mode); | |
838 | ||
839 | return 0; | |
840 | nla_put_failure: | |
841 | return -ENOBUFS; | |
842 | } | |
843 | COMMAND_ALIAS(station, set, "<MAC address> mesh_power_mode " | |
844 | "<active|light|deep>", NL80211_CMD_SET_STATION, 0, CIB_NETDEV, | |
845 | handle_station_set_mesh_power_mode, | |
846 | "Set link-specific mesh power mode for this station", | |
847 | select_station_cmd, station_set_mesh_power_mode); | |
ce0fc33a | 848 | |
82903243 THJ |
849 | static int handle_station_set_airtime_weight(struct nl80211_state *state, |
850 | struct nl_msg *msg, | |
851 | int argc, char **argv, | |
852 | enum id_input id) | |
853 | { | |
854 | unsigned char mac_addr[ETH_ALEN]; | |
855 | unsigned long airtime_weight = 0; | |
856 | char *err = NULL; | |
857 | ||
858 | if (argc < 3) | |
859 | return 1; | |
860 | ||
861 | if (mac_addr_a2n(mac_addr, argv[0])) { | |
862 | fprintf(stderr, "invalid mac address\n"); | |
863 | return 2; | |
864 | } | |
865 | argc--; | |
866 | argv++; | |
867 | ||
868 | if (strcmp("airtime_weight", argv[0]) != 0) | |
869 | return 1; | |
870 | argc--; | |
871 | argv++; | |
872 | ||
873 | airtime_weight = strtoul(argv[0], &err, 0); | |
874 | if (err && *err) { | |
875 | fprintf(stderr, "invalid airtime weight\n"); | |
876 | return 2; | |
877 | } | |
878 | argc--; | |
879 | argv++; | |
880 | ||
881 | if (argc) | |
882 | return 1; | |
883 | ||
884 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
885 | NLA_PUT_U16(msg, NL80211_ATTR_AIRTIME_WEIGHT, airtime_weight); | |
886 | ||
887 | return 0; | |
888 | nla_put_failure: | |
889 | return -ENOBUFS; | |
890 | ||
891 | } | |
892 | COMMAND_ALIAS(station, set, "<MAC address> airtime_weight <weight>", | |
893 | NL80211_CMD_SET_STATION, 0, CIB_NETDEV, handle_station_set_airtime_weight, | |
894 | "Set airtime weight for this station.", | |
895 | select_station_cmd, station_set_airtime_weight); | |
896 | ||
5bdf11e3 ARN |
897 | static int handle_station_set_txpwr(struct nl80211_state *state, |
898 | struct nl_msg *msg, | |
899 | int argc, char **argv, | |
900 | enum id_input id) | |
901 | { | |
902 | enum nl80211_tx_power_setting type; | |
903 | unsigned char mac_addr[ETH_ALEN]; | |
904 | int sta_txpwr = 0; | |
905 | char *err = NULL; | |
906 | ||
907 | if (argc != 3 && argc != 4) | |
908 | return 1; | |
909 | ||
910 | if (mac_addr_a2n(mac_addr, argv[0])) { | |
911 | fprintf(stderr, "invalid mac address\n"); | |
912 | return 2; | |
913 | } | |
914 | ||
915 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
916 | argc--; | |
917 | argv++; | |
918 | ||
919 | if (strcmp("txpwr", argv[0]) != 0) | |
920 | return 1; | |
921 | argc--; | |
922 | argv++; | |
923 | ||
924 | if (!strcmp(argv[0], "auto")) | |
925 | type = NL80211_TX_POWER_AUTOMATIC; | |
926 | else if (!strcmp(argv[0], "limit")) | |
927 | type = NL80211_TX_POWER_LIMITED; | |
928 | else { | |
929 | printf("Invalid parameter: %s\n", argv[0]); | |
930 | return 2; | |
931 | } | |
932 | ||
933 | NLA_PUT_U8(msg, NL80211_ATTR_STA_TX_POWER_SETTING, type); | |
934 | ||
935 | if (type != NL80211_TX_POWER_AUTOMATIC) { | |
936 | if (argc != 2) { | |
937 | printf("Missing TX power level argument.\n"); | |
938 | return 2; | |
939 | } | |
940 | ||
941 | argc--; | |
942 | argv++; | |
943 | ||
944 | sta_txpwr = strtoul(argv[0], &err, 0); | |
945 | NLA_PUT_U16(msg, NL80211_ATTR_STA_TX_POWER, sta_txpwr); | |
946 | } | |
947 | ||
948 | argc--; | |
949 | argv++; | |
950 | ||
951 | if (argc) | |
952 | return 1; | |
953 | ||
954 | return 0; | |
955 | nla_put_failure: | |
956 | return -ENOBUFS; | |
957 | } | |
958 | COMMAND_ALIAS(station, set, "<MAC address> txpwr <auto|limit> [<tx power dBm>]", | |
959 | NL80211_CMD_SET_STATION, 0, CIB_NETDEV, handle_station_set_txpwr, | |
960 | "Set Tx power for this station.", | |
961 | select_station_cmd, station_set_txpwr); | |
962 | ||
7c37a24d | 963 | static int handle_station_dump(struct nl80211_state *state, |
b1ca19a8 | 964 | struct nl_msg *msg, |
05514f95 JB |
965 | int argc, char **argv, |
966 | enum id_input id) | |
3d1e8704 | 967 | { |
568c7057 | 968 | register_handler(print_sta_handler, *argv); |
70391ccf | 969 | return 0; |
3d1e8704 | 970 | } |
568c7057 | 971 | COMMAND(station, dump, "[-v]", |
70cf4544 JB |
972 | NL80211_CMD_GET_STATION, NLM_F_DUMP, CIB_NETDEV, handle_station_dump, |
973 | "List all stations known, e.g. the AP on managed interfaces"); |