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>
26 static void print_power_mode(struct nlattr
*a
)
28 enum nl80211_mesh_power_mode pm
= nla_get_u32(a
);
31 case NL80211_MESH_POWER_ACTIVE
:
34 case NL80211_MESH_POWER_LIGHT_SLEEP
:
35 printf("LIGHT SLEEP");
37 case NL80211_MESH_POWER_DEEP_SLEEP
:
46 void parse_tid_stats(struct nlattr
*tid_stats_attr
)
48 struct nlattr
*stats_info
[NL80211_TID_STATS_MAX
+ 1], *tidattr
, *info
;
49 static struct nla_policy stats_policy
[NL80211_TID_STATS_MAX
+ 1] = {
50 [NL80211_TID_STATS_RX_MSDU
] = { .type
= NLA_U64
},
51 [NL80211_TID_STATS_TX_MSDU
] = { .type
= NLA_U64
},
52 [NL80211_TID_STATS_TX_MSDU_RETRIES
] = { .type
= NLA_U64
},
53 [NL80211_TID_STATS_TX_MSDU_FAILED
] = { .type
= NLA_U64
},
57 printf("\n\tMSDU:\n\t\tTID\trx\ttx\ttx retries\ttx failed");
58 nla_for_each_nested(tidattr
, tid_stats_attr
, rem
) {
59 if (nla_parse_nested(stats_info
, NL80211_TID_STATS_MAX
,
60 tidattr
, stats_policy
)) {
61 printf("failed to parse nested stats attributes!");
64 printf("\n\t\t%d", i
++);
65 info
= stats_info
[NL80211_TID_STATS_RX_MSDU
];
67 printf("\t%llu", (unsigned long long)nla_get_u64(info
));
68 info
= stats_info
[NL80211_TID_STATS_TX_MSDU
];
70 printf("\t%llu", (unsigned long long)nla_get_u64(info
));
71 info
= stats_info
[NL80211_TID_STATS_TX_MSDU_RETRIES
];
73 printf("\t%llu", (unsigned long long)nla_get_u64(info
));
74 info
= stats_info
[NL80211_TID_STATS_TX_MSDU_FAILED
];
76 printf("\t\t%llu", (unsigned long long)nla_get_u64(info
));
80 void parse_bss_param(struct nlattr
*bss_param_attr
)
82 struct nlattr
*bss_param_info
[NL80211_STA_BSS_PARAM_MAX
+ 1], *info
;
83 static struct nla_policy bss_poilcy
[NL80211_STA_BSS_PARAM_MAX
+ 1] = {
84 [NL80211_STA_BSS_PARAM_CTS_PROT
] = { .type
= NLA_FLAG
},
85 [NL80211_STA_BSS_PARAM_SHORT_PREAMBLE
] = { .type
= NLA_FLAG
},
86 [NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME
] = { .type
= NLA_FLAG
},
87 [NL80211_STA_BSS_PARAM_DTIM_PERIOD
] = { .type
= NLA_U8
},
88 [NL80211_STA_BSS_PARAM_BEACON_INTERVAL
] = { .type
= NLA_U16
},
91 if (nla_parse_nested(bss_param_info
, NL80211_STA_BSS_PARAM_MAX
,
92 bss_param_attr
, bss_poilcy
)) {
93 printf("failed to parse nested bss param attributes!");
96 info
= bss_param_info
[NL80211_STA_BSS_PARAM_DTIM_PERIOD
];
98 printf("\n\tDTIM period:\t%u", nla_get_u8(info
));
99 info
= bss_param_info
[NL80211_STA_BSS_PARAM_BEACON_INTERVAL
];
101 printf("\n\tbeacon interval:%u", nla_get_u16(info
));
102 info
= bss_param_info
[NL80211_STA_BSS_PARAM_CTS_PROT
];
104 printf("\n\tCTS protection:");
105 if (nla_get_u16(info
))
110 info
= bss_param_info
[NL80211_STA_BSS_PARAM_SHORT_PREAMBLE
];
112 printf("\n\tshort preamble:");
113 if (nla_get_u16(info
))
118 info
= bss_param_info
[NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME
];
120 printf("\n\tshort slot time:");
121 if (nla_get_u16(info
))
128 void parse_bitrate(struct nlattr
*bitrate_attr
, char *buf
, int buflen
)
132 struct nlattr
*rinfo
[NL80211_RATE_INFO_MAX
+ 1];
133 static struct nla_policy rate_policy
[NL80211_RATE_INFO_MAX
+ 1] = {
134 [NL80211_RATE_INFO_BITRATE
] = { .type
= NLA_U16
},
135 [NL80211_RATE_INFO_BITRATE32
] = { .type
= NLA_U32
},
136 [NL80211_RATE_INFO_MCS
] = { .type
= NLA_U8
},
137 [NL80211_RATE_INFO_40_MHZ_WIDTH
] = { .type
= NLA_FLAG
},
138 [NL80211_RATE_INFO_SHORT_GI
] = { .type
= NLA_FLAG
},
141 if (nla_parse_nested(rinfo
, NL80211_RATE_INFO_MAX
,
142 bitrate_attr
, rate_policy
)) {
143 snprintf(buf
, buflen
, "failed to parse nested rate attributes!");
147 if (rinfo
[NL80211_RATE_INFO_BITRATE32
])
148 rate
= nla_get_u32(rinfo
[NL80211_RATE_INFO_BITRATE32
]);
149 else if (rinfo
[NL80211_RATE_INFO_BITRATE
])
150 rate
= nla_get_u16(rinfo
[NL80211_RATE_INFO_BITRATE
]);
152 pos
+= snprintf(pos
, buflen
- (pos
- buf
),
153 "%d.%d MBit/s", rate
/ 10, rate
% 10);
155 pos
+= snprintf(pos
, buflen
- (pos
- buf
), "(unknown)");
157 if (rinfo
[NL80211_RATE_INFO_MCS
])
158 pos
+= snprintf(pos
, buflen
- (pos
- buf
),
159 " MCS %d", nla_get_u8(rinfo
[NL80211_RATE_INFO_MCS
]));
160 if (rinfo
[NL80211_RATE_INFO_VHT_MCS
])
161 pos
+= snprintf(pos
, buflen
- (pos
- buf
),
162 " VHT-MCS %d", nla_get_u8(rinfo
[NL80211_RATE_INFO_VHT_MCS
]));
163 if (rinfo
[NL80211_RATE_INFO_40_MHZ_WIDTH
])
164 pos
+= snprintf(pos
, buflen
- (pos
- buf
), " 40MHz");
165 if (rinfo
[NL80211_RATE_INFO_80_MHZ_WIDTH
])
166 pos
+= snprintf(pos
, buflen
- (pos
- buf
), " 80MHz");
167 if (rinfo
[NL80211_RATE_INFO_80P80_MHZ_WIDTH
])
168 pos
+= snprintf(pos
, buflen
- (pos
- buf
), " 80P80MHz");
169 if (rinfo
[NL80211_RATE_INFO_160_MHZ_WIDTH
])
170 pos
+= snprintf(pos
, buflen
- (pos
- buf
), " 160MHz");
171 if (rinfo
[NL80211_RATE_INFO_SHORT_GI
])
172 pos
+= snprintf(pos
, buflen
- (pos
- buf
), " short GI");
173 if (rinfo
[NL80211_RATE_INFO_VHT_NSS
])
174 pos
+= snprintf(pos
, buflen
- (pos
- buf
),
175 " VHT-NSS %d", nla_get_u8(rinfo
[NL80211_RATE_INFO_VHT_NSS
]));
178 static char *get_chain_signal(struct nlattr
*attr_list
)
189 nla_for_each_nested(attr
, attr_list
, rem
) {
195 cur
+= snprintf(cur
, sizeof(buf
) - (cur
- buf
), "%s%d", prefix
,
196 (int8_t) nla_get_u8(attr
));
200 snprintf(cur
, sizeof(buf
) - (cur
- buf
), "] ");
205 static int print_sta_handler(struct nl_msg
*msg
, void *arg
)
207 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
208 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
209 struct nlattr
*sinfo
[NL80211_STA_INFO_MAX
+ 1];
210 char mac_addr
[20], state_name
[10], dev
[20];
211 struct nl80211_sta_flag_update
*sta_flags
;
212 static struct nla_policy stats_policy
[NL80211_STA_INFO_MAX
+ 1] = {
213 [NL80211_STA_INFO_INACTIVE_TIME
] = { .type
= NLA_U32
},
214 [NL80211_STA_INFO_RX_BYTES
] = { .type
= NLA_U32
},
215 [NL80211_STA_INFO_TX_BYTES
] = { .type
= NLA_U32
},
216 [NL80211_STA_INFO_RX_BYTES64
] = { .type
= NLA_U64
},
217 [NL80211_STA_INFO_TX_BYTES64
] = { .type
= NLA_U64
},
218 [NL80211_STA_INFO_RX_PACKETS
] = { .type
= NLA_U32
},
219 [NL80211_STA_INFO_TX_PACKETS
] = { .type
= NLA_U32
},
220 [NL80211_STA_INFO_BEACON_RX
] = { .type
= NLA_U64
},
221 [NL80211_STA_INFO_SIGNAL
] = { .type
= NLA_U8
},
222 [NL80211_STA_INFO_T_OFFSET
] = { .type
= NLA_U64
},
223 [NL80211_STA_INFO_TX_BITRATE
] = { .type
= NLA_NESTED
},
224 [NL80211_STA_INFO_RX_BITRATE
] = { .type
= NLA_NESTED
},
225 [NL80211_STA_INFO_LLID
] = { .type
= NLA_U16
},
226 [NL80211_STA_INFO_PLID
] = { .type
= NLA_U16
},
227 [NL80211_STA_INFO_PLINK_STATE
] = { .type
= NLA_U8
},
228 [NL80211_STA_INFO_TX_RETRIES
] = { .type
= NLA_U32
},
229 [NL80211_STA_INFO_TX_FAILED
] = { .type
= NLA_U32
},
230 [NL80211_STA_INFO_BEACON_LOSS
] = { .type
= NLA_U32
},
231 [NL80211_STA_INFO_RX_DROP_MISC
] = { .type
= NLA_U64
},
232 [NL80211_STA_INFO_STA_FLAGS
] =
233 { .minlen
= sizeof(struct nl80211_sta_flag_update
) },
234 [NL80211_STA_INFO_LOCAL_PM
] = { .type
= NLA_U32
},
235 [NL80211_STA_INFO_PEER_PM
] = { .type
= NLA_U32
},
236 [NL80211_STA_INFO_NONPEER_PM
] = { .type
= NLA_U32
},
237 [NL80211_STA_INFO_CHAIN_SIGNAL
] = { .type
= NLA_NESTED
},
238 [NL80211_STA_INFO_CHAIN_SIGNAL_AVG
] = { .type
= NLA_NESTED
},
239 [NL80211_STA_INFO_TID_STATS
] = { .type
= NLA_NESTED
},
240 [NL80211_STA_INFO_BSS_PARAM
] = { .type
= NLA_NESTED
},
241 [NL80211_STA_INFO_RX_DURATION
] = { .type
= NLA_U64
},
245 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
246 genlmsg_attrlen(gnlh
, 0), NULL
);
249 * TODO: validate the interface and mac address!
250 * Otherwise, there's a race condition as soon as
251 * the kernel starts sending station notifications.
254 if (!tb
[NL80211_ATTR_STA_INFO
]) {
255 fprintf(stderr
, "sta stats missing!\n");
258 if (nla_parse_nested(sinfo
, NL80211_STA_INFO_MAX
,
259 tb
[NL80211_ATTR_STA_INFO
],
261 fprintf(stderr
, "failed to parse nested attributes!\n");
265 mac_addr_n2a(mac_addr
, nla_data(tb
[NL80211_ATTR_MAC
]));
266 if_indextoname(nla_get_u32(tb
[NL80211_ATTR_IFINDEX
]), dev
);
267 printf("Station %s (on %s)", mac_addr
, dev
);
269 if (sinfo
[NL80211_STA_INFO_INACTIVE_TIME
])
270 printf("\n\tinactive time:\t%u ms",
271 nla_get_u32(sinfo
[NL80211_STA_INFO_INACTIVE_TIME
]));
272 if (sinfo
[NL80211_STA_INFO_RX_BYTES64
])
273 printf("\n\trx bytes:\t%llu",
274 (unsigned long long)nla_get_u64(sinfo
[NL80211_STA_INFO_RX_BYTES64
]));
275 else if (sinfo
[NL80211_STA_INFO_RX_BYTES
])
276 printf("\n\trx bytes:\t%u",
277 nla_get_u32(sinfo
[NL80211_STA_INFO_RX_BYTES
]));
278 if (sinfo
[NL80211_STA_INFO_RX_PACKETS
])
279 printf("\n\trx packets:\t%u",
280 nla_get_u32(sinfo
[NL80211_STA_INFO_RX_PACKETS
]));
281 if (sinfo
[NL80211_STA_INFO_TX_BYTES64
])
282 printf("\n\ttx bytes:\t%llu",
283 (unsigned long long)nla_get_u64(sinfo
[NL80211_STA_INFO_TX_BYTES64
]));
284 else if (sinfo
[NL80211_STA_INFO_TX_BYTES
])
285 printf("\n\ttx bytes:\t%u",
286 nla_get_u32(sinfo
[NL80211_STA_INFO_TX_BYTES
]));
287 if (sinfo
[NL80211_STA_INFO_TX_PACKETS
])
288 printf("\n\ttx packets:\t%u",
289 nla_get_u32(sinfo
[NL80211_STA_INFO_TX_PACKETS
]));
290 if (sinfo
[NL80211_STA_INFO_TX_RETRIES
])
291 printf("\n\ttx retries:\t%u",
292 nla_get_u32(sinfo
[NL80211_STA_INFO_TX_RETRIES
]));
293 if (sinfo
[NL80211_STA_INFO_TX_FAILED
])
294 printf("\n\ttx failed:\t%u",
295 nla_get_u32(sinfo
[NL80211_STA_INFO_TX_FAILED
]));
296 if (sinfo
[NL80211_STA_INFO_BEACON_LOSS
])
297 printf("\n\tbeacon loss:\t%u",
298 nla_get_u32(sinfo
[NL80211_STA_INFO_BEACON_LOSS
]));
299 if (sinfo
[NL80211_STA_INFO_BEACON_RX
])
300 printf("\n\tbeacon rx:\t%llu",
301 (unsigned long long)nla_get_u64(sinfo
[NL80211_STA_INFO_BEACON_RX
]));
302 if (sinfo
[NL80211_STA_INFO_RX_DROP_MISC
])
303 printf("\n\trx drop misc:\t%llu",
304 (unsigned long long)nla_get_u64(sinfo
[NL80211_STA_INFO_RX_DROP_MISC
]));
306 chain
= get_chain_signal(sinfo
[NL80211_STA_INFO_CHAIN_SIGNAL
]);
307 if (sinfo
[NL80211_STA_INFO_SIGNAL
])
308 printf("\n\tsignal: \t%d %sdBm",
309 (int8_t)nla_get_u8(sinfo
[NL80211_STA_INFO_SIGNAL
]),
312 chain
= get_chain_signal(sinfo
[NL80211_STA_INFO_CHAIN_SIGNAL_AVG
]);
313 if (sinfo
[NL80211_STA_INFO_SIGNAL_AVG
])
314 printf("\n\tsignal avg:\t%d %sdBm",
315 (int8_t)nla_get_u8(sinfo
[NL80211_STA_INFO_SIGNAL_AVG
]),
318 if (sinfo
[NL80211_STA_INFO_BEACON_SIGNAL_AVG
])
319 printf("\n\tbeacon signal avg:\t%d dBm",
320 nla_get_u8(sinfo
[NL80211_STA_INFO_BEACON_SIGNAL_AVG
]));
321 if (sinfo
[NL80211_STA_INFO_T_OFFSET
])
322 printf("\n\tToffset:\t%llu us",
323 (unsigned long long)nla_get_u64(sinfo
[NL80211_STA_INFO_T_OFFSET
]));
325 if (sinfo
[NL80211_STA_INFO_TX_BITRATE
]) {
328 parse_bitrate(sinfo
[NL80211_STA_INFO_TX_BITRATE
], buf
, sizeof(buf
));
329 printf("\n\ttx bitrate:\t%s", buf
);
332 if (sinfo
[NL80211_STA_INFO_RX_BITRATE
]) {
335 parse_bitrate(sinfo
[NL80211_STA_INFO_RX_BITRATE
], buf
, sizeof(buf
));
336 printf("\n\trx bitrate:\t%s", buf
);
339 if (sinfo
[NL80211_STA_INFO_RX_DURATION
])
340 printf("\n\trx duration:\t%lld us",
341 (unsigned long long)nla_get_u64(sinfo
[NL80211_STA_INFO_RX_DURATION
]));
343 if (sinfo
[NL80211_STA_INFO_EXPECTED_THROUGHPUT
]) {
346 thr
= nla_get_u32(sinfo
[NL80211_STA_INFO_EXPECTED_THROUGHPUT
]);
347 /* convert in Mbps but scale by 1000 to save kbps units */
348 thr
= thr
* 1000 / 1024;
350 printf("\n\texpected throughput:\t%u.%uMbps",
351 thr
/ 1000, thr
% 1000);
354 if (sinfo
[NL80211_STA_INFO_LLID
])
355 printf("\n\tmesh llid:\t%d",
356 nla_get_u16(sinfo
[NL80211_STA_INFO_LLID
]));
357 if (sinfo
[NL80211_STA_INFO_PLID
])
358 printf("\n\tmesh plid:\t%d",
359 nla_get_u16(sinfo
[NL80211_STA_INFO_PLID
]));
360 if (sinfo
[NL80211_STA_INFO_PLINK_STATE
]) {
361 switch (nla_get_u8(sinfo
[NL80211_STA_INFO_PLINK_STATE
])) {
363 strcpy(state_name
, "LISTEN");
366 strcpy(state_name
, "OPN_SNT");
369 strcpy(state_name
, "OPN_RCVD");
372 strcpy(state_name
, "CNF_RCVD");
375 strcpy(state_name
, "ESTAB");
378 strcpy(state_name
, "HOLDING");
381 strcpy(state_name
, "BLOCKED");
384 strcpy(state_name
, "UNKNOWN");
387 printf("\n\tmesh plink:\t%s", state_name
);
389 if (sinfo
[NL80211_STA_INFO_LOCAL_PM
]) {
390 printf("\n\tmesh local PS mode:\t");
391 print_power_mode(sinfo
[NL80211_STA_INFO_LOCAL_PM
]);
393 if (sinfo
[NL80211_STA_INFO_PEER_PM
]) {
394 printf("\n\tmesh peer PS mode:\t");
395 print_power_mode(sinfo
[NL80211_STA_INFO_PEER_PM
]);
397 if (sinfo
[NL80211_STA_INFO_NONPEER_PM
]) {
398 printf("\n\tmesh non-peer PS mode:\t");
399 print_power_mode(sinfo
[NL80211_STA_INFO_NONPEER_PM
]);
402 if (sinfo
[NL80211_STA_INFO_STA_FLAGS
]) {
403 sta_flags
= (struct nl80211_sta_flag_update
*)
404 nla_data(sinfo
[NL80211_STA_INFO_STA_FLAGS
]);
406 if (sta_flags
->mask
& BIT(NL80211_STA_FLAG_AUTHORIZED
)) {
407 printf("\n\tauthorized:\t");
408 if (sta_flags
->set
& BIT(NL80211_STA_FLAG_AUTHORIZED
))
414 if (sta_flags
->mask
& BIT(NL80211_STA_FLAG_AUTHENTICATED
)) {
415 printf("\n\tauthenticated:\t");
416 if (sta_flags
->set
& BIT(NL80211_STA_FLAG_AUTHENTICATED
))
422 if (sta_flags
->mask
& BIT(NL80211_STA_FLAG_ASSOCIATED
)) {
423 printf("\n\tassociated:\t");
424 if (sta_flags
->set
& BIT(NL80211_STA_FLAG_ASSOCIATED
))
430 if (sta_flags
->mask
& BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
)) {
431 printf("\n\tpreamble:\t");
432 if (sta_flags
->set
& BIT(NL80211_STA_FLAG_SHORT_PREAMBLE
))
438 if (sta_flags
->mask
& BIT(NL80211_STA_FLAG_WME
)) {
439 printf("\n\tWMM/WME:\t");
440 if (sta_flags
->set
& BIT(NL80211_STA_FLAG_WME
))
446 if (sta_flags
->mask
& BIT(NL80211_STA_FLAG_MFP
)) {
447 printf("\n\tMFP:\t\t");
448 if (sta_flags
->set
& BIT(NL80211_STA_FLAG_MFP
))
454 if (sta_flags
->mask
& BIT(NL80211_STA_FLAG_TDLS_PEER
)) {
455 printf("\n\tTDLS peer:\t");
456 if (sta_flags
->set
& BIT(NL80211_STA_FLAG_TDLS_PEER
))
463 if (sinfo
[NL80211_STA_INFO_TID_STATS
] && arg
!= NULL
&&
464 !strcmp((char *)arg
, "-v"))
465 parse_tid_stats(sinfo
[NL80211_STA_INFO_TID_STATS
]);
466 if (sinfo
[NL80211_STA_INFO_BSS_PARAM
])
467 parse_bss_param(sinfo
[NL80211_STA_INFO_BSS_PARAM
]);
468 if (sinfo
[NL80211_STA_INFO_CONNECTED_TIME
])
469 printf("\n\tconnected time:\t%u seconds",
470 nla_get_u32(sinfo
[NL80211_STA_INFO_CONNECTED_TIME
]));
476 static int handle_station_get(struct nl80211_state
*state
,
478 int argc
, char **argv
,
481 unsigned char mac_addr
[ETH_ALEN
];
486 if (mac_addr_a2n(mac_addr
, argv
[0])) {
487 fprintf(stderr
, "invalid mac address\n");
497 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
499 register_handler(print_sta_handler
, NULL
);
505 COMMAND(station
, get
, "<MAC address>",
506 NL80211_CMD_GET_STATION
, 0, CIB_NETDEV
, handle_station_get
,
507 "Get information for a specific station.");
509 static int handle_station_del(struct nl80211_state
*state
,
511 int argc
, char **argv
,
515 unsigned char mac_addr
[ETH_ALEN
];
522 if (mac_addr_a2n(mac_addr
, argv
[0])) {
523 fprintf(stderr
, "invalid mac address\n");
529 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
531 if (argc
> 1 && strcmp(argv
[0], "subtype") == 0) {
535 subtype
= strtod(argv
[0], &end
);
539 NLA_PUT_U8(msg
, NL80211_ATTR_MGMT_SUBTYPE
, subtype
);
544 if (argc
> 1 && strcmp(argv
[0], "reason-code") == 0) {
548 reason_code
= strtod(argv
[0], &end
);
552 NLA_PUT_U16(msg
, NL80211_ATTR_REASON_CODE
, reason_code
);
560 register_handler(print_sta_handler
, NULL
);
566 COMMAND(station
, del
, "<MAC address> [subtype <subtype>] [reason-code <code>]",
567 NL80211_CMD_DEL_STATION
, 0, CIB_NETDEV
, handle_station_del
,
568 "Remove the given station entry (use with caution!)\n"
569 "Example subtype values: 0xA (disassociation), 0xC (deauthentication)");
571 static const struct cmd
*station_set_plink
;
572 static const struct cmd
*station_set_vlan
;
573 static const struct cmd
*station_set_mesh_power_mode
;
575 static const struct cmd
*select_station_cmd(int argc
, char **argv
)
579 if (strcmp(argv
[1], "plink_action") == 0)
580 return station_set_plink
;
581 if (strcmp(argv
[1], "vlan") == 0)
582 return station_set_vlan
;
583 if (strcmp(argv
[1], "mesh_power_mode") == 0)
584 return station_set_mesh_power_mode
;
588 static int handle_station_set_plink(struct nl80211_state
*state
,
590 int argc
, char **argv
,
593 unsigned char plink_action
;
594 unsigned char mac_addr
[ETH_ALEN
];
599 if (mac_addr_a2n(mac_addr
, argv
[0])) {
600 fprintf(stderr
, "invalid mac address\n");
606 if (strcmp("plink_action", argv
[0]) != 0)
611 if (strcmp("open", argv
[0]) == 0)
612 plink_action
= NL80211_PLINK_ACTION_OPEN
;
613 else if (strcmp("block", argv
[0]) == 0)
614 plink_action
= NL80211_PLINK_ACTION_BLOCK
;
616 fprintf(stderr
, "plink action not supported\n");
625 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
626 NLA_PUT_U8(msg
, NL80211_ATTR_STA_PLINK_ACTION
, plink_action
);
632 COMMAND_ALIAS(station
, set
, "<MAC address> plink_action <open|block>",
633 NL80211_CMD_SET_STATION
, 0, CIB_NETDEV
, handle_station_set_plink
,
634 "Set mesh peer link action for this station (peer).",
635 select_station_cmd
, station_set_plink
);
637 static int handle_station_set_vlan(struct nl80211_state
*state
,
639 int argc
, char **argv
,
642 unsigned char mac_addr
[ETH_ALEN
];
643 unsigned long sta_vlan
= 0;
649 if (mac_addr_a2n(mac_addr
, argv
[0])) {
650 fprintf(stderr
, "invalid mac address\n");
656 if (strcmp("vlan", argv
[0]) != 0)
661 sta_vlan
= strtoul(argv
[0], &err
, 0);
663 fprintf(stderr
, "invalid vlan id\n");
672 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
673 NLA_PUT_U32(msg
, NL80211_ATTR_STA_VLAN
, sta_vlan
);
679 COMMAND_ALIAS(station
, set
, "<MAC address> vlan <ifindex>",
680 NL80211_CMD_SET_STATION
, 0, CIB_NETDEV
, handle_station_set_vlan
,
681 "Set an AP VLAN for this station.",
682 select_station_cmd
, station_set_vlan
);
684 static int handle_station_set_mesh_power_mode(struct nl80211_state
*state
,
686 int argc
, char **argv
,
689 unsigned char mesh_power_mode
;
690 unsigned char mac_addr
[ETH_ALEN
];
695 if (mac_addr_a2n(mac_addr
, argv
[0])) {
696 fprintf(stderr
, "invalid mac address\n");
702 if (strcmp("mesh_power_mode", argv
[0]) != 0)
707 if (strcmp("active", argv
[0]) == 0)
708 mesh_power_mode
= NL80211_MESH_POWER_ACTIVE
;
709 else if (strcmp("light", argv
[0]) == 0)
710 mesh_power_mode
= NL80211_MESH_POWER_LIGHT_SLEEP
;
711 else if (strcmp("deep", argv
[0]) == 0)
712 mesh_power_mode
= NL80211_MESH_POWER_DEEP_SLEEP
;
714 fprintf(stderr
, "unknown mesh power mode\n");
723 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, mac_addr
);
724 NLA_PUT_U32(msg
, NL80211_ATTR_LOCAL_MESH_POWER_MODE
, mesh_power_mode
);
730 COMMAND_ALIAS(station
, set
, "<MAC address> mesh_power_mode "
731 "<active|light|deep>", NL80211_CMD_SET_STATION
, 0, CIB_NETDEV
,
732 handle_station_set_mesh_power_mode
,
733 "Set link-specific mesh power mode for this station",
734 select_station_cmd
, station_set_mesh_power_mode
);
736 static int handle_station_dump(struct nl80211_state
*state
,
738 int argc
, char **argv
,
741 register_handler(print_sta_handler
, *argv
);
744 COMMAND(station
, dump
, "[-v]",
745 NL80211_CMD_GET_STATION
, NLM_F_DUMP
, CIB_NETDEV
, handle_station_dump
,
746 "List all stations known, e.g. the AP on managed interfaces");