2 * WPA Supplicant / Control interface (shared code for all backends)
3 * Copyright (c) 2004-2014, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
9 #include "utils/includes.h"
11 #include "utils/common.h"
12 #include "utils/eloop.h"
13 #include "utils/uuid.h"
14 #include "common/version.h"
15 #include "common/ieee802_11_defs.h"
16 #include "common/ieee802_11_common.h"
17 #include "common/wpa_ctrl.h"
18 #include "eap_peer/eap.h"
19 #include "eapol_supp/eapol_supp_sm.h"
20 #include "rsn_supp/wpa.h"
21 #include "rsn_supp/preauth.h"
22 #include "rsn_supp/pmksa_cache.h"
23 #include "l2_packet/l2_packet.h"
26 #include "wpa_supplicant_i.h"
28 #include "wps_supplicant.h"
31 #include "p2p_supplicant.h"
33 #include "hs20_supplicant.h"
34 #include "wifi_display.h"
38 #include "ctrl_iface.h"
39 #include "interworking.h"
40 #include "blacklist.h"
44 static int wpa_supplicant_global_iface_list(struct wpa_global *global,
46 static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
50 static int pno_start(struct wpa_supplicant *wpa_s)
54 struct wpa_ssid *ssid;
55 struct wpa_driver_scan_params params;
57 if (wpa_s->pno || wpa_s->pno_sched_pending)
60 if ((wpa_s->wpa_state > WPA_SCANNING) &&
61 (wpa_s->wpa_state <= WPA_COMPLETED)) {
62 wpa_printf(MSG_ERROR, "PNO: In assoc process");
66 if (wpa_s->wpa_state == WPA_SCANNING) {
67 wpa_supplicant_cancel_scan(wpa_s);
68 if (wpa_s->sched_scanning) {
69 wpa_printf(MSG_DEBUG, "Schedule PNO on completion of "
70 "ongoing sched scan");
71 wpa_supplicant_cancel_sched_scan(wpa_s);
72 wpa_s->pno_sched_pending = 1;
77 os_memset(¶ms, 0, sizeof(params));
80 ssid = wpa_s->conf->ssid;
82 if (!wpas_network_disabled(wpa_s, ssid))
86 if (num_ssid > WPAS_MAX_SCAN_SSIDS) {
87 wpa_printf(MSG_DEBUG, "PNO: Use only the first %u SSIDs from "
88 "%u", WPAS_MAX_SCAN_SSIDS, (unsigned int) num_ssid);
89 num_ssid = WPAS_MAX_SCAN_SSIDS;
93 wpa_printf(MSG_DEBUG, "PNO: No configured SSIDs");
97 params.filter_ssids = os_malloc(sizeof(struct wpa_driver_scan_filter) *
99 if (params.filter_ssids == NULL)
102 ssid = wpa_s->conf->ssid;
104 if (!wpas_network_disabled(wpa_s, ssid)) {
105 params.ssids[i].ssid = ssid->ssid;
106 params.ssids[i].ssid_len = ssid->ssid_len;
108 os_memcpy(params.filter_ssids[i].ssid, ssid->ssid,
110 params.filter_ssids[i].ssid_len = ssid->ssid_len;
111 params.num_filter_ssids++;
119 if (wpa_s->conf->filter_rssi)
120 params.filter_rssi = wpa_s->conf->filter_rssi;
122 interval = wpa_s->conf->sched_scan_interval ?
123 wpa_s->conf->sched_scan_interval : 10;
125 ret = wpa_supplicant_start_sched_scan(wpa_s, ¶ms, interval);
126 os_free(params.filter_ssids);
133 static int pno_stop(struct wpa_supplicant *wpa_s)
137 if (wpa_s->pno || wpa_s->sched_scanning) {
139 ret = wpa_supplicant_stop_sched_scan(wpa_s);
142 wpa_s->pno_sched_pending = 0;
144 if (wpa_s->wpa_state == WPA_SCANNING)
145 wpa_supplicant_req_scan(wpa_s, 0, 0);
151 static int set_bssid_filter(struct wpa_supplicant *wpa_s, char *val)
154 u8 addr[ETH_ALEN], *filter = NULL, *n;
161 if (hwaddr_aton(pos, addr)) {
165 n = os_realloc_array(filter, count + 1, ETH_ALEN);
171 os_memcpy(filter + count * ETH_ALEN, addr, ETH_ALEN);
174 pos = os_strchr(pos, ' ');
179 wpa_hexdump(MSG_DEBUG, "bssid_filter", filter, count * ETH_ALEN);
180 os_free(wpa_s->bssid_filter);
181 wpa_s->bssid_filter = filter;
182 wpa_s->bssid_filter_count = count;
188 static int set_disallow_aps(struct wpa_supplicant *wpa_s, char *val)
191 u8 addr[ETH_ALEN], *bssid = NULL, *n;
192 struct wpa_ssid_value *ssid = NULL, *ns;
193 size_t count = 0, ssid_count = 0;
197 * disallow_list ::= <ssid_spec> | <bssid_spec> | <disallow_list> | ""
198 * SSID_SPEC ::= ssid <SSID_HEX>
199 * BSSID_SPEC ::= bssid <BSSID_HEX>
206 if (os_strncmp(pos, "bssid ", 6) == 0) {
209 res = hwaddr_aton2(pos, addr);
213 wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
214 "BSSID value '%s'", pos);
218 n = os_realloc_array(bssid, count + 1, ETH_ALEN);
225 os_memcpy(bssid + count * ETH_ALEN, addr, ETH_ALEN);
227 } else if (os_strncmp(pos, "ssid ", 5) == 0) {
233 if (*end == '\0' || *end == ' ')
238 ns = os_realloc_array(ssid, ssid_count + 1,
239 sizeof(struct wpa_ssid_value));
247 if ((end - pos) & 0x01 || end - pos > 2 * 32 ||
248 hexstr2bin(pos, ssid[ssid_count].ssid,
249 (end - pos) / 2) < 0) {
252 wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
253 "SSID value '%s'", pos);
256 ssid[ssid_count].ssid_len = (end - pos) / 2;
257 wpa_hexdump_ascii(MSG_DEBUG, "disallow_aps SSID",
258 ssid[ssid_count].ssid,
259 ssid[ssid_count].ssid_len);
263 wpa_printf(MSG_DEBUG, "Unexpected disallow_aps value "
270 pos = os_strchr(pos, ' ');
275 wpa_hexdump(MSG_DEBUG, "disallow_aps_bssid", bssid, count * ETH_ALEN);
276 os_free(wpa_s->disallow_aps_bssid);
277 wpa_s->disallow_aps_bssid = bssid;
278 wpa_s->disallow_aps_bssid_count = count;
280 wpa_printf(MSG_DEBUG, "disallow_aps_ssid_count %d", (int) ssid_count);
281 os_free(wpa_s->disallow_aps_ssid);
282 wpa_s->disallow_aps_ssid = ssid;
283 wpa_s->disallow_aps_ssid_count = ssid_count;
285 if (!wpa_s->current_ssid || wpa_s->wpa_state < WPA_AUTHENTICATING)
288 c = wpa_s->current_ssid;
289 if (c->mode != WPAS_MODE_INFRA && c->mode != WPAS_MODE_IBSS)
292 if (!disallowed_bssid(wpa_s, wpa_s->bssid) &&
293 !disallowed_ssid(wpa_s, c->ssid, c->ssid_len))
296 wpa_printf(MSG_DEBUG, "Disconnect and try to find another network "
297 "because current AP was marked disallowed");
300 wpa_s->sme.prev_bssid_set = 0;
301 #endif /* CONFIG_SME */
302 wpa_s->reassociate = 1;
303 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
304 wpa_supplicant_req_scan(wpa_s, 0, 0);
310 static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s,
316 value = os_strchr(cmd, ' ');
321 wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value);
322 if (os_strcasecmp(cmd, "EAPOL::heldPeriod") == 0) {
323 eapol_sm_configure(wpa_s->eapol,
324 atoi(value), -1, -1, -1);
325 } else if (os_strcasecmp(cmd, "EAPOL::authPeriod") == 0) {
326 eapol_sm_configure(wpa_s->eapol,
327 -1, atoi(value), -1, -1);
328 } else if (os_strcasecmp(cmd, "EAPOL::startPeriod") == 0) {
329 eapol_sm_configure(wpa_s->eapol,
330 -1, -1, atoi(value), -1);
331 } else if (os_strcasecmp(cmd, "EAPOL::maxStart") == 0) {
332 eapol_sm_configure(wpa_s->eapol,
333 -1, -1, -1, atoi(value));
334 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKLifetime") == 0) {
335 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME,
338 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKReauthThreshold") ==
340 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD,
343 } else if (os_strcasecmp(cmd, "dot11RSNAConfigSATimeout") == 0) {
344 if (wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, atoi(value)))
346 } else if (os_strcasecmp(cmd, "wps_fragment_size") == 0) {
347 wpa_s->wps_fragment_size = atoi(value);
348 #ifdef CONFIG_WPS_TESTING
349 } else if (os_strcasecmp(cmd, "wps_version_number") == 0) {
351 val = strtol(value, NULL, 0);
352 if (val < 0 || val > 0xff) {
354 wpa_printf(MSG_DEBUG, "WPS: Invalid "
355 "wps_version_number %ld", val);
357 wps_version_number = val;
358 wpa_printf(MSG_DEBUG, "WPS: Testing - force WPS "
360 (wps_version_number & 0xf0) >> 4,
361 wps_version_number & 0x0f);
363 } else if (os_strcasecmp(cmd, "wps_testing_dummy_cred") == 0) {
364 wps_testing_dummy_cred = atoi(value);
365 wpa_printf(MSG_DEBUG, "WPS: Testing - dummy_cred=%d",
366 wps_testing_dummy_cred);
367 #endif /* CONFIG_WPS_TESTING */
368 } else if (os_strcasecmp(cmd, "ampdu") == 0) {
369 if (wpa_drv_ampdu(wpa_s, atoi(value)) < 0)
372 #ifdef CONFIG_TDLS_TESTING
373 } else if (os_strcasecmp(cmd, "tdls_testing") == 0) {
374 extern unsigned int tdls_testing;
375 tdls_testing = strtol(value, NULL, 0);
376 wpa_printf(MSG_DEBUG, "TDLS: tdls_testing=0x%x", tdls_testing);
377 #endif /* CONFIG_TDLS_TESTING */
378 } else if (os_strcasecmp(cmd, "tdls_disabled") == 0) {
379 int disabled = atoi(value);
380 wpa_printf(MSG_DEBUG, "TDLS: tdls_disabled=%d", disabled);
382 if (wpa_drv_tdls_oper(wpa_s, TDLS_DISABLE, NULL) < 0)
384 } else if (wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL) < 0)
386 wpa_tdls_enable(wpa_s->wpa, !disabled);
387 #endif /* CONFIG_TDLS */
388 } else if (os_strcasecmp(cmd, "pno") == 0) {
390 ret = pno_start(wpa_s);
392 ret = pno_stop(wpa_s);
393 } else if (os_strcasecmp(cmd, "radio_disabled") == 0) {
394 int disabled = atoi(value);
395 if (wpa_drv_radio_disable(wpa_s, disabled) < 0)
398 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
399 } else if (os_strcasecmp(cmd, "uapsd") == 0) {
400 if (os_strcmp(value, "disable") == 0)
401 wpa_s->set_sta_uapsd = 0;
405 /* format: BE,BK,VI,VO;max SP Length */
407 pos = os_strchr(value, ',');
412 pos = os_strchr(pos, ',');
417 pos = os_strchr(pos, ',');
422 /* ignore max SP Length for now */
424 wpa_s->set_sta_uapsd = 1;
425 wpa_s->sta_uapsd = 0;
427 wpa_s->sta_uapsd |= BIT(0);
429 wpa_s->sta_uapsd |= BIT(1);
431 wpa_s->sta_uapsd |= BIT(2);
433 wpa_s->sta_uapsd |= BIT(3);
435 } else if (os_strcasecmp(cmd, "ps") == 0) {
436 ret = wpa_drv_set_p2p_powersave(wpa_s, atoi(value), -1, -1);
437 #ifdef CONFIG_WIFI_DISPLAY
438 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
439 wifi_display_enable(wpa_s->global, !!atoi(value));
440 #endif /* CONFIG_WIFI_DISPLAY */
441 } else if (os_strcasecmp(cmd, "bssid_filter") == 0) {
442 ret = set_bssid_filter(wpa_s, value);
443 } else if (os_strcasecmp(cmd, "disallow_aps") == 0) {
444 ret = set_disallow_aps(wpa_s, value);
445 } else if (os_strcasecmp(cmd, "no_keep_alive") == 0) {
446 wpa_s->no_keep_alive = !!atoi(value);
449 ret = wpa_config_process_global(wpa_s->conf, cmd, -1);
451 wpa_supplicant_update_config(wpa_s);
458 static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s,
459 char *cmd, char *buf, size_t buflen)
463 wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd);
465 if (os_strcmp(cmd, "version") == 0) {
466 res = os_snprintf(buf, buflen, "%s", VERSION_STR);
467 } else if (os_strcasecmp(cmd, "country") == 0) {
468 if (wpa_s->conf->country[0] && wpa_s->conf->country[1])
469 res = os_snprintf(buf, buflen, "%c%c",
470 wpa_s->conf->country[0],
471 wpa_s->conf->country[1]);
472 #ifdef CONFIG_WIFI_DISPLAY
473 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
474 res = os_snprintf(buf, buflen, "%d",
475 wpa_s->global->wifi_display);
476 if (res < 0 || (unsigned int) res >= buflen)
479 #endif /* CONFIG_WIFI_DISPLAY */
480 #ifdef CONFIG_TESTING_GET_GTK
481 } else if (os_strcmp(cmd, "gtk") == 0) {
482 if (wpa_s->last_gtk_len == 0)
484 res = wpa_snprintf_hex(buf, buflen, wpa_s->last_gtk,
485 wpa_s->last_gtk_len);
487 #endif /* CONFIG_TESTING_GET_GTK */
490 if (res < 0 || (unsigned int) res >= buflen)
496 #ifdef IEEE8021X_EAPOL
497 static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s,
501 struct wpa_ssid *ssid = wpa_s->current_ssid;
503 if (hwaddr_aton(addr, bssid)) {
504 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address "
509 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid));
510 rsn_preauth_deinit(wpa_s->wpa);
511 if (rsn_preauth_init(wpa_s->wpa, bssid, ssid ? &ssid->eap : NULL))
516 #endif /* IEEE8021X_EAPOL */
519 #ifdef CONFIG_PEERKEY
520 /* MLME-STKSTART.request(peer) */
521 static int wpa_supplicant_ctrl_iface_stkstart(
522 struct wpa_supplicant *wpa_s, char *addr)
526 if (hwaddr_aton(addr, peer)) {
527 wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART: invalid "
528 "address '%s'", addr);
532 wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART " MACSTR,
535 return wpa_sm_stkstart(wpa_s->wpa, peer);
537 #endif /* CONFIG_PEERKEY */
542 static int wpa_supplicant_ctrl_iface_tdls_discover(
543 struct wpa_supplicant *wpa_s, char *addr)
548 if (hwaddr_aton(addr, peer)) {
549 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER: invalid "
550 "address '%s'", addr);
554 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER " MACSTR,
557 if (wpa_tdls_is_external_setup(wpa_s->wpa))
558 ret = wpa_tdls_send_discovery_request(wpa_s->wpa, peer);
560 ret = wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer);
566 static int wpa_supplicant_ctrl_iface_tdls_setup(
567 struct wpa_supplicant *wpa_s, char *addr)
572 if (hwaddr_aton(addr, peer)) {
573 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP: invalid "
574 "address '%s'", addr);
578 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP " MACSTR,
581 if ((wpa_s->conf->tdls_external_control) &&
582 wpa_tdls_is_external_setup(wpa_s->wpa))
583 return wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
585 wpa_tdls_remove(wpa_s->wpa, peer);
587 if (wpa_tdls_is_external_setup(wpa_s->wpa))
588 ret = wpa_tdls_start(wpa_s->wpa, peer);
590 ret = wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
596 static int wpa_supplicant_ctrl_iface_tdls_teardown(
597 struct wpa_supplicant *wpa_s, char *addr)
602 if (hwaddr_aton(addr, peer)) {
603 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN: invalid "
604 "address '%s'", addr);
608 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN " MACSTR,
611 if ((wpa_s->conf->tdls_external_control) &&
612 wpa_tdls_is_external_setup(wpa_s->wpa))
613 return wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
615 if (wpa_tdls_is_external_setup(wpa_s->wpa))
616 ret = wpa_tdls_teardown_link(
618 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED);
620 ret = wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
625 #endif /* CONFIG_TDLS */
628 #ifdef CONFIG_IEEE80211R
629 static int wpa_supplicant_ctrl_iface_ft_ds(
630 struct wpa_supplicant *wpa_s, char *addr)
632 u8 target_ap[ETH_ALEN];
636 if (hwaddr_aton(addr, target_ap)) {
637 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid "
638 "address '%s'", addr);
642 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap));
644 bss = wpa_bss_get_bssid(wpa_s, target_ap);
646 mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN);
650 return wpa_ft_start_over_ds(wpa_s->wpa, target_ap, mdie);
652 #endif /* CONFIG_IEEE80211R */
656 static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s,
659 u8 bssid[ETH_ALEN], *_bssid = bssid;
661 u8 p2p_dev_addr[ETH_ALEN];
662 #endif /* CONFIG_P2P */
664 u8 *_p2p_dev_addr = NULL;
665 #endif /* CONFIG_AP */
667 if (cmd == NULL || os_strcmp(cmd, "any") == 0) {
670 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
671 if (hwaddr_aton(cmd + 13, p2p_dev_addr)) {
672 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid "
673 "P2P Device Address '%s'",
677 _p2p_dev_addr = p2p_dev_addr;
678 #endif /* CONFIG_P2P */
679 } else if (hwaddr_aton(cmd, bssid)) {
680 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
687 return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid, _p2p_dev_addr);
688 #endif /* CONFIG_AP */
690 return wpas_wps_start_pbc(wpa_s, _bssid, 0);
694 static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s,
695 char *cmd, char *buf,
698 u8 bssid[ETH_ALEN], *_bssid = bssid;
702 pin = os_strchr(cmd, ' ');
706 if (os_strcmp(cmd, "any") == 0)
708 else if (os_strcmp(cmd, "get") == 0) {
709 ret = wps_generate_pin();
711 } else if (hwaddr_aton(cmd, bssid)) {
712 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
718 if (wpa_s->ap_iface) {
723 pos = os_strchr(pin, ' ');
730 return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin,
731 buf, buflen, timeout);
733 #endif /* CONFIG_AP */
736 ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0,
740 ret = os_snprintf(buf, buflen, "%s", pin);
741 if (ret < 0 || (size_t) ret >= buflen)
746 ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0, DEV_PW_DEFAULT);
751 /* Return the generated PIN */
752 ret = os_snprintf(buf, buflen, "%08d", ret);
753 if (ret < 0 || (size_t) ret >= buflen)
759 static int wpa_supplicant_ctrl_iface_wps_check_pin(
760 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
767 wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN",
768 (u8 *) cmd, os_strlen(cmd));
769 for (pos = cmd, len = 0; *pos != '\0'; pos++) {
770 if (*pos < '0' || *pos > '9')
774 wpa_printf(MSG_DEBUG, "WPS: Too long PIN");
778 if (len != 4 && len != 8) {
779 wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len);
785 unsigned int pin_val;
787 if (!wps_pin_valid(pin_val)) {
788 wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit");
789 ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n");
790 if (ret < 0 || (size_t) ret >= buflen)
796 ret = os_snprintf(buf, buflen, "%s", pin);
797 if (ret < 0 || (size_t) ret >= buflen)
804 #ifdef CONFIG_WPS_NFC
806 static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant *wpa_s,
809 u8 bssid[ETH_ALEN], *_bssid = bssid;
811 if (cmd == NULL || cmd[0] == '\0')
813 else if (hwaddr_aton(cmd, bssid))
816 return wpas_wps_start_nfc(wpa_s, _bssid);
820 static int wpa_supplicant_ctrl_iface_wps_nfc_config_token(
821 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
828 pos = os_strchr(cmd, ' ');
831 if (os_strcmp(cmd, "WPS") == 0)
833 else if (os_strcmp(cmd, "NDEF") == 0)
838 buf = wpas_wps_nfc_config_token(wpa_s, ndef, pos);
842 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
853 static int wpa_supplicant_ctrl_iface_wps_nfc_token(
854 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
860 if (os_strcmp(cmd, "WPS") == 0)
862 else if (os_strcmp(cmd, "NDEF") == 0)
867 buf = wpas_wps_nfc_token(wpa_s, ndef);
871 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
882 static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
883 struct wpa_supplicant *wpa_s, char *pos)
889 len = os_strlen(pos);
894 buf = wpabuf_alloc(len);
897 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
902 ret = wpas_wps_nfc_tag_read(wpa_s, buf);
909 static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant *wpa_s,
910 char *reply, size_t max_len,
916 buf = wpas_wps_nfc_handover_req(wpa_s, cr);
920 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
931 static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant *wpa_s,
932 char *cmd, char *reply,
937 pos = os_strchr(cmd, ' ');
942 if (os_strcmp(cmd, "NDEF") != 0)
945 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
946 return wpas_ctrl_nfc_get_handover_req_wps(
947 wpa_s, reply, max_len, os_strcmp(pos, "WPS-CR") == 0);
954 static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant *wpa_s,
955 char *reply, size_t max_len,
956 int ndef, int cr, char *uuid)
961 buf = wpas_wps_nfc_handover_sel(wpa_s, ndef, cr, uuid);
965 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
976 static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant *wpa_s,
977 char *cmd, char *reply,
983 pos = os_strchr(cmd, ' ');
988 if (os_strcmp(cmd, "WPS") == 0)
990 else if (os_strcmp(cmd, "NDEF") == 0)
995 pos2 = os_strchr(pos, ' ');
998 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
999 return wpas_ctrl_nfc_get_handover_sel_wps(
1000 wpa_s, reply, max_len, ndef,
1001 os_strcmp(pos, "WPS-CR") == 0, pos2);
1008 static int wpas_ctrl_nfc_rx_handover_req(struct wpa_supplicant *wpa_s,
1009 char *cmd, char *reply,
1016 len = os_strlen(cmd);
1021 buf = wpabuf_alloc(len);
1024 if (hexstr2bin(cmd, wpabuf_put(buf, len), len) < 0) {
1029 ret = wpas_wps_nfc_rx_handover_req(wpa_s, buf);
1036 static int wpas_ctrl_nfc_rx_handover_sel(struct wpa_supplicant *wpa_s,
1043 len = os_strlen(cmd);
1048 buf = wpabuf_alloc(len);
1051 if (hexstr2bin(cmd, wpabuf_put(buf, len), len) < 0) {
1056 ret = wpas_wps_nfc_rx_handover_sel(wpa_s, buf);
1063 static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant *wpa_s,
1067 struct wpabuf *req, *sel;
1069 char *pos, *role, *type, *pos2;
1072 pos = os_strchr(role, ' ');
1078 pos = os_strchr(type, ' ');
1083 pos2 = os_strchr(pos, ' ');
1088 len = os_strlen(pos);
1093 req = wpabuf_alloc(len);
1096 if (hexstr2bin(pos, wpabuf_put(req, len), len) < 0) {
1101 len = os_strlen(pos2);
1108 sel = wpabuf_alloc(len);
1113 if (hexstr2bin(pos2, wpabuf_put(sel, len), len) < 0) {
1119 if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "WPS") == 0) {
1120 ret = wpas_wps_nfc_report_handover(wpa_s, req, sel);
1122 wpa_printf(MSG_DEBUG, "NFC: Unsupported connection handover "
1123 "reported: role=%s type=%s", role, type);
1132 #endif /* CONFIG_WPS_NFC */
1135 static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s,
1144 struct wps_new_ap_settings ap;
1146 pin = os_strchr(cmd, ' ');
1151 if (hwaddr_aton(cmd, bssid)) {
1152 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
1157 new_ssid = os_strchr(pin, ' ');
1158 if (new_ssid == NULL)
1159 return wpas_wps_start_reg(wpa_s, bssid, pin, NULL);
1162 new_auth = os_strchr(new_ssid, ' ');
1163 if (new_auth == NULL)
1167 new_encr = os_strchr(new_auth, ' ');
1168 if (new_encr == NULL)
1172 new_key = os_strchr(new_encr, ' ');
1173 if (new_key == NULL)
1177 os_memset(&ap, 0, sizeof(ap));
1178 ap.ssid_hex = new_ssid;
1181 ap.key_hex = new_key;
1182 return wpas_wps_start_reg(wpa_s, bssid, pin, &ap);
1187 static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant *wpa_s,
1188 char *cmd, char *buf,
1193 const char *pin_txt;
1195 if (!wpa_s->ap_iface)
1198 pos = os_strchr(cmd, ' ');
1202 if (os_strcmp(cmd, "disable") == 0) {
1203 wpas_wps_ap_pin_disable(wpa_s);
1204 return os_snprintf(buf, buflen, "OK\n");
1207 if (os_strcmp(cmd, "random") == 0) {
1209 timeout = atoi(pos);
1210 pin_txt = wpas_wps_ap_pin_random(wpa_s, timeout);
1211 if (pin_txt == NULL)
1213 return os_snprintf(buf, buflen, "%s", pin_txt);
1216 if (os_strcmp(cmd, "get") == 0) {
1217 pin_txt = wpas_wps_ap_pin_get(wpa_s);
1218 if (pin_txt == NULL)
1220 return os_snprintf(buf, buflen, "%s", pin_txt);
1223 if (os_strcmp(cmd, "set") == 0) {
1228 pos = os_strchr(pos, ' ');
1231 timeout = atoi(pos);
1233 if (os_strlen(pin) > buflen)
1235 if (wpas_wps_ap_pin_set(wpa_s, pin, timeout) < 0)
1237 return os_snprintf(buf, buflen, "%s", pin);
1242 #endif /* CONFIG_AP */
1245 #ifdef CONFIG_WPS_ER
1246 static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant *wpa_s,
1249 char *uuid = cmd, *pin, *pos;
1250 u8 addr_buf[ETH_ALEN], *addr = NULL;
1251 pin = os_strchr(uuid, ' ');
1255 pos = os_strchr(pin, ' ');
1258 if (hwaddr_aton(pos, addr_buf) == 0)
1261 return wpas_wps_er_add_pin(wpa_s, addr, uuid, pin);
1265 static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant *wpa_s,
1268 char *uuid = cmd, *pin;
1269 pin = os_strchr(uuid, ' ');
1273 return wpas_wps_er_learn(wpa_s, uuid, pin);
1277 static int wpa_supplicant_ctrl_iface_wps_er_set_config(
1278 struct wpa_supplicant *wpa_s, char *cmd)
1280 char *uuid = cmd, *id;
1281 id = os_strchr(uuid, ' ');
1285 return wpas_wps_er_set_config(wpa_s, uuid, atoi(id));
1289 static int wpa_supplicant_ctrl_iface_wps_er_config(
1290 struct wpa_supplicant *wpa_s, char *cmd)
1297 struct wps_new_ap_settings ap;
1299 pin = os_strchr(cmd, ' ');
1304 new_ssid = os_strchr(pin, ' ');
1305 if (new_ssid == NULL)
1309 new_auth = os_strchr(new_ssid, ' ');
1310 if (new_auth == NULL)
1314 new_encr = os_strchr(new_auth, ' ');
1315 if (new_encr == NULL)
1319 new_key = os_strchr(new_encr, ' ');
1320 if (new_key == NULL)
1324 os_memset(&ap, 0, sizeof(ap));
1325 ap.ssid_hex = new_ssid;
1328 ap.key_hex = new_key;
1329 return wpas_wps_er_config(wpa_s, cmd, pin, &ap);
1333 #ifdef CONFIG_WPS_NFC
1334 static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
1335 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1342 uuid = os_strchr(cmd, ' ');
1347 if (os_strcmp(cmd, "WPS") == 0)
1349 else if (os_strcmp(cmd, "NDEF") == 0)
1354 buf = wpas_wps_er_nfc_config_token(wpa_s, ndef, uuid);
1358 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1360 reply[res++] = '\n';
1367 #endif /* CONFIG_WPS_NFC */
1368 #endif /* CONFIG_WPS_ER */
1370 #endif /* CONFIG_WPS */
1373 #ifdef CONFIG_IBSS_RSN
1374 static int wpa_supplicant_ctrl_iface_ibss_rsn(
1375 struct wpa_supplicant *wpa_s, char *addr)
1379 if (hwaddr_aton(addr, peer)) {
1380 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN: invalid "
1381 "address '%s'", addr);
1385 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN " MACSTR,
1388 return ibss_rsn_start(wpa_s->ibss_rsn, peer);
1390 #endif /* CONFIG_IBSS_RSN */
1393 static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s,
1396 #ifdef IEEE8021X_EAPOL
1399 struct wpa_ssid *ssid;
1401 pos = os_strchr(rsp, '-');
1406 pos = os_strchr(pos, ':');
1411 wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id);
1412 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
1413 (u8 *) pos, os_strlen(pos));
1415 ssid = wpa_config_get_network(wpa_s->conf, id);
1417 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
1422 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s, ssid, rsp,
1424 #else /* IEEE8021X_EAPOL */
1425 wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included");
1427 #endif /* IEEE8021X_EAPOL */
1431 static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
1433 char *buf, size_t buflen)
1435 char *pos, *end, tmp[30];
1436 int res, verbose, wps, ret;
1438 if (os_strcmp(params, "-DRIVER") == 0)
1439 return wpa_drv_status(wpa_s, buf, buflen);
1440 verbose = os_strcmp(params, "-VERBOSE") == 0;
1441 wps = os_strcmp(params, "-WPS") == 0;
1444 if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
1445 struct wpa_ssid *ssid = wpa_s->current_ssid;
1446 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
1447 MAC2STR(wpa_s->bssid));
1448 if (ret < 0 || ret >= end - pos)
1452 u8 *_ssid = ssid->ssid;
1453 size_t ssid_len = ssid->ssid_len;
1454 u8 ssid_buf[MAX_SSID_LEN];
1455 if (ssid_len == 0) {
1456 int _res = wpa_drv_get_ssid(wpa_s, ssid_buf);
1463 ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n",
1464 wpa_ssid_txt(_ssid, ssid_len),
1466 if (ret < 0 || ret >= end - pos)
1470 if (wps && ssid->passphrase &&
1471 wpa_key_mgmt_wpa_psk(ssid->key_mgmt) &&
1472 (ssid->mode == WPAS_MODE_AP ||
1473 ssid->mode == WPAS_MODE_P2P_GO)) {
1474 ret = os_snprintf(pos, end - pos,
1477 if (ret < 0 || ret >= end - pos)
1482 ret = os_snprintf(pos, end - pos,
1485 if (ret < 0 || ret >= end - pos)
1490 switch (ssid->mode) {
1491 case WPAS_MODE_INFRA:
1492 ret = os_snprintf(pos, end - pos,
1495 case WPAS_MODE_IBSS:
1496 ret = os_snprintf(pos, end - pos,
1500 ret = os_snprintf(pos, end - pos,
1503 case WPAS_MODE_P2P_GO:
1504 ret = os_snprintf(pos, end - pos,
1507 case WPAS_MODE_P2P_GROUP_FORMATION:
1508 ret = os_snprintf(pos, end - pos,
1509 "mode=P2P GO - group "
1516 if (ret < 0 || ret >= end - pos)
1522 if (wpa_s->ap_iface) {
1523 pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos,
1527 #endif /* CONFIG_AP */
1528 pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose);
1531 if (wpa_s->wpa_state >= WPA_ASSOCIATED &&
1534 #endif /* CONFIG_AP */
1535 wpa_s->sme.sae.state == SAE_ACCEPTED) {
1536 ret = os_snprintf(pos, end - pos, "sae_group=%d\n",
1537 wpa_s->sme.sae.group);
1538 if (ret < 0 || ret >= end - pos)
1542 #endif /* CONFIG_SAE */
1543 ret = os_snprintf(pos, end - pos, "wpa_state=%s\n",
1544 wpa_supplicant_state_txt(wpa_s->wpa_state));
1545 if (ret < 0 || ret >= end - pos)
1550 l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) {
1551 ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp);
1552 if (ret < 0 || ret >= end - pos)
1558 if (wpa_s->global->p2p) {
1559 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
1560 "\n", MAC2STR(wpa_s->global->p2p_dev_addr));
1561 if (ret < 0 || ret >= end - pos)
1565 #endif /* CONFIG_P2P */
1567 ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n",
1568 MAC2STR(wpa_s->own_addr));
1569 if (ret < 0 || ret >= end - pos)
1574 if (wpa_s->current_bss &&
1575 wpa_bss_get_vendor_ie(wpa_s->current_bss, HS20_IE_VENDOR_TYPE) &&
1576 wpa_s->wpa_proto == WPA_PROTO_RSN &&
1577 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1578 ret = os_snprintf(pos, end - pos, "hs20=1\n");
1579 if (ret < 0 || ret >= end - pos)
1584 if (wpa_s->current_ssid) {
1585 struct wpa_cred *cred;
1588 for (cred = wpa_s->conf->cred; cred; cred = cred->next) {
1591 if (wpa_s->current_ssid->parent_cred != cred)
1594 for (i = 0; cred->domain && i < cred->num_domain; i++) {
1595 ret = os_snprintf(pos, end - pos,
1598 if (ret < 0 || ret >= end - pos)
1603 if (wpa_s->current_bss == NULL ||
1604 wpa_s->current_bss->anqp == NULL)
1607 res = interworking_home_sp_cred(
1609 wpa_s->current_bss->anqp->domain_name);
1617 ret = os_snprintf(pos, end - pos, "sp_type=%s\n", type);
1618 if (ret < 0 || ret >= end - pos)
1625 #endif /* CONFIG_HS20 */
1627 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
1628 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
1629 res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos,
1635 res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose);
1642 uuid_bin2str(wpa_s->wps->uuid, uuid_str, sizeof(uuid_str));
1643 ret = os_snprintf(pos, end - pos, "uuid=%s\n", uuid_str);
1644 if (ret < 0 || ret >= end - pos)
1648 #endif /* CONFIG_WPS */
1651 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_STATE_CHANGE
1652 "id=%d state=%d BSSID=" MACSTR " SSID=%s",
1653 wpa_s->current_ssid ? wpa_s->current_ssid->id : -1,
1655 MAC2STR(wpa_s->bssid),
1656 wpa_s->current_ssid && wpa_s->current_ssid->ssid ?
1657 wpa_ssid_txt(wpa_s->current_ssid->ssid,
1658 wpa_s->current_ssid->ssid_len) : "");
1659 if (wpa_s->wpa_state == WPA_COMPLETED) {
1660 struct wpa_ssid *ssid = wpa_s->current_ssid;
1661 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_CONNECTED
1662 "- connection to " MACSTR
1663 " completed %s [id=%d id_str=%s]",
1664 MAC2STR(wpa_s->bssid), "(auth)",
1665 ssid ? ssid->id : -1,
1666 ssid && ssid->id_str ? ssid->id_str : "");
1668 #endif /* ANDROID */
1674 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s,
1679 struct wpa_ssid *ssid;
1682 /* cmd: "<network id> <BSSID>" */
1683 pos = os_strchr(cmd, ' ');
1688 wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos);
1689 if (hwaddr_aton(pos, bssid)) {
1690 wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos);
1694 ssid = wpa_config_get_network(wpa_s->conf, id);
1696 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
1701 os_memcpy(ssid->bssid, bssid, ETH_ALEN);
1702 ssid->bssid_set = !is_zero_ether_addr(bssid);
1708 static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant *wpa_s,
1709 char *cmd, char *buf,
1713 struct wpa_blacklist *e;
1717 /* cmd: "BLACKLIST [<BSSID>]" */
1721 e = wpa_s->blacklist;
1723 ret = os_snprintf(pos, end - pos, MACSTR "\n",
1725 if (ret < 0 || ret >= end - pos)
1734 if (os_strncmp(cmd, "clear", 5) == 0) {
1735 wpa_blacklist_clear(wpa_s);
1736 os_memcpy(buf, "OK\n", 3);
1740 wpa_printf(MSG_DEBUG, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd);
1741 if (hwaddr_aton(cmd, bssid)) {
1742 wpa_printf(MSG_DEBUG, "CTRL_IFACE: invalid BSSID '%s'", cmd);
1747 * Add the BSSID twice, so its count will be 2, causing it to be
1748 * skipped when processing scan results.
1750 ret = wpa_blacklist_add(wpa_s, bssid);
1753 ret = wpa_blacklist_add(wpa_s, bssid);
1756 os_memcpy(buf, "OK\n", 3);
1761 static const char * debug_level_str(int level)
1782 static int str_to_debug_level(const char *s)
1784 if (os_strcasecmp(s, "EXCESSIVE") == 0)
1785 return MSG_EXCESSIVE;
1786 if (os_strcasecmp(s, "MSGDUMP") == 0)
1788 if (os_strcasecmp(s, "DEBUG") == 0)
1790 if (os_strcasecmp(s, "INFO") == 0)
1792 if (os_strcasecmp(s, "WARNING") == 0)
1794 if (os_strcasecmp(s, "ERROR") == 0)
1800 static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant *wpa_s,
1801 char *cmd, char *buf,
1804 char *pos, *end, *stamp;
1811 /* cmd: "LOG_LEVEL [<level>]" */
1815 ret = os_snprintf(pos, end - pos, "Current level: %s\n"
1817 debug_level_str(wpa_debug_level),
1818 wpa_debug_timestamp);
1819 if (ret < 0 || ret >= end - pos)
1828 stamp = os_strchr(cmd, ' ');
1831 while (*stamp == ' ') {
1836 if (cmd && os_strlen(cmd)) {
1837 int level = str_to_debug_level(cmd);
1840 wpa_debug_level = level;
1843 if (stamp && os_strlen(stamp))
1844 wpa_debug_timestamp = atoi(stamp);
1846 os_memcpy(buf, "OK\n", 3);
1851 static int wpa_supplicant_ctrl_iface_list_networks(
1852 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
1855 struct wpa_ssid *ssid;
1860 ret = os_snprintf(pos, end - pos,
1861 "network id / ssid / bssid / flags\n");
1862 if (ret < 0 || ret >= end - pos)
1866 ssid = wpa_s->conf->ssid;
1868 ret = os_snprintf(pos, end - pos, "%d\t%s",
1870 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
1871 if (ret < 0 || ret >= end - pos)
1874 if (ssid->bssid_set) {
1875 ret = os_snprintf(pos, end - pos, "\t" MACSTR,
1876 MAC2STR(ssid->bssid));
1878 ret = os_snprintf(pos, end - pos, "\tany");
1880 if (ret < 0 || ret >= end - pos)
1883 ret = os_snprintf(pos, end - pos, "\t%s%s%s%s",
1884 ssid == wpa_s->current_ssid ?
1886 ssid->disabled ? "[DISABLED]" : "",
1887 ssid->disabled_until.sec ?
1888 "[TEMP-DISABLED]" : "",
1889 ssid->disabled == 2 ? "[P2P-PERSISTENT]" :
1891 if (ret < 0 || ret >= end - pos)
1894 ret = os_snprintf(pos, end - pos, "\n");
1895 if (ret < 0 || ret >= end - pos)
1906 static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher)
1909 ret = os_snprintf(pos, end - pos, "-");
1910 if (ret < 0 || ret >= end - pos)
1913 ret = wpa_write_ciphers(pos, end, cipher, "+");
1921 static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
1922 const u8 *ie, size_t ie_len)
1924 struct wpa_ie_data data;
1927 ret = os_snprintf(pos, end - pos, "[%s-", proto);
1928 if (ret < 0 || ret >= end - pos)
1932 if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) {
1933 ret = os_snprintf(pos, end - pos, "?]");
1934 if (ret < 0 || ret >= end - pos)
1941 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
1942 ret = os_snprintf(pos, end - pos, "%sEAP", first ? "" : "+");
1943 if (ret < 0 || ret >= end - pos)
1948 if (data.key_mgmt & WPA_KEY_MGMT_PSK) {
1949 ret = os_snprintf(pos, end - pos, "%sPSK", first ? "" : "+");
1950 if (ret < 0 || ret >= end - pos)
1955 if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
1956 ret = os_snprintf(pos, end - pos, "%sNone", first ? "" : "+");
1957 if (ret < 0 || ret >= end - pos)
1962 #ifdef CONFIG_IEEE80211R
1963 if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
1964 ret = os_snprintf(pos, end - pos, "%sFT/EAP",
1966 if (ret < 0 || ret >= end - pos)
1971 if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) {
1972 ret = os_snprintf(pos, end - pos, "%sFT/PSK",
1974 if (ret < 0 || ret >= end - pos)
1979 #endif /* CONFIG_IEEE80211R */
1980 #ifdef CONFIG_IEEE80211W
1981 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
1982 ret = os_snprintf(pos, end - pos, "%sEAP-SHA256",
1984 if (ret < 0 || ret >= end - pos)
1989 if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
1990 ret = os_snprintf(pos, end - pos, "%sPSK-SHA256",
1992 if (ret < 0 || ret >= end - pos)
1997 #endif /* CONFIG_IEEE80211W */
1999 pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher);
2001 if (data.capabilities & WPA_CAPABILITY_PREAUTH) {
2002 ret = os_snprintf(pos, end - pos, "-preauth");
2003 if (ret < 0 || ret >= end - pos)
2008 ret = os_snprintf(pos, end - pos, "]");
2009 if (ret < 0 || ret >= end - pos)
2018 static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s,
2019 char *pos, char *end,
2020 struct wpabuf *wps_ie)
2027 if (wps_is_selected_pbc_registrar(wps_ie))
2030 else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0))
2032 #endif /* CONFIG_WPS2 */
2033 else if (wps_is_selected_pin_registrar(wps_ie))
2038 ret = os_snprintf(pos, end - pos, "%s", txt);
2039 if (ret >= 0 && ret < end - pos)
2041 wpabuf_free(wps_ie);
2044 #endif /* CONFIG_WPS */
2047 static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s,
2048 char *pos, char *end,
2049 const struct wpa_bss *bss)
2052 struct wpabuf *wps_ie;
2053 wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
2054 return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie);
2055 #else /* CONFIG_WPS */
2057 #endif /* CONFIG_WPS */
2061 /* Format one result on one text line into a buffer. */
2062 static int wpa_supplicant_ctrl_iface_scan_result(
2063 struct wpa_supplicant *wpa_s,
2064 const struct wpa_bss *bss, char *buf, size_t buflen)
2068 const u8 *ie, *ie2, *p2p;
2070 p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
2072 p2p = wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE);
2073 if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN &&
2074 os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) ==
2076 return 0; /* Do not show P2P listen discovery results here */
2081 ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t",
2082 MAC2STR(bss->bssid), bss->freq, bss->level);
2083 if (ret < 0 || ret >= end - pos)
2086 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
2088 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]);
2089 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
2091 pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2, 2 + ie2[1]);
2092 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
2093 if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
2094 ret = os_snprintf(pos, end - pos, "[WEP]");
2095 if (ret < 0 || ret >= end - pos)
2099 if (bss->caps & IEEE80211_CAP_IBSS) {
2100 ret = os_snprintf(pos, end - pos, "[IBSS]");
2101 if (ret < 0 || ret >= end - pos)
2105 if (bss->caps & IEEE80211_CAP_ESS) {
2106 ret = os_snprintf(pos, end - pos, "[ESS]");
2107 if (ret < 0 || ret >= end - pos)
2112 ret = os_snprintf(pos, end - pos, "[P2P]");
2113 if (ret < 0 || ret >= end - pos)
2118 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE) && ie2) {
2119 ret = os_snprintf(pos, end - pos, "[HS20]");
2120 if (ret < 0 || ret >= end - pos)
2124 #endif /* CONFIG_HS20 */
2126 ret = os_snprintf(pos, end - pos, "\t%s",
2127 wpa_ssid_txt(bss->ssid, bss->ssid_len));
2128 if (ret < 0 || ret >= end - pos)
2132 ret = os_snprintf(pos, end - pos, "\n");
2133 if (ret < 0 || ret >= end - pos)
2141 static int wpa_supplicant_ctrl_iface_scan_results(
2142 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
2145 struct wpa_bss *bss;
2150 ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / "
2152 if (ret < 0 || ret >= end - pos)
2156 dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
2157 ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos,
2159 if (ret < 0 || ret >= end - pos)
2168 static int wpa_supplicant_ctrl_iface_select_network(
2169 struct wpa_supplicant *wpa_s, char *cmd)
2172 struct wpa_ssid *ssid;
2174 /* cmd: "<network id>" or "any" */
2175 if (os_strcmp(cmd, "any") == 0) {
2176 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any");
2180 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id);
2182 ssid = wpa_config_get_network(wpa_s->conf, id);
2184 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2185 "network id=%d", id);
2188 if (ssid->disabled == 2) {
2189 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2190 "SELECT_NETWORK with persistent P2P group");
2195 wpa_supplicant_select_network(wpa_s, ssid);
2201 static int wpa_supplicant_ctrl_iface_enable_network(
2202 struct wpa_supplicant *wpa_s, char *cmd)
2205 struct wpa_ssid *ssid;
2207 /* cmd: "<network id>" or "all" */
2208 if (os_strcmp(cmd, "all") == 0) {
2209 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all");
2213 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id);
2215 ssid = wpa_config_get_network(wpa_s->conf, id);
2217 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2218 "network id=%d", id);
2221 if (ssid->disabled == 2) {
2222 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2223 "ENABLE_NETWORK with persistent P2P group");
2227 if (os_strstr(cmd, " no-connect")) {
2232 wpa_supplicant_enable_network(wpa_s, ssid);
2238 static int wpa_supplicant_ctrl_iface_disable_network(
2239 struct wpa_supplicant *wpa_s, char *cmd)
2242 struct wpa_ssid *ssid;
2244 /* cmd: "<network id>" or "all" */
2245 if (os_strcmp(cmd, "all") == 0) {
2246 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all");
2250 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id);
2252 ssid = wpa_config_get_network(wpa_s->conf, id);
2254 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2255 "network id=%d", id);
2258 if (ssid->disabled == 2) {
2259 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2260 "DISABLE_NETWORK with persistent P2P "
2265 wpa_supplicant_disable_network(wpa_s, ssid);
2271 static int wpa_supplicant_ctrl_iface_add_network(
2272 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
2274 struct wpa_ssid *ssid;
2277 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK");
2279 ssid = wpa_config_add_network(wpa_s->conf);
2283 wpas_notify_network_added(wpa_s, ssid);
2286 wpa_config_set_network_defaults(ssid);
2288 ret = os_snprintf(buf, buflen, "%d\n", ssid->id);
2289 if (ret < 0 || (size_t) ret >= buflen)
2295 static int wpa_supplicant_ctrl_iface_remove_network(
2296 struct wpa_supplicant *wpa_s, char *cmd)
2299 struct wpa_ssid *ssid;
2302 /* cmd: "<network id>" or "all" */
2303 if (os_strcmp(cmd, "all") == 0) {
2304 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all");
2305 if (wpa_s->sched_scanning)
2306 wpa_supplicant_cancel_sched_scan(wpa_s);
2308 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2309 if (wpa_s->current_ssid) {
2311 wpa_s->sme.prev_bssid_set = 0;
2312 #endif /* CONFIG_SME */
2313 wpa_sm_set_config(wpa_s->wpa, NULL);
2314 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
2315 wpa_supplicant_deauthenticate(
2316 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2318 ssid = wpa_s->conf->ssid;
2320 struct wpa_ssid *remove_ssid = ssid;
2323 wpas_notify_network_removed(wpa_s, remove_ssid);
2324 wpa_config_remove_network(wpa_s->conf, id);
2330 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id);
2332 ssid = wpa_config_get_network(wpa_s->conf, id);
2334 wpas_notify_network_removed(wpa_s, ssid);
2336 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2341 if (ssid == wpa_s->current_ssid || wpa_s->current_ssid == NULL) {
2343 wpa_s->sme.prev_bssid_set = 0;
2344 #endif /* CONFIG_SME */
2346 * Invalidate the EAP session cache if the current or
2347 * previously used network is removed.
2349 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2352 if (ssid == wpa_s->current_ssid) {
2353 wpa_sm_set_config(wpa_s->wpa, NULL);
2354 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
2356 wpa_supplicant_deauthenticate(wpa_s,
2357 WLAN_REASON_DEAUTH_LEAVING);
2360 was_disabled = ssid->disabled;
2362 if (wpa_config_remove_network(wpa_s->conf, id) < 0) {
2363 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Not able to remove the "
2364 "network id=%d", id);
2368 if (!was_disabled && wpa_s->sched_scanning) {
2369 wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to remove "
2370 "network from filters");
2371 wpa_supplicant_cancel_sched_scan(wpa_s);
2372 wpa_supplicant_req_scan(wpa_s, 0, 0);
2379 static int wpa_supplicant_ctrl_iface_set_network(
2380 struct wpa_supplicant *wpa_s, char *cmd)
2383 struct wpa_ssid *ssid;
2386 /* cmd: "<network id> <variable name> <value>" */
2387 name = os_strchr(cmd, ' ');
2392 value = os_strchr(name, ' ');
2398 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
2400 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
2401 (u8 *) value, os_strlen(value));
2403 ssid = wpa_config_get_network(wpa_s->conf, id);
2405 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2410 if (wpa_config_set(ssid, name, value, 0) < 0) {
2411 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network "
2412 "variable '%s'", name);
2416 if (os_strcmp(name, "bssid") != 0 &&
2417 os_strcmp(name, "priority") != 0)
2418 wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
2420 if (wpa_s->current_ssid == ssid || wpa_s->current_ssid == NULL) {
2422 * Invalidate the EAP session cache if anything in the current
2423 * or previously used configuration changes.
2425 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2428 if ((os_strcmp(name, "psk") == 0 &&
2429 value[0] == '"' && ssid->ssid_len) ||
2430 (os_strcmp(name, "ssid") == 0 && ssid->passphrase))
2431 wpa_config_update_psk(ssid);
2432 else if (os_strcmp(name, "priority") == 0)
2433 wpa_config_update_prio_list(wpa_s->conf);
2439 static int wpa_supplicant_ctrl_iface_get_network(
2440 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
2444 struct wpa_ssid *ssid;
2447 /* cmd: "<network id> <variable name>" */
2448 name = os_strchr(cmd, ' ');
2449 if (name == NULL || buflen == 0)
2454 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
2457 ssid = wpa_config_get_network(wpa_s->conf, id);
2459 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2464 value = wpa_config_get_no_key(ssid, name);
2465 if (value == NULL) {
2466 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
2467 "variable '%s'", name);
2471 res = os_strlcpy(buf, value, buflen);
2472 if (res >= buflen) {
2483 static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant *wpa_s,
2484 char *buf, size_t buflen)
2487 struct wpa_cred *cred;
2492 ret = os_snprintf(pos, end - pos,
2493 "cred id / realm / username / domain / imsi\n");
2494 if (ret < 0 || ret >= end - pos)
2498 cred = wpa_s->conf->cred;
2500 ret = os_snprintf(pos, end - pos, "%d\t%s\t%s\t%s\t%s\n",
2501 cred->id, cred->realm ? cred->realm : "",
2502 cred->username ? cred->username : "",
2503 cred->domain ? cred->domain[0] : "",
2504 cred->imsi ? cred->imsi : "");
2505 if (ret < 0 || ret >= end - pos)
2516 static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant *wpa_s,
2517 char *buf, size_t buflen)
2519 struct wpa_cred *cred;
2522 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_CRED");
2524 cred = wpa_config_add_cred(wpa_s->conf);
2528 ret = os_snprintf(buf, buflen, "%d\n", cred->id);
2529 if (ret < 0 || (size_t) ret >= buflen)
2535 static int wpas_ctrl_remove_cred(struct wpa_supplicant *wpa_s,
2536 struct wpa_cred *cred)
2538 struct wpa_ssid *ssid;
2541 if (cred == NULL || wpa_config_remove_cred(wpa_s->conf, cred->id) < 0) {
2542 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred");
2546 /* Remove any network entry created based on the removed credential */
2547 ssid = wpa_s->conf->ssid;
2549 if (ssid->parent_cred == cred) {
2550 wpa_printf(MSG_DEBUG, "Remove network id %d since it "
2551 "used the removed credential", ssid->id);
2552 os_snprintf(str, sizeof(str), "%d", ssid->id);
2554 wpa_supplicant_ctrl_iface_remove_network(wpa_s, str);
2563 static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s,
2567 struct wpa_cred *cred, *prev;
2569 /* cmd: "<cred id>", "all", or "sp_fqdn=<FQDN>" */
2570 if (os_strcmp(cmd, "all") == 0) {
2571 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED all");
2572 cred = wpa_s->conf->cred;
2576 wpas_ctrl_remove_cred(wpa_s, prev);
2581 if (os_strncmp(cmd, "sp_fqdn=", 8) == 0) {
2582 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
2584 cred = wpa_s->conf->cred;
2590 for (i = 0; i < prev->num_domain; i++) {
2591 if (os_strcmp(prev->domain[i], cmd + 8)
2594 wpas_ctrl_remove_cred(wpa_s, prev);
2603 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED id=%d", id);
2605 cred = wpa_config_get_cred(wpa_s->conf, id);
2606 return wpas_ctrl_remove_cred(wpa_s, cred);
2610 static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant *wpa_s,
2614 struct wpa_cred *cred;
2617 /* cmd: "<cred id> <variable name> <value>" */
2618 name = os_strchr(cmd, ' ');
2623 value = os_strchr(name, ' ');
2629 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_CRED id=%d name='%s'",
2631 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
2632 (u8 *) value, os_strlen(value));
2634 cred = wpa_config_get_cred(wpa_s->conf, id);
2636 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
2641 if (wpa_config_set_cred(cred, name, value, 0) < 0) {
2642 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set cred "
2643 "variable '%s'", name);
2651 #ifndef CONFIG_NO_CONFIG_WRITE
2652 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s)
2656 if (!wpa_s->conf->update_config) {
2657 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
2658 "to update configuration (update_config=0)");
2662 ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
2664 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to "
2665 "update configuration");
2667 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration"
2673 #endif /* CONFIG_NO_CONFIG_WRITE */
2676 struct cipher_info {
2682 static const struct cipher_info ciphers[] = {
2683 { WPA_DRIVER_CAPA_ENC_CCMP_256, "CCMP-256", 0 },
2684 { WPA_DRIVER_CAPA_ENC_GCMP_256, "GCMP-256", 0 },
2685 { WPA_DRIVER_CAPA_ENC_CCMP, "CCMP", 0 },
2686 { WPA_DRIVER_CAPA_ENC_GCMP, "GCMP", 0 },
2687 { WPA_DRIVER_CAPA_ENC_TKIP, "TKIP", 0 },
2688 { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE, "NONE", 0 },
2689 { WPA_DRIVER_CAPA_ENC_WEP104, "WEP104", 1 },
2690 { WPA_DRIVER_CAPA_ENC_WEP40, "WEP40", 1 }
2694 static int ctrl_iface_get_capability_pairwise(int res, char *strict,
2695 struct wpa_driver_capa *capa,
2696 char *buf, size_t buflen)
2709 len = os_strlcpy(buf, "CCMP TKIP NONE", buflen);
2715 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
2716 if (!ciphers[i].group_only && capa->enc & ciphers[i].capa) {
2717 ret = os_snprintf(pos, end - pos, "%s%s",
2718 first ? "" : " ", ciphers[i].name);
2719 if (ret < 0 || ret >= end - pos)
2730 static int ctrl_iface_get_capability_group(int res, char *strict,
2731 struct wpa_driver_capa *capa,
2732 char *buf, size_t buflen)
2745 len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen);
2751 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
2752 if (capa->enc & ciphers[i].capa) {
2753 ret = os_snprintf(pos, end - pos, "%s%s",
2754 first ? "" : " ", ciphers[i].name);
2755 if (ret < 0 || ret >= end - pos)
2766 static int ctrl_iface_get_capability_key_mgmt(int res, char *strict,
2767 struct wpa_driver_capa *capa,
2768 char *buf, size_t buflen)
2780 len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
2787 ret = os_snprintf(pos, end - pos, "NONE IEEE8021X");
2788 if (ret < 0 || ret >= end - pos)
2792 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
2793 WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
2794 ret = os_snprintf(pos, end - pos, " WPA-EAP");
2795 if (ret < 0 || ret >= end - pos)
2800 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
2801 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
2802 ret = os_snprintf(pos, end - pos, " WPA-PSK");
2803 if (ret < 0 || ret >= end - pos)
2808 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
2809 ret = os_snprintf(pos, end - pos, " WPA-NONE");
2810 if (ret < 0 || ret >= end - pos)
2819 static int ctrl_iface_get_capability_proto(int res, char *strict,
2820 struct wpa_driver_capa *capa,
2821 char *buf, size_t buflen)
2833 len = os_strlcpy(buf, "RSN WPA", buflen);
2839 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
2840 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
2841 ret = os_snprintf(pos, end - pos, "%sRSN", first ? "" : " ");
2842 if (ret < 0 || ret >= end - pos)
2848 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
2849 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
2850 ret = os_snprintf(pos, end - pos, "%sWPA", first ? "" : " ");
2851 if (ret < 0 || ret >= end - pos)
2861 static int ctrl_iface_get_capability_auth_alg(int res, char *strict,
2862 struct wpa_driver_capa *capa,
2863 char *buf, size_t buflen)
2875 len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen);
2881 if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) {
2882 ret = os_snprintf(pos, end - pos, "%sOPEN", first ? "" : " ");
2883 if (ret < 0 || ret >= end - pos)
2889 if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) {
2890 ret = os_snprintf(pos, end - pos, "%sSHARED",
2892 if (ret < 0 || ret >= end - pos)
2898 if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) {
2899 ret = os_snprintf(pos, end - pos, "%sLEAP", first ? "" : " ");
2900 if (ret < 0 || ret >= end - pos)
2910 static int ctrl_iface_get_capability_modes(int res, char *strict,
2911 struct wpa_driver_capa *capa,
2912 char *buf, size_t buflen)
2924 len = os_strlcpy(buf, "IBSS AP", buflen);
2930 if (capa->flags & WPA_DRIVER_FLAGS_IBSS) {
2931 ret = os_snprintf(pos, end - pos, "%sIBSS", first ? "" : " ");
2932 if (ret < 0 || ret >= end - pos)
2938 if (capa->flags & WPA_DRIVER_FLAGS_AP) {
2939 ret = os_snprintf(pos, end - pos, "%sAP", first ? "" : " ");
2940 if (ret < 0 || ret >= end - pos)
2950 static int ctrl_iface_get_capability_channels(struct wpa_supplicant *wpa_s,
2951 char *buf, size_t buflen)
2953 struct hostapd_channel_data *chnl;
2955 char *pos, *end, *hmode;
2960 for (j = 0; j < wpa_s->hw.num_modes; j++) {
2961 switch (wpa_s->hw.modes[j].mode) {
2962 case HOSTAPD_MODE_IEEE80211B:
2965 case HOSTAPD_MODE_IEEE80211G:
2968 case HOSTAPD_MODE_IEEE80211A:
2971 case HOSTAPD_MODE_IEEE80211AD:
2977 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:", hmode);
2978 if (ret < 0 || ret >= end - pos)
2981 chnl = wpa_s->hw.modes[j].channels;
2982 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
2983 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
2985 ret = os_snprintf(pos, end - pos, " %d", chnl[i].chan);
2986 if (ret < 0 || ret >= end - pos)
2990 ret = os_snprintf(pos, end - pos, "\n");
2991 if (ret < 0 || ret >= end - pos)
3000 static int ctrl_iface_get_capability_freq(struct wpa_supplicant *wpa_s,
3001 char *buf, size_t buflen)
3003 struct hostapd_channel_data *chnl;
3005 char *pos, *end, *hmode;
3010 for (j = 0; j < wpa_s->hw.num_modes; j++) {
3011 switch (wpa_s->hw.modes[j].mode) {
3012 case HOSTAPD_MODE_IEEE80211B:
3015 case HOSTAPD_MODE_IEEE80211G:
3018 case HOSTAPD_MODE_IEEE80211A:
3021 case HOSTAPD_MODE_IEEE80211AD:
3027 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:\n",
3029 if (ret < 0 || ret >= end - pos)
3032 chnl = wpa_s->hw.modes[j].channels;
3033 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
3034 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
3036 ret = os_snprintf(pos, end - pos, " %d = %d MHz%s\n",
3037 chnl[i].chan, chnl[i].freq,
3038 chnl[i].flag & HOSTAPD_CHAN_NO_IBSS ?
3040 if (ret < 0 || ret >= end - pos)
3044 ret = os_snprintf(pos, end - pos, "\n");
3045 if (ret < 0 || ret >= end - pos)
3054 static int wpa_supplicant_ctrl_iface_get_capability(
3055 struct wpa_supplicant *wpa_s, const char *_field, char *buf,
3058 struct wpa_driver_capa capa;
3064 /* Determine whether or not strict checking was requested */
3065 len = os_strlcpy(field, _field, sizeof(field));
3066 if (len >= sizeof(field))
3068 strict = os_strchr(field, ' ');
3069 if (strict != NULL) {
3071 if (os_strcmp(strict, "strict") != 0)
3075 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
3076 field, strict ? strict : "");
3078 if (os_strcmp(field, "eap") == 0) {
3079 return eap_get_names(buf, buflen);
3082 res = wpa_drv_get_capa(wpa_s, &capa);
3084 if (os_strcmp(field, "pairwise") == 0)
3085 return ctrl_iface_get_capability_pairwise(res, strict, &capa,
3088 if (os_strcmp(field, "group") == 0)
3089 return ctrl_iface_get_capability_group(res, strict, &capa,
3092 if (os_strcmp(field, "key_mgmt") == 0)
3093 return ctrl_iface_get_capability_key_mgmt(res, strict, &capa,
3096 if (os_strcmp(field, "proto") == 0)
3097 return ctrl_iface_get_capability_proto(res, strict, &capa,
3100 if (os_strcmp(field, "auth_alg") == 0)
3101 return ctrl_iface_get_capability_auth_alg(res, strict, &capa,
3104 if (os_strcmp(field, "modes") == 0)
3105 return ctrl_iface_get_capability_modes(res, strict, &capa,
3108 if (os_strcmp(field, "channels") == 0)
3109 return ctrl_iface_get_capability_channels(wpa_s, buf, buflen);
3111 if (os_strcmp(field, "freq") == 0)
3112 return ctrl_iface_get_capability_freq(wpa_s, buf, buflen);
3114 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
3121 #ifdef CONFIG_INTERWORKING
3122 static char * anqp_add_hex(char *pos, char *end, const char *title,
3123 struct wpabuf *data)
3133 ret = os_snprintf(pos, end - pos, "%s=", title);
3134 if (ret < 0 || ret >= end - pos)
3138 d = wpabuf_head_u8(data);
3139 for (i = 0; i < wpabuf_len(data); i++) {
3140 ret = os_snprintf(pos, end - pos, "%02x", *d++);
3141 if (ret < 0 || ret >= end - pos)
3146 ret = os_snprintf(pos, end - pos, "\n");
3147 if (ret < 0 || ret >= end - pos)
3153 #endif /* CONFIG_INTERWORKING */
3156 static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
3157 unsigned long mask, char *buf, size_t buflen)
3167 if (mask & WPA_BSS_MASK_ID) {
3168 ret = os_snprintf(pos, end - pos, "id=%u\n", bss->id);
3169 if (ret < 0 || ret >= end - pos)
3174 if (mask & WPA_BSS_MASK_BSSID) {
3175 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
3176 MAC2STR(bss->bssid));
3177 if (ret < 0 || ret >= end - pos)
3182 if (mask & WPA_BSS_MASK_FREQ) {
3183 ret = os_snprintf(pos, end - pos, "freq=%d\n", bss->freq);
3184 if (ret < 0 || ret >= end - pos)
3189 if (mask & WPA_BSS_MASK_BEACON_INT) {
3190 ret = os_snprintf(pos, end - pos, "beacon_int=%d\n",
3192 if (ret < 0 || ret >= end - pos)
3197 if (mask & WPA_BSS_MASK_CAPABILITIES) {
3198 ret = os_snprintf(pos, end - pos, "capabilities=0x%04x\n",
3200 if (ret < 0 || ret >= end - pos)
3205 if (mask & WPA_BSS_MASK_QUAL) {
3206 ret = os_snprintf(pos, end - pos, "qual=%d\n", bss->qual);
3207 if (ret < 0 || ret >= end - pos)
3212 if (mask & WPA_BSS_MASK_NOISE) {
3213 ret = os_snprintf(pos, end - pos, "noise=%d\n", bss->noise);
3214 if (ret < 0 || ret >= end - pos)
3219 if (mask & WPA_BSS_MASK_LEVEL) {
3220 ret = os_snprintf(pos, end - pos, "level=%d\n", bss->level);
3221 if (ret < 0 || ret >= end - pos)
3226 if (mask & WPA_BSS_MASK_TSF) {
3227 ret = os_snprintf(pos, end - pos, "tsf=%016llu\n",
3228 (unsigned long long) bss->tsf);
3229 if (ret < 0 || ret >= end - pos)
3234 if (mask & WPA_BSS_MASK_AGE) {
3235 struct os_reltime now;
3237 os_get_reltime(&now);
3238 ret = os_snprintf(pos, end - pos, "age=%d\n",
3239 (int) (now.sec - bss->last_update.sec));
3240 if (ret < 0 || ret >= end - pos)
3245 if (mask & WPA_BSS_MASK_IE) {
3246 ret = os_snprintf(pos, end - pos, "ie=");
3247 if (ret < 0 || ret >= end - pos)
3251 ie = (const u8 *) (bss + 1);
3252 for (i = 0; i < bss->ie_len; i++) {
3253 ret = os_snprintf(pos, end - pos, "%02x", *ie++);
3254 if (ret < 0 || ret >= end - pos)
3259 ret = os_snprintf(pos, end - pos, "\n");
3260 if (ret < 0 || ret >= end - pos)
3265 if (mask & WPA_BSS_MASK_FLAGS) {
3266 ret = os_snprintf(pos, end - pos, "flags=");
3267 if (ret < 0 || ret >= end - pos)
3271 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
3273 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie,
3275 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
3277 pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2,
3279 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
3280 if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
3281 ret = os_snprintf(pos, end - pos, "[WEP]");
3282 if (ret < 0 || ret >= end - pos)
3286 if (bss->caps & IEEE80211_CAP_IBSS) {
3287 ret = os_snprintf(pos, end - pos, "[IBSS]");
3288 if (ret < 0 || ret >= end - pos)
3292 if (bss->caps & IEEE80211_CAP_ESS) {
3293 ret = os_snprintf(pos, end - pos, "[ESS]");
3294 if (ret < 0 || ret >= end - pos)
3298 if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
3299 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
3300 ret = os_snprintf(pos, end - pos, "[P2P]");
3301 if (ret < 0 || ret >= end - pos)
3306 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) {
3307 ret = os_snprintf(pos, end - pos, "[HS20]");
3308 if (ret < 0 || ret >= end - pos)
3312 #endif /* CONFIG_HS20 */
3314 ret = os_snprintf(pos, end - pos, "\n");
3315 if (ret < 0 || ret >= end - pos)
3320 if (mask & WPA_BSS_MASK_SSID) {
3321 ret = os_snprintf(pos, end - pos, "ssid=%s\n",
3322 wpa_ssid_txt(bss->ssid, bss->ssid_len));
3323 if (ret < 0 || ret >= end - pos)
3329 if (mask & WPA_BSS_MASK_WPS_SCAN) {
3330 ie = (const u8 *) (bss + 1);
3331 ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end);
3332 if (ret < 0 || ret >= end - pos)
3336 #endif /* CONFIG_WPS */
3339 if (mask & WPA_BSS_MASK_P2P_SCAN) {
3340 ie = (const u8 *) (bss + 1);
3341 ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end);
3342 if (ret < 0 || ret >= end - pos)
3346 #endif /* CONFIG_P2P */
3348 #ifdef CONFIG_WIFI_DISPLAY
3349 if (mask & WPA_BSS_MASK_WIFI_DISPLAY) {
3351 ie = (const u8 *) (bss + 1);
3352 wfd = ieee802_11_vendor_ie_concat(ie, bss->ie_len,
3353 WFD_IE_VENDOR_TYPE);
3355 ret = os_snprintf(pos, end - pos, "wfd_subelems=");
3356 if (ret < 0 || ret >= end - pos)
3360 pos += wpa_snprintf_hex(pos, end - pos,
3365 ret = os_snprintf(pos, end - pos, "\n");
3366 if (ret < 0 || ret >= end - pos)
3371 #endif /* CONFIG_WIFI_DISPLAY */
3373 #ifdef CONFIG_INTERWORKING
3374 if ((mask & WPA_BSS_MASK_INTERNETW) && bss->anqp) {
3375 struct wpa_bss_anqp *anqp = bss->anqp;
3376 pos = anqp_add_hex(pos, end, "anqp_venue_name",
3378 pos = anqp_add_hex(pos, end, "anqp_network_auth_type",
3379 anqp->network_auth_type);
3380 pos = anqp_add_hex(pos, end, "anqp_roaming_consortium",
3381 anqp->roaming_consortium);
3382 pos = anqp_add_hex(pos, end, "anqp_ip_addr_type_availability",
3383 anqp->ip_addr_type_availability);
3384 pos = anqp_add_hex(pos, end, "anqp_nai_realm",
3386 pos = anqp_add_hex(pos, end, "anqp_3gpp", anqp->anqp_3gpp);
3387 pos = anqp_add_hex(pos, end, "anqp_domain_name",
3390 pos = anqp_add_hex(pos, end, "hs20_operator_friendly_name",
3391 anqp->hs20_operator_friendly_name);
3392 pos = anqp_add_hex(pos, end, "hs20_wan_metrics",
3393 anqp->hs20_wan_metrics);
3394 pos = anqp_add_hex(pos, end, "hs20_connection_capability",
3395 anqp->hs20_connection_capability);
3396 #endif /* CONFIG_HS20 */
3398 #endif /* CONFIG_INTERWORKING */
3400 if (mask & WPA_BSS_MASK_DELIM) {
3401 ret = os_snprintf(pos, end - pos, "====\n");
3402 if (ret < 0 || ret >= end - pos)
3411 static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
3412 const char *cmd, char *buf,
3417 struct wpa_bss *bss;
3418 struct wpa_bss *bsslast = NULL;
3419 struct dl_list *next;
3423 unsigned long mask = WPA_BSS_MASK_ALL;
3425 if (os_strncmp(cmd, "RANGE=", 6) == 0) {
3426 if (os_strncmp(cmd + 6, "ALL", 3) == 0) {
3427 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss,
3429 bsslast = dl_list_last(&wpa_s->bss_id, struct wpa_bss,
3431 } else { /* N1-N2 */
3432 unsigned int id1, id2;
3434 if ((ctmp = os_strchr(cmd + 6, '-')) == NULL) {
3435 wpa_printf(MSG_INFO, "Wrong BSS range "
3440 if (*(cmd + 6) == '-')
3443 id1 = atoi(cmd + 6);
3445 if (*ctmp >= '0' && *ctmp <= '9')
3448 id2 = (unsigned int) -1;
3449 bss = wpa_bss_get_id_range(wpa_s, id1, id2);
3450 if (id2 == (unsigned int) -1)
3451 bsslast = dl_list_last(&wpa_s->bss_id,
3455 bsslast = wpa_bss_get_id(wpa_s, id2);
3456 if (bsslast == NULL && bss && id2 > id1) {
3457 struct wpa_bss *tmp = bss;
3459 next = tmp->list_id.next;
3460 if (next == &wpa_s->bss_id)
3462 tmp = dl_list_entry(
3463 next, struct wpa_bss,
3472 } else if (os_strncmp(cmd, "FIRST", 5) == 0)
3473 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, list_id);
3474 else if (os_strncmp(cmd, "LAST", 4) == 0)
3475 bss = dl_list_last(&wpa_s->bss_id, struct wpa_bss, list_id);
3476 else if (os_strncmp(cmd, "ID-", 3) == 0) {
3478 bss = wpa_bss_get_id(wpa_s, i);
3479 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
3481 bss = wpa_bss_get_id(wpa_s, i);
3483 next = bss->list_id.next;
3484 if (next == &wpa_s->bss_id)
3487 bss = dl_list_entry(next, struct wpa_bss,
3491 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
3492 if (hwaddr_aton(cmd + 13, bssid) == 0)
3493 bss = wpa_bss_get_p2p_dev_addr(wpa_s, bssid);
3496 #endif /* CONFIG_P2P */
3497 } else if (hwaddr_aton(cmd, bssid) == 0)
3498 bss = wpa_bss_get_bssid(wpa_s, bssid);
3500 struct wpa_bss *tmp;
3503 dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id)
3512 if ((ctmp = os_strstr(cmd, "MASK=")) != NULL) {
3513 mask = strtoul(ctmp + 5, NULL, 0x10);
3515 mask = WPA_BSS_MASK_ALL;
3521 if (bsslast == NULL)
3524 len = print_bss_info(wpa_s, bss, mask, buf, buflen);
3528 if (bss == bsslast) {
3529 if ((mask & WPA_BSS_MASK_DELIM) && len &&
3530 (bss == dl_list_last(&wpa_s->bss_id,
3531 struct wpa_bss, list_id)))
3532 os_snprintf(buf - 5, 5, "####\n");
3535 next = bss->list_id.next;
3536 if (next == &wpa_s->bss_id)
3538 bss = dl_list_entry(next, struct wpa_bss, list_id);
3539 } while (bss && len);
3545 static int wpa_supplicant_ctrl_iface_ap_scan(
3546 struct wpa_supplicant *wpa_s, char *cmd)
3548 int ap_scan = atoi(cmd);
3549 return wpa_supplicant_set_ap_scan(wpa_s, ap_scan);
3553 static int wpa_supplicant_ctrl_iface_scan_interval(
3554 struct wpa_supplicant *wpa_s, char *cmd)
3556 int scan_int = atoi(cmd);
3557 return wpa_supplicant_set_scan_interval(wpa_s, scan_int);
3561 static int wpa_supplicant_ctrl_iface_bss_expire_age(
3562 struct wpa_supplicant *wpa_s, char *cmd)
3564 int expire_age = atoi(cmd);
3565 return wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age);
3569 static int wpa_supplicant_ctrl_iface_bss_expire_count(
3570 struct wpa_supplicant *wpa_s, char *cmd)
3572 int expire_count = atoi(cmd);
3573 return wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count);
3577 static int wpa_supplicant_ctrl_iface_bss_flush(
3578 struct wpa_supplicant *wpa_s, char *cmd)
3580 int flush_age = atoi(cmd);
3583 wpa_bss_flush(wpa_s);
3585 wpa_bss_flush_by_age(wpa_s, flush_age);
3590 static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s)
3592 wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication");
3593 /* MLME-DELETEKEYS.request */
3594 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL, 0);
3595 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL, 0);
3596 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL, 0);
3597 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL, 0);
3598 #ifdef CONFIG_IEEE80211W
3599 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL, 0);
3600 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL, 0);
3601 #endif /* CONFIG_IEEE80211W */
3603 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, wpa_s->bssid, 0, 0, NULL, 0, NULL,
3605 /* MLME-SETPROTECTION.request(None) */
3606 wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid,
3607 MLME_SETPROTECTION_PROTECT_TYPE_NONE,
3608 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE);
3609 wpa_sm_drop_sa(wpa_s->wpa);
3613 static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s,
3616 #ifdef CONFIG_NO_SCAN_PROCESSING
3618 #else /* CONFIG_NO_SCAN_PROCESSING */
3620 struct wpa_bss *bss;
3621 struct wpa_ssid *ssid = wpa_s->current_ssid;
3623 if (hwaddr_aton(addr, bssid)) {
3624 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid "
3625 "address '%s'", addr);
3629 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR, MAC2STR(bssid));
3632 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network "
3633 "configuration known for the target AP");
3637 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
3639 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found "
3645 * TODO: Find best network configuration block from configuration to
3646 * allow roaming to other networks
3649 wpa_s->reassociate = 1;
3650 wpa_supplicant_connect(wpa_s, bss, ssid);
3653 #endif /* CONFIG_NO_SCAN_PROCESSING */
3658 static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd)
3660 unsigned int timeout = atoi(cmd);
3661 enum p2p_discovery_type type = P2P_FIND_START_WITH_FULL;
3662 u8 dev_id[ETH_ALEN], *_dev_id = NULL;
3663 u8 dev_type[WPS_DEV_TYPE_LEN], *_dev_type = NULL;
3665 unsigned int search_delay;
3667 if (os_strstr(cmd, "type=social"))
3668 type = P2P_FIND_ONLY_SOCIAL;
3669 else if (os_strstr(cmd, "type=progressive"))
3670 type = P2P_FIND_PROGRESSIVE;
3672 pos = os_strstr(cmd, "dev_id=");
3675 if (hwaddr_aton(pos, dev_id))
3680 pos = os_strstr(cmd, "dev_type=");
3683 if (wps_dev_type_str2bin(pos, dev_type) < 0)
3685 _dev_type = dev_type;
3688 pos = os_strstr(cmd, "delay=");
3691 search_delay = atoi(pos);
3693 search_delay = wpas_p2p_search_delay(wpa_s);
3695 return wpas_p2p_find(wpa_s, timeout, type, _dev_type != NULL, _dev_type,
3696 _dev_id, search_delay);
3700 static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd,
3701 char *buf, size_t buflen)
3706 enum p2p_wps_method wps_method;
3709 int persistent_group, persistent_id = -1;
3718 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad]
3719 * [persistent|persistent=<network id>]
3720 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
3723 if (hwaddr_aton(cmd, addr))
3731 persistent_group = os_strstr(pos, " persistent") != NULL;
3732 pos2 = os_strstr(pos, " persistent=");
3734 struct wpa_ssid *ssid;
3735 persistent_id = atoi(pos2 + 12);
3736 ssid = wpa_config_get_network(wpa_s->conf, persistent_id);
3737 if (ssid == NULL || ssid->disabled != 2 ||
3738 ssid->mode != WPAS_MODE_P2P_GO) {
3739 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3740 "SSID id=%d for persistent P2P group (GO)",
3745 join = os_strstr(pos, " join") != NULL;
3746 auth = os_strstr(pos, " auth") != NULL;
3747 automatic = os_strstr(pos, " auto") != NULL;
3748 pd = os_strstr(pos, " provdisc") != NULL;
3749 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
3750 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
3753 pos2 = os_strstr(pos, " go_intent=");
3756 go_intent = atoi(pos2);
3757 if (go_intent < 0 || go_intent > 15)
3761 pos2 = os_strstr(pos, " freq=");
3769 if (os_strncmp(pos, "pin", 3) == 0) {
3770 /* Request random PIN (to be displayed) and enable the PIN */
3771 wps_method = WPS_PIN_DISPLAY;
3772 } else if (os_strncmp(pos, "pbc", 3) == 0) {
3773 wps_method = WPS_PBC;
3776 pos = os_strchr(pin, ' ');
3777 wps_method = WPS_PIN_KEYPAD;
3780 if (os_strncmp(pos, "display", 7) == 0)
3781 wps_method = WPS_PIN_DISPLAY;
3783 if (!wps_pin_str_valid(pin)) {
3784 os_memcpy(buf, "FAIL-INVALID-PIN\n", 17);
3789 new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method,
3790 persistent_group, automatic, join,
3791 auth, go_intent, freq, persistent_id, pd,
3793 if (new_pin == -2) {
3794 os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
3797 if (new_pin == -3) {
3798 os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
3803 if (wps_method == WPS_PIN_DISPLAY && pin == NULL) {
3804 ret = os_snprintf(buf, buflen, "%08d", new_pin);
3805 if (ret < 0 || (size_t) ret >= buflen)
3810 os_memcpy(buf, "OK\n", 3);
3815 static int p2p_ctrl_listen(struct wpa_supplicant *wpa_s, char *cmd)
3817 unsigned int timeout = atoi(cmd);
3818 return wpas_p2p_listen(wpa_s, timeout);
3822 static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd)
3826 enum wpas_p2p_prov_disc_use use = WPAS_P2P_PD_FOR_GO_NEG;
3828 /* <addr> <config method> [join|auto] */
3830 if (hwaddr_aton(cmd, addr))
3838 if (os_strstr(pos, " join") != NULL)
3839 use = WPAS_P2P_PD_FOR_JOIN;
3840 else if (os_strstr(pos, " auto") != NULL)
3841 use = WPAS_P2P_PD_AUTO;
3843 return wpas_p2p_prov_disc(wpa_s, addr, pos, use);
3847 static int p2p_get_passphrase(struct wpa_supplicant *wpa_s, char *buf,
3850 struct wpa_ssid *ssid = wpa_s->current_ssid;
3852 if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO ||
3853 ssid->passphrase == NULL)
3856 os_strlcpy(buf, ssid->passphrase, buflen);
3857 return os_strlen(buf);
3861 static int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd,
3862 char *buf, size_t buflen)
3866 u8 dst_buf[ETH_ALEN], *dst;
3867 struct wpabuf *tlvs;
3871 if (hwaddr_aton(cmd, dst_buf))
3874 if (dst[0] == 0 && dst[1] == 0 && dst[2] == 0 &&
3875 dst[3] == 0 && dst[4] == 0 && dst[5] == 0)
3882 if (os_strncmp(pos, "upnp ", 5) == 0) {
3885 if (hexstr2bin(pos, &version, 1) < 0)
3891 ref = wpas_p2p_sd_request_upnp(wpa_s, dst, version, pos);
3892 #ifdef CONFIG_WIFI_DISPLAY
3893 } else if (os_strncmp(pos, "wifi-display ", 13) == 0) {
3894 ref = wpas_p2p_sd_request_wifi_display(wpa_s, dst, pos + 13);
3895 #endif /* CONFIG_WIFI_DISPLAY */
3897 len = os_strlen(pos);
3901 tlvs = wpabuf_alloc(len);
3904 if (hexstr2bin(pos, wpabuf_put(tlvs, len), len) < 0) {
3909 ref = wpas_p2p_sd_request(wpa_s, dst, tlvs);
3914 res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref);
3915 if (res < 0 || (unsigned) res >= buflen)
3921 static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s,
3924 long long unsigned val;
3926 if (sscanf(cmd, "%llx", &val) != 1)
3929 return wpas_p2p_sd_cancel_request(wpa_s, req);
3933 static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant *wpa_s, char *cmd)
3938 struct wpabuf *resp_tlvs;
3942 pos = os_strchr(cmd, ' ');
3950 if (hwaddr_aton(pos, dst))
3957 pos2 = os_strchr(pos, ' ');
3961 dialog_token = atoi(pos);
3963 len = os_strlen(pos2);
3967 resp_tlvs = wpabuf_alloc(len);
3968 if (resp_tlvs == NULL)
3970 if (hexstr2bin(pos2, wpabuf_put(resp_tlvs, len), len) < 0) {
3971 wpabuf_free(resp_tlvs);
3975 wpas_p2p_sd_response(wpa_s, freq, dst, dialog_token, resp_tlvs);
3976 wpabuf_free(resp_tlvs);
3981 static int p2p_ctrl_serv_disc_external(struct wpa_supplicant *wpa_s,
3984 if (os_strcmp(cmd, "0") && os_strcmp(cmd, "1"))
3986 wpa_s->p2p_sd_over_ctrl_iface = atoi(cmd);
3991 static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant *wpa_s,
3996 struct wpabuf *query, *resp;
3998 pos = os_strchr(cmd, ' ');
4003 len = os_strlen(cmd);
4007 query = wpabuf_alloc(len);
4010 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
4015 len = os_strlen(pos);
4021 resp = wpabuf_alloc(len);
4026 if (hexstr2bin(pos, wpabuf_put(resp, len), len) < 0) {
4032 if (wpas_p2p_service_add_bonjour(wpa_s, query, resp) < 0) {
4041 static int p2p_ctrl_service_add_upnp(struct wpa_supplicant *wpa_s, char *cmd)
4046 pos = os_strchr(cmd, ' ');
4051 if (hexstr2bin(cmd, &version, 1) < 0)
4054 return wpas_p2p_service_add_upnp(wpa_s, version, pos);
4058 static int p2p_ctrl_service_add(struct wpa_supplicant *wpa_s, char *cmd)
4062 pos = os_strchr(cmd, ' ');
4067 if (os_strcmp(cmd, "bonjour") == 0)
4068 return p2p_ctrl_service_add_bonjour(wpa_s, pos);
4069 if (os_strcmp(cmd, "upnp") == 0)
4070 return p2p_ctrl_service_add_upnp(wpa_s, pos);
4071 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
4076 static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant *wpa_s,
4080 struct wpabuf *query;
4083 len = os_strlen(cmd);
4087 query = wpabuf_alloc(len);
4090 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
4095 ret = wpas_p2p_service_del_bonjour(wpa_s, query);
4101 static int p2p_ctrl_service_del_upnp(struct wpa_supplicant *wpa_s, char *cmd)
4106 pos = os_strchr(cmd, ' ');
4111 if (hexstr2bin(cmd, &version, 1) < 0)
4114 return wpas_p2p_service_del_upnp(wpa_s, version, pos);
4118 static int p2p_ctrl_service_del(struct wpa_supplicant *wpa_s, char *cmd)
4122 pos = os_strchr(cmd, ' ');
4127 if (os_strcmp(cmd, "bonjour") == 0)
4128 return p2p_ctrl_service_del_bonjour(wpa_s, pos);
4129 if (os_strcmp(cmd, "upnp") == 0)
4130 return p2p_ctrl_service_del_upnp(wpa_s, pos);
4131 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
4136 static int p2p_ctrl_reject(struct wpa_supplicant *wpa_s, char *cmd)
4142 if (hwaddr_aton(cmd, addr))
4145 return wpas_p2p_reject(wpa_s, addr);
4149 static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd)
4153 struct wpa_ssid *ssid;
4154 u8 *_peer = NULL, peer[ETH_ALEN];
4155 int freq = 0, pref_freq = 0;
4159 pos = os_strstr(cmd, " peer=");
4162 if (hwaddr_aton(pos, peer))
4166 ssid = wpa_config_get_network(wpa_s->conf, id);
4167 if (ssid == NULL || ssid->disabled != 2) {
4168 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
4169 "for persistent P2P group",
4174 pos = os_strstr(cmd, " freq=");
4182 pos = os_strstr(cmd, " pref=");
4185 pref_freq = atoi(pos);
4190 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
4191 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
4194 return wpas_p2p_invite(wpa_s, _peer, ssid, NULL, freq, ht40, vht,
4199 static int p2p_ctrl_invite_group(struct wpa_supplicant *wpa_s, char *cmd)
4202 u8 peer[ETH_ALEN], go_dev_addr[ETH_ALEN], *go_dev = NULL;
4204 pos = os_strstr(cmd, " peer=");
4210 if (hwaddr_aton(pos, peer)) {
4211 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", pos);
4215 pos = os_strstr(pos, " go_dev_addr=");
4218 if (hwaddr_aton(pos, go_dev_addr)) {
4219 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'",
4223 go_dev = go_dev_addr;
4226 return wpas_p2p_invite_group(wpa_s, cmd, peer, go_dev);
4230 static int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd)
4232 if (os_strncmp(cmd, "persistent=", 11) == 0)
4233 return p2p_ctrl_invite_persistent(wpa_s, cmd + 11);
4234 if (os_strncmp(cmd, "group=", 6) == 0)
4235 return p2p_ctrl_invite_group(wpa_s, cmd + 6);
4241 static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s,
4242 char *cmd, int freq, int ht40,
4246 struct wpa_ssid *ssid;
4249 ssid = wpa_config_get_network(wpa_s->conf, id);
4250 if (ssid == NULL || ssid->disabled != 2) {
4251 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
4252 "for persistent P2P group",
4257 return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq, ht40, vht,
4262 static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd)
4264 int freq = 0, ht40, vht;
4267 pos = os_strstr(cmd, "freq=");
4269 freq = atoi(pos + 5);
4271 vht = (os_strstr(cmd, "vht") != NULL) || wpa_s->conf->p2p_go_vht;
4272 ht40 = (os_strstr(cmd, "ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
4275 if (os_strncmp(cmd, "persistent=", 11) == 0)
4276 return p2p_ctrl_group_add_persistent(wpa_s, cmd + 11, freq,
4278 if (os_strcmp(cmd, "persistent") == 0 ||
4279 os_strncmp(cmd, "persistent ", 11) == 0)
4280 return wpas_p2p_group_add(wpa_s, 1, freq, ht40, vht);
4281 if (os_strncmp(cmd, "freq=", 5) == 0)
4282 return wpas_p2p_group_add(wpa_s, 0, freq, ht40, vht);
4284 return wpas_p2p_group_add(wpa_s, 0, freq, ht40, vht);
4286 wpa_printf(MSG_DEBUG, "CTRL: Invalid P2P_GROUP_ADD parameters '%s'",
4292 static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd,
4293 char *buf, size_t buflen)
4295 u8 addr[ETH_ALEN], *addr_ptr;
4297 const struct p2p_peer_info *info;
4299 char devtype[WPS_DEV_TYPE_BUFSIZE];
4300 struct wpa_ssid *ssid;
4303 if (!wpa_s->global->p2p)
4306 if (os_strcmp(cmd, "FIRST") == 0) {
4309 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
4310 if (hwaddr_aton(cmd + 5, addr) < 0)
4315 if (hwaddr_aton(cmd, addr) < 0)
4321 info = p2p_get_peer_info(wpa_s->global->p2p, addr_ptr, next);
4328 res = os_snprintf(pos, end - pos, MACSTR "\n"
4334 "serial_number=%s\n"
4335 "config_methods=0x%x\n"
4337 "group_capab=0x%x\n"
4339 MAC2STR(info->p2p_device_addr),
4340 wps_dev_type_bin2str(info->pri_dev_type,
4341 devtype, sizeof(devtype)),
4346 info->serial_number,
4347 info->config_methods,
4351 if (res < 0 || res >= end - pos)
4355 for (i = 0; i < info->wps_sec_dev_type_list_len / WPS_DEV_TYPE_LEN; i++)
4358 t = &info->wps_sec_dev_type_list[i * WPS_DEV_TYPE_LEN];
4359 res = os_snprintf(pos, end - pos, "sec_dev_type=%s\n",
4360 wps_dev_type_bin2str(t, devtype,
4362 if (res < 0 || res >= end - pos)
4367 ssid = wpas_p2p_get_persistent(wpa_s, info->p2p_device_addr, NULL, 0);
4369 res = os_snprintf(pos, end - pos, "persistent=%d\n", ssid->id);
4370 if (res < 0 || res >= end - pos)
4375 res = p2p_get_peer_info_txt(info, pos, end - pos);
4384 static int p2p_ctrl_disallow_freq(struct wpa_supplicant *wpa_s,
4389 if (wpa_s->global->p2p == NULL)
4392 if (freq_range_list_parse(&wpa_s->global->p2p_disallow_freq, param) < 0)
4395 for (i = 0; i < wpa_s->global->p2p_disallow_freq.num; i++) {
4396 struct wpa_freq_range *freq;
4397 freq = &wpa_s->global->p2p_disallow_freq.range[i];
4398 wpa_printf(MSG_DEBUG, "P2P: Disallowed frequency range %u-%u",
4399 freq->min, freq->max);
4402 wpas_p2p_update_channel_list(wpa_s);
4407 static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd)
4411 if (wpa_s->global->p2p == NULL)
4414 param = os_strchr(cmd, ' ');
4419 if (os_strcmp(cmd, "discoverability") == 0) {
4420 p2p_set_client_discoverability(wpa_s->global->p2p,
4425 if (os_strcmp(cmd, "managed") == 0) {
4426 p2p_set_managed_oper(wpa_s->global->p2p, atoi(param));
4430 if (os_strcmp(cmd, "listen_channel") == 0) {
4431 return p2p_set_listen_channel(wpa_s->global->p2p, 81,
4435 if (os_strcmp(cmd, "ssid_postfix") == 0) {
4436 return p2p_set_ssid_postfix(wpa_s->global->p2p, (u8 *) param,
4440 if (os_strcmp(cmd, "noa") == 0) {
4442 int count, start, duration;
4443 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
4444 count = atoi(param);
4445 pos = os_strchr(param, ',');
4450 pos = os_strchr(pos, ',');
4454 duration = atoi(pos);
4455 if (count < 0 || count > 255 || start < 0 || duration < 0)
4457 if (count == 0 && duration > 0)
4459 wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
4460 "start=%d duration=%d", count, start, duration);
4461 return wpas_p2p_set_noa(wpa_s, count, start, duration);
4464 if (os_strcmp(cmd, "ps") == 0)
4465 return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1);
4467 if (os_strcmp(cmd, "oppps") == 0)
4468 return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1);
4470 if (os_strcmp(cmd, "ctwindow") == 0)
4471 return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param));
4473 if (os_strcmp(cmd, "disabled") == 0) {
4474 wpa_s->global->p2p_disabled = atoi(param);
4475 wpa_printf(MSG_DEBUG, "P2P functionality %s",
4476 wpa_s->global->p2p_disabled ?
4477 "disabled" : "enabled");
4478 if (wpa_s->global->p2p_disabled) {
4479 wpas_p2p_stop_find(wpa_s);
4480 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
4481 p2p_flush(wpa_s->global->p2p);
4486 if (os_strcmp(cmd, "conc_pref") == 0) {
4487 if (os_strcmp(param, "sta") == 0)
4488 wpa_s->global->conc_pref = WPA_CONC_PREF_STA;
4489 else if (os_strcmp(param, "p2p") == 0)
4490 wpa_s->global->conc_pref = WPA_CONC_PREF_P2P;
4492 wpa_printf(MSG_INFO, "Invalid conc_pref value");
4495 wpa_printf(MSG_DEBUG, "Single channel concurrency preference: "
4500 if (os_strcmp(cmd, "force_long_sd") == 0) {
4501 wpa_s->force_long_sd = atoi(param);
4505 if (os_strcmp(cmd, "peer_filter") == 0) {
4507 if (hwaddr_aton(param, addr))
4509 p2p_set_peer_filter(wpa_s->global->p2p, addr);
4513 if (os_strcmp(cmd, "cross_connect") == 0)
4514 return wpas_p2p_set_cross_connect(wpa_s, atoi(param));
4516 if (os_strcmp(cmd, "go_apsd") == 0) {
4517 if (os_strcmp(param, "disable") == 0)
4518 wpa_s->set_ap_uapsd = 0;
4520 wpa_s->set_ap_uapsd = 1;
4521 wpa_s->ap_uapsd = atoi(param);
4526 if (os_strcmp(cmd, "client_apsd") == 0) {
4527 if (os_strcmp(param, "disable") == 0)
4528 wpa_s->set_sta_uapsd = 0;
4532 /* format: BE,BK,VI,VO;max SP Length */
4534 pos = os_strchr(param, ',');
4539 pos = os_strchr(pos, ',');
4544 pos = os_strchr(pos, ',');
4549 /* ignore max SP Length for now */
4551 wpa_s->set_sta_uapsd = 1;
4552 wpa_s->sta_uapsd = 0;
4554 wpa_s->sta_uapsd |= BIT(0);
4556 wpa_s->sta_uapsd |= BIT(1);
4558 wpa_s->sta_uapsd |= BIT(2);
4560 wpa_s->sta_uapsd |= BIT(3);
4565 if (os_strcmp(cmd, "disallow_freq") == 0)
4566 return p2p_ctrl_disallow_freq(wpa_s, param);
4568 if (os_strcmp(cmd, "disc_int") == 0) {
4569 int min_disc_int, max_disc_int, max_disc_tu;
4574 min_disc_int = atoi(pos);
4575 pos = os_strchr(pos, ' ');
4580 max_disc_int = atoi(pos);
4581 pos = os_strchr(pos, ' ');
4586 max_disc_tu = atoi(pos);
4588 return p2p_set_disc_int(wpa_s->global->p2p, min_disc_int,
4589 max_disc_int, max_disc_tu);
4592 if (os_strcmp(cmd, "per_sta_psk") == 0) {
4593 wpa_s->global->p2p_per_sta_psk = !!atoi(param);
4597 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
4604 static void p2p_ctrl_flush(struct wpa_supplicant *wpa_s)
4606 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
4607 wpa_s->force_long_sd = 0;
4608 if (wpa_s->global->p2p)
4609 p2p_flush(wpa_s->global->p2p);
4613 static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd)
4616 unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0;
4619 pos = os_strchr(cmd, ' ');
4625 pos2 = os_strchr(pos, ' ');
4633 pos = os_strchr(pos2, ' ');
4641 return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2);
4645 static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd)
4648 unsigned int period = 0, interval = 0;
4651 pos = os_strchr(cmd, ' ');
4656 interval = atoi(pos);
4659 return wpas_p2p_ext_listen(wpa_s, period, interval);
4663 static int p2p_ctrl_remove_client(struct wpa_supplicant *wpa_s, const char *cmd)
4670 if (os_strncmp(pos, "iface=", 6) == 0) {
4674 if (hwaddr_aton(pos, peer))
4677 wpas_p2p_remove_client(wpa_s, peer, iface_addr);
4681 #endif /* CONFIG_P2P */
4684 static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s, char *val)
4686 struct wpa_freq_range_list ranges;
4688 struct hostapd_hw_modes *mode;
4691 if (wpa_s->hw.modes == NULL)
4694 os_memset(&ranges, 0, sizeof(ranges));
4695 if (freq_range_list_parse(&ranges, val) < 0)
4698 for (i = 0; i < wpa_s->hw.num_modes; i++) {
4701 mode = &wpa_s->hw.modes[i];
4702 for (j = 0; j < mode->num_channels; j++) {
4705 if (mode->channels[j].flag & HOSTAPD_CHAN_DISABLED)
4708 freq = mode->channels[j].freq;
4709 if (!freq_range_list_includes(&ranges, freq))
4712 int_array_add_unique(&freqs, freq);
4716 os_free(ranges.range);
4721 #ifdef CONFIG_INTERWORKING
4723 static int ctrl_interworking_select(struct wpa_supplicant *wpa_s, char *param)
4731 auto_sel = os_strstr(param, "auto") != NULL;
4733 pos = os_strstr(param, "freq=");
4735 freqs = freq_range_to_channel_list(wpa_s, pos + 5);
4742 return interworking_select(wpa_s, auto_sel, freqs);
4746 static int ctrl_interworking_connect(struct wpa_supplicant *wpa_s, char *dst)
4749 struct wpa_bss *bss;
4751 if (hwaddr_aton(dst, bssid)) {
4752 wpa_printf(MSG_DEBUG, "Invalid BSSID '%s'", dst);
4756 bss = wpa_bss_get_bssid(wpa_s, bssid);
4758 wpa_printf(MSG_DEBUG, "Could not find BSS " MACSTR,
4763 return interworking_connect(wpa_s, bss);
4767 static int get_anqp(struct wpa_supplicant *wpa_s, char *dst)
4769 u8 dst_addr[ETH_ALEN];
4772 #define MAX_ANQP_INFO_ID 100
4773 u16 id[MAX_ANQP_INFO_ID];
4776 used = hwaddr_aton2(dst, dst_addr);
4780 while (num_id < MAX_ANQP_INFO_ID) {
4781 id[num_id] = atoi(pos);
4784 pos = os_strchr(pos + 1, ',');
4793 return anqp_send_req(wpa_s, dst_addr, id, num_id);
4797 static int gas_request(struct wpa_supplicant *wpa_s, char *cmd)
4799 u8 dst_addr[ETH_ALEN];
4800 struct wpabuf *advproto, *query = NULL;
4805 used = hwaddr_aton2(cmd, dst_addr);
4813 /* Advertisement Protocol ID */
4814 end = os_strchr(pos, ' ');
4818 len = os_strlen(pos);
4824 advproto = wpabuf_alloc(len);
4825 if (advproto == NULL)
4827 if (hexstr2bin(pos, wpabuf_put(advproto, len), len) < 0)
4831 /* Optional Query Request */
4836 len = os_strlen(pos);
4843 query = wpabuf_alloc(len);
4846 if (hexstr2bin(pos, wpabuf_put(query, len), len) < 0)
4851 ret = gas_send_request(wpa_s, dst_addr, advproto, query);
4854 wpabuf_free(advproto);
4861 static int gas_response_get(struct wpa_supplicant *wpa_s, char *cmd, char *buf,
4868 size_t resp_len, start, requested_len;
4869 struct wpabuf *resp;
4872 used = hwaddr_aton2(cmd, addr);
4879 dialog_token = atoi(pos);
4881 if (wpa_s->last_gas_resp &&
4882 os_memcmp(addr, wpa_s->last_gas_addr, ETH_ALEN) == 0 &&
4883 dialog_token == wpa_s->last_gas_dialog_token)
4884 resp = wpa_s->last_gas_resp;
4885 else if (wpa_s->prev_gas_resp &&
4886 os_memcmp(addr, wpa_s->prev_gas_addr, ETH_ALEN) == 0 &&
4887 dialog_token == wpa_s->prev_gas_dialog_token)
4888 resp = wpa_s->prev_gas_resp;
4892 resp_len = wpabuf_len(resp);
4894 requested_len = resp_len;
4896 pos = os_strchr(pos, ' ');
4899 if (start > resp_len)
4900 return os_snprintf(buf, buflen, "FAIL-Invalid range");
4901 pos = os_strchr(pos, ',');
4905 requested_len = atoi(pos);
4906 if (start + requested_len > resp_len)
4907 return os_snprintf(buf, buflen, "FAIL-Invalid range");
4910 if (requested_len * 2 + 1 > buflen)
4911 return os_snprintf(buf, buflen, "FAIL-Too long response");
4913 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(resp) + start,
4916 if (start + requested_len == resp_len) {
4918 * Free memory by dropping the response after it has been
4921 if (resp == wpa_s->prev_gas_resp) {
4922 wpabuf_free(wpa_s->prev_gas_resp);
4923 wpa_s->prev_gas_resp = NULL;
4925 wpabuf_free(wpa_s->last_gas_resp);
4926 wpa_s->last_gas_resp = NULL;
4932 #endif /* CONFIG_INTERWORKING */
4937 static int get_hs20_anqp(struct wpa_supplicant *wpa_s, char *dst)
4939 u8 dst_addr[ETH_ALEN];
4944 used = hwaddr_aton2(dst, dst_addr);
4949 int num = atoi(pos);
4950 if (num <= 0 || num > 31)
4952 subtypes |= BIT(num);
4953 pos = os_strchr(pos + 1, ',');
4962 return hs20_anqp_send_req(wpa_s, dst_addr, subtypes, NULL, 0);
4966 static int hs20_nai_home_realm_list(struct wpa_supplicant *wpa_s,
4967 const u8 *addr, const char *realm)
4973 rlen = os_strlen(realm);
4975 buf = os_malloc(len);
4978 buf[0] = 1; /* NAI Home Realm Count */
4979 buf[1] = 0; /* Formatted in accordance with RFC 4282 */
4981 os_memcpy(buf + 3, realm, rlen);
4983 ret = hs20_anqp_send_req(wpa_s, addr,
4984 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
4993 static int hs20_get_nai_home_realm_list(struct wpa_supplicant *wpa_s,
4996 struct wpa_cred *cred = wpa_s->conf->cred;
4997 u8 dst_addr[ETH_ALEN];
5003 used = hwaddr_aton2(dst, dst_addr);
5007 while (dst[used] == ' ')
5009 if (os_strncmp(dst + used, "realm=", 6) == 0)
5010 return hs20_nai_home_realm_list(wpa_s, dst_addr,
5013 len = os_strlen(dst + used);
5015 if (len == 0 && cred && cred->realm)
5016 return hs20_nai_home_realm_list(wpa_s, dst_addr, cred->realm);
5021 buf = os_malloc(len);
5024 if (hexstr2bin(dst + used, buf, len) < 0) {
5029 ret = hs20_anqp_send_req(wpa_s, dst_addr,
5030 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
5037 #endif /* CONFIG_HS20 */
5040 static int wpa_supplicant_ctrl_iface_sta_autoconnect(
5041 struct wpa_supplicant *wpa_s, char *cmd)
5043 wpa_s->auto_reconnect_disabled = atoi(cmd) == 0 ? 1 : 0;
5048 #ifdef CONFIG_AUTOSCAN
5050 static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant *wpa_s,
5053 enum wpa_states state = wpa_s->wpa_state;
5054 char *new_params = NULL;
5056 if (os_strlen(cmd) > 0) {
5057 new_params = os_strdup(cmd);
5058 if (new_params == NULL)
5062 os_free(wpa_s->conf->autoscan);
5063 wpa_s->conf->autoscan = new_params;
5065 if (wpa_s->conf->autoscan == NULL)
5066 autoscan_deinit(wpa_s);
5067 else if (state == WPA_DISCONNECTED || state == WPA_INACTIVE)
5068 autoscan_init(wpa_s, 1);
5069 else if (state == WPA_SCANNING)
5070 wpa_supplicant_reinit_autoscan(wpa_s);
5075 #endif /* CONFIG_AUTOSCAN */
5080 static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant *wpa_s, char *cmd)
5086 struct wpabuf *tfs_req = NULL;
5088 if (os_strncmp(cmd, "enter", 5) == 0)
5090 else if (os_strncmp(cmd, "exit", 4) == 0)
5095 pos = os_strstr(cmd, " interval=");
5097 intval = atoi(pos + 10);
5099 pos = os_strstr(cmd, " tfs_req=");
5104 end = os_strchr(pos, ' ');
5108 len = os_strlen(pos);
5112 tfs_req = wpabuf_alloc(len);
5113 if (tfs_req == NULL)
5115 if (hexstr2bin(pos, wpabuf_put(tfs_req, len), len) < 0) {
5116 wpabuf_free(tfs_req);
5121 ret = ieee802_11_send_wnmsleep_req(wpa_s, enter ? WNM_SLEEP_MODE_ENTER :
5122 WNM_SLEEP_MODE_EXIT, intval,
5124 wpabuf_free(tfs_req);
5130 static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant *wpa_s, char *cmd)
5134 query_reason = atoi(cmd);
5136 wpa_printf(MSG_DEBUG, "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d",
5139 return wnm_send_bss_transition_mgmt_query(wpa_s, query_reason);
5142 #endif /* CONFIG_WNM */
5145 /* Get string representation of channel width */
5146 static const char * channel_width_name(enum chan_width width)
5149 case CHAN_WIDTH_20_NOHT:
5150 return "20 MHz (no HT)";
5157 case CHAN_WIDTH_80P80:
5159 case CHAN_WIDTH_160:
5167 static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf,
5170 struct wpa_signal_info si;
5174 ret = wpa_drv_signal_poll(wpa_s, &si);
5181 ret = os_snprintf(pos, end - pos, "RSSI=%d\nLINKSPEED=%d\n"
5182 "NOISE=%d\nFREQUENCY=%u\n",
5183 si.current_signal, si.current_txrate / 1000,
5184 si.current_noise, si.frequency);
5185 if (ret < 0 || ret > end - pos)
5189 if (si.chanwidth != CHAN_WIDTH_UNKNOWN) {
5190 ret = os_snprintf(pos, end - pos, "WIDTH=%s\n",
5191 channel_width_name(si.chanwidth));
5192 if (ret < 0 || ret > end - pos)
5197 if (si.center_frq1 > 0 && si.center_frq2 > 0) {
5198 ret = os_snprintf(pos, end - pos,
5199 "CENTER_FRQ1=%d\nCENTER_FRQ2=%d\n",
5200 si.center_frq1, si.center_frq2);
5201 if (ret < 0 || ret > end - pos)
5206 if (si.avg_signal) {
5207 ret = os_snprintf(pos, end - pos,
5208 "AVG_RSSI=%d\n", si.avg_signal);
5209 if (ret < 0 || ret >= end - pos)
5218 static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant *wpa_s, char *buf,
5221 struct hostap_sta_driver_data sta;
5224 ret = wpa_drv_pktcnt_poll(wpa_s, &sta);
5228 ret = os_snprintf(buf, buflen, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
5229 sta.tx_packets, sta.tx_retry_failed, sta.rx_packets);
5230 if (ret < 0 || (size_t) ret > buflen)
5237 static int wpa_supplicant_driver_cmd(struct wpa_supplicant *wpa_s, char *cmd,
5238 char *buf, size_t buflen)
5242 ret = wpa_drv_driver_cmd(wpa_s, cmd, buf, buflen);
5244 if (os_strncasecmp(cmd, "COUNTRY", 7) == 0) {
5245 struct p2p_data *p2p = wpa_s->global->p2p;
5248 country[0] = cmd[8];
5249 country[1] = cmd[9];
5251 p2p_set_country(p2p, country);
5254 ret = os_snprintf(buf, buflen, "%s\n", "OK");
5258 #endif /* ANDROID */
5261 static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s)
5263 wpa_dbg(wpa_s, MSG_DEBUG, "Flush all wpa_supplicant state");
5266 wpas_p2p_stop_find(wpa_s);
5267 p2p_ctrl_flush(wpa_s);
5268 wpas_p2p_group_remove(wpa_s, "*");
5269 wpas_p2p_service_flush(wpa_s);
5270 wpa_s->global->p2p_disabled = 0;
5271 wpa_s->global->p2p_per_sta_psk = 0;
5272 wpa_s->conf->num_sec_device_types = 0;
5273 #endif /* CONFIG_P2P */
5275 #ifdef CONFIG_WPS_TESTING
5276 wps_version_number = 0x20;
5277 wps_testing_dummy_cred = 0;
5278 #endif /* CONFIG_WPS_TESTING */
5280 wpa_s->wps_fragment_size = 0;
5281 wpas_wps_cancel(wpa_s);
5282 #endif /* CONFIG_WPS */
5283 wpa_s->after_wps = 0;
5284 wpa_s->known_wps_freq = 0;
5287 #ifdef CONFIG_TDLS_TESTING
5288 extern unsigned int tdls_testing;
5290 #endif /* CONFIG_TDLS_TESTING */
5291 wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL);
5292 wpa_tdls_enable(wpa_s->wpa, 1);
5293 #endif /* CONFIG_TDLS */
5295 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, wpa_s, NULL);
5296 wpa_supplicant_stop_countermeasures(wpa_s, NULL);
5298 wpa_s->no_keep_alive = 0;
5300 os_free(wpa_s->disallow_aps_bssid);
5301 wpa_s->disallow_aps_bssid = NULL;
5302 wpa_s->disallow_aps_bssid_count = 0;
5303 os_free(wpa_s->disallow_aps_ssid);
5304 wpa_s->disallow_aps_ssid = NULL;
5305 wpa_s->disallow_aps_ssid_count = 0;
5307 wpa_s->set_sta_uapsd = 0;
5308 wpa_s->sta_uapsd = 0;
5310 wpa_drv_radio_disable(wpa_s, 0);
5312 wpa_bss_flush(wpa_s);
5313 wpa_blacklist_clear(wpa_s);
5314 wpa_s->extra_blacklist_count = 0;
5315 wpa_supplicant_ctrl_iface_remove_network(wpa_s, "all");
5316 wpa_supplicant_ctrl_iface_remove_cred(wpa_s, "all");
5317 wpa_config_flush_blobs(wpa_s->conf);
5319 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, 43200);
5320 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, 70);
5321 wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, 60);
5322 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
5324 radio_remove_unstarted_work(wpa_s, NULL);
5328 static int wpas_ctrl_radio_work_show(struct wpa_supplicant *wpa_s,
5329 char *buf, size_t buflen)
5331 struct wpa_radio_work *work;
5333 struct os_reltime now, diff;
5338 os_get_reltime(&now);
5340 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
5344 os_reltime_sub(&now, &work->time, &diff);
5345 ret = os_snprintf(pos, end - pos, "%s@%s:%u:%u:%ld.%06ld\n",
5346 work->type, work->wpa_s->ifname, work->freq,
5347 work->started, diff.sec, diff.usec);
5348 if (ret < 0 || ret >= end - pos)
5357 static void wpas_ctrl_radio_work_timeout(void *eloop_ctx, void *timeout_ctx)
5359 struct wpa_radio_work *work = eloop_ctx;
5360 struct wpa_external_work *ework = work->ctx;
5362 wpa_dbg(work->wpa_s, MSG_DEBUG,
5363 "Timing out external radio work %u (%s)",
5364 ework->id, work->type);
5365 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_TIMEOUT "%u", ework->id);
5367 radio_work_done(work);
5371 static void wpas_ctrl_radio_work_cb(struct wpa_radio_work *work, int deinit)
5373 struct wpa_external_work *ework = work->ctx;
5380 wpa_dbg(work->wpa_s, MSG_DEBUG, "Starting external radio work %u (%s)",
5381 ework->id, ework->type);
5382 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_START "%u", ework->id);
5383 if (!ework->timeout)
5384 ework->timeout = 10;
5385 eloop_register_timeout(ework->timeout, 0, wpas_ctrl_radio_work_timeout,
5390 static int wpas_ctrl_radio_work_add(struct wpa_supplicant *wpa_s, char *cmd,
5391 char *buf, size_t buflen)
5393 struct wpa_external_work *ework;
5397 unsigned int freq = 0;
5399 /* format: <name> [freq=<MHz>] [timeout=<seconds>] */
5401 ework = os_zalloc(sizeof(*ework));
5405 pos = os_strchr(cmd, ' ');
5407 type_len = pos - cmd;
5410 pos2 = os_strstr(pos, "freq=");
5412 freq = atoi(pos2 + 5);
5414 pos2 = os_strstr(pos, "timeout=");
5416 ework->timeout = atoi(pos2 + 8);
5418 type_len = os_strlen(cmd);
5420 if (4 + type_len >= sizeof(ework->type))
5421 type_len = sizeof(ework->type) - 4 - 1;
5422 os_strlcpy(ework->type, "ext:", sizeof(ework->type));
5423 os_memcpy(ework->type + 4, cmd, type_len);
5424 ework->type[4 + type_len] = '\0';
5426 wpa_s->ext_work_id++;
5427 if (wpa_s->ext_work_id == 0)
5428 wpa_s->ext_work_id++;
5429 ework->id = wpa_s->ext_work_id;
5431 if (radio_add_work(wpa_s, freq, ework->type, 0, wpas_ctrl_radio_work_cb,
5437 ret = os_snprintf(buf, buflen, "%u", ework->id);
5438 if (ret < 0 || (size_t) ret >= buflen)
5444 static int wpas_ctrl_radio_work_done(struct wpa_supplicant *wpa_s, char *cmd)
5446 struct wpa_radio_work *work;
5447 unsigned int id = atoi(cmd);
5449 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
5451 struct wpa_external_work *ework;
5453 if (os_strncmp(work->type, "ext:", 4) != 0)
5456 if (id && ework->id != id)
5458 wpa_dbg(wpa_s, MSG_DEBUG,
5459 "Completed external radio work %u (%s)",
5460 ework->id, ework->type);
5461 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, work, NULL);
5463 radio_work_done(work);
5464 return 3; /* "OK\n" */
5471 static int wpas_ctrl_radio_work(struct wpa_supplicant *wpa_s, char *cmd,
5472 char *buf, size_t buflen)
5474 if (os_strcmp(cmd, "show") == 0)
5475 return wpas_ctrl_radio_work_show(wpa_s, buf, buflen);
5476 if (os_strncmp(cmd, "add ", 4) == 0)
5477 return wpas_ctrl_radio_work_add(wpa_s, cmd + 4, buf, buflen);
5478 if (os_strncmp(cmd, "done ", 5) == 0)
5479 return wpas_ctrl_radio_work_done(wpa_s, cmd + 4);
5484 void wpas_ctrl_radio_work_flush(struct wpa_supplicant *wpa_s)
5486 struct wpa_radio_work *work, *tmp;
5488 if (!wpa_s || !wpa_s->radio)
5491 dl_list_for_each_safe(work, tmp, &wpa_s->radio->work,
5492 struct wpa_radio_work, list) {
5493 struct wpa_external_work *ework;
5495 if (os_strncmp(work->type, "ext:", 4) != 0)
5498 wpa_dbg(wpa_s, MSG_DEBUG,
5499 "Flushing %sexternal radio work %u (%s)",
5500 work->started ? " started" : "", ework->id,
5503 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
5506 radio_work_done(work);
5511 static void wpas_ctrl_eapol_response(void *eloop_ctx, void *timeout_ctx)
5513 struct wpa_supplicant *wpa_s = eloop_ctx;
5514 eapol_sm_notify_ctrl_response(wpa_s->eapol);
5518 static int set_scan_freqs(struct wpa_supplicant *wpa_s, char *val)
5522 freqs = freq_range_to_channel_list(wpa_s, val);
5526 os_free(wpa_s->manual_scan_freqs);
5527 wpa_s->manual_scan_freqs = freqs;
5533 static void wpas_ctrl_scan(struct wpa_supplicant *wpa_s, char *params,
5534 char *reply, int reply_size, int *reply_len)
5538 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
5543 wpa_s->manual_scan_passive = 0;
5544 wpa_s->manual_scan_use_id = 0;
5545 wpa_s->manual_scan_only_new = 0;
5548 if (os_strncasecmp(params, "TYPE=ONLY", 9) == 0)
5549 wpa_s->scan_res_handler = scan_only_handler;
5551 pos = os_strstr(params, "freq=");
5552 if (pos && set_scan_freqs(wpa_s, pos + 5) < 0) {
5557 pos = os_strstr(params, "passive=");
5559 wpa_s->manual_scan_passive = !!atoi(pos + 8);
5561 pos = os_strstr(params, "use_id=");
5563 wpa_s->manual_scan_use_id = atoi(pos + 7);
5565 pos = os_strstr(params, "only_new=1");
5567 wpa_s->manual_scan_only_new = 1;
5569 os_free(wpa_s->manual_scan_freqs);
5570 wpa_s->manual_scan_freqs = NULL;
5571 if (wpa_s->scan_res_handler == scan_only_handler)
5572 wpa_s->scan_res_handler = NULL;
5575 if (!wpa_s->sched_scanning && !wpa_s->scanning &&
5576 ((wpa_s->wpa_state <= WPA_SCANNING) ||
5577 (wpa_s->wpa_state == WPA_COMPLETED))) {
5578 wpa_s->normal_scans = 0;
5579 wpa_s->scan_req = MANUAL_SCAN_REQ;
5580 wpa_s->after_wps = 0;
5581 wpa_s->known_wps_freq = 0;
5582 wpa_supplicant_req_scan(wpa_s, 0, 0);
5583 if (wpa_s->manual_scan_use_id) {
5584 wpa_s->manual_scan_id++;
5585 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
5586 wpa_s->manual_scan_id);
5587 *reply_len = os_snprintf(reply, reply_size, "%u\n",
5588 wpa_s->manual_scan_id);
5590 } else if (wpa_s->sched_scanning) {
5591 wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to allow requested full scan to proceed");
5592 wpa_supplicant_cancel_sched_scan(wpa_s);
5593 wpa_s->scan_req = MANUAL_SCAN_REQ;
5594 wpa_supplicant_req_scan(wpa_s, 0, 0);
5595 if (wpa_s->manual_scan_use_id) {
5596 wpa_s->manual_scan_id++;
5597 *reply_len = os_snprintf(reply, reply_size, "%u\n",
5598 wpa_s->manual_scan_id);
5599 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
5600 wpa_s->manual_scan_id);
5603 wpa_printf(MSG_DEBUG, "Ongoing scan action - reject new request");
5604 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
5609 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
5610 char *buf, size_t *resp_len)
5613 const int reply_size = 4096;
5616 if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 ||
5617 os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
5618 if (wpa_debug_show_keys)
5619 wpa_dbg(wpa_s, MSG_DEBUG,
5620 "Control interface command '%s'", buf);
5622 wpa_dbg(wpa_s, MSG_DEBUG,
5623 "Control interface command '%s [REMOVED]'",
5624 os_strncmp(buf, WPA_CTRL_RSP,
5625 os_strlen(WPA_CTRL_RSP)) == 0 ?
5626 WPA_CTRL_RSP : "SET_NETWORK");
5627 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ", 16) == 0 ||
5628 os_strncmp(buf, "NFC_REPORT_HANDOVER", 19) == 0 ||
5629 os_strncmp(buf, "NFC_RX_HANDOVER_SEL", 19) == 0) {
5630 wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface",
5631 (const u8 *) buf, os_strlen(buf));
5633 int level = MSG_DEBUG;
5634 if (os_strcmp(buf, "PING") == 0)
5635 level = MSG_EXCESSIVE;
5636 wpa_dbg(wpa_s, level, "Control interface command '%s'", buf);
5639 reply = os_malloc(reply_size);
5640 if (reply == NULL) {
5645 os_memcpy(reply, "OK\n", 3);
5648 if (os_strcmp(buf, "PING") == 0) {
5649 os_memcpy(reply, "PONG\n", 5);
5651 } else if (os_strcmp(buf, "IFNAME") == 0) {
5652 reply_len = os_strlen(wpa_s->ifname);
5653 os_memcpy(reply, wpa_s->ifname, reply_len);
5654 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
5655 if (wpa_debug_reopen_file() < 0)
5657 } else if (os_strncmp(buf, "NOTE ", 5) == 0) {
5658 wpa_printf(MSG_INFO, "NOTE: %s", buf + 5);
5659 } else if (os_strcmp(buf, "MIB") == 0) {
5660 reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size);
5661 if (reply_len >= 0) {
5663 res = eapol_sm_get_mib(wpa_s->eapol, reply + reply_len,
5664 reply_size - reply_len);
5670 } else if (os_strncmp(buf, "STATUS", 6) == 0) {
5671 reply_len = wpa_supplicant_ctrl_iface_status(
5672 wpa_s, buf + 6, reply, reply_size);
5673 } else if (os_strcmp(buf, "PMKSA") == 0) {
5674 reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, reply,
5676 } else if (os_strncmp(buf, "SET ", 4) == 0) {
5677 if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4))
5679 } else if (os_strncmp(buf, "GET ", 4) == 0) {
5680 reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4,
5682 } else if (os_strcmp(buf, "LOGON") == 0) {
5683 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
5684 } else if (os_strcmp(buf, "LOGOFF") == 0) {
5685 eapol_sm_notify_logoff(wpa_s->eapol, TRUE);
5686 } else if (os_strcmp(buf, "REASSOCIATE") == 0) {
5687 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
5690 wpas_request_connection(wpa_s);
5691 } else if (os_strcmp(buf, "RECONNECT") == 0) {
5692 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
5694 else if (wpa_s->disconnected)
5695 wpas_request_connection(wpa_s);
5696 #ifdef IEEE8021X_EAPOL
5697 } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) {
5698 if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8))
5700 #endif /* IEEE8021X_EAPOL */
5701 #ifdef CONFIG_PEERKEY
5702 } else if (os_strncmp(buf, "STKSTART ", 9) == 0) {
5703 if (wpa_supplicant_ctrl_iface_stkstart(wpa_s, buf + 9))
5705 #endif /* CONFIG_PEERKEY */
5706 #ifdef CONFIG_IEEE80211R
5707 } else if (os_strncmp(buf, "FT_DS ", 6) == 0) {
5708 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6))
5710 #endif /* CONFIG_IEEE80211R */
5712 } else if (os_strcmp(buf, "WPS_PBC") == 0) {
5713 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL);
5715 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
5719 } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) {
5720 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8);
5722 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
5726 } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {
5727 reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8,
5730 } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) {
5731 reply_len = wpa_supplicant_ctrl_iface_wps_check_pin(
5732 wpa_s, buf + 14, reply, reply_size);
5733 } else if (os_strcmp(buf, "WPS_CANCEL") == 0) {
5734 if (wpas_wps_cancel(wpa_s))
5736 #ifdef CONFIG_WPS_NFC
5737 } else if (os_strcmp(buf, "WPS_NFC") == 0) {
5738 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, NULL))
5740 } else if (os_strncmp(buf, "WPS_NFC ", 8) == 0) {
5741 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, buf + 8))
5743 } else if (os_strncmp(buf, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
5744 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_config_token(
5745 wpa_s, buf + 21, reply, reply_size);
5746 } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) {
5747 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_token(
5748 wpa_s, buf + 14, reply, reply_size);
5749 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) {
5750 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s,
5753 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
5754 reply_len = wpas_ctrl_nfc_get_handover_req(
5755 wpa_s, buf + 21, reply, reply_size);
5756 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
5757 reply_len = wpas_ctrl_nfc_get_handover_sel(
5758 wpa_s, buf + 21, reply, reply_size);
5759 } else if (os_strncmp(buf, "NFC_RX_HANDOVER_REQ ", 20) == 0) {
5760 reply_len = wpas_ctrl_nfc_rx_handover_req(
5761 wpa_s, buf + 20, reply, reply_size);
5762 } else if (os_strncmp(buf, "NFC_RX_HANDOVER_SEL ", 20) == 0) {
5763 if (wpas_ctrl_nfc_rx_handover_sel(wpa_s, buf + 20))
5765 } else if (os_strncmp(buf, "NFC_REPORT_HANDOVER ", 20) == 0) {
5766 if (wpas_ctrl_nfc_report_handover(wpa_s, buf + 20))
5768 #endif /* CONFIG_WPS_NFC */
5769 } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) {
5770 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8))
5773 } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) {
5774 reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin(
5775 wpa_s, buf + 11, reply, reply_size);
5776 #endif /* CONFIG_AP */
5777 #ifdef CONFIG_WPS_ER
5778 } else if (os_strcmp(buf, "WPS_ER_START") == 0) {
5779 if (wpas_wps_er_start(wpa_s, NULL))
5781 } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) {
5782 if (wpas_wps_er_start(wpa_s, buf + 13))
5784 } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) {
5785 if (wpas_wps_er_stop(wpa_s))
5787 } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) {
5788 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11))
5790 } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) {
5791 int ret = wpas_wps_er_pbc(wpa_s, buf + 11);
5793 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
5795 } else if (ret == -3) {
5796 os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18);
5798 } else if (ret == -4) {
5799 os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20);
5803 } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) {
5804 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13))
5806 } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) {
5807 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s,
5810 } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) {
5811 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14))
5813 #ifdef CONFIG_WPS_NFC
5814 } else if (os_strncmp(buf, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
5815 reply_len = wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
5816 wpa_s, buf + 24, reply, reply_size);
5817 #endif /* CONFIG_WPS_NFC */
5818 #endif /* CONFIG_WPS_ER */
5819 #endif /* CONFIG_WPS */
5820 #ifdef CONFIG_IBSS_RSN
5821 } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) {
5822 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9))
5824 #endif /* CONFIG_IBSS_RSN */
5826 } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) {
5827 if (p2p_ctrl_find(wpa_s, buf + 9))
5829 } else if (os_strcmp(buf, "P2P_FIND") == 0) {
5830 if (p2p_ctrl_find(wpa_s, ""))
5832 } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) {
5833 wpas_p2p_stop_find(wpa_s);
5834 } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) {
5835 reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply,
5837 } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) {
5838 if (p2p_ctrl_listen(wpa_s, buf + 11))
5840 } else if (os_strcmp(buf, "P2P_LISTEN") == 0) {
5841 if (p2p_ctrl_listen(wpa_s, ""))
5843 } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) {
5844 if (wpas_p2p_group_remove(wpa_s, buf + 17))
5846 } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) {
5847 if (wpas_p2p_group_add(wpa_s, 0, 0, 0, 0))
5849 } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) {
5850 if (p2p_ctrl_group_add(wpa_s, buf + 14))
5852 } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) {
5853 if (p2p_ctrl_prov_disc(wpa_s, buf + 14))
5855 } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) {
5856 reply_len = p2p_get_passphrase(wpa_s, reply, reply_size);
5857 } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) {
5858 reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply,
5860 } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
5861 if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0)
5863 } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) {
5864 if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0)
5866 } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) {
5867 wpas_p2p_sd_service_update(wpa_s);
5868 } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
5869 if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0)
5871 } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) {
5872 wpas_p2p_service_flush(wpa_s);
5873 } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) {
5874 if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0)
5876 } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) {
5877 if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0)
5879 } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) {
5880 if (p2p_ctrl_reject(wpa_s, buf + 11) < 0)
5882 } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) {
5883 if (p2p_ctrl_invite(wpa_s, buf + 11) < 0)
5885 } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) {
5886 reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply,
5888 } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) {
5889 if (p2p_ctrl_set(wpa_s, buf + 8) < 0)
5891 } else if (os_strcmp(buf, "P2P_FLUSH") == 0) {
5892 p2p_ctrl_flush(wpa_s);
5893 } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) {
5894 if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0)
5896 } else if (os_strcmp(buf, "P2P_CANCEL") == 0) {
5897 if (wpas_p2p_cancel(wpa_s))
5899 } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) {
5900 if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0)
5902 } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) {
5903 if (p2p_ctrl_presence_req(wpa_s, "") < 0)
5905 } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) {
5906 if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0)
5908 } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) {
5909 if (p2p_ctrl_ext_listen(wpa_s, "") < 0)
5911 } else if (os_strncmp(buf, "P2P_REMOVE_CLIENT ", 18) == 0) {
5912 if (p2p_ctrl_remove_client(wpa_s, buf + 18) < 0)
5914 #endif /* CONFIG_P2P */
5915 #ifdef CONFIG_WIFI_DISPLAY
5916 } else if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0) {
5917 if (wifi_display_subelem_set(wpa_s->global, buf + 16) < 0)
5919 } else if (os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) {
5920 reply_len = wifi_display_subelem_get(wpa_s->global, buf + 16,
5922 #endif /* CONFIG_WIFI_DISPLAY */
5923 #ifdef CONFIG_INTERWORKING
5924 } else if (os_strcmp(buf, "FETCH_ANQP") == 0) {
5925 if (interworking_fetch_anqp(wpa_s) < 0)
5927 } else if (os_strcmp(buf, "STOP_FETCH_ANQP") == 0) {
5928 interworking_stop_fetch_anqp(wpa_s);
5929 } else if (os_strcmp(buf, "INTERWORKING_SELECT") == 0) {
5930 if (ctrl_interworking_select(wpa_s, NULL) < 0)
5932 } else if (os_strncmp(buf, "INTERWORKING_SELECT ", 20) == 0) {
5933 if (ctrl_interworking_select(wpa_s, buf + 20) < 0)
5935 } else if (os_strncmp(buf, "INTERWORKING_CONNECT ", 21) == 0) {
5936 if (ctrl_interworking_connect(wpa_s, buf + 21) < 0)
5938 } else if (os_strncmp(buf, "ANQP_GET ", 9) == 0) {
5939 if (get_anqp(wpa_s, buf + 9) < 0)
5941 } else if (os_strncmp(buf, "GAS_REQUEST ", 12) == 0) {
5942 if (gas_request(wpa_s, buf + 12) < 0)
5944 } else if (os_strncmp(buf, "GAS_RESPONSE_GET ", 17) == 0) {
5945 reply_len = gas_response_get(wpa_s, buf + 17, reply,
5947 #endif /* CONFIG_INTERWORKING */
5949 } else if (os_strncmp(buf, "HS20_ANQP_GET ", 14) == 0) {
5950 if (get_hs20_anqp(wpa_s, buf + 14) < 0)
5952 } else if (os_strncmp(buf, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
5953 if (hs20_get_nai_home_realm_list(wpa_s, buf + 29) < 0)
5955 #endif /* CONFIG_HS20 */
5956 } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0)
5958 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
5959 wpa_s, buf + os_strlen(WPA_CTRL_RSP)))
5963 * Notify response from timeout to allow the control
5964 * interface response to be sent first.
5966 eloop_register_timeout(0, 0, wpas_ctrl_eapol_response,
5969 } else if (os_strcmp(buf, "RECONFIGURE") == 0) {
5970 if (wpa_supplicant_reload_configuration(wpa_s))
5972 } else if (os_strcmp(buf, "TERMINATE") == 0) {
5973 wpa_supplicant_terminate_proc(wpa_s->global);
5974 } else if (os_strncmp(buf, "BSSID ", 6) == 0) {
5975 if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6))
5977 } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) {
5978 reply_len = wpa_supplicant_ctrl_iface_blacklist(
5979 wpa_s, buf + 9, reply, reply_size);
5980 } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) {
5981 reply_len = wpa_supplicant_ctrl_iface_log_level(
5982 wpa_s, buf + 9, reply, reply_size);
5983 } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) {
5984 reply_len = wpa_supplicant_ctrl_iface_list_networks(
5985 wpa_s, reply, reply_size);
5986 } else if (os_strcmp(buf, "DISCONNECT") == 0) {
5988 wpa_s->sme.prev_bssid_set = 0;
5989 #endif /* CONFIG_SME */
5990 wpa_s->reassociate = 0;
5991 wpa_s->disconnected = 1;
5992 wpa_supplicant_cancel_sched_scan(wpa_s);
5993 wpa_supplicant_cancel_scan(wpa_s);
5994 wpa_supplicant_deauthenticate(wpa_s,
5995 WLAN_REASON_DEAUTH_LEAVING);
5996 } else if (os_strcmp(buf, "SCAN") == 0) {
5997 wpas_ctrl_scan(wpa_s, NULL, reply, reply_size, &reply_len);
5998 } else if (os_strncmp(buf, "SCAN ", 5) == 0) {
5999 wpas_ctrl_scan(wpa_s, buf + 5, reply, reply_size, &reply_len);
6000 } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) {
6001 reply_len = wpa_supplicant_ctrl_iface_scan_results(
6002 wpa_s, reply, reply_size);
6003 } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) {
6004 if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15))
6006 } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) {
6007 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15))
6009 } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) {
6010 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16))
6012 } else if (os_strcmp(buf, "ADD_NETWORK") == 0) {
6013 reply_len = wpa_supplicant_ctrl_iface_add_network(
6014 wpa_s, reply, reply_size);
6015 } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) {
6016 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15))
6018 } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
6019 if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12))
6021 } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) {
6022 reply_len = wpa_supplicant_ctrl_iface_get_network(
6023 wpa_s, buf + 12, reply, reply_size);
6024 } else if (os_strcmp(buf, "LIST_CREDS") == 0) {
6025 reply_len = wpa_supplicant_ctrl_iface_list_creds(
6026 wpa_s, reply, reply_size);
6027 } else if (os_strcmp(buf, "ADD_CRED") == 0) {
6028 reply_len = wpa_supplicant_ctrl_iface_add_cred(
6029 wpa_s, reply, reply_size);
6030 } else if (os_strncmp(buf, "REMOVE_CRED ", 12) == 0) {
6031 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s, buf + 12))
6033 } else if (os_strncmp(buf, "SET_CRED ", 9) == 0) {
6034 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s, buf + 9))
6036 #ifndef CONFIG_NO_CONFIG_WRITE
6037 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
6038 if (wpa_supplicant_ctrl_iface_save_config(wpa_s))
6040 #endif /* CONFIG_NO_CONFIG_WRITE */
6041 } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
6042 reply_len = wpa_supplicant_ctrl_iface_get_capability(
6043 wpa_s, buf + 15, reply, reply_size);
6044 } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) {
6045 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8))
6047 } else if (os_strncmp(buf, "SCAN_INTERVAL ", 14) == 0) {
6048 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s, buf + 14))
6050 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
6051 reply_len = wpa_supplicant_global_iface_list(
6052 wpa_s->global, reply, reply_size);
6053 } else if (os_strcmp(buf, "INTERFACES") == 0) {
6054 reply_len = wpa_supplicant_global_iface_interfaces(
6055 wpa_s->global, reply, reply_size);
6056 } else if (os_strncmp(buf, "BSS ", 4) == 0) {
6057 reply_len = wpa_supplicant_ctrl_iface_bss(
6058 wpa_s, buf + 4, reply, reply_size);
6060 } else if (os_strcmp(buf, "STA-FIRST") == 0) {
6061 reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size);
6062 } else if (os_strncmp(buf, "STA ", 4) == 0) {
6063 reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply,
6065 } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) {
6066 reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply,
6068 } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) {
6069 if (ap_ctrl_iface_sta_deauthenticate(wpa_s, buf + 15))
6071 } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) {
6072 if (ap_ctrl_iface_sta_disassociate(wpa_s, buf + 13))
6074 } else if (os_strncmp(buf, "CHAN_SWITCH ", 12) == 0) {
6075 if (ap_ctrl_iface_chanswitch(wpa_s, buf + 12))
6077 #endif /* CONFIG_AP */
6078 } else if (os_strcmp(buf, "SUSPEND") == 0) {
6079 wpas_notify_suspend(wpa_s->global);
6080 } else if (os_strcmp(buf, "RESUME") == 0) {
6081 wpas_notify_resume(wpa_s->global);
6082 } else if (os_strcmp(buf, "DROP_SA") == 0) {
6083 wpa_supplicant_ctrl_iface_drop_sa(wpa_s);
6084 } else if (os_strncmp(buf, "ROAM ", 5) == 0) {
6085 if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5))
6087 } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) {
6088 if (wpa_supplicant_ctrl_iface_sta_autoconnect(wpa_s, buf + 16))
6090 } else if (os_strncmp(buf, "BSS_EXPIRE_AGE ", 15) == 0) {
6091 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s, buf + 15))
6093 } else if (os_strncmp(buf, "BSS_EXPIRE_COUNT ", 17) == 0) {
6094 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s,
6097 } else if (os_strncmp(buf, "BSS_FLUSH ", 10) == 0) {
6098 if (wpa_supplicant_ctrl_iface_bss_flush(wpa_s, buf + 10))
6101 } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) {
6102 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14))
6104 } else if (os_strncmp(buf, "TDLS_SETUP ", 11) == 0) {
6105 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s, buf + 11))
6107 } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) {
6108 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14))
6110 #endif /* CONFIG_TDLS */
6111 } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) {
6112 reply_len = wpa_supplicant_signal_poll(wpa_s, reply,
6114 } else if (os_strncmp(buf, "PKTCNT_POLL", 11) == 0) {
6115 reply_len = wpa_supplicant_pktcnt_poll(wpa_s, reply,
6117 #ifdef CONFIG_AUTOSCAN
6118 } else if (os_strncmp(buf, "AUTOSCAN ", 9) == 0) {
6119 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s, buf + 9))
6121 #endif /* CONFIG_AUTOSCAN */
6123 } else if (os_strncmp(buf, "DRIVER ", 7) == 0) {
6124 reply_len = wpa_supplicant_driver_cmd(wpa_s, buf + 7, reply,
6126 #endif /* ANDROID */
6127 } else if (os_strcmp(buf, "REAUTHENTICATE") == 0) {
6128 pmksa_cache_clear_current(wpa_s->wpa);
6129 eapol_sm_request_reauth(wpa_s->eapol);
6131 } else if (os_strncmp(buf, "WNM_SLEEP ", 10) == 0) {
6132 if (wpas_ctrl_iface_wnm_sleep(wpa_s, buf + 10))
6134 } else if (os_strncmp(buf, "WNM_BSS_QUERY ", 10) == 0) {
6135 if (wpas_ctrl_iface_wnm_bss_query(wpa_s, buf + 10))
6137 #endif /* CONFIG_WNM */
6138 } else if (os_strcmp(buf, "FLUSH") == 0) {
6139 wpa_supplicant_ctrl_iface_flush(wpa_s);
6140 } else if (os_strncmp(buf, "RADIO_WORK ", 11) == 0) {
6141 reply_len = wpas_ctrl_radio_work(wpa_s, buf + 11, reply,
6144 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
6148 if (reply_len < 0) {
6149 os_memcpy(reply, "FAIL\n", 5);
6153 *resp_len = reply_len;
6158 static int wpa_supplicant_global_iface_add(struct wpa_global *global,
6161 struct wpa_interface iface;
6165 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
6166 * TAB<bridge_ifname>
6168 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd);
6170 os_memset(&iface, 0, sizeof(iface));
6173 iface.ifname = pos = cmd;
6174 pos = os_strchr(pos, '\t');
6177 if (iface.ifname[0] == '\0')
6182 iface.confname = pos;
6183 pos = os_strchr(pos, '\t');
6186 if (iface.confname[0] == '\0')
6187 iface.confname = NULL;
6192 pos = os_strchr(pos, '\t');
6195 if (iface.driver[0] == '\0')
6196 iface.driver = NULL;
6200 iface.ctrl_interface = pos;
6201 pos = os_strchr(pos, '\t');
6204 if (iface.ctrl_interface[0] == '\0')
6205 iface.ctrl_interface = NULL;
6209 iface.driver_param = pos;
6210 pos = os_strchr(pos, '\t');
6213 if (iface.driver_param[0] == '\0')
6214 iface.driver_param = NULL;
6218 iface.bridge_ifname = pos;
6219 pos = os_strchr(pos, '\t');
6222 if (iface.bridge_ifname[0] == '\0')
6223 iface.bridge_ifname = NULL;
6228 if (wpa_supplicant_get_iface(global, iface.ifname))
6231 return wpa_supplicant_add_iface(global, &iface) ? 0 : -1;
6235 static int wpa_supplicant_global_iface_remove(struct wpa_global *global,
6238 struct wpa_supplicant *wpa_s;
6240 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd);
6242 wpa_s = wpa_supplicant_get_iface(global, cmd);
6245 return wpa_supplicant_remove_iface(global, wpa_s, 0);
6249 static void wpa_free_iface_info(struct wpa_interface_info *iface)
6251 struct wpa_interface_info *prev;
6255 iface = iface->next;
6257 os_free(prev->ifname);
6258 os_free(prev->desc);
6264 static int wpa_supplicant_global_iface_list(struct wpa_global *global,
6268 struct wpa_interface_info *iface = NULL, *last = NULL, *tmp;
6271 for (i = 0; wpa_drivers[i]; i++) {
6272 struct wpa_driver_ops *drv = wpa_drivers[i];
6273 if (drv->get_interfaces == NULL)
6275 tmp = drv->get_interfaces(global->drv_priv[i]);
6289 for (tmp = iface; tmp; tmp = tmp->next) {
6290 res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n",
6291 tmp->drv_name, tmp->ifname,
6292 tmp->desc ? tmp->desc : "");
6293 if (res < 0 || res >= end - pos) {
6300 wpa_free_iface_info(iface);
6306 static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
6311 struct wpa_supplicant *wpa_s;
6313 wpa_s = global->ifaces;
6318 res = os_snprintf(pos, end - pos, "%s\n", wpa_s->ifname);
6319 if (res < 0 || res >= end - pos) {
6324 wpa_s = wpa_s->next;
6330 static char * wpas_global_ctrl_iface_ifname(struct wpa_global *global,
6332 char *cmd, size_t *resp_len)
6334 struct wpa_supplicant *wpa_s;
6336 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
6337 if (os_strcmp(ifname, wpa_s->ifname) == 0)
6341 if (wpa_s == NULL) {
6342 char *resp = os_strdup("FAIL-NO-IFNAME-MATCH\n");
6344 *resp_len = os_strlen(resp);
6350 return wpa_supplicant_ctrl_iface_process(wpa_s, cmd, resp_len);
6354 static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global *global,
6355 char *buf, size_t *resp_len)
6358 static const char * cmd[] = {
6365 "P2P_GET_PASSPHRASE",
6366 "P2P_SERVICE_UPDATE",
6367 "P2P_SERVICE_FLUSH",
6374 static const char * prefix[] = {
6377 #endif /* ANDROID */
6384 "P2P_GROUP_REMOVE ",
6387 "P2P_SERV_DISC_REQ ",
6388 "P2P_SERV_DISC_CANCEL_REQ ",
6389 "P2P_SERV_DISC_RESP ",
6390 "P2P_SERV_DISC_EXTERNAL ",
6398 "P2P_PRESENCE_REQ ",
6400 "P2P_REMOVE_CLIENT ",
6406 if (global->p2p_init_wpa_s == NULL)
6409 for (i = 0; !found && cmd[i]; i++) {
6410 if (os_strcmp(buf, cmd[i]) == 0)
6414 for (i = 0; !found && prefix[i]; i++) {
6415 if (os_strncmp(buf, prefix[i], os_strlen(prefix[i])) == 0)
6420 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
6422 #endif /* CONFIG_P2P */
6427 static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global *global,
6428 char *buf, size_t *resp_len)
6430 #ifdef CONFIG_WIFI_DISPLAY
6431 if (global->p2p_init_wpa_s == NULL)
6433 if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0 ||
6434 os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0)
6435 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
6437 #endif /* CONFIG_WIFI_DISPLAY */
6442 static char * wpas_global_ctrl_iface_redir(struct wpa_global *global,
6443 char *buf, size_t *resp_len)
6447 ret = wpas_global_ctrl_iface_redir_p2p(global, buf, resp_len);
6451 ret = wpas_global_ctrl_iface_redir_wfd(global, buf, resp_len);
6459 static int wpas_global_ctrl_iface_set(struct wpa_global *global, char *cmd)
6463 value = os_strchr(cmd, ' ');
6468 wpa_printf(MSG_DEBUG, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd, value);
6470 #ifdef CONFIG_WIFI_DISPLAY
6471 if (os_strcasecmp(cmd, "wifi_display") == 0) {
6472 wifi_display_enable(global, !!atoi(value));
6475 #endif /* CONFIG_WIFI_DISPLAY */
6481 #ifndef CONFIG_NO_CONFIG_WRITE
6482 static int wpas_global_ctrl_iface_save_config(struct wpa_global *global)
6485 struct wpa_supplicant *wpa_s;
6487 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
6488 if (!wpa_s->conf->update_config) {
6489 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
6493 if (wpa_config_write(wpa_s->confname, wpa_s->conf)) {
6494 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
6497 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
6503 #endif /* CONFIG_NO_CONFIG_WRITE */
6506 static int wpas_global_ctrl_iface_status(struct wpa_global *global,
6507 char *buf, size_t buflen)
6511 struct wpa_supplicant *wpa_s;
6517 if (global->p2p && !global->p2p_disabled) {
6518 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
6521 MAC2STR(global->p2p_dev_addr),
6522 p2p_get_state_txt(global->p2p));
6523 if (ret < 0 || ret >= end - pos)
6526 } else if (global->p2p) {
6527 ret = os_snprintf(pos, end - pos, "p2p_state=DISABLED\n");
6528 if (ret < 0 || ret >= end - pos)
6532 #endif /* CONFIG_P2P */
6534 #ifdef CONFIG_WIFI_DISPLAY
6535 ret = os_snprintf(pos, end - pos, "wifi_display=%d\n",
6536 !!global->wifi_display);
6537 if (ret < 0 || ret >= end - pos)
6540 #endif /* CONFIG_WIFI_DISPLAY */
6542 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
6543 ret = os_snprintf(pos, end - pos, "ifname=%s\n"
6544 "address=" MACSTR "\n",
6545 wpa_s->ifname, MAC2STR(wpa_s->own_addr));
6546 if (ret < 0 || ret >= end - pos)
6555 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
6556 char *buf, size_t *resp_len)
6559 const int reply_size = 2048;
6561 int level = MSG_DEBUG;
6563 if (os_strncmp(buf, "IFNAME=", 7) == 0) {
6564 char *pos = os_strchr(buf + 7, ' ');
6567 return wpas_global_ctrl_iface_ifname(global,
6573 reply = wpas_global_ctrl_iface_redir(global, buf, resp_len);
6577 if (os_strcmp(buf, "PING") == 0)
6578 level = MSG_EXCESSIVE;
6579 wpa_hexdump_ascii(level, "RX global ctrl_iface",
6580 (const u8 *) buf, os_strlen(buf));
6582 reply = os_malloc(reply_size);
6583 if (reply == NULL) {
6588 os_memcpy(reply, "OK\n", 3);
6591 if (os_strcmp(buf, "PING") == 0) {
6592 os_memcpy(reply, "PONG\n", 5);
6594 } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) {
6595 if (wpa_supplicant_global_iface_add(global, buf + 14))
6597 } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) {
6598 if (wpa_supplicant_global_iface_remove(global, buf + 17))
6600 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
6601 reply_len = wpa_supplicant_global_iface_list(
6602 global, reply, reply_size);
6603 } else if (os_strcmp(buf, "INTERFACES") == 0) {
6604 reply_len = wpa_supplicant_global_iface_interfaces(
6605 global, reply, reply_size);
6606 } else if (os_strcmp(buf, "TERMINATE") == 0) {
6607 wpa_supplicant_terminate_proc(global);
6608 } else if (os_strcmp(buf, "SUSPEND") == 0) {
6609 wpas_notify_suspend(global);
6610 } else if (os_strcmp(buf, "RESUME") == 0) {
6611 wpas_notify_resume(global);
6612 } else if (os_strncmp(buf, "SET ", 4) == 0) {
6613 if (wpas_global_ctrl_iface_set(global, buf + 4))
6615 #ifndef CONFIG_NO_CONFIG_WRITE
6616 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
6617 if (wpas_global_ctrl_iface_save_config(global))
6619 #endif /* CONFIG_NO_CONFIG_WRITE */
6620 } else if (os_strcmp(buf, "STATUS") == 0) {
6621 reply_len = wpas_global_ctrl_iface_status(global, reply,
6624 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
6628 if (reply_len < 0) {
6629 os_memcpy(reply, "FAIL\n", 5);
6633 *resp_len = reply_len;