1e28a4053SRui Paulo /*
2e28a4053SRui Paulo * Control interface for shared AP commands
34bc52338SCy Schubert * Copyright (c) 2004-2019, Jouni Malinen <j@w1.fi>
4e28a4053SRui Paulo *
5f05cddf9SRui Paulo * This software may be distributed under the terms of the BSD license.
6f05cddf9SRui Paulo * See README for more details.
7e28a4053SRui Paulo */
8e28a4053SRui Paulo
9e28a4053SRui Paulo #include "utils/includes.h"
10e28a4053SRui Paulo
11e28a4053SRui Paulo #include "utils/common.h"
12f05cddf9SRui Paulo #include "common/ieee802_11_defs.h"
135b9c547cSRui Paulo #include "common/sae.h"
145b9c547cSRui Paulo #include "eapol_auth/eapol_auth_sm.h"
15325151a3SRui Paulo #include "fst/fst_ctrl_iface.h"
16e28a4053SRui Paulo #include "hostapd.h"
17e28a4053SRui Paulo #include "ieee802_1x.h"
18e28a4053SRui Paulo #include "wpa_auth.h"
19e28a4053SRui Paulo #include "ieee802_11.h"
20e28a4053SRui Paulo #include "sta_info.h"
21e28a4053SRui Paulo #include "wps_hostapd.h"
22f05cddf9SRui Paulo #include "p2p_hostapd.h"
23e28a4053SRui Paulo #include "ctrl_iface_ap.h"
24f05cddf9SRui Paulo #include "ap_drv_ops.h"
25780fb4a2SCy Schubert #include "mbo_ap.h"
26780fb4a2SCy Schubert #include "taxonomy.h"
27*a90b9d01SCy Schubert #include "wnm_ap.h"
28f05cddf9SRui Paulo
29f05cddf9SRui Paulo
hostapd_write_ht_mcs_bitmask(char * buf,size_t buflen,size_t curr_len,const u8 * mcs_set)3085732ac8SCy Schubert static size_t hostapd_write_ht_mcs_bitmask(char *buf, size_t buflen,
3185732ac8SCy Schubert size_t curr_len, const u8 *mcs_set)
3285732ac8SCy Schubert {
3385732ac8SCy Schubert int ret;
3485732ac8SCy Schubert size_t len = curr_len;
3585732ac8SCy Schubert
3685732ac8SCy Schubert ret = os_snprintf(buf + len, buflen - len,
3785732ac8SCy Schubert "ht_mcs_bitmask=");
3885732ac8SCy Schubert if (os_snprintf_error(buflen - len, ret))
3985732ac8SCy Schubert return len;
4085732ac8SCy Schubert len += ret;
4185732ac8SCy Schubert
4285732ac8SCy Schubert /* 77 first bits (+ 3 reserved bits) */
4385732ac8SCy Schubert len += wpa_snprintf_hex(buf + len, buflen - len, mcs_set, 10);
4485732ac8SCy Schubert
4585732ac8SCy Schubert ret = os_snprintf(buf + len, buflen - len, "\n");
4685732ac8SCy Schubert if (os_snprintf_error(buflen - len, ret))
4785732ac8SCy Schubert return curr_len;
4885732ac8SCy Schubert len += ret;
4985732ac8SCy Schubert
5085732ac8SCy Schubert return len;
5185732ac8SCy Schubert }
5285732ac8SCy Schubert
5385732ac8SCy Schubert
hostapd_get_sta_conn_time(struct sta_info * sta,struct hostap_sta_driver_data * data,char * buf,size_t buflen)544b72b91aSCy Schubert static int hostapd_get_sta_conn_time(struct sta_info *sta,
554b72b91aSCy Schubert struct hostap_sta_driver_data *data,
564b72b91aSCy Schubert char *buf, size_t buflen)
574b72b91aSCy Schubert {
584b72b91aSCy Schubert struct os_reltime age;
594b72b91aSCy Schubert unsigned long secs;
604b72b91aSCy Schubert int ret;
614b72b91aSCy Schubert
624b72b91aSCy Schubert if (sta->connected_time.sec) {
634b72b91aSCy Schubert /* Locally maintained time in AP mode */
644b72b91aSCy Schubert os_reltime_age(&sta->connected_time, &age);
654b72b91aSCy Schubert secs = (unsigned long) age.sec;
664b72b91aSCy Schubert } else if (data->flags & STA_DRV_DATA_CONN_TIME) {
674b72b91aSCy Schubert /* Time from the driver in mesh mode */
684b72b91aSCy Schubert secs = data->connected_sec;
694b72b91aSCy Schubert } else {
704b72b91aSCy Schubert return 0;
714b72b91aSCy Schubert }
724b72b91aSCy Schubert
734b72b91aSCy Schubert ret = os_snprintf(buf, buflen, "connected_time=%lu\n", secs);
744b72b91aSCy Schubert if (os_snprintf_error(buflen, ret))
754b72b91aSCy Schubert return 0;
764b72b91aSCy Schubert return ret;
774b72b91aSCy Schubert }
784b72b91aSCy Schubert
794b72b91aSCy Schubert
hostapd_get_sta_info(struct hostapd_data * hapd,struct sta_info * sta,char * buf,size_t buflen)804b72b91aSCy Schubert static int hostapd_get_sta_info(struct hostapd_data *hapd,
815b9c547cSRui Paulo struct sta_info *sta,
825b9c547cSRui Paulo char *buf, size_t buflen)
835b9c547cSRui Paulo {
845b9c547cSRui Paulo struct hostap_sta_driver_data data;
855b9c547cSRui Paulo int ret;
8685732ac8SCy Schubert int len = 0;
875b9c547cSRui Paulo
885b9c547cSRui Paulo if (hostapd_drv_read_sta_data(hapd, &data, sta->addr) < 0)
895b9c547cSRui Paulo return 0;
905b9c547cSRui Paulo
915b9c547cSRui Paulo ret = os_snprintf(buf, buflen, "rx_packets=%lu\ntx_packets=%lu\n"
9285732ac8SCy Schubert "rx_bytes=%llu\ntx_bytes=%llu\ninactive_msec=%lu\n"
9385732ac8SCy Schubert "signal=%d\n",
945b9c547cSRui Paulo data.rx_packets, data.tx_packets,
9585732ac8SCy Schubert data.rx_bytes, data.tx_bytes, data.inactive_msec,
9685732ac8SCy Schubert data.signal);
975b9c547cSRui Paulo if (os_snprintf_error(buflen, ret))
985b9c547cSRui Paulo return 0;
9985732ac8SCy Schubert len += ret;
10085732ac8SCy Schubert
10185732ac8SCy Schubert ret = os_snprintf(buf + len, buflen - len, "rx_rate_info=%lu",
102*a90b9d01SCy Schubert data.current_rx_rate / 100);
10385732ac8SCy Schubert if (os_snprintf_error(buflen - len, ret))
10485732ac8SCy Schubert return len;
10585732ac8SCy Schubert len += ret;
10685732ac8SCy Schubert if (data.flags & STA_DRV_DATA_RX_MCS) {
10785732ac8SCy Schubert ret = os_snprintf(buf + len, buflen - len, " mcs %u",
10885732ac8SCy Schubert data.rx_mcs);
10985732ac8SCy Schubert if (!os_snprintf_error(buflen - len, ret))
11085732ac8SCy Schubert len += ret;
11185732ac8SCy Schubert }
11285732ac8SCy Schubert if (data.flags & STA_DRV_DATA_RX_VHT_MCS) {
11385732ac8SCy Schubert ret = os_snprintf(buf + len, buflen - len, " vhtmcs %u",
11485732ac8SCy Schubert data.rx_vhtmcs);
11585732ac8SCy Schubert if (!os_snprintf_error(buflen - len, ret))
11685732ac8SCy Schubert len += ret;
11785732ac8SCy Schubert }
11885732ac8SCy Schubert if (data.flags & STA_DRV_DATA_RX_VHT_NSS) {
11985732ac8SCy Schubert ret = os_snprintf(buf + len, buflen - len, " vhtnss %u",
12085732ac8SCy Schubert data.rx_vht_nss);
12185732ac8SCy Schubert if (!os_snprintf_error(buflen - len, ret))
12285732ac8SCy Schubert len += ret;
12385732ac8SCy Schubert }
12485732ac8SCy Schubert if (data.flags & STA_DRV_DATA_RX_SHORT_GI) {
12585732ac8SCy Schubert ret = os_snprintf(buf + len, buflen - len, " shortGI");
12685732ac8SCy Schubert if (!os_snprintf_error(buflen - len, ret))
12785732ac8SCy Schubert len += ret;
12885732ac8SCy Schubert }
12985732ac8SCy Schubert ret = os_snprintf(buf + len, buflen - len, "\n");
13085732ac8SCy Schubert if (!os_snprintf_error(buflen - len, ret))
13185732ac8SCy Schubert len += ret;
13285732ac8SCy Schubert
13385732ac8SCy Schubert ret = os_snprintf(buf + len, buflen - len, "tx_rate_info=%lu",
134*a90b9d01SCy Schubert data.current_tx_rate / 100);
13585732ac8SCy Schubert if (os_snprintf_error(buflen - len, ret))
13685732ac8SCy Schubert return len;
13785732ac8SCy Schubert len += ret;
13885732ac8SCy Schubert if (data.flags & STA_DRV_DATA_TX_MCS) {
13985732ac8SCy Schubert ret = os_snprintf(buf + len, buflen - len, " mcs %u",
14085732ac8SCy Schubert data.tx_mcs);
14185732ac8SCy Schubert if (!os_snprintf_error(buflen - len, ret))
14285732ac8SCy Schubert len += ret;
14385732ac8SCy Schubert }
14485732ac8SCy Schubert if (data.flags & STA_DRV_DATA_TX_VHT_MCS) {
14585732ac8SCy Schubert ret = os_snprintf(buf + len, buflen - len, " vhtmcs %u",
14685732ac8SCy Schubert data.tx_vhtmcs);
14785732ac8SCy Schubert if (!os_snprintf_error(buflen - len, ret))
14885732ac8SCy Schubert len += ret;
14985732ac8SCy Schubert }
15085732ac8SCy Schubert if (data.flags & STA_DRV_DATA_TX_VHT_NSS) {
15185732ac8SCy Schubert ret = os_snprintf(buf + len, buflen - len, " vhtnss %u",
15285732ac8SCy Schubert data.tx_vht_nss);
15385732ac8SCy Schubert if (!os_snprintf_error(buflen - len, ret))
15485732ac8SCy Schubert len += ret;
15585732ac8SCy Schubert }
15685732ac8SCy Schubert if (data.flags & STA_DRV_DATA_TX_SHORT_GI) {
15785732ac8SCy Schubert ret = os_snprintf(buf + len, buflen - len, " shortGI");
15885732ac8SCy Schubert if (!os_snprintf_error(buflen - len, ret))
15985732ac8SCy Schubert len += ret;
16085732ac8SCy Schubert }
16185732ac8SCy Schubert ret = os_snprintf(buf + len, buflen - len, "\n");
16285732ac8SCy Schubert if (!os_snprintf_error(buflen - len, ret))
16385732ac8SCy Schubert len += ret;
16485732ac8SCy Schubert
16585732ac8SCy Schubert if ((sta->flags & WLAN_STA_VHT) && sta->vht_capabilities) {
16685732ac8SCy Schubert ret = os_snprintf(buf + len, buflen - len,
16785732ac8SCy Schubert "rx_vht_mcs_map=%04x\n"
16885732ac8SCy Schubert "tx_vht_mcs_map=%04x\n",
16985732ac8SCy Schubert le_to_host16(sta->vht_capabilities->
17085732ac8SCy Schubert vht_supported_mcs_set.rx_map),
17185732ac8SCy Schubert le_to_host16(sta->vht_capabilities->
17285732ac8SCy Schubert vht_supported_mcs_set.tx_map));
17385732ac8SCy Schubert if (!os_snprintf_error(buflen - len, ret))
17485732ac8SCy Schubert len += ret;
17585732ac8SCy Schubert }
17685732ac8SCy Schubert
17785732ac8SCy Schubert if ((sta->flags & WLAN_STA_HT) && sta->ht_capabilities) {
17885732ac8SCy Schubert len = hostapd_write_ht_mcs_bitmask(buf, buflen, len,
17985732ac8SCy Schubert sta->ht_capabilities->
18085732ac8SCy Schubert supported_mcs_set);
18185732ac8SCy Schubert }
18285732ac8SCy Schubert
18385732ac8SCy Schubert if (data.flags & STA_DRV_DATA_LAST_ACK_RSSI) {
18485732ac8SCy Schubert ret = os_snprintf(buf + len, buflen - len,
18585732ac8SCy Schubert "last_ack_signal=%d\n", data.last_ack_rssi);
18685732ac8SCy Schubert if (!os_snprintf_error(buflen - len, ret))
18785732ac8SCy Schubert len += ret;
18885732ac8SCy Schubert }
18985732ac8SCy Schubert
1904b72b91aSCy Schubert len += hostapd_get_sta_conn_time(sta, &data, buf + len, buflen - len);
1914b72b91aSCy Schubert
19285732ac8SCy Schubert return len;
1935b9c547cSRui Paulo }
1945b9c547cSRui Paulo
1955b9c547cSRui Paulo
timeout_next_str(int val)1965b9c547cSRui Paulo static const char * timeout_next_str(int val)
1975b9c547cSRui Paulo {
1985b9c547cSRui Paulo switch (val) {
1995b9c547cSRui Paulo case STA_NULLFUNC:
2005b9c547cSRui Paulo return "NULLFUNC POLL";
2015b9c547cSRui Paulo case STA_DISASSOC:
2025b9c547cSRui Paulo return "DISASSOC";
2035b9c547cSRui Paulo case STA_DEAUTH:
2045b9c547cSRui Paulo return "DEAUTH";
2055b9c547cSRui Paulo case STA_REMOVE:
2065b9c547cSRui Paulo return "REMOVE";
2075b9c547cSRui Paulo case STA_DISASSOC_FROM_CLI:
2085b9c547cSRui Paulo return "DISASSOC_FROM_CLI";
209*a90b9d01SCy Schubert default:
210*a90b9d01SCy Schubert return "?";
211*a90b9d01SCy Schubert }
2125b9c547cSRui Paulo }
2135b9c547cSRui Paulo
214*a90b9d01SCy Schubert
hw_mode_str(enum hostapd_hw_mode mode)215*a90b9d01SCy Schubert static const char * hw_mode_str(enum hostapd_hw_mode mode)
216*a90b9d01SCy Schubert {
217*a90b9d01SCy Schubert switch (mode) {
218*a90b9d01SCy Schubert case HOSTAPD_MODE_IEEE80211B:
219*a90b9d01SCy Schubert return "b";
220*a90b9d01SCy Schubert case HOSTAPD_MODE_IEEE80211G:
221*a90b9d01SCy Schubert return "g";
222*a90b9d01SCy Schubert case HOSTAPD_MODE_IEEE80211A:
223*a90b9d01SCy Schubert return "a";
224*a90b9d01SCy Schubert case HOSTAPD_MODE_IEEE80211AD:
225*a90b9d01SCy Schubert return "ad";
226*a90b9d01SCy Schubert case HOSTAPD_MODE_IEEE80211ANY:
227*a90b9d01SCy Schubert return "any";
228*a90b9d01SCy Schubert case NUM_HOSTAPD_MODES:
229*a90b9d01SCy Schubert return "invalid";
230*a90b9d01SCy Schubert }
231*a90b9d01SCy Schubert return "unknown";
232f05cddf9SRui Paulo }
233e28a4053SRui Paulo
234e28a4053SRui Paulo
hostapd_ctrl_iface_sta_mib(struct hostapd_data * hapd,struct sta_info * sta,char * buf,size_t buflen)235e28a4053SRui Paulo static int hostapd_ctrl_iface_sta_mib(struct hostapd_data *hapd,
236e28a4053SRui Paulo struct sta_info *sta,
237e28a4053SRui Paulo char *buf, size_t buflen)
238e28a4053SRui Paulo {
2395b9c547cSRui Paulo int len, res, ret, i;
2404bc52338SCy Schubert const char *keyid;
241*a90b9d01SCy Schubert const u8 *dpp_pkhash;
242e28a4053SRui Paulo
2435b9c547cSRui Paulo if (!sta)
244e28a4053SRui Paulo return 0;
245e28a4053SRui Paulo
246e28a4053SRui Paulo len = 0;
2475b9c547cSRui Paulo ret = os_snprintf(buf + len, buflen - len, MACSTR "\nflags=",
248e28a4053SRui Paulo MAC2STR(sta->addr));
2495b9c547cSRui Paulo if (os_snprintf_error(buflen - len, ret))
2505b9c547cSRui Paulo return len;
2515b9c547cSRui Paulo len += ret;
2525b9c547cSRui Paulo
2535b9c547cSRui Paulo ret = ap_sta_flags_txt(sta->flags, buf + len, buflen - len);
2545b9c547cSRui Paulo if (ret < 0)
2555b9c547cSRui Paulo return len;
2565b9c547cSRui Paulo len += ret;
2575b9c547cSRui Paulo
2585b9c547cSRui Paulo ret = os_snprintf(buf + len, buflen - len, "\naid=%d\ncapability=0x%x\n"
2595b9c547cSRui Paulo "listen_interval=%d\nsupported_rates=",
2605b9c547cSRui Paulo sta->aid, sta->capability, sta->listen_interval);
2615b9c547cSRui Paulo if (os_snprintf_error(buflen - len, ret))
2625b9c547cSRui Paulo return len;
2635b9c547cSRui Paulo len += ret;
2645b9c547cSRui Paulo
2655b9c547cSRui Paulo for (i = 0; i < sta->supported_rates_len; i++) {
2665b9c547cSRui Paulo ret = os_snprintf(buf + len, buflen - len, "%02x%s",
2675b9c547cSRui Paulo sta->supported_rates[i],
2685b9c547cSRui Paulo i + 1 < sta->supported_rates_len ? " " : "");
2695b9c547cSRui Paulo if (os_snprintf_error(buflen - len, ret))
2705b9c547cSRui Paulo return len;
2715b9c547cSRui Paulo len += ret;
2725b9c547cSRui Paulo }
2735b9c547cSRui Paulo
2745b9c547cSRui Paulo ret = os_snprintf(buf + len, buflen - len, "\ntimeout_next=%s\n",
2755b9c547cSRui Paulo timeout_next_str(sta->timeout_next));
2765b9c547cSRui Paulo if (os_snprintf_error(buflen - len, ret))
277e28a4053SRui Paulo return len;
278e28a4053SRui Paulo len += ret;
279e28a4053SRui Paulo
280*a90b9d01SCy Schubert if (sta->max_idle_period) {
281*a90b9d01SCy Schubert ret = os_snprintf(buf + len, buflen - len,
282*a90b9d01SCy Schubert "max_idle_period=%d\n", sta->max_idle_period);
283*a90b9d01SCy Schubert if (os_snprintf_error(buflen - len, ret))
284*a90b9d01SCy Schubert return len;
285*a90b9d01SCy Schubert len += ret;
286*a90b9d01SCy Schubert }
287*a90b9d01SCy Schubert
288e28a4053SRui Paulo res = ieee802_11_get_mib_sta(hapd, sta, buf + len, buflen - len);
289e28a4053SRui Paulo if (res >= 0)
290e28a4053SRui Paulo len += res;
291e28a4053SRui Paulo res = wpa_get_mib_sta(sta->wpa_sm, buf + len, buflen - len);
292e28a4053SRui Paulo if (res >= 0)
293e28a4053SRui Paulo len += res;
294e28a4053SRui Paulo res = ieee802_1x_get_mib_sta(hapd, sta, buf + len, buflen - len);
295e28a4053SRui Paulo if (res >= 0)
296e28a4053SRui Paulo len += res;
297e28a4053SRui Paulo res = hostapd_wps_get_mib_sta(hapd, sta->addr, buf + len,
298e28a4053SRui Paulo buflen - len);
299e28a4053SRui Paulo if (res >= 0)
300e28a4053SRui Paulo len += res;
301f05cddf9SRui Paulo res = hostapd_p2p_get_mib_sta(hapd, sta, buf + len, buflen - len);
302f05cddf9SRui Paulo if (res >= 0)
303f05cddf9SRui Paulo len += res;
304f05cddf9SRui Paulo
3054b72b91aSCy Schubert len += hostapd_get_sta_info(hapd, sta, buf + len, buflen - len);
3065b9c547cSRui Paulo
3075b9c547cSRui Paulo #ifdef CONFIG_SAE
3085b9c547cSRui Paulo if (sta->sae && sta->sae->state == SAE_ACCEPTED) {
3095b9c547cSRui Paulo res = os_snprintf(buf + len, buflen - len, "sae_group=%d\n",
3105b9c547cSRui Paulo sta->sae->group);
3115b9c547cSRui Paulo if (!os_snprintf_error(buflen - len, res))
312f05cddf9SRui Paulo len += res;
3135b9c547cSRui Paulo }
314c1d255d3SCy Schubert
315c1d255d3SCy Schubert if (sta->sae && sta->sae->tmp) {
316c1d255d3SCy Schubert const u8 *pos;
317c1d255d3SCy Schubert unsigned int j, count;
318c1d255d3SCy Schubert struct wpabuf *groups = sta->sae->tmp->peer_rejected_groups;
319c1d255d3SCy Schubert
320c1d255d3SCy Schubert res = os_snprintf(buf + len, buflen - len,
321c1d255d3SCy Schubert "sae_rejected_groups=");
322c1d255d3SCy Schubert if (!os_snprintf_error(buflen - len, res))
323c1d255d3SCy Schubert len += res;
324c1d255d3SCy Schubert
325c1d255d3SCy Schubert if (groups) {
326c1d255d3SCy Schubert pos = wpabuf_head(groups);
327c1d255d3SCy Schubert count = wpabuf_len(groups) / 2;
328c1d255d3SCy Schubert } else {
329c1d255d3SCy Schubert pos = NULL;
330c1d255d3SCy Schubert count = 0;
331c1d255d3SCy Schubert }
332c1d255d3SCy Schubert for (j = 0; pos && j < count; j++) {
333c1d255d3SCy Schubert res = os_snprintf(buf + len, buflen - len, "%s%d",
334c1d255d3SCy Schubert j == 0 ? "" : " ", WPA_GET_LE16(pos));
335c1d255d3SCy Schubert if (!os_snprintf_error(buflen - len, res))
336c1d255d3SCy Schubert len += res;
337c1d255d3SCy Schubert pos += 2;
338c1d255d3SCy Schubert }
339c1d255d3SCy Schubert
340c1d255d3SCy Schubert res = os_snprintf(buf + len, buflen - len, "\n");
341c1d255d3SCy Schubert if (!os_snprintf_error(buflen - len, res))
342c1d255d3SCy Schubert len += res;
343c1d255d3SCy Schubert }
3445b9c547cSRui Paulo #endif /* CONFIG_SAE */
345e28a4053SRui Paulo
346325151a3SRui Paulo if (sta->vlan_id > 0) {
347325151a3SRui Paulo res = os_snprintf(buf + len, buflen - len, "vlan_id=%d\n",
348325151a3SRui Paulo sta->vlan_id);
349325151a3SRui Paulo if (!os_snprintf_error(buflen - len, res))
350325151a3SRui Paulo len += res;
351325151a3SRui Paulo }
352325151a3SRui Paulo
353780fb4a2SCy Schubert res = mbo_ap_get_info(sta, buf + len, buflen - len);
354780fb4a2SCy Schubert if (res >= 0)
355780fb4a2SCy Schubert len += res;
356780fb4a2SCy Schubert
357780fb4a2SCy Schubert if (sta->supp_op_classes &&
358780fb4a2SCy Schubert buflen - len > (unsigned) (17 + 2 * sta->supp_op_classes[0])) {
359*a90b9d01SCy Schubert res = os_snprintf(buf + len, buflen - len, "supp_op_classes=");
360*a90b9d01SCy Schubert if (!os_snprintf_error(buflen - len, res))
361*a90b9d01SCy Schubert len += res;
362780fb4a2SCy Schubert len += wpa_snprintf_hex(buf + len, buflen - len,
363780fb4a2SCy Schubert sta->supp_op_classes + 1,
364780fb4a2SCy Schubert sta->supp_op_classes[0]);
365*a90b9d01SCy Schubert res = os_snprintf(buf + len, buflen - len, "\n");
366*a90b9d01SCy Schubert if (!os_snprintf_error(buflen - len, res))
367*a90b9d01SCy Schubert len += res;
368780fb4a2SCy Schubert }
369780fb4a2SCy Schubert
37085732ac8SCy Schubert if (sta->power_capab) {
37185732ac8SCy Schubert ret = os_snprintf(buf + len, buflen - len,
37285732ac8SCy Schubert "min_txpower=%d\n"
37385732ac8SCy Schubert "max_txpower=%d\n",
37485732ac8SCy Schubert sta->min_tx_power, sta->max_tx_power);
37585732ac8SCy Schubert if (!os_snprintf_error(buflen - len, ret))
37685732ac8SCy Schubert len += ret;
37785732ac8SCy Schubert }
37885732ac8SCy Schubert
379*a90b9d01SCy Schubert #ifdef CONFIG_IEEE80211AX
380*a90b9d01SCy Schubert if ((sta->flags & WLAN_STA_HE) && sta->he_capab) {
381*a90b9d01SCy Schubert res = os_snprintf(buf + len, buflen - len, "he_capab=");
382*a90b9d01SCy Schubert if (!os_snprintf_error(buflen - len, res))
383*a90b9d01SCy Schubert len += res;
384*a90b9d01SCy Schubert len += wpa_snprintf_hex(buf + len, buflen - len,
385*a90b9d01SCy Schubert (const u8 *) sta->he_capab,
386*a90b9d01SCy Schubert sta->he_capab_len);
387*a90b9d01SCy Schubert res = os_snprintf(buf + len, buflen - len, "\n");
388*a90b9d01SCy Schubert if (!os_snprintf_error(buflen - len, res))
389*a90b9d01SCy Schubert len += res;
390*a90b9d01SCy Schubert }
391*a90b9d01SCy Schubert #endif /* CONFIG_IEEE80211AX */
392*a90b9d01SCy Schubert
393*a90b9d01SCy Schubert #ifdef CONFIG_IEEE80211BE
394*a90b9d01SCy Schubert if ((sta->flags & WLAN_STA_EHT) && sta->eht_capab) {
395*a90b9d01SCy Schubert res = os_snprintf(buf + len, buflen - len, "eht_capab=");
396*a90b9d01SCy Schubert if (!os_snprintf_error(buflen - len, res))
397*a90b9d01SCy Schubert len += res;
398*a90b9d01SCy Schubert len += wpa_snprintf_hex(buf + len, buflen - len,
399*a90b9d01SCy Schubert (const u8 *) sta->eht_capab,
400*a90b9d01SCy Schubert sta->eht_capab_len);
401*a90b9d01SCy Schubert res = os_snprintf(buf + len, buflen - len, "\n");
402*a90b9d01SCy Schubert if (!os_snprintf_error(buflen - len, res))
403*a90b9d01SCy Schubert len += res;
404*a90b9d01SCy Schubert }
405*a90b9d01SCy Schubert #endif /* CONFIG_IEEE80211BE */
406*a90b9d01SCy Schubert
40785732ac8SCy Schubert #ifdef CONFIG_IEEE80211AC
40885732ac8SCy Schubert if ((sta->flags & WLAN_STA_VHT) && sta->vht_capabilities) {
40985732ac8SCy Schubert res = os_snprintf(buf + len, buflen - len,
41085732ac8SCy Schubert "vht_caps_info=0x%08x\n",
41185732ac8SCy Schubert le_to_host32(sta->vht_capabilities->
41285732ac8SCy Schubert vht_capabilities_info));
41385732ac8SCy Schubert if (!os_snprintf_error(buflen - len, res))
41485732ac8SCy Schubert len += res;
415*a90b9d01SCy Schubert
416*a90b9d01SCy Schubert res = os_snprintf(buf + len, buflen - len, "vht_capab=");
417*a90b9d01SCy Schubert if (!os_snprintf_error(buflen - len, res))
418*a90b9d01SCy Schubert len += res;
419*a90b9d01SCy Schubert len += wpa_snprintf_hex(buf + len, buflen - len,
420*a90b9d01SCy Schubert (const u8 *) sta->vht_capabilities,
421*a90b9d01SCy Schubert sizeof(*sta->vht_capabilities));
422*a90b9d01SCy Schubert res = os_snprintf(buf + len, buflen - len, "\n");
423*a90b9d01SCy Schubert if (!os_snprintf_error(buflen - len, res))
424*a90b9d01SCy Schubert len += res;
42585732ac8SCy Schubert }
42685732ac8SCy Schubert #endif /* CONFIG_IEEE80211AC */
42785732ac8SCy Schubert
42885732ac8SCy Schubert if ((sta->flags & WLAN_STA_HT) && sta->ht_capabilities) {
42985732ac8SCy Schubert res = os_snprintf(buf + len, buflen - len,
43085732ac8SCy Schubert "ht_caps_info=0x%04x\n",
43185732ac8SCy Schubert le_to_host16(sta->ht_capabilities->
43285732ac8SCy Schubert ht_capabilities_info));
43385732ac8SCy Schubert if (!os_snprintf_error(buflen - len, res))
43485732ac8SCy Schubert len += res;
43585732ac8SCy Schubert }
43685732ac8SCy Schubert
43785732ac8SCy Schubert if (sta->ext_capability &&
43885732ac8SCy Schubert buflen - len > (unsigned) (11 + 2 * sta->ext_capability[0])) {
439*a90b9d01SCy Schubert res = os_snprintf(buf + len, buflen - len, "ext_capab=");
440*a90b9d01SCy Schubert if (!os_snprintf_error(buflen - len, res))
441*a90b9d01SCy Schubert len += res;
44285732ac8SCy Schubert len += wpa_snprintf_hex(buf + len, buflen - len,
44385732ac8SCy Schubert sta->ext_capability + 1,
44485732ac8SCy Schubert sta->ext_capability[0]);
445*a90b9d01SCy Schubert res = os_snprintf(buf + len, buflen - len, "\n");
446*a90b9d01SCy Schubert if (!os_snprintf_error(buflen - len, res))
447*a90b9d01SCy Schubert len += res;
44885732ac8SCy Schubert }
44985732ac8SCy Schubert
45085732ac8SCy Schubert if (sta->flags & WLAN_STA_WDS && sta->ifname_wds) {
45185732ac8SCy Schubert ret = os_snprintf(buf + len, buflen - len,
45285732ac8SCy Schubert "wds_sta_ifname=%s\n", sta->ifname_wds);
45385732ac8SCy Schubert if (!os_snprintf_error(buflen - len, ret))
45485732ac8SCy Schubert len += ret;
45585732ac8SCy Schubert }
45685732ac8SCy Schubert
4574bc52338SCy Schubert keyid = ap_sta_wpa_get_keyid(hapd, sta);
4584bc52338SCy Schubert if (keyid) {
4594bc52338SCy Schubert ret = os_snprintf(buf + len, buflen - len, "keyid=%s\n", keyid);
4604bc52338SCy Schubert if (!os_snprintf_error(buflen - len, ret))
4614bc52338SCy Schubert len += ret;
4624bc52338SCy Schubert }
4634bc52338SCy Schubert
464*a90b9d01SCy Schubert dpp_pkhash = ap_sta_wpa_get_dpp_pkhash(hapd, sta);
465*a90b9d01SCy Schubert if (dpp_pkhash) {
466*a90b9d01SCy Schubert ret = os_snprintf(buf + len, buflen - len, "dpp_pkhash=");
467*a90b9d01SCy Schubert if (!os_snprintf_error(buflen - len, ret))
468*a90b9d01SCy Schubert len += ret;
469*a90b9d01SCy Schubert len += wpa_snprintf_hex(buf + len, buflen - len, dpp_pkhash,
470*a90b9d01SCy Schubert SHA256_MAC_LEN);
471*a90b9d01SCy Schubert ret = os_snprintf(buf + len, buflen - len, "\n");
472*a90b9d01SCy Schubert if (!os_snprintf_error(buflen - len, ret))
473*a90b9d01SCy Schubert len += ret;
474*a90b9d01SCy Schubert }
475*a90b9d01SCy Schubert
476*a90b9d01SCy Schubert #ifdef CONFIG_IEEE80211BE
477*a90b9d01SCy Schubert if (sta->mld_info.mld_sta) {
478*a90b9d01SCy Schubert for (i = 0; i < MAX_NUM_MLD_LINKS; ++i) {
479*a90b9d01SCy Schubert if (!sta->mld_info.links[i].valid)
480*a90b9d01SCy Schubert continue;
481*a90b9d01SCy Schubert ret = os_snprintf(
482*a90b9d01SCy Schubert buf + len, buflen - len,
483*a90b9d01SCy Schubert "peer_addr[%d]=" MACSTR "\n",
484*a90b9d01SCy Schubert i, MAC2STR(sta->mld_info.links[i].peer_addr));
485*a90b9d01SCy Schubert if (!os_snprintf_error(buflen - len, ret))
486*a90b9d01SCy Schubert len += ret;
487*a90b9d01SCy Schubert }
488*a90b9d01SCy Schubert }
489*a90b9d01SCy Schubert #endif /* CONFIG_IEEE80211BE */
490*a90b9d01SCy Schubert
491e28a4053SRui Paulo return len;
492e28a4053SRui Paulo }
493e28a4053SRui Paulo
494e28a4053SRui Paulo
hostapd_ctrl_iface_sta_first(struct hostapd_data * hapd,char * buf,size_t buflen)495e28a4053SRui Paulo int hostapd_ctrl_iface_sta_first(struct hostapd_data *hapd,
496e28a4053SRui Paulo char *buf, size_t buflen)
497e28a4053SRui Paulo {
498e28a4053SRui Paulo return hostapd_ctrl_iface_sta_mib(hapd, hapd->sta_list, buf, buflen);
499e28a4053SRui Paulo }
500e28a4053SRui Paulo
501e28a4053SRui Paulo
hostapd_ctrl_iface_sta(struct hostapd_data * hapd,const char * txtaddr,char * buf,size_t buflen)502e28a4053SRui Paulo int hostapd_ctrl_iface_sta(struct hostapd_data *hapd, const char *txtaddr,
503e28a4053SRui Paulo char *buf, size_t buflen)
504e28a4053SRui Paulo {
505e28a4053SRui Paulo u8 addr[ETH_ALEN];
506e28a4053SRui Paulo int ret;
5075b9c547cSRui Paulo const char *pos;
5085b9c547cSRui Paulo struct sta_info *sta;
509e28a4053SRui Paulo
510e28a4053SRui Paulo if (hwaddr_aton(txtaddr, addr)) {
511e28a4053SRui Paulo ret = os_snprintf(buf, buflen, "FAIL\n");
5125b9c547cSRui Paulo if (os_snprintf_error(buflen, ret))
513e28a4053SRui Paulo return 0;
514e28a4053SRui Paulo return ret;
515e28a4053SRui Paulo }
5165b9c547cSRui Paulo
5175b9c547cSRui Paulo sta = ap_get_sta(hapd, addr);
5185b9c547cSRui Paulo if (sta == NULL)
5195b9c547cSRui Paulo return -1;
5205b9c547cSRui Paulo
5215b9c547cSRui Paulo pos = os_strchr(txtaddr, ' ');
5225b9c547cSRui Paulo if (pos) {
5235b9c547cSRui Paulo pos++;
5245b9c547cSRui Paulo
5255b9c547cSRui Paulo #ifdef HOSTAPD_DUMP_STATE
5265b9c547cSRui Paulo if (os_strcmp(pos, "eapol") == 0) {
5275b9c547cSRui Paulo if (sta->eapol_sm == NULL)
5285b9c547cSRui Paulo return -1;
5295b9c547cSRui Paulo return eapol_auth_dump_state(sta->eapol_sm, buf,
5305b9c547cSRui Paulo buflen);
5315b9c547cSRui Paulo }
5325b9c547cSRui Paulo #endif /* HOSTAPD_DUMP_STATE */
5335b9c547cSRui Paulo
5345b9c547cSRui Paulo return -1;
5355b9c547cSRui Paulo }
5365b9c547cSRui Paulo
537325151a3SRui Paulo ret = hostapd_ctrl_iface_sta_mib(hapd, sta, buf, buflen);
538325151a3SRui Paulo ret += fst_ctrl_iface_mb_info(addr, buf + ret, buflen - ret);
539325151a3SRui Paulo
540325151a3SRui Paulo return ret;
541e28a4053SRui Paulo }
542e28a4053SRui Paulo
543e28a4053SRui Paulo
hostapd_ctrl_iface_sta_next(struct hostapd_data * hapd,const char * txtaddr,char * buf,size_t buflen)544e28a4053SRui Paulo int hostapd_ctrl_iface_sta_next(struct hostapd_data *hapd, const char *txtaddr,
545e28a4053SRui Paulo char *buf, size_t buflen)
546e28a4053SRui Paulo {
547e28a4053SRui Paulo u8 addr[ETH_ALEN];
548e28a4053SRui Paulo struct sta_info *sta;
549e28a4053SRui Paulo int ret;
550e28a4053SRui Paulo
551e28a4053SRui Paulo if (hwaddr_aton(txtaddr, addr) ||
552e28a4053SRui Paulo (sta = ap_get_sta(hapd, addr)) == NULL) {
553e28a4053SRui Paulo ret = os_snprintf(buf, buflen, "FAIL\n");
5545b9c547cSRui Paulo if (os_snprintf_error(buflen, ret))
555e28a4053SRui Paulo return 0;
556e28a4053SRui Paulo return ret;
557e28a4053SRui Paulo }
5585b9c547cSRui Paulo
5595b9c547cSRui Paulo if (!sta->next)
5605b9c547cSRui Paulo return 0;
5615b9c547cSRui Paulo
562e28a4053SRui Paulo return hostapd_ctrl_iface_sta_mib(hapd, sta->next, buf, buflen);
563e28a4053SRui Paulo }
564f05cddf9SRui Paulo
565f05cddf9SRui Paulo
566f05cddf9SRui Paulo #ifdef CONFIG_P2P_MANAGER
p2p_manager_disconnect(struct hostapd_data * hapd,u16 stype,u8 minor_reason_code,const u8 * addr)567f05cddf9SRui Paulo static int p2p_manager_disconnect(struct hostapd_data *hapd, u16 stype,
568f05cddf9SRui Paulo u8 minor_reason_code, const u8 *addr)
569f05cddf9SRui Paulo {
570f05cddf9SRui Paulo struct ieee80211_mgmt *mgmt;
571f05cddf9SRui Paulo int ret;
572f05cddf9SRui Paulo u8 *pos;
573f05cddf9SRui Paulo
574f05cddf9SRui Paulo mgmt = os_zalloc(sizeof(*mgmt) + 100);
575f05cddf9SRui Paulo if (mgmt == NULL)
576f05cddf9SRui Paulo return -1;
577f05cddf9SRui Paulo
578f05cddf9SRui Paulo mgmt->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, stype);
5795b9c547cSRui Paulo wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "P2P: Disconnect STA " MACSTR
5805b9c547cSRui Paulo " with minor reason code %u (stype=%u (%s))",
5815b9c547cSRui Paulo MAC2STR(addr), minor_reason_code, stype,
582780fb4a2SCy Schubert fc2str(le_to_host16(mgmt->frame_control)));
5835b9c547cSRui Paulo
584f05cddf9SRui Paulo os_memcpy(mgmt->da, addr, ETH_ALEN);
585f05cddf9SRui Paulo os_memcpy(mgmt->sa, hapd->own_addr, ETH_ALEN);
586f05cddf9SRui Paulo os_memcpy(mgmt->bssid, hapd->own_addr, ETH_ALEN);
587f05cddf9SRui Paulo if (stype == WLAN_FC_STYPE_DEAUTH) {
588f05cddf9SRui Paulo mgmt->u.deauth.reason_code =
589f05cddf9SRui Paulo host_to_le16(WLAN_REASON_PREV_AUTH_NOT_VALID);
5904bc52338SCy Schubert pos = mgmt->u.deauth.variable;
591f05cddf9SRui Paulo } else {
592f05cddf9SRui Paulo mgmt->u.disassoc.reason_code =
593f05cddf9SRui Paulo host_to_le16(WLAN_REASON_PREV_AUTH_NOT_VALID);
5944bc52338SCy Schubert pos = mgmt->u.disassoc.variable;
595f05cddf9SRui Paulo }
596f05cddf9SRui Paulo
597f05cddf9SRui Paulo *pos++ = WLAN_EID_VENDOR_SPECIFIC;
598f05cddf9SRui Paulo *pos++ = 4 + 3 + 1;
5995b9c547cSRui Paulo WPA_PUT_BE32(pos, P2P_IE_VENDOR_TYPE);
6005b9c547cSRui Paulo pos += 4;
601f05cddf9SRui Paulo
602f05cddf9SRui Paulo *pos++ = P2P_ATTR_MINOR_REASON_CODE;
603f05cddf9SRui Paulo WPA_PUT_LE16(pos, 1);
604f05cddf9SRui Paulo pos += 2;
605f05cddf9SRui Paulo *pos++ = minor_reason_code;
606f05cddf9SRui Paulo
607c1d255d3SCy Schubert ret = hostapd_drv_send_mlme(hapd, mgmt, pos - (u8 *) mgmt, 0, NULL, 0,
608c1d255d3SCy Schubert 0);
609f05cddf9SRui Paulo os_free(mgmt);
610f05cddf9SRui Paulo
611f05cddf9SRui Paulo return ret < 0 ? -1 : 0;
612f05cddf9SRui Paulo }
613f05cddf9SRui Paulo #endif /* CONFIG_P2P_MANAGER */
614f05cddf9SRui Paulo
615f05cddf9SRui Paulo
hostapd_ctrl_iface_deauthenticate(struct hostapd_data * hapd,const char * txtaddr)616f05cddf9SRui Paulo int hostapd_ctrl_iface_deauthenticate(struct hostapd_data *hapd,
617f05cddf9SRui Paulo const char *txtaddr)
618f05cddf9SRui Paulo {
619f05cddf9SRui Paulo u8 addr[ETH_ALEN];
620f05cddf9SRui Paulo struct sta_info *sta;
621f05cddf9SRui Paulo const char *pos;
6225b9c547cSRui Paulo u16 reason = WLAN_REASON_PREV_AUTH_NOT_VALID;
623f05cddf9SRui Paulo
624f05cddf9SRui Paulo wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "CTRL_IFACE DEAUTHENTICATE %s",
625f05cddf9SRui Paulo txtaddr);
626f05cddf9SRui Paulo
627f05cddf9SRui Paulo if (hwaddr_aton(txtaddr, addr))
628f05cddf9SRui Paulo return -1;
629f05cddf9SRui Paulo
6305b9c547cSRui Paulo pos = os_strstr(txtaddr, " reason=");
6315b9c547cSRui Paulo if (pos)
6325b9c547cSRui Paulo reason = atoi(pos + 8);
6335b9c547cSRui Paulo
634f05cddf9SRui Paulo pos = os_strstr(txtaddr, " test=");
635f05cddf9SRui Paulo if (pos) {
636f05cddf9SRui Paulo struct ieee80211_mgmt mgmt;
637f05cddf9SRui Paulo int encrypt;
638c1d255d3SCy Schubert
639f05cddf9SRui Paulo pos += 6;
640f05cddf9SRui Paulo encrypt = atoi(pos);
641f05cddf9SRui Paulo os_memset(&mgmt, 0, sizeof(mgmt));
642f05cddf9SRui Paulo mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
643f05cddf9SRui Paulo WLAN_FC_STYPE_DEAUTH);
644f05cddf9SRui Paulo os_memcpy(mgmt.da, addr, ETH_ALEN);
645f05cddf9SRui Paulo os_memcpy(mgmt.sa, hapd->own_addr, ETH_ALEN);
646f05cddf9SRui Paulo os_memcpy(mgmt.bssid, hapd->own_addr, ETH_ALEN);
6475b9c547cSRui Paulo mgmt.u.deauth.reason_code = host_to_le16(reason);
648c1d255d3SCy Schubert if (hostapd_drv_send_mlme(hapd, (u8 *) &mgmt,
649f05cddf9SRui Paulo IEEE80211_HDRLEN +
650f05cddf9SRui Paulo sizeof(mgmt.u.deauth),
651c1d255d3SCy Schubert 0, NULL, 0, !encrypt) < 0)
652f05cddf9SRui Paulo return -1;
653f05cddf9SRui Paulo return 0;
654f05cddf9SRui Paulo }
655f05cddf9SRui Paulo
656f05cddf9SRui Paulo #ifdef CONFIG_P2P_MANAGER
657f05cddf9SRui Paulo pos = os_strstr(txtaddr, " p2p=");
658f05cddf9SRui Paulo if (pos) {
659f05cddf9SRui Paulo return p2p_manager_disconnect(hapd, WLAN_FC_STYPE_DEAUTH,
660f05cddf9SRui Paulo atoi(pos + 5), addr);
661f05cddf9SRui Paulo }
662f05cddf9SRui Paulo #endif /* CONFIG_P2P_MANAGER */
663f05cddf9SRui Paulo
664780fb4a2SCy Schubert if (os_strstr(txtaddr, " tx=0"))
665780fb4a2SCy Schubert hostapd_drv_sta_remove(hapd, addr);
666780fb4a2SCy Schubert else
6675b9c547cSRui Paulo hostapd_drv_sta_deauth(hapd, addr, reason);
668f05cddf9SRui Paulo sta = ap_get_sta(hapd, addr);
669f05cddf9SRui Paulo if (sta)
6705b9c547cSRui Paulo ap_sta_deauthenticate(hapd, sta, reason);
671f05cddf9SRui Paulo else if (addr[0] == 0xff)
672f05cddf9SRui Paulo hostapd_free_stas(hapd);
673f05cddf9SRui Paulo
674f05cddf9SRui Paulo return 0;
675f05cddf9SRui Paulo }
676f05cddf9SRui Paulo
677f05cddf9SRui Paulo
hostapd_ctrl_iface_disassociate(struct hostapd_data * hapd,const char * txtaddr)678f05cddf9SRui Paulo int hostapd_ctrl_iface_disassociate(struct hostapd_data *hapd,
679f05cddf9SRui Paulo const char *txtaddr)
680f05cddf9SRui Paulo {
681f05cddf9SRui Paulo u8 addr[ETH_ALEN];
682f05cddf9SRui Paulo struct sta_info *sta;
683f05cddf9SRui Paulo const char *pos;
6845b9c547cSRui Paulo u16 reason = WLAN_REASON_PREV_AUTH_NOT_VALID;
685f05cddf9SRui Paulo
686f05cddf9SRui Paulo wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "CTRL_IFACE DISASSOCIATE %s",
687f05cddf9SRui Paulo txtaddr);
688f05cddf9SRui Paulo
689f05cddf9SRui Paulo if (hwaddr_aton(txtaddr, addr))
690f05cddf9SRui Paulo return -1;
691f05cddf9SRui Paulo
6925b9c547cSRui Paulo pos = os_strstr(txtaddr, " reason=");
6935b9c547cSRui Paulo if (pos)
6945b9c547cSRui Paulo reason = atoi(pos + 8);
6955b9c547cSRui Paulo
696f05cddf9SRui Paulo pos = os_strstr(txtaddr, " test=");
697f05cddf9SRui Paulo if (pos) {
698f05cddf9SRui Paulo struct ieee80211_mgmt mgmt;
699f05cddf9SRui Paulo int encrypt;
700c1d255d3SCy Schubert
701f05cddf9SRui Paulo pos += 6;
702f05cddf9SRui Paulo encrypt = atoi(pos);
703f05cddf9SRui Paulo os_memset(&mgmt, 0, sizeof(mgmt));
704f05cddf9SRui Paulo mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
705f05cddf9SRui Paulo WLAN_FC_STYPE_DISASSOC);
706f05cddf9SRui Paulo os_memcpy(mgmt.da, addr, ETH_ALEN);
707f05cddf9SRui Paulo os_memcpy(mgmt.sa, hapd->own_addr, ETH_ALEN);
708f05cddf9SRui Paulo os_memcpy(mgmt.bssid, hapd->own_addr, ETH_ALEN);
7095b9c547cSRui Paulo mgmt.u.disassoc.reason_code = host_to_le16(reason);
710c1d255d3SCy Schubert if (hostapd_drv_send_mlme(hapd, (u8 *) &mgmt,
711f05cddf9SRui Paulo IEEE80211_HDRLEN +
712f05cddf9SRui Paulo sizeof(mgmt.u.deauth),
713c1d255d3SCy Schubert 0, NULL, 0, !encrypt) < 0)
714f05cddf9SRui Paulo return -1;
715f05cddf9SRui Paulo return 0;
716f05cddf9SRui Paulo }
717f05cddf9SRui Paulo
718f05cddf9SRui Paulo #ifdef CONFIG_P2P_MANAGER
719f05cddf9SRui Paulo pos = os_strstr(txtaddr, " p2p=");
720f05cddf9SRui Paulo if (pos) {
721f05cddf9SRui Paulo return p2p_manager_disconnect(hapd, WLAN_FC_STYPE_DISASSOC,
722f05cddf9SRui Paulo atoi(pos + 5), addr);
723f05cddf9SRui Paulo }
724f05cddf9SRui Paulo #endif /* CONFIG_P2P_MANAGER */
725f05cddf9SRui Paulo
726780fb4a2SCy Schubert if (os_strstr(txtaddr, " tx=0"))
727780fb4a2SCy Schubert hostapd_drv_sta_remove(hapd, addr);
728780fb4a2SCy Schubert else
7295b9c547cSRui Paulo hostapd_drv_sta_disassoc(hapd, addr, reason);
730f05cddf9SRui Paulo sta = ap_get_sta(hapd, addr);
731f05cddf9SRui Paulo if (sta)
7325b9c547cSRui Paulo ap_sta_disassociate(hapd, sta, reason);
733f05cddf9SRui Paulo else if (addr[0] == 0xff)
734f05cddf9SRui Paulo hostapd_free_stas(hapd);
735f05cddf9SRui Paulo
736f05cddf9SRui Paulo return 0;
737f05cddf9SRui Paulo }
7385b9c547cSRui Paulo
7395b9c547cSRui Paulo
740780fb4a2SCy Schubert #ifdef CONFIG_TAXONOMY
hostapd_ctrl_iface_signature(struct hostapd_data * hapd,const char * txtaddr,char * buf,size_t buflen)741780fb4a2SCy Schubert int hostapd_ctrl_iface_signature(struct hostapd_data *hapd,
742780fb4a2SCy Schubert const char *txtaddr,
743780fb4a2SCy Schubert char *buf, size_t buflen)
744780fb4a2SCy Schubert {
745780fb4a2SCy Schubert u8 addr[ETH_ALEN];
746780fb4a2SCy Schubert struct sta_info *sta;
747780fb4a2SCy Schubert
748780fb4a2SCy Schubert wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "CTRL_IFACE SIGNATURE %s", txtaddr);
749780fb4a2SCy Schubert
750780fb4a2SCy Schubert if (hwaddr_aton(txtaddr, addr))
751780fb4a2SCy Schubert return -1;
752780fb4a2SCy Schubert
753780fb4a2SCy Schubert sta = ap_get_sta(hapd, addr);
754780fb4a2SCy Schubert if (!sta)
755780fb4a2SCy Schubert return -1;
756780fb4a2SCy Schubert
757780fb4a2SCy Schubert return retrieve_sta_taxonomy(hapd, sta, buf, buflen);
758780fb4a2SCy Schubert }
759780fb4a2SCy Schubert #endif /* CONFIG_TAXONOMY */
760780fb4a2SCy Schubert
761780fb4a2SCy Schubert
hostapd_ctrl_iface_poll_sta(struct hostapd_data * hapd,const char * txtaddr)762780fb4a2SCy Schubert int hostapd_ctrl_iface_poll_sta(struct hostapd_data *hapd,
763780fb4a2SCy Schubert const char *txtaddr)
764780fb4a2SCy Schubert {
765780fb4a2SCy Schubert u8 addr[ETH_ALEN];
766780fb4a2SCy Schubert struct sta_info *sta;
767780fb4a2SCy Schubert
768780fb4a2SCy Schubert wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "CTRL_IFACE POLL_STA %s", txtaddr);
769780fb4a2SCy Schubert
770780fb4a2SCy Schubert if (hwaddr_aton(txtaddr, addr))
771780fb4a2SCy Schubert return -1;
772780fb4a2SCy Schubert
773780fb4a2SCy Schubert sta = ap_get_sta(hapd, addr);
774780fb4a2SCy Schubert if (!sta)
775780fb4a2SCy Schubert return -1;
776780fb4a2SCy Schubert
777780fb4a2SCy Schubert hostapd_drv_poll_client(hapd, hapd->own_addr, addr,
778780fb4a2SCy Schubert sta->flags & WLAN_STA_WMM);
779780fb4a2SCy Schubert return 0;
780780fb4a2SCy Schubert }
781780fb4a2SCy Schubert
782780fb4a2SCy Schubert
hostapd_ctrl_iface_status(struct hostapd_data * hapd,char * buf,size_t buflen)7835b9c547cSRui Paulo int hostapd_ctrl_iface_status(struct hostapd_data *hapd, char *buf,
7845b9c547cSRui Paulo size_t buflen)
7855b9c547cSRui Paulo {
7865b9c547cSRui Paulo struct hostapd_iface *iface = hapd->iface;
78785732ac8SCy Schubert struct hostapd_hw_modes *mode = iface->current_mode;
788*a90b9d01SCy Schubert struct hostapd_config *iconf = hapd->iconf;
78985732ac8SCy Schubert int len = 0, ret, j;
7905b9c547cSRui Paulo size_t i;
7915b9c547cSRui Paulo
7925b9c547cSRui Paulo ret = os_snprintf(buf + len, buflen - len,
7935b9c547cSRui Paulo "state=%s\n"
7945b9c547cSRui Paulo "phy=%s\n"
7955b9c547cSRui Paulo "freq=%d\n"
7965b9c547cSRui Paulo "num_sta_non_erp=%d\n"
7975b9c547cSRui Paulo "num_sta_no_short_slot_time=%d\n"
7985b9c547cSRui Paulo "num_sta_no_short_preamble=%d\n"
7995b9c547cSRui Paulo "olbc=%d\n"
8005b9c547cSRui Paulo "num_sta_ht_no_gf=%d\n"
8015b9c547cSRui Paulo "num_sta_no_ht=%d\n"
8025b9c547cSRui Paulo "num_sta_ht_20_mhz=%d\n"
8035b9c547cSRui Paulo "num_sta_ht40_intolerant=%d\n"
8045b9c547cSRui Paulo "olbc_ht=%d\n"
8055b9c547cSRui Paulo "ht_op_mode=0x%x\n",
8065b9c547cSRui Paulo hostapd_state_text(iface->state),
8075b9c547cSRui Paulo iface->phy,
8085b9c547cSRui Paulo iface->freq,
8095b9c547cSRui Paulo iface->num_sta_non_erp,
8105b9c547cSRui Paulo iface->num_sta_no_short_slot_time,
8115b9c547cSRui Paulo iface->num_sta_no_short_preamble,
8125b9c547cSRui Paulo iface->olbc,
8135b9c547cSRui Paulo iface->num_sta_ht_no_gf,
8145b9c547cSRui Paulo iface->num_sta_no_ht,
8155b9c547cSRui Paulo iface->num_sta_ht_20mhz,
8165b9c547cSRui Paulo iface->num_sta_ht40_intolerant,
8175b9c547cSRui Paulo iface->olbc_ht,
8185b9c547cSRui Paulo iface->ht_op_mode);
8195b9c547cSRui Paulo if (os_snprintf_error(buflen - len, ret))
8205b9c547cSRui Paulo return len;
8215b9c547cSRui Paulo len += ret;
8225b9c547cSRui Paulo
823*a90b9d01SCy Schubert if (mode) {
824*a90b9d01SCy Schubert ret = os_snprintf(buf + len, buflen - len, "hw_mode=%s\n",
825*a90b9d01SCy Schubert hw_mode_str(mode->mode));
826*a90b9d01SCy Schubert if (os_snprintf_error(buflen - len, ret))
827*a90b9d01SCy Schubert return len;
828*a90b9d01SCy Schubert len += ret;
829*a90b9d01SCy Schubert }
830*a90b9d01SCy Schubert
831*a90b9d01SCy Schubert if (iconf->country[0] && iconf->country[1]) {
832*a90b9d01SCy Schubert ret = os_snprintf(buf + len, buflen - len,
833*a90b9d01SCy Schubert "country_code=%c%c\ncountry3=0x%X\n",
834*a90b9d01SCy Schubert iconf->country[0], iconf->country[1],
835*a90b9d01SCy Schubert iconf->country[2]);
836*a90b9d01SCy Schubert if (os_snprintf_error(buflen - len, ret))
837*a90b9d01SCy Schubert return len;
838*a90b9d01SCy Schubert len += ret;
839*a90b9d01SCy Schubert }
840*a90b9d01SCy Schubert
8415b9c547cSRui Paulo if (!iface->cac_started || !iface->dfs_cac_ms) {
8425b9c547cSRui Paulo ret = os_snprintf(buf + len, buflen - len,
8435b9c547cSRui Paulo "cac_time_seconds=%d\n"
8445b9c547cSRui Paulo "cac_time_left_seconds=N/A\n",
8455b9c547cSRui Paulo iface->dfs_cac_ms / 1000);
8465b9c547cSRui Paulo } else {
8475b9c547cSRui Paulo /* CAC started and CAC time set - calculate remaining time */
8485b9c547cSRui Paulo struct os_reltime now;
849*a90b9d01SCy Schubert long left_time;
8505b9c547cSRui Paulo
8515b9c547cSRui Paulo os_reltime_age(&iface->dfs_cac_start, &now);
852*a90b9d01SCy Schubert left_time = (long) iface->dfs_cac_ms / 1000 - now.sec;
8535b9c547cSRui Paulo ret = os_snprintf(buf + len, buflen - len,
8545b9c547cSRui Paulo "cac_time_seconds=%u\n"
855*a90b9d01SCy Schubert "cac_time_left_seconds=%lu\n",
8565b9c547cSRui Paulo iface->dfs_cac_ms / 1000,
857*a90b9d01SCy Schubert left_time > 0 ? left_time : 0);
8585b9c547cSRui Paulo }
8595b9c547cSRui Paulo if (os_snprintf_error(buflen - len, ret))
8605b9c547cSRui Paulo return len;
8615b9c547cSRui Paulo len += ret;
8625b9c547cSRui Paulo
8635b9c547cSRui Paulo ret = os_snprintf(buf + len, buflen - len,
8645b9c547cSRui Paulo "channel=%u\n"
865c1d255d3SCy Schubert "edmg_enable=%d\n"
866c1d255d3SCy Schubert "edmg_channel=%d\n"
8675b9c547cSRui Paulo "secondary_channel=%d\n"
8685b9c547cSRui Paulo "ieee80211n=%d\n"
86985732ac8SCy Schubert "ieee80211ac=%d\n"
870206b73d0SCy Schubert "ieee80211ax=%d\n"
871*a90b9d01SCy Schubert "ieee80211be=%d\n"
87285732ac8SCy Schubert "beacon_int=%u\n"
87385732ac8SCy Schubert "dtim_period=%d\n",
874780fb4a2SCy Schubert iface->conf->channel,
875c1d255d3SCy Schubert iface->conf->enable_edmg,
876c1d255d3SCy Schubert iface->conf->edmg_channel,
877780fb4a2SCy Schubert iface->conf->ieee80211n && !hapd->conf->disable_11n ?
878780fb4a2SCy Schubert iface->conf->secondary_channel : 0,
879780fb4a2SCy Schubert iface->conf->ieee80211n && !hapd->conf->disable_11n,
880780fb4a2SCy Schubert iface->conf->ieee80211ac &&
88185732ac8SCy Schubert !hapd->conf->disable_11ac,
882c1d255d3SCy Schubert iface->conf->ieee80211ax &&
883c1d255d3SCy Schubert !hapd->conf->disable_11ax,
884*a90b9d01SCy Schubert iface->conf->ieee80211be &&
885*a90b9d01SCy Schubert !hapd->conf->disable_11be,
88685732ac8SCy Schubert iface->conf->beacon_int,
88785732ac8SCy Schubert hapd->conf->dtim_period);
888780fb4a2SCy Schubert if (os_snprintf_error(buflen - len, ret))
889780fb4a2SCy Schubert return len;
890780fb4a2SCy Schubert len += ret;
891c1d255d3SCy Schubert
892*a90b9d01SCy Schubert #ifdef CONFIG_IEEE80211BE
893*a90b9d01SCy Schubert if (iface->conf->ieee80211be && !hapd->conf->disable_11be) {
894*a90b9d01SCy Schubert ret = os_snprintf(buf + len, buflen - len,
895*a90b9d01SCy Schubert "eht_oper_chwidth=%d\n"
896*a90b9d01SCy Schubert "eht_oper_centr_freq_seg0_idx=%d\n",
897*a90b9d01SCy Schubert iface->conf->eht_oper_chwidth,
898*a90b9d01SCy Schubert iface->conf->eht_oper_centr_freq_seg0_idx);
899*a90b9d01SCy Schubert if (os_snprintf_error(buflen - len, ret))
900*a90b9d01SCy Schubert return len;
901*a90b9d01SCy Schubert len += ret;
902*a90b9d01SCy Schubert
903*a90b9d01SCy Schubert if (is_6ghz_op_class(iface->conf->op_class) &&
904*a90b9d01SCy Schubert hostapd_get_oper_chwidth(iface->conf) ==
905*a90b9d01SCy Schubert CONF_OPER_CHWIDTH_320MHZ) {
906*a90b9d01SCy Schubert ret = os_snprintf(buf + len, buflen - len,
907*a90b9d01SCy Schubert "eht_bw320_offset=%d\n",
908*a90b9d01SCy Schubert iface->conf->eht_bw320_offset);
909*a90b9d01SCy Schubert if (os_snprintf_error(buflen - len, ret))
910*a90b9d01SCy Schubert return len;
911*a90b9d01SCy Schubert len += ret;
912*a90b9d01SCy Schubert }
913*a90b9d01SCy Schubert
914*a90b9d01SCy Schubert if (hapd->conf->mld_ap) {
915*a90b9d01SCy Schubert struct hostapd_data *link_bss;
916*a90b9d01SCy Schubert
917*a90b9d01SCy Schubert ret = os_snprintf(buf + len, buflen - len,
918*a90b9d01SCy Schubert "num_links=%d\n",
919*a90b9d01SCy Schubert hapd->mld->num_links);
920*a90b9d01SCy Schubert if (os_snprintf_error(buflen - len, ret))
921*a90b9d01SCy Schubert return len;
922*a90b9d01SCy Schubert len += ret;
923*a90b9d01SCy Schubert
924*a90b9d01SCy Schubert /* Self BSS */
925*a90b9d01SCy Schubert ret = os_snprintf(buf + len, buflen - len,
926*a90b9d01SCy Schubert "link_id=%d\n"
927*a90b9d01SCy Schubert "link_addr=" MACSTR "\n",
928*a90b9d01SCy Schubert hapd->mld_link_id,
929*a90b9d01SCy Schubert MAC2STR(hapd->own_addr));
930*a90b9d01SCy Schubert if (os_snprintf_error(buflen - len, ret))
931*a90b9d01SCy Schubert return len;
932*a90b9d01SCy Schubert len += ret;
933*a90b9d01SCy Schubert
934*a90b9d01SCy Schubert /* Partner BSSs */
935*a90b9d01SCy Schubert for_each_mld_link(link_bss, hapd) {
936*a90b9d01SCy Schubert if (link_bss == hapd)
937*a90b9d01SCy Schubert continue;
938*a90b9d01SCy Schubert
939*a90b9d01SCy Schubert ret = os_snprintf(buf + len, buflen - len,
940*a90b9d01SCy Schubert "partner_link[%d]=" MACSTR
941*a90b9d01SCy Schubert "\n",
942*a90b9d01SCy Schubert link_bss->mld_link_id,
943*a90b9d01SCy Schubert MAC2STR(link_bss->own_addr));
944*a90b9d01SCy Schubert if (os_snprintf_error(buflen - len, ret))
945*a90b9d01SCy Schubert return len;
946*a90b9d01SCy Schubert len += ret;
947*a90b9d01SCy Schubert }
948*a90b9d01SCy Schubert }
949*a90b9d01SCy Schubert }
950*a90b9d01SCy Schubert #endif /* CONFIG_IEEE80211BE */
951*a90b9d01SCy Schubert
952c1d255d3SCy Schubert #ifdef CONFIG_IEEE80211AX
953c1d255d3SCy Schubert if (iface->conf->ieee80211ax && !hapd->conf->disable_11ax) {
954c1d255d3SCy Schubert ret = os_snprintf(buf + len, buflen - len,
955c1d255d3SCy Schubert "he_oper_chwidth=%d\n"
956c1d255d3SCy Schubert "he_oper_centr_freq_seg0_idx=%d\n"
957c1d255d3SCy Schubert "he_oper_centr_freq_seg1_idx=%d\n",
958c1d255d3SCy Schubert iface->conf->he_oper_chwidth,
959c1d255d3SCy Schubert iface->conf->he_oper_centr_freq_seg0_idx,
960c1d255d3SCy Schubert iface->conf->he_oper_centr_freq_seg1_idx);
961c1d255d3SCy Schubert if (os_snprintf_error(buflen - len, ret))
962c1d255d3SCy Schubert return len;
963c1d255d3SCy Schubert len += ret;
964*a90b9d01SCy Schubert
965*a90b9d01SCy Schubert if (!iconf->he_op.he_bss_color_disabled &&
966*a90b9d01SCy Schubert iconf->he_op.he_bss_color) {
967*a90b9d01SCy Schubert ret = os_snprintf(buf + len, buflen - len,
968*a90b9d01SCy Schubert "he_bss_color=%d\n",
969*a90b9d01SCy Schubert iconf->he_op.he_bss_color);
970*a90b9d01SCy Schubert if (os_snprintf_error(buflen - len, ret))
971*a90b9d01SCy Schubert return len;
972*a90b9d01SCy Schubert len += ret;
973*a90b9d01SCy Schubert }
974c1d255d3SCy Schubert }
975c1d255d3SCy Schubert #endif /* CONFIG_IEEE80211AX */
976c1d255d3SCy Schubert
977780fb4a2SCy Schubert if (iface->conf->ieee80211ac && !hapd->conf->disable_11ac) {
978780fb4a2SCy Schubert ret = os_snprintf(buf + len, buflen - len,
9795b9c547cSRui Paulo "vht_oper_chwidth=%d\n"
9805b9c547cSRui Paulo "vht_oper_centr_freq_seg0_idx=%d\n"
98185732ac8SCy Schubert "vht_oper_centr_freq_seg1_idx=%d\n"
98285732ac8SCy Schubert "vht_caps_info=%08x\n",
9835b9c547cSRui Paulo iface->conf->vht_oper_chwidth,
9845b9c547cSRui Paulo iface->conf->vht_oper_centr_freq_seg0_idx,
98585732ac8SCy Schubert iface->conf->vht_oper_centr_freq_seg1_idx,
98685732ac8SCy Schubert iface->conf->vht_capab);
9875b9c547cSRui Paulo if (os_snprintf_error(buflen - len, ret))
9885b9c547cSRui Paulo return len;
9895b9c547cSRui Paulo len += ret;
990780fb4a2SCy Schubert }
9915b9c547cSRui Paulo
99285732ac8SCy Schubert if (iface->conf->ieee80211ac && !hapd->conf->disable_11ac && mode) {
99385732ac8SCy Schubert u16 rxmap = WPA_GET_LE16(&mode->vht_mcs_set[0]);
99485732ac8SCy Schubert u16 txmap = WPA_GET_LE16(&mode->vht_mcs_set[4]);
99585732ac8SCy Schubert
99685732ac8SCy Schubert ret = os_snprintf(buf + len, buflen - len,
99785732ac8SCy Schubert "rx_vht_mcs_map=%04x\n"
99885732ac8SCy Schubert "tx_vht_mcs_map=%04x\n",
99985732ac8SCy Schubert rxmap, txmap);
100085732ac8SCy Schubert if (os_snprintf_error(buflen - len, ret))
100185732ac8SCy Schubert return len;
100285732ac8SCy Schubert len += ret;
100385732ac8SCy Schubert }
100485732ac8SCy Schubert
100585732ac8SCy Schubert if (iface->conf->ieee80211n && !hapd->conf->disable_11n) {
100685732ac8SCy Schubert ret = os_snprintf(buf + len, buflen - len,
100785732ac8SCy Schubert "ht_caps_info=%04x\n",
100885732ac8SCy Schubert hapd->iconf->ht_capab);
100985732ac8SCy Schubert if (os_snprintf_error(buflen - len, ret))
101085732ac8SCy Schubert return len;
101185732ac8SCy Schubert len += ret;
101285732ac8SCy Schubert }
101385732ac8SCy Schubert
101485732ac8SCy Schubert if (iface->conf->ieee80211n && !hapd->conf->disable_11n && mode) {
101585732ac8SCy Schubert len = hostapd_write_ht_mcs_bitmask(buf, buflen, len,
101685732ac8SCy Schubert mode->mcs_set);
101785732ac8SCy Schubert }
101885732ac8SCy Schubert
101985732ac8SCy Schubert if (iface->current_rates && iface->num_rates) {
102085732ac8SCy Schubert ret = os_snprintf(buf + len, buflen - len, "supported_rates=");
102185732ac8SCy Schubert if (os_snprintf_error(buflen - len, ret))
102285732ac8SCy Schubert return len;
102385732ac8SCy Schubert len += ret;
102485732ac8SCy Schubert
102585732ac8SCy Schubert for (j = 0; j < iface->num_rates; j++) {
102685732ac8SCy Schubert ret = os_snprintf(buf + len, buflen - len, "%s%02x",
102785732ac8SCy Schubert j > 0 ? " " : "",
102885732ac8SCy Schubert iface->current_rates[j].rate / 5);
102985732ac8SCy Schubert if (os_snprintf_error(buflen - len, ret))
103085732ac8SCy Schubert return len;
103185732ac8SCy Schubert len += ret;
103285732ac8SCy Schubert }
103385732ac8SCy Schubert ret = os_snprintf(buf + len, buflen - len, "\n");
103485732ac8SCy Schubert if (os_snprintf_error(buflen - len, ret))
103585732ac8SCy Schubert return len;
103685732ac8SCy Schubert len += ret;
103785732ac8SCy Schubert }
103885732ac8SCy Schubert
103985732ac8SCy Schubert for (j = 0; mode && j < mode->num_channels; j++) {
104085732ac8SCy Schubert if (mode->channels[j].freq == iface->freq) {
104185732ac8SCy Schubert ret = os_snprintf(buf + len, buflen - len,
104285732ac8SCy Schubert "max_txpower=%u\n",
104385732ac8SCy Schubert mode->channels[j].max_tx_power);
104485732ac8SCy Schubert if (os_snprintf_error(buflen - len, ret))
104585732ac8SCy Schubert return len;
104685732ac8SCy Schubert len += ret;
104785732ac8SCy Schubert break;
104885732ac8SCy Schubert }
104985732ac8SCy Schubert }
105085732ac8SCy Schubert
10515b9c547cSRui Paulo for (i = 0; i < iface->num_bss; i++) {
10525b9c547cSRui Paulo struct hostapd_data *bss = iface->bss[i];
10535b9c547cSRui Paulo ret = os_snprintf(buf + len, buflen - len,
10545b9c547cSRui Paulo "bss[%d]=%s\n"
10555b9c547cSRui Paulo "bssid[%d]=" MACSTR "\n"
10565b9c547cSRui Paulo "ssid[%d]=%s\n"
10575b9c547cSRui Paulo "num_sta[%d]=%d\n",
10585b9c547cSRui Paulo (int) i, bss->conf->iface,
10595b9c547cSRui Paulo (int) i, MAC2STR(bss->own_addr),
10605b9c547cSRui Paulo (int) i,
10615b9c547cSRui Paulo wpa_ssid_txt(bss->conf->ssid.ssid,
10625b9c547cSRui Paulo bss->conf->ssid.ssid_len),
10635b9c547cSRui Paulo (int) i, bss->num_sta);
10645b9c547cSRui Paulo if (os_snprintf_error(buflen - len, ret))
10655b9c547cSRui Paulo return len;
10665b9c547cSRui Paulo len += ret;
1067*a90b9d01SCy Schubert
1068*a90b9d01SCy Schubert #ifdef CONFIG_IEEE80211BE
1069*a90b9d01SCy Schubert if (bss->conf->mld_ap) {
1070*a90b9d01SCy Schubert ret = os_snprintf(buf + len, buflen - len,
1071*a90b9d01SCy Schubert "mld_addr[%d]=" MACSTR "\n"
1072*a90b9d01SCy Schubert "mld_id[%d]=%d\n"
1073*a90b9d01SCy Schubert "mld_link_id[%d]=%d\n",
1074*a90b9d01SCy Schubert (int) i, MAC2STR(bss->mld->mld_addr),
1075*a90b9d01SCy Schubert (int) i, hostapd_get_mld_id(bss),
1076*a90b9d01SCy Schubert (int) i, bss->mld_link_id);
1077*a90b9d01SCy Schubert if (os_snprintf_error(buflen - len, ret))
1078*a90b9d01SCy Schubert return len;
1079*a90b9d01SCy Schubert len += ret;
1080*a90b9d01SCy Schubert }
1081*a90b9d01SCy Schubert #endif /* CONFIG_IEEE80211BE */
10825b9c547cSRui Paulo }
10835b9c547cSRui Paulo
108485732ac8SCy Schubert if (hapd->conf->chan_util_avg_period) {
108585732ac8SCy Schubert ret = os_snprintf(buf + len, buflen - len,
108685732ac8SCy Schubert "chan_util_avg=%u\n",
108785732ac8SCy Schubert iface->chan_util_average);
108885732ac8SCy Schubert if (os_snprintf_error(buflen - len, ret))
108985732ac8SCy Schubert return len;
109085732ac8SCy Schubert len += ret;
109185732ac8SCy Schubert }
109285732ac8SCy Schubert
10935b9c547cSRui Paulo return len;
10945b9c547cSRui Paulo }
10955b9c547cSRui Paulo
10965b9c547cSRui Paulo
hostapd_parse_csa_settings(const char * pos,struct csa_settings * settings)10975b9c547cSRui Paulo int hostapd_parse_csa_settings(const char *pos,
10985b9c547cSRui Paulo struct csa_settings *settings)
10995b9c547cSRui Paulo {
11005b9c547cSRui Paulo char *end;
11015b9c547cSRui Paulo
11025b9c547cSRui Paulo os_memset(settings, 0, sizeof(*settings));
11035b9c547cSRui Paulo settings->cs_count = strtol(pos, &end, 10);
11045b9c547cSRui Paulo if (pos == end) {
11055b9c547cSRui Paulo wpa_printf(MSG_ERROR, "chanswitch: invalid cs_count provided");
11065b9c547cSRui Paulo return -1;
11075b9c547cSRui Paulo }
11085b9c547cSRui Paulo
11095b9c547cSRui Paulo settings->freq_params.freq = atoi(end);
11105b9c547cSRui Paulo if (settings->freq_params.freq == 0) {
11115b9c547cSRui Paulo wpa_printf(MSG_ERROR, "chanswitch: invalid freq provided");
11125b9c547cSRui Paulo return -1;
11135b9c547cSRui Paulo }
11145b9c547cSRui Paulo
11155b9c547cSRui Paulo #define SET_CSA_SETTING(str) \
11165b9c547cSRui Paulo do { \
11175b9c547cSRui Paulo const char *pos2 = os_strstr(pos, " " #str "="); \
11185b9c547cSRui Paulo if (pos2) { \
11195b9c547cSRui Paulo pos2 += sizeof(" " #str "=") - 1; \
11205b9c547cSRui Paulo settings->freq_params.str = atoi(pos2); \
11215b9c547cSRui Paulo } \
11225b9c547cSRui Paulo } while (0)
11235b9c547cSRui Paulo
1124*a90b9d01SCy Schubert #define SET_CSA_SETTING_EXT(str) \
1125*a90b9d01SCy Schubert do { \
1126*a90b9d01SCy Schubert const char *pos2 = os_strstr(pos, " " #str "="); \
1127*a90b9d01SCy Schubert if (pos2) { \
1128*a90b9d01SCy Schubert pos2 += sizeof(" " #str "=") - 1; \
1129*a90b9d01SCy Schubert settings->str = atoi(pos2); \
1130*a90b9d01SCy Schubert } \
1131*a90b9d01SCy Schubert } while (0)
1132*a90b9d01SCy Schubert
11335b9c547cSRui Paulo SET_CSA_SETTING(center_freq1);
11345b9c547cSRui Paulo SET_CSA_SETTING(center_freq2);
11355b9c547cSRui Paulo SET_CSA_SETTING(bandwidth);
11365b9c547cSRui Paulo SET_CSA_SETTING(sec_channel_offset);
1137*a90b9d01SCy Schubert SET_CSA_SETTING_EXT(punct_bitmap);
11385b9c547cSRui Paulo settings->freq_params.ht_enabled = !!os_strstr(pos, " ht");
11395b9c547cSRui Paulo settings->freq_params.vht_enabled = !!os_strstr(pos, " vht");
1140c1d255d3SCy Schubert settings->freq_params.he_enabled = !!os_strstr(pos, " he");
1141*a90b9d01SCy Schubert settings->freq_params.eht_enabled = !!os_strstr(pos, " eht");
11425b9c547cSRui Paulo settings->block_tx = !!os_strstr(pos, " blocktx");
11435b9c547cSRui Paulo #undef SET_CSA_SETTING
1144*a90b9d01SCy Schubert #undef SET_CSA_SETTING_EXT
11455b9c547cSRui Paulo
11465b9c547cSRui Paulo return 0;
11475b9c547cSRui Paulo }
11485b9c547cSRui Paulo
11495b9c547cSRui Paulo
hostapd_ctrl_iface_stop_ap(struct hostapd_data * hapd)11505b9c547cSRui Paulo int hostapd_ctrl_iface_stop_ap(struct hostapd_data *hapd)
11515b9c547cSRui Paulo {
11525b9c547cSRui Paulo return hostapd_drv_stop_ap(hapd);
11535b9c547cSRui Paulo }
1154780fb4a2SCy Schubert
1155780fb4a2SCy Schubert
hostapd_ctrl_iface_pmksa_list(struct hostapd_data * hapd,char * buf,size_t len)1156780fb4a2SCy Schubert int hostapd_ctrl_iface_pmksa_list(struct hostapd_data *hapd, char *buf,
1157780fb4a2SCy Schubert size_t len)
1158780fb4a2SCy Schubert {
1159780fb4a2SCy Schubert return wpa_auth_pmksa_list(hapd->wpa_auth, buf, len);
1160780fb4a2SCy Schubert }
1161780fb4a2SCy Schubert
1162780fb4a2SCy Schubert
hostapd_ctrl_iface_pmksa_flush(struct hostapd_data * hapd)1163780fb4a2SCy Schubert void hostapd_ctrl_iface_pmksa_flush(struct hostapd_data *hapd)
1164780fb4a2SCy Schubert {
1165780fb4a2SCy Schubert wpa_auth_pmksa_flush(hapd->wpa_auth);
1166780fb4a2SCy Schubert }
116785732ac8SCy Schubert
116885732ac8SCy Schubert
hostapd_ctrl_iface_pmksa_add(struct hostapd_data * hapd,char * cmd)116985732ac8SCy Schubert int hostapd_ctrl_iface_pmksa_add(struct hostapd_data *hapd, char *cmd)
117085732ac8SCy Schubert {
117185732ac8SCy Schubert u8 spa[ETH_ALEN];
117285732ac8SCy Schubert u8 pmkid[PMKID_LEN];
117385732ac8SCy Schubert u8 pmk[PMK_LEN_MAX];
117485732ac8SCy Schubert size_t pmk_len;
117585732ac8SCy Schubert char *pos, *pos2;
117685732ac8SCy Schubert int akmp = 0, expiration = 0;
117785732ac8SCy Schubert
117885732ac8SCy Schubert /*
117985732ac8SCy Schubert * Entry format:
118085732ac8SCy Schubert * <STA addr> <PMKID> <PMK> <expiration in seconds> <akmp>
118185732ac8SCy Schubert */
118285732ac8SCy Schubert
118385732ac8SCy Schubert if (hwaddr_aton(cmd, spa))
118485732ac8SCy Schubert return -1;
118585732ac8SCy Schubert
118685732ac8SCy Schubert pos = os_strchr(cmd, ' ');
118785732ac8SCy Schubert if (!pos)
118885732ac8SCy Schubert return -1;
118985732ac8SCy Schubert pos++;
119085732ac8SCy Schubert
119185732ac8SCy Schubert if (hexstr2bin(pos, pmkid, PMKID_LEN) < 0)
119285732ac8SCy Schubert return -1;
119385732ac8SCy Schubert
119485732ac8SCy Schubert pos = os_strchr(pos, ' ');
119585732ac8SCy Schubert if (!pos)
119685732ac8SCy Schubert return -1;
119785732ac8SCy Schubert pos++;
119885732ac8SCy Schubert
119985732ac8SCy Schubert pos2 = os_strchr(pos, ' ');
120085732ac8SCy Schubert if (!pos2)
120185732ac8SCy Schubert return -1;
120285732ac8SCy Schubert pmk_len = (pos2 - pos) / 2;
120385732ac8SCy Schubert if (pmk_len < PMK_LEN || pmk_len > PMK_LEN_MAX ||
120485732ac8SCy Schubert hexstr2bin(pos, pmk, pmk_len) < 0)
120585732ac8SCy Schubert return -1;
120685732ac8SCy Schubert
120785732ac8SCy Schubert pos = pos2 + 1;
120885732ac8SCy Schubert
120985732ac8SCy Schubert if (sscanf(pos, "%d %d", &expiration, &akmp) != 2)
121085732ac8SCy Schubert return -1;
121185732ac8SCy Schubert
121285732ac8SCy Schubert return wpa_auth_pmksa_add2(hapd->wpa_auth, spa, pmk, pmk_len,
1213*a90b9d01SCy Schubert pmkid, expiration, akmp, NULL);
121485732ac8SCy Schubert }
121585732ac8SCy Schubert
121685732ac8SCy Schubert
121785732ac8SCy Schubert #ifdef CONFIG_PMKSA_CACHE_EXTERNAL
121885732ac8SCy Schubert #ifdef CONFIG_MESH
121985732ac8SCy Schubert
hostapd_ctrl_iface_pmksa_list_mesh(struct hostapd_data * hapd,const u8 * addr,char * buf,size_t len)122085732ac8SCy Schubert int hostapd_ctrl_iface_pmksa_list_mesh(struct hostapd_data *hapd,
122185732ac8SCy Schubert const u8 *addr, char *buf, size_t len)
122285732ac8SCy Schubert {
122385732ac8SCy Schubert return wpa_auth_pmksa_list_mesh(hapd->wpa_auth, addr, buf, len);
122485732ac8SCy Schubert }
122585732ac8SCy Schubert
122685732ac8SCy Schubert
hostapd_ctrl_iface_pmksa_create_entry(const u8 * aa,char * cmd)122785732ac8SCy Schubert void * hostapd_ctrl_iface_pmksa_create_entry(const u8 *aa, char *cmd)
122885732ac8SCy Schubert {
122985732ac8SCy Schubert u8 spa[ETH_ALEN];
123085732ac8SCy Schubert u8 pmkid[PMKID_LEN];
123185732ac8SCy Schubert u8 pmk[PMK_LEN_MAX];
123285732ac8SCy Schubert char *pos;
123385732ac8SCy Schubert int expiration;
123485732ac8SCy Schubert
123585732ac8SCy Schubert /*
123685732ac8SCy Schubert * Entry format:
123785732ac8SCy Schubert * <BSSID> <PMKID> <PMK> <expiration in seconds>
123885732ac8SCy Schubert */
123985732ac8SCy Schubert
124085732ac8SCy Schubert if (hwaddr_aton(cmd, spa))
124185732ac8SCy Schubert return NULL;
124285732ac8SCy Schubert
124385732ac8SCy Schubert pos = os_strchr(cmd, ' ');
124485732ac8SCy Schubert if (!pos)
124585732ac8SCy Schubert return NULL;
124685732ac8SCy Schubert pos++;
124785732ac8SCy Schubert
124885732ac8SCy Schubert if (hexstr2bin(pos, pmkid, PMKID_LEN) < 0)
124985732ac8SCy Schubert return NULL;
125085732ac8SCy Schubert
125185732ac8SCy Schubert pos = os_strchr(pos, ' ');
125285732ac8SCy Schubert if (!pos)
125385732ac8SCy Schubert return NULL;
125485732ac8SCy Schubert pos++;
125585732ac8SCy Schubert
125685732ac8SCy Schubert if (hexstr2bin(pos, pmk, PMK_LEN) < 0)
125785732ac8SCy Schubert return NULL;
125885732ac8SCy Schubert
125985732ac8SCy Schubert pos = os_strchr(pos, ' ');
126085732ac8SCy Schubert if (!pos)
126185732ac8SCy Schubert return NULL;
126285732ac8SCy Schubert pos++;
126385732ac8SCy Schubert
126485732ac8SCy Schubert if (sscanf(pos, "%d", &expiration) != 1)
126585732ac8SCy Schubert return NULL;
126685732ac8SCy Schubert
1267*a90b9d01SCy Schubert return wpa_auth_pmksa_create_entry(aa, spa, pmk, PMK_LEN,
1268*a90b9d01SCy Schubert WPA_KEY_MGMT_SAE, pmkid, expiration);
126985732ac8SCy Schubert }
127085732ac8SCy Schubert
127185732ac8SCy Schubert #endif /* CONFIG_MESH */
127285732ac8SCy Schubert #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
1273*a90b9d01SCy Schubert
1274*a90b9d01SCy Schubert
1275*a90b9d01SCy Schubert #ifdef CONFIG_WNM_AP
1276*a90b9d01SCy Schubert
hostapd_ctrl_iface_disassoc_imminent(struct hostapd_data * hapd,const char * cmd)1277*a90b9d01SCy Schubert int hostapd_ctrl_iface_disassoc_imminent(struct hostapd_data *hapd,
1278*a90b9d01SCy Schubert const char *cmd)
1279*a90b9d01SCy Schubert {
1280*a90b9d01SCy Schubert u8 addr[ETH_ALEN];
1281*a90b9d01SCy Schubert int disassoc_timer;
1282*a90b9d01SCy Schubert struct sta_info *sta;
1283*a90b9d01SCy Schubert
1284*a90b9d01SCy Schubert if (hwaddr_aton(cmd, addr))
1285*a90b9d01SCy Schubert return -1;
1286*a90b9d01SCy Schubert if (cmd[17] != ' ')
1287*a90b9d01SCy Schubert return -1;
1288*a90b9d01SCy Schubert disassoc_timer = atoi(cmd + 17);
1289*a90b9d01SCy Schubert
1290*a90b9d01SCy Schubert sta = ap_get_sta(hapd, addr);
1291*a90b9d01SCy Schubert if (sta == NULL) {
1292*a90b9d01SCy Schubert wpa_printf(MSG_DEBUG, "Station " MACSTR
1293*a90b9d01SCy Schubert " not found for disassociation imminent message",
1294*a90b9d01SCy Schubert MAC2STR(addr));
1295*a90b9d01SCy Schubert return -1;
1296*a90b9d01SCy Schubert }
1297*a90b9d01SCy Schubert
1298*a90b9d01SCy Schubert return wnm_send_disassoc_imminent(hapd, sta, disassoc_timer);
1299*a90b9d01SCy Schubert }
1300*a90b9d01SCy Schubert
1301*a90b9d01SCy Schubert
hostapd_ctrl_iface_ess_disassoc(struct hostapd_data * hapd,const char * cmd)1302*a90b9d01SCy Schubert int hostapd_ctrl_iface_ess_disassoc(struct hostapd_data *hapd,
1303*a90b9d01SCy Schubert const char *cmd)
1304*a90b9d01SCy Schubert {
1305*a90b9d01SCy Schubert u8 addr[ETH_ALEN];
1306*a90b9d01SCy Schubert const char *url, *timerstr;
1307*a90b9d01SCy Schubert int disassoc_timer;
1308*a90b9d01SCy Schubert struct sta_info *sta;
1309*a90b9d01SCy Schubert
1310*a90b9d01SCy Schubert if (hwaddr_aton(cmd, addr))
1311*a90b9d01SCy Schubert return -1;
1312*a90b9d01SCy Schubert
1313*a90b9d01SCy Schubert sta = ap_get_sta(hapd, addr);
1314*a90b9d01SCy Schubert if (sta == NULL) {
1315*a90b9d01SCy Schubert wpa_printf(MSG_DEBUG, "Station " MACSTR
1316*a90b9d01SCy Schubert " not found for ESS disassociation imminent message",
1317*a90b9d01SCy Schubert MAC2STR(addr));
1318*a90b9d01SCy Schubert return -1;
1319*a90b9d01SCy Schubert }
1320*a90b9d01SCy Schubert
1321*a90b9d01SCy Schubert timerstr = cmd + 17;
1322*a90b9d01SCy Schubert if (*timerstr != ' ')
1323*a90b9d01SCy Schubert return -1;
1324*a90b9d01SCy Schubert timerstr++;
1325*a90b9d01SCy Schubert disassoc_timer = atoi(timerstr);
1326*a90b9d01SCy Schubert if (disassoc_timer < 0 || disassoc_timer > 65535)
1327*a90b9d01SCy Schubert return -1;
1328*a90b9d01SCy Schubert
1329*a90b9d01SCy Schubert url = os_strchr(timerstr, ' ');
1330*a90b9d01SCy Schubert if (url == NULL)
1331*a90b9d01SCy Schubert return -1;
1332*a90b9d01SCy Schubert url++;
1333*a90b9d01SCy Schubert
1334*a90b9d01SCy Schubert return wnm_send_ess_disassoc_imminent(hapd, sta, url, disassoc_timer);
1335*a90b9d01SCy Schubert }
1336*a90b9d01SCy Schubert
1337*a90b9d01SCy Schubert
hostapd_ctrl_iface_bss_tm_req(struct hostapd_data * hapd,const char * cmd)1338*a90b9d01SCy Schubert int hostapd_ctrl_iface_bss_tm_req(struct hostapd_data *hapd,
1339*a90b9d01SCy Schubert const char *cmd)
1340*a90b9d01SCy Schubert {
1341*a90b9d01SCy Schubert u8 addr[ETH_ALEN];
1342*a90b9d01SCy Schubert const char *pos, *end;
1343*a90b9d01SCy Schubert int disassoc_timer = 0;
1344*a90b9d01SCy Schubert struct sta_info *sta;
1345*a90b9d01SCy Schubert u8 req_mode = 0, valid_int = 0x01, dialog_token = 0x01;
1346*a90b9d01SCy Schubert u8 bss_term_dur[12];
1347*a90b9d01SCy Schubert char *url = NULL;
1348*a90b9d01SCy Schubert int ret;
1349*a90b9d01SCy Schubert u8 nei_rep[1000];
1350*a90b9d01SCy Schubert int nei_len;
1351*a90b9d01SCy Schubert u8 mbo[10];
1352*a90b9d01SCy Schubert size_t mbo_len = 0;
1353*a90b9d01SCy Schubert
1354*a90b9d01SCy Schubert if (hwaddr_aton(cmd, addr)) {
1355*a90b9d01SCy Schubert wpa_printf(MSG_DEBUG, "Invalid STA MAC address");
1356*a90b9d01SCy Schubert return -1;
1357*a90b9d01SCy Schubert }
1358*a90b9d01SCy Schubert
1359*a90b9d01SCy Schubert sta = ap_get_sta(hapd, addr);
1360*a90b9d01SCy Schubert if (sta == NULL) {
1361*a90b9d01SCy Schubert wpa_printf(MSG_DEBUG, "Station " MACSTR
1362*a90b9d01SCy Schubert " not found for BSS TM Request message",
1363*a90b9d01SCy Schubert MAC2STR(addr));
1364*a90b9d01SCy Schubert return -1;
1365*a90b9d01SCy Schubert }
1366*a90b9d01SCy Schubert
1367*a90b9d01SCy Schubert pos = os_strstr(cmd, " disassoc_timer=");
1368*a90b9d01SCy Schubert if (pos) {
1369*a90b9d01SCy Schubert pos += 16;
1370*a90b9d01SCy Schubert disassoc_timer = atoi(pos);
1371*a90b9d01SCy Schubert if (disassoc_timer < 0 || disassoc_timer > 65535) {
1372*a90b9d01SCy Schubert wpa_printf(MSG_DEBUG, "Invalid disassoc_timer");
1373*a90b9d01SCy Schubert return -1;
1374*a90b9d01SCy Schubert }
1375*a90b9d01SCy Schubert }
1376*a90b9d01SCy Schubert
1377*a90b9d01SCy Schubert pos = os_strstr(cmd, " valid_int=");
1378*a90b9d01SCy Schubert if (pos) {
1379*a90b9d01SCy Schubert pos += 11;
1380*a90b9d01SCy Schubert valid_int = atoi(pos);
1381*a90b9d01SCy Schubert }
1382*a90b9d01SCy Schubert
1383*a90b9d01SCy Schubert pos = os_strstr(cmd, " dialog_token=");
1384*a90b9d01SCy Schubert if (pos) {
1385*a90b9d01SCy Schubert pos += 14;
1386*a90b9d01SCy Schubert dialog_token = atoi(pos);
1387*a90b9d01SCy Schubert }
1388*a90b9d01SCy Schubert
1389*a90b9d01SCy Schubert pos = os_strstr(cmd, " bss_term=");
1390*a90b9d01SCy Schubert if (pos) {
1391*a90b9d01SCy Schubert pos += 10;
1392*a90b9d01SCy Schubert req_mode |= WNM_BSS_TM_REQ_BSS_TERMINATION_INCLUDED;
1393*a90b9d01SCy Schubert /* TODO: TSF configurable/learnable */
1394*a90b9d01SCy Schubert bss_term_dur[0] = 4; /* Subelement ID */
1395*a90b9d01SCy Schubert bss_term_dur[1] = 10; /* Length */
1396*a90b9d01SCy Schubert os_memset(&bss_term_dur[2], 0, 8);
1397*a90b9d01SCy Schubert end = os_strchr(pos, ',');
1398*a90b9d01SCy Schubert if (end == NULL) {
1399*a90b9d01SCy Schubert wpa_printf(MSG_DEBUG, "Invalid bss_term data");
1400*a90b9d01SCy Schubert return -1;
1401*a90b9d01SCy Schubert }
1402*a90b9d01SCy Schubert end++;
1403*a90b9d01SCy Schubert WPA_PUT_LE16(&bss_term_dur[10], atoi(end));
1404*a90b9d01SCy Schubert }
1405*a90b9d01SCy Schubert
1406*a90b9d01SCy Schubert nei_len = ieee802_11_parse_candidate_list(cmd, nei_rep,
1407*a90b9d01SCy Schubert sizeof(nei_rep));
1408*a90b9d01SCy Schubert if (nei_len < 0)
1409*a90b9d01SCy Schubert return -1;
1410*a90b9d01SCy Schubert
1411*a90b9d01SCy Schubert pos = os_strstr(cmd, " url=");
1412*a90b9d01SCy Schubert if (pos) {
1413*a90b9d01SCy Schubert size_t len;
1414*a90b9d01SCy Schubert pos += 5;
1415*a90b9d01SCy Schubert end = os_strchr(pos, ' ');
1416*a90b9d01SCy Schubert if (end)
1417*a90b9d01SCy Schubert len = end - pos;
1418*a90b9d01SCy Schubert else
1419*a90b9d01SCy Schubert len = os_strlen(pos);
1420*a90b9d01SCy Schubert url = os_malloc(len + 1);
1421*a90b9d01SCy Schubert if (url == NULL)
1422*a90b9d01SCy Schubert return -1;
1423*a90b9d01SCy Schubert os_memcpy(url, pos, len);
1424*a90b9d01SCy Schubert url[len] = '\0';
1425*a90b9d01SCy Schubert req_mode |= WNM_BSS_TM_REQ_ESS_DISASSOC_IMMINENT;
1426*a90b9d01SCy Schubert }
1427*a90b9d01SCy Schubert
1428*a90b9d01SCy Schubert if (os_strstr(cmd, " pref=1"))
1429*a90b9d01SCy Schubert req_mode |= WNM_BSS_TM_REQ_PREF_CAND_LIST_INCLUDED;
1430*a90b9d01SCy Schubert if (os_strstr(cmd, " abridged=1"))
1431*a90b9d01SCy Schubert req_mode |= WNM_BSS_TM_REQ_ABRIDGED;
1432*a90b9d01SCy Schubert if (os_strstr(cmd, " disassoc_imminent=1"))
1433*a90b9d01SCy Schubert req_mode |= WNM_BSS_TM_REQ_DISASSOC_IMMINENT;
1434*a90b9d01SCy Schubert if (os_strstr(cmd, " link_removal_imminent=1"))
1435*a90b9d01SCy Schubert req_mode |= WNM_BSS_TM_REQ_LINK_REMOVAL_IMMINENT;
1436*a90b9d01SCy Schubert
1437*a90b9d01SCy Schubert #ifdef CONFIG_MBO
1438*a90b9d01SCy Schubert pos = os_strstr(cmd, "mbo=");
1439*a90b9d01SCy Schubert if (pos) {
1440*a90b9d01SCy Schubert unsigned int mbo_reason, cell_pref, reassoc_delay;
1441*a90b9d01SCy Schubert u8 *mbo_pos = mbo;
1442*a90b9d01SCy Schubert
1443*a90b9d01SCy Schubert ret = sscanf(pos, "mbo=%u:%u:%u", &mbo_reason,
1444*a90b9d01SCy Schubert &reassoc_delay, &cell_pref);
1445*a90b9d01SCy Schubert if (ret != 3) {
1446*a90b9d01SCy Schubert wpa_printf(MSG_DEBUG,
1447*a90b9d01SCy Schubert "MBO requires three arguments: mbo=<reason>:<reassoc_delay>:<cell_pref>");
1448*a90b9d01SCy Schubert ret = -1;
1449*a90b9d01SCy Schubert goto fail;
1450*a90b9d01SCy Schubert }
1451*a90b9d01SCy Schubert
1452*a90b9d01SCy Schubert if (mbo_reason > MBO_TRANSITION_REASON_PREMIUM_AP) {
1453*a90b9d01SCy Schubert wpa_printf(MSG_DEBUG,
1454*a90b9d01SCy Schubert "Invalid MBO transition reason code %u",
1455*a90b9d01SCy Schubert mbo_reason);
1456*a90b9d01SCy Schubert ret = -1;
1457*a90b9d01SCy Schubert goto fail;
1458*a90b9d01SCy Schubert }
1459*a90b9d01SCy Schubert
1460*a90b9d01SCy Schubert /* Valid values for Cellular preference are: 0, 1, 255 */
1461*a90b9d01SCy Schubert if (cell_pref != 0 && cell_pref != 1 && cell_pref != 255) {
1462*a90b9d01SCy Schubert wpa_printf(MSG_DEBUG,
1463*a90b9d01SCy Schubert "Invalid MBO cellular capability %u",
1464*a90b9d01SCy Schubert cell_pref);
1465*a90b9d01SCy Schubert ret = -1;
1466*a90b9d01SCy Schubert goto fail;
1467*a90b9d01SCy Schubert }
1468*a90b9d01SCy Schubert
1469*a90b9d01SCy Schubert if (reassoc_delay > 65535 ||
1470*a90b9d01SCy Schubert (reassoc_delay &&
1471*a90b9d01SCy Schubert !(req_mode & WNM_BSS_TM_REQ_DISASSOC_IMMINENT))) {
1472*a90b9d01SCy Schubert wpa_printf(MSG_DEBUG,
1473*a90b9d01SCy Schubert "MBO: Assoc retry delay is only valid in disassoc imminent mode");
1474*a90b9d01SCy Schubert ret = -1;
1475*a90b9d01SCy Schubert goto fail;
1476*a90b9d01SCy Schubert }
1477*a90b9d01SCy Schubert
1478*a90b9d01SCy Schubert *mbo_pos++ = MBO_ATTR_ID_TRANSITION_REASON;
1479*a90b9d01SCy Schubert *mbo_pos++ = 1;
1480*a90b9d01SCy Schubert *mbo_pos++ = mbo_reason;
1481*a90b9d01SCy Schubert *mbo_pos++ = MBO_ATTR_ID_CELL_DATA_PREF;
1482*a90b9d01SCy Schubert *mbo_pos++ = 1;
1483*a90b9d01SCy Schubert *mbo_pos++ = cell_pref;
1484*a90b9d01SCy Schubert
1485*a90b9d01SCy Schubert if (reassoc_delay) {
1486*a90b9d01SCy Schubert *mbo_pos++ = MBO_ATTR_ID_ASSOC_RETRY_DELAY;
1487*a90b9d01SCy Schubert *mbo_pos++ = 2;
1488*a90b9d01SCy Schubert WPA_PUT_LE16(mbo_pos, reassoc_delay);
1489*a90b9d01SCy Schubert mbo_pos += 2;
1490*a90b9d01SCy Schubert }
1491*a90b9d01SCy Schubert
1492*a90b9d01SCy Schubert mbo_len = mbo_pos - mbo;
1493*a90b9d01SCy Schubert }
1494*a90b9d01SCy Schubert #endif /* CONFIG_MBO */
1495*a90b9d01SCy Schubert
1496*a90b9d01SCy Schubert ret = wnm_send_bss_tm_req(hapd, sta, req_mode, disassoc_timer,
1497*a90b9d01SCy Schubert valid_int, bss_term_dur, dialog_token, url,
1498*a90b9d01SCy Schubert nei_len ? nei_rep : NULL, nei_len,
1499*a90b9d01SCy Schubert mbo_len ? mbo : NULL, mbo_len);
1500*a90b9d01SCy Schubert #ifdef CONFIG_MBO
1501*a90b9d01SCy Schubert fail:
1502*a90b9d01SCy Schubert #endif /* CONFIG_MBO */
1503*a90b9d01SCy Schubert os_free(url);
1504*a90b9d01SCy Schubert return ret;
1505*a90b9d01SCy Schubert }
1506*a90b9d01SCy Schubert
1507*a90b9d01SCy Schubert #endif /* CONFIG_WNM_AP */
1508*a90b9d01SCy Schubert
1509*a90b9d01SCy Schubert
hostapd_ctrl_iface_acl_del_mac(struct mac_acl_entry ** acl,int * num,const char * txtaddr)1510*a90b9d01SCy Schubert int hostapd_ctrl_iface_acl_del_mac(struct mac_acl_entry **acl, int *num,
1511*a90b9d01SCy Schubert const char *txtaddr)
1512*a90b9d01SCy Schubert {
1513*a90b9d01SCy Schubert u8 addr[ETH_ALEN];
1514*a90b9d01SCy Schubert struct vlan_description vlan_id;
1515*a90b9d01SCy Schubert
1516*a90b9d01SCy Schubert if (!(*num))
1517*a90b9d01SCy Schubert return 0;
1518*a90b9d01SCy Schubert
1519*a90b9d01SCy Schubert if (hwaddr_aton(txtaddr, addr))
1520*a90b9d01SCy Schubert return -1;
1521*a90b9d01SCy Schubert
1522*a90b9d01SCy Schubert if (hostapd_maclist_found(*acl, *num, addr, &vlan_id))
1523*a90b9d01SCy Schubert hostapd_remove_acl_mac(acl, num, addr);
1524*a90b9d01SCy Schubert
1525*a90b9d01SCy Schubert return 0;
1526*a90b9d01SCy Schubert }
1527*a90b9d01SCy Schubert
1528*a90b9d01SCy Schubert
hostapd_ctrl_iface_acl_clear_list(struct mac_acl_entry ** acl,int * num)1529*a90b9d01SCy Schubert void hostapd_ctrl_iface_acl_clear_list(struct mac_acl_entry **acl,
1530*a90b9d01SCy Schubert int *num)
1531*a90b9d01SCy Schubert {
1532*a90b9d01SCy Schubert while (*num)
1533*a90b9d01SCy Schubert hostapd_remove_acl_mac(acl, num, (*acl)[0].addr);
1534*a90b9d01SCy Schubert }
1535*a90b9d01SCy Schubert
1536*a90b9d01SCy Schubert
hostapd_ctrl_iface_acl_show_mac(struct mac_acl_entry * acl,int num,char * buf,size_t buflen)1537*a90b9d01SCy Schubert int hostapd_ctrl_iface_acl_show_mac(struct mac_acl_entry *acl, int num,
1538*a90b9d01SCy Schubert char *buf, size_t buflen)
1539*a90b9d01SCy Schubert {
1540*a90b9d01SCy Schubert int i = 0, len = 0, ret = 0;
1541*a90b9d01SCy Schubert
1542*a90b9d01SCy Schubert if (!acl)
1543*a90b9d01SCy Schubert return 0;
1544*a90b9d01SCy Schubert
1545*a90b9d01SCy Schubert while (i < num) {
1546*a90b9d01SCy Schubert ret = os_snprintf(buf + len, buflen - len,
1547*a90b9d01SCy Schubert MACSTR " VLAN_ID=%d\n",
1548*a90b9d01SCy Schubert MAC2STR(acl[i].addr),
1549*a90b9d01SCy Schubert acl[i].vlan_id.untagged);
1550*a90b9d01SCy Schubert if (ret < 0 || (size_t) ret >= buflen - len)
1551*a90b9d01SCy Schubert return len;
1552*a90b9d01SCy Schubert i++;
1553*a90b9d01SCy Schubert len += ret;
1554*a90b9d01SCy Schubert }
1555*a90b9d01SCy Schubert return len;
1556*a90b9d01SCy Schubert }
1557*a90b9d01SCy Schubert
1558*a90b9d01SCy Schubert
hostapd_ctrl_iface_acl_add_mac(struct mac_acl_entry ** acl,int * num,const char * cmd)1559*a90b9d01SCy Schubert int hostapd_ctrl_iface_acl_add_mac(struct mac_acl_entry **acl, int *num,
1560*a90b9d01SCy Schubert const char *cmd)
1561*a90b9d01SCy Schubert {
1562*a90b9d01SCy Schubert u8 addr[ETH_ALEN];
1563*a90b9d01SCy Schubert struct vlan_description vlan_id;
1564*a90b9d01SCy Schubert int ret = 0, vlanid = 0;
1565*a90b9d01SCy Schubert const char *pos;
1566*a90b9d01SCy Schubert
1567*a90b9d01SCy Schubert if (hwaddr_aton(cmd, addr))
1568*a90b9d01SCy Schubert return -1;
1569*a90b9d01SCy Schubert
1570*a90b9d01SCy Schubert pos = os_strstr(cmd, "VLAN_ID=");
1571*a90b9d01SCy Schubert if (pos)
1572*a90b9d01SCy Schubert vlanid = atoi(pos + 8);
1573*a90b9d01SCy Schubert
1574*a90b9d01SCy Schubert if (!hostapd_maclist_found(*acl, *num, addr, &vlan_id)) {
1575*a90b9d01SCy Schubert ret = hostapd_add_acl_maclist(acl, num, vlanid, addr);
1576*a90b9d01SCy Schubert if (ret != -1 && *acl)
1577*a90b9d01SCy Schubert qsort(*acl, *num, sizeof(**acl), hostapd_acl_comp);
1578*a90b9d01SCy Schubert }
1579*a90b9d01SCy Schubert
1580*a90b9d01SCy Schubert return ret < 0 ? -1 : 0;
1581*a90b9d01SCy Schubert }
1582*a90b9d01SCy Schubert
1583*a90b9d01SCy Schubert
hostapd_disassoc_accept_mac(struct hostapd_data * hapd)1584*a90b9d01SCy Schubert int hostapd_disassoc_accept_mac(struct hostapd_data *hapd)
1585*a90b9d01SCy Schubert {
1586*a90b9d01SCy Schubert struct sta_info *sta;
1587*a90b9d01SCy Schubert struct vlan_description vlan_id;
1588*a90b9d01SCy Schubert
1589*a90b9d01SCy Schubert if (hapd->conf->macaddr_acl != DENY_UNLESS_ACCEPTED)
1590*a90b9d01SCy Schubert return 0;
1591*a90b9d01SCy Schubert
1592*a90b9d01SCy Schubert for (sta = hapd->sta_list; sta; sta = sta->next) {
1593*a90b9d01SCy Schubert if (!hostapd_maclist_found(hapd->conf->accept_mac,
1594*a90b9d01SCy Schubert hapd->conf->num_accept_mac,
1595*a90b9d01SCy Schubert sta->addr, &vlan_id) ||
1596*a90b9d01SCy Schubert (vlan_id.notempty &&
1597*a90b9d01SCy Schubert vlan_compare(&vlan_id, sta->vlan_desc)))
1598*a90b9d01SCy Schubert ap_sta_disconnect(hapd, sta, sta->addr,
1599*a90b9d01SCy Schubert WLAN_REASON_UNSPECIFIED);
1600*a90b9d01SCy Schubert }
1601*a90b9d01SCy Schubert
1602*a90b9d01SCy Schubert return 0;
1603*a90b9d01SCy Schubert }
1604*a90b9d01SCy Schubert
1605*a90b9d01SCy Schubert
hostapd_disassoc_deny_mac(struct hostapd_data * hapd)1606*a90b9d01SCy Schubert int hostapd_disassoc_deny_mac(struct hostapd_data *hapd)
1607*a90b9d01SCy Schubert {
1608*a90b9d01SCy Schubert struct sta_info *sta;
1609*a90b9d01SCy Schubert struct vlan_description vlan_id;
1610*a90b9d01SCy Schubert
1611*a90b9d01SCy Schubert for (sta = hapd->sta_list; sta; sta = sta->next) {
1612*a90b9d01SCy Schubert if (hostapd_maclist_found(hapd->conf->deny_mac,
1613*a90b9d01SCy Schubert hapd->conf->num_deny_mac, sta->addr,
1614*a90b9d01SCy Schubert &vlan_id) &&
1615*a90b9d01SCy Schubert (!vlan_id.notempty ||
1616*a90b9d01SCy Schubert !vlan_compare(&vlan_id, sta->vlan_desc)))
1617*a90b9d01SCy Schubert ap_sta_disconnect(hapd, sta, sta->addr,
1618*a90b9d01SCy Schubert WLAN_REASON_UNSPECIFIED);
1619*a90b9d01SCy Schubert }
1620*a90b9d01SCy Schubert
1621*a90b9d01SCy Schubert return 0;
1622*a90b9d01SCy Schubert }
1623