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"
11 #include "utils/common.h"
12 #include "utils/eloop.h"
13 #include "utils/uuid.h"
14 #include "common/version.h"
15 #include "common/ieee802_11_defs.h"
16 #include "common/ieee802_11_common.h"
17 #include "common/wpa_ctrl.h"
18 #include "eap_peer/eap.h"
19 #include "eapol_supp/eapol_supp_sm.h"
20 #include "rsn_supp/wpa.h"
21 #include "rsn_supp/preauth.h"
22 #include "rsn_supp/pmksa_cache.h"
23 #include "l2_packet/l2_packet.h"
26 #include "wpa_supplicant_i.h"
28 #include "wps_supplicant.h"
31 #include "p2p_supplicant.h"
33 #include "hs20_supplicant.h"
34 #include "wifi_display.h"
38 #include "ctrl_iface.h"
39 #include "interworking.h"
40 #include "blacklist.h"
43 #include "offchannel.h"
45 static int wpa_supplicant_global_iface_list(struct wpa_global *global,
47 static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
49 static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s,
52 static int set_bssid_filter(struct wpa_supplicant *wpa_s, char *val)
55 u8 addr[ETH_ALEN], *filter = NULL, *n;
62 if (hwaddr_aton(pos, addr)) {
66 n = os_realloc_array(filter, count + 1, ETH_ALEN);
72 os_memcpy(filter + count * ETH_ALEN, addr, ETH_ALEN);
75 pos = os_strchr(pos, ' ');
80 wpa_hexdump(MSG_DEBUG, "bssid_filter", filter, count * ETH_ALEN);
81 os_free(wpa_s->bssid_filter);
82 wpa_s->bssid_filter = filter;
83 wpa_s->bssid_filter_count = count;
89 static int set_disallow_aps(struct wpa_supplicant *wpa_s, char *val)
92 u8 addr[ETH_ALEN], *bssid = NULL, *n;
93 struct wpa_ssid_value *ssid = NULL, *ns;
94 size_t count = 0, ssid_count = 0;
98 * disallow_list ::= <ssid_spec> | <bssid_spec> | <disallow_list> | ""
99 * SSID_SPEC ::= ssid <SSID_HEX>
100 * BSSID_SPEC ::= bssid <BSSID_HEX>
107 if (os_strncmp(pos, "bssid ", 6) == 0) {
110 res = hwaddr_aton2(pos, addr);
114 wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
115 "BSSID value '%s'", pos);
119 n = os_realloc_array(bssid, count + 1, ETH_ALEN);
126 os_memcpy(bssid + count * ETH_ALEN, addr, ETH_ALEN);
128 } else if (os_strncmp(pos, "ssid ", 5) == 0) {
134 if (*end == '\0' || *end == ' ')
139 ns = os_realloc_array(ssid, ssid_count + 1,
140 sizeof(struct wpa_ssid_value));
148 if ((end - pos) & 0x01 || end - pos > 2 * 32 ||
149 hexstr2bin(pos, ssid[ssid_count].ssid,
150 (end - pos) / 2) < 0) {
153 wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
154 "SSID value '%s'", pos);
157 ssid[ssid_count].ssid_len = (end - pos) / 2;
158 wpa_hexdump_ascii(MSG_DEBUG, "disallow_aps SSID",
159 ssid[ssid_count].ssid,
160 ssid[ssid_count].ssid_len);
164 wpa_printf(MSG_DEBUG, "Unexpected disallow_aps value "
171 pos = os_strchr(pos, ' ');
176 wpa_hexdump(MSG_DEBUG, "disallow_aps_bssid", bssid, count * ETH_ALEN);
177 os_free(wpa_s->disallow_aps_bssid);
178 wpa_s->disallow_aps_bssid = bssid;
179 wpa_s->disallow_aps_bssid_count = count;
181 wpa_printf(MSG_DEBUG, "disallow_aps_ssid_count %d", (int) ssid_count);
182 os_free(wpa_s->disallow_aps_ssid);
183 wpa_s->disallow_aps_ssid = ssid;
184 wpa_s->disallow_aps_ssid_count = ssid_count;
186 if (!wpa_s->current_ssid || wpa_s->wpa_state < WPA_AUTHENTICATING)
189 c = wpa_s->current_ssid;
190 if (c->mode != WPAS_MODE_INFRA && c->mode != WPAS_MODE_IBSS)
193 if (!disallowed_bssid(wpa_s, wpa_s->bssid) &&
194 !disallowed_ssid(wpa_s, c->ssid, c->ssid_len))
197 wpa_printf(MSG_DEBUG, "Disconnect and try to find another network "
198 "because current AP was marked disallowed");
201 wpa_s->sme.prev_bssid_set = 0;
202 #endif /* CONFIG_SME */
203 wpa_s->reassociate = 1;
204 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
205 wpa_supplicant_req_scan(wpa_s, 0, 0);
211 #ifndef CONFIG_NO_CONFIG_BLOBS
212 static int wpas_ctrl_set_blob(struct wpa_supplicant *wpa_s, char *pos)
215 struct wpa_config_blob *blob;
218 pos = os_strchr(pos, ' ');
222 len = os_strlen(pos);
226 wpa_printf(MSG_DEBUG, "CTRL: Set blob '%s'", name);
227 blob = os_zalloc(sizeof(*blob));
230 blob->name = os_strdup(name);
231 blob->data = os_malloc(len / 2);
232 if (blob->name == NULL || blob->data == NULL) {
233 wpa_config_free_blob(blob);
237 if (hexstr2bin(pos, blob->data, len / 2) < 0) {
238 wpa_printf(MSG_DEBUG, "CTRL: Invalid blob hex data");
239 wpa_config_free_blob(blob);
244 wpa_config_set_blob(wpa_s->conf, blob);
248 #endif /* CONFIG_NO_CONFIG_BLOBS */
251 static int wpas_ctrl_pno(struct wpa_supplicant *wpa_s, char *cmd)
259 params = os_strchr(cmd, ' ');
260 os_free(wpa_s->manual_sched_scan_freqs);
263 pos = os_strstr(params, "freq=");
265 freqs = freq_range_to_channel_list(wpa_s,
268 wpa_s->manual_sched_scan_freqs = freqs;
269 ret = wpas_start_pno(wpa_s);
271 ret = wpas_stop_pno(wpa_s);
277 static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s,
283 value = os_strchr(cmd, ' ');
288 wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value);
289 if (os_strcasecmp(cmd, "EAPOL::heldPeriod") == 0) {
290 eapol_sm_configure(wpa_s->eapol,
291 atoi(value), -1, -1, -1);
292 } else if (os_strcasecmp(cmd, "EAPOL::authPeriod") == 0) {
293 eapol_sm_configure(wpa_s->eapol,
294 -1, atoi(value), -1, -1);
295 } else if (os_strcasecmp(cmd, "EAPOL::startPeriod") == 0) {
296 eapol_sm_configure(wpa_s->eapol,
297 -1, -1, atoi(value), -1);
298 } else if (os_strcasecmp(cmd, "EAPOL::maxStart") == 0) {
299 eapol_sm_configure(wpa_s->eapol,
300 -1, -1, -1, atoi(value));
301 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKLifetime") == 0) {
302 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME,
305 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKReauthThreshold") ==
307 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD,
310 } else if (os_strcasecmp(cmd, "dot11RSNAConfigSATimeout") == 0) {
311 if (wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, atoi(value)))
313 } else if (os_strcasecmp(cmd, "wps_fragment_size") == 0) {
314 wpa_s->wps_fragment_size = atoi(value);
315 #ifdef CONFIG_WPS_TESTING
316 } else if (os_strcasecmp(cmd, "wps_version_number") == 0) {
318 val = strtol(value, NULL, 0);
319 if (val < 0 || val > 0xff) {
321 wpa_printf(MSG_DEBUG, "WPS: Invalid "
322 "wps_version_number %ld", val);
324 wps_version_number = val;
325 wpa_printf(MSG_DEBUG, "WPS: Testing - force WPS "
327 (wps_version_number & 0xf0) >> 4,
328 wps_version_number & 0x0f);
330 } else if (os_strcasecmp(cmd, "wps_testing_dummy_cred") == 0) {
331 wps_testing_dummy_cred = atoi(value);
332 wpa_printf(MSG_DEBUG, "WPS: Testing - dummy_cred=%d",
333 wps_testing_dummy_cred);
334 } else if (os_strcasecmp(cmd, "wps_corrupt_pkhash") == 0) {
335 wps_corrupt_pkhash = atoi(value);
336 wpa_printf(MSG_DEBUG, "WPS: Testing - wps_corrupt_pkhash=%d",
338 #endif /* CONFIG_WPS_TESTING */
339 } else if (os_strcasecmp(cmd, "ampdu") == 0) {
340 if (wpa_drv_ampdu(wpa_s, atoi(value)) < 0)
343 #ifdef CONFIG_TDLS_TESTING
344 } else if (os_strcasecmp(cmd, "tdls_testing") == 0) {
345 extern unsigned int tdls_testing;
346 tdls_testing = strtol(value, NULL, 0);
347 wpa_printf(MSG_DEBUG, "TDLS: tdls_testing=0x%x", tdls_testing);
348 #endif /* CONFIG_TDLS_TESTING */
349 } else if (os_strcasecmp(cmd, "tdls_disabled") == 0) {
350 int disabled = atoi(value);
351 wpa_printf(MSG_DEBUG, "TDLS: tdls_disabled=%d", disabled);
353 if (wpa_drv_tdls_oper(wpa_s, TDLS_DISABLE, NULL) < 0)
355 } else if (wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL) < 0)
357 wpa_tdls_enable(wpa_s->wpa, !disabled);
358 #endif /* CONFIG_TDLS */
359 } else if (os_strcasecmp(cmd, "pno") == 0) {
360 ret = wpas_ctrl_pno(wpa_s, value);
361 } else if (os_strcasecmp(cmd, "radio_disabled") == 0) {
362 int disabled = atoi(value);
363 if (wpa_drv_radio_disable(wpa_s, disabled) < 0)
366 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
367 } else if (os_strcasecmp(cmd, "uapsd") == 0) {
368 if (os_strcmp(value, "disable") == 0)
369 wpa_s->set_sta_uapsd = 0;
373 /* format: BE,BK,VI,VO;max SP Length */
375 pos = os_strchr(value, ',');
380 pos = os_strchr(pos, ',');
385 pos = os_strchr(pos, ',');
390 /* ignore max SP Length for now */
392 wpa_s->set_sta_uapsd = 1;
393 wpa_s->sta_uapsd = 0;
395 wpa_s->sta_uapsd |= BIT(0);
397 wpa_s->sta_uapsd |= BIT(1);
399 wpa_s->sta_uapsd |= BIT(2);
401 wpa_s->sta_uapsd |= BIT(3);
403 } else if (os_strcasecmp(cmd, "ps") == 0) {
404 ret = wpa_drv_set_p2p_powersave(wpa_s, atoi(value), -1, -1);
405 #ifdef CONFIG_WIFI_DISPLAY
406 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
407 int enabled = !!atoi(value);
408 if (enabled && !wpa_s->global->p2p)
411 wifi_display_enable(wpa_s->global, enabled);
412 #endif /* CONFIG_WIFI_DISPLAY */
413 } else if (os_strcasecmp(cmd, "bssid_filter") == 0) {
414 ret = set_bssid_filter(wpa_s, value);
415 } else if (os_strcasecmp(cmd, "disallow_aps") == 0) {
416 ret = set_disallow_aps(wpa_s, value);
417 } else if (os_strcasecmp(cmd, "no_keep_alive") == 0) {
418 wpa_s->no_keep_alive = !!atoi(value);
419 #ifdef CONFIG_TESTING_OPTIONS
420 } else if (os_strcasecmp(cmd, "ext_mgmt_frame_handling") == 0) {
421 wpa_s->ext_mgmt_frame_handling = !!atoi(value);
422 #endif /* CONFIG_TESTING_OPTIONS */
423 #ifndef CONFIG_NO_CONFIG_BLOBS
424 } else if (os_strcmp(cmd, "blob") == 0) {
425 ret = wpas_ctrl_set_blob(wpa_s, value);
426 #endif /* CONFIG_NO_CONFIG_BLOBS */
429 ret = wpa_config_process_global(wpa_s->conf, cmd, -1);
431 wpa_supplicant_update_config(wpa_s);
438 static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s,
439 char *cmd, char *buf, size_t buflen)
443 wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd);
445 if (os_strcmp(cmd, "version") == 0) {
446 res = os_snprintf(buf, buflen, "%s", VERSION_STR);
447 } else if (os_strcasecmp(cmd, "country") == 0) {
448 if (wpa_s->conf->country[0] && wpa_s->conf->country[1])
449 res = os_snprintf(buf, buflen, "%c%c",
450 wpa_s->conf->country[0],
451 wpa_s->conf->country[1]);
452 #ifdef CONFIG_WIFI_DISPLAY
453 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
455 if (wpa_s->global->p2p == NULL ||
456 wpa_s->global->p2p_disabled)
459 enabled = wpa_s->global->wifi_display;
460 res = os_snprintf(buf, buflen, "%d", enabled);
461 if (res < 0 || (unsigned int) res >= buflen)
464 #endif /* CONFIG_WIFI_DISPLAY */
465 #ifdef CONFIG_TESTING_GET_GTK
466 } else if (os_strcmp(cmd, "gtk") == 0) {
467 if (wpa_s->last_gtk_len == 0)
469 res = wpa_snprintf_hex(buf, buflen, wpa_s->last_gtk,
470 wpa_s->last_gtk_len);
472 #endif /* CONFIG_TESTING_GET_GTK */
475 if (res < 0 || (unsigned int) res >= buflen)
481 #ifdef IEEE8021X_EAPOL
482 static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s,
486 struct wpa_ssid *ssid = wpa_s->current_ssid;
488 if (hwaddr_aton(addr, bssid)) {
489 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address "
494 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid));
495 rsn_preauth_deinit(wpa_s->wpa);
496 if (rsn_preauth_init(wpa_s->wpa, bssid, ssid ? &ssid->eap : NULL))
501 #endif /* IEEE8021X_EAPOL */
504 #ifdef CONFIG_PEERKEY
505 /* MLME-STKSTART.request(peer) */
506 static int wpa_supplicant_ctrl_iface_stkstart(
507 struct wpa_supplicant *wpa_s, char *addr)
511 if (hwaddr_aton(addr, peer)) {
512 wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART: invalid "
513 "address '%s'", addr);
517 wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART " MACSTR,
520 return wpa_sm_stkstart(wpa_s->wpa, peer);
522 #endif /* CONFIG_PEERKEY */
527 static int wpa_supplicant_ctrl_iface_tdls_discover(
528 struct wpa_supplicant *wpa_s, char *addr)
533 if (hwaddr_aton(addr, peer)) {
534 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER: invalid "
535 "address '%s'", addr);
539 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER " MACSTR,
542 if (wpa_tdls_is_external_setup(wpa_s->wpa))
543 ret = wpa_tdls_send_discovery_request(wpa_s->wpa, peer);
545 ret = wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer);
551 static int wpa_supplicant_ctrl_iface_tdls_setup(
552 struct wpa_supplicant *wpa_s, char *addr)
557 if (hwaddr_aton(addr, peer)) {
558 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP: invalid "
559 "address '%s'", addr);
563 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP " MACSTR,
566 if ((wpa_s->conf->tdls_external_control) &&
567 wpa_tdls_is_external_setup(wpa_s->wpa))
568 return wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
570 wpa_tdls_remove(wpa_s->wpa, peer);
572 if (wpa_tdls_is_external_setup(wpa_s->wpa))
573 ret = wpa_tdls_start(wpa_s->wpa, peer);
575 ret = wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
581 static int wpa_supplicant_ctrl_iface_tdls_teardown(
582 struct wpa_supplicant *wpa_s, char *addr)
587 if (os_strcmp(addr, "*") == 0) {
588 /* remove everyone */
589 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN *");
590 wpa_tdls_teardown_peers(wpa_s->wpa);
594 if (hwaddr_aton(addr, peer)) {
595 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN: invalid "
596 "address '%s'", addr);
600 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN " MACSTR,
603 if ((wpa_s->conf->tdls_external_control) &&
604 wpa_tdls_is_external_setup(wpa_s->wpa))
605 return wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
607 if (wpa_tdls_is_external_setup(wpa_s->wpa))
608 ret = wpa_tdls_teardown_link(
610 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED);
612 ret = wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
618 static int ctrl_iface_get_capability_tdls(
619 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
623 ret = os_snprintf(buf, buflen, "%s\n",
624 wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT ?
626 WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP ?
627 "EXTERNAL" : "INTERNAL") : "UNSUPPORTED");
628 if (ret < 0 || (size_t) ret > buflen)
633 #endif /* CONFIG_TDLS */
636 #ifdef CONFIG_IEEE80211R
637 static int wpa_supplicant_ctrl_iface_ft_ds(
638 struct wpa_supplicant *wpa_s, char *addr)
640 u8 target_ap[ETH_ALEN];
644 if (hwaddr_aton(addr, target_ap)) {
645 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid "
646 "address '%s'", addr);
650 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap));
652 bss = wpa_bss_get_bssid(wpa_s, target_ap);
654 mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN);
658 return wpa_ft_start_over_ds(wpa_s->wpa, target_ap, mdie);
660 #endif /* CONFIG_IEEE80211R */
664 static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s,
667 u8 bssid[ETH_ALEN], *_bssid = bssid;
669 u8 p2p_dev_addr[ETH_ALEN];
670 #endif /* CONFIG_P2P */
672 u8 *_p2p_dev_addr = NULL;
673 #endif /* CONFIG_AP */
675 if (cmd == NULL || os_strcmp(cmd, "any") == 0) {
678 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
679 if (hwaddr_aton(cmd + 13, p2p_dev_addr)) {
680 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid "
681 "P2P Device Address '%s'",
685 _p2p_dev_addr = p2p_dev_addr;
686 #endif /* CONFIG_P2P */
687 } else if (hwaddr_aton(cmd, bssid)) {
688 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
695 return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid, _p2p_dev_addr);
696 #endif /* CONFIG_AP */
698 return wpas_wps_start_pbc(wpa_s, _bssid, 0);
702 static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s,
703 char *cmd, char *buf,
706 u8 bssid[ETH_ALEN], *_bssid = bssid;
710 pin = os_strchr(cmd, ' ');
714 if (os_strcmp(cmd, "any") == 0)
716 else if (os_strcmp(cmd, "get") == 0) {
717 ret = wps_generate_pin();
719 } else if (hwaddr_aton(cmd, bssid)) {
720 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
726 if (wpa_s->ap_iface) {
731 pos = os_strchr(pin, ' ');
738 return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin,
739 buf, buflen, timeout);
741 #endif /* CONFIG_AP */
744 ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0,
748 ret = os_snprintf(buf, buflen, "%s", pin);
749 if (ret < 0 || (size_t) ret >= buflen)
754 ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0, DEV_PW_DEFAULT);
759 /* Return the generated PIN */
760 ret = os_snprintf(buf, buflen, "%08d", ret);
761 if (ret < 0 || (size_t) ret >= buflen)
767 static int wpa_supplicant_ctrl_iface_wps_check_pin(
768 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
775 wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN",
776 (u8 *) cmd, os_strlen(cmd));
777 for (pos = cmd, len = 0; *pos != '\0'; pos++) {
778 if (*pos < '0' || *pos > '9')
782 wpa_printf(MSG_DEBUG, "WPS: Too long PIN");
786 if (len != 4 && len != 8) {
787 wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len);
793 unsigned int pin_val;
795 if (!wps_pin_valid(pin_val)) {
796 wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit");
797 ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n");
798 if (ret < 0 || (size_t) ret >= buflen)
804 ret = os_snprintf(buf, buflen, "%s", pin);
805 if (ret < 0 || (size_t) ret >= buflen)
812 #ifdef CONFIG_WPS_NFC
814 static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant *wpa_s,
817 u8 bssid[ETH_ALEN], *_bssid = bssid;
819 if (cmd == NULL || cmd[0] == '\0')
821 else if (hwaddr_aton(cmd, bssid))
824 return wpas_wps_start_nfc(wpa_s, NULL, _bssid, NULL, 0, 0, NULL, NULL,
829 static int wpa_supplicant_ctrl_iface_wps_nfc_config_token(
830 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
837 pos = os_strchr(cmd, ' ');
840 if (os_strcmp(cmd, "WPS") == 0)
842 else if (os_strcmp(cmd, "NDEF") == 0)
847 buf = wpas_wps_nfc_config_token(wpa_s, ndef, pos);
851 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
862 static int wpa_supplicant_ctrl_iface_wps_nfc_token(
863 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
869 if (os_strcmp(cmd, "WPS") == 0)
871 else if (os_strcmp(cmd, "NDEF") == 0)
876 buf = wpas_wps_nfc_token(wpa_s, ndef);
880 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
891 static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
892 struct wpa_supplicant *wpa_s, char *pos)
900 freq = strstr(pos, " freq=");
904 forced_freq = atoi(freq);
907 len = os_strlen(pos);
912 buf = wpabuf_alloc(len);
915 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
920 ret = wpas_wps_nfc_tag_read(wpa_s, buf, forced_freq);
927 static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant *wpa_s,
928 char *reply, size_t max_len,
934 buf = wpas_wps_nfc_handover_req(wpa_s, ndef);
938 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
950 static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant *wpa_s,
951 char *reply, size_t max_len,
957 buf = wpas_p2p_nfc_handover_req(wpa_s, ndef);
959 wpa_printf(MSG_DEBUG, "P2P: Could not generate NFC handover request");
963 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
972 #endif /* CONFIG_P2P */
975 static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant *wpa_s,
976 char *cmd, char *reply,
982 pos = os_strchr(cmd, ' ');
987 if (os_strcmp(cmd, "WPS") == 0)
989 else if (os_strcmp(cmd, "NDEF") == 0)
994 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
997 return wpas_ctrl_nfc_get_handover_req_wps(
998 wpa_s, reply, max_len, ndef);
1002 if (os_strcmp(pos, "P2P-CR") == 0) {
1003 return wpas_ctrl_nfc_get_handover_req_p2p(
1004 wpa_s, reply, max_len, ndef);
1006 #endif /* CONFIG_P2P */
1012 static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant *wpa_s,
1013 char *reply, size_t max_len,
1014 int ndef, int cr, char *uuid)
1019 buf = wpas_wps_nfc_handover_sel(wpa_s, ndef, cr, uuid);
1023 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1025 reply[res++] = '\n';
1035 static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant *wpa_s,
1036 char *reply, size_t max_len,
1042 buf = wpas_p2p_nfc_handover_sel(wpa_s, ndef, tag);
1046 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1048 reply[res++] = '\n';
1055 #endif /* CONFIG_P2P */
1058 static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant *wpa_s,
1059 char *cmd, char *reply,
1065 pos = os_strchr(cmd, ' ');
1070 if (os_strcmp(cmd, "WPS") == 0)
1072 else if (os_strcmp(cmd, "NDEF") == 0)
1077 pos2 = os_strchr(pos, ' ');
1080 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
1083 return wpas_ctrl_nfc_get_handover_sel_wps(
1084 wpa_s, reply, max_len, ndef,
1085 os_strcmp(pos, "WPS-CR") == 0, pos2);
1089 if (os_strcmp(pos, "P2P-CR") == 0) {
1090 return wpas_ctrl_nfc_get_handover_sel_p2p(
1091 wpa_s, reply, max_len, ndef, 0);
1094 if (os_strcmp(pos, "P2P-CR-TAG") == 0) {
1095 return wpas_ctrl_nfc_get_handover_sel_p2p(
1096 wpa_s, reply, max_len, ndef, 1);
1098 #endif /* CONFIG_P2P */
1104 static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant *wpa_s,
1108 struct wpabuf *req, *sel;
1110 char *pos, *role, *type, *pos2;
1113 int forced_freq = 0;
1115 freq = strstr(cmd, " freq=");
1119 forced_freq = atoi(freq);
1121 #endif /* CONFIG_P2P */
1124 pos = os_strchr(role, ' ');
1126 wpa_printf(MSG_DEBUG, "NFC: Missing type in handover report");
1132 pos = os_strchr(type, ' ');
1134 wpa_printf(MSG_DEBUG, "NFC: Missing request message in handover report");
1139 pos2 = os_strchr(pos, ' ');
1141 wpa_printf(MSG_DEBUG, "NFC: Missing select message in handover report");
1146 len = os_strlen(pos);
1148 wpa_printf(MSG_DEBUG, "NFC: Invalid request message length in handover report");
1153 req = wpabuf_alloc(len);
1155 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for request message");
1158 if (hexstr2bin(pos, wpabuf_put(req, len), len) < 0) {
1159 wpa_printf(MSG_DEBUG, "NFC: Invalid request message hexdump in handover report");
1164 len = os_strlen(pos2);
1166 wpa_printf(MSG_DEBUG, "NFC: Invalid select message length in handover report");
1172 sel = wpabuf_alloc(len);
1174 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for select message");
1178 if (hexstr2bin(pos2, wpabuf_put(sel, len), len) < 0) {
1179 wpa_printf(MSG_DEBUG, "NFC: Invalid select message hexdump in handover report");
1185 wpa_printf(MSG_DEBUG, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d",
1186 role, type, (int) wpabuf_len(req), (int) wpabuf_len(sel));
1188 if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "WPS") == 0) {
1189 ret = wpas_wps_nfc_report_handover(wpa_s, req, sel);
1191 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "WPS") == 0)
1193 ret = wpas_ap_wps_nfc_report_handover(wpa_s, req, sel);
1195 ret = wpas_er_wps_nfc_report_handover(wpa_s, req, sel);
1196 #endif /* CONFIG_AP */
1198 } else if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "P2P") == 0)
1200 ret = wpas_p2p_nfc_report_handover(wpa_s, 1, req, sel, 0);
1201 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "P2P") == 0)
1203 ret = wpas_p2p_nfc_report_handover(wpa_s, 0, req, sel,
1205 #endif /* CONFIG_P2P */
1207 wpa_printf(MSG_DEBUG, "NFC: Unsupported connection handover "
1208 "reported: role=%s type=%s", role, type);
1215 wpa_printf(MSG_DEBUG, "NFC: Failed to process reported handover messages");
1220 #endif /* CONFIG_WPS_NFC */
1223 static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s,
1232 struct wps_new_ap_settings ap;
1234 pin = os_strchr(cmd, ' ');
1239 if (hwaddr_aton(cmd, bssid)) {
1240 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
1245 new_ssid = os_strchr(pin, ' ');
1246 if (new_ssid == NULL)
1247 return wpas_wps_start_reg(wpa_s, bssid, pin, NULL);
1250 new_auth = os_strchr(new_ssid, ' ');
1251 if (new_auth == NULL)
1255 new_encr = os_strchr(new_auth, ' ');
1256 if (new_encr == NULL)
1260 new_key = os_strchr(new_encr, ' ');
1261 if (new_key == NULL)
1265 os_memset(&ap, 0, sizeof(ap));
1266 ap.ssid_hex = new_ssid;
1269 ap.key_hex = new_key;
1270 return wpas_wps_start_reg(wpa_s, bssid, pin, &ap);
1275 static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant *wpa_s,
1276 char *cmd, char *buf,
1281 const char *pin_txt;
1283 if (!wpa_s->ap_iface)
1286 pos = os_strchr(cmd, ' ');
1290 if (os_strcmp(cmd, "disable") == 0) {
1291 wpas_wps_ap_pin_disable(wpa_s);
1292 return os_snprintf(buf, buflen, "OK\n");
1295 if (os_strcmp(cmd, "random") == 0) {
1297 timeout = atoi(pos);
1298 pin_txt = wpas_wps_ap_pin_random(wpa_s, timeout);
1299 if (pin_txt == NULL)
1301 return os_snprintf(buf, buflen, "%s", pin_txt);
1304 if (os_strcmp(cmd, "get") == 0) {
1305 pin_txt = wpas_wps_ap_pin_get(wpa_s);
1306 if (pin_txt == NULL)
1308 return os_snprintf(buf, buflen, "%s", pin_txt);
1311 if (os_strcmp(cmd, "set") == 0) {
1316 pos = os_strchr(pos, ' ');
1319 timeout = atoi(pos);
1321 if (os_strlen(pin) > buflen)
1323 if (wpas_wps_ap_pin_set(wpa_s, pin, timeout) < 0)
1325 return os_snprintf(buf, buflen, "%s", pin);
1330 #endif /* CONFIG_AP */
1333 #ifdef CONFIG_WPS_ER
1334 static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant *wpa_s,
1337 char *uuid = cmd, *pin, *pos;
1338 u8 addr_buf[ETH_ALEN], *addr = NULL;
1339 pin = os_strchr(uuid, ' ');
1343 pos = os_strchr(pin, ' ');
1346 if (hwaddr_aton(pos, addr_buf) == 0)
1349 return wpas_wps_er_add_pin(wpa_s, addr, uuid, pin);
1353 static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant *wpa_s,
1356 char *uuid = cmd, *pin;
1357 pin = os_strchr(uuid, ' ');
1361 return wpas_wps_er_learn(wpa_s, uuid, pin);
1365 static int wpa_supplicant_ctrl_iface_wps_er_set_config(
1366 struct wpa_supplicant *wpa_s, char *cmd)
1368 char *uuid = cmd, *id;
1369 id = os_strchr(uuid, ' ');
1373 return wpas_wps_er_set_config(wpa_s, uuid, atoi(id));
1377 static int wpa_supplicant_ctrl_iface_wps_er_config(
1378 struct wpa_supplicant *wpa_s, char *cmd)
1385 struct wps_new_ap_settings ap;
1387 pin = os_strchr(cmd, ' ');
1392 new_ssid = os_strchr(pin, ' ');
1393 if (new_ssid == NULL)
1397 new_auth = os_strchr(new_ssid, ' ');
1398 if (new_auth == NULL)
1402 new_encr = os_strchr(new_auth, ' ');
1403 if (new_encr == NULL)
1407 new_key = os_strchr(new_encr, ' ');
1408 if (new_key == NULL)
1412 os_memset(&ap, 0, sizeof(ap));
1413 ap.ssid_hex = new_ssid;
1416 ap.key_hex = new_key;
1417 return wpas_wps_er_config(wpa_s, cmd, pin, &ap);
1421 #ifdef CONFIG_WPS_NFC
1422 static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
1423 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1430 uuid = os_strchr(cmd, ' ');
1435 if (os_strcmp(cmd, "WPS") == 0)
1437 else if (os_strcmp(cmd, "NDEF") == 0)
1442 buf = wpas_wps_er_nfc_config_token(wpa_s, ndef, uuid);
1446 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1448 reply[res++] = '\n';
1455 #endif /* CONFIG_WPS_NFC */
1456 #endif /* CONFIG_WPS_ER */
1458 #endif /* CONFIG_WPS */
1461 #ifdef CONFIG_IBSS_RSN
1462 static int wpa_supplicant_ctrl_iface_ibss_rsn(
1463 struct wpa_supplicant *wpa_s, char *addr)
1467 if (hwaddr_aton(addr, peer)) {
1468 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN: invalid "
1469 "address '%s'", addr);
1473 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN " MACSTR,
1476 return ibss_rsn_start(wpa_s->ibss_rsn, peer);
1478 #endif /* CONFIG_IBSS_RSN */
1481 static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s,
1484 #ifdef IEEE8021X_EAPOL
1487 struct wpa_ssid *ssid;
1489 pos = os_strchr(rsp, '-');
1494 pos = os_strchr(pos, ':');
1499 wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id);
1500 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
1501 (u8 *) pos, os_strlen(pos));
1503 ssid = wpa_config_get_network(wpa_s->conf, id);
1505 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
1510 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s, ssid, rsp,
1512 #else /* IEEE8021X_EAPOL */
1513 wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included");
1515 #endif /* IEEE8021X_EAPOL */
1519 static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
1521 char *buf, size_t buflen)
1523 char *pos, *end, tmp[30];
1524 int res, verbose, wps, ret;
1527 #endif /* CONFIG_HS20 */
1529 if (os_strcmp(params, "-DRIVER") == 0)
1530 return wpa_drv_status(wpa_s, buf, buflen);
1531 verbose = os_strcmp(params, "-VERBOSE") == 0;
1532 wps = os_strcmp(params, "-WPS") == 0;
1535 if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
1536 struct wpa_ssid *ssid = wpa_s->current_ssid;
1537 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
1538 MAC2STR(wpa_s->bssid));
1539 if (ret < 0 || ret >= end - pos)
1543 u8 *_ssid = ssid->ssid;
1544 size_t ssid_len = ssid->ssid_len;
1545 u8 ssid_buf[MAX_SSID_LEN];
1546 if (ssid_len == 0) {
1547 int _res = wpa_drv_get_ssid(wpa_s, ssid_buf);
1554 ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n",
1555 wpa_ssid_txt(_ssid, ssid_len),
1557 if (ret < 0 || ret >= end - pos)
1561 if (wps && ssid->passphrase &&
1562 wpa_key_mgmt_wpa_psk(ssid->key_mgmt) &&
1563 (ssid->mode == WPAS_MODE_AP ||
1564 ssid->mode == WPAS_MODE_P2P_GO)) {
1565 ret = os_snprintf(pos, end - pos,
1568 if (ret < 0 || ret >= end - pos)
1573 ret = os_snprintf(pos, end - pos,
1576 if (ret < 0 || ret >= end - pos)
1581 switch (ssid->mode) {
1582 case WPAS_MODE_INFRA:
1583 ret = os_snprintf(pos, end - pos,
1586 case WPAS_MODE_IBSS:
1587 ret = os_snprintf(pos, end - pos,
1591 ret = os_snprintf(pos, end - pos,
1594 case WPAS_MODE_P2P_GO:
1595 ret = os_snprintf(pos, end - pos,
1598 case WPAS_MODE_P2P_GROUP_FORMATION:
1599 ret = os_snprintf(pos, end - pos,
1600 "mode=P2P GO - group "
1607 if (ret < 0 || ret >= end - pos)
1613 if (wpa_s->ap_iface) {
1614 pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos,
1618 #endif /* CONFIG_AP */
1619 pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose);
1622 if (wpa_s->wpa_state >= WPA_ASSOCIATED &&
1625 #endif /* CONFIG_AP */
1626 wpa_s->sme.sae.state == SAE_ACCEPTED) {
1627 ret = os_snprintf(pos, end - pos, "sae_group=%d\n",
1628 wpa_s->sme.sae.group);
1629 if (ret < 0 || ret >= end - pos)
1633 #endif /* CONFIG_SAE */
1634 ret = os_snprintf(pos, end - pos, "wpa_state=%s\n",
1635 wpa_supplicant_state_txt(wpa_s->wpa_state));
1636 if (ret < 0 || ret >= end - pos)
1641 l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) {
1642 ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp);
1643 if (ret < 0 || ret >= end - pos)
1649 if (wpa_s->global->p2p) {
1650 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
1651 "\n", MAC2STR(wpa_s->global->p2p_dev_addr));
1652 if (ret < 0 || ret >= end - pos)
1656 #endif /* CONFIG_P2P */
1658 ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n",
1659 MAC2STR(wpa_s->own_addr));
1660 if (ret < 0 || ret >= end - pos)
1665 if (wpa_s->current_bss &&
1666 (hs20 = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1667 HS20_IE_VENDOR_TYPE)) &&
1668 wpa_s->wpa_proto == WPA_PROTO_RSN &&
1669 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1672 u8 rel_num = (hs20[6] & 0xf0) >> 4;
1673 release = rel_num + 1;
1675 ret = os_snprintf(pos, end - pos, "hs20=%d\n", release);
1676 if (ret < 0 || ret >= end - pos)
1681 if (wpa_s->current_ssid) {
1682 struct wpa_cred *cred;
1685 for (cred = wpa_s->conf->cred; cred; cred = cred->next) {
1688 if (wpa_s->current_ssid->parent_cred != cred)
1691 if (cred->provisioning_sp) {
1692 ret = os_snprintf(pos, end - pos,
1693 "provisioning_sp=%s\n",
1694 cred->provisioning_sp);
1695 if (ret < 0 || ret >= end - pos)
1704 if (wpa_s->current_bss && wpa_s->current_bss->anqp) {
1705 struct wpabuf *names =
1706 wpa_s->current_bss->anqp->domain_name;
1707 for (i = 0; names && i < cred->num_domain; i++)
1709 if (domain_name_list_contains(
1710 names, cred->domain[i], 1))
1713 if (i == cred->num_domain)
1714 i = 0; /* show first entry by default */
1716 ret = os_snprintf(pos, end - pos, "home_sp=%s\n",
1718 if (ret < 0 || ret >= end - pos)
1723 if (wpa_s->current_bss == NULL ||
1724 wpa_s->current_bss->anqp == NULL)
1727 res = interworking_home_sp_cred(
1729 wpa_s->current_bss->anqp->domain_name);
1737 ret = os_snprintf(pos, end - pos, "sp_type=%s\n", type);
1738 if (ret < 0 || ret >= end - pos)
1745 #endif /* CONFIG_HS20 */
1747 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
1748 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
1749 res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos,
1755 res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose);
1762 uuid_bin2str(wpa_s->wps->uuid, uuid_str, sizeof(uuid_str));
1763 ret = os_snprintf(pos, end - pos, "uuid=%s\n", uuid_str);
1764 if (ret < 0 || ret >= end - pos)
1768 #endif /* CONFIG_WPS */
1772 * Allow using the STATUS command with default behavior, say for debug,
1773 * i.e., don't generate a "fake" CONNECTION and SUPPLICANT_STATE_CHANGE
1774 * events with STATUS-NO_EVENTS.
1776 if (os_strcmp(params, "-NO_EVENTS")) {
1777 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_STATE_CHANGE
1778 "id=%d state=%d BSSID=" MACSTR " SSID=%s",
1779 wpa_s->current_ssid ? wpa_s->current_ssid->id : -1,
1781 MAC2STR(wpa_s->bssid),
1782 wpa_s->current_ssid && wpa_s->current_ssid->ssid ?
1783 wpa_ssid_txt(wpa_s->current_ssid->ssid,
1784 wpa_s->current_ssid->ssid_len) : "");
1785 if (wpa_s->wpa_state == WPA_COMPLETED) {
1786 struct wpa_ssid *ssid = wpa_s->current_ssid;
1787 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_CONNECTED
1788 "- connection to " MACSTR
1789 " completed %s [id=%d id_str=%s]",
1790 MAC2STR(wpa_s->bssid), "(auth)",
1791 ssid ? ssid->id : -1,
1792 ssid && ssid->id_str ? ssid->id_str : "");
1795 #endif /* ANDROID */
1801 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s,
1806 struct wpa_ssid *ssid;
1809 /* cmd: "<network id> <BSSID>" */
1810 pos = os_strchr(cmd, ' ');
1815 wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos);
1816 if (hwaddr_aton(pos, bssid)) {
1817 wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos);
1821 ssid = wpa_config_get_network(wpa_s->conf, id);
1823 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
1828 os_memcpy(ssid->bssid, bssid, ETH_ALEN);
1829 ssid->bssid_set = !is_zero_ether_addr(bssid);
1835 static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant *wpa_s,
1836 char *cmd, char *buf,
1840 struct wpa_blacklist *e;
1844 /* cmd: "BLACKLIST [<BSSID>]" */
1848 e = wpa_s->blacklist;
1850 ret = os_snprintf(pos, end - pos, MACSTR "\n",
1852 if (ret < 0 || ret >= end - pos)
1861 if (os_strncmp(cmd, "clear", 5) == 0) {
1862 wpa_blacklist_clear(wpa_s);
1863 os_memcpy(buf, "OK\n", 3);
1867 wpa_printf(MSG_DEBUG, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd);
1868 if (hwaddr_aton(cmd, bssid)) {
1869 wpa_printf(MSG_DEBUG, "CTRL_IFACE: invalid BSSID '%s'", cmd);
1874 * Add the BSSID twice, so its count will be 2, causing it to be
1875 * skipped when processing scan results.
1877 ret = wpa_blacklist_add(wpa_s, bssid);
1880 ret = wpa_blacklist_add(wpa_s, bssid);
1883 os_memcpy(buf, "OK\n", 3);
1888 static const char * debug_level_str(int level)
1909 static int str_to_debug_level(const char *s)
1911 if (os_strcasecmp(s, "EXCESSIVE") == 0)
1912 return MSG_EXCESSIVE;
1913 if (os_strcasecmp(s, "MSGDUMP") == 0)
1915 if (os_strcasecmp(s, "DEBUG") == 0)
1917 if (os_strcasecmp(s, "INFO") == 0)
1919 if (os_strcasecmp(s, "WARNING") == 0)
1921 if (os_strcasecmp(s, "ERROR") == 0)
1927 static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant *wpa_s,
1928 char *cmd, char *buf,
1931 char *pos, *end, *stamp;
1938 /* cmd: "LOG_LEVEL [<level>]" */
1942 ret = os_snprintf(pos, end - pos, "Current level: %s\n"
1944 debug_level_str(wpa_debug_level),
1945 wpa_debug_timestamp);
1946 if (ret < 0 || ret >= end - pos)
1955 stamp = os_strchr(cmd, ' ');
1958 while (*stamp == ' ') {
1963 if (cmd && os_strlen(cmd)) {
1964 int level = str_to_debug_level(cmd);
1967 wpa_debug_level = level;
1970 if (stamp && os_strlen(stamp))
1971 wpa_debug_timestamp = atoi(stamp);
1973 os_memcpy(buf, "OK\n", 3);
1978 static int wpa_supplicant_ctrl_iface_list_networks(
1979 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
1982 struct wpa_ssid *ssid;
1987 ret = os_snprintf(pos, end - pos,
1988 "network id / ssid / bssid / flags\n");
1989 if (ret < 0 || ret >= end - pos)
1993 ssid = wpa_s->conf->ssid;
1995 ret = os_snprintf(pos, end - pos, "%d\t%s",
1997 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
1998 if (ret < 0 || ret >= end - pos)
2001 if (ssid->bssid_set) {
2002 ret = os_snprintf(pos, end - pos, "\t" MACSTR,
2003 MAC2STR(ssid->bssid));
2005 ret = os_snprintf(pos, end - pos, "\tany");
2007 if (ret < 0 || ret >= end - pos)
2010 ret = os_snprintf(pos, end - pos, "\t%s%s%s%s",
2011 ssid == wpa_s->current_ssid ?
2013 ssid->disabled ? "[DISABLED]" : "",
2014 ssid->disabled_until.sec ?
2015 "[TEMP-DISABLED]" : "",
2016 ssid->disabled == 2 ? "[P2P-PERSISTENT]" :
2018 if (ret < 0 || ret >= end - pos)
2021 ret = os_snprintf(pos, end - pos, "\n");
2022 if (ret < 0 || ret >= end - pos)
2033 static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher)
2036 ret = os_snprintf(pos, end - pos, "-");
2037 if (ret < 0 || ret >= end - pos)
2040 ret = wpa_write_ciphers(pos, end, cipher, "+");
2048 static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
2049 const u8 *ie, size_t ie_len)
2051 struct wpa_ie_data data;
2055 ret = os_snprintf(pos, end - pos, "[%s-", proto);
2056 if (ret < 0 || ret >= end - pos)
2060 if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) {
2061 ret = os_snprintf(pos, end - pos, "?]");
2062 if (ret < 0 || ret >= end - pos)
2069 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
2070 ret = os_snprintf(pos, end - pos, "%sEAP",
2071 pos == start ? "" : "+");
2072 if (ret < 0 || ret >= end - pos)
2076 if (data.key_mgmt & WPA_KEY_MGMT_PSK) {
2077 ret = os_snprintf(pos, end - pos, "%sPSK",
2078 pos == start ? "" : "+");
2079 if (ret < 0 || ret >= end - pos)
2083 if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
2084 ret = os_snprintf(pos, end - pos, "%sNone",
2085 pos == start ? "" : "+");
2086 if (ret < 0 || ret >= end - pos)
2090 #ifdef CONFIG_IEEE80211R
2091 if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
2092 ret = os_snprintf(pos, end - pos, "%sFT/EAP",
2093 pos == start ? "" : "+");
2094 if (ret < 0 || ret >= end - pos)
2098 if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) {
2099 ret = os_snprintf(pos, end - pos, "%sFT/PSK",
2100 pos == start ? "" : "+");
2101 if (ret < 0 || ret >= end - pos)
2105 #endif /* CONFIG_IEEE80211R */
2106 #ifdef CONFIG_IEEE80211W
2107 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
2108 ret = os_snprintf(pos, end - pos, "%sEAP-SHA256",
2109 pos == start ? "" : "+");
2110 if (ret < 0 || ret >= end - pos)
2114 if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
2115 ret = os_snprintf(pos, end - pos, "%sPSK-SHA256",
2116 pos == start ? "" : "+");
2117 if (ret < 0 || ret >= end - pos)
2121 #endif /* CONFIG_IEEE80211W */
2123 pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher);
2125 if (data.capabilities & WPA_CAPABILITY_PREAUTH) {
2126 ret = os_snprintf(pos, end - pos, "-preauth");
2127 if (ret < 0 || ret >= end - pos)
2132 ret = os_snprintf(pos, end - pos, "]");
2133 if (ret < 0 || ret >= end - pos)
2142 static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s,
2143 char *pos, char *end,
2144 struct wpabuf *wps_ie)
2151 if (wps_is_selected_pbc_registrar(wps_ie))
2153 else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0))
2155 else if (wps_is_selected_pin_registrar(wps_ie))
2160 ret = os_snprintf(pos, end - pos, "%s", txt);
2161 if (ret >= 0 && ret < end - pos)
2163 wpabuf_free(wps_ie);
2166 #endif /* CONFIG_WPS */
2169 static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s,
2170 char *pos, char *end,
2171 const struct wpa_bss *bss)
2174 struct wpabuf *wps_ie;
2175 wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
2176 return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie);
2177 #else /* CONFIG_WPS */
2179 #endif /* CONFIG_WPS */
2183 /* Format one result on one text line into a buffer. */
2184 static int wpa_supplicant_ctrl_iface_scan_result(
2185 struct wpa_supplicant *wpa_s,
2186 const struct wpa_bss *bss, char *buf, size_t buflen)
2190 const u8 *ie, *ie2, *p2p;
2192 p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
2194 p2p = wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE);
2195 if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN &&
2196 os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) ==
2198 return 0; /* Do not show P2P listen discovery results here */
2203 ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t",
2204 MAC2STR(bss->bssid), bss->freq, bss->level);
2205 if (ret < 0 || ret >= end - pos)
2208 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
2210 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]);
2211 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
2213 pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2, 2 + ie2[1]);
2214 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
2215 if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
2216 ret = os_snprintf(pos, end - pos, "[WEP]");
2217 if (ret < 0 || ret >= end - pos)
2221 if (bss_is_dmg(bss)) {
2223 ret = os_snprintf(pos, end - pos, "[DMG]");
2224 if (ret < 0 || ret >= end - pos)
2227 switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
2228 case IEEE80211_CAP_DMG_IBSS:
2231 case IEEE80211_CAP_DMG_AP:
2234 case IEEE80211_CAP_DMG_PBSS:
2241 ret = os_snprintf(pos, end - pos, "%s", s);
2242 if (ret < 0 || ret >= end - pos)
2246 if (bss->caps & IEEE80211_CAP_IBSS) {
2247 ret = os_snprintf(pos, end - pos, "[IBSS]");
2248 if (ret < 0 || ret >= end - pos)
2252 if (bss->caps & IEEE80211_CAP_ESS) {
2253 ret = os_snprintf(pos, end - pos, "[ESS]");
2254 if (ret < 0 || ret >= end - pos)
2260 ret = os_snprintf(pos, end - pos, "[P2P]");
2261 if (ret < 0 || ret >= end - pos)
2266 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE) && ie2) {
2267 ret = os_snprintf(pos, end - pos, "[HS20]");
2268 if (ret < 0 || ret >= end - pos)
2272 #endif /* CONFIG_HS20 */
2274 ret = os_snprintf(pos, end - pos, "\t%s",
2275 wpa_ssid_txt(bss->ssid, bss->ssid_len));
2276 if (ret < 0 || ret >= end - pos)
2280 ret = os_snprintf(pos, end - pos, "\n");
2281 if (ret < 0 || ret >= end - pos)
2289 static int wpa_supplicant_ctrl_iface_scan_results(
2290 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
2293 struct wpa_bss *bss;
2298 ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / "
2300 if (ret < 0 || ret >= end - pos)
2304 dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
2305 ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos,
2307 if (ret < 0 || ret >= end - pos)
2316 static int wpa_supplicant_ctrl_iface_select_network(
2317 struct wpa_supplicant *wpa_s, char *cmd)
2320 struct wpa_ssid *ssid;
2323 /* cmd: "<network id>" or "any" */
2324 if (os_strncmp(cmd, "any", 3) == 0) {
2325 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any");
2329 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id);
2331 ssid = wpa_config_get_network(wpa_s->conf, id);
2333 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2334 "network id=%d", id);
2337 if (ssid->disabled == 2) {
2338 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2339 "SELECT_NETWORK with persistent P2P group");
2344 pos = os_strstr(cmd, " freq=");
2346 int *freqs = freq_range_to_channel_list(wpa_s, pos + 6);
2348 wpa_s->scan_req = MANUAL_SCAN_REQ;
2349 os_free(wpa_s->manual_scan_freqs);
2350 wpa_s->manual_scan_freqs = freqs;
2354 wpa_supplicant_select_network(wpa_s, ssid);
2360 static int wpa_supplicant_ctrl_iface_enable_network(
2361 struct wpa_supplicant *wpa_s, char *cmd)
2364 struct wpa_ssid *ssid;
2366 /* cmd: "<network id>" or "all" */
2367 if (os_strcmp(cmd, "all") == 0) {
2368 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all");
2372 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id);
2374 ssid = wpa_config_get_network(wpa_s->conf, id);
2376 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2377 "network id=%d", id);
2380 if (ssid->disabled == 2) {
2381 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2382 "ENABLE_NETWORK with persistent P2P group");
2386 if (os_strstr(cmd, " no-connect")) {
2391 wpa_supplicant_enable_network(wpa_s, ssid);
2397 static int wpa_supplicant_ctrl_iface_disable_network(
2398 struct wpa_supplicant *wpa_s, char *cmd)
2401 struct wpa_ssid *ssid;
2403 /* cmd: "<network id>" or "all" */
2404 if (os_strcmp(cmd, "all") == 0) {
2405 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all");
2409 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id);
2411 ssid = wpa_config_get_network(wpa_s->conf, id);
2413 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2414 "network id=%d", id);
2417 if (ssid->disabled == 2) {
2418 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2419 "DISABLE_NETWORK with persistent P2P "
2424 wpa_supplicant_disable_network(wpa_s, ssid);
2430 static int wpa_supplicant_ctrl_iface_add_network(
2431 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
2433 struct wpa_ssid *ssid;
2436 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK");
2438 ssid = wpa_config_add_network(wpa_s->conf);
2442 wpas_notify_network_added(wpa_s, ssid);
2445 wpa_config_set_network_defaults(ssid);
2447 ret = os_snprintf(buf, buflen, "%d\n", ssid->id);
2448 if (ret < 0 || (size_t) ret >= buflen)
2454 static int wpa_supplicant_ctrl_iface_remove_network(
2455 struct wpa_supplicant *wpa_s, char *cmd)
2458 struct wpa_ssid *ssid;
2461 /* cmd: "<network id>" or "all" */
2462 if (os_strcmp(cmd, "all") == 0) {
2463 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all");
2464 if (wpa_s->sched_scanning)
2465 wpa_supplicant_cancel_sched_scan(wpa_s);
2467 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2468 if (wpa_s->current_ssid) {
2470 wpa_s->sme.prev_bssid_set = 0;
2471 #endif /* CONFIG_SME */
2472 wpa_sm_set_config(wpa_s->wpa, NULL);
2473 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
2474 wpa_supplicant_deauthenticate(
2475 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2477 ssid = wpa_s->conf->ssid;
2479 struct wpa_ssid *remove_ssid = ssid;
2482 wpas_notify_network_removed(wpa_s, remove_ssid);
2483 wpa_config_remove_network(wpa_s->conf, id);
2489 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id);
2491 ssid = wpa_config_get_network(wpa_s->conf, id);
2493 wpas_notify_network_removed(wpa_s, ssid);
2495 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2500 if (ssid == wpa_s->current_ssid || wpa_s->current_ssid == NULL) {
2502 wpa_s->sme.prev_bssid_set = 0;
2503 #endif /* CONFIG_SME */
2505 * Invalidate the EAP session cache if the current or
2506 * previously used network is removed.
2508 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2511 if (ssid == wpa_s->current_ssid) {
2512 wpa_sm_set_config(wpa_s->wpa, NULL);
2513 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
2515 wpa_supplicant_deauthenticate(wpa_s,
2516 WLAN_REASON_DEAUTH_LEAVING);
2519 was_disabled = ssid->disabled;
2521 if (wpa_config_remove_network(wpa_s->conf, id) < 0) {
2522 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Not able to remove the "
2523 "network id=%d", id);
2527 if (!was_disabled && wpa_s->sched_scanning) {
2528 wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to remove "
2529 "network from filters");
2530 wpa_supplicant_cancel_sched_scan(wpa_s);
2531 wpa_supplicant_req_scan(wpa_s, 0, 0);
2538 static int wpa_supplicant_ctrl_iface_update_network(
2539 struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
2540 char *name, char *value)
2542 if (wpa_config_set(ssid, name, value, 0) < 0) {
2543 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network "
2544 "variable '%s'", name);
2548 if (os_strcmp(name, "bssid") != 0 &&
2549 os_strcmp(name, "priority") != 0)
2550 wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
2552 if (wpa_s->current_ssid == ssid || wpa_s->current_ssid == NULL) {
2554 * Invalidate the EAP session cache if anything in the current
2555 * or previously used configuration changes.
2557 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2560 if ((os_strcmp(name, "psk") == 0 &&
2561 value[0] == '"' && ssid->ssid_len) ||
2562 (os_strcmp(name, "ssid") == 0 && ssid->passphrase))
2563 wpa_config_update_psk(ssid);
2564 else if (os_strcmp(name, "priority") == 0)
2565 wpa_config_update_prio_list(wpa_s->conf);
2571 static int wpa_supplicant_ctrl_iface_set_network(
2572 struct wpa_supplicant *wpa_s, char *cmd)
2574 int id, ret, prev_bssid_set;
2575 struct wpa_ssid *ssid;
2577 u8 prev_bssid[ETH_ALEN];
2579 /* cmd: "<network id> <variable name> <value>" */
2580 name = os_strchr(cmd, ' ');
2585 value = os_strchr(name, ' ');
2591 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
2593 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
2594 (u8 *) value, os_strlen(value));
2596 ssid = wpa_config_get_network(wpa_s->conf, id);
2598 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2603 prev_bssid_set = ssid->bssid_set;
2604 os_memcpy(prev_bssid, ssid->bssid, ETH_ALEN);
2605 ret = wpa_supplicant_ctrl_iface_update_network(wpa_s, ssid, name,
2608 (ssid->bssid_set != prev_bssid_set ||
2609 os_memcmp(ssid->bssid, prev_bssid, ETH_ALEN) != 0))
2610 wpas_notify_network_bssid_set_changed(wpa_s, ssid);
2615 static int wpa_supplicant_ctrl_iface_get_network(
2616 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
2620 struct wpa_ssid *ssid;
2623 /* cmd: "<network id> <variable name>" */
2624 name = os_strchr(cmd, ' ');
2625 if (name == NULL || buflen == 0)
2630 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
2633 ssid = wpa_config_get_network(wpa_s->conf, id);
2635 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2640 value = wpa_config_get_no_key(ssid, name);
2641 if (value == NULL) {
2642 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
2643 "variable '%s'", name);
2647 res = os_strlcpy(buf, value, buflen);
2648 if (res >= buflen) {
2659 static int wpa_supplicant_ctrl_iface_dup_network(
2660 struct wpa_supplicant *wpa_s, char *cmd)
2662 struct wpa_ssid *ssid_s, *ssid_d;
2663 char *name, *id, *value;
2664 int id_s, id_d, ret;
2666 /* cmd: "<src network id> <dst network id> <variable name>" */
2667 id = os_strchr(cmd, ' ');
2672 name = os_strchr(id, ' ');
2679 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DUP_NETWORK id=%d -> %d name='%s'",
2682 ssid_s = wpa_config_get_network(wpa_s->conf, id_s);
2683 if (ssid_s == NULL) {
2684 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2685 "network id=%d", id_s);
2689 ssid_d = wpa_config_get_network(wpa_s->conf, id_d);
2690 if (ssid_d == NULL) {
2691 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2692 "network id=%d", id_s);
2696 value = wpa_config_get(ssid_s, name);
2697 if (value == NULL) {
2698 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
2699 "variable '%s'", name);
2703 ret = wpa_supplicant_ctrl_iface_update_network(wpa_s, ssid_d, name,
2712 static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant *wpa_s,
2713 char *buf, size_t buflen)
2716 struct wpa_cred *cred;
2721 ret = os_snprintf(pos, end - pos,
2722 "cred id / realm / username / domain / imsi\n");
2723 if (ret < 0 || ret >= end - pos)
2727 cred = wpa_s->conf->cred;
2729 ret = os_snprintf(pos, end - pos, "%d\t%s\t%s\t%s\t%s\n",
2730 cred->id, cred->realm ? cred->realm : "",
2731 cred->username ? cred->username : "",
2732 cred->domain ? cred->domain[0] : "",
2733 cred->imsi ? cred->imsi : "");
2734 if (ret < 0 || ret >= end - pos)
2745 static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant *wpa_s,
2746 char *buf, size_t buflen)
2748 struct wpa_cred *cred;
2751 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_CRED");
2753 cred = wpa_config_add_cred(wpa_s->conf);
2757 wpa_msg(wpa_s, MSG_INFO, CRED_ADDED "%d", cred->id);
2759 ret = os_snprintf(buf, buflen, "%d\n", cred->id);
2760 if (ret < 0 || (size_t) ret >= buflen)
2766 static int wpas_ctrl_remove_cred(struct wpa_supplicant *wpa_s,
2767 struct wpa_cred *cred)
2769 struct wpa_ssid *ssid;
2774 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred");
2779 if (wpa_config_remove_cred(wpa_s->conf, id) < 0) {
2780 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred");
2784 wpa_msg(wpa_s, MSG_INFO, CRED_REMOVED "%d", id);
2786 /* Remove any network entry created based on the removed credential */
2787 ssid = wpa_s->conf->ssid;
2789 if (ssid->parent_cred == cred) {
2790 wpa_printf(MSG_DEBUG, "Remove network id %d since it "
2791 "used the removed credential", ssid->id);
2792 os_snprintf(str, sizeof(str), "%d", ssid->id);
2794 wpa_supplicant_ctrl_iface_remove_network(wpa_s, str);
2803 static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s,
2807 struct wpa_cred *cred, *prev;
2809 /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or
2810 * "provisioning_sp=<FQDN> */
2811 if (os_strcmp(cmd, "all") == 0) {
2812 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED all");
2813 cred = wpa_s->conf->cred;
2817 wpas_ctrl_remove_cred(wpa_s, prev);
2822 if (os_strncmp(cmd, "sp_fqdn=", 8) == 0) {
2823 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
2825 cred = wpa_s->conf->cred;
2831 for (i = 0; i < prev->num_domain; i++) {
2832 if (os_strcmp(prev->domain[i], cmd + 8)
2835 wpas_ctrl_remove_cred(wpa_s, prev);
2843 if (os_strncmp(cmd, "provisioning_sp=", 16) == 0) {
2844 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'",
2846 cred = wpa_s->conf->cred;
2850 if (prev->provisioning_sp &&
2851 os_strcmp(prev->provisioning_sp, cmd + 16) == 0)
2852 wpas_ctrl_remove_cred(wpa_s, prev);
2858 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED id=%d", id);
2860 cred = wpa_config_get_cred(wpa_s->conf, id);
2861 return wpas_ctrl_remove_cred(wpa_s, cred);
2865 static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant *wpa_s,
2869 struct wpa_cred *cred;
2872 /* cmd: "<cred id> <variable name> <value>" */
2873 name = os_strchr(cmd, ' ');
2878 value = os_strchr(name, ' ');
2884 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_CRED id=%d name='%s'",
2886 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
2887 (u8 *) value, os_strlen(value));
2889 cred = wpa_config_get_cred(wpa_s->conf, id);
2891 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
2896 if (wpa_config_set_cred(cred, name, value, 0) < 0) {
2897 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set cred "
2898 "variable '%s'", name);
2902 wpa_msg(wpa_s, MSG_INFO, CRED_MODIFIED "%d %s", cred->id, name);
2908 static int wpa_supplicant_ctrl_iface_get_cred(struct wpa_supplicant *wpa_s,
2909 char *cmd, char *buf,
2914 struct wpa_cred *cred;
2917 /* cmd: "<cred id> <variable name>" */
2918 name = os_strchr(cmd, ' ');
2924 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CRED id=%d name='%s'",
2927 cred = wpa_config_get_cred(wpa_s->conf, id);
2929 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
2934 value = wpa_config_get_cred_no_key(cred, name);
2935 if (value == NULL) {
2936 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get cred variable '%s'",
2941 res = os_strlcpy(buf, value, buflen);
2942 if (res >= buflen) {
2953 #ifndef CONFIG_NO_CONFIG_WRITE
2954 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s)
2958 if (!wpa_s->conf->update_config) {
2959 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
2960 "to update configuration (update_config=0)");
2964 ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
2966 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to "
2967 "update configuration");
2969 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration"
2975 #endif /* CONFIG_NO_CONFIG_WRITE */
2978 struct cipher_info {
2984 static const struct cipher_info ciphers[] = {
2985 { WPA_DRIVER_CAPA_ENC_CCMP_256, "CCMP-256", 0 },
2986 { WPA_DRIVER_CAPA_ENC_GCMP_256, "GCMP-256", 0 },
2987 { WPA_DRIVER_CAPA_ENC_CCMP, "CCMP", 0 },
2988 { WPA_DRIVER_CAPA_ENC_GCMP, "GCMP", 0 },
2989 { WPA_DRIVER_CAPA_ENC_TKIP, "TKIP", 0 },
2990 { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE, "NONE", 0 },
2991 { WPA_DRIVER_CAPA_ENC_WEP104, "WEP104", 1 },
2992 { WPA_DRIVER_CAPA_ENC_WEP40, "WEP40", 1 }
2996 static int ctrl_iface_get_capability_pairwise(int res, char *strict,
2997 struct wpa_driver_capa *capa,
2998 char *buf, size_t buflen)
3011 len = os_strlcpy(buf, "CCMP TKIP NONE", buflen);
3017 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
3018 if (!ciphers[i].group_only && capa->enc & ciphers[i].capa) {
3019 ret = os_snprintf(pos, end - pos, "%s%s",
3020 pos == buf ? "" : " ",
3022 if (ret < 0 || ret >= end - pos)
3032 static int ctrl_iface_get_capability_group(int res, char *strict,
3033 struct wpa_driver_capa *capa,
3034 char *buf, size_t buflen)
3047 len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen);
3053 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
3054 if (capa->enc & ciphers[i].capa) {
3055 ret = os_snprintf(pos, end - pos, "%s%s",
3056 pos == buf ? "" : " ",
3058 if (ret < 0 || ret >= end - pos)
3068 static int ctrl_iface_get_capability_key_mgmt(int res, char *strict,
3069 struct wpa_driver_capa *capa,
3070 char *buf, size_t buflen)
3082 len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
3089 ret = os_snprintf(pos, end - pos, "NONE IEEE8021X");
3090 if (ret < 0 || ret >= end - pos)
3094 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
3095 WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
3096 ret = os_snprintf(pos, end - pos, " WPA-EAP");
3097 if (ret < 0 || ret >= end - pos)
3102 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
3103 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
3104 ret = os_snprintf(pos, end - pos, " WPA-PSK");
3105 if (ret < 0 || ret >= end - pos)
3110 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
3111 ret = os_snprintf(pos, end - pos, " WPA-NONE");
3112 if (ret < 0 || ret >= end - pos)
3121 static int ctrl_iface_get_capability_proto(int res, char *strict,
3122 struct wpa_driver_capa *capa,
3123 char *buf, size_t buflen)
3135 len = os_strlcpy(buf, "RSN WPA", buflen);
3141 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
3142 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
3143 ret = os_snprintf(pos, end - pos, "%sRSN",
3144 pos == buf ? "" : " ");
3145 if (ret < 0 || ret >= end - pos)
3150 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
3151 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
3152 ret = os_snprintf(pos, end - pos, "%sWPA",
3153 pos == buf ? "" : " ");
3154 if (ret < 0 || ret >= end - pos)
3163 static int ctrl_iface_get_capability_auth_alg(int res, char *strict,
3164 struct wpa_driver_capa *capa,
3165 char *buf, size_t buflen)
3177 len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen);
3183 if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) {
3184 ret = os_snprintf(pos, end - pos, "%sOPEN",
3185 pos == buf ? "" : " ");
3186 if (ret < 0 || ret >= end - pos)
3191 if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) {
3192 ret = os_snprintf(pos, end - pos, "%sSHARED",
3193 pos == buf ? "" : " ");
3194 if (ret < 0 || ret >= end - pos)
3199 if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) {
3200 ret = os_snprintf(pos, end - pos, "%sLEAP",
3201 pos == buf ? "" : " ");
3202 if (ret < 0 || ret >= end - pos)
3211 static int ctrl_iface_get_capability_modes(int res, char *strict,
3212 struct wpa_driver_capa *capa,
3213 char *buf, size_t buflen)
3225 len = os_strlcpy(buf, "IBSS AP", buflen);
3231 if (capa->flags & WPA_DRIVER_FLAGS_IBSS) {
3232 ret = os_snprintf(pos, end - pos, "%sIBSS",
3233 pos == buf ? "" : " ");
3234 if (ret < 0 || ret >= end - pos)
3239 if (capa->flags & WPA_DRIVER_FLAGS_AP) {
3240 ret = os_snprintf(pos, end - pos, "%sAP",
3241 pos == buf ? "" : " ");
3242 if (ret < 0 || ret >= end - pos)
3251 static int ctrl_iface_get_capability_channels(struct wpa_supplicant *wpa_s,
3252 char *buf, size_t buflen)
3254 struct hostapd_channel_data *chnl;
3256 char *pos, *end, *hmode;
3261 for (j = 0; j < wpa_s->hw.num_modes; j++) {
3262 switch (wpa_s->hw.modes[j].mode) {
3263 case HOSTAPD_MODE_IEEE80211B:
3266 case HOSTAPD_MODE_IEEE80211G:
3269 case HOSTAPD_MODE_IEEE80211A:
3272 case HOSTAPD_MODE_IEEE80211AD:
3278 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:", hmode);
3279 if (ret < 0 || ret >= end - pos)
3282 chnl = wpa_s->hw.modes[j].channels;
3283 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
3284 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
3286 ret = os_snprintf(pos, end - pos, " %d", chnl[i].chan);
3287 if (ret < 0 || ret >= end - pos)
3291 ret = os_snprintf(pos, end - pos, "\n");
3292 if (ret < 0 || ret >= end - pos)
3301 static int ctrl_iface_get_capability_freq(struct wpa_supplicant *wpa_s,
3302 char *buf, size_t buflen)
3304 struct hostapd_channel_data *chnl;
3306 char *pos, *end, *hmode;
3311 for (j = 0; j < wpa_s->hw.num_modes; j++) {
3312 switch (wpa_s->hw.modes[j].mode) {
3313 case HOSTAPD_MODE_IEEE80211B:
3316 case HOSTAPD_MODE_IEEE80211G:
3319 case HOSTAPD_MODE_IEEE80211A:
3322 case HOSTAPD_MODE_IEEE80211AD:
3328 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:\n",
3330 if (ret < 0 || ret >= end - pos)
3333 chnl = wpa_s->hw.modes[j].channels;
3334 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
3335 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
3337 ret = os_snprintf(pos, end - pos, " %d = %d MHz%s%s\n",
3338 chnl[i].chan, chnl[i].freq,
3339 chnl[i].flag & HOSTAPD_CHAN_NO_IBSS ?
3341 chnl[i].flag & HOSTAPD_CHAN_RADAR ?
3344 if (ret < 0 || ret >= end - pos)
3348 ret = os_snprintf(pos, end - pos, "\n");
3349 if (ret < 0 || ret >= end - pos)
3358 static int wpa_supplicant_ctrl_iface_get_capability(
3359 struct wpa_supplicant *wpa_s, const char *_field, char *buf,
3362 struct wpa_driver_capa capa;
3368 /* Determine whether or not strict checking was requested */
3369 len = os_strlcpy(field, _field, sizeof(field));
3370 if (len >= sizeof(field))
3372 strict = os_strchr(field, ' ');
3373 if (strict != NULL) {
3375 if (os_strcmp(strict, "strict") != 0)
3379 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
3380 field, strict ? strict : "");
3382 if (os_strcmp(field, "eap") == 0) {
3383 return eap_get_names(buf, buflen);
3386 res = wpa_drv_get_capa(wpa_s, &capa);
3388 if (os_strcmp(field, "pairwise") == 0)
3389 return ctrl_iface_get_capability_pairwise(res, strict, &capa,
3392 if (os_strcmp(field, "group") == 0)
3393 return ctrl_iface_get_capability_group(res, strict, &capa,
3396 if (os_strcmp(field, "key_mgmt") == 0)
3397 return ctrl_iface_get_capability_key_mgmt(res, strict, &capa,
3400 if (os_strcmp(field, "proto") == 0)
3401 return ctrl_iface_get_capability_proto(res, strict, &capa,
3404 if (os_strcmp(field, "auth_alg") == 0)
3405 return ctrl_iface_get_capability_auth_alg(res, strict, &capa,
3408 if (os_strcmp(field, "modes") == 0)
3409 return ctrl_iface_get_capability_modes(res, strict, &capa,
3412 if (os_strcmp(field, "channels") == 0)
3413 return ctrl_iface_get_capability_channels(wpa_s, buf, buflen);
3415 if (os_strcmp(field, "freq") == 0)
3416 return ctrl_iface_get_capability_freq(wpa_s, buf, buflen);
3419 if (os_strcmp(field, "tdls") == 0)
3420 return ctrl_iface_get_capability_tdls(wpa_s, buf, buflen);
3421 #endif /* CONFIG_TDLS */
3423 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
3430 #ifdef CONFIG_INTERWORKING
3431 static char * anqp_add_hex(char *pos, char *end, const char *title,
3432 struct wpabuf *data)
3442 ret = os_snprintf(pos, end - pos, "%s=", title);
3443 if (ret < 0 || ret >= end - pos)
3447 d = wpabuf_head_u8(data);
3448 for (i = 0; i < wpabuf_len(data); i++) {
3449 ret = os_snprintf(pos, end - pos, "%02x", *d++);
3450 if (ret < 0 || ret >= end - pos)
3455 ret = os_snprintf(pos, end - pos, "\n");
3456 if (ret < 0 || ret >= end - pos)
3462 #endif /* CONFIG_INTERWORKING */
3465 static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
3466 unsigned long mask, char *buf, size_t buflen)
3476 if (mask & WPA_BSS_MASK_ID) {
3477 ret = os_snprintf(pos, end - pos, "id=%u\n", bss->id);
3478 if (ret < 0 || ret >= end - pos)
3483 if (mask & WPA_BSS_MASK_BSSID) {
3484 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
3485 MAC2STR(bss->bssid));
3486 if (ret < 0 || ret >= end - pos)
3491 if (mask & WPA_BSS_MASK_FREQ) {
3492 ret = os_snprintf(pos, end - pos, "freq=%d\n", bss->freq);
3493 if (ret < 0 || ret >= end - pos)
3498 if (mask & WPA_BSS_MASK_BEACON_INT) {
3499 ret = os_snprintf(pos, end - pos, "beacon_int=%d\n",
3501 if (ret < 0 || ret >= end - pos)
3506 if (mask & WPA_BSS_MASK_CAPABILITIES) {
3507 ret = os_snprintf(pos, end - pos, "capabilities=0x%04x\n",
3509 if (ret < 0 || ret >= end - pos)
3514 if (mask & WPA_BSS_MASK_QUAL) {
3515 ret = os_snprintf(pos, end - pos, "qual=%d\n", bss->qual);
3516 if (ret < 0 || ret >= end - pos)
3521 if (mask & WPA_BSS_MASK_NOISE) {
3522 ret = os_snprintf(pos, end - pos, "noise=%d\n", bss->noise);
3523 if (ret < 0 || ret >= end - pos)
3528 if (mask & WPA_BSS_MASK_LEVEL) {
3529 ret = os_snprintf(pos, end - pos, "level=%d\n", bss->level);
3530 if (ret < 0 || ret >= end - pos)
3535 if (mask & WPA_BSS_MASK_TSF) {
3536 ret = os_snprintf(pos, end - pos, "tsf=%016llu\n",
3537 (unsigned long long) bss->tsf);
3538 if (ret < 0 || ret >= end - pos)
3543 if (mask & WPA_BSS_MASK_AGE) {
3544 struct os_reltime now;
3546 os_get_reltime(&now);
3547 ret = os_snprintf(pos, end - pos, "age=%d\n",
3548 (int) (now.sec - bss->last_update.sec));
3549 if (ret < 0 || ret >= end - pos)
3554 if (mask & WPA_BSS_MASK_IE) {
3555 ret = os_snprintf(pos, end - pos, "ie=");
3556 if (ret < 0 || ret >= end - pos)
3560 ie = (const u8 *) (bss + 1);
3561 for (i = 0; i < bss->ie_len; i++) {
3562 ret = os_snprintf(pos, end - pos, "%02x", *ie++);
3563 if (ret < 0 || ret >= end - pos)
3568 ret = os_snprintf(pos, end - pos, "\n");
3569 if (ret < 0 || ret >= end - pos)
3574 if (mask & WPA_BSS_MASK_FLAGS) {
3575 ret = os_snprintf(pos, end - pos, "flags=");
3576 if (ret < 0 || ret >= end - pos)
3580 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
3582 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie,
3584 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
3586 pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2,
3588 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
3589 if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
3590 ret = os_snprintf(pos, end - pos, "[WEP]");
3591 if (ret < 0 || ret >= end - pos)
3595 if (bss_is_dmg(bss)) {
3597 ret = os_snprintf(pos, end - pos, "[DMG]");
3598 if (ret < 0 || ret >= end - pos)
3601 switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
3602 case IEEE80211_CAP_DMG_IBSS:
3605 case IEEE80211_CAP_DMG_AP:
3608 case IEEE80211_CAP_DMG_PBSS:
3615 ret = os_snprintf(pos, end - pos, "%s", s);
3616 if (ret < 0 || ret >= end - pos)
3620 if (bss->caps & IEEE80211_CAP_IBSS) {
3621 ret = os_snprintf(pos, end - pos, "[IBSS]");
3622 if (ret < 0 || ret >= end - pos)
3626 if (bss->caps & IEEE80211_CAP_ESS) {
3627 ret = os_snprintf(pos, end - pos, "[ESS]");
3628 if (ret < 0 || ret >= end - pos)
3633 if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
3634 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
3635 ret = os_snprintf(pos, end - pos, "[P2P]");
3636 if (ret < 0 || ret >= end - pos)
3641 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) {
3642 ret = os_snprintf(pos, end - pos, "[HS20]");
3643 if (ret < 0 || ret >= end - pos)
3647 #endif /* CONFIG_HS20 */
3649 ret = os_snprintf(pos, end - pos, "\n");
3650 if (ret < 0 || ret >= end - pos)
3655 if (mask & WPA_BSS_MASK_SSID) {
3656 ret = os_snprintf(pos, end - pos, "ssid=%s\n",
3657 wpa_ssid_txt(bss->ssid, bss->ssid_len));
3658 if (ret < 0 || ret >= end - pos)
3664 if (mask & WPA_BSS_MASK_WPS_SCAN) {
3665 ie = (const u8 *) (bss + 1);
3666 ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end);
3667 if (ret < 0 || ret >= end - pos)
3671 #endif /* CONFIG_WPS */
3674 if (mask & WPA_BSS_MASK_P2P_SCAN) {
3675 ie = (const u8 *) (bss + 1);
3676 ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end);
3677 if (ret < 0 || ret >= end - pos)
3681 #endif /* CONFIG_P2P */
3683 #ifdef CONFIG_WIFI_DISPLAY
3684 if (mask & WPA_BSS_MASK_WIFI_DISPLAY) {
3686 ie = (const u8 *) (bss + 1);
3687 wfd = ieee802_11_vendor_ie_concat(ie, bss->ie_len,
3688 WFD_IE_VENDOR_TYPE);
3690 ret = os_snprintf(pos, end - pos, "wfd_subelems=");
3691 if (ret < 0 || ret >= end - pos) {
3697 pos += wpa_snprintf_hex(pos, end - pos,
3702 ret = os_snprintf(pos, end - pos, "\n");
3703 if (ret < 0 || ret >= end - pos)
3708 #endif /* CONFIG_WIFI_DISPLAY */
3710 #ifdef CONFIG_INTERWORKING
3711 if ((mask & WPA_BSS_MASK_INTERNETW) && bss->anqp) {
3712 struct wpa_bss_anqp *anqp = bss->anqp;
3713 pos = anqp_add_hex(pos, end, "anqp_venue_name",
3715 pos = anqp_add_hex(pos, end, "anqp_network_auth_type",
3716 anqp->network_auth_type);
3717 pos = anqp_add_hex(pos, end, "anqp_roaming_consortium",
3718 anqp->roaming_consortium);
3719 pos = anqp_add_hex(pos, end, "anqp_ip_addr_type_availability",
3720 anqp->ip_addr_type_availability);
3721 pos = anqp_add_hex(pos, end, "anqp_nai_realm",
3723 pos = anqp_add_hex(pos, end, "anqp_3gpp", anqp->anqp_3gpp);
3724 pos = anqp_add_hex(pos, end, "anqp_domain_name",
3727 pos = anqp_add_hex(pos, end, "hs20_operator_friendly_name",
3728 anqp->hs20_operator_friendly_name);
3729 pos = anqp_add_hex(pos, end, "hs20_wan_metrics",
3730 anqp->hs20_wan_metrics);
3731 pos = anqp_add_hex(pos, end, "hs20_connection_capability",
3732 anqp->hs20_connection_capability);
3733 pos = anqp_add_hex(pos, end, "hs20_operating_class",
3734 anqp->hs20_operating_class);
3735 pos = anqp_add_hex(pos, end, "hs20_osu_providers_list",
3736 anqp->hs20_osu_providers_list);
3737 #endif /* CONFIG_HS20 */
3739 #endif /* CONFIG_INTERWORKING */
3741 if (mask & WPA_BSS_MASK_DELIM) {
3742 ret = os_snprintf(pos, end - pos, "====\n");
3743 if (ret < 0 || ret >= end - pos)
3752 static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
3753 const char *cmd, char *buf,
3758 struct wpa_bss *bss;
3759 struct wpa_bss *bsslast = NULL;
3760 struct dl_list *next;
3764 unsigned long mask = WPA_BSS_MASK_ALL;
3766 if (os_strncmp(cmd, "RANGE=", 6) == 0) {
3767 if (os_strncmp(cmd + 6, "ALL", 3) == 0) {
3768 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss,
3770 bsslast = dl_list_last(&wpa_s->bss_id, struct wpa_bss,
3772 } else { /* N1-N2 */
3773 unsigned int id1, id2;
3775 if ((ctmp = os_strchr(cmd + 6, '-')) == NULL) {
3776 wpa_printf(MSG_INFO, "Wrong BSS range "
3781 if (*(cmd + 6) == '-')
3784 id1 = atoi(cmd + 6);
3786 if (*ctmp >= '0' && *ctmp <= '9')
3789 id2 = (unsigned int) -1;
3790 bss = wpa_bss_get_id_range(wpa_s, id1, id2);
3791 if (id2 == (unsigned int) -1)
3792 bsslast = dl_list_last(&wpa_s->bss_id,
3796 bsslast = wpa_bss_get_id(wpa_s, id2);
3797 if (bsslast == NULL && bss && id2 > id1) {
3798 struct wpa_bss *tmp = bss;
3800 next = tmp->list_id.next;
3801 if (next == &wpa_s->bss_id)
3803 tmp = dl_list_entry(
3804 next, struct wpa_bss,
3813 } else if (os_strncmp(cmd, "FIRST", 5) == 0)
3814 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, list_id);
3815 else if (os_strncmp(cmd, "LAST", 4) == 0)
3816 bss = dl_list_last(&wpa_s->bss_id, struct wpa_bss, list_id);
3817 else if (os_strncmp(cmd, "ID-", 3) == 0) {
3819 bss = wpa_bss_get_id(wpa_s, i);
3820 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
3822 bss = wpa_bss_get_id(wpa_s, i);
3824 next = bss->list_id.next;
3825 if (next == &wpa_s->bss_id)
3828 bss = dl_list_entry(next, struct wpa_bss,
3832 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
3833 if (hwaddr_aton(cmd + 13, bssid) == 0)
3834 bss = wpa_bss_get_p2p_dev_addr(wpa_s, bssid);
3837 #endif /* CONFIG_P2P */
3838 } else if (hwaddr_aton(cmd, bssid) == 0)
3839 bss = wpa_bss_get_bssid(wpa_s, bssid);
3841 struct wpa_bss *tmp;
3844 dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id)
3853 if ((ctmp = os_strstr(cmd, "MASK=")) != NULL) {
3854 mask = strtoul(ctmp + 5, NULL, 0x10);
3856 mask = WPA_BSS_MASK_ALL;
3862 if (bsslast == NULL)
3865 len = print_bss_info(wpa_s, bss, mask, buf, buflen);
3869 if (bss == bsslast) {
3870 if ((mask & WPA_BSS_MASK_DELIM) && len &&
3871 (bss == dl_list_last(&wpa_s->bss_id,
3872 struct wpa_bss, list_id)))
3873 os_snprintf(buf - 5, 5, "####\n");
3876 next = bss->list_id.next;
3877 if (next == &wpa_s->bss_id)
3879 bss = dl_list_entry(next, struct wpa_bss, list_id);
3880 } while (bss && len);
3886 static int wpa_supplicant_ctrl_iface_ap_scan(
3887 struct wpa_supplicant *wpa_s, char *cmd)
3889 int ap_scan = atoi(cmd);
3890 return wpa_supplicant_set_ap_scan(wpa_s, ap_scan);
3894 static int wpa_supplicant_ctrl_iface_scan_interval(
3895 struct wpa_supplicant *wpa_s, char *cmd)
3897 int scan_int = atoi(cmd);
3898 return wpa_supplicant_set_scan_interval(wpa_s, scan_int);
3902 static int wpa_supplicant_ctrl_iface_bss_expire_age(
3903 struct wpa_supplicant *wpa_s, char *cmd)
3905 int expire_age = atoi(cmd);
3906 return wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age);
3910 static int wpa_supplicant_ctrl_iface_bss_expire_count(
3911 struct wpa_supplicant *wpa_s, char *cmd)
3913 int expire_count = atoi(cmd);
3914 return wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count);
3918 static int wpa_supplicant_ctrl_iface_bss_flush(
3919 struct wpa_supplicant *wpa_s, char *cmd)
3921 int flush_age = atoi(cmd);
3924 wpa_bss_flush(wpa_s);
3926 wpa_bss_flush_by_age(wpa_s, flush_age);
3931 #ifdef CONFIG_TESTING_OPTIONS
3932 static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s)
3934 wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication");
3935 /* MLME-DELETEKEYS.request */
3936 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL, 0);
3937 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL, 0);
3938 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL, 0);
3939 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL, 0);
3940 #ifdef CONFIG_IEEE80211W
3941 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL, 0);
3942 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL, 0);
3943 #endif /* CONFIG_IEEE80211W */
3945 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, wpa_s->bssid, 0, 0, NULL, 0, NULL,
3947 /* MLME-SETPROTECTION.request(None) */
3948 wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid,
3949 MLME_SETPROTECTION_PROTECT_TYPE_NONE,
3950 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE);
3951 wpa_sm_drop_sa(wpa_s->wpa);
3953 #endif /* CONFIG_TESTING_OPTIONS */
3956 static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s,
3959 #ifdef CONFIG_NO_SCAN_PROCESSING
3961 #else /* CONFIG_NO_SCAN_PROCESSING */
3963 struct wpa_bss *bss;
3964 struct wpa_ssid *ssid = wpa_s->current_ssid;
3966 if (hwaddr_aton(addr, bssid)) {
3967 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid "
3968 "address '%s'", addr);
3972 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR, MAC2STR(bssid));
3975 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network "
3976 "configuration known for the target AP");
3980 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
3982 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found "
3988 * TODO: Find best network configuration block from configuration to
3989 * allow roaming to other networks
3992 wpa_s->reassociate = 1;
3993 wpa_supplicant_connect(wpa_s, bss, ssid);
3996 #endif /* CONFIG_NO_SCAN_PROCESSING */
4001 static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd)
4003 unsigned int timeout = atoi(cmd);
4004 enum p2p_discovery_type type = P2P_FIND_START_WITH_FULL;
4005 u8 dev_id[ETH_ALEN], *_dev_id = NULL;
4006 u8 dev_type[WPS_DEV_TYPE_LEN], *_dev_type = NULL;
4008 unsigned int search_delay;
4010 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
4011 wpa_dbg(wpa_s, MSG_INFO,
4012 "Reject P2P_FIND since interface is disabled");
4015 if (os_strstr(cmd, "type=social"))
4016 type = P2P_FIND_ONLY_SOCIAL;
4017 else if (os_strstr(cmd, "type=progressive"))
4018 type = P2P_FIND_PROGRESSIVE;
4020 pos = os_strstr(cmd, "dev_id=");
4023 if (hwaddr_aton(pos, dev_id))
4028 pos = os_strstr(cmd, "dev_type=");
4031 if (wps_dev_type_str2bin(pos, dev_type) < 0)
4033 _dev_type = dev_type;
4036 pos = os_strstr(cmd, "delay=");
4039 search_delay = atoi(pos);
4041 search_delay = wpas_p2p_search_delay(wpa_s);
4043 return wpas_p2p_find(wpa_s, timeout, type, _dev_type != NULL, _dev_type,
4044 _dev_id, search_delay);
4048 static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd,
4049 char *buf, size_t buflen)
4054 enum p2p_wps_method wps_method;
4057 int persistent_group, persistent_id = -1;
4066 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad]
4067 * [persistent|persistent=<network id>]
4068 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
4071 if (hwaddr_aton(cmd, addr))
4079 persistent_group = os_strstr(pos, " persistent") != NULL;
4080 pos2 = os_strstr(pos, " persistent=");
4082 struct wpa_ssid *ssid;
4083 persistent_id = atoi(pos2 + 12);
4084 ssid = wpa_config_get_network(wpa_s->conf, persistent_id);
4085 if (ssid == NULL || ssid->disabled != 2 ||
4086 ssid->mode != WPAS_MODE_P2P_GO) {
4087 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
4088 "SSID id=%d for persistent P2P group (GO)",
4093 join = os_strstr(pos, " join") != NULL;
4094 auth = os_strstr(pos, " auth") != NULL;
4095 automatic = os_strstr(pos, " auto") != NULL;
4096 pd = os_strstr(pos, " provdisc") != NULL;
4097 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
4098 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
4101 pos2 = os_strstr(pos, " go_intent=");
4104 go_intent = atoi(pos2);
4105 if (go_intent < 0 || go_intent > 15)
4109 pos2 = os_strstr(pos, " freq=");
4117 if (os_strncmp(pos, "pin", 3) == 0) {
4118 /* Request random PIN (to be displayed) and enable the PIN */
4119 wps_method = WPS_PIN_DISPLAY;
4120 } else if (os_strncmp(pos, "pbc", 3) == 0) {
4121 wps_method = WPS_PBC;
4124 pos = os_strchr(pin, ' ');
4125 wps_method = WPS_PIN_KEYPAD;
4128 if (os_strncmp(pos, "display", 7) == 0)
4129 wps_method = WPS_PIN_DISPLAY;
4131 if (!wps_pin_str_valid(pin)) {
4132 os_memcpy(buf, "FAIL-INVALID-PIN\n", 17);
4137 new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method,
4138 persistent_group, automatic, join,
4139 auth, go_intent, freq, persistent_id, pd,
4141 if (new_pin == -2) {
4142 os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
4145 if (new_pin == -3) {
4146 os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
4151 if (wps_method == WPS_PIN_DISPLAY && pin == NULL) {
4152 ret = os_snprintf(buf, buflen, "%08d", new_pin);
4153 if (ret < 0 || (size_t) ret >= buflen)
4158 os_memcpy(buf, "OK\n", 3);
4163 static int p2p_ctrl_listen(struct wpa_supplicant *wpa_s, char *cmd)
4165 unsigned int timeout = atoi(cmd);
4166 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
4167 wpa_dbg(wpa_s, MSG_INFO,
4168 "Reject P2P_LISTEN since interface is disabled");
4171 return wpas_p2p_listen(wpa_s, timeout);
4175 static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd)
4179 enum wpas_p2p_prov_disc_use use = WPAS_P2P_PD_FOR_GO_NEG;
4181 /* <addr> <config method> [join|auto] */
4183 if (hwaddr_aton(cmd, addr))
4191 if (os_strstr(pos, " join") != NULL)
4192 use = WPAS_P2P_PD_FOR_JOIN;
4193 else if (os_strstr(pos, " auto") != NULL)
4194 use = WPAS_P2P_PD_AUTO;
4196 return wpas_p2p_prov_disc(wpa_s, addr, pos, use);
4200 static int p2p_get_passphrase(struct wpa_supplicant *wpa_s, char *buf,
4203 struct wpa_ssid *ssid = wpa_s->current_ssid;
4205 if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO ||
4206 ssid->passphrase == NULL)
4209 os_strlcpy(buf, ssid->passphrase, buflen);
4210 return os_strlen(buf);
4214 static int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd,
4215 char *buf, size_t buflen)
4219 u8 dst_buf[ETH_ALEN], *dst;
4220 struct wpabuf *tlvs;
4224 if (hwaddr_aton(cmd, dst_buf))
4227 if (dst[0] == 0 && dst[1] == 0 && dst[2] == 0 &&
4228 dst[3] == 0 && dst[4] == 0 && dst[5] == 0)
4235 if (os_strncmp(pos, "upnp ", 5) == 0) {
4238 if (hexstr2bin(pos, &version, 1) < 0)
4244 ref = wpas_p2p_sd_request_upnp(wpa_s, dst, version, pos);
4245 #ifdef CONFIG_WIFI_DISPLAY
4246 } else if (os_strncmp(pos, "wifi-display ", 13) == 0) {
4247 ref = wpas_p2p_sd_request_wifi_display(wpa_s, dst, pos + 13);
4248 #endif /* CONFIG_WIFI_DISPLAY */
4250 len = os_strlen(pos);
4254 tlvs = wpabuf_alloc(len);
4257 if (hexstr2bin(pos, wpabuf_put(tlvs, len), len) < 0) {
4262 ref = wpas_p2p_sd_request(wpa_s, dst, tlvs);
4267 res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref);
4268 if (res < 0 || (unsigned) res >= buflen)
4274 static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s,
4277 long long unsigned val;
4279 if (sscanf(cmd, "%llx", &val) != 1)
4282 return wpas_p2p_sd_cancel_request(wpa_s, req);
4286 static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant *wpa_s, char *cmd)
4291 struct wpabuf *resp_tlvs;
4295 pos = os_strchr(cmd, ' ');
4303 if (hwaddr_aton(pos, dst))
4310 pos2 = os_strchr(pos, ' ');
4314 dialog_token = atoi(pos);
4316 len = os_strlen(pos2);
4320 resp_tlvs = wpabuf_alloc(len);
4321 if (resp_tlvs == NULL)
4323 if (hexstr2bin(pos2, wpabuf_put(resp_tlvs, len), len) < 0) {
4324 wpabuf_free(resp_tlvs);
4328 wpas_p2p_sd_response(wpa_s, freq, dst, dialog_token, resp_tlvs);
4329 wpabuf_free(resp_tlvs);
4334 static int p2p_ctrl_serv_disc_external(struct wpa_supplicant *wpa_s,
4337 if (os_strcmp(cmd, "0") && os_strcmp(cmd, "1"))
4339 wpa_s->p2p_sd_over_ctrl_iface = atoi(cmd);
4344 static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant *wpa_s,
4349 struct wpabuf *query, *resp;
4351 pos = os_strchr(cmd, ' ');
4356 len = os_strlen(cmd);
4360 query = wpabuf_alloc(len);
4363 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
4368 len = os_strlen(pos);
4374 resp = wpabuf_alloc(len);
4379 if (hexstr2bin(pos, wpabuf_put(resp, len), len) < 0) {
4385 if (wpas_p2p_service_add_bonjour(wpa_s, query, resp) < 0) {
4394 static int p2p_ctrl_service_add_upnp(struct wpa_supplicant *wpa_s, char *cmd)
4399 pos = os_strchr(cmd, ' ');
4404 if (hexstr2bin(cmd, &version, 1) < 0)
4407 return wpas_p2p_service_add_upnp(wpa_s, version, pos);
4411 static int p2p_ctrl_service_add(struct wpa_supplicant *wpa_s, char *cmd)
4415 pos = os_strchr(cmd, ' ');
4420 if (os_strcmp(cmd, "bonjour") == 0)
4421 return p2p_ctrl_service_add_bonjour(wpa_s, pos);
4422 if (os_strcmp(cmd, "upnp") == 0)
4423 return p2p_ctrl_service_add_upnp(wpa_s, pos);
4424 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
4429 static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant *wpa_s,
4433 struct wpabuf *query;
4436 len = os_strlen(cmd);
4440 query = wpabuf_alloc(len);
4443 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
4448 ret = wpas_p2p_service_del_bonjour(wpa_s, query);
4454 static int p2p_ctrl_service_del_upnp(struct wpa_supplicant *wpa_s, char *cmd)
4459 pos = os_strchr(cmd, ' ');
4464 if (hexstr2bin(cmd, &version, 1) < 0)
4467 return wpas_p2p_service_del_upnp(wpa_s, version, pos);
4471 static int p2p_ctrl_service_del(struct wpa_supplicant *wpa_s, char *cmd)
4475 pos = os_strchr(cmd, ' ');
4480 if (os_strcmp(cmd, "bonjour") == 0)
4481 return p2p_ctrl_service_del_bonjour(wpa_s, pos);
4482 if (os_strcmp(cmd, "upnp") == 0)
4483 return p2p_ctrl_service_del_upnp(wpa_s, pos);
4484 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
4489 static int p2p_ctrl_reject(struct wpa_supplicant *wpa_s, char *cmd)
4495 if (hwaddr_aton(cmd, addr))
4498 return wpas_p2p_reject(wpa_s, addr);
4502 static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd)
4506 struct wpa_ssid *ssid;
4507 u8 *_peer = NULL, peer[ETH_ALEN];
4508 int freq = 0, pref_freq = 0;
4512 pos = os_strstr(cmd, " peer=");
4515 if (hwaddr_aton(pos, peer))
4519 ssid = wpa_config_get_network(wpa_s->conf, id);
4520 if (ssid == NULL || ssid->disabled != 2) {
4521 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
4522 "for persistent P2P group",
4527 pos = os_strstr(cmd, " freq=");
4535 pos = os_strstr(cmd, " pref=");
4538 pref_freq = atoi(pos);
4543 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
4544 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
4547 return wpas_p2p_invite(wpa_s, _peer, ssid, NULL, freq, ht40, vht,
4552 static int p2p_ctrl_invite_group(struct wpa_supplicant *wpa_s, char *cmd)
4555 u8 peer[ETH_ALEN], go_dev_addr[ETH_ALEN], *go_dev = NULL;
4557 pos = os_strstr(cmd, " peer=");
4563 if (hwaddr_aton(pos, peer)) {
4564 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", pos);
4568 pos = os_strstr(pos, " go_dev_addr=");
4571 if (hwaddr_aton(pos, go_dev_addr)) {
4572 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'",
4576 go_dev = go_dev_addr;
4579 return wpas_p2p_invite_group(wpa_s, cmd, peer, go_dev);
4583 static int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd)
4585 if (os_strncmp(cmd, "persistent=", 11) == 0)
4586 return p2p_ctrl_invite_persistent(wpa_s, cmd + 11);
4587 if (os_strncmp(cmd, "group=", 6) == 0)
4588 return p2p_ctrl_invite_group(wpa_s, cmd + 6);
4594 static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s,
4595 char *cmd, int freq, int ht40,
4599 struct wpa_ssid *ssid;
4602 ssid = wpa_config_get_network(wpa_s->conf, id);
4603 if (ssid == NULL || ssid->disabled != 2) {
4604 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
4605 "for persistent P2P group",
4610 return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq, 0, ht40, vht,
4615 static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd)
4617 int freq = 0, ht40, vht;
4620 pos = os_strstr(cmd, "freq=");
4622 freq = atoi(pos + 5);
4624 vht = (os_strstr(cmd, "vht") != NULL) || wpa_s->conf->p2p_go_vht;
4625 ht40 = (os_strstr(cmd, "ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
4628 if (os_strncmp(cmd, "persistent=", 11) == 0)
4629 return p2p_ctrl_group_add_persistent(wpa_s, cmd + 11, freq,
4631 if (os_strcmp(cmd, "persistent") == 0 ||
4632 os_strncmp(cmd, "persistent ", 11) == 0)
4633 return wpas_p2p_group_add(wpa_s, 1, freq, ht40, vht);
4634 if (os_strncmp(cmd, "freq=", 5) == 0)
4635 return wpas_p2p_group_add(wpa_s, 0, freq, ht40, vht);
4637 return wpas_p2p_group_add(wpa_s, 0, freq, ht40, vht);
4639 wpa_printf(MSG_DEBUG, "CTRL: Invalid P2P_GROUP_ADD parameters '%s'",
4645 static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd,
4646 char *buf, size_t buflen)
4648 u8 addr[ETH_ALEN], *addr_ptr;
4650 const struct p2p_peer_info *info;
4652 char devtype[WPS_DEV_TYPE_BUFSIZE];
4653 struct wpa_ssid *ssid;
4656 if (!wpa_s->global->p2p)
4659 if (os_strcmp(cmd, "FIRST") == 0) {
4662 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
4663 if (hwaddr_aton(cmd + 5, addr) < 0)
4668 if (hwaddr_aton(cmd, addr) < 0)
4674 info = p2p_get_peer_info(wpa_s->global->p2p, addr_ptr, next);
4681 res = os_snprintf(pos, end - pos, MACSTR "\n"
4687 "serial_number=%s\n"
4688 "config_methods=0x%x\n"
4690 "group_capab=0x%x\n"
4692 MAC2STR(info->p2p_device_addr),
4693 wps_dev_type_bin2str(info->pri_dev_type,
4694 devtype, sizeof(devtype)),
4699 info->serial_number,
4700 info->config_methods,
4704 if (res < 0 || res >= end - pos)
4708 for (i = 0; i < info->wps_sec_dev_type_list_len / WPS_DEV_TYPE_LEN; i++)
4711 t = &info->wps_sec_dev_type_list[i * WPS_DEV_TYPE_LEN];
4712 res = os_snprintf(pos, end - pos, "sec_dev_type=%s\n",
4713 wps_dev_type_bin2str(t, devtype,
4715 if (res < 0 || res >= end - pos)
4720 ssid = wpas_p2p_get_persistent(wpa_s, info->p2p_device_addr, NULL, 0);
4722 res = os_snprintf(pos, end - pos, "persistent=%d\n", ssid->id);
4723 if (res < 0 || res >= end - pos)
4728 res = p2p_get_peer_info_txt(info, pos, end - pos);
4733 if (info->vendor_elems) {
4734 res = os_snprintf(pos, end - pos, "vendor_elems=");
4735 if (res < 0 || res >= end - pos)
4739 pos += wpa_snprintf_hex(pos, end - pos,
4740 wpabuf_head(info->vendor_elems),
4741 wpabuf_len(info->vendor_elems));
4743 res = os_snprintf(pos, end - pos, "\n");
4744 if (res < 0 || res >= end - pos)
4753 static int p2p_ctrl_disallow_freq(struct wpa_supplicant *wpa_s,
4758 if (wpa_s->global->p2p == NULL)
4761 if (freq_range_list_parse(&wpa_s->global->p2p_disallow_freq, param) < 0)
4764 for (i = 0; i < wpa_s->global->p2p_disallow_freq.num; i++) {
4765 struct wpa_freq_range *freq;
4766 freq = &wpa_s->global->p2p_disallow_freq.range[i];
4767 wpa_printf(MSG_DEBUG, "P2P: Disallowed frequency range %u-%u",
4768 freq->min, freq->max);
4771 wpas_p2p_update_channel_list(wpa_s);
4776 static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd)
4780 if (wpa_s->global->p2p == NULL)
4783 param = os_strchr(cmd, ' ');
4788 if (os_strcmp(cmd, "discoverability") == 0) {
4789 p2p_set_client_discoverability(wpa_s->global->p2p,
4794 if (os_strcmp(cmd, "managed") == 0) {
4795 p2p_set_managed_oper(wpa_s->global->p2p, atoi(param));
4799 if (os_strcmp(cmd, "listen_channel") == 0) {
4800 return p2p_set_listen_channel(wpa_s->global->p2p, 81,
4804 if (os_strcmp(cmd, "ssid_postfix") == 0) {
4805 return p2p_set_ssid_postfix(wpa_s->global->p2p, (u8 *) param,
4809 if (os_strcmp(cmd, "noa") == 0) {
4811 int count, start, duration;
4812 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
4813 count = atoi(param);
4814 pos = os_strchr(param, ',');
4819 pos = os_strchr(pos, ',');
4823 duration = atoi(pos);
4824 if (count < 0 || count > 255 || start < 0 || duration < 0)
4826 if (count == 0 && duration > 0)
4828 wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
4829 "start=%d duration=%d", count, start, duration);
4830 return wpas_p2p_set_noa(wpa_s, count, start, duration);
4833 if (os_strcmp(cmd, "ps") == 0)
4834 return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1);
4836 if (os_strcmp(cmd, "oppps") == 0)
4837 return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1);
4839 if (os_strcmp(cmd, "ctwindow") == 0)
4840 return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param));
4842 if (os_strcmp(cmd, "disabled") == 0) {
4843 wpa_s->global->p2p_disabled = atoi(param);
4844 wpa_printf(MSG_DEBUG, "P2P functionality %s",
4845 wpa_s->global->p2p_disabled ?
4846 "disabled" : "enabled");
4847 if (wpa_s->global->p2p_disabled) {
4848 wpas_p2p_stop_find(wpa_s);
4849 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
4850 p2p_flush(wpa_s->global->p2p);
4855 if (os_strcmp(cmd, "conc_pref") == 0) {
4856 if (os_strcmp(param, "sta") == 0)
4857 wpa_s->global->conc_pref = WPA_CONC_PREF_STA;
4858 else if (os_strcmp(param, "p2p") == 0)
4859 wpa_s->global->conc_pref = WPA_CONC_PREF_P2P;
4861 wpa_printf(MSG_INFO, "Invalid conc_pref value");
4864 wpa_printf(MSG_DEBUG, "Single channel concurrency preference: "
4869 if (os_strcmp(cmd, "force_long_sd") == 0) {
4870 wpa_s->force_long_sd = atoi(param);
4874 if (os_strcmp(cmd, "peer_filter") == 0) {
4876 if (hwaddr_aton(param, addr))
4878 p2p_set_peer_filter(wpa_s->global->p2p, addr);
4882 if (os_strcmp(cmd, "cross_connect") == 0)
4883 return wpas_p2p_set_cross_connect(wpa_s, atoi(param));
4885 if (os_strcmp(cmd, "go_apsd") == 0) {
4886 if (os_strcmp(param, "disable") == 0)
4887 wpa_s->set_ap_uapsd = 0;
4889 wpa_s->set_ap_uapsd = 1;
4890 wpa_s->ap_uapsd = atoi(param);
4895 if (os_strcmp(cmd, "client_apsd") == 0) {
4896 if (os_strcmp(param, "disable") == 0)
4897 wpa_s->set_sta_uapsd = 0;
4901 /* format: BE,BK,VI,VO;max SP Length */
4903 pos = os_strchr(param, ',');
4908 pos = os_strchr(pos, ',');
4913 pos = os_strchr(pos, ',');
4918 /* ignore max SP Length for now */
4920 wpa_s->set_sta_uapsd = 1;
4921 wpa_s->sta_uapsd = 0;
4923 wpa_s->sta_uapsd |= BIT(0);
4925 wpa_s->sta_uapsd |= BIT(1);
4927 wpa_s->sta_uapsd |= BIT(2);
4929 wpa_s->sta_uapsd |= BIT(3);
4934 if (os_strcmp(cmd, "disallow_freq") == 0)
4935 return p2p_ctrl_disallow_freq(wpa_s, param);
4937 if (os_strcmp(cmd, "disc_int") == 0) {
4938 int min_disc_int, max_disc_int, max_disc_tu;
4943 min_disc_int = atoi(pos);
4944 pos = os_strchr(pos, ' ');
4949 max_disc_int = atoi(pos);
4950 pos = os_strchr(pos, ' ');
4955 max_disc_tu = atoi(pos);
4957 return p2p_set_disc_int(wpa_s->global->p2p, min_disc_int,
4958 max_disc_int, max_disc_tu);
4961 if (os_strcmp(cmd, "per_sta_psk") == 0) {
4962 wpa_s->global->p2p_per_sta_psk = !!atoi(param);
4966 #ifdef CONFIG_WPS_NFC
4967 if (os_strcmp(cmd, "nfc_tag") == 0)
4968 return wpas_p2p_nfc_tag_enabled(wpa_s, !!atoi(param));
4969 #endif /* CONFIG_WPS_NFC */
4971 if (os_strcmp(cmd, "disable_ip_addr_req") == 0) {
4972 wpa_s->p2p_disable_ip_addr_req = !!atoi(param);
4976 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
4983 static void p2p_ctrl_flush(struct wpa_supplicant *wpa_s)
4985 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
4986 wpa_s->force_long_sd = 0;
4987 if (wpa_s->global->p2p)
4988 p2p_flush(wpa_s->global->p2p);
4992 static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd)
4995 unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0;
4998 pos = os_strchr(cmd, ' ');
5004 pos2 = os_strchr(pos, ' ');
5012 pos = os_strchr(pos2, ' ');
5020 return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2);
5024 static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd)
5027 unsigned int period = 0, interval = 0;
5030 pos = os_strchr(cmd, ' ');
5035 interval = atoi(pos);
5038 return wpas_p2p_ext_listen(wpa_s, period, interval);
5042 static int p2p_ctrl_remove_client(struct wpa_supplicant *wpa_s, const char *cmd)
5049 if (os_strncmp(pos, "iface=", 6) == 0) {
5053 if (hwaddr_aton(pos, peer))
5056 wpas_p2p_remove_client(wpa_s, peer, iface_addr);
5060 #endif /* CONFIG_P2P */
5063 static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s, char *val)
5065 struct wpa_freq_range_list ranges;
5067 struct hostapd_hw_modes *mode;
5070 if (wpa_s->hw.modes == NULL)
5073 os_memset(&ranges, 0, sizeof(ranges));
5074 if (freq_range_list_parse(&ranges, val) < 0)
5077 for (i = 0; i < wpa_s->hw.num_modes; i++) {
5080 mode = &wpa_s->hw.modes[i];
5081 for (j = 0; j < mode->num_channels; j++) {
5084 if (mode->channels[j].flag & HOSTAPD_CHAN_DISABLED)
5087 freq = mode->channels[j].freq;
5088 if (!freq_range_list_includes(&ranges, freq))
5091 int_array_add_unique(&freqs, freq);
5095 os_free(ranges.range);
5100 #ifdef CONFIG_INTERWORKING
5102 static int ctrl_interworking_select(struct wpa_supplicant *wpa_s, char *param)
5110 auto_sel = os_strstr(param, "auto") != NULL;
5112 pos = os_strstr(param, "freq=");
5114 freqs = freq_range_to_channel_list(wpa_s, pos + 5);
5121 return interworking_select(wpa_s, auto_sel, freqs);
5125 static int ctrl_interworking_connect(struct wpa_supplicant *wpa_s, char *dst)
5128 struct wpa_bss *bss;
5130 if (hwaddr_aton(dst, bssid)) {
5131 wpa_printf(MSG_DEBUG, "Invalid BSSID '%s'", dst);
5135 bss = wpa_bss_get_bssid(wpa_s, bssid);
5137 wpa_printf(MSG_DEBUG, "Could not find BSS " MACSTR,
5142 return interworking_connect(wpa_s, bss);
5146 static int get_anqp(struct wpa_supplicant *wpa_s, char *dst)
5148 u8 dst_addr[ETH_ALEN];
5151 #define MAX_ANQP_INFO_ID 100
5152 u16 id[MAX_ANQP_INFO_ID];
5156 used = hwaddr_aton2(dst, dst_addr);
5160 while (num_id < MAX_ANQP_INFO_ID) {
5161 if (os_strncmp(pos, "hs20:", 5) == 0) {
5163 int num = atoi(pos + 5);
5164 if (num <= 0 || num > 31)
5166 subtypes |= BIT(num);
5167 #else /* CONFIG_HS20 */
5169 #endif /* CONFIG_HS20 */
5171 id[num_id] = atoi(pos);
5175 pos = os_strchr(pos + 1, ',');
5184 return anqp_send_req(wpa_s, dst_addr, id, num_id, subtypes);
5188 static int gas_request(struct wpa_supplicant *wpa_s, char *cmd)
5190 u8 dst_addr[ETH_ALEN];
5191 struct wpabuf *advproto, *query = NULL;
5196 used = hwaddr_aton2(cmd, dst_addr);
5204 /* Advertisement Protocol ID */
5205 end = os_strchr(pos, ' ');
5209 len = os_strlen(pos);
5215 advproto = wpabuf_alloc(len);
5216 if (advproto == NULL)
5218 if (hexstr2bin(pos, wpabuf_put(advproto, len), len) < 0)
5222 /* Optional Query Request */
5227 len = os_strlen(pos);
5234 query = wpabuf_alloc(len);
5237 if (hexstr2bin(pos, wpabuf_put(query, len), len) < 0)
5242 ret = gas_send_request(wpa_s, dst_addr, advproto, query);
5245 wpabuf_free(advproto);
5252 static int gas_response_get(struct wpa_supplicant *wpa_s, char *cmd, char *buf,
5259 size_t resp_len, start, requested_len;
5260 struct wpabuf *resp;
5263 used = hwaddr_aton2(cmd, addr);
5270 dialog_token = atoi(pos);
5272 if (wpa_s->last_gas_resp &&
5273 os_memcmp(addr, wpa_s->last_gas_addr, ETH_ALEN) == 0 &&
5274 dialog_token == wpa_s->last_gas_dialog_token)
5275 resp = wpa_s->last_gas_resp;
5276 else if (wpa_s->prev_gas_resp &&
5277 os_memcmp(addr, wpa_s->prev_gas_addr, ETH_ALEN) == 0 &&
5278 dialog_token == wpa_s->prev_gas_dialog_token)
5279 resp = wpa_s->prev_gas_resp;
5283 resp_len = wpabuf_len(resp);
5285 requested_len = resp_len;
5287 pos = os_strchr(pos, ' ');
5290 if (start > resp_len)
5291 return os_snprintf(buf, buflen, "FAIL-Invalid range");
5292 pos = os_strchr(pos, ',');
5296 requested_len = atoi(pos);
5297 if (start + requested_len > resp_len)
5298 return os_snprintf(buf, buflen, "FAIL-Invalid range");
5301 if (requested_len * 2 + 1 > buflen)
5302 return os_snprintf(buf, buflen, "FAIL-Too long response");
5304 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(resp) + start,
5307 if (start + requested_len == resp_len) {
5309 * Free memory by dropping the response after it has been
5312 if (resp == wpa_s->prev_gas_resp) {
5313 wpabuf_free(wpa_s->prev_gas_resp);
5314 wpa_s->prev_gas_resp = NULL;
5316 wpabuf_free(wpa_s->last_gas_resp);
5317 wpa_s->last_gas_resp = NULL;
5323 #endif /* CONFIG_INTERWORKING */
5328 static int get_hs20_anqp(struct wpa_supplicant *wpa_s, char *dst)
5330 u8 dst_addr[ETH_ALEN];
5335 used = hwaddr_aton2(dst, dst_addr);
5340 int num = atoi(pos);
5341 if (num <= 0 || num > 31)
5343 subtypes |= BIT(num);
5344 pos = os_strchr(pos + 1, ',');
5353 return hs20_anqp_send_req(wpa_s, dst_addr, subtypes, NULL, 0);
5357 static int hs20_nai_home_realm_list(struct wpa_supplicant *wpa_s,
5358 const u8 *addr, const char *realm)
5364 rlen = os_strlen(realm);
5366 buf = os_malloc(len);
5369 buf[0] = 1; /* NAI Home Realm Count */
5370 buf[1] = 0; /* Formatted in accordance with RFC 4282 */
5372 os_memcpy(buf + 3, realm, rlen);
5374 ret = hs20_anqp_send_req(wpa_s, addr,
5375 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
5384 static int hs20_get_nai_home_realm_list(struct wpa_supplicant *wpa_s,
5387 struct wpa_cred *cred = wpa_s->conf->cred;
5388 u8 dst_addr[ETH_ALEN];
5394 used = hwaddr_aton2(dst, dst_addr);
5398 while (dst[used] == ' ')
5400 if (os_strncmp(dst + used, "realm=", 6) == 0)
5401 return hs20_nai_home_realm_list(wpa_s, dst_addr,
5404 len = os_strlen(dst + used);
5406 if (len == 0 && cred && cred->realm)
5407 return hs20_nai_home_realm_list(wpa_s, dst_addr, cred->realm);
5412 buf = os_malloc(len);
5415 if (hexstr2bin(dst + used, buf, len) < 0) {
5420 ret = hs20_anqp_send_req(wpa_s, dst_addr,
5421 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
5429 static int hs20_icon_request(struct wpa_supplicant *wpa_s, char *cmd)
5431 u8 dst_addr[ETH_ALEN];
5435 used = hwaddr_aton2(cmd, dst_addr);
5439 while (cmd[used] == ' ')
5443 wpa_s->fetch_osu_icon_in_progress = 0;
5444 return hs20_anqp_send_req(wpa_s, dst_addr, BIT(HS20_STYPE_ICON_REQUEST),
5445 (u8 *) icon, os_strlen(icon));
5448 #endif /* CONFIG_HS20 */
5451 static int wpa_supplicant_ctrl_iface_sta_autoconnect(
5452 struct wpa_supplicant *wpa_s, char *cmd)
5454 wpa_s->auto_reconnect_disabled = atoi(cmd) == 0 ? 1 : 0;
5459 #ifdef CONFIG_AUTOSCAN
5461 static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant *wpa_s,
5464 enum wpa_states state = wpa_s->wpa_state;
5465 char *new_params = NULL;
5467 if (os_strlen(cmd) > 0) {
5468 new_params = os_strdup(cmd);
5469 if (new_params == NULL)
5473 os_free(wpa_s->conf->autoscan);
5474 wpa_s->conf->autoscan = new_params;
5476 if (wpa_s->conf->autoscan == NULL)
5477 autoscan_deinit(wpa_s);
5478 else if (state == WPA_DISCONNECTED || state == WPA_INACTIVE)
5479 autoscan_init(wpa_s, 1);
5480 else if (state == WPA_SCANNING)
5481 wpa_supplicant_reinit_autoscan(wpa_s);
5486 #endif /* CONFIG_AUTOSCAN */
5491 static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant *wpa_s, char *cmd)
5497 struct wpabuf *tfs_req = NULL;
5499 if (os_strncmp(cmd, "enter", 5) == 0)
5501 else if (os_strncmp(cmd, "exit", 4) == 0)
5506 pos = os_strstr(cmd, " interval=");
5508 intval = atoi(pos + 10);
5510 pos = os_strstr(cmd, " tfs_req=");
5515 end = os_strchr(pos, ' ');
5519 len = os_strlen(pos);
5523 tfs_req = wpabuf_alloc(len);
5524 if (tfs_req == NULL)
5526 if (hexstr2bin(pos, wpabuf_put(tfs_req, len), len) < 0) {
5527 wpabuf_free(tfs_req);
5532 ret = ieee802_11_send_wnmsleep_req(wpa_s, enter ? WNM_SLEEP_MODE_ENTER :
5533 WNM_SLEEP_MODE_EXIT, intval,
5535 wpabuf_free(tfs_req);
5541 static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant *wpa_s, char *cmd)
5545 query_reason = atoi(cmd);
5547 wpa_printf(MSG_DEBUG, "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d",
5550 return wnm_send_bss_transition_mgmt_query(wpa_s, query_reason);
5553 #endif /* CONFIG_WNM */
5556 /* Get string representation of channel width */
5557 static const char * channel_width_name(enum chan_width width)
5560 case CHAN_WIDTH_20_NOHT:
5561 return "20 MHz (no HT)";
5568 case CHAN_WIDTH_80P80:
5570 case CHAN_WIDTH_160:
5578 static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf,
5581 struct wpa_signal_info si;
5585 ret = wpa_drv_signal_poll(wpa_s, &si);
5592 ret = os_snprintf(pos, end - pos, "RSSI=%d\nLINKSPEED=%d\n"
5593 "NOISE=%d\nFREQUENCY=%u\n",
5594 si.current_signal, si.current_txrate / 1000,
5595 si.current_noise, si.frequency);
5596 if (ret < 0 || ret > end - pos)
5600 if (si.chanwidth != CHAN_WIDTH_UNKNOWN) {
5601 ret = os_snprintf(pos, end - pos, "WIDTH=%s\n",
5602 channel_width_name(si.chanwidth));
5603 if (ret < 0 || ret > end - pos)
5608 if (si.center_frq1 > 0 && si.center_frq2 > 0) {
5609 ret = os_snprintf(pos, end - pos,
5610 "CENTER_FRQ1=%d\nCENTER_FRQ2=%d\n",
5611 si.center_frq1, si.center_frq2);
5612 if (ret < 0 || ret > end - pos)
5617 if (si.avg_signal) {
5618 ret = os_snprintf(pos, end - pos,
5619 "AVG_RSSI=%d\n", si.avg_signal);
5620 if (ret < 0 || ret >= end - pos)
5629 static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant *wpa_s, char *buf,
5632 struct hostap_sta_driver_data sta;
5635 ret = wpa_drv_pktcnt_poll(wpa_s, &sta);
5639 ret = os_snprintf(buf, buflen, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
5640 sta.tx_packets, sta.tx_retry_failed, sta.rx_packets);
5641 if (ret < 0 || (size_t) ret > buflen)
5648 static int wpa_supplicant_driver_cmd(struct wpa_supplicant *wpa_s, char *cmd,
5649 char *buf, size_t buflen)
5653 ret = wpa_drv_driver_cmd(wpa_s, cmd, buf, buflen);
5655 if (os_strncasecmp(cmd, "COUNTRY", 7) == 0) {
5656 struct p2p_data *p2p = wpa_s->global->p2p;
5659 country[0] = cmd[8];
5660 country[1] = cmd[9];
5662 p2p_set_country(p2p, country);
5665 ret = os_snprintf(buf, buflen, "%s\n", "OK");
5669 #endif /* ANDROID */
5672 static int wpa_supplicant_vendor_cmd(struct wpa_supplicant *wpa_s, char *cmd,
5673 char *buf, size_t buflen)
5678 unsigned int vendor_id, subcmd;
5679 struct wpabuf *reply;
5680 size_t data_len = 0;
5682 /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */
5683 vendor_id = strtoul(cmd, &pos, 16);
5687 subcmd = strtoul(pos, &pos, 10);
5690 if (!isblank(*pos++))
5692 data_len = os_strlen(pos);
5697 data = os_malloc(data_len);
5701 if (hexstr2bin(pos, data, data_len)) {
5702 wpa_printf(MSG_DEBUG,
5703 "Vendor command: wrong parameter format");
5709 reply = wpabuf_alloc((buflen - 1) / 2);
5715 ret = wpa_drv_vendor_cmd(wpa_s, vendor_id, subcmd, data, data_len,
5719 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(reply),
5729 static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s)
5731 wpa_dbg(wpa_s, MSG_DEBUG, "Flush all wpa_supplicant state");
5734 wpas_p2p_cancel(wpa_s);
5735 wpas_p2p_stop_find(wpa_s);
5736 p2p_ctrl_flush(wpa_s);
5737 wpas_p2p_group_remove(wpa_s, "*");
5738 wpas_p2p_service_flush(wpa_s);
5739 wpa_s->global->p2p_disabled = 0;
5740 wpa_s->global->p2p_per_sta_psk = 0;
5741 wpa_s->conf->num_sec_device_types = 0;
5742 wpa_s->p2p_disable_ip_addr_req = 0;
5743 os_free(wpa_s->global->p2p_go_avoid_freq.range);
5744 wpa_s->global->p2p_go_avoid_freq.range = NULL;
5745 #endif /* CONFIG_P2P */
5747 #ifdef CONFIG_WPS_TESTING
5748 wps_version_number = 0x20;
5749 wps_testing_dummy_cred = 0;
5750 wps_corrupt_pkhash = 0;
5751 #endif /* CONFIG_WPS_TESTING */
5753 wpa_s->wps_fragment_size = 0;
5754 wpas_wps_cancel(wpa_s);
5755 #endif /* CONFIG_WPS */
5756 wpa_s->after_wps = 0;
5757 wpa_s->known_wps_freq = 0;
5760 #ifdef CONFIG_TDLS_TESTING
5761 extern unsigned int tdls_testing;
5763 #endif /* CONFIG_TDLS_TESTING */
5764 wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL);
5765 wpa_tdls_enable(wpa_s->wpa, 1);
5766 #endif /* CONFIG_TDLS */
5768 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, wpa_s, NULL);
5769 wpa_supplicant_stop_countermeasures(wpa_s, NULL);
5771 wpa_s->no_keep_alive = 0;
5773 os_free(wpa_s->disallow_aps_bssid);
5774 wpa_s->disallow_aps_bssid = NULL;
5775 wpa_s->disallow_aps_bssid_count = 0;
5776 os_free(wpa_s->disallow_aps_ssid);
5777 wpa_s->disallow_aps_ssid = NULL;
5778 wpa_s->disallow_aps_ssid_count = 0;
5780 wpa_s->set_sta_uapsd = 0;
5781 wpa_s->sta_uapsd = 0;
5783 wpa_drv_radio_disable(wpa_s, 0);
5785 wpa_bss_flush(wpa_s);
5786 wpa_blacklist_clear(wpa_s);
5787 wpa_s->extra_blacklist_count = 0;
5788 wpa_supplicant_ctrl_iface_remove_network(wpa_s, "all");
5789 wpa_supplicant_ctrl_iface_remove_cred(wpa_s, "all");
5790 wpa_config_flush_blobs(wpa_s->conf);
5791 wpa_s->conf->auto_interworking = 0;
5792 wpa_s->conf->okc = 0;
5794 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, 43200);
5795 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, 70);
5796 wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, 60);
5797 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
5799 radio_remove_works(wpa_s, NULL, 1);
5801 wpa_s->next_ssid = NULL;
5803 #ifdef CONFIG_INTERWORKING
5804 hs20_cancel_fetch_osu(wpa_s);
5805 #endif /* CONFIG_INTERWORKING */
5807 wpa_s->ext_mgmt_frame_handling = 0;
5811 static int wpas_ctrl_radio_work_show(struct wpa_supplicant *wpa_s,
5812 char *buf, size_t buflen)
5814 struct wpa_radio_work *work;
5816 struct os_reltime now, diff;
5821 os_get_reltime(&now);
5823 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
5827 os_reltime_sub(&now, &work->time, &diff);
5828 ret = os_snprintf(pos, end - pos, "%s@%s:%u:%u:%ld.%06ld\n",
5829 work->type, work->wpa_s->ifname, work->freq,
5830 work->started, diff.sec, diff.usec);
5831 if (ret < 0 || ret >= end - pos)
5840 static void wpas_ctrl_radio_work_timeout(void *eloop_ctx, void *timeout_ctx)
5842 struct wpa_radio_work *work = eloop_ctx;
5843 struct wpa_external_work *ework = work->ctx;
5845 wpa_dbg(work->wpa_s, MSG_DEBUG,
5846 "Timing out external radio work %u (%s)",
5847 ework->id, work->type);
5848 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_TIMEOUT "%u", ework->id);
5849 radio_work_done(work);
5854 static void wpas_ctrl_radio_work_cb(struct wpa_radio_work *work, int deinit)
5856 struct wpa_external_work *ework = work->ctx;
5860 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
5867 wpa_dbg(work->wpa_s, MSG_DEBUG, "Starting external radio work %u (%s)",
5868 ework->id, ework->type);
5869 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_START "%u", ework->id);
5870 if (!ework->timeout)
5871 ework->timeout = 10;
5872 eloop_register_timeout(ework->timeout, 0, wpas_ctrl_radio_work_timeout,
5877 static int wpas_ctrl_radio_work_add(struct wpa_supplicant *wpa_s, char *cmd,
5878 char *buf, size_t buflen)
5880 struct wpa_external_work *ework;
5884 unsigned int freq = 0;
5886 /* format: <name> [freq=<MHz>] [timeout=<seconds>] */
5888 ework = os_zalloc(sizeof(*ework));
5892 pos = os_strchr(cmd, ' ');
5894 type_len = pos - cmd;
5897 pos2 = os_strstr(pos, "freq=");
5899 freq = atoi(pos2 + 5);
5901 pos2 = os_strstr(pos, "timeout=");
5903 ework->timeout = atoi(pos2 + 8);
5905 type_len = os_strlen(cmd);
5907 if (4 + type_len >= sizeof(ework->type))
5908 type_len = sizeof(ework->type) - 4 - 1;
5909 os_strlcpy(ework->type, "ext:", sizeof(ework->type));
5910 os_memcpy(ework->type + 4, cmd, type_len);
5911 ework->type[4 + type_len] = '\0';
5913 wpa_s->ext_work_id++;
5914 if (wpa_s->ext_work_id == 0)
5915 wpa_s->ext_work_id++;
5916 ework->id = wpa_s->ext_work_id;
5918 if (radio_add_work(wpa_s, freq, ework->type, 0, wpas_ctrl_radio_work_cb,
5924 ret = os_snprintf(buf, buflen, "%u", ework->id);
5925 if (ret < 0 || (size_t) ret >= buflen)
5931 static int wpas_ctrl_radio_work_done(struct wpa_supplicant *wpa_s, char *cmd)
5933 struct wpa_radio_work *work;
5934 unsigned int id = atoi(cmd);
5936 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
5938 struct wpa_external_work *ework;
5940 if (os_strncmp(work->type, "ext:", 4) != 0)
5943 if (id && ework->id != id)
5945 wpa_dbg(wpa_s, MSG_DEBUG,
5946 "Completed external radio work %u (%s)",
5947 ework->id, ework->type);
5948 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, work, NULL);
5949 radio_work_done(work);
5951 return 3; /* "OK\n" */
5958 static int wpas_ctrl_radio_work(struct wpa_supplicant *wpa_s, char *cmd,
5959 char *buf, size_t buflen)
5961 if (os_strcmp(cmd, "show") == 0)
5962 return wpas_ctrl_radio_work_show(wpa_s, buf, buflen);
5963 if (os_strncmp(cmd, "add ", 4) == 0)
5964 return wpas_ctrl_radio_work_add(wpa_s, cmd + 4, buf, buflen);
5965 if (os_strncmp(cmd, "done ", 5) == 0)
5966 return wpas_ctrl_radio_work_done(wpa_s, cmd + 4);
5971 void wpas_ctrl_radio_work_flush(struct wpa_supplicant *wpa_s)
5973 struct wpa_radio_work *work, *tmp;
5975 if (!wpa_s || !wpa_s->radio)
5978 dl_list_for_each_safe(work, tmp, &wpa_s->radio->work,
5979 struct wpa_radio_work, list) {
5980 struct wpa_external_work *ework;
5982 if (os_strncmp(work->type, "ext:", 4) != 0)
5985 wpa_dbg(wpa_s, MSG_DEBUG,
5986 "Flushing%s external radio work %u (%s)",
5987 work->started ? " started" : "", ework->id,
5990 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
5992 radio_work_done(work);
5998 static void wpas_ctrl_eapol_response(void *eloop_ctx, void *timeout_ctx)
6000 struct wpa_supplicant *wpa_s = eloop_ctx;
6001 eapol_sm_notify_ctrl_response(wpa_s->eapol);
6005 static int set_scan_freqs(struct wpa_supplicant *wpa_s, char *val)
6009 freqs = freq_range_to_channel_list(wpa_s, val);
6013 os_free(wpa_s->manual_scan_freqs);
6014 wpa_s->manual_scan_freqs = freqs;
6020 static int scan_id_list_parse(struct wpa_supplicant *wpa_s, const char *value)
6022 const char *pos = value;
6025 if (*pos == ' ' || *pos == '\0')
6027 if (wpa_s->scan_id_count == MAX_SCAN_ID)
6029 wpa_s->scan_id[wpa_s->scan_id_count++] = atoi(pos);
6030 pos = os_strchr(pos, ',');
6039 static void wpas_ctrl_scan(struct wpa_supplicant *wpa_s, char *params,
6040 char *reply, int reply_size, int *reply_len)
6044 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
6049 wpa_s->manual_scan_passive = 0;
6050 wpa_s->manual_scan_use_id = 0;
6051 wpa_s->manual_scan_only_new = 0;
6052 wpa_s->scan_id_count = 0;
6055 if (os_strncasecmp(params, "TYPE=ONLY", 9) == 0)
6056 wpa_s->scan_res_handler = scan_only_handler;
6058 pos = os_strstr(params, "freq=");
6059 if (pos && set_scan_freqs(wpa_s, pos + 5) < 0) {
6064 pos = os_strstr(params, "passive=");
6066 wpa_s->manual_scan_passive = !!atoi(pos + 8);
6068 pos = os_strstr(params, "use_id=");
6070 wpa_s->manual_scan_use_id = atoi(pos + 7);
6072 pos = os_strstr(params, "only_new=1");
6074 wpa_s->manual_scan_only_new = 1;
6076 pos = os_strstr(params, "scan_id=");
6077 if (pos && scan_id_list_parse(wpa_s, pos + 8) < 0) {
6082 os_free(wpa_s->manual_scan_freqs);
6083 wpa_s->manual_scan_freqs = NULL;
6084 if (wpa_s->scan_res_handler == scan_only_handler)
6085 wpa_s->scan_res_handler = NULL;
6088 if (!wpa_s->sched_scanning && !wpa_s->scanning &&
6089 ((wpa_s->wpa_state <= WPA_SCANNING) ||
6090 (wpa_s->wpa_state == WPA_COMPLETED))) {
6091 wpa_s->normal_scans = 0;
6092 wpa_s->scan_req = MANUAL_SCAN_REQ;
6093 wpa_s->after_wps = 0;
6094 wpa_s->known_wps_freq = 0;
6095 wpa_supplicant_req_scan(wpa_s, 0, 0);
6096 if (wpa_s->manual_scan_use_id) {
6097 wpa_s->manual_scan_id++;
6098 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
6099 wpa_s->manual_scan_id);
6100 *reply_len = os_snprintf(reply, reply_size, "%u\n",
6101 wpa_s->manual_scan_id);
6103 } else if (wpa_s->sched_scanning) {
6104 wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to allow requested full scan to proceed");
6105 wpa_supplicant_cancel_sched_scan(wpa_s);
6106 wpa_s->scan_req = MANUAL_SCAN_REQ;
6107 wpa_supplicant_req_scan(wpa_s, 0, 0);
6108 if (wpa_s->manual_scan_use_id) {
6109 wpa_s->manual_scan_id++;
6110 *reply_len = os_snprintf(reply, reply_size, "%u\n",
6111 wpa_s->manual_scan_id);
6112 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
6113 wpa_s->manual_scan_id);
6116 wpa_printf(MSG_DEBUG, "Ongoing scan action - reject new request");
6117 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
6122 #ifdef CONFIG_TESTING_OPTIONS
6124 static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant *wpa_s,
6125 unsigned int freq, const u8 *dst,
6126 const u8 *src, const u8 *bssid,
6127 const u8 *data, size_t data_len,
6128 enum offchannel_send_action_result
6131 wpa_msg(wpa_s, MSG_INFO, "MGMT-TX-STATUS freq=%u dst=" MACSTR
6132 " src=" MACSTR " bssid=" MACSTR " result=%s",
6133 freq, MAC2STR(dst), MAC2STR(src), MAC2STR(bssid),
6134 result == OFFCHANNEL_SEND_ACTION_SUCCESS ?
6135 "SUCCESS" : (result == OFFCHANNEL_SEND_ACTION_NO_ACK ?
6136 "NO_ACK" : "FAILED"));
6140 static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant *wpa_s, char *cmd)
6144 u8 *buf, da[ETH_ALEN], bssid[ETH_ALEN];
6146 int freq = 0, no_cck = 0, wait_time = 0;
6148 /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1]
6149 * <action=Action frame payload> */
6151 wpa_printf(MSG_DEBUG, "External MGMT TX: %s", cmd);
6154 used = hwaddr_aton2(pos, da);
6160 used = hwaddr_aton2(pos, bssid);
6165 param = os_strstr(pos, " freq=");
6171 param = os_strstr(pos, " no_cck=");
6174 no_cck = atoi(param);
6177 param = os_strstr(pos, " wait_time=");
6180 wait_time = atoi(param);
6183 param = os_strstr(pos, " action=");
6188 len = os_strlen(param);
6193 buf = os_malloc(len);
6197 if (hexstr2bin(param, buf, len) < 0) {
6202 res = offchannel_send_action(wpa_s, freq, da, wpa_s->own_addr, bssid,
6203 buf, len, wait_time,
6204 wpas_ctrl_iface_mgmt_tx_cb, no_cck);
6210 static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant *wpa_s)
6212 wpa_printf(MSG_DEBUG, "External MGMT TX - done waiting");
6213 offchannel_send_action_done(wpa_s);
6217 static int wpas_ctrl_iface_driver_event(struct wpa_supplicant *wpa_s, char *cmd)
6220 union wpa_event_data event;
6221 enum wpa_event_type ev;
6223 /* <event name> [parameters..] */
6225 wpa_dbg(wpa_s, MSG_DEBUG, "Testing - external driver event: %s", cmd);
6228 param = os_strchr(pos, ' ');
6232 os_memset(&event, 0, sizeof(event));
6234 if (os_strcmp(cmd, "INTERFACE_ENABLED") == 0) {
6235 ev = EVENT_INTERFACE_ENABLED;
6236 } else if (os_strcmp(cmd, "INTERFACE_DISABLED") == 0) {
6237 ev = EVENT_INTERFACE_DISABLED;
6238 } else if (os_strcmp(cmd, "AVOID_FREQUENCIES") == 0) {
6239 ev = EVENT_AVOID_FREQUENCIES;
6242 if (freq_range_list_parse(&event.freq_range, param) < 0)
6244 wpa_supplicant_event(wpa_s, ev, &event);
6245 os_free(event.freq_range.range);
6248 wpa_dbg(wpa_s, MSG_DEBUG, "Testing - unknown driver event: %s",
6253 wpa_supplicant_event(wpa_s, ev, &event);
6258 #endif /* CONFIG_TESTING_OPTIONS */
6261 static void wpas_ctrl_vendor_elem_update(struct wpa_supplicant *wpa_s)
6266 wpa_printf(MSG_DEBUG, "Update vendor elements");
6268 for (i = 0; i < NUM_VENDOR_ELEM_FRAMES; i++) {
6269 if (wpa_s->vendor_elem[i]) {
6270 os_snprintf(buf, sizeof(buf), "frame[%u]", i);
6271 wpa_hexdump_buf(MSG_DEBUG, buf, wpa_s->vendor_elem[i]);
6276 if (wpa_s->parent == wpa_s &&
6277 wpa_s->global->p2p &&
6278 !wpa_s->global->p2p_disabled)
6279 p2p_set_vendor_elems(wpa_s->global->p2p, wpa_s->vendor_elem);
6280 #endif /* CONFIG_P2P */
6284 static struct wpa_supplicant *
6285 wpas_ctrl_vendor_elem_iface(struct wpa_supplicant *wpa_s,
6286 enum wpa_vendor_elem_frame frame)
6290 case VENDOR_ELEM_PROBE_REQ_P2P:
6291 case VENDOR_ELEM_PROBE_RESP_P2P:
6292 case VENDOR_ELEM_PROBE_RESP_P2P_GO:
6293 case VENDOR_ELEM_BEACON_P2P_GO:
6294 case VENDOR_ELEM_P2P_PD_REQ:
6295 case VENDOR_ELEM_P2P_PD_RESP:
6296 case VENDOR_ELEM_P2P_GO_NEG_REQ:
6297 case VENDOR_ELEM_P2P_GO_NEG_RESP:
6298 case VENDOR_ELEM_P2P_GO_NEG_CONF:
6299 case VENDOR_ELEM_P2P_INV_REQ:
6300 case VENDOR_ELEM_P2P_INV_RESP:
6301 case VENDOR_ELEM_P2P_ASSOC_REQ:
6302 return wpa_s->parent;
6303 #endif /* CONFIG_P2P */
6310 static int wpas_ctrl_vendor_elem_add(struct wpa_supplicant *wpa_s, char *cmd)
6316 struct ieee802_11_elems elems;
6319 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
6321 wpa_s = wpas_ctrl_vendor_elem_iface(wpa_s, frame);
6323 pos = os_strchr(pos, ' ');
6328 len = os_strlen(pos);
6335 buf = wpabuf_alloc(len);
6339 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
6344 if (ieee802_11_parse_elems(wpabuf_head_u8(buf), len, &elems, 0) ==
6350 if (wpa_s->vendor_elem[frame] == NULL) {
6351 wpa_s->vendor_elem[frame] = buf;
6352 wpas_ctrl_vendor_elem_update(wpa_s);
6356 if (wpabuf_resize(&wpa_s->vendor_elem[frame], len) < 0) {
6361 wpabuf_put_buf(wpa_s->vendor_elem[frame], buf);
6363 wpas_ctrl_vendor_elem_update(wpa_s);
6369 static int wpas_ctrl_vendor_elem_get(struct wpa_supplicant *wpa_s, char *cmd,
6370 char *buf, size_t buflen)
6372 int frame = atoi(cmd);
6374 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
6376 wpa_s = wpas_ctrl_vendor_elem_iface(wpa_s, frame);
6378 if (wpa_s->vendor_elem[frame] == NULL)
6381 return wpa_snprintf_hex(buf, buflen,
6382 wpabuf_head_u8(wpa_s->vendor_elem[frame]),
6383 wpabuf_len(wpa_s->vendor_elem[frame]));
6387 static int wpas_ctrl_vendor_elem_remove(struct wpa_supplicant *wpa_s, char *cmd)
6393 struct ieee802_11_elems elems;
6397 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
6399 wpa_s = wpas_ctrl_vendor_elem_iface(wpa_s, frame);
6401 pos = os_strchr(pos, ' ');
6407 wpabuf_free(wpa_s->vendor_elem[frame]);
6408 wpa_s->vendor_elem[frame] = NULL;
6409 wpas_ctrl_vendor_elem_update(wpa_s);
6413 if (wpa_s->vendor_elem[frame] == NULL)
6416 len = os_strlen(pos);
6423 buf = os_malloc(len);
6427 if (hexstr2bin(pos, buf, len) < 0) {
6432 if (ieee802_11_parse_elems(buf, len, &elems, 0) == ParseFailed) {
6437 ie = wpabuf_mhead_u8(wpa_s->vendor_elem[frame]);
6438 end = ie + wpabuf_len(wpa_s->vendor_elem[frame]);
6440 for (; ie + 1 < end; ie += 2 + ie[1]) {
6443 if (os_memcmp(ie, buf, len) != 0)
6446 if (wpabuf_len(wpa_s->vendor_elem[frame]) == len) {
6447 wpabuf_free(wpa_s->vendor_elem[frame]);
6448 wpa_s->vendor_elem[frame] = NULL;
6450 os_memmove(ie, ie + len,
6451 wpabuf_len(wpa_s->vendor_elem[frame]) - len);
6452 wpa_s->vendor_elem[frame]->used -= len;
6455 wpas_ctrl_vendor_elem_update(wpa_s);
6465 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
6466 char *buf, size_t *resp_len)
6469 const int reply_size = 4096;
6472 if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 ||
6473 os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
6474 if (wpa_debug_show_keys)
6475 wpa_dbg(wpa_s, MSG_DEBUG,
6476 "Control interface command '%s'", buf);
6478 wpa_dbg(wpa_s, MSG_DEBUG,
6479 "Control interface command '%s [REMOVED]'",
6480 os_strncmp(buf, WPA_CTRL_RSP,
6481 os_strlen(WPA_CTRL_RSP)) == 0 ?
6482 WPA_CTRL_RSP : "SET_NETWORK");
6483 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ", 16) == 0 ||
6484 os_strncmp(buf, "NFC_REPORT_HANDOVER", 19) == 0) {
6485 wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface",
6486 (const u8 *) buf, os_strlen(buf));
6488 int level = MSG_DEBUG;
6489 if (os_strcmp(buf, "PING") == 0)
6490 level = MSG_EXCESSIVE;
6491 wpa_dbg(wpa_s, level, "Control interface command '%s'", buf);
6494 reply = os_malloc(reply_size);
6495 if (reply == NULL) {
6500 os_memcpy(reply, "OK\n", 3);
6503 if (os_strcmp(buf, "PING") == 0) {
6504 os_memcpy(reply, "PONG\n", 5);
6506 } else if (os_strcmp(buf, "IFNAME") == 0) {
6507 reply_len = os_strlen(wpa_s->ifname);
6508 os_memcpy(reply, wpa_s->ifname, reply_len);
6509 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
6510 if (wpa_debug_reopen_file() < 0)
6512 } else if (os_strncmp(buf, "NOTE ", 5) == 0) {
6513 wpa_printf(MSG_INFO, "NOTE: %s", buf + 5);
6514 } else if (os_strcmp(buf, "MIB") == 0) {
6515 reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size);
6516 if (reply_len >= 0) {
6518 res = eapol_sm_get_mib(wpa_s->eapol, reply + reply_len,
6519 reply_size - reply_len);
6525 } else if (os_strncmp(buf, "STATUS", 6) == 0) {
6526 reply_len = wpa_supplicant_ctrl_iface_status(
6527 wpa_s, buf + 6, reply, reply_size);
6528 } else if (os_strcmp(buf, "PMKSA") == 0) {
6529 reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, reply,
6531 } else if (os_strncmp(buf, "SET ", 4) == 0) {
6532 if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4))
6534 } else if (os_strncmp(buf, "GET ", 4) == 0) {
6535 reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4,
6537 } else if (os_strcmp(buf, "LOGON") == 0) {
6538 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
6539 } else if (os_strcmp(buf, "LOGOFF") == 0) {
6540 eapol_sm_notify_logoff(wpa_s->eapol, TRUE);
6541 } else if (os_strcmp(buf, "REASSOCIATE") == 0) {
6542 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
6545 wpas_request_connection(wpa_s);
6546 } else if (os_strcmp(buf, "REATTACH") == 0) {
6547 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED ||
6548 !wpa_s->current_ssid)
6551 wpa_s->reattach = 1;
6552 wpas_request_connection(wpa_s);
6554 } else if (os_strcmp(buf, "RECONNECT") == 0) {
6555 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
6557 else if (wpa_s->disconnected)
6558 wpas_request_connection(wpa_s);
6559 #ifdef IEEE8021X_EAPOL
6560 } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) {
6561 if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8))
6563 #endif /* IEEE8021X_EAPOL */
6564 #ifdef CONFIG_PEERKEY
6565 } else if (os_strncmp(buf, "STKSTART ", 9) == 0) {
6566 if (wpa_supplicant_ctrl_iface_stkstart(wpa_s, buf + 9))
6568 #endif /* CONFIG_PEERKEY */
6569 #ifdef CONFIG_IEEE80211R
6570 } else if (os_strncmp(buf, "FT_DS ", 6) == 0) {
6571 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6))
6573 #endif /* CONFIG_IEEE80211R */
6575 } else if (os_strcmp(buf, "WPS_PBC") == 0) {
6576 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL);
6578 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
6582 } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) {
6583 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8);
6585 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
6589 } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {
6590 reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8,
6593 } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) {
6594 reply_len = wpa_supplicant_ctrl_iface_wps_check_pin(
6595 wpa_s, buf + 14, reply, reply_size);
6596 } else if (os_strcmp(buf, "WPS_CANCEL") == 0) {
6597 if (wpas_wps_cancel(wpa_s))
6599 #ifdef CONFIG_WPS_NFC
6600 } else if (os_strcmp(buf, "WPS_NFC") == 0) {
6601 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, NULL))
6603 } else if (os_strncmp(buf, "WPS_NFC ", 8) == 0) {
6604 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, buf + 8))
6606 } else if (os_strncmp(buf, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
6607 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_config_token(
6608 wpa_s, buf + 21, reply, reply_size);
6609 } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) {
6610 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_token(
6611 wpa_s, buf + 14, reply, reply_size);
6612 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) {
6613 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s,
6616 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
6617 reply_len = wpas_ctrl_nfc_get_handover_req(
6618 wpa_s, buf + 21, reply, reply_size);
6619 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
6620 reply_len = wpas_ctrl_nfc_get_handover_sel(
6621 wpa_s, buf + 21, reply, reply_size);
6622 } else if (os_strncmp(buf, "NFC_REPORT_HANDOVER ", 20) == 0) {
6623 if (wpas_ctrl_nfc_report_handover(wpa_s, buf + 20))
6625 #endif /* CONFIG_WPS_NFC */
6626 } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) {
6627 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8))
6630 } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) {
6631 reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin(
6632 wpa_s, buf + 11, reply, reply_size);
6633 #endif /* CONFIG_AP */
6634 #ifdef CONFIG_WPS_ER
6635 } else if (os_strcmp(buf, "WPS_ER_START") == 0) {
6636 if (wpas_wps_er_start(wpa_s, NULL))
6638 } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) {
6639 if (wpas_wps_er_start(wpa_s, buf + 13))
6641 } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) {
6642 if (wpas_wps_er_stop(wpa_s))
6644 } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) {
6645 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11))
6647 } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) {
6648 int ret = wpas_wps_er_pbc(wpa_s, buf + 11);
6650 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
6652 } else if (ret == -3) {
6653 os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18);
6655 } else if (ret == -4) {
6656 os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20);
6660 } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) {
6661 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13))
6663 } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) {
6664 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s,
6667 } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) {
6668 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14))
6670 #ifdef CONFIG_WPS_NFC
6671 } else if (os_strncmp(buf, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
6672 reply_len = wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
6673 wpa_s, buf + 24, reply, reply_size);
6674 #endif /* CONFIG_WPS_NFC */
6675 #endif /* CONFIG_WPS_ER */
6676 #endif /* CONFIG_WPS */
6677 #ifdef CONFIG_IBSS_RSN
6678 } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) {
6679 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9))
6681 #endif /* CONFIG_IBSS_RSN */
6683 } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) {
6684 if (p2p_ctrl_find(wpa_s, buf + 9))
6686 } else if (os_strcmp(buf, "P2P_FIND") == 0) {
6687 if (p2p_ctrl_find(wpa_s, ""))
6689 } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) {
6690 wpas_p2p_stop_find(wpa_s);
6691 } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) {
6692 reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply,
6694 } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) {
6695 if (p2p_ctrl_listen(wpa_s, buf + 11))
6697 } else if (os_strcmp(buf, "P2P_LISTEN") == 0) {
6698 if (p2p_ctrl_listen(wpa_s, ""))
6700 } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) {
6701 if (wpas_p2p_group_remove(wpa_s, buf + 17))
6703 } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) {
6704 if (wpas_p2p_group_add(wpa_s, 0, 0, 0, 0))
6706 } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) {
6707 if (p2p_ctrl_group_add(wpa_s, buf + 14))
6709 } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) {
6710 if (p2p_ctrl_prov_disc(wpa_s, buf + 14))
6712 } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) {
6713 reply_len = p2p_get_passphrase(wpa_s, reply, reply_size);
6714 } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) {
6715 reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply,
6717 } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
6718 if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0)
6720 } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) {
6721 if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0)
6723 } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) {
6724 wpas_p2p_sd_service_update(wpa_s);
6725 } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
6726 if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0)
6728 } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) {
6729 wpas_p2p_service_flush(wpa_s);
6730 } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) {
6731 if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0)
6733 } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) {
6734 if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0)
6736 } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) {
6737 if (p2p_ctrl_reject(wpa_s, buf + 11) < 0)
6739 } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) {
6740 if (p2p_ctrl_invite(wpa_s, buf + 11) < 0)
6742 } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) {
6743 reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply,
6745 } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) {
6746 if (p2p_ctrl_set(wpa_s, buf + 8) < 0)
6748 } else if (os_strcmp(buf, "P2P_FLUSH") == 0) {
6749 p2p_ctrl_flush(wpa_s);
6750 } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) {
6751 if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0)
6753 } else if (os_strcmp(buf, "P2P_CANCEL") == 0) {
6754 if (wpas_p2p_cancel(wpa_s))
6756 } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) {
6757 if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0)
6759 } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) {
6760 if (p2p_ctrl_presence_req(wpa_s, "") < 0)
6762 } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) {
6763 if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0)
6765 } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) {
6766 if (p2p_ctrl_ext_listen(wpa_s, "") < 0)
6768 } else if (os_strncmp(buf, "P2P_REMOVE_CLIENT ", 18) == 0) {
6769 if (p2p_ctrl_remove_client(wpa_s, buf + 18) < 0)
6771 #endif /* CONFIG_P2P */
6772 #ifdef CONFIG_WIFI_DISPLAY
6773 } else if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0) {
6774 if (wifi_display_subelem_set(wpa_s->global, buf + 16) < 0)
6776 } else if (os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) {
6777 reply_len = wifi_display_subelem_get(wpa_s->global, buf + 16,
6779 #endif /* CONFIG_WIFI_DISPLAY */
6780 #ifdef CONFIG_INTERWORKING
6781 } else if (os_strcmp(buf, "FETCH_ANQP") == 0) {
6782 if (interworking_fetch_anqp(wpa_s) < 0)
6784 } else if (os_strcmp(buf, "STOP_FETCH_ANQP") == 0) {
6785 interworking_stop_fetch_anqp(wpa_s);
6786 } else if (os_strcmp(buf, "INTERWORKING_SELECT") == 0) {
6787 if (ctrl_interworking_select(wpa_s, NULL) < 0)
6789 } else if (os_strncmp(buf, "INTERWORKING_SELECT ", 20) == 0) {
6790 if (ctrl_interworking_select(wpa_s, buf + 20) < 0)
6792 } else if (os_strncmp(buf, "INTERWORKING_CONNECT ", 21) == 0) {
6793 if (ctrl_interworking_connect(wpa_s, buf + 21) < 0)
6795 } else if (os_strncmp(buf, "ANQP_GET ", 9) == 0) {
6796 if (get_anqp(wpa_s, buf + 9) < 0)
6798 } else if (os_strncmp(buf, "GAS_REQUEST ", 12) == 0) {
6799 if (gas_request(wpa_s, buf + 12) < 0)
6801 } else if (os_strncmp(buf, "GAS_RESPONSE_GET ", 17) == 0) {
6802 reply_len = gas_response_get(wpa_s, buf + 17, reply,
6804 #endif /* CONFIG_INTERWORKING */
6806 } else if (os_strncmp(buf, "HS20_ANQP_GET ", 14) == 0) {
6807 if (get_hs20_anqp(wpa_s, buf + 14) < 0)
6809 } else if (os_strncmp(buf, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
6810 if (hs20_get_nai_home_realm_list(wpa_s, buf + 29) < 0)
6812 } else if (os_strncmp(buf, "HS20_ICON_REQUEST ", 18) == 0) {
6813 if (hs20_icon_request(wpa_s, buf + 18) < 0)
6815 } else if (os_strcmp(buf, "FETCH_OSU") == 0) {
6816 if (hs20_fetch_osu(wpa_s) < 0)
6818 } else if (os_strcmp(buf, "CANCEL_FETCH_OSU") == 0) {
6819 hs20_cancel_fetch_osu(wpa_s);
6820 #endif /* CONFIG_HS20 */
6821 } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0)
6823 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
6824 wpa_s, buf + os_strlen(WPA_CTRL_RSP)))
6828 * Notify response from timeout to allow the control
6829 * interface response to be sent first.
6831 eloop_register_timeout(0, 0, wpas_ctrl_eapol_response,
6834 } else if (os_strcmp(buf, "RECONFIGURE") == 0) {
6835 if (wpa_supplicant_reload_configuration(wpa_s))
6837 } else if (os_strcmp(buf, "TERMINATE") == 0) {
6838 wpa_supplicant_terminate_proc(wpa_s->global);
6839 } else if (os_strncmp(buf, "BSSID ", 6) == 0) {
6840 if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6))
6842 } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) {
6843 reply_len = wpa_supplicant_ctrl_iface_blacklist(
6844 wpa_s, buf + 9, reply, reply_size);
6845 } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) {
6846 reply_len = wpa_supplicant_ctrl_iface_log_level(
6847 wpa_s, buf + 9, reply, reply_size);
6848 } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) {
6849 reply_len = wpa_supplicant_ctrl_iface_list_networks(
6850 wpa_s, reply, reply_size);
6851 } else if (os_strcmp(buf, "DISCONNECT") == 0) {
6853 wpa_s->sme.prev_bssid_set = 0;
6854 #endif /* CONFIG_SME */
6855 wpa_s->reassociate = 0;
6856 wpa_s->disconnected = 1;
6857 wpa_supplicant_cancel_sched_scan(wpa_s);
6858 wpa_supplicant_cancel_scan(wpa_s);
6859 wpa_supplicant_deauthenticate(wpa_s,
6860 WLAN_REASON_DEAUTH_LEAVING);
6861 } else if (os_strcmp(buf, "SCAN") == 0) {
6862 wpas_ctrl_scan(wpa_s, NULL, reply, reply_size, &reply_len);
6863 } else if (os_strncmp(buf, "SCAN ", 5) == 0) {
6864 wpas_ctrl_scan(wpa_s, buf + 5, reply, reply_size, &reply_len);
6865 } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) {
6866 reply_len = wpa_supplicant_ctrl_iface_scan_results(
6867 wpa_s, reply, reply_size);
6868 } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) {
6869 if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15))
6871 } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) {
6872 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15))
6874 } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) {
6875 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16))
6877 } else if (os_strcmp(buf, "ADD_NETWORK") == 0) {
6878 reply_len = wpa_supplicant_ctrl_iface_add_network(
6879 wpa_s, reply, reply_size);
6880 } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) {
6881 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15))
6883 } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
6884 if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12))
6886 } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) {
6887 reply_len = wpa_supplicant_ctrl_iface_get_network(
6888 wpa_s, buf + 12, reply, reply_size);
6889 } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) {
6890 if (wpa_supplicant_ctrl_iface_dup_network(wpa_s, buf + 12))
6892 } else if (os_strcmp(buf, "LIST_CREDS") == 0) {
6893 reply_len = wpa_supplicant_ctrl_iface_list_creds(
6894 wpa_s, reply, reply_size);
6895 } else if (os_strcmp(buf, "ADD_CRED") == 0) {
6896 reply_len = wpa_supplicant_ctrl_iface_add_cred(
6897 wpa_s, reply, reply_size);
6898 } else if (os_strncmp(buf, "REMOVE_CRED ", 12) == 0) {
6899 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s, buf + 12))
6901 } else if (os_strncmp(buf, "SET_CRED ", 9) == 0) {
6902 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s, buf + 9))
6904 } else if (os_strncmp(buf, "GET_CRED ", 9) == 0) {
6905 reply_len = wpa_supplicant_ctrl_iface_get_cred(wpa_s, buf + 9,
6908 #ifndef CONFIG_NO_CONFIG_WRITE
6909 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
6910 if (wpa_supplicant_ctrl_iface_save_config(wpa_s))
6912 #endif /* CONFIG_NO_CONFIG_WRITE */
6913 } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
6914 reply_len = wpa_supplicant_ctrl_iface_get_capability(
6915 wpa_s, buf + 15, reply, reply_size);
6916 } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) {
6917 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8))
6919 } else if (os_strncmp(buf, "SCAN_INTERVAL ", 14) == 0) {
6920 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s, buf + 14))
6922 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
6923 reply_len = wpa_supplicant_global_iface_list(
6924 wpa_s->global, reply, reply_size);
6925 } else if (os_strcmp(buf, "INTERFACES") == 0) {
6926 reply_len = wpa_supplicant_global_iface_interfaces(
6927 wpa_s->global, reply, reply_size);
6928 } else if (os_strncmp(buf, "BSS ", 4) == 0) {
6929 reply_len = wpa_supplicant_ctrl_iface_bss(
6930 wpa_s, buf + 4, reply, reply_size);
6932 } else if (os_strcmp(buf, "STA-FIRST") == 0) {
6933 reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size);
6934 } else if (os_strncmp(buf, "STA ", 4) == 0) {
6935 reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply,
6937 } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) {
6938 reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply,
6940 } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) {
6941 if (ap_ctrl_iface_sta_deauthenticate(wpa_s, buf + 15))
6943 } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) {
6944 if (ap_ctrl_iface_sta_disassociate(wpa_s, buf + 13))
6946 } else if (os_strncmp(buf, "CHAN_SWITCH ", 12) == 0) {
6947 if (ap_ctrl_iface_chanswitch(wpa_s, buf + 12))
6949 #endif /* CONFIG_AP */
6950 } else if (os_strcmp(buf, "SUSPEND") == 0) {
6951 wpas_notify_suspend(wpa_s->global);
6952 } else if (os_strcmp(buf, "RESUME") == 0) {
6953 wpas_notify_resume(wpa_s->global);
6954 #ifdef CONFIG_TESTING_OPTIONS
6955 } else if (os_strcmp(buf, "DROP_SA") == 0) {
6956 wpa_supplicant_ctrl_iface_drop_sa(wpa_s);
6957 #endif /* CONFIG_TESTING_OPTIONS */
6958 } else if (os_strncmp(buf, "ROAM ", 5) == 0) {
6959 if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5))
6961 } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) {
6962 if (wpa_supplicant_ctrl_iface_sta_autoconnect(wpa_s, buf + 16))
6964 } else if (os_strncmp(buf, "BSS_EXPIRE_AGE ", 15) == 0) {
6965 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s, buf + 15))
6967 } else if (os_strncmp(buf, "BSS_EXPIRE_COUNT ", 17) == 0) {
6968 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s,
6971 } else if (os_strncmp(buf, "BSS_FLUSH ", 10) == 0) {
6972 if (wpa_supplicant_ctrl_iface_bss_flush(wpa_s, buf + 10))
6975 } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) {
6976 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14))
6978 } else if (os_strncmp(buf, "TDLS_SETUP ", 11) == 0) {
6979 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s, buf + 11))
6981 } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) {
6982 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14))
6984 #endif /* CONFIG_TDLS */
6985 } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) {
6986 reply_len = wpa_supplicant_signal_poll(wpa_s, reply,
6988 } else if (os_strncmp(buf, "PKTCNT_POLL", 11) == 0) {
6989 reply_len = wpa_supplicant_pktcnt_poll(wpa_s, reply,
6991 #ifdef CONFIG_AUTOSCAN
6992 } else if (os_strncmp(buf, "AUTOSCAN ", 9) == 0) {
6993 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s, buf + 9))
6995 #endif /* CONFIG_AUTOSCAN */
6997 } else if (os_strncmp(buf, "DRIVER ", 7) == 0) {
6998 reply_len = wpa_supplicant_driver_cmd(wpa_s, buf + 7, reply,
7000 #endif /* ANDROID */
7001 } else if (os_strncmp(buf, "VENDOR ", 7) == 0) {
7002 reply_len = wpa_supplicant_vendor_cmd(wpa_s, buf + 7, reply,
7004 } else if (os_strcmp(buf, "REAUTHENTICATE") == 0) {
7005 pmksa_cache_clear_current(wpa_s->wpa);
7006 eapol_sm_request_reauth(wpa_s->eapol);
7008 } else if (os_strncmp(buf, "WNM_SLEEP ", 10) == 0) {
7009 if (wpas_ctrl_iface_wnm_sleep(wpa_s, buf + 10))
7011 } else if (os_strncmp(buf, "WNM_BSS_QUERY ", 10) == 0) {
7012 if (wpas_ctrl_iface_wnm_bss_query(wpa_s, buf + 10))
7014 #endif /* CONFIG_WNM */
7015 } else if (os_strcmp(buf, "FLUSH") == 0) {
7016 wpa_supplicant_ctrl_iface_flush(wpa_s);
7017 } else if (os_strncmp(buf, "RADIO_WORK ", 11) == 0) {
7018 reply_len = wpas_ctrl_radio_work(wpa_s, buf + 11, reply,
7020 #ifdef CONFIG_TESTING_OPTIONS
7021 } else if (os_strncmp(buf, "MGMT_TX ", 8) == 0) {
7022 if (wpas_ctrl_iface_mgmt_tx(wpa_s, buf + 8) < 0)
7024 } else if (os_strcmp(buf, "MGMT_TX_DONE") == 0) {
7025 wpas_ctrl_iface_mgmt_tx_done(wpa_s);
7026 } else if (os_strncmp(buf, "DRIVER_EVENT ", 13) == 0) {
7027 if (wpas_ctrl_iface_driver_event(wpa_s, buf + 13) < 0)
7029 #endif /* CONFIG_TESTING_OPTIONS */
7030 } else if (os_strncmp(buf, "VENDOR_ELEM_ADD ", 16) == 0) {
7031 if (wpas_ctrl_vendor_elem_add(wpa_s, buf + 16) < 0)
7033 } else if (os_strncmp(buf, "VENDOR_ELEM_GET ", 16) == 0) {
7034 reply_len = wpas_ctrl_vendor_elem_get(wpa_s, buf + 16, reply,
7036 } else if (os_strncmp(buf, "VENDOR_ELEM_REMOVE ", 19) == 0) {
7037 if (wpas_ctrl_vendor_elem_remove(wpa_s, buf + 19) < 0)
7040 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
7044 if (reply_len < 0) {
7045 os_memcpy(reply, "FAIL\n", 5);
7049 *resp_len = reply_len;
7054 static int wpa_supplicant_global_iface_add(struct wpa_global *global,
7057 struct wpa_interface iface;
7061 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
7062 * TAB<bridge_ifname>
7064 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd);
7066 os_memset(&iface, 0, sizeof(iface));
7069 iface.ifname = pos = cmd;
7070 pos = os_strchr(pos, '\t');
7073 if (iface.ifname[0] == '\0')
7078 iface.confname = pos;
7079 pos = os_strchr(pos, '\t');
7082 if (iface.confname[0] == '\0')
7083 iface.confname = NULL;
7088 pos = os_strchr(pos, '\t');
7091 if (iface.driver[0] == '\0')
7092 iface.driver = NULL;
7096 iface.ctrl_interface = pos;
7097 pos = os_strchr(pos, '\t');
7100 if (iface.ctrl_interface[0] == '\0')
7101 iface.ctrl_interface = NULL;
7105 iface.driver_param = pos;
7106 pos = os_strchr(pos, '\t');
7109 if (iface.driver_param[0] == '\0')
7110 iface.driver_param = NULL;
7114 iface.bridge_ifname = pos;
7115 pos = os_strchr(pos, '\t');
7118 if (iface.bridge_ifname[0] == '\0')
7119 iface.bridge_ifname = NULL;
7124 if (wpa_supplicant_get_iface(global, iface.ifname))
7127 return wpa_supplicant_add_iface(global, &iface) ? 0 : -1;
7131 static int wpa_supplicant_global_iface_remove(struct wpa_global *global,
7134 struct wpa_supplicant *wpa_s;
7136 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd);
7138 wpa_s = wpa_supplicant_get_iface(global, cmd);
7141 return wpa_supplicant_remove_iface(global, wpa_s, 0);
7145 static void wpa_free_iface_info(struct wpa_interface_info *iface)
7147 struct wpa_interface_info *prev;
7151 iface = iface->next;
7153 os_free(prev->ifname);
7154 os_free(prev->desc);
7160 static int wpa_supplicant_global_iface_list(struct wpa_global *global,
7164 struct wpa_interface_info *iface = NULL, *last = NULL, *tmp;
7167 for (i = 0; wpa_drivers[i]; i++) {
7168 struct wpa_driver_ops *drv = wpa_drivers[i];
7169 if (drv->get_interfaces == NULL)
7171 tmp = drv->get_interfaces(global->drv_priv[i]);
7185 for (tmp = iface; tmp; tmp = tmp->next) {
7186 res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n",
7187 tmp->drv_name, tmp->ifname,
7188 tmp->desc ? tmp->desc : "");
7189 if (res < 0 || res >= end - pos) {
7196 wpa_free_iface_info(iface);
7202 static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
7207 struct wpa_supplicant *wpa_s;
7209 wpa_s = global->ifaces;
7214 res = os_snprintf(pos, end - pos, "%s\n", wpa_s->ifname);
7215 if (res < 0 || res >= end - pos) {
7220 wpa_s = wpa_s->next;
7226 static char * wpas_global_ctrl_iface_ifname(struct wpa_global *global,
7228 char *cmd, size_t *resp_len)
7230 struct wpa_supplicant *wpa_s;
7232 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
7233 if (os_strcmp(ifname, wpa_s->ifname) == 0)
7237 if (wpa_s == NULL) {
7238 char *resp = os_strdup("FAIL-NO-IFNAME-MATCH\n");
7240 *resp_len = os_strlen(resp);
7246 return wpa_supplicant_ctrl_iface_process(wpa_s, cmd, resp_len);
7250 static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global *global,
7251 char *buf, size_t *resp_len)
7254 static const char * cmd[] = {
7260 "P2P_GET_PASSPHRASE",
7261 "P2P_SERVICE_UPDATE",
7262 "P2P_SERVICE_FLUSH",
7269 static const char * prefix[] = {
7272 #endif /* ANDROID */
7278 "P2P_GROUP_REMOVE ",
7281 "P2P_SERV_DISC_REQ ",
7282 "P2P_SERV_DISC_CANCEL_REQ ",
7283 "P2P_SERV_DISC_RESP ",
7284 "P2P_SERV_DISC_EXTERNAL ",
7292 "P2P_PRESENCE_REQ ",
7294 "P2P_REMOVE_CLIENT ",
7295 "NFC_GET_HANDOVER_SEL ",
7296 "NFC_GET_HANDOVER_REQ ",
7297 "NFC_REPORT_HANDOVER ",
7303 if (global->p2p_init_wpa_s == NULL)
7306 for (i = 0; !found && cmd[i]; i++) {
7307 if (os_strcmp(buf, cmd[i]) == 0)
7311 for (i = 0; !found && prefix[i]; i++) {
7312 if (os_strncmp(buf, prefix[i], os_strlen(prefix[i])) == 0)
7317 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
7319 #endif /* CONFIG_P2P */
7324 static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global *global,
7325 char *buf, size_t *resp_len)
7327 #ifdef CONFIG_WIFI_DISPLAY
7328 if (global->p2p_init_wpa_s == NULL)
7330 if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0 ||
7331 os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0)
7332 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
7334 #endif /* CONFIG_WIFI_DISPLAY */
7339 static char * wpas_global_ctrl_iface_redir(struct wpa_global *global,
7340 char *buf, size_t *resp_len)
7344 ret = wpas_global_ctrl_iface_redir_p2p(global, buf, resp_len);
7348 ret = wpas_global_ctrl_iface_redir_wfd(global, buf, resp_len);
7356 static int wpas_global_ctrl_iface_set(struct wpa_global *global, char *cmd)
7360 value = os_strchr(cmd, ' ');
7365 wpa_printf(MSG_DEBUG, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd, value);
7367 #ifdef CONFIG_WIFI_DISPLAY
7368 if (os_strcasecmp(cmd, "wifi_display") == 0) {
7369 wifi_display_enable(global, !!atoi(value));
7372 #endif /* CONFIG_WIFI_DISPLAY */
7374 /* Restore cmd to its original value to allow redirection */
7381 #ifndef CONFIG_NO_CONFIG_WRITE
7382 static int wpas_global_ctrl_iface_save_config(struct wpa_global *global)
7384 int ret = 0, saved = 0;
7385 struct wpa_supplicant *wpa_s;
7387 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
7388 if (!wpa_s->conf->update_config) {
7389 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
7393 if (wpa_config_write(wpa_s->confname, wpa_s->conf)) {
7394 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
7397 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
7402 if (!saved && !ret) {
7403 wpa_dbg(wpa_s, MSG_DEBUG,
7404 "CTRL_IFACE: SAVE_CONFIG - No configuration files could be updated");
7410 #endif /* CONFIG_NO_CONFIG_WRITE */
7413 static int wpas_global_ctrl_iface_status(struct wpa_global *global,
7414 char *buf, size_t buflen)
7418 struct wpa_supplicant *wpa_s;
7424 if (global->p2p && !global->p2p_disabled) {
7425 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
7428 MAC2STR(global->p2p_dev_addr),
7429 p2p_get_state_txt(global->p2p));
7430 if (ret < 0 || ret >= end - pos)
7433 } else if (global->p2p) {
7434 ret = os_snprintf(pos, end - pos, "p2p_state=DISABLED\n");
7435 if (ret < 0 || ret >= end - pos)
7439 #endif /* CONFIG_P2P */
7441 #ifdef CONFIG_WIFI_DISPLAY
7442 ret = os_snprintf(pos, end - pos, "wifi_display=%d\n",
7443 !!global->wifi_display);
7444 if (ret < 0 || ret >= end - pos)
7447 #endif /* CONFIG_WIFI_DISPLAY */
7449 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
7450 ret = os_snprintf(pos, end - pos, "ifname=%s\n"
7451 "address=" MACSTR "\n",
7452 wpa_s->ifname, MAC2STR(wpa_s->own_addr));
7453 if (ret < 0 || ret >= end - pos)
7462 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
7463 char *buf, size_t *resp_len)
7466 const int reply_size = 2048;
7468 int level = MSG_DEBUG;
7470 if (os_strncmp(buf, "IFNAME=", 7) == 0) {
7471 char *pos = os_strchr(buf + 7, ' ');
7474 return wpas_global_ctrl_iface_ifname(global,
7480 reply = wpas_global_ctrl_iface_redir(global, buf, resp_len);
7484 if (os_strcmp(buf, "PING") == 0)
7485 level = MSG_EXCESSIVE;
7486 wpa_hexdump_ascii(level, "RX global ctrl_iface",
7487 (const u8 *) buf, os_strlen(buf));
7489 reply = os_malloc(reply_size);
7490 if (reply == NULL) {
7495 os_memcpy(reply, "OK\n", 3);
7498 if (os_strcmp(buf, "PING") == 0) {
7499 os_memcpy(reply, "PONG\n", 5);
7501 } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) {
7502 if (wpa_supplicant_global_iface_add(global, buf + 14))
7504 } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) {
7505 if (wpa_supplicant_global_iface_remove(global, buf + 17))
7507 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
7508 reply_len = wpa_supplicant_global_iface_list(
7509 global, reply, reply_size);
7510 } else if (os_strcmp(buf, "INTERFACES") == 0) {
7511 reply_len = wpa_supplicant_global_iface_interfaces(
7512 global, reply, reply_size);
7513 } else if (os_strcmp(buf, "TERMINATE") == 0) {
7514 wpa_supplicant_terminate_proc(global);
7515 } else if (os_strcmp(buf, "SUSPEND") == 0) {
7516 wpas_notify_suspend(global);
7517 } else if (os_strcmp(buf, "RESUME") == 0) {
7518 wpas_notify_resume(global);
7519 } else if (os_strncmp(buf, "SET ", 4) == 0) {
7520 if (wpas_global_ctrl_iface_set(global, buf + 4)) {
7522 if (global->p2p_init_wpa_s) {
7524 /* Check if P2P redirection would work for this
7526 return wpa_supplicant_ctrl_iface_process(
7527 global->p2p_init_wpa_s,
7530 #endif /* CONFIG_P2P */
7533 #ifndef CONFIG_NO_CONFIG_WRITE
7534 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
7535 if (wpas_global_ctrl_iface_save_config(global))
7537 #endif /* CONFIG_NO_CONFIG_WRITE */
7538 } else if (os_strcmp(buf, "STATUS") == 0) {
7539 reply_len = wpas_global_ctrl_iface_status(global, reply,
7541 #ifdef CONFIG_MODULE_TESTS
7542 } else if (os_strcmp(buf, "MODULE_TESTS") == 0) {
7543 int wpas_module_tests(void);
7544 if (wpas_module_tests() < 0)
7546 #endif /* CONFIG_MODULE_TESTS */
7548 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
7552 if (reply_len < 0) {
7553 os_memcpy(reply, "FAIL\n", 5);
7557 *resp_len = reply_len;