2 * WPA Supplicant / Control interface (shared code for all backends)
3 * Copyright (c) 2004-2014, 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"
10 #ifdef CONFIG_TESTING_OPTIONS
11 #include <net/ethernet.h>
12 #include <netinet/ip.h>
13 #endif /* CONFIG_TESTING_OPTIONS */
15 #include "utils/common.h"
16 #include "utils/eloop.h"
17 #include "utils/uuid.h"
18 #include "common/version.h"
19 #include "common/ieee802_11_defs.h"
20 #include "common/ieee802_11_common.h"
21 #include "common/wpa_ctrl.h"
22 #include "ap/hostapd.h"
23 #include "eap_peer/eap.h"
24 #include "eapol_supp/eapol_supp_sm.h"
25 #include "rsn_supp/wpa.h"
26 #include "rsn_supp/preauth.h"
27 #include "rsn_supp/pmksa_cache.h"
28 #include "l2_packet/l2_packet.h"
31 #include "wpa_supplicant_i.h"
33 #include "wps_supplicant.h"
36 #include "p2p_supplicant.h"
38 #include "hs20_supplicant.h"
39 #include "wifi_display.h"
43 #include "ctrl_iface.h"
44 #include "interworking.h"
45 #include "blacklist.h"
48 #include "offchannel.h"
49 #include "drivers/driver.h"
51 static int wpa_supplicant_global_iface_list(struct wpa_global *global,
53 static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
55 static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s,
58 static int set_bssid_filter(struct wpa_supplicant *wpa_s, char *val)
61 u8 addr[ETH_ALEN], *filter = NULL, *n;
68 if (hwaddr_aton(pos, addr)) {
72 n = os_realloc_array(filter, count + 1, ETH_ALEN);
78 os_memcpy(filter + count * ETH_ALEN, addr, ETH_ALEN);
81 pos = os_strchr(pos, ' ');
86 wpa_hexdump(MSG_DEBUG, "bssid_filter", filter, count * ETH_ALEN);
87 os_free(wpa_s->bssid_filter);
88 wpa_s->bssid_filter = filter;
89 wpa_s->bssid_filter_count = count;
95 static int set_disallow_aps(struct wpa_supplicant *wpa_s, char *val)
98 u8 addr[ETH_ALEN], *bssid = NULL, *n;
99 struct wpa_ssid_value *ssid = NULL, *ns;
100 size_t count = 0, ssid_count = 0;
104 * disallow_list ::= <ssid_spec> | <bssid_spec> | <disallow_list> | ""
105 * SSID_SPEC ::= ssid <SSID_HEX>
106 * BSSID_SPEC ::= bssid <BSSID_HEX>
113 if (os_strncmp(pos, "bssid ", 6) == 0) {
116 res = hwaddr_aton2(pos, addr);
120 wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
121 "BSSID value '%s'", pos);
125 n = os_realloc_array(bssid, count + 1, ETH_ALEN);
132 os_memcpy(bssid + count * ETH_ALEN, addr, ETH_ALEN);
134 } else if (os_strncmp(pos, "ssid ", 5) == 0) {
140 if (*end == '\0' || *end == ' ')
145 ns = os_realloc_array(ssid, ssid_count + 1,
146 sizeof(struct wpa_ssid_value));
154 if ((end - pos) & 0x01 || end - pos > 2 * 32 ||
155 hexstr2bin(pos, ssid[ssid_count].ssid,
156 (end - pos) / 2) < 0) {
159 wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
160 "SSID value '%s'", pos);
163 ssid[ssid_count].ssid_len = (end - pos) / 2;
164 wpa_hexdump_ascii(MSG_DEBUG, "disallow_aps SSID",
165 ssid[ssid_count].ssid,
166 ssid[ssid_count].ssid_len);
170 wpa_printf(MSG_DEBUG, "Unexpected disallow_aps value "
177 pos = os_strchr(pos, ' ');
182 wpa_hexdump(MSG_DEBUG, "disallow_aps_bssid", bssid, count * ETH_ALEN);
183 os_free(wpa_s->disallow_aps_bssid);
184 wpa_s->disallow_aps_bssid = bssid;
185 wpa_s->disallow_aps_bssid_count = count;
187 wpa_printf(MSG_DEBUG, "disallow_aps_ssid_count %d", (int) ssid_count);
188 os_free(wpa_s->disallow_aps_ssid);
189 wpa_s->disallow_aps_ssid = ssid;
190 wpa_s->disallow_aps_ssid_count = ssid_count;
192 if (!wpa_s->current_ssid || wpa_s->wpa_state < WPA_AUTHENTICATING)
195 c = wpa_s->current_ssid;
196 if (c->mode != WPAS_MODE_INFRA && c->mode != WPAS_MODE_IBSS)
199 if (!disallowed_bssid(wpa_s, wpa_s->bssid) &&
200 !disallowed_ssid(wpa_s, c->ssid, c->ssid_len))
203 wpa_printf(MSG_DEBUG, "Disconnect and try to find another network "
204 "because current AP was marked disallowed");
207 wpa_s->sme.prev_bssid_set = 0;
208 #endif /* CONFIG_SME */
209 wpa_s->reassociate = 1;
210 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
211 wpa_supplicant_req_scan(wpa_s, 0, 0);
217 #ifndef CONFIG_NO_CONFIG_BLOBS
218 static int wpas_ctrl_set_blob(struct wpa_supplicant *wpa_s, char *pos)
221 struct wpa_config_blob *blob;
224 pos = os_strchr(pos, ' ');
228 len = os_strlen(pos);
232 wpa_printf(MSG_DEBUG, "CTRL: Set blob '%s'", name);
233 blob = os_zalloc(sizeof(*blob));
236 blob->name = os_strdup(name);
237 blob->data = os_malloc(len / 2);
238 if (blob->name == NULL || blob->data == NULL) {
239 wpa_config_free_blob(blob);
243 if (hexstr2bin(pos, blob->data, len / 2) < 0) {
244 wpa_printf(MSG_DEBUG, "CTRL: Invalid blob hex data");
245 wpa_config_free_blob(blob);
250 wpa_config_set_blob(wpa_s->conf, blob);
254 #endif /* CONFIG_NO_CONFIG_BLOBS */
257 static int wpas_ctrl_pno(struct wpa_supplicant *wpa_s, char *cmd)
265 params = os_strchr(cmd, ' ');
266 os_free(wpa_s->manual_sched_scan_freqs);
269 pos = os_strstr(params, "freq=");
271 freqs = freq_range_to_channel_list(wpa_s,
274 wpa_s->manual_sched_scan_freqs = freqs;
275 ret = wpas_start_pno(wpa_s);
277 ret = wpas_stop_pno(wpa_s);
283 static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s,
289 value = os_strchr(cmd, ' ');
294 wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value);
295 if (os_strcasecmp(cmd, "EAPOL::heldPeriod") == 0) {
296 eapol_sm_configure(wpa_s->eapol,
297 atoi(value), -1, -1, -1);
298 } else if (os_strcasecmp(cmd, "EAPOL::authPeriod") == 0) {
299 eapol_sm_configure(wpa_s->eapol,
300 -1, atoi(value), -1, -1);
301 } else if (os_strcasecmp(cmd, "EAPOL::startPeriod") == 0) {
302 eapol_sm_configure(wpa_s->eapol,
303 -1, -1, atoi(value), -1);
304 } else if (os_strcasecmp(cmd, "EAPOL::maxStart") == 0) {
305 eapol_sm_configure(wpa_s->eapol,
306 -1, -1, -1, atoi(value));
307 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKLifetime") == 0) {
308 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME,
311 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKReauthThreshold") ==
313 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD,
316 } else if (os_strcasecmp(cmd, "dot11RSNAConfigSATimeout") == 0) {
317 if (wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, atoi(value)))
319 } else if (os_strcasecmp(cmd, "wps_fragment_size") == 0) {
320 wpa_s->wps_fragment_size = atoi(value);
321 #ifdef CONFIG_WPS_TESTING
322 } else if (os_strcasecmp(cmd, "wps_version_number") == 0) {
324 val = strtol(value, NULL, 0);
325 if (val < 0 || val > 0xff) {
327 wpa_printf(MSG_DEBUG, "WPS: Invalid "
328 "wps_version_number %ld", val);
330 wps_version_number = val;
331 wpa_printf(MSG_DEBUG, "WPS: Testing - force WPS "
333 (wps_version_number & 0xf0) >> 4,
334 wps_version_number & 0x0f);
336 } else if (os_strcasecmp(cmd, "wps_testing_dummy_cred") == 0) {
337 wps_testing_dummy_cred = atoi(value);
338 wpa_printf(MSG_DEBUG, "WPS: Testing - dummy_cred=%d",
339 wps_testing_dummy_cred);
340 } else if (os_strcasecmp(cmd, "wps_corrupt_pkhash") == 0) {
341 wps_corrupt_pkhash = atoi(value);
342 wpa_printf(MSG_DEBUG, "WPS: Testing - wps_corrupt_pkhash=%d",
344 #endif /* CONFIG_WPS_TESTING */
345 } else if (os_strcasecmp(cmd, "ampdu") == 0) {
346 if (wpa_drv_ampdu(wpa_s, atoi(value)) < 0)
349 #ifdef CONFIG_TDLS_TESTING
350 } else if (os_strcasecmp(cmd, "tdls_testing") == 0) {
351 extern unsigned int tdls_testing;
352 tdls_testing = strtol(value, NULL, 0);
353 wpa_printf(MSG_DEBUG, "TDLS: tdls_testing=0x%x", tdls_testing);
354 #endif /* CONFIG_TDLS_TESTING */
355 } else if (os_strcasecmp(cmd, "tdls_disabled") == 0) {
356 int disabled = atoi(value);
357 wpa_printf(MSG_DEBUG, "TDLS: tdls_disabled=%d", disabled);
359 if (wpa_drv_tdls_oper(wpa_s, TDLS_DISABLE, NULL) < 0)
361 } else if (wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL) < 0)
363 wpa_tdls_enable(wpa_s->wpa, !disabled);
364 #endif /* CONFIG_TDLS */
365 } else if (os_strcasecmp(cmd, "pno") == 0) {
366 ret = wpas_ctrl_pno(wpa_s, value);
367 } else if (os_strcasecmp(cmd, "radio_disabled") == 0) {
368 int disabled = atoi(value);
369 if (wpa_drv_radio_disable(wpa_s, disabled) < 0)
372 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
373 } else if (os_strcasecmp(cmd, "uapsd") == 0) {
374 if (os_strcmp(value, "disable") == 0)
375 wpa_s->set_sta_uapsd = 0;
379 /* format: BE,BK,VI,VO;max SP Length */
381 pos = os_strchr(value, ',');
386 pos = os_strchr(pos, ',');
391 pos = os_strchr(pos, ',');
396 /* ignore max SP Length for now */
398 wpa_s->set_sta_uapsd = 1;
399 wpa_s->sta_uapsd = 0;
401 wpa_s->sta_uapsd |= BIT(0);
403 wpa_s->sta_uapsd |= BIT(1);
405 wpa_s->sta_uapsd |= BIT(2);
407 wpa_s->sta_uapsd |= BIT(3);
409 } else if (os_strcasecmp(cmd, "ps") == 0) {
410 ret = wpa_drv_set_p2p_powersave(wpa_s, atoi(value), -1, -1);
411 #ifdef CONFIG_WIFI_DISPLAY
412 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
413 int enabled = !!atoi(value);
414 if (enabled && !wpa_s->global->p2p)
417 wifi_display_enable(wpa_s->global, enabled);
418 #endif /* CONFIG_WIFI_DISPLAY */
419 } else if (os_strcasecmp(cmd, "bssid_filter") == 0) {
420 ret = set_bssid_filter(wpa_s, value);
421 } else if (os_strcasecmp(cmd, "disallow_aps") == 0) {
422 ret = set_disallow_aps(wpa_s, value);
423 } else if (os_strcasecmp(cmd, "no_keep_alive") == 0) {
424 wpa_s->no_keep_alive = !!atoi(value);
425 #ifdef CONFIG_TESTING_OPTIONS
426 } else if (os_strcasecmp(cmd, "ext_mgmt_frame_handling") == 0) {
427 wpa_s->ext_mgmt_frame_handling = !!atoi(value);
428 } else if (os_strcasecmp(cmd, "ext_eapol_frame_io") == 0) {
429 wpa_s->ext_eapol_frame_io = !!atoi(value);
431 if (wpa_s->ap_iface) {
432 wpa_s->ap_iface->bss[0]->ext_eapol_frame_io =
433 wpa_s->ext_eapol_frame_io;
435 #endif /* CONFIG_AP */
436 } else if (os_strcasecmp(cmd, "extra_roc_dur") == 0) {
437 wpa_s->extra_roc_dur = atoi(value);
438 #endif /* CONFIG_TESTING_OPTIONS */
439 #ifndef CONFIG_NO_CONFIG_BLOBS
440 } else if (os_strcmp(cmd, "blob") == 0) {
441 ret = wpas_ctrl_set_blob(wpa_s, value);
442 #endif /* CONFIG_NO_CONFIG_BLOBS */
445 ret = wpa_config_process_global(wpa_s->conf, cmd, -1);
447 wpa_supplicant_update_config(wpa_s);
454 static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s,
455 char *cmd, char *buf, size_t buflen)
459 wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd);
461 if (os_strcmp(cmd, "version") == 0) {
462 res = os_snprintf(buf, buflen, "%s", VERSION_STR);
463 } else if (os_strcasecmp(cmd, "country") == 0) {
464 if (wpa_s->conf->country[0] && wpa_s->conf->country[1])
465 res = os_snprintf(buf, buflen, "%c%c",
466 wpa_s->conf->country[0],
467 wpa_s->conf->country[1]);
468 #ifdef CONFIG_WIFI_DISPLAY
469 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
471 if (wpa_s->global->p2p == NULL ||
472 wpa_s->global->p2p_disabled)
475 enabled = wpa_s->global->wifi_display;
476 res = os_snprintf(buf, buflen, "%d", enabled);
477 if (res < 0 || (unsigned int) res >= buflen)
480 #endif /* CONFIG_WIFI_DISPLAY */
481 #ifdef CONFIG_TESTING_GET_GTK
482 } else if (os_strcmp(cmd, "gtk") == 0) {
483 if (wpa_s->last_gtk_len == 0)
485 res = wpa_snprintf_hex(buf, buflen, wpa_s->last_gtk,
486 wpa_s->last_gtk_len);
488 #endif /* CONFIG_TESTING_GET_GTK */
491 if (res < 0 || (unsigned int) res >= buflen)
497 #ifdef IEEE8021X_EAPOL
498 static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s,
502 struct wpa_ssid *ssid = wpa_s->current_ssid;
504 if (hwaddr_aton(addr, bssid)) {
505 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address "
510 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid));
511 rsn_preauth_deinit(wpa_s->wpa);
512 if (rsn_preauth_init(wpa_s->wpa, bssid, ssid ? &ssid->eap : NULL))
517 #endif /* IEEE8021X_EAPOL */
520 #ifdef CONFIG_PEERKEY
521 /* MLME-STKSTART.request(peer) */
522 static int wpa_supplicant_ctrl_iface_stkstart(
523 struct wpa_supplicant *wpa_s, char *addr)
527 if (hwaddr_aton(addr, peer)) {
528 wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART: invalid "
529 "address '%s'", addr);
533 wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART " MACSTR,
536 return wpa_sm_stkstart(wpa_s->wpa, peer);
538 #endif /* CONFIG_PEERKEY */
543 static int wpa_supplicant_ctrl_iface_tdls_discover(
544 struct wpa_supplicant *wpa_s, char *addr)
549 if (hwaddr_aton(addr, peer)) {
550 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER: invalid "
551 "address '%s'", addr);
555 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER " MACSTR,
558 if (wpa_tdls_is_external_setup(wpa_s->wpa))
559 ret = wpa_tdls_send_discovery_request(wpa_s->wpa, peer);
561 ret = wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer);
567 static int wpa_supplicant_ctrl_iface_tdls_setup(
568 struct wpa_supplicant *wpa_s, char *addr)
573 if (hwaddr_aton(addr, peer)) {
574 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP: invalid "
575 "address '%s'", addr);
579 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP " MACSTR,
582 if ((wpa_s->conf->tdls_external_control) &&
583 wpa_tdls_is_external_setup(wpa_s->wpa))
584 return wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
586 wpa_tdls_remove(wpa_s->wpa, peer);
588 if (wpa_tdls_is_external_setup(wpa_s->wpa))
589 ret = wpa_tdls_start(wpa_s->wpa, peer);
591 ret = wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
597 static int wpa_supplicant_ctrl_iface_tdls_teardown(
598 struct wpa_supplicant *wpa_s, char *addr)
603 if (os_strcmp(addr, "*") == 0) {
604 /* remove everyone */
605 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN *");
606 wpa_tdls_teardown_peers(wpa_s->wpa);
610 if (hwaddr_aton(addr, peer)) {
611 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN: invalid "
612 "address '%s'", addr);
616 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN " MACSTR,
619 if ((wpa_s->conf->tdls_external_control) &&
620 wpa_tdls_is_external_setup(wpa_s->wpa))
621 return wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
623 if (wpa_tdls_is_external_setup(wpa_s->wpa))
624 ret = wpa_tdls_teardown_link(
626 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED);
628 ret = wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
634 static int ctrl_iface_get_capability_tdls(
635 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
639 ret = os_snprintf(buf, buflen, "%s\n",
640 wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT ?
642 WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP ?
643 "EXTERNAL" : "INTERNAL") : "UNSUPPORTED");
644 if (ret < 0 || (size_t) ret > buflen)
649 #endif /* CONFIG_TDLS */
652 #ifdef CONFIG_IEEE80211R
653 static int wpa_supplicant_ctrl_iface_ft_ds(
654 struct wpa_supplicant *wpa_s, char *addr)
656 u8 target_ap[ETH_ALEN];
660 if (hwaddr_aton(addr, target_ap)) {
661 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid "
662 "address '%s'", addr);
666 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap));
668 bss = wpa_bss_get_bssid(wpa_s, target_ap);
670 mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN);
674 return wpa_ft_start_over_ds(wpa_s->wpa, target_ap, mdie);
676 #endif /* CONFIG_IEEE80211R */
680 static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s,
683 u8 bssid[ETH_ALEN], *_bssid = bssid;
685 u8 p2p_dev_addr[ETH_ALEN];
686 #endif /* CONFIG_P2P */
688 u8 *_p2p_dev_addr = NULL;
689 #endif /* CONFIG_AP */
691 if (cmd == NULL || os_strcmp(cmd, "any") == 0) {
694 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
695 if (hwaddr_aton(cmd + 13, p2p_dev_addr)) {
696 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid "
697 "P2P Device Address '%s'",
701 _p2p_dev_addr = p2p_dev_addr;
702 #endif /* CONFIG_P2P */
703 } else if (hwaddr_aton(cmd, bssid)) {
704 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
711 return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid, _p2p_dev_addr);
712 #endif /* CONFIG_AP */
714 return wpas_wps_start_pbc(wpa_s, _bssid, 0);
718 static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s,
719 char *cmd, char *buf,
722 u8 bssid[ETH_ALEN], *_bssid = bssid;
726 pin = os_strchr(cmd, ' ');
730 if (os_strcmp(cmd, "any") == 0)
732 else if (os_strcmp(cmd, "get") == 0) {
733 ret = wps_generate_pin();
735 } else if (hwaddr_aton(cmd, bssid)) {
736 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
742 if (wpa_s->ap_iface) {
747 pos = os_strchr(pin, ' ');
754 return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin,
755 buf, buflen, timeout);
757 #endif /* CONFIG_AP */
760 ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0,
764 ret = os_snprintf(buf, buflen, "%s", pin);
765 if (ret < 0 || (size_t) ret >= buflen)
770 ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0, DEV_PW_DEFAULT);
775 /* Return the generated PIN */
776 ret = os_snprintf(buf, buflen, "%08d", ret);
777 if (ret < 0 || (size_t) ret >= buflen)
783 static int wpa_supplicant_ctrl_iface_wps_check_pin(
784 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
791 wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN",
792 (u8 *) cmd, os_strlen(cmd));
793 for (pos = cmd, len = 0; *pos != '\0'; pos++) {
794 if (*pos < '0' || *pos > '9')
798 wpa_printf(MSG_DEBUG, "WPS: Too long PIN");
802 if (len != 4 && len != 8) {
803 wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len);
809 unsigned int pin_val;
811 if (!wps_pin_valid(pin_val)) {
812 wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit");
813 ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n");
814 if (ret < 0 || (size_t) ret >= buflen)
820 ret = os_snprintf(buf, buflen, "%s", pin);
821 if (ret < 0 || (size_t) ret >= buflen)
828 #ifdef CONFIG_WPS_NFC
830 static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant *wpa_s,
833 u8 bssid[ETH_ALEN], *_bssid = bssid;
835 if (cmd == NULL || cmd[0] == '\0')
837 else if (hwaddr_aton(cmd, bssid))
840 return wpas_wps_start_nfc(wpa_s, NULL, _bssid, NULL, 0, 0, NULL, NULL,
845 static int wpa_supplicant_ctrl_iface_wps_nfc_config_token(
846 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
853 pos = os_strchr(cmd, ' ');
856 if (os_strcmp(cmd, "WPS") == 0)
858 else if (os_strcmp(cmd, "NDEF") == 0)
863 buf = wpas_wps_nfc_config_token(wpa_s, ndef, pos);
867 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
878 static int wpa_supplicant_ctrl_iface_wps_nfc_token(
879 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
885 if (os_strcmp(cmd, "WPS") == 0)
887 else if (os_strcmp(cmd, "NDEF") == 0)
892 buf = wpas_wps_nfc_token(wpa_s, ndef);
896 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
907 static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
908 struct wpa_supplicant *wpa_s, char *pos)
916 freq = strstr(pos, " freq=");
920 forced_freq = atoi(freq);
923 len = os_strlen(pos);
928 buf = wpabuf_alloc(len);
931 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
936 ret = wpas_wps_nfc_tag_read(wpa_s, buf, forced_freq);
943 static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant *wpa_s,
944 char *reply, size_t max_len,
950 buf = wpas_wps_nfc_handover_req(wpa_s, ndef);
954 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
966 static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant *wpa_s,
967 char *reply, size_t max_len,
973 buf = wpas_p2p_nfc_handover_req(wpa_s, ndef);
975 wpa_printf(MSG_DEBUG, "P2P: Could not generate NFC handover request");
979 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
988 #endif /* CONFIG_P2P */
991 static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant *wpa_s,
992 char *cmd, char *reply,
998 pos = os_strchr(cmd, ' ');
1003 if (os_strcmp(cmd, "WPS") == 0)
1005 else if (os_strcmp(cmd, "NDEF") == 0)
1010 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
1013 return wpas_ctrl_nfc_get_handover_req_wps(
1014 wpa_s, reply, max_len, ndef);
1018 if (os_strcmp(pos, "P2P-CR") == 0) {
1019 return wpas_ctrl_nfc_get_handover_req_p2p(
1020 wpa_s, reply, max_len, ndef);
1022 #endif /* CONFIG_P2P */
1028 static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant *wpa_s,
1029 char *reply, size_t max_len,
1030 int ndef, int cr, char *uuid)
1035 buf = wpas_wps_nfc_handover_sel(wpa_s, ndef, cr, uuid);
1039 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1041 reply[res++] = '\n';
1051 static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant *wpa_s,
1052 char *reply, size_t max_len,
1058 buf = wpas_p2p_nfc_handover_sel(wpa_s, ndef, tag);
1062 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1064 reply[res++] = '\n';
1071 #endif /* CONFIG_P2P */
1074 static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant *wpa_s,
1075 char *cmd, char *reply,
1081 pos = os_strchr(cmd, ' ');
1086 if (os_strcmp(cmd, "WPS") == 0)
1088 else if (os_strcmp(cmd, "NDEF") == 0)
1093 pos2 = os_strchr(pos, ' ');
1096 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
1099 return wpas_ctrl_nfc_get_handover_sel_wps(
1100 wpa_s, reply, max_len, ndef,
1101 os_strcmp(pos, "WPS-CR") == 0, pos2);
1105 if (os_strcmp(pos, "P2P-CR") == 0) {
1106 return wpas_ctrl_nfc_get_handover_sel_p2p(
1107 wpa_s, reply, max_len, ndef, 0);
1110 if (os_strcmp(pos, "P2P-CR-TAG") == 0) {
1111 return wpas_ctrl_nfc_get_handover_sel_p2p(
1112 wpa_s, reply, max_len, ndef, 1);
1114 #endif /* CONFIG_P2P */
1120 static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant *wpa_s,
1124 struct wpabuf *req, *sel;
1126 char *pos, *role, *type, *pos2;
1129 int forced_freq = 0;
1131 freq = strstr(cmd, " freq=");
1135 forced_freq = atoi(freq);
1137 #endif /* CONFIG_P2P */
1140 pos = os_strchr(role, ' ');
1142 wpa_printf(MSG_DEBUG, "NFC: Missing type in handover report");
1148 pos = os_strchr(type, ' ');
1150 wpa_printf(MSG_DEBUG, "NFC: Missing request message in handover report");
1155 pos2 = os_strchr(pos, ' ');
1157 wpa_printf(MSG_DEBUG, "NFC: Missing select message in handover report");
1162 len = os_strlen(pos);
1164 wpa_printf(MSG_DEBUG, "NFC: Invalid request message length in handover report");
1169 req = wpabuf_alloc(len);
1171 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for request message");
1174 if (hexstr2bin(pos, wpabuf_put(req, len), len) < 0) {
1175 wpa_printf(MSG_DEBUG, "NFC: Invalid request message hexdump in handover report");
1180 len = os_strlen(pos2);
1182 wpa_printf(MSG_DEBUG, "NFC: Invalid select message length in handover report");
1188 sel = wpabuf_alloc(len);
1190 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for select message");
1194 if (hexstr2bin(pos2, wpabuf_put(sel, len), len) < 0) {
1195 wpa_printf(MSG_DEBUG, "NFC: Invalid select message hexdump in handover report");
1201 wpa_printf(MSG_DEBUG, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d",
1202 role, type, (int) wpabuf_len(req), (int) wpabuf_len(sel));
1204 if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "WPS") == 0) {
1205 ret = wpas_wps_nfc_report_handover(wpa_s, req, sel);
1207 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "WPS") == 0)
1209 ret = wpas_ap_wps_nfc_report_handover(wpa_s, req, sel);
1211 ret = wpas_er_wps_nfc_report_handover(wpa_s, req, sel);
1212 #endif /* CONFIG_AP */
1214 } else if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "P2P") == 0)
1216 ret = wpas_p2p_nfc_report_handover(wpa_s, 1, req, sel, 0);
1217 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "P2P") == 0)
1219 ret = wpas_p2p_nfc_report_handover(wpa_s, 0, req, sel,
1221 #endif /* CONFIG_P2P */
1223 wpa_printf(MSG_DEBUG, "NFC: Unsupported connection handover "
1224 "reported: role=%s type=%s", role, type);
1231 wpa_printf(MSG_DEBUG, "NFC: Failed to process reported handover messages");
1236 #endif /* CONFIG_WPS_NFC */
1239 static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s,
1248 struct wps_new_ap_settings ap;
1250 pin = os_strchr(cmd, ' ');
1255 if (hwaddr_aton(cmd, bssid)) {
1256 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
1261 new_ssid = os_strchr(pin, ' ');
1262 if (new_ssid == NULL)
1263 return wpas_wps_start_reg(wpa_s, bssid, pin, NULL);
1266 new_auth = os_strchr(new_ssid, ' ');
1267 if (new_auth == NULL)
1271 new_encr = os_strchr(new_auth, ' ');
1272 if (new_encr == NULL)
1276 new_key = os_strchr(new_encr, ' ');
1277 if (new_key == NULL)
1281 os_memset(&ap, 0, sizeof(ap));
1282 ap.ssid_hex = new_ssid;
1285 ap.key_hex = new_key;
1286 return wpas_wps_start_reg(wpa_s, bssid, pin, &ap);
1291 static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant *wpa_s,
1292 char *cmd, char *buf,
1297 const char *pin_txt;
1299 if (!wpa_s->ap_iface)
1302 pos = os_strchr(cmd, ' ');
1306 if (os_strcmp(cmd, "disable") == 0) {
1307 wpas_wps_ap_pin_disable(wpa_s);
1308 return os_snprintf(buf, buflen, "OK\n");
1311 if (os_strcmp(cmd, "random") == 0) {
1313 timeout = atoi(pos);
1314 pin_txt = wpas_wps_ap_pin_random(wpa_s, timeout);
1315 if (pin_txt == NULL)
1317 return os_snprintf(buf, buflen, "%s", pin_txt);
1320 if (os_strcmp(cmd, "get") == 0) {
1321 pin_txt = wpas_wps_ap_pin_get(wpa_s);
1322 if (pin_txt == NULL)
1324 return os_snprintf(buf, buflen, "%s", pin_txt);
1327 if (os_strcmp(cmd, "set") == 0) {
1332 pos = os_strchr(pos, ' ');
1335 timeout = atoi(pos);
1337 if (os_strlen(pin) > buflen)
1339 if (wpas_wps_ap_pin_set(wpa_s, pin, timeout) < 0)
1341 return os_snprintf(buf, buflen, "%s", pin);
1346 #endif /* CONFIG_AP */
1349 #ifdef CONFIG_WPS_ER
1350 static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant *wpa_s,
1353 char *uuid = cmd, *pin, *pos;
1354 u8 addr_buf[ETH_ALEN], *addr = NULL;
1355 pin = os_strchr(uuid, ' ');
1359 pos = os_strchr(pin, ' ');
1362 if (hwaddr_aton(pos, addr_buf) == 0)
1365 return wpas_wps_er_add_pin(wpa_s, addr, uuid, pin);
1369 static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant *wpa_s,
1372 char *uuid = cmd, *pin;
1373 pin = os_strchr(uuid, ' ');
1377 return wpas_wps_er_learn(wpa_s, uuid, pin);
1381 static int wpa_supplicant_ctrl_iface_wps_er_set_config(
1382 struct wpa_supplicant *wpa_s, char *cmd)
1384 char *uuid = cmd, *id;
1385 id = os_strchr(uuid, ' ');
1389 return wpas_wps_er_set_config(wpa_s, uuid, atoi(id));
1393 static int wpa_supplicant_ctrl_iface_wps_er_config(
1394 struct wpa_supplicant *wpa_s, char *cmd)
1401 struct wps_new_ap_settings ap;
1403 pin = os_strchr(cmd, ' ');
1408 new_ssid = os_strchr(pin, ' ');
1409 if (new_ssid == NULL)
1413 new_auth = os_strchr(new_ssid, ' ');
1414 if (new_auth == NULL)
1418 new_encr = os_strchr(new_auth, ' ');
1419 if (new_encr == NULL)
1423 new_key = os_strchr(new_encr, ' ');
1424 if (new_key == NULL)
1428 os_memset(&ap, 0, sizeof(ap));
1429 ap.ssid_hex = new_ssid;
1432 ap.key_hex = new_key;
1433 return wpas_wps_er_config(wpa_s, cmd, pin, &ap);
1437 #ifdef CONFIG_WPS_NFC
1438 static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
1439 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1446 uuid = os_strchr(cmd, ' ');
1451 if (os_strcmp(cmd, "WPS") == 0)
1453 else if (os_strcmp(cmd, "NDEF") == 0)
1458 buf = wpas_wps_er_nfc_config_token(wpa_s, ndef, uuid);
1462 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1464 reply[res++] = '\n';
1471 #endif /* CONFIG_WPS_NFC */
1472 #endif /* CONFIG_WPS_ER */
1474 #endif /* CONFIG_WPS */
1477 #ifdef CONFIG_IBSS_RSN
1478 static int wpa_supplicant_ctrl_iface_ibss_rsn(
1479 struct wpa_supplicant *wpa_s, char *addr)
1483 if (hwaddr_aton(addr, peer)) {
1484 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN: invalid "
1485 "address '%s'", addr);
1489 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN " MACSTR,
1492 return ibss_rsn_start(wpa_s->ibss_rsn, peer);
1494 #endif /* CONFIG_IBSS_RSN */
1497 static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s,
1500 #ifdef IEEE8021X_EAPOL
1503 struct wpa_ssid *ssid;
1505 pos = os_strchr(rsp, '-');
1510 pos = os_strchr(pos, ':');
1515 wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id);
1516 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
1517 (u8 *) pos, os_strlen(pos));
1519 ssid = wpa_config_get_network(wpa_s->conf, id);
1521 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
1526 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s, ssid, rsp,
1528 #else /* IEEE8021X_EAPOL */
1529 wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included");
1531 #endif /* IEEE8021X_EAPOL */
1535 static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
1537 char *buf, size_t buflen)
1539 char *pos, *end, tmp[30];
1540 int res, verbose, wps, ret;
1543 #endif /* CONFIG_HS20 */
1545 if (os_strcmp(params, "-DRIVER") == 0)
1546 return wpa_drv_status(wpa_s, buf, buflen);
1547 verbose = os_strcmp(params, "-VERBOSE") == 0;
1548 wps = os_strcmp(params, "-WPS") == 0;
1551 if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
1552 struct wpa_ssid *ssid = wpa_s->current_ssid;
1553 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
1554 MAC2STR(wpa_s->bssid));
1555 if (ret < 0 || ret >= end - pos)
1558 ret = os_snprintf(pos, end - pos, "freq=%u\n",
1560 if (ret < 0 || ret >= end - pos)
1564 u8 *_ssid = ssid->ssid;
1565 size_t ssid_len = ssid->ssid_len;
1566 u8 ssid_buf[MAX_SSID_LEN];
1567 if (ssid_len == 0) {
1568 int _res = wpa_drv_get_ssid(wpa_s, ssid_buf);
1575 ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n",
1576 wpa_ssid_txt(_ssid, ssid_len),
1578 if (ret < 0 || ret >= end - pos)
1582 if (wps && ssid->passphrase &&
1583 wpa_key_mgmt_wpa_psk(ssid->key_mgmt) &&
1584 (ssid->mode == WPAS_MODE_AP ||
1585 ssid->mode == WPAS_MODE_P2P_GO)) {
1586 ret = os_snprintf(pos, end - pos,
1589 if (ret < 0 || ret >= end - pos)
1594 ret = os_snprintf(pos, end - pos,
1597 if (ret < 0 || ret >= end - pos)
1602 switch (ssid->mode) {
1603 case WPAS_MODE_INFRA:
1604 ret = os_snprintf(pos, end - pos,
1607 case WPAS_MODE_IBSS:
1608 ret = os_snprintf(pos, end - pos,
1612 ret = os_snprintf(pos, end - pos,
1615 case WPAS_MODE_P2P_GO:
1616 ret = os_snprintf(pos, end - pos,
1619 case WPAS_MODE_P2P_GROUP_FORMATION:
1620 ret = os_snprintf(pos, end - pos,
1621 "mode=P2P GO - group "
1628 if (ret < 0 || ret >= end - pos)
1634 if (wpa_s->ap_iface) {
1635 pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos,
1639 #endif /* CONFIG_AP */
1640 pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose);
1643 if (wpa_s->wpa_state >= WPA_ASSOCIATED &&
1646 #endif /* CONFIG_AP */
1647 wpa_s->sme.sae.state == SAE_ACCEPTED) {
1648 ret = os_snprintf(pos, end - pos, "sae_group=%d\n",
1649 wpa_s->sme.sae.group);
1650 if (ret < 0 || ret >= end - pos)
1654 #endif /* CONFIG_SAE */
1655 ret = os_snprintf(pos, end - pos, "wpa_state=%s\n",
1656 wpa_supplicant_state_txt(wpa_s->wpa_state));
1657 if (ret < 0 || ret >= end - pos)
1662 l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) {
1663 ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp);
1664 if (ret < 0 || ret >= end - pos)
1670 if (wpa_s->global->p2p) {
1671 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
1672 "\n", MAC2STR(wpa_s->global->p2p_dev_addr));
1673 if (ret < 0 || ret >= end - pos)
1677 #endif /* CONFIG_P2P */
1679 ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n",
1680 MAC2STR(wpa_s->own_addr));
1681 if (ret < 0 || ret >= end - pos)
1686 if (wpa_s->current_bss &&
1687 (hs20 = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1688 HS20_IE_VENDOR_TYPE)) &&
1689 wpa_s->wpa_proto == WPA_PROTO_RSN &&
1690 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1693 u8 rel_num = (hs20[6] & 0xf0) >> 4;
1694 release = rel_num + 1;
1696 ret = os_snprintf(pos, end - pos, "hs20=%d\n", release);
1697 if (ret < 0 || ret >= end - pos)
1702 if (wpa_s->current_ssid) {
1703 struct wpa_cred *cred;
1706 for (cred = wpa_s->conf->cred; cred; cred = cred->next) {
1709 if (wpa_s->current_ssid->parent_cred != cred)
1712 if (cred->provisioning_sp) {
1713 ret = os_snprintf(pos, end - pos,
1714 "provisioning_sp=%s\n",
1715 cred->provisioning_sp);
1716 if (ret < 0 || ret >= end - pos)
1725 if (wpa_s->current_bss && wpa_s->current_bss->anqp) {
1726 struct wpabuf *names =
1727 wpa_s->current_bss->anqp->domain_name;
1728 for (i = 0; names && i < cred->num_domain; i++)
1730 if (domain_name_list_contains(
1731 names, cred->domain[i], 1))
1734 if (i == cred->num_domain)
1735 i = 0; /* show first entry by default */
1737 ret = os_snprintf(pos, end - pos, "home_sp=%s\n",
1739 if (ret < 0 || ret >= end - pos)
1744 if (wpa_s->current_bss == NULL ||
1745 wpa_s->current_bss->anqp == NULL)
1748 res = interworking_home_sp_cred(
1750 wpa_s->current_bss->anqp->domain_name);
1758 ret = os_snprintf(pos, end - pos, "sp_type=%s\n", type);
1759 if (ret < 0 || ret >= end - pos)
1766 #endif /* CONFIG_HS20 */
1768 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
1769 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
1770 res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos,
1776 res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose);
1783 uuid_bin2str(wpa_s->wps->uuid, uuid_str, sizeof(uuid_str));
1784 ret = os_snprintf(pos, end - pos, "uuid=%s\n", uuid_str);
1785 if (ret < 0 || ret >= end - pos)
1789 #endif /* CONFIG_WPS */
1793 * Allow using the STATUS command with default behavior, say for debug,
1794 * i.e., don't generate a "fake" CONNECTION and SUPPLICANT_STATE_CHANGE
1795 * events with STATUS-NO_EVENTS.
1797 if (os_strcmp(params, "-NO_EVENTS")) {
1798 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_STATE_CHANGE
1799 "id=%d state=%d BSSID=" MACSTR " SSID=%s",
1800 wpa_s->current_ssid ? wpa_s->current_ssid->id : -1,
1802 MAC2STR(wpa_s->bssid),
1803 wpa_s->current_ssid && wpa_s->current_ssid->ssid ?
1804 wpa_ssid_txt(wpa_s->current_ssid->ssid,
1805 wpa_s->current_ssid->ssid_len) : "");
1806 if (wpa_s->wpa_state == WPA_COMPLETED) {
1807 struct wpa_ssid *ssid = wpa_s->current_ssid;
1808 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_CONNECTED
1809 "- connection to " MACSTR
1810 " completed %s [id=%d id_str=%s]",
1811 MAC2STR(wpa_s->bssid), "(auth)",
1812 ssid ? ssid->id : -1,
1813 ssid && ssid->id_str ? ssid->id_str : "");
1816 #endif /* ANDROID */
1822 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s,
1827 struct wpa_ssid *ssid;
1830 /* cmd: "<network id> <BSSID>" */
1831 pos = os_strchr(cmd, ' ');
1836 wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos);
1837 if (hwaddr_aton(pos, bssid)) {
1838 wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos);
1842 ssid = wpa_config_get_network(wpa_s->conf, id);
1844 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
1849 os_memcpy(ssid->bssid, bssid, ETH_ALEN);
1850 ssid->bssid_set = !is_zero_ether_addr(bssid);
1856 static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant *wpa_s,
1857 char *cmd, char *buf,
1861 struct wpa_blacklist *e;
1865 /* cmd: "BLACKLIST [<BSSID>]" */
1869 e = wpa_s->blacklist;
1871 ret = os_snprintf(pos, end - pos, MACSTR "\n",
1873 if (ret < 0 || ret >= end - pos)
1882 if (os_strncmp(cmd, "clear", 5) == 0) {
1883 wpa_blacklist_clear(wpa_s);
1884 os_memcpy(buf, "OK\n", 3);
1888 wpa_printf(MSG_DEBUG, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd);
1889 if (hwaddr_aton(cmd, bssid)) {
1890 wpa_printf(MSG_DEBUG, "CTRL_IFACE: invalid BSSID '%s'", cmd);
1895 * Add the BSSID twice, so its count will be 2, causing it to be
1896 * skipped when processing scan results.
1898 ret = wpa_blacklist_add(wpa_s, bssid);
1901 ret = wpa_blacklist_add(wpa_s, bssid);
1904 os_memcpy(buf, "OK\n", 3);
1909 static const char * debug_level_str(int level)
1930 static int str_to_debug_level(const char *s)
1932 if (os_strcasecmp(s, "EXCESSIVE") == 0)
1933 return MSG_EXCESSIVE;
1934 if (os_strcasecmp(s, "MSGDUMP") == 0)
1936 if (os_strcasecmp(s, "DEBUG") == 0)
1938 if (os_strcasecmp(s, "INFO") == 0)
1940 if (os_strcasecmp(s, "WARNING") == 0)
1942 if (os_strcasecmp(s, "ERROR") == 0)
1948 static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant *wpa_s,
1949 char *cmd, char *buf,
1952 char *pos, *end, *stamp;
1959 /* cmd: "LOG_LEVEL [<level>]" */
1963 ret = os_snprintf(pos, end - pos, "Current level: %s\n"
1965 debug_level_str(wpa_debug_level),
1966 wpa_debug_timestamp);
1967 if (ret < 0 || ret >= end - pos)
1976 stamp = os_strchr(cmd, ' ');
1979 while (*stamp == ' ') {
1984 if (cmd && os_strlen(cmd)) {
1985 int level = str_to_debug_level(cmd);
1988 wpa_debug_level = level;
1991 if (stamp && os_strlen(stamp))
1992 wpa_debug_timestamp = atoi(stamp);
1994 os_memcpy(buf, "OK\n", 3);
1999 static int wpa_supplicant_ctrl_iface_list_networks(
2000 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
2003 struct wpa_ssid *ssid;
2008 ret = os_snprintf(pos, end - pos,
2009 "network id / ssid / bssid / flags\n");
2010 if (ret < 0 || ret >= end - pos)
2014 ssid = wpa_s->conf->ssid;
2016 ret = os_snprintf(pos, end - pos, "%d\t%s",
2018 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
2019 if (ret < 0 || ret >= end - pos)
2022 if (ssid->bssid_set) {
2023 ret = os_snprintf(pos, end - pos, "\t" MACSTR,
2024 MAC2STR(ssid->bssid));
2026 ret = os_snprintf(pos, end - pos, "\tany");
2028 if (ret < 0 || ret >= end - pos)
2031 ret = os_snprintf(pos, end - pos, "\t%s%s%s%s",
2032 ssid == wpa_s->current_ssid ?
2034 ssid->disabled ? "[DISABLED]" : "",
2035 ssid->disabled_until.sec ?
2036 "[TEMP-DISABLED]" : "",
2037 ssid->disabled == 2 ? "[P2P-PERSISTENT]" :
2039 if (ret < 0 || ret >= end - pos)
2042 ret = os_snprintf(pos, end - pos, "\n");
2043 if (ret < 0 || ret >= end - pos)
2054 static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher)
2057 ret = os_snprintf(pos, end - pos, "-");
2058 if (ret < 0 || ret >= end - pos)
2061 ret = wpa_write_ciphers(pos, end, cipher, "+");
2069 static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
2070 const u8 *ie, size_t ie_len)
2072 struct wpa_ie_data data;
2076 ret = os_snprintf(pos, end - pos, "[%s-", proto);
2077 if (ret < 0 || ret >= end - pos)
2081 if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) {
2082 ret = os_snprintf(pos, end - pos, "?]");
2083 if (ret < 0 || ret >= end - pos)
2090 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
2091 ret = os_snprintf(pos, end - pos, "%sEAP",
2092 pos == start ? "" : "+");
2093 if (ret < 0 || ret >= end - pos)
2097 if (data.key_mgmt & WPA_KEY_MGMT_PSK) {
2098 ret = os_snprintf(pos, end - pos, "%sPSK",
2099 pos == start ? "" : "+");
2100 if (ret < 0 || ret >= end - pos)
2104 if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
2105 ret = os_snprintf(pos, end - pos, "%sNone",
2106 pos == start ? "" : "+");
2107 if (ret < 0 || ret >= end - pos)
2111 if (data.key_mgmt & WPA_KEY_MGMT_SAE) {
2112 ret = os_snprintf(pos, end - pos, "%sSAE",
2113 pos == start ? "" : "+");
2114 if (ret < 0 || ret >= end - pos)
2118 #ifdef CONFIG_IEEE80211R
2119 if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
2120 ret = os_snprintf(pos, end - pos, "%sFT/EAP",
2121 pos == start ? "" : "+");
2122 if (ret < 0 || ret >= end - pos)
2126 if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) {
2127 ret = os_snprintf(pos, end - pos, "%sFT/PSK",
2128 pos == start ? "" : "+");
2129 if (ret < 0 || ret >= end - pos)
2133 if (data.key_mgmt & WPA_KEY_MGMT_FT_SAE) {
2134 ret = os_snprintf(pos, end - pos, "%sFT/SAE",
2135 pos == start ? "" : "+");
2136 if (ret < 0 || ret >= end - pos)
2140 #endif /* CONFIG_IEEE80211R */
2141 #ifdef CONFIG_IEEE80211W
2142 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
2143 ret = os_snprintf(pos, end - pos, "%sEAP-SHA256",
2144 pos == start ? "" : "+");
2145 if (ret < 0 || ret >= end - pos)
2149 if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
2150 ret = os_snprintf(pos, end - pos, "%sPSK-SHA256",
2151 pos == start ? "" : "+");
2152 if (ret < 0 || ret >= end - pos)
2156 #endif /* CONFIG_IEEE80211W */
2158 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B) {
2159 ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B",
2160 pos == start ? "" : "+");
2161 if (ret < 0 || ret >= end - pos)
2166 pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher);
2168 if (data.capabilities & WPA_CAPABILITY_PREAUTH) {
2169 ret = os_snprintf(pos, end - pos, "-preauth");
2170 if (ret < 0 || ret >= end - pos)
2175 ret = os_snprintf(pos, end - pos, "]");
2176 if (ret < 0 || ret >= end - pos)
2185 static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s,
2186 char *pos, char *end,
2187 struct wpabuf *wps_ie)
2194 if (wps_is_selected_pbc_registrar(wps_ie))
2196 else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0))
2198 else if (wps_is_selected_pin_registrar(wps_ie))
2203 ret = os_snprintf(pos, end - pos, "%s", txt);
2204 if (ret >= 0 && ret < end - pos)
2206 wpabuf_free(wps_ie);
2209 #endif /* CONFIG_WPS */
2212 static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s,
2213 char *pos, char *end,
2214 const struct wpa_bss *bss)
2217 struct wpabuf *wps_ie;
2218 wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
2219 return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie);
2220 #else /* CONFIG_WPS */
2222 #endif /* CONFIG_WPS */
2226 /* Format one result on one text line into a buffer. */
2227 static int wpa_supplicant_ctrl_iface_scan_result(
2228 struct wpa_supplicant *wpa_s,
2229 const struct wpa_bss *bss, char *buf, size_t buflen)
2233 const u8 *ie, *ie2, *p2p, *mesh;
2235 mesh = wpa_bss_get_ie(bss, WLAN_EID_MESH_ID);
2236 p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
2238 p2p = wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE);
2239 if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN &&
2240 os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) ==
2242 return 0; /* Do not show P2P listen discovery results here */
2247 ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t",
2248 MAC2STR(bss->bssid), bss->freq, bss->level);
2249 if (ret < 0 || ret >= end - pos)
2252 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
2254 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]);
2255 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
2257 pos = wpa_supplicant_ie_txt(pos, end, mesh ? "RSN" : "WPA2",
2260 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
2261 if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
2262 ret = os_snprintf(pos, end - pos, "[WEP]");
2263 if (ret < 0 || ret >= end - pos)
2268 ret = os_snprintf(pos, end - pos, "[MESH]");
2269 if (ret < 0 || ret >= end - pos)
2273 if (bss_is_dmg(bss)) {
2275 ret = os_snprintf(pos, end - pos, "[DMG]");
2276 if (ret < 0 || ret >= end - pos)
2279 switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
2280 case IEEE80211_CAP_DMG_IBSS:
2283 case IEEE80211_CAP_DMG_AP:
2286 case IEEE80211_CAP_DMG_PBSS:
2293 ret = os_snprintf(pos, end - pos, "%s", s);
2294 if (ret < 0 || ret >= end - pos)
2298 if (bss->caps & IEEE80211_CAP_IBSS) {
2299 ret = os_snprintf(pos, end - pos, "[IBSS]");
2300 if (ret < 0 || ret >= end - pos)
2304 if (bss->caps & IEEE80211_CAP_ESS) {
2305 ret = os_snprintf(pos, end - pos, "[ESS]");
2306 if (ret < 0 || ret >= end - pos)
2312 ret = os_snprintf(pos, end - pos, "[P2P]");
2313 if (ret < 0 || ret >= end - pos)
2318 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE) && ie2) {
2319 ret = os_snprintf(pos, end - pos, "[HS20]");
2320 if (ret < 0 || ret >= end - pos)
2324 #endif /* CONFIG_HS20 */
2326 ret = os_snprintf(pos, end - pos, "\t%s",
2327 wpa_ssid_txt(bss->ssid, bss->ssid_len));
2328 if (ret < 0 || ret >= end - pos)
2332 ret = os_snprintf(pos, end - pos, "\n");
2333 if (ret < 0 || ret >= end - pos)
2341 static int wpa_supplicant_ctrl_iface_scan_results(
2342 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
2345 struct wpa_bss *bss;
2350 ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / "
2352 if (ret < 0 || ret >= end - pos)
2356 dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
2357 ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos,
2359 if (ret < 0 || ret >= end - pos)
2368 static int wpa_supplicant_ctrl_iface_select_network(
2369 struct wpa_supplicant *wpa_s, char *cmd)
2372 struct wpa_ssid *ssid;
2375 /* cmd: "<network id>" or "any" */
2376 if (os_strncmp(cmd, "any", 3) == 0) {
2377 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any");
2381 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id);
2383 ssid = wpa_config_get_network(wpa_s->conf, id);
2385 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2386 "network id=%d", id);
2389 if (ssid->disabled == 2) {
2390 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2391 "SELECT_NETWORK with persistent P2P group");
2396 pos = os_strstr(cmd, " freq=");
2398 int *freqs = freq_range_to_channel_list(wpa_s, pos + 6);
2400 wpa_s->scan_req = MANUAL_SCAN_REQ;
2401 os_free(wpa_s->manual_scan_freqs);
2402 wpa_s->manual_scan_freqs = freqs;
2406 wpa_supplicant_select_network(wpa_s, ssid);
2412 static int wpa_supplicant_ctrl_iface_enable_network(
2413 struct wpa_supplicant *wpa_s, char *cmd)
2416 struct wpa_ssid *ssid;
2418 /* cmd: "<network id>" or "all" */
2419 if (os_strcmp(cmd, "all") == 0) {
2420 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all");
2424 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id);
2426 ssid = wpa_config_get_network(wpa_s->conf, id);
2428 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2429 "network id=%d", id);
2432 if (ssid->disabled == 2) {
2433 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2434 "ENABLE_NETWORK with persistent P2P group");
2438 if (os_strstr(cmd, " no-connect")) {
2443 wpa_supplicant_enable_network(wpa_s, ssid);
2449 static int wpa_supplicant_ctrl_iface_disable_network(
2450 struct wpa_supplicant *wpa_s, char *cmd)
2453 struct wpa_ssid *ssid;
2455 /* cmd: "<network id>" or "all" */
2456 if (os_strcmp(cmd, "all") == 0) {
2457 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all");
2461 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id);
2463 ssid = wpa_config_get_network(wpa_s->conf, id);
2465 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2466 "network id=%d", id);
2469 if (ssid->disabled == 2) {
2470 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2471 "DISABLE_NETWORK with persistent P2P "
2476 wpa_supplicant_disable_network(wpa_s, ssid);
2482 static int wpa_supplicant_ctrl_iface_add_network(
2483 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
2485 struct wpa_ssid *ssid;
2488 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK");
2490 ssid = wpa_config_add_network(wpa_s->conf);
2494 wpas_notify_network_added(wpa_s, ssid);
2497 wpa_config_set_network_defaults(ssid);
2499 ret = os_snprintf(buf, buflen, "%d\n", ssid->id);
2500 if (ret < 0 || (size_t) ret >= buflen)
2506 static int wpa_supplicant_ctrl_iface_remove_network(
2507 struct wpa_supplicant *wpa_s, char *cmd)
2510 struct wpa_ssid *ssid;
2513 /* cmd: "<network id>" or "all" */
2514 if (os_strcmp(cmd, "all") == 0) {
2515 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all");
2516 if (wpa_s->sched_scanning)
2517 wpa_supplicant_cancel_sched_scan(wpa_s);
2519 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2520 if (wpa_s->current_ssid) {
2522 wpa_s->sme.prev_bssid_set = 0;
2523 #endif /* CONFIG_SME */
2524 wpa_sm_set_config(wpa_s->wpa, NULL);
2525 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
2526 wpa_supplicant_deauthenticate(
2527 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2529 ssid = wpa_s->conf->ssid;
2531 struct wpa_ssid *remove_ssid = ssid;
2534 if (wpa_s->last_ssid == remove_ssid)
2535 wpa_s->last_ssid = NULL;
2536 wpas_notify_network_removed(wpa_s, remove_ssid);
2537 wpa_config_remove_network(wpa_s->conf, id);
2543 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id);
2545 ssid = wpa_config_get_network(wpa_s->conf, id);
2547 wpas_notify_network_removed(wpa_s, ssid);
2549 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2554 if (wpa_s->last_ssid == ssid)
2555 wpa_s->last_ssid = NULL;
2557 if (ssid == wpa_s->current_ssid || wpa_s->current_ssid == NULL) {
2559 wpa_s->sme.prev_bssid_set = 0;
2560 #endif /* CONFIG_SME */
2562 * Invalidate the EAP session cache if the current or
2563 * previously used network is removed.
2565 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2568 if (ssid == wpa_s->current_ssid) {
2569 wpa_sm_set_config(wpa_s->wpa, NULL);
2570 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
2572 wpa_supplicant_deauthenticate(wpa_s,
2573 WLAN_REASON_DEAUTH_LEAVING);
2576 was_disabled = ssid->disabled;
2578 if (wpa_config_remove_network(wpa_s->conf, id) < 0) {
2579 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Not able to remove the "
2580 "network id=%d", id);
2584 if (!was_disabled && wpa_s->sched_scanning) {
2585 wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to remove "
2586 "network from filters");
2587 wpa_supplicant_cancel_sched_scan(wpa_s);
2588 wpa_supplicant_req_scan(wpa_s, 0, 0);
2595 static int wpa_supplicant_ctrl_iface_update_network(
2596 struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
2597 char *name, char *value)
2599 if (wpa_config_set(ssid, name, value, 0) < 0) {
2600 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network "
2601 "variable '%s'", name);
2605 if (os_strcmp(name, "bssid") != 0 &&
2606 os_strcmp(name, "priority") != 0)
2607 wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
2609 if (wpa_s->current_ssid == ssid || wpa_s->current_ssid == NULL) {
2611 * Invalidate the EAP session cache if anything in the current
2612 * or previously used configuration changes.
2614 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2617 if ((os_strcmp(name, "psk") == 0 &&
2618 value[0] == '"' && ssid->ssid_len) ||
2619 (os_strcmp(name, "ssid") == 0 && ssid->passphrase))
2620 wpa_config_update_psk(ssid);
2621 else if (os_strcmp(name, "priority") == 0)
2622 wpa_config_update_prio_list(wpa_s->conf);
2623 else if (os_strcmp(name, "no_auto_peer") == 0)
2624 ssid->no_auto_peer = atoi(value);
2630 static int wpa_supplicant_ctrl_iface_set_network(
2631 struct wpa_supplicant *wpa_s, char *cmd)
2633 int id, ret, prev_bssid_set;
2634 struct wpa_ssid *ssid;
2636 u8 prev_bssid[ETH_ALEN];
2638 /* cmd: "<network id> <variable name> <value>" */
2639 name = os_strchr(cmd, ' ');
2644 value = os_strchr(name, ' ');
2650 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
2652 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
2653 (u8 *) value, os_strlen(value));
2655 ssid = wpa_config_get_network(wpa_s->conf, id);
2657 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2662 prev_bssid_set = ssid->bssid_set;
2663 os_memcpy(prev_bssid, ssid->bssid, ETH_ALEN);
2664 ret = wpa_supplicant_ctrl_iface_update_network(wpa_s, ssid, name,
2667 (ssid->bssid_set != prev_bssid_set ||
2668 os_memcmp(ssid->bssid, prev_bssid, ETH_ALEN) != 0))
2669 wpas_notify_network_bssid_set_changed(wpa_s, ssid);
2674 static int wpa_supplicant_ctrl_iface_get_network(
2675 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
2679 struct wpa_ssid *ssid;
2682 /* cmd: "<network id> <variable name>" */
2683 name = os_strchr(cmd, ' ');
2684 if (name == NULL || buflen == 0)
2689 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
2692 ssid = wpa_config_get_network(wpa_s->conf, id);
2694 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2699 value = wpa_config_get_no_key(ssid, name);
2700 if (value == NULL) {
2701 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
2702 "variable '%s'", name);
2706 res = os_strlcpy(buf, value, buflen);
2707 if (res >= buflen) {
2718 static int wpa_supplicant_ctrl_iface_dup_network(
2719 struct wpa_supplicant *wpa_s, char *cmd)
2721 struct wpa_ssid *ssid_s, *ssid_d;
2722 char *name, *id, *value;
2723 int id_s, id_d, ret;
2725 /* cmd: "<src network id> <dst network id> <variable name>" */
2726 id = os_strchr(cmd, ' ');
2731 name = os_strchr(id, ' ');
2738 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DUP_NETWORK id=%d -> %d name='%s'",
2741 ssid_s = wpa_config_get_network(wpa_s->conf, id_s);
2742 if (ssid_s == NULL) {
2743 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2744 "network id=%d", id_s);
2748 ssid_d = wpa_config_get_network(wpa_s->conf, id_d);
2749 if (ssid_d == NULL) {
2750 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2751 "network id=%d", id_s);
2755 value = wpa_config_get(ssid_s, name);
2756 if (value == NULL) {
2757 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
2758 "variable '%s'", name);
2762 ret = wpa_supplicant_ctrl_iface_update_network(wpa_s, ssid_d, name,
2771 static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant *wpa_s,
2772 char *buf, size_t buflen)
2775 struct wpa_cred *cred;
2780 ret = os_snprintf(pos, end - pos,
2781 "cred id / realm / username / domain / imsi\n");
2782 if (ret < 0 || ret >= end - pos)
2786 cred = wpa_s->conf->cred;
2788 ret = os_snprintf(pos, end - pos, "%d\t%s\t%s\t%s\t%s\n",
2789 cred->id, cred->realm ? cred->realm : "",
2790 cred->username ? cred->username : "",
2791 cred->domain ? cred->domain[0] : "",
2792 cred->imsi ? cred->imsi : "");
2793 if (ret < 0 || ret >= end - pos)
2804 static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant *wpa_s,
2805 char *buf, size_t buflen)
2807 struct wpa_cred *cred;
2810 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_CRED");
2812 cred = wpa_config_add_cred(wpa_s->conf);
2816 wpa_msg(wpa_s, MSG_INFO, CRED_ADDED "%d", cred->id);
2818 ret = os_snprintf(buf, buflen, "%d\n", cred->id);
2819 if (ret < 0 || (size_t) ret >= buflen)
2825 static int wpas_ctrl_remove_cred(struct wpa_supplicant *wpa_s,
2826 struct wpa_cred *cred)
2828 struct wpa_ssid *ssid;
2833 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred");
2838 if (wpa_config_remove_cred(wpa_s->conf, id) < 0) {
2839 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred");
2843 wpa_msg(wpa_s, MSG_INFO, CRED_REMOVED "%d", id);
2845 /* Remove any network entry created based on the removed credential */
2846 ssid = wpa_s->conf->ssid;
2848 if (ssid->parent_cred == cred) {
2849 wpa_printf(MSG_DEBUG, "Remove network id %d since it "
2850 "used the removed credential", ssid->id);
2851 os_snprintf(str, sizeof(str), "%d", ssid->id);
2853 wpa_supplicant_ctrl_iface_remove_network(wpa_s, str);
2862 static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s,
2866 struct wpa_cred *cred, *prev;
2868 /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or
2869 * "provisioning_sp=<FQDN> */
2870 if (os_strcmp(cmd, "all") == 0) {
2871 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED all");
2872 cred = wpa_s->conf->cred;
2876 wpas_ctrl_remove_cred(wpa_s, prev);
2881 if (os_strncmp(cmd, "sp_fqdn=", 8) == 0) {
2882 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
2884 cred = wpa_s->conf->cred;
2890 for (i = 0; i < prev->num_domain; i++) {
2891 if (os_strcmp(prev->domain[i], cmd + 8)
2894 wpas_ctrl_remove_cred(wpa_s, prev);
2902 if (os_strncmp(cmd, "provisioning_sp=", 16) == 0) {
2903 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'",
2905 cred = wpa_s->conf->cred;
2909 if (prev->provisioning_sp &&
2910 os_strcmp(prev->provisioning_sp, cmd + 16) == 0)
2911 wpas_ctrl_remove_cred(wpa_s, prev);
2917 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED id=%d", id);
2919 cred = wpa_config_get_cred(wpa_s->conf, id);
2920 return wpas_ctrl_remove_cred(wpa_s, cred);
2924 static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant *wpa_s,
2928 struct wpa_cred *cred;
2931 /* cmd: "<cred id> <variable name> <value>" */
2932 name = os_strchr(cmd, ' ');
2937 value = os_strchr(name, ' ');
2943 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_CRED id=%d name='%s'",
2945 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
2946 (u8 *) value, os_strlen(value));
2948 cred = wpa_config_get_cred(wpa_s->conf, id);
2950 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
2955 if (wpa_config_set_cred(cred, name, value, 0) < 0) {
2956 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set cred "
2957 "variable '%s'", name);
2961 wpa_msg(wpa_s, MSG_INFO, CRED_MODIFIED "%d %s", cred->id, name);
2967 static int wpa_supplicant_ctrl_iface_get_cred(struct wpa_supplicant *wpa_s,
2968 char *cmd, char *buf,
2973 struct wpa_cred *cred;
2976 /* cmd: "<cred id> <variable name>" */
2977 name = os_strchr(cmd, ' ');
2983 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CRED id=%d name='%s'",
2986 cred = wpa_config_get_cred(wpa_s->conf, id);
2988 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
2993 value = wpa_config_get_cred_no_key(cred, name);
2994 if (value == NULL) {
2995 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get cred variable '%s'",
3000 res = os_strlcpy(buf, value, buflen);
3001 if (res >= buflen) {
3012 #ifndef CONFIG_NO_CONFIG_WRITE
3013 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s)
3017 if (!wpa_s->conf->update_config) {
3018 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
3019 "to update configuration (update_config=0)");
3023 ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
3025 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to "
3026 "update configuration");
3028 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration"
3034 #endif /* CONFIG_NO_CONFIG_WRITE */
3037 struct cipher_info {
3043 static const struct cipher_info ciphers[] = {
3044 { WPA_DRIVER_CAPA_ENC_CCMP_256, "CCMP-256", 0 },
3045 { WPA_DRIVER_CAPA_ENC_GCMP_256, "GCMP-256", 0 },
3046 { WPA_DRIVER_CAPA_ENC_CCMP, "CCMP", 0 },
3047 { WPA_DRIVER_CAPA_ENC_GCMP, "GCMP", 0 },
3048 { WPA_DRIVER_CAPA_ENC_TKIP, "TKIP", 0 },
3049 { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE, "NONE", 0 },
3050 { WPA_DRIVER_CAPA_ENC_WEP104, "WEP104", 1 },
3051 { WPA_DRIVER_CAPA_ENC_WEP40, "WEP40", 1 }
3055 static int ctrl_iface_get_capability_pairwise(int res, char *strict,
3056 struct wpa_driver_capa *capa,
3057 char *buf, size_t buflen)
3070 len = os_strlcpy(buf, "CCMP TKIP NONE", buflen);
3076 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
3077 if (!ciphers[i].group_only && capa->enc & ciphers[i].capa) {
3078 ret = os_snprintf(pos, end - pos, "%s%s",
3079 pos == buf ? "" : " ",
3081 if (ret < 0 || ret >= end - pos)
3091 static int ctrl_iface_get_capability_group(int res, char *strict,
3092 struct wpa_driver_capa *capa,
3093 char *buf, size_t buflen)
3106 len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen);
3112 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
3113 if (capa->enc & ciphers[i].capa) {
3114 ret = os_snprintf(pos, end - pos, "%s%s",
3115 pos == buf ? "" : " ",
3117 if (ret < 0 || ret >= end - pos)
3127 static int ctrl_iface_get_capability_key_mgmt(int res, char *strict,
3128 struct wpa_driver_capa *capa,
3129 char *buf, size_t buflen)
3141 len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
3148 ret = os_snprintf(pos, end - pos, "NONE IEEE8021X");
3149 if (ret < 0 || ret >= end - pos)
3153 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
3154 WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
3155 ret = os_snprintf(pos, end - pos, " WPA-EAP");
3156 if (ret < 0 || ret >= end - pos)
3161 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
3162 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
3163 ret = os_snprintf(pos, end - pos, " WPA-PSK");
3164 if (ret < 0 || ret >= end - pos)
3169 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
3170 ret = os_snprintf(pos, end - pos, " WPA-NONE");
3171 if (ret < 0 || ret >= end - pos)
3180 static int ctrl_iface_get_capability_proto(int res, char *strict,
3181 struct wpa_driver_capa *capa,
3182 char *buf, size_t buflen)
3194 len = os_strlcpy(buf, "RSN WPA", buflen);
3200 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
3201 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
3202 ret = os_snprintf(pos, end - pos, "%sRSN",
3203 pos == buf ? "" : " ");
3204 if (ret < 0 || ret >= end - pos)
3209 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
3210 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
3211 ret = os_snprintf(pos, end - pos, "%sWPA",
3212 pos == buf ? "" : " ");
3213 if (ret < 0 || ret >= end - pos)
3222 static int ctrl_iface_get_capability_auth_alg(int res, char *strict,
3223 struct wpa_driver_capa *capa,
3224 char *buf, size_t buflen)
3236 len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen);
3242 if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) {
3243 ret = os_snprintf(pos, end - pos, "%sOPEN",
3244 pos == buf ? "" : " ");
3245 if (ret < 0 || ret >= end - pos)
3250 if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) {
3251 ret = os_snprintf(pos, end - pos, "%sSHARED",
3252 pos == buf ? "" : " ");
3253 if (ret < 0 || ret >= end - pos)
3258 if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) {
3259 ret = os_snprintf(pos, end - pos, "%sLEAP",
3260 pos == buf ? "" : " ");
3261 if (ret < 0 || ret >= end - pos)
3270 static int ctrl_iface_get_capability_modes(int res, char *strict,
3271 struct wpa_driver_capa *capa,
3272 char *buf, size_t buflen)
3284 len = os_strlcpy(buf, "IBSS AP", buflen);
3290 if (capa->flags & WPA_DRIVER_FLAGS_IBSS) {
3291 ret = os_snprintf(pos, end - pos, "%sIBSS",
3292 pos == buf ? "" : " ");
3293 if (ret < 0 || ret >= end - pos)
3298 if (capa->flags & WPA_DRIVER_FLAGS_AP) {
3299 ret = os_snprintf(pos, end - pos, "%sAP",
3300 pos == buf ? "" : " ");
3301 if (ret < 0 || ret >= end - pos)
3310 static int ctrl_iface_get_capability_channels(struct wpa_supplicant *wpa_s,
3311 char *buf, size_t buflen)
3313 struct hostapd_channel_data *chnl;
3315 char *pos, *end, *hmode;
3320 for (j = 0; j < wpa_s->hw.num_modes; j++) {
3321 switch (wpa_s->hw.modes[j].mode) {
3322 case HOSTAPD_MODE_IEEE80211B:
3325 case HOSTAPD_MODE_IEEE80211G:
3328 case HOSTAPD_MODE_IEEE80211A:
3331 case HOSTAPD_MODE_IEEE80211AD:
3337 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:", hmode);
3338 if (ret < 0 || ret >= end - pos)
3341 chnl = wpa_s->hw.modes[j].channels;
3342 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
3343 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
3345 ret = os_snprintf(pos, end - pos, " %d", chnl[i].chan);
3346 if (ret < 0 || ret >= end - pos)
3350 ret = os_snprintf(pos, end - pos, "\n");
3351 if (ret < 0 || ret >= end - pos)
3360 static int ctrl_iface_get_capability_freq(struct wpa_supplicant *wpa_s,
3361 char *buf, size_t buflen)
3363 struct hostapd_channel_data *chnl;
3365 char *pos, *end, *hmode;
3370 for (j = 0; j < wpa_s->hw.num_modes; j++) {
3371 switch (wpa_s->hw.modes[j].mode) {
3372 case HOSTAPD_MODE_IEEE80211B:
3375 case HOSTAPD_MODE_IEEE80211G:
3378 case HOSTAPD_MODE_IEEE80211A:
3381 case HOSTAPD_MODE_IEEE80211AD:
3387 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:\n",
3389 if (ret < 0 || ret >= end - pos)
3392 chnl = wpa_s->hw.modes[j].channels;
3393 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
3394 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
3396 ret = os_snprintf(pos, end - pos, " %d = %d MHz%s%s\n",
3397 chnl[i].chan, chnl[i].freq,
3398 chnl[i].flag & HOSTAPD_CHAN_NO_IR ?
3400 chnl[i].flag & HOSTAPD_CHAN_RADAR ?
3403 if (ret < 0 || ret >= end - pos)
3407 ret = os_snprintf(pos, end - pos, "\n");
3408 if (ret < 0 || ret >= end - pos)
3417 static int wpa_supplicant_ctrl_iface_get_capability(
3418 struct wpa_supplicant *wpa_s, const char *_field, char *buf,
3421 struct wpa_driver_capa capa;
3427 /* Determine whether or not strict checking was requested */
3428 len = os_strlcpy(field, _field, sizeof(field));
3429 if (len >= sizeof(field))
3431 strict = os_strchr(field, ' ');
3432 if (strict != NULL) {
3434 if (os_strcmp(strict, "strict") != 0)
3438 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
3439 field, strict ? strict : "");
3441 if (os_strcmp(field, "eap") == 0) {
3442 return eap_get_names(buf, buflen);
3445 res = wpa_drv_get_capa(wpa_s, &capa);
3447 if (os_strcmp(field, "pairwise") == 0)
3448 return ctrl_iface_get_capability_pairwise(res, strict, &capa,
3451 if (os_strcmp(field, "group") == 0)
3452 return ctrl_iface_get_capability_group(res, strict, &capa,
3455 if (os_strcmp(field, "key_mgmt") == 0)
3456 return ctrl_iface_get_capability_key_mgmt(res, strict, &capa,
3459 if (os_strcmp(field, "proto") == 0)
3460 return ctrl_iface_get_capability_proto(res, strict, &capa,
3463 if (os_strcmp(field, "auth_alg") == 0)
3464 return ctrl_iface_get_capability_auth_alg(res, strict, &capa,
3467 if (os_strcmp(field, "modes") == 0)
3468 return ctrl_iface_get_capability_modes(res, strict, &capa,
3471 if (os_strcmp(field, "channels") == 0)
3472 return ctrl_iface_get_capability_channels(wpa_s, buf, buflen);
3474 if (os_strcmp(field, "freq") == 0)
3475 return ctrl_iface_get_capability_freq(wpa_s, buf, buflen);
3478 if (os_strcmp(field, "tdls") == 0)
3479 return ctrl_iface_get_capability_tdls(wpa_s, buf, buflen);
3480 #endif /* CONFIG_TDLS */
3482 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
3489 #ifdef CONFIG_INTERWORKING
3490 static char * anqp_add_hex(char *pos, char *end, const char *title,
3491 struct wpabuf *data)
3501 ret = os_snprintf(pos, end - pos, "%s=", title);
3502 if (ret < 0 || ret >= end - pos)
3506 d = wpabuf_head_u8(data);
3507 for (i = 0; i < wpabuf_len(data); i++) {
3508 ret = os_snprintf(pos, end - pos, "%02x", *d++);
3509 if (ret < 0 || ret >= end - pos)
3514 ret = os_snprintf(pos, end - pos, "\n");
3515 if (ret < 0 || ret >= end - pos)
3521 #endif /* CONFIG_INTERWORKING */
3524 static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
3525 unsigned long mask, char *buf, size_t buflen)
3535 if (mask & WPA_BSS_MASK_ID) {
3536 ret = os_snprintf(pos, end - pos, "id=%u\n", bss->id);
3537 if (ret < 0 || ret >= end - pos)
3542 if (mask & WPA_BSS_MASK_BSSID) {
3543 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
3544 MAC2STR(bss->bssid));
3545 if (ret < 0 || ret >= end - pos)
3550 if (mask & WPA_BSS_MASK_FREQ) {
3551 ret = os_snprintf(pos, end - pos, "freq=%d\n", bss->freq);
3552 if (ret < 0 || ret >= end - pos)
3557 if (mask & WPA_BSS_MASK_BEACON_INT) {
3558 ret = os_snprintf(pos, end - pos, "beacon_int=%d\n",
3560 if (ret < 0 || ret >= end - pos)
3565 if (mask & WPA_BSS_MASK_CAPABILITIES) {
3566 ret = os_snprintf(pos, end - pos, "capabilities=0x%04x\n",
3568 if (ret < 0 || ret >= end - pos)
3573 if (mask & WPA_BSS_MASK_QUAL) {
3574 ret = os_snprintf(pos, end - pos, "qual=%d\n", bss->qual);
3575 if (ret < 0 || ret >= end - pos)
3580 if (mask & WPA_BSS_MASK_NOISE) {
3581 ret = os_snprintf(pos, end - pos, "noise=%d\n", bss->noise);
3582 if (ret < 0 || ret >= end - pos)
3587 if (mask & WPA_BSS_MASK_LEVEL) {
3588 ret = os_snprintf(pos, end - pos, "level=%d\n", bss->level);
3589 if (ret < 0 || ret >= end - pos)
3594 if (mask & WPA_BSS_MASK_TSF) {
3595 ret = os_snprintf(pos, end - pos, "tsf=%016llu\n",
3596 (unsigned long long) bss->tsf);
3597 if (ret < 0 || ret >= end - pos)
3602 if (mask & WPA_BSS_MASK_AGE) {
3603 struct os_reltime now;
3605 os_get_reltime(&now);
3606 ret = os_snprintf(pos, end - pos, "age=%d\n",
3607 (int) (now.sec - bss->last_update.sec));
3608 if (ret < 0 || ret >= end - pos)
3613 if (mask & WPA_BSS_MASK_IE) {
3614 ret = os_snprintf(pos, end - pos, "ie=");
3615 if (ret < 0 || ret >= end - pos)
3619 ie = (const u8 *) (bss + 1);
3620 for (i = 0; i < bss->ie_len; i++) {
3621 ret = os_snprintf(pos, end - pos, "%02x", *ie++);
3622 if (ret < 0 || ret >= end - pos)
3627 ret = os_snprintf(pos, end - pos, "\n");
3628 if (ret < 0 || ret >= end - pos)
3633 if (mask & WPA_BSS_MASK_FLAGS) {
3634 ret = os_snprintf(pos, end - pos, "flags=");
3635 if (ret < 0 || ret >= end - pos)
3639 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
3641 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie,
3643 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
3645 pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2,
3647 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
3648 if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
3649 ret = os_snprintf(pos, end - pos, "[WEP]");
3650 if (ret < 0 || ret >= end - pos)
3654 if (bss_is_dmg(bss)) {
3656 ret = os_snprintf(pos, end - pos, "[DMG]");
3657 if (ret < 0 || ret >= end - pos)
3660 switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
3661 case IEEE80211_CAP_DMG_IBSS:
3664 case IEEE80211_CAP_DMG_AP:
3667 case IEEE80211_CAP_DMG_PBSS:
3674 ret = os_snprintf(pos, end - pos, "%s", s);
3675 if (ret < 0 || ret >= end - pos)
3679 if (bss->caps & IEEE80211_CAP_IBSS) {
3680 ret = os_snprintf(pos, end - pos, "[IBSS]");
3681 if (ret < 0 || ret >= end - pos)
3685 if (bss->caps & IEEE80211_CAP_ESS) {
3686 ret = os_snprintf(pos, end - pos, "[ESS]");
3687 if (ret < 0 || ret >= end - pos)
3692 if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
3693 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
3694 ret = os_snprintf(pos, end - pos, "[P2P]");
3695 if (ret < 0 || ret >= end - pos)
3700 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) {
3701 ret = os_snprintf(pos, end - pos, "[HS20]");
3702 if (ret < 0 || ret >= end - pos)
3706 #endif /* CONFIG_HS20 */
3708 ret = os_snprintf(pos, end - pos, "\n");
3709 if (ret < 0 || ret >= end - pos)
3714 if (mask & WPA_BSS_MASK_SSID) {
3715 ret = os_snprintf(pos, end - pos, "ssid=%s\n",
3716 wpa_ssid_txt(bss->ssid, bss->ssid_len));
3717 if (ret < 0 || ret >= end - pos)
3723 if (mask & WPA_BSS_MASK_WPS_SCAN) {
3724 ie = (const u8 *) (bss + 1);
3725 ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end);
3726 if (ret < 0 || ret >= end - pos)
3730 #endif /* CONFIG_WPS */
3733 if (mask & WPA_BSS_MASK_P2P_SCAN) {
3734 ie = (const u8 *) (bss + 1);
3735 ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end);
3736 if (ret < 0 || ret >= end - pos)
3740 #endif /* CONFIG_P2P */
3742 #ifdef CONFIG_WIFI_DISPLAY
3743 if (mask & WPA_BSS_MASK_WIFI_DISPLAY) {
3745 ie = (const u8 *) (bss + 1);
3746 wfd = ieee802_11_vendor_ie_concat(ie, bss->ie_len,
3747 WFD_IE_VENDOR_TYPE);
3749 ret = os_snprintf(pos, end - pos, "wfd_subelems=");
3750 if (ret < 0 || ret >= end - pos) {
3756 pos += wpa_snprintf_hex(pos, end - pos,
3761 ret = os_snprintf(pos, end - pos, "\n");
3762 if (ret < 0 || ret >= end - pos)
3767 #endif /* CONFIG_WIFI_DISPLAY */
3769 #ifdef CONFIG_INTERWORKING
3770 if ((mask & WPA_BSS_MASK_INTERNETW) && bss->anqp) {
3771 struct wpa_bss_anqp *anqp = bss->anqp;
3772 pos = anqp_add_hex(pos, end, "anqp_venue_name",
3774 pos = anqp_add_hex(pos, end, "anqp_network_auth_type",
3775 anqp->network_auth_type);
3776 pos = anqp_add_hex(pos, end, "anqp_roaming_consortium",
3777 anqp->roaming_consortium);
3778 pos = anqp_add_hex(pos, end, "anqp_ip_addr_type_availability",
3779 anqp->ip_addr_type_availability);
3780 pos = anqp_add_hex(pos, end, "anqp_nai_realm",
3782 pos = anqp_add_hex(pos, end, "anqp_3gpp", anqp->anqp_3gpp);
3783 pos = anqp_add_hex(pos, end, "anqp_domain_name",
3786 pos = anqp_add_hex(pos, end, "hs20_operator_friendly_name",
3787 anqp->hs20_operator_friendly_name);
3788 pos = anqp_add_hex(pos, end, "hs20_wan_metrics",
3789 anqp->hs20_wan_metrics);
3790 pos = anqp_add_hex(pos, end, "hs20_connection_capability",
3791 anqp->hs20_connection_capability);
3792 pos = anqp_add_hex(pos, end, "hs20_operating_class",
3793 anqp->hs20_operating_class);
3794 pos = anqp_add_hex(pos, end, "hs20_osu_providers_list",
3795 anqp->hs20_osu_providers_list);
3796 #endif /* CONFIG_HS20 */
3798 #endif /* CONFIG_INTERWORKING */
3800 if (mask & WPA_BSS_MASK_DELIM) {
3801 ret = os_snprintf(pos, end - pos, "====\n");
3802 if (ret < 0 || ret >= end - pos)
3811 static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
3812 const char *cmd, char *buf,
3817 struct wpa_bss *bss;
3818 struct wpa_bss *bsslast = NULL;
3819 struct dl_list *next;
3823 unsigned long mask = WPA_BSS_MASK_ALL;
3825 if (os_strncmp(cmd, "RANGE=", 6) == 0) {
3826 if (os_strncmp(cmd + 6, "ALL", 3) == 0) {
3827 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss,
3829 bsslast = dl_list_last(&wpa_s->bss_id, struct wpa_bss,
3831 } else { /* N1-N2 */
3832 unsigned int id1, id2;
3834 if ((ctmp = os_strchr(cmd + 6, '-')) == NULL) {
3835 wpa_printf(MSG_INFO, "Wrong BSS range "
3840 if (*(cmd + 6) == '-')
3843 id1 = atoi(cmd + 6);
3845 if (*ctmp >= '0' && *ctmp <= '9')
3848 id2 = (unsigned int) -1;
3849 bss = wpa_bss_get_id_range(wpa_s, id1, id2);
3850 if (id2 == (unsigned int) -1)
3851 bsslast = dl_list_last(&wpa_s->bss_id,
3855 bsslast = wpa_bss_get_id(wpa_s, id2);
3856 if (bsslast == NULL && bss && id2 > id1) {
3857 struct wpa_bss *tmp = bss;
3859 next = tmp->list_id.next;
3860 if (next == &wpa_s->bss_id)
3862 tmp = dl_list_entry(
3863 next, struct wpa_bss,
3872 } else if (os_strncmp(cmd, "FIRST", 5) == 0)
3873 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, list_id);
3874 else if (os_strncmp(cmd, "LAST", 4) == 0)
3875 bss = dl_list_last(&wpa_s->bss_id, struct wpa_bss, list_id);
3876 else if (os_strncmp(cmd, "ID-", 3) == 0) {
3878 bss = wpa_bss_get_id(wpa_s, i);
3879 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
3881 bss = wpa_bss_get_id(wpa_s, i);
3883 next = bss->list_id.next;
3884 if (next == &wpa_s->bss_id)
3887 bss = dl_list_entry(next, struct wpa_bss,
3891 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
3892 if (hwaddr_aton(cmd + 13, bssid) == 0)
3893 bss = wpa_bss_get_p2p_dev_addr(wpa_s, bssid);
3896 #endif /* CONFIG_P2P */
3897 } else if (hwaddr_aton(cmd, bssid) == 0)
3898 bss = wpa_bss_get_bssid(wpa_s, bssid);
3900 struct wpa_bss *tmp;
3903 dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id)
3912 if ((ctmp = os_strstr(cmd, "MASK=")) != NULL) {
3913 mask = strtoul(ctmp + 5, NULL, 0x10);
3915 mask = WPA_BSS_MASK_ALL;
3921 if (bsslast == NULL)
3924 len = print_bss_info(wpa_s, bss, mask, buf, buflen);
3928 if (bss == bsslast) {
3929 if ((mask & WPA_BSS_MASK_DELIM) && len &&
3930 (bss == dl_list_last(&wpa_s->bss_id,
3931 struct wpa_bss, list_id)))
3932 os_snprintf(buf - 5, 5, "####\n");
3935 next = bss->list_id.next;
3936 if (next == &wpa_s->bss_id)
3938 bss = dl_list_entry(next, struct wpa_bss, list_id);
3939 } while (bss && len);
3945 static int wpa_supplicant_ctrl_iface_ap_scan(
3946 struct wpa_supplicant *wpa_s, char *cmd)
3948 int ap_scan = atoi(cmd);
3949 return wpa_supplicant_set_ap_scan(wpa_s, ap_scan);
3953 static int wpa_supplicant_ctrl_iface_scan_interval(
3954 struct wpa_supplicant *wpa_s, char *cmd)
3956 int scan_int = atoi(cmd);
3957 return wpa_supplicant_set_scan_interval(wpa_s, scan_int);
3961 static int wpa_supplicant_ctrl_iface_bss_expire_age(
3962 struct wpa_supplicant *wpa_s, char *cmd)
3964 int expire_age = atoi(cmd);
3965 return wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age);
3969 static int wpa_supplicant_ctrl_iface_bss_expire_count(
3970 struct wpa_supplicant *wpa_s, char *cmd)
3972 int expire_count = atoi(cmd);
3973 return wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count);
3977 static int wpa_supplicant_ctrl_iface_bss_flush(
3978 struct wpa_supplicant *wpa_s, char *cmd)
3980 int flush_age = atoi(cmd);
3983 wpa_bss_flush(wpa_s);
3985 wpa_bss_flush_by_age(wpa_s, flush_age);
3990 #ifdef CONFIG_TESTING_OPTIONS
3991 static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s)
3993 wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication");
3994 /* MLME-DELETEKEYS.request */
3995 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL, 0);
3996 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL, 0);
3997 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL, 0);
3998 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL, 0);
3999 #ifdef CONFIG_IEEE80211W
4000 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL, 0);
4001 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL, 0);
4002 #endif /* CONFIG_IEEE80211W */
4004 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, wpa_s->bssid, 0, 0, NULL, 0, NULL,
4006 /* MLME-SETPROTECTION.request(None) */
4007 wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid,
4008 MLME_SETPROTECTION_PROTECT_TYPE_NONE,
4009 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE);
4010 wpa_sm_drop_sa(wpa_s->wpa);
4012 #endif /* CONFIG_TESTING_OPTIONS */
4015 static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s,
4018 #ifdef CONFIG_NO_SCAN_PROCESSING
4020 #else /* CONFIG_NO_SCAN_PROCESSING */
4022 struct wpa_bss *bss;
4023 struct wpa_ssid *ssid = wpa_s->current_ssid;
4025 if (hwaddr_aton(addr, bssid)) {
4026 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid "
4027 "address '%s'", addr);
4031 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR, MAC2STR(bssid));
4034 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network "
4035 "configuration known for the target AP");
4039 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
4041 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found "
4047 * TODO: Find best network configuration block from configuration to
4048 * allow roaming to other networks
4051 wpa_s->reassociate = 1;
4052 wpa_supplicant_connect(wpa_s, bss, ssid);
4055 #endif /* CONFIG_NO_SCAN_PROCESSING */
4060 static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd)
4062 unsigned int timeout = atoi(cmd);
4063 enum p2p_discovery_type type = P2P_FIND_START_WITH_FULL;
4064 u8 dev_id[ETH_ALEN], *_dev_id = NULL;
4065 u8 dev_type[WPS_DEV_TYPE_LEN], *_dev_type = NULL;
4067 unsigned int search_delay;
4069 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
4070 wpa_dbg(wpa_s, MSG_INFO,
4071 "Reject P2P_FIND since interface is disabled");
4074 if (os_strstr(cmd, "type=social"))
4075 type = P2P_FIND_ONLY_SOCIAL;
4076 else if (os_strstr(cmd, "type=progressive"))
4077 type = P2P_FIND_PROGRESSIVE;
4079 pos = os_strstr(cmd, "dev_id=");
4082 if (hwaddr_aton(pos, dev_id))
4087 pos = os_strstr(cmd, "dev_type=");
4090 if (wps_dev_type_str2bin(pos, dev_type) < 0)
4092 _dev_type = dev_type;
4095 pos = os_strstr(cmd, "delay=");
4098 search_delay = atoi(pos);
4100 search_delay = wpas_p2p_search_delay(wpa_s);
4102 return wpas_p2p_find(wpa_s, timeout, type, _dev_type != NULL, _dev_type,
4103 _dev_id, search_delay);
4107 static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd,
4108 char *buf, size_t buflen)
4113 enum p2p_wps_method wps_method;
4116 int persistent_group, persistent_id = -1;
4125 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad]
4126 * [persistent|persistent=<network id>]
4127 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
4130 if (hwaddr_aton(cmd, addr))
4138 persistent_group = os_strstr(pos, " persistent") != NULL;
4139 pos2 = os_strstr(pos, " persistent=");
4141 struct wpa_ssid *ssid;
4142 persistent_id = atoi(pos2 + 12);
4143 ssid = wpa_config_get_network(wpa_s->conf, persistent_id);
4144 if (ssid == NULL || ssid->disabled != 2 ||
4145 ssid->mode != WPAS_MODE_P2P_GO) {
4146 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
4147 "SSID id=%d for persistent P2P group (GO)",
4152 join = os_strstr(pos, " join") != NULL;
4153 auth = os_strstr(pos, " auth") != NULL;
4154 automatic = os_strstr(pos, " auto") != NULL;
4155 pd = os_strstr(pos, " provdisc") != NULL;
4156 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
4157 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
4160 pos2 = os_strstr(pos, " go_intent=");
4163 go_intent = atoi(pos2);
4164 if (go_intent < 0 || go_intent > 15)
4168 pos2 = os_strstr(pos, " freq=");
4176 if (os_strncmp(pos, "pin", 3) == 0) {
4177 /* Request random PIN (to be displayed) and enable the PIN */
4178 wps_method = WPS_PIN_DISPLAY;
4179 } else if (os_strncmp(pos, "pbc", 3) == 0) {
4180 wps_method = WPS_PBC;
4183 pos = os_strchr(pin, ' ');
4184 wps_method = WPS_PIN_KEYPAD;
4187 if (os_strncmp(pos, "display", 7) == 0)
4188 wps_method = WPS_PIN_DISPLAY;
4190 if (!wps_pin_str_valid(pin)) {
4191 os_memcpy(buf, "FAIL-INVALID-PIN\n", 17);
4196 new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method,
4197 persistent_group, automatic, join,
4198 auth, go_intent, freq, persistent_id, pd,
4200 if (new_pin == -2) {
4201 os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
4204 if (new_pin == -3) {
4205 os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
4210 if (wps_method == WPS_PIN_DISPLAY && pin == NULL) {
4211 ret = os_snprintf(buf, buflen, "%08d", new_pin);
4212 if (ret < 0 || (size_t) ret >= buflen)
4217 os_memcpy(buf, "OK\n", 3);
4222 static int p2p_ctrl_listen(struct wpa_supplicant *wpa_s, char *cmd)
4224 unsigned int timeout = atoi(cmd);
4225 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
4226 wpa_dbg(wpa_s, MSG_INFO,
4227 "Reject P2P_LISTEN since interface is disabled");
4230 return wpas_p2p_listen(wpa_s, timeout);
4234 static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd)
4238 enum wpas_p2p_prov_disc_use use = WPAS_P2P_PD_FOR_GO_NEG;
4240 /* <addr> <config method> [join|auto] */
4242 if (hwaddr_aton(cmd, addr))
4250 if (os_strstr(pos, " join") != NULL)
4251 use = WPAS_P2P_PD_FOR_JOIN;
4252 else if (os_strstr(pos, " auto") != NULL)
4253 use = WPAS_P2P_PD_AUTO;
4255 return wpas_p2p_prov_disc(wpa_s, addr, pos, use);
4259 static int p2p_get_passphrase(struct wpa_supplicant *wpa_s, char *buf,
4262 struct wpa_ssid *ssid = wpa_s->current_ssid;
4264 if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO ||
4265 ssid->passphrase == NULL)
4268 os_strlcpy(buf, ssid->passphrase, buflen);
4269 return os_strlen(buf);
4273 static int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd,
4274 char *buf, size_t buflen)
4278 u8 dst_buf[ETH_ALEN], *dst;
4279 struct wpabuf *tlvs;
4283 if (hwaddr_aton(cmd, dst_buf))
4286 if (dst[0] == 0 && dst[1] == 0 && dst[2] == 0 &&
4287 dst[3] == 0 && dst[4] == 0 && dst[5] == 0)
4294 if (os_strncmp(pos, "upnp ", 5) == 0) {
4297 if (hexstr2bin(pos, &version, 1) < 0)
4303 ref = wpas_p2p_sd_request_upnp(wpa_s, dst, version, pos);
4304 #ifdef CONFIG_WIFI_DISPLAY
4305 } else if (os_strncmp(pos, "wifi-display ", 13) == 0) {
4306 ref = wpas_p2p_sd_request_wifi_display(wpa_s, dst, pos + 13);
4307 #endif /* CONFIG_WIFI_DISPLAY */
4309 len = os_strlen(pos);
4313 tlvs = wpabuf_alloc(len);
4316 if (hexstr2bin(pos, wpabuf_put(tlvs, len), len) < 0) {
4321 ref = wpas_p2p_sd_request(wpa_s, dst, tlvs);
4326 res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref);
4327 if (res < 0 || (unsigned) res >= buflen)
4333 static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s,
4336 long long unsigned val;
4338 if (sscanf(cmd, "%llx", &val) != 1)
4341 return wpas_p2p_sd_cancel_request(wpa_s, req);
4345 static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant *wpa_s, char *cmd)
4350 struct wpabuf *resp_tlvs;
4354 pos = os_strchr(cmd, ' ');
4362 if (hwaddr_aton(pos, dst))
4369 pos2 = os_strchr(pos, ' ');
4373 dialog_token = atoi(pos);
4375 len = os_strlen(pos2);
4379 resp_tlvs = wpabuf_alloc(len);
4380 if (resp_tlvs == NULL)
4382 if (hexstr2bin(pos2, wpabuf_put(resp_tlvs, len), len) < 0) {
4383 wpabuf_free(resp_tlvs);
4387 wpas_p2p_sd_response(wpa_s, freq, dst, dialog_token, resp_tlvs);
4388 wpabuf_free(resp_tlvs);
4393 static int p2p_ctrl_serv_disc_external(struct wpa_supplicant *wpa_s,
4396 if (os_strcmp(cmd, "0") && os_strcmp(cmd, "1"))
4398 wpa_s->p2p_sd_over_ctrl_iface = atoi(cmd);
4403 static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant *wpa_s,
4408 struct wpabuf *query, *resp;
4410 pos = os_strchr(cmd, ' ');
4415 len = os_strlen(cmd);
4419 query = wpabuf_alloc(len);
4422 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
4427 len = os_strlen(pos);
4433 resp = wpabuf_alloc(len);
4438 if (hexstr2bin(pos, wpabuf_put(resp, len), len) < 0) {
4444 if (wpas_p2p_service_add_bonjour(wpa_s, query, resp) < 0) {
4453 static int p2p_ctrl_service_add_upnp(struct wpa_supplicant *wpa_s, char *cmd)
4458 pos = os_strchr(cmd, ' ');
4463 if (hexstr2bin(cmd, &version, 1) < 0)
4466 return wpas_p2p_service_add_upnp(wpa_s, version, pos);
4470 static int p2p_ctrl_service_add(struct wpa_supplicant *wpa_s, char *cmd)
4474 pos = os_strchr(cmd, ' ');
4479 if (os_strcmp(cmd, "bonjour") == 0)
4480 return p2p_ctrl_service_add_bonjour(wpa_s, pos);
4481 if (os_strcmp(cmd, "upnp") == 0)
4482 return p2p_ctrl_service_add_upnp(wpa_s, pos);
4483 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
4488 static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant *wpa_s,
4492 struct wpabuf *query;
4495 len = os_strlen(cmd);
4499 query = wpabuf_alloc(len);
4502 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
4507 ret = wpas_p2p_service_del_bonjour(wpa_s, query);
4513 static int p2p_ctrl_service_del_upnp(struct wpa_supplicant *wpa_s, char *cmd)
4518 pos = os_strchr(cmd, ' ');
4523 if (hexstr2bin(cmd, &version, 1) < 0)
4526 return wpas_p2p_service_del_upnp(wpa_s, version, pos);
4530 static int p2p_ctrl_service_del(struct wpa_supplicant *wpa_s, char *cmd)
4534 pos = os_strchr(cmd, ' ');
4539 if (os_strcmp(cmd, "bonjour") == 0)
4540 return p2p_ctrl_service_del_bonjour(wpa_s, pos);
4541 if (os_strcmp(cmd, "upnp") == 0)
4542 return p2p_ctrl_service_del_upnp(wpa_s, pos);
4543 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
4548 static int p2p_ctrl_reject(struct wpa_supplicant *wpa_s, char *cmd)
4554 if (hwaddr_aton(cmd, addr))
4557 return wpas_p2p_reject(wpa_s, addr);
4561 static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd)
4565 struct wpa_ssid *ssid;
4566 u8 *_peer = NULL, peer[ETH_ALEN];
4567 int freq = 0, pref_freq = 0;
4571 pos = os_strstr(cmd, " peer=");
4574 if (hwaddr_aton(pos, peer))
4578 ssid = wpa_config_get_network(wpa_s->conf, id);
4579 if (ssid == NULL || ssid->disabled != 2) {
4580 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
4581 "for persistent P2P group",
4586 pos = os_strstr(cmd, " freq=");
4594 pos = os_strstr(cmd, " pref=");
4597 pref_freq = atoi(pos);
4602 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
4603 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
4606 return wpas_p2p_invite(wpa_s, _peer, ssid, NULL, freq, ht40, vht,
4611 static int p2p_ctrl_invite_group(struct wpa_supplicant *wpa_s, char *cmd)
4614 u8 peer[ETH_ALEN], go_dev_addr[ETH_ALEN], *go_dev = NULL;
4616 pos = os_strstr(cmd, " peer=");
4622 if (hwaddr_aton(pos, peer)) {
4623 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", pos);
4627 pos = os_strstr(pos, " go_dev_addr=");
4630 if (hwaddr_aton(pos, go_dev_addr)) {
4631 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'",
4635 go_dev = go_dev_addr;
4638 return wpas_p2p_invite_group(wpa_s, cmd, peer, go_dev);
4642 static int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd)
4644 if (os_strncmp(cmd, "persistent=", 11) == 0)
4645 return p2p_ctrl_invite_persistent(wpa_s, cmd + 11);
4646 if (os_strncmp(cmd, "group=", 6) == 0)
4647 return p2p_ctrl_invite_group(wpa_s, cmd + 6);
4653 static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s,
4654 char *cmd, int freq, int ht40,
4658 struct wpa_ssid *ssid;
4661 ssid = wpa_config_get_network(wpa_s->conf, id);
4662 if (ssid == NULL || ssid->disabled != 2) {
4663 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
4664 "for persistent P2P group",
4669 return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq, 0, ht40, vht,
4674 static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd)
4676 int freq = 0, ht40, vht;
4679 pos = os_strstr(cmd, "freq=");
4681 freq = atoi(pos + 5);
4683 vht = (os_strstr(cmd, "vht") != NULL) || wpa_s->conf->p2p_go_vht;
4684 ht40 = (os_strstr(cmd, "ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
4687 if (os_strncmp(cmd, "persistent=", 11) == 0)
4688 return p2p_ctrl_group_add_persistent(wpa_s, cmd + 11, freq,
4690 if (os_strcmp(cmd, "persistent") == 0 ||
4691 os_strncmp(cmd, "persistent ", 11) == 0)
4692 return wpas_p2p_group_add(wpa_s, 1, freq, ht40, vht);
4693 if (os_strncmp(cmd, "freq=", 5) == 0)
4694 return wpas_p2p_group_add(wpa_s, 0, freq, ht40, vht);
4696 return wpas_p2p_group_add(wpa_s, 0, freq, ht40, vht);
4698 wpa_printf(MSG_DEBUG, "CTRL: Invalid P2P_GROUP_ADD parameters '%s'",
4704 static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd,
4705 char *buf, size_t buflen)
4707 u8 addr[ETH_ALEN], *addr_ptr;
4709 const struct p2p_peer_info *info;
4711 char devtype[WPS_DEV_TYPE_BUFSIZE];
4712 struct wpa_ssid *ssid;
4715 if (!wpa_s->global->p2p)
4718 if (os_strcmp(cmd, "FIRST") == 0) {
4721 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
4722 if (hwaddr_aton(cmd + 5, addr) < 0)
4727 if (hwaddr_aton(cmd, addr) < 0)
4733 info = p2p_get_peer_info(wpa_s->global->p2p, addr_ptr, next);
4740 res = os_snprintf(pos, end - pos, MACSTR "\n"
4746 "serial_number=%s\n"
4747 "config_methods=0x%x\n"
4749 "group_capab=0x%x\n"
4751 MAC2STR(info->p2p_device_addr),
4752 wps_dev_type_bin2str(info->pri_dev_type,
4753 devtype, sizeof(devtype)),
4758 info->serial_number,
4759 info->config_methods,
4763 if (res < 0 || res >= end - pos)
4767 for (i = 0; i < info->wps_sec_dev_type_list_len / WPS_DEV_TYPE_LEN; i++)
4770 t = &info->wps_sec_dev_type_list[i * WPS_DEV_TYPE_LEN];
4771 res = os_snprintf(pos, end - pos, "sec_dev_type=%s\n",
4772 wps_dev_type_bin2str(t, devtype,
4774 if (res < 0 || res >= end - pos)
4779 ssid = wpas_p2p_get_persistent(wpa_s, info->p2p_device_addr, NULL, 0);
4781 res = os_snprintf(pos, end - pos, "persistent=%d\n", ssid->id);
4782 if (res < 0 || res >= end - pos)
4787 res = p2p_get_peer_info_txt(info, pos, end - pos);
4792 if (info->vendor_elems) {
4793 res = os_snprintf(pos, end - pos, "vendor_elems=");
4794 if (res < 0 || res >= end - pos)
4798 pos += wpa_snprintf_hex(pos, end - pos,
4799 wpabuf_head(info->vendor_elems),
4800 wpabuf_len(info->vendor_elems));
4802 res = os_snprintf(pos, end - pos, "\n");
4803 if (res < 0 || res >= end - pos)
4812 static int p2p_ctrl_disallow_freq(struct wpa_supplicant *wpa_s,
4817 if (wpa_s->global->p2p == NULL)
4820 if (freq_range_list_parse(&wpa_s->global->p2p_disallow_freq, param) < 0)
4823 for (i = 0; i < wpa_s->global->p2p_disallow_freq.num; i++) {
4824 struct wpa_freq_range *freq;
4825 freq = &wpa_s->global->p2p_disallow_freq.range[i];
4826 wpa_printf(MSG_DEBUG, "P2P: Disallowed frequency range %u-%u",
4827 freq->min, freq->max);
4830 wpas_p2p_update_channel_list(wpa_s);
4835 static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd)
4839 if (wpa_s->global->p2p == NULL)
4842 param = os_strchr(cmd, ' ');
4847 if (os_strcmp(cmd, "discoverability") == 0) {
4848 p2p_set_client_discoverability(wpa_s->global->p2p,
4853 if (os_strcmp(cmd, "managed") == 0) {
4854 p2p_set_managed_oper(wpa_s->global->p2p, atoi(param));
4858 if (os_strcmp(cmd, "listen_channel") == 0) {
4859 return p2p_set_listen_channel(wpa_s->global->p2p, 81,
4863 if (os_strcmp(cmd, "ssid_postfix") == 0) {
4864 return p2p_set_ssid_postfix(wpa_s->global->p2p, (u8 *) param,
4868 if (os_strcmp(cmd, "noa") == 0) {
4870 int count, start, duration;
4871 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
4872 count = atoi(param);
4873 pos = os_strchr(param, ',');
4878 pos = os_strchr(pos, ',');
4882 duration = atoi(pos);
4883 if (count < 0 || count > 255 || start < 0 || duration < 0)
4885 if (count == 0 && duration > 0)
4887 wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
4888 "start=%d duration=%d", count, start, duration);
4889 return wpas_p2p_set_noa(wpa_s, count, start, duration);
4892 if (os_strcmp(cmd, "ps") == 0)
4893 return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1);
4895 if (os_strcmp(cmd, "oppps") == 0)
4896 return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1);
4898 if (os_strcmp(cmd, "ctwindow") == 0)
4899 return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param));
4901 if (os_strcmp(cmd, "disabled") == 0) {
4902 wpa_s->global->p2p_disabled = atoi(param);
4903 wpa_printf(MSG_DEBUG, "P2P functionality %s",
4904 wpa_s->global->p2p_disabled ?
4905 "disabled" : "enabled");
4906 if (wpa_s->global->p2p_disabled) {
4907 wpas_p2p_stop_find(wpa_s);
4908 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
4909 p2p_flush(wpa_s->global->p2p);
4914 if (os_strcmp(cmd, "conc_pref") == 0) {
4915 if (os_strcmp(param, "sta") == 0)
4916 wpa_s->global->conc_pref = WPA_CONC_PREF_STA;
4917 else if (os_strcmp(param, "p2p") == 0)
4918 wpa_s->global->conc_pref = WPA_CONC_PREF_P2P;
4920 wpa_printf(MSG_INFO, "Invalid conc_pref value");
4923 wpa_printf(MSG_DEBUG, "Single channel concurrency preference: "
4928 if (os_strcmp(cmd, "force_long_sd") == 0) {
4929 wpa_s->force_long_sd = atoi(param);
4933 if (os_strcmp(cmd, "peer_filter") == 0) {
4935 if (hwaddr_aton(param, addr))
4937 p2p_set_peer_filter(wpa_s->global->p2p, addr);
4941 if (os_strcmp(cmd, "cross_connect") == 0)
4942 return wpas_p2p_set_cross_connect(wpa_s, atoi(param));
4944 if (os_strcmp(cmd, "go_apsd") == 0) {
4945 if (os_strcmp(param, "disable") == 0)
4946 wpa_s->set_ap_uapsd = 0;
4948 wpa_s->set_ap_uapsd = 1;
4949 wpa_s->ap_uapsd = atoi(param);
4954 if (os_strcmp(cmd, "client_apsd") == 0) {
4955 if (os_strcmp(param, "disable") == 0)
4956 wpa_s->set_sta_uapsd = 0;
4960 /* format: BE,BK,VI,VO;max SP Length */
4962 pos = os_strchr(param, ',');
4967 pos = os_strchr(pos, ',');
4972 pos = os_strchr(pos, ',');
4977 /* ignore max SP Length for now */
4979 wpa_s->set_sta_uapsd = 1;
4980 wpa_s->sta_uapsd = 0;
4982 wpa_s->sta_uapsd |= BIT(0);
4984 wpa_s->sta_uapsd |= BIT(1);
4986 wpa_s->sta_uapsd |= BIT(2);
4988 wpa_s->sta_uapsd |= BIT(3);
4993 if (os_strcmp(cmd, "disallow_freq") == 0)
4994 return p2p_ctrl_disallow_freq(wpa_s, param);
4996 if (os_strcmp(cmd, "disc_int") == 0) {
4997 int min_disc_int, max_disc_int, max_disc_tu;
5002 min_disc_int = atoi(pos);
5003 pos = os_strchr(pos, ' ');
5008 max_disc_int = atoi(pos);
5009 pos = os_strchr(pos, ' ');
5014 max_disc_tu = atoi(pos);
5016 return p2p_set_disc_int(wpa_s->global->p2p, min_disc_int,
5017 max_disc_int, max_disc_tu);
5020 if (os_strcmp(cmd, "per_sta_psk") == 0) {
5021 wpa_s->global->p2p_per_sta_psk = !!atoi(param);
5025 #ifdef CONFIG_WPS_NFC
5026 if (os_strcmp(cmd, "nfc_tag") == 0)
5027 return wpas_p2p_nfc_tag_enabled(wpa_s, !!atoi(param));
5028 #endif /* CONFIG_WPS_NFC */
5030 if (os_strcmp(cmd, "disable_ip_addr_req") == 0) {
5031 wpa_s->p2p_disable_ip_addr_req = !!atoi(param);
5035 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
5042 static void p2p_ctrl_flush(struct wpa_supplicant *wpa_s)
5044 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
5045 wpa_s->force_long_sd = 0;
5046 wpas_p2p_stop_find(wpa_s);
5047 if (wpa_s->global->p2p)
5048 p2p_flush(wpa_s->global->p2p);
5052 static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd)
5055 unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0;
5058 pos = os_strchr(cmd, ' ');
5064 pos2 = os_strchr(pos, ' ');
5072 pos = os_strchr(pos2, ' ');
5080 return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2);
5084 static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd)
5087 unsigned int period = 0, interval = 0;
5090 pos = os_strchr(cmd, ' ');
5095 interval = atoi(pos);
5098 return wpas_p2p_ext_listen(wpa_s, period, interval);
5102 static int p2p_ctrl_remove_client(struct wpa_supplicant *wpa_s, const char *cmd)
5109 if (os_strncmp(pos, "iface=", 6) == 0) {
5113 if (hwaddr_aton(pos, peer))
5116 wpas_p2p_remove_client(wpa_s, peer, iface_addr);
5120 #endif /* CONFIG_P2P */
5123 static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s, char *val)
5125 struct wpa_freq_range_list ranges;
5127 struct hostapd_hw_modes *mode;
5130 if (wpa_s->hw.modes == NULL)
5133 os_memset(&ranges, 0, sizeof(ranges));
5134 if (freq_range_list_parse(&ranges, val) < 0)
5137 for (i = 0; i < wpa_s->hw.num_modes; i++) {
5140 mode = &wpa_s->hw.modes[i];
5141 for (j = 0; j < mode->num_channels; j++) {
5144 if (mode->channels[j].flag & HOSTAPD_CHAN_DISABLED)
5147 freq = mode->channels[j].freq;
5148 if (!freq_range_list_includes(&ranges, freq))
5151 int_array_add_unique(&freqs, freq);
5155 os_free(ranges.range);
5160 #ifdef CONFIG_INTERWORKING
5162 static int ctrl_interworking_select(struct wpa_supplicant *wpa_s, char *param)
5170 auto_sel = os_strstr(param, "auto") != NULL;
5172 pos = os_strstr(param, "freq=");
5174 freqs = freq_range_to_channel_list(wpa_s, pos + 5);
5181 return interworking_select(wpa_s, auto_sel, freqs);
5185 static int ctrl_interworking_connect(struct wpa_supplicant *wpa_s, char *dst)
5188 struct wpa_bss *bss;
5190 if (hwaddr_aton(dst, bssid)) {
5191 wpa_printf(MSG_DEBUG, "Invalid BSSID '%s'", dst);
5195 bss = wpa_bss_get_bssid(wpa_s, bssid);
5197 wpa_printf(MSG_DEBUG, "Could not find BSS " MACSTR,
5202 return interworking_connect(wpa_s, bss);
5206 static int get_anqp(struct wpa_supplicant *wpa_s, char *dst)
5208 u8 dst_addr[ETH_ALEN];
5211 #define MAX_ANQP_INFO_ID 100
5212 u16 id[MAX_ANQP_INFO_ID];
5216 used = hwaddr_aton2(dst, dst_addr);
5220 while (num_id < MAX_ANQP_INFO_ID) {
5221 if (os_strncmp(pos, "hs20:", 5) == 0) {
5223 int num = atoi(pos + 5);
5224 if (num <= 0 || num > 31)
5226 subtypes |= BIT(num);
5227 #else /* CONFIG_HS20 */
5229 #endif /* CONFIG_HS20 */
5231 id[num_id] = atoi(pos);
5235 pos = os_strchr(pos + 1, ',');
5244 return anqp_send_req(wpa_s, dst_addr, id, num_id, subtypes);
5248 static int gas_request(struct wpa_supplicant *wpa_s, char *cmd)
5250 u8 dst_addr[ETH_ALEN];
5251 struct wpabuf *advproto, *query = NULL;
5256 used = hwaddr_aton2(cmd, dst_addr);
5264 /* Advertisement Protocol ID */
5265 end = os_strchr(pos, ' ');
5269 len = os_strlen(pos);
5275 advproto = wpabuf_alloc(len);
5276 if (advproto == NULL)
5278 if (hexstr2bin(pos, wpabuf_put(advproto, len), len) < 0)
5282 /* Optional Query Request */
5287 len = os_strlen(pos);
5294 query = wpabuf_alloc(len);
5297 if (hexstr2bin(pos, wpabuf_put(query, len), len) < 0)
5302 ret = gas_send_request(wpa_s, dst_addr, advproto, query);
5305 wpabuf_free(advproto);
5312 static int gas_response_get(struct wpa_supplicant *wpa_s, char *cmd, char *buf,
5319 size_t resp_len, start, requested_len;
5320 struct wpabuf *resp;
5323 used = hwaddr_aton2(cmd, addr);
5330 dialog_token = atoi(pos);
5332 if (wpa_s->last_gas_resp &&
5333 os_memcmp(addr, wpa_s->last_gas_addr, ETH_ALEN) == 0 &&
5334 dialog_token == wpa_s->last_gas_dialog_token)
5335 resp = wpa_s->last_gas_resp;
5336 else if (wpa_s->prev_gas_resp &&
5337 os_memcmp(addr, wpa_s->prev_gas_addr, ETH_ALEN) == 0 &&
5338 dialog_token == wpa_s->prev_gas_dialog_token)
5339 resp = wpa_s->prev_gas_resp;
5343 resp_len = wpabuf_len(resp);
5345 requested_len = resp_len;
5347 pos = os_strchr(pos, ' ');
5350 if (start > resp_len)
5351 return os_snprintf(buf, buflen, "FAIL-Invalid range");
5352 pos = os_strchr(pos, ',');
5356 requested_len = atoi(pos);
5357 if (start + requested_len > resp_len)
5358 return os_snprintf(buf, buflen, "FAIL-Invalid range");
5361 if (requested_len * 2 + 1 > buflen)
5362 return os_snprintf(buf, buflen, "FAIL-Too long response");
5364 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(resp) + start,
5367 if (start + requested_len == resp_len) {
5369 * Free memory by dropping the response after it has been
5372 if (resp == wpa_s->prev_gas_resp) {
5373 wpabuf_free(wpa_s->prev_gas_resp);
5374 wpa_s->prev_gas_resp = NULL;
5376 wpabuf_free(wpa_s->last_gas_resp);
5377 wpa_s->last_gas_resp = NULL;
5383 #endif /* CONFIG_INTERWORKING */
5388 static int get_hs20_anqp(struct wpa_supplicant *wpa_s, char *dst)
5390 u8 dst_addr[ETH_ALEN];
5395 used = hwaddr_aton2(dst, dst_addr);
5400 int num = atoi(pos);
5401 if (num <= 0 || num > 31)
5403 subtypes |= BIT(num);
5404 pos = os_strchr(pos + 1, ',');
5413 return hs20_anqp_send_req(wpa_s, dst_addr, subtypes, NULL, 0);
5417 static int hs20_nai_home_realm_list(struct wpa_supplicant *wpa_s,
5418 const u8 *addr, const char *realm)
5424 rlen = os_strlen(realm);
5426 buf = os_malloc(len);
5429 buf[0] = 1; /* NAI Home Realm Count */
5430 buf[1] = 0; /* Formatted in accordance with RFC 4282 */
5432 os_memcpy(buf + 3, realm, rlen);
5434 ret = hs20_anqp_send_req(wpa_s, addr,
5435 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
5444 static int hs20_get_nai_home_realm_list(struct wpa_supplicant *wpa_s,
5447 struct wpa_cred *cred = wpa_s->conf->cred;
5448 u8 dst_addr[ETH_ALEN];
5454 used = hwaddr_aton2(dst, dst_addr);
5458 while (dst[used] == ' ')
5460 if (os_strncmp(dst + used, "realm=", 6) == 0)
5461 return hs20_nai_home_realm_list(wpa_s, dst_addr,
5464 len = os_strlen(dst + used);
5466 if (len == 0 && cred && cred->realm)
5467 return hs20_nai_home_realm_list(wpa_s, dst_addr, cred->realm);
5472 buf = os_malloc(len);
5475 if (hexstr2bin(dst + used, buf, len) < 0) {
5480 ret = hs20_anqp_send_req(wpa_s, dst_addr,
5481 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
5489 static int hs20_icon_request(struct wpa_supplicant *wpa_s, char *cmd)
5491 u8 dst_addr[ETH_ALEN];
5495 used = hwaddr_aton2(cmd, dst_addr);
5499 while (cmd[used] == ' ')
5503 wpa_s->fetch_osu_icon_in_progress = 0;
5504 return hs20_anqp_send_req(wpa_s, dst_addr, BIT(HS20_STYPE_ICON_REQUEST),
5505 (u8 *) icon, os_strlen(icon));
5508 #endif /* CONFIG_HS20 */
5511 static int wpa_supplicant_ctrl_iface_sta_autoconnect(
5512 struct wpa_supplicant *wpa_s, char *cmd)
5514 wpa_s->auto_reconnect_disabled = atoi(cmd) == 0 ? 1 : 0;
5519 #ifdef CONFIG_AUTOSCAN
5521 static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant *wpa_s,
5524 enum wpa_states state = wpa_s->wpa_state;
5525 char *new_params = NULL;
5527 if (os_strlen(cmd) > 0) {
5528 new_params = os_strdup(cmd);
5529 if (new_params == NULL)
5533 os_free(wpa_s->conf->autoscan);
5534 wpa_s->conf->autoscan = new_params;
5536 if (wpa_s->conf->autoscan == NULL)
5537 autoscan_deinit(wpa_s);
5538 else if (state == WPA_DISCONNECTED || state == WPA_INACTIVE)
5539 autoscan_init(wpa_s, 1);
5540 else if (state == WPA_SCANNING)
5541 wpa_supplicant_reinit_autoscan(wpa_s);
5546 #endif /* CONFIG_AUTOSCAN */
5551 static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant *wpa_s, char *cmd)
5557 struct wpabuf *tfs_req = NULL;
5559 if (os_strncmp(cmd, "enter", 5) == 0)
5561 else if (os_strncmp(cmd, "exit", 4) == 0)
5566 pos = os_strstr(cmd, " interval=");
5568 intval = atoi(pos + 10);
5570 pos = os_strstr(cmd, " tfs_req=");
5575 end = os_strchr(pos, ' ');
5579 len = os_strlen(pos);
5583 tfs_req = wpabuf_alloc(len);
5584 if (tfs_req == NULL)
5586 if (hexstr2bin(pos, wpabuf_put(tfs_req, len), len) < 0) {
5587 wpabuf_free(tfs_req);
5592 ret = ieee802_11_send_wnmsleep_req(wpa_s, enter ? WNM_SLEEP_MODE_ENTER :
5593 WNM_SLEEP_MODE_EXIT, intval,
5595 wpabuf_free(tfs_req);
5601 static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant *wpa_s, char *cmd)
5605 query_reason = atoi(cmd);
5607 wpa_printf(MSG_DEBUG, "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d",
5610 return wnm_send_bss_transition_mgmt_query(wpa_s, query_reason);
5613 #endif /* CONFIG_WNM */
5616 static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf,
5619 struct wpa_signal_info si;
5623 ret = wpa_drv_signal_poll(wpa_s, &si);
5630 ret = os_snprintf(pos, end - pos, "RSSI=%d\nLINKSPEED=%d\n"
5631 "NOISE=%d\nFREQUENCY=%u\n",
5632 si.current_signal, si.current_txrate / 1000,
5633 si.current_noise, si.frequency);
5634 if (ret < 0 || ret > end - pos)
5638 if (si.chanwidth != CHAN_WIDTH_UNKNOWN) {
5639 ret = os_snprintf(pos, end - pos, "WIDTH=%s\n",
5640 channel_width_to_string(si.chanwidth));
5641 if (ret < 0 || ret > end - pos)
5646 if (si.center_frq1 > 0 && si.center_frq2 > 0) {
5647 ret = os_snprintf(pos, end - pos,
5648 "CENTER_FRQ1=%d\nCENTER_FRQ2=%d\n",
5649 si.center_frq1, si.center_frq2);
5650 if (ret < 0 || ret > end - pos)
5655 if (si.avg_signal) {
5656 ret = os_snprintf(pos, end - pos,
5657 "AVG_RSSI=%d\n", si.avg_signal);
5658 if (ret < 0 || ret >= end - pos)
5667 static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant *wpa_s, char *buf,
5670 struct hostap_sta_driver_data sta;
5673 ret = wpa_drv_pktcnt_poll(wpa_s, &sta);
5677 ret = os_snprintf(buf, buflen, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
5678 sta.tx_packets, sta.tx_retry_failed, sta.rx_packets);
5679 if (ret < 0 || (size_t) ret > buflen)
5686 static int wpa_supplicant_driver_cmd(struct wpa_supplicant *wpa_s, char *cmd,
5687 char *buf, size_t buflen)
5691 ret = wpa_drv_driver_cmd(wpa_s, cmd, buf, buflen);
5693 if (os_strncasecmp(cmd, "COUNTRY", 7) == 0) {
5694 struct p2p_data *p2p = wpa_s->global->p2p;
5697 country[0] = cmd[8];
5698 country[1] = cmd[9];
5700 p2p_set_country(p2p, country);
5703 ret = os_snprintf(buf, buflen, "%s\n", "OK");
5707 #endif /* ANDROID */
5710 static int wpa_supplicant_vendor_cmd(struct wpa_supplicant *wpa_s, char *cmd,
5711 char *buf, size_t buflen)
5716 unsigned int vendor_id, subcmd;
5717 struct wpabuf *reply;
5718 size_t data_len = 0;
5720 /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */
5721 vendor_id = strtoul(cmd, &pos, 16);
5725 subcmd = strtoul(pos, &pos, 10);
5728 if (!isblank(*pos++))
5730 data_len = os_strlen(pos);
5735 data = os_malloc(data_len);
5739 if (hexstr2bin(pos, data, data_len)) {
5740 wpa_printf(MSG_DEBUG,
5741 "Vendor command: wrong parameter format");
5747 reply = wpabuf_alloc((buflen - 1) / 2);
5753 ret = wpa_drv_vendor_cmd(wpa_s, vendor_id, subcmd, data, data_len,
5757 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(reply),
5767 static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s)
5769 wpa_dbg(wpa_s, MSG_DEBUG, "Flush all wpa_supplicant state");
5772 wpas_p2p_cancel(wpa_s);
5773 wpas_p2p_stop_find(wpa_s);
5774 p2p_ctrl_flush(wpa_s);
5775 wpas_p2p_group_remove(wpa_s, "*");
5776 wpas_p2p_service_flush(wpa_s);
5777 wpa_s->global->p2p_disabled = 0;
5778 wpa_s->global->p2p_per_sta_psk = 0;
5779 wpa_s->conf->num_sec_device_types = 0;
5780 wpa_s->p2p_disable_ip_addr_req = 0;
5781 os_free(wpa_s->global->p2p_go_avoid_freq.range);
5782 wpa_s->global->p2p_go_avoid_freq.range = NULL;
5783 #endif /* CONFIG_P2P */
5785 #ifdef CONFIG_WPS_TESTING
5786 wps_version_number = 0x20;
5787 wps_testing_dummy_cred = 0;
5788 wps_corrupt_pkhash = 0;
5789 #endif /* CONFIG_WPS_TESTING */
5791 wpa_s->wps_fragment_size = 0;
5792 wpas_wps_cancel(wpa_s);
5793 #endif /* CONFIG_WPS */
5794 wpa_s->after_wps = 0;
5795 wpa_s->known_wps_freq = 0;
5798 #ifdef CONFIG_TDLS_TESTING
5799 extern unsigned int tdls_testing;
5801 #endif /* CONFIG_TDLS_TESTING */
5802 wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL);
5803 wpa_tdls_enable(wpa_s->wpa, 1);
5804 #endif /* CONFIG_TDLS */
5806 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, wpa_s, NULL);
5807 wpa_supplicant_stop_countermeasures(wpa_s, NULL);
5809 wpa_s->no_keep_alive = 0;
5811 os_free(wpa_s->disallow_aps_bssid);
5812 wpa_s->disallow_aps_bssid = NULL;
5813 wpa_s->disallow_aps_bssid_count = 0;
5814 os_free(wpa_s->disallow_aps_ssid);
5815 wpa_s->disallow_aps_ssid = NULL;
5816 wpa_s->disallow_aps_ssid_count = 0;
5818 wpa_s->set_sta_uapsd = 0;
5819 wpa_s->sta_uapsd = 0;
5821 wpa_drv_radio_disable(wpa_s, 0);
5823 wpa_bss_flush(wpa_s);
5824 wpa_blacklist_clear(wpa_s);
5825 wpa_s->extra_blacklist_count = 0;
5826 wpa_supplicant_ctrl_iface_remove_network(wpa_s, "all");
5827 wpa_supplicant_ctrl_iface_remove_cred(wpa_s, "all");
5828 wpa_config_flush_blobs(wpa_s->conf);
5829 wpa_s->conf->auto_interworking = 0;
5830 wpa_s->conf->okc = 0;
5832 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, 43200);
5833 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, 70);
5834 wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, 60);
5835 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
5837 radio_remove_works(wpa_s, NULL, 1);
5839 wpa_s->next_ssid = NULL;
5841 #ifdef CONFIG_INTERWORKING
5842 hs20_cancel_fetch_osu(wpa_s);
5843 #endif /* CONFIG_INTERWORKING */
5845 wpa_s->ext_mgmt_frame_handling = 0;
5846 wpa_s->ext_eapol_frame_io = 0;
5847 #ifdef CONFIG_TESTING_OPTIONS
5848 wpa_s->extra_roc_dur = 0;
5849 #endif /* CONFIG_TESTING_OPTIONS */
5853 static int wpas_ctrl_radio_work_show(struct wpa_supplicant *wpa_s,
5854 char *buf, size_t buflen)
5856 struct wpa_radio_work *work;
5858 struct os_reltime now, diff;
5863 os_get_reltime(&now);
5865 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
5869 os_reltime_sub(&now, &work->time, &diff);
5870 ret = os_snprintf(pos, end - pos, "%s@%s:%u:%u:%ld.%06ld\n",
5871 work->type, work->wpa_s->ifname, work->freq,
5872 work->started, diff.sec, diff.usec);
5873 if (ret < 0 || ret >= end - pos)
5882 static void wpas_ctrl_radio_work_timeout(void *eloop_ctx, void *timeout_ctx)
5884 struct wpa_radio_work *work = eloop_ctx;
5885 struct wpa_external_work *ework = work->ctx;
5887 wpa_dbg(work->wpa_s, MSG_DEBUG,
5888 "Timing out external radio work %u (%s)",
5889 ework->id, work->type);
5890 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_TIMEOUT "%u", ework->id);
5891 radio_work_done(work);
5896 static void wpas_ctrl_radio_work_cb(struct wpa_radio_work *work, int deinit)
5898 struct wpa_external_work *ework = work->ctx;
5902 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
5909 wpa_dbg(work->wpa_s, MSG_DEBUG, "Starting external radio work %u (%s)",
5910 ework->id, ework->type);
5911 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_START "%u", ework->id);
5912 if (!ework->timeout)
5913 ework->timeout = 10;
5914 eloop_register_timeout(ework->timeout, 0, wpas_ctrl_radio_work_timeout,
5919 static int wpas_ctrl_radio_work_add(struct wpa_supplicant *wpa_s, char *cmd,
5920 char *buf, size_t buflen)
5922 struct wpa_external_work *ework;
5926 unsigned int freq = 0;
5928 /* format: <name> [freq=<MHz>] [timeout=<seconds>] */
5930 ework = os_zalloc(sizeof(*ework));
5934 pos = os_strchr(cmd, ' ');
5936 type_len = pos - cmd;
5939 pos2 = os_strstr(pos, "freq=");
5941 freq = atoi(pos2 + 5);
5943 pos2 = os_strstr(pos, "timeout=");
5945 ework->timeout = atoi(pos2 + 8);
5947 type_len = os_strlen(cmd);
5949 if (4 + type_len >= sizeof(ework->type))
5950 type_len = sizeof(ework->type) - 4 - 1;
5951 os_strlcpy(ework->type, "ext:", sizeof(ework->type));
5952 os_memcpy(ework->type + 4, cmd, type_len);
5953 ework->type[4 + type_len] = '\0';
5955 wpa_s->ext_work_id++;
5956 if (wpa_s->ext_work_id == 0)
5957 wpa_s->ext_work_id++;
5958 ework->id = wpa_s->ext_work_id;
5960 if (radio_add_work(wpa_s, freq, ework->type, 0, wpas_ctrl_radio_work_cb,
5966 ret = os_snprintf(buf, buflen, "%u", ework->id);
5967 if (ret < 0 || (size_t) ret >= buflen)
5973 static int wpas_ctrl_radio_work_done(struct wpa_supplicant *wpa_s, char *cmd)
5975 struct wpa_radio_work *work;
5976 unsigned int id = atoi(cmd);
5978 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
5980 struct wpa_external_work *ework;
5982 if (os_strncmp(work->type, "ext:", 4) != 0)
5985 if (id && ework->id != id)
5987 wpa_dbg(wpa_s, MSG_DEBUG,
5988 "Completed external radio work %u (%s)",
5989 ework->id, ework->type);
5990 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, work, NULL);
5991 radio_work_done(work);
5993 return 3; /* "OK\n" */
6000 static int wpas_ctrl_radio_work(struct wpa_supplicant *wpa_s, char *cmd,
6001 char *buf, size_t buflen)
6003 if (os_strcmp(cmd, "show") == 0)
6004 return wpas_ctrl_radio_work_show(wpa_s, buf, buflen);
6005 if (os_strncmp(cmd, "add ", 4) == 0)
6006 return wpas_ctrl_radio_work_add(wpa_s, cmd + 4, buf, buflen);
6007 if (os_strncmp(cmd, "done ", 5) == 0)
6008 return wpas_ctrl_radio_work_done(wpa_s, cmd + 4);
6013 void wpas_ctrl_radio_work_flush(struct wpa_supplicant *wpa_s)
6015 struct wpa_radio_work *work, *tmp;
6017 if (!wpa_s || !wpa_s->radio)
6020 dl_list_for_each_safe(work, tmp, &wpa_s->radio->work,
6021 struct wpa_radio_work, list) {
6022 struct wpa_external_work *ework;
6024 if (os_strncmp(work->type, "ext:", 4) != 0)
6027 wpa_dbg(wpa_s, MSG_DEBUG,
6028 "Flushing%s external radio work %u (%s)",
6029 work->started ? " started" : "", ework->id,
6032 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
6034 radio_work_done(work);
6040 static void wpas_ctrl_eapol_response(void *eloop_ctx, void *timeout_ctx)
6042 struct wpa_supplicant *wpa_s = eloop_ctx;
6043 eapol_sm_notify_ctrl_response(wpa_s->eapol);
6047 static int set_scan_freqs(struct wpa_supplicant *wpa_s, char *val)
6051 freqs = freq_range_to_channel_list(wpa_s, val);
6055 os_free(wpa_s->manual_scan_freqs);
6056 wpa_s->manual_scan_freqs = freqs;
6062 static int scan_id_list_parse(struct wpa_supplicant *wpa_s, const char *value)
6064 const char *pos = value;
6067 if (*pos == ' ' || *pos == '\0')
6069 if (wpa_s->scan_id_count == MAX_SCAN_ID)
6071 wpa_s->scan_id[wpa_s->scan_id_count++] = atoi(pos);
6072 pos = os_strchr(pos, ',');
6081 static void wpas_ctrl_scan(struct wpa_supplicant *wpa_s, char *params,
6082 char *reply, int reply_size, int *reply_len)
6086 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
6091 wpa_s->manual_scan_passive = 0;
6092 wpa_s->manual_scan_use_id = 0;
6093 wpa_s->manual_scan_only_new = 0;
6094 wpa_s->scan_id_count = 0;
6097 if (os_strncasecmp(params, "TYPE=ONLY", 9) == 0)
6098 wpa_s->scan_res_handler = scan_only_handler;
6100 pos = os_strstr(params, "freq=");
6101 if (pos && set_scan_freqs(wpa_s, pos + 5) < 0) {
6106 pos = os_strstr(params, "passive=");
6108 wpa_s->manual_scan_passive = !!atoi(pos + 8);
6110 pos = os_strstr(params, "use_id=");
6112 wpa_s->manual_scan_use_id = atoi(pos + 7);
6114 pos = os_strstr(params, "only_new=1");
6116 wpa_s->manual_scan_only_new = 1;
6118 pos = os_strstr(params, "scan_id=");
6119 if (pos && scan_id_list_parse(wpa_s, pos + 8) < 0) {
6124 os_free(wpa_s->manual_scan_freqs);
6125 wpa_s->manual_scan_freqs = NULL;
6126 if (wpa_s->scan_res_handler == scan_only_handler)
6127 wpa_s->scan_res_handler = NULL;
6130 if (!wpa_s->sched_scanning && !wpa_s->scanning &&
6131 ((wpa_s->wpa_state <= WPA_SCANNING) ||
6132 (wpa_s->wpa_state == WPA_COMPLETED))) {
6133 wpa_s->normal_scans = 0;
6134 wpa_s->scan_req = MANUAL_SCAN_REQ;
6135 wpa_s->after_wps = 0;
6136 wpa_s->known_wps_freq = 0;
6137 wpa_supplicant_req_scan(wpa_s, 0, 0);
6138 if (wpa_s->manual_scan_use_id) {
6139 wpa_s->manual_scan_id++;
6140 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
6141 wpa_s->manual_scan_id);
6142 *reply_len = os_snprintf(reply, reply_size, "%u\n",
6143 wpa_s->manual_scan_id);
6145 } else if (wpa_s->sched_scanning) {
6146 wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to allow requested full scan to proceed");
6147 wpa_supplicant_cancel_sched_scan(wpa_s);
6148 wpa_s->scan_req = MANUAL_SCAN_REQ;
6149 wpa_supplicant_req_scan(wpa_s, 0, 0);
6150 if (wpa_s->manual_scan_use_id) {
6151 wpa_s->manual_scan_id++;
6152 *reply_len = os_snprintf(reply, reply_size, "%u\n",
6153 wpa_s->manual_scan_id);
6154 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
6155 wpa_s->manual_scan_id);
6158 wpa_printf(MSG_DEBUG, "Ongoing scan action - reject new request");
6159 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
6164 #ifdef CONFIG_TESTING_OPTIONS
6166 static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant *wpa_s,
6167 unsigned int freq, const u8 *dst,
6168 const u8 *src, const u8 *bssid,
6169 const u8 *data, size_t data_len,
6170 enum offchannel_send_action_result
6173 wpa_msg(wpa_s, MSG_INFO, "MGMT-TX-STATUS freq=%u dst=" MACSTR
6174 " src=" MACSTR " bssid=" MACSTR " result=%s",
6175 freq, MAC2STR(dst), MAC2STR(src), MAC2STR(bssid),
6176 result == OFFCHANNEL_SEND_ACTION_SUCCESS ?
6177 "SUCCESS" : (result == OFFCHANNEL_SEND_ACTION_NO_ACK ?
6178 "NO_ACK" : "FAILED"));
6182 static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant *wpa_s, char *cmd)
6186 u8 *buf, da[ETH_ALEN], bssid[ETH_ALEN];
6188 int freq = 0, no_cck = 0, wait_time = 0;
6190 /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1]
6191 * <action=Action frame payload> */
6193 wpa_printf(MSG_DEBUG, "External MGMT TX: %s", cmd);
6196 used = hwaddr_aton2(pos, da);
6202 used = hwaddr_aton2(pos, bssid);
6207 param = os_strstr(pos, " freq=");
6213 param = os_strstr(pos, " no_cck=");
6216 no_cck = atoi(param);
6219 param = os_strstr(pos, " wait_time=");
6222 wait_time = atoi(param);
6225 param = os_strstr(pos, " action=");
6230 len = os_strlen(param);
6235 buf = os_malloc(len);
6239 if (hexstr2bin(param, buf, len) < 0) {
6244 res = offchannel_send_action(wpa_s, freq, da, wpa_s->own_addr, bssid,
6245 buf, len, wait_time,
6246 wpas_ctrl_iface_mgmt_tx_cb, no_cck);
6252 static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant *wpa_s)
6254 wpa_printf(MSG_DEBUG, "External MGMT TX - done waiting");
6255 offchannel_send_action_done(wpa_s);
6259 static int wpas_ctrl_iface_driver_event(struct wpa_supplicant *wpa_s, char *cmd)
6262 union wpa_event_data event;
6263 enum wpa_event_type ev;
6265 /* <event name> [parameters..] */
6267 wpa_dbg(wpa_s, MSG_DEBUG, "Testing - external driver event: %s", cmd);
6270 param = os_strchr(pos, ' ');
6274 os_memset(&event, 0, sizeof(event));
6276 if (os_strcmp(cmd, "INTERFACE_ENABLED") == 0) {
6277 ev = EVENT_INTERFACE_ENABLED;
6278 } else if (os_strcmp(cmd, "INTERFACE_DISABLED") == 0) {
6279 ev = EVENT_INTERFACE_DISABLED;
6280 } else if (os_strcmp(cmd, "AVOID_FREQUENCIES") == 0) {
6281 ev = EVENT_AVOID_FREQUENCIES;
6284 if (freq_range_list_parse(&event.freq_range, param) < 0)
6286 wpa_supplicant_event(wpa_s, ev, &event);
6287 os_free(event.freq_range.range);
6290 wpa_dbg(wpa_s, MSG_DEBUG, "Testing - unknown driver event: %s",
6295 wpa_supplicant_event(wpa_s, ev, &event);
6301 static int wpas_ctrl_iface_eapol_rx(struct wpa_supplicant *wpa_s, char *cmd)
6304 u8 src[ETH_ALEN], *buf;
6308 wpa_printf(MSG_DEBUG, "External EAPOL RX: %s", cmd);
6311 used = hwaddr_aton2(pos, src);
6318 len = os_strlen(pos);
6323 buf = os_malloc(len);
6327 if (hexstr2bin(pos, buf, len) < 0) {
6332 wpa_supplicant_rx_eapol(wpa_s, src, buf, len);
6339 static u16 ipv4_hdr_checksum(const void *buf, size_t len)
6343 const u16 *pos = buf;
6345 for (i = 0; i < len / 2; i++)
6349 sum = (sum & 0xffff) + (sum >> 16);
6351 return sum ^ 0xffff;
6355 #define HWSIM_PACKETLEN 1500
6356 #define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header))
6358 void wpas_data_test_rx(void *ctx, const u8 *src_addr, const u8 *buf, size_t len)
6360 struct wpa_supplicant *wpa_s = ctx;
6361 const struct ether_header *eth;
6362 const struct iphdr *ip;
6366 if (len != HWSIM_PACKETLEN)
6369 eth = (const struct ether_header *) buf;
6370 ip = (const struct iphdr *) (eth + 1);
6371 pos = (const u8 *) (ip + 1);
6373 if (ip->ihl != 5 || ip->version != 4 ||
6374 ntohs(ip->tot_len) != HWSIM_IP_LEN)
6377 for (i = 0; i < HWSIM_IP_LEN - sizeof(*ip); i++) {
6383 wpa_msg(wpa_s, MSG_INFO, "DATA-TEST-RX " MACSTR " " MACSTR,
6384 MAC2STR(eth->ether_dhost), MAC2STR(eth->ether_shost));
6388 static int wpas_ctrl_iface_data_test_config(struct wpa_supplicant *wpa_s,
6391 int enabled = atoi(cmd);
6394 if (wpa_s->l2_test) {
6395 l2_packet_deinit(wpa_s->l2_test);
6396 wpa_s->l2_test = NULL;
6397 wpa_dbg(wpa_s, MSG_DEBUG, "test data: Disabled");
6405 wpa_s->l2_test = l2_packet_init(wpa_s->ifname, wpa_s->own_addr,
6406 ETHERTYPE_IP, wpas_data_test_rx,
6408 if (wpa_s->l2_test == NULL)
6411 wpa_dbg(wpa_s, MSG_DEBUG, "test data: Enabled");
6417 static int wpas_ctrl_iface_data_test_tx(struct wpa_supplicant *wpa_s, char *cmd)
6419 u8 dst[ETH_ALEN], src[ETH_ALEN];
6424 u8 buf[HWSIM_PACKETLEN];
6425 struct ether_header *eth;
6430 if (wpa_s->l2_test == NULL)
6433 /* format: <dst> <src> <tos> */
6436 used = hwaddr_aton2(pos, dst);
6442 used = hwaddr_aton2(pos, src);
6447 val = strtol(pos, NULL, 0);
6448 if (val < 0 || val > 0xff)
6452 eth = (struct ether_header *) buf;
6453 os_memcpy(eth->ether_dhost, dst, ETH_ALEN);
6454 os_memcpy(eth->ether_shost, src, ETH_ALEN);
6455 eth->ether_type = htons(ETHERTYPE_IP);
6456 ip = (struct iphdr *) (eth + 1);
6457 os_memset(ip, 0, sizeof(*ip));
6462 ip->tot_len = htons(HWSIM_IP_LEN);
6464 ip->saddr = htonl(192 << 24 | 168 << 16 | 1 << 8 | 1);
6465 ip->daddr = htonl(192 << 24 | 168 << 16 | 1 << 8 | 2);
6466 ip->check = ipv4_hdr_checksum(ip, sizeof(*ip));
6467 dpos = (u8 *) (ip + 1);
6468 for (i = 0; i < HWSIM_IP_LEN - sizeof(*ip); i++)
6471 if (l2_packet_send(wpa_s->l2_test, dst, ETHERTYPE_IP, buf,
6472 HWSIM_PACKETLEN) < 0)
6475 wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX dst=" MACSTR " src=" MACSTR
6476 " tos=0x%x", MAC2STR(dst), MAC2STR(src), tos);
6481 #endif /* CONFIG_TESTING_OPTIONS */
6484 static void wpas_ctrl_vendor_elem_update(struct wpa_supplicant *wpa_s)
6489 wpa_printf(MSG_DEBUG, "Update vendor elements");
6491 for (i = 0; i < NUM_VENDOR_ELEM_FRAMES; i++) {
6492 if (wpa_s->vendor_elem[i]) {
6493 os_snprintf(buf, sizeof(buf), "frame[%u]", i);
6494 wpa_hexdump_buf(MSG_DEBUG, buf, wpa_s->vendor_elem[i]);
6499 if (wpa_s->parent == wpa_s &&
6500 wpa_s->global->p2p &&
6501 !wpa_s->global->p2p_disabled)
6502 p2p_set_vendor_elems(wpa_s->global->p2p, wpa_s->vendor_elem);
6503 #endif /* CONFIG_P2P */
6507 static struct wpa_supplicant *
6508 wpas_ctrl_vendor_elem_iface(struct wpa_supplicant *wpa_s,
6509 enum wpa_vendor_elem_frame frame)
6513 case VENDOR_ELEM_PROBE_REQ_P2P:
6514 case VENDOR_ELEM_PROBE_RESP_P2P:
6515 case VENDOR_ELEM_PROBE_RESP_P2P_GO:
6516 case VENDOR_ELEM_BEACON_P2P_GO:
6517 case VENDOR_ELEM_P2P_PD_REQ:
6518 case VENDOR_ELEM_P2P_PD_RESP:
6519 case VENDOR_ELEM_P2P_GO_NEG_REQ:
6520 case VENDOR_ELEM_P2P_GO_NEG_RESP:
6521 case VENDOR_ELEM_P2P_GO_NEG_CONF:
6522 case VENDOR_ELEM_P2P_INV_REQ:
6523 case VENDOR_ELEM_P2P_INV_RESP:
6524 case VENDOR_ELEM_P2P_ASSOC_REQ:
6525 return wpa_s->parent;
6526 #endif /* CONFIG_P2P */
6533 static int wpas_ctrl_vendor_elem_add(struct wpa_supplicant *wpa_s, char *cmd)
6539 struct ieee802_11_elems elems;
6542 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
6544 wpa_s = wpas_ctrl_vendor_elem_iface(wpa_s, frame);
6546 pos = os_strchr(pos, ' ');
6551 len = os_strlen(pos);
6558 buf = wpabuf_alloc(len);
6562 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
6567 if (ieee802_11_parse_elems(wpabuf_head_u8(buf), len, &elems, 0) ==
6573 if (wpa_s->vendor_elem[frame] == NULL) {
6574 wpa_s->vendor_elem[frame] = buf;
6575 wpas_ctrl_vendor_elem_update(wpa_s);
6579 if (wpabuf_resize(&wpa_s->vendor_elem[frame], len) < 0) {
6584 wpabuf_put_buf(wpa_s->vendor_elem[frame], buf);
6586 wpas_ctrl_vendor_elem_update(wpa_s);
6592 static int wpas_ctrl_vendor_elem_get(struct wpa_supplicant *wpa_s, char *cmd,
6593 char *buf, size_t buflen)
6595 int frame = atoi(cmd);
6597 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
6599 wpa_s = wpas_ctrl_vendor_elem_iface(wpa_s, frame);
6601 if (wpa_s->vendor_elem[frame] == NULL)
6604 return wpa_snprintf_hex(buf, buflen,
6605 wpabuf_head_u8(wpa_s->vendor_elem[frame]),
6606 wpabuf_len(wpa_s->vendor_elem[frame]));
6610 static int wpas_ctrl_vendor_elem_remove(struct wpa_supplicant *wpa_s, char *cmd)
6616 struct ieee802_11_elems elems;
6620 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
6622 wpa_s = wpas_ctrl_vendor_elem_iface(wpa_s, frame);
6624 pos = os_strchr(pos, ' ');
6630 wpabuf_free(wpa_s->vendor_elem[frame]);
6631 wpa_s->vendor_elem[frame] = NULL;
6632 wpas_ctrl_vendor_elem_update(wpa_s);
6636 if (wpa_s->vendor_elem[frame] == NULL)
6639 len = os_strlen(pos);
6646 buf = os_malloc(len);
6650 if (hexstr2bin(pos, buf, len) < 0) {
6655 if (ieee802_11_parse_elems(buf, len, &elems, 0) == ParseFailed) {
6660 ie = wpabuf_mhead_u8(wpa_s->vendor_elem[frame]);
6661 end = ie + wpabuf_len(wpa_s->vendor_elem[frame]);
6663 for (; ie + 1 < end; ie += 2 + ie[1]) {
6666 if (os_memcmp(ie, buf, len) != 0)
6669 if (wpabuf_len(wpa_s->vendor_elem[frame]) == len) {
6670 wpabuf_free(wpa_s->vendor_elem[frame]);
6671 wpa_s->vendor_elem[frame] = NULL;
6673 os_memmove(ie, ie + len,
6675 wpa_s->vendor_elem[frame]->used -= len;
6678 wpas_ctrl_vendor_elem_update(wpa_s);
6688 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
6689 char *buf, size_t *resp_len)
6692 const int reply_size = 4096;
6695 if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 ||
6696 os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
6697 if (wpa_debug_show_keys)
6698 wpa_dbg(wpa_s, MSG_DEBUG,
6699 "Control interface command '%s'", buf);
6701 wpa_dbg(wpa_s, MSG_DEBUG,
6702 "Control interface command '%s [REMOVED]'",
6703 os_strncmp(buf, WPA_CTRL_RSP,
6704 os_strlen(WPA_CTRL_RSP)) == 0 ?
6705 WPA_CTRL_RSP : "SET_NETWORK");
6706 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ", 16) == 0 ||
6707 os_strncmp(buf, "NFC_REPORT_HANDOVER", 19) == 0) {
6708 wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface",
6709 (const u8 *) buf, os_strlen(buf));
6711 int level = MSG_DEBUG;
6712 if (os_strcmp(buf, "PING") == 0)
6713 level = MSG_EXCESSIVE;
6714 wpa_dbg(wpa_s, level, "Control interface command '%s'", buf);
6717 reply = os_malloc(reply_size);
6718 if (reply == NULL) {
6723 os_memcpy(reply, "OK\n", 3);
6726 if (os_strcmp(buf, "PING") == 0) {
6727 os_memcpy(reply, "PONG\n", 5);
6729 } else if (os_strcmp(buf, "IFNAME") == 0) {
6730 reply_len = os_strlen(wpa_s->ifname);
6731 os_memcpy(reply, wpa_s->ifname, reply_len);
6732 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
6733 if (wpa_debug_reopen_file() < 0)
6735 } else if (os_strncmp(buf, "NOTE ", 5) == 0) {
6736 wpa_printf(MSG_INFO, "NOTE: %s", buf + 5);
6737 } else if (os_strcmp(buf, "MIB") == 0) {
6738 reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size);
6739 if (reply_len >= 0) {
6741 res = eapol_sm_get_mib(wpa_s->eapol, reply + reply_len,
6742 reply_size - reply_len);
6748 } else if (os_strncmp(buf, "STATUS", 6) == 0) {
6749 reply_len = wpa_supplicant_ctrl_iface_status(
6750 wpa_s, buf + 6, reply, reply_size);
6751 } else if (os_strcmp(buf, "PMKSA") == 0) {
6752 reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, reply,
6754 } else if (os_strcmp(buf, "PMKSA_FLUSH") == 0) {
6755 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
6756 } else if (os_strncmp(buf, "SET ", 4) == 0) {
6757 if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4))
6759 } else if (os_strncmp(buf, "GET ", 4) == 0) {
6760 reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4,
6762 } else if (os_strcmp(buf, "LOGON") == 0) {
6763 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
6764 } else if (os_strcmp(buf, "LOGOFF") == 0) {
6765 eapol_sm_notify_logoff(wpa_s->eapol, TRUE);
6766 } else if (os_strcmp(buf, "REASSOCIATE") == 0) {
6767 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
6770 wpas_request_connection(wpa_s);
6771 } else if (os_strcmp(buf, "REATTACH") == 0) {
6772 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED ||
6773 !wpa_s->current_ssid)
6776 wpa_s->reattach = 1;
6777 wpas_request_connection(wpa_s);
6779 } else if (os_strcmp(buf, "RECONNECT") == 0) {
6780 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
6782 else if (wpa_s->disconnected)
6783 wpas_request_connection(wpa_s);
6784 #ifdef IEEE8021X_EAPOL
6785 } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) {
6786 if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8))
6788 #endif /* IEEE8021X_EAPOL */
6789 #ifdef CONFIG_PEERKEY
6790 } else if (os_strncmp(buf, "STKSTART ", 9) == 0) {
6791 if (wpa_supplicant_ctrl_iface_stkstart(wpa_s, buf + 9))
6793 #endif /* CONFIG_PEERKEY */
6794 #ifdef CONFIG_IEEE80211R
6795 } else if (os_strncmp(buf, "FT_DS ", 6) == 0) {
6796 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6))
6798 #endif /* CONFIG_IEEE80211R */
6800 } else if (os_strcmp(buf, "WPS_PBC") == 0) {
6801 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL);
6803 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
6807 } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) {
6808 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8);
6810 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
6814 } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {
6815 reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8,
6818 } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) {
6819 reply_len = wpa_supplicant_ctrl_iface_wps_check_pin(
6820 wpa_s, buf + 14, reply, reply_size);
6821 } else if (os_strcmp(buf, "WPS_CANCEL") == 0) {
6822 if (wpas_wps_cancel(wpa_s))
6824 #ifdef CONFIG_WPS_NFC
6825 } else if (os_strcmp(buf, "WPS_NFC") == 0) {
6826 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, NULL))
6828 } else if (os_strncmp(buf, "WPS_NFC ", 8) == 0) {
6829 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, buf + 8))
6831 } else if (os_strncmp(buf, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
6832 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_config_token(
6833 wpa_s, buf + 21, reply, reply_size);
6834 } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) {
6835 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_token(
6836 wpa_s, buf + 14, reply, reply_size);
6837 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) {
6838 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s,
6841 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
6842 reply_len = wpas_ctrl_nfc_get_handover_req(
6843 wpa_s, buf + 21, reply, reply_size);
6844 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
6845 reply_len = wpas_ctrl_nfc_get_handover_sel(
6846 wpa_s, buf + 21, reply, reply_size);
6847 } else if (os_strncmp(buf, "NFC_REPORT_HANDOVER ", 20) == 0) {
6848 if (wpas_ctrl_nfc_report_handover(wpa_s, buf + 20))
6850 #endif /* CONFIG_WPS_NFC */
6851 } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) {
6852 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8))
6855 } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) {
6856 reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin(
6857 wpa_s, buf + 11, reply, reply_size);
6858 #endif /* CONFIG_AP */
6859 #ifdef CONFIG_WPS_ER
6860 } else if (os_strcmp(buf, "WPS_ER_START") == 0) {
6861 if (wpas_wps_er_start(wpa_s, NULL))
6863 } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) {
6864 if (wpas_wps_er_start(wpa_s, buf + 13))
6866 } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) {
6867 if (wpas_wps_er_stop(wpa_s))
6869 } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) {
6870 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11))
6872 } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) {
6873 int ret = wpas_wps_er_pbc(wpa_s, buf + 11);
6875 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
6877 } else if (ret == -3) {
6878 os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18);
6880 } else if (ret == -4) {
6881 os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20);
6885 } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) {
6886 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13))
6888 } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) {
6889 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s,
6892 } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) {
6893 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14))
6895 #ifdef CONFIG_WPS_NFC
6896 } else if (os_strncmp(buf, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
6897 reply_len = wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
6898 wpa_s, buf + 24, reply, reply_size);
6899 #endif /* CONFIG_WPS_NFC */
6900 #endif /* CONFIG_WPS_ER */
6901 #endif /* CONFIG_WPS */
6902 #ifdef CONFIG_IBSS_RSN
6903 } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) {
6904 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9))
6906 #endif /* CONFIG_IBSS_RSN */
6908 } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) {
6909 if (p2p_ctrl_find(wpa_s, buf + 9))
6911 } else if (os_strcmp(buf, "P2P_FIND") == 0) {
6912 if (p2p_ctrl_find(wpa_s, ""))
6914 } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) {
6915 wpas_p2p_stop_find(wpa_s);
6916 } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) {
6917 reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply,
6919 } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) {
6920 if (p2p_ctrl_listen(wpa_s, buf + 11))
6922 } else if (os_strcmp(buf, "P2P_LISTEN") == 0) {
6923 if (p2p_ctrl_listen(wpa_s, ""))
6925 } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) {
6926 if (wpas_p2p_group_remove(wpa_s, buf + 17))
6928 } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) {
6929 if (wpas_p2p_group_add(wpa_s, 0, 0, 0, 0))
6931 } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) {
6932 if (p2p_ctrl_group_add(wpa_s, buf + 14))
6934 } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) {
6935 if (p2p_ctrl_prov_disc(wpa_s, buf + 14))
6937 } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) {
6938 reply_len = p2p_get_passphrase(wpa_s, reply, reply_size);
6939 } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) {
6940 reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply,
6942 } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
6943 if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0)
6945 } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) {
6946 if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0)
6948 } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) {
6949 wpas_p2p_sd_service_update(wpa_s);
6950 } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
6951 if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0)
6953 } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) {
6954 wpas_p2p_service_flush(wpa_s);
6955 } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) {
6956 if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0)
6958 } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) {
6959 if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0)
6961 } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) {
6962 if (p2p_ctrl_reject(wpa_s, buf + 11) < 0)
6964 } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) {
6965 if (p2p_ctrl_invite(wpa_s, buf + 11) < 0)
6967 } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) {
6968 reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply,
6970 } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) {
6971 if (p2p_ctrl_set(wpa_s, buf + 8) < 0)
6973 } else if (os_strcmp(buf, "P2P_FLUSH") == 0) {
6974 p2p_ctrl_flush(wpa_s);
6975 } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) {
6976 if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0)
6978 } else if (os_strcmp(buf, "P2P_CANCEL") == 0) {
6979 if (wpas_p2p_cancel(wpa_s))
6981 } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) {
6982 if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0)
6984 } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) {
6985 if (p2p_ctrl_presence_req(wpa_s, "") < 0)
6987 } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) {
6988 if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0)
6990 } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) {
6991 if (p2p_ctrl_ext_listen(wpa_s, "") < 0)
6993 } else if (os_strncmp(buf, "P2P_REMOVE_CLIENT ", 18) == 0) {
6994 if (p2p_ctrl_remove_client(wpa_s, buf + 18) < 0)
6996 #endif /* CONFIG_P2P */
6997 #ifdef CONFIG_WIFI_DISPLAY
6998 } else if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0) {
6999 if (wifi_display_subelem_set(wpa_s->global, buf + 16) < 0)
7001 } else if (os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) {
7002 reply_len = wifi_display_subelem_get(wpa_s->global, buf + 16,
7004 #endif /* CONFIG_WIFI_DISPLAY */
7005 #ifdef CONFIG_INTERWORKING
7006 } else if (os_strcmp(buf, "FETCH_ANQP") == 0) {
7007 if (interworking_fetch_anqp(wpa_s) < 0)
7009 } else if (os_strcmp(buf, "STOP_FETCH_ANQP") == 0) {
7010 interworking_stop_fetch_anqp(wpa_s);
7011 } else if (os_strcmp(buf, "INTERWORKING_SELECT") == 0) {
7012 if (ctrl_interworking_select(wpa_s, NULL) < 0)
7014 } else if (os_strncmp(buf, "INTERWORKING_SELECT ", 20) == 0) {
7015 if (ctrl_interworking_select(wpa_s, buf + 20) < 0)
7017 } else if (os_strncmp(buf, "INTERWORKING_CONNECT ", 21) == 0) {
7018 if (ctrl_interworking_connect(wpa_s, buf + 21) < 0)
7020 } else if (os_strncmp(buf, "ANQP_GET ", 9) == 0) {
7021 if (get_anqp(wpa_s, buf + 9) < 0)
7023 } else if (os_strncmp(buf, "GAS_REQUEST ", 12) == 0) {
7024 if (gas_request(wpa_s, buf + 12) < 0)
7026 } else if (os_strncmp(buf, "GAS_RESPONSE_GET ", 17) == 0) {
7027 reply_len = gas_response_get(wpa_s, buf + 17, reply,
7029 #endif /* CONFIG_INTERWORKING */
7031 } else if (os_strncmp(buf, "HS20_ANQP_GET ", 14) == 0) {
7032 if (get_hs20_anqp(wpa_s, buf + 14) < 0)
7034 } else if (os_strncmp(buf, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
7035 if (hs20_get_nai_home_realm_list(wpa_s, buf + 29) < 0)
7037 } else if (os_strncmp(buf, "HS20_ICON_REQUEST ", 18) == 0) {
7038 if (hs20_icon_request(wpa_s, buf + 18) < 0)
7040 } else if (os_strcmp(buf, "FETCH_OSU") == 0) {
7041 if (hs20_fetch_osu(wpa_s) < 0)
7043 } else if (os_strcmp(buf, "CANCEL_FETCH_OSU") == 0) {
7044 hs20_cancel_fetch_osu(wpa_s);
7045 #endif /* CONFIG_HS20 */
7046 } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0)
7048 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
7049 wpa_s, buf + os_strlen(WPA_CTRL_RSP)))
7053 * Notify response from timeout to allow the control
7054 * interface response to be sent first.
7056 eloop_register_timeout(0, 0, wpas_ctrl_eapol_response,
7059 } else if (os_strcmp(buf, "RECONFIGURE") == 0) {
7060 if (wpa_supplicant_reload_configuration(wpa_s))
7062 } else if (os_strcmp(buf, "TERMINATE") == 0) {
7063 wpa_supplicant_terminate_proc(wpa_s->global);
7064 } else if (os_strncmp(buf, "BSSID ", 6) == 0) {
7065 if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6))
7067 } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) {
7068 reply_len = wpa_supplicant_ctrl_iface_blacklist(
7069 wpa_s, buf + 9, reply, reply_size);
7070 } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) {
7071 reply_len = wpa_supplicant_ctrl_iface_log_level(
7072 wpa_s, buf + 9, reply, reply_size);
7073 } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) {
7074 reply_len = wpa_supplicant_ctrl_iface_list_networks(
7075 wpa_s, reply, reply_size);
7076 } else if (os_strcmp(buf, "DISCONNECT") == 0) {
7078 wpa_s->sme.prev_bssid_set = 0;
7079 #endif /* CONFIG_SME */
7080 wpa_s->reassociate = 0;
7081 wpa_s->disconnected = 1;
7082 wpa_supplicant_cancel_sched_scan(wpa_s);
7083 wpa_supplicant_cancel_scan(wpa_s);
7084 wpa_supplicant_deauthenticate(wpa_s,
7085 WLAN_REASON_DEAUTH_LEAVING);
7086 } else if (os_strcmp(buf, "SCAN") == 0) {
7087 wpas_ctrl_scan(wpa_s, NULL, reply, reply_size, &reply_len);
7088 } else if (os_strncmp(buf, "SCAN ", 5) == 0) {
7089 wpas_ctrl_scan(wpa_s, buf + 5, reply, reply_size, &reply_len);
7090 } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) {
7091 reply_len = wpa_supplicant_ctrl_iface_scan_results(
7092 wpa_s, reply, reply_size);
7093 } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) {
7094 if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15))
7096 } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) {
7097 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15))
7099 } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) {
7100 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16))
7102 } else if (os_strcmp(buf, "ADD_NETWORK") == 0) {
7103 reply_len = wpa_supplicant_ctrl_iface_add_network(
7104 wpa_s, reply, reply_size);
7105 } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) {
7106 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15))
7108 } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
7109 if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12))
7111 } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) {
7112 reply_len = wpa_supplicant_ctrl_iface_get_network(
7113 wpa_s, buf + 12, reply, reply_size);
7114 } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) {
7115 if (wpa_supplicant_ctrl_iface_dup_network(wpa_s, buf + 12))
7117 } else if (os_strcmp(buf, "LIST_CREDS") == 0) {
7118 reply_len = wpa_supplicant_ctrl_iface_list_creds(
7119 wpa_s, reply, reply_size);
7120 } else if (os_strcmp(buf, "ADD_CRED") == 0) {
7121 reply_len = wpa_supplicant_ctrl_iface_add_cred(
7122 wpa_s, reply, reply_size);
7123 } else if (os_strncmp(buf, "REMOVE_CRED ", 12) == 0) {
7124 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s, buf + 12))
7126 } else if (os_strncmp(buf, "SET_CRED ", 9) == 0) {
7127 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s, buf + 9))
7129 } else if (os_strncmp(buf, "GET_CRED ", 9) == 0) {
7130 reply_len = wpa_supplicant_ctrl_iface_get_cred(wpa_s, buf + 9,
7133 #ifndef CONFIG_NO_CONFIG_WRITE
7134 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
7135 if (wpa_supplicant_ctrl_iface_save_config(wpa_s))
7137 #endif /* CONFIG_NO_CONFIG_WRITE */
7138 } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
7139 reply_len = wpa_supplicant_ctrl_iface_get_capability(
7140 wpa_s, buf + 15, reply, reply_size);
7141 } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) {
7142 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8))
7144 } else if (os_strncmp(buf, "SCAN_INTERVAL ", 14) == 0) {
7145 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s, buf + 14))
7147 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
7148 reply_len = wpa_supplicant_global_iface_list(
7149 wpa_s->global, reply, reply_size);
7150 } else if (os_strcmp(buf, "INTERFACES") == 0) {
7151 reply_len = wpa_supplicant_global_iface_interfaces(
7152 wpa_s->global, reply, reply_size);
7153 } else if (os_strncmp(buf, "BSS ", 4) == 0) {
7154 reply_len = wpa_supplicant_ctrl_iface_bss(
7155 wpa_s, buf + 4, reply, reply_size);
7157 } else if (os_strcmp(buf, "STA-FIRST") == 0) {
7158 reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size);
7159 } else if (os_strncmp(buf, "STA ", 4) == 0) {
7160 reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply,
7162 } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) {
7163 reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply,
7165 } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) {
7166 if (ap_ctrl_iface_sta_deauthenticate(wpa_s, buf + 15))
7168 } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) {
7169 if (ap_ctrl_iface_sta_disassociate(wpa_s, buf + 13))
7171 } else if (os_strncmp(buf, "CHAN_SWITCH ", 12) == 0) {
7172 if (ap_ctrl_iface_chanswitch(wpa_s, buf + 12))
7174 #endif /* CONFIG_AP */
7175 } else if (os_strcmp(buf, "SUSPEND") == 0) {
7176 wpas_notify_suspend(wpa_s->global);
7177 } else if (os_strcmp(buf, "RESUME") == 0) {
7178 wpas_notify_resume(wpa_s->global);
7179 #ifdef CONFIG_TESTING_OPTIONS
7180 } else if (os_strcmp(buf, "DROP_SA") == 0) {
7181 wpa_supplicant_ctrl_iface_drop_sa(wpa_s);
7182 #endif /* CONFIG_TESTING_OPTIONS */
7183 } else if (os_strncmp(buf, "ROAM ", 5) == 0) {
7184 if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5))
7186 } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) {
7187 if (wpa_supplicant_ctrl_iface_sta_autoconnect(wpa_s, buf + 16))
7189 } else if (os_strncmp(buf, "BSS_EXPIRE_AGE ", 15) == 0) {
7190 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s, buf + 15))
7192 } else if (os_strncmp(buf, "BSS_EXPIRE_COUNT ", 17) == 0) {
7193 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s,
7196 } else if (os_strncmp(buf, "BSS_FLUSH ", 10) == 0) {
7197 if (wpa_supplicant_ctrl_iface_bss_flush(wpa_s, buf + 10))
7200 } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) {
7201 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14))
7203 } else if (os_strncmp(buf, "TDLS_SETUP ", 11) == 0) {
7204 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s, buf + 11))
7206 } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) {
7207 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14))
7209 #endif /* CONFIG_TDLS */
7210 } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) {
7211 reply_len = wpa_supplicant_signal_poll(wpa_s, reply,
7213 } else if (os_strncmp(buf, "PKTCNT_POLL", 11) == 0) {
7214 reply_len = wpa_supplicant_pktcnt_poll(wpa_s, reply,
7216 #ifdef CONFIG_AUTOSCAN
7217 } else if (os_strncmp(buf, "AUTOSCAN ", 9) == 0) {
7218 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s, buf + 9))
7220 #endif /* CONFIG_AUTOSCAN */
7222 } else if (os_strncmp(buf, "DRIVER ", 7) == 0) {
7223 reply_len = wpa_supplicant_driver_cmd(wpa_s, buf + 7, reply,
7225 #endif /* ANDROID */
7226 } else if (os_strncmp(buf, "VENDOR ", 7) == 0) {
7227 reply_len = wpa_supplicant_vendor_cmd(wpa_s, buf + 7, reply,
7229 } else if (os_strcmp(buf, "REAUTHENTICATE") == 0) {
7230 pmksa_cache_clear_current(wpa_s->wpa);
7231 eapol_sm_request_reauth(wpa_s->eapol);
7233 } else if (os_strncmp(buf, "WNM_SLEEP ", 10) == 0) {
7234 if (wpas_ctrl_iface_wnm_sleep(wpa_s, buf + 10))
7236 } else if (os_strncmp(buf, "WNM_BSS_QUERY ", 10) == 0) {
7237 if (wpas_ctrl_iface_wnm_bss_query(wpa_s, buf + 10))
7239 #endif /* CONFIG_WNM */
7240 } else if (os_strcmp(buf, "FLUSH") == 0) {
7241 wpa_supplicant_ctrl_iface_flush(wpa_s);
7242 } else if (os_strncmp(buf, "RADIO_WORK ", 11) == 0) {
7243 reply_len = wpas_ctrl_radio_work(wpa_s, buf + 11, reply,
7245 #ifdef CONFIG_TESTING_OPTIONS
7246 } else if (os_strncmp(buf, "MGMT_TX ", 8) == 0) {
7247 if (wpas_ctrl_iface_mgmt_tx(wpa_s, buf + 8) < 0)
7249 } else if (os_strcmp(buf, "MGMT_TX_DONE") == 0) {
7250 wpas_ctrl_iface_mgmt_tx_done(wpa_s);
7251 } else if (os_strncmp(buf, "DRIVER_EVENT ", 13) == 0) {
7252 if (wpas_ctrl_iface_driver_event(wpa_s, buf + 13) < 0)
7254 } else if (os_strncmp(buf, "EAPOL_RX ", 9) == 0) {
7255 if (wpas_ctrl_iface_eapol_rx(wpa_s, buf + 9) < 0)
7257 } else if (os_strncmp(buf, "DATA_TEST_CONFIG ", 17) == 0) {
7258 if (wpas_ctrl_iface_data_test_config(wpa_s, buf + 17) < 0)
7260 } else if (os_strncmp(buf, "DATA_TEST_TX ", 13) == 0) {
7261 if (wpas_ctrl_iface_data_test_tx(wpa_s, buf + 13) < 0)
7263 #endif /* CONFIG_TESTING_OPTIONS */
7264 } else if (os_strncmp(buf, "VENDOR_ELEM_ADD ", 16) == 0) {
7265 if (wpas_ctrl_vendor_elem_add(wpa_s, buf + 16) < 0)
7267 } else if (os_strncmp(buf, "VENDOR_ELEM_GET ", 16) == 0) {
7268 reply_len = wpas_ctrl_vendor_elem_get(wpa_s, buf + 16, reply,
7270 } else if (os_strncmp(buf, "VENDOR_ELEM_REMOVE ", 19) == 0) {
7271 if (wpas_ctrl_vendor_elem_remove(wpa_s, buf + 19) < 0)
7274 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
7278 if (reply_len < 0) {
7279 os_memcpy(reply, "FAIL\n", 5);
7283 *resp_len = reply_len;
7288 static int wpa_supplicant_global_iface_add(struct wpa_global *global,
7291 struct wpa_interface iface;
7295 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
7296 * TAB<bridge_ifname>
7298 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd);
7300 os_memset(&iface, 0, sizeof(iface));
7303 iface.ifname = pos = cmd;
7304 pos = os_strchr(pos, '\t');
7307 if (iface.ifname[0] == '\0')
7312 iface.confname = pos;
7313 pos = os_strchr(pos, '\t');
7316 if (iface.confname[0] == '\0')
7317 iface.confname = NULL;
7322 pos = os_strchr(pos, '\t');
7325 if (iface.driver[0] == '\0')
7326 iface.driver = NULL;
7330 iface.ctrl_interface = pos;
7331 pos = os_strchr(pos, '\t');
7334 if (iface.ctrl_interface[0] == '\0')
7335 iface.ctrl_interface = NULL;
7339 iface.driver_param = pos;
7340 pos = os_strchr(pos, '\t');
7343 if (iface.driver_param[0] == '\0')
7344 iface.driver_param = NULL;
7348 iface.bridge_ifname = pos;
7349 pos = os_strchr(pos, '\t');
7352 if (iface.bridge_ifname[0] == '\0')
7353 iface.bridge_ifname = NULL;
7358 if (wpa_supplicant_get_iface(global, iface.ifname))
7361 return wpa_supplicant_add_iface(global, &iface) ? 0 : -1;
7365 static int wpa_supplicant_global_iface_remove(struct wpa_global *global,
7368 struct wpa_supplicant *wpa_s;
7370 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd);
7372 wpa_s = wpa_supplicant_get_iface(global, cmd);
7375 return wpa_supplicant_remove_iface(global, wpa_s, 0);
7379 static void wpa_free_iface_info(struct wpa_interface_info *iface)
7381 struct wpa_interface_info *prev;
7385 iface = iface->next;
7387 os_free(prev->ifname);
7388 os_free(prev->desc);
7394 static int wpa_supplicant_global_iface_list(struct wpa_global *global,
7398 struct wpa_interface_info *iface = NULL, *last = NULL, *tmp;
7401 for (i = 0; wpa_drivers[i]; i++) {
7402 struct wpa_driver_ops *drv = wpa_drivers[i];
7403 if (drv->get_interfaces == NULL)
7405 tmp = drv->get_interfaces(global->drv_priv[i]);
7419 for (tmp = iface; tmp; tmp = tmp->next) {
7420 res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n",
7421 tmp->drv_name, tmp->ifname,
7422 tmp->desc ? tmp->desc : "");
7423 if (res < 0 || res >= end - pos) {
7430 wpa_free_iface_info(iface);
7436 static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
7441 struct wpa_supplicant *wpa_s;
7443 wpa_s = global->ifaces;
7448 res = os_snprintf(pos, end - pos, "%s\n", wpa_s->ifname);
7449 if (res < 0 || res >= end - pos) {
7454 wpa_s = wpa_s->next;
7460 static char * wpas_global_ctrl_iface_ifname(struct wpa_global *global,
7462 char *cmd, size_t *resp_len)
7464 struct wpa_supplicant *wpa_s;
7466 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
7467 if (os_strcmp(ifname, wpa_s->ifname) == 0)
7471 if (wpa_s == NULL) {
7472 char *resp = os_strdup("FAIL-NO-IFNAME-MATCH\n");
7474 *resp_len = os_strlen(resp);
7480 return wpa_supplicant_ctrl_iface_process(wpa_s, cmd, resp_len);
7484 static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global *global,
7485 char *buf, size_t *resp_len)
7488 static const char * cmd[] = {
7494 "P2P_GET_PASSPHRASE",
7495 "P2P_SERVICE_UPDATE",
7496 "P2P_SERVICE_FLUSH",
7503 static const char * prefix[] = {
7506 #endif /* ANDROID */
7512 "P2P_GROUP_REMOVE ",
7515 "P2P_SERV_DISC_REQ ",
7516 "P2P_SERV_DISC_CANCEL_REQ ",
7517 "P2P_SERV_DISC_RESP ",
7518 "P2P_SERV_DISC_EXTERNAL ",
7526 "P2P_PRESENCE_REQ ",
7528 "P2P_REMOVE_CLIENT ",
7529 "NFC_GET_HANDOVER_SEL ",
7530 "NFC_GET_HANDOVER_REQ ",
7531 "NFC_REPORT_HANDOVER ",
7537 if (global->p2p_init_wpa_s == NULL)
7540 for (i = 0; !found && cmd[i]; i++) {
7541 if (os_strcmp(buf, cmd[i]) == 0)
7545 for (i = 0; !found && prefix[i]; i++) {
7546 if (os_strncmp(buf, prefix[i], os_strlen(prefix[i])) == 0)
7551 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
7553 #endif /* CONFIG_P2P */
7558 static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global *global,
7559 char *buf, size_t *resp_len)
7561 #ifdef CONFIG_WIFI_DISPLAY
7562 if (global->p2p_init_wpa_s == NULL)
7564 if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0 ||
7565 os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0)
7566 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
7568 #endif /* CONFIG_WIFI_DISPLAY */
7573 static char * wpas_global_ctrl_iface_redir(struct wpa_global *global,
7574 char *buf, size_t *resp_len)
7578 ret = wpas_global_ctrl_iface_redir_p2p(global, buf, resp_len);
7582 ret = wpas_global_ctrl_iface_redir_wfd(global, buf, resp_len);
7590 static int wpas_global_ctrl_iface_set(struct wpa_global *global, char *cmd)
7594 value = os_strchr(cmd, ' ');
7599 wpa_printf(MSG_DEBUG, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd, value);
7601 #ifdef CONFIG_WIFI_DISPLAY
7602 if (os_strcasecmp(cmd, "wifi_display") == 0) {
7603 wifi_display_enable(global, !!atoi(value));
7606 #endif /* CONFIG_WIFI_DISPLAY */
7608 /* Restore cmd to its original value to allow redirection */
7615 #ifndef CONFIG_NO_CONFIG_WRITE
7616 static int wpas_global_ctrl_iface_save_config(struct wpa_global *global)
7618 int ret = 0, saved = 0;
7619 struct wpa_supplicant *wpa_s;
7621 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
7622 if (!wpa_s->conf->update_config) {
7623 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
7627 if (wpa_config_write(wpa_s->confname, wpa_s->conf)) {
7628 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
7631 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
7636 if (!saved && !ret) {
7637 wpa_dbg(wpa_s, MSG_DEBUG,
7638 "CTRL_IFACE: SAVE_CONFIG - No configuration files could be updated");
7644 #endif /* CONFIG_NO_CONFIG_WRITE */
7647 static int wpas_global_ctrl_iface_status(struct wpa_global *global,
7648 char *buf, size_t buflen)
7652 struct wpa_supplicant *wpa_s;
7658 if (global->p2p && !global->p2p_disabled) {
7659 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
7662 MAC2STR(global->p2p_dev_addr),
7663 p2p_get_state_txt(global->p2p));
7664 if (ret < 0 || ret >= end - pos)
7667 } else if (global->p2p) {
7668 ret = os_snprintf(pos, end - pos, "p2p_state=DISABLED\n");
7669 if (ret < 0 || ret >= end - pos)
7673 #endif /* CONFIG_P2P */
7675 #ifdef CONFIG_WIFI_DISPLAY
7676 ret = os_snprintf(pos, end - pos, "wifi_display=%d\n",
7677 !!global->wifi_display);
7678 if (ret < 0 || ret >= end - pos)
7681 #endif /* CONFIG_WIFI_DISPLAY */
7683 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
7684 ret = os_snprintf(pos, end - pos, "ifname=%s\n"
7685 "address=" MACSTR "\n",
7686 wpa_s->ifname, MAC2STR(wpa_s->own_addr));
7687 if (ret < 0 || ret >= end - pos)
7696 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
7697 char *buf, size_t *resp_len)
7700 const int reply_size = 2048;
7702 int level = MSG_DEBUG;
7704 if (os_strncmp(buf, "IFNAME=", 7) == 0) {
7705 char *pos = os_strchr(buf + 7, ' ');
7708 return wpas_global_ctrl_iface_ifname(global,
7714 reply = wpas_global_ctrl_iface_redir(global, buf, resp_len);
7718 if (os_strcmp(buf, "PING") == 0)
7719 level = MSG_EXCESSIVE;
7720 wpa_hexdump_ascii(level, "RX global ctrl_iface",
7721 (const u8 *) buf, os_strlen(buf));
7723 reply = os_malloc(reply_size);
7724 if (reply == NULL) {
7729 os_memcpy(reply, "OK\n", 3);
7732 if (os_strcmp(buf, "PING") == 0) {
7733 os_memcpy(reply, "PONG\n", 5);
7735 } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) {
7736 if (wpa_supplicant_global_iface_add(global, buf + 14))
7738 } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) {
7739 if (wpa_supplicant_global_iface_remove(global, buf + 17))
7741 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
7742 reply_len = wpa_supplicant_global_iface_list(
7743 global, reply, reply_size);
7744 } else if (os_strcmp(buf, "INTERFACES") == 0) {
7745 reply_len = wpa_supplicant_global_iface_interfaces(
7746 global, reply, reply_size);
7747 } else if (os_strcmp(buf, "TERMINATE") == 0) {
7748 wpa_supplicant_terminate_proc(global);
7749 } else if (os_strcmp(buf, "SUSPEND") == 0) {
7750 wpas_notify_suspend(global);
7751 } else if (os_strcmp(buf, "RESUME") == 0) {
7752 wpas_notify_resume(global);
7753 } else if (os_strncmp(buf, "SET ", 4) == 0) {
7754 if (wpas_global_ctrl_iface_set(global, buf + 4)) {
7756 if (global->p2p_init_wpa_s) {
7758 /* Check if P2P redirection would work for this
7760 return wpa_supplicant_ctrl_iface_process(
7761 global->p2p_init_wpa_s,
7764 #endif /* CONFIG_P2P */
7767 #ifndef CONFIG_NO_CONFIG_WRITE
7768 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
7769 if (wpas_global_ctrl_iface_save_config(global))
7771 #endif /* CONFIG_NO_CONFIG_WRITE */
7772 } else if (os_strcmp(buf, "STATUS") == 0) {
7773 reply_len = wpas_global_ctrl_iface_status(global, reply,
7775 #ifdef CONFIG_MODULE_TESTS
7776 } else if (os_strcmp(buf, "MODULE_TESTS") == 0) {
7777 int wpas_module_tests(void);
7778 if (wpas_module_tests() < 0)
7780 #endif /* CONFIG_MODULE_TESTS */
7781 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
7782 if (wpa_debug_reopen_file() < 0)
7785 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
7789 if (reply_len < 0) {
7790 os_memcpy(reply, "FAIL\n", 5);
7794 *resp_len = reply_len;