2 * WPA Supplicant / Control interface (shared code for all backends)
3 * Copyright (c) 2004-2014, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
9 #include "utils/includes.h"
11 #include "utils/common.h"
12 #include "utils/eloop.h"
13 #include "utils/uuid.h"
14 #include "common/version.h"
15 #include "common/ieee802_11_defs.h"
16 #include "common/ieee802_11_common.h"
17 #include "common/wpa_ctrl.h"
18 #include "eap_peer/eap.h"
19 #include "eapol_supp/eapol_supp_sm.h"
20 #include "rsn_supp/wpa.h"
21 #include "rsn_supp/preauth.h"
22 #include "rsn_supp/pmksa_cache.h"
23 #include "l2_packet/l2_packet.h"
26 #include "wpa_supplicant_i.h"
28 #include "wps_supplicant.h"
31 #include "p2p_supplicant.h"
33 #include "hs20_supplicant.h"
34 #include "wifi_display.h"
38 #include "ctrl_iface.h"
39 #include "interworking.h"
40 #include "blacklist.h"
43 #include "offchannel.h"
45 static int wpa_supplicant_global_iface_list(struct wpa_global *global,
47 static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
49 static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s,
52 static int set_bssid_filter(struct wpa_supplicant *wpa_s, char *val)
55 u8 addr[ETH_ALEN], *filter = NULL, *n;
62 if (hwaddr_aton(pos, addr)) {
66 n = os_realloc_array(filter, count + 1, ETH_ALEN);
72 os_memcpy(filter + count * ETH_ALEN, addr, ETH_ALEN);
75 pos = os_strchr(pos, ' ');
80 wpa_hexdump(MSG_DEBUG, "bssid_filter", filter, count * ETH_ALEN);
81 os_free(wpa_s->bssid_filter);
82 wpa_s->bssid_filter = filter;
83 wpa_s->bssid_filter_count = count;
89 static int set_disallow_aps(struct wpa_supplicant *wpa_s, char *val)
92 u8 addr[ETH_ALEN], *bssid = NULL, *n;
93 struct wpa_ssid_value *ssid = NULL, *ns;
94 size_t count = 0, ssid_count = 0;
98 * disallow_list ::= <ssid_spec> | <bssid_spec> | <disallow_list> | ""
99 * SSID_SPEC ::= ssid <SSID_HEX>
100 * BSSID_SPEC ::= bssid <BSSID_HEX>
107 if (os_strncmp(pos, "bssid ", 6) == 0) {
110 res = hwaddr_aton2(pos, addr);
114 wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
115 "BSSID value '%s'", pos);
119 n = os_realloc_array(bssid, count + 1, ETH_ALEN);
126 os_memcpy(bssid + count * ETH_ALEN, addr, ETH_ALEN);
128 } else if (os_strncmp(pos, "ssid ", 5) == 0) {
134 if (*end == '\0' || *end == ' ')
139 ns = os_realloc_array(ssid, ssid_count + 1,
140 sizeof(struct wpa_ssid_value));
148 if ((end - pos) & 0x01 || end - pos > 2 * 32 ||
149 hexstr2bin(pos, ssid[ssid_count].ssid,
150 (end - pos) / 2) < 0) {
153 wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
154 "SSID value '%s'", pos);
157 ssid[ssid_count].ssid_len = (end - pos) / 2;
158 wpa_hexdump_ascii(MSG_DEBUG, "disallow_aps SSID",
159 ssid[ssid_count].ssid,
160 ssid[ssid_count].ssid_len);
164 wpa_printf(MSG_DEBUG, "Unexpected disallow_aps value "
171 pos = os_strchr(pos, ' ');
176 wpa_hexdump(MSG_DEBUG, "disallow_aps_bssid", bssid, count * ETH_ALEN);
177 os_free(wpa_s->disallow_aps_bssid);
178 wpa_s->disallow_aps_bssid = bssid;
179 wpa_s->disallow_aps_bssid_count = count;
181 wpa_printf(MSG_DEBUG, "disallow_aps_ssid_count %d", (int) ssid_count);
182 os_free(wpa_s->disallow_aps_ssid);
183 wpa_s->disallow_aps_ssid = ssid;
184 wpa_s->disallow_aps_ssid_count = ssid_count;
186 if (!wpa_s->current_ssid || wpa_s->wpa_state < WPA_AUTHENTICATING)
189 c = wpa_s->current_ssid;
190 if (c->mode != WPAS_MODE_INFRA && c->mode != WPAS_MODE_IBSS)
193 if (!disallowed_bssid(wpa_s, wpa_s->bssid) &&
194 !disallowed_ssid(wpa_s, c->ssid, c->ssid_len))
197 wpa_printf(MSG_DEBUG, "Disconnect and try to find another network "
198 "because current AP was marked disallowed");
201 wpa_s->sme.prev_bssid_set = 0;
202 #endif /* CONFIG_SME */
203 wpa_s->reassociate = 1;
204 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
205 wpa_supplicant_req_scan(wpa_s, 0, 0);
211 #ifndef CONFIG_NO_CONFIG_BLOBS
212 static int wpas_ctrl_set_blob(struct wpa_supplicant *wpa_s, char *pos)
215 struct wpa_config_blob *blob;
218 pos = os_strchr(pos, ' ');
222 len = os_strlen(pos);
226 wpa_printf(MSG_DEBUG, "CTRL: Set blob '%s'", name);
227 blob = os_zalloc(sizeof(*blob));
230 blob->name = os_strdup(name);
231 blob->data = os_malloc(len / 2);
232 if (blob->name == NULL || blob->data == NULL) {
233 wpa_config_free_blob(blob);
237 if (hexstr2bin(pos, blob->data, len / 2) < 0) {
238 wpa_printf(MSG_DEBUG, "CTRL: Invalid blob hex data");
239 wpa_config_free_blob(blob);
244 wpa_config_set_blob(wpa_s->conf, blob);
248 #endif /* CONFIG_NO_CONFIG_BLOBS */
251 static int wpas_ctrl_pno(struct wpa_supplicant *wpa_s, char *cmd)
259 params = os_strchr(cmd, ' ');
260 os_free(wpa_s->manual_sched_scan_freqs);
263 pos = os_strstr(params, "freq=");
265 freqs = freq_range_to_channel_list(wpa_s,
268 wpa_s->manual_sched_scan_freqs = freqs;
269 ret = wpas_start_pno(wpa_s);
271 ret = wpas_stop_pno(wpa_s);
277 static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s,
283 value = os_strchr(cmd, ' ');
288 wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value);
289 if (os_strcasecmp(cmd, "EAPOL::heldPeriod") == 0) {
290 eapol_sm_configure(wpa_s->eapol,
291 atoi(value), -1, -1, -1);
292 } else if (os_strcasecmp(cmd, "EAPOL::authPeriod") == 0) {
293 eapol_sm_configure(wpa_s->eapol,
294 -1, atoi(value), -1, -1);
295 } else if (os_strcasecmp(cmd, "EAPOL::startPeriod") == 0) {
296 eapol_sm_configure(wpa_s->eapol,
297 -1, -1, atoi(value), -1);
298 } else if (os_strcasecmp(cmd, "EAPOL::maxStart") == 0) {
299 eapol_sm_configure(wpa_s->eapol,
300 -1, -1, -1, atoi(value));
301 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKLifetime") == 0) {
302 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME,
305 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKReauthThreshold") ==
307 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD,
310 } else if (os_strcasecmp(cmd, "dot11RSNAConfigSATimeout") == 0) {
311 if (wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, atoi(value)))
313 } else if (os_strcasecmp(cmd, "wps_fragment_size") == 0) {
314 wpa_s->wps_fragment_size = atoi(value);
315 #ifdef CONFIG_WPS_TESTING
316 } else if (os_strcasecmp(cmd, "wps_version_number") == 0) {
318 val = strtol(value, NULL, 0);
319 if (val < 0 || val > 0xff) {
321 wpa_printf(MSG_DEBUG, "WPS: Invalid "
322 "wps_version_number %ld", val);
324 wps_version_number = val;
325 wpa_printf(MSG_DEBUG, "WPS: Testing - force WPS "
327 (wps_version_number & 0xf0) >> 4,
328 wps_version_number & 0x0f);
330 } else if (os_strcasecmp(cmd, "wps_testing_dummy_cred") == 0) {
331 wps_testing_dummy_cred = atoi(value);
332 wpa_printf(MSG_DEBUG, "WPS: Testing - dummy_cred=%d",
333 wps_testing_dummy_cred);
334 } else if (os_strcasecmp(cmd, "wps_corrupt_pkhash") == 0) {
335 wps_corrupt_pkhash = atoi(value);
336 wpa_printf(MSG_DEBUG, "WPS: Testing - wps_corrupt_pkhash=%d",
338 #endif /* CONFIG_WPS_TESTING */
339 } else if (os_strcasecmp(cmd, "ampdu") == 0) {
340 if (wpa_drv_ampdu(wpa_s, atoi(value)) < 0)
343 #ifdef CONFIG_TDLS_TESTING
344 } else if (os_strcasecmp(cmd, "tdls_testing") == 0) {
345 extern unsigned int tdls_testing;
346 tdls_testing = strtol(value, NULL, 0);
347 wpa_printf(MSG_DEBUG, "TDLS: tdls_testing=0x%x", tdls_testing);
348 #endif /* CONFIG_TDLS_TESTING */
349 } else if (os_strcasecmp(cmd, "tdls_disabled") == 0) {
350 int disabled = atoi(value);
351 wpa_printf(MSG_DEBUG, "TDLS: tdls_disabled=%d", disabled);
353 if (wpa_drv_tdls_oper(wpa_s, TDLS_DISABLE, NULL) < 0)
355 } else if (wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL) < 0)
357 wpa_tdls_enable(wpa_s->wpa, !disabled);
358 #endif /* CONFIG_TDLS */
359 } else if (os_strcasecmp(cmd, "pno") == 0) {
360 ret = wpas_ctrl_pno(wpa_s, value);
361 } else if (os_strcasecmp(cmd, "radio_disabled") == 0) {
362 int disabled = atoi(value);
363 if (wpa_drv_radio_disable(wpa_s, disabled) < 0)
366 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
367 } else if (os_strcasecmp(cmd, "uapsd") == 0) {
368 if (os_strcmp(value, "disable") == 0)
369 wpa_s->set_sta_uapsd = 0;
373 /* format: BE,BK,VI,VO;max SP Length */
375 pos = os_strchr(value, ',');
380 pos = os_strchr(pos, ',');
385 pos = os_strchr(pos, ',');
390 /* ignore max SP Length for now */
392 wpa_s->set_sta_uapsd = 1;
393 wpa_s->sta_uapsd = 0;
395 wpa_s->sta_uapsd |= BIT(0);
397 wpa_s->sta_uapsd |= BIT(1);
399 wpa_s->sta_uapsd |= BIT(2);
401 wpa_s->sta_uapsd |= BIT(3);
403 } else if (os_strcasecmp(cmd, "ps") == 0) {
404 ret = wpa_drv_set_p2p_powersave(wpa_s, atoi(value), -1, -1);
405 #ifdef CONFIG_WIFI_DISPLAY
406 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
407 int enabled = !!atoi(value);
408 if (enabled && !wpa_s->global->p2p)
411 wifi_display_enable(wpa_s->global, enabled);
412 #endif /* CONFIG_WIFI_DISPLAY */
413 } else if (os_strcasecmp(cmd, "bssid_filter") == 0) {
414 ret = set_bssid_filter(wpa_s, value);
415 } else if (os_strcasecmp(cmd, "disallow_aps") == 0) {
416 ret = set_disallow_aps(wpa_s, value);
417 } else if (os_strcasecmp(cmd, "no_keep_alive") == 0) {
418 wpa_s->no_keep_alive = !!atoi(value);
419 #ifdef CONFIG_TESTING_OPTIONS
420 } else if (os_strcasecmp(cmd, "ext_mgmt_frame_handling") == 0) {
421 wpa_s->ext_mgmt_frame_handling = !!atoi(value);
422 #endif /* CONFIG_TESTING_OPTIONS */
423 #ifndef CONFIG_NO_CONFIG_BLOBS
424 } else if (os_strcmp(cmd, "blob") == 0) {
425 ret = wpas_ctrl_set_blob(wpa_s, value);
426 #endif /* CONFIG_NO_CONFIG_BLOBS */
429 ret = wpa_config_process_global(wpa_s->conf, cmd, -1);
431 wpa_supplicant_update_config(wpa_s);
438 static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s,
439 char *cmd, char *buf, size_t buflen)
443 wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd);
445 if (os_strcmp(cmd, "version") == 0) {
446 res = os_snprintf(buf, buflen, "%s", VERSION_STR);
447 } else if (os_strcasecmp(cmd, "country") == 0) {
448 if (wpa_s->conf->country[0] && wpa_s->conf->country[1])
449 res = os_snprintf(buf, buflen, "%c%c",
450 wpa_s->conf->country[0],
451 wpa_s->conf->country[1]);
452 #ifdef CONFIG_WIFI_DISPLAY
453 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
455 if (wpa_s->global->p2p == NULL ||
456 wpa_s->global->p2p_disabled)
459 enabled = wpa_s->global->wifi_display;
460 res = os_snprintf(buf, buflen, "%d", enabled);
461 if (res < 0 || (unsigned int) res >= buflen)
464 #endif /* CONFIG_WIFI_DISPLAY */
465 #ifdef CONFIG_TESTING_GET_GTK
466 } else if (os_strcmp(cmd, "gtk") == 0) {
467 if (wpa_s->last_gtk_len == 0)
469 res = wpa_snprintf_hex(buf, buflen, wpa_s->last_gtk,
470 wpa_s->last_gtk_len);
472 #endif /* CONFIG_TESTING_GET_GTK */
475 if (res < 0 || (unsigned int) res >= buflen)
481 #ifdef IEEE8021X_EAPOL
482 static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s,
486 struct wpa_ssid *ssid = wpa_s->current_ssid;
488 if (hwaddr_aton(addr, bssid)) {
489 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address "
494 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid));
495 rsn_preauth_deinit(wpa_s->wpa);
496 if (rsn_preauth_init(wpa_s->wpa, bssid, ssid ? &ssid->eap : NULL))
501 #endif /* IEEE8021X_EAPOL */
504 #ifdef CONFIG_PEERKEY
505 /* MLME-STKSTART.request(peer) */
506 static int wpa_supplicant_ctrl_iface_stkstart(
507 struct wpa_supplicant *wpa_s, char *addr)
511 if (hwaddr_aton(addr, peer)) {
512 wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART: invalid "
513 "address '%s'", addr);
517 wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART " MACSTR,
520 return wpa_sm_stkstart(wpa_s->wpa, peer);
522 #endif /* CONFIG_PEERKEY */
527 static int wpa_supplicant_ctrl_iface_tdls_discover(
528 struct wpa_supplicant *wpa_s, char *addr)
533 if (hwaddr_aton(addr, peer)) {
534 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER: invalid "
535 "address '%s'", addr);
539 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER " MACSTR,
542 if (wpa_tdls_is_external_setup(wpa_s->wpa))
543 ret = wpa_tdls_send_discovery_request(wpa_s->wpa, peer);
545 ret = wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer);
551 static int wpa_supplicant_ctrl_iface_tdls_setup(
552 struct wpa_supplicant *wpa_s, char *addr)
557 if (hwaddr_aton(addr, peer)) {
558 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP: invalid "
559 "address '%s'", addr);
563 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP " MACSTR,
566 if ((wpa_s->conf->tdls_external_control) &&
567 wpa_tdls_is_external_setup(wpa_s->wpa))
568 return wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
570 wpa_tdls_remove(wpa_s->wpa, peer);
572 if (wpa_tdls_is_external_setup(wpa_s->wpa))
573 ret = wpa_tdls_start(wpa_s->wpa, peer);
575 ret = wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
581 static int wpa_supplicant_ctrl_iface_tdls_teardown(
582 struct wpa_supplicant *wpa_s, char *addr)
587 if (hwaddr_aton(addr, peer)) {
588 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN: invalid "
589 "address '%s'", addr);
593 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN " MACSTR,
596 if ((wpa_s->conf->tdls_external_control) &&
597 wpa_tdls_is_external_setup(wpa_s->wpa))
598 return wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
600 if (wpa_tdls_is_external_setup(wpa_s->wpa))
601 ret = wpa_tdls_teardown_link(
603 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED);
605 ret = wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
611 static int ctrl_iface_get_capability_tdls(
612 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
616 ret = os_snprintf(buf, buflen, "%s\n",
617 wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT ?
619 WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP ?
620 "EXTERNAL" : "INTERNAL") : "UNSUPPORTED");
621 if (ret < 0 || (size_t) ret > buflen)
626 #endif /* CONFIG_TDLS */
629 #ifdef CONFIG_IEEE80211R
630 static int wpa_supplicant_ctrl_iface_ft_ds(
631 struct wpa_supplicant *wpa_s, char *addr)
633 u8 target_ap[ETH_ALEN];
637 if (hwaddr_aton(addr, target_ap)) {
638 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid "
639 "address '%s'", addr);
643 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap));
645 bss = wpa_bss_get_bssid(wpa_s, target_ap);
647 mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN);
651 return wpa_ft_start_over_ds(wpa_s->wpa, target_ap, mdie);
653 #endif /* CONFIG_IEEE80211R */
657 static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s,
660 u8 bssid[ETH_ALEN], *_bssid = bssid;
662 u8 p2p_dev_addr[ETH_ALEN];
663 #endif /* CONFIG_P2P */
665 u8 *_p2p_dev_addr = NULL;
666 #endif /* CONFIG_AP */
668 if (cmd == NULL || os_strcmp(cmd, "any") == 0) {
671 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
672 if (hwaddr_aton(cmd + 13, p2p_dev_addr)) {
673 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid "
674 "P2P Device Address '%s'",
678 _p2p_dev_addr = p2p_dev_addr;
679 #endif /* CONFIG_P2P */
680 } else if (hwaddr_aton(cmd, bssid)) {
681 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
688 return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid, _p2p_dev_addr);
689 #endif /* CONFIG_AP */
691 return wpas_wps_start_pbc(wpa_s, _bssid, 0);
695 static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s,
696 char *cmd, char *buf,
699 u8 bssid[ETH_ALEN], *_bssid = bssid;
703 pin = os_strchr(cmd, ' ');
707 if (os_strcmp(cmd, "any") == 0)
709 else if (os_strcmp(cmd, "get") == 0) {
710 ret = wps_generate_pin();
712 } else if (hwaddr_aton(cmd, bssid)) {
713 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
719 if (wpa_s->ap_iface) {
724 pos = os_strchr(pin, ' ');
731 return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin,
732 buf, buflen, timeout);
734 #endif /* CONFIG_AP */
737 ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0,
741 ret = os_snprintf(buf, buflen, "%s", pin);
742 if (ret < 0 || (size_t) ret >= buflen)
747 ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0, DEV_PW_DEFAULT);
752 /* Return the generated PIN */
753 ret = os_snprintf(buf, buflen, "%08d", ret);
754 if (ret < 0 || (size_t) ret >= buflen)
760 static int wpa_supplicant_ctrl_iface_wps_check_pin(
761 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
768 wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN",
769 (u8 *) cmd, os_strlen(cmd));
770 for (pos = cmd, len = 0; *pos != '\0'; pos++) {
771 if (*pos < '0' || *pos > '9')
775 wpa_printf(MSG_DEBUG, "WPS: Too long PIN");
779 if (len != 4 && len != 8) {
780 wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len);
786 unsigned int pin_val;
788 if (!wps_pin_valid(pin_val)) {
789 wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit");
790 ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n");
791 if (ret < 0 || (size_t) ret >= buflen)
797 ret = os_snprintf(buf, buflen, "%s", pin);
798 if (ret < 0 || (size_t) ret >= buflen)
805 #ifdef CONFIG_WPS_NFC
807 static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant *wpa_s,
810 u8 bssid[ETH_ALEN], *_bssid = bssid;
812 if (cmd == NULL || cmd[0] == '\0')
814 else if (hwaddr_aton(cmd, bssid))
817 return wpas_wps_start_nfc(wpa_s, NULL, _bssid, NULL, 0, 0, NULL, NULL,
822 static int wpa_supplicant_ctrl_iface_wps_nfc_config_token(
823 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
830 pos = os_strchr(cmd, ' ');
833 if (os_strcmp(cmd, "WPS") == 0)
835 else if (os_strcmp(cmd, "NDEF") == 0)
840 buf = wpas_wps_nfc_config_token(wpa_s, ndef, pos);
844 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
855 static int wpa_supplicant_ctrl_iface_wps_nfc_token(
856 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
862 if (os_strcmp(cmd, "WPS") == 0)
864 else if (os_strcmp(cmd, "NDEF") == 0)
869 buf = wpas_wps_nfc_token(wpa_s, ndef);
873 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
884 static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
885 struct wpa_supplicant *wpa_s, char *pos)
893 freq = strstr(pos, " freq=");
897 forced_freq = atoi(freq);
900 len = os_strlen(pos);
905 buf = wpabuf_alloc(len);
908 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
913 ret = wpas_wps_nfc_tag_read(wpa_s, buf, forced_freq);
920 static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant *wpa_s,
921 char *reply, size_t max_len,
927 buf = wpas_wps_nfc_handover_req(wpa_s, ndef);
931 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
943 static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant *wpa_s,
944 char *reply, size_t max_len,
950 buf = wpas_p2p_nfc_handover_req(wpa_s, ndef);
952 wpa_printf(MSG_DEBUG, "P2P: Could not generate NFC handover request");
956 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
965 #endif /* CONFIG_P2P */
968 static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant *wpa_s,
969 char *cmd, char *reply,
975 pos = os_strchr(cmd, ' ');
980 if (os_strcmp(cmd, "WPS") == 0)
982 else if (os_strcmp(cmd, "NDEF") == 0)
987 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
990 return wpas_ctrl_nfc_get_handover_req_wps(
991 wpa_s, reply, max_len, ndef);
995 if (os_strcmp(pos, "P2P-CR") == 0) {
996 return wpas_ctrl_nfc_get_handover_req_p2p(
997 wpa_s, reply, max_len, ndef);
999 #endif /* CONFIG_P2P */
1005 static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant *wpa_s,
1006 char *reply, size_t max_len,
1007 int ndef, int cr, char *uuid)
1012 buf = wpas_wps_nfc_handover_sel(wpa_s, ndef, cr, uuid);
1016 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1018 reply[res++] = '\n';
1028 static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant *wpa_s,
1029 char *reply, size_t max_len,
1035 buf = wpas_p2p_nfc_handover_sel(wpa_s, ndef, tag);
1039 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1041 reply[res++] = '\n';
1048 #endif /* CONFIG_P2P */
1051 static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant *wpa_s,
1052 char *cmd, char *reply,
1058 pos = os_strchr(cmd, ' ');
1063 if (os_strcmp(cmd, "WPS") == 0)
1065 else if (os_strcmp(cmd, "NDEF") == 0)
1070 pos2 = os_strchr(pos, ' ');
1073 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
1076 return wpas_ctrl_nfc_get_handover_sel_wps(
1077 wpa_s, reply, max_len, ndef,
1078 os_strcmp(pos, "WPS-CR") == 0, pos2);
1082 if (os_strcmp(pos, "P2P-CR") == 0) {
1083 return wpas_ctrl_nfc_get_handover_sel_p2p(
1084 wpa_s, reply, max_len, ndef, 0);
1087 if (os_strcmp(pos, "P2P-CR-TAG") == 0) {
1088 return wpas_ctrl_nfc_get_handover_sel_p2p(
1089 wpa_s, reply, max_len, ndef, 1);
1091 #endif /* CONFIG_P2P */
1097 static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant *wpa_s,
1101 struct wpabuf *req, *sel;
1103 char *pos, *role, *type, *pos2;
1106 int forced_freq = 0;
1108 freq = strstr(cmd, " freq=");
1112 forced_freq = atoi(freq);
1114 #endif /* CONFIG_P2P */
1117 pos = os_strchr(role, ' ');
1119 wpa_printf(MSG_DEBUG, "NFC: Missing type in handover report");
1125 pos = os_strchr(type, ' ');
1127 wpa_printf(MSG_DEBUG, "NFC: Missing request message in handover report");
1132 pos2 = os_strchr(pos, ' ');
1134 wpa_printf(MSG_DEBUG, "NFC: Missing select message in handover report");
1139 len = os_strlen(pos);
1141 wpa_printf(MSG_DEBUG, "NFC: Invalid request message length in handover report");
1146 req = wpabuf_alloc(len);
1148 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for request message");
1151 if (hexstr2bin(pos, wpabuf_put(req, len), len) < 0) {
1152 wpa_printf(MSG_DEBUG, "NFC: Invalid request message hexdump in handover report");
1157 len = os_strlen(pos2);
1159 wpa_printf(MSG_DEBUG, "NFC: Invalid select message length in handover report");
1165 sel = wpabuf_alloc(len);
1167 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for select message");
1171 if (hexstr2bin(pos2, wpabuf_put(sel, len), len) < 0) {
1172 wpa_printf(MSG_DEBUG, "NFC: Invalid select message hexdump in handover report");
1178 wpa_printf(MSG_DEBUG, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d",
1179 role, type, (int) wpabuf_len(req), (int) wpabuf_len(sel));
1181 if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "WPS") == 0) {
1182 ret = wpas_wps_nfc_report_handover(wpa_s, req, sel);
1184 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "WPS") == 0)
1186 ret = wpas_ap_wps_nfc_report_handover(wpa_s, req, sel);
1188 ret = wpas_er_wps_nfc_report_handover(wpa_s, req, sel);
1189 #endif /* CONFIG_AP */
1191 } else if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "P2P") == 0)
1193 ret = wpas_p2p_nfc_report_handover(wpa_s, 1, req, sel, 0);
1194 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "P2P") == 0)
1196 ret = wpas_p2p_nfc_report_handover(wpa_s, 0, req, sel,
1198 #endif /* CONFIG_P2P */
1200 wpa_printf(MSG_DEBUG, "NFC: Unsupported connection handover "
1201 "reported: role=%s type=%s", role, type);
1208 wpa_printf(MSG_DEBUG, "NFC: Failed to process reported handover messages");
1213 #endif /* CONFIG_WPS_NFC */
1216 static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s,
1225 struct wps_new_ap_settings ap;
1227 pin = os_strchr(cmd, ' ');
1232 if (hwaddr_aton(cmd, bssid)) {
1233 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
1238 new_ssid = os_strchr(pin, ' ');
1239 if (new_ssid == NULL)
1240 return wpas_wps_start_reg(wpa_s, bssid, pin, NULL);
1243 new_auth = os_strchr(new_ssid, ' ');
1244 if (new_auth == NULL)
1248 new_encr = os_strchr(new_auth, ' ');
1249 if (new_encr == NULL)
1253 new_key = os_strchr(new_encr, ' ');
1254 if (new_key == NULL)
1258 os_memset(&ap, 0, sizeof(ap));
1259 ap.ssid_hex = new_ssid;
1262 ap.key_hex = new_key;
1263 return wpas_wps_start_reg(wpa_s, bssid, pin, &ap);
1268 static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant *wpa_s,
1269 char *cmd, char *buf,
1274 const char *pin_txt;
1276 if (!wpa_s->ap_iface)
1279 pos = os_strchr(cmd, ' ');
1283 if (os_strcmp(cmd, "disable") == 0) {
1284 wpas_wps_ap_pin_disable(wpa_s);
1285 return os_snprintf(buf, buflen, "OK\n");
1288 if (os_strcmp(cmd, "random") == 0) {
1290 timeout = atoi(pos);
1291 pin_txt = wpas_wps_ap_pin_random(wpa_s, timeout);
1292 if (pin_txt == NULL)
1294 return os_snprintf(buf, buflen, "%s", pin_txt);
1297 if (os_strcmp(cmd, "get") == 0) {
1298 pin_txt = wpas_wps_ap_pin_get(wpa_s);
1299 if (pin_txt == NULL)
1301 return os_snprintf(buf, buflen, "%s", pin_txt);
1304 if (os_strcmp(cmd, "set") == 0) {
1309 pos = os_strchr(pos, ' ');
1312 timeout = atoi(pos);
1314 if (os_strlen(pin) > buflen)
1316 if (wpas_wps_ap_pin_set(wpa_s, pin, timeout) < 0)
1318 return os_snprintf(buf, buflen, "%s", pin);
1323 #endif /* CONFIG_AP */
1326 #ifdef CONFIG_WPS_ER
1327 static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant *wpa_s,
1330 char *uuid = cmd, *pin, *pos;
1331 u8 addr_buf[ETH_ALEN], *addr = NULL;
1332 pin = os_strchr(uuid, ' ');
1336 pos = os_strchr(pin, ' ');
1339 if (hwaddr_aton(pos, addr_buf) == 0)
1342 return wpas_wps_er_add_pin(wpa_s, addr, uuid, pin);
1346 static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant *wpa_s,
1349 char *uuid = cmd, *pin;
1350 pin = os_strchr(uuid, ' ');
1354 return wpas_wps_er_learn(wpa_s, uuid, pin);
1358 static int wpa_supplicant_ctrl_iface_wps_er_set_config(
1359 struct wpa_supplicant *wpa_s, char *cmd)
1361 char *uuid = cmd, *id;
1362 id = os_strchr(uuid, ' ');
1366 return wpas_wps_er_set_config(wpa_s, uuid, atoi(id));
1370 static int wpa_supplicant_ctrl_iface_wps_er_config(
1371 struct wpa_supplicant *wpa_s, char *cmd)
1378 struct wps_new_ap_settings ap;
1380 pin = os_strchr(cmd, ' ');
1385 new_ssid = os_strchr(pin, ' ');
1386 if (new_ssid == NULL)
1390 new_auth = os_strchr(new_ssid, ' ');
1391 if (new_auth == NULL)
1395 new_encr = os_strchr(new_auth, ' ');
1396 if (new_encr == NULL)
1400 new_key = os_strchr(new_encr, ' ');
1401 if (new_key == NULL)
1405 os_memset(&ap, 0, sizeof(ap));
1406 ap.ssid_hex = new_ssid;
1409 ap.key_hex = new_key;
1410 return wpas_wps_er_config(wpa_s, cmd, pin, &ap);
1414 #ifdef CONFIG_WPS_NFC
1415 static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
1416 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1423 uuid = os_strchr(cmd, ' ');
1428 if (os_strcmp(cmd, "WPS") == 0)
1430 else if (os_strcmp(cmd, "NDEF") == 0)
1435 buf = wpas_wps_er_nfc_config_token(wpa_s, ndef, uuid);
1439 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1441 reply[res++] = '\n';
1448 #endif /* CONFIG_WPS_NFC */
1449 #endif /* CONFIG_WPS_ER */
1451 #endif /* CONFIG_WPS */
1454 #ifdef CONFIG_IBSS_RSN
1455 static int wpa_supplicant_ctrl_iface_ibss_rsn(
1456 struct wpa_supplicant *wpa_s, char *addr)
1460 if (hwaddr_aton(addr, peer)) {
1461 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN: invalid "
1462 "address '%s'", addr);
1466 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN " MACSTR,
1469 return ibss_rsn_start(wpa_s->ibss_rsn, peer);
1471 #endif /* CONFIG_IBSS_RSN */
1474 static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s,
1477 #ifdef IEEE8021X_EAPOL
1480 struct wpa_ssid *ssid;
1482 pos = os_strchr(rsp, '-');
1487 pos = os_strchr(pos, ':');
1492 wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id);
1493 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
1494 (u8 *) pos, os_strlen(pos));
1496 ssid = wpa_config_get_network(wpa_s->conf, id);
1498 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
1503 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s, ssid, rsp,
1505 #else /* IEEE8021X_EAPOL */
1506 wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included");
1508 #endif /* IEEE8021X_EAPOL */
1512 static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
1514 char *buf, size_t buflen)
1516 char *pos, *end, tmp[30];
1517 int res, verbose, wps, ret;
1520 #endif /* CONFIG_HS20 */
1522 if (os_strcmp(params, "-DRIVER") == 0)
1523 return wpa_drv_status(wpa_s, buf, buflen);
1524 verbose = os_strcmp(params, "-VERBOSE") == 0;
1525 wps = os_strcmp(params, "-WPS") == 0;
1528 if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
1529 struct wpa_ssid *ssid = wpa_s->current_ssid;
1530 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
1531 MAC2STR(wpa_s->bssid));
1532 if (ret < 0 || ret >= end - pos)
1536 u8 *_ssid = ssid->ssid;
1537 size_t ssid_len = ssid->ssid_len;
1538 u8 ssid_buf[MAX_SSID_LEN];
1539 if (ssid_len == 0) {
1540 int _res = wpa_drv_get_ssid(wpa_s, ssid_buf);
1547 ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n",
1548 wpa_ssid_txt(_ssid, ssid_len),
1550 if (ret < 0 || ret >= end - pos)
1554 if (wps && ssid->passphrase &&
1555 wpa_key_mgmt_wpa_psk(ssid->key_mgmt) &&
1556 (ssid->mode == WPAS_MODE_AP ||
1557 ssid->mode == WPAS_MODE_P2P_GO)) {
1558 ret = os_snprintf(pos, end - pos,
1561 if (ret < 0 || ret >= end - pos)
1566 ret = os_snprintf(pos, end - pos,
1569 if (ret < 0 || ret >= end - pos)
1574 switch (ssid->mode) {
1575 case WPAS_MODE_INFRA:
1576 ret = os_snprintf(pos, end - pos,
1579 case WPAS_MODE_IBSS:
1580 ret = os_snprintf(pos, end - pos,
1584 ret = os_snprintf(pos, end - pos,
1587 case WPAS_MODE_P2P_GO:
1588 ret = os_snprintf(pos, end - pos,
1591 case WPAS_MODE_P2P_GROUP_FORMATION:
1592 ret = os_snprintf(pos, end - pos,
1593 "mode=P2P GO - group "
1600 if (ret < 0 || ret >= end - pos)
1606 if (wpa_s->ap_iface) {
1607 pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos,
1611 #endif /* CONFIG_AP */
1612 pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose);
1615 if (wpa_s->wpa_state >= WPA_ASSOCIATED &&
1618 #endif /* CONFIG_AP */
1619 wpa_s->sme.sae.state == SAE_ACCEPTED) {
1620 ret = os_snprintf(pos, end - pos, "sae_group=%d\n",
1621 wpa_s->sme.sae.group);
1622 if (ret < 0 || ret >= end - pos)
1626 #endif /* CONFIG_SAE */
1627 ret = os_snprintf(pos, end - pos, "wpa_state=%s\n",
1628 wpa_supplicant_state_txt(wpa_s->wpa_state));
1629 if (ret < 0 || ret >= end - pos)
1634 l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) {
1635 ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp);
1636 if (ret < 0 || ret >= end - pos)
1642 if (wpa_s->global->p2p) {
1643 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
1644 "\n", MAC2STR(wpa_s->global->p2p_dev_addr));
1645 if (ret < 0 || ret >= end - pos)
1649 #endif /* CONFIG_P2P */
1651 ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n",
1652 MAC2STR(wpa_s->own_addr));
1653 if (ret < 0 || ret >= end - pos)
1658 if (wpa_s->current_bss &&
1659 (hs20 = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1660 HS20_IE_VENDOR_TYPE)) &&
1661 wpa_s->wpa_proto == WPA_PROTO_RSN &&
1662 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1665 u8 rel_num = (hs20[6] & 0xf0) >> 4;
1666 release = rel_num + 1;
1668 ret = os_snprintf(pos, end - pos, "hs20=%d\n", release);
1669 if (ret < 0 || ret >= end - pos)
1674 if (wpa_s->current_ssid) {
1675 struct wpa_cred *cred;
1678 for (cred = wpa_s->conf->cred; cred; cred = cred->next) {
1681 if (wpa_s->current_ssid->parent_cred != cred)
1684 if (cred->provisioning_sp) {
1685 ret = os_snprintf(pos, end - pos,
1686 "provisioning_sp=%s\n",
1687 cred->provisioning_sp);
1688 if (ret < 0 || ret >= end - pos)
1697 if (wpa_s->current_bss && wpa_s->current_bss->anqp) {
1698 struct wpabuf *names =
1699 wpa_s->current_bss->anqp->domain_name;
1700 for (i = 0; names && i < cred->num_domain; i++)
1702 if (domain_name_list_contains(
1703 names, cred->domain[i], 1))
1706 if (i == cred->num_domain)
1707 i = 0; /* show first entry by default */
1709 ret = os_snprintf(pos, end - pos, "home_sp=%s\n",
1711 if (ret < 0 || ret >= end - pos)
1716 if (wpa_s->current_bss == NULL ||
1717 wpa_s->current_bss->anqp == NULL)
1720 res = interworking_home_sp_cred(
1722 wpa_s->current_bss->anqp->domain_name);
1730 ret = os_snprintf(pos, end - pos, "sp_type=%s\n", type);
1731 if (ret < 0 || ret >= end - pos)
1738 #endif /* CONFIG_HS20 */
1740 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
1741 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
1742 res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos,
1748 res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose);
1755 uuid_bin2str(wpa_s->wps->uuid, uuid_str, sizeof(uuid_str));
1756 ret = os_snprintf(pos, end - pos, "uuid=%s\n", uuid_str);
1757 if (ret < 0 || ret >= end - pos)
1761 #endif /* CONFIG_WPS */
1764 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_STATE_CHANGE
1765 "id=%d state=%d BSSID=" MACSTR " SSID=%s",
1766 wpa_s->current_ssid ? wpa_s->current_ssid->id : -1,
1768 MAC2STR(wpa_s->bssid),
1769 wpa_s->current_ssid && wpa_s->current_ssid->ssid ?
1770 wpa_ssid_txt(wpa_s->current_ssid->ssid,
1771 wpa_s->current_ssid->ssid_len) : "");
1772 if (wpa_s->wpa_state == WPA_COMPLETED) {
1773 struct wpa_ssid *ssid = wpa_s->current_ssid;
1774 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_CONNECTED
1775 "- connection to " MACSTR
1776 " completed %s [id=%d id_str=%s]",
1777 MAC2STR(wpa_s->bssid), "(auth)",
1778 ssid ? ssid->id : -1,
1779 ssid && ssid->id_str ? ssid->id_str : "");
1781 #endif /* ANDROID */
1787 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s,
1792 struct wpa_ssid *ssid;
1795 /* cmd: "<network id> <BSSID>" */
1796 pos = os_strchr(cmd, ' ');
1801 wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos);
1802 if (hwaddr_aton(pos, bssid)) {
1803 wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos);
1807 ssid = wpa_config_get_network(wpa_s->conf, id);
1809 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
1814 os_memcpy(ssid->bssid, bssid, ETH_ALEN);
1815 ssid->bssid_set = !is_zero_ether_addr(bssid);
1821 static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant *wpa_s,
1822 char *cmd, char *buf,
1826 struct wpa_blacklist *e;
1830 /* cmd: "BLACKLIST [<BSSID>]" */
1834 e = wpa_s->blacklist;
1836 ret = os_snprintf(pos, end - pos, MACSTR "\n",
1838 if (ret < 0 || ret >= end - pos)
1847 if (os_strncmp(cmd, "clear", 5) == 0) {
1848 wpa_blacklist_clear(wpa_s);
1849 os_memcpy(buf, "OK\n", 3);
1853 wpa_printf(MSG_DEBUG, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd);
1854 if (hwaddr_aton(cmd, bssid)) {
1855 wpa_printf(MSG_DEBUG, "CTRL_IFACE: invalid BSSID '%s'", cmd);
1860 * Add the BSSID twice, so its count will be 2, causing it to be
1861 * skipped when processing scan results.
1863 ret = wpa_blacklist_add(wpa_s, bssid);
1866 ret = wpa_blacklist_add(wpa_s, bssid);
1869 os_memcpy(buf, "OK\n", 3);
1874 static const char * debug_level_str(int level)
1895 static int str_to_debug_level(const char *s)
1897 if (os_strcasecmp(s, "EXCESSIVE") == 0)
1898 return MSG_EXCESSIVE;
1899 if (os_strcasecmp(s, "MSGDUMP") == 0)
1901 if (os_strcasecmp(s, "DEBUG") == 0)
1903 if (os_strcasecmp(s, "INFO") == 0)
1905 if (os_strcasecmp(s, "WARNING") == 0)
1907 if (os_strcasecmp(s, "ERROR") == 0)
1913 static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant *wpa_s,
1914 char *cmd, char *buf,
1917 char *pos, *end, *stamp;
1924 /* cmd: "LOG_LEVEL [<level>]" */
1928 ret = os_snprintf(pos, end - pos, "Current level: %s\n"
1930 debug_level_str(wpa_debug_level),
1931 wpa_debug_timestamp);
1932 if (ret < 0 || ret >= end - pos)
1941 stamp = os_strchr(cmd, ' ');
1944 while (*stamp == ' ') {
1949 if (cmd && os_strlen(cmd)) {
1950 int level = str_to_debug_level(cmd);
1953 wpa_debug_level = level;
1956 if (stamp && os_strlen(stamp))
1957 wpa_debug_timestamp = atoi(stamp);
1959 os_memcpy(buf, "OK\n", 3);
1964 static int wpa_supplicant_ctrl_iface_list_networks(
1965 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
1968 struct wpa_ssid *ssid;
1973 ret = os_snprintf(pos, end - pos,
1974 "network id / ssid / bssid / flags\n");
1975 if (ret < 0 || ret >= end - pos)
1979 ssid = wpa_s->conf->ssid;
1981 ret = os_snprintf(pos, end - pos, "%d\t%s",
1983 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
1984 if (ret < 0 || ret >= end - pos)
1987 if (ssid->bssid_set) {
1988 ret = os_snprintf(pos, end - pos, "\t" MACSTR,
1989 MAC2STR(ssid->bssid));
1991 ret = os_snprintf(pos, end - pos, "\tany");
1993 if (ret < 0 || ret >= end - pos)
1996 ret = os_snprintf(pos, end - pos, "\t%s%s%s%s",
1997 ssid == wpa_s->current_ssid ?
1999 ssid->disabled ? "[DISABLED]" : "",
2000 ssid->disabled_until.sec ?
2001 "[TEMP-DISABLED]" : "",
2002 ssid->disabled == 2 ? "[P2P-PERSISTENT]" :
2004 if (ret < 0 || ret >= end - pos)
2007 ret = os_snprintf(pos, end - pos, "\n");
2008 if (ret < 0 || ret >= end - pos)
2019 static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher)
2022 ret = os_snprintf(pos, end - pos, "-");
2023 if (ret < 0 || ret >= end - pos)
2026 ret = wpa_write_ciphers(pos, end, cipher, "+");
2034 static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
2035 const u8 *ie, size_t ie_len)
2037 struct wpa_ie_data data;
2041 ret = os_snprintf(pos, end - pos, "[%s-", proto);
2042 if (ret < 0 || ret >= end - pos)
2046 if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) {
2047 ret = os_snprintf(pos, end - pos, "?]");
2048 if (ret < 0 || ret >= end - pos)
2055 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
2056 ret = os_snprintf(pos, end - pos, "%sEAP",
2057 pos == start ? "" : "+");
2058 if (ret < 0 || ret >= end - pos)
2062 if (data.key_mgmt & WPA_KEY_MGMT_PSK) {
2063 ret = os_snprintf(pos, end - pos, "%sPSK",
2064 pos == start ? "" : "+");
2065 if (ret < 0 || ret >= end - pos)
2069 if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
2070 ret = os_snprintf(pos, end - pos, "%sNone",
2071 pos == start ? "" : "+");
2072 if (ret < 0 || ret >= end - pos)
2076 #ifdef CONFIG_IEEE80211R
2077 if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
2078 ret = os_snprintf(pos, end - pos, "%sFT/EAP",
2079 pos == start ? "" : "+");
2080 if (ret < 0 || ret >= end - pos)
2084 if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) {
2085 ret = os_snprintf(pos, end - pos, "%sFT/PSK",
2086 pos == start ? "" : "+");
2087 if (ret < 0 || ret >= end - pos)
2091 #endif /* CONFIG_IEEE80211R */
2092 #ifdef CONFIG_IEEE80211W
2093 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
2094 ret = os_snprintf(pos, end - pos, "%sEAP-SHA256",
2095 pos == start ? "" : "+");
2096 if (ret < 0 || ret >= end - pos)
2100 if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
2101 ret = os_snprintf(pos, end - pos, "%sPSK-SHA256",
2102 pos == start ? "" : "+");
2103 if (ret < 0 || ret >= end - pos)
2107 #endif /* CONFIG_IEEE80211W */
2109 pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher);
2111 if (data.capabilities & WPA_CAPABILITY_PREAUTH) {
2112 ret = os_snprintf(pos, end - pos, "-preauth");
2113 if (ret < 0 || ret >= end - pos)
2118 ret = os_snprintf(pos, end - pos, "]");
2119 if (ret < 0 || ret >= end - pos)
2128 static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s,
2129 char *pos, char *end,
2130 struct wpabuf *wps_ie)
2137 if (wps_is_selected_pbc_registrar(wps_ie))
2139 else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0))
2141 else if (wps_is_selected_pin_registrar(wps_ie))
2146 ret = os_snprintf(pos, end - pos, "%s", txt);
2147 if (ret >= 0 && ret < end - pos)
2149 wpabuf_free(wps_ie);
2152 #endif /* CONFIG_WPS */
2155 static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s,
2156 char *pos, char *end,
2157 const struct wpa_bss *bss)
2160 struct wpabuf *wps_ie;
2161 wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
2162 return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie);
2163 #else /* CONFIG_WPS */
2165 #endif /* CONFIG_WPS */
2169 /* Format one result on one text line into a buffer. */
2170 static int wpa_supplicant_ctrl_iface_scan_result(
2171 struct wpa_supplicant *wpa_s,
2172 const struct wpa_bss *bss, char *buf, size_t buflen)
2176 const u8 *ie, *ie2, *p2p;
2178 p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
2180 p2p = wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE);
2181 if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN &&
2182 os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) ==
2184 return 0; /* Do not show P2P listen discovery results here */
2189 ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t",
2190 MAC2STR(bss->bssid), bss->freq, bss->level);
2191 if (ret < 0 || ret >= end - pos)
2194 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
2196 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]);
2197 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
2199 pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2, 2 + ie2[1]);
2200 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
2201 if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
2202 ret = os_snprintf(pos, end - pos, "[WEP]");
2203 if (ret < 0 || ret >= end - pos)
2207 if (bss_is_dmg(bss)) {
2209 ret = os_snprintf(pos, end - pos, "[DMG]");
2210 if (ret < 0 || ret >= end - pos)
2213 switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
2214 case IEEE80211_CAP_DMG_IBSS:
2217 case IEEE80211_CAP_DMG_AP:
2220 case IEEE80211_CAP_DMG_PBSS:
2227 ret = os_snprintf(pos, end - pos, "%s", s);
2228 if (ret < 0 || ret >= end - pos)
2232 if (bss->caps & IEEE80211_CAP_IBSS) {
2233 ret = os_snprintf(pos, end - pos, "[IBSS]");
2234 if (ret < 0 || ret >= end - pos)
2238 if (bss->caps & IEEE80211_CAP_ESS) {
2239 ret = os_snprintf(pos, end - pos, "[ESS]");
2240 if (ret < 0 || ret >= end - pos)
2246 ret = os_snprintf(pos, end - pos, "[P2P]");
2247 if (ret < 0 || ret >= end - pos)
2252 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE) && ie2) {
2253 ret = os_snprintf(pos, end - pos, "[HS20]");
2254 if (ret < 0 || ret >= end - pos)
2258 #endif /* CONFIG_HS20 */
2260 ret = os_snprintf(pos, end - pos, "\t%s",
2261 wpa_ssid_txt(bss->ssid, bss->ssid_len));
2262 if (ret < 0 || ret >= end - pos)
2266 ret = os_snprintf(pos, end - pos, "\n");
2267 if (ret < 0 || ret >= end - pos)
2275 static int wpa_supplicant_ctrl_iface_scan_results(
2276 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
2279 struct wpa_bss *bss;
2284 ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / "
2286 if (ret < 0 || ret >= end - pos)
2290 dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
2291 ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos,
2293 if (ret < 0 || ret >= end - pos)
2302 static int wpa_supplicant_ctrl_iface_select_network(
2303 struct wpa_supplicant *wpa_s, char *cmd)
2306 struct wpa_ssid *ssid;
2309 /* cmd: "<network id>" or "any" */
2310 if (os_strncmp(cmd, "any", 3) == 0) {
2311 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any");
2315 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id);
2317 ssid = wpa_config_get_network(wpa_s->conf, id);
2319 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2320 "network id=%d", id);
2323 if (ssid->disabled == 2) {
2324 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2325 "SELECT_NETWORK with persistent P2P group");
2330 pos = os_strstr(cmd, " freq=");
2332 int *freqs = freq_range_to_channel_list(wpa_s, pos + 6);
2334 wpa_s->scan_req = MANUAL_SCAN_REQ;
2335 os_free(wpa_s->manual_scan_freqs);
2336 wpa_s->manual_scan_freqs = freqs;
2340 wpa_supplicant_select_network(wpa_s, ssid);
2346 static int wpa_supplicant_ctrl_iface_enable_network(
2347 struct wpa_supplicant *wpa_s, char *cmd)
2350 struct wpa_ssid *ssid;
2352 /* cmd: "<network id>" or "all" */
2353 if (os_strcmp(cmd, "all") == 0) {
2354 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all");
2358 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id);
2360 ssid = wpa_config_get_network(wpa_s->conf, id);
2362 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2363 "network id=%d", id);
2366 if (ssid->disabled == 2) {
2367 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2368 "ENABLE_NETWORK with persistent P2P group");
2372 if (os_strstr(cmd, " no-connect")) {
2377 wpa_supplicant_enable_network(wpa_s, ssid);
2383 static int wpa_supplicant_ctrl_iface_disable_network(
2384 struct wpa_supplicant *wpa_s, char *cmd)
2387 struct wpa_ssid *ssid;
2389 /* cmd: "<network id>" or "all" */
2390 if (os_strcmp(cmd, "all") == 0) {
2391 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all");
2395 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id);
2397 ssid = wpa_config_get_network(wpa_s->conf, id);
2399 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2400 "network id=%d", id);
2403 if (ssid->disabled == 2) {
2404 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2405 "DISABLE_NETWORK with persistent P2P "
2410 wpa_supplicant_disable_network(wpa_s, ssid);
2416 static int wpa_supplicant_ctrl_iface_add_network(
2417 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
2419 struct wpa_ssid *ssid;
2422 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK");
2424 ssid = wpa_config_add_network(wpa_s->conf);
2428 wpas_notify_network_added(wpa_s, ssid);
2431 wpa_config_set_network_defaults(ssid);
2433 ret = os_snprintf(buf, buflen, "%d\n", ssid->id);
2434 if (ret < 0 || (size_t) ret >= buflen)
2440 static int wpa_supplicant_ctrl_iface_remove_network(
2441 struct wpa_supplicant *wpa_s, char *cmd)
2444 struct wpa_ssid *ssid;
2447 /* cmd: "<network id>" or "all" */
2448 if (os_strcmp(cmd, "all") == 0) {
2449 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all");
2450 if (wpa_s->sched_scanning)
2451 wpa_supplicant_cancel_sched_scan(wpa_s);
2453 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2454 if (wpa_s->current_ssid) {
2456 wpa_s->sme.prev_bssid_set = 0;
2457 #endif /* CONFIG_SME */
2458 wpa_sm_set_config(wpa_s->wpa, NULL);
2459 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
2460 wpa_supplicant_deauthenticate(
2461 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2463 ssid = wpa_s->conf->ssid;
2465 struct wpa_ssid *remove_ssid = ssid;
2468 wpas_notify_network_removed(wpa_s, remove_ssid);
2469 wpa_config_remove_network(wpa_s->conf, id);
2475 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id);
2477 ssid = wpa_config_get_network(wpa_s->conf, id);
2479 wpas_notify_network_removed(wpa_s, ssid);
2481 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2486 if (ssid == wpa_s->current_ssid || wpa_s->current_ssid == NULL) {
2488 wpa_s->sme.prev_bssid_set = 0;
2489 #endif /* CONFIG_SME */
2491 * Invalidate the EAP session cache if the current or
2492 * previously used network is removed.
2494 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2497 if (ssid == wpa_s->current_ssid) {
2498 wpa_sm_set_config(wpa_s->wpa, NULL);
2499 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
2501 wpa_supplicant_deauthenticate(wpa_s,
2502 WLAN_REASON_DEAUTH_LEAVING);
2505 was_disabled = ssid->disabled;
2507 if (wpa_config_remove_network(wpa_s->conf, id) < 0) {
2508 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Not able to remove the "
2509 "network id=%d", id);
2513 if (!was_disabled && wpa_s->sched_scanning) {
2514 wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to remove "
2515 "network from filters");
2516 wpa_supplicant_cancel_sched_scan(wpa_s);
2517 wpa_supplicant_req_scan(wpa_s, 0, 0);
2524 static int wpa_supplicant_ctrl_iface_update_network(
2525 struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
2526 char *name, char *value)
2528 if (wpa_config_set(ssid, name, value, 0) < 0) {
2529 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network "
2530 "variable '%s'", name);
2534 if (os_strcmp(name, "bssid") != 0 &&
2535 os_strcmp(name, "priority") != 0)
2536 wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
2538 if (wpa_s->current_ssid == ssid || wpa_s->current_ssid == NULL) {
2540 * Invalidate the EAP session cache if anything in the current
2541 * or previously used configuration changes.
2543 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2546 if ((os_strcmp(name, "psk") == 0 &&
2547 value[0] == '"' && ssid->ssid_len) ||
2548 (os_strcmp(name, "ssid") == 0 && ssid->passphrase))
2549 wpa_config_update_psk(ssid);
2550 else if (os_strcmp(name, "priority") == 0)
2551 wpa_config_update_prio_list(wpa_s->conf);
2557 static int wpa_supplicant_ctrl_iface_set_network(
2558 struct wpa_supplicant *wpa_s, char *cmd)
2561 struct wpa_ssid *ssid;
2564 /* cmd: "<network id> <variable name> <value>" */
2565 name = os_strchr(cmd, ' ');
2570 value = os_strchr(name, ' ');
2576 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
2578 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
2579 (u8 *) value, os_strlen(value));
2581 ssid = wpa_config_get_network(wpa_s->conf, id);
2583 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2588 return wpa_supplicant_ctrl_iface_update_network(wpa_s, ssid, name,
2593 static int wpa_supplicant_ctrl_iface_get_network(
2594 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
2598 struct wpa_ssid *ssid;
2601 /* cmd: "<network id> <variable name>" */
2602 name = os_strchr(cmd, ' ');
2603 if (name == NULL || buflen == 0)
2608 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
2611 ssid = wpa_config_get_network(wpa_s->conf, id);
2613 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2618 value = wpa_config_get_no_key(ssid, name);
2619 if (value == NULL) {
2620 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
2621 "variable '%s'", name);
2625 res = os_strlcpy(buf, value, buflen);
2626 if (res >= buflen) {
2637 static int wpa_supplicant_ctrl_iface_dup_network(
2638 struct wpa_supplicant *wpa_s, char *cmd)
2640 struct wpa_ssid *ssid_s, *ssid_d;
2641 char *name, *id, *value;
2642 int id_s, id_d, ret;
2644 /* cmd: "<src network id> <dst network id> <variable name>" */
2645 id = os_strchr(cmd, ' ');
2650 name = os_strchr(id, ' ');
2657 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DUP_NETWORK id=%d -> %d name='%s'",
2660 ssid_s = wpa_config_get_network(wpa_s->conf, id_s);
2661 if (ssid_s == NULL) {
2662 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2663 "network id=%d", id_s);
2667 ssid_d = wpa_config_get_network(wpa_s->conf, id_d);
2668 if (ssid_d == NULL) {
2669 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2670 "network id=%d", id_s);
2674 value = wpa_config_get(ssid_s, name);
2675 if (value == NULL) {
2676 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
2677 "variable '%s'", name);
2681 ret = wpa_supplicant_ctrl_iface_update_network(wpa_s, ssid_d, name,
2690 static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant *wpa_s,
2691 char *buf, size_t buflen)
2694 struct wpa_cred *cred;
2699 ret = os_snprintf(pos, end - pos,
2700 "cred id / realm / username / domain / imsi\n");
2701 if (ret < 0 || ret >= end - pos)
2705 cred = wpa_s->conf->cred;
2707 ret = os_snprintf(pos, end - pos, "%d\t%s\t%s\t%s\t%s\n",
2708 cred->id, cred->realm ? cred->realm : "",
2709 cred->username ? cred->username : "",
2710 cred->domain ? cred->domain[0] : "",
2711 cred->imsi ? cred->imsi : "");
2712 if (ret < 0 || ret >= end - pos)
2723 static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant *wpa_s,
2724 char *buf, size_t buflen)
2726 struct wpa_cred *cred;
2729 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_CRED");
2731 cred = wpa_config_add_cred(wpa_s->conf);
2735 wpa_msg(wpa_s, MSG_INFO, CRED_ADDED "%d", cred->id);
2737 ret = os_snprintf(buf, buflen, "%d\n", cred->id);
2738 if (ret < 0 || (size_t) ret >= buflen)
2744 static int wpas_ctrl_remove_cred(struct wpa_supplicant *wpa_s,
2745 struct wpa_cred *cred)
2747 struct wpa_ssid *ssid;
2752 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred");
2757 if (wpa_config_remove_cred(wpa_s->conf, id) < 0) {
2758 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred");
2762 wpa_msg(wpa_s, MSG_INFO, CRED_REMOVED "%d", id);
2764 /* Remove any network entry created based on the removed credential */
2765 ssid = wpa_s->conf->ssid;
2767 if (ssid->parent_cred == cred) {
2768 wpa_printf(MSG_DEBUG, "Remove network id %d since it "
2769 "used the removed credential", ssid->id);
2770 os_snprintf(str, sizeof(str), "%d", ssid->id);
2772 wpa_supplicant_ctrl_iface_remove_network(wpa_s, str);
2781 static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s,
2785 struct wpa_cred *cred, *prev;
2787 /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or
2788 * "provisioning_sp=<FQDN> */
2789 if (os_strcmp(cmd, "all") == 0) {
2790 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED all");
2791 cred = wpa_s->conf->cred;
2795 wpas_ctrl_remove_cred(wpa_s, prev);
2800 if (os_strncmp(cmd, "sp_fqdn=", 8) == 0) {
2801 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
2803 cred = wpa_s->conf->cred;
2809 for (i = 0; i < prev->num_domain; i++) {
2810 if (os_strcmp(prev->domain[i], cmd + 8)
2813 wpas_ctrl_remove_cred(wpa_s, prev);
2821 if (os_strncmp(cmd, "provisioning_sp=", 16) == 0) {
2822 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'",
2824 cred = wpa_s->conf->cred;
2828 if (prev->provisioning_sp &&
2829 os_strcmp(prev->provisioning_sp, cmd + 16) == 0)
2830 wpas_ctrl_remove_cred(wpa_s, prev);
2836 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED id=%d", id);
2838 cred = wpa_config_get_cred(wpa_s->conf, id);
2839 return wpas_ctrl_remove_cred(wpa_s, cred);
2843 static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant *wpa_s,
2847 struct wpa_cred *cred;
2850 /* cmd: "<cred id> <variable name> <value>" */
2851 name = os_strchr(cmd, ' ');
2856 value = os_strchr(name, ' ');
2862 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_CRED id=%d name='%s'",
2864 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
2865 (u8 *) value, os_strlen(value));
2867 cred = wpa_config_get_cred(wpa_s->conf, id);
2869 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
2874 if (wpa_config_set_cred(cred, name, value, 0) < 0) {
2875 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set cred "
2876 "variable '%s'", name);
2880 wpa_msg(wpa_s, MSG_INFO, CRED_MODIFIED "%d %s", cred->id, name);
2886 static int wpa_supplicant_ctrl_iface_get_cred(struct wpa_supplicant *wpa_s,
2887 char *cmd, char *buf,
2892 struct wpa_cred *cred;
2895 /* cmd: "<cred id> <variable name>" */
2896 name = os_strchr(cmd, ' ');
2902 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CRED id=%d name='%s'",
2905 cred = wpa_config_get_cred(wpa_s->conf, id);
2907 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
2912 value = wpa_config_get_cred_no_key(cred, name);
2913 if (value == NULL) {
2914 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get cred variable '%s'",
2919 res = os_strlcpy(buf, value, buflen);
2920 if (res >= buflen) {
2931 #ifndef CONFIG_NO_CONFIG_WRITE
2932 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s)
2936 if (!wpa_s->conf->update_config) {
2937 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
2938 "to update configuration (update_config=0)");
2942 ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
2944 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to "
2945 "update configuration");
2947 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration"
2953 #endif /* CONFIG_NO_CONFIG_WRITE */
2956 struct cipher_info {
2962 static const struct cipher_info ciphers[] = {
2963 { WPA_DRIVER_CAPA_ENC_CCMP_256, "CCMP-256", 0 },
2964 { WPA_DRIVER_CAPA_ENC_GCMP_256, "GCMP-256", 0 },
2965 { WPA_DRIVER_CAPA_ENC_CCMP, "CCMP", 0 },
2966 { WPA_DRIVER_CAPA_ENC_GCMP, "GCMP", 0 },
2967 { WPA_DRIVER_CAPA_ENC_TKIP, "TKIP", 0 },
2968 { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE, "NONE", 0 },
2969 { WPA_DRIVER_CAPA_ENC_WEP104, "WEP104", 1 },
2970 { WPA_DRIVER_CAPA_ENC_WEP40, "WEP40", 1 }
2974 static int ctrl_iface_get_capability_pairwise(int res, char *strict,
2975 struct wpa_driver_capa *capa,
2976 char *buf, size_t buflen)
2989 len = os_strlcpy(buf, "CCMP TKIP NONE", buflen);
2995 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
2996 if (!ciphers[i].group_only && capa->enc & ciphers[i].capa) {
2997 ret = os_snprintf(pos, end - pos, "%s%s",
2998 pos == buf ? "" : " ",
3000 if (ret < 0 || ret >= end - pos)
3010 static int ctrl_iface_get_capability_group(int res, char *strict,
3011 struct wpa_driver_capa *capa,
3012 char *buf, size_t buflen)
3025 len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen);
3031 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
3032 if (capa->enc & ciphers[i].capa) {
3033 ret = os_snprintf(pos, end - pos, "%s%s",
3034 pos == buf ? "" : " ",
3036 if (ret < 0 || ret >= end - pos)
3046 static int ctrl_iface_get_capability_key_mgmt(int res, char *strict,
3047 struct wpa_driver_capa *capa,
3048 char *buf, size_t buflen)
3060 len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
3067 ret = os_snprintf(pos, end - pos, "NONE IEEE8021X");
3068 if (ret < 0 || ret >= end - pos)
3072 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
3073 WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
3074 ret = os_snprintf(pos, end - pos, " WPA-EAP");
3075 if (ret < 0 || ret >= end - pos)
3080 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
3081 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
3082 ret = os_snprintf(pos, end - pos, " WPA-PSK");
3083 if (ret < 0 || ret >= end - pos)
3088 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
3089 ret = os_snprintf(pos, end - pos, " WPA-NONE");
3090 if (ret < 0 || ret >= end - pos)
3099 static int ctrl_iface_get_capability_proto(int res, char *strict,
3100 struct wpa_driver_capa *capa,
3101 char *buf, size_t buflen)
3113 len = os_strlcpy(buf, "RSN WPA", buflen);
3119 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
3120 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
3121 ret = os_snprintf(pos, end - pos, "%sRSN",
3122 pos == buf ? "" : " ");
3123 if (ret < 0 || ret >= end - pos)
3128 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
3129 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
3130 ret = os_snprintf(pos, end - pos, "%sWPA",
3131 pos == buf ? "" : " ");
3132 if (ret < 0 || ret >= end - pos)
3141 static int ctrl_iface_get_capability_auth_alg(int res, char *strict,
3142 struct wpa_driver_capa *capa,
3143 char *buf, size_t buflen)
3155 len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen);
3161 if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) {
3162 ret = os_snprintf(pos, end - pos, "%sOPEN",
3163 pos == buf ? "" : " ");
3164 if (ret < 0 || ret >= end - pos)
3169 if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) {
3170 ret = os_snprintf(pos, end - pos, "%sSHARED",
3171 pos == buf ? "" : " ");
3172 if (ret < 0 || ret >= end - pos)
3177 if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) {
3178 ret = os_snprintf(pos, end - pos, "%sLEAP",
3179 pos == buf ? "" : " ");
3180 if (ret < 0 || ret >= end - pos)
3189 static int ctrl_iface_get_capability_modes(int res, char *strict,
3190 struct wpa_driver_capa *capa,
3191 char *buf, size_t buflen)
3203 len = os_strlcpy(buf, "IBSS AP", buflen);
3209 if (capa->flags & WPA_DRIVER_FLAGS_IBSS) {
3210 ret = os_snprintf(pos, end - pos, "%sIBSS",
3211 pos == buf ? "" : " ");
3212 if (ret < 0 || ret >= end - pos)
3217 if (capa->flags & WPA_DRIVER_FLAGS_AP) {
3218 ret = os_snprintf(pos, end - pos, "%sAP",
3219 pos == buf ? "" : " ");
3220 if (ret < 0 || ret >= end - pos)
3229 static int ctrl_iface_get_capability_channels(struct wpa_supplicant *wpa_s,
3230 char *buf, size_t buflen)
3232 struct hostapd_channel_data *chnl;
3234 char *pos, *end, *hmode;
3239 for (j = 0; j < wpa_s->hw.num_modes; j++) {
3240 switch (wpa_s->hw.modes[j].mode) {
3241 case HOSTAPD_MODE_IEEE80211B:
3244 case HOSTAPD_MODE_IEEE80211G:
3247 case HOSTAPD_MODE_IEEE80211A:
3250 case HOSTAPD_MODE_IEEE80211AD:
3256 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:", hmode);
3257 if (ret < 0 || ret >= end - pos)
3260 chnl = wpa_s->hw.modes[j].channels;
3261 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
3262 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
3264 ret = os_snprintf(pos, end - pos, " %d", chnl[i].chan);
3265 if (ret < 0 || ret >= end - pos)
3269 ret = os_snprintf(pos, end - pos, "\n");
3270 if (ret < 0 || ret >= end - pos)
3279 static int ctrl_iface_get_capability_freq(struct wpa_supplicant *wpa_s,
3280 char *buf, size_t buflen)
3282 struct hostapd_channel_data *chnl;
3284 char *pos, *end, *hmode;
3289 for (j = 0; j < wpa_s->hw.num_modes; j++) {
3290 switch (wpa_s->hw.modes[j].mode) {
3291 case HOSTAPD_MODE_IEEE80211B:
3294 case HOSTAPD_MODE_IEEE80211G:
3297 case HOSTAPD_MODE_IEEE80211A:
3300 case HOSTAPD_MODE_IEEE80211AD:
3306 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:\n",
3308 if (ret < 0 || ret >= end - pos)
3311 chnl = wpa_s->hw.modes[j].channels;
3312 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
3313 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
3315 ret = os_snprintf(pos, end - pos, " %d = %d MHz%s%s\n",
3316 chnl[i].chan, chnl[i].freq,
3317 chnl[i].flag & HOSTAPD_CHAN_NO_IBSS ?
3319 chnl[i].flag & HOSTAPD_CHAN_RADAR ?
3322 if (ret < 0 || ret >= end - pos)
3326 ret = os_snprintf(pos, end - pos, "\n");
3327 if (ret < 0 || ret >= end - pos)
3336 static int wpa_supplicant_ctrl_iface_get_capability(
3337 struct wpa_supplicant *wpa_s, const char *_field, char *buf,
3340 struct wpa_driver_capa capa;
3346 /* Determine whether or not strict checking was requested */
3347 len = os_strlcpy(field, _field, sizeof(field));
3348 if (len >= sizeof(field))
3350 strict = os_strchr(field, ' ');
3351 if (strict != NULL) {
3353 if (os_strcmp(strict, "strict") != 0)
3357 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
3358 field, strict ? strict : "");
3360 if (os_strcmp(field, "eap") == 0) {
3361 return eap_get_names(buf, buflen);
3364 res = wpa_drv_get_capa(wpa_s, &capa);
3366 if (os_strcmp(field, "pairwise") == 0)
3367 return ctrl_iface_get_capability_pairwise(res, strict, &capa,
3370 if (os_strcmp(field, "group") == 0)
3371 return ctrl_iface_get_capability_group(res, strict, &capa,
3374 if (os_strcmp(field, "key_mgmt") == 0)
3375 return ctrl_iface_get_capability_key_mgmt(res, strict, &capa,
3378 if (os_strcmp(field, "proto") == 0)
3379 return ctrl_iface_get_capability_proto(res, strict, &capa,
3382 if (os_strcmp(field, "auth_alg") == 0)
3383 return ctrl_iface_get_capability_auth_alg(res, strict, &capa,
3386 if (os_strcmp(field, "modes") == 0)
3387 return ctrl_iface_get_capability_modes(res, strict, &capa,
3390 if (os_strcmp(field, "channels") == 0)
3391 return ctrl_iface_get_capability_channels(wpa_s, buf, buflen);
3393 if (os_strcmp(field, "freq") == 0)
3394 return ctrl_iface_get_capability_freq(wpa_s, buf, buflen);
3397 if (os_strcmp(field, "tdls") == 0)
3398 return ctrl_iface_get_capability_tdls(wpa_s, buf, buflen);
3399 #endif /* CONFIG_TDLS */
3401 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
3408 #ifdef CONFIG_INTERWORKING
3409 static char * anqp_add_hex(char *pos, char *end, const char *title,
3410 struct wpabuf *data)
3420 ret = os_snprintf(pos, end - pos, "%s=", title);
3421 if (ret < 0 || ret >= end - pos)
3425 d = wpabuf_head_u8(data);
3426 for (i = 0; i < wpabuf_len(data); i++) {
3427 ret = os_snprintf(pos, end - pos, "%02x", *d++);
3428 if (ret < 0 || ret >= end - pos)
3433 ret = os_snprintf(pos, end - pos, "\n");
3434 if (ret < 0 || ret >= end - pos)
3440 #endif /* CONFIG_INTERWORKING */
3443 static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
3444 unsigned long mask, char *buf, size_t buflen)
3454 if (mask & WPA_BSS_MASK_ID) {
3455 ret = os_snprintf(pos, end - pos, "id=%u\n", bss->id);
3456 if (ret < 0 || ret >= end - pos)
3461 if (mask & WPA_BSS_MASK_BSSID) {
3462 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
3463 MAC2STR(bss->bssid));
3464 if (ret < 0 || ret >= end - pos)
3469 if (mask & WPA_BSS_MASK_FREQ) {
3470 ret = os_snprintf(pos, end - pos, "freq=%d\n", bss->freq);
3471 if (ret < 0 || ret >= end - pos)
3476 if (mask & WPA_BSS_MASK_BEACON_INT) {
3477 ret = os_snprintf(pos, end - pos, "beacon_int=%d\n",
3479 if (ret < 0 || ret >= end - pos)
3484 if (mask & WPA_BSS_MASK_CAPABILITIES) {
3485 ret = os_snprintf(pos, end - pos, "capabilities=0x%04x\n",
3487 if (ret < 0 || ret >= end - pos)
3492 if (mask & WPA_BSS_MASK_QUAL) {
3493 ret = os_snprintf(pos, end - pos, "qual=%d\n", bss->qual);
3494 if (ret < 0 || ret >= end - pos)
3499 if (mask & WPA_BSS_MASK_NOISE) {
3500 ret = os_snprintf(pos, end - pos, "noise=%d\n", bss->noise);
3501 if (ret < 0 || ret >= end - pos)
3506 if (mask & WPA_BSS_MASK_LEVEL) {
3507 ret = os_snprintf(pos, end - pos, "level=%d\n", bss->level);
3508 if (ret < 0 || ret >= end - pos)
3513 if (mask & WPA_BSS_MASK_TSF) {
3514 ret = os_snprintf(pos, end - pos, "tsf=%016llu\n",
3515 (unsigned long long) bss->tsf);
3516 if (ret < 0 || ret >= end - pos)
3521 if (mask & WPA_BSS_MASK_AGE) {
3522 struct os_reltime now;
3524 os_get_reltime(&now);
3525 ret = os_snprintf(pos, end - pos, "age=%d\n",
3526 (int) (now.sec - bss->last_update.sec));
3527 if (ret < 0 || ret >= end - pos)
3532 if (mask & WPA_BSS_MASK_IE) {
3533 ret = os_snprintf(pos, end - pos, "ie=");
3534 if (ret < 0 || ret >= end - pos)
3538 ie = (const u8 *) (bss + 1);
3539 for (i = 0; i < bss->ie_len; i++) {
3540 ret = os_snprintf(pos, end - pos, "%02x", *ie++);
3541 if (ret < 0 || ret >= end - pos)
3546 ret = os_snprintf(pos, end - pos, "\n");
3547 if (ret < 0 || ret >= end - pos)
3552 if (mask & WPA_BSS_MASK_FLAGS) {
3553 ret = os_snprintf(pos, end - pos, "flags=");
3554 if (ret < 0 || ret >= end - pos)
3558 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
3560 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie,
3562 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
3564 pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2,
3566 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
3567 if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
3568 ret = os_snprintf(pos, end - pos, "[WEP]");
3569 if (ret < 0 || ret >= end - pos)
3573 if (bss_is_dmg(bss)) {
3575 ret = os_snprintf(pos, end - pos, "[DMG]");
3576 if (ret < 0 || ret >= end - pos)
3579 switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
3580 case IEEE80211_CAP_DMG_IBSS:
3583 case IEEE80211_CAP_DMG_AP:
3586 case IEEE80211_CAP_DMG_PBSS:
3593 ret = os_snprintf(pos, end - pos, "%s", s);
3594 if (ret < 0 || ret >= end - pos)
3598 if (bss->caps & IEEE80211_CAP_IBSS) {
3599 ret = os_snprintf(pos, end - pos, "[IBSS]");
3600 if (ret < 0 || ret >= end - pos)
3604 if (bss->caps & IEEE80211_CAP_ESS) {
3605 ret = os_snprintf(pos, end - pos, "[ESS]");
3606 if (ret < 0 || ret >= end - pos)
3611 if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
3612 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
3613 ret = os_snprintf(pos, end - pos, "[P2P]");
3614 if (ret < 0 || ret >= end - pos)
3619 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) {
3620 ret = os_snprintf(pos, end - pos, "[HS20]");
3621 if (ret < 0 || ret >= end - pos)
3625 #endif /* CONFIG_HS20 */
3627 ret = os_snprintf(pos, end - pos, "\n");
3628 if (ret < 0 || ret >= end - pos)
3633 if (mask & WPA_BSS_MASK_SSID) {
3634 ret = os_snprintf(pos, end - pos, "ssid=%s\n",
3635 wpa_ssid_txt(bss->ssid, bss->ssid_len));
3636 if (ret < 0 || ret >= end - pos)
3642 if (mask & WPA_BSS_MASK_WPS_SCAN) {
3643 ie = (const u8 *) (bss + 1);
3644 ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end);
3645 if (ret < 0 || ret >= end - pos)
3649 #endif /* CONFIG_WPS */
3652 if (mask & WPA_BSS_MASK_P2P_SCAN) {
3653 ie = (const u8 *) (bss + 1);
3654 ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end);
3655 if (ret < 0 || ret >= end - pos)
3659 #endif /* CONFIG_P2P */
3661 #ifdef CONFIG_WIFI_DISPLAY
3662 if (mask & WPA_BSS_MASK_WIFI_DISPLAY) {
3664 ie = (const u8 *) (bss + 1);
3665 wfd = ieee802_11_vendor_ie_concat(ie, bss->ie_len,
3666 WFD_IE_VENDOR_TYPE);
3668 ret = os_snprintf(pos, end - pos, "wfd_subelems=");
3669 if (ret < 0 || ret >= end - pos) {
3675 pos += wpa_snprintf_hex(pos, end - pos,
3680 ret = os_snprintf(pos, end - pos, "\n");
3681 if (ret < 0 || ret >= end - pos)
3686 #endif /* CONFIG_WIFI_DISPLAY */
3688 #ifdef CONFIG_INTERWORKING
3689 if ((mask & WPA_BSS_MASK_INTERNETW) && bss->anqp) {
3690 struct wpa_bss_anqp *anqp = bss->anqp;
3691 pos = anqp_add_hex(pos, end, "anqp_venue_name",
3693 pos = anqp_add_hex(pos, end, "anqp_network_auth_type",
3694 anqp->network_auth_type);
3695 pos = anqp_add_hex(pos, end, "anqp_roaming_consortium",
3696 anqp->roaming_consortium);
3697 pos = anqp_add_hex(pos, end, "anqp_ip_addr_type_availability",
3698 anqp->ip_addr_type_availability);
3699 pos = anqp_add_hex(pos, end, "anqp_nai_realm",
3701 pos = anqp_add_hex(pos, end, "anqp_3gpp", anqp->anqp_3gpp);
3702 pos = anqp_add_hex(pos, end, "anqp_domain_name",
3705 pos = anqp_add_hex(pos, end, "hs20_operator_friendly_name",
3706 anqp->hs20_operator_friendly_name);
3707 pos = anqp_add_hex(pos, end, "hs20_wan_metrics",
3708 anqp->hs20_wan_metrics);
3709 pos = anqp_add_hex(pos, end, "hs20_connection_capability",
3710 anqp->hs20_connection_capability);
3711 pos = anqp_add_hex(pos, end, "hs20_operating_class",
3712 anqp->hs20_operating_class);
3713 pos = anqp_add_hex(pos, end, "hs20_osu_providers_list",
3714 anqp->hs20_osu_providers_list);
3715 #endif /* CONFIG_HS20 */
3717 #endif /* CONFIG_INTERWORKING */
3719 if (mask & WPA_BSS_MASK_DELIM) {
3720 ret = os_snprintf(pos, end - pos, "====\n");
3721 if (ret < 0 || ret >= end - pos)
3730 static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
3731 const char *cmd, char *buf,
3736 struct wpa_bss *bss;
3737 struct wpa_bss *bsslast = NULL;
3738 struct dl_list *next;
3742 unsigned long mask = WPA_BSS_MASK_ALL;
3744 if (os_strncmp(cmd, "RANGE=", 6) == 0) {
3745 if (os_strncmp(cmd + 6, "ALL", 3) == 0) {
3746 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss,
3748 bsslast = dl_list_last(&wpa_s->bss_id, struct wpa_bss,
3750 } else { /* N1-N2 */
3751 unsigned int id1, id2;
3753 if ((ctmp = os_strchr(cmd + 6, '-')) == NULL) {
3754 wpa_printf(MSG_INFO, "Wrong BSS range "
3759 if (*(cmd + 6) == '-')
3762 id1 = atoi(cmd + 6);
3764 if (*ctmp >= '0' && *ctmp <= '9')
3767 id2 = (unsigned int) -1;
3768 bss = wpa_bss_get_id_range(wpa_s, id1, id2);
3769 if (id2 == (unsigned int) -1)
3770 bsslast = dl_list_last(&wpa_s->bss_id,
3774 bsslast = wpa_bss_get_id(wpa_s, id2);
3775 if (bsslast == NULL && bss && id2 > id1) {
3776 struct wpa_bss *tmp = bss;
3778 next = tmp->list_id.next;
3779 if (next == &wpa_s->bss_id)
3781 tmp = dl_list_entry(
3782 next, struct wpa_bss,
3791 } else if (os_strncmp(cmd, "FIRST", 5) == 0)
3792 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, list_id);
3793 else if (os_strncmp(cmd, "LAST", 4) == 0)
3794 bss = dl_list_last(&wpa_s->bss_id, struct wpa_bss, list_id);
3795 else if (os_strncmp(cmd, "ID-", 3) == 0) {
3797 bss = wpa_bss_get_id(wpa_s, i);
3798 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
3800 bss = wpa_bss_get_id(wpa_s, i);
3802 next = bss->list_id.next;
3803 if (next == &wpa_s->bss_id)
3806 bss = dl_list_entry(next, struct wpa_bss,
3810 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
3811 if (hwaddr_aton(cmd + 13, bssid) == 0)
3812 bss = wpa_bss_get_p2p_dev_addr(wpa_s, bssid);
3815 #endif /* CONFIG_P2P */
3816 } else if (hwaddr_aton(cmd, bssid) == 0)
3817 bss = wpa_bss_get_bssid(wpa_s, bssid);
3819 struct wpa_bss *tmp;
3822 dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id)
3831 if ((ctmp = os_strstr(cmd, "MASK=")) != NULL) {
3832 mask = strtoul(ctmp + 5, NULL, 0x10);
3834 mask = WPA_BSS_MASK_ALL;
3840 if (bsslast == NULL)
3843 len = print_bss_info(wpa_s, bss, mask, buf, buflen);
3847 if (bss == bsslast) {
3848 if ((mask & WPA_BSS_MASK_DELIM) && len &&
3849 (bss == dl_list_last(&wpa_s->bss_id,
3850 struct wpa_bss, list_id)))
3851 os_snprintf(buf - 5, 5, "####\n");
3854 next = bss->list_id.next;
3855 if (next == &wpa_s->bss_id)
3857 bss = dl_list_entry(next, struct wpa_bss, list_id);
3858 } while (bss && len);
3864 static int wpa_supplicant_ctrl_iface_ap_scan(
3865 struct wpa_supplicant *wpa_s, char *cmd)
3867 int ap_scan = atoi(cmd);
3868 return wpa_supplicant_set_ap_scan(wpa_s, ap_scan);
3872 static int wpa_supplicant_ctrl_iface_scan_interval(
3873 struct wpa_supplicant *wpa_s, char *cmd)
3875 int scan_int = atoi(cmd);
3876 return wpa_supplicant_set_scan_interval(wpa_s, scan_int);
3880 static int wpa_supplicant_ctrl_iface_bss_expire_age(
3881 struct wpa_supplicant *wpa_s, char *cmd)
3883 int expire_age = atoi(cmd);
3884 return wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age);
3888 static int wpa_supplicant_ctrl_iface_bss_expire_count(
3889 struct wpa_supplicant *wpa_s, char *cmd)
3891 int expire_count = atoi(cmd);
3892 return wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count);
3896 static int wpa_supplicant_ctrl_iface_bss_flush(
3897 struct wpa_supplicant *wpa_s, char *cmd)
3899 int flush_age = atoi(cmd);
3902 wpa_bss_flush(wpa_s);
3904 wpa_bss_flush_by_age(wpa_s, flush_age);
3909 #ifdef CONFIG_TESTING_OPTIONS
3910 static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s)
3912 wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication");
3913 /* MLME-DELETEKEYS.request */
3914 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL, 0);
3915 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL, 0);
3916 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL, 0);
3917 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL, 0);
3918 #ifdef CONFIG_IEEE80211W
3919 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL, 0);
3920 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL, 0);
3921 #endif /* CONFIG_IEEE80211W */
3923 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, wpa_s->bssid, 0, 0, NULL, 0, NULL,
3925 /* MLME-SETPROTECTION.request(None) */
3926 wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid,
3927 MLME_SETPROTECTION_PROTECT_TYPE_NONE,
3928 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE);
3929 wpa_sm_drop_sa(wpa_s->wpa);
3931 #endif /* CONFIG_TESTING_OPTIONS */
3934 static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s,
3937 #ifdef CONFIG_NO_SCAN_PROCESSING
3939 #else /* CONFIG_NO_SCAN_PROCESSING */
3941 struct wpa_bss *bss;
3942 struct wpa_ssid *ssid = wpa_s->current_ssid;
3944 if (hwaddr_aton(addr, bssid)) {
3945 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid "
3946 "address '%s'", addr);
3950 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR, MAC2STR(bssid));
3953 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network "
3954 "configuration known for the target AP");
3958 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
3960 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found "
3966 * TODO: Find best network configuration block from configuration to
3967 * allow roaming to other networks
3970 wpa_s->reassociate = 1;
3971 wpa_supplicant_connect(wpa_s, bss, ssid);
3974 #endif /* CONFIG_NO_SCAN_PROCESSING */
3979 static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd)
3981 unsigned int timeout = atoi(cmd);
3982 enum p2p_discovery_type type = P2P_FIND_START_WITH_FULL;
3983 u8 dev_id[ETH_ALEN], *_dev_id = NULL;
3984 u8 dev_type[WPS_DEV_TYPE_LEN], *_dev_type = NULL;
3986 unsigned int search_delay;
3988 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
3989 wpa_dbg(wpa_s, MSG_INFO,
3990 "Reject P2P_FIND since interface is disabled");
3993 if (os_strstr(cmd, "type=social"))
3994 type = P2P_FIND_ONLY_SOCIAL;
3995 else if (os_strstr(cmd, "type=progressive"))
3996 type = P2P_FIND_PROGRESSIVE;
3998 pos = os_strstr(cmd, "dev_id=");
4001 if (hwaddr_aton(pos, dev_id))
4006 pos = os_strstr(cmd, "dev_type=");
4009 if (wps_dev_type_str2bin(pos, dev_type) < 0)
4011 _dev_type = dev_type;
4014 pos = os_strstr(cmd, "delay=");
4017 search_delay = atoi(pos);
4019 search_delay = wpas_p2p_search_delay(wpa_s);
4021 return wpas_p2p_find(wpa_s, timeout, type, _dev_type != NULL, _dev_type,
4022 _dev_id, search_delay);
4026 static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd,
4027 char *buf, size_t buflen)
4032 enum p2p_wps_method wps_method;
4035 int persistent_group, persistent_id = -1;
4044 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad]
4045 * [persistent|persistent=<network id>]
4046 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
4049 if (hwaddr_aton(cmd, addr))
4057 persistent_group = os_strstr(pos, " persistent") != NULL;
4058 pos2 = os_strstr(pos, " persistent=");
4060 struct wpa_ssid *ssid;
4061 persistent_id = atoi(pos2 + 12);
4062 ssid = wpa_config_get_network(wpa_s->conf, persistent_id);
4063 if (ssid == NULL || ssid->disabled != 2 ||
4064 ssid->mode != WPAS_MODE_P2P_GO) {
4065 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
4066 "SSID id=%d for persistent P2P group (GO)",
4071 join = os_strstr(pos, " join") != NULL;
4072 auth = os_strstr(pos, " auth") != NULL;
4073 automatic = os_strstr(pos, " auto") != NULL;
4074 pd = os_strstr(pos, " provdisc") != NULL;
4075 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
4076 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
4079 pos2 = os_strstr(pos, " go_intent=");
4082 go_intent = atoi(pos2);
4083 if (go_intent < 0 || go_intent > 15)
4087 pos2 = os_strstr(pos, " freq=");
4095 if (os_strncmp(pos, "pin", 3) == 0) {
4096 /* Request random PIN (to be displayed) and enable the PIN */
4097 wps_method = WPS_PIN_DISPLAY;
4098 } else if (os_strncmp(pos, "pbc", 3) == 0) {
4099 wps_method = WPS_PBC;
4102 pos = os_strchr(pin, ' ');
4103 wps_method = WPS_PIN_KEYPAD;
4106 if (os_strncmp(pos, "display", 7) == 0)
4107 wps_method = WPS_PIN_DISPLAY;
4109 if (!wps_pin_str_valid(pin)) {
4110 os_memcpy(buf, "FAIL-INVALID-PIN\n", 17);
4115 new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method,
4116 persistent_group, automatic, join,
4117 auth, go_intent, freq, persistent_id, pd,
4119 if (new_pin == -2) {
4120 os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
4123 if (new_pin == -3) {
4124 os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
4129 if (wps_method == WPS_PIN_DISPLAY && pin == NULL) {
4130 ret = os_snprintf(buf, buflen, "%08d", new_pin);
4131 if (ret < 0 || (size_t) ret >= buflen)
4136 os_memcpy(buf, "OK\n", 3);
4141 static int p2p_ctrl_listen(struct wpa_supplicant *wpa_s, char *cmd)
4143 unsigned int timeout = atoi(cmd);
4144 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
4145 wpa_dbg(wpa_s, MSG_INFO,
4146 "Reject P2P_LISTEN since interface is disabled");
4149 return wpas_p2p_listen(wpa_s, timeout);
4153 static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd)
4157 enum wpas_p2p_prov_disc_use use = WPAS_P2P_PD_FOR_GO_NEG;
4159 /* <addr> <config method> [join|auto] */
4161 if (hwaddr_aton(cmd, addr))
4169 if (os_strstr(pos, " join") != NULL)
4170 use = WPAS_P2P_PD_FOR_JOIN;
4171 else if (os_strstr(pos, " auto") != NULL)
4172 use = WPAS_P2P_PD_AUTO;
4174 return wpas_p2p_prov_disc(wpa_s, addr, pos, use);
4178 static int p2p_get_passphrase(struct wpa_supplicant *wpa_s, char *buf,
4181 struct wpa_ssid *ssid = wpa_s->current_ssid;
4183 if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO ||
4184 ssid->passphrase == NULL)
4187 os_strlcpy(buf, ssid->passphrase, buflen);
4188 return os_strlen(buf);
4192 static int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd,
4193 char *buf, size_t buflen)
4197 u8 dst_buf[ETH_ALEN], *dst;
4198 struct wpabuf *tlvs;
4202 if (hwaddr_aton(cmd, dst_buf))
4205 if (dst[0] == 0 && dst[1] == 0 && dst[2] == 0 &&
4206 dst[3] == 0 && dst[4] == 0 && dst[5] == 0)
4213 if (os_strncmp(pos, "upnp ", 5) == 0) {
4216 if (hexstr2bin(pos, &version, 1) < 0)
4222 ref = wpas_p2p_sd_request_upnp(wpa_s, dst, version, pos);
4223 #ifdef CONFIG_WIFI_DISPLAY
4224 } else if (os_strncmp(pos, "wifi-display ", 13) == 0) {
4225 ref = wpas_p2p_sd_request_wifi_display(wpa_s, dst, pos + 13);
4226 #endif /* CONFIG_WIFI_DISPLAY */
4228 len = os_strlen(pos);
4232 tlvs = wpabuf_alloc(len);
4235 if (hexstr2bin(pos, wpabuf_put(tlvs, len), len) < 0) {
4240 ref = wpas_p2p_sd_request(wpa_s, dst, tlvs);
4245 res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref);
4246 if (res < 0 || (unsigned) res >= buflen)
4252 static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s,
4255 long long unsigned val;
4257 if (sscanf(cmd, "%llx", &val) != 1)
4260 return wpas_p2p_sd_cancel_request(wpa_s, req);
4264 static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant *wpa_s, char *cmd)
4269 struct wpabuf *resp_tlvs;
4273 pos = os_strchr(cmd, ' ');
4281 if (hwaddr_aton(pos, dst))
4288 pos2 = os_strchr(pos, ' ');
4292 dialog_token = atoi(pos);
4294 len = os_strlen(pos2);
4298 resp_tlvs = wpabuf_alloc(len);
4299 if (resp_tlvs == NULL)
4301 if (hexstr2bin(pos2, wpabuf_put(resp_tlvs, len), len) < 0) {
4302 wpabuf_free(resp_tlvs);
4306 wpas_p2p_sd_response(wpa_s, freq, dst, dialog_token, resp_tlvs);
4307 wpabuf_free(resp_tlvs);
4312 static int p2p_ctrl_serv_disc_external(struct wpa_supplicant *wpa_s,
4315 if (os_strcmp(cmd, "0") && os_strcmp(cmd, "1"))
4317 wpa_s->p2p_sd_over_ctrl_iface = atoi(cmd);
4322 static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant *wpa_s,
4327 struct wpabuf *query, *resp;
4329 pos = os_strchr(cmd, ' ');
4334 len = os_strlen(cmd);
4338 query = wpabuf_alloc(len);
4341 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
4346 len = os_strlen(pos);
4352 resp = wpabuf_alloc(len);
4357 if (hexstr2bin(pos, wpabuf_put(resp, len), len) < 0) {
4363 if (wpas_p2p_service_add_bonjour(wpa_s, query, resp) < 0) {
4372 static int p2p_ctrl_service_add_upnp(struct wpa_supplicant *wpa_s, char *cmd)
4377 pos = os_strchr(cmd, ' ');
4382 if (hexstr2bin(cmd, &version, 1) < 0)
4385 return wpas_p2p_service_add_upnp(wpa_s, version, pos);
4389 static int p2p_ctrl_service_add(struct wpa_supplicant *wpa_s, char *cmd)
4393 pos = os_strchr(cmd, ' ');
4398 if (os_strcmp(cmd, "bonjour") == 0)
4399 return p2p_ctrl_service_add_bonjour(wpa_s, pos);
4400 if (os_strcmp(cmd, "upnp") == 0)
4401 return p2p_ctrl_service_add_upnp(wpa_s, pos);
4402 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
4407 static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant *wpa_s,
4411 struct wpabuf *query;
4414 len = os_strlen(cmd);
4418 query = wpabuf_alloc(len);
4421 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
4426 ret = wpas_p2p_service_del_bonjour(wpa_s, query);
4432 static int p2p_ctrl_service_del_upnp(struct wpa_supplicant *wpa_s, char *cmd)
4437 pos = os_strchr(cmd, ' ');
4442 if (hexstr2bin(cmd, &version, 1) < 0)
4445 return wpas_p2p_service_del_upnp(wpa_s, version, pos);
4449 static int p2p_ctrl_service_del(struct wpa_supplicant *wpa_s, char *cmd)
4453 pos = os_strchr(cmd, ' ');
4458 if (os_strcmp(cmd, "bonjour") == 0)
4459 return p2p_ctrl_service_del_bonjour(wpa_s, pos);
4460 if (os_strcmp(cmd, "upnp") == 0)
4461 return p2p_ctrl_service_del_upnp(wpa_s, pos);
4462 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
4467 static int p2p_ctrl_reject(struct wpa_supplicant *wpa_s, char *cmd)
4473 if (hwaddr_aton(cmd, addr))
4476 return wpas_p2p_reject(wpa_s, addr);
4480 static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd)
4484 struct wpa_ssid *ssid;
4485 u8 *_peer = NULL, peer[ETH_ALEN];
4486 int freq = 0, pref_freq = 0;
4490 pos = os_strstr(cmd, " peer=");
4493 if (hwaddr_aton(pos, peer))
4497 ssid = wpa_config_get_network(wpa_s->conf, id);
4498 if (ssid == NULL || ssid->disabled != 2) {
4499 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
4500 "for persistent P2P group",
4505 pos = os_strstr(cmd, " freq=");
4513 pos = os_strstr(cmd, " pref=");
4516 pref_freq = atoi(pos);
4521 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
4522 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
4525 return wpas_p2p_invite(wpa_s, _peer, ssid, NULL, freq, ht40, vht,
4530 static int p2p_ctrl_invite_group(struct wpa_supplicant *wpa_s, char *cmd)
4533 u8 peer[ETH_ALEN], go_dev_addr[ETH_ALEN], *go_dev = NULL;
4535 pos = os_strstr(cmd, " peer=");
4541 if (hwaddr_aton(pos, peer)) {
4542 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", pos);
4546 pos = os_strstr(pos, " go_dev_addr=");
4549 if (hwaddr_aton(pos, go_dev_addr)) {
4550 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'",
4554 go_dev = go_dev_addr;
4557 return wpas_p2p_invite_group(wpa_s, cmd, peer, go_dev);
4561 static int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd)
4563 if (os_strncmp(cmd, "persistent=", 11) == 0)
4564 return p2p_ctrl_invite_persistent(wpa_s, cmd + 11);
4565 if (os_strncmp(cmd, "group=", 6) == 0)
4566 return p2p_ctrl_invite_group(wpa_s, cmd + 6);
4572 static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s,
4573 char *cmd, int freq, int ht40,
4577 struct wpa_ssid *ssid;
4580 ssid = wpa_config_get_network(wpa_s->conf, id);
4581 if (ssid == NULL || ssid->disabled != 2) {
4582 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
4583 "for persistent P2P group",
4588 return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq, 0, ht40, vht,
4593 static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd)
4595 int freq = 0, ht40, vht;
4598 pos = os_strstr(cmd, "freq=");
4600 freq = atoi(pos + 5);
4602 vht = (os_strstr(cmd, "vht") != NULL) || wpa_s->conf->p2p_go_vht;
4603 ht40 = (os_strstr(cmd, "ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
4606 if (os_strncmp(cmd, "persistent=", 11) == 0)
4607 return p2p_ctrl_group_add_persistent(wpa_s, cmd + 11, freq,
4609 if (os_strcmp(cmd, "persistent") == 0 ||
4610 os_strncmp(cmd, "persistent ", 11) == 0)
4611 return wpas_p2p_group_add(wpa_s, 1, freq, ht40, vht);
4612 if (os_strncmp(cmd, "freq=", 5) == 0)
4613 return wpas_p2p_group_add(wpa_s, 0, freq, ht40, vht);
4615 return wpas_p2p_group_add(wpa_s, 0, freq, ht40, vht);
4617 wpa_printf(MSG_DEBUG, "CTRL: Invalid P2P_GROUP_ADD parameters '%s'",
4623 static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd,
4624 char *buf, size_t buflen)
4626 u8 addr[ETH_ALEN], *addr_ptr;
4628 const struct p2p_peer_info *info;
4630 char devtype[WPS_DEV_TYPE_BUFSIZE];
4631 struct wpa_ssid *ssid;
4634 if (!wpa_s->global->p2p)
4637 if (os_strcmp(cmd, "FIRST") == 0) {
4640 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
4641 if (hwaddr_aton(cmd + 5, addr) < 0)
4646 if (hwaddr_aton(cmd, addr) < 0)
4652 info = p2p_get_peer_info(wpa_s->global->p2p, addr_ptr, next);
4659 res = os_snprintf(pos, end - pos, MACSTR "\n"
4665 "serial_number=%s\n"
4666 "config_methods=0x%x\n"
4668 "group_capab=0x%x\n"
4670 MAC2STR(info->p2p_device_addr),
4671 wps_dev_type_bin2str(info->pri_dev_type,
4672 devtype, sizeof(devtype)),
4677 info->serial_number,
4678 info->config_methods,
4682 if (res < 0 || res >= end - pos)
4686 for (i = 0; i < info->wps_sec_dev_type_list_len / WPS_DEV_TYPE_LEN; i++)
4689 t = &info->wps_sec_dev_type_list[i * WPS_DEV_TYPE_LEN];
4690 res = os_snprintf(pos, end - pos, "sec_dev_type=%s\n",
4691 wps_dev_type_bin2str(t, devtype,
4693 if (res < 0 || res >= end - pos)
4698 ssid = wpas_p2p_get_persistent(wpa_s, info->p2p_device_addr, NULL, 0);
4700 res = os_snprintf(pos, end - pos, "persistent=%d\n", ssid->id);
4701 if (res < 0 || res >= end - pos)
4706 res = p2p_get_peer_info_txt(info, pos, end - pos);
4715 static int p2p_ctrl_disallow_freq(struct wpa_supplicant *wpa_s,
4720 if (wpa_s->global->p2p == NULL)
4723 if (freq_range_list_parse(&wpa_s->global->p2p_disallow_freq, param) < 0)
4726 for (i = 0; i < wpa_s->global->p2p_disallow_freq.num; i++) {
4727 struct wpa_freq_range *freq;
4728 freq = &wpa_s->global->p2p_disallow_freq.range[i];
4729 wpa_printf(MSG_DEBUG, "P2P: Disallowed frequency range %u-%u",
4730 freq->min, freq->max);
4733 wpas_p2p_update_channel_list(wpa_s);
4738 static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd)
4742 if (wpa_s->global->p2p == NULL)
4745 param = os_strchr(cmd, ' ');
4750 if (os_strcmp(cmd, "discoverability") == 0) {
4751 p2p_set_client_discoverability(wpa_s->global->p2p,
4756 if (os_strcmp(cmd, "managed") == 0) {
4757 p2p_set_managed_oper(wpa_s->global->p2p, atoi(param));
4761 if (os_strcmp(cmd, "listen_channel") == 0) {
4762 return p2p_set_listen_channel(wpa_s->global->p2p, 81,
4766 if (os_strcmp(cmd, "ssid_postfix") == 0) {
4767 return p2p_set_ssid_postfix(wpa_s->global->p2p, (u8 *) param,
4771 if (os_strcmp(cmd, "noa") == 0) {
4773 int count, start, duration;
4774 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
4775 count = atoi(param);
4776 pos = os_strchr(param, ',');
4781 pos = os_strchr(pos, ',');
4785 duration = atoi(pos);
4786 if (count < 0 || count > 255 || start < 0 || duration < 0)
4788 if (count == 0 && duration > 0)
4790 wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
4791 "start=%d duration=%d", count, start, duration);
4792 return wpas_p2p_set_noa(wpa_s, count, start, duration);
4795 if (os_strcmp(cmd, "ps") == 0)
4796 return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1);
4798 if (os_strcmp(cmd, "oppps") == 0)
4799 return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1);
4801 if (os_strcmp(cmd, "ctwindow") == 0)
4802 return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param));
4804 if (os_strcmp(cmd, "disabled") == 0) {
4805 wpa_s->global->p2p_disabled = atoi(param);
4806 wpa_printf(MSG_DEBUG, "P2P functionality %s",
4807 wpa_s->global->p2p_disabled ?
4808 "disabled" : "enabled");
4809 if (wpa_s->global->p2p_disabled) {
4810 wpas_p2p_stop_find(wpa_s);
4811 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
4812 p2p_flush(wpa_s->global->p2p);
4817 if (os_strcmp(cmd, "conc_pref") == 0) {
4818 if (os_strcmp(param, "sta") == 0)
4819 wpa_s->global->conc_pref = WPA_CONC_PREF_STA;
4820 else if (os_strcmp(param, "p2p") == 0)
4821 wpa_s->global->conc_pref = WPA_CONC_PREF_P2P;
4823 wpa_printf(MSG_INFO, "Invalid conc_pref value");
4826 wpa_printf(MSG_DEBUG, "Single channel concurrency preference: "
4831 if (os_strcmp(cmd, "force_long_sd") == 0) {
4832 wpa_s->force_long_sd = atoi(param);
4836 if (os_strcmp(cmd, "peer_filter") == 0) {
4838 if (hwaddr_aton(param, addr))
4840 p2p_set_peer_filter(wpa_s->global->p2p, addr);
4844 if (os_strcmp(cmd, "cross_connect") == 0)
4845 return wpas_p2p_set_cross_connect(wpa_s, atoi(param));
4847 if (os_strcmp(cmd, "go_apsd") == 0) {
4848 if (os_strcmp(param, "disable") == 0)
4849 wpa_s->set_ap_uapsd = 0;
4851 wpa_s->set_ap_uapsd = 1;
4852 wpa_s->ap_uapsd = atoi(param);
4857 if (os_strcmp(cmd, "client_apsd") == 0) {
4858 if (os_strcmp(param, "disable") == 0)
4859 wpa_s->set_sta_uapsd = 0;
4863 /* format: BE,BK,VI,VO;max SP Length */
4865 pos = os_strchr(param, ',');
4870 pos = os_strchr(pos, ',');
4875 pos = os_strchr(pos, ',');
4880 /* ignore max SP Length for now */
4882 wpa_s->set_sta_uapsd = 1;
4883 wpa_s->sta_uapsd = 0;
4885 wpa_s->sta_uapsd |= BIT(0);
4887 wpa_s->sta_uapsd |= BIT(1);
4889 wpa_s->sta_uapsd |= BIT(2);
4891 wpa_s->sta_uapsd |= BIT(3);
4896 if (os_strcmp(cmd, "disallow_freq") == 0)
4897 return p2p_ctrl_disallow_freq(wpa_s, param);
4899 if (os_strcmp(cmd, "disc_int") == 0) {
4900 int min_disc_int, max_disc_int, max_disc_tu;
4905 min_disc_int = atoi(pos);
4906 pos = os_strchr(pos, ' ');
4911 max_disc_int = atoi(pos);
4912 pos = os_strchr(pos, ' ');
4917 max_disc_tu = atoi(pos);
4919 return p2p_set_disc_int(wpa_s->global->p2p, min_disc_int,
4920 max_disc_int, max_disc_tu);
4923 if (os_strcmp(cmd, "per_sta_psk") == 0) {
4924 wpa_s->global->p2p_per_sta_psk = !!atoi(param);
4928 #ifdef CONFIG_WPS_NFC
4929 if (os_strcmp(cmd, "nfc_tag") == 0)
4930 return wpas_p2p_nfc_tag_enabled(wpa_s, !!atoi(param));
4931 #endif /* CONFIG_WPS_NFC */
4933 if (os_strcmp(cmd, "disable_ip_addr_req") == 0) {
4934 wpa_s->p2p_disable_ip_addr_req = !!atoi(param);
4938 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
4945 static void p2p_ctrl_flush(struct wpa_supplicant *wpa_s)
4947 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
4948 wpa_s->force_long_sd = 0;
4949 if (wpa_s->global->p2p)
4950 p2p_flush(wpa_s->global->p2p);
4954 static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd)
4957 unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0;
4960 pos = os_strchr(cmd, ' ');
4966 pos2 = os_strchr(pos, ' ');
4974 pos = os_strchr(pos2, ' ');
4982 return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2);
4986 static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd)
4989 unsigned int period = 0, interval = 0;
4992 pos = os_strchr(cmd, ' ');
4997 interval = atoi(pos);
5000 return wpas_p2p_ext_listen(wpa_s, period, interval);
5004 static int p2p_ctrl_remove_client(struct wpa_supplicant *wpa_s, const char *cmd)
5011 if (os_strncmp(pos, "iface=", 6) == 0) {
5015 if (hwaddr_aton(pos, peer))
5018 wpas_p2p_remove_client(wpa_s, peer, iface_addr);
5022 #endif /* CONFIG_P2P */
5025 static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s, char *val)
5027 struct wpa_freq_range_list ranges;
5029 struct hostapd_hw_modes *mode;
5032 if (wpa_s->hw.modes == NULL)
5035 os_memset(&ranges, 0, sizeof(ranges));
5036 if (freq_range_list_parse(&ranges, val) < 0)
5039 for (i = 0; i < wpa_s->hw.num_modes; i++) {
5042 mode = &wpa_s->hw.modes[i];
5043 for (j = 0; j < mode->num_channels; j++) {
5046 if (mode->channels[j].flag & HOSTAPD_CHAN_DISABLED)
5049 freq = mode->channels[j].freq;
5050 if (!freq_range_list_includes(&ranges, freq))
5053 int_array_add_unique(&freqs, freq);
5057 os_free(ranges.range);
5062 #ifdef CONFIG_INTERWORKING
5064 static int ctrl_interworking_select(struct wpa_supplicant *wpa_s, char *param)
5072 auto_sel = os_strstr(param, "auto") != NULL;
5074 pos = os_strstr(param, "freq=");
5076 freqs = freq_range_to_channel_list(wpa_s, pos + 5);
5083 return interworking_select(wpa_s, auto_sel, freqs);
5087 static int ctrl_interworking_connect(struct wpa_supplicant *wpa_s, char *dst)
5090 struct wpa_bss *bss;
5092 if (hwaddr_aton(dst, bssid)) {
5093 wpa_printf(MSG_DEBUG, "Invalid BSSID '%s'", dst);
5097 bss = wpa_bss_get_bssid(wpa_s, bssid);
5099 wpa_printf(MSG_DEBUG, "Could not find BSS " MACSTR,
5104 return interworking_connect(wpa_s, bss);
5108 static int get_anqp(struct wpa_supplicant *wpa_s, char *dst)
5110 u8 dst_addr[ETH_ALEN];
5113 #define MAX_ANQP_INFO_ID 100
5114 u16 id[MAX_ANQP_INFO_ID];
5118 used = hwaddr_aton2(dst, dst_addr);
5122 while (num_id < MAX_ANQP_INFO_ID) {
5123 if (os_strncmp(pos, "hs20:", 5) == 0) {
5125 int num = atoi(pos + 5);
5126 if (num <= 0 || num > 31)
5128 subtypes |= BIT(num);
5129 #else /* CONFIG_HS20 */
5131 #endif /* CONFIG_HS20 */
5133 id[num_id] = atoi(pos);
5137 pos = os_strchr(pos + 1, ',');
5146 return anqp_send_req(wpa_s, dst_addr, id, num_id, subtypes);
5150 static int gas_request(struct wpa_supplicant *wpa_s, char *cmd)
5152 u8 dst_addr[ETH_ALEN];
5153 struct wpabuf *advproto, *query = NULL;
5158 used = hwaddr_aton2(cmd, dst_addr);
5166 /* Advertisement Protocol ID */
5167 end = os_strchr(pos, ' ');
5171 len = os_strlen(pos);
5177 advproto = wpabuf_alloc(len);
5178 if (advproto == NULL)
5180 if (hexstr2bin(pos, wpabuf_put(advproto, len), len) < 0)
5184 /* Optional Query Request */
5189 len = os_strlen(pos);
5196 query = wpabuf_alloc(len);
5199 if (hexstr2bin(pos, wpabuf_put(query, len), len) < 0)
5204 ret = gas_send_request(wpa_s, dst_addr, advproto, query);
5207 wpabuf_free(advproto);
5214 static int gas_response_get(struct wpa_supplicant *wpa_s, char *cmd, char *buf,
5221 size_t resp_len, start, requested_len;
5222 struct wpabuf *resp;
5225 used = hwaddr_aton2(cmd, addr);
5232 dialog_token = atoi(pos);
5234 if (wpa_s->last_gas_resp &&
5235 os_memcmp(addr, wpa_s->last_gas_addr, ETH_ALEN) == 0 &&
5236 dialog_token == wpa_s->last_gas_dialog_token)
5237 resp = wpa_s->last_gas_resp;
5238 else if (wpa_s->prev_gas_resp &&
5239 os_memcmp(addr, wpa_s->prev_gas_addr, ETH_ALEN) == 0 &&
5240 dialog_token == wpa_s->prev_gas_dialog_token)
5241 resp = wpa_s->prev_gas_resp;
5245 resp_len = wpabuf_len(resp);
5247 requested_len = resp_len;
5249 pos = os_strchr(pos, ' ');
5252 if (start > resp_len)
5253 return os_snprintf(buf, buflen, "FAIL-Invalid range");
5254 pos = os_strchr(pos, ',');
5258 requested_len = atoi(pos);
5259 if (start + requested_len > resp_len)
5260 return os_snprintf(buf, buflen, "FAIL-Invalid range");
5263 if (requested_len * 2 + 1 > buflen)
5264 return os_snprintf(buf, buflen, "FAIL-Too long response");
5266 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(resp) + start,
5269 if (start + requested_len == resp_len) {
5271 * Free memory by dropping the response after it has been
5274 if (resp == wpa_s->prev_gas_resp) {
5275 wpabuf_free(wpa_s->prev_gas_resp);
5276 wpa_s->prev_gas_resp = NULL;
5278 wpabuf_free(wpa_s->last_gas_resp);
5279 wpa_s->last_gas_resp = NULL;
5285 #endif /* CONFIG_INTERWORKING */
5290 static int get_hs20_anqp(struct wpa_supplicant *wpa_s, char *dst)
5292 u8 dst_addr[ETH_ALEN];
5297 used = hwaddr_aton2(dst, dst_addr);
5302 int num = atoi(pos);
5303 if (num <= 0 || num > 31)
5305 subtypes |= BIT(num);
5306 pos = os_strchr(pos + 1, ',');
5315 return hs20_anqp_send_req(wpa_s, dst_addr, subtypes, NULL, 0);
5319 static int hs20_nai_home_realm_list(struct wpa_supplicant *wpa_s,
5320 const u8 *addr, const char *realm)
5326 rlen = os_strlen(realm);
5328 buf = os_malloc(len);
5331 buf[0] = 1; /* NAI Home Realm Count */
5332 buf[1] = 0; /* Formatted in accordance with RFC 4282 */
5334 os_memcpy(buf + 3, realm, rlen);
5336 ret = hs20_anqp_send_req(wpa_s, addr,
5337 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
5346 static int hs20_get_nai_home_realm_list(struct wpa_supplicant *wpa_s,
5349 struct wpa_cred *cred = wpa_s->conf->cred;
5350 u8 dst_addr[ETH_ALEN];
5356 used = hwaddr_aton2(dst, dst_addr);
5360 while (dst[used] == ' ')
5362 if (os_strncmp(dst + used, "realm=", 6) == 0)
5363 return hs20_nai_home_realm_list(wpa_s, dst_addr,
5366 len = os_strlen(dst + used);
5368 if (len == 0 && cred && cred->realm)
5369 return hs20_nai_home_realm_list(wpa_s, dst_addr, cred->realm);
5374 buf = os_malloc(len);
5377 if (hexstr2bin(dst + used, buf, len) < 0) {
5382 ret = hs20_anqp_send_req(wpa_s, dst_addr,
5383 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
5391 static int hs20_icon_request(struct wpa_supplicant *wpa_s, char *cmd)
5393 u8 dst_addr[ETH_ALEN];
5397 used = hwaddr_aton2(cmd, dst_addr);
5401 while (cmd[used] == ' ')
5405 wpa_s->fetch_osu_icon_in_progress = 0;
5406 return hs20_anqp_send_req(wpa_s, dst_addr, BIT(HS20_STYPE_ICON_REQUEST),
5407 (u8 *) icon, os_strlen(icon));
5410 #endif /* CONFIG_HS20 */
5413 static int wpa_supplicant_ctrl_iface_sta_autoconnect(
5414 struct wpa_supplicant *wpa_s, char *cmd)
5416 wpa_s->auto_reconnect_disabled = atoi(cmd) == 0 ? 1 : 0;
5421 #ifdef CONFIG_AUTOSCAN
5423 static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant *wpa_s,
5426 enum wpa_states state = wpa_s->wpa_state;
5427 char *new_params = NULL;
5429 if (os_strlen(cmd) > 0) {
5430 new_params = os_strdup(cmd);
5431 if (new_params == NULL)
5435 os_free(wpa_s->conf->autoscan);
5436 wpa_s->conf->autoscan = new_params;
5438 if (wpa_s->conf->autoscan == NULL)
5439 autoscan_deinit(wpa_s);
5440 else if (state == WPA_DISCONNECTED || state == WPA_INACTIVE)
5441 autoscan_init(wpa_s, 1);
5442 else if (state == WPA_SCANNING)
5443 wpa_supplicant_reinit_autoscan(wpa_s);
5448 #endif /* CONFIG_AUTOSCAN */
5453 static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant *wpa_s, char *cmd)
5459 struct wpabuf *tfs_req = NULL;
5461 if (os_strncmp(cmd, "enter", 5) == 0)
5463 else if (os_strncmp(cmd, "exit", 4) == 0)
5468 pos = os_strstr(cmd, " interval=");
5470 intval = atoi(pos + 10);
5472 pos = os_strstr(cmd, " tfs_req=");
5477 end = os_strchr(pos, ' ');
5481 len = os_strlen(pos);
5485 tfs_req = wpabuf_alloc(len);
5486 if (tfs_req == NULL)
5488 if (hexstr2bin(pos, wpabuf_put(tfs_req, len), len) < 0) {
5489 wpabuf_free(tfs_req);
5494 ret = ieee802_11_send_wnmsleep_req(wpa_s, enter ? WNM_SLEEP_MODE_ENTER :
5495 WNM_SLEEP_MODE_EXIT, intval,
5497 wpabuf_free(tfs_req);
5503 static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant *wpa_s, char *cmd)
5507 query_reason = atoi(cmd);
5509 wpa_printf(MSG_DEBUG, "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d",
5512 return wnm_send_bss_transition_mgmt_query(wpa_s, query_reason);
5515 #endif /* CONFIG_WNM */
5518 /* Get string representation of channel width */
5519 static const char * channel_width_name(enum chan_width width)
5522 case CHAN_WIDTH_20_NOHT:
5523 return "20 MHz (no HT)";
5530 case CHAN_WIDTH_80P80:
5532 case CHAN_WIDTH_160:
5540 static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf,
5543 struct wpa_signal_info si;
5547 ret = wpa_drv_signal_poll(wpa_s, &si);
5554 ret = os_snprintf(pos, end - pos, "RSSI=%d\nLINKSPEED=%d\n"
5555 "NOISE=%d\nFREQUENCY=%u\n",
5556 si.current_signal, si.current_txrate / 1000,
5557 si.current_noise, si.frequency);
5558 if (ret < 0 || ret > end - pos)
5562 if (si.chanwidth != CHAN_WIDTH_UNKNOWN) {
5563 ret = os_snprintf(pos, end - pos, "WIDTH=%s\n",
5564 channel_width_name(si.chanwidth));
5565 if (ret < 0 || ret > end - pos)
5570 if (si.center_frq1 > 0 && si.center_frq2 > 0) {
5571 ret = os_snprintf(pos, end - pos,
5572 "CENTER_FRQ1=%d\nCENTER_FRQ2=%d\n",
5573 si.center_frq1, si.center_frq2);
5574 if (ret < 0 || ret > end - pos)
5579 if (si.avg_signal) {
5580 ret = os_snprintf(pos, end - pos,
5581 "AVG_RSSI=%d\n", si.avg_signal);
5582 if (ret < 0 || ret >= end - pos)
5591 static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant *wpa_s, char *buf,
5594 struct hostap_sta_driver_data sta;
5597 ret = wpa_drv_pktcnt_poll(wpa_s, &sta);
5601 ret = os_snprintf(buf, buflen, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
5602 sta.tx_packets, sta.tx_retry_failed, sta.rx_packets);
5603 if (ret < 0 || (size_t) ret > buflen)
5610 static int wpa_supplicant_driver_cmd(struct wpa_supplicant *wpa_s, char *cmd,
5611 char *buf, size_t buflen)
5615 ret = wpa_drv_driver_cmd(wpa_s, cmd, buf, buflen);
5617 if (os_strncasecmp(cmd, "COUNTRY", 7) == 0) {
5618 struct p2p_data *p2p = wpa_s->global->p2p;
5621 country[0] = cmd[8];
5622 country[1] = cmd[9];
5624 p2p_set_country(p2p, country);
5627 ret = os_snprintf(buf, buflen, "%s\n", "OK");
5631 #endif /* ANDROID */
5634 static int wpa_supplicant_vendor_cmd(struct wpa_supplicant *wpa_s, char *cmd,
5635 char *buf, size_t buflen)
5640 unsigned int vendor_id, subcmd;
5641 struct wpabuf *reply;
5642 size_t data_len = 0;
5644 /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */
5645 vendor_id = strtoul(cmd, &pos, 16);
5649 subcmd = strtoul(pos, &pos, 10);
5652 if (!isblank(*pos++))
5654 data_len = os_strlen(pos);
5659 data = os_malloc(data_len);
5663 if (hexstr2bin(pos, data, data_len)) {
5664 wpa_printf(MSG_DEBUG,
5665 "Vendor command: wrong parameter format");
5671 reply = wpabuf_alloc((buflen - 1) / 2);
5677 ret = wpa_drv_vendor_cmd(wpa_s, vendor_id, subcmd, data, data_len,
5681 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(reply),
5691 static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s)
5693 wpa_dbg(wpa_s, MSG_DEBUG, "Flush all wpa_supplicant state");
5696 wpas_p2p_cancel(wpa_s);
5697 wpas_p2p_stop_find(wpa_s);
5698 p2p_ctrl_flush(wpa_s);
5699 wpas_p2p_group_remove(wpa_s, "*");
5700 wpas_p2p_service_flush(wpa_s);
5701 wpa_s->global->p2p_disabled = 0;
5702 wpa_s->global->p2p_per_sta_psk = 0;
5703 wpa_s->conf->num_sec_device_types = 0;
5704 wpa_s->p2p_disable_ip_addr_req = 0;
5705 os_free(wpa_s->global->p2p_go_avoid_freq.range);
5706 wpa_s->global->p2p_go_avoid_freq.range = NULL;
5707 #endif /* CONFIG_P2P */
5709 #ifdef CONFIG_WPS_TESTING
5710 wps_version_number = 0x20;
5711 wps_testing_dummy_cred = 0;
5712 wps_corrupt_pkhash = 0;
5713 #endif /* CONFIG_WPS_TESTING */
5715 wpa_s->wps_fragment_size = 0;
5716 wpas_wps_cancel(wpa_s);
5717 #endif /* CONFIG_WPS */
5718 wpa_s->after_wps = 0;
5719 wpa_s->known_wps_freq = 0;
5722 #ifdef CONFIG_TDLS_TESTING
5723 extern unsigned int tdls_testing;
5725 #endif /* CONFIG_TDLS_TESTING */
5726 wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL);
5727 wpa_tdls_enable(wpa_s->wpa, 1);
5728 #endif /* CONFIG_TDLS */
5730 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, wpa_s, NULL);
5731 wpa_supplicant_stop_countermeasures(wpa_s, NULL);
5733 wpa_s->no_keep_alive = 0;
5735 os_free(wpa_s->disallow_aps_bssid);
5736 wpa_s->disallow_aps_bssid = NULL;
5737 wpa_s->disallow_aps_bssid_count = 0;
5738 os_free(wpa_s->disallow_aps_ssid);
5739 wpa_s->disallow_aps_ssid = NULL;
5740 wpa_s->disallow_aps_ssid_count = 0;
5742 wpa_s->set_sta_uapsd = 0;
5743 wpa_s->sta_uapsd = 0;
5745 wpa_drv_radio_disable(wpa_s, 0);
5747 wpa_bss_flush(wpa_s);
5748 wpa_blacklist_clear(wpa_s);
5749 wpa_s->extra_blacklist_count = 0;
5750 wpa_supplicant_ctrl_iface_remove_network(wpa_s, "all");
5751 wpa_supplicant_ctrl_iface_remove_cred(wpa_s, "all");
5752 wpa_config_flush_blobs(wpa_s->conf);
5753 wpa_s->conf->auto_interworking = 0;
5754 wpa_s->conf->okc = 0;
5756 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, 43200);
5757 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, 70);
5758 wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, 60);
5759 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
5761 radio_remove_works(wpa_s, NULL, 1);
5763 wpa_s->next_ssid = NULL;
5765 #ifdef CONFIG_INTERWORKING
5766 hs20_cancel_fetch_osu(wpa_s);
5767 #endif /* CONFIG_INTERWORKING */
5769 wpa_s->ext_mgmt_frame_handling = 0;
5773 static int wpas_ctrl_radio_work_show(struct wpa_supplicant *wpa_s,
5774 char *buf, size_t buflen)
5776 struct wpa_radio_work *work;
5778 struct os_reltime now, diff;
5783 os_get_reltime(&now);
5785 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
5789 os_reltime_sub(&now, &work->time, &diff);
5790 ret = os_snprintf(pos, end - pos, "%s@%s:%u:%u:%ld.%06ld\n",
5791 work->type, work->wpa_s->ifname, work->freq,
5792 work->started, diff.sec, diff.usec);
5793 if (ret < 0 || ret >= end - pos)
5802 static void wpas_ctrl_radio_work_timeout(void *eloop_ctx, void *timeout_ctx)
5804 struct wpa_radio_work *work = eloop_ctx;
5805 struct wpa_external_work *ework = work->ctx;
5807 wpa_dbg(work->wpa_s, MSG_DEBUG,
5808 "Timing out external radio work %u (%s)",
5809 ework->id, work->type);
5810 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_TIMEOUT "%u", ework->id);
5811 radio_work_done(work);
5816 static void wpas_ctrl_radio_work_cb(struct wpa_radio_work *work, int deinit)
5818 struct wpa_external_work *ework = work->ctx;
5822 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
5829 wpa_dbg(work->wpa_s, MSG_DEBUG, "Starting external radio work %u (%s)",
5830 ework->id, ework->type);
5831 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_START "%u", ework->id);
5832 if (!ework->timeout)
5833 ework->timeout = 10;
5834 eloop_register_timeout(ework->timeout, 0, wpas_ctrl_radio_work_timeout,
5839 static int wpas_ctrl_radio_work_add(struct wpa_supplicant *wpa_s, char *cmd,
5840 char *buf, size_t buflen)
5842 struct wpa_external_work *ework;
5846 unsigned int freq = 0;
5848 /* format: <name> [freq=<MHz>] [timeout=<seconds>] */
5850 ework = os_zalloc(sizeof(*ework));
5854 pos = os_strchr(cmd, ' ');
5856 type_len = pos - cmd;
5859 pos2 = os_strstr(pos, "freq=");
5861 freq = atoi(pos2 + 5);
5863 pos2 = os_strstr(pos, "timeout=");
5865 ework->timeout = atoi(pos2 + 8);
5867 type_len = os_strlen(cmd);
5869 if (4 + type_len >= sizeof(ework->type))
5870 type_len = sizeof(ework->type) - 4 - 1;
5871 os_strlcpy(ework->type, "ext:", sizeof(ework->type));
5872 os_memcpy(ework->type + 4, cmd, type_len);
5873 ework->type[4 + type_len] = '\0';
5875 wpa_s->ext_work_id++;
5876 if (wpa_s->ext_work_id == 0)
5877 wpa_s->ext_work_id++;
5878 ework->id = wpa_s->ext_work_id;
5880 if (radio_add_work(wpa_s, freq, ework->type, 0, wpas_ctrl_radio_work_cb,
5886 ret = os_snprintf(buf, buflen, "%u", ework->id);
5887 if (ret < 0 || (size_t) ret >= buflen)
5893 static int wpas_ctrl_radio_work_done(struct wpa_supplicant *wpa_s, char *cmd)
5895 struct wpa_radio_work *work;
5896 unsigned int id = atoi(cmd);
5898 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
5900 struct wpa_external_work *ework;
5902 if (os_strncmp(work->type, "ext:", 4) != 0)
5905 if (id && ework->id != id)
5907 wpa_dbg(wpa_s, MSG_DEBUG,
5908 "Completed external radio work %u (%s)",
5909 ework->id, ework->type);
5910 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, work, NULL);
5911 radio_work_done(work);
5913 return 3; /* "OK\n" */
5920 static int wpas_ctrl_radio_work(struct wpa_supplicant *wpa_s, char *cmd,
5921 char *buf, size_t buflen)
5923 if (os_strcmp(cmd, "show") == 0)
5924 return wpas_ctrl_radio_work_show(wpa_s, buf, buflen);
5925 if (os_strncmp(cmd, "add ", 4) == 0)
5926 return wpas_ctrl_radio_work_add(wpa_s, cmd + 4, buf, buflen);
5927 if (os_strncmp(cmd, "done ", 5) == 0)
5928 return wpas_ctrl_radio_work_done(wpa_s, cmd + 4);
5933 void wpas_ctrl_radio_work_flush(struct wpa_supplicant *wpa_s)
5935 struct wpa_radio_work *work, *tmp;
5937 if (!wpa_s || !wpa_s->radio)
5940 dl_list_for_each_safe(work, tmp, &wpa_s->radio->work,
5941 struct wpa_radio_work, list) {
5942 struct wpa_external_work *ework;
5944 if (os_strncmp(work->type, "ext:", 4) != 0)
5947 wpa_dbg(wpa_s, MSG_DEBUG,
5948 "Flushing%s external radio work %u (%s)",
5949 work->started ? " started" : "", ework->id,
5952 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
5954 radio_work_done(work);
5960 static void wpas_ctrl_eapol_response(void *eloop_ctx, void *timeout_ctx)
5962 struct wpa_supplicant *wpa_s = eloop_ctx;
5963 eapol_sm_notify_ctrl_response(wpa_s->eapol);
5967 static int set_scan_freqs(struct wpa_supplicant *wpa_s, char *val)
5971 freqs = freq_range_to_channel_list(wpa_s, val);
5975 os_free(wpa_s->manual_scan_freqs);
5976 wpa_s->manual_scan_freqs = freqs;
5982 static void wpas_ctrl_scan(struct wpa_supplicant *wpa_s, char *params,
5983 char *reply, int reply_size, int *reply_len)
5987 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
5992 wpa_s->manual_scan_passive = 0;
5993 wpa_s->manual_scan_use_id = 0;
5994 wpa_s->manual_scan_only_new = 0;
5997 if (os_strncasecmp(params, "TYPE=ONLY", 9) == 0)
5998 wpa_s->scan_res_handler = scan_only_handler;
6000 pos = os_strstr(params, "freq=");
6001 if (pos && set_scan_freqs(wpa_s, pos + 5) < 0) {
6006 pos = os_strstr(params, "passive=");
6008 wpa_s->manual_scan_passive = !!atoi(pos + 8);
6010 pos = os_strstr(params, "use_id=");
6012 wpa_s->manual_scan_use_id = atoi(pos + 7);
6014 pos = os_strstr(params, "only_new=1");
6016 wpa_s->manual_scan_only_new = 1;
6018 os_free(wpa_s->manual_scan_freqs);
6019 wpa_s->manual_scan_freqs = NULL;
6020 if (wpa_s->scan_res_handler == scan_only_handler)
6021 wpa_s->scan_res_handler = NULL;
6024 if (!wpa_s->sched_scanning && !wpa_s->scanning &&
6025 ((wpa_s->wpa_state <= WPA_SCANNING) ||
6026 (wpa_s->wpa_state == WPA_COMPLETED))) {
6027 wpa_s->normal_scans = 0;
6028 wpa_s->scan_req = MANUAL_SCAN_REQ;
6029 wpa_s->after_wps = 0;
6030 wpa_s->known_wps_freq = 0;
6031 wpa_supplicant_req_scan(wpa_s, 0, 0);
6032 if (wpa_s->manual_scan_use_id) {
6033 wpa_s->manual_scan_id++;
6034 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
6035 wpa_s->manual_scan_id);
6036 *reply_len = os_snprintf(reply, reply_size, "%u\n",
6037 wpa_s->manual_scan_id);
6039 } else if (wpa_s->sched_scanning) {
6040 wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to allow requested full scan to proceed");
6041 wpa_supplicant_cancel_sched_scan(wpa_s);
6042 wpa_s->scan_req = MANUAL_SCAN_REQ;
6043 wpa_supplicant_req_scan(wpa_s, 0, 0);
6044 if (wpa_s->manual_scan_use_id) {
6045 wpa_s->manual_scan_id++;
6046 *reply_len = os_snprintf(reply, reply_size, "%u\n",
6047 wpa_s->manual_scan_id);
6048 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
6049 wpa_s->manual_scan_id);
6052 wpa_printf(MSG_DEBUG, "Ongoing scan action - reject new request");
6053 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
6058 #ifdef CONFIG_TESTING_OPTIONS
6060 static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant *wpa_s,
6061 unsigned int freq, const u8 *dst,
6062 const u8 *src, const u8 *bssid,
6063 const u8 *data, size_t data_len,
6064 enum offchannel_send_action_result
6067 wpa_msg(wpa_s, MSG_INFO, "MGMT-TX-STATUS freq=%u dst=" MACSTR
6068 " src=" MACSTR " bssid=" MACSTR " result=%s",
6069 freq, MAC2STR(dst), MAC2STR(src), MAC2STR(bssid),
6070 result == OFFCHANNEL_SEND_ACTION_SUCCESS ?
6071 "SUCCESS" : (result == OFFCHANNEL_SEND_ACTION_NO_ACK ?
6072 "NO_ACK" : "FAILED"));
6076 static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant *wpa_s, char *cmd)
6080 u8 *buf, da[ETH_ALEN], bssid[ETH_ALEN];
6082 int freq = 0, no_cck = 0, wait_time = 0;
6084 /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1]
6085 * <action=Action frame payload> */
6087 wpa_printf(MSG_DEBUG, "External MGMT TX: %s", cmd);
6090 used = hwaddr_aton2(pos, da);
6096 used = hwaddr_aton2(pos, bssid);
6101 param = os_strstr(pos, " freq=");
6107 param = os_strstr(pos, " no_cck=");
6110 no_cck = atoi(param);
6113 param = os_strstr(pos, " wait_time=");
6116 wait_time = atoi(param);
6119 param = os_strstr(pos, " action=");
6124 len = os_strlen(param);
6129 buf = os_malloc(len);
6133 if (hexstr2bin(param, buf, len) < 0) {
6138 res = offchannel_send_action(wpa_s, freq, da, wpa_s->own_addr, bssid,
6139 buf, len, wait_time,
6140 wpas_ctrl_iface_mgmt_tx_cb, no_cck);
6146 static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant *wpa_s)
6148 wpa_printf(MSG_DEBUG, "External MGMT TX - done waiting");
6149 offchannel_send_action_done(wpa_s);
6153 static int wpas_ctrl_iface_driver_event(struct wpa_supplicant *wpa_s, char *cmd)
6156 union wpa_event_data event;
6157 enum wpa_event_type ev;
6159 /* <event name> [parameters..] */
6161 wpa_dbg(wpa_s, MSG_DEBUG, "Testing - external driver event: %s", cmd);
6164 param = os_strchr(pos, ' ');
6168 os_memset(&event, 0, sizeof(event));
6170 if (os_strcmp(cmd, "INTERFACE_ENABLED") == 0) {
6171 ev = EVENT_INTERFACE_ENABLED;
6172 } else if (os_strcmp(cmd, "INTERFACE_DISABLED") == 0) {
6173 ev = EVENT_INTERFACE_DISABLED;
6174 } else if (os_strcmp(cmd, "AVOID_FREQUENCIES") == 0) {
6175 ev = EVENT_AVOID_FREQUENCIES;
6178 if (freq_range_list_parse(&event.freq_range, param) < 0)
6180 wpa_supplicant_event(wpa_s, ev, &event);
6181 os_free(event.freq_range.range);
6184 wpa_dbg(wpa_s, MSG_DEBUG, "Testing - unknown driver event: %s",
6189 wpa_supplicant_event(wpa_s, ev, &event);
6194 #endif /* CONFIG_TESTING_OPTIONS */
6197 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
6198 char *buf, size_t *resp_len)
6201 const int reply_size = 4096;
6204 if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 ||
6205 os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
6206 if (wpa_debug_show_keys)
6207 wpa_dbg(wpa_s, MSG_DEBUG,
6208 "Control interface command '%s'", buf);
6210 wpa_dbg(wpa_s, MSG_DEBUG,
6211 "Control interface command '%s [REMOVED]'",
6212 os_strncmp(buf, WPA_CTRL_RSP,
6213 os_strlen(WPA_CTRL_RSP)) == 0 ?
6214 WPA_CTRL_RSP : "SET_NETWORK");
6215 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ", 16) == 0 ||
6216 os_strncmp(buf, "NFC_REPORT_HANDOVER", 19) == 0) {
6217 wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface",
6218 (const u8 *) buf, os_strlen(buf));
6220 int level = MSG_DEBUG;
6221 if (os_strcmp(buf, "PING") == 0)
6222 level = MSG_EXCESSIVE;
6223 wpa_dbg(wpa_s, level, "Control interface command '%s'", buf);
6226 reply = os_malloc(reply_size);
6227 if (reply == NULL) {
6232 os_memcpy(reply, "OK\n", 3);
6235 if (os_strcmp(buf, "PING") == 0) {
6236 os_memcpy(reply, "PONG\n", 5);
6238 } else if (os_strcmp(buf, "IFNAME") == 0) {
6239 reply_len = os_strlen(wpa_s->ifname);
6240 os_memcpy(reply, wpa_s->ifname, reply_len);
6241 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
6242 if (wpa_debug_reopen_file() < 0)
6244 } else if (os_strncmp(buf, "NOTE ", 5) == 0) {
6245 wpa_printf(MSG_INFO, "NOTE: %s", buf + 5);
6246 } else if (os_strcmp(buf, "MIB") == 0) {
6247 reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size);
6248 if (reply_len >= 0) {
6250 res = eapol_sm_get_mib(wpa_s->eapol, reply + reply_len,
6251 reply_size - reply_len);
6257 } else if (os_strncmp(buf, "STATUS", 6) == 0) {
6258 reply_len = wpa_supplicant_ctrl_iface_status(
6259 wpa_s, buf + 6, reply, reply_size);
6260 } else if (os_strcmp(buf, "PMKSA") == 0) {
6261 reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, reply,
6263 } else if (os_strncmp(buf, "SET ", 4) == 0) {
6264 if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4))
6266 } else if (os_strncmp(buf, "GET ", 4) == 0) {
6267 reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4,
6269 } else if (os_strcmp(buf, "LOGON") == 0) {
6270 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
6271 } else if (os_strcmp(buf, "LOGOFF") == 0) {
6272 eapol_sm_notify_logoff(wpa_s->eapol, TRUE);
6273 } else if (os_strcmp(buf, "REASSOCIATE") == 0) {
6274 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
6277 wpas_request_connection(wpa_s);
6278 } else if (os_strcmp(buf, "REATTACH") == 0) {
6279 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED ||
6280 !wpa_s->current_ssid)
6283 wpa_s->reattach = 1;
6284 wpas_request_connection(wpa_s);
6286 } else if (os_strcmp(buf, "RECONNECT") == 0) {
6287 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
6289 else if (wpa_s->disconnected)
6290 wpas_request_connection(wpa_s);
6291 #ifdef IEEE8021X_EAPOL
6292 } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) {
6293 if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8))
6295 #endif /* IEEE8021X_EAPOL */
6296 #ifdef CONFIG_PEERKEY
6297 } else if (os_strncmp(buf, "STKSTART ", 9) == 0) {
6298 if (wpa_supplicant_ctrl_iface_stkstart(wpa_s, buf + 9))
6300 #endif /* CONFIG_PEERKEY */
6301 #ifdef CONFIG_IEEE80211R
6302 } else if (os_strncmp(buf, "FT_DS ", 6) == 0) {
6303 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6))
6305 #endif /* CONFIG_IEEE80211R */
6307 } else if (os_strcmp(buf, "WPS_PBC") == 0) {
6308 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL);
6310 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
6314 } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) {
6315 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8);
6317 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
6321 } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {
6322 reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8,
6325 } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) {
6326 reply_len = wpa_supplicant_ctrl_iface_wps_check_pin(
6327 wpa_s, buf + 14, reply, reply_size);
6328 } else if (os_strcmp(buf, "WPS_CANCEL") == 0) {
6329 if (wpas_wps_cancel(wpa_s))
6331 #ifdef CONFIG_WPS_NFC
6332 } else if (os_strcmp(buf, "WPS_NFC") == 0) {
6333 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, NULL))
6335 } else if (os_strncmp(buf, "WPS_NFC ", 8) == 0) {
6336 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, buf + 8))
6338 } else if (os_strncmp(buf, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
6339 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_config_token(
6340 wpa_s, buf + 21, reply, reply_size);
6341 } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) {
6342 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_token(
6343 wpa_s, buf + 14, reply, reply_size);
6344 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) {
6345 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s,
6348 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
6349 reply_len = wpas_ctrl_nfc_get_handover_req(
6350 wpa_s, buf + 21, reply, reply_size);
6351 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
6352 reply_len = wpas_ctrl_nfc_get_handover_sel(
6353 wpa_s, buf + 21, reply, reply_size);
6354 } else if (os_strncmp(buf, "NFC_REPORT_HANDOVER ", 20) == 0) {
6355 if (wpas_ctrl_nfc_report_handover(wpa_s, buf + 20))
6357 #endif /* CONFIG_WPS_NFC */
6358 } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) {
6359 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8))
6362 } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) {
6363 reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin(
6364 wpa_s, buf + 11, reply, reply_size);
6365 #endif /* CONFIG_AP */
6366 #ifdef CONFIG_WPS_ER
6367 } else if (os_strcmp(buf, "WPS_ER_START") == 0) {
6368 if (wpas_wps_er_start(wpa_s, NULL))
6370 } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) {
6371 if (wpas_wps_er_start(wpa_s, buf + 13))
6373 } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) {
6374 if (wpas_wps_er_stop(wpa_s))
6376 } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) {
6377 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11))
6379 } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) {
6380 int ret = wpas_wps_er_pbc(wpa_s, buf + 11);
6382 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
6384 } else if (ret == -3) {
6385 os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18);
6387 } else if (ret == -4) {
6388 os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20);
6392 } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) {
6393 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13))
6395 } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) {
6396 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s,
6399 } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) {
6400 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14))
6402 #ifdef CONFIG_WPS_NFC
6403 } else if (os_strncmp(buf, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
6404 reply_len = wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
6405 wpa_s, buf + 24, reply, reply_size);
6406 #endif /* CONFIG_WPS_NFC */
6407 #endif /* CONFIG_WPS_ER */
6408 #endif /* CONFIG_WPS */
6409 #ifdef CONFIG_IBSS_RSN
6410 } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) {
6411 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9))
6413 #endif /* CONFIG_IBSS_RSN */
6415 } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) {
6416 if (p2p_ctrl_find(wpa_s, buf + 9))
6418 } else if (os_strcmp(buf, "P2P_FIND") == 0) {
6419 if (p2p_ctrl_find(wpa_s, ""))
6421 } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) {
6422 wpas_p2p_stop_find(wpa_s);
6423 } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) {
6424 reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply,
6426 } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) {
6427 if (p2p_ctrl_listen(wpa_s, buf + 11))
6429 } else if (os_strcmp(buf, "P2P_LISTEN") == 0) {
6430 if (p2p_ctrl_listen(wpa_s, ""))
6432 } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) {
6433 if (wpas_p2p_group_remove(wpa_s, buf + 17))
6435 } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) {
6436 if (wpas_p2p_group_add(wpa_s, 0, 0, 0, 0))
6438 } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) {
6439 if (p2p_ctrl_group_add(wpa_s, buf + 14))
6441 } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) {
6442 if (p2p_ctrl_prov_disc(wpa_s, buf + 14))
6444 } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) {
6445 reply_len = p2p_get_passphrase(wpa_s, reply, reply_size);
6446 } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) {
6447 reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply,
6449 } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
6450 if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0)
6452 } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) {
6453 if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0)
6455 } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) {
6456 wpas_p2p_sd_service_update(wpa_s);
6457 } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
6458 if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0)
6460 } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) {
6461 wpas_p2p_service_flush(wpa_s);
6462 } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) {
6463 if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0)
6465 } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) {
6466 if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0)
6468 } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) {
6469 if (p2p_ctrl_reject(wpa_s, buf + 11) < 0)
6471 } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) {
6472 if (p2p_ctrl_invite(wpa_s, buf + 11) < 0)
6474 } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) {
6475 reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply,
6477 } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) {
6478 if (p2p_ctrl_set(wpa_s, buf + 8) < 0)
6480 } else if (os_strcmp(buf, "P2P_FLUSH") == 0) {
6481 p2p_ctrl_flush(wpa_s);
6482 } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) {
6483 if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0)
6485 } else if (os_strcmp(buf, "P2P_CANCEL") == 0) {
6486 if (wpas_p2p_cancel(wpa_s))
6488 } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) {
6489 if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0)
6491 } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) {
6492 if (p2p_ctrl_presence_req(wpa_s, "") < 0)
6494 } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) {
6495 if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0)
6497 } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) {
6498 if (p2p_ctrl_ext_listen(wpa_s, "") < 0)
6500 } else if (os_strncmp(buf, "P2P_REMOVE_CLIENT ", 18) == 0) {
6501 if (p2p_ctrl_remove_client(wpa_s, buf + 18) < 0)
6503 #endif /* CONFIG_P2P */
6504 #ifdef CONFIG_WIFI_DISPLAY
6505 } else if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0) {
6506 if (wifi_display_subelem_set(wpa_s->global, buf + 16) < 0)
6508 } else if (os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) {
6509 reply_len = wifi_display_subelem_get(wpa_s->global, buf + 16,
6511 #endif /* CONFIG_WIFI_DISPLAY */
6512 #ifdef CONFIG_INTERWORKING
6513 } else if (os_strcmp(buf, "FETCH_ANQP") == 0) {
6514 if (interworking_fetch_anqp(wpa_s) < 0)
6516 } else if (os_strcmp(buf, "STOP_FETCH_ANQP") == 0) {
6517 interworking_stop_fetch_anqp(wpa_s);
6518 } else if (os_strcmp(buf, "INTERWORKING_SELECT") == 0) {
6519 if (ctrl_interworking_select(wpa_s, NULL) < 0)
6521 } else if (os_strncmp(buf, "INTERWORKING_SELECT ", 20) == 0) {
6522 if (ctrl_interworking_select(wpa_s, buf + 20) < 0)
6524 } else if (os_strncmp(buf, "INTERWORKING_CONNECT ", 21) == 0) {
6525 if (ctrl_interworking_connect(wpa_s, buf + 21) < 0)
6527 } else if (os_strncmp(buf, "ANQP_GET ", 9) == 0) {
6528 if (get_anqp(wpa_s, buf + 9) < 0)
6530 } else if (os_strncmp(buf, "GAS_REQUEST ", 12) == 0) {
6531 if (gas_request(wpa_s, buf + 12) < 0)
6533 } else if (os_strncmp(buf, "GAS_RESPONSE_GET ", 17) == 0) {
6534 reply_len = gas_response_get(wpa_s, buf + 17, reply,
6536 #endif /* CONFIG_INTERWORKING */
6538 } else if (os_strncmp(buf, "HS20_ANQP_GET ", 14) == 0) {
6539 if (get_hs20_anqp(wpa_s, buf + 14) < 0)
6541 } else if (os_strncmp(buf, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
6542 if (hs20_get_nai_home_realm_list(wpa_s, buf + 29) < 0)
6544 } else if (os_strncmp(buf, "HS20_ICON_REQUEST ", 18) == 0) {
6545 if (hs20_icon_request(wpa_s, buf + 18) < 0)
6547 } else if (os_strcmp(buf, "FETCH_OSU") == 0) {
6548 if (hs20_fetch_osu(wpa_s) < 0)
6550 } else if (os_strcmp(buf, "CANCEL_FETCH_OSU") == 0) {
6551 hs20_cancel_fetch_osu(wpa_s);
6552 #endif /* CONFIG_HS20 */
6553 } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0)
6555 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
6556 wpa_s, buf + os_strlen(WPA_CTRL_RSP)))
6560 * Notify response from timeout to allow the control
6561 * interface response to be sent first.
6563 eloop_register_timeout(0, 0, wpas_ctrl_eapol_response,
6566 } else if (os_strcmp(buf, "RECONFIGURE") == 0) {
6567 if (wpa_supplicant_reload_configuration(wpa_s))
6569 } else if (os_strcmp(buf, "TERMINATE") == 0) {
6570 wpa_supplicant_terminate_proc(wpa_s->global);
6571 } else if (os_strncmp(buf, "BSSID ", 6) == 0) {
6572 if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6))
6574 } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) {
6575 reply_len = wpa_supplicant_ctrl_iface_blacklist(
6576 wpa_s, buf + 9, reply, reply_size);
6577 } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) {
6578 reply_len = wpa_supplicant_ctrl_iface_log_level(
6579 wpa_s, buf + 9, reply, reply_size);
6580 } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) {
6581 reply_len = wpa_supplicant_ctrl_iface_list_networks(
6582 wpa_s, reply, reply_size);
6583 } else if (os_strcmp(buf, "DISCONNECT") == 0) {
6585 wpa_s->sme.prev_bssid_set = 0;
6586 #endif /* CONFIG_SME */
6587 wpa_s->reassociate = 0;
6588 wpa_s->disconnected = 1;
6589 wpa_supplicant_cancel_sched_scan(wpa_s);
6590 wpa_supplicant_cancel_scan(wpa_s);
6591 wpa_supplicant_deauthenticate(wpa_s,
6592 WLAN_REASON_DEAUTH_LEAVING);
6593 } else if (os_strcmp(buf, "SCAN") == 0) {
6594 wpas_ctrl_scan(wpa_s, NULL, reply, reply_size, &reply_len);
6595 } else if (os_strncmp(buf, "SCAN ", 5) == 0) {
6596 wpas_ctrl_scan(wpa_s, buf + 5, reply, reply_size, &reply_len);
6597 } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) {
6598 reply_len = wpa_supplicant_ctrl_iface_scan_results(
6599 wpa_s, reply, reply_size);
6600 } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) {
6601 if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15))
6603 } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) {
6604 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15))
6606 } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) {
6607 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16))
6609 } else if (os_strcmp(buf, "ADD_NETWORK") == 0) {
6610 reply_len = wpa_supplicant_ctrl_iface_add_network(
6611 wpa_s, reply, reply_size);
6612 } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) {
6613 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15))
6615 } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
6616 if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12))
6618 } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) {
6619 reply_len = wpa_supplicant_ctrl_iface_get_network(
6620 wpa_s, buf + 12, reply, reply_size);
6621 } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) {
6622 if (wpa_supplicant_ctrl_iface_dup_network(wpa_s, buf + 12))
6624 } else if (os_strcmp(buf, "LIST_CREDS") == 0) {
6625 reply_len = wpa_supplicant_ctrl_iface_list_creds(
6626 wpa_s, reply, reply_size);
6627 } else if (os_strcmp(buf, "ADD_CRED") == 0) {
6628 reply_len = wpa_supplicant_ctrl_iface_add_cred(
6629 wpa_s, reply, reply_size);
6630 } else if (os_strncmp(buf, "REMOVE_CRED ", 12) == 0) {
6631 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s, buf + 12))
6633 } else if (os_strncmp(buf, "SET_CRED ", 9) == 0) {
6634 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s, buf + 9))
6636 } else if (os_strncmp(buf, "GET_CRED ", 9) == 0) {
6637 reply_len = wpa_supplicant_ctrl_iface_get_cred(wpa_s, buf + 9,
6640 #ifndef CONFIG_NO_CONFIG_WRITE
6641 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
6642 if (wpa_supplicant_ctrl_iface_save_config(wpa_s))
6644 #endif /* CONFIG_NO_CONFIG_WRITE */
6645 } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
6646 reply_len = wpa_supplicant_ctrl_iface_get_capability(
6647 wpa_s, buf + 15, reply, reply_size);
6648 } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) {
6649 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8))
6651 } else if (os_strncmp(buf, "SCAN_INTERVAL ", 14) == 0) {
6652 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s, buf + 14))
6654 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
6655 reply_len = wpa_supplicant_global_iface_list(
6656 wpa_s->global, reply, reply_size);
6657 } else if (os_strcmp(buf, "INTERFACES") == 0) {
6658 reply_len = wpa_supplicant_global_iface_interfaces(
6659 wpa_s->global, reply, reply_size);
6660 } else if (os_strncmp(buf, "BSS ", 4) == 0) {
6661 reply_len = wpa_supplicant_ctrl_iface_bss(
6662 wpa_s, buf + 4, reply, reply_size);
6664 } else if (os_strcmp(buf, "STA-FIRST") == 0) {
6665 reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size);
6666 } else if (os_strncmp(buf, "STA ", 4) == 0) {
6667 reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply,
6669 } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) {
6670 reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply,
6672 } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) {
6673 if (ap_ctrl_iface_sta_deauthenticate(wpa_s, buf + 15))
6675 } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) {
6676 if (ap_ctrl_iface_sta_disassociate(wpa_s, buf + 13))
6678 } else if (os_strncmp(buf, "CHAN_SWITCH ", 12) == 0) {
6679 if (ap_ctrl_iface_chanswitch(wpa_s, buf + 12))
6681 #endif /* CONFIG_AP */
6682 } else if (os_strcmp(buf, "SUSPEND") == 0) {
6683 wpas_notify_suspend(wpa_s->global);
6684 } else if (os_strcmp(buf, "RESUME") == 0) {
6685 wpas_notify_resume(wpa_s->global);
6686 #ifdef CONFIG_TESTING_OPTIONS
6687 } else if (os_strcmp(buf, "DROP_SA") == 0) {
6688 wpa_supplicant_ctrl_iface_drop_sa(wpa_s);
6689 #endif /* CONFIG_TESTING_OPTIONS */
6690 } else if (os_strncmp(buf, "ROAM ", 5) == 0) {
6691 if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5))
6693 } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) {
6694 if (wpa_supplicant_ctrl_iface_sta_autoconnect(wpa_s, buf + 16))
6696 } else if (os_strncmp(buf, "BSS_EXPIRE_AGE ", 15) == 0) {
6697 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s, buf + 15))
6699 } else if (os_strncmp(buf, "BSS_EXPIRE_COUNT ", 17) == 0) {
6700 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s,
6703 } else if (os_strncmp(buf, "BSS_FLUSH ", 10) == 0) {
6704 if (wpa_supplicant_ctrl_iface_bss_flush(wpa_s, buf + 10))
6707 } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) {
6708 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14))
6710 } else if (os_strncmp(buf, "TDLS_SETUP ", 11) == 0) {
6711 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s, buf + 11))
6713 } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) {
6714 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14))
6716 #endif /* CONFIG_TDLS */
6717 } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) {
6718 reply_len = wpa_supplicant_signal_poll(wpa_s, reply,
6720 } else if (os_strncmp(buf, "PKTCNT_POLL", 11) == 0) {
6721 reply_len = wpa_supplicant_pktcnt_poll(wpa_s, reply,
6723 #ifdef CONFIG_AUTOSCAN
6724 } else if (os_strncmp(buf, "AUTOSCAN ", 9) == 0) {
6725 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s, buf + 9))
6727 #endif /* CONFIG_AUTOSCAN */
6729 } else if (os_strncmp(buf, "DRIVER ", 7) == 0) {
6730 reply_len = wpa_supplicant_driver_cmd(wpa_s, buf + 7, reply,
6732 #endif /* ANDROID */
6733 } else if (os_strncmp(buf, "VENDOR ", 7) == 0) {
6734 reply_len = wpa_supplicant_vendor_cmd(wpa_s, buf + 7, reply,
6736 } else if (os_strcmp(buf, "REAUTHENTICATE") == 0) {
6737 pmksa_cache_clear_current(wpa_s->wpa);
6738 eapol_sm_request_reauth(wpa_s->eapol);
6740 } else if (os_strncmp(buf, "WNM_SLEEP ", 10) == 0) {
6741 if (wpas_ctrl_iface_wnm_sleep(wpa_s, buf + 10))
6743 } else if (os_strncmp(buf, "WNM_BSS_QUERY ", 10) == 0) {
6744 if (wpas_ctrl_iface_wnm_bss_query(wpa_s, buf + 10))
6746 #endif /* CONFIG_WNM */
6747 } else if (os_strcmp(buf, "FLUSH") == 0) {
6748 wpa_supplicant_ctrl_iface_flush(wpa_s);
6749 } else if (os_strncmp(buf, "RADIO_WORK ", 11) == 0) {
6750 reply_len = wpas_ctrl_radio_work(wpa_s, buf + 11, reply,
6752 #ifdef CONFIG_TESTING_OPTIONS
6753 } else if (os_strncmp(buf, "MGMT_TX ", 8) == 0) {
6754 if (wpas_ctrl_iface_mgmt_tx(wpa_s, buf + 8) < 0)
6756 } else if (os_strcmp(buf, "MGMT_TX_DONE") == 0) {
6757 wpas_ctrl_iface_mgmt_tx_done(wpa_s);
6758 } else if (os_strncmp(buf, "DRIVER_EVENT ", 13) == 0) {
6759 if (wpas_ctrl_iface_driver_event(wpa_s, buf + 13) < 0)
6761 #endif /* CONFIG_TESTING_OPTIONS */
6763 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
6767 if (reply_len < 0) {
6768 os_memcpy(reply, "FAIL\n", 5);
6772 *resp_len = reply_len;
6777 static int wpa_supplicant_global_iface_add(struct wpa_global *global,
6780 struct wpa_interface iface;
6784 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
6785 * TAB<bridge_ifname>
6787 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd);
6789 os_memset(&iface, 0, sizeof(iface));
6792 iface.ifname = pos = cmd;
6793 pos = os_strchr(pos, '\t');
6796 if (iface.ifname[0] == '\0')
6801 iface.confname = pos;
6802 pos = os_strchr(pos, '\t');
6805 if (iface.confname[0] == '\0')
6806 iface.confname = NULL;
6811 pos = os_strchr(pos, '\t');
6814 if (iface.driver[0] == '\0')
6815 iface.driver = NULL;
6819 iface.ctrl_interface = pos;
6820 pos = os_strchr(pos, '\t');
6823 if (iface.ctrl_interface[0] == '\0')
6824 iface.ctrl_interface = NULL;
6828 iface.driver_param = pos;
6829 pos = os_strchr(pos, '\t');
6832 if (iface.driver_param[0] == '\0')
6833 iface.driver_param = NULL;
6837 iface.bridge_ifname = pos;
6838 pos = os_strchr(pos, '\t');
6841 if (iface.bridge_ifname[0] == '\0')
6842 iface.bridge_ifname = NULL;
6847 if (wpa_supplicant_get_iface(global, iface.ifname))
6850 return wpa_supplicant_add_iface(global, &iface) ? 0 : -1;
6854 static int wpa_supplicant_global_iface_remove(struct wpa_global *global,
6857 struct wpa_supplicant *wpa_s;
6859 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd);
6861 wpa_s = wpa_supplicant_get_iface(global, cmd);
6864 return wpa_supplicant_remove_iface(global, wpa_s, 0);
6868 static void wpa_free_iface_info(struct wpa_interface_info *iface)
6870 struct wpa_interface_info *prev;
6874 iface = iface->next;
6876 os_free(prev->ifname);
6877 os_free(prev->desc);
6883 static int wpa_supplicant_global_iface_list(struct wpa_global *global,
6887 struct wpa_interface_info *iface = NULL, *last = NULL, *tmp;
6890 for (i = 0; wpa_drivers[i]; i++) {
6891 struct wpa_driver_ops *drv = wpa_drivers[i];
6892 if (drv->get_interfaces == NULL)
6894 tmp = drv->get_interfaces(global->drv_priv[i]);
6908 for (tmp = iface; tmp; tmp = tmp->next) {
6909 res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n",
6910 tmp->drv_name, tmp->ifname,
6911 tmp->desc ? tmp->desc : "");
6912 if (res < 0 || res >= end - pos) {
6919 wpa_free_iface_info(iface);
6925 static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
6930 struct wpa_supplicant *wpa_s;
6932 wpa_s = global->ifaces;
6937 res = os_snprintf(pos, end - pos, "%s\n", wpa_s->ifname);
6938 if (res < 0 || res >= end - pos) {
6943 wpa_s = wpa_s->next;
6949 static char * wpas_global_ctrl_iface_ifname(struct wpa_global *global,
6951 char *cmd, size_t *resp_len)
6953 struct wpa_supplicant *wpa_s;
6955 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
6956 if (os_strcmp(ifname, wpa_s->ifname) == 0)
6960 if (wpa_s == NULL) {
6961 char *resp = os_strdup("FAIL-NO-IFNAME-MATCH\n");
6963 *resp_len = os_strlen(resp);
6969 return wpa_supplicant_ctrl_iface_process(wpa_s, cmd, resp_len);
6973 static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global *global,
6974 char *buf, size_t *resp_len)
6977 static const char * cmd[] = {
6983 "P2P_GET_PASSPHRASE",
6984 "P2P_SERVICE_UPDATE",
6985 "P2P_SERVICE_FLUSH",
6992 static const char * prefix[] = {
6995 #endif /* ANDROID */
7001 "P2P_GROUP_REMOVE ",
7004 "P2P_SERV_DISC_REQ ",
7005 "P2P_SERV_DISC_CANCEL_REQ ",
7006 "P2P_SERV_DISC_RESP ",
7007 "P2P_SERV_DISC_EXTERNAL ",
7015 "P2P_PRESENCE_REQ ",
7017 "P2P_REMOVE_CLIENT ",
7018 "NFC_GET_HANDOVER_SEL ",
7019 "NFC_GET_HANDOVER_REQ ",
7020 "NFC_REPORT_HANDOVER ",
7026 if (global->p2p_init_wpa_s == NULL)
7029 for (i = 0; !found && cmd[i]; i++) {
7030 if (os_strcmp(buf, cmd[i]) == 0)
7034 for (i = 0; !found && prefix[i]; i++) {
7035 if (os_strncmp(buf, prefix[i], os_strlen(prefix[i])) == 0)
7040 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
7042 #endif /* CONFIG_P2P */
7047 static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global *global,
7048 char *buf, size_t *resp_len)
7050 #ifdef CONFIG_WIFI_DISPLAY
7051 if (global->p2p_init_wpa_s == NULL)
7053 if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0 ||
7054 os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0)
7055 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
7057 #endif /* CONFIG_WIFI_DISPLAY */
7062 static char * wpas_global_ctrl_iface_redir(struct wpa_global *global,
7063 char *buf, size_t *resp_len)
7067 ret = wpas_global_ctrl_iface_redir_p2p(global, buf, resp_len);
7071 ret = wpas_global_ctrl_iface_redir_wfd(global, buf, resp_len);
7079 static int wpas_global_ctrl_iface_set(struct wpa_global *global, char *cmd)
7083 value = os_strchr(cmd, ' ');
7088 wpa_printf(MSG_DEBUG, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd, value);
7090 #ifdef CONFIG_WIFI_DISPLAY
7091 if (os_strcasecmp(cmd, "wifi_display") == 0) {
7092 wifi_display_enable(global, !!atoi(value));
7095 #endif /* CONFIG_WIFI_DISPLAY */
7097 /* Restore cmd to its original value to allow redirection */
7104 #ifndef CONFIG_NO_CONFIG_WRITE
7105 static int wpas_global_ctrl_iface_save_config(struct wpa_global *global)
7107 int ret = 0, saved = 0;
7108 struct wpa_supplicant *wpa_s;
7110 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
7111 if (!wpa_s->conf->update_config) {
7112 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
7116 if (wpa_config_write(wpa_s->confname, wpa_s->conf)) {
7117 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
7120 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
7125 if (!saved && !ret) {
7126 wpa_dbg(wpa_s, MSG_DEBUG,
7127 "CTRL_IFACE: SAVE_CONFIG - No configuration files could be updated");
7133 #endif /* CONFIG_NO_CONFIG_WRITE */
7136 static int wpas_global_ctrl_iface_status(struct wpa_global *global,
7137 char *buf, size_t buflen)
7141 struct wpa_supplicant *wpa_s;
7147 if (global->p2p && !global->p2p_disabled) {
7148 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
7151 MAC2STR(global->p2p_dev_addr),
7152 p2p_get_state_txt(global->p2p));
7153 if (ret < 0 || ret >= end - pos)
7156 } else if (global->p2p) {
7157 ret = os_snprintf(pos, end - pos, "p2p_state=DISABLED\n");
7158 if (ret < 0 || ret >= end - pos)
7162 #endif /* CONFIG_P2P */
7164 #ifdef CONFIG_WIFI_DISPLAY
7165 ret = os_snprintf(pos, end - pos, "wifi_display=%d\n",
7166 !!global->wifi_display);
7167 if (ret < 0 || ret >= end - pos)
7170 #endif /* CONFIG_WIFI_DISPLAY */
7172 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
7173 ret = os_snprintf(pos, end - pos, "ifname=%s\n"
7174 "address=" MACSTR "\n",
7175 wpa_s->ifname, MAC2STR(wpa_s->own_addr));
7176 if (ret < 0 || ret >= end - pos)
7185 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
7186 char *buf, size_t *resp_len)
7189 const int reply_size = 2048;
7191 int level = MSG_DEBUG;
7193 if (os_strncmp(buf, "IFNAME=", 7) == 0) {
7194 char *pos = os_strchr(buf + 7, ' ');
7197 return wpas_global_ctrl_iface_ifname(global,
7203 reply = wpas_global_ctrl_iface_redir(global, buf, resp_len);
7207 if (os_strcmp(buf, "PING") == 0)
7208 level = MSG_EXCESSIVE;
7209 wpa_hexdump_ascii(level, "RX global ctrl_iface",
7210 (const u8 *) buf, os_strlen(buf));
7212 reply = os_malloc(reply_size);
7213 if (reply == NULL) {
7218 os_memcpy(reply, "OK\n", 3);
7221 if (os_strcmp(buf, "PING") == 0) {
7222 os_memcpy(reply, "PONG\n", 5);
7224 } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) {
7225 if (wpa_supplicant_global_iface_add(global, buf + 14))
7227 } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) {
7228 if (wpa_supplicant_global_iface_remove(global, buf + 17))
7230 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
7231 reply_len = wpa_supplicant_global_iface_list(
7232 global, reply, reply_size);
7233 } else if (os_strcmp(buf, "INTERFACES") == 0) {
7234 reply_len = wpa_supplicant_global_iface_interfaces(
7235 global, reply, reply_size);
7236 } else if (os_strcmp(buf, "TERMINATE") == 0) {
7237 wpa_supplicant_terminate_proc(global);
7238 } else if (os_strcmp(buf, "SUSPEND") == 0) {
7239 wpas_notify_suspend(global);
7240 } else if (os_strcmp(buf, "RESUME") == 0) {
7241 wpas_notify_resume(global);
7242 } else if (os_strncmp(buf, "SET ", 4) == 0) {
7243 if (wpas_global_ctrl_iface_set(global, buf + 4)) {
7245 if (global->p2p_init_wpa_s) {
7247 /* Check if P2P redirection would work for this
7249 return wpa_supplicant_ctrl_iface_process(
7250 global->p2p_init_wpa_s,
7253 #endif /* CONFIG_P2P */
7256 #ifndef CONFIG_NO_CONFIG_WRITE
7257 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
7258 if (wpas_global_ctrl_iface_save_config(global))
7260 #endif /* CONFIG_NO_CONFIG_WRITE */
7261 } else if (os_strcmp(buf, "STATUS") == 0) {
7262 reply_len = wpas_global_ctrl_iface_status(global, reply,
7264 #ifdef CONFIG_MODULE_TESTS
7265 } else if (os_strcmp(buf, "MODULE_TESTS") == 0) {
7266 int wpas_module_tests(void);
7267 if (wpas_module_tests() < 0)
7269 #endif /* CONFIG_MODULE_TESTS */
7271 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
7275 if (reply_len < 0) {
7276 os_memcpy(reply, "FAIL\n", 5);
7280 *resp_len = reply_len;