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"
43 #include "offchannel.h"
45 static int wpa_supplicant_global_iface_list(struct wpa_global *global,
47 static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
51 static int pno_start(struct wpa_supplicant *wpa_s)
55 struct wpa_ssid *ssid;
56 struct wpa_driver_scan_params params;
58 if (wpa_s->pno || wpa_s->pno_sched_pending)
61 if ((wpa_s->wpa_state > WPA_SCANNING) &&
62 (wpa_s->wpa_state <= WPA_COMPLETED)) {
63 wpa_printf(MSG_ERROR, "PNO: In assoc process");
67 if (wpa_s->wpa_state == WPA_SCANNING) {
68 wpa_supplicant_cancel_scan(wpa_s);
69 if (wpa_s->sched_scanning) {
70 wpa_printf(MSG_DEBUG, "Schedule PNO on completion of "
71 "ongoing sched scan");
72 wpa_supplicant_cancel_sched_scan(wpa_s);
73 wpa_s->pno_sched_pending = 1;
78 os_memset(¶ms, 0, sizeof(params));
81 ssid = wpa_s->conf->ssid;
83 if (!wpas_network_disabled(wpa_s, ssid))
87 if (num_ssid > WPAS_MAX_SCAN_SSIDS) {
88 wpa_printf(MSG_DEBUG, "PNO: Use only the first %u SSIDs from "
89 "%u", WPAS_MAX_SCAN_SSIDS, (unsigned int) num_ssid);
90 num_ssid = WPAS_MAX_SCAN_SSIDS;
94 wpa_printf(MSG_DEBUG, "PNO: No configured SSIDs");
98 params.filter_ssids = os_malloc(sizeof(struct wpa_driver_scan_filter) *
100 if (params.filter_ssids == NULL)
103 ssid = wpa_s->conf->ssid;
105 if (!wpas_network_disabled(wpa_s, ssid)) {
106 params.ssids[i].ssid = ssid->ssid;
107 params.ssids[i].ssid_len = ssid->ssid_len;
109 os_memcpy(params.filter_ssids[i].ssid, ssid->ssid,
111 params.filter_ssids[i].ssid_len = ssid->ssid_len;
112 params.num_filter_ssids++;
120 if (wpa_s->conf->filter_rssi)
121 params.filter_rssi = wpa_s->conf->filter_rssi;
123 interval = wpa_s->conf->sched_scan_interval ?
124 wpa_s->conf->sched_scan_interval : 10;
126 ret = wpa_supplicant_start_sched_scan(wpa_s, ¶ms, interval);
127 os_free(params.filter_ssids);
134 static int pno_stop(struct wpa_supplicant *wpa_s)
138 if (wpa_s->pno || wpa_s->sched_scanning) {
140 ret = wpa_supplicant_stop_sched_scan(wpa_s);
143 wpa_s->pno_sched_pending = 0;
145 if (wpa_s->wpa_state == WPA_SCANNING)
146 wpa_supplicant_req_scan(wpa_s, 0, 0);
152 static int set_bssid_filter(struct wpa_supplicant *wpa_s, char *val)
155 u8 addr[ETH_ALEN], *filter = NULL, *n;
162 if (hwaddr_aton(pos, addr)) {
166 n = os_realloc_array(filter, count + 1, ETH_ALEN);
172 os_memcpy(filter + count * ETH_ALEN, addr, ETH_ALEN);
175 pos = os_strchr(pos, ' ');
180 wpa_hexdump(MSG_DEBUG, "bssid_filter", filter, count * ETH_ALEN);
181 os_free(wpa_s->bssid_filter);
182 wpa_s->bssid_filter = filter;
183 wpa_s->bssid_filter_count = count;
189 static int set_disallow_aps(struct wpa_supplicant *wpa_s, char *val)
192 u8 addr[ETH_ALEN], *bssid = NULL, *n;
193 struct wpa_ssid_value *ssid = NULL, *ns;
194 size_t count = 0, ssid_count = 0;
198 * disallow_list ::= <ssid_spec> | <bssid_spec> | <disallow_list> | ""
199 * SSID_SPEC ::= ssid <SSID_HEX>
200 * BSSID_SPEC ::= bssid <BSSID_HEX>
207 if (os_strncmp(pos, "bssid ", 6) == 0) {
210 res = hwaddr_aton2(pos, addr);
214 wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
215 "BSSID value '%s'", pos);
219 n = os_realloc_array(bssid, count + 1, ETH_ALEN);
226 os_memcpy(bssid + count * ETH_ALEN, addr, ETH_ALEN);
228 } else if (os_strncmp(pos, "ssid ", 5) == 0) {
234 if (*end == '\0' || *end == ' ')
239 ns = os_realloc_array(ssid, ssid_count + 1,
240 sizeof(struct wpa_ssid_value));
248 if ((end - pos) & 0x01 || end - pos > 2 * 32 ||
249 hexstr2bin(pos, ssid[ssid_count].ssid,
250 (end - pos) / 2) < 0) {
253 wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
254 "SSID value '%s'", pos);
257 ssid[ssid_count].ssid_len = (end - pos) / 2;
258 wpa_hexdump_ascii(MSG_DEBUG, "disallow_aps SSID",
259 ssid[ssid_count].ssid,
260 ssid[ssid_count].ssid_len);
264 wpa_printf(MSG_DEBUG, "Unexpected disallow_aps value "
271 pos = os_strchr(pos, ' ');
276 wpa_hexdump(MSG_DEBUG, "disallow_aps_bssid", bssid, count * ETH_ALEN);
277 os_free(wpa_s->disallow_aps_bssid);
278 wpa_s->disallow_aps_bssid = bssid;
279 wpa_s->disallow_aps_bssid_count = count;
281 wpa_printf(MSG_DEBUG, "disallow_aps_ssid_count %d", (int) ssid_count);
282 os_free(wpa_s->disallow_aps_ssid);
283 wpa_s->disallow_aps_ssid = ssid;
284 wpa_s->disallow_aps_ssid_count = ssid_count;
286 if (!wpa_s->current_ssid || wpa_s->wpa_state < WPA_AUTHENTICATING)
289 c = wpa_s->current_ssid;
290 if (c->mode != WPAS_MODE_INFRA && c->mode != WPAS_MODE_IBSS)
293 if (!disallowed_bssid(wpa_s, wpa_s->bssid) &&
294 !disallowed_ssid(wpa_s, c->ssid, c->ssid_len))
297 wpa_printf(MSG_DEBUG, "Disconnect and try to find another network "
298 "because current AP was marked disallowed");
301 wpa_s->sme.prev_bssid_set = 0;
302 #endif /* CONFIG_SME */
303 wpa_s->reassociate = 1;
304 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
305 wpa_supplicant_req_scan(wpa_s, 0, 0);
311 static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s,
317 value = os_strchr(cmd, ' ');
322 wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value);
323 if (os_strcasecmp(cmd, "EAPOL::heldPeriod") == 0) {
324 eapol_sm_configure(wpa_s->eapol,
325 atoi(value), -1, -1, -1);
326 } else if (os_strcasecmp(cmd, "EAPOL::authPeriod") == 0) {
327 eapol_sm_configure(wpa_s->eapol,
328 -1, atoi(value), -1, -1);
329 } else if (os_strcasecmp(cmd, "EAPOL::startPeriod") == 0) {
330 eapol_sm_configure(wpa_s->eapol,
331 -1, -1, atoi(value), -1);
332 } else if (os_strcasecmp(cmd, "EAPOL::maxStart") == 0) {
333 eapol_sm_configure(wpa_s->eapol,
334 -1, -1, -1, atoi(value));
335 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKLifetime") == 0) {
336 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME,
339 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKReauthThreshold") ==
341 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD,
344 } else if (os_strcasecmp(cmd, "dot11RSNAConfigSATimeout") == 0) {
345 if (wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, atoi(value)))
347 } else if (os_strcasecmp(cmd, "wps_fragment_size") == 0) {
348 wpa_s->wps_fragment_size = atoi(value);
349 #ifdef CONFIG_WPS_TESTING
350 } else if (os_strcasecmp(cmd, "wps_version_number") == 0) {
352 val = strtol(value, NULL, 0);
353 if (val < 0 || val > 0xff) {
355 wpa_printf(MSG_DEBUG, "WPS: Invalid "
356 "wps_version_number %ld", val);
358 wps_version_number = val;
359 wpa_printf(MSG_DEBUG, "WPS: Testing - force WPS "
361 (wps_version_number & 0xf0) >> 4,
362 wps_version_number & 0x0f);
364 } else if (os_strcasecmp(cmd, "wps_testing_dummy_cred") == 0) {
365 wps_testing_dummy_cred = atoi(value);
366 wpa_printf(MSG_DEBUG, "WPS: Testing - dummy_cred=%d",
367 wps_testing_dummy_cred);
368 } else if (os_strcasecmp(cmd, "wps_corrupt_pkhash") == 0) {
369 wps_corrupt_pkhash = atoi(value);
370 wpa_printf(MSG_DEBUG, "WPS: Testing - wps_corrupt_pkhash=%d",
372 #endif /* CONFIG_WPS_TESTING */
373 } else if (os_strcasecmp(cmd, "ampdu") == 0) {
374 if (wpa_drv_ampdu(wpa_s, atoi(value)) < 0)
377 #ifdef CONFIG_TDLS_TESTING
378 } else if (os_strcasecmp(cmd, "tdls_testing") == 0) {
379 extern unsigned int tdls_testing;
380 tdls_testing = strtol(value, NULL, 0);
381 wpa_printf(MSG_DEBUG, "TDLS: tdls_testing=0x%x", tdls_testing);
382 #endif /* CONFIG_TDLS_TESTING */
383 } else if (os_strcasecmp(cmd, "tdls_disabled") == 0) {
384 int disabled = atoi(value);
385 wpa_printf(MSG_DEBUG, "TDLS: tdls_disabled=%d", disabled);
387 if (wpa_drv_tdls_oper(wpa_s, TDLS_DISABLE, NULL) < 0)
389 } else if (wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL) < 0)
391 wpa_tdls_enable(wpa_s->wpa, !disabled);
392 #endif /* CONFIG_TDLS */
393 } else if (os_strcasecmp(cmd, "pno") == 0) {
395 ret = pno_start(wpa_s);
397 ret = pno_stop(wpa_s);
398 } else if (os_strcasecmp(cmd, "radio_disabled") == 0) {
399 int disabled = atoi(value);
400 if (wpa_drv_radio_disable(wpa_s, disabled) < 0)
403 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
404 } else if (os_strcasecmp(cmd, "uapsd") == 0) {
405 if (os_strcmp(value, "disable") == 0)
406 wpa_s->set_sta_uapsd = 0;
410 /* format: BE,BK,VI,VO;max SP Length */
412 pos = os_strchr(value, ',');
417 pos = os_strchr(pos, ',');
422 pos = os_strchr(pos, ',');
427 /* ignore max SP Length for now */
429 wpa_s->set_sta_uapsd = 1;
430 wpa_s->sta_uapsd = 0;
432 wpa_s->sta_uapsd |= BIT(0);
434 wpa_s->sta_uapsd |= BIT(1);
436 wpa_s->sta_uapsd |= BIT(2);
438 wpa_s->sta_uapsd |= BIT(3);
440 } else if (os_strcasecmp(cmd, "ps") == 0) {
441 ret = wpa_drv_set_p2p_powersave(wpa_s, atoi(value), -1, -1);
442 #ifdef CONFIG_WIFI_DISPLAY
443 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
444 int enabled = !!atoi(value);
445 if (enabled && !wpa_s->global->p2p)
448 wifi_display_enable(wpa_s->global, enabled);
449 #endif /* CONFIG_WIFI_DISPLAY */
450 } else if (os_strcasecmp(cmd, "bssid_filter") == 0) {
451 ret = set_bssid_filter(wpa_s, value);
452 } else if (os_strcasecmp(cmd, "disallow_aps") == 0) {
453 ret = set_disallow_aps(wpa_s, value);
454 } else if (os_strcasecmp(cmd, "no_keep_alive") == 0) {
455 wpa_s->no_keep_alive = !!atoi(value);
456 #ifdef CONFIG_TESTING_OPTIONS
457 } else if (os_strcasecmp(cmd, "ext_mgmt_frame_handling") == 0) {
458 wpa_s->ext_mgmt_frame_handling = !!atoi(value);
459 #endif /* CONFIG_TESTING_OPTIONS */
462 ret = wpa_config_process_global(wpa_s->conf, cmd, -1);
464 wpa_supplicant_update_config(wpa_s);
471 static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s,
472 char *cmd, char *buf, size_t buflen)
476 wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd);
478 if (os_strcmp(cmd, "version") == 0) {
479 res = os_snprintf(buf, buflen, "%s", VERSION_STR);
480 } else if (os_strcasecmp(cmd, "country") == 0) {
481 if (wpa_s->conf->country[0] && wpa_s->conf->country[1])
482 res = os_snprintf(buf, buflen, "%c%c",
483 wpa_s->conf->country[0],
484 wpa_s->conf->country[1]);
485 #ifdef CONFIG_WIFI_DISPLAY
486 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
488 if (wpa_s->global->p2p == NULL ||
489 wpa_s->global->p2p_disabled)
492 enabled = wpa_s->global->wifi_display;
493 res = os_snprintf(buf, buflen, "%d", enabled);
494 if (res < 0 || (unsigned int) res >= buflen)
497 #endif /* CONFIG_WIFI_DISPLAY */
498 #ifdef CONFIG_TESTING_GET_GTK
499 } else if (os_strcmp(cmd, "gtk") == 0) {
500 if (wpa_s->last_gtk_len == 0)
502 res = wpa_snprintf_hex(buf, buflen, wpa_s->last_gtk,
503 wpa_s->last_gtk_len);
505 #endif /* CONFIG_TESTING_GET_GTK */
508 if (res < 0 || (unsigned int) res >= buflen)
514 #ifdef IEEE8021X_EAPOL
515 static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s,
519 struct wpa_ssid *ssid = wpa_s->current_ssid;
521 if (hwaddr_aton(addr, bssid)) {
522 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address "
527 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid));
528 rsn_preauth_deinit(wpa_s->wpa);
529 if (rsn_preauth_init(wpa_s->wpa, bssid, ssid ? &ssid->eap : NULL))
534 #endif /* IEEE8021X_EAPOL */
537 #ifdef CONFIG_PEERKEY
538 /* MLME-STKSTART.request(peer) */
539 static int wpa_supplicant_ctrl_iface_stkstart(
540 struct wpa_supplicant *wpa_s, char *addr)
544 if (hwaddr_aton(addr, peer)) {
545 wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART: invalid "
546 "address '%s'", addr);
550 wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART " MACSTR,
553 return wpa_sm_stkstart(wpa_s->wpa, peer);
555 #endif /* CONFIG_PEERKEY */
560 static int wpa_supplicant_ctrl_iface_tdls_discover(
561 struct wpa_supplicant *wpa_s, char *addr)
566 if (hwaddr_aton(addr, peer)) {
567 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER: invalid "
568 "address '%s'", addr);
572 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER " MACSTR,
575 if (wpa_tdls_is_external_setup(wpa_s->wpa))
576 ret = wpa_tdls_send_discovery_request(wpa_s->wpa, peer);
578 ret = wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer);
584 static int wpa_supplicant_ctrl_iface_tdls_setup(
585 struct wpa_supplicant *wpa_s, char *addr)
590 if (hwaddr_aton(addr, peer)) {
591 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP: invalid "
592 "address '%s'", addr);
596 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP " MACSTR,
599 if ((wpa_s->conf->tdls_external_control) &&
600 wpa_tdls_is_external_setup(wpa_s->wpa))
601 return wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
603 wpa_tdls_remove(wpa_s->wpa, peer);
605 if (wpa_tdls_is_external_setup(wpa_s->wpa))
606 ret = wpa_tdls_start(wpa_s->wpa, peer);
608 ret = wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
614 static int wpa_supplicant_ctrl_iface_tdls_teardown(
615 struct wpa_supplicant *wpa_s, char *addr)
620 if (hwaddr_aton(addr, peer)) {
621 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN: invalid "
622 "address '%s'", addr);
626 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN " MACSTR,
629 if ((wpa_s->conf->tdls_external_control) &&
630 wpa_tdls_is_external_setup(wpa_s->wpa))
631 return wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
633 if (wpa_tdls_is_external_setup(wpa_s->wpa))
634 ret = wpa_tdls_teardown_link(
636 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED);
638 ret = wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
643 #endif /* CONFIG_TDLS */
646 #ifdef CONFIG_IEEE80211R
647 static int wpa_supplicant_ctrl_iface_ft_ds(
648 struct wpa_supplicant *wpa_s, char *addr)
650 u8 target_ap[ETH_ALEN];
654 if (hwaddr_aton(addr, target_ap)) {
655 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid "
656 "address '%s'", addr);
660 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap));
662 bss = wpa_bss_get_bssid(wpa_s, target_ap);
664 mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN);
668 return wpa_ft_start_over_ds(wpa_s->wpa, target_ap, mdie);
670 #endif /* CONFIG_IEEE80211R */
674 static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s,
677 u8 bssid[ETH_ALEN], *_bssid = bssid;
679 u8 p2p_dev_addr[ETH_ALEN];
680 #endif /* CONFIG_P2P */
682 u8 *_p2p_dev_addr = NULL;
683 #endif /* CONFIG_AP */
685 if (cmd == NULL || os_strcmp(cmd, "any") == 0) {
688 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
689 if (hwaddr_aton(cmd + 13, p2p_dev_addr)) {
690 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid "
691 "P2P Device Address '%s'",
695 _p2p_dev_addr = p2p_dev_addr;
696 #endif /* CONFIG_P2P */
697 } else if (hwaddr_aton(cmd, bssid)) {
698 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
705 return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid, _p2p_dev_addr);
706 #endif /* CONFIG_AP */
708 return wpas_wps_start_pbc(wpa_s, _bssid, 0);
712 static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s,
713 char *cmd, char *buf,
716 u8 bssid[ETH_ALEN], *_bssid = bssid;
720 pin = os_strchr(cmd, ' ');
724 if (os_strcmp(cmd, "any") == 0)
726 else if (os_strcmp(cmd, "get") == 0) {
727 ret = wps_generate_pin();
729 } else if (hwaddr_aton(cmd, bssid)) {
730 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
736 if (wpa_s->ap_iface) {
741 pos = os_strchr(pin, ' ');
748 return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin,
749 buf, buflen, timeout);
751 #endif /* CONFIG_AP */
754 ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0,
758 ret = os_snprintf(buf, buflen, "%s", pin);
759 if (ret < 0 || (size_t) ret >= buflen)
764 ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0, DEV_PW_DEFAULT);
769 /* Return the generated PIN */
770 ret = os_snprintf(buf, buflen, "%08d", ret);
771 if (ret < 0 || (size_t) ret >= buflen)
777 static int wpa_supplicant_ctrl_iface_wps_check_pin(
778 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
785 wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN",
786 (u8 *) cmd, os_strlen(cmd));
787 for (pos = cmd, len = 0; *pos != '\0'; pos++) {
788 if (*pos < '0' || *pos > '9')
792 wpa_printf(MSG_DEBUG, "WPS: Too long PIN");
796 if (len != 4 && len != 8) {
797 wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len);
803 unsigned int pin_val;
805 if (!wps_pin_valid(pin_val)) {
806 wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit");
807 ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n");
808 if (ret < 0 || (size_t) ret >= buflen)
814 ret = os_snprintf(buf, buflen, "%s", pin);
815 if (ret < 0 || (size_t) ret >= buflen)
822 #ifdef CONFIG_WPS_NFC
824 static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant *wpa_s,
827 u8 bssid[ETH_ALEN], *_bssid = bssid;
829 if (cmd == NULL || cmd[0] == '\0')
831 else if (hwaddr_aton(cmd, bssid))
834 return wpas_wps_start_nfc(wpa_s, NULL, _bssid, NULL, 0, 0, NULL, NULL,
839 static int wpa_supplicant_ctrl_iface_wps_nfc_config_token(
840 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
847 pos = os_strchr(cmd, ' ');
850 if (os_strcmp(cmd, "WPS") == 0)
852 else if (os_strcmp(cmd, "NDEF") == 0)
857 buf = wpas_wps_nfc_config_token(wpa_s, ndef, pos);
861 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
872 static int wpa_supplicant_ctrl_iface_wps_nfc_token(
873 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
879 if (os_strcmp(cmd, "WPS") == 0)
881 else if (os_strcmp(cmd, "NDEF") == 0)
886 buf = wpas_wps_nfc_token(wpa_s, ndef);
890 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
901 static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
902 struct wpa_supplicant *wpa_s, char *pos)
910 freq = strstr(pos, " freq=");
914 forced_freq = atoi(freq);
917 len = os_strlen(pos);
922 buf = wpabuf_alloc(len);
925 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
930 ret = wpas_wps_nfc_tag_read(wpa_s, buf, forced_freq);
937 static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant *wpa_s,
938 char *reply, size_t max_len,
944 buf = wpas_wps_nfc_handover_req(wpa_s, ndef);
948 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
960 static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant *wpa_s,
961 char *reply, size_t max_len,
967 buf = wpas_p2p_nfc_handover_req(wpa_s, ndef);
969 wpa_printf(MSG_DEBUG, "P2P: Could not generate NFC handover request");
973 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
982 #endif /* CONFIG_P2P */
985 static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant *wpa_s,
986 char *cmd, char *reply,
992 pos = os_strchr(cmd, ' ');
997 if (os_strcmp(cmd, "WPS") == 0)
999 else if (os_strcmp(cmd, "NDEF") == 0)
1004 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
1007 return wpas_ctrl_nfc_get_handover_req_wps(
1008 wpa_s, reply, max_len, ndef);
1012 if (os_strcmp(pos, "P2P-CR") == 0) {
1013 return wpas_ctrl_nfc_get_handover_req_p2p(
1014 wpa_s, reply, max_len, ndef);
1016 #endif /* CONFIG_P2P */
1022 static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant *wpa_s,
1023 char *reply, size_t max_len,
1024 int ndef, int cr, char *uuid)
1029 buf = wpas_wps_nfc_handover_sel(wpa_s, ndef, cr, uuid);
1033 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1035 reply[res++] = '\n';
1045 static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant *wpa_s,
1046 char *reply, size_t max_len,
1052 buf = wpas_p2p_nfc_handover_sel(wpa_s, ndef, tag);
1056 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1058 reply[res++] = '\n';
1065 #endif /* CONFIG_P2P */
1068 static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant *wpa_s,
1069 char *cmd, char *reply,
1075 pos = os_strchr(cmd, ' ');
1080 if (os_strcmp(cmd, "WPS") == 0)
1082 else if (os_strcmp(cmd, "NDEF") == 0)
1087 pos2 = os_strchr(pos, ' ');
1090 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
1093 return wpas_ctrl_nfc_get_handover_sel_wps(
1094 wpa_s, reply, max_len, ndef,
1095 os_strcmp(pos, "WPS-CR") == 0, pos2);
1099 if (os_strcmp(pos, "P2P-CR") == 0) {
1100 return wpas_ctrl_nfc_get_handover_sel_p2p(
1101 wpa_s, reply, max_len, ndef, 0);
1104 if (os_strcmp(pos, "P2P-CR-TAG") == 0) {
1105 return wpas_ctrl_nfc_get_handover_sel_p2p(
1106 wpa_s, reply, max_len, ndef, 1);
1108 #endif /* CONFIG_P2P */
1114 static int wpas_ctrl_nfc_rx_handover_sel(struct wpa_supplicant *wpa_s,
1121 len = os_strlen(cmd);
1126 buf = wpabuf_alloc(len);
1129 if (hexstr2bin(cmd, wpabuf_put(buf, len), len) < 0) {
1134 ret = wpas_wps_nfc_rx_handover_sel(wpa_s, buf);
1141 static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant *wpa_s,
1145 struct wpabuf *req, *sel;
1147 char *pos, *role, *type, *pos2;
1150 int forced_freq = 0;
1152 freq = strstr(cmd, " freq=");
1156 forced_freq = atoi(freq);
1158 #endif /* CONFIG_P2P */
1161 pos = os_strchr(role, ' ');
1163 wpa_printf(MSG_DEBUG, "NFC: Missing type in handover report");
1169 pos = os_strchr(type, ' ');
1171 wpa_printf(MSG_DEBUG, "NFC: Missing request message in handover report");
1176 pos2 = os_strchr(pos, ' ');
1178 wpa_printf(MSG_DEBUG, "NFC: Missing select message in handover report");
1183 len = os_strlen(pos);
1185 wpa_printf(MSG_DEBUG, "NFC: Invalid request message length in handover report");
1190 req = wpabuf_alloc(len);
1192 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for request message");
1195 if (hexstr2bin(pos, wpabuf_put(req, len), len) < 0) {
1196 wpa_printf(MSG_DEBUG, "NFC: Invalid request message hexdump in handover report");
1201 len = os_strlen(pos2);
1203 wpa_printf(MSG_DEBUG, "NFC: Invalid select message length in handover report");
1209 sel = wpabuf_alloc(len);
1211 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for select message");
1215 if (hexstr2bin(pos2, wpabuf_put(sel, len), len) < 0) {
1216 wpa_printf(MSG_DEBUG, "NFC: Invalid select message hexdump in handover report");
1222 wpa_printf(MSG_DEBUG, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d",
1223 role, type, (int) wpabuf_len(req), (int) wpabuf_len(sel));
1225 if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "WPS") == 0) {
1226 ret = wpas_wps_nfc_report_handover(wpa_s, req, sel);
1228 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "WPS") == 0)
1230 ret = wpas_ap_wps_nfc_report_handover(wpa_s, req, sel);
1232 ret = wpas_er_wps_nfc_report_handover(wpa_s, req, sel);
1233 #endif /* CONFIG_AP */
1235 } else if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "P2P") == 0)
1237 ret = wpas_p2p_nfc_report_handover(wpa_s, 1, req, sel, 0);
1238 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "P2P") == 0)
1240 ret = wpas_p2p_nfc_report_handover(wpa_s, 0, req, sel,
1242 #endif /* CONFIG_P2P */
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;
1564 #endif /* CONFIG_HS20 */
1566 if (os_strcmp(params, "-DRIVER") == 0)
1567 return wpa_drv_status(wpa_s, buf, buflen);
1568 verbose = os_strcmp(params, "-VERBOSE") == 0;
1569 wps = os_strcmp(params, "-WPS") == 0;
1572 if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
1573 struct wpa_ssid *ssid = wpa_s->current_ssid;
1574 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
1575 MAC2STR(wpa_s->bssid));
1576 if (ret < 0 || ret >= end - pos)
1580 u8 *_ssid = ssid->ssid;
1581 size_t ssid_len = ssid->ssid_len;
1582 u8 ssid_buf[MAX_SSID_LEN];
1583 if (ssid_len == 0) {
1584 int _res = wpa_drv_get_ssid(wpa_s, ssid_buf);
1591 ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n",
1592 wpa_ssid_txt(_ssid, ssid_len),
1594 if (ret < 0 || ret >= end - pos)
1598 if (wps && ssid->passphrase &&
1599 wpa_key_mgmt_wpa_psk(ssid->key_mgmt) &&
1600 (ssid->mode == WPAS_MODE_AP ||
1601 ssid->mode == WPAS_MODE_P2P_GO)) {
1602 ret = os_snprintf(pos, end - pos,
1605 if (ret < 0 || ret >= end - pos)
1610 ret = os_snprintf(pos, end - pos,
1613 if (ret < 0 || ret >= end - pos)
1618 switch (ssid->mode) {
1619 case WPAS_MODE_INFRA:
1620 ret = os_snprintf(pos, end - pos,
1623 case WPAS_MODE_IBSS:
1624 ret = os_snprintf(pos, end - pos,
1628 ret = os_snprintf(pos, end - pos,
1631 case WPAS_MODE_P2P_GO:
1632 ret = os_snprintf(pos, end - pos,
1635 case WPAS_MODE_P2P_GROUP_FORMATION:
1636 ret = os_snprintf(pos, end - pos,
1637 "mode=P2P GO - group "
1644 if (ret < 0 || ret >= end - pos)
1650 if (wpa_s->ap_iface) {
1651 pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos,
1655 #endif /* CONFIG_AP */
1656 pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose);
1659 if (wpa_s->wpa_state >= WPA_ASSOCIATED &&
1662 #endif /* CONFIG_AP */
1663 wpa_s->sme.sae.state == SAE_ACCEPTED) {
1664 ret = os_snprintf(pos, end - pos, "sae_group=%d\n",
1665 wpa_s->sme.sae.group);
1666 if (ret < 0 || ret >= end - pos)
1670 #endif /* CONFIG_SAE */
1671 ret = os_snprintf(pos, end - pos, "wpa_state=%s\n",
1672 wpa_supplicant_state_txt(wpa_s->wpa_state));
1673 if (ret < 0 || ret >= end - pos)
1678 l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) {
1679 ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp);
1680 if (ret < 0 || ret >= end - pos)
1686 if (wpa_s->global->p2p) {
1687 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
1688 "\n", MAC2STR(wpa_s->global->p2p_dev_addr));
1689 if (ret < 0 || ret >= end - pos)
1693 #endif /* CONFIG_P2P */
1695 ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n",
1696 MAC2STR(wpa_s->own_addr));
1697 if (ret < 0 || ret >= end - pos)
1702 if (wpa_s->current_bss &&
1703 (hs20 = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1704 HS20_IE_VENDOR_TYPE)) &&
1705 wpa_s->wpa_proto == WPA_PROTO_RSN &&
1706 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1709 u8 rel_num = (hs20[6] & 0xf0) >> 4;
1710 release = rel_num + 1;
1712 ret = os_snprintf(pos, end - pos, "hs20=%d\n", release);
1713 if (ret < 0 || ret >= end - pos)
1718 if (wpa_s->current_ssid) {
1719 struct wpa_cred *cred;
1722 for (cred = wpa_s->conf->cred; cred; cred = cred->next) {
1725 if (wpa_s->current_ssid->parent_cred != cred)
1728 if (cred->provisioning_sp) {
1729 ret = os_snprintf(pos, end - pos,
1730 "provisioning_sp=%s\n",
1731 cred->provisioning_sp);
1732 if (ret < 0 || ret >= end - pos)
1741 if (wpa_s->current_bss && wpa_s->current_bss->anqp) {
1742 struct wpabuf *names =
1743 wpa_s->current_bss->anqp->domain_name;
1744 for (i = 0; names && i < cred->num_domain; i++)
1746 if (domain_name_list_contains(
1747 names, cred->domain[i], 1))
1750 if (i == cred->num_domain)
1751 i = 0; /* show first entry by default */
1753 ret = os_snprintf(pos, end - pos, "home_sp=%s\n",
1755 if (ret < 0 || ret >= end - pos)
1760 if (wpa_s->current_bss == NULL ||
1761 wpa_s->current_bss->anqp == NULL)
1764 res = interworking_home_sp_cred(
1766 wpa_s->current_bss->anqp->domain_name);
1774 ret = os_snprintf(pos, end - pos, "sp_type=%s\n", type);
1775 if (ret < 0 || ret >= end - pos)
1782 #endif /* CONFIG_HS20 */
1784 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
1785 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
1786 res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos,
1792 res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose);
1799 uuid_bin2str(wpa_s->wps->uuid, uuid_str, sizeof(uuid_str));
1800 ret = os_snprintf(pos, end - pos, "uuid=%s\n", uuid_str);
1801 if (ret < 0 || ret >= end - pos)
1805 #endif /* CONFIG_WPS */
1808 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_STATE_CHANGE
1809 "id=%d state=%d BSSID=" MACSTR " SSID=%s",
1810 wpa_s->current_ssid ? wpa_s->current_ssid->id : -1,
1812 MAC2STR(wpa_s->bssid),
1813 wpa_s->current_ssid && wpa_s->current_ssid->ssid ?
1814 wpa_ssid_txt(wpa_s->current_ssid->ssid,
1815 wpa_s->current_ssid->ssid_len) : "");
1816 if (wpa_s->wpa_state == WPA_COMPLETED) {
1817 struct wpa_ssid *ssid = wpa_s->current_ssid;
1818 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_CONNECTED
1819 "- connection to " MACSTR
1820 " completed %s [id=%d id_str=%s]",
1821 MAC2STR(wpa_s->bssid), "(auth)",
1822 ssid ? ssid->id : -1,
1823 ssid && ssid->id_str ? ssid->id_str : "");
1825 #endif /* ANDROID */
1831 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s,
1836 struct wpa_ssid *ssid;
1839 /* cmd: "<network id> <BSSID>" */
1840 pos = os_strchr(cmd, ' ');
1845 wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos);
1846 if (hwaddr_aton(pos, bssid)) {
1847 wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos);
1851 ssid = wpa_config_get_network(wpa_s->conf, id);
1853 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
1858 os_memcpy(ssid->bssid, bssid, ETH_ALEN);
1859 ssid->bssid_set = !is_zero_ether_addr(bssid);
1865 static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant *wpa_s,
1866 char *cmd, char *buf,
1870 struct wpa_blacklist *e;
1874 /* cmd: "BLACKLIST [<BSSID>]" */
1878 e = wpa_s->blacklist;
1880 ret = os_snprintf(pos, end - pos, MACSTR "\n",
1882 if (ret < 0 || ret >= end - pos)
1891 if (os_strncmp(cmd, "clear", 5) == 0) {
1892 wpa_blacklist_clear(wpa_s);
1893 os_memcpy(buf, "OK\n", 3);
1897 wpa_printf(MSG_DEBUG, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd);
1898 if (hwaddr_aton(cmd, bssid)) {
1899 wpa_printf(MSG_DEBUG, "CTRL_IFACE: invalid BSSID '%s'", cmd);
1904 * Add the BSSID twice, so its count will be 2, causing it to be
1905 * skipped when processing scan results.
1907 ret = wpa_blacklist_add(wpa_s, bssid);
1910 ret = wpa_blacklist_add(wpa_s, bssid);
1913 os_memcpy(buf, "OK\n", 3);
1918 static const char * debug_level_str(int level)
1939 static int str_to_debug_level(const char *s)
1941 if (os_strcasecmp(s, "EXCESSIVE") == 0)
1942 return MSG_EXCESSIVE;
1943 if (os_strcasecmp(s, "MSGDUMP") == 0)
1945 if (os_strcasecmp(s, "DEBUG") == 0)
1947 if (os_strcasecmp(s, "INFO") == 0)
1949 if (os_strcasecmp(s, "WARNING") == 0)
1951 if (os_strcasecmp(s, "ERROR") == 0)
1957 static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant *wpa_s,
1958 char *cmd, char *buf,
1961 char *pos, *end, *stamp;
1968 /* cmd: "LOG_LEVEL [<level>]" */
1972 ret = os_snprintf(pos, end - pos, "Current level: %s\n"
1974 debug_level_str(wpa_debug_level),
1975 wpa_debug_timestamp);
1976 if (ret < 0 || ret >= end - pos)
1985 stamp = os_strchr(cmd, ' ');
1988 while (*stamp == ' ') {
1993 if (cmd && os_strlen(cmd)) {
1994 int level = str_to_debug_level(cmd);
1997 wpa_debug_level = level;
2000 if (stamp && os_strlen(stamp))
2001 wpa_debug_timestamp = atoi(stamp);
2003 os_memcpy(buf, "OK\n", 3);
2008 static int wpa_supplicant_ctrl_iface_list_networks(
2009 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
2012 struct wpa_ssid *ssid;
2017 ret = os_snprintf(pos, end - pos,
2018 "network id / ssid / bssid / flags\n");
2019 if (ret < 0 || ret >= end - pos)
2023 ssid = wpa_s->conf->ssid;
2025 ret = os_snprintf(pos, end - pos, "%d\t%s",
2027 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
2028 if (ret < 0 || ret >= end - pos)
2031 if (ssid->bssid_set) {
2032 ret = os_snprintf(pos, end - pos, "\t" MACSTR,
2033 MAC2STR(ssid->bssid));
2035 ret = os_snprintf(pos, end - pos, "\tany");
2037 if (ret < 0 || ret >= end - pos)
2040 ret = os_snprintf(pos, end - pos, "\t%s%s%s%s",
2041 ssid == wpa_s->current_ssid ?
2043 ssid->disabled ? "[DISABLED]" : "",
2044 ssid->disabled_until.sec ?
2045 "[TEMP-DISABLED]" : "",
2046 ssid->disabled == 2 ? "[P2P-PERSISTENT]" :
2048 if (ret < 0 || ret >= end - pos)
2051 ret = os_snprintf(pos, end - pos, "\n");
2052 if (ret < 0 || ret >= end - pos)
2063 static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher)
2066 ret = os_snprintf(pos, end - pos, "-");
2067 if (ret < 0 || ret >= end - pos)
2070 ret = wpa_write_ciphers(pos, end, cipher, "+");
2078 static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
2079 const u8 *ie, size_t ie_len)
2081 struct wpa_ie_data data;
2085 ret = os_snprintf(pos, end - pos, "[%s-", proto);
2086 if (ret < 0 || ret >= end - pos)
2090 if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) {
2091 ret = os_snprintf(pos, end - pos, "?]");
2092 if (ret < 0 || ret >= end - pos)
2099 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
2100 ret = os_snprintf(pos, end - pos, "%sEAP",
2101 pos == start ? "" : "+");
2102 if (ret < 0 || ret >= end - pos)
2106 if (data.key_mgmt & WPA_KEY_MGMT_PSK) {
2107 ret = os_snprintf(pos, end - pos, "%sPSK",
2108 pos == start ? "" : "+");
2109 if (ret < 0 || ret >= end - pos)
2113 if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
2114 ret = os_snprintf(pos, end - pos, "%sNone",
2115 pos == start ? "" : "+");
2116 if (ret < 0 || ret >= end - pos)
2120 #ifdef CONFIG_IEEE80211R
2121 if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
2122 ret = os_snprintf(pos, end - pos, "%sFT/EAP",
2123 pos == start ? "" : "+");
2124 if (ret < 0 || ret >= end - pos)
2128 if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) {
2129 ret = os_snprintf(pos, end - pos, "%sFT/PSK",
2130 pos == start ? "" : "+");
2131 if (ret < 0 || ret >= end - pos)
2135 #endif /* CONFIG_IEEE80211R */
2136 #ifdef CONFIG_IEEE80211W
2137 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
2138 ret = os_snprintf(pos, end - pos, "%sEAP-SHA256",
2139 pos == start ? "" : "+");
2140 if (ret < 0 || ret >= end - pos)
2144 if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
2145 ret = os_snprintf(pos, end - pos, "%sPSK-SHA256",
2146 pos == start ? "" : "+");
2147 if (ret < 0 || ret >= end - pos)
2151 #endif /* CONFIG_IEEE80211W */
2153 pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher);
2155 if (data.capabilities & WPA_CAPABILITY_PREAUTH) {
2156 ret = os_snprintf(pos, end - pos, "-preauth");
2157 if (ret < 0 || ret >= end - pos)
2162 ret = os_snprintf(pos, end - pos, "]");
2163 if (ret < 0 || ret >= end - pos)
2172 static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s,
2173 char *pos, char *end,
2174 struct wpabuf *wps_ie)
2181 if (wps_is_selected_pbc_registrar(wps_ie))
2184 else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0))
2186 #endif /* CONFIG_WPS2 */
2187 else if (wps_is_selected_pin_registrar(wps_ie))
2192 ret = os_snprintf(pos, end - pos, "%s", txt);
2193 if (ret >= 0 && ret < end - pos)
2195 wpabuf_free(wps_ie);
2198 #endif /* CONFIG_WPS */
2201 static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s,
2202 char *pos, char *end,
2203 const struct wpa_bss *bss)
2206 struct wpabuf *wps_ie;
2207 wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
2208 return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie);
2209 #else /* CONFIG_WPS */
2211 #endif /* CONFIG_WPS */
2215 /* Format one result on one text line into a buffer. */
2216 static int wpa_supplicant_ctrl_iface_scan_result(
2217 struct wpa_supplicant *wpa_s,
2218 const struct wpa_bss *bss, char *buf, size_t buflen)
2222 const u8 *ie, *ie2, *p2p;
2224 p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
2226 p2p = wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE);
2227 if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN &&
2228 os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) ==
2230 return 0; /* Do not show P2P listen discovery results here */
2235 ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t",
2236 MAC2STR(bss->bssid), bss->freq, bss->level);
2237 if (ret < 0 || ret >= end - pos)
2240 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
2242 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]);
2243 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
2245 pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2, 2 + ie2[1]);
2246 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
2247 if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
2248 ret = os_snprintf(pos, end - pos, "[WEP]");
2249 if (ret < 0 || ret >= end - pos)
2253 if (bss->caps & IEEE80211_CAP_IBSS) {
2254 ret = os_snprintf(pos, end - pos, "[IBSS]");
2255 if (ret < 0 || ret >= end - pos)
2259 if (bss->caps & IEEE80211_CAP_ESS) {
2260 ret = os_snprintf(pos, end - pos, "[ESS]");
2261 if (ret < 0 || ret >= end - pos)
2266 ret = os_snprintf(pos, end - pos, "[P2P]");
2267 if (ret < 0 || ret >= end - pos)
2272 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE) && ie2) {
2273 ret = os_snprintf(pos, end - pos, "[HS20]");
2274 if (ret < 0 || ret >= end - pos)
2278 #endif /* CONFIG_HS20 */
2280 ret = os_snprintf(pos, end - pos, "\t%s",
2281 wpa_ssid_txt(bss->ssid, bss->ssid_len));
2282 if (ret < 0 || ret >= end - pos)
2286 ret = os_snprintf(pos, end - pos, "\n");
2287 if (ret < 0 || ret >= end - pos)
2295 static int wpa_supplicant_ctrl_iface_scan_results(
2296 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
2299 struct wpa_bss *bss;
2304 ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / "
2306 if (ret < 0 || ret >= end - pos)
2310 dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
2311 ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos,
2313 if (ret < 0 || ret >= end - pos)
2322 static int wpa_supplicant_ctrl_iface_select_network(
2323 struct wpa_supplicant *wpa_s, char *cmd)
2326 struct wpa_ssid *ssid;
2328 /* cmd: "<network id>" or "any" */
2329 if (os_strcmp(cmd, "any") == 0) {
2330 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any");
2334 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id);
2336 ssid = wpa_config_get_network(wpa_s->conf, id);
2338 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2339 "network id=%d", id);
2342 if (ssid->disabled == 2) {
2343 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2344 "SELECT_NETWORK with persistent P2P group");
2349 wpa_supplicant_select_network(wpa_s, ssid);
2355 static int wpa_supplicant_ctrl_iface_enable_network(
2356 struct wpa_supplicant *wpa_s, char *cmd)
2359 struct wpa_ssid *ssid;
2361 /* cmd: "<network id>" or "all" */
2362 if (os_strcmp(cmd, "all") == 0) {
2363 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all");
2367 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id);
2369 ssid = wpa_config_get_network(wpa_s->conf, id);
2371 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2372 "network id=%d", id);
2375 if (ssid->disabled == 2) {
2376 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2377 "ENABLE_NETWORK with persistent P2P group");
2381 if (os_strstr(cmd, " no-connect")) {
2386 wpa_supplicant_enable_network(wpa_s, ssid);
2392 static int wpa_supplicant_ctrl_iface_disable_network(
2393 struct wpa_supplicant *wpa_s, char *cmd)
2396 struct wpa_ssid *ssid;
2398 /* cmd: "<network id>" or "all" */
2399 if (os_strcmp(cmd, "all") == 0) {
2400 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all");
2404 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id);
2406 ssid = wpa_config_get_network(wpa_s->conf, id);
2408 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2409 "network id=%d", id);
2412 if (ssid->disabled == 2) {
2413 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2414 "DISABLE_NETWORK with persistent P2P "
2419 wpa_supplicant_disable_network(wpa_s, ssid);
2425 static int wpa_supplicant_ctrl_iface_add_network(
2426 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
2428 struct wpa_ssid *ssid;
2431 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK");
2433 ssid = wpa_config_add_network(wpa_s->conf);
2437 wpas_notify_network_added(wpa_s, ssid);
2440 wpa_config_set_network_defaults(ssid);
2442 ret = os_snprintf(buf, buflen, "%d\n", ssid->id);
2443 if (ret < 0 || (size_t) ret >= buflen)
2449 static int wpa_supplicant_ctrl_iface_remove_network(
2450 struct wpa_supplicant *wpa_s, char *cmd)
2453 struct wpa_ssid *ssid;
2456 /* cmd: "<network id>" or "all" */
2457 if (os_strcmp(cmd, "all") == 0) {
2458 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all");
2459 if (wpa_s->sched_scanning)
2460 wpa_supplicant_cancel_sched_scan(wpa_s);
2462 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2463 if (wpa_s->current_ssid) {
2465 wpa_s->sme.prev_bssid_set = 0;
2466 #endif /* CONFIG_SME */
2467 wpa_sm_set_config(wpa_s->wpa, NULL);
2468 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
2469 wpa_supplicant_deauthenticate(
2470 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2472 ssid = wpa_s->conf->ssid;
2474 struct wpa_ssid *remove_ssid = ssid;
2477 wpas_notify_network_removed(wpa_s, remove_ssid);
2478 wpa_config_remove_network(wpa_s->conf, id);
2484 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id);
2486 ssid = wpa_config_get_network(wpa_s->conf, id);
2488 wpas_notify_network_removed(wpa_s, ssid);
2490 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2495 if (ssid == wpa_s->current_ssid || wpa_s->current_ssid == NULL) {
2497 wpa_s->sme.prev_bssid_set = 0;
2498 #endif /* CONFIG_SME */
2500 * Invalidate the EAP session cache if the current or
2501 * previously used network is removed.
2503 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2506 if (ssid == wpa_s->current_ssid) {
2507 wpa_sm_set_config(wpa_s->wpa, NULL);
2508 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
2510 wpa_supplicant_deauthenticate(wpa_s,
2511 WLAN_REASON_DEAUTH_LEAVING);
2514 was_disabled = ssid->disabled;
2516 if (wpa_config_remove_network(wpa_s->conf, id) < 0) {
2517 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Not able to remove the "
2518 "network id=%d", id);
2522 if (!was_disabled && wpa_s->sched_scanning) {
2523 wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to remove "
2524 "network from filters");
2525 wpa_supplicant_cancel_sched_scan(wpa_s);
2526 wpa_supplicant_req_scan(wpa_s, 0, 0);
2533 static int wpa_supplicant_ctrl_iface_set_network(
2534 struct wpa_supplicant *wpa_s, char *cmd)
2537 struct wpa_ssid *ssid;
2540 /* cmd: "<network id> <variable name> <value>" */
2541 name = os_strchr(cmd, ' ');
2546 value = os_strchr(name, ' ');
2552 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
2554 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
2555 (u8 *) value, os_strlen(value));
2557 ssid = wpa_config_get_network(wpa_s->conf, id);
2559 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2564 if (wpa_config_set(ssid, name, value, 0) < 0) {
2565 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network "
2566 "variable '%s'", name);
2570 if (os_strcmp(name, "bssid") != 0 &&
2571 os_strcmp(name, "priority") != 0)
2572 wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
2574 if (wpa_s->current_ssid == ssid || wpa_s->current_ssid == NULL) {
2576 * Invalidate the EAP session cache if anything in the current
2577 * or previously used configuration changes.
2579 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2582 if ((os_strcmp(name, "psk") == 0 &&
2583 value[0] == '"' && ssid->ssid_len) ||
2584 (os_strcmp(name, "ssid") == 0 && ssid->passphrase))
2585 wpa_config_update_psk(ssid);
2586 else if (os_strcmp(name, "priority") == 0)
2587 wpa_config_update_prio_list(wpa_s->conf);
2593 static int wpa_supplicant_ctrl_iface_get_network(
2594 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
2598 struct wpa_ssid *ssid;
2601 /* cmd: "<network id> <variable name>" */
2602 name = os_strchr(cmd, ' ');
2603 if (name == NULL || buflen == 0)
2608 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
2611 ssid = wpa_config_get_network(wpa_s->conf, id);
2613 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2618 value = wpa_config_get_no_key(ssid, name);
2619 if (value == NULL) {
2620 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
2621 "variable '%s'", name);
2625 res = os_strlcpy(buf, value, buflen);
2626 if (res >= buflen) {
2637 static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant *wpa_s,
2638 char *buf, size_t buflen)
2641 struct wpa_cred *cred;
2646 ret = os_snprintf(pos, end - pos,
2647 "cred id / realm / username / domain / imsi\n");
2648 if (ret < 0 || ret >= end - pos)
2652 cred = wpa_s->conf->cred;
2654 ret = os_snprintf(pos, end - pos, "%d\t%s\t%s\t%s\t%s\n",
2655 cred->id, cred->realm ? cred->realm : "",
2656 cred->username ? cred->username : "",
2657 cred->domain ? cred->domain[0] : "",
2658 cred->imsi ? cred->imsi : "");
2659 if (ret < 0 || ret >= end - pos)
2670 static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant *wpa_s,
2671 char *buf, size_t buflen)
2673 struct wpa_cred *cred;
2676 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_CRED");
2678 cred = wpa_config_add_cred(wpa_s->conf);
2682 ret = os_snprintf(buf, buflen, "%d\n", cred->id);
2683 if (ret < 0 || (size_t) ret >= buflen)
2689 static int wpas_ctrl_remove_cred(struct wpa_supplicant *wpa_s,
2690 struct wpa_cred *cred)
2692 struct wpa_ssid *ssid;
2695 if (cred == NULL || wpa_config_remove_cred(wpa_s->conf, cred->id) < 0) {
2696 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred");
2700 /* Remove any network entry created based on the removed credential */
2701 ssid = wpa_s->conf->ssid;
2703 if (ssid->parent_cred == cred) {
2704 wpa_printf(MSG_DEBUG, "Remove network id %d since it "
2705 "used the removed credential", ssid->id);
2706 os_snprintf(str, sizeof(str), "%d", ssid->id);
2708 wpa_supplicant_ctrl_iface_remove_network(wpa_s, str);
2717 static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s,
2721 struct wpa_cred *cred, *prev;
2723 /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or
2724 * "provisioning_sp=<FQDN> */
2725 if (os_strcmp(cmd, "all") == 0) {
2726 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED all");
2727 cred = wpa_s->conf->cred;
2731 wpas_ctrl_remove_cred(wpa_s, prev);
2736 if (os_strncmp(cmd, "sp_fqdn=", 8) == 0) {
2737 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
2739 cred = wpa_s->conf->cred;
2745 for (i = 0; i < prev->num_domain; i++) {
2746 if (os_strcmp(prev->domain[i], cmd + 8)
2749 wpas_ctrl_remove_cred(wpa_s, prev);
2757 if (os_strncmp(cmd, "provisioning_sp=", 16) == 0) {
2758 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'",
2760 cred = wpa_s->conf->cred;
2764 if (prev->provisioning_sp &&
2765 os_strcmp(prev->provisioning_sp, cmd + 16) == 0)
2766 wpas_ctrl_remove_cred(wpa_s, prev);
2772 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED id=%d", id);
2774 cred = wpa_config_get_cred(wpa_s->conf, id);
2775 return wpas_ctrl_remove_cred(wpa_s, cred);
2779 static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant *wpa_s,
2783 struct wpa_cred *cred;
2786 /* cmd: "<cred id> <variable name> <value>" */
2787 name = os_strchr(cmd, ' ');
2792 value = os_strchr(name, ' ');
2798 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_CRED id=%d name='%s'",
2800 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
2801 (u8 *) value, os_strlen(value));
2803 cred = wpa_config_get_cred(wpa_s->conf, id);
2805 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
2810 if (wpa_config_set_cred(cred, name, value, 0) < 0) {
2811 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set cred "
2812 "variable '%s'", name);
2820 #ifndef CONFIG_NO_CONFIG_WRITE
2821 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s)
2825 if (!wpa_s->conf->update_config) {
2826 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
2827 "to update configuration (update_config=0)");
2831 ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
2833 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to "
2834 "update configuration");
2836 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration"
2842 #endif /* CONFIG_NO_CONFIG_WRITE */
2845 struct cipher_info {
2851 static const struct cipher_info ciphers[] = {
2852 { WPA_DRIVER_CAPA_ENC_CCMP_256, "CCMP-256", 0 },
2853 { WPA_DRIVER_CAPA_ENC_GCMP_256, "GCMP-256", 0 },
2854 { WPA_DRIVER_CAPA_ENC_CCMP, "CCMP", 0 },
2855 { WPA_DRIVER_CAPA_ENC_GCMP, "GCMP", 0 },
2856 { WPA_DRIVER_CAPA_ENC_TKIP, "TKIP", 0 },
2857 { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE, "NONE", 0 },
2858 { WPA_DRIVER_CAPA_ENC_WEP104, "WEP104", 1 },
2859 { WPA_DRIVER_CAPA_ENC_WEP40, "WEP40", 1 }
2863 static int ctrl_iface_get_capability_pairwise(int res, char *strict,
2864 struct wpa_driver_capa *capa,
2865 char *buf, size_t buflen)
2878 len = os_strlcpy(buf, "CCMP TKIP NONE", buflen);
2884 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
2885 if (!ciphers[i].group_only && capa->enc & ciphers[i].capa) {
2886 ret = os_snprintf(pos, end - pos, "%s%s",
2887 pos == buf ? "" : " ",
2889 if (ret < 0 || ret >= end - pos)
2899 static int ctrl_iface_get_capability_group(int res, char *strict,
2900 struct wpa_driver_capa *capa,
2901 char *buf, size_t buflen)
2914 len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen);
2920 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
2921 if (capa->enc & ciphers[i].capa) {
2922 ret = os_snprintf(pos, end - pos, "%s%s",
2923 pos == buf ? "" : " ",
2925 if (ret < 0 || ret >= end - pos)
2935 static int ctrl_iface_get_capability_key_mgmt(int res, char *strict,
2936 struct wpa_driver_capa *capa,
2937 char *buf, size_t buflen)
2949 len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
2956 ret = os_snprintf(pos, end - pos, "NONE IEEE8021X");
2957 if (ret < 0 || ret >= end - pos)
2961 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
2962 WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
2963 ret = os_snprintf(pos, end - pos, " WPA-EAP");
2964 if (ret < 0 || ret >= end - pos)
2969 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
2970 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
2971 ret = os_snprintf(pos, end - pos, " WPA-PSK");
2972 if (ret < 0 || ret >= end - pos)
2977 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
2978 ret = os_snprintf(pos, end - pos, " WPA-NONE");
2979 if (ret < 0 || ret >= end - pos)
2988 static int ctrl_iface_get_capability_proto(int res, char *strict,
2989 struct wpa_driver_capa *capa,
2990 char *buf, size_t buflen)
3002 len = os_strlcpy(buf, "RSN WPA", buflen);
3008 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
3009 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
3010 ret = os_snprintf(pos, end - pos, "%sRSN",
3011 pos == buf ? "" : " ");
3012 if (ret < 0 || ret >= end - pos)
3017 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
3018 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
3019 ret = os_snprintf(pos, end - pos, "%sWPA",
3020 pos == buf ? "" : " ");
3021 if (ret < 0 || ret >= end - pos)
3030 static int ctrl_iface_get_capability_auth_alg(int res, char *strict,
3031 struct wpa_driver_capa *capa,
3032 char *buf, size_t buflen)
3044 len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen);
3050 if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) {
3051 ret = os_snprintf(pos, end - pos, "%sOPEN",
3052 pos == buf ? "" : " ");
3053 if (ret < 0 || ret >= end - pos)
3058 if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) {
3059 ret = os_snprintf(pos, end - pos, "%sSHARED",
3060 pos == buf ? "" : " ");
3061 if (ret < 0 || ret >= end - pos)
3066 if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) {
3067 ret = os_snprintf(pos, end - pos, "%sLEAP",
3068 pos == buf ? "" : " ");
3069 if (ret < 0 || ret >= end - pos)
3078 static int ctrl_iface_get_capability_modes(int res, char *strict,
3079 struct wpa_driver_capa *capa,
3080 char *buf, size_t buflen)
3092 len = os_strlcpy(buf, "IBSS AP", buflen);
3098 if (capa->flags & WPA_DRIVER_FLAGS_IBSS) {
3099 ret = os_snprintf(pos, end - pos, "%sIBSS",
3100 pos == buf ? "" : " ");
3101 if (ret < 0 || ret >= end - pos)
3106 if (capa->flags & WPA_DRIVER_FLAGS_AP) {
3107 ret = os_snprintf(pos, end - pos, "%sAP",
3108 pos == buf ? "" : " ");
3109 if (ret < 0 || ret >= end - pos)
3118 static int ctrl_iface_get_capability_channels(struct wpa_supplicant *wpa_s,
3119 char *buf, size_t buflen)
3121 struct hostapd_channel_data *chnl;
3123 char *pos, *end, *hmode;
3128 for (j = 0; j < wpa_s->hw.num_modes; j++) {
3129 switch (wpa_s->hw.modes[j].mode) {
3130 case HOSTAPD_MODE_IEEE80211B:
3133 case HOSTAPD_MODE_IEEE80211G:
3136 case HOSTAPD_MODE_IEEE80211A:
3139 case HOSTAPD_MODE_IEEE80211AD:
3145 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:", hmode);
3146 if (ret < 0 || ret >= end - pos)
3149 chnl = wpa_s->hw.modes[j].channels;
3150 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
3151 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
3153 ret = os_snprintf(pos, end - pos, " %d", chnl[i].chan);
3154 if (ret < 0 || ret >= end - pos)
3158 ret = os_snprintf(pos, end - pos, "\n");
3159 if (ret < 0 || ret >= end - pos)
3168 static int ctrl_iface_get_capability_freq(struct wpa_supplicant *wpa_s,
3169 char *buf, size_t buflen)
3171 struct hostapd_channel_data *chnl;
3173 char *pos, *end, *hmode;
3178 for (j = 0; j < wpa_s->hw.num_modes; j++) {
3179 switch (wpa_s->hw.modes[j].mode) {
3180 case HOSTAPD_MODE_IEEE80211B:
3183 case HOSTAPD_MODE_IEEE80211G:
3186 case HOSTAPD_MODE_IEEE80211A:
3189 case HOSTAPD_MODE_IEEE80211AD:
3195 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:\n",
3197 if (ret < 0 || ret >= end - pos)
3200 chnl = wpa_s->hw.modes[j].channels;
3201 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
3202 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
3204 ret = os_snprintf(pos, end - pos, " %d = %d MHz%s%s\n",
3205 chnl[i].chan, chnl[i].freq,
3206 chnl[i].flag & HOSTAPD_CHAN_NO_IBSS ?
3208 chnl[i].flag & HOSTAPD_CHAN_RADAR ?
3211 if (ret < 0 || ret >= end - pos)
3215 ret = os_snprintf(pos, end - pos, "\n");
3216 if (ret < 0 || ret >= end - pos)
3225 static int wpa_supplicant_ctrl_iface_get_capability(
3226 struct wpa_supplicant *wpa_s, const char *_field, char *buf,
3229 struct wpa_driver_capa capa;
3235 /* Determine whether or not strict checking was requested */
3236 len = os_strlcpy(field, _field, sizeof(field));
3237 if (len >= sizeof(field))
3239 strict = os_strchr(field, ' ');
3240 if (strict != NULL) {
3242 if (os_strcmp(strict, "strict") != 0)
3246 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
3247 field, strict ? strict : "");
3249 if (os_strcmp(field, "eap") == 0) {
3250 return eap_get_names(buf, buflen);
3253 res = wpa_drv_get_capa(wpa_s, &capa);
3255 if (os_strcmp(field, "pairwise") == 0)
3256 return ctrl_iface_get_capability_pairwise(res, strict, &capa,
3259 if (os_strcmp(field, "group") == 0)
3260 return ctrl_iface_get_capability_group(res, strict, &capa,
3263 if (os_strcmp(field, "key_mgmt") == 0)
3264 return ctrl_iface_get_capability_key_mgmt(res, strict, &capa,
3267 if (os_strcmp(field, "proto") == 0)
3268 return ctrl_iface_get_capability_proto(res, strict, &capa,
3271 if (os_strcmp(field, "auth_alg") == 0)
3272 return ctrl_iface_get_capability_auth_alg(res, strict, &capa,
3275 if (os_strcmp(field, "modes") == 0)
3276 return ctrl_iface_get_capability_modes(res, strict, &capa,
3279 if (os_strcmp(field, "channels") == 0)
3280 return ctrl_iface_get_capability_channels(wpa_s, buf, buflen);
3282 if (os_strcmp(field, "freq") == 0)
3283 return ctrl_iface_get_capability_freq(wpa_s, buf, buflen);
3285 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
3292 #ifdef CONFIG_INTERWORKING
3293 static char * anqp_add_hex(char *pos, char *end, const char *title,
3294 struct wpabuf *data)
3304 ret = os_snprintf(pos, end - pos, "%s=", title);
3305 if (ret < 0 || ret >= end - pos)
3309 d = wpabuf_head_u8(data);
3310 for (i = 0; i < wpabuf_len(data); i++) {
3311 ret = os_snprintf(pos, end - pos, "%02x", *d++);
3312 if (ret < 0 || ret >= end - pos)
3317 ret = os_snprintf(pos, end - pos, "\n");
3318 if (ret < 0 || ret >= end - pos)
3324 #endif /* CONFIG_INTERWORKING */
3327 static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
3328 unsigned long mask, char *buf, size_t buflen)
3338 if (mask & WPA_BSS_MASK_ID) {
3339 ret = os_snprintf(pos, end - pos, "id=%u\n", bss->id);
3340 if (ret < 0 || ret >= end - pos)
3345 if (mask & WPA_BSS_MASK_BSSID) {
3346 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
3347 MAC2STR(bss->bssid));
3348 if (ret < 0 || ret >= end - pos)
3353 if (mask & WPA_BSS_MASK_FREQ) {
3354 ret = os_snprintf(pos, end - pos, "freq=%d\n", bss->freq);
3355 if (ret < 0 || ret >= end - pos)
3360 if (mask & WPA_BSS_MASK_BEACON_INT) {
3361 ret = os_snprintf(pos, end - pos, "beacon_int=%d\n",
3363 if (ret < 0 || ret >= end - pos)
3368 if (mask & WPA_BSS_MASK_CAPABILITIES) {
3369 ret = os_snprintf(pos, end - pos, "capabilities=0x%04x\n",
3371 if (ret < 0 || ret >= end - pos)
3376 if (mask & WPA_BSS_MASK_QUAL) {
3377 ret = os_snprintf(pos, end - pos, "qual=%d\n", bss->qual);
3378 if (ret < 0 || ret >= end - pos)
3383 if (mask & WPA_BSS_MASK_NOISE) {
3384 ret = os_snprintf(pos, end - pos, "noise=%d\n", bss->noise);
3385 if (ret < 0 || ret >= end - pos)
3390 if (mask & WPA_BSS_MASK_LEVEL) {
3391 ret = os_snprintf(pos, end - pos, "level=%d\n", bss->level);
3392 if (ret < 0 || ret >= end - pos)
3397 if (mask & WPA_BSS_MASK_TSF) {
3398 ret = os_snprintf(pos, end - pos, "tsf=%016llu\n",
3399 (unsigned long long) bss->tsf);
3400 if (ret < 0 || ret >= end - pos)
3405 if (mask & WPA_BSS_MASK_AGE) {
3406 struct os_reltime now;
3408 os_get_reltime(&now);
3409 ret = os_snprintf(pos, end - pos, "age=%d\n",
3410 (int) (now.sec - bss->last_update.sec));
3411 if (ret < 0 || ret >= end - pos)
3416 if (mask & WPA_BSS_MASK_IE) {
3417 ret = os_snprintf(pos, end - pos, "ie=");
3418 if (ret < 0 || ret >= end - pos)
3422 ie = (const u8 *) (bss + 1);
3423 for (i = 0; i < bss->ie_len; i++) {
3424 ret = os_snprintf(pos, end - pos, "%02x", *ie++);
3425 if (ret < 0 || ret >= end - pos)
3430 ret = os_snprintf(pos, end - pos, "\n");
3431 if (ret < 0 || ret >= end - pos)
3436 if (mask & WPA_BSS_MASK_FLAGS) {
3437 ret = os_snprintf(pos, end - pos, "flags=");
3438 if (ret < 0 || ret >= end - pos)
3442 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
3444 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie,
3446 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
3448 pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2,
3450 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
3451 if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
3452 ret = os_snprintf(pos, end - pos, "[WEP]");
3453 if (ret < 0 || ret >= end - pos)
3457 if (bss->caps & IEEE80211_CAP_IBSS) {
3458 ret = os_snprintf(pos, end - pos, "[IBSS]");
3459 if (ret < 0 || ret >= end - pos)
3463 if (bss->caps & IEEE80211_CAP_ESS) {
3464 ret = os_snprintf(pos, end - pos, "[ESS]");
3465 if (ret < 0 || ret >= end - pos)
3469 if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
3470 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
3471 ret = os_snprintf(pos, end - pos, "[P2P]");
3472 if (ret < 0 || ret >= end - pos)
3477 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) {
3478 ret = os_snprintf(pos, end - pos, "[HS20]");
3479 if (ret < 0 || ret >= end - pos)
3483 #endif /* CONFIG_HS20 */
3485 ret = os_snprintf(pos, end - pos, "\n");
3486 if (ret < 0 || ret >= end - pos)
3491 if (mask & WPA_BSS_MASK_SSID) {
3492 ret = os_snprintf(pos, end - pos, "ssid=%s\n",
3493 wpa_ssid_txt(bss->ssid, bss->ssid_len));
3494 if (ret < 0 || ret >= end - pos)
3500 if (mask & WPA_BSS_MASK_WPS_SCAN) {
3501 ie = (const u8 *) (bss + 1);
3502 ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end);
3503 if (ret < 0 || ret >= end - pos)
3507 #endif /* CONFIG_WPS */
3510 if (mask & WPA_BSS_MASK_P2P_SCAN) {
3511 ie = (const u8 *) (bss + 1);
3512 ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end);
3513 if (ret < 0 || ret >= end - pos)
3517 #endif /* CONFIG_P2P */
3519 #ifdef CONFIG_WIFI_DISPLAY
3520 if (mask & WPA_BSS_MASK_WIFI_DISPLAY) {
3522 ie = (const u8 *) (bss + 1);
3523 wfd = ieee802_11_vendor_ie_concat(ie, bss->ie_len,
3524 WFD_IE_VENDOR_TYPE);
3526 ret = os_snprintf(pos, end - pos, "wfd_subelems=");
3527 if (ret < 0 || ret >= end - pos) {
3533 pos += wpa_snprintf_hex(pos, end - pos,
3538 ret = os_snprintf(pos, end - pos, "\n");
3539 if (ret < 0 || ret >= end - pos)
3544 #endif /* CONFIG_WIFI_DISPLAY */
3546 #ifdef CONFIG_INTERWORKING
3547 if ((mask & WPA_BSS_MASK_INTERNETW) && bss->anqp) {
3548 struct wpa_bss_anqp *anqp = bss->anqp;
3549 pos = anqp_add_hex(pos, end, "anqp_venue_name",
3551 pos = anqp_add_hex(pos, end, "anqp_network_auth_type",
3552 anqp->network_auth_type);
3553 pos = anqp_add_hex(pos, end, "anqp_roaming_consortium",
3554 anqp->roaming_consortium);
3555 pos = anqp_add_hex(pos, end, "anqp_ip_addr_type_availability",
3556 anqp->ip_addr_type_availability);
3557 pos = anqp_add_hex(pos, end, "anqp_nai_realm",
3559 pos = anqp_add_hex(pos, end, "anqp_3gpp", anqp->anqp_3gpp);
3560 pos = anqp_add_hex(pos, end, "anqp_domain_name",
3563 pos = anqp_add_hex(pos, end, "hs20_operator_friendly_name",
3564 anqp->hs20_operator_friendly_name);
3565 pos = anqp_add_hex(pos, end, "hs20_wan_metrics",
3566 anqp->hs20_wan_metrics);
3567 pos = anqp_add_hex(pos, end, "hs20_connection_capability",
3568 anqp->hs20_connection_capability);
3569 pos = anqp_add_hex(pos, end, "hs20_operating_class",
3570 anqp->hs20_operating_class);
3571 pos = anqp_add_hex(pos, end, "hs20_osu_providers_list",
3572 anqp->hs20_osu_providers_list);
3573 #endif /* CONFIG_HS20 */
3575 #endif /* CONFIG_INTERWORKING */
3577 if (mask & WPA_BSS_MASK_DELIM) {
3578 ret = os_snprintf(pos, end - pos, "====\n");
3579 if (ret < 0 || ret >= end - pos)
3588 static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
3589 const char *cmd, char *buf,
3594 struct wpa_bss *bss;
3595 struct wpa_bss *bsslast = NULL;
3596 struct dl_list *next;
3600 unsigned long mask = WPA_BSS_MASK_ALL;
3602 if (os_strncmp(cmd, "RANGE=", 6) == 0) {
3603 if (os_strncmp(cmd + 6, "ALL", 3) == 0) {
3604 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss,
3606 bsslast = dl_list_last(&wpa_s->bss_id, struct wpa_bss,
3608 } else { /* N1-N2 */
3609 unsigned int id1, id2;
3611 if ((ctmp = os_strchr(cmd + 6, '-')) == NULL) {
3612 wpa_printf(MSG_INFO, "Wrong BSS range "
3617 if (*(cmd + 6) == '-')
3620 id1 = atoi(cmd + 6);
3622 if (*ctmp >= '0' && *ctmp <= '9')
3625 id2 = (unsigned int) -1;
3626 bss = wpa_bss_get_id_range(wpa_s, id1, id2);
3627 if (id2 == (unsigned int) -1)
3628 bsslast = dl_list_last(&wpa_s->bss_id,
3632 bsslast = wpa_bss_get_id(wpa_s, id2);
3633 if (bsslast == NULL && bss && id2 > id1) {
3634 struct wpa_bss *tmp = bss;
3636 next = tmp->list_id.next;
3637 if (next == &wpa_s->bss_id)
3639 tmp = dl_list_entry(
3640 next, struct wpa_bss,
3649 } else if (os_strncmp(cmd, "FIRST", 5) == 0)
3650 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, list_id);
3651 else if (os_strncmp(cmd, "LAST", 4) == 0)
3652 bss = dl_list_last(&wpa_s->bss_id, struct wpa_bss, list_id);
3653 else if (os_strncmp(cmd, "ID-", 3) == 0) {
3655 bss = wpa_bss_get_id(wpa_s, i);
3656 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
3658 bss = wpa_bss_get_id(wpa_s, i);
3660 next = bss->list_id.next;
3661 if (next == &wpa_s->bss_id)
3664 bss = dl_list_entry(next, struct wpa_bss,
3668 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
3669 if (hwaddr_aton(cmd + 13, bssid) == 0)
3670 bss = wpa_bss_get_p2p_dev_addr(wpa_s, bssid);
3673 #endif /* CONFIG_P2P */
3674 } else if (hwaddr_aton(cmd, bssid) == 0)
3675 bss = wpa_bss_get_bssid(wpa_s, bssid);
3677 struct wpa_bss *tmp;
3680 dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id)
3689 if ((ctmp = os_strstr(cmd, "MASK=")) != NULL) {
3690 mask = strtoul(ctmp + 5, NULL, 0x10);
3692 mask = WPA_BSS_MASK_ALL;
3698 if (bsslast == NULL)
3701 len = print_bss_info(wpa_s, bss, mask, buf, buflen);
3705 if (bss == bsslast) {
3706 if ((mask & WPA_BSS_MASK_DELIM) && len &&
3707 (bss == dl_list_last(&wpa_s->bss_id,
3708 struct wpa_bss, list_id)))
3709 os_snprintf(buf - 5, 5, "####\n");
3712 next = bss->list_id.next;
3713 if (next == &wpa_s->bss_id)
3715 bss = dl_list_entry(next, struct wpa_bss, list_id);
3716 } while (bss && len);
3722 static int wpa_supplicant_ctrl_iface_ap_scan(
3723 struct wpa_supplicant *wpa_s, char *cmd)
3725 int ap_scan = atoi(cmd);
3726 return wpa_supplicant_set_ap_scan(wpa_s, ap_scan);
3730 static int wpa_supplicant_ctrl_iface_scan_interval(
3731 struct wpa_supplicant *wpa_s, char *cmd)
3733 int scan_int = atoi(cmd);
3734 return wpa_supplicant_set_scan_interval(wpa_s, scan_int);
3738 static int wpa_supplicant_ctrl_iface_bss_expire_age(
3739 struct wpa_supplicant *wpa_s, char *cmd)
3741 int expire_age = atoi(cmd);
3742 return wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age);
3746 static int wpa_supplicant_ctrl_iface_bss_expire_count(
3747 struct wpa_supplicant *wpa_s, char *cmd)
3749 int expire_count = atoi(cmd);
3750 return wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count);
3754 static int wpa_supplicant_ctrl_iface_bss_flush(
3755 struct wpa_supplicant *wpa_s, char *cmd)
3757 int flush_age = atoi(cmd);
3760 wpa_bss_flush(wpa_s);
3762 wpa_bss_flush_by_age(wpa_s, flush_age);
3767 static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s)
3769 wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication");
3770 /* MLME-DELETEKEYS.request */
3771 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL, 0);
3772 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL, 0);
3773 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL, 0);
3774 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL, 0);
3775 #ifdef CONFIG_IEEE80211W
3776 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL, 0);
3777 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL, 0);
3778 #endif /* CONFIG_IEEE80211W */
3780 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, wpa_s->bssid, 0, 0, NULL, 0, NULL,
3782 /* MLME-SETPROTECTION.request(None) */
3783 wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid,
3784 MLME_SETPROTECTION_PROTECT_TYPE_NONE,
3785 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE);
3786 wpa_sm_drop_sa(wpa_s->wpa);
3790 static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s,
3793 #ifdef CONFIG_NO_SCAN_PROCESSING
3795 #else /* CONFIG_NO_SCAN_PROCESSING */
3797 struct wpa_bss *bss;
3798 struct wpa_ssid *ssid = wpa_s->current_ssid;
3800 if (hwaddr_aton(addr, bssid)) {
3801 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid "
3802 "address '%s'", addr);
3806 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR, MAC2STR(bssid));
3809 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network "
3810 "configuration known for the target AP");
3814 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
3816 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found "
3822 * TODO: Find best network configuration block from configuration to
3823 * allow roaming to other networks
3826 wpa_s->reassociate = 1;
3827 wpa_supplicant_connect(wpa_s, bss, ssid);
3830 #endif /* CONFIG_NO_SCAN_PROCESSING */
3835 static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd)
3837 unsigned int timeout = atoi(cmd);
3838 enum p2p_discovery_type type = P2P_FIND_START_WITH_FULL;
3839 u8 dev_id[ETH_ALEN], *_dev_id = NULL;
3840 u8 dev_type[WPS_DEV_TYPE_LEN], *_dev_type = NULL;
3842 unsigned int search_delay;
3844 if (os_strstr(cmd, "type=social"))
3845 type = P2P_FIND_ONLY_SOCIAL;
3846 else if (os_strstr(cmd, "type=progressive"))
3847 type = P2P_FIND_PROGRESSIVE;
3849 pos = os_strstr(cmd, "dev_id=");
3852 if (hwaddr_aton(pos, dev_id))
3857 pos = os_strstr(cmd, "dev_type=");
3860 if (wps_dev_type_str2bin(pos, dev_type) < 0)
3862 _dev_type = dev_type;
3865 pos = os_strstr(cmd, "delay=");
3868 search_delay = atoi(pos);
3870 search_delay = wpas_p2p_search_delay(wpa_s);
3872 return wpas_p2p_find(wpa_s, timeout, type, _dev_type != NULL, _dev_type,
3873 _dev_id, search_delay);
3877 static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd,
3878 char *buf, size_t buflen)
3883 enum p2p_wps_method wps_method;
3886 int persistent_group, persistent_id = -1;
3895 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad]
3896 * [persistent|persistent=<network id>]
3897 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
3900 if (hwaddr_aton(cmd, addr))
3908 persistent_group = os_strstr(pos, " persistent") != NULL;
3909 pos2 = os_strstr(pos, " persistent=");
3911 struct wpa_ssid *ssid;
3912 persistent_id = atoi(pos2 + 12);
3913 ssid = wpa_config_get_network(wpa_s->conf, persistent_id);
3914 if (ssid == NULL || ssid->disabled != 2 ||
3915 ssid->mode != WPAS_MODE_P2P_GO) {
3916 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3917 "SSID id=%d for persistent P2P group (GO)",
3922 join = os_strstr(pos, " join") != NULL;
3923 auth = os_strstr(pos, " auth") != NULL;
3924 automatic = os_strstr(pos, " auto") != NULL;
3925 pd = os_strstr(pos, " provdisc") != NULL;
3926 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
3927 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
3930 pos2 = os_strstr(pos, " go_intent=");
3933 go_intent = atoi(pos2);
3934 if (go_intent < 0 || go_intent > 15)
3938 pos2 = os_strstr(pos, " freq=");
3946 if (os_strncmp(pos, "pin", 3) == 0) {
3947 /* Request random PIN (to be displayed) and enable the PIN */
3948 wps_method = WPS_PIN_DISPLAY;
3949 } else if (os_strncmp(pos, "pbc", 3) == 0) {
3950 wps_method = WPS_PBC;
3953 pos = os_strchr(pin, ' ');
3954 wps_method = WPS_PIN_KEYPAD;
3957 if (os_strncmp(pos, "display", 7) == 0)
3958 wps_method = WPS_PIN_DISPLAY;
3960 if (!wps_pin_str_valid(pin)) {
3961 os_memcpy(buf, "FAIL-INVALID-PIN\n", 17);
3966 new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method,
3967 persistent_group, automatic, join,
3968 auth, go_intent, freq, persistent_id, pd,
3970 if (new_pin == -2) {
3971 os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
3974 if (new_pin == -3) {
3975 os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
3980 if (wps_method == WPS_PIN_DISPLAY && pin == NULL) {
3981 ret = os_snprintf(buf, buflen, "%08d", new_pin);
3982 if (ret < 0 || (size_t) ret >= buflen)
3987 os_memcpy(buf, "OK\n", 3);
3992 static int p2p_ctrl_listen(struct wpa_supplicant *wpa_s, char *cmd)
3994 unsigned int timeout = atoi(cmd);
3995 return wpas_p2p_listen(wpa_s, timeout);
3999 static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd)
4003 enum wpas_p2p_prov_disc_use use = WPAS_P2P_PD_FOR_GO_NEG;
4005 /* <addr> <config method> [join|auto] */
4007 if (hwaddr_aton(cmd, addr))
4015 if (os_strstr(pos, " join") != NULL)
4016 use = WPAS_P2P_PD_FOR_JOIN;
4017 else if (os_strstr(pos, " auto") != NULL)
4018 use = WPAS_P2P_PD_AUTO;
4020 return wpas_p2p_prov_disc(wpa_s, addr, pos, use);
4024 static int p2p_get_passphrase(struct wpa_supplicant *wpa_s, char *buf,
4027 struct wpa_ssid *ssid = wpa_s->current_ssid;
4029 if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO ||
4030 ssid->passphrase == NULL)
4033 os_strlcpy(buf, ssid->passphrase, buflen);
4034 return os_strlen(buf);
4038 static int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd,
4039 char *buf, size_t buflen)
4043 u8 dst_buf[ETH_ALEN], *dst;
4044 struct wpabuf *tlvs;
4048 if (hwaddr_aton(cmd, dst_buf))
4051 if (dst[0] == 0 && dst[1] == 0 && dst[2] == 0 &&
4052 dst[3] == 0 && dst[4] == 0 && dst[5] == 0)
4059 if (os_strncmp(pos, "upnp ", 5) == 0) {
4062 if (hexstr2bin(pos, &version, 1) < 0)
4068 ref = wpas_p2p_sd_request_upnp(wpa_s, dst, version, pos);
4069 #ifdef CONFIG_WIFI_DISPLAY
4070 } else if (os_strncmp(pos, "wifi-display ", 13) == 0) {
4071 ref = wpas_p2p_sd_request_wifi_display(wpa_s, dst, pos + 13);
4072 #endif /* CONFIG_WIFI_DISPLAY */
4074 len = os_strlen(pos);
4078 tlvs = wpabuf_alloc(len);
4081 if (hexstr2bin(pos, wpabuf_put(tlvs, len), len) < 0) {
4086 ref = wpas_p2p_sd_request(wpa_s, dst, tlvs);
4091 res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref);
4092 if (res < 0 || (unsigned) res >= buflen)
4098 static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s,
4101 long long unsigned val;
4103 if (sscanf(cmd, "%llx", &val) != 1)
4106 return wpas_p2p_sd_cancel_request(wpa_s, req);
4110 static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant *wpa_s, char *cmd)
4115 struct wpabuf *resp_tlvs;
4119 pos = os_strchr(cmd, ' ');
4127 if (hwaddr_aton(pos, dst))
4134 pos2 = os_strchr(pos, ' ');
4138 dialog_token = atoi(pos);
4140 len = os_strlen(pos2);
4144 resp_tlvs = wpabuf_alloc(len);
4145 if (resp_tlvs == NULL)
4147 if (hexstr2bin(pos2, wpabuf_put(resp_tlvs, len), len) < 0) {
4148 wpabuf_free(resp_tlvs);
4152 wpas_p2p_sd_response(wpa_s, freq, dst, dialog_token, resp_tlvs);
4153 wpabuf_free(resp_tlvs);
4158 static int p2p_ctrl_serv_disc_external(struct wpa_supplicant *wpa_s,
4161 if (os_strcmp(cmd, "0") && os_strcmp(cmd, "1"))
4163 wpa_s->p2p_sd_over_ctrl_iface = atoi(cmd);
4168 static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant *wpa_s,
4173 struct wpabuf *query, *resp;
4175 pos = os_strchr(cmd, ' ');
4180 len = os_strlen(cmd);
4184 query = wpabuf_alloc(len);
4187 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
4192 len = os_strlen(pos);
4198 resp = wpabuf_alloc(len);
4203 if (hexstr2bin(pos, wpabuf_put(resp, len), len) < 0) {
4209 if (wpas_p2p_service_add_bonjour(wpa_s, query, resp) < 0) {
4218 static int p2p_ctrl_service_add_upnp(struct wpa_supplicant *wpa_s, char *cmd)
4223 pos = os_strchr(cmd, ' ');
4228 if (hexstr2bin(cmd, &version, 1) < 0)
4231 return wpas_p2p_service_add_upnp(wpa_s, version, pos);
4235 static int p2p_ctrl_service_add(struct wpa_supplicant *wpa_s, char *cmd)
4239 pos = os_strchr(cmd, ' ');
4244 if (os_strcmp(cmd, "bonjour") == 0)
4245 return p2p_ctrl_service_add_bonjour(wpa_s, pos);
4246 if (os_strcmp(cmd, "upnp") == 0)
4247 return p2p_ctrl_service_add_upnp(wpa_s, pos);
4248 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
4253 static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant *wpa_s,
4257 struct wpabuf *query;
4260 len = os_strlen(cmd);
4264 query = wpabuf_alloc(len);
4267 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
4272 ret = wpas_p2p_service_del_bonjour(wpa_s, query);
4278 static int p2p_ctrl_service_del_upnp(struct wpa_supplicant *wpa_s, char *cmd)
4283 pos = os_strchr(cmd, ' ');
4288 if (hexstr2bin(cmd, &version, 1) < 0)
4291 return wpas_p2p_service_del_upnp(wpa_s, version, pos);
4295 static int p2p_ctrl_service_del(struct wpa_supplicant *wpa_s, char *cmd)
4299 pos = os_strchr(cmd, ' ');
4304 if (os_strcmp(cmd, "bonjour") == 0)
4305 return p2p_ctrl_service_del_bonjour(wpa_s, pos);
4306 if (os_strcmp(cmd, "upnp") == 0)
4307 return p2p_ctrl_service_del_upnp(wpa_s, pos);
4308 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
4313 static int p2p_ctrl_reject(struct wpa_supplicant *wpa_s, char *cmd)
4319 if (hwaddr_aton(cmd, addr))
4322 return wpas_p2p_reject(wpa_s, addr);
4326 static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd)
4330 struct wpa_ssid *ssid;
4331 u8 *_peer = NULL, peer[ETH_ALEN];
4332 int freq = 0, pref_freq = 0;
4336 pos = os_strstr(cmd, " peer=");
4339 if (hwaddr_aton(pos, peer))
4343 ssid = wpa_config_get_network(wpa_s->conf, id);
4344 if (ssid == NULL || ssid->disabled != 2) {
4345 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
4346 "for persistent P2P group",
4351 pos = os_strstr(cmd, " freq=");
4359 pos = os_strstr(cmd, " pref=");
4362 pref_freq = atoi(pos);
4367 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
4368 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
4371 return wpas_p2p_invite(wpa_s, _peer, ssid, NULL, freq, ht40, vht,
4376 static int p2p_ctrl_invite_group(struct wpa_supplicant *wpa_s, char *cmd)
4379 u8 peer[ETH_ALEN], go_dev_addr[ETH_ALEN], *go_dev = NULL;
4381 pos = os_strstr(cmd, " peer=");
4387 if (hwaddr_aton(pos, peer)) {
4388 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", pos);
4392 pos = os_strstr(pos, " go_dev_addr=");
4395 if (hwaddr_aton(pos, go_dev_addr)) {
4396 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'",
4400 go_dev = go_dev_addr;
4403 return wpas_p2p_invite_group(wpa_s, cmd, peer, go_dev);
4407 static int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd)
4409 if (os_strncmp(cmd, "persistent=", 11) == 0)
4410 return p2p_ctrl_invite_persistent(wpa_s, cmd + 11);
4411 if (os_strncmp(cmd, "group=", 6) == 0)
4412 return p2p_ctrl_invite_group(wpa_s, cmd + 6);
4418 static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s,
4419 char *cmd, int freq, int ht40,
4423 struct wpa_ssid *ssid;
4426 ssid = wpa_config_get_network(wpa_s->conf, id);
4427 if (ssid == NULL || ssid->disabled != 2) {
4428 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
4429 "for persistent P2P group",
4434 return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq, 0, ht40, vht,
4439 static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd)
4441 int freq = 0, ht40, vht;
4444 pos = os_strstr(cmd, "freq=");
4446 freq = atoi(pos + 5);
4448 vht = (os_strstr(cmd, "vht") != NULL) || wpa_s->conf->p2p_go_vht;
4449 ht40 = (os_strstr(cmd, "ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
4452 if (os_strncmp(cmd, "persistent=", 11) == 0)
4453 return p2p_ctrl_group_add_persistent(wpa_s, cmd + 11, freq,
4455 if (os_strcmp(cmd, "persistent") == 0 ||
4456 os_strncmp(cmd, "persistent ", 11) == 0)
4457 return wpas_p2p_group_add(wpa_s, 1, freq, ht40, vht);
4458 if (os_strncmp(cmd, "freq=", 5) == 0)
4459 return wpas_p2p_group_add(wpa_s, 0, freq, ht40, vht);
4461 return wpas_p2p_group_add(wpa_s, 0, freq, ht40, vht);
4463 wpa_printf(MSG_DEBUG, "CTRL: Invalid P2P_GROUP_ADD parameters '%s'",
4469 static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd,
4470 char *buf, size_t buflen)
4472 u8 addr[ETH_ALEN], *addr_ptr;
4474 const struct p2p_peer_info *info;
4476 char devtype[WPS_DEV_TYPE_BUFSIZE];
4477 struct wpa_ssid *ssid;
4480 if (!wpa_s->global->p2p)
4483 if (os_strcmp(cmd, "FIRST") == 0) {
4486 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
4487 if (hwaddr_aton(cmd + 5, addr) < 0)
4492 if (hwaddr_aton(cmd, addr) < 0)
4498 info = p2p_get_peer_info(wpa_s->global->p2p, addr_ptr, next);
4505 res = os_snprintf(pos, end - pos, MACSTR "\n"
4511 "serial_number=%s\n"
4512 "config_methods=0x%x\n"
4514 "group_capab=0x%x\n"
4516 MAC2STR(info->p2p_device_addr),
4517 wps_dev_type_bin2str(info->pri_dev_type,
4518 devtype, sizeof(devtype)),
4523 info->serial_number,
4524 info->config_methods,
4528 if (res < 0 || res >= end - pos)
4532 for (i = 0; i < info->wps_sec_dev_type_list_len / WPS_DEV_TYPE_LEN; i++)
4535 t = &info->wps_sec_dev_type_list[i * WPS_DEV_TYPE_LEN];
4536 res = os_snprintf(pos, end - pos, "sec_dev_type=%s\n",
4537 wps_dev_type_bin2str(t, devtype,
4539 if (res < 0 || res >= end - pos)
4544 ssid = wpas_p2p_get_persistent(wpa_s, info->p2p_device_addr, NULL, 0);
4546 res = os_snprintf(pos, end - pos, "persistent=%d\n", ssid->id);
4547 if (res < 0 || res >= end - pos)
4552 res = p2p_get_peer_info_txt(info, pos, end - pos);
4561 static int p2p_ctrl_disallow_freq(struct wpa_supplicant *wpa_s,
4566 if (wpa_s->global->p2p == NULL)
4569 if (freq_range_list_parse(&wpa_s->global->p2p_disallow_freq, param) < 0)
4572 for (i = 0; i < wpa_s->global->p2p_disallow_freq.num; i++) {
4573 struct wpa_freq_range *freq;
4574 freq = &wpa_s->global->p2p_disallow_freq.range[i];
4575 wpa_printf(MSG_DEBUG, "P2P: Disallowed frequency range %u-%u",
4576 freq->min, freq->max);
4579 wpas_p2p_update_channel_list(wpa_s);
4584 static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd)
4588 if (wpa_s->global->p2p == NULL)
4591 param = os_strchr(cmd, ' ');
4596 if (os_strcmp(cmd, "discoverability") == 0) {
4597 p2p_set_client_discoverability(wpa_s->global->p2p,
4602 if (os_strcmp(cmd, "managed") == 0) {
4603 p2p_set_managed_oper(wpa_s->global->p2p, atoi(param));
4607 if (os_strcmp(cmd, "listen_channel") == 0) {
4608 return p2p_set_listen_channel(wpa_s->global->p2p, 81,
4612 if (os_strcmp(cmd, "ssid_postfix") == 0) {
4613 return p2p_set_ssid_postfix(wpa_s->global->p2p, (u8 *) param,
4617 if (os_strcmp(cmd, "noa") == 0) {
4619 int count, start, duration;
4620 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
4621 count = atoi(param);
4622 pos = os_strchr(param, ',');
4627 pos = os_strchr(pos, ',');
4631 duration = atoi(pos);
4632 if (count < 0 || count > 255 || start < 0 || duration < 0)
4634 if (count == 0 && duration > 0)
4636 wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
4637 "start=%d duration=%d", count, start, duration);
4638 return wpas_p2p_set_noa(wpa_s, count, start, duration);
4641 if (os_strcmp(cmd, "ps") == 0)
4642 return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1);
4644 if (os_strcmp(cmd, "oppps") == 0)
4645 return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1);
4647 if (os_strcmp(cmd, "ctwindow") == 0)
4648 return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param));
4650 if (os_strcmp(cmd, "disabled") == 0) {
4651 wpa_s->global->p2p_disabled = atoi(param);
4652 wpa_printf(MSG_DEBUG, "P2P functionality %s",
4653 wpa_s->global->p2p_disabled ?
4654 "disabled" : "enabled");
4655 if (wpa_s->global->p2p_disabled) {
4656 wpas_p2p_stop_find(wpa_s);
4657 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
4658 p2p_flush(wpa_s->global->p2p);
4663 if (os_strcmp(cmd, "conc_pref") == 0) {
4664 if (os_strcmp(param, "sta") == 0)
4665 wpa_s->global->conc_pref = WPA_CONC_PREF_STA;
4666 else if (os_strcmp(param, "p2p") == 0)
4667 wpa_s->global->conc_pref = WPA_CONC_PREF_P2P;
4669 wpa_printf(MSG_INFO, "Invalid conc_pref value");
4672 wpa_printf(MSG_DEBUG, "Single channel concurrency preference: "
4677 if (os_strcmp(cmd, "force_long_sd") == 0) {
4678 wpa_s->force_long_sd = atoi(param);
4682 if (os_strcmp(cmd, "peer_filter") == 0) {
4684 if (hwaddr_aton(param, addr))
4686 p2p_set_peer_filter(wpa_s->global->p2p, addr);
4690 if (os_strcmp(cmd, "cross_connect") == 0)
4691 return wpas_p2p_set_cross_connect(wpa_s, atoi(param));
4693 if (os_strcmp(cmd, "go_apsd") == 0) {
4694 if (os_strcmp(param, "disable") == 0)
4695 wpa_s->set_ap_uapsd = 0;
4697 wpa_s->set_ap_uapsd = 1;
4698 wpa_s->ap_uapsd = atoi(param);
4703 if (os_strcmp(cmd, "client_apsd") == 0) {
4704 if (os_strcmp(param, "disable") == 0)
4705 wpa_s->set_sta_uapsd = 0;
4709 /* format: BE,BK,VI,VO;max SP Length */
4711 pos = os_strchr(param, ',');
4716 pos = os_strchr(pos, ',');
4721 pos = os_strchr(pos, ',');
4726 /* ignore max SP Length for now */
4728 wpa_s->set_sta_uapsd = 1;
4729 wpa_s->sta_uapsd = 0;
4731 wpa_s->sta_uapsd |= BIT(0);
4733 wpa_s->sta_uapsd |= BIT(1);
4735 wpa_s->sta_uapsd |= BIT(2);
4737 wpa_s->sta_uapsd |= BIT(3);
4742 if (os_strcmp(cmd, "disallow_freq") == 0)
4743 return p2p_ctrl_disallow_freq(wpa_s, param);
4745 if (os_strcmp(cmd, "disc_int") == 0) {
4746 int min_disc_int, max_disc_int, max_disc_tu;
4751 min_disc_int = atoi(pos);
4752 pos = os_strchr(pos, ' ');
4757 max_disc_int = atoi(pos);
4758 pos = os_strchr(pos, ' ');
4763 max_disc_tu = atoi(pos);
4765 return p2p_set_disc_int(wpa_s->global->p2p, min_disc_int,
4766 max_disc_int, max_disc_tu);
4769 if (os_strcmp(cmd, "per_sta_psk") == 0) {
4770 wpa_s->global->p2p_per_sta_psk = !!atoi(param);
4774 #ifdef CONFIG_WPS_NFC
4775 if (os_strcmp(cmd, "nfc_tag") == 0)
4776 return wpas_p2p_nfc_tag_enabled(wpa_s, !!atoi(param));
4777 #endif /* CONFIG_WPS_NFC */
4779 if (os_strcmp(cmd, "disable_ip_addr_req") == 0) {
4780 wpa_s->p2p_disable_ip_addr_req = !!atoi(param);
4784 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
4791 static void p2p_ctrl_flush(struct wpa_supplicant *wpa_s)
4793 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
4794 wpa_s->force_long_sd = 0;
4795 if (wpa_s->global->p2p)
4796 p2p_flush(wpa_s->global->p2p);
4800 static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd)
4803 unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0;
4806 pos = os_strchr(cmd, ' ');
4812 pos2 = os_strchr(pos, ' ');
4820 pos = os_strchr(pos2, ' ');
4828 return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2);
4832 static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd)
4835 unsigned int period = 0, interval = 0;
4838 pos = os_strchr(cmd, ' ');
4843 interval = atoi(pos);
4846 return wpas_p2p_ext_listen(wpa_s, period, interval);
4850 static int p2p_ctrl_remove_client(struct wpa_supplicant *wpa_s, const char *cmd)
4857 if (os_strncmp(pos, "iface=", 6) == 0) {
4861 if (hwaddr_aton(pos, peer))
4864 wpas_p2p_remove_client(wpa_s, peer, iface_addr);
4868 #endif /* CONFIG_P2P */
4871 static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s, char *val)
4873 struct wpa_freq_range_list ranges;
4875 struct hostapd_hw_modes *mode;
4878 if (wpa_s->hw.modes == NULL)
4881 os_memset(&ranges, 0, sizeof(ranges));
4882 if (freq_range_list_parse(&ranges, val) < 0)
4885 for (i = 0; i < wpa_s->hw.num_modes; i++) {
4888 mode = &wpa_s->hw.modes[i];
4889 for (j = 0; j < mode->num_channels; j++) {
4892 if (mode->channels[j].flag & HOSTAPD_CHAN_DISABLED)
4895 freq = mode->channels[j].freq;
4896 if (!freq_range_list_includes(&ranges, freq))
4899 int_array_add_unique(&freqs, freq);
4903 os_free(ranges.range);
4908 #ifdef CONFIG_INTERWORKING
4910 static int ctrl_interworking_select(struct wpa_supplicant *wpa_s, char *param)
4918 auto_sel = os_strstr(param, "auto") != NULL;
4920 pos = os_strstr(param, "freq=");
4922 freqs = freq_range_to_channel_list(wpa_s, pos + 5);
4929 return interworking_select(wpa_s, auto_sel, freqs);
4933 static int ctrl_interworking_connect(struct wpa_supplicant *wpa_s, char *dst)
4936 struct wpa_bss *bss;
4938 if (hwaddr_aton(dst, bssid)) {
4939 wpa_printf(MSG_DEBUG, "Invalid BSSID '%s'", dst);
4943 bss = wpa_bss_get_bssid(wpa_s, bssid);
4945 wpa_printf(MSG_DEBUG, "Could not find BSS " MACSTR,
4950 return interworking_connect(wpa_s, bss);
4954 static int get_anqp(struct wpa_supplicant *wpa_s, char *dst)
4956 u8 dst_addr[ETH_ALEN];
4959 #define MAX_ANQP_INFO_ID 100
4960 u16 id[MAX_ANQP_INFO_ID];
4963 used = hwaddr_aton2(dst, dst_addr);
4967 while (num_id < MAX_ANQP_INFO_ID) {
4968 id[num_id] = atoi(pos);
4971 pos = os_strchr(pos + 1, ',');
4980 return anqp_send_req(wpa_s, dst_addr, id, num_id);
4984 static int gas_request(struct wpa_supplicant *wpa_s, char *cmd)
4986 u8 dst_addr[ETH_ALEN];
4987 struct wpabuf *advproto, *query = NULL;
4992 used = hwaddr_aton2(cmd, dst_addr);
5000 /* Advertisement Protocol ID */
5001 end = os_strchr(pos, ' ');
5005 len = os_strlen(pos);
5011 advproto = wpabuf_alloc(len);
5012 if (advproto == NULL)
5014 if (hexstr2bin(pos, wpabuf_put(advproto, len), len) < 0)
5018 /* Optional Query Request */
5023 len = os_strlen(pos);
5030 query = wpabuf_alloc(len);
5033 if (hexstr2bin(pos, wpabuf_put(query, len), len) < 0)
5038 ret = gas_send_request(wpa_s, dst_addr, advproto, query);
5041 wpabuf_free(advproto);
5048 static int gas_response_get(struct wpa_supplicant *wpa_s, char *cmd, char *buf,
5055 size_t resp_len, start, requested_len;
5056 struct wpabuf *resp;
5059 used = hwaddr_aton2(cmd, addr);
5066 dialog_token = atoi(pos);
5068 if (wpa_s->last_gas_resp &&
5069 os_memcmp(addr, wpa_s->last_gas_addr, ETH_ALEN) == 0 &&
5070 dialog_token == wpa_s->last_gas_dialog_token)
5071 resp = wpa_s->last_gas_resp;
5072 else if (wpa_s->prev_gas_resp &&
5073 os_memcmp(addr, wpa_s->prev_gas_addr, ETH_ALEN) == 0 &&
5074 dialog_token == wpa_s->prev_gas_dialog_token)
5075 resp = wpa_s->prev_gas_resp;
5079 resp_len = wpabuf_len(resp);
5081 requested_len = resp_len;
5083 pos = os_strchr(pos, ' ');
5086 if (start > resp_len)
5087 return os_snprintf(buf, buflen, "FAIL-Invalid range");
5088 pos = os_strchr(pos, ',');
5092 requested_len = atoi(pos);
5093 if (start + requested_len > resp_len)
5094 return os_snprintf(buf, buflen, "FAIL-Invalid range");
5097 if (requested_len * 2 + 1 > buflen)
5098 return os_snprintf(buf, buflen, "FAIL-Too long response");
5100 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(resp) + start,
5103 if (start + requested_len == resp_len) {
5105 * Free memory by dropping the response after it has been
5108 if (resp == wpa_s->prev_gas_resp) {
5109 wpabuf_free(wpa_s->prev_gas_resp);
5110 wpa_s->prev_gas_resp = NULL;
5112 wpabuf_free(wpa_s->last_gas_resp);
5113 wpa_s->last_gas_resp = NULL;
5119 #endif /* CONFIG_INTERWORKING */
5124 static int get_hs20_anqp(struct wpa_supplicant *wpa_s, char *dst)
5126 u8 dst_addr[ETH_ALEN];
5131 used = hwaddr_aton2(dst, dst_addr);
5136 int num = atoi(pos);
5137 if (num <= 0 || num > 31)
5139 subtypes |= BIT(num);
5140 pos = os_strchr(pos + 1, ',');
5149 return hs20_anqp_send_req(wpa_s, dst_addr, subtypes, NULL, 0);
5153 static int hs20_nai_home_realm_list(struct wpa_supplicant *wpa_s,
5154 const u8 *addr, const char *realm)
5160 rlen = os_strlen(realm);
5162 buf = os_malloc(len);
5165 buf[0] = 1; /* NAI Home Realm Count */
5166 buf[1] = 0; /* Formatted in accordance with RFC 4282 */
5168 os_memcpy(buf + 3, realm, rlen);
5170 ret = hs20_anqp_send_req(wpa_s, addr,
5171 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
5180 static int hs20_get_nai_home_realm_list(struct wpa_supplicant *wpa_s,
5183 struct wpa_cred *cred = wpa_s->conf->cred;
5184 u8 dst_addr[ETH_ALEN];
5190 used = hwaddr_aton2(dst, dst_addr);
5194 while (dst[used] == ' ')
5196 if (os_strncmp(dst + used, "realm=", 6) == 0)
5197 return hs20_nai_home_realm_list(wpa_s, dst_addr,
5200 len = os_strlen(dst + used);
5202 if (len == 0 && cred && cred->realm)
5203 return hs20_nai_home_realm_list(wpa_s, dst_addr, cred->realm);
5208 buf = os_malloc(len);
5211 if (hexstr2bin(dst + used, buf, len) < 0) {
5216 ret = hs20_anqp_send_req(wpa_s, dst_addr,
5217 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
5225 static int hs20_icon_request(struct wpa_supplicant *wpa_s, char *cmd)
5227 u8 dst_addr[ETH_ALEN];
5231 used = hwaddr_aton2(cmd, dst_addr);
5235 while (cmd[used] == ' ')
5239 wpa_s->fetch_osu_icon_in_progress = 0;
5240 return hs20_anqp_send_req(wpa_s, dst_addr, BIT(HS20_STYPE_ICON_REQUEST),
5241 (u8 *) icon, os_strlen(icon));
5244 #endif /* CONFIG_HS20 */
5247 static int wpa_supplicant_ctrl_iface_sta_autoconnect(
5248 struct wpa_supplicant *wpa_s, char *cmd)
5250 wpa_s->auto_reconnect_disabled = atoi(cmd) == 0 ? 1 : 0;
5255 #ifdef CONFIG_AUTOSCAN
5257 static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant *wpa_s,
5260 enum wpa_states state = wpa_s->wpa_state;
5261 char *new_params = NULL;
5263 if (os_strlen(cmd) > 0) {
5264 new_params = os_strdup(cmd);
5265 if (new_params == NULL)
5269 os_free(wpa_s->conf->autoscan);
5270 wpa_s->conf->autoscan = new_params;
5272 if (wpa_s->conf->autoscan == NULL)
5273 autoscan_deinit(wpa_s);
5274 else if (state == WPA_DISCONNECTED || state == WPA_INACTIVE)
5275 autoscan_init(wpa_s, 1);
5276 else if (state == WPA_SCANNING)
5277 wpa_supplicant_reinit_autoscan(wpa_s);
5282 #endif /* CONFIG_AUTOSCAN */
5287 static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant *wpa_s, char *cmd)
5293 struct wpabuf *tfs_req = NULL;
5295 if (os_strncmp(cmd, "enter", 5) == 0)
5297 else if (os_strncmp(cmd, "exit", 4) == 0)
5302 pos = os_strstr(cmd, " interval=");
5304 intval = atoi(pos + 10);
5306 pos = os_strstr(cmd, " tfs_req=");
5311 end = os_strchr(pos, ' ');
5315 len = os_strlen(pos);
5319 tfs_req = wpabuf_alloc(len);
5320 if (tfs_req == NULL)
5322 if (hexstr2bin(pos, wpabuf_put(tfs_req, len), len) < 0) {
5323 wpabuf_free(tfs_req);
5328 ret = ieee802_11_send_wnmsleep_req(wpa_s, enter ? WNM_SLEEP_MODE_ENTER :
5329 WNM_SLEEP_MODE_EXIT, intval,
5331 wpabuf_free(tfs_req);
5337 static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant *wpa_s, char *cmd)
5341 query_reason = atoi(cmd);
5343 wpa_printf(MSG_DEBUG, "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d",
5346 return wnm_send_bss_transition_mgmt_query(wpa_s, query_reason);
5349 #endif /* CONFIG_WNM */
5352 /* Get string representation of channel width */
5353 static const char * channel_width_name(enum chan_width width)
5356 case CHAN_WIDTH_20_NOHT:
5357 return "20 MHz (no HT)";
5364 case CHAN_WIDTH_80P80:
5366 case CHAN_WIDTH_160:
5374 static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf,
5377 struct wpa_signal_info si;
5381 ret = wpa_drv_signal_poll(wpa_s, &si);
5388 ret = os_snprintf(pos, end - pos, "RSSI=%d\nLINKSPEED=%d\n"
5389 "NOISE=%d\nFREQUENCY=%u\n",
5390 si.current_signal, si.current_txrate / 1000,
5391 si.current_noise, si.frequency);
5392 if (ret < 0 || ret > end - pos)
5396 if (si.chanwidth != CHAN_WIDTH_UNKNOWN) {
5397 ret = os_snprintf(pos, end - pos, "WIDTH=%s\n",
5398 channel_width_name(si.chanwidth));
5399 if (ret < 0 || ret > end - pos)
5404 if (si.center_frq1 > 0 && si.center_frq2 > 0) {
5405 ret = os_snprintf(pos, end - pos,
5406 "CENTER_FRQ1=%d\nCENTER_FRQ2=%d\n",
5407 si.center_frq1, si.center_frq2);
5408 if (ret < 0 || ret > end - pos)
5413 if (si.avg_signal) {
5414 ret = os_snprintf(pos, end - pos,
5415 "AVG_RSSI=%d\n", si.avg_signal);
5416 if (ret < 0 || ret >= end - pos)
5425 static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant *wpa_s, char *buf,
5428 struct hostap_sta_driver_data sta;
5431 ret = wpa_drv_pktcnt_poll(wpa_s, &sta);
5435 ret = os_snprintf(buf, buflen, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
5436 sta.tx_packets, sta.tx_retry_failed, sta.rx_packets);
5437 if (ret < 0 || (size_t) ret > buflen)
5444 static int wpa_supplicant_driver_cmd(struct wpa_supplicant *wpa_s, char *cmd,
5445 char *buf, size_t buflen)
5449 ret = wpa_drv_driver_cmd(wpa_s, cmd, buf, buflen);
5451 if (os_strncasecmp(cmd, "COUNTRY", 7) == 0) {
5452 struct p2p_data *p2p = wpa_s->global->p2p;
5455 country[0] = cmd[8];
5456 country[1] = cmd[9];
5458 p2p_set_country(p2p, country);
5461 ret = os_snprintf(buf, buflen, "%s\n", "OK");
5465 #endif /* ANDROID */
5468 static int wpa_supplicant_vendor_cmd(struct wpa_supplicant *wpa_s, char *cmd,
5469 char *buf, size_t buflen)
5474 unsigned int vendor_id, subcmd;
5475 struct wpabuf *reply;
5476 size_t data_len = 0;
5478 /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */
5479 vendor_id = strtoul(cmd, &pos, 16);
5483 subcmd = strtoul(pos, &pos, 10);
5486 if (!isblank(*pos++))
5488 data_len = os_strlen(pos);
5493 data = os_malloc(data_len);
5497 if (hexstr2bin(pos, data, data_len)) {
5498 wpa_printf(MSG_DEBUG,
5499 "Vendor command: wrong parameter format");
5505 reply = wpabuf_alloc((buflen - 1) / 2);
5511 ret = wpa_drv_vendor_cmd(wpa_s, vendor_id, subcmd, data, data_len,
5515 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(reply),
5525 static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s)
5527 wpa_dbg(wpa_s, MSG_DEBUG, "Flush all wpa_supplicant state");
5530 wpas_p2p_stop_find(wpa_s);
5531 p2p_ctrl_flush(wpa_s);
5532 wpas_p2p_group_remove(wpa_s, "*");
5533 wpas_p2p_service_flush(wpa_s);
5534 wpa_s->global->p2p_disabled = 0;
5535 wpa_s->global->p2p_per_sta_psk = 0;
5536 wpa_s->conf->num_sec_device_types = 0;
5537 wpa_s->p2p_disable_ip_addr_req = 0;
5538 #endif /* CONFIG_P2P */
5540 #ifdef CONFIG_WPS_TESTING
5541 wps_version_number = 0x20;
5542 wps_testing_dummy_cred = 0;
5543 wps_corrupt_pkhash = 0;
5544 #endif /* CONFIG_WPS_TESTING */
5546 wpa_s->wps_fragment_size = 0;
5547 wpas_wps_cancel(wpa_s);
5548 #endif /* CONFIG_WPS */
5549 wpa_s->after_wps = 0;
5550 wpa_s->known_wps_freq = 0;
5553 #ifdef CONFIG_TDLS_TESTING
5554 extern unsigned int tdls_testing;
5556 #endif /* CONFIG_TDLS_TESTING */
5557 wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL);
5558 wpa_tdls_enable(wpa_s->wpa, 1);
5559 #endif /* CONFIG_TDLS */
5561 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, wpa_s, NULL);
5562 wpa_supplicant_stop_countermeasures(wpa_s, NULL);
5564 wpa_s->no_keep_alive = 0;
5566 os_free(wpa_s->disallow_aps_bssid);
5567 wpa_s->disallow_aps_bssid = NULL;
5568 wpa_s->disallow_aps_bssid_count = 0;
5569 os_free(wpa_s->disallow_aps_ssid);
5570 wpa_s->disallow_aps_ssid = NULL;
5571 wpa_s->disallow_aps_ssid_count = 0;
5573 wpa_s->set_sta_uapsd = 0;
5574 wpa_s->sta_uapsd = 0;
5576 wpa_drv_radio_disable(wpa_s, 0);
5578 wpa_bss_flush(wpa_s);
5579 wpa_blacklist_clear(wpa_s);
5580 wpa_s->extra_blacklist_count = 0;
5581 wpa_supplicant_ctrl_iface_remove_network(wpa_s, "all");
5582 wpa_supplicant_ctrl_iface_remove_cred(wpa_s, "all");
5583 wpa_config_flush_blobs(wpa_s->conf);
5584 wpa_s->conf->auto_interworking = 0;
5585 wpa_s->conf->okc = 0;
5587 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, 43200);
5588 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, 70);
5589 wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, 60);
5590 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
5592 radio_remove_works(wpa_s, NULL, 1);
5594 wpa_s->next_ssid = NULL;
5596 #ifdef CONFIG_INTERWORKING
5597 hs20_cancel_fetch_osu(wpa_s);
5598 #endif /* CONFIG_INTERWORKING */
5600 wpa_s->ext_mgmt_frame_handling = 0;
5604 static int wpas_ctrl_radio_work_show(struct wpa_supplicant *wpa_s,
5605 char *buf, size_t buflen)
5607 struct wpa_radio_work *work;
5609 struct os_reltime now, diff;
5614 os_get_reltime(&now);
5616 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
5620 os_reltime_sub(&now, &work->time, &diff);
5621 ret = os_snprintf(pos, end - pos, "%s@%s:%u:%u:%ld.%06ld\n",
5622 work->type, work->wpa_s->ifname, work->freq,
5623 work->started, diff.sec, diff.usec);
5624 if (ret < 0 || ret >= end - pos)
5633 static void wpas_ctrl_radio_work_timeout(void *eloop_ctx, void *timeout_ctx)
5635 struct wpa_radio_work *work = eloop_ctx;
5636 struct wpa_external_work *ework = work->ctx;
5638 wpa_dbg(work->wpa_s, MSG_DEBUG,
5639 "Timing out external radio work %u (%s)",
5640 ework->id, work->type);
5641 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_TIMEOUT "%u", ework->id);
5643 radio_work_done(work);
5647 static void wpas_ctrl_radio_work_cb(struct wpa_radio_work *work, int deinit)
5649 struct wpa_external_work *ework = work->ctx;
5653 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
5660 wpa_dbg(work->wpa_s, MSG_DEBUG, "Starting external radio work %u (%s)",
5661 ework->id, ework->type);
5662 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_START "%u", ework->id);
5663 if (!ework->timeout)
5664 ework->timeout = 10;
5665 eloop_register_timeout(ework->timeout, 0, wpas_ctrl_radio_work_timeout,
5670 static int wpas_ctrl_radio_work_add(struct wpa_supplicant *wpa_s, char *cmd,
5671 char *buf, size_t buflen)
5673 struct wpa_external_work *ework;
5677 unsigned int freq = 0;
5679 /* format: <name> [freq=<MHz>] [timeout=<seconds>] */
5681 ework = os_zalloc(sizeof(*ework));
5685 pos = os_strchr(cmd, ' ');
5687 type_len = pos - cmd;
5690 pos2 = os_strstr(pos, "freq=");
5692 freq = atoi(pos2 + 5);
5694 pos2 = os_strstr(pos, "timeout=");
5696 ework->timeout = atoi(pos2 + 8);
5698 type_len = os_strlen(cmd);
5700 if (4 + type_len >= sizeof(ework->type))
5701 type_len = sizeof(ework->type) - 4 - 1;
5702 os_strlcpy(ework->type, "ext:", sizeof(ework->type));
5703 os_memcpy(ework->type + 4, cmd, type_len);
5704 ework->type[4 + type_len] = '\0';
5706 wpa_s->ext_work_id++;
5707 if (wpa_s->ext_work_id == 0)
5708 wpa_s->ext_work_id++;
5709 ework->id = wpa_s->ext_work_id;
5711 if (radio_add_work(wpa_s, freq, ework->type, 0, wpas_ctrl_radio_work_cb,
5717 ret = os_snprintf(buf, buflen, "%u", ework->id);
5718 if (ret < 0 || (size_t) ret >= buflen)
5724 static int wpas_ctrl_radio_work_done(struct wpa_supplicant *wpa_s, char *cmd)
5726 struct wpa_radio_work *work;
5727 unsigned int id = atoi(cmd);
5729 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
5731 struct wpa_external_work *ework;
5733 if (os_strncmp(work->type, "ext:", 4) != 0)
5736 if (id && ework->id != id)
5738 wpa_dbg(wpa_s, MSG_DEBUG,
5739 "Completed external radio work %u (%s)",
5740 ework->id, ework->type);
5741 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, work, NULL);
5743 radio_work_done(work);
5744 return 3; /* "OK\n" */
5751 static int wpas_ctrl_radio_work(struct wpa_supplicant *wpa_s, char *cmd,
5752 char *buf, size_t buflen)
5754 if (os_strcmp(cmd, "show") == 0)
5755 return wpas_ctrl_radio_work_show(wpa_s, buf, buflen);
5756 if (os_strncmp(cmd, "add ", 4) == 0)
5757 return wpas_ctrl_radio_work_add(wpa_s, cmd + 4, buf, buflen);
5758 if (os_strncmp(cmd, "done ", 5) == 0)
5759 return wpas_ctrl_radio_work_done(wpa_s, cmd + 4);
5764 void wpas_ctrl_radio_work_flush(struct wpa_supplicant *wpa_s)
5766 struct wpa_radio_work *work, *tmp;
5768 if (!wpa_s || !wpa_s->radio)
5771 dl_list_for_each_safe(work, tmp, &wpa_s->radio->work,
5772 struct wpa_radio_work, list) {
5773 struct wpa_external_work *ework;
5775 if (os_strncmp(work->type, "ext:", 4) != 0)
5778 wpa_dbg(wpa_s, MSG_DEBUG,
5779 "Flushing %sexternal radio work %u (%s)",
5780 work->started ? " started" : "", ework->id,
5783 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
5786 radio_work_done(work);
5791 static void wpas_ctrl_eapol_response(void *eloop_ctx, void *timeout_ctx)
5793 struct wpa_supplicant *wpa_s = eloop_ctx;
5794 eapol_sm_notify_ctrl_response(wpa_s->eapol);
5798 static int set_scan_freqs(struct wpa_supplicant *wpa_s, char *val)
5802 freqs = freq_range_to_channel_list(wpa_s, val);
5806 os_free(wpa_s->manual_scan_freqs);
5807 wpa_s->manual_scan_freqs = freqs;
5813 static void wpas_ctrl_scan(struct wpa_supplicant *wpa_s, char *params,
5814 char *reply, int reply_size, int *reply_len)
5818 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
5823 wpa_s->manual_scan_passive = 0;
5824 wpa_s->manual_scan_use_id = 0;
5825 wpa_s->manual_scan_only_new = 0;
5828 if (os_strncasecmp(params, "TYPE=ONLY", 9) == 0)
5829 wpa_s->scan_res_handler = scan_only_handler;
5831 pos = os_strstr(params, "freq=");
5832 if (pos && set_scan_freqs(wpa_s, pos + 5) < 0) {
5837 pos = os_strstr(params, "passive=");
5839 wpa_s->manual_scan_passive = !!atoi(pos + 8);
5841 pos = os_strstr(params, "use_id=");
5843 wpa_s->manual_scan_use_id = atoi(pos + 7);
5845 pos = os_strstr(params, "only_new=1");
5847 wpa_s->manual_scan_only_new = 1;
5849 os_free(wpa_s->manual_scan_freqs);
5850 wpa_s->manual_scan_freqs = NULL;
5851 if (wpa_s->scan_res_handler == scan_only_handler)
5852 wpa_s->scan_res_handler = NULL;
5855 if (!wpa_s->sched_scanning && !wpa_s->scanning &&
5856 ((wpa_s->wpa_state <= WPA_SCANNING) ||
5857 (wpa_s->wpa_state == WPA_COMPLETED))) {
5858 wpa_s->normal_scans = 0;
5859 wpa_s->scan_req = MANUAL_SCAN_REQ;
5860 wpa_s->after_wps = 0;
5861 wpa_s->known_wps_freq = 0;
5862 wpa_supplicant_req_scan(wpa_s, 0, 0);
5863 if (wpa_s->manual_scan_use_id) {
5864 wpa_s->manual_scan_id++;
5865 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
5866 wpa_s->manual_scan_id);
5867 *reply_len = os_snprintf(reply, reply_size, "%u\n",
5868 wpa_s->manual_scan_id);
5870 } else if (wpa_s->sched_scanning) {
5871 wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to allow requested full scan to proceed");
5872 wpa_supplicant_cancel_sched_scan(wpa_s);
5873 wpa_s->scan_req = MANUAL_SCAN_REQ;
5874 wpa_supplicant_req_scan(wpa_s, 0, 0);
5875 if (wpa_s->manual_scan_use_id) {
5876 wpa_s->manual_scan_id++;
5877 *reply_len = os_snprintf(reply, reply_size, "%u\n",
5878 wpa_s->manual_scan_id);
5879 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
5880 wpa_s->manual_scan_id);
5883 wpa_printf(MSG_DEBUG, "Ongoing scan action - reject new request");
5884 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
5889 #ifdef CONFIG_TESTING_OPTIONS
5891 static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant *wpa_s,
5892 unsigned int freq, const u8 *dst,
5893 const u8 *src, const u8 *bssid,
5894 const u8 *data, size_t data_len,
5895 enum offchannel_send_action_result
5898 wpa_msg(wpa_s, MSG_INFO, "MGMT-TX-STATUS freq=%u dst=" MACSTR
5899 " src=" MACSTR " bssid=" MACSTR " result=%s",
5900 freq, MAC2STR(dst), MAC2STR(src), MAC2STR(bssid),
5901 result == OFFCHANNEL_SEND_ACTION_SUCCESS ?
5902 "SUCCESS" : (result == OFFCHANNEL_SEND_ACTION_NO_ACK ?
5903 "NO_ACK" : "FAILED"));
5907 static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant *wpa_s, char *cmd)
5911 u8 *buf, da[ETH_ALEN], bssid[ETH_ALEN];
5913 int freq = 0, no_cck = 0, wait_time = 0;
5915 /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1]
5916 * <action=Action frame payload> */
5918 wpa_printf(MSG_DEBUG, "External MGMT TX: %s", cmd);
5921 used = hwaddr_aton2(pos, da);
5927 used = hwaddr_aton2(pos, bssid);
5932 param = os_strstr(pos, " freq=");
5938 param = os_strstr(pos, " no_cck=");
5941 no_cck = atoi(param);
5944 param = os_strstr(pos, " wait_time=");
5947 wait_time = atoi(param);
5950 param = os_strstr(pos, " action=");
5955 len = os_strlen(param);
5960 buf = os_malloc(len);
5964 if (hexstr2bin(param, buf, len) < 0) {
5969 res = offchannel_send_action(wpa_s, freq, da, wpa_s->own_addr, bssid,
5970 buf, len, wait_time,
5971 wpas_ctrl_iface_mgmt_tx_cb, no_cck);
5977 static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant *wpa_s)
5979 wpa_printf(MSG_DEBUG, "External MGMT TX - done waiting");
5980 offchannel_send_action_done(wpa_s);
5983 #endif /* CONFIG_TESTING_OPTIONS */
5986 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
5987 char *buf, size_t *resp_len)
5990 const int reply_size = 4096;
5993 if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 ||
5994 os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
5995 if (wpa_debug_show_keys)
5996 wpa_dbg(wpa_s, MSG_DEBUG,
5997 "Control interface command '%s'", buf);
5999 wpa_dbg(wpa_s, MSG_DEBUG,
6000 "Control interface command '%s [REMOVED]'",
6001 os_strncmp(buf, WPA_CTRL_RSP,
6002 os_strlen(WPA_CTRL_RSP)) == 0 ?
6003 WPA_CTRL_RSP : "SET_NETWORK");
6004 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ", 16) == 0 ||
6005 os_strncmp(buf, "NFC_REPORT_HANDOVER", 19) == 0 ||
6006 os_strncmp(buf, "NFC_RX_HANDOVER_SEL", 19) == 0) {
6007 wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface",
6008 (const u8 *) buf, os_strlen(buf));
6010 int level = MSG_DEBUG;
6011 if (os_strcmp(buf, "PING") == 0)
6012 level = MSG_EXCESSIVE;
6013 wpa_dbg(wpa_s, level, "Control interface command '%s'", buf);
6016 reply = os_malloc(reply_size);
6017 if (reply == NULL) {
6022 os_memcpy(reply, "OK\n", 3);
6025 if (os_strcmp(buf, "PING") == 0) {
6026 os_memcpy(reply, "PONG\n", 5);
6028 } else if (os_strcmp(buf, "IFNAME") == 0) {
6029 reply_len = os_strlen(wpa_s->ifname);
6030 os_memcpy(reply, wpa_s->ifname, reply_len);
6031 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
6032 if (wpa_debug_reopen_file() < 0)
6034 } else if (os_strncmp(buf, "NOTE ", 5) == 0) {
6035 wpa_printf(MSG_INFO, "NOTE: %s", buf + 5);
6036 } else if (os_strcmp(buf, "MIB") == 0) {
6037 reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size);
6038 if (reply_len >= 0) {
6040 res = eapol_sm_get_mib(wpa_s->eapol, reply + reply_len,
6041 reply_size - reply_len);
6047 } else if (os_strncmp(buf, "STATUS", 6) == 0) {
6048 reply_len = wpa_supplicant_ctrl_iface_status(
6049 wpa_s, buf + 6, reply, reply_size);
6050 } else if (os_strcmp(buf, "PMKSA") == 0) {
6051 reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, reply,
6053 } else if (os_strncmp(buf, "SET ", 4) == 0) {
6054 if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4))
6056 } else if (os_strncmp(buf, "GET ", 4) == 0) {
6057 reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4,
6059 } else if (os_strcmp(buf, "LOGON") == 0) {
6060 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
6061 } else if (os_strcmp(buf, "LOGOFF") == 0) {
6062 eapol_sm_notify_logoff(wpa_s->eapol, TRUE);
6063 } else if (os_strcmp(buf, "REASSOCIATE") == 0) {
6064 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
6067 wpas_request_connection(wpa_s);
6068 } else if (os_strcmp(buf, "RECONNECT") == 0) {
6069 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
6071 else if (wpa_s->disconnected)
6072 wpas_request_connection(wpa_s);
6073 #ifdef IEEE8021X_EAPOL
6074 } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) {
6075 if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8))
6077 #endif /* IEEE8021X_EAPOL */
6078 #ifdef CONFIG_PEERKEY
6079 } else if (os_strncmp(buf, "STKSTART ", 9) == 0) {
6080 if (wpa_supplicant_ctrl_iface_stkstart(wpa_s, buf + 9))
6082 #endif /* CONFIG_PEERKEY */
6083 #ifdef CONFIG_IEEE80211R
6084 } else if (os_strncmp(buf, "FT_DS ", 6) == 0) {
6085 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6))
6087 #endif /* CONFIG_IEEE80211R */
6089 } else if (os_strcmp(buf, "WPS_PBC") == 0) {
6090 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL);
6092 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
6096 } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) {
6097 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8);
6099 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
6103 } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {
6104 reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8,
6107 } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) {
6108 reply_len = wpa_supplicant_ctrl_iface_wps_check_pin(
6109 wpa_s, buf + 14, reply, reply_size);
6110 } else if (os_strcmp(buf, "WPS_CANCEL") == 0) {
6111 if (wpas_wps_cancel(wpa_s))
6113 #ifdef CONFIG_WPS_NFC
6114 } else if (os_strcmp(buf, "WPS_NFC") == 0) {
6115 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, NULL))
6117 } else if (os_strncmp(buf, "WPS_NFC ", 8) == 0) {
6118 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, buf + 8))
6120 } else if (os_strncmp(buf, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
6121 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_config_token(
6122 wpa_s, buf + 21, reply, reply_size);
6123 } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) {
6124 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_token(
6125 wpa_s, buf + 14, reply, reply_size);
6126 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) {
6127 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s,
6130 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
6131 reply_len = wpas_ctrl_nfc_get_handover_req(
6132 wpa_s, buf + 21, reply, reply_size);
6133 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
6134 reply_len = wpas_ctrl_nfc_get_handover_sel(
6135 wpa_s, buf + 21, reply, reply_size);
6136 } else if (os_strncmp(buf, "NFC_RX_HANDOVER_SEL ", 20) == 0) {
6137 if (wpas_ctrl_nfc_rx_handover_sel(wpa_s, buf + 20))
6139 } else if (os_strncmp(buf, "NFC_REPORT_HANDOVER ", 20) == 0) {
6140 if (wpas_ctrl_nfc_report_handover(wpa_s, buf + 20))
6142 #endif /* CONFIG_WPS_NFC */
6143 } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) {
6144 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8))
6147 } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) {
6148 reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin(
6149 wpa_s, buf + 11, reply, reply_size);
6150 #endif /* CONFIG_AP */
6151 #ifdef CONFIG_WPS_ER
6152 } else if (os_strcmp(buf, "WPS_ER_START") == 0) {
6153 if (wpas_wps_er_start(wpa_s, NULL))
6155 } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) {
6156 if (wpas_wps_er_start(wpa_s, buf + 13))
6158 } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) {
6159 if (wpas_wps_er_stop(wpa_s))
6161 } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) {
6162 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11))
6164 } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) {
6165 int ret = wpas_wps_er_pbc(wpa_s, buf + 11);
6167 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
6169 } else if (ret == -3) {
6170 os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18);
6172 } else if (ret == -4) {
6173 os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20);
6177 } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) {
6178 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13))
6180 } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) {
6181 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s,
6184 } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) {
6185 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14))
6187 #ifdef CONFIG_WPS_NFC
6188 } else if (os_strncmp(buf, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
6189 reply_len = wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
6190 wpa_s, buf + 24, reply, reply_size);
6191 #endif /* CONFIG_WPS_NFC */
6192 #endif /* CONFIG_WPS_ER */
6193 #endif /* CONFIG_WPS */
6194 #ifdef CONFIG_IBSS_RSN
6195 } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) {
6196 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9))
6198 #endif /* CONFIG_IBSS_RSN */
6200 } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) {
6201 if (p2p_ctrl_find(wpa_s, buf + 9))
6203 } else if (os_strcmp(buf, "P2P_FIND") == 0) {
6204 if (p2p_ctrl_find(wpa_s, ""))
6206 } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) {
6207 wpas_p2p_stop_find(wpa_s);
6208 } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) {
6209 reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply,
6211 } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) {
6212 if (p2p_ctrl_listen(wpa_s, buf + 11))
6214 } else if (os_strcmp(buf, "P2P_LISTEN") == 0) {
6215 if (p2p_ctrl_listen(wpa_s, ""))
6217 } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) {
6218 if (wpas_p2p_group_remove(wpa_s, buf + 17))
6220 } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) {
6221 if (wpas_p2p_group_add(wpa_s, 0, 0, 0, 0))
6223 } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) {
6224 if (p2p_ctrl_group_add(wpa_s, buf + 14))
6226 } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) {
6227 if (p2p_ctrl_prov_disc(wpa_s, buf + 14))
6229 } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) {
6230 reply_len = p2p_get_passphrase(wpa_s, reply, reply_size);
6231 } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) {
6232 reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply,
6234 } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
6235 if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0)
6237 } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) {
6238 if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0)
6240 } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) {
6241 wpas_p2p_sd_service_update(wpa_s);
6242 } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
6243 if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0)
6245 } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) {
6246 wpas_p2p_service_flush(wpa_s);
6247 } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) {
6248 if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0)
6250 } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) {
6251 if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0)
6253 } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) {
6254 if (p2p_ctrl_reject(wpa_s, buf + 11) < 0)
6256 } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) {
6257 if (p2p_ctrl_invite(wpa_s, buf + 11) < 0)
6259 } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) {
6260 reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply,
6262 } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) {
6263 if (p2p_ctrl_set(wpa_s, buf + 8) < 0)
6265 } else if (os_strcmp(buf, "P2P_FLUSH") == 0) {
6266 p2p_ctrl_flush(wpa_s);
6267 } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) {
6268 if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0)
6270 } else if (os_strcmp(buf, "P2P_CANCEL") == 0) {
6271 if (wpas_p2p_cancel(wpa_s))
6273 } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) {
6274 if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0)
6276 } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) {
6277 if (p2p_ctrl_presence_req(wpa_s, "") < 0)
6279 } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) {
6280 if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0)
6282 } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) {
6283 if (p2p_ctrl_ext_listen(wpa_s, "") < 0)
6285 } else if (os_strncmp(buf, "P2P_REMOVE_CLIENT ", 18) == 0) {
6286 if (p2p_ctrl_remove_client(wpa_s, buf + 18) < 0)
6288 #endif /* CONFIG_P2P */
6289 #ifdef CONFIG_WIFI_DISPLAY
6290 } else if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0) {
6291 if (wifi_display_subelem_set(wpa_s->global, buf + 16) < 0)
6293 } else if (os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) {
6294 reply_len = wifi_display_subelem_get(wpa_s->global, buf + 16,
6296 #endif /* CONFIG_WIFI_DISPLAY */
6297 #ifdef CONFIG_INTERWORKING
6298 } else if (os_strcmp(buf, "FETCH_ANQP") == 0) {
6299 if (interworking_fetch_anqp(wpa_s) < 0)
6301 } else if (os_strcmp(buf, "STOP_FETCH_ANQP") == 0) {
6302 interworking_stop_fetch_anqp(wpa_s);
6303 } else if (os_strcmp(buf, "INTERWORKING_SELECT") == 0) {
6304 if (ctrl_interworking_select(wpa_s, NULL) < 0)
6306 } else if (os_strncmp(buf, "INTERWORKING_SELECT ", 20) == 0) {
6307 if (ctrl_interworking_select(wpa_s, buf + 20) < 0)
6309 } else if (os_strncmp(buf, "INTERWORKING_CONNECT ", 21) == 0) {
6310 if (ctrl_interworking_connect(wpa_s, buf + 21) < 0)
6312 } else if (os_strncmp(buf, "ANQP_GET ", 9) == 0) {
6313 if (get_anqp(wpa_s, buf + 9) < 0)
6315 } else if (os_strncmp(buf, "GAS_REQUEST ", 12) == 0) {
6316 if (gas_request(wpa_s, buf + 12) < 0)
6318 } else if (os_strncmp(buf, "GAS_RESPONSE_GET ", 17) == 0) {
6319 reply_len = gas_response_get(wpa_s, buf + 17, reply,
6321 #endif /* CONFIG_INTERWORKING */
6323 } else if (os_strncmp(buf, "HS20_ANQP_GET ", 14) == 0) {
6324 if (get_hs20_anqp(wpa_s, buf + 14) < 0)
6326 } else if (os_strncmp(buf, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
6327 if (hs20_get_nai_home_realm_list(wpa_s, buf + 29) < 0)
6329 } else if (os_strncmp(buf, "HS20_ICON_REQUEST ", 18) == 0) {
6330 if (hs20_icon_request(wpa_s, buf + 18) < 0)
6332 } else if (os_strcmp(buf, "FETCH_OSU") == 0) {
6333 if (hs20_fetch_osu(wpa_s) < 0)
6335 } else if (os_strcmp(buf, "CANCEL_FETCH_OSU") == 0) {
6336 hs20_cancel_fetch_osu(wpa_s);
6337 #endif /* CONFIG_HS20 */
6338 } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0)
6340 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
6341 wpa_s, buf + os_strlen(WPA_CTRL_RSP)))
6345 * Notify response from timeout to allow the control
6346 * interface response to be sent first.
6348 eloop_register_timeout(0, 0, wpas_ctrl_eapol_response,
6351 } else if (os_strcmp(buf, "RECONFIGURE") == 0) {
6352 if (wpa_supplicant_reload_configuration(wpa_s))
6354 } else if (os_strcmp(buf, "TERMINATE") == 0) {
6355 wpa_supplicant_terminate_proc(wpa_s->global);
6356 } else if (os_strncmp(buf, "BSSID ", 6) == 0) {
6357 if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6))
6359 } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) {
6360 reply_len = wpa_supplicant_ctrl_iface_blacklist(
6361 wpa_s, buf + 9, reply, reply_size);
6362 } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) {
6363 reply_len = wpa_supplicant_ctrl_iface_log_level(
6364 wpa_s, buf + 9, reply, reply_size);
6365 } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) {
6366 reply_len = wpa_supplicant_ctrl_iface_list_networks(
6367 wpa_s, reply, reply_size);
6368 } else if (os_strcmp(buf, "DISCONNECT") == 0) {
6370 wpa_s->sme.prev_bssid_set = 0;
6371 #endif /* CONFIG_SME */
6372 wpa_s->reassociate = 0;
6373 wpa_s->disconnected = 1;
6374 wpa_supplicant_cancel_sched_scan(wpa_s);
6375 wpa_supplicant_cancel_scan(wpa_s);
6376 wpa_supplicant_deauthenticate(wpa_s,
6377 WLAN_REASON_DEAUTH_LEAVING);
6378 } else if (os_strcmp(buf, "SCAN") == 0) {
6379 wpas_ctrl_scan(wpa_s, NULL, reply, reply_size, &reply_len);
6380 } else if (os_strncmp(buf, "SCAN ", 5) == 0) {
6381 wpas_ctrl_scan(wpa_s, buf + 5, reply, reply_size, &reply_len);
6382 } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) {
6383 reply_len = wpa_supplicant_ctrl_iface_scan_results(
6384 wpa_s, reply, reply_size);
6385 } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) {
6386 if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15))
6388 } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) {
6389 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15))
6391 } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) {
6392 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16))
6394 } else if (os_strcmp(buf, "ADD_NETWORK") == 0) {
6395 reply_len = wpa_supplicant_ctrl_iface_add_network(
6396 wpa_s, reply, reply_size);
6397 } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) {
6398 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15))
6400 } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
6401 if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12))
6403 } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) {
6404 reply_len = wpa_supplicant_ctrl_iface_get_network(
6405 wpa_s, buf + 12, reply, reply_size);
6406 } else if (os_strcmp(buf, "LIST_CREDS") == 0) {
6407 reply_len = wpa_supplicant_ctrl_iface_list_creds(
6408 wpa_s, reply, reply_size);
6409 } else if (os_strcmp(buf, "ADD_CRED") == 0) {
6410 reply_len = wpa_supplicant_ctrl_iface_add_cred(
6411 wpa_s, reply, reply_size);
6412 } else if (os_strncmp(buf, "REMOVE_CRED ", 12) == 0) {
6413 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s, buf + 12))
6415 } else if (os_strncmp(buf, "SET_CRED ", 9) == 0) {
6416 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s, buf + 9))
6418 #ifndef CONFIG_NO_CONFIG_WRITE
6419 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
6420 if (wpa_supplicant_ctrl_iface_save_config(wpa_s))
6422 #endif /* CONFIG_NO_CONFIG_WRITE */
6423 } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
6424 reply_len = wpa_supplicant_ctrl_iface_get_capability(
6425 wpa_s, buf + 15, reply, reply_size);
6426 } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) {
6427 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8))
6429 } else if (os_strncmp(buf, "SCAN_INTERVAL ", 14) == 0) {
6430 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s, buf + 14))
6432 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
6433 reply_len = wpa_supplicant_global_iface_list(
6434 wpa_s->global, reply, reply_size);
6435 } else if (os_strcmp(buf, "INTERFACES") == 0) {
6436 reply_len = wpa_supplicant_global_iface_interfaces(
6437 wpa_s->global, reply, reply_size);
6438 } else if (os_strncmp(buf, "BSS ", 4) == 0) {
6439 reply_len = wpa_supplicant_ctrl_iface_bss(
6440 wpa_s, buf + 4, reply, reply_size);
6442 } else if (os_strcmp(buf, "STA-FIRST") == 0) {
6443 reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size);
6444 } else if (os_strncmp(buf, "STA ", 4) == 0) {
6445 reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply,
6447 } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) {
6448 reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply,
6450 } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) {
6451 if (ap_ctrl_iface_sta_deauthenticate(wpa_s, buf + 15))
6453 } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) {
6454 if (ap_ctrl_iface_sta_disassociate(wpa_s, buf + 13))
6456 } else if (os_strncmp(buf, "CHAN_SWITCH ", 12) == 0) {
6457 if (ap_ctrl_iface_chanswitch(wpa_s, buf + 12))
6459 #endif /* CONFIG_AP */
6460 } else if (os_strcmp(buf, "SUSPEND") == 0) {
6461 wpas_notify_suspend(wpa_s->global);
6462 } else if (os_strcmp(buf, "RESUME") == 0) {
6463 wpas_notify_resume(wpa_s->global);
6464 } else if (os_strcmp(buf, "DROP_SA") == 0) {
6465 wpa_supplicant_ctrl_iface_drop_sa(wpa_s);
6466 } else if (os_strncmp(buf, "ROAM ", 5) == 0) {
6467 if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5))
6469 } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) {
6470 if (wpa_supplicant_ctrl_iface_sta_autoconnect(wpa_s, buf + 16))
6472 } else if (os_strncmp(buf, "BSS_EXPIRE_AGE ", 15) == 0) {
6473 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s, buf + 15))
6475 } else if (os_strncmp(buf, "BSS_EXPIRE_COUNT ", 17) == 0) {
6476 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s,
6479 } else if (os_strncmp(buf, "BSS_FLUSH ", 10) == 0) {
6480 if (wpa_supplicant_ctrl_iface_bss_flush(wpa_s, buf + 10))
6483 } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) {
6484 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14))
6486 } else if (os_strncmp(buf, "TDLS_SETUP ", 11) == 0) {
6487 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s, buf + 11))
6489 } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) {
6490 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14))
6492 #endif /* CONFIG_TDLS */
6493 } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) {
6494 reply_len = wpa_supplicant_signal_poll(wpa_s, reply,
6496 } else if (os_strncmp(buf, "PKTCNT_POLL", 11) == 0) {
6497 reply_len = wpa_supplicant_pktcnt_poll(wpa_s, reply,
6499 #ifdef CONFIG_AUTOSCAN
6500 } else if (os_strncmp(buf, "AUTOSCAN ", 9) == 0) {
6501 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s, buf + 9))
6503 #endif /* CONFIG_AUTOSCAN */
6505 } else if (os_strncmp(buf, "DRIVER ", 7) == 0) {
6506 reply_len = wpa_supplicant_driver_cmd(wpa_s, buf + 7, reply,
6508 #endif /* ANDROID */
6509 } else if (os_strncmp(buf, "VENDOR ", 7) == 0) {
6510 reply_len = wpa_supplicant_vendor_cmd(wpa_s, buf + 7, reply,
6512 } else if (os_strcmp(buf, "REAUTHENTICATE") == 0) {
6513 pmksa_cache_clear_current(wpa_s->wpa);
6514 eapol_sm_request_reauth(wpa_s->eapol);
6516 } else if (os_strncmp(buf, "WNM_SLEEP ", 10) == 0) {
6517 if (wpas_ctrl_iface_wnm_sleep(wpa_s, buf + 10))
6519 } else if (os_strncmp(buf, "WNM_BSS_QUERY ", 10) == 0) {
6520 if (wpas_ctrl_iface_wnm_bss_query(wpa_s, buf + 10))
6522 #endif /* CONFIG_WNM */
6523 } else if (os_strcmp(buf, "FLUSH") == 0) {
6524 wpa_supplicant_ctrl_iface_flush(wpa_s);
6525 } else if (os_strncmp(buf, "RADIO_WORK ", 11) == 0) {
6526 reply_len = wpas_ctrl_radio_work(wpa_s, buf + 11, reply,
6528 #ifdef CONFIG_TESTING_OPTIONS
6529 } else if (os_strncmp(buf, "MGMT_TX ", 8) == 0) {
6530 if (wpas_ctrl_iface_mgmt_tx(wpa_s, buf + 8) < 0)
6532 } else if (os_strcmp(buf, "MGMT_TX_DONE") == 0) {
6533 wpas_ctrl_iface_mgmt_tx_done(wpa_s);
6534 #endif /* CONFIG_TESTING_OPTIONS */
6536 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
6540 if (reply_len < 0) {
6541 os_memcpy(reply, "FAIL\n", 5);
6545 *resp_len = reply_len;
6550 static int wpa_supplicant_global_iface_add(struct wpa_global *global,
6553 struct wpa_interface iface;
6557 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
6558 * TAB<bridge_ifname>
6560 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd);
6562 os_memset(&iface, 0, sizeof(iface));
6565 iface.ifname = pos = cmd;
6566 pos = os_strchr(pos, '\t');
6569 if (iface.ifname[0] == '\0')
6574 iface.confname = pos;
6575 pos = os_strchr(pos, '\t');
6578 if (iface.confname[0] == '\0')
6579 iface.confname = NULL;
6584 pos = os_strchr(pos, '\t');
6587 if (iface.driver[0] == '\0')
6588 iface.driver = NULL;
6592 iface.ctrl_interface = pos;
6593 pos = os_strchr(pos, '\t');
6596 if (iface.ctrl_interface[0] == '\0')
6597 iface.ctrl_interface = NULL;
6601 iface.driver_param = pos;
6602 pos = os_strchr(pos, '\t');
6605 if (iface.driver_param[0] == '\0')
6606 iface.driver_param = NULL;
6610 iface.bridge_ifname = pos;
6611 pos = os_strchr(pos, '\t');
6614 if (iface.bridge_ifname[0] == '\0')
6615 iface.bridge_ifname = NULL;
6620 if (wpa_supplicant_get_iface(global, iface.ifname))
6623 return wpa_supplicant_add_iface(global, &iface) ? 0 : -1;
6627 static int wpa_supplicant_global_iface_remove(struct wpa_global *global,
6630 struct wpa_supplicant *wpa_s;
6632 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd);
6634 wpa_s = wpa_supplicant_get_iface(global, cmd);
6637 return wpa_supplicant_remove_iface(global, wpa_s, 0);
6641 static void wpa_free_iface_info(struct wpa_interface_info *iface)
6643 struct wpa_interface_info *prev;
6647 iface = iface->next;
6649 os_free(prev->ifname);
6650 os_free(prev->desc);
6656 static int wpa_supplicant_global_iface_list(struct wpa_global *global,
6660 struct wpa_interface_info *iface = NULL, *last = NULL, *tmp;
6663 for (i = 0; wpa_drivers[i]; i++) {
6664 struct wpa_driver_ops *drv = wpa_drivers[i];
6665 if (drv->get_interfaces == NULL)
6667 tmp = drv->get_interfaces(global->drv_priv[i]);
6681 for (tmp = iface; tmp; tmp = tmp->next) {
6682 res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n",
6683 tmp->drv_name, tmp->ifname,
6684 tmp->desc ? tmp->desc : "");
6685 if (res < 0 || res >= end - pos) {
6692 wpa_free_iface_info(iface);
6698 static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
6703 struct wpa_supplicant *wpa_s;
6705 wpa_s = global->ifaces;
6710 res = os_snprintf(pos, end - pos, "%s\n", wpa_s->ifname);
6711 if (res < 0 || res >= end - pos) {
6716 wpa_s = wpa_s->next;
6722 static char * wpas_global_ctrl_iface_ifname(struct wpa_global *global,
6724 char *cmd, size_t *resp_len)
6726 struct wpa_supplicant *wpa_s;
6728 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
6729 if (os_strcmp(ifname, wpa_s->ifname) == 0)
6733 if (wpa_s == NULL) {
6734 char *resp = os_strdup("FAIL-NO-IFNAME-MATCH\n");
6736 *resp_len = os_strlen(resp);
6742 return wpa_supplicant_ctrl_iface_process(wpa_s, cmd, resp_len);
6746 static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global *global,
6747 char *buf, size_t *resp_len)
6750 static const char * cmd[] = {
6757 "P2P_GET_PASSPHRASE",
6758 "P2P_SERVICE_UPDATE",
6759 "P2P_SERVICE_FLUSH",
6766 static const char * prefix[] = {
6769 #endif /* ANDROID */
6776 "P2P_GROUP_REMOVE ",
6779 "P2P_SERV_DISC_REQ ",
6780 "P2P_SERV_DISC_CANCEL_REQ ",
6781 "P2P_SERV_DISC_RESP ",
6782 "P2P_SERV_DISC_EXTERNAL ",
6790 "P2P_PRESENCE_REQ ",
6792 "P2P_REMOVE_CLIENT ",
6798 if (global->p2p_init_wpa_s == NULL)
6801 for (i = 0; !found && cmd[i]; i++) {
6802 if (os_strcmp(buf, cmd[i]) == 0)
6806 for (i = 0; !found && prefix[i]; i++) {
6807 if (os_strncmp(buf, prefix[i], os_strlen(prefix[i])) == 0)
6812 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
6814 #endif /* CONFIG_P2P */
6819 static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global *global,
6820 char *buf, size_t *resp_len)
6822 #ifdef CONFIG_WIFI_DISPLAY
6823 if (global->p2p_init_wpa_s == NULL)
6825 if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0 ||
6826 os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0)
6827 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
6829 #endif /* CONFIG_WIFI_DISPLAY */
6834 static char * wpas_global_ctrl_iface_redir(struct wpa_global *global,
6835 char *buf, size_t *resp_len)
6839 ret = wpas_global_ctrl_iface_redir_p2p(global, buf, resp_len);
6843 ret = wpas_global_ctrl_iface_redir_wfd(global, buf, resp_len);
6851 static int wpas_global_ctrl_iface_set(struct wpa_global *global, char *cmd)
6855 value = os_strchr(cmd, ' ');
6860 wpa_printf(MSG_DEBUG, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd, value);
6862 #ifdef CONFIG_WIFI_DISPLAY
6863 if (os_strcasecmp(cmd, "wifi_display") == 0) {
6864 wifi_display_enable(global, !!atoi(value));
6867 #endif /* CONFIG_WIFI_DISPLAY */
6873 #ifndef CONFIG_NO_CONFIG_WRITE
6874 static int wpas_global_ctrl_iface_save_config(struct wpa_global *global)
6877 struct wpa_supplicant *wpa_s;
6879 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
6880 if (!wpa_s->conf->update_config) {
6881 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
6885 if (wpa_config_write(wpa_s->confname, wpa_s->conf)) {
6886 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
6889 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
6895 #endif /* CONFIG_NO_CONFIG_WRITE */
6898 static int wpas_global_ctrl_iface_status(struct wpa_global *global,
6899 char *buf, size_t buflen)
6903 struct wpa_supplicant *wpa_s;
6909 if (global->p2p && !global->p2p_disabled) {
6910 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
6913 MAC2STR(global->p2p_dev_addr),
6914 p2p_get_state_txt(global->p2p));
6915 if (ret < 0 || ret >= end - pos)
6918 } else if (global->p2p) {
6919 ret = os_snprintf(pos, end - pos, "p2p_state=DISABLED\n");
6920 if (ret < 0 || ret >= end - pos)
6924 #endif /* CONFIG_P2P */
6926 #ifdef CONFIG_WIFI_DISPLAY
6927 ret = os_snprintf(pos, end - pos, "wifi_display=%d\n",
6928 !!global->wifi_display);
6929 if (ret < 0 || ret >= end - pos)
6932 #endif /* CONFIG_WIFI_DISPLAY */
6934 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
6935 ret = os_snprintf(pos, end - pos, "ifname=%s\n"
6936 "address=" MACSTR "\n",
6937 wpa_s->ifname, MAC2STR(wpa_s->own_addr));
6938 if (ret < 0 || ret >= end - pos)
6947 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
6948 char *buf, size_t *resp_len)
6951 const int reply_size = 2048;
6953 int level = MSG_DEBUG;
6955 if (os_strncmp(buf, "IFNAME=", 7) == 0) {
6956 char *pos = os_strchr(buf + 7, ' ');
6959 return wpas_global_ctrl_iface_ifname(global,
6965 reply = wpas_global_ctrl_iface_redir(global, buf, resp_len);
6969 if (os_strcmp(buf, "PING") == 0)
6970 level = MSG_EXCESSIVE;
6971 wpa_hexdump_ascii(level, "RX global ctrl_iface",
6972 (const u8 *) buf, os_strlen(buf));
6974 reply = os_malloc(reply_size);
6975 if (reply == NULL) {
6980 os_memcpy(reply, "OK\n", 3);
6983 if (os_strcmp(buf, "PING") == 0) {
6984 os_memcpy(reply, "PONG\n", 5);
6986 } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) {
6987 if (wpa_supplicant_global_iface_add(global, buf + 14))
6989 } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) {
6990 if (wpa_supplicant_global_iface_remove(global, buf + 17))
6992 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
6993 reply_len = wpa_supplicant_global_iface_list(
6994 global, reply, reply_size);
6995 } else if (os_strcmp(buf, "INTERFACES") == 0) {
6996 reply_len = wpa_supplicant_global_iface_interfaces(
6997 global, reply, reply_size);
6998 } else if (os_strcmp(buf, "TERMINATE") == 0) {
6999 wpa_supplicant_terminate_proc(global);
7000 } else if (os_strcmp(buf, "SUSPEND") == 0) {
7001 wpas_notify_suspend(global);
7002 } else if (os_strcmp(buf, "RESUME") == 0) {
7003 wpas_notify_resume(global);
7004 } else if (os_strncmp(buf, "SET ", 4) == 0) {
7005 if (wpas_global_ctrl_iface_set(global, buf + 4))
7007 #ifndef CONFIG_NO_CONFIG_WRITE
7008 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
7009 if (wpas_global_ctrl_iface_save_config(global))
7011 #endif /* CONFIG_NO_CONFIG_WRITE */
7012 } else if (os_strcmp(buf, "STATUS") == 0) {
7013 reply_len = wpas_global_ctrl_iface_status(global, reply,
7015 #ifdef CONFIG_MODULE_TESTS
7016 } else if (os_strcmp(buf, "MODULE_TESTS") == 0) {
7017 int wpas_module_tests(void);
7018 if (wpas_module_tests() < 0)
7020 #endif /* CONFIG_MODULE_TESTS */
7022 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
7026 if (reply_len < 0) {
7027 os_memcpy(reply, "FAIL\n", 5);
7031 *resp_len = reply_len;