]>
Commit | Line | Data |
---|---|---|
ded30a6b JM |
1 | /* |
2 | * Control interface for shared AP commands | |
bd0b6203 | 3 | * Copyright (c) 2004-2014, Jouni Malinen <j@w1.fi> |
ded30a6b | 4 | * |
0f3d578e JM |
5 | * This software may be distributed under the terms of the BSD license. |
6 | * See README for more details. | |
ded30a6b JM |
7 | */ |
8 | ||
6226e38d | 9 | #include "utils/includes.h" |
ded30a6b | 10 | |
6226e38d | 11 | #include "utils/common.h" |
e60b2951 | 12 | #include "common/ieee802_11_defs.h" |
bd0b6203 | 13 | #include "common/sae.h" |
ea23df65 | 14 | #include "eapol_auth/eapol_auth_sm.h" |
8e9a8b0f | 15 | #include "fst/fst_ctrl_iface.h" |
6226e38d JM |
16 | #include "hostapd.h" |
17 | #include "ieee802_1x.h" | |
18 | #include "wpa_auth.h" | |
19 | #include "ieee802_11.h" | |
20 | #include "sta_info.h" | |
21 | #include "wps_hostapd.h" | |
e44f8bf2 | 22 | #include "p2p_hostapd.h" |
ded30a6b | 23 | #include "ctrl_iface_ap.h" |
e60b2951 | 24 | #include "ap_drv_ops.h" |
6332aaf3 | 25 | #include "mbo_ap.h" |
ded30a6b JM |
26 | |
27 | ||
f538be3e JM |
28 | static int hostapd_get_sta_tx_rx(struct hostapd_data *hapd, |
29 | struct sta_info *sta, | |
30 | char *buf, size_t buflen) | |
31 | { | |
32 | struct hostap_sta_driver_data data; | |
33 | int ret; | |
34 | ||
35 | if (hostapd_drv_read_sta_data(hapd, &data, sta->addr) < 0) | |
36 | return 0; | |
37 | ||
38 | ret = os_snprintf(buf, buflen, "rx_packets=%lu\ntx_packets=%lu\n" | |
de923140 | 39 | "rx_bytes=%llu\ntx_bytes=%llu\ninactive_msec=%lu\n", |
f538be3e | 40 | data.rx_packets, data.tx_packets, |
de923140 | 41 | data.rx_bytes, data.tx_bytes, data.inactive_msec); |
d85e1fc8 | 42 | if (os_snprintf_error(buflen, ret)) |
f538be3e JM |
43 | return 0; |
44 | return ret; | |
45 | } | |
46 | ||
47 | ||
39b1572c RM |
48 | static int hostapd_get_sta_conn_time(struct sta_info *sta, |
49 | char *buf, size_t buflen) | |
50 | { | |
b3493fa1 | 51 | struct os_reltime age; |
f538be3e | 52 | int ret; |
39b1572c RM |
53 | |
54 | if (!sta->connected_time.sec) | |
55 | return 0; | |
56 | ||
b3493fa1 | 57 | os_reltime_age(&sta->connected_time, &age); |
39b1572c | 58 | |
f538be3e | 59 | ret = os_snprintf(buf, buflen, "connected_time=%u\n", |
39b1572c | 60 | (unsigned int) age.sec); |
d85e1fc8 | 61 | if (os_snprintf_error(buflen, ret)) |
f538be3e JM |
62 | return 0; |
63 | return ret; | |
64 | } | |
39b1572c | 65 | |
f538be3e JM |
66 | |
67 | static const char * timeout_next_str(int val) | |
68 | { | |
69 | switch (val) { | |
70 | case STA_NULLFUNC: | |
71 | return "NULLFUNC POLL"; | |
72 | case STA_DISASSOC: | |
73 | return "DISASSOC"; | |
74 | case STA_DEAUTH: | |
75 | return "DEAUTH"; | |
76 | case STA_REMOVE: | |
77 | return "REMOVE"; | |
78 | case STA_DISASSOC_FROM_CLI: | |
79 | return "DISASSOC_FROM_CLI"; | |
80 | } | |
81 | ||
82 | return "?"; | |
39b1572c RM |
83 | } |
84 | ||
85 | ||
ded30a6b JM |
86 | static int hostapd_ctrl_iface_sta_mib(struct hostapd_data *hapd, |
87 | struct sta_info *sta, | |
88 | char *buf, size_t buflen) | |
89 | { | |
f538be3e | 90 | int len, res, ret, i; |
ded30a6b | 91 | |
a487b355 IP |
92 | if (!sta) |
93 | return 0; | |
94 | ||
ded30a6b | 95 | len = 0; |
b76f4c27 | 96 | ret = os_snprintf(buf + len, buflen - len, MACSTR "\nflags=", |
ded30a6b | 97 | MAC2STR(sta->addr)); |
d85e1fc8 | 98 | if (os_snprintf_error(buflen - len, ret)) |
ded30a6b JM |
99 | return len; |
100 | len += ret; | |
101 | ||
b76f4c27 JM |
102 | ret = ap_sta_flags_txt(sta->flags, buf + len, buflen - len); |
103 | if (ret < 0) | |
104 | return len; | |
105 | len += ret; | |
106 | ||
f538be3e JM |
107 | ret = os_snprintf(buf + len, buflen - len, "\naid=%d\ncapability=0x%x\n" |
108 | "listen_interval=%d\nsupported_rates=", | |
109 | sta->aid, sta->capability, sta->listen_interval); | |
d85e1fc8 | 110 | if (os_snprintf_error(buflen - len, ret)) |
f538be3e JM |
111 | return len; |
112 | len += ret; | |
113 | ||
114 | for (i = 0; i < sta->supported_rates_len; i++) { | |
115 | ret = os_snprintf(buf + len, buflen - len, "%02x%s", | |
116 | sta->supported_rates[i], | |
117 | i + 1 < sta->supported_rates_len ? " " : ""); | |
d85e1fc8 | 118 | if (os_snprintf_error(buflen - len, ret)) |
f538be3e JM |
119 | return len; |
120 | len += ret; | |
121 | } | |
122 | ||
123 | ret = os_snprintf(buf + len, buflen - len, "\ntimeout_next=%s\n", | |
124 | timeout_next_str(sta->timeout_next)); | |
d85e1fc8 | 125 | if (os_snprintf_error(buflen - len, ret)) |
b76f4c27 JM |
126 | return len; |
127 | len += ret; | |
128 | ||
ded30a6b JM |
129 | res = ieee802_11_get_mib_sta(hapd, sta, buf + len, buflen - len); |
130 | if (res >= 0) | |
131 | len += res; | |
132 | res = wpa_get_mib_sta(sta->wpa_sm, buf + len, buflen - len); | |
133 | if (res >= 0) | |
134 | len += res; | |
135 | res = ieee802_1x_get_mib_sta(hapd, sta, buf + len, buflen - len); | |
136 | if (res >= 0) | |
137 | len += res; | |
138 | res = hostapd_wps_get_mib_sta(hapd, sta->addr, buf + len, | |
139 | buflen - len); | |
140 | if (res >= 0) | |
e44f8bf2 JM |
141 | len += res; |
142 | res = hostapd_p2p_get_mib_sta(hapd, sta, buf + len, buflen - len); | |
143 | if (res >= 0) | |
ded30a6b JM |
144 | len += res; |
145 | ||
f538be3e JM |
146 | len += hostapd_get_sta_tx_rx(hapd, sta, buf + len, buflen - len); |
147 | len += hostapd_get_sta_conn_time(sta, buf + len, buflen - len); | |
39b1572c | 148 | |
bd0b6203 JM |
149 | #ifdef CONFIG_SAE |
150 | if (sta->sae && sta->sae->state == SAE_ACCEPTED) { | |
151 | res = os_snprintf(buf + len, buflen - len, "sae_group=%d\n", | |
152 | sta->sae->group); | |
153 | if (!os_snprintf_error(buflen - len, res)) | |
154 | len += res; | |
155 | } | |
156 | #endif /* CONFIG_SAE */ | |
157 | ||
87b5b539 JM |
158 | if (sta->vlan_id > 0) { |
159 | res = os_snprintf(buf + len, buflen - len, "vlan_id=%d\n", | |
160 | sta->vlan_id); | |
161 | if (!os_snprintf_error(buflen - len, res)) | |
162 | len += res; | |
163 | } | |
164 | ||
6332aaf3 JM |
165 | res = mbo_ap_get_info(sta, buf + len, buflen - len); |
166 | if (res >= 0) | |
167 | len += res; | |
168 | ||
adf0478e JM |
169 | if (sta->supp_op_classes && |
170 | buflen - len > (unsigned) (17 + 2 * sta->supp_op_classes[0])) { | |
171 | len += os_snprintf(buf + len, buflen - len, "supp_op_classes="); | |
172 | len += wpa_snprintf_hex(buf + len, buflen - len, | |
173 | sta->supp_op_classes + 1, | |
174 | sta->supp_op_classes[0]); | |
175 | len += os_snprintf(buf + len, buflen - len, "\n"); | |
176 | } | |
177 | ||
ded30a6b JM |
178 | return len; |
179 | } | |
180 | ||
181 | ||
182 | int hostapd_ctrl_iface_sta_first(struct hostapd_data *hapd, | |
183 | char *buf, size_t buflen) | |
184 | { | |
185 | return hostapd_ctrl_iface_sta_mib(hapd, hapd->sta_list, buf, buflen); | |
186 | } | |
187 | ||
188 | ||
189 | int hostapd_ctrl_iface_sta(struct hostapd_data *hapd, const char *txtaddr, | |
190 | char *buf, size_t buflen) | |
191 | { | |
192 | u8 addr[ETH_ALEN]; | |
193 | int ret; | |
ea23df65 JM |
194 | const char *pos; |
195 | struct sta_info *sta; | |
ded30a6b JM |
196 | |
197 | if (hwaddr_aton(txtaddr, addr)) { | |
198 | ret = os_snprintf(buf, buflen, "FAIL\n"); | |
d85e1fc8 | 199 | if (os_snprintf_error(buflen, ret)) |
ded30a6b JM |
200 | return 0; |
201 | return ret; | |
202 | } | |
ea23df65 JM |
203 | |
204 | sta = ap_get_sta(hapd, addr); | |
205 | if (sta == NULL) | |
206 | return -1; | |
207 | ||
208 | pos = os_strchr(txtaddr, ' '); | |
209 | if (pos) { | |
210 | pos++; | |
211 | ||
212 | #ifdef HOSTAPD_DUMP_STATE | |
213 | if (os_strcmp(pos, "eapol") == 0) { | |
214 | if (sta->eapol_sm == NULL) | |
215 | return -1; | |
216 | return eapol_auth_dump_state(sta->eapol_sm, buf, | |
217 | buflen); | |
218 | } | |
219 | #endif /* HOSTAPD_DUMP_STATE */ | |
220 | ||
221 | return -1; | |
222 | } | |
223 | ||
8e9a8b0f AN |
224 | ret = hostapd_ctrl_iface_sta_mib(hapd, sta, buf, buflen); |
225 | ret += fst_ctrl_iface_mb_info(addr, buf + ret, buflen - ret); | |
226 | ||
227 | return ret; | |
ded30a6b JM |
228 | } |
229 | ||
230 | ||
231 | int hostapd_ctrl_iface_sta_next(struct hostapd_data *hapd, const char *txtaddr, | |
232 | char *buf, size_t buflen) | |
233 | { | |
234 | u8 addr[ETH_ALEN]; | |
235 | struct sta_info *sta; | |
236 | int ret; | |
237 | ||
238 | if (hwaddr_aton(txtaddr, addr) || | |
239 | (sta = ap_get_sta(hapd, addr)) == NULL) { | |
240 | ret = os_snprintf(buf, buflen, "FAIL\n"); | |
d85e1fc8 | 241 | if (os_snprintf_error(buflen, ret)) |
ded30a6b JM |
242 | return 0; |
243 | return ret; | |
a487b355 IP |
244 | } |
245 | ||
246 | if (!sta->next) | |
247 | return 0; | |
248 | ||
ded30a6b JM |
249 | return hostapd_ctrl_iface_sta_mib(hapd, sta->next, buf, buflen); |
250 | } | |
e60b2951 JJ |
251 | |
252 | ||
253 | #ifdef CONFIG_P2P_MANAGER | |
254 | static int p2p_manager_disconnect(struct hostapd_data *hapd, u16 stype, | |
255 | u8 minor_reason_code, const u8 *addr) | |
256 | { | |
257 | struct ieee80211_mgmt *mgmt; | |
258 | int ret; | |
259 | u8 *pos; | |
260 | ||
261 | if (hapd->driver->send_frame == NULL) | |
262 | return -1; | |
263 | ||
264 | mgmt = os_zalloc(sizeof(*mgmt) + 100); | |
265 | if (mgmt == NULL) | |
266 | return -1; | |
267 | ||
dedfa440 | 268 | mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, stype); |
e60b2951 | 269 | wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "P2P: Disconnect STA " MACSTR |
dedfa440 PF |
270 | " with minor reason code %u (stype=%u (%s))", |
271 | MAC2STR(addr), minor_reason_code, stype, | |
272 | fc2str(mgmt->frame_control)); | |
e60b2951 | 273 | |
e60b2951 JJ |
274 | os_memcpy(mgmt->da, addr, ETH_ALEN); |
275 | os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN); | |
276 | os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN); | |
277 | if (stype == WLAN_FC_STYPE_DEAUTH) { | |
278 | mgmt->u.deauth.reason_code = | |
279 | host_to_le16(WLAN_REASON_PREV_AUTH_NOT_VALID); | |
280 | pos = (u8 *) (&mgmt->u.deauth.reason_code + 1); | |
281 | } else { | |
282 | mgmt->u.disassoc.reason_code = | |
283 | host_to_le16(WLAN_REASON_PREV_AUTH_NOT_VALID); | |
284 | pos = (u8 *) (&mgmt->u.disassoc.reason_code + 1); | |
285 | } | |
286 | ||
287 | *pos++ = WLAN_EID_VENDOR_SPECIFIC; | |
288 | *pos++ = 4 + 3 + 1; | |
8bc4372f RJ |
289 | WPA_PUT_BE32(pos, P2P_IE_VENDOR_TYPE); |
290 | pos += 4; | |
e60b2951 JJ |
291 | |
292 | *pos++ = P2P_ATTR_MINOR_REASON_CODE; | |
293 | WPA_PUT_LE16(pos, 1); | |
294 | pos += 2; | |
295 | *pos++ = minor_reason_code; | |
296 | ||
297 | ret = hapd->driver->send_frame(hapd->drv_priv, (u8 *) mgmt, | |
298 | pos - (u8 *) mgmt, 1); | |
299 | os_free(mgmt); | |
300 | ||
301 | return ret < 0 ? -1 : 0; | |
302 | } | |
303 | #endif /* CONFIG_P2P_MANAGER */ | |
304 | ||
305 | ||
306 | int hostapd_ctrl_iface_deauthenticate(struct hostapd_data *hapd, | |
307 | const char *txtaddr) | |
308 | { | |
309 | u8 addr[ETH_ALEN]; | |
310 | struct sta_info *sta; | |
311 | const char *pos; | |
6917c9e8 | 312 | u16 reason = WLAN_REASON_PREV_AUTH_NOT_VALID; |
e60b2951 JJ |
313 | |
314 | wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "CTRL_IFACE DEAUTHENTICATE %s", | |
315 | txtaddr); | |
316 | ||
317 | if (hwaddr_aton(txtaddr, addr)) | |
318 | return -1; | |
319 | ||
ce6b9cd4 JM |
320 | pos = os_strstr(txtaddr, " reason="); |
321 | if (pos) | |
322 | reason = atoi(pos + 8); | |
323 | ||
e60b2951 JJ |
324 | pos = os_strstr(txtaddr, " test="); |
325 | if (pos) { | |
326 | struct ieee80211_mgmt mgmt; | |
327 | int encrypt; | |
328 | if (hapd->driver->send_frame == NULL) | |
329 | return -1; | |
330 | pos += 6; | |
331 | encrypt = atoi(pos); | |
332 | os_memset(&mgmt, 0, sizeof(mgmt)); | |
333 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, | |
334 | WLAN_FC_STYPE_DEAUTH); | |
335 | os_memcpy(mgmt.da, addr, ETH_ALEN); | |
336 | os_memcpy(mgmt.sa, hapd->own_addr, ETH_ALEN); | |
337 | os_memcpy(mgmt.bssid, hapd->own_addr, ETH_ALEN); | |
ce6b9cd4 | 338 | mgmt.u.deauth.reason_code = host_to_le16(reason); |
e60b2951 JJ |
339 | if (hapd->driver->send_frame(hapd->drv_priv, (u8 *) &mgmt, |
340 | IEEE80211_HDRLEN + | |
341 | sizeof(mgmt.u.deauth), | |
342 | encrypt) < 0) | |
343 | return -1; | |
344 | return 0; | |
345 | } | |
346 | ||
347 | #ifdef CONFIG_P2P_MANAGER | |
348 | pos = os_strstr(txtaddr, " p2p="); | |
349 | if (pos) { | |
350 | return p2p_manager_disconnect(hapd, WLAN_FC_STYPE_DEAUTH, | |
351 | atoi(pos + 5), addr); | |
352 | } | |
353 | #endif /* CONFIG_P2P_MANAGER */ | |
354 | ||
3dbfb28c JM |
355 | if (os_strstr(txtaddr, " tx=0")) |
356 | hostapd_drv_sta_remove(hapd, addr); | |
357 | else | |
358 | hostapd_drv_sta_deauth(hapd, addr, reason); | |
e60b2951 JJ |
359 | sta = ap_get_sta(hapd, addr); |
360 | if (sta) | |
6917c9e8 | 361 | ap_sta_deauthenticate(hapd, sta, reason); |
e60b2951 JJ |
362 | else if (addr[0] == 0xff) |
363 | hostapd_free_stas(hapd); | |
364 | ||
365 | return 0; | |
366 | } | |
367 | ||
368 | ||
369 | int hostapd_ctrl_iface_disassociate(struct hostapd_data *hapd, | |
370 | const char *txtaddr) | |
371 | { | |
372 | u8 addr[ETH_ALEN]; | |
373 | struct sta_info *sta; | |
374 | const char *pos; | |
6917c9e8 | 375 | u16 reason = WLAN_REASON_PREV_AUTH_NOT_VALID; |
e60b2951 JJ |
376 | |
377 | wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "CTRL_IFACE DISASSOCIATE %s", | |
378 | txtaddr); | |
379 | ||
380 | if (hwaddr_aton(txtaddr, addr)) | |
381 | return -1; | |
382 | ||
ce6b9cd4 JM |
383 | pos = os_strstr(txtaddr, " reason="); |
384 | if (pos) | |
385 | reason = atoi(pos + 8); | |
386 | ||
e60b2951 JJ |
387 | pos = os_strstr(txtaddr, " test="); |
388 | if (pos) { | |
389 | struct ieee80211_mgmt mgmt; | |
390 | int encrypt; | |
391 | if (hapd->driver->send_frame == NULL) | |
392 | return -1; | |
393 | pos += 6; | |
394 | encrypt = atoi(pos); | |
395 | os_memset(&mgmt, 0, sizeof(mgmt)); | |
396 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, | |
397 | WLAN_FC_STYPE_DISASSOC); | |
398 | os_memcpy(mgmt.da, addr, ETH_ALEN); | |
399 | os_memcpy(mgmt.sa, hapd->own_addr, ETH_ALEN); | |
400 | os_memcpy(mgmt.bssid, hapd->own_addr, ETH_ALEN); | |
ce6b9cd4 | 401 | mgmt.u.disassoc.reason_code = host_to_le16(reason); |
e60b2951 JJ |
402 | if (hapd->driver->send_frame(hapd->drv_priv, (u8 *) &mgmt, |
403 | IEEE80211_HDRLEN + | |
404 | sizeof(mgmt.u.deauth), | |
405 | encrypt) < 0) | |
406 | return -1; | |
407 | return 0; | |
408 | } | |
409 | ||
410 | #ifdef CONFIG_P2P_MANAGER | |
411 | pos = os_strstr(txtaddr, " p2p="); | |
412 | if (pos) { | |
413 | return p2p_manager_disconnect(hapd, WLAN_FC_STYPE_DISASSOC, | |
414 | atoi(pos + 5), addr); | |
415 | } | |
416 | #endif /* CONFIG_P2P_MANAGER */ | |
417 | ||
3dbfb28c JM |
418 | if (os_strstr(txtaddr, " tx=0")) |
419 | hostapd_drv_sta_remove(hapd, addr); | |
420 | else | |
421 | hostapd_drv_sta_disassoc(hapd, addr, reason); | |
e60b2951 JJ |
422 | sta = ap_get_sta(hapd, addr); |
423 | if (sta) | |
6917c9e8 | 424 | ap_sta_disassociate(hapd, sta, reason); |
e60b2951 JJ |
425 | else if (addr[0] == 0xff) |
426 | hostapd_free_stas(hapd); | |
427 | ||
428 | return 0; | |
429 | } | |
5ae6449c JM |
430 | |
431 | ||
1854eeca JM |
432 | int hostapd_ctrl_iface_poll_sta(struct hostapd_data *hapd, |
433 | const char *txtaddr) | |
434 | { | |
435 | u8 addr[ETH_ALEN]; | |
436 | struct sta_info *sta; | |
437 | ||
438 | wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "CTRL_IFACE POLL_STA %s", txtaddr); | |
439 | ||
440 | if (hwaddr_aton(txtaddr, addr)) | |
441 | return -1; | |
442 | ||
443 | sta = ap_get_sta(hapd, addr); | |
444 | if (!sta) | |
445 | return -1; | |
446 | ||
447 | hostapd_drv_poll_client(hapd, hapd->own_addr, addr, | |
448 | sta->flags & WLAN_STA_WMM); | |
449 | return 0; | |
450 | } | |
451 | ||
452 | ||
5ae6449c JM |
453 | int hostapd_ctrl_iface_status(struct hostapd_data *hapd, char *buf, |
454 | size_t buflen) | |
455 | { | |
456 | struct hostapd_iface *iface = hapd->iface; | |
457 | int len = 0, ret; | |
458 | size_t i; | |
459 | ||
460 | ret = os_snprintf(buf + len, buflen - len, | |
461 | "state=%s\n" | |
462 | "phy=%s\n" | |
463 | "freq=%d\n" | |
464 | "num_sta_non_erp=%d\n" | |
465 | "num_sta_no_short_slot_time=%d\n" | |
466 | "num_sta_no_short_preamble=%d\n" | |
467 | "olbc=%d\n" | |
468 | "num_sta_ht_no_gf=%d\n" | |
469 | "num_sta_no_ht=%d\n" | |
470 | "num_sta_ht_20_mhz=%d\n" | |
9c47f6a2 | 471 | "num_sta_ht40_intolerant=%d\n" |
5ae6449c JM |
472 | "olbc_ht=%d\n" |
473 | "ht_op_mode=0x%x\n", | |
474 | hostapd_state_text(iface->state), | |
475 | iface->phy, | |
476 | iface->freq, | |
477 | iface->num_sta_non_erp, | |
478 | iface->num_sta_no_short_slot_time, | |
479 | iface->num_sta_no_short_preamble, | |
480 | iface->olbc, | |
481 | iface->num_sta_ht_no_gf, | |
482 | iface->num_sta_no_ht, | |
483 | iface->num_sta_ht_20mhz, | |
9c47f6a2 | 484 | iface->num_sta_ht40_intolerant, |
5ae6449c JM |
485 | iface->olbc_ht, |
486 | iface->ht_op_mode); | |
d85e1fc8 | 487 | if (os_snprintf_error(buflen - len, ret)) |
5ae6449c JM |
488 | return len; |
489 | len += ret; | |
490 | ||
bbbacbf2 JD |
491 | if (!iface->cac_started || !iface->dfs_cac_ms) { |
492 | ret = os_snprintf(buf + len, buflen - len, | |
493 | "cac_time_seconds=%d\n" | |
494 | "cac_time_left_seconds=N/A\n", | |
495 | iface->dfs_cac_ms / 1000); | |
496 | } else { | |
497 | /* CAC started and CAC time set - calculate remaining time */ | |
498 | struct os_reltime now; | |
499 | unsigned int left_time; | |
500 | ||
501 | os_reltime_age(&iface->dfs_cac_start, &now); | |
502 | left_time = iface->dfs_cac_ms / 1000 - now.sec; | |
503 | ret = os_snprintf(buf + len, buflen - len, | |
504 | "cac_time_seconds=%u\n" | |
505 | "cac_time_left_seconds=%u\n", | |
506 | iface->dfs_cac_ms / 1000, | |
507 | left_time); | |
508 | } | |
d85e1fc8 | 509 | if (os_snprintf_error(buflen - len, ret)) |
bbbacbf2 JD |
510 | return len; |
511 | len += ret; | |
512 | ||
5ae6449c JM |
513 | ret = os_snprintf(buf + len, buflen - len, |
514 | "channel=%u\n" | |
515 | "secondary_channel=%d\n" | |
516 | "ieee80211n=%d\n" | |
517 | "ieee80211ac=%d\n" | |
518 | "vht_oper_chwidth=%d\n" | |
519 | "vht_oper_centr_freq_seg0_idx=%d\n" | |
520 | "vht_oper_centr_freq_seg1_idx=%d\n", | |
521 | iface->conf->channel, | |
522 | iface->conf->secondary_channel, | |
523 | iface->conf->ieee80211n, | |
524 | iface->conf->ieee80211ac, | |
525 | iface->conf->vht_oper_chwidth, | |
526 | iface->conf->vht_oper_centr_freq_seg0_idx, | |
527 | iface->conf->vht_oper_centr_freq_seg1_idx); | |
d85e1fc8 | 528 | if (os_snprintf_error(buflen - len, ret)) |
5ae6449c JM |
529 | return len; |
530 | len += ret; | |
531 | ||
532 | for (i = 0; i < iface->num_bss; i++) { | |
533 | struct hostapd_data *bss = iface->bss[i]; | |
534 | ret = os_snprintf(buf + len, buflen - len, | |
535 | "bss[%d]=%s\n" | |
536 | "bssid[%d]=" MACSTR "\n" | |
537 | "ssid[%d]=%s\n" | |
538 | "num_sta[%d]=%d\n", | |
539 | (int) i, bss->conf->iface, | |
540 | (int) i, MAC2STR(bss->own_addr), | |
541 | (int) i, | |
542 | wpa_ssid_txt(bss->conf->ssid.ssid, | |
543 | bss->conf->ssid.ssid_len), | |
544 | (int) i, bss->num_sta); | |
d85e1fc8 | 545 | if (os_snprintf_error(buflen - len, ret)) |
5ae6449c JM |
546 | return len; |
547 | len += ret; | |
548 | } | |
549 | ||
550 | return len; | |
551 | } | |
334bf36a AO |
552 | |
553 | ||
554 | int hostapd_parse_csa_settings(const char *pos, | |
555 | struct csa_settings *settings) | |
556 | { | |
557 | char *end; | |
558 | ||
334bf36a AO |
559 | os_memset(settings, 0, sizeof(*settings)); |
560 | settings->cs_count = strtol(pos, &end, 10); | |
561 | if (pos == end) { | |
562 | wpa_printf(MSG_ERROR, "chanswitch: invalid cs_count provided"); | |
563 | return -1; | |
564 | } | |
565 | ||
566 | settings->freq_params.freq = atoi(end); | |
567 | if (settings->freq_params.freq == 0) { | |
568 | wpa_printf(MSG_ERROR, "chanswitch: invalid freq provided"); | |
569 | return -1; | |
570 | } | |
571 | ||
572 | #define SET_CSA_SETTING(str) \ | |
573 | do { \ | |
574 | const char *pos2 = os_strstr(pos, " " #str "="); \ | |
575 | if (pos2) { \ | |
576 | pos2 += sizeof(" " #str "=") - 1; \ | |
577 | settings->freq_params.str = atoi(pos2); \ | |
578 | } \ | |
579 | } while (0) | |
580 | ||
581 | SET_CSA_SETTING(center_freq1); | |
582 | SET_CSA_SETTING(center_freq2); | |
583 | SET_CSA_SETTING(bandwidth); | |
584 | SET_CSA_SETTING(sec_channel_offset); | |
585 | settings->freq_params.ht_enabled = !!os_strstr(pos, " ht"); | |
586 | settings->freq_params.vht_enabled = !!os_strstr(pos, " vht"); | |
587 | settings->block_tx = !!os_strstr(pos, " blocktx"); | |
588 | #undef SET_CSA_SETTING | |
589 | ||
590 | return 0; | |
591 | } | |
99650cad JM |
592 | |
593 | ||
594 | int hostapd_ctrl_iface_stop_ap(struct hostapd_data *hapd) | |
595 | { | |
596 | return hostapd_drv_stop_ap(hapd); | |
597 | } | |
b8daac18 MH |
598 | |
599 | ||
600 | int hostapd_ctrl_iface_pmksa_list(struct hostapd_data *hapd, char *buf, | |
601 | size_t len) | |
602 | { | |
603 | return wpa_auth_pmksa_list(hapd->wpa_auth, buf, len); | |
604 | } | |
4c522c77 MH |
605 | |
606 | ||
607 | void hostapd_ctrl_iface_pmksa_flush(struct hostapd_data *hapd) | |
608 | { | |
609 | wpa_auth_pmksa_flush(hapd->wpa_auth); | |
610 | } |