2 * WPA Supplicant / Control interface (shared code for all backends)
3 * Copyright (c) 2004-2014, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
9 #include "utils/includes.h"
11 #include "utils/common.h"
12 #include "utils/eloop.h"
13 #include "utils/uuid.h"
14 #include "common/version.h"
15 #include "common/ieee802_11_defs.h"
16 #include "common/ieee802_11_common.h"
17 #include "common/wpa_ctrl.h"
18 #include "eap_peer/eap.h"
19 #include "eapol_supp/eapol_supp_sm.h"
20 #include "rsn_supp/wpa.h"
21 #include "rsn_supp/preauth.h"
22 #include "rsn_supp/pmksa_cache.h"
23 #include "l2_packet/l2_packet.h"
26 #include "wpa_supplicant_i.h"
28 #include "wps_supplicant.h"
31 #include "p2p_supplicant.h"
33 #include "hs20_supplicant.h"
34 #include "wifi_display.h"
38 #include "ctrl_iface.h"
39 #include "interworking.h"
40 #include "blacklist.h"
44 static int wpa_supplicant_global_iface_list(struct wpa_global *global,
46 static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
50 static int pno_start(struct wpa_supplicant *wpa_s)
54 struct wpa_ssid *ssid;
55 struct wpa_driver_scan_params params;
57 if (wpa_s->pno || wpa_s->pno_sched_pending)
60 if ((wpa_s->wpa_state > WPA_SCANNING) &&
61 (wpa_s->wpa_state <= WPA_COMPLETED)) {
62 wpa_printf(MSG_ERROR, "PNO: In assoc process");
66 if (wpa_s->wpa_state == WPA_SCANNING) {
67 wpa_supplicant_cancel_scan(wpa_s);
68 if (wpa_s->sched_scanning) {
69 wpa_printf(MSG_DEBUG, "Schedule PNO on completion of "
70 "ongoing sched scan");
71 wpa_supplicant_cancel_sched_scan(wpa_s);
72 wpa_s->pno_sched_pending = 1;
77 os_memset(¶ms, 0, sizeof(params));
80 ssid = wpa_s->conf->ssid;
82 if (!wpas_network_disabled(wpa_s, ssid))
86 if (num_ssid > WPAS_MAX_SCAN_SSIDS) {
87 wpa_printf(MSG_DEBUG, "PNO: Use only the first %u SSIDs from "
88 "%u", WPAS_MAX_SCAN_SSIDS, (unsigned int) num_ssid);
89 num_ssid = WPAS_MAX_SCAN_SSIDS;
93 wpa_printf(MSG_DEBUG, "PNO: No configured SSIDs");
97 params.filter_ssids = os_malloc(sizeof(struct wpa_driver_scan_filter) *
99 if (params.filter_ssids == NULL)
102 ssid = wpa_s->conf->ssid;
104 if (!wpas_network_disabled(wpa_s, ssid)) {
105 params.ssids[i].ssid = ssid->ssid;
106 params.ssids[i].ssid_len = ssid->ssid_len;
108 os_memcpy(params.filter_ssids[i].ssid, ssid->ssid,
110 params.filter_ssids[i].ssid_len = ssid->ssid_len;
111 params.num_filter_ssids++;
119 if (wpa_s->conf->filter_rssi)
120 params.filter_rssi = wpa_s->conf->filter_rssi;
122 interval = wpa_s->conf->sched_scan_interval ?
123 wpa_s->conf->sched_scan_interval : 10;
125 ret = wpa_supplicant_start_sched_scan(wpa_s, ¶ms, interval);
126 os_free(params.filter_ssids);
133 static int pno_stop(struct wpa_supplicant *wpa_s)
137 if (wpa_s->pno || wpa_s->sched_scanning) {
139 ret = wpa_supplicant_stop_sched_scan(wpa_s);
142 wpa_s->pno_sched_pending = 0;
144 if (wpa_s->wpa_state == WPA_SCANNING)
145 wpa_supplicant_req_scan(wpa_s, 0, 0);
151 static int set_bssid_filter(struct wpa_supplicant *wpa_s, char *val)
154 u8 addr[ETH_ALEN], *filter = NULL, *n;
161 if (hwaddr_aton(pos, addr)) {
165 n = os_realloc_array(filter, count + 1, ETH_ALEN);
171 os_memcpy(filter + count * ETH_ALEN, addr, ETH_ALEN);
174 pos = os_strchr(pos, ' ');
179 wpa_hexdump(MSG_DEBUG, "bssid_filter", filter, count * ETH_ALEN);
180 os_free(wpa_s->bssid_filter);
181 wpa_s->bssid_filter = filter;
182 wpa_s->bssid_filter_count = count;
188 static int set_disallow_aps(struct wpa_supplicant *wpa_s, char *val)
191 u8 addr[ETH_ALEN], *bssid = NULL, *n;
192 struct wpa_ssid_value *ssid = NULL, *ns;
193 size_t count = 0, ssid_count = 0;
197 * disallow_list ::= <ssid_spec> | <bssid_spec> | <disallow_list> | ""
198 * SSID_SPEC ::= ssid <SSID_HEX>
199 * BSSID_SPEC ::= bssid <BSSID_HEX>
206 if (os_strncmp(pos, "bssid ", 6) == 0) {
209 res = hwaddr_aton2(pos, addr);
213 wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
214 "BSSID value '%s'", pos);
218 n = os_realloc_array(bssid, count + 1, ETH_ALEN);
225 os_memcpy(bssid + count * ETH_ALEN, addr, ETH_ALEN);
227 } else if (os_strncmp(pos, "ssid ", 5) == 0) {
233 if (*end == '\0' || *end == ' ')
238 ns = os_realloc_array(ssid, ssid_count + 1,
239 sizeof(struct wpa_ssid_value));
247 if ((end - pos) & 0x01 || end - pos > 2 * 32 ||
248 hexstr2bin(pos, ssid[ssid_count].ssid,
249 (end - pos) / 2) < 0) {
252 wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
253 "SSID value '%s'", pos);
256 ssid[ssid_count].ssid_len = (end - pos) / 2;
257 wpa_hexdump_ascii(MSG_DEBUG, "disallow_aps SSID",
258 ssid[ssid_count].ssid,
259 ssid[ssid_count].ssid_len);
263 wpa_printf(MSG_DEBUG, "Unexpected disallow_aps value "
270 pos = os_strchr(pos, ' ');
275 wpa_hexdump(MSG_DEBUG, "disallow_aps_bssid", bssid, count * ETH_ALEN);
276 os_free(wpa_s->disallow_aps_bssid);
277 wpa_s->disallow_aps_bssid = bssid;
278 wpa_s->disallow_aps_bssid_count = count;
280 wpa_printf(MSG_DEBUG, "disallow_aps_ssid_count %d", (int) ssid_count);
281 os_free(wpa_s->disallow_aps_ssid);
282 wpa_s->disallow_aps_ssid = ssid;
283 wpa_s->disallow_aps_ssid_count = ssid_count;
285 if (!wpa_s->current_ssid || wpa_s->wpa_state < WPA_AUTHENTICATING)
288 c = wpa_s->current_ssid;
289 if (c->mode != WPAS_MODE_INFRA && c->mode != WPAS_MODE_IBSS)
292 if (!disallowed_bssid(wpa_s, wpa_s->bssid) &&
293 !disallowed_ssid(wpa_s, c->ssid, c->ssid_len))
296 wpa_printf(MSG_DEBUG, "Disconnect and try to find another network "
297 "because current AP was marked disallowed");
300 wpa_s->sme.prev_bssid_set = 0;
301 #endif /* CONFIG_SME */
302 wpa_s->reassociate = 1;
303 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
304 wpa_supplicant_req_scan(wpa_s, 0, 0);
310 static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s,
316 value = os_strchr(cmd, ' ');
321 wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value);
322 if (os_strcasecmp(cmd, "EAPOL::heldPeriod") == 0) {
323 eapol_sm_configure(wpa_s->eapol,
324 atoi(value), -1, -1, -1);
325 } else if (os_strcasecmp(cmd, "EAPOL::authPeriod") == 0) {
326 eapol_sm_configure(wpa_s->eapol,
327 -1, atoi(value), -1, -1);
328 } else if (os_strcasecmp(cmd, "EAPOL::startPeriod") == 0) {
329 eapol_sm_configure(wpa_s->eapol,
330 -1, -1, atoi(value), -1);
331 } else if (os_strcasecmp(cmd, "EAPOL::maxStart") == 0) {
332 eapol_sm_configure(wpa_s->eapol,
333 -1, -1, -1, atoi(value));
334 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKLifetime") == 0) {
335 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME,
338 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKReauthThreshold") ==
340 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD,
343 } else if (os_strcasecmp(cmd, "dot11RSNAConfigSATimeout") == 0) {
344 if (wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, atoi(value)))
346 } else if (os_strcasecmp(cmd, "wps_fragment_size") == 0) {
347 wpa_s->wps_fragment_size = atoi(value);
348 #ifdef CONFIG_WPS_TESTING
349 } else if (os_strcasecmp(cmd, "wps_version_number") == 0) {
351 val = strtol(value, NULL, 0);
352 if (val < 0 || val > 0xff) {
354 wpa_printf(MSG_DEBUG, "WPS: Invalid "
355 "wps_version_number %ld", val);
357 wps_version_number = val;
358 wpa_printf(MSG_DEBUG, "WPS: Testing - force WPS "
360 (wps_version_number & 0xf0) >> 4,
361 wps_version_number & 0x0f);
363 } else if (os_strcasecmp(cmd, "wps_testing_dummy_cred") == 0) {
364 wps_testing_dummy_cred = atoi(value);
365 wpa_printf(MSG_DEBUG, "WPS: Testing - dummy_cred=%d",
366 wps_testing_dummy_cred);
367 } else if (os_strcasecmp(cmd, "wps_corrupt_pkhash") == 0) {
368 wps_corrupt_pkhash = atoi(value);
369 wpa_printf(MSG_DEBUG, "WPS: Testing - wps_corrupt_pkhash=%d",
371 #endif /* CONFIG_WPS_TESTING */
372 } else if (os_strcasecmp(cmd, "ampdu") == 0) {
373 if (wpa_drv_ampdu(wpa_s, atoi(value)) < 0)
376 #ifdef CONFIG_TDLS_TESTING
377 } else if (os_strcasecmp(cmd, "tdls_testing") == 0) {
378 extern unsigned int tdls_testing;
379 tdls_testing = strtol(value, NULL, 0);
380 wpa_printf(MSG_DEBUG, "TDLS: tdls_testing=0x%x", tdls_testing);
381 #endif /* CONFIG_TDLS_TESTING */
382 } else if (os_strcasecmp(cmd, "tdls_disabled") == 0) {
383 int disabled = atoi(value);
384 wpa_printf(MSG_DEBUG, "TDLS: tdls_disabled=%d", disabled);
386 if (wpa_drv_tdls_oper(wpa_s, TDLS_DISABLE, NULL) < 0)
388 } else if (wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL) < 0)
390 wpa_tdls_enable(wpa_s->wpa, !disabled);
391 #endif /* CONFIG_TDLS */
392 } else if (os_strcasecmp(cmd, "pno") == 0) {
394 ret = pno_start(wpa_s);
396 ret = pno_stop(wpa_s);
397 } else if (os_strcasecmp(cmd, "radio_disabled") == 0) {
398 int disabled = atoi(value);
399 if (wpa_drv_radio_disable(wpa_s, disabled) < 0)
402 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
403 } else if (os_strcasecmp(cmd, "uapsd") == 0) {
404 if (os_strcmp(value, "disable") == 0)
405 wpa_s->set_sta_uapsd = 0;
409 /* format: BE,BK,VI,VO;max SP Length */
411 pos = os_strchr(value, ',');
416 pos = os_strchr(pos, ',');
421 pos = os_strchr(pos, ',');
426 /* ignore max SP Length for now */
428 wpa_s->set_sta_uapsd = 1;
429 wpa_s->sta_uapsd = 0;
431 wpa_s->sta_uapsd |= BIT(0);
433 wpa_s->sta_uapsd |= BIT(1);
435 wpa_s->sta_uapsd |= BIT(2);
437 wpa_s->sta_uapsd |= BIT(3);
439 } else if (os_strcasecmp(cmd, "ps") == 0) {
440 ret = wpa_drv_set_p2p_powersave(wpa_s, atoi(value), -1, -1);
441 #ifdef CONFIG_WIFI_DISPLAY
442 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
443 wifi_display_enable(wpa_s->global, !!atoi(value));
444 #endif /* CONFIG_WIFI_DISPLAY */
445 } else if (os_strcasecmp(cmd, "bssid_filter") == 0) {
446 ret = set_bssid_filter(wpa_s, value);
447 } else if (os_strcasecmp(cmd, "disallow_aps") == 0) {
448 ret = set_disallow_aps(wpa_s, value);
449 } else if (os_strcasecmp(cmd, "no_keep_alive") == 0) {
450 wpa_s->no_keep_alive = !!atoi(value);
453 ret = wpa_config_process_global(wpa_s->conf, cmd, -1);
455 wpa_supplicant_update_config(wpa_s);
462 static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s,
463 char *cmd, char *buf, size_t buflen)
467 wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd);
469 if (os_strcmp(cmd, "version") == 0) {
470 res = os_snprintf(buf, buflen, "%s", VERSION_STR);
471 } else if (os_strcasecmp(cmd, "country") == 0) {
472 if (wpa_s->conf->country[0] && wpa_s->conf->country[1])
473 res = os_snprintf(buf, buflen, "%c%c",
474 wpa_s->conf->country[0],
475 wpa_s->conf->country[1]);
476 #ifdef CONFIG_WIFI_DISPLAY
477 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
478 res = os_snprintf(buf, buflen, "%d",
479 wpa_s->global->wifi_display);
480 if (res < 0 || (unsigned int) res >= buflen)
483 #endif /* CONFIG_WIFI_DISPLAY */
484 #ifdef CONFIG_TESTING_GET_GTK
485 } else if (os_strcmp(cmd, "gtk") == 0) {
486 if (wpa_s->last_gtk_len == 0)
488 res = wpa_snprintf_hex(buf, buflen, wpa_s->last_gtk,
489 wpa_s->last_gtk_len);
491 #endif /* CONFIG_TESTING_GET_GTK */
494 if (res < 0 || (unsigned int) res >= buflen)
500 #ifdef IEEE8021X_EAPOL
501 static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s,
505 struct wpa_ssid *ssid = wpa_s->current_ssid;
507 if (hwaddr_aton(addr, bssid)) {
508 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address "
513 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid));
514 rsn_preauth_deinit(wpa_s->wpa);
515 if (rsn_preauth_init(wpa_s->wpa, bssid, ssid ? &ssid->eap : NULL))
520 #endif /* IEEE8021X_EAPOL */
523 #ifdef CONFIG_PEERKEY
524 /* MLME-STKSTART.request(peer) */
525 static int wpa_supplicant_ctrl_iface_stkstart(
526 struct wpa_supplicant *wpa_s, char *addr)
530 if (hwaddr_aton(addr, peer)) {
531 wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART: invalid "
532 "address '%s'", addr);
536 wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART " MACSTR,
539 return wpa_sm_stkstart(wpa_s->wpa, peer);
541 #endif /* CONFIG_PEERKEY */
546 static int wpa_supplicant_ctrl_iface_tdls_discover(
547 struct wpa_supplicant *wpa_s, char *addr)
552 if (hwaddr_aton(addr, peer)) {
553 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER: invalid "
554 "address '%s'", addr);
558 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER " MACSTR,
561 if (wpa_tdls_is_external_setup(wpa_s->wpa))
562 ret = wpa_tdls_send_discovery_request(wpa_s->wpa, peer);
564 ret = wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer);
570 static int wpa_supplicant_ctrl_iface_tdls_setup(
571 struct wpa_supplicant *wpa_s, char *addr)
576 if (hwaddr_aton(addr, peer)) {
577 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP: invalid "
578 "address '%s'", addr);
582 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP " MACSTR,
585 if ((wpa_s->conf->tdls_external_control) &&
586 wpa_tdls_is_external_setup(wpa_s->wpa))
587 return wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
589 wpa_tdls_remove(wpa_s->wpa, peer);
591 if (wpa_tdls_is_external_setup(wpa_s->wpa))
592 ret = wpa_tdls_start(wpa_s->wpa, peer);
594 ret = wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
600 static int wpa_supplicant_ctrl_iface_tdls_teardown(
601 struct wpa_supplicant *wpa_s, char *addr)
606 if (hwaddr_aton(addr, peer)) {
607 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN: invalid "
608 "address '%s'", addr);
612 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN " MACSTR,
615 if ((wpa_s->conf->tdls_external_control) &&
616 wpa_tdls_is_external_setup(wpa_s->wpa))
617 return wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
619 if (wpa_tdls_is_external_setup(wpa_s->wpa))
620 ret = wpa_tdls_teardown_link(
622 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED);
624 ret = wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
629 #endif /* CONFIG_TDLS */
632 #ifdef CONFIG_IEEE80211R
633 static int wpa_supplicant_ctrl_iface_ft_ds(
634 struct wpa_supplicant *wpa_s, char *addr)
636 u8 target_ap[ETH_ALEN];
640 if (hwaddr_aton(addr, target_ap)) {
641 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid "
642 "address '%s'", addr);
646 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap));
648 bss = wpa_bss_get_bssid(wpa_s, target_ap);
650 mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN);
654 return wpa_ft_start_over_ds(wpa_s->wpa, target_ap, mdie);
656 #endif /* CONFIG_IEEE80211R */
660 static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s,
663 u8 bssid[ETH_ALEN], *_bssid = bssid;
665 u8 p2p_dev_addr[ETH_ALEN];
666 #endif /* CONFIG_P2P */
668 u8 *_p2p_dev_addr = NULL;
669 #endif /* CONFIG_AP */
671 if (cmd == NULL || os_strcmp(cmd, "any") == 0) {
674 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
675 if (hwaddr_aton(cmd + 13, p2p_dev_addr)) {
676 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid "
677 "P2P Device Address '%s'",
681 _p2p_dev_addr = p2p_dev_addr;
682 #endif /* CONFIG_P2P */
683 } else if (hwaddr_aton(cmd, bssid)) {
684 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
691 return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid, _p2p_dev_addr);
692 #endif /* CONFIG_AP */
694 return wpas_wps_start_pbc(wpa_s, _bssid, 0);
698 static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s,
699 char *cmd, char *buf,
702 u8 bssid[ETH_ALEN], *_bssid = bssid;
706 pin = os_strchr(cmd, ' ');
710 if (os_strcmp(cmd, "any") == 0)
712 else if (os_strcmp(cmd, "get") == 0) {
713 ret = wps_generate_pin();
715 } else if (hwaddr_aton(cmd, bssid)) {
716 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
722 if (wpa_s->ap_iface) {
727 pos = os_strchr(pin, ' ');
734 return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin,
735 buf, buflen, timeout);
737 #endif /* CONFIG_AP */
740 ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0,
744 ret = os_snprintf(buf, buflen, "%s", pin);
745 if (ret < 0 || (size_t) ret >= buflen)
750 ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0, DEV_PW_DEFAULT);
755 /* Return the generated PIN */
756 ret = os_snprintf(buf, buflen, "%08d", ret);
757 if (ret < 0 || (size_t) ret >= buflen)
763 static int wpa_supplicant_ctrl_iface_wps_check_pin(
764 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
771 wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN",
772 (u8 *) cmd, os_strlen(cmd));
773 for (pos = cmd, len = 0; *pos != '\0'; pos++) {
774 if (*pos < '0' || *pos > '9')
778 wpa_printf(MSG_DEBUG, "WPS: Too long PIN");
782 if (len != 4 && len != 8) {
783 wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len);
789 unsigned int pin_val;
791 if (!wps_pin_valid(pin_val)) {
792 wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit");
793 ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n");
794 if (ret < 0 || (size_t) ret >= buflen)
800 ret = os_snprintf(buf, buflen, "%s", pin);
801 if (ret < 0 || (size_t) ret >= buflen)
808 #ifdef CONFIG_WPS_NFC
810 static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant *wpa_s,
813 u8 bssid[ETH_ALEN], *_bssid = bssid;
815 if (cmd == NULL || cmd[0] == '\0')
817 else if (hwaddr_aton(cmd, bssid))
820 return wpas_wps_start_nfc(wpa_s, NULL, _bssid, NULL, 0, 0, NULL, NULL,
825 static int wpa_supplicant_ctrl_iface_wps_nfc_config_token(
826 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
833 pos = os_strchr(cmd, ' ');
836 if (os_strcmp(cmd, "WPS") == 0)
838 else if (os_strcmp(cmd, "NDEF") == 0)
843 buf = wpas_wps_nfc_config_token(wpa_s, ndef, pos);
847 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
858 static int wpa_supplicant_ctrl_iface_wps_nfc_token(
859 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
865 if (os_strcmp(cmd, "WPS") == 0)
867 else if (os_strcmp(cmd, "NDEF") == 0)
872 buf = wpas_wps_nfc_token(wpa_s, ndef);
876 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
887 static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
888 struct wpa_supplicant *wpa_s, char *pos)
896 freq = strstr(pos, " freq=");
900 forced_freq = atoi(freq);
903 len = os_strlen(pos);
908 buf = wpabuf_alloc(len);
911 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
916 ret = wpas_wps_nfc_tag_read(wpa_s, buf, forced_freq);
923 static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant *wpa_s,
924 char *reply, size_t max_len,
930 buf = wpas_wps_nfc_handover_req(wpa_s, ndef);
934 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
945 static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant *wpa_s,
946 char *reply, size_t max_len,
952 buf = wpas_p2p_nfc_handover_req(wpa_s, ndef);
954 wpa_printf(MSG_DEBUG, "P2P: Could not generate NFC handover request");
958 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
969 static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant *wpa_s,
970 char *cmd, char *reply,
976 pos = os_strchr(cmd, ' ');
981 if (os_strcmp(cmd, "WPS") == 0)
983 else if (os_strcmp(cmd, "NDEF") == 0)
988 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
991 return wpas_ctrl_nfc_get_handover_req_wps(
992 wpa_s, reply, max_len, ndef);
995 if (os_strcmp(pos, "P2P-CR") == 0) {
996 return wpas_ctrl_nfc_get_handover_req_p2p(
997 wpa_s, reply, max_len, ndef);
1004 static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant *wpa_s,
1005 char *reply, size_t max_len,
1006 int ndef, int cr, char *uuid)
1011 buf = wpas_wps_nfc_handover_sel(wpa_s, ndef, cr, uuid);
1015 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1017 reply[res++] = '\n';
1026 static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant *wpa_s,
1027 char *reply, size_t max_len,
1033 buf = wpas_p2p_nfc_handover_sel(wpa_s, ndef, tag);
1037 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1039 reply[res++] = '\n';
1048 static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant *wpa_s,
1049 char *cmd, char *reply,
1055 pos = os_strchr(cmd, ' ');
1060 if (os_strcmp(cmd, "WPS") == 0)
1062 else if (os_strcmp(cmd, "NDEF") == 0)
1067 pos2 = os_strchr(pos, ' ');
1070 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
1073 return wpas_ctrl_nfc_get_handover_sel_wps(
1074 wpa_s, reply, max_len, ndef,
1075 os_strcmp(pos, "WPS-CR") == 0, pos2);
1078 if (os_strcmp(pos, "P2P-CR") == 0) {
1079 return wpas_ctrl_nfc_get_handover_sel_p2p(
1080 wpa_s, reply, max_len, ndef, 0);
1083 if (os_strcmp(pos, "P2P-CR-TAG") == 0) {
1084 return wpas_ctrl_nfc_get_handover_sel_p2p(
1085 wpa_s, reply, max_len, ndef, 1);
1092 static int wpas_ctrl_nfc_rx_handover_req(struct wpa_supplicant *wpa_s,
1093 char *cmd, char *reply,
1100 len = os_strlen(cmd);
1105 buf = wpabuf_alloc(len);
1108 if (hexstr2bin(cmd, wpabuf_put(buf, len), len) < 0) {
1113 ret = wpas_wps_nfc_rx_handover_req(wpa_s, buf);
1120 static int wpas_ctrl_nfc_rx_handover_sel(struct wpa_supplicant *wpa_s,
1127 len = os_strlen(cmd);
1132 buf = wpabuf_alloc(len);
1135 if (hexstr2bin(cmd, wpabuf_put(buf, len), len) < 0) {
1140 ret = wpas_wps_nfc_rx_handover_sel(wpa_s, buf);
1147 static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant *wpa_s,
1151 struct wpabuf *req, *sel;
1153 char *pos, *role, *type, *pos2;
1155 int forced_freq = 0;
1157 freq = strstr(cmd, " freq=");
1161 forced_freq = atoi(freq);
1165 pos = os_strchr(role, ' ');
1167 wpa_printf(MSG_DEBUG, "NFC: Missing type in handover report");
1173 pos = os_strchr(type, ' ');
1175 wpa_printf(MSG_DEBUG, "NFC: Missing request message in handover report");
1180 pos2 = os_strchr(pos, ' ');
1182 wpa_printf(MSG_DEBUG, "NFC: Missing select message in handover report");
1187 len = os_strlen(pos);
1189 wpa_printf(MSG_DEBUG, "NFC: Invalid request message length in handover report");
1194 req = wpabuf_alloc(len);
1196 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for request message");
1199 if (hexstr2bin(pos, wpabuf_put(req, len), len) < 0) {
1200 wpa_printf(MSG_DEBUG, "NFC: Invalid request message hexdump in handover report");
1205 len = os_strlen(pos2);
1207 wpa_printf(MSG_DEBUG, "NFC: Invalid select message length in handover report");
1213 sel = wpabuf_alloc(len);
1215 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for select message");
1219 if (hexstr2bin(pos2, wpabuf_put(sel, len), len) < 0) {
1220 wpa_printf(MSG_DEBUG, "NFC: Invalid select message hexdump in handover report");
1226 wpa_printf(MSG_DEBUG, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d",
1227 role, type, (int) wpabuf_len(req), (int) wpabuf_len(sel));
1229 if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "WPS") == 0) {
1230 ret = wpas_wps_nfc_report_handover(wpa_s, req, sel);
1231 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "WPS") == 0)
1233 ret = wpas_ap_wps_nfc_report_handover(wpa_s, req, sel);
1235 ret = wpas_er_wps_nfc_report_handover(wpa_s, req, sel);
1236 } else if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "P2P") == 0)
1238 ret = wpas_p2p_nfc_report_handover(wpa_s, 1, req, sel, 0);
1239 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "P2P") == 0)
1241 ret = wpas_p2p_nfc_report_handover(wpa_s, 0, req, sel,
1244 wpa_printf(MSG_DEBUG, "NFC: Unsupported connection handover "
1245 "reported: role=%s type=%s", role, type);
1252 wpa_printf(MSG_DEBUG, "NFC: Failed to process reported handover messages");
1257 #endif /* CONFIG_WPS_NFC */
1260 static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s,
1269 struct wps_new_ap_settings ap;
1271 pin = os_strchr(cmd, ' ');
1276 if (hwaddr_aton(cmd, bssid)) {
1277 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
1282 new_ssid = os_strchr(pin, ' ');
1283 if (new_ssid == NULL)
1284 return wpas_wps_start_reg(wpa_s, bssid, pin, NULL);
1287 new_auth = os_strchr(new_ssid, ' ');
1288 if (new_auth == NULL)
1292 new_encr = os_strchr(new_auth, ' ');
1293 if (new_encr == NULL)
1297 new_key = os_strchr(new_encr, ' ');
1298 if (new_key == NULL)
1302 os_memset(&ap, 0, sizeof(ap));
1303 ap.ssid_hex = new_ssid;
1306 ap.key_hex = new_key;
1307 return wpas_wps_start_reg(wpa_s, bssid, pin, &ap);
1312 static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant *wpa_s,
1313 char *cmd, char *buf,
1318 const char *pin_txt;
1320 if (!wpa_s->ap_iface)
1323 pos = os_strchr(cmd, ' ');
1327 if (os_strcmp(cmd, "disable") == 0) {
1328 wpas_wps_ap_pin_disable(wpa_s);
1329 return os_snprintf(buf, buflen, "OK\n");
1332 if (os_strcmp(cmd, "random") == 0) {
1334 timeout = atoi(pos);
1335 pin_txt = wpas_wps_ap_pin_random(wpa_s, timeout);
1336 if (pin_txt == NULL)
1338 return os_snprintf(buf, buflen, "%s", pin_txt);
1341 if (os_strcmp(cmd, "get") == 0) {
1342 pin_txt = wpas_wps_ap_pin_get(wpa_s);
1343 if (pin_txt == NULL)
1345 return os_snprintf(buf, buflen, "%s", pin_txt);
1348 if (os_strcmp(cmd, "set") == 0) {
1353 pos = os_strchr(pos, ' ');
1356 timeout = atoi(pos);
1358 if (os_strlen(pin) > buflen)
1360 if (wpas_wps_ap_pin_set(wpa_s, pin, timeout) < 0)
1362 return os_snprintf(buf, buflen, "%s", pin);
1367 #endif /* CONFIG_AP */
1370 #ifdef CONFIG_WPS_ER
1371 static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant *wpa_s,
1374 char *uuid = cmd, *pin, *pos;
1375 u8 addr_buf[ETH_ALEN], *addr = NULL;
1376 pin = os_strchr(uuid, ' ');
1380 pos = os_strchr(pin, ' ');
1383 if (hwaddr_aton(pos, addr_buf) == 0)
1386 return wpas_wps_er_add_pin(wpa_s, addr, uuid, pin);
1390 static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant *wpa_s,
1393 char *uuid = cmd, *pin;
1394 pin = os_strchr(uuid, ' ');
1398 return wpas_wps_er_learn(wpa_s, uuid, pin);
1402 static int wpa_supplicant_ctrl_iface_wps_er_set_config(
1403 struct wpa_supplicant *wpa_s, char *cmd)
1405 char *uuid = cmd, *id;
1406 id = os_strchr(uuid, ' ');
1410 return wpas_wps_er_set_config(wpa_s, uuid, atoi(id));
1414 static int wpa_supplicant_ctrl_iface_wps_er_config(
1415 struct wpa_supplicant *wpa_s, char *cmd)
1422 struct wps_new_ap_settings ap;
1424 pin = os_strchr(cmd, ' ');
1429 new_ssid = os_strchr(pin, ' ');
1430 if (new_ssid == NULL)
1434 new_auth = os_strchr(new_ssid, ' ');
1435 if (new_auth == NULL)
1439 new_encr = os_strchr(new_auth, ' ');
1440 if (new_encr == NULL)
1444 new_key = os_strchr(new_encr, ' ');
1445 if (new_key == NULL)
1449 os_memset(&ap, 0, sizeof(ap));
1450 ap.ssid_hex = new_ssid;
1453 ap.key_hex = new_key;
1454 return wpas_wps_er_config(wpa_s, cmd, pin, &ap);
1458 #ifdef CONFIG_WPS_NFC
1459 static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
1460 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1467 uuid = os_strchr(cmd, ' ');
1472 if (os_strcmp(cmd, "WPS") == 0)
1474 else if (os_strcmp(cmd, "NDEF") == 0)
1479 buf = wpas_wps_er_nfc_config_token(wpa_s, ndef, uuid);
1483 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1485 reply[res++] = '\n';
1492 #endif /* CONFIG_WPS_NFC */
1493 #endif /* CONFIG_WPS_ER */
1495 #endif /* CONFIG_WPS */
1498 #ifdef CONFIG_IBSS_RSN
1499 static int wpa_supplicant_ctrl_iface_ibss_rsn(
1500 struct wpa_supplicant *wpa_s, char *addr)
1504 if (hwaddr_aton(addr, peer)) {
1505 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN: invalid "
1506 "address '%s'", addr);
1510 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN " MACSTR,
1513 return ibss_rsn_start(wpa_s->ibss_rsn, peer);
1515 #endif /* CONFIG_IBSS_RSN */
1518 static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s,
1521 #ifdef IEEE8021X_EAPOL
1524 struct wpa_ssid *ssid;
1526 pos = os_strchr(rsp, '-');
1531 pos = os_strchr(pos, ':');
1536 wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id);
1537 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
1538 (u8 *) pos, os_strlen(pos));
1540 ssid = wpa_config_get_network(wpa_s->conf, id);
1542 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
1547 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s, ssid, rsp,
1549 #else /* IEEE8021X_EAPOL */
1550 wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included");
1552 #endif /* IEEE8021X_EAPOL */
1556 static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
1558 char *buf, size_t buflen)
1560 char *pos, *end, tmp[30];
1561 int res, verbose, wps, ret;
1563 if (os_strcmp(params, "-DRIVER") == 0)
1564 return wpa_drv_status(wpa_s, buf, buflen);
1565 verbose = os_strcmp(params, "-VERBOSE") == 0;
1566 wps = os_strcmp(params, "-WPS") == 0;
1569 if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
1570 struct wpa_ssid *ssid = wpa_s->current_ssid;
1571 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
1572 MAC2STR(wpa_s->bssid));
1573 if (ret < 0 || ret >= end - pos)
1577 u8 *_ssid = ssid->ssid;
1578 size_t ssid_len = ssid->ssid_len;
1579 u8 ssid_buf[MAX_SSID_LEN];
1580 if (ssid_len == 0) {
1581 int _res = wpa_drv_get_ssid(wpa_s, ssid_buf);
1588 ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n",
1589 wpa_ssid_txt(_ssid, ssid_len),
1591 if (ret < 0 || ret >= end - pos)
1595 if (wps && ssid->passphrase &&
1596 wpa_key_mgmt_wpa_psk(ssid->key_mgmt) &&
1597 (ssid->mode == WPAS_MODE_AP ||
1598 ssid->mode == WPAS_MODE_P2P_GO)) {
1599 ret = os_snprintf(pos, end - pos,
1602 if (ret < 0 || ret >= end - pos)
1607 ret = os_snprintf(pos, end - pos,
1610 if (ret < 0 || ret >= end - pos)
1615 switch (ssid->mode) {
1616 case WPAS_MODE_INFRA:
1617 ret = os_snprintf(pos, end - pos,
1620 case WPAS_MODE_IBSS:
1621 ret = os_snprintf(pos, end - pos,
1625 ret = os_snprintf(pos, end - pos,
1628 case WPAS_MODE_P2P_GO:
1629 ret = os_snprintf(pos, end - pos,
1632 case WPAS_MODE_P2P_GROUP_FORMATION:
1633 ret = os_snprintf(pos, end - pos,
1634 "mode=P2P GO - group "
1641 if (ret < 0 || ret >= end - pos)
1647 if (wpa_s->ap_iface) {
1648 pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos,
1652 #endif /* CONFIG_AP */
1653 pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose);
1656 if (wpa_s->wpa_state >= WPA_ASSOCIATED &&
1659 #endif /* CONFIG_AP */
1660 wpa_s->sme.sae.state == SAE_ACCEPTED) {
1661 ret = os_snprintf(pos, end - pos, "sae_group=%d\n",
1662 wpa_s->sme.sae.group);
1663 if (ret < 0 || ret >= end - pos)
1667 #endif /* CONFIG_SAE */
1668 ret = os_snprintf(pos, end - pos, "wpa_state=%s\n",
1669 wpa_supplicant_state_txt(wpa_s->wpa_state));
1670 if (ret < 0 || ret >= end - pos)
1675 l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) {
1676 ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp);
1677 if (ret < 0 || ret >= end - pos)
1683 if (wpa_s->global->p2p) {
1684 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
1685 "\n", MAC2STR(wpa_s->global->p2p_dev_addr));
1686 if (ret < 0 || ret >= end - pos)
1690 #endif /* CONFIG_P2P */
1692 ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n",
1693 MAC2STR(wpa_s->own_addr));
1694 if (ret < 0 || ret >= end - pos)
1699 if (wpa_s->current_bss &&
1700 wpa_bss_get_vendor_ie(wpa_s->current_bss, HS20_IE_VENDOR_TYPE) &&
1701 wpa_s->wpa_proto == WPA_PROTO_RSN &&
1702 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1703 ret = os_snprintf(pos, end - pos, "hs20=1\n");
1704 if (ret < 0 || ret >= end - pos)
1709 if (wpa_s->current_ssid) {
1710 struct wpa_cred *cred;
1713 for (cred = wpa_s->conf->cred; cred; cred = cred->next) {
1716 if (wpa_s->current_ssid->parent_cred != cred)
1719 for (i = 0; cred->domain && i < cred->num_domain; i++) {
1720 ret = os_snprintf(pos, end - pos,
1723 if (ret < 0 || ret >= end - pos)
1728 if (wpa_s->current_bss == NULL ||
1729 wpa_s->current_bss->anqp == NULL)
1732 res = interworking_home_sp_cred(
1734 wpa_s->current_bss->anqp->domain_name);
1742 ret = os_snprintf(pos, end - pos, "sp_type=%s\n", type);
1743 if (ret < 0 || ret >= end - pos)
1750 #endif /* CONFIG_HS20 */
1752 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
1753 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
1754 res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos,
1760 res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose);
1767 uuid_bin2str(wpa_s->wps->uuid, uuid_str, sizeof(uuid_str));
1768 ret = os_snprintf(pos, end - pos, "uuid=%s\n", uuid_str);
1769 if (ret < 0 || ret >= end - pos)
1773 #endif /* CONFIG_WPS */
1776 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_STATE_CHANGE
1777 "id=%d state=%d BSSID=" MACSTR " SSID=%s",
1778 wpa_s->current_ssid ? wpa_s->current_ssid->id : -1,
1780 MAC2STR(wpa_s->bssid),
1781 wpa_s->current_ssid && wpa_s->current_ssid->ssid ?
1782 wpa_ssid_txt(wpa_s->current_ssid->ssid,
1783 wpa_s->current_ssid->ssid_len) : "");
1784 if (wpa_s->wpa_state == WPA_COMPLETED) {
1785 struct wpa_ssid *ssid = wpa_s->current_ssid;
1786 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_CONNECTED
1787 "- connection to " MACSTR
1788 " completed %s [id=%d id_str=%s]",
1789 MAC2STR(wpa_s->bssid), "(auth)",
1790 ssid ? ssid->id : -1,
1791 ssid && ssid->id_str ? ssid->id_str : "");
1793 #endif /* ANDROID */
1799 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s,
1804 struct wpa_ssid *ssid;
1807 /* cmd: "<network id> <BSSID>" */
1808 pos = os_strchr(cmd, ' ');
1813 wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos);
1814 if (hwaddr_aton(pos, bssid)) {
1815 wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos);
1819 ssid = wpa_config_get_network(wpa_s->conf, id);
1821 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
1826 os_memcpy(ssid->bssid, bssid, ETH_ALEN);
1827 ssid->bssid_set = !is_zero_ether_addr(bssid);
1833 static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant *wpa_s,
1834 char *cmd, char *buf,
1838 struct wpa_blacklist *e;
1842 /* cmd: "BLACKLIST [<BSSID>]" */
1846 e = wpa_s->blacklist;
1848 ret = os_snprintf(pos, end - pos, MACSTR "\n",
1850 if (ret < 0 || ret >= end - pos)
1859 if (os_strncmp(cmd, "clear", 5) == 0) {
1860 wpa_blacklist_clear(wpa_s);
1861 os_memcpy(buf, "OK\n", 3);
1865 wpa_printf(MSG_DEBUG, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd);
1866 if (hwaddr_aton(cmd, bssid)) {
1867 wpa_printf(MSG_DEBUG, "CTRL_IFACE: invalid BSSID '%s'", cmd);
1872 * Add the BSSID twice, so its count will be 2, causing it to be
1873 * skipped when processing scan results.
1875 ret = wpa_blacklist_add(wpa_s, bssid);
1878 ret = wpa_blacklist_add(wpa_s, bssid);
1881 os_memcpy(buf, "OK\n", 3);
1886 static const char * debug_level_str(int level)
1907 static int str_to_debug_level(const char *s)
1909 if (os_strcasecmp(s, "EXCESSIVE") == 0)
1910 return MSG_EXCESSIVE;
1911 if (os_strcasecmp(s, "MSGDUMP") == 0)
1913 if (os_strcasecmp(s, "DEBUG") == 0)
1915 if (os_strcasecmp(s, "INFO") == 0)
1917 if (os_strcasecmp(s, "WARNING") == 0)
1919 if (os_strcasecmp(s, "ERROR") == 0)
1925 static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant *wpa_s,
1926 char *cmd, char *buf,
1929 char *pos, *end, *stamp;
1936 /* cmd: "LOG_LEVEL [<level>]" */
1940 ret = os_snprintf(pos, end - pos, "Current level: %s\n"
1942 debug_level_str(wpa_debug_level),
1943 wpa_debug_timestamp);
1944 if (ret < 0 || ret >= end - pos)
1953 stamp = os_strchr(cmd, ' ');
1956 while (*stamp == ' ') {
1961 if (cmd && os_strlen(cmd)) {
1962 int level = str_to_debug_level(cmd);
1965 wpa_debug_level = level;
1968 if (stamp && os_strlen(stamp))
1969 wpa_debug_timestamp = atoi(stamp);
1971 os_memcpy(buf, "OK\n", 3);
1976 static int wpa_supplicant_ctrl_iface_list_networks(
1977 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
1980 struct wpa_ssid *ssid;
1985 ret = os_snprintf(pos, end - pos,
1986 "network id / ssid / bssid / flags\n");
1987 if (ret < 0 || ret >= end - pos)
1991 ssid = wpa_s->conf->ssid;
1993 ret = os_snprintf(pos, end - pos, "%d\t%s",
1995 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
1996 if (ret < 0 || ret >= end - pos)
1999 if (ssid->bssid_set) {
2000 ret = os_snprintf(pos, end - pos, "\t" MACSTR,
2001 MAC2STR(ssid->bssid));
2003 ret = os_snprintf(pos, end - pos, "\tany");
2005 if (ret < 0 || ret >= end - pos)
2008 ret = os_snprintf(pos, end - pos, "\t%s%s%s%s",
2009 ssid == wpa_s->current_ssid ?
2011 ssid->disabled ? "[DISABLED]" : "",
2012 ssid->disabled_until.sec ?
2013 "[TEMP-DISABLED]" : "",
2014 ssid->disabled == 2 ? "[P2P-PERSISTENT]" :
2016 if (ret < 0 || ret >= end - pos)
2019 ret = os_snprintf(pos, end - pos, "\n");
2020 if (ret < 0 || ret >= end - pos)
2031 static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher)
2034 ret = os_snprintf(pos, end - pos, "-");
2035 if (ret < 0 || ret >= end - pos)
2038 ret = wpa_write_ciphers(pos, end, cipher, "+");
2046 static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
2047 const u8 *ie, size_t ie_len)
2049 struct wpa_ie_data data;
2052 ret = os_snprintf(pos, end - pos, "[%s-", proto);
2053 if (ret < 0 || ret >= end - pos)
2057 if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) {
2058 ret = os_snprintf(pos, end - pos, "?]");
2059 if (ret < 0 || ret >= end - pos)
2066 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
2067 ret = os_snprintf(pos, end - pos, "%sEAP", first ? "" : "+");
2068 if (ret < 0 || ret >= end - pos)
2073 if (data.key_mgmt & WPA_KEY_MGMT_PSK) {
2074 ret = os_snprintf(pos, end - pos, "%sPSK", first ? "" : "+");
2075 if (ret < 0 || ret >= end - pos)
2080 if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
2081 ret = os_snprintf(pos, end - pos, "%sNone", first ? "" : "+");
2082 if (ret < 0 || ret >= end - pos)
2087 #ifdef CONFIG_IEEE80211R
2088 if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
2089 ret = os_snprintf(pos, end - pos, "%sFT/EAP",
2091 if (ret < 0 || ret >= end - pos)
2096 if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) {
2097 ret = os_snprintf(pos, end - pos, "%sFT/PSK",
2099 if (ret < 0 || ret >= end - pos)
2104 #endif /* CONFIG_IEEE80211R */
2105 #ifdef CONFIG_IEEE80211W
2106 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
2107 ret = os_snprintf(pos, end - pos, "%sEAP-SHA256",
2109 if (ret < 0 || ret >= end - pos)
2114 if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
2115 ret = os_snprintf(pos, end - pos, "%sPSK-SHA256",
2117 if (ret < 0 || ret >= end - pos)
2122 #endif /* CONFIG_IEEE80211W */
2124 pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher);
2126 if (data.capabilities & WPA_CAPABILITY_PREAUTH) {
2127 ret = os_snprintf(pos, end - pos, "-preauth");
2128 if (ret < 0 || ret >= end - pos)
2133 ret = os_snprintf(pos, end - pos, "]");
2134 if (ret < 0 || ret >= end - pos)
2143 static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s,
2144 char *pos, char *end,
2145 struct wpabuf *wps_ie)
2152 if (wps_is_selected_pbc_registrar(wps_ie))
2155 else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0))
2157 #endif /* CONFIG_WPS2 */
2158 else if (wps_is_selected_pin_registrar(wps_ie))
2163 ret = os_snprintf(pos, end - pos, "%s", txt);
2164 if (ret >= 0 && ret < end - pos)
2166 wpabuf_free(wps_ie);
2169 #endif /* CONFIG_WPS */
2172 static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s,
2173 char *pos, char *end,
2174 const struct wpa_bss *bss)
2177 struct wpabuf *wps_ie;
2178 wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
2179 return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie);
2180 #else /* CONFIG_WPS */
2182 #endif /* CONFIG_WPS */
2186 /* Format one result on one text line into a buffer. */
2187 static int wpa_supplicant_ctrl_iface_scan_result(
2188 struct wpa_supplicant *wpa_s,
2189 const struct wpa_bss *bss, char *buf, size_t buflen)
2193 const u8 *ie, *ie2, *p2p;
2195 p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
2197 p2p = wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE);
2198 if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN &&
2199 os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) ==
2201 return 0; /* Do not show P2P listen discovery results here */
2206 ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t",
2207 MAC2STR(bss->bssid), bss->freq, bss->level);
2208 if (ret < 0 || ret >= end - pos)
2211 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
2213 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]);
2214 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
2216 pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2, 2 + ie2[1]);
2217 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
2218 if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
2219 ret = os_snprintf(pos, end - pos, "[WEP]");
2220 if (ret < 0 || ret >= end - pos)
2224 if (bss->caps & IEEE80211_CAP_IBSS) {
2225 ret = os_snprintf(pos, end - pos, "[IBSS]");
2226 if (ret < 0 || ret >= end - pos)
2230 if (bss->caps & IEEE80211_CAP_ESS) {
2231 ret = os_snprintf(pos, end - pos, "[ESS]");
2232 if (ret < 0 || ret >= end - pos)
2237 ret = os_snprintf(pos, end - pos, "[P2P]");
2238 if (ret < 0 || ret >= end - pos)
2243 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE) && ie2) {
2244 ret = os_snprintf(pos, end - pos, "[HS20]");
2245 if (ret < 0 || ret >= end - pos)
2249 #endif /* CONFIG_HS20 */
2251 ret = os_snprintf(pos, end - pos, "\t%s",
2252 wpa_ssid_txt(bss->ssid, bss->ssid_len));
2253 if (ret < 0 || ret >= end - pos)
2257 ret = os_snprintf(pos, end - pos, "\n");
2258 if (ret < 0 || ret >= end - pos)
2266 static int wpa_supplicant_ctrl_iface_scan_results(
2267 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
2270 struct wpa_bss *bss;
2275 ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / "
2277 if (ret < 0 || ret >= end - pos)
2281 dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
2282 ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos,
2284 if (ret < 0 || ret >= end - pos)
2293 static int wpa_supplicant_ctrl_iface_select_network(
2294 struct wpa_supplicant *wpa_s, char *cmd)
2297 struct wpa_ssid *ssid;
2299 /* cmd: "<network id>" or "any" */
2300 if (os_strcmp(cmd, "any") == 0) {
2301 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any");
2305 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id);
2307 ssid = wpa_config_get_network(wpa_s->conf, id);
2309 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2310 "network id=%d", id);
2313 if (ssid->disabled == 2) {
2314 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2315 "SELECT_NETWORK with persistent P2P group");
2320 wpa_supplicant_select_network(wpa_s, ssid);
2326 static int wpa_supplicant_ctrl_iface_enable_network(
2327 struct wpa_supplicant *wpa_s, char *cmd)
2330 struct wpa_ssid *ssid;
2332 /* cmd: "<network id>" or "all" */
2333 if (os_strcmp(cmd, "all") == 0) {
2334 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all");
2338 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id);
2340 ssid = wpa_config_get_network(wpa_s->conf, id);
2342 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2343 "network id=%d", id);
2346 if (ssid->disabled == 2) {
2347 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2348 "ENABLE_NETWORK with persistent P2P group");
2352 if (os_strstr(cmd, " no-connect")) {
2357 wpa_supplicant_enable_network(wpa_s, ssid);
2363 static int wpa_supplicant_ctrl_iface_disable_network(
2364 struct wpa_supplicant *wpa_s, char *cmd)
2367 struct wpa_ssid *ssid;
2369 /* cmd: "<network id>" or "all" */
2370 if (os_strcmp(cmd, "all") == 0) {
2371 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all");
2375 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id);
2377 ssid = wpa_config_get_network(wpa_s->conf, id);
2379 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2380 "network id=%d", id);
2383 if (ssid->disabled == 2) {
2384 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2385 "DISABLE_NETWORK with persistent P2P "
2390 wpa_supplicant_disable_network(wpa_s, ssid);
2396 static int wpa_supplicant_ctrl_iface_add_network(
2397 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
2399 struct wpa_ssid *ssid;
2402 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK");
2404 ssid = wpa_config_add_network(wpa_s->conf);
2408 wpas_notify_network_added(wpa_s, ssid);
2411 wpa_config_set_network_defaults(ssid);
2413 ret = os_snprintf(buf, buflen, "%d\n", ssid->id);
2414 if (ret < 0 || (size_t) ret >= buflen)
2420 static int wpa_supplicant_ctrl_iface_remove_network(
2421 struct wpa_supplicant *wpa_s, char *cmd)
2424 struct wpa_ssid *ssid;
2427 /* cmd: "<network id>" or "all" */
2428 if (os_strcmp(cmd, "all") == 0) {
2429 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all");
2430 if (wpa_s->sched_scanning)
2431 wpa_supplicant_cancel_sched_scan(wpa_s);
2433 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2434 if (wpa_s->current_ssid) {
2436 wpa_s->sme.prev_bssid_set = 0;
2437 #endif /* CONFIG_SME */
2438 wpa_sm_set_config(wpa_s->wpa, NULL);
2439 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
2440 wpa_supplicant_deauthenticate(
2441 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2443 ssid = wpa_s->conf->ssid;
2445 struct wpa_ssid *remove_ssid = ssid;
2448 wpas_notify_network_removed(wpa_s, remove_ssid);
2449 wpa_config_remove_network(wpa_s->conf, id);
2455 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id);
2457 ssid = wpa_config_get_network(wpa_s->conf, id);
2459 wpas_notify_network_removed(wpa_s, ssid);
2461 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2466 if (ssid == wpa_s->current_ssid || wpa_s->current_ssid == NULL) {
2468 wpa_s->sme.prev_bssid_set = 0;
2469 #endif /* CONFIG_SME */
2471 * Invalidate the EAP session cache if the current or
2472 * previously used network is removed.
2474 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2477 if (ssid == wpa_s->current_ssid) {
2478 wpa_sm_set_config(wpa_s->wpa, NULL);
2479 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
2481 wpa_supplicant_deauthenticate(wpa_s,
2482 WLAN_REASON_DEAUTH_LEAVING);
2485 was_disabled = ssid->disabled;
2487 if (wpa_config_remove_network(wpa_s->conf, id) < 0) {
2488 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Not able to remove the "
2489 "network id=%d", id);
2493 if (!was_disabled && wpa_s->sched_scanning) {
2494 wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to remove "
2495 "network from filters");
2496 wpa_supplicant_cancel_sched_scan(wpa_s);
2497 wpa_supplicant_req_scan(wpa_s, 0, 0);
2504 static int wpa_supplicant_ctrl_iface_set_network(
2505 struct wpa_supplicant *wpa_s, char *cmd)
2508 struct wpa_ssid *ssid;
2511 /* cmd: "<network id> <variable name> <value>" */
2512 name = os_strchr(cmd, ' ');
2517 value = os_strchr(name, ' ');
2523 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
2525 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
2526 (u8 *) value, os_strlen(value));
2528 ssid = wpa_config_get_network(wpa_s->conf, id);
2530 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2535 if (wpa_config_set(ssid, name, value, 0) < 0) {
2536 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network "
2537 "variable '%s'", name);
2541 if (os_strcmp(name, "bssid") != 0 &&
2542 os_strcmp(name, "priority") != 0)
2543 wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
2545 if (wpa_s->current_ssid == ssid || wpa_s->current_ssid == NULL) {
2547 * Invalidate the EAP session cache if anything in the current
2548 * or previously used configuration changes.
2550 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2553 if ((os_strcmp(name, "psk") == 0 &&
2554 value[0] == '"' && ssid->ssid_len) ||
2555 (os_strcmp(name, "ssid") == 0 && ssid->passphrase))
2556 wpa_config_update_psk(ssid);
2557 else if (os_strcmp(name, "priority") == 0)
2558 wpa_config_update_prio_list(wpa_s->conf);
2564 static int wpa_supplicant_ctrl_iface_get_network(
2565 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
2569 struct wpa_ssid *ssid;
2572 /* cmd: "<network id> <variable name>" */
2573 name = os_strchr(cmd, ' ');
2574 if (name == NULL || buflen == 0)
2579 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
2582 ssid = wpa_config_get_network(wpa_s->conf, id);
2584 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2589 value = wpa_config_get_no_key(ssid, name);
2590 if (value == NULL) {
2591 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
2592 "variable '%s'", name);
2596 res = os_strlcpy(buf, value, buflen);
2597 if (res >= buflen) {
2608 static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant *wpa_s,
2609 char *buf, size_t buflen)
2612 struct wpa_cred *cred;
2617 ret = os_snprintf(pos, end - pos,
2618 "cred id / realm / username / domain / imsi\n");
2619 if (ret < 0 || ret >= end - pos)
2623 cred = wpa_s->conf->cred;
2625 ret = os_snprintf(pos, end - pos, "%d\t%s\t%s\t%s\t%s\n",
2626 cred->id, cred->realm ? cred->realm : "",
2627 cred->username ? cred->username : "",
2628 cred->domain ? cred->domain[0] : "",
2629 cred->imsi ? cred->imsi : "");
2630 if (ret < 0 || ret >= end - pos)
2641 static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant *wpa_s,
2642 char *buf, size_t buflen)
2644 struct wpa_cred *cred;
2647 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_CRED");
2649 cred = wpa_config_add_cred(wpa_s->conf);
2653 ret = os_snprintf(buf, buflen, "%d\n", cred->id);
2654 if (ret < 0 || (size_t) ret >= buflen)
2660 static int wpas_ctrl_remove_cred(struct wpa_supplicant *wpa_s,
2661 struct wpa_cred *cred)
2663 struct wpa_ssid *ssid;
2666 if (cred == NULL || wpa_config_remove_cred(wpa_s->conf, cred->id) < 0) {
2667 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred");
2671 /* Remove any network entry created based on the removed credential */
2672 ssid = wpa_s->conf->ssid;
2674 if (ssid->parent_cred == cred) {
2675 wpa_printf(MSG_DEBUG, "Remove network id %d since it "
2676 "used the removed credential", ssid->id);
2677 os_snprintf(str, sizeof(str), "%d", ssid->id);
2679 wpa_supplicant_ctrl_iface_remove_network(wpa_s, str);
2688 static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s,
2692 struct wpa_cred *cred, *prev;
2694 /* cmd: "<cred id>", "all", or "sp_fqdn=<FQDN>" */
2695 if (os_strcmp(cmd, "all") == 0) {
2696 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED all");
2697 cred = wpa_s->conf->cred;
2701 wpas_ctrl_remove_cred(wpa_s, prev);
2706 if (os_strncmp(cmd, "sp_fqdn=", 8) == 0) {
2707 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
2709 cred = wpa_s->conf->cred;
2715 for (i = 0; i < prev->num_domain; i++) {
2716 if (os_strcmp(prev->domain[i], cmd + 8)
2719 wpas_ctrl_remove_cred(wpa_s, prev);
2728 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED id=%d", id);
2730 cred = wpa_config_get_cred(wpa_s->conf, id);
2731 return wpas_ctrl_remove_cred(wpa_s, cred);
2735 static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant *wpa_s,
2739 struct wpa_cred *cred;
2742 /* cmd: "<cred id> <variable name> <value>" */
2743 name = os_strchr(cmd, ' ');
2748 value = os_strchr(name, ' ');
2754 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_CRED id=%d name='%s'",
2756 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
2757 (u8 *) value, os_strlen(value));
2759 cred = wpa_config_get_cred(wpa_s->conf, id);
2761 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
2766 if (wpa_config_set_cred(cred, name, value, 0) < 0) {
2767 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set cred "
2768 "variable '%s'", name);
2776 #ifndef CONFIG_NO_CONFIG_WRITE
2777 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s)
2781 if (!wpa_s->conf->update_config) {
2782 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
2783 "to update configuration (update_config=0)");
2787 ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
2789 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to "
2790 "update configuration");
2792 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration"
2798 #endif /* CONFIG_NO_CONFIG_WRITE */
2801 struct cipher_info {
2807 static const struct cipher_info ciphers[] = {
2808 { WPA_DRIVER_CAPA_ENC_CCMP_256, "CCMP-256", 0 },
2809 { WPA_DRIVER_CAPA_ENC_GCMP_256, "GCMP-256", 0 },
2810 { WPA_DRIVER_CAPA_ENC_CCMP, "CCMP", 0 },
2811 { WPA_DRIVER_CAPA_ENC_GCMP, "GCMP", 0 },
2812 { WPA_DRIVER_CAPA_ENC_TKIP, "TKIP", 0 },
2813 { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE, "NONE", 0 },
2814 { WPA_DRIVER_CAPA_ENC_WEP104, "WEP104", 1 },
2815 { WPA_DRIVER_CAPA_ENC_WEP40, "WEP40", 1 }
2819 static int ctrl_iface_get_capability_pairwise(int res, char *strict,
2820 struct wpa_driver_capa *capa,
2821 char *buf, size_t buflen)
2834 len = os_strlcpy(buf, "CCMP TKIP NONE", buflen);
2840 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
2841 if (!ciphers[i].group_only && capa->enc & ciphers[i].capa) {
2842 ret = os_snprintf(pos, end - pos, "%s%s",
2843 first ? "" : " ", ciphers[i].name);
2844 if (ret < 0 || ret >= end - pos)
2855 static int ctrl_iface_get_capability_group(int res, char *strict,
2856 struct wpa_driver_capa *capa,
2857 char *buf, size_t buflen)
2870 len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen);
2876 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
2877 if (capa->enc & ciphers[i].capa) {
2878 ret = os_snprintf(pos, end - pos, "%s%s",
2879 first ? "" : " ", ciphers[i].name);
2880 if (ret < 0 || ret >= end - pos)
2891 static int ctrl_iface_get_capability_key_mgmt(int res, char *strict,
2892 struct wpa_driver_capa *capa,
2893 char *buf, size_t buflen)
2905 len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
2912 ret = os_snprintf(pos, end - pos, "NONE IEEE8021X");
2913 if (ret < 0 || ret >= end - pos)
2917 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
2918 WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
2919 ret = os_snprintf(pos, end - pos, " WPA-EAP");
2920 if (ret < 0 || ret >= end - pos)
2925 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
2926 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
2927 ret = os_snprintf(pos, end - pos, " WPA-PSK");
2928 if (ret < 0 || ret >= end - pos)
2933 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
2934 ret = os_snprintf(pos, end - pos, " WPA-NONE");
2935 if (ret < 0 || ret >= end - pos)
2944 static int ctrl_iface_get_capability_proto(int res, char *strict,
2945 struct wpa_driver_capa *capa,
2946 char *buf, size_t buflen)
2958 len = os_strlcpy(buf, "RSN WPA", buflen);
2964 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
2965 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
2966 ret = os_snprintf(pos, end - pos, "%sRSN", first ? "" : " ");
2967 if (ret < 0 || ret >= end - pos)
2973 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
2974 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
2975 ret = os_snprintf(pos, end - pos, "%sWPA", first ? "" : " ");
2976 if (ret < 0 || ret >= end - pos)
2986 static int ctrl_iface_get_capability_auth_alg(int res, char *strict,
2987 struct wpa_driver_capa *capa,
2988 char *buf, size_t buflen)
3000 len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen);
3006 if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) {
3007 ret = os_snprintf(pos, end - pos, "%sOPEN", first ? "" : " ");
3008 if (ret < 0 || ret >= end - pos)
3014 if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) {
3015 ret = os_snprintf(pos, end - pos, "%sSHARED",
3017 if (ret < 0 || ret >= end - pos)
3023 if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) {
3024 ret = os_snprintf(pos, end - pos, "%sLEAP", first ? "" : " ");
3025 if (ret < 0 || ret >= end - pos)
3035 static int ctrl_iface_get_capability_modes(int res, char *strict,
3036 struct wpa_driver_capa *capa,
3037 char *buf, size_t buflen)
3049 len = os_strlcpy(buf, "IBSS AP", buflen);
3055 if (capa->flags & WPA_DRIVER_FLAGS_IBSS) {
3056 ret = os_snprintf(pos, end - pos, "%sIBSS", first ? "" : " ");
3057 if (ret < 0 || ret >= end - pos)
3063 if (capa->flags & WPA_DRIVER_FLAGS_AP) {
3064 ret = os_snprintf(pos, end - pos, "%sAP", first ? "" : " ");
3065 if (ret < 0 || ret >= end - pos)
3075 static int ctrl_iface_get_capability_channels(struct wpa_supplicant *wpa_s,
3076 char *buf, size_t buflen)
3078 struct hostapd_channel_data *chnl;
3080 char *pos, *end, *hmode;
3085 for (j = 0; j < wpa_s->hw.num_modes; j++) {
3086 switch (wpa_s->hw.modes[j].mode) {
3087 case HOSTAPD_MODE_IEEE80211B:
3090 case HOSTAPD_MODE_IEEE80211G:
3093 case HOSTAPD_MODE_IEEE80211A:
3096 case HOSTAPD_MODE_IEEE80211AD:
3102 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:", hmode);
3103 if (ret < 0 || ret >= end - pos)
3106 chnl = wpa_s->hw.modes[j].channels;
3107 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
3108 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
3110 ret = os_snprintf(pos, end - pos, " %d", chnl[i].chan);
3111 if (ret < 0 || ret >= end - pos)
3115 ret = os_snprintf(pos, end - pos, "\n");
3116 if (ret < 0 || ret >= end - pos)
3125 static int ctrl_iface_get_capability_freq(struct wpa_supplicant *wpa_s,
3126 char *buf, size_t buflen)
3128 struct hostapd_channel_data *chnl;
3130 char *pos, *end, *hmode;
3135 for (j = 0; j < wpa_s->hw.num_modes; j++) {
3136 switch (wpa_s->hw.modes[j].mode) {
3137 case HOSTAPD_MODE_IEEE80211B:
3140 case HOSTAPD_MODE_IEEE80211G:
3143 case HOSTAPD_MODE_IEEE80211A:
3146 case HOSTAPD_MODE_IEEE80211AD:
3152 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:\n",
3154 if (ret < 0 || ret >= end - pos)
3157 chnl = wpa_s->hw.modes[j].channels;
3158 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
3159 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
3161 ret = os_snprintf(pos, end - pos, " %d = %d MHz%s\n",
3162 chnl[i].chan, chnl[i].freq,
3163 chnl[i].flag & HOSTAPD_CHAN_NO_IBSS ?
3165 if (ret < 0 || ret >= end - pos)
3169 ret = os_snprintf(pos, end - pos, "\n");
3170 if (ret < 0 || ret >= end - pos)
3179 static int wpa_supplicant_ctrl_iface_get_capability(
3180 struct wpa_supplicant *wpa_s, const char *_field, char *buf,
3183 struct wpa_driver_capa capa;
3189 /* Determine whether or not strict checking was requested */
3190 len = os_strlcpy(field, _field, sizeof(field));
3191 if (len >= sizeof(field))
3193 strict = os_strchr(field, ' ');
3194 if (strict != NULL) {
3196 if (os_strcmp(strict, "strict") != 0)
3200 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
3201 field, strict ? strict : "");
3203 if (os_strcmp(field, "eap") == 0) {
3204 return eap_get_names(buf, buflen);
3207 res = wpa_drv_get_capa(wpa_s, &capa);
3209 if (os_strcmp(field, "pairwise") == 0)
3210 return ctrl_iface_get_capability_pairwise(res, strict, &capa,
3213 if (os_strcmp(field, "group") == 0)
3214 return ctrl_iface_get_capability_group(res, strict, &capa,
3217 if (os_strcmp(field, "key_mgmt") == 0)
3218 return ctrl_iface_get_capability_key_mgmt(res, strict, &capa,
3221 if (os_strcmp(field, "proto") == 0)
3222 return ctrl_iface_get_capability_proto(res, strict, &capa,
3225 if (os_strcmp(field, "auth_alg") == 0)
3226 return ctrl_iface_get_capability_auth_alg(res, strict, &capa,
3229 if (os_strcmp(field, "modes") == 0)
3230 return ctrl_iface_get_capability_modes(res, strict, &capa,
3233 if (os_strcmp(field, "channels") == 0)
3234 return ctrl_iface_get_capability_channels(wpa_s, buf, buflen);
3236 if (os_strcmp(field, "freq") == 0)
3237 return ctrl_iface_get_capability_freq(wpa_s, buf, buflen);
3239 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
3246 #ifdef CONFIG_INTERWORKING
3247 static char * anqp_add_hex(char *pos, char *end, const char *title,
3248 struct wpabuf *data)
3258 ret = os_snprintf(pos, end - pos, "%s=", title);
3259 if (ret < 0 || ret >= end - pos)
3263 d = wpabuf_head_u8(data);
3264 for (i = 0; i < wpabuf_len(data); i++) {
3265 ret = os_snprintf(pos, end - pos, "%02x", *d++);
3266 if (ret < 0 || ret >= end - pos)
3271 ret = os_snprintf(pos, end - pos, "\n");
3272 if (ret < 0 || ret >= end - pos)
3278 #endif /* CONFIG_INTERWORKING */
3281 static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
3282 unsigned long mask, char *buf, size_t buflen)
3292 if (mask & WPA_BSS_MASK_ID) {
3293 ret = os_snprintf(pos, end - pos, "id=%u\n", bss->id);
3294 if (ret < 0 || ret >= end - pos)
3299 if (mask & WPA_BSS_MASK_BSSID) {
3300 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
3301 MAC2STR(bss->bssid));
3302 if (ret < 0 || ret >= end - pos)
3307 if (mask & WPA_BSS_MASK_FREQ) {
3308 ret = os_snprintf(pos, end - pos, "freq=%d\n", bss->freq);
3309 if (ret < 0 || ret >= end - pos)
3314 if (mask & WPA_BSS_MASK_BEACON_INT) {
3315 ret = os_snprintf(pos, end - pos, "beacon_int=%d\n",
3317 if (ret < 0 || ret >= end - pos)
3322 if (mask & WPA_BSS_MASK_CAPABILITIES) {
3323 ret = os_snprintf(pos, end - pos, "capabilities=0x%04x\n",
3325 if (ret < 0 || ret >= end - pos)
3330 if (mask & WPA_BSS_MASK_QUAL) {
3331 ret = os_snprintf(pos, end - pos, "qual=%d\n", bss->qual);
3332 if (ret < 0 || ret >= end - pos)
3337 if (mask & WPA_BSS_MASK_NOISE) {
3338 ret = os_snprintf(pos, end - pos, "noise=%d\n", bss->noise);
3339 if (ret < 0 || ret >= end - pos)
3344 if (mask & WPA_BSS_MASK_LEVEL) {
3345 ret = os_snprintf(pos, end - pos, "level=%d\n", bss->level);
3346 if (ret < 0 || ret >= end - pos)
3351 if (mask & WPA_BSS_MASK_TSF) {
3352 ret = os_snprintf(pos, end - pos, "tsf=%016llu\n",
3353 (unsigned long long) bss->tsf);
3354 if (ret < 0 || ret >= end - pos)
3359 if (mask & WPA_BSS_MASK_AGE) {
3360 struct os_reltime now;
3362 os_get_reltime(&now);
3363 ret = os_snprintf(pos, end - pos, "age=%d\n",
3364 (int) (now.sec - bss->last_update.sec));
3365 if (ret < 0 || ret >= end - pos)
3370 if (mask & WPA_BSS_MASK_IE) {
3371 ret = os_snprintf(pos, end - pos, "ie=");
3372 if (ret < 0 || ret >= end - pos)
3376 ie = (const u8 *) (bss + 1);
3377 for (i = 0; i < bss->ie_len; i++) {
3378 ret = os_snprintf(pos, end - pos, "%02x", *ie++);
3379 if (ret < 0 || ret >= end - pos)
3384 ret = os_snprintf(pos, end - pos, "\n");
3385 if (ret < 0 || ret >= end - pos)
3390 if (mask & WPA_BSS_MASK_FLAGS) {
3391 ret = os_snprintf(pos, end - pos, "flags=");
3392 if (ret < 0 || ret >= end - pos)
3396 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
3398 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie,
3400 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
3402 pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2,
3404 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
3405 if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
3406 ret = os_snprintf(pos, end - pos, "[WEP]");
3407 if (ret < 0 || ret >= end - pos)
3411 if (bss->caps & IEEE80211_CAP_IBSS) {
3412 ret = os_snprintf(pos, end - pos, "[IBSS]");
3413 if (ret < 0 || ret >= end - pos)
3417 if (bss->caps & IEEE80211_CAP_ESS) {
3418 ret = os_snprintf(pos, end - pos, "[ESS]");
3419 if (ret < 0 || ret >= end - pos)
3423 if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
3424 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
3425 ret = os_snprintf(pos, end - pos, "[P2P]");
3426 if (ret < 0 || ret >= end - pos)
3431 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) {
3432 ret = os_snprintf(pos, end - pos, "[HS20]");
3433 if (ret < 0 || ret >= end - pos)
3437 #endif /* CONFIG_HS20 */
3439 ret = os_snprintf(pos, end - pos, "\n");
3440 if (ret < 0 || ret >= end - pos)
3445 if (mask & WPA_BSS_MASK_SSID) {
3446 ret = os_snprintf(pos, end - pos, "ssid=%s\n",
3447 wpa_ssid_txt(bss->ssid, bss->ssid_len));
3448 if (ret < 0 || ret >= end - pos)
3454 if (mask & WPA_BSS_MASK_WPS_SCAN) {
3455 ie = (const u8 *) (bss + 1);
3456 ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end);
3457 if (ret < 0 || ret >= end - pos)
3461 #endif /* CONFIG_WPS */
3464 if (mask & WPA_BSS_MASK_P2P_SCAN) {
3465 ie = (const u8 *) (bss + 1);
3466 ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end);
3467 if (ret < 0 || ret >= end - pos)
3471 #endif /* CONFIG_P2P */
3473 #ifdef CONFIG_WIFI_DISPLAY
3474 if (mask & WPA_BSS_MASK_WIFI_DISPLAY) {
3476 ie = (const u8 *) (bss + 1);
3477 wfd = ieee802_11_vendor_ie_concat(ie, bss->ie_len,
3478 WFD_IE_VENDOR_TYPE);
3480 ret = os_snprintf(pos, end - pos, "wfd_subelems=");
3481 if (ret < 0 || ret >= end - pos)
3485 pos += wpa_snprintf_hex(pos, end - pos,
3490 ret = os_snprintf(pos, end - pos, "\n");
3491 if (ret < 0 || ret >= end - pos)
3496 #endif /* CONFIG_WIFI_DISPLAY */
3498 #ifdef CONFIG_INTERWORKING
3499 if ((mask & WPA_BSS_MASK_INTERNETW) && bss->anqp) {
3500 struct wpa_bss_anqp *anqp = bss->anqp;
3501 pos = anqp_add_hex(pos, end, "anqp_venue_name",
3503 pos = anqp_add_hex(pos, end, "anqp_network_auth_type",
3504 anqp->network_auth_type);
3505 pos = anqp_add_hex(pos, end, "anqp_roaming_consortium",
3506 anqp->roaming_consortium);
3507 pos = anqp_add_hex(pos, end, "anqp_ip_addr_type_availability",
3508 anqp->ip_addr_type_availability);
3509 pos = anqp_add_hex(pos, end, "anqp_nai_realm",
3511 pos = anqp_add_hex(pos, end, "anqp_3gpp", anqp->anqp_3gpp);
3512 pos = anqp_add_hex(pos, end, "anqp_domain_name",
3515 pos = anqp_add_hex(pos, end, "hs20_operator_friendly_name",
3516 anqp->hs20_operator_friendly_name);
3517 pos = anqp_add_hex(pos, end, "hs20_wan_metrics",
3518 anqp->hs20_wan_metrics);
3519 pos = anqp_add_hex(pos, end, "hs20_connection_capability",
3520 anqp->hs20_connection_capability);
3521 #endif /* CONFIG_HS20 */
3523 #endif /* CONFIG_INTERWORKING */
3525 if (mask & WPA_BSS_MASK_DELIM) {
3526 ret = os_snprintf(pos, end - pos, "====\n");
3527 if (ret < 0 || ret >= end - pos)
3536 static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
3537 const char *cmd, char *buf,
3542 struct wpa_bss *bss;
3543 struct wpa_bss *bsslast = NULL;
3544 struct dl_list *next;
3548 unsigned long mask = WPA_BSS_MASK_ALL;
3550 if (os_strncmp(cmd, "RANGE=", 6) == 0) {
3551 if (os_strncmp(cmd + 6, "ALL", 3) == 0) {
3552 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss,
3554 bsslast = dl_list_last(&wpa_s->bss_id, struct wpa_bss,
3556 } else { /* N1-N2 */
3557 unsigned int id1, id2;
3559 if ((ctmp = os_strchr(cmd + 6, '-')) == NULL) {
3560 wpa_printf(MSG_INFO, "Wrong BSS range "
3565 if (*(cmd + 6) == '-')
3568 id1 = atoi(cmd + 6);
3570 if (*ctmp >= '0' && *ctmp <= '9')
3573 id2 = (unsigned int) -1;
3574 bss = wpa_bss_get_id_range(wpa_s, id1, id2);
3575 if (id2 == (unsigned int) -1)
3576 bsslast = dl_list_last(&wpa_s->bss_id,
3580 bsslast = wpa_bss_get_id(wpa_s, id2);
3581 if (bsslast == NULL && bss && id2 > id1) {
3582 struct wpa_bss *tmp = bss;
3584 next = tmp->list_id.next;
3585 if (next == &wpa_s->bss_id)
3587 tmp = dl_list_entry(
3588 next, struct wpa_bss,
3597 } else if (os_strncmp(cmd, "FIRST", 5) == 0)
3598 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, list_id);
3599 else if (os_strncmp(cmd, "LAST", 4) == 0)
3600 bss = dl_list_last(&wpa_s->bss_id, struct wpa_bss, list_id);
3601 else if (os_strncmp(cmd, "ID-", 3) == 0) {
3603 bss = wpa_bss_get_id(wpa_s, i);
3604 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
3606 bss = wpa_bss_get_id(wpa_s, i);
3608 next = bss->list_id.next;
3609 if (next == &wpa_s->bss_id)
3612 bss = dl_list_entry(next, struct wpa_bss,
3616 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
3617 if (hwaddr_aton(cmd + 13, bssid) == 0)
3618 bss = wpa_bss_get_p2p_dev_addr(wpa_s, bssid);
3621 #endif /* CONFIG_P2P */
3622 } else if (hwaddr_aton(cmd, bssid) == 0)
3623 bss = wpa_bss_get_bssid(wpa_s, bssid);
3625 struct wpa_bss *tmp;
3628 dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id)
3637 if ((ctmp = os_strstr(cmd, "MASK=")) != NULL) {
3638 mask = strtoul(ctmp + 5, NULL, 0x10);
3640 mask = WPA_BSS_MASK_ALL;
3646 if (bsslast == NULL)
3649 len = print_bss_info(wpa_s, bss, mask, buf, buflen);
3653 if (bss == bsslast) {
3654 if ((mask & WPA_BSS_MASK_DELIM) && len &&
3655 (bss == dl_list_last(&wpa_s->bss_id,
3656 struct wpa_bss, list_id)))
3657 os_snprintf(buf - 5, 5, "####\n");
3660 next = bss->list_id.next;
3661 if (next == &wpa_s->bss_id)
3663 bss = dl_list_entry(next, struct wpa_bss, list_id);
3664 } while (bss && len);
3670 static int wpa_supplicant_ctrl_iface_ap_scan(
3671 struct wpa_supplicant *wpa_s, char *cmd)
3673 int ap_scan = atoi(cmd);
3674 return wpa_supplicant_set_ap_scan(wpa_s, ap_scan);
3678 static int wpa_supplicant_ctrl_iface_scan_interval(
3679 struct wpa_supplicant *wpa_s, char *cmd)
3681 int scan_int = atoi(cmd);
3682 return wpa_supplicant_set_scan_interval(wpa_s, scan_int);
3686 static int wpa_supplicant_ctrl_iface_bss_expire_age(
3687 struct wpa_supplicant *wpa_s, char *cmd)
3689 int expire_age = atoi(cmd);
3690 return wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age);
3694 static int wpa_supplicant_ctrl_iface_bss_expire_count(
3695 struct wpa_supplicant *wpa_s, char *cmd)
3697 int expire_count = atoi(cmd);
3698 return wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count);
3702 static int wpa_supplicant_ctrl_iface_bss_flush(
3703 struct wpa_supplicant *wpa_s, char *cmd)
3705 int flush_age = atoi(cmd);
3708 wpa_bss_flush(wpa_s);
3710 wpa_bss_flush_by_age(wpa_s, flush_age);
3715 static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s)
3717 wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication");
3718 /* MLME-DELETEKEYS.request */
3719 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL, 0);
3720 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL, 0);
3721 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL, 0);
3722 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL, 0);
3723 #ifdef CONFIG_IEEE80211W
3724 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL, 0);
3725 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL, 0);
3726 #endif /* CONFIG_IEEE80211W */
3728 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, wpa_s->bssid, 0, 0, NULL, 0, NULL,
3730 /* MLME-SETPROTECTION.request(None) */
3731 wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid,
3732 MLME_SETPROTECTION_PROTECT_TYPE_NONE,
3733 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE);
3734 wpa_sm_drop_sa(wpa_s->wpa);
3738 static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s,
3741 #ifdef CONFIG_NO_SCAN_PROCESSING
3743 #else /* CONFIG_NO_SCAN_PROCESSING */
3745 struct wpa_bss *bss;
3746 struct wpa_ssid *ssid = wpa_s->current_ssid;
3748 if (hwaddr_aton(addr, bssid)) {
3749 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid "
3750 "address '%s'", addr);
3754 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR, MAC2STR(bssid));
3757 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network "
3758 "configuration known for the target AP");
3762 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
3764 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found "
3770 * TODO: Find best network configuration block from configuration to
3771 * allow roaming to other networks
3774 wpa_s->reassociate = 1;
3775 wpa_supplicant_connect(wpa_s, bss, ssid);
3778 #endif /* CONFIG_NO_SCAN_PROCESSING */
3783 static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd)
3785 unsigned int timeout = atoi(cmd);
3786 enum p2p_discovery_type type = P2P_FIND_START_WITH_FULL;
3787 u8 dev_id[ETH_ALEN], *_dev_id = NULL;
3788 u8 dev_type[WPS_DEV_TYPE_LEN], *_dev_type = NULL;
3790 unsigned int search_delay;
3792 if (os_strstr(cmd, "type=social"))
3793 type = P2P_FIND_ONLY_SOCIAL;
3794 else if (os_strstr(cmd, "type=progressive"))
3795 type = P2P_FIND_PROGRESSIVE;
3797 pos = os_strstr(cmd, "dev_id=");
3800 if (hwaddr_aton(pos, dev_id))
3805 pos = os_strstr(cmd, "dev_type=");
3808 if (wps_dev_type_str2bin(pos, dev_type) < 0)
3810 _dev_type = dev_type;
3813 pos = os_strstr(cmd, "delay=");
3816 search_delay = atoi(pos);
3818 search_delay = wpas_p2p_search_delay(wpa_s);
3820 return wpas_p2p_find(wpa_s, timeout, type, _dev_type != NULL, _dev_type,
3821 _dev_id, search_delay);
3825 static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd,
3826 char *buf, size_t buflen)
3831 enum p2p_wps_method wps_method;
3834 int persistent_group, persistent_id = -1;
3843 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad]
3844 * [persistent|persistent=<network id>]
3845 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
3848 if (hwaddr_aton(cmd, addr))
3856 persistent_group = os_strstr(pos, " persistent") != NULL;
3857 pos2 = os_strstr(pos, " persistent=");
3859 struct wpa_ssid *ssid;
3860 persistent_id = atoi(pos2 + 12);
3861 ssid = wpa_config_get_network(wpa_s->conf, persistent_id);
3862 if (ssid == NULL || ssid->disabled != 2 ||
3863 ssid->mode != WPAS_MODE_P2P_GO) {
3864 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3865 "SSID id=%d for persistent P2P group (GO)",
3870 join = os_strstr(pos, " join") != NULL;
3871 auth = os_strstr(pos, " auth") != NULL;
3872 automatic = os_strstr(pos, " auto") != NULL;
3873 pd = os_strstr(pos, " provdisc") != NULL;
3874 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
3875 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
3878 pos2 = os_strstr(pos, " go_intent=");
3881 go_intent = atoi(pos2);
3882 if (go_intent < 0 || go_intent > 15)
3886 pos2 = os_strstr(pos, " freq=");
3894 if (os_strncmp(pos, "pin", 3) == 0) {
3895 /* Request random PIN (to be displayed) and enable the PIN */
3896 wps_method = WPS_PIN_DISPLAY;
3897 } else if (os_strncmp(pos, "pbc", 3) == 0) {
3898 wps_method = WPS_PBC;
3901 pos = os_strchr(pin, ' ');
3902 wps_method = WPS_PIN_KEYPAD;
3905 if (os_strncmp(pos, "display", 7) == 0)
3906 wps_method = WPS_PIN_DISPLAY;
3908 if (!wps_pin_str_valid(pin)) {
3909 os_memcpy(buf, "FAIL-INVALID-PIN\n", 17);
3914 new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method,
3915 persistent_group, automatic, join,
3916 auth, go_intent, freq, persistent_id, pd,
3918 if (new_pin == -2) {
3919 os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
3922 if (new_pin == -3) {
3923 os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
3928 if (wps_method == WPS_PIN_DISPLAY && pin == NULL) {
3929 ret = os_snprintf(buf, buflen, "%08d", new_pin);
3930 if (ret < 0 || (size_t) ret >= buflen)
3935 os_memcpy(buf, "OK\n", 3);
3940 static int p2p_ctrl_listen(struct wpa_supplicant *wpa_s, char *cmd)
3942 unsigned int timeout = atoi(cmd);
3943 return wpas_p2p_listen(wpa_s, timeout);
3947 static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd)
3951 enum wpas_p2p_prov_disc_use use = WPAS_P2P_PD_FOR_GO_NEG;
3953 /* <addr> <config method> [join|auto] */
3955 if (hwaddr_aton(cmd, addr))
3963 if (os_strstr(pos, " join") != NULL)
3964 use = WPAS_P2P_PD_FOR_JOIN;
3965 else if (os_strstr(pos, " auto") != NULL)
3966 use = WPAS_P2P_PD_AUTO;
3968 return wpas_p2p_prov_disc(wpa_s, addr, pos, use);
3972 static int p2p_get_passphrase(struct wpa_supplicant *wpa_s, char *buf,
3975 struct wpa_ssid *ssid = wpa_s->current_ssid;
3977 if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO ||
3978 ssid->passphrase == NULL)
3981 os_strlcpy(buf, ssid->passphrase, buflen);
3982 return os_strlen(buf);
3986 static int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd,
3987 char *buf, size_t buflen)
3991 u8 dst_buf[ETH_ALEN], *dst;
3992 struct wpabuf *tlvs;
3996 if (hwaddr_aton(cmd, dst_buf))
3999 if (dst[0] == 0 && dst[1] == 0 && dst[2] == 0 &&
4000 dst[3] == 0 && dst[4] == 0 && dst[5] == 0)
4007 if (os_strncmp(pos, "upnp ", 5) == 0) {
4010 if (hexstr2bin(pos, &version, 1) < 0)
4016 ref = wpas_p2p_sd_request_upnp(wpa_s, dst, version, pos);
4017 #ifdef CONFIG_WIFI_DISPLAY
4018 } else if (os_strncmp(pos, "wifi-display ", 13) == 0) {
4019 ref = wpas_p2p_sd_request_wifi_display(wpa_s, dst, pos + 13);
4020 #endif /* CONFIG_WIFI_DISPLAY */
4022 len = os_strlen(pos);
4026 tlvs = wpabuf_alloc(len);
4029 if (hexstr2bin(pos, wpabuf_put(tlvs, len), len) < 0) {
4034 ref = wpas_p2p_sd_request(wpa_s, dst, tlvs);
4039 res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref);
4040 if (res < 0 || (unsigned) res >= buflen)
4046 static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s,
4049 long long unsigned val;
4051 if (sscanf(cmd, "%llx", &val) != 1)
4054 return wpas_p2p_sd_cancel_request(wpa_s, req);
4058 static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant *wpa_s, char *cmd)
4063 struct wpabuf *resp_tlvs;
4067 pos = os_strchr(cmd, ' ');
4075 if (hwaddr_aton(pos, dst))
4082 pos2 = os_strchr(pos, ' ');
4086 dialog_token = atoi(pos);
4088 len = os_strlen(pos2);
4092 resp_tlvs = wpabuf_alloc(len);
4093 if (resp_tlvs == NULL)
4095 if (hexstr2bin(pos2, wpabuf_put(resp_tlvs, len), len) < 0) {
4096 wpabuf_free(resp_tlvs);
4100 wpas_p2p_sd_response(wpa_s, freq, dst, dialog_token, resp_tlvs);
4101 wpabuf_free(resp_tlvs);
4106 static int p2p_ctrl_serv_disc_external(struct wpa_supplicant *wpa_s,
4109 if (os_strcmp(cmd, "0") && os_strcmp(cmd, "1"))
4111 wpa_s->p2p_sd_over_ctrl_iface = atoi(cmd);
4116 static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant *wpa_s,
4121 struct wpabuf *query, *resp;
4123 pos = os_strchr(cmd, ' ');
4128 len = os_strlen(cmd);
4132 query = wpabuf_alloc(len);
4135 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
4140 len = os_strlen(pos);
4146 resp = wpabuf_alloc(len);
4151 if (hexstr2bin(pos, wpabuf_put(resp, len), len) < 0) {
4157 if (wpas_p2p_service_add_bonjour(wpa_s, query, resp) < 0) {
4166 static int p2p_ctrl_service_add_upnp(struct wpa_supplicant *wpa_s, char *cmd)
4171 pos = os_strchr(cmd, ' ');
4176 if (hexstr2bin(cmd, &version, 1) < 0)
4179 return wpas_p2p_service_add_upnp(wpa_s, version, pos);
4183 static int p2p_ctrl_service_add(struct wpa_supplicant *wpa_s, char *cmd)
4187 pos = os_strchr(cmd, ' ');
4192 if (os_strcmp(cmd, "bonjour") == 0)
4193 return p2p_ctrl_service_add_bonjour(wpa_s, pos);
4194 if (os_strcmp(cmd, "upnp") == 0)
4195 return p2p_ctrl_service_add_upnp(wpa_s, pos);
4196 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
4201 static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant *wpa_s,
4205 struct wpabuf *query;
4208 len = os_strlen(cmd);
4212 query = wpabuf_alloc(len);
4215 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
4220 ret = wpas_p2p_service_del_bonjour(wpa_s, query);
4226 static int p2p_ctrl_service_del_upnp(struct wpa_supplicant *wpa_s, char *cmd)
4231 pos = os_strchr(cmd, ' ');
4236 if (hexstr2bin(cmd, &version, 1) < 0)
4239 return wpas_p2p_service_del_upnp(wpa_s, version, pos);
4243 static int p2p_ctrl_service_del(struct wpa_supplicant *wpa_s, char *cmd)
4247 pos = os_strchr(cmd, ' ');
4252 if (os_strcmp(cmd, "bonjour") == 0)
4253 return p2p_ctrl_service_del_bonjour(wpa_s, pos);
4254 if (os_strcmp(cmd, "upnp") == 0)
4255 return p2p_ctrl_service_del_upnp(wpa_s, pos);
4256 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
4261 static int p2p_ctrl_reject(struct wpa_supplicant *wpa_s, char *cmd)
4267 if (hwaddr_aton(cmd, addr))
4270 return wpas_p2p_reject(wpa_s, addr);
4274 static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd)
4278 struct wpa_ssid *ssid;
4279 u8 *_peer = NULL, peer[ETH_ALEN];
4280 int freq = 0, pref_freq = 0;
4284 pos = os_strstr(cmd, " peer=");
4287 if (hwaddr_aton(pos, peer))
4291 ssid = wpa_config_get_network(wpa_s->conf, id);
4292 if (ssid == NULL || ssid->disabled != 2) {
4293 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
4294 "for persistent P2P group",
4299 pos = os_strstr(cmd, " freq=");
4307 pos = os_strstr(cmd, " pref=");
4310 pref_freq = atoi(pos);
4315 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
4316 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
4319 return wpas_p2p_invite(wpa_s, _peer, ssid, NULL, freq, ht40, vht,
4324 static int p2p_ctrl_invite_group(struct wpa_supplicant *wpa_s, char *cmd)
4327 u8 peer[ETH_ALEN], go_dev_addr[ETH_ALEN], *go_dev = NULL;
4329 pos = os_strstr(cmd, " peer=");
4335 if (hwaddr_aton(pos, peer)) {
4336 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", pos);
4340 pos = os_strstr(pos, " go_dev_addr=");
4343 if (hwaddr_aton(pos, go_dev_addr)) {
4344 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'",
4348 go_dev = go_dev_addr;
4351 return wpas_p2p_invite_group(wpa_s, cmd, peer, go_dev);
4355 static int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd)
4357 if (os_strncmp(cmd, "persistent=", 11) == 0)
4358 return p2p_ctrl_invite_persistent(wpa_s, cmd + 11);
4359 if (os_strncmp(cmd, "group=", 6) == 0)
4360 return p2p_ctrl_invite_group(wpa_s, cmd + 6);
4366 static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s,
4367 char *cmd, int freq, int ht40,
4371 struct wpa_ssid *ssid;
4374 ssid = wpa_config_get_network(wpa_s->conf, id);
4375 if (ssid == NULL || ssid->disabled != 2) {
4376 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
4377 "for persistent P2P group",
4382 return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq, ht40, vht,
4387 static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd)
4389 int freq = 0, ht40, vht;
4392 pos = os_strstr(cmd, "freq=");
4394 freq = atoi(pos + 5);
4396 vht = (os_strstr(cmd, "vht") != NULL) || wpa_s->conf->p2p_go_vht;
4397 ht40 = (os_strstr(cmd, "ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
4400 if (os_strncmp(cmd, "persistent=", 11) == 0)
4401 return p2p_ctrl_group_add_persistent(wpa_s, cmd + 11, freq,
4403 if (os_strcmp(cmd, "persistent") == 0 ||
4404 os_strncmp(cmd, "persistent ", 11) == 0)
4405 return wpas_p2p_group_add(wpa_s, 1, freq, ht40, vht);
4406 if (os_strncmp(cmd, "freq=", 5) == 0)
4407 return wpas_p2p_group_add(wpa_s, 0, freq, ht40, vht);
4409 return wpas_p2p_group_add(wpa_s, 0, freq, ht40, vht);
4411 wpa_printf(MSG_DEBUG, "CTRL: Invalid P2P_GROUP_ADD parameters '%s'",
4417 static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd,
4418 char *buf, size_t buflen)
4420 u8 addr[ETH_ALEN], *addr_ptr;
4422 const struct p2p_peer_info *info;
4424 char devtype[WPS_DEV_TYPE_BUFSIZE];
4425 struct wpa_ssid *ssid;
4428 if (!wpa_s->global->p2p)
4431 if (os_strcmp(cmd, "FIRST") == 0) {
4434 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
4435 if (hwaddr_aton(cmd + 5, addr) < 0)
4440 if (hwaddr_aton(cmd, addr) < 0)
4446 info = p2p_get_peer_info(wpa_s->global->p2p, addr_ptr, next);
4453 res = os_snprintf(pos, end - pos, MACSTR "\n"
4459 "serial_number=%s\n"
4460 "config_methods=0x%x\n"
4462 "group_capab=0x%x\n"
4464 MAC2STR(info->p2p_device_addr),
4465 wps_dev_type_bin2str(info->pri_dev_type,
4466 devtype, sizeof(devtype)),
4471 info->serial_number,
4472 info->config_methods,
4476 if (res < 0 || res >= end - pos)
4480 for (i = 0; i < info->wps_sec_dev_type_list_len / WPS_DEV_TYPE_LEN; i++)
4483 t = &info->wps_sec_dev_type_list[i * WPS_DEV_TYPE_LEN];
4484 res = os_snprintf(pos, end - pos, "sec_dev_type=%s\n",
4485 wps_dev_type_bin2str(t, devtype,
4487 if (res < 0 || res >= end - pos)
4492 ssid = wpas_p2p_get_persistent(wpa_s, info->p2p_device_addr, NULL, 0);
4494 res = os_snprintf(pos, end - pos, "persistent=%d\n", ssid->id);
4495 if (res < 0 || res >= end - pos)
4500 res = p2p_get_peer_info_txt(info, pos, end - pos);
4509 static int p2p_ctrl_disallow_freq(struct wpa_supplicant *wpa_s,
4514 if (wpa_s->global->p2p == NULL)
4517 if (freq_range_list_parse(&wpa_s->global->p2p_disallow_freq, param) < 0)
4520 for (i = 0; i < wpa_s->global->p2p_disallow_freq.num; i++) {
4521 struct wpa_freq_range *freq;
4522 freq = &wpa_s->global->p2p_disallow_freq.range[i];
4523 wpa_printf(MSG_DEBUG, "P2P: Disallowed frequency range %u-%u",
4524 freq->min, freq->max);
4527 wpas_p2p_update_channel_list(wpa_s);
4532 static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd)
4536 if (wpa_s->global->p2p == NULL)
4539 param = os_strchr(cmd, ' ');
4544 if (os_strcmp(cmd, "discoverability") == 0) {
4545 p2p_set_client_discoverability(wpa_s->global->p2p,
4550 if (os_strcmp(cmd, "managed") == 0) {
4551 p2p_set_managed_oper(wpa_s->global->p2p, atoi(param));
4555 if (os_strcmp(cmd, "listen_channel") == 0) {
4556 return p2p_set_listen_channel(wpa_s->global->p2p, 81,
4560 if (os_strcmp(cmd, "ssid_postfix") == 0) {
4561 return p2p_set_ssid_postfix(wpa_s->global->p2p, (u8 *) param,
4565 if (os_strcmp(cmd, "noa") == 0) {
4567 int count, start, duration;
4568 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
4569 count = atoi(param);
4570 pos = os_strchr(param, ',');
4575 pos = os_strchr(pos, ',');
4579 duration = atoi(pos);
4580 if (count < 0 || count > 255 || start < 0 || duration < 0)
4582 if (count == 0 && duration > 0)
4584 wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
4585 "start=%d duration=%d", count, start, duration);
4586 return wpas_p2p_set_noa(wpa_s, count, start, duration);
4589 if (os_strcmp(cmd, "ps") == 0)
4590 return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1);
4592 if (os_strcmp(cmd, "oppps") == 0)
4593 return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1);
4595 if (os_strcmp(cmd, "ctwindow") == 0)
4596 return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param));
4598 if (os_strcmp(cmd, "disabled") == 0) {
4599 wpa_s->global->p2p_disabled = atoi(param);
4600 wpa_printf(MSG_DEBUG, "P2P functionality %s",
4601 wpa_s->global->p2p_disabled ?
4602 "disabled" : "enabled");
4603 if (wpa_s->global->p2p_disabled) {
4604 wpas_p2p_stop_find(wpa_s);
4605 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
4606 p2p_flush(wpa_s->global->p2p);
4611 if (os_strcmp(cmd, "conc_pref") == 0) {
4612 if (os_strcmp(param, "sta") == 0)
4613 wpa_s->global->conc_pref = WPA_CONC_PREF_STA;
4614 else if (os_strcmp(param, "p2p") == 0)
4615 wpa_s->global->conc_pref = WPA_CONC_PREF_P2P;
4617 wpa_printf(MSG_INFO, "Invalid conc_pref value");
4620 wpa_printf(MSG_DEBUG, "Single channel concurrency preference: "
4625 if (os_strcmp(cmd, "force_long_sd") == 0) {
4626 wpa_s->force_long_sd = atoi(param);
4630 if (os_strcmp(cmd, "peer_filter") == 0) {
4632 if (hwaddr_aton(param, addr))
4634 p2p_set_peer_filter(wpa_s->global->p2p, addr);
4638 if (os_strcmp(cmd, "cross_connect") == 0)
4639 return wpas_p2p_set_cross_connect(wpa_s, atoi(param));
4641 if (os_strcmp(cmd, "go_apsd") == 0) {
4642 if (os_strcmp(param, "disable") == 0)
4643 wpa_s->set_ap_uapsd = 0;
4645 wpa_s->set_ap_uapsd = 1;
4646 wpa_s->ap_uapsd = atoi(param);
4651 if (os_strcmp(cmd, "client_apsd") == 0) {
4652 if (os_strcmp(param, "disable") == 0)
4653 wpa_s->set_sta_uapsd = 0;
4657 /* format: BE,BK,VI,VO;max SP Length */
4659 pos = os_strchr(param, ',');
4664 pos = os_strchr(pos, ',');
4669 pos = os_strchr(pos, ',');
4674 /* ignore max SP Length for now */
4676 wpa_s->set_sta_uapsd = 1;
4677 wpa_s->sta_uapsd = 0;
4679 wpa_s->sta_uapsd |= BIT(0);
4681 wpa_s->sta_uapsd |= BIT(1);
4683 wpa_s->sta_uapsd |= BIT(2);
4685 wpa_s->sta_uapsd |= BIT(3);
4690 if (os_strcmp(cmd, "disallow_freq") == 0)
4691 return p2p_ctrl_disallow_freq(wpa_s, param);
4693 if (os_strcmp(cmd, "disc_int") == 0) {
4694 int min_disc_int, max_disc_int, max_disc_tu;
4699 min_disc_int = atoi(pos);
4700 pos = os_strchr(pos, ' ');
4705 max_disc_int = atoi(pos);
4706 pos = os_strchr(pos, ' ');
4711 max_disc_tu = atoi(pos);
4713 return p2p_set_disc_int(wpa_s->global->p2p, min_disc_int,
4714 max_disc_int, max_disc_tu);
4717 if (os_strcmp(cmd, "per_sta_psk") == 0) {
4718 wpa_s->global->p2p_per_sta_psk = !!atoi(param);
4722 #ifdef CONFIG_WPS_NFC
4723 if (os_strcmp(cmd, "nfc_tag") == 0)
4724 return wpas_p2p_nfc_tag_enabled(wpa_s, !!atoi(param));
4725 #endif /* CONFIG_WPS_NFC */
4727 if (os_strcmp(cmd, "disable_ip_addr_req") == 0) {
4728 wpa_s->p2p_disable_ip_addr_req = !!atoi(param);
4732 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
4739 static void p2p_ctrl_flush(struct wpa_supplicant *wpa_s)
4741 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
4742 wpa_s->force_long_sd = 0;
4743 if (wpa_s->global->p2p)
4744 p2p_flush(wpa_s->global->p2p);
4748 static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd)
4751 unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0;
4754 pos = os_strchr(cmd, ' ');
4760 pos2 = os_strchr(pos, ' ');
4768 pos = os_strchr(pos2, ' ');
4776 return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2);
4780 static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd)
4783 unsigned int period = 0, interval = 0;
4786 pos = os_strchr(cmd, ' ');
4791 interval = atoi(pos);
4794 return wpas_p2p_ext_listen(wpa_s, period, interval);
4798 static int p2p_ctrl_remove_client(struct wpa_supplicant *wpa_s, const char *cmd)
4805 if (os_strncmp(pos, "iface=", 6) == 0) {
4809 if (hwaddr_aton(pos, peer))
4812 wpas_p2p_remove_client(wpa_s, peer, iface_addr);
4816 #endif /* CONFIG_P2P */
4819 static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s, char *val)
4821 struct wpa_freq_range_list ranges;
4823 struct hostapd_hw_modes *mode;
4826 if (wpa_s->hw.modes == NULL)
4829 os_memset(&ranges, 0, sizeof(ranges));
4830 if (freq_range_list_parse(&ranges, val) < 0)
4833 for (i = 0; i < wpa_s->hw.num_modes; i++) {
4836 mode = &wpa_s->hw.modes[i];
4837 for (j = 0; j < mode->num_channels; j++) {
4840 if (mode->channels[j].flag & HOSTAPD_CHAN_DISABLED)
4843 freq = mode->channels[j].freq;
4844 if (!freq_range_list_includes(&ranges, freq))
4847 int_array_add_unique(&freqs, freq);
4851 os_free(ranges.range);
4856 #ifdef CONFIG_INTERWORKING
4858 static int ctrl_interworking_select(struct wpa_supplicant *wpa_s, char *param)
4866 auto_sel = os_strstr(param, "auto") != NULL;
4868 pos = os_strstr(param, "freq=");
4870 freqs = freq_range_to_channel_list(wpa_s, pos + 5);
4877 return interworking_select(wpa_s, auto_sel, freqs);
4881 static int ctrl_interworking_connect(struct wpa_supplicant *wpa_s, char *dst)
4884 struct wpa_bss *bss;
4886 if (hwaddr_aton(dst, bssid)) {
4887 wpa_printf(MSG_DEBUG, "Invalid BSSID '%s'", dst);
4891 bss = wpa_bss_get_bssid(wpa_s, bssid);
4893 wpa_printf(MSG_DEBUG, "Could not find BSS " MACSTR,
4898 return interworking_connect(wpa_s, bss);
4902 static int get_anqp(struct wpa_supplicant *wpa_s, char *dst)
4904 u8 dst_addr[ETH_ALEN];
4907 #define MAX_ANQP_INFO_ID 100
4908 u16 id[MAX_ANQP_INFO_ID];
4911 used = hwaddr_aton2(dst, dst_addr);
4915 while (num_id < MAX_ANQP_INFO_ID) {
4916 id[num_id] = atoi(pos);
4919 pos = os_strchr(pos + 1, ',');
4928 return anqp_send_req(wpa_s, dst_addr, id, num_id);
4932 static int gas_request(struct wpa_supplicant *wpa_s, char *cmd)
4934 u8 dst_addr[ETH_ALEN];
4935 struct wpabuf *advproto, *query = NULL;
4940 used = hwaddr_aton2(cmd, dst_addr);
4948 /* Advertisement Protocol ID */
4949 end = os_strchr(pos, ' ');
4953 len = os_strlen(pos);
4959 advproto = wpabuf_alloc(len);
4960 if (advproto == NULL)
4962 if (hexstr2bin(pos, wpabuf_put(advproto, len), len) < 0)
4966 /* Optional Query Request */
4971 len = os_strlen(pos);
4978 query = wpabuf_alloc(len);
4981 if (hexstr2bin(pos, wpabuf_put(query, len), len) < 0)
4986 ret = gas_send_request(wpa_s, dst_addr, advproto, query);
4989 wpabuf_free(advproto);
4996 static int gas_response_get(struct wpa_supplicant *wpa_s, char *cmd, char *buf,
5003 size_t resp_len, start, requested_len;
5004 struct wpabuf *resp;
5007 used = hwaddr_aton2(cmd, addr);
5014 dialog_token = atoi(pos);
5016 if (wpa_s->last_gas_resp &&
5017 os_memcmp(addr, wpa_s->last_gas_addr, ETH_ALEN) == 0 &&
5018 dialog_token == wpa_s->last_gas_dialog_token)
5019 resp = wpa_s->last_gas_resp;
5020 else if (wpa_s->prev_gas_resp &&
5021 os_memcmp(addr, wpa_s->prev_gas_addr, ETH_ALEN) == 0 &&
5022 dialog_token == wpa_s->prev_gas_dialog_token)
5023 resp = wpa_s->prev_gas_resp;
5027 resp_len = wpabuf_len(resp);
5029 requested_len = resp_len;
5031 pos = os_strchr(pos, ' ');
5034 if (start > resp_len)
5035 return os_snprintf(buf, buflen, "FAIL-Invalid range");
5036 pos = os_strchr(pos, ',');
5040 requested_len = atoi(pos);
5041 if (start + requested_len > resp_len)
5042 return os_snprintf(buf, buflen, "FAIL-Invalid range");
5045 if (requested_len * 2 + 1 > buflen)
5046 return os_snprintf(buf, buflen, "FAIL-Too long response");
5048 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(resp) + start,
5051 if (start + requested_len == resp_len) {
5053 * Free memory by dropping the response after it has been
5056 if (resp == wpa_s->prev_gas_resp) {
5057 wpabuf_free(wpa_s->prev_gas_resp);
5058 wpa_s->prev_gas_resp = NULL;
5060 wpabuf_free(wpa_s->last_gas_resp);
5061 wpa_s->last_gas_resp = NULL;
5067 #endif /* CONFIG_INTERWORKING */
5072 static int get_hs20_anqp(struct wpa_supplicant *wpa_s, char *dst)
5074 u8 dst_addr[ETH_ALEN];
5079 used = hwaddr_aton2(dst, dst_addr);
5084 int num = atoi(pos);
5085 if (num <= 0 || num > 31)
5087 subtypes |= BIT(num);
5088 pos = os_strchr(pos + 1, ',');
5097 return hs20_anqp_send_req(wpa_s, dst_addr, subtypes, NULL, 0);
5101 static int hs20_nai_home_realm_list(struct wpa_supplicant *wpa_s,
5102 const u8 *addr, const char *realm)
5108 rlen = os_strlen(realm);
5110 buf = os_malloc(len);
5113 buf[0] = 1; /* NAI Home Realm Count */
5114 buf[1] = 0; /* Formatted in accordance with RFC 4282 */
5116 os_memcpy(buf + 3, realm, rlen);
5118 ret = hs20_anqp_send_req(wpa_s, addr,
5119 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
5128 static int hs20_get_nai_home_realm_list(struct wpa_supplicant *wpa_s,
5131 struct wpa_cred *cred = wpa_s->conf->cred;
5132 u8 dst_addr[ETH_ALEN];
5138 used = hwaddr_aton2(dst, dst_addr);
5142 while (dst[used] == ' ')
5144 if (os_strncmp(dst + used, "realm=", 6) == 0)
5145 return hs20_nai_home_realm_list(wpa_s, dst_addr,
5148 len = os_strlen(dst + used);
5150 if (len == 0 && cred && cred->realm)
5151 return hs20_nai_home_realm_list(wpa_s, dst_addr, cred->realm);
5156 buf = os_malloc(len);
5159 if (hexstr2bin(dst + used, buf, len) < 0) {
5164 ret = hs20_anqp_send_req(wpa_s, dst_addr,
5165 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
5172 #endif /* CONFIG_HS20 */
5175 static int wpa_supplicant_ctrl_iface_sta_autoconnect(
5176 struct wpa_supplicant *wpa_s, char *cmd)
5178 wpa_s->auto_reconnect_disabled = atoi(cmd) == 0 ? 1 : 0;
5183 #ifdef CONFIG_AUTOSCAN
5185 static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant *wpa_s,
5188 enum wpa_states state = wpa_s->wpa_state;
5189 char *new_params = NULL;
5191 if (os_strlen(cmd) > 0) {
5192 new_params = os_strdup(cmd);
5193 if (new_params == NULL)
5197 os_free(wpa_s->conf->autoscan);
5198 wpa_s->conf->autoscan = new_params;
5200 if (wpa_s->conf->autoscan == NULL)
5201 autoscan_deinit(wpa_s);
5202 else if (state == WPA_DISCONNECTED || state == WPA_INACTIVE)
5203 autoscan_init(wpa_s, 1);
5204 else if (state == WPA_SCANNING)
5205 wpa_supplicant_reinit_autoscan(wpa_s);
5210 #endif /* CONFIG_AUTOSCAN */
5215 static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant *wpa_s, char *cmd)
5221 struct wpabuf *tfs_req = NULL;
5223 if (os_strncmp(cmd, "enter", 5) == 0)
5225 else if (os_strncmp(cmd, "exit", 4) == 0)
5230 pos = os_strstr(cmd, " interval=");
5232 intval = atoi(pos + 10);
5234 pos = os_strstr(cmd, " tfs_req=");
5239 end = os_strchr(pos, ' ');
5243 len = os_strlen(pos);
5247 tfs_req = wpabuf_alloc(len);
5248 if (tfs_req == NULL)
5250 if (hexstr2bin(pos, wpabuf_put(tfs_req, len), len) < 0) {
5251 wpabuf_free(tfs_req);
5256 ret = ieee802_11_send_wnmsleep_req(wpa_s, enter ? WNM_SLEEP_MODE_ENTER :
5257 WNM_SLEEP_MODE_EXIT, intval,
5259 wpabuf_free(tfs_req);
5265 static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant *wpa_s, char *cmd)
5269 query_reason = atoi(cmd);
5271 wpa_printf(MSG_DEBUG, "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d",
5274 return wnm_send_bss_transition_mgmt_query(wpa_s, query_reason);
5277 #endif /* CONFIG_WNM */
5280 /* Get string representation of channel width */
5281 static const char * channel_width_name(enum chan_width width)
5284 case CHAN_WIDTH_20_NOHT:
5285 return "20 MHz (no HT)";
5292 case CHAN_WIDTH_80P80:
5294 case CHAN_WIDTH_160:
5302 static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf,
5305 struct wpa_signal_info si;
5309 ret = wpa_drv_signal_poll(wpa_s, &si);
5316 ret = os_snprintf(pos, end - pos, "RSSI=%d\nLINKSPEED=%d\n"
5317 "NOISE=%d\nFREQUENCY=%u\n",
5318 si.current_signal, si.current_txrate / 1000,
5319 si.current_noise, si.frequency);
5320 if (ret < 0 || ret > end - pos)
5324 if (si.chanwidth != CHAN_WIDTH_UNKNOWN) {
5325 ret = os_snprintf(pos, end - pos, "WIDTH=%s\n",
5326 channel_width_name(si.chanwidth));
5327 if (ret < 0 || ret > end - pos)
5332 if (si.center_frq1 > 0 && si.center_frq2 > 0) {
5333 ret = os_snprintf(pos, end - pos,
5334 "CENTER_FRQ1=%d\nCENTER_FRQ2=%d\n",
5335 si.center_frq1, si.center_frq2);
5336 if (ret < 0 || ret > end - pos)
5341 if (si.avg_signal) {
5342 ret = os_snprintf(pos, end - pos,
5343 "AVG_RSSI=%d\n", si.avg_signal);
5344 if (ret < 0 || ret >= end - pos)
5353 static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant *wpa_s, char *buf,
5356 struct hostap_sta_driver_data sta;
5359 ret = wpa_drv_pktcnt_poll(wpa_s, &sta);
5363 ret = os_snprintf(buf, buflen, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
5364 sta.tx_packets, sta.tx_retry_failed, sta.rx_packets);
5365 if (ret < 0 || (size_t) ret > buflen)
5372 static int wpa_supplicant_driver_cmd(struct wpa_supplicant *wpa_s, char *cmd,
5373 char *buf, size_t buflen)
5377 ret = wpa_drv_driver_cmd(wpa_s, cmd, buf, buflen);
5379 if (os_strncasecmp(cmd, "COUNTRY", 7) == 0) {
5380 struct p2p_data *p2p = wpa_s->global->p2p;
5383 country[0] = cmd[8];
5384 country[1] = cmd[9];
5386 p2p_set_country(p2p, country);
5389 ret = os_snprintf(buf, buflen, "%s\n", "OK");
5393 #endif /* ANDROID */
5396 static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s)
5398 wpa_dbg(wpa_s, MSG_DEBUG, "Flush all wpa_supplicant state");
5401 wpas_p2p_stop_find(wpa_s);
5402 p2p_ctrl_flush(wpa_s);
5403 wpas_p2p_group_remove(wpa_s, "*");
5404 wpas_p2p_service_flush(wpa_s);
5405 wpa_s->global->p2p_disabled = 0;
5406 wpa_s->global->p2p_per_sta_psk = 0;
5407 wpa_s->conf->num_sec_device_types = 0;
5408 wpa_s->p2p_disable_ip_addr_req = 0;
5409 #endif /* CONFIG_P2P */
5411 #ifdef CONFIG_WPS_TESTING
5412 wps_version_number = 0x20;
5413 wps_testing_dummy_cred = 0;
5414 wps_corrupt_pkhash = 0;
5415 #endif /* CONFIG_WPS_TESTING */
5417 wpa_s->wps_fragment_size = 0;
5418 wpas_wps_cancel(wpa_s);
5419 #endif /* CONFIG_WPS */
5420 wpa_s->after_wps = 0;
5421 wpa_s->known_wps_freq = 0;
5424 #ifdef CONFIG_TDLS_TESTING
5425 extern unsigned int tdls_testing;
5427 #endif /* CONFIG_TDLS_TESTING */
5428 wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL);
5429 wpa_tdls_enable(wpa_s->wpa, 1);
5430 #endif /* CONFIG_TDLS */
5432 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, wpa_s, NULL);
5433 wpa_supplicant_stop_countermeasures(wpa_s, NULL);
5435 wpa_s->no_keep_alive = 0;
5437 os_free(wpa_s->disallow_aps_bssid);
5438 wpa_s->disallow_aps_bssid = NULL;
5439 wpa_s->disallow_aps_bssid_count = 0;
5440 os_free(wpa_s->disallow_aps_ssid);
5441 wpa_s->disallow_aps_ssid = NULL;
5442 wpa_s->disallow_aps_ssid_count = 0;
5444 wpa_s->set_sta_uapsd = 0;
5445 wpa_s->sta_uapsd = 0;
5447 wpa_drv_radio_disable(wpa_s, 0);
5449 wpa_bss_flush(wpa_s);
5450 wpa_blacklist_clear(wpa_s);
5451 wpa_s->extra_blacklist_count = 0;
5452 wpa_supplicant_ctrl_iface_remove_network(wpa_s, "all");
5453 wpa_supplicant_ctrl_iface_remove_cred(wpa_s, "all");
5454 wpa_config_flush_blobs(wpa_s->conf);
5455 wpa_s->conf->auto_interworking = 0;
5456 wpa_s->conf->okc = 0;
5457 wpa_s->conf->pmf = 0;
5459 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, 43200);
5460 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, 70);
5461 wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, 60);
5462 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
5464 radio_remove_unstarted_work(wpa_s, NULL);
5468 static int wpas_ctrl_radio_work_show(struct wpa_supplicant *wpa_s,
5469 char *buf, size_t buflen)
5471 struct wpa_radio_work *work;
5473 struct os_reltime now, diff;
5478 os_get_reltime(&now);
5480 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
5484 os_reltime_sub(&now, &work->time, &diff);
5485 ret = os_snprintf(pos, end - pos, "%s@%s:%u:%u:%ld.%06ld\n",
5486 work->type, work->wpa_s->ifname, work->freq,
5487 work->started, diff.sec, diff.usec);
5488 if (ret < 0 || ret >= end - pos)
5497 static void wpas_ctrl_radio_work_timeout(void *eloop_ctx, void *timeout_ctx)
5499 struct wpa_radio_work *work = eloop_ctx;
5500 struct wpa_external_work *ework = work->ctx;
5502 wpa_dbg(work->wpa_s, MSG_DEBUG,
5503 "Timing out external radio work %u (%s)",
5504 ework->id, work->type);
5505 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_TIMEOUT "%u", ework->id);
5507 radio_work_done(work);
5511 static void wpas_ctrl_radio_work_cb(struct wpa_radio_work *work, int deinit)
5513 struct wpa_external_work *ework = work->ctx;
5520 wpa_dbg(work->wpa_s, MSG_DEBUG, "Starting external radio work %u (%s)",
5521 ework->id, ework->type);
5522 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_START "%u", ework->id);
5523 if (!ework->timeout)
5524 ework->timeout = 10;
5525 eloop_register_timeout(ework->timeout, 0, wpas_ctrl_radio_work_timeout,
5530 static int wpas_ctrl_radio_work_add(struct wpa_supplicant *wpa_s, char *cmd,
5531 char *buf, size_t buflen)
5533 struct wpa_external_work *ework;
5537 unsigned int freq = 0;
5539 /* format: <name> [freq=<MHz>] [timeout=<seconds>] */
5541 ework = os_zalloc(sizeof(*ework));
5545 pos = os_strchr(cmd, ' ');
5547 type_len = pos - cmd;
5550 pos2 = os_strstr(pos, "freq=");
5552 freq = atoi(pos2 + 5);
5554 pos2 = os_strstr(pos, "timeout=");
5556 ework->timeout = atoi(pos2 + 8);
5558 type_len = os_strlen(cmd);
5560 if (4 + type_len >= sizeof(ework->type))
5561 type_len = sizeof(ework->type) - 4 - 1;
5562 os_strlcpy(ework->type, "ext:", sizeof(ework->type));
5563 os_memcpy(ework->type + 4, cmd, type_len);
5564 ework->type[4 + type_len] = '\0';
5566 wpa_s->ext_work_id++;
5567 if (wpa_s->ext_work_id == 0)
5568 wpa_s->ext_work_id++;
5569 ework->id = wpa_s->ext_work_id;
5571 if (radio_add_work(wpa_s, freq, ework->type, 0, wpas_ctrl_radio_work_cb,
5577 ret = os_snprintf(buf, buflen, "%u", ework->id);
5578 if (ret < 0 || (size_t) ret >= buflen)
5584 static int wpas_ctrl_radio_work_done(struct wpa_supplicant *wpa_s, char *cmd)
5586 struct wpa_radio_work *work;
5587 unsigned int id = atoi(cmd);
5589 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
5591 struct wpa_external_work *ework;
5593 if (os_strncmp(work->type, "ext:", 4) != 0)
5596 if (id && ework->id != id)
5598 wpa_dbg(wpa_s, MSG_DEBUG,
5599 "Completed external radio work %u (%s)",
5600 ework->id, ework->type);
5601 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, work, NULL);
5603 radio_work_done(work);
5604 return 3; /* "OK\n" */
5611 static int wpas_ctrl_radio_work(struct wpa_supplicant *wpa_s, char *cmd,
5612 char *buf, size_t buflen)
5614 if (os_strcmp(cmd, "show") == 0)
5615 return wpas_ctrl_radio_work_show(wpa_s, buf, buflen);
5616 if (os_strncmp(cmd, "add ", 4) == 0)
5617 return wpas_ctrl_radio_work_add(wpa_s, cmd + 4, buf, buflen);
5618 if (os_strncmp(cmd, "done ", 5) == 0)
5619 return wpas_ctrl_radio_work_done(wpa_s, cmd + 4);
5624 void wpas_ctrl_radio_work_flush(struct wpa_supplicant *wpa_s)
5626 struct wpa_radio_work *work, *tmp;
5628 if (!wpa_s || !wpa_s->radio)
5631 dl_list_for_each_safe(work, tmp, &wpa_s->radio->work,
5632 struct wpa_radio_work, list) {
5633 struct wpa_external_work *ework;
5635 if (os_strncmp(work->type, "ext:", 4) != 0)
5638 wpa_dbg(wpa_s, MSG_DEBUG,
5639 "Flushing %sexternal radio work %u (%s)",
5640 work->started ? " started" : "", ework->id,
5643 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
5646 radio_work_done(work);
5651 static void wpas_ctrl_eapol_response(void *eloop_ctx, void *timeout_ctx)
5653 struct wpa_supplicant *wpa_s = eloop_ctx;
5654 eapol_sm_notify_ctrl_response(wpa_s->eapol);
5658 static int set_scan_freqs(struct wpa_supplicant *wpa_s, char *val)
5662 freqs = freq_range_to_channel_list(wpa_s, val);
5666 os_free(wpa_s->manual_scan_freqs);
5667 wpa_s->manual_scan_freqs = freqs;
5673 static void wpas_ctrl_scan(struct wpa_supplicant *wpa_s, char *params,
5674 char *reply, int reply_size, int *reply_len)
5678 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
5683 wpa_s->manual_scan_passive = 0;
5684 wpa_s->manual_scan_use_id = 0;
5685 wpa_s->manual_scan_only_new = 0;
5688 if (os_strncasecmp(params, "TYPE=ONLY", 9) == 0)
5689 wpa_s->scan_res_handler = scan_only_handler;
5691 pos = os_strstr(params, "freq=");
5692 if (pos && set_scan_freqs(wpa_s, pos + 5) < 0) {
5697 pos = os_strstr(params, "passive=");
5699 wpa_s->manual_scan_passive = !!atoi(pos + 8);
5701 pos = os_strstr(params, "use_id=");
5703 wpa_s->manual_scan_use_id = atoi(pos + 7);
5705 pos = os_strstr(params, "only_new=1");
5707 wpa_s->manual_scan_only_new = 1;
5709 os_free(wpa_s->manual_scan_freqs);
5710 wpa_s->manual_scan_freqs = NULL;
5711 if (wpa_s->scan_res_handler == scan_only_handler)
5712 wpa_s->scan_res_handler = NULL;
5715 if (!wpa_s->sched_scanning && !wpa_s->scanning &&
5716 ((wpa_s->wpa_state <= WPA_SCANNING) ||
5717 (wpa_s->wpa_state == WPA_COMPLETED))) {
5718 wpa_s->normal_scans = 0;
5719 wpa_s->scan_req = MANUAL_SCAN_REQ;
5720 wpa_s->after_wps = 0;
5721 wpa_s->known_wps_freq = 0;
5722 wpa_supplicant_req_scan(wpa_s, 0, 0);
5723 if (wpa_s->manual_scan_use_id) {
5724 wpa_s->manual_scan_id++;
5725 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
5726 wpa_s->manual_scan_id);
5727 *reply_len = os_snprintf(reply, reply_size, "%u\n",
5728 wpa_s->manual_scan_id);
5730 } else if (wpa_s->sched_scanning) {
5731 wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to allow requested full scan to proceed");
5732 wpa_supplicant_cancel_sched_scan(wpa_s);
5733 wpa_s->scan_req = MANUAL_SCAN_REQ;
5734 wpa_supplicant_req_scan(wpa_s, 0, 0);
5735 if (wpa_s->manual_scan_use_id) {
5736 wpa_s->manual_scan_id++;
5737 *reply_len = os_snprintf(reply, reply_size, "%u\n",
5738 wpa_s->manual_scan_id);
5739 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
5740 wpa_s->manual_scan_id);
5743 wpa_printf(MSG_DEBUG, "Ongoing scan action - reject new request");
5744 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
5749 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
5750 char *buf, size_t *resp_len)
5753 const int reply_size = 4096;
5756 if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 ||
5757 os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
5758 if (wpa_debug_show_keys)
5759 wpa_dbg(wpa_s, MSG_DEBUG,
5760 "Control interface command '%s'", buf);
5762 wpa_dbg(wpa_s, MSG_DEBUG,
5763 "Control interface command '%s [REMOVED]'",
5764 os_strncmp(buf, WPA_CTRL_RSP,
5765 os_strlen(WPA_CTRL_RSP)) == 0 ?
5766 WPA_CTRL_RSP : "SET_NETWORK");
5767 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ", 16) == 0 ||
5768 os_strncmp(buf, "NFC_REPORT_HANDOVER", 19) == 0 ||
5769 os_strncmp(buf, "NFC_RX_HANDOVER_SEL", 19) == 0) {
5770 wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface",
5771 (const u8 *) buf, os_strlen(buf));
5773 int level = MSG_DEBUG;
5774 if (os_strcmp(buf, "PING") == 0)
5775 level = MSG_EXCESSIVE;
5776 wpa_dbg(wpa_s, level, "Control interface command '%s'", buf);
5779 reply = os_malloc(reply_size);
5780 if (reply == NULL) {
5785 os_memcpy(reply, "OK\n", 3);
5788 if (os_strcmp(buf, "PING") == 0) {
5789 os_memcpy(reply, "PONG\n", 5);
5791 } else if (os_strcmp(buf, "IFNAME") == 0) {
5792 reply_len = os_strlen(wpa_s->ifname);
5793 os_memcpy(reply, wpa_s->ifname, reply_len);
5794 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
5795 if (wpa_debug_reopen_file() < 0)
5797 } else if (os_strncmp(buf, "NOTE ", 5) == 0) {
5798 wpa_printf(MSG_INFO, "NOTE: %s", buf + 5);
5799 } else if (os_strcmp(buf, "MIB") == 0) {
5800 reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size);
5801 if (reply_len >= 0) {
5803 res = eapol_sm_get_mib(wpa_s->eapol, reply + reply_len,
5804 reply_size - reply_len);
5810 } else if (os_strncmp(buf, "STATUS", 6) == 0) {
5811 reply_len = wpa_supplicant_ctrl_iface_status(
5812 wpa_s, buf + 6, reply, reply_size);
5813 } else if (os_strcmp(buf, "PMKSA") == 0) {
5814 reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, reply,
5816 } else if (os_strncmp(buf, "SET ", 4) == 0) {
5817 if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4))
5819 } else if (os_strncmp(buf, "GET ", 4) == 0) {
5820 reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4,
5822 } else if (os_strcmp(buf, "LOGON") == 0) {
5823 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
5824 } else if (os_strcmp(buf, "LOGOFF") == 0) {
5825 eapol_sm_notify_logoff(wpa_s->eapol, TRUE);
5826 } else if (os_strcmp(buf, "REASSOCIATE") == 0) {
5827 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
5830 wpas_request_connection(wpa_s);
5831 } else if (os_strcmp(buf, "RECONNECT") == 0) {
5832 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
5834 else if (wpa_s->disconnected)
5835 wpas_request_connection(wpa_s);
5836 #ifdef IEEE8021X_EAPOL
5837 } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) {
5838 if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8))
5840 #endif /* IEEE8021X_EAPOL */
5841 #ifdef CONFIG_PEERKEY
5842 } else if (os_strncmp(buf, "STKSTART ", 9) == 0) {
5843 if (wpa_supplicant_ctrl_iface_stkstart(wpa_s, buf + 9))
5845 #endif /* CONFIG_PEERKEY */
5846 #ifdef CONFIG_IEEE80211R
5847 } else if (os_strncmp(buf, "FT_DS ", 6) == 0) {
5848 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6))
5850 #endif /* CONFIG_IEEE80211R */
5852 } else if (os_strcmp(buf, "WPS_PBC") == 0) {
5853 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL);
5855 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
5859 } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) {
5860 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8);
5862 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
5866 } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {
5867 reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8,
5870 } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) {
5871 reply_len = wpa_supplicant_ctrl_iface_wps_check_pin(
5872 wpa_s, buf + 14, reply, reply_size);
5873 } else if (os_strcmp(buf, "WPS_CANCEL") == 0) {
5874 if (wpas_wps_cancel(wpa_s))
5876 #ifdef CONFIG_WPS_NFC
5877 } else if (os_strcmp(buf, "WPS_NFC") == 0) {
5878 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, NULL))
5880 } else if (os_strncmp(buf, "WPS_NFC ", 8) == 0) {
5881 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, buf + 8))
5883 } else if (os_strncmp(buf, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
5884 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_config_token(
5885 wpa_s, buf + 21, reply, reply_size);
5886 } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) {
5887 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_token(
5888 wpa_s, buf + 14, reply, reply_size);
5889 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) {
5890 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s,
5893 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
5894 reply_len = wpas_ctrl_nfc_get_handover_req(
5895 wpa_s, buf + 21, reply, reply_size);
5896 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
5897 reply_len = wpas_ctrl_nfc_get_handover_sel(
5898 wpa_s, buf + 21, reply, reply_size);
5899 } else if (os_strncmp(buf, "NFC_RX_HANDOVER_REQ ", 20) == 0) {
5900 reply_len = wpas_ctrl_nfc_rx_handover_req(
5901 wpa_s, buf + 20, reply, reply_size);
5902 } else if (os_strncmp(buf, "NFC_RX_HANDOVER_SEL ", 20) == 0) {
5903 if (wpas_ctrl_nfc_rx_handover_sel(wpa_s, buf + 20))
5905 } else if (os_strncmp(buf, "NFC_REPORT_HANDOVER ", 20) == 0) {
5906 if (wpas_ctrl_nfc_report_handover(wpa_s, buf + 20))
5908 #endif /* CONFIG_WPS_NFC */
5909 } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) {
5910 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8))
5913 } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) {
5914 reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin(
5915 wpa_s, buf + 11, reply, reply_size);
5916 #endif /* CONFIG_AP */
5917 #ifdef CONFIG_WPS_ER
5918 } else if (os_strcmp(buf, "WPS_ER_START") == 0) {
5919 if (wpas_wps_er_start(wpa_s, NULL))
5921 } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) {
5922 if (wpas_wps_er_start(wpa_s, buf + 13))
5924 } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) {
5925 if (wpas_wps_er_stop(wpa_s))
5927 } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) {
5928 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11))
5930 } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) {
5931 int ret = wpas_wps_er_pbc(wpa_s, buf + 11);
5933 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
5935 } else if (ret == -3) {
5936 os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18);
5938 } else if (ret == -4) {
5939 os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20);
5943 } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) {
5944 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13))
5946 } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) {
5947 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s,
5950 } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) {
5951 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14))
5953 #ifdef CONFIG_WPS_NFC
5954 } else if (os_strncmp(buf, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
5955 reply_len = wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
5956 wpa_s, buf + 24, reply, reply_size);
5957 #endif /* CONFIG_WPS_NFC */
5958 #endif /* CONFIG_WPS_ER */
5959 #endif /* CONFIG_WPS */
5960 #ifdef CONFIG_IBSS_RSN
5961 } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) {
5962 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9))
5964 #endif /* CONFIG_IBSS_RSN */
5966 } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) {
5967 if (p2p_ctrl_find(wpa_s, buf + 9))
5969 } else if (os_strcmp(buf, "P2P_FIND") == 0) {
5970 if (p2p_ctrl_find(wpa_s, ""))
5972 } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) {
5973 wpas_p2p_stop_find(wpa_s);
5974 } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) {
5975 reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply,
5977 } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) {
5978 if (p2p_ctrl_listen(wpa_s, buf + 11))
5980 } else if (os_strcmp(buf, "P2P_LISTEN") == 0) {
5981 if (p2p_ctrl_listen(wpa_s, ""))
5983 } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) {
5984 if (wpas_p2p_group_remove(wpa_s, buf + 17))
5986 } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) {
5987 if (wpas_p2p_group_add(wpa_s, 0, 0, 0, 0))
5989 } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) {
5990 if (p2p_ctrl_group_add(wpa_s, buf + 14))
5992 } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) {
5993 if (p2p_ctrl_prov_disc(wpa_s, buf + 14))
5995 } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) {
5996 reply_len = p2p_get_passphrase(wpa_s, reply, reply_size);
5997 } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) {
5998 reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply,
6000 } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
6001 if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0)
6003 } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) {
6004 if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0)
6006 } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) {
6007 wpas_p2p_sd_service_update(wpa_s);
6008 } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
6009 if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0)
6011 } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) {
6012 wpas_p2p_service_flush(wpa_s);
6013 } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) {
6014 if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0)
6016 } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) {
6017 if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0)
6019 } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) {
6020 if (p2p_ctrl_reject(wpa_s, buf + 11) < 0)
6022 } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) {
6023 if (p2p_ctrl_invite(wpa_s, buf + 11) < 0)
6025 } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) {
6026 reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply,
6028 } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) {
6029 if (p2p_ctrl_set(wpa_s, buf + 8) < 0)
6031 } else if (os_strcmp(buf, "P2P_FLUSH") == 0) {
6032 p2p_ctrl_flush(wpa_s);
6033 } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) {
6034 if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0)
6036 } else if (os_strcmp(buf, "P2P_CANCEL") == 0) {
6037 if (wpas_p2p_cancel(wpa_s))
6039 } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) {
6040 if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0)
6042 } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) {
6043 if (p2p_ctrl_presence_req(wpa_s, "") < 0)
6045 } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) {
6046 if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0)
6048 } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) {
6049 if (p2p_ctrl_ext_listen(wpa_s, "") < 0)
6051 } else if (os_strncmp(buf, "P2P_REMOVE_CLIENT ", 18) == 0) {
6052 if (p2p_ctrl_remove_client(wpa_s, buf + 18) < 0)
6054 #endif /* CONFIG_P2P */
6055 #ifdef CONFIG_WIFI_DISPLAY
6056 } else if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0) {
6057 if (wifi_display_subelem_set(wpa_s->global, buf + 16) < 0)
6059 } else if (os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) {
6060 reply_len = wifi_display_subelem_get(wpa_s->global, buf + 16,
6062 #endif /* CONFIG_WIFI_DISPLAY */
6063 #ifdef CONFIG_INTERWORKING
6064 } else if (os_strcmp(buf, "FETCH_ANQP") == 0) {
6065 if (interworking_fetch_anqp(wpa_s) < 0)
6067 } else if (os_strcmp(buf, "STOP_FETCH_ANQP") == 0) {
6068 interworking_stop_fetch_anqp(wpa_s);
6069 } else if (os_strcmp(buf, "INTERWORKING_SELECT") == 0) {
6070 if (ctrl_interworking_select(wpa_s, NULL) < 0)
6072 } else if (os_strncmp(buf, "INTERWORKING_SELECT ", 20) == 0) {
6073 if (ctrl_interworking_select(wpa_s, buf + 20) < 0)
6075 } else if (os_strncmp(buf, "INTERWORKING_CONNECT ", 21) == 0) {
6076 if (ctrl_interworking_connect(wpa_s, buf + 21) < 0)
6078 } else if (os_strncmp(buf, "ANQP_GET ", 9) == 0) {
6079 if (get_anqp(wpa_s, buf + 9) < 0)
6081 } else if (os_strncmp(buf, "GAS_REQUEST ", 12) == 0) {
6082 if (gas_request(wpa_s, buf + 12) < 0)
6084 } else if (os_strncmp(buf, "GAS_RESPONSE_GET ", 17) == 0) {
6085 reply_len = gas_response_get(wpa_s, buf + 17, reply,
6087 #endif /* CONFIG_INTERWORKING */
6089 } else if (os_strncmp(buf, "HS20_ANQP_GET ", 14) == 0) {
6090 if (get_hs20_anqp(wpa_s, buf + 14) < 0)
6092 } else if (os_strncmp(buf, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
6093 if (hs20_get_nai_home_realm_list(wpa_s, buf + 29) < 0)
6095 #endif /* CONFIG_HS20 */
6096 } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0)
6098 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
6099 wpa_s, buf + os_strlen(WPA_CTRL_RSP)))
6103 * Notify response from timeout to allow the control
6104 * interface response to be sent first.
6106 eloop_register_timeout(0, 0, wpas_ctrl_eapol_response,
6109 } else if (os_strcmp(buf, "RECONFIGURE") == 0) {
6110 if (wpa_supplicant_reload_configuration(wpa_s))
6112 } else if (os_strcmp(buf, "TERMINATE") == 0) {
6113 wpa_supplicant_terminate_proc(wpa_s->global);
6114 } else if (os_strncmp(buf, "BSSID ", 6) == 0) {
6115 if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6))
6117 } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) {
6118 reply_len = wpa_supplicant_ctrl_iface_blacklist(
6119 wpa_s, buf + 9, reply, reply_size);
6120 } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) {
6121 reply_len = wpa_supplicant_ctrl_iface_log_level(
6122 wpa_s, buf + 9, reply, reply_size);
6123 } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) {
6124 reply_len = wpa_supplicant_ctrl_iface_list_networks(
6125 wpa_s, reply, reply_size);
6126 } else if (os_strcmp(buf, "DISCONNECT") == 0) {
6128 wpa_s->sme.prev_bssid_set = 0;
6129 #endif /* CONFIG_SME */
6130 wpa_s->reassociate = 0;
6131 wpa_s->disconnected = 1;
6132 wpa_supplicant_cancel_sched_scan(wpa_s);
6133 wpa_supplicant_cancel_scan(wpa_s);
6134 wpa_supplicant_deauthenticate(wpa_s,
6135 WLAN_REASON_DEAUTH_LEAVING);
6136 } else if (os_strcmp(buf, "SCAN") == 0) {
6137 wpas_ctrl_scan(wpa_s, NULL, reply, reply_size, &reply_len);
6138 } else if (os_strncmp(buf, "SCAN ", 5) == 0) {
6139 wpas_ctrl_scan(wpa_s, buf + 5, reply, reply_size, &reply_len);
6140 } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) {
6141 reply_len = wpa_supplicant_ctrl_iface_scan_results(
6142 wpa_s, reply, reply_size);
6143 } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) {
6144 if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15))
6146 } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) {
6147 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15))
6149 } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) {
6150 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16))
6152 } else if (os_strcmp(buf, "ADD_NETWORK") == 0) {
6153 reply_len = wpa_supplicant_ctrl_iface_add_network(
6154 wpa_s, reply, reply_size);
6155 } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) {
6156 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15))
6158 } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
6159 if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12))
6161 } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) {
6162 reply_len = wpa_supplicant_ctrl_iface_get_network(
6163 wpa_s, buf + 12, reply, reply_size);
6164 } else if (os_strcmp(buf, "LIST_CREDS") == 0) {
6165 reply_len = wpa_supplicant_ctrl_iface_list_creds(
6166 wpa_s, reply, reply_size);
6167 } else if (os_strcmp(buf, "ADD_CRED") == 0) {
6168 reply_len = wpa_supplicant_ctrl_iface_add_cred(
6169 wpa_s, reply, reply_size);
6170 } else if (os_strncmp(buf, "REMOVE_CRED ", 12) == 0) {
6171 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s, buf + 12))
6173 } else if (os_strncmp(buf, "SET_CRED ", 9) == 0) {
6174 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s, buf + 9))
6176 #ifndef CONFIG_NO_CONFIG_WRITE
6177 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
6178 if (wpa_supplicant_ctrl_iface_save_config(wpa_s))
6180 #endif /* CONFIG_NO_CONFIG_WRITE */
6181 } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
6182 reply_len = wpa_supplicant_ctrl_iface_get_capability(
6183 wpa_s, buf + 15, reply, reply_size);
6184 } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) {
6185 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8))
6187 } else if (os_strncmp(buf, "SCAN_INTERVAL ", 14) == 0) {
6188 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s, buf + 14))
6190 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
6191 reply_len = wpa_supplicant_global_iface_list(
6192 wpa_s->global, reply, reply_size);
6193 } else if (os_strcmp(buf, "INTERFACES") == 0) {
6194 reply_len = wpa_supplicant_global_iface_interfaces(
6195 wpa_s->global, reply, reply_size);
6196 } else if (os_strncmp(buf, "BSS ", 4) == 0) {
6197 reply_len = wpa_supplicant_ctrl_iface_bss(
6198 wpa_s, buf + 4, reply, reply_size);
6200 } else if (os_strcmp(buf, "STA-FIRST") == 0) {
6201 reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size);
6202 } else if (os_strncmp(buf, "STA ", 4) == 0) {
6203 reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply,
6205 } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) {
6206 reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply,
6208 } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) {
6209 if (ap_ctrl_iface_sta_deauthenticate(wpa_s, buf + 15))
6211 } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) {
6212 if (ap_ctrl_iface_sta_disassociate(wpa_s, buf + 13))
6214 } else if (os_strncmp(buf, "CHAN_SWITCH ", 12) == 0) {
6215 if (ap_ctrl_iface_chanswitch(wpa_s, buf + 12))
6217 #endif /* CONFIG_AP */
6218 } else if (os_strcmp(buf, "SUSPEND") == 0) {
6219 wpas_notify_suspend(wpa_s->global);
6220 } else if (os_strcmp(buf, "RESUME") == 0) {
6221 wpas_notify_resume(wpa_s->global);
6222 } else if (os_strcmp(buf, "DROP_SA") == 0) {
6223 wpa_supplicant_ctrl_iface_drop_sa(wpa_s);
6224 } else if (os_strncmp(buf, "ROAM ", 5) == 0) {
6225 if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5))
6227 } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) {
6228 if (wpa_supplicant_ctrl_iface_sta_autoconnect(wpa_s, buf + 16))
6230 } else if (os_strncmp(buf, "BSS_EXPIRE_AGE ", 15) == 0) {
6231 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s, buf + 15))
6233 } else if (os_strncmp(buf, "BSS_EXPIRE_COUNT ", 17) == 0) {
6234 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s,
6237 } else if (os_strncmp(buf, "BSS_FLUSH ", 10) == 0) {
6238 if (wpa_supplicant_ctrl_iface_bss_flush(wpa_s, buf + 10))
6241 } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) {
6242 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14))
6244 } else if (os_strncmp(buf, "TDLS_SETUP ", 11) == 0) {
6245 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s, buf + 11))
6247 } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) {
6248 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14))
6250 #endif /* CONFIG_TDLS */
6251 } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) {
6252 reply_len = wpa_supplicant_signal_poll(wpa_s, reply,
6254 } else if (os_strncmp(buf, "PKTCNT_POLL", 11) == 0) {
6255 reply_len = wpa_supplicant_pktcnt_poll(wpa_s, reply,
6257 #ifdef CONFIG_AUTOSCAN
6258 } else if (os_strncmp(buf, "AUTOSCAN ", 9) == 0) {
6259 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s, buf + 9))
6261 #endif /* CONFIG_AUTOSCAN */
6263 } else if (os_strncmp(buf, "DRIVER ", 7) == 0) {
6264 reply_len = wpa_supplicant_driver_cmd(wpa_s, buf + 7, reply,
6266 #endif /* ANDROID */
6267 } else if (os_strcmp(buf, "REAUTHENTICATE") == 0) {
6268 pmksa_cache_clear_current(wpa_s->wpa);
6269 eapol_sm_request_reauth(wpa_s->eapol);
6271 } else if (os_strncmp(buf, "WNM_SLEEP ", 10) == 0) {
6272 if (wpas_ctrl_iface_wnm_sleep(wpa_s, buf + 10))
6274 } else if (os_strncmp(buf, "WNM_BSS_QUERY ", 10) == 0) {
6275 if (wpas_ctrl_iface_wnm_bss_query(wpa_s, buf + 10))
6277 #endif /* CONFIG_WNM */
6278 } else if (os_strcmp(buf, "FLUSH") == 0) {
6279 wpa_supplicant_ctrl_iface_flush(wpa_s);
6280 } else if (os_strncmp(buf, "RADIO_WORK ", 11) == 0) {
6281 reply_len = wpas_ctrl_radio_work(wpa_s, buf + 11, reply,
6284 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
6288 if (reply_len < 0) {
6289 os_memcpy(reply, "FAIL\n", 5);
6293 *resp_len = reply_len;
6298 static int wpa_supplicant_global_iface_add(struct wpa_global *global,
6301 struct wpa_interface iface;
6305 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
6306 * TAB<bridge_ifname>
6308 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd);
6310 os_memset(&iface, 0, sizeof(iface));
6313 iface.ifname = pos = cmd;
6314 pos = os_strchr(pos, '\t');
6317 if (iface.ifname[0] == '\0')
6322 iface.confname = pos;
6323 pos = os_strchr(pos, '\t');
6326 if (iface.confname[0] == '\0')
6327 iface.confname = NULL;
6332 pos = os_strchr(pos, '\t');
6335 if (iface.driver[0] == '\0')
6336 iface.driver = NULL;
6340 iface.ctrl_interface = pos;
6341 pos = os_strchr(pos, '\t');
6344 if (iface.ctrl_interface[0] == '\0')
6345 iface.ctrl_interface = NULL;
6349 iface.driver_param = pos;
6350 pos = os_strchr(pos, '\t');
6353 if (iface.driver_param[0] == '\0')
6354 iface.driver_param = NULL;
6358 iface.bridge_ifname = pos;
6359 pos = os_strchr(pos, '\t');
6362 if (iface.bridge_ifname[0] == '\0')
6363 iface.bridge_ifname = NULL;
6368 if (wpa_supplicant_get_iface(global, iface.ifname))
6371 return wpa_supplicant_add_iface(global, &iface) ? 0 : -1;
6375 static int wpa_supplicant_global_iface_remove(struct wpa_global *global,
6378 struct wpa_supplicant *wpa_s;
6380 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd);
6382 wpa_s = wpa_supplicant_get_iface(global, cmd);
6385 return wpa_supplicant_remove_iface(global, wpa_s, 0);
6389 static void wpa_free_iface_info(struct wpa_interface_info *iface)
6391 struct wpa_interface_info *prev;
6395 iface = iface->next;
6397 os_free(prev->ifname);
6398 os_free(prev->desc);
6404 static int wpa_supplicant_global_iface_list(struct wpa_global *global,
6408 struct wpa_interface_info *iface = NULL, *last = NULL, *tmp;
6411 for (i = 0; wpa_drivers[i]; i++) {
6412 struct wpa_driver_ops *drv = wpa_drivers[i];
6413 if (drv->get_interfaces == NULL)
6415 tmp = drv->get_interfaces(global->drv_priv[i]);
6429 for (tmp = iface; tmp; tmp = tmp->next) {
6430 res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n",
6431 tmp->drv_name, tmp->ifname,
6432 tmp->desc ? tmp->desc : "");
6433 if (res < 0 || res >= end - pos) {
6440 wpa_free_iface_info(iface);
6446 static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
6451 struct wpa_supplicant *wpa_s;
6453 wpa_s = global->ifaces;
6458 res = os_snprintf(pos, end - pos, "%s\n", wpa_s->ifname);
6459 if (res < 0 || res >= end - pos) {
6464 wpa_s = wpa_s->next;
6470 static char * wpas_global_ctrl_iface_ifname(struct wpa_global *global,
6472 char *cmd, size_t *resp_len)
6474 struct wpa_supplicant *wpa_s;
6476 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
6477 if (os_strcmp(ifname, wpa_s->ifname) == 0)
6481 if (wpa_s == NULL) {
6482 char *resp = os_strdup("FAIL-NO-IFNAME-MATCH\n");
6484 *resp_len = os_strlen(resp);
6490 return wpa_supplicant_ctrl_iface_process(wpa_s, cmd, resp_len);
6494 static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global *global,
6495 char *buf, size_t *resp_len)
6498 static const char * cmd[] = {
6505 "P2P_GET_PASSPHRASE",
6506 "P2P_SERVICE_UPDATE",
6507 "P2P_SERVICE_FLUSH",
6514 static const char * prefix[] = {
6517 #endif /* ANDROID */
6524 "P2P_GROUP_REMOVE ",
6527 "P2P_SERV_DISC_REQ ",
6528 "P2P_SERV_DISC_CANCEL_REQ ",
6529 "P2P_SERV_DISC_RESP ",
6530 "P2P_SERV_DISC_EXTERNAL ",
6538 "P2P_PRESENCE_REQ ",
6540 "P2P_REMOVE_CLIENT ",
6546 if (global->p2p_init_wpa_s == NULL)
6549 for (i = 0; !found && cmd[i]; i++) {
6550 if (os_strcmp(buf, cmd[i]) == 0)
6554 for (i = 0; !found && prefix[i]; i++) {
6555 if (os_strncmp(buf, prefix[i], os_strlen(prefix[i])) == 0)
6560 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
6562 #endif /* CONFIG_P2P */
6567 static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global *global,
6568 char *buf, size_t *resp_len)
6570 #ifdef CONFIG_WIFI_DISPLAY
6571 if (global->p2p_init_wpa_s == NULL)
6573 if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0 ||
6574 os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0)
6575 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
6577 #endif /* CONFIG_WIFI_DISPLAY */
6582 static char * wpas_global_ctrl_iface_redir(struct wpa_global *global,
6583 char *buf, size_t *resp_len)
6587 ret = wpas_global_ctrl_iface_redir_p2p(global, buf, resp_len);
6591 ret = wpas_global_ctrl_iface_redir_wfd(global, buf, resp_len);
6599 static int wpas_global_ctrl_iface_set(struct wpa_global *global, char *cmd)
6603 value = os_strchr(cmd, ' ');
6608 wpa_printf(MSG_DEBUG, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd, value);
6610 #ifdef CONFIG_WIFI_DISPLAY
6611 if (os_strcasecmp(cmd, "wifi_display") == 0) {
6612 wifi_display_enable(global, !!atoi(value));
6615 #endif /* CONFIG_WIFI_DISPLAY */
6621 #ifndef CONFIG_NO_CONFIG_WRITE
6622 static int wpas_global_ctrl_iface_save_config(struct wpa_global *global)
6625 struct wpa_supplicant *wpa_s;
6627 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
6628 if (!wpa_s->conf->update_config) {
6629 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
6633 if (wpa_config_write(wpa_s->confname, wpa_s->conf)) {
6634 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
6637 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
6643 #endif /* CONFIG_NO_CONFIG_WRITE */
6646 static int wpas_global_ctrl_iface_status(struct wpa_global *global,
6647 char *buf, size_t buflen)
6651 struct wpa_supplicant *wpa_s;
6657 if (global->p2p && !global->p2p_disabled) {
6658 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
6661 MAC2STR(global->p2p_dev_addr),
6662 p2p_get_state_txt(global->p2p));
6663 if (ret < 0 || ret >= end - pos)
6666 } else if (global->p2p) {
6667 ret = os_snprintf(pos, end - pos, "p2p_state=DISABLED\n");
6668 if (ret < 0 || ret >= end - pos)
6672 #endif /* CONFIG_P2P */
6674 #ifdef CONFIG_WIFI_DISPLAY
6675 ret = os_snprintf(pos, end - pos, "wifi_display=%d\n",
6676 !!global->wifi_display);
6677 if (ret < 0 || ret >= end - pos)
6680 #endif /* CONFIG_WIFI_DISPLAY */
6682 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
6683 ret = os_snprintf(pos, end - pos, "ifname=%s\n"
6684 "address=" MACSTR "\n",
6685 wpa_s->ifname, MAC2STR(wpa_s->own_addr));
6686 if (ret < 0 || ret >= end - pos)
6695 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
6696 char *buf, size_t *resp_len)
6699 const int reply_size = 2048;
6701 int level = MSG_DEBUG;
6703 if (os_strncmp(buf, "IFNAME=", 7) == 0) {
6704 char *pos = os_strchr(buf + 7, ' ');
6707 return wpas_global_ctrl_iface_ifname(global,
6713 reply = wpas_global_ctrl_iface_redir(global, buf, resp_len);
6717 if (os_strcmp(buf, "PING") == 0)
6718 level = MSG_EXCESSIVE;
6719 wpa_hexdump_ascii(level, "RX global ctrl_iface",
6720 (const u8 *) buf, os_strlen(buf));
6722 reply = os_malloc(reply_size);
6723 if (reply == NULL) {
6728 os_memcpy(reply, "OK\n", 3);
6731 if (os_strcmp(buf, "PING") == 0) {
6732 os_memcpy(reply, "PONG\n", 5);
6734 } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) {
6735 if (wpa_supplicant_global_iface_add(global, buf + 14))
6737 } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) {
6738 if (wpa_supplicant_global_iface_remove(global, buf + 17))
6740 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
6741 reply_len = wpa_supplicant_global_iface_list(
6742 global, reply, reply_size);
6743 } else if (os_strcmp(buf, "INTERFACES") == 0) {
6744 reply_len = wpa_supplicant_global_iface_interfaces(
6745 global, reply, reply_size);
6746 } else if (os_strcmp(buf, "TERMINATE") == 0) {
6747 wpa_supplicant_terminate_proc(global);
6748 } else if (os_strcmp(buf, "SUSPEND") == 0) {
6749 wpas_notify_suspend(global);
6750 } else if (os_strcmp(buf, "RESUME") == 0) {
6751 wpas_notify_resume(global);
6752 } else if (os_strncmp(buf, "SET ", 4) == 0) {
6753 if (wpas_global_ctrl_iface_set(global, buf + 4))
6755 #ifndef CONFIG_NO_CONFIG_WRITE
6756 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
6757 if (wpas_global_ctrl_iface_save_config(global))
6759 #endif /* CONFIG_NO_CONFIG_WRITE */
6760 } else if (os_strcmp(buf, "STATUS") == 0) {
6761 reply_len = wpas_global_ctrl_iface_status(global, reply,
6764 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
6768 if (reply_len < 0) {
6769 os_memcpy(reply, "FAIL\n", 5);
6773 *resp_len = reply_len;