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"
10 #ifdef CONFIG_TESTING_OPTIONS
11 #include <net/ethernet.h>
12 #include <netinet/ip.h>
13 #endif /* CONFIG_TESTING_OPTIONS */
15 #include "utils/common.h"
16 #include "utils/eloop.h"
17 #include "utils/uuid.h"
18 #include "common/version.h"
19 #include "common/ieee802_11_defs.h"
20 #include "common/ieee802_11_common.h"
21 #include "common/wpa_ctrl.h"
22 #include "ap/hostapd.h"
23 #include "eap_peer/eap.h"
24 #include "eapol_supp/eapol_supp_sm.h"
25 #include "rsn_supp/wpa.h"
26 #include "rsn_supp/preauth.h"
27 #include "rsn_supp/pmksa_cache.h"
28 #include "l2_packet/l2_packet.h"
31 #include "wpa_supplicant_i.h"
33 #include "wps_supplicant.h"
36 #include "p2p_supplicant.h"
38 #include "hs20_supplicant.h"
39 #include "wifi_display.h"
43 #include "ctrl_iface.h"
44 #include "interworking.h"
45 #include "blacklist.h"
48 #include "offchannel.h"
49 #include "drivers/driver.h"
52 static int wpa_supplicant_global_iface_list(struct wpa_global *global,
54 static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
56 static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s,
59 static int set_bssid_filter(struct wpa_supplicant *wpa_s, char *val)
62 u8 addr[ETH_ALEN], *filter = NULL, *n;
69 if (hwaddr_aton(pos, addr)) {
73 n = os_realloc_array(filter, count + 1, ETH_ALEN);
79 os_memcpy(filter + count * ETH_ALEN, addr, ETH_ALEN);
82 pos = os_strchr(pos, ' ');
87 wpa_hexdump(MSG_DEBUG, "bssid_filter", filter, count * ETH_ALEN);
88 os_free(wpa_s->bssid_filter);
89 wpa_s->bssid_filter = filter;
90 wpa_s->bssid_filter_count = count;
96 static int set_disallow_aps(struct wpa_supplicant *wpa_s, char *val)
99 u8 addr[ETH_ALEN], *bssid = NULL, *n;
100 struct wpa_ssid_value *ssid = NULL, *ns;
101 size_t count = 0, ssid_count = 0;
105 * disallow_list ::= <ssid_spec> | <bssid_spec> | <disallow_list> | ""
106 * SSID_SPEC ::= ssid <SSID_HEX>
107 * BSSID_SPEC ::= bssid <BSSID_HEX>
114 if (os_strncmp(pos, "bssid ", 6) == 0) {
117 res = hwaddr_aton2(pos, addr);
121 wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
122 "BSSID value '%s'", pos);
126 n = os_realloc_array(bssid, count + 1, ETH_ALEN);
133 os_memcpy(bssid + count * ETH_ALEN, addr, ETH_ALEN);
135 } else if (os_strncmp(pos, "ssid ", 5) == 0) {
141 if (*end == '\0' || *end == ' ')
146 ns = os_realloc_array(ssid, ssid_count + 1,
147 sizeof(struct wpa_ssid_value));
155 if ((end - pos) & 0x01 || end - pos > 2 * 32 ||
156 hexstr2bin(pos, ssid[ssid_count].ssid,
157 (end - pos) / 2) < 0) {
160 wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
161 "SSID value '%s'", pos);
164 ssid[ssid_count].ssid_len = (end - pos) / 2;
165 wpa_hexdump_ascii(MSG_DEBUG, "disallow_aps SSID",
166 ssid[ssid_count].ssid,
167 ssid[ssid_count].ssid_len);
171 wpa_printf(MSG_DEBUG, "Unexpected disallow_aps value "
178 pos = os_strchr(pos, ' ');
183 wpa_hexdump(MSG_DEBUG, "disallow_aps_bssid", bssid, count * ETH_ALEN);
184 os_free(wpa_s->disallow_aps_bssid);
185 wpa_s->disallow_aps_bssid = bssid;
186 wpa_s->disallow_aps_bssid_count = count;
188 wpa_printf(MSG_DEBUG, "disallow_aps_ssid_count %d", (int) ssid_count);
189 os_free(wpa_s->disallow_aps_ssid);
190 wpa_s->disallow_aps_ssid = ssid;
191 wpa_s->disallow_aps_ssid_count = ssid_count;
193 if (!wpa_s->current_ssid || wpa_s->wpa_state < WPA_AUTHENTICATING)
196 c = wpa_s->current_ssid;
197 if (c->mode != WPAS_MODE_INFRA && c->mode != WPAS_MODE_IBSS)
200 if (!disallowed_bssid(wpa_s, wpa_s->bssid) &&
201 !disallowed_ssid(wpa_s, c->ssid, c->ssid_len))
204 wpa_printf(MSG_DEBUG, "Disconnect and try to find another network "
205 "because current AP was marked disallowed");
208 wpa_s->sme.prev_bssid_set = 0;
209 #endif /* CONFIG_SME */
210 wpa_s->reassociate = 1;
211 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
212 wpa_supplicant_req_scan(wpa_s, 0, 0);
218 #ifndef CONFIG_NO_CONFIG_BLOBS
219 static int wpas_ctrl_set_blob(struct wpa_supplicant *wpa_s, char *pos)
222 struct wpa_config_blob *blob;
225 pos = os_strchr(pos, ' ');
229 len = os_strlen(pos);
233 wpa_printf(MSG_DEBUG, "CTRL: Set blob '%s'", name);
234 blob = os_zalloc(sizeof(*blob));
237 blob->name = os_strdup(name);
238 blob->data = os_malloc(len / 2);
239 if (blob->name == NULL || blob->data == NULL) {
240 wpa_config_free_blob(blob);
244 if (hexstr2bin(pos, blob->data, len / 2) < 0) {
245 wpa_printf(MSG_DEBUG, "CTRL: Invalid blob hex data");
246 wpa_config_free_blob(blob);
251 wpa_config_set_blob(wpa_s->conf, blob);
255 #endif /* CONFIG_NO_CONFIG_BLOBS */
258 static int wpas_ctrl_pno(struct wpa_supplicant *wpa_s, char *cmd)
266 params = os_strchr(cmd, ' ');
267 os_free(wpa_s->manual_sched_scan_freqs);
270 pos = os_strstr(params, "freq=");
272 freqs = freq_range_to_channel_list(wpa_s,
275 wpa_s->manual_sched_scan_freqs = freqs;
276 ret = wpas_start_pno(wpa_s);
278 ret = wpas_stop_pno(wpa_s);
284 static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s,
290 value = os_strchr(cmd, ' ');
295 wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value);
296 if (os_strcasecmp(cmd, "EAPOL::heldPeriod") == 0) {
297 eapol_sm_configure(wpa_s->eapol,
298 atoi(value), -1, -1, -1);
299 } else if (os_strcasecmp(cmd, "EAPOL::authPeriod") == 0) {
300 eapol_sm_configure(wpa_s->eapol,
301 -1, atoi(value), -1, -1);
302 } else if (os_strcasecmp(cmd, "EAPOL::startPeriod") == 0) {
303 eapol_sm_configure(wpa_s->eapol,
304 -1, -1, atoi(value), -1);
305 } else if (os_strcasecmp(cmd, "EAPOL::maxStart") == 0) {
306 eapol_sm_configure(wpa_s->eapol,
307 -1, -1, -1, atoi(value));
308 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKLifetime") == 0) {
309 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME,
312 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKReauthThreshold") ==
314 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD,
317 } else if (os_strcasecmp(cmd, "dot11RSNAConfigSATimeout") == 0) {
318 if (wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, atoi(value)))
320 } else if (os_strcasecmp(cmd, "wps_fragment_size") == 0) {
321 wpa_s->wps_fragment_size = atoi(value);
322 #ifdef CONFIG_WPS_TESTING
323 } else if (os_strcasecmp(cmd, "wps_version_number") == 0) {
325 val = strtol(value, NULL, 0);
326 if (val < 0 || val > 0xff) {
328 wpa_printf(MSG_DEBUG, "WPS: Invalid "
329 "wps_version_number %ld", val);
331 wps_version_number = val;
332 wpa_printf(MSG_DEBUG, "WPS: Testing - force WPS "
334 (wps_version_number & 0xf0) >> 4,
335 wps_version_number & 0x0f);
337 } else if (os_strcasecmp(cmd, "wps_testing_dummy_cred") == 0) {
338 wps_testing_dummy_cred = atoi(value);
339 wpa_printf(MSG_DEBUG, "WPS: Testing - dummy_cred=%d",
340 wps_testing_dummy_cred);
341 } else if (os_strcasecmp(cmd, "wps_corrupt_pkhash") == 0) {
342 wps_corrupt_pkhash = atoi(value);
343 wpa_printf(MSG_DEBUG, "WPS: Testing - wps_corrupt_pkhash=%d",
345 #endif /* CONFIG_WPS_TESTING */
346 } else if (os_strcasecmp(cmd, "ampdu") == 0) {
347 if (wpa_drv_ampdu(wpa_s, atoi(value)) < 0)
350 #ifdef CONFIG_TDLS_TESTING
351 } else if (os_strcasecmp(cmd, "tdls_testing") == 0) {
352 extern unsigned int tdls_testing;
353 tdls_testing = strtol(value, NULL, 0);
354 wpa_printf(MSG_DEBUG, "TDLS: tdls_testing=0x%x", tdls_testing);
355 #endif /* CONFIG_TDLS_TESTING */
356 } else if (os_strcasecmp(cmd, "tdls_disabled") == 0) {
357 int disabled = atoi(value);
358 wpa_printf(MSG_DEBUG, "TDLS: tdls_disabled=%d", disabled);
360 if (wpa_drv_tdls_oper(wpa_s, TDLS_DISABLE, NULL) < 0)
362 } else if (wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL) < 0)
364 wpa_tdls_enable(wpa_s->wpa, !disabled);
365 #endif /* CONFIG_TDLS */
366 } else if (os_strcasecmp(cmd, "pno") == 0) {
367 ret = wpas_ctrl_pno(wpa_s, value);
368 } else if (os_strcasecmp(cmd, "radio_disabled") == 0) {
369 int disabled = atoi(value);
370 if (wpa_drv_radio_disable(wpa_s, disabled) < 0)
373 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
374 } else if (os_strcasecmp(cmd, "uapsd") == 0) {
375 if (os_strcmp(value, "disable") == 0)
376 wpa_s->set_sta_uapsd = 0;
380 /* format: BE,BK,VI,VO;max SP Length */
382 pos = os_strchr(value, ',');
387 pos = os_strchr(pos, ',');
392 pos = os_strchr(pos, ',');
397 /* ignore max SP Length for now */
399 wpa_s->set_sta_uapsd = 1;
400 wpa_s->sta_uapsd = 0;
402 wpa_s->sta_uapsd |= BIT(0);
404 wpa_s->sta_uapsd |= BIT(1);
406 wpa_s->sta_uapsd |= BIT(2);
408 wpa_s->sta_uapsd |= BIT(3);
410 } else if (os_strcasecmp(cmd, "ps") == 0) {
411 ret = wpa_drv_set_p2p_powersave(wpa_s, atoi(value), -1, -1);
412 #ifdef CONFIG_WIFI_DISPLAY
413 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
414 int enabled = !!atoi(value);
415 if (enabled && !wpa_s->global->p2p)
418 wifi_display_enable(wpa_s->global, enabled);
419 #endif /* CONFIG_WIFI_DISPLAY */
420 } else if (os_strcasecmp(cmd, "bssid_filter") == 0) {
421 ret = set_bssid_filter(wpa_s, value);
422 } else if (os_strcasecmp(cmd, "disallow_aps") == 0) {
423 ret = set_disallow_aps(wpa_s, value);
424 } else if (os_strcasecmp(cmd, "no_keep_alive") == 0) {
425 wpa_s->no_keep_alive = !!atoi(value);
426 #ifdef CONFIG_TESTING_OPTIONS
427 } else if (os_strcasecmp(cmd, "ext_mgmt_frame_handling") == 0) {
428 wpa_s->ext_mgmt_frame_handling = !!atoi(value);
429 } else if (os_strcasecmp(cmd, "ext_eapol_frame_io") == 0) {
430 wpa_s->ext_eapol_frame_io = !!atoi(value);
432 if (wpa_s->ap_iface) {
433 wpa_s->ap_iface->bss[0]->ext_eapol_frame_io =
434 wpa_s->ext_eapol_frame_io;
436 #endif /* CONFIG_AP */
437 } else if (os_strcasecmp(cmd, "extra_roc_dur") == 0) {
438 wpa_s->extra_roc_dur = atoi(value);
439 #endif /* CONFIG_TESTING_OPTIONS */
440 #ifndef CONFIG_NO_CONFIG_BLOBS
441 } else if (os_strcmp(cmd, "blob") == 0) {
442 ret = wpas_ctrl_set_blob(wpa_s, value);
443 #endif /* CONFIG_NO_CONFIG_BLOBS */
446 ret = wpa_config_process_global(wpa_s->conf, cmd, -1);
448 wpa_supplicant_update_config(wpa_s);
455 static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s,
456 char *cmd, char *buf, size_t buflen)
460 wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd);
462 if (os_strcmp(cmd, "version") == 0) {
463 res = os_snprintf(buf, buflen, "%s", VERSION_STR);
464 } else if (os_strcasecmp(cmd, "country") == 0) {
465 if (wpa_s->conf->country[0] && wpa_s->conf->country[1])
466 res = os_snprintf(buf, buflen, "%c%c",
467 wpa_s->conf->country[0],
468 wpa_s->conf->country[1]);
469 #ifdef CONFIG_WIFI_DISPLAY
470 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
472 if (wpa_s->global->p2p == NULL ||
473 wpa_s->global->p2p_disabled)
476 enabled = wpa_s->global->wifi_display;
477 res = os_snprintf(buf, buflen, "%d", enabled);
478 if (res < 0 || (unsigned int) res >= buflen)
481 #endif /* CONFIG_WIFI_DISPLAY */
482 #ifdef CONFIG_TESTING_GET_GTK
483 } else if (os_strcmp(cmd, "gtk") == 0) {
484 if (wpa_s->last_gtk_len == 0)
486 res = wpa_snprintf_hex(buf, buflen, wpa_s->last_gtk,
487 wpa_s->last_gtk_len);
489 #endif /* CONFIG_TESTING_GET_GTK */
492 if (res < 0 || (unsigned int) res >= buflen)
498 #ifdef IEEE8021X_EAPOL
499 static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s,
503 struct wpa_ssid *ssid = wpa_s->current_ssid;
505 if (hwaddr_aton(addr, bssid)) {
506 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address "
511 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid));
512 rsn_preauth_deinit(wpa_s->wpa);
513 if (rsn_preauth_init(wpa_s->wpa, bssid, ssid ? &ssid->eap : NULL))
518 #endif /* IEEE8021X_EAPOL */
521 #ifdef CONFIG_PEERKEY
522 /* MLME-STKSTART.request(peer) */
523 static int wpa_supplicant_ctrl_iface_stkstart(
524 struct wpa_supplicant *wpa_s, char *addr)
528 if (hwaddr_aton(addr, peer)) {
529 wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART: invalid "
530 "address '%s'", addr);
534 wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART " MACSTR,
537 return wpa_sm_stkstart(wpa_s->wpa, peer);
539 #endif /* CONFIG_PEERKEY */
544 static int wpa_supplicant_ctrl_iface_tdls_discover(
545 struct wpa_supplicant *wpa_s, char *addr)
550 if (hwaddr_aton(addr, peer)) {
551 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER: invalid "
552 "address '%s'", addr);
556 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER " MACSTR,
559 if (wpa_tdls_is_external_setup(wpa_s->wpa))
560 ret = wpa_tdls_send_discovery_request(wpa_s->wpa, peer);
562 ret = wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer);
568 static int wpa_supplicant_ctrl_iface_tdls_setup(
569 struct wpa_supplicant *wpa_s, char *addr)
574 if (hwaddr_aton(addr, peer)) {
575 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP: invalid "
576 "address '%s'", addr);
580 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP " MACSTR,
583 if ((wpa_s->conf->tdls_external_control) &&
584 wpa_tdls_is_external_setup(wpa_s->wpa))
585 return wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
587 wpa_tdls_remove(wpa_s->wpa, peer);
589 if (wpa_tdls_is_external_setup(wpa_s->wpa))
590 ret = wpa_tdls_start(wpa_s->wpa, peer);
592 ret = wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
598 static int wpa_supplicant_ctrl_iface_tdls_teardown(
599 struct wpa_supplicant *wpa_s, char *addr)
604 if (os_strcmp(addr, "*") == 0) {
605 /* remove everyone */
606 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN *");
607 wpa_tdls_teardown_peers(wpa_s->wpa);
611 if (hwaddr_aton(addr, peer)) {
612 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN: invalid "
613 "address '%s'", addr);
617 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN " MACSTR,
620 if ((wpa_s->conf->tdls_external_control) &&
621 wpa_tdls_is_external_setup(wpa_s->wpa))
622 return wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
624 if (wpa_tdls_is_external_setup(wpa_s->wpa))
625 ret = wpa_tdls_teardown_link(
627 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED);
629 ret = wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
635 static int ctrl_iface_get_capability_tdls(
636 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
640 ret = os_snprintf(buf, buflen, "%s\n",
641 wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT ?
643 WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP ?
644 "EXTERNAL" : "INTERNAL") : "UNSUPPORTED");
645 if (ret < 0 || (size_t) ret > buflen)
650 #endif /* CONFIG_TDLS */
653 #ifdef CONFIG_IEEE80211R
654 static int wpa_supplicant_ctrl_iface_ft_ds(
655 struct wpa_supplicant *wpa_s, char *addr)
657 u8 target_ap[ETH_ALEN];
661 if (hwaddr_aton(addr, target_ap)) {
662 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid "
663 "address '%s'", addr);
667 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap));
669 bss = wpa_bss_get_bssid(wpa_s, target_ap);
671 mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN);
675 return wpa_ft_start_over_ds(wpa_s->wpa, target_ap, mdie);
677 #endif /* CONFIG_IEEE80211R */
681 static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s,
684 u8 bssid[ETH_ALEN], *_bssid = bssid;
686 u8 p2p_dev_addr[ETH_ALEN];
687 #endif /* CONFIG_P2P */
689 u8 *_p2p_dev_addr = NULL;
690 #endif /* CONFIG_AP */
692 if (cmd == NULL || os_strcmp(cmd, "any") == 0) {
695 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
696 if (hwaddr_aton(cmd + 13, p2p_dev_addr)) {
697 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid "
698 "P2P Device Address '%s'",
702 _p2p_dev_addr = p2p_dev_addr;
703 #endif /* CONFIG_P2P */
704 } else if (hwaddr_aton(cmd, bssid)) {
705 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
712 return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid, _p2p_dev_addr);
713 #endif /* CONFIG_AP */
715 return wpas_wps_start_pbc(wpa_s, _bssid, 0);
719 static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s,
720 char *cmd, char *buf,
723 u8 bssid[ETH_ALEN], *_bssid = bssid;
727 pin = os_strchr(cmd, ' ');
731 if (os_strcmp(cmd, "any") == 0)
733 else if (os_strcmp(cmd, "get") == 0) {
734 ret = wps_generate_pin();
736 } else if (hwaddr_aton(cmd, bssid)) {
737 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
743 if (wpa_s->ap_iface) {
748 pos = os_strchr(pin, ' ');
755 return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin,
756 buf, buflen, timeout);
758 #endif /* CONFIG_AP */
761 ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0,
765 ret = os_snprintf(buf, buflen, "%s", pin);
766 if (ret < 0 || (size_t) ret >= buflen)
771 ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0, DEV_PW_DEFAULT);
776 /* Return the generated PIN */
777 ret = os_snprintf(buf, buflen, "%08d", ret);
778 if (ret < 0 || (size_t) ret >= buflen)
784 static int wpa_supplicant_ctrl_iface_wps_check_pin(
785 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
792 wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN",
793 (u8 *) cmd, os_strlen(cmd));
794 for (pos = cmd, len = 0; *pos != '\0'; pos++) {
795 if (*pos < '0' || *pos > '9')
799 wpa_printf(MSG_DEBUG, "WPS: Too long PIN");
803 if (len != 4 && len != 8) {
804 wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len);
810 unsigned int pin_val;
812 if (!wps_pin_valid(pin_val)) {
813 wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit");
814 ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n");
815 if (ret < 0 || (size_t) ret >= buflen)
821 ret = os_snprintf(buf, buflen, "%s", pin);
822 if (ret < 0 || (size_t) ret >= buflen)
829 #ifdef CONFIG_WPS_NFC
831 static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant *wpa_s,
834 u8 bssid[ETH_ALEN], *_bssid = bssid;
836 if (cmd == NULL || cmd[0] == '\0')
838 else if (hwaddr_aton(cmd, bssid))
841 return wpas_wps_start_nfc(wpa_s, NULL, _bssid, NULL, 0, 0, NULL, NULL,
846 static int wpa_supplicant_ctrl_iface_wps_nfc_config_token(
847 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
854 pos = os_strchr(cmd, ' ');
857 if (os_strcmp(cmd, "WPS") == 0)
859 else if (os_strcmp(cmd, "NDEF") == 0)
864 buf = wpas_wps_nfc_config_token(wpa_s, ndef, pos);
868 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
879 static int wpa_supplicant_ctrl_iface_wps_nfc_token(
880 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
886 if (os_strcmp(cmd, "WPS") == 0)
888 else if (os_strcmp(cmd, "NDEF") == 0)
893 buf = wpas_wps_nfc_token(wpa_s, ndef);
897 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
908 static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
909 struct wpa_supplicant *wpa_s, char *pos)
917 freq = strstr(pos, " freq=");
921 forced_freq = atoi(freq);
924 len = os_strlen(pos);
929 buf = wpabuf_alloc(len);
932 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
937 ret = wpas_wps_nfc_tag_read(wpa_s, buf, forced_freq);
944 static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant *wpa_s,
945 char *reply, size_t max_len,
951 buf = wpas_wps_nfc_handover_req(wpa_s, ndef);
955 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
967 static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant *wpa_s,
968 char *reply, size_t max_len,
974 buf = wpas_p2p_nfc_handover_req(wpa_s, ndef);
976 wpa_printf(MSG_DEBUG, "P2P: Could not generate NFC handover request");
980 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
989 #endif /* CONFIG_P2P */
992 static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant *wpa_s,
993 char *cmd, char *reply,
999 pos = os_strchr(cmd, ' ');
1004 if (os_strcmp(cmd, "WPS") == 0)
1006 else if (os_strcmp(cmd, "NDEF") == 0)
1011 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
1014 return wpas_ctrl_nfc_get_handover_req_wps(
1015 wpa_s, reply, max_len, ndef);
1019 if (os_strcmp(pos, "P2P-CR") == 0) {
1020 return wpas_ctrl_nfc_get_handover_req_p2p(
1021 wpa_s, reply, max_len, ndef);
1023 #endif /* CONFIG_P2P */
1029 static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant *wpa_s,
1030 char *reply, size_t max_len,
1031 int ndef, int cr, char *uuid)
1036 buf = wpas_wps_nfc_handover_sel(wpa_s, ndef, cr, uuid);
1040 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1042 reply[res++] = '\n';
1052 static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant *wpa_s,
1053 char *reply, size_t max_len,
1059 buf = wpas_p2p_nfc_handover_sel(wpa_s, ndef, tag);
1063 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1065 reply[res++] = '\n';
1072 #endif /* CONFIG_P2P */
1075 static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant *wpa_s,
1076 char *cmd, char *reply,
1082 pos = os_strchr(cmd, ' ');
1087 if (os_strcmp(cmd, "WPS") == 0)
1089 else if (os_strcmp(cmd, "NDEF") == 0)
1094 pos2 = os_strchr(pos, ' ');
1097 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
1100 return wpas_ctrl_nfc_get_handover_sel_wps(
1101 wpa_s, reply, max_len, ndef,
1102 os_strcmp(pos, "WPS-CR") == 0, pos2);
1106 if (os_strcmp(pos, "P2P-CR") == 0) {
1107 return wpas_ctrl_nfc_get_handover_sel_p2p(
1108 wpa_s, reply, max_len, ndef, 0);
1111 if (os_strcmp(pos, "P2P-CR-TAG") == 0) {
1112 return wpas_ctrl_nfc_get_handover_sel_p2p(
1113 wpa_s, reply, max_len, ndef, 1);
1115 #endif /* CONFIG_P2P */
1121 static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant *wpa_s,
1125 struct wpabuf *req, *sel;
1127 char *pos, *role, *type, *pos2;
1130 int forced_freq = 0;
1132 freq = strstr(cmd, " freq=");
1136 forced_freq = atoi(freq);
1138 #endif /* CONFIG_P2P */
1141 pos = os_strchr(role, ' ');
1143 wpa_printf(MSG_DEBUG, "NFC: Missing type in handover report");
1149 pos = os_strchr(type, ' ');
1151 wpa_printf(MSG_DEBUG, "NFC: Missing request message in handover report");
1156 pos2 = os_strchr(pos, ' ');
1158 wpa_printf(MSG_DEBUG, "NFC: Missing select message in handover report");
1163 len = os_strlen(pos);
1165 wpa_printf(MSG_DEBUG, "NFC: Invalid request message length in handover report");
1170 req = wpabuf_alloc(len);
1172 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for request message");
1175 if (hexstr2bin(pos, wpabuf_put(req, len), len) < 0) {
1176 wpa_printf(MSG_DEBUG, "NFC: Invalid request message hexdump in handover report");
1181 len = os_strlen(pos2);
1183 wpa_printf(MSG_DEBUG, "NFC: Invalid select message length in handover report");
1189 sel = wpabuf_alloc(len);
1191 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for select message");
1195 if (hexstr2bin(pos2, wpabuf_put(sel, len), len) < 0) {
1196 wpa_printf(MSG_DEBUG, "NFC: Invalid select message hexdump in handover report");
1202 wpa_printf(MSG_DEBUG, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d",
1203 role, type, (int) wpabuf_len(req), (int) wpabuf_len(sel));
1205 if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "WPS") == 0) {
1206 ret = wpas_wps_nfc_report_handover(wpa_s, req, sel);
1208 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "WPS") == 0)
1210 ret = wpas_ap_wps_nfc_report_handover(wpa_s, req, sel);
1212 ret = wpas_er_wps_nfc_report_handover(wpa_s, req, sel);
1213 #endif /* CONFIG_AP */
1215 } else if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "P2P") == 0)
1217 ret = wpas_p2p_nfc_report_handover(wpa_s, 1, req, sel, 0);
1218 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "P2P") == 0)
1220 ret = wpas_p2p_nfc_report_handover(wpa_s, 0, req, sel,
1222 #endif /* CONFIG_P2P */
1224 wpa_printf(MSG_DEBUG, "NFC: Unsupported connection handover "
1225 "reported: role=%s type=%s", role, type);
1232 wpa_printf(MSG_DEBUG, "NFC: Failed to process reported handover messages");
1237 #endif /* CONFIG_WPS_NFC */
1240 static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s,
1249 struct wps_new_ap_settings ap;
1251 pin = os_strchr(cmd, ' ');
1256 if (hwaddr_aton(cmd, bssid)) {
1257 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
1262 new_ssid = os_strchr(pin, ' ');
1263 if (new_ssid == NULL)
1264 return wpas_wps_start_reg(wpa_s, bssid, pin, NULL);
1267 new_auth = os_strchr(new_ssid, ' ');
1268 if (new_auth == NULL)
1272 new_encr = os_strchr(new_auth, ' ');
1273 if (new_encr == NULL)
1277 new_key = os_strchr(new_encr, ' ');
1278 if (new_key == NULL)
1282 os_memset(&ap, 0, sizeof(ap));
1283 ap.ssid_hex = new_ssid;
1286 ap.key_hex = new_key;
1287 return wpas_wps_start_reg(wpa_s, bssid, pin, &ap);
1292 static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant *wpa_s,
1293 char *cmd, char *buf,
1298 const char *pin_txt;
1300 if (!wpa_s->ap_iface)
1303 pos = os_strchr(cmd, ' ');
1307 if (os_strcmp(cmd, "disable") == 0) {
1308 wpas_wps_ap_pin_disable(wpa_s);
1309 return os_snprintf(buf, buflen, "OK\n");
1312 if (os_strcmp(cmd, "random") == 0) {
1314 timeout = atoi(pos);
1315 pin_txt = wpas_wps_ap_pin_random(wpa_s, timeout);
1316 if (pin_txt == NULL)
1318 return os_snprintf(buf, buflen, "%s", pin_txt);
1321 if (os_strcmp(cmd, "get") == 0) {
1322 pin_txt = wpas_wps_ap_pin_get(wpa_s);
1323 if (pin_txt == NULL)
1325 return os_snprintf(buf, buflen, "%s", pin_txt);
1328 if (os_strcmp(cmd, "set") == 0) {
1333 pos = os_strchr(pos, ' ');
1336 timeout = atoi(pos);
1338 if (os_strlen(pin) > buflen)
1340 if (wpas_wps_ap_pin_set(wpa_s, pin, timeout) < 0)
1342 return os_snprintf(buf, buflen, "%s", pin);
1347 #endif /* CONFIG_AP */
1350 #ifdef CONFIG_WPS_ER
1351 static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant *wpa_s,
1354 char *uuid = cmd, *pin, *pos;
1355 u8 addr_buf[ETH_ALEN], *addr = NULL;
1356 pin = os_strchr(uuid, ' ');
1360 pos = os_strchr(pin, ' ');
1363 if (hwaddr_aton(pos, addr_buf) == 0)
1366 return wpas_wps_er_add_pin(wpa_s, addr, uuid, pin);
1370 static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant *wpa_s,
1373 char *uuid = cmd, *pin;
1374 pin = os_strchr(uuid, ' ');
1378 return wpas_wps_er_learn(wpa_s, uuid, pin);
1382 static int wpa_supplicant_ctrl_iface_wps_er_set_config(
1383 struct wpa_supplicant *wpa_s, char *cmd)
1385 char *uuid = cmd, *id;
1386 id = os_strchr(uuid, ' ');
1390 return wpas_wps_er_set_config(wpa_s, uuid, atoi(id));
1394 static int wpa_supplicant_ctrl_iface_wps_er_config(
1395 struct wpa_supplicant *wpa_s, char *cmd)
1402 struct wps_new_ap_settings ap;
1404 pin = os_strchr(cmd, ' ');
1409 new_ssid = os_strchr(pin, ' ');
1410 if (new_ssid == NULL)
1414 new_auth = os_strchr(new_ssid, ' ');
1415 if (new_auth == NULL)
1419 new_encr = os_strchr(new_auth, ' ');
1420 if (new_encr == NULL)
1424 new_key = os_strchr(new_encr, ' ');
1425 if (new_key == NULL)
1429 os_memset(&ap, 0, sizeof(ap));
1430 ap.ssid_hex = new_ssid;
1433 ap.key_hex = new_key;
1434 return wpas_wps_er_config(wpa_s, cmd, pin, &ap);
1438 #ifdef CONFIG_WPS_NFC
1439 static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
1440 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1447 uuid = os_strchr(cmd, ' ');
1452 if (os_strcmp(cmd, "WPS") == 0)
1454 else if (os_strcmp(cmd, "NDEF") == 0)
1459 buf = wpas_wps_er_nfc_config_token(wpa_s, ndef, uuid);
1463 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1465 reply[res++] = '\n';
1472 #endif /* CONFIG_WPS_NFC */
1473 #endif /* CONFIG_WPS_ER */
1475 #endif /* CONFIG_WPS */
1478 #ifdef CONFIG_IBSS_RSN
1479 static int wpa_supplicant_ctrl_iface_ibss_rsn(
1480 struct wpa_supplicant *wpa_s, char *addr)
1484 if (hwaddr_aton(addr, peer)) {
1485 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN: invalid "
1486 "address '%s'", addr);
1490 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN " MACSTR,
1493 return ibss_rsn_start(wpa_s->ibss_rsn, peer);
1495 #endif /* CONFIG_IBSS_RSN */
1498 static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s,
1501 #ifdef IEEE8021X_EAPOL
1504 struct wpa_ssid *ssid;
1506 pos = os_strchr(rsp, '-');
1511 pos = os_strchr(pos, ':');
1516 wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id);
1517 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
1518 (u8 *) pos, os_strlen(pos));
1520 ssid = wpa_config_get_network(wpa_s->conf, id);
1522 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
1527 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s, ssid, rsp,
1529 #else /* IEEE8021X_EAPOL */
1530 wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included");
1532 #endif /* IEEE8021X_EAPOL */
1536 static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
1538 char *buf, size_t buflen)
1540 char *pos, *end, tmp[30];
1541 int res, verbose, wps, ret;
1544 #endif /* CONFIG_HS20 */
1546 if (os_strcmp(params, "-DRIVER") == 0)
1547 return wpa_drv_status(wpa_s, buf, buflen);
1548 verbose = os_strcmp(params, "-VERBOSE") == 0;
1549 wps = os_strcmp(params, "-WPS") == 0;
1552 if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
1553 struct wpa_ssid *ssid = wpa_s->current_ssid;
1554 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
1555 MAC2STR(wpa_s->bssid));
1556 if (ret < 0 || ret >= end - pos)
1559 ret = os_snprintf(pos, end - pos, "freq=%u\n",
1561 if (ret < 0 || ret >= end - pos)
1565 u8 *_ssid = ssid->ssid;
1566 size_t ssid_len = ssid->ssid_len;
1567 u8 ssid_buf[MAX_SSID_LEN];
1568 if (ssid_len == 0) {
1569 int _res = wpa_drv_get_ssid(wpa_s, ssid_buf);
1576 ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n",
1577 wpa_ssid_txt(_ssid, ssid_len),
1579 if (ret < 0 || ret >= end - pos)
1583 if (wps && ssid->passphrase &&
1584 wpa_key_mgmt_wpa_psk(ssid->key_mgmt) &&
1585 (ssid->mode == WPAS_MODE_AP ||
1586 ssid->mode == WPAS_MODE_P2P_GO)) {
1587 ret = os_snprintf(pos, end - pos,
1590 if (ret < 0 || ret >= end - pos)
1595 ret = os_snprintf(pos, end - pos,
1598 if (ret < 0 || ret >= end - pos)
1603 switch (ssid->mode) {
1604 case WPAS_MODE_INFRA:
1605 ret = os_snprintf(pos, end - pos,
1608 case WPAS_MODE_IBSS:
1609 ret = os_snprintf(pos, end - pos,
1613 ret = os_snprintf(pos, end - pos,
1616 case WPAS_MODE_P2P_GO:
1617 ret = os_snprintf(pos, end - pos,
1620 case WPAS_MODE_P2P_GROUP_FORMATION:
1621 ret = os_snprintf(pos, end - pos,
1622 "mode=P2P GO - group "
1629 if (ret < 0 || ret >= end - pos)
1635 if (wpa_s->ap_iface) {
1636 pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos,
1640 #endif /* CONFIG_AP */
1641 pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose);
1644 if (wpa_s->wpa_state >= WPA_ASSOCIATED &&
1647 #endif /* CONFIG_AP */
1648 wpa_s->sme.sae.state == SAE_ACCEPTED) {
1649 ret = os_snprintf(pos, end - pos, "sae_group=%d\n",
1650 wpa_s->sme.sae.group);
1651 if (ret < 0 || ret >= end - pos)
1655 #endif /* CONFIG_SAE */
1656 ret = os_snprintf(pos, end - pos, "wpa_state=%s\n",
1657 wpa_supplicant_state_txt(wpa_s->wpa_state));
1658 if (ret < 0 || ret >= end - pos)
1663 l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) {
1664 ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp);
1665 if (ret < 0 || ret >= end - pos)
1671 if (wpa_s->global->p2p) {
1672 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
1673 "\n", MAC2STR(wpa_s->global->p2p_dev_addr));
1674 if (ret < 0 || ret >= end - pos)
1678 #endif /* CONFIG_P2P */
1680 ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n",
1681 MAC2STR(wpa_s->own_addr));
1682 if (ret < 0 || ret >= end - pos)
1687 if (wpa_s->current_bss &&
1688 (hs20 = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1689 HS20_IE_VENDOR_TYPE)) &&
1690 wpa_s->wpa_proto == WPA_PROTO_RSN &&
1691 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1694 u8 rel_num = (hs20[6] & 0xf0) >> 4;
1695 release = rel_num + 1;
1697 ret = os_snprintf(pos, end - pos, "hs20=%d\n", release);
1698 if (ret < 0 || ret >= end - pos)
1703 if (wpa_s->current_ssid) {
1704 struct wpa_cred *cred;
1707 for (cred = wpa_s->conf->cred; cred; cred = cred->next) {
1710 if (wpa_s->current_ssid->parent_cred != cred)
1713 if (cred->provisioning_sp) {
1714 ret = os_snprintf(pos, end - pos,
1715 "provisioning_sp=%s\n",
1716 cred->provisioning_sp);
1717 if (ret < 0 || ret >= end - pos)
1726 if (wpa_s->current_bss && wpa_s->current_bss->anqp) {
1727 struct wpabuf *names =
1728 wpa_s->current_bss->anqp->domain_name;
1729 for (i = 0; names && i < cred->num_domain; i++)
1731 if (domain_name_list_contains(
1732 names, cred->domain[i], 1))
1735 if (i == cred->num_domain)
1736 i = 0; /* show first entry by default */
1738 ret = os_snprintf(pos, end - pos, "home_sp=%s\n",
1740 if (ret < 0 || ret >= end - pos)
1745 if (wpa_s->current_bss == NULL ||
1746 wpa_s->current_bss->anqp == NULL)
1749 res = interworking_home_sp_cred(
1751 wpa_s->current_bss->anqp->domain_name);
1759 ret = os_snprintf(pos, end - pos, "sp_type=%s\n", type);
1760 if (ret < 0 || ret >= end - pos)
1767 #endif /* CONFIG_HS20 */
1769 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
1770 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
1771 res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos,
1777 res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose);
1784 uuid_bin2str(wpa_s->wps->uuid, uuid_str, sizeof(uuid_str));
1785 ret = os_snprintf(pos, end - pos, "uuid=%s\n", uuid_str);
1786 if (ret < 0 || ret >= end - pos)
1790 #endif /* CONFIG_WPS */
1794 * Allow using the STATUS command with default behavior, say for debug,
1795 * i.e., don't generate a "fake" CONNECTION and SUPPLICANT_STATE_CHANGE
1796 * events with STATUS-NO_EVENTS.
1798 if (os_strcmp(params, "-NO_EVENTS")) {
1799 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_STATE_CHANGE
1800 "id=%d state=%d BSSID=" MACSTR " SSID=%s",
1801 wpa_s->current_ssid ? wpa_s->current_ssid->id : -1,
1803 MAC2STR(wpa_s->bssid),
1804 wpa_s->current_ssid && wpa_s->current_ssid->ssid ?
1805 wpa_ssid_txt(wpa_s->current_ssid->ssid,
1806 wpa_s->current_ssid->ssid_len) : "");
1807 if (wpa_s->wpa_state == WPA_COMPLETED) {
1808 struct wpa_ssid *ssid = wpa_s->current_ssid;
1809 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_CONNECTED
1810 "- connection to " MACSTR
1811 " completed %s [id=%d id_str=%s]",
1812 MAC2STR(wpa_s->bssid), "(auth)",
1813 ssid ? ssid->id : -1,
1814 ssid && ssid->id_str ? ssid->id_str : "");
1817 #endif /* ANDROID */
1823 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s,
1828 struct wpa_ssid *ssid;
1831 /* cmd: "<network id> <BSSID>" */
1832 pos = os_strchr(cmd, ' ');
1837 wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos);
1838 if (hwaddr_aton(pos, bssid)) {
1839 wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos);
1843 ssid = wpa_config_get_network(wpa_s->conf, id);
1845 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
1850 os_memcpy(ssid->bssid, bssid, ETH_ALEN);
1851 ssid->bssid_set = !is_zero_ether_addr(bssid);
1857 static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant *wpa_s,
1858 char *cmd, char *buf,
1862 struct wpa_blacklist *e;
1866 /* cmd: "BLACKLIST [<BSSID>]" */
1870 e = wpa_s->blacklist;
1872 ret = os_snprintf(pos, end - pos, MACSTR "\n",
1874 if (ret < 0 || ret >= end - pos)
1883 if (os_strncmp(cmd, "clear", 5) == 0) {
1884 wpa_blacklist_clear(wpa_s);
1885 os_memcpy(buf, "OK\n", 3);
1889 wpa_printf(MSG_DEBUG, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd);
1890 if (hwaddr_aton(cmd, bssid)) {
1891 wpa_printf(MSG_DEBUG, "CTRL_IFACE: invalid BSSID '%s'", cmd);
1896 * Add the BSSID twice, so its count will be 2, causing it to be
1897 * skipped when processing scan results.
1899 ret = wpa_blacklist_add(wpa_s, bssid);
1902 ret = wpa_blacklist_add(wpa_s, bssid);
1905 os_memcpy(buf, "OK\n", 3);
1910 static const char * debug_level_str(int level)
1931 static int str_to_debug_level(const char *s)
1933 if (os_strcasecmp(s, "EXCESSIVE") == 0)
1934 return MSG_EXCESSIVE;
1935 if (os_strcasecmp(s, "MSGDUMP") == 0)
1937 if (os_strcasecmp(s, "DEBUG") == 0)
1939 if (os_strcasecmp(s, "INFO") == 0)
1941 if (os_strcasecmp(s, "WARNING") == 0)
1943 if (os_strcasecmp(s, "ERROR") == 0)
1949 static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant *wpa_s,
1950 char *cmd, char *buf,
1953 char *pos, *end, *stamp;
1960 /* cmd: "LOG_LEVEL [<level>]" */
1964 ret = os_snprintf(pos, end - pos, "Current level: %s\n"
1966 debug_level_str(wpa_debug_level),
1967 wpa_debug_timestamp);
1968 if (ret < 0 || ret >= end - pos)
1977 stamp = os_strchr(cmd, ' ');
1980 while (*stamp == ' ') {
1985 if (cmd && os_strlen(cmd)) {
1986 int level = str_to_debug_level(cmd);
1989 wpa_debug_level = level;
1992 if (stamp && os_strlen(stamp))
1993 wpa_debug_timestamp = atoi(stamp);
1995 os_memcpy(buf, "OK\n", 3);
2000 static int wpa_supplicant_ctrl_iface_list_networks(
2001 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
2004 struct wpa_ssid *ssid;
2009 ret = os_snprintf(pos, end - pos,
2010 "network id / ssid / bssid / flags\n");
2011 if (ret < 0 || ret >= end - pos)
2015 ssid = wpa_s->conf->ssid;
2017 ret = os_snprintf(pos, end - pos, "%d\t%s",
2019 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
2020 if (ret < 0 || ret >= end - pos)
2023 if (ssid->bssid_set) {
2024 ret = os_snprintf(pos, end - pos, "\t" MACSTR,
2025 MAC2STR(ssid->bssid));
2027 ret = os_snprintf(pos, end - pos, "\tany");
2029 if (ret < 0 || ret >= end - pos)
2032 ret = os_snprintf(pos, end - pos, "\t%s%s%s%s",
2033 ssid == wpa_s->current_ssid ?
2035 ssid->disabled ? "[DISABLED]" : "",
2036 ssid->disabled_until.sec ?
2037 "[TEMP-DISABLED]" : "",
2038 ssid->disabled == 2 ? "[P2P-PERSISTENT]" :
2040 if (ret < 0 || ret >= end - pos)
2043 ret = os_snprintf(pos, end - pos, "\n");
2044 if (ret < 0 || ret >= end - pos)
2055 static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher)
2058 ret = os_snprintf(pos, end - pos, "-");
2059 if (ret < 0 || ret >= end - pos)
2062 ret = wpa_write_ciphers(pos, end, cipher, "+");
2070 static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
2071 const u8 *ie, size_t ie_len)
2073 struct wpa_ie_data data;
2077 ret = os_snprintf(pos, end - pos, "[%s-", proto);
2078 if (ret < 0 || ret >= end - pos)
2082 if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) {
2083 ret = os_snprintf(pos, end - pos, "?]");
2084 if (ret < 0 || ret >= end - pos)
2091 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
2092 ret = os_snprintf(pos, end - pos, "%sEAP",
2093 pos == start ? "" : "+");
2094 if (ret < 0 || ret >= end - pos)
2098 if (data.key_mgmt & WPA_KEY_MGMT_PSK) {
2099 ret = os_snprintf(pos, end - pos, "%sPSK",
2100 pos == start ? "" : "+");
2101 if (ret < 0 || ret >= end - pos)
2105 if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
2106 ret = os_snprintf(pos, end - pos, "%sNone",
2107 pos == start ? "" : "+");
2108 if (ret < 0 || ret >= end - pos)
2112 if (data.key_mgmt & WPA_KEY_MGMT_SAE) {
2113 ret = os_snprintf(pos, end - pos, "%sSAE",
2114 pos == start ? "" : "+");
2115 if (ret < 0 || ret >= end - pos)
2119 #ifdef CONFIG_IEEE80211R
2120 if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
2121 ret = os_snprintf(pos, end - pos, "%sFT/EAP",
2122 pos == start ? "" : "+");
2123 if (ret < 0 || ret >= end - pos)
2127 if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) {
2128 ret = os_snprintf(pos, end - pos, "%sFT/PSK",
2129 pos == start ? "" : "+");
2130 if (ret < 0 || ret >= end - pos)
2134 if (data.key_mgmt & WPA_KEY_MGMT_FT_SAE) {
2135 ret = os_snprintf(pos, end - pos, "%sFT/SAE",
2136 pos == start ? "" : "+");
2137 if (ret < 0 || ret >= end - pos)
2141 #endif /* CONFIG_IEEE80211R */
2142 #ifdef CONFIG_IEEE80211W
2143 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
2144 ret = os_snprintf(pos, end - pos, "%sEAP-SHA256",
2145 pos == start ? "" : "+");
2146 if (ret < 0 || ret >= end - pos)
2150 if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
2151 ret = os_snprintf(pos, end - pos, "%sPSK-SHA256",
2152 pos == start ? "" : "+");
2153 if (ret < 0 || ret >= end - pos)
2157 #endif /* CONFIG_IEEE80211W */
2159 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B) {
2160 ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B",
2161 pos == start ? "" : "+");
2162 if (ret < 0 || ret >= end - pos)
2167 pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher);
2169 if (data.capabilities & WPA_CAPABILITY_PREAUTH) {
2170 ret = os_snprintf(pos, end - pos, "-preauth");
2171 if (ret < 0 || ret >= end - pos)
2176 ret = os_snprintf(pos, end - pos, "]");
2177 if (ret < 0 || ret >= end - pos)
2186 static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s,
2187 char *pos, char *end,
2188 struct wpabuf *wps_ie)
2195 if (wps_is_selected_pbc_registrar(wps_ie))
2197 else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0))
2199 else if (wps_is_selected_pin_registrar(wps_ie))
2204 ret = os_snprintf(pos, end - pos, "%s", txt);
2205 if (ret >= 0 && ret < end - pos)
2207 wpabuf_free(wps_ie);
2210 #endif /* CONFIG_WPS */
2213 static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s,
2214 char *pos, char *end,
2215 const struct wpa_bss *bss)
2218 struct wpabuf *wps_ie;
2219 wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
2220 return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie);
2221 #else /* CONFIG_WPS */
2223 #endif /* CONFIG_WPS */
2227 /* Format one result on one text line into a buffer. */
2228 static int wpa_supplicant_ctrl_iface_scan_result(
2229 struct wpa_supplicant *wpa_s,
2230 const struct wpa_bss *bss, char *buf, size_t buflen)
2234 const u8 *ie, *ie2, *p2p, *mesh;
2236 mesh = wpa_bss_get_ie(bss, WLAN_EID_MESH_ID);
2237 p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
2239 p2p = wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE);
2240 if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN &&
2241 os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) ==
2243 return 0; /* Do not show P2P listen discovery results here */
2248 ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t",
2249 MAC2STR(bss->bssid), bss->freq, bss->level);
2250 if (ret < 0 || ret >= end - pos)
2253 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
2255 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]);
2256 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
2258 pos = wpa_supplicant_ie_txt(pos, end, mesh ? "RSN" : "WPA2",
2261 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
2262 if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
2263 ret = os_snprintf(pos, end - pos, "[WEP]");
2264 if (ret < 0 || ret >= end - pos)
2269 ret = os_snprintf(pos, end - pos, "[MESH]");
2270 if (ret < 0 || ret >= end - pos)
2274 if (bss_is_dmg(bss)) {
2276 ret = os_snprintf(pos, end - pos, "[DMG]");
2277 if (ret < 0 || ret >= end - pos)
2280 switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
2281 case IEEE80211_CAP_DMG_IBSS:
2284 case IEEE80211_CAP_DMG_AP:
2287 case IEEE80211_CAP_DMG_PBSS:
2294 ret = os_snprintf(pos, end - pos, "%s", s);
2295 if (ret < 0 || ret >= end - pos)
2299 if (bss->caps & IEEE80211_CAP_IBSS) {
2300 ret = os_snprintf(pos, end - pos, "[IBSS]");
2301 if (ret < 0 || ret >= end - pos)
2305 if (bss->caps & IEEE80211_CAP_ESS) {
2306 ret = os_snprintf(pos, end - pos, "[ESS]");
2307 if (ret < 0 || ret >= end - pos)
2313 ret = os_snprintf(pos, end - pos, "[P2P]");
2314 if (ret < 0 || ret >= end - pos)
2319 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE) && ie2) {
2320 ret = os_snprintf(pos, end - pos, "[HS20]");
2321 if (ret < 0 || ret >= end - pos)
2325 #endif /* CONFIG_HS20 */
2327 ret = os_snprintf(pos, end - pos, "\t%s",
2328 wpa_ssid_txt(bss->ssid, bss->ssid_len));
2329 if (ret < 0 || ret >= end - pos)
2333 ret = os_snprintf(pos, end - pos, "\n");
2334 if (ret < 0 || ret >= end - pos)
2342 static int wpa_supplicant_ctrl_iface_scan_results(
2343 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
2346 struct wpa_bss *bss;
2351 ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / "
2353 if (ret < 0 || ret >= end - pos)
2357 dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
2358 ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos,
2360 if (ret < 0 || ret >= end - pos)
2371 static int wpa_supplicant_ctrl_iface_mesh_group_add(
2372 struct wpa_supplicant *wpa_s, char *cmd)
2375 struct wpa_ssid *ssid;
2378 wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_ADD id=%d", id);
2380 ssid = wpa_config_get_network(wpa_s->conf, id);
2382 wpa_printf(MSG_DEBUG,
2383 "CTRL_IFACE: Could not find network id=%d", id);
2386 if (ssid->mode != WPAS_MODE_MESH) {
2387 wpa_printf(MSG_DEBUG,
2388 "CTRL_IFACE: Cannot use MESH_GROUP_ADD on a non mesh network");
2391 if (ssid->key_mgmt != WPA_KEY_MGMT_NONE &&
2392 ssid->key_mgmt != WPA_KEY_MGMT_SAE) {
2393 wpa_printf(MSG_ERROR,
2394 "CTRL_IFACE: key_mgmt for mesh network should be open or SAE");
2399 * TODO: If necessary write our own group_add function,
2400 * for now we can reuse select_network
2402 wpa_supplicant_select_network(wpa_s, ssid);
2408 static int wpa_supplicant_ctrl_iface_mesh_group_remove(
2409 struct wpa_supplicant *wpa_s, char *cmd)
2412 wpa_printf(MSG_ERROR,
2413 "CTRL_IFACE: MESH_GROUP_REMOVE ifname cannot be empty");
2418 * TODO: Support a multiple mesh and other iface type combinations
2420 if (os_strcmp(cmd, wpa_s->ifname) != 0) {
2421 wpa_printf(MSG_DEBUG,
2422 "CTRL_IFACE: MESH_GROUP_REMOVE unknown interface name: %s",
2427 wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s", cmd);
2429 wpa_s->reassociate = 0;
2430 wpa_s->disconnected = 1;
2431 wpa_supplicant_cancel_sched_scan(wpa_s);
2432 wpa_supplicant_cancel_scan(wpa_s);
2435 * TODO: If necessary write our own group_remove function,
2436 * for now we can reuse deauthenticate
2438 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2443 #endif /* CONFIG_MESH */
2446 static int wpa_supplicant_ctrl_iface_select_network(
2447 struct wpa_supplicant *wpa_s, char *cmd)
2450 struct wpa_ssid *ssid;
2453 /* cmd: "<network id>" or "any" */
2454 if (os_strncmp(cmd, "any", 3) == 0) {
2455 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any");
2459 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id);
2461 ssid = wpa_config_get_network(wpa_s->conf, id);
2463 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2464 "network id=%d", id);
2467 if (ssid->disabled == 2) {
2468 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2469 "SELECT_NETWORK with persistent P2P group");
2474 pos = os_strstr(cmd, " freq=");
2476 int *freqs = freq_range_to_channel_list(wpa_s, pos + 6);
2478 wpa_s->scan_req = MANUAL_SCAN_REQ;
2479 os_free(wpa_s->manual_scan_freqs);
2480 wpa_s->manual_scan_freqs = freqs;
2484 wpa_supplicant_select_network(wpa_s, ssid);
2490 static int wpa_supplicant_ctrl_iface_enable_network(
2491 struct wpa_supplicant *wpa_s, char *cmd)
2494 struct wpa_ssid *ssid;
2496 /* cmd: "<network id>" or "all" */
2497 if (os_strcmp(cmd, "all") == 0) {
2498 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all");
2502 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id);
2504 ssid = wpa_config_get_network(wpa_s->conf, id);
2506 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2507 "network id=%d", id);
2510 if (ssid->disabled == 2) {
2511 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2512 "ENABLE_NETWORK with persistent P2P group");
2516 if (os_strstr(cmd, " no-connect")) {
2521 wpa_supplicant_enable_network(wpa_s, ssid);
2527 static int wpa_supplicant_ctrl_iface_disable_network(
2528 struct wpa_supplicant *wpa_s, char *cmd)
2531 struct wpa_ssid *ssid;
2533 /* cmd: "<network id>" or "all" */
2534 if (os_strcmp(cmd, "all") == 0) {
2535 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all");
2539 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id);
2541 ssid = wpa_config_get_network(wpa_s->conf, id);
2543 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2544 "network id=%d", id);
2547 if (ssid->disabled == 2) {
2548 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2549 "DISABLE_NETWORK with persistent P2P "
2554 wpa_supplicant_disable_network(wpa_s, ssid);
2560 static int wpa_supplicant_ctrl_iface_add_network(
2561 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
2563 struct wpa_ssid *ssid;
2566 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK");
2568 ssid = wpa_config_add_network(wpa_s->conf);
2572 wpas_notify_network_added(wpa_s, ssid);
2575 wpa_config_set_network_defaults(ssid);
2577 ret = os_snprintf(buf, buflen, "%d\n", ssid->id);
2578 if (ret < 0 || (size_t) ret >= buflen)
2584 static int wpa_supplicant_ctrl_iface_remove_network(
2585 struct wpa_supplicant *wpa_s, char *cmd)
2588 struct wpa_ssid *ssid;
2591 /* cmd: "<network id>" or "all" */
2592 if (os_strcmp(cmd, "all") == 0) {
2593 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all");
2594 if (wpa_s->sched_scanning)
2595 wpa_supplicant_cancel_sched_scan(wpa_s);
2597 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2598 if (wpa_s->current_ssid) {
2600 wpa_s->sme.prev_bssid_set = 0;
2601 #endif /* CONFIG_SME */
2602 wpa_sm_set_config(wpa_s->wpa, NULL);
2603 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
2604 wpa_supplicant_deauthenticate(
2605 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2607 ssid = wpa_s->conf->ssid;
2609 struct wpa_ssid *remove_ssid = ssid;
2612 if (wpa_s->last_ssid == remove_ssid)
2613 wpa_s->last_ssid = NULL;
2614 wpas_notify_network_removed(wpa_s, remove_ssid);
2615 wpa_config_remove_network(wpa_s->conf, id);
2621 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id);
2623 ssid = wpa_config_get_network(wpa_s->conf, id);
2625 wpas_notify_network_removed(wpa_s, ssid);
2627 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2632 if (wpa_s->last_ssid == ssid)
2633 wpa_s->last_ssid = NULL;
2635 if (ssid == wpa_s->current_ssid || wpa_s->current_ssid == NULL) {
2637 wpa_s->sme.prev_bssid_set = 0;
2638 #endif /* CONFIG_SME */
2640 * Invalidate the EAP session cache if the current or
2641 * previously used network is removed.
2643 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2646 if (ssid == wpa_s->current_ssid) {
2647 wpa_sm_set_config(wpa_s->wpa, NULL);
2648 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
2650 wpa_supplicant_deauthenticate(wpa_s,
2651 WLAN_REASON_DEAUTH_LEAVING);
2654 was_disabled = ssid->disabled;
2656 if (wpa_config_remove_network(wpa_s->conf, id) < 0) {
2657 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Not able to remove the "
2658 "network id=%d", id);
2662 if (!was_disabled && wpa_s->sched_scanning) {
2663 wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to remove "
2664 "network from filters");
2665 wpa_supplicant_cancel_sched_scan(wpa_s);
2666 wpa_supplicant_req_scan(wpa_s, 0, 0);
2673 static int wpa_supplicant_ctrl_iface_update_network(
2674 struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
2675 char *name, char *value)
2677 if (wpa_config_set(ssid, name, value, 0) < 0) {
2678 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network "
2679 "variable '%s'", name);
2683 if (os_strcmp(name, "bssid") != 0 &&
2684 os_strcmp(name, "priority") != 0)
2685 wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
2687 if (wpa_s->current_ssid == ssid || wpa_s->current_ssid == NULL) {
2689 * Invalidate the EAP session cache if anything in the current
2690 * or previously used configuration changes.
2692 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2695 if ((os_strcmp(name, "psk") == 0 &&
2696 value[0] == '"' && ssid->ssid_len) ||
2697 (os_strcmp(name, "ssid") == 0 && ssid->passphrase))
2698 wpa_config_update_psk(ssid);
2699 else if (os_strcmp(name, "priority") == 0)
2700 wpa_config_update_prio_list(wpa_s->conf);
2701 else if (os_strcmp(name, "no_auto_peer") == 0)
2702 ssid->no_auto_peer = atoi(value);
2708 static int wpa_supplicant_ctrl_iface_set_network(
2709 struct wpa_supplicant *wpa_s, char *cmd)
2711 int id, ret, prev_bssid_set;
2712 struct wpa_ssid *ssid;
2714 u8 prev_bssid[ETH_ALEN];
2716 /* cmd: "<network id> <variable name> <value>" */
2717 name = os_strchr(cmd, ' ');
2722 value = os_strchr(name, ' ');
2728 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
2730 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
2731 (u8 *) value, os_strlen(value));
2733 ssid = wpa_config_get_network(wpa_s->conf, id);
2735 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2740 prev_bssid_set = ssid->bssid_set;
2741 os_memcpy(prev_bssid, ssid->bssid, ETH_ALEN);
2742 ret = wpa_supplicant_ctrl_iface_update_network(wpa_s, ssid, name,
2745 (ssid->bssid_set != prev_bssid_set ||
2746 os_memcmp(ssid->bssid, prev_bssid, ETH_ALEN) != 0))
2747 wpas_notify_network_bssid_set_changed(wpa_s, ssid);
2752 static int wpa_supplicant_ctrl_iface_get_network(
2753 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
2757 struct wpa_ssid *ssid;
2760 /* cmd: "<network id> <variable name>" */
2761 name = os_strchr(cmd, ' ');
2762 if (name == NULL || buflen == 0)
2767 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
2770 ssid = wpa_config_get_network(wpa_s->conf, id);
2772 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2777 value = wpa_config_get_no_key(ssid, name);
2778 if (value == NULL) {
2779 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
2780 "variable '%s'", name);
2784 res = os_strlcpy(buf, value, buflen);
2785 if (res >= buflen) {
2796 static int wpa_supplicant_ctrl_iface_dup_network(
2797 struct wpa_supplicant *wpa_s, char *cmd)
2799 struct wpa_ssid *ssid_s, *ssid_d;
2800 char *name, *id, *value;
2801 int id_s, id_d, ret;
2803 /* cmd: "<src network id> <dst network id> <variable name>" */
2804 id = os_strchr(cmd, ' ');
2809 name = os_strchr(id, ' ');
2816 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DUP_NETWORK id=%d -> %d name='%s'",
2819 ssid_s = wpa_config_get_network(wpa_s->conf, id_s);
2820 if (ssid_s == NULL) {
2821 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2822 "network id=%d", id_s);
2826 ssid_d = wpa_config_get_network(wpa_s->conf, id_d);
2827 if (ssid_d == NULL) {
2828 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2829 "network id=%d", id_s);
2833 value = wpa_config_get(ssid_s, name);
2834 if (value == NULL) {
2835 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
2836 "variable '%s'", name);
2840 ret = wpa_supplicant_ctrl_iface_update_network(wpa_s, ssid_d, name,
2849 static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant *wpa_s,
2850 char *buf, size_t buflen)
2853 struct wpa_cred *cred;
2858 ret = os_snprintf(pos, end - pos,
2859 "cred id / realm / username / domain / imsi\n");
2860 if (ret < 0 || ret >= end - pos)
2864 cred = wpa_s->conf->cred;
2866 ret = os_snprintf(pos, end - pos, "%d\t%s\t%s\t%s\t%s\n",
2867 cred->id, cred->realm ? cred->realm : "",
2868 cred->username ? cred->username : "",
2869 cred->domain ? cred->domain[0] : "",
2870 cred->imsi ? cred->imsi : "");
2871 if (ret < 0 || ret >= end - pos)
2882 static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant *wpa_s,
2883 char *buf, size_t buflen)
2885 struct wpa_cred *cred;
2888 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_CRED");
2890 cred = wpa_config_add_cred(wpa_s->conf);
2894 wpa_msg(wpa_s, MSG_INFO, CRED_ADDED "%d", cred->id);
2896 ret = os_snprintf(buf, buflen, "%d\n", cred->id);
2897 if (ret < 0 || (size_t) ret >= buflen)
2903 static int wpas_ctrl_remove_cred(struct wpa_supplicant *wpa_s,
2904 struct wpa_cred *cred)
2906 struct wpa_ssid *ssid;
2911 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred");
2916 if (wpa_config_remove_cred(wpa_s->conf, id) < 0) {
2917 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred");
2921 wpa_msg(wpa_s, MSG_INFO, CRED_REMOVED "%d", id);
2923 /* Remove any network entry created based on the removed credential */
2924 ssid = wpa_s->conf->ssid;
2926 if (ssid->parent_cred == cred) {
2927 wpa_printf(MSG_DEBUG, "Remove network id %d since it "
2928 "used the removed credential", ssid->id);
2929 os_snprintf(str, sizeof(str), "%d", ssid->id);
2931 wpa_supplicant_ctrl_iface_remove_network(wpa_s, str);
2940 static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s,
2944 struct wpa_cred *cred, *prev;
2946 /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or
2947 * "provisioning_sp=<FQDN> */
2948 if (os_strcmp(cmd, "all") == 0) {
2949 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED all");
2950 cred = wpa_s->conf->cred;
2954 wpas_ctrl_remove_cred(wpa_s, prev);
2959 if (os_strncmp(cmd, "sp_fqdn=", 8) == 0) {
2960 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
2962 cred = wpa_s->conf->cred;
2968 for (i = 0; i < prev->num_domain; i++) {
2969 if (os_strcmp(prev->domain[i], cmd + 8)
2972 wpas_ctrl_remove_cred(wpa_s, prev);
2980 if (os_strncmp(cmd, "provisioning_sp=", 16) == 0) {
2981 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'",
2983 cred = wpa_s->conf->cred;
2987 if (prev->provisioning_sp &&
2988 os_strcmp(prev->provisioning_sp, cmd + 16) == 0)
2989 wpas_ctrl_remove_cred(wpa_s, prev);
2995 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED id=%d", id);
2997 cred = wpa_config_get_cred(wpa_s->conf, id);
2998 return wpas_ctrl_remove_cred(wpa_s, cred);
3002 static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant *wpa_s,
3006 struct wpa_cred *cred;
3009 /* cmd: "<cred id> <variable name> <value>" */
3010 name = os_strchr(cmd, ' ');
3015 value = os_strchr(name, ' ');
3021 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_CRED id=%d name='%s'",
3023 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
3024 (u8 *) value, os_strlen(value));
3026 cred = wpa_config_get_cred(wpa_s->conf, id);
3028 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
3033 if (wpa_config_set_cred(cred, name, value, 0) < 0) {
3034 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set cred "
3035 "variable '%s'", name);
3039 wpa_msg(wpa_s, MSG_INFO, CRED_MODIFIED "%d %s", cred->id, name);
3045 static int wpa_supplicant_ctrl_iface_get_cred(struct wpa_supplicant *wpa_s,
3046 char *cmd, char *buf,
3051 struct wpa_cred *cred;
3054 /* cmd: "<cred id> <variable name>" */
3055 name = os_strchr(cmd, ' ');
3061 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CRED id=%d name='%s'",
3064 cred = wpa_config_get_cred(wpa_s->conf, id);
3066 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
3071 value = wpa_config_get_cred_no_key(cred, name);
3072 if (value == NULL) {
3073 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get cred variable '%s'",
3078 res = os_strlcpy(buf, value, buflen);
3079 if (res >= buflen) {
3090 #ifndef CONFIG_NO_CONFIG_WRITE
3091 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s)
3095 if (!wpa_s->conf->update_config) {
3096 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
3097 "to update configuration (update_config=0)");
3101 ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
3103 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to "
3104 "update configuration");
3106 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration"
3112 #endif /* CONFIG_NO_CONFIG_WRITE */
3115 struct cipher_info {
3121 static const struct cipher_info ciphers[] = {
3122 { WPA_DRIVER_CAPA_ENC_CCMP_256, "CCMP-256", 0 },
3123 { WPA_DRIVER_CAPA_ENC_GCMP_256, "GCMP-256", 0 },
3124 { WPA_DRIVER_CAPA_ENC_CCMP, "CCMP", 0 },
3125 { WPA_DRIVER_CAPA_ENC_GCMP, "GCMP", 0 },
3126 { WPA_DRIVER_CAPA_ENC_TKIP, "TKIP", 0 },
3127 { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE, "NONE", 0 },
3128 { WPA_DRIVER_CAPA_ENC_WEP104, "WEP104", 1 },
3129 { WPA_DRIVER_CAPA_ENC_WEP40, "WEP40", 1 }
3133 static int ctrl_iface_get_capability_pairwise(int res, char *strict,
3134 struct wpa_driver_capa *capa,
3135 char *buf, size_t buflen)
3148 len = os_strlcpy(buf, "CCMP TKIP NONE", buflen);
3154 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
3155 if (!ciphers[i].group_only && capa->enc & ciphers[i].capa) {
3156 ret = os_snprintf(pos, end - pos, "%s%s",
3157 pos == buf ? "" : " ",
3159 if (ret < 0 || ret >= end - pos)
3169 static int ctrl_iface_get_capability_group(int res, char *strict,
3170 struct wpa_driver_capa *capa,
3171 char *buf, size_t buflen)
3184 len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen);
3190 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
3191 if (capa->enc & ciphers[i].capa) {
3192 ret = os_snprintf(pos, end - pos, "%s%s",
3193 pos == buf ? "" : " ",
3195 if (ret < 0 || ret >= end - pos)
3205 static int ctrl_iface_get_capability_key_mgmt(int res, char *strict,
3206 struct wpa_driver_capa *capa,
3207 char *buf, size_t buflen)
3219 len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
3226 ret = os_snprintf(pos, end - pos, "NONE IEEE8021X");
3227 if (ret < 0 || ret >= end - pos)
3231 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
3232 WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
3233 ret = os_snprintf(pos, end - pos, " WPA-EAP");
3234 if (ret < 0 || ret >= end - pos)
3239 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
3240 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
3241 ret = os_snprintf(pos, end - pos, " WPA-PSK");
3242 if (ret < 0 || ret >= end - pos)
3247 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
3248 ret = os_snprintf(pos, end - pos, " WPA-NONE");
3249 if (ret < 0 || ret >= end - pos)
3258 static int ctrl_iface_get_capability_proto(int res, char *strict,
3259 struct wpa_driver_capa *capa,
3260 char *buf, size_t buflen)
3272 len = os_strlcpy(buf, "RSN WPA", buflen);
3278 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
3279 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
3280 ret = os_snprintf(pos, end - pos, "%sRSN",
3281 pos == buf ? "" : " ");
3282 if (ret < 0 || ret >= end - pos)
3287 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
3288 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
3289 ret = os_snprintf(pos, end - pos, "%sWPA",
3290 pos == buf ? "" : " ");
3291 if (ret < 0 || ret >= end - pos)
3300 static int ctrl_iface_get_capability_auth_alg(int res, char *strict,
3301 struct wpa_driver_capa *capa,
3302 char *buf, size_t buflen)
3314 len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen);
3320 if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) {
3321 ret = os_snprintf(pos, end - pos, "%sOPEN",
3322 pos == buf ? "" : " ");
3323 if (ret < 0 || ret >= end - pos)
3328 if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) {
3329 ret = os_snprintf(pos, end - pos, "%sSHARED",
3330 pos == buf ? "" : " ");
3331 if (ret < 0 || ret >= end - pos)
3336 if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) {
3337 ret = os_snprintf(pos, end - pos, "%sLEAP",
3338 pos == buf ? "" : " ");
3339 if (ret < 0 || ret >= end - pos)
3348 static int ctrl_iface_get_capability_modes(int res, char *strict,
3349 struct wpa_driver_capa *capa,
3350 char *buf, size_t buflen)
3362 len = os_strlcpy(buf, "IBSS AP", buflen);
3368 if (capa->flags & WPA_DRIVER_FLAGS_IBSS) {
3369 ret = os_snprintf(pos, end - pos, "%sIBSS",
3370 pos == buf ? "" : " ");
3371 if (ret < 0 || ret >= end - pos)
3376 if (capa->flags & WPA_DRIVER_FLAGS_AP) {
3377 ret = os_snprintf(pos, end - pos, "%sAP",
3378 pos == buf ? "" : " ");
3379 if (ret < 0 || ret >= end - pos)
3388 static int ctrl_iface_get_capability_channels(struct wpa_supplicant *wpa_s,
3389 char *buf, size_t buflen)
3391 struct hostapd_channel_data *chnl;
3393 char *pos, *end, *hmode;
3398 for (j = 0; j < wpa_s->hw.num_modes; j++) {
3399 switch (wpa_s->hw.modes[j].mode) {
3400 case HOSTAPD_MODE_IEEE80211B:
3403 case HOSTAPD_MODE_IEEE80211G:
3406 case HOSTAPD_MODE_IEEE80211A:
3409 case HOSTAPD_MODE_IEEE80211AD:
3415 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:", hmode);
3416 if (ret < 0 || ret >= end - pos)
3419 chnl = wpa_s->hw.modes[j].channels;
3420 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
3421 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
3423 ret = os_snprintf(pos, end - pos, " %d", chnl[i].chan);
3424 if (ret < 0 || ret >= end - pos)
3428 ret = os_snprintf(pos, end - pos, "\n");
3429 if (ret < 0 || ret >= end - pos)
3438 static int ctrl_iface_get_capability_freq(struct wpa_supplicant *wpa_s,
3439 char *buf, size_t buflen)
3441 struct hostapd_channel_data *chnl;
3443 char *pos, *end, *hmode;
3448 for (j = 0; j < wpa_s->hw.num_modes; j++) {
3449 switch (wpa_s->hw.modes[j].mode) {
3450 case HOSTAPD_MODE_IEEE80211B:
3453 case HOSTAPD_MODE_IEEE80211G:
3456 case HOSTAPD_MODE_IEEE80211A:
3459 case HOSTAPD_MODE_IEEE80211AD:
3465 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:\n",
3467 if (ret < 0 || ret >= end - pos)
3470 chnl = wpa_s->hw.modes[j].channels;
3471 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
3472 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
3474 ret = os_snprintf(pos, end - pos, " %d = %d MHz%s%s\n",
3475 chnl[i].chan, chnl[i].freq,
3476 chnl[i].flag & HOSTAPD_CHAN_NO_IR ?
3478 chnl[i].flag & HOSTAPD_CHAN_RADAR ?
3481 if (ret < 0 || ret >= end - pos)
3485 ret = os_snprintf(pos, end - pos, "\n");
3486 if (ret < 0 || ret >= end - pos)
3495 static int wpa_supplicant_ctrl_iface_get_capability(
3496 struct wpa_supplicant *wpa_s, const char *_field, char *buf,
3499 struct wpa_driver_capa capa;
3505 /* Determine whether or not strict checking was requested */
3506 len = os_strlcpy(field, _field, sizeof(field));
3507 if (len >= sizeof(field))
3509 strict = os_strchr(field, ' ');
3510 if (strict != NULL) {
3512 if (os_strcmp(strict, "strict") != 0)
3516 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
3517 field, strict ? strict : "");
3519 if (os_strcmp(field, "eap") == 0) {
3520 return eap_get_names(buf, buflen);
3523 res = wpa_drv_get_capa(wpa_s, &capa);
3525 if (os_strcmp(field, "pairwise") == 0)
3526 return ctrl_iface_get_capability_pairwise(res, strict, &capa,
3529 if (os_strcmp(field, "group") == 0)
3530 return ctrl_iface_get_capability_group(res, strict, &capa,
3533 if (os_strcmp(field, "key_mgmt") == 0)
3534 return ctrl_iface_get_capability_key_mgmt(res, strict, &capa,
3537 if (os_strcmp(field, "proto") == 0)
3538 return ctrl_iface_get_capability_proto(res, strict, &capa,
3541 if (os_strcmp(field, "auth_alg") == 0)
3542 return ctrl_iface_get_capability_auth_alg(res, strict, &capa,
3545 if (os_strcmp(field, "modes") == 0)
3546 return ctrl_iface_get_capability_modes(res, strict, &capa,
3549 if (os_strcmp(field, "channels") == 0)
3550 return ctrl_iface_get_capability_channels(wpa_s, buf, buflen);
3552 if (os_strcmp(field, "freq") == 0)
3553 return ctrl_iface_get_capability_freq(wpa_s, buf, buflen);
3556 if (os_strcmp(field, "tdls") == 0)
3557 return ctrl_iface_get_capability_tdls(wpa_s, buf, buflen);
3558 #endif /* CONFIG_TDLS */
3560 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
3567 #ifdef CONFIG_INTERWORKING
3568 static char * anqp_add_hex(char *pos, char *end, const char *title,
3569 struct wpabuf *data)
3579 ret = os_snprintf(pos, end - pos, "%s=", title);
3580 if (ret < 0 || ret >= end - pos)
3584 d = wpabuf_head_u8(data);
3585 for (i = 0; i < wpabuf_len(data); i++) {
3586 ret = os_snprintf(pos, end - pos, "%02x", *d++);
3587 if (ret < 0 || ret >= end - pos)
3592 ret = os_snprintf(pos, end - pos, "\n");
3593 if (ret < 0 || ret >= end - pos)
3599 #endif /* CONFIG_INTERWORKING */
3602 static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
3603 unsigned long mask, char *buf, size_t buflen)
3613 if (mask & WPA_BSS_MASK_ID) {
3614 ret = os_snprintf(pos, end - pos, "id=%u\n", bss->id);
3615 if (ret < 0 || ret >= end - pos)
3620 if (mask & WPA_BSS_MASK_BSSID) {
3621 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
3622 MAC2STR(bss->bssid));
3623 if (ret < 0 || ret >= end - pos)
3628 if (mask & WPA_BSS_MASK_FREQ) {
3629 ret = os_snprintf(pos, end - pos, "freq=%d\n", bss->freq);
3630 if (ret < 0 || ret >= end - pos)
3635 if (mask & WPA_BSS_MASK_BEACON_INT) {
3636 ret = os_snprintf(pos, end - pos, "beacon_int=%d\n",
3638 if (ret < 0 || ret >= end - pos)
3643 if (mask & WPA_BSS_MASK_CAPABILITIES) {
3644 ret = os_snprintf(pos, end - pos, "capabilities=0x%04x\n",
3646 if (ret < 0 || ret >= end - pos)
3651 if (mask & WPA_BSS_MASK_QUAL) {
3652 ret = os_snprintf(pos, end - pos, "qual=%d\n", bss->qual);
3653 if (ret < 0 || ret >= end - pos)
3658 if (mask & WPA_BSS_MASK_NOISE) {
3659 ret = os_snprintf(pos, end - pos, "noise=%d\n", bss->noise);
3660 if (ret < 0 || ret >= end - pos)
3665 if (mask & WPA_BSS_MASK_LEVEL) {
3666 ret = os_snprintf(pos, end - pos, "level=%d\n", bss->level);
3667 if (ret < 0 || ret >= end - pos)
3672 if (mask & WPA_BSS_MASK_TSF) {
3673 ret = os_snprintf(pos, end - pos, "tsf=%016llu\n",
3674 (unsigned long long) bss->tsf);
3675 if (ret < 0 || ret >= end - pos)
3680 if (mask & WPA_BSS_MASK_AGE) {
3681 struct os_reltime now;
3683 os_get_reltime(&now);
3684 ret = os_snprintf(pos, end - pos, "age=%d\n",
3685 (int) (now.sec - bss->last_update.sec));
3686 if (ret < 0 || ret >= end - pos)
3691 if (mask & WPA_BSS_MASK_IE) {
3692 ret = os_snprintf(pos, end - pos, "ie=");
3693 if (ret < 0 || ret >= end - pos)
3697 ie = (const u8 *) (bss + 1);
3698 for (i = 0; i < bss->ie_len; i++) {
3699 ret = os_snprintf(pos, end - pos, "%02x", *ie++);
3700 if (ret < 0 || ret >= end - pos)
3705 ret = os_snprintf(pos, end - pos, "\n");
3706 if (ret < 0 || ret >= end - pos)
3711 if (mask & WPA_BSS_MASK_FLAGS) {
3712 ret = os_snprintf(pos, end - pos, "flags=");
3713 if (ret < 0 || ret >= end - pos)
3717 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
3719 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie,
3721 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
3723 pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2,
3725 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
3726 if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
3727 ret = os_snprintf(pos, end - pos, "[WEP]");
3728 if (ret < 0 || ret >= end - pos)
3732 if (bss_is_dmg(bss)) {
3734 ret = os_snprintf(pos, end - pos, "[DMG]");
3735 if (ret < 0 || ret >= end - pos)
3738 switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
3739 case IEEE80211_CAP_DMG_IBSS:
3742 case IEEE80211_CAP_DMG_AP:
3745 case IEEE80211_CAP_DMG_PBSS:
3752 ret = os_snprintf(pos, end - pos, "%s", s);
3753 if (ret < 0 || ret >= end - pos)
3757 if (bss->caps & IEEE80211_CAP_IBSS) {
3758 ret = os_snprintf(pos, end - pos, "[IBSS]");
3759 if (ret < 0 || ret >= end - pos)
3763 if (bss->caps & IEEE80211_CAP_ESS) {
3764 ret = os_snprintf(pos, end - pos, "[ESS]");
3765 if (ret < 0 || ret >= end - pos)
3770 if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
3771 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
3772 ret = os_snprintf(pos, end - pos, "[P2P]");
3773 if (ret < 0 || ret >= end - pos)
3778 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) {
3779 ret = os_snprintf(pos, end - pos, "[HS20]");
3780 if (ret < 0 || ret >= end - pos)
3784 #endif /* CONFIG_HS20 */
3786 ret = os_snprintf(pos, end - pos, "\n");
3787 if (ret < 0 || ret >= end - pos)
3792 if (mask & WPA_BSS_MASK_SSID) {
3793 ret = os_snprintf(pos, end - pos, "ssid=%s\n",
3794 wpa_ssid_txt(bss->ssid, bss->ssid_len));
3795 if (ret < 0 || ret >= end - pos)
3801 if (mask & WPA_BSS_MASK_WPS_SCAN) {
3802 ie = (const u8 *) (bss + 1);
3803 ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end);
3804 if (ret < 0 || ret >= end - pos)
3808 #endif /* CONFIG_WPS */
3811 if (mask & WPA_BSS_MASK_P2P_SCAN) {
3812 ie = (const u8 *) (bss + 1);
3813 ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end);
3814 if (ret < 0 || ret >= end - pos)
3818 #endif /* CONFIG_P2P */
3820 #ifdef CONFIG_WIFI_DISPLAY
3821 if (mask & WPA_BSS_MASK_WIFI_DISPLAY) {
3823 ie = (const u8 *) (bss + 1);
3824 wfd = ieee802_11_vendor_ie_concat(ie, bss->ie_len,
3825 WFD_IE_VENDOR_TYPE);
3827 ret = os_snprintf(pos, end - pos, "wfd_subelems=");
3828 if (ret < 0 || ret >= end - pos) {
3834 pos += wpa_snprintf_hex(pos, end - pos,
3839 ret = os_snprintf(pos, end - pos, "\n");
3840 if (ret < 0 || ret >= end - pos)
3845 #endif /* CONFIG_WIFI_DISPLAY */
3847 #ifdef CONFIG_INTERWORKING
3848 if ((mask & WPA_BSS_MASK_INTERNETW) && bss->anqp) {
3849 struct wpa_bss_anqp *anqp = bss->anqp;
3850 pos = anqp_add_hex(pos, end, "anqp_venue_name",
3852 pos = anqp_add_hex(pos, end, "anqp_network_auth_type",
3853 anqp->network_auth_type);
3854 pos = anqp_add_hex(pos, end, "anqp_roaming_consortium",
3855 anqp->roaming_consortium);
3856 pos = anqp_add_hex(pos, end, "anqp_ip_addr_type_availability",
3857 anqp->ip_addr_type_availability);
3858 pos = anqp_add_hex(pos, end, "anqp_nai_realm",
3860 pos = anqp_add_hex(pos, end, "anqp_3gpp", anqp->anqp_3gpp);
3861 pos = anqp_add_hex(pos, end, "anqp_domain_name",
3864 pos = anqp_add_hex(pos, end, "hs20_operator_friendly_name",
3865 anqp->hs20_operator_friendly_name);
3866 pos = anqp_add_hex(pos, end, "hs20_wan_metrics",
3867 anqp->hs20_wan_metrics);
3868 pos = anqp_add_hex(pos, end, "hs20_connection_capability",
3869 anqp->hs20_connection_capability);
3870 pos = anqp_add_hex(pos, end, "hs20_operating_class",
3871 anqp->hs20_operating_class);
3872 pos = anqp_add_hex(pos, end, "hs20_osu_providers_list",
3873 anqp->hs20_osu_providers_list);
3874 #endif /* CONFIG_HS20 */
3876 #endif /* CONFIG_INTERWORKING */
3879 if (mask & WPA_BSS_MASK_MESH_SCAN) {
3880 ie = (const u8 *) (bss + 1);
3881 ret = wpas_mesh_scan_result_text(ie, bss->ie_len, pos, end);
3882 if (ret < 0 || ret >= end - pos)
3886 #endif /* CONFIG_MESH */
3888 if (mask & WPA_BSS_MASK_DELIM) {
3889 ret = os_snprintf(pos, end - pos, "====\n");
3890 if (ret < 0 || ret >= end - pos)
3899 static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
3900 const char *cmd, char *buf,
3905 struct wpa_bss *bss;
3906 struct wpa_bss *bsslast = NULL;
3907 struct dl_list *next;
3911 unsigned long mask = WPA_BSS_MASK_ALL;
3913 if (os_strncmp(cmd, "RANGE=", 6) == 0) {
3914 if (os_strncmp(cmd + 6, "ALL", 3) == 0) {
3915 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss,
3917 bsslast = dl_list_last(&wpa_s->bss_id, struct wpa_bss,
3919 } else { /* N1-N2 */
3920 unsigned int id1, id2;
3922 if ((ctmp = os_strchr(cmd + 6, '-')) == NULL) {
3923 wpa_printf(MSG_INFO, "Wrong BSS range "
3928 if (*(cmd + 6) == '-')
3931 id1 = atoi(cmd + 6);
3933 if (*ctmp >= '0' && *ctmp <= '9')
3936 id2 = (unsigned int) -1;
3937 bss = wpa_bss_get_id_range(wpa_s, id1, id2);
3938 if (id2 == (unsigned int) -1)
3939 bsslast = dl_list_last(&wpa_s->bss_id,
3943 bsslast = wpa_bss_get_id(wpa_s, id2);
3944 if (bsslast == NULL && bss && id2 > id1) {
3945 struct wpa_bss *tmp = bss;
3947 next = tmp->list_id.next;
3948 if (next == &wpa_s->bss_id)
3950 tmp = dl_list_entry(
3951 next, struct wpa_bss,
3960 } else if (os_strncmp(cmd, "FIRST", 5) == 0)
3961 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, list_id);
3962 else if (os_strncmp(cmd, "LAST", 4) == 0)
3963 bss = dl_list_last(&wpa_s->bss_id, struct wpa_bss, list_id);
3964 else if (os_strncmp(cmd, "ID-", 3) == 0) {
3966 bss = wpa_bss_get_id(wpa_s, i);
3967 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
3969 bss = wpa_bss_get_id(wpa_s, i);
3971 next = bss->list_id.next;
3972 if (next == &wpa_s->bss_id)
3975 bss = dl_list_entry(next, struct wpa_bss,
3979 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
3980 if (hwaddr_aton(cmd + 13, bssid) == 0)
3981 bss = wpa_bss_get_p2p_dev_addr(wpa_s, bssid);
3984 #endif /* CONFIG_P2P */
3985 } else if (hwaddr_aton(cmd, bssid) == 0)
3986 bss = wpa_bss_get_bssid(wpa_s, bssid);
3988 struct wpa_bss *tmp;
3991 dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id)
4000 if ((ctmp = os_strstr(cmd, "MASK=")) != NULL) {
4001 mask = strtoul(ctmp + 5, NULL, 0x10);
4003 mask = WPA_BSS_MASK_ALL;
4009 if (bsslast == NULL)
4012 len = print_bss_info(wpa_s, bss, mask, buf, buflen);
4016 if (bss == bsslast) {
4017 if ((mask & WPA_BSS_MASK_DELIM) && len &&
4018 (bss == dl_list_last(&wpa_s->bss_id,
4019 struct wpa_bss, list_id)))
4020 os_snprintf(buf - 5, 5, "####\n");
4023 next = bss->list_id.next;
4024 if (next == &wpa_s->bss_id)
4026 bss = dl_list_entry(next, struct wpa_bss, list_id);
4027 } while (bss && len);
4033 static int wpa_supplicant_ctrl_iface_ap_scan(
4034 struct wpa_supplicant *wpa_s, char *cmd)
4036 int ap_scan = atoi(cmd);
4037 return wpa_supplicant_set_ap_scan(wpa_s, ap_scan);
4041 static int wpa_supplicant_ctrl_iface_scan_interval(
4042 struct wpa_supplicant *wpa_s, char *cmd)
4044 int scan_int = atoi(cmd);
4045 return wpa_supplicant_set_scan_interval(wpa_s, scan_int);
4049 static int wpa_supplicant_ctrl_iface_bss_expire_age(
4050 struct wpa_supplicant *wpa_s, char *cmd)
4052 int expire_age = atoi(cmd);
4053 return wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age);
4057 static int wpa_supplicant_ctrl_iface_bss_expire_count(
4058 struct wpa_supplicant *wpa_s, char *cmd)
4060 int expire_count = atoi(cmd);
4061 return wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count);
4065 static int wpa_supplicant_ctrl_iface_bss_flush(
4066 struct wpa_supplicant *wpa_s, char *cmd)
4068 int flush_age = atoi(cmd);
4071 wpa_bss_flush(wpa_s);
4073 wpa_bss_flush_by_age(wpa_s, flush_age);
4078 #ifdef CONFIG_TESTING_OPTIONS
4079 static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s)
4081 wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication");
4082 /* MLME-DELETEKEYS.request */
4083 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL, 0);
4084 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL, 0);
4085 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL, 0);
4086 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL, 0);
4087 #ifdef CONFIG_IEEE80211W
4088 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL, 0);
4089 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL, 0);
4090 #endif /* CONFIG_IEEE80211W */
4092 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, wpa_s->bssid, 0, 0, NULL, 0, NULL,
4094 /* MLME-SETPROTECTION.request(None) */
4095 wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid,
4096 MLME_SETPROTECTION_PROTECT_TYPE_NONE,
4097 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE);
4098 wpa_sm_drop_sa(wpa_s->wpa);
4100 #endif /* CONFIG_TESTING_OPTIONS */
4103 static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s,
4106 #ifdef CONFIG_NO_SCAN_PROCESSING
4108 #else /* CONFIG_NO_SCAN_PROCESSING */
4110 struct wpa_bss *bss;
4111 struct wpa_ssid *ssid = wpa_s->current_ssid;
4113 if (hwaddr_aton(addr, bssid)) {
4114 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid "
4115 "address '%s'", addr);
4119 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR, MAC2STR(bssid));
4122 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network "
4123 "configuration known for the target AP");
4127 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
4129 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found "
4135 * TODO: Find best network configuration block from configuration to
4136 * allow roaming to other networks
4139 wpa_s->reassociate = 1;
4140 wpa_supplicant_connect(wpa_s, bss, ssid);
4143 #endif /* CONFIG_NO_SCAN_PROCESSING */
4148 static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd)
4150 unsigned int timeout = atoi(cmd);
4151 enum p2p_discovery_type type = P2P_FIND_START_WITH_FULL;
4152 u8 dev_id[ETH_ALEN], *_dev_id = NULL;
4153 u8 dev_type[WPS_DEV_TYPE_LEN], *_dev_type = NULL;
4155 unsigned int search_delay;
4157 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
4158 wpa_dbg(wpa_s, MSG_INFO,
4159 "Reject P2P_FIND since interface is disabled");
4162 if (os_strstr(cmd, "type=social"))
4163 type = P2P_FIND_ONLY_SOCIAL;
4164 else if (os_strstr(cmd, "type=progressive"))
4165 type = P2P_FIND_PROGRESSIVE;
4167 pos = os_strstr(cmd, "dev_id=");
4170 if (hwaddr_aton(pos, dev_id))
4175 pos = os_strstr(cmd, "dev_type=");
4178 if (wps_dev_type_str2bin(pos, dev_type) < 0)
4180 _dev_type = dev_type;
4183 pos = os_strstr(cmd, "delay=");
4186 search_delay = atoi(pos);
4188 search_delay = wpas_p2p_search_delay(wpa_s);
4190 return wpas_p2p_find(wpa_s, timeout, type, _dev_type != NULL, _dev_type,
4191 _dev_id, search_delay);
4195 static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd,
4196 char *buf, size_t buflen)
4201 enum p2p_wps_method wps_method;
4204 int persistent_group, persistent_id = -1;
4213 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad]
4214 * [persistent|persistent=<network id>]
4215 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
4218 if (hwaddr_aton(cmd, addr))
4226 persistent_group = os_strstr(pos, " persistent") != NULL;
4227 pos2 = os_strstr(pos, " persistent=");
4229 struct wpa_ssid *ssid;
4230 persistent_id = atoi(pos2 + 12);
4231 ssid = wpa_config_get_network(wpa_s->conf, persistent_id);
4232 if (ssid == NULL || ssid->disabled != 2 ||
4233 ssid->mode != WPAS_MODE_P2P_GO) {
4234 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
4235 "SSID id=%d for persistent P2P group (GO)",
4240 join = os_strstr(pos, " join") != NULL;
4241 auth = os_strstr(pos, " auth") != NULL;
4242 automatic = os_strstr(pos, " auto") != NULL;
4243 pd = os_strstr(pos, " provdisc") != NULL;
4244 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
4245 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
4248 pos2 = os_strstr(pos, " go_intent=");
4251 go_intent = atoi(pos2);
4252 if (go_intent < 0 || go_intent > 15)
4256 pos2 = os_strstr(pos, " freq=");
4264 if (os_strncmp(pos, "pin", 3) == 0) {
4265 /* Request random PIN (to be displayed) and enable the PIN */
4266 wps_method = WPS_PIN_DISPLAY;
4267 } else if (os_strncmp(pos, "pbc", 3) == 0) {
4268 wps_method = WPS_PBC;
4271 pos = os_strchr(pin, ' ');
4272 wps_method = WPS_PIN_KEYPAD;
4275 if (os_strncmp(pos, "display", 7) == 0)
4276 wps_method = WPS_PIN_DISPLAY;
4278 if (!wps_pin_str_valid(pin)) {
4279 os_memcpy(buf, "FAIL-INVALID-PIN\n", 17);
4284 new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method,
4285 persistent_group, automatic, join,
4286 auth, go_intent, freq, persistent_id, pd,
4288 if (new_pin == -2) {
4289 os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
4292 if (new_pin == -3) {
4293 os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
4298 if (wps_method == WPS_PIN_DISPLAY && pin == NULL) {
4299 ret = os_snprintf(buf, buflen, "%08d", new_pin);
4300 if (ret < 0 || (size_t) ret >= buflen)
4305 os_memcpy(buf, "OK\n", 3);
4310 static int p2p_ctrl_listen(struct wpa_supplicant *wpa_s, char *cmd)
4312 unsigned int timeout = atoi(cmd);
4313 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
4314 wpa_dbg(wpa_s, MSG_INFO,
4315 "Reject P2P_LISTEN since interface is disabled");
4318 return wpas_p2p_listen(wpa_s, timeout);
4322 static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd)
4326 enum wpas_p2p_prov_disc_use use = WPAS_P2P_PD_FOR_GO_NEG;
4328 /* <addr> <config method> [join|auto] */
4330 if (hwaddr_aton(cmd, addr))
4338 if (os_strstr(pos, " join") != NULL)
4339 use = WPAS_P2P_PD_FOR_JOIN;
4340 else if (os_strstr(pos, " auto") != NULL)
4341 use = WPAS_P2P_PD_AUTO;
4343 return wpas_p2p_prov_disc(wpa_s, addr, pos, use);
4347 static int p2p_get_passphrase(struct wpa_supplicant *wpa_s, char *buf,
4350 struct wpa_ssid *ssid = wpa_s->current_ssid;
4352 if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO ||
4353 ssid->passphrase == NULL)
4356 os_strlcpy(buf, ssid->passphrase, buflen);
4357 return os_strlen(buf);
4361 static int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd,
4362 char *buf, size_t buflen)
4366 u8 dst_buf[ETH_ALEN], *dst;
4367 struct wpabuf *tlvs;
4371 if (hwaddr_aton(cmd, dst_buf))
4374 if (dst[0] == 0 && dst[1] == 0 && dst[2] == 0 &&
4375 dst[3] == 0 && dst[4] == 0 && dst[5] == 0)
4382 if (os_strncmp(pos, "upnp ", 5) == 0) {
4385 if (hexstr2bin(pos, &version, 1) < 0)
4391 ref = wpas_p2p_sd_request_upnp(wpa_s, dst, version, pos);
4392 #ifdef CONFIG_WIFI_DISPLAY
4393 } else if (os_strncmp(pos, "wifi-display ", 13) == 0) {
4394 ref = wpas_p2p_sd_request_wifi_display(wpa_s, dst, pos + 13);
4395 #endif /* CONFIG_WIFI_DISPLAY */
4397 len = os_strlen(pos);
4401 tlvs = wpabuf_alloc(len);
4404 if (hexstr2bin(pos, wpabuf_put(tlvs, len), len) < 0) {
4409 ref = wpas_p2p_sd_request(wpa_s, dst, tlvs);
4414 res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref);
4415 if (res < 0 || (unsigned) res >= buflen)
4421 static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s,
4424 long long unsigned val;
4426 if (sscanf(cmd, "%llx", &val) != 1)
4429 return wpas_p2p_sd_cancel_request(wpa_s, req);
4433 static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant *wpa_s, char *cmd)
4438 struct wpabuf *resp_tlvs;
4442 pos = os_strchr(cmd, ' ');
4450 if (hwaddr_aton(pos, dst))
4457 pos2 = os_strchr(pos, ' ');
4461 dialog_token = atoi(pos);
4463 len = os_strlen(pos2);
4467 resp_tlvs = wpabuf_alloc(len);
4468 if (resp_tlvs == NULL)
4470 if (hexstr2bin(pos2, wpabuf_put(resp_tlvs, len), len) < 0) {
4471 wpabuf_free(resp_tlvs);
4475 wpas_p2p_sd_response(wpa_s, freq, dst, dialog_token, resp_tlvs);
4476 wpabuf_free(resp_tlvs);
4481 static int p2p_ctrl_serv_disc_external(struct wpa_supplicant *wpa_s,
4484 if (os_strcmp(cmd, "0") && os_strcmp(cmd, "1"))
4486 wpa_s->p2p_sd_over_ctrl_iface = atoi(cmd);
4491 static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant *wpa_s,
4496 struct wpabuf *query, *resp;
4498 pos = os_strchr(cmd, ' ');
4503 len = os_strlen(cmd);
4507 query = wpabuf_alloc(len);
4510 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
4515 len = os_strlen(pos);
4521 resp = wpabuf_alloc(len);
4526 if (hexstr2bin(pos, wpabuf_put(resp, len), len) < 0) {
4532 if (wpas_p2p_service_add_bonjour(wpa_s, query, resp) < 0) {
4541 static int p2p_ctrl_service_add_upnp(struct wpa_supplicant *wpa_s, char *cmd)
4546 pos = os_strchr(cmd, ' ');
4551 if (hexstr2bin(cmd, &version, 1) < 0)
4554 return wpas_p2p_service_add_upnp(wpa_s, version, pos);
4558 static int p2p_ctrl_service_add(struct wpa_supplicant *wpa_s, char *cmd)
4562 pos = os_strchr(cmd, ' ');
4567 if (os_strcmp(cmd, "bonjour") == 0)
4568 return p2p_ctrl_service_add_bonjour(wpa_s, pos);
4569 if (os_strcmp(cmd, "upnp") == 0)
4570 return p2p_ctrl_service_add_upnp(wpa_s, pos);
4571 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
4576 static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant *wpa_s,
4580 struct wpabuf *query;
4583 len = os_strlen(cmd);
4587 query = wpabuf_alloc(len);
4590 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
4595 ret = wpas_p2p_service_del_bonjour(wpa_s, query);
4601 static int p2p_ctrl_service_del_upnp(struct wpa_supplicant *wpa_s, char *cmd)
4606 pos = os_strchr(cmd, ' ');
4611 if (hexstr2bin(cmd, &version, 1) < 0)
4614 return wpas_p2p_service_del_upnp(wpa_s, version, pos);
4618 static int p2p_ctrl_service_del(struct wpa_supplicant *wpa_s, char *cmd)
4622 pos = os_strchr(cmd, ' ');
4627 if (os_strcmp(cmd, "bonjour") == 0)
4628 return p2p_ctrl_service_del_bonjour(wpa_s, pos);
4629 if (os_strcmp(cmd, "upnp") == 0)
4630 return p2p_ctrl_service_del_upnp(wpa_s, pos);
4631 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
4636 static int p2p_ctrl_reject(struct wpa_supplicant *wpa_s, char *cmd)
4642 if (hwaddr_aton(cmd, addr))
4645 return wpas_p2p_reject(wpa_s, addr);
4649 static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd)
4653 struct wpa_ssid *ssid;
4654 u8 *_peer = NULL, peer[ETH_ALEN];
4655 int freq = 0, pref_freq = 0;
4659 pos = os_strstr(cmd, " peer=");
4662 if (hwaddr_aton(pos, peer))
4666 ssid = wpa_config_get_network(wpa_s->conf, id);
4667 if (ssid == NULL || ssid->disabled != 2) {
4668 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
4669 "for persistent P2P group",
4674 pos = os_strstr(cmd, " freq=");
4682 pos = os_strstr(cmd, " pref=");
4685 pref_freq = atoi(pos);
4690 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
4691 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
4694 return wpas_p2p_invite(wpa_s, _peer, ssid, NULL, freq, ht40, vht,
4699 static int p2p_ctrl_invite_group(struct wpa_supplicant *wpa_s, char *cmd)
4702 u8 peer[ETH_ALEN], go_dev_addr[ETH_ALEN], *go_dev = NULL;
4704 pos = os_strstr(cmd, " peer=");
4710 if (hwaddr_aton(pos, peer)) {
4711 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", pos);
4715 pos = os_strstr(pos, " go_dev_addr=");
4718 if (hwaddr_aton(pos, go_dev_addr)) {
4719 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'",
4723 go_dev = go_dev_addr;
4726 return wpas_p2p_invite_group(wpa_s, cmd, peer, go_dev);
4730 static int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd)
4732 if (os_strncmp(cmd, "persistent=", 11) == 0)
4733 return p2p_ctrl_invite_persistent(wpa_s, cmd + 11);
4734 if (os_strncmp(cmd, "group=", 6) == 0)
4735 return p2p_ctrl_invite_group(wpa_s, cmd + 6);
4741 static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s,
4742 char *cmd, int freq, int ht40,
4746 struct wpa_ssid *ssid;
4749 ssid = wpa_config_get_network(wpa_s->conf, id);
4750 if (ssid == NULL || ssid->disabled != 2) {
4751 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
4752 "for persistent P2P group",
4757 return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq, 0, ht40, vht,
4762 static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd)
4764 int freq = 0, ht40, vht;
4767 pos = os_strstr(cmd, "freq=");
4769 freq = atoi(pos + 5);
4771 vht = (os_strstr(cmd, "vht") != NULL) || wpa_s->conf->p2p_go_vht;
4772 ht40 = (os_strstr(cmd, "ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
4775 if (os_strncmp(cmd, "persistent=", 11) == 0)
4776 return p2p_ctrl_group_add_persistent(wpa_s, cmd + 11, freq,
4778 if (os_strcmp(cmd, "persistent") == 0 ||
4779 os_strncmp(cmd, "persistent ", 11) == 0)
4780 return wpas_p2p_group_add(wpa_s, 1, freq, ht40, vht);
4781 if (os_strncmp(cmd, "freq=", 5) == 0)
4782 return wpas_p2p_group_add(wpa_s, 0, freq, ht40, vht);
4784 return wpas_p2p_group_add(wpa_s, 0, freq, ht40, vht);
4786 wpa_printf(MSG_DEBUG, "CTRL: Invalid P2P_GROUP_ADD parameters '%s'",
4792 static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd,
4793 char *buf, size_t buflen)
4795 u8 addr[ETH_ALEN], *addr_ptr;
4797 const struct p2p_peer_info *info;
4799 char devtype[WPS_DEV_TYPE_BUFSIZE];
4800 struct wpa_ssid *ssid;
4803 if (!wpa_s->global->p2p)
4806 if (os_strcmp(cmd, "FIRST") == 0) {
4809 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
4810 if (hwaddr_aton(cmd + 5, addr) < 0)
4815 if (hwaddr_aton(cmd, addr) < 0)
4821 info = p2p_get_peer_info(wpa_s->global->p2p, addr_ptr, next);
4828 res = os_snprintf(pos, end - pos, MACSTR "\n"
4834 "serial_number=%s\n"
4835 "config_methods=0x%x\n"
4837 "group_capab=0x%x\n"
4839 MAC2STR(info->p2p_device_addr),
4840 wps_dev_type_bin2str(info->pri_dev_type,
4841 devtype, sizeof(devtype)),
4846 info->serial_number,
4847 info->config_methods,
4851 if (res < 0 || res >= end - pos)
4855 for (i = 0; i < info->wps_sec_dev_type_list_len / WPS_DEV_TYPE_LEN; i++)
4858 t = &info->wps_sec_dev_type_list[i * WPS_DEV_TYPE_LEN];
4859 res = os_snprintf(pos, end - pos, "sec_dev_type=%s\n",
4860 wps_dev_type_bin2str(t, devtype,
4862 if (res < 0 || res >= end - pos)
4867 ssid = wpas_p2p_get_persistent(wpa_s, info->p2p_device_addr, NULL, 0);
4869 res = os_snprintf(pos, end - pos, "persistent=%d\n", ssid->id);
4870 if (res < 0 || res >= end - pos)
4875 res = p2p_get_peer_info_txt(info, pos, end - pos);
4880 if (info->vendor_elems) {
4881 res = os_snprintf(pos, end - pos, "vendor_elems=");
4882 if (res < 0 || res >= end - pos)
4886 pos += wpa_snprintf_hex(pos, end - pos,
4887 wpabuf_head(info->vendor_elems),
4888 wpabuf_len(info->vendor_elems));
4890 res = os_snprintf(pos, end - pos, "\n");
4891 if (res < 0 || res >= end - pos)
4900 static int p2p_ctrl_disallow_freq(struct wpa_supplicant *wpa_s,
4905 if (wpa_s->global->p2p == NULL)
4908 if (freq_range_list_parse(&wpa_s->global->p2p_disallow_freq, param) < 0)
4911 for (i = 0; i < wpa_s->global->p2p_disallow_freq.num; i++) {
4912 struct wpa_freq_range *freq;
4913 freq = &wpa_s->global->p2p_disallow_freq.range[i];
4914 wpa_printf(MSG_DEBUG, "P2P: Disallowed frequency range %u-%u",
4915 freq->min, freq->max);
4918 wpas_p2p_update_channel_list(wpa_s);
4923 static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd)
4927 if (wpa_s->global->p2p == NULL)
4930 param = os_strchr(cmd, ' ');
4935 if (os_strcmp(cmd, "discoverability") == 0) {
4936 p2p_set_client_discoverability(wpa_s->global->p2p,
4941 if (os_strcmp(cmd, "managed") == 0) {
4942 p2p_set_managed_oper(wpa_s->global->p2p, atoi(param));
4946 if (os_strcmp(cmd, "listen_channel") == 0) {
4947 return p2p_set_listen_channel(wpa_s->global->p2p, 81,
4951 if (os_strcmp(cmd, "ssid_postfix") == 0) {
4952 return p2p_set_ssid_postfix(wpa_s->global->p2p, (u8 *) param,
4956 if (os_strcmp(cmd, "noa") == 0) {
4958 int count, start, duration;
4959 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
4960 count = atoi(param);
4961 pos = os_strchr(param, ',');
4966 pos = os_strchr(pos, ',');
4970 duration = atoi(pos);
4971 if (count < 0 || count > 255 || start < 0 || duration < 0)
4973 if (count == 0 && duration > 0)
4975 wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
4976 "start=%d duration=%d", count, start, duration);
4977 return wpas_p2p_set_noa(wpa_s, count, start, duration);
4980 if (os_strcmp(cmd, "ps") == 0)
4981 return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1);
4983 if (os_strcmp(cmd, "oppps") == 0)
4984 return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1);
4986 if (os_strcmp(cmd, "ctwindow") == 0)
4987 return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param));
4989 if (os_strcmp(cmd, "disabled") == 0) {
4990 wpa_s->global->p2p_disabled = atoi(param);
4991 wpa_printf(MSG_DEBUG, "P2P functionality %s",
4992 wpa_s->global->p2p_disabled ?
4993 "disabled" : "enabled");
4994 if (wpa_s->global->p2p_disabled) {
4995 wpas_p2p_stop_find(wpa_s);
4996 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
4997 p2p_flush(wpa_s->global->p2p);
5002 if (os_strcmp(cmd, "conc_pref") == 0) {
5003 if (os_strcmp(param, "sta") == 0)
5004 wpa_s->global->conc_pref = WPA_CONC_PREF_STA;
5005 else if (os_strcmp(param, "p2p") == 0)
5006 wpa_s->global->conc_pref = WPA_CONC_PREF_P2P;
5008 wpa_printf(MSG_INFO, "Invalid conc_pref value");
5011 wpa_printf(MSG_DEBUG, "Single channel concurrency preference: "
5016 if (os_strcmp(cmd, "force_long_sd") == 0) {
5017 wpa_s->force_long_sd = atoi(param);
5021 if (os_strcmp(cmd, "peer_filter") == 0) {
5023 if (hwaddr_aton(param, addr))
5025 p2p_set_peer_filter(wpa_s->global->p2p, addr);
5029 if (os_strcmp(cmd, "cross_connect") == 0)
5030 return wpas_p2p_set_cross_connect(wpa_s, atoi(param));
5032 if (os_strcmp(cmd, "go_apsd") == 0) {
5033 if (os_strcmp(param, "disable") == 0)
5034 wpa_s->set_ap_uapsd = 0;
5036 wpa_s->set_ap_uapsd = 1;
5037 wpa_s->ap_uapsd = atoi(param);
5042 if (os_strcmp(cmd, "client_apsd") == 0) {
5043 if (os_strcmp(param, "disable") == 0)
5044 wpa_s->set_sta_uapsd = 0;
5048 /* format: BE,BK,VI,VO;max SP Length */
5050 pos = os_strchr(param, ',');
5055 pos = os_strchr(pos, ',');
5060 pos = os_strchr(pos, ',');
5065 /* ignore max SP Length for now */
5067 wpa_s->set_sta_uapsd = 1;
5068 wpa_s->sta_uapsd = 0;
5070 wpa_s->sta_uapsd |= BIT(0);
5072 wpa_s->sta_uapsd |= BIT(1);
5074 wpa_s->sta_uapsd |= BIT(2);
5076 wpa_s->sta_uapsd |= BIT(3);
5081 if (os_strcmp(cmd, "disallow_freq") == 0)
5082 return p2p_ctrl_disallow_freq(wpa_s, param);
5084 if (os_strcmp(cmd, "disc_int") == 0) {
5085 int min_disc_int, max_disc_int, max_disc_tu;
5090 min_disc_int = atoi(pos);
5091 pos = os_strchr(pos, ' ');
5096 max_disc_int = atoi(pos);
5097 pos = os_strchr(pos, ' ');
5102 max_disc_tu = atoi(pos);
5104 return p2p_set_disc_int(wpa_s->global->p2p, min_disc_int,
5105 max_disc_int, max_disc_tu);
5108 if (os_strcmp(cmd, "per_sta_psk") == 0) {
5109 wpa_s->global->p2p_per_sta_psk = !!atoi(param);
5113 #ifdef CONFIG_WPS_NFC
5114 if (os_strcmp(cmd, "nfc_tag") == 0)
5115 return wpas_p2p_nfc_tag_enabled(wpa_s, !!atoi(param));
5116 #endif /* CONFIG_WPS_NFC */
5118 if (os_strcmp(cmd, "disable_ip_addr_req") == 0) {
5119 wpa_s->p2p_disable_ip_addr_req = !!atoi(param);
5123 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
5130 static void p2p_ctrl_flush(struct wpa_supplicant *wpa_s)
5132 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
5133 wpa_s->force_long_sd = 0;
5134 wpas_p2p_stop_find(wpa_s);
5135 if (wpa_s->global->p2p)
5136 p2p_flush(wpa_s->global->p2p);
5140 static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd)
5143 unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0;
5146 pos = os_strchr(cmd, ' ');
5152 pos2 = os_strchr(pos, ' ');
5160 pos = os_strchr(pos2, ' ');
5168 return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2);
5172 static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd)
5175 unsigned int period = 0, interval = 0;
5178 pos = os_strchr(cmd, ' ');
5183 interval = atoi(pos);
5186 return wpas_p2p_ext_listen(wpa_s, period, interval);
5190 static int p2p_ctrl_remove_client(struct wpa_supplicant *wpa_s, const char *cmd)
5197 if (os_strncmp(pos, "iface=", 6) == 0) {
5201 if (hwaddr_aton(pos, peer))
5204 wpas_p2p_remove_client(wpa_s, peer, iface_addr);
5208 #endif /* CONFIG_P2P */
5211 static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s, char *val)
5213 struct wpa_freq_range_list ranges;
5215 struct hostapd_hw_modes *mode;
5218 if (wpa_s->hw.modes == NULL)
5221 os_memset(&ranges, 0, sizeof(ranges));
5222 if (freq_range_list_parse(&ranges, val) < 0)
5225 for (i = 0; i < wpa_s->hw.num_modes; i++) {
5228 mode = &wpa_s->hw.modes[i];
5229 for (j = 0; j < mode->num_channels; j++) {
5232 if (mode->channels[j].flag & HOSTAPD_CHAN_DISABLED)
5235 freq = mode->channels[j].freq;
5236 if (!freq_range_list_includes(&ranges, freq))
5239 int_array_add_unique(&freqs, freq);
5243 os_free(ranges.range);
5248 #ifdef CONFIG_INTERWORKING
5250 static int ctrl_interworking_select(struct wpa_supplicant *wpa_s, char *param)
5258 auto_sel = os_strstr(param, "auto") != NULL;
5260 pos = os_strstr(param, "freq=");
5262 freqs = freq_range_to_channel_list(wpa_s, pos + 5);
5269 return interworking_select(wpa_s, auto_sel, freqs);
5273 static int ctrl_interworking_connect(struct wpa_supplicant *wpa_s, char *dst)
5276 struct wpa_bss *bss;
5278 if (hwaddr_aton(dst, bssid)) {
5279 wpa_printf(MSG_DEBUG, "Invalid BSSID '%s'", dst);
5283 bss = wpa_bss_get_bssid(wpa_s, bssid);
5285 wpa_printf(MSG_DEBUG, "Could not find BSS " MACSTR,
5290 return interworking_connect(wpa_s, bss);
5294 static int get_anqp(struct wpa_supplicant *wpa_s, char *dst)
5296 u8 dst_addr[ETH_ALEN];
5299 #define MAX_ANQP_INFO_ID 100
5300 u16 id[MAX_ANQP_INFO_ID];
5304 used = hwaddr_aton2(dst, dst_addr);
5308 while (num_id < MAX_ANQP_INFO_ID) {
5309 if (os_strncmp(pos, "hs20:", 5) == 0) {
5311 int num = atoi(pos + 5);
5312 if (num <= 0 || num > 31)
5314 subtypes |= BIT(num);
5315 #else /* CONFIG_HS20 */
5317 #endif /* CONFIG_HS20 */
5319 id[num_id] = atoi(pos);
5323 pos = os_strchr(pos + 1, ',');
5332 return anqp_send_req(wpa_s, dst_addr, id, num_id, subtypes);
5336 static int gas_request(struct wpa_supplicant *wpa_s, char *cmd)
5338 u8 dst_addr[ETH_ALEN];
5339 struct wpabuf *advproto, *query = NULL;
5344 used = hwaddr_aton2(cmd, dst_addr);
5352 /* Advertisement Protocol ID */
5353 end = os_strchr(pos, ' ');
5357 len = os_strlen(pos);
5363 advproto = wpabuf_alloc(len);
5364 if (advproto == NULL)
5366 if (hexstr2bin(pos, wpabuf_put(advproto, len), len) < 0)
5370 /* Optional Query Request */
5375 len = os_strlen(pos);
5382 query = wpabuf_alloc(len);
5385 if (hexstr2bin(pos, wpabuf_put(query, len), len) < 0)
5390 ret = gas_send_request(wpa_s, dst_addr, advproto, query);
5393 wpabuf_free(advproto);
5400 static int gas_response_get(struct wpa_supplicant *wpa_s, char *cmd, char *buf,
5407 size_t resp_len, start, requested_len;
5408 struct wpabuf *resp;
5411 used = hwaddr_aton2(cmd, addr);
5418 dialog_token = atoi(pos);
5420 if (wpa_s->last_gas_resp &&
5421 os_memcmp(addr, wpa_s->last_gas_addr, ETH_ALEN) == 0 &&
5422 dialog_token == wpa_s->last_gas_dialog_token)
5423 resp = wpa_s->last_gas_resp;
5424 else if (wpa_s->prev_gas_resp &&
5425 os_memcmp(addr, wpa_s->prev_gas_addr, ETH_ALEN) == 0 &&
5426 dialog_token == wpa_s->prev_gas_dialog_token)
5427 resp = wpa_s->prev_gas_resp;
5431 resp_len = wpabuf_len(resp);
5433 requested_len = resp_len;
5435 pos = os_strchr(pos, ' ');
5438 if (start > resp_len)
5439 return os_snprintf(buf, buflen, "FAIL-Invalid range");
5440 pos = os_strchr(pos, ',');
5444 requested_len = atoi(pos);
5445 if (start + requested_len > resp_len)
5446 return os_snprintf(buf, buflen, "FAIL-Invalid range");
5449 if (requested_len * 2 + 1 > buflen)
5450 return os_snprintf(buf, buflen, "FAIL-Too long response");
5452 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(resp) + start,
5455 if (start + requested_len == resp_len) {
5457 * Free memory by dropping the response after it has been
5460 if (resp == wpa_s->prev_gas_resp) {
5461 wpabuf_free(wpa_s->prev_gas_resp);
5462 wpa_s->prev_gas_resp = NULL;
5464 wpabuf_free(wpa_s->last_gas_resp);
5465 wpa_s->last_gas_resp = NULL;
5471 #endif /* CONFIG_INTERWORKING */
5476 static int get_hs20_anqp(struct wpa_supplicant *wpa_s, char *dst)
5478 u8 dst_addr[ETH_ALEN];
5483 used = hwaddr_aton2(dst, dst_addr);
5488 int num = atoi(pos);
5489 if (num <= 0 || num > 31)
5491 subtypes |= BIT(num);
5492 pos = os_strchr(pos + 1, ',');
5501 return hs20_anqp_send_req(wpa_s, dst_addr, subtypes, NULL, 0);
5505 static int hs20_nai_home_realm_list(struct wpa_supplicant *wpa_s,
5506 const u8 *addr, const char *realm)
5512 rlen = os_strlen(realm);
5514 buf = os_malloc(len);
5517 buf[0] = 1; /* NAI Home Realm Count */
5518 buf[1] = 0; /* Formatted in accordance with RFC 4282 */
5520 os_memcpy(buf + 3, realm, rlen);
5522 ret = hs20_anqp_send_req(wpa_s, addr,
5523 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
5532 static int hs20_get_nai_home_realm_list(struct wpa_supplicant *wpa_s,
5535 struct wpa_cred *cred = wpa_s->conf->cred;
5536 u8 dst_addr[ETH_ALEN];
5542 used = hwaddr_aton2(dst, dst_addr);
5546 while (dst[used] == ' ')
5548 if (os_strncmp(dst + used, "realm=", 6) == 0)
5549 return hs20_nai_home_realm_list(wpa_s, dst_addr,
5552 len = os_strlen(dst + used);
5554 if (len == 0 && cred && cred->realm)
5555 return hs20_nai_home_realm_list(wpa_s, dst_addr, cred->realm);
5560 buf = os_malloc(len);
5563 if (hexstr2bin(dst + used, buf, len) < 0) {
5568 ret = hs20_anqp_send_req(wpa_s, dst_addr,
5569 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
5577 static int hs20_icon_request(struct wpa_supplicant *wpa_s, char *cmd)
5579 u8 dst_addr[ETH_ALEN];
5583 used = hwaddr_aton2(cmd, dst_addr);
5587 while (cmd[used] == ' ')
5591 wpa_s->fetch_osu_icon_in_progress = 0;
5592 return hs20_anqp_send_req(wpa_s, dst_addr, BIT(HS20_STYPE_ICON_REQUEST),
5593 (u8 *) icon, os_strlen(icon));
5596 #endif /* CONFIG_HS20 */
5599 static int wpa_supplicant_ctrl_iface_sta_autoconnect(
5600 struct wpa_supplicant *wpa_s, char *cmd)
5602 wpa_s->auto_reconnect_disabled = atoi(cmd) == 0 ? 1 : 0;
5607 #ifdef CONFIG_AUTOSCAN
5609 static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant *wpa_s,
5612 enum wpa_states state = wpa_s->wpa_state;
5613 char *new_params = NULL;
5615 if (os_strlen(cmd) > 0) {
5616 new_params = os_strdup(cmd);
5617 if (new_params == NULL)
5621 os_free(wpa_s->conf->autoscan);
5622 wpa_s->conf->autoscan = new_params;
5624 if (wpa_s->conf->autoscan == NULL)
5625 autoscan_deinit(wpa_s);
5626 else if (state == WPA_DISCONNECTED || state == WPA_INACTIVE)
5627 autoscan_init(wpa_s, 1);
5628 else if (state == WPA_SCANNING)
5629 wpa_supplicant_reinit_autoscan(wpa_s);
5634 #endif /* CONFIG_AUTOSCAN */
5639 static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant *wpa_s, char *cmd)
5645 struct wpabuf *tfs_req = NULL;
5647 if (os_strncmp(cmd, "enter", 5) == 0)
5649 else if (os_strncmp(cmd, "exit", 4) == 0)
5654 pos = os_strstr(cmd, " interval=");
5656 intval = atoi(pos + 10);
5658 pos = os_strstr(cmd, " tfs_req=");
5663 end = os_strchr(pos, ' ');
5667 len = os_strlen(pos);
5671 tfs_req = wpabuf_alloc(len);
5672 if (tfs_req == NULL)
5674 if (hexstr2bin(pos, wpabuf_put(tfs_req, len), len) < 0) {
5675 wpabuf_free(tfs_req);
5680 ret = ieee802_11_send_wnmsleep_req(wpa_s, enter ? WNM_SLEEP_MODE_ENTER :
5681 WNM_SLEEP_MODE_EXIT, intval,
5683 wpabuf_free(tfs_req);
5689 static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant *wpa_s, char *cmd)
5693 query_reason = atoi(cmd);
5695 wpa_printf(MSG_DEBUG, "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d",
5698 return wnm_send_bss_transition_mgmt_query(wpa_s, query_reason);
5701 #endif /* CONFIG_WNM */
5704 static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf,
5707 struct wpa_signal_info si;
5711 ret = wpa_drv_signal_poll(wpa_s, &si);
5718 ret = os_snprintf(pos, end - pos, "RSSI=%d\nLINKSPEED=%d\n"
5719 "NOISE=%d\nFREQUENCY=%u\n",
5720 si.current_signal, si.current_txrate / 1000,
5721 si.current_noise, si.frequency);
5722 if (ret < 0 || ret > end - pos)
5726 if (si.chanwidth != CHAN_WIDTH_UNKNOWN) {
5727 ret = os_snprintf(pos, end - pos, "WIDTH=%s\n",
5728 channel_width_to_string(si.chanwidth));
5729 if (ret < 0 || ret > end - pos)
5734 if (si.center_frq1 > 0 && si.center_frq2 > 0) {
5735 ret = os_snprintf(pos, end - pos,
5736 "CENTER_FRQ1=%d\nCENTER_FRQ2=%d\n",
5737 si.center_frq1, si.center_frq2);
5738 if (ret < 0 || ret > end - pos)
5743 if (si.avg_signal) {
5744 ret = os_snprintf(pos, end - pos,
5745 "AVG_RSSI=%d\n", si.avg_signal);
5746 if (ret < 0 || ret >= end - pos)
5755 static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant *wpa_s, char *buf,
5758 struct hostap_sta_driver_data sta;
5761 ret = wpa_drv_pktcnt_poll(wpa_s, &sta);
5765 ret = os_snprintf(buf, buflen, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
5766 sta.tx_packets, sta.tx_retry_failed, sta.rx_packets);
5767 if (ret < 0 || (size_t) ret > buflen)
5774 static int wpa_supplicant_driver_cmd(struct wpa_supplicant *wpa_s, char *cmd,
5775 char *buf, size_t buflen)
5779 ret = wpa_drv_driver_cmd(wpa_s, cmd, buf, buflen);
5781 if (os_strncasecmp(cmd, "COUNTRY", 7) == 0) {
5782 struct p2p_data *p2p = wpa_s->global->p2p;
5785 country[0] = cmd[8];
5786 country[1] = cmd[9];
5788 p2p_set_country(p2p, country);
5791 ret = os_snprintf(buf, buflen, "%s\n", "OK");
5795 #endif /* ANDROID */
5798 static int wpa_supplicant_vendor_cmd(struct wpa_supplicant *wpa_s, char *cmd,
5799 char *buf, size_t buflen)
5804 unsigned int vendor_id, subcmd;
5805 struct wpabuf *reply;
5806 size_t data_len = 0;
5808 /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */
5809 vendor_id = strtoul(cmd, &pos, 16);
5813 subcmd = strtoul(pos, &pos, 10);
5816 if (!isblank(*pos++))
5818 data_len = os_strlen(pos);
5823 data = os_malloc(data_len);
5827 if (hexstr2bin(pos, data, data_len)) {
5828 wpa_printf(MSG_DEBUG,
5829 "Vendor command: wrong parameter format");
5835 reply = wpabuf_alloc((buflen - 1) / 2);
5841 ret = wpa_drv_vendor_cmd(wpa_s, vendor_id, subcmd, data, data_len,
5845 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(reply),
5855 static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s)
5857 wpa_dbg(wpa_s, MSG_DEBUG, "Flush all wpa_supplicant state");
5860 wpas_p2p_cancel(wpa_s);
5861 wpas_p2p_stop_find(wpa_s);
5862 p2p_ctrl_flush(wpa_s);
5863 wpas_p2p_group_remove(wpa_s, "*");
5864 wpas_p2p_service_flush(wpa_s);
5865 wpa_s->global->p2p_disabled = 0;
5866 wpa_s->global->p2p_per_sta_psk = 0;
5867 wpa_s->conf->num_sec_device_types = 0;
5868 wpa_s->p2p_disable_ip_addr_req = 0;
5869 os_free(wpa_s->global->p2p_go_avoid_freq.range);
5870 wpa_s->global->p2p_go_avoid_freq.range = NULL;
5871 #endif /* CONFIG_P2P */
5873 #ifdef CONFIG_WPS_TESTING
5874 wps_version_number = 0x20;
5875 wps_testing_dummy_cred = 0;
5876 wps_corrupt_pkhash = 0;
5877 #endif /* CONFIG_WPS_TESTING */
5879 wpa_s->wps_fragment_size = 0;
5880 wpas_wps_cancel(wpa_s);
5881 #endif /* CONFIG_WPS */
5882 wpa_s->after_wps = 0;
5883 wpa_s->known_wps_freq = 0;
5886 #ifdef CONFIG_TDLS_TESTING
5887 extern unsigned int tdls_testing;
5889 #endif /* CONFIG_TDLS_TESTING */
5890 wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL);
5891 wpa_tdls_enable(wpa_s->wpa, 1);
5892 #endif /* CONFIG_TDLS */
5894 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, wpa_s, NULL);
5895 wpa_supplicant_stop_countermeasures(wpa_s, NULL);
5897 wpa_s->no_keep_alive = 0;
5899 os_free(wpa_s->disallow_aps_bssid);
5900 wpa_s->disallow_aps_bssid = NULL;
5901 wpa_s->disallow_aps_bssid_count = 0;
5902 os_free(wpa_s->disallow_aps_ssid);
5903 wpa_s->disallow_aps_ssid = NULL;
5904 wpa_s->disallow_aps_ssid_count = 0;
5906 wpa_s->set_sta_uapsd = 0;
5907 wpa_s->sta_uapsd = 0;
5909 wpa_drv_radio_disable(wpa_s, 0);
5911 wpa_bss_flush(wpa_s);
5912 wpa_blacklist_clear(wpa_s);
5913 wpa_s->extra_blacklist_count = 0;
5914 wpa_supplicant_ctrl_iface_remove_network(wpa_s, "all");
5915 wpa_supplicant_ctrl_iface_remove_cred(wpa_s, "all");
5916 wpa_config_flush_blobs(wpa_s->conf);
5917 wpa_s->conf->auto_interworking = 0;
5918 wpa_s->conf->okc = 0;
5920 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, 43200);
5921 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, 70);
5922 wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, 60);
5923 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
5925 radio_remove_works(wpa_s, NULL, 1);
5927 wpa_s->next_ssid = NULL;
5929 #ifdef CONFIG_INTERWORKING
5930 hs20_cancel_fetch_osu(wpa_s);
5931 #endif /* CONFIG_INTERWORKING */
5933 wpa_s->ext_mgmt_frame_handling = 0;
5934 wpa_s->ext_eapol_frame_io = 0;
5935 #ifdef CONFIG_TESTING_OPTIONS
5936 wpa_s->extra_roc_dur = 0;
5937 #endif /* CONFIG_TESTING_OPTIONS */
5941 static int wpas_ctrl_radio_work_show(struct wpa_supplicant *wpa_s,
5942 char *buf, size_t buflen)
5944 struct wpa_radio_work *work;
5946 struct os_reltime now, diff;
5951 os_get_reltime(&now);
5953 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
5957 os_reltime_sub(&now, &work->time, &diff);
5958 ret = os_snprintf(pos, end - pos, "%s@%s:%u:%u:%ld.%06ld\n",
5959 work->type, work->wpa_s->ifname, work->freq,
5960 work->started, diff.sec, diff.usec);
5961 if (ret < 0 || ret >= end - pos)
5970 static void wpas_ctrl_radio_work_timeout(void *eloop_ctx, void *timeout_ctx)
5972 struct wpa_radio_work *work = eloop_ctx;
5973 struct wpa_external_work *ework = work->ctx;
5975 wpa_dbg(work->wpa_s, MSG_DEBUG,
5976 "Timing out external radio work %u (%s)",
5977 ework->id, work->type);
5978 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_TIMEOUT "%u", ework->id);
5979 radio_work_done(work);
5984 static void wpas_ctrl_radio_work_cb(struct wpa_radio_work *work, int deinit)
5986 struct wpa_external_work *ework = work->ctx;
5990 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
5997 wpa_dbg(work->wpa_s, MSG_DEBUG, "Starting external radio work %u (%s)",
5998 ework->id, ework->type);
5999 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_START "%u", ework->id);
6000 if (!ework->timeout)
6001 ework->timeout = 10;
6002 eloop_register_timeout(ework->timeout, 0, wpas_ctrl_radio_work_timeout,
6007 static int wpas_ctrl_radio_work_add(struct wpa_supplicant *wpa_s, char *cmd,
6008 char *buf, size_t buflen)
6010 struct wpa_external_work *ework;
6014 unsigned int freq = 0;
6016 /* format: <name> [freq=<MHz>] [timeout=<seconds>] */
6018 ework = os_zalloc(sizeof(*ework));
6022 pos = os_strchr(cmd, ' ');
6024 type_len = pos - cmd;
6027 pos2 = os_strstr(pos, "freq=");
6029 freq = atoi(pos2 + 5);
6031 pos2 = os_strstr(pos, "timeout=");
6033 ework->timeout = atoi(pos2 + 8);
6035 type_len = os_strlen(cmd);
6037 if (4 + type_len >= sizeof(ework->type))
6038 type_len = sizeof(ework->type) - 4 - 1;
6039 os_strlcpy(ework->type, "ext:", sizeof(ework->type));
6040 os_memcpy(ework->type + 4, cmd, type_len);
6041 ework->type[4 + type_len] = '\0';
6043 wpa_s->ext_work_id++;
6044 if (wpa_s->ext_work_id == 0)
6045 wpa_s->ext_work_id++;
6046 ework->id = wpa_s->ext_work_id;
6048 if (radio_add_work(wpa_s, freq, ework->type, 0, wpas_ctrl_radio_work_cb,
6054 ret = os_snprintf(buf, buflen, "%u", ework->id);
6055 if (ret < 0 || (size_t) ret >= buflen)
6061 static int wpas_ctrl_radio_work_done(struct wpa_supplicant *wpa_s, char *cmd)
6063 struct wpa_radio_work *work;
6064 unsigned int id = atoi(cmd);
6066 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
6068 struct wpa_external_work *ework;
6070 if (os_strncmp(work->type, "ext:", 4) != 0)
6073 if (id && ework->id != id)
6075 wpa_dbg(wpa_s, MSG_DEBUG,
6076 "Completed external radio work %u (%s)",
6077 ework->id, ework->type);
6078 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, work, NULL);
6079 radio_work_done(work);
6081 return 3; /* "OK\n" */
6088 static int wpas_ctrl_radio_work(struct wpa_supplicant *wpa_s, char *cmd,
6089 char *buf, size_t buflen)
6091 if (os_strcmp(cmd, "show") == 0)
6092 return wpas_ctrl_radio_work_show(wpa_s, buf, buflen);
6093 if (os_strncmp(cmd, "add ", 4) == 0)
6094 return wpas_ctrl_radio_work_add(wpa_s, cmd + 4, buf, buflen);
6095 if (os_strncmp(cmd, "done ", 5) == 0)
6096 return wpas_ctrl_radio_work_done(wpa_s, cmd + 4);
6101 void wpas_ctrl_radio_work_flush(struct wpa_supplicant *wpa_s)
6103 struct wpa_radio_work *work, *tmp;
6105 if (!wpa_s || !wpa_s->radio)
6108 dl_list_for_each_safe(work, tmp, &wpa_s->radio->work,
6109 struct wpa_radio_work, list) {
6110 struct wpa_external_work *ework;
6112 if (os_strncmp(work->type, "ext:", 4) != 0)
6115 wpa_dbg(wpa_s, MSG_DEBUG,
6116 "Flushing%s external radio work %u (%s)",
6117 work->started ? " started" : "", ework->id,
6120 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
6122 radio_work_done(work);
6128 static void wpas_ctrl_eapol_response(void *eloop_ctx, void *timeout_ctx)
6130 struct wpa_supplicant *wpa_s = eloop_ctx;
6131 eapol_sm_notify_ctrl_response(wpa_s->eapol);
6135 static int set_scan_freqs(struct wpa_supplicant *wpa_s, char *val)
6139 freqs = freq_range_to_channel_list(wpa_s, val);
6143 os_free(wpa_s->manual_scan_freqs);
6144 wpa_s->manual_scan_freqs = freqs;
6150 static int scan_id_list_parse(struct wpa_supplicant *wpa_s, const char *value)
6152 const char *pos = value;
6155 if (*pos == ' ' || *pos == '\0')
6157 if (wpa_s->scan_id_count == MAX_SCAN_ID)
6159 wpa_s->scan_id[wpa_s->scan_id_count++] = atoi(pos);
6160 pos = os_strchr(pos, ',');
6169 static void wpas_ctrl_scan(struct wpa_supplicant *wpa_s, char *params,
6170 char *reply, int reply_size, int *reply_len)
6174 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
6179 wpa_s->manual_scan_passive = 0;
6180 wpa_s->manual_scan_use_id = 0;
6181 wpa_s->manual_scan_only_new = 0;
6182 wpa_s->scan_id_count = 0;
6185 if (os_strncasecmp(params, "TYPE=ONLY", 9) == 0)
6186 wpa_s->scan_res_handler = scan_only_handler;
6188 pos = os_strstr(params, "freq=");
6189 if (pos && set_scan_freqs(wpa_s, pos + 5) < 0) {
6194 pos = os_strstr(params, "passive=");
6196 wpa_s->manual_scan_passive = !!atoi(pos + 8);
6198 pos = os_strstr(params, "use_id=");
6200 wpa_s->manual_scan_use_id = atoi(pos + 7);
6202 pos = os_strstr(params, "only_new=1");
6204 wpa_s->manual_scan_only_new = 1;
6206 pos = os_strstr(params, "scan_id=");
6207 if (pos && scan_id_list_parse(wpa_s, pos + 8) < 0) {
6212 os_free(wpa_s->manual_scan_freqs);
6213 wpa_s->manual_scan_freqs = NULL;
6214 if (wpa_s->scan_res_handler == scan_only_handler)
6215 wpa_s->scan_res_handler = NULL;
6218 if (!wpa_s->sched_scanning && !wpa_s->scanning &&
6219 ((wpa_s->wpa_state <= WPA_SCANNING) ||
6220 (wpa_s->wpa_state == WPA_COMPLETED))) {
6221 wpa_s->normal_scans = 0;
6222 wpa_s->scan_req = MANUAL_SCAN_REQ;
6223 wpa_s->after_wps = 0;
6224 wpa_s->known_wps_freq = 0;
6225 wpa_supplicant_req_scan(wpa_s, 0, 0);
6226 if (wpa_s->manual_scan_use_id) {
6227 wpa_s->manual_scan_id++;
6228 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
6229 wpa_s->manual_scan_id);
6230 *reply_len = os_snprintf(reply, reply_size, "%u\n",
6231 wpa_s->manual_scan_id);
6233 } else if (wpa_s->sched_scanning) {
6234 wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to allow requested full scan to proceed");
6235 wpa_supplicant_cancel_sched_scan(wpa_s);
6236 wpa_s->scan_req = MANUAL_SCAN_REQ;
6237 wpa_supplicant_req_scan(wpa_s, 0, 0);
6238 if (wpa_s->manual_scan_use_id) {
6239 wpa_s->manual_scan_id++;
6240 *reply_len = os_snprintf(reply, reply_size, "%u\n",
6241 wpa_s->manual_scan_id);
6242 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
6243 wpa_s->manual_scan_id);
6246 wpa_printf(MSG_DEBUG, "Ongoing scan action - reject new request");
6247 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
6252 #ifdef CONFIG_TESTING_OPTIONS
6254 static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant *wpa_s,
6255 unsigned int freq, const u8 *dst,
6256 const u8 *src, const u8 *bssid,
6257 const u8 *data, size_t data_len,
6258 enum offchannel_send_action_result
6261 wpa_msg(wpa_s, MSG_INFO, "MGMT-TX-STATUS freq=%u dst=" MACSTR
6262 " src=" MACSTR " bssid=" MACSTR " result=%s",
6263 freq, MAC2STR(dst), MAC2STR(src), MAC2STR(bssid),
6264 result == OFFCHANNEL_SEND_ACTION_SUCCESS ?
6265 "SUCCESS" : (result == OFFCHANNEL_SEND_ACTION_NO_ACK ?
6266 "NO_ACK" : "FAILED"));
6270 static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant *wpa_s, char *cmd)
6274 u8 *buf, da[ETH_ALEN], bssid[ETH_ALEN];
6276 int freq = 0, no_cck = 0, wait_time = 0;
6278 /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1]
6279 * <action=Action frame payload> */
6281 wpa_printf(MSG_DEBUG, "External MGMT TX: %s", cmd);
6284 used = hwaddr_aton2(pos, da);
6290 used = hwaddr_aton2(pos, bssid);
6295 param = os_strstr(pos, " freq=");
6301 param = os_strstr(pos, " no_cck=");
6304 no_cck = atoi(param);
6307 param = os_strstr(pos, " wait_time=");
6310 wait_time = atoi(param);
6313 param = os_strstr(pos, " action=");
6318 len = os_strlen(param);
6323 buf = os_malloc(len);
6327 if (hexstr2bin(param, buf, len) < 0) {
6332 res = offchannel_send_action(wpa_s, freq, da, wpa_s->own_addr, bssid,
6333 buf, len, wait_time,
6334 wpas_ctrl_iface_mgmt_tx_cb, no_cck);
6340 static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant *wpa_s)
6342 wpa_printf(MSG_DEBUG, "External MGMT TX - done waiting");
6343 offchannel_send_action_done(wpa_s);
6347 static int wpas_ctrl_iface_driver_event(struct wpa_supplicant *wpa_s, char *cmd)
6350 union wpa_event_data event;
6351 enum wpa_event_type ev;
6353 /* <event name> [parameters..] */
6355 wpa_dbg(wpa_s, MSG_DEBUG, "Testing - external driver event: %s", cmd);
6358 param = os_strchr(pos, ' ');
6362 os_memset(&event, 0, sizeof(event));
6364 if (os_strcmp(cmd, "INTERFACE_ENABLED") == 0) {
6365 ev = EVENT_INTERFACE_ENABLED;
6366 } else if (os_strcmp(cmd, "INTERFACE_DISABLED") == 0) {
6367 ev = EVENT_INTERFACE_DISABLED;
6368 } else if (os_strcmp(cmd, "AVOID_FREQUENCIES") == 0) {
6369 ev = EVENT_AVOID_FREQUENCIES;
6372 if (freq_range_list_parse(&event.freq_range, param) < 0)
6374 wpa_supplicant_event(wpa_s, ev, &event);
6375 os_free(event.freq_range.range);
6378 wpa_dbg(wpa_s, MSG_DEBUG, "Testing - unknown driver event: %s",
6383 wpa_supplicant_event(wpa_s, ev, &event);
6389 static int wpas_ctrl_iface_eapol_rx(struct wpa_supplicant *wpa_s, char *cmd)
6392 u8 src[ETH_ALEN], *buf;
6396 wpa_printf(MSG_DEBUG, "External EAPOL RX: %s", cmd);
6399 used = hwaddr_aton2(pos, src);
6406 len = os_strlen(pos);
6411 buf = os_malloc(len);
6415 if (hexstr2bin(pos, buf, len) < 0) {
6420 wpa_supplicant_rx_eapol(wpa_s, src, buf, len);
6427 static u16 ipv4_hdr_checksum(const void *buf, size_t len)
6431 const u16 *pos = buf;
6433 for (i = 0; i < len / 2; i++)
6437 sum = (sum & 0xffff) + (sum >> 16);
6439 return sum ^ 0xffff;
6443 #define HWSIM_PACKETLEN 1500
6444 #define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header))
6446 void wpas_data_test_rx(void *ctx, const u8 *src_addr, const u8 *buf, size_t len)
6448 struct wpa_supplicant *wpa_s = ctx;
6449 const struct ether_header *eth;
6450 const struct iphdr *ip;
6454 if (len != HWSIM_PACKETLEN)
6457 eth = (const struct ether_header *) buf;
6458 ip = (const struct iphdr *) (eth + 1);
6459 pos = (const u8 *) (ip + 1);
6461 if (ip->ihl != 5 || ip->version != 4 ||
6462 ntohs(ip->tot_len) != HWSIM_IP_LEN)
6465 for (i = 0; i < HWSIM_IP_LEN - sizeof(*ip); i++) {
6471 wpa_msg(wpa_s, MSG_INFO, "DATA-TEST-RX " MACSTR " " MACSTR,
6472 MAC2STR(eth->ether_dhost), MAC2STR(eth->ether_shost));
6476 static int wpas_ctrl_iface_data_test_config(struct wpa_supplicant *wpa_s,
6479 int enabled = atoi(cmd);
6482 if (wpa_s->l2_test) {
6483 l2_packet_deinit(wpa_s->l2_test);
6484 wpa_s->l2_test = NULL;
6485 wpa_dbg(wpa_s, MSG_DEBUG, "test data: Disabled");
6493 wpa_s->l2_test = l2_packet_init(wpa_s->ifname, wpa_s->own_addr,
6494 ETHERTYPE_IP, wpas_data_test_rx,
6496 if (wpa_s->l2_test == NULL)
6499 wpa_dbg(wpa_s, MSG_DEBUG, "test data: Enabled");
6505 static int wpas_ctrl_iface_data_test_tx(struct wpa_supplicant *wpa_s, char *cmd)
6507 u8 dst[ETH_ALEN], src[ETH_ALEN];
6512 u8 buf[HWSIM_PACKETLEN];
6513 struct ether_header *eth;
6518 if (wpa_s->l2_test == NULL)
6521 /* format: <dst> <src> <tos> */
6524 used = hwaddr_aton2(pos, dst);
6530 used = hwaddr_aton2(pos, src);
6535 val = strtol(pos, NULL, 0);
6536 if (val < 0 || val > 0xff)
6540 eth = (struct ether_header *) buf;
6541 os_memcpy(eth->ether_dhost, dst, ETH_ALEN);
6542 os_memcpy(eth->ether_shost, src, ETH_ALEN);
6543 eth->ether_type = htons(ETHERTYPE_IP);
6544 ip = (struct iphdr *) (eth + 1);
6545 os_memset(ip, 0, sizeof(*ip));
6550 ip->tot_len = htons(HWSIM_IP_LEN);
6552 ip->saddr = htonl(192 << 24 | 168 << 16 | 1 << 8 | 1);
6553 ip->daddr = htonl(192 << 24 | 168 << 16 | 1 << 8 | 2);
6554 ip->check = ipv4_hdr_checksum(ip, sizeof(*ip));
6555 dpos = (u8 *) (ip + 1);
6556 for (i = 0; i < HWSIM_IP_LEN - sizeof(*ip); i++)
6559 if (l2_packet_send(wpa_s->l2_test, dst, ETHERTYPE_IP, buf,
6560 HWSIM_PACKETLEN) < 0)
6563 wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX dst=" MACSTR " src=" MACSTR
6564 " tos=0x%x", MAC2STR(dst), MAC2STR(src), tos);
6569 #endif /* CONFIG_TESTING_OPTIONS */
6572 static void wpas_ctrl_vendor_elem_update(struct wpa_supplicant *wpa_s)
6577 wpa_printf(MSG_DEBUG, "Update vendor elements");
6579 for (i = 0; i < NUM_VENDOR_ELEM_FRAMES; i++) {
6580 if (wpa_s->vendor_elem[i]) {
6581 os_snprintf(buf, sizeof(buf), "frame[%u]", i);
6582 wpa_hexdump_buf(MSG_DEBUG, buf, wpa_s->vendor_elem[i]);
6587 if (wpa_s->parent == wpa_s &&
6588 wpa_s->global->p2p &&
6589 !wpa_s->global->p2p_disabled)
6590 p2p_set_vendor_elems(wpa_s->global->p2p, wpa_s->vendor_elem);
6591 #endif /* CONFIG_P2P */
6595 static struct wpa_supplicant *
6596 wpas_ctrl_vendor_elem_iface(struct wpa_supplicant *wpa_s,
6597 enum wpa_vendor_elem_frame frame)
6601 case VENDOR_ELEM_PROBE_REQ_P2P:
6602 case VENDOR_ELEM_PROBE_RESP_P2P:
6603 case VENDOR_ELEM_PROBE_RESP_P2P_GO:
6604 case VENDOR_ELEM_BEACON_P2P_GO:
6605 case VENDOR_ELEM_P2P_PD_REQ:
6606 case VENDOR_ELEM_P2P_PD_RESP:
6607 case VENDOR_ELEM_P2P_GO_NEG_REQ:
6608 case VENDOR_ELEM_P2P_GO_NEG_RESP:
6609 case VENDOR_ELEM_P2P_GO_NEG_CONF:
6610 case VENDOR_ELEM_P2P_INV_REQ:
6611 case VENDOR_ELEM_P2P_INV_RESP:
6612 case VENDOR_ELEM_P2P_ASSOC_REQ:
6613 return wpa_s->parent;
6614 #endif /* CONFIG_P2P */
6621 static int wpas_ctrl_vendor_elem_add(struct wpa_supplicant *wpa_s, char *cmd)
6627 struct ieee802_11_elems elems;
6630 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
6632 wpa_s = wpas_ctrl_vendor_elem_iface(wpa_s, frame);
6634 pos = os_strchr(pos, ' ');
6639 len = os_strlen(pos);
6646 buf = wpabuf_alloc(len);
6650 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
6655 if (ieee802_11_parse_elems(wpabuf_head_u8(buf), len, &elems, 0) ==
6661 if (wpa_s->vendor_elem[frame] == NULL) {
6662 wpa_s->vendor_elem[frame] = buf;
6663 wpas_ctrl_vendor_elem_update(wpa_s);
6667 if (wpabuf_resize(&wpa_s->vendor_elem[frame], len) < 0) {
6672 wpabuf_put_buf(wpa_s->vendor_elem[frame], buf);
6674 wpas_ctrl_vendor_elem_update(wpa_s);
6680 static int wpas_ctrl_vendor_elem_get(struct wpa_supplicant *wpa_s, char *cmd,
6681 char *buf, size_t buflen)
6683 int frame = atoi(cmd);
6685 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
6687 wpa_s = wpas_ctrl_vendor_elem_iface(wpa_s, frame);
6689 if (wpa_s->vendor_elem[frame] == NULL)
6692 return wpa_snprintf_hex(buf, buflen,
6693 wpabuf_head_u8(wpa_s->vendor_elem[frame]),
6694 wpabuf_len(wpa_s->vendor_elem[frame]));
6698 static int wpas_ctrl_vendor_elem_remove(struct wpa_supplicant *wpa_s, char *cmd)
6704 struct ieee802_11_elems elems;
6708 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
6710 wpa_s = wpas_ctrl_vendor_elem_iface(wpa_s, frame);
6712 pos = os_strchr(pos, ' ');
6718 wpabuf_free(wpa_s->vendor_elem[frame]);
6719 wpa_s->vendor_elem[frame] = NULL;
6720 wpas_ctrl_vendor_elem_update(wpa_s);
6724 if (wpa_s->vendor_elem[frame] == NULL)
6727 len = os_strlen(pos);
6734 buf = os_malloc(len);
6738 if (hexstr2bin(pos, buf, len) < 0) {
6743 if (ieee802_11_parse_elems(buf, len, &elems, 0) == ParseFailed) {
6748 ie = wpabuf_mhead_u8(wpa_s->vendor_elem[frame]);
6749 end = ie + wpabuf_len(wpa_s->vendor_elem[frame]);
6751 for (; ie + 1 < end; ie += 2 + ie[1]) {
6754 if (os_memcmp(ie, buf, len) != 0)
6757 if (wpabuf_len(wpa_s->vendor_elem[frame]) == len) {
6758 wpabuf_free(wpa_s->vendor_elem[frame]);
6759 wpa_s->vendor_elem[frame] = NULL;
6761 os_memmove(ie, ie + len,
6763 wpa_s->vendor_elem[frame]->used -= len;
6766 wpas_ctrl_vendor_elem_update(wpa_s);
6776 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
6777 char *buf, size_t *resp_len)
6780 const int reply_size = 4096;
6783 if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 ||
6784 os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
6785 if (wpa_debug_show_keys)
6786 wpa_dbg(wpa_s, MSG_DEBUG,
6787 "Control interface command '%s'", buf);
6789 wpa_dbg(wpa_s, MSG_DEBUG,
6790 "Control interface command '%s [REMOVED]'",
6791 os_strncmp(buf, WPA_CTRL_RSP,
6792 os_strlen(WPA_CTRL_RSP)) == 0 ?
6793 WPA_CTRL_RSP : "SET_NETWORK");
6794 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ", 16) == 0 ||
6795 os_strncmp(buf, "NFC_REPORT_HANDOVER", 19) == 0) {
6796 wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface",
6797 (const u8 *) buf, os_strlen(buf));
6799 int level = MSG_DEBUG;
6800 if (os_strcmp(buf, "PING") == 0)
6801 level = MSG_EXCESSIVE;
6802 wpa_dbg(wpa_s, level, "Control interface command '%s'", buf);
6805 reply = os_malloc(reply_size);
6806 if (reply == NULL) {
6811 os_memcpy(reply, "OK\n", 3);
6814 if (os_strcmp(buf, "PING") == 0) {
6815 os_memcpy(reply, "PONG\n", 5);
6817 } else if (os_strcmp(buf, "IFNAME") == 0) {
6818 reply_len = os_strlen(wpa_s->ifname);
6819 os_memcpy(reply, wpa_s->ifname, reply_len);
6820 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
6821 if (wpa_debug_reopen_file() < 0)
6823 } else if (os_strncmp(buf, "NOTE ", 5) == 0) {
6824 wpa_printf(MSG_INFO, "NOTE: %s", buf + 5);
6825 } else if (os_strcmp(buf, "MIB") == 0) {
6826 reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size);
6827 if (reply_len >= 0) {
6829 res = eapol_sm_get_mib(wpa_s->eapol, reply + reply_len,
6830 reply_size - reply_len);
6836 } else if (os_strncmp(buf, "STATUS", 6) == 0) {
6837 reply_len = wpa_supplicant_ctrl_iface_status(
6838 wpa_s, buf + 6, reply, reply_size);
6839 } else if (os_strcmp(buf, "PMKSA") == 0) {
6840 reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, reply,
6842 } else if (os_strcmp(buf, "PMKSA_FLUSH") == 0) {
6843 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
6844 } else if (os_strncmp(buf, "SET ", 4) == 0) {
6845 if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4))
6847 } else if (os_strncmp(buf, "GET ", 4) == 0) {
6848 reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4,
6850 } else if (os_strcmp(buf, "LOGON") == 0) {
6851 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
6852 } else if (os_strcmp(buf, "LOGOFF") == 0) {
6853 eapol_sm_notify_logoff(wpa_s->eapol, TRUE);
6854 } else if (os_strcmp(buf, "REASSOCIATE") == 0) {
6855 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
6858 wpas_request_connection(wpa_s);
6859 } else if (os_strcmp(buf, "REATTACH") == 0) {
6860 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED ||
6861 !wpa_s->current_ssid)
6864 wpa_s->reattach = 1;
6865 wpas_request_connection(wpa_s);
6867 } else if (os_strcmp(buf, "RECONNECT") == 0) {
6868 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
6870 else if (wpa_s->disconnected)
6871 wpas_request_connection(wpa_s);
6872 #ifdef IEEE8021X_EAPOL
6873 } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) {
6874 if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8))
6876 #endif /* IEEE8021X_EAPOL */
6877 #ifdef CONFIG_PEERKEY
6878 } else if (os_strncmp(buf, "STKSTART ", 9) == 0) {
6879 if (wpa_supplicant_ctrl_iface_stkstart(wpa_s, buf + 9))
6881 #endif /* CONFIG_PEERKEY */
6882 #ifdef CONFIG_IEEE80211R
6883 } else if (os_strncmp(buf, "FT_DS ", 6) == 0) {
6884 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6))
6886 #endif /* CONFIG_IEEE80211R */
6888 } else if (os_strcmp(buf, "WPS_PBC") == 0) {
6889 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL);
6891 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
6895 } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) {
6896 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8);
6898 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
6902 } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {
6903 reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8,
6906 } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) {
6907 reply_len = wpa_supplicant_ctrl_iface_wps_check_pin(
6908 wpa_s, buf + 14, reply, reply_size);
6909 } else if (os_strcmp(buf, "WPS_CANCEL") == 0) {
6910 if (wpas_wps_cancel(wpa_s))
6912 #ifdef CONFIG_WPS_NFC
6913 } else if (os_strcmp(buf, "WPS_NFC") == 0) {
6914 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, NULL))
6916 } else if (os_strncmp(buf, "WPS_NFC ", 8) == 0) {
6917 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, buf + 8))
6919 } else if (os_strncmp(buf, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
6920 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_config_token(
6921 wpa_s, buf + 21, reply, reply_size);
6922 } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) {
6923 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_token(
6924 wpa_s, buf + 14, reply, reply_size);
6925 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) {
6926 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s,
6929 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
6930 reply_len = wpas_ctrl_nfc_get_handover_req(
6931 wpa_s, buf + 21, reply, reply_size);
6932 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
6933 reply_len = wpas_ctrl_nfc_get_handover_sel(
6934 wpa_s, buf + 21, reply, reply_size);
6935 } else if (os_strncmp(buf, "NFC_REPORT_HANDOVER ", 20) == 0) {
6936 if (wpas_ctrl_nfc_report_handover(wpa_s, buf + 20))
6938 #endif /* CONFIG_WPS_NFC */
6939 } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) {
6940 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8))
6943 } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) {
6944 reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin(
6945 wpa_s, buf + 11, reply, reply_size);
6946 #endif /* CONFIG_AP */
6947 #ifdef CONFIG_WPS_ER
6948 } else if (os_strcmp(buf, "WPS_ER_START") == 0) {
6949 if (wpas_wps_er_start(wpa_s, NULL))
6951 } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) {
6952 if (wpas_wps_er_start(wpa_s, buf + 13))
6954 } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) {
6955 if (wpas_wps_er_stop(wpa_s))
6957 } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) {
6958 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11))
6960 } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) {
6961 int ret = wpas_wps_er_pbc(wpa_s, buf + 11);
6963 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
6965 } else if (ret == -3) {
6966 os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18);
6968 } else if (ret == -4) {
6969 os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20);
6973 } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) {
6974 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13))
6976 } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) {
6977 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s,
6980 } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) {
6981 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14))
6983 #ifdef CONFIG_WPS_NFC
6984 } else if (os_strncmp(buf, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
6985 reply_len = wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
6986 wpa_s, buf + 24, reply, reply_size);
6987 #endif /* CONFIG_WPS_NFC */
6988 #endif /* CONFIG_WPS_ER */
6989 #endif /* CONFIG_WPS */
6990 #ifdef CONFIG_IBSS_RSN
6991 } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) {
6992 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9))
6994 #endif /* CONFIG_IBSS_RSN */
6996 } else if (os_strncmp(buf, "MESH_GROUP_ADD ", 15) == 0) {
6997 if (wpa_supplicant_ctrl_iface_mesh_group_add(wpa_s, buf + 15))
6999 } else if (os_strncmp(buf, "MESH_GROUP_REMOVE ", 18) == 0) {
7000 if (wpa_supplicant_ctrl_iface_mesh_group_remove(wpa_s,
7003 #endif /* CONFIG_MESH */
7005 } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) {
7006 if (p2p_ctrl_find(wpa_s, buf + 9))
7008 } else if (os_strcmp(buf, "P2P_FIND") == 0) {
7009 if (p2p_ctrl_find(wpa_s, ""))
7011 } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) {
7012 wpas_p2p_stop_find(wpa_s);
7013 } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) {
7014 reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply,
7016 } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) {
7017 if (p2p_ctrl_listen(wpa_s, buf + 11))
7019 } else if (os_strcmp(buf, "P2P_LISTEN") == 0) {
7020 if (p2p_ctrl_listen(wpa_s, ""))
7022 } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) {
7023 if (wpas_p2p_group_remove(wpa_s, buf + 17))
7025 } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) {
7026 if (wpas_p2p_group_add(wpa_s, 0, 0, 0, 0))
7028 } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) {
7029 if (p2p_ctrl_group_add(wpa_s, buf + 14))
7031 } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) {
7032 if (p2p_ctrl_prov_disc(wpa_s, buf + 14))
7034 } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) {
7035 reply_len = p2p_get_passphrase(wpa_s, reply, reply_size);
7036 } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) {
7037 reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply,
7039 } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
7040 if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0)
7042 } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) {
7043 if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0)
7045 } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) {
7046 wpas_p2p_sd_service_update(wpa_s);
7047 } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
7048 if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0)
7050 } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) {
7051 wpas_p2p_service_flush(wpa_s);
7052 } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) {
7053 if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0)
7055 } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) {
7056 if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0)
7058 } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) {
7059 if (p2p_ctrl_reject(wpa_s, buf + 11) < 0)
7061 } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) {
7062 if (p2p_ctrl_invite(wpa_s, buf + 11) < 0)
7064 } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) {
7065 reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply,
7067 } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) {
7068 if (p2p_ctrl_set(wpa_s, buf + 8) < 0)
7070 } else if (os_strcmp(buf, "P2P_FLUSH") == 0) {
7071 p2p_ctrl_flush(wpa_s);
7072 } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) {
7073 if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0)
7075 } else if (os_strcmp(buf, "P2P_CANCEL") == 0) {
7076 if (wpas_p2p_cancel(wpa_s))
7078 } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) {
7079 if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0)
7081 } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) {
7082 if (p2p_ctrl_presence_req(wpa_s, "") < 0)
7084 } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) {
7085 if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0)
7087 } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) {
7088 if (p2p_ctrl_ext_listen(wpa_s, "") < 0)
7090 } else if (os_strncmp(buf, "P2P_REMOVE_CLIENT ", 18) == 0) {
7091 if (p2p_ctrl_remove_client(wpa_s, buf + 18) < 0)
7093 #endif /* CONFIG_P2P */
7094 #ifdef CONFIG_WIFI_DISPLAY
7095 } else if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0) {
7096 if (wifi_display_subelem_set(wpa_s->global, buf + 16) < 0)
7098 } else if (os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) {
7099 reply_len = wifi_display_subelem_get(wpa_s->global, buf + 16,
7101 #endif /* CONFIG_WIFI_DISPLAY */
7102 #ifdef CONFIG_INTERWORKING
7103 } else if (os_strcmp(buf, "FETCH_ANQP") == 0) {
7104 if (interworking_fetch_anqp(wpa_s) < 0)
7106 } else if (os_strcmp(buf, "STOP_FETCH_ANQP") == 0) {
7107 interworking_stop_fetch_anqp(wpa_s);
7108 } else if (os_strcmp(buf, "INTERWORKING_SELECT") == 0) {
7109 if (ctrl_interworking_select(wpa_s, NULL) < 0)
7111 } else if (os_strncmp(buf, "INTERWORKING_SELECT ", 20) == 0) {
7112 if (ctrl_interworking_select(wpa_s, buf + 20) < 0)
7114 } else if (os_strncmp(buf, "INTERWORKING_CONNECT ", 21) == 0) {
7115 if (ctrl_interworking_connect(wpa_s, buf + 21) < 0)
7117 } else if (os_strncmp(buf, "ANQP_GET ", 9) == 0) {
7118 if (get_anqp(wpa_s, buf + 9) < 0)
7120 } else if (os_strncmp(buf, "GAS_REQUEST ", 12) == 0) {
7121 if (gas_request(wpa_s, buf + 12) < 0)
7123 } else if (os_strncmp(buf, "GAS_RESPONSE_GET ", 17) == 0) {
7124 reply_len = gas_response_get(wpa_s, buf + 17, reply,
7126 #endif /* CONFIG_INTERWORKING */
7128 } else if (os_strncmp(buf, "HS20_ANQP_GET ", 14) == 0) {
7129 if (get_hs20_anqp(wpa_s, buf + 14) < 0)
7131 } else if (os_strncmp(buf, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
7132 if (hs20_get_nai_home_realm_list(wpa_s, buf + 29) < 0)
7134 } else if (os_strncmp(buf, "HS20_ICON_REQUEST ", 18) == 0) {
7135 if (hs20_icon_request(wpa_s, buf + 18) < 0)
7137 } else if (os_strcmp(buf, "FETCH_OSU") == 0) {
7138 if (hs20_fetch_osu(wpa_s) < 0)
7140 } else if (os_strcmp(buf, "CANCEL_FETCH_OSU") == 0) {
7141 hs20_cancel_fetch_osu(wpa_s);
7142 #endif /* CONFIG_HS20 */
7143 } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0)
7145 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
7146 wpa_s, buf + os_strlen(WPA_CTRL_RSP)))
7150 * Notify response from timeout to allow the control
7151 * interface response to be sent first.
7153 eloop_register_timeout(0, 0, wpas_ctrl_eapol_response,
7156 } else if (os_strcmp(buf, "RECONFIGURE") == 0) {
7157 if (wpa_supplicant_reload_configuration(wpa_s))
7159 } else if (os_strcmp(buf, "TERMINATE") == 0) {
7160 wpa_supplicant_terminate_proc(wpa_s->global);
7161 } else if (os_strncmp(buf, "BSSID ", 6) == 0) {
7162 if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6))
7164 } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) {
7165 reply_len = wpa_supplicant_ctrl_iface_blacklist(
7166 wpa_s, buf + 9, reply, reply_size);
7167 } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) {
7168 reply_len = wpa_supplicant_ctrl_iface_log_level(
7169 wpa_s, buf + 9, reply, reply_size);
7170 } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) {
7171 reply_len = wpa_supplicant_ctrl_iface_list_networks(
7172 wpa_s, reply, reply_size);
7173 } else if (os_strcmp(buf, "DISCONNECT") == 0) {
7175 wpa_s->sme.prev_bssid_set = 0;
7176 #endif /* CONFIG_SME */
7177 wpa_s->reassociate = 0;
7178 wpa_s->disconnected = 1;
7179 wpa_supplicant_cancel_sched_scan(wpa_s);
7180 wpa_supplicant_cancel_scan(wpa_s);
7181 wpa_supplicant_deauthenticate(wpa_s,
7182 WLAN_REASON_DEAUTH_LEAVING);
7183 } else if (os_strcmp(buf, "SCAN") == 0) {
7184 wpas_ctrl_scan(wpa_s, NULL, reply, reply_size, &reply_len);
7185 } else if (os_strncmp(buf, "SCAN ", 5) == 0) {
7186 wpas_ctrl_scan(wpa_s, buf + 5, reply, reply_size, &reply_len);
7187 } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) {
7188 reply_len = wpa_supplicant_ctrl_iface_scan_results(
7189 wpa_s, reply, reply_size);
7190 } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) {
7191 if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15))
7193 } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) {
7194 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15))
7196 } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) {
7197 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16))
7199 } else if (os_strcmp(buf, "ADD_NETWORK") == 0) {
7200 reply_len = wpa_supplicant_ctrl_iface_add_network(
7201 wpa_s, reply, reply_size);
7202 } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) {
7203 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15))
7205 } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
7206 if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12))
7208 } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) {
7209 reply_len = wpa_supplicant_ctrl_iface_get_network(
7210 wpa_s, buf + 12, reply, reply_size);
7211 } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) {
7212 if (wpa_supplicant_ctrl_iface_dup_network(wpa_s, buf + 12))
7214 } else if (os_strcmp(buf, "LIST_CREDS") == 0) {
7215 reply_len = wpa_supplicant_ctrl_iface_list_creds(
7216 wpa_s, reply, reply_size);
7217 } else if (os_strcmp(buf, "ADD_CRED") == 0) {
7218 reply_len = wpa_supplicant_ctrl_iface_add_cred(
7219 wpa_s, reply, reply_size);
7220 } else if (os_strncmp(buf, "REMOVE_CRED ", 12) == 0) {
7221 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s, buf + 12))
7223 } else if (os_strncmp(buf, "SET_CRED ", 9) == 0) {
7224 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s, buf + 9))
7226 } else if (os_strncmp(buf, "GET_CRED ", 9) == 0) {
7227 reply_len = wpa_supplicant_ctrl_iface_get_cred(wpa_s, buf + 9,
7230 #ifndef CONFIG_NO_CONFIG_WRITE
7231 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
7232 if (wpa_supplicant_ctrl_iface_save_config(wpa_s))
7234 #endif /* CONFIG_NO_CONFIG_WRITE */
7235 } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
7236 reply_len = wpa_supplicant_ctrl_iface_get_capability(
7237 wpa_s, buf + 15, reply, reply_size);
7238 } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) {
7239 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8))
7241 } else if (os_strncmp(buf, "SCAN_INTERVAL ", 14) == 0) {
7242 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s, buf + 14))
7244 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
7245 reply_len = wpa_supplicant_global_iface_list(
7246 wpa_s->global, reply, reply_size);
7247 } else if (os_strcmp(buf, "INTERFACES") == 0) {
7248 reply_len = wpa_supplicant_global_iface_interfaces(
7249 wpa_s->global, reply, reply_size);
7250 } else if (os_strncmp(buf, "BSS ", 4) == 0) {
7251 reply_len = wpa_supplicant_ctrl_iface_bss(
7252 wpa_s, buf + 4, reply, reply_size);
7254 } else if (os_strcmp(buf, "STA-FIRST") == 0) {
7255 reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size);
7256 } else if (os_strncmp(buf, "STA ", 4) == 0) {
7257 reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply,
7259 } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) {
7260 reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply,
7262 } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) {
7263 if (ap_ctrl_iface_sta_deauthenticate(wpa_s, buf + 15))
7265 } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) {
7266 if (ap_ctrl_iface_sta_disassociate(wpa_s, buf + 13))
7268 } else if (os_strncmp(buf, "CHAN_SWITCH ", 12) == 0) {
7269 if (ap_ctrl_iface_chanswitch(wpa_s, buf + 12))
7271 #endif /* CONFIG_AP */
7272 } else if (os_strcmp(buf, "SUSPEND") == 0) {
7273 wpas_notify_suspend(wpa_s->global);
7274 } else if (os_strcmp(buf, "RESUME") == 0) {
7275 wpas_notify_resume(wpa_s->global);
7276 #ifdef CONFIG_TESTING_OPTIONS
7277 } else if (os_strcmp(buf, "DROP_SA") == 0) {
7278 wpa_supplicant_ctrl_iface_drop_sa(wpa_s);
7279 #endif /* CONFIG_TESTING_OPTIONS */
7280 } else if (os_strncmp(buf, "ROAM ", 5) == 0) {
7281 if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5))
7283 } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) {
7284 if (wpa_supplicant_ctrl_iface_sta_autoconnect(wpa_s, buf + 16))
7286 } else if (os_strncmp(buf, "BSS_EXPIRE_AGE ", 15) == 0) {
7287 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s, buf + 15))
7289 } else if (os_strncmp(buf, "BSS_EXPIRE_COUNT ", 17) == 0) {
7290 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s,
7293 } else if (os_strncmp(buf, "BSS_FLUSH ", 10) == 0) {
7294 if (wpa_supplicant_ctrl_iface_bss_flush(wpa_s, buf + 10))
7297 } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) {
7298 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14))
7300 } else if (os_strncmp(buf, "TDLS_SETUP ", 11) == 0) {
7301 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s, buf + 11))
7303 } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) {
7304 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14))
7306 #endif /* CONFIG_TDLS */
7307 } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) {
7308 reply_len = wpa_supplicant_signal_poll(wpa_s, reply,
7310 } else if (os_strncmp(buf, "PKTCNT_POLL", 11) == 0) {
7311 reply_len = wpa_supplicant_pktcnt_poll(wpa_s, reply,
7313 #ifdef CONFIG_AUTOSCAN
7314 } else if (os_strncmp(buf, "AUTOSCAN ", 9) == 0) {
7315 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s, buf + 9))
7317 #endif /* CONFIG_AUTOSCAN */
7319 } else if (os_strncmp(buf, "DRIVER ", 7) == 0) {
7320 reply_len = wpa_supplicant_driver_cmd(wpa_s, buf + 7, reply,
7322 #endif /* ANDROID */
7323 } else if (os_strncmp(buf, "VENDOR ", 7) == 0) {
7324 reply_len = wpa_supplicant_vendor_cmd(wpa_s, buf + 7, reply,
7326 } else if (os_strcmp(buf, "REAUTHENTICATE") == 0) {
7327 pmksa_cache_clear_current(wpa_s->wpa);
7328 eapol_sm_request_reauth(wpa_s->eapol);
7330 } else if (os_strncmp(buf, "WNM_SLEEP ", 10) == 0) {
7331 if (wpas_ctrl_iface_wnm_sleep(wpa_s, buf + 10))
7333 } else if (os_strncmp(buf, "WNM_BSS_QUERY ", 10) == 0) {
7334 if (wpas_ctrl_iface_wnm_bss_query(wpa_s, buf + 10))
7336 #endif /* CONFIG_WNM */
7337 } else if (os_strcmp(buf, "FLUSH") == 0) {
7338 wpa_supplicant_ctrl_iface_flush(wpa_s);
7339 } else if (os_strncmp(buf, "RADIO_WORK ", 11) == 0) {
7340 reply_len = wpas_ctrl_radio_work(wpa_s, buf + 11, reply,
7342 #ifdef CONFIG_TESTING_OPTIONS
7343 } else if (os_strncmp(buf, "MGMT_TX ", 8) == 0) {
7344 if (wpas_ctrl_iface_mgmt_tx(wpa_s, buf + 8) < 0)
7346 } else if (os_strcmp(buf, "MGMT_TX_DONE") == 0) {
7347 wpas_ctrl_iface_mgmt_tx_done(wpa_s);
7348 } else if (os_strncmp(buf, "DRIVER_EVENT ", 13) == 0) {
7349 if (wpas_ctrl_iface_driver_event(wpa_s, buf + 13) < 0)
7351 } else if (os_strncmp(buf, "EAPOL_RX ", 9) == 0) {
7352 if (wpas_ctrl_iface_eapol_rx(wpa_s, buf + 9) < 0)
7354 } else if (os_strncmp(buf, "DATA_TEST_CONFIG ", 17) == 0) {
7355 if (wpas_ctrl_iface_data_test_config(wpa_s, buf + 17) < 0)
7357 } else if (os_strncmp(buf, "DATA_TEST_TX ", 13) == 0) {
7358 if (wpas_ctrl_iface_data_test_tx(wpa_s, buf + 13) < 0)
7360 #endif /* CONFIG_TESTING_OPTIONS */
7361 } else if (os_strncmp(buf, "VENDOR_ELEM_ADD ", 16) == 0) {
7362 if (wpas_ctrl_vendor_elem_add(wpa_s, buf + 16) < 0)
7364 } else if (os_strncmp(buf, "VENDOR_ELEM_GET ", 16) == 0) {
7365 reply_len = wpas_ctrl_vendor_elem_get(wpa_s, buf + 16, reply,
7367 } else if (os_strncmp(buf, "VENDOR_ELEM_REMOVE ", 19) == 0) {
7368 if (wpas_ctrl_vendor_elem_remove(wpa_s, buf + 19) < 0)
7371 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
7375 if (reply_len < 0) {
7376 os_memcpy(reply, "FAIL\n", 5);
7380 *resp_len = reply_len;
7385 static int wpa_supplicant_global_iface_add(struct wpa_global *global,
7388 struct wpa_interface iface;
7392 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
7393 * TAB<bridge_ifname>
7395 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd);
7397 os_memset(&iface, 0, sizeof(iface));
7400 iface.ifname = pos = cmd;
7401 pos = os_strchr(pos, '\t');
7404 if (iface.ifname[0] == '\0')
7409 iface.confname = pos;
7410 pos = os_strchr(pos, '\t');
7413 if (iface.confname[0] == '\0')
7414 iface.confname = NULL;
7419 pos = os_strchr(pos, '\t');
7422 if (iface.driver[0] == '\0')
7423 iface.driver = NULL;
7427 iface.ctrl_interface = pos;
7428 pos = os_strchr(pos, '\t');
7431 if (iface.ctrl_interface[0] == '\0')
7432 iface.ctrl_interface = NULL;
7436 iface.driver_param = pos;
7437 pos = os_strchr(pos, '\t');
7440 if (iface.driver_param[0] == '\0')
7441 iface.driver_param = NULL;
7445 iface.bridge_ifname = pos;
7446 pos = os_strchr(pos, '\t');
7449 if (iface.bridge_ifname[0] == '\0')
7450 iface.bridge_ifname = NULL;
7455 if (wpa_supplicant_get_iface(global, iface.ifname))
7458 return wpa_supplicant_add_iface(global, &iface) ? 0 : -1;
7462 static int wpa_supplicant_global_iface_remove(struct wpa_global *global,
7465 struct wpa_supplicant *wpa_s;
7467 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd);
7469 wpa_s = wpa_supplicant_get_iface(global, cmd);
7472 return wpa_supplicant_remove_iface(global, wpa_s, 0);
7476 static void wpa_free_iface_info(struct wpa_interface_info *iface)
7478 struct wpa_interface_info *prev;
7482 iface = iface->next;
7484 os_free(prev->ifname);
7485 os_free(prev->desc);
7491 static int wpa_supplicant_global_iface_list(struct wpa_global *global,
7495 struct wpa_interface_info *iface = NULL, *last = NULL, *tmp;
7498 for (i = 0; wpa_drivers[i]; i++) {
7499 struct wpa_driver_ops *drv = wpa_drivers[i];
7500 if (drv->get_interfaces == NULL)
7502 tmp = drv->get_interfaces(global->drv_priv[i]);
7516 for (tmp = iface; tmp; tmp = tmp->next) {
7517 res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n",
7518 tmp->drv_name, tmp->ifname,
7519 tmp->desc ? tmp->desc : "");
7520 if (res < 0 || res >= end - pos) {
7527 wpa_free_iface_info(iface);
7533 static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
7538 struct wpa_supplicant *wpa_s;
7540 wpa_s = global->ifaces;
7545 res = os_snprintf(pos, end - pos, "%s\n", wpa_s->ifname);
7546 if (res < 0 || res >= end - pos) {
7551 wpa_s = wpa_s->next;
7557 static char * wpas_global_ctrl_iface_ifname(struct wpa_global *global,
7559 char *cmd, size_t *resp_len)
7561 struct wpa_supplicant *wpa_s;
7563 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
7564 if (os_strcmp(ifname, wpa_s->ifname) == 0)
7568 if (wpa_s == NULL) {
7569 char *resp = os_strdup("FAIL-NO-IFNAME-MATCH\n");
7571 *resp_len = os_strlen(resp);
7577 return wpa_supplicant_ctrl_iface_process(wpa_s, cmd, resp_len);
7581 static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global *global,
7582 char *buf, size_t *resp_len)
7585 static const char * cmd[] = {
7591 "P2P_GET_PASSPHRASE",
7592 "P2P_SERVICE_UPDATE",
7593 "P2P_SERVICE_FLUSH",
7600 static const char * prefix[] = {
7603 #endif /* ANDROID */
7609 "P2P_GROUP_REMOVE ",
7612 "P2P_SERV_DISC_REQ ",
7613 "P2P_SERV_DISC_CANCEL_REQ ",
7614 "P2P_SERV_DISC_RESP ",
7615 "P2P_SERV_DISC_EXTERNAL ",
7623 "P2P_PRESENCE_REQ ",
7625 "P2P_REMOVE_CLIENT ",
7626 "NFC_GET_HANDOVER_SEL ",
7627 "NFC_GET_HANDOVER_REQ ",
7628 "NFC_REPORT_HANDOVER ",
7634 if (global->p2p_init_wpa_s == NULL)
7637 for (i = 0; !found && cmd[i]; i++) {
7638 if (os_strcmp(buf, cmd[i]) == 0)
7642 for (i = 0; !found && prefix[i]; i++) {
7643 if (os_strncmp(buf, prefix[i], os_strlen(prefix[i])) == 0)
7648 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
7650 #endif /* CONFIG_P2P */
7655 static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global *global,
7656 char *buf, size_t *resp_len)
7658 #ifdef CONFIG_WIFI_DISPLAY
7659 if (global->p2p_init_wpa_s == NULL)
7661 if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0 ||
7662 os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0)
7663 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
7665 #endif /* CONFIG_WIFI_DISPLAY */
7670 static char * wpas_global_ctrl_iface_redir(struct wpa_global *global,
7671 char *buf, size_t *resp_len)
7675 ret = wpas_global_ctrl_iface_redir_p2p(global, buf, resp_len);
7679 ret = wpas_global_ctrl_iface_redir_wfd(global, buf, resp_len);
7687 static int wpas_global_ctrl_iface_set(struct wpa_global *global, char *cmd)
7691 value = os_strchr(cmd, ' ');
7696 wpa_printf(MSG_DEBUG, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd, value);
7698 #ifdef CONFIG_WIFI_DISPLAY
7699 if (os_strcasecmp(cmd, "wifi_display") == 0) {
7700 wifi_display_enable(global, !!atoi(value));
7703 #endif /* CONFIG_WIFI_DISPLAY */
7705 /* Restore cmd to its original value to allow redirection */
7712 #ifndef CONFIG_NO_CONFIG_WRITE
7713 static int wpas_global_ctrl_iface_save_config(struct wpa_global *global)
7715 int ret = 0, saved = 0;
7716 struct wpa_supplicant *wpa_s;
7718 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
7719 if (!wpa_s->conf->update_config) {
7720 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
7724 if (wpa_config_write(wpa_s->confname, wpa_s->conf)) {
7725 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
7728 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
7733 if (!saved && !ret) {
7734 wpa_dbg(wpa_s, MSG_DEBUG,
7735 "CTRL_IFACE: SAVE_CONFIG - No configuration files could be updated");
7741 #endif /* CONFIG_NO_CONFIG_WRITE */
7744 static int wpas_global_ctrl_iface_status(struct wpa_global *global,
7745 char *buf, size_t buflen)
7749 struct wpa_supplicant *wpa_s;
7755 if (global->p2p && !global->p2p_disabled) {
7756 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
7759 MAC2STR(global->p2p_dev_addr),
7760 p2p_get_state_txt(global->p2p));
7761 if (ret < 0 || ret >= end - pos)
7764 } else if (global->p2p) {
7765 ret = os_snprintf(pos, end - pos, "p2p_state=DISABLED\n");
7766 if (ret < 0 || ret >= end - pos)
7770 #endif /* CONFIG_P2P */
7772 #ifdef CONFIG_WIFI_DISPLAY
7773 ret = os_snprintf(pos, end - pos, "wifi_display=%d\n",
7774 !!global->wifi_display);
7775 if (ret < 0 || ret >= end - pos)
7778 #endif /* CONFIG_WIFI_DISPLAY */
7780 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
7781 ret = os_snprintf(pos, end - pos, "ifname=%s\n"
7782 "address=" MACSTR "\n",
7783 wpa_s->ifname, MAC2STR(wpa_s->own_addr));
7784 if (ret < 0 || ret >= end - pos)
7793 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
7794 char *buf, size_t *resp_len)
7797 const int reply_size = 2048;
7799 int level = MSG_DEBUG;
7801 if (os_strncmp(buf, "IFNAME=", 7) == 0) {
7802 char *pos = os_strchr(buf + 7, ' ');
7805 return wpas_global_ctrl_iface_ifname(global,
7811 reply = wpas_global_ctrl_iface_redir(global, buf, resp_len);
7815 if (os_strcmp(buf, "PING") == 0)
7816 level = MSG_EXCESSIVE;
7817 wpa_hexdump_ascii(level, "RX global ctrl_iface",
7818 (const u8 *) buf, os_strlen(buf));
7820 reply = os_malloc(reply_size);
7821 if (reply == NULL) {
7826 os_memcpy(reply, "OK\n", 3);
7829 if (os_strcmp(buf, "PING") == 0) {
7830 os_memcpy(reply, "PONG\n", 5);
7832 } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) {
7833 if (wpa_supplicant_global_iface_add(global, buf + 14))
7835 } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) {
7836 if (wpa_supplicant_global_iface_remove(global, buf + 17))
7838 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
7839 reply_len = wpa_supplicant_global_iface_list(
7840 global, reply, reply_size);
7841 } else if (os_strcmp(buf, "INTERFACES") == 0) {
7842 reply_len = wpa_supplicant_global_iface_interfaces(
7843 global, reply, reply_size);
7844 } else if (os_strcmp(buf, "TERMINATE") == 0) {
7845 wpa_supplicant_terminate_proc(global);
7846 } else if (os_strcmp(buf, "SUSPEND") == 0) {
7847 wpas_notify_suspend(global);
7848 } else if (os_strcmp(buf, "RESUME") == 0) {
7849 wpas_notify_resume(global);
7850 } else if (os_strncmp(buf, "SET ", 4) == 0) {
7851 if (wpas_global_ctrl_iface_set(global, buf + 4)) {
7853 if (global->p2p_init_wpa_s) {
7855 /* Check if P2P redirection would work for this
7857 return wpa_supplicant_ctrl_iface_process(
7858 global->p2p_init_wpa_s,
7861 #endif /* CONFIG_P2P */
7864 #ifndef CONFIG_NO_CONFIG_WRITE
7865 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
7866 if (wpas_global_ctrl_iface_save_config(global))
7868 #endif /* CONFIG_NO_CONFIG_WRITE */
7869 } else if (os_strcmp(buf, "STATUS") == 0) {
7870 reply_len = wpas_global_ctrl_iface_status(global, reply,
7872 #ifdef CONFIG_MODULE_TESTS
7873 } else if (os_strcmp(buf, "MODULE_TESTS") == 0) {
7874 int wpas_module_tests(void);
7875 if (wpas_module_tests() < 0)
7877 #endif /* CONFIG_MODULE_TESTS */
7878 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
7879 if (wpa_debug_reopen_file() < 0)
7882 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
7886 if (reply_len < 0) {
7887 os_memcpy(reply, "FAIL\n", 5);
7891 *resp_len = reply_len;