2 * WPA Supplicant / Control interface (shared code for all backends)
3 * Copyright (c) 2004-2013, 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 "common/version.h"
14 #include "common/ieee802_11_defs.h"
15 #include "common/ieee802_11_common.h"
16 #include "common/wpa_ctrl.h"
17 #include "eap_peer/eap.h"
18 #include "eapol_supp/eapol_supp_sm.h"
19 #include "rsn_supp/wpa.h"
20 #include "rsn_supp/preauth.h"
21 #include "rsn_supp/pmksa_cache.h"
22 #include "l2_packet/l2_packet.h"
25 #include "wpa_supplicant_i.h"
27 #include "wps_supplicant.h"
30 #include "p2p_supplicant.h"
32 #include "hs20_supplicant.h"
33 #include "wifi_display.h"
37 #include "ctrl_iface.h"
38 #include "interworking.h"
39 #include "blacklist.h"
43 extern struct wpa_driver_ops *wpa_drivers[];
45 static int wpa_supplicant_global_iface_list(struct wpa_global *global,
47 static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
51 static int pno_start(struct wpa_supplicant *wpa_s)
55 struct wpa_ssid *ssid;
56 struct wpa_driver_scan_params params;
61 if ((wpa_s->wpa_state > WPA_SCANNING) &&
62 (wpa_s->wpa_state <= WPA_COMPLETED)) {
63 wpa_printf(MSG_ERROR, "PNO: In assoc process");
67 if (wpa_s->wpa_state == WPA_SCANNING) {
68 wpa_supplicant_cancel_sched_scan(wpa_s);
69 wpa_supplicant_cancel_scan(wpa_s);
72 os_memset(¶ms, 0, sizeof(params));
75 ssid = wpa_s->conf->ssid;
77 if (!wpas_network_disabled(wpa_s, ssid))
81 if (num_ssid > WPAS_MAX_SCAN_SSIDS) {
82 wpa_printf(MSG_DEBUG, "PNO: Use only the first %u SSIDs from "
83 "%u", WPAS_MAX_SCAN_SSIDS, (unsigned int) num_ssid);
84 num_ssid = WPAS_MAX_SCAN_SSIDS;
88 wpa_printf(MSG_DEBUG, "PNO: No configured SSIDs");
92 params.filter_ssids = os_malloc(sizeof(struct wpa_driver_scan_filter) *
94 if (params.filter_ssids == NULL)
97 ssid = wpa_s->conf->ssid;
99 if (!wpas_network_disabled(wpa_s, ssid)) {
100 params.ssids[i].ssid = ssid->ssid;
101 params.ssids[i].ssid_len = ssid->ssid_len;
103 os_memcpy(params.filter_ssids[i].ssid, ssid->ssid,
105 params.filter_ssids[i].ssid_len = ssid->ssid_len;
106 params.num_filter_ssids++;
114 if (wpa_s->conf->filter_rssi)
115 params.filter_rssi = wpa_s->conf->filter_rssi;
117 interval = wpa_s->conf->sched_scan_interval ?
118 wpa_s->conf->sched_scan_interval : 10;
120 ret = wpa_supplicant_start_sched_scan(wpa_s, ¶ms, interval);
121 os_free(params.filter_ssids);
128 static int pno_stop(struct wpa_supplicant *wpa_s)
134 ret = wpa_supplicant_stop_sched_scan(wpa_s);
137 if (wpa_s->wpa_state == WPA_SCANNING)
138 wpa_supplicant_req_scan(wpa_s, 0, 0);
144 static int set_bssid_filter(struct wpa_supplicant *wpa_s, char *val)
147 u8 addr[ETH_ALEN], *filter = NULL, *n;
154 if (hwaddr_aton(pos, addr)) {
158 n = os_realloc_array(filter, count + 1, ETH_ALEN);
164 os_memcpy(filter + count * ETH_ALEN, addr, ETH_ALEN);
167 pos = os_strchr(pos, ' ');
172 wpa_hexdump(MSG_DEBUG, "bssid_filter", filter, count * ETH_ALEN);
173 os_free(wpa_s->bssid_filter);
174 wpa_s->bssid_filter = filter;
175 wpa_s->bssid_filter_count = count;
181 static int set_disallow_aps(struct wpa_supplicant *wpa_s, char *val)
184 u8 addr[ETH_ALEN], *bssid = NULL, *n;
185 struct wpa_ssid_value *ssid = NULL, *ns;
186 size_t count = 0, ssid_count = 0;
190 * disallow_list ::= <ssid_spec> | <bssid_spec> | <disallow_list> | ""
191 * SSID_SPEC ::= ssid <SSID_HEX>
192 * BSSID_SPEC ::= bssid <BSSID_HEX>
199 if (os_strncmp(pos, "bssid ", 6) == 0) {
202 res = hwaddr_aton2(pos, addr);
206 wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
207 "BSSID value '%s'", pos);
211 n = os_realloc_array(bssid, count + 1, ETH_ALEN);
218 os_memcpy(bssid + count * ETH_ALEN, addr, ETH_ALEN);
220 } else if (os_strncmp(pos, "ssid ", 5) == 0) {
226 if (*end == '\0' || *end == ' ')
231 ns = os_realloc_array(ssid, ssid_count + 1,
232 sizeof(struct wpa_ssid_value));
240 if ((end - pos) & 0x01 || end - pos > 2 * 32 ||
241 hexstr2bin(pos, ssid[ssid_count].ssid,
242 (end - pos) / 2) < 0) {
245 wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
246 "SSID value '%s'", pos);
249 ssid[ssid_count].ssid_len = (end - pos) / 2;
250 wpa_hexdump_ascii(MSG_DEBUG, "disallow_aps SSID",
251 ssid[ssid_count].ssid,
252 ssid[ssid_count].ssid_len);
256 wpa_printf(MSG_DEBUG, "Unexpected disallow_aps value "
263 pos = os_strchr(pos, ' ');
268 wpa_hexdump(MSG_DEBUG, "disallow_aps_bssid", bssid, count * ETH_ALEN);
269 os_free(wpa_s->disallow_aps_bssid);
270 wpa_s->disallow_aps_bssid = bssid;
271 wpa_s->disallow_aps_bssid_count = count;
273 wpa_printf(MSG_DEBUG, "disallow_aps_ssid_count %d", (int) ssid_count);
274 os_free(wpa_s->disallow_aps_ssid);
275 wpa_s->disallow_aps_ssid = ssid;
276 wpa_s->disallow_aps_ssid_count = ssid_count;
278 if (!wpa_s->current_ssid || wpa_s->wpa_state < WPA_AUTHENTICATING)
281 c = wpa_s->current_ssid;
282 if (c->mode != WPAS_MODE_INFRA && c->mode != WPAS_MODE_IBSS)
285 if (!disallowed_bssid(wpa_s, wpa_s->bssid) &&
286 !disallowed_ssid(wpa_s, c->ssid, c->ssid_len))
289 wpa_printf(MSG_DEBUG, "Disconnect and try to find another network "
290 "because current AP was marked disallowed");
293 wpa_s->sme.prev_bssid_set = 0;
294 #endif /* CONFIG_SME */
295 wpa_s->reassociate = 1;
296 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
297 wpa_supplicant_req_scan(wpa_s, 0, 0);
303 static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s,
309 value = os_strchr(cmd, ' ');
314 wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value);
315 if (os_strcasecmp(cmd, "EAPOL::heldPeriod") == 0) {
316 eapol_sm_configure(wpa_s->eapol,
317 atoi(value), -1, -1, -1);
318 } else if (os_strcasecmp(cmd, "EAPOL::authPeriod") == 0) {
319 eapol_sm_configure(wpa_s->eapol,
320 -1, atoi(value), -1, -1);
321 } else if (os_strcasecmp(cmd, "EAPOL::startPeriod") == 0) {
322 eapol_sm_configure(wpa_s->eapol,
323 -1, -1, atoi(value), -1);
324 } else if (os_strcasecmp(cmd, "EAPOL::maxStart") == 0) {
325 eapol_sm_configure(wpa_s->eapol,
326 -1, -1, -1, atoi(value));
327 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKLifetime") == 0) {
328 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME,
331 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKReauthThreshold") ==
333 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD,
336 } else if (os_strcasecmp(cmd, "dot11RSNAConfigSATimeout") == 0) {
337 if (wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, atoi(value)))
339 } else if (os_strcasecmp(cmd, "wps_fragment_size") == 0) {
340 wpa_s->wps_fragment_size = atoi(value);
341 #ifdef CONFIG_WPS_TESTING
342 } else if (os_strcasecmp(cmd, "wps_version_number") == 0) {
344 val = strtol(value, NULL, 0);
345 if (val < 0 || val > 0xff) {
347 wpa_printf(MSG_DEBUG, "WPS: Invalid "
348 "wps_version_number %ld", val);
350 wps_version_number = val;
351 wpa_printf(MSG_DEBUG, "WPS: Testing - force WPS "
353 (wps_version_number & 0xf0) >> 4,
354 wps_version_number & 0x0f);
356 } else if (os_strcasecmp(cmd, "wps_testing_dummy_cred") == 0) {
357 wps_testing_dummy_cred = atoi(value);
358 wpa_printf(MSG_DEBUG, "WPS: Testing - dummy_cred=%d",
359 wps_testing_dummy_cred);
360 #endif /* CONFIG_WPS_TESTING */
361 } else if (os_strcasecmp(cmd, "ampdu") == 0) {
362 if (wpa_drv_ampdu(wpa_s, atoi(value)) < 0)
364 #ifdef CONFIG_TDLS_TESTING
365 } else if (os_strcasecmp(cmd, "tdls_testing") == 0) {
366 extern unsigned int tdls_testing;
367 tdls_testing = strtol(value, NULL, 0);
368 wpa_printf(MSG_DEBUG, "TDLS: tdls_testing=0x%x", tdls_testing);
369 #endif /* CONFIG_TDLS_TESTING */
371 } else if (os_strcasecmp(cmd, "tdls_disabled") == 0) {
372 int disabled = atoi(value);
373 wpa_printf(MSG_DEBUG, "TDLS: tdls_disabled=%d", disabled);
375 if (wpa_drv_tdls_oper(wpa_s, TDLS_DISABLE, NULL) < 0)
377 } else if (wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL) < 0)
379 wpa_tdls_enable(wpa_s->wpa, !disabled);
380 #endif /* CONFIG_TDLS */
381 } else if (os_strcasecmp(cmd, "pno") == 0) {
383 ret = pno_start(wpa_s);
385 ret = pno_stop(wpa_s);
386 } else if (os_strcasecmp(cmd, "radio_disabled") == 0) {
387 int disabled = atoi(value);
388 if (wpa_drv_radio_disable(wpa_s, disabled) < 0)
391 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
392 } else if (os_strcasecmp(cmd, "uapsd") == 0) {
393 if (os_strcmp(value, "disable") == 0)
394 wpa_s->set_sta_uapsd = 0;
398 /* format: BE,BK,VI,VO;max SP Length */
400 pos = os_strchr(value, ',');
405 pos = os_strchr(pos, ',');
410 pos = os_strchr(pos, ',');
415 /* ignore max SP Length for now */
417 wpa_s->set_sta_uapsd = 1;
418 wpa_s->sta_uapsd = 0;
420 wpa_s->sta_uapsd |= BIT(0);
422 wpa_s->sta_uapsd |= BIT(1);
424 wpa_s->sta_uapsd |= BIT(2);
426 wpa_s->sta_uapsd |= BIT(3);
428 } else if (os_strcasecmp(cmd, "ps") == 0) {
429 ret = wpa_drv_set_p2p_powersave(wpa_s, atoi(value), -1, -1);
430 #ifdef CONFIG_WIFI_DISPLAY
431 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
432 wifi_display_enable(wpa_s->global, !!atoi(value));
433 #endif /* CONFIG_WIFI_DISPLAY */
434 } else if (os_strcasecmp(cmd, "bssid_filter") == 0) {
435 ret = set_bssid_filter(wpa_s, value);
436 } else if (os_strcasecmp(cmd, "disallow_aps") == 0) {
437 ret = set_disallow_aps(wpa_s, value);
438 } else if (os_strcasecmp(cmd, "no_keep_alive") == 0) {
439 wpa_s->no_keep_alive = !!atoi(value);
442 ret = wpa_config_process_global(wpa_s->conf, cmd, -1);
444 wpa_supplicant_update_config(wpa_s);
451 static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s,
452 char *cmd, char *buf, size_t buflen)
456 wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd);
458 if (os_strcmp(cmd, "version") == 0) {
459 res = os_snprintf(buf, buflen, "%s", VERSION_STR);
460 } else if (os_strcasecmp(cmd, "country") == 0) {
461 if (wpa_s->conf->country[0] && wpa_s->conf->country[1])
462 res = os_snprintf(buf, buflen, "%c%c",
463 wpa_s->conf->country[0],
464 wpa_s->conf->country[1]);
465 #ifdef CONFIG_WIFI_DISPLAY
466 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
467 res = os_snprintf(buf, buflen, "%d",
468 wpa_s->global->wifi_display);
469 if (res < 0 || (unsigned int) res >= buflen)
472 #endif /* CONFIG_WIFI_DISPLAY */
473 #ifdef CONFIG_TESTING_GET_GTK
474 } else if (os_strcmp(cmd, "gtk") == 0) {
475 if (wpa_s->last_gtk_len == 0)
477 res = wpa_snprintf_hex(buf, buflen, wpa_s->last_gtk,
478 wpa_s->last_gtk_len);
480 #endif /* CONFIG_TESTING_GET_GTK */
483 if (res < 0 || (unsigned int) res >= buflen)
489 #ifdef IEEE8021X_EAPOL
490 static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s,
494 struct wpa_ssid *ssid = wpa_s->current_ssid;
496 if (hwaddr_aton(addr, bssid)) {
497 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address "
502 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid));
503 rsn_preauth_deinit(wpa_s->wpa);
504 if (rsn_preauth_init(wpa_s->wpa, bssid, ssid ? &ssid->eap : NULL))
509 #endif /* IEEE8021X_EAPOL */
512 #ifdef CONFIG_PEERKEY
513 /* MLME-STKSTART.request(peer) */
514 static int wpa_supplicant_ctrl_iface_stkstart(
515 struct wpa_supplicant *wpa_s, char *addr)
519 if (hwaddr_aton(addr, peer)) {
520 wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART: invalid "
521 "address '%s'", addr);
525 wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART " MACSTR,
528 return wpa_sm_stkstart(wpa_s->wpa, peer);
530 #endif /* CONFIG_PEERKEY */
535 static int wpa_supplicant_ctrl_iface_tdls_discover(
536 struct wpa_supplicant *wpa_s, char *addr)
541 if (hwaddr_aton(addr, peer)) {
542 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER: invalid "
543 "address '%s'", addr);
547 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER " MACSTR,
550 if (wpa_tdls_is_external_setup(wpa_s->wpa))
551 ret = wpa_tdls_send_discovery_request(wpa_s->wpa, peer);
553 ret = wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer);
559 static int wpa_supplicant_ctrl_iface_tdls_setup(
560 struct wpa_supplicant *wpa_s, char *addr)
565 if (hwaddr_aton(addr, peer)) {
566 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP: invalid "
567 "address '%s'", addr);
571 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP " MACSTR,
574 if ((wpa_s->conf->tdls_external_control) &&
575 wpa_tdls_is_external_setup(wpa_s->wpa))
576 return wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
578 wpa_tdls_remove(wpa_s->wpa, peer);
580 if (wpa_tdls_is_external_setup(wpa_s->wpa))
581 ret = wpa_tdls_start(wpa_s->wpa, peer);
583 ret = wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
589 static int wpa_supplicant_ctrl_iface_tdls_teardown(
590 struct wpa_supplicant *wpa_s, char *addr)
595 if (hwaddr_aton(addr, peer)) {
596 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN: invalid "
597 "address '%s'", addr);
601 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN " MACSTR,
604 if ((wpa_s->conf->tdls_external_control) &&
605 wpa_tdls_is_external_setup(wpa_s->wpa))
606 return wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
608 if (wpa_tdls_is_external_setup(wpa_s->wpa))
609 ret = wpa_tdls_teardown_link(
611 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED);
613 ret = wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
618 #endif /* CONFIG_TDLS */
621 #ifdef CONFIG_IEEE80211R
622 static int wpa_supplicant_ctrl_iface_ft_ds(
623 struct wpa_supplicant *wpa_s, char *addr)
625 u8 target_ap[ETH_ALEN];
629 if (hwaddr_aton(addr, target_ap)) {
630 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid "
631 "address '%s'", addr);
635 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap));
637 bss = wpa_bss_get_bssid(wpa_s, target_ap);
639 mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN);
643 return wpa_ft_start_over_ds(wpa_s->wpa, target_ap, mdie);
645 #endif /* CONFIG_IEEE80211R */
649 static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s,
652 u8 bssid[ETH_ALEN], *_bssid = bssid;
654 u8 p2p_dev_addr[ETH_ALEN];
655 #endif /* CONFIG_P2P */
657 u8 *_p2p_dev_addr = NULL;
658 #endif /* CONFIG_AP */
660 if (cmd == NULL || os_strcmp(cmd, "any") == 0) {
663 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
664 if (hwaddr_aton(cmd + 13, p2p_dev_addr)) {
665 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid "
666 "P2P Device Address '%s'",
670 _p2p_dev_addr = p2p_dev_addr;
671 #endif /* CONFIG_P2P */
672 } else if (hwaddr_aton(cmd, bssid)) {
673 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
680 return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid, _p2p_dev_addr);
681 #endif /* CONFIG_AP */
683 return wpas_wps_start_pbc(wpa_s, _bssid, 0);
687 static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s,
688 char *cmd, char *buf,
691 u8 bssid[ETH_ALEN], *_bssid = bssid;
695 pin = os_strchr(cmd, ' ');
699 if (os_strcmp(cmd, "any") == 0)
701 else if (os_strcmp(cmd, "get") == 0) {
702 ret = wps_generate_pin();
704 } else if (hwaddr_aton(cmd, bssid)) {
705 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
711 if (wpa_s->ap_iface) {
716 pos = os_strchr(pin, ' ');
723 return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin,
724 buf, buflen, timeout);
726 #endif /* CONFIG_AP */
729 ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0,
733 ret = os_snprintf(buf, buflen, "%s", pin);
734 if (ret < 0 || (size_t) ret >= buflen)
739 ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0, DEV_PW_DEFAULT);
744 /* Return the generated PIN */
745 ret = os_snprintf(buf, buflen, "%08d", ret);
746 if (ret < 0 || (size_t) ret >= buflen)
752 static int wpa_supplicant_ctrl_iface_wps_check_pin(
753 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
760 wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN",
761 (u8 *) cmd, os_strlen(cmd));
762 for (pos = cmd, len = 0; *pos != '\0'; pos++) {
763 if (*pos < '0' || *pos > '9')
767 wpa_printf(MSG_DEBUG, "WPS: Too long PIN");
771 if (len != 4 && len != 8) {
772 wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len);
778 unsigned int pin_val;
780 if (!wps_pin_valid(pin_val)) {
781 wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit");
782 ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n");
783 if (ret < 0 || (size_t) ret >= buflen)
789 ret = os_snprintf(buf, buflen, "%s", pin);
790 if (ret < 0 || (size_t) ret >= buflen)
797 #ifdef CONFIG_WPS_NFC
799 static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant *wpa_s,
802 u8 bssid[ETH_ALEN], *_bssid = bssid;
804 if (cmd == NULL || cmd[0] == '\0')
806 else if (hwaddr_aton(cmd, bssid))
809 return wpas_wps_start_nfc(wpa_s, _bssid);
813 static int wpa_supplicant_ctrl_iface_wps_nfc_config_token(
814 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
821 pos = os_strchr(cmd, ' ');
824 if (os_strcmp(cmd, "WPS") == 0)
826 else if (os_strcmp(cmd, "NDEF") == 0)
831 buf = wpas_wps_nfc_config_token(wpa_s, ndef, pos);
835 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
846 static int wpa_supplicant_ctrl_iface_wps_nfc_token(
847 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
853 if (os_strcmp(cmd, "WPS") == 0)
855 else if (os_strcmp(cmd, "NDEF") == 0)
860 buf = wpas_wps_nfc_token(wpa_s, ndef);
864 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
875 static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
876 struct wpa_supplicant *wpa_s, char *pos)
882 len = os_strlen(pos);
887 buf = wpabuf_alloc(len);
890 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
895 ret = wpas_wps_nfc_tag_read(wpa_s, buf);
902 static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant *wpa_s,
903 char *reply, size_t max_len,
909 buf = wpas_wps_nfc_handover_req(wpa_s, cr);
913 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
924 static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant *wpa_s,
925 char *cmd, char *reply,
930 pos = os_strchr(cmd, ' ');
935 if (os_strcmp(cmd, "NDEF") != 0)
938 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
939 return wpas_ctrl_nfc_get_handover_req_wps(
940 wpa_s, reply, max_len, os_strcmp(pos, "WPS-CR") == 0);
947 static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant *wpa_s,
948 char *reply, size_t max_len,
949 int ndef, int cr, char *uuid)
954 buf = wpas_wps_nfc_handover_sel(wpa_s, ndef, cr, uuid);
958 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
969 static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant *wpa_s,
970 char *cmd, char *reply,
976 pos = os_strchr(cmd, ' ');
981 if (os_strcmp(cmd, "WPS") == 0)
983 else if (os_strcmp(cmd, "NDEF") == 0)
988 pos2 = os_strchr(pos, ' ');
991 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
992 return wpas_ctrl_nfc_get_handover_sel_wps(
993 wpa_s, reply, max_len, ndef,
994 os_strcmp(pos, "WPS-CR") == 0, pos2);
1001 static int wpas_ctrl_nfc_rx_handover_req(struct wpa_supplicant *wpa_s,
1002 char *cmd, char *reply,
1009 len = os_strlen(cmd);
1014 buf = wpabuf_alloc(len);
1017 if (hexstr2bin(cmd, wpabuf_put(buf, len), len) < 0) {
1022 ret = wpas_wps_nfc_rx_handover_req(wpa_s, buf);
1029 static int wpas_ctrl_nfc_rx_handover_sel(struct wpa_supplicant *wpa_s,
1036 len = os_strlen(cmd);
1041 buf = wpabuf_alloc(len);
1044 if (hexstr2bin(cmd, wpabuf_put(buf, len), len) < 0) {
1049 ret = wpas_wps_nfc_rx_handover_sel(wpa_s, buf);
1056 static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant *wpa_s,
1060 struct wpabuf *req, *sel;
1062 char *pos, *role, *type, *pos2;
1065 pos = os_strchr(role, ' ');
1071 pos = os_strchr(type, ' ');
1076 pos2 = os_strchr(pos, ' ');
1081 len = os_strlen(pos);
1086 req = wpabuf_alloc(len);
1089 if (hexstr2bin(pos, wpabuf_put(req, len), len) < 0) {
1094 len = os_strlen(pos2);
1101 sel = wpabuf_alloc(len);
1106 if (hexstr2bin(pos2, wpabuf_put(sel, len), len) < 0) {
1112 if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "WPS") == 0) {
1113 ret = wpas_wps_nfc_report_handover(wpa_s, req, sel);
1115 wpa_printf(MSG_DEBUG, "NFC: Unsupported connection handover "
1116 "reported: role=%s type=%s", role, type);
1125 #endif /* CONFIG_WPS_NFC */
1128 static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s,
1137 struct wps_new_ap_settings ap;
1139 pin = os_strchr(cmd, ' ');
1144 if (hwaddr_aton(cmd, bssid)) {
1145 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
1150 new_ssid = os_strchr(pin, ' ');
1151 if (new_ssid == NULL)
1152 return wpas_wps_start_reg(wpa_s, bssid, pin, NULL);
1155 new_auth = os_strchr(new_ssid, ' ');
1156 if (new_auth == NULL)
1160 new_encr = os_strchr(new_auth, ' ');
1161 if (new_encr == NULL)
1165 new_key = os_strchr(new_encr, ' ');
1166 if (new_key == NULL)
1170 os_memset(&ap, 0, sizeof(ap));
1171 ap.ssid_hex = new_ssid;
1174 ap.key_hex = new_key;
1175 return wpas_wps_start_reg(wpa_s, bssid, pin, &ap);
1180 static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant *wpa_s,
1181 char *cmd, char *buf,
1186 const char *pin_txt;
1188 if (!wpa_s->ap_iface)
1191 pos = os_strchr(cmd, ' ');
1195 if (os_strcmp(cmd, "disable") == 0) {
1196 wpas_wps_ap_pin_disable(wpa_s);
1197 return os_snprintf(buf, buflen, "OK\n");
1200 if (os_strcmp(cmd, "random") == 0) {
1202 timeout = atoi(pos);
1203 pin_txt = wpas_wps_ap_pin_random(wpa_s, timeout);
1204 if (pin_txt == NULL)
1206 return os_snprintf(buf, buflen, "%s", pin_txt);
1209 if (os_strcmp(cmd, "get") == 0) {
1210 pin_txt = wpas_wps_ap_pin_get(wpa_s);
1211 if (pin_txt == NULL)
1213 return os_snprintf(buf, buflen, "%s", pin_txt);
1216 if (os_strcmp(cmd, "set") == 0) {
1221 pos = os_strchr(pos, ' ');
1224 timeout = atoi(pos);
1226 if (os_strlen(pin) > buflen)
1228 if (wpas_wps_ap_pin_set(wpa_s, pin, timeout) < 0)
1230 return os_snprintf(buf, buflen, "%s", pin);
1235 #endif /* CONFIG_AP */
1238 #ifdef CONFIG_WPS_ER
1239 static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant *wpa_s,
1242 char *uuid = cmd, *pin, *pos;
1243 u8 addr_buf[ETH_ALEN], *addr = NULL;
1244 pin = os_strchr(uuid, ' ');
1248 pos = os_strchr(pin, ' ');
1251 if (hwaddr_aton(pos, addr_buf) == 0)
1254 return wpas_wps_er_add_pin(wpa_s, addr, uuid, pin);
1258 static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant *wpa_s,
1261 char *uuid = cmd, *pin;
1262 pin = os_strchr(uuid, ' ');
1266 return wpas_wps_er_learn(wpa_s, uuid, pin);
1270 static int wpa_supplicant_ctrl_iface_wps_er_set_config(
1271 struct wpa_supplicant *wpa_s, char *cmd)
1273 char *uuid = cmd, *id;
1274 id = os_strchr(uuid, ' ');
1278 return wpas_wps_er_set_config(wpa_s, uuid, atoi(id));
1282 static int wpa_supplicant_ctrl_iface_wps_er_config(
1283 struct wpa_supplicant *wpa_s, char *cmd)
1290 struct wps_new_ap_settings ap;
1292 pin = os_strchr(cmd, ' ');
1297 new_ssid = os_strchr(pin, ' ');
1298 if (new_ssid == NULL)
1302 new_auth = os_strchr(new_ssid, ' ');
1303 if (new_auth == NULL)
1307 new_encr = os_strchr(new_auth, ' ');
1308 if (new_encr == NULL)
1312 new_key = os_strchr(new_encr, ' ');
1313 if (new_key == NULL)
1317 os_memset(&ap, 0, sizeof(ap));
1318 ap.ssid_hex = new_ssid;
1321 ap.key_hex = new_key;
1322 return wpas_wps_er_config(wpa_s, cmd, pin, &ap);
1326 #ifdef CONFIG_WPS_NFC
1327 static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
1328 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1335 uuid = os_strchr(cmd, ' ');
1340 if (os_strcmp(cmd, "WPS") == 0)
1342 else if (os_strcmp(cmd, "NDEF") == 0)
1347 buf = wpas_wps_er_nfc_config_token(wpa_s, ndef, uuid);
1351 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1353 reply[res++] = '\n';
1360 #endif /* CONFIG_WPS_NFC */
1361 #endif /* CONFIG_WPS_ER */
1363 #endif /* CONFIG_WPS */
1366 #ifdef CONFIG_IBSS_RSN
1367 static int wpa_supplicant_ctrl_iface_ibss_rsn(
1368 struct wpa_supplicant *wpa_s, char *addr)
1372 if (hwaddr_aton(addr, peer)) {
1373 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN: invalid "
1374 "address '%s'", addr);
1378 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN " MACSTR,
1381 return ibss_rsn_start(wpa_s->ibss_rsn, peer);
1383 #endif /* CONFIG_IBSS_RSN */
1386 static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s,
1389 #ifdef IEEE8021X_EAPOL
1392 struct wpa_ssid *ssid;
1394 pos = os_strchr(rsp, '-');
1399 pos = os_strchr(pos, ':');
1404 wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id);
1405 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
1406 (u8 *) pos, os_strlen(pos));
1408 ssid = wpa_config_get_network(wpa_s->conf, id);
1410 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
1415 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s, ssid, rsp,
1417 #else /* IEEE8021X_EAPOL */
1418 wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included");
1420 #endif /* IEEE8021X_EAPOL */
1424 static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
1426 char *buf, size_t buflen)
1428 char *pos, *end, tmp[30];
1429 int res, verbose, wps, ret;
1431 if (os_strcmp(params, "-DRIVER") == 0)
1432 return wpa_drv_status(wpa_s, buf, buflen);
1433 verbose = os_strcmp(params, "-VERBOSE") == 0;
1434 wps = os_strcmp(params, "-WPS") == 0;
1437 if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
1438 struct wpa_ssid *ssid = wpa_s->current_ssid;
1439 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
1440 MAC2STR(wpa_s->bssid));
1441 if (ret < 0 || ret >= end - pos)
1445 u8 *_ssid = ssid->ssid;
1446 size_t ssid_len = ssid->ssid_len;
1447 u8 ssid_buf[MAX_SSID_LEN];
1448 if (ssid_len == 0) {
1449 int _res = wpa_drv_get_ssid(wpa_s, ssid_buf);
1456 ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n",
1457 wpa_ssid_txt(_ssid, ssid_len),
1459 if (ret < 0 || ret >= end - pos)
1463 if (wps && ssid->passphrase &&
1464 wpa_key_mgmt_wpa_psk(ssid->key_mgmt) &&
1465 (ssid->mode == WPAS_MODE_AP ||
1466 ssid->mode == WPAS_MODE_P2P_GO)) {
1467 ret = os_snprintf(pos, end - pos,
1470 if (ret < 0 || ret >= end - pos)
1475 ret = os_snprintf(pos, end - pos,
1478 if (ret < 0 || ret >= end - pos)
1483 switch (ssid->mode) {
1484 case WPAS_MODE_INFRA:
1485 ret = os_snprintf(pos, end - pos,
1488 case WPAS_MODE_IBSS:
1489 ret = os_snprintf(pos, end - pos,
1493 ret = os_snprintf(pos, end - pos,
1496 case WPAS_MODE_P2P_GO:
1497 ret = os_snprintf(pos, end - pos,
1500 case WPAS_MODE_P2P_GROUP_FORMATION:
1501 ret = os_snprintf(pos, end - pos,
1502 "mode=P2P GO - group "
1509 if (ret < 0 || ret >= end - pos)
1515 if (wpa_s->ap_iface) {
1516 pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos,
1520 #endif /* CONFIG_AP */
1521 pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose);
1524 if (wpa_s->wpa_state >= WPA_ASSOCIATED &&
1527 #endif /* CONFIG_AP */
1528 wpa_s->sme.sae.state == SAE_ACCEPTED) {
1529 ret = os_snprintf(pos, end - pos, "sae_group=%d\n",
1530 wpa_s->sme.sae.group);
1531 if (ret < 0 || ret >= end - pos)
1535 #endif /* CONFIG_SAE */
1536 ret = os_snprintf(pos, end - pos, "wpa_state=%s\n",
1537 wpa_supplicant_state_txt(wpa_s->wpa_state));
1538 if (ret < 0 || ret >= end - pos)
1543 l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) {
1544 ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp);
1545 if (ret < 0 || ret >= end - pos)
1551 if (wpa_s->global->p2p) {
1552 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
1553 "\n", MAC2STR(wpa_s->global->p2p_dev_addr));
1554 if (ret < 0 || ret >= end - pos)
1558 #endif /* CONFIG_P2P */
1560 ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n",
1561 MAC2STR(wpa_s->own_addr));
1562 if (ret < 0 || ret >= end - pos)
1567 if (wpa_s->current_bss &&
1568 wpa_bss_get_vendor_ie(wpa_s->current_bss, HS20_IE_VENDOR_TYPE) &&
1569 wpa_s->wpa_proto == WPA_PROTO_RSN &&
1570 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1571 ret = os_snprintf(pos, end - pos, "hs20=1\n");
1572 if (ret < 0 || ret >= end - pos)
1577 if (wpa_s->current_ssid) {
1578 struct wpa_cred *cred;
1581 for (cred = wpa_s->conf->cred; cred; cred = cred->next) {
1584 if (wpa_s->current_ssid->parent_cred != cred)
1587 for (i = 0; cred->domain && i < cred->num_domain; i++) {
1588 ret = os_snprintf(pos, end - pos,
1591 if (ret < 0 || ret >= end - pos)
1596 if (wpa_s->current_bss == NULL ||
1597 wpa_s->current_bss->anqp == NULL)
1600 res = interworking_home_sp_cred(
1602 wpa_s->current_bss->anqp->domain_name);
1610 ret = os_snprintf(pos, end - pos, "sp_type=%s\n", type);
1611 if (ret < 0 || ret >= end - pos)
1618 #endif /* CONFIG_HS20 */
1620 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
1621 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
1622 res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos,
1628 res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose);
1633 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_STATE_CHANGE
1634 "id=%d state=%d BSSID=" MACSTR " SSID=%s",
1635 wpa_s->current_ssid ? wpa_s->current_ssid->id : -1,
1637 MAC2STR(wpa_s->bssid),
1638 wpa_s->current_ssid && wpa_s->current_ssid->ssid ?
1639 wpa_ssid_txt(wpa_s->current_ssid->ssid,
1640 wpa_s->current_ssid->ssid_len) : "");
1641 if (wpa_s->wpa_state == WPA_COMPLETED) {
1642 struct wpa_ssid *ssid = wpa_s->current_ssid;
1643 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_CONNECTED
1644 "- connection to " MACSTR
1645 " completed %s [id=%d id_str=%s]",
1646 MAC2STR(wpa_s->bssid), "(auth)",
1647 ssid ? ssid->id : -1,
1648 ssid && ssid->id_str ? ssid->id_str : "");
1650 #endif /* ANDROID */
1656 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s,
1661 struct wpa_ssid *ssid;
1664 /* cmd: "<network id> <BSSID>" */
1665 pos = os_strchr(cmd, ' ');
1670 wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos);
1671 if (hwaddr_aton(pos, bssid)) {
1672 wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos);
1676 ssid = wpa_config_get_network(wpa_s->conf, id);
1678 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
1683 os_memcpy(ssid->bssid, bssid, ETH_ALEN);
1684 ssid->bssid_set = !is_zero_ether_addr(bssid);
1690 static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant *wpa_s,
1691 char *cmd, char *buf,
1695 struct wpa_blacklist *e;
1699 /* cmd: "BLACKLIST [<BSSID>]" */
1703 e = wpa_s->blacklist;
1705 ret = os_snprintf(pos, end - pos, MACSTR "\n",
1707 if (ret < 0 || ret >= end - pos)
1716 if (os_strncmp(cmd, "clear", 5) == 0) {
1717 wpa_blacklist_clear(wpa_s);
1718 os_memcpy(buf, "OK\n", 3);
1722 wpa_printf(MSG_DEBUG, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd);
1723 if (hwaddr_aton(cmd, bssid)) {
1724 wpa_printf(MSG_DEBUG, "CTRL_IFACE: invalid BSSID '%s'", cmd);
1729 * Add the BSSID twice, so its count will be 2, causing it to be
1730 * skipped when processing scan results.
1732 ret = wpa_blacklist_add(wpa_s, bssid);
1735 ret = wpa_blacklist_add(wpa_s, bssid);
1738 os_memcpy(buf, "OK\n", 3);
1743 extern int wpa_debug_level;
1744 extern int wpa_debug_timestamp;
1746 static const char * debug_level_str(int level)
1767 static int str_to_debug_level(const char *s)
1769 if (os_strcasecmp(s, "EXCESSIVE") == 0)
1770 return MSG_EXCESSIVE;
1771 if (os_strcasecmp(s, "MSGDUMP") == 0)
1773 if (os_strcasecmp(s, "DEBUG") == 0)
1775 if (os_strcasecmp(s, "INFO") == 0)
1777 if (os_strcasecmp(s, "WARNING") == 0)
1779 if (os_strcasecmp(s, "ERROR") == 0)
1785 static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant *wpa_s,
1786 char *cmd, char *buf,
1789 char *pos, *end, *stamp;
1796 /* cmd: "LOG_LEVEL [<level>]" */
1800 ret = os_snprintf(pos, end - pos, "Current level: %s\n"
1802 debug_level_str(wpa_debug_level),
1803 wpa_debug_timestamp);
1804 if (ret < 0 || ret >= end - pos)
1813 stamp = os_strchr(cmd, ' ');
1816 while (*stamp == ' ') {
1821 if (cmd && os_strlen(cmd)) {
1822 int level = str_to_debug_level(cmd);
1825 wpa_debug_level = level;
1828 if (stamp && os_strlen(stamp))
1829 wpa_debug_timestamp = atoi(stamp);
1831 os_memcpy(buf, "OK\n", 3);
1836 static int wpa_supplicant_ctrl_iface_list_networks(
1837 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
1840 struct wpa_ssid *ssid;
1845 ret = os_snprintf(pos, end - pos,
1846 "network id / ssid / bssid / flags\n");
1847 if (ret < 0 || ret >= end - pos)
1851 ssid = wpa_s->conf->ssid;
1853 ret = os_snprintf(pos, end - pos, "%d\t%s",
1855 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
1856 if (ret < 0 || ret >= end - pos)
1859 if (ssid->bssid_set) {
1860 ret = os_snprintf(pos, end - pos, "\t" MACSTR,
1861 MAC2STR(ssid->bssid));
1863 ret = os_snprintf(pos, end - pos, "\tany");
1865 if (ret < 0 || ret >= end - pos)
1868 ret = os_snprintf(pos, end - pos, "\t%s%s%s%s",
1869 ssid == wpa_s->current_ssid ?
1871 ssid->disabled ? "[DISABLED]" : "",
1872 ssid->disabled_until.sec ?
1873 "[TEMP-DISABLED]" : "",
1874 ssid->disabled == 2 ? "[P2P-PERSISTENT]" :
1876 if (ret < 0 || ret >= end - pos)
1879 ret = os_snprintf(pos, end - pos, "\n");
1880 if (ret < 0 || ret >= end - pos)
1891 static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher)
1894 ret = os_snprintf(pos, end - pos, "-");
1895 if (ret < 0 || ret >= end - pos)
1898 ret = wpa_write_ciphers(pos, end, cipher, "+");
1906 static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
1907 const u8 *ie, size_t ie_len)
1909 struct wpa_ie_data data;
1912 ret = os_snprintf(pos, end - pos, "[%s-", proto);
1913 if (ret < 0 || ret >= end - pos)
1917 if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) {
1918 ret = os_snprintf(pos, end - pos, "?]");
1919 if (ret < 0 || ret >= end - pos)
1926 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
1927 ret = os_snprintf(pos, end - pos, "%sEAP", first ? "" : "+");
1928 if (ret < 0 || ret >= end - pos)
1933 if (data.key_mgmt & WPA_KEY_MGMT_PSK) {
1934 ret = os_snprintf(pos, end - pos, "%sPSK", first ? "" : "+");
1935 if (ret < 0 || ret >= end - pos)
1940 if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
1941 ret = os_snprintf(pos, end - pos, "%sNone", first ? "" : "+");
1942 if (ret < 0 || ret >= end - pos)
1947 #ifdef CONFIG_IEEE80211R
1948 if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
1949 ret = os_snprintf(pos, end - pos, "%sFT/EAP",
1951 if (ret < 0 || ret >= end - pos)
1956 if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) {
1957 ret = os_snprintf(pos, end - pos, "%sFT/PSK",
1959 if (ret < 0 || ret >= end - pos)
1964 #endif /* CONFIG_IEEE80211R */
1965 #ifdef CONFIG_IEEE80211W
1966 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
1967 ret = os_snprintf(pos, end - pos, "%sEAP-SHA256",
1969 if (ret < 0 || ret >= end - pos)
1974 if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
1975 ret = os_snprintf(pos, end - pos, "%sPSK-SHA256",
1977 if (ret < 0 || ret >= end - pos)
1982 #endif /* CONFIG_IEEE80211W */
1984 pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher);
1986 if (data.capabilities & WPA_CAPABILITY_PREAUTH) {
1987 ret = os_snprintf(pos, end - pos, "-preauth");
1988 if (ret < 0 || ret >= end - pos)
1993 ret = os_snprintf(pos, end - pos, "]");
1994 if (ret < 0 || ret >= end - pos)
2003 static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s,
2004 char *pos, char *end,
2005 struct wpabuf *wps_ie)
2012 if (wps_is_selected_pbc_registrar(wps_ie))
2015 else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0))
2017 #endif /* CONFIG_WPS2 */
2018 else if (wps_is_selected_pin_registrar(wps_ie))
2023 ret = os_snprintf(pos, end - pos, "%s", txt);
2024 if (ret >= 0 && ret < end - pos)
2026 wpabuf_free(wps_ie);
2029 #endif /* CONFIG_WPS */
2032 static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s,
2033 char *pos, char *end,
2034 const struct wpa_bss *bss)
2037 struct wpabuf *wps_ie;
2038 wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
2039 return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie);
2040 #else /* CONFIG_WPS */
2042 #endif /* CONFIG_WPS */
2046 /* Format one result on one text line into a buffer. */
2047 static int wpa_supplicant_ctrl_iface_scan_result(
2048 struct wpa_supplicant *wpa_s,
2049 const struct wpa_bss *bss, char *buf, size_t buflen)
2053 const u8 *ie, *ie2, *p2p;
2055 p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
2057 p2p = wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE);
2058 if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN &&
2059 os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) ==
2061 return 0; /* Do not show P2P listen discovery results here */
2066 ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t",
2067 MAC2STR(bss->bssid), bss->freq, bss->level);
2068 if (ret < 0 || ret >= end - pos)
2071 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
2073 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]);
2074 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
2076 pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2, 2 + ie2[1]);
2077 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
2078 if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
2079 ret = os_snprintf(pos, end - pos, "[WEP]");
2080 if (ret < 0 || ret >= end - pos)
2084 if (bss->caps & IEEE80211_CAP_IBSS) {
2085 ret = os_snprintf(pos, end - pos, "[IBSS]");
2086 if (ret < 0 || ret >= end - pos)
2090 if (bss->caps & IEEE80211_CAP_ESS) {
2091 ret = os_snprintf(pos, end - pos, "[ESS]");
2092 if (ret < 0 || ret >= end - pos)
2097 ret = os_snprintf(pos, end - pos, "[P2P]");
2098 if (ret < 0 || ret >= end - pos)
2103 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE) && ie2) {
2104 ret = os_snprintf(pos, end - pos, "[HS20]");
2105 if (ret < 0 || ret >= end - pos)
2109 #endif /* CONFIG_HS20 */
2111 ret = os_snprintf(pos, end - pos, "\t%s",
2112 wpa_ssid_txt(bss->ssid, bss->ssid_len));
2113 if (ret < 0 || ret >= end - pos)
2117 ret = os_snprintf(pos, end - pos, "\n");
2118 if (ret < 0 || ret >= end - pos)
2126 static int wpa_supplicant_ctrl_iface_scan_results(
2127 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
2130 struct wpa_bss *bss;
2135 ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / "
2137 if (ret < 0 || ret >= end - pos)
2141 dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
2142 ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos,
2144 if (ret < 0 || ret >= end - pos)
2153 static int wpa_supplicant_ctrl_iface_select_network(
2154 struct wpa_supplicant *wpa_s, char *cmd)
2157 struct wpa_ssid *ssid;
2159 /* cmd: "<network id>" or "any" */
2160 if (os_strcmp(cmd, "any") == 0) {
2161 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any");
2165 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id);
2167 ssid = wpa_config_get_network(wpa_s->conf, id);
2169 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2170 "network id=%d", id);
2173 if (ssid->disabled == 2) {
2174 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2175 "SELECT_NETWORK with persistent P2P group");
2180 wpa_supplicant_select_network(wpa_s, ssid);
2186 static int wpa_supplicant_ctrl_iface_enable_network(
2187 struct wpa_supplicant *wpa_s, char *cmd)
2190 struct wpa_ssid *ssid;
2192 /* cmd: "<network id>" or "all" */
2193 if (os_strcmp(cmd, "all") == 0) {
2194 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all");
2198 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id);
2200 ssid = wpa_config_get_network(wpa_s->conf, id);
2202 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2203 "network id=%d", id);
2206 if (ssid->disabled == 2) {
2207 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2208 "ENABLE_NETWORK with persistent P2P group");
2212 if (os_strstr(cmd, " no-connect")) {
2217 wpa_supplicant_enable_network(wpa_s, ssid);
2223 static int wpa_supplicant_ctrl_iface_disable_network(
2224 struct wpa_supplicant *wpa_s, char *cmd)
2227 struct wpa_ssid *ssid;
2229 /* cmd: "<network id>" or "all" */
2230 if (os_strcmp(cmd, "all") == 0) {
2231 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all");
2235 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id);
2237 ssid = wpa_config_get_network(wpa_s->conf, id);
2239 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2240 "network id=%d", id);
2243 if (ssid->disabled == 2) {
2244 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2245 "DISABLE_NETWORK with persistent P2P "
2250 wpa_supplicant_disable_network(wpa_s, ssid);
2256 static int wpa_supplicant_ctrl_iface_add_network(
2257 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
2259 struct wpa_ssid *ssid;
2262 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK");
2264 ssid = wpa_config_add_network(wpa_s->conf);
2268 wpas_notify_network_added(wpa_s, ssid);
2271 wpa_config_set_network_defaults(ssid);
2273 ret = os_snprintf(buf, buflen, "%d\n", ssid->id);
2274 if (ret < 0 || (size_t) ret >= buflen)
2280 static int wpa_supplicant_ctrl_iface_remove_network(
2281 struct wpa_supplicant *wpa_s, char *cmd)
2284 struct wpa_ssid *ssid;
2287 /* cmd: "<network id>" or "all" */
2288 if (os_strcmp(cmd, "all") == 0) {
2289 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all");
2290 if (wpa_s->sched_scanning)
2291 wpa_supplicant_cancel_sched_scan(wpa_s);
2293 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2294 if (wpa_s->current_ssid) {
2296 wpa_s->sme.prev_bssid_set = 0;
2297 #endif /* CONFIG_SME */
2298 wpa_sm_set_config(wpa_s->wpa, NULL);
2299 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
2300 wpa_supplicant_deauthenticate(
2301 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2303 ssid = wpa_s->conf->ssid;
2305 struct wpa_ssid *remove_ssid = ssid;
2308 wpas_notify_network_removed(wpa_s, remove_ssid);
2309 wpa_config_remove_network(wpa_s->conf, id);
2315 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id);
2317 ssid = wpa_config_get_network(wpa_s->conf, id);
2319 wpas_notify_network_removed(wpa_s, ssid);
2321 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2326 if (ssid == wpa_s->current_ssid || wpa_s->current_ssid == NULL) {
2328 wpa_s->sme.prev_bssid_set = 0;
2329 #endif /* CONFIG_SME */
2331 * Invalidate the EAP session cache if the current or
2332 * previously used network is removed.
2334 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2337 if (ssid == wpa_s->current_ssid) {
2338 wpa_sm_set_config(wpa_s->wpa, NULL);
2339 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
2341 wpa_supplicant_deauthenticate(wpa_s,
2342 WLAN_REASON_DEAUTH_LEAVING);
2345 was_disabled = ssid->disabled;
2347 if (wpa_config_remove_network(wpa_s->conf, id) < 0) {
2348 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Not able to remove the "
2349 "network id=%d", id);
2353 if (!was_disabled && wpa_s->sched_scanning) {
2354 wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to remove "
2355 "network from filters");
2356 wpa_supplicant_cancel_sched_scan(wpa_s);
2357 wpa_supplicant_req_scan(wpa_s, 0, 0);
2364 static int wpa_supplicant_ctrl_iface_set_network(
2365 struct wpa_supplicant *wpa_s, char *cmd)
2368 struct wpa_ssid *ssid;
2371 /* cmd: "<network id> <variable name> <value>" */
2372 name = os_strchr(cmd, ' ');
2377 value = os_strchr(name, ' ');
2383 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
2385 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
2386 (u8 *) value, os_strlen(value));
2388 ssid = wpa_config_get_network(wpa_s->conf, id);
2390 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2395 if (wpa_config_set(ssid, name, value, 0) < 0) {
2396 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network "
2397 "variable '%s'", name);
2401 if (os_strcmp(name, "bssid") != 0 &&
2402 os_strcmp(name, "priority") != 0)
2403 wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
2405 if (wpa_s->current_ssid == ssid || wpa_s->current_ssid == NULL) {
2407 * Invalidate the EAP session cache if anything in the current
2408 * or previously used configuration changes.
2410 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2413 if ((os_strcmp(name, "psk") == 0 &&
2414 value[0] == '"' && ssid->ssid_len) ||
2415 (os_strcmp(name, "ssid") == 0 && ssid->passphrase))
2416 wpa_config_update_psk(ssid);
2417 else if (os_strcmp(name, "priority") == 0)
2418 wpa_config_update_prio_list(wpa_s->conf);
2424 static int wpa_supplicant_ctrl_iface_get_network(
2425 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
2429 struct wpa_ssid *ssid;
2432 /* cmd: "<network id> <variable name>" */
2433 name = os_strchr(cmd, ' ');
2434 if (name == NULL || buflen == 0)
2439 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
2442 ssid = wpa_config_get_network(wpa_s->conf, id);
2444 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2449 value = wpa_config_get_no_key(ssid, name);
2450 if (value == NULL) {
2451 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
2452 "variable '%s'", name);
2456 res = os_strlcpy(buf, value, buflen);
2457 if (res >= buflen) {
2468 static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant *wpa_s,
2469 char *buf, size_t buflen)
2472 struct wpa_cred *cred;
2477 ret = os_snprintf(pos, end - pos,
2478 "cred id / realm / username / domain / imsi\n");
2479 if (ret < 0 || ret >= end - pos)
2483 cred = wpa_s->conf->cred;
2485 ret = os_snprintf(pos, end - pos, "%d\t%s\t%s\t%s\t%s\n",
2486 cred->id, cred->realm ? cred->realm : "",
2487 cred->username ? cred->username : "",
2488 cred->domain ? cred->domain[0] : "",
2489 cred->imsi ? cred->imsi : "");
2490 if (ret < 0 || ret >= end - pos)
2501 static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant *wpa_s,
2502 char *buf, size_t buflen)
2504 struct wpa_cred *cred;
2507 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_CRED");
2509 cred = wpa_config_add_cred(wpa_s->conf);
2513 ret = os_snprintf(buf, buflen, "%d\n", cred->id);
2514 if (ret < 0 || (size_t) ret >= buflen)
2520 static int wpas_ctrl_remove_cred(struct wpa_supplicant *wpa_s,
2521 struct wpa_cred *cred)
2523 struct wpa_ssid *ssid;
2526 if (cred == NULL || wpa_config_remove_cred(wpa_s->conf, cred->id) < 0) {
2527 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred");
2531 /* Remove any network entry created based on the removed credential */
2532 ssid = wpa_s->conf->ssid;
2534 if (ssid->parent_cred == cred) {
2535 wpa_printf(MSG_DEBUG, "Remove network id %d since it "
2536 "used the removed credential", ssid->id);
2537 os_snprintf(str, sizeof(str), "%d", ssid->id);
2539 wpa_supplicant_ctrl_iface_remove_network(wpa_s, str);
2548 static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s,
2552 struct wpa_cred *cred, *prev;
2554 /* cmd: "<cred id>", "all", or "sp_fqdn=<FQDN>" */
2555 if (os_strcmp(cmd, "all") == 0) {
2556 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED all");
2557 cred = wpa_s->conf->cred;
2561 wpas_ctrl_remove_cred(wpa_s, prev);
2566 if (os_strncmp(cmd, "sp_fqdn=", 8) == 0) {
2567 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
2569 cred = wpa_s->conf->cred;
2575 for (i = 0; i < prev->num_domain; i++) {
2576 if (os_strcmp(prev->domain[i], cmd + 8)
2579 wpas_ctrl_remove_cred(wpa_s, prev);
2588 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED id=%d", id);
2590 cred = wpa_config_get_cred(wpa_s->conf, id);
2591 return wpas_ctrl_remove_cred(wpa_s, cred);
2595 static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant *wpa_s,
2599 struct wpa_cred *cred;
2602 /* cmd: "<cred id> <variable name> <value>" */
2603 name = os_strchr(cmd, ' ');
2608 value = os_strchr(name, ' ');
2614 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_CRED id=%d name='%s'",
2616 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
2617 (u8 *) value, os_strlen(value));
2619 cred = wpa_config_get_cred(wpa_s->conf, id);
2621 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
2626 if (wpa_config_set_cred(cred, name, value, 0) < 0) {
2627 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set cred "
2628 "variable '%s'", name);
2636 #ifndef CONFIG_NO_CONFIG_WRITE
2637 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s)
2641 if (!wpa_s->conf->update_config) {
2642 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
2643 "to update configuration (update_config=0)");
2647 ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
2649 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to "
2650 "update configuration");
2652 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration"
2658 #endif /* CONFIG_NO_CONFIG_WRITE */
2661 struct cipher_info {
2667 static const struct cipher_info ciphers[] = {
2668 { WPA_DRIVER_CAPA_ENC_CCMP_256, "CCMP-256", 0 },
2669 { WPA_DRIVER_CAPA_ENC_GCMP_256, "GCMP-256", 0 },
2670 { WPA_DRIVER_CAPA_ENC_CCMP, "CCMP", 0 },
2671 { WPA_DRIVER_CAPA_ENC_GCMP, "GCMP", 0 },
2672 { WPA_DRIVER_CAPA_ENC_TKIP, "TKIP", 0 },
2673 { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE, "NONE", 0 },
2674 { WPA_DRIVER_CAPA_ENC_WEP104, "WEP104", 1 },
2675 { WPA_DRIVER_CAPA_ENC_WEP40, "WEP40", 1 }
2679 static int ctrl_iface_get_capability_pairwise(int res, char *strict,
2680 struct wpa_driver_capa *capa,
2681 char *buf, size_t buflen)
2694 len = os_strlcpy(buf, "CCMP TKIP NONE", buflen);
2700 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
2701 if (!ciphers[i].group_only && capa->enc & ciphers[i].capa) {
2702 ret = os_snprintf(pos, end - pos, "%s%s",
2703 first ? "" : " ", ciphers[i].name);
2704 if (ret < 0 || ret >= end - pos)
2715 static int ctrl_iface_get_capability_group(int res, char *strict,
2716 struct wpa_driver_capa *capa,
2717 char *buf, size_t buflen)
2730 len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen);
2736 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
2737 if (capa->enc & ciphers[i].capa) {
2738 ret = os_snprintf(pos, end - pos, "%s%s",
2739 first ? "" : " ", ciphers[i].name);
2740 if (ret < 0 || ret >= end - pos)
2751 static int ctrl_iface_get_capability_key_mgmt(int res, char *strict,
2752 struct wpa_driver_capa *capa,
2753 char *buf, size_t buflen)
2765 len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
2772 ret = os_snprintf(pos, end - pos, "NONE IEEE8021X");
2773 if (ret < 0 || ret >= end - pos)
2777 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
2778 WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
2779 ret = os_snprintf(pos, end - pos, " WPA-EAP");
2780 if (ret < 0 || ret >= end - pos)
2785 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
2786 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
2787 ret = os_snprintf(pos, end - pos, " WPA-PSK");
2788 if (ret < 0 || ret >= end - pos)
2793 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
2794 ret = os_snprintf(pos, end - pos, " WPA-NONE");
2795 if (ret < 0 || ret >= end - pos)
2804 static int ctrl_iface_get_capability_proto(int res, char *strict,
2805 struct wpa_driver_capa *capa,
2806 char *buf, size_t buflen)
2818 len = os_strlcpy(buf, "RSN WPA", buflen);
2824 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
2825 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
2826 ret = os_snprintf(pos, end - pos, "%sRSN", first ? "" : " ");
2827 if (ret < 0 || ret >= end - pos)
2833 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
2834 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
2835 ret = os_snprintf(pos, end - pos, "%sWPA", first ? "" : " ");
2836 if (ret < 0 || ret >= end - pos)
2846 static int ctrl_iface_get_capability_auth_alg(int res, char *strict,
2847 struct wpa_driver_capa *capa,
2848 char *buf, size_t buflen)
2860 len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen);
2866 if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) {
2867 ret = os_snprintf(pos, end - pos, "%sOPEN", first ? "" : " ");
2868 if (ret < 0 || ret >= end - pos)
2874 if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) {
2875 ret = os_snprintf(pos, end - pos, "%sSHARED",
2877 if (ret < 0 || ret >= end - pos)
2883 if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) {
2884 ret = os_snprintf(pos, end - pos, "%sLEAP", first ? "" : " ");
2885 if (ret < 0 || ret >= end - pos)
2895 static int ctrl_iface_get_capability_modes(int res, char *strict,
2896 struct wpa_driver_capa *capa,
2897 char *buf, size_t buflen)
2909 len = os_strlcpy(buf, "IBSS AP", buflen);
2915 if (capa->flags & WPA_DRIVER_FLAGS_IBSS) {
2916 ret = os_snprintf(pos, end - pos, "%sIBSS", first ? "" : " ");
2917 if (ret < 0 || ret >= end - pos)
2923 if (capa->flags & WPA_DRIVER_FLAGS_AP) {
2924 ret = os_snprintf(pos, end - pos, "%sAP", first ? "" : " ");
2925 if (ret < 0 || ret >= end - pos)
2935 static int ctrl_iface_get_capability_channels(struct wpa_supplicant *wpa_s,
2936 char *buf, size_t buflen)
2938 struct hostapd_channel_data *chnl;
2940 char *pos, *end, *hmode;
2945 for (j = 0; j < wpa_s->hw.num_modes; j++) {
2946 switch (wpa_s->hw.modes[j].mode) {
2947 case HOSTAPD_MODE_IEEE80211B:
2950 case HOSTAPD_MODE_IEEE80211G:
2953 case HOSTAPD_MODE_IEEE80211A:
2956 case HOSTAPD_MODE_IEEE80211AD:
2962 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:", hmode);
2963 if (ret < 0 || ret >= end - pos)
2966 chnl = wpa_s->hw.modes[j].channels;
2967 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
2968 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
2970 ret = os_snprintf(pos, end - pos, " %d", chnl[i].chan);
2971 if (ret < 0 || ret >= end - pos)
2975 ret = os_snprintf(pos, end - pos, "\n");
2976 if (ret < 0 || ret >= end - pos)
2985 static int ctrl_iface_get_capability_freq(struct wpa_supplicant *wpa_s,
2986 char *buf, size_t buflen)
2988 struct hostapd_channel_data *chnl;
2990 char *pos, *end, *hmode;
2995 for (j = 0; j < wpa_s->hw.num_modes; j++) {
2996 switch (wpa_s->hw.modes[j].mode) {
2997 case HOSTAPD_MODE_IEEE80211B:
3000 case HOSTAPD_MODE_IEEE80211G:
3003 case HOSTAPD_MODE_IEEE80211A:
3006 case HOSTAPD_MODE_IEEE80211AD:
3012 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:\n",
3014 if (ret < 0 || ret >= end - pos)
3017 chnl = wpa_s->hw.modes[j].channels;
3018 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
3019 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
3021 ret = os_snprintf(pos, end - pos, " %d = %d MHz%s\n",
3022 chnl[i].chan, chnl[i].freq,
3023 chnl[i].flag & HOSTAPD_CHAN_NO_IBSS ?
3025 if (ret < 0 || ret >= end - pos)
3029 ret = os_snprintf(pos, end - pos, "\n");
3030 if (ret < 0 || ret >= end - pos)
3039 static int wpa_supplicant_ctrl_iface_get_capability(
3040 struct wpa_supplicant *wpa_s, const char *_field, char *buf,
3043 struct wpa_driver_capa capa;
3049 /* Determine whether or not strict checking was requested */
3050 len = os_strlcpy(field, _field, sizeof(field));
3051 if (len >= sizeof(field))
3053 strict = os_strchr(field, ' ');
3054 if (strict != NULL) {
3056 if (os_strcmp(strict, "strict") != 0)
3060 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
3061 field, strict ? strict : "");
3063 if (os_strcmp(field, "eap") == 0) {
3064 return eap_get_names(buf, buflen);
3067 res = wpa_drv_get_capa(wpa_s, &capa);
3069 if (os_strcmp(field, "pairwise") == 0)
3070 return ctrl_iface_get_capability_pairwise(res, strict, &capa,
3073 if (os_strcmp(field, "group") == 0)
3074 return ctrl_iface_get_capability_group(res, strict, &capa,
3077 if (os_strcmp(field, "key_mgmt") == 0)
3078 return ctrl_iface_get_capability_key_mgmt(res, strict, &capa,
3081 if (os_strcmp(field, "proto") == 0)
3082 return ctrl_iface_get_capability_proto(res, strict, &capa,
3085 if (os_strcmp(field, "auth_alg") == 0)
3086 return ctrl_iface_get_capability_auth_alg(res, strict, &capa,
3089 if (os_strcmp(field, "modes") == 0)
3090 return ctrl_iface_get_capability_modes(res, strict, &capa,
3093 if (os_strcmp(field, "channels") == 0)
3094 return ctrl_iface_get_capability_channels(wpa_s, buf, buflen);
3096 if (os_strcmp(field, "freq") == 0)
3097 return ctrl_iface_get_capability_freq(wpa_s, buf, buflen);
3099 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
3106 #ifdef CONFIG_INTERWORKING
3107 static char * anqp_add_hex(char *pos, char *end, const char *title,
3108 struct wpabuf *data)
3118 ret = os_snprintf(pos, end - pos, "%s=", title);
3119 if (ret < 0 || ret >= end - pos)
3123 d = wpabuf_head_u8(data);
3124 for (i = 0; i < wpabuf_len(data); i++) {
3125 ret = os_snprintf(pos, end - pos, "%02x", *d++);
3126 if (ret < 0 || ret >= end - pos)
3131 ret = os_snprintf(pos, end - pos, "\n");
3132 if (ret < 0 || ret >= end - pos)
3138 #endif /* CONFIG_INTERWORKING */
3141 static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
3142 unsigned long mask, char *buf, size_t buflen)
3152 if (mask & WPA_BSS_MASK_ID) {
3153 ret = os_snprintf(pos, end - pos, "id=%u\n", bss->id);
3154 if (ret < 0 || ret >= end - pos)
3159 if (mask & WPA_BSS_MASK_BSSID) {
3160 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
3161 MAC2STR(bss->bssid));
3162 if (ret < 0 || ret >= end - pos)
3167 if (mask & WPA_BSS_MASK_FREQ) {
3168 ret = os_snprintf(pos, end - pos, "freq=%d\n", bss->freq);
3169 if (ret < 0 || ret >= end - pos)
3174 if (mask & WPA_BSS_MASK_BEACON_INT) {
3175 ret = os_snprintf(pos, end - pos, "beacon_int=%d\n",
3177 if (ret < 0 || ret >= end - pos)
3182 if (mask & WPA_BSS_MASK_CAPABILITIES) {
3183 ret = os_snprintf(pos, end - pos, "capabilities=0x%04x\n",
3185 if (ret < 0 || ret >= end - pos)
3190 if (mask & WPA_BSS_MASK_QUAL) {
3191 ret = os_snprintf(pos, end - pos, "qual=%d\n", bss->qual);
3192 if (ret < 0 || ret >= end - pos)
3197 if (mask & WPA_BSS_MASK_NOISE) {
3198 ret = os_snprintf(pos, end - pos, "noise=%d\n", bss->noise);
3199 if (ret < 0 || ret >= end - pos)
3204 if (mask & WPA_BSS_MASK_LEVEL) {
3205 ret = os_snprintf(pos, end - pos, "level=%d\n", bss->level);
3206 if (ret < 0 || ret >= end - pos)
3211 if (mask & WPA_BSS_MASK_TSF) {
3212 ret = os_snprintf(pos, end - pos, "tsf=%016llu\n",
3213 (unsigned long long) bss->tsf);
3214 if (ret < 0 || ret >= end - pos)
3219 if (mask & WPA_BSS_MASK_AGE) {
3220 struct os_reltime now;
3222 os_get_reltime(&now);
3223 ret = os_snprintf(pos, end - pos, "age=%d\n",
3224 (int) (now.sec - bss->last_update.sec));
3225 if (ret < 0 || ret >= end - pos)
3230 if (mask & WPA_BSS_MASK_IE) {
3231 ret = os_snprintf(pos, end - pos, "ie=");
3232 if (ret < 0 || ret >= end - pos)
3236 ie = (const u8 *) (bss + 1);
3237 for (i = 0; i < bss->ie_len; i++) {
3238 ret = os_snprintf(pos, end - pos, "%02x", *ie++);
3239 if (ret < 0 || ret >= end - pos)
3244 ret = os_snprintf(pos, end - pos, "\n");
3245 if (ret < 0 || ret >= end - pos)
3250 if (mask & WPA_BSS_MASK_FLAGS) {
3251 ret = os_snprintf(pos, end - pos, "flags=");
3252 if (ret < 0 || ret >= end - pos)
3256 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
3258 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie,
3260 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
3262 pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2,
3264 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
3265 if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
3266 ret = os_snprintf(pos, end - pos, "[WEP]");
3267 if (ret < 0 || ret >= end - pos)
3271 if (bss->caps & IEEE80211_CAP_IBSS) {
3272 ret = os_snprintf(pos, end - pos, "[IBSS]");
3273 if (ret < 0 || ret >= end - pos)
3277 if (bss->caps & IEEE80211_CAP_ESS) {
3278 ret = os_snprintf(pos, end - pos, "[ESS]");
3279 if (ret < 0 || ret >= end - pos)
3283 if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
3284 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
3285 ret = os_snprintf(pos, end - pos, "[P2P]");
3286 if (ret < 0 || ret >= end - pos)
3291 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) {
3292 ret = os_snprintf(pos, end - pos, "[HS20]");
3293 if (ret < 0 || ret >= end - pos)
3297 #endif /* CONFIG_HS20 */
3299 ret = os_snprintf(pos, end - pos, "\n");
3300 if (ret < 0 || ret >= end - pos)
3305 if (mask & WPA_BSS_MASK_SSID) {
3306 ret = os_snprintf(pos, end - pos, "ssid=%s\n",
3307 wpa_ssid_txt(bss->ssid, bss->ssid_len));
3308 if (ret < 0 || ret >= end - pos)
3314 if (mask & WPA_BSS_MASK_WPS_SCAN) {
3315 ie = (const u8 *) (bss + 1);
3316 ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end);
3317 if (ret < 0 || ret >= end - pos)
3321 #endif /* CONFIG_WPS */
3324 if (mask & WPA_BSS_MASK_P2P_SCAN) {
3325 ie = (const u8 *) (bss + 1);
3326 ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end);
3327 if (ret < 0 || ret >= end - pos)
3331 #endif /* CONFIG_P2P */
3333 #ifdef CONFIG_WIFI_DISPLAY
3334 if (mask & WPA_BSS_MASK_WIFI_DISPLAY) {
3336 ie = (const u8 *) (bss + 1);
3337 wfd = ieee802_11_vendor_ie_concat(ie, bss->ie_len,
3338 WFD_IE_VENDOR_TYPE);
3340 ret = os_snprintf(pos, end - pos, "wfd_subelems=");
3341 if (ret < 0 || ret >= end - pos)
3345 pos += wpa_snprintf_hex(pos, end - pos,
3350 ret = os_snprintf(pos, end - pos, "\n");
3351 if (ret < 0 || ret >= end - pos)
3356 #endif /* CONFIG_WIFI_DISPLAY */
3358 #ifdef CONFIG_INTERWORKING
3359 if ((mask & WPA_BSS_MASK_INTERNETW) && bss->anqp) {
3360 struct wpa_bss_anqp *anqp = bss->anqp;
3361 pos = anqp_add_hex(pos, end, "anqp_venue_name",
3363 pos = anqp_add_hex(pos, end, "anqp_network_auth_type",
3364 anqp->network_auth_type);
3365 pos = anqp_add_hex(pos, end, "anqp_roaming_consortium",
3366 anqp->roaming_consortium);
3367 pos = anqp_add_hex(pos, end, "anqp_ip_addr_type_availability",
3368 anqp->ip_addr_type_availability);
3369 pos = anqp_add_hex(pos, end, "anqp_nai_realm",
3371 pos = anqp_add_hex(pos, end, "anqp_3gpp", anqp->anqp_3gpp);
3372 pos = anqp_add_hex(pos, end, "anqp_domain_name",
3375 pos = anqp_add_hex(pos, end, "hs20_operator_friendly_name",
3376 anqp->hs20_operator_friendly_name);
3377 pos = anqp_add_hex(pos, end, "hs20_wan_metrics",
3378 anqp->hs20_wan_metrics);
3379 pos = anqp_add_hex(pos, end, "hs20_connection_capability",
3380 anqp->hs20_connection_capability);
3381 #endif /* CONFIG_HS20 */
3383 #endif /* CONFIG_INTERWORKING */
3385 if (mask & WPA_BSS_MASK_DELIM) {
3386 ret = os_snprintf(pos, end - pos, "====\n");
3387 if (ret < 0 || ret >= end - pos)
3396 static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
3397 const char *cmd, char *buf,
3402 struct wpa_bss *bss;
3403 struct wpa_bss *bsslast = NULL;
3404 struct dl_list *next;
3408 unsigned long mask = WPA_BSS_MASK_ALL;
3410 if (os_strncmp(cmd, "RANGE=", 6) == 0) {
3411 if (os_strncmp(cmd + 6, "ALL", 3) == 0) {
3412 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss,
3414 bsslast = dl_list_last(&wpa_s->bss_id, struct wpa_bss,
3416 } else { /* N1-N2 */
3417 unsigned int id1, id2;
3419 if ((ctmp = os_strchr(cmd + 6, '-')) == NULL) {
3420 wpa_printf(MSG_INFO, "Wrong BSS range "
3425 if (*(cmd + 6) == '-')
3428 id1 = atoi(cmd + 6);
3430 if (*ctmp >= '0' && *ctmp <= '9')
3433 id2 = (unsigned int) -1;
3434 bss = wpa_bss_get_id_range(wpa_s, id1, id2);
3435 if (id2 == (unsigned int) -1)
3436 bsslast = dl_list_last(&wpa_s->bss_id,
3440 bsslast = wpa_bss_get_id(wpa_s, id2);
3441 if (bsslast == NULL && bss && id2 > id1) {
3442 struct wpa_bss *tmp = bss;
3444 next = tmp->list_id.next;
3445 if (next == &wpa_s->bss_id)
3447 tmp = dl_list_entry(
3448 next, struct wpa_bss,
3457 } else if (os_strncmp(cmd, "FIRST", 5) == 0)
3458 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, list_id);
3459 else if (os_strncmp(cmd, "LAST", 4) == 0)
3460 bss = dl_list_last(&wpa_s->bss_id, struct wpa_bss, list_id);
3461 else if (os_strncmp(cmd, "ID-", 3) == 0) {
3463 bss = wpa_bss_get_id(wpa_s, i);
3464 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
3466 bss = wpa_bss_get_id(wpa_s, i);
3468 next = bss->list_id.next;
3469 if (next == &wpa_s->bss_id)
3472 bss = dl_list_entry(next, struct wpa_bss,
3476 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
3477 if (hwaddr_aton(cmd + 13, bssid) == 0)
3478 bss = wpa_bss_get_p2p_dev_addr(wpa_s, bssid);
3481 #endif /* CONFIG_P2P */
3482 } else if (hwaddr_aton(cmd, bssid) == 0)
3483 bss = wpa_bss_get_bssid(wpa_s, bssid);
3485 struct wpa_bss *tmp;
3488 dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id)
3497 if ((ctmp = os_strstr(cmd, "MASK=")) != NULL) {
3498 mask = strtoul(ctmp + 5, NULL, 0x10);
3500 mask = WPA_BSS_MASK_ALL;
3506 if (bsslast == NULL)
3509 len = print_bss_info(wpa_s, bss, mask, buf, buflen);
3513 if (bss == bsslast) {
3514 if ((mask & WPA_BSS_MASK_DELIM) && len &&
3515 (bss == dl_list_last(&wpa_s->bss_id,
3516 struct wpa_bss, list_id)))
3517 os_snprintf(buf - 5, 5, "####\n");
3520 next = bss->list_id.next;
3521 if (next == &wpa_s->bss_id)
3523 bss = dl_list_entry(next, struct wpa_bss, list_id);
3524 } while (bss && len);
3530 static int wpa_supplicant_ctrl_iface_ap_scan(
3531 struct wpa_supplicant *wpa_s, char *cmd)
3533 int ap_scan = atoi(cmd);
3534 return wpa_supplicant_set_ap_scan(wpa_s, ap_scan);
3538 static int wpa_supplicant_ctrl_iface_scan_interval(
3539 struct wpa_supplicant *wpa_s, char *cmd)
3541 int scan_int = atoi(cmd);
3542 return wpa_supplicant_set_scan_interval(wpa_s, scan_int);
3546 static int wpa_supplicant_ctrl_iface_bss_expire_age(
3547 struct wpa_supplicant *wpa_s, char *cmd)
3549 int expire_age = atoi(cmd);
3550 return wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age);
3554 static int wpa_supplicant_ctrl_iface_bss_expire_count(
3555 struct wpa_supplicant *wpa_s, char *cmd)
3557 int expire_count = atoi(cmd);
3558 return wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count);
3562 static int wpa_supplicant_ctrl_iface_bss_flush(
3563 struct wpa_supplicant *wpa_s, char *cmd)
3565 int flush_age = atoi(cmd);
3568 wpa_bss_flush(wpa_s);
3570 wpa_bss_flush_by_age(wpa_s, flush_age);
3575 static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s)
3577 wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication");
3578 /* MLME-DELETEKEYS.request */
3579 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL, 0);
3580 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL, 0);
3581 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL, 0);
3582 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL, 0);
3583 #ifdef CONFIG_IEEE80211W
3584 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL, 0);
3585 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL, 0);
3586 #endif /* CONFIG_IEEE80211W */
3588 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, wpa_s->bssid, 0, 0, NULL, 0, NULL,
3590 /* MLME-SETPROTECTION.request(None) */
3591 wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid,
3592 MLME_SETPROTECTION_PROTECT_TYPE_NONE,
3593 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE);
3594 wpa_sm_drop_sa(wpa_s->wpa);
3598 static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s,
3601 #ifdef CONFIG_NO_SCAN_PROCESSING
3603 #else /* CONFIG_NO_SCAN_PROCESSING */
3605 struct wpa_bss *bss;
3606 struct wpa_ssid *ssid = wpa_s->current_ssid;
3608 if (hwaddr_aton(addr, bssid)) {
3609 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid "
3610 "address '%s'", addr);
3614 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR, MAC2STR(bssid));
3617 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network "
3618 "configuration known for the target AP");
3622 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
3624 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found "
3630 * TODO: Find best network configuration block from configuration to
3631 * allow roaming to other networks
3634 wpa_s->reassociate = 1;
3635 wpa_supplicant_connect(wpa_s, bss, ssid);
3638 #endif /* CONFIG_NO_SCAN_PROCESSING */
3643 static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd)
3645 unsigned int timeout = atoi(cmd);
3646 enum p2p_discovery_type type = P2P_FIND_START_WITH_FULL;
3647 u8 dev_id[ETH_ALEN], *_dev_id = NULL;
3649 unsigned int search_delay;
3651 if (os_strstr(cmd, "type=social"))
3652 type = P2P_FIND_ONLY_SOCIAL;
3653 else if (os_strstr(cmd, "type=progressive"))
3654 type = P2P_FIND_PROGRESSIVE;
3656 pos = os_strstr(cmd, "dev_id=");
3659 if (hwaddr_aton(pos, dev_id))
3664 pos = os_strstr(cmd, "delay=");
3667 search_delay = atoi(pos);
3669 search_delay = wpas_p2p_search_delay(wpa_s);
3671 return wpas_p2p_find(wpa_s, timeout, type, 0, NULL, _dev_id,
3676 static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd,
3677 char *buf, size_t buflen)
3682 enum p2p_wps_method wps_method;
3685 int persistent_group, persistent_id = -1;
3694 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad]
3695 * [persistent|persistent=<network id>]
3696 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
3699 if (hwaddr_aton(cmd, addr))
3707 persistent_group = os_strstr(pos, " persistent") != NULL;
3708 pos2 = os_strstr(pos, " persistent=");
3710 struct wpa_ssid *ssid;
3711 persistent_id = atoi(pos2 + 12);
3712 ssid = wpa_config_get_network(wpa_s->conf, persistent_id);
3713 if (ssid == NULL || ssid->disabled != 2 ||
3714 ssid->mode != WPAS_MODE_P2P_GO) {
3715 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3716 "SSID id=%d for persistent P2P group (GO)",
3721 join = os_strstr(pos, " join") != NULL;
3722 auth = os_strstr(pos, " auth") != NULL;
3723 automatic = os_strstr(pos, " auto") != NULL;
3724 pd = os_strstr(pos, " provdisc") != NULL;
3725 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
3726 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
3729 pos2 = os_strstr(pos, " go_intent=");
3732 go_intent = atoi(pos2);
3733 if (go_intent < 0 || go_intent > 15)
3737 pos2 = os_strstr(pos, " freq=");
3745 if (os_strncmp(pos, "pin", 3) == 0) {
3746 /* Request random PIN (to be displayed) and enable the PIN */
3747 wps_method = WPS_PIN_DISPLAY;
3748 } else if (os_strncmp(pos, "pbc", 3) == 0) {
3749 wps_method = WPS_PBC;
3752 pos = os_strchr(pin, ' ');
3753 wps_method = WPS_PIN_KEYPAD;
3756 if (os_strncmp(pos, "display", 7) == 0)
3757 wps_method = WPS_PIN_DISPLAY;
3759 if (!wps_pin_str_valid(pin)) {
3760 os_memcpy(buf, "FAIL-INVALID-PIN\n", 17);
3765 new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method,
3766 persistent_group, automatic, join,
3767 auth, go_intent, freq, persistent_id, pd,
3769 if (new_pin == -2) {
3770 os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
3773 if (new_pin == -3) {
3774 os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
3779 if (wps_method == WPS_PIN_DISPLAY && pin == NULL) {
3780 ret = os_snprintf(buf, buflen, "%08d", new_pin);
3781 if (ret < 0 || (size_t) ret >= buflen)
3786 os_memcpy(buf, "OK\n", 3);
3791 static int p2p_ctrl_listen(struct wpa_supplicant *wpa_s, char *cmd)
3793 unsigned int timeout = atoi(cmd);
3794 return wpas_p2p_listen(wpa_s, timeout);
3798 static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd)
3802 enum wpas_p2p_prov_disc_use use = WPAS_P2P_PD_FOR_GO_NEG;
3804 /* <addr> <config method> [join|auto] */
3806 if (hwaddr_aton(cmd, addr))
3814 if (os_strstr(pos, " join") != NULL)
3815 use = WPAS_P2P_PD_FOR_JOIN;
3816 else if (os_strstr(pos, " auto") != NULL)
3817 use = WPAS_P2P_PD_AUTO;
3819 return wpas_p2p_prov_disc(wpa_s, addr, pos, use);
3823 static int p2p_get_passphrase(struct wpa_supplicant *wpa_s, char *buf,
3826 struct wpa_ssid *ssid = wpa_s->current_ssid;
3828 if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO ||
3829 ssid->passphrase == NULL)
3832 os_strlcpy(buf, ssid->passphrase, buflen);
3833 return os_strlen(buf);
3837 static int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd,
3838 char *buf, size_t buflen)
3842 u8 dst_buf[ETH_ALEN], *dst;
3843 struct wpabuf *tlvs;
3847 if (hwaddr_aton(cmd, dst_buf))
3850 if (dst[0] == 0 && dst[1] == 0 && dst[2] == 0 &&
3851 dst[3] == 0 && dst[4] == 0 && dst[5] == 0)
3858 if (os_strncmp(pos, "upnp ", 5) == 0) {
3861 if (hexstr2bin(pos, &version, 1) < 0)
3867 ref = wpas_p2p_sd_request_upnp(wpa_s, dst, version, pos);
3868 #ifdef CONFIG_WIFI_DISPLAY
3869 } else if (os_strncmp(pos, "wifi-display ", 13) == 0) {
3870 ref = wpas_p2p_sd_request_wifi_display(wpa_s, dst, pos + 13);
3871 #endif /* CONFIG_WIFI_DISPLAY */
3873 len = os_strlen(pos);
3877 tlvs = wpabuf_alloc(len);
3880 if (hexstr2bin(pos, wpabuf_put(tlvs, len), len) < 0) {
3885 ref = wpas_p2p_sd_request(wpa_s, dst, tlvs);
3890 res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref);
3891 if (res < 0 || (unsigned) res >= buflen)
3897 static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s,
3900 long long unsigned val;
3902 if (sscanf(cmd, "%llx", &val) != 1)
3905 return wpas_p2p_sd_cancel_request(wpa_s, req);
3909 static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant *wpa_s, char *cmd)
3914 struct wpabuf *resp_tlvs;
3918 pos = os_strchr(cmd, ' ');
3926 if (hwaddr_aton(pos, dst))
3933 pos2 = os_strchr(pos, ' ');
3937 dialog_token = atoi(pos);
3939 len = os_strlen(pos2);
3943 resp_tlvs = wpabuf_alloc(len);
3944 if (resp_tlvs == NULL)
3946 if (hexstr2bin(pos2, wpabuf_put(resp_tlvs, len), len) < 0) {
3947 wpabuf_free(resp_tlvs);
3951 wpas_p2p_sd_response(wpa_s, freq, dst, dialog_token, resp_tlvs);
3952 wpabuf_free(resp_tlvs);
3957 static int p2p_ctrl_serv_disc_external(struct wpa_supplicant *wpa_s,
3960 if (os_strcmp(cmd, "0") && os_strcmp(cmd, "1"))
3962 wpa_s->p2p_sd_over_ctrl_iface = atoi(cmd);
3967 static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant *wpa_s,
3972 struct wpabuf *query, *resp;
3974 pos = os_strchr(cmd, ' ');
3979 len = os_strlen(cmd);
3983 query = wpabuf_alloc(len);
3986 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
3991 len = os_strlen(pos);
3997 resp = wpabuf_alloc(len);
4002 if (hexstr2bin(pos, wpabuf_put(resp, len), len) < 0) {
4008 if (wpas_p2p_service_add_bonjour(wpa_s, query, resp) < 0) {
4017 static int p2p_ctrl_service_add_upnp(struct wpa_supplicant *wpa_s, char *cmd)
4022 pos = os_strchr(cmd, ' ');
4027 if (hexstr2bin(cmd, &version, 1) < 0)
4030 return wpas_p2p_service_add_upnp(wpa_s, version, pos);
4034 static int p2p_ctrl_service_add(struct wpa_supplicant *wpa_s, char *cmd)
4038 pos = os_strchr(cmd, ' ');
4043 if (os_strcmp(cmd, "bonjour") == 0)
4044 return p2p_ctrl_service_add_bonjour(wpa_s, pos);
4045 if (os_strcmp(cmd, "upnp") == 0)
4046 return p2p_ctrl_service_add_upnp(wpa_s, pos);
4047 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
4052 static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant *wpa_s,
4056 struct wpabuf *query;
4059 len = os_strlen(cmd);
4063 query = wpabuf_alloc(len);
4066 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
4071 ret = wpas_p2p_service_del_bonjour(wpa_s, query);
4077 static int p2p_ctrl_service_del_upnp(struct wpa_supplicant *wpa_s, char *cmd)
4082 pos = os_strchr(cmd, ' ');
4087 if (hexstr2bin(cmd, &version, 1) < 0)
4090 return wpas_p2p_service_del_upnp(wpa_s, version, pos);
4094 static int p2p_ctrl_service_del(struct wpa_supplicant *wpa_s, char *cmd)
4098 pos = os_strchr(cmd, ' ');
4103 if (os_strcmp(cmd, "bonjour") == 0)
4104 return p2p_ctrl_service_del_bonjour(wpa_s, pos);
4105 if (os_strcmp(cmd, "upnp") == 0)
4106 return p2p_ctrl_service_del_upnp(wpa_s, pos);
4107 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
4112 static int p2p_ctrl_reject(struct wpa_supplicant *wpa_s, char *cmd)
4118 if (hwaddr_aton(cmd, addr))
4121 return wpas_p2p_reject(wpa_s, addr);
4125 static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd)
4129 struct wpa_ssid *ssid;
4130 u8 *_peer = NULL, peer[ETH_ALEN];
4131 int freq = 0, pref_freq = 0;
4135 pos = os_strstr(cmd, " peer=");
4138 if (hwaddr_aton(pos, peer))
4142 ssid = wpa_config_get_network(wpa_s->conf, id);
4143 if (ssid == NULL || ssid->disabled != 2) {
4144 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
4145 "for persistent P2P group",
4150 pos = os_strstr(cmd, " freq=");
4158 pos = os_strstr(cmd, " pref=");
4161 pref_freq = atoi(pos);
4166 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
4167 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
4170 return wpas_p2p_invite(wpa_s, _peer, ssid, NULL, freq, ht40, vht,
4175 static int p2p_ctrl_invite_group(struct wpa_supplicant *wpa_s, char *cmd)
4178 u8 peer[ETH_ALEN], go_dev_addr[ETH_ALEN], *go_dev = NULL;
4180 pos = os_strstr(cmd, " peer=");
4186 if (hwaddr_aton(pos, peer)) {
4187 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", pos);
4191 pos = os_strstr(pos, " go_dev_addr=");
4194 if (hwaddr_aton(pos, go_dev_addr)) {
4195 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'",
4199 go_dev = go_dev_addr;
4202 return wpas_p2p_invite_group(wpa_s, cmd, peer, go_dev);
4206 static int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd)
4208 if (os_strncmp(cmd, "persistent=", 11) == 0)
4209 return p2p_ctrl_invite_persistent(wpa_s, cmd + 11);
4210 if (os_strncmp(cmd, "group=", 6) == 0)
4211 return p2p_ctrl_invite_group(wpa_s, cmd + 6);
4217 static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s,
4218 char *cmd, int freq, int ht40,
4222 struct wpa_ssid *ssid;
4225 ssid = wpa_config_get_network(wpa_s->conf, id);
4226 if (ssid == NULL || ssid->disabled != 2) {
4227 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
4228 "for persistent P2P group",
4233 return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq, ht40, vht,
4238 static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd)
4240 int freq = 0, ht40, vht;
4243 pos = os_strstr(cmd, "freq=");
4245 freq = atoi(pos + 5);
4247 vht = (os_strstr(cmd, "vht") != NULL) || wpa_s->conf->p2p_go_vht;
4248 ht40 = (os_strstr(cmd, "ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
4251 if (os_strncmp(cmd, "persistent=", 11) == 0)
4252 return p2p_ctrl_group_add_persistent(wpa_s, cmd + 11, freq,
4254 if (os_strcmp(cmd, "persistent") == 0 ||
4255 os_strncmp(cmd, "persistent ", 11) == 0)
4256 return wpas_p2p_group_add(wpa_s, 1, freq, ht40, vht);
4257 if (os_strncmp(cmd, "freq=", 5) == 0)
4258 return wpas_p2p_group_add(wpa_s, 0, freq, ht40, vht);
4260 return wpas_p2p_group_add(wpa_s, 0, freq, ht40, vht);
4262 wpa_printf(MSG_DEBUG, "CTRL: Invalid P2P_GROUP_ADD parameters '%s'",
4268 static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd,
4269 char *buf, size_t buflen)
4271 u8 addr[ETH_ALEN], *addr_ptr;
4273 const struct p2p_peer_info *info;
4275 char devtype[WPS_DEV_TYPE_BUFSIZE];
4276 struct wpa_ssid *ssid;
4279 if (!wpa_s->global->p2p)
4282 if (os_strcmp(cmd, "FIRST") == 0) {
4285 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
4286 if (hwaddr_aton(cmd + 5, addr) < 0)
4291 if (hwaddr_aton(cmd, addr) < 0)
4297 info = p2p_get_peer_info(wpa_s->global->p2p, addr_ptr, next);
4304 res = os_snprintf(pos, end - pos, MACSTR "\n"
4310 "serial_number=%s\n"
4311 "config_methods=0x%x\n"
4313 "group_capab=0x%x\n"
4315 MAC2STR(info->p2p_device_addr),
4316 wps_dev_type_bin2str(info->pri_dev_type,
4317 devtype, sizeof(devtype)),
4322 info->serial_number,
4323 info->config_methods,
4327 if (res < 0 || res >= end - pos)
4331 for (i = 0; i < info->wps_sec_dev_type_list_len / WPS_DEV_TYPE_LEN; i++)
4334 t = &info->wps_sec_dev_type_list[i * WPS_DEV_TYPE_LEN];
4335 res = os_snprintf(pos, end - pos, "sec_dev_type=%s\n",
4336 wps_dev_type_bin2str(t, devtype,
4338 if (res < 0 || res >= end - pos)
4343 ssid = wpas_p2p_get_persistent(wpa_s, info->p2p_device_addr, NULL, 0);
4345 res = os_snprintf(pos, end - pos, "persistent=%d\n", ssid->id);
4346 if (res < 0 || res >= end - pos)
4351 res = p2p_get_peer_info_txt(info, pos, end - pos);
4360 static int p2p_ctrl_disallow_freq(struct wpa_supplicant *wpa_s,
4365 if (wpa_s->global->p2p == NULL)
4368 if (freq_range_list_parse(&wpa_s->global->p2p_disallow_freq, param) < 0)
4371 for (i = 0; i < wpa_s->global->p2p_disallow_freq.num; i++) {
4372 struct wpa_freq_range *freq;
4373 freq = &wpa_s->global->p2p_disallow_freq.range[i];
4374 wpa_printf(MSG_DEBUG, "P2P: Disallowed frequency range %u-%u",
4375 freq->min, freq->max);
4378 wpas_p2p_update_channel_list(wpa_s);
4383 static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd)
4387 if (wpa_s->global->p2p == NULL)
4390 param = os_strchr(cmd, ' ');
4395 if (os_strcmp(cmd, "discoverability") == 0) {
4396 p2p_set_client_discoverability(wpa_s->global->p2p,
4401 if (os_strcmp(cmd, "managed") == 0) {
4402 p2p_set_managed_oper(wpa_s->global->p2p, atoi(param));
4406 if (os_strcmp(cmd, "listen_channel") == 0) {
4407 return p2p_set_listen_channel(wpa_s->global->p2p, 81,
4411 if (os_strcmp(cmd, "ssid_postfix") == 0) {
4412 return p2p_set_ssid_postfix(wpa_s->global->p2p, (u8 *) param,
4416 if (os_strcmp(cmd, "noa") == 0) {
4418 int count, start, duration;
4419 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
4420 count = atoi(param);
4421 pos = os_strchr(param, ',');
4426 pos = os_strchr(pos, ',');
4430 duration = atoi(pos);
4431 if (count < 0 || count > 255 || start < 0 || duration < 0)
4433 if (count == 0 && duration > 0)
4435 wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
4436 "start=%d duration=%d", count, start, duration);
4437 return wpas_p2p_set_noa(wpa_s, count, start, duration);
4440 if (os_strcmp(cmd, "ps") == 0)
4441 return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1);
4443 if (os_strcmp(cmd, "oppps") == 0)
4444 return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1);
4446 if (os_strcmp(cmd, "ctwindow") == 0)
4447 return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param));
4449 if (os_strcmp(cmd, "disabled") == 0) {
4450 wpa_s->global->p2p_disabled = atoi(param);
4451 wpa_printf(MSG_DEBUG, "P2P functionality %s",
4452 wpa_s->global->p2p_disabled ?
4453 "disabled" : "enabled");
4454 if (wpa_s->global->p2p_disabled) {
4455 wpas_p2p_stop_find(wpa_s);
4456 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
4457 p2p_flush(wpa_s->global->p2p);
4462 if (os_strcmp(cmd, "conc_pref") == 0) {
4463 if (os_strcmp(param, "sta") == 0)
4464 wpa_s->global->conc_pref = WPA_CONC_PREF_STA;
4465 else if (os_strcmp(param, "p2p") == 0)
4466 wpa_s->global->conc_pref = WPA_CONC_PREF_P2P;
4468 wpa_printf(MSG_INFO, "Invalid conc_pref value");
4471 wpa_printf(MSG_DEBUG, "Single channel concurrency preference: "
4476 if (os_strcmp(cmd, "force_long_sd") == 0) {
4477 wpa_s->force_long_sd = atoi(param);
4481 if (os_strcmp(cmd, "peer_filter") == 0) {
4483 if (hwaddr_aton(param, addr))
4485 p2p_set_peer_filter(wpa_s->global->p2p, addr);
4489 if (os_strcmp(cmd, "cross_connect") == 0)
4490 return wpas_p2p_set_cross_connect(wpa_s, atoi(param));
4492 if (os_strcmp(cmd, "go_apsd") == 0) {
4493 if (os_strcmp(param, "disable") == 0)
4494 wpa_s->set_ap_uapsd = 0;
4496 wpa_s->set_ap_uapsd = 1;
4497 wpa_s->ap_uapsd = atoi(param);
4502 if (os_strcmp(cmd, "client_apsd") == 0) {
4503 if (os_strcmp(param, "disable") == 0)
4504 wpa_s->set_sta_uapsd = 0;
4508 /* format: BE,BK,VI,VO;max SP Length */
4510 pos = os_strchr(param, ',');
4515 pos = os_strchr(pos, ',');
4520 pos = os_strchr(pos, ',');
4525 /* ignore max SP Length for now */
4527 wpa_s->set_sta_uapsd = 1;
4528 wpa_s->sta_uapsd = 0;
4530 wpa_s->sta_uapsd |= BIT(0);
4532 wpa_s->sta_uapsd |= BIT(1);
4534 wpa_s->sta_uapsd |= BIT(2);
4536 wpa_s->sta_uapsd |= BIT(3);
4541 if (os_strcmp(cmd, "disallow_freq") == 0)
4542 return p2p_ctrl_disallow_freq(wpa_s, param);
4544 if (os_strcmp(cmd, "disc_int") == 0) {
4545 int min_disc_int, max_disc_int, max_disc_tu;
4550 min_disc_int = atoi(pos);
4551 pos = os_strchr(pos, ' ');
4556 max_disc_int = atoi(pos);
4557 pos = os_strchr(pos, ' ');
4562 max_disc_tu = atoi(pos);
4564 return p2p_set_disc_int(wpa_s->global->p2p, min_disc_int,
4565 max_disc_int, max_disc_tu);
4568 if (os_strcmp(cmd, "per_sta_psk") == 0) {
4569 wpa_s->global->p2p_per_sta_psk = !!atoi(param);
4573 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
4580 static void p2p_ctrl_flush(struct wpa_supplicant *wpa_s)
4582 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
4583 wpa_s->force_long_sd = 0;
4584 if (wpa_s->global->p2p)
4585 p2p_flush(wpa_s->global->p2p);
4589 static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd)
4592 unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0;
4595 pos = os_strchr(cmd, ' ');
4601 pos2 = os_strchr(pos, ' ');
4609 pos = os_strchr(pos2, ' ');
4617 return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2);
4621 static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd)
4624 unsigned int period = 0, interval = 0;
4627 pos = os_strchr(cmd, ' ');
4632 interval = atoi(pos);
4635 return wpas_p2p_ext_listen(wpa_s, period, interval);
4639 static int p2p_ctrl_remove_client(struct wpa_supplicant *wpa_s, const char *cmd)
4646 if (os_strncmp(pos, "iface=", 6) == 0) {
4650 if (hwaddr_aton(pos, peer))
4653 wpas_p2p_remove_client(wpa_s, peer, iface_addr);
4657 #endif /* CONFIG_P2P */
4660 #ifdef CONFIG_INTERWORKING
4661 static int ctrl_interworking_connect(struct wpa_supplicant *wpa_s, char *dst)
4664 struct wpa_bss *bss;
4666 if (hwaddr_aton(dst, bssid)) {
4667 wpa_printf(MSG_DEBUG, "Invalid BSSID '%s'", dst);
4671 bss = wpa_bss_get_bssid(wpa_s, bssid);
4673 wpa_printf(MSG_DEBUG, "Could not find BSS " MACSTR,
4678 return interworking_connect(wpa_s, bss);
4682 static int get_anqp(struct wpa_supplicant *wpa_s, char *dst)
4684 u8 dst_addr[ETH_ALEN];
4687 #define MAX_ANQP_INFO_ID 100
4688 u16 id[MAX_ANQP_INFO_ID];
4691 used = hwaddr_aton2(dst, dst_addr);
4695 while (num_id < MAX_ANQP_INFO_ID) {
4696 id[num_id] = atoi(pos);
4699 pos = os_strchr(pos + 1, ',');
4708 return anqp_send_req(wpa_s, dst_addr, id, num_id);
4712 static int gas_request(struct wpa_supplicant *wpa_s, char *cmd)
4714 u8 dst_addr[ETH_ALEN];
4715 struct wpabuf *advproto, *query = NULL;
4720 used = hwaddr_aton2(cmd, dst_addr);
4728 /* Advertisement Protocol ID */
4729 end = os_strchr(pos, ' ');
4733 len = os_strlen(pos);
4739 advproto = wpabuf_alloc(len);
4740 if (advproto == NULL)
4742 if (hexstr2bin(pos, wpabuf_put(advproto, len), len) < 0)
4746 /* Optional Query Request */
4751 len = os_strlen(pos);
4758 query = wpabuf_alloc(len);
4761 if (hexstr2bin(pos, wpabuf_put(query, len), len) < 0)
4766 ret = gas_send_request(wpa_s, dst_addr, advproto, query);
4769 wpabuf_free(advproto);
4776 static int gas_response_get(struct wpa_supplicant *wpa_s, char *cmd, char *buf,
4783 size_t resp_len, start, requested_len;
4785 if (!wpa_s->last_gas_resp)
4788 used = hwaddr_aton2(cmd, addr);
4795 dialog_token = atoi(pos);
4797 if (os_memcmp(addr, wpa_s->last_gas_addr, ETH_ALEN) != 0 ||
4798 dialog_token != wpa_s->last_gas_dialog_token)
4801 resp_len = wpabuf_len(wpa_s->last_gas_resp);
4803 requested_len = resp_len;
4805 pos = os_strchr(pos, ' ');
4808 if (start > resp_len)
4809 return os_snprintf(buf, buflen, "FAIL-Invalid range");
4810 pos = os_strchr(pos, ',');
4814 requested_len = atoi(pos);
4815 if (start + requested_len > resp_len)
4816 return os_snprintf(buf, buflen, "FAIL-Invalid range");
4819 if (requested_len * 2 + 1 > buflen)
4820 return os_snprintf(buf, buflen, "FAIL-Too long response");
4822 return wpa_snprintf_hex(buf, buflen,
4823 wpabuf_head_u8(wpa_s->last_gas_resp) + start,
4826 #endif /* CONFIG_INTERWORKING */
4831 static int get_hs20_anqp(struct wpa_supplicant *wpa_s, char *dst)
4833 u8 dst_addr[ETH_ALEN];
4838 used = hwaddr_aton2(dst, dst_addr);
4843 int num = atoi(pos);
4844 if (num <= 0 || num > 31)
4846 subtypes |= BIT(num);
4847 pos = os_strchr(pos + 1, ',');
4856 return hs20_anqp_send_req(wpa_s, dst_addr, subtypes, NULL, 0);
4860 static int hs20_nai_home_realm_list(struct wpa_supplicant *wpa_s,
4861 const u8 *addr, const char *realm)
4867 rlen = os_strlen(realm);
4869 buf = os_malloc(len);
4872 buf[0] = 1; /* NAI Home Realm Count */
4873 buf[1] = 0; /* Formatted in accordance with RFC 4282 */
4875 os_memcpy(buf + 3, realm, rlen);
4877 ret = hs20_anqp_send_req(wpa_s, addr,
4878 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
4887 static int hs20_get_nai_home_realm_list(struct wpa_supplicant *wpa_s,
4890 struct wpa_cred *cred = wpa_s->conf->cred;
4891 u8 dst_addr[ETH_ALEN];
4897 used = hwaddr_aton2(dst, dst_addr);
4901 while (dst[used] == ' ')
4903 if (os_strncmp(dst + used, "realm=", 6) == 0)
4904 return hs20_nai_home_realm_list(wpa_s, dst_addr,
4907 len = os_strlen(dst + used);
4909 if (len == 0 && cred && cred->realm)
4910 return hs20_nai_home_realm_list(wpa_s, dst_addr, cred->realm);
4915 buf = os_malloc(len);
4918 if (hexstr2bin(dst + used, buf, len) < 0) {
4923 ret = hs20_anqp_send_req(wpa_s, dst_addr,
4924 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
4931 #endif /* CONFIG_HS20 */
4934 static int wpa_supplicant_ctrl_iface_sta_autoconnect(
4935 struct wpa_supplicant *wpa_s, char *cmd)
4937 wpa_s->auto_reconnect_disabled = atoi(cmd) == 0 ? 1 : 0;
4942 #ifdef CONFIG_AUTOSCAN
4944 static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant *wpa_s,
4947 enum wpa_states state = wpa_s->wpa_state;
4948 char *new_params = NULL;
4950 if (os_strlen(cmd) > 0) {
4951 new_params = os_strdup(cmd);
4952 if (new_params == NULL)
4956 os_free(wpa_s->conf->autoscan);
4957 wpa_s->conf->autoscan = new_params;
4959 if (wpa_s->conf->autoscan == NULL)
4960 autoscan_deinit(wpa_s);
4961 else if (state == WPA_DISCONNECTED || state == WPA_INACTIVE)
4962 autoscan_init(wpa_s, 1);
4963 else if (state == WPA_SCANNING)
4964 wpa_supplicant_reinit_autoscan(wpa_s);
4969 #endif /* CONFIG_AUTOSCAN */
4974 static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant *wpa_s, char *cmd)
4980 struct wpabuf *tfs_req = NULL;
4982 if (os_strncmp(cmd, "enter", 5) == 0)
4984 else if (os_strncmp(cmd, "exit", 4) == 0)
4989 pos = os_strstr(cmd, " interval=");
4991 intval = atoi(pos + 10);
4993 pos = os_strstr(cmd, " tfs_req=");
4998 end = os_strchr(pos, ' ');
5002 len = os_strlen(pos);
5006 tfs_req = wpabuf_alloc(len);
5007 if (tfs_req == NULL)
5009 if (hexstr2bin(pos, wpabuf_put(tfs_req, len), len) < 0) {
5010 wpabuf_free(tfs_req);
5015 ret = ieee802_11_send_wnmsleep_req(wpa_s, enter ? WNM_SLEEP_MODE_ENTER :
5016 WNM_SLEEP_MODE_EXIT, intval,
5018 wpabuf_free(tfs_req);
5024 static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant *wpa_s, char *cmd)
5028 query_reason = atoi(cmd);
5030 wpa_printf(MSG_DEBUG, "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d",
5033 return wnm_send_bss_transition_mgmt_query(wpa_s, query_reason);
5036 #endif /* CONFIG_WNM */
5039 /* Get string representation of channel width */
5040 static const char * channel_width_name(enum chan_width width)
5043 case CHAN_WIDTH_20_NOHT:
5044 return "20 MHz (no HT)";
5051 case CHAN_WIDTH_80P80:
5053 case CHAN_WIDTH_160:
5061 static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf,
5064 struct wpa_signal_info si;
5068 ret = wpa_drv_signal_poll(wpa_s, &si);
5075 ret = os_snprintf(pos, end - pos, "RSSI=%d\nLINKSPEED=%d\n"
5076 "NOISE=%d\nFREQUENCY=%u\n",
5077 si.current_signal, si.current_txrate / 1000,
5078 si.current_noise, si.frequency);
5079 if (ret < 0 || ret > end - pos)
5083 if (si.chanwidth != CHAN_WIDTH_UNKNOWN) {
5084 ret = os_snprintf(pos, end - pos, "WIDTH=%s\n",
5085 channel_width_name(si.chanwidth));
5086 if (ret < 0 || ret > end - pos)
5091 if (si.center_frq1 > 0 && si.center_frq2 > 0) {
5092 ret = os_snprintf(pos, end - pos,
5093 "CENTER_FRQ1=%d\nCENTER_FRQ2=%d\n",
5094 si.center_frq1, si.center_frq2);
5095 if (ret < 0 || ret > end - pos)
5100 if (si.avg_signal) {
5101 ret = os_snprintf(pos, end - pos,
5102 "AVG_RSSI=%d\n", si.avg_signal);
5103 if (ret < 0 || ret >= end - pos)
5112 static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant *wpa_s, char *buf,
5115 struct hostap_sta_driver_data sta;
5118 ret = wpa_drv_pktcnt_poll(wpa_s, &sta);
5122 ret = os_snprintf(buf, buflen, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
5123 sta.tx_packets, sta.tx_retry_failed, sta.rx_packets);
5124 if (ret < 0 || (size_t) ret > buflen)
5131 static int wpa_supplicant_driver_cmd(struct wpa_supplicant *wpa_s, char *cmd,
5132 char *buf, size_t buflen)
5136 ret = wpa_drv_driver_cmd(wpa_s, cmd, buf, buflen);
5138 if (os_strncasecmp(cmd, "COUNTRY", 7) == 0) {
5139 struct p2p_data *p2p = wpa_s->global->p2p;
5142 country[0] = cmd[8];
5143 country[1] = cmd[9];
5145 p2p_set_country(p2p, country);
5148 ret = os_snprintf(buf, buflen, "%s\n", "OK");
5152 #endif /* ANDROID */
5155 static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s)
5157 wpa_dbg(wpa_s, MSG_DEBUG, "Flush all wpa_supplicant state");
5160 wpas_p2p_stop_find(wpa_s);
5161 p2p_ctrl_flush(wpa_s);
5162 wpas_p2p_group_remove(wpa_s, "*");
5163 #endif /* CONFIG_P2P */
5165 #ifdef CONFIG_WPS_TESTING
5166 wps_version_number = 0x20;
5167 wps_testing_dummy_cred = 0;
5168 #endif /* CONFIG_WPS_TESTING */
5170 wpas_wps_cancel(wpa_s);
5171 #endif /* CONFIG_WPS */
5172 wpa_s->after_wps = 0;
5173 wpa_s->known_wps_freq = 0;
5175 #ifdef CONFIG_TDLS_TESTING
5176 extern unsigned int tdls_testing;
5178 #endif /* CONFIG_TDLS_TESTING */
5180 wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL);
5181 wpa_tdls_enable(wpa_s->wpa, 1);
5182 #endif /* CONFIG_TDLS */
5184 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, wpa_s, NULL);
5185 wpa_supplicant_stop_countermeasures(wpa_s, NULL);
5187 wpa_s->no_keep_alive = 0;
5189 os_free(wpa_s->disallow_aps_bssid);
5190 wpa_s->disallow_aps_bssid = NULL;
5191 wpa_s->disallow_aps_bssid_count = 0;
5192 os_free(wpa_s->disallow_aps_ssid);
5193 wpa_s->disallow_aps_ssid = NULL;
5194 wpa_s->disallow_aps_ssid_count = 0;
5196 wpa_s->set_sta_uapsd = 0;
5197 wpa_s->sta_uapsd = 0;
5199 wpa_drv_radio_disable(wpa_s, 0);
5201 wpa_bss_flush(wpa_s);
5202 wpa_blacklist_clear(wpa_s);
5203 wpa_s->extra_blacklist_count = 0;
5204 wpa_supplicant_ctrl_iface_remove_network(wpa_s, "all");
5205 wpa_supplicant_ctrl_iface_remove_cred(wpa_s, "all");
5209 static void wpas_ctrl_eapol_response(void *eloop_ctx, void *timeout_ctx)
5211 struct wpa_supplicant *wpa_s = eloop_ctx;
5212 eapol_sm_notify_ctrl_response(wpa_s->eapol);
5216 static int set_scan_freqs(struct wpa_supplicant *wpa_s, char *val)
5218 struct wpa_freq_range_list ranges;
5220 struct hostapd_hw_modes *mode;
5223 if (wpa_s->hw.modes == NULL)
5226 os_memset(&ranges, 0, sizeof(ranges));
5227 if (freq_range_list_parse(&ranges, val) < 0)
5230 for (i = 0; i < wpa_s->hw.num_modes; i++) {
5233 mode = &wpa_s->hw.modes[i];
5234 for (j = 0; j < mode->num_channels; j++) {
5237 if (mode->channels[j].flag & HOSTAPD_CHAN_DISABLED)
5240 freq = mode->channels[j].freq;
5241 if (!freq_range_list_includes(&ranges, freq))
5244 int_array_add_unique(&freqs, freq);
5248 os_free(ranges.range);
5249 os_free(wpa_s->manual_scan_freqs);
5250 wpa_s->manual_scan_freqs = freqs;
5256 static void wpas_ctrl_scan(struct wpa_supplicant *wpa_s, char *params,
5257 char *reply, int reply_size, int *reply_len)
5261 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
5266 wpa_s->manual_scan_passive = 0;
5269 if (os_strncasecmp(params, "TYPE=ONLY", 9) == 0)
5270 wpa_s->scan_res_handler = scan_only_handler;
5272 pos = os_strstr(params, "freq=");
5273 if (pos && set_scan_freqs(wpa_s, pos + 5) < 0) {
5278 pos = os_strstr(params, "passive=");
5280 wpa_s->manual_scan_passive = !!atoi(pos + 8);
5282 os_free(wpa_s->manual_scan_freqs);
5283 wpa_s->manual_scan_freqs = NULL;
5284 if (wpa_s->scan_res_handler == scan_only_handler)
5285 wpa_s->scan_res_handler = NULL;
5288 if (!wpa_s->sched_scanning && !wpa_s->scanning &&
5289 ((wpa_s->wpa_state <= WPA_SCANNING) ||
5290 (wpa_s->wpa_state == WPA_COMPLETED))) {
5291 wpa_s->normal_scans = 0;
5292 wpa_s->scan_req = MANUAL_SCAN_REQ;
5293 wpa_s->after_wps = 0;
5294 wpa_s->known_wps_freq = 0;
5295 wpa_supplicant_req_scan(wpa_s, 0, 0);
5296 } else if (wpa_s->sched_scanning) {
5297 wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to allow requested full scan to proceed");
5298 wpa_supplicant_cancel_sched_scan(wpa_s);
5299 wpa_s->scan_req = MANUAL_SCAN_REQ;
5300 wpa_supplicant_req_scan(wpa_s, 0, 0);
5302 wpa_printf(MSG_DEBUG, "Ongoing scan action - reject new request");
5303 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
5308 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
5309 char *buf, size_t *resp_len)
5312 const int reply_size = 4096;
5315 if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 ||
5316 os_strncmp(buf, "SET_NETWORK ", 12) == 0 ||
5317 os_strncmp(buf, "WPS_NFC_TAG_READ", 16) == 0 ||
5318 os_strncmp(buf, "NFC_REPORT_HANDOVER", 19) == 0 ||
5319 os_strncmp(buf, "NFC_RX_HANDOVER_SEL", 19) == 0) {
5320 wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface",
5321 (const u8 *) buf, os_strlen(buf));
5323 int level = MSG_DEBUG;
5324 if (os_strcmp(buf, "PING") == 0)
5325 level = MSG_EXCESSIVE;
5326 wpa_hexdump_ascii(level, "RX ctrl_iface",
5327 (const u8 *) buf, os_strlen(buf));
5328 wpa_dbg(wpa_s, level, "Control interface command '%s'", buf);
5331 reply = os_malloc(reply_size);
5332 if (reply == NULL) {
5337 os_memcpy(reply, "OK\n", 3);
5340 if (os_strcmp(buf, "PING") == 0) {
5341 os_memcpy(reply, "PONG\n", 5);
5343 } else if (os_strcmp(buf, "IFNAME") == 0) {
5344 reply_len = os_strlen(wpa_s->ifname);
5345 os_memcpy(reply, wpa_s->ifname, reply_len);
5346 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
5347 if (wpa_debug_reopen_file() < 0)
5349 } else if (os_strncmp(buf, "NOTE ", 5) == 0) {
5350 wpa_printf(MSG_INFO, "NOTE: %s", buf + 5);
5351 } else if (os_strcmp(buf, "MIB") == 0) {
5352 reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size);
5353 if (reply_len >= 0) {
5355 res = eapol_sm_get_mib(wpa_s->eapol, reply + reply_len,
5356 reply_size - reply_len);
5362 } else if (os_strncmp(buf, "STATUS", 6) == 0) {
5363 reply_len = wpa_supplicant_ctrl_iface_status(
5364 wpa_s, buf + 6, reply, reply_size);
5365 } else if (os_strcmp(buf, "PMKSA") == 0) {
5366 reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, reply,
5368 } else if (os_strncmp(buf, "SET ", 4) == 0) {
5369 if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4))
5371 } else if (os_strncmp(buf, "GET ", 4) == 0) {
5372 reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4,
5374 } else if (os_strcmp(buf, "LOGON") == 0) {
5375 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
5376 } else if (os_strcmp(buf, "LOGOFF") == 0) {
5377 eapol_sm_notify_logoff(wpa_s->eapol, TRUE);
5378 } else if (os_strcmp(buf, "REASSOCIATE") == 0) {
5379 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
5382 wpas_request_connection(wpa_s);
5383 } else if (os_strcmp(buf, "RECONNECT") == 0) {
5384 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
5386 else if (wpa_s->disconnected)
5387 wpas_request_connection(wpa_s);
5388 #ifdef IEEE8021X_EAPOL
5389 } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) {
5390 if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8))
5392 #endif /* IEEE8021X_EAPOL */
5393 #ifdef CONFIG_PEERKEY
5394 } else if (os_strncmp(buf, "STKSTART ", 9) == 0) {
5395 if (wpa_supplicant_ctrl_iface_stkstart(wpa_s, buf + 9))
5397 #endif /* CONFIG_PEERKEY */
5398 #ifdef CONFIG_IEEE80211R
5399 } else if (os_strncmp(buf, "FT_DS ", 6) == 0) {
5400 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6))
5402 #endif /* CONFIG_IEEE80211R */
5404 } else if (os_strcmp(buf, "WPS_PBC") == 0) {
5405 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL);
5407 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
5411 } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) {
5412 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8);
5414 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
5418 } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {
5419 reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8,
5422 } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) {
5423 reply_len = wpa_supplicant_ctrl_iface_wps_check_pin(
5424 wpa_s, buf + 14, reply, reply_size);
5425 } else if (os_strcmp(buf, "WPS_CANCEL") == 0) {
5426 if (wpas_wps_cancel(wpa_s))
5428 #ifdef CONFIG_WPS_NFC
5429 } else if (os_strcmp(buf, "WPS_NFC") == 0) {
5430 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, NULL))
5432 } else if (os_strncmp(buf, "WPS_NFC ", 8) == 0) {
5433 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, buf + 8))
5435 } else if (os_strncmp(buf, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
5436 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_config_token(
5437 wpa_s, buf + 21, reply, reply_size);
5438 } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) {
5439 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_token(
5440 wpa_s, buf + 14, reply, reply_size);
5441 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) {
5442 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s,
5445 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
5446 reply_len = wpas_ctrl_nfc_get_handover_req(
5447 wpa_s, buf + 21, reply, reply_size);
5448 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
5449 reply_len = wpas_ctrl_nfc_get_handover_sel(
5450 wpa_s, buf + 21, reply, reply_size);
5451 } else if (os_strncmp(buf, "NFC_RX_HANDOVER_REQ ", 20) == 0) {
5452 reply_len = wpas_ctrl_nfc_rx_handover_req(
5453 wpa_s, buf + 20, reply, reply_size);
5454 } else if (os_strncmp(buf, "NFC_RX_HANDOVER_SEL ", 20) == 0) {
5455 if (wpas_ctrl_nfc_rx_handover_sel(wpa_s, buf + 20))
5457 } else if (os_strncmp(buf, "NFC_REPORT_HANDOVER ", 20) == 0) {
5458 if (wpas_ctrl_nfc_report_handover(wpa_s, buf + 20))
5460 #endif /* CONFIG_WPS_NFC */
5461 } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) {
5462 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8))
5465 } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) {
5466 reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin(
5467 wpa_s, buf + 11, reply, reply_size);
5468 #endif /* CONFIG_AP */
5469 #ifdef CONFIG_WPS_ER
5470 } else if (os_strcmp(buf, "WPS_ER_START") == 0) {
5471 if (wpas_wps_er_start(wpa_s, NULL))
5473 } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) {
5474 if (wpas_wps_er_start(wpa_s, buf + 13))
5476 } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) {
5477 if (wpas_wps_er_stop(wpa_s))
5479 } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) {
5480 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11))
5482 } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) {
5483 int ret = wpas_wps_er_pbc(wpa_s, buf + 11);
5485 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
5487 } else if (ret == -3) {
5488 os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18);
5490 } else if (ret == -4) {
5491 os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20);
5495 } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) {
5496 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13))
5498 } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) {
5499 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s,
5502 } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) {
5503 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14))
5505 #ifdef CONFIG_WPS_NFC
5506 } else if (os_strncmp(buf, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
5507 reply_len = wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
5508 wpa_s, buf + 24, reply, reply_size);
5509 #endif /* CONFIG_WPS_NFC */
5510 #endif /* CONFIG_WPS_ER */
5511 #endif /* CONFIG_WPS */
5512 #ifdef CONFIG_IBSS_RSN
5513 } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) {
5514 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9))
5516 #endif /* CONFIG_IBSS_RSN */
5518 } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) {
5519 if (p2p_ctrl_find(wpa_s, buf + 9))
5521 } else if (os_strcmp(buf, "P2P_FIND") == 0) {
5522 if (p2p_ctrl_find(wpa_s, ""))
5524 } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) {
5525 wpas_p2p_stop_find(wpa_s);
5526 } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) {
5527 reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply,
5529 } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) {
5530 if (p2p_ctrl_listen(wpa_s, buf + 11))
5532 } else if (os_strcmp(buf, "P2P_LISTEN") == 0) {
5533 if (p2p_ctrl_listen(wpa_s, ""))
5535 } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) {
5536 if (wpas_p2p_group_remove(wpa_s, buf + 17))
5538 } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) {
5539 if (wpas_p2p_group_add(wpa_s, 0, 0, 0, 0))
5541 } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) {
5542 if (p2p_ctrl_group_add(wpa_s, buf + 14))
5544 } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) {
5545 if (p2p_ctrl_prov_disc(wpa_s, buf + 14))
5547 } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) {
5548 reply_len = p2p_get_passphrase(wpa_s, reply, reply_size);
5549 } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) {
5550 reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply,
5552 } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
5553 if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0)
5555 } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) {
5556 if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0)
5558 } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) {
5559 wpas_p2p_sd_service_update(wpa_s);
5560 } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
5561 if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0)
5563 } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) {
5564 wpas_p2p_service_flush(wpa_s);
5565 } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) {
5566 if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0)
5568 } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) {
5569 if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0)
5571 } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) {
5572 if (p2p_ctrl_reject(wpa_s, buf + 11) < 0)
5574 } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) {
5575 if (p2p_ctrl_invite(wpa_s, buf + 11) < 0)
5577 } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) {
5578 reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply,
5580 } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) {
5581 if (p2p_ctrl_set(wpa_s, buf + 8) < 0)
5583 } else if (os_strcmp(buf, "P2P_FLUSH") == 0) {
5584 p2p_ctrl_flush(wpa_s);
5585 } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) {
5586 if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0)
5588 } else if (os_strcmp(buf, "P2P_CANCEL") == 0) {
5589 if (wpas_p2p_cancel(wpa_s))
5591 } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) {
5592 if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0)
5594 } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) {
5595 if (p2p_ctrl_presence_req(wpa_s, "") < 0)
5597 } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) {
5598 if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0)
5600 } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) {
5601 if (p2p_ctrl_ext_listen(wpa_s, "") < 0)
5603 } else if (os_strncmp(buf, "P2P_REMOVE_CLIENT ", 18) == 0) {
5604 if (p2p_ctrl_remove_client(wpa_s, buf + 18) < 0)
5606 #endif /* CONFIG_P2P */
5607 #ifdef CONFIG_WIFI_DISPLAY
5608 } else if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0) {
5609 if (wifi_display_subelem_set(wpa_s->global, buf + 16) < 0)
5611 } else if (os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) {
5612 reply_len = wifi_display_subelem_get(wpa_s->global, buf + 16,
5614 #endif /* CONFIG_WIFI_DISPLAY */
5615 #ifdef CONFIG_INTERWORKING
5616 } else if (os_strcmp(buf, "FETCH_ANQP") == 0) {
5617 if (interworking_fetch_anqp(wpa_s) < 0)
5619 } else if (os_strcmp(buf, "STOP_FETCH_ANQP") == 0) {
5620 interworking_stop_fetch_anqp(wpa_s);
5621 } else if (os_strncmp(buf, "INTERWORKING_SELECT", 19) == 0) {
5622 if (interworking_select(wpa_s, os_strstr(buf + 19, "auto") !=
5625 } else if (os_strncmp(buf, "INTERWORKING_CONNECT ", 21) == 0) {
5626 if (ctrl_interworking_connect(wpa_s, buf + 21) < 0)
5628 } else if (os_strncmp(buf, "ANQP_GET ", 9) == 0) {
5629 if (get_anqp(wpa_s, buf + 9) < 0)
5631 } else if (os_strncmp(buf, "GAS_REQUEST ", 12) == 0) {
5632 if (gas_request(wpa_s, buf + 12) < 0)
5634 } else if (os_strncmp(buf, "GAS_RESPONSE_GET ", 17) == 0) {
5635 reply_len = gas_response_get(wpa_s, buf + 17, reply,
5637 #endif /* CONFIG_INTERWORKING */
5639 } else if (os_strncmp(buf, "HS20_ANQP_GET ", 14) == 0) {
5640 if (get_hs20_anqp(wpa_s, buf + 14) < 0)
5642 } else if (os_strncmp(buf, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
5643 if (hs20_get_nai_home_realm_list(wpa_s, buf + 29) < 0)
5645 #endif /* CONFIG_HS20 */
5646 } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0)
5648 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
5649 wpa_s, buf + os_strlen(WPA_CTRL_RSP)))
5653 * Notify response from timeout to allow the control
5654 * interface response to be sent first.
5656 eloop_register_timeout(0, 0, wpas_ctrl_eapol_response,
5659 } else if (os_strcmp(buf, "RECONFIGURE") == 0) {
5660 if (wpa_supplicant_reload_configuration(wpa_s))
5662 } else if (os_strcmp(buf, "TERMINATE") == 0) {
5663 wpa_supplicant_terminate_proc(wpa_s->global);
5664 } else if (os_strncmp(buf, "BSSID ", 6) == 0) {
5665 if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6))
5667 } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) {
5668 reply_len = wpa_supplicant_ctrl_iface_blacklist(
5669 wpa_s, buf + 9, reply, reply_size);
5670 } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) {
5671 reply_len = wpa_supplicant_ctrl_iface_log_level(
5672 wpa_s, buf + 9, reply, reply_size);
5673 } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) {
5674 reply_len = wpa_supplicant_ctrl_iface_list_networks(
5675 wpa_s, reply, reply_size);
5676 } else if (os_strcmp(buf, "DISCONNECT") == 0) {
5678 wpa_s->sme.prev_bssid_set = 0;
5679 #endif /* CONFIG_SME */
5680 wpa_s->reassociate = 0;
5681 wpa_s->disconnected = 1;
5682 wpa_supplicant_cancel_sched_scan(wpa_s);
5683 wpa_supplicant_cancel_scan(wpa_s);
5684 wpa_supplicant_deauthenticate(wpa_s,
5685 WLAN_REASON_DEAUTH_LEAVING);
5686 } else if (os_strcmp(buf, "SCAN") == 0) {
5687 wpas_ctrl_scan(wpa_s, NULL, reply, reply_size, &reply_len);
5688 } else if (os_strncmp(buf, "SCAN ", 5) == 0) {
5689 wpas_ctrl_scan(wpa_s, buf + 5, reply, reply_size, &reply_len);
5690 } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) {
5691 reply_len = wpa_supplicant_ctrl_iface_scan_results(
5692 wpa_s, reply, reply_size);
5693 } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) {
5694 if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15))
5696 } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) {
5697 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15))
5699 } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) {
5700 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16))
5702 } else if (os_strcmp(buf, "ADD_NETWORK") == 0) {
5703 reply_len = wpa_supplicant_ctrl_iface_add_network(
5704 wpa_s, reply, reply_size);
5705 } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) {
5706 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15))
5708 } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
5709 if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12))
5711 } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) {
5712 reply_len = wpa_supplicant_ctrl_iface_get_network(
5713 wpa_s, buf + 12, reply, reply_size);
5714 } else if (os_strcmp(buf, "LIST_CREDS") == 0) {
5715 reply_len = wpa_supplicant_ctrl_iface_list_creds(
5716 wpa_s, reply, reply_size);
5717 } else if (os_strcmp(buf, "ADD_CRED") == 0) {
5718 reply_len = wpa_supplicant_ctrl_iface_add_cred(
5719 wpa_s, reply, reply_size);
5720 } else if (os_strncmp(buf, "REMOVE_CRED ", 12) == 0) {
5721 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s, buf + 12))
5723 } else if (os_strncmp(buf, "SET_CRED ", 9) == 0) {
5724 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s, buf + 9))
5726 #ifndef CONFIG_NO_CONFIG_WRITE
5727 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
5728 if (wpa_supplicant_ctrl_iface_save_config(wpa_s))
5730 #endif /* CONFIG_NO_CONFIG_WRITE */
5731 } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
5732 reply_len = wpa_supplicant_ctrl_iface_get_capability(
5733 wpa_s, buf + 15, reply, reply_size);
5734 } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) {
5735 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8))
5737 } else if (os_strncmp(buf, "SCAN_INTERVAL ", 14) == 0) {
5738 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s, buf + 14))
5740 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
5741 reply_len = wpa_supplicant_global_iface_list(
5742 wpa_s->global, reply, reply_size);
5743 } else if (os_strcmp(buf, "INTERFACES") == 0) {
5744 reply_len = wpa_supplicant_global_iface_interfaces(
5745 wpa_s->global, reply, reply_size);
5746 } else if (os_strncmp(buf, "BSS ", 4) == 0) {
5747 reply_len = wpa_supplicant_ctrl_iface_bss(
5748 wpa_s, buf + 4, reply, reply_size);
5750 } else if (os_strcmp(buf, "STA-FIRST") == 0) {
5751 reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size);
5752 } else if (os_strncmp(buf, "STA ", 4) == 0) {
5753 reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply,
5755 } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) {
5756 reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply,
5758 } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) {
5759 if (ap_ctrl_iface_sta_deauthenticate(wpa_s, buf + 15))
5761 } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) {
5762 if (ap_ctrl_iface_sta_disassociate(wpa_s, buf + 13))
5764 } else if (os_strncmp(buf, "CHAN_SWITCH ", 12) == 0) {
5765 if (ap_ctrl_iface_chanswitch(wpa_s, buf + 12))
5767 #endif /* CONFIG_AP */
5768 } else if (os_strcmp(buf, "SUSPEND") == 0) {
5769 wpas_notify_suspend(wpa_s->global);
5770 } else if (os_strcmp(buf, "RESUME") == 0) {
5771 wpas_notify_resume(wpa_s->global);
5772 } else if (os_strcmp(buf, "DROP_SA") == 0) {
5773 wpa_supplicant_ctrl_iface_drop_sa(wpa_s);
5774 } else if (os_strncmp(buf, "ROAM ", 5) == 0) {
5775 if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5))
5777 } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) {
5778 if (wpa_supplicant_ctrl_iface_sta_autoconnect(wpa_s, buf + 16))
5780 } else if (os_strncmp(buf, "BSS_EXPIRE_AGE ", 15) == 0) {
5781 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s, buf + 15))
5783 } else if (os_strncmp(buf, "BSS_EXPIRE_COUNT ", 17) == 0) {
5784 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s,
5787 } else if (os_strncmp(buf, "BSS_FLUSH ", 10) == 0) {
5788 if (wpa_supplicant_ctrl_iface_bss_flush(wpa_s, buf + 10))
5791 } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) {
5792 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14))
5794 } else if (os_strncmp(buf, "TDLS_SETUP ", 11) == 0) {
5795 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s, buf + 11))
5797 } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) {
5798 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14))
5800 #endif /* CONFIG_TDLS */
5801 } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) {
5802 reply_len = wpa_supplicant_signal_poll(wpa_s, reply,
5804 } else if (os_strncmp(buf, "PKTCNT_POLL", 11) == 0) {
5805 reply_len = wpa_supplicant_pktcnt_poll(wpa_s, reply,
5807 #ifdef CONFIG_AUTOSCAN
5808 } else if (os_strncmp(buf, "AUTOSCAN ", 9) == 0) {
5809 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s, buf + 9))
5811 #endif /* CONFIG_AUTOSCAN */
5813 } else if (os_strncmp(buf, "DRIVER ", 7) == 0) {
5814 reply_len = wpa_supplicant_driver_cmd(wpa_s, buf + 7, reply,
5816 #endif /* ANDROID */
5817 } else if (os_strcmp(buf, "REAUTHENTICATE") == 0) {
5818 pmksa_cache_clear_current(wpa_s->wpa);
5819 eapol_sm_request_reauth(wpa_s->eapol);
5821 } else if (os_strncmp(buf, "WNM_SLEEP ", 10) == 0) {
5822 if (wpas_ctrl_iface_wnm_sleep(wpa_s, buf + 10))
5824 } else if (os_strncmp(buf, "WNM_BSS_QUERY ", 10) == 0) {
5825 if (wpas_ctrl_iface_wnm_bss_query(wpa_s, buf + 10))
5827 #endif /* CONFIG_WNM */
5828 } else if (os_strcmp(buf, "FLUSH") == 0) {
5829 wpa_supplicant_ctrl_iface_flush(wpa_s);
5831 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
5835 if (reply_len < 0) {
5836 os_memcpy(reply, "FAIL\n", 5);
5840 *resp_len = reply_len;
5845 static int wpa_supplicant_global_iface_add(struct wpa_global *global,
5848 struct wpa_interface iface;
5852 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
5853 * TAB<bridge_ifname>
5855 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd);
5857 os_memset(&iface, 0, sizeof(iface));
5860 iface.ifname = pos = cmd;
5861 pos = os_strchr(pos, '\t');
5864 if (iface.ifname[0] == '\0')
5869 iface.confname = pos;
5870 pos = os_strchr(pos, '\t');
5873 if (iface.confname[0] == '\0')
5874 iface.confname = NULL;
5879 pos = os_strchr(pos, '\t');
5882 if (iface.driver[0] == '\0')
5883 iface.driver = NULL;
5887 iface.ctrl_interface = pos;
5888 pos = os_strchr(pos, '\t');
5891 if (iface.ctrl_interface[0] == '\0')
5892 iface.ctrl_interface = NULL;
5896 iface.driver_param = pos;
5897 pos = os_strchr(pos, '\t');
5900 if (iface.driver_param[0] == '\0')
5901 iface.driver_param = NULL;
5905 iface.bridge_ifname = pos;
5906 pos = os_strchr(pos, '\t');
5909 if (iface.bridge_ifname[0] == '\0')
5910 iface.bridge_ifname = NULL;
5915 if (wpa_supplicant_get_iface(global, iface.ifname))
5918 return wpa_supplicant_add_iface(global, &iface) ? 0 : -1;
5922 static int wpa_supplicant_global_iface_remove(struct wpa_global *global,
5925 struct wpa_supplicant *wpa_s;
5927 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd);
5929 wpa_s = wpa_supplicant_get_iface(global, cmd);
5932 return wpa_supplicant_remove_iface(global, wpa_s, 0);
5936 static void wpa_free_iface_info(struct wpa_interface_info *iface)
5938 struct wpa_interface_info *prev;
5942 iface = iface->next;
5944 os_free(prev->ifname);
5945 os_free(prev->desc);
5951 static int wpa_supplicant_global_iface_list(struct wpa_global *global,
5955 struct wpa_interface_info *iface = NULL, *last = NULL, *tmp;
5958 for (i = 0; wpa_drivers[i]; i++) {
5959 struct wpa_driver_ops *drv = wpa_drivers[i];
5960 if (drv->get_interfaces == NULL)
5962 tmp = drv->get_interfaces(global->drv_priv[i]);
5976 for (tmp = iface; tmp; tmp = tmp->next) {
5977 res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n",
5978 tmp->drv_name, tmp->ifname,
5979 tmp->desc ? tmp->desc : "");
5980 if (res < 0 || res >= end - pos) {
5987 wpa_free_iface_info(iface);
5993 static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
5998 struct wpa_supplicant *wpa_s;
6000 wpa_s = global->ifaces;
6005 res = os_snprintf(pos, end - pos, "%s\n", wpa_s->ifname);
6006 if (res < 0 || res >= end - pos) {
6011 wpa_s = wpa_s->next;
6017 static char * wpas_global_ctrl_iface_ifname(struct wpa_global *global,
6019 char *cmd, size_t *resp_len)
6021 struct wpa_supplicant *wpa_s;
6023 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
6024 if (os_strcmp(ifname, wpa_s->ifname) == 0)
6028 if (wpa_s == NULL) {
6029 char *resp = os_strdup("FAIL-NO-IFNAME-MATCH\n");
6031 *resp_len = os_strlen(resp);
6037 return wpa_supplicant_ctrl_iface_process(wpa_s, cmd, resp_len);
6041 static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global *global,
6042 char *buf, size_t *resp_len)
6045 static const char * cmd[] = {
6050 "P2P_GET_PASSPHRASE",
6051 "P2P_SERVICE_UPDATE",
6052 "P2P_SERVICE_FLUSH",
6059 static const char * prefix[] = {
6063 "P2P_GROUP_REMOVE ",
6066 "P2P_SERV_DISC_REQ ",
6067 "P2P_SERV_DISC_CANCEL_REQ ",
6068 "P2P_SERV_DISC_RESP ",
6069 "P2P_SERV_DISC_EXTERNAL ",
6077 "P2P_PRESENCE_REQ ",
6079 "P2P_REMOVE_CLIENT ",
6085 if (global->p2p_init_wpa_s == NULL)
6088 for (i = 0; !found && cmd[i]; i++) {
6089 if (os_strcmp(buf, cmd[i]) == 0)
6093 for (i = 0; !found && prefix[i]; i++) {
6094 if (os_strncmp(buf, prefix[i], os_strlen(prefix[i])) == 0)
6099 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
6101 #endif /* CONFIG_P2P */
6106 static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global *global,
6107 char *buf, size_t *resp_len)
6109 #ifdef CONFIG_WIFI_DISPLAY
6110 if (global->p2p_init_wpa_s == NULL)
6112 if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0 ||
6113 os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0)
6114 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
6116 #endif /* CONFIG_WIFI_DISPLAY */
6121 static char * wpas_global_ctrl_iface_redir(struct wpa_global *global,
6122 char *buf, size_t *resp_len)
6126 ret = wpas_global_ctrl_iface_redir_p2p(global, buf, resp_len);
6130 ret = wpas_global_ctrl_iface_redir_wfd(global, buf, resp_len);
6138 static int wpas_global_ctrl_iface_set(struct wpa_global *global, char *cmd)
6142 value = os_strchr(cmd, ' ');
6147 wpa_printf(MSG_DEBUG, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd, value);
6149 #ifdef CONFIG_WIFI_DISPLAY
6150 if (os_strcasecmp(cmd, "wifi_display") == 0) {
6151 wifi_display_enable(global, !!atoi(value));
6154 #endif /* CONFIG_WIFI_DISPLAY */
6160 #ifndef CONFIG_NO_CONFIG_WRITE
6161 static int wpas_global_ctrl_iface_save_config(struct wpa_global *global)
6164 struct wpa_supplicant *wpa_s;
6166 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
6167 if (!wpa_s->conf->update_config) {
6168 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
6172 if (wpa_config_write(wpa_s->confname, wpa_s->conf)) {
6173 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
6176 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
6182 #endif /* CONFIG_NO_CONFIG_WRITE */
6185 static int wpas_global_ctrl_iface_status(struct wpa_global *global,
6186 char *buf, size_t buflen)
6190 struct wpa_supplicant *wpa_s;
6196 if (global->p2p && !global->p2p_disabled) {
6197 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
6200 MAC2STR(global->p2p_dev_addr),
6201 p2p_get_state_txt(global->p2p));
6202 if (ret < 0 || ret >= end - pos)
6205 } else if (global->p2p) {
6206 ret = os_snprintf(pos, end - pos, "p2p_state=DISABLED\n");
6207 if (ret < 0 || ret >= end - pos)
6211 #endif /* CONFIG_P2P */
6213 #ifdef CONFIG_WIFI_DISPLAY
6214 ret = os_snprintf(pos, end - pos, "wifi_display=%d\n",
6215 !!global->wifi_display);
6216 if (ret < 0 || ret >= end - pos)
6219 #endif /* CONFIG_WIFI_DISPLAY */
6221 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
6222 ret = os_snprintf(pos, end - pos, "ifname=%s\n"
6223 "address=" MACSTR "\n",
6224 wpa_s->ifname, MAC2STR(wpa_s->own_addr));
6225 if (ret < 0 || ret >= end - pos)
6234 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
6235 char *buf, size_t *resp_len)
6238 const int reply_size = 2048;
6240 int level = MSG_DEBUG;
6242 if (os_strncmp(buf, "IFNAME=", 7) == 0) {
6243 char *pos = os_strchr(buf + 7, ' ');
6246 return wpas_global_ctrl_iface_ifname(global,
6252 reply = wpas_global_ctrl_iface_redir(global, buf, resp_len);
6256 if (os_strcmp(buf, "PING") == 0)
6257 level = MSG_EXCESSIVE;
6258 wpa_hexdump_ascii(level, "RX global ctrl_iface",
6259 (const u8 *) buf, os_strlen(buf));
6261 reply = os_malloc(reply_size);
6262 if (reply == NULL) {
6267 os_memcpy(reply, "OK\n", 3);
6270 if (os_strcmp(buf, "PING") == 0) {
6271 os_memcpy(reply, "PONG\n", 5);
6273 } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) {
6274 if (wpa_supplicant_global_iface_add(global, buf + 14))
6276 } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) {
6277 if (wpa_supplicant_global_iface_remove(global, buf + 17))
6279 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
6280 reply_len = wpa_supplicant_global_iface_list(
6281 global, reply, reply_size);
6282 } else if (os_strcmp(buf, "INTERFACES") == 0) {
6283 reply_len = wpa_supplicant_global_iface_interfaces(
6284 global, reply, reply_size);
6285 } else if (os_strcmp(buf, "TERMINATE") == 0) {
6286 wpa_supplicant_terminate_proc(global);
6287 } else if (os_strcmp(buf, "SUSPEND") == 0) {
6288 wpas_notify_suspend(global);
6289 } else if (os_strcmp(buf, "RESUME") == 0) {
6290 wpas_notify_resume(global);
6291 } else if (os_strncmp(buf, "SET ", 4) == 0) {
6292 if (wpas_global_ctrl_iface_set(global, buf + 4))
6294 #ifndef CONFIG_NO_CONFIG_WRITE
6295 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
6296 if (wpas_global_ctrl_iface_save_config(global))
6298 #endif /* CONFIG_NO_CONFIG_WRITE */
6299 } else if (os_strcmp(buf, "STATUS") == 0) {
6300 reply_len = wpas_global_ctrl_iface_status(global, reply,
6303 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
6307 if (reply_len < 0) {
6308 os_memcpy(reply, "FAIL\n", 5);
6312 *resp_len = reply_len;