2 * Control interface for shared AP commands
3 * Copyright (c) 2004-2019, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
9 #include "utils/includes.h"
11 #include "utils/common.h"
12 #include "common/ieee802_11_defs.h"
13 #include "common/sae.h"
14 #include "eapol_auth/eapol_auth_sm.h"
15 #include "fst/fst_ctrl_iface.h"
17 #include "ieee802_1x.h"
19 #include "ieee802_11.h"
21 #include "wps_hostapd.h"
22 #include "p2p_hostapd.h"
23 #include "ctrl_iface_ap.h"
24 #include "ap_drv_ops.h"
29 static size_t hostapd_write_ht_mcs_bitmask(char *buf, size_t buflen,
30 size_t curr_len, const u8 *mcs_set)
33 size_t len = curr_len;
35 ret = os_snprintf(buf + len, buflen - len,
37 if (os_snprintf_error(buflen - len, ret))
41 /* 77 first bits (+ 3 reserved bits) */
42 len += wpa_snprintf_hex(buf + len, buflen - len, mcs_set, 10);
44 ret = os_snprintf(buf + len, buflen - len, "\n");
45 if (os_snprintf_error(buflen - len, ret))
53 static int hostapd_get_sta_tx_rx(struct hostapd_data *hapd,
55 char *buf, size_t buflen)
57 struct hostap_sta_driver_data data;
61 if (hostapd_drv_read_sta_data(hapd, &data, sta->addr) < 0)
64 ret = os_snprintf(buf, buflen, "rx_packets=%lu\ntx_packets=%lu\n"
65 "rx_bytes=%llu\ntx_bytes=%llu\ninactive_msec=%lu\n"
67 data.rx_packets, data.tx_packets,
68 data.rx_bytes, data.tx_bytes, data.inactive_msec,
70 if (os_snprintf_error(buflen, ret))
74 ret = os_snprintf(buf + len, buflen - len, "rx_rate_info=%lu",
75 data.current_rx_rate);
76 if (os_snprintf_error(buflen - len, ret))
79 if (data.flags & STA_DRV_DATA_RX_MCS) {
80 ret = os_snprintf(buf + len, buflen - len, " mcs %u",
82 if (!os_snprintf_error(buflen - len, ret))
85 if (data.flags & STA_DRV_DATA_RX_VHT_MCS) {
86 ret = os_snprintf(buf + len, buflen - len, " vhtmcs %u",
88 if (!os_snprintf_error(buflen - len, ret))
91 if (data.flags & STA_DRV_DATA_RX_VHT_NSS) {
92 ret = os_snprintf(buf + len, buflen - len, " vhtnss %u",
94 if (!os_snprintf_error(buflen - len, ret))
97 if (data.flags & STA_DRV_DATA_RX_SHORT_GI) {
98 ret = os_snprintf(buf + len, buflen - len, " shortGI");
99 if (!os_snprintf_error(buflen - len, ret))
102 ret = os_snprintf(buf + len, buflen - len, "\n");
103 if (!os_snprintf_error(buflen - len, ret))
106 ret = os_snprintf(buf + len, buflen - len, "tx_rate_info=%lu",
107 data.current_tx_rate);
108 if (os_snprintf_error(buflen - len, ret))
111 if (data.flags & STA_DRV_DATA_TX_MCS) {
112 ret = os_snprintf(buf + len, buflen - len, " mcs %u",
114 if (!os_snprintf_error(buflen - len, ret))
117 if (data.flags & STA_DRV_DATA_TX_VHT_MCS) {
118 ret = os_snprintf(buf + len, buflen - len, " vhtmcs %u",
120 if (!os_snprintf_error(buflen - len, ret))
123 if (data.flags & STA_DRV_DATA_TX_VHT_NSS) {
124 ret = os_snprintf(buf + len, buflen - len, " vhtnss %u",
126 if (!os_snprintf_error(buflen - len, ret))
129 if (data.flags & STA_DRV_DATA_TX_SHORT_GI) {
130 ret = os_snprintf(buf + len, buflen - len, " shortGI");
131 if (!os_snprintf_error(buflen - len, ret))
134 ret = os_snprintf(buf + len, buflen - len, "\n");
135 if (!os_snprintf_error(buflen - len, ret))
138 if ((sta->flags & WLAN_STA_VHT) && sta->vht_capabilities) {
139 ret = os_snprintf(buf + len, buflen - len,
140 "rx_vht_mcs_map=%04x\n"
141 "tx_vht_mcs_map=%04x\n",
142 le_to_host16(sta->vht_capabilities->
143 vht_supported_mcs_set.rx_map),
144 le_to_host16(sta->vht_capabilities->
145 vht_supported_mcs_set.tx_map));
146 if (!os_snprintf_error(buflen - len, ret))
150 if ((sta->flags & WLAN_STA_HT) && sta->ht_capabilities) {
151 len = hostapd_write_ht_mcs_bitmask(buf, buflen, len,
152 sta->ht_capabilities->
156 if (data.flags & STA_DRV_DATA_LAST_ACK_RSSI) {
157 ret = os_snprintf(buf + len, buflen - len,
158 "last_ack_signal=%d\n", data.last_ack_rssi);
159 if (!os_snprintf_error(buflen - len, ret))
167 static int hostapd_get_sta_conn_time(struct sta_info *sta,
168 char *buf, size_t buflen)
170 struct os_reltime age;
173 if (!sta->connected_time.sec)
176 os_reltime_age(&sta->connected_time, &age);
178 ret = os_snprintf(buf, buflen, "connected_time=%u\n",
179 (unsigned int) age.sec);
180 if (os_snprintf_error(buflen, ret))
186 static const char * timeout_next_str(int val)
190 return "NULLFUNC POLL";
197 case STA_DISASSOC_FROM_CLI:
198 return "DISASSOC_FROM_CLI";
205 static int hostapd_ctrl_iface_sta_mib(struct hostapd_data *hapd,
206 struct sta_info *sta,
207 char *buf, size_t buflen)
209 int len, res, ret, i;
216 ret = os_snprintf(buf + len, buflen - len, MACSTR "\nflags=",
218 if (os_snprintf_error(buflen - len, ret))
222 ret = ap_sta_flags_txt(sta->flags, buf + len, buflen - len);
227 ret = os_snprintf(buf + len, buflen - len, "\naid=%d\ncapability=0x%x\n"
228 "listen_interval=%d\nsupported_rates=",
229 sta->aid, sta->capability, sta->listen_interval);
230 if (os_snprintf_error(buflen - len, ret))
234 for (i = 0; i < sta->supported_rates_len; i++) {
235 ret = os_snprintf(buf + len, buflen - len, "%02x%s",
236 sta->supported_rates[i],
237 i + 1 < sta->supported_rates_len ? " " : "");
238 if (os_snprintf_error(buflen - len, ret))
243 ret = os_snprintf(buf + len, buflen - len, "\ntimeout_next=%s\n",
244 timeout_next_str(sta->timeout_next));
245 if (os_snprintf_error(buflen - len, ret))
249 res = ieee802_11_get_mib_sta(hapd, sta, buf + len, buflen - len);
252 res = wpa_get_mib_sta(sta->wpa_sm, buf + len, buflen - len);
255 res = ieee802_1x_get_mib_sta(hapd, sta, buf + len, buflen - len);
258 res = hostapd_wps_get_mib_sta(hapd, sta->addr, buf + len,
262 res = hostapd_p2p_get_mib_sta(hapd, sta, buf + len, buflen - len);
266 len += hostapd_get_sta_tx_rx(hapd, sta, buf + len, buflen - len);
267 len += hostapd_get_sta_conn_time(sta, buf + len, buflen - len);
270 if (sta->sae && sta->sae->state == SAE_ACCEPTED) {
271 res = os_snprintf(buf + len, buflen - len, "sae_group=%d\n",
273 if (!os_snprintf_error(buflen - len, res))
276 #endif /* CONFIG_SAE */
278 if (sta->vlan_id > 0) {
279 res = os_snprintf(buf + len, buflen - len, "vlan_id=%d\n",
281 if (!os_snprintf_error(buflen - len, res))
285 res = mbo_ap_get_info(sta, buf + len, buflen - len);
289 if (sta->supp_op_classes &&
290 buflen - len > (unsigned) (17 + 2 * sta->supp_op_classes[0])) {
291 len += os_snprintf(buf + len, buflen - len, "supp_op_classes=");
292 len += wpa_snprintf_hex(buf + len, buflen - len,
293 sta->supp_op_classes + 1,
294 sta->supp_op_classes[0]);
295 len += os_snprintf(buf + len, buflen - len, "\n");
298 if (sta->power_capab) {
299 ret = os_snprintf(buf + len, buflen - len,
302 sta->min_tx_power, sta->max_tx_power);
303 if (!os_snprintf_error(buflen - len, ret))
307 #ifdef CONFIG_IEEE80211AC
308 if ((sta->flags & WLAN_STA_VHT) && sta->vht_capabilities) {
309 res = os_snprintf(buf + len, buflen - len,
310 "vht_caps_info=0x%08x\n",
311 le_to_host32(sta->vht_capabilities->
312 vht_capabilities_info));
313 if (!os_snprintf_error(buflen - len, res))
316 #endif /* CONFIG_IEEE80211AC */
318 #ifdef CONFIG_IEEE80211N
319 if ((sta->flags & WLAN_STA_HT) && sta->ht_capabilities) {
320 res = os_snprintf(buf + len, buflen - len,
321 "ht_caps_info=0x%04x\n",
322 le_to_host16(sta->ht_capabilities->
323 ht_capabilities_info));
324 if (!os_snprintf_error(buflen - len, res))
327 #endif /* CONFIG_IEEE80211N */
329 if (sta->ext_capability &&
330 buflen - len > (unsigned) (11 + 2 * sta->ext_capability[0])) {
331 len += os_snprintf(buf + len, buflen - len, "ext_capab=");
332 len += wpa_snprintf_hex(buf + len, buflen - len,
333 sta->ext_capability + 1,
334 sta->ext_capability[0]);
335 len += os_snprintf(buf + len, buflen - len, "\n");
338 if (sta->flags & WLAN_STA_WDS && sta->ifname_wds) {
339 ret = os_snprintf(buf + len, buflen - len,
340 "wds_sta_ifname=%s\n", sta->ifname_wds);
341 if (!os_snprintf_error(buflen - len, ret))
345 keyid = ap_sta_wpa_get_keyid(hapd, sta);
347 ret = os_snprintf(buf + len, buflen - len, "keyid=%s\n", keyid);
348 if (!os_snprintf_error(buflen - len, ret))
356 int hostapd_ctrl_iface_sta_first(struct hostapd_data *hapd,
357 char *buf, size_t buflen)
359 return hostapd_ctrl_iface_sta_mib(hapd, hapd->sta_list, buf, buflen);
363 int hostapd_ctrl_iface_sta(struct hostapd_data *hapd, const char *txtaddr,
364 char *buf, size_t buflen)
369 struct sta_info *sta;
371 if (hwaddr_aton(txtaddr, addr)) {
372 ret = os_snprintf(buf, buflen, "FAIL\n");
373 if (os_snprintf_error(buflen, ret))
378 sta = ap_get_sta(hapd, addr);
382 pos = os_strchr(txtaddr, ' ');
386 #ifdef HOSTAPD_DUMP_STATE
387 if (os_strcmp(pos, "eapol") == 0) {
388 if (sta->eapol_sm == NULL)
390 return eapol_auth_dump_state(sta->eapol_sm, buf,
393 #endif /* HOSTAPD_DUMP_STATE */
398 ret = hostapd_ctrl_iface_sta_mib(hapd, sta, buf, buflen);
399 ret += fst_ctrl_iface_mb_info(addr, buf + ret, buflen - ret);
405 int hostapd_ctrl_iface_sta_next(struct hostapd_data *hapd, const char *txtaddr,
406 char *buf, size_t buflen)
409 struct sta_info *sta;
412 if (hwaddr_aton(txtaddr, addr) ||
413 (sta = ap_get_sta(hapd, addr)) == NULL) {
414 ret = os_snprintf(buf, buflen, "FAIL\n");
415 if (os_snprintf_error(buflen, ret))
423 return hostapd_ctrl_iface_sta_mib(hapd, sta->next, buf, buflen);
427 #ifdef CONFIG_P2P_MANAGER
428 static int p2p_manager_disconnect(struct hostapd_data *hapd, u16 stype,
429 u8 minor_reason_code, const u8 *addr)
431 struct ieee80211_mgmt *mgmt;
435 if (!hapd->drv_priv || !hapd->driver->send_frame)
438 mgmt = os_zalloc(sizeof(*mgmt) + 100);
442 mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, stype);
443 wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "P2P: Disconnect STA " MACSTR
444 " with minor reason code %u (stype=%u (%s))",
445 MAC2STR(addr), minor_reason_code, stype,
446 fc2str(le_to_host16(mgmt->frame_control)));
448 os_memcpy(mgmt->da, addr, ETH_ALEN);
449 os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
450 os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
451 if (stype == WLAN_FC_STYPE_DEAUTH) {
452 mgmt->u.deauth.reason_code =
453 host_to_le16(WLAN_REASON_PREV_AUTH_NOT_VALID);
454 pos = mgmt->u.deauth.variable;
456 mgmt->u.disassoc.reason_code =
457 host_to_le16(WLAN_REASON_PREV_AUTH_NOT_VALID);
458 pos = mgmt->u.disassoc.variable;
461 *pos++ = WLAN_EID_VENDOR_SPECIFIC;
463 WPA_PUT_BE32(pos, P2P_IE_VENDOR_TYPE);
466 *pos++ = P2P_ATTR_MINOR_REASON_CODE;
467 WPA_PUT_LE16(pos, 1);
469 *pos++ = minor_reason_code;
471 ret = hapd->driver->send_frame(hapd->drv_priv, (u8 *) mgmt,
472 pos - (u8 *) mgmt, 1);
475 return ret < 0 ? -1 : 0;
477 #endif /* CONFIG_P2P_MANAGER */
480 int hostapd_ctrl_iface_deauthenticate(struct hostapd_data *hapd,
484 struct sta_info *sta;
486 u16 reason = WLAN_REASON_PREV_AUTH_NOT_VALID;
488 wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "CTRL_IFACE DEAUTHENTICATE %s",
491 if (hwaddr_aton(txtaddr, addr))
494 pos = os_strstr(txtaddr, " reason=");
496 reason = atoi(pos + 8);
498 pos = os_strstr(txtaddr, " test=");
500 struct ieee80211_mgmt mgmt;
502 if (!hapd->drv_priv || !hapd->driver->send_frame)
506 os_memset(&mgmt, 0, sizeof(mgmt));
507 mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
508 WLAN_FC_STYPE_DEAUTH);
509 os_memcpy(mgmt.da, addr, ETH_ALEN);
510 os_memcpy(mgmt.sa, hapd->own_addr, ETH_ALEN);
511 os_memcpy(mgmt.bssid, hapd->own_addr, ETH_ALEN);
512 mgmt.u.deauth.reason_code = host_to_le16(reason);
513 if (hapd->driver->send_frame(hapd->drv_priv, (u8 *) &mgmt,
515 sizeof(mgmt.u.deauth),
521 #ifdef CONFIG_P2P_MANAGER
522 pos = os_strstr(txtaddr, " p2p=");
524 return p2p_manager_disconnect(hapd, WLAN_FC_STYPE_DEAUTH,
525 atoi(pos + 5), addr);
527 #endif /* CONFIG_P2P_MANAGER */
529 if (os_strstr(txtaddr, " tx=0"))
530 hostapd_drv_sta_remove(hapd, addr);
532 hostapd_drv_sta_deauth(hapd, addr, reason);
533 sta = ap_get_sta(hapd, addr);
535 ap_sta_deauthenticate(hapd, sta, reason);
536 else if (addr[0] == 0xff)
537 hostapd_free_stas(hapd);
543 int hostapd_ctrl_iface_disassociate(struct hostapd_data *hapd,
547 struct sta_info *sta;
549 u16 reason = WLAN_REASON_PREV_AUTH_NOT_VALID;
551 wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "CTRL_IFACE DISASSOCIATE %s",
554 if (hwaddr_aton(txtaddr, addr))
557 pos = os_strstr(txtaddr, " reason=");
559 reason = atoi(pos + 8);
561 pos = os_strstr(txtaddr, " test=");
563 struct ieee80211_mgmt mgmt;
565 if (!hapd->drv_priv || !hapd->driver->send_frame)
569 os_memset(&mgmt, 0, sizeof(mgmt));
570 mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
571 WLAN_FC_STYPE_DISASSOC);
572 os_memcpy(mgmt.da, addr, ETH_ALEN);
573 os_memcpy(mgmt.sa, hapd->own_addr, ETH_ALEN);
574 os_memcpy(mgmt.bssid, hapd->own_addr, ETH_ALEN);
575 mgmt.u.disassoc.reason_code = host_to_le16(reason);
576 if (hapd->driver->send_frame(hapd->drv_priv, (u8 *) &mgmt,
578 sizeof(mgmt.u.deauth),
584 #ifdef CONFIG_P2P_MANAGER
585 pos = os_strstr(txtaddr, " p2p=");
587 return p2p_manager_disconnect(hapd, WLAN_FC_STYPE_DISASSOC,
588 atoi(pos + 5), addr);
590 #endif /* CONFIG_P2P_MANAGER */
592 if (os_strstr(txtaddr, " tx=0"))
593 hostapd_drv_sta_remove(hapd, addr);
595 hostapd_drv_sta_disassoc(hapd, addr, reason);
596 sta = ap_get_sta(hapd, addr);
598 ap_sta_disassociate(hapd, sta, reason);
599 else if (addr[0] == 0xff)
600 hostapd_free_stas(hapd);
606 #ifdef CONFIG_TAXONOMY
607 int hostapd_ctrl_iface_signature(struct hostapd_data *hapd,
609 char *buf, size_t buflen)
612 struct sta_info *sta;
614 wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "CTRL_IFACE SIGNATURE %s", txtaddr);
616 if (hwaddr_aton(txtaddr, addr))
619 sta = ap_get_sta(hapd, addr);
623 return retrieve_sta_taxonomy(hapd, sta, buf, buflen);
625 #endif /* CONFIG_TAXONOMY */
628 int hostapd_ctrl_iface_poll_sta(struct hostapd_data *hapd,
632 struct sta_info *sta;
634 wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "CTRL_IFACE POLL_STA %s", txtaddr);
636 if (hwaddr_aton(txtaddr, addr))
639 sta = ap_get_sta(hapd, addr);
643 hostapd_drv_poll_client(hapd, hapd->own_addr, addr,
644 sta->flags & WLAN_STA_WMM);
649 int hostapd_ctrl_iface_status(struct hostapd_data *hapd, char *buf,
652 struct hostapd_iface *iface = hapd->iface;
653 struct hostapd_hw_modes *mode = iface->current_mode;
657 ret = os_snprintf(buf + len, buflen - len,
661 "num_sta_non_erp=%d\n"
662 "num_sta_no_short_slot_time=%d\n"
663 "num_sta_no_short_preamble=%d\n"
665 "num_sta_ht_no_gf=%d\n"
667 "num_sta_ht_20_mhz=%d\n"
668 "num_sta_ht40_intolerant=%d\n"
671 hostapd_state_text(iface->state),
674 iface->num_sta_non_erp,
675 iface->num_sta_no_short_slot_time,
676 iface->num_sta_no_short_preamble,
678 iface->num_sta_ht_no_gf,
679 iface->num_sta_no_ht,
680 iface->num_sta_ht_20mhz,
681 iface->num_sta_ht40_intolerant,
684 if (os_snprintf_error(buflen - len, ret))
688 if (!iface->cac_started || !iface->dfs_cac_ms) {
689 ret = os_snprintf(buf + len, buflen - len,
690 "cac_time_seconds=%d\n"
691 "cac_time_left_seconds=N/A\n",
692 iface->dfs_cac_ms / 1000);
694 /* CAC started and CAC time set - calculate remaining time */
695 struct os_reltime now;
696 unsigned int left_time;
698 os_reltime_age(&iface->dfs_cac_start, &now);
699 left_time = iface->dfs_cac_ms / 1000 - now.sec;
700 ret = os_snprintf(buf + len, buflen - len,
701 "cac_time_seconds=%u\n"
702 "cac_time_left_seconds=%u\n",
703 iface->dfs_cac_ms / 1000,
706 if (os_snprintf_error(buflen - len, ret))
710 ret = os_snprintf(buf + len, buflen - len,
712 "secondary_channel=%d\n"
717 iface->conf->channel,
718 iface->conf->ieee80211n && !hapd->conf->disable_11n ?
719 iface->conf->secondary_channel : 0,
720 iface->conf->ieee80211n && !hapd->conf->disable_11n,
721 iface->conf->ieee80211ac &&
722 !hapd->conf->disable_11ac,
723 iface->conf->beacon_int,
724 hapd->conf->dtim_period);
725 if (os_snprintf_error(buflen - len, ret))
728 if (iface->conf->ieee80211ac && !hapd->conf->disable_11ac) {
729 ret = os_snprintf(buf + len, buflen - len,
730 "vht_oper_chwidth=%d\n"
731 "vht_oper_centr_freq_seg0_idx=%d\n"
732 "vht_oper_centr_freq_seg1_idx=%d\n"
733 "vht_caps_info=%08x\n",
734 iface->conf->vht_oper_chwidth,
735 iface->conf->vht_oper_centr_freq_seg0_idx,
736 iface->conf->vht_oper_centr_freq_seg1_idx,
737 iface->conf->vht_capab);
738 if (os_snprintf_error(buflen - len, ret))
743 if (iface->conf->ieee80211ac && !hapd->conf->disable_11ac && mode) {
744 u16 rxmap = WPA_GET_LE16(&mode->vht_mcs_set[0]);
745 u16 txmap = WPA_GET_LE16(&mode->vht_mcs_set[4]);
747 ret = os_snprintf(buf + len, buflen - len,
748 "rx_vht_mcs_map=%04x\n"
749 "tx_vht_mcs_map=%04x\n",
751 if (os_snprintf_error(buflen - len, ret))
756 if (iface->conf->ieee80211n && !hapd->conf->disable_11n) {
757 ret = os_snprintf(buf + len, buflen - len,
758 "ht_caps_info=%04x\n",
759 hapd->iconf->ht_capab);
760 if (os_snprintf_error(buflen - len, ret))
765 if (iface->conf->ieee80211n && !hapd->conf->disable_11n && mode) {
766 len = hostapd_write_ht_mcs_bitmask(buf, buflen, len,
770 if (iface->current_rates && iface->num_rates) {
771 ret = os_snprintf(buf + len, buflen - len, "supported_rates=");
772 if (os_snprintf_error(buflen - len, ret))
776 for (j = 0; j < iface->num_rates; j++) {
777 ret = os_snprintf(buf + len, buflen - len, "%s%02x",
779 iface->current_rates[j].rate / 5);
780 if (os_snprintf_error(buflen - len, ret))
784 ret = os_snprintf(buf + len, buflen - len, "\n");
785 if (os_snprintf_error(buflen - len, ret))
790 for (j = 0; mode && j < mode->num_channels; j++) {
791 if (mode->channels[j].freq == iface->freq) {
792 ret = os_snprintf(buf + len, buflen - len,
794 mode->channels[j].max_tx_power);
795 if (os_snprintf_error(buflen - len, ret))
802 for (i = 0; i < iface->num_bss; i++) {
803 struct hostapd_data *bss = iface->bss[i];
804 ret = os_snprintf(buf + len, buflen - len,
806 "bssid[%d]=" MACSTR "\n"
809 (int) i, bss->conf->iface,
810 (int) i, MAC2STR(bss->own_addr),
812 wpa_ssid_txt(bss->conf->ssid.ssid,
813 bss->conf->ssid.ssid_len),
814 (int) i, bss->num_sta);
815 if (os_snprintf_error(buflen - len, ret))
820 if (hapd->conf->chan_util_avg_period) {
821 ret = os_snprintf(buf + len, buflen - len,
822 "chan_util_avg=%u\n",
823 iface->chan_util_average);
824 if (os_snprintf_error(buflen - len, ret))
833 int hostapd_parse_csa_settings(const char *pos,
834 struct csa_settings *settings)
838 os_memset(settings, 0, sizeof(*settings));
839 settings->cs_count = strtol(pos, &end, 10);
841 wpa_printf(MSG_ERROR, "chanswitch: invalid cs_count provided");
845 settings->freq_params.freq = atoi(end);
846 if (settings->freq_params.freq == 0) {
847 wpa_printf(MSG_ERROR, "chanswitch: invalid freq provided");
851 #define SET_CSA_SETTING(str) \
853 const char *pos2 = os_strstr(pos, " " #str "="); \
855 pos2 += sizeof(" " #str "=") - 1; \
856 settings->freq_params.str = atoi(pos2); \
860 SET_CSA_SETTING(center_freq1);
861 SET_CSA_SETTING(center_freq2);
862 SET_CSA_SETTING(bandwidth);
863 SET_CSA_SETTING(sec_channel_offset);
864 settings->freq_params.ht_enabled = !!os_strstr(pos, " ht");
865 settings->freq_params.vht_enabled = !!os_strstr(pos, " vht");
866 settings->block_tx = !!os_strstr(pos, " blocktx");
867 #undef SET_CSA_SETTING
873 int hostapd_ctrl_iface_stop_ap(struct hostapd_data *hapd)
875 return hostapd_drv_stop_ap(hapd);
879 int hostapd_ctrl_iface_pmksa_list(struct hostapd_data *hapd, char *buf,
882 return wpa_auth_pmksa_list(hapd->wpa_auth, buf, len);
886 void hostapd_ctrl_iface_pmksa_flush(struct hostapd_data *hapd)
888 wpa_auth_pmksa_flush(hapd->wpa_auth);
892 int hostapd_ctrl_iface_pmksa_add(struct hostapd_data *hapd, char *cmd)
899 int akmp = 0, expiration = 0;
903 * <STA addr> <PMKID> <PMK> <expiration in seconds> <akmp>
906 if (hwaddr_aton(cmd, spa))
909 pos = os_strchr(cmd, ' ');
914 if (hexstr2bin(pos, pmkid, PMKID_LEN) < 0)
917 pos = os_strchr(pos, ' ');
922 pos2 = os_strchr(pos, ' ');
925 pmk_len = (pos2 - pos) / 2;
926 if (pmk_len < PMK_LEN || pmk_len > PMK_LEN_MAX ||
927 hexstr2bin(pos, pmk, pmk_len) < 0)
932 if (sscanf(pos, "%d %d", &expiration, &akmp) != 2)
935 return wpa_auth_pmksa_add2(hapd->wpa_auth, spa, pmk, pmk_len,
936 pmkid, expiration, akmp);
940 #ifdef CONFIG_PMKSA_CACHE_EXTERNAL
943 int hostapd_ctrl_iface_pmksa_list_mesh(struct hostapd_data *hapd,
944 const u8 *addr, char *buf, size_t len)
946 return wpa_auth_pmksa_list_mesh(hapd->wpa_auth, addr, buf, len);
950 void * hostapd_ctrl_iface_pmksa_create_entry(const u8 *aa, char *cmd)
960 * <BSSID> <PMKID> <PMK> <expiration in seconds>
963 if (hwaddr_aton(cmd, spa))
966 pos = os_strchr(cmd, ' ');
971 if (hexstr2bin(pos, pmkid, PMKID_LEN) < 0)
974 pos = os_strchr(pos, ' ');
979 if (hexstr2bin(pos, pmk, PMK_LEN) < 0)
982 pos = os_strchr(pos, ' ');
987 if (sscanf(pos, "%d", &expiration) != 1)
990 return wpa_auth_pmksa_create_entry(aa, spa, pmk, pmkid, expiration);
993 #endif /* CONFIG_MESH */
994 #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */