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"
44 static int wpa_supplicant_global_iface_list(struct wpa_global *global,
46 static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
50 static int pno_start(struct wpa_supplicant *wpa_s)
54 struct wpa_ssid *ssid;
55 struct wpa_driver_scan_params params;
57 if (wpa_s->pno || wpa_s->pno_sched_pending)
60 if ((wpa_s->wpa_state > WPA_SCANNING) &&
61 (wpa_s->wpa_state <= WPA_COMPLETED)) {
62 wpa_printf(MSG_ERROR, "PNO: In assoc process");
66 if (wpa_s->wpa_state == WPA_SCANNING) {
67 wpa_supplicant_cancel_scan(wpa_s);
68 if (wpa_s->sched_scanning) {
69 wpa_printf(MSG_DEBUG, "Schedule PNO on completion of "
70 "ongoing sched scan");
71 wpa_supplicant_cancel_sched_scan(wpa_s);
72 wpa_s->pno_sched_pending = 1;
77 os_memset(¶ms, 0, sizeof(params));
80 ssid = wpa_s->conf->ssid;
82 if (!wpas_network_disabled(wpa_s, ssid))
86 if (num_ssid > WPAS_MAX_SCAN_SSIDS) {
87 wpa_printf(MSG_DEBUG, "PNO: Use only the first %u SSIDs from "
88 "%u", WPAS_MAX_SCAN_SSIDS, (unsigned int) num_ssid);
89 num_ssid = WPAS_MAX_SCAN_SSIDS;
93 wpa_printf(MSG_DEBUG, "PNO: No configured SSIDs");
97 params.filter_ssids = os_malloc(sizeof(struct wpa_driver_scan_filter) *
99 if (params.filter_ssids == NULL)
102 ssid = wpa_s->conf->ssid;
104 if (!wpas_network_disabled(wpa_s, ssid)) {
105 params.ssids[i].ssid = ssid->ssid;
106 params.ssids[i].ssid_len = ssid->ssid_len;
108 os_memcpy(params.filter_ssids[i].ssid, ssid->ssid,
110 params.filter_ssids[i].ssid_len = ssid->ssid_len;
111 params.num_filter_ssids++;
119 if (wpa_s->conf->filter_rssi)
120 params.filter_rssi = wpa_s->conf->filter_rssi;
122 interval = wpa_s->conf->sched_scan_interval ?
123 wpa_s->conf->sched_scan_interval : 10;
125 ret = wpa_supplicant_start_sched_scan(wpa_s, ¶ms, interval);
126 os_free(params.filter_ssids);
133 static int pno_stop(struct wpa_supplicant *wpa_s)
137 if (wpa_s->pno || wpa_s->sched_scanning) {
139 ret = wpa_supplicant_stop_sched_scan(wpa_s);
142 wpa_s->pno_sched_pending = 0;
144 if (wpa_s->wpa_state == WPA_SCANNING)
145 wpa_supplicant_req_scan(wpa_s, 0, 0);
151 static int set_bssid_filter(struct wpa_supplicant *wpa_s, char *val)
154 u8 addr[ETH_ALEN], *filter = NULL, *n;
161 if (hwaddr_aton(pos, addr)) {
165 n = os_realloc_array(filter, count + 1, ETH_ALEN);
171 os_memcpy(filter + count * ETH_ALEN, addr, ETH_ALEN);
174 pos = os_strchr(pos, ' ');
179 wpa_hexdump(MSG_DEBUG, "bssid_filter", filter, count * ETH_ALEN);
180 os_free(wpa_s->bssid_filter);
181 wpa_s->bssid_filter = filter;
182 wpa_s->bssid_filter_count = count;
188 static int set_disallow_aps(struct wpa_supplicant *wpa_s, char *val)
191 u8 addr[ETH_ALEN], *bssid = NULL, *n;
192 struct wpa_ssid_value *ssid = NULL, *ns;
193 size_t count = 0, ssid_count = 0;
197 * disallow_list ::= <ssid_spec> | <bssid_spec> | <disallow_list> | ""
198 * SSID_SPEC ::= ssid <SSID_HEX>
199 * BSSID_SPEC ::= bssid <BSSID_HEX>
206 if (os_strncmp(pos, "bssid ", 6) == 0) {
209 res = hwaddr_aton2(pos, addr);
213 wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
214 "BSSID value '%s'", pos);
218 n = os_realloc_array(bssid, count + 1, ETH_ALEN);
225 os_memcpy(bssid + count * ETH_ALEN, addr, ETH_ALEN);
227 } else if (os_strncmp(pos, "ssid ", 5) == 0) {
233 if (*end == '\0' || *end == ' ')
238 ns = os_realloc_array(ssid, ssid_count + 1,
239 sizeof(struct wpa_ssid_value));
247 if ((end - pos) & 0x01 || end - pos > 2 * 32 ||
248 hexstr2bin(pos, ssid[ssid_count].ssid,
249 (end - pos) / 2) < 0) {
252 wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
253 "SSID value '%s'", pos);
256 ssid[ssid_count].ssid_len = (end - pos) / 2;
257 wpa_hexdump_ascii(MSG_DEBUG, "disallow_aps SSID",
258 ssid[ssid_count].ssid,
259 ssid[ssid_count].ssid_len);
263 wpa_printf(MSG_DEBUG, "Unexpected disallow_aps value "
270 pos = os_strchr(pos, ' ');
275 wpa_hexdump(MSG_DEBUG, "disallow_aps_bssid", bssid, count * ETH_ALEN);
276 os_free(wpa_s->disallow_aps_bssid);
277 wpa_s->disallow_aps_bssid = bssid;
278 wpa_s->disallow_aps_bssid_count = count;
280 wpa_printf(MSG_DEBUG, "disallow_aps_ssid_count %d", (int) ssid_count);
281 os_free(wpa_s->disallow_aps_ssid);
282 wpa_s->disallow_aps_ssid = ssid;
283 wpa_s->disallow_aps_ssid_count = ssid_count;
285 if (!wpa_s->current_ssid || wpa_s->wpa_state < WPA_AUTHENTICATING)
288 c = wpa_s->current_ssid;
289 if (c->mode != WPAS_MODE_INFRA && c->mode != WPAS_MODE_IBSS)
292 if (!disallowed_bssid(wpa_s, wpa_s->bssid) &&
293 !disallowed_ssid(wpa_s, c->ssid, c->ssid_len))
296 wpa_printf(MSG_DEBUG, "Disconnect and try to find another network "
297 "because current AP was marked disallowed");
300 wpa_s->sme.prev_bssid_set = 0;
301 #endif /* CONFIG_SME */
302 wpa_s->reassociate = 1;
303 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
304 wpa_supplicant_req_scan(wpa_s, 0, 0);
310 static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s,
316 value = os_strchr(cmd, ' ');
321 wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value);
322 if (os_strcasecmp(cmd, "EAPOL::heldPeriod") == 0) {
323 eapol_sm_configure(wpa_s->eapol,
324 atoi(value), -1, -1, -1);
325 } else if (os_strcasecmp(cmd, "EAPOL::authPeriod") == 0) {
326 eapol_sm_configure(wpa_s->eapol,
327 -1, atoi(value), -1, -1);
328 } else if (os_strcasecmp(cmd, "EAPOL::startPeriod") == 0) {
329 eapol_sm_configure(wpa_s->eapol,
330 -1, -1, atoi(value), -1);
331 } else if (os_strcasecmp(cmd, "EAPOL::maxStart") == 0) {
332 eapol_sm_configure(wpa_s->eapol,
333 -1, -1, -1, atoi(value));
334 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKLifetime") == 0) {
335 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME,
338 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKReauthThreshold") ==
340 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD,
343 } else if (os_strcasecmp(cmd, "dot11RSNAConfigSATimeout") == 0) {
344 if (wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, atoi(value)))
346 } else if (os_strcasecmp(cmd, "wps_fragment_size") == 0) {
347 wpa_s->wps_fragment_size = atoi(value);
348 #ifdef CONFIG_WPS_TESTING
349 } else if (os_strcasecmp(cmd, "wps_version_number") == 0) {
351 val = strtol(value, NULL, 0);
352 if (val < 0 || val > 0xff) {
354 wpa_printf(MSG_DEBUG, "WPS: Invalid "
355 "wps_version_number %ld", val);
357 wps_version_number = val;
358 wpa_printf(MSG_DEBUG, "WPS: Testing - force WPS "
360 (wps_version_number & 0xf0) >> 4,
361 wps_version_number & 0x0f);
363 } else if (os_strcasecmp(cmd, "wps_testing_dummy_cred") == 0) {
364 wps_testing_dummy_cred = atoi(value);
365 wpa_printf(MSG_DEBUG, "WPS: Testing - dummy_cred=%d",
366 wps_testing_dummy_cred);
367 } else if (os_strcasecmp(cmd, "wps_corrupt_pkhash") == 0) {
368 wps_corrupt_pkhash = atoi(value);
369 wpa_printf(MSG_DEBUG, "WPS: Testing - wps_corrupt_pkhash=%d",
371 #endif /* CONFIG_WPS_TESTING */
372 } else if (os_strcasecmp(cmd, "ampdu") == 0) {
373 if (wpa_drv_ampdu(wpa_s, atoi(value)) < 0)
376 #ifdef CONFIG_TDLS_TESTING
377 } else if (os_strcasecmp(cmd, "tdls_testing") == 0) {
378 extern unsigned int tdls_testing;
379 tdls_testing = strtol(value, NULL, 0);
380 wpa_printf(MSG_DEBUG, "TDLS: tdls_testing=0x%x", tdls_testing);
381 #endif /* CONFIG_TDLS_TESTING */
382 } else if (os_strcasecmp(cmd, "tdls_disabled") == 0) {
383 int disabled = atoi(value);
384 wpa_printf(MSG_DEBUG, "TDLS: tdls_disabled=%d", disabled);
386 if (wpa_drv_tdls_oper(wpa_s, TDLS_DISABLE, NULL) < 0)
388 } else if (wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL) < 0)
390 wpa_tdls_enable(wpa_s->wpa, !disabled);
391 #endif /* CONFIG_TDLS */
392 } else if (os_strcasecmp(cmd, "pno") == 0) {
394 ret = pno_start(wpa_s);
396 ret = pno_stop(wpa_s);
397 } else if (os_strcasecmp(cmd, "radio_disabled") == 0) {
398 int disabled = atoi(value);
399 if (wpa_drv_radio_disable(wpa_s, disabled) < 0)
402 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
403 } else if (os_strcasecmp(cmd, "uapsd") == 0) {
404 if (os_strcmp(value, "disable") == 0)
405 wpa_s->set_sta_uapsd = 0;
409 /* format: BE,BK,VI,VO;max SP Length */
411 pos = os_strchr(value, ',');
416 pos = os_strchr(pos, ',');
421 pos = os_strchr(pos, ',');
426 /* ignore max SP Length for now */
428 wpa_s->set_sta_uapsd = 1;
429 wpa_s->sta_uapsd = 0;
431 wpa_s->sta_uapsd |= BIT(0);
433 wpa_s->sta_uapsd |= BIT(1);
435 wpa_s->sta_uapsd |= BIT(2);
437 wpa_s->sta_uapsd |= BIT(3);
439 } else if (os_strcasecmp(cmd, "ps") == 0) {
440 ret = wpa_drv_set_p2p_powersave(wpa_s, atoi(value), -1, -1);
441 #ifdef CONFIG_WIFI_DISPLAY
442 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
443 int enabled = !!atoi(value);
444 if (enabled && !wpa_s->global->p2p)
447 wifi_display_enable(wpa_s->global, enabled);
448 #endif /* CONFIG_WIFI_DISPLAY */
449 } else if (os_strcasecmp(cmd, "bssid_filter") == 0) {
450 ret = set_bssid_filter(wpa_s, value);
451 } else if (os_strcasecmp(cmd, "disallow_aps") == 0) {
452 ret = set_disallow_aps(wpa_s, value);
453 } else if (os_strcasecmp(cmd, "no_keep_alive") == 0) {
454 wpa_s->no_keep_alive = !!atoi(value);
457 ret = wpa_config_process_global(wpa_s->conf, cmd, -1);
459 wpa_supplicant_update_config(wpa_s);
466 static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s,
467 char *cmd, char *buf, size_t buflen)
471 wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd);
473 if (os_strcmp(cmd, "version") == 0) {
474 res = os_snprintf(buf, buflen, "%s", VERSION_STR);
475 } else if (os_strcasecmp(cmd, "country") == 0) {
476 if (wpa_s->conf->country[0] && wpa_s->conf->country[1])
477 res = os_snprintf(buf, buflen, "%c%c",
478 wpa_s->conf->country[0],
479 wpa_s->conf->country[1]);
480 #ifdef CONFIG_WIFI_DISPLAY
481 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
483 if (wpa_s->global->p2p == NULL ||
484 wpa_s->global->p2p_disabled)
487 enabled = wpa_s->global->wifi_display;
488 res = os_snprintf(buf, buflen, "%d", enabled);
489 if (res < 0 || (unsigned int) res >= buflen)
492 #endif /* CONFIG_WIFI_DISPLAY */
493 #ifdef CONFIG_TESTING_GET_GTK
494 } else if (os_strcmp(cmd, "gtk") == 0) {
495 if (wpa_s->last_gtk_len == 0)
497 res = wpa_snprintf_hex(buf, buflen, wpa_s->last_gtk,
498 wpa_s->last_gtk_len);
500 #endif /* CONFIG_TESTING_GET_GTK */
503 if (res < 0 || (unsigned int) res >= buflen)
509 #ifdef IEEE8021X_EAPOL
510 static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s,
514 struct wpa_ssid *ssid = wpa_s->current_ssid;
516 if (hwaddr_aton(addr, bssid)) {
517 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address "
522 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid));
523 rsn_preauth_deinit(wpa_s->wpa);
524 if (rsn_preauth_init(wpa_s->wpa, bssid, ssid ? &ssid->eap : NULL))
529 #endif /* IEEE8021X_EAPOL */
532 #ifdef CONFIG_PEERKEY
533 /* MLME-STKSTART.request(peer) */
534 static int wpa_supplicant_ctrl_iface_stkstart(
535 struct wpa_supplicant *wpa_s, char *addr)
539 if (hwaddr_aton(addr, peer)) {
540 wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART: invalid "
541 "address '%s'", addr);
545 wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART " MACSTR,
548 return wpa_sm_stkstart(wpa_s->wpa, peer);
550 #endif /* CONFIG_PEERKEY */
555 static int wpa_supplicant_ctrl_iface_tdls_discover(
556 struct wpa_supplicant *wpa_s, char *addr)
561 if (hwaddr_aton(addr, peer)) {
562 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER: invalid "
563 "address '%s'", addr);
567 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER " MACSTR,
570 if (wpa_tdls_is_external_setup(wpa_s->wpa))
571 ret = wpa_tdls_send_discovery_request(wpa_s->wpa, peer);
573 ret = wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer);
579 static int wpa_supplicant_ctrl_iface_tdls_setup(
580 struct wpa_supplicant *wpa_s, char *addr)
585 if (hwaddr_aton(addr, peer)) {
586 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP: invalid "
587 "address '%s'", addr);
591 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP " MACSTR,
594 if ((wpa_s->conf->tdls_external_control) &&
595 wpa_tdls_is_external_setup(wpa_s->wpa))
596 return wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
598 wpa_tdls_remove(wpa_s->wpa, peer);
600 if (wpa_tdls_is_external_setup(wpa_s->wpa))
601 ret = wpa_tdls_start(wpa_s->wpa, peer);
603 ret = wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
609 static int wpa_supplicant_ctrl_iface_tdls_teardown(
610 struct wpa_supplicant *wpa_s, char *addr)
615 if (hwaddr_aton(addr, peer)) {
616 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN: invalid "
617 "address '%s'", addr);
621 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN " MACSTR,
624 if ((wpa_s->conf->tdls_external_control) &&
625 wpa_tdls_is_external_setup(wpa_s->wpa))
626 return wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
628 if (wpa_tdls_is_external_setup(wpa_s->wpa))
629 ret = wpa_tdls_teardown_link(
631 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED);
633 ret = wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
638 #endif /* CONFIG_TDLS */
641 #ifdef CONFIG_IEEE80211R
642 static int wpa_supplicant_ctrl_iface_ft_ds(
643 struct wpa_supplicant *wpa_s, char *addr)
645 u8 target_ap[ETH_ALEN];
649 if (hwaddr_aton(addr, target_ap)) {
650 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid "
651 "address '%s'", addr);
655 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap));
657 bss = wpa_bss_get_bssid(wpa_s, target_ap);
659 mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN);
663 return wpa_ft_start_over_ds(wpa_s->wpa, target_ap, mdie);
665 #endif /* CONFIG_IEEE80211R */
669 static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s,
672 u8 bssid[ETH_ALEN], *_bssid = bssid;
674 u8 p2p_dev_addr[ETH_ALEN];
675 #endif /* CONFIG_P2P */
677 u8 *_p2p_dev_addr = NULL;
678 #endif /* CONFIG_AP */
680 if (cmd == NULL || os_strcmp(cmd, "any") == 0) {
683 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
684 if (hwaddr_aton(cmd + 13, p2p_dev_addr)) {
685 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid "
686 "P2P Device Address '%s'",
690 _p2p_dev_addr = p2p_dev_addr;
691 #endif /* CONFIG_P2P */
692 } else if (hwaddr_aton(cmd, bssid)) {
693 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
700 return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid, _p2p_dev_addr);
701 #endif /* CONFIG_AP */
703 return wpas_wps_start_pbc(wpa_s, _bssid, 0);
707 static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s,
708 char *cmd, char *buf,
711 u8 bssid[ETH_ALEN], *_bssid = bssid;
715 pin = os_strchr(cmd, ' ');
719 if (os_strcmp(cmd, "any") == 0)
721 else if (os_strcmp(cmd, "get") == 0) {
722 ret = wps_generate_pin();
724 } else if (hwaddr_aton(cmd, bssid)) {
725 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
731 if (wpa_s->ap_iface) {
736 pos = os_strchr(pin, ' ');
743 return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin,
744 buf, buflen, timeout);
746 #endif /* CONFIG_AP */
749 ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0,
753 ret = os_snprintf(buf, buflen, "%s", pin);
754 if (ret < 0 || (size_t) ret >= buflen)
759 ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0, DEV_PW_DEFAULT);
764 /* Return the generated PIN */
765 ret = os_snprintf(buf, buflen, "%08d", ret);
766 if (ret < 0 || (size_t) ret >= buflen)
772 static int wpa_supplicant_ctrl_iface_wps_check_pin(
773 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
780 wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN",
781 (u8 *) cmd, os_strlen(cmd));
782 for (pos = cmd, len = 0; *pos != '\0'; pos++) {
783 if (*pos < '0' || *pos > '9')
787 wpa_printf(MSG_DEBUG, "WPS: Too long PIN");
791 if (len != 4 && len != 8) {
792 wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len);
798 unsigned int pin_val;
800 if (!wps_pin_valid(pin_val)) {
801 wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit");
802 ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n");
803 if (ret < 0 || (size_t) ret >= buflen)
809 ret = os_snprintf(buf, buflen, "%s", pin);
810 if (ret < 0 || (size_t) ret >= buflen)
817 #ifdef CONFIG_WPS_NFC
819 static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant *wpa_s,
822 u8 bssid[ETH_ALEN], *_bssid = bssid;
824 if (cmd == NULL || cmd[0] == '\0')
826 else if (hwaddr_aton(cmd, bssid))
829 return wpas_wps_start_nfc(wpa_s, NULL, _bssid, NULL, 0, 0, NULL, NULL,
834 static int wpa_supplicant_ctrl_iface_wps_nfc_config_token(
835 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
842 pos = os_strchr(cmd, ' ');
845 if (os_strcmp(cmd, "WPS") == 0)
847 else if (os_strcmp(cmd, "NDEF") == 0)
852 buf = wpas_wps_nfc_config_token(wpa_s, ndef, pos);
856 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
867 static int wpa_supplicant_ctrl_iface_wps_nfc_token(
868 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
874 if (os_strcmp(cmd, "WPS") == 0)
876 else if (os_strcmp(cmd, "NDEF") == 0)
881 buf = wpas_wps_nfc_token(wpa_s, ndef);
885 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
896 static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
897 struct wpa_supplicant *wpa_s, char *pos)
905 freq = strstr(pos, " freq=");
909 forced_freq = atoi(freq);
912 len = os_strlen(pos);
917 buf = wpabuf_alloc(len);
920 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
925 ret = wpas_wps_nfc_tag_read(wpa_s, buf, forced_freq);
932 static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant *wpa_s,
933 char *reply, size_t max_len,
939 buf = wpas_wps_nfc_handover_req(wpa_s, ndef);
943 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
955 static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant *wpa_s,
956 char *reply, size_t max_len,
962 buf = wpas_p2p_nfc_handover_req(wpa_s, ndef);
964 wpa_printf(MSG_DEBUG, "P2P: Could not generate NFC handover request");
968 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
977 #endif /* CONFIG_P2P */
980 static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant *wpa_s,
981 char *cmd, char *reply,
987 pos = os_strchr(cmd, ' ');
992 if (os_strcmp(cmd, "WPS") == 0)
994 else if (os_strcmp(cmd, "NDEF") == 0)
999 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
1002 return wpas_ctrl_nfc_get_handover_req_wps(
1003 wpa_s, reply, max_len, ndef);
1007 if (os_strcmp(pos, "P2P-CR") == 0) {
1008 return wpas_ctrl_nfc_get_handover_req_p2p(
1009 wpa_s, reply, max_len, ndef);
1011 #endif /* CONFIG_P2P */
1017 static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant *wpa_s,
1018 char *reply, size_t max_len,
1019 int ndef, int cr, char *uuid)
1024 buf = wpas_wps_nfc_handover_sel(wpa_s, ndef, cr, uuid);
1028 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1030 reply[res++] = '\n';
1040 static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant *wpa_s,
1041 char *reply, size_t max_len,
1047 buf = wpas_p2p_nfc_handover_sel(wpa_s, ndef, tag);
1051 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1053 reply[res++] = '\n';
1060 #endif /* CONFIG_P2P */
1063 static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant *wpa_s,
1064 char *cmd, char *reply,
1070 pos = os_strchr(cmd, ' ');
1075 if (os_strcmp(cmd, "WPS") == 0)
1077 else if (os_strcmp(cmd, "NDEF") == 0)
1082 pos2 = os_strchr(pos, ' ');
1085 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
1088 return wpas_ctrl_nfc_get_handover_sel_wps(
1089 wpa_s, reply, max_len, ndef,
1090 os_strcmp(pos, "WPS-CR") == 0, pos2);
1094 if (os_strcmp(pos, "P2P-CR") == 0) {
1095 return wpas_ctrl_nfc_get_handover_sel_p2p(
1096 wpa_s, reply, max_len, ndef, 0);
1099 if (os_strcmp(pos, "P2P-CR-TAG") == 0) {
1100 return wpas_ctrl_nfc_get_handover_sel_p2p(
1101 wpa_s, reply, max_len, ndef, 1);
1103 #endif /* CONFIG_P2P */
1109 static int wpas_ctrl_nfc_rx_handover_req(struct wpa_supplicant *wpa_s,
1110 char *cmd, char *reply,
1117 len = os_strlen(cmd);
1122 buf = wpabuf_alloc(len);
1125 if (hexstr2bin(cmd, wpabuf_put(buf, len), len) < 0) {
1130 ret = wpas_wps_nfc_rx_handover_req(wpa_s, buf);
1137 static int wpas_ctrl_nfc_rx_handover_sel(struct wpa_supplicant *wpa_s,
1144 len = os_strlen(cmd);
1149 buf = wpabuf_alloc(len);
1152 if (hexstr2bin(cmd, wpabuf_put(buf, len), len) < 0) {
1157 ret = wpas_wps_nfc_rx_handover_sel(wpa_s, buf);
1164 static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant *wpa_s,
1168 struct wpabuf *req, *sel;
1170 char *pos, *role, *type, *pos2;
1173 int forced_freq = 0;
1175 freq = strstr(cmd, " freq=");
1179 forced_freq = atoi(freq);
1181 #endif /* CONFIG_P2P */
1184 pos = os_strchr(role, ' ');
1186 wpa_printf(MSG_DEBUG, "NFC: Missing type in handover report");
1192 pos = os_strchr(type, ' ');
1194 wpa_printf(MSG_DEBUG, "NFC: Missing request message in handover report");
1199 pos2 = os_strchr(pos, ' ');
1201 wpa_printf(MSG_DEBUG, "NFC: Missing select message in handover report");
1206 len = os_strlen(pos);
1208 wpa_printf(MSG_DEBUG, "NFC: Invalid request message length in handover report");
1213 req = wpabuf_alloc(len);
1215 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for request message");
1218 if (hexstr2bin(pos, wpabuf_put(req, len), len) < 0) {
1219 wpa_printf(MSG_DEBUG, "NFC: Invalid request message hexdump in handover report");
1224 len = os_strlen(pos2);
1226 wpa_printf(MSG_DEBUG, "NFC: Invalid select message length in handover report");
1232 sel = wpabuf_alloc(len);
1234 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for select message");
1238 if (hexstr2bin(pos2, wpabuf_put(sel, len), len) < 0) {
1239 wpa_printf(MSG_DEBUG, "NFC: Invalid select message hexdump in handover report");
1245 wpa_printf(MSG_DEBUG, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d",
1246 role, type, (int) wpabuf_len(req), (int) wpabuf_len(sel));
1248 if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "WPS") == 0) {
1249 ret = wpas_wps_nfc_report_handover(wpa_s, req, sel);
1251 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "WPS") == 0)
1253 ret = wpas_ap_wps_nfc_report_handover(wpa_s, req, sel);
1255 ret = wpas_er_wps_nfc_report_handover(wpa_s, req, sel);
1256 #endif /* CONFIG_AP */
1258 } else if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "P2P") == 0)
1260 ret = wpas_p2p_nfc_report_handover(wpa_s, 1, req, sel, 0);
1261 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "P2P") == 0)
1263 ret = wpas_p2p_nfc_report_handover(wpa_s, 0, req, sel,
1265 #endif /* CONFIG_P2P */
1267 wpa_printf(MSG_DEBUG, "NFC: Unsupported connection handover "
1268 "reported: role=%s type=%s", role, type);
1275 wpa_printf(MSG_DEBUG, "NFC: Failed to process reported handover messages");
1280 #endif /* CONFIG_WPS_NFC */
1283 static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s,
1292 struct wps_new_ap_settings ap;
1294 pin = os_strchr(cmd, ' ');
1299 if (hwaddr_aton(cmd, bssid)) {
1300 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
1305 new_ssid = os_strchr(pin, ' ');
1306 if (new_ssid == NULL)
1307 return wpas_wps_start_reg(wpa_s, bssid, pin, NULL);
1310 new_auth = os_strchr(new_ssid, ' ');
1311 if (new_auth == NULL)
1315 new_encr = os_strchr(new_auth, ' ');
1316 if (new_encr == NULL)
1320 new_key = os_strchr(new_encr, ' ');
1321 if (new_key == NULL)
1325 os_memset(&ap, 0, sizeof(ap));
1326 ap.ssid_hex = new_ssid;
1329 ap.key_hex = new_key;
1330 return wpas_wps_start_reg(wpa_s, bssid, pin, &ap);
1335 static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant *wpa_s,
1336 char *cmd, char *buf,
1341 const char *pin_txt;
1343 if (!wpa_s->ap_iface)
1346 pos = os_strchr(cmd, ' ');
1350 if (os_strcmp(cmd, "disable") == 0) {
1351 wpas_wps_ap_pin_disable(wpa_s);
1352 return os_snprintf(buf, buflen, "OK\n");
1355 if (os_strcmp(cmd, "random") == 0) {
1357 timeout = atoi(pos);
1358 pin_txt = wpas_wps_ap_pin_random(wpa_s, timeout);
1359 if (pin_txt == NULL)
1361 return os_snprintf(buf, buflen, "%s", pin_txt);
1364 if (os_strcmp(cmd, "get") == 0) {
1365 pin_txt = wpas_wps_ap_pin_get(wpa_s);
1366 if (pin_txt == NULL)
1368 return os_snprintf(buf, buflen, "%s", pin_txt);
1371 if (os_strcmp(cmd, "set") == 0) {
1376 pos = os_strchr(pos, ' ');
1379 timeout = atoi(pos);
1381 if (os_strlen(pin) > buflen)
1383 if (wpas_wps_ap_pin_set(wpa_s, pin, timeout) < 0)
1385 return os_snprintf(buf, buflen, "%s", pin);
1390 #endif /* CONFIG_AP */
1393 #ifdef CONFIG_WPS_ER
1394 static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant *wpa_s,
1397 char *uuid = cmd, *pin, *pos;
1398 u8 addr_buf[ETH_ALEN], *addr = NULL;
1399 pin = os_strchr(uuid, ' ');
1403 pos = os_strchr(pin, ' ');
1406 if (hwaddr_aton(pos, addr_buf) == 0)
1409 return wpas_wps_er_add_pin(wpa_s, addr, uuid, pin);
1413 static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant *wpa_s,
1416 char *uuid = cmd, *pin;
1417 pin = os_strchr(uuid, ' ');
1421 return wpas_wps_er_learn(wpa_s, uuid, pin);
1425 static int wpa_supplicant_ctrl_iface_wps_er_set_config(
1426 struct wpa_supplicant *wpa_s, char *cmd)
1428 char *uuid = cmd, *id;
1429 id = os_strchr(uuid, ' ');
1433 return wpas_wps_er_set_config(wpa_s, uuid, atoi(id));
1437 static int wpa_supplicant_ctrl_iface_wps_er_config(
1438 struct wpa_supplicant *wpa_s, char *cmd)
1445 struct wps_new_ap_settings ap;
1447 pin = os_strchr(cmd, ' ');
1452 new_ssid = os_strchr(pin, ' ');
1453 if (new_ssid == NULL)
1457 new_auth = os_strchr(new_ssid, ' ');
1458 if (new_auth == NULL)
1462 new_encr = os_strchr(new_auth, ' ');
1463 if (new_encr == NULL)
1467 new_key = os_strchr(new_encr, ' ');
1468 if (new_key == NULL)
1472 os_memset(&ap, 0, sizeof(ap));
1473 ap.ssid_hex = new_ssid;
1476 ap.key_hex = new_key;
1477 return wpas_wps_er_config(wpa_s, cmd, pin, &ap);
1481 #ifdef CONFIG_WPS_NFC
1482 static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
1483 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1490 uuid = os_strchr(cmd, ' ');
1495 if (os_strcmp(cmd, "WPS") == 0)
1497 else if (os_strcmp(cmd, "NDEF") == 0)
1502 buf = wpas_wps_er_nfc_config_token(wpa_s, ndef, uuid);
1506 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1508 reply[res++] = '\n';
1515 #endif /* CONFIG_WPS_NFC */
1516 #endif /* CONFIG_WPS_ER */
1518 #endif /* CONFIG_WPS */
1521 #ifdef CONFIG_IBSS_RSN
1522 static int wpa_supplicant_ctrl_iface_ibss_rsn(
1523 struct wpa_supplicant *wpa_s, char *addr)
1527 if (hwaddr_aton(addr, peer)) {
1528 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN: invalid "
1529 "address '%s'", addr);
1533 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN " MACSTR,
1536 return ibss_rsn_start(wpa_s->ibss_rsn, peer);
1538 #endif /* CONFIG_IBSS_RSN */
1541 static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s,
1544 #ifdef IEEE8021X_EAPOL
1547 struct wpa_ssid *ssid;
1549 pos = os_strchr(rsp, '-');
1554 pos = os_strchr(pos, ':');
1559 wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id);
1560 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
1561 (u8 *) pos, os_strlen(pos));
1563 ssid = wpa_config_get_network(wpa_s->conf, id);
1565 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
1570 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s, ssid, rsp,
1572 #else /* IEEE8021X_EAPOL */
1573 wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included");
1575 #endif /* IEEE8021X_EAPOL */
1579 static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
1581 char *buf, size_t buflen)
1583 char *pos, *end, tmp[30];
1584 int res, verbose, wps, ret;
1586 if (os_strcmp(params, "-DRIVER") == 0)
1587 return wpa_drv_status(wpa_s, buf, buflen);
1588 verbose = os_strcmp(params, "-VERBOSE") == 0;
1589 wps = os_strcmp(params, "-WPS") == 0;
1592 if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
1593 struct wpa_ssid *ssid = wpa_s->current_ssid;
1594 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
1595 MAC2STR(wpa_s->bssid));
1596 if (ret < 0 || ret >= end - pos)
1600 u8 *_ssid = ssid->ssid;
1601 size_t ssid_len = ssid->ssid_len;
1602 u8 ssid_buf[MAX_SSID_LEN];
1603 if (ssid_len == 0) {
1604 int _res = wpa_drv_get_ssid(wpa_s, ssid_buf);
1611 ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n",
1612 wpa_ssid_txt(_ssid, ssid_len),
1614 if (ret < 0 || ret >= end - pos)
1618 if (wps && ssid->passphrase &&
1619 wpa_key_mgmt_wpa_psk(ssid->key_mgmt) &&
1620 (ssid->mode == WPAS_MODE_AP ||
1621 ssid->mode == WPAS_MODE_P2P_GO)) {
1622 ret = os_snprintf(pos, end - pos,
1625 if (ret < 0 || ret >= end - pos)
1630 ret = os_snprintf(pos, end - pos,
1633 if (ret < 0 || ret >= end - pos)
1638 switch (ssid->mode) {
1639 case WPAS_MODE_INFRA:
1640 ret = os_snprintf(pos, end - pos,
1643 case WPAS_MODE_IBSS:
1644 ret = os_snprintf(pos, end - pos,
1648 ret = os_snprintf(pos, end - pos,
1651 case WPAS_MODE_P2P_GO:
1652 ret = os_snprintf(pos, end - pos,
1655 case WPAS_MODE_P2P_GROUP_FORMATION:
1656 ret = os_snprintf(pos, end - pos,
1657 "mode=P2P GO - group "
1664 if (ret < 0 || ret >= end - pos)
1670 if (wpa_s->ap_iface) {
1671 pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos,
1675 #endif /* CONFIG_AP */
1676 pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose);
1679 if (wpa_s->wpa_state >= WPA_ASSOCIATED &&
1682 #endif /* CONFIG_AP */
1683 wpa_s->sme.sae.state == SAE_ACCEPTED) {
1684 ret = os_snprintf(pos, end - pos, "sae_group=%d\n",
1685 wpa_s->sme.sae.group);
1686 if (ret < 0 || ret >= end - pos)
1690 #endif /* CONFIG_SAE */
1691 ret = os_snprintf(pos, end - pos, "wpa_state=%s\n",
1692 wpa_supplicant_state_txt(wpa_s->wpa_state));
1693 if (ret < 0 || ret >= end - pos)
1698 l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) {
1699 ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp);
1700 if (ret < 0 || ret >= end - pos)
1706 if (wpa_s->global->p2p) {
1707 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
1708 "\n", MAC2STR(wpa_s->global->p2p_dev_addr));
1709 if (ret < 0 || ret >= end - pos)
1713 #endif /* CONFIG_P2P */
1715 ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n",
1716 MAC2STR(wpa_s->own_addr));
1717 if (ret < 0 || ret >= end - pos)
1722 if (wpa_s->current_bss &&
1723 wpa_bss_get_vendor_ie(wpa_s->current_bss, HS20_IE_VENDOR_TYPE) &&
1724 wpa_s->wpa_proto == WPA_PROTO_RSN &&
1725 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1726 ret = os_snprintf(pos, end - pos, "hs20=1\n");
1727 if (ret < 0 || ret >= end - pos)
1732 if (wpa_s->current_ssid) {
1733 struct wpa_cred *cred;
1736 for (cred = wpa_s->conf->cred; cred; cred = cred->next) {
1739 if (wpa_s->current_ssid->parent_cred != cred)
1742 for (i = 0; cred->domain && i < cred->num_domain; i++) {
1743 ret = os_snprintf(pos, end - pos,
1746 if (ret < 0 || ret >= end - pos)
1751 if (wpa_s->current_bss == NULL ||
1752 wpa_s->current_bss->anqp == NULL)
1755 res = interworking_home_sp_cred(
1757 wpa_s->current_bss->anqp->domain_name);
1765 ret = os_snprintf(pos, end - pos, "sp_type=%s\n", type);
1766 if (ret < 0 || ret >= end - pos)
1773 #endif /* CONFIG_HS20 */
1775 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
1776 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
1777 res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos,
1783 res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose);
1790 uuid_bin2str(wpa_s->wps->uuid, uuid_str, sizeof(uuid_str));
1791 ret = os_snprintf(pos, end - pos, "uuid=%s\n", uuid_str);
1792 if (ret < 0 || ret >= end - pos)
1796 #endif /* CONFIG_WPS */
1799 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_STATE_CHANGE
1800 "id=%d state=%d BSSID=" MACSTR " SSID=%s",
1801 wpa_s->current_ssid ? wpa_s->current_ssid->id : -1,
1803 MAC2STR(wpa_s->bssid),
1804 wpa_s->current_ssid && wpa_s->current_ssid->ssid ?
1805 wpa_ssid_txt(wpa_s->current_ssid->ssid,
1806 wpa_s->current_ssid->ssid_len) : "");
1807 if (wpa_s->wpa_state == WPA_COMPLETED) {
1808 struct wpa_ssid *ssid = wpa_s->current_ssid;
1809 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_CONNECTED
1810 "- connection to " MACSTR
1811 " completed %s [id=%d id_str=%s]",
1812 MAC2STR(wpa_s->bssid), "(auth)",
1813 ssid ? ssid->id : -1,
1814 ssid && ssid->id_str ? ssid->id_str : "");
1816 #endif /* ANDROID */
1822 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s,
1827 struct wpa_ssid *ssid;
1830 /* cmd: "<network id> <BSSID>" */
1831 pos = os_strchr(cmd, ' ');
1836 wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos);
1837 if (hwaddr_aton(pos, bssid)) {
1838 wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos);
1842 ssid = wpa_config_get_network(wpa_s->conf, id);
1844 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
1849 os_memcpy(ssid->bssid, bssid, ETH_ALEN);
1850 ssid->bssid_set = !is_zero_ether_addr(bssid);
1856 static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant *wpa_s,
1857 char *cmd, char *buf,
1861 struct wpa_blacklist *e;
1865 /* cmd: "BLACKLIST [<BSSID>]" */
1869 e = wpa_s->blacklist;
1871 ret = os_snprintf(pos, end - pos, MACSTR "\n",
1873 if (ret < 0 || ret >= end - pos)
1882 if (os_strncmp(cmd, "clear", 5) == 0) {
1883 wpa_blacklist_clear(wpa_s);
1884 os_memcpy(buf, "OK\n", 3);
1888 wpa_printf(MSG_DEBUG, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd);
1889 if (hwaddr_aton(cmd, bssid)) {
1890 wpa_printf(MSG_DEBUG, "CTRL_IFACE: invalid BSSID '%s'", cmd);
1895 * Add the BSSID twice, so its count will be 2, causing it to be
1896 * skipped when processing scan results.
1898 ret = wpa_blacklist_add(wpa_s, bssid);
1901 ret = wpa_blacklist_add(wpa_s, bssid);
1904 os_memcpy(buf, "OK\n", 3);
1909 static const char * debug_level_str(int level)
1930 static int str_to_debug_level(const char *s)
1932 if (os_strcasecmp(s, "EXCESSIVE") == 0)
1933 return MSG_EXCESSIVE;
1934 if (os_strcasecmp(s, "MSGDUMP") == 0)
1936 if (os_strcasecmp(s, "DEBUG") == 0)
1938 if (os_strcasecmp(s, "INFO") == 0)
1940 if (os_strcasecmp(s, "WARNING") == 0)
1942 if (os_strcasecmp(s, "ERROR") == 0)
1948 static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant *wpa_s,
1949 char *cmd, char *buf,
1952 char *pos, *end, *stamp;
1959 /* cmd: "LOG_LEVEL [<level>]" */
1963 ret = os_snprintf(pos, end - pos, "Current level: %s\n"
1965 debug_level_str(wpa_debug_level),
1966 wpa_debug_timestamp);
1967 if (ret < 0 || ret >= end - pos)
1976 stamp = os_strchr(cmd, ' ');
1979 while (*stamp == ' ') {
1984 if (cmd && os_strlen(cmd)) {
1985 int level = str_to_debug_level(cmd);
1988 wpa_debug_level = level;
1991 if (stamp && os_strlen(stamp))
1992 wpa_debug_timestamp = atoi(stamp);
1994 os_memcpy(buf, "OK\n", 3);
1999 static int wpa_supplicant_ctrl_iface_list_networks(
2000 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
2003 struct wpa_ssid *ssid;
2008 ret = os_snprintf(pos, end - pos,
2009 "network id / ssid / bssid / flags\n");
2010 if (ret < 0 || ret >= end - pos)
2014 ssid = wpa_s->conf->ssid;
2016 ret = os_snprintf(pos, end - pos, "%d\t%s",
2018 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
2019 if (ret < 0 || ret >= end - pos)
2022 if (ssid->bssid_set) {
2023 ret = os_snprintf(pos, end - pos, "\t" MACSTR,
2024 MAC2STR(ssid->bssid));
2026 ret = os_snprintf(pos, end - pos, "\tany");
2028 if (ret < 0 || ret >= end - pos)
2031 ret = os_snprintf(pos, end - pos, "\t%s%s%s%s",
2032 ssid == wpa_s->current_ssid ?
2034 ssid->disabled ? "[DISABLED]" : "",
2035 ssid->disabled_until.sec ?
2036 "[TEMP-DISABLED]" : "",
2037 ssid->disabled == 2 ? "[P2P-PERSISTENT]" :
2039 if (ret < 0 || ret >= end - pos)
2042 ret = os_snprintf(pos, end - pos, "\n");
2043 if (ret < 0 || ret >= end - pos)
2054 static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher)
2057 ret = os_snprintf(pos, end - pos, "-");
2058 if (ret < 0 || ret >= end - pos)
2061 ret = wpa_write_ciphers(pos, end, cipher, "+");
2069 static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
2070 const u8 *ie, size_t ie_len)
2072 struct wpa_ie_data data;
2075 ret = os_snprintf(pos, end - pos, "[%s-", proto);
2076 if (ret < 0 || ret >= end - pos)
2080 if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) {
2081 ret = os_snprintf(pos, end - pos, "?]");
2082 if (ret < 0 || ret >= end - pos)
2089 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
2090 ret = os_snprintf(pos, end - pos, "%sEAP", first ? "" : "+");
2091 if (ret < 0 || ret >= end - pos)
2096 if (data.key_mgmt & WPA_KEY_MGMT_PSK) {
2097 ret = os_snprintf(pos, end - pos, "%sPSK", first ? "" : "+");
2098 if (ret < 0 || ret >= end - pos)
2103 if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
2104 ret = os_snprintf(pos, end - pos, "%sNone", first ? "" : "+");
2105 if (ret < 0 || ret >= end - pos)
2110 #ifdef CONFIG_IEEE80211R
2111 if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
2112 ret = os_snprintf(pos, end - pos, "%sFT/EAP",
2114 if (ret < 0 || ret >= end - pos)
2119 if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) {
2120 ret = os_snprintf(pos, end - pos, "%sFT/PSK",
2122 if (ret < 0 || ret >= end - pos)
2127 #endif /* CONFIG_IEEE80211R */
2128 #ifdef CONFIG_IEEE80211W
2129 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
2130 ret = os_snprintf(pos, end - pos, "%sEAP-SHA256",
2132 if (ret < 0 || ret >= end - pos)
2137 if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
2138 ret = os_snprintf(pos, end - pos, "%sPSK-SHA256",
2140 if (ret < 0 || ret >= end - pos)
2145 #endif /* CONFIG_IEEE80211W */
2147 pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher);
2149 if (data.capabilities & WPA_CAPABILITY_PREAUTH) {
2150 ret = os_snprintf(pos, end - pos, "-preauth");
2151 if (ret < 0 || ret >= end - pos)
2156 ret = os_snprintf(pos, end - pos, "]");
2157 if (ret < 0 || ret >= end - pos)
2166 static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s,
2167 char *pos, char *end,
2168 struct wpabuf *wps_ie)
2175 if (wps_is_selected_pbc_registrar(wps_ie))
2178 else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0))
2180 #endif /* CONFIG_WPS2 */
2181 else if (wps_is_selected_pin_registrar(wps_ie))
2186 ret = os_snprintf(pos, end - pos, "%s", txt);
2187 if (ret >= 0 && ret < end - pos)
2189 wpabuf_free(wps_ie);
2192 #endif /* CONFIG_WPS */
2195 static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s,
2196 char *pos, char *end,
2197 const struct wpa_bss *bss)
2200 struct wpabuf *wps_ie;
2201 wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
2202 return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie);
2203 #else /* CONFIG_WPS */
2205 #endif /* CONFIG_WPS */
2209 /* Format one result on one text line into a buffer. */
2210 static int wpa_supplicant_ctrl_iface_scan_result(
2211 struct wpa_supplicant *wpa_s,
2212 const struct wpa_bss *bss, char *buf, size_t buflen)
2216 const u8 *ie, *ie2, *p2p;
2218 p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
2220 p2p = wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE);
2221 if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN &&
2222 os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) ==
2224 return 0; /* Do not show P2P listen discovery results here */
2229 ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t",
2230 MAC2STR(bss->bssid), bss->freq, bss->level);
2231 if (ret < 0 || ret >= end - pos)
2234 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
2236 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]);
2237 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
2239 pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2, 2 + ie2[1]);
2240 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
2241 if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
2242 ret = os_snprintf(pos, end - pos, "[WEP]");
2243 if (ret < 0 || ret >= end - pos)
2247 if (bss->caps & IEEE80211_CAP_IBSS) {
2248 ret = os_snprintf(pos, end - pos, "[IBSS]");
2249 if (ret < 0 || ret >= end - pos)
2253 if (bss->caps & IEEE80211_CAP_ESS) {
2254 ret = os_snprintf(pos, end - pos, "[ESS]");
2255 if (ret < 0 || ret >= end - pos)
2260 ret = os_snprintf(pos, end - pos, "[P2P]");
2261 if (ret < 0 || ret >= end - pos)
2266 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE) && ie2) {
2267 ret = os_snprintf(pos, end - pos, "[HS20]");
2268 if (ret < 0 || ret >= end - pos)
2272 #endif /* CONFIG_HS20 */
2274 ret = os_snprintf(pos, end - pos, "\t%s",
2275 wpa_ssid_txt(bss->ssid, bss->ssid_len));
2276 if (ret < 0 || ret >= end - pos)
2280 ret = os_snprintf(pos, end - pos, "\n");
2281 if (ret < 0 || ret >= end - pos)
2289 static int wpa_supplicant_ctrl_iface_scan_results(
2290 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
2293 struct wpa_bss *bss;
2298 ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / "
2300 if (ret < 0 || ret >= end - pos)
2304 dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
2305 ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos,
2307 if (ret < 0 || ret >= end - pos)
2316 static int wpa_supplicant_ctrl_iface_select_network(
2317 struct wpa_supplicant *wpa_s, char *cmd)
2320 struct wpa_ssid *ssid;
2322 /* cmd: "<network id>" or "any" */
2323 if (os_strcmp(cmd, "any") == 0) {
2324 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any");
2328 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id);
2330 ssid = wpa_config_get_network(wpa_s->conf, id);
2332 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2333 "network id=%d", id);
2336 if (ssid->disabled == 2) {
2337 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2338 "SELECT_NETWORK with persistent P2P group");
2343 wpa_supplicant_select_network(wpa_s, ssid);
2349 static int wpa_supplicant_ctrl_iface_enable_network(
2350 struct wpa_supplicant *wpa_s, char *cmd)
2353 struct wpa_ssid *ssid;
2355 /* cmd: "<network id>" or "all" */
2356 if (os_strcmp(cmd, "all") == 0) {
2357 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all");
2361 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id);
2363 ssid = wpa_config_get_network(wpa_s->conf, id);
2365 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2366 "network id=%d", id);
2369 if (ssid->disabled == 2) {
2370 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2371 "ENABLE_NETWORK with persistent P2P group");
2375 if (os_strstr(cmd, " no-connect")) {
2380 wpa_supplicant_enable_network(wpa_s, ssid);
2386 static int wpa_supplicant_ctrl_iface_disable_network(
2387 struct wpa_supplicant *wpa_s, char *cmd)
2390 struct wpa_ssid *ssid;
2392 /* cmd: "<network id>" or "all" */
2393 if (os_strcmp(cmd, "all") == 0) {
2394 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all");
2398 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id);
2400 ssid = wpa_config_get_network(wpa_s->conf, id);
2402 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2403 "network id=%d", id);
2406 if (ssid->disabled == 2) {
2407 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2408 "DISABLE_NETWORK with persistent P2P "
2413 wpa_supplicant_disable_network(wpa_s, ssid);
2419 static int wpa_supplicant_ctrl_iface_add_network(
2420 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
2422 struct wpa_ssid *ssid;
2425 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK");
2427 ssid = wpa_config_add_network(wpa_s->conf);
2431 wpas_notify_network_added(wpa_s, ssid);
2434 wpa_config_set_network_defaults(ssid);
2436 ret = os_snprintf(buf, buflen, "%d\n", ssid->id);
2437 if (ret < 0 || (size_t) ret >= buflen)
2443 static int wpa_supplicant_ctrl_iface_remove_network(
2444 struct wpa_supplicant *wpa_s, char *cmd)
2447 struct wpa_ssid *ssid;
2450 /* cmd: "<network id>" or "all" */
2451 if (os_strcmp(cmd, "all") == 0) {
2452 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all");
2453 if (wpa_s->sched_scanning)
2454 wpa_supplicant_cancel_sched_scan(wpa_s);
2456 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2457 if (wpa_s->current_ssid) {
2459 wpa_s->sme.prev_bssid_set = 0;
2460 #endif /* CONFIG_SME */
2461 wpa_sm_set_config(wpa_s->wpa, NULL);
2462 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
2463 wpa_supplicant_deauthenticate(
2464 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2466 ssid = wpa_s->conf->ssid;
2468 struct wpa_ssid *remove_ssid = ssid;
2471 wpas_notify_network_removed(wpa_s, remove_ssid);
2472 wpa_config_remove_network(wpa_s->conf, id);
2478 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id);
2480 ssid = wpa_config_get_network(wpa_s->conf, id);
2482 wpas_notify_network_removed(wpa_s, ssid);
2484 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2489 if (ssid == wpa_s->current_ssid || wpa_s->current_ssid == NULL) {
2491 wpa_s->sme.prev_bssid_set = 0;
2492 #endif /* CONFIG_SME */
2494 * Invalidate the EAP session cache if the current or
2495 * previously used network is removed.
2497 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2500 if (ssid == wpa_s->current_ssid) {
2501 wpa_sm_set_config(wpa_s->wpa, NULL);
2502 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
2504 wpa_supplicant_deauthenticate(wpa_s,
2505 WLAN_REASON_DEAUTH_LEAVING);
2508 was_disabled = ssid->disabled;
2510 if (wpa_config_remove_network(wpa_s->conf, id) < 0) {
2511 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Not able to remove the "
2512 "network id=%d", id);
2516 if (!was_disabled && wpa_s->sched_scanning) {
2517 wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to remove "
2518 "network from filters");
2519 wpa_supplicant_cancel_sched_scan(wpa_s);
2520 wpa_supplicant_req_scan(wpa_s, 0, 0);
2527 static int wpa_supplicant_ctrl_iface_set_network(
2528 struct wpa_supplicant *wpa_s, char *cmd)
2531 struct wpa_ssid *ssid;
2534 /* cmd: "<network id> <variable name> <value>" */
2535 name = os_strchr(cmd, ' ');
2540 value = os_strchr(name, ' ');
2546 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
2548 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
2549 (u8 *) value, os_strlen(value));
2551 ssid = wpa_config_get_network(wpa_s->conf, id);
2553 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2558 if (wpa_config_set(ssid, name, value, 0) < 0) {
2559 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network "
2560 "variable '%s'", name);
2564 if (os_strcmp(name, "bssid") != 0 &&
2565 os_strcmp(name, "priority") != 0)
2566 wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
2568 if (wpa_s->current_ssid == ssid || wpa_s->current_ssid == NULL) {
2570 * Invalidate the EAP session cache if anything in the current
2571 * or previously used configuration changes.
2573 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2576 if ((os_strcmp(name, "psk") == 0 &&
2577 value[0] == '"' && ssid->ssid_len) ||
2578 (os_strcmp(name, "ssid") == 0 && ssid->passphrase))
2579 wpa_config_update_psk(ssid);
2580 else if (os_strcmp(name, "priority") == 0)
2581 wpa_config_update_prio_list(wpa_s->conf);
2587 static int wpa_supplicant_ctrl_iface_get_network(
2588 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
2592 struct wpa_ssid *ssid;
2595 /* cmd: "<network id> <variable name>" */
2596 name = os_strchr(cmd, ' ');
2597 if (name == NULL || buflen == 0)
2602 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
2605 ssid = wpa_config_get_network(wpa_s->conf, id);
2607 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2612 value = wpa_config_get_no_key(ssid, name);
2613 if (value == NULL) {
2614 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
2615 "variable '%s'", name);
2619 res = os_strlcpy(buf, value, buflen);
2620 if (res >= buflen) {
2631 static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant *wpa_s,
2632 char *buf, size_t buflen)
2635 struct wpa_cred *cred;
2640 ret = os_snprintf(pos, end - pos,
2641 "cred id / realm / username / domain / imsi\n");
2642 if (ret < 0 || ret >= end - pos)
2646 cred = wpa_s->conf->cred;
2648 ret = os_snprintf(pos, end - pos, "%d\t%s\t%s\t%s\t%s\n",
2649 cred->id, cred->realm ? cred->realm : "",
2650 cred->username ? cred->username : "",
2651 cred->domain ? cred->domain[0] : "",
2652 cred->imsi ? cred->imsi : "");
2653 if (ret < 0 || ret >= end - pos)
2664 static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant *wpa_s,
2665 char *buf, size_t buflen)
2667 struct wpa_cred *cred;
2670 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_CRED");
2672 cred = wpa_config_add_cred(wpa_s->conf);
2676 ret = os_snprintf(buf, buflen, "%d\n", cred->id);
2677 if (ret < 0 || (size_t) ret >= buflen)
2683 static int wpas_ctrl_remove_cred(struct wpa_supplicant *wpa_s,
2684 struct wpa_cred *cred)
2686 struct wpa_ssid *ssid;
2689 if (cred == NULL || wpa_config_remove_cred(wpa_s->conf, cred->id) < 0) {
2690 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred");
2694 /* Remove any network entry created based on the removed credential */
2695 ssid = wpa_s->conf->ssid;
2697 if (ssid->parent_cred == cred) {
2698 wpa_printf(MSG_DEBUG, "Remove network id %d since it "
2699 "used the removed credential", ssid->id);
2700 os_snprintf(str, sizeof(str), "%d", ssid->id);
2702 wpa_supplicant_ctrl_iface_remove_network(wpa_s, str);
2711 static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s,
2715 struct wpa_cred *cred, *prev;
2717 /* cmd: "<cred id>", "all", or "sp_fqdn=<FQDN>" */
2718 if (os_strcmp(cmd, "all") == 0) {
2719 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED all");
2720 cred = wpa_s->conf->cred;
2724 wpas_ctrl_remove_cred(wpa_s, prev);
2729 if (os_strncmp(cmd, "sp_fqdn=", 8) == 0) {
2730 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
2732 cred = wpa_s->conf->cred;
2738 for (i = 0; i < prev->num_domain; i++) {
2739 if (os_strcmp(prev->domain[i], cmd + 8)
2742 wpas_ctrl_remove_cred(wpa_s, prev);
2751 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED id=%d", id);
2753 cred = wpa_config_get_cred(wpa_s->conf, id);
2754 return wpas_ctrl_remove_cred(wpa_s, cred);
2758 static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant *wpa_s,
2762 struct wpa_cred *cred;
2765 /* cmd: "<cred id> <variable name> <value>" */
2766 name = os_strchr(cmd, ' ');
2771 value = os_strchr(name, ' ');
2777 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_CRED id=%d name='%s'",
2779 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
2780 (u8 *) value, os_strlen(value));
2782 cred = wpa_config_get_cred(wpa_s->conf, id);
2784 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
2789 if (wpa_config_set_cred(cred, name, value, 0) < 0) {
2790 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set cred "
2791 "variable '%s'", name);
2799 #ifndef CONFIG_NO_CONFIG_WRITE
2800 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s)
2804 if (!wpa_s->conf->update_config) {
2805 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
2806 "to update configuration (update_config=0)");
2810 ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
2812 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to "
2813 "update configuration");
2815 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration"
2821 #endif /* CONFIG_NO_CONFIG_WRITE */
2824 struct cipher_info {
2830 static const struct cipher_info ciphers[] = {
2831 { WPA_DRIVER_CAPA_ENC_CCMP_256, "CCMP-256", 0 },
2832 { WPA_DRIVER_CAPA_ENC_GCMP_256, "GCMP-256", 0 },
2833 { WPA_DRIVER_CAPA_ENC_CCMP, "CCMP", 0 },
2834 { WPA_DRIVER_CAPA_ENC_GCMP, "GCMP", 0 },
2835 { WPA_DRIVER_CAPA_ENC_TKIP, "TKIP", 0 },
2836 { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE, "NONE", 0 },
2837 { WPA_DRIVER_CAPA_ENC_WEP104, "WEP104", 1 },
2838 { WPA_DRIVER_CAPA_ENC_WEP40, "WEP40", 1 }
2842 static int ctrl_iface_get_capability_pairwise(int res, char *strict,
2843 struct wpa_driver_capa *capa,
2844 char *buf, size_t buflen)
2857 len = os_strlcpy(buf, "CCMP TKIP NONE", buflen);
2863 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
2864 if (!ciphers[i].group_only && capa->enc & ciphers[i].capa) {
2865 ret = os_snprintf(pos, end - pos, "%s%s",
2866 first ? "" : " ", ciphers[i].name);
2867 if (ret < 0 || ret >= end - pos)
2878 static int ctrl_iface_get_capability_group(int res, char *strict,
2879 struct wpa_driver_capa *capa,
2880 char *buf, size_t buflen)
2893 len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen);
2899 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
2900 if (capa->enc & ciphers[i].capa) {
2901 ret = os_snprintf(pos, end - pos, "%s%s",
2902 first ? "" : " ", ciphers[i].name);
2903 if (ret < 0 || ret >= end - pos)
2914 static int ctrl_iface_get_capability_key_mgmt(int res, char *strict,
2915 struct wpa_driver_capa *capa,
2916 char *buf, size_t buflen)
2928 len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
2935 ret = os_snprintf(pos, end - pos, "NONE IEEE8021X");
2936 if (ret < 0 || ret >= end - pos)
2940 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
2941 WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
2942 ret = os_snprintf(pos, end - pos, " WPA-EAP");
2943 if (ret < 0 || ret >= end - pos)
2948 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
2949 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
2950 ret = os_snprintf(pos, end - pos, " WPA-PSK");
2951 if (ret < 0 || ret >= end - pos)
2956 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
2957 ret = os_snprintf(pos, end - pos, " WPA-NONE");
2958 if (ret < 0 || ret >= end - pos)
2967 static int ctrl_iface_get_capability_proto(int res, char *strict,
2968 struct wpa_driver_capa *capa,
2969 char *buf, size_t buflen)
2981 len = os_strlcpy(buf, "RSN WPA", buflen);
2987 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
2988 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
2989 ret = os_snprintf(pos, end - pos, "%sRSN", first ? "" : " ");
2990 if (ret < 0 || ret >= end - pos)
2996 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
2997 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
2998 ret = os_snprintf(pos, end - pos, "%sWPA", first ? "" : " ");
2999 if (ret < 0 || ret >= end - pos)
3009 static int ctrl_iface_get_capability_auth_alg(int res, char *strict,
3010 struct wpa_driver_capa *capa,
3011 char *buf, size_t buflen)
3023 len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen);
3029 if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) {
3030 ret = os_snprintf(pos, end - pos, "%sOPEN", first ? "" : " ");
3031 if (ret < 0 || ret >= end - pos)
3037 if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) {
3038 ret = os_snprintf(pos, end - pos, "%sSHARED",
3040 if (ret < 0 || ret >= end - pos)
3046 if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) {
3047 ret = os_snprintf(pos, end - pos, "%sLEAP", first ? "" : " ");
3048 if (ret < 0 || ret >= end - pos)
3058 static int ctrl_iface_get_capability_modes(int res, char *strict,
3059 struct wpa_driver_capa *capa,
3060 char *buf, size_t buflen)
3072 len = os_strlcpy(buf, "IBSS AP", buflen);
3078 if (capa->flags & WPA_DRIVER_FLAGS_IBSS) {
3079 ret = os_snprintf(pos, end - pos, "%sIBSS", first ? "" : " ");
3080 if (ret < 0 || ret >= end - pos)
3086 if (capa->flags & WPA_DRIVER_FLAGS_AP) {
3087 ret = os_snprintf(pos, end - pos, "%sAP", first ? "" : " ");
3088 if (ret < 0 || ret >= end - pos)
3098 static int ctrl_iface_get_capability_channels(struct wpa_supplicant *wpa_s,
3099 char *buf, size_t buflen)
3101 struct hostapd_channel_data *chnl;
3103 char *pos, *end, *hmode;
3108 for (j = 0; j < wpa_s->hw.num_modes; j++) {
3109 switch (wpa_s->hw.modes[j].mode) {
3110 case HOSTAPD_MODE_IEEE80211B:
3113 case HOSTAPD_MODE_IEEE80211G:
3116 case HOSTAPD_MODE_IEEE80211A:
3119 case HOSTAPD_MODE_IEEE80211AD:
3125 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:", hmode);
3126 if (ret < 0 || ret >= end - pos)
3129 chnl = wpa_s->hw.modes[j].channels;
3130 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
3131 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
3133 ret = os_snprintf(pos, end - pos, " %d", chnl[i].chan);
3134 if (ret < 0 || ret >= end - pos)
3138 ret = os_snprintf(pos, end - pos, "\n");
3139 if (ret < 0 || ret >= end - pos)
3148 static int ctrl_iface_get_capability_freq(struct wpa_supplicant *wpa_s,
3149 char *buf, size_t buflen)
3151 struct hostapd_channel_data *chnl;
3153 char *pos, *end, *hmode;
3158 for (j = 0; j < wpa_s->hw.num_modes; j++) {
3159 switch (wpa_s->hw.modes[j].mode) {
3160 case HOSTAPD_MODE_IEEE80211B:
3163 case HOSTAPD_MODE_IEEE80211G:
3166 case HOSTAPD_MODE_IEEE80211A:
3169 case HOSTAPD_MODE_IEEE80211AD:
3175 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:\n",
3177 if (ret < 0 || ret >= end - pos)
3180 chnl = wpa_s->hw.modes[j].channels;
3181 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
3182 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
3184 ret = os_snprintf(pos, end - pos, " %d = %d MHz%s%s\n",
3185 chnl[i].chan, chnl[i].freq,
3186 chnl[i].flag & HOSTAPD_CHAN_NO_IBSS ?
3188 chnl[i].flag & HOSTAPD_CHAN_RADAR ?
3191 if (ret < 0 || ret >= end - pos)
3195 ret = os_snprintf(pos, end - pos, "\n");
3196 if (ret < 0 || ret >= end - pos)
3205 static int wpa_supplicant_ctrl_iface_get_capability(
3206 struct wpa_supplicant *wpa_s, const char *_field, char *buf,
3209 struct wpa_driver_capa capa;
3215 /* Determine whether or not strict checking was requested */
3216 len = os_strlcpy(field, _field, sizeof(field));
3217 if (len >= sizeof(field))
3219 strict = os_strchr(field, ' ');
3220 if (strict != NULL) {
3222 if (os_strcmp(strict, "strict") != 0)
3226 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
3227 field, strict ? strict : "");
3229 if (os_strcmp(field, "eap") == 0) {
3230 return eap_get_names(buf, buflen);
3233 res = wpa_drv_get_capa(wpa_s, &capa);
3235 if (os_strcmp(field, "pairwise") == 0)
3236 return ctrl_iface_get_capability_pairwise(res, strict, &capa,
3239 if (os_strcmp(field, "group") == 0)
3240 return ctrl_iface_get_capability_group(res, strict, &capa,
3243 if (os_strcmp(field, "key_mgmt") == 0)
3244 return ctrl_iface_get_capability_key_mgmt(res, strict, &capa,
3247 if (os_strcmp(field, "proto") == 0)
3248 return ctrl_iface_get_capability_proto(res, strict, &capa,
3251 if (os_strcmp(field, "auth_alg") == 0)
3252 return ctrl_iface_get_capability_auth_alg(res, strict, &capa,
3255 if (os_strcmp(field, "modes") == 0)
3256 return ctrl_iface_get_capability_modes(res, strict, &capa,
3259 if (os_strcmp(field, "channels") == 0)
3260 return ctrl_iface_get_capability_channels(wpa_s, buf, buflen);
3262 if (os_strcmp(field, "freq") == 0)
3263 return ctrl_iface_get_capability_freq(wpa_s, buf, buflen);
3265 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
3272 #ifdef CONFIG_INTERWORKING
3273 static char * anqp_add_hex(char *pos, char *end, const char *title,
3274 struct wpabuf *data)
3284 ret = os_snprintf(pos, end - pos, "%s=", title);
3285 if (ret < 0 || ret >= end - pos)
3289 d = wpabuf_head_u8(data);
3290 for (i = 0; i < wpabuf_len(data); i++) {
3291 ret = os_snprintf(pos, end - pos, "%02x", *d++);
3292 if (ret < 0 || ret >= end - pos)
3297 ret = os_snprintf(pos, end - pos, "\n");
3298 if (ret < 0 || ret >= end - pos)
3304 #endif /* CONFIG_INTERWORKING */
3307 static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
3308 unsigned long mask, char *buf, size_t buflen)
3318 if (mask & WPA_BSS_MASK_ID) {
3319 ret = os_snprintf(pos, end - pos, "id=%u\n", bss->id);
3320 if (ret < 0 || ret >= end - pos)
3325 if (mask & WPA_BSS_MASK_BSSID) {
3326 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
3327 MAC2STR(bss->bssid));
3328 if (ret < 0 || ret >= end - pos)
3333 if (mask & WPA_BSS_MASK_FREQ) {
3334 ret = os_snprintf(pos, end - pos, "freq=%d\n", bss->freq);
3335 if (ret < 0 || ret >= end - pos)
3340 if (mask & WPA_BSS_MASK_BEACON_INT) {
3341 ret = os_snprintf(pos, end - pos, "beacon_int=%d\n",
3343 if (ret < 0 || ret >= end - pos)
3348 if (mask & WPA_BSS_MASK_CAPABILITIES) {
3349 ret = os_snprintf(pos, end - pos, "capabilities=0x%04x\n",
3351 if (ret < 0 || ret >= end - pos)
3356 if (mask & WPA_BSS_MASK_QUAL) {
3357 ret = os_snprintf(pos, end - pos, "qual=%d\n", bss->qual);
3358 if (ret < 0 || ret >= end - pos)
3363 if (mask & WPA_BSS_MASK_NOISE) {
3364 ret = os_snprintf(pos, end - pos, "noise=%d\n", bss->noise);
3365 if (ret < 0 || ret >= end - pos)
3370 if (mask & WPA_BSS_MASK_LEVEL) {
3371 ret = os_snprintf(pos, end - pos, "level=%d\n", bss->level);
3372 if (ret < 0 || ret >= end - pos)
3377 if (mask & WPA_BSS_MASK_TSF) {
3378 ret = os_snprintf(pos, end - pos, "tsf=%016llu\n",
3379 (unsigned long long) bss->tsf);
3380 if (ret < 0 || ret >= end - pos)
3385 if (mask & WPA_BSS_MASK_AGE) {
3386 struct os_reltime now;
3388 os_get_reltime(&now);
3389 ret = os_snprintf(pos, end - pos, "age=%d\n",
3390 (int) (now.sec - bss->last_update.sec));
3391 if (ret < 0 || ret >= end - pos)
3396 if (mask & WPA_BSS_MASK_IE) {
3397 ret = os_snprintf(pos, end - pos, "ie=");
3398 if (ret < 0 || ret >= end - pos)
3402 ie = (const u8 *) (bss + 1);
3403 for (i = 0; i < bss->ie_len; i++) {
3404 ret = os_snprintf(pos, end - pos, "%02x", *ie++);
3405 if (ret < 0 || ret >= end - pos)
3410 ret = os_snprintf(pos, end - pos, "\n");
3411 if (ret < 0 || ret >= end - pos)
3416 if (mask & WPA_BSS_MASK_FLAGS) {
3417 ret = os_snprintf(pos, end - pos, "flags=");
3418 if (ret < 0 || ret >= end - pos)
3422 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
3424 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie,
3426 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
3428 pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2,
3430 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
3431 if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
3432 ret = os_snprintf(pos, end - pos, "[WEP]");
3433 if (ret < 0 || ret >= end - pos)
3437 if (bss->caps & IEEE80211_CAP_IBSS) {
3438 ret = os_snprintf(pos, end - pos, "[IBSS]");
3439 if (ret < 0 || ret >= end - pos)
3443 if (bss->caps & IEEE80211_CAP_ESS) {
3444 ret = os_snprintf(pos, end - pos, "[ESS]");
3445 if (ret < 0 || ret >= end - pos)
3449 if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
3450 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
3451 ret = os_snprintf(pos, end - pos, "[P2P]");
3452 if (ret < 0 || ret >= end - pos)
3457 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) {
3458 ret = os_snprintf(pos, end - pos, "[HS20]");
3459 if (ret < 0 || ret >= end - pos)
3463 #endif /* CONFIG_HS20 */
3465 ret = os_snprintf(pos, end - pos, "\n");
3466 if (ret < 0 || ret >= end - pos)
3471 if (mask & WPA_BSS_MASK_SSID) {
3472 ret = os_snprintf(pos, end - pos, "ssid=%s\n",
3473 wpa_ssid_txt(bss->ssid, bss->ssid_len));
3474 if (ret < 0 || ret >= end - pos)
3480 if (mask & WPA_BSS_MASK_WPS_SCAN) {
3481 ie = (const u8 *) (bss + 1);
3482 ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end);
3483 if (ret < 0 || ret >= end - pos)
3487 #endif /* CONFIG_WPS */
3490 if (mask & WPA_BSS_MASK_P2P_SCAN) {
3491 ie = (const u8 *) (bss + 1);
3492 ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end);
3493 if (ret < 0 || ret >= end - pos)
3497 #endif /* CONFIG_P2P */
3499 #ifdef CONFIG_WIFI_DISPLAY
3500 if (mask & WPA_BSS_MASK_WIFI_DISPLAY) {
3502 ie = (const u8 *) (bss + 1);
3503 wfd = ieee802_11_vendor_ie_concat(ie, bss->ie_len,
3504 WFD_IE_VENDOR_TYPE);
3506 ret = os_snprintf(pos, end - pos, "wfd_subelems=");
3507 if (ret < 0 || ret >= end - pos) {
3513 pos += wpa_snprintf_hex(pos, end - pos,
3518 ret = os_snprintf(pos, end - pos, "\n");
3519 if (ret < 0 || ret >= end - pos)
3524 #endif /* CONFIG_WIFI_DISPLAY */
3526 #ifdef CONFIG_INTERWORKING
3527 if ((mask & WPA_BSS_MASK_INTERNETW) && bss->anqp) {
3528 struct wpa_bss_anqp *anqp = bss->anqp;
3529 pos = anqp_add_hex(pos, end, "anqp_venue_name",
3531 pos = anqp_add_hex(pos, end, "anqp_network_auth_type",
3532 anqp->network_auth_type);
3533 pos = anqp_add_hex(pos, end, "anqp_roaming_consortium",
3534 anqp->roaming_consortium);
3535 pos = anqp_add_hex(pos, end, "anqp_ip_addr_type_availability",
3536 anqp->ip_addr_type_availability);
3537 pos = anqp_add_hex(pos, end, "anqp_nai_realm",
3539 pos = anqp_add_hex(pos, end, "anqp_3gpp", anqp->anqp_3gpp);
3540 pos = anqp_add_hex(pos, end, "anqp_domain_name",
3543 pos = anqp_add_hex(pos, end, "hs20_operator_friendly_name",
3544 anqp->hs20_operator_friendly_name);
3545 pos = anqp_add_hex(pos, end, "hs20_wan_metrics",
3546 anqp->hs20_wan_metrics);
3547 pos = anqp_add_hex(pos, end, "hs20_connection_capability",
3548 anqp->hs20_connection_capability);
3549 #endif /* CONFIG_HS20 */
3551 #endif /* CONFIG_INTERWORKING */
3553 if (mask & WPA_BSS_MASK_DELIM) {
3554 ret = os_snprintf(pos, end - pos, "====\n");
3555 if (ret < 0 || ret >= end - pos)
3564 static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
3565 const char *cmd, char *buf,
3570 struct wpa_bss *bss;
3571 struct wpa_bss *bsslast = NULL;
3572 struct dl_list *next;
3576 unsigned long mask = WPA_BSS_MASK_ALL;
3578 if (os_strncmp(cmd, "RANGE=", 6) == 0) {
3579 if (os_strncmp(cmd + 6, "ALL", 3) == 0) {
3580 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss,
3582 bsslast = dl_list_last(&wpa_s->bss_id, struct wpa_bss,
3584 } else { /* N1-N2 */
3585 unsigned int id1, id2;
3587 if ((ctmp = os_strchr(cmd + 6, '-')) == NULL) {
3588 wpa_printf(MSG_INFO, "Wrong BSS range "
3593 if (*(cmd + 6) == '-')
3596 id1 = atoi(cmd + 6);
3598 if (*ctmp >= '0' && *ctmp <= '9')
3601 id2 = (unsigned int) -1;
3602 bss = wpa_bss_get_id_range(wpa_s, id1, id2);
3603 if (id2 == (unsigned int) -1)
3604 bsslast = dl_list_last(&wpa_s->bss_id,
3608 bsslast = wpa_bss_get_id(wpa_s, id2);
3609 if (bsslast == NULL && bss && id2 > id1) {
3610 struct wpa_bss *tmp = bss;
3612 next = tmp->list_id.next;
3613 if (next == &wpa_s->bss_id)
3615 tmp = dl_list_entry(
3616 next, struct wpa_bss,
3625 } else if (os_strncmp(cmd, "FIRST", 5) == 0)
3626 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, list_id);
3627 else if (os_strncmp(cmd, "LAST", 4) == 0)
3628 bss = dl_list_last(&wpa_s->bss_id, struct wpa_bss, list_id);
3629 else if (os_strncmp(cmd, "ID-", 3) == 0) {
3631 bss = wpa_bss_get_id(wpa_s, i);
3632 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
3634 bss = wpa_bss_get_id(wpa_s, i);
3636 next = bss->list_id.next;
3637 if (next == &wpa_s->bss_id)
3640 bss = dl_list_entry(next, struct wpa_bss,
3644 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
3645 if (hwaddr_aton(cmd + 13, bssid) == 0)
3646 bss = wpa_bss_get_p2p_dev_addr(wpa_s, bssid);
3649 #endif /* CONFIG_P2P */
3650 } else if (hwaddr_aton(cmd, bssid) == 0)
3651 bss = wpa_bss_get_bssid(wpa_s, bssid);
3653 struct wpa_bss *tmp;
3656 dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id)
3665 if ((ctmp = os_strstr(cmd, "MASK=")) != NULL) {
3666 mask = strtoul(ctmp + 5, NULL, 0x10);
3668 mask = WPA_BSS_MASK_ALL;
3674 if (bsslast == NULL)
3677 len = print_bss_info(wpa_s, bss, mask, buf, buflen);
3681 if (bss == bsslast) {
3682 if ((mask & WPA_BSS_MASK_DELIM) && len &&
3683 (bss == dl_list_last(&wpa_s->bss_id,
3684 struct wpa_bss, list_id)))
3685 os_snprintf(buf - 5, 5, "####\n");
3688 next = bss->list_id.next;
3689 if (next == &wpa_s->bss_id)
3691 bss = dl_list_entry(next, struct wpa_bss, list_id);
3692 } while (bss && len);
3698 static int wpa_supplicant_ctrl_iface_ap_scan(
3699 struct wpa_supplicant *wpa_s, char *cmd)
3701 int ap_scan = atoi(cmd);
3702 return wpa_supplicant_set_ap_scan(wpa_s, ap_scan);
3706 static int wpa_supplicant_ctrl_iface_scan_interval(
3707 struct wpa_supplicant *wpa_s, char *cmd)
3709 int scan_int = atoi(cmd);
3710 return wpa_supplicant_set_scan_interval(wpa_s, scan_int);
3714 static int wpa_supplicant_ctrl_iface_bss_expire_age(
3715 struct wpa_supplicant *wpa_s, char *cmd)
3717 int expire_age = atoi(cmd);
3718 return wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age);
3722 static int wpa_supplicant_ctrl_iface_bss_expire_count(
3723 struct wpa_supplicant *wpa_s, char *cmd)
3725 int expire_count = atoi(cmd);
3726 return wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count);
3730 static int wpa_supplicant_ctrl_iface_bss_flush(
3731 struct wpa_supplicant *wpa_s, char *cmd)
3733 int flush_age = atoi(cmd);
3736 wpa_bss_flush(wpa_s);
3738 wpa_bss_flush_by_age(wpa_s, flush_age);
3743 static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s)
3745 wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication");
3746 /* MLME-DELETEKEYS.request */
3747 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL, 0);
3748 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL, 0);
3749 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL, 0);
3750 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL, 0);
3751 #ifdef CONFIG_IEEE80211W
3752 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL, 0);
3753 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL, 0);
3754 #endif /* CONFIG_IEEE80211W */
3756 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, wpa_s->bssid, 0, 0, NULL, 0, NULL,
3758 /* MLME-SETPROTECTION.request(None) */
3759 wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid,
3760 MLME_SETPROTECTION_PROTECT_TYPE_NONE,
3761 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE);
3762 wpa_sm_drop_sa(wpa_s->wpa);
3766 static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s,
3769 #ifdef CONFIG_NO_SCAN_PROCESSING
3771 #else /* CONFIG_NO_SCAN_PROCESSING */
3773 struct wpa_bss *bss;
3774 struct wpa_ssid *ssid = wpa_s->current_ssid;
3776 if (hwaddr_aton(addr, bssid)) {
3777 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid "
3778 "address '%s'", addr);
3782 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR, MAC2STR(bssid));
3785 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network "
3786 "configuration known for the target AP");
3790 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
3792 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found "
3798 * TODO: Find best network configuration block from configuration to
3799 * allow roaming to other networks
3802 wpa_s->reassociate = 1;
3803 wpa_supplicant_connect(wpa_s, bss, ssid);
3806 #endif /* CONFIG_NO_SCAN_PROCESSING */
3811 static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd)
3813 unsigned int timeout = atoi(cmd);
3814 enum p2p_discovery_type type = P2P_FIND_START_WITH_FULL;
3815 u8 dev_id[ETH_ALEN], *_dev_id = NULL;
3816 u8 dev_type[WPS_DEV_TYPE_LEN], *_dev_type = NULL;
3818 unsigned int search_delay;
3820 if (os_strstr(cmd, "type=social"))
3821 type = P2P_FIND_ONLY_SOCIAL;
3822 else if (os_strstr(cmd, "type=progressive"))
3823 type = P2P_FIND_PROGRESSIVE;
3825 pos = os_strstr(cmd, "dev_id=");
3828 if (hwaddr_aton(pos, dev_id))
3833 pos = os_strstr(cmd, "dev_type=");
3836 if (wps_dev_type_str2bin(pos, dev_type) < 0)
3838 _dev_type = dev_type;
3841 pos = os_strstr(cmd, "delay=");
3844 search_delay = atoi(pos);
3846 search_delay = wpas_p2p_search_delay(wpa_s);
3848 return wpas_p2p_find(wpa_s, timeout, type, _dev_type != NULL, _dev_type,
3849 _dev_id, search_delay);
3853 static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd,
3854 char *buf, size_t buflen)
3859 enum p2p_wps_method wps_method;
3862 int persistent_group, persistent_id = -1;
3871 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad]
3872 * [persistent|persistent=<network id>]
3873 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
3876 if (hwaddr_aton(cmd, addr))
3884 persistent_group = os_strstr(pos, " persistent") != NULL;
3885 pos2 = os_strstr(pos, " persistent=");
3887 struct wpa_ssid *ssid;
3888 persistent_id = atoi(pos2 + 12);
3889 ssid = wpa_config_get_network(wpa_s->conf, persistent_id);
3890 if (ssid == NULL || ssid->disabled != 2 ||
3891 ssid->mode != WPAS_MODE_P2P_GO) {
3892 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3893 "SSID id=%d for persistent P2P group (GO)",
3898 join = os_strstr(pos, " join") != NULL;
3899 auth = os_strstr(pos, " auth") != NULL;
3900 automatic = os_strstr(pos, " auto") != NULL;
3901 pd = os_strstr(pos, " provdisc") != NULL;
3902 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
3903 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
3906 pos2 = os_strstr(pos, " go_intent=");
3909 go_intent = atoi(pos2);
3910 if (go_intent < 0 || go_intent > 15)
3914 pos2 = os_strstr(pos, " freq=");
3922 if (os_strncmp(pos, "pin", 3) == 0) {
3923 /* Request random PIN (to be displayed) and enable the PIN */
3924 wps_method = WPS_PIN_DISPLAY;
3925 } else if (os_strncmp(pos, "pbc", 3) == 0) {
3926 wps_method = WPS_PBC;
3929 pos = os_strchr(pin, ' ');
3930 wps_method = WPS_PIN_KEYPAD;
3933 if (os_strncmp(pos, "display", 7) == 0)
3934 wps_method = WPS_PIN_DISPLAY;
3936 if (!wps_pin_str_valid(pin)) {
3937 os_memcpy(buf, "FAIL-INVALID-PIN\n", 17);
3942 new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method,
3943 persistent_group, automatic, join,
3944 auth, go_intent, freq, persistent_id, pd,
3946 if (new_pin == -2) {
3947 os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
3950 if (new_pin == -3) {
3951 os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
3956 if (wps_method == WPS_PIN_DISPLAY && pin == NULL) {
3957 ret = os_snprintf(buf, buflen, "%08d", new_pin);
3958 if (ret < 0 || (size_t) ret >= buflen)
3963 os_memcpy(buf, "OK\n", 3);
3968 static int p2p_ctrl_listen(struct wpa_supplicant *wpa_s, char *cmd)
3970 unsigned int timeout = atoi(cmd);
3971 return wpas_p2p_listen(wpa_s, timeout);
3975 static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd)
3979 enum wpas_p2p_prov_disc_use use = WPAS_P2P_PD_FOR_GO_NEG;
3981 /* <addr> <config method> [join|auto] */
3983 if (hwaddr_aton(cmd, addr))
3991 if (os_strstr(pos, " join") != NULL)
3992 use = WPAS_P2P_PD_FOR_JOIN;
3993 else if (os_strstr(pos, " auto") != NULL)
3994 use = WPAS_P2P_PD_AUTO;
3996 return wpas_p2p_prov_disc(wpa_s, addr, pos, use);
4000 static int p2p_get_passphrase(struct wpa_supplicant *wpa_s, char *buf,
4003 struct wpa_ssid *ssid = wpa_s->current_ssid;
4005 if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO ||
4006 ssid->passphrase == NULL)
4009 os_strlcpy(buf, ssid->passphrase, buflen);
4010 return os_strlen(buf);
4014 static int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd,
4015 char *buf, size_t buflen)
4019 u8 dst_buf[ETH_ALEN], *dst;
4020 struct wpabuf *tlvs;
4024 if (hwaddr_aton(cmd, dst_buf))
4027 if (dst[0] == 0 && dst[1] == 0 && dst[2] == 0 &&
4028 dst[3] == 0 && dst[4] == 0 && dst[5] == 0)
4035 if (os_strncmp(pos, "upnp ", 5) == 0) {
4038 if (hexstr2bin(pos, &version, 1) < 0)
4044 ref = wpas_p2p_sd_request_upnp(wpa_s, dst, version, pos);
4045 #ifdef CONFIG_WIFI_DISPLAY
4046 } else if (os_strncmp(pos, "wifi-display ", 13) == 0) {
4047 ref = wpas_p2p_sd_request_wifi_display(wpa_s, dst, pos + 13);
4048 #endif /* CONFIG_WIFI_DISPLAY */
4050 len = os_strlen(pos);
4054 tlvs = wpabuf_alloc(len);
4057 if (hexstr2bin(pos, wpabuf_put(tlvs, len), len) < 0) {
4062 ref = wpas_p2p_sd_request(wpa_s, dst, tlvs);
4067 res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref);
4068 if (res < 0 || (unsigned) res >= buflen)
4074 static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s,
4077 long long unsigned val;
4079 if (sscanf(cmd, "%llx", &val) != 1)
4082 return wpas_p2p_sd_cancel_request(wpa_s, req);
4086 static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant *wpa_s, char *cmd)
4091 struct wpabuf *resp_tlvs;
4095 pos = os_strchr(cmd, ' ');
4103 if (hwaddr_aton(pos, dst))
4110 pos2 = os_strchr(pos, ' ');
4114 dialog_token = atoi(pos);
4116 len = os_strlen(pos2);
4120 resp_tlvs = wpabuf_alloc(len);
4121 if (resp_tlvs == NULL)
4123 if (hexstr2bin(pos2, wpabuf_put(resp_tlvs, len), len) < 0) {
4124 wpabuf_free(resp_tlvs);
4128 wpas_p2p_sd_response(wpa_s, freq, dst, dialog_token, resp_tlvs);
4129 wpabuf_free(resp_tlvs);
4134 static int p2p_ctrl_serv_disc_external(struct wpa_supplicant *wpa_s,
4137 if (os_strcmp(cmd, "0") && os_strcmp(cmd, "1"))
4139 wpa_s->p2p_sd_over_ctrl_iface = atoi(cmd);
4144 static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant *wpa_s,
4149 struct wpabuf *query, *resp;
4151 pos = os_strchr(cmd, ' ');
4156 len = os_strlen(cmd);
4160 query = wpabuf_alloc(len);
4163 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
4168 len = os_strlen(pos);
4174 resp = wpabuf_alloc(len);
4179 if (hexstr2bin(pos, wpabuf_put(resp, len), len) < 0) {
4185 if (wpas_p2p_service_add_bonjour(wpa_s, query, resp) < 0) {
4194 static int p2p_ctrl_service_add_upnp(struct wpa_supplicant *wpa_s, char *cmd)
4199 pos = os_strchr(cmd, ' ');
4204 if (hexstr2bin(cmd, &version, 1) < 0)
4207 return wpas_p2p_service_add_upnp(wpa_s, version, pos);
4211 static int p2p_ctrl_service_add(struct wpa_supplicant *wpa_s, char *cmd)
4215 pos = os_strchr(cmd, ' ');
4220 if (os_strcmp(cmd, "bonjour") == 0)
4221 return p2p_ctrl_service_add_bonjour(wpa_s, pos);
4222 if (os_strcmp(cmd, "upnp") == 0)
4223 return p2p_ctrl_service_add_upnp(wpa_s, pos);
4224 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
4229 static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant *wpa_s,
4233 struct wpabuf *query;
4236 len = os_strlen(cmd);
4240 query = wpabuf_alloc(len);
4243 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
4248 ret = wpas_p2p_service_del_bonjour(wpa_s, query);
4254 static int p2p_ctrl_service_del_upnp(struct wpa_supplicant *wpa_s, char *cmd)
4259 pos = os_strchr(cmd, ' ');
4264 if (hexstr2bin(cmd, &version, 1) < 0)
4267 return wpas_p2p_service_del_upnp(wpa_s, version, pos);
4271 static int p2p_ctrl_service_del(struct wpa_supplicant *wpa_s, char *cmd)
4275 pos = os_strchr(cmd, ' ');
4280 if (os_strcmp(cmd, "bonjour") == 0)
4281 return p2p_ctrl_service_del_bonjour(wpa_s, pos);
4282 if (os_strcmp(cmd, "upnp") == 0)
4283 return p2p_ctrl_service_del_upnp(wpa_s, pos);
4284 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
4289 static int p2p_ctrl_reject(struct wpa_supplicant *wpa_s, char *cmd)
4295 if (hwaddr_aton(cmd, addr))
4298 return wpas_p2p_reject(wpa_s, addr);
4302 static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd)
4306 struct wpa_ssid *ssid;
4307 u8 *_peer = NULL, peer[ETH_ALEN];
4308 int freq = 0, pref_freq = 0;
4312 pos = os_strstr(cmd, " peer=");
4315 if (hwaddr_aton(pos, peer))
4319 ssid = wpa_config_get_network(wpa_s->conf, id);
4320 if (ssid == NULL || ssid->disabled != 2) {
4321 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
4322 "for persistent P2P group",
4327 pos = os_strstr(cmd, " freq=");
4335 pos = os_strstr(cmd, " pref=");
4338 pref_freq = atoi(pos);
4343 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
4344 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
4347 return wpas_p2p_invite(wpa_s, _peer, ssid, NULL, freq, ht40, vht,
4352 static int p2p_ctrl_invite_group(struct wpa_supplicant *wpa_s, char *cmd)
4355 u8 peer[ETH_ALEN], go_dev_addr[ETH_ALEN], *go_dev = NULL;
4357 pos = os_strstr(cmd, " peer=");
4363 if (hwaddr_aton(pos, peer)) {
4364 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", pos);
4368 pos = os_strstr(pos, " go_dev_addr=");
4371 if (hwaddr_aton(pos, go_dev_addr)) {
4372 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'",
4376 go_dev = go_dev_addr;
4379 return wpas_p2p_invite_group(wpa_s, cmd, peer, go_dev);
4383 static int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd)
4385 if (os_strncmp(cmd, "persistent=", 11) == 0)
4386 return p2p_ctrl_invite_persistent(wpa_s, cmd + 11);
4387 if (os_strncmp(cmd, "group=", 6) == 0)
4388 return p2p_ctrl_invite_group(wpa_s, cmd + 6);
4394 static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s,
4395 char *cmd, int freq, int ht40,
4399 struct wpa_ssid *ssid;
4402 ssid = wpa_config_get_network(wpa_s->conf, id);
4403 if (ssid == NULL || ssid->disabled != 2) {
4404 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
4405 "for persistent P2P group",
4410 return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq, 0, ht40, vht,
4415 static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd)
4417 int freq = 0, ht40, vht;
4420 pos = os_strstr(cmd, "freq=");
4422 freq = atoi(pos + 5);
4424 vht = (os_strstr(cmd, "vht") != NULL) || wpa_s->conf->p2p_go_vht;
4425 ht40 = (os_strstr(cmd, "ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
4428 if (os_strncmp(cmd, "persistent=", 11) == 0)
4429 return p2p_ctrl_group_add_persistent(wpa_s, cmd + 11, freq,
4431 if (os_strcmp(cmd, "persistent") == 0 ||
4432 os_strncmp(cmd, "persistent ", 11) == 0)
4433 return wpas_p2p_group_add(wpa_s, 1, freq, ht40, vht);
4434 if (os_strncmp(cmd, "freq=", 5) == 0)
4435 return wpas_p2p_group_add(wpa_s, 0, freq, ht40, vht);
4437 return wpas_p2p_group_add(wpa_s, 0, freq, ht40, vht);
4439 wpa_printf(MSG_DEBUG, "CTRL: Invalid P2P_GROUP_ADD parameters '%s'",
4445 static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd,
4446 char *buf, size_t buflen)
4448 u8 addr[ETH_ALEN], *addr_ptr;
4450 const struct p2p_peer_info *info;
4452 char devtype[WPS_DEV_TYPE_BUFSIZE];
4453 struct wpa_ssid *ssid;
4456 if (!wpa_s->global->p2p)
4459 if (os_strcmp(cmd, "FIRST") == 0) {
4462 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
4463 if (hwaddr_aton(cmd + 5, addr) < 0)
4468 if (hwaddr_aton(cmd, addr) < 0)
4474 info = p2p_get_peer_info(wpa_s->global->p2p, addr_ptr, next);
4481 res = os_snprintf(pos, end - pos, MACSTR "\n"
4487 "serial_number=%s\n"
4488 "config_methods=0x%x\n"
4490 "group_capab=0x%x\n"
4492 MAC2STR(info->p2p_device_addr),
4493 wps_dev_type_bin2str(info->pri_dev_type,
4494 devtype, sizeof(devtype)),
4499 info->serial_number,
4500 info->config_methods,
4504 if (res < 0 || res >= end - pos)
4508 for (i = 0; i < info->wps_sec_dev_type_list_len / WPS_DEV_TYPE_LEN; i++)
4511 t = &info->wps_sec_dev_type_list[i * WPS_DEV_TYPE_LEN];
4512 res = os_snprintf(pos, end - pos, "sec_dev_type=%s\n",
4513 wps_dev_type_bin2str(t, devtype,
4515 if (res < 0 || res >= end - pos)
4520 ssid = wpas_p2p_get_persistent(wpa_s, info->p2p_device_addr, NULL, 0);
4522 res = os_snprintf(pos, end - pos, "persistent=%d\n", ssid->id);
4523 if (res < 0 || res >= end - pos)
4528 res = p2p_get_peer_info_txt(info, pos, end - pos);
4537 static int p2p_ctrl_disallow_freq(struct wpa_supplicant *wpa_s,
4542 if (wpa_s->global->p2p == NULL)
4545 if (freq_range_list_parse(&wpa_s->global->p2p_disallow_freq, param) < 0)
4548 for (i = 0; i < wpa_s->global->p2p_disallow_freq.num; i++) {
4549 struct wpa_freq_range *freq;
4550 freq = &wpa_s->global->p2p_disallow_freq.range[i];
4551 wpa_printf(MSG_DEBUG, "P2P: Disallowed frequency range %u-%u",
4552 freq->min, freq->max);
4555 wpas_p2p_update_channel_list(wpa_s);
4560 static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd)
4564 if (wpa_s->global->p2p == NULL)
4567 param = os_strchr(cmd, ' ');
4572 if (os_strcmp(cmd, "discoverability") == 0) {
4573 p2p_set_client_discoverability(wpa_s->global->p2p,
4578 if (os_strcmp(cmd, "managed") == 0) {
4579 p2p_set_managed_oper(wpa_s->global->p2p, atoi(param));
4583 if (os_strcmp(cmd, "listen_channel") == 0) {
4584 return p2p_set_listen_channel(wpa_s->global->p2p, 81,
4588 if (os_strcmp(cmd, "ssid_postfix") == 0) {
4589 return p2p_set_ssid_postfix(wpa_s->global->p2p, (u8 *) param,
4593 if (os_strcmp(cmd, "noa") == 0) {
4595 int count, start, duration;
4596 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
4597 count = atoi(param);
4598 pos = os_strchr(param, ',');
4603 pos = os_strchr(pos, ',');
4607 duration = atoi(pos);
4608 if (count < 0 || count > 255 || start < 0 || duration < 0)
4610 if (count == 0 && duration > 0)
4612 wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
4613 "start=%d duration=%d", count, start, duration);
4614 return wpas_p2p_set_noa(wpa_s, count, start, duration);
4617 if (os_strcmp(cmd, "ps") == 0)
4618 return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1);
4620 if (os_strcmp(cmd, "oppps") == 0)
4621 return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1);
4623 if (os_strcmp(cmd, "ctwindow") == 0)
4624 return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param));
4626 if (os_strcmp(cmd, "disabled") == 0) {
4627 wpa_s->global->p2p_disabled = atoi(param);
4628 wpa_printf(MSG_DEBUG, "P2P functionality %s",
4629 wpa_s->global->p2p_disabled ?
4630 "disabled" : "enabled");
4631 if (wpa_s->global->p2p_disabled) {
4632 wpas_p2p_stop_find(wpa_s);
4633 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
4634 p2p_flush(wpa_s->global->p2p);
4639 if (os_strcmp(cmd, "conc_pref") == 0) {
4640 if (os_strcmp(param, "sta") == 0)
4641 wpa_s->global->conc_pref = WPA_CONC_PREF_STA;
4642 else if (os_strcmp(param, "p2p") == 0)
4643 wpa_s->global->conc_pref = WPA_CONC_PREF_P2P;
4645 wpa_printf(MSG_INFO, "Invalid conc_pref value");
4648 wpa_printf(MSG_DEBUG, "Single channel concurrency preference: "
4653 if (os_strcmp(cmd, "force_long_sd") == 0) {
4654 wpa_s->force_long_sd = atoi(param);
4658 if (os_strcmp(cmd, "peer_filter") == 0) {
4660 if (hwaddr_aton(param, addr))
4662 p2p_set_peer_filter(wpa_s->global->p2p, addr);
4666 if (os_strcmp(cmd, "cross_connect") == 0)
4667 return wpas_p2p_set_cross_connect(wpa_s, atoi(param));
4669 if (os_strcmp(cmd, "go_apsd") == 0) {
4670 if (os_strcmp(param, "disable") == 0)
4671 wpa_s->set_ap_uapsd = 0;
4673 wpa_s->set_ap_uapsd = 1;
4674 wpa_s->ap_uapsd = atoi(param);
4679 if (os_strcmp(cmd, "client_apsd") == 0) {
4680 if (os_strcmp(param, "disable") == 0)
4681 wpa_s->set_sta_uapsd = 0;
4685 /* format: BE,BK,VI,VO;max SP Length */
4687 pos = os_strchr(param, ',');
4692 pos = os_strchr(pos, ',');
4697 pos = os_strchr(pos, ',');
4702 /* ignore max SP Length for now */
4704 wpa_s->set_sta_uapsd = 1;
4705 wpa_s->sta_uapsd = 0;
4707 wpa_s->sta_uapsd |= BIT(0);
4709 wpa_s->sta_uapsd |= BIT(1);
4711 wpa_s->sta_uapsd |= BIT(2);
4713 wpa_s->sta_uapsd |= BIT(3);
4718 if (os_strcmp(cmd, "disallow_freq") == 0)
4719 return p2p_ctrl_disallow_freq(wpa_s, param);
4721 if (os_strcmp(cmd, "disc_int") == 0) {
4722 int min_disc_int, max_disc_int, max_disc_tu;
4727 min_disc_int = atoi(pos);
4728 pos = os_strchr(pos, ' ');
4733 max_disc_int = atoi(pos);
4734 pos = os_strchr(pos, ' ');
4739 max_disc_tu = atoi(pos);
4741 return p2p_set_disc_int(wpa_s->global->p2p, min_disc_int,
4742 max_disc_int, max_disc_tu);
4745 if (os_strcmp(cmd, "per_sta_psk") == 0) {
4746 wpa_s->global->p2p_per_sta_psk = !!atoi(param);
4750 #ifdef CONFIG_WPS_NFC
4751 if (os_strcmp(cmd, "nfc_tag") == 0)
4752 return wpas_p2p_nfc_tag_enabled(wpa_s, !!atoi(param));
4753 #endif /* CONFIG_WPS_NFC */
4755 if (os_strcmp(cmd, "disable_ip_addr_req") == 0) {
4756 wpa_s->p2p_disable_ip_addr_req = !!atoi(param);
4760 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
4767 static void p2p_ctrl_flush(struct wpa_supplicant *wpa_s)
4769 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
4770 wpa_s->force_long_sd = 0;
4771 if (wpa_s->global->p2p)
4772 p2p_flush(wpa_s->global->p2p);
4776 static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd)
4779 unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0;
4782 pos = os_strchr(cmd, ' ');
4788 pos2 = os_strchr(pos, ' ');
4796 pos = os_strchr(pos2, ' ');
4804 return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2);
4808 static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd)
4811 unsigned int period = 0, interval = 0;
4814 pos = os_strchr(cmd, ' ');
4819 interval = atoi(pos);
4822 return wpas_p2p_ext_listen(wpa_s, period, interval);
4826 static int p2p_ctrl_remove_client(struct wpa_supplicant *wpa_s, const char *cmd)
4833 if (os_strncmp(pos, "iface=", 6) == 0) {
4837 if (hwaddr_aton(pos, peer))
4840 wpas_p2p_remove_client(wpa_s, peer, iface_addr);
4844 #endif /* CONFIG_P2P */
4847 static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s, char *val)
4849 struct wpa_freq_range_list ranges;
4851 struct hostapd_hw_modes *mode;
4854 if (wpa_s->hw.modes == NULL)
4857 os_memset(&ranges, 0, sizeof(ranges));
4858 if (freq_range_list_parse(&ranges, val) < 0)
4861 for (i = 0; i < wpa_s->hw.num_modes; i++) {
4864 mode = &wpa_s->hw.modes[i];
4865 for (j = 0; j < mode->num_channels; j++) {
4868 if (mode->channels[j].flag & HOSTAPD_CHAN_DISABLED)
4871 freq = mode->channels[j].freq;
4872 if (!freq_range_list_includes(&ranges, freq))
4875 int_array_add_unique(&freqs, freq);
4879 os_free(ranges.range);
4884 #ifdef CONFIG_INTERWORKING
4886 static int ctrl_interworking_select(struct wpa_supplicant *wpa_s, char *param)
4894 auto_sel = os_strstr(param, "auto") != NULL;
4896 pos = os_strstr(param, "freq=");
4898 freqs = freq_range_to_channel_list(wpa_s, pos + 5);
4905 return interworking_select(wpa_s, auto_sel, freqs);
4909 static int ctrl_interworking_connect(struct wpa_supplicant *wpa_s, char *dst)
4912 struct wpa_bss *bss;
4914 if (hwaddr_aton(dst, bssid)) {
4915 wpa_printf(MSG_DEBUG, "Invalid BSSID '%s'", dst);
4919 bss = wpa_bss_get_bssid(wpa_s, bssid);
4921 wpa_printf(MSG_DEBUG, "Could not find BSS " MACSTR,
4926 return interworking_connect(wpa_s, bss);
4930 static int get_anqp(struct wpa_supplicant *wpa_s, char *dst)
4932 u8 dst_addr[ETH_ALEN];
4935 #define MAX_ANQP_INFO_ID 100
4936 u16 id[MAX_ANQP_INFO_ID];
4939 used = hwaddr_aton2(dst, dst_addr);
4943 while (num_id < MAX_ANQP_INFO_ID) {
4944 id[num_id] = atoi(pos);
4947 pos = os_strchr(pos + 1, ',');
4956 return anqp_send_req(wpa_s, dst_addr, id, num_id);
4960 static int gas_request(struct wpa_supplicant *wpa_s, char *cmd)
4962 u8 dst_addr[ETH_ALEN];
4963 struct wpabuf *advproto, *query = NULL;
4968 used = hwaddr_aton2(cmd, dst_addr);
4976 /* Advertisement Protocol ID */
4977 end = os_strchr(pos, ' ');
4981 len = os_strlen(pos);
4987 advproto = wpabuf_alloc(len);
4988 if (advproto == NULL)
4990 if (hexstr2bin(pos, wpabuf_put(advproto, len), len) < 0)
4994 /* Optional Query Request */
4999 len = os_strlen(pos);
5006 query = wpabuf_alloc(len);
5009 if (hexstr2bin(pos, wpabuf_put(query, len), len) < 0)
5014 ret = gas_send_request(wpa_s, dst_addr, advproto, query);
5017 wpabuf_free(advproto);
5024 static int gas_response_get(struct wpa_supplicant *wpa_s, char *cmd, char *buf,
5031 size_t resp_len, start, requested_len;
5032 struct wpabuf *resp;
5035 used = hwaddr_aton2(cmd, addr);
5042 dialog_token = atoi(pos);
5044 if (wpa_s->last_gas_resp &&
5045 os_memcmp(addr, wpa_s->last_gas_addr, ETH_ALEN) == 0 &&
5046 dialog_token == wpa_s->last_gas_dialog_token)
5047 resp = wpa_s->last_gas_resp;
5048 else if (wpa_s->prev_gas_resp &&
5049 os_memcmp(addr, wpa_s->prev_gas_addr, ETH_ALEN) == 0 &&
5050 dialog_token == wpa_s->prev_gas_dialog_token)
5051 resp = wpa_s->prev_gas_resp;
5055 resp_len = wpabuf_len(resp);
5057 requested_len = resp_len;
5059 pos = os_strchr(pos, ' ');
5062 if (start > resp_len)
5063 return os_snprintf(buf, buflen, "FAIL-Invalid range");
5064 pos = os_strchr(pos, ',');
5068 requested_len = atoi(pos);
5069 if (start + requested_len > resp_len)
5070 return os_snprintf(buf, buflen, "FAIL-Invalid range");
5073 if (requested_len * 2 + 1 > buflen)
5074 return os_snprintf(buf, buflen, "FAIL-Too long response");
5076 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(resp) + start,
5079 if (start + requested_len == resp_len) {
5081 * Free memory by dropping the response after it has been
5084 if (resp == wpa_s->prev_gas_resp) {
5085 wpabuf_free(wpa_s->prev_gas_resp);
5086 wpa_s->prev_gas_resp = NULL;
5088 wpabuf_free(wpa_s->last_gas_resp);
5089 wpa_s->last_gas_resp = NULL;
5095 #endif /* CONFIG_INTERWORKING */
5100 static int get_hs20_anqp(struct wpa_supplicant *wpa_s, char *dst)
5102 u8 dst_addr[ETH_ALEN];
5107 used = hwaddr_aton2(dst, dst_addr);
5112 int num = atoi(pos);
5113 if (num <= 0 || num > 31)
5115 subtypes |= BIT(num);
5116 pos = os_strchr(pos + 1, ',');
5125 return hs20_anqp_send_req(wpa_s, dst_addr, subtypes, NULL, 0);
5129 static int hs20_nai_home_realm_list(struct wpa_supplicant *wpa_s,
5130 const u8 *addr, const char *realm)
5136 rlen = os_strlen(realm);
5138 buf = os_malloc(len);
5141 buf[0] = 1; /* NAI Home Realm Count */
5142 buf[1] = 0; /* Formatted in accordance with RFC 4282 */
5144 os_memcpy(buf + 3, realm, rlen);
5146 ret = hs20_anqp_send_req(wpa_s, addr,
5147 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
5156 static int hs20_get_nai_home_realm_list(struct wpa_supplicant *wpa_s,
5159 struct wpa_cred *cred = wpa_s->conf->cred;
5160 u8 dst_addr[ETH_ALEN];
5166 used = hwaddr_aton2(dst, dst_addr);
5170 while (dst[used] == ' ')
5172 if (os_strncmp(dst + used, "realm=", 6) == 0)
5173 return hs20_nai_home_realm_list(wpa_s, dst_addr,
5176 len = os_strlen(dst + used);
5178 if (len == 0 && cred && cred->realm)
5179 return hs20_nai_home_realm_list(wpa_s, dst_addr, cred->realm);
5184 buf = os_malloc(len);
5187 if (hexstr2bin(dst + used, buf, len) < 0) {
5192 ret = hs20_anqp_send_req(wpa_s, dst_addr,
5193 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
5200 #endif /* CONFIG_HS20 */
5203 static int wpa_supplicant_ctrl_iface_sta_autoconnect(
5204 struct wpa_supplicant *wpa_s, char *cmd)
5206 wpa_s->auto_reconnect_disabled = atoi(cmd) == 0 ? 1 : 0;
5211 #ifdef CONFIG_AUTOSCAN
5213 static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant *wpa_s,
5216 enum wpa_states state = wpa_s->wpa_state;
5217 char *new_params = NULL;
5219 if (os_strlen(cmd) > 0) {
5220 new_params = os_strdup(cmd);
5221 if (new_params == NULL)
5225 os_free(wpa_s->conf->autoscan);
5226 wpa_s->conf->autoscan = new_params;
5228 if (wpa_s->conf->autoscan == NULL)
5229 autoscan_deinit(wpa_s);
5230 else if (state == WPA_DISCONNECTED || state == WPA_INACTIVE)
5231 autoscan_init(wpa_s, 1);
5232 else if (state == WPA_SCANNING)
5233 wpa_supplicant_reinit_autoscan(wpa_s);
5238 #endif /* CONFIG_AUTOSCAN */
5243 static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant *wpa_s, char *cmd)
5249 struct wpabuf *tfs_req = NULL;
5251 if (os_strncmp(cmd, "enter", 5) == 0)
5253 else if (os_strncmp(cmd, "exit", 4) == 0)
5258 pos = os_strstr(cmd, " interval=");
5260 intval = atoi(pos + 10);
5262 pos = os_strstr(cmd, " tfs_req=");
5267 end = os_strchr(pos, ' ');
5271 len = os_strlen(pos);
5275 tfs_req = wpabuf_alloc(len);
5276 if (tfs_req == NULL)
5278 if (hexstr2bin(pos, wpabuf_put(tfs_req, len), len) < 0) {
5279 wpabuf_free(tfs_req);
5284 ret = ieee802_11_send_wnmsleep_req(wpa_s, enter ? WNM_SLEEP_MODE_ENTER :
5285 WNM_SLEEP_MODE_EXIT, intval,
5287 wpabuf_free(tfs_req);
5293 static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant *wpa_s, char *cmd)
5297 query_reason = atoi(cmd);
5299 wpa_printf(MSG_DEBUG, "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d",
5302 return wnm_send_bss_transition_mgmt_query(wpa_s, query_reason);
5305 #endif /* CONFIG_WNM */
5308 /* Get string representation of channel width */
5309 static const char * channel_width_name(enum chan_width width)
5312 case CHAN_WIDTH_20_NOHT:
5313 return "20 MHz (no HT)";
5320 case CHAN_WIDTH_80P80:
5322 case CHAN_WIDTH_160:
5330 static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf,
5333 struct wpa_signal_info si;
5337 ret = wpa_drv_signal_poll(wpa_s, &si);
5344 ret = os_snprintf(pos, end - pos, "RSSI=%d\nLINKSPEED=%d\n"
5345 "NOISE=%d\nFREQUENCY=%u\n",
5346 si.current_signal, si.current_txrate / 1000,
5347 si.current_noise, si.frequency);
5348 if (ret < 0 || ret > end - pos)
5352 if (si.chanwidth != CHAN_WIDTH_UNKNOWN) {
5353 ret = os_snprintf(pos, end - pos, "WIDTH=%s\n",
5354 channel_width_name(si.chanwidth));
5355 if (ret < 0 || ret > end - pos)
5360 if (si.center_frq1 > 0 && si.center_frq2 > 0) {
5361 ret = os_snprintf(pos, end - pos,
5362 "CENTER_FRQ1=%d\nCENTER_FRQ2=%d\n",
5363 si.center_frq1, si.center_frq2);
5364 if (ret < 0 || ret > end - pos)
5369 if (si.avg_signal) {
5370 ret = os_snprintf(pos, end - pos,
5371 "AVG_RSSI=%d\n", si.avg_signal);
5372 if (ret < 0 || ret >= end - pos)
5381 static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant *wpa_s, char *buf,
5384 struct hostap_sta_driver_data sta;
5387 ret = wpa_drv_pktcnt_poll(wpa_s, &sta);
5391 ret = os_snprintf(buf, buflen, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
5392 sta.tx_packets, sta.tx_retry_failed, sta.rx_packets);
5393 if (ret < 0 || (size_t) ret > buflen)
5400 static int wpa_supplicant_driver_cmd(struct wpa_supplicant *wpa_s, char *cmd,
5401 char *buf, size_t buflen)
5405 ret = wpa_drv_driver_cmd(wpa_s, cmd, buf, buflen);
5407 if (os_strncasecmp(cmd, "COUNTRY", 7) == 0) {
5408 struct p2p_data *p2p = wpa_s->global->p2p;
5411 country[0] = cmd[8];
5412 country[1] = cmd[9];
5414 p2p_set_country(p2p, country);
5417 ret = os_snprintf(buf, buflen, "%s\n", "OK");
5421 #endif /* ANDROID */
5424 static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s)
5426 wpa_dbg(wpa_s, MSG_DEBUG, "Flush all wpa_supplicant state");
5429 wpas_p2p_stop_find(wpa_s);
5430 p2p_ctrl_flush(wpa_s);
5431 wpas_p2p_group_remove(wpa_s, "*");
5432 wpas_p2p_service_flush(wpa_s);
5433 wpa_s->global->p2p_disabled = 0;
5434 wpa_s->global->p2p_per_sta_psk = 0;
5435 wpa_s->conf->num_sec_device_types = 0;
5436 wpa_s->p2p_disable_ip_addr_req = 0;
5437 #endif /* CONFIG_P2P */
5439 #ifdef CONFIG_WPS_TESTING
5440 wps_version_number = 0x20;
5441 wps_testing_dummy_cred = 0;
5442 wps_corrupt_pkhash = 0;
5443 #endif /* CONFIG_WPS_TESTING */
5445 wpa_s->wps_fragment_size = 0;
5446 wpas_wps_cancel(wpa_s);
5447 #endif /* CONFIG_WPS */
5448 wpa_s->after_wps = 0;
5449 wpa_s->known_wps_freq = 0;
5452 #ifdef CONFIG_TDLS_TESTING
5453 extern unsigned int tdls_testing;
5455 #endif /* CONFIG_TDLS_TESTING */
5456 wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL);
5457 wpa_tdls_enable(wpa_s->wpa, 1);
5458 #endif /* CONFIG_TDLS */
5460 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, wpa_s, NULL);
5461 wpa_supplicant_stop_countermeasures(wpa_s, NULL);
5463 wpa_s->no_keep_alive = 0;
5465 os_free(wpa_s->disallow_aps_bssid);
5466 wpa_s->disallow_aps_bssid = NULL;
5467 wpa_s->disallow_aps_bssid_count = 0;
5468 os_free(wpa_s->disallow_aps_ssid);
5469 wpa_s->disallow_aps_ssid = NULL;
5470 wpa_s->disallow_aps_ssid_count = 0;
5472 wpa_s->set_sta_uapsd = 0;
5473 wpa_s->sta_uapsd = 0;
5475 wpa_drv_radio_disable(wpa_s, 0);
5477 wpa_bss_flush(wpa_s);
5478 wpa_blacklist_clear(wpa_s);
5479 wpa_s->extra_blacklist_count = 0;
5480 wpa_supplicant_ctrl_iface_remove_network(wpa_s, "all");
5481 wpa_supplicant_ctrl_iface_remove_cred(wpa_s, "all");
5482 wpa_config_flush_blobs(wpa_s->conf);
5483 wpa_s->conf->auto_interworking = 0;
5484 wpa_s->conf->okc = 0;
5485 wpa_s->conf->pmf = 0;
5487 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, 43200);
5488 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, 70);
5489 wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, 60);
5490 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
5492 radio_remove_unstarted_work(wpa_s, NULL);
5496 static int wpas_ctrl_radio_work_show(struct wpa_supplicant *wpa_s,
5497 char *buf, size_t buflen)
5499 struct wpa_radio_work *work;
5501 struct os_reltime now, diff;
5506 os_get_reltime(&now);
5508 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
5512 os_reltime_sub(&now, &work->time, &diff);
5513 ret = os_snprintf(pos, end - pos, "%s@%s:%u:%u:%ld.%06ld\n",
5514 work->type, work->wpa_s->ifname, work->freq,
5515 work->started, diff.sec, diff.usec);
5516 if (ret < 0 || ret >= end - pos)
5525 static void wpas_ctrl_radio_work_timeout(void *eloop_ctx, void *timeout_ctx)
5527 struct wpa_radio_work *work = eloop_ctx;
5528 struct wpa_external_work *ework = work->ctx;
5530 wpa_dbg(work->wpa_s, MSG_DEBUG,
5531 "Timing out external radio work %u (%s)",
5532 ework->id, work->type);
5533 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_TIMEOUT "%u", ework->id);
5535 radio_work_done(work);
5539 static void wpas_ctrl_radio_work_cb(struct wpa_radio_work *work, int deinit)
5541 struct wpa_external_work *ework = work->ctx;
5548 wpa_dbg(work->wpa_s, MSG_DEBUG, "Starting external radio work %u (%s)",
5549 ework->id, ework->type);
5550 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_START "%u", ework->id);
5551 if (!ework->timeout)
5552 ework->timeout = 10;
5553 eloop_register_timeout(ework->timeout, 0, wpas_ctrl_radio_work_timeout,
5558 static int wpas_ctrl_radio_work_add(struct wpa_supplicant *wpa_s, char *cmd,
5559 char *buf, size_t buflen)
5561 struct wpa_external_work *ework;
5565 unsigned int freq = 0;
5567 /* format: <name> [freq=<MHz>] [timeout=<seconds>] */
5569 ework = os_zalloc(sizeof(*ework));
5573 pos = os_strchr(cmd, ' ');
5575 type_len = pos - cmd;
5578 pos2 = os_strstr(pos, "freq=");
5580 freq = atoi(pos2 + 5);
5582 pos2 = os_strstr(pos, "timeout=");
5584 ework->timeout = atoi(pos2 + 8);
5586 type_len = os_strlen(cmd);
5588 if (4 + type_len >= sizeof(ework->type))
5589 type_len = sizeof(ework->type) - 4 - 1;
5590 os_strlcpy(ework->type, "ext:", sizeof(ework->type));
5591 os_memcpy(ework->type + 4, cmd, type_len);
5592 ework->type[4 + type_len] = '\0';
5594 wpa_s->ext_work_id++;
5595 if (wpa_s->ext_work_id == 0)
5596 wpa_s->ext_work_id++;
5597 ework->id = wpa_s->ext_work_id;
5599 if (radio_add_work(wpa_s, freq, ework->type, 0, wpas_ctrl_radio_work_cb,
5605 ret = os_snprintf(buf, buflen, "%u", ework->id);
5606 if (ret < 0 || (size_t) ret >= buflen)
5612 static int wpas_ctrl_radio_work_done(struct wpa_supplicant *wpa_s, char *cmd)
5614 struct wpa_radio_work *work;
5615 unsigned int id = atoi(cmd);
5617 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
5619 struct wpa_external_work *ework;
5621 if (os_strncmp(work->type, "ext:", 4) != 0)
5624 if (id && ework->id != id)
5626 wpa_dbg(wpa_s, MSG_DEBUG,
5627 "Completed external radio work %u (%s)",
5628 ework->id, ework->type);
5629 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, work, NULL);
5631 radio_work_done(work);
5632 return 3; /* "OK\n" */
5639 static int wpas_ctrl_radio_work(struct wpa_supplicant *wpa_s, char *cmd,
5640 char *buf, size_t buflen)
5642 if (os_strcmp(cmd, "show") == 0)
5643 return wpas_ctrl_radio_work_show(wpa_s, buf, buflen);
5644 if (os_strncmp(cmd, "add ", 4) == 0)
5645 return wpas_ctrl_radio_work_add(wpa_s, cmd + 4, buf, buflen);
5646 if (os_strncmp(cmd, "done ", 5) == 0)
5647 return wpas_ctrl_radio_work_done(wpa_s, cmd + 4);
5652 void wpas_ctrl_radio_work_flush(struct wpa_supplicant *wpa_s)
5654 struct wpa_radio_work *work, *tmp;
5656 if (!wpa_s || !wpa_s->radio)
5659 dl_list_for_each_safe(work, tmp, &wpa_s->radio->work,
5660 struct wpa_radio_work, list) {
5661 struct wpa_external_work *ework;
5663 if (os_strncmp(work->type, "ext:", 4) != 0)
5666 wpa_dbg(wpa_s, MSG_DEBUG,
5667 "Flushing %sexternal radio work %u (%s)",
5668 work->started ? " started" : "", ework->id,
5671 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
5674 radio_work_done(work);
5679 static void wpas_ctrl_eapol_response(void *eloop_ctx, void *timeout_ctx)
5681 struct wpa_supplicant *wpa_s = eloop_ctx;
5682 eapol_sm_notify_ctrl_response(wpa_s->eapol);
5686 static int set_scan_freqs(struct wpa_supplicant *wpa_s, char *val)
5690 freqs = freq_range_to_channel_list(wpa_s, val);
5694 os_free(wpa_s->manual_scan_freqs);
5695 wpa_s->manual_scan_freqs = freqs;
5701 static void wpas_ctrl_scan(struct wpa_supplicant *wpa_s, char *params,
5702 char *reply, int reply_size, int *reply_len)
5706 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
5711 wpa_s->manual_scan_passive = 0;
5712 wpa_s->manual_scan_use_id = 0;
5713 wpa_s->manual_scan_only_new = 0;
5716 if (os_strncasecmp(params, "TYPE=ONLY", 9) == 0)
5717 wpa_s->scan_res_handler = scan_only_handler;
5719 pos = os_strstr(params, "freq=");
5720 if (pos && set_scan_freqs(wpa_s, pos + 5) < 0) {
5725 pos = os_strstr(params, "passive=");
5727 wpa_s->manual_scan_passive = !!atoi(pos + 8);
5729 pos = os_strstr(params, "use_id=");
5731 wpa_s->manual_scan_use_id = atoi(pos + 7);
5733 pos = os_strstr(params, "only_new=1");
5735 wpa_s->manual_scan_only_new = 1;
5737 os_free(wpa_s->manual_scan_freqs);
5738 wpa_s->manual_scan_freqs = NULL;
5739 if (wpa_s->scan_res_handler == scan_only_handler)
5740 wpa_s->scan_res_handler = NULL;
5743 if (!wpa_s->sched_scanning && !wpa_s->scanning &&
5744 ((wpa_s->wpa_state <= WPA_SCANNING) ||
5745 (wpa_s->wpa_state == WPA_COMPLETED))) {
5746 wpa_s->normal_scans = 0;
5747 wpa_s->scan_req = MANUAL_SCAN_REQ;
5748 wpa_s->after_wps = 0;
5749 wpa_s->known_wps_freq = 0;
5750 wpa_supplicant_req_scan(wpa_s, 0, 0);
5751 if (wpa_s->manual_scan_use_id) {
5752 wpa_s->manual_scan_id++;
5753 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
5754 wpa_s->manual_scan_id);
5755 *reply_len = os_snprintf(reply, reply_size, "%u\n",
5756 wpa_s->manual_scan_id);
5758 } else if (wpa_s->sched_scanning) {
5759 wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to allow requested full scan to proceed");
5760 wpa_supplicant_cancel_sched_scan(wpa_s);
5761 wpa_s->scan_req = MANUAL_SCAN_REQ;
5762 wpa_supplicant_req_scan(wpa_s, 0, 0);
5763 if (wpa_s->manual_scan_use_id) {
5764 wpa_s->manual_scan_id++;
5765 *reply_len = os_snprintf(reply, reply_size, "%u\n",
5766 wpa_s->manual_scan_id);
5767 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
5768 wpa_s->manual_scan_id);
5771 wpa_printf(MSG_DEBUG, "Ongoing scan action - reject new request");
5772 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
5777 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
5778 char *buf, size_t *resp_len)
5781 const int reply_size = 4096;
5784 if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 ||
5785 os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
5786 if (wpa_debug_show_keys)
5787 wpa_dbg(wpa_s, MSG_DEBUG,
5788 "Control interface command '%s'", buf);
5790 wpa_dbg(wpa_s, MSG_DEBUG,
5791 "Control interface command '%s [REMOVED]'",
5792 os_strncmp(buf, WPA_CTRL_RSP,
5793 os_strlen(WPA_CTRL_RSP)) == 0 ?
5794 WPA_CTRL_RSP : "SET_NETWORK");
5795 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ", 16) == 0 ||
5796 os_strncmp(buf, "NFC_REPORT_HANDOVER", 19) == 0 ||
5797 os_strncmp(buf, "NFC_RX_HANDOVER_SEL", 19) == 0) {
5798 wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface",
5799 (const u8 *) buf, os_strlen(buf));
5801 int level = MSG_DEBUG;
5802 if (os_strcmp(buf, "PING") == 0)
5803 level = MSG_EXCESSIVE;
5804 wpa_dbg(wpa_s, level, "Control interface command '%s'", buf);
5807 reply = os_malloc(reply_size);
5808 if (reply == NULL) {
5813 os_memcpy(reply, "OK\n", 3);
5816 if (os_strcmp(buf, "PING") == 0) {
5817 os_memcpy(reply, "PONG\n", 5);
5819 } else if (os_strcmp(buf, "IFNAME") == 0) {
5820 reply_len = os_strlen(wpa_s->ifname);
5821 os_memcpy(reply, wpa_s->ifname, reply_len);
5822 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
5823 if (wpa_debug_reopen_file() < 0)
5825 } else if (os_strncmp(buf, "NOTE ", 5) == 0) {
5826 wpa_printf(MSG_INFO, "NOTE: %s", buf + 5);
5827 } else if (os_strcmp(buf, "MIB") == 0) {
5828 reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size);
5829 if (reply_len >= 0) {
5831 res = eapol_sm_get_mib(wpa_s->eapol, reply + reply_len,
5832 reply_size - reply_len);
5838 } else if (os_strncmp(buf, "STATUS", 6) == 0) {
5839 reply_len = wpa_supplicant_ctrl_iface_status(
5840 wpa_s, buf + 6, reply, reply_size);
5841 } else if (os_strcmp(buf, "PMKSA") == 0) {
5842 reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, reply,
5844 } else if (os_strncmp(buf, "SET ", 4) == 0) {
5845 if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4))
5847 } else if (os_strncmp(buf, "GET ", 4) == 0) {
5848 reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4,
5850 } else if (os_strcmp(buf, "LOGON") == 0) {
5851 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
5852 } else if (os_strcmp(buf, "LOGOFF") == 0) {
5853 eapol_sm_notify_logoff(wpa_s->eapol, TRUE);
5854 } else if (os_strcmp(buf, "REASSOCIATE") == 0) {
5855 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
5858 wpas_request_connection(wpa_s);
5859 } else if (os_strcmp(buf, "RECONNECT") == 0) {
5860 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
5862 else if (wpa_s->disconnected)
5863 wpas_request_connection(wpa_s);
5864 #ifdef IEEE8021X_EAPOL
5865 } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) {
5866 if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8))
5868 #endif /* IEEE8021X_EAPOL */
5869 #ifdef CONFIG_PEERKEY
5870 } else if (os_strncmp(buf, "STKSTART ", 9) == 0) {
5871 if (wpa_supplicant_ctrl_iface_stkstart(wpa_s, buf + 9))
5873 #endif /* CONFIG_PEERKEY */
5874 #ifdef CONFIG_IEEE80211R
5875 } else if (os_strncmp(buf, "FT_DS ", 6) == 0) {
5876 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6))
5878 #endif /* CONFIG_IEEE80211R */
5880 } else if (os_strcmp(buf, "WPS_PBC") == 0) {
5881 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL);
5883 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
5887 } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) {
5888 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8);
5890 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
5894 } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {
5895 reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8,
5898 } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) {
5899 reply_len = wpa_supplicant_ctrl_iface_wps_check_pin(
5900 wpa_s, buf + 14, reply, reply_size);
5901 } else if (os_strcmp(buf, "WPS_CANCEL") == 0) {
5902 if (wpas_wps_cancel(wpa_s))
5904 #ifdef CONFIG_WPS_NFC
5905 } else if (os_strcmp(buf, "WPS_NFC") == 0) {
5906 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, NULL))
5908 } else if (os_strncmp(buf, "WPS_NFC ", 8) == 0) {
5909 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, buf + 8))
5911 } else if (os_strncmp(buf, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
5912 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_config_token(
5913 wpa_s, buf + 21, reply, reply_size);
5914 } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) {
5915 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_token(
5916 wpa_s, buf + 14, reply, reply_size);
5917 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) {
5918 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s,
5921 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
5922 reply_len = wpas_ctrl_nfc_get_handover_req(
5923 wpa_s, buf + 21, reply, reply_size);
5924 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
5925 reply_len = wpas_ctrl_nfc_get_handover_sel(
5926 wpa_s, buf + 21, reply, reply_size);
5927 } else if (os_strncmp(buf, "NFC_RX_HANDOVER_REQ ", 20) == 0) {
5928 reply_len = wpas_ctrl_nfc_rx_handover_req(
5929 wpa_s, buf + 20, reply, reply_size);
5930 } else if (os_strncmp(buf, "NFC_RX_HANDOVER_SEL ", 20) == 0) {
5931 if (wpas_ctrl_nfc_rx_handover_sel(wpa_s, buf + 20))
5933 } else if (os_strncmp(buf, "NFC_REPORT_HANDOVER ", 20) == 0) {
5934 if (wpas_ctrl_nfc_report_handover(wpa_s, buf + 20))
5936 #endif /* CONFIG_WPS_NFC */
5937 } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) {
5938 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8))
5941 } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) {
5942 reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin(
5943 wpa_s, buf + 11, reply, reply_size);
5944 #endif /* CONFIG_AP */
5945 #ifdef CONFIG_WPS_ER
5946 } else if (os_strcmp(buf, "WPS_ER_START") == 0) {
5947 if (wpas_wps_er_start(wpa_s, NULL))
5949 } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) {
5950 if (wpas_wps_er_start(wpa_s, buf + 13))
5952 } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) {
5953 if (wpas_wps_er_stop(wpa_s))
5955 } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) {
5956 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11))
5958 } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) {
5959 int ret = wpas_wps_er_pbc(wpa_s, buf + 11);
5961 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
5963 } else if (ret == -3) {
5964 os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18);
5966 } else if (ret == -4) {
5967 os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20);
5971 } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) {
5972 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13))
5974 } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) {
5975 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s,
5978 } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) {
5979 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14))
5981 #ifdef CONFIG_WPS_NFC
5982 } else if (os_strncmp(buf, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
5983 reply_len = wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
5984 wpa_s, buf + 24, reply, reply_size);
5985 #endif /* CONFIG_WPS_NFC */
5986 #endif /* CONFIG_WPS_ER */
5987 #endif /* CONFIG_WPS */
5988 #ifdef CONFIG_IBSS_RSN
5989 } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) {
5990 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9))
5992 #endif /* CONFIG_IBSS_RSN */
5994 } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) {
5995 if (p2p_ctrl_find(wpa_s, buf + 9))
5997 } else if (os_strcmp(buf, "P2P_FIND") == 0) {
5998 if (p2p_ctrl_find(wpa_s, ""))
6000 } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) {
6001 wpas_p2p_stop_find(wpa_s);
6002 } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) {
6003 reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply,
6005 } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) {
6006 if (p2p_ctrl_listen(wpa_s, buf + 11))
6008 } else if (os_strcmp(buf, "P2P_LISTEN") == 0) {
6009 if (p2p_ctrl_listen(wpa_s, ""))
6011 } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) {
6012 if (wpas_p2p_group_remove(wpa_s, buf + 17))
6014 } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) {
6015 if (wpas_p2p_group_add(wpa_s, 0, 0, 0, 0))
6017 } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) {
6018 if (p2p_ctrl_group_add(wpa_s, buf + 14))
6020 } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) {
6021 if (p2p_ctrl_prov_disc(wpa_s, buf + 14))
6023 } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) {
6024 reply_len = p2p_get_passphrase(wpa_s, reply, reply_size);
6025 } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) {
6026 reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply,
6028 } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
6029 if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0)
6031 } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) {
6032 if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0)
6034 } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) {
6035 wpas_p2p_sd_service_update(wpa_s);
6036 } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
6037 if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0)
6039 } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) {
6040 wpas_p2p_service_flush(wpa_s);
6041 } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) {
6042 if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0)
6044 } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) {
6045 if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0)
6047 } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) {
6048 if (p2p_ctrl_reject(wpa_s, buf + 11) < 0)
6050 } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) {
6051 if (p2p_ctrl_invite(wpa_s, buf + 11) < 0)
6053 } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) {
6054 reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply,
6056 } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) {
6057 if (p2p_ctrl_set(wpa_s, buf + 8) < 0)
6059 } else if (os_strcmp(buf, "P2P_FLUSH") == 0) {
6060 p2p_ctrl_flush(wpa_s);
6061 } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) {
6062 if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0)
6064 } else if (os_strcmp(buf, "P2P_CANCEL") == 0) {
6065 if (wpas_p2p_cancel(wpa_s))
6067 } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) {
6068 if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0)
6070 } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) {
6071 if (p2p_ctrl_presence_req(wpa_s, "") < 0)
6073 } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) {
6074 if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0)
6076 } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) {
6077 if (p2p_ctrl_ext_listen(wpa_s, "") < 0)
6079 } else if (os_strncmp(buf, "P2P_REMOVE_CLIENT ", 18) == 0) {
6080 if (p2p_ctrl_remove_client(wpa_s, buf + 18) < 0)
6082 #endif /* CONFIG_P2P */
6083 #ifdef CONFIG_WIFI_DISPLAY
6084 } else if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0) {
6085 if (wifi_display_subelem_set(wpa_s->global, buf + 16) < 0)
6087 } else if (os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) {
6088 reply_len = wifi_display_subelem_get(wpa_s->global, buf + 16,
6090 #endif /* CONFIG_WIFI_DISPLAY */
6091 #ifdef CONFIG_INTERWORKING
6092 } else if (os_strcmp(buf, "FETCH_ANQP") == 0) {
6093 if (interworking_fetch_anqp(wpa_s) < 0)
6095 } else if (os_strcmp(buf, "STOP_FETCH_ANQP") == 0) {
6096 interworking_stop_fetch_anqp(wpa_s);
6097 } else if (os_strcmp(buf, "INTERWORKING_SELECT") == 0) {
6098 if (ctrl_interworking_select(wpa_s, NULL) < 0)
6100 } else if (os_strncmp(buf, "INTERWORKING_SELECT ", 20) == 0) {
6101 if (ctrl_interworking_select(wpa_s, buf + 20) < 0)
6103 } else if (os_strncmp(buf, "INTERWORKING_CONNECT ", 21) == 0) {
6104 if (ctrl_interworking_connect(wpa_s, buf + 21) < 0)
6106 } else if (os_strncmp(buf, "ANQP_GET ", 9) == 0) {
6107 if (get_anqp(wpa_s, buf + 9) < 0)
6109 } else if (os_strncmp(buf, "GAS_REQUEST ", 12) == 0) {
6110 if (gas_request(wpa_s, buf + 12) < 0)
6112 } else if (os_strncmp(buf, "GAS_RESPONSE_GET ", 17) == 0) {
6113 reply_len = gas_response_get(wpa_s, buf + 17, reply,
6115 #endif /* CONFIG_INTERWORKING */
6117 } else if (os_strncmp(buf, "HS20_ANQP_GET ", 14) == 0) {
6118 if (get_hs20_anqp(wpa_s, buf + 14) < 0)
6120 } else if (os_strncmp(buf, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
6121 if (hs20_get_nai_home_realm_list(wpa_s, buf + 29) < 0)
6123 #endif /* CONFIG_HS20 */
6124 } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0)
6126 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
6127 wpa_s, buf + os_strlen(WPA_CTRL_RSP)))
6131 * Notify response from timeout to allow the control
6132 * interface response to be sent first.
6134 eloop_register_timeout(0, 0, wpas_ctrl_eapol_response,
6137 } else if (os_strcmp(buf, "RECONFIGURE") == 0) {
6138 if (wpa_supplicant_reload_configuration(wpa_s))
6140 } else if (os_strcmp(buf, "TERMINATE") == 0) {
6141 wpa_supplicant_terminate_proc(wpa_s->global);
6142 } else if (os_strncmp(buf, "BSSID ", 6) == 0) {
6143 if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6))
6145 } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) {
6146 reply_len = wpa_supplicant_ctrl_iface_blacklist(
6147 wpa_s, buf + 9, reply, reply_size);
6148 } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) {
6149 reply_len = wpa_supplicant_ctrl_iface_log_level(
6150 wpa_s, buf + 9, reply, reply_size);
6151 } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) {
6152 reply_len = wpa_supplicant_ctrl_iface_list_networks(
6153 wpa_s, reply, reply_size);
6154 } else if (os_strcmp(buf, "DISCONNECT") == 0) {
6156 wpa_s->sme.prev_bssid_set = 0;
6157 #endif /* CONFIG_SME */
6158 wpa_s->reassociate = 0;
6159 wpa_s->disconnected = 1;
6160 wpa_supplicant_cancel_sched_scan(wpa_s);
6161 wpa_supplicant_cancel_scan(wpa_s);
6162 wpa_supplicant_deauthenticate(wpa_s,
6163 WLAN_REASON_DEAUTH_LEAVING);
6164 } else if (os_strcmp(buf, "SCAN") == 0) {
6165 wpas_ctrl_scan(wpa_s, NULL, reply, reply_size, &reply_len);
6166 } else if (os_strncmp(buf, "SCAN ", 5) == 0) {
6167 wpas_ctrl_scan(wpa_s, buf + 5, reply, reply_size, &reply_len);
6168 } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) {
6169 reply_len = wpa_supplicant_ctrl_iface_scan_results(
6170 wpa_s, reply, reply_size);
6171 } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) {
6172 if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15))
6174 } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) {
6175 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15))
6177 } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) {
6178 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16))
6180 } else if (os_strcmp(buf, "ADD_NETWORK") == 0) {
6181 reply_len = wpa_supplicant_ctrl_iface_add_network(
6182 wpa_s, reply, reply_size);
6183 } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) {
6184 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15))
6186 } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
6187 if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12))
6189 } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) {
6190 reply_len = wpa_supplicant_ctrl_iface_get_network(
6191 wpa_s, buf + 12, reply, reply_size);
6192 } else if (os_strcmp(buf, "LIST_CREDS") == 0) {
6193 reply_len = wpa_supplicant_ctrl_iface_list_creds(
6194 wpa_s, reply, reply_size);
6195 } else if (os_strcmp(buf, "ADD_CRED") == 0) {
6196 reply_len = wpa_supplicant_ctrl_iface_add_cred(
6197 wpa_s, reply, reply_size);
6198 } else if (os_strncmp(buf, "REMOVE_CRED ", 12) == 0) {
6199 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s, buf + 12))
6201 } else if (os_strncmp(buf, "SET_CRED ", 9) == 0) {
6202 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s, buf + 9))
6204 #ifndef CONFIG_NO_CONFIG_WRITE
6205 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
6206 if (wpa_supplicant_ctrl_iface_save_config(wpa_s))
6208 #endif /* CONFIG_NO_CONFIG_WRITE */
6209 } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
6210 reply_len = wpa_supplicant_ctrl_iface_get_capability(
6211 wpa_s, buf + 15, reply, reply_size);
6212 } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) {
6213 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8))
6215 } else if (os_strncmp(buf, "SCAN_INTERVAL ", 14) == 0) {
6216 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s, buf + 14))
6218 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
6219 reply_len = wpa_supplicant_global_iface_list(
6220 wpa_s->global, reply, reply_size);
6221 } else if (os_strcmp(buf, "INTERFACES") == 0) {
6222 reply_len = wpa_supplicant_global_iface_interfaces(
6223 wpa_s->global, reply, reply_size);
6224 } else if (os_strncmp(buf, "BSS ", 4) == 0) {
6225 reply_len = wpa_supplicant_ctrl_iface_bss(
6226 wpa_s, buf + 4, reply, reply_size);
6228 } else if (os_strcmp(buf, "STA-FIRST") == 0) {
6229 reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size);
6230 } else if (os_strncmp(buf, "STA ", 4) == 0) {
6231 reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply,
6233 } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) {
6234 reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply,
6236 } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) {
6237 if (ap_ctrl_iface_sta_deauthenticate(wpa_s, buf + 15))
6239 } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) {
6240 if (ap_ctrl_iface_sta_disassociate(wpa_s, buf + 13))
6242 } else if (os_strncmp(buf, "CHAN_SWITCH ", 12) == 0) {
6243 if (ap_ctrl_iface_chanswitch(wpa_s, buf + 12))
6245 #endif /* CONFIG_AP */
6246 } else if (os_strcmp(buf, "SUSPEND") == 0) {
6247 wpas_notify_suspend(wpa_s->global);
6248 } else if (os_strcmp(buf, "RESUME") == 0) {
6249 wpas_notify_resume(wpa_s->global);
6250 } else if (os_strcmp(buf, "DROP_SA") == 0) {
6251 wpa_supplicant_ctrl_iface_drop_sa(wpa_s);
6252 } else if (os_strncmp(buf, "ROAM ", 5) == 0) {
6253 if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5))
6255 } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) {
6256 if (wpa_supplicant_ctrl_iface_sta_autoconnect(wpa_s, buf + 16))
6258 } else if (os_strncmp(buf, "BSS_EXPIRE_AGE ", 15) == 0) {
6259 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s, buf + 15))
6261 } else if (os_strncmp(buf, "BSS_EXPIRE_COUNT ", 17) == 0) {
6262 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s,
6265 } else if (os_strncmp(buf, "BSS_FLUSH ", 10) == 0) {
6266 if (wpa_supplicant_ctrl_iface_bss_flush(wpa_s, buf + 10))
6269 } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) {
6270 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14))
6272 } else if (os_strncmp(buf, "TDLS_SETUP ", 11) == 0) {
6273 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s, buf + 11))
6275 } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) {
6276 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14))
6278 #endif /* CONFIG_TDLS */
6279 } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) {
6280 reply_len = wpa_supplicant_signal_poll(wpa_s, reply,
6282 } else if (os_strncmp(buf, "PKTCNT_POLL", 11) == 0) {
6283 reply_len = wpa_supplicant_pktcnt_poll(wpa_s, reply,
6285 #ifdef CONFIG_AUTOSCAN
6286 } else if (os_strncmp(buf, "AUTOSCAN ", 9) == 0) {
6287 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s, buf + 9))
6289 #endif /* CONFIG_AUTOSCAN */
6291 } else if (os_strncmp(buf, "DRIVER ", 7) == 0) {
6292 reply_len = wpa_supplicant_driver_cmd(wpa_s, buf + 7, reply,
6294 #endif /* ANDROID */
6295 } else if (os_strcmp(buf, "REAUTHENTICATE") == 0) {
6296 pmksa_cache_clear_current(wpa_s->wpa);
6297 eapol_sm_request_reauth(wpa_s->eapol);
6299 } else if (os_strncmp(buf, "WNM_SLEEP ", 10) == 0) {
6300 if (wpas_ctrl_iface_wnm_sleep(wpa_s, buf + 10))
6302 } else if (os_strncmp(buf, "WNM_BSS_QUERY ", 10) == 0) {
6303 if (wpas_ctrl_iface_wnm_bss_query(wpa_s, buf + 10))
6305 #endif /* CONFIG_WNM */
6306 } else if (os_strcmp(buf, "FLUSH") == 0) {
6307 wpa_supplicant_ctrl_iface_flush(wpa_s);
6308 } else if (os_strncmp(buf, "RADIO_WORK ", 11) == 0) {
6309 reply_len = wpas_ctrl_radio_work(wpa_s, buf + 11, reply,
6312 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
6316 if (reply_len < 0) {
6317 os_memcpy(reply, "FAIL\n", 5);
6321 *resp_len = reply_len;
6326 static int wpa_supplicant_global_iface_add(struct wpa_global *global,
6329 struct wpa_interface iface;
6333 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
6334 * TAB<bridge_ifname>
6336 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd);
6338 os_memset(&iface, 0, sizeof(iface));
6341 iface.ifname = pos = cmd;
6342 pos = os_strchr(pos, '\t');
6345 if (iface.ifname[0] == '\0')
6350 iface.confname = pos;
6351 pos = os_strchr(pos, '\t');
6354 if (iface.confname[0] == '\0')
6355 iface.confname = NULL;
6360 pos = os_strchr(pos, '\t');
6363 if (iface.driver[0] == '\0')
6364 iface.driver = NULL;
6368 iface.ctrl_interface = pos;
6369 pos = os_strchr(pos, '\t');
6372 if (iface.ctrl_interface[0] == '\0')
6373 iface.ctrl_interface = NULL;
6377 iface.driver_param = pos;
6378 pos = os_strchr(pos, '\t');
6381 if (iface.driver_param[0] == '\0')
6382 iface.driver_param = NULL;
6386 iface.bridge_ifname = pos;
6387 pos = os_strchr(pos, '\t');
6390 if (iface.bridge_ifname[0] == '\0')
6391 iface.bridge_ifname = NULL;
6396 if (wpa_supplicant_get_iface(global, iface.ifname))
6399 return wpa_supplicant_add_iface(global, &iface) ? 0 : -1;
6403 static int wpa_supplicant_global_iface_remove(struct wpa_global *global,
6406 struct wpa_supplicant *wpa_s;
6408 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd);
6410 wpa_s = wpa_supplicant_get_iface(global, cmd);
6413 return wpa_supplicant_remove_iface(global, wpa_s, 0);
6417 static void wpa_free_iface_info(struct wpa_interface_info *iface)
6419 struct wpa_interface_info *prev;
6423 iface = iface->next;
6425 os_free(prev->ifname);
6426 os_free(prev->desc);
6432 static int wpa_supplicant_global_iface_list(struct wpa_global *global,
6436 struct wpa_interface_info *iface = NULL, *last = NULL, *tmp;
6439 for (i = 0; wpa_drivers[i]; i++) {
6440 struct wpa_driver_ops *drv = wpa_drivers[i];
6441 if (drv->get_interfaces == NULL)
6443 tmp = drv->get_interfaces(global->drv_priv[i]);
6457 for (tmp = iface; tmp; tmp = tmp->next) {
6458 res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n",
6459 tmp->drv_name, tmp->ifname,
6460 tmp->desc ? tmp->desc : "");
6461 if (res < 0 || res >= end - pos) {
6468 wpa_free_iface_info(iface);
6474 static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
6479 struct wpa_supplicant *wpa_s;
6481 wpa_s = global->ifaces;
6486 res = os_snprintf(pos, end - pos, "%s\n", wpa_s->ifname);
6487 if (res < 0 || res >= end - pos) {
6492 wpa_s = wpa_s->next;
6498 static char * wpas_global_ctrl_iface_ifname(struct wpa_global *global,
6500 char *cmd, size_t *resp_len)
6502 struct wpa_supplicant *wpa_s;
6504 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
6505 if (os_strcmp(ifname, wpa_s->ifname) == 0)
6509 if (wpa_s == NULL) {
6510 char *resp = os_strdup("FAIL-NO-IFNAME-MATCH\n");
6512 *resp_len = os_strlen(resp);
6518 return wpa_supplicant_ctrl_iface_process(wpa_s, cmd, resp_len);
6522 static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global *global,
6523 char *buf, size_t *resp_len)
6526 static const char * cmd[] = {
6533 "P2P_GET_PASSPHRASE",
6534 "P2P_SERVICE_UPDATE",
6535 "P2P_SERVICE_FLUSH",
6542 static const char * prefix[] = {
6545 #endif /* ANDROID */
6552 "P2P_GROUP_REMOVE ",
6555 "P2P_SERV_DISC_REQ ",
6556 "P2P_SERV_DISC_CANCEL_REQ ",
6557 "P2P_SERV_DISC_RESP ",
6558 "P2P_SERV_DISC_EXTERNAL ",
6566 "P2P_PRESENCE_REQ ",
6568 "P2P_REMOVE_CLIENT ",
6574 if (global->p2p_init_wpa_s == NULL)
6577 for (i = 0; !found && cmd[i]; i++) {
6578 if (os_strcmp(buf, cmd[i]) == 0)
6582 for (i = 0; !found && prefix[i]; i++) {
6583 if (os_strncmp(buf, prefix[i], os_strlen(prefix[i])) == 0)
6588 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
6590 #endif /* CONFIG_P2P */
6595 static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global *global,
6596 char *buf, size_t *resp_len)
6598 #ifdef CONFIG_WIFI_DISPLAY
6599 if (global->p2p_init_wpa_s == NULL)
6601 if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0 ||
6602 os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0)
6603 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
6605 #endif /* CONFIG_WIFI_DISPLAY */
6610 static char * wpas_global_ctrl_iface_redir(struct wpa_global *global,
6611 char *buf, size_t *resp_len)
6615 ret = wpas_global_ctrl_iface_redir_p2p(global, buf, resp_len);
6619 ret = wpas_global_ctrl_iface_redir_wfd(global, buf, resp_len);
6627 static int wpas_global_ctrl_iface_set(struct wpa_global *global, char *cmd)
6631 value = os_strchr(cmd, ' ');
6636 wpa_printf(MSG_DEBUG, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd, value);
6638 #ifdef CONFIG_WIFI_DISPLAY
6639 if (os_strcasecmp(cmd, "wifi_display") == 0) {
6640 wifi_display_enable(global, !!atoi(value));
6643 #endif /* CONFIG_WIFI_DISPLAY */
6649 #ifndef CONFIG_NO_CONFIG_WRITE
6650 static int wpas_global_ctrl_iface_save_config(struct wpa_global *global)
6653 struct wpa_supplicant *wpa_s;
6655 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
6656 if (!wpa_s->conf->update_config) {
6657 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
6661 if (wpa_config_write(wpa_s->confname, wpa_s->conf)) {
6662 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
6665 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
6671 #endif /* CONFIG_NO_CONFIG_WRITE */
6674 static int wpas_global_ctrl_iface_status(struct wpa_global *global,
6675 char *buf, size_t buflen)
6679 struct wpa_supplicant *wpa_s;
6685 if (global->p2p && !global->p2p_disabled) {
6686 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
6689 MAC2STR(global->p2p_dev_addr),
6690 p2p_get_state_txt(global->p2p));
6691 if (ret < 0 || ret >= end - pos)
6694 } else if (global->p2p) {
6695 ret = os_snprintf(pos, end - pos, "p2p_state=DISABLED\n");
6696 if (ret < 0 || ret >= end - pos)
6700 #endif /* CONFIG_P2P */
6702 #ifdef CONFIG_WIFI_DISPLAY
6703 ret = os_snprintf(pos, end - pos, "wifi_display=%d\n",
6704 !!global->wifi_display);
6705 if (ret < 0 || ret >= end - pos)
6708 #endif /* CONFIG_WIFI_DISPLAY */
6710 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
6711 ret = os_snprintf(pos, end - pos, "ifname=%s\n"
6712 "address=" MACSTR "\n",
6713 wpa_s->ifname, MAC2STR(wpa_s->own_addr));
6714 if (ret < 0 || ret >= end - pos)
6723 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
6724 char *buf, size_t *resp_len)
6727 const int reply_size = 2048;
6729 int level = MSG_DEBUG;
6731 if (os_strncmp(buf, "IFNAME=", 7) == 0) {
6732 char *pos = os_strchr(buf + 7, ' ');
6735 return wpas_global_ctrl_iface_ifname(global,
6741 reply = wpas_global_ctrl_iface_redir(global, buf, resp_len);
6745 if (os_strcmp(buf, "PING") == 0)
6746 level = MSG_EXCESSIVE;
6747 wpa_hexdump_ascii(level, "RX global ctrl_iface",
6748 (const u8 *) buf, os_strlen(buf));
6750 reply = os_malloc(reply_size);
6751 if (reply == NULL) {
6756 os_memcpy(reply, "OK\n", 3);
6759 if (os_strcmp(buf, "PING") == 0) {
6760 os_memcpy(reply, "PONG\n", 5);
6762 } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) {
6763 if (wpa_supplicant_global_iface_add(global, buf + 14))
6765 } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) {
6766 if (wpa_supplicant_global_iface_remove(global, buf + 17))
6768 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
6769 reply_len = wpa_supplicant_global_iface_list(
6770 global, reply, reply_size);
6771 } else if (os_strcmp(buf, "INTERFACES") == 0) {
6772 reply_len = wpa_supplicant_global_iface_interfaces(
6773 global, reply, reply_size);
6774 } else if (os_strcmp(buf, "TERMINATE") == 0) {
6775 wpa_supplicant_terminate_proc(global);
6776 } else if (os_strcmp(buf, "SUSPEND") == 0) {
6777 wpas_notify_suspend(global);
6778 } else if (os_strcmp(buf, "RESUME") == 0) {
6779 wpas_notify_resume(global);
6780 } else if (os_strncmp(buf, "SET ", 4) == 0) {
6781 if (wpas_global_ctrl_iface_set(global, buf + 4))
6783 #ifndef CONFIG_NO_CONFIG_WRITE
6784 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
6785 if (wpas_global_ctrl_iface_save_config(global))
6787 #endif /* CONFIG_NO_CONFIG_WRITE */
6788 } else if (os_strcmp(buf, "STATUS") == 0) {
6789 reply_len = wpas_global_ctrl_iface_status(global, reply,
6792 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
6796 if (reply_len < 0) {
6797 os_memcpy(reply, "FAIL\n", 5);
6801 *resp_len = reply_len;