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 #endif /* CONFIG_TESTING_OPTIONS */
437 #ifndef CONFIG_NO_CONFIG_BLOBS
438 } else if (os_strcmp(cmd, "blob") == 0) {
439 ret = wpas_ctrl_set_blob(wpa_s, value);
440 #endif /* CONFIG_NO_CONFIG_BLOBS */
443 ret = wpa_config_process_global(wpa_s->conf, cmd, -1);
445 wpa_supplicant_update_config(wpa_s);
452 static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s,
453 char *cmd, char *buf, size_t buflen)
457 wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd);
459 if (os_strcmp(cmd, "version") == 0) {
460 res = os_snprintf(buf, buflen, "%s", VERSION_STR);
461 } else if (os_strcasecmp(cmd, "country") == 0) {
462 if (wpa_s->conf->country[0] && wpa_s->conf->country[1])
463 res = os_snprintf(buf, buflen, "%c%c",
464 wpa_s->conf->country[0],
465 wpa_s->conf->country[1]);
466 #ifdef CONFIG_WIFI_DISPLAY
467 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
469 if (wpa_s->global->p2p == NULL ||
470 wpa_s->global->p2p_disabled)
473 enabled = wpa_s->global->wifi_display;
474 res = os_snprintf(buf, buflen, "%d", enabled);
475 if (res < 0 || (unsigned int) res >= buflen)
478 #endif /* CONFIG_WIFI_DISPLAY */
479 #ifdef CONFIG_TESTING_GET_GTK
480 } else if (os_strcmp(cmd, "gtk") == 0) {
481 if (wpa_s->last_gtk_len == 0)
483 res = wpa_snprintf_hex(buf, buflen, wpa_s->last_gtk,
484 wpa_s->last_gtk_len);
486 #endif /* CONFIG_TESTING_GET_GTK */
489 if (res < 0 || (unsigned int) res >= buflen)
495 #ifdef IEEE8021X_EAPOL
496 static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s,
500 struct wpa_ssid *ssid = wpa_s->current_ssid;
502 if (hwaddr_aton(addr, bssid)) {
503 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address "
508 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid));
509 rsn_preauth_deinit(wpa_s->wpa);
510 if (rsn_preauth_init(wpa_s->wpa, bssid, ssid ? &ssid->eap : NULL))
515 #endif /* IEEE8021X_EAPOL */
518 #ifdef CONFIG_PEERKEY
519 /* MLME-STKSTART.request(peer) */
520 static int wpa_supplicant_ctrl_iface_stkstart(
521 struct wpa_supplicant *wpa_s, char *addr)
525 if (hwaddr_aton(addr, peer)) {
526 wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART: invalid "
527 "address '%s'", addr);
531 wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART " MACSTR,
534 return wpa_sm_stkstart(wpa_s->wpa, peer);
536 #endif /* CONFIG_PEERKEY */
541 static int wpa_supplicant_ctrl_iface_tdls_discover(
542 struct wpa_supplicant *wpa_s, char *addr)
547 if (hwaddr_aton(addr, peer)) {
548 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER: invalid "
549 "address '%s'", addr);
553 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER " MACSTR,
556 if (wpa_tdls_is_external_setup(wpa_s->wpa))
557 ret = wpa_tdls_send_discovery_request(wpa_s->wpa, peer);
559 ret = wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer);
565 static int wpa_supplicant_ctrl_iface_tdls_setup(
566 struct wpa_supplicant *wpa_s, char *addr)
571 if (hwaddr_aton(addr, peer)) {
572 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP: invalid "
573 "address '%s'", addr);
577 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP " MACSTR,
580 if ((wpa_s->conf->tdls_external_control) &&
581 wpa_tdls_is_external_setup(wpa_s->wpa))
582 return wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
584 wpa_tdls_remove(wpa_s->wpa, peer);
586 if (wpa_tdls_is_external_setup(wpa_s->wpa))
587 ret = wpa_tdls_start(wpa_s->wpa, peer);
589 ret = wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
595 static int wpa_supplicant_ctrl_iface_tdls_teardown(
596 struct wpa_supplicant *wpa_s, char *addr)
601 if (os_strcmp(addr, "*") == 0) {
602 /* remove everyone */
603 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN *");
604 wpa_tdls_teardown_peers(wpa_s->wpa);
608 if (hwaddr_aton(addr, peer)) {
609 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN: invalid "
610 "address '%s'", addr);
614 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN " MACSTR,
617 if ((wpa_s->conf->tdls_external_control) &&
618 wpa_tdls_is_external_setup(wpa_s->wpa))
619 return wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
621 if (wpa_tdls_is_external_setup(wpa_s->wpa))
622 ret = wpa_tdls_teardown_link(
624 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED);
626 ret = wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
632 static int ctrl_iface_get_capability_tdls(
633 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
637 ret = os_snprintf(buf, buflen, "%s\n",
638 wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT ?
640 WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP ?
641 "EXTERNAL" : "INTERNAL") : "UNSUPPORTED");
642 if (ret < 0 || (size_t) ret > buflen)
647 #endif /* CONFIG_TDLS */
650 #ifdef CONFIG_IEEE80211R
651 static int wpa_supplicant_ctrl_iface_ft_ds(
652 struct wpa_supplicant *wpa_s, char *addr)
654 u8 target_ap[ETH_ALEN];
658 if (hwaddr_aton(addr, target_ap)) {
659 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid "
660 "address '%s'", addr);
664 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap));
666 bss = wpa_bss_get_bssid(wpa_s, target_ap);
668 mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN);
672 return wpa_ft_start_over_ds(wpa_s->wpa, target_ap, mdie);
674 #endif /* CONFIG_IEEE80211R */
678 static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s,
681 u8 bssid[ETH_ALEN], *_bssid = bssid;
683 u8 p2p_dev_addr[ETH_ALEN];
684 #endif /* CONFIG_P2P */
686 u8 *_p2p_dev_addr = NULL;
687 #endif /* CONFIG_AP */
689 if (cmd == NULL || os_strcmp(cmd, "any") == 0) {
692 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
693 if (hwaddr_aton(cmd + 13, p2p_dev_addr)) {
694 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid "
695 "P2P Device Address '%s'",
699 _p2p_dev_addr = p2p_dev_addr;
700 #endif /* CONFIG_P2P */
701 } else if (hwaddr_aton(cmd, bssid)) {
702 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
709 return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid, _p2p_dev_addr);
710 #endif /* CONFIG_AP */
712 return wpas_wps_start_pbc(wpa_s, _bssid, 0);
716 static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s,
717 char *cmd, char *buf,
720 u8 bssid[ETH_ALEN], *_bssid = bssid;
724 pin = os_strchr(cmd, ' ');
728 if (os_strcmp(cmd, "any") == 0)
730 else if (os_strcmp(cmd, "get") == 0) {
731 ret = wps_generate_pin();
733 } else if (hwaddr_aton(cmd, bssid)) {
734 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
740 if (wpa_s->ap_iface) {
745 pos = os_strchr(pin, ' ');
752 return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin,
753 buf, buflen, timeout);
755 #endif /* CONFIG_AP */
758 ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0,
762 ret = os_snprintf(buf, buflen, "%s", pin);
763 if (ret < 0 || (size_t) ret >= buflen)
768 ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0, DEV_PW_DEFAULT);
773 /* Return the generated PIN */
774 ret = os_snprintf(buf, buflen, "%08d", ret);
775 if (ret < 0 || (size_t) ret >= buflen)
781 static int wpa_supplicant_ctrl_iface_wps_check_pin(
782 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
789 wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN",
790 (u8 *) cmd, os_strlen(cmd));
791 for (pos = cmd, len = 0; *pos != '\0'; pos++) {
792 if (*pos < '0' || *pos > '9')
796 wpa_printf(MSG_DEBUG, "WPS: Too long PIN");
800 if (len != 4 && len != 8) {
801 wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len);
807 unsigned int pin_val;
809 if (!wps_pin_valid(pin_val)) {
810 wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit");
811 ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n");
812 if (ret < 0 || (size_t) ret >= buflen)
818 ret = os_snprintf(buf, buflen, "%s", pin);
819 if (ret < 0 || (size_t) ret >= buflen)
826 #ifdef CONFIG_WPS_NFC
828 static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant *wpa_s,
831 u8 bssid[ETH_ALEN], *_bssid = bssid;
833 if (cmd == NULL || cmd[0] == '\0')
835 else if (hwaddr_aton(cmd, bssid))
838 return wpas_wps_start_nfc(wpa_s, NULL, _bssid, NULL, 0, 0, NULL, NULL,
843 static int wpa_supplicant_ctrl_iface_wps_nfc_config_token(
844 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
851 pos = os_strchr(cmd, ' ');
854 if (os_strcmp(cmd, "WPS") == 0)
856 else if (os_strcmp(cmd, "NDEF") == 0)
861 buf = wpas_wps_nfc_config_token(wpa_s, ndef, pos);
865 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
876 static int wpa_supplicant_ctrl_iface_wps_nfc_token(
877 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
883 if (os_strcmp(cmd, "WPS") == 0)
885 else if (os_strcmp(cmd, "NDEF") == 0)
890 buf = wpas_wps_nfc_token(wpa_s, ndef);
894 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
905 static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
906 struct wpa_supplicant *wpa_s, char *pos)
914 freq = strstr(pos, " freq=");
918 forced_freq = atoi(freq);
921 len = os_strlen(pos);
926 buf = wpabuf_alloc(len);
929 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
934 ret = wpas_wps_nfc_tag_read(wpa_s, buf, forced_freq);
941 static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant *wpa_s,
942 char *reply, size_t max_len,
948 buf = wpas_wps_nfc_handover_req(wpa_s, ndef);
952 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
964 static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant *wpa_s,
965 char *reply, size_t max_len,
971 buf = wpas_p2p_nfc_handover_req(wpa_s, ndef);
973 wpa_printf(MSG_DEBUG, "P2P: Could not generate NFC handover request");
977 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
986 #endif /* CONFIG_P2P */
989 static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant *wpa_s,
990 char *cmd, char *reply,
996 pos = os_strchr(cmd, ' ');
1001 if (os_strcmp(cmd, "WPS") == 0)
1003 else if (os_strcmp(cmd, "NDEF") == 0)
1008 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
1011 return wpas_ctrl_nfc_get_handover_req_wps(
1012 wpa_s, reply, max_len, ndef);
1016 if (os_strcmp(pos, "P2P-CR") == 0) {
1017 return wpas_ctrl_nfc_get_handover_req_p2p(
1018 wpa_s, reply, max_len, ndef);
1020 #endif /* CONFIG_P2P */
1026 static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant *wpa_s,
1027 char *reply, size_t max_len,
1028 int ndef, int cr, char *uuid)
1033 buf = wpas_wps_nfc_handover_sel(wpa_s, ndef, cr, uuid);
1037 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1039 reply[res++] = '\n';
1049 static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant *wpa_s,
1050 char *reply, size_t max_len,
1056 buf = wpas_p2p_nfc_handover_sel(wpa_s, ndef, tag);
1060 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1062 reply[res++] = '\n';
1069 #endif /* CONFIG_P2P */
1072 static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant *wpa_s,
1073 char *cmd, char *reply,
1079 pos = os_strchr(cmd, ' ');
1084 if (os_strcmp(cmd, "WPS") == 0)
1086 else if (os_strcmp(cmd, "NDEF") == 0)
1091 pos2 = os_strchr(pos, ' ');
1094 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
1097 return wpas_ctrl_nfc_get_handover_sel_wps(
1098 wpa_s, reply, max_len, ndef,
1099 os_strcmp(pos, "WPS-CR") == 0, pos2);
1103 if (os_strcmp(pos, "P2P-CR") == 0) {
1104 return wpas_ctrl_nfc_get_handover_sel_p2p(
1105 wpa_s, reply, max_len, ndef, 0);
1108 if (os_strcmp(pos, "P2P-CR-TAG") == 0) {
1109 return wpas_ctrl_nfc_get_handover_sel_p2p(
1110 wpa_s, reply, max_len, ndef, 1);
1112 #endif /* CONFIG_P2P */
1118 static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant *wpa_s,
1122 struct wpabuf *req, *sel;
1124 char *pos, *role, *type, *pos2;
1127 int forced_freq = 0;
1129 freq = strstr(cmd, " freq=");
1133 forced_freq = atoi(freq);
1135 #endif /* CONFIG_P2P */
1138 pos = os_strchr(role, ' ');
1140 wpa_printf(MSG_DEBUG, "NFC: Missing type in handover report");
1146 pos = os_strchr(type, ' ');
1148 wpa_printf(MSG_DEBUG, "NFC: Missing request message in handover report");
1153 pos2 = os_strchr(pos, ' ');
1155 wpa_printf(MSG_DEBUG, "NFC: Missing select message in handover report");
1160 len = os_strlen(pos);
1162 wpa_printf(MSG_DEBUG, "NFC: Invalid request message length in handover report");
1167 req = wpabuf_alloc(len);
1169 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for request message");
1172 if (hexstr2bin(pos, wpabuf_put(req, len), len) < 0) {
1173 wpa_printf(MSG_DEBUG, "NFC: Invalid request message hexdump in handover report");
1178 len = os_strlen(pos2);
1180 wpa_printf(MSG_DEBUG, "NFC: Invalid select message length in handover report");
1186 sel = wpabuf_alloc(len);
1188 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for select message");
1192 if (hexstr2bin(pos2, wpabuf_put(sel, len), len) < 0) {
1193 wpa_printf(MSG_DEBUG, "NFC: Invalid select message hexdump in handover report");
1199 wpa_printf(MSG_DEBUG, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d",
1200 role, type, (int) wpabuf_len(req), (int) wpabuf_len(sel));
1202 if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "WPS") == 0) {
1203 ret = wpas_wps_nfc_report_handover(wpa_s, req, sel);
1205 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "WPS") == 0)
1207 ret = wpas_ap_wps_nfc_report_handover(wpa_s, req, sel);
1209 ret = wpas_er_wps_nfc_report_handover(wpa_s, req, sel);
1210 #endif /* CONFIG_AP */
1212 } else if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "P2P") == 0)
1214 ret = wpas_p2p_nfc_report_handover(wpa_s, 1, req, sel, 0);
1215 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "P2P") == 0)
1217 ret = wpas_p2p_nfc_report_handover(wpa_s, 0, req, sel,
1219 #endif /* CONFIG_P2P */
1221 wpa_printf(MSG_DEBUG, "NFC: Unsupported connection handover "
1222 "reported: role=%s type=%s", role, type);
1229 wpa_printf(MSG_DEBUG, "NFC: Failed to process reported handover messages");
1234 #endif /* CONFIG_WPS_NFC */
1237 static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s,
1246 struct wps_new_ap_settings ap;
1248 pin = os_strchr(cmd, ' ');
1253 if (hwaddr_aton(cmd, bssid)) {
1254 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
1259 new_ssid = os_strchr(pin, ' ');
1260 if (new_ssid == NULL)
1261 return wpas_wps_start_reg(wpa_s, bssid, pin, NULL);
1264 new_auth = os_strchr(new_ssid, ' ');
1265 if (new_auth == NULL)
1269 new_encr = os_strchr(new_auth, ' ');
1270 if (new_encr == NULL)
1274 new_key = os_strchr(new_encr, ' ');
1275 if (new_key == NULL)
1279 os_memset(&ap, 0, sizeof(ap));
1280 ap.ssid_hex = new_ssid;
1283 ap.key_hex = new_key;
1284 return wpas_wps_start_reg(wpa_s, bssid, pin, &ap);
1289 static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant *wpa_s,
1290 char *cmd, char *buf,
1295 const char *pin_txt;
1297 if (!wpa_s->ap_iface)
1300 pos = os_strchr(cmd, ' ');
1304 if (os_strcmp(cmd, "disable") == 0) {
1305 wpas_wps_ap_pin_disable(wpa_s);
1306 return os_snprintf(buf, buflen, "OK\n");
1309 if (os_strcmp(cmd, "random") == 0) {
1311 timeout = atoi(pos);
1312 pin_txt = wpas_wps_ap_pin_random(wpa_s, timeout);
1313 if (pin_txt == NULL)
1315 return os_snprintf(buf, buflen, "%s", pin_txt);
1318 if (os_strcmp(cmd, "get") == 0) {
1319 pin_txt = wpas_wps_ap_pin_get(wpa_s);
1320 if (pin_txt == NULL)
1322 return os_snprintf(buf, buflen, "%s", pin_txt);
1325 if (os_strcmp(cmd, "set") == 0) {
1330 pos = os_strchr(pos, ' ');
1333 timeout = atoi(pos);
1335 if (os_strlen(pin) > buflen)
1337 if (wpas_wps_ap_pin_set(wpa_s, pin, timeout) < 0)
1339 return os_snprintf(buf, buflen, "%s", pin);
1344 #endif /* CONFIG_AP */
1347 #ifdef CONFIG_WPS_ER
1348 static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant *wpa_s,
1351 char *uuid = cmd, *pin, *pos;
1352 u8 addr_buf[ETH_ALEN], *addr = NULL;
1353 pin = os_strchr(uuid, ' ');
1357 pos = os_strchr(pin, ' ');
1360 if (hwaddr_aton(pos, addr_buf) == 0)
1363 return wpas_wps_er_add_pin(wpa_s, addr, uuid, pin);
1367 static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant *wpa_s,
1370 char *uuid = cmd, *pin;
1371 pin = os_strchr(uuid, ' ');
1375 return wpas_wps_er_learn(wpa_s, uuid, pin);
1379 static int wpa_supplicant_ctrl_iface_wps_er_set_config(
1380 struct wpa_supplicant *wpa_s, char *cmd)
1382 char *uuid = cmd, *id;
1383 id = os_strchr(uuid, ' ');
1387 return wpas_wps_er_set_config(wpa_s, uuid, atoi(id));
1391 static int wpa_supplicant_ctrl_iface_wps_er_config(
1392 struct wpa_supplicant *wpa_s, char *cmd)
1399 struct wps_new_ap_settings ap;
1401 pin = os_strchr(cmd, ' ');
1406 new_ssid = os_strchr(pin, ' ');
1407 if (new_ssid == NULL)
1411 new_auth = os_strchr(new_ssid, ' ');
1412 if (new_auth == NULL)
1416 new_encr = os_strchr(new_auth, ' ');
1417 if (new_encr == NULL)
1421 new_key = os_strchr(new_encr, ' ');
1422 if (new_key == NULL)
1426 os_memset(&ap, 0, sizeof(ap));
1427 ap.ssid_hex = new_ssid;
1430 ap.key_hex = new_key;
1431 return wpas_wps_er_config(wpa_s, cmd, pin, &ap);
1435 #ifdef CONFIG_WPS_NFC
1436 static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
1437 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1444 uuid = os_strchr(cmd, ' ');
1449 if (os_strcmp(cmd, "WPS") == 0)
1451 else if (os_strcmp(cmd, "NDEF") == 0)
1456 buf = wpas_wps_er_nfc_config_token(wpa_s, ndef, uuid);
1460 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1462 reply[res++] = '\n';
1469 #endif /* CONFIG_WPS_NFC */
1470 #endif /* CONFIG_WPS_ER */
1472 #endif /* CONFIG_WPS */
1475 #ifdef CONFIG_IBSS_RSN
1476 static int wpa_supplicant_ctrl_iface_ibss_rsn(
1477 struct wpa_supplicant *wpa_s, char *addr)
1481 if (hwaddr_aton(addr, peer)) {
1482 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN: invalid "
1483 "address '%s'", addr);
1487 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN " MACSTR,
1490 return ibss_rsn_start(wpa_s->ibss_rsn, peer);
1492 #endif /* CONFIG_IBSS_RSN */
1495 static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s,
1498 #ifdef IEEE8021X_EAPOL
1501 struct wpa_ssid *ssid;
1503 pos = os_strchr(rsp, '-');
1508 pos = os_strchr(pos, ':');
1513 wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id);
1514 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
1515 (u8 *) pos, os_strlen(pos));
1517 ssid = wpa_config_get_network(wpa_s->conf, id);
1519 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
1524 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s, ssid, rsp,
1526 #else /* IEEE8021X_EAPOL */
1527 wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included");
1529 #endif /* IEEE8021X_EAPOL */
1533 static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
1535 char *buf, size_t buflen)
1537 char *pos, *end, tmp[30];
1538 int res, verbose, wps, ret;
1541 #endif /* CONFIG_HS20 */
1543 if (os_strcmp(params, "-DRIVER") == 0)
1544 return wpa_drv_status(wpa_s, buf, buflen);
1545 verbose = os_strcmp(params, "-VERBOSE") == 0;
1546 wps = os_strcmp(params, "-WPS") == 0;
1549 if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
1550 struct wpa_ssid *ssid = wpa_s->current_ssid;
1551 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
1552 MAC2STR(wpa_s->bssid));
1553 if (ret < 0 || ret >= end - pos)
1556 ret = os_snprintf(pos, end - pos, "freq=%u\n",
1558 if (ret < 0 || ret >= end - pos)
1562 u8 *_ssid = ssid->ssid;
1563 size_t ssid_len = ssid->ssid_len;
1564 u8 ssid_buf[MAX_SSID_LEN];
1565 if (ssid_len == 0) {
1566 int _res = wpa_drv_get_ssid(wpa_s, ssid_buf);
1573 ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n",
1574 wpa_ssid_txt(_ssid, ssid_len),
1576 if (ret < 0 || ret >= end - pos)
1580 if (wps && ssid->passphrase &&
1581 wpa_key_mgmt_wpa_psk(ssid->key_mgmt) &&
1582 (ssid->mode == WPAS_MODE_AP ||
1583 ssid->mode == WPAS_MODE_P2P_GO)) {
1584 ret = os_snprintf(pos, end - pos,
1587 if (ret < 0 || ret >= end - pos)
1592 ret = os_snprintf(pos, end - pos,
1595 if (ret < 0 || ret >= end - pos)
1600 switch (ssid->mode) {
1601 case WPAS_MODE_INFRA:
1602 ret = os_snprintf(pos, end - pos,
1605 case WPAS_MODE_IBSS:
1606 ret = os_snprintf(pos, end - pos,
1610 ret = os_snprintf(pos, end - pos,
1613 case WPAS_MODE_P2P_GO:
1614 ret = os_snprintf(pos, end - pos,
1617 case WPAS_MODE_P2P_GROUP_FORMATION:
1618 ret = os_snprintf(pos, end - pos,
1619 "mode=P2P GO - group "
1626 if (ret < 0 || ret >= end - pos)
1632 if (wpa_s->ap_iface) {
1633 pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos,
1637 #endif /* CONFIG_AP */
1638 pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose);
1641 if (wpa_s->wpa_state >= WPA_ASSOCIATED &&
1644 #endif /* CONFIG_AP */
1645 wpa_s->sme.sae.state == SAE_ACCEPTED) {
1646 ret = os_snprintf(pos, end - pos, "sae_group=%d\n",
1647 wpa_s->sme.sae.group);
1648 if (ret < 0 || ret >= end - pos)
1652 #endif /* CONFIG_SAE */
1653 ret = os_snprintf(pos, end - pos, "wpa_state=%s\n",
1654 wpa_supplicant_state_txt(wpa_s->wpa_state));
1655 if (ret < 0 || ret >= end - pos)
1660 l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) {
1661 ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp);
1662 if (ret < 0 || ret >= end - pos)
1668 if (wpa_s->global->p2p) {
1669 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
1670 "\n", MAC2STR(wpa_s->global->p2p_dev_addr));
1671 if (ret < 0 || ret >= end - pos)
1675 #endif /* CONFIG_P2P */
1677 ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n",
1678 MAC2STR(wpa_s->own_addr));
1679 if (ret < 0 || ret >= end - pos)
1684 if (wpa_s->current_bss &&
1685 (hs20 = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1686 HS20_IE_VENDOR_TYPE)) &&
1687 wpa_s->wpa_proto == WPA_PROTO_RSN &&
1688 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1691 u8 rel_num = (hs20[6] & 0xf0) >> 4;
1692 release = rel_num + 1;
1694 ret = os_snprintf(pos, end - pos, "hs20=%d\n", release);
1695 if (ret < 0 || ret >= end - pos)
1700 if (wpa_s->current_ssid) {
1701 struct wpa_cred *cred;
1704 for (cred = wpa_s->conf->cred; cred; cred = cred->next) {
1707 if (wpa_s->current_ssid->parent_cred != cred)
1710 if (cred->provisioning_sp) {
1711 ret = os_snprintf(pos, end - pos,
1712 "provisioning_sp=%s\n",
1713 cred->provisioning_sp);
1714 if (ret < 0 || ret >= end - pos)
1723 if (wpa_s->current_bss && wpa_s->current_bss->anqp) {
1724 struct wpabuf *names =
1725 wpa_s->current_bss->anqp->domain_name;
1726 for (i = 0; names && i < cred->num_domain; i++)
1728 if (domain_name_list_contains(
1729 names, cred->domain[i], 1))
1732 if (i == cred->num_domain)
1733 i = 0; /* show first entry by default */
1735 ret = os_snprintf(pos, end - pos, "home_sp=%s\n",
1737 if (ret < 0 || ret >= end - pos)
1742 if (wpa_s->current_bss == NULL ||
1743 wpa_s->current_bss->anqp == NULL)
1746 res = interworking_home_sp_cred(
1748 wpa_s->current_bss->anqp->domain_name);
1756 ret = os_snprintf(pos, end - pos, "sp_type=%s\n", type);
1757 if (ret < 0 || ret >= end - pos)
1764 #endif /* CONFIG_HS20 */
1766 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
1767 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
1768 res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos,
1774 res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose);
1781 uuid_bin2str(wpa_s->wps->uuid, uuid_str, sizeof(uuid_str));
1782 ret = os_snprintf(pos, end - pos, "uuid=%s\n", uuid_str);
1783 if (ret < 0 || ret >= end - pos)
1787 #endif /* CONFIG_WPS */
1791 * Allow using the STATUS command with default behavior, say for debug,
1792 * i.e., don't generate a "fake" CONNECTION and SUPPLICANT_STATE_CHANGE
1793 * events with STATUS-NO_EVENTS.
1795 if (os_strcmp(params, "-NO_EVENTS")) {
1796 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_STATE_CHANGE
1797 "id=%d state=%d BSSID=" MACSTR " SSID=%s",
1798 wpa_s->current_ssid ? wpa_s->current_ssid->id : -1,
1800 MAC2STR(wpa_s->bssid),
1801 wpa_s->current_ssid && wpa_s->current_ssid->ssid ?
1802 wpa_ssid_txt(wpa_s->current_ssid->ssid,
1803 wpa_s->current_ssid->ssid_len) : "");
1804 if (wpa_s->wpa_state == WPA_COMPLETED) {
1805 struct wpa_ssid *ssid = wpa_s->current_ssid;
1806 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_CONNECTED
1807 "- connection to " MACSTR
1808 " completed %s [id=%d id_str=%s]",
1809 MAC2STR(wpa_s->bssid), "(auth)",
1810 ssid ? ssid->id : -1,
1811 ssid && ssid->id_str ? ssid->id_str : "");
1814 #endif /* ANDROID */
1820 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s,
1825 struct wpa_ssid *ssid;
1828 /* cmd: "<network id> <BSSID>" */
1829 pos = os_strchr(cmd, ' ');
1834 wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos);
1835 if (hwaddr_aton(pos, bssid)) {
1836 wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos);
1840 ssid = wpa_config_get_network(wpa_s->conf, id);
1842 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
1847 os_memcpy(ssid->bssid, bssid, ETH_ALEN);
1848 ssid->bssid_set = !is_zero_ether_addr(bssid);
1854 static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant *wpa_s,
1855 char *cmd, char *buf,
1859 struct wpa_blacklist *e;
1863 /* cmd: "BLACKLIST [<BSSID>]" */
1867 e = wpa_s->blacklist;
1869 ret = os_snprintf(pos, end - pos, MACSTR "\n",
1871 if (ret < 0 || ret >= end - pos)
1880 if (os_strncmp(cmd, "clear", 5) == 0) {
1881 wpa_blacklist_clear(wpa_s);
1882 os_memcpy(buf, "OK\n", 3);
1886 wpa_printf(MSG_DEBUG, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd);
1887 if (hwaddr_aton(cmd, bssid)) {
1888 wpa_printf(MSG_DEBUG, "CTRL_IFACE: invalid BSSID '%s'", cmd);
1893 * Add the BSSID twice, so its count will be 2, causing it to be
1894 * skipped when processing scan results.
1896 ret = wpa_blacklist_add(wpa_s, bssid);
1899 ret = wpa_blacklist_add(wpa_s, bssid);
1902 os_memcpy(buf, "OK\n", 3);
1907 static const char * debug_level_str(int level)
1928 static int str_to_debug_level(const char *s)
1930 if (os_strcasecmp(s, "EXCESSIVE") == 0)
1931 return MSG_EXCESSIVE;
1932 if (os_strcasecmp(s, "MSGDUMP") == 0)
1934 if (os_strcasecmp(s, "DEBUG") == 0)
1936 if (os_strcasecmp(s, "INFO") == 0)
1938 if (os_strcasecmp(s, "WARNING") == 0)
1940 if (os_strcasecmp(s, "ERROR") == 0)
1946 static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant *wpa_s,
1947 char *cmd, char *buf,
1950 char *pos, *end, *stamp;
1957 /* cmd: "LOG_LEVEL [<level>]" */
1961 ret = os_snprintf(pos, end - pos, "Current level: %s\n"
1963 debug_level_str(wpa_debug_level),
1964 wpa_debug_timestamp);
1965 if (ret < 0 || ret >= end - pos)
1974 stamp = os_strchr(cmd, ' ');
1977 while (*stamp == ' ') {
1982 if (cmd && os_strlen(cmd)) {
1983 int level = str_to_debug_level(cmd);
1986 wpa_debug_level = level;
1989 if (stamp && os_strlen(stamp))
1990 wpa_debug_timestamp = atoi(stamp);
1992 os_memcpy(buf, "OK\n", 3);
1997 static int wpa_supplicant_ctrl_iface_list_networks(
1998 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
2001 struct wpa_ssid *ssid;
2006 ret = os_snprintf(pos, end - pos,
2007 "network id / ssid / bssid / flags\n");
2008 if (ret < 0 || ret >= end - pos)
2012 ssid = wpa_s->conf->ssid;
2014 ret = os_snprintf(pos, end - pos, "%d\t%s",
2016 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
2017 if (ret < 0 || ret >= end - pos)
2020 if (ssid->bssid_set) {
2021 ret = os_snprintf(pos, end - pos, "\t" MACSTR,
2022 MAC2STR(ssid->bssid));
2024 ret = os_snprintf(pos, end - pos, "\tany");
2026 if (ret < 0 || ret >= end - pos)
2029 ret = os_snprintf(pos, end - pos, "\t%s%s%s%s",
2030 ssid == wpa_s->current_ssid ?
2032 ssid->disabled ? "[DISABLED]" : "",
2033 ssid->disabled_until.sec ?
2034 "[TEMP-DISABLED]" : "",
2035 ssid->disabled == 2 ? "[P2P-PERSISTENT]" :
2037 if (ret < 0 || ret >= end - pos)
2040 ret = os_snprintf(pos, end - pos, "\n");
2041 if (ret < 0 || ret >= end - pos)
2052 static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher)
2055 ret = os_snprintf(pos, end - pos, "-");
2056 if (ret < 0 || ret >= end - pos)
2059 ret = wpa_write_ciphers(pos, end, cipher, "+");
2067 static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
2068 const u8 *ie, size_t ie_len)
2070 struct wpa_ie_data data;
2074 ret = os_snprintf(pos, end - pos, "[%s-", proto);
2075 if (ret < 0 || ret >= end - pos)
2079 if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) {
2080 ret = os_snprintf(pos, end - pos, "?]");
2081 if (ret < 0 || ret >= end - pos)
2088 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
2089 ret = os_snprintf(pos, end - pos, "%sEAP",
2090 pos == start ? "" : "+");
2091 if (ret < 0 || ret >= end - pos)
2095 if (data.key_mgmt & WPA_KEY_MGMT_PSK) {
2096 ret = os_snprintf(pos, end - pos, "%sPSK",
2097 pos == start ? "" : "+");
2098 if (ret < 0 || ret >= end - pos)
2102 if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
2103 ret = os_snprintf(pos, end - pos, "%sNone",
2104 pos == start ? "" : "+");
2105 if (ret < 0 || ret >= end - pos)
2109 if (data.key_mgmt & WPA_KEY_MGMT_SAE) {
2110 ret = os_snprintf(pos, end - pos, "%sSAE",
2111 pos == start ? "" : "+");
2112 if (ret < 0 || ret >= end - pos)
2116 #ifdef CONFIG_IEEE80211R
2117 if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
2118 ret = os_snprintf(pos, end - pos, "%sFT/EAP",
2119 pos == start ? "" : "+");
2120 if (ret < 0 || ret >= end - pos)
2124 if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) {
2125 ret = os_snprintf(pos, end - pos, "%sFT/PSK",
2126 pos == start ? "" : "+");
2127 if (ret < 0 || ret >= end - pos)
2131 if (data.key_mgmt & WPA_KEY_MGMT_FT_SAE) {
2132 ret = os_snprintf(pos, end - pos, "%sFT/SAE",
2133 pos == start ? "" : "+");
2134 if (ret < 0 || ret >= end - pos)
2138 #endif /* CONFIG_IEEE80211R */
2139 #ifdef CONFIG_IEEE80211W
2140 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
2141 ret = os_snprintf(pos, end - pos, "%sEAP-SHA256",
2142 pos == start ? "" : "+");
2143 if (ret < 0 || ret >= end - pos)
2147 if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
2148 ret = os_snprintf(pos, end - pos, "%sPSK-SHA256",
2149 pos == start ? "" : "+");
2150 if (ret < 0 || ret >= end - pos)
2154 #endif /* CONFIG_IEEE80211W */
2156 pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher);
2158 if (data.capabilities & WPA_CAPABILITY_PREAUTH) {
2159 ret = os_snprintf(pos, end - pos, "-preauth");
2160 if (ret < 0 || ret >= end - pos)
2165 ret = os_snprintf(pos, end - pos, "]");
2166 if (ret < 0 || ret >= end - pos)
2175 static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s,
2176 char *pos, char *end,
2177 struct wpabuf *wps_ie)
2184 if (wps_is_selected_pbc_registrar(wps_ie))
2186 else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0))
2188 else if (wps_is_selected_pin_registrar(wps_ie))
2193 ret = os_snprintf(pos, end - pos, "%s", txt);
2194 if (ret >= 0 && ret < end - pos)
2196 wpabuf_free(wps_ie);
2199 #endif /* CONFIG_WPS */
2202 static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s,
2203 char *pos, char *end,
2204 const struct wpa_bss *bss)
2207 struct wpabuf *wps_ie;
2208 wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
2209 return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie);
2210 #else /* CONFIG_WPS */
2212 #endif /* CONFIG_WPS */
2216 /* Format one result on one text line into a buffer. */
2217 static int wpa_supplicant_ctrl_iface_scan_result(
2218 struct wpa_supplicant *wpa_s,
2219 const struct wpa_bss *bss, char *buf, size_t buflen)
2223 const u8 *ie, *ie2, *p2p, *mesh;
2225 mesh = wpa_bss_get_ie(bss, WLAN_EID_MESH_ID);
2226 p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
2228 p2p = wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE);
2229 if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN &&
2230 os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) ==
2232 return 0; /* Do not show P2P listen discovery results here */
2237 ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t",
2238 MAC2STR(bss->bssid), bss->freq, bss->level);
2239 if (ret < 0 || ret >= end - pos)
2242 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
2244 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]);
2245 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
2247 pos = wpa_supplicant_ie_txt(pos, end, mesh ? "RSN" : "WPA2",
2250 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
2251 if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
2252 ret = os_snprintf(pos, end - pos, "[WEP]");
2253 if (ret < 0 || ret >= end - pos)
2258 ret = os_snprintf(pos, end - pos, "[MESH]");
2259 if (ret < 0 || ret >= end - pos)
2263 if (bss_is_dmg(bss)) {
2265 ret = os_snprintf(pos, end - pos, "[DMG]");
2266 if (ret < 0 || ret >= end - pos)
2269 switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
2270 case IEEE80211_CAP_DMG_IBSS:
2273 case IEEE80211_CAP_DMG_AP:
2276 case IEEE80211_CAP_DMG_PBSS:
2283 ret = os_snprintf(pos, end - pos, "%s", s);
2284 if (ret < 0 || ret >= end - pos)
2288 if (bss->caps & IEEE80211_CAP_IBSS) {
2289 ret = os_snprintf(pos, end - pos, "[IBSS]");
2290 if (ret < 0 || ret >= end - pos)
2294 if (bss->caps & IEEE80211_CAP_ESS) {
2295 ret = os_snprintf(pos, end - pos, "[ESS]");
2296 if (ret < 0 || ret >= end - pos)
2302 ret = os_snprintf(pos, end - pos, "[P2P]");
2303 if (ret < 0 || ret >= end - pos)
2308 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE) && ie2) {
2309 ret = os_snprintf(pos, end - pos, "[HS20]");
2310 if (ret < 0 || ret >= end - pos)
2314 #endif /* CONFIG_HS20 */
2316 ret = os_snprintf(pos, end - pos, "\t%s",
2317 wpa_ssid_txt(bss->ssid, bss->ssid_len));
2318 if (ret < 0 || ret >= end - pos)
2322 ret = os_snprintf(pos, end - pos, "\n");
2323 if (ret < 0 || ret >= end - pos)
2331 static int wpa_supplicant_ctrl_iface_scan_results(
2332 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
2335 struct wpa_bss *bss;
2340 ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / "
2342 if (ret < 0 || ret >= end - pos)
2346 dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
2347 ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos,
2349 if (ret < 0 || ret >= end - pos)
2358 static int wpa_supplicant_ctrl_iface_select_network(
2359 struct wpa_supplicant *wpa_s, char *cmd)
2362 struct wpa_ssid *ssid;
2365 /* cmd: "<network id>" or "any" */
2366 if (os_strncmp(cmd, "any", 3) == 0) {
2367 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any");
2371 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id);
2373 ssid = wpa_config_get_network(wpa_s->conf, id);
2375 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2376 "network id=%d", id);
2379 if (ssid->disabled == 2) {
2380 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2381 "SELECT_NETWORK with persistent P2P group");
2386 pos = os_strstr(cmd, " freq=");
2388 int *freqs = freq_range_to_channel_list(wpa_s, pos + 6);
2390 wpa_s->scan_req = MANUAL_SCAN_REQ;
2391 os_free(wpa_s->manual_scan_freqs);
2392 wpa_s->manual_scan_freqs = freqs;
2396 wpa_supplicant_select_network(wpa_s, ssid);
2402 static int wpa_supplicant_ctrl_iface_enable_network(
2403 struct wpa_supplicant *wpa_s, char *cmd)
2406 struct wpa_ssid *ssid;
2408 /* cmd: "<network id>" or "all" */
2409 if (os_strcmp(cmd, "all") == 0) {
2410 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all");
2414 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id);
2416 ssid = wpa_config_get_network(wpa_s->conf, id);
2418 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2419 "network id=%d", id);
2422 if (ssid->disabled == 2) {
2423 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2424 "ENABLE_NETWORK with persistent P2P group");
2428 if (os_strstr(cmd, " no-connect")) {
2433 wpa_supplicant_enable_network(wpa_s, ssid);
2439 static int wpa_supplicant_ctrl_iface_disable_network(
2440 struct wpa_supplicant *wpa_s, char *cmd)
2443 struct wpa_ssid *ssid;
2445 /* cmd: "<network id>" or "all" */
2446 if (os_strcmp(cmd, "all") == 0) {
2447 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all");
2451 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id);
2453 ssid = wpa_config_get_network(wpa_s->conf, id);
2455 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2456 "network id=%d", id);
2459 if (ssid->disabled == 2) {
2460 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2461 "DISABLE_NETWORK with persistent P2P "
2466 wpa_supplicant_disable_network(wpa_s, ssid);
2472 static int wpa_supplicant_ctrl_iface_add_network(
2473 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
2475 struct wpa_ssid *ssid;
2478 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK");
2480 ssid = wpa_config_add_network(wpa_s->conf);
2484 wpas_notify_network_added(wpa_s, ssid);
2487 wpa_config_set_network_defaults(ssid);
2489 ret = os_snprintf(buf, buflen, "%d\n", ssid->id);
2490 if (ret < 0 || (size_t) ret >= buflen)
2496 static int wpa_supplicant_ctrl_iface_remove_network(
2497 struct wpa_supplicant *wpa_s, char *cmd)
2500 struct wpa_ssid *ssid;
2503 /* cmd: "<network id>" or "all" */
2504 if (os_strcmp(cmd, "all") == 0) {
2505 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all");
2506 if (wpa_s->sched_scanning)
2507 wpa_supplicant_cancel_sched_scan(wpa_s);
2509 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2510 if (wpa_s->current_ssid) {
2512 wpa_s->sme.prev_bssid_set = 0;
2513 #endif /* CONFIG_SME */
2514 wpa_sm_set_config(wpa_s->wpa, NULL);
2515 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
2516 wpa_supplicant_deauthenticate(
2517 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2519 ssid = wpa_s->conf->ssid;
2521 struct wpa_ssid *remove_ssid = ssid;
2524 if (wpa_s->last_ssid == remove_ssid)
2525 wpa_s->last_ssid = NULL;
2526 wpas_notify_network_removed(wpa_s, remove_ssid);
2527 wpa_config_remove_network(wpa_s->conf, id);
2533 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id);
2535 ssid = wpa_config_get_network(wpa_s->conf, id);
2537 wpas_notify_network_removed(wpa_s, ssid);
2539 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2544 if (wpa_s->last_ssid == ssid)
2545 wpa_s->last_ssid = NULL;
2547 if (ssid == wpa_s->current_ssid || wpa_s->current_ssid == NULL) {
2549 wpa_s->sme.prev_bssid_set = 0;
2550 #endif /* CONFIG_SME */
2552 * Invalidate the EAP session cache if the current or
2553 * previously used network is removed.
2555 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2558 if (ssid == wpa_s->current_ssid) {
2559 wpa_sm_set_config(wpa_s->wpa, NULL);
2560 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
2562 wpa_supplicant_deauthenticate(wpa_s,
2563 WLAN_REASON_DEAUTH_LEAVING);
2566 was_disabled = ssid->disabled;
2568 if (wpa_config_remove_network(wpa_s->conf, id) < 0) {
2569 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Not able to remove the "
2570 "network id=%d", id);
2574 if (!was_disabled && wpa_s->sched_scanning) {
2575 wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to remove "
2576 "network from filters");
2577 wpa_supplicant_cancel_sched_scan(wpa_s);
2578 wpa_supplicant_req_scan(wpa_s, 0, 0);
2585 static int wpa_supplicant_ctrl_iface_update_network(
2586 struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
2587 char *name, char *value)
2589 if (wpa_config_set(ssid, name, value, 0) < 0) {
2590 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network "
2591 "variable '%s'", name);
2595 if (os_strcmp(name, "bssid") != 0 &&
2596 os_strcmp(name, "priority") != 0)
2597 wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
2599 if (wpa_s->current_ssid == ssid || wpa_s->current_ssid == NULL) {
2601 * Invalidate the EAP session cache if anything in the current
2602 * or previously used configuration changes.
2604 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2607 if ((os_strcmp(name, "psk") == 0 &&
2608 value[0] == '"' && ssid->ssid_len) ||
2609 (os_strcmp(name, "ssid") == 0 && ssid->passphrase))
2610 wpa_config_update_psk(ssid);
2611 else if (os_strcmp(name, "priority") == 0)
2612 wpa_config_update_prio_list(wpa_s->conf);
2613 else if (os_strcmp(name, "no_auto_peer") == 0)
2614 ssid->no_auto_peer = atoi(value);
2620 static int wpa_supplicant_ctrl_iface_set_network(
2621 struct wpa_supplicant *wpa_s, char *cmd)
2623 int id, ret, prev_bssid_set;
2624 struct wpa_ssid *ssid;
2626 u8 prev_bssid[ETH_ALEN];
2628 /* cmd: "<network id> <variable name> <value>" */
2629 name = os_strchr(cmd, ' ');
2634 value = os_strchr(name, ' ');
2640 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
2642 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
2643 (u8 *) value, os_strlen(value));
2645 ssid = wpa_config_get_network(wpa_s->conf, id);
2647 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2652 prev_bssid_set = ssid->bssid_set;
2653 os_memcpy(prev_bssid, ssid->bssid, ETH_ALEN);
2654 ret = wpa_supplicant_ctrl_iface_update_network(wpa_s, ssid, name,
2657 (ssid->bssid_set != prev_bssid_set ||
2658 os_memcmp(ssid->bssid, prev_bssid, ETH_ALEN) != 0))
2659 wpas_notify_network_bssid_set_changed(wpa_s, ssid);
2664 static int wpa_supplicant_ctrl_iface_get_network(
2665 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
2669 struct wpa_ssid *ssid;
2672 /* cmd: "<network id> <variable name>" */
2673 name = os_strchr(cmd, ' ');
2674 if (name == NULL || buflen == 0)
2679 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
2682 ssid = wpa_config_get_network(wpa_s->conf, id);
2684 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2689 value = wpa_config_get_no_key(ssid, name);
2690 if (value == NULL) {
2691 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
2692 "variable '%s'", name);
2696 res = os_strlcpy(buf, value, buflen);
2697 if (res >= buflen) {
2708 static int wpa_supplicant_ctrl_iface_dup_network(
2709 struct wpa_supplicant *wpa_s, char *cmd)
2711 struct wpa_ssid *ssid_s, *ssid_d;
2712 char *name, *id, *value;
2713 int id_s, id_d, ret;
2715 /* cmd: "<src network id> <dst network id> <variable name>" */
2716 id = os_strchr(cmd, ' ');
2721 name = os_strchr(id, ' ');
2728 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DUP_NETWORK id=%d -> %d name='%s'",
2731 ssid_s = wpa_config_get_network(wpa_s->conf, id_s);
2732 if (ssid_s == NULL) {
2733 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2734 "network id=%d", id_s);
2738 ssid_d = wpa_config_get_network(wpa_s->conf, id_d);
2739 if (ssid_d == NULL) {
2740 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2741 "network id=%d", id_s);
2745 value = wpa_config_get(ssid_s, name);
2746 if (value == NULL) {
2747 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
2748 "variable '%s'", name);
2752 ret = wpa_supplicant_ctrl_iface_update_network(wpa_s, ssid_d, name,
2761 static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant *wpa_s,
2762 char *buf, size_t buflen)
2765 struct wpa_cred *cred;
2770 ret = os_snprintf(pos, end - pos,
2771 "cred id / realm / username / domain / imsi\n");
2772 if (ret < 0 || ret >= end - pos)
2776 cred = wpa_s->conf->cred;
2778 ret = os_snprintf(pos, end - pos, "%d\t%s\t%s\t%s\t%s\n",
2779 cred->id, cred->realm ? cred->realm : "",
2780 cred->username ? cred->username : "",
2781 cred->domain ? cred->domain[0] : "",
2782 cred->imsi ? cred->imsi : "");
2783 if (ret < 0 || ret >= end - pos)
2794 static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant *wpa_s,
2795 char *buf, size_t buflen)
2797 struct wpa_cred *cred;
2800 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_CRED");
2802 cred = wpa_config_add_cred(wpa_s->conf);
2806 wpa_msg(wpa_s, MSG_INFO, CRED_ADDED "%d", cred->id);
2808 ret = os_snprintf(buf, buflen, "%d\n", cred->id);
2809 if (ret < 0 || (size_t) ret >= buflen)
2815 static int wpas_ctrl_remove_cred(struct wpa_supplicant *wpa_s,
2816 struct wpa_cred *cred)
2818 struct wpa_ssid *ssid;
2823 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred");
2828 if (wpa_config_remove_cred(wpa_s->conf, id) < 0) {
2829 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred");
2833 wpa_msg(wpa_s, MSG_INFO, CRED_REMOVED "%d", id);
2835 /* Remove any network entry created based on the removed credential */
2836 ssid = wpa_s->conf->ssid;
2838 if (ssid->parent_cred == cred) {
2839 wpa_printf(MSG_DEBUG, "Remove network id %d since it "
2840 "used the removed credential", ssid->id);
2841 os_snprintf(str, sizeof(str), "%d", ssid->id);
2843 wpa_supplicant_ctrl_iface_remove_network(wpa_s, str);
2852 static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s,
2856 struct wpa_cred *cred, *prev;
2858 /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or
2859 * "provisioning_sp=<FQDN> */
2860 if (os_strcmp(cmd, "all") == 0) {
2861 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED all");
2862 cred = wpa_s->conf->cred;
2866 wpas_ctrl_remove_cred(wpa_s, prev);
2871 if (os_strncmp(cmd, "sp_fqdn=", 8) == 0) {
2872 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
2874 cred = wpa_s->conf->cred;
2880 for (i = 0; i < prev->num_domain; i++) {
2881 if (os_strcmp(prev->domain[i], cmd + 8)
2884 wpas_ctrl_remove_cred(wpa_s, prev);
2892 if (os_strncmp(cmd, "provisioning_sp=", 16) == 0) {
2893 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'",
2895 cred = wpa_s->conf->cred;
2899 if (prev->provisioning_sp &&
2900 os_strcmp(prev->provisioning_sp, cmd + 16) == 0)
2901 wpas_ctrl_remove_cred(wpa_s, prev);
2907 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED id=%d", id);
2909 cred = wpa_config_get_cred(wpa_s->conf, id);
2910 return wpas_ctrl_remove_cred(wpa_s, cred);
2914 static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant *wpa_s,
2918 struct wpa_cred *cred;
2921 /* cmd: "<cred id> <variable name> <value>" */
2922 name = os_strchr(cmd, ' ');
2927 value = os_strchr(name, ' ');
2933 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_CRED id=%d name='%s'",
2935 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
2936 (u8 *) value, os_strlen(value));
2938 cred = wpa_config_get_cred(wpa_s->conf, id);
2940 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
2945 if (wpa_config_set_cred(cred, name, value, 0) < 0) {
2946 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set cred "
2947 "variable '%s'", name);
2951 wpa_msg(wpa_s, MSG_INFO, CRED_MODIFIED "%d %s", cred->id, name);
2957 static int wpa_supplicant_ctrl_iface_get_cred(struct wpa_supplicant *wpa_s,
2958 char *cmd, char *buf,
2963 struct wpa_cred *cred;
2966 /* cmd: "<cred id> <variable name>" */
2967 name = os_strchr(cmd, ' ');
2973 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CRED id=%d name='%s'",
2976 cred = wpa_config_get_cred(wpa_s->conf, id);
2978 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
2983 value = wpa_config_get_cred_no_key(cred, name);
2984 if (value == NULL) {
2985 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get cred variable '%s'",
2990 res = os_strlcpy(buf, value, buflen);
2991 if (res >= buflen) {
3002 #ifndef CONFIG_NO_CONFIG_WRITE
3003 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s)
3007 if (!wpa_s->conf->update_config) {
3008 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
3009 "to update configuration (update_config=0)");
3013 ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
3015 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to "
3016 "update configuration");
3018 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration"
3024 #endif /* CONFIG_NO_CONFIG_WRITE */
3027 struct cipher_info {
3033 static const struct cipher_info ciphers[] = {
3034 { WPA_DRIVER_CAPA_ENC_CCMP_256, "CCMP-256", 0 },
3035 { WPA_DRIVER_CAPA_ENC_GCMP_256, "GCMP-256", 0 },
3036 { WPA_DRIVER_CAPA_ENC_CCMP, "CCMP", 0 },
3037 { WPA_DRIVER_CAPA_ENC_GCMP, "GCMP", 0 },
3038 { WPA_DRIVER_CAPA_ENC_TKIP, "TKIP", 0 },
3039 { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE, "NONE", 0 },
3040 { WPA_DRIVER_CAPA_ENC_WEP104, "WEP104", 1 },
3041 { WPA_DRIVER_CAPA_ENC_WEP40, "WEP40", 1 }
3045 static int ctrl_iface_get_capability_pairwise(int res, char *strict,
3046 struct wpa_driver_capa *capa,
3047 char *buf, size_t buflen)
3060 len = os_strlcpy(buf, "CCMP TKIP NONE", buflen);
3066 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
3067 if (!ciphers[i].group_only && capa->enc & ciphers[i].capa) {
3068 ret = os_snprintf(pos, end - pos, "%s%s",
3069 pos == buf ? "" : " ",
3071 if (ret < 0 || ret >= end - pos)
3081 static int ctrl_iface_get_capability_group(int res, char *strict,
3082 struct wpa_driver_capa *capa,
3083 char *buf, size_t buflen)
3096 len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen);
3102 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
3103 if (capa->enc & ciphers[i].capa) {
3104 ret = os_snprintf(pos, end - pos, "%s%s",
3105 pos == buf ? "" : " ",
3107 if (ret < 0 || ret >= end - pos)
3117 static int ctrl_iface_get_capability_key_mgmt(int res, char *strict,
3118 struct wpa_driver_capa *capa,
3119 char *buf, size_t buflen)
3131 len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
3138 ret = os_snprintf(pos, end - pos, "NONE IEEE8021X");
3139 if (ret < 0 || ret >= end - pos)
3143 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
3144 WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
3145 ret = os_snprintf(pos, end - pos, " WPA-EAP");
3146 if (ret < 0 || ret >= end - pos)
3151 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
3152 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
3153 ret = os_snprintf(pos, end - pos, " WPA-PSK");
3154 if (ret < 0 || ret >= end - pos)
3159 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
3160 ret = os_snprintf(pos, end - pos, " WPA-NONE");
3161 if (ret < 0 || ret >= end - pos)
3170 static int ctrl_iface_get_capability_proto(int res, char *strict,
3171 struct wpa_driver_capa *capa,
3172 char *buf, size_t buflen)
3184 len = os_strlcpy(buf, "RSN WPA", buflen);
3190 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
3191 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
3192 ret = os_snprintf(pos, end - pos, "%sRSN",
3193 pos == buf ? "" : " ");
3194 if (ret < 0 || ret >= end - pos)
3199 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
3200 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
3201 ret = os_snprintf(pos, end - pos, "%sWPA",
3202 pos == buf ? "" : " ");
3203 if (ret < 0 || ret >= end - pos)
3212 static int ctrl_iface_get_capability_auth_alg(int res, char *strict,
3213 struct wpa_driver_capa *capa,
3214 char *buf, size_t buflen)
3226 len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen);
3232 if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) {
3233 ret = os_snprintf(pos, end - pos, "%sOPEN",
3234 pos == buf ? "" : " ");
3235 if (ret < 0 || ret >= end - pos)
3240 if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) {
3241 ret = os_snprintf(pos, end - pos, "%sSHARED",
3242 pos == buf ? "" : " ");
3243 if (ret < 0 || ret >= end - pos)
3248 if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) {
3249 ret = os_snprintf(pos, end - pos, "%sLEAP",
3250 pos == buf ? "" : " ");
3251 if (ret < 0 || ret >= end - pos)
3260 static int ctrl_iface_get_capability_modes(int res, char *strict,
3261 struct wpa_driver_capa *capa,
3262 char *buf, size_t buflen)
3274 len = os_strlcpy(buf, "IBSS AP", buflen);
3280 if (capa->flags & WPA_DRIVER_FLAGS_IBSS) {
3281 ret = os_snprintf(pos, end - pos, "%sIBSS",
3282 pos == buf ? "" : " ");
3283 if (ret < 0 || ret >= end - pos)
3288 if (capa->flags & WPA_DRIVER_FLAGS_AP) {
3289 ret = os_snprintf(pos, end - pos, "%sAP",
3290 pos == buf ? "" : " ");
3291 if (ret < 0 || ret >= end - pos)
3300 static int ctrl_iface_get_capability_channels(struct wpa_supplicant *wpa_s,
3301 char *buf, size_t buflen)
3303 struct hostapd_channel_data *chnl;
3305 char *pos, *end, *hmode;
3310 for (j = 0; j < wpa_s->hw.num_modes; j++) {
3311 switch (wpa_s->hw.modes[j].mode) {
3312 case HOSTAPD_MODE_IEEE80211B:
3315 case HOSTAPD_MODE_IEEE80211G:
3318 case HOSTAPD_MODE_IEEE80211A:
3321 case HOSTAPD_MODE_IEEE80211AD:
3327 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:", hmode);
3328 if (ret < 0 || ret >= end - pos)
3331 chnl = wpa_s->hw.modes[j].channels;
3332 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
3333 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
3335 ret = os_snprintf(pos, end - pos, " %d", chnl[i].chan);
3336 if (ret < 0 || ret >= end - pos)
3340 ret = os_snprintf(pos, end - pos, "\n");
3341 if (ret < 0 || ret >= end - pos)
3350 static int ctrl_iface_get_capability_freq(struct wpa_supplicant *wpa_s,
3351 char *buf, size_t buflen)
3353 struct hostapd_channel_data *chnl;
3355 char *pos, *end, *hmode;
3360 for (j = 0; j < wpa_s->hw.num_modes; j++) {
3361 switch (wpa_s->hw.modes[j].mode) {
3362 case HOSTAPD_MODE_IEEE80211B:
3365 case HOSTAPD_MODE_IEEE80211G:
3368 case HOSTAPD_MODE_IEEE80211A:
3371 case HOSTAPD_MODE_IEEE80211AD:
3377 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:\n",
3379 if (ret < 0 || ret >= end - pos)
3382 chnl = wpa_s->hw.modes[j].channels;
3383 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
3384 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
3386 ret = os_snprintf(pos, end - pos, " %d = %d MHz%s%s\n",
3387 chnl[i].chan, chnl[i].freq,
3388 chnl[i].flag & HOSTAPD_CHAN_NO_IBSS ?
3390 chnl[i].flag & HOSTAPD_CHAN_RADAR ?
3393 if (ret < 0 || ret >= end - pos)
3397 ret = os_snprintf(pos, end - pos, "\n");
3398 if (ret < 0 || ret >= end - pos)
3407 static int wpa_supplicant_ctrl_iface_get_capability(
3408 struct wpa_supplicant *wpa_s, const char *_field, char *buf,
3411 struct wpa_driver_capa capa;
3417 /* Determine whether or not strict checking was requested */
3418 len = os_strlcpy(field, _field, sizeof(field));
3419 if (len >= sizeof(field))
3421 strict = os_strchr(field, ' ');
3422 if (strict != NULL) {
3424 if (os_strcmp(strict, "strict") != 0)
3428 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
3429 field, strict ? strict : "");
3431 if (os_strcmp(field, "eap") == 0) {
3432 return eap_get_names(buf, buflen);
3435 res = wpa_drv_get_capa(wpa_s, &capa);
3437 if (os_strcmp(field, "pairwise") == 0)
3438 return ctrl_iface_get_capability_pairwise(res, strict, &capa,
3441 if (os_strcmp(field, "group") == 0)
3442 return ctrl_iface_get_capability_group(res, strict, &capa,
3445 if (os_strcmp(field, "key_mgmt") == 0)
3446 return ctrl_iface_get_capability_key_mgmt(res, strict, &capa,
3449 if (os_strcmp(field, "proto") == 0)
3450 return ctrl_iface_get_capability_proto(res, strict, &capa,
3453 if (os_strcmp(field, "auth_alg") == 0)
3454 return ctrl_iface_get_capability_auth_alg(res, strict, &capa,
3457 if (os_strcmp(field, "modes") == 0)
3458 return ctrl_iface_get_capability_modes(res, strict, &capa,
3461 if (os_strcmp(field, "channels") == 0)
3462 return ctrl_iface_get_capability_channels(wpa_s, buf, buflen);
3464 if (os_strcmp(field, "freq") == 0)
3465 return ctrl_iface_get_capability_freq(wpa_s, buf, buflen);
3468 if (os_strcmp(field, "tdls") == 0)
3469 return ctrl_iface_get_capability_tdls(wpa_s, buf, buflen);
3470 #endif /* CONFIG_TDLS */
3472 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
3479 #ifdef CONFIG_INTERWORKING
3480 static char * anqp_add_hex(char *pos, char *end, const char *title,
3481 struct wpabuf *data)
3491 ret = os_snprintf(pos, end - pos, "%s=", title);
3492 if (ret < 0 || ret >= end - pos)
3496 d = wpabuf_head_u8(data);
3497 for (i = 0; i < wpabuf_len(data); i++) {
3498 ret = os_snprintf(pos, end - pos, "%02x", *d++);
3499 if (ret < 0 || ret >= end - pos)
3504 ret = os_snprintf(pos, end - pos, "\n");
3505 if (ret < 0 || ret >= end - pos)
3511 #endif /* CONFIG_INTERWORKING */
3514 static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
3515 unsigned long mask, char *buf, size_t buflen)
3525 if (mask & WPA_BSS_MASK_ID) {
3526 ret = os_snprintf(pos, end - pos, "id=%u\n", bss->id);
3527 if (ret < 0 || ret >= end - pos)
3532 if (mask & WPA_BSS_MASK_BSSID) {
3533 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
3534 MAC2STR(bss->bssid));
3535 if (ret < 0 || ret >= end - pos)
3540 if (mask & WPA_BSS_MASK_FREQ) {
3541 ret = os_snprintf(pos, end - pos, "freq=%d\n", bss->freq);
3542 if (ret < 0 || ret >= end - pos)
3547 if (mask & WPA_BSS_MASK_BEACON_INT) {
3548 ret = os_snprintf(pos, end - pos, "beacon_int=%d\n",
3550 if (ret < 0 || ret >= end - pos)
3555 if (mask & WPA_BSS_MASK_CAPABILITIES) {
3556 ret = os_snprintf(pos, end - pos, "capabilities=0x%04x\n",
3558 if (ret < 0 || ret >= end - pos)
3563 if (mask & WPA_BSS_MASK_QUAL) {
3564 ret = os_snprintf(pos, end - pos, "qual=%d\n", bss->qual);
3565 if (ret < 0 || ret >= end - pos)
3570 if (mask & WPA_BSS_MASK_NOISE) {
3571 ret = os_snprintf(pos, end - pos, "noise=%d\n", bss->noise);
3572 if (ret < 0 || ret >= end - pos)
3577 if (mask & WPA_BSS_MASK_LEVEL) {
3578 ret = os_snprintf(pos, end - pos, "level=%d\n", bss->level);
3579 if (ret < 0 || ret >= end - pos)
3584 if (mask & WPA_BSS_MASK_TSF) {
3585 ret = os_snprintf(pos, end - pos, "tsf=%016llu\n",
3586 (unsigned long long) bss->tsf);
3587 if (ret < 0 || ret >= end - pos)
3592 if (mask & WPA_BSS_MASK_AGE) {
3593 struct os_reltime now;
3595 os_get_reltime(&now);
3596 ret = os_snprintf(pos, end - pos, "age=%d\n",
3597 (int) (now.sec - bss->last_update.sec));
3598 if (ret < 0 || ret >= end - pos)
3603 if (mask & WPA_BSS_MASK_IE) {
3604 ret = os_snprintf(pos, end - pos, "ie=");
3605 if (ret < 0 || ret >= end - pos)
3609 ie = (const u8 *) (bss + 1);
3610 for (i = 0; i < bss->ie_len; i++) {
3611 ret = os_snprintf(pos, end - pos, "%02x", *ie++);
3612 if (ret < 0 || ret >= end - pos)
3617 ret = os_snprintf(pos, end - pos, "\n");
3618 if (ret < 0 || ret >= end - pos)
3623 if (mask & WPA_BSS_MASK_FLAGS) {
3624 ret = os_snprintf(pos, end - pos, "flags=");
3625 if (ret < 0 || ret >= end - pos)
3629 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
3631 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie,
3633 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
3635 pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2,
3637 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
3638 if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
3639 ret = os_snprintf(pos, end - pos, "[WEP]");
3640 if (ret < 0 || ret >= end - pos)
3644 if (bss_is_dmg(bss)) {
3646 ret = os_snprintf(pos, end - pos, "[DMG]");
3647 if (ret < 0 || ret >= end - pos)
3650 switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
3651 case IEEE80211_CAP_DMG_IBSS:
3654 case IEEE80211_CAP_DMG_AP:
3657 case IEEE80211_CAP_DMG_PBSS:
3664 ret = os_snprintf(pos, end - pos, "%s", s);
3665 if (ret < 0 || ret >= end - pos)
3669 if (bss->caps & IEEE80211_CAP_IBSS) {
3670 ret = os_snprintf(pos, end - pos, "[IBSS]");
3671 if (ret < 0 || ret >= end - pos)
3675 if (bss->caps & IEEE80211_CAP_ESS) {
3676 ret = os_snprintf(pos, end - pos, "[ESS]");
3677 if (ret < 0 || ret >= end - pos)
3682 if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
3683 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
3684 ret = os_snprintf(pos, end - pos, "[P2P]");
3685 if (ret < 0 || ret >= end - pos)
3690 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) {
3691 ret = os_snprintf(pos, end - pos, "[HS20]");
3692 if (ret < 0 || ret >= end - pos)
3696 #endif /* CONFIG_HS20 */
3698 ret = os_snprintf(pos, end - pos, "\n");
3699 if (ret < 0 || ret >= end - pos)
3704 if (mask & WPA_BSS_MASK_SSID) {
3705 ret = os_snprintf(pos, end - pos, "ssid=%s\n",
3706 wpa_ssid_txt(bss->ssid, bss->ssid_len));
3707 if (ret < 0 || ret >= end - pos)
3713 if (mask & WPA_BSS_MASK_WPS_SCAN) {
3714 ie = (const u8 *) (bss + 1);
3715 ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end);
3716 if (ret < 0 || ret >= end - pos)
3720 #endif /* CONFIG_WPS */
3723 if (mask & WPA_BSS_MASK_P2P_SCAN) {
3724 ie = (const u8 *) (bss + 1);
3725 ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end);
3726 if (ret < 0 || ret >= end - pos)
3730 #endif /* CONFIG_P2P */
3732 #ifdef CONFIG_WIFI_DISPLAY
3733 if (mask & WPA_BSS_MASK_WIFI_DISPLAY) {
3735 ie = (const u8 *) (bss + 1);
3736 wfd = ieee802_11_vendor_ie_concat(ie, bss->ie_len,
3737 WFD_IE_VENDOR_TYPE);
3739 ret = os_snprintf(pos, end - pos, "wfd_subelems=");
3740 if (ret < 0 || ret >= end - pos) {
3746 pos += wpa_snprintf_hex(pos, end - pos,
3751 ret = os_snprintf(pos, end - pos, "\n");
3752 if (ret < 0 || ret >= end - pos)
3757 #endif /* CONFIG_WIFI_DISPLAY */
3759 #ifdef CONFIG_INTERWORKING
3760 if ((mask & WPA_BSS_MASK_INTERNETW) && bss->anqp) {
3761 struct wpa_bss_anqp *anqp = bss->anqp;
3762 pos = anqp_add_hex(pos, end, "anqp_venue_name",
3764 pos = anqp_add_hex(pos, end, "anqp_network_auth_type",
3765 anqp->network_auth_type);
3766 pos = anqp_add_hex(pos, end, "anqp_roaming_consortium",
3767 anqp->roaming_consortium);
3768 pos = anqp_add_hex(pos, end, "anqp_ip_addr_type_availability",
3769 anqp->ip_addr_type_availability);
3770 pos = anqp_add_hex(pos, end, "anqp_nai_realm",
3772 pos = anqp_add_hex(pos, end, "anqp_3gpp", anqp->anqp_3gpp);
3773 pos = anqp_add_hex(pos, end, "anqp_domain_name",
3776 pos = anqp_add_hex(pos, end, "hs20_operator_friendly_name",
3777 anqp->hs20_operator_friendly_name);
3778 pos = anqp_add_hex(pos, end, "hs20_wan_metrics",
3779 anqp->hs20_wan_metrics);
3780 pos = anqp_add_hex(pos, end, "hs20_connection_capability",
3781 anqp->hs20_connection_capability);
3782 pos = anqp_add_hex(pos, end, "hs20_operating_class",
3783 anqp->hs20_operating_class);
3784 pos = anqp_add_hex(pos, end, "hs20_osu_providers_list",
3785 anqp->hs20_osu_providers_list);
3786 #endif /* CONFIG_HS20 */
3788 #endif /* CONFIG_INTERWORKING */
3790 if (mask & WPA_BSS_MASK_DELIM) {
3791 ret = os_snprintf(pos, end - pos, "====\n");
3792 if (ret < 0 || ret >= end - pos)
3801 static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
3802 const char *cmd, char *buf,
3807 struct wpa_bss *bss;
3808 struct wpa_bss *bsslast = NULL;
3809 struct dl_list *next;
3813 unsigned long mask = WPA_BSS_MASK_ALL;
3815 if (os_strncmp(cmd, "RANGE=", 6) == 0) {
3816 if (os_strncmp(cmd + 6, "ALL", 3) == 0) {
3817 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss,
3819 bsslast = dl_list_last(&wpa_s->bss_id, struct wpa_bss,
3821 } else { /* N1-N2 */
3822 unsigned int id1, id2;
3824 if ((ctmp = os_strchr(cmd + 6, '-')) == NULL) {
3825 wpa_printf(MSG_INFO, "Wrong BSS range "
3830 if (*(cmd + 6) == '-')
3833 id1 = atoi(cmd + 6);
3835 if (*ctmp >= '0' && *ctmp <= '9')
3838 id2 = (unsigned int) -1;
3839 bss = wpa_bss_get_id_range(wpa_s, id1, id2);
3840 if (id2 == (unsigned int) -1)
3841 bsslast = dl_list_last(&wpa_s->bss_id,
3845 bsslast = wpa_bss_get_id(wpa_s, id2);
3846 if (bsslast == NULL && bss && id2 > id1) {
3847 struct wpa_bss *tmp = bss;
3849 next = tmp->list_id.next;
3850 if (next == &wpa_s->bss_id)
3852 tmp = dl_list_entry(
3853 next, struct wpa_bss,
3862 } else if (os_strncmp(cmd, "FIRST", 5) == 0)
3863 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, list_id);
3864 else if (os_strncmp(cmd, "LAST", 4) == 0)
3865 bss = dl_list_last(&wpa_s->bss_id, struct wpa_bss, list_id);
3866 else if (os_strncmp(cmd, "ID-", 3) == 0) {
3868 bss = wpa_bss_get_id(wpa_s, i);
3869 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
3871 bss = wpa_bss_get_id(wpa_s, i);
3873 next = bss->list_id.next;
3874 if (next == &wpa_s->bss_id)
3877 bss = dl_list_entry(next, struct wpa_bss,
3881 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
3882 if (hwaddr_aton(cmd + 13, bssid) == 0)
3883 bss = wpa_bss_get_p2p_dev_addr(wpa_s, bssid);
3886 #endif /* CONFIG_P2P */
3887 } else if (hwaddr_aton(cmd, bssid) == 0)
3888 bss = wpa_bss_get_bssid(wpa_s, bssid);
3890 struct wpa_bss *tmp;
3893 dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id)
3902 if ((ctmp = os_strstr(cmd, "MASK=")) != NULL) {
3903 mask = strtoul(ctmp + 5, NULL, 0x10);
3905 mask = WPA_BSS_MASK_ALL;
3911 if (bsslast == NULL)
3914 len = print_bss_info(wpa_s, bss, mask, buf, buflen);
3918 if (bss == bsslast) {
3919 if ((mask & WPA_BSS_MASK_DELIM) && len &&
3920 (bss == dl_list_last(&wpa_s->bss_id,
3921 struct wpa_bss, list_id)))
3922 os_snprintf(buf - 5, 5, "####\n");
3925 next = bss->list_id.next;
3926 if (next == &wpa_s->bss_id)
3928 bss = dl_list_entry(next, struct wpa_bss, list_id);
3929 } while (bss && len);
3935 static int wpa_supplicant_ctrl_iface_ap_scan(
3936 struct wpa_supplicant *wpa_s, char *cmd)
3938 int ap_scan = atoi(cmd);
3939 return wpa_supplicant_set_ap_scan(wpa_s, ap_scan);
3943 static int wpa_supplicant_ctrl_iface_scan_interval(
3944 struct wpa_supplicant *wpa_s, char *cmd)
3946 int scan_int = atoi(cmd);
3947 return wpa_supplicant_set_scan_interval(wpa_s, scan_int);
3951 static int wpa_supplicant_ctrl_iface_bss_expire_age(
3952 struct wpa_supplicant *wpa_s, char *cmd)
3954 int expire_age = atoi(cmd);
3955 return wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age);
3959 static int wpa_supplicant_ctrl_iface_bss_expire_count(
3960 struct wpa_supplicant *wpa_s, char *cmd)
3962 int expire_count = atoi(cmd);
3963 return wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count);
3967 static int wpa_supplicant_ctrl_iface_bss_flush(
3968 struct wpa_supplicant *wpa_s, char *cmd)
3970 int flush_age = atoi(cmd);
3973 wpa_bss_flush(wpa_s);
3975 wpa_bss_flush_by_age(wpa_s, flush_age);
3980 #ifdef CONFIG_TESTING_OPTIONS
3981 static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s)
3983 wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication");
3984 /* MLME-DELETEKEYS.request */
3985 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL, 0);
3986 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL, 0);
3987 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL, 0);
3988 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL, 0);
3989 #ifdef CONFIG_IEEE80211W
3990 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL, 0);
3991 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL, 0);
3992 #endif /* CONFIG_IEEE80211W */
3994 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, wpa_s->bssid, 0, 0, NULL, 0, NULL,
3996 /* MLME-SETPROTECTION.request(None) */
3997 wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid,
3998 MLME_SETPROTECTION_PROTECT_TYPE_NONE,
3999 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE);
4000 wpa_sm_drop_sa(wpa_s->wpa);
4002 #endif /* CONFIG_TESTING_OPTIONS */
4005 static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s,
4008 #ifdef CONFIG_NO_SCAN_PROCESSING
4010 #else /* CONFIG_NO_SCAN_PROCESSING */
4012 struct wpa_bss *bss;
4013 struct wpa_ssid *ssid = wpa_s->current_ssid;
4015 if (hwaddr_aton(addr, bssid)) {
4016 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid "
4017 "address '%s'", addr);
4021 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR, MAC2STR(bssid));
4024 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network "
4025 "configuration known for the target AP");
4029 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
4031 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found "
4037 * TODO: Find best network configuration block from configuration to
4038 * allow roaming to other networks
4041 wpa_s->reassociate = 1;
4042 wpa_supplicant_connect(wpa_s, bss, ssid);
4045 #endif /* CONFIG_NO_SCAN_PROCESSING */
4050 static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd)
4052 unsigned int timeout = atoi(cmd);
4053 enum p2p_discovery_type type = P2P_FIND_START_WITH_FULL;
4054 u8 dev_id[ETH_ALEN], *_dev_id = NULL;
4055 u8 dev_type[WPS_DEV_TYPE_LEN], *_dev_type = NULL;
4057 unsigned int search_delay;
4059 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
4060 wpa_dbg(wpa_s, MSG_INFO,
4061 "Reject P2P_FIND since interface is disabled");
4064 if (os_strstr(cmd, "type=social"))
4065 type = P2P_FIND_ONLY_SOCIAL;
4066 else if (os_strstr(cmd, "type=progressive"))
4067 type = P2P_FIND_PROGRESSIVE;
4069 pos = os_strstr(cmd, "dev_id=");
4072 if (hwaddr_aton(pos, dev_id))
4077 pos = os_strstr(cmd, "dev_type=");
4080 if (wps_dev_type_str2bin(pos, dev_type) < 0)
4082 _dev_type = dev_type;
4085 pos = os_strstr(cmd, "delay=");
4088 search_delay = atoi(pos);
4090 search_delay = wpas_p2p_search_delay(wpa_s);
4092 return wpas_p2p_find(wpa_s, timeout, type, _dev_type != NULL, _dev_type,
4093 _dev_id, search_delay);
4097 static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd,
4098 char *buf, size_t buflen)
4103 enum p2p_wps_method wps_method;
4106 int persistent_group, persistent_id = -1;
4115 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad]
4116 * [persistent|persistent=<network id>]
4117 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
4120 if (hwaddr_aton(cmd, addr))
4128 persistent_group = os_strstr(pos, " persistent") != NULL;
4129 pos2 = os_strstr(pos, " persistent=");
4131 struct wpa_ssid *ssid;
4132 persistent_id = atoi(pos2 + 12);
4133 ssid = wpa_config_get_network(wpa_s->conf, persistent_id);
4134 if (ssid == NULL || ssid->disabled != 2 ||
4135 ssid->mode != WPAS_MODE_P2P_GO) {
4136 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
4137 "SSID id=%d for persistent P2P group (GO)",
4142 join = os_strstr(pos, " join") != NULL;
4143 auth = os_strstr(pos, " auth") != NULL;
4144 automatic = os_strstr(pos, " auto") != NULL;
4145 pd = os_strstr(pos, " provdisc") != NULL;
4146 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
4147 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
4150 pos2 = os_strstr(pos, " go_intent=");
4153 go_intent = atoi(pos2);
4154 if (go_intent < 0 || go_intent > 15)
4158 pos2 = os_strstr(pos, " freq=");
4166 if (os_strncmp(pos, "pin", 3) == 0) {
4167 /* Request random PIN (to be displayed) and enable the PIN */
4168 wps_method = WPS_PIN_DISPLAY;
4169 } else if (os_strncmp(pos, "pbc", 3) == 0) {
4170 wps_method = WPS_PBC;
4173 pos = os_strchr(pin, ' ');
4174 wps_method = WPS_PIN_KEYPAD;
4177 if (os_strncmp(pos, "display", 7) == 0)
4178 wps_method = WPS_PIN_DISPLAY;
4180 if (!wps_pin_str_valid(pin)) {
4181 os_memcpy(buf, "FAIL-INVALID-PIN\n", 17);
4186 new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method,
4187 persistent_group, automatic, join,
4188 auth, go_intent, freq, persistent_id, pd,
4190 if (new_pin == -2) {
4191 os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
4194 if (new_pin == -3) {
4195 os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
4200 if (wps_method == WPS_PIN_DISPLAY && pin == NULL) {
4201 ret = os_snprintf(buf, buflen, "%08d", new_pin);
4202 if (ret < 0 || (size_t) ret >= buflen)
4207 os_memcpy(buf, "OK\n", 3);
4212 static int p2p_ctrl_listen(struct wpa_supplicant *wpa_s, char *cmd)
4214 unsigned int timeout = atoi(cmd);
4215 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
4216 wpa_dbg(wpa_s, MSG_INFO,
4217 "Reject P2P_LISTEN since interface is disabled");
4220 return wpas_p2p_listen(wpa_s, timeout);
4224 static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd)
4228 enum wpas_p2p_prov_disc_use use = WPAS_P2P_PD_FOR_GO_NEG;
4230 /* <addr> <config method> [join|auto] */
4232 if (hwaddr_aton(cmd, addr))
4240 if (os_strstr(pos, " join") != NULL)
4241 use = WPAS_P2P_PD_FOR_JOIN;
4242 else if (os_strstr(pos, " auto") != NULL)
4243 use = WPAS_P2P_PD_AUTO;
4245 return wpas_p2p_prov_disc(wpa_s, addr, pos, use);
4249 static int p2p_get_passphrase(struct wpa_supplicant *wpa_s, char *buf,
4252 struct wpa_ssid *ssid = wpa_s->current_ssid;
4254 if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO ||
4255 ssid->passphrase == NULL)
4258 os_strlcpy(buf, ssid->passphrase, buflen);
4259 return os_strlen(buf);
4263 static int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd,
4264 char *buf, size_t buflen)
4268 u8 dst_buf[ETH_ALEN], *dst;
4269 struct wpabuf *tlvs;
4273 if (hwaddr_aton(cmd, dst_buf))
4276 if (dst[0] == 0 && dst[1] == 0 && dst[2] == 0 &&
4277 dst[3] == 0 && dst[4] == 0 && dst[5] == 0)
4284 if (os_strncmp(pos, "upnp ", 5) == 0) {
4287 if (hexstr2bin(pos, &version, 1) < 0)
4293 ref = wpas_p2p_sd_request_upnp(wpa_s, dst, version, pos);
4294 #ifdef CONFIG_WIFI_DISPLAY
4295 } else if (os_strncmp(pos, "wifi-display ", 13) == 0) {
4296 ref = wpas_p2p_sd_request_wifi_display(wpa_s, dst, pos + 13);
4297 #endif /* CONFIG_WIFI_DISPLAY */
4299 len = os_strlen(pos);
4303 tlvs = wpabuf_alloc(len);
4306 if (hexstr2bin(pos, wpabuf_put(tlvs, len), len) < 0) {
4311 ref = wpas_p2p_sd_request(wpa_s, dst, tlvs);
4316 res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref);
4317 if (res < 0 || (unsigned) res >= buflen)
4323 static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s,
4326 long long unsigned val;
4328 if (sscanf(cmd, "%llx", &val) != 1)
4331 return wpas_p2p_sd_cancel_request(wpa_s, req);
4335 static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant *wpa_s, char *cmd)
4340 struct wpabuf *resp_tlvs;
4344 pos = os_strchr(cmd, ' ');
4352 if (hwaddr_aton(pos, dst))
4359 pos2 = os_strchr(pos, ' ');
4363 dialog_token = atoi(pos);
4365 len = os_strlen(pos2);
4369 resp_tlvs = wpabuf_alloc(len);
4370 if (resp_tlvs == NULL)
4372 if (hexstr2bin(pos2, wpabuf_put(resp_tlvs, len), len) < 0) {
4373 wpabuf_free(resp_tlvs);
4377 wpas_p2p_sd_response(wpa_s, freq, dst, dialog_token, resp_tlvs);
4378 wpabuf_free(resp_tlvs);
4383 static int p2p_ctrl_serv_disc_external(struct wpa_supplicant *wpa_s,
4386 if (os_strcmp(cmd, "0") && os_strcmp(cmd, "1"))
4388 wpa_s->p2p_sd_over_ctrl_iface = atoi(cmd);
4393 static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant *wpa_s,
4398 struct wpabuf *query, *resp;
4400 pos = os_strchr(cmd, ' ');
4405 len = os_strlen(cmd);
4409 query = wpabuf_alloc(len);
4412 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
4417 len = os_strlen(pos);
4423 resp = wpabuf_alloc(len);
4428 if (hexstr2bin(pos, wpabuf_put(resp, len), len) < 0) {
4434 if (wpas_p2p_service_add_bonjour(wpa_s, query, resp) < 0) {
4443 static int p2p_ctrl_service_add_upnp(struct wpa_supplicant *wpa_s, char *cmd)
4448 pos = os_strchr(cmd, ' ');
4453 if (hexstr2bin(cmd, &version, 1) < 0)
4456 return wpas_p2p_service_add_upnp(wpa_s, version, pos);
4460 static int p2p_ctrl_service_add(struct wpa_supplicant *wpa_s, char *cmd)
4464 pos = os_strchr(cmd, ' ');
4469 if (os_strcmp(cmd, "bonjour") == 0)
4470 return p2p_ctrl_service_add_bonjour(wpa_s, pos);
4471 if (os_strcmp(cmd, "upnp") == 0)
4472 return p2p_ctrl_service_add_upnp(wpa_s, pos);
4473 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
4478 static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant *wpa_s,
4482 struct wpabuf *query;
4485 len = os_strlen(cmd);
4489 query = wpabuf_alloc(len);
4492 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
4497 ret = wpas_p2p_service_del_bonjour(wpa_s, query);
4503 static int p2p_ctrl_service_del_upnp(struct wpa_supplicant *wpa_s, char *cmd)
4508 pos = os_strchr(cmd, ' ');
4513 if (hexstr2bin(cmd, &version, 1) < 0)
4516 return wpas_p2p_service_del_upnp(wpa_s, version, pos);
4520 static int p2p_ctrl_service_del(struct wpa_supplicant *wpa_s, char *cmd)
4524 pos = os_strchr(cmd, ' ');
4529 if (os_strcmp(cmd, "bonjour") == 0)
4530 return p2p_ctrl_service_del_bonjour(wpa_s, pos);
4531 if (os_strcmp(cmd, "upnp") == 0)
4532 return p2p_ctrl_service_del_upnp(wpa_s, pos);
4533 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
4538 static int p2p_ctrl_reject(struct wpa_supplicant *wpa_s, char *cmd)
4544 if (hwaddr_aton(cmd, addr))
4547 return wpas_p2p_reject(wpa_s, addr);
4551 static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd)
4555 struct wpa_ssid *ssid;
4556 u8 *_peer = NULL, peer[ETH_ALEN];
4557 int freq = 0, pref_freq = 0;
4561 pos = os_strstr(cmd, " peer=");
4564 if (hwaddr_aton(pos, peer))
4568 ssid = wpa_config_get_network(wpa_s->conf, id);
4569 if (ssid == NULL || ssid->disabled != 2) {
4570 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
4571 "for persistent P2P group",
4576 pos = os_strstr(cmd, " freq=");
4584 pos = os_strstr(cmd, " pref=");
4587 pref_freq = atoi(pos);
4592 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
4593 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
4596 return wpas_p2p_invite(wpa_s, _peer, ssid, NULL, freq, ht40, vht,
4601 static int p2p_ctrl_invite_group(struct wpa_supplicant *wpa_s, char *cmd)
4604 u8 peer[ETH_ALEN], go_dev_addr[ETH_ALEN], *go_dev = NULL;
4606 pos = os_strstr(cmd, " peer=");
4612 if (hwaddr_aton(pos, peer)) {
4613 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", pos);
4617 pos = os_strstr(pos, " go_dev_addr=");
4620 if (hwaddr_aton(pos, go_dev_addr)) {
4621 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'",
4625 go_dev = go_dev_addr;
4628 return wpas_p2p_invite_group(wpa_s, cmd, peer, go_dev);
4632 static int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd)
4634 if (os_strncmp(cmd, "persistent=", 11) == 0)
4635 return p2p_ctrl_invite_persistent(wpa_s, cmd + 11);
4636 if (os_strncmp(cmd, "group=", 6) == 0)
4637 return p2p_ctrl_invite_group(wpa_s, cmd + 6);
4643 static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s,
4644 char *cmd, int freq, int ht40,
4648 struct wpa_ssid *ssid;
4651 ssid = wpa_config_get_network(wpa_s->conf, id);
4652 if (ssid == NULL || ssid->disabled != 2) {
4653 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
4654 "for persistent P2P group",
4659 return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq, 0, ht40, vht,
4664 static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd)
4666 int freq = 0, ht40, vht;
4669 pos = os_strstr(cmd, "freq=");
4671 freq = atoi(pos + 5);
4673 vht = (os_strstr(cmd, "vht") != NULL) || wpa_s->conf->p2p_go_vht;
4674 ht40 = (os_strstr(cmd, "ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
4677 if (os_strncmp(cmd, "persistent=", 11) == 0)
4678 return p2p_ctrl_group_add_persistent(wpa_s, cmd + 11, freq,
4680 if (os_strcmp(cmd, "persistent") == 0 ||
4681 os_strncmp(cmd, "persistent ", 11) == 0)
4682 return wpas_p2p_group_add(wpa_s, 1, freq, ht40, vht);
4683 if (os_strncmp(cmd, "freq=", 5) == 0)
4684 return wpas_p2p_group_add(wpa_s, 0, freq, ht40, vht);
4686 return wpas_p2p_group_add(wpa_s, 0, freq, ht40, vht);
4688 wpa_printf(MSG_DEBUG, "CTRL: Invalid P2P_GROUP_ADD parameters '%s'",
4694 static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd,
4695 char *buf, size_t buflen)
4697 u8 addr[ETH_ALEN], *addr_ptr;
4699 const struct p2p_peer_info *info;
4701 char devtype[WPS_DEV_TYPE_BUFSIZE];
4702 struct wpa_ssid *ssid;
4705 if (!wpa_s->global->p2p)
4708 if (os_strcmp(cmd, "FIRST") == 0) {
4711 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
4712 if (hwaddr_aton(cmd + 5, addr) < 0)
4717 if (hwaddr_aton(cmd, addr) < 0)
4723 info = p2p_get_peer_info(wpa_s->global->p2p, addr_ptr, next);
4730 res = os_snprintf(pos, end - pos, MACSTR "\n"
4736 "serial_number=%s\n"
4737 "config_methods=0x%x\n"
4739 "group_capab=0x%x\n"
4741 MAC2STR(info->p2p_device_addr),
4742 wps_dev_type_bin2str(info->pri_dev_type,
4743 devtype, sizeof(devtype)),
4748 info->serial_number,
4749 info->config_methods,
4753 if (res < 0 || res >= end - pos)
4757 for (i = 0; i < info->wps_sec_dev_type_list_len / WPS_DEV_TYPE_LEN; i++)
4760 t = &info->wps_sec_dev_type_list[i * WPS_DEV_TYPE_LEN];
4761 res = os_snprintf(pos, end - pos, "sec_dev_type=%s\n",
4762 wps_dev_type_bin2str(t, devtype,
4764 if (res < 0 || res >= end - pos)
4769 ssid = wpas_p2p_get_persistent(wpa_s, info->p2p_device_addr, NULL, 0);
4771 res = os_snprintf(pos, end - pos, "persistent=%d\n", ssid->id);
4772 if (res < 0 || res >= end - pos)
4777 res = p2p_get_peer_info_txt(info, pos, end - pos);
4782 if (info->vendor_elems) {
4783 res = os_snprintf(pos, end - pos, "vendor_elems=");
4784 if (res < 0 || res >= end - pos)
4788 pos += wpa_snprintf_hex(pos, end - pos,
4789 wpabuf_head(info->vendor_elems),
4790 wpabuf_len(info->vendor_elems));
4792 res = os_snprintf(pos, end - pos, "\n");
4793 if (res < 0 || res >= end - pos)
4802 static int p2p_ctrl_disallow_freq(struct wpa_supplicant *wpa_s,
4807 if (wpa_s->global->p2p == NULL)
4810 if (freq_range_list_parse(&wpa_s->global->p2p_disallow_freq, param) < 0)
4813 for (i = 0; i < wpa_s->global->p2p_disallow_freq.num; i++) {
4814 struct wpa_freq_range *freq;
4815 freq = &wpa_s->global->p2p_disallow_freq.range[i];
4816 wpa_printf(MSG_DEBUG, "P2P: Disallowed frequency range %u-%u",
4817 freq->min, freq->max);
4820 wpas_p2p_update_channel_list(wpa_s);
4825 static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd)
4829 if (wpa_s->global->p2p == NULL)
4832 param = os_strchr(cmd, ' ');
4837 if (os_strcmp(cmd, "discoverability") == 0) {
4838 p2p_set_client_discoverability(wpa_s->global->p2p,
4843 if (os_strcmp(cmd, "managed") == 0) {
4844 p2p_set_managed_oper(wpa_s->global->p2p, atoi(param));
4848 if (os_strcmp(cmd, "listen_channel") == 0) {
4849 return p2p_set_listen_channel(wpa_s->global->p2p, 81,
4853 if (os_strcmp(cmd, "ssid_postfix") == 0) {
4854 return p2p_set_ssid_postfix(wpa_s->global->p2p, (u8 *) param,
4858 if (os_strcmp(cmd, "noa") == 0) {
4860 int count, start, duration;
4861 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
4862 count = atoi(param);
4863 pos = os_strchr(param, ',');
4868 pos = os_strchr(pos, ',');
4872 duration = atoi(pos);
4873 if (count < 0 || count > 255 || start < 0 || duration < 0)
4875 if (count == 0 && duration > 0)
4877 wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
4878 "start=%d duration=%d", count, start, duration);
4879 return wpas_p2p_set_noa(wpa_s, count, start, duration);
4882 if (os_strcmp(cmd, "ps") == 0)
4883 return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1);
4885 if (os_strcmp(cmd, "oppps") == 0)
4886 return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1);
4888 if (os_strcmp(cmd, "ctwindow") == 0)
4889 return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param));
4891 if (os_strcmp(cmd, "disabled") == 0) {
4892 wpa_s->global->p2p_disabled = atoi(param);
4893 wpa_printf(MSG_DEBUG, "P2P functionality %s",
4894 wpa_s->global->p2p_disabled ?
4895 "disabled" : "enabled");
4896 if (wpa_s->global->p2p_disabled) {
4897 wpas_p2p_stop_find(wpa_s);
4898 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
4899 p2p_flush(wpa_s->global->p2p);
4904 if (os_strcmp(cmd, "conc_pref") == 0) {
4905 if (os_strcmp(param, "sta") == 0)
4906 wpa_s->global->conc_pref = WPA_CONC_PREF_STA;
4907 else if (os_strcmp(param, "p2p") == 0)
4908 wpa_s->global->conc_pref = WPA_CONC_PREF_P2P;
4910 wpa_printf(MSG_INFO, "Invalid conc_pref value");
4913 wpa_printf(MSG_DEBUG, "Single channel concurrency preference: "
4918 if (os_strcmp(cmd, "force_long_sd") == 0) {
4919 wpa_s->force_long_sd = atoi(param);
4923 if (os_strcmp(cmd, "peer_filter") == 0) {
4925 if (hwaddr_aton(param, addr))
4927 p2p_set_peer_filter(wpa_s->global->p2p, addr);
4931 if (os_strcmp(cmd, "cross_connect") == 0)
4932 return wpas_p2p_set_cross_connect(wpa_s, atoi(param));
4934 if (os_strcmp(cmd, "go_apsd") == 0) {
4935 if (os_strcmp(param, "disable") == 0)
4936 wpa_s->set_ap_uapsd = 0;
4938 wpa_s->set_ap_uapsd = 1;
4939 wpa_s->ap_uapsd = atoi(param);
4944 if (os_strcmp(cmd, "client_apsd") == 0) {
4945 if (os_strcmp(param, "disable") == 0)
4946 wpa_s->set_sta_uapsd = 0;
4950 /* format: BE,BK,VI,VO;max SP Length */
4952 pos = os_strchr(param, ',');
4957 pos = os_strchr(pos, ',');
4962 pos = os_strchr(pos, ',');
4967 /* ignore max SP Length for now */
4969 wpa_s->set_sta_uapsd = 1;
4970 wpa_s->sta_uapsd = 0;
4972 wpa_s->sta_uapsd |= BIT(0);
4974 wpa_s->sta_uapsd |= BIT(1);
4976 wpa_s->sta_uapsd |= BIT(2);
4978 wpa_s->sta_uapsd |= BIT(3);
4983 if (os_strcmp(cmd, "disallow_freq") == 0)
4984 return p2p_ctrl_disallow_freq(wpa_s, param);
4986 if (os_strcmp(cmd, "disc_int") == 0) {
4987 int min_disc_int, max_disc_int, max_disc_tu;
4992 min_disc_int = atoi(pos);
4993 pos = os_strchr(pos, ' ');
4998 max_disc_int = atoi(pos);
4999 pos = os_strchr(pos, ' ');
5004 max_disc_tu = atoi(pos);
5006 return p2p_set_disc_int(wpa_s->global->p2p, min_disc_int,
5007 max_disc_int, max_disc_tu);
5010 if (os_strcmp(cmd, "per_sta_psk") == 0) {
5011 wpa_s->global->p2p_per_sta_psk = !!atoi(param);
5015 #ifdef CONFIG_WPS_NFC
5016 if (os_strcmp(cmd, "nfc_tag") == 0)
5017 return wpas_p2p_nfc_tag_enabled(wpa_s, !!atoi(param));
5018 #endif /* CONFIG_WPS_NFC */
5020 if (os_strcmp(cmd, "disable_ip_addr_req") == 0) {
5021 wpa_s->p2p_disable_ip_addr_req = !!atoi(param);
5025 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
5032 static void p2p_ctrl_flush(struct wpa_supplicant *wpa_s)
5034 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
5035 wpa_s->force_long_sd = 0;
5036 if (wpa_s->global->p2p)
5037 p2p_flush(wpa_s->global->p2p);
5041 static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd)
5044 unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0;
5047 pos = os_strchr(cmd, ' ');
5053 pos2 = os_strchr(pos, ' ');
5061 pos = os_strchr(pos2, ' ');
5069 return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2);
5073 static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd)
5076 unsigned int period = 0, interval = 0;
5079 pos = os_strchr(cmd, ' ');
5084 interval = atoi(pos);
5087 return wpas_p2p_ext_listen(wpa_s, period, interval);
5091 static int p2p_ctrl_remove_client(struct wpa_supplicant *wpa_s, const char *cmd)
5098 if (os_strncmp(pos, "iface=", 6) == 0) {
5102 if (hwaddr_aton(pos, peer))
5105 wpas_p2p_remove_client(wpa_s, peer, iface_addr);
5109 #endif /* CONFIG_P2P */
5112 static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s, char *val)
5114 struct wpa_freq_range_list ranges;
5116 struct hostapd_hw_modes *mode;
5119 if (wpa_s->hw.modes == NULL)
5122 os_memset(&ranges, 0, sizeof(ranges));
5123 if (freq_range_list_parse(&ranges, val) < 0)
5126 for (i = 0; i < wpa_s->hw.num_modes; i++) {
5129 mode = &wpa_s->hw.modes[i];
5130 for (j = 0; j < mode->num_channels; j++) {
5133 if (mode->channels[j].flag & HOSTAPD_CHAN_DISABLED)
5136 freq = mode->channels[j].freq;
5137 if (!freq_range_list_includes(&ranges, freq))
5140 int_array_add_unique(&freqs, freq);
5144 os_free(ranges.range);
5149 #ifdef CONFIG_INTERWORKING
5151 static int ctrl_interworking_select(struct wpa_supplicant *wpa_s, char *param)
5159 auto_sel = os_strstr(param, "auto") != NULL;
5161 pos = os_strstr(param, "freq=");
5163 freqs = freq_range_to_channel_list(wpa_s, pos + 5);
5170 return interworking_select(wpa_s, auto_sel, freqs);
5174 static int ctrl_interworking_connect(struct wpa_supplicant *wpa_s, char *dst)
5177 struct wpa_bss *bss;
5179 if (hwaddr_aton(dst, bssid)) {
5180 wpa_printf(MSG_DEBUG, "Invalid BSSID '%s'", dst);
5184 bss = wpa_bss_get_bssid(wpa_s, bssid);
5186 wpa_printf(MSG_DEBUG, "Could not find BSS " MACSTR,
5191 return interworking_connect(wpa_s, bss);
5195 static int get_anqp(struct wpa_supplicant *wpa_s, char *dst)
5197 u8 dst_addr[ETH_ALEN];
5200 #define MAX_ANQP_INFO_ID 100
5201 u16 id[MAX_ANQP_INFO_ID];
5205 used = hwaddr_aton2(dst, dst_addr);
5209 while (num_id < MAX_ANQP_INFO_ID) {
5210 if (os_strncmp(pos, "hs20:", 5) == 0) {
5212 int num = atoi(pos + 5);
5213 if (num <= 0 || num > 31)
5215 subtypes |= BIT(num);
5216 #else /* CONFIG_HS20 */
5218 #endif /* CONFIG_HS20 */
5220 id[num_id] = atoi(pos);
5224 pos = os_strchr(pos + 1, ',');
5233 return anqp_send_req(wpa_s, dst_addr, id, num_id, subtypes);
5237 static int gas_request(struct wpa_supplicant *wpa_s, char *cmd)
5239 u8 dst_addr[ETH_ALEN];
5240 struct wpabuf *advproto, *query = NULL;
5245 used = hwaddr_aton2(cmd, dst_addr);
5253 /* Advertisement Protocol ID */
5254 end = os_strchr(pos, ' ');
5258 len = os_strlen(pos);
5264 advproto = wpabuf_alloc(len);
5265 if (advproto == NULL)
5267 if (hexstr2bin(pos, wpabuf_put(advproto, len), len) < 0)
5271 /* Optional Query Request */
5276 len = os_strlen(pos);
5283 query = wpabuf_alloc(len);
5286 if (hexstr2bin(pos, wpabuf_put(query, len), len) < 0)
5291 ret = gas_send_request(wpa_s, dst_addr, advproto, query);
5294 wpabuf_free(advproto);
5301 static int gas_response_get(struct wpa_supplicant *wpa_s, char *cmd, char *buf,
5308 size_t resp_len, start, requested_len;
5309 struct wpabuf *resp;
5312 used = hwaddr_aton2(cmd, addr);
5319 dialog_token = atoi(pos);
5321 if (wpa_s->last_gas_resp &&
5322 os_memcmp(addr, wpa_s->last_gas_addr, ETH_ALEN) == 0 &&
5323 dialog_token == wpa_s->last_gas_dialog_token)
5324 resp = wpa_s->last_gas_resp;
5325 else if (wpa_s->prev_gas_resp &&
5326 os_memcmp(addr, wpa_s->prev_gas_addr, ETH_ALEN) == 0 &&
5327 dialog_token == wpa_s->prev_gas_dialog_token)
5328 resp = wpa_s->prev_gas_resp;
5332 resp_len = wpabuf_len(resp);
5334 requested_len = resp_len;
5336 pos = os_strchr(pos, ' ');
5339 if (start > resp_len)
5340 return os_snprintf(buf, buflen, "FAIL-Invalid range");
5341 pos = os_strchr(pos, ',');
5345 requested_len = atoi(pos);
5346 if (start + requested_len > resp_len)
5347 return os_snprintf(buf, buflen, "FAIL-Invalid range");
5350 if (requested_len * 2 + 1 > buflen)
5351 return os_snprintf(buf, buflen, "FAIL-Too long response");
5353 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(resp) + start,
5356 if (start + requested_len == resp_len) {
5358 * Free memory by dropping the response after it has been
5361 if (resp == wpa_s->prev_gas_resp) {
5362 wpabuf_free(wpa_s->prev_gas_resp);
5363 wpa_s->prev_gas_resp = NULL;
5365 wpabuf_free(wpa_s->last_gas_resp);
5366 wpa_s->last_gas_resp = NULL;
5372 #endif /* CONFIG_INTERWORKING */
5377 static int get_hs20_anqp(struct wpa_supplicant *wpa_s, char *dst)
5379 u8 dst_addr[ETH_ALEN];
5384 used = hwaddr_aton2(dst, dst_addr);
5389 int num = atoi(pos);
5390 if (num <= 0 || num > 31)
5392 subtypes |= BIT(num);
5393 pos = os_strchr(pos + 1, ',');
5402 return hs20_anqp_send_req(wpa_s, dst_addr, subtypes, NULL, 0);
5406 static int hs20_nai_home_realm_list(struct wpa_supplicant *wpa_s,
5407 const u8 *addr, const char *realm)
5413 rlen = os_strlen(realm);
5415 buf = os_malloc(len);
5418 buf[0] = 1; /* NAI Home Realm Count */
5419 buf[1] = 0; /* Formatted in accordance with RFC 4282 */
5421 os_memcpy(buf + 3, realm, rlen);
5423 ret = hs20_anqp_send_req(wpa_s, addr,
5424 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
5433 static int hs20_get_nai_home_realm_list(struct wpa_supplicant *wpa_s,
5436 struct wpa_cred *cred = wpa_s->conf->cred;
5437 u8 dst_addr[ETH_ALEN];
5443 used = hwaddr_aton2(dst, dst_addr);
5447 while (dst[used] == ' ')
5449 if (os_strncmp(dst + used, "realm=", 6) == 0)
5450 return hs20_nai_home_realm_list(wpa_s, dst_addr,
5453 len = os_strlen(dst + used);
5455 if (len == 0 && cred && cred->realm)
5456 return hs20_nai_home_realm_list(wpa_s, dst_addr, cred->realm);
5461 buf = os_malloc(len);
5464 if (hexstr2bin(dst + used, buf, len) < 0) {
5469 ret = hs20_anqp_send_req(wpa_s, dst_addr,
5470 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
5478 static int hs20_icon_request(struct wpa_supplicant *wpa_s, char *cmd)
5480 u8 dst_addr[ETH_ALEN];
5484 used = hwaddr_aton2(cmd, dst_addr);
5488 while (cmd[used] == ' ')
5492 wpa_s->fetch_osu_icon_in_progress = 0;
5493 return hs20_anqp_send_req(wpa_s, dst_addr, BIT(HS20_STYPE_ICON_REQUEST),
5494 (u8 *) icon, os_strlen(icon));
5497 #endif /* CONFIG_HS20 */
5500 static int wpa_supplicant_ctrl_iface_sta_autoconnect(
5501 struct wpa_supplicant *wpa_s, char *cmd)
5503 wpa_s->auto_reconnect_disabled = atoi(cmd) == 0 ? 1 : 0;
5508 #ifdef CONFIG_AUTOSCAN
5510 static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant *wpa_s,
5513 enum wpa_states state = wpa_s->wpa_state;
5514 char *new_params = NULL;
5516 if (os_strlen(cmd) > 0) {
5517 new_params = os_strdup(cmd);
5518 if (new_params == NULL)
5522 os_free(wpa_s->conf->autoscan);
5523 wpa_s->conf->autoscan = new_params;
5525 if (wpa_s->conf->autoscan == NULL)
5526 autoscan_deinit(wpa_s);
5527 else if (state == WPA_DISCONNECTED || state == WPA_INACTIVE)
5528 autoscan_init(wpa_s, 1);
5529 else if (state == WPA_SCANNING)
5530 wpa_supplicant_reinit_autoscan(wpa_s);
5535 #endif /* CONFIG_AUTOSCAN */
5540 static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant *wpa_s, char *cmd)
5546 struct wpabuf *tfs_req = NULL;
5548 if (os_strncmp(cmd, "enter", 5) == 0)
5550 else if (os_strncmp(cmd, "exit", 4) == 0)
5555 pos = os_strstr(cmd, " interval=");
5557 intval = atoi(pos + 10);
5559 pos = os_strstr(cmd, " tfs_req=");
5564 end = os_strchr(pos, ' ');
5568 len = os_strlen(pos);
5572 tfs_req = wpabuf_alloc(len);
5573 if (tfs_req == NULL)
5575 if (hexstr2bin(pos, wpabuf_put(tfs_req, len), len) < 0) {
5576 wpabuf_free(tfs_req);
5581 ret = ieee802_11_send_wnmsleep_req(wpa_s, enter ? WNM_SLEEP_MODE_ENTER :
5582 WNM_SLEEP_MODE_EXIT, intval,
5584 wpabuf_free(tfs_req);
5590 static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant *wpa_s, char *cmd)
5594 query_reason = atoi(cmd);
5596 wpa_printf(MSG_DEBUG, "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d",
5599 return wnm_send_bss_transition_mgmt_query(wpa_s, query_reason);
5602 #endif /* CONFIG_WNM */
5605 static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf,
5608 struct wpa_signal_info si;
5612 ret = wpa_drv_signal_poll(wpa_s, &si);
5619 ret = os_snprintf(pos, end - pos, "RSSI=%d\nLINKSPEED=%d\n"
5620 "NOISE=%d\nFREQUENCY=%u\n",
5621 si.current_signal, si.current_txrate / 1000,
5622 si.current_noise, si.frequency);
5623 if (ret < 0 || ret > end - pos)
5627 if (si.chanwidth != CHAN_WIDTH_UNKNOWN) {
5628 ret = os_snprintf(pos, end - pos, "WIDTH=%s\n",
5629 channel_width_to_string(si.chanwidth));
5630 if (ret < 0 || ret > end - pos)
5635 if (si.center_frq1 > 0 && si.center_frq2 > 0) {
5636 ret = os_snprintf(pos, end - pos,
5637 "CENTER_FRQ1=%d\nCENTER_FRQ2=%d\n",
5638 si.center_frq1, si.center_frq2);
5639 if (ret < 0 || ret > end - pos)
5644 if (si.avg_signal) {
5645 ret = os_snprintf(pos, end - pos,
5646 "AVG_RSSI=%d\n", si.avg_signal);
5647 if (ret < 0 || ret >= end - pos)
5656 static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant *wpa_s, char *buf,
5659 struct hostap_sta_driver_data sta;
5662 ret = wpa_drv_pktcnt_poll(wpa_s, &sta);
5666 ret = os_snprintf(buf, buflen, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
5667 sta.tx_packets, sta.tx_retry_failed, sta.rx_packets);
5668 if (ret < 0 || (size_t) ret > buflen)
5675 static int wpa_supplicant_driver_cmd(struct wpa_supplicant *wpa_s, char *cmd,
5676 char *buf, size_t buflen)
5680 ret = wpa_drv_driver_cmd(wpa_s, cmd, buf, buflen);
5682 if (os_strncasecmp(cmd, "COUNTRY", 7) == 0) {
5683 struct p2p_data *p2p = wpa_s->global->p2p;
5686 country[0] = cmd[8];
5687 country[1] = cmd[9];
5689 p2p_set_country(p2p, country);
5692 ret = os_snprintf(buf, buflen, "%s\n", "OK");
5696 #endif /* ANDROID */
5699 static int wpa_supplicant_vendor_cmd(struct wpa_supplicant *wpa_s, char *cmd,
5700 char *buf, size_t buflen)
5705 unsigned int vendor_id, subcmd;
5706 struct wpabuf *reply;
5707 size_t data_len = 0;
5709 /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */
5710 vendor_id = strtoul(cmd, &pos, 16);
5714 subcmd = strtoul(pos, &pos, 10);
5717 if (!isblank(*pos++))
5719 data_len = os_strlen(pos);
5724 data = os_malloc(data_len);
5728 if (hexstr2bin(pos, data, data_len)) {
5729 wpa_printf(MSG_DEBUG,
5730 "Vendor command: wrong parameter format");
5736 reply = wpabuf_alloc((buflen - 1) / 2);
5742 ret = wpa_drv_vendor_cmd(wpa_s, vendor_id, subcmd, data, data_len,
5746 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(reply),
5756 static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s)
5758 wpa_dbg(wpa_s, MSG_DEBUG, "Flush all wpa_supplicant state");
5761 wpas_p2p_cancel(wpa_s);
5762 wpas_p2p_stop_find(wpa_s);
5763 p2p_ctrl_flush(wpa_s);
5764 wpas_p2p_group_remove(wpa_s, "*");
5765 wpas_p2p_service_flush(wpa_s);
5766 wpa_s->global->p2p_disabled = 0;
5767 wpa_s->global->p2p_per_sta_psk = 0;
5768 wpa_s->conf->num_sec_device_types = 0;
5769 wpa_s->p2p_disable_ip_addr_req = 0;
5770 os_free(wpa_s->global->p2p_go_avoid_freq.range);
5771 wpa_s->global->p2p_go_avoid_freq.range = NULL;
5772 #endif /* CONFIG_P2P */
5774 #ifdef CONFIG_WPS_TESTING
5775 wps_version_number = 0x20;
5776 wps_testing_dummy_cred = 0;
5777 wps_corrupt_pkhash = 0;
5778 #endif /* CONFIG_WPS_TESTING */
5780 wpa_s->wps_fragment_size = 0;
5781 wpas_wps_cancel(wpa_s);
5782 #endif /* CONFIG_WPS */
5783 wpa_s->after_wps = 0;
5784 wpa_s->known_wps_freq = 0;
5787 #ifdef CONFIG_TDLS_TESTING
5788 extern unsigned int tdls_testing;
5790 #endif /* CONFIG_TDLS_TESTING */
5791 wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL);
5792 wpa_tdls_enable(wpa_s->wpa, 1);
5793 #endif /* CONFIG_TDLS */
5795 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, wpa_s, NULL);
5796 wpa_supplicant_stop_countermeasures(wpa_s, NULL);
5798 wpa_s->no_keep_alive = 0;
5800 os_free(wpa_s->disallow_aps_bssid);
5801 wpa_s->disallow_aps_bssid = NULL;
5802 wpa_s->disallow_aps_bssid_count = 0;
5803 os_free(wpa_s->disallow_aps_ssid);
5804 wpa_s->disallow_aps_ssid = NULL;
5805 wpa_s->disallow_aps_ssid_count = 0;
5807 wpa_s->set_sta_uapsd = 0;
5808 wpa_s->sta_uapsd = 0;
5810 wpa_drv_radio_disable(wpa_s, 0);
5812 wpa_bss_flush(wpa_s);
5813 wpa_blacklist_clear(wpa_s);
5814 wpa_s->extra_blacklist_count = 0;
5815 wpa_supplicant_ctrl_iface_remove_network(wpa_s, "all");
5816 wpa_supplicant_ctrl_iface_remove_cred(wpa_s, "all");
5817 wpa_config_flush_blobs(wpa_s->conf);
5818 wpa_s->conf->auto_interworking = 0;
5819 wpa_s->conf->okc = 0;
5821 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, 43200);
5822 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, 70);
5823 wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, 60);
5824 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
5826 radio_remove_works(wpa_s, NULL, 1);
5828 wpa_s->next_ssid = NULL;
5830 #ifdef CONFIG_INTERWORKING
5831 hs20_cancel_fetch_osu(wpa_s);
5832 #endif /* CONFIG_INTERWORKING */
5834 wpa_s->ext_mgmt_frame_handling = 0;
5835 wpa_s->ext_eapol_frame_io = 0;
5839 static int wpas_ctrl_radio_work_show(struct wpa_supplicant *wpa_s,
5840 char *buf, size_t buflen)
5842 struct wpa_radio_work *work;
5844 struct os_reltime now, diff;
5849 os_get_reltime(&now);
5851 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
5855 os_reltime_sub(&now, &work->time, &diff);
5856 ret = os_snprintf(pos, end - pos, "%s@%s:%u:%u:%ld.%06ld\n",
5857 work->type, work->wpa_s->ifname, work->freq,
5858 work->started, diff.sec, diff.usec);
5859 if (ret < 0 || ret >= end - pos)
5868 static void wpas_ctrl_radio_work_timeout(void *eloop_ctx, void *timeout_ctx)
5870 struct wpa_radio_work *work = eloop_ctx;
5871 struct wpa_external_work *ework = work->ctx;
5873 wpa_dbg(work->wpa_s, MSG_DEBUG,
5874 "Timing out external radio work %u (%s)",
5875 ework->id, work->type);
5876 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_TIMEOUT "%u", ework->id);
5877 radio_work_done(work);
5882 static void wpas_ctrl_radio_work_cb(struct wpa_radio_work *work, int deinit)
5884 struct wpa_external_work *ework = work->ctx;
5888 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
5895 wpa_dbg(work->wpa_s, MSG_DEBUG, "Starting external radio work %u (%s)",
5896 ework->id, ework->type);
5897 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_START "%u", ework->id);
5898 if (!ework->timeout)
5899 ework->timeout = 10;
5900 eloop_register_timeout(ework->timeout, 0, wpas_ctrl_radio_work_timeout,
5905 static int wpas_ctrl_radio_work_add(struct wpa_supplicant *wpa_s, char *cmd,
5906 char *buf, size_t buflen)
5908 struct wpa_external_work *ework;
5912 unsigned int freq = 0;
5914 /* format: <name> [freq=<MHz>] [timeout=<seconds>] */
5916 ework = os_zalloc(sizeof(*ework));
5920 pos = os_strchr(cmd, ' ');
5922 type_len = pos - cmd;
5925 pos2 = os_strstr(pos, "freq=");
5927 freq = atoi(pos2 + 5);
5929 pos2 = os_strstr(pos, "timeout=");
5931 ework->timeout = atoi(pos2 + 8);
5933 type_len = os_strlen(cmd);
5935 if (4 + type_len >= sizeof(ework->type))
5936 type_len = sizeof(ework->type) - 4 - 1;
5937 os_strlcpy(ework->type, "ext:", sizeof(ework->type));
5938 os_memcpy(ework->type + 4, cmd, type_len);
5939 ework->type[4 + type_len] = '\0';
5941 wpa_s->ext_work_id++;
5942 if (wpa_s->ext_work_id == 0)
5943 wpa_s->ext_work_id++;
5944 ework->id = wpa_s->ext_work_id;
5946 if (radio_add_work(wpa_s, freq, ework->type, 0, wpas_ctrl_radio_work_cb,
5952 ret = os_snprintf(buf, buflen, "%u", ework->id);
5953 if (ret < 0 || (size_t) ret >= buflen)
5959 static int wpas_ctrl_radio_work_done(struct wpa_supplicant *wpa_s, char *cmd)
5961 struct wpa_radio_work *work;
5962 unsigned int id = atoi(cmd);
5964 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
5966 struct wpa_external_work *ework;
5968 if (os_strncmp(work->type, "ext:", 4) != 0)
5971 if (id && ework->id != id)
5973 wpa_dbg(wpa_s, MSG_DEBUG,
5974 "Completed external radio work %u (%s)",
5975 ework->id, ework->type);
5976 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, work, NULL);
5977 radio_work_done(work);
5979 return 3; /* "OK\n" */
5986 static int wpas_ctrl_radio_work(struct wpa_supplicant *wpa_s, char *cmd,
5987 char *buf, size_t buflen)
5989 if (os_strcmp(cmd, "show") == 0)
5990 return wpas_ctrl_radio_work_show(wpa_s, buf, buflen);
5991 if (os_strncmp(cmd, "add ", 4) == 0)
5992 return wpas_ctrl_radio_work_add(wpa_s, cmd + 4, buf, buflen);
5993 if (os_strncmp(cmd, "done ", 5) == 0)
5994 return wpas_ctrl_radio_work_done(wpa_s, cmd + 4);
5999 void wpas_ctrl_radio_work_flush(struct wpa_supplicant *wpa_s)
6001 struct wpa_radio_work *work, *tmp;
6003 if (!wpa_s || !wpa_s->radio)
6006 dl_list_for_each_safe(work, tmp, &wpa_s->radio->work,
6007 struct wpa_radio_work, list) {
6008 struct wpa_external_work *ework;
6010 if (os_strncmp(work->type, "ext:", 4) != 0)
6013 wpa_dbg(wpa_s, MSG_DEBUG,
6014 "Flushing%s external radio work %u (%s)",
6015 work->started ? " started" : "", ework->id,
6018 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
6020 radio_work_done(work);
6026 static void wpas_ctrl_eapol_response(void *eloop_ctx, void *timeout_ctx)
6028 struct wpa_supplicant *wpa_s = eloop_ctx;
6029 eapol_sm_notify_ctrl_response(wpa_s->eapol);
6033 static int set_scan_freqs(struct wpa_supplicant *wpa_s, char *val)
6037 freqs = freq_range_to_channel_list(wpa_s, val);
6041 os_free(wpa_s->manual_scan_freqs);
6042 wpa_s->manual_scan_freqs = freqs;
6048 static int scan_id_list_parse(struct wpa_supplicant *wpa_s, const char *value)
6050 const char *pos = value;
6053 if (*pos == ' ' || *pos == '\0')
6055 if (wpa_s->scan_id_count == MAX_SCAN_ID)
6057 wpa_s->scan_id[wpa_s->scan_id_count++] = atoi(pos);
6058 pos = os_strchr(pos, ',');
6067 static void wpas_ctrl_scan(struct wpa_supplicant *wpa_s, char *params,
6068 char *reply, int reply_size, int *reply_len)
6072 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
6077 wpa_s->manual_scan_passive = 0;
6078 wpa_s->manual_scan_use_id = 0;
6079 wpa_s->manual_scan_only_new = 0;
6080 wpa_s->scan_id_count = 0;
6083 if (os_strncasecmp(params, "TYPE=ONLY", 9) == 0)
6084 wpa_s->scan_res_handler = scan_only_handler;
6086 pos = os_strstr(params, "freq=");
6087 if (pos && set_scan_freqs(wpa_s, pos + 5) < 0) {
6092 pos = os_strstr(params, "passive=");
6094 wpa_s->manual_scan_passive = !!atoi(pos + 8);
6096 pos = os_strstr(params, "use_id=");
6098 wpa_s->manual_scan_use_id = atoi(pos + 7);
6100 pos = os_strstr(params, "only_new=1");
6102 wpa_s->manual_scan_only_new = 1;
6104 pos = os_strstr(params, "scan_id=");
6105 if (pos && scan_id_list_parse(wpa_s, pos + 8) < 0) {
6110 os_free(wpa_s->manual_scan_freqs);
6111 wpa_s->manual_scan_freqs = NULL;
6112 if (wpa_s->scan_res_handler == scan_only_handler)
6113 wpa_s->scan_res_handler = NULL;
6116 if (!wpa_s->sched_scanning && !wpa_s->scanning &&
6117 ((wpa_s->wpa_state <= WPA_SCANNING) ||
6118 (wpa_s->wpa_state == WPA_COMPLETED))) {
6119 wpa_s->normal_scans = 0;
6120 wpa_s->scan_req = MANUAL_SCAN_REQ;
6121 wpa_s->after_wps = 0;
6122 wpa_s->known_wps_freq = 0;
6123 wpa_supplicant_req_scan(wpa_s, 0, 0);
6124 if (wpa_s->manual_scan_use_id) {
6125 wpa_s->manual_scan_id++;
6126 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
6127 wpa_s->manual_scan_id);
6128 *reply_len = os_snprintf(reply, reply_size, "%u\n",
6129 wpa_s->manual_scan_id);
6131 } else if (wpa_s->sched_scanning) {
6132 wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to allow requested full scan to proceed");
6133 wpa_supplicant_cancel_sched_scan(wpa_s);
6134 wpa_s->scan_req = MANUAL_SCAN_REQ;
6135 wpa_supplicant_req_scan(wpa_s, 0, 0);
6136 if (wpa_s->manual_scan_use_id) {
6137 wpa_s->manual_scan_id++;
6138 *reply_len = os_snprintf(reply, reply_size, "%u\n",
6139 wpa_s->manual_scan_id);
6140 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
6141 wpa_s->manual_scan_id);
6144 wpa_printf(MSG_DEBUG, "Ongoing scan action - reject new request");
6145 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
6150 #ifdef CONFIG_TESTING_OPTIONS
6152 static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant *wpa_s,
6153 unsigned int freq, const u8 *dst,
6154 const u8 *src, const u8 *bssid,
6155 const u8 *data, size_t data_len,
6156 enum offchannel_send_action_result
6159 wpa_msg(wpa_s, MSG_INFO, "MGMT-TX-STATUS freq=%u dst=" MACSTR
6160 " src=" MACSTR " bssid=" MACSTR " result=%s",
6161 freq, MAC2STR(dst), MAC2STR(src), MAC2STR(bssid),
6162 result == OFFCHANNEL_SEND_ACTION_SUCCESS ?
6163 "SUCCESS" : (result == OFFCHANNEL_SEND_ACTION_NO_ACK ?
6164 "NO_ACK" : "FAILED"));
6168 static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant *wpa_s, char *cmd)
6172 u8 *buf, da[ETH_ALEN], bssid[ETH_ALEN];
6174 int freq = 0, no_cck = 0, wait_time = 0;
6176 /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1]
6177 * <action=Action frame payload> */
6179 wpa_printf(MSG_DEBUG, "External MGMT TX: %s", cmd);
6182 used = hwaddr_aton2(pos, da);
6188 used = hwaddr_aton2(pos, bssid);
6193 param = os_strstr(pos, " freq=");
6199 param = os_strstr(pos, " no_cck=");
6202 no_cck = atoi(param);
6205 param = os_strstr(pos, " wait_time=");
6208 wait_time = atoi(param);
6211 param = os_strstr(pos, " action=");
6216 len = os_strlen(param);
6221 buf = os_malloc(len);
6225 if (hexstr2bin(param, buf, len) < 0) {
6230 res = offchannel_send_action(wpa_s, freq, da, wpa_s->own_addr, bssid,
6231 buf, len, wait_time,
6232 wpas_ctrl_iface_mgmt_tx_cb, no_cck);
6238 static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant *wpa_s)
6240 wpa_printf(MSG_DEBUG, "External MGMT TX - done waiting");
6241 offchannel_send_action_done(wpa_s);
6245 static int wpas_ctrl_iface_driver_event(struct wpa_supplicant *wpa_s, char *cmd)
6248 union wpa_event_data event;
6249 enum wpa_event_type ev;
6251 /* <event name> [parameters..] */
6253 wpa_dbg(wpa_s, MSG_DEBUG, "Testing - external driver event: %s", cmd);
6256 param = os_strchr(pos, ' ');
6260 os_memset(&event, 0, sizeof(event));
6262 if (os_strcmp(cmd, "INTERFACE_ENABLED") == 0) {
6263 ev = EVENT_INTERFACE_ENABLED;
6264 } else if (os_strcmp(cmd, "INTERFACE_DISABLED") == 0) {
6265 ev = EVENT_INTERFACE_DISABLED;
6266 } else if (os_strcmp(cmd, "AVOID_FREQUENCIES") == 0) {
6267 ev = EVENT_AVOID_FREQUENCIES;
6270 if (freq_range_list_parse(&event.freq_range, param) < 0)
6272 wpa_supplicant_event(wpa_s, ev, &event);
6273 os_free(event.freq_range.range);
6276 wpa_dbg(wpa_s, MSG_DEBUG, "Testing - unknown driver event: %s",
6281 wpa_supplicant_event(wpa_s, ev, &event);
6287 static int wpas_ctrl_iface_eapol_rx(struct wpa_supplicant *wpa_s, char *cmd)
6290 u8 src[ETH_ALEN], *buf;
6294 wpa_printf(MSG_DEBUG, "External EAPOL RX: %s", cmd);
6297 used = hwaddr_aton2(pos, src);
6304 len = os_strlen(pos);
6309 buf = os_malloc(len);
6313 if (hexstr2bin(pos, buf, len) < 0) {
6318 wpa_supplicant_rx_eapol(wpa_s, src, buf, len);
6325 static u16 ipv4_hdr_checksum(const void *buf, size_t len)
6329 const u16 *pos = buf;
6331 for (i = 0; i < len / 2; i++)
6335 sum = (sum & 0xffff) + (sum >> 16);
6337 return sum ^ 0xffff;
6341 #define HWSIM_PACKETLEN 1500
6342 #define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header))
6344 void wpas_data_test_rx(void *ctx, const u8 *src_addr, const u8 *buf, size_t len)
6346 struct wpa_supplicant *wpa_s = ctx;
6347 const struct ether_header *eth;
6348 const struct iphdr *ip;
6352 if (len != HWSIM_PACKETLEN)
6355 eth = (const struct ether_header *) buf;
6356 ip = (const struct iphdr *) (eth + 1);
6357 pos = (const u8 *) (ip + 1);
6359 if (ip->ihl != 5 || ip->version != 4 ||
6360 ntohs(ip->tot_len) != HWSIM_IP_LEN)
6363 for (i = 0; i < HWSIM_IP_LEN - sizeof(*ip); i++) {
6369 wpa_msg(wpa_s, MSG_INFO, "DATA-TEST-RX " MACSTR " " MACSTR,
6370 MAC2STR(eth->ether_dhost), MAC2STR(eth->ether_shost));
6374 static int wpas_ctrl_iface_data_test_config(struct wpa_supplicant *wpa_s,
6377 int enabled = atoi(cmd);
6380 if (wpa_s->l2_test) {
6381 l2_packet_deinit(wpa_s->l2_test);
6382 wpa_s->l2_test = NULL;
6383 wpa_dbg(wpa_s, MSG_DEBUG, "test data: Disabled");
6391 wpa_s->l2_test = l2_packet_init(wpa_s->ifname, wpa_s->own_addr,
6392 ETHERTYPE_IP, wpas_data_test_rx,
6394 if (wpa_s->l2_test == NULL)
6397 wpa_dbg(wpa_s, MSG_DEBUG, "test data: Enabled");
6403 static int wpas_ctrl_iface_data_test_tx(struct wpa_supplicant *wpa_s, char *cmd)
6405 u8 dst[ETH_ALEN], src[ETH_ALEN];
6410 u8 buf[HWSIM_PACKETLEN];
6411 struct ether_header *eth;
6416 if (wpa_s->l2_test == NULL)
6419 /* format: <dst> <src> <tos> */
6422 used = hwaddr_aton2(pos, dst);
6428 used = hwaddr_aton2(pos, src);
6433 val = strtol(pos, NULL, 0);
6434 if (val < 0 || val > 0xff)
6438 eth = (struct ether_header *) buf;
6439 os_memcpy(eth->ether_dhost, dst, ETH_ALEN);
6440 os_memcpy(eth->ether_shost, src, ETH_ALEN);
6441 eth->ether_type = htons(ETHERTYPE_IP);
6442 ip = (struct iphdr *) (eth + 1);
6443 os_memset(ip, 0, sizeof(*ip));
6448 ip->tot_len = htons(HWSIM_IP_LEN);
6450 ip->saddr = htonl(192 << 24 | 168 << 16 | 1 << 8 | 1);
6451 ip->daddr = htonl(192 << 24 | 168 << 16 | 1 << 8 | 2);
6452 ip->check = ipv4_hdr_checksum(ip, sizeof(*ip));
6453 dpos = (u8 *) (ip + 1);
6454 for (i = 0; i < HWSIM_IP_LEN - sizeof(*ip); i++)
6457 if (l2_packet_send(wpa_s->l2_test, dst, ETHERTYPE_IP, buf,
6458 HWSIM_PACKETLEN) < 0)
6461 wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX dst=" MACSTR " src=" MACSTR
6462 " tos=0x%x", MAC2STR(dst), MAC2STR(src), tos);
6467 #endif /* CONFIG_TESTING_OPTIONS */
6470 static void wpas_ctrl_vendor_elem_update(struct wpa_supplicant *wpa_s)
6475 wpa_printf(MSG_DEBUG, "Update vendor elements");
6477 for (i = 0; i < NUM_VENDOR_ELEM_FRAMES; i++) {
6478 if (wpa_s->vendor_elem[i]) {
6479 os_snprintf(buf, sizeof(buf), "frame[%u]", i);
6480 wpa_hexdump_buf(MSG_DEBUG, buf, wpa_s->vendor_elem[i]);
6485 if (wpa_s->parent == wpa_s &&
6486 wpa_s->global->p2p &&
6487 !wpa_s->global->p2p_disabled)
6488 p2p_set_vendor_elems(wpa_s->global->p2p, wpa_s->vendor_elem);
6489 #endif /* CONFIG_P2P */
6493 static struct wpa_supplicant *
6494 wpas_ctrl_vendor_elem_iface(struct wpa_supplicant *wpa_s,
6495 enum wpa_vendor_elem_frame frame)
6499 case VENDOR_ELEM_PROBE_REQ_P2P:
6500 case VENDOR_ELEM_PROBE_RESP_P2P:
6501 case VENDOR_ELEM_PROBE_RESP_P2P_GO:
6502 case VENDOR_ELEM_BEACON_P2P_GO:
6503 case VENDOR_ELEM_P2P_PD_REQ:
6504 case VENDOR_ELEM_P2P_PD_RESP:
6505 case VENDOR_ELEM_P2P_GO_NEG_REQ:
6506 case VENDOR_ELEM_P2P_GO_NEG_RESP:
6507 case VENDOR_ELEM_P2P_GO_NEG_CONF:
6508 case VENDOR_ELEM_P2P_INV_REQ:
6509 case VENDOR_ELEM_P2P_INV_RESP:
6510 case VENDOR_ELEM_P2P_ASSOC_REQ:
6511 return wpa_s->parent;
6512 #endif /* CONFIG_P2P */
6519 static int wpas_ctrl_vendor_elem_add(struct wpa_supplicant *wpa_s, char *cmd)
6525 struct ieee802_11_elems elems;
6528 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
6530 wpa_s = wpas_ctrl_vendor_elem_iface(wpa_s, frame);
6532 pos = os_strchr(pos, ' ');
6537 len = os_strlen(pos);
6544 buf = wpabuf_alloc(len);
6548 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
6553 if (ieee802_11_parse_elems(wpabuf_head_u8(buf), len, &elems, 0) ==
6559 if (wpa_s->vendor_elem[frame] == NULL) {
6560 wpa_s->vendor_elem[frame] = buf;
6561 wpas_ctrl_vendor_elem_update(wpa_s);
6565 if (wpabuf_resize(&wpa_s->vendor_elem[frame], len) < 0) {
6570 wpabuf_put_buf(wpa_s->vendor_elem[frame], buf);
6572 wpas_ctrl_vendor_elem_update(wpa_s);
6578 static int wpas_ctrl_vendor_elem_get(struct wpa_supplicant *wpa_s, char *cmd,
6579 char *buf, size_t buflen)
6581 int frame = atoi(cmd);
6583 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
6585 wpa_s = wpas_ctrl_vendor_elem_iface(wpa_s, frame);
6587 if (wpa_s->vendor_elem[frame] == NULL)
6590 return wpa_snprintf_hex(buf, buflen,
6591 wpabuf_head_u8(wpa_s->vendor_elem[frame]),
6592 wpabuf_len(wpa_s->vendor_elem[frame]));
6596 static int wpas_ctrl_vendor_elem_remove(struct wpa_supplicant *wpa_s, char *cmd)
6602 struct ieee802_11_elems elems;
6606 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
6608 wpa_s = wpas_ctrl_vendor_elem_iface(wpa_s, frame);
6610 pos = os_strchr(pos, ' ');
6616 wpabuf_free(wpa_s->vendor_elem[frame]);
6617 wpa_s->vendor_elem[frame] = NULL;
6618 wpas_ctrl_vendor_elem_update(wpa_s);
6622 if (wpa_s->vendor_elem[frame] == NULL)
6625 len = os_strlen(pos);
6632 buf = os_malloc(len);
6636 if (hexstr2bin(pos, buf, len) < 0) {
6641 if (ieee802_11_parse_elems(buf, len, &elems, 0) == ParseFailed) {
6646 ie = wpabuf_mhead_u8(wpa_s->vendor_elem[frame]);
6647 end = ie + wpabuf_len(wpa_s->vendor_elem[frame]);
6649 for (; ie + 1 < end; ie += 2 + ie[1]) {
6652 if (os_memcmp(ie, buf, len) != 0)
6655 if (wpabuf_len(wpa_s->vendor_elem[frame]) == len) {
6656 wpabuf_free(wpa_s->vendor_elem[frame]);
6657 wpa_s->vendor_elem[frame] = NULL;
6659 os_memmove(ie, ie + len,
6661 wpa_s->vendor_elem[frame]->used -= len;
6664 wpas_ctrl_vendor_elem_update(wpa_s);
6674 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
6675 char *buf, size_t *resp_len)
6678 const int reply_size = 4096;
6681 if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 ||
6682 os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
6683 if (wpa_debug_show_keys)
6684 wpa_dbg(wpa_s, MSG_DEBUG,
6685 "Control interface command '%s'", buf);
6687 wpa_dbg(wpa_s, MSG_DEBUG,
6688 "Control interface command '%s [REMOVED]'",
6689 os_strncmp(buf, WPA_CTRL_RSP,
6690 os_strlen(WPA_CTRL_RSP)) == 0 ?
6691 WPA_CTRL_RSP : "SET_NETWORK");
6692 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ", 16) == 0 ||
6693 os_strncmp(buf, "NFC_REPORT_HANDOVER", 19) == 0) {
6694 wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface",
6695 (const u8 *) buf, os_strlen(buf));
6697 int level = MSG_DEBUG;
6698 if (os_strcmp(buf, "PING") == 0)
6699 level = MSG_EXCESSIVE;
6700 wpa_dbg(wpa_s, level, "Control interface command '%s'", buf);
6703 reply = os_malloc(reply_size);
6704 if (reply == NULL) {
6709 os_memcpy(reply, "OK\n", 3);
6712 if (os_strcmp(buf, "PING") == 0) {
6713 os_memcpy(reply, "PONG\n", 5);
6715 } else if (os_strcmp(buf, "IFNAME") == 0) {
6716 reply_len = os_strlen(wpa_s->ifname);
6717 os_memcpy(reply, wpa_s->ifname, reply_len);
6718 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
6719 if (wpa_debug_reopen_file() < 0)
6721 } else if (os_strncmp(buf, "NOTE ", 5) == 0) {
6722 wpa_printf(MSG_INFO, "NOTE: %s", buf + 5);
6723 } else if (os_strcmp(buf, "MIB") == 0) {
6724 reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size);
6725 if (reply_len >= 0) {
6727 res = eapol_sm_get_mib(wpa_s->eapol, reply + reply_len,
6728 reply_size - reply_len);
6734 } else if (os_strncmp(buf, "STATUS", 6) == 0) {
6735 reply_len = wpa_supplicant_ctrl_iface_status(
6736 wpa_s, buf + 6, reply, reply_size);
6737 } else if (os_strcmp(buf, "PMKSA") == 0) {
6738 reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, reply,
6740 } else if (os_strcmp(buf, "PMKSA_FLUSH") == 0) {
6741 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
6742 } else if (os_strncmp(buf, "SET ", 4) == 0) {
6743 if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4))
6745 } else if (os_strncmp(buf, "GET ", 4) == 0) {
6746 reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4,
6748 } else if (os_strcmp(buf, "LOGON") == 0) {
6749 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
6750 } else if (os_strcmp(buf, "LOGOFF") == 0) {
6751 eapol_sm_notify_logoff(wpa_s->eapol, TRUE);
6752 } else if (os_strcmp(buf, "REASSOCIATE") == 0) {
6753 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
6756 wpas_request_connection(wpa_s);
6757 } else if (os_strcmp(buf, "REATTACH") == 0) {
6758 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED ||
6759 !wpa_s->current_ssid)
6762 wpa_s->reattach = 1;
6763 wpas_request_connection(wpa_s);
6765 } else if (os_strcmp(buf, "RECONNECT") == 0) {
6766 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
6768 else if (wpa_s->disconnected)
6769 wpas_request_connection(wpa_s);
6770 #ifdef IEEE8021X_EAPOL
6771 } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) {
6772 if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8))
6774 #endif /* IEEE8021X_EAPOL */
6775 #ifdef CONFIG_PEERKEY
6776 } else if (os_strncmp(buf, "STKSTART ", 9) == 0) {
6777 if (wpa_supplicant_ctrl_iface_stkstart(wpa_s, buf + 9))
6779 #endif /* CONFIG_PEERKEY */
6780 #ifdef CONFIG_IEEE80211R
6781 } else if (os_strncmp(buf, "FT_DS ", 6) == 0) {
6782 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6))
6784 #endif /* CONFIG_IEEE80211R */
6786 } else if (os_strcmp(buf, "WPS_PBC") == 0) {
6787 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL);
6789 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
6793 } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) {
6794 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8);
6796 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
6800 } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {
6801 reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8,
6804 } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) {
6805 reply_len = wpa_supplicant_ctrl_iface_wps_check_pin(
6806 wpa_s, buf + 14, reply, reply_size);
6807 } else if (os_strcmp(buf, "WPS_CANCEL") == 0) {
6808 if (wpas_wps_cancel(wpa_s))
6810 #ifdef CONFIG_WPS_NFC
6811 } else if (os_strcmp(buf, "WPS_NFC") == 0) {
6812 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, NULL))
6814 } else if (os_strncmp(buf, "WPS_NFC ", 8) == 0) {
6815 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, buf + 8))
6817 } else if (os_strncmp(buf, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
6818 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_config_token(
6819 wpa_s, buf + 21, reply, reply_size);
6820 } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) {
6821 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_token(
6822 wpa_s, buf + 14, reply, reply_size);
6823 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) {
6824 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s,
6827 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
6828 reply_len = wpas_ctrl_nfc_get_handover_req(
6829 wpa_s, buf + 21, reply, reply_size);
6830 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
6831 reply_len = wpas_ctrl_nfc_get_handover_sel(
6832 wpa_s, buf + 21, reply, reply_size);
6833 } else if (os_strncmp(buf, "NFC_REPORT_HANDOVER ", 20) == 0) {
6834 if (wpas_ctrl_nfc_report_handover(wpa_s, buf + 20))
6836 #endif /* CONFIG_WPS_NFC */
6837 } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) {
6838 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8))
6841 } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) {
6842 reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin(
6843 wpa_s, buf + 11, reply, reply_size);
6844 #endif /* CONFIG_AP */
6845 #ifdef CONFIG_WPS_ER
6846 } else if (os_strcmp(buf, "WPS_ER_START") == 0) {
6847 if (wpas_wps_er_start(wpa_s, NULL))
6849 } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) {
6850 if (wpas_wps_er_start(wpa_s, buf + 13))
6852 } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) {
6853 if (wpas_wps_er_stop(wpa_s))
6855 } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) {
6856 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11))
6858 } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) {
6859 int ret = wpas_wps_er_pbc(wpa_s, buf + 11);
6861 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
6863 } else if (ret == -3) {
6864 os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18);
6866 } else if (ret == -4) {
6867 os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20);
6871 } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) {
6872 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13))
6874 } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) {
6875 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s,
6878 } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) {
6879 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14))
6881 #ifdef CONFIG_WPS_NFC
6882 } else if (os_strncmp(buf, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
6883 reply_len = wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
6884 wpa_s, buf + 24, reply, reply_size);
6885 #endif /* CONFIG_WPS_NFC */
6886 #endif /* CONFIG_WPS_ER */
6887 #endif /* CONFIG_WPS */
6888 #ifdef CONFIG_IBSS_RSN
6889 } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) {
6890 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9))
6892 #endif /* CONFIG_IBSS_RSN */
6894 } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) {
6895 if (p2p_ctrl_find(wpa_s, buf + 9))
6897 } else if (os_strcmp(buf, "P2P_FIND") == 0) {
6898 if (p2p_ctrl_find(wpa_s, ""))
6900 } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) {
6901 wpas_p2p_stop_find(wpa_s);
6902 } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) {
6903 reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply,
6905 } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) {
6906 if (p2p_ctrl_listen(wpa_s, buf + 11))
6908 } else if (os_strcmp(buf, "P2P_LISTEN") == 0) {
6909 if (p2p_ctrl_listen(wpa_s, ""))
6911 } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) {
6912 if (wpas_p2p_group_remove(wpa_s, buf + 17))
6914 } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) {
6915 if (wpas_p2p_group_add(wpa_s, 0, 0, 0, 0))
6917 } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) {
6918 if (p2p_ctrl_group_add(wpa_s, buf + 14))
6920 } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) {
6921 if (p2p_ctrl_prov_disc(wpa_s, buf + 14))
6923 } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) {
6924 reply_len = p2p_get_passphrase(wpa_s, reply, reply_size);
6925 } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) {
6926 reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply,
6928 } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
6929 if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0)
6931 } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) {
6932 if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0)
6934 } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) {
6935 wpas_p2p_sd_service_update(wpa_s);
6936 } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
6937 if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0)
6939 } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) {
6940 wpas_p2p_service_flush(wpa_s);
6941 } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) {
6942 if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0)
6944 } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) {
6945 if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0)
6947 } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) {
6948 if (p2p_ctrl_reject(wpa_s, buf + 11) < 0)
6950 } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) {
6951 if (p2p_ctrl_invite(wpa_s, buf + 11) < 0)
6953 } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) {
6954 reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply,
6956 } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) {
6957 if (p2p_ctrl_set(wpa_s, buf + 8) < 0)
6959 } else if (os_strcmp(buf, "P2P_FLUSH") == 0) {
6960 p2p_ctrl_flush(wpa_s);
6961 } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) {
6962 if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0)
6964 } else if (os_strcmp(buf, "P2P_CANCEL") == 0) {
6965 if (wpas_p2p_cancel(wpa_s))
6967 } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) {
6968 if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0)
6970 } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) {
6971 if (p2p_ctrl_presence_req(wpa_s, "") < 0)
6973 } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) {
6974 if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0)
6976 } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) {
6977 if (p2p_ctrl_ext_listen(wpa_s, "") < 0)
6979 } else if (os_strncmp(buf, "P2P_REMOVE_CLIENT ", 18) == 0) {
6980 if (p2p_ctrl_remove_client(wpa_s, buf + 18) < 0)
6982 #endif /* CONFIG_P2P */
6983 #ifdef CONFIG_WIFI_DISPLAY
6984 } else if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0) {
6985 if (wifi_display_subelem_set(wpa_s->global, buf + 16) < 0)
6987 } else if (os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) {
6988 reply_len = wifi_display_subelem_get(wpa_s->global, buf + 16,
6990 #endif /* CONFIG_WIFI_DISPLAY */
6991 #ifdef CONFIG_INTERWORKING
6992 } else if (os_strcmp(buf, "FETCH_ANQP") == 0) {
6993 if (interworking_fetch_anqp(wpa_s) < 0)
6995 } else if (os_strcmp(buf, "STOP_FETCH_ANQP") == 0) {
6996 interworking_stop_fetch_anqp(wpa_s);
6997 } else if (os_strcmp(buf, "INTERWORKING_SELECT") == 0) {
6998 if (ctrl_interworking_select(wpa_s, NULL) < 0)
7000 } else if (os_strncmp(buf, "INTERWORKING_SELECT ", 20) == 0) {
7001 if (ctrl_interworking_select(wpa_s, buf + 20) < 0)
7003 } else if (os_strncmp(buf, "INTERWORKING_CONNECT ", 21) == 0) {
7004 if (ctrl_interworking_connect(wpa_s, buf + 21) < 0)
7006 } else if (os_strncmp(buf, "ANQP_GET ", 9) == 0) {
7007 if (get_anqp(wpa_s, buf + 9) < 0)
7009 } else if (os_strncmp(buf, "GAS_REQUEST ", 12) == 0) {
7010 if (gas_request(wpa_s, buf + 12) < 0)
7012 } else if (os_strncmp(buf, "GAS_RESPONSE_GET ", 17) == 0) {
7013 reply_len = gas_response_get(wpa_s, buf + 17, reply,
7015 #endif /* CONFIG_INTERWORKING */
7017 } else if (os_strncmp(buf, "HS20_ANQP_GET ", 14) == 0) {
7018 if (get_hs20_anqp(wpa_s, buf + 14) < 0)
7020 } else if (os_strncmp(buf, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
7021 if (hs20_get_nai_home_realm_list(wpa_s, buf + 29) < 0)
7023 } else if (os_strncmp(buf, "HS20_ICON_REQUEST ", 18) == 0) {
7024 if (hs20_icon_request(wpa_s, buf + 18) < 0)
7026 } else if (os_strcmp(buf, "FETCH_OSU") == 0) {
7027 if (hs20_fetch_osu(wpa_s) < 0)
7029 } else if (os_strcmp(buf, "CANCEL_FETCH_OSU") == 0) {
7030 hs20_cancel_fetch_osu(wpa_s);
7031 #endif /* CONFIG_HS20 */
7032 } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0)
7034 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
7035 wpa_s, buf + os_strlen(WPA_CTRL_RSP)))
7039 * Notify response from timeout to allow the control
7040 * interface response to be sent first.
7042 eloop_register_timeout(0, 0, wpas_ctrl_eapol_response,
7045 } else if (os_strcmp(buf, "RECONFIGURE") == 0) {
7046 if (wpa_supplicant_reload_configuration(wpa_s))
7048 } else if (os_strcmp(buf, "TERMINATE") == 0) {
7049 wpa_supplicant_terminate_proc(wpa_s->global);
7050 } else if (os_strncmp(buf, "BSSID ", 6) == 0) {
7051 if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6))
7053 } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) {
7054 reply_len = wpa_supplicant_ctrl_iface_blacklist(
7055 wpa_s, buf + 9, reply, reply_size);
7056 } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) {
7057 reply_len = wpa_supplicant_ctrl_iface_log_level(
7058 wpa_s, buf + 9, reply, reply_size);
7059 } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) {
7060 reply_len = wpa_supplicant_ctrl_iface_list_networks(
7061 wpa_s, reply, reply_size);
7062 } else if (os_strcmp(buf, "DISCONNECT") == 0) {
7064 wpa_s->sme.prev_bssid_set = 0;
7065 #endif /* CONFIG_SME */
7066 wpa_s->reassociate = 0;
7067 wpa_s->disconnected = 1;
7068 wpa_supplicant_cancel_sched_scan(wpa_s);
7069 wpa_supplicant_cancel_scan(wpa_s);
7070 wpa_supplicant_deauthenticate(wpa_s,
7071 WLAN_REASON_DEAUTH_LEAVING);
7072 } else if (os_strcmp(buf, "SCAN") == 0) {
7073 wpas_ctrl_scan(wpa_s, NULL, reply, reply_size, &reply_len);
7074 } else if (os_strncmp(buf, "SCAN ", 5) == 0) {
7075 wpas_ctrl_scan(wpa_s, buf + 5, reply, reply_size, &reply_len);
7076 } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) {
7077 reply_len = wpa_supplicant_ctrl_iface_scan_results(
7078 wpa_s, reply, reply_size);
7079 } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) {
7080 if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15))
7082 } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) {
7083 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15))
7085 } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) {
7086 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16))
7088 } else if (os_strcmp(buf, "ADD_NETWORK") == 0) {
7089 reply_len = wpa_supplicant_ctrl_iface_add_network(
7090 wpa_s, reply, reply_size);
7091 } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) {
7092 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15))
7094 } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
7095 if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12))
7097 } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) {
7098 reply_len = wpa_supplicant_ctrl_iface_get_network(
7099 wpa_s, buf + 12, reply, reply_size);
7100 } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) {
7101 if (wpa_supplicant_ctrl_iface_dup_network(wpa_s, buf + 12))
7103 } else if (os_strcmp(buf, "LIST_CREDS") == 0) {
7104 reply_len = wpa_supplicant_ctrl_iface_list_creds(
7105 wpa_s, reply, reply_size);
7106 } else if (os_strcmp(buf, "ADD_CRED") == 0) {
7107 reply_len = wpa_supplicant_ctrl_iface_add_cred(
7108 wpa_s, reply, reply_size);
7109 } else if (os_strncmp(buf, "REMOVE_CRED ", 12) == 0) {
7110 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s, buf + 12))
7112 } else if (os_strncmp(buf, "SET_CRED ", 9) == 0) {
7113 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s, buf + 9))
7115 } else if (os_strncmp(buf, "GET_CRED ", 9) == 0) {
7116 reply_len = wpa_supplicant_ctrl_iface_get_cred(wpa_s, buf + 9,
7119 #ifndef CONFIG_NO_CONFIG_WRITE
7120 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
7121 if (wpa_supplicant_ctrl_iface_save_config(wpa_s))
7123 #endif /* CONFIG_NO_CONFIG_WRITE */
7124 } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
7125 reply_len = wpa_supplicant_ctrl_iface_get_capability(
7126 wpa_s, buf + 15, reply, reply_size);
7127 } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) {
7128 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8))
7130 } else if (os_strncmp(buf, "SCAN_INTERVAL ", 14) == 0) {
7131 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s, buf + 14))
7133 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
7134 reply_len = wpa_supplicant_global_iface_list(
7135 wpa_s->global, reply, reply_size);
7136 } else if (os_strcmp(buf, "INTERFACES") == 0) {
7137 reply_len = wpa_supplicant_global_iface_interfaces(
7138 wpa_s->global, reply, reply_size);
7139 } else if (os_strncmp(buf, "BSS ", 4) == 0) {
7140 reply_len = wpa_supplicant_ctrl_iface_bss(
7141 wpa_s, buf + 4, reply, reply_size);
7143 } else if (os_strcmp(buf, "STA-FIRST") == 0) {
7144 reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size);
7145 } else if (os_strncmp(buf, "STA ", 4) == 0) {
7146 reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply,
7148 } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) {
7149 reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply,
7151 } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) {
7152 if (ap_ctrl_iface_sta_deauthenticate(wpa_s, buf + 15))
7154 } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) {
7155 if (ap_ctrl_iface_sta_disassociate(wpa_s, buf + 13))
7157 } else if (os_strncmp(buf, "CHAN_SWITCH ", 12) == 0) {
7158 if (ap_ctrl_iface_chanswitch(wpa_s, buf + 12))
7160 #endif /* CONFIG_AP */
7161 } else if (os_strcmp(buf, "SUSPEND") == 0) {
7162 wpas_notify_suspend(wpa_s->global);
7163 } else if (os_strcmp(buf, "RESUME") == 0) {
7164 wpas_notify_resume(wpa_s->global);
7165 #ifdef CONFIG_TESTING_OPTIONS
7166 } else if (os_strcmp(buf, "DROP_SA") == 0) {
7167 wpa_supplicant_ctrl_iface_drop_sa(wpa_s);
7168 #endif /* CONFIG_TESTING_OPTIONS */
7169 } else if (os_strncmp(buf, "ROAM ", 5) == 0) {
7170 if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5))
7172 } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) {
7173 if (wpa_supplicant_ctrl_iface_sta_autoconnect(wpa_s, buf + 16))
7175 } else if (os_strncmp(buf, "BSS_EXPIRE_AGE ", 15) == 0) {
7176 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s, buf + 15))
7178 } else if (os_strncmp(buf, "BSS_EXPIRE_COUNT ", 17) == 0) {
7179 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s,
7182 } else if (os_strncmp(buf, "BSS_FLUSH ", 10) == 0) {
7183 if (wpa_supplicant_ctrl_iface_bss_flush(wpa_s, buf + 10))
7186 } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) {
7187 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14))
7189 } else if (os_strncmp(buf, "TDLS_SETUP ", 11) == 0) {
7190 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s, buf + 11))
7192 } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) {
7193 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14))
7195 #endif /* CONFIG_TDLS */
7196 } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) {
7197 reply_len = wpa_supplicant_signal_poll(wpa_s, reply,
7199 } else if (os_strncmp(buf, "PKTCNT_POLL", 11) == 0) {
7200 reply_len = wpa_supplicant_pktcnt_poll(wpa_s, reply,
7202 #ifdef CONFIG_AUTOSCAN
7203 } else if (os_strncmp(buf, "AUTOSCAN ", 9) == 0) {
7204 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s, buf + 9))
7206 #endif /* CONFIG_AUTOSCAN */
7208 } else if (os_strncmp(buf, "DRIVER ", 7) == 0) {
7209 reply_len = wpa_supplicant_driver_cmd(wpa_s, buf + 7, reply,
7211 #endif /* ANDROID */
7212 } else if (os_strncmp(buf, "VENDOR ", 7) == 0) {
7213 reply_len = wpa_supplicant_vendor_cmd(wpa_s, buf + 7, reply,
7215 } else if (os_strcmp(buf, "REAUTHENTICATE") == 0) {
7216 pmksa_cache_clear_current(wpa_s->wpa);
7217 eapol_sm_request_reauth(wpa_s->eapol);
7219 } else if (os_strncmp(buf, "WNM_SLEEP ", 10) == 0) {
7220 if (wpas_ctrl_iface_wnm_sleep(wpa_s, buf + 10))
7222 } else if (os_strncmp(buf, "WNM_BSS_QUERY ", 10) == 0) {
7223 if (wpas_ctrl_iface_wnm_bss_query(wpa_s, buf + 10))
7225 #endif /* CONFIG_WNM */
7226 } else if (os_strcmp(buf, "FLUSH") == 0) {
7227 wpa_supplicant_ctrl_iface_flush(wpa_s);
7228 } else if (os_strncmp(buf, "RADIO_WORK ", 11) == 0) {
7229 reply_len = wpas_ctrl_radio_work(wpa_s, buf + 11, reply,
7231 #ifdef CONFIG_TESTING_OPTIONS
7232 } else if (os_strncmp(buf, "MGMT_TX ", 8) == 0) {
7233 if (wpas_ctrl_iface_mgmt_tx(wpa_s, buf + 8) < 0)
7235 } else if (os_strcmp(buf, "MGMT_TX_DONE") == 0) {
7236 wpas_ctrl_iface_mgmt_tx_done(wpa_s);
7237 } else if (os_strncmp(buf, "DRIVER_EVENT ", 13) == 0) {
7238 if (wpas_ctrl_iface_driver_event(wpa_s, buf + 13) < 0)
7240 } else if (os_strncmp(buf, "EAPOL_RX ", 9) == 0) {
7241 if (wpas_ctrl_iface_eapol_rx(wpa_s, buf + 9) < 0)
7243 } else if (os_strncmp(buf, "DATA_TEST_CONFIG ", 17) == 0) {
7244 if (wpas_ctrl_iface_data_test_config(wpa_s, buf + 17) < 0)
7246 } else if (os_strncmp(buf, "DATA_TEST_TX ", 13) == 0) {
7247 if (wpas_ctrl_iface_data_test_tx(wpa_s, buf + 13) < 0)
7249 #endif /* CONFIG_TESTING_OPTIONS */
7250 } else if (os_strncmp(buf, "VENDOR_ELEM_ADD ", 16) == 0) {
7251 if (wpas_ctrl_vendor_elem_add(wpa_s, buf + 16) < 0)
7253 } else if (os_strncmp(buf, "VENDOR_ELEM_GET ", 16) == 0) {
7254 reply_len = wpas_ctrl_vendor_elem_get(wpa_s, buf + 16, reply,
7256 } else if (os_strncmp(buf, "VENDOR_ELEM_REMOVE ", 19) == 0) {
7257 if (wpas_ctrl_vendor_elem_remove(wpa_s, buf + 19) < 0)
7260 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
7264 if (reply_len < 0) {
7265 os_memcpy(reply, "FAIL\n", 5);
7269 *resp_len = reply_len;
7274 static int wpa_supplicant_global_iface_add(struct wpa_global *global,
7277 struct wpa_interface iface;
7281 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
7282 * TAB<bridge_ifname>
7284 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd);
7286 os_memset(&iface, 0, sizeof(iface));
7289 iface.ifname = pos = cmd;
7290 pos = os_strchr(pos, '\t');
7293 if (iface.ifname[0] == '\0')
7298 iface.confname = pos;
7299 pos = os_strchr(pos, '\t');
7302 if (iface.confname[0] == '\0')
7303 iface.confname = NULL;
7308 pos = os_strchr(pos, '\t');
7311 if (iface.driver[0] == '\0')
7312 iface.driver = NULL;
7316 iface.ctrl_interface = pos;
7317 pos = os_strchr(pos, '\t');
7320 if (iface.ctrl_interface[0] == '\0')
7321 iface.ctrl_interface = NULL;
7325 iface.driver_param = pos;
7326 pos = os_strchr(pos, '\t');
7329 if (iface.driver_param[0] == '\0')
7330 iface.driver_param = NULL;
7334 iface.bridge_ifname = pos;
7335 pos = os_strchr(pos, '\t');
7338 if (iface.bridge_ifname[0] == '\0')
7339 iface.bridge_ifname = NULL;
7344 if (wpa_supplicant_get_iface(global, iface.ifname))
7347 return wpa_supplicant_add_iface(global, &iface) ? 0 : -1;
7351 static int wpa_supplicant_global_iface_remove(struct wpa_global *global,
7354 struct wpa_supplicant *wpa_s;
7356 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd);
7358 wpa_s = wpa_supplicant_get_iface(global, cmd);
7361 return wpa_supplicant_remove_iface(global, wpa_s, 0);
7365 static void wpa_free_iface_info(struct wpa_interface_info *iface)
7367 struct wpa_interface_info *prev;
7371 iface = iface->next;
7373 os_free(prev->ifname);
7374 os_free(prev->desc);
7380 static int wpa_supplicant_global_iface_list(struct wpa_global *global,
7384 struct wpa_interface_info *iface = NULL, *last = NULL, *tmp;
7387 for (i = 0; wpa_drivers[i]; i++) {
7388 struct wpa_driver_ops *drv = wpa_drivers[i];
7389 if (drv->get_interfaces == NULL)
7391 tmp = drv->get_interfaces(global->drv_priv[i]);
7405 for (tmp = iface; tmp; tmp = tmp->next) {
7406 res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n",
7407 tmp->drv_name, tmp->ifname,
7408 tmp->desc ? tmp->desc : "");
7409 if (res < 0 || res >= end - pos) {
7416 wpa_free_iface_info(iface);
7422 static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
7427 struct wpa_supplicant *wpa_s;
7429 wpa_s = global->ifaces;
7434 res = os_snprintf(pos, end - pos, "%s\n", wpa_s->ifname);
7435 if (res < 0 || res >= end - pos) {
7440 wpa_s = wpa_s->next;
7446 static char * wpas_global_ctrl_iface_ifname(struct wpa_global *global,
7448 char *cmd, size_t *resp_len)
7450 struct wpa_supplicant *wpa_s;
7452 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
7453 if (os_strcmp(ifname, wpa_s->ifname) == 0)
7457 if (wpa_s == NULL) {
7458 char *resp = os_strdup("FAIL-NO-IFNAME-MATCH\n");
7460 *resp_len = os_strlen(resp);
7466 return wpa_supplicant_ctrl_iface_process(wpa_s, cmd, resp_len);
7470 static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global *global,
7471 char *buf, size_t *resp_len)
7474 static const char * cmd[] = {
7480 "P2P_GET_PASSPHRASE",
7481 "P2P_SERVICE_UPDATE",
7482 "P2P_SERVICE_FLUSH",
7489 static const char * prefix[] = {
7492 #endif /* ANDROID */
7498 "P2P_GROUP_REMOVE ",
7501 "P2P_SERV_DISC_REQ ",
7502 "P2P_SERV_DISC_CANCEL_REQ ",
7503 "P2P_SERV_DISC_RESP ",
7504 "P2P_SERV_DISC_EXTERNAL ",
7512 "P2P_PRESENCE_REQ ",
7514 "P2P_REMOVE_CLIENT ",
7515 "NFC_GET_HANDOVER_SEL ",
7516 "NFC_GET_HANDOVER_REQ ",
7517 "NFC_REPORT_HANDOVER ",
7523 if (global->p2p_init_wpa_s == NULL)
7526 for (i = 0; !found && cmd[i]; i++) {
7527 if (os_strcmp(buf, cmd[i]) == 0)
7531 for (i = 0; !found && prefix[i]; i++) {
7532 if (os_strncmp(buf, prefix[i], os_strlen(prefix[i])) == 0)
7537 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
7539 #endif /* CONFIG_P2P */
7544 static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global *global,
7545 char *buf, size_t *resp_len)
7547 #ifdef CONFIG_WIFI_DISPLAY
7548 if (global->p2p_init_wpa_s == NULL)
7550 if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0 ||
7551 os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0)
7552 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
7554 #endif /* CONFIG_WIFI_DISPLAY */
7559 static char * wpas_global_ctrl_iface_redir(struct wpa_global *global,
7560 char *buf, size_t *resp_len)
7564 ret = wpas_global_ctrl_iface_redir_p2p(global, buf, resp_len);
7568 ret = wpas_global_ctrl_iface_redir_wfd(global, buf, resp_len);
7576 static int wpas_global_ctrl_iface_set(struct wpa_global *global, char *cmd)
7580 value = os_strchr(cmd, ' ');
7585 wpa_printf(MSG_DEBUG, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd, value);
7587 #ifdef CONFIG_WIFI_DISPLAY
7588 if (os_strcasecmp(cmd, "wifi_display") == 0) {
7589 wifi_display_enable(global, !!atoi(value));
7592 #endif /* CONFIG_WIFI_DISPLAY */
7594 /* Restore cmd to its original value to allow redirection */
7601 #ifndef CONFIG_NO_CONFIG_WRITE
7602 static int wpas_global_ctrl_iface_save_config(struct wpa_global *global)
7604 int ret = 0, saved = 0;
7605 struct wpa_supplicant *wpa_s;
7607 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
7608 if (!wpa_s->conf->update_config) {
7609 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
7613 if (wpa_config_write(wpa_s->confname, wpa_s->conf)) {
7614 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
7617 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
7622 if (!saved && !ret) {
7623 wpa_dbg(wpa_s, MSG_DEBUG,
7624 "CTRL_IFACE: SAVE_CONFIG - No configuration files could be updated");
7630 #endif /* CONFIG_NO_CONFIG_WRITE */
7633 static int wpas_global_ctrl_iface_status(struct wpa_global *global,
7634 char *buf, size_t buflen)
7638 struct wpa_supplicant *wpa_s;
7644 if (global->p2p && !global->p2p_disabled) {
7645 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
7648 MAC2STR(global->p2p_dev_addr),
7649 p2p_get_state_txt(global->p2p));
7650 if (ret < 0 || ret >= end - pos)
7653 } else if (global->p2p) {
7654 ret = os_snprintf(pos, end - pos, "p2p_state=DISABLED\n");
7655 if (ret < 0 || ret >= end - pos)
7659 #endif /* CONFIG_P2P */
7661 #ifdef CONFIG_WIFI_DISPLAY
7662 ret = os_snprintf(pos, end - pos, "wifi_display=%d\n",
7663 !!global->wifi_display);
7664 if (ret < 0 || ret >= end - pos)
7667 #endif /* CONFIG_WIFI_DISPLAY */
7669 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
7670 ret = os_snprintf(pos, end - pos, "ifname=%s\n"
7671 "address=" MACSTR "\n",
7672 wpa_s->ifname, MAC2STR(wpa_s->own_addr));
7673 if (ret < 0 || ret >= end - pos)
7682 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
7683 char *buf, size_t *resp_len)
7686 const int reply_size = 2048;
7688 int level = MSG_DEBUG;
7690 if (os_strncmp(buf, "IFNAME=", 7) == 0) {
7691 char *pos = os_strchr(buf + 7, ' ');
7694 return wpas_global_ctrl_iface_ifname(global,
7700 reply = wpas_global_ctrl_iface_redir(global, buf, resp_len);
7704 if (os_strcmp(buf, "PING") == 0)
7705 level = MSG_EXCESSIVE;
7706 wpa_hexdump_ascii(level, "RX global ctrl_iface",
7707 (const u8 *) buf, os_strlen(buf));
7709 reply = os_malloc(reply_size);
7710 if (reply == NULL) {
7715 os_memcpy(reply, "OK\n", 3);
7718 if (os_strcmp(buf, "PING") == 0) {
7719 os_memcpy(reply, "PONG\n", 5);
7721 } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) {
7722 if (wpa_supplicant_global_iface_add(global, buf + 14))
7724 } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) {
7725 if (wpa_supplicant_global_iface_remove(global, buf + 17))
7727 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
7728 reply_len = wpa_supplicant_global_iface_list(
7729 global, reply, reply_size);
7730 } else if (os_strcmp(buf, "INTERFACES") == 0) {
7731 reply_len = wpa_supplicant_global_iface_interfaces(
7732 global, reply, reply_size);
7733 } else if (os_strcmp(buf, "TERMINATE") == 0) {
7734 wpa_supplicant_terminate_proc(global);
7735 } else if (os_strcmp(buf, "SUSPEND") == 0) {
7736 wpas_notify_suspend(global);
7737 } else if (os_strcmp(buf, "RESUME") == 0) {
7738 wpas_notify_resume(global);
7739 } else if (os_strncmp(buf, "SET ", 4) == 0) {
7740 if (wpas_global_ctrl_iface_set(global, buf + 4)) {
7742 if (global->p2p_init_wpa_s) {
7744 /* Check if P2P redirection would work for this
7746 return wpa_supplicant_ctrl_iface_process(
7747 global->p2p_init_wpa_s,
7750 #endif /* CONFIG_P2P */
7753 #ifndef CONFIG_NO_CONFIG_WRITE
7754 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
7755 if (wpas_global_ctrl_iface_save_config(global))
7757 #endif /* CONFIG_NO_CONFIG_WRITE */
7758 } else if (os_strcmp(buf, "STATUS") == 0) {
7759 reply_len = wpas_global_ctrl_iface_status(global, reply,
7761 #ifdef CONFIG_MODULE_TESTS
7762 } else if (os_strcmp(buf, "MODULE_TESTS") == 0) {
7763 int wpas_module_tests(void);
7764 if (wpas_module_tests() < 0)
7766 #endif /* CONFIG_MODULE_TESTS */
7767 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
7768 if (wpa_debug_reopen_file() < 0)
7771 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
7775 if (reply_len < 0) {
7776 os_memcpy(reply, "FAIL\n", 5);
7780 *resp_len = reply_len;