2 * WPA Supplicant / Control interface (shared code for all backends)
3 * Copyright (c) 2004-2015, 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 "crypto/tls.h"
23 #include "ap/hostapd.h"
24 #include "eap_peer/eap.h"
25 #include "eapol_supp/eapol_supp_sm.h"
26 #include "rsn_supp/wpa.h"
27 #include "rsn_supp/preauth.h"
28 #include "rsn_supp/pmksa_cache.h"
29 #include "l2_packet/l2_packet.h"
32 #include "wpa_supplicant_i.h"
34 #include "wps_supplicant.h"
37 #include "p2p_supplicant.h"
39 #include "hs20_supplicant.h"
40 #include "wifi_display.h"
44 #include "ctrl_iface.h"
45 #include "interworking.h"
46 #include "blacklist.h"
49 #include "offchannel.h"
50 #include "drivers/driver.h"
53 static int wpa_supplicant_global_iface_list(struct wpa_global *global,
55 static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
57 static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s,
60 static int set_bssid_filter(struct wpa_supplicant *wpa_s, char *val)
63 u8 addr[ETH_ALEN], *filter = NULL, *n;
70 if (hwaddr_aton(pos, addr)) {
74 n = os_realloc_array(filter, count + 1, ETH_ALEN);
80 os_memcpy(filter + count * ETH_ALEN, addr, ETH_ALEN);
83 pos = os_strchr(pos, ' ');
88 wpa_hexdump(MSG_DEBUG, "bssid_filter", filter, count * ETH_ALEN);
89 os_free(wpa_s->bssid_filter);
90 wpa_s->bssid_filter = filter;
91 wpa_s->bssid_filter_count = count;
97 static int set_disallow_aps(struct wpa_supplicant *wpa_s, char *val)
100 u8 addr[ETH_ALEN], *bssid = NULL, *n;
101 struct wpa_ssid_value *ssid = NULL, *ns;
102 size_t count = 0, ssid_count = 0;
106 * disallow_list ::= <ssid_spec> | <bssid_spec> | <disallow_list> | ""
107 * SSID_SPEC ::= ssid <SSID_HEX>
108 * BSSID_SPEC ::= bssid <BSSID_HEX>
115 if (os_strncmp(pos, "bssid ", 6) == 0) {
118 res = hwaddr_aton2(pos, addr);
122 wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
123 "BSSID value '%s'", pos);
127 n = os_realloc_array(bssid, count + 1, ETH_ALEN);
134 os_memcpy(bssid + count * ETH_ALEN, addr, ETH_ALEN);
136 } else if (os_strncmp(pos, "ssid ", 5) == 0) {
142 if (*end == '\0' || *end == ' ')
147 ns = os_realloc_array(ssid, ssid_count + 1,
148 sizeof(struct wpa_ssid_value));
156 if ((end - pos) & 0x01 ||
157 end - pos > 2 * SSID_MAX_LEN ||
158 hexstr2bin(pos, ssid[ssid_count].ssid,
159 (end - pos) / 2) < 0) {
162 wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
163 "SSID value '%s'", pos);
166 ssid[ssid_count].ssid_len = (end - pos) / 2;
167 wpa_hexdump_ascii(MSG_DEBUG, "disallow_aps SSID",
168 ssid[ssid_count].ssid,
169 ssid[ssid_count].ssid_len);
173 wpa_printf(MSG_DEBUG, "Unexpected disallow_aps value "
180 pos = os_strchr(pos, ' ');
185 wpa_hexdump(MSG_DEBUG, "disallow_aps_bssid", bssid, count * ETH_ALEN);
186 os_free(wpa_s->disallow_aps_bssid);
187 wpa_s->disallow_aps_bssid = bssid;
188 wpa_s->disallow_aps_bssid_count = count;
190 wpa_printf(MSG_DEBUG, "disallow_aps_ssid_count %d", (int) ssid_count);
191 os_free(wpa_s->disallow_aps_ssid);
192 wpa_s->disallow_aps_ssid = ssid;
193 wpa_s->disallow_aps_ssid_count = ssid_count;
195 if (!wpa_s->current_ssid || wpa_s->wpa_state < WPA_AUTHENTICATING)
198 c = wpa_s->current_ssid;
199 if (c->mode != WPAS_MODE_INFRA && c->mode != WPAS_MODE_IBSS)
202 if (!disallowed_bssid(wpa_s, wpa_s->bssid) &&
203 !disallowed_ssid(wpa_s, c->ssid, c->ssid_len))
206 wpa_printf(MSG_DEBUG, "Disconnect and try to find another network "
207 "because current AP was marked disallowed");
210 wpa_s->sme.prev_bssid_set = 0;
211 #endif /* CONFIG_SME */
212 wpa_s->reassociate = 1;
213 wpa_s->own_disconnect_req = 1;
214 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
215 wpa_supplicant_req_scan(wpa_s, 0, 0);
221 #ifndef CONFIG_NO_CONFIG_BLOBS
222 static int wpas_ctrl_set_blob(struct wpa_supplicant *wpa_s, char *pos)
225 struct wpa_config_blob *blob;
228 pos = os_strchr(pos, ' ');
232 len = os_strlen(pos);
236 wpa_printf(MSG_DEBUG, "CTRL: Set blob '%s'", name);
237 blob = os_zalloc(sizeof(*blob));
240 blob->name = os_strdup(name);
241 blob->data = os_malloc(len / 2);
242 if (blob->name == NULL || blob->data == NULL) {
243 wpa_config_free_blob(blob);
247 if (hexstr2bin(pos, blob->data, len / 2) < 0) {
248 wpa_printf(MSG_DEBUG, "CTRL: Invalid blob hex data");
249 wpa_config_free_blob(blob);
254 wpa_config_set_blob(wpa_s->conf, blob);
258 #endif /* CONFIG_NO_CONFIG_BLOBS */
261 static int wpas_ctrl_pno(struct wpa_supplicant *wpa_s, char *cmd)
269 params = os_strchr(cmd, ' ');
270 os_free(wpa_s->manual_sched_scan_freqs);
273 pos = os_strstr(params, "freq=");
275 freqs = freq_range_to_channel_list(wpa_s,
278 wpa_s->manual_sched_scan_freqs = freqs;
279 ret = wpas_start_pno(wpa_s);
281 ret = wpas_stop_pno(wpa_s);
287 static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s,
293 value = os_strchr(cmd, ' ');
298 wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value);
299 if (os_strcasecmp(cmd, "EAPOL::heldPeriod") == 0) {
300 eapol_sm_configure(wpa_s->eapol,
301 atoi(value), -1, -1, -1);
302 } else if (os_strcasecmp(cmd, "EAPOL::authPeriod") == 0) {
303 eapol_sm_configure(wpa_s->eapol,
304 -1, atoi(value), -1, -1);
305 } else if (os_strcasecmp(cmd, "EAPOL::startPeriod") == 0) {
306 eapol_sm_configure(wpa_s->eapol,
307 -1, -1, atoi(value), -1);
308 } else if (os_strcasecmp(cmd, "EAPOL::maxStart") == 0) {
309 eapol_sm_configure(wpa_s->eapol,
310 -1, -1, -1, atoi(value));
311 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKLifetime") == 0) {
312 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME,
315 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKReauthThreshold") ==
317 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD,
320 } else if (os_strcasecmp(cmd, "dot11RSNAConfigSATimeout") == 0) {
321 if (wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, atoi(value)))
323 } else if (os_strcasecmp(cmd, "wps_fragment_size") == 0) {
324 wpa_s->wps_fragment_size = atoi(value);
325 #ifdef CONFIG_WPS_TESTING
326 } else if (os_strcasecmp(cmd, "wps_version_number") == 0) {
328 val = strtol(value, NULL, 0);
329 if (val < 0 || val > 0xff) {
331 wpa_printf(MSG_DEBUG, "WPS: Invalid "
332 "wps_version_number %ld", val);
334 wps_version_number = val;
335 wpa_printf(MSG_DEBUG, "WPS: Testing - force WPS "
337 (wps_version_number & 0xf0) >> 4,
338 wps_version_number & 0x0f);
340 } else if (os_strcasecmp(cmd, "wps_testing_dummy_cred") == 0) {
341 wps_testing_dummy_cred = atoi(value);
342 wpa_printf(MSG_DEBUG, "WPS: Testing - dummy_cred=%d",
343 wps_testing_dummy_cred);
344 } else if (os_strcasecmp(cmd, "wps_corrupt_pkhash") == 0) {
345 wps_corrupt_pkhash = atoi(value);
346 wpa_printf(MSG_DEBUG, "WPS: Testing - wps_corrupt_pkhash=%d",
348 #endif /* CONFIG_WPS_TESTING */
349 } else if (os_strcasecmp(cmd, "ampdu") == 0) {
350 if (wpa_drv_ampdu(wpa_s, atoi(value)) < 0)
353 #ifdef CONFIG_TDLS_TESTING
354 } else if (os_strcasecmp(cmd, "tdls_testing") == 0) {
355 extern unsigned int tdls_testing;
356 tdls_testing = strtol(value, NULL, 0);
357 wpa_printf(MSG_DEBUG, "TDLS: tdls_testing=0x%x", tdls_testing);
358 #endif /* CONFIG_TDLS_TESTING */
359 } else if (os_strcasecmp(cmd, "tdls_disabled") == 0) {
360 int disabled = atoi(value);
361 wpa_printf(MSG_DEBUG, "TDLS: tdls_disabled=%d", disabled);
363 if (wpa_drv_tdls_oper(wpa_s, TDLS_DISABLE, NULL) < 0)
365 } else if (wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL) < 0)
367 wpa_tdls_enable(wpa_s->wpa, !disabled);
368 #endif /* CONFIG_TDLS */
369 } else if (os_strcasecmp(cmd, "pno") == 0) {
370 ret = wpas_ctrl_pno(wpa_s, value);
371 } else if (os_strcasecmp(cmd, "radio_disabled") == 0) {
372 int disabled = atoi(value);
373 if (wpa_drv_radio_disable(wpa_s, disabled) < 0)
376 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
377 } else if (os_strcasecmp(cmd, "uapsd") == 0) {
378 if (os_strcmp(value, "disable") == 0)
379 wpa_s->set_sta_uapsd = 0;
383 /* format: BE,BK,VI,VO;max SP Length */
385 pos = os_strchr(value, ',');
390 pos = os_strchr(pos, ',');
395 pos = os_strchr(pos, ',');
400 /* ignore max SP Length for now */
402 wpa_s->set_sta_uapsd = 1;
403 wpa_s->sta_uapsd = 0;
405 wpa_s->sta_uapsd |= BIT(0);
407 wpa_s->sta_uapsd |= BIT(1);
409 wpa_s->sta_uapsd |= BIT(2);
411 wpa_s->sta_uapsd |= BIT(3);
413 } else if (os_strcasecmp(cmd, "ps") == 0) {
414 ret = wpa_drv_set_p2p_powersave(wpa_s, atoi(value), -1, -1);
415 #ifdef CONFIG_WIFI_DISPLAY
416 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
417 int enabled = !!atoi(value);
418 if (enabled && !wpa_s->global->p2p)
421 wifi_display_enable(wpa_s->global, enabled);
422 #endif /* CONFIG_WIFI_DISPLAY */
423 } else if (os_strcasecmp(cmd, "bssid_filter") == 0) {
424 ret = set_bssid_filter(wpa_s, value);
425 } else if (os_strcasecmp(cmd, "disallow_aps") == 0) {
426 ret = set_disallow_aps(wpa_s, value);
427 } else if (os_strcasecmp(cmd, "no_keep_alive") == 0) {
428 wpa_s->no_keep_alive = !!atoi(value);
429 #ifdef CONFIG_TESTING_OPTIONS
430 } else if (os_strcasecmp(cmd, "ext_mgmt_frame_handling") == 0) {
431 wpa_s->ext_mgmt_frame_handling = !!atoi(value);
432 } else if (os_strcasecmp(cmd, "ext_eapol_frame_io") == 0) {
433 wpa_s->ext_eapol_frame_io = !!atoi(value);
435 if (wpa_s->ap_iface) {
436 wpa_s->ap_iface->bss[0]->ext_eapol_frame_io =
437 wpa_s->ext_eapol_frame_io;
439 #endif /* CONFIG_AP */
440 } else if (os_strcasecmp(cmd, "extra_roc_dur") == 0) {
441 wpa_s->extra_roc_dur = atoi(value);
442 } else if (os_strcasecmp(cmd, "test_failure") == 0) {
443 wpa_s->test_failure = atoi(value);
444 #endif /* CONFIG_TESTING_OPTIONS */
445 #ifndef CONFIG_NO_CONFIG_BLOBS
446 } else if (os_strcmp(cmd, "blob") == 0) {
447 ret = wpas_ctrl_set_blob(wpa_s, value);
448 #endif /* CONFIG_NO_CONFIG_BLOBS */
449 } else if (os_strcasecmp(cmd, "setband") == 0) {
450 if (os_strcmp(value, "AUTO") == 0)
451 wpa_s->setband = WPA_SETBAND_AUTO;
452 else if (os_strcmp(value, "5G") == 0)
453 wpa_s->setband = WPA_SETBAND_5G;
454 else if (os_strcmp(value, "2G") == 0)
455 wpa_s->setband = WPA_SETBAND_2G;
460 ret = wpa_config_process_global(wpa_s->conf, cmd, -1);
462 wpa_supplicant_update_config(wpa_s);
469 static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s,
470 char *cmd, char *buf, size_t buflen)
474 wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd);
476 if (os_strcmp(cmd, "version") == 0) {
477 res = os_snprintf(buf, buflen, "%s", VERSION_STR);
478 } else if (os_strcasecmp(cmd, "country") == 0) {
479 if (wpa_s->conf->country[0] && wpa_s->conf->country[1])
480 res = os_snprintf(buf, buflen, "%c%c",
481 wpa_s->conf->country[0],
482 wpa_s->conf->country[1]);
483 #ifdef CONFIG_WIFI_DISPLAY
484 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
486 if (wpa_s->global->p2p == NULL ||
487 wpa_s->global->p2p_disabled)
490 enabled = wpa_s->global->wifi_display;
491 res = os_snprintf(buf, buflen, "%d", enabled);
492 #endif /* CONFIG_WIFI_DISPLAY */
493 #ifdef CONFIG_TESTING_GET_GTK
494 } else if (os_strcmp(cmd, "gtk") == 0) {
495 if (wpa_s->last_gtk_len == 0)
497 res = wpa_snprintf_hex(buf, buflen, wpa_s->last_gtk,
498 wpa_s->last_gtk_len);
500 #endif /* CONFIG_TESTING_GET_GTK */
501 } else if (os_strcmp(cmd, "tls_library") == 0) {
502 res = tls_get_library_version(buf, buflen);
504 res = wpa_config_get_value(cmd, wpa_s->conf, buf, buflen);
507 if (os_snprintf_error(buflen, res))
513 #ifdef IEEE8021X_EAPOL
514 static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s,
518 struct wpa_ssid *ssid = wpa_s->current_ssid;
520 if (hwaddr_aton(addr, bssid)) {
521 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address "
526 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid));
527 rsn_preauth_deinit(wpa_s->wpa);
528 if (rsn_preauth_init(wpa_s->wpa, bssid, ssid ? &ssid->eap : NULL))
533 #endif /* IEEE8021X_EAPOL */
536 #ifdef CONFIG_PEERKEY
537 /* MLME-STKSTART.request(peer) */
538 static int wpa_supplicant_ctrl_iface_stkstart(
539 struct wpa_supplicant *wpa_s, char *addr)
543 if (hwaddr_aton(addr, peer)) {
544 wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART: invalid "
545 "address '%s'", addr);
549 wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART " MACSTR,
552 return wpa_sm_stkstart(wpa_s->wpa, peer);
554 #endif /* CONFIG_PEERKEY */
559 static int wpa_supplicant_ctrl_iface_tdls_discover(
560 struct wpa_supplicant *wpa_s, char *addr)
565 if (hwaddr_aton(addr, peer)) {
566 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER: invalid "
567 "address '%s'", addr);
571 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER " MACSTR,
574 if (wpa_tdls_is_external_setup(wpa_s->wpa))
575 ret = wpa_tdls_send_discovery_request(wpa_s->wpa, peer);
577 ret = wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer);
583 static int wpa_supplicant_ctrl_iface_tdls_setup(
584 struct wpa_supplicant *wpa_s, char *addr)
589 if (hwaddr_aton(addr, peer)) {
590 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP: invalid "
591 "address '%s'", addr);
595 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP " MACSTR,
598 if ((wpa_s->conf->tdls_external_control) &&
599 wpa_tdls_is_external_setup(wpa_s->wpa))
600 return wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
602 wpa_tdls_remove(wpa_s->wpa, peer);
604 if (wpa_tdls_is_external_setup(wpa_s->wpa))
605 ret = wpa_tdls_start(wpa_s->wpa, peer);
607 ret = wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
613 static int wpa_supplicant_ctrl_iface_tdls_teardown(
614 struct wpa_supplicant *wpa_s, char *addr)
619 if (os_strcmp(addr, "*") == 0) {
620 /* remove everyone */
621 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN *");
622 wpa_tdls_teardown_peers(wpa_s->wpa);
626 if (hwaddr_aton(addr, peer)) {
627 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN: invalid "
628 "address '%s'", addr);
632 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN " MACSTR,
635 if ((wpa_s->conf->tdls_external_control) &&
636 wpa_tdls_is_external_setup(wpa_s->wpa))
637 return wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
639 if (wpa_tdls_is_external_setup(wpa_s->wpa))
640 ret = wpa_tdls_teardown_link(
642 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED);
644 ret = wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
650 static int ctrl_iface_get_capability_tdls(
651 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
655 ret = os_snprintf(buf, buflen, "%s\n",
656 wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT ?
658 WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP ?
659 "EXTERNAL" : "INTERNAL") : "UNSUPPORTED");
660 if (os_snprintf_error(buflen, ret))
666 static int wpa_supplicant_ctrl_iface_tdls_chan_switch(
667 struct wpa_supplicant *wpa_s, char *cmd)
670 struct hostapd_freq_params freq_params;
674 if (!wpa_tdls_is_external_setup(wpa_s->wpa)) {
676 "tdls_chanswitch: Only supported with external setup");
680 os_memset(&freq_params, 0, sizeof(freq_params));
682 pos = os_strchr(cmd, ' ');
687 oper_class = strtol(pos, &end, 10);
690 "tdls_chanswitch: Invalid op class provided");
695 freq_params.freq = atoi(pos);
696 if (freq_params.freq == 0) {
697 wpa_printf(MSG_INFO, "tdls_chanswitch: Invalid freq provided");
701 #define SET_FREQ_SETTING(str) \
703 const char *pos2 = os_strstr(pos, " " #str "="); \
705 pos2 += sizeof(" " #str "=") - 1; \
706 freq_params.str = atoi(pos2); \
710 SET_FREQ_SETTING(center_freq1);
711 SET_FREQ_SETTING(center_freq2);
712 SET_FREQ_SETTING(bandwidth);
713 SET_FREQ_SETTING(sec_channel_offset);
714 #undef SET_FREQ_SETTING
716 freq_params.ht_enabled = !!os_strstr(pos, " ht");
717 freq_params.vht_enabled = !!os_strstr(pos, " vht");
719 if (hwaddr_aton(cmd, peer)) {
720 wpa_printf(MSG_DEBUG,
721 "CTRL_IFACE TDLS_CHAN_SWITCH: Invalid address '%s'",
726 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_CHAN_SWITCH " MACSTR
727 " OP CLASS %d FREQ %d CENTER1 %d CENTER2 %d BW %d SEC_OFFSET %d%s%s",
728 MAC2STR(peer), oper_class, freq_params.freq,
729 freq_params.center_freq1, freq_params.center_freq2,
730 freq_params.bandwidth, freq_params.sec_channel_offset,
731 freq_params.ht_enabled ? " HT" : "",
732 freq_params.vht_enabled ? " VHT" : "");
734 return wpa_tdls_enable_chan_switch(wpa_s->wpa, peer, oper_class,
739 static int wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(
740 struct wpa_supplicant *wpa_s, char *cmd)
744 if (!wpa_tdls_is_external_setup(wpa_s->wpa)) {
746 "tdls_chanswitch: Only supported with external setup");
750 if (hwaddr_aton(cmd, peer)) {
751 wpa_printf(MSG_DEBUG,
752 "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH: Invalid address '%s'",
757 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH " MACSTR,
760 return wpa_tdls_disable_chan_switch(wpa_s->wpa, peer);
763 #endif /* CONFIG_TDLS */
766 static int wmm_ac_ctrl_addts(struct wpa_supplicant *wpa_s, char *cmd)
768 char *token, *context = NULL;
769 struct wmm_ac_ts_setup_params params = {
774 while ((token = str_token(cmd, " ", &context))) {
775 if (sscanf(token, "tsid=%i", ¶ms.tsid) == 1 ||
776 sscanf(token, "up=%i", ¶ms.user_priority) == 1 ||
777 sscanf(token, "nominal_msdu_size=%i",
778 ¶ms.nominal_msdu_size) == 1 ||
779 sscanf(token, "mean_data_rate=%i",
780 ¶ms.mean_data_rate) == 1 ||
781 sscanf(token, "min_phy_rate=%i",
782 ¶ms.minimum_phy_rate) == 1 ||
783 sscanf(token, "sba=%i",
784 ¶ms.surplus_bandwidth_allowance) == 1)
787 if (os_strcasecmp(token, "downlink") == 0) {
788 params.direction = WMM_TSPEC_DIRECTION_DOWNLINK;
789 } else if (os_strcasecmp(token, "uplink") == 0) {
790 params.direction = WMM_TSPEC_DIRECTION_UPLINK;
791 } else if (os_strcasecmp(token, "bidi") == 0) {
792 params.direction = WMM_TSPEC_DIRECTION_BI_DIRECTIONAL;
793 } else if (os_strcasecmp(token, "fixed_nominal_msdu") == 0) {
794 params.fixed_nominal_msdu = 1;
796 wpa_printf(MSG_DEBUG,
797 "CTRL: Invalid WMM_AC_ADDTS parameter: '%s'",
804 return wpas_wmm_ac_addts(wpa_s, ¶ms);
808 static int wmm_ac_ctrl_delts(struct wpa_supplicant *wpa_s, char *cmd)
812 return wpas_wmm_ac_delts(wpa_s, tsid);
816 #ifdef CONFIG_IEEE80211R
817 static int wpa_supplicant_ctrl_iface_ft_ds(
818 struct wpa_supplicant *wpa_s, char *addr)
820 u8 target_ap[ETH_ALEN];
824 if (hwaddr_aton(addr, target_ap)) {
825 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid "
826 "address '%s'", addr);
830 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap));
832 bss = wpa_bss_get_bssid(wpa_s, target_ap);
834 mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN);
838 return wpa_ft_start_over_ds(wpa_s->wpa, target_ap, mdie);
840 #endif /* CONFIG_IEEE80211R */
844 static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s,
847 u8 bssid[ETH_ALEN], *_bssid = bssid;
849 u8 p2p_dev_addr[ETH_ALEN];
850 #endif /* CONFIG_P2P */
852 u8 *_p2p_dev_addr = NULL;
853 #endif /* CONFIG_AP */
855 if (cmd == NULL || os_strcmp(cmd, "any") == 0) {
858 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
859 if (hwaddr_aton(cmd + 13, p2p_dev_addr)) {
860 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid "
861 "P2P Device Address '%s'",
865 _p2p_dev_addr = p2p_dev_addr;
866 #endif /* CONFIG_P2P */
867 } else if (hwaddr_aton(cmd, bssid)) {
868 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
875 return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid, _p2p_dev_addr);
876 #endif /* CONFIG_AP */
878 return wpas_wps_start_pbc(wpa_s, _bssid, 0);
882 static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s,
883 char *cmd, char *buf,
886 u8 bssid[ETH_ALEN], *_bssid = bssid;
890 pin = os_strchr(cmd, ' ');
894 if (os_strcmp(cmd, "any") == 0)
896 else if (os_strcmp(cmd, "get") == 0) {
897 ret = wps_generate_pin();
899 } else if (hwaddr_aton(cmd, bssid)) {
900 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
906 if (wpa_s->ap_iface) {
911 pos = os_strchr(pin, ' ');
918 return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin,
919 buf, buflen, timeout);
921 #endif /* CONFIG_AP */
924 ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0,
928 ret = os_snprintf(buf, buflen, "%s", pin);
929 if (os_snprintf_error(buflen, ret))
934 ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0, DEV_PW_DEFAULT);
939 /* Return the generated PIN */
940 ret = os_snprintf(buf, buflen, "%08d", ret);
941 if (os_snprintf_error(buflen, ret))
947 static int wpa_supplicant_ctrl_iface_wps_check_pin(
948 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
955 wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN",
956 (u8 *) cmd, os_strlen(cmd));
957 for (pos = cmd, len = 0; *pos != '\0'; pos++) {
958 if (*pos < '0' || *pos > '9')
962 wpa_printf(MSG_DEBUG, "WPS: Too long PIN");
966 if (len != 4 && len != 8) {
967 wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len);
973 unsigned int pin_val;
975 if (!wps_pin_valid(pin_val)) {
976 wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit");
977 ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n");
978 if (os_snprintf_error(buflen, ret))
984 ret = os_snprintf(buf, buflen, "%s", pin);
985 if (os_snprintf_error(buflen, ret))
992 #ifdef CONFIG_WPS_NFC
994 static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant *wpa_s,
997 u8 bssid[ETH_ALEN], *_bssid = bssid;
999 if (cmd == NULL || cmd[0] == '\0')
1001 else if (hwaddr_aton(cmd, bssid))
1004 return wpas_wps_start_nfc(wpa_s, NULL, _bssid, NULL, 0, 0, NULL, NULL,
1009 static int wpa_supplicant_ctrl_iface_wps_nfc_config_token(
1010 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1017 pos = os_strchr(cmd, ' ');
1020 if (os_strcmp(cmd, "WPS") == 0)
1022 else if (os_strcmp(cmd, "NDEF") == 0)
1027 buf = wpas_wps_nfc_config_token(wpa_s, ndef, pos);
1031 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1033 reply[res++] = '\n';
1042 static int wpa_supplicant_ctrl_iface_wps_nfc_token(
1043 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1049 if (os_strcmp(cmd, "WPS") == 0)
1051 else if (os_strcmp(cmd, "NDEF") == 0)
1056 buf = wpas_wps_nfc_token(wpa_s, ndef);
1060 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1062 reply[res++] = '\n';
1071 static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
1072 struct wpa_supplicant *wpa_s, char *pos)
1078 int forced_freq = 0;
1080 freq = strstr(pos, " freq=");
1084 forced_freq = atoi(freq);
1087 len = os_strlen(pos);
1092 buf = wpabuf_alloc(len);
1095 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
1100 ret = wpas_wps_nfc_tag_read(wpa_s, buf, forced_freq);
1107 static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant *wpa_s,
1108 char *reply, size_t max_len,
1114 buf = wpas_wps_nfc_handover_req(wpa_s, ndef);
1118 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1120 reply[res++] = '\n';
1130 static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant *wpa_s,
1131 char *reply, size_t max_len,
1137 buf = wpas_p2p_nfc_handover_req(wpa_s, ndef);
1139 wpa_printf(MSG_DEBUG, "P2P: Could not generate NFC handover request");
1143 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1145 reply[res++] = '\n';
1152 #endif /* CONFIG_P2P */
1155 static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant *wpa_s,
1156 char *cmd, char *reply,
1162 pos = os_strchr(cmd, ' ');
1167 if (os_strcmp(cmd, "WPS") == 0)
1169 else if (os_strcmp(cmd, "NDEF") == 0)
1174 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
1177 return wpas_ctrl_nfc_get_handover_req_wps(
1178 wpa_s, reply, max_len, ndef);
1182 if (os_strcmp(pos, "P2P-CR") == 0) {
1183 return wpas_ctrl_nfc_get_handover_req_p2p(
1184 wpa_s, reply, max_len, ndef);
1186 #endif /* CONFIG_P2P */
1192 static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant *wpa_s,
1193 char *reply, size_t max_len,
1194 int ndef, int cr, char *uuid)
1199 buf = wpas_wps_nfc_handover_sel(wpa_s, ndef, cr, uuid);
1203 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1205 reply[res++] = '\n';
1215 static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant *wpa_s,
1216 char *reply, size_t max_len,
1222 buf = wpas_p2p_nfc_handover_sel(wpa_s, ndef, tag);
1226 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1228 reply[res++] = '\n';
1235 #endif /* CONFIG_P2P */
1238 static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant *wpa_s,
1239 char *cmd, char *reply,
1245 pos = os_strchr(cmd, ' ');
1250 if (os_strcmp(cmd, "WPS") == 0)
1252 else if (os_strcmp(cmd, "NDEF") == 0)
1257 pos2 = os_strchr(pos, ' ');
1260 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
1263 return wpas_ctrl_nfc_get_handover_sel_wps(
1264 wpa_s, reply, max_len, ndef,
1265 os_strcmp(pos, "WPS-CR") == 0, pos2);
1269 if (os_strcmp(pos, "P2P-CR") == 0) {
1270 return wpas_ctrl_nfc_get_handover_sel_p2p(
1271 wpa_s, reply, max_len, ndef, 0);
1274 if (os_strcmp(pos, "P2P-CR-TAG") == 0) {
1275 return wpas_ctrl_nfc_get_handover_sel_p2p(
1276 wpa_s, reply, max_len, ndef, 1);
1278 #endif /* CONFIG_P2P */
1284 static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant *wpa_s,
1288 struct wpabuf *req, *sel;
1290 char *pos, *role, *type, *pos2;
1293 int forced_freq = 0;
1295 freq = strstr(cmd, " freq=");
1299 forced_freq = atoi(freq);
1301 #endif /* CONFIG_P2P */
1304 pos = os_strchr(role, ' ');
1306 wpa_printf(MSG_DEBUG, "NFC: Missing type in handover report");
1312 pos = os_strchr(type, ' ');
1314 wpa_printf(MSG_DEBUG, "NFC: Missing request message in handover report");
1319 pos2 = os_strchr(pos, ' ');
1321 wpa_printf(MSG_DEBUG, "NFC: Missing select message in handover report");
1326 len = os_strlen(pos);
1328 wpa_printf(MSG_DEBUG, "NFC: Invalid request message length in handover report");
1333 req = wpabuf_alloc(len);
1335 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for request message");
1338 if (hexstr2bin(pos, wpabuf_put(req, len), len) < 0) {
1339 wpa_printf(MSG_DEBUG, "NFC: Invalid request message hexdump in handover report");
1344 len = os_strlen(pos2);
1346 wpa_printf(MSG_DEBUG, "NFC: Invalid select message length in handover report");
1352 sel = wpabuf_alloc(len);
1354 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for select message");
1358 if (hexstr2bin(pos2, wpabuf_put(sel, len), len) < 0) {
1359 wpa_printf(MSG_DEBUG, "NFC: Invalid select message hexdump in handover report");
1365 wpa_printf(MSG_DEBUG, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d",
1366 role, type, (int) wpabuf_len(req), (int) wpabuf_len(sel));
1368 if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "WPS") == 0) {
1369 ret = wpas_wps_nfc_report_handover(wpa_s, req, sel);
1371 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "WPS") == 0)
1373 ret = wpas_ap_wps_nfc_report_handover(wpa_s, req, sel);
1375 ret = wpas_er_wps_nfc_report_handover(wpa_s, req, sel);
1376 #endif /* CONFIG_AP */
1378 } else if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "P2P") == 0)
1380 ret = wpas_p2p_nfc_report_handover(wpa_s, 1, req, sel, 0);
1381 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "P2P") == 0)
1383 ret = wpas_p2p_nfc_report_handover(wpa_s, 0, req, sel,
1385 #endif /* CONFIG_P2P */
1387 wpa_printf(MSG_DEBUG, "NFC: Unsupported connection handover "
1388 "reported: role=%s type=%s", role, type);
1395 wpa_printf(MSG_DEBUG, "NFC: Failed to process reported handover messages");
1400 #endif /* CONFIG_WPS_NFC */
1403 static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s,
1412 struct wps_new_ap_settings ap;
1414 pin = os_strchr(cmd, ' ');
1419 if (hwaddr_aton(cmd, bssid)) {
1420 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
1425 new_ssid = os_strchr(pin, ' ');
1426 if (new_ssid == NULL)
1427 return wpas_wps_start_reg(wpa_s, bssid, pin, NULL);
1430 new_auth = os_strchr(new_ssid, ' ');
1431 if (new_auth == NULL)
1435 new_encr = os_strchr(new_auth, ' ');
1436 if (new_encr == NULL)
1440 new_key = os_strchr(new_encr, ' ');
1441 if (new_key == NULL)
1445 os_memset(&ap, 0, sizeof(ap));
1446 ap.ssid_hex = new_ssid;
1449 ap.key_hex = new_key;
1450 return wpas_wps_start_reg(wpa_s, bssid, pin, &ap);
1455 static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant *wpa_s,
1456 char *cmd, char *buf,
1461 const char *pin_txt;
1463 if (!wpa_s->ap_iface)
1466 pos = os_strchr(cmd, ' ');
1470 if (os_strcmp(cmd, "disable") == 0) {
1471 wpas_wps_ap_pin_disable(wpa_s);
1472 return os_snprintf(buf, buflen, "OK\n");
1475 if (os_strcmp(cmd, "random") == 0) {
1477 timeout = atoi(pos);
1478 pin_txt = wpas_wps_ap_pin_random(wpa_s, timeout);
1479 if (pin_txt == NULL)
1481 return os_snprintf(buf, buflen, "%s", pin_txt);
1484 if (os_strcmp(cmd, "get") == 0) {
1485 pin_txt = wpas_wps_ap_pin_get(wpa_s);
1486 if (pin_txt == NULL)
1488 return os_snprintf(buf, buflen, "%s", pin_txt);
1491 if (os_strcmp(cmd, "set") == 0) {
1496 pos = os_strchr(pos, ' ');
1499 timeout = atoi(pos);
1501 if (os_strlen(pin) > buflen)
1503 if (wpas_wps_ap_pin_set(wpa_s, pin, timeout) < 0)
1505 return os_snprintf(buf, buflen, "%s", pin);
1510 #endif /* CONFIG_AP */
1513 #ifdef CONFIG_WPS_ER
1514 static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant *wpa_s,
1517 char *uuid = cmd, *pin, *pos;
1518 u8 addr_buf[ETH_ALEN], *addr = NULL;
1519 pin = os_strchr(uuid, ' ');
1523 pos = os_strchr(pin, ' ');
1526 if (hwaddr_aton(pos, addr_buf) == 0)
1529 return wpas_wps_er_add_pin(wpa_s, addr, uuid, pin);
1533 static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant *wpa_s,
1536 char *uuid = cmd, *pin;
1537 pin = os_strchr(uuid, ' ');
1541 return wpas_wps_er_learn(wpa_s, uuid, pin);
1545 static int wpa_supplicant_ctrl_iface_wps_er_set_config(
1546 struct wpa_supplicant *wpa_s, char *cmd)
1548 char *uuid = cmd, *id;
1549 id = os_strchr(uuid, ' ');
1553 return wpas_wps_er_set_config(wpa_s, uuid, atoi(id));
1557 static int wpa_supplicant_ctrl_iface_wps_er_config(
1558 struct wpa_supplicant *wpa_s, char *cmd)
1565 struct wps_new_ap_settings ap;
1567 pin = os_strchr(cmd, ' ');
1572 new_ssid = os_strchr(pin, ' ');
1573 if (new_ssid == NULL)
1577 new_auth = os_strchr(new_ssid, ' ');
1578 if (new_auth == NULL)
1582 new_encr = os_strchr(new_auth, ' ');
1583 if (new_encr == NULL)
1587 new_key = os_strchr(new_encr, ' ');
1588 if (new_key == NULL)
1592 os_memset(&ap, 0, sizeof(ap));
1593 ap.ssid_hex = new_ssid;
1596 ap.key_hex = new_key;
1597 return wpas_wps_er_config(wpa_s, cmd, pin, &ap);
1601 #ifdef CONFIG_WPS_NFC
1602 static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
1603 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1610 uuid = os_strchr(cmd, ' ');
1615 if (os_strcmp(cmd, "WPS") == 0)
1617 else if (os_strcmp(cmd, "NDEF") == 0)
1622 buf = wpas_wps_er_nfc_config_token(wpa_s, ndef, uuid);
1626 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1628 reply[res++] = '\n';
1635 #endif /* CONFIG_WPS_NFC */
1636 #endif /* CONFIG_WPS_ER */
1638 #endif /* CONFIG_WPS */
1641 #ifdef CONFIG_IBSS_RSN
1642 static int wpa_supplicant_ctrl_iface_ibss_rsn(
1643 struct wpa_supplicant *wpa_s, char *addr)
1647 if (hwaddr_aton(addr, peer)) {
1648 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN: invalid "
1649 "address '%s'", addr);
1653 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN " MACSTR,
1656 return ibss_rsn_start(wpa_s->ibss_rsn, peer);
1658 #endif /* CONFIG_IBSS_RSN */
1661 static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s,
1664 #ifdef IEEE8021X_EAPOL
1667 struct wpa_ssid *ssid;
1669 pos = os_strchr(rsp, '-');
1674 pos = os_strchr(pos, ':');
1679 wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id);
1680 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
1681 (u8 *) pos, os_strlen(pos));
1683 ssid = wpa_config_get_network(wpa_s->conf, id);
1685 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
1690 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s, ssid, rsp,
1692 #else /* IEEE8021X_EAPOL */
1693 wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included");
1695 #endif /* IEEE8021X_EAPOL */
1699 static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
1701 char *buf, size_t buflen)
1703 char *pos, *end, tmp[30];
1704 int res, verbose, wps, ret;
1707 #endif /* CONFIG_HS20 */
1711 if (os_strcmp(params, "-DRIVER") == 0)
1712 return wpa_drv_status(wpa_s, buf, buflen);
1713 verbose = os_strcmp(params, "-VERBOSE") == 0;
1714 wps = os_strcmp(params, "-WPS") == 0;
1717 if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
1718 struct wpa_ssid *ssid = wpa_s->current_ssid;
1719 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
1720 MAC2STR(wpa_s->bssid));
1721 if (os_snprintf_error(end - pos, ret))
1724 ret = os_snprintf(pos, end - pos, "freq=%u\n",
1726 if (os_snprintf_error(end - pos, ret))
1730 u8 *_ssid = ssid->ssid;
1731 size_t ssid_len = ssid->ssid_len;
1732 u8 ssid_buf[SSID_MAX_LEN];
1733 if (ssid_len == 0) {
1734 int _res = wpa_drv_get_ssid(wpa_s, ssid_buf);
1741 ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n",
1742 wpa_ssid_txt(_ssid, ssid_len),
1744 if (os_snprintf_error(end - pos, ret))
1748 if (wps && ssid->passphrase &&
1749 wpa_key_mgmt_wpa_psk(ssid->key_mgmt) &&
1750 (ssid->mode == WPAS_MODE_AP ||
1751 ssid->mode == WPAS_MODE_P2P_GO)) {
1752 ret = os_snprintf(pos, end - pos,
1755 if (os_snprintf_error(end - pos, ret))
1760 ret = os_snprintf(pos, end - pos,
1763 if (os_snprintf_error(end - pos, ret))
1768 switch (ssid->mode) {
1769 case WPAS_MODE_INFRA:
1770 ret = os_snprintf(pos, end - pos,
1773 case WPAS_MODE_IBSS:
1774 ret = os_snprintf(pos, end - pos,
1778 ret = os_snprintf(pos, end - pos,
1781 case WPAS_MODE_P2P_GO:
1782 ret = os_snprintf(pos, end - pos,
1785 case WPAS_MODE_P2P_GROUP_FORMATION:
1786 ret = os_snprintf(pos, end - pos,
1787 "mode=P2P GO - group "
1794 if (os_snprintf_error(end - pos, ret))
1800 if (wpa_s->ap_iface) {
1801 pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos,
1805 #endif /* CONFIG_AP */
1806 pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose);
1809 if (wpa_s->wpa_state >= WPA_ASSOCIATED &&
1812 #endif /* CONFIG_AP */
1813 wpa_s->sme.sae.state == SAE_ACCEPTED) {
1814 ret = os_snprintf(pos, end - pos, "sae_group=%d\n",
1815 wpa_s->sme.sae.group);
1816 if (os_snprintf_error(end - pos, ret))
1820 #endif /* CONFIG_SAE */
1821 ret = os_snprintf(pos, end - pos, "wpa_state=%s\n",
1822 wpa_supplicant_state_txt(wpa_s->wpa_state));
1823 if (os_snprintf_error(end - pos, ret))
1828 l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) {
1829 ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp);
1830 if (os_snprintf_error(end - pos, ret))
1836 if (wpa_s->global->p2p) {
1837 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
1838 "\n", MAC2STR(wpa_s->global->p2p_dev_addr));
1839 if (os_snprintf_error(end - pos, ret))
1843 #endif /* CONFIG_P2P */
1845 ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n",
1846 MAC2STR(wpa_s->own_addr));
1847 if (os_snprintf_error(end - pos, ret))
1852 if (wpa_s->current_bss &&
1853 (hs20 = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1854 HS20_IE_VENDOR_TYPE)) &&
1855 wpa_s->wpa_proto == WPA_PROTO_RSN &&
1856 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1859 u8 rel_num = (hs20[6] & 0xf0) >> 4;
1860 release = rel_num + 1;
1862 ret = os_snprintf(pos, end - pos, "hs20=%d\n", release);
1863 if (os_snprintf_error(end - pos, ret))
1868 if (wpa_s->current_ssid) {
1869 struct wpa_cred *cred;
1872 for (cred = wpa_s->conf->cred; cred; cred = cred->next) {
1875 if (wpa_s->current_ssid->parent_cred != cred)
1878 if (cred->provisioning_sp) {
1879 ret = os_snprintf(pos, end - pos,
1880 "provisioning_sp=%s\n",
1881 cred->provisioning_sp);
1882 if (os_snprintf_error(end - pos, ret))
1891 if (wpa_s->current_bss && wpa_s->current_bss->anqp) {
1892 struct wpabuf *names =
1893 wpa_s->current_bss->anqp->domain_name;
1894 for (i = 0; names && i < cred->num_domain; i++)
1896 if (domain_name_list_contains(
1897 names, cred->domain[i], 1))
1900 if (i == cred->num_domain)
1901 i = 0; /* show first entry by default */
1903 ret = os_snprintf(pos, end - pos, "home_sp=%s\n",
1905 if (os_snprintf_error(end - pos, ret))
1910 if (wpa_s->current_bss == NULL ||
1911 wpa_s->current_bss->anqp == NULL)
1914 res = interworking_home_sp_cred(
1916 wpa_s->current_bss->anqp->domain_name);
1924 ret = os_snprintf(pos, end - pos, "sp_type=%s\n", type);
1925 if (os_snprintf_error(end - pos, ret))
1932 #endif /* CONFIG_HS20 */
1934 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
1935 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
1936 res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos,
1942 sess_id = eapol_sm_get_session_id(wpa_s->eapol, &sess_id_len);
1946 ret = os_snprintf(pos, end - pos, "eap_session_id=");
1947 if (os_snprintf_error(end - pos, ret))
1950 ret = wpa_snprintf_hex(pos, end - pos, sess_id, sess_id_len);
1954 ret = os_snprintf(pos, end - pos, "\n");
1955 if (os_snprintf_error(end - pos, ret))
1960 res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose);
1967 uuid_bin2str(wpa_s->wps->uuid, uuid_str, sizeof(uuid_str));
1968 ret = os_snprintf(pos, end - pos, "uuid=%s\n", uuid_str);
1969 if (os_snprintf_error(end - pos, ret))
1973 #endif /* CONFIG_WPS */
1977 * Allow using the STATUS command with default behavior, say for debug,
1978 * i.e., don't generate a "fake" CONNECTION and SUPPLICANT_STATE_CHANGE
1979 * events with STATUS-NO_EVENTS.
1981 if (os_strcmp(params, "-NO_EVENTS")) {
1982 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_STATE_CHANGE
1983 "id=%d state=%d BSSID=" MACSTR " SSID=%s",
1984 wpa_s->current_ssid ? wpa_s->current_ssid->id : -1,
1986 MAC2STR(wpa_s->bssid),
1987 wpa_s->current_ssid && wpa_s->current_ssid->ssid ?
1988 wpa_ssid_txt(wpa_s->current_ssid->ssid,
1989 wpa_s->current_ssid->ssid_len) : "");
1990 if (wpa_s->wpa_state == WPA_COMPLETED) {
1991 struct wpa_ssid *ssid = wpa_s->current_ssid;
1992 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_CONNECTED
1993 "- connection to " MACSTR
1994 " completed %s [id=%d id_str=%s]",
1995 MAC2STR(wpa_s->bssid), "(auth)",
1996 ssid ? ssid->id : -1,
1997 ssid && ssid->id_str ? ssid->id_str : "");
2000 #endif /* ANDROID */
2006 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s,
2011 struct wpa_ssid *ssid;
2014 /* cmd: "<network id> <BSSID>" */
2015 pos = os_strchr(cmd, ' ');
2020 wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos);
2021 if (hwaddr_aton(pos, bssid)) {
2022 wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos);
2026 ssid = wpa_config_get_network(wpa_s->conf, id);
2028 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
2033 os_memcpy(ssid->bssid, bssid, ETH_ALEN);
2034 ssid->bssid_set = !is_zero_ether_addr(bssid);
2040 static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant *wpa_s,
2041 char *cmd, char *buf,
2045 struct wpa_blacklist *e;
2049 /* cmd: "BLACKLIST [<BSSID>]" */
2053 e = wpa_s->blacklist;
2055 ret = os_snprintf(pos, end - pos, MACSTR "\n",
2057 if (os_snprintf_error(end - pos, ret))
2066 if (os_strncmp(cmd, "clear", 5) == 0) {
2067 wpa_blacklist_clear(wpa_s);
2068 os_memcpy(buf, "OK\n", 3);
2072 wpa_printf(MSG_DEBUG, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd);
2073 if (hwaddr_aton(cmd, bssid)) {
2074 wpa_printf(MSG_DEBUG, "CTRL_IFACE: invalid BSSID '%s'", cmd);
2079 * Add the BSSID twice, so its count will be 2, causing it to be
2080 * skipped when processing scan results.
2082 ret = wpa_blacklist_add(wpa_s, bssid);
2085 ret = wpa_blacklist_add(wpa_s, bssid);
2088 os_memcpy(buf, "OK\n", 3);
2093 static const char * debug_level_str(int level)
2114 static int str_to_debug_level(const char *s)
2116 if (os_strcasecmp(s, "EXCESSIVE") == 0)
2117 return MSG_EXCESSIVE;
2118 if (os_strcasecmp(s, "MSGDUMP") == 0)
2120 if (os_strcasecmp(s, "DEBUG") == 0)
2122 if (os_strcasecmp(s, "INFO") == 0)
2124 if (os_strcasecmp(s, "WARNING") == 0)
2126 if (os_strcasecmp(s, "ERROR") == 0)
2132 static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant *wpa_s,
2133 char *cmd, char *buf,
2136 char *pos, *end, *stamp;
2139 /* cmd: "LOG_LEVEL [<level>]" */
2143 ret = os_snprintf(pos, end - pos, "Current level: %s\n"
2145 debug_level_str(wpa_debug_level),
2146 wpa_debug_timestamp);
2147 if (os_snprintf_error(end - pos, ret))
2156 stamp = os_strchr(cmd, ' ');
2159 while (*stamp == ' ') {
2164 if (cmd && os_strlen(cmd)) {
2165 int level = str_to_debug_level(cmd);
2168 wpa_debug_level = level;
2171 if (stamp && os_strlen(stamp))
2172 wpa_debug_timestamp = atoi(stamp);
2174 os_memcpy(buf, "OK\n", 3);
2179 static int wpa_supplicant_ctrl_iface_list_networks(
2180 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
2182 char *pos, *end, *prev;
2183 struct wpa_ssid *ssid;
2188 ret = os_snprintf(pos, end - pos,
2189 "network id / ssid / bssid / flags\n");
2190 if (os_snprintf_error(end - pos, ret))
2194 ssid = wpa_s->conf->ssid;
2196 /* skip over ssids until we find next one */
2197 if (cmd != NULL && os_strncmp(cmd, "LAST_ID=", 8) == 0) {
2198 int last_id = atoi(cmd + 8);
2199 if (last_id != -1) {
2200 while (ssid != NULL && ssid->id <= last_id) {
2208 ret = os_snprintf(pos, end - pos, "%d\t%s",
2210 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
2211 if (os_snprintf_error(end - pos, ret))
2214 if (ssid->bssid_set) {
2215 ret = os_snprintf(pos, end - pos, "\t" MACSTR,
2216 MAC2STR(ssid->bssid));
2218 ret = os_snprintf(pos, end - pos, "\tany");
2220 if (os_snprintf_error(end - pos, ret))
2223 ret = os_snprintf(pos, end - pos, "\t%s%s%s%s",
2224 ssid == wpa_s->current_ssid ?
2226 ssid->disabled ? "[DISABLED]" : "",
2227 ssid->disabled_until.sec ?
2228 "[TEMP-DISABLED]" : "",
2229 ssid->disabled == 2 ? "[P2P-PERSISTENT]" :
2231 if (os_snprintf_error(end - pos, ret))
2234 ret = os_snprintf(pos, end - pos, "\n");
2235 if (os_snprintf_error(end - pos, ret))
2246 static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher)
2249 ret = os_snprintf(pos, end - pos, "-");
2250 if (os_snprintf_error(end - pos, ret))
2253 ret = wpa_write_ciphers(pos, end, cipher, "+");
2261 static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
2262 const u8 *ie, size_t ie_len)
2264 struct wpa_ie_data data;
2268 ret = os_snprintf(pos, end - pos, "[%s-", proto);
2269 if (os_snprintf_error(end - pos, ret))
2273 if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) {
2274 ret = os_snprintf(pos, end - pos, "?]");
2275 if (os_snprintf_error(end - pos, ret))
2282 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
2283 ret = os_snprintf(pos, end - pos, "%sEAP",
2284 pos == start ? "" : "+");
2285 if (os_snprintf_error(end - pos, ret))
2289 if (data.key_mgmt & WPA_KEY_MGMT_PSK) {
2290 ret = os_snprintf(pos, end - pos, "%sPSK",
2291 pos == start ? "" : "+");
2292 if (os_snprintf_error(end - pos, ret))
2296 if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
2297 ret = os_snprintf(pos, end - pos, "%sNone",
2298 pos == start ? "" : "+");
2299 if (os_snprintf_error(end - pos, ret))
2303 if (data.key_mgmt & WPA_KEY_MGMT_SAE) {
2304 ret = os_snprintf(pos, end - pos, "%sSAE",
2305 pos == start ? "" : "+");
2306 if (os_snprintf_error(end - pos, ret))
2310 #ifdef CONFIG_IEEE80211R
2311 if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
2312 ret = os_snprintf(pos, end - pos, "%sFT/EAP",
2313 pos == start ? "" : "+");
2314 if (os_snprintf_error(end - pos, ret))
2318 if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) {
2319 ret = os_snprintf(pos, end - pos, "%sFT/PSK",
2320 pos == start ? "" : "+");
2321 if (os_snprintf_error(end - pos, ret))
2325 if (data.key_mgmt & WPA_KEY_MGMT_FT_SAE) {
2326 ret = os_snprintf(pos, end - pos, "%sFT/SAE",
2327 pos == start ? "" : "+");
2328 if (os_snprintf_error(end - pos, ret))
2332 #endif /* CONFIG_IEEE80211R */
2333 #ifdef CONFIG_IEEE80211W
2334 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
2335 ret = os_snprintf(pos, end - pos, "%sEAP-SHA256",
2336 pos == start ? "" : "+");
2337 if (os_snprintf_error(end - pos, ret))
2341 if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
2342 ret = os_snprintf(pos, end - pos, "%sPSK-SHA256",
2343 pos == start ? "" : "+");
2344 if (os_snprintf_error(end - pos, ret))
2348 #endif /* CONFIG_IEEE80211W */
2350 #ifdef CONFIG_SUITEB
2351 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B) {
2352 ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B",
2353 pos == start ? "" : "+");
2354 if (os_snprintf_error(end - pos, ret))
2358 #endif /* CONFIG_SUITEB */
2360 #ifdef CONFIG_SUITEB192
2361 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) {
2362 ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B-192",
2363 pos == start ? "" : "+");
2364 if (os_snprintf_error(end - pos, ret))
2368 #endif /* CONFIG_SUITEB192 */
2370 if (data.key_mgmt & WPA_KEY_MGMT_OSEN) {
2371 ret = os_snprintf(pos, end - pos, "%sOSEN",
2372 pos == start ? "" : "+");
2373 if (os_snprintf_error(end - pos, ret))
2378 pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher);
2380 if (data.capabilities & WPA_CAPABILITY_PREAUTH) {
2381 ret = os_snprintf(pos, end - pos, "-preauth");
2382 if (os_snprintf_error(end - pos, ret))
2387 ret = os_snprintf(pos, end - pos, "]");
2388 if (os_snprintf_error(end - pos, ret))
2397 static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s,
2398 char *pos, char *end,
2399 struct wpabuf *wps_ie)
2406 if (wps_is_selected_pbc_registrar(wps_ie))
2408 else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0))
2410 else if (wps_is_selected_pin_registrar(wps_ie))
2415 ret = os_snprintf(pos, end - pos, "%s", txt);
2416 if (!os_snprintf_error(end - pos, ret))
2418 wpabuf_free(wps_ie);
2421 #endif /* CONFIG_WPS */
2424 static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s,
2425 char *pos, char *end,
2426 const struct wpa_bss *bss)
2429 struct wpabuf *wps_ie;
2430 wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
2431 return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie);
2432 #else /* CONFIG_WPS */
2434 #endif /* CONFIG_WPS */
2438 /* Format one result on one text line into a buffer. */
2439 static int wpa_supplicant_ctrl_iface_scan_result(
2440 struct wpa_supplicant *wpa_s,
2441 const struct wpa_bss *bss, char *buf, size_t buflen)
2445 const u8 *ie, *ie2, *osen_ie, *p2p, *mesh;
2447 mesh = wpa_bss_get_ie(bss, WLAN_EID_MESH_ID);
2448 p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
2450 p2p = wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE);
2451 if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN &&
2452 os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) ==
2454 return 0; /* Do not show P2P listen discovery results here */
2459 ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t",
2460 MAC2STR(bss->bssid), bss->freq, bss->level);
2461 if (os_snprintf_error(end - pos, ret))
2464 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
2466 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]);
2467 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
2469 pos = wpa_supplicant_ie_txt(pos, end, mesh ? "RSN" : "WPA2",
2472 osen_ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
2474 pos = wpa_supplicant_ie_txt(pos, end, "OSEN",
2475 osen_ie, 2 + osen_ie[1]);
2476 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
2477 if (!ie && !ie2 && !osen_ie && (bss->caps & IEEE80211_CAP_PRIVACY)) {
2478 ret = os_snprintf(pos, end - pos, "[WEP]");
2479 if (os_snprintf_error(end - pos, ret))
2484 ret = os_snprintf(pos, end - pos, "[MESH]");
2485 if (os_snprintf_error(end - pos, ret))
2489 if (bss_is_dmg(bss)) {
2491 ret = os_snprintf(pos, end - pos, "[DMG]");
2492 if (os_snprintf_error(end - pos, ret))
2495 switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
2496 case IEEE80211_CAP_DMG_IBSS:
2499 case IEEE80211_CAP_DMG_AP:
2502 case IEEE80211_CAP_DMG_PBSS:
2509 ret = os_snprintf(pos, end - pos, "%s", s);
2510 if (os_snprintf_error(end - pos, ret))
2514 if (bss->caps & IEEE80211_CAP_IBSS) {
2515 ret = os_snprintf(pos, end - pos, "[IBSS]");
2516 if (os_snprintf_error(end - pos, ret))
2520 if (bss->caps & IEEE80211_CAP_ESS) {
2521 ret = os_snprintf(pos, end - pos, "[ESS]");
2522 if (os_snprintf_error(end - pos, ret))
2528 ret = os_snprintf(pos, end - pos, "[P2P]");
2529 if (os_snprintf_error(end - pos, ret))
2534 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE) && ie2) {
2535 ret = os_snprintf(pos, end - pos, "[HS20]");
2536 if (os_snprintf_error(end - pos, ret))
2540 #endif /* CONFIG_HS20 */
2542 ret = os_snprintf(pos, end - pos, "\t%s",
2543 wpa_ssid_txt(bss->ssid, bss->ssid_len));
2544 if (os_snprintf_error(end - pos, ret))
2548 ret = os_snprintf(pos, end - pos, "\n");
2549 if (os_snprintf_error(end - pos, ret))
2557 static int wpa_supplicant_ctrl_iface_scan_results(
2558 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
2561 struct wpa_bss *bss;
2566 ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / "
2568 if (os_snprintf_error(end - pos, ret))
2572 dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
2573 ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos,
2575 if (ret < 0 || ret >= end - pos)
2586 static int wpa_supplicant_ctrl_iface_mesh_interface_add(
2587 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
2589 char *pos, ifname[IFNAMSIZ + 1];
2593 pos = os_strstr(cmd, "ifname=");
2596 os_strlcpy(ifname, pos, sizeof(ifname));
2599 if (wpas_mesh_add_interface(wpa_s, ifname, sizeof(ifname)) < 0)
2602 os_strlcpy(reply, ifname, max_len);
2603 return os_strlen(ifname);
2607 static int wpa_supplicant_ctrl_iface_mesh_group_add(
2608 struct wpa_supplicant *wpa_s, char *cmd)
2611 struct wpa_ssid *ssid;
2614 wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_ADD id=%d", id);
2616 ssid = wpa_config_get_network(wpa_s->conf, id);
2618 wpa_printf(MSG_DEBUG,
2619 "CTRL_IFACE: Could not find network id=%d", id);
2622 if (ssid->mode != WPAS_MODE_MESH) {
2623 wpa_printf(MSG_DEBUG,
2624 "CTRL_IFACE: Cannot use MESH_GROUP_ADD on a non mesh network");
2627 if (ssid->key_mgmt != WPA_KEY_MGMT_NONE &&
2628 ssid->key_mgmt != WPA_KEY_MGMT_SAE) {
2629 wpa_printf(MSG_ERROR,
2630 "CTRL_IFACE: key_mgmt for mesh network should be open or SAE");
2635 * TODO: If necessary write our own group_add function,
2636 * for now we can reuse select_network
2638 wpa_supplicant_select_network(wpa_s, ssid);
2644 static int wpa_supplicant_ctrl_iface_mesh_group_remove(
2645 struct wpa_supplicant *wpa_s, char *cmd)
2647 struct wpa_supplicant *orig;
2648 struct wpa_global *global;
2651 wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s", cmd);
2653 global = wpa_s->global;
2656 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
2657 if (os_strcmp(wpa_s->ifname, cmd) == 0) {
2663 wpa_printf(MSG_ERROR,
2664 "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s not found",
2668 if (wpa_s->mesh_if_created && wpa_s == orig) {
2669 wpa_printf(MSG_ERROR,
2670 "CTRL_IFACE: MESH_GROUP_REMOVE can't remove itself");
2674 wpa_s->reassociate = 0;
2675 wpa_s->disconnected = 1;
2676 wpa_supplicant_cancel_sched_scan(wpa_s);
2677 wpa_supplicant_cancel_scan(wpa_s);
2680 * TODO: If necessary write our own group_remove function,
2681 * for now we can reuse deauthenticate
2683 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2685 if (wpa_s->mesh_if_created)
2686 wpa_supplicant_remove_iface(global, wpa_s, 0);
2691 #endif /* CONFIG_MESH */
2694 static int wpa_supplicant_ctrl_iface_select_network(
2695 struct wpa_supplicant *wpa_s, char *cmd)
2698 struct wpa_ssid *ssid;
2701 /* cmd: "<network id>" or "any" */
2702 if (os_strncmp(cmd, "any", 3) == 0) {
2703 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any");
2707 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id);
2709 ssid = wpa_config_get_network(wpa_s->conf, id);
2711 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2712 "network id=%d", id);
2715 if (ssid->disabled == 2) {
2716 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2717 "SELECT_NETWORK with persistent P2P group");
2722 pos = os_strstr(cmd, " freq=");
2724 int *freqs = freq_range_to_channel_list(wpa_s, pos + 6);
2726 wpa_s->scan_req = MANUAL_SCAN_REQ;
2727 os_free(wpa_s->manual_scan_freqs);
2728 wpa_s->manual_scan_freqs = freqs;
2732 wpa_supplicant_select_network(wpa_s, ssid);
2738 static int wpa_supplicant_ctrl_iface_enable_network(
2739 struct wpa_supplicant *wpa_s, char *cmd)
2742 struct wpa_ssid *ssid;
2744 /* cmd: "<network id>" or "all" */
2745 if (os_strcmp(cmd, "all") == 0) {
2746 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all");
2750 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id);
2752 ssid = wpa_config_get_network(wpa_s->conf, id);
2754 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2755 "network id=%d", id);
2758 if (ssid->disabled == 2) {
2759 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2760 "ENABLE_NETWORK with persistent P2P group");
2764 if (os_strstr(cmd, " no-connect")) {
2769 wpa_supplicant_enable_network(wpa_s, ssid);
2775 static int wpa_supplicant_ctrl_iface_disable_network(
2776 struct wpa_supplicant *wpa_s, char *cmd)
2779 struct wpa_ssid *ssid;
2781 /* cmd: "<network id>" or "all" */
2782 if (os_strcmp(cmd, "all") == 0) {
2783 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all");
2787 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id);
2789 ssid = wpa_config_get_network(wpa_s->conf, id);
2791 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2792 "network id=%d", id);
2795 if (ssid->disabled == 2) {
2796 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2797 "DISABLE_NETWORK with persistent P2P "
2802 wpa_supplicant_disable_network(wpa_s, ssid);
2808 static int wpa_supplicant_ctrl_iface_add_network(
2809 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
2811 struct wpa_ssid *ssid;
2814 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK");
2816 ssid = wpa_config_add_network(wpa_s->conf);
2820 wpas_notify_network_added(wpa_s, ssid);
2823 wpa_config_set_network_defaults(ssid);
2825 ret = os_snprintf(buf, buflen, "%d\n", ssid->id);
2826 if (os_snprintf_error(buflen, ret))
2832 static int wpa_supplicant_ctrl_iface_remove_network(
2833 struct wpa_supplicant *wpa_s, char *cmd)
2836 struct wpa_ssid *ssid;
2839 /* cmd: "<network id>" or "all" */
2840 if (os_strcmp(cmd, "all") == 0) {
2841 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all");
2842 if (wpa_s->sched_scanning)
2843 wpa_supplicant_cancel_sched_scan(wpa_s);
2845 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2846 if (wpa_s->current_ssid) {
2848 wpa_s->sme.prev_bssid_set = 0;
2849 #endif /* CONFIG_SME */
2850 wpa_sm_set_config(wpa_s->wpa, NULL);
2851 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
2852 wpa_s->own_disconnect_req = 1;
2853 wpa_supplicant_deauthenticate(
2854 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2856 ssid = wpa_s->conf->ssid;
2858 struct wpa_ssid *remove_ssid = ssid;
2861 if (wpa_s->last_ssid == remove_ssid)
2862 wpa_s->last_ssid = NULL;
2863 wpas_notify_network_removed(wpa_s, remove_ssid);
2864 wpa_config_remove_network(wpa_s->conf, id);
2870 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id);
2872 ssid = wpa_config_get_network(wpa_s->conf, id);
2874 wpas_notify_network_removed(wpa_s, ssid);
2876 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2881 if (wpa_s->last_ssid == ssid)
2882 wpa_s->last_ssid = NULL;
2884 if (ssid == wpa_s->current_ssid || wpa_s->current_ssid == NULL) {
2886 wpa_s->sme.prev_bssid_set = 0;
2887 #endif /* CONFIG_SME */
2889 * Invalidate the EAP session cache if the current or
2890 * previously used network is removed.
2892 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2895 if (ssid == wpa_s->current_ssid) {
2896 wpa_sm_set_config(wpa_s->wpa, NULL);
2897 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
2899 wpa_s->own_disconnect_req = 1;
2900 wpa_supplicant_deauthenticate(wpa_s,
2901 WLAN_REASON_DEAUTH_LEAVING);
2904 was_disabled = ssid->disabled;
2906 if (wpa_config_remove_network(wpa_s->conf, id) < 0) {
2907 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Not able to remove the "
2908 "network id=%d", id);
2912 if (!was_disabled && wpa_s->sched_scanning) {
2913 wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to remove "
2914 "network from filters");
2915 wpa_supplicant_cancel_sched_scan(wpa_s);
2916 wpa_supplicant_req_scan(wpa_s, 0, 0);
2923 static int wpa_supplicant_ctrl_iface_update_network(
2924 struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
2925 char *name, char *value)
2927 if (wpa_config_set(ssid, name, value, 0) < 0) {
2928 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network "
2929 "variable '%s'", name);
2933 if (os_strcmp(name, "bssid") != 0 &&
2934 os_strcmp(name, "priority") != 0)
2935 wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
2937 if (wpa_s->current_ssid == ssid || wpa_s->current_ssid == NULL) {
2939 * Invalidate the EAP session cache if anything in the current
2940 * or previously used configuration changes.
2942 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2945 if ((os_strcmp(name, "psk") == 0 &&
2946 value[0] == '"' && ssid->ssid_len) ||
2947 (os_strcmp(name, "ssid") == 0 && ssid->passphrase))
2948 wpa_config_update_psk(ssid);
2949 else if (os_strcmp(name, "priority") == 0)
2950 wpa_config_update_prio_list(wpa_s->conf);
2956 static int wpa_supplicant_ctrl_iface_set_network(
2957 struct wpa_supplicant *wpa_s, char *cmd)
2959 int id, ret, prev_bssid_set, prev_disabled;
2960 struct wpa_ssid *ssid;
2962 u8 prev_bssid[ETH_ALEN];
2964 /* cmd: "<network id> <variable name> <value>" */
2965 name = os_strchr(cmd, ' ');
2970 value = os_strchr(name, ' ');
2976 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
2978 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
2979 (u8 *) value, os_strlen(value));
2981 ssid = wpa_config_get_network(wpa_s->conf, id);
2983 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2988 prev_bssid_set = ssid->bssid_set;
2989 prev_disabled = ssid->disabled;
2990 os_memcpy(prev_bssid, ssid->bssid, ETH_ALEN);
2991 ret = wpa_supplicant_ctrl_iface_update_network(wpa_s, ssid, name,
2994 (ssid->bssid_set != prev_bssid_set ||
2995 os_memcmp(ssid->bssid, prev_bssid, ETH_ALEN) != 0))
2996 wpas_notify_network_bssid_set_changed(wpa_s, ssid);
2998 if (prev_disabled != ssid->disabled &&
2999 (prev_disabled == 2 || ssid->disabled == 2))
3000 wpas_notify_network_type_changed(wpa_s, ssid);
3006 static int wpa_supplicant_ctrl_iface_get_network(
3007 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
3011 struct wpa_ssid *ssid;
3014 /* cmd: "<network id> <variable name>" */
3015 name = os_strchr(cmd, ' ');
3016 if (name == NULL || buflen == 0)
3021 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
3024 ssid = wpa_config_get_network(wpa_s->conf, id);
3026 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
3031 value = wpa_config_get_no_key(ssid, name);
3032 if (value == NULL) {
3033 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
3034 "variable '%s'", name);
3038 res = os_strlcpy(buf, value, buflen);
3039 if (res >= buflen) {
3050 static int wpa_supplicant_ctrl_iface_dup_network(
3051 struct wpa_supplicant *wpa_s, char *cmd)
3053 struct wpa_ssid *ssid_s, *ssid_d;
3054 char *name, *id, *value;
3055 int id_s, id_d, ret;
3057 /* cmd: "<src network id> <dst network id> <variable name>" */
3058 id = os_strchr(cmd, ' ');
3063 name = os_strchr(id, ' ');
3070 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DUP_NETWORK id=%d -> %d name='%s'",
3073 ssid_s = wpa_config_get_network(wpa_s->conf, id_s);
3074 if (ssid_s == NULL) {
3075 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3076 "network id=%d", id_s);
3080 ssid_d = wpa_config_get_network(wpa_s->conf, id_d);
3081 if (ssid_d == NULL) {
3082 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3083 "network id=%d", id_d);
3087 value = wpa_config_get(ssid_s, name);
3088 if (value == NULL) {
3089 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
3090 "variable '%s'", name);
3094 ret = wpa_supplicant_ctrl_iface_update_network(wpa_s, ssid_d, name,
3103 static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant *wpa_s,
3104 char *buf, size_t buflen)
3107 struct wpa_cred *cred;
3112 ret = os_snprintf(pos, end - pos,
3113 "cred id / realm / username / domain / imsi\n");
3114 if (os_snprintf_error(end - pos, ret))
3118 cred = wpa_s->conf->cred;
3120 ret = os_snprintf(pos, end - pos, "%d\t%s\t%s\t%s\t%s\n",
3121 cred->id, cred->realm ? cred->realm : "",
3122 cred->username ? cred->username : "",
3123 cred->domain ? cred->domain[0] : "",
3124 cred->imsi ? cred->imsi : "");
3125 if (os_snprintf_error(end - pos, ret))
3136 static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant *wpa_s,
3137 char *buf, size_t buflen)
3139 struct wpa_cred *cred;
3142 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_CRED");
3144 cred = wpa_config_add_cred(wpa_s->conf);
3148 wpa_msg(wpa_s, MSG_INFO, CRED_ADDED "%d", cred->id);
3150 ret = os_snprintf(buf, buflen, "%d\n", cred->id);
3151 if (os_snprintf_error(buflen, ret))
3157 static int wpas_ctrl_remove_cred(struct wpa_supplicant *wpa_s,
3158 struct wpa_cred *cred)
3160 struct wpa_ssid *ssid;
3165 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred");
3170 if (wpa_config_remove_cred(wpa_s->conf, id) < 0) {
3171 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred");
3175 wpa_msg(wpa_s, MSG_INFO, CRED_REMOVED "%d", id);
3177 /* Remove any network entry created based on the removed credential */
3178 ssid = wpa_s->conf->ssid;
3180 if (ssid->parent_cred == cred) {
3183 wpa_printf(MSG_DEBUG, "Remove network id %d since it "
3184 "used the removed credential", ssid->id);
3185 res = os_snprintf(str, sizeof(str), "%d", ssid->id);
3186 if (os_snprintf_error(sizeof(str), res))
3187 str[sizeof(str) - 1] = '\0';
3189 wpa_supplicant_ctrl_iface_remove_network(wpa_s, str);
3198 static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s,
3202 struct wpa_cred *cred, *prev;
3204 /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or
3205 * "provisioning_sp=<FQDN> */
3206 if (os_strcmp(cmd, "all") == 0) {
3207 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED all");
3208 cred = wpa_s->conf->cred;
3212 wpas_ctrl_remove_cred(wpa_s, prev);
3217 if (os_strncmp(cmd, "sp_fqdn=", 8) == 0) {
3218 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
3220 cred = wpa_s->conf->cred;
3226 for (i = 0; i < prev->num_domain; i++) {
3227 if (os_strcmp(prev->domain[i], cmd + 8)
3230 wpas_ctrl_remove_cred(wpa_s, prev);
3238 if (os_strncmp(cmd, "provisioning_sp=", 16) == 0) {
3239 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'",
3241 cred = wpa_s->conf->cred;
3245 if (prev->provisioning_sp &&
3246 os_strcmp(prev->provisioning_sp, cmd + 16) == 0)
3247 wpas_ctrl_remove_cred(wpa_s, prev);
3253 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED id=%d", id);
3255 cred = wpa_config_get_cred(wpa_s->conf, id);
3256 return wpas_ctrl_remove_cred(wpa_s, cred);
3260 static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant *wpa_s,
3264 struct wpa_cred *cred;
3267 /* cmd: "<cred id> <variable name> <value>" */
3268 name = os_strchr(cmd, ' ');
3273 value = os_strchr(name, ' ');
3279 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_CRED id=%d name='%s'",
3281 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
3282 (u8 *) value, os_strlen(value));
3284 cred = wpa_config_get_cred(wpa_s->conf, id);
3286 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
3291 if (wpa_config_set_cred(cred, name, value, 0) < 0) {
3292 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set cred "
3293 "variable '%s'", name);
3297 wpa_msg(wpa_s, MSG_INFO, CRED_MODIFIED "%d %s", cred->id, name);
3303 static int wpa_supplicant_ctrl_iface_get_cred(struct wpa_supplicant *wpa_s,
3304 char *cmd, char *buf,
3309 struct wpa_cred *cred;
3312 /* cmd: "<cred id> <variable name>" */
3313 name = os_strchr(cmd, ' ');
3319 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CRED id=%d name='%s'",
3322 cred = wpa_config_get_cred(wpa_s->conf, id);
3324 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
3329 value = wpa_config_get_cred_no_key(cred, name);
3330 if (value == NULL) {
3331 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get cred variable '%s'",
3336 res = os_strlcpy(buf, value, buflen);
3337 if (res >= buflen) {
3348 #ifndef CONFIG_NO_CONFIG_WRITE
3349 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s)
3353 if (!wpa_s->conf->update_config) {
3354 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
3355 "to update configuration (update_config=0)");
3359 ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
3361 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to "
3362 "update configuration");
3364 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration"
3370 #endif /* CONFIG_NO_CONFIG_WRITE */
3373 struct cipher_info {
3379 static const struct cipher_info ciphers[] = {
3380 { WPA_DRIVER_CAPA_ENC_CCMP_256, "CCMP-256", 0 },
3381 { WPA_DRIVER_CAPA_ENC_GCMP_256, "GCMP-256", 0 },
3382 { WPA_DRIVER_CAPA_ENC_CCMP, "CCMP", 0 },
3383 { WPA_DRIVER_CAPA_ENC_GCMP, "GCMP", 0 },
3384 { WPA_DRIVER_CAPA_ENC_TKIP, "TKIP", 0 },
3385 { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE, "NONE", 0 },
3386 { WPA_DRIVER_CAPA_ENC_WEP104, "WEP104", 1 },
3387 { WPA_DRIVER_CAPA_ENC_WEP40, "WEP40", 1 }
3390 static const struct cipher_info ciphers_group_mgmt[] = {
3391 { WPA_DRIVER_CAPA_ENC_BIP, "AES-128-CMAC", 1 },
3392 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_128, "BIP-GMAC-128", 1 },
3393 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_256, "BIP-GMAC-256", 1 },
3394 { WPA_DRIVER_CAPA_ENC_BIP_CMAC_256, "BIP-CMAC-256", 1 },
3398 static int ctrl_iface_get_capability_pairwise(int res, char *strict,
3399 struct wpa_driver_capa *capa,
3400 char *buf, size_t buflen)
3413 len = os_strlcpy(buf, "CCMP TKIP NONE", buflen);
3419 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
3420 if (!ciphers[i].group_only && capa->enc & ciphers[i].capa) {
3421 ret = os_snprintf(pos, end - pos, "%s%s",
3422 pos == buf ? "" : " ",
3424 if (os_snprintf_error(end - pos, ret))
3434 static int ctrl_iface_get_capability_group(int res, char *strict,
3435 struct wpa_driver_capa *capa,
3436 char *buf, size_t buflen)
3449 len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen);
3455 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
3456 if (capa->enc & ciphers[i].capa) {
3457 ret = os_snprintf(pos, end - pos, "%s%s",
3458 pos == buf ? "" : " ",
3460 if (os_snprintf_error(end - pos, ret))
3470 static int ctrl_iface_get_capability_group_mgmt(int res, char *strict,
3471 struct wpa_driver_capa *capa,
3472 char *buf, size_t buflen)
3484 for (i = 0; i < ARRAY_SIZE(ciphers_group_mgmt); i++) {
3485 if (capa->enc & ciphers_group_mgmt[i].capa) {
3486 ret = os_snprintf(pos, end - pos, "%s%s",
3487 pos == buf ? "" : " ",
3488 ciphers_group_mgmt[i].name);
3489 if (os_snprintf_error(end - pos, ret))
3499 static int ctrl_iface_get_capability_key_mgmt(int res, char *strict,
3500 struct wpa_driver_capa *capa,
3501 char *buf, size_t buflen)
3513 len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
3520 ret = os_snprintf(pos, end - pos, "NONE IEEE8021X");
3521 if (os_snprintf_error(end - pos, ret))
3525 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
3526 WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
3527 ret = os_snprintf(pos, end - pos, " WPA-EAP");
3528 if (os_snprintf_error(end - pos, ret))
3533 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
3534 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
3535 ret = os_snprintf(pos, end - pos, " WPA-PSK");
3536 if (os_snprintf_error(end - pos, ret))
3541 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
3542 ret = os_snprintf(pos, end - pos, " WPA-NONE");
3543 if (os_snprintf_error(end - pos, ret))
3548 #ifdef CONFIG_SUITEB
3549 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B) {
3550 ret = os_snprintf(pos, end - pos, " WPA-EAP-SUITE-B");
3551 if (os_snprintf_error(end - pos, ret))
3555 #endif /* CONFIG_SUITEB */
3556 #ifdef CONFIG_SUITEB192
3557 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192) {
3558 ret = os_snprintf(pos, end - pos, " WPA-EAP-SUITE-B-192");
3559 if (os_snprintf_error(end - pos, ret))
3563 #endif /* CONFIG_SUITEB192 */
3569 static int ctrl_iface_get_capability_proto(int res, char *strict,
3570 struct wpa_driver_capa *capa,
3571 char *buf, size_t buflen)
3583 len = os_strlcpy(buf, "RSN WPA", buflen);
3589 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
3590 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
3591 ret = os_snprintf(pos, end - pos, "%sRSN",
3592 pos == buf ? "" : " ");
3593 if (os_snprintf_error(end - pos, ret))
3598 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
3599 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
3600 ret = os_snprintf(pos, end - pos, "%sWPA",
3601 pos == buf ? "" : " ");
3602 if (os_snprintf_error(end - pos, ret))
3611 static int ctrl_iface_get_capability_auth_alg(struct wpa_supplicant *wpa_s,
3612 int res, char *strict,
3613 struct wpa_driver_capa *capa,
3614 char *buf, size_t buflen)
3626 len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen);
3632 if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) {
3633 ret = os_snprintf(pos, end - pos, "%sOPEN",
3634 pos == buf ? "" : " ");
3635 if (os_snprintf_error(end - pos, ret))
3640 if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) {
3641 ret = os_snprintf(pos, end - pos, "%sSHARED",
3642 pos == buf ? "" : " ");
3643 if (os_snprintf_error(end - pos, ret))
3648 if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) {
3649 ret = os_snprintf(pos, end - pos, "%sLEAP",
3650 pos == buf ? "" : " ");
3651 if (os_snprintf_error(end - pos, ret))
3657 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE) {
3658 ret = os_snprintf(pos, end - pos, "%sSAE",
3659 pos == buf ? "" : " ");
3660 if (os_snprintf_error(end - pos, ret))
3664 #endif /* CONFIG_SAE */
3670 static int ctrl_iface_get_capability_modes(int res, char *strict,
3671 struct wpa_driver_capa *capa,
3672 char *buf, size_t buflen)
3684 len = os_strlcpy(buf, "IBSS AP", buflen);
3690 if (capa->flags & WPA_DRIVER_FLAGS_IBSS) {
3691 ret = os_snprintf(pos, end - pos, "%sIBSS",
3692 pos == buf ? "" : " ");
3693 if (os_snprintf_error(end - pos, ret))
3698 if (capa->flags & WPA_DRIVER_FLAGS_AP) {
3699 ret = os_snprintf(pos, end - pos, "%sAP",
3700 pos == buf ? "" : " ");
3701 if (os_snprintf_error(end - pos, ret))
3707 if (capa->flags & WPA_DRIVER_FLAGS_MESH) {
3708 ret = os_snprintf(pos, end - pos, "%sMESH",
3709 pos == buf ? "" : " ");
3710 if (os_snprintf_error(end - pos, ret))
3714 #endif /* CONFIG_MESH */
3720 static int ctrl_iface_get_capability_channels(struct wpa_supplicant *wpa_s,
3721 char *buf, size_t buflen)
3723 struct hostapd_channel_data *chnl;
3725 char *pos, *end, *hmode;
3730 for (j = 0; j < wpa_s->hw.num_modes; j++) {
3731 switch (wpa_s->hw.modes[j].mode) {
3732 case HOSTAPD_MODE_IEEE80211B:
3735 case HOSTAPD_MODE_IEEE80211G:
3738 case HOSTAPD_MODE_IEEE80211A:
3741 case HOSTAPD_MODE_IEEE80211AD:
3747 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:", hmode);
3748 if (os_snprintf_error(end - pos, ret))
3751 chnl = wpa_s->hw.modes[j].channels;
3752 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
3753 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
3755 ret = os_snprintf(pos, end - pos, " %d", chnl[i].chan);
3756 if (os_snprintf_error(end - pos, ret))
3760 ret = os_snprintf(pos, end - pos, "\n");
3761 if (os_snprintf_error(end - pos, ret))
3770 static int ctrl_iface_get_capability_freq(struct wpa_supplicant *wpa_s,
3771 char *buf, size_t buflen)
3773 struct hostapd_channel_data *chnl;
3775 char *pos, *end, *hmode;
3780 for (j = 0; j < wpa_s->hw.num_modes; j++) {
3781 switch (wpa_s->hw.modes[j].mode) {
3782 case HOSTAPD_MODE_IEEE80211B:
3785 case HOSTAPD_MODE_IEEE80211G:
3788 case HOSTAPD_MODE_IEEE80211A:
3791 case HOSTAPD_MODE_IEEE80211AD:
3797 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:\n",
3799 if (os_snprintf_error(end - pos, ret))
3802 chnl = wpa_s->hw.modes[j].channels;
3803 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
3804 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
3806 ret = os_snprintf(pos, end - pos, " %d = %d MHz%s%s\n",
3807 chnl[i].chan, chnl[i].freq,
3808 chnl[i].flag & HOSTAPD_CHAN_NO_IR ?
3810 chnl[i].flag & HOSTAPD_CHAN_RADAR ?
3813 if (os_snprintf_error(end - pos, ret))
3817 ret = os_snprintf(pos, end - pos, "\n");
3818 if (os_snprintf_error(end - pos, ret))
3827 static int wpa_supplicant_ctrl_iface_get_capability(
3828 struct wpa_supplicant *wpa_s, const char *_field, char *buf,
3831 struct wpa_driver_capa capa;
3837 /* Determine whether or not strict checking was requested */
3838 len = os_strlcpy(field, _field, sizeof(field));
3839 if (len >= sizeof(field))
3841 strict = os_strchr(field, ' ');
3842 if (strict != NULL) {
3844 if (os_strcmp(strict, "strict") != 0)
3848 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
3849 field, strict ? strict : "");
3851 if (os_strcmp(field, "eap") == 0) {
3852 return eap_get_names(buf, buflen);
3855 res = wpa_drv_get_capa(wpa_s, &capa);
3857 if (os_strcmp(field, "pairwise") == 0)
3858 return ctrl_iface_get_capability_pairwise(res, strict, &capa,
3861 if (os_strcmp(field, "group") == 0)
3862 return ctrl_iface_get_capability_group(res, strict, &capa,
3865 if (os_strcmp(field, "group_mgmt") == 0)
3866 return ctrl_iface_get_capability_group_mgmt(res, strict, &capa,
3869 if (os_strcmp(field, "key_mgmt") == 0)
3870 return ctrl_iface_get_capability_key_mgmt(res, strict, &capa,
3873 if (os_strcmp(field, "proto") == 0)
3874 return ctrl_iface_get_capability_proto(res, strict, &capa,
3877 if (os_strcmp(field, "auth_alg") == 0)
3878 return ctrl_iface_get_capability_auth_alg(wpa_s, res, strict,
3879 &capa, buf, buflen);
3881 if (os_strcmp(field, "modes") == 0)
3882 return ctrl_iface_get_capability_modes(res, strict, &capa,
3885 if (os_strcmp(field, "channels") == 0)
3886 return ctrl_iface_get_capability_channels(wpa_s, buf, buflen);
3888 if (os_strcmp(field, "freq") == 0)
3889 return ctrl_iface_get_capability_freq(wpa_s, buf, buflen);
3892 if (os_strcmp(field, "tdls") == 0)
3893 return ctrl_iface_get_capability_tdls(wpa_s, buf, buflen);
3894 #endif /* CONFIG_TDLS */
3897 if (os_strcmp(field, "erp") == 0) {
3898 res = os_snprintf(buf, buflen, "ERP");
3899 if (os_snprintf_error(buflen, res))
3903 #endif /* CONFIG_EPR */
3905 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
3912 #ifdef CONFIG_INTERWORKING
3913 static char * anqp_add_hex(char *pos, char *end, const char *title,
3914 struct wpabuf *data)
3924 ret = os_snprintf(pos, end - pos, "%s=", title);
3925 if (os_snprintf_error(end - pos, ret))
3929 d = wpabuf_head_u8(data);
3930 for (i = 0; i < wpabuf_len(data); i++) {
3931 ret = os_snprintf(pos, end - pos, "%02x", *d++);
3932 if (os_snprintf_error(end - pos, ret))
3937 ret = os_snprintf(pos, end - pos, "\n");
3938 if (os_snprintf_error(end - pos, ret))
3944 #endif /* CONFIG_INTERWORKING */
3947 static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
3948 unsigned long mask, char *buf, size_t buflen)
3953 const u8 *ie, *ie2, *osen_ie;
3958 if (mask & WPA_BSS_MASK_ID) {
3959 ret = os_snprintf(pos, end - pos, "id=%u\n", bss->id);
3960 if (os_snprintf_error(end - pos, ret))
3965 if (mask & WPA_BSS_MASK_BSSID) {
3966 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
3967 MAC2STR(bss->bssid));
3968 if (os_snprintf_error(end - pos, ret))
3973 if (mask & WPA_BSS_MASK_FREQ) {
3974 ret = os_snprintf(pos, end - pos, "freq=%d\n", bss->freq);
3975 if (os_snprintf_error(end - pos, ret))
3980 if (mask & WPA_BSS_MASK_BEACON_INT) {
3981 ret = os_snprintf(pos, end - pos, "beacon_int=%d\n",
3983 if (os_snprintf_error(end - pos, ret))
3988 if (mask & WPA_BSS_MASK_CAPABILITIES) {
3989 ret = os_snprintf(pos, end - pos, "capabilities=0x%04x\n",
3991 if (os_snprintf_error(end - pos, ret))
3996 if (mask & WPA_BSS_MASK_QUAL) {
3997 ret = os_snprintf(pos, end - pos, "qual=%d\n", bss->qual);
3998 if (os_snprintf_error(end - pos, ret))
4003 if (mask & WPA_BSS_MASK_NOISE) {
4004 ret = os_snprintf(pos, end - pos, "noise=%d\n", bss->noise);
4005 if (os_snprintf_error(end - pos, ret))
4010 if (mask & WPA_BSS_MASK_LEVEL) {
4011 ret = os_snprintf(pos, end - pos, "level=%d\n", bss->level);
4012 if (os_snprintf_error(end - pos, ret))
4017 if (mask & WPA_BSS_MASK_TSF) {
4018 ret = os_snprintf(pos, end - pos, "tsf=%016llu\n",
4019 (unsigned long long) bss->tsf);
4020 if (os_snprintf_error(end - pos, ret))
4025 if (mask & WPA_BSS_MASK_AGE) {
4026 struct os_reltime now;
4028 os_get_reltime(&now);
4029 ret = os_snprintf(pos, end - pos, "age=%d\n",
4030 (int) (now.sec - bss->last_update.sec));
4031 if (os_snprintf_error(end - pos, ret))
4036 if (mask & WPA_BSS_MASK_IE) {
4037 ret = os_snprintf(pos, end - pos, "ie=");
4038 if (os_snprintf_error(end - pos, ret))
4042 ie = (const u8 *) (bss + 1);
4043 for (i = 0; i < bss->ie_len; i++) {
4044 ret = os_snprintf(pos, end - pos, "%02x", *ie++);
4045 if (os_snprintf_error(end - pos, ret))
4050 ret = os_snprintf(pos, end - pos, "\n");
4051 if (os_snprintf_error(end - pos, ret))
4056 if (mask & WPA_BSS_MASK_FLAGS) {
4057 ret = os_snprintf(pos, end - pos, "flags=");
4058 if (os_snprintf_error(end - pos, ret))
4062 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
4064 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie,
4066 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
4068 pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2,
4070 osen_ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
4072 pos = wpa_supplicant_ie_txt(pos, end, "OSEN",
4073 osen_ie, 2 + osen_ie[1]);
4074 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
4075 if (!ie && !ie2 && !osen_ie &&
4076 (bss->caps & IEEE80211_CAP_PRIVACY)) {
4077 ret = os_snprintf(pos, end - pos, "[WEP]");
4078 if (os_snprintf_error(end - pos, ret))
4082 if (bss_is_dmg(bss)) {
4084 ret = os_snprintf(pos, end - pos, "[DMG]");
4085 if (os_snprintf_error(end - pos, ret))
4088 switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
4089 case IEEE80211_CAP_DMG_IBSS:
4092 case IEEE80211_CAP_DMG_AP:
4095 case IEEE80211_CAP_DMG_PBSS:
4102 ret = os_snprintf(pos, end - pos, "%s", s);
4103 if (os_snprintf_error(end - pos, ret))
4107 if (bss->caps & IEEE80211_CAP_IBSS) {
4108 ret = os_snprintf(pos, end - pos, "[IBSS]");
4109 if (os_snprintf_error(end - pos, ret))
4113 if (bss->caps & IEEE80211_CAP_ESS) {
4114 ret = os_snprintf(pos, end - pos, "[ESS]");
4115 if (os_snprintf_error(end - pos, ret))
4120 if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
4121 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
4122 ret = os_snprintf(pos, end - pos, "[P2P]");
4123 if (os_snprintf_error(end - pos, ret))
4128 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) {
4129 ret = os_snprintf(pos, end - pos, "[HS20]");
4130 if (os_snprintf_error(end - pos, ret))
4134 #endif /* CONFIG_HS20 */
4136 ret = os_snprintf(pos, end - pos, "\n");
4137 if (os_snprintf_error(end - pos, ret))
4142 if (mask & WPA_BSS_MASK_SSID) {
4143 ret = os_snprintf(pos, end - pos, "ssid=%s\n",
4144 wpa_ssid_txt(bss->ssid, bss->ssid_len));
4145 if (os_snprintf_error(end - pos, ret))
4151 if (mask & WPA_BSS_MASK_WPS_SCAN) {
4152 ie = (const u8 *) (bss + 1);
4153 ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end);
4154 if (ret < 0 || ret >= end - pos)
4158 #endif /* CONFIG_WPS */
4161 if (mask & WPA_BSS_MASK_P2P_SCAN) {
4162 ie = (const u8 *) (bss + 1);
4163 ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end);
4164 if (ret < 0 || ret >= end - pos)
4168 #endif /* CONFIG_P2P */
4170 #ifdef CONFIG_WIFI_DISPLAY
4171 if (mask & WPA_BSS_MASK_WIFI_DISPLAY) {
4173 ie = (const u8 *) (bss + 1);
4174 wfd = ieee802_11_vendor_ie_concat(ie, bss->ie_len,
4175 WFD_IE_VENDOR_TYPE);
4177 ret = os_snprintf(pos, end - pos, "wfd_subelems=");
4178 if (os_snprintf_error(end - pos, ret)) {
4184 pos += wpa_snprintf_hex(pos, end - pos,
4189 ret = os_snprintf(pos, end - pos, "\n");
4190 if (os_snprintf_error(end - pos, ret))
4195 #endif /* CONFIG_WIFI_DISPLAY */
4197 #ifdef CONFIG_INTERWORKING
4198 if ((mask & WPA_BSS_MASK_INTERNETW) && bss->anqp) {
4199 struct wpa_bss_anqp *anqp = bss->anqp;
4200 pos = anqp_add_hex(pos, end, "anqp_capability_list",
4201 anqp->capability_list);
4202 pos = anqp_add_hex(pos, end, "anqp_venue_name",
4204 pos = anqp_add_hex(pos, end, "anqp_network_auth_type",
4205 anqp->network_auth_type);
4206 pos = anqp_add_hex(pos, end, "anqp_roaming_consortium",
4207 anqp->roaming_consortium);
4208 pos = anqp_add_hex(pos, end, "anqp_ip_addr_type_availability",
4209 anqp->ip_addr_type_availability);
4210 pos = anqp_add_hex(pos, end, "anqp_nai_realm",
4212 pos = anqp_add_hex(pos, end, "anqp_3gpp", anqp->anqp_3gpp);
4213 pos = anqp_add_hex(pos, end, "anqp_domain_name",
4216 pos = anqp_add_hex(pos, end, "hs20_capability_list",
4217 anqp->hs20_capability_list);
4218 pos = anqp_add_hex(pos, end, "hs20_operator_friendly_name",
4219 anqp->hs20_operator_friendly_name);
4220 pos = anqp_add_hex(pos, end, "hs20_wan_metrics",
4221 anqp->hs20_wan_metrics);
4222 pos = anqp_add_hex(pos, end, "hs20_connection_capability",
4223 anqp->hs20_connection_capability);
4224 pos = anqp_add_hex(pos, end, "hs20_operating_class",
4225 anqp->hs20_operating_class);
4226 pos = anqp_add_hex(pos, end, "hs20_osu_providers_list",
4227 anqp->hs20_osu_providers_list);
4228 #endif /* CONFIG_HS20 */
4230 #endif /* CONFIG_INTERWORKING */
4233 if (mask & WPA_BSS_MASK_MESH_SCAN) {
4234 ie = (const u8 *) (bss + 1);
4235 ret = wpas_mesh_scan_result_text(ie, bss->ie_len, pos, end);
4236 if (ret < 0 || ret >= end - pos)
4240 #endif /* CONFIG_MESH */
4242 if (mask & WPA_BSS_MASK_SNR) {
4243 ret = os_snprintf(pos, end - pos, "snr=%d\n", bss->snr);
4244 if (os_snprintf_error(end - pos, ret))
4249 if (mask & WPA_BSS_MASK_EST_THROUGHPUT) {
4250 ret = os_snprintf(pos, end - pos, "est_throughput=%d\n",
4251 bss->est_throughput);
4252 if (os_snprintf_error(end - pos, ret))
4257 if (mask & WPA_BSS_MASK_DELIM) {
4258 ret = os_snprintf(pos, end - pos, "====\n");
4259 if (os_snprintf_error(end - pos, ret))
4268 static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
4269 const char *cmd, char *buf,
4274 struct wpa_bss *bss;
4275 struct wpa_bss *bsslast = NULL;
4276 struct dl_list *next;
4279 char *ctmp, *end = buf + buflen;
4280 unsigned long mask = WPA_BSS_MASK_ALL;
4282 if (os_strncmp(cmd, "RANGE=", 6) == 0) {
4283 if (os_strncmp(cmd + 6, "ALL", 3) == 0) {
4284 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss,
4286 bsslast = dl_list_last(&wpa_s->bss_id, struct wpa_bss,
4288 } else { /* N1-N2 */
4289 unsigned int id1, id2;
4291 if ((ctmp = os_strchr(cmd + 6, '-')) == NULL) {
4292 wpa_printf(MSG_INFO, "Wrong BSS range "
4297 if (*(cmd + 6) == '-')
4300 id1 = atoi(cmd + 6);
4302 if (*ctmp >= '0' && *ctmp <= '9')
4305 id2 = (unsigned int) -1;
4306 bss = wpa_bss_get_id_range(wpa_s, id1, id2);
4307 if (id2 == (unsigned int) -1)
4308 bsslast = dl_list_last(&wpa_s->bss_id,
4312 bsslast = wpa_bss_get_id(wpa_s, id2);
4313 if (bsslast == NULL && bss && id2 > id1) {
4314 struct wpa_bss *tmp = bss;
4316 next = tmp->list_id.next;
4317 if (next == &wpa_s->bss_id)
4319 tmp = dl_list_entry(
4320 next, struct wpa_bss,
4329 } else if (os_strncmp(cmd, "FIRST", 5) == 0)
4330 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, list_id);
4331 else if (os_strncmp(cmd, "LAST", 4) == 0)
4332 bss = dl_list_last(&wpa_s->bss_id, struct wpa_bss, list_id);
4333 else if (os_strncmp(cmd, "ID-", 3) == 0) {
4335 bss = wpa_bss_get_id(wpa_s, i);
4336 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
4338 bss = wpa_bss_get_id(wpa_s, i);
4340 next = bss->list_id.next;
4341 if (next == &wpa_s->bss_id)
4344 bss = dl_list_entry(next, struct wpa_bss,
4348 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
4349 if (hwaddr_aton(cmd + 13, bssid) == 0)
4350 bss = wpa_bss_get_p2p_dev_addr(wpa_s, bssid);
4353 #endif /* CONFIG_P2P */
4354 } else if (hwaddr_aton(cmd, bssid) == 0)
4355 bss = wpa_bss_get_bssid(wpa_s, bssid);
4357 struct wpa_bss *tmp;
4360 dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id)
4369 if ((ctmp = os_strstr(cmd, "MASK=")) != NULL) {
4370 mask = strtoul(ctmp + 5, NULL, 0x10);
4372 mask = WPA_BSS_MASK_ALL;
4378 if (bsslast == NULL)
4381 len = print_bss_info(wpa_s, bss, mask, buf, buflen);
4385 if (bss == bsslast) {
4386 if ((mask & WPA_BSS_MASK_DELIM) && len &&
4387 (bss == dl_list_last(&wpa_s->bss_id,
4388 struct wpa_bss, list_id))) {
4391 res = os_snprintf(buf - 5, end - buf + 5,
4393 if (os_snprintf_error(end - buf + 5, res)) {
4394 wpa_printf(MSG_DEBUG,
4395 "Could not add end delim");
4400 next = bss->list_id.next;
4401 if (next == &wpa_s->bss_id)
4403 bss = dl_list_entry(next, struct wpa_bss, list_id);
4404 } while (bss && len);
4410 static int wpa_supplicant_ctrl_iface_ap_scan(
4411 struct wpa_supplicant *wpa_s, char *cmd)
4413 int ap_scan = atoi(cmd);
4414 return wpa_supplicant_set_ap_scan(wpa_s, ap_scan);
4418 static int wpa_supplicant_ctrl_iface_scan_interval(
4419 struct wpa_supplicant *wpa_s, char *cmd)
4421 int scan_int = atoi(cmd);
4422 return wpa_supplicant_set_scan_interval(wpa_s, scan_int);
4426 static int wpa_supplicant_ctrl_iface_bss_expire_age(
4427 struct wpa_supplicant *wpa_s, char *cmd)
4429 int expire_age = atoi(cmd);
4430 return wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age);
4434 static int wpa_supplicant_ctrl_iface_bss_expire_count(
4435 struct wpa_supplicant *wpa_s, char *cmd)
4437 int expire_count = atoi(cmd);
4438 return wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count);
4442 static void wpa_supplicant_ctrl_iface_bss_flush(
4443 struct wpa_supplicant *wpa_s, char *cmd)
4445 int flush_age = atoi(cmd);
4448 wpa_bss_flush(wpa_s);
4450 wpa_bss_flush_by_age(wpa_s, flush_age);
4454 #ifdef CONFIG_TESTING_OPTIONS
4455 static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s)
4457 wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication");
4458 /* MLME-DELETEKEYS.request */
4459 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL, 0);
4460 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL, 0);
4461 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL, 0);
4462 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL, 0);
4463 #ifdef CONFIG_IEEE80211W
4464 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL, 0);
4465 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL, 0);
4466 #endif /* CONFIG_IEEE80211W */
4468 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, wpa_s->bssid, 0, 0, NULL, 0, NULL,
4470 /* MLME-SETPROTECTION.request(None) */
4471 wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid,
4472 MLME_SETPROTECTION_PROTECT_TYPE_NONE,
4473 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE);
4474 wpa_sm_drop_sa(wpa_s->wpa);
4476 #endif /* CONFIG_TESTING_OPTIONS */
4479 static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s,
4482 #ifdef CONFIG_NO_SCAN_PROCESSING
4484 #else /* CONFIG_NO_SCAN_PROCESSING */
4486 struct wpa_bss *bss;
4487 struct wpa_ssid *ssid = wpa_s->current_ssid;
4489 if (hwaddr_aton(addr, bssid)) {
4490 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid "
4491 "address '%s'", addr);
4495 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR, MAC2STR(bssid));
4498 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network "
4499 "configuration known for the target AP");
4503 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
4505 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found "
4511 * TODO: Find best network configuration block from configuration to
4512 * allow roaming to other networks
4515 wpa_s->reassociate = 1;
4516 wpa_supplicant_connect(wpa_s, bss, ssid);
4519 #endif /* CONFIG_NO_SCAN_PROCESSING */
4524 static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd)
4526 unsigned int timeout = atoi(cmd);
4527 enum p2p_discovery_type type = P2P_FIND_START_WITH_FULL;
4528 u8 dev_id[ETH_ALEN], *_dev_id = NULL;
4529 u8 dev_type[WPS_DEV_TYPE_LEN], *_dev_type = NULL;
4531 unsigned int search_delay;
4532 const char *_seek[P2P_MAX_QUERY_HASH + 1], **seek = NULL;
4536 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
4537 wpa_dbg(wpa_s, MSG_INFO,
4538 "Reject P2P_FIND since interface is disabled");
4541 if (os_strstr(cmd, "type=social"))
4542 type = P2P_FIND_ONLY_SOCIAL;
4543 else if (os_strstr(cmd, "type=progressive"))
4544 type = P2P_FIND_PROGRESSIVE;
4546 pos = os_strstr(cmd, "dev_id=");
4549 if (hwaddr_aton(pos, dev_id))
4554 pos = os_strstr(cmd, "dev_type=");
4557 if (wps_dev_type_str2bin(pos, dev_type) < 0)
4559 _dev_type = dev_type;
4562 pos = os_strstr(cmd, "delay=");
4565 search_delay = atoi(pos);
4567 search_delay = wpas_p2p_search_delay(wpa_s);
4569 /* Must be searched for last, because it adds nul termination */
4570 pos = os_strstr(cmd, " seek=");
4571 while (pos && seek_count < P2P_MAX_QUERY_HASH + 1) {
4574 term = os_strchr(pos + 1, ' ');
4575 _seek[seek_count++] = pos + 6;
4577 pos = os_strstr(pos + 6, " seek=");
4582 if (seek_count > P2P_MAX_QUERY_HASH) {
4587 pos = os_strstr(cmd, "freq=");
4595 return wpas_p2p_find(wpa_s, timeout, type, _dev_type != NULL, _dev_type,
4596 _dev_id, search_delay, seek_count, seek, freq);
4600 static struct p2ps_provision * p2p_parse_asp_provision_cmd(const char *cmd)
4602 struct p2ps_provision *p2ps_prov;
4604 size_t info_len = 0;
4606 u8 role = P2PS_SETUP_NONE;
4607 long long unsigned val;
4609 pos = os_strstr(cmd, "info=");
4612 info_len = os_strlen(pos);
4615 info = os_malloc(info_len + 1);
4617 info_len = utf8_unescape(pos, info_len,
4618 info, info_len + 1);
4624 p2ps_prov = os_zalloc(sizeof(struct p2ps_provision) + info_len + 1);
4625 if (p2ps_prov == NULL) {
4631 os_memcpy(p2ps_prov->info, info, info_len);
4632 p2ps_prov->info[info_len] = '\0';
4636 pos = os_strstr(cmd, "status=");
4638 p2ps_prov->status = atoi(pos + 7);
4640 p2ps_prov->status = -1;
4642 pos = os_strstr(cmd, "adv_id=");
4643 if (!pos || sscanf(pos + 7, "%llx", &val) != 1 || val > 0xffffffffULL)
4645 p2ps_prov->adv_id = val;
4647 pos = os_strstr(cmd, "method=");
4649 p2ps_prov->method = strtol(pos + 7, NULL, 16);
4651 p2ps_prov->method = 0;
4653 pos = os_strstr(cmd, "session=");
4654 if (!pos || sscanf(pos + 8, "%llx", &val) != 1 || val > 0xffffffffULL)
4656 p2ps_prov->session_id = val;
4658 pos = os_strstr(cmd, "adv_mac=");
4659 if (!pos || hwaddr_aton(pos + 8, p2ps_prov->adv_mac))
4662 pos = os_strstr(cmd, "session_mac=");
4663 if (!pos || hwaddr_aton(pos + 12, p2ps_prov->session_mac))
4666 /* force conncap with tstCap (no sanity checks) */
4667 pos = os_strstr(cmd, "tstCap=");
4669 role = strtol(pos + 7, NULL, 16);
4671 pos = os_strstr(cmd, "role=");
4673 role = strtol(pos + 5, NULL, 16);
4674 if (role != P2PS_SETUP_CLIENT &&
4675 role != P2PS_SETUP_GROUP_OWNER)
4676 role = P2PS_SETUP_NONE;
4679 p2ps_prov->role = role;
4689 static int p2p_ctrl_asp_provision_resp(struct wpa_supplicant *wpa_s, char *cmd)
4692 struct p2ps_provision *p2ps_prov;
4695 /* <addr> id=<adv_id> [role=<conncap>] [info=<infodata>] */
4697 wpa_printf(MSG_DEBUG, "%s: %s", __func__, cmd);
4699 if (hwaddr_aton(cmd, addr))
4706 p2ps_prov = p2p_parse_asp_provision_cmd(pos);
4710 if (p2ps_prov->status < 0) {
4715 return wpas_p2p_prov_disc(wpa_s, addr, NULL, WPAS_P2P_PD_FOR_ASP,
4720 static int p2p_ctrl_asp_provision(struct wpa_supplicant *wpa_s, char *cmd)
4723 struct p2ps_provision *p2ps_prov;
4726 /* <addr> id=<adv_id> adv_mac=<adv_mac> conncap=<conncap>
4727 * session=<ses_id> mac=<ses_mac> [info=<infodata>]
4730 wpa_printf(MSG_DEBUG, "%s: %s", __func__, cmd);
4731 if (hwaddr_aton(cmd, addr))
4738 p2ps_prov = p2p_parse_asp_provision_cmd(pos);
4742 return wpas_p2p_prov_disc(wpa_s, addr, NULL, WPAS_P2P_PD_FOR_ASP,
4747 static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd,
4748 char *buf, size_t buflen)
4753 enum p2p_wps_method wps_method;
4756 int persistent_group, persistent_id = -1;
4765 if (!wpa_s->global->p2p_init_wpa_s)
4767 if (wpa_s->global->p2p_init_wpa_s != wpa_s) {
4768 wpa_dbg(wpa_s, MSG_DEBUG, "Direct P2P_CONNECT command to %s",
4769 wpa_s->global->p2p_init_wpa_s->ifname);
4770 wpa_s = wpa_s->global->p2p_init_wpa_s;
4773 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad|p2ps]
4774 * [persistent|persistent=<network id>]
4775 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
4776 * [ht40] [vht] [auto] */
4778 if (hwaddr_aton(cmd, addr))
4786 persistent_group = os_strstr(pos, " persistent") != NULL;
4787 pos2 = os_strstr(pos, " persistent=");
4789 struct wpa_ssid *ssid;
4790 persistent_id = atoi(pos2 + 12);
4791 ssid = wpa_config_get_network(wpa_s->conf, persistent_id);
4792 if (ssid == NULL || ssid->disabled != 2 ||
4793 ssid->mode != WPAS_MODE_P2P_GO) {
4794 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
4795 "SSID id=%d for persistent P2P group (GO)",
4800 join = os_strstr(pos, " join") != NULL;
4801 auth = os_strstr(pos, " auth") != NULL;
4802 automatic = os_strstr(pos, " auto") != NULL;
4803 pd = os_strstr(pos, " provdisc") != NULL;
4804 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
4805 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
4808 pos2 = os_strstr(pos, " go_intent=");
4811 go_intent = atoi(pos2);
4812 if (go_intent < 0 || go_intent > 15)
4816 pos2 = os_strstr(pos, " freq=");
4824 if (os_strncmp(pos, "pin", 3) == 0) {
4825 /* Request random PIN (to be displayed) and enable the PIN */
4826 wps_method = WPS_PIN_DISPLAY;
4827 } else if (os_strncmp(pos, "pbc", 3) == 0) {
4828 wps_method = WPS_PBC;
4831 pos = os_strchr(pin, ' ');
4832 wps_method = WPS_PIN_KEYPAD;
4835 if (os_strncmp(pos, "display", 7) == 0)
4836 wps_method = WPS_PIN_DISPLAY;
4837 else if (os_strncmp(pos, "p2ps", 4) == 0)
4838 wps_method = WPS_P2PS;
4840 if (!wps_pin_str_valid(pin)) {
4841 os_memcpy(buf, "FAIL-INVALID-PIN\n", 17);
4846 new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method,
4847 persistent_group, automatic, join,
4848 auth, go_intent, freq, persistent_id, pd,
4850 if (new_pin == -2) {
4851 os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
4854 if (new_pin == -3) {
4855 os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
4860 if (wps_method == WPS_PIN_DISPLAY && pin == NULL) {
4861 ret = os_snprintf(buf, buflen, "%08d", new_pin);
4862 if (os_snprintf_error(buflen, ret))
4867 os_memcpy(buf, "OK\n", 3);
4872 static int p2p_ctrl_listen(struct wpa_supplicant *wpa_s, char *cmd)
4874 unsigned int timeout = atoi(cmd);
4875 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
4876 wpa_dbg(wpa_s, MSG_INFO,
4877 "Reject P2P_LISTEN since interface is disabled");
4880 return wpas_p2p_listen(wpa_s, timeout);
4884 static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd)
4888 enum wpas_p2p_prov_disc_use use = WPAS_P2P_PD_FOR_GO_NEG;
4890 /* <addr> <config method> [join|auto] */
4892 if (hwaddr_aton(cmd, addr))
4900 if (os_strstr(pos, " join") != NULL)
4901 use = WPAS_P2P_PD_FOR_JOIN;
4902 else if (os_strstr(pos, " auto") != NULL)
4903 use = WPAS_P2P_PD_AUTO;
4905 return wpas_p2p_prov_disc(wpa_s, addr, pos, use, NULL);
4909 static int p2p_get_passphrase(struct wpa_supplicant *wpa_s, char *buf,
4912 struct wpa_ssid *ssid = wpa_s->current_ssid;
4914 if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO ||
4915 ssid->passphrase == NULL)
4918 os_strlcpy(buf, ssid->passphrase, buflen);
4919 return os_strlen(buf);
4923 static int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd,
4924 char *buf, size_t buflen)
4928 u8 dst_buf[ETH_ALEN], *dst;
4929 struct wpabuf *tlvs;
4933 if (hwaddr_aton(cmd, dst_buf))
4936 if (dst[0] == 0 && dst[1] == 0 && dst[2] == 0 &&
4937 dst[3] == 0 && dst[4] == 0 && dst[5] == 0)
4944 if (os_strncmp(pos, "upnp ", 5) == 0) {
4947 if (hexstr2bin(pos, &version, 1) < 0)
4953 ref = wpas_p2p_sd_request_upnp(wpa_s, dst, version, pos);
4954 #ifdef CONFIG_WIFI_DISPLAY
4955 } else if (os_strncmp(pos, "wifi-display ", 13) == 0) {
4956 ref = wpas_p2p_sd_request_wifi_display(wpa_s, dst, pos + 13);
4957 #endif /* CONFIG_WIFI_DISPLAY */
4958 } else if (os_strncmp(pos, "asp ", 4) == 0) {
4960 char *svc_info = NULL;
4964 if (sscanf(pos, "%x", &id) != 1 || id > 0xff)
4967 pos = os_strchr(pos, ' ');
4968 if (pos == NULL || pos[1] == '\0' || pos[1] == ' ')
4973 pos = os_strchr(svc_str, ' ');
4978 /* All remaining data is the svc_info string */
4979 if (pos && pos[0] && pos[0] != ' ') {
4980 len = os_strlen(pos);
4982 /* Unescape in place */
4983 len = utf8_unescape(pos, len, pos, len);
4990 ref = wpas_p2p_sd_request_asp(wpa_s, dst, (u8) id,
4993 len = os_strlen(pos);
4997 tlvs = wpabuf_alloc(len);
5000 if (hexstr2bin(pos, wpabuf_put(tlvs, len), len) < 0) {
5005 ref = wpas_p2p_sd_request(wpa_s, dst, tlvs);
5010 res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref);
5011 if (os_snprintf_error(buflen, res))
5017 static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s,
5020 long long unsigned val;
5022 if (sscanf(cmd, "%llx", &val) != 1)
5025 return wpas_p2p_sd_cancel_request(wpa_s, req);
5029 static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant *wpa_s, char *cmd)
5034 struct wpabuf *resp_tlvs;
5038 pos = os_strchr(cmd, ' ');
5046 if (hwaddr_aton(pos, dst))
5053 pos2 = os_strchr(pos, ' ');
5057 dialog_token = atoi(pos);
5059 len = os_strlen(pos2);
5063 resp_tlvs = wpabuf_alloc(len);
5064 if (resp_tlvs == NULL)
5066 if (hexstr2bin(pos2, wpabuf_put(resp_tlvs, len), len) < 0) {
5067 wpabuf_free(resp_tlvs);
5071 wpas_p2p_sd_response(wpa_s, freq, dst, dialog_token, resp_tlvs);
5072 wpabuf_free(resp_tlvs);
5077 static int p2p_ctrl_serv_disc_external(struct wpa_supplicant *wpa_s,
5080 if (os_strcmp(cmd, "0") && os_strcmp(cmd, "1"))
5082 wpa_s->p2p_sd_over_ctrl_iface = atoi(cmd);
5087 static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant *wpa_s,
5092 struct wpabuf *query, *resp;
5094 pos = os_strchr(cmd, ' ');
5099 len = os_strlen(cmd);
5103 query = wpabuf_alloc(len);
5106 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
5111 len = os_strlen(pos);
5117 resp = wpabuf_alloc(len);
5122 if (hexstr2bin(pos, wpabuf_put(resp, len), len) < 0) {
5128 if (wpas_p2p_service_add_bonjour(wpa_s, query, resp) < 0) {
5137 static int p2p_ctrl_service_add_upnp(struct wpa_supplicant *wpa_s, char *cmd)
5142 pos = os_strchr(cmd, ' ');
5147 if (hexstr2bin(cmd, &version, 1) < 0)
5150 return wpas_p2p_service_add_upnp(wpa_s, version, pos);
5154 static int p2p_ctrl_service_add_asp(struct wpa_supplicant *wpa_s,
5155 u8 replace, char *cmd)
5159 u32 auto_accept, adv_id, svc_state, config_methods;
5160 char *svc_info = NULL;
5162 pos = os_strchr(cmd, ' ');
5167 /* Auto-Accept value is mandatory, and must be one of the
5168 * single values (0, 1, 2, 4) */
5169 auto_accept = atoi(cmd);
5170 switch (auto_accept) {
5171 case P2PS_SETUP_NONE: /* No auto-accept */
5172 case P2PS_SETUP_NEW:
5173 case P2PS_SETUP_CLIENT:
5174 case P2PS_SETUP_GROUP_OWNER:
5180 /* Advertisement ID is mandatory */
5182 pos = os_strchr(cmd, ' ');
5187 /* Handle Adv_ID == 0 (wildcard "org.wi-fi.wfds") internally. */
5188 if (sscanf(cmd, "%x", &adv_id) != 1 || adv_id == 0)
5191 /* Only allow replacements if exist, and adds if not */
5192 if (wpas_p2p_service_p2ps_id_exists(wpa_s, adv_id)) {
5200 /* svc_state between 0 - 0xff is mandatory */
5201 if (sscanf(pos, "%x", &svc_state) != 1 || svc_state > 0xff)
5204 pos = os_strchr(pos, ' ');
5208 /* config_methods is mandatory */
5210 if (sscanf(pos, "%x", &config_methods) != 1)
5213 if (!(config_methods &
5214 (WPS_CONFIG_DISPLAY | WPS_CONFIG_KEYPAD | WPS_CONFIG_P2PS)))
5217 pos = os_strchr(pos, ' ');
5224 /* Advertisement string is mandatory */
5225 if (!pos[0] || pos[0] == ' ')
5228 /* Terminate svc string */
5229 pos = os_strchr(pos, ' ');
5233 /* Service and Response Information are optional */
5234 if (pos && pos[0]) {
5237 /* Note the bare ' included, which cannot exist legally
5238 * in unescaped string. */
5239 svc_info = os_strstr(pos, "svc_info='");
5243 len = os_strlen(svc_info);
5244 utf8_unescape(svc_info, len, svc_info, len);
5248 return wpas_p2p_service_add_asp(wpa_s, auto_accept, adv_id, adv_str,
5249 (u8) svc_state, (u16) config_methods,
5254 static int p2p_ctrl_service_add(struct wpa_supplicant *wpa_s, char *cmd)
5258 pos = os_strchr(cmd, ' ');
5263 if (os_strcmp(cmd, "bonjour") == 0)
5264 return p2p_ctrl_service_add_bonjour(wpa_s, pos);
5265 if (os_strcmp(cmd, "upnp") == 0)
5266 return p2p_ctrl_service_add_upnp(wpa_s, pos);
5267 if (os_strcmp(cmd, "asp") == 0)
5268 return p2p_ctrl_service_add_asp(wpa_s, 0, pos);
5269 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
5274 static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant *wpa_s,
5278 struct wpabuf *query;
5281 len = os_strlen(cmd);
5285 query = wpabuf_alloc(len);
5288 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
5293 ret = wpas_p2p_service_del_bonjour(wpa_s, query);
5299 static int p2p_ctrl_service_del_upnp(struct wpa_supplicant *wpa_s, char *cmd)
5304 pos = os_strchr(cmd, ' ');
5309 if (hexstr2bin(cmd, &version, 1) < 0)
5312 return wpas_p2p_service_del_upnp(wpa_s, version, pos);
5316 static int p2p_ctrl_service_del_asp(struct wpa_supplicant *wpa_s, char *cmd)
5320 if (os_strcmp(cmd, "all") == 0) {
5321 wpas_p2p_service_flush_asp(wpa_s);
5325 if (sscanf(cmd, "%x", &adv_id) != 1)
5328 return wpas_p2p_service_del_asp(wpa_s, adv_id);
5332 static int p2p_ctrl_service_del(struct wpa_supplicant *wpa_s, char *cmd)
5336 pos = os_strchr(cmd, ' ');
5341 if (os_strcmp(cmd, "bonjour") == 0)
5342 return p2p_ctrl_service_del_bonjour(wpa_s, pos);
5343 if (os_strcmp(cmd, "upnp") == 0)
5344 return p2p_ctrl_service_del_upnp(wpa_s, pos);
5345 if (os_strcmp(cmd, "asp") == 0)
5346 return p2p_ctrl_service_del_asp(wpa_s, pos);
5347 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
5352 static int p2p_ctrl_service_replace(struct wpa_supplicant *wpa_s, char *cmd)
5356 pos = os_strchr(cmd, ' ');
5361 if (os_strcmp(cmd, "asp") == 0)
5362 return p2p_ctrl_service_add_asp(wpa_s, 1, pos);
5364 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
5369 static int p2p_ctrl_reject(struct wpa_supplicant *wpa_s, char *cmd)
5375 if (hwaddr_aton(cmd, addr))
5378 return wpas_p2p_reject(wpa_s, addr);
5382 static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd)
5386 struct wpa_ssid *ssid;
5387 u8 *_peer = NULL, peer[ETH_ALEN];
5388 int freq = 0, pref_freq = 0;
5392 pos = os_strstr(cmd, " peer=");
5395 if (hwaddr_aton(pos, peer))
5399 ssid = wpa_config_get_network(wpa_s->conf, id);
5400 if (ssid == NULL || ssid->disabled != 2) {
5401 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
5402 "for persistent P2P group",
5407 pos = os_strstr(cmd, " freq=");
5415 pos = os_strstr(cmd, " pref=");
5418 pref_freq = atoi(pos);
5423 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
5424 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
5427 return wpas_p2p_invite(wpa_s, _peer, ssid, NULL, freq, ht40, vht,
5432 static int p2p_ctrl_invite_group(struct wpa_supplicant *wpa_s, char *cmd)
5435 u8 peer[ETH_ALEN], go_dev_addr[ETH_ALEN], *go_dev = NULL;
5437 pos = os_strstr(cmd, " peer=");
5443 if (hwaddr_aton(pos, peer)) {
5444 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", pos);
5448 pos = os_strstr(pos, " go_dev_addr=");
5451 if (hwaddr_aton(pos, go_dev_addr)) {
5452 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'",
5456 go_dev = go_dev_addr;
5459 return wpas_p2p_invite_group(wpa_s, cmd, peer, go_dev);
5463 static int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd)
5465 if (os_strncmp(cmd, "persistent=", 11) == 0)
5466 return p2p_ctrl_invite_persistent(wpa_s, cmd + 11);
5467 if (os_strncmp(cmd, "group=", 6) == 0)
5468 return p2p_ctrl_invite_group(wpa_s, cmd + 6);
5474 static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s,
5475 char *cmd, int freq, int ht40,
5479 struct wpa_ssid *ssid;
5482 ssid = wpa_config_get_network(wpa_s->conf, id);
5483 if (ssid == NULL || ssid->disabled != 2) {
5484 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
5485 "for persistent P2P group",
5490 return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq, 0, ht40, vht,
5495 static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd)
5497 int freq = 0, ht40, vht;
5500 pos = os_strstr(cmd, "freq=");
5502 freq = atoi(pos + 5);
5504 vht = (os_strstr(cmd, "vht") != NULL) || wpa_s->conf->p2p_go_vht;
5505 ht40 = (os_strstr(cmd, "ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
5508 if (os_strncmp(cmd, "persistent=", 11) == 0)
5509 return p2p_ctrl_group_add_persistent(wpa_s, cmd + 11, freq,
5511 if (os_strcmp(cmd, "persistent") == 0 ||
5512 os_strncmp(cmd, "persistent ", 11) == 0)
5513 return wpas_p2p_group_add(wpa_s, 1, freq, ht40, vht);
5514 if (os_strncmp(cmd, "freq=", 5) == 0)
5515 return wpas_p2p_group_add(wpa_s, 0, freq, ht40, vht);
5517 return wpas_p2p_group_add(wpa_s, 0, freq, ht40, vht);
5519 wpa_printf(MSG_DEBUG, "CTRL: Invalid P2P_GROUP_ADD parameters '%s'",
5525 static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd,
5526 char *buf, size_t buflen)
5528 u8 addr[ETH_ALEN], *addr_ptr;
5530 const struct p2p_peer_info *info;
5532 char devtype[WPS_DEV_TYPE_BUFSIZE];
5533 struct wpa_ssid *ssid;
5536 if (!wpa_s->global->p2p)
5539 if (os_strcmp(cmd, "FIRST") == 0) {
5542 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
5543 if (hwaddr_aton(cmd + 5, addr) < 0)
5548 if (hwaddr_aton(cmd, addr) < 0)
5554 info = p2p_get_peer_info(wpa_s->global->p2p, addr_ptr, next);
5561 res = os_snprintf(pos, end - pos, MACSTR "\n"
5567 "serial_number=%s\n"
5568 "config_methods=0x%x\n"
5570 "group_capab=0x%x\n"
5572 MAC2STR(info->p2p_device_addr),
5573 wps_dev_type_bin2str(info->pri_dev_type,
5574 devtype, sizeof(devtype)),
5579 info->serial_number,
5580 info->config_methods,
5584 if (os_snprintf_error(end - pos, res))
5588 for (i = 0; i < info->wps_sec_dev_type_list_len / WPS_DEV_TYPE_LEN; i++)
5591 t = &info->wps_sec_dev_type_list[i * WPS_DEV_TYPE_LEN];
5592 res = os_snprintf(pos, end - pos, "sec_dev_type=%s\n",
5593 wps_dev_type_bin2str(t, devtype,
5595 if (os_snprintf_error(end - pos, res))
5600 ssid = wpas_p2p_get_persistent(wpa_s, info->p2p_device_addr, NULL, 0);
5602 res = os_snprintf(pos, end - pos, "persistent=%d\n", ssid->id);
5603 if (os_snprintf_error(end - pos, res))
5608 res = p2p_get_peer_info_txt(info, pos, end - pos);
5613 if (info->vendor_elems) {
5614 res = os_snprintf(pos, end - pos, "vendor_elems=");
5615 if (os_snprintf_error(end - pos, res))
5619 pos += wpa_snprintf_hex(pos, end - pos,
5620 wpabuf_head(info->vendor_elems),
5621 wpabuf_len(info->vendor_elems));
5623 res = os_snprintf(pos, end - pos, "\n");
5624 if (os_snprintf_error(end - pos, res))
5633 static int p2p_ctrl_disallow_freq(struct wpa_supplicant *wpa_s,
5638 if (wpa_s->global->p2p == NULL)
5641 if (freq_range_list_parse(&wpa_s->global->p2p_disallow_freq, param) < 0)
5644 for (i = 0; i < wpa_s->global->p2p_disallow_freq.num; i++) {
5645 struct wpa_freq_range *freq;
5646 freq = &wpa_s->global->p2p_disallow_freq.range[i];
5647 wpa_printf(MSG_DEBUG, "P2P: Disallowed frequency range %u-%u",
5648 freq->min, freq->max);
5651 wpas_p2p_update_channel_list(wpa_s);
5656 static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd)
5660 if (wpa_s->global->p2p == NULL)
5663 param = os_strchr(cmd, ' ');
5668 if (os_strcmp(cmd, "discoverability") == 0) {
5669 p2p_set_client_discoverability(wpa_s->global->p2p,
5674 if (os_strcmp(cmd, "managed") == 0) {
5675 p2p_set_managed_oper(wpa_s->global->p2p, atoi(param));
5679 if (os_strcmp(cmd, "listen_channel") == 0) {
5680 return p2p_set_listen_channel(wpa_s->global->p2p, 81,
5684 if (os_strcmp(cmd, "ssid_postfix") == 0) {
5685 return p2p_set_ssid_postfix(wpa_s->global->p2p, (u8 *) param,
5689 if (os_strcmp(cmd, "noa") == 0) {
5691 int count, start, duration;
5692 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
5693 count = atoi(param);
5694 pos = os_strchr(param, ',');
5699 pos = os_strchr(pos, ',');
5703 duration = atoi(pos);
5704 if (count < 0 || count > 255 || start < 0 || duration < 0)
5706 if (count == 0 && duration > 0)
5708 wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
5709 "start=%d duration=%d", count, start, duration);
5710 return wpas_p2p_set_noa(wpa_s, count, start, duration);
5713 if (os_strcmp(cmd, "ps") == 0)
5714 return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1);
5716 if (os_strcmp(cmd, "oppps") == 0)
5717 return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1);
5719 if (os_strcmp(cmd, "ctwindow") == 0)
5720 return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param));
5722 if (os_strcmp(cmd, "disabled") == 0) {
5723 wpa_s->global->p2p_disabled = atoi(param);
5724 wpa_printf(MSG_DEBUG, "P2P functionality %s",
5725 wpa_s->global->p2p_disabled ?
5726 "disabled" : "enabled");
5727 if (wpa_s->global->p2p_disabled) {
5728 wpas_p2p_stop_find(wpa_s);
5729 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
5730 p2p_flush(wpa_s->global->p2p);
5735 if (os_strcmp(cmd, "conc_pref") == 0) {
5736 if (os_strcmp(param, "sta") == 0)
5737 wpa_s->global->conc_pref = WPA_CONC_PREF_STA;
5738 else if (os_strcmp(param, "p2p") == 0)
5739 wpa_s->global->conc_pref = WPA_CONC_PREF_P2P;
5741 wpa_printf(MSG_INFO, "Invalid conc_pref value");
5744 wpa_printf(MSG_DEBUG, "Single channel concurrency preference: "
5749 if (os_strcmp(cmd, "force_long_sd") == 0) {
5750 wpa_s->force_long_sd = atoi(param);
5754 if (os_strcmp(cmd, "peer_filter") == 0) {
5756 if (hwaddr_aton(param, addr))
5758 p2p_set_peer_filter(wpa_s->global->p2p, addr);
5762 if (os_strcmp(cmd, "cross_connect") == 0)
5763 return wpas_p2p_set_cross_connect(wpa_s, atoi(param));
5765 if (os_strcmp(cmd, "go_apsd") == 0) {
5766 if (os_strcmp(param, "disable") == 0)
5767 wpa_s->set_ap_uapsd = 0;
5769 wpa_s->set_ap_uapsd = 1;
5770 wpa_s->ap_uapsd = atoi(param);
5775 if (os_strcmp(cmd, "client_apsd") == 0) {
5776 if (os_strcmp(param, "disable") == 0)
5777 wpa_s->set_sta_uapsd = 0;
5781 /* format: BE,BK,VI,VO;max SP Length */
5783 pos = os_strchr(param, ',');
5788 pos = os_strchr(pos, ',');
5793 pos = os_strchr(pos, ',');
5798 /* ignore max SP Length for now */
5800 wpa_s->set_sta_uapsd = 1;
5801 wpa_s->sta_uapsd = 0;
5803 wpa_s->sta_uapsd |= BIT(0);
5805 wpa_s->sta_uapsd |= BIT(1);
5807 wpa_s->sta_uapsd |= BIT(2);
5809 wpa_s->sta_uapsd |= BIT(3);
5814 if (os_strcmp(cmd, "disallow_freq") == 0)
5815 return p2p_ctrl_disallow_freq(wpa_s, param);
5817 if (os_strcmp(cmd, "disc_int") == 0) {
5818 int min_disc_int, max_disc_int, max_disc_tu;
5823 min_disc_int = atoi(pos);
5824 pos = os_strchr(pos, ' ');
5829 max_disc_int = atoi(pos);
5830 pos = os_strchr(pos, ' ');
5835 max_disc_tu = atoi(pos);
5837 return p2p_set_disc_int(wpa_s->global->p2p, min_disc_int,
5838 max_disc_int, max_disc_tu);
5841 if (os_strcmp(cmd, "per_sta_psk") == 0) {
5842 wpa_s->global->p2p_per_sta_psk = !!atoi(param);
5846 #ifdef CONFIG_WPS_NFC
5847 if (os_strcmp(cmd, "nfc_tag") == 0)
5848 return wpas_p2p_nfc_tag_enabled(wpa_s, !!atoi(param));
5849 #endif /* CONFIG_WPS_NFC */
5851 if (os_strcmp(cmd, "disable_ip_addr_req") == 0) {
5852 wpa_s->p2p_disable_ip_addr_req = !!atoi(param);
5856 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
5863 static void p2p_ctrl_flush(struct wpa_supplicant *wpa_s)
5865 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
5866 wpa_s->force_long_sd = 0;
5867 wpas_p2p_stop_find(wpa_s);
5868 if (wpa_s->global->p2p)
5869 p2p_flush(wpa_s->global->p2p);
5873 static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd)
5876 unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0;
5879 pos = os_strchr(cmd, ' ');
5885 pos2 = os_strchr(pos, ' ');
5893 pos = os_strchr(pos2, ' ');
5901 return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2);
5905 static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd)
5908 unsigned int period = 0, interval = 0;
5911 pos = os_strchr(cmd, ' ');
5916 interval = atoi(pos);
5919 return wpas_p2p_ext_listen(wpa_s, period, interval);
5923 static int p2p_ctrl_remove_client(struct wpa_supplicant *wpa_s, const char *cmd)
5930 if (os_strncmp(pos, "iface=", 6) == 0) {
5934 if (hwaddr_aton(pos, peer))
5937 wpas_p2p_remove_client(wpa_s, peer, iface_addr);
5941 #endif /* CONFIG_P2P */
5944 static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s, char *val)
5946 struct wpa_freq_range_list ranges;
5948 struct hostapd_hw_modes *mode;
5951 if (wpa_s->hw.modes == NULL)
5954 os_memset(&ranges, 0, sizeof(ranges));
5955 if (freq_range_list_parse(&ranges, val) < 0)
5958 for (i = 0; i < wpa_s->hw.num_modes; i++) {
5961 mode = &wpa_s->hw.modes[i];
5962 for (j = 0; j < mode->num_channels; j++) {
5965 if (mode->channels[j].flag & HOSTAPD_CHAN_DISABLED)
5968 freq = mode->channels[j].freq;
5969 if (!freq_range_list_includes(&ranges, freq))
5972 int_array_add_unique(&freqs, freq);
5976 os_free(ranges.range);
5981 #ifdef CONFIG_INTERWORKING
5983 static int ctrl_interworking_select(struct wpa_supplicant *wpa_s, char *param)
5991 auto_sel = os_strstr(param, "auto") != NULL;
5993 pos = os_strstr(param, "freq=");
5995 freqs = freq_range_to_channel_list(wpa_s, pos + 5);
6002 return interworking_select(wpa_s, auto_sel, freqs);
6006 static int ctrl_interworking_connect(struct wpa_supplicant *wpa_s, char *dst,
6010 struct wpa_bss *bss;
6012 if (hwaddr_aton(dst, bssid)) {
6013 wpa_printf(MSG_DEBUG, "Invalid BSSID '%s'", dst);
6017 bss = wpa_bss_get_bssid(wpa_s, bssid);
6019 wpa_printf(MSG_DEBUG, "Could not find BSS " MACSTR,
6024 if (bss->ssid_len == 0) {
6027 wpa_printf(MSG_DEBUG, "Selected BSS entry for " MACSTR
6028 " does not have SSID information", MAC2STR(bssid));
6030 dl_list_for_each_reverse(bss, &wpa_s->bss, struct wpa_bss,
6032 if (os_memcmp(bss->bssid, bssid, ETH_ALEN) == 0 &&
6033 bss->ssid_len > 0) {
6041 wpa_printf(MSG_DEBUG,
6042 "Found another matching BSS entry with SSID");
6045 return interworking_connect(wpa_s, bss, only_add);
6049 static int get_anqp(struct wpa_supplicant *wpa_s, char *dst)
6051 u8 dst_addr[ETH_ALEN];
6054 #define MAX_ANQP_INFO_ID 100
6055 u16 id[MAX_ANQP_INFO_ID];
6059 used = hwaddr_aton2(dst, dst_addr);
6065 while (num_id < MAX_ANQP_INFO_ID) {
6066 if (os_strncmp(pos, "hs20:", 5) == 0) {
6068 int num = atoi(pos + 5);
6069 if (num <= 0 || num > 31)
6071 subtypes |= BIT(num);
6072 #else /* CONFIG_HS20 */
6074 #endif /* CONFIG_HS20 */
6076 id[num_id] = atoi(pos);
6080 pos = os_strchr(pos + 1, ',');
6089 return anqp_send_req(wpa_s, dst_addr, id, num_id, subtypes);
6093 static int gas_request(struct wpa_supplicant *wpa_s, char *cmd)
6095 u8 dst_addr[ETH_ALEN];
6096 struct wpabuf *advproto, *query = NULL;
6101 used = hwaddr_aton2(cmd, dst_addr);
6109 /* Advertisement Protocol ID */
6110 end = os_strchr(pos, ' ');
6114 len = os_strlen(pos);
6120 advproto = wpabuf_alloc(len);
6121 if (advproto == NULL)
6123 if (hexstr2bin(pos, wpabuf_put(advproto, len), len) < 0)
6127 /* Optional Query Request */
6132 len = os_strlen(pos);
6139 query = wpabuf_alloc(len);
6142 if (hexstr2bin(pos, wpabuf_put(query, len), len) < 0)
6147 ret = gas_send_request(wpa_s, dst_addr, advproto, query);
6150 wpabuf_free(advproto);
6157 static int gas_response_get(struct wpa_supplicant *wpa_s, char *cmd, char *buf,
6164 size_t resp_len, start, requested_len;
6165 struct wpabuf *resp;
6168 used = hwaddr_aton2(cmd, addr);
6175 dialog_token = atoi(pos);
6177 if (wpa_s->last_gas_resp &&
6178 os_memcmp(addr, wpa_s->last_gas_addr, ETH_ALEN) == 0 &&
6179 dialog_token == wpa_s->last_gas_dialog_token)
6180 resp = wpa_s->last_gas_resp;
6181 else if (wpa_s->prev_gas_resp &&
6182 os_memcmp(addr, wpa_s->prev_gas_addr, ETH_ALEN) == 0 &&
6183 dialog_token == wpa_s->prev_gas_dialog_token)
6184 resp = wpa_s->prev_gas_resp;
6188 resp_len = wpabuf_len(resp);
6190 requested_len = resp_len;
6192 pos = os_strchr(pos, ' ');
6195 if (start > resp_len)
6196 return os_snprintf(buf, buflen, "FAIL-Invalid range");
6197 pos = os_strchr(pos, ',');
6201 requested_len = atoi(pos);
6202 if (start + requested_len > resp_len)
6203 return os_snprintf(buf, buflen, "FAIL-Invalid range");
6206 if (requested_len * 2 + 1 > buflen)
6207 return os_snprintf(buf, buflen, "FAIL-Too long response");
6209 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(resp) + start,
6212 if (start + requested_len == resp_len) {
6214 * Free memory by dropping the response after it has been
6217 if (resp == wpa_s->prev_gas_resp) {
6218 wpabuf_free(wpa_s->prev_gas_resp);
6219 wpa_s->prev_gas_resp = NULL;
6221 wpabuf_free(wpa_s->last_gas_resp);
6222 wpa_s->last_gas_resp = NULL;
6228 #endif /* CONFIG_INTERWORKING */
6233 static int get_hs20_anqp(struct wpa_supplicant *wpa_s, char *dst)
6235 u8 dst_addr[ETH_ALEN];
6240 used = hwaddr_aton2(dst, dst_addr);
6247 int num = atoi(pos);
6248 if (num <= 0 || num > 31)
6250 subtypes |= BIT(num);
6251 pos = os_strchr(pos + 1, ',');
6260 return hs20_anqp_send_req(wpa_s, dst_addr, subtypes, NULL, 0);
6264 static int hs20_nai_home_realm_list(struct wpa_supplicant *wpa_s,
6265 const u8 *addr, const char *realm)
6271 rlen = os_strlen(realm);
6273 buf = os_malloc(len);
6276 buf[0] = 1; /* NAI Home Realm Count */
6277 buf[1] = 0; /* Formatted in accordance with RFC 4282 */
6279 os_memcpy(buf + 3, realm, rlen);
6281 ret = hs20_anqp_send_req(wpa_s, addr,
6282 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
6291 static int hs20_get_nai_home_realm_list(struct wpa_supplicant *wpa_s,
6294 struct wpa_cred *cred = wpa_s->conf->cred;
6295 u8 dst_addr[ETH_ALEN];
6301 used = hwaddr_aton2(dst, dst_addr);
6305 while (dst[used] == ' ')
6307 if (os_strncmp(dst + used, "realm=", 6) == 0)
6308 return hs20_nai_home_realm_list(wpa_s, dst_addr,
6311 len = os_strlen(dst + used);
6313 if (len == 0 && cred && cred->realm)
6314 return hs20_nai_home_realm_list(wpa_s, dst_addr, cred->realm);
6319 buf = os_malloc(len);
6322 if (hexstr2bin(dst + used, buf, len) < 0) {
6327 ret = hs20_anqp_send_req(wpa_s, dst_addr,
6328 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
6336 static int hs20_icon_request(struct wpa_supplicant *wpa_s, char *cmd)
6338 u8 dst_addr[ETH_ALEN];
6342 used = hwaddr_aton2(cmd, dst_addr);
6346 while (cmd[used] == ' ')
6350 wpa_s->fetch_osu_icon_in_progress = 0;
6351 return hs20_anqp_send_req(wpa_s, dst_addr, BIT(HS20_STYPE_ICON_REQUEST),
6352 (u8 *) icon, os_strlen(icon));
6355 #endif /* CONFIG_HS20 */
6358 #ifdef CONFIG_AUTOSCAN
6360 static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant *wpa_s,
6363 enum wpa_states state = wpa_s->wpa_state;
6364 char *new_params = NULL;
6366 if (os_strlen(cmd) > 0) {
6367 new_params = os_strdup(cmd);
6368 if (new_params == NULL)
6372 os_free(wpa_s->conf->autoscan);
6373 wpa_s->conf->autoscan = new_params;
6375 if (wpa_s->conf->autoscan == NULL)
6376 autoscan_deinit(wpa_s);
6377 else if (state == WPA_DISCONNECTED || state == WPA_INACTIVE)
6378 autoscan_init(wpa_s, 1);
6379 else if (state == WPA_SCANNING)
6380 wpa_supplicant_reinit_autoscan(wpa_s);
6385 #endif /* CONFIG_AUTOSCAN */
6390 static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant *wpa_s, char *cmd)
6396 struct wpabuf *tfs_req = NULL;
6398 if (os_strncmp(cmd, "enter", 5) == 0)
6400 else if (os_strncmp(cmd, "exit", 4) == 0)
6405 pos = os_strstr(cmd, " interval=");
6407 intval = atoi(pos + 10);
6409 pos = os_strstr(cmd, " tfs_req=");
6414 end = os_strchr(pos, ' ');
6418 len = os_strlen(pos);
6422 tfs_req = wpabuf_alloc(len);
6423 if (tfs_req == NULL)
6425 if (hexstr2bin(pos, wpabuf_put(tfs_req, len), len) < 0) {
6426 wpabuf_free(tfs_req);
6431 ret = ieee802_11_send_wnmsleep_req(wpa_s, enter ? WNM_SLEEP_MODE_ENTER :
6432 WNM_SLEEP_MODE_EXIT, intval,
6434 wpabuf_free(tfs_req);
6440 static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant *wpa_s, char *cmd)
6444 query_reason = atoi(cmd);
6446 wpa_printf(MSG_DEBUG, "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d",
6449 return wnm_send_bss_transition_mgmt_query(wpa_s, query_reason);
6452 #endif /* CONFIG_WNM */
6455 static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf,
6458 struct wpa_signal_info si;
6462 ret = wpa_drv_signal_poll(wpa_s, &si);
6469 ret = os_snprintf(pos, end - pos, "RSSI=%d\nLINKSPEED=%d\n"
6470 "NOISE=%d\nFREQUENCY=%u\n",
6471 si.current_signal, si.current_txrate / 1000,
6472 si.current_noise, si.frequency);
6473 if (os_snprintf_error(end - pos, ret))
6477 if (si.chanwidth != CHAN_WIDTH_UNKNOWN) {
6478 ret = os_snprintf(pos, end - pos, "WIDTH=%s\n",
6479 channel_width_to_string(si.chanwidth));
6480 if (os_snprintf_error(end - pos, ret))
6485 if (si.center_frq1 > 0 && si.center_frq2 > 0) {
6486 ret = os_snprintf(pos, end - pos,
6487 "CENTER_FRQ1=%d\nCENTER_FRQ2=%d\n",
6488 si.center_frq1, si.center_frq2);
6489 if (os_snprintf_error(end - pos, ret))
6494 if (si.avg_signal) {
6495 ret = os_snprintf(pos, end - pos,
6496 "AVG_RSSI=%d\n", si.avg_signal);
6497 if (os_snprintf_error(end - pos, ret))
6502 if (si.avg_beacon_signal) {
6503 ret = os_snprintf(pos, end - pos,
6504 "AVG_BEACON_RSSI=%d\n", si.avg_beacon_signal);
6505 if (os_snprintf_error(end - pos, ret))
6514 static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant *wpa_s, char *buf,
6517 struct hostap_sta_driver_data sta;
6520 ret = wpa_drv_pktcnt_poll(wpa_s, &sta);
6524 ret = os_snprintf(buf, buflen, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
6525 sta.tx_packets, sta.tx_retry_failed, sta.rx_packets);
6526 if (os_snprintf_error(buflen, ret))
6533 static int wpa_supplicant_driver_cmd(struct wpa_supplicant *wpa_s, char *cmd,
6534 char *buf, size_t buflen)
6538 ret = wpa_drv_driver_cmd(wpa_s, cmd, buf, buflen);
6540 if (os_strncasecmp(cmd, "COUNTRY", 7) == 0) {
6541 struct p2p_data *p2p = wpa_s->global->p2p;
6544 country[0] = cmd[8];
6545 country[1] = cmd[9];
6547 p2p_set_country(p2p, country);
6550 ret = os_snprintf(buf, buflen, "%s\n", "OK");
6551 if (os_snprintf_error(buflen, ret))
6556 #endif /* ANDROID */
6559 static int wpa_supplicant_vendor_cmd(struct wpa_supplicant *wpa_s, char *cmd,
6560 char *buf, size_t buflen)
6565 unsigned int vendor_id, subcmd;
6566 struct wpabuf *reply;
6567 size_t data_len = 0;
6569 /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */
6570 vendor_id = strtoul(cmd, &pos, 16);
6574 subcmd = strtoul(pos, &pos, 10);
6577 if (!isblank(*pos++))
6579 data_len = os_strlen(pos);
6584 data = os_malloc(data_len);
6588 if (hexstr2bin(pos, data, data_len)) {
6589 wpa_printf(MSG_DEBUG,
6590 "Vendor command: wrong parameter format");
6596 reply = wpabuf_alloc((buflen - 1) / 2);
6602 ret = wpa_drv_vendor_cmd(wpa_s, vendor_id, subcmd, data, data_len,
6606 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(reply),
6616 static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s)
6619 struct wpa_supplicant *p2p_wpa_s = wpa_s->global->p2p_init_wpa_s ?
6620 wpa_s->global->p2p_init_wpa_s : wpa_s;
6621 #endif /* CONFIG_P2P */
6623 wpa_dbg(wpa_s, MSG_DEBUG, "Flush all wpa_supplicant state");
6626 wpas_p2p_cancel(p2p_wpa_s);
6627 p2p_ctrl_flush(p2p_wpa_s);
6628 wpas_p2p_group_remove(p2p_wpa_s, "*");
6629 wpas_p2p_service_flush(p2p_wpa_s);
6630 p2p_wpa_s->global->p2p_disabled = 0;
6631 p2p_wpa_s->global->p2p_per_sta_psk = 0;
6632 p2p_wpa_s->conf->num_sec_device_types = 0;
6633 p2p_wpa_s->p2p_disable_ip_addr_req = 0;
6634 os_free(p2p_wpa_s->global->p2p_go_avoid_freq.range);
6635 p2p_wpa_s->global->p2p_go_avoid_freq.range = NULL;
6636 p2p_wpa_s->global->pending_p2ps_group = 0;
6637 #endif /* CONFIG_P2P */
6639 #ifdef CONFIG_WPS_TESTING
6640 wps_version_number = 0x20;
6641 wps_testing_dummy_cred = 0;
6642 wps_corrupt_pkhash = 0;
6643 #endif /* CONFIG_WPS_TESTING */
6645 wpa_s->wps_fragment_size = 0;
6646 wpas_wps_cancel(wpa_s);
6647 wps_registrar_flush(wpa_s->wps->registrar);
6648 #endif /* CONFIG_WPS */
6649 wpa_s->after_wps = 0;
6650 wpa_s->known_wps_freq = 0;
6653 #ifdef CONFIG_TDLS_TESTING
6654 extern unsigned int tdls_testing;
6656 #endif /* CONFIG_TDLS_TESTING */
6657 wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL);
6658 wpa_tdls_enable(wpa_s->wpa, 1);
6659 #endif /* CONFIG_TDLS */
6661 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, wpa_s, NULL);
6662 wpa_supplicant_stop_countermeasures(wpa_s, NULL);
6664 wpa_s->no_keep_alive = 0;
6665 wpa_s->own_disconnect_req = 0;
6667 os_free(wpa_s->disallow_aps_bssid);
6668 wpa_s->disallow_aps_bssid = NULL;
6669 wpa_s->disallow_aps_bssid_count = 0;
6670 os_free(wpa_s->disallow_aps_ssid);
6671 wpa_s->disallow_aps_ssid = NULL;
6672 wpa_s->disallow_aps_ssid_count = 0;
6674 wpa_s->set_sta_uapsd = 0;
6675 wpa_s->sta_uapsd = 0;
6677 wpa_drv_radio_disable(wpa_s, 0);
6678 wpa_blacklist_clear(wpa_s);
6679 wpa_s->extra_blacklist_count = 0;
6680 wpa_supplicant_ctrl_iface_remove_network(wpa_s, "all");
6681 wpa_supplicant_ctrl_iface_remove_cred(wpa_s, "all");
6682 wpa_config_flush_blobs(wpa_s->conf);
6683 wpa_s->conf->auto_interworking = 0;
6684 wpa_s->conf->okc = 0;
6686 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
6687 rsn_preauth_deinit(wpa_s->wpa);
6689 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, 43200);
6690 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, 70);
6691 wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, 60);
6692 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
6694 radio_remove_works(wpa_s, NULL, 1);
6695 wpa_s->ext_work_in_progress = 0;
6697 wpa_s->next_ssid = NULL;
6699 #ifdef CONFIG_INTERWORKING
6700 hs20_cancel_fetch_osu(wpa_s);
6701 #endif /* CONFIG_INTERWORKING */
6703 wpa_s->ext_mgmt_frame_handling = 0;
6704 wpa_s->ext_eapol_frame_io = 0;
6705 #ifdef CONFIG_TESTING_OPTIONS
6706 wpa_s->extra_roc_dur = 0;
6707 wpa_s->test_failure = WPAS_TEST_FAILURE_NONE;
6708 #endif /* CONFIG_TESTING_OPTIONS */
6710 wpa_s->disconnected = 0;
6711 os_free(wpa_s->next_scan_freqs);
6712 wpa_s->next_scan_freqs = NULL;
6714 wpa_bss_flush(wpa_s);
6715 if (!dl_list_empty(&wpa_s->bss)) {
6716 wpa_printf(MSG_DEBUG,
6717 "BSS table not empty after flush: %u entries, current_bss=%p bssid="
6718 MACSTR " pending_bssid=" MACSTR,
6719 dl_list_len(&wpa_s->bss), wpa_s->current_bss,
6720 MAC2STR(wpa_s->bssid),
6721 MAC2STR(wpa_s->pending_bssid));
6724 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
6728 static int wpas_ctrl_radio_work_show(struct wpa_supplicant *wpa_s,
6729 char *buf, size_t buflen)
6731 struct wpa_radio_work *work;
6733 struct os_reltime now, diff;
6738 os_get_reltime(&now);
6740 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
6744 os_reltime_sub(&now, &work->time, &diff);
6745 ret = os_snprintf(pos, end - pos, "%s@%s:%u:%u:%ld.%06ld\n",
6746 work->type, work->wpa_s->ifname, work->freq,
6747 work->started, diff.sec, diff.usec);
6748 if (os_snprintf_error(end - pos, ret))
6757 static void wpas_ctrl_radio_work_timeout(void *eloop_ctx, void *timeout_ctx)
6759 struct wpa_radio_work *work = eloop_ctx;
6760 struct wpa_external_work *ework = work->ctx;
6762 wpa_dbg(work->wpa_s, MSG_DEBUG,
6763 "Timing out external radio work %u (%s)",
6764 ework->id, work->type);
6765 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_TIMEOUT "%u", ework->id);
6766 work->wpa_s->ext_work_in_progress = 0;
6767 radio_work_done(work);
6772 static void wpas_ctrl_radio_work_cb(struct wpa_radio_work *work, int deinit)
6774 struct wpa_external_work *ework = work->ctx;
6778 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
6785 wpa_dbg(work->wpa_s, MSG_DEBUG, "Starting external radio work %u (%s)",
6786 ework->id, ework->type);
6787 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_START "%u", ework->id);
6788 work->wpa_s->ext_work_in_progress = 1;
6789 if (!ework->timeout)
6790 ework->timeout = 10;
6791 eloop_register_timeout(ework->timeout, 0, wpas_ctrl_radio_work_timeout,
6796 static int wpas_ctrl_radio_work_add(struct wpa_supplicant *wpa_s, char *cmd,
6797 char *buf, size_t buflen)
6799 struct wpa_external_work *ework;
6803 unsigned int freq = 0;
6805 /* format: <name> [freq=<MHz>] [timeout=<seconds>] */
6807 ework = os_zalloc(sizeof(*ework));
6811 pos = os_strchr(cmd, ' ');
6813 type_len = pos - cmd;
6816 pos2 = os_strstr(pos, "freq=");
6818 freq = atoi(pos2 + 5);
6820 pos2 = os_strstr(pos, "timeout=");
6822 ework->timeout = atoi(pos2 + 8);
6824 type_len = os_strlen(cmd);
6826 if (4 + type_len >= sizeof(ework->type))
6827 type_len = sizeof(ework->type) - 4 - 1;
6828 os_strlcpy(ework->type, "ext:", sizeof(ework->type));
6829 os_memcpy(ework->type + 4, cmd, type_len);
6830 ework->type[4 + type_len] = '\0';
6832 wpa_s->ext_work_id++;
6833 if (wpa_s->ext_work_id == 0)
6834 wpa_s->ext_work_id++;
6835 ework->id = wpa_s->ext_work_id;
6837 if (radio_add_work(wpa_s, freq, ework->type, 0, wpas_ctrl_radio_work_cb,
6843 ret = os_snprintf(buf, buflen, "%u", ework->id);
6844 if (os_snprintf_error(buflen, ret))
6850 static int wpas_ctrl_radio_work_done(struct wpa_supplicant *wpa_s, char *cmd)
6852 struct wpa_radio_work *work;
6853 unsigned int id = atoi(cmd);
6855 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
6857 struct wpa_external_work *ework;
6859 if (os_strncmp(work->type, "ext:", 4) != 0)
6862 if (id && ework->id != id)
6864 wpa_dbg(wpa_s, MSG_DEBUG,
6865 "Completed external radio work %u (%s)",
6866 ework->id, ework->type);
6867 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, work, NULL);
6868 wpa_s->ext_work_in_progress = 0;
6869 radio_work_done(work);
6871 return 3; /* "OK\n" */
6878 static int wpas_ctrl_radio_work(struct wpa_supplicant *wpa_s, char *cmd,
6879 char *buf, size_t buflen)
6881 if (os_strcmp(cmd, "show") == 0)
6882 return wpas_ctrl_radio_work_show(wpa_s, buf, buflen);
6883 if (os_strncmp(cmd, "add ", 4) == 0)
6884 return wpas_ctrl_radio_work_add(wpa_s, cmd + 4, buf, buflen);
6885 if (os_strncmp(cmd, "done ", 5) == 0)
6886 return wpas_ctrl_radio_work_done(wpa_s, cmd + 4);
6891 void wpas_ctrl_radio_work_flush(struct wpa_supplicant *wpa_s)
6893 struct wpa_radio_work *work, *tmp;
6895 if (!wpa_s || !wpa_s->radio)
6898 dl_list_for_each_safe(work, tmp, &wpa_s->radio->work,
6899 struct wpa_radio_work, list) {
6900 struct wpa_external_work *ework;
6902 if (os_strncmp(work->type, "ext:", 4) != 0)
6905 wpa_dbg(wpa_s, MSG_DEBUG,
6906 "Flushing%s external radio work %u (%s)",
6907 work->started ? " started" : "", ework->id,
6910 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
6912 radio_work_done(work);
6918 static void wpas_ctrl_eapol_response(void *eloop_ctx, void *timeout_ctx)
6920 struct wpa_supplicant *wpa_s = eloop_ctx;
6921 eapol_sm_notify_ctrl_response(wpa_s->eapol);
6925 static int scan_id_list_parse(struct wpa_supplicant *wpa_s, const char *value,
6926 unsigned int *scan_id_count, int scan_id[])
6928 const char *pos = value;
6931 if (*pos == ' ' || *pos == '\0')
6933 if (*scan_id_count == MAX_SCAN_ID)
6935 scan_id[(*scan_id_count)++] = atoi(pos);
6936 pos = os_strchr(pos, ',');
6945 static void wpas_ctrl_scan(struct wpa_supplicant *wpa_s, char *params,
6946 char *reply, int reply_size, int *reply_len)
6949 unsigned int manual_scan_passive = 0;
6950 unsigned int manual_scan_use_id = 0;
6951 unsigned int manual_scan_only_new = 0;
6952 unsigned int scan_only = 0;
6953 unsigned int scan_id_count = 0;
6954 int scan_id[MAX_SCAN_ID];
6955 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
6956 struct wpa_scan_results *scan_res);
6957 int *manual_scan_freqs = NULL;
6959 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
6964 if (radio_work_pending(wpa_s, "scan")) {
6965 wpa_printf(MSG_DEBUG,
6966 "Pending scan scheduled - reject new request");
6967 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
6971 #ifdef CONFIG_INTERWORKING
6972 if (wpa_s->fetch_anqp_in_progress || wpa_s->network_select) {
6973 wpa_printf(MSG_DEBUG,
6974 "Interworking select in progress - reject new scan");
6975 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
6978 #endif /* CONFIG_INTERWORKING */
6981 if (os_strncasecmp(params, "TYPE=ONLY", 9) == 0)
6984 pos = os_strstr(params, "freq=");
6986 manual_scan_freqs = freq_range_to_channel_list(wpa_s,
6988 if (manual_scan_freqs == NULL) {
6994 pos = os_strstr(params, "passive=");
6996 manual_scan_passive = !!atoi(pos + 8);
6998 pos = os_strstr(params, "use_id=");
7000 manual_scan_use_id = atoi(pos + 7);
7002 pos = os_strstr(params, "only_new=1");
7004 manual_scan_only_new = 1;
7006 pos = os_strstr(params, "scan_id=");
7007 if (pos && scan_id_list_parse(wpa_s, pos + 8, &scan_id_count,
7015 scan_res_handler = scan_only_handler;
7016 else if (wpa_s->scan_res_handler == scan_only_handler)
7017 scan_res_handler = NULL;
7019 scan_res_handler = wpa_s->scan_res_handler;
7021 if (!wpa_s->sched_scanning && !wpa_s->scanning &&
7022 ((wpa_s->wpa_state <= WPA_SCANNING) ||
7023 (wpa_s->wpa_state == WPA_COMPLETED))) {
7024 wpa_s->manual_scan_passive = manual_scan_passive;
7025 wpa_s->manual_scan_use_id = manual_scan_use_id;
7026 wpa_s->manual_scan_only_new = manual_scan_only_new;
7027 wpa_s->scan_id_count = scan_id_count;
7028 os_memcpy(wpa_s->scan_id, scan_id, scan_id_count * sizeof(int));
7029 wpa_s->scan_res_handler = scan_res_handler;
7030 os_free(wpa_s->manual_scan_freqs);
7031 wpa_s->manual_scan_freqs = manual_scan_freqs;
7032 manual_scan_freqs = NULL;
7034 wpa_s->normal_scans = 0;
7035 wpa_s->scan_req = MANUAL_SCAN_REQ;
7036 wpa_s->after_wps = 0;
7037 wpa_s->known_wps_freq = 0;
7038 wpa_supplicant_req_scan(wpa_s, 0, 0);
7039 if (wpa_s->manual_scan_use_id) {
7040 wpa_s->manual_scan_id++;
7041 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
7042 wpa_s->manual_scan_id);
7043 *reply_len = os_snprintf(reply, reply_size, "%u\n",
7044 wpa_s->manual_scan_id);
7046 } else if (wpa_s->sched_scanning) {
7047 wpa_s->manual_scan_passive = manual_scan_passive;
7048 wpa_s->manual_scan_use_id = manual_scan_use_id;
7049 wpa_s->manual_scan_only_new = manual_scan_only_new;
7050 wpa_s->scan_id_count = scan_id_count;
7051 os_memcpy(wpa_s->scan_id, scan_id, scan_id_count * sizeof(int));
7052 wpa_s->scan_res_handler = scan_res_handler;
7053 os_free(wpa_s->manual_scan_freqs);
7054 wpa_s->manual_scan_freqs = manual_scan_freqs;
7055 manual_scan_freqs = NULL;
7057 wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to allow requested full scan to proceed");
7058 wpa_supplicant_cancel_sched_scan(wpa_s);
7059 wpa_s->scan_req = MANUAL_SCAN_REQ;
7060 wpa_supplicant_req_scan(wpa_s, 0, 0);
7061 if (wpa_s->manual_scan_use_id) {
7062 wpa_s->manual_scan_id++;
7063 *reply_len = os_snprintf(reply, reply_size, "%u\n",
7064 wpa_s->manual_scan_id);
7065 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
7066 wpa_s->manual_scan_id);
7069 wpa_printf(MSG_DEBUG, "Ongoing scan action - reject new request");
7070 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
7074 os_free(manual_scan_freqs);
7078 #ifdef CONFIG_TESTING_OPTIONS
7080 static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant *wpa_s,
7081 unsigned int freq, const u8 *dst,
7082 const u8 *src, const u8 *bssid,
7083 const u8 *data, size_t data_len,
7084 enum offchannel_send_action_result
7087 wpa_msg(wpa_s, MSG_INFO, "MGMT-TX-STATUS freq=%u dst=" MACSTR
7088 " src=" MACSTR " bssid=" MACSTR " result=%s",
7089 freq, MAC2STR(dst), MAC2STR(src), MAC2STR(bssid),
7090 result == OFFCHANNEL_SEND_ACTION_SUCCESS ?
7091 "SUCCESS" : (result == OFFCHANNEL_SEND_ACTION_NO_ACK ?
7092 "NO_ACK" : "FAILED"));
7096 static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant *wpa_s, char *cmd)
7100 u8 *buf, da[ETH_ALEN], bssid[ETH_ALEN];
7102 int freq = 0, no_cck = 0, wait_time = 0;
7104 /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1]
7105 * <action=Action frame payload> */
7107 wpa_printf(MSG_DEBUG, "External MGMT TX: %s", cmd);
7110 used = hwaddr_aton2(pos, da);
7116 used = hwaddr_aton2(pos, bssid);
7121 param = os_strstr(pos, " freq=");
7127 param = os_strstr(pos, " no_cck=");
7130 no_cck = atoi(param);
7133 param = os_strstr(pos, " wait_time=");
7136 wait_time = atoi(param);
7139 param = os_strstr(pos, " action=");
7144 len = os_strlen(param);
7149 buf = os_malloc(len);
7153 if (hexstr2bin(param, buf, len) < 0) {
7158 res = offchannel_send_action(wpa_s, freq, da, wpa_s->own_addr, bssid,
7159 buf, len, wait_time,
7160 wpas_ctrl_iface_mgmt_tx_cb, no_cck);
7166 static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant *wpa_s)
7168 wpa_printf(MSG_DEBUG, "External MGMT TX - done waiting");
7169 offchannel_send_action_done(wpa_s);
7173 static int wpas_ctrl_iface_driver_event(struct wpa_supplicant *wpa_s, char *cmd)
7176 union wpa_event_data event;
7177 enum wpa_event_type ev;
7179 /* <event name> [parameters..] */
7181 wpa_dbg(wpa_s, MSG_DEBUG, "Testing - external driver event: %s", cmd);
7184 param = os_strchr(pos, ' ');
7188 os_memset(&event, 0, sizeof(event));
7190 if (os_strcmp(cmd, "INTERFACE_ENABLED") == 0) {
7191 ev = EVENT_INTERFACE_ENABLED;
7192 } else if (os_strcmp(cmd, "INTERFACE_DISABLED") == 0) {
7193 ev = EVENT_INTERFACE_DISABLED;
7194 } else if (os_strcmp(cmd, "AVOID_FREQUENCIES") == 0) {
7195 ev = EVENT_AVOID_FREQUENCIES;
7198 if (freq_range_list_parse(&event.freq_range, param) < 0)
7200 wpa_supplicant_event(wpa_s, ev, &event);
7201 os_free(event.freq_range.range);
7204 wpa_dbg(wpa_s, MSG_DEBUG, "Testing - unknown driver event: %s",
7209 wpa_supplicant_event(wpa_s, ev, &event);
7215 static int wpas_ctrl_iface_eapol_rx(struct wpa_supplicant *wpa_s, char *cmd)
7218 u8 src[ETH_ALEN], *buf;
7222 wpa_printf(MSG_DEBUG, "External EAPOL RX: %s", cmd);
7225 used = hwaddr_aton2(pos, src);
7232 len = os_strlen(pos);
7237 buf = os_malloc(len);
7241 if (hexstr2bin(pos, buf, len) < 0) {
7246 wpa_supplicant_rx_eapol(wpa_s, src, buf, len);
7253 static u16 ipv4_hdr_checksum(const void *buf, size_t len)
7257 const u16 *pos = buf;
7259 for (i = 0; i < len / 2; i++)
7263 sum = (sum & 0xffff) + (sum >> 16);
7265 return sum ^ 0xffff;
7269 #define HWSIM_PACKETLEN 1500
7270 #define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header))
7272 void wpas_data_test_rx(void *ctx, const u8 *src_addr, const u8 *buf, size_t len)
7274 struct wpa_supplicant *wpa_s = ctx;
7275 const struct ether_header *eth;
7276 const struct iphdr *ip;
7280 if (len != HWSIM_PACKETLEN)
7283 eth = (const struct ether_header *) buf;
7284 ip = (const struct iphdr *) (eth + 1);
7285 pos = (const u8 *) (ip + 1);
7287 if (ip->ihl != 5 || ip->version != 4 ||
7288 ntohs(ip->tot_len) != HWSIM_IP_LEN)
7291 for (i = 0; i < HWSIM_IP_LEN - sizeof(*ip); i++) {
7297 wpa_msg(wpa_s, MSG_INFO, "DATA-TEST-RX " MACSTR " " MACSTR,
7298 MAC2STR(eth->ether_dhost), MAC2STR(eth->ether_shost));
7302 static int wpas_ctrl_iface_data_test_config(struct wpa_supplicant *wpa_s,
7305 int enabled = atoi(cmd);
7308 if (wpa_s->l2_test) {
7309 l2_packet_deinit(wpa_s->l2_test);
7310 wpa_s->l2_test = NULL;
7311 wpa_dbg(wpa_s, MSG_DEBUG, "test data: Disabled");
7319 wpa_s->l2_test = l2_packet_init(wpa_s->ifname, wpa_s->own_addr,
7320 ETHERTYPE_IP, wpas_data_test_rx,
7322 if (wpa_s->l2_test == NULL)
7325 wpa_dbg(wpa_s, MSG_DEBUG, "test data: Enabled");
7331 static int wpas_ctrl_iface_data_test_tx(struct wpa_supplicant *wpa_s, char *cmd)
7333 u8 dst[ETH_ALEN], src[ETH_ALEN];
7338 u8 buf[HWSIM_PACKETLEN];
7339 struct ether_header *eth;
7344 if (wpa_s->l2_test == NULL)
7347 /* format: <dst> <src> <tos> */
7350 used = hwaddr_aton2(pos, dst);
7356 used = hwaddr_aton2(pos, src);
7361 val = strtol(pos, NULL, 0);
7362 if (val < 0 || val > 0xff)
7366 eth = (struct ether_header *) buf;
7367 os_memcpy(eth->ether_dhost, dst, ETH_ALEN);
7368 os_memcpy(eth->ether_shost, src, ETH_ALEN);
7369 eth->ether_type = htons(ETHERTYPE_IP);
7370 ip = (struct iphdr *) (eth + 1);
7371 os_memset(ip, 0, sizeof(*ip));
7376 ip->tot_len = htons(HWSIM_IP_LEN);
7378 ip->saddr = htonl(192 << 24 | 168 << 16 | 1 << 8 | 1);
7379 ip->daddr = htonl(192 << 24 | 168 << 16 | 1 << 8 | 2);
7380 ip->check = ipv4_hdr_checksum(ip, sizeof(*ip));
7381 dpos = (u8 *) (ip + 1);
7382 for (i = 0; i < HWSIM_IP_LEN - sizeof(*ip); i++)
7385 if (l2_packet_send(wpa_s->l2_test, dst, ETHERTYPE_IP, buf,
7386 HWSIM_PACKETLEN) < 0)
7389 wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX dst=" MACSTR " src=" MACSTR
7390 " tos=0x%x", MAC2STR(dst), MAC2STR(src), tos);
7396 static int wpas_ctrl_iface_data_test_frame(struct wpa_supplicant *wpa_s,
7400 struct ether_header *eth;
7401 struct l2_packet_data *l2 = NULL;
7406 len = os_strlen(cmd);
7407 if (len & 1 || len < ETH_HLEN * 2)
7411 buf = os_malloc(len);
7415 if (hexstr2bin(cmd, buf, len) < 0)
7418 eth = (struct ether_header *) buf;
7419 ethertype = ntohs(eth->ether_type);
7421 l2 = l2_packet_init(wpa_s->ifname, wpa_s->own_addr, ethertype,
7422 wpas_data_test_rx, wpa_s, 1);
7426 res = l2_packet_send(l2, eth->ether_dhost, ethertype, buf, len);
7427 wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX frame res=%d", res);
7430 l2_packet_deinit(l2);
7433 return res < 0 ? -1 : 0;
7437 static int wpas_ctrl_test_alloc_fail(struct wpa_supplicant *wpa_s, char *cmd)
7439 #ifdef WPA_TRACE_BFD
7440 extern char wpa_trace_fail_func[256];
7441 extern unsigned int wpa_trace_fail_after;
7444 wpa_trace_fail_after = atoi(cmd);
7445 pos = os_strchr(cmd, ':');
7448 os_strlcpy(wpa_trace_fail_func, pos,
7449 sizeof(wpa_trace_fail_func));
7451 wpa_trace_fail_after = 0;
7454 #else /* WPA_TRACE_BFD */
7456 #endif /* WPA_TRACE_BFD */
7460 static int wpas_ctrl_get_alloc_fail(struct wpa_supplicant *wpa_s,
7461 char *buf, size_t buflen)
7463 #ifdef WPA_TRACE_BFD
7464 extern char wpa_trace_fail_func[256];
7465 extern unsigned int wpa_trace_fail_after;
7467 return os_snprintf(buf, buflen, "%u:%s", wpa_trace_fail_after,
7468 wpa_trace_fail_func);
7469 #else /* WPA_TRACE_BFD */
7471 #endif /* WPA_TRACE_BFD */
7474 #endif /* CONFIG_TESTING_OPTIONS */
7477 static void wpas_ctrl_vendor_elem_update(struct wpa_supplicant *wpa_s)
7482 wpa_printf(MSG_DEBUG, "Update vendor elements");
7484 for (i = 0; i < NUM_VENDOR_ELEM_FRAMES; i++) {
7485 if (wpa_s->vendor_elem[i]) {
7488 res = os_snprintf(buf, sizeof(buf), "frame[%u]", i);
7489 if (!os_snprintf_error(sizeof(buf), res)) {
7490 wpa_hexdump_buf(MSG_DEBUG, buf,
7491 wpa_s->vendor_elem[i]);
7497 if (wpa_s->parent == wpa_s &&
7498 wpa_s->global->p2p &&
7499 !wpa_s->global->p2p_disabled)
7500 p2p_set_vendor_elems(wpa_s->global->p2p, wpa_s->vendor_elem);
7501 #endif /* CONFIG_P2P */
7505 static struct wpa_supplicant *
7506 wpas_ctrl_vendor_elem_iface(struct wpa_supplicant *wpa_s,
7507 enum wpa_vendor_elem_frame frame)
7511 case VENDOR_ELEM_PROBE_REQ_P2P:
7512 case VENDOR_ELEM_PROBE_RESP_P2P:
7513 case VENDOR_ELEM_PROBE_RESP_P2P_GO:
7514 case VENDOR_ELEM_BEACON_P2P_GO:
7515 case VENDOR_ELEM_P2P_PD_REQ:
7516 case VENDOR_ELEM_P2P_PD_RESP:
7517 case VENDOR_ELEM_P2P_GO_NEG_REQ:
7518 case VENDOR_ELEM_P2P_GO_NEG_RESP:
7519 case VENDOR_ELEM_P2P_GO_NEG_CONF:
7520 case VENDOR_ELEM_P2P_INV_REQ:
7521 case VENDOR_ELEM_P2P_INV_RESP:
7522 case VENDOR_ELEM_P2P_ASSOC_REQ:
7523 return wpa_s->parent;
7524 #endif /* CONFIG_P2P */
7531 static int wpas_ctrl_vendor_elem_add(struct wpa_supplicant *wpa_s, char *cmd)
7537 struct ieee802_11_elems elems;
7540 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
7542 wpa_s = wpas_ctrl_vendor_elem_iface(wpa_s, frame);
7544 pos = os_strchr(pos, ' ');
7549 len = os_strlen(pos);
7556 buf = wpabuf_alloc(len);
7560 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
7565 if (ieee802_11_parse_elems(wpabuf_head_u8(buf), len, &elems, 0) ==
7571 if (wpa_s->vendor_elem[frame] == NULL) {
7572 wpa_s->vendor_elem[frame] = buf;
7573 wpas_ctrl_vendor_elem_update(wpa_s);
7577 if (wpabuf_resize(&wpa_s->vendor_elem[frame], len) < 0) {
7582 wpabuf_put_buf(wpa_s->vendor_elem[frame], buf);
7584 wpas_ctrl_vendor_elem_update(wpa_s);
7590 static int wpas_ctrl_vendor_elem_get(struct wpa_supplicant *wpa_s, char *cmd,
7591 char *buf, size_t buflen)
7593 int frame = atoi(cmd);
7595 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
7597 wpa_s = wpas_ctrl_vendor_elem_iface(wpa_s, frame);
7599 if (wpa_s->vendor_elem[frame] == NULL)
7602 return wpa_snprintf_hex(buf, buflen,
7603 wpabuf_head_u8(wpa_s->vendor_elem[frame]),
7604 wpabuf_len(wpa_s->vendor_elem[frame]));
7608 static int wpas_ctrl_vendor_elem_remove(struct wpa_supplicant *wpa_s, char *cmd)
7614 struct ieee802_11_elems elems;
7618 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
7620 wpa_s = wpas_ctrl_vendor_elem_iface(wpa_s, frame);
7622 pos = os_strchr(pos, ' ');
7628 wpabuf_free(wpa_s->vendor_elem[frame]);
7629 wpa_s->vendor_elem[frame] = NULL;
7630 wpas_ctrl_vendor_elem_update(wpa_s);
7634 if (wpa_s->vendor_elem[frame] == NULL)
7637 len = os_strlen(pos);
7644 buf = os_malloc(len);
7648 if (hexstr2bin(pos, buf, len) < 0) {
7653 if (ieee802_11_parse_elems(buf, len, &elems, 0) == ParseFailed) {
7658 ie = wpabuf_mhead_u8(wpa_s->vendor_elem[frame]);
7659 end = ie + wpabuf_len(wpa_s->vendor_elem[frame]);
7661 for (; ie + 1 < end; ie += 2 + ie[1]) {
7664 if (os_memcmp(ie, buf, len) != 0)
7667 if (wpabuf_len(wpa_s->vendor_elem[frame]) == len) {
7668 wpabuf_free(wpa_s->vendor_elem[frame]);
7669 wpa_s->vendor_elem[frame] = NULL;
7671 os_memmove(ie, ie + len,
7673 wpa_s->vendor_elem[frame]->used -= len;
7676 wpas_ctrl_vendor_elem_update(wpa_s);
7686 static void wpas_ctrl_neighbor_rep_cb(void *ctx, struct wpabuf *neighbor_rep)
7688 struct wpa_supplicant *wpa_s = ctx;
7691 wpa_msg_ctrl(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_RXED
7693 (unsigned int) wpabuf_len(neighbor_rep));
7694 wpabuf_free(neighbor_rep);
7696 wpa_msg_ctrl(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_FAILED);
7701 static int wpas_ctrl_iface_send_neigbor_rep(struct wpa_supplicant *wpa_s,
7704 struct wpa_ssid ssid;
7705 struct wpa_ssid *ssid_p = NULL;
7708 if (os_strncmp(cmd, " ssid=", 6) == 0) {
7709 ssid.ssid_len = os_strlen(cmd + 6);
7710 if (ssid.ssid_len > SSID_MAX_LEN)
7712 ssid.ssid = (u8 *) (cmd + 6);
7716 ret = wpas_rrm_send_neighbor_rep_request(wpa_s, ssid_p,
7717 wpas_ctrl_neighbor_rep_cb,
7724 static int wpas_ctrl_iface_erp_flush(struct wpa_supplicant *wpa_s)
7726 eapol_sm_erp_flush(wpa_s->eapol);
7731 static int wpas_ctrl_iface_mac_rand_scan(struct wpa_supplicant *wpa_s,
7734 char *token, *context = NULL;
7735 unsigned int enable = ~0, type = 0;
7736 u8 _addr[ETH_ALEN], _mask[ETH_ALEN];
7737 u8 *addr = NULL, *mask = NULL;
7739 while ((token = str_token(cmd, " ", &context))) {
7740 if (os_strcasecmp(token, "scan") == 0) {
7741 type |= MAC_ADDR_RAND_SCAN;
7742 } else if (os_strcasecmp(token, "sched") == 0) {
7743 type |= MAC_ADDR_RAND_SCHED_SCAN;
7744 } else if (os_strcasecmp(token, "pno") == 0) {
7745 type |= MAC_ADDR_RAND_PNO;
7746 } else if (os_strcasecmp(token, "all") == 0) {
7747 type = wpa_s->mac_addr_rand_supported;
7748 } else if (os_strncasecmp(token, "enable=", 7) == 0) {
7749 enable = atoi(token + 7);
7750 } else if (os_strncasecmp(token, "addr=", 5) == 0) {
7752 if (hwaddr_aton(token + 5, addr)) {
7753 wpa_printf(MSG_INFO,
7754 "CTRL: Invalid MAC address: %s",
7758 } else if (os_strncasecmp(token, "mask=", 5) == 0) {
7760 if (hwaddr_aton(token + 5, mask)) {
7761 wpa_printf(MSG_INFO,
7762 "CTRL: Invalid MAC address mask: %s",
7767 wpa_printf(MSG_INFO,
7768 "CTRL: Invalid MAC_RAND_SCAN parameter: %s",
7775 wpa_printf(MSG_INFO, "CTRL: MAC_RAND_SCAN no type specified");
7779 if ((wpa_s->mac_addr_rand_supported & type) != type) {
7780 wpa_printf(MSG_INFO,
7781 "CTRL: MAC_RAND_SCAN types=%u != supported=%u",
7782 type, wpa_s->mac_addr_rand_supported);
7787 wpa_printf(MSG_INFO,
7788 "CTRL: MAC_RAND_SCAN enable=<0/1> not specified");
7793 wpas_mac_addr_rand_scan_clear(wpa_s, type);
7795 if (type & MAC_ADDR_RAND_PNO) {
7796 wpas_stop_pno(wpa_s);
7797 wpas_start_pno(wpa_s);
7799 } else if (wpa_s->sched_scanning &&
7800 (type & MAC_ADDR_RAND_SCHED_SCAN)) {
7801 /* simulate timeout to restart the sched scan */
7802 wpa_s->sched_scan_timed_out = 1;
7803 wpa_s->prev_sched_ssid = NULL;
7804 wpa_supplicant_cancel_sched_scan(wpa_s);
7809 if ((addr && !mask) || (!addr && mask)) {
7810 wpa_printf(MSG_INFO,
7811 "CTRL: MAC_RAND_SCAN invalid addr/mask combination");
7815 if (addr && mask && (!(mask[0] & 0x01) || (addr[0] & 0x01))) {
7816 wpa_printf(MSG_INFO,
7817 "CTRL: MAC_RAND_SCAN cannot allow multicast address");
7821 if (type & MAC_ADDR_RAND_SCAN) {
7822 wpas_mac_addr_rand_scan_set(wpa_s, MAC_ADDR_RAND_SCAN,
7826 if (type & MAC_ADDR_RAND_SCHED_SCAN) {
7827 wpas_mac_addr_rand_scan_set(wpa_s, MAC_ADDR_RAND_SCHED_SCAN,
7830 if (wpa_s->sched_scanning && !wpa_s->pno) {
7831 /* simulate timeout to restart the sched scan */
7832 wpa_s->sched_scan_timed_out = 1;
7833 wpa_s->prev_sched_ssid = NULL;
7834 wpa_supplicant_cancel_sched_scan(wpa_s);
7838 if (type & MAC_ADDR_RAND_PNO) {
7839 wpas_mac_addr_rand_scan_set(wpa_s, MAC_ADDR_RAND_PNO,
7842 wpas_stop_pno(wpa_s);
7843 wpas_start_pno(wpa_s);
7851 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
7852 char *buf, size_t *resp_len)
7855 const int reply_size = 4096;
7858 if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 ||
7859 os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
7860 if (wpa_debug_show_keys)
7861 wpa_dbg(wpa_s, MSG_DEBUG,
7862 "Control interface command '%s'", buf);
7864 wpa_dbg(wpa_s, MSG_DEBUG,
7865 "Control interface command '%s [REMOVED]'",
7866 os_strncmp(buf, WPA_CTRL_RSP,
7867 os_strlen(WPA_CTRL_RSP)) == 0 ?
7868 WPA_CTRL_RSP : "SET_NETWORK");
7869 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ", 16) == 0 ||
7870 os_strncmp(buf, "NFC_REPORT_HANDOVER", 19) == 0) {
7871 wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface",
7872 (const u8 *) buf, os_strlen(buf));
7874 int level = MSG_DEBUG;
7875 if (os_strcmp(buf, "PING") == 0)
7876 level = MSG_EXCESSIVE;
7877 wpa_dbg(wpa_s, level, "Control interface command '%s'", buf);
7880 reply = os_malloc(reply_size);
7881 if (reply == NULL) {
7886 os_memcpy(reply, "OK\n", 3);
7889 if (os_strcmp(buf, "PING") == 0) {
7890 os_memcpy(reply, "PONG\n", 5);
7892 } else if (os_strcmp(buf, "IFNAME") == 0) {
7893 reply_len = os_strlen(wpa_s->ifname);
7894 os_memcpy(reply, wpa_s->ifname, reply_len);
7895 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
7896 if (wpa_debug_reopen_file() < 0)
7898 } else if (os_strncmp(buf, "NOTE ", 5) == 0) {
7899 wpa_printf(MSG_INFO, "NOTE: %s", buf + 5);
7900 } else if (os_strcmp(buf, "MIB") == 0) {
7901 reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size);
7902 if (reply_len >= 0) {
7903 reply_len += eapol_sm_get_mib(wpa_s->eapol,
7905 reply_size - reply_len);
7907 } else if (os_strncmp(buf, "STATUS", 6) == 0) {
7908 reply_len = wpa_supplicant_ctrl_iface_status(
7909 wpa_s, buf + 6, reply, reply_size);
7910 } else if (os_strcmp(buf, "PMKSA") == 0) {
7911 reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, reply,
7913 } else if (os_strcmp(buf, "PMKSA_FLUSH") == 0) {
7914 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
7915 } else if (os_strncmp(buf, "SET ", 4) == 0) {
7916 if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4))
7918 } else if (os_strncmp(buf, "DUMP", 4) == 0) {
7919 reply_len = wpa_config_dump_values(wpa_s->conf,
7921 } else if (os_strncmp(buf, "GET ", 4) == 0) {
7922 reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4,
7924 } else if (os_strcmp(buf, "LOGON") == 0) {
7925 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
7926 } else if (os_strcmp(buf, "LOGOFF") == 0) {
7927 eapol_sm_notify_logoff(wpa_s->eapol, TRUE);
7928 } else if (os_strcmp(buf, "REASSOCIATE") == 0) {
7929 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
7932 wpas_request_connection(wpa_s);
7933 } else if (os_strcmp(buf, "REATTACH") == 0) {
7934 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED ||
7935 !wpa_s->current_ssid)
7938 wpa_s->reattach = 1;
7939 wpas_request_connection(wpa_s);
7941 } else if (os_strcmp(buf, "RECONNECT") == 0) {
7942 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
7944 else if (wpa_s->disconnected)
7945 wpas_request_connection(wpa_s);
7946 #ifdef IEEE8021X_EAPOL
7947 } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) {
7948 if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8))
7950 #endif /* IEEE8021X_EAPOL */
7951 #ifdef CONFIG_PEERKEY
7952 } else if (os_strncmp(buf, "STKSTART ", 9) == 0) {
7953 if (wpa_supplicant_ctrl_iface_stkstart(wpa_s, buf + 9))
7955 #endif /* CONFIG_PEERKEY */
7956 #ifdef CONFIG_IEEE80211R
7957 } else if (os_strncmp(buf, "FT_DS ", 6) == 0) {
7958 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6))
7960 #endif /* CONFIG_IEEE80211R */
7962 } else if (os_strcmp(buf, "WPS_PBC") == 0) {
7963 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL);
7965 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
7969 } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) {
7970 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8);
7972 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
7976 } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {
7977 reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8,
7980 } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) {
7981 reply_len = wpa_supplicant_ctrl_iface_wps_check_pin(
7982 wpa_s, buf + 14, reply, reply_size);
7983 } else if (os_strcmp(buf, "WPS_CANCEL") == 0) {
7984 if (wpas_wps_cancel(wpa_s))
7986 #ifdef CONFIG_WPS_NFC
7987 } else if (os_strcmp(buf, "WPS_NFC") == 0) {
7988 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, NULL))
7990 } else if (os_strncmp(buf, "WPS_NFC ", 8) == 0) {
7991 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, buf + 8))
7993 } else if (os_strncmp(buf, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
7994 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_config_token(
7995 wpa_s, buf + 21, reply, reply_size);
7996 } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) {
7997 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_token(
7998 wpa_s, buf + 14, reply, reply_size);
7999 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) {
8000 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s,
8003 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
8004 reply_len = wpas_ctrl_nfc_get_handover_req(
8005 wpa_s, buf + 21, reply, reply_size);
8006 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
8007 reply_len = wpas_ctrl_nfc_get_handover_sel(
8008 wpa_s, buf + 21, reply, reply_size);
8009 } else if (os_strncmp(buf, "NFC_REPORT_HANDOVER ", 20) == 0) {
8010 if (wpas_ctrl_nfc_report_handover(wpa_s, buf + 20))
8012 #endif /* CONFIG_WPS_NFC */
8013 } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) {
8014 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8))
8017 } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) {
8018 reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin(
8019 wpa_s, buf + 11, reply, reply_size);
8020 #endif /* CONFIG_AP */
8021 #ifdef CONFIG_WPS_ER
8022 } else if (os_strcmp(buf, "WPS_ER_START") == 0) {
8023 if (wpas_wps_er_start(wpa_s, NULL))
8025 } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) {
8026 if (wpas_wps_er_start(wpa_s, buf + 13))
8028 } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) {
8029 wpas_wps_er_stop(wpa_s);
8030 } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) {
8031 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11))
8033 } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) {
8034 int ret = wpas_wps_er_pbc(wpa_s, buf + 11);
8036 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
8038 } else if (ret == -3) {
8039 os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18);
8041 } else if (ret == -4) {
8042 os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20);
8046 } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) {
8047 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13))
8049 } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) {
8050 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s,
8053 } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) {
8054 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14))
8056 #ifdef CONFIG_WPS_NFC
8057 } else if (os_strncmp(buf, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
8058 reply_len = wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
8059 wpa_s, buf + 24, reply, reply_size);
8060 #endif /* CONFIG_WPS_NFC */
8061 #endif /* CONFIG_WPS_ER */
8062 #endif /* CONFIG_WPS */
8063 #ifdef CONFIG_IBSS_RSN
8064 } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) {
8065 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9))
8067 #endif /* CONFIG_IBSS_RSN */
8069 } else if (os_strncmp(buf, "MESH_INTERFACE_ADD ", 19) == 0) {
8070 reply_len = wpa_supplicant_ctrl_iface_mesh_interface_add(
8071 wpa_s, buf + 19, reply, reply_size);
8072 } else if (os_strcmp(buf, "MESH_INTERFACE_ADD") == 0) {
8073 reply_len = wpa_supplicant_ctrl_iface_mesh_interface_add(
8074 wpa_s, "", reply, reply_size);
8075 } else if (os_strncmp(buf, "MESH_GROUP_ADD ", 15) == 0) {
8076 if (wpa_supplicant_ctrl_iface_mesh_group_add(wpa_s, buf + 15))
8078 } else if (os_strncmp(buf, "MESH_GROUP_REMOVE ", 18) == 0) {
8079 if (wpa_supplicant_ctrl_iface_mesh_group_remove(wpa_s,
8082 #endif /* CONFIG_MESH */
8084 } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) {
8085 if (p2p_ctrl_find(wpa_s, buf + 8))
8087 } else if (os_strcmp(buf, "P2P_FIND") == 0) {
8088 if (p2p_ctrl_find(wpa_s, ""))
8090 } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) {
8091 wpas_p2p_stop_find(wpa_s);
8092 } else if (os_strncmp(buf, "P2P_ASP_PROVISION ", 18) == 0) {
8093 if (p2p_ctrl_asp_provision(wpa_s, buf + 18))
8095 } else if (os_strncmp(buf, "P2P_ASP_PROVISION_RESP ", 23) == 0) {
8096 if (p2p_ctrl_asp_provision_resp(wpa_s, buf + 23))
8098 } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) {
8099 reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply,
8101 } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) {
8102 if (p2p_ctrl_listen(wpa_s, buf + 11))
8104 } else if (os_strcmp(buf, "P2P_LISTEN") == 0) {
8105 if (p2p_ctrl_listen(wpa_s, ""))
8107 } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) {
8108 if (wpas_p2p_group_remove(wpa_s, buf + 17))
8110 } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) {
8111 if (wpas_p2p_group_add(wpa_s, 0, 0, 0, 0))
8113 } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) {
8114 if (p2p_ctrl_group_add(wpa_s, buf + 14))
8116 } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) {
8117 if (p2p_ctrl_prov_disc(wpa_s, buf + 14))
8119 } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) {
8120 reply_len = p2p_get_passphrase(wpa_s, reply, reply_size);
8121 } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) {
8122 reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply,
8124 } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
8125 if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0)
8127 } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) {
8128 if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0)
8130 } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) {
8131 wpas_p2p_sd_service_update(wpa_s);
8132 } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
8133 if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0)
8135 } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) {
8136 wpas_p2p_service_flush(wpa_s);
8137 } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) {
8138 if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0)
8140 } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) {
8141 if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0)
8143 } else if (os_strncmp(buf, "P2P_SERVICE_REP ", 16) == 0) {
8144 if (p2p_ctrl_service_replace(wpa_s, buf + 16) < 0)
8146 } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) {
8147 if (p2p_ctrl_reject(wpa_s, buf + 11) < 0)
8149 } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) {
8150 if (p2p_ctrl_invite(wpa_s, buf + 11) < 0)
8152 } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) {
8153 reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply,
8155 } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) {
8156 if (p2p_ctrl_set(wpa_s, buf + 8) < 0)
8158 } else if (os_strcmp(buf, "P2P_FLUSH") == 0) {
8159 p2p_ctrl_flush(wpa_s);
8160 } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) {
8161 if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0)
8163 } else if (os_strcmp(buf, "P2P_CANCEL") == 0) {
8164 if (wpas_p2p_cancel(wpa_s))
8166 } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) {
8167 if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0)
8169 } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) {
8170 if (p2p_ctrl_presence_req(wpa_s, "") < 0)
8172 } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) {
8173 if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0)
8175 } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) {
8176 if (p2p_ctrl_ext_listen(wpa_s, "") < 0)
8178 } else if (os_strncmp(buf, "P2P_REMOVE_CLIENT ", 18) == 0) {
8179 if (p2p_ctrl_remove_client(wpa_s, buf + 18) < 0)
8181 #endif /* CONFIG_P2P */
8182 #ifdef CONFIG_WIFI_DISPLAY
8183 } else if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0) {
8184 if (wifi_display_subelem_set(wpa_s->global, buf + 16) < 0)
8186 } else if (os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) {
8187 reply_len = wifi_display_subelem_get(wpa_s->global, buf + 16,
8189 #endif /* CONFIG_WIFI_DISPLAY */
8190 #ifdef CONFIG_INTERWORKING
8191 } else if (os_strcmp(buf, "FETCH_ANQP") == 0) {
8192 if (interworking_fetch_anqp(wpa_s) < 0)
8194 } else if (os_strcmp(buf, "STOP_FETCH_ANQP") == 0) {
8195 interworking_stop_fetch_anqp(wpa_s);
8196 } else if (os_strcmp(buf, "INTERWORKING_SELECT") == 0) {
8197 if (ctrl_interworking_select(wpa_s, NULL) < 0)
8199 } else if (os_strncmp(buf, "INTERWORKING_SELECT ", 20) == 0) {
8200 if (ctrl_interworking_select(wpa_s, buf + 20) < 0)
8202 } else if (os_strncmp(buf, "INTERWORKING_CONNECT ", 21) == 0) {
8203 if (ctrl_interworking_connect(wpa_s, buf + 21, 0) < 0)
8205 } else if (os_strncmp(buf, "INTERWORKING_ADD_NETWORK ", 25) == 0) {
8208 id = ctrl_interworking_connect(wpa_s, buf + 25, 1);
8212 reply_len = os_snprintf(reply, reply_size, "%d\n", id);
8213 if (os_snprintf_error(reply_size, reply_len))
8216 } else if (os_strncmp(buf, "ANQP_GET ", 9) == 0) {
8217 if (get_anqp(wpa_s, buf + 9) < 0)
8219 } else if (os_strncmp(buf, "GAS_REQUEST ", 12) == 0) {
8220 if (gas_request(wpa_s, buf + 12) < 0)
8222 } else if (os_strncmp(buf, "GAS_RESPONSE_GET ", 17) == 0) {
8223 reply_len = gas_response_get(wpa_s, buf + 17, reply,
8225 #endif /* CONFIG_INTERWORKING */
8227 } else if (os_strncmp(buf, "HS20_ANQP_GET ", 14) == 0) {
8228 if (get_hs20_anqp(wpa_s, buf + 14) < 0)
8230 } else if (os_strncmp(buf, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
8231 if (hs20_get_nai_home_realm_list(wpa_s, buf + 29) < 0)
8233 } else if (os_strncmp(buf, "HS20_ICON_REQUEST ", 18) == 0) {
8234 if (hs20_icon_request(wpa_s, buf + 18) < 0)
8236 } else if (os_strcmp(buf, "FETCH_OSU") == 0) {
8237 if (hs20_fetch_osu(wpa_s) < 0)
8239 } else if (os_strcmp(buf, "CANCEL_FETCH_OSU") == 0) {
8240 hs20_cancel_fetch_osu(wpa_s);
8241 #endif /* CONFIG_HS20 */
8242 } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0)
8244 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
8245 wpa_s, buf + os_strlen(WPA_CTRL_RSP)))
8249 * Notify response from timeout to allow the control
8250 * interface response to be sent first.
8252 eloop_register_timeout(0, 0, wpas_ctrl_eapol_response,
8255 } else if (os_strcmp(buf, "RECONFIGURE") == 0) {
8256 if (wpa_supplicant_reload_configuration(wpa_s))
8258 } else if (os_strcmp(buf, "TERMINATE") == 0) {
8259 wpa_supplicant_terminate_proc(wpa_s->global);
8260 } else if (os_strncmp(buf, "BSSID ", 6) == 0) {
8261 if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6))
8263 } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) {
8264 reply_len = wpa_supplicant_ctrl_iface_blacklist(
8265 wpa_s, buf + 9, reply, reply_size);
8266 } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) {
8267 reply_len = wpa_supplicant_ctrl_iface_log_level(
8268 wpa_s, buf + 9, reply, reply_size);
8269 } else if (os_strncmp(buf, "LIST_NETWORKS ", 14) == 0) {
8270 reply_len = wpa_supplicant_ctrl_iface_list_networks(
8271 wpa_s, buf + 14, reply, reply_size);
8272 } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) {
8273 reply_len = wpa_supplicant_ctrl_iface_list_networks(
8274 wpa_s, NULL, reply, reply_size);
8275 } else if (os_strcmp(buf, "DISCONNECT") == 0) {
8277 wpa_s->sme.prev_bssid_set = 0;
8278 #endif /* CONFIG_SME */
8279 wpa_s->reassociate = 0;
8280 wpa_s->disconnected = 1;
8281 wpa_supplicant_cancel_sched_scan(wpa_s);
8282 wpa_supplicant_cancel_scan(wpa_s);
8283 wpa_supplicant_deauthenticate(wpa_s,
8284 WLAN_REASON_DEAUTH_LEAVING);
8285 eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
8286 } else if (os_strcmp(buf, "SCAN") == 0) {
8287 wpas_ctrl_scan(wpa_s, NULL, reply, reply_size, &reply_len);
8288 } else if (os_strncmp(buf, "SCAN ", 5) == 0) {
8289 wpas_ctrl_scan(wpa_s, buf + 5, reply, reply_size, &reply_len);
8290 } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) {
8291 reply_len = wpa_supplicant_ctrl_iface_scan_results(
8292 wpa_s, reply, reply_size);
8293 } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) {
8294 if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15))
8296 } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) {
8297 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15))
8299 } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) {
8300 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16))
8302 } else if (os_strcmp(buf, "ADD_NETWORK") == 0) {
8303 reply_len = wpa_supplicant_ctrl_iface_add_network(
8304 wpa_s, reply, reply_size);
8305 } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) {
8306 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15))
8308 } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
8309 if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12))
8311 } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) {
8312 reply_len = wpa_supplicant_ctrl_iface_get_network(
8313 wpa_s, buf + 12, reply, reply_size);
8314 } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) {
8315 if (wpa_supplicant_ctrl_iface_dup_network(wpa_s, buf + 12))
8317 } else if (os_strcmp(buf, "LIST_CREDS") == 0) {
8318 reply_len = wpa_supplicant_ctrl_iface_list_creds(
8319 wpa_s, reply, reply_size);
8320 } else if (os_strcmp(buf, "ADD_CRED") == 0) {
8321 reply_len = wpa_supplicant_ctrl_iface_add_cred(
8322 wpa_s, reply, reply_size);
8323 } else if (os_strncmp(buf, "REMOVE_CRED ", 12) == 0) {
8324 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s, buf + 12))
8326 } else if (os_strncmp(buf, "SET_CRED ", 9) == 0) {
8327 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s, buf + 9))
8329 } else if (os_strncmp(buf, "GET_CRED ", 9) == 0) {
8330 reply_len = wpa_supplicant_ctrl_iface_get_cred(wpa_s, buf + 9,
8333 #ifndef CONFIG_NO_CONFIG_WRITE
8334 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
8335 if (wpa_supplicant_ctrl_iface_save_config(wpa_s))
8337 #endif /* CONFIG_NO_CONFIG_WRITE */
8338 } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
8339 reply_len = wpa_supplicant_ctrl_iface_get_capability(
8340 wpa_s, buf + 15, reply, reply_size);
8341 } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) {
8342 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8))
8344 } else if (os_strncmp(buf, "SCAN_INTERVAL ", 14) == 0) {
8345 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s, buf + 14))
8347 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
8348 reply_len = wpa_supplicant_global_iface_list(
8349 wpa_s->global, reply, reply_size);
8350 } else if (os_strcmp(buf, "INTERFACES") == 0) {
8351 reply_len = wpa_supplicant_global_iface_interfaces(
8352 wpa_s->global, reply, reply_size);
8353 } else if (os_strncmp(buf, "BSS ", 4) == 0) {
8354 reply_len = wpa_supplicant_ctrl_iface_bss(
8355 wpa_s, buf + 4, reply, reply_size);
8357 } else if (os_strcmp(buf, "STA-FIRST") == 0) {
8358 reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size);
8359 } else if (os_strncmp(buf, "STA ", 4) == 0) {
8360 reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply,
8362 } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) {
8363 reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply,
8365 } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) {
8366 if (ap_ctrl_iface_sta_deauthenticate(wpa_s, buf + 15))
8368 } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) {
8369 if (ap_ctrl_iface_sta_disassociate(wpa_s, buf + 13))
8371 } else if (os_strncmp(buf, "CHAN_SWITCH ", 12) == 0) {
8372 if (ap_ctrl_iface_chanswitch(wpa_s, buf + 12))
8374 } else if (os_strcmp(buf, "STOP_AP") == 0) {
8375 if (wpas_ap_stop_ap(wpa_s))
8377 #endif /* CONFIG_AP */
8378 } else if (os_strcmp(buf, "SUSPEND") == 0) {
8379 wpas_notify_suspend(wpa_s->global);
8380 } else if (os_strcmp(buf, "RESUME") == 0) {
8381 wpas_notify_resume(wpa_s->global);
8382 #ifdef CONFIG_TESTING_OPTIONS
8383 } else if (os_strcmp(buf, "DROP_SA") == 0) {
8384 wpa_supplicant_ctrl_iface_drop_sa(wpa_s);
8385 #endif /* CONFIG_TESTING_OPTIONS */
8386 } else if (os_strncmp(buf, "ROAM ", 5) == 0) {
8387 if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5))
8389 } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) {
8390 wpa_s->auto_reconnect_disabled = atoi(buf + 16) == 0;
8391 } else if (os_strncmp(buf, "BSS_EXPIRE_AGE ", 15) == 0) {
8392 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s, buf + 15))
8394 } else if (os_strncmp(buf, "BSS_EXPIRE_COUNT ", 17) == 0) {
8395 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s,
8398 } else if (os_strncmp(buf, "BSS_FLUSH ", 10) == 0) {
8399 wpa_supplicant_ctrl_iface_bss_flush(wpa_s, buf + 10);
8401 } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) {
8402 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14))
8404 } else if (os_strncmp(buf, "TDLS_SETUP ", 11) == 0) {
8405 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s, buf + 11))
8407 } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) {
8408 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14))
8410 } else if (os_strncmp(buf, "TDLS_CHAN_SWITCH ", 17) == 0) {
8411 if (wpa_supplicant_ctrl_iface_tdls_chan_switch(wpa_s,
8414 } else if (os_strncmp(buf, "TDLS_CANCEL_CHAN_SWITCH ", 24) == 0) {
8415 if (wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(wpa_s,
8418 #endif /* CONFIG_TDLS */
8419 } else if (os_strcmp(buf, "WMM_AC_STATUS") == 0) {
8420 reply_len = wpas_wmm_ac_status(wpa_s, reply, reply_size);
8421 } else if (os_strncmp(buf, "WMM_AC_ADDTS ", 13) == 0) {
8422 if (wmm_ac_ctrl_addts(wpa_s, buf + 13))
8424 } else if (os_strncmp(buf, "WMM_AC_DELTS ", 13) == 0) {
8425 if (wmm_ac_ctrl_delts(wpa_s, buf + 13))
8427 } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) {
8428 reply_len = wpa_supplicant_signal_poll(wpa_s, reply,
8430 } else if (os_strncmp(buf, "PKTCNT_POLL", 11) == 0) {
8431 reply_len = wpa_supplicant_pktcnt_poll(wpa_s, reply,
8433 #ifdef CONFIG_AUTOSCAN
8434 } else if (os_strncmp(buf, "AUTOSCAN ", 9) == 0) {
8435 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s, buf + 9))
8437 #endif /* CONFIG_AUTOSCAN */
8439 } else if (os_strncmp(buf, "DRIVER ", 7) == 0) {
8440 reply_len = wpa_supplicant_driver_cmd(wpa_s, buf + 7, reply,
8442 #endif /* ANDROID */
8443 } else if (os_strncmp(buf, "VENDOR ", 7) == 0) {
8444 reply_len = wpa_supplicant_vendor_cmd(wpa_s, buf + 7, reply,
8446 } else if (os_strcmp(buf, "REAUTHENTICATE") == 0) {
8447 pmksa_cache_clear_current(wpa_s->wpa);
8448 eapol_sm_request_reauth(wpa_s->eapol);
8450 } else if (os_strncmp(buf, "WNM_SLEEP ", 10) == 0) {
8451 if (wpas_ctrl_iface_wnm_sleep(wpa_s, buf + 10))
8453 } else if (os_strncmp(buf, "WNM_BSS_QUERY ", 14) == 0) {
8454 if (wpas_ctrl_iface_wnm_bss_query(wpa_s, buf + 14))
8456 #endif /* CONFIG_WNM */
8457 } else if (os_strcmp(buf, "FLUSH") == 0) {
8458 wpa_supplicant_ctrl_iface_flush(wpa_s);
8459 } else if (os_strncmp(buf, "RADIO_WORK ", 11) == 0) {
8460 reply_len = wpas_ctrl_radio_work(wpa_s, buf + 11, reply,
8462 #ifdef CONFIG_TESTING_OPTIONS
8463 } else if (os_strncmp(buf, "MGMT_TX ", 8) == 0) {
8464 if (wpas_ctrl_iface_mgmt_tx(wpa_s, buf + 8) < 0)
8466 } else if (os_strcmp(buf, "MGMT_TX_DONE") == 0) {
8467 wpas_ctrl_iface_mgmt_tx_done(wpa_s);
8468 } else if (os_strncmp(buf, "DRIVER_EVENT ", 13) == 0) {
8469 if (wpas_ctrl_iface_driver_event(wpa_s, buf + 13) < 0)
8471 } else if (os_strncmp(buf, "EAPOL_RX ", 9) == 0) {
8472 if (wpas_ctrl_iface_eapol_rx(wpa_s, buf + 9) < 0)
8474 } else if (os_strncmp(buf, "DATA_TEST_CONFIG ", 17) == 0) {
8475 if (wpas_ctrl_iface_data_test_config(wpa_s, buf + 17) < 0)
8477 } else if (os_strncmp(buf, "DATA_TEST_TX ", 13) == 0) {
8478 if (wpas_ctrl_iface_data_test_tx(wpa_s, buf + 13) < 0)
8480 } else if (os_strncmp(buf, "DATA_TEST_FRAME ", 16) == 0) {
8481 if (wpas_ctrl_iface_data_test_frame(wpa_s, buf + 16) < 0)
8483 } else if (os_strncmp(buf, "TEST_ALLOC_FAIL ", 16) == 0) {
8484 if (wpas_ctrl_test_alloc_fail(wpa_s, buf + 16) < 0)
8486 } else if (os_strcmp(buf, "GET_ALLOC_FAIL") == 0) {
8487 reply_len = wpas_ctrl_get_alloc_fail(wpa_s, reply, reply_size);
8488 #endif /* CONFIG_TESTING_OPTIONS */
8489 } else if (os_strncmp(buf, "VENDOR_ELEM_ADD ", 16) == 0) {
8490 if (wpas_ctrl_vendor_elem_add(wpa_s, buf + 16) < 0)
8492 } else if (os_strncmp(buf, "VENDOR_ELEM_GET ", 16) == 0) {
8493 reply_len = wpas_ctrl_vendor_elem_get(wpa_s, buf + 16, reply,
8495 } else if (os_strncmp(buf, "VENDOR_ELEM_REMOVE ", 19) == 0) {
8496 if (wpas_ctrl_vendor_elem_remove(wpa_s, buf + 19) < 0)
8498 } else if (os_strncmp(buf, "NEIGHBOR_REP_REQUEST", 20) == 0) {
8499 if (wpas_ctrl_iface_send_neigbor_rep(wpa_s, buf + 20))
8501 } else if (os_strcmp(buf, "ERP_FLUSH") == 0) {
8502 wpas_ctrl_iface_erp_flush(wpa_s);
8503 } else if (os_strncmp(buf, "MAC_RAND_SCAN ", 14) == 0) {
8504 if (wpas_ctrl_iface_mac_rand_scan(wpa_s, buf + 14))
8507 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
8511 if (reply_len < 0) {
8512 os_memcpy(reply, "FAIL\n", 5);
8516 *resp_len = reply_len;
8521 static int wpa_supplicant_global_iface_add(struct wpa_global *global,
8524 struct wpa_interface iface;
8526 struct wpa_supplicant *wpa_s;
8527 unsigned int create_iface = 0;
8528 u8 mac_addr[ETH_ALEN];
8531 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
8532 * TAB<bridge_ifname>[TAB<create>]
8534 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd);
8536 os_memset(&iface, 0, sizeof(iface));
8539 iface.ifname = pos = cmd;
8540 pos = os_strchr(pos, '\t');
8543 if (iface.ifname[0] == '\0')
8548 iface.confname = pos;
8549 pos = os_strchr(pos, '\t');
8552 if (iface.confname[0] == '\0')
8553 iface.confname = NULL;
8558 pos = os_strchr(pos, '\t');
8561 if (iface.driver[0] == '\0')
8562 iface.driver = NULL;
8566 iface.ctrl_interface = pos;
8567 pos = os_strchr(pos, '\t');
8570 if (iface.ctrl_interface[0] == '\0')
8571 iface.ctrl_interface = NULL;
8575 iface.driver_param = pos;
8576 pos = os_strchr(pos, '\t');
8579 if (iface.driver_param[0] == '\0')
8580 iface.driver_param = NULL;
8584 iface.bridge_ifname = pos;
8585 pos = os_strchr(pos, '\t');
8588 if (iface.bridge_ifname[0] == '\0')
8589 iface.bridge_ifname = NULL;
8594 pos = os_strchr(pos, '\t');
8600 if (os_strcmp(extra, "create") == 0)
8603 wpa_printf(MSG_DEBUG,
8604 "INTERFACE_ADD unsupported extra parameter: '%s'",
8611 wpa_printf(MSG_DEBUG, "CTRL_IFACE creating interface '%s'",
8613 if (!global->ifaces)
8615 if (wpa_drv_if_add(global->ifaces, WPA_IF_STATION, iface.ifname,
8616 NULL, NULL, NULL, mac_addr, NULL) < 0) {
8617 wpa_printf(MSG_ERROR,
8618 "CTRL_IFACE interface creation failed");
8622 wpa_printf(MSG_DEBUG,
8623 "CTRL_IFACE interface '%s' created with MAC addr: "
8624 MACSTR, iface.ifname, MAC2STR(mac_addr));
8627 if (wpa_supplicant_get_iface(global, iface.ifname))
8630 wpa_s = wpa_supplicant_add_iface(global, &iface, NULL);
8633 wpa_s->added_vif = create_iface;
8638 wpa_drv_if_remove(global->ifaces, WPA_IF_STATION, iface.ifname);
8643 static int wpa_supplicant_global_iface_remove(struct wpa_global *global,
8646 struct wpa_supplicant *wpa_s;
8648 unsigned int delete_iface;
8650 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd);
8652 wpa_s = wpa_supplicant_get_iface(global, cmd);
8655 delete_iface = wpa_s->added_vif;
8656 ret = wpa_supplicant_remove_iface(global, wpa_s, 0);
8657 if (!ret && delete_iface) {
8658 wpa_printf(MSG_DEBUG, "CTRL_IFACE deleting the interface '%s'",
8660 ret = wpa_drv_if_remove(global->ifaces, WPA_IF_STATION, cmd);
8666 static void wpa_free_iface_info(struct wpa_interface_info *iface)
8668 struct wpa_interface_info *prev;
8672 iface = iface->next;
8674 os_free(prev->ifname);
8675 os_free(prev->desc);
8681 static int wpa_supplicant_global_iface_list(struct wpa_global *global,
8685 struct wpa_interface_info *iface = NULL, *last = NULL, *tmp;
8688 for (i = 0; wpa_drivers[i]; i++) {
8689 const struct wpa_driver_ops *drv = wpa_drivers[i];
8690 if (drv->get_interfaces == NULL)
8692 tmp = drv->get_interfaces(global->drv_priv[i]);
8706 for (tmp = iface; tmp; tmp = tmp->next) {
8707 res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n",
8708 tmp->drv_name, tmp->ifname,
8709 tmp->desc ? tmp->desc : "");
8710 if (os_snprintf_error(end - pos, res)) {
8717 wpa_free_iface_info(iface);
8723 static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
8728 struct wpa_supplicant *wpa_s;
8730 wpa_s = global->ifaces;
8735 res = os_snprintf(pos, end - pos, "%s\n", wpa_s->ifname);
8736 if (os_snprintf_error(end - pos, res)) {
8741 wpa_s = wpa_s->next;
8747 static char * wpas_global_ctrl_iface_ifname(struct wpa_global *global,
8749 char *cmd, size_t *resp_len)
8751 struct wpa_supplicant *wpa_s;
8753 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
8754 if (os_strcmp(ifname, wpa_s->ifname) == 0)
8758 if (wpa_s == NULL) {
8759 char *resp = os_strdup("FAIL-NO-IFNAME-MATCH\n");
8761 *resp_len = os_strlen(resp);
8767 return wpa_supplicant_ctrl_iface_process(wpa_s, cmd, resp_len);
8771 static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global *global,
8772 char *buf, size_t *resp_len)
8775 static const char * cmd[] = {
8781 "P2P_GET_PASSPHRASE",
8782 "P2P_SERVICE_UPDATE",
8783 "P2P_SERVICE_FLUSH",
8790 static const char * prefix[] = {
8793 #endif /* ANDROID */
8799 "P2P_GROUP_REMOVE ",
8802 "P2P_SERV_DISC_REQ ",
8803 "P2P_SERV_DISC_CANCEL_REQ ",
8804 "P2P_SERV_DISC_RESP ",
8805 "P2P_SERV_DISC_EXTERNAL ",
8814 "P2P_PRESENCE_REQ ",
8816 "P2P_REMOVE_CLIENT ",
8818 "WPS_NFC_TAG_READ ",
8819 "NFC_GET_HANDOVER_SEL ",
8820 "NFC_GET_HANDOVER_REQ ",
8821 "NFC_REPORT_HANDOVER ",
8822 "P2P_ASP_PROVISION ",
8823 "P2P_ASP_PROVISION_RESP ",
8829 if (global->p2p_init_wpa_s == NULL)
8832 for (i = 0; !found && cmd[i]; i++) {
8833 if (os_strcmp(buf, cmd[i]) == 0)
8837 for (i = 0; !found && prefix[i]; i++) {
8838 if (os_strncmp(buf, prefix[i], os_strlen(prefix[i])) == 0)
8843 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
8845 #endif /* CONFIG_P2P */
8850 static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global *global,
8851 char *buf, size_t *resp_len)
8853 #ifdef CONFIG_WIFI_DISPLAY
8854 if (global->p2p_init_wpa_s == NULL)
8856 if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0 ||
8857 os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0)
8858 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
8860 #endif /* CONFIG_WIFI_DISPLAY */
8865 static char * wpas_global_ctrl_iface_redir(struct wpa_global *global,
8866 char *buf, size_t *resp_len)
8870 ret = wpas_global_ctrl_iface_redir_p2p(global, buf, resp_len);
8874 ret = wpas_global_ctrl_iface_redir_wfd(global, buf, resp_len);
8882 static int wpas_global_ctrl_iface_set(struct wpa_global *global, char *cmd)
8886 value = os_strchr(cmd, ' ');
8891 wpa_printf(MSG_DEBUG, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd, value);
8893 #ifdef CONFIG_WIFI_DISPLAY
8894 if (os_strcasecmp(cmd, "wifi_display") == 0) {
8895 wifi_display_enable(global, !!atoi(value));
8898 #endif /* CONFIG_WIFI_DISPLAY */
8900 /* Restore cmd to its original value to allow redirection */
8907 #ifndef CONFIG_NO_CONFIG_WRITE
8908 static int wpas_global_ctrl_iface_save_config(struct wpa_global *global)
8910 int ret = 0, saved = 0;
8911 struct wpa_supplicant *wpa_s;
8913 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
8914 if (!wpa_s->conf->update_config) {
8915 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
8919 if (wpa_config_write(wpa_s->confname, wpa_s->conf)) {
8920 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
8923 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
8928 if (!saved && !ret) {
8929 wpa_dbg(wpa_s, MSG_DEBUG,
8930 "CTRL_IFACE: SAVE_CONFIG - No configuration files could be updated");
8936 #endif /* CONFIG_NO_CONFIG_WRITE */
8939 static int wpas_global_ctrl_iface_status(struct wpa_global *global,
8940 char *buf, size_t buflen)
8944 struct wpa_supplicant *wpa_s;
8950 if (global->p2p && !global->p2p_disabled) {
8951 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
8954 MAC2STR(global->p2p_dev_addr),
8955 p2p_get_state_txt(global->p2p));
8956 if (os_snprintf_error(end - pos, ret))
8959 } else if (global->p2p) {
8960 ret = os_snprintf(pos, end - pos, "p2p_state=DISABLED\n");
8961 if (os_snprintf_error(end - pos, ret))
8965 #endif /* CONFIG_P2P */
8967 #ifdef CONFIG_WIFI_DISPLAY
8968 ret = os_snprintf(pos, end - pos, "wifi_display=%d\n",
8969 !!global->wifi_display);
8970 if (os_snprintf_error(end - pos, ret))
8973 #endif /* CONFIG_WIFI_DISPLAY */
8975 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
8976 ret = os_snprintf(pos, end - pos, "ifname=%s\n"
8977 "address=" MACSTR "\n",
8978 wpa_s->ifname, MAC2STR(wpa_s->own_addr));
8979 if (os_snprintf_error(end - pos, ret))
8988 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
8989 char *buf, size_t *resp_len)
8992 const int reply_size = 2048;
8994 int level = MSG_DEBUG;
8996 if (os_strncmp(buf, "IFNAME=", 7) == 0) {
8997 char *pos = os_strchr(buf + 7, ' ');
9000 return wpas_global_ctrl_iface_ifname(global,
9006 reply = wpas_global_ctrl_iface_redir(global, buf, resp_len);
9010 if (os_strcmp(buf, "PING") == 0)
9011 level = MSG_EXCESSIVE;
9012 wpa_hexdump_ascii(level, "RX global ctrl_iface",
9013 (const u8 *) buf, os_strlen(buf));
9015 reply = os_malloc(reply_size);
9016 if (reply == NULL) {
9021 os_memcpy(reply, "OK\n", 3);
9024 if (os_strcmp(buf, "PING") == 0) {
9025 os_memcpy(reply, "PONG\n", 5);
9027 } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) {
9028 if (wpa_supplicant_global_iface_add(global, buf + 14))
9030 } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) {
9031 if (wpa_supplicant_global_iface_remove(global, buf + 17))
9033 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
9034 reply_len = wpa_supplicant_global_iface_list(
9035 global, reply, reply_size);
9036 } else if (os_strcmp(buf, "INTERFACES") == 0) {
9037 reply_len = wpa_supplicant_global_iface_interfaces(
9038 global, reply, reply_size);
9039 } else if (os_strcmp(buf, "TERMINATE") == 0) {
9040 wpa_supplicant_terminate_proc(global);
9041 } else if (os_strcmp(buf, "SUSPEND") == 0) {
9042 wpas_notify_suspend(global);
9043 } else if (os_strcmp(buf, "RESUME") == 0) {
9044 wpas_notify_resume(global);
9045 } else if (os_strncmp(buf, "SET ", 4) == 0) {
9046 if (wpas_global_ctrl_iface_set(global, buf + 4)) {
9048 if (global->p2p_init_wpa_s) {
9050 /* Check if P2P redirection would work for this
9052 return wpa_supplicant_ctrl_iface_process(
9053 global->p2p_init_wpa_s,
9056 #endif /* CONFIG_P2P */
9059 #ifndef CONFIG_NO_CONFIG_WRITE
9060 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
9061 if (wpas_global_ctrl_iface_save_config(global))
9063 #endif /* CONFIG_NO_CONFIG_WRITE */
9064 } else if (os_strcmp(buf, "STATUS") == 0) {
9065 reply_len = wpas_global_ctrl_iface_status(global, reply,
9067 #ifdef CONFIG_MODULE_TESTS
9068 } else if (os_strcmp(buf, "MODULE_TESTS") == 0) {
9069 int wpas_module_tests(void);
9070 if (wpas_module_tests() < 0)
9072 #endif /* CONFIG_MODULE_TESTS */
9073 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
9074 if (wpa_debug_reopen_file() < 0)
9077 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
9081 if (reply_len < 0) {
9082 os_memcpy(reply, "FAIL\n", 5);
9086 *resp_len = reply_len;