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"
44 #include "drivers/driver.h"
46 static int wpa_supplicant_global_iface_list(struct wpa_global *global,
48 static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
50 static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s,
53 static int set_bssid_filter(struct wpa_supplicant *wpa_s, char *val)
56 u8 addr[ETH_ALEN], *filter = NULL, *n;
63 if (hwaddr_aton(pos, addr)) {
67 n = os_realloc_array(filter, count + 1, ETH_ALEN);
73 os_memcpy(filter + count * ETH_ALEN, addr, ETH_ALEN);
76 pos = os_strchr(pos, ' ');
81 wpa_hexdump(MSG_DEBUG, "bssid_filter", filter, count * ETH_ALEN);
82 os_free(wpa_s->bssid_filter);
83 wpa_s->bssid_filter = filter;
84 wpa_s->bssid_filter_count = count;
90 static int set_disallow_aps(struct wpa_supplicant *wpa_s, char *val)
93 u8 addr[ETH_ALEN], *bssid = NULL, *n;
94 struct wpa_ssid_value *ssid = NULL, *ns;
95 size_t count = 0, ssid_count = 0;
99 * disallow_list ::= <ssid_spec> | <bssid_spec> | <disallow_list> | ""
100 * SSID_SPEC ::= ssid <SSID_HEX>
101 * BSSID_SPEC ::= bssid <BSSID_HEX>
108 if (os_strncmp(pos, "bssid ", 6) == 0) {
111 res = hwaddr_aton2(pos, addr);
115 wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
116 "BSSID value '%s'", pos);
120 n = os_realloc_array(bssid, count + 1, ETH_ALEN);
127 os_memcpy(bssid + count * ETH_ALEN, addr, ETH_ALEN);
129 } else if (os_strncmp(pos, "ssid ", 5) == 0) {
135 if (*end == '\0' || *end == ' ')
140 ns = os_realloc_array(ssid, ssid_count + 1,
141 sizeof(struct wpa_ssid_value));
149 if ((end - pos) & 0x01 || end - pos > 2 * 32 ||
150 hexstr2bin(pos, ssid[ssid_count].ssid,
151 (end - pos) / 2) < 0) {
154 wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
155 "SSID value '%s'", pos);
158 ssid[ssid_count].ssid_len = (end - pos) / 2;
159 wpa_hexdump_ascii(MSG_DEBUG, "disallow_aps SSID",
160 ssid[ssid_count].ssid,
161 ssid[ssid_count].ssid_len);
165 wpa_printf(MSG_DEBUG, "Unexpected disallow_aps value "
172 pos = os_strchr(pos, ' ');
177 wpa_hexdump(MSG_DEBUG, "disallow_aps_bssid", bssid, count * ETH_ALEN);
178 os_free(wpa_s->disallow_aps_bssid);
179 wpa_s->disallow_aps_bssid = bssid;
180 wpa_s->disallow_aps_bssid_count = count;
182 wpa_printf(MSG_DEBUG, "disallow_aps_ssid_count %d", (int) ssid_count);
183 os_free(wpa_s->disallow_aps_ssid);
184 wpa_s->disallow_aps_ssid = ssid;
185 wpa_s->disallow_aps_ssid_count = ssid_count;
187 if (!wpa_s->current_ssid || wpa_s->wpa_state < WPA_AUTHENTICATING)
190 c = wpa_s->current_ssid;
191 if (c->mode != WPAS_MODE_INFRA && c->mode != WPAS_MODE_IBSS)
194 if (!disallowed_bssid(wpa_s, wpa_s->bssid) &&
195 !disallowed_ssid(wpa_s, c->ssid, c->ssid_len))
198 wpa_printf(MSG_DEBUG, "Disconnect and try to find another network "
199 "because current AP was marked disallowed");
202 wpa_s->sme.prev_bssid_set = 0;
203 #endif /* CONFIG_SME */
204 wpa_s->reassociate = 1;
205 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
206 wpa_supplicant_req_scan(wpa_s, 0, 0);
212 #ifndef CONFIG_NO_CONFIG_BLOBS
213 static int wpas_ctrl_set_blob(struct wpa_supplicant *wpa_s, char *pos)
216 struct wpa_config_blob *blob;
219 pos = os_strchr(pos, ' ');
223 len = os_strlen(pos);
227 wpa_printf(MSG_DEBUG, "CTRL: Set blob '%s'", name);
228 blob = os_zalloc(sizeof(*blob));
231 blob->name = os_strdup(name);
232 blob->data = os_malloc(len / 2);
233 if (blob->name == NULL || blob->data == NULL) {
234 wpa_config_free_blob(blob);
238 if (hexstr2bin(pos, blob->data, len / 2) < 0) {
239 wpa_printf(MSG_DEBUG, "CTRL: Invalid blob hex data");
240 wpa_config_free_blob(blob);
245 wpa_config_set_blob(wpa_s->conf, blob);
249 #endif /* CONFIG_NO_CONFIG_BLOBS */
252 static int wpas_ctrl_pno(struct wpa_supplicant *wpa_s, char *cmd)
260 params = os_strchr(cmd, ' ');
261 os_free(wpa_s->manual_sched_scan_freqs);
264 pos = os_strstr(params, "freq=");
266 freqs = freq_range_to_channel_list(wpa_s,
269 wpa_s->manual_sched_scan_freqs = freqs;
270 ret = wpas_start_pno(wpa_s);
272 ret = wpas_stop_pno(wpa_s);
278 static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s,
284 value = os_strchr(cmd, ' ');
289 wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value);
290 if (os_strcasecmp(cmd, "EAPOL::heldPeriod") == 0) {
291 eapol_sm_configure(wpa_s->eapol,
292 atoi(value), -1, -1, -1);
293 } else if (os_strcasecmp(cmd, "EAPOL::authPeriod") == 0) {
294 eapol_sm_configure(wpa_s->eapol,
295 -1, atoi(value), -1, -1);
296 } else if (os_strcasecmp(cmd, "EAPOL::startPeriod") == 0) {
297 eapol_sm_configure(wpa_s->eapol,
298 -1, -1, atoi(value), -1);
299 } else if (os_strcasecmp(cmd, "EAPOL::maxStart") == 0) {
300 eapol_sm_configure(wpa_s->eapol,
301 -1, -1, -1, atoi(value));
302 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKLifetime") == 0) {
303 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME,
306 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKReauthThreshold") ==
308 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD,
311 } else if (os_strcasecmp(cmd, "dot11RSNAConfigSATimeout") == 0) {
312 if (wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, atoi(value)))
314 } else if (os_strcasecmp(cmd, "wps_fragment_size") == 0) {
315 wpa_s->wps_fragment_size = atoi(value);
316 #ifdef CONFIG_WPS_TESTING
317 } else if (os_strcasecmp(cmd, "wps_version_number") == 0) {
319 val = strtol(value, NULL, 0);
320 if (val < 0 || val > 0xff) {
322 wpa_printf(MSG_DEBUG, "WPS: Invalid "
323 "wps_version_number %ld", val);
325 wps_version_number = val;
326 wpa_printf(MSG_DEBUG, "WPS: Testing - force WPS "
328 (wps_version_number & 0xf0) >> 4,
329 wps_version_number & 0x0f);
331 } else if (os_strcasecmp(cmd, "wps_testing_dummy_cred") == 0) {
332 wps_testing_dummy_cred = atoi(value);
333 wpa_printf(MSG_DEBUG, "WPS: Testing - dummy_cred=%d",
334 wps_testing_dummy_cred);
335 } else if (os_strcasecmp(cmd, "wps_corrupt_pkhash") == 0) {
336 wps_corrupt_pkhash = atoi(value);
337 wpa_printf(MSG_DEBUG, "WPS: Testing - wps_corrupt_pkhash=%d",
339 #endif /* CONFIG_WPS_TESTING */
340 } else if (os_strcasecmp(cmd, "ampdu") == 0) {
341 if (wpa_drv_ampdu(wpa_s, atoi(value)) < 0)
344 #ifdef CONFIG_TDLS_TESTING
345 } else if (os_strcasecmp(cmd, "tdls_testing") == 0) {
346 extern unsigned int tdls_testing;
347 tdls_testing = strtol(value, NULL, 0);
348 wpa_printf(MSG_DEBUG, "TDLS: tdls_testing=0x%x", tdls_testing);
349 #endif /* CONFIG_TDLS_TESTING */
350 } else if (os_strcasecmp(cmd, "tdls_disabled") == 0) {
351 int disabled = atoi(value);
352 wpa_printf(MSG_DEBUG, "TDLS: tdls_disabled=%d", disabled);
354 if (wpa_drv_tdls_oper(wpa_s, TDLS_DISABLE, NULL) < 0)
356 } else if (wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL) < 0)
358 wpa_tdls_enable(wpa_s->wpa, !disabled);
359 #endif /* CONFIG_TDLS */
360 } else if (os_strcasecmp(cmd, "pno") == 0) {
361 ret = wpas_ctrl_pno(wpa_s, value);
362 } else if (os_strcasecmp(cmd, "radio_disabled") == 0) {
363 int disabled = atoi(value);
364 if (wpa_drv_radio_disable(wpa_s, disabled) < 0)
367 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
368 } else if (os_strcasecmp(cmd, "uapsd") == 0) {
369 if (os_strcmp(value, "disable") == 0)
370 wpa_s->set_sta_uapsd = 0;
374 /* format: BE,BK,VI,VO;max SP Length */
376 pos = os_strchr(value, ',');
381 pos = os_strchr(pos, ',');
386 pos = os_strchr(pos, ',');
391 /* ignore max SP Length for now */
393 wpa_s->set_sta_uapsd = 1;
394 wpa_s->sta_uapsd = 0;
396 wpa_s->sta_uapsd |= BIT(0);
398 wpa_s->sta_uapsd |= BIT(1);
400 wpa_s->sta_uapsd |= BIT(2);
402 wpa_s->sta_uapsd |= BIT(3);
404 } else if (os_strcasecmp(cmd, "ps") == 0) {
405 ret = wpa_drv_set_p2p_powersave(wpa_s, atoi(value), -1, -1);
406 #ifdef CONFIG_WIFI_DISPLAY
407 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
408 int enabled = !!atoi(value);
409 if (enabled && !wpa_s->global->p2p)
412 wifi_display_enable(wpa_s->global, enabled);
413 #endif /* CONFIG_WIFI_DISPLAY */
414 } else if (os_strcasecmp(cmd, "bssid_filter") == 0) {
415 ret = set_bssid_filter(wpa_s, value);
416 } else if (os_strcasecmp(cmd, "disallow_aps") == 0) {
417 ret = set_disallow_aps(wpa_s, value);
418 } else if (os_strcasecmp(cmd, "no_keep_alive") == 0) {
419 wpa_s->no_keep_alive = !!atoi(value);
420 #ifdef CONFIG_TESTING_OPTIONS
421 } else if (os_strcasecmp(cmd, "ext_mgmt_frame_handling") == 0) {
422 wpa_s->ext_mgmt_frame_handling = !!atoi(value);
423 #endif /* CONFIG_TESTING_OPTIONS */
424 #ifndef CONFIG_NO_CONFIG_BLOBS
425 } else if (os_strcmp(cmd, "blob") == 0) {
426 ret = wpas_ctrl_set_blob(wpa_s, value);
427 #endif /* CONFIG_NO_CONFIG_BLOBS */
430 ret = wpa_config_process_global(wpa_s->conf, cmd, -1);
432 wpa_supplicant_update_config(wpa_s);
439 static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s,
440 char *cmd, char *buf, size_t buflen)
444 wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd);
446 if (os_strcmp(cmd, "version") == 0) {
447 res = os_snprintf(buf, buflen, "%s", VERSION_STR);
448 } else if (os_strcasecmp(cmd, "country") == 0) {
449 if (wpa_s->conf->country[0] && wpa_s->conf->country[1])
450 res = os_snprintf(buf, buflen, "%c%c",
451 wpa_s->conf->country[0],
452 wpa_s->conf->country[1]);
453 #ifdef CONFIG_WIFI_DISPLAY
454 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
456 if (wpa_s->global->p2p == NULL ||
457 wpa_s->global->p2p_disabled)
460 enabled = wpa_s->global->wifi_display;
461 res = os_snprintf(buf, buflen, "%d", enabled);
462 if (res < 0 || (unsigned int) res >= buflen)
465 #endif /* CONFIG_WIFI_DISPLAY */
466 #ifdef CONFIG_TESTING_GET_GTK
467 } else if (os_strcmp(cmd, "gtk") == 0) {
468 if (wpa_s->last_gtk_len == 0)
470 res = wpa_snprintf_hex(buf, buflen, wpa_s->last_gtk,
471 wpa_s->last_gtk_len);
473 #endif /* CONFIG_TESTING_GET_GTK */
476 if (res < 0 || (unsigned int) res >= buflen)
482 #ifdef IEEE8021X_EAPOL
483 static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s,
487 struct wpa_ssid *ssid = wpa_s->current_ssid;
489 if (hwaddr_aton(addr, bssid)) {
490 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address "
495 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid));
496 rsn_preauth_deinit(wpa_s->wpa);
497 if (rsn_preauth_init(wpa_s->wpa, bssid, ssid ? &ssid->eap : NULL))
502 #endif /* IEEE8021X_EAPOL */
505 #ifdef CONFIG_PEERKEY
506 /* MLME-STKSTART.request(peer) */
507 static int wpa_supplicant_ctrl_iface_stkstart(
508 struct wpa_supplicant *wpa_s, char *addr)
512 if (hwaddr_aton(addr, peer)) {
513 wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART: invalid "
514 "address '%s'", addr);
518 wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART " MACSTR,
521 return wpa_sm_stkstart(wpa_s->wpa, peer);
523 #endif /* CONFIG_PEERKEY */
528 static int wpa_supplicant_ctrl_iface_tdls_discover(
529 struct wpa_supplicant *wpa_s, char *addr)
534 if (hwaddr_aton(addr, peer)) {
535 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER: invalid "
536 "address '%s'", addr);
540 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER " MACSTR,
543 if (wpa_tdls_is_external_setup(wpa_s->wpa))
544 ret = wpa_tdls_send_discovery_request(wpa_s->wpa, peer);
546 ret = wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer);
552 static int wpa_supplicant_ctrl_iface_tdls_setup(
553 struct wpa_supplicant *wpa_s, char *addr)
558 if (hwaddr_aton(addr, peer)) {
559 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP: invalid "
560 "address '%s'", addr);
564 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP " MACSTR,
567 if ((wpa_s->conf->tdls_external_control) &&
568 wpa_tdls_is_external_setup(wpa_s->wpa))
569 return wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
571 wpa_tdls_remove(wpa_s->wpa, peer);
573 if (wpa_tdls_is_external_setup(wpa_s->wpa))
574 ret = wpa_tdls_start(wpa_s->wpa, peer);
576 ret = wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
582 static int wpa_supplicant_ctrl_iface_tdls_teardown(
583 struct wpa_supplicant *wpa_s, char *addr)
588 if (os_strcmp(addr, "*") == 0) {
589 /* remove everyone */
590 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN *");
591 wpa_tdls_teardown_peers(wpa_s->wpa);
595 if (hwaddr_aton(addr, peer)) {
596 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN: invalid "
597 "address '%s'", addr);
601 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN " MACSTR,
604 if ((wpa_s->conf->tdls_external_control) &&
605 wpa_tdls_is_external_setup(wpa_s->wpa))
606 return wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
608 if (wpa_tdls_is_external_setup(wpa_s->wpa))
609 ret = wpa_tdls_teardown_link(
611 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED);
613 ret = wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
619 static int ctrl_iface_get_capability_tdls(
620 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
624 ret = os_snprintf(buf, buflen, "%s\n",
625 wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT ?
627 WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP ?
628 "EXTERNAL" : "INTERNAL") : "UNSUPPORTED");
629 if (ret < 0 || (size_t) ret > buflen)
634 #endif /* CONFIG_TDLS */
637 #ifdef CONFIG_IEEE80211R
638 static int wpa_supplicant_ctrl_iface_ft_ds(
639 struct wpa_supplicant *wpa_s, char *addr)
641 u8 target_ap[ETH_ALEN];
645 if (hwaddr_aton(addr, target_ap)) {
646 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid "
647 "address '%s'", addr);
651 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap));
653 bss = wpa_bss_get_bssid(wpa_s, target_ap);
655 mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN);
659 return wpa_ft_start_over_ds(wpa_s->wpa, target_ap, mdie);
661 #endif /* CONFIG_IEEE80211R */
665 static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s,
668 u8 bssid[ETH_ALEN], *_bssid = bssid;
670 u8 p2p_dev_addr[ETH_ALEN];
671 #endif /* CONFIG_P2P */
673 u8 *_p2p_dev_addr = NULL;
674 #endif /* CONFIG_AP */
676 if (cmd == NULL || os_strcmp(cmd, "any") == 0) {
679 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
680 if (hwaddr_aton(cmd + 13, p2p_dev_addr)) {
681 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid "
682 "P2P Device Address '%s'",
686 _p2p_dev_addr = p2p_dev_addr;
687 #endif /* CONFIG_P2P */
688 } else if (hwaddr_aton(cmd, bssid)) {
689 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
696 return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid, _p2p_dev_addr);
697 #endif /* CONFIG_AP */
699 return wpas_wps_start_pbc(wpa_s, _bssid, 0);
703 static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s,
704 char *cmd, char *buf,
707 u8 bssid[ETH_ALEN], *_bssid = bssid;
711 pin = os_strchr(cmd, ' ');
715 if (os_strcmp(cmd, "any") == 0)
717 else if (os_strcmp(cmd, "get") == 0) {
718 ret = wps_generate_pin();
720 } else if (hwaddr_aton(cmd, bssid)) {
721 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
727 if (wpa_s->ap_iface) {
732 pos = os_strchr(pin, ' ');
739 return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin,
740 buf, buflen, timeout);
742 #endif /* CONFIG_AP */
745 ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0,
749 ret = os_snprintf(buf, buflen, "%s", pin);
750 if (ret < 0 || (size_t) ret >= buflen)
755 ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0, DEV_PW_DEFAULT);
760 /* Return the generated PIN */
761 ret = os_snprintf(buf, buflen, "%08d", ret);
762 if (ret < 0 || (size_t) ret >= buflen)
768 static int wpa_supplicant_ctrl_iface_wps_check_pin(
769 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
776 wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN",
777 (u8 *) cmd, os_strlen(cmd));
778 for (pos = cmd, len = 0; *pos != '\0'; pos++) {
779 if (*pos < '0' || *pos > '9')
783 wpa_printf(MSG_DEBUG, "WPS: Too long PIN");
787 if (len != 4 && len != 8) {
788 wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len);
794 unsigned int pin_val;
796 if (!wps_pin_valid(pin_val)) {
797 wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit");
798 ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n");
799 if (ret < 0 || (size_t) ret >= buflen)
805 ret = os_snprintf(buf, buflen, "%s", pin);
806 if (ret < 0 || (size_t) ret >= buflen)
813 #ifdef CONFIG_WPS_NFC
815 static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant *wpa_s,
818 u8 bssid[ETH_ALEN], *_bssid = bssid;
820 if (cmd == NULL || cmd[0] == '\0')
822 else if (hwaddr_aton(cmd, bssid))
825 return wpas_wps_start_nfc(wpa_s, NULL, _bssid, NULL, 0, 0, NULL, NULL,
830 static int wpa_supplicant_ctrl_iface_wps_nfc_config_token(
831 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
838 pos = os_strchr(cmd, ' ');
841 if (os_strcmp(cmd, "WPS") == 0)
843 else if (os_strcmp(cmd, "NDEF") == 0)
848 buf = wpas_wps_nfc_config_token(wpa_s, ndef, pos);
852 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
863 static int wpa_supplicant_ctrl_iface_wps_nfc_token(
864 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
870 if (os_strcmp(cmd, "WPS") == 0)
872 else if (os_strcmp(cmd, "NDEF") == 0)
877 buf = wpas_wps_nfc_token(wpa_s, ndef);
881 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
892 static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
893 struct wpa_supplicant *wpa_s, char *pos)
901 freq = strstr(pos, " freq=");
905 forced_freq = atoi(freq);
908 len = os_strlen(pos);
913 buf = wpabuf_alloc(len);
916 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
921 ret = wpas_wps_nfc_tag_read(wpa_s, buf, forced_freq);
928 static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant *wpa_s,
929 char *reply, size_t max_len,
935 buf = wpas_wps_nfc_handover_req(wpa_s, ndef);
939 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
951 static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant *wpa_s,
952 char *reply, size_t max_len,
958 buf = wpas_p2p_nfc_handover_req(wpa_s, ndef);
960 wpa_printf(MSG_DEBUG, "P2P: Could not generate NFC handover request");
964 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
973 #endif /* CONFIG_P2P */
976 static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant *wpa_s,
977 char *cmd, char *reply,
983 pos = os_strchr(cmd, ' ');
988 if (os_strcmp(cmd, "WPS") == 0)
990 else if (os_strcmp(cmd, "NDEF") == 0)
995 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
998 return wpas_ctrl_nfc_get_handover_req_wps(
999 wpa_s, reply, max_len, ndef);
1003 if (os_strcmp(pos, "P2P-CR") == 0) {
1004 return wpas_ctrl_nfc_get_handover_req_p2p(
1005 wpa_s, reply, max_len, ndef);
1007 #endif /* CONFIG_P2P */
1013 static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant *wpa_s,
1014 char *reply, size_t max_len,
1015 int ndef, int cr, char *uuid)
1020 buf = wpas_wps_nfc_handover_sel(wpa_s, ndef, cr, uuid);
1024 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1026 reply[res++] = '\n';
1036 static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant *wpa_s,
1037 char *reply, size_t max_len,
1043 buf = wpas_p2p_nfc_handover_sel(wpa_s, ndef, tag);
1047 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1049 reply[res++] = '\n';
1056 #endif /* CONFIG_P2P */
1059 static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant *wpa_s,
1060 char *cmd, char *reply,
1066 pos = os_strchr(cmd, ' ');
1071 if (os_strcmp(cmd, "WPS") == 0)
1073 else if (os_strcmp(cmd, "NDEF") == 0)
1078 pos2 = os_strchr(pos, ' ');
1081 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
1084 return wpas_ctrl_nfc_get_handover_sel_wps(
1085 wpa_s, reply, max_len, ndef,
1086 os_strcmp(pos, "WPS-CR") == 0, pos2);
1090 if (os_strcmp(pos, "P2P-CR") == 0) {
1091 return wpas_ctrl_nfc_get_handover_sel_p2p(
1092 wpa_s, reply, max_len, ndef, 0);
1095 if (os_strcmp(pos, "P2P-CR-TAG") == 0) {
1096 return wpas_ctrl_nfc_get_handover_sel_p2p(
1097 wpa_s, reply, max_len, ndef, 1);
1099 #endif /* CONFIG_P2P */
1105 static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant *wpa_s,
1109 struct wpabuf *req, *sel;
1111 char *pos, *role, *type, *pos2;
1114 int forced_freq = 0;
1116 freq = strstr(cmd, " freq=");
1120 forced_freq = atoi(freq);
1122 #endif /* CONFIG_P2P */
1125 pos = os_strchr(role, ' ');
1127 wpa_printf(MSG_DEBUG, "NFC: Missing type in handover report");
1133 pos = os_strchr(type, ' ');
1135 wpa_printf(MSG_DEBUG, "NFC: Missing request message in handover report");
1140 pos2 = os_strchr(pos, ' ');
1142 wpa_printf(MSG_DEBUG, "NFC: Missing select message in handover report");
1147 len = os_strlen(pos);
1149 wpa_printf(MSG_DEBUG, "NFC: Invalid request message length in handover report");
1154 req = wpabuf_alloc(len);
1156 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for request message");
1159 if (hexstr2bin(pos, wpabuf_put(req, len), len) < 0) {
1160 wpa_printf(MSG_DEBUG, "NFC: Invalid request message hexdump in handover report");
1165 len = os_strlen(pos2);
1167 wpa_printf(MSG_DEBUG, "NFC: Invalid select message length in handover report");
1173 sel = wpabuf_alloc(len);
1175 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for select message");
1179 if (hexstr2bin(pos2, wpabuf_put(sel, len), len) < 0) {
1180 wpa_printf(MSG_DEBUG, "NFC: Invalid select message hexdump in handover report");
1186 wpa_printf(MSG_DEBUG, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d",
1187 role, type, (int) wpabuf_len(req), (int) wpabuf_len(sel));
1189 if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "WPS") == 0) {
1190 ret = wpas_wps_nfc_report_handover(wpa_s, req, sel);
1192 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "WPS") == 0)
1194 ret = wpas_ap_wps_nfc_report_handover(wpa_s, req, sel);
1196 ret = wpas_er_wps_nfc_report_handover(wpa_s, req, sel);
1197 #endif /* CONFIG_AP */
1199 } else if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "P2P") == 0)
1201 ret = wpas_p2p_nfc_report_handover(wpa_s, 1, req, sel, 0);
1202 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "P2P") == 0)
1204 ret = wpas_p2p_nfc_report_handover(wpa_s, 0, req, sel,
1206 #endif /* CONFIG_P2P */
1208 wpa_printf(MSG_DEBUG, "NFC: Unsupported connection handover "
1209 "reported: role=%s type=%s", role, type);
1216 wpa_printf(MSG_DEBUG, "NFC: Failed to process reported handover messages");
1221 #endif /* CONFIG_WPS_NFC */
1224 static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s,
1233 struct wps_new_ap_settings ap;
1235 pin = os_strchr(cmd, ' ');
1240 if (hwaddr_aton(cmd, bssid)) {
1241 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
1246 new_ssid = os_strchr(pin, ' ');
1247 if (new_ssid == NULL)
1248 return wpas_wps_start_reg(wpa_s, bssid, pin, NULL);
1251 new_auth = os_strchr(new_ssid, ' ');
1252 if (new_auth == NULL)
1256 new_encr = os_strchr(new_auth, ' ');
1257 if (new_encr == NULL)
1261 new_key = os_strchr(new_encr, ' ');
1262 if (new_key == NULL)
1266 os_memset(&ap, 0, sizeof(ap));
1267 ap.ssid_hex = new_ssid;
1270 ap.key_hex = new_key;
1271 return wpas_wps_start_reg(wpa_s, bssid, pin, &ap);
1276 static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant *wpa_s,
1277 char *cmd, char *buf,
1282 const char *pin_txt;
1284 if (!wpa_s->ap_iface)
1287 pos = os_strchr(cmd, ' ');
1291 if (os_strcmp(cmd, "disable") == 0) {
1292 wpas_wps_ap_pin_disable(wpa_s);
1293 return os_snprintf(buf, buflen, "OK\n");
1296 if (os_strcmp(cmd, "random") == 0) {
1298 timeout = atoi(pos);
1299 pin_txt = wpas_wps_ap_pin_random(wpa_s, timeout);
1300 if (pin_txt == NULL)
1302 return os_snprintf(buf, buflen, "%s", pin_txt);
1305 if (os_strcmp(cmd, "get") == 0) {
1306 pin_txt = wpas_wps_ap_pin_get(wpa_s);
1307 if (pin_txt == NULL)
1309 return os_snprintf(buf, buflen, "%s", pin_txt);
1312 if (os_strcmp(cmd, "set") == 0) {
1317 pos = os_strchr(pos, ' ');
1320 timeout = atoi(pos);
1322 if (os_strlen(pin) > buflen)
1324 if (wpas_wps_ap_pin_set(wpa_s, pin, timeout) < 0)
1326 return os_snprintf(buf, buflen, "%s", pin);
1331 #endif /* CONFIG_AP */
1334 #ifdef CONFIG_WPS_ER
1335 static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant *wpa_s,
1338 char *uuid = cmd, *pin, *pos;
1339 u8 addr_buf[ETH_ALEN], *addr = NULL;
1340 pin = os_strchr(uuid, ' ');
1344 pos = os_strchr(pin, ' ');
1347 if (hwaddr_aton(pos, addr_buf) == 0)
1350 return wpas_wps_er_add_pin(wpa_s, addr, uuid, pin);
1354 static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant *wpa_s,
1357 char *uuid = cmd, *pin;
1358 pin = os_strchr(uuid, ' ');
1362 return wpas_wps_er_learn(wpa_s, uuid, pin);
1366 static int wpa_supplicant_ctrl_iface_wps_er_set_config(
1367 struct wpa_supplicant *wpa_s, char *cmd)
1369 char *uuid = cmd, *id;
1370 id = os_strchr(uuid, ' ');
1374 return wpas_wps_er_set_config(wpa_s, uuid, atoi(id));
1378 static int wpa_supplicant_ctrl_iface_wps_er_config(
1379 struct wpa_supplicant *wpa_s, char *cmd)
1386 struct wps_new_ap_settings ap;
1388 pin = os_strchr(cmd, ' ');
1393 new_ssid = os_strchr(pin, ' ');
1394 if (new_ssid == NULL)
1398 new_auth = os_strchr(new_ssid, ' ');
1399 if (new_auth == NULL)
1403 new_encr = os_strchr(new_auth, ' ');
1404 if (new_encr == NULL)
1408 new_key = os_strchr(new_encr, ' ');
1409 if (new_key == NULL)
1413 os_memset(&ap, 0, sizeof(ap));
1414 ap.ssid_hex = new_ssid;
1417 ap.key_hex = new_key;
1418 return wpas_wps_er_config(wpa_s, cmd, pin, &ap);
1422 #ifdef CONFIG_WPS_NFC
1423 static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
1424 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1431 uuid = os_strchr(cmd, ' ');
1436 if (os_strcmp(cmd, "WPS") == 0)
1438 else if (os_strcmp(cmd, "NDEF") == 0)
1443 buf = wpas_wps_er_nfc_config_token(wpa_s, ndef, uuid);
1447 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1449 reply[res++] = '\n';
1456 #endif /* CONFIG_WPS_NFC */
1457 #endif /* CONFIG_WPS_ER */
1459 #endif /* CONFIG_WPS */
1462 #ifdef CONFIG_IBSS_RSN
1463 static int wpa_supplicant_ctrl_iface_ibss_rsn(
1464 struct wpa_supplicant *wpa_s, char *addr)
1468 if (hwaddr_aton(addr, peer)) {
1469 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN: invalid "
1470 "address '%s'", addr);
1474 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN " MACSTR,
1477 return ibss_rsn_start(wpa_s->ibss_rsn, peer);
1479 #endif /* CONFIG_IBSS_RSN */
1482 static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s,
1485 #ifdef IEEE8021X_EAPOL
1488 struct wpa_ssid *ssid;
1490 pos = os_strchr(rsp, '-');
1495 pos = os_strchr(pos, ':');
1500 wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id);
1501 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
1502 (u8 *) pos, os_strlen(pos));
1504 ssid = wpa_config_get_network(wpa_s->conf, id);
1506 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
1511 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s, ssid, rsp,
1513 #else /* IEEE8021X_EAPOL */
1514 wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included");
1516 #endif /* IEEE8021X_EAPOL */
1520 static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
1522 char *buf, size_t buflen)
1524 char *pos, *end, tmp[30];
1525 int res, verbose, wps, ret;
1528 #endif /* CONFIG_HS20 */
1530 if (os_strcmp(params, "-DRIVER") == 0)
1531 return wpa_drv_status(wpa_s, buf, buflen);
1532 verbose = os_strcmp(params, "-VERBOSE") == 0;
1533 wps = os_strcmp(params, "-WPS") == 0;
1536 if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
1537 struct wpa_ssid *ssid = wpa_s->current_ssid;
1538 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
1539 MAC2STR(wpa_s->bssid));
1540 if (ret < 0 || ret >= end - pos)
1544 u8 *_ssid = ssid->ssid;
1545 size_t ssid_len = ssid->ssid_len;
1546 u8 ssid_buf[MAX_SSID_LEN];
1547 if (ssid_len == 0) {
1548 int _res = wpa_drv_get_ssid(wpa_s, ssid_buf);
1555 ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n",
1556 wpa_ssid_txt(_ssid, ssid_len),
1558 if (ret < 0 || ret >= end - pos)
1562 if (wps && ssid->passphrase &&
1563 wpa_key_mgmt_wpa_psk(ssid->key_mgmt) &&
1564 (ssid->mode == WPAS_MODE_AP ||
1565 ssid->mode == WPAS_MODE_P2P_GO)) {
1566 ret = os_snprintf(pos, end - pos,
1569 if (ret < 0 || ret >= end - pos)
1574 ret = os_snprintf(pos, end - pos,
1577 if (ret < 0 || ret >= end - pos)
1582 switch (ssid->mode) {
1583 case WPAS_MODE_INFRA:
1584 ret = os_snprintf(pos, end - pos,
1587 case WPAS_MODE_IBSS:
1588 ret = os_snprintf(pos, end - pos,
1592 ret = os_snprintf(pos, end - pos,
1595 case WPAS_MODE_P2P_GO:
1596 ret = os_snprintf(pos, end - pos,
1599 case WPAS_MODE_P2P_GROUP_FORMATION:
1600 ret = os_snprintf(pos, end - pos,
1601 "mode=P2P GO - group "
1608 if (ret < 0 || ret >= end - pos)
1614 if (wpa_s->ap_iface) {
1615 pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos,
1619 #endif /* CONFIG_AP */
1620 pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose);
1623 if (wpa_s->wpa_state >= WPA_ASSOCIATED &&
1626 #endif /* CONFIG_AP */
1627 wpa_s->sme.sae.state == SAE_ACCEPTED) {
1628 ret = os_snprintf(pos, end - pos, "sae_group=%d\n",
1629 wpa_s->sme.sae.group);
1630 if (ret < 0 || ret >= end - pos)
1634 #endif /* CONFIG_SAE */
1635 ret = os_snprintf(pos, end - pos, "wpa_state=%s\n",
1636 wpa_supplicant_state_txt(wpa_s->wpa_state));
1637 if (ret < 0 || ret >= end - pos)
1642 l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) {
1643 ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp);
1644 if (ret < 0 || ret >= end - pos)
1650 if (wpa_s->global->p2p) {
1651 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
1652 "\n", MAC2STR(wpa_s->global->p2p_dev_addr));
1653 if (ret < 0 || ret >= end - pos)
1657 #endif /* CONFIG_P2P */
1659 ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n",
1660 MAC2STR(wpa_s->own_addr));
1661 if (ret < 0 || ret >= end - pos)
1666 if (wpa_s->current_bss &&
1667 (hs20 = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1668 HS20_IE_VENDOR_TYPE)) &&
1669 wpa_s->wpa_proto == WPA_PROTO_RSN &&
1670 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1673 u8 rel_num = (hs20[6] & 0xf0) >> 4;
1674 release = rel_num + 1;
1676 ret = os_snprintf(pos, end - pos, "hs20=%d\n", release);
1677 if (ret < 0 || ret >= end - pos)
1682 if (wpa_s->current_ssid) {
1683 struct wpa_cred *cred;
1686 for (cred = wpa_s->conf->cred; cred; cred = cred->next) {
1689 if (wpa_s->current_ssid->parent_cred != cred)
1692 if (cred->provisioning_sp) {
1693 ret = os_snprintf(pos, end - pos,
1694 "provisioning_sp=%s\n",
1695 cred->provisioning_sp);
1696 if (ret < 0 || ret >= end - pos)
1705 if (wpa_s->current_bss && wpa_s->current_bss->anqp) {
1706 struct wpabuf *names =
1707 wpa_s->current_bss->anqp->domain_name;
1708 for (i = 0; names && i < cred->num_domain; i++)
1710 if (domain_name_list_contains(
1711 names, cred->domain[i], 1))
1714 if (i == cred->num_domain)
1715 i = 0; /* show first entry by default */
1717 ret = os_snprintf(pos, end - pos, "home_sp=%s\n",
1719 if (ret < 0 || ret >= end - pos)
1724 if (wpa_s->current_bss == NULL ||
1725 wpa_s->current_bss->anqp == NULL)
1728 res = interworking_home_sp_cred(
1730 wpa_s->current_bss->anqp->domain_name);
1738 ret = os_snprintf(pos, end - pos, "sp_type=%s\n", type);
1739 if (ret < 0 || ret >= end - pos)
1746 #endif /* CONFIG_HS20 */
1748 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
1749 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
1750 res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos,
1756 res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose);
1763 uuid_bin2str(wpa_s->wps->uuid, uuid_str, sizeof(uuid_str));
1764 ret = os_snprintf(pos, end - pos, "uuid=%s\n", uuid_str);
1765 if (ret < 0 || ret >= end - pos)
1769 #endif /* CONFIG_WPS */
1773 * Allow using the STATUS command with default behavior, say for debug,
1774 * i.e., don't generate a "fake" CONNECTION and SUPPLICANT_STATE_CHANGE
1775 * events with STATUS-NO_EVENTS.
1777 if (os_strcmp(params, "-NO_EVENTS")) {
1778 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_STATE_CHANGE
1779 "id=%d state=%d BSSID=" MACSTR " SSID=%s",
1780 wpa_s->current_ssid ? wpa_s->current_ssid->id : -1,
1782 MAC2STR(wpa_s->bssid),
1783 wpa_s->current_ssid && wpa_s->current_ssid->ssid ?
1784 wpa_ssid_txt(wpa_s->current_ssid->ssid,
1785 wpa_s->current_ssid->ssid_len) : "");
1786 if (wpa_s->wpa_state == WPA_COMPLETED) {
1787 struct wpa_ssid *ssid = wpa_s->current_ssid;
1788 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_CONNECTED
1789 "- connection to " MACSTR
1790 " completed %s [id=%d id_str=%s]",
1791 MAC2STR(wpa_s->bssid), "(auth)",
1792 ssid ? ssid->id : -1,
1793 ssid && ssid->id_str ? ssid->id_str : "");
1796 #endif /* ANDROID */
1802 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s,
1807 struct wpa_ssid *ssid;
1810 /* cmd: "<network id> <BSSID>" */
1811 pos = os_strchr(cmd, ' ');
1816 wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos);
1817 if (hwaddr_aton(pos, bssid)) {
1818 wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos);
1822 ssid = wpa_config_get_network(wpa_s->conf, id);
1824 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
1829 os_memcpy(ssid->bssid, bssid, ETH_ALEN);
1830 ssid->bssid_set = !is_zero_ether_addr(bssid);
1836 static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant *wpa_s,
1837 char *cmd, char *buf,
1841 struct wpa_blacklist *e;
1845 /* cmd: "BLACKLIST [<BSSID>]" */
1849 e = wpa_s->blacklist;
1851 ret = os_snprintf(pos, end - pos, MACSTR "\n",
1853 if (ret < 0 || ret >= end - pos)
1862 if (os_strncmp(cmd, "clear", 5) == 0) {
1863 wpa_blacklist_clear(wpa_s);
1864 os_memcpy(buf, "OK\n", 3);
1868 wpa_printf(MSG_DEBUG, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd);
1869 if (hwaddr_aton(cmd, bssid)) {
1870 wpa_printf(MSG_DEBUG, "CTRL_IFACE: invalid BSSID '%s'", cmd);
1875 * Add the BSSID twice, so its count will be 2, causing it to be
1876 * skipped when processing scan results.
1878 ret = wpa_blacklist_add(wpa_s, bssid);
1881 ret = wpa_blacklist_add(wpa_s, bssid);
1884 os_memcpy(buf, "OK\n", 3);
1889 static const char * debug_level_str(int level)
1910 static int str_to_debug_level(const char *s)
1912 if (os_strcasecmp(s, "EXCESSIVE") == 0)
1913 return MSG_EXCESSIVE;
1914 if (os_strcasecmp(s, "MSGDUMP") == 0)
1916 if (os_strcasecmp(s, "DEBUG") == 0)
1918 if (os_strcasecmp(s, "INFO") == 0)
1920 if (os_strcasecmp(s, "WARNING") == 0)
1922 if (os_strcasecmp(s, "ERROR") == 0)
1928 static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant *wpa_s,
1929 char *cmd, char *buf,
1932 char *pos, *end, *stamp;
1939 /* cmd: "LOG_LEVEL [<level>]" */
1943 ret = os_snprintf(pos, end - pos, "Current level: %s\n"
1945 debug_level_str(wpa_debug_level),
1946 wpa_debug_timestamp);
1947 if (ret < 0 || ret >= end - pos)
1956 stamp = os_strchr(cmd, ' ');
1959 while (*stamp == ' ') {
1964 if (cmd && os_strlen(cmd)) {
1965 int level = str_to_debug_level(cmd);
1968 wpa_debug_level = level;
1971 if (stamp && os_strlen(stamp))
1972 wpa_debug_timestamp = atoi(stamp);
1974 os_memcpy(buf, "OK\n", 3);
1979 static int wpa_supplicant_ctrl_iface_list_networks(
1980 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
1983 struct wpa_ssid *ssid;
1988 ret = os_snprintf(pos, end - pos,
1989 "network id / ssid / bssid / flags\n");
1990 if (ret < 0 || ret >= end - pos)
1994 ssid = wpa_s->conf->ssid;
1996 ret = os_snprintf(pos, end - pos, "%d\t%s",
1998 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
1999 if (ret < 0 || ret >= end - pos)
2002 if (ssid->bssid_set) {
2003 ret = os_snprintf(pos, end - pos, "\t" MACSTR,
2004 MAC2STR(ssid->bssid));
2006 ret = os_snprintf(pos, end - pos, "\tany");
2008 if (ret < 0 || ret >= end - pos)
2011 ret = os_snprintf(pos, end - pos, "\t%s%s%s%s",
2012 ssid == wpa_s->current_ssid ?
2014 ssid->disabled ? "[DISABLED]" : "",
2015 ssid->disabled_until.sec ?
2016 "[TEMP-DISABLED]" : "",
2017 ssid->disabled == 2 ? "[P2P-PERSISTENT]" :
2019 if (ret < 0 || ret >= end - pos)
2022 ret = os_snprintf(pos, end - pos, "\n");
2023 if (ret < 0 || ret >= end - pos)
2034 static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher)
2037 ret = os_snprintf(pos, end - pos, "-");
2038 if (ret < 0 || ret >= end - pos)
2041 ret = wpa_write_ciphers(pos, end, cipher, "+");
2049 static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
2050 const u8 *ie, size_t ie_len)
2052 struct wpa_ie_data data;
2056 ret = os_snprintf(pos, end - pos, "[%s-", proto);
2057 if (ret < 0 || ret >= end - pos)
2061 if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) {
2062 ret = os_snprintf(pos, end - pos, "?]");
2063 if (ret < 0 || ret >= end - pos)
2070 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
2071 ret = os_snprintf(pos, end - pos, "%sEAP",
2072 pos == start ? "" : "+");
2073 if (ret < 0 || ret >= end - pos)
2077 if (data.key_mgmt & WPA_KEY_MGMT_PSK) {
2078 ret = os_snprintf(pos, end - pos, "%sPSK",
2079 pos == start ? "" : "+");
2080 if (ret < 0 || ret >= end - pos)
2084 if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
2085 ret = os_snprintf(pos, end - pos, "%sNone",
2086 pos == start ? "" : "+");
2087 if (ret < 0 || ret >= end - pos)
2091 #ifdef CONFIG_IEEE80211R
2092 if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
2093 ret = os_snprintf(pos, end - pos, "%sFT/EAP",
2094 pos == start ? "" : "+");
2095 if (ret < 0 || ret >= end - pos)
2099 if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) {
2100 ret = os_snprintf(pos, end - pos, "%sFT/PSK",
2101 pos == start ? "" : "+");
2102 if (ret < 0 || ret >= end - pos)
2106 #endif /* CONFIG_IEEE80211R */
2107 #ifdef CONFIG_IEEE80211W
2108 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
2109 ret = os_snprintf(pos, end - pos, "%sEAP-SHA256",
2110 pos == start ? "" : "+");
2111 if (ret < 0 || ret >= end - pos)
2115 if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
2116 ret = os_snprintf(pos, end - pos, "%sPSK-SHA256",
2117 pos == start ? "" : "+");
2118 if (ret < 0 || ret >= end - pos)
2122 #endif /* CONFIG_IEEE80211W */
2124 pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher);
2126 if (data.capabilities & WPA_CAPABILITY_PREAUTH) {
2127 ret = os_snprintf(pos, end - pos, "-preauth");
2128 if (ret < 0 || ret >= end - pos)
2133 ret = os_snprintf(pos, end - pos, "]");
2134 if (ret < 0 || ret >= end - pos)
2143 static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s,
2144 char *pos, char *end,
2145 struct wpabuf *wps_ie)
2152 if (wps_is_selected_pbc_registrar(wps_ie))
2154 else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0))
2156 else if (wps_is_selected_pin_registrar(wps_ie))
2161 ret = os_snprintf(pos, end - pos, "%s", txt);
2162 if (ret >= 0 && ret < end - pos)
2164 wpabuf_free(wps_ie);
2167 #endif /* CONFIG_WPS */
2170 static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s,
2171 char *pos, char *end,
2172 const struct wpa_bss *bss)
2175 struct wpabuf *wps_ie;
2176 wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
2177 return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie);
2178 #else /* CONFIG_WPS */
2180 #endif /* CONFIG_WPS */
2184 /* Format one result on one text line into a buffer. */
2185 static int wpa_supplicant_ctrl_iface_scan_result(
2186 struct wpa_supplicant *wpa_s,
2187 const struct wpa_bss *bss, char *buf, size_t buflen)
2191 const u8 *ie, *ie2, *p2p;
2193 p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
2195 p2p = wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE);
2196 if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN &&
2197 os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) ==
2199 return 0; /* Do not show P2P listen discovery results here */
2204 ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t",
2205 MAC2STR(bss->bssid), bss->freq, bss->level);
2206 if (ret < 0 || ret >= end - pos)
2209 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
2211 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]);
2212 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
2214 pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2, 2 + ie2[1]);
2215 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
2216 if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
2217 ret = os_snprintf(pos, end - pos, "[WEP]");
2218 if (ret < 0 || ret >= end - pos)
2222 if (bss_is_dmg(bss)) {
2224 ret = os_snprintf(pos, end - pos, "[DMG]");
2225 if (ret < 0 || ret >= end - pos)
2228 switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
2229 case IEEE80211_CAP_DMG_IBSS:
2232 case IEEE80211_CAP_DMG_AP:
2235 case IEEE80211_CAP_DMG_PBSS:
2242 ret = os_snprintf(pos, end - pos, "%s", s);
2243 if (ret < 0 || ret >= end - pos)
2247 if (bss->caps & IEEE80211_CAP_IBSS) {
2248 ret = os_snprintf(pos, end - pos, "[IBSS]");
2249 if (ret < 0 || ret >= end - pos)
2253 if (bss->caps & IEEE80211_CAP_ESS) {
2254 ret = os_snprintf(pos, end - pos, "[ESS]");
2255 if (ret < 0 || ret >= end - pos)
2261 ret = os_snprintf(pos, end - pos, "[P2P]");
2262 if (ret < 0 || ret >= end - pos)
2267 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE) && ie2) {
2268 ret = os_snprintf(pos, end - pos, "[HS20]");
2269 if (ret < 0 || ret >= end - pos)
2273 #endif /* CONFIG_HS20 */
2275 ret = os_snprintf(pos, end - pos, "\t%s",
2276 wpa_ssid_txt(bss->ssid, bss->ssid_len));
2277 if (ret < 0 || ret >= end - pos)
2281 ret = os_snprintf(pos, end - pos, "\n");
2282 if (ret < 0 || ret >= end - pos)
2290 static int wpa_supplicant_ctrl_iface_scan_results(
2291 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
2294 struct wpa_bss *bss;
2299 ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / "
2301 if (ret < 0 || ret >= end - pos)
2305 dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
2306 ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos,
2308 if (ret < 0 || ret >= end - pos)
2317 static int wpa_supplicant_ctrl_iface_select_network(
2318 struct wpa_supplicant *wpa_s, char *cmd)
2321 struct wpa_ssid *ssid;
2324 /* cmd: "<network id>" or "any" */
2325 if (os_strncmp(cmd, "any", 3) == 0) {
2326 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any");
2330 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id);
2332 ssid = wpa_config_get_network(wpa_s->conf, id);
2334 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2335 "network id=%d", id);
2338 if (ssid->disabled == 2) {
2339 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2340 "SELECT_NETWORK with persistent P2P group");
2345 pos = os_strstr(cmd, " freq=");
2347 int *freqs = freq_range_to_channel_list(wpa_s, pos + 6);
2349 wpa_s->scan_req = MANUAL_SCAN_REQ;
2350 os_free(wpa_s->manual_scan_freqs);
2351 wpa_s->manual_scan_freqs = freqs;
2355 wpa_supplicant_select_network(wpa_s, ssid);
2361 static int wpa_supplicant_ctrl_iface_enable_network(
2362 struct wpa_supplicant *wpa_s, char *cmd)
2365 struct wpa_ssid *ssid;
2367 /* cmd: "<network id>" or "all" */
2368 if (os_strcmp(cmd, "all") == 0) {
2369 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all");
2373 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id);
2375 ssid = wpa_config_get_network(wpa_s->conf, id);
2377 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2378 "network id=%d", id);
2381 if (ssid->disabled == 2) {
2382 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2383 "ENABLE_NETWORK with persistent P2P group");
2387 if (os_strstr(cmd, " no-connect")) {
2392 wpa_supplicant_enable_network(wpa_s, ssid);
2398 static int wpa_supplicant_ctrl_iface_disable_network(
2399 struct wpa_supplicant *wpa_s, char *cmd)
2402 struct wpa_ssid *ssid;
2404 /* cmd: "<network id>" or "all" */
2405 if (os_strcmp(cmd, "all") == 0) {
2406 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all");
2410 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id);
2412 ssid = wpa_config_get_network(wpa_s->conf, id);
2414 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2415 "network id=%d", id);
2418 if (ssid->disabled == 2) {
2419 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2420 "DISABLE_NETWORK with persistent P2P "
2425 wpa_supplicant_disable_network(wpa_s, ssid);
2431 static int wpa_supplicant_ctrl_iface_add_network(
2432 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
2434 struct wpa_ssid *ssid;
2437 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK");
2439 ssid = wpa_config_add_network(wpa_s->conf);
2443 wpas_notify_network_added(wpa_s, ssid);
2446 wpa_config_set_network_defaults(ssid);
2448 ret = os_snprintf(buf, buflen, "%d\n", ssid->id);
2449 if (ret < 0 || (size_t) ret >= buflen)
2455 static int wpa_supplicant_ctrl_iface_remove_network(
2456 struct wpa_supplicant *wpa_s, char *cmd)
2459 struct wpa_ssid *ssid;
2462 /* cmd: "<network id>" or "all" */
2463 if (os_strcmp(cmd, "all") == 0) {
2464 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all");
2465 if (wpa_s->sched_scanning)
2466 wpa_supplicant_cancel_sched_scan(wpa_s);
2468 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2469 if (wpa_s->current_ssid) {
2471 wpa_s->sme.prev_bssid_set = 0;
2472 #endif /* CONFIG_SME */
2473 wpa_sm_set_config(wpa_s->wpa, NULL);
2474 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
2475 wpa_supplicant_deauthenticate(
2476 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2478 ssid = wpa_s->conf->ssid;
2480 struct wpa_ssid *remove_ssid = ssid;
2483 if (wpa_s->last_ssid == remove_ssid)
2484 wpa_s->last_ssid = NULL;
2485 wpas_notify_network_removed(wpa_s, remove_ssid);
2486 wpa_config_remove_network(wpa_s->conf, id);
2492 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id);
2494 ssid = wpa_config_get_network(wpa_s->conf, id);
2496 wpas_notify_network_removed(wpa_s, ssid);
2498 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2503 if (wpa_s->last_ssid == ssid)
2504 wpa_s->last_ssid = NULL;
2506 if (ssid == wpa_s->current_ssid || wpa_s->current_ssid == NULL) {
2508 wpa_s->sme.prev_bssid_set = 0;
2509 #endif /* CONFIG_SME */
2511 * Invalidate the EAP session cache if the current or
2512 * previously used network is removed.
2514 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2517 if (ssid == wpa_s->current_ssid) {
2518 wpa_sm_set_config(wpa_s->wpa, NULL);
2519 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
2521 wpa_supplicant_deauthenticate(wpa_s,
2522 WLAN_REASON_DEAUTH_LEAVING);
2525 was_disabled = ssid->disabled;
2527 if (wpa_config_remove_network(wpa_s->conf, id) < 0) {
2528 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Not able to remove the "
2529 "network id=%d", id);
2533 if (!was_disabled && wpa_s->sched_scanning) {
2534 wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to remove "
2535 "network from filters");
2536 wpa_supplicant_cancel_sched_scan(wpa_s);
2537 wpa_supplicant_req_scan(wpa_s, 0, 0);
2544 static int wpa_supplicant_ctrl_iface_update_network(
2545 struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
2546 char *name, char *value)
2548 if (wpa_config_set(ssid, name, value, 0) < 0) {
2549 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network "
2550 "variable '%s'", name);
2554 if (os_strcmp(name, "bssid") != 0 &&
2555 os_strcmp(name, "priority") != 0)
2556 wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
2558 if (wpa_s->current_ssid == ssid || wpa_s->current_ssid == NULL) {
2560 * Invalidate the EAP session cache if anything in the current
2561 * or previously used configuration changes.
2563 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2566 if ((os_strcmp(name, "psk") == 0 &&
2567 value[0] == '"' && ssid->ssid_len) ||
2568 (os_strcmp(name, "ssid") == 0 && ssid->passphrase))
2569 wpa_config_update_psk(ssid);
2570 else if (os_strcmp(name, "priority") == 0)
2571 wpa_config_update_prio_list(wpa_s->conf);
2577 static int wpa_supplicant_ctrl_iface_set_network(
2578 struct wpa_supplicant *wpa_s, char *cmd)
2580 int id, ret, prev_bssid_set;
2581 struct wpa_ssid *ssid;
2583 u8 prev_bssid[ETH_ALEN];
2585 /* cmd: "<network id> <variable name> <value>" */
2586 name = os_strchr(cmd, ' ');
2591 value = os_strchr(name, ' ');
2597 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
2599 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
2600 (u8 *) value, os_strlen(value));
2602 ssid = wpa_config_get_network(wpa_s->conf, id);
2604 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2609 prev_bssid_set = ssid->bssid_set;
2610 os_memcpy(prev_bssid, ssid->bssid, ETH_ALEN);
2611 ret = wpa_supplicant_ctrl_iface_update_network(wpa_s, ssid, name,
2614 (ssid->bssid_set != prev_bssid_set ||
2615 os_memcmp(ssid->bssid, prev_bssid, ETH_ALEN) != 0))
2616 wpas_notify_network_bssid_set_changed(wpa_s, ssid);
2621 static int wpa_supplicant_ctrl_iface_get_network(
2622 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
2626 struct wpa_ssid *ssid;
2629 /* cmd: "<network id> <variable name>" */
2630 name = os_strchr(cmd, ' ');
2631 if (name == NULL || buflen == 0)
2636 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
2639 ssid = wpa_config_get_network(wpa_s->conf, id);
2641 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2646 value = wpa_config_get_no_key(ssid, name);
2647 if (value == NULL) {
2648 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
2649 "variable '%s'", name);
2653 res = os_strlcpy(buf, value, buflen);
2654 if (res >= buflen) {
2665 static int wpa_supplicant_ctrl_iface_dup_network(
2666 struct wpa_supplicant *wpa_s, char *cmd)
2668 struct wpa_ssid *ssid_s, *ssid_d;
2669 char *name, *id, *value;
2670 int id_s, id_d, ret;
2672 /* cmd: "<src network id> <dst network id> <variable name>" */
2673 id = os_strchr(cmd, ' ');
2678 name = os_strchr(id, ' ');
2685 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DUP_NETWORK id=%d -> %d name='%s'",
2688 ssid_s = wpa_config_get_network(wpa_s->conf, id_s);
2689 if (ssid_s == NULL) {
2690 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2691 "network id=%d", id_s);
2695 ssid_d = wpa_config_get_network(wpa_s->conf, id_d);
2696 if (ssid_d == NULL) {
2697 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2698 "network id=%d", id_s);
2702 value = wpa_config_get(ssid_s, name);
2703 if (value == NULL) {
2704 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
2705 "variable '%s'", name);
2709 ret = wpa_supplicant_ctrl_iface_update_network(wpa_s, ssid_d, name,
2718 static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant *wpa_s,
2719 char *buf, size_t buflen)
2722 struct wpa_cred *cred;
2727 ret = os_snprintf(pos, end - pos,
2728 "cred id / realm / username / domain / imsi\n");
2729 if (ret < 0 || ret >= end - pos)
2733 cred = wpa_s->conf->cred;
2735 ret = os_snprintf(pos, end - pos, "%d\t%s\t%s\t%s\t%s\n",
2736 cred->id, cred->realm ? cred->realm : "",
2737 cred->username ? cred->username : "",
2738 cred->domain ? cred->domain[0] : "",
2739 cred->imsi ? cred->imsi : "");
2740 if (ret < 0 || ret >= end - pos)
2751 static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant *wpa_s,
2752 char *buf, size_t buflen)
2754 struct wpa_cred *cred;
2757 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_CRED");
2759 cred = wpa_config_add_cred(wpa_s->conf);
2763 wpa_msg(wpa_s, MSG_INFO, CRED_ADDED "%d", cred->id);
2765 ret = os_snprintf(buf, buflen, "%d\n", cred->id);
2766 if (ret < 0 || (size_t) ret >= buflen)
2772 static int wpas_ctrl_remove_cred(struct wpa_supplicant *wpa_s,
2773 struct wpa_cred *cred)
2775 struct wpa_ssid *ssid;
2780 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred");
2785 if (wpa_config_remove_cred(wpa_s->conf, id) < 0) {
2786 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred");
2790 wpa_msg(wpa_s, MSG_INFO, CRED_REMOVED "%d", id);
2792 /* Remove any network entry created based on the removed credential */
2793 ssid = wpa_s->conf->ssid;
2795 if (ssid->parent_cred == cred) {
2796 wpa_printf(MSG_DEBUG, "Remove network id %d since it "
2797 "used the removed credential", ssid->id);
2798 os_snprintf(str, sizeof(str), "%d", ssid->id);
2800 wpa_supplicant_ctrl_iface_remove_network(wpa_s, str);
2809 static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s,
2813 struct wpa_cred *cred, *prev;
2815 /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or
2816 * "provisioning_sp=<FQDN> */
2817 if (os_strcmp(cmd, "all") == 0) {
2818 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED all");
2819 cred = wpa_s->conf->cred;
2823 wpas_ctrl_remove_cred(wpa_s, prev);
2828 if (os_strncmp(cmd, "sp_fqdn=", 8) == 0) {
2829 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
2831 cred = wpa_s->conf->cred;
2837 for (i = 0; i < prev->num_domain; i++) {
2838 if (os_strcmp(prev->domain[i], cmd + 8)
2841 wpas_ctrl_remove_cred(wpa_s, prev);
2849 if (os_strncmp(cmd, "provisioning_sp=", 16) == 0) {
2850 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'",
2852 cred = wpa_s->conf->cred;
2856 if (prev->provisioning_sp &&
2857 os_strcmp(prev->provisioning_sp, cmd + 16) == 0)
2858 wpas_ctrl_remove_cred(wpa_s, prev);
2864 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED id=%d", id);
2866 cred = wpa_config_get_cred(wpa_s->conf, id);
2867 return wpas_ctrl_remove_cred(wpa_s, cred);
2871 static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant *wpa_s,
2875 struct wpa_cred *cred;
2878 /* cmd: "<cred id> <variable name> <value>" */
2879 name = os_strchr(cmd, ' ');
2884 value = os_strchr(name, ' ');
2890 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_CRED id=%d name='%s'",
2892 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
2893 (u8 *) value, os_strlen(value));
2895 cred = wpa_config_get_cred(wpa_s->conf, id);
2897 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
2902 if (wpa_config_set_cred(cred, name, value, 0) < 0) {
2903 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set cred "
2904 "variable '%s'", name);
2908 wpa_msg(wpa_s, MSG_INFO, CRED_MODIFIED "%d %s", cred->id, name);
2914 static int wpa_supplicant_ctrl_iface_get_cred(struct wpa_supplicant *wpa_s,
2915 char *cmd, char *buf,
2920 struct wpa_cred *cred;
2923 /* cmd: "<cred id> <variable name>" */
2924 name = os_strchr(cmd, ' ');
2930 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CRED id=%d name='%s'",
2933 cred = wpa_config_get_cred(wpa_s->conf, id);
2935 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
2940 value = wpa_config_get_cred_no_key(cred, name);
2941 if (value == NULL) {
2942 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get cred variable '%s'",
2947 res = os_strlcpy(buf, value, buflen);
2948 if (res >= buflen) {
2959 #ifndef CONFIG_NO_CONFIG_WRITE
2960 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s)
2964 if (!wpa_s->conf->update_config) {
2965 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
2966 "to update configuration (update_config=0)");
2970 ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
2972 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to "
2973 "update configuration");
2975 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration"
2981 #endif /* CONFIG_NO_CONFIG_WRITE */
2984 struct cipher_info {
2990 static const struct cipher_info ciphers[] = {
2991 { WPA_DRIVER_CAPA_ENC_CCMP_256, "CCMP-256", 0 },
2992 { WPA_DRIVER_CAPA_ENC_GCMP_256, "GCMP-256", 0 },
2993 { WPA_DRIVER_CAPA_ENC_CCMP, "CCMP", 0 },
2994 { WPA_DRIVER_CAPA_ENC_GCMP, "GCMP", 0 },
2995 { WPA_DRIVER_CAPA_ENC_TKIP, "TKIP", 0 },
2996 { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE, "NONE", 0 },
2997 { WPA_DRIVER_CAPA_ENC_WEP104, "WEP104", 1 },
2998 { WPA_DRIVER_CAPA_ENC_WEP40, "WEP40", 1 }
3002 static int ctrl_iface_get_capability_pairwise(int res, char *strict,
3003 struct wpa_driver_capa *capa,
3004 char *buf, size_t buflen)
3017 len = os_strlcpy(buf, "CCMP TKIP NONE", buflen);
3023 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
3024 if (!ciphers[i].group_only && capa->enc & ciphers[i].capa) {
3025 ret = os_snprintf(pos, end - pos, "%s%s",
3026 pos == buf ? "" : " ",
3028 if (ret < 0 || ret >= end - pos)
3038 static int ctrl_iface_get_capability_group(int res, char *strict,
3039 struct wpa_driver_capa *capa,
3040 char *buf, size_t buflen)
3053 len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen);
3059 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
3060 if (capa->enc & ciphers[i].capa) {
3061 ret = os_snprintf(pos, end - pos, "%s%s",
3062 pos == buf ? "" : " ",
3064 if (ret < 0 || ret >= end - pos)
3074 static int ctrl_iface_get_capability_key_mgmt(int res, char *strict,
3075 struct wpa_driver_capa *capa,
3076 char *buf, size_t buflen)
3088 len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
3095 ret = os_snprintf(pos, end - pos, "NONE IEEE8021X");
3096 if (ret < 0 || ret >= end - pos)
3100 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
3101 WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
3102 ret = os_snprintf(pos, end - pos, " WPA-EAP");
3103 if (ret < 0 || ret >= end - pos)
3108 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
3109 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
3110 ret = os_snprintf(pos, end - pos, " WPA-PSK");
3111 if (ret < 0 || ret >= end - pos)
3116 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
3117 ret = os_snprintf(pos, end - pos, " WPA-NONE");
3118 if (ret < 0 || ret >= end - pos)
3127 static int ctrl_iface_get_capability_proto(int res, char *strict,
3128 struct wpa_driver_capa *capa,
3129 char *buf, size_t buflen)
3141 len = os_strlcpy(buf, "RSN WPA", buflen);
3147 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
3148 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
3149 ret = os_snprintf(pos, end - pos, "%sRSN",
3150 pos == buf ? "" : " ");
3151 if (ret < 0 || ret >= end - pos)
3156 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
3157 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
3158 ret = os_snprintf(pos, end - pos, "%sWPA",
3159 pos == buf ? "" : " ");
3160 if (ret < 0 || ret >= end - pos)
3169 static int ctrl_iface_get_capability_auth_alg(int res, char *strict,
3170 struct wpa_driver_capa *capa,
3171 char *buf, size_t buflen)
3183 len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen);
3189 if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) {
3190 ret = os_snprintf(pos, end - pos, "%sOPEN",
3191 pos == buf ? "" : " ");
3192 if (ret < 0 || ret >= end - pos)
3197 if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) {
3198 ret = os_snprintf(pos, end - pos, "%sSHARED",
3199 pos == buf ? "" : " ");
3200 if (ret < 0 || ret >= end - pos)
3205 if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) {
3206 ret = os_snprintf(pos, end - pos, "%sLEAP",
3207 pos == buf ? "" : " ");
3208 if (ret < 0 || ret >= end - pos)
3217 static int ctrl_iface_get_capability_modes(int res, char *strict,
3218 struct wpa_driver_capa *capa,
3219 char *buf, size_t buflen)
3231 len = os_strlcpy(buf, "IBSS AP", buflen);
3237 if (capa->flags & WPA_DRIVER_FLAGS_IBSS) {
3238 ret = os_snprintf(pos, end - pos, "%sIBSS",
3239 pos == buf ? "" : " ");
3240 if (ret < 0 || ret >= end - pos)
3245 if (capa->flags & WPA_DRIVER_FLAGS_AP) {
3246 ret = os_snprintf(pos, end - pos, "%sAP",
3247 pos == buf ? "" : " ");
3248 if (ret < 0 || ret >= end - pos)
3257 static int ctrl_iface_get_capability_channels(struct wpa_supplicant *wpa_s,
3258 char *buf, size_t buflen)
3260 struct hostapd_channel_data *chnl;
3262 char *pos, *end, *hmode;
3267 for (j = 0; j < wpa_s->hw.num_modes; j++) {
3268 switch (wpa_s->hw.modes[j].mode) {
3269 case HOSTAPD_MODE_IEEE80211B:
3272 case HOSTAPD_MODE_IEEE80211G:
3275 case HOSTAPD_MODE_IEEE80211A:
3278 case HOSTAPD_MODE_IEEE80211AD:
3284 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:", hmode);
3285 if (ret < 0 || ret >= end - pos)
3288 chnl = wpa_s->hw.modes[j].channels;
3289 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
3290 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
3292 ret = os_snprintf(pos, end - pos, " %d", chnl[i].chan);
3293 if (ret < 0 || ret >= end - pos)
3297 ret = os_snprintf(pos, end - pos, "\n");
3298 if (ret < 0 || ret >= end - pos)
3307 static int ctrl_iface_get_capability_freq(struct wpa_supplicant *wpa_s,
3308 char *buf, size_t buflen)
3310 struct hostapd_channel_data *chnl;
3312 char *pos, *end, *hmode;
3317 for (j = 0; j < wpa_s->hw.num_modes; j++) {
3318 switch (wpa_s->hw.modes[j].mode) {
3319 case HOSTAPD_MODE_IEEE80211B:
3322 case HOSTAPD_MODE_IEEE80211G:
3325 case HOSTAPD_MODE_IEEE80211A:
3328 case HOSTAPD_MODE_IEEE80211AD:
3334 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:\n",
3336 if (ret < 0 || ret >= end - pos)
3339 chnl = wpa_s->hw.modes[j].channels;
3340 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
3341 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
3343 ret = os_snprintf(pos, end - pos, " %d = %d MHz%s%s\n",
3344 chnl[i].chan, chnl[i].freq,
3345 chnl[i].flag & HOSTAPD_CHAN_NO_IBSS ?
3347 chnl[i].flag & HOSTAPD_CHAN_RADAR ?
3350 if (ret < 0 || ret >= end - pos)
3354 ret = os_snprintf(pos, end - pos, "\n");
3355 if (ret < 0 || ret >= end - pos)
3364 static int wpa_supplicant_ctrl_iface_get_capability(
3365 struct wpa_supplicant *wpa_s, const char *_field, char *buf,
3368 struct wpa_driver_capa capa;
3374 /* Determine whether or not strict checking was requested */
3375 len = os_strlcpy(field, _field, sizeof(field));
3376 if (len >= sizeof(field))
3378 strict = os_strchr(field, ' ');
3379 if (strict != NULL) {
3381 if (os_strcmp(strict, "strict") != 0)
3385 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
3386 field, strict ? strict : "");
3388 if (os_strcmp(field, "eap") == 0) {
3389 return eap_get_names(buf, buflen);
3392 res = wpa_drv_get_capa(wpa_s, &capa);
3394 if (os_strcmp(field, "pairwise") == 0)
3395 return ctrl_iface_get_capability_pairwise(res, strict, &capa,
3398 if (os_strcmp(field, "group") == 0)
3399 return ctrl_iface_get_capability_group(res, strict, &capa,
3402 if (os_strcmp(field, "key_mgmt") == 0)
3403 return ctrl_iface_get_capability_key_mgmt(res, strict, &capa,
3406 if (os_strcmp(field, "proto") == 0)
3407 return ctrl_iface_get_capability_proto(res, strict, &capa,
3410 if (os_strcmp(field, "auth_alg") == 0)
3411 return ctrl_iface_get_capability_auth_alg(res, strict, &capa,
3414 if (os_strcmp(field, "modes") == 0)
3415 return ctrl_iface_get_capability_modes(res, strict, &capa,
3418 if (os_strcmp(field, "channels") == 0)
3419 return ctrl_iface_get_capability_channels(wpa_s, buf, buflen);
3421 if (os_strcmp(field, "freq") == 0)
3422 return ctrl_iface_get_capability_freq(wpa_s, buf, buflen);
3425 if (os_strcmp(field, "tdls") == 0)
3426 return ctrl_iface_get_capability_tdls(wpa_s, buf, buflen);
3427 #endif /* CONFIG_TDLS */
3429 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
3436 #ifdef CONFIG_INTERWORKING
3437 static char * anqp_add_hex(char *pos, char *end, const char *title,
3438 struct wpabuf *data)
3448 ret = os_snprintf(pos, end - pos, "%s=", title);
3449 if (ret < 0 || ret >= end - pos)
3453 d = wpabuf_head_u8(data);
3454 for (i = 0; i < wpabuf_len(data); i++) {
3455 ret = os_snprintf(pos, end - pos, "%02x", *d++);
3456 if (ret < 0 || ret >= end - pos)
3461 ret = os_snprintf(pos, end - pos, "\n");
3462 if (ret < 0 || ret >= end - pos)
3468 #endif /* CONFIG_INTERWORKING */
3471 static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
3472 unsigned long mask, char *buf, size_t buflen)
3482 if (mask & WPA_BSS_MASK_ID) {
3483 ret = os_snprintf(pos, end - pos, "id=%u\n", bss->id);
3484 if (ret < 0 || ret >= end - pos)
3489 if (mask & WPA_BSS_MASK_BSSID) {
3490 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
3491 MAC2STR(bss->bssid));
3492 if (ret < 0 || ret >= end - pos)
3497 if (mask & WPA_BSS_MASK_FREQ) {
3498 ret = os_snprintf(pos, end - pos, "freq=%d\n", bss->freq);
3499 if (ret < 0 || ret >= end - pos)
3504 if (mask & WPA_BSS_MASK_BEACON_INT) {
3505 ret = os_snprintf(pos, end - pos, "beacon_int=%d\n",
3507 if (ret < 0 || ret >= end - pos)
3512 if (mask & WPA_BSS_MASK_CAPABILITIES) {
3513 ret = os_snprintf(pos, end - pos, "capabilities=0x%04x\n",
3515 if (ret < 0 || ret >= end - pos)
3520 if (mask & WPA_BSS_MASK_QUAL) {
3521 ret = os_snprintf(pos, end - pos, "qual=%d\n", bss->qual);
3522 if (ret < 0 || ret >= end - pos)
3527 if (mask & WPA_BSS_MASK_NOISE) {
3528 ret = os_snprintf(pos, end - pos, "noise=%d\n", bss->noise);
3529 if (ret < 0 || ret >= end - pos)
3534 if (mask & WPA_BSS_MASK_LEVEL) {
3535 ret = os_snprintf(pos, end - pos, "level=%d\n", bss->level);
3536 if (ret < 0 || ret >= end - pos)
3541 if (mask & WPA_BSS_MASK_TSF) {
3542 ret = os_snprintf(pos, end - pos, "tsf=%016llu\n",
3543 (unsigned long long) bss->tsf);
3544 if (ret < 0 || ret >= end - pos)
3549 if (mask & WPA_BSS_MASK_AGE) {
3550 struct os_reltime now;
3552 os_get_reltime(&now);
3553 ret = os_snprintf(pos, end - pos, "age=%d\n",
3554 (int) (now.sec - bss->last_update.sec));
3555 if (ret < 0 || ret >= end - pos)
3560 if (mask & WPA_BSS_MASK_IE) {
3561 ret = os_snprintf(pos, end - pos, "ie=");
3562 if (ret < 0 || ret >= end - pos)
3566 ie = (const u8 *) (bss + 1);
3567 for (i = 0; i < bss->ie_len; i++) {
3568 ret = os_snprintf(pos, end - pos, "%02x", *ie++);
3569 if (ret < 0 || ret >= end - pos)
3574 ret = os_snprintf(pos, end - pos, "\n");
3575 if (ret < 0 || ret >= end - pos)
3580 if (mask & WPA_BSS_MASK_FLAGS) {
3581 ret = os_snprintf(pos, end - pos, "flags=");
3582 if (ret < 0 || ret >= end - pos)
3586 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
3588 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie,
3590 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
3592 pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2,
3594 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
3595 if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
3596 ret = os_snprintf(pos, end - pos, "[WEP]");
3597 if (ret < 0 || ret >= end - pos)
3601 if (bss_is_dmg(bss)) {
3603 ret = os_snprintf(pos, end - pos, "[DMG]");
3604 if (ret < 0 || ret >= end - pos)
3607 switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
3608 case IEEE80211_CAP_DMG_IBSS:
3611 case IEEE80211_CAP_DMG_AP:
3614 case IEEE80211_CAP_DMG_PBSS:
3621 ret = os_snprintf(pos, end - pos, "%s", s);
3622 if (ret < 0 || ret >= end - pos)
3626 if (bss->caps & IEEE80211_CAP_IBSS) {
3627 ret = os_snprintf(pos, end - pos, "[IBSS]");
3628 if (ret < 0 || ret >= end - pos)
3632 if (bss->caps & IEEE80211_CAP_ESS) {
3633 ret = os_snprintf(pos, end - pos, "[ESS]");
3634 if (ret < 0 || ret >= end - pos)
3639 if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
3640 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
3641 ret = os_snprintf(pos, end - pos, "[P2P]");
3642 if (ret < 0 || ret >= end - pos)
3647 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) {
3648 ret = os_snprintf(pos, end - pos, "[HS20]");
3649 if (ret < 0 || ret >= end - pos)
3653 #endif /* CONFIG_HS20 */
3655 ret = os_snprintf(pos, end - pos, "\n");
3656 if (ret < 0 || ret >= end - pos)
3661 if (mask & WPA_BSS_MASK_SSID) {
3662 ret = os_snprintf(pos, end - pos, "ssid=%s\n",
3663 wpa_ssid_txt(bss->ssid, bss->ssid_len));
3664 if (ret < 0 || ret >= end - pos)
3670 if (mask & WPA_BSS_MASK_WPS_SCAN) {
3671 ie = (const u8 *) (bss + 1);
3672 ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end);
3673 if (ret < 0 || ret >= end - pos)
3677 #endif /* CONFIG_WPS */
3680 if (mask & WPA_BSS_MASK_P2P_SCAN) {
3681 ie = (const u8 *) (bss + 1);
3682 ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end);
3683 if (ret < 0 || ret >= end - pos)
3687 #endif /* CONFIG_P2P */
3689 #ifdef CONFIG_WIFI_DISPLAY
3690 if (mask & WPA_BSS_MASK_WIFI_DISPLAY) {
3692 ie = (const u8 *) (bss + 1);
3693 wfd = ieee802_11_vendor_ie_concat(ie, bss->ie_len,
3694 WFD_IE_VENDOR_TYPE);
3696 ret = os_snprintf(pos, end - pos, "wfd_subelems=");
3697 if (ret < 0 || ret >= end - pos) {
3703 pos += wpa_snprintf_hex(pos, end - pos,
3708 ret = os_snprintf(pos, end - pos, "\n");
3709 if (ret < 0 || ret >= end - pos)
3714 #endif /* CONFIG_WIFI_DISPLAY */
3716 #ifdef CONFIG_INTERWORKING
3717 if ((mask & WPA_BSS_MASK_INTERNETW) && bss->anqp) {
3718 struct wpa_bss_anqp *anqp = bss->anqp;
3719 pos = anqp_add_hex(pos, end, "anqp_venue_name",
3721 pos = anqp_add_hex(pos, end, "anqp_network_auth_type",
3722 anqp->network_auth_type);
3723 pos = anqp_add_hex(pos, end, "anqp_roaming_consortium",
3724 anqp->roaming_consortium);
3725 pos = anqp_add_hex(pos, end, "anqp_ip_addr_type_availability",
3726 anqp->ip_addr_type_availability);
3727 pos = anqp_add_hex(pos, end, "anqp_nai_realm",
3729 pos = anqp_add_hex(pos, end, "anqp_3gpp", anqp->anqp_3gpp);
3730 pos = anqp_add_hex(pos, end, "anqp_domain_name",
3733 pos = anqp_add_hex(pos, end, "hs20_operator_friendly_name",
3734 anqp->hs20_operator_friendly_name);
3735 pos = anqp_add_hex(pos, end, "hs20_wan_metrics",
3736 anqp->hs20_wan_metrics);
3737 pos = anqp_add_hex(pos, end, "hs20_connection_capability",
3738 anqp->hs20_connection_capability);
3739 pos = anqp_add_hex(pos, end, "hs20_operating_class",
3740 anqp->hs20_operating_class);
3741 pos = anqp_add_hex(pos, end, "hs20_osu_providers_list",
3742 anqp->hs20_osu_providers_list);
3743 #endif /* CONFIG_HS20 */
3745 #endif /* CONFIG_INTERWORKING */
3747 if (mask & WPA_BSS_MASK_DELIM) {
3748 ret = os_snprintf(pos, end - pos, "====\n");
3749 if (ret < 0 || ret >= end - pos)
3758 static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
3759 const char *cmd, char *buf,
3764 struct wpa_bss *bss;
3765 struct wpa_bss *bsslast = NULL;
3766 struct dl_list *next;
3770 unsigned long mask = WPA_BSS_MASK_ALL;
3772 if (os_strncmp(cmd, "RANGE=", 6) == 0) {
3773 if (os_strncmp(cmd + 6, "ALL", 3) == 0) {
3774 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss,
3776 bsslast = dl_list_last(&wpa_s->bss_id, struct wpa_bss,
3778 } else { /* N1-N2 */
3779 unsigned int id1, id2;
3781 if ((ctmp = os_strchr(cmd + 6, '-')) == NULL) {
3782 wpa_printf(MSG_INFO, "Wrong BSS range "
3787 if (*(cmd + 6) == '-')
3790 id1 = atoi(cmd + 6);
3792 if (*ctmp >= '0' && *ctmp <= '9')
3795 id2 = (unsigned int) -1;
3796 bss = wpa_bss_get_id_range(wpa_s, id1, id2);
3797 if (id2 == (unsigned int) -1)
3798 bsslast = dl_list_last(&wpa_s->bss_id,
3802 bsslast = wpa_bss_get_id(wpa_s, id2);
3803 if (bsslast == NULL && bss && id2 > id1) {
3804 struct wpa_bss *tmp = bss;
3806 next = tmp->list_id.next;
3807 if (next == &wpa_s->bss_id)
3809 tmp = dl_list_entry(
3810 next, struct wpa_bss,
3819 } else if (os_strncmp(cmd, "FIRST", 5) == 0)
3820 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, list_id);
3821 else if (os_strncmp(cmd, "LAST", 4) == 0)
3822 bss = dl_list_last(&wpa_s->bss_id, struct wpa_bss, list_id);
3823 else if (os_strncmp(cmd, "ID-", 3) == 0) {
3825 bss = wpa_bss_get_id(wpa_s, i);
3826 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
3828 bss = wpa_bss_get_id(wpa_s, i);
3830 next = bss->list_id.next;
3831 if (next == &wpa_s->bss_id)
3834 bss = dl_list_entry(next, struct wpa_bss,
3838 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
3839 if (hwaddr_aton(cmd + 13, bssid) == 0)
3840 bss = wpa_bss_get_p2p_dev_addr(wpa_s, bssid);
3843 #endif /* CONFIG_P2P */
3844 } else if (hwaddr_aton(cmd, bssid) == 0)
3845 bss = wpa_bss_get_bssid(wpa_s, bssid);
3847 struct wpa_bss *tmp;
3850 dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id)
3859 if ((ctmp = os_strstr(cmd, "MASK=")) != NULL) {
3860 mask = strtoul(ctmp + 5, NULL, 0x10);
3862 mask = WPA_BSS_MASK_ALL;
3868 if (bsslast == NULL)
3871 len = print_bss_info(wpa_s, bss, mask, buf, buflen);
3875 if (bss == bsslast) {
3876 if ((mask & WPA_BSS_MASK_DELIM) && len &&
3877 (bss == dl_list_last(&wpa_s->bss_id,
3878 struct wpa_bss, list_id)))
3879 os_snprintf(buf - 5, 5, "####\n");
3882 next = bss->list_id.next;
3883 if (next == &wpa_s->bss_id)
3885 bss = dl_list_entry(next, struct wpa_bss, list_id);
3886 } while (bss && len);
3892 static int wpa_supplicant_ctrl_iface_ap_scan(
3893 struct wpa_supplicant *wpa_s, char *cmd)
3895 int ap_scan = atoi(cmd);
3896 return wpa_supplicant_set_ap_scan(wpa_s, ap_scan);
3900 static int wpa_supplicant_ctrl_iface_scan_interval(
3901 struct wpa_supplicant *wpa_s, char *cmd)
3903 int scan_int = atoi(cmd);
3904 return wpa_supplicant_set_scan_interval(wpa_s, scan_int);
3908 static int wpa_supplicant_ctrl_iface_bss_expire_age(
3909 struct wpa_supplicant *wpa_s, char *cmd)
3911 int expire_age = atoi(cmd);
3912 return wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age);
3916 static int wpa_supplicant_ctrl_iface_bss_expire_count(
3917 struct wpa_supplicant *wpa_s, char *cmd)
3919 int expire_count = atoi(cmd);
3920 return wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count);
3924 static int wpa_supplicant_ctrl_iface_bss_flush(
3925 struct wpa_supplicant *wpa_s, char *cmd)
3927 int flush_age = atoi(cmd);
3930 wpa_bss_flush(wpa_s);
3932 wpa_bss_flush_by_age(wpa_s, flush_age);
3937 #ifdef CONFIG_TESTING_OPTIONS
3938 static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s)
3940 wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication");
3941 /* MLME-DELETEKEYS.request */
3942 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL, 0);
3943 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL, 0);
3944 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL, 0);
3945 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL, 0);
3946 #ifdef CONFIG_IEEE80211W
3947 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL, 0);
3948 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL, 0);
3949 #endif /* CONFIG_IEEE80211W */
3951 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, wpa_s->bssid, 0, 0, NULL, 0, NULL,
3953 /* MLME-SETPROTECTION.request(None) */
3954 wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid,
3955 MLME_SETPROTECTION_PROTECT_TYPE_NONE,
3956 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE);
3957 wpa_sm_drop_sa(wpa_s->wpa);
3959 #endif /* CONFIG_TESTING_OPTIONS */
3962 static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s,
3965 #ifdef CONFIG_NO_SCAN_PROCESSING
3967 #else /* CONFIG_NO_SCAN_PROCESSING */
3969 struct wpa_bss *bss;
3970 struct wpa_ssid *ssid = wpa_s->current_ssid;
3972 if (hwaddr_aton(addr, bssid)) {
3973 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid "
3974 "address '%s'", addr);
3978 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR, MAC2STR(bssid));
3981 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network "
3982 "configuration known for the target AP");
3986 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
3988 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found "
3994 * TODO: Find best network configuration block from configuration to
3995 * allow roaming to other networks
3998 wpa_s->reassociate = 1;
3999 wpa_supplicant_connect(wpa_s, bss, ssid);
4002 #endif /* CONFIG_NO_SCAN_PROCESSING */
4007 static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd)
4009 unsigned int timeout = atoi(cmd);
4010 enum p2p_discovery_type type = P2P_FIND_START_WITH_FULL;
4011 u8 dev_id[ETH_ALEN], *_dev_id = NULL;
4012 u8 dev_type[WPS_DEV_TYPE_LEN], *_dev_type = NULL;
4014 unsigned int search_delay;
4016 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
4017 wpa_dbg(wpa_s, MSG_INFO,
4018 "Reject P2P_FIND since interface is disabled");
4021 if (os_strstr(cmd, "type=social"))
4022 type = P2P_FIND_ONLY_SOCIAL;
4023 else if (os_strstr(cmd, "type=progressive"))
4024 type = P2P_FIND_PROGRESSIVE;
4026 pos = os_strstr(cmd, "dev_id=");
4029 if (hwaddr_aton(pos, dev_id))
4034 pos = os_strstr(cmd, "dev_type=");
4037 if (wps_dev_type_str2bin(pos, dev_type) < 0)
4039 _dev_type = dev_type;
4042 pos = os_strstr(cmd, "delay=");
4045 search_delay = atoi(pos);
4047 search_delay = wpas_p2p_search_delay(wpa_s);
4049 return wpas_p2p_find(wpa_s, timeout, type, _dev_type != NULL, _dev_type,
4050 _dev_id, search_delay);
4054 static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd,
4055 char *buf, size_t buflen)
4060 enum p2p_wps_method wps_method;
4063 int persistent_group, persistent_id = -1;
4072 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad]
4073 * [persistent|persistent=<network id>]
4074 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
4077 if (hwaddr_aton(cmd, addr))
4085 persistent_group = os_strstr(pos, " persistent") != NULL;
4086 pos2 = os_strstr(pos, " persistent=");
4088 struct wpa_ssid *ssid;
4089 persistent_id = atoi(pos2 + 12);
4090 ssid = wpa_config_get_network(wpa_s->conf, persistent_id);
4091 if (ssid == NULL || ssid->disabled != 2 ||
4092 ssid->mode != WPAS_MODE_P2P_GO) {
4093 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
4094 "SSID id=%d for persistent P2P group (GO)",
4099 join = os_strstr(pos, " join") != NULL;
4100 auth = os_strstr(pos, " auth") != NULL;
4101 automatic = os_strstr(pos, " auto") != NULL;
4102 pd = os_strstr(pos, " provdisc") != NULL;
4103 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
4104 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
4107 pos2 = os_strstr(pos, " go_intent=");
4110 go_intent = atoi(pos2);
4111 if (go_intent < 0 || go_intent > 15)
4115 pos2 = os_strstr(pos, " freq=");
4123 if (os_strncmp(pos, "pin", 3) == 0) {
4124 /* Request random PIN (to be displayed) and enable the PIN */
4125 wps_method = WPS_PIN_DISPLAY;
4126 } else if (os_strncmp(pos, "pbc", 3) == 0) {
4127 wps_method = WPS_PBC;
4130 pos = os_strchr(pin, ' ');
4131 wps_method = WPS_PIN_KEYPAD;
4134 if (os_strncmp(pos, "display", 7) == 0)
4135 wps_method = WPS_PIN_DISPLAY;
4137 if (!wps_pin_str_valid(pin)) {
4138 os_memcpy(buf, "FAIL-INVALID-PIN\n", 17);
4143 new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method,
4144 persistent_group, automatic, join,
4145 auth, go_intent, freq, persistent_id, pd,
4147 if (new_pin == -2) {
4148 os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
4151 if (new_pin == -3) {
4152 os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
4157 if (wps_method == WPS_PIN_DISPLAY && pin == NULL) {
4158 ret = os_snprintf(buf, buflen, "%08d", new_pin);
4159 if (ret < 0 || (size_t) ret >= buflen)
4164 os_memcpy(buf, "OK\n", 3);
4169 static int p2p_ctrl_listen(struct wpa_supplicant *wpa_s, char *cmd)
4171 unsigned int timeout = atoi(cmd);
4172 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
4173 wpa_dbg(wpa_s, MSG_INFO,
4174 "Reject P2P_LISTEN since interface is disabled");
4177 return wpas_p2p_listen(wpa_s, timeout);
4181 static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd)
4185 enum wpas_p2p_prov_disc_use use = WPAS_P2P_PD_FOR_GO_NEG;
4187 /* <addr> <config method> [join|auto] */
4189 if (hwaddr_aton(cmd, addr))
4197 if (os_strstr(pos, " join") != NULL)
4198 use = WPAS_P2P_PD_FOR_JOIN;
4199 else if (os_strstr(pos, " auto") != NULL)
4200 use = WPAS_P2P_PD_AUTO;
4202 return wpas_p2p_prov_disc(wpa_s, addr, pos, use);
4206 static int p2p_get_passphrase(struct wpa_supplicant *wpa_s, char *buf,
4209 struct wpa_ssid *ssid = wpa_s->current_ssid;
4211 if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO ||
4212 ssid->passphrase == NULL)
4215 os_strlcpy(buf, ssid->passphrase, buflen);
4216 return os_strlen(buf);
4220 static int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd,
4221 char *buf, size_t buflen)
4225 u8 dst_buf[ETH_ALEN], *dst;
4226 struct wpabuf *tlvs;
4230 if (hwaddr_aton(cmd, dst_buf))
4233 if (dst[0] == 0 && dst[1] == 0 && dst[2] == 0 &&
4234 dst[3] == 0 && dst[4] == 0 && dst[5] == 0)
4241 if (os_strncmp(pos, "upnp ", 5) == 0) {
4244 if (hexstr2bin(pos, &version, 1) < 0)
4250 ref = wpas_p2p_sd_request_upnp(wpa_s, dst, version, pos);
4251 #ifdef CONFIG_WIFI_DISPLAY
4252 } else if (os_strncmp(pos, "wifi-display ", 13) == 0) {
4253 ref = wpas_p2p_sd_request_wifi_display(wpa_s, dst, pos + 13);
4254 #endif /* CONFIG_WIFI_DISPLAY */
4256 len = os_strlen(pos);
4260 tlvs = wpabuf_alloc(len);
4263 if (hexstr2bin(pos, wpabuf_put(tlvs, len), len) < 0) {
4268 ref = wpas_p2p_sd_request(wpa_s, dst, tlvs);
4273 res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref);
4274 if (res < 0 || (unsigned) res >= buflen)
4280 static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s,
4283 long long unsigned val;
4285 if (sscanf(cmd, "%llx", &val) != 1)
4288 return wpas_p2p_sd_cancel_request(wpa_s, req);
4292 static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant *wpa_s, char *cmd)
4297 struct wpabuf *resp_tlvs;
4301 pos = os_strchr(cmd, ' ');
4309 if (hwaddr_aton(pos, dst))
4316 pos2 = os_strchr(pos, ' ');
4320 dialog_token = atoi(pos);
4322 len = os_strlen(pos2);
4326 resp_tlvs = wpabuf_alloc(len);
4327 if (resp_tlvs == NULL)
4329 if (hexstr2bin(pos2, wpabuf_put(resp_tlvs, len), len) < 0) {
4330 wpabuf_free(resp_tlvs);
4334 wpas_p2p_sd_response(wpa_s, freq, dst, dialog_token, resp_tlvs);
4335 wpabuf_free(resp_tlvs);
4340 static int p2p_ctrl_serv_disc_external(struct wpa_supplicant *wpa_s,
4343 if (os_strcmp(cmd, "0") && os_strcmp(cmd, "1"))
4345 wpa_s->p2p_sd_over_ctrl_iface = atoi(cmd);
4350 static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant *wpa_s,
4355 struct wpabuf *query, *resp;
4357 pos = os_strchr(cmd, ' ');
4362 len = os_strlen(cmd);
4366 query = wpabuf_alloc(len);
4369 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
4374 len = os_strlen(pos);
4380 resp = wpabuf_alloc(len);
4385 if (hexstr2bin(pos, wpabuf_put(resp, len), len) < 0) {
4391 if (wpas_p2p_service_add_bonjour(wpa_s, query, resp) < 0) {
4400 static int p2p_ctrl_service_add_upnp(struct wpa_supplicant *wpa_s, char *cmd)
4405 pos = os_strchr(cmd, ' ');
4410 if (hexstr2bin(cmd, &version, 1) < 0)
4413 return wpas_p2p_service_add_upnp(wpa_s, version, pos);
4417 static int p2p_ctrl_service_add(struct wpa_supplicant *wpa_s, char *cmd)
4421 pos = os_strchr(cmd, ' ');
4426 if (os_strcmp(cmd, "bonjour") == 0)
4427 return p2p_ctrl_service_add_bonjour(wpa_s, pos);
4428 if (os_strcmp(cmd, "upnp") == 0)
4429 return p2p_ctrl_service_add_upnp(wpa_s, pos);
4430 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
4435 static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant *wpa_s,
4439 struct wpabuf *query;
4442 len = os_strlen(cmd);
4446 query = wpabuf_alloc(len);
4449 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
4454 ret = wpas_p2p_service_del_bonjour(wpa_s, query);
4460 static int p2p_ctrl_service_del_upnp(struct wpa_supplicant *wpa_s, char *cmd)
4465 pos = os_strchr(cmd, ' ');
4470 if (hexstr2bin(cmd, &version, 1) < 0)
4473 return wpas_p2p_service_del_upnp(wpa_s, version, pos);
4477 static int p2p_ctrl_service_del(struct wpa_supplicant *wpa_s, char *cmd)
4481 pos = os_strchr(cmd, ' ');
4486 if (os_strcmp(cmd, "bonjour") == 0)
4487 return p2p_ctrl_service_del_bonjour(wpa_s, pos);
4488 if (os_strcmp(cmd, "upnp") == 0)
4489 return p2p_ctrl_service_del_upnp(wpa_s, pos);
4490 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
4495 static int p2p_ctrl_reject(struct wpa_supplicant *wpa_s, char *cmd)
4501 if (hwaddr_aton(cmd, addr))
4504 return wpas_p2p_reject(wpa_s, addr);
4508 static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd)
4512 struct wpa_ssid *ssid;
4513 u8 *_peer = NULL, peer[ETH_ALEN];
4514 int freq = 0, pref_freq = 0;
4518 pos = os_strstr(cmd, " peer=");
4521 if (hwaddr_aton(pos, peer))
4525 ssid = wpa_config_get_network(wpa_s->conf, id);
4526 if (ssid == NULL || ssid->disabled != 2) {
4527 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
4528 "for persistent P2P group",
4533 pos = os_strstr(cmd, " freq=");
4541 pos = os_strstr(cmd, " pref=");
4544 pref_freq = atoi(pos);
4549 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
4550 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
4553 return wpas_p2p_invite(wpa_s, _peer, ssid, NULL, freq, ht40, vht,
4558 static int p2p_ctrl_invite_group(struct wpa_supplicant *wpa_s, char *cmd)
4561 u8 peer[ETH_ALEN], go_dev_addr[ETH_ALEN], *go_dev = NULL;
4563 pos = os_strstr(cmd, " peer=");
4569 if (hwaddr_aton(pos, peer)) {
4570 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", pos);
4574 pos = os_strstr(pos, " go_dev_addr=");
4577 if (hwaddr_aton(pos, go_dev_addr)) {
4578 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'",
4582 go_dev = go_dev_addr;
4585 return wpas_p2p_invite_group(wpa_s, cmd, peer, go_dev);
4589 static int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd)
4591 if (os_strncmp(cmd, "persistent=", 11) == 0)
4592 return p2p_ctrl_invite_persistent(wpa_s, cmd + 11);
4593 if (os_strncmp(cmd, "group=", 6) == 0)
4594 return p2p_ctrl_invite_group(wpa_s, cmd + 6);
4600 static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s,
4601 char *cmd, int freq, int ht40,
4605 struct wpa_ssid *ssid;
4608 ssid = wpa_config_get_network(wpa_s->conf, id);
4609 if (ssid == NULL || ssid->disabled != 2) {
4610 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
4611 "for persistent P2P group",
4616 return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq, 0, ht40, vht,
4621 static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd)
4623 int freq = 0, ht40, vht;
4626 pos = os_strstr(cmd, "freq=");
4628 freq = atoi(pos + 5);
4630 vht = (os_strstr(cmd, "vht") != NULL) || wpa_s->conf->p2p_go_vht;
4631 ht40 = (os_strstr(cmd, "ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
4634 if (os_strncmp(cmd, "persistent=", 11) == 0)
4635 return p2p_ctrl_group_add_persistent(wpa_s, cmd + 11, freq,
4637 if (os_strcmp(cmd, "persistent") == 0 ||
4638 os_strncmp(cmd, "persistent ", 11) == 0)
4639 return wpas_p2p_group_add(wpa_s, 1, freq, ht40, vht);
4640 if (os_strncmp(cmd, "freq=", 5) == 0)
4641 return wpas_p2p_group_add(wpa_s, 0, freq, ht40, vht);
4643 return wpas_p2p_group_add(wpa_s, 0, freq, ht40, vht);
4645 wpa_printf(MSG_DEBUG, "CTRL: Invalid P2P_GROUP_ADD parameters '%s'",
4651 static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd,
4652 char *buf, size_t buflen)
4654 u8 addr[ETH_ALEN], *addr_ptr;
4656 const struct p2p_peer_info *info;
4658 char devtype[WPS_DEV_TYPE_BUFSIZE];
4659 struct wpa_ssid *ssid;
4662 if (!wpa_s->global->p2p)
4665 if (os_strcmp(cmd, "FIRST") == 0) {
4668 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
4669 if (hwaddr_aton(cmd + 5, addr) < 0)
4674 if (hwaddr_aton(cmd, addr) < 0)
4680 info = p2p_get_peer_info(wpa_s->global->p2p, addr_ptr, next);
4687 res = os_snprintf(pos, end - pos, MACSTR "\n"
4693 "serial_number=%s\n"
4694 "config_methods=0x%x\n"
4696 "group_capab=0x%x\n"
4698 MAC2STR(info->p2p_device_addr),
4699 wps_dev_type_bin2str(info->pri_dev_type,
4700 devtype, sizeof(devtype)),
4705 info->serial_number,
4706 info->config_methods,
4710 if (res < 0 || res >= end - pos)
4714 for (i = 0; i < info->wps_sec_dev_type_list_len / WPS_DEV_TYPE_LEN; i++)
4717 t = &info->wps_sec_dev_type_list[i * WPS_DEV_TYPE_LEN];
4718 res = os_snprintf(pos, end - pos, "sec_dev_type=%s\n",
4719 wps_dev_type_bin2str(t, devtype,
4721 if (res < 0 || res >= end - pos)
4726 ssid = wpas_p2p_get_persistent(wpa_s, info->p2p_device_addr, NULL, 0);
4728 res = os_snprintf(pos, end - pos, "persistent=%d\n", ssid->id);
4729 if (res < 0 || res >= end - pos)
4734 res = p2p_get_peer_info_txt(info, pos, end - pos);
4739 if (info->vendor_elems) {
4740 res = os_snprintf(pos, end - pos, "vendor_elems=");
4741 if (res < 0 || res >= end - pos)
4745 pos += wpa_snprintf_hex(pos, end - pos,
4746 wpabuf_head(info->vendor_elems),
4747 wpabuf_len(info->vendor_elems));
4749 res = os_snprintf(pos, end - pos, "\n");
4750 if (res < 0 || res >= end - pos)
4759 static int p2p_ctrl_disallow_freq(struct wpa_supplicant *wpa_s,
4764 if (wpa_s->global->p2p == NULL)
4767 if (freq_range_list_parse(&wpa_s->global->p2p_disallow_freq, param) < 0)
4770 for (i = 0; i < wpa_s->global->p2p_disallow_freq.num; i++) {
4771 struct wpa_freq_range *freq;
4772 freq = &wpa_s->global->p2p_disallow_freq.range[i];
4773 wpa_printf(MSG_DEBUG, "P2P: Disallowed frequency range %u-%u",
4774 freq->min, freq->max);
4777 wpas_p2p_update_channel_list(wpa_s);
4782 static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd)
4786 if (wpa_s->global->p2p == NULL)
4789 param = os_strchr(cmd, ' ');
4794 if (os_strcmp(cmd, "discoverability") == 0) {
4795 p2p_set_client_discoverability(wpa_s->global->p2p,
4800 if (os_strcmp(cmd, "managed") == 0) {
4801 p2p_set_managed_oper(wpa_s->global->p2p, atoi(param));
4805 if (os_strcmp(cmd, "listen_channel") == 0) {
4806 return p2p_set_listen_channel(wpa_s->global->p2p, 81,
4810 if (os_strcmp(cmd, "ssid_postfix") == 0) {
4811 return p2p_set_ssid_postfix(wpa_s->global->p2p, (u8 *) param,
4815 if (os_strcmp(cmd, "noa") == 0) {
4817 int count, start, duration;
4818 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
4819 count = atoi(param);
4820 pos = os_strchr(param, ',');
4825 pos = os_strchr(pos, ',');
4829 duration = atoi(pos);
4830 if (count < 0 || count > 255 || start < 0 || duration < 0)
4832 if (count == 0 && duration > 0)
4834 wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
4835 "start=%d duration=%d", count, start, duration);
4836 return wpas_p2p_set_noa(wpa_s, count, start, duration);
4839 if (os_strcmp(cmd, "ps") == 0)
4840 return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1);
4842 if (os_strcmp(cmd, "oppps") == 0)
4843 return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1);
4845 if (os_strcmp(cmd, "ctwindow") == 0)
4846 return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param));
4848 if (os_strcmp(cmd, "disabled") == 0) {
4849 wpa_s->global->p2p_disabled = atoi(param);
4850 wpa_printf(MSG_DEBUG, "P2P functionality %s",
4851 wpa_s->global->p2p_disabled ?
4852 "disabled" : "enabled");
4853 if (wpa_s->global->p2p_disabled) {
4854 wpas_p2p_stop_find(wpa_s);
4855 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
4856 p2p_flush(wpa_s->global->p2p);
4861 if (os_strcmp(cmd, "conc_pref") == 0) {
4862 if (os_strcmp(param, "sta") == 0)
4863 wpa_s->global->conc_pref = WPA_CONC_PREF_STA;
4864 else if (os_strcmp(param, "p2p") == 0)
4865 wpa_s->global->conc_pref = WPA_CONC_PREF_P2P;
4867 wpa_printf(MSG_INFO, "Invalid conc_pref value");
4870 wpa_printf(MSG_DEBUG, "Single channel concurrency preference: "
4875 if (os_strcmp(cmd, "force_long_sd") == 0) {
4876 wpa_s->force_long_sd = atoi(param);
4880 if (os_strcmp(cmd, "peer_filter") == 0) {
4882 if (hwaddr_aton(param, addr))
4884 p2p_set_peer_filter(wpa_s->global->p2p, addr);
4888 if (os_strcmp(cmd, "cross_connect") == 0)
4889 return wpas_p2p_set_cross_connect(wpa_s, atoi(param));
4891 if (os_strcmp(cmd, "go_apsd") == 0) {
4892 if (os_strcmp(param, "disable") == 0)
4893 wpa_s->set_ap_uapsd = 0;
4895 wpa_s->set_ap_uapsd = 1;
4896 wpa_s->ap_uapsd = atoi(param);
4901 if (os_strcmp(cmd, "client_apsd") == 0) {
4902 if (os_strcmp(param, "disable") == 0)
4903 wpa_s->set_sta_uapsd = 0;
4907 /* format: BE,BK,VI,VO;max SP Length */
4909 pos = os_strchr(param, ',');
4914 pos = os_strchr(pos, ',');
4919 pos = os_strchr(pos, ',');
4924 /* ignore max SP Length for now */
4926 wpa_s->set_sta_uapsd = 1;
4927 wpa_s->sta_uapsd = 0;
4929 wpa_s->sta_uapsd |= BIT(0);
4931 wpa_s->sta_uapsd |= BIT(1);
4933 wpa_s->sta_uapsd |= BIT(2);
4935 wpa_s->sta_uapsd |= BIT(3);
4940 if (os_strcmp(cmd, "disallow_freq") == 0)
4941 return p2p_ctrl_disallow_freq(wpa_s, param);
4943 if (os_strcmp(cmd, "disc_int") == 0) {
4944 int min_disc_int, max_disc_int, max_disc_tu;
4949 min_disc_int = atoi(pos);
4950 pos = os_strchr(pos, ' ');
4955 max_disc_int = atoi(pos);
4956 pos = os_strchr(pos, ' ');
4961 max_disc_tu = atoi(pos);
4963 return p2p_set_disc_int(wpa_s->global->p2p, min_disc_int,
4964 max_disc_int, max_disc_tu);
4967 if (os_strcmp(cmd, "per_sta_psk") == 0) {
4968 wpa_s->global->p2p_per_sta_psk = !!atoi(param);
4972 #ifdef CONFIG_WPS_NFC
4973 if (os_strcmp(cmd, "nfc_tag") == 0)
4974 return wpas_p2p_nfc_tag_enabled(wpa_s, !!atoi(param));
4975 #endif /* CONFIG_WPS_NFC */
4977 if (os_strcmp(cmd, "disable_ip_addr_req") == 0) {
4978 wpa_s->p2p_disable_ip_addr_req = !!atoi(param);
4982 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
4989 static void p2p_ctrl_flush(struct wpa_supplicant *wpa_s)
4991 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
4992 wpa_s->force_long_sd = 0;
4993 if (wpa_s->global->p2p)
4994 p2p_flush(wpa_s->global->p2p);
4998 static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd)
5001 unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0;
5004 pos = os_strchr(cmd, ' ');
5010 pos2 = os_strchr(pos, ' ');
5018 pos = os_strchr(pos2, ' ');
5026 return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2);
5030 static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd)
5033 unsigned int period = 0, interval = 0;
5036 pos = os_strchr(cmd, ' ');
5041 interval = atoi(pos);
5044 return wpas_p2p_ext_listen(wpa_s, period, interval);
5048 static int p2p_ctrl_remove_client(struct wpa_supplicant *wpa_s, const char *cmd)
5055 if (os_strncmp(pos, "iface=", 6) == 0) {
5059 if (hwaddr_aton(pos, peer))
5062 wpas_p2p_remove_client(wpa_s, peer, iface_addr);
5066 #endif /* CONFIG_P2P */
5069 static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s, char *val)
5071 struct wpa_freq_range_list ranges;
5073 struct hostapd_hw_modes *mode;
5076 if (wpa_s->hw.modes == NULL)
5079 os_memset(&ranges, 0, sizeof(ranges));
5080 if (freq_range_list_parse(&ranges, val) < 0)
5083 for (i = 0; i < wpa_s->hw.num_modes; i++) {
5086 mode = &wpa_s->hw.modes[i];
5087 for (j = 0; j < mode->num_channels; j++) {
5090 if (mode->channels[j].flag & HOSTAPD_CHAN_DISABLED)
5093 freq = mode->channels[j].freq;
5094 if (!freq_range_list_includes(&ranges, freq))
5097 int_array_add_unique(&freqs, freq);
5101 os_free(ranges.range);
5106 #ifdef CONFIG_INTERWORKING
5108 static int ctrl_interworking_select(struct wpa_supplicant *wpa_s, char *param)
5116 auto_sel = os_strstr(param, "auto") != NULL;
5118 pos = os_strstr(param, "freq=");
5120 freqs = freq_range_to_channel_list(wpa_s, pos + 5);
5127 return interworking_select(wpa_s, auto_sel, freqs);
5131 static int ctrl_interworking_connect(struct wpa_supplicant *wpa_s, char *dst)
5134 struct wpa_bss *bss;
5136 if (hwaddr_aton(dst, bssid)) {
5137 wpa_printf(MSG_DEBUG, "Invalid BSSID '%s'", dst);
5141 bss = wpa_bss_get_bssid(wpa_s, bssid);
5143 wpa_printf(MSG_DEBUG, "Could not find BSS " MACSTR,
5148 return interworking_connect(wpa_s, bss);
5152 static int get_anqp(struct wpa_supplicant *wpa_s, char *dst)
5154 u8 dst_addr[ETH_ALEN];
5157 #define MAX_ANQP_INFO_ID 100
5158 u16 id[MAX_ANQP_INFO_ID];
5162 used = hwaddr_aton2(dst, dst_addr);
5166 while (num_id < MAX_ANQP_INFO_ID) {
5167 if (os_strncmp(pos, "hs20:", 5) == 0) {
5169 int num = atoi(pos + 5);
5170 if (num <= 0 || num > 31)
5172 subtypes |= BIT(num);
5173 #else /* CONFIG_HS20 */
5175 #endif /* CONFIG_HS20 */
5177 id[num_id] = atoi(pos);
5181 pos = os_strchr(pos + 1, ',');
5190 return anqp_send_req(wpa_s, dst_addr, id, num_id, subtypes);
5194 static int gas_request(struct wpa_supplicant *wpa_s, char *cmd)
5196 u8 dst_addr[ETH_ALEN];
5197 struct wpabuf *advproto, *query = NULL;
5202 used = hwaddr_aton2(cmd, dst_addr);
5210 /* Advertisement Protocol ID */
5211 end = os_strchr(pos, ' ');
5215 len = os_strlen(pos);
5221 advproto = wpabuf_alloc(len);
5222 if (advproto == NULL)
5224 if (hexstr2bin(pos, wpabuf_put(advproto, len), len) < 0)
5228 /* Optional Query Request */
5233 len = os_strlen(pos);
5240 query = wpabuf_alloc(len);
5243 if (hexstr2bin(pos, wpabuf_put(query, len), len) < 0)
5248 ret = gas_send_request(wpa_s, dst_addr, advproto, query);
5251 wpabuf_free(advproto);
5258 static int gas_response_get(struct wpa_supplicant *wpa_s, char *cmd, char *buf,
5265 size_t resp_len, start, requested_len;
5266 struct wpabuf *resp;
5269 used = hwaddr_aton2(cmd, addr);
5276 dialog_token = atoi(pos);
5278 if (wpa_s->last_gas_resp &&
5279 os_memcmp(addr, wpa_s->last_gas_addr, ETH_ALEN) == 0 &&
5280 dialog_token == wpa_s->last_gas_dialog_token)
5281 resp = wpa_s->last_gas_resp;
5282 else if (wpa_s->prev_gas_resp &&
5283 os_memcmp(addr, wpa_s->prev_gas_addr, ETH_ALEN) == 0 &&
5284 dialog_token == wpa_s->prev_gas_dialog_token)
5285 resp = wpa_s->prev_gas_resp;
5289 resp_len = wpabuf_len(resp);
5291 requested_len = resp_len;
5293 pos = os_strchr(pos, ' ');
5296 if (start > resp_len)
5297 return os_snprintf(buf, buflen, "FAIL-Invalid range");
5298 pos = os_strchr(pos, ',');
5302 requested_len = atoi(pos);
5303 if (start + requested_len > resp_len)
5304 return os_snprintf(buf, buflen, "FAIL-Invalid range");
5307 if (requested_len * 2 + 1 > buflen)
5308 return os_snprintf(buf, buflen, "FAIL-Too long response");
5310 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(resp) + start,
5313 if (start + requested_len == resp_len) {
5315 * Free memory by dropping the response after it has been
5318 if (resp == wpa_s->prev_gas_resp) {
5319 wpabuf_free(wpa_s->prev_gas_resp);
5320 wpa_s->prev_gas_resp = NULL;
5322 wpabuf_free(wpa_s->last_gas_resp);
5323 wpa_s->last_gas_resp = NULL;
5329 #endif /* CONFIG_INTERWORKING */
5334 static int get_hs20_anqp(struct wpa_supplicant *wpa_s, char *dst)
5336 u8 dst_addr[ETH_ALEN];
5341 used = hwaddr_aton2(dst, dst_addr);
5346 int num = atoi(pos);
5347 if (num <= 0 || num > 31)
5349 subtypes |= BIT(num);
5350 pos = os_strchr(pos + 1, ',');
5359 return hs20_anqp_send_req(wpa_s, dst_addr, subtypes, NULL, 0);
5363 static int hs20_nai_home_realm_list(struct wpa_supplicant *wpa_s,
5364 const u8 *addr, const char *realm)
5370 rlen = os_strlen(realm);
5372 buf = os_malloc(len);
5375 buf[0] = 1; /* NAI Home Realm Count */
5376 buf[1] = 0; /* Formatted in accordance with RFC 4282 */
5378 os_memcpy(buf + 3, realm, rlen);
5380 ret = hs20_anqp_send_req(wpa_s, addr,
5381 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
5390 static int hs20_get_nai_home_realm_list(struct wpa_supplicant *wpa_s,
5393 struct wpa_cred *cred = wpa_s->conf->cred;
5394 u8 dst_addr[ETH_ALEN];
5400 used = hwaddr_aton2(dst, dst_addr);
5404 while (dst[used] == ' ')
5406 if (os_strncmp(dst + used, "realm=", 6) == 0)
5407 return hs20_nai_home_realm_list(wpa_s, dst_addr,
5410 len = os_strlen(dst + used);
5412 if (len == 0 && cred && cred->realm)
5413 return hs20_nai_home_realm_list(wpa_s, dst_addr, cred->realm);
5418 buf = os_malloc(len);
5421 if (hexstr2bin(dst + used, buf, len) < 0) {
5426 ret = hs20_anqp_send_req(wpa_s, dst_addr,
5427 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
5435 static int hs20_icon_request(struct wpa_supplicant *wpa_s, char *cmd)
5437 u8 dst_addr[ETH_ALEN];
5441 used = hwaddr_aton2(cmd, dst_addr);
5445 while (cmd[used] == ' ')
5449 wpa_s->fetch_osu_icon_in_progress = 0;
5450 return hs20_anqp_send_req(wpa_s, dst_addr, BIT(HS20_STYPE_ICON_REQUEST),
5451 (u8 *) icon, os_strlen(icon));
5454 #endif /* CONFIG_HS20 */
5457 static int wpa_supplicant_ctrl_iface_sta_autoconnect(
5458 struct wpa_supplicant *wpa_s, char *cmd)
5460 wpa_s->auto_reconnect_disabled = atoi(cmd) == 0 ? 1 : 0;
5465 #ifdef CONFIG_AUTOSCAN
5467 static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant *wpa_s,
5470 enum wpa_states state = wpa_s->wpa_state;
5471 char *new_params = NULL;
5473 if (os_strlen(cmd) > 0) {
5474 new_params = os_strdup(cmd);
5475 if (new_params == NULL)
5479 os_free(wpa_s->conf->autoscan);
5480 wpa_s->conf->autoscan = new_params;
5482 if (wpa_s->conf->autoscan == NULL)
5483 autoscan_deinit(wpa_s);
5484 else if (state == WPA_DISCONNECTED || state == WPA_INACTIVE)
5485 autoscan_init(wpa_s, 1);
5486 else if (state == WPA_SCANNING)
5487 wpa_supplicant_reinit_autoscan(wpa_s);
5492 #endif /* CONFIG_AUTOSCAN */
5497 static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant *wpa_s, char *cmd)
5503 struct wpabuf *tfs_req = NULL;
5505 if (os_strncmp(cmd, "enter", 5) == 0)
5507 else if (os_strncmp(cmd, "exit", 4) == 0)
5512 pos = os_strstr(cmd, " interval=");
5514 intval = atoi(pos + 10);
5516 pos = os_strstr(cmd, " tfs_req=");
5521 end = os_strchr(pos, ' ');
5525 len = os_strlen(pos);
5529 tfs_req = wpabuf_alloc(len);
5530 if (tfs_req == NULL)
5532 if (hexstr2bin(pos, wpabuf_put(tfs_req, len), len) < 0) {
5533 wpabuf_free(tfs_req);
5538 ret = ieee802_11_send_wnmsleep_req(wpa_s, enter ? WNM_SLEEP_MODE_ENTER :
5539 WNM_SLEEP_MODE_EXIT, intval,
5541 wpabuf_free(tfs_req);
5547 static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant *wpa_s, char *cmd)
5551 query_reason = atoi(cmd);
5553 wpa_printf(MSG_DEBUG, "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d",
5556 return wnm_send_bss_transition_mgmt_query(wpa_s, query_reason);
5559 #endif /* CONFIG_WNM */
5562 static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf,
5565 struct wpa_signal_info si;
5569 ret = wpa_drv_signal_poll(wpa_s, &si);
5576 ret = os_snprintf(pos, end - pos, "RSSI=%d\nLINKSPEED=%d\n"
5577 "NOISE=%d\nFREQUENCY=%u\n",
5578 si.current_signal, si.current_txrate / 1000,
5579 si.current_noise, si.frequency);
5580 if (ret < 0 || ret > end - pos)
5584 if (si.chanwidth != CHAN_WIDTH_UNKNOWN) {
5585 ret = os_snprintf(pos, end - pos, "WIDTH=%s\n",
5586 channel_width_to_string(si.chanwidth));
5587 if (ret < 0 || ret > end - pos)
5592 if (si.center_frq1 > 0 && si.center_frq2 > 0) {
5593 ret = os_snprintf(pos, end - pos,
5594 "CENTER_FRQ1=%d\nCENTER_FRQ2=%d\n",
5595 si.center_frq1, si.center_frq2);
5596 if (ret < 0 || ret > end - pos)
5601 if (si.avg_signal) {
5602 ret = os_snprintf(pos, end - pos,
5603 "AVG_RSSI=%d\n", si.avg_signal);
5604 if (ret < 0 || ret >= end - pos)
5613 static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant *wpa_s, char *buf,
5616 struct hostap_sta_driver_data sta;
5619 ret = wpa_drv_pktcnt_poll(wpa_s, &sta);
5623 ret = os_snprintf(buf, buflen, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
5624 sta.tx_packets, sta.tx_retry_failed, sta.rx_packets);
5625 if (ret < 0 || (size_t) ret > buflen)
5632 static int wpa_supplicant_driver_cmd(struct wpa_supplicant *wpa_s, char *cmd,
5633 char *buf, size_t buflen)
5637 ret = wpa_drv_driver_cmd(wpa_s, cmd, buf, buflen);
5639 if (os_strncasecmp(cmd, "COUNTRY", 7) == 0) {
5640 struct p2p_data *p2p = wpa_s->global->p2p;
5643 country[0] = cmd[8];
5644 country[1] = cmd[9];
5646 p2p_set_country(p2p, country);
5649 ret = os_snprintf(buf, buflen, "%s\n", "OK");
5653 #endif /* ANDROID */
5656 static int wpa_supplicant_vendor_cmd(struct wpa_supplicant *wpa_s, char *cmd,
5657 char *buf, size_t buflen)
5662 unsigned int vendor_id, subcmd;
5663 struct wpabuf *reply;
5664 size_t data_len = 0;
5666 /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */
5667 vendor_id = strtoul(cmd, &pos, 16);
5671 subcmd = strtoul(pos, &pos, 10);
5674 if (!isblank(*pos++))
5676 data_len = os_strlen(pos);
5681 data = os_malloc(data_len);
5685 if (hexstr2bin(pos, data, data_len)) {
5686 wpa_printf(MSG_DEBUG,
5687 "Vendor command: wrong parameter format");
5693 reply = wpabuf_alloc((buflen - 1) / 2);
5699 ret = wpa_drv_vendor_cmd(wpa_s, vendor_id, subcmd, data, data_len,
5703 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(reply),
5713 static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s)
5715 wpa_dbg(wpa_s, MSG_DEBUG, "Flush all wpa_supplicant state");
5718 wpas_p2p_cancel(wpa_s);
5719 wpas_p2p_stop_find(wpa_s);
5720 p2p_ctrl_flush(wpa_s);
5721 wpas_p2p_group_remove(wpa_s, "*");
5722 wpas_p2p_service_flush(wpa_s);
5723 wpa_s->global->p2p_disabled = 0;
5724 wpa_s->global->p2p_per_sta_psk = 0;
5725 wpa_s->conf->num_sec_device_types = 0;
5726 wpa_s->p2p_disable_ip_addr_req = 0;
5727 os_free(wpa_s->global->p2p_go_avoid_freq.range);
5728 wpa_s->global->p2p_go_avoid_freq.range = NULL;
5729 #endif /* CONFIG_P2P */
5731 #ifdef CONFIG_WPS_TESTING
5732 wps_version_number = 0x20;
5733 wps_testing_dummy_cred = 0;
5734 wps_corrupt_pkhash = 0;
5735 #endif /* CONFIG_WPS_TESTING */
5737 wpa_s->wps_fragment_size = 0;
5738 wpas_wps_cancel(wpa_s);
5739 #endif /* CONFIG_WPS */
5740 wpa_s->after_wps = 0;
5741 wpa_s->known_wps_freq = 0;
5744 #ifdef CONFIG_TDLS_TESTING
5745 extern unsigned int tdls_testing;
5747 #endif /* CONFIG_TDLS_TESTING */
5748 wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL);
5749 wpa_tdls_enable(wpa_s->wpa, 1);
5750 #endif /* CONFIG_TDLS */
5752 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, wpa_s, NULL);
5753 wpa_supplicant_stop_countermeasures(wpa_s, NULL);
5755 wpa_s->no_keep_alive = 0;
5757 os_free(wpa_s->disallow_aps_bssid);
5758 wpa_s->disallow_aps_bssid = NULL;
5759 wpa_s->disallow_aps_bssid_count = 0;
5760 os_free(wpa_s->disallow_aps_ssid);
5761 wpa_s->disallow_aps_ssid = NULL;
5762 wpa_s->disallow_aps_ssid_count = 0;
5764 wpa_s->set_sta_uapsd = 0;
5765 wpa_s->sta_uapsd = 0;
5767 wpa_drv_radio_disable(wpa_s, 0);
5769 wpa_bss_flush(wpa_s);
5770 wpa_blacklist_clear(wpa_s);
5771 wpa_s->extra_blacklist_count = 0;
5772 wpa_supplicant_ctrl_iface_remove_network(wpa_s, "all");
5773 wpa_supplicant_ctrl_iface_remove_cred(wpa_s, "all");
5774 wpa_config_flush_blobs(wpa_s->conf);
5775 wpa_s->conf->auto_interworking = 0;
5776 wpa_s->conf->okc = 0;
5778 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, 43200);
5779 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, 70);
5780 wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, 60);
5781 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
5783 radio_remove_works(wpa_s, NULL, 1);
5785 wpa_s->next_ssid = NULL;
5787 #ifdef CONFIG_INTERWORKING
5788 hs20_cancel_fetch_osu(wpa_s);
5789 #endif /* CONFIG_INTERWORKING */
5791 wpa_s->ext_mgmt_frame_handling = 0;
5795 static int wpas_ctrl_radio_work_show(struct wpa_supplicant *wpa_s,
5796 char *buf, size_t buflen)
5798 struct wpa_radio_work *work;
5800 struct os_reltime now, diff;
5805 os_get_reltime(&now);
5807 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
5811 os_reltime_sub(&now, &work->time, &diff);
5812 ret = os_snprintf(pos, end - pos, "%s@%s:%u:%u:%ld.%06ld\n",
5813 work->type, work->wpa_s->ifname, work->freq,
5814 work->started, diff.sec, diff.usec);
5815 if (ret < 0 || ret >= end - pos)
5824 static void wpas_ctrl_radio_work_timeout(void *eloop_ctx, void *timeout_ctx)
5826 struct wpa_radio_work *work = eloop_ctx;
5827 struct wpa_external_work *ework = work->ctx;
5829 wpa_dbg(work->wpa_s, MSG_DEBUG,
5830 "Timing out external radio work %u (%s)",
5831 ework->id, work->type);
5832 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_TIMEOUT "%u", ework->id);
5833 radio_work_done(work);
5838 static void wpas_ctrl_radio_work_cb(struct wpa_radio_work *work, int deinit)
5840 struct wpa_external_work *ework = work->ctx;
5844 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
5851 wpa_dbg(work->wpa_s, MSG_DEBUG, "Starting external radio work %u (%s)",
5852 ework->id, ework->type);
5853 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_START "%u", ework->id);
5854 if (!ework->timeout)
5855 ework->timeout = 10;
5856 eloop_register_timeout(ework->timeout, 0, wpas_ctrl_radio_work_timeout,
5861 static int wpas_ctrl_radio_work_add(struct wpa_supplicant *wpa_s, char *cmd,
5862 char *buf, size_t buflen)
5864 struct wpa_external_work *ework;
5868 unsigned int freq = 0;
5870 /* format: <name> [freq=<MHz>] [timeout=<seconds>] */
5872 ework = os_zalloc(sizeof(*ework));
5876 pos = os_strchr(cmd, ' ');
5878 type_len = pos - cmd;
5881 pos2 = os_strstr(pos, "freq=");
5883 freq = atoi(pos2 + 5);
5885 pos2 = os_strstr(pos, "timeout=");
5887 ework->timeout = atoi(pos2 + 8);
5889 type_len = os_strlen(cmd);
5891 if (4 + type_len >= sizeof(ework->type))
5892 type_len = sizeof(ework->type) - 4 - 1;
5893 os_strlcpy(ework->type, "ext:", sizeof(ework->type));
5894 os_memcpy(ework->type + 4, cmd, type_len);
5895 ework->type[4 + type_len] = '\0';
5897 wpa_s->ext_work_id++;
5898 if (wpa_s->ext_work_id == 0)
5899 wpa_s->ext_work_id++;
5900 ework->id = wpa_s->ext_work_id;
5902 if (radio_add_work(wpa_s, freq, ework->type, 0, wpas_ctrl_radio_work_cb,
5908 ret = os_snprintf(buf, buflen, "%u", ework->id);
5909 if (ret < 0 || (size_t) ret >= buflen)
5915 static int wpas_ctrl_radio_work_done(struct wpa_supplicant *wpa_s, char *cmd)
5917 struct wpa_radio_work *work;
5918 unsigned int id = atoi(cmd);
5920 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
5922 struct wpa_external_work *ework;
5924 if (os_strncmp(work->type, "ext:", 4) != 0)
5927 if (id && ework->id != id)
5929 wpa_dbg(wpa_s, MSG_DEBUG,
5930 "Completed external radio work %u (%s)",
5931 ework->id, ework->type);
5932 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, work, NULL);
5933 radio_work_done(work);
5935 return 3; /* "OK\n" */
5942 static int wpas_ctrl_radio_work(struct wpa_supplicant *wpa_s, char *cmd,
5943 char *buf, size_t buflen)
5945 if (os_strcmp(cmd, "show") == 0)
5946 return wpas_ctrl_radio_work_show(wpa_s, buf, buflen);
5947 if (os_strncmp(cmd, "add ", 4) == 0)
5948 return wpas_ctrl_radio_work_add(wpa_s, cmd + 4, buf, buflen);
5949 if (os_strncmp(cmd, "done ", 5) == 0)
5950 return wpas_ctrl_radio_work_done(wpa_s, cmd + 4);
5955 void wpas_ctrl_radio_work_flush(struct wpa_supplicant *wpa_s)
5957 struct wpa_radio_work *work, *tmp;
5959 if (!wpa_s || !wpa_s->radio)
5962 dl_list_for_each_safe(work, tmp, &wpa_s->radio->work,
5963 struct wpa_radio_work, list) {
5964 struct wpa_external_work *ework;
5966 if (os_strncmp(work->type, "ext:", 4) != 0)
5969 wpa_dbg(wpa_s, MSG_DEBUG,
5970 "Flushing%s external radio work %u (%s)",
5971 work->started ? " started" : "", ework->id,
5974 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
5976 radio_work_done(work);
5982 static void wpas_ctrl_eapol_response(void *eloop_ctx, void *timeout_ctx)
5984 struct wpa_supplicant *wpa_s = eloop_ctx;
5985 eapol_sm_notify_ctrl_response(wpa_s->eapol);
5989 static int set_scan_freqs(struct wpa_supplicant *wpa_s, char *val)
5993 freqs = freq_range_to_channel_list(wpa_s, val);
5997 os_free(wpa_s->manual_scan_freqs);
5998 wpa_s->manual_scan_freqs = freqs;
6004 static int scan_id_list_parse(struct wpa_supplicant *wpa_s, const char *value)
6006 const char *pos = value;
6009 if (*pos == ' ' || *pos == '\0')
6011 if (wpa_s->scan_id_count == MAX_SCAN_ID)
6013 wpa_s->scan_id[wpa_s->scan_id_count++] = atoi(pos);
6014 pos = os_strchr(pos, ',');
6023 static void wpas_ctrl_scan(struct wpa_supplicant *wpa_s, char *params,
6024 char *reply, int reply_size, int *reply_len)
6028 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
6033 wpa_s->manual_scan_passive = 0;
6034 wpa_s->manual_scan_use_id = 0;
6035 wpa_s->manual_scan_only_new = 0;
6036 wpa_s->scan_id_count = 0;
6039 if (os_strncasecmp(params, "TYPE=ONLY", 9) == 0)
6040 wpa_s->scan_res_handler = scan_only_handler;
6042 pos = os_strstr(params, "freq=");
6043 if (pos && set_scan_freqs(wpa_s, pos + 5) < 0) {
6048 pos = os_strstr(params, "passive=");
6050 wpa_s->manual_scan_passive = !!atoi(pos + 8);
6052 pos = os_strstr(params, "use_id=");
6054 wpa_s->manual_scan_use_id = atoi(pos + 7);
6056 pos = os_strstr(params, "only_new=1");
6058 wpa_s->manual_scan_only_new = 1;
6060 pos = os_strstr(params, "scan_id=");
6061 if (pos && scan_id_list_parse(wpa_s, pos + 8) < 0) {
6066 os_free(wpa_s->manual_scan_freqs);
6067 wpa_s->manual_scan_freqs = NULL;
6068 if (wpa_s->scan_res_handler == scan_only_handler)
6069 wpa_s->scan_res_handler = NULL;
6072 if (!wpa_s->sched_scanning && !wpa_s->scanning &&
6073 ((wpa_s->wpa_state <= WPA_SCANNING) ||
6074 (wpa_s->wpa_state == WPA_COMPLETED))) {
6075 wpa_s->normal_scans = 0;
6076 wpa_s->scan_req = MANUAL_SCAN_REQ;
6077 wpa_s->after_wps = 0;
6078 wpa_s->known_wps_freq = 0;
6079 wpa_supplicant_req_scan(wpa_s, 0, 0);
6080 if (wpa_s->manual_scan_use_id) {
6081 wpa_s->manual_scan_id++;
6082 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
6083 wpa_s->manual_scan_id);
6084 *reply_len = os_snprintf(reply, reply_size, "%u\n",
6085 wpa_s->manual_scan_id);
6087 } else if (wpa_s->sched_scanning) {
6088 wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to allow requested full scan to proceed");
6089 wpa_supplicant_cancel_sched_scan(wpa_s);
6090 wpa_s->scan_req = MANUAL_SCAN_REQ;
6091 wpa_supplicant_req_scan(wpa_s, 0, 0);
6092 if (wpa_s->manual_scan_use_id) {
6093 wpa_s->manual_scan_id++;
6094 *reply_len = os_snprintf(reply, reply_size, "%u\n",
6095 wpa_s->manual_scan_id);
6096 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
6097 wpa_s->manual_scan_id);
6100 wpa_printf(MSG_DEBUG, "Ongoing scan action - reject new request");
6101 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
6106 #ifdef CONFIG_TESTING_OPTIONS
6108 static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant *wpa_s,
6109 unsigned int freq, const u8 *dst,
6110 const u8 *src, const u8 *bssid,
6111 const u8 *data, size_t data_len,
6112 enum offchannel_send_action_result
6115 wpa_msg(wpa_s, MSG_INFO, "MGMT-TX-STATUS freq=%u dst=" MACSTR
6116 " src=" MACSTR " bssid=" MACSTR " result=%s",
6117 freq, MAC2STR(dst), MAC2STR(src), MAC2STR(bssid),
6118 result == OFFCHANNEL_SEND_ACTION_SUCCESS ?
6119 "SUCCESS" : (result == OFFCHANNEL_SEND_ACTION_NO_ACK ?
6120 "NO_ACK" : "FAILED"));
6124 static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant *wpa_s, char *cmd)
6128 u8 *buf, da[ETH_ALEN], bssid[ETH_ALEN];
6130 int freq = 0, no_cck = 0, wait_time = 0;
6132 /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1]
6133 * <action=Action frame payload> */
6135 wpa_printf(MSG_DEBUG, "External MGMT TX: %s", cmd);
6138 used = hwaddr_aton2(pos, da);
6144 used = hwaddr_aton2(pos, bssid);
6149 param = os_strstr(pos, " freq=");
6155 param = os_strstr(pos, " no_cck=");
6158 no_cck = atoi(param);
6161 param = os_strstr(pos, " wait_time=");
6164 wait_time = atoi(param);
6167 param = os_strstr(pos, " action=");
6172 len = os_strlen(param);
6177 buf = os_malloc(len);
6181 if (hexstr2bin(param, buf, len) < 0) {
6186 res = offchannel_send_action(wpa_s, freq, da, wpa_s->own_addr, bssid,
6187 buf, len, wait_time,
6188 wpas_ctrl_iface_mgmt_tx_cb, no_cck);
6194 static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant *wpa_s)
6196 wpa_printf(MSG_DEBUG, "External MGMT TX - done waiting");
6197 offchannel_send_action_done(wpa_s);
6201 static int wpas_ctrl_iface_driver_event(struct wpa_supplicant *wpa_s, char *cmd)
6204 union wpa_event_data event;
6205 enum wpa_event_type ev;
6207 /* <event name> [parameters..] */
6209 wpa_dbg(wpa_s, MSG_DEBUG, "Testing - external driver event: %s", cmd);
6212 param = os_strchr(pos, ' ');
6216 os_memset(&event, 0, sizeof(event));
6218 if (os_strcmp(cmd, "INTERFACE_ENABLED") == 0) {
6219 ev = EVENT_INTERFACE_ENABLED;
6220 } else if (os_strcmp(cmd, "INTERFACE_DISABLED") == 0) {
6221 ev = EVENT_INTERFACE_DISABLED;
6222 } else if (os_strcmp(cmd, "AVOID_FREQUENCIES") == 0) {
6223 ev = EVENT_AVOID_FREQUENCIES;
6226 if (freq_range_list_parse(&event.freq_range, param) < 0)
6228 wpa_supplicant_event(wpa_s, ev, &event);
6229 os_free(event.freq_range.range);
6232 wpa_dbg(wpa_s, MSG_DEBUG, "Testing - unknown driver event: %s",
6237 wpa_supplicant_event(wpa_s, ev, &event);
6242 #endif /* CONFIG_TESTING_OPTIONS */
6245 static void wpas_ctrl_vendor_elem_update(struct wpa_supplicant *wpa_s)
6250 wpa_printf(MSG_DEBUG, "Update vendor elements");
6252 for (i = 0; i < NUM_VENDOR_ELEM_FRAMES; i++) {
6253 if (wpa_s->vendor_elem[i]) {
6254 os_snprintf(buf, sizeof(buf), "frame[%u]", i);
6255 wpa_hexdump_buf(MSG_DEBUG, buf, wpa_s->vendor_elem[i]);
6260 if (wpa_s->parent == wpa_s &&
6261 wpa_s->global->p2p &&
6262 !wpa_s->global->p2p_disabled)
6263 p2p_set_vendor_elems(wpa_s->global->p2p, wpa_s->vendor_elem);
6264 #endif /* CONFIG_P2P */
6268 static struct wpa_supplicant *
6269 wpas_ctrl_vendor_elem_iface(struct wpa_supplicant *wpa_s,
6270 enum wpa_vendor_elem_frame frame)
6274 case VENDOR_ELEM_PROBE_REQ_P2P:
6275 case VENDOR_ELEM_PROBE_RESP_P2P:
6276 case VENDOR_ELEM_PROBE_RESP_P2P_GO:
6277 case VENDOR_ELEM_BEACON_P2P_GO:
6278 case VENDOR_ELEM_P2P_PD_REQ:
6279 case VENDOR_ELEM_P2P_PD_RESP:
6280 case VENDOR_ELEM_P2P_GO_NEG_REQ:
6281 case VENDOR_ELEM_P2P_GO_NEG_RESP:
6282 case VENDOR_ELEM_P2P_GO_NEG_CONF:
6283 case VENDOR_ELEM_P2P_INV_REQ:
6284 case VENDOR_ELEM_P2P_INV_RESP:
6285 case VENDOR_ELEM_P2P_ASSOC_REQ:
6286 return wpa_s->parent;
6287 #endif /* CONFIG_P2P */
6294 static int wpas_ctrl_vendor_elem_add(struct wpa_supplicant *wpa_s, char *cmd)
6300 struct ieee802_11_elems elems;
6303 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
6305 wpa_s = wpas_ctrl_vendor_elem_iface(wpa_s, frame);
6307 pos = os_strchr(pos, ' ');
6312 len = os_strlen(pos);
6319 buf = wpabuf_alloc(len);
6323 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
6328 if (ieee802_11_parse_elems(wpabuf_head_u8(buf), len, &elems, 0) ==
6334 if (wpa_s->vendor_elem[frame] == NULL) {
6335 wpa_s->vendor_elem[frame] = buf;
6336 wpas_ctrl_vendor_elem_update(wpa_s);
6340 if (wpabuf_resize(&wpa_s->vendor_elem[frame], len) < 0) {
6345 wpabuf_put_buf(wpa_s->vendor_elem[frame], buf);
6347 wpas_ctrl_vendor_elem_update(wpa_s);
6353 static int wpas_ctrl_vendor_elem_get(struct wpa_supplicant *wpa_s, char *cmd,
6354 char *buf, size_t buflen)
6356 int frame = atoi(cmd);
6358 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
6360 wpa_s = wpas_ctrl_vendor_elem_iface(wpa_s, frame);
6362 if (wpa_s->vendor_elem[frame] == NULL)
6365 return wpa_snprintf_hex(buf, buflen,
6366 wpabuf_head_u8(wpa_s->vendor_elem[frame]),
6367 wpabuf_len(wpa_s->vendor_elem[frame]));
6371 static int wpas_ctrl_vendor_elem_remove(struct wpa_supplicant *wpa_s, char *cmd)
6377 struct ieee802_11_elems elems;
6381 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
6383 wpa_s = wpas_ctrl_vendor_elem_iface(wpa_s, frame);
6385 pos = os_strchr(pos, ' ');
6391 wpabuf_free(wpa_s->vendor_elem[frame]);
6392 wpa_s->vendor_elem[frame] = NULL;
6393 wpas_ctrl_vendor_elem_update(wpa_s);
6397 if (wpa_s->vendor_elem[frame] == NULL)
6400 len = os_strlen(pos);
6407 buf = os_malloc(len);
6411 if (hexstr2bin(pos, buf, len) < 0) {
6416 if (ieee802_11_parse_elems(buf, len, &elems, 0) == ParseFailed) {
6421 ie = wpabuf_mhead_u8(wpa_s->vendor_elem[frame]);
6422 end = ie + wpabuf_len(wpa_s->vendor_elem[frame]);
6424 for (; ie + 1 < end; ie += 2 + ie[1]) {
6427 if (os_memcmp(ie, buf, len) != 0)
6430 if (wpabuf_len(wpa_s->vendor_elem[frame]) == len) {
6431 wpabuf_free(wpa_s->vendor_elem[frame]);
6432 wpa_s->vendor_elem[frame] = NULL;
6434 os_memmove(ie, ie + len,
6435 wpabuf_len(wpa_s->vendor_elem[frame]) - len);
6436 wpa_s->vendor_elem[frame]->used -= len;
6439 wpas_ctrl_vendor_elem_update(wpa_s);
6449 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
6450 char *buf, size_t *resp_len)
6453 const int reply_size = 4096;
6456 if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 ||
6457 os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
6458 if (wpa_debug_show_keys)
6459 wpa_dbg(wpa_s, MSG_DEBUG,
6460 "Control interface command '%s'", buf);
6462 wpa_dbg(wpa_s, MSG_DEBUG,
6463 "Control interface command '%s [REMOVED]'",
6464 os_strncmp(buf, WPA_CTRL_RSP,
6465 os_strlen(WPA_CTRL_RSP)) == 0 ?
6466 WPA_CTRL_RSP : "SET_NETWORK");
6467 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ", 16) == 0 ||
6468 os_strncmp(buf, "NFC_REPORT_HANDOVER", 19) == 0) {
6469 wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface",
6470 (const u8 *) buf, os_strlen(buf));
6472 int level = MSG_DEBUG;
6473 if (os_strcmp(buf, "PING") == 0)
6474 level = MSG_EXCESSIVE;
6475 wpa_dbg(wpa_s, level, "Control interface command '%s'", buf);
6478 reply = os_malloc(reply_size);
6479 if (reply == NULL) {
6484 os_memcpy(reply, "OK\n", 3);
6487 if (os_strcmp(buf, "PING") == 0) {
6488 os_memcpy(reply, "PONG\n", 5);
6490 } else if (os_strcmp(buf, "IFNAME") == 0) {
6491 reply_len = os_strlen(wpa_s->ifname);
6492 os_memcpy(reply, wpa_s->ifname, reply_len);
6493 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
6494 if (wpa_debug_reopen_file() < 0)
6496 } else if (os_strncmp(buf, "NOTE ", 5) == 0) {
6497 wpa_printf(MSG_INFO, "NOTE: %s", buf + 5);
6498 } else if (os_strcmp(buf, "MIB") == 0) {
6499 reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size);
6500 if (reply_len >= 0) {
6502 res = eapol_sm_get_mib(wpa_s->eapol, reply + reply_len,
6503 reply_size - reply_len);
6509 } else if (os_strncmp(buf, "STATUS", 6) == 0) {
6510 reply_len = wpa_supplicant_ctrl_iface_status(
6511 wpa_s, buf + 6, reply, reply_size);
6512 } else if (os_strcmp(buf, "PMKSA") == 0) {
6513 reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, reply,
6515 } else if (os_strcmp(buf, "PMKSA_FLUSH") == 0) {
6516 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
6517 } else if (os_strncmp(buf, "SET ", 4) == 0) {
6518 if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4))
6520 } else if (os_strncmp(buf, "GET ", 4) == 0) {
6521 reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4,
6523 } else if (os_strcmp(buf, "LOGON") == 0) {
6524 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
6525 } else if (os_strcmp(buf, "LOGOFF") == 0) {
6526 eapol_sm_notify_logoff(wpa_s->eapol, TRUE);
6527 } else if (os_strcmp(buf, "REASSOCIATE") == 0) {
6528 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
6531 wpas_request_connection(wpa_s);
6532 } else if (os_strcmp(buf, "REATTACH") == 0) {
6533 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED ||
6534 !wpa_s->current_ssid)
6537 wpa_s->reattach = 1;
6538 wpas_request_connection(wpa_s);
6540 } else if (os_strcmp(buf, "RECONNECT") == 0) {
6541 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
6543 else if (wpa_s->disconnected)
6544 wpas_request_connection(wpa_s);
6545 #ifdef IEEE8021X_EAPOL
6546 } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) {
6547 if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8))
6549 #endif /* IEEE8021X_EAPOL */
6550 #ifdef CONFIG_PEERKEY
6551 } else if (os_strncmp(buf, "STKSTART ", 9) == 0) {
6552 if (wpa_supplicant_ctrl_iface_stkstart(wpa_s, buf + 9))
6554 #endif /* CONFIG_PEERKEY */
6555 #ifdef CONFIG_IEEE80211R
6556 } else if (os_strncmp(buf, "FT_DS ", 6) == 0) {
6557 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6))
6559 #endif /* CONFIG_IEEE80211R */
6561 } else if (os_strcmp(buf, "WPS_PBC") == 0) {
6562 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL);
6564 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
6568 } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) {
6569 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8);
6571 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
6575 } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {
6576 reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8,
6579 } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) {
6580 reply_len = wpa_supplicant_ctrl_iface_wps_check_pin(
6581 wpa_s, buf + 14, reply, reply_size);
6582 } else if (os_strcmp(buf, "WPS_CANCEL") == 0) {
6583 if (wpas_wps_cancel(wpa_s))
6585 #ifdef CONFIG_WPS_NFC
6586 } else if (os_strcmp(buf, "WPS_NFC") == 0) {
6587 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, NULL))
6589 } else if (os_strncmp(buf, "WPS_NFC ", 8) == 0) {
6590 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, buf + 8))
6592 } else if (os_strncmp(buf, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
6593 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_config_token(
6594 wpa_s, buf + 21, reply, reply_size);
6595 } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) {
6596 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_token(
6597 wpa_s, buf + 14, reply, reply_size);
6598 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) {
6599 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s,
6602 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
6603 reply_len = wpas_ctrl_nfc_get_handover_req(
6604 wpa_s, buf + 21, reply, reply_size);
6605 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
6606 reply_len = wpas_ctrl_nfc_get_handover_sel(
6607 wpa_s, buf + 21, reply, reply_size);
6608 } else if (os_strncmp(buf, "NFC_REPORT_HANDOVER ", 20) == 0) {
6609 if (wpas_ctrl_nfc_report_handover(wpa_s, buf + 20))
6611 #endif /* CONFIG_WPS_NFC */
6612 } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) {
6613 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8))
6616 } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) {
6617 reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin(
6618 wpa_s, buf + 11, reply, reply_size);
6619 #endif /* CONFIG_AP */
6620 #ifdef CONFIG_WPS_ER
6621 } else if (os_strcmp(buf, "WPS_ER_START") == 0) {
6622 if (wpas_wps_er_start(wpa_s, NULL))
6624 } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) {
6625 if (wpas_wps_er_start(wpa_s, buf + 13))
6627 } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) {
6628 if (wpas_wps_er_stop(wpa_s))
6630 } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) {
6631 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11))
6633 } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) {
6634 int ret = wpas_wps_er_pbc(wpa_s, buf + 11);
6636 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
6638 } else if (ret == -3) {
6639 os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18);
6641 } else if (ret == -4) {
6642 os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20);
6646 } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) {
6647 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13))
6649 } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) {
6650 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s,
6653 } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) {
6654 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14))
6656 #ifdef CONFIG_WPS_NFC
6657 } else if (os_strncmp(buf, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
6658 reply_len = wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
6659 wpa_s, buf + 24, reply, reply_size);
6660 #endif /* CONFIG_WPS_NFC */
6661 #endif /* CONFIG_WPS_ER */
6662 #endif /* CONFIG_WPS */
6663 #ifdef CONFIG_IBSS_RSN
6664 } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) {
6665 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9))
6667 #endif /* CONFIG_IBSS_RSN */
6669 } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) {
6670 if (p2p_ctrl_find(wpa_s, buf + 9))
6672 } else if (os_strcmp(buf, "P2P_FIND") == 0) {
6673 if (p2p_ctrl_find(wpa_s, ""))
6675 } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) {
6676 wpas_p2p_stop_find(wpa_s);
6677 } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) {
6678 reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply,
6680 } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) {
6681 if (p2p_ctrl_listen(wpa_s, buf + 11))
6683 } else if (os_strcmp(buf, "P2P_LISTEN") == 0) {
6684 if (p2p_ctrl_listen(wpa_s, ""))
6686 } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) {
6687 if (wpas_p2p_group_remove(wpa_s, buf + 17))
6689 } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) {
6690 if (wpas_p2p_group_add(wpa_s, 0, 0, 0, 0))
6692 } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) {
6693 if (p2p_ctrl_group_add(wpa_s, buf + 14))
6695 } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) {
6696 if (p2p_ctrl_prov_disc(wpa_s, buf + 14))
6698 } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) {
6699 reply_len = p2p_get_passphrase(wpa_s, reply, reply_size);
6700 } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) {
6701 reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply,
6703 } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
6704 if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0)
6706 } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) {
6707 if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0)
6709 } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) {
6710 wpas_p2p_sd_service_update(wpa_s);
6711 } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
6712 if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0)
6714 } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) {
6715 wpas_p2p_service_flush(wpa_s);
6716 } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) {
6717 if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0)
6719 } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) {
6720 if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0)
6722 } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) {
6723 if (p2p_ctrl_reject(wpa_s, buf + 11) < 0)
6725 } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) {
6726 if (p2p_ctrl_invite(wpa_s, buf + 11) < 0)
6728 } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) {
6729 reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply,
6731 } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) {
6732 if (p2p_ctrl_set(wpa_s, buf + 8) < 0)
6734 } else if (os_strcmp(buf, "P2P_FLUSH") == 0) {
6735 p2p_ctrl_flush(wpa_s);
6736 } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) {
6737 if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0)
6739 } else if (os_strcmp(buf, "P2P_CANCEL") == 0) {
6740 if (wpas_p2p_cancel(wpa_s))
6742 } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) {
6743 if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0)
6745 } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) {
6746 if (p2p_ctrl_presence_req(wpa_s, "") < 0)
6748 } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) {
6749 if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0)
6751 } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) {
6752 if (p2p_ctrl_ext_listen(wpa_s, "") < 0)
6754 } else if (os_strncmp(buf, "P2P_REMOVE_CLIENT ", 18) == 0) {
6755 if (p2p_ctrl_remove_client(wpa_s, buf + 18) < 0)
6757 #endif /* CONFIG_P2P */
6758 #ifdef CONFIG_WIFI_DISPLAY
6759 } else if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0) {
6760 if (wifi_display_subelem_set(wpa_s->global, buf + 16) < 0)
6762 } else if (os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) {
6763 reply_len = wifi_display_subelem_get(wpa_s->global, buf + 16,
6765 #endif /* CONFIG_WIFI_DISPLAY */
6766 #ifdef CONFIG_INTERWORKING
6767 } else if (os_strcmp(buf, "FETCH_ANQP") == 0) {
6768 if (interworking_fetch_anqp(wpa_s) < 0)
6770 } else if (os_strcmp(buf, "STOP_FETCH_ANQP") == 0) {
6771 interworking_stop_fetch_anqp(wpa_s);
6772 } else if (os_strcmp(buf, "INTERWORKING_SELECT") == 0) {
6773 if (ctrl_interworking_select(wpa_s, NULL) < 0)
6775 } else if (os_strncmp(buf, "INTERWORKING_SELECT ", 20) == 0) {
6776 if (ctrl_interworking_select(wpa_s, buf + 20) < 0)
6778 } else if (os_strncmp(buf, "INTERWORKING_CONNECT ", 21) == 0) {
6779 if (ctrl_interworking_connect(wpa_s, buf + 21) < 0)
6781 } else if (os_strncmp(buf, "ANQP_GET ", 9) == 0) {
6782 if (get_anqp(wpa_s, buf + 9) < 0)
6784 } else if (os_strncmp(buf, "GAS_REQUEST ", 12) == 0) {
6785 if (gas_request(wpa_s, buf + 12) < 0)
6787 } else if (os_strncmp(buf, "GAS_RESPONSE_GET ", 17) == 0) {
6788 reply_len = gas_response_get(wpa_s, buf + 17, reply,
6790 #endif /* CONFIG_INTERWORKING */
6792 } else if (os_strncmp(buf, "HS20_ANQP_GET ", 14) == 0) {
6793 if (get_hs20_anqp(wpa_s, buf + 14) < 0)
6795 } else if (os_strncmp(buf, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
6796 if (hs20_get_nai_home_realm_list(wpa_s, buf + 29) < 0)
6798 } else if (os_strncmp(buf, "HS20_ICON_REQUEST ", 18) == 0) {
6799 if (hs20_icon_request(wpa_s, buf + 18) < 0)
6801 } else if (os_strcmp(buf, "FETCH_OSU") == 0) {
6802 if (hs20_fetch_osu(wpa_s) < 0)
6804 } else if (os_strcmp(buf, "CANCEL_FETCH_OSU") == 0) {
6805 hs20_cancel_fetch_osu(wpa_s);
6806 #endif /* CONFIG_HS20 */
6807 } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0)
6809 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
6810 wpa_s, buf + os_strlen(WPA_CTRL_RSP)))
6814 * Notify response from timeout to allow the control
6815 * interface response to be sent first.
6817 eloop_register_timeout(0, 0, wpas_ctrl_eapol_response,
6820 } else if (os_strcmp(buf, "RECONFIGURE") == 0) {
6821 if (wpa_supplicant_reload_configuration(wpa_s))
6823 } else if (os_strcmp(buf, "TERMINATE") == 0) {
6824 wpa_supplicant_terminate_proc(wpa_s->global);
6825 } else if (os_strncmp(buf, "BSSID ", 6) == 0) {
6826 if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6))
6828 } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) {
6829 reply_len = wpa_supplicant_ctrl_iface_blacklist(
6830 wpa_s, buf + 9, reply, reply_size);
6831 } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) {
6832 reply_len = wpa_supplicant_ctrl_iface_log_level(
6833 wpa_s, buf + 9, reply, reply_size);
6834 } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) {
6835 reply_len = wpa_supplicant_ctrl_iface_list_networks(
6836 wpa_s, reply, reply_size);
6837 } else if (os_strcmp(buf, "DISCONNECT") == 0) {
6839 wpa_s->sme.prev_bssid_set = 0;
6840 #endif /* CONFIG_SME */
6841 wpa_s->reassociate = 0;
6842 wpa_s->disconnected = 1;
6843 wpa_supplicant_cancel_sched_scan(wpa_s);
6844 wpa_supplicant_cancel_scan(wpa_s);
6845 wpa_supplicant_deauthenticate(wpa_s,
6846 WLAN_REASON_DEAUTH_LEAVING);
6847 } else if (os_strcmp(buf, "SCAN") == 0) {
6848 wpas_ctrl_scan(wpa_s, NULL, reply, reply_size, &reply_len);
6849 } else if (os_strncmp(buf, "SCAN ", 5) == 0) {
6850 wpas_ctrl_scan(wpa_s, buf + 5, reply, reply_size, &reply_len);
6851 } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) {
6852 reply_len = wpa_supplicant_ctrl_iface_scan_results(
6853 wpa_s, reply, reply_size);
6854 } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) {
6855 if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15))
6857 } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) {
6858 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15))
6860 } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) {
6861 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16))
6863 } else if (os_strcmp(buf, "ADD_NETWORK") == 0) {
6864 reply_len = wpa_supplicant_ctrl_iface_add_network(
6865 wpa_s, reply, reply_size);
6866 } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) {
6867 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15))
6869 } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
6870 if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12))
6872 } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) {
6873 reply_len = wpa_supplicant_ctrl_iface_get_network(
6874 wpa_s, buf + 12, reply, reply_size);
6875 } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) {
6876 if (wpa_supplicant_ctrl_iface_dup_network(wpa_s, buf + 12))
6878 } else if (os_strcmp(buf, "LIST_CREDS") == 0) {
6879 reply_len = wpa_supplicant_ctrl_iface_list_creds(
6880 wpa_s, reply, reply_size);
6881 } else if (os_strcmp(buf, "ADD_CRED") == 0) {
6882 reply_len = wpa_supplicant_ctrl_iface_add_cred(
6883 wpa_s, reply, reply_size);
6884 } else if (os_strncmp(buf, "REMOVE_CRED ", 12) == 0) {
6885 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s, buf + 12))
6887 } else if (os_strncmp(buf, "SET_CRED ", 9) == 0) {
6888 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s, buf + 9))
6890 } else if (os_strncmp(buf, "GET_CRED ", 9) == 0) {
6891 reply_len = wpa_supplicant_ctrl_iface_get_cred(wpa_s, buf + 9,
6894 #ifndef CONFIG_NO_CONFIG_WRITE
6895 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
6896 if (wpa_supplicant_ctrl_iface_save_config(wpa_s))
6898 #endif /* CONFIG_NO_CONFIG_WRITE */
6899 } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
6900 reply_len = wpa_supplicant_ctrl_iface_get_capability(
6901 wpa_s, buf + 15, reply, reply_size);
6902 } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) {
6903 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8))
6905 } else if (os_strncmp(buf, "SCAN_INTERVAL ", 14) == 0) {
6906 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s, buf + 14))
6908 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
6909 reply_len = wpa_supplicant_global_iface_list(
6910 wpa_s->global, reply, reply_size);
6911 } else if (os_strcmp(buf, "INTERFACES") == 0) {
6912 reply_len = wpa_supplicant_global_iface_interfaces(
6913 wpa_s->global, reply, reply_size);
6914 } else if (os_strncmp(buf, "BSS ", 4) == 0) {
6915 reply_len = wpa_supplicant_ctrl_iface_bss(
6916 wpa_s, buf + 4, reply, reply_size);
6918 } else if (os_strcmp(buf, "STA-FIRST") == 0) {
6919 reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size);
6920 } else if (os_strncmp(buf, "STA ", 4) == 0) {
6921 reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply,
6923 } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) {
6924 reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply,
6926 } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) {
6927 if (ap_ctrl_iface_sta_deauthenticate(wpa_s, buf + 15))
6929 } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) {
6930 if (ap_ctrl_iface_sta_disassociate(wpa_s, buf + 13))
6932 } else if (os_strncmp(buf, "CHAN_SWITCH ", 12) == 0) {
6933 if (ap_ctrl_iface_chanswitch(wpa_s, buf + 12))
6935 #endif /* CONFIG_AP */
6936 } else if (os_strcmp(buf, "SUSPEND") == 0) {
6937 wpas_notify_suspend(wpa_s->global);
6938 } else if (os_strcmp(buf, "RESUME") == 0) {
6939 wpas_notify_resume(wpa_s->global);
6940 #ifdef CONFIG_TESTING_OPTIONS
6941 } else if (os_strcmp(buf, "DROP_SA") == 0) {
6942 wpa_supplicant_ctrl_iface_drop_sa(wpa_s);
6943 #endif /* CONFIG_TESTING_OPTIONS */
6944 } else if (os_strncmp(buf, "ROAM ", 5) == 0) {
6945 if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5))
6947 } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) {
6948 if (wpa_supplicant_ctrl_iface_sta_autoconnect(wpa_s, buf + 16))
6950 } else if (os_strncmp(buf, "BSS_EXPIRE_AGE ", 15) == 0) {
6951 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s, buf + 15))
6953 } else if (os_strncmp(buf, "BSS_EXPIRE_COUNT ", 17) == 0) {
6954 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s,
6957 } else if (os_strncmp(buf, "BSS_FLUSH ", 10) == 0) {
6958 if (wpa_supplicant_ctrl_iface_bss_flush(wpa_s, buf + 10))
6961 } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) {
6962 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14))
6964 } else if (os_strncmp(buf, "TDLS_SETUP ", 11) == 0) {
6965 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s, buf + 11))
6967 } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) {
6968 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14))
6970 #endif /* CONFIG_TDLS */
6971 } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) {
6972 reply_len = wpa_supplicant_signal_poll(wpa_s, reply,
6974 } else if (os_strncmp(buf, "PKTCNT_POLL", 11) == 0) {
6975 reply_len = wpa_supplicant_pktcnt_poll(wpa_s, reply,
6977 #ifdef CONFIG_AUTOSCAN
6978 } else if (os_strncmp(buf, "AUTOSCAN ", 9) == 0) {
6979 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s, buf + 9))
6981 #endif /* CONFIG_AUTOSCAN */
6983 } else if (os_strncmp(buf, "DRIVER ", 7) == 0) {
6984 reply_len = wpa_supplicant_driver_cmd(wpa_s, buf + 7, reply,
6986 #endif /* ANDROID */
6987 } else if (os_strncmp(buf, "VENDOR ", 7) == 0) {
6988 reply_len = wpa_supplicant_vendor_cmd(wpa_s, buf + 7, reply,
6990 } else if (os_strcmp(buf, "REAUTHENTICATE") == 0) {
6991 pmksa_cache_clear_current(wpa_s->wpa);
6992 eapol_sm_request_reauth(wpa_s->eapol);
6994 } else if (os_strncmp(buf, "WNM_SLEEP ", 10) == 0) {
6995 if (wpas_ctrl_iface_wnm_sleep(wpa_s, buf + 10))
6997 } else if (os_strncmp(buf, "WNM_BSS_QUERY ", 10) == 0) {
6998 if (wpas_ctrl_iface_wnm_bss_query(wpa_s, buf + 10))
7000 #endif /* CONFIG_WNM */
7001 } else if (os_strcmp(buf, "FLUSH") == 0) {
7002 wpa_supplicant_ctrl_iface_flush(wpa_s);
7003 } else if (os_strncmp(buf, "RADIO_WORK ", 11) == 0) {
7004 reply_len = wpas_ctrl_radio_work(wpa_s, buf + 11, reply,
7006 #ifdef CONFIG_TESTING_OPTIONS
7007 } else if (os_strncmp(buf, "MGMT_TX ", 8) == 0) {
7008 if (wpas_ctrl_iface_mgmt_tx(wpa_s, buf + 8) < 0)
7010 } else if (os_strcmp(buf, "MGMT_TX_DONE") == 0) {
7011 wpas_ctrl_iface_mgmt_tx_done(wpa_s);
7012 } else if (os_strncmp(buf, "DRIVER_EVENT ", 13) == 0) {
7013 if (wpas_ctrl_iface_driver_event(wpa_s, buf + 13) < 0)
7015 #endif /* CONFIG_TESTING_OPTIONS */
7016 } else if (os_strncmp(buf, "VENDOR_ELEM_ADD ", 16) == 0) {
7017 if (wpas_ctrl_vendor_elem_add(wpa_s, buf + 16) < 0)
7019 } else if (os_strncmp(buf, "VENDOR_ELEM_GET ", 16) == 0) {
7020 reply_len = wpas_ctrl_vendor_elem_get(wpa_s, buf + 16, reply,
7022 } else if (os_strncmp(buf, "VENDOR_ELEM_REMOVE ", 19) == 0) {
7023 if (wpas_ctrl_vendor_elem_remove(wpa_s, buf + 19) < 0)
7026 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
7030 if (reply_len < 0) {
7031 os_memcpy(reply, "FAIL\n", 5);
7035 *resp_len = reply_len;
7040 static int wpa_supplicant_global_iface_add(struct wpa_global *global,
7043 struct wpa_interface iface;
7047 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
7048 * TAB<bridge_ifname>
7050 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd);
7052 os_memset(&iface, 0, sizeof(iface));
7055 iface.ifname = pos = cmd;
7056 pos = os_strchr(pos, '\t');
7059 if (iface.ifname[0] == '\0')
7064 iface.confname = pos;
7065 pos = os_strchr(pos, '\t');
7068 if (iface.confname[0] == '\0')
7069 iface.confname = NULL;
7074 pos = os_strchr(pos, '\t');
7077 if (iface.driver[0] == '\0')
7078 iface.driver = NULL;
7082 iface.ctrl_interface = pos;
7083 pos = os_strchr(pos, '\t');
7086 if (iface.ctrl_interface[0] == '\0')
7087 iface.ctrl_interface = NULL;
7091 iface.driver_param = pos;
7092 pos = os_strchr(pos, '\t');
7095 if (iface.driver_param[0] == '\0')
7096 iface.driver_param = NULL;
7100 iface.bridge_ifname = pos;
7101 pos = os_strchr(pos, '\t');
7104 if (iface.bridge_ifname[0] == '\0')
7105 iface.bridge_ifname = NULL;
7110 if (wpa_supplicant_get_iface(global, iface.ifname))
7113 return wpa_supplicant_add_iface(global, &iface) ? 0 : -1;
7117 static int wpa_supplicant_global_iface_remove(struct wpa_global *global,
7120 struct wpa_supplicant *wpa_s;
7122 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd);
7124 wpa_s = wpa_supplicant_get_iface(global, cmd);
7127 return wpa_supplicant_remove_iface(global, wpa_s, 0);
7131 static void wpa_free_iface_info(struct wpa_interface_info *iface)
7133 struct wpa_interface_info *prev;
7137 iface = iface->next;
7139 os_free(prev->ifname);
7140 os_free(prev->desc);
7146 static int wpa_supplicant_global_iface_list(struct wpa_global *global,
7150 struct wpa_interface_info *iface = NULL, *last = NULL, *tmp;
7153 for (i = 0; wpa_drivers[i]; i++) {
7154 struct wpa_driver_ops *drv = wpa_drivers[i];
7155 if (drv->get_interfaces == NULL)
7157 tmp = drv->get_interfaces(global->drv_priv[i]);
7171 for (tmp = iface; tmp; tmp = tmp->next) {
7172 res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n",
7173 tmp->drv_name, tmp->ifname,
7174 tmp->desc ? tmp->desc : "");
7175 if (res < 0 || res >= end - pos) {
7182 wpa_free_iface_info(iface);
7188 static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
7193 struct wpa_supplicant *wpa_s;
7195 wpa_s = global->ifaces;
7200 res = os_snprintf(pos, end - pos, "%s\n", wpa_s->ifname);
7201 if (res < 0 || res >= end - pos) {
7206 wpa_s = wpa_s->next;
7212 static char * wpas_global_ctrl_iface_ifname(struct wpa_global *global,
7214 char *cmd, size_t *resp_len)
7216 struct wpa_supplicant *wpa_s;
7218 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
7219 if (os_strcmp(ifname, wpa_s->ifname) == 0)
7223 if (wpa_s == NULL) {
7224 char *resp = os_strdup("FAIL-NO-IFNAME-MATCH\n");
7226 *resp_len = os_strlen(resp);
7232 return wpa_supplicant_ctrl_iface_process(wpa_s, cmd, resp_len);
7236 static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global *global,
7237 char *buf, size_t *resp_len)
7240 static const char * cmd[] = {
7246 "P2P_GET_PASSPHRASE",
7247 "P2P_SERVICE_UPDATE",
7248 "P2P_SERVICE_FLUSH",
7255 static const char * prefix[] = {
7258 #endif /* ANDROID */
7264 "P2P_GROUP_REMOVE ",
7267 "P2P_SERV_DISC_REQ ",
7268 "P2P_SERV_DISC_CANCEL_REQ ",
7269 "P2P_SERV_DISC_RESP ",
7270 "P2P_SERV_DISC_EXTERNAL ",
7278 "P2P_PRESENCE_REQ ",
7280 "P2P_REMOVE_CLIENT ",
7281 "NFC_GET_HANDOVER_SEL ",
7282 "NFC_GET_HANDOVER_REQ ",
7283 "NFC_REPORT_HANDOVER ",
7289 if (global->p2p_init_wpa_s == NULL)
7292 for (i = 0; !found && cmd[i]; i++) {
7293 if (os_strcmp(buf, cmd[i]) == 0)
7297 for (i = 0; !found && prefix[i]; i++) {
7298 if (os_strncmp(buf, prefix[i], os_strlen(prefix[i])) == 0)
7303 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
7305 #endif /* CONFIG_P2P */
7310 static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global *global,
7311 char *buf, size_t *resp_len)
7313 #ifdef CONFIG_WIFI_DISPLAY
7314 if (global->p2p_init_wpa_s == NULL)
7316 if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0 ||
7317 os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0)
7318 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
7320 #endif /* CONFIG_WIFI_DISPLAY */
7325 static char * wpas_global_ctrl_iface_redir(struct wpa_global *global,
7326 char *buf, size_t *resp_len)
7330 ret = wpas_global_ctrl_iface_redir_p2p(global, buf, resp_len);
7334 ret = wpas_global_ctrl_iface_redir_wfd(global, buf, resp_len);
7342 static int wpas_global_ctrl_iface_set(struct wpa_global *global, char *cmd)
7346 value = os_strchr(cmd, ' ');
7351 wpa_printf(MSG_DEBUG, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd, value);
7353 #ifdef CONFIG_WIFI_DISPLAY
7354 if (os_strcasecmp(cmd, "wifi_display") == 0) {
7355 wifi_display_enable(global, !!atoi(value));
7358 #endif /* CONFIG_WIFI_DISPLAY */
7360 /* Restore cmd to its original value to allow redirection */
7367 #ifndef CONFIG_NO_CONFIG_WRITE
7368 static int wpas_global_ctrl_iface_save_config(struct wpa_global *global)
7370 int ret = 0, saved = 0;
7371 struct wpa_supplicant *wpa_s;
7373 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
7374 if (!wpa_s->conf->update_config) {
7375 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
7379 if (wpa_config_write(wpa_s->confname, wpa_s->conf)) {
7380 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
7383 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
7388 if (!saved && !ret) {
7389 wpa_dbg(wpa_s, MSG_DEBUG,
7390 "CTRL_IFACE: SAVE_CONFIG - No configuration files could be updated");
7396 #endif /* CONFIG_NO_CONFIG_WRITE */
7399 static int wpas_global_ctrl_iface_status(struct wpa_global *global,
7400 char *buf, size_t buflen)
7404 struct wpa_supplicant *wpa_s;
7410 if (global->p2p && !global->p2p_disabled) {
7411 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
7414 MAC2STR(global->p2p_dev_addr),
7415 p2p_get_state_txt(global->p2p));
7416 if (ret < 0 || ret >= end - pos)
7419 } else if (global->p2p) {
7420 ret = os_snprintf(pos, end - pos, "p2p_state=DISABLED\n");
7421 if (ret < 0 || ret >= end - pos)
7425 #endif /* CONFIG_P2P */
7427 #ifdef CONFIG_WIFI_DISPLAY
7428 ret = os_snprintf(pos, end - pos, "wifi_display=%d\n",
7429 !!global->wifi_display);
7430 if (ret < 0 || ret >= end - pos)
7433 #endif /* CONFIG_WIFI_DISPLAY */
7435 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
7436 ret = os_snprintf(pos, end - pos, "ifname=%s\n"
7437 "address=" MACSTR "\n",
7438 wpa_s->ifname, MAC2STR(wpa_s->own_addr));
7439 if (ret < 0 || ret >= end - pos)
7448 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
7449 char *buf, size_t *resp_len)
7452 const int reply_size = 2048;
7454 int level = MSG_DEBUG;
7456 if (os_strncmp(buf, "IFNAME=", 7) == 0) {
7457 char *pos = os_strchr(buf + 7, ' ');
7460 return wpas_global_ctrl_iface_ifname(global,
7466 reply = wpas_global_ctrl_iface_redir(global, buf, resp_len);
7470 if (os_strcmp(buf, "PING") == 0)
7471 level = MSG_EXCESSIVE;
7472 wpa_hexdump_ascii(level, "RX global ctrl_iface",
7473 (const u8 *) buf, os_strlen(buf));
7475 reply = os_malloc(reply_size);
7476 if (reply == NULL) {
7481 os_memcpy(reply, "OK\n", 3);
7484 if (os_strcmp(buf, "PING") == 0) {
7485 os_memcpy(reply, "PONG\n", 5);
7487 } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) {
7488 if (wpa_supplicant_global_iface_add(global, buf + 14))
7490 } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) {
7491 if (wpa_supplicant_global_iface_remove(global, buf + 17))
7493 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
7494 reply_len = wpa_supplicant_global_iface_list(
7495 global, reply, reply_size);
7496 } else if (os_strcmp(buf, "INTERFACES") == 0) {
7497 reply_len = wpa_supplicant_global_iface_interfaces(
7498 global, reply, reply_size);
7499 } else if (os_strcmp(buf, "TERMINATE") == 0) {
7500 wpa_supplicant_terminate_proc(global);
7501 } else if (os_strcmp(buf, "SUSPEND") == 0) {
7502 wpas_notify_suspend(global);
7503 } else if (os_strcmp(buf, "RESUME") == 0) {
7504 wpas_notify_resume(global);
7505 } else if (os_strncmp(buf, "SET ", 4) == 0) {
7506 if (wpas_global_ctrl_iface_set(global, buf + 4)) {
7508 if (global->p2p_init_wpa_s) {
7510 /* Check if P2P redirection would work for this
7512 return wpa_supplicant_ctrl_iface_process(
7513 global->p2p_init_wpa_s,
7516 #endif /* CONFIG_P2P */
7519 #ifndef CONFIG_NO_CONFIG_WRITE
7520 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
7521 if (wpas_global_ctrl_iface_save_config(global))
7523 #endif /* CONFIG_NO_CONFIG_WRITE */
7524 } else if (os_strcmp(buf, "STATUS") == 0) {
7525 reply_len = wpas_global_ctrl_iface_status(global, reply,
7527 #ifdef CONFIG_MODULE_TESTS
7528 } else if (os_strcmp(buf, "MODULE_TESTS") == 0) {
7529 int wpas_module_tests(void);
7530 if (wpas_module_tests() < 0)
7532 #endif /* CONFIG_MODULE_TESTS */
7534 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
7538 if (reply_len < 0) {
7539 os_memcpy(reply, "FAIL\n", 5);
7543 *resp_len = reply_len;