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)
1543 ret = os_snprintf(pos, end - pos, "freq=%u\n",
1545 if (ret < 0 || ret >= end - pos)
1549 u8 *_ssid = ssid->ssid;
1550 size_t ssid_len = ssid->ssid_len;
1551 u8 ssid_buf[MAX_SSID_LEN];
1552 if (ssid_len == 0) {
1553 int _res = wpa_drv_get_ssid(wpa_s, ssid_buf);
1560 ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n",
1561 wpa_ssid_txt(_ssid, ssid_len),
1563 if (ret < 0 || ret >= end - pos)
1567 if (wps && ssid->passphrase &&
1568 wpa_key_mgmt_wpa_psk(ssid->key_mgmt) &&
1569 (ssid->mode == WPAS_MODE_AP ||
1570 ssid->mode == WPAS_MODE_P2P_GO)) {
1571 ret = os_snprintf(pos, end - pos,
1574 if (ret < 0 || ret >= end - pos)
1579 ret = os_snprintf(pos, end - pos,
1582 if (ret < 0 || ret >= end - pos)
1587 switch (ssid->mode) {
1588 case WPAS_MODE_INFRA:
1589 ret = os_snprintf(pos, end - pos,
1592 case WPAS_MODE_IBSS:
1593 ret = os_snprintf(pos, end - pos,
1597 ret = os_snprintf(pos, end - pos,
1600 case WPAS_MODE_P2P_GO:
1601 ret = os_snprintf(pos, end - pos,
1604 case WPAS_MODE_P2P_GROUP_FORMATION:
1605 ret = os_snprintf(pos, end - pos,
1606 "mode=P2P GO - group "
1613 if (ret < 0 || ret >= end - pos)
1619 if (wpa_s->ap_iface) {
1620 pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos,
1624 #endif /* CONFIG_AP */
1625 pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose);
1628 if (wpa_s->wpa_state >= WPA_ASSOCIATED &&
1631 #endif /* CONFIG_AP */
1632 wpa_s->sme.sae.state == SAE_ACCEPTED) {
1633 ret = os_snprintf(pos, end - pos, "sae_group=%d\n",
1634 wpa_s->sme.sae.group);
1635 if (ret < 0 || ret >= end - pos)
1639 #endif /* CONFIG_SAE */
1640 ret = os_snprintf(pos, end - pos, "wpa_state=%s\n",
1641 wpa_supplicant_state_txt(wpa_s->wpa_state));
1642 if (ret < 0 || ret >= end - pos)
1647 l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) {
1648 ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp);
1649 if (ret < 0 || ret >= end - pos)
1655 if (wpa_s->global->p2p) {
1656 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
1657 "\n", MAC2STR(wpa_s->global->p2p_dev_addr));
1658 if (ret < 0 || ret >= end - pos)
1662 #endif /* CONFIG_P2P */
1664 ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n",
1665 MAC2STR(wpa_s->own_addr));
1666 if (ret < 0 || ret >= end - pos)
1671 if (wpa_s->current_bss &&
1672 (hs20 = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1673 HS20_IE_VENDOR_TYPE)) &&
1674 wpa_s->wpa_proto == WPA_PROTO_RSN &&
1675 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1678 u8 rel_num = (hs20[6] & 0xf0) >> 4;
1679 release = rel_num + 1;
1681 ret = os_snprintf(pos, end - pos, "hs20=%d\n", release);
1682 if (ret < 0 || ret >= end - pos)
1687 if (wpa_s->current_ssid) {
1688 struct wpa_cred *cred;
1691 for (cred = wpa_s->conf->cred; cred; cred = cred->next) {
1694 if (wpa_s->current_ssid->parent_cred != cred)
1697 if (cred->provisioning_sp) {
1698 ret = os_snprintf(pos, end - pos,
1699 "provisioning_sp=%s\n",
1700 cred->provisioning_sp);
1701 if (ret < 0 || ret >= end - pos)
1710 if (wpa_s->current_bss && wpa_s->current_bss->anqp) {
1711 struct wpabuf *names =
1712 wpa_s->current_bss->anqp->domain_name;
1713 for (i = 0; names && i < cred->num_domain; i++)
1715 if (domain_name_list_contains(
1716 names, cred->domain[i], 1))
1719 if (i == cred->num_domain)
1720 i = 0; /* show first entry by default */
1722 ret = os_snprintf(pos, end - pos, "home_sp=%s\n",
1724 if (ret < 0 || ret >= end - pos)
1729 if (wpa_s->current_bss == NULL ||
1730 wpa_s->current_bss->anqp == NULL)
1733 res = interworking_home_sp_cred(
1735 wpa_s->current_bss->anqp->domain_name);
1743 ret = os_snprintf(pos, end - pos, "sp_type=%s\n", type);
1744 if (ret < 0 || ret >= end - pos)
1751 #endif /* CONFIG_HS20 */
1753 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
1754 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
1755 res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos,
1761 res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose);
1768 uuid_bin2str(wpa_s->wps->uuid, uuid_str, sizeof(uuid_str));
1769 ret = os_snprintf(pos, end - pos, "uuid=%s\n", uuid_str);
1770 if (ret < 0 || ret >= end - pos)
1774 #endif /* CONFIG_WPS */
1778 * Allow using the STATUS command with default behavior, say for debug,
1779 * i.e., don't generate a "fake" CONNECTION and SUPPLICANT_STATE_CHANGE
1780 * events with STATUS-NO_EVENTS.
1782 if (os_strcmp(params, "-NO_EVENTS")) {
1783 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_STATE_CHANGE
1784 "id=%d state=%d BSSID=" MACSTR " SSID=%s",
1785 wpa_s->current_ssid ? wpa_s->current_ssid->id : -1,
1787 MAC2STR(wpa_s->bssid),
1788 wpa_s->current_ssid && wpa_s->current_ssid->ssid ?
1789 wpa_ssid_txt(wpa_s->current_ssid->ssid,
1790 wpa_s->current_ssid->ssid_len) : "");
1791 if (wpa_s->wpa_state == WPA_COMPLETED) {
1792 struct wpa_ssid *ssid = wpa_s->current_ssid;
1793 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_CONNECTED
1794 "- connection to " MACSTR
1795 " completed %s [id=%d id_str=%s]",
1796 MAC2STR(wpa_s->bssid), "(auth)",
1797 ssid ? ssid->id : -1,
1798 ssid && ssid->id_str ? ssid->id_str : "");
1801 #endif /* ANDROID */
1807 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s,
1812 struct wpa_ssid *ssid;
1815 /* cmd: "<network id> <BSSID>" */
1816 pos = os_strchr(cmd, ' ');
1821 wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos);
1822 if (hwaddr_aton(pos, bssid)) {
1823 wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos);
1827 ssid = wpa_config_get_network(wpa_s->conf, id);
1829 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
1834 os_memcpy(ssid->bssid, bssid, ETH_ALEN);
1835 ssid->bssid_set = !is_zero_ether_addr(bssid);
1841 static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant *wpa_s,
1842 char *cmd, char *buf,
1846 struct wpa_blacklist *e;
1850 /* cmd: "BLACKLIST [<BSSID>]" */
1854 e = wpa_s->blacklist;
1856 ret = os_snprintf(pos, end - pos, MACSTR "\n",
1858 if (ret < 0 || ret >= end - pos)
1867 if (os_strncmp(cmd, "clear", 5) == 0) {
1868 wpa_blacklist_clear(wpa_s);
1869 os_memcpy(buf, "OK\n", 3);
1873 wpa_printf(MSG_DEBUG, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd);
1874 if (hwaddr_aton(cmd, bssid)) {
1875 wpa_printf(MSG_DEBUG, "CTRL_IFACE: invalid BSSID '%s'", cmd);
1880 * Add the BSSID twice, so its count will be 2, causing it to be
1881 * skipped when processing scan results.
1883 ret = wpa_blacklist_add(wpa_s, bssid);
1886 ret = wpa_blacklist_add(wpa_s, bssid);
1889 os_memcpy(buf, "OK\n", 3);
1894 static const char * debug_level_str(int level)
1915 static int str_to_debug_level(const char *s)
1917 if (os_strcasecmp(s, "EXCESSIVE") == 0)
1918 return MSG_EXCESSIVE;
1919 if (os_strcasecmp(s, "MSGDUMP") == 0)
1921 if (os_strcasecmp(s, "DEBUG") == 0)
1923 if (os_strcasecmp(s, "INFO") == 0)
1925 if (os_strcasecmp(s, "WARNING") == 0)
1927 if (os_strcasecmp(s, "ERROR") == 0)
1933 static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant *wpa_s,
1934 char *cmd, char *buf,
1937 char *pos, *end, *stamp;
1944 /* cmd: "LOG_LEVEL [<level>]" */
1948 ret = os_snprintf(pos, end - pos, "Current level: %s\n"
1950 debug_level_str(wpa_debug_level),
1951 wpa_debug_timestamp);
1952 if (ret < 0 || ret >= end - pos)
1961 stamp = os_strchr(cmd, ' ');
1964 while (*stamp == ' ') {
1969 if (cmd && os_strlen(cmd)) {
1970 int level = str_to_debug_level(cmd);
1973 wpa_debug_level = level;
1976 if (stamp && os_strlen(stamp))
1977 wpa_debug_timestamp = atoi(stamp);
1979 os_memcpy(buf, "OK\n", 3);
1984 static int wpa_supplicant_ctrl_iface_list_networks(
1985 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
1988 struct wpa_ssid *ssid;
1993 ret = os_snprintf(pos, end - pos,
1994 "network id / ssid / bssid / flags\n");
1995 if (ret < 0 || ret >= end - pos)
1999 ssid = wpa_s->conf->ssid;
2001 ret = os_snprintf(pos, end - pos, "%d\t%s",
2003 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
2004 if (ret < 0 || ret >= end - pos)
2007 if (ssid->bssid_set) {
2008 ret = os_snprintf(pos, end - pos, "\t" MACSTR,
2009 MAC2STR(ssid->bssid));
2011 ret = os_snprintf(pos, end - pos, "\tany");
2013 if (ret < 0 || ret >= end - pos)
2016 ret = os_snprintf(pos, end - pos, "\t%s%s%s%s",
2017 ssid == wpa_s->current_ssid ?
2019 ssid->disabled ? "[DISABLED]" : "",
2020 ssid->disabled_until.sec ?
2021 "[TEMP-DISABLED]" : "",
2022 ssid->disabled == 2 ? "[P2P-PERSISTENT]" :
2024 if (ret < 0 || ret >= end - pos)
2027 ret = os_snprintf(pos, end - pos, "\n");
2028 if (ret < 0 || ret >= end - pos)
2039 static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher)
2042 ret = os_snprintf(pos, end - pos, "-");
2043 if (ret < 0 || ret >= end - pos)
2046 ret = wpa_write_ciphers(pos, end, cipher, "+");
2054 static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
2055 const u8 *ie, size_t ie_len)
2057 struct wpa_ie_data data;
2061 ret = os_snprintf(pos, end - pos, "[%s-", proto);
2062 if (ret < 0 || ret >= end - pos)
2066 if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) {
2067 ret = os_snprintf(pos, end - pos, "?]");
2068 if (ret < 0 || ret >= end - pos)
2075 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
2076 ret = os_snprintf(pos, end - pos, "%sEAP",
2077 pos == start ? "" : "+");
2078 if (ret < 0 || ret >= end - pos)
2082 if (data.key_mgmt & WPA_KEY_MGMT_PSK) {
2083 ret = os_snprintf(pos, end - pos, "%sPSK",
2084 pos == start ? "" : "+");
2085 if (ret < 0 || ret >= end - pos)
2089 if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
2090 ret = os_snprintf(pos, end - pos, "%sNone",
2091 pos == start ? "" : "+");
2092 if (ret < 0 || ret >= end - pos)
2096 #ifdef CONFIG_IEEE80211R
2097 if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
2098 ret = os_snprintf(pos, end - pos, "%sFT/EAP",
2099 pos == start ? "" : "+");
2100 if (ret < 0 || ret >= end - pos)
2104 if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) {
2105 ret = os_snprintf(pos, end - pos, "%sFT/PSK",
2106 pos == start ? "" : "+");
2107 if (ret < 0 || ret >= end - pos)
2111 #endif /* CONFIG_IEEE80211R */
2112 #ifdef CONFIG_IEEE80211W
2113 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
2114 ret = os_snprintf(pos, end - pos, "%sEAP-SHA256",
2115 pos == start ? "" : "+");
2116 if (ret < 0 || ret >= end - pos)
2120 if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
2121 ret = os_snprintf(pos, end - pos, "%sPSK-SHA256",
2122 pos == start ? "" : "+");
2123 if (ret < 0 || ret >= end - pos)
2127 #endif /* CONFIG_IEEE80211W */
2129 pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher);
2131 if (data.capabilities & WPA_CAPABILITY_PREAUTH) {
2132 ret = os_snprintf(pos, end - pos, "-preauth");
2133 if (ret < 0 || ret >= end - pos)
2138 ret = os_snprintf(pos, end - pos, "]");
2139 if (ret < 0 || ret >= end - pos)
2148 static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s,
2149 char *pos, char *end,
2150 struct wpabuf *wps_ie)
2157 if (wps_is_selected_pbc_registrar(wps_ie))
2159 else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0))
2161 else if (wps_is_selected_pin_registrar(wps_ie))
2166 ret = os_snprintf(pos, end - pos, "%s", txt);
2167 if (ret >= 0 && ret < end - pos)
2169 wpabuf_free(wps_ie);
2172 #endif /* CONFIG_WPS */
2175 static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s,
2176 char *pos, char *end,
2177 const struct wpa_bss *bss)
2180 struct wpabuf *wps_ie;
2181 wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
2182 return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie);
2183 #else /* CONFIG_WPS */
2185 #endif /* CONFIG_WPS */
2189 /* Format one result on one text line into a buffer. */
2190 static int wpa_supplicant_ctrl_iface_scan_result(
2191 struct wpa_supplicant *wpa_s,
2192 const struct wpa_bss *bss, char *buf, size_t buflen)
2196 const u8 *ie, *ie2, *p2p;
2198 p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
2200 p2p = wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE);
2201 if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN &&
2202 os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) ==
2204 return 0; /* Do not show P2P listen discovery results here */
2209 ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t",
2210 MAC2STR(bss->bssid), bss->freq, bss->level);
2211 if (ret < 0 || ret >= end - pos)
2214 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
2216 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]);
2217 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
2219 pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2, 2 + ie2[1]);
2220 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
2221 if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
2222 ret = os_snprintf(pos, end - pos, "[WEP]");
2223 if (ret < 0 || ret >= end - pos)
2227 if (bss_is_dmg(bss)) {
2229 ret = os_snprintf(pos, end - pos, "[DMG]");
2230 if (ret < 0 || ret >= end - pos)
2233 switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
2234 case IEEE80211_CAP_DMG_IBSS:
2237 case IEEE80211_CAP_DMG_AP:
2240 case IEEE80211_CAP_DMG_PBSS:
2247 ret = os_snprintf(pos, end - pos, "%s", s);
2248 if (ret < 0 || ret >= end - pos)
2252 if (bss->caps & IEEE80211_CAP_IBSS) {
2253 ret = os_snprintf(pos, end - pos, "[IBSS]");
2254 if (ret < 0 || ret >= end - pos)
2258 if (bss->caps & IEEE80211_CAP_ESS) {
2259 ret = os_snprintf(pos, end - pos, "[ESS]");
2260 if (ret < 0 || ret >= end - pos)
2266 ret = os_snprintf(pos, end - pos, "[P2P]");
2267 if (ret < 0 || ret >= end - pos)
2272 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE) && ie2) {
2273 ret = os_snprintf(pos, end - pos, "[HS20]");
2274 if (ret < 0 || ret >= end - pos)
2278 #endif /* CONFIG_HS20 */
2280 ret = os_snprintf(pos, end - pos, "\t%s",
2281 wpa_ssid_txt(bss->ssid, bss->ssid_len));
2282 if (ret < 0 || ret >= end - pos)
2286 ret = os_snprintf(pos, end - pos, "\n");
2287 if (ret < 0 || ret >= end - pos)
2295 static int wpa_supplicant_ctrl_iface_scan_results(
2296 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
2299 struct wpa_bss *bss;
2304 ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / "
2306 if (ret < 0 || ret >= end - pos)
2310 dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
2311 ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos,
2313 if (ret < 0 || ret >= end - pos)
2322 static int wpa_supplicant_ctrl_iface_select_network(
2323 struct wpa_supplicant *wpa_s, char *cmd)
2326 struct wpa_ssid *ssid;
2329 /* cmd: "<network id>" or "any" */
2330 if (os_strncmp(cmd, "any", 3) == 0) {
2331 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any");
2335 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id);
2337 ssid = wpa_config_get_network(wpa_s->conf, id);
2339 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2340 "network id=%d", id);
2343 if (ssid->disabled == 2) {
2344 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2345 "SELECT_NETWORK with persistent P2P group");
2350 pos = os_strstr(cmd, " freq=");
2352 int *freqs = freq_range_to_channel_list(wpa_s, pos + 6);
2354 wpa_s->scan_req = MANUAL_SCAN_REQ;
2355 os_free(wpa_s->manual_scan_freqs);
2356 wpa_s->manual_scan_freqs = freqs;
2360 wpa_supplicant_select_network(wpa_s, ssid);
2366 static int wpa_supplicant_ctrl_iface_enable_network(
2367 struct wpa_supplicant *wpa_s, char *cmd)
2370 struct wpa_ssid *ssid;
2372 /* cmd: "<network id>" or "all" */
2373 if (os_strcmp(cmd, "all") == 0) {
2374 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all");
2378 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id);
2380 ssid = wpa_config_get_network(wpa_s->conf, id);
2382 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2383 "network id=%d", id);
2386 if (ssid->disabled == 2) {
2387 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2388 "ENABLE_NETWORK with persistent P2P group");
2392 if (os_strstr(cmd, " no-connect")) {
2397 wpa_supplicant_enable_network(wpa_s, ssid);
2403 static int wpa_supplicant_ctrl_iface_disable_network(
2404 struct wpa_supplicant *wpa_s, char *cmd)
2407 struct wpa_ssid *ssid;
2409 /* cmd: "<network id>" or "all" */
2410 if (os_strcmp(cmd, "all") == 0) {
2411 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all");
2415 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id);
2417 ssid = wpa_config_get_network(wpa_s->conf, id);
2419 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2420 "network id=%d", id);
2423 if (ssid->disabled == 2) {
2424 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2425 "DISABLE_NETWORK with persistent P2P "
2430 wpa_supplicant_disable_network(wpa_s, ssid);
2436 static int wpa_supplicant_ctrl_iface_add_network(
2437 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
2439 struct wpa_ssid *ssid;
2442 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK");
2444 ssid = wpa_config_add_network(wpa_s->conf);
2448 wpas_notify_network_added(wpa_s, ssid);
2451 wpa_config_set_network_defaults(ssid);
2453 ret = os_snprintf(buf, buflen, "%d\n", ssid->id);
2454 if (ret < 0 || (size_t) ret >= buflen)
2460 static int wpa_supplicant_ctrl_iface_remove_network(
2461 struct wpa_supplicant *wpa_s, char *cmd)
2464 struct wpa_ssid *ssid;
2467 /* cmd: "<network id>" or "all" */
2468 if (os_strcmp(cmd, "all") == 0) {
2469 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all");
2470 if (wpa_s->sched_scanning)
2471 wpa_supplicant_cancel_sched_scan(wpa_s);
2473 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2474 if (wpa_s->current_ssid) {
2476 wpa_s->sme.prev_bssid_set = 0;
2477 #endif /* CONFIG_SME */
2478 wpa_sm_set_config(wpa_s->wpa, NULL);
2479 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
2480 wpa_supplicant_deauthenticate(
2481 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2483 ssid = wpa_s->conf->ssid;
2485 struct wpa_ssid *remove_ssid = ssid;
2488 if (wpa_s->last_ssid == remove_ssid)
2489 wpa_s->last_ssid = NULL;
2490 wpas_notify_network_removed(wpa_s, remove_ssid);
2491 wpa_config_remove_network(wpa_s->conf, id);
2497 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id);
2499 ssid = wpa_config_get_network(wpa_s->conf, id);
2501 wpas_notify_network_removed(wpa_s, ssid);
2503 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2508 if (wpa_s->last_ssid == ssid)
2509 wpa_s->last_ssid = NULL;
2511 if (ssid == wpa_s->current_ssid || wpa_s->current_ssid == NULL) {
2513 wpa_s->sme.prev_bssid_set = 0;
2514 #endif /* CONFIG_SME */
2516 * Invalidate the EAP session cache if the current or
2517 * previously used network is removed.
2519 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2522 if (ssid == wpa_s->current_ssid) {
2523 wpa_sm_set_config(wpa_s->wpa, NULL);
2524 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
2526 wpa_supplicant_deauthenticate(wpa_s,
2527 WLAN_REASON_DEAUTH_LEAVING);
2530 was_disabled = ssid->disabled;
2532 if (wpa_config_remove_network(wpa_s->conf, id) < 0) {
2533 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Not able to remove the "
2534 "network id=%d", id);
2538 if (!was_disabled && wpa_s->sched_scanning) {
2539 wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to remove "
2540 "network from filters");
2541 wpa_supplicant_cancel_sched_scan(wpa_s);
2542 wpa_supplicant_req_scan(wpa_s, 0, 0);
2549 static int wpa_supplicant_ctrl_iface_update_network(
2550 struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
2551 char *name, char *value)
2553 if (wpa_config_set(ssid, name, value, 0) < 0) {
2554 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network "
2555 "variable '%s'", name);
2559 if (os_strcmp(name, "bssid") != 0 &&
2560 os_strcmp(name, "priority") != 0)
2561 wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
2563 if (wpa_s->current_ssid == ssid || wpa_s->current_ssid == NULL) {
2565 * Invalidate the EAP session cache if anything in the current
2566 * or previously used configuration changes.
2568 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2571 if ((os_strcmp(name, "psk") == 0 &&
2572 value[0] == '"' && ssid->ssid_len) ||
2573 (os_strcmp(name, "ssid") == 0 && ssid->passphrase))
2574 wpa_config_update_psk(ssid);
2575 else if (os_strcmp(name, "priority") == 0)
2576 wpa_config_update_prio_list(wpa_s->conf);
2582 static int wpa_supplicant_ctrl_iface_set_network(
2583 struct wpa_supplicant *wpa_s, char *cmd)
2585 int id, ret, prev_bssid_set;
2586 struct wpa_ssid *ssid;
2588 u8 prev_bssid[ETH_ALEN];
2590 /* cmd: "<network id> <variable name> <value>" */
2591 name = os_strchr(cmd, ' ');
2596 value = os_strchr(name, ' ');
2602 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
2604 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
2605 (u8 *) value, os_strlen(value));
2607 ssid = wpa_config_get_network(wpa_s->conf, id);
2609 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2614 prev_bssid_set = ssid->bssid_set;
2615 os_memcpy(prev_bssid, ssid->bssid, ETH_ALEN);
2616 ret = wpa_supplicant_ctrl_iface_update_network(wpa_s, ssid, name,
2619 (ssid->bssid_set != prev_bssid_set ||
2620 os_memcmp(ssid->bssid, prev_bssid, ETH_ALEN) != 0))
2621 wpas_notify_network_bssid_set_changed(wpa_s, ssid);
2626 static int wpa_supplicant_ctrl_iface_get_network(
2627 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
2631 struct wpa_ssid *ssid;
2634 /* cmd: "<network id> <variable name>" */
2635 name = os_strchr(cmd, ' ');
2636 if (name == NULL || buflen == 0)
2641 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
2644 ssid = wpa_config_get_network(wpa_s->conf, id);
2646 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2651 value = wpa_config_get_no_key(ssid, name);
2652 if (value == NULL) {
2653 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
2654 "variable '%s'", name);
2658 res = os_strlcpy(buf, value, buflen);
2659 if (res >= buflen) {
2670 static int wpa_supplicant_ctrl_iface_dup_network(
2671 struct wpa_supplicant *wpa_s, char *cmd)
2673 struct wpa_ssid *ssid_s, *ssid_d;
2674 char *name, *id, *value;
2675 int id_s, id_d, ret;
2677 /* cmd: "<src network id> <dst network id> <variable name>" */
2678 id = os_strchr(cmd, ' ');
2683 name = os_strchr(id, ' ');
2690 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DUP_NETWORK id=%d -> %d name='%s'",
2693 ssid_s = wpa_config_get_network(wpa_s->conf, id_s);
2694 if (ssid_s == NULL) {
2695 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2696 "network id=%d", id_s);
2700 ssid_d = wpa_config_get_network(wpa_s->conf, id_d);
2701 if (ssid_d == NULL) {
2702 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2703 "network id=%d", id_s);
2707 value = wpa_config_get(ssid_s, name);
2708 if (value == NULL) {
2709 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
2710 "variable '%s'", name);
2714 ret = wpa_supplicant_ctrl_iface_update_network(wpa_s, ssid_d, name,
2723 static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant *wpa_s,
2724 char *buf, size_t buflen)
2727 struct wpa_cred *cred;
2732 ret = os_snprintf(pos, end - pos,
2733 "cred id / realm / username / domain / imsi\n");
2734 if (ret < 0 || ret >= end - pos)
2738 cred = wpa_s->conf->cred;
2740 ret = os_snprintf(pos, end - pos, "%d\t%s\t%s\t%s\t%s\n",
2741 cred->id, cred->realm ? cred->realm : "",
2742 cred->username ? cred->username : "",
2743 cred->domain ? cred->domain[0] : "",
2744 cred->imsi ? cred->imsi : "");
2745 if (ret < 0 || ret >= end - pos)
2756 static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant *wpa_s,
2757 char *buf, size_t buflen)
2759 struct wpa_cred *cred;
2762 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_CRED");
2764 cred = wpa_config_add_cred(wpa_s->conf);
2768 wpa_msg(wpa_s, MSG_INFO, CRED_ADDED "%d", cred->id);
2770 ret = os_snprintf(buf, buflen, "%d\n", cred->id);
2771 if (ret < 0 || (size_t) ret >= buflen)
2777 static int wpas_ctrl_remove_cred(struct wpa_supplicant *wpa_s,
2778 struct wpa_cred *cred)
2780 struct wpa_ssid *ssid;
2785 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred");
2790 if (wpa_config_remove_cred(wpa_s->conf, id) < 0) {
2791 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred");
2795 wpa_msg(wpa_s, MSG_INFO, CRED_REMOVED "%d", id);
2797 /* Remove any network entry created based on the removed credential */
2798 ssid = wpa_s->conf->ssid;
2800 if (ssid->parent_cred == cred) {
2801 wpa_printf(MSG_DEBUG, "Remove network id %d since it "
2802 "used the removed credential", ssid->id);
2803 os_snprintf(str, sizeof(str), "%d", ssid->id);
2805 wpa_supplicant_ctrl_iface_remove_network(wpa_s, str);
2814 static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s,
2818 struct wpa_cred *cred, *prev;
2820 /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or
2821 * "provisioning_sp=<FQDN> */
2822 if (os_strcmp(cmd, "all") == 0) {
2823 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED all");
2824 cred = wpa_s->conf->cred;
2828 wpas_ctrl_remove_cred(wpa_s, prev);
2833 if (os_strncmp(cmd, "sp_fqdn=", 8) == 0) {
2834 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
2836 cred = wpa_s->conf->cred;
2842 for (i = 0; i < prev->num_domain; i++) {
2843 if (os_strcmp(prev->domain[i], cmd + 8)
2846 wpas_ctrl_remove_cred(wpa_s, prev);
2854 if (os_strncmp(cmd, "provisioning_sp=", 16) == 0) {
2855 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'",
2857 cred = wpa_s->conf->cred;
2861 if (prev->provisioning_sp &&
2862 os_strcmp(prev->provisioning_sp, cmd + 16) == 0)
2863 wpas_ctrl_remove_cred(wpa_s, prev);
2869 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED id=%d", id);
2871 cred = wpa_config_get_cred(wpa_s->conf, id);
2872 return wpas_ctrl_remove_cred(wpa_s, cred);
2876 static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant *wpa_s,
2880 struct wpa_cred *cred;
2883 /* cmd: "<cred id> <variable name> <value>" */
2884 name = os_strchr(cmd, ' ');
2889 value = os_strchr(name, ' ');
2895 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_CRED id=%d name='%s'",
2897 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
2898 (u8 *) value, os_strlen(value));
2900 cred = wpa_config_get_cred(wpa_s->conf, id);
2902 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
2907 if (wpa_config_set_cred(cred, name, value, 0) < 0) {
2908 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set cred "
2909 "variable '%s'", name);
2913 wpa_msg(wpa_s, MSG_INFO, CRED_MODIFIED "%d %s", cred->id, name);
2919 static int wpa_supplicant_ctrl_iface_get_cred(struct wpa_supplicant *wpa_s,
2920 char *cmd, char *buf,
2925 struct wpa_cred *cred;
2928 /* cmd: "<cred id> <variable name>" */
2929 name = os_strchr(cmd, ' ');
2935 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CRED id=%d name='%s'",
2938 cred = wpa_config_get_cred(wpa_s->conf, id);
2940 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
2945 value = wpa_config_get_cred_no_key(cred, name);
2946 if (value == NULL) {
2947 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get cred variable '%s'",
2952 res = os_strlcpy(buf, value, buflen);
2953 if (res >= buflen) {
2964 #ifndef CONFIG_NO_CONFIG_WRITE
2965 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s)
2969 if (!wpa_s->conf->update_config) {
2970 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
2971 "to update configuration (update_config=0)");
2975 ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
2977 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to "
2978 "update configuration");
2980 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration"
2986 #endif /* CONFIG_NO_CONFIG_WRITE */
2989 struct cipher_info {
2995 static const struct cipher_info ciphers[] = {
2996 { WPA_DRIVER_CAPA_ENC_CCMP_256, "CCMP-256", 0 },
2997 { WPA_DRIVER_CAPA_ENC_GCMP_256, "GCMP-256", 0 },
2998 { WPA_DRIVER_CAPA_ENC_CCMP, "CCMP", 0 },
2999 { WPA_DRIVER_CAPA_ENC_GCMP, "GCMP", 0 },
3000 { WPA_DRIVER_CAPA_ENC_TKIP, "TKIP", 0 },
3001 { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE, "NONE", 0 },
3002 { WPA_DRIVER_CAPA_ENC_WEP104, "WEP104", 1 },
3003 { WPA_DRIVER_CAPA_ENC_WEP40, "WEP40", 1 }
3007 static int ctrl_iface_get_capability_pairwise(int res, char *strict,
3008 struct wpa_driver_capa *capa,
3009 char *buf, size_t buflen)
3022 len = os_strlcpy(buf, "CCMP TKIP NONE", buflen);
3028 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
3029 if (!ciphers[i].group_only && capa->enc & ciphers[i].capa) {
3030 ret = os_snprintf(pos, end - pos, "%s%s",
3031 pos == buf ? "" : " ",
3033 if (ret < 0 || ret >= end - pos)
3043 static int ctrl_iface_get_capability_group(int res, char *strict,
3044 struct wpa_driver_capa *capa,
3045 char *buf, size_t buflen)
3058 len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen);
3064 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
3065 if (capa->enc & ciphers[i].capa) {
3066 ret = os_snprintf(pos, end - pos, "%s%s",
3067 pos == buf ? "" : " ",
3069 if (ret < 0 || ret >= end - pos)
3079 static int ctrl_iface_get_capability_key_mgmt(int res, char *strict,
3080 struct wpa_driver_capa *capa,
3081 char *buf, size_t buflen)
3093 len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
3100 ret = os_snprintf(pos, end - pos, "NONE IEEE8021X");
3101 if (ret < 0 || ret >= end - pos)
3105 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
3106 WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
3107 ret = os_snprintf(pos, end - pos, " WPA-EAP");
3108 if (ret < 0 || ret >= end - pos)
3113 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
3114 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
3115 ret = os_snprintf(pos, end - pos, " WPA-PSK");
3116 if (ret < 0 || ret >= end - pos)
3121 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
3122 ret = os_snprintf(pos, end - pos, " WPA-NONE");
3123 if (ret < 0 || ret >= end - pos)
3132 static int ctrl_iface_get_capability_proto(int res, char *strict,
3133 struct wpa_driver_capa *capa,
3134 char *buf, size_t buflen)
3146 len = os_strlcpy(buf, "RSN WPA", buflen);
3152 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
3153 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
3154 ret = os_snprintf(pos, end - pos, "%sRSN",
3155 pos == buf ? "" : " ");
3156 if (ret < 0 || ret >= end - pos)
3161 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
3162 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
3163 ret = os_snprintf(pos, end - pos, "%sWPA",
3164 pos == buf ? "" : " ");
3165 if (ret < 0 || ret >= end - pos)
3174 static int ctrl_iface_get_capability_auth_alg(int res, char *strict,
3175 struct wpa_driver_capa *capa,
3176 char *buf, size_t buflen)
3188 len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen);
3194 if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) {
3195 ret = os_snprintf(pos, end - pos, "%sOPEN",
3196 pos == buf ? "" : " ");
3197 if (ret < 0 || ret >= end - pos)
3202 if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) {
3203 ret = os_snprintf(pos, end - pos, "%sSHARED",
3204 pos == buf ? "" : " ");
3205 if (ret < 0 || ret >= end - pos)
3210 if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) {
3211 ret = os_snprintf(pos, end - pos, "%sLEAP",
3212 pos == buf ? "" : " ");
3213 if (ret < 0 || ret >= end - pos)
3222 static int ctrl_iface_get_capability_modes(int res, char *strict,
3223 struct wpa_driver_capa *capa,
3224 char *buf, size_t buflen)
3236 len = os_strlcpy(buf, "IBSS AP", buflen);
3242 if (capa->flags & WPA_DRIVER_FLAGS_IBSS) {
3243 ret = os_snprintf(pos, end - pos, "%sIBSS",
3244 pos == buf ? "" : " ");
3245 if (ret < 0 || ret >= end - pos)
3250 if (capa->flags & WPA_DRIVER_FLAGS_AP) {
3251 ret = os_snprintf(pos, end - pos, "%sAP",
3252 pos == buf ? "" : " ");
3253 if (ret < 0 || ret >= end - pos)
3262 static int ctrl_iface_get_capability_channels(struct wpa_supplicant *wpa_s,
3263 char *buf, size_t buflen)
3265 struct hostapd_channel_data *chnl;
3267 char *pos, *end, *hmode;
3272 for (j = 0; j < wpa_s->hw.num_modes; j++) {
3273 switch (wpa_s->hw.modes[j].mode) {
3274 case HOSTAPD_MODE_IEEE80211B:
3277 case HOSTAPD_MODE_IEEE80211G:
3280 case HOSTAPD_MODE_IEEE80211A:
3283 case HOSTAPD_MODE_IEEE80211AD:
3289 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:", hmode);
3290 if (ret < 0 || ret >= end - pos)
3293 chnl = wpa_s->hw.modes[j].channels;
3294 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
3295 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
3297 ret = os_snprintf(pos, end - pos, " %d", chnl[i].chan);
3298 if (ret < 0 || ret >= end - pos)
3302 ret = os_snprintf(pos, end - pos, "\n");
3303 if (ret < 0 || ret >= end - pos)
3312 static int ctrl_iface_get_capability_freq(struct wpa_supplicant *wpa_s,
3313 char *buf, size_t buflen)
3315 struct hostapd_channel_data *chnl;
3317 char *pos, *end, *hmode;
3322 for (j = 0; j < wpa_s->hw.num_modes; j++) {
3323 switch (wpa_s->hw.modes[j].mode) {
3324 case HOSTAPD_MODE_IEEE80211B:
3327 case HOSTAPD_MODE_IEEE80211G:
3330 case HOSTAPD_MODE_IEEE80211A:
3333 case HOSTAPD_MODE_IEEE80211AD:
3339 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:\n",
3341 if (ret < 0 || ret >= end - pos)
3344 chnl = wpa_s->hw.modes[j].channels;
3345 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
3346 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
3348 ret = os_snprintf(pos, end - pos, " %d = %d MHz%s%s\n",
3349 chnl[i].chan, chnl[i].freq,
3350 chnl[i].flag & HOSTAPD_CHAN_NO_IBSS ?
3352 chnl[i].flag & HOSTAPD_CHAN_RADAR ?
3355 if (ret < 0 || ret >= end - pos)
3359 ret = os_snprintf(pos, end - pos, "\n");
3360 if (ret < 0 || ret >= end - pos)
3369 static int wpa_supplicant_ctrl_iface_get_capability(
3370 struct wpa_supplicant *wpa_s, const char *_field, char *buf,
3373 struct wpa_driver_capa capa;
3379 /* Determine whether or not strict checking was requested */
3380 len = os_strlcpy(field, _field, sizeof(field));
3381 if (len >= sizeof(field))
3383 strict = os_strchr(field, ' ');
3384 if (strict != NULL) {
3386 if (os_strcmp(strict, "strict") != 0)
3390 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
3391 field, strict ? strict : "");
3393 if (os_strcmp(field, "eap") == 0) {
3394 return eap_get_names(buf, buflen);
3397 res = wpa_drv_get_capa(wpa_s, &capa);
3399 if (os_strcmp(field, "pairwise") == 0)
3400 return ctrl_iface_get_capability_pairwise(res, strict, &capa,
3403 if (os_strcmp(field, "group") == 0)
3404 return ctrl_iface_get_capability_group(res, strict, &capa,
3407 if (os_strcmp(field, "key_mgmt") == 0)
3408 return ctrl_iface_get_capability_key_mgmt(res, strict, &capa,
3411 if (os_strcmp(field, "proto") == 0)
3412 return ctrl_iface_get_capability_proto(res, strict, &capa,
3415 if (os_strcmp(field, "auth_alg") == 0)
3416 return ctrl_iface_get_capability_auth_alg(res, strict, &capa,
3419 if (os_strcmp(field, "modes") == 0)
3420 return ctrl_iface_get_capability_modes(res, strict, &capa,
3423 if (os_strcmp(field, "channels") == 0)
3424 return ctrl_iface_get_capability_channels(wpa_s, buf, buflen);
3426 if (os_strcmp(field, "freq") == 0)
3427 return ctrl_iface_get_capability_freq(wpa_s, buf, buflen);
3430 if (os_strcmp(field, "tdls") == 0)
3431 return ctrl_iface_get_capability_tdls(wpa_s, buf, buflen);
3432 #endif /* CONFIG_TDLS */
3434 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
3441 #ifdef CONFIG_INTERWORKING
3442 static char * anqp_add_hex(char *pos, char *end, const char *title,
3443 struct wpabuf *data)
3453 ret = os_snprintf(pos, end - pos, "%s=", title);
3454 if (ret < 0 || ret >= end - pos)
3458 d = wpabuf_head_u8(data);
3459 for (i = 0; i < wpabuf_len(data); i++) {
3460 ret = os_snprintf(pos, end - pos, "%02x", *d++);
3461 if (ret < 0 || ret >= end - pos)
3466 ret = os_snprintf(pos, end - pos, "\n");
3467 if (ret < 0 || ret >= end - pos)
3473 #endif /* CONFIG_INTERWORKING */
3476 static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
3477 unsigned long mask, char *buf, size_t buflen)
3487 if (mask & WPA_BSS_MASK_ID) {
3488 ret = os_snprintf(pos, end - pos, "id=%u\n", bss->id);
3489 if (ret < 0 || ret >= end - pos)
3494 if (mask & WPA_BSS_MASK_BSSID) {
3495 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
3496 MAC2STR(bss->bssid));
3497 if (ret < 0 || ret >= end - pos)
3502 if (mask & WPA_BSS_MASK_FREQ) {
3503 ret = os_snprintf(pos, end - pos, "freq=%d\n", bss->freq);
3504 if (ret < 0 || ret >= end - pos)
3509 if (mask & WPA_BSS_MASK_BEACON_INT) {
3510 ret = os_snprintf(pos, end - pos, "beacon_int=%d\n",
3512 if (ret < 0 || ret >= end - pos)
3517 if (mask & WPA_BSS_MASK_CAPABILITIES) {
3518 ret = os_snprintf(pos, end - pos, "capabilities=0x%04x\n",
3520 if (ret < 0 || ret >= end - pos)
3525 if (mask & WPA_BSS_MASK_QUAL) {
3526 ret = os_snprintf(pos, end - pos, "qual=%d\n", bss->qual);
3527 if (ret < 0 || ret >= end - pos)
3532 if (mask & WPA_BSS_MASK_NOISE) {
3533 ret = os_snprintf(pos, end - pos, "noise=%d\n", bss->noise);
3534 if (ret < 0 || ret >= end - pos)
3539 if (mask & WPA_BSS_MASK_LEVEL) {
3540 ret = os_snprintf(pos, end - pos, "level=%d\n", bss->level);
3541 if (ret < 0 || ret >= end - pos)
3546 if (mask & WPA_BSS_MASK_TSF) {
3547 ret = os_snprintf(pos, end - pos, "tsf=%016llu\n",
3548 (unsigned long long) bss->tsf);
3549 if (ret < 0 || ret >= end - pos)
3554 if (mask & WPA_BSS_MASK_AGE) {
3555 struct os_reltime now;
3557 os_get_reltime(&now);
3558 ret = os_snprintf(pos, end - pos, "age=%d\n",
3559 (int) (now.sec - bss->last_update.sec));
3560 if (ret < 0 || ret >= end - pos)
3565 if (mask & WPA_BSS_MASK_IE) {
3566 ret = os_snprintf(pos, end - pos, "ie=");
3567 if (ret < 0 || ret >= end - pos)
3571 ie = (const u8 *) (bss + 1);
3572 for (i = 0; i < bss->ie_len; i++) {
3573 ret = os_snprintf(pos, end - pos, "%02x", *ie++);
3574 if (ret < 0 || ret >= end - pos)
3579 ret = os_snprintf(pos, end - pos, "\n");
3580 if (ret < 0 || ret >= end - pos)
3585 if (mask & WPA_BSS_MASK_FLAGS) {
3586 ret = os_snprintf(pos, end - pos, "flags=");
3587 if (ret < 0 || ret >= end - pos)
3591 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
3593 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie,
3595 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
3597 pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2,
3599 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
3600 if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
3601 ret = os_snprintf(pos, end - pos, "[WEP]");
3602 if (ret < 0 || ret >= end - pos)
3606 if (bss_is_dmg(bss)) {
3608 ret = os_snprintf(pos, end - pos, "[DMG]");
3609 if (ret < 0 || ret >= end - pos)
3612 switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
3613 case IEEE80211_CAP_DMG_IBSS:
3616 case IEEE80211_CAP_DMG_AP:
3619 case IEEE80211_CAP_DMG_PBSS:
3626 ret = os_snprintf(pos, end - pos, "%s", s);
3627 if (ret < 0 || ret >= end - pos)
3631 if (bss->caps & IEEE80211_CAP_IBSS) {
3632 ret = os_snprintf(pos, end - pos, "[IBSS]");
3633 if (ret < 0 || ret >= end - pos)
3637 if (bss->caps & IEEE80211_CAP_ESS) {
3638 ret = os_snprintf(pos, end - pos, "[ESS]");
3639 if (ret < 0 || ret >= end - pos)
3644 if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
3645 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
3646 ret = os_snprintf(pos, end - pos, "[P2P]");
3647 if (ret < 0 || ret >= end - pos)
3652 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) {
3653 ret = os_snprintf(pos, end - pos, "[HS20]");
3654 if (ret < 0 || ret >= end - pos)
3658 #endif /* CONFIG_HS20 */
3660 ret = os_snprintf(pos, end - pos, "\n");
3661 if (ret < 0 || ret >= end - pos)
3666 if (mask & WPA_BSS_MASK_SSID) {
3667 ret = os_snprintf(pos, end - pos, "ssid=%s\n",
3668 wpa_ssid_txt(bss->ssid, bss->ssid_len));
3669 if (ret < 0 || ret >= end - pos)
3675 if (mask & WPA_BSS_MASK_WPS_SCAN) {
3676 ie = (const u8 *) (bss + 1);
3677 ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end);
3678 if (ret < 0 || ret >= end - pos)
3682 #endif /* CONFIG_WPS */
3685 if (mask & WPA_BSS_MASK_P2P_SCAN) {
3686 ie = (const u8 *) (bss + 1);
3687 ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end);
3688 if (ret < 0 || ret >= end - pos)
3692 #endif /* CONFIG_P2P */
3694 #ifdef CONFIG_WIFI_DISPLAY
3695 if (mask & WPA_BSS_MASK_WIFI_DISPLAY) {
3697 ie = (const u8 *) (bss + 1);
3698 wfd = ieee802_11_vendor_ie_concat(ie, bss->ie_len,
3699 WFD_IE_VENDOR_TYPE);
3701 ret = os_snprintf(pos, end - pos, "wfd_subelems=");
3702 if (ret < 0 || ret >= end - pos) {
3708 pos += wpa_snprintf_hex(pos, end - pos,
3713 ret = os_snprintf(pos, end - pos, "\n");
3714 if (ret < 0 || ret >= end - pos)
3719 #endif /* CONFIG_WIFI_DISPLAY */
3721 #ifdef CONFIG_INTERWORKING
3722 if ((mask & WPA_BSS_MASK_INTERNETW) && bss->anqp) {
3723 struct wpa_bss_anqp *anqp = bss->anqp;
3724 pos = anqp_add_hex(pos, end, "anqp_venue_name",
3726 pos = anqp_add_hex(pos, end, "anqp_network_auth_type",
3727 anqp->network_auth_type);
3728 pos = anqp_add_hex(pos, end, "anqp_roaming_consortium",
3729 anqp->roaming_consortium);
3730 pos = anqp_add_hex(pos, end, "anqp_ip_addr_type_availability",
3731 anqp->ip_addr_type_availability);
3732 pos = anqp_add_hex(pos, end, "anqp_nai_realm",
3734 pos = anqp_add_hex(pos, end, "anqp_3gpp", anqp->anqp_3gpp);
3735 pos = anqp_add_hex(pos, end, "anqp_domain_name",
3738 pos = anqp_add_hex(pos, end, "hs20_operator_friendly_name",
3739 anqp->hs20_operator_friendly_name);
3740 pos = anqp_add_hex(pos, end, "hs20_wan_metrics",
3741 anqp->hs20_wan_metrics);
3742 pos = anqp_add_hex(pos, end, "hs20_connection_capability",
3743 anqp->hs20_connection_capability);
3744 pos = anqp_add_hex(pos, end, "hs20_operating_class",
3745 anqp->hs20_operating_class);
3746 pos = anqp_add_hex(pos, end, "hs20_osu_providers_list",
3747 anqp->hs20_osu_providers_list);
3748 #endif /* CONFIG_HS20 */
3750 #endif /* CONFIG_INTERWORKING */
3752 if (mask & WPA_BSS_MASK_DELIM) {
3753 ret = os_snprintf(pos, end - pos, "====\n");
3754 if (ret < 0 || ret >= end - pos)
3763 static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
3764 const char *cmd, char *buf,
3769 struct wpa_bss *bss;
3770 struct wpa_bss *bsslast = NULL;
3771 struct dl_list *next;
3775 unsigned long mask = WPA_BSS_MASK_ALL;
3777 if (os_strncmp(cmd, "RANGE=", 6) == 0) {
3778 if (os_strncmp(cmd + 6, "ALL", 3) == 0) {
3779 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss,
3781 bsslast = dl_list_last(&wpa_s->bss_id, struct wpa_bss,
3783 } else { /* N1-N2 */
3784 unsigned int id1, id2;
3786 if ((ctmp = os_strchr(cmd + 6, '-')) == NULL) {
3787 wpa_printf(MSG_INFO, "Wrong BSS range "
3792 if (*(cmd + 6) == '-')
3795 id1 = atoi(cmd + 6);
3797 if (*ctmp >= '0' && *ctmp <= '9')
3800 id2 = (unsigned int) -1;
3801 bss = wpa_bss_get_id_range(wpa_s, id1, id2);
3802 if (id2 == (unsigned int) -1)
3803 bsslast = dl_list_last(&wpa_s->bss_id,
3807 bsslast = wpa_bss_get_id(wpa_s, id2);
3808 if (bsslast == NULL && bss && id2 > id1) {
3809 struct wpa_bss *tmp = bss;
3811 next = tmp->list_id.next;
3812 if (next == &wpa_s->bss_id)
3814 tmp = dl_list_entry(
3815 next, struct wpa_bss,
3824 } else if (os_strncmp(cmd, "FIRST", 5) == 0)
3825 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, list_id);
3826 else if (os_strncmp(cmd, "LAST", 4) == 0)
3827 bss = dl_list_last(&wpa_s->bss_id, struct wpa_bss, list_id);
3828 else if (os_strncmp(cmd, "ID-", 3) == 0) {
3830 bss = wpa_bss_get_id(wpa_s, i);
3831 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
3833 bss = wpa_bss_get_id(wpa_s, i);
3835 next = bss->list_id.next;
3836 if (next == &wpa_s->bss_id)
3839 bss = dl_list_entry(next, struct wpa_bss,
3843 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
3844 if (hwaddr_aton(cmd + 13, bssid) == 0)
3845 bss = wpa_bss_get_p2p_dev_addr(wpa_s, bssid);
3848 #endif /* CONFIG_P2P */
3849 } else if (hwaddr_aton(cmd, bssid) == 0)
3850 bss = wpa_bss_get_bssid(wpa_s, bssid);
3852 struct wpa_bss *tmp;
3855 dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id)
3864 if ((ctmp = os_strstr(cmd, "MASK=")) != NULL) {
3865 mask = strtoul(ctmp + 5, NULL, 0x10);
3867 mask = WPA_BSS_MASK_ALL;
3873 if (bsslast == NULL)
3876 len = print_bss_info(wpa_s, bss, mask, buf, buflen);
3880 if (bss == bsslast) {
3881 if ((mask & WPA_BSS_MASK_DELIM) && len &&
3882 (bss == dl_list_last(&wpa_s->bss_id,
3883 struct wpa_bss, list_id)))
3884 os_snprintf(buf - 5, 5, "####\n");
3887 next = bss->list_id.next;
3888 if (next == &wpa_s->bss_id)
3890 bss = dl_list_entry(next, struct wpa_bss, list_id);
3891 } while (bss && len);
3897 static int wpa_supplicant_ctrl_iface_ap_scan(
3898 struct wpa_supplicant *wpa_s, char *cmd)
3900 int ap_scan = atoi(cmd);
3901 return wpa_supplicant_set_ap_scan(wpa_s, ap_scan);
3905 static int wpa_supplicant_ctrl_iface_scan_interval(
3906 struct wpa_supplicant *wpa_s, char *cmd)
3908 int scan_int = atoi(cmd);
3909 return wpa_supplicant_set_scan_interval(wpa_s, scan_int);
3913 static int wpa_supplicant_ctrl_iface_bss_expire_age(
3914 struct wpa_supplicant *wpa_s, char *cmd)
3916 int expire_age = atoi(cmd);
3917 return wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age);
3921 static int wpa_supplicant_ctrl_iface_bss_expire_count(
3922 struct wpa_supplicant *wpa_s, char *cmd)
3924 int expire_count = atoi(cmd);
3925 return wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count);
3929 static int wpa_supplicant_ctrl_iface_bss_flush(
3930 struct wpa_supplicant *wpa_s, char *cmd)
3932 int flush_age = atoi(cmd);
3935 wpa_bss_flush(wpa_s);
3937 wpa_bss_flush_by_age(wpa_s, flush_age);
3942 #ifdef CONFIG_TESTING_OPTIONS
3943 static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s)
3945 wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication");
3946 /* MLME-DELETEKEYS.request */
3947 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL, 0);
3948 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL, 0);
3949 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL, 0);
3950 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL, 0);
3951 #ifdef CONFIG_IEEE80211W
3952 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL, 0);
3953 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL, 0);
3954 #endif /* CONFIG_IEEE80211W */
3956 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, wpa_s->bssid, 0, 0, NULL, 0, NULL,
3958 /* MLME-SETPROTECTION.request(None) */
3959 wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid,
3960 MLME_SETPROTECTION_PROTECT_TYPE_NONE,
3961 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE);
3962 wpa_sm_drop_sa(wpa_s->wpa);
3964 #endif /* CONFIG_TESTING_OPTIONS */
3967 static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s,
3970 #ifdef CONFIG_NO_SCAN_PROCESSING
3972 #else /* CONFIG_NO_SCAN_PROCESSING */
3974 struct wpa_bss *bss;
3975 struct wpa_ssid *ssid = wpa_s->current_ssid;
3977 if (hwaddr_aton(addr, bssid)) {
3978 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid "
3979 "address '%s'", addr);
3983 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR, MAC2STR(bssid));
3986 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network "
3987 "configuration known for the target AP");
3991 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
3993 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found "
3999 * TODO: Find best network configuration block from configuration to
4000 * allow roaming to other networks
4003 wpa_s->reassociate = 1;
4004 wpa_supplicant_connect(wpa_s, bss, ssid);
4007 #endif /* CONFIG_NO_SCAN_PROCESSING */
4012 static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd)
4014 unsigned int timeout = atoi(cmd);
4015 enum p2p_discovery_type type = P2P_FIND_START_WITH_FULL;
4016 u8 dev_id[ETH_ALEN], *_dev_id = NULL;
4017 u8 dev_type[WPS_DEV_TYPE_LEN], *_dev_type = NULL;
4019 unsigned int search_delay;
4021 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
4022 wpa_dbg(wpa_s, MSG_INFO,
4023 "Reject P2P_FIND since interface is disabled");
4026 if (os_strstr(cmd, "type=social"))
4027 type = P2P_FIND_ONLY_SOCIAL;
4028 else if (os_strstr(cmd, "type=progressive"))
4029 type = P2P_FIND_PROGRESSIVE;
4031 pos = os_strstr(cmd, "dev_id=");
4034 if (hwaddr_aton(pos, dev_id))
4039 pos = os_strstr(cmd, "dev_type=");
4042 if (wps_dev_type_str2bin(pos, dev_type) < 0)
4044 _dev_type = dev_type;
4047 pos = os_strstr(cmd, "delay=");
4050 search_delay = atoi(pos);
4052 search_delay = wpas_p2p_search_delay(wpa_s);
4054 return wpas_p2p_find(wpa_s, timeout, type, _dev_type != NULL, _dev_type,
4055 _dev_id, search_delay);
4059 static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd,
4060 char *buf, size_t buflen)
4065 enum p2p_wps_method wps_method;
4068 int persistent_group, persistent_id = -1;
4077 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad]
4078 * [persistent|persistent=<network id>]
4079 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
4082 if (hwaddr_aton(cmd, addr))
4090 persistent_group = os_strstr(pos, " persistent") != NULL;
4091 pos2 = os_strstr(pos, " persistent=");
4093 struct wpa_ssid *ssid;
4094 persistent_id = atoi(pos2 + 12);
4095 ssid = wpa_config_get_network(wpa_s->conf, persistent_id);
4096 if (ssid == NULL || ssid->disabled != 2 ||
4097 ssid->mode != WPAS_MODE_P2P_GO) {
4098 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
4099 "SSID id=%d for persistent P2P group (GO)",
4104 join = os_strstr(pos, " join") != NULL;
4105 auth = os_strstr(pos, " auth") != NULL;
4106 automatic = os_strstr(pos, " auto") != NULL;
4107 pd = os_strstr(pos, " provdisc") != NULL;
4108 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
4109 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
4112 pos2 = os_strstr(pos, " go_intent=");
4115 go_intent = atoi(pos2);
4116 if (go_intent < 0 || go_intent > 15)
4120 pos2 = os_strstr(pos, " freq=");
4128 if (os_strncmp(pos, "pin", 3) == 0) {
4129 /* Request random PIN (to be displayed) and enable the PIN */
4130 wps_method = WPS_PIN_DISPLAY;
4131 } else if (os_strncmp(pos, "pbc", 3) == 0) {
4132 wps_method = WPS_PBC;
4135 pos = os_strchr(pin, ' ');
4136 wps_method = WPS_PIN_KEYPAD;
4139 if (os_strncmp(pos, "display", 7) == 0)
4140 wps_method = WPS_PIN_DISPLAY;
4142 if (!wps_pin_str_valid(pin)) {
4143 os_memcpy(buf, "FAIL-INVALID-PIN\n", 17);
4148 new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method,
4149 persistent_group, automatic, join,
4150 auth, go_intent, freq, persistent_id, pd,
4152 if (new_pin == -2) {
4153 os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
4156 if (new_pin == -3) {
4157 os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
4162 if (wps_method == WPS_PIN_DISPLAY && pin == NULL) {
4163 ret = os_snprintf(buf, buflen, "%08d", new_pin);
4164 if (ret < 0 || (size_t) ret >= buflen)
4169 os_memcpy(buf, "OK\n", 3);
4174 static int p2p_ctrl_listen(struct wpa_supplicant *wpa_s, char *cmd)
4176 unsigned int timeout = atoi(cmd);
4177 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
4178 wpa_dbg(wpa_s, MSG_INFO,
4179 "Reject P2P_LISTEN since interface is disabled");
4182 return wpas_p2p_listen(wpa_s, timeout);
4186 static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd)
4190 enum wpas_p2p_prov_disc_use use = WPAS_P2P_PD_FOR_GO_NEG;
4192 /* <addr> <config method> [join|auto] */
4194 if (hwaddr_aton(cmd, addr))
4202 if (os_strstr(pos, " join") != NULL)
4203 use = WPAS_P2P_PD_FOR_JOIN;
4204 else if (os_strstr(pos, " auto") != NULL)
4205 use = WPAS_P2P_PD_AUTO;
4207 return wpas_p2p_prov_disc(wpa_s, addr, pos, use);
4211 static int p2p_get_passphrase(struct wpa_supplicant *wpa_s, char *buf,
4214 struct wpa_ssid *ssid = wpa_s->current_ssid;
4216 if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO ||
4217 ssid->passphrase == NULL)
4220 os_strlcpy(buf, ssid->passphrase, buflen);
4221 return os_strlen(buf);
4225 static int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd,
4226 char *buf, size_t buflen)
4230 u8 dst_buf[ETH_ALEN], *dst;
4231 struct wpabuf *tlvs;
4235 if (hwaddr_aton(cmd, dst_buf))
4238 if (dst[0] == 0 && dst[1] == 0 && dst[2] == 0 &&
4239 dst[3] == 0 && dst[4] == 0 && dst[5] == 0)
4246 if (os_strncmp(pos, "upnp ", 5) == 0) {
4249 if (hexstr2bin(pos, &version, 1) < 0)
4255 ref = wpas_p2p_sd_request_upnp(wpa_s, dst, version, pos);
4256 #ifdef CONFIG_WIFI_DISPLAY
4257 } else if (os_strncmp(pos, "wifi-display ", 13) == 0) {
4258 ref = wpas_p2p_sd_request_wifi_display(wpa_s, dst, pos + 13);
4259 #endif /* CONFIG_WIFI_DISPLAY */
4261 len = os_strlen(pos);
4265 tlvs = wpabuf_alloc(len);
4268 if (hexstr2bin(pos, wpabuf_put(tlvs, len), len) < 0) {
4273 ref = wpas_p2p_sd_request(wpa_s, dst, tlvs);
4278 res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref);
4279 if (res < 0 || (unsigned) res >= buflen)
4285 static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s,
4288 long long unsigned val;
4290 if (sscanf(cmd, "%llx", &val) != 1)
4293 return wpas_p2p_sd_cancel_request(wpa_s, req);
4297 static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant *wpa_s, char *cmd)
4302 struct wpabuf *resp_tlvs;
4306 pos = os_strchr(cmd, ' ');
4314 if (hwaddr_aton(pos, dst))
4321 pos2 = os_strchr(pos, ' ');
4325 dialog_token = atoi(pos);
4327 len = os_strlen(pos2);
4331 resp_tlvs = wpabuf_alloc(len);
4332 if (resp_tlvs == NULL)
4334 if (hexstr2bin(pos2, wpabuf_put(resp_tlvs, len), len) < 0) {
4335 wpabuf_free(resp_tlvs);
4339 wpas_p2p_sd_response(wpa_s, freq, dst, dialog_token, resp_tlvs);
4340 wpabuf_free(resp_tlvs);
4345 static int p2p_ctrl_serv_disc_external(struct wpa_supplicant *wpa_s,
4348 if (os_strcmp(cmd, "0") && os_strcmp(cmd, "1"))
4350 wpa_s->p2p_sd_over_ctrl_iface = atoi(cmd);
4355 static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant *wpa_s,
4360 struct wpabuf *query, *resp;
4362 pos = os_strchr(cmd, ' ');
4367 len = os_strlen(cmd);
4371 query = wpabuf_alloc(len);
4374 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
4379 len = os_strlen(pos);
4385 resp = wpabuf_alloc(len);
4390 if (hexstr2bin(pos, wpabuf_put(resp, len), len) < 0) {
4396 if (wpas_p2p_service_add_bonjour(wpa_s, query, resp) < 0) {
4405 static int p2p_ctrl_service_add_upnp(struct wpa_supplicant *wpa_s, char *cmd)
4410 pos = os_strchr(cmd, ' ');
4415 if (hexstr2bin(cmd, &version, 1) < 0)
4418 return wpas_p2p_service_add_upnp(wpa_s, version, pos);
4422 static int p2p_ctrl_service_add(struct wpa_supplicant *wpa_s, char *cmd)
4426 pos = os_strchr(cmd, ' ');
4431 if (os_strcmp(cmd, "bonjour") == 0)
4432 return p2p_ctrl_service_add_bonjour(wpa_s, pos);
4433 if (os_strcmp(cmd, "upnp") == 0)
4434 return p2p_ctrl_service_add_upnp(wpa_s, pos);
4435 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
4440 static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant *wpa_s,
4444 struct wpabuf *query;
4447 len = os_strlen(cmd);
4451 query = wpabuf_alloc(len);
4454 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
4459 ret = wpas_p2p_service_del_bonjour(wpa_s, query);
4465 static int p2p_ctrl_service_del_upnp(struct wpa_supplicant *wpa_s, char *cmd)
4470 pos = os_strchr(cmd, ' ');
4475 if (hexstr2bin(cmd, &version, 1) < 0)
4478 return wpas_p2p_service_del_upnp(wpa_s, version, pos);
4482 static int p2p_ctrl_service_del(struct wpa_supplicant *wpa_s, char *cmd)
4486 pos = os_strchr(cmd, ' ');
4491 if (os_strcmp(cmd, "bonjour") == 0)
4492 return p2p_ctrl_service_del_bonjour(wpa_s, pos);
4493 if (os_strcmp(cmd, "upnp") == 0)
4494 return p2p_ctrl_service_del_upnp(wpa_s, pos);
4495 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
4500 static int p2p_ctrl_reject(struct wpa_supplicant *wpa_s, char *cmd)
4506 if (hwaddr_aton(cmd, addr))
4509 return wpas_p2p_reject(wpa_s, addr);
4513 static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd)
4517 struct wpa_ssid *ssid;
4518 u8 *_peer = NULL, peer[ETH_ALEN];
4519 int freq = 0, pref_freq = 0;
4523 pos = os_strstr(cmd, " peer=");
4526 if (hwaddr_aton(pos, peer))
4530 ssid = wpa_config_get_network(wpa_s->conf, id);
4531 if (ssid == NULL || ssid->disabled != 2) {
4532 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
4533 "for persistent P2P group",
4538 pos = os_strstr(cmd, " freq=");
4546 pos = os_strstr(cmd, " pref=");
4549 pref_freq = atoi(pos);
4554 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
4555 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
4558 return wpas_p2p_invite(wpa_s, _peer, ssid, NULL, freq, ht40, vht,
4563 static int p2p_ctrl_invite_group(struct wpa_supplicant *wpa_s, char *cmd)
4566 u8 peer[ETH_ALEN], go_dev_addr[ETH_ALEN], *go_dev = NULL;
4568 pos = os_strstr(cmd, " peer=");
4574 if (hwaddr_aton(pos, peer)) {
4575 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", pos);
4579 pos = os_strstr(pos, " go_dev_addr=");
4582 if (hwaddr_aton(pos, go_dev_addr)) {
4583 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'",
4587 go_dev = go_dev_addr;
4590 return wpas_p2p_invite_group(wpa_s, cmd, peer, go_dev);
4594 static int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd)
4596 if (os_strncmp(cmd, "persistent=", 11) == 0)
4597 return p2p_ctrl_invite_persistent(wpa_s, cmd + 11);
4598 if (os_strncmp(cmd, "group=", 6) == 0)
4599 return p2p_ctrl_invite_group(wpa_s, cmd + 6);
4605 static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s,
4606 char *cmd, int freq, int ht40,
4610 struct wpa_ssid *ssid;
4613 ssid = wpa_config_get_network(wpa_s->conf, id);
4614 if (ssid == NULL || ssid->disabled != 2) {
4615 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
4616 "for persistent P2P group",
4621 return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq, 0, ht40, vht,
4626 static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd)
4628 int freq = 0, ht40, vht;
4631 pos = os_strstr(cmd, "freq=");
4633 freq = atoi(pos + 5);
4635 vht = (os_strstr(cmd, "vht") != NULL) || wpa_s->conf->p2p_go_vht;
4636 ht40 = (os_strstr(cmd, "ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
4639 if (os_strncmp(cmd, "persistent=", 11) == 0)
4640 return p2p_ctrl_group_add_persistent(wpa_s, cmd + 11, freq,
4642 if (os_strcmp(cmd, "persistent") == 0 ||
4643 os_strncmp(cmd, "persistent ", 11) == 0)
4644 return wpas_p2p_group_add(wpa_s, 1, freq, ht40, vht);
4645 if (os_strncmp(cmd, "freq=", 5) == 0)
4646 return wpas_p2p_group_add(wpa_s, 0, freq, ht40, vht);
4648 return wpas_p2p_group_add(wpa_s, 0, freq, ht40, vht);
4650 wpa_printf(MSG_DEBUG, "CTRL: Invalid P2P_GROUP_ADD parameters '%s'",
4656 static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd,
4657 char *buf, size_t buflen)
4659 u8 addr[ETH_ALEN], *addr_ptr;
4661 const struct p2p_peer_info *info;
4663 char devtype[WPS_DEV_TYPE_BUFSIZE];
4664 struct wpa_ssid *ssid;
4667 if (!wpa_s->global->p2p)
4670 if (os_strcmp(cmd, "FIRST") == 0) {
4673 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
4674 if (hwaddr_aton(cmd + 5, addr) < 0)
4679 if (hwaddr_aton(cmd, addr) < 0)
4685 info = p2p_get_peer_info(wpa_s->global->p2p, addr_ptr, next);
4692 res = os_snprintf(pos, end - pos, MACSTR "\n"
4698 "serial_number=%s\n"
4699 "config_methods=0x%x\n"
4701 "group_capab=0x%x\n"
4703 MAC2STR(info->p2p_device_addr),
4704 wps_dev_type_bin2str(info->pri_dev_type,
4705 devtype, sizeof(devtype)),
4710 info->serial_number,
4711 info->config_methods,
4715 if (res < 0 || res >= end - pos)
4719 for (i = 0; i < info->wps_sec_dev_type_list_len / WPS_DEV_TYPE_LEN; i++)
4722 t = &info->wps_sec_dev_type_list[i * WPS_DEV_TYPE_LEN];
4723 res = os_snprintf(pos, end - pos, "sec_dev_type=%s\n",
4724 wps_dev_type_bin2str(t, devtype,
4726 if (res < 0 || res >= end - pos)
4731 ssid = wpas_p2p_get_persistent(wpa_s, info->p2p_device_addr, NULL, 0);
4733 res = os_snprintf(pos, end - pos, "persistent=%d\n", ssid->id);
4734 if (res < 0 || res >= end - pos)
4739 res = p2p_get_peer_info_txt(info, pos, end - pos);
4744 if (info->vendor_elems) {
4745 res = os_snprintf(pos, end - pos, "vendor_elems=");
4746 if (res < 0 || res >= end - pos)
4750 pos += wpa_snprintf_hex(pos, end - pos,
4751 wpabuf_head(info->vendor_elems),
4752 wpabuf_len(info->vendor_elems));
4754 res = os_snprintf(pos, end - pos, "\n");
4755 if (res < 0 || res >= end - pos)
4764 static int p2p_ctrl_disallow_freq(struct wpa_supplicant *wpa_s,
4769 if (wpa_s->global->p2p == NULL)
4772 if (freq_range_list_parse(&wpa_s->global->p2p_disallow_freq, param) < 0)
4775 for (i = 0; i < wpa_s->global->p2p_disallow_freq.num; i++) {
4776 struct wpa_freq_range *freq;
4777 freq = &wpa_s->global->p2p_disallow_freq.range[i];
4778 wpa_printf(MSG_DEBUG, "P2P: Disallowed frequency range %u-%u",
4779 freq->min, freq->max);
4782 wpas_p2p_update_channel_list(wpa_s);
4787 static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd)
4791 if (wpa_s->global->p2p == NULL)
4794 param = os_strchr(cmd, ' ');
4799 if (os_strcmp(cmd, "discoverability") == 0) {
4800 p2p_set_client_discoverability(wpa_s->global->p2p,
4805 if (os_strcmp(cmd, "managed") == 0) {
4806 p2p_set_managed_oper(wpa_s->global->p2p, atoi(param));
4810 if (os_strcmp(cmd, "listen_channel") == 0) {
4811 return p2p_set_listen_channel(wpa_s->global->p2p, 81,
4815 if (os_strcmp(cmd, "ssid_postfix") == 0) {
4816 return p2p_set_ssid_postfix(wpa_s->global->p2p, (u8 *) param,
4820 if (os_strcmp(cmd, "noa") == 0) {
4822 int count, start, duration;
4823 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
4824 count = atoi(param);
4825 pos = os_strchr(param, ',');
4830 pos = os_strchr(pos, ',');
4834 duration = atoi(pos);
4835 if (count < 0 || count > 255 || start < 0 || duration < 0)
4837 if (count == 0 && duration > 0)
4839 wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
4840 "start=%d duration=%d", count, start, duration);
4841 return wpas_p2p_set_noa(wpa_s, count, start, duration);
4844 if (os_strcmp(cmd, "ps") == 0)
4845 return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1);
4847 if (os_strcmp(cmd, "oppps") == 0)
4848 return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1);
4850 if (os_strcmp(cmd, "ctwindow") == 0)
4851 return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param));
4853 if (os_strcmp(cmd, "disabled") == 0) {
4854 wpa_s->global->p2p_disabled = atoi(param);
4855 wpa_printf(MSG_DEBUG, "P2P functionality %s",
4856 wpa_s->global->p2p_disabled ?
4857 "disabled" : "enabled");
4858 if (wpa_s->global->p2p_disabled) {
4859 wpas_p2p_stop_find(wpa_s);
4860 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
4861 p2p_flush(wpa_s->global->p2p);
4866 if (os_strcmp(cmd, "conc_pref") == 0) {
4867 if (os_strcmp(param, "sta") == 0)
4868 wpa_s->global->conc_pref = WPA_CONC_PREF_STA;
4869 else if (os_strcmp(param, "p2p") == 0)
4870 wpa_s->global->conc_pref = WPA_CONC_PREF_P2P;
4872 wpa_printf(MSG_INFO, "Invalid conc_pref value");
4875 wpa_printf(MSG_DEBUG, "Single channel concurrency preference: "
4880 if (os_strcmp(cmd, "force_long_sd") == 0) {
4881 wpa_s->force_long_sd = atoi(param);
4885 if (os_strcmp(cmd, "peer_filter") == 0) {
4887 if (hwaddr_aton(param, addr))
4889 p2p_set_peer_filter(wpa_s->global->p2p, addr);
4893 if (os_strcmp(cmd, "cross_connect") == 0)
4894 return wpas_p2p_set_cross_connect(wpa_s, atoi(param));
4896 if (os_strcmp(cmd, "go_apsd") == 0) {
4897 if (os_strcmp(param, "disable") == 0)
4898 wpa_s->set_ap_uapsd = 0;
4900 wpa_s->set_ap_uapsd = 1;
4901 wpa_s->ap_uapsd = atoi(param);
4906 if (os_strcmp(cmd, "client_apsd") == 0) {
4907 if (os_strcmp(param, "disable") == 0)
4908 wpa_s->set_sta_uapsd = 0;
4912 /* format: BE,BK,VI,VO;max SP Length */
4914 pos = os_strchr(param, ',');
4919 pos = os_strchr(pos, ',');
4924 pos = os_strchr(pos, ',');
4929 /* ignore max SP Length for now */
4931 wpa_s->set_sta_uapsd = 1;
4932 wpa_s->sta_uapsd = 0;
4934 wpa_s->sta_uapsd |= BIT(0);
4936 wpa_s->sta_uapsd |= BIT(1);
4938 wpa_s->sta_uapsd |= BIT(2);
4940 wpa_s->sta_uapsd |= BIT(3);
4945 if (os_strcmp(cmd, "disallow_freq") == 0)
4946 return p2p_ctrl_disallow_freq(wpa_s, param);
4948 if (os_strcmp(cmd, "disc_int") == 0) {
4949 int min_disc_int, max_disc_int, max_disc_tu;
4954 min_disc_int = atoi(pos);
4955 pos = os_strchr(pos, ' ');
4960 max_disc_int = atoi(pos);
4961 pos = os_strchr(pos, ' ');
4966 max_disc_tu = atoi(pos);
4968 return p2p_set_disc_int(wpa_s->global->p2p, min_disc_int,
4969 max_disc_int, max_disc_tu);
4972 if (os_strcmp(cmd, "per_sta_psk") == 0) {
4973 wpa_s->global->p2p_per_sta_psk = !!atoi(param);
4977 #ifdef CONFIG_WPS_NFC
4978 if (os_strcmp(cmd, "nfc_tag") == 0)
4979 return wpas_p2p_nfc_tag_enabled(wpa_s, !!atoi(param));
4980 #endif /* CONFIG_WPS_NFC */
4982 if (os_strcmp(cmd, "disable_ip_addr_req") == 0) {
4983 wpa_s->p2p_disable_ip_addr_req = !!atoi(param);
4987 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
4994 static void p2p_ctrl_flush(struct wpa_supplicant *wpa_s)
4996 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
4997 wpa_s->force_long_sd = 0;
4998 if (wpa_s->global->p2p)
4999 p2p_flush(wpa_s->global->p2p);
5003 static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd)
5006 unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0;
5009 pos = os_strchr(cmd, ' ');
5015 pos2 = os_strchr(pos, ' ');
5023 pos = os_strchr(pos2, ' ');
5031 return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2);
5035 static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd)
5038 unsigned int period = 0, interval = 0;
5041 pos = os_strchr(cmd, ' ');
5046 interval = atoi(pos);
5049 return wpas_p2p_ext_listen(wpa_s, period, interval);
5053 static int p2p_ctrl_remove_client(struct wpa_supplicant *wpa_s, const char *cmd)
5060 if (os_strncmp(pos, "iface=", 6) == 0) {
5064 if (hwaddr_aton(pos, peer))
5067 wpas_p2p_remove_client(wpa_s, peer, iface_addr);
5071 #endif /* CONFIG_P2P */
5074 static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s, char *val)
5076 struct wpa_freq_range_list ranges;
5078 struct hostapd_hw_modes *mode;
5081 if (wpa_s->hw.modes == NULL)
5084 os_memset(&ranges, 0, sizeof(ranges));
5085 if (freq_range_list_parse(&ranges, val) < 0)
5088 for (i = 0; i < wpa_s->hw.num_modes; i++) {
5091 mode = &wpa_s->hw.modes[i];
5092 for (j = 0; j < mode->num_channels; j++) {
5095 if (mode->channels[j].flag & HOSTAPD_CHAN_DISABLED)
5098 freq = mode->channels[j].freq;
5099 if (!freq_range_list_includes(&ranges, freq))
5102 int_array_add_unique(&freqs, freq);
5106 os_free(ranges.range);
5111 #ifdef CONFIG_INTERWORKING
5113 static int ctrl_interworking_select(struct wpa_supplicant *wpa_s, char *param)
5121 auto_sel = os_strstr(param, "auto") != NULL;
5123 pos = os_strstr(param, "freq=");
5125 freqs = freq_range_to_channel_list(wpa_s, pos + 5);
5132 return interworking_select(wpa_s, auto_sel, freqs);
5136 static int ctrl_interworking_connect(struct wpa_supplicant *wpa_s, char *dst)
5139 struct wpa_bss *bss;
5141 if (hwaddr_aton(dst, bssid)) {
5142 wpa_printf(MSG_DEBUG, "Invalid BSSID '%s'", dst);
5146 bss = wpa_bss_get_bssid(wpa_s, bssid);
5148 wpa_printf(MSG_DEBUG, "Could not find BSS " MACSTR,
5153 return interworking_connect(wpa_s, bss);
5157 static int get_anqp(struct wpa_supplicant *wpa_s, char *dst)
5159 u8 dst_addr[ETH_ALEN];
5162 #define MAX_ANQP_INFO_ID 100
5163 u16 id[MAX_ANQP_INFO_ID];
5167 used = hwaddr_aton2(dst, dst_addr);
5171 while (num_id < MAX_ANQP_INFO_ID) {
5172 if (os_strncmp(pos, "hs20:", 5) == 0) {
5174 int num = atoi(pos + 5);
5175 if (num <= 0 || num > 31)
5177 subtypes |= BIT(num);
5178 #else /* CONFIG_HS20 */
5180 #endif /* CONFIG_HS20 */
5182 id[num_id] = atoi(pos);
5186 pos = os_strchr(pos + 1, ',');
5195 return anqp_send_req(wpa_s, dst_addr, id, num_id, subtypes);
5199 static int gas_request(struct wpa_supplicant *wpa_s, char *cmd)
5201 u8 dst_addr[ETH_ALEN];
5202 struct wpabuf *advproto, *query = NULL;
5207 used = hwaddr_aton2(cmd, dst_addr);
5215 /* Advertisement Protocol ID */
5216 end = os_strchr(pos, ' ');
5220 len = os_strlen(pos);
5226 advproto = wpabuf_alloc(len);
5227 if (advproto == NULL)
5229 if (hexstr2bin(pos, wpabuf_put(advproto, len), len) < 0)
5233 /* Optional Query Request */
5238 len = os_strlen(pos);
5245 query = wpabuf_alloc(len);
5248 if (hexstr2bin(pos, wpabuf_put(query, len), len) < 0)
5253 ret = gas_send_request(wpa_s, dst_addr, advproto, query);
5256 wpabuf_free(advproto);
5263 static int gas_response_get(struct wpa_supplicant *wpa_s, char *cmd, char *buf,
5270 size_t resp_len, start, requested_len;
5271 struct wpabuf *resp;
5274 used = hwaddr_aton2(cmd, addr);
5281 dialog_token = atoi(pos);
5283 if (wpa_s->last_gas_resp &&
5284 os_memcmp(addr, wpa_s->last_gas_addr, ETH_ALEN) == 0 &&
5285 dialog_token == wpa_s->last_gas_dialog_token)
5286 resp = wpa_s->last_gas_resp;
5287 else if (wpa_s->prev_gas_resp &&
5288 os_memcmp(addr, wpa_s->prev_gas_addr, ETH_ALEN) == 0 &&
5289 dialog_token == wpa_s->prev_gas_dialog_token)
5290 resp = wpa_s->prev_gas_resp;
5294 resp_len = wpabuf_len(resp);
5296 requested_len = resp_len;
5298 pos = os_strchr(pos, ' ');
5301 if (start > resp_len)
5302 return os_snprintf(buf, buflen, "FAIL-Invalid range");
5303 pos = os_strchr(pos, ',');
5307 requested_len = atoi(pos);
5308 if (start + requested_len > resp_len)
5309 return os_snprintf(buf, buflen, "FAIL-Invalid range");
5312 if (requested_len * 2 + 1 > buflen)
5313 return os_snprintf(buf, buflen, "FAIL-Too long response");
5315 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(resp) + start,
5318 if (start + requested_len == resp_len) {
5320 * Free memory by dropping the response after it has been
5323 if (resp == wpa_s->prev_gas_resp) {
5324 wpabuf_free(wpa_s->prev_gas_resp);
5325 wpa_s->prev_gas_resp = NULL;
5327 wpabuf_free(wpa_s->last_gas_resp);
5328 wpa_s->last_gas_resp = NULL;
5334 #endif /* CONFIG_INTERWORKING */
5339 static int get_hs20_anqp(struct wpa_supplicant *wpa_s, char *dst)
5341 u8 dst_addr[ETH_ALEN];
5346 used = hwaddr_aton2(dst, dst_addr);
5351 int num = atoi(pos);
5352 if (num <= 0 || num > 31)
5354 subtypes |= BIT(num);
5355 pos = os_strchr(pos + 1, ',');
5364 return hs20_anqp_send_req(wpa_s, dst_addr, subtypes, NULL, 0);
5368 static int hs20_nai_home_realm_list(struct wpa_supplicant *wpa_s,
5369 const u8 *addr, const char *realm)
5375 rlen = os_strlen(realm);
5377 buf = os_malloc(len);
5380 buf[0] = 1; /* NAI Home Realm Count */
5381 buf[1] = 0; /* Formatted in accordance with RFC 4282 */
5383 os_memcpy(buf + 3, realm, rlen);
5385 ret = hs20_anqp_send_req(wpa_s, addr,
5386 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
5395 static int hs20_get_nai_home_realm_list(struct wpa_supplicant *wpa_s,
5398 struct wpa_cred *cred = wpa_s->conf->cred;
5399 u8 dst_addr[ETH_ALEN];
5405 used = hwaddr_aton2(dst, dst_addr);
5409 while (dst[used] == ' ')
5411 if (os_strncmp(dst + used, "realm=", 6) == 0)
5412 return hs20_nai_home_realm_list(wpa_s, dst_addr,
5415 len = os_strlen(dst + used);
5417 if (len == 0 && cred && cred->realm)
5418 return hs20_nai_home_realm_list(wpa_s, dst_addr, cred->realm);
5423 buf = os_malloc(len);
5426 if (hexstr2bin(dst + used, buf, len) < 0) {
5431 ret = hs20_anqp_send_req(wpa_s, dst_addr,
5432 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
5440 static int hs20_icon_request(struct wpa_supplicant *wpa_s, char *cmd)
5442 u8 dst_addr[ETH_ALEN];
5446 used = hwaddr_aton2(cmd, dst_addr);
5450 while (cmd[used] == ' ')
5454 wpa_s->fetch_osu_icon_in_progress = 0;
5455 return hs20_anqp_send_req(wpa_s, dst_addr, BIT(HS20_STYPE_ICON_REQUEST),
5456 (u8 *) icon, os_strlen(icon));
5459 #endif /* CONFIG_HS20 */
5462 static int wpa_supplicant_ctrl_iface_sta_autoconnect(
5463 struct wpa_supplicant *wpa_s, char *cmd)
5465 wpa_s->auto_reconnect_disabled = atoi(cmd) == 0 ? 1 : 0;
5470 #ifdef CONFIG_AUTOSCAN
5472 static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant *wpa_s,
5475 enum wpa_states state = wpa_s->wpa_state;
5476 char *new_params = NULL;
5478 if (os_strlen(cmd) > 0) {
5479 new_params = os_strdup(cmd);
5480 if (new_params == NULL)
5484 os_free(wpa_s->conf->autoscan);
5485 wpa_s->conf->autoscan = new_params;
5487 if (wpa_s->conf->autoscan == NULL)
5488 autoscan_deinit(wpa_s);
5489 else if (state == WPA_DISCONNECTED || state == WPA_INACTIVE)
5490 autoscan_init(wpa_s, 1);
5491 else if (state == WPA_SCANNING)
5492 wpa_supplicant_reinit_autoscan(wpa_s);
5497 #endif /* CONFIG_AUTOSCAN */
5502 static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant *wpa_s, char *cmd)
5508 struct wpabuf *tfs_req = NULL;
5510 if (os_strncmp(cmd, "enter", 5) == 0)
5512 else if (os_strncmp(cmd, "exit", 4) == 0)
5517 pos = os_strstr(cmd, " interval=");
5519 intval = atoi(pos + 10);
5521 pos = os_strstr(cmd, " tfs_req=");
5526 end = os_strchr(pos, ' ');
5530 len = os_strlen(pos);
5534 tfs_req = wpabuf_alloc(len);
5535 if (tfs_req == NULL)
5537 if (hexstr2bin(pos, wpabuf_put(tfs_req, len), len) < 0) {
5538 wpabuf_free(tfs_req);
5543 ret = ieee802_11_send_wnmsleep_req(wpa_s, enter ? WNM_SLEEP_MODE_ENTER :
5544 WNM_SLEEP_MODE_EXIT, intval,
5546 wpabuf_free(tfs_req);
5552 static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant *wpa_s, char *cmd)
5556 query_reason = atoi(cmd);
5558 wpa_printf(MSG_DEBUG, "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d",
5561 return wnm_send_bss_transition_mgmt_query(wpa_s, query_reason);
5564 #endif /* CONFIG_WNM */
5567 static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf,
5570 struct wpa_signal_info si;
5574 ret = wpa_drv_signal_poll(wpa_s, &si);
5581 ret = os_snprintf(pos, end - pos, "RSSI=%d\nLINKSPEED=%d\n"
5582 "NOISE=%d\nFREQUENCY=%u\n",
5583 si.current_signal, si.current_txrate / 1000,
5584 si.current_noise, si.frequency);
5585 if (ret < 0 || ret > end - pos)
5589 if (si.chanwidth != CHAN_WIDTH_UNKNOWN) {
5590 ret = os_snprintf(pos, end - pos, "WIDTH=%s\n",
5591 channel_width_to_string(si.chanwidth));
5592 if (ret < 0 || ret > end - pos)
5597 if (si.center_frq1 > 0 && si.center_frq2 > 0) {
5598 ret = os_snprintf(pos, end - pos,
5599 "CENTER_FRQ1=%d\nCENTER_FRQ2=%d\n",
5600 si.center_frq1, si.center_frq2);
5601 if (ret < 0 || ret > end - pos)
5606 if (si.avg_signal) {
5607 ret = os_snprintf(pos, end - pos,
5608 "AVG_RSSI=%d\n", si.avg_signal);
5609 if (ret < 0 || ret >= end - pos)
5618 static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant *wpa_s, char *buf,
5621 struct hostap_sta_driver_data sta;
5624 ret = wpa_drv_pktcnt_poll(wpa_s, &sta);
5628 ret = os_snprintf(buf, buflen, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
5629 sta.tx_packets, sta.tx_retry_failed, sta.rx_packets);
5630 if (ret < 0 || (size_t) ret > buflen)
5637 static int wpa_supplicant_driver_cmd(struct wpa_supplicant *wpa_s, char *cmd,
5638 char *buf, size_t buflen)
5642 ret = wpa_drv_driver_cmd(wpa_s, cmd, buf, buflen);
5644 if (os_strncasecmp(cmd, "COUNTRY", 7) == 0) {
5645 struct p2p_data *p2p = wpa_s->global->p2p;
5648 country[0] = cmd[8];
5649 country[1] = cmd[9];
5651 p2p_set_country(p2p, country);
5654 ret = os_snprintf(buf, buflen, "%s\n", "OK");
5658 #endif /* ANDROID */
5661 static int wpa_supplicant_vendor_cmd(struct wpa_supplicant *wpa_s, char *cmd,
5662 char *buf, size_t buflen)
5667 unsigned int vendor_id, subcmd;
5668 struct wpabuf *reply;
5669 size_t data_len = 0;
5671 /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */
5672 vendor_id = strtoul(cmd, &pos, 16);
5676 subcmd = strtoul(pos, &pos, 10);
5679 if (!isblank(*pos++))
5681 data_len = os_strlen(pos);
5686 data = os_malloc(data_len);
5690 if (hexstr2bin(pos, data, data_len)) {
5691 wpa_printf(MSG_DEBUG,
5692 "Vendor command: wrong parameter format");
5698 reply = wpabuf_alloc((buflen - 1) / 2);
5704 ret = wpa_drv_vendor_cmd(wpa_s, vendor_id, subcmd, data, data_len,
5708 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(reply),
5718 static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s)
5720 wpa_dbg(wpa_s, MSG_DEBUG, "Flush all wpa_supplicant state");
5723 wpas_p2p_cancel(wpa_s);
5724 wpas_p2p_stop_find(wpa_s);
5725 p2p_ctrl_flush(wpa_s);
5726 wpas_p2p_group_remove(wpa_s, "*");
5727 wpas_p2p_service_flush(wpa_s);
5728 wpa_s->global->p2p_disabled = 0;
5729 wpa_s->global->p2p_per_sta_psk = 0;
5730 wpa_s->conf->num_sec_device_types = 0;
5731 wpa_s->p2p_disable_ip_addr_req = 0;
5732 os_free(wpa_s->global->p2p_go_avoid_freq.range);
5733 wpa_s->global->p2p_go_avoid_freq.range = NULL;
5734 #endif /* CONFIG_P2P */
5736 #ifdef CONFIG_WPS_TESTING
5737 wps_version_number = 0x20;
5738 wps_testing_dummy_cred = 0;
5739 wps_corrupt_pkhash = 0;
5740 #endif /* CONFIG_WPS_TESTING */
5742 wpa_s->wps_fragment_size = 0;
5743 wpas_wps_cancel(wpa_s);
5744 #endif /* CONFIG_WPS */
5745 wpa_s->after_wps = 0;
5746 wpa_s->known_wps_freq = 0;
5749 #ifdef CONFIG_TDLS_TESTING
5750 extern unsigned int tdls_testing;
5752 #endif /* CONFIG_TDLS_TESTING */
5753 wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL);
5754 wpa_tdls_enable(wpa_s->wpa, 1);
5755 #endif /* CONFIG_TDLS */
5757 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, wpa_s, NULL);
5758 wpa_supplicant_stop_countermeasures(wpa_s, NULL);
5760 wpa_s->no_keep_alive = 0;
5762 os_free(wpa_s->disallow_aps_bssid);
5763 wpa_s->disallow_aps_bssid = NULL;
5764 wpa_s->disallow_aps_bssid_count = 0;
5765 os_free(wpa_s->disallow_aps_ssid);
5766 wpa_s->disallow_aps_ssid = NULL;
5767 wpa_s->disallow_aps_ssid_count = 0;
5769 wpa_s->set_sta_uapsd = 0;
5770 wpa_s->sta_uapsd = 0;
5772 wpa_drv_radio_disable(wpa_s, 0);
5774 wpa_bss_flush(wpa_s);
5775 wpa_blacklist_clear(wpa_s);
5776 wpa_s->extra_blacklist_count = 0;
5777 wpa_supplicant_ctrl_iface_remove_network(wpa_s, "all");
5778 wpa_supplicant_ctrl_iface_remove_cred(wpa_s, "all");
5779 wpa_config_flush_blobs(wpa_s->conf);
5780 wpa_s->conf->auto_interworking = 0;
5781 wpa_s->conf->okc = 0;
5783 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, 43200);
5784 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, 70);
5785 wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, 60);
5786 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
5788 radio_remove_works(wpa_s, NULL, 1);
5790 wpa_s->next_ssid = NULL;
5792 #ifdef CONFIG_INTERWORKING
5793 hs20_cancel_fetch_osu(wpa_s);
5794 #endif /* CONFIG_INTERWORKING */
5796 wpa_s->ext_mgmt_frame_handling = 0;
5800 static int wpas_ctrl_radio_work_show(struct wpa_supplicant *wpa_s,
5801 char *buf, size_t buflen)
5803 struct wpa_radio_work *work;
5805 struct os_reltime now, diff;
5810 os_get_reltime(&now);
5812 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
5816 os_reltime_sub(&now, &work->time, &diff);
5817 ret = os_snprintf(pos, end - pos, "%s@%s:%u:%u:%ld.%06ld\n",
5818 work->type, work->wpa_s->ifname, work->freq,
5819 work->started, diff.sec, diff.usec);
5820 if (ret < 0 || ret >= end - pos)
5829 static void wpas_ctrl_radio_work_timeout(void *eloop_ctx, void *timeout_ctx)
5831 struct wpa_radio_work *work = eloop_ctx;
5832 struct wpa_external_work *ework = work->ctx;
5834 wpa_dbg(work->wpa_s, MSG_DEBUG,
5835 "Timing out external radio work %u (%s)",
5836 ework->id, work->type);
5837 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_TIMEOUT "%u", ework->id);
5838 radio_work_done(work);
5843 static void wpas_ctrl_radio_work_cb(struct wpa_radio_work *work, int deinit)
5845 struct wpa_external_work *ework = work->ctx;
5849 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
5856 wpa_dbg(work->wpa_s, MSG_DEBUG, "Starting external radio work %u (%s)",
5857 ework->id, ework->type);
5858 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_START "%u", ework->id);
5859 if (!ework->timeout)
5860 ework->timeout = 10;
5861 eloop_register_timeout(ework->timeout, 0, wpas_ctrl_radio_work_timeout,
5866 static int wpas_ctrl_radio_work_add(struct wpa_supplicant *wpa_s, char *cmd,
5867 char *buf, size_t buflen)
5869 struct wpa_external_work *ework;
5873 unsigned int freq = 0;
5875 /* format: <name> [freq=<MHz>] [timeout=<seconds>] */
5877 ework = os_zalloc(sizeof(*ework));
5881 pos = os_strchr(cmd, ' ');
5883 type_len = pos - cmd;
5886 pos2 = os_strstr(pos, "freq=");
5888 freq = atoi(pos2 + 5);
5890 pos2 = os_strstr(pos, "timeout=");
5892 ework->timeout = atoi(pos2 + 8);
5894 type_len = os_strlen(cmd);
5896 if (4 + type_len >= sizeof(ework->type))
5897 type_len = sizeof(ework->type) - 4 - 1;
5898 os_strlcpy(ework->type, "ext:", sizeof(ework->type));
5899 os_memcpy(ework->type + 4, cmd, type_len);
5900 ework->type[4 + type_len] = '\0';
5902 wpa_s->ext_work_id++;
5903 if (wpa_s->ext_work_id == 0)
5904 wpa_s->ext_work_id++;
5905 ework->id = wpa_s->ext_work_id;
5907 if (radio_add_work(wpa_s, freq, ework->type, 0, wpas_ctrl_radio_work_cb,
5913 ret = os_snprintf(buf, buflen, "%u", ework->id);
5914 if (ret < 0 || (size_t) ret >= buflen)
5920 static int wpas_ctrl_radio_work_done(struct wpa_supplicant *wpa_s, char *cmd)
5922 struct wpa_radio_work *work;
5923 unsigned int id = atoi(cmd);
5925 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
5927 struct wpa_external_work *ework;
5929 if (os_strncmp(work->type, "ext:", 4) != 0)
5932 if (id && ework->id != id)
5934 wpa_dbg(wpa_s, MSG_DEBUG,
5935 "Completed external radio work %u (%s)",
5936 ework->id, ework->type);
5937 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, work, NULL);
5938 radio_work_done(work);
5940 return 3; /* "OK\n" */
5947 static int wpas_ctrl_radio_work(struct wpa_supplicant *wpa_s, char *cmd,
5948 char *buf, size_t buflen)
5950 if (os_strcmp(cmd, "show") == 0)
5951 return wpas_ctrl_radio_work_show(wpa_s, buf, buflen);
5952 if (os_strncmp(cmd, "add ", 4) == 0)
5953 return wpas_ctrl_radio_work_add(wpa_s, cmd + 4, buf, buflen);
5954 if (os_strncmp(cmd, "done ", 5) == 0)
5955 return wpas_ctrl_radio_work_done(wpa_s, cmd + 4);
5960 void wpas_ctrl_radio_work_flush(struct wpa_supplicant *wpa_s)
5962 struct wpa_radio_work *work, *tmp;
5964 if (!wpa_s || !wpa_s->radio)
5967 dl_list_for_each_safe(work, tmp, &wpa_s->radio->work,
5968 struct wpa_radio_work, list) {
5969 struct wpa_external_work *ework;
5971 if (os_strncmp(work->type, "ext:", 4) != 0)
5974 wpa_dbg(wpa_s, MSG_DEBUG,
5975 "Flushing%s external radio work %u (%s)",
5976 work->started ? " started" : "", ework->id,
5979 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
5981 radio_work_done(work);
5987 static void wpas_ctrl_eapol_response(void *eloop_ctx, void *timeout_ctx)
5989 struct wpa_supplicant *wpa_s = eloop_ctx;
5990 eapol_sm_notify_ctrl_response(wpa_s->eapol);
5994 static int set_scan_freqs(struct wpa_supplicant *wpa_s, char *val)
5998 freqs = freq_range_to_channel_list(wpa_s, val);
6002 os_free(wpa_s->manual_scan_freqs);
6003 wpa_s->manual_scan_freqs = freqs;
6009 static int scan_id_list_parse(struct wpa_supplicant *wpa_s, const char *value)
6011 const char *pos = value;
6014 if (*pos == ' ' || *pos == '\0')
6016 if (wpa_s->scan_id_count == MAX_SCAN_ID)
6018 wpa_s->scan_id[wpa_s->scan_id_count++] = atoi(pos);
6019 pos = os_strchr(pos, ',');
6028 static void wpas_ctrl_scan(struct wpa_supplicant *wpa_s, char *params,
6029 char *reply, int reply_size, int *reply_len)
6033 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
6038 wpa_s->manual_scan_passive = 0;
6039 wpa_s->manual_scan_use_id = 0;
6040 wpa_s->manual_scan_only_new = 0;
6041 wpa_s->scan_id_count = 0;
6044 if (os_strncasecmp(params, "TYPE=ONLY", 9) == 0)
6045 wpa_s->scan_res_handler = scan_only_handler;
6047 pos = os_strstr(params, "freq=");
6048 if (pos && set_scan_freqs(wpa_s, pos + 5) < 0) {
6053 pos = os_strstr(params, "passive=");
6055 wpa_s->manual_scan_passive = !!atoi(pos + 8);
6057 pos = os_strstr(params, "use_id=");
6059 wpa_s->manual_scan_use_id = atoi(pos + 7);
6061 pos = os_strstr(params, "only_new=1");
6063 wpa_s->manual_scan_only_new = 1;
6065 pos = os_strstr(params, "scan_id=");
6066 if (pos && scan_id_list_parse(wpa_s, pos + 8) < 0) {
6071 os_free(wpa_s->manual_scan_freqs);
6072 wpa_s->manual_scan_freqs = NULL;
6073 if (wpa_s->scan_res_handler == scan_only_handler)
6074 wpa_s->scan_res_handler = NULL;
6077 if (!wpa_s->sched_scanning && !wpa_s->scanning &&
6078 ((wpa_s->wpa_state <= WPA_SCANNING) ||
6079 (wpa_s->wpa_state == WPA_COMPLETED))) {
6080 wpa_s->normal_scans = 0;
6081 wpa_s->scan_req = MANUAL_SCAN_REQ;
6082 wpa_s->after_wps = 0;
6083 wpa_s->known_wps_freq = 0;
6084 wpa_supplicant_req_scan(wpa_s, 0, 0);
6085 if (wpa_s->manual_scan_use_id) {
6086 wpa_s->manual_scan_id++;
6087 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
6088 wpa_s->manual_scan_id);
6089 *reply_len = os_snprintf(reply, reply_size, "%u\n",
6090 wpa_s->manual_scan_id);
6092 } else if (wpa_s->sched_scanning) {
6093 wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to allow requested full scan to proceed");
6094 wpa_supplicant_cancel_sched_scan(wpa_s);
6095 wpa_s->scan_req = MANUAL_SCAN_REQ;
6096 wpa_supplicant_req_scan(wpa_s, 0, 0);
6097 if (wpa_s->manual_scan_use_id) {
6098 wpa_s->manual_scan_id++;
6099 *reply_len = os_snprintf(reply, reply_size, "%u\n",
6100 wpa_s->manual_scan_id);
6101 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
6102 wpa_s->manual_scan_id);
6105 wpa_printf(MSG_DEBUG, "Ongoing scan action - reject new request");
6106 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
6111 #ifdef CONFIG_TESTING_OPTIONS
6113 static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant *wpa_s,
6114 unsigned int freq, const u8 *dst,
6115 const u8 *src, const u8 *bssid,
6116 const u8 *data, size_t data_len,
6117 enum offchannel_send_action_result
6120 wpa_msg(wpa_s, MSG_INFO, "MGMT-TX-STATUS freq=%u dst=" MACSTR
6121 " src=" MACSTR " bssid=" MACSTR " result=%s",
6122 freq, MAC2STR(dst), MAC2STR(src), MAC2STR(bssid),
6123 result == OFFCHANNEL_SEND_ACTION_SUCCESS ?
6124 "SUCCESS" : (result == OFFCHANNEL_SEND_ACTION_NO_ACK ?
6125 "NO_ACK" : "FAILED"));
6129 static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant *wpa_s, char *cmd)
6133 u8 *buf, da[ETH_ALEN], bssid[ETH_ALEN];
6135 int freq = 0, no_cck = 0, wait_time = 0;
6137 /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1]
6138 * <action=Action frame payload> */
6140 wpa_printf(MSG_DEBUG, "External MGMT TX: %s", cmd);
6143 used = hwaddr_aton2(pos, da);
6149 used = hwaddr_aton2(pos, bssid);
6154 param = os_strstr(pos, " freq=");
6160 param = os_strstr(pos, " no_cck=");
6163 no_cck = atoi(param);
6166 param = os_strstr(pos, " wait_time=");
6169 wait_time = atoi(param);
6172 param = os_strstr(pos, " action=");
6177 len = os_strlen(param);
6182 buf = os_malloc(len);
6186 if (hexstr2bin(param, buf, len) < 0) {
6191 res = offchannel_send_action(wpa_s, freq, da, wpa_s->own_addr, bssid,
6192 buf, len, wait_time,
6193 wpas_ctrl_iface_mgmt_tx_cb, no_cck);
6199 static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant *wpa_s)
6201 wpa_printf(MSG_DEBUG, "External MGMT TX - done waiting");
6202 offchannel_send_action_done(wpa_s);
6206 static int wpas_ctrl_iface_driver_event(struct wpa_supplicant *wpa_s, char *cmd)
6209 union wpa_event_data event;
6210 enum wpa_event_type ev;
6212 /* <event name> [parameters..] */
6214 wpa_dbg(wpa_s, MSG_DEBUG, "Testing - external driver event: %s", cmd);
6217 param = os_strchr(pos, ' ');
6221 os_memset(&event, 0, sizeof(event));
6223 if (os_strcmp(cmd, "INTERFACE_ENABLED") == 0) {
6224 ev = EVENT_INTERFACE_ENABLED;
6225 } else if (os_strcmp(cmd, "INTERFACE_DISABLED") == 0) {
6226 ev = EVENT_INTERFACE_DISABLED;
6227 } else if (os_strcmp(cmd, "AVOID_FREQUENCIES") == 0) {
6228 ev = EVENT_AVOID_FREQUENCIES;
6231 if (freq_range_list_parse(&event.freq_range, param) < 0)
6233 wpa_supplicant_event(wpa_s, ev, &event);
6234 os_free(event.freq_range.range);
6237 wpa_dbg(wpa_s, MSG_DEBUG, "Testing - unknown driver event: %s",
6242 wpa_supplicant_event(wpa_s, ev, &event);
6247 #endif /* CONFIG_TESTING_OPTIONS */
6250 static void wpas_ctrl_vendor_elem_update(struct wpa_supplicant *wpa_s)
6255 wpa_printf(MSG_DEBUG, "Update vendor elements");
6257 for (i = 0; i < NUM_VENDOR_ELEM_FRAMES; i++) {
6258 if (wpa_s->vendor_elem[i]) {
6259 os_snprintf(buf, sizeof(buf), "frame[%u]", i);
6260 wpa_hexdump_buf(MSG_DEBUG, buf, wpa_s->vendor_elem[i]);
6265 if (wpa_s->parent == wpa_s &&
6266 wpa_s->global->p2p &&
6267 !wpa_s->global->p2p_disabled)
6268 p2p_set_vendor_elems(wpa_s->global->p2p, wpa_s->vendor_elem);
6269 #endif /* CONFIG_P2P */
6273 static struct wpa_supplicant *
6274 wpas_ctrl_vendor_elem_iface(struct wpa_supplicant *wpa_s,
6275 enum wpa_vendor_elem_frame frame)
6279 case VENDOR_ELEM_PROBE_REQ_P2P:
6280 case VENDOR_ELEM_PROBE_RESP_P2P:
6281 case VENDOR_ELEM_PROBE_RESP_P2P_GO:
6282 case VENDOR_ELEM_BEACON_P2P_GO:
6283 case VENDOR_ELEM_P2P_PD_REQ:
6284 case VENDOR_ELEM_P2P_PD_RESP:
6285 case VENDOR_ELEM_P2P_GO_NEG_REQ:
6286 case VENDOR_ELEM_P2P_GO_NEG_RESP:
6287 case VENDOR_ELEM_P2P_GO_NEG_CONF:
6288 case VENDOR_ELEM_P2P_INV_REQ:
6289 case VENDOR_ELEM_P2P_INV_RESP:
6290 case VENDOR_ELEM_P2P_ASSOC_REQ:
6291 return wpa_s->parent;
6292 #endif /* CONFIG_P2P */
6299 static int wpas_ctrl_vendor_elem_add(struct wpa_supplicant *wpa_s, char *cmd)
6305 struct ieee802_11_elems elems;
6308 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
6310 wpa_s = wpas_ctrl_vendor_elem_iface(wpa_s, frame);
6312 pos = os_strchr(pos, ' ');
6317 len = os_strlen(pos);
6324 buf = wpabuf_alloc(len);
6328 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
6333 if (ieee802_11_parse_elems(wpabuf_head_u8(buf), len, &elems, 0) ==
6339 if (wpa_s->vendor_elem[frame] == NULL) {
6340 wpa_s->vendor_elem[frame] = buf;
6341 wpas_ctrl_vendor_elem_update(wpa_s);
6345 if (wpabuf_resize(&wpa_s->vendor_elem[frame], len) < 0) {
6350 wpabuf_put_buf(wpa_s->vendor_elem[frame], buf);
6352 wpas_ctrl_vendor_elem_update(wpa_s);
6358 static int wpas_ctrl_vendor_elem_get(struct wpa_supplicant *wpa_s, char *cmd,
6359 char *buf, size_t buflen)
6361 int frame = atoi(cmd);
6363 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
6365 wpa_s = wpas_ctrl_vendor_elem_iface(wpa_s, frame);
6367 if (wpa_s->vendor_elem[frame] == NULL)
6370 return wpa_snprintf_hex(buf, buflen,
6371 wpabuf_head_u8(wpa_s->vendor_elem[frame]),
6372 wpabuf_len(wpa_s->vendor_elem[frame]));
6376 static int wpas_ctrl_vendor_elem_remove(struct wpa_supplicant *wpa_s, char *cmd)
6382 struct ieee802_11_elems elems;
6386 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
6388 wpa_s = wpas_ctrl_vendor_elem_iface(wpa_s, frame);
6390 pos = os_strchr(pos, ' ');
6396 wpabuf_free(wpa_s->vendor_elem[frame]);
6397 wpa_s->vendor_elem[frame] = NULL;
6398 wpas_ctrl_vendor_elem_update(wpa_s);
6402 if (wpa_s->vendor_elem[frame] == NULL)
6405 len = os_strlen(pos);
6412 buf = os_malloc(len);
6416 if (hexstr2bin(pos, buf, len) < 0) {
6421 if (ieee802_11_parse_elems(buf, len, &elems, 0) == ParseFailed) {
6426 ie = wpabuf_mhead_u8(wpa_s->vendor_elem[frame]);
6427 end = ie + wpabuf_len(wpa_s->vendor_elem[frame]);
6429 for (; ie + 1 < end; ie += 2 + ie[1]) {
6432 if (os_memcmp(ie, buf, len) != 0)
6435 if (wpabuf_len(wpa_s->vendor_elem[frame]) == len) {
6436 wpabuf_free(wpa_s->vendor_elem[frame]);
6437 wpa_s->vendor_elem[frame] = NULL;
6439 os_memmove(ie, ie + len,
6440 wpabuf_len(wpa_s->vendor_elem[frame]) - len);
6441 wpa_s->vendor_elem[frame]->used -= len;
6444 wpas_ctrl_vendor_elem_update(wpa_s);
6454 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
6455 char *buf, size_t *resp_len)
6458 const int reply_size = 4096;
6461 if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 ||
6462 os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
6463 if (wpa_debug_show_keys)
6464 wpa_dbg(wpa_s, MSG_DEBUG,
6465 "Control interface command '%s'", buf);
6467 wpa_dbg(wpa_s, MSG_DEBUG,
6468 "Control interface command '%s [REMOVED]'",
6469 os_strncmp(buf, WPA_CTRL_RSP,
6470 os_strlen(WPA_CTRL_RSP)) == 0 ?
6471 WPA_CTRL_RSP : "SET_NETWORK");
6472 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ", 16) == 0 ||
6473 os_strncmp(buf, "NFC_REPORT_HANDOVER", 19) == 0) {
6474 wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface",
6475 (const u8 *) buf, os_strlen(buf));
6477 int level = MSG_DEBUG;
6478 if (os_strcmp(buf, "PING") == 0)
6479 level = MSG_EXCESSIVE;
6480 wpa_dbg(wpa_s, level, "Control interface command '%s'", buf);
6483 reply = os_malloc(reply_size);
6484 if (reply == NULL) {
6489 os_memcpy(reply, "OK\n", 3);
6492 if (os_strcmp(buf, "PING") == 0) {
6493 os_memcpy(reply, "PONG\n", 5);
6495 } else if (os_strcmp(buf, "IFNAME") == 0) {
6496 reply_len = os_strlen(wpa_s->ifname);
6497 os_memcpy(reply, wpa_s->ifname, reply_len);
6498 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
6499 if (wpa_debug_reopen_file() < 0)
6501 } else if (os_strncmp(buf, "NOTE ", 5) == 0) {
6502 wpa_printf(MSG_INFO, "NOTE: %s", buf + 5);
6503 } else if (os_strcmp(buf, "MIB") == 0) {
6504 reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size);
6505 if (reply_len >= 0) {
6507 res = eapol_sm_get_mib(wpa_s->eapol, reply + reply_len,
6508 reply_size - reply_len);
6514 } else if (os_strncmp(buf, "STATUS", 6) == 0) {
6515 reply_len = wpa_supplicant_ctrl_iface_status(
6516 wpa_s, buf + 6, reply, reply_size);
6517 } else if (os_strcmp(buf, "PMKSA") == 0) {
6518 reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, reply,
6520 } else if (os_strcmp(buf, "PMKSA_FLUSH") == 0) {
6521 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
6522 } else if (os_strncmp(buf, "SET ", 4) == 0) {
6523 if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4))
6525 } else if (os_strncmp(buf, "GET ", 4) == 0) {
6526 reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4,
6528 } else if (os_strcmp(buf, "LOGON") == 0) {
6529 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
6530 } else if (os_strcmp(buf, "LOGOFF") == 0) {
6531 eapol_sm_notify_logoff(wpa_s->eapol, TRUE);
6532 } else if (os_strcmp(buf, "REASSOCIATE") == 0) {
6533 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
6536 wpas_request_connection(wpa_s);
6537 } else if (os_strcmp(buf, "REATTACH") == 0) {
6538 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED ||
6539 !wpa_s->current_ssid)
6542 wpa_s->reattach = 1;
6543 wpas_request_connection(wpa_s);
6545 } else if (os_strcmp(buf, "RECONNECT") == 0) {
6546 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
6548 else if (wpa_s->disconnected)
6549 wpas_request_connection(wpa_s);
6550 #ifdef IEEE8021X_EAPOL
6551 } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) {
6552 if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8))
6554 #endif /* IEEE8021X_EAPOL */
6555 #ifdef CONFIG_PEERKEY
6556 } else if (os_strncmp(buf, "STKSTART ", 9) == 0) {
6557 if (wpa_supplicant_ctrl_iface_stkstart(wpa_s, buf + 9))
6559 #endif /* CONFIG_PEERKEY */
6560 #ifdef CONFIG_IEEE80211R
6561 } else if (os_strncmp(buf, "FT_DS ", 6) == 0) {
6562 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6))
6564 #endif /* CONFIG_IEEE80211R */
6566 } else if (os_strcmp(buf, "WPS_PBC") == 0) {
6567 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL);
6569 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
6573 } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) {
6574 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8);
6576 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
6580 } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {
6581 reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8,
6584 } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) {
6585 reply_len = wpa_supplicant_ctrl_iface_wps_check_pin(
6586 wpa_s, buf + 14, reply, reply_size);
6587 } else if (os_strcmp(buf, "WPS_CANCEL") == 0) {
6588 if (wpas_wps_cancel(wpa_s))
6590 #ifdef CONFIG_WPS_NFC
6591 } else if (os_strcmp(buf, "WPS_NFC") == 0) {
6592 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, NULL))
6594 } else if (os_strncmp(buf, "WPS_NFC ", 8) == 0) {
6595 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, buf + 8))
6597 } else if (os_strncmp(buf, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
6598 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_config_token(
6599 wpa_s, buf + 21, reply, reply_size);
6600 } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) {
6601 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_token(
6602 wpa_s, buf + 14, reply, reply_size);
6603 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) {
6604 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s,
6607 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
6608 reply_len = wpas_ctrl_nfc_get_handover_req(
6609 wpa_s, buf + 21, reply, reply_size);
6610 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
6611 reply_len = wpas_ctrl_nfc_get_handover_sel(
6612 wpa_s, buf + 21, reply, reply_size);
6613 } else if (os_strncmp(buf, "NFC_REPORT_HANDOVER ", 20) == 0) {
6614 if (wpas_ctrl_nfc_report_handover(wpa_s, buf + 20))
6616 #endif /* CONFIG_WPS_NFC */
6617 } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) {
6618 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8))
6621 } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) {
6622 reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin(
6623 wpa_s, buf + 11, reply, reply_size);
6624 #endif /* CONFIG_AP */
6625 #ifdef CONFIG_WPS_ER
6626 } else if (os_strcmp(buf, "WPS_ER_START") == 0) {
6627 if (wpas_wps_er_start(wpa_s, NULL))
6629 } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) {
6630 if (wpas_wps_er_start(wpa_s, buf + 13))
6632 } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) {
6633 if (wpas_wps_er_stop(wpa_s))
6635 } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) {
6636 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11))
6638 } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) {
6639 int ret = wpas_wps_er_pbc(wpa_s, buf + 11);
6641 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
6643 } else if (ret == -3) {
6644 os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18);
6646 } else if (ret == -4) {
6647 os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20);
6651 } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) {
6652 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13))
6654 } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) {
6655 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s,
6658 } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) {
6659 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14))
6661 #ifdef CONFIG_WPS_NFC
6662 } else if (os_strncmp(buf, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
6663 reply_len = wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
6664 wpa_s, buf + 24, reply, reply_size);
6665 #endif /* CONFIG_WPS_NFC */
6666 #endif /* CONFIG_WPS_ER */
6667 #endif /* CONFIG_WPS */
6668 #ifdef CONFIG_IBSS_RSN
6669 } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) {
6670 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9))
6672 #endif /* CONFIG_IBSS_RSN */
6674 } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) {
6675 if (p2p_ctrl_find(wpa_s, buf + 9))
6677 } else if (os_strcmp(buf, "P2P_FIND") == 0) {
6678 if (p2p_ctrl_find(wpa_s, ""))
6680 } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) {
6681 wpas_p2p_stop_find(wpa_s);
6682 } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) {
6683 reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply,
6685 } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) {
6686 if (p2p_ctrl_listen(wpa_s, buf + 11))
6688 } else if (os_strcmp(buf, "P2P_LISTEN") == 0) {
6689 if (p2p_ctrl_listen(wpa_s, ""))
6691 } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) {
6692 if (wpas_p2p_group_remove(wpa_s, buf + 17))
6694 } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) {
6695 if (wpas_p2p_group_add(wpa_s, 0, 0, 0, 0))
6697 } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) {
6698 if (p2p_ctrl_group_add(wpa_s, buf + 14))
6700 } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) {
6701 if (p2p_ctrl_prov_disc(wpa_s, buf + 14))
6703 } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) {
6704 reply_len = p2p_get_passphrase(wpa_s, reply, reply_size);
6705 } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) {
6706 reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply,
6708 } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
6709 if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0)
6711 } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) {
6712 if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0)
6714 } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) {
6715 wpas_p2p_sd_service_update(wpa_s);
6716 } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
6717 if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0)
6719 } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) {
6720 wpas_p2p_service_flush(wpa_s);
6721 } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) {
6722 if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0)
6724 } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) {
6725 if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0)
6727 } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) {
6728 if (p2p_ctrl_reject(wpa_s, buf + 11) < 0)
6730 } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) {
6731 if (p2p_ctrl_invite(wpa_s, buf + 11) < 0)
6733 } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) {
6734 reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply,
6736 } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) {
6737 if (p2p_ctrl_set(wpa_s, buf + 8) < 0)
6739 } else if (os_strcmp(buf, "P2P_FLUSH") == 0) {
6740 p2p_ctrl_flush(wpa_s);
6741 } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) {
6742 if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0)
6744 } else if (os_strcmp(buf, "P2P_CANCEL") == 0) {
6745 if (wpas_p2p_cancel(wpa_s))
6747 } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) {
6748 if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0)
6750 } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) {
6751 if (p2p_ctrl_presence_req(wpa_s, "") < 0)
6753 } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) {
6754 if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0)
6756 } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) {
6757 if (p2p_ctrl_ext_listen(wpa_s, "") < 0)
6759 } else if (os_strncmp(buf, "P2P_REMOVE_CLIENT ", 18) == 0) {
6760 if (p2p_ctrl_remove_client(wpa_s, buf + 18) < 0)
6762 #endif /* CONFIG_P2P */
6763 #ifdef CONFIG_WIFI_DISPLAY
6764 } else if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0) {
6765 if (wifi_display_subelem_set(wpa_s->global, buf + 16) < 0)
6767 } else if (os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) {
6768 reply_len = wifi_display_subelem_get(wpa_s->global, buf + 16,
6770 #endif /* CONFIG_WIFI_DISPLAY */
6771 #ifdef CONFIG_INTERWORKING
6772 } else if (os_strcmp(buf, "FETCH_ANQP") == 0) {
6773 if (interworking_fetch_anqp(wpa_s) < 0)
6775 } else if (os_strcmp(buf, "STOP_FETCH_ANQP") == 0) {
6776 interworking_stop_fetch_anqp(wpa_s);
6777 } else if (os_strcmp(buf, "INTERWORKING_SELECT") == 0) {
6778 if (ctrl_interworking_select(wpa_s, NULL) < 0)
6780 } else if (os_strncmp(buf, "INTERWORKING_SELECT ", 20) == 0) {
6781 if (ctrl_interworking_select(wpa_s, buf + 20) < 0)
6783 } else if (os_strncmp(buf, "INTERWORKING_CONNECT ", 21) == 0) {
6784 if (ctrl_interworking_connect(wpa_s, buf + 21) < 0)
6786 } else if (os_strncmp(buf, "ANQP_GET ", 9) == 0) {
6787 if (get_anqp(wpa_s, buf + 9) < 0)
6789 } else if (os_strncmp(buf, "GAS_REQUEST ", 12) == 0) {
6790 if (gas_request(wpa_s, buf + 12) < 0)
6792 } else if (os_strncmp(buf, "GAS_RESPONSE_GET ", 17) == 0) {
6793 reply_len = gas_response_get(wpa_s, buf + 17, reply,
6795 #endif /* CONFIG_INTERWORKING */
6797 } else if (os_strncmp(buf, "HS20_ANQP_GET ", 14) == 0) {
6798 if (get_hs20_anqp(wpa_s, buf + 14) < 0)
6800 } else if (os_strncmp(buf, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
6801 if (hs20_get_nai_home_realm_list(wpa_s, buf + 29) < 0)
6803 } else if (os_strncmp(buf, "HS20_ICON_REQUEST ", 18) == 0) {
6804 if (hs20_icon_request(wpa_s, buf + 18) < 0)
6806 } else if (os_strcmp(buf, "FETCH_OSU") == 0) {
6807 if (hs20_fetch_osu(wpa_s) < 0)
6809 } else if (os_strcmp(buf, "CANCEL_FETCH_OSU") == 0) {
6810 hs20_cancel_fetch_osu(wpa_s);
6811 #endif /* CONFIG_HS20 */
6812 } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0)
6814 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
6815 wpa_s, buf + os_strlen(WPA_CTRL_RSP)))
6819 * Notify response from timeout to allow the control
6820 * interface response to be sent first.
6822 eloop_register_timeout(0, 0, wpas_ctrl_eapol_response,
6825 } else if (os_strcmp(buf, "RECONFIGURE") == 0) {
6826 if (wpa_supplicant_reload_configuration(wpa_s))
6828 } else if (os_strcmp(buf, "TERMINATE") == 0) {
6829 wpa_supplicant_terminate_proc(wpa_s->global);
6830 } else if (os_strncmp(buf, "BSSID ", 6) == 0) {
6831 if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6))
6833 } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) {
6834 reply_len = wpa_supplicant_ctrl_iface_blacklist(
6835 wpa_s, buf + 9, reply, reply_size);
6836 } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) {
6837 reply_len = wpa_supplicant_ctrl_iface_log_level(
6838 wpa_s, buf + 9, reply, reply_size);
6839 } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) {
6840 reply_len = wpa_supplicant_ctrl_iface_list_networks(
6841 wpa_s, reply, reply_size);
6842 } else if (os_strcmp(buf, "DISCONNECT") == 0) {
6844 wpa_s->sme.prev_bssid_set = 0;
6845 #endif /* CONFIG_SME */
6846 wpa_s->reassociate = 0;
6847 wpa_s->disconnected = 1;
6848 wpa_supplicant_cancel_sched_scan(wpa_s);
6849 wpa_supplicant_cancel_scan(wpa_s);
6850 wpa_supplicant_deauthenticate(wpa_s,
6851 WLAN_REASON_DEAUTH_LEAVING);
6852 } else if (os_strcmp(buf, "SCAN") == 0) {
6853 wpas_ctrl_scan(wpa_s, NULL, reply, reply_size, &reply_len);
6854 } else if (os_strncmp(buf, "SCAN ", 5) == 0) {
6855 wpas_ctrl_scan(wpa_s, buf + 5, reply, reply_size, &reply_len);
6856 } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) {
6857 reply_len = wpa_supplicant_ctrl_iface_scan_results(
6858 wpa_s, reply, reply_size);
6859 } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) {
6860 if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15))
6862 } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) {
6863 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15))
6865 } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) {
6866 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16))
6868 } else if (os_strcmp(buf, "ADD_NETWORK") == 0) {
6869 reply_len = wpa_supplicant_ctrl_iface_add_network(
6870 wpa_s, reply, reply_size);
6871 } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) {
6872 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15))
6874 } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
6875 if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12))
6877 } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) {
6878 reply_len = wpa_supplicant_ctrl_iface_get_network(
6879 wpa_s, buf + 12, reply, reply_size);
6880 } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) {
6881 if (wpa_supplicant_ctrl_iface_dup_network(wpa_s, buf + 12))
6883 } else if (os_strcmp(buf, "LIST_CREDS") == 0) {
6884 reply_len = wpa_supplicant_ctrl_iface_list_creds(
6885 wpa_s, reply, reply_size);
6886 } else if (os_strcmp(buf, "ADD_CRED") == 0) {
6887 reply_len = wpa_supplicant_ctrl_iface_add_cred(
6888 wpa_s, reply, reply_size);
6889 } else if (os_strncmp(buf, "REMOVE_CRED ", 12) == 0) {
6890 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s, buf + 12))
6892 } else if (os_strncmp(buf, "SET_CRED ", 9) == 0) {
6893 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s, buf + 9))
6895 } else if (os_strncmp(buf, "GET_CRED ", 9) == 0) {
6896 reply_len = wpa_supplicant_ctrl_iface_get_cred(wpa_s, buf + 9,
6899 #ifndef CONFIG_NO_CONFIG_WRITE
6900 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
6901 if (wpa_supplicant_ctrl_iface_save_config(wpa_s))
6903 #endif /* CONFIG_NO_CONFIG_WRITE */
6904 } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
6905 reply_len = wpa_supplicant_ctrl_iface_get_capability(
6906 wpa_s, buf + 15, reply, reply_size);
6907 } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) {
6908 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8))
6910 } else if (os_strncmp(buf, "SCAN_INTERVAL ", 14) == 0) {
6911 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s, buf + 14))
6913 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
6914 reply_len = wpa_supplicant_global_iface_list(
6915 wpa_s->global, reply, reply_size);
6916 } else if (os_strcmp(buf, "INTERFACES") == 0) {
6917 reply_len = wpa_supplicant_global_iface_interfaces(
6918 wpa_s->global, reply, reply_size);
6919 } else if (os_strncmp(buf, "BSS ", 4) == 0) {
6920 reply_len = wpa_supplicant_ctrl_iface_bss(
6921 wpa_s, buf + 4, reply, reply_size);
6923 } else if (os_strcmp(buf, "STA-FIRST") == 0) {
6924 reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size);
6925 } else if (os_strncmp(buf, "STA ", 4) == 0) {
6926 reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply,
6928 } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) {
6929 reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply,
6931 } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) {
6932 if (ap_ctrl_iface_sta_deauthenticate(wpa_s, buf + 15))
6934 } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) {
6935 if (ap_ctrl_iface_sta_disassociate(wpa_s, buf + 13))
6937 } else if (os_strncmp(buf, "CHAN_SWITCH ", 12) == 0) {
6938 if (ap_ctrl_iface_chanswitch(wpa_s, buf + 12))
6940 #endif /* CONFIG_AP */
6941 } else if (os_strcmp(buf, "SUSPEND") == 0) {
6942 wpas_notify_suspend(wpa_s->global);
6943 } else if (os_strcmp(buf, "RESUME") == 0) {
6944 wpas_notify_resume(wpa_s->global);
6945 #ifdef CONFIG_TESTING_OPTIONS
6946 } else if (os_strcmp(buf, "DROP_SA") == 0) {
6947 wpa_supplicant_ctrl_iface_drop_sa(wpa_s);
6948 #endif /* CONFIG_TESTING_OPTIONS */
6949 } else if (os_strncmp(buf, "ROAM ", 5) == 0) {
6950 if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5))
6952 } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) {
6953 if (wpa_supplicant_ctrl_iface_sta_autoconnect(wpa_s, buf + 16))
6955 } else if (os_strncmp(buf, "BSS_EXPIRE_AGE ", 15) == 0) {
6956 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s, buf + 15))
6958 } else if (os_strncmp(buf, "BSS_EXPIRE_COUNT ", 17) == 0) {
6959 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s,
6962 } else if (os_strncmp(buf, "BSS_FLUSH ", 10) == 0) {
6963 if (wpa_supplicant_ctrl_iface_bss_flush(wpa_s, buf + 10))
6966 } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) {
6967 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14))
6969 } else if (os_strncmp(buf, "TDLS_SETUP ", 11) == 0) {
6970 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s, buf + 11))
6972 } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) {
6973 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14))
6975 #endif /* CONFIG_TDLS */
6976 } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) {
6977 reply_len = wpa_supplicant_signal_poll(wpa_s, reply,
6979 } else if (os_strncmp(buf, "PKTCNT_POLL", 11) == 0) {
6980 reply_len = wpa_supplicant_pktcnt_poll(wpa_s, reply,
6982 #ifdef CONFIG_AUTOSCAN
6983 } else if (os_strncmp(buf, "AUTOSCAN ", 9) == 0) {
6984 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s, buf + 9))
6986 #endif /* CONFIG_AUTOSCAN */
6988 } else if (os_strncmp(buf, "DRIVER ", 7) == 0) {
6989 reply_len = wpa_supplicant_driver_cmd(wpa_s, buf + 7, reply,
6991 #endif /* ANDROID */
6992 } else if (os_strncmp(buf, "VENDOR ", 7) == 0) {
6993 reply_len = wpa_supplicant_vendor_cmd(wpa_s, buf + 7, reply,
6995 } else if (os_strcmp(buf, "REAUTHENTICATE") == 0) {
6996 pmksa_cache_clear_current(wpa_s->wpa);
6997 eapol_sm_request_reauth(wpa_s->eapol);
6999 } else if (os_strncmp(buf, "WNM_SLEEP ", 10) == 0) {
7000 if (wpas_ctrl_iface_wnm_sleep(wpa_s, buf + 10))
7002 } else if (os_strncmp(buf, "WNM_BSS_QUERY ", 10) == 0) {
7003 if (wpas_ctrl_iface_wnm_bss_query(wpa_s, buf + 10))
7005 #endif /* CONFIG_WNM */
7006 } else if (os_strcmp(buf, "FLUSH") == 0) {
7007 wpa_supplicant_ctrl_iface_flush(wpa_s);
7008 } else if (os_strncmp(buf, "RADIO_WORK ", 11) == 0) {
7009 reply_len = wpas_ctrl_radio_work(wpa_s, buf + 11, reply,
7011 #ifdef CONFIG_TESTING_OPTIONS
7012 } else if (os_strncmp(buf, "MGMT_TX ", 8) == 0) {
7013 if (wpas_ctrl_iface_mgmt_tx(wpa_s, buf + 8) < 0)
7015 } else if (os_strcmp(buf, "MGMT_TX_DONE") == 0) {
7016 wpas_ctrl_iface_mgmt_tx_done(wpa_s);
7017 } else if (os_strncmp(buf, "DRIVER_EVENT ", 13) == 0) {
7018 if (wpas_ctrl_iface_driver_event(wpa_s, buf + 13) < 0)
7020 #endif /* CONFIG_TESTING_OPTIONS */
7021 } else if (os_strncmp(buf, "VENDOR_ELEM_ADD ", 16) == 0) {
7022 if (wpas_ctrl_vendor_elem_add(wpa_s, buf + 16) < 0)
7024 } else if (os_strncmp(buf, "VENDOR_ELEM_GET ", 16) == 0) {
7025 reply_len = wpas_ctrl_vendor_elem_get(wpa_s, buf + 16, reply,
7027 } else if (os_strncmp(buf, "VENDOR_ELEM_REMOVE ", 19) == 0) {
7028 if (wpas_ctrl_vendor_elem_remove(wpa_s, buf + 19) < 0)
7031 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
7035 if (reply_len < 0) {
7036 os_memcpy(reply, "FAIL\n", 5);
7040 *resp_len = reply_len;
7045 static int wpa_supplicant_global_iface_add(struct wpa_global *global,
7048 struct wpa_interface iface;
7052 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
7053 * TAB<bridge_ifname>
7055 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd);
7057 os_memset(&iface, 0, sizeof(iface));
7060 iface.ifname = pos = cmd;
7061 pos = os_strchr(pos, '\t');
7064 if (iface.ifname[0] == '\0')
7069 iface.confname = pos;
7070 pos = os_strchr(pos, '\t');
7073 if (iface.confname[0] == '\0')
7074 iface.confname = NULL;
7079 pos = os_strchr(pos, '\t');
7082 if (iface.driver[0] == '\0')
7083 iface.driver = NULL;
7087 iface.ctrl_interface = pos;
7088 pos = os_strchr(pos, '\t');
7091 if (iface.ctrl_interface[0] == '\0')
7092 iface.ctrl_interface = NULL;
7096 iface.driver_param = pos;
7097 pos = os_strchr(pos, '\t');
7100 if (iface.driver_param[0] == '\0')
7101 iface.driver_param = NULL;
7105 iface.bridge_ifname = pos;
7106 pos = os_strchr(pos, '\t');
7109 if (iface.bridge_ifname[0] == '\0')
7110 iface.bridge_ifname = NULL;
7115 if (wpa_supplicant_get_iface(global, iface.ifname))
7118 return wpa_supplicant_add_iface(global, &iface) ? 0 : -1;
7122 static int wpa_supplicant_global_iface_remove(struct wpa_global *global,
7125 struct wpa_supplicant *wpa_s;
7127 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd);
7129 wpa_s = wpa_supplicant_get_iface(global, cmd);
7132 return wpa_supplicant_remove_iface(global, wpa_s, 0);
7136 static void wpa_free_iface_info(struct wpa_interface_info *iface)
7138 struct wpa_interface_info *prev;
7142 iface = iface->next;
7144 os_free(prev->ifname);
7145 os_free(prev->desc);
7151 static int wpa_supplicant_global_iface_list(struct wpa_global *global,
7155 struct wpa_interface_info *iface = NULL, *last = NULL, *tmp;
7158 for (i = 0; wpa_drivers[i]; i++) {
7159 struct wpa_driver_ops *drv = wpa_drivers[i];
7160 if (drv->get_interfaces == NULL)
7162 tmp = drv->get_interfaces(global->drv_priv[i]);
7176 for (tmp = iface; tmp; tmp = tmp->next) {
7177 res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n",
7178 tmp->drv_name, tmp->ifname,
7179 tmp->desc ? tmp->desc : "");
7180 if (res < 0 || res >= end - pos) {
7187 wpa_free_iface_info(iface);
7193 static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
7198 struct wpa_supplicant *wpa_s;
7200 wpa_s = global->ifaces;
7205 res = os_snprintf(pos, end - pos, "%s\n", wpa_s->ifname);
7206 if (res < 0 || res >= end - pos) {
7211 wpa_s = wpa_s->next;
7217 static char * wpas_global_ctrl_iface_ifname(struct wpa_global *global,
7219 char *cmd, size_t *resp_len)
7221 struct wpa_supplicant *wpa_s;
7223 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
7224 if (os_strcmp(ifname, wpa_s->ifname) == 0)
7228 if (wpa_s == NULL) {
7229 char *resp = os_strdup("FAIL-NO-IFNAME-MATCH\n");
7231 *resp_len = os_strlen(resp);
7237 return wpa_supplicant_ctrl_iface_process(wpa_s, cmd, resp_len);
7241 static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global *global,
7242 char *buf, size_t *resp_len)
7245 static const char * cmd[] = {
7251 "P2P_GET_PASSPHRASE",
7252 "P2P_SERVICE_UPDATE",
7253 "P2P_SERVICE_FLUSH",
7260 static const char * prefix[] = {
7263 #endif /* ANDROID */
7269 "P2P_GROUP_REMOVE ",
7272 "P2P_SERV_DISC_REQ ",
7273 "P2P_SERV_DISC_CANCEL_REQ ",
7274 "P2P_SERV_DISC_RESP ",
7275 "P2P_SERV_DISC_EXTERNAL ",
7283 "P2P_PRESENCE_REQ ",
7285 "P2P_REMOVE_CLIENT ",
7286 "NFC_GET_HANDOVER_SEL ",
7287 "NFC_GET_HANDOVER_REQ ",
7288 "NFC_REPORT_HANDOVER ",
7294 if (global->p2p_init_wpa_s == NULL)
7297 for (i = 0; !found && cmd[i]; i++) {
7298 if (os_strcmp(buf, cmd[i]) == 0)
7302 for (i = 0; !found && prefix[i]; i++) {
7303 if (os_strncmp(buf, prefix[i], os_strlen(prefix[i])) == 0)
7308 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
7310 #endif /* CONFIG_P2P */
7315 static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global *global,
7316 char *buf, size_t *resp_len)
7318 #ifdef CONFIG_WIFI_DISPLAY
7319 if (global->p2p_init_wpa_s == NULL)
7321 if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0 ||
7322 os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0)
7323 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
7325 #endif /* CONFIG_WIFI_DISPLAY */
7330 static char * wpas_global_ctrl_iface_redir(struct wpa_global *global,
7331 char *buf, size_t *resp_len)
7335 ret = wpas_global_ctrl_iface_redir_p2p(global, buf, resp_len);
7339 ret = wpas_global_ctrl_iface_redir_wfd(global, buf, resp_len);
7347 static int wpas_global_ctrl_iface_set(struct wpa_global *global, char *cmd)
7351 value = os_strchr(cmd, ' ');
7356 wpa_printf(MSG_DEBUG, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd, value);
7358 #ifdef CONFIG_WIFI_DISPLAY
7359 if (os_strcasecmp(cmd, "wifi_display") == 0) {
7360 wifi_display_enable(global, !!atoi(value));
7363 #endif /* CONFIG_WIFI_DISPLAY */
7365 /* Restore cmd to its original value to allow redirection */
7372 #ifndef CONFIG_NO_CONFIG_WRITE
7373 static int wpas_global_ctrl_iface_save_config(struct wpa_global *global)
7375 int ret = 0, saved = 0;
7376 struct wpa_supplicant *wpa_s;
7378 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
7379 if (!wpa_s->conf->update_config) {
7380 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
7384 if (wpa_config_write(wpa_s->confname, wpa_s->conf)) {
7385 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
7388 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
7393 if (!saved && !ret) {
7394 wpa_dbg(wpa_s, MSG_DEBUG,
7395 "CTRL_IFACE: SAVE_CONFIG - No configuration files could be updated");
7401 #endif /* CONFIG_NO_CONFIG_WRITE */
7404 static int wpas_global_ctrl_iface_status(struct wpa_global *global,
7405 char *buf, size_t buflen)
7409 struct wpa_supplicant *wpa_s;
7415 if (global->p2p && !global->p2p_disabled) {
7416 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
7419 MAC2STR(global->p2p_dev_addr),
7420 p2p_get_state_txt(global->p2p));
7421 if (ret < 0 || ret >= end - pos)
7424 } else if (global->p2p) {
7425 ret = os_snprintf(pos, end - pos, "p2p_state=DISABLED\n");
7426 if (ret < 0 || ret >= end - pos)
7430 #endif /* CONFIG_P2P */
7432 #ifdef CONFIG_WIFI_DISPLAY
7433 ret = os_snprintf(pos, end - pos, "wifi_display=%d\n",
7434 !!global->wifi_display);
7435 if (ret < 0 || ret >= end - pos)
7438 #endif /* CONFIG_WIFI_DISPLAY */
7440 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
7441 ret = os_snprintf(pos, end - pos, "ifname=%s\n"
7442 "address=" MACSTR "\n",
7443 wpa_s->ifname, MAC2STR(wpa_s->own_addr));
7444 if (ret < 0 || ret >= end - pos)
7453 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
7454 char *buf, size_t *resp_len)
7457 const int reply_size = 2048;
7459 int level = MSG_DEBUG;
7461 if (os_strncmp(buf, "IFNAME=", 7) == 0) {
7462 char *pos = os_strchr(buf + 7, ' ');
7465 return wpas_global_ctrl_iface_ifname(global,
7471 reply = wpas_global_ctrl_iface_redir(global, buf, resp_len);
7475 if (os_strcmp(buf, "PING") == 0)
7476 level = MSG_EXCESSIVE;
7477 wpa_hexdump_ascii(level, "RX global ctrl_iface",
7478 (const u8 *) buf, os_strlen(buf));
7480 reply = os_malloc(reply_size);
7481 if (reply == NULL) {
7486 os_memcpy(reply, "OK\n", 3);
7489 if (os_strcmp(buf, "PING") == 0) {
7490 os_memcpy(reply, "PONG\n", 5);
7492 } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) {
7493 if (wpa_supplicant_global_iface_add(global, buf + 14))
7495 } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) {
7496 if (wpa_supplicant_global_iface_remove(global, buf + 17))
7498 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
7499 reply_len = wpa_supplicant_global_iface_list(
7500 global, reply, reply_size);
7501 } else if (os_strcmp(buf, "INTERFACES") == 0) {
7502 reply_len = wpa_supplicant_global_iface_interfaces(
7503 global, reply, reply_size);
7504 } else if (os_strcmp(buf, "TERMINATE") == 0) {
7505 wpa_supplicant_terminate_proc(global);
7506 } else if (os_strcmp(buf, "SUSPEND") == 0) {
7507 wpas_notify_suspend(global);
7508 } else if (os_strcmp(buf, "RESUME") == 0) {
7509 wpas_notify_resume(global);
7510 } else if (os_strncmp(buf, "SET ", 4) == 0) {
7511 if (wpas_global_ctrl_iface_set(global, buf + 4)) {
7513 if (global->p2p_init_wpa_s) {
7515 /* Check if P2P redirection would work for this
7517 return wpa_supplicant_ctrl_iface_process(
7518 global->p2p_init_wpa_s,
7521 #endif /* CONFIG_P2P */
7524 #ifndef CONFIG_NO_CONFIG_WRITE
7525 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
7526 if (wpas_global_ctrl_iface_save_config(global))
7528 #endif /* CONFIG_NO_CONFIG_WRITE */
7529 } else if (os_strcmp(buf, "STATUS") == 0) {
7530 reply_len = wpas_global_ctrl_iface_status(global, reply,
7532 #ifdef CONFIG_MODULE_TESTS
7533 } else if (os_strcmp(buf, "MODULE_TESTS") == 0) {
7534 int wpas_module_tests(void);
7535 if (wpas_module_tests() < 0)
7537 #endif /* CONFIG_MODULE_TESTS */
7539 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
7543 if (reply_len < 0) {
7544 os_memcpy(reply, "FAIL\n", 5);
7548 *resp_len = reply_len;