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"
51 static int wpa_supplicant_global_iface_list(struct wpa_global *global,
53 static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
55 static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s,
58 static int set_bssid_filter(struct wpa_supplicant *wpa_s, char *val)
61 u8 addr[ETH_ALEN], *filter = NULL, *n;
68 if (hwaddr_aton(pos, addr)) {
72 n = os_realloc_array(filter, count + 1, ETH_ALEN);
78 os_memcpy(filter + count * ETH_ALEN, addr, ETH_ALEN);
81 pos = os_strchr(pos, ' ');
86 wpa_hexdump(MSG_DEBUG, "bssid_filter", filter, count * ETH_ALEN);
87 os_free(wpa_s->bssid_filter);
88 wpa_s->bssid_filter = filter;
89 wpa_s->bssid_filter_count = count;
95 static int set_disallow_aps(struct wpa_supplicant *wpa_s, char *val)
98 u8 addr[ETH_ALEN], *bssid = NULL, *n;
99 struct wpa_ssid_value *ssid = NULL, *ns;
100 size_t count = 0, ssid_count = 0;
104 * disallow_list ::= <ssid_spec> | <bssid_spec> | <disallow_list> | ""
105 * SSID_SPEC ::= ssid <SSID_HEX>
106 * BSSID_SPEC ::= bssid <BSSID_HEX>
113 if (os_strncmp(pos, "bssid ", 6) == 0) {
116 res = hwaddr_aton2(pos, addr);
120 wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
121 "BSSID value '%s'", pos);
125 n = os_realloc_array(bssid, count + 1, ETH_ALEN);
132 os_memcpy(bssid + count * ETH_ALEN, addr, ETH_ALEN);
134 } else if (os_strncmp(pos, "ssid ", 5) == 0) {
140 if (*end == '\0' || *end == ' ')
145 ns = os_realloc_array(ssid, ssid_count + 1,
146 sizeof(struct wpa_ssid_value));
154 if ((end - pos) & 0x01 || end - pos > 2 * 32 ||
155 hexstr2bin(pos, ssid[ssid_count].ssid,
156 (end - pos) / 2) < 0) {
159 wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
160 "SSID value '%s'", pos);
163 ssid[ssid_count].ssid_len = (end - pos) / 2;
164 wpa_hexdump_ascii(MSG_DEBUG, "disallow_aps SSID",
165 ssid[ssid_count].ssid,
166 ssid[ssid_count].ssid_len);
170 wpa_printf(MSG_DEBUG, "Unexpected disallow_aps value "
177 pos = os_strchr(pos, ' ');
182 wpa_hexdump(MSG_DEBUG, "disallow_aps_bssid", bssid, count * ETH_ALEN);
183 os_free(wpa_s->disallow_aps_bssid);
184 wpa_s->disallow_aps_bssid = bssid;
185 wpa_s->disallow_aps_bssid_count = count;
187 wpa_printf(MSG_DEBUG, "disallow_aps_ssid_count %d", (int) ssid_count);
188 os_free(wpa_s->disallow_aps_ssid);
189 wpa_s->disallow_aps_ssid = ssid;
190 wpa_s->disallow_aps_ssid_count = ssid_count;
192 if (!wpa_s->current_ssid || wpa_s->wpa_state < WPA_AUTHENTICATING)
195 c = wpa_s->current_ssid;
196 if (c->mode != WPAS_MODE_INFRA && c->mode != WPAS_MODE_IBSS)
199 if (!disallowed_bssid(wpa_s, wpa_s->bssid) &&
200 !disallowed_ssid(wpa_s, c->ssid, c->ssid_len))
203 wpa_printf(MSG_DEBUG, "Disconnect and try to find another network "
204 "because current AP was marked disallowed");
207 wpa_s->sme.prev_bssid_set = 0;
208 #endif /* CONFIG_SME */
209 wpa_s->reassociate = 1;
210 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
211 wpa_supplicant_req_scan(wpa_s, 0, 0);
217 #ifndef CONFIG_NO_CONFIG_BLOBS
218 static int wpas_ctrl_set_blob(struct wpa_supplicant *wpa_s, char *pos)
221 struct wpa_config_blob *blob;
224 pos = os_strchr(pos, ' ');
228 len = os_strlen(pos);
232 wpa_printf(MSG_DEBUG, "CTRL: Set blob '%s'", name);
233 blob = os_zalloc(sizeof(*blob));
236 blob->name = os_strdup(name);
237 blob->data = os_malloc(len / 2);
238 if (blob->name == NULL || blob->data == NULL) {
239 wpa_config_free_blob(blob);
243 if (hexstr2bin(pos, blob->data, len / 2) < 0) {
244 wpa_printf(MSG_DEBUG, "CTRL: Invalid blob hex data");
245 wpa_config_free_blob(blob);
250 wpa_config_set_blob(wpa_s->conf, blob);
254 #endif /* CONFIG_NO_CONFIG_BLOBS */
257 static int wpas_ctrl_pno(struct wpa_supplicant *wpa_s, char *cmd)
265 params = os_strchr(cmd, ' ');
266 os_free(wpa_s->manual_sched_scan_freqs);
269 pos = os_strstr(params, "freq=");
271 freqs = freq_range_to_channel_list(wpa_s,
274 wpa_s->manual_sched_scan_freqs = freqs;
275 ret = wpas_start_pno(wpa_s);
277 ret = wpas_stop_pno(wpa_s);
283 static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s,
289 value = os_strchr(cmd, ' ');
294 wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value);
295 if (os_strcasecmp(cmd, "EAPOL::heldPeriod") == 0) {
296 eapol_sm_configure(wpa_s->eapol,
297 atoi(value), -1, -1, -1);
298 } else if (os_strcasecmp(cmd, "EAPOL::authPeriod") == 0) {
299 eapol_sm_configure(wpa_s->eapol,
300 -1, atoi(value), -1, -1);
301 } else if (os_strcasecmp(cmd, "EAPOL::startPeriod") == 0) {
302 eapol_sm_configure(wpa_s->eapol,
303 -1, -1, atoi(value), -1);
304 } else if (os_strcasecmp(cmd, "EAPOL::maxStart") == 0) {
305 eapol_sm_configure(wpa_s->eapol,
306 -1, -1, -1, atoi(value));
307 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKLifetime") == 0) {
308 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME,
311 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKReauthThreshold") ==
313 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD,
316 } else if (os_strcasecmp(cmd, "dot11RSNAConfigSATimeout") == 0) {
317 if (wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, atoi(value)))
319 } else if (os_strcasecmp(cmd, "wps_fragment_size") == 0) {
320 wpa_s->wps_fragment_size = atoi(value);
321 #ifdef CONFIG_WPS_TESTING
322 } else if (os_strcasecmp(cmd, "wps_version_number") == 0) {
324 val = strtol(value, NULL, 0);
325 if (val < 0 || val > 0xff) {
327 wpa_printf(MSG_DEBUG, "WPS: Invalid "
328 "wps_version_number %ld", val);
330 wps_version_number = val;
331 wpa_printf(MSG_DEBUG, "WPS: Testing - force WPS "
333 (wps_version_number & 0xf0) >> 4,
334 wps_version_number & 0x0f);
336 } else if (os_strcasecmp(cmd, "wps_testing_dummy_cred") == 0) {
337 wps_testing_dummy_cred = atoi(value);
338 wpa_printf(MSG_DEBUG, "WPS: Testing - dummy_cred=%d",
339 wps_testing_dummy_cred);
340 } else if (os_strcasecmp(cmd, "wps_corrupt_pkhash") == 0) {
341 wps_corrupt_pkhash = atoi(value);
342 wpa_printf(MSG_DEBUG, "WPS: Testing - wps_corrupt_pkhash=%d",
344 #endif /* CONFIG_WPS_TESTING */
345 } else if (os_strcasecmp(cmd, "ampdu") == 0) {
346 if (wpa_drv_ampdu(wpa_s, atoi(value)) < 0)
349 #ifdef CONFIG_TDLS_TESTING
350 } else if (os_strcasecmp(cmd, "tdls_testing") == 0) {
351 extern unsigned int tdls_testing;
352 tdls_testing = strtol(value, NULL, 0);
353 wpa_printf(MSG_DEBUG, "TDLS: tdls_testing=0x%x", tdls_testing);
354 #endif /* CONFIG_TDLS_TESTING */
355 } else if (os_strcasecmp(cmd, "tdls_disabled") == 0) {
356 int disabled = atoi(value);
357 wpa_printf(MSG_DEBUG, "TDLS: tdls_disabled=%d", disabled);
359 if (wpa_drv_tdls_oper(wpa_s, TDLS_DISABLE, NULL) < 0)
361 } else if (wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL) < 0)
363 wpa_tdls_enable(wpa_s->wpa, !disabled);
364 #endif /* CONFIG_TDLS */
365 } else if (os_strcasecmp(cmd, "pno") == 0) {
366 ret = wpas_ctrl_pno(wpa_s, value);
367 } else if (os_strcasecmp(cmd, "radio_disabled") == 0) {
368 int disabled = atoi(value);
369 if (wpa_drv_radio_disable(wpa_s, disabled) < 0)
372 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
373 } else if (os_strcasecmp(cmd, "uapsd") == 0) {
374 if (os_strcmp(value, "disable") == 0)
375 wpa_s->set_sta_uapsd = 0;
379 /* format: BE,BK,VI,VO;max SP Length */
381 pos = os_strchr(value, ',');
386 pos = os_strchr(pos, ',');
391 pos = os_strchr(pos, ',');
396 /* ignore max SP Length for now */
398 wpa_s->set_sta_uapsd = 1;
399 wpa_s->sta_uapsd = 0;
401 wpa_s->sta_uapsd |= BIT(0);
403 wpa_s->sta_uapsd |= BIT(1);
405 wpa_s->sta_uapsd |= BIT(2);
407 wpa_s->sta_uapsd |= BIT(3);
409 } else if (os_strcasecmp(cmd, "ps") == 0) {
410 ret = wpa_drv_set_p2p_powersave(wpa_s, atoi(value), -1, -1);
411 #ifdef CONFIG_WIFI_DISPLAY
412 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
413 int enabled = !!atoi(value);
414 if (enabled && !wpa_s->global->p2p)
417 wifi_display_enable(wpa_s->global, enabled);
418 #endif /* CONFIG_WIFI_DISPLAY */
419 } else if (os_strcasecmp(cmd, "bssid_filter") == 0) {
420 ret = set_bssid_filter(wpa_s, value);
421 } else if (os_strcasecmp(cmd, "disallow_aps") == 0) {
422 ret = set_disallow_aps(wpa_s, value);
423 } else if (os_strcasecmp(cmd, "no_keep_alive") == 0) {
424 wpa_s->no_keep_alive = !!atoi(value);
425 #ifdef CONFIG_TESTING_OPTIONS
426 } else if (os_strcasecmp(cmd, "ext_mgmt_frame_handling") == 0) {
427 wpa_s->ext_mgmt_frame_handling = !!atoi(value);
428 } else if (os_strcasecmp(cmd, "ext_eapol_frame_io") == 0) {
429 wpa_s->ext_eapol_frame_io = !!atoi(value);
431 if (wpa_s->ap_iface) {
432 wpa_s->ap_iface->bss[0]->ext_eapol_frame_io =
433 wpa_s->ext_eapol_frame_io;
435 #endif /* CONFIG_AP */
436 #endif /* CONFIG_TESTING_OPTIONS */
437 #ifndef CONFIG_NO_CONFIG_BLOBS
438 } else if (os_strcmp(cmd, "blob") == 0) {
439 ret = wpas_ctrl_set_blob(wpa_s, value);
440 #endif /* CONFIG_NO_CONFIG_BLOBS */
443 ret = wpa_config_process_global(wpa_s->conf, cmd, -1);
445 wpa_supplicant_update_config(wpa_s);
452 static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s,
453 char *cmd, char *buf, size_t buflen)
457 wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd);
459 if (os_strcmp(cmd, "version") == 0) {
460 res = os_snprintf(buf, buflen, "%s", VERSION_STR);
461 } else if (os_strcasecmp(cmd, "country") == 0) {
462 if (wpa_s->conf->country[0] && wpa_s->conf->country[1])
463 res = os_snprintf(buf, buflen, "%c%c",
464 wpa_s->conf->country[0],
465 wpa_s->conf->country[1]);
466 #ifdef CONFIG_WIFI_DISPLAY
467 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
469 if (wpa_s->global->p2p == NULL ||
470 wpa_s->global->p2p_disabled)
473 enabled = wpa_s->global->wifi_display;
474 res = os_snprintf(buf, buflen, "%d", enabled);
475 if (res < 0 || (unsigned int) res >= buflen)
478 #endif /* CONFIG_WIFI_DISPLAY */
479 #ifdef CONFIG_TESTING_GET_GTK
480 } else if (os_strcmp(cmd, "gtk") == 0) {
481 if (wpa_s->last_gtk_len == 0)
483 res = wpa_snprintf_hex(buf, buflen, wpa_s->last_gtk,
484 wpa_s->last_gtk_len);
486 #endif /* CONFIG_TESTING_GET_GTK */
489 if (res < 0 || (unsigned int) res >= buflen)
495 #ifdef IEEE8021X_EAPOL
496 static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s,
500 struct wpa_ssid *ssid = wpa_s->current_ssid;
502 if (hwaddr_aton(addr, bssid)) {
503 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address "
508 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid));
509 rsn_preauth_deinit(wpa_s->wpa);
510 if (rsn_preauth_init(wpa_s->wpa, bssid, ssid ? &ssid->eap : NULL))
515 #endif /* IEEE8021X_EAPOL */
518 #ifdef CONFIG_PEERKEY
519 /* MLME-STKSTART.request(peer) */
520 static int wpa_supplicant_ctrl_iface_stkstart(
521 struct wpa_supplicant *wpa_s, char *addr)
525 if (hwaddr_aton(addr, peer)) {
526 wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART: invalid "
527 "address '%s'", addr);
531 wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART " MACSTR,
534 return wpa_sm_stkstart(wpa_s->wpa, peer);
536 #endif /* CONFIG_PEERKEY */
541 static int wpa_supplicant_ctrl_iface_tdls_discover(
542 struct wpa_supplicant *wpa_s, char *addr)
547 if (hwaddr_aton(addr, peer)) {
548 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER: invalid "
549 "address '%s'", addr);
553 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER " MACSTR,
556 if (wpa_tdls_is_external_setup(wpa_s->wpa))
557 ret = wpa_tdls_send_discovery_request(wpa_s->wpa, peer);
559 ret = wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer);
565 static int wpa_supplicant_ctrl_iface_tdls_setup(
566 struct wpa_supplicant *wpa_s, char *addr)
571 if (hwaddr_aton(addr, peer)) {
572 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP: invalid "
573 "address '%s'", addr);
577 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP " MACSTR,
580 if ((wpa_s->conf->tdls_external_control) &&
581 wpa_tdls_is_external_setup(wpa_s->wpa))
582 return wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
584 wpa_tdls_remove(wpa_s->wpa, peer);
586 if (wpa_tdls_is_external_setup(wpa_s->wpa))
587 ret = wpa_tdls_start(wpa_s->wpa, peer);
589 ret = wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
595 static int wpa_supplicant_ctrl_iface_tdls_teardown(
596 struct wpa_supplicant *wpa_s, char *addr)
601 if (os_strcmp(addr, "*") == 0) {
602 /* remove everyone */
603 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN *");
604 wpa_tdls_teardown_peers(wpa_s->wpa);
608 if (hwaddr_aton(addr, peer)) {
609 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN: invalid "
610 "address '%s'", addr);
614 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN " MACSTR,
617 if ((wpa_s->conf->tdls_external_control) &&
618 wpa_tdls_is_external_setup(wpa_s->wpa))
619 return wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
621 if (wpa_tdls_is_external_setup(wpa_s->wpa))
622 ret = wpa_tdls_teardown_link(
624 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED);
626 ret = wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
632 static int ctrl_iface_get_capability_tdls(
633 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
637 ret = os_snprintf(buf, buflen, "%s\n",
638 wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT ?
640 WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP ?
641 "EXTERNAL" : "INTERNAL") : "UNSUPPORTED");
642 if (ret < 0 || (size_t) ret > buflen)
647 #endif /* CONFIG_TDLS */
650 #ifdef CONFIG_IEEE80211R
651 static int wpa_supplicant_ctrl_iface_ft_ds(
652 struct wpa_supplicant *wpa_s, char *addr)
654 u8 target_ap[ETH_ALEN];
658 if (hwaddr_aton(addr, target_ap)) {
659 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid "
660 "address '%s'", addr);
664 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap));
666 bss = wpa_bss_get_bssid(wpa_s, target_ap);
668 mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN);
672 return wpa_ft_start_over_ds(wpa_s->wpa, target_ap, mdie);
674 #endif /* CONFIG_IEEE80211R */
678 static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s,
681 u8 bssid[ETH_ALEN], *_bssid = bssid;
683 u8 p2p_dev_addr[ETH_ALEN];
684 #endif /* CONFIG_P2P */
686 u8 *_p2p_dev_addr = NULL;
687 #endif /* CONFIG_AP */
689 if (cmd == NULL || os_strcmp(cmd, "any") == 0) {
692 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
693 if (hwaddr_aton(cmd + 13, p2p_dev_addr)) {
694 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid "
695 "P2P Device Address '%s'",
699 _p2p_dev_addr = p2p_dev_addr;
700 #endif /* CONFIG_P2P */
701 } else if (hwaddr_aton(cmd, bssid)) {
702 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
709 return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid, _p2p_dev_addr);
710 #endif /* CONFIG_AP */
712 return wpas_wps_start_pbc(wpa_s, _bssid, 0);
716 static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s,
717 char *cmd, char *buf,
720 u8 bssid[ETH_ALEN], *_bssid = bssid;
724 pin = os_strchr(cmd, ' ');
728 if (os_strcmp(cmd, "any") == 0)
730 else if (os_strcmp(cmd, "get") == 0) {
731 ret = wps_generate_pin();
733 } else if (hwaddr_aton(cmd, bssid)) {
734 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
740 if (wpa_s->ap_iface) {
745 pos = os_strchr(pin, ' ');
752 return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin,
753 buf, buflen, timeout);
755 #endif /* CONFIG_AP */
758 ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0,
762 ret = os_snprintf(buf, buflen, "%s", pin);
763 if (ret < 0 || (size_t) ret >= buflen)
768 ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0, DEV_PW_DEFAULT);
773 /* Return the generated PIN */
774 ret = os_snprintf(buf, buflen, "%08d", ret);
775 if (ret < 0 || (size_t) ret >= buflen)
781 static int wpa_supplicant_ctrl_iface_wps_check_pin(
782 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
789 wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN",
790 (u8 *) cmd, os_strlen(cmd));
791 for (pos = cmd, len = 0; *pos != '\0'; pos++) {
792 if (*pos < '0' || *pos > '9')
796 wpa_printf(MSG_DEBUG, "WPS: Too long PIN");
800 if (len != 4 && len != 8) {
801 wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len);
807 unsigned int pin_val;
809 if (!wps_pin_valid(pin_val)) {
810 wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit");
811 ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n");
812 if (ret < 0 || (size_t) ret >= buflen)
818 ret = os_snprintf(buf, buflen, "%s", pin);
819 if (ret < 0 || (size_t) ret >= buflen)
826 #ifdef CONFIG_WPS_NFC
828 static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant *wpa_s,
831 u8 bssid[ETH_ALEN], *_bssid = bssid;
833 if (cmd == NULL || cmd[0] == '\0')
835 else if (hwaddr_aton(cmd, bssid))
838 return wpas_wps_start_nfc(wpa_s, NULL, _bssid, NULL, 0, 0, NULL, NULL,
843 static int wpa_supplicant_ctrl_iface_wps_nfc_config_token(
844 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
851 pos = os_strchr(cmd, ' ');
854 if (os_strcmp(cmd, "WPS") == 0)
856 else if (os_strcmp(cmd, "NDEF") == 0)
861 buf = wpas_wps_nfc_config_token(wpa_s, ndef, pos);
865 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
876 static int wpa_supplicant_ctrl_iface_wps_nfc_token(
877 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
883 if (os_strcmp(cmd, "WPS") == 0)
885 else if (os_strcmp(cmd, "NDEF") == 0)
890 buf = wpas_wps_nfc_token(wpa_s, ndef);
894 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
905 static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
906 struct wpa_supplicant *wpa_s, char *pos)
914 freq = strstr(pos, " freq=");
918 forced_freq = atoi(freq);
921 len = os_strlen(pos);
926 buf = wpabuf_alloc(len);
929 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
934 ret = wpas_wps_nfc_tag_read(wpa_s, buf, forced_freq);
941 static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant *wpa_s,
942 char *reply, size_t max_len,
948 buf = wpas_wps_nfc_handover_req(wpa_s, ndef);
952 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
964 static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant *wpa_s,
965 char *reply, size_t max_len,
971 buf = wpas_p2p_nfc_handover_req(wpa_s, ndef);
973 wpa_printf(MSG_DEBUG, "P2P: Could not generate NFC handover request");
977 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
986 #endif /* CONFIG_P2P */
989 static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant *wpa_s,
990 char *cmd, char *reply,
996 pos = os_strchr(cmd, ' ');
1001 if (os_strcmp(cmd, "WPS") == 0)
1003 else if (os_strcmp(cmd, "NDEF") == 0)
1008 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
1011 return wpas_ctrl_nfc_get_handover_req_wps(
1012 wpa_s, reply, max_len, ndef);
1016 if (os_strcmp(pos, "P2P-CR") == 0) {
1017 return wpas_ctrl_nfc_get_handover_req_p2p(
1018 wpa_s, reply, max_len, ndef);
1020 #endif /* CONFIG_P2P */
1026 static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant *wpa_s,
1027 char *reply, size_t max_len,
1028 int ndef, int cr, char *uuid)
1033 buf = wpas_wps_nfc_handover_sel(wpa_s, ndef, cr, uuid);
1037 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1039 reply[res++] = '\n';
1049 static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant *wpa_s,
1050 char *reply, size_t max_len,
1056 buf = wpas_p2p_nfc_handover_sel(wpa_s, ndef, tag);
1060 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1062 reply[res++] = '\n';
1069 #endif /* CONFIG_P2P */
1072 static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant *wpa_s,
1073 char *cmd, char *reply,
1079 pos = os_strchr(cmd, ' ');
1084 if (os_strcmp(cmd, "WPS") == 0)
1086 else if (os_strcmp(cmd, "NDEF") == 0)
1091 pos2 = os_strchr(pos, ' ');
1094 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
1097 return wpas_ctrl_nfc_get_handover_sel_wps(
1098 wpa_s, reply, max_len, ndef,
1099 os_strcmp(pos, "WPS-CR") == 0, pos2);
1103 if (os_strcmp(pos, "P2P-CR") == 0) {
1104 return wpas_ctrl_nfc_get_handover_sel_p2p(
1105 wpa_s, reply, max_len, ndef, 0);
1108 if (os_strcmp(pos, "P2P-CR-TAG") == 0) {
1109 return wpas_ctrl_nfc_get_handover_sel_p2p(
1110 wpa_s, reply, max_len, ndef, 1);
1112 #endif /* CONFIG_P2P */
1118 static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant *wpa_s,
1122 struct wpabuf *req, *sel;
1124 char *pos, *role, *type, *pos2;
1127 int forced_freq = 0;
1129 freq = strstr(cmd, " freq=");
1133 forced_freq = atoi(freq);
1135 #endif /* CONFIG_P2P */
1138 pos = os_strchr(role, ' ');
1140 wpa_printf(MSG_DEBUG, "NFC: Missing type in handover report");
1146 pos = os_strchr(type, ' ');
1148 wpa_printf(MSG_DEBUG, "NFC: Missing request message in handover report");
1153 pos2 = os_strchr(pos, ' ');
1155 wpa_printf(MSG_DEBUG, "NFC: Missing select message in handover report");
1160 len = os_strlen(pos);
1162 wpa_printf(MSG_DEBUG, "NFC: Invalid request message length in handover report");
1167 req = wpabuf_alloc(len);
1169 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for request message");
1172 if (hexstr2bin(pos, wpabuf_put(req, len), len) < 0) {
1173 wpa_printf(MSG_DEBUG, "NFC: Invalid request message hexdump in handover report");
1178 len = os_strlen(pos2);
1180 wpa_printf(MSG_DEBUG, "NFC: Invalid select message length in handover report");
1186 sel = wpabuf_alloc(len);
1188 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for select message");
1192 if (hexstr2bin(pos2, wpabuf_put(sel, len), len) < 0) {
1193 wpa_printf(MSG_DEBUG, "NFC: Invalid select message hexdump in handover report");
1199 wpa_printf(MSG_DEBUG, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d",
1200 role, type, (int) wpabuf_len(req), (int) wpabuf_len(sel));
1202 if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "WPS") == 0) {
1203 ret = wpas_wps_nfc_report_handover(wpa_s, req, sel);
1205 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "WPS") == 0)
1207 ret = wpas_ap_wps_nfc_report_handover(wpa_s, req, sel);
1209 ret = wpas_er_wps_nfc_report_handover(wpa_s, req, sel);
1210 #endif /* CONFIG_AP */
1212 } else if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "P2P") == 0)
1214 ret = wpas_p2p_nfc_report_handover(wpa_s, 1, req, sel, 0);
1215 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "P2P") == 0)
1217 ret = wpas_p2p_nfc_report_handover(wpa_s, 0, req, sel,
1219 #endif /* CONFIG_P2P */
1221 wpa_printf(MSG_DEBUG, "NFC: Unsupported connection handover "
1222 "reported: role=%s type=%s", role, type);
1229 wpa_printf(MSG_DEBUG, "NFC: Failed to process reported handover messages");
1234 #endif /* CONFIG_WPS_NFC */
1237 static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s,
1246 struct wps_new_ap_settings ap;
1248 pin = os_strchr(cmd, ' ');
1253 if (hwaddr_aton(cmd, bssid)) {
1254 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
1259 new_ssid = os_strchr(pin, ' ');
1260 if (new_ssid == NULL)
1261 return wpas_wps_start_reg(wpa_s, bssid, pin, NULL);
1264 new_auth = os_strchr(new_ssid, ' ');
1265 if (new_auth == NULL)
1269 new_encr = os_strchr(new_auth, ' ');
1270 if (new_encr == NULL)
1274 new_key = os_strchr(new_encr, ' ');
1275 if (new_key == NULL)
1279 os_memset(&ap, 0, sizeof(ap));
1280 ap.ssid_hex = new_ssid;
1283 ap.key_hex = new_key;
1284 return wpas_wps_start_reg(wpa_s, bssid, pin, &ap);
1289 static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant *wpa_s,
1290 char *cmd, char *buf,
1295 const char *pin_txt;
1297 if (!wpa_s->ap_iface)
1300 pos = os_strchr(cmd, ' ');
1304 if (os_strcmp(cmd, "disable") == 0) {
1305 wpas_wps_ap_pin_disable(wpa_s);
1306 return os_snprintf(buf, buflen, "OK\n");
1309 if (os_strcmp(cmd, "random") == 0) {
1311 timeout = atoi(pos);
1312 pin_txt = wpas_wps_ap_pin_random(wpa_s, timeout);
1313 if (pin_txt == NULL)
1315 return os_snprintf(buf, buflen, "%s", pin_txt);
1318 if (os_strcmp(cmd, "get") == 0) {
1319 pin_txt = wpas_wps_ap_pin_get(wpa_s);
1320 if (pin_txt == NULL)
1322 return os_snprintf(buf, buflen, "%s", pin_txt);
1325 if (os_strcmp(cmd, "set") == 0) {
1330 pos = os_strchr(pos, ' ');
1333 timeout = atoi(pos);
1335 if (os_strlen(pin) > buflen)
1337 if (wpas_wps_ap_pin_set(wpa_s, pin, timeout) < 0)
1339 return os_snprintf(buf, buflen, "%s", pin);
1344 #endif /* CONFIG_AP */
1347 #ifdef CONFIG_WPS_ER
1348 static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant *wpa_s,
1351 char *uuid = cmd, *pin, *pos;
1352 u8 addr_buf[ETH_ALEN], *addr = NULL;
1353 pin = os_strchr(uuid, ' ');
1357 pos = os_strchr(pin, ' ');
1360 if (hwaddr_aton(pos, addr_buf) == 0)
1363 return wpas_wps_er_add_pin(wpa_s, addr, uuid, pin);
1367 static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant *wpa_s,
1370 char *uuid = cmd, *pin;
1371 pin = os_strchr(uuid, ' ');
1375 return wpas_wps_er_learn(wpa_s, uuid, pin);
1379 static int wpa_supplicant_ctrl_iface_wps_er_set_config(
1380 struct wpa_supplicant *wpa_s, char *cmd)
1382 char *uuid = cmd, *id;
1383 id = os_strchr(uuid, ' ');
1387 return wpas_wps_er_set_config(wpa_s, uuid, atoi(id));
1391 static int wpa_supplicant_ctrl_iface_wps_er_config(
1392 struct wpa_supplicant *wpa_s, char *cmd)
1399 struct wps_new_ap_settings ap;
1401 pin = os_strchr(cmd, ' ');
1406 new_ssid = os_strchr(pin, ' ');
1407 if (new_ssid == NULL)
1411 new_auth = os_strchr(new_ssid, ' ');
1412 if (new_auth == NULL)
1416 new_encr = os_strchr(new_auth, ' ');
1417 if (new_encr == NULL)
1421 new_key = os_strchr(new_encr, ' ');
1422 if (new_key == NULL)
1426 os_memset(&ap, 0, sizeof(ap));
1427 ap.ssid_hex = new_ssid;
1430 ap.key_hex = new_key;
1431 return wpas_wps_er_config(wpa_s, cmd, pin, &ap);
1435 #ifdef CONFIG_WPS_NFC
1436 static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
1437 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1444 uuid = os_strchr(cmd, ' ');
1449 if (os_strcmp(cmd, "WPS") == 0)
1451 else if (os_strcmp(cmd, "NDEF") == 0)
1456 buf = wpas_wps_er_nfc_config_token(wpa_s, ndef, uuid);
1460 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1462 reply[res++] = '\n';
1469 #endif /* CONFIG_WPS_NFC */
1470 #endif /* CONFIG_WPS_ER */
1472 #endif /* CONFIG_WPS */
1475 #ifdef CONFIG_IBSS_RSN
1476 static int wpa_supplicant_ctrl_iface_ibss_rsn(
1477 struct wpa_supplicant *wpa_s, char *addr)
1481 if (hwaddr_aton(addr, peer)) {
1482 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN: invalid "
1483 "address '%s'", addr);
1487 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN " MACSTR,
1490 return ibss_rsn_start(wpa_s->ibss_rsn, peer);
1492 #endif /* CONFIG_IBSS_RSN */
1495 static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s,
1498 #ifdef IEEE8021X_EAPOL
1501 struct wpa_ssid *ssid;
1503 pos = os_strchr(rsp, '-');
1508 pos = os_strchr(pos, ':');
1513 wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id);
1514 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
1515 (u8 *) pos, os_strlen(pos));
1517 ssid = wpa_config_get_network(wpa_s->conf, id);
1519 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
1524 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s, ssid, rsp,
1526 #else /* IEEE8021X_EAPOL */
1527 wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included");
1529 #endif /* IEEE8021X_EAPOL */
1533 static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
1535 char *buf, size_t buflen)
1537 char *pos, *end, tmp[30];
1538 int res, verbose, wps, ret;
1541 #endif /* CONFIG_HS20 */
1543 if (os_strcmp(params, "-DRIVER") == 0)
1544 return wpa_drv_status(wpa_s, buf, buflen);
1545 verbose = os_strcmp(params, "-VERBOSE") == 0;
1546 wps = os_strcmp(params, "-WPS") == 0;
1549 if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
1550 struct wpa_ssid *ssid = wpa_s->current_ssid;
1551 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
1552 MAC2STR(wpa_s->bssid));
1553 if (ret < 0 || ret >= end - pos)
1556 ret = os_snprintf(pos, end - pos, "freq=%u\n",
1558 if (ret < 0 || ret >= end - pos)
1562 u8 *_ssid = ssid->ssid;
1563 size_t ssid_len = ssid->ssid_len;
1564 u8 ssid_buf[MAX_SSID_LEN];
1565 if (ssid_len == 0) {
1566 int _res = wpa_drv_get_ssid(wpa_s, ssid_buf);
1573 ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n",
1574 wpa_ssid_txt(_ssid, ssid_len),
1576 if (ret < 0 || ret >= end - pos)
1580 if (wps && ssid->passphrase &&
1581 wpa_key_mgmt_wpa_psk(ssid->key_mgmt) &&
1582 (ssid->mode == WPAS_MODE_AP ||
1583 ssid->mode == WPAS_MODE_P2P_GO)) {
1584 ret = os_snprintf(pos, end - pos,
1587 if (ret < 0 || ret >= end - pos)
1592 ret = os_snprintf(pos, end - pos,
1595 if (ret < 0 || ret >= end - pos)
1600 switch (ssid->mode) {
1601 case WPAS_MODE_INFRA:
1602 ret = os_snprintf(pos, end - pos,
1605 case WPAS_MODE_IBSS:
1606 ret = os_snprintf(pos, end - pos,
1610 ret = os_snprintf(pos, end - pos,
1613 case WPAS_MODE_P2P_GO:
1614 ret = os_snprintf(pos, end - pos,
1617 case WPAS_MODE_P2P_GROUP_FORMATION:
1618 ret = os_snprintf(pos, end - pos,
1619 "mode=P2P GO - group "
1626 if (ret < 0 || ret >= end - pos)
1632 if (wpa_s->ap_iface) {
1633 pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos,
1637 #endif /* CONFIG_AP */
1638 pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose);
1641 if (wpa_s->wpa_state >= WPA_ASSOCIATED &&
1644 #endif /* CONFIG_AP */
1645 wpa_s->sme.sae.state == SAE_ACCEPTED) {
1646 ret = os_snprintf(pos, end - pos, "sae_group=%d\n",
1647 wpa_s->sme.sae.group);
1648 if (ret < 0 || ret >= end - pos)
1652 #endif /* CONFIG_SAE */
1653 ret = os_snprintf(pos, end - pos, "wpa_state=%s\n",
1654 wpa_supplicant_state_txt(wpa_s->wpa_state));
1655 if (ret < 0 || ret >= end - pos)
1660 l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) {
1661 ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp);
1662 if (ret < 0 || ret >= end - pos)
1668 if (wpa_s->global->p2p) {
1669 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
1670 "\n", MAC2STR(wpa_s->global->p2p_dev_addr));
1671 if (ret < 0 || ret >= end - pos)
1675 #endif /* CONFIG_P2P */
1677 ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n",
1678 MAC2STR(wpa_s->own_addr));
1679 if (ret < 0 || ret >= end - pos)
1684 if (wpa_s->current_bss &&
1685 (hs20 = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1686 HS20_IE_VENDOR_TYPE)) &&
1687 wpa_s->wpa_proto == WPA_PROTO_RSN &&
1688 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1691 u8 rel_num = (hs20[6] & 0xf0) >> 4;
1692 release = rel_num + 1;
1694 ret = os_snprintf(pos, end - pos, "hs20=%d\n", release);
1695 if (ret < 0 || ret >= end - pos)
1700 if (wpa_s->current_ssid) {
1701 struct wpa_cred *cred;
1704 for (cred = wpa_s->conf->cred; cred; cred = cred->next) {
1707 if (wpa_s->current_ssid->parent_cred != cred)
1710 if (cred->provisioning_sp) {
1711 ret = os_snprintf(pos, end - pos,
1712 "provisioning_sp=%s\n",
1713 cred->provisioning_sp);
1714 if (ret < 0 || ret >= end - pos)
1723 if (wpa_s->current_bss && wpa_s->current_bss->anqp) {
1724 struct wpabuf *names =
1725 wpa_s->current_bss->anqp->domain_name;
1726 for (i = 0; names && i < cred->num_domain; i++)
1728 if (domain_name_list_contains(
1729 names, cred->domain[i], 1))
1732 if (i == cred->num_domain)
1733 i = 0; /* show first entry by default */
1735 ret = os_snprintf(pos, end - pos, "home_sp=%s\n",
1737 if (ret < 0 || ret >= end - pos)
1742 if (wpa_s->current_bss == NULL ||
1743 wpa_s->current_bss->anqp == NULL)
1746 res = interworking_home_sp_cred(
1748 wpa_s->current_bss->anqp->domain_name);
1756 ret = os_snprintf(pos, end - pos, "sp_type=%s\n", type);
1757 if (ret < 0 || ret >= end - pos)
1764 #endif /* CONFIG_HS20 */
1766 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
1767 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
1768 res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos,
1774 res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose);
1781 uuid_bin2str(wpa_s->wps->uuid, uuid_str, sizeof(uuid_str));
1782 ret = os_snprintf(pos, end - pos, "uuid=%s\n", uuid_str);
1783 if (ret < 0 || ret >= end - pos)
1787 #endif /* CONFIG_WPS */
1791 * Allow using the STATUS command with default behavior, say for debug,
1792 * i.e., don't generate a "fake" CONNECTION and SUPPLICANT_STATE_CHANGE
1793 * events with STATUS-NO_EVENTS.
1795 if (os_strcmp(params, "-NO_EVENTS")) {
1796 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_STATE_CHANGE
1797 "id=%d state=%d BSSID=" MACSTR " SSID=%s",
1798 wpa_s->current_ssid ? wpa_s->current_ssid->id : -1,
1800 MAC2STR(wpa_s->bssid),
1801 wpa_s->current_ssid && wpa_s->current_ssid->ssid ?
1802 wpa_ssid_txt(wpa_s->current_ssid->ssid,
1803 wpa_s->current_ssid->ssid_len) : "");
1804 if (wpa_s->wpa_state == WPA_COMPLETED) {
1805 struct wpa_ssid *ssid = wpa_s->current_ssid;
1806 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_CONNECTED
1807 "- connection to " MACSTR
1808 " completed %s [id=%d id_str=%s]",
1809 MAC2STR(wpa_s->bssid), "(auth)",
1810 ssid ? ssid->id : -1,
1811 ssid && ssid->id_str ? ssid->id_str : "");
1814 #endif /* ANDROID */
1820 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s,
1825 struct wpa_ssid *ssid;
1828 /* cmd: "<network id> <BSSID>" */
1829 pos = os_strchr(cmd, ' ');
1834 wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos);
1835 if (hwaddr_aton(pos, bssid)) {
1836 wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos);
1840 ssid = wpa_config_get_network(wpa_s->conf, id);
1842 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
1847 os_memcpy(ssid->bssid, bssid, ETH_ALEN);
1848 ssid->bssid_set = !is_zero_ether_addr(bssid);
1854 static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant *wpa_s,
1855 char *cmd, char *buf,
1859 struct wpa_blacklist *e;
1863 /* cmd: "BLACKLIST [<BSSID>]" */
1867 e = wpa_s->blacklist;
1869 ret = os_snprintf(pos, end - pos, MACSTR "\n",
1871 if (ret < 0 || ret >= end - pos)
1880 if (os_strncmp(cmd, "clear", 5) == 0) {
1881 wpa_blacklist_clear(wpa_s);
1882 os_memcpy(buf, "OK\n", 3);
1886 wpa_printf(MSG_DEBUG, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd);
1887 if (hwaddr_aton(cmd, bssid)) {
1888 wpa_printf(MSG_DEBUG, "CTRL_IFACE: invalid BSSID '%s'", cmd);
1893 * Add the BSSID twice, so its count will be 2, causing it to be
1894 * skipped when processing scan results.
1896 ret = wpa_blacklist_add(wpa_s, bssid);
1899 ret = wpa_blacklist_add(wpa_s, bssid);
1902 os_memcpy(buf, "OK\n", 3);
1907 static const char * debug_level_str(int level)
1928 static int str_to_debug_level(const char *s)
1930 if (os_strcasecmp(s, "EXCESSIVE") == 0)
1931 return MSG_EXCESSIVE;
1932 if (os_strcasecmp(s, "MSGDUMP") == 0)
1934 if (os_strcasecmp(s, "DEBUG") == 0)
1936 if (os_strcasecmp(s, "INFO") == 0)
1938 if (os_strcasecmp(s, "WARNING") == 0)
1940 if (os_strcasecmp(s, "ERROR") == 0)
1946 static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant *wpa_s,
1947 char *cmd, char *buf,
1950 char *pos, *end, *stamp;
1957 /* cmd: "LOG_LEVEL [<level>]" */
1961 ret = os_snprintf(pos, end - pos, "Current level: %s\n"
1963 debug_level_str(wpa_debug_level),
1964 wpa_debug_timestamp);
1965 if (ret < 0 || ret >= end - pos)
1974 stamp = os_strchr(cmd, ' ');
1977 while (*stamp == ' ') {
1982 if (cmd && os_strlen(cmd)) {
1983 int level = str_to_debug_level(cmd);
1986 wpa_debug_level = level;
1989 if (stamp && os_strlen(stamp))
1990 wpa_debug_timestamp = atoi(stamp);
1992 os_memcpy(buf, "OK\n", 3);
1997 static int wpa_supplicant_ctrl_iface_list_networks(
1998 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
2001 struct wpa_ssid *ssid;
2006 ret = os_snprintf(pos, end - pos,
2007 "network id / ssid / bssid / flags\n");
2008 if (ret < 0 || ret >= end - pos)
2012 ssid = wpa_s->conf->ssid;
2014 ret = os_snprintf(pos, end - pos, "%d\t%s",
2016 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
2017 if (ret < 0 || ret >= end - pos)
2020 if (ssid->bssid_set) {
2021 ret = os_snprintf(pos, end - pos, "\t" MACSTR,
2022 MAC2STR(ssid->bssid));
2024 ret = os_snprintf(pos, end - pos, "\tany");
2026 if (ret < 0 || ret >= end - pos)
2029 ret = os_snprintf(pos, end - pos, "\t%s%s%s%s",
2030 ssid == wpa_s->current_ssid ?
2032 ssid->disabled ? "[DISABLED]" : "",
2033 ssid->disabled_until.sec ?
2034 "[TEMP-DISABLED]" : "",
2035 ssid->disabled == 2 ? "[P2P-PERSISTENT]" :
2037 if (ret < 0 || ret >= end - pos)
2040 ret = os_snprintf(pos, end - pos, "\n");
2041 if (ret < 0 || ret >= end - pos)
2052 static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher)
2055 ret = os_snprintf(pos, end - pos, "-");
2056 if (ret < 0 || ret >= end - pos)
2059 ret = wpa_write_ciphers(pos, end, cipher, "+");
2067 static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
2068 const u8 *ie, size_t ie_len)
2070 struct wpa_ie_data data;
2074 ret = os_snprintf(pos, end - pos, "[%s-", proto);
2075 if (ret < 0 || ret >= end - pos)
2079 if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) {
2080 ret = os_snprintf(pos, end - pos, "?]");
2081 if (ret < 0 || ret >= end - pos)
2088 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
2089 ret = os_snprintf(pos, end - pos, "%sEAP",
2090 pos == start ? "" : "+");
2091 if (ret < 0 || ret >= end - pos)
2095 if (data.key_mgmt & WPA_KEY_MGMT_PSK) {
2096 ret = os_snprintf(pos, end - pos, "%sPSK",
2097 pos == start ? "" : "+");
2098 if (ret < 0 || ret >= end - pos)
2102 if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
2103 ret = os_snprintf(pos, end - pos, "%sNone",
2104 pos == start ? "" : "+");
2105 if (ret < 0 || ret >= end - pos)
2109 #ifdef CONFIG_IEEE80211R
2110 if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
2111 ret = os_snprintf(pos, end - pos, "%sFT/EAP",
2112 pos == start ? "" : "+");
2113 if (ret < 0 || ret >= end - pos)
2117 if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) {
2118 ret = os_snprintf(pos, end - pos, "%sFT/PSK",
2119 pos == start ? "" : "+");
2120 if (ret < 0 || ret >= end - pos)
2124 #endif /* CONFIG_IEEE80211R */
2125 #ifdef CONFIG_IEEE80211W
2126 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
2127 ret = os_snprintf(pos, end - pos, "%sEAP-SHA256",
2128 pos == start ? "" : "+");
2129 if (ret < 0 || ret >= end - pos)
2133 if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
2134 ret = os_snprintf(pos, end - pos, "%sPSK-SHA256",
2135 pos == start ? "" : "+");
2136 if (ret < 0 || ret >= end - pos)
2140 #endif /* CONFIG_IEEE80211W */
2142 pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher);
2144 if (data.capabilities & WPA_CAPABILITY_PREAUTH) {
2145 ret = os_snprintf(pos, end - pos, "-preauth");
2146 if (ret < 0 || ret >= end - pos)
2151 ret = os_snprintf(pos, end - pos, "]");
2152 if (ret < 0 || ret >= end - pos)
2161 static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s,
2162 char *pos, char *end,
2163 struct wpabuf *wps_ie)
2170 if (wps_is_selected_pbc_registrar(wps_ie))
2172 else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0))
2174 else if (wps_is_selected_pin_registrar(wps_ie))
2179 ret = os_snprintf(pos, end - pos, "%s", txt);
2180 if (ret >= 0 && ret < end - pos)
2182 wpabuf_free(wps_ie);
2185 #endif /* CONFIG_WPS */
2188 static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s,
2189 char *pos, char *end,
2190 const struct wpa_bss *bss)
2193 struct wpabuf *wps_ie;
2194 wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
2195 return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie);
2196 #else /* CONFIG_WPS */
2198 #endif /* CONFIG_WPS */
2202 /* Format one result on one text line into a buffer. */
2203 static int wpa_supplicant_ctrl_iface_scan_result(
2204 struct wpa_supplicant *wpa_s,
2205 const struct wpa_bss *bss, char *buf, size_t buflen)
2209 const u8 *ie, *ie2, *p2p;
2211 p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
2213 p2p = wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE);
2214 if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN &&
2215 os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) ==
2217 return 0; /* Do not show P2P listen discovery results here */
2222 ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t",
2223 MAC2STR(bss->bssid), bss->freq, bss->level);
2224 if (ret < 0 || ret >= end - pos)
2227 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
2229 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]);
2230 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
2232 pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2, 2 + ie2[1]);
2233 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
2234 if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
2235 ret = os_snprintf(pos, end - pos, "[WEP]");
2236 if (ret < 0 || ret >= end - pos)
2240 if (bss_is_dmg(bss)) {
2242 ret = os_snprintf(pos, end - pos, "[DMG]");
2243 if (ret < 0 || ret >= end - pos)
2246 switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
2247 case IEEE80211_CAP_DMG_IBSS:
2250 case IEEE80211_CAP_DMG_AP:
2253 case IEEE80211_CAP_DMG_PBSS:
2260 ret = os_snprintf(pos, end - pos, "%s", s);
2261 if (ret < 0 || ret >= end - pos)
2265 if (bss->caps & IEEE80211_CAP_IBSS) {
2266 ret = os_snprintf(pos, end - pos, "[IBSS]");
2267 if (ret < 0 || ret >= end - pos)
2271 if (bss->caps & IEEE80211_CAP_ESS) {
2272 ret = os_snprintf(pos, end - pos, "[ESS]");
2273 if (ret < 0 || ret >= end - pos)
2279 ret = os_snprintf(pos, end - pos, "[P2P]");
2280 if (ret < 0 || ret >= end - pos)
2285 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE) && ie2) {
2286 ret = os_snprintf(pos, end - pos, "[HS20]");
2287 if (ret < 0 || ret >= end - pos)
2291 #endif /* CONFIG_HS20 */
2293 ret = os_snprintf(pos, end - pos, "\t%s",
2294 wpa_ssid_txt(bss->ssid, bss->ssid_len));
2295 if (ret < 0 || ret >= end - pos)
2299 ret = os_snprintf(pos, end - pos, "\n");
2300 if (ret < 0 || ret >= end - pos)
2308 static int wpa_supplicant_ctrl_iface_scan_results(
2309 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
2312 struct wpa_bss *bss;
2317 ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / "
2319 if (ret < 0 || ret >= end - pos)
2323 dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
2324 ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos,
2326 if (ret < 0 || ret >= end - pos)
2335 static int wpa_supplicant_ctrl_iface_select_network(
2336 struct wpa_supplicant *wpa_s, char *cmd)
2339 struct wpa_ssid *ssid;
2342 /* cmd: "<network id>" or "any" */
2343 if (os_strncmp(cmd, "any", 3) == 0) {
2344 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any");
2348 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id);
2350 ssid = wpa_config_get_network(wpa_s->conf, id);
2352 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2353 "network id=%d", id);
2356 if (ssid->disabled == 2) {
2357 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2358 "SELECT_NETWORK with persistent P2P group");
2363 pos = os_strstr(cmd, " freq=");
2365 int *freqs = freq_range_to_channel_list(wpa_s, pos + 6);
2367 wpa_s->scan_req = MANUAL_SCAN_REQ;
2368 os_free(wpa_s->manual_scan_freqs);
2369 wpa_s->manual_scan_freqs = freqs;
2373 wpa_supplicant_select_network(wpa_s, ssid);
2379 static int wpa_supplicant_ctrl_iface_enable_network(
2380 struct wpa_supplicant *wpa_s, char *cmd)
2383 struct wpa_ssid *ssid;
2385 /* cmd: "<network id>" or "all" */
2386 if (os_strcmp(cmd, "all") == 0) {
2387 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all");
2391 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id);
2393 ssid = wpa_config_get_network(wpa_s->conf, id);
2395 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2396 "network id=%d", id);
2399 if (ssid->disabled == 2) {
2400 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2401 "ENABLE_NETWORK with persistent P2P group");
2405 if (os_strstr(cmd, " no-connect")) {
2410 wpa_supplicant_enable_network(wpa_s, ssid);
2416 static int wpa_supplicant_ctrl_iface_disable_network(
2417 struct wpa_supplicant *wpa_s, char *cmd)
2420 struct wpa_ssid *ssid;
2422 /* cmd: "<network id>" or "all" */
2423 if (os_strcmp(cmd, "all") == 0) {
2424 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all");
2428 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id);
2430 ssid = wpa_config_get_network(wpa_s->conf, id);
2432 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2433 "network id=%d", id);
2436 if (ssid->disabled == 2) {
2437 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2438 "DISABLE_NETWORK with persistent P2P "
2443 wpa_supplicant_disable_network(wpa_s, ssid);
2449 static int wpa_supplicant_ctrl_iface_add_network(
2450 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
2452 struct wpa_ssid *ssid;
2455 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK");
2457 ssid = wpa_config_add_network(wpa_s->conf);
2461 wpas_notify_network_added(wpa_s, ssid);
2464 wpa_config_set_network_defaults(ssid);
2466 ret = os_snprintf(buf, buflen, "%d\n", ssid->id);
2467 if (ret < 0 || (size_t) ret >= buflen)
2473 static int wpa_supplicant_ctrl_iface_remove_network(
2474 struct wpa_supplicant *wpa_s, char *cmd)
2477 struct wpa_ssid *ssid;
2480 /* cmd: "<network id>" or "all" */
2481 if (os_strcmp(cmd, "all") == 0) {
2482 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all");
2483 if (wpa_s->sched_scanning)
2484 wpa_supplicant_cancel_sched_scan(wpa_s);
2486 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2487 if (wpa_s->current_ssid) {
2489 wpa_s->sme.prev_bssid_set = 0;
2490 #endif /* CONFIG_SME */
2491 wpa_sm_set_config(wpa_s->wpa, NULL);
2492 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
2493 wpa_supplicant_deauthenticate(
2494 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2496 ssid = wpa_s->conf->ssid;
2498 struct wpa_ssid *remove_ssid = ssid;
2501 if (wpa_s->last_ssid == remove_ssid)
2502 wpa_s->last_ssid = NULL;
2503 wpas_notify_network_removed(wpa_s, remove_ssid);
2504 wpa_config_remove_network(wpa_s->conf, id);
2510 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id);
2512 ssid = wpa_config_get_network(wpa_s->conf, id);
2514 wpas_notify_network_removed(wpa_s, ssid);
2516 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2521 if (wpa_s->last_ssid == ssid)
2522 wpa_s->last_ssid = NULL;
2524 if (ssid == wpa_s->current_ssid || wpa_s->current_ssid == NULL) {
2526 wpa_s->sme.prev_bssid_set = 0;
2527 #endif /* CONFIG_SME */
2529 * Invalidate the EAP session cache if the current or
2530 * previously used network is removed.
2532 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2535 if (ssid == wpa_s->current_ssid) {
2536 wpa_sm_set_config(wpa_s->wpa, NULL);
2537 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
2539 wpa_supplicant_deauthenticate(wpa_s,
2540 WLAN_REASON_DEAUTH_LEAVING);
2543 was_disabled = ssid->disabled;
2545 if (wpa_config_remove_network(wpa_s->conf, id) < 0) {
2546 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Not able to remove the "
2547 "network id=%d", id);
2551 if (!was_disabled && wpa_s->sched_scanning) {
2552 wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to remove "
2553 "network from filters");
2554 wpa_supplicant_cancel_sched_scan(wpa_s);
2555 wpa_supplicant_req_scan(wpa_s, 0, 0);
2562 static int wpa_supplicant_ctrl_iface_update_network(
2563 struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
2564 char *name, char *value)
2566 if (wpa_config_set(ssid, name, value, 0) < 0) {
2567 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network "
2568 "variable '%s'", name);
2572 if (os_strcmp(name, "bssid") != 0 &&
2573 os_strcmp(name, "priority") != 0)
2574 wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
2576 if (wpa_s->current_ssid == ssid || wpa_s->current_ssid == NULL) {
2578 * Invalidate the EAP session cache if anything in the current
2579 * or previously used configuration changes.
2581 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2584 if ((os_strcmp(name, "psk") == 0 &&
2585 value[0] == '"' && ssid->ssid_len) ||
2586 (os_strcmp(name, "ssid") == 0 && ssid->passphrase))
2587 wpa_config_update_psk(ssid);
2588 else if (os_strcmp(name, "priority") == 0)
2589 wpa_config_update_prio_list(wpa_s->conf);
2595 static int wpa_supplicant_ctrl_iface_set_network(
2596 struct wpa_supplicant *wpa_s, char *cmd)
2598 int id, ret, prev_bssid_set;
2599 struct wpa_ssid *ssid;
2601 u8 prev_bssid[ETH_ALEN];
2603 /* cmd: "<network id> <variable name> <value>" */
2604 name = os_strchr(cmd, ' ');
2609 value = os_strchr(name, ' ');
2615 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
2617 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
2618 (u8 *) value, os_strlen(value));
2620 ssid = wpa_config_get_network(wpa_s->conf, id);
2622 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2627 prev_bssid_set = ssid->bssid_set;
2628 os_memcpy(prev_bssid, ssid->bssid, ETH_ALEN);
2629 ret = wpa_supplicant_ctrl_iface_update_network(wpa_s, ssid, name,
2632 (ssid->bssid_set != prev_bssid_set ||
2633 os_memcmp(ssid->bssid, prev_bssid, ETH_ALEN) != 0))
2634 wpas_notify_network_bssid_set_changed(wpa_s, ssid);
2639 static int wpa_supplicant_ctrl_iface_get_network(
2640 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
2644 struct wpa_ssid *ssid;
2647 /* cmd: "<network id> <variable name>" */
2648 name = os_strchr(cmd, ' ');
2649 if (name == NULL || buflen == 0)
2654 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
2657 ssid = wpa_config_get_network(wpa_s->conf, id);
2659 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2664 value = wpa_config_get_no_key(ssid, name);
2665 if (value == NULL) {
2666 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
2667 "variable '%s'", name);
2671 res = os_strlcpy(buf, value, buflen);
2672 if (res >= buflen) {
2683 static int wpa_supplicant_ctrl_iface_dup_network(
2684 struct wpa_supplicant *wpa_s, char *cmd)
2686 struct wpa_ssid *ssid_s, *ssid_d;
2687 char *name, *id, *value;
2688 int id_s, id_d, ret;
2690 /* cmd: "<src network id> <dst network id> <variable name>" */
2691 id = os_strchr(cmd, ' ');
2696 name = os_strchr(id, ' ');
2703 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DUP_NETWORK id=%d -> %d name='%s'",
2706 ssid_s = wpa_config_get_network(wpa_s->conf, id_s);
2707 if (ssid_s == NULL) {
2708 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2709 "network id=%d", id_s);
2713 ssid_d = wpa_config_get_network(wpa_s->conf, id_d);
2714 if (ssid_d == NULL) {
2715 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2716 "network id=%d", id_s);
2720 value = wpa_config_get(ssid_s, name);
2721 if (value == NULL) {
2722 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
2723 "variable '%s'", name);
2727 ret = wpa_supplicant_ctrl_iface_update_network(wpa_s, ssid_d, name,
2736 static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant *wpa_s,
2737 char *buf, size_t buflen)
2740 struct wpa_cred *cred;
2745 ret = os_snprintf(pos, end - pos,
2746 "cred id / realm / username / domain / imsi\n");
2747 if (ret < 0 || ret >= end - pos)
2751 cred = wpa_s->conf->cred;
2753 ret = os_snprintf(pos, end - pos, "%d\t%s\t%s\t%s\t%s\n",
2754 cred->id, cred->realm ? cred->realm : "",
2755 cred->username ? cred->username : "",
2756 cred->domain ? cred->domain[0] : "",
2757 cred->imsi ? cred->imsi : "");
2758 if (ret < 0 || ret >= end - pos)
2769 static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant *wpa_s,
2770 char *buf, size_t buflen)
2772 struct wpa_cred *cred;
2775 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_CRED");
2777 cred = wpa_config_add_cred(wpa_s->conf);
2781 wpa_msg(wpa_s, MSG_INFO, CRED_ADDED "%d", cred->id);
2783 ret = os_snprintf(buf, buflen, "%d\n", cred->id);
2784 if (ret < 0 || (size_t) ret >= buflen)
2790 static int wpas_ctrl_remove_cred(struct wpa_supplicant *wpa_s,
2791 struct wpa_cred *cred)
2793 struct wpa_ssid *ssid;
2798 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred");
2803 if (wpa_config_remove_cred(wpa_s->conf, id) < 0) {
2804 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred");
2808 wpa_msg(wpa_s, MSG_INFO, CRED_REMOVED "%d", id);
2810 /* Remove any network entry created based on the removed credential */
2811 ssid = wpa_s->conf->ssid;
2813 if (ssid->parent_cred == cred) {
2814 wpa_printf(MSG_DEBUG, "Remove network id %d since it "
2815 "used the removed credential", ssid->id);
2816 os_snprintf(str, sizeof(str), "%d", ssid->id);
2818 wpa_supplicant_ctrl_iface_remove_network(wpa_s, str);
2827 static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s,
2831 struct wpa_cred *cred, *prev;
2833 /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or
2834 * "provisioning_sp=<FQDN> */
2835 if (os_strcmp(cmd, "all") == 0) {
2836 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED all");
2837 cred = wpa_s->conf->cred;
2841 wpas_ctrl_remove_cred(wpa_s, prev);
2846 if (os_strncmp(cmd, "sp_fqdn=", 8) == 0) {
2847 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
2849 cred = wpa_s->conf->cred;
2855 for (i = 0; i < prev->num_domain; i++) {
2856 if (os_strcmp(prev->domain[i], cmd + 8)
2859 wpas_ctrl_remove_cred(wpa_s, prev);
2867 if (os_strncmp(cmd, "provisioning_sp=", 16) == 0) {
2868 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'",
2870 cred = wpa_s->conf->cred;
2874 if (prev->provisioning_sp &&
2875 os_strcmp(prev->provisioning_sp, cmd + 16) == 0)
2876 wpas_ctrl_remove_cred(wpa_s, prev);
2882 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED id=%d", id);
2884 cred = wpa_config_get_cred(wpa_s->conf, id);
2885 return wpas_ctrl_remove_cred(wpa_s, cred);
2889 static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant *wpa_s,
2893 struct wpa_cred *cred;
2896 /* cmd: "<cred id> <variable name> <value>" */
2897 name = os_strchr(cmd, ' ');
2902 value = os_strchr(name, ' ');
2908 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_CRED id=%d name='%s'",
2910 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
2911 (u8 *) value, os_strlen(value));
2913 cred = wpa_config_get_cred(wpa_s->conf, id);
2915 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
2920 if (wpa_config_set_cred(cred, name, value, 0) < 0) {
2921 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set cred "
2922 "variable '%s'", name);
2926 wpa_msg(wpa_s, MSG_INFO, CRED_MODIFIED "%d %s", cred->id, name);
2932 static int wpa_supplicant_ctrl_iface_get_cred(struct wpa_supplicant *wpa_s,
2933 char *cmd, char *buf,
2938 struct wpa_cred *cred;
2941 /* cmd: "<cred id> <variable name>" */
2942 name = os_strchr(cmd, ' ');
2948 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CRED id=%d name='%s'",
2951 cred = wpa_config_get_cred(wpa_s->conf, id);
2953 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
2958 value = wpa_config_get_cred_no_key(cred, name);
2959 if (value == NULL) {
2960 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get cred variable '%s'",
2965 res = os_strlcpy(buf, value, buflen);
2966 if (res >= buflen) {
2977 #ifndef CONFIG_NO_CONFIG_WRITE
2978 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s)
2982 if (!wpa_s->conf->update_config) {
2983 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
2984 "to update configuration (update_config=0)");
2988 ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
2990 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to "
2991 "update configuration");
2993 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration"
2999 #endif /* CONFIG_NO_CONFIG_WRITE */
3002 struct cipher_info {
3008 static const struct cipher_info ciphers[] = {
3009 { WPA_DRIVER_CAPA_ENC_CCMP_256, "CCMP-256", 0 },
3010 { WPA_DRIVER_CAPA_ENC_GCMP_256, "GCMP-256", 0 },
3011 { WPA_DRIVER_CAPA_ENC_CCMP, "CCMP", 0 },
3012 { WPA_DRIVER_CAPA_ENC_GCMP, "GCMP", 0 },
3013 { WPA_DRIVER_CAPA_ENC_TKIP, "TKIP", 0 },
3014 { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE, "NONE", 0 },
3015 { WPA_DRIVER_CAPA_ENC_WEP104, "WEP104", 1 },
3016 { WPA_DRIVER_CAPA_ENC_WEP40, "WEP40", 1 }
3020 static int ctrl_iface_get_capability_pairwise(int res, char *strict,
3021 struct wpa_driver_capa *capa,
3022 char *buf, size_t buflen)
3035 len = os_strlcpy(buf, "CCMP TKIP NONE", buflen);
3041 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
3042 if (!ciphers[i].group_only && capa->enc & ciphers[i].capa) {
3043 ret = os_snprintf(pos, end - pos, "%s%s",
3044 pos == buf ? "" : " ",
3046 if (ret < 0 || ret >= end - pos)
3056 static int ctrl_iface_get_capability_group(int res, char *strict,
3057 struct wpa_driver_capa *capa,
3058 char *buf, size_t buflen)
3071 len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen);
3077 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
3078 if (capa->enc & ciphers[i].capa) {
3079 ret = os_snprintf(pos, end - pos, "%s%s",
3080 pos == buf ? "" : " ",
3082 if (ret < 0 || ret >= end - pos)
3092 static int ctrl_iface_get_capability_key_mgmt(int res, char *strict,
3093 struct wpa_driver_capa *capa,
3094 char *buf, size_t buflen)
3106 len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
3113 ret = os_snprintf(pos, end - pos, "NONE IEEE8021X");
3114 if (ret < 0 || ret >= end - pos)
3118 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
3119 WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
3120 ret = os_snprintf(pos, end - pos, " WPA-EAP");
3121 if (ret < 0 || ret >= end - pos)
3126 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
3127 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
3128 ret = os_snprintf(pos, end - pos, " WPA-PSK");
3129 if (ret < 0 || ret >= end - pos)
3134 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
3135 ret = os_snprintf(pos, end - pos, " WPA-NONE");
3136 if (ret < 0 || ret >= end - pos)
3145 static int ctrl_iface_get_capability_proto(int res, char *strict,
3146 struct wpa_driver_capa *capa,
3147 char *buf, size_t buflen)
3159 len = os_strlcpy(buf, "RSN WPA", buflen);
3165 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
3166 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
3167 ret = os_snprintf(pos, end - pos, "%sRSN",
3168 pos == buf ? "" : " ");
3169 if (ret < 0 || ret >= end - pos)
3174 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
3175 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
3176 ret = os_snprintf(pos, end - pos, "%sWPA",
3177 pos == buf ? "" : " ");
3178 if (ret < 0 || ret >= end - pos)
3187 static int ctrl_iface_get_capability_auth_alg(int res, char *strict,
3188 struct wpa_driver_capa *capa,
3189 char *buf, size_t buflen)
3201 len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen);
3207 if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) {
3208 ret = os_snprintf(pos, end - pos, "%sOPEN",
3209 pos == buf ? "" : " ");
3210 if (ret < 0 || ret >= end - pos)
3215 if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) {
3216 ret = os_snprintf(pos, end - pos, "%sSHARED",
3217 pos == buf ? "" : " ");
3218 if (ret < 0 || ret >= end - pos)
3223 if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) {
3224 ret = os_snprintf(pos, end - pos, "%sLEAP",
3225 pos == buf ? "" : " ");
3226 if (ret < 0 || ret >= end - pos)
3235 static int ctrl_iface_get_capability_modes(int res, char *strict,
3236 struct wpa_driver_capa *capa,
3237 char *buf, size_t buflen)
3249 len = os_strlcpy(buf, "IBSS AP", buflen);
3255 if (capa->flags & WPA_DRIVER_FLAGS_IBSS) {
3256 ret = os_snprintf(pos, end - pos, "%sIBSS",
3257 pos == buf ? "" : " ");
3258 if (ret < 0 || ret >= end - pos)
3263 if (capa->flags & WPA_DRIVER_FLAGS_AP) {
3264 ret = os_snprintf(pos, end - pos, "%sAP",
3265 pos == buf ? "" : " ");
3266 if (ret < 0 || ret >= end - pos)
3275 static int ctrl_iface_get_capability_channels(struct wpa_supplicant *wpa_s,
3276 char *buf, size_t buflen)
3278 struct hostapd_channel_data *chnl;
3280 char *pos, *end, *hmode;
3285 for (j = 0; j < wpa_s->hw.num_modes; j++) {
3286 switch (wpa_s->hw.modes[j].mode) {
3287 case HOSTAPD_MODE_IEEE80211B:
3290 case HOSTAPD_MODE_IEEE80211G:
3293 case HOSTAPD_MODE_IEEE80211A:
3296 case HOSTAPD_MODE_IEEE80211AD:
3302 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:", hmode);
3303 if (ret < 0 || ret >= end - pos)
3306 chnl = wpa_s->hw.modes[j].channels;
3307 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
3308 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
3310 ret = os_snprintf(pos, end - pos, " %d", chnl[i].chan);
3311 if (ret < 0 || ret >= end - pos)
3315 ret = os_snprintf(pos, end - pos, "\n");
3316 if (ret < 0 || ret >= end - pos)
3325 static int ctrl_iface_get_capability_freq(struct wpa_supplicant *wpa_s,
3326 char *buf, size_t buflen)
3328 struct hostapd_channel_data *chnl;
3330 char *pos, *end, *hmode;
3335 for (j = 0; j < wpa_s->hw.num_modes; j++) {
3336 switch (wpa_s->hw.modes[j].mode) {
3337 case HOSTAPD_MODE_IEEE80211B:
3340 case HOSTAPD_MODE_IEEE80211G:
3343 case HOSTAPD_MODE_IEEE80211A:
3346 case HOSTAPD_MODE_IEEE80211AD:
3352 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:\n",
3354 if (ret < 0 || ret >= end - pos)
3357 chnl = wpa_s->hw.modes[j].channels;
3358 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
3359 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
3361 ret = os_snprintf(pos, end - pos, " %d = %d MHz%s%s\n",
3362 chnl[i].chan, chnl[i].freq,
3363 chnl[i].flag & HOSTAPD_CHAN_NO_IBSS ?
3365 chnl[i].flag & HOSTAPD_CHAN_RADAR ?
3368 if (ret < 0 || ret >= end - pos)
3372 ret = os_snprintf(pos, end - pos, "\n");
3373 if (ret < 0 || ret >= end - pos)
3382 static int wpa_supplicant_ctrl_iface_get_capability(
3383 struct wpa_supplicant *wpa_s, const char *_field, char *buf,
3386 struct wpa_driver_capa capa;
3392 /* Determine whether or not strict checking was requested */
3393 len = os_strlcpy(field, _field, sizeof(field));
3394 if (len >= sizeof(field))
3396 strict = os_strchr(field, ' ');
3397 if (strict != NULL) {
3399 if (os_strcmp(strict, "strict") != 0)
3403 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
3404 field, strict ? strict : "");
3406 if (os_strcmp(field, "eap") == 0) {
3407 return eap_get_names(buf, buflen);
3410 res = wpa_drv_get_capa(wpa_s, &capa);
3412 if (os_strcmp(field, "pairwise") == 0)
3413 return ctrl_iface_get_capability_pairwise(res, strict, &capa,
3416 if (os_strcmp(field, "group") == 0)
3417 return ctrl_iface_get_capability_group(res, strict, &capa,
3420 if (os_strcmp(field, "key_mgmt") == 0)
3421 return ctrl_iface_get_capability_key_mgmt(res, strict, &capa,
3424 if (os_strcmp(field, "proto") == 0)
3425 return ctrl_iface_get_capability_proto(res, strict, &capa,
3428 if (os_strcmp(field, "auth_alg") == 0)
3429 return ctrl_iface_get_capability_auth_alg(res, strict, &capa,
3432 if (os_strcmp(field, "modes") == 0)
3433 return ctrl_iface_get_capability_modes(res, strict, &capa,
3436 if (os_strcmp(field, "channels") == 0)
3437 return ctrl_iface_get_capability_channels(wpa_s, buf, buflen);
3439 if (os_strcmp(field, "freq") == 0)
3440 return ctrl_iface_get_capability_freq(wpa_s, buf, buflen);
3443 if (os_strcmp(field, "tdls") == 0)
3444 return ctrl_iface_get_capability_tdls(wpa_s, buf, buflen);
3445 #endif /* CONFIG_TDLS */
3447 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
3454 #ifdef CONFIG_INTERWORKING
3455 static char * anqp_add_hex(char *pos, char *end, const char *title,
3456 struct wpabuf *data)
3466 ret = os_snprintf(pos, end - pos, "%s=", title);
3467 if (ret < 0 || ret >= end - pos)
3471 d = wpabuf_head_u8(data);
3472 for (i = 0; i < wpabuf_len(data); i++) {
3473 ret = os_snprintf(pos, end - pos, "%02x", *d++);
3474 if (ret < 0 || ret >= end - pos)
3479 ret = os_snprintf(pos, end - pos, "\n");
3480 if (ret < 0 || ret >= end - pos)
3486 #endif /* CONFIG_INTERWORKING */
3489 static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
3490 unsigned long mask, char *buf, size_t buflen)
3500 if (mask & WPA_BSS_MASK_ID) {
3501 ret = os_snprintf(pos, end - pos, "id=%u\n", bss->id);
3502 if (ret < 0 || ret >= end - pos)
3507 if (mask & WPA_BSS_MASK_BSSID) {
3508 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
3509 MAC2STR(bss->bssid));
3510 if (ret < 0 || ret >= end - pos)
3515 if (mask & WPA_BSS_MASK_FREQ) {
3516 ret = os_snprintf(pos, end - pos, "freq=%d\n", bss->freq);
3517 if (ret < 0 || ret >= end - pos)
3522 if (mask & WPA_BSS_MASK_BEACON_INT) {
3523 ret = os_snprintf(pos, end - pos, "beacon_int=%d\n",
3525 if (ret < 0 || ret >= end - pos)
3530 if (mask & WPA_BSS_MASK_CAPABILITIES) {
3531 ret = os_snprintf(pos, end - pos, "capabilities=0x%04x\n",
3533 if (ret < 0 || ret >= end - pos)
3538 if (mask & WPA_BSS_MASK_QUAL) {
3539 ret = os_snprintf(pos, end - pos, "qual=%d\n", bss->qual);
3540 if (ret < 0 || ret >= end - pos)
3545 if (mask & WPA_BSS_MASK_NOISE) {
3546 ret = os_snprintf(pos, end - pos, "noise=%d\n", bss->noise);
3547 if (ret < 0 || ret >= end - pos)
3552 if (mask & WPA_BSS_MASK_LEVEL) {
3553 ret = os_snprintf(pos, end - pos, "level=%d\n", bss->level);
3554 if (ret < 0 || ret >= end - pos)
3559 if (mask & WPA_BSS_MASK_TSF) {
3560 ret = os_snprintf(pos, end - pos, "tsf=%016llu\n",
3561 (unsigned long long) bss->tsf);
3562 if (ret < 0 || ret >= end - pos)
3567 if (mask & WPA_BSS_MASK_AGE) {
3568 struct os_reltime now;
3570 os_get_reltime(&now);
3571 ret = os_snprintf(pos, end - pos, "age=%d\n",
3572 (int) (now.sec - bss->last_update.sec));
3573 if (ret < 0 || ret >= end - pos)
3578 if (mask & WPA_BSS_MASK_IE) {
3579 ret = os_snprintf(pos, end - pos, "ie=");
3580 if (ret < 0 || ret >= end - pos)
3584 ie = (const u8 *) (bss + 1);
3585 for (i = 0; i < bss->ie_len; i++) {
3586 ret = os_snprintf(pos, end - pos, "%02x", *ie++);
3587 if (ret < 0 || ret >= end - pos)
3592 ret = os_snprintf(pos, end - pos, "\n");
3593 if (ret < 0 || ret >= end - pos)
3598 if (mask & WPA_BSS_MASK_FLAGS) {
3599 ret = os_snprintf(pos, end - pos, "flags=");
3600 if (ret < 0 || ret >= end - pos)
3604 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
3606 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie,
3608 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
3610 pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2,
3612 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
3613 if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
3614 ret = os_snprintf(pos, end - pos, "[WEP]");
3615 if (ret < 0 || ret >= end - pos)
3619 if (bss_is_dmg(bss)) {
3621 ret = os_snprintf(pos, end - pos, "[DMG]");
3622 if (ret < 0 || ret >= end - pos)
3625 switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
3626 case IEEE80211_CAP_DMG_IBSS:
3629 case IEEE80211_CAP_DMG_AP:
3632 case IEEE80211_CAP_DMG_PBSS:
3639 ret = os_snprintf(pos, end - pos, "%s", s);
3640 if (ret < 0 || ret >= end - pos)
3644 if (bss->caps & IEEE80211_CAP_IBSS) {
3645 ret = os_snprintf(pos, end - pos, "[IBSS]");
3646 if (ret < 0 || ret >= end - pos)
3650 if (bss->caps & IEEE80211_CAP_ESS) {
3651 ret = os_snprintf(pos, end - pos, "[ESS]");
3652 if (ret < 0 || ret >= end - pos)
3657 if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
3658 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
3659 ret = os_snprintf(pos, end - pos, "[P2P]");
3660 if (ret < 0 || ret >= end - pos)
3665 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) {
3666 ret = os_snprintf(pos, end - pos, "[HS20]");
3667 if (ret < 0 || ret >= end - pos)
3671 #endif /* CONFIG_HS20 */
3673 ret = os_snprintf(pos, end - pos, "\n");
3674 if (ret < 0 || ret >= end - pos)
3679 if (mask & WPA_BSS_MASK_SSID) {
3680 ret = os_snprintf(pos, end - pos, "ssid=%s\n",
3681 wpa_ssid_txt(bss->ssid, bss->ssid_len));
3682 if (ret < 0 || ret >= end - pos)
3688 if (mask & WPA_BSS_MASK_WPS_SCAN) {
3689 ie = (const u8 *) (bss + 1);
3690 ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end);
3691 if (ret < 0 || ret >= end - pos)
3695 #endif /* CONFIG_WPS */
3698 if (mask & WPA_BSS_MASK_P2P_SCAN) {
3699 ie = (const u8 *) (bss + 1);
3700 ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end);
3701 if (ret < 0 || ret >= end - pos)
3705 #endif /* CONFIG_P2P */
3707 #ifdef CONFIG_WIFI_DISPLAY
3708 if (mask & WPA_BSS_MASK_WIFI_DISPLAY) {
3710 ie = (const u8 *) (bss + 1);
3711 wfd = ieee802_11_vendor_ie_concat(ie, bss->ie_len,
3712 WFD_IE_VENDOR_TYPE);
3714 ret = os_snprintf(pos, end - pos, "wfd_subelems=");
3715 if (ret < 0 || ret >= end - pos) {
3721 pos += wpa_snprintf_hex(pos, end - pos,
3726 ret = os_snprintf(pos, end - pos, "\n");
3727 if (ret < 0 || ret >= end - pos)
3732 #endif /* CONFIG_WIFI_DISPLAY */
3734 #ifdef CONFIG_INTERWORKING
3735 if ((mask & WPA_BSS_MASK_INTERNETW) && bss->anqp) {
3736 struct wpa_bss_anqp *anqp = bss->anqp;
3737 pos = anqp_add_hex(pos, end, "anqp_venue_name",
3739 pos = anqp_add_hex(pos, end, "anqp_network_auth_type",
3740 anqp->network_auth_type);
3741 pos = anqp_add_hex(pos, end, "anqp_roaming_consortium",
3742 anqp->roaming_consortium);
3743 pos = anqp_add_hex(pos, end, "anqp_ip_addr_type_availability",
3744 anqp->ip_addr_type_availability);
3745 pos = anqp_add_hex(pos, end, "anqp_nai_realm",
3747 pos = anqp_add_hex(pos, end, "anqp_3gpp", anqp->anqp_3gpp);
3748 pos = anqp_add_hex(pos, end, "anqp_domain_name",
3751 pos = anqp_add_hex(pos, end, "hs20_operator_friendly_name",
3752 anqp->hs20_operator_friendly_name);
3753 pos = anqp_add_hex(pos, end, "hs20_wan_metrics",
3754 anqp->hs20_wan_metrics);
3755 pos = anqp_add_hex(pos, end, "hs20_connection_capability",
3756 anqp->hs20_connection_capability);
3757 pos = anqp_add_hex(pos, end, "hs20_operating_class",
3758 anqp->hs20_operating_class);
3759 pos = anqp_add_hex(pos, end, "hs20_osu_providers_list",
3760 anqp->hs20_osu_providers_list);
3761 #endif /* CONFIG_HS20 */
3763 #endif /* CONFIG_INTERWORKING */
3765 if (mask & WPA_BSS_MASK_DELIM) {
3766 ret = os_snprintf(pos, end - pos, "====\n");
3767 if (ret < 0 || ret >= end - pos)
3776 static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
3777 const char *cmd, char *buf,
3782 struct wpa_bss *bss;
3783 struct wpa_bss *bsslast = NULL;
3784 struct dl_list *next;
3788 unsigned long mask = WPA_BSS_MASK_ALL;
3790 if (os_strncmp(cmd, "RANGE=", 6) == 0) {
3791 if (os_strncmp(cmd + 6, "ALL", 3) == 0) {
3792 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss,
3794 bsslast = dl_list_last(&wpa_s->bss_id, struct wpa_bss,
3796 } else { /* N1-N2 */
3797 unsigned int id1, id2;
3799 if ((ctmp = os_strchr(cmd + 6, '-')) == NULL) {
3800 wpa_printf(MSG_INFO, "Wrong BSS range "
3805 if (*(cmd + 6) == '-')
3808 id1 = atoi(cmd + 6);
3810 if (*ctmp >= '0' && *ctmp <= '9')
3813 id2 = (unsigned int) -1;
3814 bss = wpa_bss_get_id_range(wpa_s, id1, id2);
3815 if (id2 == (unsigned int) -1)
3816 bsslast = dl_list_last(&wpa_s->bss_id,
3820 bsslast = wpa_bss_get_id(wpa_s, id2);
3821 if (bsslast == NULL && bss && id2 > id1) {
3822 struct wpa_bss *tmp = bss;
3824 next = tmp->list_id.next;
3825 if (next == &wpa_s->bss_id)
3827 tmp = dl_list_entry(
3828 next, struct wpa_bss,
3837 } else if (os_strncmp(cmd, "FIRST", 5) == 0)
3838 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, list_id);
3839 else if (os_strncmp(cmd, "LAST", 4) == 0)
3840 bss = dl_list_last(&wpa_s->bss_id, struct wpa_bss, list_id);
3841 else if (os_strncmp(cmd, "ID-", 3) == 0) {
3843 bss = wpa_bss_get_id(wpa_s, i);
3844 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
3846 bss = wpa_bss_get_id(wpa_s, i);
3848 next = bss->list_id.next;
3849 if (next == &wpa_s->bss_id)
3852 bss = dl_list_entry(next, struct wpa_bss,
3856 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
3857 if (hwaddr_aton(cmd + 13, bssid) == 0)
3858 bss = wpa_bss_get_p2p_dev_addr(wpa_s, bssid);
3861 #endif /* CONFIG_P2P */
3862 } else if (hwaddr_aton(cmd, bssid) == 0)
3863 bss = wpa_bss_get_bssid(wpa_s, bssid);
3865 struct wpa_bss *tmp;
3868 dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id)
3877 if ((ctmp = os_strstr(cmd, "MASK=")) != NULL) {
3878 mask = strtoul(ctmp + 5, NULL, 0x10);
3880 mask = WPA_BSS_MASK_ALL;
3886 if (bsslast == NULL)
3889 len = print_bss_info(wpa_s, bss, mask, buf, buflen);
3893 if (bss == bsslast) {
3894 if ((mask & WPA_BSS_MASK_DELIM) && len &&
3895 (bss == dl_list_last(&wpa_s->bss_id,
3896 struct wpa_bss, list_id)))
3897 os_snprintf(buf - 5, 5, "####\n");
3900 next = bss->list_id.next;
3901 if (next == &wpa_s->bss_id)
3903 bss = dl_list_entry(next, struct wpa_bss, list_id);
3904 } while (bss && len);
3910 static int wpa_supplicant_ctrl_iface_ap_scan(
3911 struct wpa_supplicant *wpa_s, char *cmd)
3913 int ap_scan = atoi(cmd);
3914 return wpa_supplicant_set_ap_scan(wpa_s, ap_scan);
3918 static int wpa_supplicant_ctrl_iface_scan_interval(
3919 struct wpa_supplicant *wpa_s, char *cmd)
3921 int scan_int = atoi(cmd);
3922 return wpa_supplicant_set_scan_interval(wpa_s, scan_int);
3926 static int wpa_supplicant_ctrl_iface_bss_expire_age(
3927 struct wpa_supplicant *wpa_s, char *cmd)
3929 int expire_age = atoi(cmd);
3930 return wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age);
3934 static int wpa_supplicant_ctrl_iface_bss_expire_count(
3935 struct wpa_supplicant *wpa_s, char *cmd)
3937 int expire_count = atoi(cmd);
3938 return wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count);
3942 static int wpa_supplicant_ctrl_iface_bss_flush(
3943 struct wpa_supplicant *wpa_s, char *cmd)
3945 int flush_age = atoi(cmd);
3948 wpa_bss_flush(wpa_s);
3950 wpa_bss_flush_by_age(wpa_s, flush_age);
3955 #ifdef CONFIG_TESTING_OPTIONS
3956 static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s)
3958 wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication");
3959 /* MLME-DELETEKEYS.request */
3960 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL, 0);
3961 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL, 0);
3962 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL, 0);
3963 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL, 0);
3964 #ifdef CONFIG_IEEE80211W
3965 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL, 0);
3966 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL, 0);
3967 #endif /* CONFIG_IEEE80211W */
3969 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, wpa_s->bssid, 0, 0, NULL, 0, NULL,
3971 /* MLME-SETPROTECTION.request(None) */
3972 wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid,
3973 MLME_SETPROTECTION_PROTECT_TYPE_NONE,
3974 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE);
3975 wpa_sm_drop_sa(wpa_s->wpa);
3977 #endif /* CONFIG_TESTING_OPTIONS */
3980 static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s,
3983 #ifdef CONFIG_NO_SCAN_PROCESSING
3985 #else /* CONFIG_NO_SCAN_PROCESSING */
3987 struct wpa_bss *bss;
3988 struct wpa_ssid *ssid = wpa_s->current_ssid;
3990 if (hwaddr_aton(addr, bssid)) {
3991 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid "
3992 "address '%s'", addr);
3996 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR, MAC2STR(bssid));
3999 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network "
4000 "configuration known for the target AP");
4004 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
4006 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found "
4012 * TODO: Find best network configuration block from configuration to
4013 * allow roaming to other networks
4016 wpa_s->reassociate = 1;
4017 wpa_supplicant_connect(wpa_s, bss, ssid);
4020 #endif /* CONFIG_NO_SCAN_PROCESSING */
4025 static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd)
4027 unsigned int timeout = atoi(cmd);
4028 enum p2p_discovery_type type = P2P_FIND_START_WITH_FULL;
4029 u8 dev_id[ETH_ALEN], *_dev_id = NULL;
4030 u8 dev_type[WPS_DEV_TYPE_LEN], *_dev_type = NULL;
4032 unsigned int search_delay;
4034 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
4035 wpa_dbg(wpa_s, MSG_INFO,
4036 "Reject P2P_FIND since interface is disabled");
4039 if (os_strstr(cmd, "type=social"))
4040 type = P2P_FIND_ONLY_SOCIAL;
4041 else if (os_strstr(cmd, "type=progressive"))
4042 type = P2P_FIND_PROGRESSIVE;
4044 pos = os_strstr(cmd, "dev_id=");
4047 if (hwaddr_aton(pos, dev_id))
4052 pos = os_strstr(cmd, "dev_type=");
4055 if (wps_dev_type_str2bin(pos, dev_type) < 0)
4057 _dev_type = dev_type;
4060 pos = os_strstr(cmd, "delay=");
4063 search_delay = atoi(pos);
4065 search_delay = wpas_p2p_search_delay(wpa_s);
4067 return wpas_p2p_find(wpa_s, timeout, type, _dev_type != NULL, _dev_type,
4068 _dev_id, search_delay);
4072 static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd,
4073 char *buf, size_t buflen)
4078 enum p2p_wps_method wps_method;
4081 int persistent_group, persistent_id = -1;
4090 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad]
4091 * [persistent|persistent=<network id>]
4092 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
4095 if (hwaddr_aton(cmd, addr))
4103 persistent_group = os_strstr(pos, " persistent") != NULL;
4104 pos2 = os_strstr(pos, " persistent=");
4106 struct wpa_ssid *ssid;
4107 persistent_id = atoi(pos2 + 12);
4108 ssid = wpa_config_get_network(wpa_s->conf, persistent_id);
4109 if (ssid == NULL || ssid->disabled != 2 ||
4110 ssid->mode != WPAS_MODE_P2P_GO) {
4111 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
4112 "SSID id=%d for persistent P2P group (GO)",
4117 join = os_strstr(pos, " join") != NULL;
4118 auth = os_strstr(pos, " auth") != NULL;
4119 automatic = os_strstr(pos, " auto") != NULL;
4120 pd = os_strstr(pos, " provdisc") != NULL;
4121 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
4122 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
4125 pos2 = os_strstr(pos, " go_intent=");
4128 go_intent = atoi(pos2);
4129 if (go_intent < 0 || go_intent > 15)
4133 pos2 = os_strstr(pos, " freq=");
4141 if (os_strncmp(pos, "pin", 3) == 0) {
4142 /* Request random PIN (to be displayed) and enable the PIN */
4143 wps_method = WPS_PIN_DISPLAY;
4144 } else if (os_strncmp(pos, "pbc", 3) == 0) {
4145 wps_method = WPS_PBC;
4148 pos = os_strchr(pin, ' ');
4149 wps_method = WPS_PIN_KEYPAD;
4152 if (os_strncmp(pos, "display", 7) == 0)
4153 wps_method = WPS_PIN_DISPLAY;
4155 if (!wps_pin_str_valid(pin)) {
4156 os_memcpy(buf, "FAIL-INVALID-PIN\n", 17);
4161 new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method,
4162 persistent_group, automatic, join,
4163 auth, go_intent, freq, persistent_id, pd,
4165 if (new_pin == -2) {
4166 os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
4169 if (new_pin == -3) {
4170 os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
4175 if (wps_method == WPS_PIN_DISPLAY && pin == NULL) {
4176 ret = os_snprintf(buf, buflen, "%08d", new_pin);
4177 if (ret < 0 || (size_t) ret >= buflen)
4182 os_memcpy(buf, "OK\n", 3);
4187 static int p2p_ctrl_listen(struct wpa_supplicant *wpa_s, char *cmd)
4189 unsigned int timeout = atoi(cmd);
4190 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
4191 wpa_dbg(wpa_s, MSG_INFO,
4192 "Reject P2P_LISTEN since interface is disabled");
4195 return wpas_p2p_listen(wpa_s, timeout);
4199 static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd)
4203 enum wpas_p2p_prov_disc_use use = WPAS_P2P_PD_FOR_GO_NEG;
4205 /* <addr> <config method> [join|auto] */
4207 if (hwaddr_aton(cmd, addr))
4215 if (os_strstr(pos, " join") != NULL)
4216 use = WPAS_P2P_PD_FOR_JOIN;
4217 else if (os_strstr(pos, " auto") != NULL)
4218 use = WPAS_P2P_PD_AUTO;
4220 return wpas_p2p_prov_disc(wpa_s, addr, pos, use);
4224 static int p2p_get_passphrase(struct wpa_supplicant *wpa_s, char *buf,
4227 struct wpa_ssid *ssid = wpa_s->current_ssid;
4229 if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO ||
4230 ssid->passphrase == NULL)
4233 os_strlcpy(buf, ssid->passphrase, buflen);
4234 return os_strlen(buf);
4238 static int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd,
4239 char *buf, size_t buflen)
4243 u8 dst_buf[ETH_ALEN], *dst;
4244 struct wpabuf *tlvs;
4248 if (hwaddr_aton(cmd, dst_buf))
4251 if (dst[0] == 0 && dst[1] == 0 && dst[2] == 0 &&
4252 dst[3] == 0 && dst[4] == 0 && dst[5] == 0)
4259 if (os_strncmp(pos, "upnp ", 5) == 0) {
4262 if (hexstr2bin(pos, &version, 1) < 0)
4268 ref = wpas_p2p_sd_request_upnp(wpa_s, dst, version, pos);
4269 #ifdef CONFIG_WIFI_DISPLAY
4270 } else if (os_strncmp(pos, "wifi-display ", 13) == 0) {
4271 ref = wpas_p2p_sd_request_wifi_display(wpa_s, dst, pos + 13);
4272 #endif /* CONFIG_WIFI_DISPLAY */
4274 len = os_strlen(pos);
4278 tlvs = wpabuf_alloc(len);
4281 if (hexstr2bin(pos, wpabuf_put(tlvs, len), len) < 0) {
4286 ref = wpas_p2p_sd_request(wpa_s, dst, tlvs);
4291 res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref);
4292 if (res < 0 || (unsigned) res >= buflen)
4298 static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s,
4301 long long unsigned val;
4303 if (sscanf(cmd, "%llx", &val) != 1)
4306 return wpas_p2p_sd_cancel_request(wpa_s, req);
4310 static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant *wpa_s, char *cmd)
4315 struct wpabuf *resp_tlvs;
4319 pos = os_strchr(cmd, ' ');
4327 if (hwaddr_aton(pos, dst))
4334 pos2 = os_strchr(pos, ' ');
4338 dialog_token = atoi(pos);
4340 len = os_strlen(pos2);
4344 resp_tlvs = wpabuf_alloc(len);
4345 if (resp_tlvs == NULL)
4347 if (hexstr2bin(pos2, wpabuf_put(resp_tlvs, len), len) < 0) {
4348 wpabuf_free(resp_tlvs);
4352 wpas_p2p_sd_response(wpa_s, freq, dst, dialog_token, resp_tlvs);
4353 wpabuf_free(resp_tlvs);
4358 static int p2p_ctrl_serv_disc_external(struct wpa_supplicant *wpa_s,
4361 if (os_strcmp(cmd, "0") && os_strcmp(cmd, "1"))
4363 wpa_s->p2p_sd_over_ctrl_iface = atoi(cmd);
4368 static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant *wpa_s,
4373 struct wpabuf *query, *resp;
4375 pos = os_strchr(cmd, ' ');
4380 len = os_strlen(cmd);
4384 query = wpabuf_alloc(len);
4387 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
4392 len = os_strlen(pos);
4398 resp = wpabuf_alloc(len);
4403 if (hexstr2bin(pos, wpabuf_put(resp, len), len) < 0) {
4409 if (wpas_p2p_service_add_bonjour(wpa_s, query, resp) < 0) {
4418 static int p2p_ctrl_service_add_upnp(struct wpa_supplicant *wpa_s, char *cmd)
4423 pos = os_strchr(cmd, ' ');
4428 if (hexstr2bin(cmd, &version, 1) < 0)
4431 return wpas_p2p_service_add_upnp(wpa_s, version, pos);
4435 static int p2p_ctrl_service_add(struct wpa_supplicant *wpa_s, char *cmd)
4439 pos = os_strchr(cmd, ' ');
4444 if (os_strcmp(cmd, "bonjour") == 0)
4445 return p2p_ctrl_service_add_bonjour(wpa_s, pos);
4446 if (os_strcmp(cmd, "upnp") == 0)
4447 return p2p_ctrl_service_add_upnp(wpa_s, pos);
4448 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
4453 static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant *wpa_s,
4457 struct wpabuf *query;
4460 len = os_strlen(cmd);
4464 query = wpabuf_alloc(len);
4467 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
4472 ret = wpas_p2p_service_del_bonjour(wpa_s, query);
4478 static int p2p_ctrl_service_del_upnp(struct wpa_supplicant *wpa_s, char *cmd)
4483 pos = os_strchr(cmd, ' ');
4488 if (hexstr2bin(cmd, &version, 1) < 0)
4491 return wpas_p2p_service_del_upnp(wpa_s, version, pos);
4495 static int p2p_ctrl_service_del(struct wpa_supplicant *wpa_s, char *cmd)
4499 pos = os_strchr(cmd, ' ');
4504 if (os_strcmp(cmd, "bonjour") == 0)
4505 return p2p_ctrl_service_del_bonjour(wpa_s, pos);
4506 if (os_strcmp(cmd, "upnp") == 0)
4507 return p2p_ctrl_service_del_upnp(wpa_s, pos);
4508 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
4513 static int p2p_ctrl_reject(struct wpa_supplicant *wpa_s, char *cmd)
4519 if (hwaddr_aton(cmd, addr))
4522 return wpas_p2p_reject(wpa_s, addr);
4526 static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd)
4530 struct wpa_ssid *ssid;
4531 u8 *_peer = NULL, peer[ETH_ALEN];
4532 int freq = 0, pref_freq = 0;
4536 pos = os_strstr(cmd, " peer=");
4539 if (hwaddr_aton(pos, peer))
4543 ssid = wpa_config_get_network(wpa_s->conf, id);
4544 if (ssid == NULL || ssid->disabled != 2) {
4545 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
4546 "for persistent P2P group",
4551 pos = os_strstr(cmd, " freq=");
4559 pos = os_strstr(cmd, " pref=");
4562 pref_freq = atoi(pos);
4567 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
4568 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
4571 return wpas_p2p_invite(wpa_s, _peer, ssid, NULL, freq, ht40, vht,
4576 static int p2p_ctrl_invite_group(struct wpa_supplicant *wpa_s, char *cmd)
4579 u8 peer[ETH_ALEN], go_dev_addr[ETH_ALEN], *go_dev = NULL;
4581 pos = os_strstr(cmd, " peer=");
4587 if (hwaddr_aton(pos, peer)) {
4588 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", pos);
4592 pos = os_strstr(pos, " go_dev_addr=");
4595 if (hwaddr_aton(pos, go_dev_addr)) {
4596 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'",
4600 go_dev = go_dev_addr;
4603 return wpas_p2p_invite_group(wpa_s, cmd, peer, go_dev);
4607 static int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd)
4609 if (os_strncmp(cmd, "persistent=", 11) == 0)
4610 return p2p_ctrl_invite_persistent(wpa_s, cmd + 11);
4611 if (os_strncmp(cmd, "group=", 6) == 0)
4612 return p2p_ctrl_invite_group(wpa_s, cmd + 6);
4618 static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s,
4619 char *cmd, int freq, int ht40,
4623 struct wpa_ssid *ssid;
4626 ssid = wpa_config_get_network(wpa_s->conf, id);
4627 if (ssid == NULL || ssid->disabled != 2) {
4628 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
4629 "for persistent P2P group",
4634 return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq, 0, ht40, vht,
4639 static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd)
4641 int freq = 0, ht40, vht;
4644 pos = os_strstr(cmd, "freq=");
4646 freq = atoi(pos + 5);
4648 vht = (os_strstr(cmd, "vht") != NULL) || wpa_s->conf->p2p_go_vht;
4649 ht40 = (os_strstr(cmd, "ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
4652 if (os_strncmp(cmd, "persistent=", 11) == 0)
4653 return p2p_ctrl_group_add_persistent(wpa_s, cmd + 11, freq,
4655 if (os_strcmp(cmd, "persistent") == 0 ||
4656 os_strncmp(cmd, "persistent ", 11) == 0)
4657 return wpas_p2p_group_add(wpa_s, 1, freq, ht40, vht);
4658 if (os_strncmp(cmd, "freq=", 5) == 0)
4659 return wpas_p2p_group_add(wpa_s, 0, freq, ht40, vht);
4661 return wpas_p2p_group_add(wpa_s, 0, freq, ht40, vht);
4663 wpa_printf(MSG_DEBUG, "CTRL: Invalid P2P_GROUP_ADD parameters '%s'",
4669 static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd,
4670 char *buf, size_t buflen)
4672 u8 addr[ETH_ALEN], *addr_ptr;
4674 const struct p2p_peer_info *info;
4676 char devtype[WPS_DEV_TYPE_BUFSIZE];
4677 struct wpa_ssid *ssid;
4680 if (!wpa_s->global->p2p)
4683 if (os_strcmp(cmd, "FIRST") == 0) {
4686 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
4687 if (hwaddr_aton(cmd + 5, addr) < 0)
4692 if (hwaddr_aton(cmd, addr) < 0)
4698 info = p2p_get_peer_info(wpa_s->global->p2p, addr_ptr, next);
4705 res = os_snprintf(pos, end - pos, MACSTR "\n"
4711 "serial_number=%s\n"
4712 "config_methods=0x%x\n"
4714 "group_capab=0x%x\n"
4716 MAC2STR(info->p2p_device_addr),
4717 wps_dev_type_bin2str(info->pri_dev_type,
4718 devtype, sizeof(devtype)),
4723 info->serial_number,
4724 info->config_methods,
4728 if (res < 0 || res >= end - pos)
4732 for (i = 0; i < info->wps_sec_dev_type_list_len / WPS_DEV_TYPE_LEN; i++)
4735 t = &info->wps_sec_dev_type_list[i * WPS_DEV_TYPE_LEN];
4736 res = os_snprintf(pos, end - pos, "sec_dev_type=%s\n",
4737 wps_dev_type_bin2str(t, devtype,
4739 if (res < 0 || res >= end - pos)
4744 ssid = wpas_p2p_get_persistent(wpa_s, info->p2p_device_addr, NULL, 0);
4746 res = os_snprintf(pos, end - pos, "persistent=%d\n", ssid->id);
4747 if (res < 0 || res >= end - pos)
4752 res = p2p_get_peer_info_txt(info, pos, end - pos);
4757 if (info->vendor_elems) {
4758 res = os_snprintf(pos, end - pos, "vendor_elems=");
4759 if (res < 0 || res >= end - pos)
4763 pos += wpa_snprintf_hex(pos, end - pos,
4764 wpabuf_head(info->vendor_elems),
4765 wpabuf_len(info->vendor_elems));
4767 res = os_snprintf(pos, end - pos, "\n");
4768 if (res < 0 || res >= end - pos)
4777 static int p2p_ctrl_disallow_freq(struct wpa_supplicant *wpa_s,
4782 if (wpa_s->global->p2p == NULL)
4785 if (freq_range_list_parse(&wpa_s->global->p2p_disallow_freq, param) < 0)
4788 for (i = 0; i < wpa_s->global->p2p_disallow_freq.num; i++) {
4789 struct wpa_freq_range *freq;
4790 freq = &wpa_s->global->p2p_disallow_freq.range[i];
4791 wpa_printf(MSG_DEBUG, "P2P: Disallowed frequency range %u-%u",
4792 freq->min, freq->max);
4795 wpas_p2p_update_channel_list(wpa_s);
4800 static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd)
4804 if (wpa_s->global->p2p == NULL)
4807 param = os_strchr(cmd, ' ');
4812 if (os_strcmp(cmd, "discoverability") == 0) {
4813 p2p_set_client_discoverability(wpa_s->global->p2p,
4818 if (os_strcmp(cmd, "managed") == 0) {
4819 p2p_set_managed_oper(wpa_s->global->p2p, atoi(param));
4823 if (os_strcmp(cmd, "listen_channel") == 0) {
4824 return p2p_set_listen_channel(wpa_s->global->p2p, 81,
4828 if (os_strcmp(cmd, "ssid_postfix") == 0) {
4829 return p2p_set_ssid_postfix(wpa_s->global->p2p, (u8 *) param,
4833 if (os_strcmp(cmd, "noa") == 0) {
4835 int count, start, duration;
4836 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
4837 count = atoi(param);
4838 pos = os_strchr(param, ',');
4843 pos = os_strchr(pos, ',');
4847 duration = atoi(pos);
4848 if (count < 0 || count > 255 || start < 0 || duration < 0)
4850 if (count == 0 && duration > 0)
4852 wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
4853 "start=%d duration=%d", count, start, duration);
4854 return wpas_p2p_set_noa(wpa_s, count, start, duration);
4857 if (os_strcmp(cmd, "ps") == 0)
4858 return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1);
4860 if (os_strcmp(cmd, "oppps") == 0)
4861 return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1);
4863 if (os_strcmp(cmd, "ctwindow") == 0)
4864 return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param));
4866 if (os_strcmp(cmd, "disabled") == 0) {
4867 wpa_s->global->p2p_disabled = atoi(param);
4868 wpa_printf(MSG_DEBUG, "P2P functionality %s",
4869 wpa_s->global->p2p_disabled ?
4870 "disabled" : "enabled");
4871 if (wpa_s->global->p2p_disabled) {
4872 wpas_p2p_stop_find(wpa_s);
4873 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
4874 p2p_flush(wpa_s->global->p2p);
4879 if (os_strcmp(cmd, "conc_pref") == 0) {
4880 if (os_strcmp(param, "sta") == 0)
4881 wpa_s->global->conc_pref = WPA_CONC_PREF_STA;
4882 else if (os_strcmp(param, "p2p") == 0)
4883 wpa_s->global->conc_pref = WPA_CONC_PREF_P2P;
4885 wpa_printf(MSG_INFO, "Invalid conc_pref value");
4888 wpa_printf(MSG_DEBUG, "Single channel concurrency preference: "
4893 if (os_strcmp(cmd, "force_long_sd") == 0) {
4894 wpa_s->force_long_sd = atoi(param);
4898 if (os_strcmp(cmd, "peer_filter") == 0) {
4900 if (hwaddr_aton(param, addr))
4902 p2p_set_peer_filter(wpa_s->global->p2p, addr);
4906 if (os_strcmp(cmd, "cross_connect") == 0)
4907 return wpas_p2p_set_cross_connect(wpa_s, atoi(param));
4909 if (os_strcmp(cmd, "go_apsd") == 0) {
4910 if (os_strcmp(param, "disable") == 0)
4911 wpa_s->set_ap_uapsd = 0;
4913 wpa_s->set_ap_uapsd = 1;
4914 wpa_s->ap_uapsd = atoi(param);
4919 if (os_strcmp(cmd, "client_apsd") == 0) {
4920 if (os_strcmp(param, "disable") == 0)
4921 wpa_s->set_sta_uapsd = 0;
4925 /* format: BE,BK,VI,VO;max SP Length */
4927 pos = os_strchr(param, ',');
4932 pos = os_strchr(pos, ',');
4937 pos = os_strchr(pos, ',');
4942 /* ignore max SP Length for now */
4944 wpa_s->set_sta_uapsd = 1;
4945 wpa_s->sta_uapsd = 0;
4947 wpa_s->sta_uapsd |= BIT(0);
4949 wpa_s->sta_uapsd |= BIT(1);
4951 wpa_s->sta_uapsd |= BIT(2);
4953 wpa_s->sta_uapsd |= BIT(3);
4958 if (os_strcmp(cmd, "disallow_freq") == 0)
4959 return p2p_ctrl_disallow_freq(wpa_s, param);
4961 if (os_strcmp(cmd, "disc_int") == 0) {
4962 int min_disc_int, max_disc_int, max_disc_tu;
4967 min_disc_int = atoi(pos);
4968 pos = os_strchr(pos, ' ');
4973 max_disc_int = atoi(pos);
4974 pos = os_strchr(pos, ' ');
4979 max_disc_tu = atoi(pos);
4981 return p2p_set_disc_int(wpa_s->global->p2p, min_disc_int,
4982 max_disc_int, max_disc_tu);
4985 if (os_strcmp(cmd, "per_sta_psk") == 0) {
4986 wpa_s->global->p2p_per_sta_psk = !!atoi(param);
4990 #ifdef CONFIG_WPS_NFC
4991 if (os_strcmp(cmd, "nfc_tag") == 0)
4992 return wpas_p2p_nfc_tag_enabled(wpa_s, !!atoi(param));
4993 #endif /* CONFIG_WPS_NFC */
4995 if (os_strcmp(cmd, "disable_ip_addr_req") == 0) {
4996 wpa_s->p2p_disable_ip_addr_req = !!atoi(param);
5000 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
5007 static void p2p_ctrl_flush(struct wpa_supplicant *wpa_s)
5009 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
5010 wpa_s->force_long_sd = 0;
5011 if (wpa_s->global->p2p)
5012 p2p_flush(wpa_s->global->p2p);
5016 static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd)
5019 unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0;
5022 pos = os_strchr(cmd, ' ');
5028 pos2 = os_strchr(pos, ' ');
5036 pos = os_strchr(pos2, ' ');
5044 return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2);
5048 static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd)
5051 unsigned int period = 0, interval = 0;
5054 pos = os_strchr(cmd, ' ');
5059 interval = atoi(pos);
5062 return wpas_p2p_ext_listen(wpa_s, period, interval);
5066 static int p2p_ctrl_remove_client(struct wpa_supplicant *wpa_s, const char *cmd)
5073 if (os_strncmp(pos, "iface=", 6) == 0) {
5077 if (hwaddr_aton(pos, peer))
5080 wpas_p2p_remove_client(wpa_s, peer, iface_addr);
5084 #endif /* CONFIG_P2P */
5087 static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s, char *val)
5089 struct wpa_freq_range_list ranges;
5091 struct hostapd_hw_modes *mode;
5094 if (wpa_s->hw.modes == NULL)
5097 os_memset(&ranges, 0, sizeof(ranges));
5098 if (freq_range_list_parse(&ranges, val) < 0)
5101 for (i = 0; i < wpa_s->hw.num_modes; i++) {
5104 mode = &wpa_s->hw.modes[i];
5105 for (j = 0; j < mode->num_channels; j++) {
5108 if (mode->channels[j].flag & HOSTAPD_CHAN_DISABLED)
5111 freq = mode->channels[j].freq;
5112 if (!freq_range_list_includes(&ranges, freq))
5115 int_array_add_unique(&freqs, freq);
5119 os_free(ranges.range);
5124 #ifdef CONFIG_INTERWORKING
5126 static int ctrl_interworking_select(struct wpa_supplicant *wpa_s, char *param)
5134 auto_sel = os_strstr(param, "auto") != NULL;
5136 pos = os_strstr(param, "freq=");
5138 freqs = freq_range_to_channel_list(wpa_s, pos + 5);
5145 return interworking_select(wpa_s, auto_sel, freqs);
5149 static int ctrl_interworking_connect(struct wpa_supplicant *wpa_s, char *dst)
5152 struct wpa_bss *bss;
5154 if (hwaddr_aton(dst, bssid)) {
5155 wpa_printf(MSG_DEBUG, "Invalid BSSID '%s'", dst);
5159 bss = wpa_bss_get_bssid(wpa_s, bssid);
5161 wpa_printf(MSG_DEBUG, "Could not find BSS " MACSTR,
5166 return interworking_connect(wpa_s, bss);
5170 static int get_anqp(struct wpa_supplicant *wpa_s, char *dst)
5172 u8 dst_addr[ETH_ALEN];
5175 #define MAX_ANQP_INFO_ID 100
5176 u16 id[MAX_ANQP_INFO_ID];
5180 used = hwaddr_aton2(dst, dst_addr);
5184 while (num_id < MAX_ANQP_INFO_ID) {
5185 if (os_strncmp(pos, "hs20:", 5) == 0) {
5187 int num = atoi(pos + 5);
5188 if (num <= 0 || num > 31)
5190 subtypes |= BIT(num);
5191 #else /* CONFIG_HS20 */
5193 #endif /* CONFIG_HS20 */
5195 id[num_id] = atoi(pos);
5199 pos = os_strchr(pos + 1, ',');
5208 return anqp_send_req(wpa_s, dst_addr, id, num_id, subtypes);
5212 static int gas_request(struct wpa_supplicant *wpa_s, char *cmd)
5214 u8 dst_addr[ETH_ALEN];
5215 struct wpabuf *advproto, *query = NULL;
5220 used = hwaddr_aton2(cmd, dst_addr);
5228 /* Advertisement Protocol ID */
5229 end = os_strchr(pos, ' ');
5233 len = os_strlen(pos);
5239 advproto = wpabuf_alloc(len);
5240 if (advproto == NULL)
5242 if (hexstr2bin(pos, wpabuf_put(advproto, len), len) < 0)
5246 /* Optional Query Request */
5251 len = os_strlen(pos);
5258 query = wpabuf_alloc(len);
5261 if (hexstr2bin(pos, wpabuf_put(query, len), len) < 0)
5266 ret = gas_send_request(wpa_s, dst_addr, advproto, query);
5269 wpabuf_free(advproto);
5276 static int gas_response_get(struct wpa_supplicant *wpa_s, char *cmd, char *buf,
5283 size_t resp_len, start, requested_len;
5284 struct wpabuf *resp;
5287 used = hwaddr_aton2(cmd, addr);
5294 dialog_token = atoi(pos);
5296 if (wpa_s->last_gas_resp &&
5297 os_memcmp(addr, wpa_s->last_gas_addr, ETH_ALEN) == 0 &&
5298 dialog_token == wpa_s->last_gas_dialog_token)
5299 resp = wpa_s->last_gas_resp;
5300 else if (wpa_s->prev_gas_resp &&
5301 os_memcmp(addr, wpa_s->prev_gas_addr, ETH_ALEN) == 0 &&
5302 dialog_token == wpa_s->prev_gas_dialog_token)
5303 resp = wpa_s->prev_gas_resp;
5307 resp_len = wpabuf_len(resp);
5309 requested_len = resp_len;
5311 pos = os_strchr(pos, ' ');
5314 if (start > resp_len)
5315 return os_snprintf(buf, buflen, "FAIL-Invalid range");
5316 pos = os_strchr(pos, ',');
5320 requested_len = atoi(pos);
5321 if (start + requested_len > resp_len)
5322 return os_snprintf(buf, buflen, "FAIL-Invalid range");
5325 if (requested_len * 2 + 1 > buflen)
5326 return os_snprintf(buf, buflen, "FAIL-Too long response");
5328 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(resp) + start,
5331 if (start + requested_len == resp_len) {
5333 * Free memory by dropping the response after it has been
5336 if (resp == wpa_s->prev_gas_resp) {
5337 wpabuf_free(wpa_s->prev_gas_resp);
5338 wpa_s->prev_gas_resp = NULL;
5340 wpabuf_free(wpa_s->last_gas_resp);
5341 wpa_s->last_gas_resp = NULL;
5347 #endif /* CONFIG_INTERWORKING */
5352 static int get_hs20_anqp(struct wpa_supplicant *wpa_s, char *dst)
5354 u8 dst_addr[ETH_ALEN];
5359 used = hwaddr_aton2(dst, dst_addr);
5364 int num = atoi(pos);
5365 if (num <= 0 || num > 31)
5367 subtypes |= BIT(num);
5368 pos = os_strchr(pos + 1, ',');
5377 return hs20_anqp_send_req(wpa_s, dst_addr, subtypes, NULL, 0);
5381 static int hs20_nai_home_realm_list(struct wpa_supplicant *wpa_s,
5382 const u8 *addr, const char *realm)
5388 rlen = os_strlen(realm);
5390 buf = os_malloc(len);
5393 buf[0] = 1; /* NAI Home Realm Count */
5394 buf[1] = 0; /* Formatted in accordance with RFC 4282 */
5396 os_memcpy(buf + 3, realm, rlen);
5398 ret = hs20_anqp_send_req(wpa_s, addr,
5399 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
5408 static int hs20_get_nai_home_realm_list(struct wpa_supplicant *wpa_s,
5411 struct wpa_cred *cred = wpa_s->conf->cred;
5412 u8 dst_addr[ETH_ALEN];
5418 used = hwaddr_aton2(dst, dst_addr);
5422 while (dst[used] == ' ')
5424 if (os_strncmp(dst + used, "realm=", 6) == 0)
5425 return hs20_nai_home_realm_list(wpa_s, dst_addr,
5428 len = os_strlen(dst + used);
5430 if (len == 0 && cred && cred->realm)
5431 return hs20_nai_home_realm_list(wpa_s, dst_addr, cred->realm);
5436 buf = os_malloc(len);
5439 if (hexstr2bin(dst + used, buf, len) < 0) {
5444 ret = hs20_anqp_send_req(wpa_s, dst_addr,
5445 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
5453 static int hs20_icon_request(struct wpa_supplicant *wpa_s, char *cmd)
5455 u8 dst_addr[ETH_ALEN];
5459 used = hwaddr_aton2(cmd, dst_addr);
5463 while (cmd[used] == ' ')
5467 wpa_s->fetch_osu_icon_in_progress = 0;
5468 return hs20_anqp_send_req(wpa_s, dst_addr, BIT(HS20_STYPE_ICON_REQUEST),
5469 (u8 *) icon, os_strlen(icon));
5472 #endif /* CONFIG_HS20 */
5475 static int wpa_supplicant_ctrl_iface_sta_autoconnect(
5476 struct wpa_supplicant *wpa_s, char *cmd)
5478 wpa_s->auto_reconnect_disabled = atoi(cmd) == 0 ? 1 : 0;
5483 #ifdef CONFIG_AUTOSCAN
5485 static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant *wpa_s,
5488 enum wpa_states state = wpa_s->wpa_state;
5489 char *new_params = NULL;
5491 if (os_strlen(cmd) > 0) {
5492 new_params = os_strdup(cmd);
5493 if (new_params == NULL)
5497 os_free(wpa_s->conf->autoscan);
5498 wpa_s->conf->autoscan = new_params;
5500 if (wpa_s->conf->autoscan == NULL)
5501 autoscan_deinit(wpa_s);
5502 else if (state == WPA_DISCONNECTED || state == WPA_INACTIVE)
5503 autoscan_init(wpa_s, 1);
5504 else if (state == WPA_SCANNING)
5505 wpa_supplicant_reinit_autoscan(wpa_s);
5510 #endif /* CONFIG_AUTOSCAN */
5515 static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant *wpa_s, char *cmd)
5521 struct wpabuf *tfs_req = NULL;
5523 if (os_strncmp(cmd, "enter", 5) == 0)
5525 else if (os_strncmp(cmd, "exit", 4) == 0)
5530 pos = os_strstr(cmd, " interval=");
5532 intval = atoi(pos + 10);
5534 pos = os_strstr(cmd, " tfs_req=");
5539 end = os_strchr(pos, ' ');
5543 len = os_strlen(pos);
5547 tfs_req = wpabuf_alloc(len);
5548 if (tfs_req == NULL)
5550 if (hexstr2bin(pos, wpabuf_put(tfs_req, len), len) < 0) {
5551 wpabuf_free(tfs_req);
5556 ret = ieee802_11_send_wnmsleep_req(wpa_s, enter ? WNM_SLEEP_MODE_ENTER :
5557 WNM_SLEEP_MODE_EXIT, intval,
5559 wpabuf_free(tfs_req);
5565 static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant *wpa_s, char *cmd)
5569 query_reason = atoi(cmd);
5571 wpa_printf(MSG_DEBUG, "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d",
5574 return wnm_send_bss_transition_mgmt_query(wpa_s, query_reason);
5577 #endif /* CONFIG_WNM */
5580 static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf,
5583 struct wpa_signal_info si;
5587 ret = wpa_drv_signal_poll(wpa_s, &si);
5594 ret = os_snprintf(pos, end - pos, "RSSI=%d\nLINKSPEED=%d\n"
5595 "NOISE=%d\nFREQUENCY=%u\n",
5596 si.current_signal, si.current_txrate / 1000,
5597 si.current_noise, si.frequency);
5598 if (ret < 0 || ret > end - pos)
5602 if (si.chanwidth != CHAN_WIDTH_UNKNOWN) {
5603 ret = os_snprintf(pos, end - pos, "WIDTH=%s\n",
5604 channel_width_to_string(si.chanwidth));
5605 if (ret < 0 || ret > end - pos)
5610 if (si.center_frq1 > 0 && si.center_frq2 > 0) {
5611 ret = os_snprintf(pos, end - pos,
5612 "CENTER_FRQ1=%d\nCENTER_FRQ2=%d\n",
5613 si.center_frq1, si.center_frq2);
5614 if (ret < 0 || ret > end - pos)
5619 if (si.avg_signal) {
5620 ret = os_snprintf(pos, end - pos,
5621 "AVG_RSSI=%d\n", si.avg_signal);
5622 if (ret < 0 || ret >= end - pos)
5631 static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant *wpa_s, char *buf,
5634 struct hostap_sta_driver_data sta;
5637 ret = wpa_drv_pktcnt_poll(wpa_s, &sta);
5641 ret = os_snprintf(buf, buflen, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
5642 sta.tx_packets, sta.tx_retry_failed, sta.rx_packets);
5643 if (ret < 0 || (size_t) ret > buflen)
5650 static int wpa_supplicant_driver_cmd(struct wpa_supplicant *wpa_s, char *cmd,
5651 char *buf, size_t buflen)
5655 ret = wpa_drv_driver_cmd(wpa_s, cmd, buf, buflen);
5657 if (os_strncasecmp(cmd, "COUNTRY", 7) == 0) {
5658 struct p2p_data *p2p = wpa_s->global->p2p;
5661 country[0] = cmd[8];
5662 country[1] = cmd[9];
5664 p2p_set_country(p2p, country);
5667 ret = os_snprintf(buf, buflen, "%s\n", "OK");
5671 #endif /* ANDROID */
5674 static int wpa_supplicant_vendor_cmd(struct wpa_supplicant *wpa_s, char *cmd,
5675 char *buf, size_t buflen)
5680 unsigned int vendor_id, subcmd;
5681 struct wpabuf *reply;
5682 size_t data_len = 0;
5684 /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */
5685 vendor_id = strtoul(cmd, &pos, 16);
5689 subcmd = strtoul(pos, &pos, 10);
5692 if (!isblank(*pos++))
5694 data_len = os_strlen(pos);
5699 data = os_malloc(data_len);
5703 if (hexstr2bin(pos, data, data_len)) {
5704 wpa_printf(MSG_DEBUG,
5705 "Vendor command: wrong parameter format");
5711 reply = wpabuf_alloc((buflen - 1) / 2);
5717 ret = wpa_drv_vendor_cmd(wpa_s, vendor_id, subcmd, data, data_len,
5721 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(reply),
5731 static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s)
5733 wpa_dbg(wpa_s, MSG_DEBUG, "Flush all wpa_supplicant state");
5736 wpas_p2p_cancel(wpa_s);
5737 wpas_p2p_stop_find(wpa_s);
5738 p2p_ctrl_flush(wpa_s);
5739 wpas_p2p_group_remove(wpa_s, "*");
5740 wpas_p2p_service_flush(wpa_s);
5741 wpa_s->global->p2p_disabled = 0;
5742 wpa_s->global->p2p_per_sta_psk = 0;
5743 wpa_s->conf->num_sec_device_types = 0;
5744 wpa_s->p2p_disable_ip_addr_req = 0;
5745 os_free(wpa_s->global->p2p_go_avoid_freq.range);
5746 wpa_s->global->p2p_go_avoid_freq.range = NULL;
5747 #endif /* CONFIG_P2P */
5749 #ifdef CONFIG_WPS_TESTING
5750 wps_version_number = 0x20;
5751 wps_testing_dummy_cred = 0;
5752 wps_corrupt_pkhash = 0;
5753 #endif /* CONFIG_WPS_TESTING */
5755 wpa_s->wps_fragment_size = 0;
5756 wpas_wps_cancel(wpa_s);
5757 #endif /* CONFIG_WPS */
5758 wpa_s->after_wps = 0;
5759 wpa_s->known_wps_freq = 0;
5762 #ifdef CONFIG_TDLS_TESTING
5763 extern unsigned int tdls_testing;
5765 #endif /* CONFIG_TDLS_TESTING */
5766 wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL);
5767 wpa_tdls_enable(wpa_s->wpa, 1);
5768 #endif /* CONFIG_TDLS */
5770 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, wpa_s, NULL);
5771 wpa_supplicant_stop_countermeasures(wpa_s, NULL);
5773 wpa_s->no_keep_alive = 0;
5775 os_free(wpa_s->disallow_aps_bssid);
5776 wpa_s->disallow_aps_bssid = NULL;
5777 wpa_s->disallow_aps_bssid_count = 0;
5778 os_free(wpa_s->disallow_aps_ssid);
5779 wpa_s->disallow_aps_ssid = NULL;
5780 wpa_s->disallow_aps_ssid_count = 0;
5782 wpa_s->set_sta_uapsd = 0;
5783 wpa_s->sta_uapsd = 0;
5785 wpa_drv_radio_disable(wpa_s, 0);
5787 wpa_bss_flush(wpa_s);
5788 wpa_blacklist_clear(wpa_s);
5789 wpa_s->extra_blacklist_count = 0;
5790 wpa_supplicant_ctrl_iface_remove_network(wpa_s, "all");
5791 wpa_supplicant_ctrl_iface_remove_cred(wpa_s, "all");
5792 wpa_config_flush_blobs(wpa_s->conf);
5793 wpa_s->conf->auto_interworking = 0;
5794 wpa_s->conf->okc = 0;
5796 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, 43200);
5797 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, 70);
5798 wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, 60);
5799 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
5801 radio_remove_works(wpa_s, NULL, 1);
5803 wpa_s->next_ssid = NULL;
5805 #ifdef CONFIG_INTERWORKING
5806 hs20_cancel_fetch_osu(wpa_s);
5807 #endif /* CONFIG_INTERWORKING */
5809 wpa_s->ext_mgmt_frame_handling = 0;
5810 wpa_s->ext_eapol_frame_io = 0;
5814 static int wpas_ctrl_radio_work_show(struct wpa_supplicant *wpa_s,
5815 char *buf, size_t buflen)
5817 struct wpa_radio_work *work;
5819 struct os_reltime now, diff;
5824 os_get_reltime(&now);
5826 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
5830 os_reltime_sub(&now, &work->time, &diff);
5831 ret = os_snprintf(pos, end - pos, "%s@%s:%u:%u:%ld.%06ld\n",
5832 work->type, work->wpa_s->ifname, work->freq,
5833 work->started, diff.sec, diff.usec);
5834 if (ret < 0 || ret >= end - pos)
5843 static void wpas_ctrl_radio_work_timeout(void *eloop_ctx, void *timeout_ctx)
5845 struct wpa_radio_work *work = eloop_ctx;
5846 struct wpa_external_work *ework = work->ctx;
5848 wpa_dbg(work->wpa_s, MSG_DEBUG,
5849 "Timing out external radio work %u (%s)",
5850 ework->id, work->type);
5851 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_TIMEOUT "%u", ework->id);
5852 radio_work_done(work);
5857 static void wpas_ctrl_radio_work_cb(struct wpa_radio_work *work, int deinit)
5859 struct wpa_external_work *ework = work->ctx;
5863 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
5870 wpa_dbg(work->wpa_s, MSG_DEBUG, "Starting external radio work %u (%s)",
5871 ework->id, ework->type);
5872 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_START "%u", ework->id);
5873 if (!ework->timeout)
5874 ework->timeout = 10;
5875 eloop_register_timeout(ework->timeout, 0, wpas_ctrl_radio_work_timeout,
5880 static int wpas_ctrl_radio_work_add(struct wpa_supplicant *wpa_s, char *cmd,
5881 char *buf, size_t buflen)
5883 struct wpa_external_work *ework;
5887 unsigned int freq = 0;
5889 /* format: <name> [freq=<MHz>] [timeout=<seconds>] */
5891 ework = os_zalloc(sizeof(*ework));
5895 pos = os_strchr(cmd, ' ');
5897 type_len = pos - cmd;
5900 pos2 = os_strstr(pos, "freq=");
5902 freq = atoi(pos2 + 5);
5904 pos2 = os_strstr(pos, "timeout=");
5906 ework->timeout = atoi(pos2 + 8);
5908 type_len = os_strlen(cmd);
5910 if (4 + type_len >= sizeof(ework->type))
5911 type_len = sizeof(ework->type) - 4 - 1;
5912 os_strlcpy(ework->type, "ext:", sizeof(ework->type));
5913 os_memcpy(ework->type + 4, cmd, type_len);
5914 ework->type[4 + type_len] = '\0';
5916 wpa_s->ext_work_id++;
5917 if (wpa_s->ext_work_id == 0)
5918 wpa_s->ext_work_id++;
5919 ework->id = wpa_s->ext_work_id;
5921 if (radio_add_work(wpa_s, freq, ework->type, 0, wpas_ctrl_radio_work_cb,
5927 ret = os_snprintf(buf, buflen, "%u", ework->id);
5928 if (ret < 0 || (size_t) ret >= buflen)
5934 static int wpas_ctrl_radio_work_done(struct wpa_supplicant *wpa_s, char *cmd)
5936 struct wpa_radio_work *work;
5937 unsigned int id = atoi(cmd);
5939 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
5941 struct wpa_external_work *ework;
5943 if (os_strncmp(work->type, "ext:", 4) != 0)
5946 if (id && ework->id != id)
5948 wpa_dbg(wpa_s, MSG_DEBUG,
5949 "Completed external radio work %u (%s)",
5950 ework->id, ework->type);
5951 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, work, NULL);
5952 radio_work_done(work);
5954 return 3; /* "OK\n" */
5961 static int wpas_ctrl_radio_work(struct wpa_supplicant *wpa_s, char *cmd,
5962 char *buf, size_t buflen)
5964 if (os_strcmp(cmd, "show") == 0)
5965 return wpas_ctrl_radio_work_show(wpa_s, buf, buflen);
5966 if (os_strncmp(cmd, "add ", 4) == 0)
5967 return wpas_ctrl_radio_work_add(wpa_s, cmd + 4, buf, buflen);
5968 if (os_strncmp(cmd, "done ", 5) == 0)
5969 return wpas_ctrl_radio_work_done(wpa_s, cmd + 4);
5974 void wpas_ctrl_radio_work_flush(struct wpa_supplicant *wpa_s)
5976 struct wpa_radio_work *work, *tmp;
5978 if (!wpa_s || !wpa_s->radio)
5981 dl_list_for_each_safe(work, tmp, &wpa_s->radio->work,
5982 struct wpa_radio_work, list) {
5983 struct wpa_external_work *ework;
5985 if (os_strncmp(work->type, "ext:", 4) != 0)
5988 wpa_dbg(wpa_s, MSG_DEBUG,
5989 "Flushing%s external radio work %u (%s)",
5990 work->started ? " started" : "", ework->id,
5993 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
5995 radio_work_done(work);
6001 static void wpas_ctrl_eapol_response(void *eloop_ctx, void *timeout_ctx)
6003 struct wpa_supplicant *wpa_s = eloop_ctx;
6004 eapol_sm_notify_ctrl_response(wpa_s->eapol);
6008 static int set_scan_freqs(struct wpa_supplicant *wpa_s, char *val)
6012 freqs = freq_range_to_channel_list(wpa_s, val);
6016 os_free(wpa_s->manual_scan_freqs);
6017 wpa_s->manual_scan_freqs = freqs;
6023 static int scan_id_list_parse(struct wpa_supplicant *wpa_s, const char *value)
6025 const char *pos = value;
6028 if (*pos == ' ' || *pos == '\0')
6030 if (wpa_s->scan_id_count == MAX_SCAN_ID)
6032 wpa_s->scan_id[wpa_s->scan_id_count++] = atoi(pos);
6033 pos = os_strchr(pos, ',');
6042 static void wpas_ctrl_scan(struct wpa_supplicant *wpa_s, char *params,
6043 char *reply, int reply_size, int *reply_len)
6047 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
6052 wpa_s->manual_scan_passive = 0;
6053 wpa_s->manual_scan_use_id = 0;
6054 wpa_s->manual_scan_only_new = 0;
6055 wpa_s->scan_id_count = 0;
6058 if (os_strncasecmp(params, "TYPE=ONLY", 9) == 0)
6059 wpa_s->scan_res_handler = scan_only_handler;
6061 pos = os_strstr(params, "freq=");
6062 if (pos && set_scan_freqs(wpa_s, pos + 5) < 0) {
6067 pos = os_strstr(params, "passive=");
6069 wpa_s->manual_scan_passive = !!atoi(pos + 8);
6071 pos = os_strstr(params, "use_id=");
6073 wpa_s->manual_scan_use_id = atoi(pos + 7);
6075 pos = os_strstr(params, "only_new=1");
6077 wpa_s->manual_scan_only_new = 1;
6079 pos = os_strstr(params, "scan_id=");
6080 if (pos && scan_id_list_parse(wpa_s, pos + 8) < 0) {
6085 os_free(wpa_s->manual_scan_freqs);
6086 wpa_s->manual_scan_freqs = NULL;
6087 if (wpa_s->scan_res_handler == scan_only_handler)
6088 wpa_s->scan_res_handler = NULL;
6091 if (!wpa_s->sched_scanning && !wpa_s->scanning &&
6092 ((wpa_s->wpa_state <= WPA_SCANNING) ||
6093 (wpa_s->wpa_state == WPA_COMPLETED))) {
6094 wpa_s->normal_scans = 0;
6095 wpa_s->scan_req = MANUAL_SCAN_REQ;
6096 wpa_s->after_wps = 0;
6097 wpa_s->known_wps_freq = 0;
6098 wpa_supplicant_req_scan(wpa_s, 0, 0);
6099 if (wpa_s->manual_scan_use_id) {
6100 wpa_s->manual_scan_id++;
6101 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
6102 wpa_s->manual_scan_id);
6103 *reply_len = os_snprintf(reply, reply_size, "%u\n",
6104 wpa_s->manual_scan_id);
6106 } else if (wpa_s->sched_scanning) {
6107 wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to allow requested full scan to proceed");
6108 wpa_supplicant_cancel_sched_scan(wpa_s);
6109 wpa_s->scan_req = MANUAL_SCAN_REQ;
6110 wpa_supplicant_req_scan(wpa_s, 0, 0);
6111 if (wpa_s->manual_scan_use_id) {
6112 wpa_s->manual_scan_id++;
6113 *reply_len = os_snprintf(reply, reply_size, "%u\n",
6114 wpa_s->manual_scan_id);
6115 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
6116 wpa_s->manual_scan_id);
6119 wpa_printf(MSG_DEBUG, "Ongoing scan action - reject new request");
6120 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
6125 #ifdef CONFIG_TESTING_OPTIONS
6127 static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant *wpa_s,
6128 unsigned int freq, const u8 *dst,
6129 const u8 *src, const u8 *bssid,
6130 const u8 *data, size_t data_len,
6131 enum offchannel_send_action_result
6134 wpa_msg(wpa_s, MSG_INFO, "MGMT-TX-STATUS freq=%u dst=" MACSTR
6135 " src=" MACSTR " bssid=" MACSTR " result=%s",
6136 freq, MAC2STR(dst), MAC2STR(src), MAC2STR(bssid),
6137 result == OFFCHANNEL_SEND_ACTION_SUCCESS ?
6138 "SUCCESS" : (result == OFFCHANNEL_SEND_ACTION_NO_ACK ?
6139 "NO_ACK" : "FAILED"));
6143 static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant *wpa_s, char *cmd)
6147 u8 *buf, da[ETH_ALEN], bssid[ETH_ALEN];
6149 int freq = 0, no_cck = 0, wait_time = 0;
6151 /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1]
6152 * <action=Action frame payload> */
6154 wpa_printf(MSG_DEBUG, "External MGMT TX: %s", cmd);
6157 used = hwaddr_aton2(pos, da);
6163 used = hwaddr_aton2(pos, bssid);
6168 param = os_strstr(pos, " freq=");
6174 param = os_strstr(pos, " no_cck=");
6177 no_cck = atoi(param);
6180 param = os_strstr(pos, " wait_time=");
6183 wait_time = atoi(param);
6186 param = os_strstr(pos, " action=");
6191 len = os_strlen(param);
6196 buf = os_malloc(len);
6200 if (hexstr2bin(param, buf, len) < 0) {
6205 res = offchannel_send_action(wpa_s, freq, da, wpa_s->own_addr, bssid,
6206 buf, len, wait_time,
6207 wpas_ctrl_iface_mgmt_tx_cb, no_cck);
6213 static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant *wpa_s)
6215 wpa_printf(MSG_DEBUG, "External MGMT TX - done waiting");
6216 offchannel_send_action_done(wpa_s);
6220 static int wpas_ctrl_iface_driver_event(struct wpa_supplicant *wpa_s, char *cmd)
6223 union wpa_event_data event;
6224 enum wpa_event_type ev;
6226 /* <event name> [parameters..] */
6228 wpa_dbg(wpa_s, MSG_DEBUG, "Testing - external driver event: %s", cmd);
6231 param = os_strchr(pos, ' ');
6235 os_memset(&event, 0, sizeof(event));
6237 if (os_strcmp(cmd, "INTERFACE_ENABLED") == 0) {
6238 ev = EVENT_INTERFACE_ENABLED;
6239 } else if (os_strcmp(cmd, "INTERFACE_DISABLED") == 0) {
6240 ev = EVENT_INTERFACE_DISABLED;
6241 } else if (os_strcmp(cmd, "AVOID_FREQUENCIES") == 0) {
6242 ev = EVENT_AVOID_FREQUENCIES;
6245 if (freq_range_list_parse(&event.freq_range, param) < 0)
6247 wpa_supplicant_event(wpa_s, ev, &event);
6248 os_free(event.freq_range.range);
6251 wpa_dbg(wpa_s, MSG_DEBUG, "Testing - unknown driver event: %s",
6256 wpa_supplicant_event(wpa_s, ev, &event);
6262 static int wpas_ctrl_iface_eapol_rx(struct wpa_supplicant *wpa_s, char *cmd)
6265 u8 src[ETH_ALEN], *buf;
6269 wpa_printf(MSG_DEBUG, "External EAPOL RX: %s", cmd);
6272 used = hwaddr_aton2(pos, src);
6279 len = os_strlen(pos);
6284 buf = os_malloc(len);
6288 if (hexstr2bin(pos, buf, len) < 0) {
6293 wpa_supplicant_rx_eapol(wpa_s, src, buf, len);
6300 static u16 ipv4_hdr_checksum(const void *buf, size_t len)
6304 const u16 *pos = buf;
6306 for (i = 0; i < len / 2; i++)
6310 sum = (sum & 0xffff) + (sum >> 16);
6312 return sum ^ 0xffff;
6316 #define HWSIM_PACKETLEN 1500
6317 #define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header))
6319 void wpas_data_test_rx(void *ctx, const u8 *src_addr, const u8 *buf, size_t len)
6321 struct wpa_supplicant *wpa_s = ctx;
6322 const struct ether_header *eth;
6323 const struct iphdr *ip;
6327 if (len != HWSIM_PACKETLEN)
6330 eth = (const struct ether_header *) buf;
6331 ip = (const struct iphdr *) (eth + 1);
6332 pos = (const u8 *) (ip + 1);
6334 if (ip->ihl != 5 || ip->version != 4 ||
6335 ntohs(ip->tot_len) != HWSIM_IP_LEN)
6338 for (i = 0; i < HWSIM_IP_LEN - sizeof(*ip); i++) {
6344 wpa_msg(wpa_s, MSG_INFO, "DATA-TEST-RX " MACSTR " " MACSTR,
6345 MAC2STR(eth->ether_dhost), MAC2STR(eth->ether_shost));
6349 static int wpas_ctrl_iface_data_test_config(struct wpa_supplicant *wpa_s,
6352 int enabled = atoi(cmd);
6355 if (wpa_s->l2_test) {
6356 l2_packet_deinit(wpa_s->l2_test);
6357 wpa_s->l2_test = NULL;
6358 wpa_dbg(wpa_s, MSG_DEBUG, "test data: Disabled");
6366 wpa_s->l2_test = l2_packet_init(wpa_s->ifname, wpa_s->own_addr,
6367 ETHERTYPE_IP, wpas_data_test_rx,
6369 if (wpa_s->l2_test == NULL)
6372 wpa_dbg(wpa_s, MSG_DEBUG, "test data: Enabled");
6378 static int wpas_ctrl_iface_data_test_tx(struct wpa_supplicant *wpa_s, char *cmd)
6380 u8 dst[ETH_ALEN], src[ETH_ALEN];
6385 u8 buf[HWSIM_PACKETLEN];
6386 struct ether_header *eth;
6391 if (wpa_s->l2_test == NULL)
6394 /* format: <dst> <src> <tos> */
6397 used = hwaddr_aton2(pos, dst);
6403 used = hwaddr_aton2(pos, src);
6408 val = strtol(pos, NULL, 0);
6409 if (val < 0 || val > 0xff)
6413 eth = (struct ether_header *) buf;
6414 os_memcpy(eth->ether_dhost, dst, ETH_ALEN);
6415 os_memcpy(eth->ether_shost, src, ETH_ALEN);
6416 eth->ether_type = htons(ETHERTYPE_IP);
6417 ip = (struct iphdr *) (eth + 1);
6418 os_memset(ip, 0, sizeof(*ip));
6423 ip->tot_len = htons(HWSIM_IP_LEN);
6425 ip->saddr = htonl(192 << 24 | 168 << 16 | 1 << 8 | 1);
6426 ip->daddr = htonl(192 << 24 | 168 << 16 | 1 << 8 | 2);
6427 ip->check = ipv4_hdr_checksum(ip, sizeof(*ip));
6428 dpos = (u8 *) (ip + 1);
6429 for (i = 0; i < HWSIM_IP_LEN - sizeof(*ip); i++)
6432 if (l2_packet_send(wpa_s->l2_test, dst, ETHERTYPE_IP, buf,
6433 HWSIM_PACKETLEN) < 0)
6436 wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX dst=" MACSTR " src=" MACSTR
6437 " tos=0x%x", MAC2STR(dst), MAC2STR(src), tos);
6442 #endif /* CONFIG_TESTING_OPTIONS */
6445 static void wpas_ctrl_vendor_elem_update(struct wpa_supplicant *wpa_s)
6450 wpa_printf(MSG_DEBUG, "Update vendor elements");
6452 for (i = 0; i < NUM_VENDOR_ELEM_FRAMES; i++) {
6453 if (wpa_s->vendor_elem[i]) {
6454 os_snprintf(buf, sizeof(buf), "frame[%u]", i);
6455 wpa_hexdump_buf(MSG_DEBUG, buf, wpa_s->vendor_elem[i]);
6460 if (wpa_s->parent == wpa_s &&
6461 wpa_s->global->p2p &&
6462 !wpa_s->global->p2p_disabled)
6463 p2p_set_vendor_elems(wpa_s->global->p2p, wpa_s->vendor_elem);
6464 #endif /* CONFIG_P2P */
6468 static struct wpa_supplicant *
6469 wpas_ctrl_vendor_elem_iface(struct wpa_supplicant *wpa_s,
6470 enum wpa_vendor_elem_frame frame)
6474 case VENDOR_ELEM_PROBE_REQ_P2P:
6475 case VENDOR_ELEM_PROBE_RESP_P2P:
6476 case VENDOR_ELEM_PROBE_RESP_P2P_GO:
6477 case VENDOR_ELEM_BEACON_P2P_GO:
6478 case VENDOR_ELEM_P2P_PD_REQ:
6479 case VENDOR_ELEM_P2P_PD_RESP:
6480 case VENDOR_ELEM_P2P_GO_NEG_REQ:
6481 case VENDOR_ELEM_P2P_GO_NEG_RESP:
6482 case VENDOR_ELEM_P2P_GO_NEG_CONF:
6483 case VENDOR_ELEM_P2P_INV_REQ:
6484 case VENDOR_ELEM_P2P_INV_RESP:
6485 case VENDOR_ELEM_P2P_ASSOC_REQ:
6486 return wpa_s->parent;
6487 #endif /* CONFIG_P2P */
6494 static int wpas_ctrl_vendor_elem_add(struct wpa_supplicant *wpa_s, char *cmd)
6500 struct ieee802_11_elems elems;
6503 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
6505 wpa_s = wpas_ctrl_vendor_elem_iface(wpa_s, frame);
6507 pos = os_strchr(pos, ' ');
6512 len = os_strlen(pos);
6519 buf = wpabuf_alloc(len);
6523 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
6528 if (ieee802_11_parse_elems(wpabuf_head_u8(buf), len, &elems, 0) ==
6534 if (wpa_s->vendor_elem[frame] == NULL) {
6535 wpa_s->vendor_elem[frame] = buf;
6536 wpas_ctrl_vendor_elem_update(wpa_s);
6540 if (wpabuf_resize(&wpa_s->vendor_elem[frame], len) < 0) {
6545 wpabuf_put_buf(wpa_s->vendor_elem[frame], buf);
6547 wpas_ctrl_vendor_elem_update(wpa_s);
6553 static int wpas_ctrl_vendor_elem_get(struct wpa_supplicant *wpa_s, char *cmd,
6554 char *buf, size_t buflen)
6556 int frame = atoi(cmd);
6558 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
6560 wpa_s = wpas_ctrl_vendor_elem_iface(wpa_s, frame);
6562 if (wpa_s->vendor_elem[frame] == NULL)
6565 return wpa_snprintf_hex(buf, buflen,
6566 wpabuf_head_u8(wpa_s->vendor_elem[frame]),
6567 wpabuf_len(wpa_s->vendor_elem[frame]));
6571 static int wpas_ctrl_vendor_elem_remove(struct wpa_supplicant *wpa_s, char *cmd)
6577 struct ieee802_11_elems elems;
6581 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
6583 wpa_s = wpas_ctrl_vendor_elem_iface(wpa_s, frame);
6585 pos = os_strchr(pos, ' ');
6591 wpabuf_free(wpa_s->vendor_elem[frame]);
6592 wpa_s->vendor_elem[frame] = NULL;
6593 wpas_ctrl_vendor_elem_update(wpa_s);
6597 if (wpa_s->vendor_elem[frame] == NULL)
6600 len = os_strlen(pos);
6607 buf = os_malloc(len);
6611 if (hexstr2bin(pos, buf, len) < 0) {
6616 if (ieee802_11_parse_elems(buf, len, &elems, 0) == ParseFailed) {
6621 ie = wpabuf_mhead_u8(wpa_s->vendor_elem[frame]);
6622 end = ie + wpabuf_len(wpa_s->vendor_elem[frame]);
6624 for (; ie + 1 < end; ie += 2 + ie[1]) {
6627 if (os_memcmp(ie, buf, len) != 0)
6630 if (wpabuf_len(wpa_s->vendor_elem[frame]) == len) {
6631 wpabuf_free(wpa_s->vendor_elem[frame]);
6632 wpa_s->vendor_elem[frame] = NULL;
6634 os_memmove(ie, ie + len,
6636 wpa_s->vendor_elem[frame]->used -= len;
6639 wpas_ctrl_vendor_elem_update(wpa_s);
6649 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
6650 char *buf, size_t *resp_len)
6653 const int reply_size = 4096;
6656 if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 ||
6657 os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
6658 if (wpa_debug_show_keys)
6659 wpa_dbg(wpa_s, MSG_DEBUG,
6660 "Control interface command '%s'", buf);
6662 wpa_dbg(wpa_s, MSG_DEBUG,
6663 "Control interface command '%s [REMOVED]'",
6664 os_strncmp(buf, WPA_CTRL_RSP,
6665 os_strlen(WPA_CTRL_RSP)) == 0 ?
6666 WPA_CTRL_RSP : "SET_NETWORK");
6667 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ", 16) == 0 ||
6668 os_strncmp(buf, "NFC_REPORT_HANDOVER", 19) == 0) {
6669 wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface",
6670 (const u8 *) buf, os_strlen(buf));
6672 int level = MSG_DEBUG;
6673 if (os_strcmp(buf, "PING") == 0)
6674 level = MSG_EXCESSIVE;
6675 wpa_dbg(wpa_s, level, "Control interface command '%s'", buf);
6678 reply = os_malloc(reply_size);
6679 if (reply == NULL) {
6684 os_memcpy(reply, "OK\n", 3);
6687 if (os_strcmp(buf, "PING") == 0) {
6688 os_memcpy(reply, "PONG\n", 5);
6690 } else if (os_strcmp(buf, "IFNAME") == 0) {
6691 reply_len = os_strlen(wpa_s->ifname);
6692 os_memcpy(reply, wpa_s->ifname, reply_len);
6693 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
6694 if (wpa_debug_reopen_file() < 0)
6696 } else if (os_strncmp(buf, "NOTE ", 5) == 0) {
6697 wpa_printf(MSG_INFO, "NOTE: %s", buf + 5);
6698 } else if (os_strcmp(buf, "MIB") == 0) {
6699 reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size);
6700 if (reply_len >= 0) {
6702 res = eapol_sm_get_mib(wpa_s->eapol, reply + reply_len,
6703 reply_size - reply_len);
6709 } else if (os_strncmp(buf, "STATUS", 6) == 0) {
6710 reply_len = wpa_supplicant_ctrl_iface_status(
6711 wpa_s, buf + 6, reply, reply_size);
6712 } else if (os_strcmp(buf, "PMKSA") == 0) {
6713 reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, reply,
6715 } else if (os_strcmp(buf, "PMKSA_FLUSH") == 0) {
6716 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
6717 } else if (os_strncmp(buf, "SET ", 4) == 0) {
6718 if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4))
6720 } else if (os_strncmp(buf, "GET ", 4) == 0) {
6721 reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4,
6723 } else if (os_strcmp(buf, "LOGON") == 0) {
6724 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
6725 } else if (os_strcmp(buf, "LOGOFF") == 0) {
6726 eapol_sm_notify_logoff(wpa_s->eapol, TRUE);
6727 } else if (os_strcmp(buf, "REASSOCIATE") == 0) {
6728 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
6731 wpas_request_connection(wpa_s);
6732 } else if (os_strcmp(buf, "REATTACH") == 0) {
6733 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED ||
6734 !wpa_s->current_ssid)
6737 wpa_s->reattach = 1;
6738 wpas_request_connection(wpa_s);
6740 } else if (os_strcmp(buf, "RECONNECT") == 0) {
6741 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
6743 else if (wpa_s->disconnected)
6744 wpas_request_connection(wpa_s);
6745 #ifdef IEEE8021X_EAPOL
6746 } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) {
6747 if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8))
6749 #endif /* IEEE8021X_EAPOL */
6750 #ifdef CONFIG_PEERKEY
6751 } else if (os_strncmp(buf, "STKSTART ", 9) == 0) {
6752 if (wpa_supplicant_ctrl_iface_stkstart(wpa_s, buf + 9))
6754 #endif /* CONFIG_PEERKEY */
6755 #ifdef CONFIG_IEEE80211R
6756 } else if (os_strncmp(buf, "FT_DS ", 6) == 0) {
6757 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6))
6759 #endif /* CONFIG_IEEE80211R */
6761 } else if (os_strcmp(buf, "WPS_PBC") == 0) {
6762 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL);
6764 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
6768 } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) {
6769 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8);
6771 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
6775 } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {
6776 reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8,
6779 } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) {
6780 reply_len = wpa_supplicant_ctrl_iface_wps_check_pin(
6781 wpa_s, buf + 14, reply, reply_size);
6782 } else if (os_strcmp(buf, "WPS_CANCEL") == 0) {
6783 if (wpas_wps_cancel(wpa_s))
6785 #ifdef CONFIG_WPS_NFC
6786 } else if (os_strcmp(buf, "WPS_NFC") == 0) {
6787 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, NULL))
6789 } else if (os_strncmp(buf, "WPS_NFC ", 8) == 0) {
6790 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, buf + 8))
6792 } else if (os_strncmp(buf, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
6793 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_config_token(
6794 wpa_s, buf + 21, reply, reply_size);
6795 } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) {
6796 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_token(
6797 wpa_s, buf + 14, reply, reply_size);
6798 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) {
6799 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s,
6802 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
6803 reply_len = wpas_ctrl_nfc_get_handover_req(
6804 wpa_s, buf + 21, reply, reply_size);
6805 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
6806 reply_len = wpas_ctrl_nfc_get_handover_sel(
6807 wpa_s, buf + 21, reply, reply_size);
6808 } else if (os_strncmp(buf, "NFC_REPORT_HANDOVER ", 20) == 0) {
6809 if (wpas_ctrl_nfc_report_handover(wpa_s, buf + 20))
6811 #endif /* CONFIG_WPS_NFC */
6812 } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) {
6813 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8))
6816 } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) {
6817 reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin(
6818 wpa_s, buf + 11, reply, reply_size);
6819 #endif /* CONFIG_AP */
6820 #ifdef CONFIG_WPS_ER
6821 } else if (os_strcmp(buf, "WPS_ER_START") == 0) {
6822 if (wpas_wps_er_start(wpa_s, NULL))
6824 } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) {
6825 if (wpas_wps_er_start(wpa_s, buf + 13))
6827 } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) {
6828 if (wpas_wps_er_stop(wpa_s))
6830 } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) {
6831 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11))
6833 } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) {
6834 int ret = wpas_wps_er_pbc(wpa_s, buf + 11);
6836 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
6838 } else if (ret == -3) {
6839 os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18);
6841 } else if (ret == -4) {
6842 os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20);
6846 } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) {
6847 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13))
6849 } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) {
6850 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s,
6853 } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) {
6854 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14))
6856 #ifdef CONFIG_WPS_NFC
6857 } else if (os_strncmp(buf, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
6858 reply_len = wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
6859 wpa_s, buf + 24, reply, reply_size);
6860 #endif /* CONFIG_WPS_NFC */
6861 #endif /* CONFIG_WPS_ER */
6862 #endif /* CONFIG_WPS */
6863 #ifdef CONFIG_IBSS_RSN
6864 } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) {
6865 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9))
6867 #endif /* CONFIG_IBSS_RSN */
6869 } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) {
6870 if (p2p_ctrl_find(wpa_s, buf + 9))
6872 } else if (os_strcmp(buf, "P2P_FIND") == 0) {
6873 if (p2p_ctrl_find(wpa_s, ""))
6875 } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) {
6876 wpas_p2p_stop_find(wpa_s);
6877 } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) {
6878 reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply,
6880 } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) {
6881 if (p2p_ctrl_listen(wpa_s, buf + 11))
6883 } else if (os_strcmp(buf, "P2P_LISTEN") == 0) {
6884 if (p2p_ctrl_listen(wpa_s, ""))
6886 } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) {
6887 if (wpas_p2p_group_remove(wpa_s, buf + 17))
6889 } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) {
6890 if (wpas_p2p_group_add(wpa_s, 0, 0, 0, 0))
6892 } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) {
6893 if (p2p_ctrl_group_add(wpa_s, buf + 14))
6895 } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) {
6896 if (p2p_ctrl_prov_disc(wpa_s, buf + 14))
6898 } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) {
6899 reply_len = p2p_get_passphrase(wpa_s, reply, reply_size);
6900 } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) {
6901 reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply,
6903 } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
6904 if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0)
6906 } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) {
6907 if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0)
6909 } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) {
6910 wpas_p2p_sd_service_update(wpa_s);
6911 } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
6912 if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0)
6914 } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) {
6915 wpas_p2p_service_flush(wpa_s);
6916 } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) {
6917 if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0)
6919 } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) {
6920 if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0)
6922 } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) {
6923 if (p2p_ctrl_reject(wpa_s, buf + 11) < 0)
6925 } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) {
6926 if (p2p_ctrl_invite(wpa_s, buf + 11) < 0)
6928 } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) {
6929 reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply,
6931 } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) {
6932 if (p2p_ctrl_set(wpa_s, buf + 8) < 0)
6934 } else if (os_strcmp(buf, "P2P_FLUSH") == 0) {
6935 p2p_ctrl_flush(wpa_s);
6936 } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) {
6937 if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0)
6939 } else if (os_strcmp(buf, "P2P_CANCEL") == 0) {
6940 if (wpas_p2p_cancel(wpa_s))
6942 } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) {
6943 if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0)
6945 } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) {
6946 if (p2p_ctrl_presence_req(wpa_s, "") < 0)
6948 } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) {
6949 if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0)
6951 } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) {
6952 if (p2p_ctrl_ext_listen(wpa_s, "") < 0)
6954 } else if (os_strncmp(buf, "P2P_REMOVE_CLIENT ", 18) == 0) {
6955 if (p2p_ctrl_remove_client(wpa_s, buf + 18) < 0)
6957 #endif /* CONFIG_P2P */
6958 #ifdef CONFIG_WIFI_DISPLAY
6959 } else if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0) {
6960 if (wifi_display_subelem_set(wpa_s->global, buf + 16) < 0)
6962 } else if (os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) {
6963 reply_len = wifi_display_subelem_get(wpa_s->global, buf + 16,
6965 #endif /* CONFIG_WIFI_DISPLAY */
6966 #ifdef CONFIG_INTERWORKING
6967 } else if (os_strcmp(buf, "FETCH_ANQP") == 0) {
6968 if (interworking_fetch_anqp(wpa_s) < 0)
6970 } else if (os_strcmp(buf, "STOP_FETCH_ANQP") == 0) {
6971 interworking_stop_fetch_anqp(wpa_s);
6972 } else if (os_strcmp(buf, "INTERWORKING_SELECT") == 0) {
6973 if (ctrl_interworking_select(wpa_s, NULL) < 0)
6975 } else if (os_strncmp(buf, "INTERWORKING_SELECT ", 20) == 0) {
6976 if (ctrl_interworking_select(wpa_s, buf + 20) < 0)
6978 } else if (os_strncmp(buf, "INTERWORKING_CONNECT ", 21) == 0) {
6979 if (ctrl_interworking_connect(wpa_s, buf + 21) < 0)
6981 } else if (os_strncmp(buf, "ANQP_GET ", 9) == 0) {
6982 if (get_anqp(wpa_s, buf + 9) < 0)
6984 } else if (os_strncmp(buf, "GAS_REQUEST ", 12) == 0) {
6985 if (gas_request(wpa_s, buf + 12) < 0)
6987 } else if (os_strncmp(buf, "GAS_RESPONSE_GET ", 17) == 0) {
6988 reply_len = gas_response_get(wpa_s, buf + 17, reply,
6990 #endif /* CONFIG_INTERWORKING */
6992 } else if (os_strncmp(buf, "HS20_ANQP_GET ", 14) == 0) {
6993 if (get_hs20_anqp(wpa_s, buf + 14) < 0)
6995 } else if (os_strncmp(buf, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
6996 if (hs20_get_nai_home_realm_list(wpa_s, buf + 29) < 0)
6998 } else if (os_strncmp(buf, "HS20_ICON_REQUEST ", 18) == 0) {
6999 if (hs20_icon_request(wpa_s, buf + 18) < 0)
7001 } else if (os_strcmp(buf, "FETCH_OSU") == 0) {
7002 if (hs20_fetch_osu(wpa_s) < 0)
7004 } else if (os_strcmp(buf, "CANCEL_FETCH_OSU") == 0) {
7005 hs20_cancel_fetch_osu(wpa_s);
7006 #endif /* CONFIG_HS20 */
7007 } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0)
7009 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
7010 wpa_s, buf + os_strlen(WPA_CTRL_RSP)))
7014 * Notify response from timeout to allow the control
7015 * interface response to be sent first.
7017 eloop_register_timeout(0, 0, wpas_ctrl_eapol_response,
7020 } else if (os_strcmp(buf, "RECONFIGURE") == 0) {
7021 if (wpa_supplicant_reload_configuration(wpa_s))
7023 } else if (os_strcmp(buf, "TERMINATE") == 0) {
7024 wpa_supplicant_terminate_proc(wpa_s->global);
7025 } else if (os_strncmp(buf, "BSSID ", 6) == 0) {
7026 if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6))
7028 } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) {
7029 reply_len = wpa_supplicant_ctrl_iface_blacklist(
7030 wpa_s, buf + 9, reply, reply_size);
7031 } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) {
7032 reply_len = wpa_supplicant_ctrl_iface_log_level(
7033 wpa_s, buf + 9, reply, reply_size);
7034 } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) {
7035 reply_len = wpa_supplicant_ctrl_iface_list_networks(
7036 wpa_s, reply, reply_size);
7037 } else if (os_strcmp(buf, "DISCONNECT") == 0) {
7039 wpa_s->sme.prev_bssid_set = 0;
7040 #endif /* CONFIG_SME */
7041 wpa_s->reassociate = 0;
7042 wpa_s->disconnected = 1;
7043 wpa_supplicant_cancel_sched_scan(wpa_s);
7044 wpa_supplicant_cancel_scan(wpa_s);
7045 wpa_supplicant_deauthenticate(wpa_s,
7046 WLAN_REASON_DEAUTH_LEAVING);
7047 } else if (os_strcmp(buf, "SCAN") == 0) {
7048 wpas_ctrl_scan(wpa_s, NULL, reply, reply_size, &reply_len);
7049 } else if (os_strncmp(buf, "SCAN ", 5) == 0) {
7050 wpas_ctrl_scan(wpa_s, buf + 5, reply, reply_size, &reply_len);
7051 } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) {
7052 reply_len = wpa_supplicant_ctrl_iface_scan_results(
7053 wpa_s, reply, reply_size);
7054 } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) {
7055 if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15))
7057 } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) {
7058 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15))
7060 } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) {
7061 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16))
7063 } else if (os_strcmp(buf, "ADD_NETWORK") == 0) {
7064 reply_len = wpa_supplicant_ctrl_iface_add_network(
7065 wpa_s, reply, reply_size);
7066 } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) {
7067 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15))
7069 } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
7070 if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12))
7072 } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) {
7073 reply_len = wpa_supplicant_ctrl_iface_get_network(
7074 wpa_s, buf + 12, reply, reply_size);
7075 } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) {
7076 if (wpa_supplicant_ctrl_iface_dup_network(wpa_s, buf + 12))
7078 } else if (os_strcmp(buf, "LIST_CREDS") == 0) {
7079 reply_len = wpa_supplicant_ctrl_iface_list_creds(
7080 wpa_s, reply, reply_size);
7081 } else if (os_strcmp(buf, "ADD_CRED") == 0) {
7082 reply_len = wpa_supplicant_ctrl_iface_add_cred(
7083 wpa_s, reply, reply_size);
7084 } else if (os_strncmp(buf, "REMOVE_CRED ", 12) == 0) {
7085 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s, buf + 12))
7087 } else if (os_strncmp(buf, "SET_CRED ", 9) == 0) {
7088 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s, buf + 9))
7090 } else if (os_strncmp(buf, "GET_CRED ", 9) == 0) {
7091 reply_len = wpa_supplicant_ctrl_iface_get_cred(wpa_s, buf + 9,
7094 #ifndef CONFIG_NO_CONFIG_WRITE
7095 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
7096 if (wpa_supplicant_ctrl_iface_save_config(wpa_s))
7098 #endif /* CONFIG_NO_CONFIG_WRITE */
7099 } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
7100 reply_len = wpa_supplicant_ctrl_iface_get_capability(
7101 wpa_s, buf + 15, reply, reply_size);
7102 } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) {
7103 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8))
7105 } else if (os_strncmp(buf, "SCAN_INTERVAL ", 14) == 0) {
7106 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s, buf + 14))
7108 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
7109 reply_len = wpa_supplicant_global_iface_list(
7110 wpa_s->global, reply, reply_size);
7111 } else if (os_strcmp(buf, "INTERFACES") == 0) {
7112 reply_len = wpa_supplicant_global_iface_interfaces(
7113 wpa_s->global, reply, reply_size);
7114 } else if (os_strncmp(buf, "BSS ", 4) == 0) {
7115 reply_len = wpa_supplicant_ctrl_iface_bss(
7116 wpa_s, buf + 4, reply, reply_size);
7118 } else if (os_strcmp(buf, "STA-FIRST") == 0) {
7119 reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size);
7120 } else if (os_strncmp(buf, "STA ", 4) == 0) {
7121 reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply,
7123 } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) {
7124 reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply,
7126 } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) {
7127 if (ap_ctrl_iface_sta_deauthenticate(wpa_s, buf + 15))
7129 } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) {
7130 if (ap_ctrl_iface_sta_disassociate(wpa_s, buf + 13))
7132 } else if (os_strncmp(buf, "CHAN_SWITCH ", 12) == 0) {
7133 if (ap_ctrl_iface_chanswitch(wpa_s, buf + 12))
7135 #endif /* CONFIG_AP */
7136 } else if (os_strcmp(buf, "SUSPEND") == 0) {
7137 wpas_notify_suspend(wpa_s->global);
7138 } else if (os_strcmp(buf, "RESUME") == 0) {
7139 wpas_notify_resume(wpa_s->global);
7140 #ifdef CONFIG_TESTING_OPTIONS
7141 } else if (os_strcmp(buf, "DROP_SA") == 0) {
7142 wpa_supplicant_ctrl_iface_drop_sa(wpa_s);
7143 #endif /* CONFIG_TESTING_OPTIONS */
7144 } else if (os_strncmp(buf, "ROAM ", 5) == 0) {
7145 if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5))
7147 } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) {
7148 if (wpa_supplicant_ctrl_iface_sta_autoconnect(wpa_s, buf + 16))
7150 } else if (os_strncmp(buf, "BSS_EXPIRE_AGE ", 15) == 0) {
7151 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s, buf + 15))
7153 } else if (os_strncmp(buf, "BSS_EXPIRE_COUNT ", 17) == 0) {
7154 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s,
7157 } else if (os_strncmp(buf, "BSS_FLUSH ", 10) == 0) {
7158 if (wpa_supplicant_ctrl_iface_bss_flush(wpa_s, buf + 10))
7161 } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) {
7162 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14))
7164 } else if (os_strncmp(buf, "TDLS_SETUP ", 11) == 0) {
7165 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s, buf + 11))
7167 } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) {
7168 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14))
7170 #endif /* CONFIG_TDLS */
7171 } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) {
7172 reply_len = wpa_supplicant_signal_poll(wpa_s, reply,
7174 } else if (os_strncmp(buf, "PKTCNT_POLL", 11) == 0) {
7175 reply_len = wpa_supplicant_pktcnt_poll(wpa_s, reply,
7177 #ifdef CONFIG_AUTOSCAN
7178 } else if (os_strncmp(buf, "AUTOSCAN ", 9) == 0) {
7179 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s, buf + 9))
7181 #endif /* CONFIG_AUTOSCAN */
7183 } else if (os_strncmp(buf, "DRIVER ", 7) == 0) {
7184 reply_len = wpa_supplicant_driver_cmd(wpa_s, buf + 7, reply,
7186 #endif /* ANDROID */
7187 } else if (os_strncmp(buf, "VENDOR ", 7) == 0) {
7188 reply_len = wpa_supplicant_vendor_cmd(wpa_s, buf + 7, reply,
7190 } else if (os_strcmp(buf, "REAUTHENTICATE") == 0) {
7191 pmksa_cache_clear_current(wpa_s->wpa);
7192 eapol_sm_request_reauth(wpa_s->eapol);
7194 } else if (os_strncmp(buf, "WNM_SLEEP ", 10) == 0) {
7195 if (wpas_ctrl_iface_wnm_sleep(wpa_s, buf + 10))
7197 } else if (os_strncmp(buf, "WNM_BSS_QUERY ", 10) == 0) {
7198 if (wpas_ctrl_iface_wnm_bss_query(wpa_s, buf + 10))
7200 #endif /* CONFIG_WNM */
7201 } else if (os_strcmp(buf, "FLUSH") == 0) {
7202 wpa_supplicant_ctrl_iface_flush(wpa_s);
7203 } else if (os_strncmp(buf, "RADIO_WORK ", 11) == 0) {
7204 reply_len = wpas_ctrl_radio_work(wpa_s, buf + 11, reply,
7206 #ifdef CONFIG_TESTING_OPTIONS
7207 } else if (os_strncmp(buf, "MGMT_TX ", 8) == 0) {
7208 if (wpas_ctrl_iface_mgmt_tx(wpa_s, buf + 8) < 0)
7210 } else if (os_strcmp(buf, "MGMT_TX_DONE") == 0) {
7211 wpas_ctrl_iface_mgmt_tx_done(wpa_s);
7212 } else if (os_strncmp(buf, "DRIVER_EVENT ", 13) == 0) {
7213 if (wpas_ctrl_iface_driver_event(wpa_s, buf + 13) < 0)
7215 } else if (os_strncmp(buf, "EAPOL_RX ", 9) == 0) {
7216 if (wpas_ctrl_iface_eapol_rx(wpa_s, buf + 9) < 0)
7218 } else if (os_strncmp(buf, "DATA_TEST_CONFIG ", 17) == 0) {
7219 if (wpas_ctrl_iface_data_test_config(wpa_s, buf + 17) < 0)
7221 } else if (os_strncmp(buf, "DATA_TEST_TX ", 13) == 0) {
7222 if (wpas_ctrl_iface_data_test_tx(wpa_s, buf + 13) < 0)
7224 #endif /* CONFIG_TESTING_OPTIONS */
7225 } else if (os_strncmp(buf, "VENDOR_ELEM_ADD ", 16) == 0) {
7226 if (wpas_ctrl_vendor_elem_add(wpa_s, buf + 16) < 0)
7228 } else if (os_strncmp(buf, "VENDOR_ELEM_GET ", 16) == 0) {
7229 reply_len = wpas_ctrl_vendor_elem_get(wpa_s, buf + 16, reply,
7231 } else if (os_strncmp(buf, "VENDOR_ELEM_REMOVE ", 19) == 0) {
7232 if (wpas_ctrl_vendor_elem_remove(wpa_s, buf + 19) < 0)
7235 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
7239 if (reply_len < 0) {
7240 os_memcpy(reply, "FAIL\n", 5);
7244 *resp_len = reply_len;
7249 static int wpa_supplicant_global_iface_add(struct wpa_global *global,
7252 struct wpa_interface iface;
7256 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
7257 * TAB<bridge_ifname>
7259 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd);
7261 os_memset(&iface, 0, sizeof(iface));
7264 iface.ifname = pos = cmd;
7265 pos = os_strchr(pos, '\t');
7268 if (iface.ifname[0] == '\0')
7273 iface.confname = pos;
7274 pos = os_strchr(pos, '\t');
7277 if (iface.confname[0] == '\0')
7278 iface.confname = NULL;
7283 pos = os_strchr(pos, '\t');
7286 if (iface.driver[0] == '\0')
7287 iface.driver = NULL;
7291 iface.ctrl_interface = pos;
7292 pos = os_strchr(pos, '\t');
7295 if (iface.ctrl_interface[0] == '\0')
7296 iface.ctrl_interface = NULL;
7300 iface.driver_param = pos;
7301 pos = os_strchr(pos, '\t');
7304 if (iface.driver_param[0] == '\0')
7305 iface.driver_param = NULL;
7309 iface.bridge_ifname = pos;
7310 pos = os_strchr(pos, '\t');
7313 if (iface.bridge_ifname[0] == '\0')
7314 iface.bridge_ifname = NULL;
7319 if (wpa_supplicant_get_iface(global, iface.ifname))
7322 return wpa_supplicant_add_iface(global, &iface) ? 0 : -1;
7326 static int wpa_supplicant_global_iface_remove(struct wpa_global *global,
7329 struct wpa_supplicant *wpa_s;
7331 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd);
7333 wpa_s = wpa_supplicant_get_iface(global, cmd);
7336 return wpa_supplicant_remove_iface(global, wpa_s, 0);
7340 static void wpa_free_iface_info(struct wpa_interface_info *iface)
7342 struct wpa_interface_info *prev;
7346 iface = iface->next;
7348 os_free(prev->ifname);
7349 os_free(prev->desc);
7355 static int wpa_supplicant_global_iface_list(struct wpa_global *global,
7359 struct wpa_interface_info *iface = NULL, *last = NULL, *tmp;
7362 for (i = 0; wpa_drivers[i]; i++) {
7363 struct wpa_driver_ops *drv = wpa_drivers[i];
7364 if (drv->get_interfaces == NULL)
7366 tmp = drv->get_interfaces(global->drv_priv[i]);
7380 for (tmp = iface; tmp; tmp = tmp->next) {
7381 res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n",
7382 tmp->drv_name, tmp->ifname,
7383 tmp->desc ? tmp->desc : "");
7384 if (res < 0 || res >= end - pos) {
7391 wpa_free_iface_info(iface);
7397 static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
7402 struct wpa_supplicant *wpa_s;
7404 wpa_s = global->ifaces;
7409 res = os_snprintf(pos, end - pos, "%s\n", wpa_s->ifname);
7410 if (res < 0 || res >= end - pos) {
7415 wpa_s = wpa_s->next;
7421 static char * wpas_global_ctrl_iface_ifname(struct wpa_global *global,
7423 char *cmd, size_t *resp_len)
7425 struct wpa_supplicant *wpa_s;
7427 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
7428 if (os_strcmp(ifname, wpa_s->ifname) == 0)
7432 if (wpa_s == NULL) {
7433 char *resp = os_strdup("FAIL-NO-IFNAME-MATCH\n");
7435 *resp_len = os_strlen(resp);
7441 return wpa_supplicant_ctrl_iface_process(wpa_s, cmd, resp_len);
7445 static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global *global,
7446 char *buf, size_t *resp_len)
7449 static const char * cmd[] = {
7455 "P2P_GET_PASSPHRASE",
7456 "P2P_SERVICE_UPDATE",
7457 "P2P_SERVICE_FLUSH",
7464 static const char * prefix[] = {
7467 #endif /* ANDROID */
7473 "P2P_GROUP_REMOVE ",
7476 "P2P_SERV_DISC_REQ ",
7477 "P2P_SERV_DISC_CANCEL_REQ ",
7478 "P2P_SERV_DISC_RESP ",
7479 "P2P_SERV_DISC_EXTERNAL ",
7487 "P2P_PRESENCE_REQ ",
7489 "P2P_REMOVE_CLIENT ",
7490 "NFC_GET_HANDOVER_SEL ",
7491 "NFC_GET_HANDOVER_REQ ",
7492 "NFC_REPORT_HANDOVER ",
7498 if (global->p2p_init_wpa_s == NULL)
7501 for (i = 0; !found && cmd[i]; i++) {
7502 if (os_strcmp(buf, cmd[i]) == 0)
7506 for (i = 0; !found && prefix[i]; i++) {
7507 if (os_strncmp(buf, prefix[i], os_strlen(prefix[i])) == 0)
7512 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
7514 #endif /* CONFIG_P2P */
7519 static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global *global,
7520 char *buf, size_t *resp_len)
7522 #ifdef CONFIG_WIFI_DISPLAY
7523 if (global->p2p_init_wpa_s == NULL)
7525 if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0 ||
7526 os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0)
7527 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
7529 #endif /* CONFIG_WIFI_DISPLAY */
7534 static char * wpas_global_ctrl_iface_redir(struct wpa_global *global,
7535 char *buf, size_t *resp_len)
7539 ret = wpas_global_ctrl_iface_redir_p2p(global, buf, resp_len);
7543 ret = wpas_global_ctrl_iface_redir_wfd(global, buf, resp_len);
7551 static int wpas_global_ctrl_iface_set(struct wpa_global *global, char *cmd)
7555 value = os_strchr(cmd, ' ');
7560 wpa_printf(MSG_DEBUG, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd, value);
7562 #ifdef CONFIG_WIFI_DISPLAY
7563 if (os_strcasecmp(cmd, "wifi_display") == 0) {
7564 wifi_display_enable(global, !!atoi(value));
7567 #endif /* CONFIG_WIFI_DISPLAY */
7569 /* Restore cmd to its original value to allow redirection */
7576 #ifndef CONFIG_NO_CONFIG_WRITE
7577 static int wpas_global_ctrl_iface_save_config(struct wpa_global *global)
7579 int ret = 0, saved = 0;
7580 struct wpa_supplicant *wpa_s;
7582 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
7583 if (!wpa_s->conf->update_config) {
7584 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
7588 if (wpa_config_write(wpa_s->confname, wpa_s->conf)) {
7589 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
7592 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
7597 if (!saved && !ret) {
7598 wpa_dbg(wpa_s, MSG_DEBUG,
7599 "CTRL_IFACE: SAVE_CONFIG - No configuration files could be updated");
7605 #endif /* CONFIG_NO_CONFIG_WRITE */
7608 static int wpas_global_ctrl_iface_status(struct wpa_global *global,
7609 char *buf, size_t buflen)
7613 struct wpa_supplicant *wpa_s;
7619 if (global->p2p && !global->p2p_disabled) {
7620 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
7623 MAC2STR(global->p2p_dev_addr),
7624 p2p_get_state_txt(global->p2p));
7625 if (ret < 0 || ret >= end - pos)
7628 } else if (global->p2p) {
7629 ret = os_snprintf(pos, end - pos, "p2p_state=DISABLED\n");
7630 if (ret < 0 || ret >= end - pos)
7634 #endif /* CONFIG_P2P */
7636 #ifdef CONFIG_WIFI_DISPLAY
7637 ret = os_snprintf(pos, end - pos, "wifi_display=%d\n",
7638 !!global->wifi_display);
7639 if (ret < 0 || ret >= end - pos)
7642 #endif /* CONFIG_WIFI_DISPLAY */
7644 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
7645 ret = os_snprintf(pos, end - pos, "ifname=%s\n"
7646 "address=" MACSTR "\n",
7647 wpa_s->ifname, MAC2STR(wpa_s->own_addr));
7648 if (ret < 0 || ret >= end - pos)
7657 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
7658 char *buf, size_t *resp_len)
7661 const int reply_size = 2048;
7663 int level = MSG_DEBUG;
7665 if (os_strncmp(buf, "IFNAME=", 7) == 0) {
7666 char *pos = os_strchr(buf + 7, ' ');
7669 return wpas_global_ctrl_iface_ifname(global,
7675 reply = wpas_global_ctrl_iface_redir(global, buf, resp_len);
7679 if (os_strcmp(buf, "PING") == 0)
7680 level = MSG_EXCESSIVE;
7681 wpa_hexdump_ascii(level, "RX global ctrl_iface",
7682 (const u8 *) buf, os_strlen(buf));
7684 reply = os_malloc(reply_size);
7685 if (reply == NULL) {
7690 os_memcpy(reply, "OK\n", 3);
7693 if (os_strcmp(buf, "PING") == 0) {
7694 os_memcpy(reply, "PONG\n", 5);
7696 } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) {
7697 if (wpa_supplicant_global_iface_add(global, buf + 14))
7699 } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) {
7700 if (wpa_supplicant_global_iface_remove(global, buf + 17))
7702 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
7703 reply_len = wpa_supplicant_global_iface_list(
7704 global, reply, reply_size);
7705 } else if (os_strcmp(buf, "INTERFACES") == 0) {
7706 reply_len = wpa_supplicant_global_iface_interfaces(
7707 global, reply, reply_size);
7708 } else if (os_strcmp(buf, "TERMINATE") == 0) {
7709 wpa_supplicant_terminate_proc(global);
7710 } else if (os_strcmp(buf, "SUSPEND") == 0) {
7711 wpas_notify_suspend(global);
7712 } else if (os_strcmp(buf, "RESUME") == 0) {
7713 wpas_notify_resume(global);
7714 } else if (os_strncmp(buf, "SET ", 4) == 0) {
7715 if (wpas_global_ctrl_iface_set(global, buf + 4)) {
7717 if (global->p2p_init_wpa_s) {
7719 /* Check if P2P redirection would work for this
7721 return wpa_supplicant_ctrl_iface_process(
7722 global->p2p_init_wpa_s,
7725 #endif /* CONFIG_P2P */
7728 #ifndef CONFIG_NO_CONFIG_WRITE
7729 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
7730 if (wpas_global_ctrl_iface_save_config(global))
7732 #endif /* CONFIG_NO_CONFIG_WRITE */
7733 } else if (os_strcmp(buf, "STATUS") == 0) {
7734 reply_len = wpas_global_ctrl_iface_status(global, reply,
7736 #ifdef CONFIG_MODULE_TESTS
7737 } else if (os_strcmp(buf, "MODULE_TESTS") == 0) {
7738 int wpas_module_tests(void);
7739 if (wpas_module_tests() < 0)
7741 #endif /* CONFIG_MODULE_TESTS */
7743 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
7747 if (reply_len < 0) {
7748 os_memcpy(reply, "FAIL\n", 5);
7752 *resp_len = reply_len;