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 #endif /* CONFIG_WPS_TESTING */
368 } else if (os_strcasecmp(cmd, "ampdu") == 0) {
369 if (wpa_drv_ampdu(wpa_s, atoi(value)) < 0)
372 #ifdef CONFIG_TDLS_TESTING
373 } else if (os_strcasecmp(cmd, "tdls_testing") == 0) {
374 extern unsigned int tdls_testing;
375 tdls_testing = strtol(value, NULL, 0);
376 wpa_printf(MSG_DEBUG, "TDLS: tdls_testing=0x%x", tdls_testing);
377 #endif /* CONFIG_TDLS_TESTING */
378 } else if (os_strcasecmp(cmd, "tdls_disabled") == 0) {
379 int disabled = atoi(value);
380 wpa_printf(MSG_DEBUG, "TDLS: tdls_disabled=%d", disabled);
382 if (wpa_drv_tdls_oper(wpa_s, TDLS_DISABLE, NULL) < 0)
384 } else if (wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL) < 0)
386 wpa_tdls_enable(wpa_s->wpa, !disabled);
387 #endif /* CONFIG_TDLS */
388 } else if (os_strcasecmp(cmd, "pno") == 0) {
390 ret = pno_start(wpa_s);
392 ret = pno_stop(wpa_s);
393 } else if (os_strcasecmp(cmd, "radio_disabled") == 0) {
394 int disabled = atoi(value);
395 if (wpa_drv_radio_disable(wpa_s, disabled) < 0)
398 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
399 } else if (os_strcasecmp(cmd, "uapsd") == 0) {
400 if (os_strcmp(value, "disable") == 0)
401 wpa_s->set_sta_uapsd = 0;
405 /* format: BE,BK,VI,VO;max SP Length */
407 pos = os_strchr(value, ',');
412 pos = os_strchr(pos, ',');
417 pos = os_strchr(pos, ',');
422 /* ignore max SP Length for now */
424 wpa_s->set_sta_uapsd = 1;
425 wpa_s->sta_uapsd = 0;
427 wpa_s->sta_uapsd |= BIT(0);
429 wpa_s->sta_uapsd |= BIT(1);
431 wpa_s->sta_uapsd |= BIT(2);
433 wpa_s->sta_uapsd |= BIT(3);
435 } else if (os_strcasecmp(cmd, "ps") == 0) {
436 ret = wpa_drv_set_p2p_powersave(wpa_s, atoi(value), -1, -1);
437 #ifdef CONFIG_WIFI_DISPLAY
438 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
439 wifi_display_enable(wpa_s->global, !!atoi(value));
440 #endif /* CONFIG_WIFI_DISPLAY */
441 } else if (os_strcasecmp(cmd, "bssid_filter") == 0) {
442 ret = set_bssid_filter(wpa_s, value);
443 } else if (os_strcasecmp(cmd, "disallow_aps") == 0) {
444 ret = set_disallow_aps(wpa_s, value);
445 } else if (os_strcasecmp(cmd, "no_keep_alive") == 0) {
446 wpa_s->no_keep_alive = !!atoi(value);
449 ret = wpa_config_process_global(wpa_s->conf, cmd, -1);
451 wpa_supplicant_update_config(wpa_s);
458 static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s,
459 char *cmd, char *buf, size_t buflen)
463 wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd);
465 if (os_strcmp(cmd, "version") == 0) {
466 res = os_snprintf(buf, buflen, "%s", VERSION_STR);
467 } else if (os_strcasecmp(cmd, "country") == 0) {
468 if (wpa_s->conf->country[0] && wpa_s->conf->country[1])
469 res = os_snprintf(buf, buflen, "%c%c",
470 wpa_s->conf->country[0],
471 wpa_s->conf->country[1]);
472 #ifdef CONFIG_WIFI_DISPLAY
473 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
474 res = os_snprintf(buf, buflen, "%d",
475 wpa_s->global->wifi_display);
476 if (res < 0 || (unsigned int) res >= buflen)
479 #endif /* CONFIG_WIFI_DISPLAY */
480 #ifdef CONFIG_TESTING_GET_GTK
481 } else if (os_strcmp(cmd, "gtk") == 0) {
482 if (wpa_s->last_gtk_len == 0)
484 res = wpa_snprintf_hex(buf, buflen, wpa_s->last_gtk,
485 wpa_s->last_gtk_len);
487 #endif /* CONFIG_TESTING_GET_GTK */
490 if (res < 0 || (unsigned int) res >= buflen)
496 #ifdef IEEE8021X_EAPOL
497 static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s,
501 struct wpa_ssid *ssid = wpa_s->current_ssid;
503 if (hwaddr_aton(addr, bssid)) {
504 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address "
509 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid));
510 rsn_preauth_deinit(wpa_s->wpa);
511 if (rsn_preauth_init(wpa_s->wpa, bssid, ssid ? &ssid->eap : NULL))
516 #endif /* IEEE8021X_EAPOL */
519 #ifdef CONFIG_PEERKEY
520 /* MLME-STKSTART.request(peer) */
521 static int wpa_supplicant_ctrl_iface_stkstart(
522 struct wpa_supplicant *wpa_s, char *addr)
526 if (hwaddr_aton(addr, peer)) {
527 wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART: invalid "
528 "address '%s'", addr);
532 wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART " MACSTR,
535 return wpa_sm_stkstart(wpa_s->wpa, peer);
537 #endif /* CONFIG_PEERKEY */
542 static int wpa_supplicant_ctrl_iface_tdls_discover(
543 struct wpa_supplicant *wpa_s, char *addr)
548 if (hwaddr_aton(addr, peer)) {
549 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER: invalid "
550 "address '%s'", addr);
554 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER " MACSTR,
557 if (wpa_tdls_is_external_setup(wpa_s->wpa))
558 ret = wpa_tdls_send_discovery_request(wpa_s->wpa, peer);
560 ret = wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer);
566 static int wpa_supplicant_ctrl_iface_tdls_setup(
567 struct wpa_supplicant *wpa_s, char *addr)
572 if (hwaddr_aton(addr, peer)) {
573 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP: invalid "
574 "address '%s'", addr);
578 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP " MACSTR,
581 if ((wpa_s->conf->tdls_external_control) &&
582 wpa_tdls_is_external_setup(wpa_s->wpa))
583 return wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
585 wpa_tdls_remove(wpa_s->wpa, peer);
587 if (wpa_tdls_is_external_setup(wpa_s->wpa))
588 ret = wpa_tdls_start(wpa_s->wpa, peer);
590 ret = wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
596 static int wpa_supplicant_ctrl_iface_tdls_teardown(
597 struct wpa_supplicant *wpa_s, char *addr)
602 if (hwaddr_aton(addr, peer)) {
603 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN: invalid "
604 "address '%s'", addr);
608 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN " MACSTR,
611 if ((wpa_s->conf->tdls_external_control) &&
612 wpa_tdls_is_external_setup(wpa_s->wpa))
613 return wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
615 if (wpa_tdls_is_external_setup(wpa_s->wpa))
616 ret = wpa_tdls_teardown_link(
618 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED);
620 ret = wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
625 #endif /* CONFIG_TDLS */
628 #ifdef CONFIG_IEEE80211R
629 static int wpa_supplicant_ctrl_iface_ft_ds(
630 struct wpa_supplicant *wpa_s, char *addr)
632 u8 target_ap[ETH_ALEN];
636 if (hwaddr_aton(addr, target_ap)) {
637 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid "
638 "address '%s'", addr);
642 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap));
644 bss = wpa_bss_get_bssid(wpa_s, target_ap);
646 mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN);
650 return wpa_ft_start_over_ds(wpa_s->wpa, target_ap, mdie);
652 #endif /* CONFIG_IEEE80211R */
656 static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s,
659 u8 bssid[ETH_ALEN], *_bssid = bssid;
661 u8 p2p_dev_addr[ETH_ALEN];
662 #endif /* CONFIG_P2P */
664 u8 *_p2p_dev_addr = NULL;
665 #endif /* CONFIG_AP */
667 if (cmd == NULL || os_strcmp(cmd, "any") == 0) {
670 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
671 if (hwaddr_aton(cmd + 13, p2p_dev_addr)) {
672 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid "
673 "P2P Device Address '%s'",
677 _p2p_dev_addr = p2p_dev_addr;
678 #endif /* CONFIG_P2P */
679 } else if (hwaddr_aton(cmd, bssid)) {
680 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
687 return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid, _p2p_dev_addr);
688 #endif /* CONFIG_AP */
690 return wpas_wps_start_pbc(wpa_s, _bssid, 0);
694 static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s,
695 char *cmd, char *buf,
698 u8 bssid[ETH_ALEN], *_bssid = bssid;
702 pin = os_strchr(cmd, ' ');
706 if (os_strcmp(cmd, "any") == 0)
708 else if (os_strcmp(cmd, "get") == 0) {
709 ret = wps_generate_pin();
711 } else if (hwaddr_aton(cmd, bssid)) {
712 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
718 if (wpa_s->ap_iface) {
723 pos = os_strchr(pin, ' ');
730 return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin,
731 buf, buflen, timeout);
733 #endif /* CONFIG_AP */
736 ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0,
740 ret = os_snprintf(buf, buflen, "%s", pin);
741 if (ret < 0 || (size_t) ret >= buflen)
746 ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0, DEV_PW_DEFAULT);
751 /* Return the generated PIN */
752 ret = os_snprintf(buf, buflen, "%08d", ret);
753 if (ret < 0 || (size_t) ret >= buflen)
759 static int wpa_supplicant_ctrl_iface_wps_check_pin(
760 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
767 wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN",
768 (u8 *) cmd, os_strlen(cmd));
769 for (pos = cmd, len = 0; *pos != '\0'; pos++) {
770 if (*pos < '0' || *pos > '9')
774 wpa_printf(MSG_DEBUG, "WPS: Too long PIN");
778 if (len != 4 && len != 8) {
779 wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len);
785 unsigned int pin_val;
787 if (!wps_pin_valid(pin_val)) {
788 wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit");
789 ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n");
790 if (ret < 0 || (size_t) ret >= buflen)
796 ret = os_snprintf(buf, buflen, "%s", pin);
797 if (ret < 0 || (size_t) ret >= buflen)
804 #ifdef CONFIG_WPS_NFC
806 static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant *wpa_s,
809 u8 bssid[ETH_ALEN], *_bssid = bssid;
811 if (cmd == NULL || cmd[0] == '\0')
813 else if (hwaddr_aton(cmd, bssid))
816 return wpas_wps_start_nfc(wpa_s, _bssid, NULL, 0, 0, NULL, NULL, 0);
820 static int wpa_supplicant_ctrl_iface_wps_nfc_config_token(
821 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
828 pos = os_strchr(cmd, ' ');
831 if (os_strcmp(cmd, "WPS") == 0)
833 else if (os_strcmp(cmd, "NDEF") == 0)
838 buf = wpas_wps_nfc_config_token(wpa_s, ndef, pos);
842 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
853 static int wpa_supplicant_ctrl_iface_wps_nfc_token(
854 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
860 if (os_strcmp(cmd, "WPS") == 0)
862 else if (os_strcmp(cmd, "NDEF") == 0)
867 buf = wpas_wps_nfc_token(wpa_s, ndef);
871 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
882 static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
883 struct wpa_supplicant *wpa_s, char *pos)
889 len = os_strlen(pos);
894 buf = wpabuf_alloc(len);
897 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
902 ret = wpas_wps_nfc_tag_read(wpa_s, buf);
909 static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant *wpa_s,
910 char *reply, size_t max_len,
916 buf = wpas_wps_nfc_handover_req(wpa_s, ndef);
920 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
931 static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant *wpa_s,
932 char *cmd, char *reply,
938 pos = os_strchr(cmd, ' ');
943 if (os_strcmp(cmd, "WPS") == 0)
945 else if (os_strcmp(cmd, "NDEF") == 0)
950 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
953 return wpas_ctrl_nfc_get_handover_req_wps(
954 wpa_s, reply, max_len, ndef);
961 static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant *wpa_s,
962 char *reply, size_t max_len,
963 int ndef, int cr, char *uuid)
968 buf = wpas_wps_nfc_handover_sel(wpa_s, ndef, cr, uuid);
972 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
983 static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant *wpa_s,
984 char *cmd, char *reply,
990 pos = os_strchr(cmd, ' ');
995 if (os_strcmp(cmd, "WPS") == 0)
997 else if (os_strcmp(cmd, "NDEF") == 0)
1002 pos2 = os_strchr(pos, ' ');
1005 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
1006 return wpas_ctrl_nfc_get_handover_sel_wps(
1007 wpa_s, reply, max_len, ndef,
1008 os_strcmp(pos, "WPS-CR") == 0, pos2);
1015 static int wpas_ctrl_nfc_rx_handover_req(struct wpa_supplicant *wpa_s,
1016 char *cmd, char *reply,
1023 len = os_strlen(cmd);
1028 buf = wpabuf_alloc(len);
1031 if (hexstr2bin(cmd, wpabuf_put(buf, len), len) < 0) {
1036 ret = wpas_wps_nfc_rx_handover_req(wpa_s, buf);
1043 static int wpas_ctrl_nfc_rx_handover_sel(struct wpa_supplicant *wpa_s,
1050 len = os_strlen(cmd);
1055 buf = wpabuf_alloc(len);
1058 if (hexstr2bin(cmd, wpabuf_put(buf, len), len) < 0) {
1063 ret = wpas_wps_nfc_rx_handover_sel(wpa_s, buf);
1070 static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant *wpa_s,
1074 struct wpabuf *req, *sel;
1076 char *pos, *role, *type, *pos2;
1079 pos = os_strchr(role, ' ');
1085 pos = os_strchr(type, ' ');
1090 pos2 = os_strchr(pos, ' ');
1095 len = os_strlen(pos);
1100 req = wpabuf_alloc(len);
1103 if (hexstr2bin(pos, wpabuf_put(req, len), len) < 0) {
1108 len = os_strlen(pos2);
1115 sel = wpabuf_alloc(len);
1120 if (hexstr2bin(pos2, wpabuf_put(sel, len), len) < 0) {
1126 if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "WPS") == 0) {
1127 ret = wpas_wps_nfc_report_handover(wpa_s, req, sel);
1128 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "WPS") == 0)
1130 ret = wpas_ap_wps_nfc_report_handover(wpa_s, req, sel);
1132 ret = wpas_er_wps_nfc_report_handover(wpa_s, req, sel);
1134 wpa_printf(MSG_DEBUG, "NFC: Unsupported connection handover "
1135 "reported: role=%s type=%s", role, type);
1144 #endif /* CONFIG_WPS_NFC */
1147 static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s,
1156 struct wps_new_ap_settings ap;
1158 pin = os_strchr(cmd, ' ');
1163 if (hwaddr_aton(cmd, bssid)) {
1164 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
1169 new_ssid = os_strchr(pin, ' ');
1170 if (new_ssid == NULL)
1171 return wpas_wps_start_reg(wpa_s, bssid, pin, NULL);
1174 new_auth = os_strchr(new_ssid, ' ');
1175 if (new_auth == NULL)
1179 new_encr = os_strchr(new_auth, ' ');
1180 if (new_encr == NULL)
1184 new_key = os_strchr(new_encr, ' ');
1185 if (new_key == NULL)
1189 os_memset(&ap, 0, sizeof(ap));
1190 ap.ssid_hex = new_ssid;
1193 ap.key_hex = new_key;
1194 return wpas_wps_start_reg(wpa_s, bssid, pin, &ap);
1199 static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant *wpa_s,
1200 char *cmd, char *buf,
1205 const char *pin_txt;
1207 if (!wpa_s->ap_iface)
1210 pos = os_strchr(cmd, ' ');
1214 if (os_strcmp(cmd, "disable") == 0) {
1215 wpas_wps_ap_pin_disable(wpa_s);
1216 return os_snprintf(buf, buflen, "OK\n");
1219 if (os_strcmp(cmd, "random") == 0) {
1221 timeout = atoi(pos);
1222 pin_txt = wpas_wps_ap_pin_random(wpa_s, timeout);
1223 if (pin_txt == NULL)
1225 return os_snprintf(buf, buflen, "%s", pin_txt);
1228 if (os_strcmp(cmd, "get") == 0) {
1229 pin_txt = wpas_wps_ap_pin_get(wpa_s);
1230 if (pin_txt == NULL)
1232 return os_snprintf(buf, buflen, "%s", pin_txt);
1235 if (os_strcmp(cmd, "set") == 0) {
1240 pos = os_strchr(pos, ' ');
1243 timeout = atoi(pos);
1245 if (os_strlen(pin) > buflen)
1247 if (wpas_wps_ap_pin_set(wpa_s, pin, timeout) < 0)
1249 return os_snprintf(buf, buflen, "%s", pin);
1254 #endif /* CONFIG_AP */
1257 #ifdef CONFIG_WPS_ER
1258 static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant *wpa_s,
1261 char *uuid = cmd, *pin, *pos;
1262 u8 addr_buf[ETH_ALEN], *addr = NULL;
1263 pin = os_strchr(uuid, ' ');
1267 pos = os_strchr(pin, ' ');
1270 if (hwaddr_aton(pos, addr_buf) == 0)
1273 return wpas_wps_er_add_pin(wpa_s, addr, uuid, pin);
1277 static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant *wpa_s,
1280 char *uuid = cmd, *pin;
1281 pin = os_strchr(uuid, ' ');
1285 return wpas_wps_er_learn(wpa_s, uuid, pin);
1289 static int wpa_supplicant_ctrl_iface_wps_er_set_config(
1290 struct wpa_supplicant *wpa_s, char *cmd)
1292 char *uuid = cmd, *id;
1293 id = os_strchr(uuid, ' ');
1297 return wpas_wps_er_set_config(wpa_s, uuid, atoi(id));
1301 static int wpa_supplicant_ctrl_iface_wps_er_config(
1302 struct wpa_supplicant *wpa_s, char *cmd)
1309 struct wps_new_ap_settings ap;
1311 pin = os_strchr(cmd, ' ');
1316 new_ssid = os_strchr(pin, ' ');
1317 if (new_ssid == NULL)
1321 new_auth = os_strchr(new_ssid, ' ');
1322 if (new_auth == NULL)
1326 new_encr = os_strchr(new_auth, ' ');
1327 if (new_encr == NULL)
1331 new_key = os_strchr(new_encr, ' ');
1332 if (new_key == NULL)
1336 os_memset(&ap, 0, sizeof(ap));
1337 ap.ssid_hex = new_ssid;
1340 ap.key_hex = new_key;
1341 return wpas_wps_er_config(wpa_s, cmd, pin, &ap);
1345 #ifdef CONFIG_WPS_NFC
1346 static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
1347 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1354 uuid = os_strchr(cmd, ' ');
1359 if (os_strcmp(cmd, "WPS") == 0)
1361 else if (os_strcmp(cmd, "NDEF") == 0)
1366 buf = wpas_wps_er_nfc_config_token(wpa_s, ndef, uuid);
1370 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1372 reply[res++] = '\n';
1379 #endif /* CONFIG_WPS_NFC */
1380 #endif /* CONFIG_WPS_ER */
1382 #endif /* CONFIG_WPS */
1385 #ifdef CONFIG_IBSS_RSN
1386 static int wpa_supplicant_ctrl_iface_ibss_rsn(
1387 struct wpa_supplicant *wpa_s, char *addr)
1391 if (hwaddr_aton(addr, peer)) {
1392 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN: invalid "
1393 "address '%s'", addr);
1397 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN " MACSTR,
1400 return ibss_rsn_start(wpa_s->ibss_rsn, peer);
1402 #endif /* CONFIG_IBSS_RSN */
1405 static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s,
1408 #ifdef IEEE8021X_EAPOL
1411 struct wpa_ssid *ssid;
1413 pos = os_strchr(rsp, '-');
1418 pos = os_strchr(pos, ':');
1423 wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id);
1424 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
1425 (u8 *) pos, os_strlen(pos));
1427 ssid = wpa_config_get_network(wpa_s->conf, id);
1429 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
1434 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s, ssid, rsp,
1436 #else /* IEEE8021X_EAPOL */
1437 wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included");
1439 #endif /* IEEE8021X_EAPOL */
1443 static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
1445 char *buf, size_t buflen)
1447 char *pos, *end, tmp[30];
1448 int res, verbose, wps, ret;
1450 if (os_strcmp(params, "-DRIVER") == 0)
1451 return wpa_drv_status(wpa_s, buf, buflen);
1452 verbose = os_strcmp(params, "-VERBOSE") == 0;
1453 wps = os_strcmp(params, "-WPS") == 0;
1456 if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
1457 struct wpa_ssid *ssid = wpa_s->current_ssid;
1458 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
1459 MAC2STR(wpa_s->bssid));
1460 if (ret < 0 || ret >= end - pos)
1464 u8 *_ssid = ssid->ssid;
1465 size_t ssid_len = ssid->ssid_len;
1466 u8 ssid_buf[MAX_SSID_LEN];
1467 if (ssid_len == 0) {
1468 int _res = wpa_drv_get_ssid(wpa_s, ssid_buf);
1475 ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n",
1476 wpa_ssid_txt(_ssid, ssid_len),
1478 if (ret < 0 || ret >= end - pos)
1482 if (wps && ssid->passphrase &&
1483 wpa_key_mgmt_wpa_psk(ssid->key_mgmt) &&
1484 (ssid->mode == WPAS_MODE_AP ||
1485 ssid->mode == WPAS_MODE_P2P_GO)) {
1486 ret = os_snprintf(pos, end - pos,
1489 if (ret < 0 || ret >= end - pos)
1494 ret = os_snprintf(pos, end - pos,
1497 if (ret < 0 || ret >= end - pos)
1502 switch (ssid->mode) {
1503 case WPAS_MODE_INFRA:
1504 ret = os_snprintf(pos, end - pos,
1507 case WPAS_MODE_IBSS:
1508 ret = os_snprintf(pos, end - pos,
1512 ret = os_snprintf(pos, end - pos,
1515 case WPAS_MODE_P2P_GO:
1516 ret = os_snprintf(pos, end - pos,
1519 case WPAS_MODE_P2P_GROUP_FORMATION:
1520 ret = os_snprintf(pos, end - pos,
1521 "mode=P2P GO - group "
1528 if (ret < 0 || ret >= end - pos)
1534 if (wpa_s->ap_iface) {
1535 pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos,
1539 #endif /* CONFIG_AP */
1540 pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose);
1543 if (wpa_s->wpa_state >= WPA_ASSOCIATED &&
1546 #endif /* CONFIG_AP */
1547 wpa_s->sme.sae.state == SAE_ACCEPTED) {
1548 ret = os_snprintf(pos, end - pos, "sae_group=%d\n",
1549 wpa_s->sme.sae.group);
1550 if (ret < 0 || ret >= end - pos)
1554 #endif /* CONFIG_SAE */
1555 ret = os_snprintf(pos, end - pos, "wpa_state=%s\n",
1556 wpa_supplicant_state_txt(wpa_s->wpa_state));
1557 if (ret < 0 || ret >= end - pos)
1562 l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) {
1563 ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp);
1564 if (ret < 0 || ret >= end - pos)
1570 if (wpa_s->global->p2p) {
1571 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
1572 "\n", MAC2STR(wpa_s->global->p2p_dev_addr));
1573 if (ret < 0 || ret >= end - pos)
1577 #endif /* CONFIG_P2P */
1579 ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n",
1580 MAC2STR(wpa_s->own_addr));
1581 if (ret < 0 || ret >= end - pos)
1586 if (wpa_s->current_bss &&
1587 wpa_bss_get_vendor_ie(wpa_s->current_bss, HS20_IE_VENDOR_TYPE) &&
1588 wpa_s->wpa_proto == WPA_PROTO_RSN &&
1589 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1590 ret = os_snprintf(pos, end - pos, "hs20=1\n");
1591 if (ret < 0 || ret >= end - pos)
1596 if (wpa_s->current_ssid) {
1597 struct wpa_cred *cred;
1600 for (cred = wpa_s->conf->cred; cred; cred = cred->next) {
1603 if (wpa_s->current_ssid->parent_cred != cred)
1606 for (i = 0; cred->domain && i < cred->num_domain; i++) {
1607 ret = os_snprintf(pos, end - pos,
1610 if (ret < 0 || ret >= end - pos)
1615 if (wpa_s->current_bss == NULL ||
1616 wpa_s->current_bss->anqp == NULL)
1619 res = interworking_home_sp_cred(
1621 wpa_s->current_bss->anqp->domain_name);
1629 ret = os_snprintf(pos, end - pos, "sp_type=%s\n", type);
1630 if (ret < 0 || ret >= end - pos)
1637 #endif /* CONFIG_HS20 */
1639 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
1640 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
1641 res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos,
1647 res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose);
1654 uuid_bin2str(wpa_s->wps->uuid, uuid_str, sizeof(uuid_str));
1655 ret = os_snprintf(pos, end - pos, "uuid=%s\n", uuid_str);
1656 if (ret < 0 || ret >= end - pos)
1660 #endif /* CONFIG_WPS */
1663 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_STATE_CHANGE
1664 "id=%d state=%d BSSID=" MACSTR " SSID=%s",
1665 wpa_s->current_ssid ? wpa_s->current_ssid->id : -1,
1667 MAC2STR(wpa_s->bssid),
1668 wpa_s->current_ssid && wpa_s->current_ssid->ssid ?
1669 wpa_ssid_txt(wpa_s->current_ssid->ssid,
1670 wpa_s->current_ssid->ssid_len) : "");
1671 if (wpa_s->wpa_state == WPA_COMPLETED) {
1672 struct wpa_ssid *ssid = wpa_s->current_ssid;
1673 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_CONNECTED
1674 "- connection to " MACSTR
1675 " completed %s [id=%d id_str=%s]",
1676 MAC2STR(wpa_s->bssid), "(auth)",
1677 ssid ? ssid->id : -1,
1678 ssid && ssid->id_str ? ssid->id_str : "");
1680 #endif /* ANDROID */
1686 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s,
1691 struct wpa_ssid *ssid;
1694 /* cmd: "<network id> <BSSID>" */
1695 pos = os_strchr(cmd, ' ');
1700 wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos);
1701 if (hwaddr_aton(pos, bssid)) {
1702 wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos);
1706 ssid = wpa_config_get_network(wpa_s->conf, id);
1708 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
1713 os_memcpy(ssid->bssid, bssid, ETH_ALEN);
1714 ssid->bssid_set = !is_zero_ether_addr(bssid);
1720 static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant *wpa_s,
1721 char *cmd, char *buf,
1725 struct wpa_blacklist *e;
1729 /* cmd: "BLACKLIST [<BSSID>]" */
1733 e = wpa_s->blacklist;
1735 ret = os_snprintf(pos, end - pos, MACSTR "\n",
1737 if (ret < 0 || ret >= end - pos)
1746 if (os_strncmp(cmd, "clear", 5) == 0) {
1747 wpa_blacklist_clear(wpa_s);
1748 os_memcpy(buf, "OK\n", 3);
1752 wpa_printf(MSG_DEBUG, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd);
1753 if (hwaddr_aton(cmd, bssid)) {
1754 wpa_printf(MSG_DEBUG, "CTRL_IFACE: invalid BSSID '%s'", cmd);
1759 * Add the BSSID twice, so its count will be 2, causing it to be
1760 * skipped when processing scan results.
1762 ret = wpa_blacklist_add(wpa_s, bssid);
1765 ret = wpa_blacklist_add(wpa_s, bssid);
1768 os_memcpy(buf, "OK\n", 3);
1773 static const char * debug_level_str(int level)
1794 static int str_to_debug_level(const char *s)
1796 if (os_strcasecmp(s, "EXCESSIVE") == 0)
1797 return MSG_EXCESSIVE;
1798 if (os_strcasecmp(s, "MSGDUMP") == 0)
1800 if (os_strcasecmp(s, "DEBUG") == 0)
1802 if (os_strcasecmp(s, "INFO") == 0)
1804 if (os_strcasecmp(s, "WARNING") == 0)
1806 if (os_strcasecmp(s, "ERROR") == 0)
1812 static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant *wpa_s,
1813 char *cmd, char *buf,
1816 char *pos, *end, *stamp;
1823 /* cmd: "LOG_LEVEL [<level>]" */
1827 ret = os_snprintf(pos, end - pos, "Current level: %s\n"
1829 debug_level_str(wpa_debug_level),
1830 wpa_debug_timestamp);
1831 if (ret < 0 || ret >= end - pos)
1840 stamp = os_strchr(cmd, ' ');
1843 while (*stamp == ' ') {
1848 if (cmd && os_strlen(cmd)) {
1849 int level = str_to_debug_level(cmd);
1852 wpa_debug_level = level;
1855 if (stamp && os_strlen(stamp))
1856 wpa_debug_timestamp = atoi(stamp);
1858 os_memcpy(buf, "OK\n", 3);
1863 static int wpa_supplicant_ctrl_iface_list_networks(
1864 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
1867 struct wpa_ssid *ssid;
1872 ret = os_snprintf(pos, end - pos,
1873 "network id / ssid / bssid / flags\n");
1874 if (ret < 0 || ret >= end - pos)
1878 ssid = wpa_s->conf->ssid;
1880 ret = os_snprintf(pos, end - pos, "%d\t%s",
1882 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
1883 if (ret < 0 || ret >= end - pos)
1886 if (ssid->bssid_set) {
1887 ret = os_snprintf(pos, end - pos, "\t" MACSTR,
1888 MAC2STR(ssid->bssid));
1890 ret = os_snprintf(pos, end - pos, "\tany");
1892 if (ret < 0 || ret >= end - pos)
1895 ret = os_snprintf(pos, end - pos, "\t%s%s%s%s",
1896 ssid == wpa_s->current_ssid ?
1898 ssid->disabled ? "[DISABLED]" : "",
1899 ssid->disabled_until.sec ?
1900 "[TEMP-DISABLED]" : "",
1901 ssid->disabled == 2 ? "[P2P-PERSISTENT]" :
1903 if (ret < 0 || ret >= end - pos)
1906 ret = os_snprintf(pos, end - pos, "\n");
1907 if (ret < 0 || ret >= end - pos)
1918 static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher)
1921 ret = os_snprintf(pos, end - pos, "-");
1922 if (ret < 0 || ret >= end - pos)
1925 ret = wpa_write_ciphers(pos, end, cipher, "+");
1933 static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
1934 const u8 *ie, size_t ie_len)
1936 struct wpa_ie_data data;
1939 ret = os_snprintf(pos, end - pos, "[%s-", proto);
1940 if (ret < 0 || ret >= end - pos)
1944 if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) {
1945 ret = os_snprintf(pos, end - pos, "?]");
1946 if (ret < 0 || ret >= end - pos)
1953 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
1954 ret = os_snprintf(pos, end - pos, "%sEAP", first ? "" : "+");
1955 if (ret < 0 || ret >= end - pos)
1960 if (data.key_mgmt & WPA_KEY_MGMT_PSK) {
1961 ret = os_snprintf(pos, end - pos, "%sPSK", first ? "" : "+");
1962 if (ret < 0 || ret >= end - pos)
1967 if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
1968 ret = os_snprintf(pos, end - pos, "%sNone", first ? "" : "+");
1969 if (ret < 0 || ret >= end - pos)
1974 #ifdef CONFIG_IEEE80211R
1975 if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
1976 ret = os_snprintf(pos, end - pos, "%sFT/EAP",
1978 if (ret < 0 || ret >= end - pos)
1983 if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) {
1984 ret = os_snprintf(pos, end - pos, "%sFT/PSK",
1986 if (ret < 0 || ret >= end - pos)
1991 #endif /* CONFIG_IEEE80211R */
1992 #ifdef CONFIG_IEEE80211W
1993 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
1994 ret = os_snprintf(pos, end - pos, "%sEAP-SHA256",
1996 if (ret < 0 || ret >= end - pos)
2001 if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
2002 ret = os_snprintf(pos, end - pos, "%sPSK-SHA256",
2004 if (ret < 0 || ret >= end - pos)
2009 #endif /* CONFIG_IEEE80211W */
2011 pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher);
2013 if (data.capabilities & WPA_CAPABILITY_PREAUTH) {
2014 ret = os_snprintf(pos, end - pos, "-preauth");
2015 if (ret < 0 || ret >= end - pos)
2020 ret = os_snprintf(pos, end - pos, "]");
2021 if (ret < 0 || ret >= end - pos)
2030 static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s,
2031 char *pos, char *end,
2032 struct wpabuf *wps_ie)
2039 if (wps_is_selected_pbc_registrar(wps_ie))
2042 else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0))
2044 #endif /* CONFIG_WPS2 */
2045 else if (wps_is_selected_pin_registrar(wps_ie))
2050 ret = os_snprintf(pos, end - pos, "%s", txt);
2051 if (ret >= 0 && ret < end - pos)
2053 wpabuf_free(wps_ie);
2056 #endif /* CONFIG_WPS */
2059 static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s,
2060 char *pos, char *end,
2061 const struct wpa_bss *bss)
2064 struct wpabuf *wps_ie;
2065 wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
2066 return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie);
2067 #else /* CONFIG_WPS */
2069 #endif /* CONFIG_WPS */
2073 /* Format one result on one text line into a buffer. */
2074 static int wpa_supplicant_ctrl_iface_scan_result(
2075 struct wpa_supplicant *wpa_s,
2076 const struct wpa_bss *bss, char *buf, size_t buflen)
2080 const u8 *ie, *ie2, *p2p;
2082 p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
2084 p2p = wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE);
2085 if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN &&
2086 os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) ==
2088 return 0; /* Do not show P2P listen discovery results here */
2093 ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t",
2094 MAC2STR(bss->bssid), bss->freq, bss->level);
2095 if (ret < 0 || ret >= end - pos)
2098 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
2100 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]);
2101 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
2103 pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2, 2 + ie2[1]);
2104 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
2105 if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
2106 ret = os_snprintf(pos, end - pos, "[WEP]");
2107 if (ret < 0 || ret >= end - pos)
2111 if (bss->caps & IEEE80211_CAP_IBSS) {
2112 ret = os_snprintf(pos, end - pos, "[IBSS]");
2113 if (ret < 0 || ret >= end - pos)
2117 if (bss->caps & IEEE80211_CAP_ESS) {
2118 ret = os_snprintf(pos, end - pos, "[ESS]");
2119 if (ret < 0 || ret >= end - pos)
2124 ret = os_snprintf(pos, end - pos, "[P2P]");
2125 if (ret < 0 || ret >= end - pos)
2130 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE) && ie2) {
2131 ret = os_snprintf(pos, end - pos, "[HS20]");
2132 if (ret < 0 || ret >= end - pos)
2136 #endif /* CONFIG_HS20 */
2138 ret = os_snprintf(pos, end - pos, "\t%s",
2139 wpa_ssid_txt(bss->ssid, bss->ssid_len));
2140 if (ret < 0 || ret >= end - pos)
2144 ret = os_snprintf(pos, end - pos, "\n");
2145 if (ret < 0 || ret >= end - pos)
2153 static int wpa_supplicant_ctrl_iface_scan_results(
2154 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
2157 struct wpa_bss *bss;
2162 ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / "
2164 if (ret < 0 || ret >= end - pos)
2168 dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
2169 ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos,
2171 if (ret < 0 || ret >= end - pos)
2180 static int wpa_supplicant_ctrl_iface_select_network(
2181 struct wpa_supplicant *wpa_s, char *cmd)
2184 struct wpa_ssid *ssid;
2186 /* cmd: "<network id>" or "any" */
2187 if (os_strcmp(cmd, "any") == 0) {
2188 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any");
2192 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id);
2194 ssid = wpa_config_get_network(wpa_s->conf, id);
2196 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2197 "network id=%d", id);
2200 if (ssid->disabled == 2) {
2201 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2202 "SELECT_NETWORK with persistent P2P group");
2207 wpa_supplicant_select_network(wpa_s, ssid);
2213 static int wpa_supplicant_ctrl_iface_enable_network(
2214 struct wpa_supplicant *wpa_s, char *cmd)
2217 struct wpa_ssid *ssid;
2219 /* cmd: "<network id>" or "all" */
2220 if (os_strcmp(cmd, "all") == 0) {
2221 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all");
2225 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id);
2227 ssid = wpa_config_get_network(wpa_s->conf, id);
2229 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2230 "network id=%d", id);
2233 if (ssid->disabled == 2) {
2234 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2235 "ENABLE_NETWORK with persistent P2P group");
2239 if (os_strstr(cmd, " no-connect")) {
2244 wpa_supplicant_enable_network(wpa_s, ssid);
2250 static int wpa_supplicant_ctrl_iface_disable_network(
2251 struct wpa_supplicant *wpa_s, char *cmd)
2254 struct wpa_ssid *ssid;
2256 /* cmd: "<network id>" or "all" */
2257 if (os_strcmp(cmd, "all") == 0) {
2258 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all");
2262 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id);
2264 ssid = wpa_config_get_network(wpa_s->conf, id);
2266 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2267 "network id=%d", id);
2270 if (ssid->disabled == 2) {
2271 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2272 "DISABLE_NETWORK with persistent P2P "
2277 wpa_supplicant_disable_network(wpa_s, ssid);
2283 static int wpa_supplicant_ctrl_iface_add_network(
2284 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
2286 struct wpa_ssid *ssid;
2289 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK");
2291 ssid = wpa_config_add_network(wpa_s->conf);
2295 wpas_notify_network_added(wpa_s, ssid);
2298 wpa_config_set_network_defaults(ssid);
2300 ret = os_snprintf(buf, buflen, "%d\n", ssid->id);
2301 if (ret < 0 || (size_t) ret >= buflen)
2307 static int wpa_supplicant_ctrl_iface_remove_network(
2308 struct wpa_supplicant *wpa_s, char *cmd)
2311 struct wpa_ssid *ssid;
2314 /* cmd: "<network id>" or "all" */
2315 if (os_strcmp(cmd, "all") == 0) {
2316 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all");
2317 if (wpa_s->sched_scanning)
2318 wpa_supplicant_cancel_sched_scan(wpa_s);
2320 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2321 if (wpa_s->current_ssid) {
2323 wpa_s->sme.prev_bssid_set = 0;
2324 #endif /* CONFIG_SME */
2325 wpa_sm_set_config(wpa_s->wpa, NULL);
2326 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
2327 wpa_supplicant_deauthenticate(
2328 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2330 ssid = wpa_s->conf->ssid;
2332 struct wpa_ssid *remove_ssid = ssid;
2335 wpas_notify_network_removed(wpa_s, remove_ssid);
2336 wpa_config_remove_network(wpa_s->conf, id);
2342 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id);
2344 ssid = wpa_config_get_network(wpa_s->conf, id);
2346 wpas_notify_network_removed(wpa_s, ssid);
2348 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2353 if (ssid == wpa_s->current_ssid || wpa_s->current_ssid == NULL) {
2355 wpa_s->sme.prev_bssid_set = 0;
2356 #endif /* CONFIG_SME */
2358 * Invalidate the EAP session cache if the current or
2359 * previously used network is removed.
2361 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2364 if (ssid == wpa_s->current_ssid) {
2365 wpa_sm_set_config(wpa_s->wpa, NULL);
2366 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
2368 wpa_supplicant_deauthenticate(wpa_s,
2369 WLAN_REASON_DEAUTH_LEAVING);
2372 was_disabled = ssid->disabled;
2374 if (wpa_config_remove_network(wpa_s->conf, id) < 0) {
2375 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Not able to remove the "
2376 "network id=%d", id);
2380 if (!was_disabled && wpa_s->sched_scanning) {
2381 wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to remove "
2382 "network from filters");
2383 wpa_supplicant_cancel_sched_scan(wpa_s);
2384 wpa_supplicant_req_scan(wpa_s, 0, 0);
2391 static int wpa_supplicant_ctrl_iface_set_network(
2392 struct wpa_supplicant *wpa_s, char *cmd)
2395 struct wpa_ssid *ssid;
2398 /* cmd: "<network id> <variable name> <value>" */
2399 name = os_strchr(cmd, ' ');
2404 value = os_strchr(name, ' ');
2410 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
2412 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
2413 (u8 *) value, os_strlen(value));
2415 ssid = wpa_config_get_network(wpa_s->conf, id);
2417 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2422 if (wpa_config_set(ssid, name, value, 0) < 0) {
2423 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network "
2424 "variable '%s'", name);
2428 if (os_strcmp(name, "bssid") != 0 &&
2429 os_strcmp(name, "priority") != 0)
2430 wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
2432 if (wpa_s->current_ssid == ssid || wpa_s->current_ssid == NULL) {
2434 * Invalidate the EAP session cache if anything in the current
2435 * or previously used configuration changes.
2437 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2440 if ((os_strcmp(name, "psk") == 0 &&
2441 value[0] == '"' && ssid->ssid_len) ||
2442 (os_strcmp(name, "ssid") == 0 && ssid->passphrase))
2443 wpa_config_update_psk(ssid);
2444 else if (os_strcmp(name, "priority") == 0)
2445 wpa_config_update_prio_list(wpa_s->conf);
2451 static int wpa_supplicant_ctrl_iface_get_network(
2452 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
2456 struct wpa_ssid *ssid;
2459 /* cmd: "<network id> <variable name>" */
2460 name = os_strchr(cmd, ' ');
2461 if (name == NULL || buflen == 0)
2466 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
2469 ssid = wpa_config_get_network(wpa_s->conf, id);
2471 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2476 value = wpa_config_get_no_key(ssid, name);
2477 if (value == NULL) {
2478 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
2479 "variable '%s'", name);
2483 res = os_strlcpy(buf, value, buflen);
2484 if (res >= buflen) {
2495 static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant *wpa_s,
2496 char *buf, size_t buflen)
2499 struct wpa_cred *cred;
2504 ret = os_snprintf(pos, end - pos,
2505 "cred id / realm / username / domain / imsi\n");
2506 if (ret < 0 || ret >= end - pos)
2510 cred = wpa_s->conf->cred;
2512 ret = os_snprintf(pos, end - pos, "%d\t%s\t%s\t%s\t%s\n",
2513 cred->id, cred->realm ? cred->realm : "",
2514 cred->username ? cred->username : "",
2515 cred->domain ? cred->domain[0] : "",
2516 cred->imsi ? cred->imsi : "");
2517 if (ret < 0 || ret >= end - pos)
2528 static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant *wpa_s,
2529 char *buf, size_t buflen)
2531 struct wpa_cred *cred;
2534 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_CRED");
2536 cred = wpa_config_add_cred(wpa_s->conf);
2540 ret = os_snprintf(buf, buflen, "%d\n", cred->id);
2541 if (ret < 0 || (size_t) ret >= buflen)
2547 static int wpas_ctrl_remove_cred(struct wpa_supplicant *wpa_s,
2548 struct wpa_cred *cred)
2550 struct wpa_ssid *ssid;
2553 if (cred == NULL || wpa_config_remove_cred(wpa_s->conf, cred->id) < 0) {
2554 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred");
2558 /* Remove any network entry created based on the removed credential */
2559 ssid = wpa_s->conf->ssid;
2561 if (ssid->parent_cred == cred) {
2562 wpa_printf(MSG_DEBUG, "Remove network id %d since it "
2563 "used the removed credential", ssid->id);
2564 os_snprintf(str, sizeof(str), "%d", ssid->id);
2566 wpa_supplicant_ctrl_iface_remove_network(wpa_s, str);
2575 static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s,
2579 struct wpa_cred *cred, *prev;
2581 /* cmd: "<cred id>", "all", or "sp_fqdn=<FQDN>" */
2582 if (os_strcmp(cmd, "all") == 0) {
2583 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED all");
2584 cred = wpa_s->conf->cred;
2588 wpas_ctrl_remove_cred(wpa_s, prev);
2593 if (os_strncmp(cmd, "sp_fqdn=", 8) == 0) {
2594 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
2596 cred = wpa_s->conf->cred;
2602 for (i = 0; i < prev->num_domain; i++) {
2603 if (os_strcmp(prev->domain[i], cmd + 8)
2606 wpas_ctrl_remove_cred(wpa_s, prev);
2615 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED id=%d", id);
2617 cred = wpa_config_get_cred(wpa_s->conf, id);
2618 return wpas_ctrl_remove_cred(wpa_s, cred);
2622 static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant *wpa_s,
2626 struct wpa_cred *cred;
2629 /* cmd: "<cred id> <variable name> <value>" */
2630 name = os_strchr(cmd, ' ');
2635 value = os_strchr(name, ' ');
2641 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_CRED id=%d name='%s'",
2643 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
2644 (u8 *) value, os_strlen(value));
2646 cred = wpa_config_get_cred(wpa_s->conf, id);
2648 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
2653 if (wpa_config_set_cred(cred, name, value, 0) < 0) {
2654 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set cred "
2655 "variable '%s'", name);
2663 #ifndef CONFIG_NO_CONFIG_WRITE
2664 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s)
2668 if (!wpa_s->conf->update_config) {
2669 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
2670 "to update configuration (update_config=0)");
2674 ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
2676 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to "
2677 "update configuration");
2679 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration"
2685 #endif /* CONFIG_NO_CONFIG_WRITE */
2688 struct cipher_info {
2694 static const struct cipher_info ciphers[] = {
2695 { WPA_DRIVER_CAPA_ENC_CCMP_256, "CCMP-256", 0 },
2696 { WPA_DRIVER_CAPA_ENC_GCMP_256, "GCMP-256", 0 },
2697 { WPA_DRIVER_CAPA_ENC_CCMP, "CCMP", 0 },
2698 { WPA_DRIVER_CAPA_ENC_GCMP, "GCMP", 0 },
2699 { WPA_DRIVER_CAPA_ENC_TKIP, "TKIP", 0 },
2700 { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE, "NONE", 0 },
2701 { WPA_DRIVER_CAPA_ENC_WEP104, "WEP104", 1 },
2702 { WPA_DRIVER_CAPA_ENC_WEP40, "WEP40", 1 }
2706 static int ctrl_iface_get_capability_pairwise(int res, char *strict,
2707 struct wpa_driver_capa *capa,
2708 char *buf, size_t buflen)
2721 len = os_strlcpy(buf, "CCMP TKIP NONE", buflen);
2727 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
2728 if (!ciphers[i].group_only && capa->enc & ciphers[i].capa) {
2729 ret = os_snprintf(pos, end - pos, "%s%s",
2730 first ? "" : " ", ciphers[i].name);
2731 if (ret < 0 || ret >= end - pos)
2742 static int ctrl_iface_get_capability_group(int res, char *strict,
2743 struct wpa_driver_capa *capa,
2744 char *buf, size_t buflen)
2757 len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen);
2763 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
2764 if (capa->enc & ciphers[i].capa) {
2765 ret = os_snprintf(pos, end - pos, "%s%s",
2766 first ? "" : " ", ciphers[i].name);
2767 if (ret < 0 || ret >= end - pos)
2778 static int ctrl_iface_get_capability_key_mgmt(int res, char *strict,
2779 struct wpa_driver_capa *capa,
2780 char *buf, size_t buflen)
2792 len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
2799 ret = os_snprintf(pos, end - pos, "NONE IEEE8021X");
2800 if (ret < 0 || ret >= end - pos)
2804 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
2805 WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
2806 ret = os_snprintf(pos, end - pos, " WPA-EAP");
2807 if (ret < 0 || ret >= end - pos)
2812 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
2813 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
2814 ret = os_snprintf(pos, end - pos, " WPA-PSK");
2815 if (ret < 0 || ret >= end - pos)
2820 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
2821 ret = os_snprintf(pos, end - pos, " WPA-NONE");
2822 if (ret < 0 || ret >= end - pos)
2831 static int ctrl_iface_get_capability_proto(int res, char *strict,
2832 struct wpa_driver_capa *capa,
2833 char *buf, size_t buflen)
2845 len = os_strlcpy(buf, "RSN WPA", buflen);
2851 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
2852 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
2853 ret = os_snprintf(pos, end - pos, "%sRSN", first ? "" : " ");
2854 if (ret < 0 || ret >= end - pos)
2860 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
2861 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
2862 ret = os_snprintf(pos, end - pos, "%sWPA", first ? "" : " ");
2863 if (ret < 0 || ret >= end - pos)
2873 static int ctrl_iface_get_capability_auth_alg(int res, char *strict,
2874 struct wpa_driver_capa *capa,
2875 char *buf, size_t buflen)
2887 len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen);
2893 if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) {
2894 ret = os_snprintf(pos, end - pos, "%sOPEN", first ? "" : " ");
2895 if (ret < 0 || ret >= end - pos)
2901 if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) {
2902 ret = os_snprintf(pos, end - pos, "%sSHARED",
2904 if (ret < 0 || ret >= end - pos)
2910 if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) {
2911 ret = os_snprintf(pos, end - pos, "%sLEAP", first ? "" : " ");
2912 if (ret < 0 || ret >= end - pos)
2922 static int ctrl_iface_get_capability_modes(int res, char *strict,
2923 struct wpa_driver_capa *capa,
2924 char *buf, size_t buflen)
2936 len = os_strlcpy(buf, "IBSS AP", buflen);
2942 if (capa->flags & WPA_DRIVER_FLAGS_IBSS) {
2943 ret = os_snprintf(pos, end - pos, "%sIBSS", first ? "" : " ");
2944 if (ret < 0 || ret >= end - pos)
2950 if (capa->flags & WPA_DRIVER_FLAGS_AP) {
2951 ret = os_snprintf(pos, end - pos, "%sAP", first ? "" : " ");
2952 if (ret < 0 || ret >= end - pos)
2962 static int ctrl_iface_get_capability_channels(struct wpa_supplicant *wpa_s,
2963 char *buf, size_t buflen)
2965 struct hostapd_channel_data *chnl;
2967 char *pos, *end, *hmode;
2972 for (j = 0; j < wpa_s->hw.num_modes; j++) {
2973 switch (wpa_s->hw.modes[j].mode) {
2974 case HOSTAPD_MODE_IEEE80211B:
2977 case HOSTAPD_MODE_IEEE80211G:
2980 case HOSTAPD_MODE_IEEE80211A:
2983 case HOSTAPD_MODE_IEEE80211AD:
2989 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:", hmode);
2990 if (ret < 0 || ret >= end - pos)
2993 chnl = wpa_s->hw.modes[j].channels;
2994 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
2995 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
2997 ret = os_snprintf(pos, end - pos, " %d", chnl[i].chan);
2998 if (ret < 0 || ret >= end - pos)
3002 ret = os_snprintf(pos, end - pos, "\n");
3003 if (ret < 0 || ret >= end - pos)
3012 static int ctrl_iface_get_capability_freq(struct wpa_supplicant *wpa_s,
3013 char *buf, size_t buflen)
3015 struct hostapd_channel_data *chnl;
3017 char *pos, *end, *hmode;
3022 for (j = 0; j < wpa_s->hw.num_modes; j++) {
3023 switch (wpa_s->hw.modes[j].mode) {
3024 case HOSTAPD_MODE_IEEE80211B:
3027 case HOSTAPD_MODE_IEEE80211G:
3030 case HOSTAPD_MODE_IEEE80211A:
3033 case HOSTAPD_MODE_IEEE80211AD:
3039 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:\n",
3041 if (ret < 0 || ret >= end - pos)
3044 chnl = wpa_s->hw.modes[j].channels;
3045 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
3046 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
3048 ret = os_snprintf(pos, end - pos, " %d = %d MHz%s\n",
3049 chnl[i].chan, chnl[i].freq,
3050 chnl[i].flag & HOSTAPD_CHAN_NO_IBSS ?
3052 if (ret < 0 || ret >= end - pos)
3056 ret = os_snprintf(pos, end - pos, "\n");
3057 if (ret < 0 || ret >= end - pos)
3066 static int wpa_supplicant_ctrl_iface_get_capability(
3067 struct wpa_supplicant *wpa_s, const char *_field, char *buf,
3070 struct wpa_driver_capa capa;
3076 /* Determine whether or not strict checking was requested */
3077 len = os_strlcpy(field, _field, sizeof(field));
3078 if (len >= sizeof(field))
3080 strict = os_strchr(field, ' ');
3081 if (strict != NULL) {
3083 if (os_strcmp(strict, "strict") != 0)
3087 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
3088 field, strict ? strict : "");
3090 if (os_strcmp(field, "eap") == 0) {
3091 return eap_get_names(buf, buflen);
3094 res = wpa_drv_get_capa(wpa_s, &capa);
3096 if (os_strcmp(field, "pairwise") == 0)
3097 return ctrl_iface_get_capability_pairwise(res, strict, &capa,
3100 if (os_strcmp(field, "group") == 0)
3101 return ctrl_iface_get_capability_group(res, strict, &capa,
3104 if (os_strcmp(field, "key_mgmt") == 0)
3105 return ctrl_iface_get_capability_key_mgmt(res, strict, &capa,
3108 if (os_strcmp(field, "proto") == 0)
3109 return ctrl_iface_get_capability_proto(res, strict, &capa,
3112 if (os_strcmp(field, "auth_alg") == 0)
3113 return ctrl_iface_get_capability_auth_alg(res, strict, &capa,
3116 if (os_strcmp(field, "modes") == 0)
3117 return ctrl_iface_get_capability_modes(res, strict, &capa,
3120 if (os_strcmp(field, "channels") == 0)
3121 return ctrl_iface_get_capability_channels(wpa_s, buf, buflen);
3123 if (os_strcmp(field, "freq") == 0)
3124 return ctrl_iface_get_capability_freq(wpa_s, buf, buflen);
3126 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
3133 #ifdef CONFIG_INTERWORKING
3134 static char * anqp_add_hex(char *pos, char *end, const char *title,
3135 struct wpabuf *data)
3145 ret = os_snprintf(pos, end - pos, "%s=", title);
3146 if (ret < 0 || ret >= end - pos)
3150 d = wpabuf_head_u8(data);
3151 for (i = 0; i < wpabuf_len(data); i++) {
3152 ret = os_snprintf(pos, end - pos, "%02x", *d++);
3153 if (ret < 0 || ret >= end - pos)
3158 ret = os_snprintf(pos, end - pos, "\n");
3159 if (ret < 0 || ret >= end - pos)
3165 #endif /* CONFIG_INTERWORKING */
3168 static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
3169 unsigned long mask, char *buf, size_t buflen)
3179 if (mask & WPA_BSS_MASK_ID) {
3180 ret = os_snprintf(pos, end - pos, "id=%u\n", bss->id);
3181 if (ret < 0 || ret >= end - pos)
3186 if (mask & WPA_BSS_MASK_BSSID) {
3187 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
3188 MAC2STR(bss->bssid));
3189 if (ret < 0 || ret >= end - pos)
3194 if (mask & WPA_BSS_MASK_FREQ) {
3195 ret = os_snprintf(pos, end - pos, "freq=%d\n", bss->freq);
3196 if (ret < 0 || ret >= end - pos)
3201 if (mask & WPA_BSS_MASK_BEACON_INT) {
3202 ret = os_snprintf(pos, end - pos, "beacon_int=%d\n",
3204 if (ret < 0 || ret >= end - pos)
3209 if (mask & WPA_BSS_MASK_CAPABILITIES) {
3210 ret = os_snprintf(pos, end - pos, "capabilities=0x%04x\n",
3212 if (ret < 0 || ret >= end - pos)
3217 if (mask & WPA_BSS_MASK_QUAL) {
3218 ret = os_snprintf(pos, end - pos, "qual=%d\n", bss->qual);
3219 if (ret < 0 || ret >= end - pos)
3224 if (mask & WPA_BSS_MASK_NOISE) {
3225 ret = os_snprintf(pos, end - pos, "noise=%d\n", bss->noise);
3226 if (ret < 0 || ret >= end - pos)
3231 if (mask & WPA_BSS_MASK_LEVEL) {
3232 ret = os_snprintf(pos, end - pos, "level=%d\n", bss->level);
3233 if (ret < 0 || ret >= end - pos)
3238 if (mask & WPA_BSS_MASK_TSF) {
3239 ret = os_snprintf(pos, end - pos, "tsf=%016llu\n",
3240 (unsigned long long) bss->tsf);
3241 if (ret < 0 || ret >= end - pos)
3246 if (mask & WPA_BSS_MASK_AGE) {
3247 struct os_reltime now;
3249 os_get_reltime(&now);
3250 ret = os_snprintf(pos, end - pos, "age=%d\n",
3251 (int) (now.sec - bss->last_update.sec));
3252 if (ret < 0 || ret >= end - pos)
3257 if (mask & WPA_BSS_MASK_IE) {
3258 ret = os_snprintf(pos, end - pos, "ie=");
3259 if (ret < 0 || ret >= end - pos)
3263 ie = (const u8 *) (bss + 1);
3264 for (i = 0; i < bss->ie_len; i++) {
3265 ret = os_snprintf(pos, end - pos, "%02x", *ie++);
3266 if (ret < 0 || ret >= end - pos)
3271 ret = os_snprintf(pos, end - pos, "\n");
3272 if (ret < 0 || ret >= end - pos)
3277 if (mask & WPA_BSS_MASK_FLAGS) {
3278 ret = os_snprintf(pos, end - pos, "flags=");
3279 if (ret < 0 || ret >= end - pos)
3283 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
3285 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie,
3287 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
3289 pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2,
3291 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
3292 if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
3293 ret = os_snprintf(pos, end - pos, "[WEP]");
3294 if (ret < 0 || ret >= end - pos)
3298 if (bss->caps & IEEE80211_CAP_IBSS) {
3299 ret = os_snprintf(pos, end - pos, "[IBSS]");
3300 if (ret < 0 || ret >= end - pos)
3304 if (bss->caps & IEEE80211_CAP_ESS) {
3305 ret = os_snprintf(pos, end - pos, "[ESS]");
3306 if (ret < 0 || ret >= end - pos)
3310 if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
3311 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
3312 ret = os_snprintf(pos, end - pos, "[P2P]");
3313 if (ret < 0 || ret >= end - pos)
3318 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) {
3319 ret = os_snprintf(pos, end - pos, "[HS20]");
3320 if (ret < 0 || ret >= end - pos)
3324 #endif /* CONFIG_HS20 */
3326 ret = os_snprintf(pos, end - pos, "\n");
3327 if (ret < 0 || ret >= end - pos)
3332 if (mask & WPA_BSS_MASK_SSID) {
3333 ret = os_snprintf(pos, end - pos, "ssid=%s\n",
3334 wpa_ssid_txt(bss->ssid, bss->ssid_len));
3335 if (ret < 0 || ret >= end - pos)
3341 if (mask & WPA_BSS_MASK_WPS_SCAN) {
3342 ie = (const u8 *) (bss + 1);
3343 ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end);
3344 if (ret < 0 || ret >= end - pos)
3348 #endif /* CONFIG_WPS */
3351 if (mask & WPA_BSS_MASK_P2P_SCAN) {
3352 ie = (const u8 *) (bss + 1);
3353 ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end);
3354 if (ret < 0 || ret >= end - pos)
3358 #endif /* CONFIG_P2P */
3360 #ifdef CONFIG_WIFI_DISPLAY
3361 if (mask & WPA_BSS_MASK_WIFI_DISPLAY) {
3363 ie = (const u8 *) (bss + 1);
3364 wfd = ieee802_11_vendor_ie_concat(ie, bss->ie_len,
3365 WFD_IE_VENDOR_TYPE);
3367 ret = os_snprintf(pos, end - pos, "wfd_subelems=");
3368 if (ret < 0 || ret >= end - pos)
3372 pos += wpa_snprintf_hex(pos, end - pos,
3377 ret = os_snprintf(pos, end - pos, "\n");
3378 if (ret < 0 || ret >= end - pos)
3383 #endif /* CONFIG_WIFI_DISPLAY */
3385 #ifdef CONFIG_INTERWORKING
3386 if ((mask & WPA_BSS_MASK_INTERNETW) && bss->anqp) {
3387 struct wpa_bss_anqp *anqp = bss->anqp;
3388 pos = anqp_add_hex(pos, end, "anqp_venue_name",
3390 pos = anqp_add_hex(pos, end, "anqp_network_auth_type",
3391 anqp->network_auth_type);
3392 pos = anqp_add_hex(pos, end, "anqp_roaming_consortium",
3393 anqp->roaming_consortium);
3394 pos = anqp_add_hex(pos, end, "anqp_ip_addr_type_availability",
3395 anqp->ip_addr_type_availability);
3396 pos = anqp_add_hex(pos, end, "anqp_nai_realm",
3398 pos = anqp_add_hex(pos, end, "anqp_3gpp", anqp->anqp_3gpp);
3399 pos = anqp_add_hex(pos, end, "anqp_domain_name",
3402 pos = anqp_add_hex(pos, end, "hs20_operator_friendly_name",
3403 anqp->hs20_operator_friendly_name);
3404 pos = anqp_add_hex(pos, end, "hs20_wan_metrics",
3405 anqp->hs20_wan_metrics);
3406 pos = anqp_add_hex(pos, end, "hs20_connection_capability",
3407 anqp->hs20_connection_capability);
3408 #endif /* CONFIG_HS20 */
3410 #endif /* CONFIG_INTERWORKING */
3412 if (mask & WPA_BSS_MASK_DELIM) {
3413 ret = os_snprintf(pos, end - pos, "====\n");
3414 if (ret < 0 || ret >= end - pos)
3423 static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
3424 const char *cmd, char *buf,
3429 struct wpa_bss *bss;
3430 struct wpa_bss *bsslast = NULL;
3431 struct dl_list *next;
3435 unsigned long mask = WPA_BSS_MASK_ALL;
3437 if (os_strncmp(cmd, "RANGE=", 6) == 0) {
3438 if (os_strncmp(cmd + 6, "ALL", 3) == 0) {
3439 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss,
3441 bsslast = dl_list_last(&wpa_s->bss_id, struct wpa_bss,
3443 } else { /* N1-N2 */
3444 unsigned int id1, id2;
3446 if ((ctmp = os_strchr(cmd + 6, '-')) == NULL) {
3447 wpa_printf(MSG_INFO, "Wrong BSS range "
3452 if (*(cmd + 6) == '-')
3455 id1 = atoi(cmd + 6);
3457 if (*ctmp >= '0' && *ctmp <= '9')
3460 id2 = (unsigned int) -1;
3461 bss = wpa_bss_get_id_range(wpa_s, id1, id2);
3462 if (id2 == (unsigned int) -1)
3463 bsslast = dl_list_last(&wpa_s->bss_id,
3467 bsslast = wpa_bss_get_id(wpa_s, id2);
3468 if (bsslast == NULL && bss && id2 > id1) {
3469 struct wpa_bss *tmp = bss;
3471 next = tmp->list_id.next;
3472 if (next == &wpa_s->bss_id)
3474 tmp = dl_list_entry(
3475 next, struct wpa_bss,
3484 } else if (os_strncmp(cmd, "FIRST", 5) == 0)
3485 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, list_id);
3486 else if (os_strncmp(cmd, "LAST", 4) == 0)
3487 bss = dl_list_last(&wpa_s->bss_id, struct wpa_bss, list_id);
3488 else if (os_strncmp(cmd, "ID-", 3) == 0) {
3490 bss = wpa_bss_get_id(wpa_s, i);
3491 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
3493 bss = wpa_bss_get_id(wpa_s, i);
3495 next = bss->list_id.next;
3496 if (next == &wpa_s->bss_id)
3499 bss = dl_list_entry(next, struct wpa_bss,
3503 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
3504 if (hwaddr_aton(cmd + 13, bssid) == 0)
3505 bss = wpa_bss_get_p2p_dev_addr(wpa_s, bssid);
3508 #endif /* CONFIG_P2P */
3509 } else if (hwaddr_aton(cmd, bssid) == 0)
3510 bss = wpa_bss_get_bssid(wpa_s, bssid);
3512 struct wpa_bss *tmp;
3515 dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id)
3524 if ((ctmp = os_strstr(cmd, "MASK=")) != NULL) {
3525 mask = strtoul(ctmp + 5, NULL, 0x10);
3527 mask = WPA_BSS_MASK_ALL;
3533 if (bsslast == NULL)
3536 len = print_bss_info(wpa_s, bss, mask, buf, buflen);
3540 if (bss == bsslast) {
3541 if ((mask & WPA_BSS_MASK_DELIM) && len &&
3542 (bss == dl_list_last(&wpa_s->bss_id,
3543 struct wpa_bss, list_id)))
3544 os_snprintf(buf - 5, 5, "####\n");
3547 next = bss->list_id.next;
3548 if (next == &wpa_s->bss_id)
3550 bss = dl_list_entry(next, struct wpa_bss, list_id);
3551 } while (bss && len);
3557 static int wpa_supplicant_ctrl_iface_ap_scan(
3558 struct wpa_supplicant *wpa_s, char *cmd)
3560 int ap_scan = atoi(cmd);
3561 return wpa_supplicant_set_ap_scan(wpa_s, ap_scan);
3565 static int wpa_supplicant_ctrl_iface_scan_interval(
3566 struct wpa_supplicant *wpa_s, char *cmd)
3568 int scan_int = atoi(cmd);
3569 return wpa_supplicant_set_scan_interval(wpa_s, scan_int);
3573 static int wpa_supplicant_ctrl_iface_bss_expire_age(
3574 struct wpa_supplicant *wpa_s, char *cmd)
3576 int expire_age = atoi(cmd);
3577 return wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age);
3581 static int wpa_supplicant_ctrl_iface_bss_expire_count(
3582 struct wpa_supplicant *wpa_s, char *cmd)
3584 int expire_count = atoi(cmd);
3585 return wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count);
3589 static int wpa_supplicant_ctrl_iface_bss_flush(
3590 struct wpa_supplicant *wpa_s, char *cmd)
3592 int flush_age = atoi(cmd);
3595 wpa_bss_flush(wpa_s);
3597 wpa_bss_flush_by_age(wpa_s, flush_age);
3602 static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s)
3604 wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication");
3605 /* MLME-DELETEKEYS.request */
3606 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL, 0);
3607 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL, 0);
3608 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL, 0);
3609 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL, 0);
3610 #ifdef CONFIG_IEEE80211W
3611 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL, 0);
3612 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL, 0);
3613 #endif /* CONFIG_IEEE80211W */
3615 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, wpa_s->bssid, 0, 0, NULL, 0, NULL,
3617 /* MLME-SETPROTECTION.request(None) */
3618 wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid,
3619 MLME_SETPROTECTION_PROTECT_TYPE_NONE,
3620 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE);
3621 wpa_sm_drop_sa(wpa_s->wpa);
3625 static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s,
3628 #ifdef CONFIG_NO_SCAN_PROCESSING
3630 #else /* CONFIG_NO_SCAN_PROCESSING */
3632 struct wpa_bss *bss;
3633 struct wpa_ssid *ssid = wpa_s->current_ssid;
3635 if (hwaddr_aton(addr, bssid)) {
3636 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid "
3637 "address '%s'", addr);
3641 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR, MAC2STR(bssid));
3644 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network "
3645 "configuration known for the target AP");
3649 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
3651 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found "
3657 * TODO: Find best network configuration block from configuration to
3658 * allow roaming to other networks
3661 wpa_s->reassociate = 1;
3662 wpa_supplicant_connect(wpa_s, bss, ssid);
3665 #endif /* CONFIG_NO_SCAN_PROCESSING */
3670 static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd)
3672 unsigned int timeout = atoi(cmd);
3673 enum p2p_discovery_type type = P2P_FIND_START_WITH_FULL;
3674 u8 dev_id[ETH_ALEN], *_dev_id = NULL;
3675 u8 dev_type[WPS_DEV_TYPE_LEN], *_dev_type = NULL;
3677 unsigned int search_delay;
3679 if (os_strstr(cmd, "type=social"))
3680 type = P2P_FIND_ONLY_SOCIAL;
3681 else if (os_strstr(cmd, "type=progressive"))
3682 type = P2P_FIND_PROGRESSIVE;
3684 pos = os_strstr(cmd, "dev_id=");
3687 if (hwaddr_aton(pos, dev_id))
3692 pos = os_strstr(cmd, "dev_type=");
3695 if (wps_dev_type_str2bin(pos, dev_type) < 0)
3697 _dev_type = dev_type;
3700 pos = os_strstr(cmd, "delay=");
3703 search_delay = atoi(pos);
3705 search_delay = wpas_p2p_search_delay(wpa_s);
3707 return wpas_p2p_find(wpa_s, timeout, type, _dev_type != NULL, _dev_type,
3708 _dev_id, search_delay);
3712 static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd,
3713 char *buf, size_t buflen)
3718 enum p2p_wps_method wps_method;
3721 int persistent_group, persistent_id = -1;
3730 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad]
3731 * [persistent|persistent=<network id>]
3732 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
3735 if (hwaddr_aton(cmd, addr))
3743 persistent_group = os_strstr(pos, " persistent") != NULL;
3744 pos2 = os_strstr(pos, " persistent=");
3746 struct wpa_ssid *ssid;
3747 persistent_id = atoi(pos2 + 12);
3748 ssid = wpa_config_get_network(wpa_s->conf, persistent_id);
3749 if (ssid == NULL || ssid->disabled != 2 ||
3750 ssid->mode != WPAS_MODE_P2P_GO) {
3751 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3752 "SSID id=%d for persistent P2P group (GO)",
3757 join = os_strstr(pos, " join") != NULL;
3758 auth = os_strstr(pos, " auth") != NULL;
3759 automatic = os_strstr(pos, " auto") != NULL;
3760 pd = os_strstr(pos, " provdisc") != NULL;
3761 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
3762 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
3765 pos2 = os_strstr(pos, " go_intent=");
3768 go_intent = atoi(pos2);
3769 if (go_intent < 0 || go_intent > 15)
3773 pos2 = os_strstr(pos, " freq=");
3781 if (os_strncmp(pos, "pin", 3) == 0) {
3782 /* Request random PIN (to be displayed) and enable the PIN */
3783 wps_method = WPS_PIN_DISPLAY;
3784 } else if (os_strncmp(pos, "pbc", 3) == 0) {
3785 wps_method = WPS_PBC;
3788 pos = os_strchr(pin, ' ');
3789 wps_method = WPS_PIN_KEYPAD;
3792 if (os_strncmp(pos, "display", 7) == 0)
3793 wps_method = WPS_PIN_DISPLAY;
3795 if (!wps_pin_str_valid(pin)) {
3796 os_memcpy(buf, "FAIL-INVALID-PIN\n", 17);
3801 new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method,
3802 persistent_group, automatic, join,
3803 auth, go_intent, freq, persistent_id, pd,
3805 if (new_pin == -2) {
3806 os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
3809 if (new_pin == -3) {
3810 os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
3815 if (wps_method == WPS_PIN_DISPLAY && pin == NULL) {
3816 ret = os_snprintf(buf, buflen, "%08d", new_pin);
3817 if (ret < 0 || (size_t) ret >= buflen)
3822 os_memcpy(buf, "OK\n", 3);
3827 static int p2p_ctrl_listen(struct wpa_supplicant *wpa_s, char *cmd)
3829 unsigned int timeout = atoi(cmd);
3830 return wpas_p2p_listen(wpa_s, timeout);
3834 static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd)
3838 enum wpas_p2p_prov_disc_use use = WPAS_P2P_PD_FOR_GO_NEG;
3840 /* <addr> <config method> [join|auto] */
3842 if (hwaddr_aton(cmd, addr))
3850 if (os_strstr(pos, " join") != NULL)
3851 use = WPAS_P2P_PD_FOR_JOIN;
3852 else if (os_strstr(pos, " auto") != NULL)
3853 use = WPAS_P2P_PD_AUTO;
3855 return wpas_p2p_prov_disc(wpa_s, addr, pos, use);
3859 static int p2p_get_passphrase(struct wpa_supplicant *wpa_s, char *buf,
3862 struct wpa_ssid *ssid = wpa_s->current_ssid;
3864 if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO ||
3865 ssid->passphrase == NULL)
3868 os_strlcpy(buf, ssid->passphrase, buflen);
3869 return os_strlen(buf);
3873 static int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd,
3874 char *buf, size_t buflen)
3878 u8 dst_buf[ETH_ALEN], *dst;
3879 struct wpabuf *tlvs;
3883 if (hwaddr_aton(cmd, dst_buf))
3886 if (dst[0] == 0 && dst[1] == 0 && dst[2] == 0 &&
3887 dst[3] == 0 && dst[4] == 0 && dst[5] == 0)
3894 if (os_strncmp(pos, "upnp ", 5) == 0) {
3897 if (hexstr2bin(pos, &version, 1) < 0)
3903 ref = wpas_p2p_sd_request_upnp(wpa_s, dst, version, pos);
3904 #ifdef CONFIG_WIFI_DISPLAY
3905 } else if (os_strncmp(pos, "wifi-display ", 13) == 0) {
3906 ref = wpas_p2p_sd_request_wifi_display(wpa_s, dst, pos + 13);
3907 #endif /* CONFIG_WIFI_DISPLAY */
3909 len = os_strlen(pos);
3913 tlvs = wpabuf_alloc(len);
3916 if (hexstr2bin(pos, wpabuf_put(tlvs, len), len) < 0) {
3921 ref = wpas_p2p_sd_request(wpa_s, dst, tlvs);
3926 res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref);
3927 if (res < 0 || (unsigned) res >= buflen)
3933 static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s,
3936 long long unsigned val;
3938 if (sscanf(cmd, "%llx", &val) != 1)
3941 return wpas_p2p_sd_cancel_request(wpa_s, req);
3945 static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant *wpa_s, char *cmd)
3950 struct wpabuf *resp_tlvs;
3954 pos = os_strchr(cmd, ' ');
3962 if (hwaddr_aton(pos, dst))
3969 pos2 = os_strchr(pos, ' ');
3973 dialog_token = atoi(pos);
3975 len = os_strlen(pos2);
3979 resp_tlvs = wpabuf_alloc(len);
3980 if (resp_tlvs == NULL)
3982 if (hexstr2bin(pos2, wpabuf_put(resp_tlvs, len), len) < 0) {
3983 wpabuf_free(resp_tlvs);
3987 wpas_p2p_sd_response(wpa_s, freq, dst, dialog_token, resp_tlvs);
3988 wpabuf_free(resp_tlvs);
3993 static int p2p_ctrl_serv_disc_external(struct wpa_supplicant *wpa_s,
3996 if (os_strcmp(cmd, "0") && os_strcmp(cmd, "1"))
3998 wpa_s->p2p_sd_over_ctrl_iface = atoi(cmd);
4003 static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant *wpa_s,
4008 struct wpabuf *query, *resp;
4010 pos = os_strchr(cmd, ' ');
4015 len = os_strlen(cmd);
4019 query = wpabuf_alloc(len);
4022 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
4027 len = os_strlen(pos);
4033 resp = wpabuf_alloc(len);
4038 if (hexstr2bin(pos, wpabuf_put(resp, len), len) < 0) {
4044 if (wpas_p2p_service_add_bonjour(wpa_s, query, resp) < 0) {
4053 static int p2p_ctrl_service_add_upnp(struct wpa_supplicant *wpa_s, char *cmd)
4058 pos = os_strchr(cmd, ' ');
4063 if (hexstr2bin(cmd, &version, 1) < 0)
4066 return wpas_p2p_service_add_upnp(wpa_s, version, pos);
4070 static int p2p_ctrl_service_add(struct wpa_supplicant *wpa_s, char *cmd)
4074 pos = os_strchr(cmd, ' ');
4079 if (os_strcmp(cmd, "bonjour") == 0)
4080 return p2p_ctrl_service_add_bonjour(wpa_s, pos);
4081 if (os_strcmp(cmd, "upnp") == 0)
4082 return p2p_ctrl_service_add_upnp(wpa_s, pos);
4083 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
4088 static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant *wpa_s,
4092 struct wpabuf *query;
4095 len = os_strlen(cmd);
4099 query = wpabuf_alloc(len);
4102 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
4107 ret = wpas_p2p_service_del_bonjour(wpa_s, query);
4113 static int p2p_ctrl_service_del_upnp(struct wpa_supplicant *wpa_s, char *cmd)
4118 pos = os_strchr(cmd, ' ');
4123 if (hexstr2bin(cmd, &version, 1) < 0)
4126 return wpas_p2p_service_del_upnp(wpa_s, version, pos);
4130 static int p2p_ctrl_service_del(struct wpa_supplicant *wpa_s, char *cmd)
4134 pos = os_strchr(cmd, ' ');
4139 if (os_strcmp(cmd, "bonjour") == 0)
4140 return p2p_ctrl_service_del_bonjour(wpa_s, pos);
4141 if (os_strcmp(cmd, "upnp") == 0)
4142 return p2p_ctrl_service_del_upnp(wpa_s, pos);
4143 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
4148 static int p2p_ctrl_reject(struct wpa_supplicant *wpa_s, char *cmd)
4154 if (hwaddr_aton(cmd, addr))
4157 return wpas_p2p_reject(wpa_s, addr);
4161 static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd)
4165 struct wpa_ssid *ssid;
4166 u8 *_peer = NULL, peer[ETH_ALEN];
4167 int freq = 0, pref_freq = 0;
4171 pos = os_strstr(cmd, " peer=");
4174 if (hwaddr_aton(pos, peer))
4178 ssid = wpa_config_get_network(wpa_s->conf, id);
4179 if (ssid == NULL || ssid->disabled != 2) {
4180 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
4181 "for persistent P2P group",
4186 pos = os_strstr(cmd, " freq=");
4194 pos = os_strstr(cmd, " pref=");
4197 pref_freq = atoi(pos);
4202 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
4203 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
4206 return wpas_p2p_invite(wpa_s, _peer, ssid, NULL, freq, ht40, vht,
4211 static int p2p_ctrl_invite_group(struct wpa_supplicant *wpa_s, char *cmd)
4214 u8 peer[ETH_ALEN], go_dev_addr[ETH_ALEN], *go_dev = NULL;
4216 pos = os_strstr(cmd, " peer=");
4222 if (hwaddr_aton(pos, peer)) {
4223 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", pos);
4227 pos = os_strstr(pos, " go_dev_addr=");
4230 if (hwaddr_aton(pos, go_dev_addr)) {
4231 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'",
4235 go_dev = go_dev_addr;
4238 return wpas_p2p_invite_group(wpa_s, cmd, peer, go_dev);
4242 static int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd)
4244 if (os_strncmp(cmd, "persistent=", 11) == 0)
4245 return p2p_ctrl_invite_persistent(wpa_s, cmd + 11);
4246 if (os_strncmp(cmd, "group=", 6) == 0)
4247 return p2p_ctrl_invite_group(wpa_s, cmd + 6);
4253 static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s,
4254 char *cmd, int freq, int ht40,
4258 struct wpa_ssid *ssid;
4261 ssid = wpa_config_get_network(wpa_s->conf, id);
4262 if (ssid == NULL || ssid->disabled != 2) {
4263 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
4264 "for persistent P2P group",
4269 return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq, ht40, vht,
4274 static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd)
4276 int freq = 0, ht40, vht;
4279 pos = os_strstr(cmd, "freq=");
4281 freq = atoi(pos + 5);
4283 vht = (os_strstr(cmd, "vht") != NULL) || wpa_s->conf->p2p_go_vht;
4284 ht40 = (os_strstr(cmd, "ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
4287 if (os_strncmp(cmd, "persistent=", 11) == 0)
4288 return p2p_ctrl_group_add_persistent(wpa_s, cmd + 11, freq,
4290 if (os_strcmp(cmd, "persistent") == 0 ||
4291 os_strncmp(cmd, "persistent ", 11) == 0)
4292 return wpas_p2p_group_add(wpa_s, 1, freq, ht40, vht);
4293 if (os_strncmp(cmd, "freq=", 5) == 0)
4294 return wpas_p2p_group_add(wpa_s, 0, freq, ht40, vht);
4296 return wpas_p2p_group_add(wpa_s, 0, freq, ht40, vht);
4298 wpa_printf(MSG_DEBUG, "CTRL: Invalid P2P_GROUP_ADD parameters '%s'",
4304 static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd,
4305 char *buf, size_t buflen)
4307 u8 addr[ETH_ALEN], *addr_ptr;
4309 const struct p2p_peer_info *info;
4311 char devtype[WPS_DEV_TYPE_BUFSIZE];
4312 struct wpa_ssid *ssid;
4315 if (!wpa_s->global->p2p)
4318 if (os_strcmp(cmd, "FIRST") == 0) {
4321 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
4322 if (hwaddr_aton(cmd + 5, addr) < 0)
4327 if (hwaddr_aton(cmd, addr) < 0)
4333 info = p2p_get_peer_info(wpa_s->global->p2p, addr_ptr, next);
4340 res = os_snprintf(pos, end - pos, MACSTR "\n"
4346 "serial_number=%s\n"
4347 "config_methods=0x%x\n"
4349 "group_capab=0x%x\n"
4351 MAC2STR(info->p2p_device_addr),
4352 wps_dev_type_bin2str(info->pri_dev_type,
4353 devtype, sizeof(devtype)),
4358 info->serial_number,
4359 info->config_methods,
4363 if (res < 0 || res >= end - pos)
4367 for (i = 0; i < info->wps_sec_dev_type_list_len / WPS_DEV_TYPE_LEN; i++)
4370 t = &info->wps_sec_dev_type_list[i * WPS_DEV_TYPE_LEN];
4371 res = os_snprintf(pos, end - pos, "sec_dev_type=%s\n",
4372 wps_dev_type_bin2str(t, devtype,
4374 if (res < 0 || res >= end - pos)
4379 ssid = wpas_p2p_get_persistent(wpa_s, info->p2p_device_addr, NULL, 0);
4381 res = os_snprintf(pos, end - pos, "persistent=%d\n", ssid->id);
4382 if (res < 0 || res >= end - pos)
4387 res = p2p_get_peer_info_txt(info, pos, end - pos);
4396 static int p2p_ctrl_disallow_freq(struct wpa_supplicant *wpa_s,
4401 if (wpa_s->global->p2p == NULL)
4404 if (freq_range_list_parse(&wpa_s->global->p2p_disallow_freq, param) < 0)
4407 for (i = 0; i < wpa_s->global->p2p_disallow_freq.num; i++) {
4408 struct wpa_freq_range *freq;
4409 freq = &wpa_s->global->p2p_disallow_freq.range[i];
4410 wpa_printf(MSG_DEBUG, "P2P: Disallowed frequency range %u-%u",
4411 freq->min, freq->max);
4414 wpas_p2p_update_channel_list(wpa_s);
4419 static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd)
4423 if (wpa_s->global->p2p == NULL)
4426 param = os_strchr(cmd, ' ');
4431 if (os_strcmp(cmd, "discoverability") == 0) {
4432 p2p_set_client_discoverability(wpa_s->global->p2p,
4437 if (os_strcmp(cmd, "managed") == 0) {
4438 p2p_set_managed_oper(wpa_s->global->p2p, atoi(param));
4442 if (os_strcmp(cmd, "listen_channel") == 0) {
4443 return p2p_set_listen_channel(wpa_s->global->p2p, 81,
4447 if (os_strcmp(cmd, "ssid_postfix") == 0) {
4448 return p2p_set_ssid_postfix(wpa_s->global->p2p, (u8 *) param,
4452 if (os_strcmp(cmd, "noa") == 0) {
4454 int count, start, duration;
4455 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
4456 count = atoi(param);
4457 pos = os_strchr(param, ',');
4462 pos = os_strchr(pos, ',');
4466 duration = atoi(pos);
4467 if (count < 0 || count > 255 || start < 0 || duration < 0)
4469 if (count == 0 && duration > 0)
4471 wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
4472 "start=%d duration=%d", count, start, duration);
4473 return wpas_p2p_set_noa(wpa_s, count, start, duration);
4476 if (os_strcmp(cmd, "ps") == 0)
4477 return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1);
4479 if (os_strcmp(cmd, "oppps") == 0)
4480 return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1);
4482 if (os_strcmp(cmd, "ctwindow") == 0)
4483 return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param));
4485 if (os_strcmp(cmd, "disabled") == 0) {
4486 wpa_s->global->p2p_disabled = atoi(param);
4487 wpa_printf(MSG_DEBUG, "P2P functionality %s",
4488 wpa_s->global->p2p_disabled ?
4489 "disabled" : "enabled");
4490 if (wpa_s->global->p2p_disabled) {
4491 wpas_p2p_stop_find(wpa_s);
4492 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
4493 p2p_flush(wpa_s->global->p2p);
4498 if (os_strcmp(cmd, "conc_pref") == 0) {
4499 if (os_strcmp(param, "sta") == 0)
4500 wpa_s->global->conc_pref = WPA_CONC_PREF_STA;
4501 else if (os_strcmp(param, "p2p") == 0)
4502 wpa_s->global->conc_pref = WPA_CONC_PREF_P2P;
4504 wpa_printf(MSG_INFO, "Invalid conc_pref value");
4507 wpa_printf(MSG_DEBUG, "Single channel concurrency preference: "
4512 if (os_strcmp(cmd, "force_long_sd") == 0) {
4513 wpa_s->force_long_sd = atoi(param);
4517 if (os_strcmp(cmd, "peer_filter") == 0) {
4519 if (hwaddr_aton(param, addr))
4521 p2p_set_peer_filter(wpa_s->global->p2p, addr);
4525 if (os_strcmp(cmd, "cross_connect") == 0)
4526 return wpas_p2p_set_cross_connect(wpa_s, atoi(param));
4528 if (os_strcmp(cmd, "go_apsd") == 0) {
4529 if (os_strcmp(param, "disable") == 0)
4530 wpa_s->set_ap_uapsd = 0;
4532 wpa_s->set_ap_uapsd = 1;
4533 wpa_s->ap_uapsd = atoi(param);
4538 if (os_strcmp(cmd, "client_apsd") == 0) {
4539 if (os_strcmp(param, "disable") == 0)
4540 wpa_s->set_sta_uapsd = 0;
4544 /* format: BE,BK,VI,VO;max SP Length */
4546 pos = os_strchr(param, ',');
4551 pos = os_strchr(pos, ',');
4556 pos = os_strchr(pos, ',');
4561 /* ignore max SP Length for now */
4563 wpa_s->set_sta_uapsd = 1;
4564 wpa_s->sta_uapsd = 0;
4566 wpa_s->sta_uapsd |= BIT(0);
4568 wpa_s->sta_uapsd |= BIT(1);
4570 wpa_s->sta_uapsd |= BIT(2);
4572 wpa_s->sta_uapsd |= BIT(3);
4577 if (os_strcmp(cmd, "disallow_freq") == 0)
4578 return p2p_ctrl_disallow_freq(wpa_s, param);
4580 if (os_strcmp(cmd, "disc_int") == 0) {
4581 int min_disc_int, max_disc_int, max_disc_tu;
4586 min_disc_int = atoi(pos);
4587 pos = os_strchr(pos, ' ');
4592 max_disc_int = atoi(pos);
4593 pos = os_strchr(pos, ' ');
4598 max_disc_tu = atoi(pos);
4600 return p2p_set_disc_int(wpa_s->global->p2p, min_disc_int,
4601 max_disc_int, max_disc_tu);
4604 if (os_strcmp(cmd, "per_sta_psk") == 0) {
4605 wpa_s->global->p2p_per_sta_psk = !!atoi(param);
4609 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
4616 static void p2p_ctrl_flush(struct wpa_supplicant *wpa_s)
4618 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
4619 wpa_s->force_long_sd = 0;
4620 if (wpa_s->global->p2p)
4621 p2p_flush(wpa_s->global->p2p);
4625 static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd)
4628 unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0;
4631 pos = os_strchr(cmd, ' ');
4637 pos2 = os_strchr(pos, ' ');
4645 pos = os_strchr(pos2, ' ');
4653 return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2);
4657 static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd)
4660 unsigned int period = 0, interval = 0;
4663 pos = os_strchr(cmd, ' ');
4668 interval = atoi(pos);
4671 return wpas_p2p_ext_listen(wpa_s, period, interval);
4675 static int p2p_ctrl_remove_client(struct wpa_supplicant *wpa_s, const char *cmd)
4682 if (os_strncmp(pos, "iface=", 6) == 0) {
4686 if (hwaddr_aton(pos, peer))
4689 wpas_p2p_remove_client(wpa_s, peer, iface_addr);
4693 #endif /* CONFIG_P2P */
4696 static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s, char *val)
4698 struct wpa_freq_range_list ranges;
4700 struct hostapd_hw_modes *mode;
4703 if (wpa_s->hw.modes == NULL)
4706 os_memset(&ranges, 0, sizeof(ranges));
4707 if (freq_range_list_parse(&ranges, val) < 0)
4710 for (i = 0; i < wpa_s->hw.num_modes; i++) {
4713 mode = &wpa_s->hw.modes[i];
4714 for (j = 0; j < mode->num_channels; j++) {
4717 if (mode->channels[j].flag & HOSTAPD_CHAN_DISABLED)
4720 freq = mode->channels[j].freq;
4721 if (!freq_range_list_includes(&ranges, freq))
4724 int_array_add_unique(&freqs, freq);
4728 os_free(ranges.range);
4733 #ifdef CONFIG_INTERWORKING
4735 static int ctrl_interworking_select(struct wpa_supplicant *wpa_s, char *param)
4743 auto_sel = os_strstr(param, "auto") != NULL;
4745 pos = os_strstr(param, "freq=");
4747 freqs = freq_range_to_channel_list(wpa_s, pos + 5);
4754 return interworking_select(wpa_s, auto_sel, freqs);
4758 static int ctrl_interworking_connect(struct wpa_supplicant *wpa_s, char *dst)
4761 struct wpa_bss *bss;
4763 if (hwaddr_aton(dst, bssid)) {
4764 wpa_printf(MSG_DEBUG, "Invalid BSSID '%s'", dst);
4768 bss = wpa_bss_get_bssid(wpa_s, bssid);
4770 wpa_printf(MSG_DEBUG, "Could not find BSS " MACSTR,
4775 return interworking_connect(wpa_s, bss);
4779 static int get_anqp(struct wpa_supplicant *wpa_s, char *dst)
4781 u8 dst_addr[ETH_ALEN];
4784 #define MAX_ANQP_INFO_ID 100
4785 u16 id[MAX_ANQP_INFO_ID];
4788 used = hwaddr_aton2(dst, dst_addr);
4792 while (num_id < MAX_ANQP_INFO_ID) {
4793 id[num_id] = atoi(pos);
4796 pos = os_strchr(pos + 1, ',');
4805 return anqp_send_req(wpa_s, dst_addr, id, num_id);
4809 static int gas_request(struct wpa_supplicant *wpa_s, char *cmd)
4811 u8 dst_addr[ETH_ALEN];
4812 struct wpabuf *advproto, *query = NULL;
4817 used = hwaddr_aton2(cmd, dst_addr);
4825 /* Advertisement Protocol ID */
4826 end = os_strchr(pos, ' ');
4830 len = os_strlen(pos);
4836 advproto = wpabuf_alloc(len);
4837 if (advproto == NULL)
4839 if (hexstr2bin(pos, wpabuf_put(advproto, len), len) < 0)
4843 /* Optional Query Request */
4848 len = os_strlen(pos);
4855 query = wpabuf_alloc(len);
4858 if (hexstr2bin(pos, wpabuf_put(query, len), len) < 0)
4863 ret = gas_send_request(wpa_s, dst_addr, advproto, query);
4866 wpabuf_free(advproto);
4873 static int gas_response_get(struct wpa_supplicant *wpa_s, char *cmd, char *buf,
4880 size_t resp_len, start, requested_len;
4881 struct wpabuf *resp;
4884 used = hwaddr_aton2(cmd, addr);
4891 dialog_token = atoi(pos);
4893 if (wpa_s->last_gas_resp &&
4894 os_memcmp(addr, wpa_s->last_gas_addr, ETH_ALEN) == 0 &&
4895 dialog_token == wpa_s->last_gas_dialog_token)
4896 resp = wpa_s->last_gas_resp;
4897 else if (wpa_s->prev_gas_resp &&
4898 os_memcmp(addr, wpa_s->prev_gas_addr, ETH_ALEN) == 0 &&
4899 dialog_token == wpa_s->prev_gas_dialog_token)
4900 resp = wpa_s->prev_gas_resp;
4904 resp_len = wpabuf_len(resp);
4906 requested_len = resp_len;
4908 pos = os_strchr(pos, ' ');
4911 if (start > resp_len)
4912 return os_snprintf(buf, buflen, "FAIL-Invalid range");
4913 pos = os_strchr(pos, ',');
4917 requested_len = atoi(pos);
4918 if (start + requested_len > resp_len)
4919 return os_snprintf(buf, buflen, "FAIL-Invalid range");
4922 if (requested_len * 2 + 1 > buflen)
4923 return os_snprintf(buf, buflen, "FAIL-Too long response");
4925 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(resp) + start,
4928 if (start + requested_len == resp_len) {
4930 * Free memory by dropping the response after it has been
4933 if (resp == wpa_s->prev_gas_resp) {
4934 wpabuf_free(wpa_s->prev_gas_resp);
4935 wpa_s->prev_gas_resp = NULL;
4937 wpabuf_free(wpa_s->last_gas_resp);
4938 wpa_s->last_gas_resp = NULL;
4944 #endif /* CONFIG_INTERWORKING */
4949 static int get_hs20_anqp(struct wpa_supplicant *wpa_s, char *dst)
4951 u8 dst_addr[ETH_ALEN];
4956 used = hwaddr_aton2(dst, dst_addr);
4961 int num = atoi(pos);
4962 if (num <= 0 || num > 31)
4964 subtypes |= BIT(num);
4965 pos = os_strchr(pos + 1, ',');
4974 return hs20_anqp_send_req(wpa_s, dst_addr, subtypes, NULL, 0);
4978 static int hs20_nai_home_realm_list(struct wpa_supplicant *wpa_s,
4979 const u8 *addr, const char *realm)
4985 rlen = os_strlen(realm);
4987 buf = os_malloc(len);
4990 buf[0] = 1; /* NAI Home Realm Count */
4991 buf[1] = 0; /* Formatted in accordance with RFC 4282 */
4993 os_memcpy(buf + 3, realm, rlen);
4995 ret = hs20_anqp_send_req(wpa_s, addr,
4996 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
5005 static int hs20_get_nai_home_realm_list(struct wpa_supplicant *wpa_s,
5008 struct wpa_cred *cred = wpa_s->conf->cred;
5009 u8 dst_addr[ETH_ALEN];
5015 used = hwaddr_aton2(dst, dst_addr);
5019 while (dst[used] == ' ')
5021 if (os_strncmp(dst + used, "realm=", 6) == 0)
5022 return hs20_nai_home_realm_list(wpa_s, dst_addr,
5025 len = os_strlen(dst + used);
5027 if (len == 0 && cred && cred->realm)
5028 return hs20_nai_home_realm_list(wpa_s, dst_addr, cred->realm);
5033 buf = os_malloc(len);
5036 if (hexstr2bin(dst + used, buf, len) < 0) {
5041 ret = hs20_anqp_send_req(wpa_s, dst_addr,
5042 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
5049 #endif /* CONFIG_HS20 */
5052 static int wpa_supplicant_ctrl_iface_sta_autoconnect(
5053 struct wpa_supplicant *wpa_s, char *cmd)
5055 wpa_s->auto_reconnect_disabled = atoi(cmd) == 0 ? 1 : 0;
5060 #ifdef CONFIG_AUTOSCAN
5062 static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant *wpa_s,
5065 enum wpa_states state = wpa_s->wpa_state;
5066 char *new_params = NULL;
5068 if (os_strlen(cmd) > 0) {
5069 new_params = os_strdup(cmd);
5070 if (new_params == NULL)
5074 os_free(wpa_s->conf->autoscan);
5075 wpa_s->conf->autoscan = new_params;
5077 if (wpa_s->conf->autoscan == NULL)
5078 autoscan_deinit(wpa_s);
5079 else if (state == WPA_DISCONNECTED || state == WPA_INACTIVE)
5080 autoscan_init(wpa_s, 1);
5081 else if (state == WPA_SCANNING)
5082 wpa_supplicant_reinit_autoscan(wpa_s);
5087 #endif /* CONFIG_AUTOSCAN */
5092 static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant *wpa_s, char *cmd)
5098 struct wpabuf *tfs_req = NULL;
5100 if (os_strncmp(cmd, "enter", 5) == 0)
5102 else if (os_strncmp(cmd, "exit", 4) == 0)
5107 pos = os_strstr(cmd, " interval=");
5109 intval = atoi(pos + 10);
5111 pos = os_strstr(cmd, " tfs_req=");
5116 end = os_strchr(pos, ' ');
5120 len = os_strlen(pos);
5124 tfs_req = wpabuf_alloc(len);
5125 if (tfs_req == NULL)
5127 if (hexstr2bin(pos, wpabuf_put(tfs_req, len), len) < 0) {
5128 wpabuf_free(tfs_req);
5133 ret = ieee802_11_send_wnmsleep_req(wpa_s, enter ? WNM_SLEEP_MODE_ENTER :
5134 WNM_SLEEP_MODE_EXIT, intval,
5136 wpabuf_free(tfs_req);
5142 static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant *wpa_s, char *cmd)
5146 query_reason = atoi(cmd);
5148 wpa_printf(MSG_DEBUG, "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d",
5151 return wnm_send_bss_transition_mgmt_query(wpa_s, query_reason);
5154 #endif /* CONFIG_WNM */
5157 /* Get string representation of channel width */
5158 static const char * channel_width_name(enum chan_width width)
5161 case CHAN_WIDTH_20_NOHT:
5162 return "20 MHz (no HT)";
5169 case CHAN_WIDTH_80P80:
5171 case CHAN_WIDTH_160:
5179 static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf,
5182 struct wpa_signal_info si;
5186 ret = wpa_drv_signal_poll(wpa_s, &si);
5193 ret = os_snprintf(pos, end - pos, "RSSI=%d\nLINKSPEED=%d\n"
5194 "NOISE=%d\nFREQUENCY=%u\n",
5195 si.current_signal, si.current_txrate / 1000,
5196 si.current_noise, si.frequency);
5197 if (ret < 0 || ret > end - pos)
5201 if (si.chanwidth != CHAN_WIDTH_UNKNOWN) {
5202 ret = os_snprintf(pos, end - pos, "WIDTH=%s\n",
5203 channel_width_name(si.chanwidth));
5204 if (ret < 0 || ret > end - pos)
5209 if (si.center_frq1 > 0 && si.center_frq2 > 0) {
5210 ret = os_snprintf(pos, end - pos,
5211 "CENTER_FRQ1=%d\nCENTER_FRQ2=%d\n",
5212 si.center_frq1, si.center_frq2);
5213 if (ret < 0 || ret > end - pos)
5218 if (si.avg_signal) {
5219 ret = os_snprintf(pos, end - pos,
5220 "AVG_RSSI=%d\n", si.avg_signal);
5221 if (ret < 0 || ret >= end - pos)
5230 static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant *wpa_s, char *buf,
5233 struct hostap_sta_driver_data sta;
5236 ret = wpa_drv_pktcnt_poll(wpa_s, &sta);
5240 ret = os_snprintf(buf, buflen, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
5241 sta.tx_packets, sta.tx_retry_failed, sta.rx_packets);
5242 if (ret < 0 || (size_t) ret > buflen)
5249 static int wpa_supplicant_driver_cmd(struct wpa_supplicant *wpa_s, char *cmd,
5250 char *buf, size_t buflen)
5254 ret = wpa_drv_driver_cmd(wpa_s, cmd, buf, buflen);
5256 if (os_strncasecmp(cmd, "COUNTRY", 7) == 0) {
5257 struct p2p_data *p2p = wpa_s->global->p2p;
5260 country[0] = cmd[8];
5261 country[1] = cmd[9];
5263 p2p_set_country(p2p, country);
5266 ret = os_snprintf(buf, buflen, "%s\n", "OK");
5270 #endif /* ANDROID */
5273 static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s)
5275 wpa_dbg(wpa_s, MSG_DEBUG, "Flush all wpa_supplicant state");
5278 wpas_p2p_stop_find(wpa_s);
5279 p2p_ctrl_flush(wpa_s);
5280 wpas_p2p_group_remove(wpa_s, "*");
5281 wpas_p2p_service_flush(wpa_s);
5282 wpa_s->global->p2p_disabled = 0;
5283 wpa_s->global->p2p_per_sta_psk = 0;
5284 wpa_s->conf->num_sec_device_types = 0;
5285 #endif /* CONFIG_P2P */
5287 #ifdef CONFIG_WPS_TESTING
5288 wps_version_number = 0x20;
5289 wps_testing_dummy_cred = 0;
5290 #endif /* CONFIG_WPS_TESTING */
5292 wpa_s->wps_fragment_size = 0;
5293 wpas_wps_cancel(wpa_s);
5294 #endif /* CONFIG_WPS */
5295 wpa_s->after_wps = 0;
5296 wpa_s->known_wps_freq = 0;
5299 #ifdef CONFIG_TDLS_TESTING
5300 extern unsigned int tdls_testing;
5302 #endif /* CONFIG_TDLS_TESTING */
5303 wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL);
5304 wpa_tdls_enable(wpa_s->wpa, 1);
5305 #endif /* CONFIG_TDLS */
5307 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, wpa_s, NULL);
5308 wpa_supplicant_stop_countermeasures(wpa_s, NULL);
5310 wpa_s->no_keep_alive = 0;
5312 os_free(wpa_s->disallow_aps_bssid);
5313 wpa_s->disallow_aps_bssid = NULL;
5314 wpa_s->disallow_aps_bssid_count = 0;
5315 os_free(wpa_s->disallow_aps_ssid);
5316 wpa_s->disallow_aps_ssid = NULL;
5317 wpa_s->disallow_aps_ssid_count = 0;
5319 wpa_s->set_sta_uapsd = 0;
5320 wpa_s->sta_uapsd = 0;
5322 wpa_drv_radio_disable(wpa_s, 0);
5324 wpa_bss_flush(wpa_s);
5325 wpa_blacklist_clear(wpa_s);
5326 wpa_s->extra_blacklist_count = 0;
5327 wpa_supplicant_ctrl_iface_remove_network(wpa_s, "all");
5328 wpa_supplicant_ctrl_iface_remove_cred(wpa_s, "all");
5329 wpa_config_flush_blobs(wpa_s->conf);
5330 wpa_s->conf->auto_interworking = 0;
5331 wpa_s->conf->okc = 0;
5332 wpa_s->conf->pmf = 0;
5334 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, 43200);
5335 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, 70);
5336 wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, 60);
5337 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
5339 radio_remove_unstarted_work(wpa_s, NULL);
5343 static int wpas_ctrl_radio_work_show(struct wpa_supplicant *wpa_s,
5344 char *buf, size_t buflen)
5346 struct wpa_radio_work *work;
5348 struct os_reltime now, diff;
5353 os_get_reltime(&now);
5355 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
5359 os_reltime_sub(&now, &work->time, &diff);
5360 ret = os_snprintf(pos, end - pos, "%s@%s:%u:%u:%ld.%06ld\n",
5361 work->type, work->wpa_s->ifname, work->freq,
5362 work->started, diff.sec, diff.usec);
5363 if (ret < 0 || ret >= end - pos)
5372 static void wpas_ctrl_radio_work_timeout(void *eloop_ctx, void *timeout_ctx)
5374 struct wpa_radio_work *work = eloop_ctx;
5375 struct wpa_external_work *ework = work->ctx;
5377 wpa_dbg(work->wpa_s, MSG_DEBUG,
5378 "Timing out external radio work %u (%s)",
5379 ework->id, work->type);
5380 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_TIMEOUT "%u", ework->id);
5382 radio_work_done(work);
5386 static void wpas_ctrl_radio_work_cb(struct wpa_radio_work *work, int deinit)
5388 struct wpa_external_work *ework = work->ctx;
5395 wpa_dbg(work->wpa_s, MSG_DEBUG, "Starting external radio work %u (%s)",
5396 ework->id, ework->type);
5397 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_START "%u", ework->id);
5398 if (!ework->timeout)
5399 ework->timeout = 10;
5400 eloop_register_timeout(ework->timeout, 0, wpas_ctrl_radio_work_timeout,
5405 static int wpas_ctrl_radio_work_add(struct wpa_supplicant *wpa_s, char *cmd,
5406 char *buf, size_t buflen)
5408 struct wpa_external_work *ework;
5412 unsigned int freq = 0;
5414 /* format: <name> [freq=<MHz>] [timeout=<seconds>] */
5416 ework = os_zalloc(sizeof(*ework));
5420 pos = os_strchr(cmd, ' ');
5422 type_len = pos - cmd;
5425 pos2 = os_strstr(pos, "freq=");
5427 freq = atoi(pos2 + 5);
5429 pos2 = os_strstr(pos, "timeout=");
5431 ework->timeout = atoi(pos2 + 8);
5433 type_len = os_strlen(cmd);
5435 if (4 + type_len >= sizeof(ework->type))
5436 type_len = sizeof(ework->type) - 4 - 1;
5437 os_strlcpy(ework->type, "ext:", sizeof(ework->type));
5438 os_memcpy(ework->type + 4, cmd, type_len);
5439 ework->type[4 + type_len] = '\0';
5441 wpa_s->ext_work_id++;
5442 if (wpa_s->ext_work_id == 0)
5443 wpa_s->ext_work_id++;
5444 ework->id = wpa_s->ext_work_id;
5446 if (radio_add_work(wpa_s, freq, ework->type, 0, wpas_ctrl_radio_work_cb,
5452 ret = os_snprintf(buf, buflen, "%u", ework->id);
5453 if (ret < 0 || (size_t) ret >= buflen)
5459 static int wpas_ctrl_radio_work_done(struct wpa_supplicant *wpa_s, char *cmd)
5461 struct wpa_radio_work *work;
5462 unsigned int id = atoi(cmd);
5464 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
5466 struct wpa_external_work *ework;
5468 if (os_strncmp(work->type, "ext:", 4) != 0)
5471 if (id && ework->id != id)
5473 wpa_dbg(wpa_s, MSG_DEBUG,
5474 "Completed external radio work %u (%s)",
5475 ework->id, ework->type);
5476 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, work, NULL);
5478 radio_work_done(work);
5479 return 3; /* "OK\n" */
5486 static int wpas_ctrl_radio_work(struct wpa_supplicant *wpa_s, char *cmd,
5487 char *buf, size_t buflen)
5489 if (os_strcmp(cmd, "show") == 0)
5490 return wpas_ctrl_radio_work_show(wpa_s, buf, buflen);
5491 if (os_strncmp(cmd, "add ", 4) == 0)
5492 return wpas_ctrl_radio_work_add(wpa_s, cmd + 4, buf, buflen);
5493 if (os_strncmp(cmd, "done ", 5) == 0)
5494 return wpas_ctrl_radio_work_done(wpa_s, cmd + 4);
5499 void wpas_ctrl_radio_work_flush(struct wpa_supplicant *wpa_s)
5501 struct wpa_radio_work *work, *tmp;
5503 if (!wpa_s || !wpa_s->radio)
5506 dl_list_for_each_safe(work, tmp, &wpa_s->radio->work,
5507 struct wpa_radio_work, list) {
5508 struct wpa_external_work *ework;
5510 if (os_strncmp(work->type, "ext:", 4) != 0)
5513 wpa_dbg(wpa_s, MSG_DEBUG,
5514 "Flushing %sexternal radio work %u (%s)",
5515 work->started ? " started" : "", ework->id,
5518 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
5521 radio_work_done(work);
5526 static void wpas_ctrl_eapol_response(void *eloop_ctx, void *timeout_ctx)
5528 struct wpa_supplicant *wpa_s = eloop_ctx;
5529 eapol_sm_notify_ctrl_response(wpa_s->eapol);
5533 static int set_scan_freqs(struct wpa_supplicant *wpa_s, char *val)
5537 freqs = freq_range_to_channel_list(wpa_s, val);
5541 os_free(wpa_s->manual_scan_freqs);
5542 wpa_s->manual_scan_freqs = freqs;
5548 static void wpas_ctrl_scan(struct wpa_supplicant *wpa_s, char *params,
5549 char *reply, int reply_size, int *reply_len)
5553 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
5558 wpa_s->manual_scan_passive = 0;
5559 wpa_s->manual_scan_use_id = 0;
5560 wpa_s->manual_scan_only_new = 0;
5563 if (os_strncasecmp(params, "TYPE=ONLY", 9) == 0)
5564 wpa_s->scan_res_handler = scan_only_handler;
5566 pos = os_strstr(params, "freq=");
5567 if (pos && set_scan_freqs(wpa_s, pos + 5) < 0) {
5572 pos = os_strstr(params, "passive=");
5574 wpa_s->manual_scan_passive = !!atoi(pos + 8);
5576 pos = os_strstr(params, "use_id=");
5578 wpa_s->manual_scan_use_id = atoi(pos + 7);
5580 pos = os_strstr(params, "only_new=1");
5582 wpa_s->manual_scan_only_new = 1;
5584 os_free(wpa_s->manual_scan_freqs);
5585 wpa_s->manual_scan_freqs = NULL;
5586 if (wpa_s->scan_res_handler == scan_only_handler)
5587 wpa_s->scan_res_handler = NULL;
5590 if (!wpa_s->sched_scanning && !wpa_s->scanning &&
5591 ((wpa_s->wpa_state <= WPA_SCANNING) ||
5592 (wpa_s->wpa_state == WPA_COMPLETED))) {
5593 wpa_s->normal_scans = 0;
5594 wpa_s->scan_req = MANUAL_SCAN_REQ;
5595 wpa_s->after_wps = 0;
5596 wpa_s->known_wps_freq = 0;
5597 wpa_supplicant_req_scan(wpa_s, 0, 0);
5598 if (wpa_s->manual_scan_use_id) {
5599 wpa_s->manual_scan_id++;
5600 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
5601 wpa_s->manual_scan_id);
5602 *reply_len = os_snprintf(reply, reply_size, "%u\n",
5603 wpa_s->manual_scan_id);
5605 } else if (wpa_s->sched_scanning) {
5606 wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to allow requested full scan to proceed");
5607 wpa_supplicant_cancel_sched_scan(wpa_s);
5608 wpa_s->scan_req = MANUAL_SCAN_REQ;
5609 wpa_supplicant_req_scan(wpa_s, 0, 0);
5610 if (wpa_s->manual_scan_use_id) {
5611 wpa_s->manual_scan_id++;
5612 *reply_len = os_snprintf(reply, reply_size, "%u\n",
5613 wpa_s->manual_scan_id);
5614 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
5615 wpa_s->manual_scan_id);
5618 wpa_printf(MSG_DEBUG, "Ongoing scan action - reject new request");
5619 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
5624 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
5625 char *buf, size_t *resp_len)
5628 const int reply_size = 4096;
5631 if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 ||
5632 os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
5633 if (wpa_debug_show_keys)
5634 wpa_dbg(wpa_s, MSG_DEBUG,
5635 "Control interface command '%s'", buf);
5637 wpa_dbg(wpa_s, MSG_DEBUG,
5638 "Control interface command '%s [REMOVED]'",
5639 os_strncmp(buf, WPA_CTRL_RSP,
5640 os_strlen(WPA_CTRL_RSP)) == 0 ?
5641 WPA_CTRL_RSP : "SET_NETWORK");
5642 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ", 16) == 0 ||
5643 os_strncmp(buf, "NFC_REPORT_HANDOVER", 19) == 0 ||
5644 os_strncmp(buf, "NFC_RX_HANDOVER_SEL", 19) == 0) {
5645 wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface",
5646 (const u8 *) buf, os_strlen(buf));
5648 int level = MSG_DEBUG;
5649 if (os_strcmp(buf, "PING") == 0)
5650 level = MSG_EXCESSIVE;
5651 wpa_dbg(wpa_s, level, "Control interface command '%s'", buf);
5654 reply = os_malloc(reply_size);
5655 if (reply == NULL) {
5660 os_memcpy(reply, "OK\n", 3);
5663 if (os_strcmp(buf, "PING") == 0) {
5664 os_memcpy(reply, "PONG\n", 5);
5666 } else if (os_strcmp(buf, "IFNAME") == 0) {
5667 reply_len = os_strlen(wpa_s->ifname);
5668 os_memcpy(reply, wpa_s->ifname, reply_len);
5669 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
5670 if (wpa_debug_reopen_file() < 0)
5672 } else if (os_strncmp(buf, "NOTE ", 5) == 0) {
5673 wpa_printf(MSG_INFO, "NOTE: %s", buf + 5);
5674 } else if (os_strcmp(buf, "MIB") == 0) {
5675 reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size);
5676 if (reply_len >= 0) {
5678 res = eapol_sm_get_mib(wpa_s->eapol, reply + reply_len,
5679 reply_size - reply_len);
5685 } else if (os_strncmp(buf, "STATUS", 6) == 0) {
5686 reply_len = wpa_supplicant_ctrl_iface_status(
5687 wpa_s, buf + 6, reply, reply_size);
5688 } else if (os_strcmp(buf, "PMKSA") == 0) {
5689 reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, reply,
5691 } else if (os_strncmp(buf, "SET ", 4) == 0) {
5692 if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4))
5694 } else if (os_strncmp(buf, "GET ", 4) == 0) {
5695 reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4,
5697 } else if (os_strcmp(buf, "LOGON") == 0) {
5698 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
5699 } else if (os_strcmp(buf, "LOGOFF") == 0) {
5700 eapol_sm_notify_logoff(wpa_s->eapol, TRUE);
5701 } else if (os_strcmp(buf, "REASSOCIATE") == 0) {
5702 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
5705 wpas_request_connection(wpa_s);
5706 } else if (os_strcmp(buf, "RECONNECT") == 0) {
5707 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
5709 else if (wpa_s->disconnected)
5710 wpas_request_connection(wpa_s);
5711 #ifdef IEEE8021X_EAPOL
5712 } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) {
5713 if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8))
5715 #endif /* IEEE8021X_EAPOL */
5716 #ifdef CONFIG_PEERKEY
5717 } else if (os_strncmp(buf, "STKSTART ", 9) == 0) {
5718 if (wpa_supplicant_ctrl_iface_stkstart(wpa_s, buf + 9))
5720 #endif /* CONFIG_PEERKEY */
5721 #ifdef CONFIG_IEEE80211R
5722 } else if (os_strncmp(buf, "FT_DS ", 6) == 0) {
5723 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6))
5725 #endif /* CONFIG_IEEE80211R */
5727 } else if (os_strcmp(buf, "WPS_PBC") == 0) {
5728 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL);
5730 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
5734 } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) {
5735 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8);
5737 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
5741 } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {
5742 reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8,
5745 } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) {
5746 reply_len = wpa_supplicant_ctrl_iface_wps_check_pin(
5747 wpa_s, buf + 14, reply, reply_size);
5748 } else if (os_strcmp(buf, "WPS_CANCEL") == 0) {
5749 if (wpas_wps_cancel(wpa_s))
5751 #ifdef CONFIG_WPS_NFC
5752 } else if (os_strcmp(buf, "WPS_NFC") == 0) {
5753 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, NULL))
5755 } else if (os_strncmp(buf, "WPS_NFC ", 8) == 0) {
5756 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, buf + 8))
5758 } else if (os_strncmp(buf, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
5759 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_config_token(
5760 wpa_s, buf + 21, reply, reply_size);
5761 } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) {
5762 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_token(
5763 wpa_s, buf + 14, reply, reply_size);
5764 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) {
5765 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s,
5768 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
5769 reply_len = wpas_ctrl_nfc_get_handover_req(
5770 wpa_s, buf + 21, reply, reply_size);
5771 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
5772 reply_len = wpas_ctrl_nfc_get_handover_sel(
5773 wpa_s, buf + 21, reply, reply_size);
5774 } else if (os_strncmp(buf, "NFC_RX_HANDOVER_REQ ", 20) == 0) {
5775 reply_len = wpas_ctrl_nfc_rx_handover_req(
5776 wpa_s, buf + 20, reply, reply_size);
5777 } else if (os_strncmp(buf, "NFC_RX_HANDOVER_SEL ", 20) == 0) {
5778 if (wpas_ctrl_nfc_rx_handover_sel(wpa_s, buf + 20))
5780 } else if (os_strncmp(buf, "NFC_REPORT_HANDOVER ", 20) == 0) {
5781 if (wpas_ctrl_nfc_report_handover(wpa_s, buf + 20))
5783 #endif /* CONFIG_WPS_NFC */
5784 } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) {
5785 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8))
5788 } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) {
5789 reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin(
5790 wpa_s, buf + 11, reply, reply_size);
5791 #endif /* CONFIG_AP */
5792 #ifdef CONFIG_WPS_ER
5793 } else if (os_strcmp(buf, "WPS_ER_START") == 0) {
5794 if (wpas_wps_er_start(wpa_s, NULL))
5796 } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) {
5797 if (wpas_wps_er_start(wpa_s, buf + 13))
5799 } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) {
5800 if (wpas_wps_er_stop(wpa_s))
5802 } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) {
5803 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11))
5805 } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) {
5806 int ret = wpas_wps_er_pbc(wpa_s, buf + 11);
5808 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
5810 } else if (ret == -3) {
5811 os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18);
5813 } else if (ret == -4) {
5814 os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20);
5818 } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) {
5819 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13))
5821 } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) {
5822 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s,
5825 } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) {
5826 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14))
5828 #ifdef CONFIG_WPS_NFC
5829 } else if (os_strncmp(buf, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
5830 reply_len = wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
5831 wpa_s, buf + 24, reply, reply_size);
5832 #endif /* CONFIG_WPS_NFC */
5833 #endif /* CONFIG_WPS_ER */
5834 #endif /* CONFIG_WPS */
5835 #ifdef CONFIG_IBSS_RSN
5836 } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) {
5837 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9))
5839 #endif /* CONFIG_IBSS_RSN */
5841 } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) {
5842 if (p2p_ctrl_find(wpa_s, buf + 9))
5844 } else if (os_strcmp(buf, "P2P_FIND") == 0) {
5845 if (p2p_ctrl_find(wpa_s, ""))
5847 } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) {
5848 wpas_p2p_stop_find(wpa_s);
5849 } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) {
5850 reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply,
5852 } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) {
5853 if (p2p_ctrl_listen(wpa_s, buf + 11))
5855 } else if (os_strcmp(buf, "P2P_LISTEN") == 0) {
5856 if (p2p_ctrl_listen(wpa_s, ""))
5858 } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) {
5859 if (wpas_p2p_group_remove(wpa_s, buf + 17))
5861 } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) {
5862 if (wpas_p2p_group_add(wpa_s, 0, 0, 0, 0))
5864 } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) {
5865 if (p2p_ctrl_group_add(wpa_s, buf + 14))
5867 } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) {
5868 if (p2p_ctrl_prov_disc(wpa_s, buf + 14))
5870 } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) {
5871 reply_len = p2p_get_passphrase(wpa_s, reply, reply_size);
5872 } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) {
5873 reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply,
5875 } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
5876 if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0)
5878 } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) {
5879 if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0)
5881 } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) {
5882 wpas_p2p_sd_service_update(wpa_s);
5883 } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
5884 if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0)
5886 } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) {
5887 wpas_p2p_service_flush(wpa_s);
5888 } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) {
5889 if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0)
5891 } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) {
5892 if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0)
5894 } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) {
5895 if (p2p_ctrl_reject(wpa_s, buf + 11) < 0)
5897 } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) {
5898 if (p2p_ctrl_invite(wpa_s, buf + 11) < 0)
5900 } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) {
5901 reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply,
5903 } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) {
5904 if (p2p_ctrl_set(wpa_s, buf + 8) < 0)
5906 } else if (os_strcmp(buf, "P2P_FLUSH") == 0) {
5907 p2p_ctrl_flush(wpa_s);
5908 } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) {
5909 if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0)
5911 } else if (os_strcmp(buf, "P2P_CANCEL") == 0) {
5912 if (wpas_p2p_cancel(wpa_s))
5914 } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) {
5915 if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0)
5917 } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) {
5918 if (p2p_ctrl_presence_req(wpa_s, "") < 0)
5920 } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) {
5921 if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0)
5923 } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) {
5924 if (p2p_ctrl_ext_listen(wpa_s, "") < 0)
5926 } else if (os_strncmp(buf, "P2P_REMOVE_CLIENT ", 18) == 0) {
5927 if (p2p_ctrl_remove_client(wpa_s, buf + 18) < 0)
5929 #endif /* CONFIG_P2P */
5930 #ifdef CONFIG_WIFI_DISPLAY
5931 } else if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0) {
5932 if (wifi_display_subelem_set(wpa_s->global, buf + 16) < 0)
5934 } else if (os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) {
5935 reply_len = wifi_display_subelem_get(wpa_s->global, buf + 16,
5937 #endif /* CONFIG_WIFI_DISPLAY */
5938 #ifdef CONFIG_INTERWORKING
5939 } else if (os_strcmp(buf, "FETCH_ANQP") == 0) {
5940 if (interworking_fetch_anqp(wpa_s) < 0)
5942 } else if (os_strcmp(buf, "STOP_FETCH_ANQP") == 0) {
5943 interworking_stop_fetch_anqp(wpa_s);
5944 } else if (os_strcmp(buf, "INTERWORKING_SELECT") == 0) {
5945 if (ctrl_interworking_select(wpa_s, NULL) < 0)
5947 } else if (os_strncmp(buf, "INTERWORKING_SELECT ", 20) == 0) {
5948 if (ctrl_interworking_select(wpa_s, buf + 20) < 0)
5950 } else if (os_strncmp(buf, "INTERWORKING_CONNECT ", 21) == 0) {
5951 if (ctrl_interworking_connect(wpa_s, buf + 21) < 0)
5953 } else if (os_strncmp(buf, "ANQP_GET ", 9) == 0) {
5954 if (get_anqp(wpa_s, buf + 9) < 0)
5956 } else if (os_strncmp(buf, "GAS_REQUEST ", 12) == 0) {
5957 if (gas_request(wpa_s, buf + 12) < 0)
5959 } else if (os_strncmp(buf, "GAS_RESPONSE_GET ", 17) == 0) {
5960 reply_len = gas_response_get(wpa_s, buf + 17, reply,
5962 #endif /* CONFIG_INTERWORKING */
5964 } else if (os_strncmp(buf, "HS20_ANQP_GET ", 14) == 0) {
5965 if (get_hs20_anqp(wpa_s, buf + 14) < 0)
5967 } else if (os_strncmp(buf, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
5968 if (hs20_get_nai_home_realm_list(wpa_s, buf + 29) < 0)
5970 #endif /* CONFIG_HS20 */
5971 } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0)
5973 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
5974 wpa_s, buf + os_strlen(WPA_CTRL_RSP)))
5978 * Notify response from timeout to allow the control
5979 * interface response to be sent first.
5981 eloop_register_timeout(0, 0, wpas_ctrl_eapol_response,
5984 } else if (os_strcmp(buf, "RECONFIGURE") == 0) {
5985 if (wpa_supplicant_reload_configuration(wpa_s))
5987 } else if (os_strcmp(buf, "TERMINATE") == 0) {
5988 wpa_supplicant_terminate_proc(wpa_s->global);
5989 } else if (os_strncmp(buf, "BSSID ", 6) == 0) {
5990 if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6))
5992 } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) {
5993 reply_len = wpa_supplicant_ctrl_iface_blacklist(
5994 wpa_s, buf + 9, reply, reply_size);
5995 } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) {
5996 reply_len = wpa_supplicant_ctrl_iface_log_level(
5997 wpa_s, buf + 9, reply, reply_size);
5998 } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) {
5999 reply_len = wpa_supplicant_ctrl_iface_list_networks(
6000 wpa_s, reply, reply_size);
6001 } else if (os_strcmp(buf, "DISCONNECT") == 0) {
6003 wpa_s->sme.prev_bssid_set = 0;
6004 #endif /* CONFIG_SME */
6005 wpa_s->reassociate = 0;
6006 wpa_s->disconnected = 1;
6007 wpa_supplicant_cancel_sched_scan(wpa_s);
6008 wpa_supplicant_cancel_scan(wpa_s);
6009 wpa_supplicant_deauthenticate(wpa_s,
6010 WLAN_REASON_DEAUTH_LEAVING);
6011 } else if (os_strcmp(buf, "SCAN") == 0) {
6012 wpas_ctrl_scan(wpa_s, NULL, reply, reply_size, &reply_len);
6013 } else if (os_strncmp(buf, "SCAN ", 5) == 0) {
6014 wpas_ctrl_scan(wpa_s, buf + 5, reply, reply_size, &reply_len);
6015 } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) {
6016 reply_len = wpa_supplicant_ctrl_iface_scan_results(
6017 wpa_s, reply, reply_size);
6018 } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) {
6019 if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15))
6021 } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) {
6022 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15))
6024 } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) {
6025 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16))
6027 } else if (os_strcmp(buf, "ADD_NETWORK") == 0) {
6028 reply_len = wpa_supplicant_ctrl_iface_add_network(
6029 wpa_s, reply, reply_size);
6030 } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) {
6031 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15))
6033 } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
6034 if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12))
6036 } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) {
6037 reply_len = wpa_supplicant_ctrl_iface_get_network(
6038 wpa_s, buf + 12, reply, reply_size);
6039 } else if (os_strcmp(buf, "LIST_CREDS") == 0) {
6040 reply_len = wpa_supplicant_ctrl_iface_list_creds(
6041 wpa_s, reply, reply_size);
6042 } else if (os_strcmp(buf, "ADD_CRED") == 0) {
6043 reply_len = wpa_supplicant_ctrl_iface_add_cred(
6044 wpa_s, reply, reply_size);
6045 } else if (os_strncmp(buf, "REMOVE_CRED ", 12) == 0) {
6046 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s, buf + 12))
6048 } else if (os_strncmp(buf, "SET_CRED ", 9) == 0) {
6049 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s, buf + 9))
6051 #ifndef CONFIG_NO_CONFIG_WRITE
6052 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
6053 if (wpa_supplicant_ctrl_iface_save_config(wpa_s))
6055 #endif /* CONFIG_NO_CONFIG_WRITE */
6056 } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
6057 reply_len = wpa_supplicant_ctrl_iface_get_capability(
6058 wpa_s, buf + 15, reply, reply_size);
6059 } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) {
6060 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8))
6062 } else if (os_strncmp(buf, "SCAN_INTERVAL ", 14) == 0) {
6063 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s, buf + 14))
6065 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
6066 reply_len = wpa_supplicant_global_iface_list(
6067 wpa_s->global, reply, reply_size);
6068 } else if (os_strcmp(buf, "INTERFACES") == 0) {
6069 reply_len = wpa_supplicant_global_iface_interfaces(
6070 wpa_s->global, reply, reply_size);
6071 } else if (os_strncmp(buf, "BSS ", 4) == 0) {
6072 reply_len = wpa_supplicant_ctrl_iface_bss(
6073 wpa_s, buf + 4, reply, reply_size);
6075 } else if (os_strcmp(buf, "STA-FIRST") == 0) {
6076 reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size);
6077 } else if (os_strncmp(buf, "STA ", 4) == 0) {
6078 reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply,
6080 } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) {
6081 reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply,
6083 } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) {
6084 if (ap_ctrl_iface_sta_deauthenticate(wpa_s, buf + 15))
6086 } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) {
6087 if (ap_ctrl_iface_sta_disassociate(wpa_s, buf + 13))
6089 } else if (os_strncmp(buf, "CHAN_SWITCH ", 12) == 0) {
6090 if (ap_ctrl_iface_chanswitch(wpa_s, buf + 12))
6092 #endif /* CONFIG_AP */
6093 } else if (os_strcmp(buf, "SUSPEND") == 0) {
6094 wpas_notify_suspend(wpa_s->global);
6095 } else if (os_strcmp(buf, "RESUME") == 0) {
6096 wpas_notify_resume(wpa_s->global);
6097 } else if (os_strcmp(buf, "DROP_SA") == 0) {
6098 wpa_supplicant_ctrl_iface_drop_sa(wpa_s);
6099 } else if (os_strncmp(buf, "ROAM ", 5) == 0) {
6100 if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5))
6102 } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) {
6103 if (wpa_supplicant_ctrl_iface_sta_autoconnect(wpa_s, buf + 16))
6105 } else if (os_strncmp(buf, "BSS_EXPIRE_AGE ", 15) == 0) {
6106 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s, buf + 15))
6108 } else if (os_strncmp(buf, "BSS_EXPIRE_COUNT ", 17) == 0) {
6109 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s,
6112 } else if (os_strncmp(buf, "BSS_FLUSH ", 10) == 0) {
6113 if (wpa_supplicant_ctrl_iface_bss_flush(wpa_s, buf + 10))
6116 } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) {
6117 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14))
6119 } else if (os_strncmp(buf, "TDLS_SETUP ", 11) == 0) {
6120 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s, buf + 11))
6122 } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) {
6123 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14))
6125 #endif /* CONFIG_TDLS */
6126 } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) {
6127 reply_len = wpa_supplicant_signal_poll(wpa_s, reply,
6129 } else if (os_strncmp(buf, "PKTCNT_POLL", 11) == 0) {
6130 reply_len = wpa_supplicant_pktcnt_poll(wpa_s, reply,
6132 #ifdef CONFIG_AUTOSCAN
6133 } else if (os_strncmp(buf, "AUTOSCAN ", 9) == 0) {
6134 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s, buf + 9))
6136 #endif /* CONFIG_AUTOSCAN */
6138 } else if (os_strncmp(buf, "DRIVER ", 7) == 0) {
6139 reply_len = wpa_supplicant_driver_cmd(wpa_s, buf + 7, reply,
6141 #endif /* ANDROID */
6142 } else if (os_strcmp(buf, "REAUTHENTICATE") == 0) {
6143 pmksa_cache_clear_current(wpa_s->wpa);
6144 eapol_sm_request_reauth(wpa_s->eapol);
6146 } else if (os_strncmp(buf, "WNM_SLEEP ", 10) == 0) {
6147 if (wpas_ctrl_iface_wnm_sleep(wpa_s, buf + 10))
6149 } else if (os_strncmp(buf, "WNM_BSS_QUERY ", 10) == 0) {
6150 if (wpas_ctrl_iface_wnm_bss_query(wpa_s, buf + 10))
6152 #endif /* CONFIG_WNM */
6153 } else if (os_strcmp(buf, "FLUSH") == 0) {
6154 wpa_supplicant_ctrl_iface_flush(wpa_s);
6155 } else if (os_strncmp(buf, "RADIO_WORK ", 11) == 0) {
6156 reply_len = wpas_ctrl_radio_work(wpa_s, buf + 11, reply,
6159 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
6163 if (reply_len < 0) {
6164 os_memcpy(reply, "FAIL\n", 5);
6168 *resp_len = reply_len;
6173 static int wpa_supplicant_global_iface_add(struct wpa_global *global,
6176 struct wpa_interface iface;
6180 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
6181 * TAB<bridge_ifname>
6183 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd);
6185 os_memset(&iface, 0, sizeof(iface));
6188 iface.ifname = pos = cmd;
6189 pos = os_strchr(pos, '\t');
6192 if (iface.ifname[0] == '\0')
6197 iface.confname = pos;
6198 pos = os_strchr(pos, '\t');
6201 if (iface.confname[0] == '\0')
6202 iface.confname = NULL;
6207 pos = os_strchr(pos, '\t');
6210 if (iface.driver[0] == '\0')
6211 iface.driver = NULL;
6215 iface.ctrl_interface = pos;
6216 pos = os_strchr(pos, '\t');
6219 if (iface.ctrl_interface[0] == '\0')
6220 iface.ctrl_interface = NULL;
6224 iface.driver_param = pos;
6225 pos = os_strchr(pos, '\t');
6228 if (iface.driver_param[0] == '\0')
6229 iface.driver_param = NULL;
6233 iface.bridge_ifname = pos;
6234 pos = os_strchr(pos, '\t');
6237 if (iface.bridge_ifname[0] == '\0')
6238 iface.bridge_ifname = NULL;
6243 if (wpa_supplicant_get_iface(global, iface.ifname))
6246 return wpa_supplicant_add_iface(global, &iface) ? 0 : -1;
6250 static int wpa_supplicant_global_iface_remove(struct wpa_global *global,
6253 struct wpa_supplicant *wpa_s;
6255 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd);
6257 wpa_s = wpa_supplicant_get_iface(global, cmd);
6260 return wpa_supplicant_remove_iface(global, wpa_s, 0);
6264 static void wpa_free_iface_info(struct wpa_interface_info *iface)
6266 struct wpa_interface_info *prev;
6270 iface = iface->next;
6272 os_free(prev->ifname);
6273 os_free(prev->desc);
6279 static int wpa_supplicant_global_iface_list(struct wpa_global *global,
6283 struct wpa_interface_info *iface = NULL, *last = NULL, *tmp;
6286 for (i = 0; wpa_drivers[i]; i++) {
6287 struct wpa_driver_ops *drv = wpa_drivers[i];
6288 if (drv->get_interfaces == NULL)
6290 tmp = drv->get_interfaces(global->drv_priv[i]);
6304 for (tmp = iface; tmp; tmp = tmp->next) {
6305 res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n",
6306 tmp->drv_name, tmp->ifname,
6307 tmp->desc ? tmp->desc : "");
6308 if (res < 0 || res >= end - pos) {
6315 wpa_free_iface_info(iface);
6321 static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
6326 struct wpa_supplicant *wpa_s;
6328 wpa_s = global->ifaces;
6333 res = os_snprintf(pos, end - pos, "%s\n", wpa_s->ifname);
6334 if (res < 0 || res >= end - pos) {
6339 wpa_s = wpa_s->next;
6345 static char * wpas_global_ctrl_iface_ifname(struct wpa_global *global,
6347 char *cmd, size_t *resp_len)
6349 struct wpa_supplicant *wpa_s;
6351 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
6352 if (os_strcmp(ifname, wpa_s->ifname) == 0)
6356 if (wpa_s == NULL) {
6357 char *resp = os_strdup("FAIL-NO-IFNAME-MATCH\n");
6359 *resp_len = os_strlen(resp);
6365 return wpa_supplicant_ctrl_iface_process(wpa_s, cmd, resp_len);
6369 static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global *global,
6370 char *buf, size_t *resp_len)
6373 static const char * cmd[] = {
6380 "P2P_GET_PASSPHRASE",
6381 "P2P_SERVICE_UPDATE",
6382 "P2P_SERVICE_FLUSH",
6389 static const char * prefix[] = {
6392 #endif /* ANDROID */
6399 "P2P_GROUP_REMOVE ",
6402 "P2P_SERV_DISC_REQ ",
6403 "P2P_SERV_DISC_CANCEL_REQ ",
6404 "P2P_SERV_DISC_RESP ",
6405 "P2P_SERV_DISC_EXTERNAL ",
6413 "P2P_PRESENCE_REQ ",
6415 "P2P_REMOVE_CLIENT ",
6421 if (global->p2p_init_wpa_s == NULL)
6424 for (i = 0; !found && cmd[i]; i++) {
6425 if (os_strcmp(buf, cmd[i]) == 0)
6429 for (i = 0; !found && prefix[i]; i++) {
6430 if (os_strncmp(buf, prefix[i], os_strlen(prefix[i])) == 0)
6435 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
6437 #endif /* CONFIG_P2P */
6442 static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global *global,
6443 char *buf, size_t *resp_len)
6445 #ifdef CONFIG_WIFI_DISPLAY
6446 if (global->p2p_init_wpa_s == NULL)
6448 if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0 ||
6449 os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0)
6450 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
6452 #endif /* CONFIG_WIFI_DISPLAY */
6457 static char * wpas_global_ctrl_iface_redir(struct wpa_global *global,
6458 char *buf, size_t *resp_len)
6462 ret = wpas_global_ctrl_iface_redir_p2p(global, buf, resp_len);
6466 ret = wpas_global_ctrl_iface_redir_wfd(global, buf, resp_len);
6474 static int wpas_global_ctrl_iface_set(struct wpa_global *global, char *cmd)
6478 value = os_strchr(cmd, ' ');
6483 wpa_printf(MSG_DEBUG, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd, value);
6485 #ifdef CONFIG_WIFI_DISPLAY
6486 if (os_strcasecmp(cmd, "wifi_display") == 0) {
6487 wifi_display_enable(global, !!atoi(value));
6490 #endif /* CONFIG_WIFI_DISPLAY */
6496 #ifndef CONFIG_NO_CONFIG_WRITE
6497 static int wpas_global_ctrl_iface_save_config(struct wpa_global *global)
6500 struct wpa_supplicant *wpa_s;
6502 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
6503 if (!wpa_s->conf->update_config) {
6504 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
6508 if (wpa_config_write(wpa_s->confname, wpa_s->conf)) {
6509 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
6512 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
6518 #endif /* CONFIG_NO_CONFIG_WRITE */
6521 static int wpas_global_ctrl_iface_status(struct wpa_global *global,
6522 char *buf, size_t buflen)
6526 struct wpa_supplicant *wpa_s;
6532 if (global->p2p && !global->p2p_disabled) {
6533 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
6536 MAC2STR(global->p2p_dev_addr),
6537 p2p_get_state_txt(global->p2p));
6538 if (ret < 0 || ret >= end - pos)
6541 } else if (global->p2p) {
6542 ret = os_snprintf(pos, end - pos, "p2p_state=DISABLED\n");
6543 if (ret < 0 || ret >= end - pos)
6547 #endif /* CONFIG_P2P */
6549 #ifdef CONFIG_WIFI_DISPLAY
6550 ret = os_snprintf(pos, end - pos, "wifi_display=%d\n",
6551 !!global->wifi_display);
6552 if (ret < 0 || ret >= end - pos)
6555 #endif /* CONFIG_WIFI_DISPLAY */
6557 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
6558 ret = os_snprintf(pos, end - pos, "ifname=%s\n"
6559 "address=" MACSTR "\n",
6560 wpa_s->ifname, MAC2STR(wpa_s->own_addr));
6561 if (ret < 0 || ret >= end - pos)
6570 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
6571 char *buf, size_t *resp_len)
6574 const int reply_size = 2048;
6576 int level = MSG_DEBUG;
6578 if (os_strncmp(buf, "IFNAME=", 7) == 0) {
6579 char *pos = os_strchr(buf + 7, ' ');
6582 return wpas_global_ctrl_iface_ifname(global,
6588 reply = wpas_global_ctrl_iface_redir(global, buf, resp_len);
6592 if (os_strcmp(buf, "PING") == 0)
6593 level = MSG_EXCESSIVE;
6594 wpa_hexdump_ascii(level, "RX global ctrl_iface",
6595 (const u8 *) buf, os_strlen(buf));
6597 reply = os_malloc(reply_size);
6598 if (reply == NULL) {
6603 os_memcpy(reply, "OK\n", 3);
6606 if (os_strcmp(buf, "PING") == 0) {
6607 os_memcpy(reply, "PONG\n", 5);
6609 } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) {
6610 if (wpa_supplicant_global_iface_add(global, buf + 14))
6612 } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) {
6613 if (wpa_supplicant_global_iface_remove(global, buf + 17))
6615 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
6616 reply_len = wpa_supplicant_global_iface_list(
6617 global, reply, reply_size);
6618 } else if (os_strcmp(buf, "INTERFACES") == 0) {
6619 reply_len = wpa_supplicant_global_iface_interfaces(
6620 global, reply, reply_size);
6621 } else if (os_strcmp(buf, "TERMINATE") == 0) {
6622 wpa_supplicant_terminate_proc(global);
6623 } else if (os_strcmp(buf, "SUSPEND") == 0) {
6624 wpas_notify_suspend(global);
6625 } else if (os_strcmp(buf, "RESUME") == 0) {
6626 wpas_notify_resume(global);
6627 } else if (os_strncmp(buf, "SET ", 4) == 0) {
6628 if (wpas_global_ctrl_iface_set(global, buf + 4))
6630 #ifndef CONFIG_NO_CONFIG_WRITE
6631 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
6632 if (wpas_global_ctrl_iface_save_config(global))
6634 #endif /* CONFIG_NO_CONFIG_WRITE */
6635 } else if (os_strcmp(buf, "STATUS") == 0) {
6636 reply_len = wpas_global_ctrl_iface_status(global, reply,
6639 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
6643 if (reply_len < 0) {
6644 os_memcpy(reply, "FAIL\n", 5);
6648 *resp_len = reply_len;