2 * WPA Supplicant / Control interface (shared code for all backends)
3 * Copyright (c) 2004-2012, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
9 #include "utils/includes.h"
11 #include "utils/common.h"
12 #include "utils/eloop.h"
13 #include "common/version.h"
14 #include "common/ieee802_11_defs.h"
15 #include "common/ieee802_11_common.h"
16 #include "common/wpa_ctrl.h"
17 #include "eap_peer/eap.h"
18 #include "eapol_supp/eapol_supp_sm.h"
19 #include "rsn_supp/wpa.h"
20 #include "rsn_supp/preauth.h"
21 #include "rsn_supp/pmksa_cache.h"
22 #include "l2_packet/l2_packet.h"
25 #include "wpa_supplicant_i.h"
27 #include "wps_supplicant.h"
30 #include "p2p_supplicant.h"
32 #include "hs20_supplicant.h"
33 #include "wifi_display.h"
37 #include "ctrl_iface.h"
38 #include "interworking.h"
39 #include "blacklist.h"
40 #include "wpas_glue.h"
43 extern struct wpa_driver_ops *wpa_drivers[];
45 static int wpa_supplicant_global_iface_list(struct wpa_global *global,
47 static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
51 static int pno_start(struct wpa_supplicant *wpa_s)
55 struct wpa_ssid *ssid;
56 struct wpa_driver_scan_params params;
61 os_memset(¶ms, 0, sizeof(params));
64 ssid = wpa_s->conf->ssid;
66 if (!wpas_network_disabled(wpa_s, ssid))
70 if (num_ssid > WPAS_MAX_SCAN_SSIDS) {
71 wpa_printf(MSG_DEBUG, "PNO: Use only the first %u SSIDs from "
72 "%u", WPAS_MAX_SCAN_SSIDS, (unsigned int) num_ssid);
73 num_ssid = WPAS_MAX_SCAN_SSIDS;
77 wpa_printf(MSG_DEBUG, "PNO: No configured SSIDs");
81 params.filter_ssids = os_malloc(sizeof(struct wpa_driver_scan_filter) *
83 if (params.filter_ssids == NULL)
86 ssid = wpa_s->conf->ssid;
88 if (!wpas_network_disabled(wpa_s, ssid)) {
89 params.ssids[i].ssid = ssid->ssid;
90 params.ssids[i].ssid_len = ssid->ssid_len;
92 os_memcpy(params.filter_ssids[i].ssid, ssid->ssid,
94 params.filter_ssids[i].ssid_len = ssid->ssid_len;
95 params.num_filter_ssids++;
103 if (wpa_s->conf->filter_rssi)
104 params.filter_rssi = wpa_s->conf->filter_rssi;
106 ret = wpa_drv_sched_scan(wpa_s, ¶ms, 10 * 1000);
107 os_free(params.filter_ssids);
114 static int pno_stop(struct wpa_supplicant *wpa_s)
118 return wpa_drv_stop_sched_scan(wpa_s);
124 static int set_bssid_filter(struct wpa_supplicant *wpa_s, char *val)
127 u8 addr[ETH_ALEN], *filter = NULL, *n;
134 if (hwaddr_aton(pos, addr)) {
138 n = os_realloc_array(filter, count + 1, ETH_ALEN);
144 os_memcpy(filter + count * ETH_ALEN, addr, ETH_ALEN);
147 pos = os_strchr(pos, ' ');
152 wpa_hexdump(MSG_DEBUG, "bssid_filter", filter, count * ETH_ALEN);
153 os_free(wpa_s->bssid_filter);
154 wpa_s->bssid_filter = filter;
155 wpa_s->bssid_filter_count = count;
161 static int set_disallow_aps(struct wpa_supplicant *wpa_s, char *val)
164 u8 addr[ETH_ALEN], *bssid = NULL, *n;
165 struct wpa_ssid_value *ssid = NULL, *ns;
166 size_t count = 0, ssid_count = 0;
170 * disallow_list ::= <ssid_spec> | <bssid_spec> | <disallow_list> | “”
171 * SSID_SPEC ::= ssid <SSID_HEX>
172 * BSSID_SPEC ::= bssid <BSSID_HEX>
179 if (os_strncmp(pos, "bssid ", 6) == 0) {
182 res = hwaddr_aton2(pos, addr);
186 wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
187 "BSSID value '%s'", pos);
191 n = os_realloc_array(bssid, count + 1, ETH_ALEN);
198 os_memcpy(bssid + count * ETH_ALEN, addr, ETH_ALEN);
200 } else if (os_strncmp(pos, "ssid ", 5) == 0) {
206 if (*end == '\0' || *end == ' ')
211 ns = os_realloc_array(ssid, ssid_count + 1,
212 sizeof(struct wpa_ssid_value));
220 if ((end - pos) & 0x01 || end - pos > 2 * 32 ||
221 hexstr2bin(pos, ssid[ssid_count].ssid,
222 (end - pos) / 2) < 0) {
225 wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
226 "SSID value '%s'", pos);
229 ssid[ssid_count].ssid_len = (end - pos) / 2;
230 wpa_hexdump_ascii(MSG_DEBUG, "disallow_aps SSID",
231 ssid[ssid_count].ssid,
232 ssid[ssid_count].ssid_len);
236 wpa_printf(MSG_DEBUG, "Unexpected disallow_aps value "
243 pos = os_strchr(pos, ' ');
248 wpa_hexdump(MSG_DEBUG, "disallow_aps_bssid", bssid, count * ETH_ALEN);
249 os_free(wpa_s->disallow_aps_bssid);
250 wpa_s->disallow_aps_bssid = bssid;
251 wpa_s->disallow_aps_bssid_count = count;
253 wpa_printf(MSG_DEBUG, "disallow_aps_ssid_count %d", (int) ssid_count);
254 os_free(wpa_s->disallow_aps_ssid);
255 wpa_s->disallow_aps_ssid = ssid;
256 wpa_s->disallow_aps_ssid_count = ssid_count;
258 if (!wpa_s->current_ssid || wpa_s->wpa_state < WPA_AUTHENTICATING)
261 c = wpa_s->current_ssid;
262 if (c->mode != WPAS_MODE_INFRA && c->mode != WPAS_MODE_IBSS)
265 if (!disallowed_bssid(wpa_s, wpa_s->bssid) &&
266 !disallowed_ssid(wpa_s, c->ssid, c->ssid_len))
269 wpa_printf(MSG_DEBUG, "Disconnect and try to find another network "
270 "because current AP was marked disallowed");
273 wpa_s->sme.prev_bssid_set = 0;
274 #endif /* CONFIG_SME */
275 wpa_s->reassociate = 1;
276 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
277 wpa_supplicant_req_scan(wpa_s, 0, 0);
283 static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s,
289 value = os_strchr(cmd, ' ');
294 wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value);
295 if (os_strcasecmp(cmd, "EAPOL::heldPeriod") == 0) {
296 eapol_sm_configure(wpa_s->eapol,
297 atoi(value), -1, -1, -1);
298 } else if (os_strcasecmp(cmd, "EAPOL::authPeriod") == 0) {
299 eapol_sm_configure(wpa_s->eapol,
300 -1, atoi(value), -1, -1);
301 } else if (os_strcasecmp(cmd, "EAPOL::startPeriod") == 0) {
302 eapol_sm_configure(wpa_s->eapol,
303 -1, -1, atoi(value), -1);
304 } else if (os_strcasecmp(cmd, "EAPOL::maxStart") == 0) {
305 eapol_sm_configure(wpa_s->eapol,
306 -1, -1, -1, atoi(value));
307 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKLifetime") == 0) {
308 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME,
311 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKReauthThreshold") ==
313 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD,
316 } else if (os_strcasecmp(cmd, "dot11RSNAConfigSATimeout") == 0) {
317 if (wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, atoi(value)))
319 } else if (os_strcasecmp(cmd, "wps_fragment_size") == 0) {
320 wpa_s->wps_fragment_size = atoi(value);
321 #ifdef CONFIG_WPS_TESTING
322 } else if (os_strcasecmp(cmd, "wps_version_number") == 0) {
324 val = strtol(value, NULL, 0);
325 if (val < 0 || val > 0xff) {
327 wpa_printf(MSG_DEBUG, "WPS: Invalid "
328 "wps_version_number %ld", val);
330 wps_version_number = val;
331 wpa_printf(MSG_DEBUG, "WPS: Testing - force WPS "
333 (wps_version_number & 0xf0) >> 4,
334 wps_version_number & 0x0f);
336 } else if (os_strcasecmp(cmd, "wps_testing_dummy_cred") == 0) {
337 wps_testing_dummy_cred = atoi(value);
338 wpa_printf(MSG_DEBUG, "WPS: Testing - dummy_cred=%d",
339 wps_testing_dummy_cred);
340 #endif /* CONFIG_WPS_TESTING */
341 } else if (os_strcasecmp(cmd, "ampdu") == 0) {
342 if (wpa_drv_ampdu(wpa_s, atoi(value)) < 0)
344 #ifdef CONFIG_TDLS_TESTING
345 } else if (os_strcasecmp(cmd, "tdls_testing") == 0) {
346 extern unsigned int tdls_testing;
347 tdls_testing = strtol(value, NULL, 0);
348 wpa_printf(MSG_DEBUG, "TDLS: tdls_testing=0x%x", tdls_testing);
349 #endif /* CONFIG_TDLS_TESTING */
351 } else if (os_strcasecmp(cmd, "tdls_disabled") == 0) {
352 int disabled = atoi(value);
353 wpa_printf(MSG_DEBUG, "TDLS: tdls_disabled=%d", disabled);
355 if (wpa_drv_tdls_oper(wpa_s, TDLS_DISABLE, NULL) < 0)
357 } else if (wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL) < 0)
359 wpa_tdls_enable(wpa_s->wpa, !disabled);
360 #endif /* CONFIG_TDLS */
361 } else if (os_strcasecmp(cmd, "pno") == 0) {
363 ret = pno_start(wpa_s);
365 ret = pno_stop(wpa_s);
366 } else if (os_strcasecmp(cmd, "radio_disabled") == 0) {
367 int disabled = atoi(value);
368 if (wpa_drv_radio_disable(wpa_s, disabled) < 0)
371 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
372 } else if (os_strcasecmp(cmd, "uapsd") == 0) {
373 if (os_strcmp(value, "disable") == 0)
374 wpa_s->set_sta_uapsd = 0;
378 /* format: BE,BK,VI,VO;max SP Length */
380 pos = os_strchr(value, ',');
385 pos = os_strchr(pos, ',');
390 pos = os_strchr(pos, ',');
395 /* ignore max SP Length for now */
397 wpa_s->set_sta_uapsd = 1;
398 wpa_s->sta_uapsd = 0;
400 wpa_s->sta_uapsd |= BIT(0);
402 wpa_s->sta_uapsd |= BIT(1);
404 wpa_s->sta_uapsd |= BIT(2);
406 wpa_s->sta_uapsd |= BIT(3);
408 } else if (os_strcasecmp(cmd, "ps") == 0) {
409 ret = wpa_drv_set_p2p_powersave(wpa_s, atoi(value), -1, -1);
410 #ifdef CONFIG_WIFI_DISPLAY
411 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
412 wifi_display_enable(wpa_s->global, !!atoi(value));
413 #endif /* CONFIG_WIFI_DISPLAY */
414 } else if (os_strcasecmp(cmd, "bssid_filter") == 0) {
415 ret = set_bssid_filter(wpa_s, value);
416 } else if (os_strcasecmp(cmd, "disallow_aps") == 0) {
417 ret = set_disallow_aps(wpa_s, value);
420 ret = wpa_config_process_global(wpa_s->conf, cmd, -1);
422 wpa_supplicant_update_config(wpa_s);
429 static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s,
430 char *cmd, char *buf, size_t buflen)
434 wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd);
436 if (os_strcmp(cmd, "version") == 0) {
437 res = os_snprintf(buf, buflen, "%s", VERSION_STR);
438 } else if (os_strcasecmp(cmd, "country") == 0) {
439 if (wpa_s->conf->country[0] && wpa_s->conf->country[1])
440 res = os_snprintf(buf, buflen, "%c%c",
441 wpa_s->conf->country[0],
442 wpa_s->conf->country[1]);
443 #ifdef CONFIG_WIFI_DISPLAY
444 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
445 res = os_snprintf(buf, buflen, "%d",
446 wpa_s->global->wifi_display);
447 if (res < 0 || (unsigned int) res >= buflen)
450 #endif /* CONFIG_WIFI_DISPLAY */
453 if (res < 0 || (unsigned int) res >= buflen)
459 #ifdef IEEE8021X_EAPOL
460 static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s,
464 struct wpa_ssid *ssid = wpa_s->current_ssid;
466 if (hwaddr_aton(addr, bssid)) {
467 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address "
472 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid));
473 rsn_preauth_deinit(wpa_s->wpa);
474 if (rsn_preauth_init(wpa_s->wpa, bssid, ssid ? &ssid->eap : NULL))
479 #endif /* IEEE8021X_EAPOL */
482 #ifdef CONFIG_PEERKEY
483 /* MLME-STKSTART.request(peer) */
484 static int wpa_supplicant_ctrl_iface_stkstart(
485 struct wpa_supplicant *wpa_s, char *addr)
489 if (hwaddr_aton(addr, peer)) {
490 wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART: invalid "
491 "address '%s'", addr);
495 wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART " MACSTR,
498 return wpa_sm_stkstart(wpa_s->wpa, peer);
500 #endif /* CONFIG_PEERKEY */
505 static int wpa_supplicant_ctrl_iface_tdls_discover(
506 struct wpa_supplicant *wpa_s, char *addr)
511 if (hwaddr_aton(addr, peer)) {
512 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER: invalid "
513 "address '%s'", addr);
517 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER " MACSTR,
520 if (wpa_tdls_is_external_setup(wpa_s->wpa))
521 ret = wpa_tdls_send_discovery_request(wpa_s->wpa, peer);
523 ret = wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer);
529 static int wpa_supplicant_ctrl_iface_tdls_setup(
530 struct wpa_supplicant *wpa_s, char *addr)
535 if (hwaddr_aton(addr, peer)) {
536 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP: invalid "
537 "address '%s'", addr);
541 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP " MACSTR,
544 ret = wpa_tdls_reneg(wpa_s->wpa, peer);
546 if (wpa_tdls_is_external_setup(wpa_s->wpa))
547 ret = wpa_tdls_start(wpa_s->wpa, peer);
549 ret = wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
556 static int wpa_supplicant_ctrl_iface_tdls_teardown(
557 struct wpa_supplicant *wpa_s, char *addr)
561 if (hwaddr_aton(addr, peer)) {
562 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN: invalid "
563 "address '%s'", addr);
567 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN " MACSTR,
570 return wpa_tdls_teardown_link(wpa_s->wpa, peer,
571 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED);
574 #endif /* CONFIG_TDLS */
577 #ifdef CONFIG_IEEE80211R
578 static int wpa_supplicant_ctrl_iface_ft_ds(
579 struct wpa_supplicant *wpa_s, char *addr)
581 u8 target_ap[ETH_ALEN];
585 if (hwaddr_aton(addr, target_ap)) {
586 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid "
587 "address '%s'", addr);
591 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap));
593 bss = wpa_bss_get_bssid(wpa_s, target_ap);
595 mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN);
599 return wpa_ft_start_over_ds(wpa_s->wpa, target_ap, mdie);
601 #endif /* CONFIG_IEEE80211R */
605 static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s,
608 u8 bssid[ETH_ALEN], *_bssid = bssid;
610 u8 p2p_dev_addr[ETH_ALEN];
611 #endif /* CONFIG_P2P */
613 u8 *_p2p_dev_addr = NULL;
614 #endif /* CONFIG_AP */
616 if (cmd == NULL || os_strcmp(cmd, "any") == 0) {
619 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
620 if (hwaddr_aton(cmd + 13, p2p_dev_addr)) {
621 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid "
622 "P2P Device Address '%s'",
626 _p2p_dev_addr = p2p_dev_addr;
627 #endif /* CONFIG_P2P */
628 } else if (hwaddr_aton(cmd, bssid)) {
629 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
636 return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid, _p2p_dev_addr);
637 #endif /* CONFIG_AP */
639 return wpas_wps_start_pbc(wpa_s, _bssid, 0);
643 static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s,
644 char *cmd, char *buf,
647 u8 bssid[ETH_ALEN], *_bssid = bssid;
651 pin = os_strchr(cmd, ' ');
655 if (os_strcmp(cmd, "any") == 0)
657 else if (os_strcmp(cmd, "get") == 0) {
658 ret = wps_generate_pin();
660 } else if (hwaddr_aton(cmd, bssid)) {
661 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
668 return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin,
670 #endif /* CONFIG_AP */
673 ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0,
677 ret = os_snprintf(buf, buflen, "%s", pin);
678 if (ret < 0 || (size_t) ret >= buflen)
683 ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0, DEV_PW_DEFAULT);
688 /* Return the generated PIN */
689 ret = os_snprintf(buf, buflen, "%08d", ret);
690 if (ret < 0 || (size_t) ret >= buflen)
696 static int wpa_supplicant_ctrl_iface_wps_check_pin(
697 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
704 wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN",
705 (u8 *) cmd, os_strlen(cmd));
706 for (pos = cmd, len = 0; *pos != '\0'; pos++) {
707 if (*pos < '0' || *pos > '9')
711 wpa_printf(MSG_DEBUG, "WPS: Too long PIN");
715 if (len != 4 && len != 8) {
716 wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len);
722 unsigned int pin_val;
724 if (!wps_pin_valid(pin_val)) {
725 wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit");
726 ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n");
727 if (ret < 0 || (size_t) ret >= buflen)
733 ret = os_snprintf(buf, buflen, "%s", pin);
734 if (ret < 0 || (size_t) ret >= buflen)
741 #ifdef CONFIG_WPS_OOB
742 static int wpa_supplicant_ctrl_iface_wps_oob(struct wpa_supplicant *wpa_s,
745 char *path, *method, *name;
747 path = os_strchr(cmd, ' ');
752 method = os_strchr(path, ' ');
757 name = os_strchr(method, ' ');
761 return wpas_wps_start_oob(wpa_s, cmd, path, method, name);
763 #endif /* CONFIG_WPS_OOB */
766 #ifdef CONFIG_WPS_NFC
768 static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant *wpa_s,
771 u8 bssid[ETH_ALEN], *_bssid = bssid;
773 if (cmd == NULL || cmd[0] == '\0')
775 else if (hwaddr_aton(cmd, bssid))
778 return wpas_wps_start_nfc(wpa_s, _bssid);
782 static int wpa_supplicant_ctrl_iface_wps_nfc_token(
783 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
789 if (os_strcmp(cmd, "WPS") == 0)
791 else if (os_strcmp(cmd, "NDEF") == 0)
796 buf = wpas_wps_nfc_token(wpa_s, ndef);
800 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
811 static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
812 struct wpa_supplicant *wpa_s, char *pos)
818 len = os_strlen(pos);
823 buf = wpabuf_alloc(len);
826 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
831 ret = wpas_wps_nfc_tag_read(wpa_s, buf);
837 #endif /* CONFIG_WPS_NFC */
840 static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s,
849 struct wps_new_ap_settings ap;
851 pin = os_strchr(cmd, ' ');
856 if (hwaddr_aton(cmd, bssid)) {
857 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
862 new_ssid = os_strchr(pin, ' ');
863 if (new_ssid == NULL)
864 return wpas_wps_start_reg(wpa_s, bssid, pin, NULL);
867 new_auth = os_strchr(new_ssid, ' ');
868 if (new_auth == NULL)
872 new_encr = os_strchr(new_auth, ' ');
873 if (new_encr == NULL)
877 new_key = os_strchr(new_encr, ' ');
882 os_memset(&ap, 0, sizeof(ap));
883 ap.ssid_hex = new_ssid;
886 ap.key_hex = new_key;
887 return wpas_wps_start_reg(wpa_s, bssid, pin, &ap);
892 static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant *wpa_s,
893 char *cmd, char *buf,
900 if (!wpa_s->ap_iface)
903 pos = os_strchr(cmd, ' ');
907 if (os_strcmp(cmd, "disable") == 0) {
908 wpas_wps_ap_pin_disable(wpa_s);
909 return os_snprintf(buf, buflen, "OK\n");
912 if (os_strcmp(cmd, "random") == 0) {
915 pin_txt = wpas_wps_ap_pin_random(wpa_s, timeout);
918 return os_snprintf(buf, buflen, "%s", pin_txt);
921 if (os_strcmp(cmd, "get") == 0) {
922 pin_txt = wpas_wps_ap_pin_get(wpa_s);
925 return os_snprintf(buf, buflen, "%s", pin_txt);
928 if (os_strcmp(cmd, "set") == 0) {
933 pos = os_strchr(pos, ' ');
938 if (os_strlen(pin) > buflen)
940 if (wpas_wps_ap_pin_set(wpa_s, pin, timeout) < 0)
942 return os_snprintf(buf, buflen, "%s", pin);
947 #endif /* CONFIG_AP */
951 static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant *wpa_s,
954 char *uuid = cmd, *pin, *pos;
955 u8 addr_buf[ETH_ALEN], *addr = NULL;
956 pin = os_strchr(uuid, ' ');
960 pos = os_strchr(pin, ' ');
963 if (hwaddr_aton(pos, addr_buf) == 0)
966 return wpas_wps_er_add_pin(wpa_s, addr, uuid, pin);
970 static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant *wpa_s,
973 char *uuid = cmd, *pin;
974 pin = os_strchr(uuid, ' ');
978 return wpas_wps_er_learn(wpa_s, uuid, pin);
982 static int wpa_supplicant_ctrl_iface_wps_er_set_config(
983 struct wpa_supplicant *wpa_s, char *cmd)
985 char *uuid = cmd, *id;
986 id = os_strchr(uuid, ' ');
990 return wpas_wps_er_set_config(wpa_s, uuid, atoi(id));
994 static int wpa_supplicant_ctrl_iface_wps_er_config(
995 struct wpa_supplicant *wpa_s, char *cmd)
1002 struct wps_new_ap_settings ap;
1004 pin = os_strchr(cmd, ' ');
1009 new_ssid = os_strchr(pin, ' ');
1010 if (new_ssid == NULL)
1014 new_auth = os_strchr(new_ssid, ' ');
1015 if (new_auth == NULL)
1019 new_encr = os_strchr(new_auth, ' ');
1020 if (new_encr == NULL)
1024 new_key = os_strchr(new_encr, ' ');
1025 if (new_key == NULL)
1029 os_memset(&ap, 0, sizeof(ap));
1030 ap.ssid_hex = new_ssid;
1033 ap.key_hex = new_key;
1034 return wpas_wps_er_config(wpa_s, cmd, pin, &ap);
1038 #ifdef CONFIG_WPS_NFC
1039 static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
1040 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1047 uuid = os_strchr(cmd, ' ');
1052 if (os_strcmp(cmd, "WPS") == 0)
1054 else if (os_strcmp(cmd, "NDEF") == 0)
1059 buf = wpas_wps_er_nfc_config_token(wpa_s, ndef, uuid);
1063 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1065 reply[res++] = '\n';
1072 #endif /* CONFIG_WPS_NFC */
1073 #endif /* CONFIG_WPS_ER */
1075 #endif /* CONFIG_WPS */
1078 #ifdef CONFIG_IBSS_RSN
1079 static int wpa_supplicant_ctrl_iface_ibss_rsn(
1080 struct wpa_supplicant *wpa_s, char *addr)
1084 if (hwaddr_aton(addr, peer)) {
1085 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN: invalid "
1086 "address '%s'", addr);
1090 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN " MACSTR,
1093 return ibss_rsn_start(wpa_s->ibss_rsn, peer);
1095 #endif /* CONFIG_IBSS_RSN */
1098 static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s,
1101 #ifdef IEEE8021X_EAPOL
1104 struct wpa_ssid *ssid;
1106 pos = os_strchr(rsp, '-');
1111 pos = os_strchr(pos, ':');
1116 wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id);
1117 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
1118 (u8 *) pos, os_strlen(pos));
1120 ssid = wpa_config_get_network(wpa_s->conf, id);
1122 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
1127 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s, ssid, rsp,
1129 #else /* IEEE8021X_EAPOL */
1130 wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included");
1132 #endif /* IEEE8021X_EAPOL */
1136 static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
1138 char *buf, size_t buflen)
1140 char *pos, *end, tmp[30];
1141 int res, verbose, wps, ret;
1143 verbose = os_strcmp(params, "-VERBOSE") == 0;
1144 wps = os_strcmp(params, "-WPS") == 0;
1147 if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
1148 struct wpa_ssid *ssid = wpa_s->current_ssid;
1149 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
1150 MAC2STR(wpa_s->bssid));
1151 if (ret < 0 || ret >= end - pos)
1155 u8 *_ssid = ssid->ssid;
1156 size_t ssid_len = ssid->ssid_len;
1157 u8 ssid_buf[MAX_SSID_LEN];
1158 if (ssid_len == 0) {
1159 int _res = wpa_drv_get_ssid(wpa_s, ssid_buf);
1166 ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n",
1167 wpa_ssid_txt(_ssid, ssid_len),
1169 if (ret < 0 || ret >= end - pos)
1173 if (wps && ssid->passphrase &&
1174 wpa_key_mgmt_wpa_psk(ssid->key_mgmt) &&
1175 (ssid->mode == WPAS_MODE_AP ||
1176 ssid->mode == WPAS_MODE_P2P_GO)) {
1177 ret = os_snprintf(pos, end - pos,
1180 if (ret < 0 || ret >= end - pos)
1185 ret = os_snprintf(pos, end - pos,
1188 if (ret < 0 || ret >= end - pos)
1193 switch (ssid->mode) {
1194 case WPAS_MODE_INFRA:
1195 ret = os_snprintf(pos, end - pos,
1198 case WPAS_MODE_IBSS:
1199 ret = os_snprintf(pos, end - pos,
1203 ret = os_snprintf(pos, end - pos,
1206 case WPAS_MODE_P2P_GO:
1207 ret = os_snprintf(pos, end - pos,
1210 case WPAS_MODE_P2P_GROUP_FORMATION:
1211 ret = os_snprintf(pos, end - pos,
1212 "mode=P2P GO - group "
1219 if (ret < 0 || ret >= end - pos)
1225 if (wpa_s->ap_iface) {
1226 pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos,
1230 #endif /* CONFIG_AP */
1231 pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose);
1233 ret = os_snprintf(pos, end - pos, "wpa_state=%s\n",
1234 wpa_supplicant_state_txt(wpa_s->wpa_state));
1235 if (ret < 0 || ret >= end - pos)
1240 l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) {
1241 ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp);
1242 if (ret < 0 || ret >= end - pos)
1248 if (wpa_s->global->p2p) {
1249 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
1250 "\n", MAC2STR(wpa_s->global->p2p_dev_addr));
1251 if (ret < 0 || ret >= end - pos)
1255 #endif /* CONFIG_P2P */
1257 ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n",
1258 MAC2STR(wpa_s->own_addr));
1259 if (ret < 0 || ret >= end - pos)
1264 if (wpa_s->current_bss &&
1265 wpa_bss_get_vendor_ie(wpa_s->current_bss, HS20_IE_VENDOR_TYPE) &&
1266 wpa_s->wpa_proto == WPA_PROTO_RSN &&
1267 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1268 ret = os_snprintf(pos, end - pos, "hs20=1\n");
1269 if (ret < 0 || ret >= end - pos)
1273 #endif /* CONFIG_HS20 */
1275 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
1276 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
1277 res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos,
1283 res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose);
1291 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s,
1296 struct wpa_ssid *ssid;
1299 /* cmd: "<network id> <BSSID>" */
1300 pos = os_strchr(cmd, ' ');
1305 wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos);
1306 if (hwaddr_aton(pos, bssid)) {
1307 wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos);
1311 ssid = wpa_config_get_network(wpa_s->conf, id);
1313 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
1318 os_memcpy(ssid->bssid, bssid, ETH_ALEN);
1319 ssid->bssid_set = !is_zero_ether_addr(bssid);
1325 static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant *wpa_s,
1326 char *cmd, char *buf,
1330 struct wpa_blacklist *e;
1334 /* cmd: "BLACKLIST [<BSSID>]" */
1338 e = wpa_s->blacklist;
1340 ret = os_snprintf(pos, end - pos, MACSTR "\n",
1342 if (ret < 0 || ret >= end - pos)
1351 if (os_strncmp(cmd, "clear", 5) == 0) {
1352 wpa_blacklist_clear(wpa_s);
1353 os_memcpy(buf, "OK\n", 3);
1357 wpa_printf(MSG_DEBUG, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd);
1358 if (hwaddr_aton(cmd, bssid)) {
1359 wpa_printf(MSG_DEBUG, "CTRL_IFACE: invalid BSSID '%s'", cmd);
1364 * Add the BSSID twice, so its count will be 2, causing it to be
1365 * skipped when processing scan results.
1367 ret = wpa_blacklist_add(wpa_s, bssid);
1370 ret = wpa_blacklist_add(wpa_s, bssid);
1373 os_memcpy(buf, "OK\n", 3);
1378 extern int wpa_debug_level;
1379 extern int wpa_debug_timestamp;
1381 static const char * debug_level_str(int level)
1402 static int str_to_debug_level(const char *s)
1404 if (os_strcasecmp(s, "EXCESSIVE") == 0)
1405 return MSG_EXCESSIVE;
1406 if (os_strcasecmp(s, "MSGDUMP") == 0)
1408 if (os_strcasecmp(s, "DEBUG") == 0)
1410 if (os_strcasecmp(s, "INFO") == 0)
1412 if (os_strcasecmp(s, "WARNING") == 0)
1414 if (os_strcasecmp(s, "ERROR") == 0)
1420 static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant *wpa_s,
1421 char *cmd, char *buf,
1424 char *pos, *end, *stamp;
1431 /* cmd: "LOG_LEVEL [<level>]" */
1435 ret = os_snprintf(pos, end - pos, "Current level: %s\n"
1437 debug_level_str(wpa_debug_level),
1438 wpa_debug_timestamp);
1439 if (ret < 0 || ret >= end - pos)
1448 stamp = os_strchr(cmd, ' ');
1451 while (*stamp == ' ') {
1456 if (cmd && os_strlen(cmd)) {
1457 int level = str_to_debug_level(cmd);
1460 wpa_debug_level = level;
1463 if (stamp && os_strlen(stamp))
1464 wpa_debug_timestamp = atoi(stamp);
1466 os_memcpy(buf, "OK\n", 3);
1471 static int wpa_supplicant_ctrl_iface_list_networks(
1472 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
1475 struct wpa_ssid *ssid;
1480 ret = os_snprintf(pos, end - pos,
1481 "network id / ssid / bssid / flags\n");
1482 if (ret < 0 || ret >= end - pos)
1486 ssid = wpa_s->conf->ssid;
1488 ret = os_snprintf(pos, end - pos, "%d\t%s",
1490 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
1491 if (ret < 0 || ret >= end - pos)
1494 if (ssid->bssid_set) {
1495 ret = os_snprintf(pos, end - pos, "\t" MACSTR,
1496 MAC2STR(ssid->bssid));
1498 ret = os_snprintf(pos, end - pos, "\tany");
1500 if (ret < 0 || ret >= end - pos)
1503 ret = os_snprintf(pos, end - pos, "\t%s%s%s%s",
1504 ssid == wpa_s->current_ssid ?
1506 ssid->disabled ? "[DISABLED]" : "",
1507 ssid->disabled_until.sec ?
1508 "[TEMP-DISABLED]" : "",
1509 ssid->disabled == 2 ? "[P2P-PERSISTENT]" :
1511 if (ret < 0 || ret >= end - pos)
1514 ret = os_snprintf(pos, end - pos, "\n");
1515 if (ret < 0 || ret >= end - pos)
1526 static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher)
1529 ret = os_snprintf(pos, end - pos, "-");
1530 if (ret < 0 || ret >= end - pos)
1533 if (cipher & WPA_CIPHER_NONE) {
1534 ret = os_snprintf(pos, end - pos, "%sNONE", first ? "" : "+");
1535 if (ret < 0 || ret >= end - pos)
1540 if (cipher & WPA_CIPHER_WEP40) {
1541 ret = os_snprintf(pos, end - pos, "%sWEP40", first ? "" : "+");
1542 if (ret < 0 || ret >= end - pos)
1547 if (cipher & WPA_CIPHER_WEP104) {
1548 ret = os_snprintf(pos, end - pos, "%sWEP104",
1550 if (ret < 0 || ret >= end - pos)
1555 if (cipher & WPA_CIPHER_TKIP) {
1556 ret = os_snprintf(pos, end - pos, "%sTKIP", first ? "" : "+");
1557 if (ret < 0 || ret >= end - pos)
1562 if (cipher & WPA_CIPHER_CCMP) {
1563 ret = os_snprintf(pos, end - pos, "%sCCMP", first ? "" : "+");
1564 if (ret < 0 || ret >= end - pos)
1569 if (cipher & WPA_CIPHER_GCMP) {
1570 ret = os_snprintf(pos, end - pos, "%sGCMP", first ? "" : "+");
1571 if (ret < 0 || ret >= end - pos)
1580 static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
1581 const u8 *ie, size_t ie_len)
1583 struct wpa_ie_data data;
1586 ret = os_snprintf(pos, end - pos, "[%s-", proto);
1587 if (ret < 0 || ret >= end - pos)
1591 if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) {
1592 ret = os_snprintf(pos, end - pos, "?]");
1593 if (ret < 0 || ret >= end - pos)
1600 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
1601 ret = os_snprintf(pos, end - pos, "%sEAP", first ? "" : "+");
1602 if (ret < 0 || ret >= end - pos)
1607 if (data.key_mgmt & WPA_KEY_MGMT_PSK) {
1608 ret = os_snprintf(pos, end - pos, "%sPSK", first ? "" : "+");
1609 if (ret < 0 || ret >= end - pos)
1614 if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
1615 ret = os_snprintf(pos, end - pos, "%sNone", first ? "" : "+");
1616 if (ret < 0 || ret >= end - pos)
1621 #ifdef CONFIG_IEEE80211R
1622 if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
1623 ret = os_snprintf(pos, end - pos, "%sFT/EAP",
1625 if (ret < 0 || ret >= end - pos)
1630 if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) {
1631 ret = os_snprintf(pos, end - pos, "%sFT/PSK",
1633 if (ret < 0 || ret >= end - pos)
1638 #endif /* CONFIG_IEEE80211R */
1639 #ifdef CONFIG_IEEE80211W
1640 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
1641 ret = os_snprintf(pos, end - pos, "%sEAP-SHA256",
1643 if (ret < 0 || ret >= end - pos)
1648 if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
1649 ret = os_snprintf(pos, end - pos, "%sPSK-SHA256",
1651 if (ret < 0 || ret >= end - pos)
1656 #endif /* CONFIG_IEEE80211W */
1658 pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher);
1660 if (data.capabilities & WPA_CAPABILITY_PREAUTH) {
1661 ret = os_snprintf(pos, end - pos, "-preauth");
1662 if (ret < 0 || ret >= end - pos)
1667 ret = os_snprintf(pos, end - pos, "]");
1668 if (ret < 0 || ret >= end - pos)
1677 static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s,
1678 char *pos, char *end,
1679 struct wpabuf *wps_ie)
1686 if (wps_is_selected_pbc_registrar(wps_ie))
1689 else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0))
1691 #endif /* CONFIG_WPS2 */
1692 else if (wps_is_selected_pin_registrar(wps_ie))
1697 ret = os_snprintf(pos, end - pos, "%s", txt);
1698 if (ret >= 0 && ret < end - pos)
1700 wpabuf_free(wps_ie);
1703 #endif /* CONFIG_WPS */
1706 static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s,
1707 char *pos, char *end,
1708 const struct wpa_bss *bss)
1711 struct wpabuf *wps_ie;
1712 wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
1713 return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie);
1714 #else /* CONFIG_WPS */
1716 #endif /* CONFIG_WPS */
1720 /* Format one result on one text line into a buffer. */
1721 static int wpa_supplicant_ctrl_iface_scan_result(
1722 struct wpa_supplicant *wpa_s,
1723 const struct wpa_bss *bss, char *buf, size_t buflen)
1727 const u8 *ie, *ie2, *p2p;
1729 p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
1730 if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN &&
1731 os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) ==
1733 return 0; /* Do not show P2P listen discovery results here */
1738 ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t",
1739 MAC2STR(bss->bssid), bss->freq, bss->level);
1740 if (ret < 0 || ret >= end - pos)
1743 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
1745 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]);
1746 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
1748 pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2, 2 + ie2[1]);
1749 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
1750 if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
1751 ret = os_snprintf(pos, end - pos, "[WEP]");
1752 if (ret < 0 || ret >= end - pos)
1756 if (bss->caps & IEEE80211_CAP_IBSS) {
1757 ret = os_snprintf(pos, end - pos, "[IBSS]");
1758 if (ret < 0 || ret >= end - pos)
1762 if (bss->caps & IEEE80211_CAP_ESS) {
1763 ret = os_snprintf(pos, end - pos, "[ESS]");
1764 if (ret < 0 || ret >= end - pos)
1769 ret = os_snprintf(pos, end - pos, "[P2P]");
1770 if (ret < 0 || ret >= end - pos)
1775 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE) && ie2) {
1776 ret = os_snprintf(pos, end - pos, "[HS20]");
1777 if (ret < 0 || ret >= end - pos)
1781 #endif /* CONFIG_HS20 */
1783 ret = os_snprintf(pos, end - pos, "\t%s",
1784 wpa_ssid_txt(bss->ssid, bss->ssid_len));
1785 if (ret < 0 || ret >= end - pos)
1789 ret = os_snprintf(pos, end - pos, "\n");
1790 if (ret < 0 || ret >= end - pos)
1798 static int wpa_supplicant_ctrl_iface_scan_results(
1799 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
1802 struct wpa_bss *bss;
1807 ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / "
1809 if (ret < 0 || ret >= end - pos)
1813 dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
1814 ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos,
1816 if (ret < 0 || ret >= end - pos)
1825 static int wpa_supplicant_ctrl_iface_select_network(
1826 struct wpa_supplicant *wpa_s, char *cmd)
1829 struct wpa_ssid *ssid;
1831 /* cmd: "<network id>" or "any" */
1832 if (os_strcmp(cmd, "any") == 0) {
1833 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any");
1837 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id);
1839 ssid = wpa_config_get_network(wpa_s->conf, id);
1841 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
1842 "network id=%d", id);
1845 if (ssid->disabled == 2) {
1846 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
1847 "SELECT_NETWORK with persistent P2P group");
1852 wpa_supplicant_select_network(wpa_s, ssid);
1858 static int wpa_supplicant_ctrl_iface_enable_network(
1859 struct wpa_supplicant *wpa_s, char *cmd)
1862 struct wpa_ssid *ssid;
1864 /* cmd: "<network id>" or "all" */
1865 if (os_strcmp(cmd, "all") == 0) {
1866 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all");
1870 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id);
1872 ssid = wpa_config_get_network(wpa_s->conf, id);
1874 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
1875 "network id=%d", id);
1878 if (ssid->disabled == 2) {
1879 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
1880 "ENABLE_NETWORK with persistent P2P group");
1884 if (os_strstr(cmd, " no-connect")) {
1889 wpa_supplicant_enable_network(wpa_s, ssid);
1895 static int wpa_supplicant_ctrl_iface_disable_network(
1896 struct wpa_supplicant *wpa_s, char *cmd)
1899 struct wpa_ssid *ssid;
1901 /* cmd: "<network id>" or "all" */
1902 if (os_strcmp(cmd, "all") == 0) {
1903 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all");
1907 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id);
1909 ssid = wpa_config_get_network(wpa_s->conf, id);
1911 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
1912 "network id=%d", id);
1915 if (ssid->disabled == 2) {
1916 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
1917 "DISABLE_NETWORK with persistent P2P "
1922 wpa_supplicant_disable_network(wpa_s, ssid);
1928 static int wpa_supplicant_ctrl_iface_add_network(
1929 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
1931 struct wpa_ssid *ssid;
1934 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK");
1936 ssid = wpa_config_add_network(wpa_s->conf);
1940 wpas_notify_network_added(wpa_s, ssid);
1943 wpa_config_set_network_defaults(ssid);
1945 ret = os_snprintf(buf, buflen, "%d\n", ssid->id);
1946 if (ret < 0 || (size_t) ret >= buflen)
1952 static int wpa_supplicant_ctrl_iface_remove_network(
1953 struct wpa_supplicant *wpa_s, char *cmd)
1956 struct wpa_ssid *ssid;
1958 /* cmd: "<network id>" or "all" */
1959 if (os_strcmp(cmd, "all") == 0) {
1960 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all");
1961 ssid = wpa_s->conf->ssid;
1963 struct wpa_ssid *remove_ssid = ssid;
1966 wpas_notify_network_removed(wpa_s, remove_ssid);
1967 wpa_config_remove_network(wpa_s->conf, id);
1969 eapol_sm_invalidate_cached_session(wpa_s->eapol);
1970 if (wpa_s->current_ssid) {
1972 wpa_s->sme.prev_bssid_set = 0;
1973 #endif /* CONFIG_SME */
1974 wpa_sm_set_config(wpa_s->wpa, NULL);
1975 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
1976 wpa_supplicant_disassociate(wpa_s,
1977 WLAN_REASON_DEAUTH_LEAVING);
1983 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id);
1985 ssid = wpa_config_get_network(wpa_s->conf, id);
1987 wpas_notify_network_removed(wpa_s, ssid);
1989 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
1994 if (ssid == wpa_s->current_ssid || wpa_s->current_ssid == NULL) {
1996 wpa_s->sme.prev_bssid_set = 0;
1997 #endif /* CONFIG_SME */
1999 * Invalidate the EAP session cache if the current or
2000 * previously used network is removed.
2002 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2005 if (ssid == wpa_s->current_ssid) {
2006 wpa_sm_set_config(wpa_s->wpa, NULL);
2007 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
2009 wpa_supplicant_disassociate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2012 if (wpa_config_remove_network(wpa_s->conf, id) < 0) {
2013 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Not able to remove the "
2014 "network id=%d", id);
2022 static int wpa_supplicant_ctrl_iface_set_network(
2023 struct wpa_supplicant *wpa_s, char *cmd)
2026 struct wpa_ssid *ssid;
2029 /* cmd: "<network id> <variable name> <value>" */
2030 name = os_strchr(cmd, ' ');
2035 value = os_strchr(name, ' ');
2041 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
2043 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
2044 (u8 *) value, os_strlen(value));
2046 ssid = wpa_config_get_network(wpa_s->conf, id);
2048 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2053 if (wpa_config_set(ssid, name, value, 0) < 0) {
2054 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network "
2055 "variable '%s'", name);
2059 wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
2061 if (wpa_s->current_ssid == ssid || wpa_s->current_ssid == NULL) {
2063 * Invalidate the EAP session cache if anything in the current
2064 * or previously used configuration changes.
2066 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2069 if ((os_strcmp(name, "psk") == 0 &&
2070 value[0] == '"' && ssid->ssid_len) ||
2071 (os_strcmp(name, "ssid") == 0 && ssid->passphrase))
2072 wpa_config_update_psk(ssid);
2073 else if (os_strcmp(name, "priority") == 0)
2074 wpa_config_update_prio_list(wpa_s->conf);
2080 static int wpa_supplicant_ctrl_iface_get_network(
2081 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
2085 struct wpa_ssid *ssid;
2088 /* cmd: "<network id> <variable name>" */
2089 name = os_strchr(cmd, ' ');
2090 if (name == NULL || buflen == 0)
2095 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
2098 ssid = wpa_config_get_network(wpa_s->conf, id);
2100 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2105 value = wpa_config_get_no_key(ssid, name);
2106 if (value == NULL) {
2107 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
2108 "variable '%s'", name);
2112 res = os_strlcpy(buf, value, buflen);
2113 if (res >= buflen) {
2124 static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant *wpa_s,
2125 char *buf, size_t buflen)
2128 struct wpa_cred *cred;
2133 ret = os_snprintf(pos, end - pos,
2134 "cred id / realm / username / domain / imsi\n");
2135 if (ret < 0 || ret >= end - pos)
2139 cred = wpa_s->conf->cred;
2141 ret = os_snprintf(pos, end - pos, "%d\t%s\t%s\t%s\t%s\n",
2142 cred->id, cred->realm ? cred->realm : "",
2143 cred->username ? cred->username : "",
2144 cred->domain ? cred->domain : "",
2145 cred->imsi ? cred->imsi : "");
2146 if (ret < 0 || ret >= end - pos)
2157 static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant *wpa_s,
2158 char *buf, size_t buflen)
2160 struct wpa_cred *cred;
2163 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_CRED");
2165 cred = wpa_config_add_cred(wpa_s->conf);
2169 ret = os_snprintf(buf, buflen, "%d\n", cred->id);
2170 if (ret < 0 || (size_t) ret >= buflen)
2176 static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s,
2180 struct wpa_cred *cred;
2182 /* cmd: "<cred id>" or "all" */
2183 if (os_strcmp(cmd, "all") == 0) {
2184 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED all");
2185 cred = wpa_s->conf->cred;
2189 wpa_config_remove_cred(wpa_s->conf, id);
2195 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED id=%d", id);
2197 cred = wpa_config_get_cred(wpa_s->conf, id);
2199 wpa_config_remove_cred(wpa_s->conf, id) < 0) {
2200 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
2209 static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant *wpa_s,
2213 struct wpa_cred *cred;
2216 /* cmd: "<cred id> <variable name> <value>" */
2217 name = os_strchr(cmd, ' ');
2222 value = os_strchr(name, ' ');
2228 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_CRED id=%d name='%s'",
2230 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
2231 (u8 *) value, os_strlen(value));
2233 cred = wpa_config_get_cred(wpa_s->conf, id);
2235 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
2240 if (wpa_config_set_cred(cred, name, value, 0) < 0) {
2241 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set cred "
2242 "variable '%s'", name);
2250 #ifndef CONFIG_NO_CONFIG_WRITE
2251 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s)
2255 if (!wpa_s->conf->update_config) {
2256 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
2257 "to update configuration (update_config=0)");
2261 ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
2263 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to "
2264 "update configuration");
2266 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration"
2272 #endif /* CONFIG_NO_CONFIG_WRITE */
2275 static int ctrl_iface_get_capability_pairwise(int res, char *strict,
2276 struct wpa_driver_capa *capa,
2277 char *buf, size_t buflen)
2289 len = os_strlcpy(buf, "CCMP TKIP NONE", buflen);
2295 if (capa->enc & WPA_DRIVER_CAPA_ENC_CCMP) {
2296 ret = os_snprintf(pos, end - pos, "%sCCMP", first ? "" : " ");
2297 if (ret < 0 || ret >= end - pos)
2303 if (capa->enc & WPA_DRIVER_CAPA_ENC_GCMP) {
2304 ret = os_snprintf(pos, end - pos, "%sGCMP", first ? "" : " ");
2305 if (ret < 0 || ret >= end - pos)
2311 if (capa->enc & WPA_DRIVER_CAPA_ENC_TKIP) {
2312 ret = os_snprintf(pos, end - pos, "%sTKIP", first ? "" : " ");
2313 if (ret < 0 || ret >= end - pos)
2319 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
2320 ret = os_snprintf(pos, end - pos, "%sNONE", first ? "" : " ");
2321 if (ret < 0 || ret >= end - pos)
2331 static int ctrl_iface_get_capability_group(int res, char *strict,
2332 struct wpa_driver_capa *capa,
2333 char *buf, size_t buflen)
2345 len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen);
2351 if (capa->enc & WPA_DRIVER_CAPA_ENC_CCMP) {
2352 ret = os_snprintf(pos, end - pos, "%sCCMP", first ? "" : " ");
2353 if (ret < 0 || ret >= end - pos)
2359 if (capa->enc & WPA_DRIVER_CAPA_ENC_GCMP) {
2360 ret = os_snprintf(pos, end - pos, "%sGCMP", first ? "" : " ");
2361 if (ret < 0 || ret >= end - pos)
2367 if (capa->enc & WPA_DRIVER_CAPA_ENC_TKIP) {
2368 ret = os_snprintf(pos, end - pos, "%sTKIP", first ? "" : " ");
2369 if (ret < 0 || ret >= end - pos)
2375 if (capa->enc & WPA_DRIVER_CAPA_ENC_WEP104) {
2376 ret = os_snprintf(pos, end - pos, "%sWEP104",
2378 if (ret < 0 || ret >= end - pos)
2384 if (capa->enc & WPA_DRIVER_CAPA_ENC_WEP40) {
2385 ret = os_snprintf(pos, end - pos, "%sWEP40", first ? "" : " ");
2386 if (ret < 0 || ret >= end - pos)
2396 static int ctrl_iface_get_capability_key_mgmt(int res, char *strict,
2397 struct wpa_driver_capa *capa,
2398 char *buf, size_t buflen)
2410 len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
2417 ret = os_snprintf(pos, end - pos, "NONE IEEE8021X");
2418 if (ret < 0 || ret >= end - pos)
2422 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
2423 WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
2424 ret = os_snprintf(pos, end - pos, " WPA-EAP");
2425 if (ret < 0 || ret >= end - pos)
2430 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
2431 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
2432 ret = os_snprintf(pos, end - pos, " WPA-PSK");
2433 if (ret < 0 || ret >= end - pos)
2438 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
2439 ret = os_snprintf(pos, end - pos, " WPA-NONE");
2440 if (ret < 0 || ret >= end - pos)
2449 static int ctrl_iface_get_capability_proto(int res, char *strict,
2450 struct wpa_driver_capa *capa,
2451 char *buf, size_t buflen)
2463 len = os_strlcpy(buf, "RSN WPA", buflen);
2469 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
2470 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
2471 ret = os_snprintf(pos, end - pos, "%sRSN", first ? "" : " ");
2472 if (ret < 0 || ret >= end - pos)
2478 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
2479 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
2480 ret = os_snprintf(pos, end - pos, "%sWPA", first ? "" : " ");
2481 if (ret < 0 || ret >= end - pos)
2491 static int ctrl_iface_get_capability_auth_alg(int res, char *strict,
2492 struct wpa_driver_capa *capa,
2493 char *buf, size_t buflen)
2505 len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen);
2511 if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) {
2512 ret = os_snprintf(pos, end - pos, "%sOPEN", first ? "" : " ");
2513 if (ret < 0 || ret >= end - pos)
2519 if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) {
2520 ret = os_snprintf(pos, end - pos, "%sSHARED",
2522 if (ret < 0 || ret >= end - pos)
2528 if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) {
2529 ret = os_snprintf(pos, end - pos, "%sLEAP", first ? "" : " ");
2530 if (ret < 0 || ret >= end - pos)
2540 static int ctrl_iface_get_capability_channels(struct wpa_supplicant *wpa_s,
2541 char *buf, size_t buflen)
2543 struct hostapd_channel_data *chnl;
2545 char *pos, *end, *hmode;
2550 for (j = 0; j < wpa_s->hw.num_modes; j++) {
2551 switch (wpa_s->hw.modes[j].mode) {
2552 case HOSTAPD_MODE_IEEE80211B:
2555 case HOSTAPD_MODE_IEEE80211G:
2558 case HOSTAPD_MODE_IEEE80211A:
2564 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:", hmode);
2565 if (ret < 0 || ret >= end - pos)
2568 chnl = wpa_s->hw.modes[j].channels;
2569 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
2570 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
2572 ret = os_snprintf(pos, end - pos, " %d", chnl[i].chan);
2573 if (ret < 0 || ret >= end - pos)
2577 ret = os_snprintf(pos, end - pos, "\n");
2578 if (ret < 0 || ret >= end - pos)
2587 static int wpa_supplicant_ctrl_iface_get_capability(
2588 struct wpa_supplicant *wpa_s, const char *_field, char *buf,
2591 struct wpa_driver_capa capa;
2597 /* Determine whether or not strict checking was requested */
2598 len = os_strlcpy(field, _field, sizeof(field));
2599 if (len >= sizeof(field))
2601 strict = os_strchr(field, ' ');
2602 if (strict != NULL) {
2604 if (os_strcmp(strict, "strict") != 0)
2608 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
2609 field, strict ? strict : "");
2611 if (os_strcmp(field, "eap") == 0) {
2612 return eap_get_names(buf, buflen);
2615 res = wpa_drv_get_capa(wpa_s, &capa);
2617 if (os_strcmp(field, "pairwise") == 0)
2618 return ctrl_iface_get_capability_pairwise(res, strict, &capa,
2621 if (os_strcmp(field, "group") == 0)
2622 return ctrl_iface_get_capability_group(res, strict, &capa,
2625 if (os_strcmp(field, "key_mgmt") == 0)
2626 return ctrl_iface_get_capability_key_mgmt(res, strict, &capa,
2629 if (os_strcmp(field, "proto") == 0)
2630 return ctrl_iface_get_capability_proto(res, strict, &capa,
2633 if (os_strcmp(field, "auth_alg") == 0)
2634 return ctrl_iface_get_capability_auth_alg(res, strict, &capa,
2637 if (os_strcmp(field, "channels") == 0)
2638 return ctrl_iface_get_capability_channels(wpa_s, buf, buflen);
2640 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
2647 #ifdef CONFIG_INTERWORKING
2648 static char * anqp_add_hex(char *pos, char *end, const char *title,
2649 struct wpabuf *data)
2659 ret = os_snprintf(pos, end - pos, "%s=", title);
2660 if (ret < 0 || ret >= end - pos)
2664 d = wpabuf_head_u8(data);
2665 for (i = 0; i < wpabuf_len(data); i++) {
2666 ret = os_snprintf(pos, end - pos, "%02x", *d++);
2667 if (ret < 0 || ret >= end - pos)
2672 ret = os_snprintf(pos, end - pos, "\n");
2673 if (ret < 0 || ret >= end - pos)
2679 #endif /* CONFIG_INTERWORKING */
2682 static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
2683 unsigned long mask, char *buf, size_t buflen)
2693 if (mask & WPA_BSS_MASK_ID) {
2694 ret = os_snprintf(pos, end - pos, "id=%u\n", bss->id);
2695 if (ret < 0 || ret >= end - pos)
2700 if (mask & WPA_BSS_MASK_BSSID) {
2701 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
2702 MAC2STR(bss->bssid));
2703 if (ret < 0 || ret >= end - pos)
2708 if (mask & WPA_BSS_MASK_FREQ) {
2709 ret = os_snprintf(pos, end - pos, "freq=%d\n", bss->freq);
2710 if (ret < 0 || ret >= end - pos)
2715 if (mask & WPA_BSS_MASK_BEACON_INT) {
2716 ret = os_snprintf(pos, end - pos, "beacon_int=%d\n",
2718 if (ret < 0 || ret >= end - pos)
2723 if (mask & WPA_BSS_MASK_CAPABILITIES) {
2724 ret = os_snprintf(pos, end - pos, "capabilities=0x%04x\n",
2726 if (ret < 0 || ret >= end - pos)
2731 if (mask & WPA_BSS_MASK_QUAL) {
2732 ret = os_snprintf(pos, end - pos, "qual=%d\n", bss->qual);
2733 if (ret < 0 || ret >= end - pos)
2738 if (mask & WPA_BSS_MASK_NOISE) {
2739 ret = os_snprintf(pos, end - pos, "noise=%d\n", bss->noise);
2740 if (ret < 0 || ret >= end - pos)
2745 if (mask & WPA_BSS_MASK_LEVEL) {
2746 ret = os_snprintf(pos, end - pos, "level=%d\n", bss->level);
2747 if (ret < 0 || ret >= end - pos)
2752 if (mask & WPA_BSS_MASK_TSF) {
2753 ret = os_snprintf(pos, end - pos, "tsf=%016llu\n",
2754 (unsigned long long) bss->tsf);
2755 if (ret < 0 || ret >= end - pos)
2760 if (mask & WPA_BSS_MASK_AGE) {
2764 ret = os_snprintf(pos, end - pos, "age=%d\n",
2765 (int) (now.sec - bss->last_update.sec));
2766 if (ret < 0 || ret >= end - pos)
2771 if (mask & WPA_BSS_MASK_IE) {
2772 ret = os_snprintf(pos, end - pos, "ie=");
2773 if (ret < 0 || ret >= end - pos)
2777 ie = (const u8 *) (bss + 1);
2778 for (i = 0; i < bss->ie_len; i++) {
2779 ret = os_snprintf(pos, end - pos, "%02x", *ie++);
2780 if (ret < 0 || ret >= end - pos)
2785 ret = os_snprintf(pos, end - pos, "\n");
2786 if (ret < 0 || ret >= end - pos)
2791 if (mask & WPA_BSS_MASK_FLAGS) {
2792 ret = os_snprintf(pos, end - pos, "flags=");
2793 if (ret < 0 || ret >= end - pos)
2797 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
2799 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie,
2801 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
2803 pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2,
2805 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
2806 if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
2807 ret = os_snprintf(pos, end - pos, "[WEP]");
2808 if (ret < 0 || ret >= end - pos)
2812 if (bss->caps & IEEE80211_CAP_IBSS) {
2813 ret = os_snprintf(pos, end - pos, "[IBSS]");
2814 if (ret < 0 || ret >= end - pos)
2818 if (bss->caps & IEEE80211_CAP_ESS) {
2819 ret = os_snprintf(pos, end - pos, "[ESS]");
2820 if (ret < 0 || ret >= end - pos)
2824 if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE)) {
2825 ret = os_snprintf(pos, end - pos, "[P2P]");
2826 if (ret < 0 || ret >= end - pos)
2831 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) {
2832 ret = os_snprintf(pos, end - pos, "[HS20]");
2833 if (ret < 0 || ret >= end - pos)
2837 #endif /* CONFIG_HS20 */
2839 ret = os_snprintf(pos, end - pos, "\n");
2840 if (ret < 0 || ret >= end - pos)
2845 if (mask & WPA_BSS_MASK_SSID) {
2846 ret = os_snprintf(pos, end - pos, "ssid=%s\n",
2847 wpa_ssid_txt(bss->ssid, bss->ssid_len));
2848 if (ret < 0 || ret >= end - pos)
2854 if (mask & WPA_BSS_MASK_WPS_SCAN) {
2855 ie = (const u8 *) (bss + 1);
2856 ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end);
2857 if (ret < 0 || ret >= end - pos)
2861 #endif /* CONFIG_WPS */
2864 if (mask & WPA_BSS_MASK_P2P_SCAN) {
2865 ie = (const u8 *) (bss + 1);
2866 ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end);
2867 if (ret < 0 || ret >= end - pos)
2871 #endif /* CONFIG_P2P */
2873 #ifdef CONFIG_WIFI_DISPLAY
2874 if (mask & WPA_BSS_MASK_WIFI_DISPLAY) {
2876 ie = (const u8 *) (bss + 1);
2877 wfd = ieee802_11_vendor_ie_concat(ie, bss->ie_len,
2878 WFD_IE_VENDOR_TYPE);
2880 ret = os_snprintf(pos, end - pos, "wfd_subelems=");
2881 if (ret < 0 || ret >= end - pos)
2885 pos += wpa_snprintf_hex(pos, end - pos,
2890 ret = os_snprintf(pos, end - pos, "\n");
2891 if (ret < 0 || ret >= end - pos)
2896 #endif /* CONFIG_WIFI_DISPLAY */
2898 #ifdef CONFIG_INTERWORKING
2899 if ((mask & WPA_BSS_MASK_INTERNETW) && bss->anqp) {
2900 struct wpa_bss_anqp *anqp = bss->anqp;
2901 pos = anqp_add_hex(pos, end, "anqp_venue_name",
2903 pos = anqp_add_hex(pos, end, "anqp_network_auth_type",
2904 anqp->network_auth_type);
2905 pos = anqp_add_hex(pos, end, "anqp_roaming_consortium",
2906 anqp->roaming_consortium);
2907 pos = anqp_add_hex(pos, end, "anqp_ip_addr_type_availability",
2908 anqp->ip_addr_type_availability);
2909 pos = anqp_add_hex(pos, end, "anqp_nai_realm",
2911 pos = anqp_add_hex(pos, end, "anqp_3gpp", anqp->anqp_3gpp);
2912 pos = anqp_add_hex(pos, end, "anqp_domain_name",
2915 pos = anqp_add_hex(pos, end, "hs20_operator_friendly_name",
2916 anqp->hs20_operator_friendly_name);
2917 pos = anqp_add_hex(pos, end, "hs20_wan_metrics",
2918 anqp->hs20_wan_metrics);
2919 pos = anqp_add_hex(pos, end, "hs20_connection_capability",
2920 anqp->hs20_connection_capability);
2921 #endif /* CONFIG_HS20 */
2923 #endif /* CONFIG_INTERWORKING */
2929 static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
2930 const char *cmd, char *buf,
2935 struct wpa_bss *bss;
2936 struct wpa_bss *bsslast = NULL;
2937 struct dl_list *next;
2941 unsigned long mask = WPA_BSS_MASK_ALL;
2943 if (os_strncmp(cmd, "RANGE=", 6) == 0) {
2944 if (os_strncmp(cmd + 6, "ALL", 3) == 0) {
2945 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss,
2947 bsslast = dl_list_last(&wpa_s->bss_id, struct wpa_bss,
2949 } else { /* N1-N2 */
2950 unsigned int id1, id2;
2952 if ((ctmp = os_strchr(cmd + 6, '-')) == NULL) {
2953 wpa_printf(MSG_INFO, "Wrong BSS range "
2958 id1 = atoi(cmd + 6);
2959 bss = wpa_bss_get_id(wpa_s, id1);
2960 id2 = atoi(ctmp + 1);
2962 bsslast = dl_list_last(&wpa_s->bss_id,
2966 bsslast = wpa_bss_get_id(wpa_s, id2);
2967 if (bsslast == NULL && bss && id2 > id1) {
2968 struct wpa_bss *tmp = bss;
2970 next = tmp->list_id.next;
2971 if (next == &wpa_s->bss_id)
2973 tmp = dl_list_entry(
2974 next, struct wpa_bss,
2983 } else if (os_strcmp(cmd, "FIRST") == 0)
2984 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, list_id);
2985 else if (os_strncmp(cmd, "ID-", 3) == 0) {
2987 bss = wpa_bss_get_id(wpa_s, i);
2988 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
2990 bss = wpa_bss_get_id(wpa_s, i);
2992 next = bss->list_id.next;
2993 if (next == &wpa_s->bss_id)
2996 bss = dl_list_entry(next, struct wpa_bss,
3000 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
3001 if (hwaddr_aton(cmd + 13, bssid) == 0)
3002 bss = wpa_bss_get_p2p_dev_addr(wpa_s, bssid);
3005 #endif /* CONFIG_P2P */
3006 } else if (hwaddr_aton(cmd, bssid) == 0)
3007 bss = wpa_bss_get_bssid(wpa_s, bssid);
3009 struct wpa_bss *tmp;
3012 dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id)
3021 if ((ctmp = os_strstr(cmd, "MASK=")) != NULL) {
3022 mask = strtoul(ctmp + 5, NULL, 0x10);
3024 mask = WPA_BSS_MASK_ALL;
3030 if (bsslast == NULL)
3033 len = print_bss_info(wpa_s, bss, mask, buf, buflen);
3039 next = bss->list_id.next;
3040 if (next == &wpa_s->bss_id)
3042 bss = dl_list_entry(next, struct wpa_bss, list_id);
3043 } while (bss && len);
3049 static int wpa_supplicant_ctrl_iface_ap_scan(
3050 struct wpa_supplicant *wpa_s, char *cmd)
3052 int ap_scan = atoi(cmd);
3053 return wpa_supplicant_set_ap_scan(wpa_s, ap_scan);
3057 static int wpa_supplicant_ctrl_iface_scan_interval(
3058 struct wpa_supplicant *wpa_s, char *cmd)
3060 int scan_int = atoi(cmd);
3061 return wpa_supplicant_set_scan_interval(wpa_s, scan_int);
3065 static int wpa_supplicant_ctrl_iface_bss_expire_age(
3066 struct wpa_supplicant *wpa_s, char *cmd)
3068 int expire_age = atoi(cmd);
3069 return wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age);
3073 static int wpa_supplicant_ctrl_iface_bss_expire_count(
3074 struct wpa_supplicant *wpa_s, char *cmd)
3076 int expire_count = atoi(cmd);
3077 return wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count);
3081 static int wpa_supplicant_ctrl_iface_bss_flush(
3082 struct wpa_supplicant *wpa_s, char *cmd)
3084 int flush_age = atoi(cmd);
3087 wpa_bss_flush(wpa_s);
3089 wpa_bss_flush_by_age(wpa_s, flush_age);
3094 static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s)
3096 wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication");
3097 /* MLME-DELETEKEYS.request */
3098 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL, 0);
3099 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL, 0);
3100 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL, 0);
3101 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL, 0);
3102 #ifdef CONFIG_IEEE80211W
3103 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL, 0);
3104 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL, 0);
3105 #endif /* CONFIG_IEEE80211W */
3107 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, wpa_s->bssid, 0, 0, NULL, 0, NULL,
3109 /* MLME-SETPROTECTION.request(None) */
3110 wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid,
3111 MLME_SETPROTECTION_PROTECT_TYPE_NONE,
3112 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE);
3113 wpa_sm_drop_sa(wpa_s->wpa);
3117 static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s,
3120 #ifdef CONFIG_NO_SCAN_PROCESSING
3122 #else /* CONFIG_NO_SCAN_PROCESSING */
3124 struct wpa_bss *bss;
3125 struct wpa_ssid *ssid = wpa_s->current_ssid;
3127 if (hwaddr_aton(addr, bssid)) {
3128 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid "
3129 "address '%s'", addr);
3133 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR, MAC2STR(bssid));
3135 bss = wpa_bss_get_bssid(wpa_s, bssid);
3137 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found "
3143 * TODO: Find best network configuration block from configuration to
3144 * allow roaming to other networks
3148 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network "
3149 "configuration known for the target AP");
3153 wpa_s->reassociate = 1;
3154 wpa_supplicant_connect(wpa_s, bss, ssid);
3157 #endif /* CONFIG_NO_SCAN_PROCESSING */
3162 static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd)
3164 unsigned int timeout = atoi(cmd);
3165 enum p2p_discovery_type type = P2P_FIND_START_WITH_FULL;
3166 u8 dev_id[ETH_ALEN], *_dev_id = NULL;
3168 unsigned int search_delay;
3170 if (os_strstr(cmd, "type=social"))
3171 type = P2P_FIND_ONLY_SOCIAL;
3172 else if (os_strstr(cmd, "type=progressive"))
3173 type = P2P_FIND_PROGRESSIVE;
3175 pos = os_strstr(cmd, "dev_id=");
3178 if (hwaddr_aton(pos, dev_id))
3183 pos = os_strstr(cmd, "delay=");
3186 search_delay = atoi(pos);
3188 search_delay = wpas_p2p_search_delay(wpa_s);
3190 return wpas_p2p_find(wpa_s, timeout, type, 0, NULL, _dev_id,
3195 static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd,
3196 char *buf, size_t buflen)
3201 enum p2p_wps_method wps_method;
3204 int persistent_group, persistent_id = -1;
3213 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad]
3214 * [persistent|persistent=<network id>]
3215 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
3218 if (hwaddr_aton(cmd, addr))
3226 persistent_group = os_strstr(pos, " persistent") != NULL;
3227 pos2 = os_strstr(pos, " persistent=");
3229 struct wpa_ssid *ssid;
3230 persistent_id = atoi(pos2 + 12);
3231 ssid = wpa_config_get_network(wpa_s->conf, persistent_id);
3232 if (ssid == NULL || ssid->disabled != 2 ||
3233 ssid->mode != WPAS_MODE_P2P_GO) {
3234 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3235 "SSID id=%d for persistent P2P group (GO)",
3240 join = os_strstr(pos, " join") != NULL;
3241 auth = os_strstr(pos, " auth") != NULL;
3242 automatic = os_strstr(pos, " auto") != NULL;
3243 pd = os_strstr(pos, " provdisc") != NULL;
3244 ht40 = os_strstr(pos, " ht40") != NULL;
3246 pos2 = os_strstr(pos, " go_intent=");
3249 go_intent = atoi(pos2);
3250 if (go_intent < 0 || go_intent > 15)
3254 pos2 = os_strstr(pos, " freq=");
3262 if (os_strncmp(pos, "pin", 3) == 0) {
3263 /* Request random PIN (to be displayed) and enable the PIN */
3264 wps_method = WPS_PIN_DISPLAY;
3265 } else if (os_strncmp(pos, "pbc", 3) == 0) {
3266 wps_method = WPS_PBC;
3269 pos = os_strchr(pin, ' ');
3270 wps_method = WPS_PIN_KEYPAD;
3273 if (os_strncmp(pos, "display", 7) == 0)
3274 wps_method = WPS_PIN_DISPLAY;
3276 if (!wps_pin_str_valid(pin)) {
3277 os_memcpy(buf, "FAIL-INVALID-PIN\n", 17);
3282 new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method,
3283 persistent_group, automatic, join,
3284 auth, go_intent, freq, persistent_id, pd,
3286 if (new_pin == -2) {
3287 os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
3290 if (new_pin == -3) {
3291 os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
3296 if (wps_method == WPS_PIN_DISPLAY && pin == NULL) {
3297 ret = os_snprintf(buf, buflen, "%08d", new_pin);
3298 if (ret < 0 || (size_t) ret >= buflen)
3303 os_memcpy(buf, "OK\n", 3);
3308 static int p2p_ctrl_listen(struct wpa_supplicant *wpa_s, char *cmd)
3310 unsigned int timeout = atoi(cmd);
3311 return wpas_p2p_listen(wpa_s, timeout);
3315 static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd)
3319 enum wpas_p2p_prov_disc_use use = WPAS_P2P_PD_FOR_GO_NEG;
3321 /* <addr> <config method> [join|auto] */
3323 if (hwaddr_aton(cmd, addr))
3331 if (os_strstr(pos, " join") != NULL)
3332 use = WPAS_P2P_PD_FOR_JOIN;
3333 else if (os_strstr(pos, " auto") != NULL)
3334 use = WPAS_P2P_PD_AUTO;
3336 return wpas_p2p_prov_disc(wpa_s, addr, pos, use);
3340 static int p2p_get_passphrase(struct wpa_supplicant *wpa_s, char *buf,
3343 struct wpa_ssid *ssid = wpa_s->current_ssid;
3345 if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO ||
3346 ssid->passphrase == NULL)
3349 os_strlcpy(buf, ssid->passphrase, buflen);
3350 return os_strlen(buf);
3354 static int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd,
3355 char *buf, size_t buflen)
3359 u8 dst_buf[ETH_ALEN], *dst;
3360 struct wpabuf *tlvs;
3364 if (hwaddr_aton(cmd, dst_buf))
3367 if (dst[0] == 0 && dst[1] == 0 && dst[2] == 0 &&
3368 dst[3] == 0 && dst[4] == 0 && dst[5] == 0)
3375 if (os_strncmp(pos, "upnp ", 5) == 0) {
3378 if (hexstr2bin(pos, &version, 1) < 0)
3384 ref = wpas_p2p_sd_request_upnp(wpa_s, dst, version, pos);
3385 #ifdef CONFIG_WIFI_DISPLAY
3386 } else if (os_strncmp(pos, "wifi-display ", 13) == 0) {
3387 ref = wpas_p2p_sd_request_wifi_display(wpa_s, dst, pos + 13);
3388 #endif /* CONFIG_WIFI_DISPLAY */
3390 len = os_strlen(pos);
3394 tlvs = wpabuf_alloc(len);
3397 if (hexstr2bin(pos, wpabuf_put(tlvs, len), len) < 0) {
3402 ref = wpas_p2p_sd_request(wpa_s, dst, tlvs);
3407 res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref);
3408 if (res < 0 || (unsigned) res >= buflen)
3414 static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s,
3417 long long unsigned val;
3419 if (sscanf(cmd, "%llx", &val) != 1)
3422 return wpas_p2p_sd_cancel_request(wpa_s, req);
3426 static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant *wpa_s, char *cmd)
3431 struct wpabuf *resp_tlvs;
3435 pos = os_strchr(cmd, ' ');
3443 if (hwaddr_aton(pos, dst))
3450 pos2 = os_strchr(pos, ' ');
3454 dialog_token = atoi(pos);
3456 len = os_strlen(pos2);
3460 resp_tlvs = wpabuf_alloc(len);
3461 if (resp_tlvs == NULL)
3463 if (hexstr2bin(pos2, wpabuf_put(resp_tlvs, len), len) < 0) {
3464 wpabuf_free(resp_tlvs);
3468 wpas_p2p_sd_response(wpa_s, freq, dst, dialog_token, resp_tlvs);
3469 wpabuf_free(resp_tlvs);
3474 static int p2p_ctrl_serv_disc_external(struct wpa_supplicant *wpa_s,
3477 if (os_strcmp(cmd, "0") && os_strcmp(cmd, "1"))
3479 wpa_s->p2p_sd_over_ctrl_iface = atoi(cmd);
3484 static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant *wpa_s,
3489 struct wpabuf *query, *resp;
3491 pos = os_strchr(cmd, ' ');
3496 len = os_strlen(cmd);
3500 query = wpabuf_alloc(len);
3503 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
3508 len = os_strlen(pos);
3514 resp = wpabuf_alloc(len);
3519 if (hexstr2bin(pos, wpabuf_put(resp, len), len) < 0) {
3525 if (wpas_p2p_service_add_bonjour(wpa_s, query, resp) < 0) {
3534 static int p2p_ctrl_service_add_upnp(struct wpa_supplicant *wpa_s, char *cmd)
3539 pos = os_strchr(cmd, ' ');
3544 if (hexstr2bin(cmd, &version, 1) < 0)
3547 return wpas_p2p_service_add_upnp(wpa_s, version, pos);
3551 static int p2p_ctrl_service_add(struct wpa_supplicant *wpa_s, char *cmd)
3555 pos = os_strchr(cmd, ' ');
3560 if (os_strcmp(cmd, "bonjour") == 0)
3561 return p2p_ctrl_service_add_bonjour(wpa_s, pos);
3562 if (os_strcmp(cmd, "upnp") == 0)
3563 return p2p_ctrl_service_add_upnp(wpa_s, pos);
3564 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
3569 static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant *wpa_s,
3573 struct wpabuf *query;
3576 len = os_strlen(cmd);
3580 query = wpabuf_alloc(len);
3583 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
3588 ret = wpas_p2p_service_del_bonjour(wpa_s, query);
3594 static int p2p_ctrl_service_del_upnp(struct wpa_supplicant *wpa_s, char *cmd)
3599 pos = os_strchr(cmd, ' ');
3604 if (hexstr2bin(cmd, &version, 1) < 0)
3607 return wpas_p2p_service_del_upnp(wpa_s, version, pos);
3611 static int p2p_ctrl_service_del(struct wpa_supplicant *wpa_s, char *cmd)
3615 pos = os_strchr(cmd, ' ');
3620 if (os_strcmp(cmd, "bonjour") == 0)
3621 return p2p_ctrl_service_del_bonjour(wpa_s, pos);
3622 if (os_strcmp(cmd, "upnp") == 0)
3623 return p2p_ctrl_service_del_upnp(wpa_s, pos);
3624 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
3629 static int p2p_ctrl_reject(struct wpa_supplicant *wpa_s, char *cmd)
3635 if (hwaddr_aton(cmd, addr))
3638 return wpas_p2p_reject(wpa_s, addr);
3642 static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd)
3646 struct wpa_ssid *ssid;
3647 u8 *_peer = NULL, peer[ETH_ALEN];
3652 pos = os_strstr(cmd, " peer=");
3655 if (hwaddr_aton(pos, peer))
3659 ssid = wpa_config_get_network(wpa_s->conf, id);
3660 if (ssid == NULL || ssid->disabled != 2) {
3661 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
3662 "for persistent P2P group",
3667 pos = os_strstr(cmd, " freq=");
3675 ht40 = os_strstr(cmd, " ht40") != NULL;
3677 return wpas_p2p_invite(wpa_s, _peer, ssid, NULL, freq, ht40);
3681 static int p2p_ctrl_invite_group(struct wpa_supplicant *wpa_s, char *cmd)
3684 u8 peer[ETH_ALEN], go_dev_addr[ETH_ALEN], *go_dev = NULL;
3686 pos = os_strstr(cmd, " peer=");
3692 if (hwaddr_aton(pos, peer)) {
3693 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", pos);
3697 pos = os_strstr(pos, " go_dev_addr=");
3700 if (hwaddr_aton(pos, go_dev_addr)) {
3701 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'",
3705 go_dev = go_dev_addr;
3708 return wpas_p2p_invite_group(wpa_s, cmd, peer, go_dev);
3712 static int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd)
3714 if (os_strncmp(cmd, "persistent=", 11) == 0)
3715 return p2p_ctrl_invite_persistent(wpa_s, cmd + 11);
3716 if (os_strncmp(cmd, "group=", 6) == 0)
3717 return p2p_ctrl_invite_group(wpa_s, cmd + 6);
3723 static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s,
3724 char *cmd, int freq, int ht40)
3727 struct wpa_ssid *ssid;
3730 ssid = wpa_config_get_network(wpa_s->conf, id);
3731 if (ssid == NULL || ssid->disabled != 2) {
3732 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
3733 "for persistent P2P group",
3738 return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq, ht40);
3742 static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd)
3747 pos = os_strstr(cmd, "freq=");
3749 freq = atoi(pos + 5);
3751 ht40 = os_strstr(cmd, "ht40") != NULL;
3753 if (os_strncmp(cmd, "persistent=", 11) == 0)
3754 return p2p_ctrl_group_add_persistent(wpa_s, cmd + 11, freq,
3756 if (os_strcmp(cmd, "persistent") == 0 ||
3757 os_strncmp(cmd, "persistent ", 11) == 0)
3758 return wpas_p2p_group_add(wpa_s, 1, freq, ht40);
3759 if (os_strncmp(cmd, "freq=", 5) == 0)
3760 return wpas_p2p_group_add(wpa_s, 0, freq, ht40);
3762 return wpas_p2p_group_add(wpa_s, 0, freq, ht40);
3764 wpa_printf(MSG_DEBUG, "CTRL: Invalid P2P_GROUP_ADD parameters '%s'",
3770 static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd,
3771 char *buf, size_t buflen)
3773 u8 addr[ETH_ALEN], *addr_ptr;
3775 const struct p2p_peer_info *info;
3777 char devtype[WPS_DEV_TYPE_BUFSIZE];
3778 struct wpa_ssid *ssid;
3780 if (!wpa_s->global->p2p)
3783 if (os_strcmp(cmd, "FIRST") == 0) {
3786 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
3787 if (hwaddr_aton(cmd + 5, addr) < 0)
3792 if (hwaddr_aton(cmd, addr) < 0)
3798 info = p2p_get_peer_info(wpa_s->global->p2p, addr_ptr, next);
3805 res = os_snprintf(pos, end - pos, MACSTR "\n"
3811 "serial_number=%s\n"
3812 "config_methods=0x%x\n"
3814 "group_capab=0x%x\n"
3816 MAC2STR(info->p2p_device_addr),
3817 wps_dev_type_bin2str(info->pri_dev_type,
3818 devtype, sizeof(devtype)),
3823 info->serial_number,
3824 info->config_methods,
3828 if (res < 0 || res >= end - pos)
3832 ssid = wpas_p2p_get_persistent(wpa_s, info->p2p_device_addr, NULL, 0);
3834 res = os_snprintf(pos, end - pos, "persistent=%d\n", ssid->id);
3835 if (res < 0 || res >= end - pos)
3840 res = p2p_get_peer_info_txt(info, pos, end - pos);
3849 static int p2p_ctrl_disallow_freq(struct wpa_supplicant *wpa_s,
3852 struct wpa_freq_range *freq = NULL, *n;
3853 unsigned int count = 0, i;
3854 const char *pos, *pos2, *pos3;
3856 if (wpa_s->global->p2p == NULL)
3860 * param includes comma separated frequency range.
3861 * For example: 2412-2432,2462,5000-6000
3864 while (pos && pos[0]) {
3865 n = os_realloc_array(freq, count + 1,
3866 sizeof(struct wpa_freq_range));
3872 freq[count].min = atoi(pos);
3873 pos2 = os_strchr(pos, '-');
3874 pos3 = os_strchr(pos, ',');
3875 if (pos2 && (!pos3 || pos2 < pos3)) {
3877 freq[count].max = atoi(pos2);
3879 freq[count].max = freq[count].min;
3886 for (i = 0; i < count; i++) {
3887 wpa_printf(MSG_DEBUG, "P2P: Disallowed frequency range %u-%u",
3888 freq[i].min, freq[i].max);
3891 os_free(wpa_s->global->p2p_disallow_freq);
3892 wpa_s->global->p2p_disallow_freq = freq;
3893 wpa_s->global->num_p2p_disallow_freq = count;
3894 wpas_p2p_update_channel_list(wpa_s);
3899 static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd)
3903 if (wpa_s->global->p2p == NULL)
3906 param = os_strchr(cmd, ' ');
3911 if (os_strcmp(cmd, "discoverability") == 0) {
3912 p2p_set_client_discoverability(wpa_s->global->p2p,
3917 if (os_strcmp(cmd, "managed") == 0) {
3918 p2p_set_managed_oper(wpa_s->global->p2p, atoi(param));
3922 if (os_strcmp(cmd, "listen_channel") == 0) {
3923 return p2p_set_listen_channel(wpa_s->global->p2p, 81,
3927 if (os_strcmp(cmd, "ssid_postfix") == 0) {
3928 return p2p_set_ssid_postfix(wpa_s->global->p2p, (u8 *) param,
3932 if (os_strcmp(cmd, "noa") == 0) {
3934 int count, start, duration;
3935 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
3936 count = atoi(param);
3937 pos = os_strchr(param, ',');
3942 pos = os_strchr(pos, ',');
3946 duration = atoi(pos);
3947 if (count < 0 || count > 255 || start < 0 || duration < 0)
3949 if (count == 0 && duration > 0)
3951 wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
3952 "start=%d duration=%d", count, start, duration);
3953 return wpas_p2p_set_noa(wpa_s, count, start, duration);
3956 if (os_strcmp(cmd, "ps") == 0)
3957 return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1);
3959 if (os_strcmp(cmd, "oppps") == 0)
3960 return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1);
3962 if (os_strcmp(cmd, "ctwindow") == 0)
3963 return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param));
3965 if (os_strcmp(cmd, "disabled") == 0) {
3966 wpa_s->global->p2p_disabled = atoi(param);
3967 wpa_printf(MSG_DEBUG, "P2P functionality %s",
3968 wpa_s->global->p2p_disabled ?
3969 "disabled" : "enabled");
3970 if (wpa_s->global->p2p_disabled) {
3971 wpas_p2p_stop_find(wpa_s);
3972 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
3973 p2p_flush(wpa_s->global->p2p);
3978 if (os_strcmp(cmd, "conc_pref") == 0) {
3979 if (os_strcmp(param, "sta") == 0)
3980 wpa_s->global->conc_pref = WPA_CONC_PREF_STA;
3981 else if (os_strcmp(param, "p2p") == 0)
3982 wpa_s->global->conc_pref = WPA_CONC_PREF_P2P;
3984 wpa_printf(MSG_INFO, "Invalid conc_pref value");
3987 wpa_printf(MSG_DEBUG, "Single channel concurrency preference: "
3992 if (os_strcmp(cmd, "force_long_sd") == 0) {
3993 wpa_s->force_long_sd = atoi(param);
3997 if (os_strcmp(cmd, "peer_filter") == 0) {
3999 if (hwaddr_aton(param, addr))
4001 p2p_set_peer_filter(wpa_s->global->p2p, addr);
4005 if (os_strcmp(cmd, "cross_connect") == 0)
4006 return wpas_p2p_set_cross_connect(wpa_s, atoi(param));
4008 if (os_strcmp(cmd, "go_apsd") == 0) {
4009 if (os_strcmp(param, "disable") == 0)
4010 wpa_s->set_ap_uapsd = 0;
4012 wpa_s->set_ap_uapsd = 1;
4013 wpa_s->ap_uapsd = atoi(param);
4018 if (os_strcmp(cmd, "client_apsd") == 0) {
4019 if (os_strcmp(param, "disable") == 0)
4020 wpa_s->set_sta_uapsd = 0;
4024 /* format: BE,BK,VI,VO;max SP Length */
4026 pos = os_strchr(param, ',');
4031 pos = os_strchr(pos, ',');
4036 pos = os_strchr(pos, ',');
4041 /* ignore max SP Length for now */
4043 wpa_s->set_sta_uapsd = 1;
4044 wpa_s->sta_uapsd = 0;
4046 wpa_s->sta_uapsd |= BIT(0);
4048 wpa_s->sta_uapsd |= BIT(1);
4050 wpa_s->sta_uapsd |= BIT(2);
4052 wpa_s->sta_uapsd |= BIT(3);
4057 if (os_strcmp(cmd, "disallow_freq") == 0)
4058 return p2p_ctrl_disallow_freq(wpa_s, param);
4060 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
4067 static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd)
4070 unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0;
4073 pos = os_strchr(cmd, ' ');
4079 pos2 = os_strchr(pos, ' ');
4087 pos = os_strchr(pos2, ' ');
4095 return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2);
4099 static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd)
4102 unsigned int period = 0, interval = 0;
4105 pos = os_strchr(cmd, ' ');
4110 interval = atoi(pos);
4113 return wpas_p2p_ext_listen(wpa_s, period, interval);
4116 #endif /* CONFIG_P2P */
4119 #ifdef CONFIG_INTERWORKING
4120 static int ctrl_interworking_connect(struct wpa_supplicant *wpa_s, char *dst)
4123 struct wpa_bss *bss;
4125 if (hwaddr_aton(dst, bssid)) {
4126 wpa_printf(MSG_DEBUG, "Invalid BSSID '%s'", dst);
4130 bss = wpa_bss_get_bssid(wpa_s, bssid);
4132 wpa_printf(MSG_DEBUG, "Could not find BSS " MACSTR,
4137 return interworking_connect(wpa_s, bss);
4141 static int get_anqp(struct wpa_supplicant *wpa_s, char *dst)
4143 u8 dst_addr[ETH_ALEN];
4146 #define MAX_ANQP_INFO_ID 100
4147 u16 id[MAX_ANQP_INFO_ID];
4150 used = hwaddr_aton2(dst, dst_addr);
4154 while (num_id < MAX_ANQP_INFO_ID) {
4155 id[num_id] = atoi(pos);
4158 pos = os_strchr(pos + 1, ',');
4167 return anqp_send_req(wpa_s, dst_addr, id, num_id);
4171 static int gas_request(struct wpa_supplicant *wpa_s, char *cmd)
4173 u8 dst_addr[ETH_ALEN];
4174 struct wpabuf *advproto, *query = NULL;
4179 used = hwaddr_aton2(cmd, dst_addr);
4187 /* Advertisement Protocol ID */
4188 end = os_strchr(pos, ' ');
4192 len = os_strlen(pos);
4198 advproto = wpabuf_alloc(len);
4199 if (advproto == NULL)
4201 if (hexstr2bin(pos, wpabuf_put(advproto, len), len) < 0)
4205 /* Optional Query Request */
4210 len = os_strlen(pos);
4217 query = wpabuf_alloc(len);
4220 if (hexstr2bin(pos, wpabuf_put(query, len), len) < 0)
4225 ret = gas_send_request(wpa_s, dst_addr, advproto, query);
4228 wpabuf_free(advproto);
4235 static int gas_response_get(struct wpa_supplicant *wpa_s, char *cmd, char *buf,
4242 size_t resp_len, start, requested_len;
4244 if (!wpa_s->last_gas_resp)
4247 used = hwaddr_aton2(cmd, addr);
4254 dialog_token = atoi(pos);
4256 if (os_memcmp(addr, wpa_s->last_gas_addr, ETH_ALEN) != 0 ||
4257 dialog_token != wpa_s->last_gas_dialog_token)
4260 resp_len = wpabuf_len(wpa_s->last_gas_resp);
4262 requested_len = resp_len;
4264 pos = os_strchr(pos, ' ');
4267 if (start > resp_len)
4268 return os_snprintf(buf, buflen, "FAIL-Invalid range");
4269 pos = os_strchr(pos, ',');
4273 requested_len = atoi(pos);
4274 if (start + requested_len > resp_len)
4275 return os_snprintf(buf, buflen, "FAIL-Invalid range");
4278 if (requested_len * 2 + 1 > buflen)
4279 return os_snprintf(buf, buflen, "FAIL-Too long response");
4281 return wpa_snprintf_hex(buf, buflen,
4282 wpabuf_head_u8(wpa_s->last_gas_resp) + start,
4285 #endif /* CONFIG_INTERWORKING */
4290 static int get_hs20_anqp(struct wpa_supplicant *wpa_s, char *dst)
4292 u8 dst_addr[ETH_ALEN];
4297 used = hwaddr_aton2(dst, dst_addr);
4302 int num = atoi(pos);
4303 if (num <= 0 || num > 31)
4305 subtypes |= BIT(num);
4306 pos = os_strchr(pos + 1, ',');
4315 return hs20_anqp_send_req(wpa_s, dst_addr, subtypes, NULL, 0);
4319 static int hs20_nai_home_realm_list(struct wpa_supplicant *wpa_s,
4320 const u8 *addr, const char *realm)
4326 rlen = os_strlen(realm);
4328 buf = os_malloc(len);
4331 buf[0] = 1; /* NAI Home Realm Count */
4332 buf[1] = 0; /* Formatted in accordance with RFC 4282 */
4334 os_memcpy(buf + 3, realm, rlen);
4336 ret = hs20_anqp_send_req(wpa_s, addr,
4337 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
4346 static int hs20_get_nai_home_realm_list(struct wpa_supplicant *wpa_s,
4349 struct wpa_cred *cred = wpa_s->conf->cred;
4350 u8 dst_addr[ETH_ALEN];
4356 used = hwaddr_aton2(dst, dst_addr);
4360 while (dst[used] == ' ')
4362 if (os_strncmp(dst + used, "realm=", 6) == 0)
4363 return hs20_nai_home_realm_list(wpa_s, dst_addr,
4366 len = os_strlen(dst + used);
4368 if (len == 0 && cred && cred->realm)
4369 return hs20_nai_home_realm_list(wpa_s, dst_addr, cred->realm);
4374 buf = os_malloc(len);
4377 if (hexstr2bin(dst + used, buf, len) < 0) {
4382 ret = hs20_anqp_send_req(wpa_s, dst_addr,
4383 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
4390 #endif /* CONFIG_HS20 */
4393 static int wpa_supplicant_ctrl_iface_sta_autoconnect(
4394 struct wpa_supplicant *wpa_s, char *cmd)
4396 wpa_s->auto_reconnect_disabled = atoi(cmd) == 0 ? 1 : 0;
4401 #ifdef CONFIG_AUTOSCAN
4403 static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant *wpa_s,
4406 enum wpa_states state = wpa_s->wpa_state;
4407 char *new_params = NULL;
4409 if (os_strlen(cmd) > 0) {
4410 new_params = os_strdup(cmd);
4411 if (new_params == NULL)
4415 os_free(wpa_s->conf->autoscan);
4416 wpa_s->conf->autoscan = new_params;
4418 if (wpa_s->conf->autoscan == NULL)
4419 autoscan_deinit(wpa_s);
4420 else if (state == WPA_DISCONNECTED || state == WPA_INACTIVE)
4421 autoscan_init(wpa_s, 1);
4422 else if (state == WPA_SCANNING)
4423 wpa_supplicant_reinit_autoscan(wpa_s);
4428 #endif /* CONFIG_AUTOSCAN */
4431 static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf,
4434 struct wpa_signal_info si;
4437 ret = wpa_drv_signal_poll(wpa_s, &si);
4441 ret = os_snprintf(buf, buflen, "RSSI=%d\nLINKSPEED=%d\n"
4442 "NOISE=%d\nFREQUENCY=%u\n",
4443 si.current_signal, si.current_txrate / 1000,
4444 si.current_noise, si.frequency);
4445 if (ret < 0 || (unsigned int) ret > buflen)
4451 static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant *wpa_s, char *buf,
4454 struct hostap_sta_driver_data sta;
4457 ret = wpa_drv_pktcnt_poll(wpa_s, &sta);
4461 ret = os_snprintf(buf, buflen, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
4462 sta.tx_packets, sta.tx_retry_failed, sta.rx_packets);
4463 if (ret < 0 || (size_t) ret > buflen)
4469 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
4470 char *buf, size_t *resp_len)
4473 const int reply_size = 4096;
4477 if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 ||
4478 os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
4479 wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface",
4480 (const u8 *) buf, os_strlen(buf));
4482 int level = MSG_DEBUG;
4483 if (os_strcmp(buf, "PING") == 0)
4484 level = MSG_EXCESSIVE;
4485 wpa_hexdump_ascii(level, "RX ctrl_iface",
4486 (const u8 *) buf, os_strlen(buf));
4487 wpa_dbg(wpa_s, level, "Control interface command '%s'", buf);
4490 reply = os_malloc(reply_size);
4491 if (reply == NULL) {
4496 os_memcpy(reply, "OK\n", 3);
4499 if (os_strcmp(buf, "PING") == 0) {
4500 os_memcpy(reply, "PONG\n", 5);
4502 } else if (os_strcmp(buf, "IFNAME") == 0) {
4503 reply_len = os_strlen(wpa_s->ifname);
4504 os_memcpy(reply, wpa_s->ifname, reply_len);
4505 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
4506 if (wpa_debug_reopen_file() < 0)
4508 } else if (os_strncmp(buf, "NOTE ", 5) == 0) {
4509 wpa_printf(MSG_INFO, "NOTE: %s", buf + 5);
4510 } else if (os_strcmp(buf, "MIB") == 0) {
4511 reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size);
4512 if (reply_len >= 0) {
4514 res = eapol_sm_get_mib(wpa_s->eapol, reply + reply_len,
4515 reply_size - reply_len);
4521 } else if (os_strncmp(buf, "STATUS", 6) == 0) {
4522 reply_len = wpa_supplicant_ctrl_iface_status(
4523 wpa_s, buf + 6, reply, reply_size);
4524 } else if (os_strcmp(buf, "PMKSA") == 0) {
4525 reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, reply,
4527 } else if (os_strncmp(buf, "SET ", 4) == 0) {
4528 if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4))
4530 } else if (os_strncmp(buf, "GET ", 4) == 0) {
4531 reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4,
4533 } else if (os_strcmp(buf, "LOGON") == 0) {
4534 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
4535 } else if (os_strcmp(buf, "LOGOFF") == 0) {
4536 eapol_sm_notify_logoff(wpa_s->eapol, TRUE);
4537 } else if (os_strcmp(buf, "REASSOCIATE") == 0) {
4538 wpa_s->normal_scans = 0;
4539 wpa_supplicant_reinit_autoscan(wpa_s);
4540 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
4543 wpa_s->disconnected = 0;
4544 wpa_s->reassociate = 1;
4545 wpa_supplicant_req_scan(wpa_s, 0, 0);
4547 } else if (os_strcmp(buf, "RECONNECT") == 0) {
4548 wpa_s->normal_scans = 0;
4549 wpa_supplicant_reinit_autoscan(wpa_s);
4550 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
4552 else if (wpa_s->disconnected) {
4553 wpa_s->disconnected = 0;
4554 wpa_s->reassociate = 1;
4555 wpa_supplicant_req_scan(wpa_s, 0, 0);
4557 #ifdef IEEE8021X_EAPOL
4558 } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) {
4559 if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8))
4561 #endif /* IEEE8021X_EAPOL */
4562 #ifdef CONFIG_PEERKEY
4563 } else if (os_strncmp(buf, "STKSTART ", 9) == 0) {
4564 if (wpa_supplicant_ctrl_iface_stkstart(wpa_s, buf + 9))
4566 #endif /* CONFIG_PEERKEY */
4567 #ifdef CONFIG_IEEE80211R
4568 } else if (os_strncmp(buf, "FT_DS ", 6) == 0) {
4569 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6))
4571 #endif /* CONFIG_IEEE80211R */
4573 } else if (os_strcmp(buf, "WPS_PBC") == 0) {
4574 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL);
4576 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
4580 } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) {
4581 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8);
4583 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
4587 } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {
4588 reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8,
4591 } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) {
4592 reply_len = wpa_supplicant_ctrl_iface_wps_check_pin(
4593 wpa_s, buf + 14, reply, reply_size);
4594 } else if (os_strcmp(buf, "WPS_CANCEL") == 0) {
4595 if (wpas_wps_cancel(wpa_s))
4597 #ifdef CONFIG_WPS_OOB
4598 } else if (os_strncmp(buf, "WPS_OOB ", 8) == 0) {
4599 if (wpa_supplicant_ctrl_iface_wps_oob(wpa_s, buf + 8))
4601 #endif /* CONFIG_WPS_OOB */
4602 #ifdef CONFIG_WPS_NFC
4603 } else if (os_strcmp(buf, "WPS_NFC") == 0) {
4604 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, NULL))
4606 } else if (os_strncmp(buf, "WPS_NFC ", 8) == 0) {
4607 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, buf + 8))
4609 } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) {
4610 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_token(
4611 wpa_s, buf + 14, reply, reply_size);
4612 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) {
4613 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s,
4616 #endif /* CONFIG_WPS_NFC */
4617 } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) {
4618 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8))
4621 } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) {
4622 reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin(
4623 wpa_s, buf + 11, reply, reply_size);
4624 #endif /* CONFIG_AP */
4625 #ifdef CONFIG_WPS_ER
4626 } else if (os_strcmp(buf, "WPS_ER_START") == 0) {
4627 if (wpas_wps_er_start(wpa_s, NULL))
4629 } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) {
4630 if (wpas_wps_er_start(wpa_s, buf + 13))
4632 } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) {
4633 if (wpas_wps_er_stop(wpa_s))
4635 } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) {
4636 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11))
4638 } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) {
4639 int ret = wpas_wps_er_pbc(wpa_s, buf + 11);
4641 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
4643 } else if (ret == -3) {
4644 os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18);
4646 } else if (ret == -4) {
4647 os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20);
4651 } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) {
4652 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13))
4654 } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) {
4655 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s,
4658 } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) {
4659 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14))
4661 #ifdef CONFIG_WPS_NFC
4662 } else if (os_strncmp(buf, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
4663 reply_len = wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
4664 wpa_s, buf + 24, reply, reply_size);
4665 #endif /* CONFIG_WPS_NFC */
4666 #endif /* CONFIG_WPS_ER */
4667 #endif /* CONFIG_WPS */
4668 #ifdef CONFIG_IBSS_RSN
4669 } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) {
4670 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9))
4672 #endif /* CONFIG_IBSS_RSN */
4674 } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) {
4675 if (p2p_ctrl_find(wpa_s, buf + 9))
4677 } else if (os_strcmp(buf, "P2P_FIND") == 0) {
4678 if (p2p_ctrl_find(wpa_s, ""))
4680 } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) {
4681 wpas_p2p_stop_find(wpa_s);
4682 } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) {
4683 reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply,
4685 } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) {
4686 if (p2p_ctrl_listen(wpa_s, buf + 11))
4688 } else if (os_strcmp(buf, "P2P_LISTEN") == 0) {
4689 if (p2p_ctrl_listen(wpa_s, ""))
4691 } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) {
4692 if (wpas_p2p_group_remove(wpa_s, buf + 17))
4694 } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) {
4695 if (wpas_p2p_group_add(wpa_s, 0, 0, 0))
4697 } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) {
4698 if (p2p_ctrl_group_add(wpa_s, buf + 14))
4700 } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) {
4701 if (p2p_ctrl_prov_disc(wpa_s, buf + 14))
4703 } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) {
4704 reply_len = p2p_get_passphrase(wpa_s, reply, reply_size);
4705 } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) {
4706 reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply,
4708 } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
4709 if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0)
4711 } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) {
4712 if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0)
4714 } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) {
4715 wpas_p2p_sd_service_update(wpa_s);
4716 } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
4717 if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0)
4719 } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) {
4720 wpas_p2p_service_flush(wpa_s);
4721 } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) {
4722 if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0)
4724 } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) {
4725 if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0)
4727 } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) {
4728 if (p2p_ctrl_reject(wpa_s, buf + 11) < 0)
4730 } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) {
4731 if (p2p_ctrl_invite(wpa_s, buf + 11) < 0)
4733 } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) {
4734 reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply,
4736 } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) {
4737 if (p2p_ctrl_set(wpa_s, buf + 8) < 0)
4739 } else if (os_strcmp(buf, "P2P_FLUSH") == 0) {
4740 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
4741 wpa_s->force_long_sd = 0;
4742 if (wpa_s->global->p2p)
4743 p2p_flush(wpa_s->global->p2p);
4744 } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) {
4745 if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0)
4747 } else if (os_strcmp(buf, "P2P_CANCEL") == 0) {
4748 if (wpas_p2p_cancel(wpa_s))
4750 } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) {
4751 if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0)
4753 } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) {
4754 if (p2p_ctrl_presence_req(wpa_s, "") < 0)
4756 } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) {
4757 if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0)
4759 } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) {
4760 if (p2p_ctrl_ext_listen(wpa_s, "") < 0)
4762 #endif /* CONFIG_P2P */
4763 #ifdef CONFIG_WIFI_DISPLAY
4764 } else if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0) {
4765 if (wifi_display_subelem_set(wpa_s->global, buf + 16) < 0)
4767 } else if (os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) {
4768 reply_len = wifi_display_subelem_get(wpa_s->global, buf + 16,
4770 #endif /* CONFIG_WIFI_DISPLAY */
4771 #ifdef CONFIG_INTERWORKING
4772 } else if (os_strcmp(buf, "FETCH_ANQP") == 0) {
4773 if (interworking_fetch_anqp(wpa_s) < 0)
4775 } else if (os_strcmp(buf, "STOP_FETCH_ANQP") == 0) {
4776 interworking_stop_fetch_anqp(wpa_s);
4777 } else if (os_strncmp(buf, "INTERWORKING_SELECT", 19) == 0) {
4778 if (interworking_select(wpa_s, os_strstr(buf + 19, "auto") !=
4781 } else if (os_strncmp(buf, "INTERWORKING_CONNECT ", 21) == 0) {
4782 if (ctrl_interworking_connect(wpa_s, buf + 21) < 0)
4784 } else if (os_strncmp(buf, "ANQP_GET ", 9) == 0) {
4785 if (get_anqp(wpa_s, buf + 9) < 0)
4787 } else if (os_strncmp(buf, "GAS_REQUEST ", 12) == 0) {
4788 if (gas_request(wpa_s, buf + 12) < 0)
4790 } else if (os_strncmp(buf, "GAS_RESPONSE_GET ", 17) == 0) {
4791 reply_len = gas_response_get(wpa_s, buf + 17, reply,
4793 #endif /* CONFIG_INTERWORKING */
4795 } else if (os_strncmp(buf, "HS20_ANQP_GET ", 14) == 0) {
4796 if (get_hs20_anqp(wpa_s, buf + 14) < 0)
4798 } else if (os_strncmp(buf, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
4799 if (hs20_get_nai_home_realm_list(wpa_s, buf + 29) < 0)
4801 #endif /* CONFIG_HS20 */
4802 } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0)
4804 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
4805 wpa_s, buf + os_strlen(WPA_CTRL_RSP)))
4809 } else if (os_strcmp(buf, "RECONFIGURE") == 0) {
4810 if (wpa_supplicant_reload_configuration(wpa_s))
4812 } else if (os_strcmp(buf, "TERMINATE") == 0) {
4813 wpa_supplicant_terminate_proc(wpa_s->global);
4814 } else if (os_strncmp(buf, "BSSID ", 6) == 0) {
4815 if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6))
4817 } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) {
4818 reply_len = wpa_supplicant_ctrl_iface_blacklist(
4819 wpa_s, buf + 9, reply, reply_size);
4820 } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) {
4821 reply_len = wpa_supplicant_ctrl_iface_log_level(
4822 wpa_s, buf + 9, reply, reply_size);
4823 } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) {
4824 reply_len = wpa_supplicant_ctrl_iface_list_networks(
4825 wpa_s, reply, reply_size);
4826 } else if (os_strcmp(buf, "DISCONNECT") == 0) {
4828 wpa_s->sme.prev_bssid_set = 0;
4829 #endif /* CONFIG_SME */
4830 wpa_s->reassociate = 0;
4831 wpa_s->disconnected = 1;
4832 wpa_supplicant_cancel_sched_scan(wpa_s);
4833 wpa_supplicant_cancel_scan(wpa_s);
4834 wpa_supplicant_deauthenticate(wpa_s,
4835 WLAN_REASON_DEAUTH_LEAVING);
4836 } else if (os_strcmp(buf, "SCAN") == 0) {
4837 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
4840 if (!wpa_s->scanning &&
4841 ((wpa_s->wpa_state <= WPA_SCANNING) ||
4842 (wpa_s->wpa_state == WPA_COMPLETED))) {
4843 wpa_s->normal_scans = 0;
4844 wpa_s->scan_req = 2;
4845 wpa_supplicant_req_scan(wpa_s, 0, 0);
4846 } else if (wpa_s->sched_scanning) {
4847 wpa_printf(MSG_DEBUG, "Stop ongoing "
4848 "sched_scan to allow requested "
4849 "full scan to proceed");
4850 wpa_supplicant_cancel_sched_scan(wpa_s);
4851 wpa_s->scan_req = 2;
4852 wpa_supplicant_req_scan(wpa_s, 0, 0);
4854 wpa_printf(MSG_DEBUG, "Ongoing scan action - "
4855 "reject new request");
4856 reply_len = os_snprintf(reply, reply_size,
4860 } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) {
4861 reply_len = wpa_supplicant_ctrl_iface_scan_results(
4862 wpa_s, reply, reply_size);
4863 } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) {
4864 if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15))
4866 } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) {
4867 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15))
4869 } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) {
4870 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16))
4872 } else if (os_strcmp(buf, "ADD_NETWORK") == 0) {
4873 reply_len = wpa_supplicant_ctrl_iface_add_network(
4874 wpa_s, reply, reply_size);
4875 } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) {
4876 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15))
4878 } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
4879 if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12))
4881 } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) {
4882 reply_len = wpa_supplicant_ctrl_iface_get_network(
4883 wpa_s, buf + 12, reply, reply_size);
4884 } else if (os_strcmp(buf, "LIST_CREDS") == 0) {
4885 reply_len = wpa_supplicant_ctrl_iface_list_creds(
4886 wpa_s, reply, reply_size);
4887 } else if (os_strcmp(buf, "ADD_CRED") == 0) {
4888 reply_len = wpa_supplicant_ctrl_iface_add_cred(
4889 wpa_s, reply, reply_size);
4890 } else if (os_strncmp(buf, "REMOVE_CRED ", 12) == 0) {
4891 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s, buf + 12))
4893 } else if (os_strncmp(buf, "SET_CRED ", 9) == 0) {
4894 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s, buf + 9))
4896 #ifndef CONFIG_NO_CONFIG_WRITE
4897 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
4898 if (wpa_supplicant_ctrl_iface_save_config(wpa_s))
4900 #endif /* CONFIG_NO_CONFIG_WRITE */
4901 } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
4902 reply_len = wpa_supplicant_ctrl_iface_get_capability(
4903 wpa_s, buf + 15, reply, reply_size);
4904 } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) {
4905 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8))
4907 } else if (os_strncmp(buf, "SCAN_INTERVAL ", 14) == 0) {
4908 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s, buf + 14))
4910 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
4911 reply_len = wpa_supplicant_global_iface_list(
4912 wpa_s->global, reply, reply_size);
4913 } else if (os_strcmp(buf, "INTERFACES") == 0) {
4914 reply_len = wpa_supplicant_global_iface_interfaces(
4915 wpa_s->global, reply, reply_size);
4916 } else if (os_strncmp(buf, "BSS ", 4) == 0) {
4917 reply_len = wpa_supplicant_ctrl_iface_bss(
4918 wpa_s, buf + 4, reply, reply_size);
4920 } else if (os_strcmp(buf, "STA-FIRST") == 0) {
4921 reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size);
4922 } else if (os_strncmp(buf, "STA ", 4) == 0) {
4923 reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply,
4925 } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) {
4926 reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply,
4928 } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) {
4929 if (ap_ctrl_iface_sta_deauthenticate(wpa_s, buf + 15))
4931 } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) {
4932 if (ap_ctrl_iface_sta_disassociate(wpa_s, buf + 13))
4934 #endif /* CONFIG_AP */
4935 } else if (os_strcmp(buf, "SUSPEND") == 0) {
4936 wpas_notify_suspend(wpa_s->global);
4937 } else if (os_strcmp(buf, "RESUME") == 0) {
4938 wpas_notify_resume(wpa_s->global);
4939 } else if (os_strcmp(buf, "DROP_SA") == 0) {
4940 wpa_supplicant_ctrl_iface_drop_sa(wpa_s);
4941 } else if (os_strncmp(buf, "ROAM ", 5) == 0) {
4942 if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5))
4944 } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) {
4945 if (wpa_supplicant_ctrl_iface_sta_autoconnect(wpa_s, buf + 16))
4947 } else if (os_strncmp(buf, "BSS_EXPIRE_AGE ", 15) == 0) {
4948 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s, buf + 15))
4950 } else if (os_strncmp(buf, "BSS_EXPIRE_COUNT ", 17) == 0) {
4951 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s,
4954 } else if (os_strncmp(buf, "BSS_FLUSH ", 10) == 0) {
4955 if (wpa_supplicant_ctrl_iface_bss_flush(wpa_s, buf + 10))
4958 } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) {
4959 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14))
4961 } else if (os_strncmp(buf, "TDLS_SETUP ", 11) == 0) {
4962 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s, buf + 11))
4964 } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) {
4965 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14))
4967 #endif /* CONFIG_TDLS */
4968 } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) {
4969 reply_len = wpa_supplicant_signal_poll(wpa_s, reply,
4971 } else if (os_strncmp(buf, "PKTCNT_POLL", 11) == 0) {
4972 reply_len = wpa_supplicant_pktcnt_poll(wpa_s, reply,
4974 #ifdef CONFIG_AUTOSCAN
4975 } else if (os_strncmp(buf, "AUTOSCAN ", 9) == 0) {
4976 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s, buf + 9))
4978 #endif /* CONFIG_AUTOSCAN */
4979 } else if (os_strcmp(buf, "REAUTHENTICATE") == 0) {
4980 eapol_sm_request_reauth(wpa_s->eapol);
4982 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
4986 if (reply_len < 0) {
4987 os_memcpy(reply, "FAIL\n", 5);
4992 eapol_sm_notify_ctrl_response(wpa_s->eapol);
4994 *resp_len = reply_len;
4999 static int wpa_supplicant_global_iface_add(struct wpa_global *global,
5002 struct wpa_interface iface;
5006 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
5007 * TAB<bridge_ifname>
5009 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd);
5011 os_memset(&iface, 0, sizeof(iface));
5014 iface.ifname = pos = cmd;
5015 pos = os_strchr(pos, '\t');
5018 if (iface.ifname[0] == '\0')
5023 iface.confname = pos;
5024 pos = os_strchr(pos, '\t');
5027 if (iface.confname[0] == '\0')
5028 iface.confname = NULL;
5033 pos = os_strchr(pos, '\t');
5036 if (iface.driver[0] == '\0')
5037 iface.driver = NULL;
5041 iface.ctrl_interface = pos;
5042 pos = os_strchr(pos, '\t');
5045 if (iface.ctrl_interface[0] == '\0')
5046 iface.ctrl_interface = NULL;
5050 iface.driver_param = pos;
5051 pos = os_strchr(pos, '\t');
5054 if (iface.driver_param[0] == '\0')
5055 iface.driver_param = NULL;
5059 iface.bridge_ifname = pos;
5060 pos = os_strchr(pos, '\t');
5063 if (iface.bridge_ifname[0] == '\0')
5064 iface.bridge_ifname = NULL;
5069 if (wpa_supplicant_get_iface(global, iface.ifname))
5072 return wpa_supplicant_add_iface(global, &iface) ? 0 : -1;
5076 static int wpa_supplicant_global_iface_remove(struct wpa_global *global,
5079 struct wpa_supplicant *wpa_s;
5081 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd);
5083 wpa_s = wpa_supplicant_get_iface(global, cmd);
5086 return wpa_supplicant_remove_iface(global, wpa_s, 0);
5090 static void wpa_free_iface_info(struct wpa_interface_info *iface)
5092 struct wpa_interface_info *prev;
5096 iface = iface->next;
5098 os_free(prev->ifname);
5099 os_free(prev->desc);
5105 static int wpa_supplicant_global_iface_list(struct wpa_global *global,
5109 struct wpa_interface_info *iface = NULL, *last = NULL, *tmp;
5112 for (i = 0; wpa_drivers[i]; i++) {
5113 struct wpa_driver_ops *drv = wpa_drivers[i];
5114 if (drv->get_interfaces == NULL)
5116 tmp = drv->get_interfaces(global->drv_priv[i]);
5130 for (tmp = iface; tmp; tmp = tmp->next) {
5131 res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n",
5132 tmp->drv_name, tmp->ifname,
5133 tmp->desc ? tmp->desc : "");
5134 if (res < 0 || res >= end - pos) {
5141 wpa_free_iface_info(iface);
5147 static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
5152 struct wpa_supplicant *wpa_s;
5154 wpa_s = global->ifaces;
5159 res = os_snprintf(pos, end - pos, "%s\n", wpa_s->ifname);
5160 if (res < 0 || res >= end - pos) {
5165 wpa_s = wpa_s->next;
5171 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
5172 char *buf, size_t *resp_len)
5175 const int reply_size = 2048;
5177 int level = MSG_DEBUG;
5179 if (os_strcmp(buf, "PING") == 0)
5180 level = MSG_EXCESSIVE;
5181 wpa_hexdump_ascii(level, "RX global ctrl_iface",
5182 (const u8 *) buf, os_strlen(buf));
5184 reply = os_malloc(reply_size);
5185 if (reply == NULL) {
5190 os_memcpy(reply, "OK\n", 3);
5193 if (os_strcmp(buf, "PING") == 0) {
5194 os_memcpy(reply, "PONG\n", 5);
5196 } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) {
5197 if (wpa_supplicant_global_iface_add(global, buf + 14))
5199 } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) {
5200 if (wpa_supplicant_global_iface_remove(global, buf + 17))
5202 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
5203 reply_len = wpa_supplicant_global_iface_list(
5204 global, reply, reply_size);
5205 } else if (os_strcmp(buf, "INTERFACES") == 0) {
5206 reply_len = wpa_supplicant_global_iface_interfaces(
5207 global, reply, reply_size);
5208 } else if (os_strcmp(buf, "TERMINATE") == 0) {
5209 wpa_supplicant_terminate_proc(global);
5210 } else if (os_strcmp(buf, "SUSPEND") == 0) {
5211 wpas_notify_suspend(global);
5212 } else if (os_strcmp(buf, "RESUME") == 0) {
5213 wpas_notify_resume(global);
5215 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
5219 if (reply_len < 0) {
5220 os_memcpy(reply, "FAIL\n", 5);
5224 *resp_len = reply_len;