]>
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 JB |
103 | |
104 | static void parse_tid_stats(struct nlattr *tid_stats_attr) | |
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 AE |
117 | |
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!"); | |
123 | return; | |
124 | } | |
910792c0 | 125 | printf("\n\t\t%d", 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) | |
148 | printf("\n\tTXQs:%s", txqbuf); | |
568c7057 AE |
149 | } |
150 | ||
bcdceae1 | 151 | static void parse_bss_param(struct nlattr *bss_param_attr) |
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) | |
169 | printf("\n\tDTIM period:\t%u", nla_get_u8(info)); | |
170 | info = bss_param_info[NL80211_STA_BSS_PARAM_BEACON_INTERVAL]; | |
171 | if (info) | |
172 | printf("\n\tbeacon interval:%u", nla_get_u16(info)); | |
173 | info = bss_param_info[NL80211_STA_BSS_PARAM_CTS_PROT]; | |
174 | if (info) { | |
175 | printf("\n\tCTS protection:"); | |
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) { | |
183 | printf("\n\tshort preamble:"); | |
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) { | |
191 | printf("\n\tshort slot time:"); | |
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"); | |
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])); | |
848d97d9 JC |
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])); | |
97dd4dad JC |
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])); | |
64179590 JB |
262 | } |
263 | ||
7d23bc2d FF |
264 | static char *get_chain_signal(struct nlattr *attr_list) |
265 | { | |
266 | struct nlattr *attr; | |
267 | static char buf[64]; | |
268 | char *cur = buf; | |
269 | int i = 0, rem; | |
270 | const char *prefix; | |
271 | ||
272 | if (!attr_list) | |
273 | return ""; | |
274 | ||
275 | nla_for_each_nested(attr, attr_list, rem) { | |
276 | if (i++ > 0) | |
277 | prefix = ", "; | |
278 | else | |
279 | prefix = "["; | |
280 | ||
281 | cur += snprintf(cur, sizeof(buf) - (cur - buf), "%s%d", prefix, | |
282 | (int8_t) nla_get_u8(attr)); | |
283 | } | |
284 | ||
285 | if (i) | |
286 | snprintf(cur, sizeof(buf) - (cur - buf), "] "); | |
287 | ||
288 | return buf; | |
289 | } | |
290 | ||
3d1e8704 LCC |
291 | static int print_sta_handler(struct nl_msg *msg, void *arg) |
292 | { | |
293 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | |
294 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | |
295 | struct nlattr *sinfo[NL80211_STA_INFO_MAX + 1]; | |
296 | char mac_addr[20], state_name[10], dev[20]; | |
b638215d | 297 | struct nl80211_sta_flag_update *sta_flags; |
3d1e8704 LCC |
298 | static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = { |
299 | [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 }, | |
300 | [NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 }, | |
301 | [NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 }, | |
568c7057 AE |
302 | [NL80211_STA_INFO_RX_BYTES64] = { .type = NLA_U64 }, |
303 | [NL80211_STA_INFO_TX_BYTES64] = { .type = NLA_U64 }, | |
859677cb JB |
304 | [NL80211_STA_INFO_RX_PACKETS] = { .type = NLA_U32 }, |
305 | [NL80211_STA_INFO_TX_PACKETS] = { .type = NLA_U32 }, | |
568c7057 | 306 | [NL80211_STA_INFO_BEACON_RX] = { .type = NLA_U64}, |
9cd3f1c1 | 307 | [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 }, |
ea3ade85 | 308 | [NL80211_STA_INFO_T_OFFSET] = { .type = NLA_U64 }, |
9cd3f1c1 | 309 | [NL80211_STA_INFO_TX_BITRATE] = { .type = NLA_NESTED }, |
e94f0201 | 310 | [NL80211_STA_INFO_RX_BITRATE] = { .type = NLA_NESTED }, |
3d1e8704 LCC |
311 | [NL80211_STA_INFO_LLID] = { .type = NLA_U16 }, |
312 | [NL80211_STA_INFO_PLID] = { .type = NLA_U16 }, | |
313 | [NL80211_STA_INFO_PLINK_STATE] = { .type = NLA_U8 }, | |
0f5868ee BR |
314 | [NL80211_STA_INFO_TX_RETRIES] = { .type = NLA_U32 }, |
315 | [NL80211_STA_INFO_TX_FAILED] = { .type = NLA_U32 }, | |
568c7057 AE |
316 | [NL80211_STA_INFO_BEACON_LOSS] = { .type = NLA_U32}, |
317 | [NL80211_STA_INFO_RX_DROP_MISC] = { .type = NLA_U64}, | |
b638215d HS |
318 | [NL80211_STA_INFO_STA_FLAGS] = |
319 | { .minlen = sizeof(struct nl80211_sta_flag_update) }, | |
8012ad28 MP |
320 | [NL80211_STA_INFO_LOCAL_PM] = { .type = NLA_U32}, |
321 | [NL80211_STA_INFO_PEER_PM] = { .type = NLA_U32}, | |
322 | [NL80211_STA_INFO_NONPEER_PM] = { .type = NLA_U32}, | |
7d23bc2d FF |
323 | [NL80211_STA_INFO_CHAIN_SIGNAL] = { .type = NLA_NESTED }, |
324 | [NL80211_STA_INFO_CHAIN_SIGNAL_AVG] = { .type = NLA_NESTED }, | |
568c7057 AE |
325 | [NL80211_STA_INFO_TID_STATS] = { .type = NLA_NESTED }, |
326 | [NL80211_STA_INFO_BSS_PARAM] = { .type = NLA_NESTED }, | |
045c1c6f | 327 | [NL80211_STA_INFO_RX_DURATION] = { .type = NLA_U64 }, |
a85d693f | 328 | [NL80211_STA_INFO_TX_DURATION] = { .type = NLA_U64 }, |
d2272671 BP |
329 | [NL80211_STA_INFO_ACK_SIGNAL] = {.type = NLA_U8 }, |
330 | [NL80211_STA_INFO_ACK_SIGNAL_AVG] = { .type = NLA_U8 }, | |
3d1e8704 | 331 | }; |
7d23bc2d | 332 | char *chain; |
3708f614 BG |
333 | struct timeval now; |
334 | unsigned long long now_ms; | |
335 | ||
336 | gettimeofday(&now, NULL); | |
337 | now_ms = now.tv_sec * 1000; | |
338 | now_ms += (now.tv_usec / 1000); | |
3d1e8704 LCC |
339 | |
340 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
341 | genlmsg_attrlen(gnlh, 0), NULL); | |
342 | ||
343 | /* | |
344 | * TODO: validate the interface and mac address! | |
345 | * Otherwise, there's a race condition as soon as | |
346 | * the kernel starts sending station notifications. | |
347 | */ | |
348 | ||
349 | if (!tb[NL80211_ATTR_STA_INFO]) { | |
5fe70c0e | 350 | fprintf(stderr, "sta stats missing!\n"); |
3d1e8704 LCC |
351 | return NL_SKIP; |
352 | } | |
353 | if (nla_parse_nested(sinfo, NL80211_STA_INFO_MAX, | |
354 | tb[NL80211_ATTR_STA_INFO], | |
355 | stats_policy)) { | |
5fe70c0e | 356 | fprintf(stderr, "failed to parse nested attributes!\n"); |
3d1e8704 LCC |
357 | return NL_SKIP; |
358 | } | |
359 | ||
360 | mac_addr_n2a(mac_addr, nla_data(tb[NL80211_ATTR_MAC])); | |
361 | if_indextoname(nla_get_u32(tb[NL80211_ATTR_IFINDEX]), dev); | |
fbb181fa | 362 | printf("Station %s (on %s)", mac_addr, dev); |
3d1e8704 LCC |
363 | |
364 | if (sinfo[NL80211_STA_INFO_INACTIVE_TIME]) | |
f5c9799c | 365 | printf("\n\tinactive time:\t%u ms", |
3d1e8704 | 366 | nla_get_u32(sinfo[NL80211_STA_INFO_INACTIVE_TIME])); |
568c7057 AE |
367 | if (sinfo[NL80211_STA_INFO_RX_BYTES64]) |
368 | printf("\n\trx bytes:\t%llu", | |
369 | (unsigned long long)nla_get_u64(sinfo[NL80211_STA_INFO_RX_BYTES64])); | |
370 | else if (sinfo[NL80211_STA_INFO_RX_BYTES]) | |
f5c9799c | 371 | printf("\n\trx bytes:\t%u", |
568c7057 | 372 | nla_get_u32(sinfo[NL80211_STA_INFO_RX_BYTES])); |
859677cb | 373 | if (sinfo[NL80211_STA_INFO_RX_PACKETS]) |
f5c9799c | 374 | printf("\n\trx packets:\t%u", |
859677cb | 375 | nla_get_u32(sinfo[NL80211_STA_INFO_RX_PACKETS])); |
568c7057 AE |
376 | if (sinfo[NL80211_STA_INFO_TX_BYTES64]) |
377 | printf("\n\ttx bytes:\t%llu", | |
378 | (unsigned long long)nla_get_u64(sinfo[NL80211_STA_INFO_TX_BYTES64])); | |
379 | else if (sinfo[NL80211_STA_INFO_TX_BYTES]) | |
f5c9799c | 380 | printf("\n\ttx bytes:\t%u", |
568c7057 | 381 | nla_get_u32(sinfo[NL80211_STA_INFO_TX_BYTES])); |
859677cb | 382 | if (sinfo[NL80211_STA_INFO_TX_PACKETS]) |
f5c9799c | 383 | printf("\n\ttx packets:\t%u", |
859677cb | 384 | nla_get_u32(sinfo[NL80211_STA_INFO_TX_PACKETS])); |
0f5868ee BR |
385 | if (sinfo[NL80211_STA_INFO_TX_RETRIES]) |
386 | printf("\n\ttx retries:\t%u", | |
387 | nla_get_u32(sinfo[NL80211_STA_INFO_TX_RETRIES])); | |
388 | if (sinfo[NL80211_STA_INFO_TX_FAILED]) | |
389 | printf("\n\ttx failed:\t%u", | |
390 | nla_get_u32(sinfo[NL80211_STA_INFO_TX_FAILED])); | |
568c7057 AE |
391 | if (sinfo[NL80211_STA_INFO_BEACON_LOSS]) |
392 | printf("\n\tbeacon loss:\t%u", | |
393 | nla_get_u32(sinfo[NL80211_STA_INFO_BEACON_LOSS])); | |
394 | if (sinfo[NL80211_STA_INFO_BEACON_RX]) | |
395 | printf("\n\tbeacon rx:\t%llu", | |
396 | (unsigned long long)nla_get_u64(sinfo[NL80211_STA_INFO_BEACON_RX])); | |
397 | if (sinfo[NL80211_STA_INFO_RX_DROP_MISC]) | |
398 | printf("\n\trx drop misc:\t%llu", | |
399 | (unsigned long long)nla_get_u64(sinfo[NL80211_STA_INFO_RX_DROP_MISC])); | |
7d23bc2d FF |
400 | |
401 | chain = get_chain_signal(sinfo[NL80211_STA_INFO_CHAIN_SIGNAL]); | |
9cd3f1c1 | 402 | if (sinfo[NL80211_STA_INFO_SIGNAL]) |
7d23bc2d FF |
403 | printf("\n\tsignal: \t%d %sdBm", |
404 | (int8_t)nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL]), | |
405 | chain); | |
406 | ||
407 | chain = get_chain_signal(sinfo[NL80211_STA_INFO_CHAIN_SIGNAL_AVG]); | |
ba292ae9 | 408 | if (sinfo[NL80211_STA_INFO_SIGNAL_AVG]) |
7d23bc2d FF |
409 | printf("\n\tsignal avg:\t%d %sdBm", |
410 | (int8_t)nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL_AVG]), | |
411 | chain); | |
412 | ||
568c7057 AE |
413 | if (sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG]) |
414 | printf("\n\tbeacon signal avg:\t%d dBm", | |
0fc92835 | 415 | (int8_t)nla_get_u8(sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG])); |
ea3ade85 | 416 | if (sinfo[NL80211_STA_INFO_T_OFFSET]) |
568c7057 AE |
417 | printf("\n\tToffset:\t%llu us", |
418 | (unsigned long long)nla_get_u64(sinfo[NL80211_STA_INFO_T_OFFSET])); | |
9cd3f1c1 HR |
419 | |
420 | if (sinfo[NL80211_STA_INFO_TX_BITRATE]) { | |
64179590 JB |
421 | char buf[100]; |
422 | ||
e94f0201 | 423 | parse_bitrate(sinfo[NL80211_STA_INFO_TX_BITRATE], buf, sizeof(buf)); |
64179590 | 424 | printf("\n\ttx bitrate:\t%s", buf); |
9cd3f1c1 HR |
425 | } |
426 | ||
a85d693f THJ |
427 | if (sinfo[NL80211_STA_INFO_TX_DURATION]) |
428 | printf("\n\ttx duration:\t%lld us", | |
429 | (unsigned long long)nla_get_u64(sinfo[NL80211_STA_INFO_TX_DURATION])); | |
430 | ||
e94f0201 FF |
431 | if (sinfo[NL80211_STA_INFO_RX_BITRATE]) { |
432 | char buf[100]; | |
433 | ||
434 | parse_bitrate(sinfo[NL80211_STA_INFO_RX_BITRATE], buf, sizeof(buf)); | |
435 | printf("\n\trx bitrate:\t%s", buf); | |
436 | } | |
437 | ||
045c1c6f MSS |
438 | if (sinfo[NL80211_STA_INFO_RX_DURATION]) |
439 | printf("\n\trx duration:\t%lld us", | |
440 | (unsigned long long)nla_get_u64(sinfo[NL80211_STA_INFO_RX_DURATION])); | |
441 | ||
d2272671 BP |
442 | if (sinfo[NL80211_STA_INFO_ACK_SIGNAL]) |
443 | printf("\n\tlast ack signal:%d dBm", | |
444 | (int8_t)nla_get_u8(sinfo[NL80211_STA_INFO_ACK_SIGNAL])); | |
445 | ||
446 | if (sinfo[NL80211_STA_INFO_ACK_SIGNAL_AVG]) | |
447 | printf("\n\tavg ack signal:\t%d dBm", | |
448 | (int8_t)nla_get_u8(sinfo[NL80211_STA_INFO_ACK_SIGNAL_AVG])); | |
449 | ||
a85d693f THJ |
450 | if (sinfo[NL80211_STA_INFO_AIRTIME_WEIGHT]) { |
451 | printf("\n\tairtime weight: %d", nla_get_u16(sinfo[NL80211_STA_INFO_AIRTIME_WEIGHT])); | |
452 | } | |
453 | ||
cf8a2aab AQ |
454 | if (sinfo[NL80211_STA_INFO_EXPECTED_THROUGHPUT]) { |
455 | uint32_t thr; | |
456 | ||
457 | thr = nla_get_u32(sinfo[NL80211_STA_INFO_EXPECTED_THROUGHPUT]); | |
458 | /* convert in Mbps but scale by 1000 to save kbps units */ | |
459 | thr = thr * 1000 / 1024; | |
460 | ||
461 | printf("\n\texpected throughput:\t%u.%uMbps", | |
462 | thr / 1000, thr % 1000); | |
463 | } | |
464 | ||
3d1e8704 | 465 | if (sinfo[NL80211_STA_INFO_LLID]) |
fbb181fa | 466 | printf("\n\tmesh llid:\t%d", |
3d1e8704 LCC |
467 | nla_get_u16(sinfo[NL80211_STA_INFO_LLID])); |
468 | if (sinfo[NL80211_STA_INFO_PLID]) | |
fbb181fa | 469 | printf("\n\tmesh plid:\t%d", |
3d1e8704 LCC |
470 | nla_get_u16(sinfo[NL80211_STA_INFO_PLID])); |
471 | if (sinfo[NL80211_STA_INFO_PLINK_STATE]) { | |
dbaabba1 | 472 | switch (nla_get_u8(sinfo[NL80211_STA_INFO_PLINK_STATE])) { |
3d1e8704 LCC |
473 | case LISTEN: |
474 | strcpy(state_name, "LISTEN"); | |
475 | break; | |
476 | case OPN_SNT: | |
477 | strcpy(state_name, "OPN_SNT"); | |
478 | break; | |
479 | case OPN_RCVD: | |
480 | strcpy(state_name, "OPN_RCVD"); | |
481 | break; | |
482 | case CNF_RCVD: | |
483 | strcpy(state_name, "CNF_RCVD"); | |
484 | break; | |
485 | case ESTAB: | |
486 | strcpy(state_name, "ESTAB"); | |
487 | break; | |
488 | case HOLDING: | |
489 | strcpy(state_name, "HOLDING"); | |
490 | break; | |
491 | case BLOCKED: | |
492 | strcpy(state_name, "BLOCKED"); | |
493 | break; | |
494 | default: | |
495 | strcpy(state_name, "UNKNOWN"); | |
496 | break; | |
497 | } | |
fbb181fa | 498 | printf("\n\tmesh plink:\t%s", state_name); |
3d1e8704 | 499 | } |
8012ad28 MP |
500 | if (sinfo[NL80211_STA_INFO_LOCAL_PM]) { |
501 | printf("\n\tmesh local PS mode:\t"); | |
502 | print_power_mode(sinfo[NL80211_STA_INFO_LOCAL_PM]); | |
503 | } | |
504 | if (sinfo[NL80211_STA_INFO_PEER_PM]) { | |
505 | printf("\n\tmesh peer PS mode:\t"); | |
506 | print_power_mode(sinfo[NL80211_STA_INFO_PEER_PM]); | |
507 | } | |
508 | if (sinfo[NL80211_STA_INFO_NONPEER_PM]) { | |
509 | printf("\n\tmesh non-peer PS mode:\t"); | |
510 | print_power_mode(sinfo[NL80211_STA_INFO_NONPEER_PM]); | |
511 | } | |
3d1e8704 | 512 | |
b638215d HS |
513 | if (sinfo[NL80211_STA_INFO_STA_FLAGS]) { |
514 | sta_flags = (struct nl80211_sta_flag_update *) | |
515 | nla_data(sinfo[NL80211_STA_INFO_STA_FLAGS]); | |
516 | ||
517 | if (sta_flags->mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) { | |
518 | printf("\n\tauthorized:\t"); | |
519 | if (sta_flags->set & BIT(NL80211_STA_FLAG_AUTHORIZED)) | |
520 | printf("yes"); | |
521 | else | |
522 | printf("no"); | |
523 | } | |
524 | ||
525 | if (sta_flags->mask & BIT(NL80211_STA_FLAG_AUTHENTICATED)) { | |
526 | printf("\n\tauthenticated:\t"); | |
527 | if (sta_flags->set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) | |
528 | printf("yes"); | |
529 | else | |
530 | printf("no"); | |
531 | } | |
532 | ||
568c7057 AE |
533 | if (sta_flags->mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) { |
534 | printf("\n\tassociated:\t"); | |
535 | if (sta_flags->set & BIT(NL80211_STA_FLAG_ASSOCIATED)) | |
536 | printf("yes"); | |
537 | else | |
538 | printf("no"); | |
539 | } | |
540 | ||
b638215d HS |
541 | if (sta_flags->mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) { |
542 | printf("\n\tpreamble:\t"); | |
543 | if (sta_flags->set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) | |
544 | printf("short"); | |
545 | else | |
546 | printf("long"); | |
547 | } | |
548 | ||
549 | if (sta_flags->mask & BIT(NL80211_STA_FLAG_WME)) { | |
550 | printf("\n\tWMM/WME:\t"); | |
551 | if (sta_flags->set & BIT(NL80211_STA_FLAG_WME)) | |
552 | printf("yes"); | |
553 | else | |
554 | printf("no"); | |
555 | } | |
556 | ||
557 | if (sta_flags->mask & BIT(NL80211_STA_FLAG_MFP)) { | |
558 | printf("\n\tMFP:\t\t"); | |
559 | if (sta_flags->set & BIT(NL80211_STA_FLAG_MFP)) | |
560 | printf("yes"); | |
561 | else | |
562 | printf("no"); | |
563 | } | |
564 | ||
565 | if (sta_flags->mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) { | |
1a463ae3 | 566 | printf("\n\tTDLS peer:\t"); |
b638215d HS |
567 | if (sta_flags->set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
568 | printf("yes"); | |
569 | else | |
570 | printf("no"); | |
571 | } | |
572 | } | |
573 | ||
568c7057 AE |
574 | if (sinfo[NL80211_STA_INFO_TID_STATS] && arg != NULL && |
575 | !strcmp((char *)arg, "-v")) | |
576 | parse_tid_stats(sinfo[NL80211_STA_INFO_TID_STATS]); | |
577 | if (sinfo[NL80211_STA_INFO_BSS_PARAM]) | |
578 | parse_bss_param(sinfo[NL80211_STA_INFO_BSS_PARAM]); | |
087d778f AN |
579 | if (sinfo[NL80211_STA_INFO_CONNECTED_TIME]) |
580 | printf("\n\tconnected time:\t%u seconds", | |
581 | nla_get_u32(sinfo[NL80211_STA_INFO_CONNECTED_TIME])); | |
0b39c408 BG |
582 | if (sinfo[NL80211_STA_INFO_ASSOC_AT_BOOTTIME]) { |
583 | unsigned long long bt; | |
3708f614 BG |
584 | struct timespec now_ts; |
585 | unsigned long long boot_ns; | |
586 | unsigned long long assoc_at_ms; | |
587 | ||
588 | clock_gettime(CLOCK_BOOTTIME, &now_ts); | |
589 | boot_ns = now_ts.tv_sec * 1000000000; | |
590 | boot_ns += now_ts.tv_nsec; | |
591 | ||
0b39c408 | 592 | bt = (unsigned long long)nla_get_u64(sinfo[NL80211_STA_INFO_ASSOC_AT_BOOTTIME]); |
3708f614 | 593 | printf("\n\tassociated at [boottime]:\t%llu.%.3llus", |
0b39c408 | 594 | bt/1000000000, (bt%1000000000)/1000000); |
3708f614 BG |
595 | assoc_at_ms = now_ms - ((boot_ns - bt) / 1000000); |
596 | printf("\n\tassociated at:\t%llu ms", assoc_at_ms); | |
0b39c408 | 597 | } |
087d778f | 598 | |
3708f614 | 599 | printf("\n\tcurrent time:\t%llu ms\n", now_ms); |
3d1e8704 LCC |
600 | return NL_SKIP; |
601 | } | |
602 | ||
7c37a24d | 603 | static int handle_station_get(struct nl80211_state *state, |
b1ca19a8 | 604 | struct nl_msg *msg, |
05514f95 JB |
605 | int argc, char **argv, |
606 | enum id_input id) | |
3d1e8704 | 607 | { |
3d1e8704 LCC |
608 | unsigned char mac_addr[ETH_ALEN]; |
609 | ||
b1ca19a8 | 610 | if (argc < 1) |
5e75fd04 | 611 | return 1; |
3d1e8704 LCC |
612 | |
613 | if (mac_addr_a2n(mac_addr, argv[0])) { | |
614 | fprintf(stderr, "invalid mac address\n"); | |
5e75fd04 | 615 | return 2; |
3d1e8704 LCC |
616 | } |
617 | ||
618 | argc--; | |
619 | argv++; | |
620 | ||
b1ca19a8 | 621 | if (argc) |
5e75fd04 | 622 | return 1; |
3d1e8704 LCC |
623 | |
624 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
3d1e8704 | 625 | |
34b23014 | 626 | register_handler(print_sta_handler, NULL); |
3d1e8704 | 627 | |
70391ccf | 628 | return 0; |
3d1e8704 | 629 | nla_put_failure: |
70391ccf | 630 | return -ENOBUFS; |
3d1e8704 | 631 | } |
b1ca19a8 | 632 | COMMAND(station, get, "<MAC address>", |
70cf4544 JB |
633 | NL80211_CMD_GET_STATION, 0, CIB_NETDEV, handle_station_get, |
634 | "Get information for a specific station."); | |
d738686c RM |
635 | |
636 | static int handle_station_del(struct nl80211_state *state, | |
637 | struct nl_msg *msg, | |
638 | int argc, char **argv, | |
639 | enum id_input id) | |
640 | { | |
641 | char *end; | |
642 | unsigned char mac_addr[ETH_ALEN]; | |
643 | int subtype; | |
644 | int reason_code; | |
645 | ||
646 | if (argc < 1) | |
647 | return 1; | |
648 | ||
649 | if (mac_addr_a2n(mac_addr, argv[0])) { | |
650 | fprintf(stderr, "invalid mac address\n"); | |
651 | return 2; | |
652 | } | |
653 | ||
654 | argc--; | |
655 | argv++; | |
656 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
657 | ||
658 | if (argc > 1 && strcmp(argv[0], "subtype") == 0) { | |
659 | argv++; | |
660 | argc--; | |
661 | ||
662 | subtype = strtod(argv[0], &end); | |
663 | if (*end != '\0') | |
664 | return 1; | |
665 | ||
666 | NLA_PUT_U8(msg, NL80211_ATTR_MGMT_SUBTYPE, subtype); | |
667 | argv++; | |
668 | argc--; | |
669 | } | |
670 | ||
671 | if (argc > 1 && strcmp(argv[0], "reason-code") == 0) { | |
672 | argv++; | |
673 | argc--; | |
674 | ||
675 | reason_code = strtod(argv[0], &end); | |
676 | if (*end != '\0') | |
677 | return 1; | |
678 | ||
679 | NLA_PUT_U16(msg, NL80211_ATTR_REASON_CODE, reason_code); | |
680 | argv++; | |
681 | argc--; | |
682 | } | |
683 | ||
684 | if (argc) | |
685 | return 1; | |
686 | ||
687 | register_handler(print_sta_handler, NULL); | |
688 | ||
689 | return 0; | |
690 | nla_put_failure: | |
691 | return -ENOBUFS; | |
692 | } | |
693 | COMMAND(station, del, "<MAC address> [subtype <subtype>] [reason-code <code>]", | |
694 | NL80211_CMD_DEL_STATION, 0, CIB_NETDEV, handle_station_del, | |
695 | "Remove the given station entry (use with caution!)\n" | |
696 | "Example subtype values: 0xA (disassociation), 0xC (deauthentication)"); | |
3d1e8704 | 697 | |
1633ddf7 JB |
698 | static const struct cmd *station_set_plink; |
699 | static const struct cmd *station_set_vlan; | |
8012ad28 | 700 | static const struct cmd *station_set_mesh_power_mode; |
82903243 | 701 | static const struct cmd *station_set_airtime_weight; |
5bdf11e3 | 702 | static const struct cmd *station_set_txpwr; |
1633ddf7 JB |
703 | |
704 | static const struct cmd *select_station_cmd(int argc, char **argv) | |
705 | { | |
706 | if (argc < 2) | |
707 | return NULL; | |
708 | if (strcmp(argv[1], "plink_action") == 0) | |
709 | return station_set_plink; | |
710 | if (strcmp(argv[1], "vlan") == 0) | |
711 | return station_set_vlan; | |
8012ad28 MP |
712 | if (strcmp(argv[1], "mesh_power_mode") == 0) |
713 | return station_set_mesh_power_mode; | |
82903243 THJ |
714 | if (strcmp(argv[1], "airtime_weight") == 0) |
715 | return station_set_airtime_weight; | |
5bdf11e3 ARN |
716 | if (strcmp(argv[1], "txpwr") == 0) |
717 | return station_set_txpwr; | |
1633ddf7 JB |
718 | return NULL; |
719 | } | |
720 | ||
ce0fc33a | 721 | static int handle_station_set_plink(struct nl80211_state *state, |
b1ca19a8 | 722 | struct nl_msg *msg, |
05514f95 JB |
723 | int argc, char **argv, |
724 | enum id_input id) | |
3d1e8704 | 725 | { |
3d1e8704 LCC |
726 | unsigned char plink_action; |
727 | unsigned char mac_addr[ETH_ALEN]; | |
728 | ||
b1ca19a8 | 729 | if (argc < 3) |
5e75fd04 | 730 | return 1; |
3d1e8704 LCC |
731 | |
732 | if (mac_addr_a2n(mac_addr, argv[0])) { | |
733 | fprintf(stderr, "invalid mac address\n"); | |
5e75fd04 | 734 | return 2; |
3d1e8704 LCC |
735 | } |
736 | argc--; | |
737 | argv++; | |
738 | ||
b1ca19a8 JB |
739 | if (strcmp("plink_action", argv[0]) != 0) |
740 | return 1; | |
3d1e8704 LCC |
741 | argc--; |
742 | argv++; | |
743 | ||
744 | if (strcmp("open", argv[0]) == 0) | |
ac38f8ad | 745 | plink_action = NL80211_PLINK_ACTION_OPEN; |
3d1e8704 | 746 | else if (strcmp("block", argv[0]) == 0) |
ac38f8ad | 747 | plink_action = NL80211_PLINK_ACTION_BLOCK; |
3d1e8704 LCC |
748 | else { |
749 | fprintf(stderr, "plink action not supported\n"); | |
5e75fd04 | 750 | return 2; |
3d1e8704 LCC |
751 | } |
752 | argc--; | |
753 | argv++; | |
754 | ||
b1ca19a8 | 755 | if (argc) |
5e75fd04 | 756 | return 1; |
3d1e8704 LCC |
757 | |
758 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
3d1e8704 LCC |
759 | NLA_PUT_U8(msg, NL80211_ATTR_STA_PLINK_ACTION, plink_action); |
760 | ||
70391ccf | 761 | return 0; |
3d1e8704 | 762 | nla_put_failure: |
70391ccf | 763 | return -ENOBUFS; |
3d1e8704 | 764 | } |
1633ddf7 | 765 | COMMAND_ALIAS(station, set, "<MAC address> plink_action <open|block>", |
ce0fc33a | 766 | NL80211_CMD_SET_STATION, 0, CIB_NETDEV, handle_station_set_plink, |
1633ddf7 JB |
767 | "Set mesh peer link action for this station (peer).", |
768 | select_station_cmd, station_set_plink); | |
b1ca19a8 | 769 | |
ce0fc33a | 770 | static int handle_station_set_vlan(struct nl80211_state *state, |
05514f95 JB |
771 | struct nl_msg *msg, |
772 | int argc, char **argv, | |
773 | enum id_input id) | |
ce0fc33a FF |
774 | { |
775 | unsigned char mac_addr[ETH_ALEN]; | |
776 | unsigned long sta_vlan = 0; | |
777 | char *err = NULL; | |
778 | ||
779 | if (argc < 3) | |
780 | return 1; | |
781 | ||
782 | if (mac_addr_a2n(mac_addr, argv[0])) { | |
783 | fprintf(stderr, "invalid mac address\n"); | |
784 | return 2; | |
785 | } | |
786 | argc--; | |
787 | argv++; | |
788 | ||
789 | if (strcmp("vlan", argv[0]) != 0) | |
790 | return 1; | |
791 | argc--; | |
792 | argv++; | |
793 | ||
794 | sta_vlan = strtoul(argv[0], &err, 0); | |
795 | if (err && *err) { | |
796 | fprintf(stderr, "invalid vlan id\n"); | |
797 | return 2; | |
798 | } | |
799 | argc--; | |
800 | argv++; | |
801 | ||
802 | if (argc) | |
803 | return 1; | |
804 | ||
805 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
806 | NLA_PUT_U32(msg, NL80211_ATTR_STA_VLAN, sta_vlan); | |
807 | ||
808 | return 0; | |
809 | nla_put_failure: | |
810 | return -ENOBUFS; | |
811 | } | |
1633ddf7 | 812 | COMMAND_ALIAS(station, set, "<MAC address> vlan <ifindex>", |
ce0fc33a | 813 | NL80211_CMD_SET_STATION, 0, CIB_NETDEV, handle_station_set_vlan, |
1633ddf7 JB |
814 | "Set an AP VLAN for this station.", |
815 | select_station_cmd, station_set_vlan); | |
ce0fc33a | 816 | |
8012ad28 | 817 | static int handle_station_set_mesh_power_mode(struct nl80211_state *state, |
8012ad28 MP |
818 | struct nl_msg *msg, |
819 | int argc, char **argv, | |
820 | enum id_input id) | |
821 | { | |
822 | unsigned char mesh_power_mode; | |
823 | unsigned char mac_addr[ETH_ALEN]; | |
824 | ||
825 | if (argc < 3) | |
826 | return 1; | |
827 | ||
828 | if (mac_addr_a2n(mac_addr, argv[0])) { | |
829 | fprintf(stderr, "invalid mac address\n"); | |
830 | return 2; | |
831 | } | |
832 | argc--; | |
833 | argv++; | |
834 | ||
835 | if (strcmp("mesh_power_mode", argv[0]) != 0) | |
836 | return 1; | |
837 | argc--; | |
838 | argv++; | |
839 | ||
840 | if (strcmp("active", argv[0]) == 0) | |
841 | mesh_power_mode = NL80211_MESH_POWER_ACTIVE; | |
842 | else if (strcmp("light", argv[0]) == 0) | |
843 | mesh_power_mode = NL80211_MESH_POWER_LIGHT_SLEEP; | |
844 | else if (strcmp("deep", argv[0]) == 0) | |
845 | mesh_power_mode = NL80211_MESH_POWER_DEEP_SLEEP; | |
846 | else { | |
847 | fprintf(stderr, "unknown mesh power mode\n"); | |
848 | return 2; | |
849 | } | |
850 | argc--; | |
851 | argv++; | |
852 | ||
853 | if (argc) | |
854 | return 1; | |
855 | ||
856 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
857 | NLA_PUT_U32(msg, NL80211_ATTR_LOCAL_MESH_POWER_MODE, mesh_power_mode); | |
858 | ||
859 | return 0; | |
860 | nla_put_failure: | |
861 | return -ENOBUFS; | |
862 | } | |
863 | COMMAND_ALIAS(station, set, "<MAC address> mesh_power_mode " | |
864 | "<active|light|deep>", NL80211_CMD_SET_STATION, 0, CIB_NETDEV, | |
865 | handle_station_set_mesh_power_mode, | |
866 | "Set link-specific mesh power mode for this station", | |
867 | select_station_cmd, station_set_mesh_power_mode); | |
ce0fc33a | 868 | |
82903243 THJ |
869 | static int handle_station_set_airtime_weight(struct nl80211_state *state, |
870 | struct nl_msg *msg, | |
871 | int argc, char **argv, | |
872 | enum id_input id) | |
873 | { | |
874 | unsigned char mac_addr[ETH_ALEN]; | |
875 | unsigned long airtime_weight = 0; | |
876 | char *err = NULL; | |
877 | ||
878 | if (argc < 3) | |
879 | return 1; | |
880 | ||
881 | if (mac_addr_a2n(mac_addr, argv[0])) { | |
882 | fprintf(stderr, "invalid mac address\n"); | |
883 | return 2; | |
884 | } | |
885 | argc--; | |
886 | argv++; | |
887 | ||
888 | if (strcmp("airtime_weight", argv[0]) != 0) | |
889 | return 1; | |
890 | argc--; | |
891 | argv++; | |
892 | ||
893 | airtime_weight = strtoul(argv[0], &err, 0); | |
894 | if (err && *err) { | |
895 | fprintf(stderr, "invalid airtime weight\n"); | |
896 | return 2; | |
897 | } | |
898 | argc--; | |
899 | argv++; | |
900 | ||
901 | if (argc) | |
902 | return 1; | |
903 | ||
904 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
905 | NLA_PUT_U16(msg, NL80211_ATTR_AIRTIME_WEIGHT, airtime_weight); | |
906 | ||
907 | return 0; | |
908 | nla_put_failure: | |
909 | return -ENOBUFS; | |
910 | ||
911 | } | |
912 | COMMAND_ALIAS(station, set, "<MAC address> airtime_weight <weight>", | |
913 | NL80211_CMD_SET_STATION, 0, CIB_NETDEV, handle_station_set_airtime_weight, | |
914 | "Set airtime weight for this station.", | |
915 | select_station_cmd, station_set_airtime_weight); | |
916 | ||
5bdf11e3 ARN |
917 | static int handle_station_set_txpwr(struct nl80211_state *state, |
918 | struct nl_msg *msg, | |
919 | int argc, char **argv, | |
920 | enum id_input id) | |
921 | { | |
922 | enum nl80211_tx_power_setting type; | |
923 | unsigned char mac_addr[ETH_ALEN]; | |
924 | int sta_txpwr = 0; | |
925 | char *err = NULL; | |
926 | ||
927 | if (argc != 3 && argc != 4) | |
928 | return 1; | |
929 | ||
930 | if (mac_addr_a2n(mac_addr, argv[0])) { | |
931 | fprintf(stderr, "invalid mac address\n"); | |
932 | return 2; | |
933 | } | |
934 | ||
935 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
936 | argc--; | |
937 | argv++; | |
938 | ||
939 | if (strcmp("txpwr", argv[0]) != 0) | |
940 | return 1; | |
941 | argc--; | |
942 | argv++; | |
943 | ||
944 | if (!strcmp(argv[0], "auto")) | |
945 | type = NL80211_TX_POWER_AUTOMATIC; | |
946 | else if (!strcmp(argv[0], "limit")) | |
947 | type = NL80211_TX_POWER_LIMITED; | |
948 | else { | |
949 | printf("Invalid parameter: %s\n", argv[0]); | |
950 | return 2; | |
951 | } | |
952 | ||
953 | NLA_PUT_U8(msg, NL80211_ATTR_STA_TX_POWER_SETTING, type); | |
954 | ||
955 | if (type != NL80211_TX_POWER_AUTOMATIC) { | |
956 | if (argc != 2) { | |
957 | printf("Missing TX power level argument.\n"); | |
958 | return 2; | |
959 | } | |
960 | ||
961 | argc--; | |
962 | argv++; | |
963 | ||
964 | sta_txpwr = strtoul(argv[0], &err, 0); | |
965 | NLA_PUT_U16(msg, NL80211_ATTR_STA_TX_POWER, sta_txpwr); | |
966 | } | |
967 | ||
968 | argc--; | |
969 | argv++; | |
970 | ||
971 | if (argc) | |
972 | return 1; | |
973 | ||
974 | return 0; | |
975 | nla_put_failure: | |
976 | return -ENOBUFS; | |
977 | } | |
978 | COMMAND_ALIAS(station, set, "<MAC address> txpwr <auto|limit> [<tx power dBm>]", | |
979 | NL80211_CMD_SET_STATION, 0, CIB_NETDEV, handle_station_set_txpwr, | |
980 | "Set Tx power for this station.", | |
981 | select_station_cmd, station_set_txpwr); | |
982 | ||
7c37a24d | 983 | static int handle_station_dump(struct nl80211_state *state, |
b1ca19a8 | 984 | struct nl_msg *msg, |
05514f95 JB |
985 | int argc, char **argv, |
986 | enum id_input id) | |
3d1e8704 | 987 | { |
568c7057 | 988 | register_handler(print_sta_handler, *argv); |
70391ccf | 989 | return 0; |
3d1e8704 | 990 | } |
568c7057 | 991 | COMMAND(station, dump, "[-v]", |
70cf4544 JB |
992 | NL80211_CMD_GET_STATION, NLM_F_DUMP, CIB_NETDEV, handle_station_dump, |
993 | "List all stations known, e.g. the AP on managed interfaces"); |