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 || end - pos > 2 * 32 ||
157 hexstr2bin(pos, ssid[ssid_count].ssid,
158 (end - pos) / 2) < 0) {
161 wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
162 "SSID value '%s'", pos);
165 ssid[ssid_count].ssid_len = (end - pos) / 2;
166 wpa_hexdump_ascii(MSG_DEBUG, "disallow_aps SSID",
167 ssid[ssid_count].ssid,
168 ssid[ssid_count].ssid_len);
172 wpa_printf(MSG_DEBUG, "Unexpected disallow_aps value "
179 pos = os_strchr(pos, ' ');
184 wpa_hexdump(MSG_DEBUG, "disallow_aps_bssid", bssid, count * ETH_ALEN);
185 os_free(wpa_s->disallow_aps_bssid);
186 wpa_s->disallow_aps_bssid = bssid;
187 wpa_s->disallow_aps_bssid_count = count;
189 wpa_printf(MSG_DEBUG, "disallow_aps_ssid_count %d", (int) ssid_count);
190 os_free(wpa_s->disallow_aps_ssid);
191 wpa_s->disallow_aps_ssid = ssid;
192 wpa_s->disallow_aps_ssid_count = ssid_count;
194 if (!wpa_s->current_ssid || wpa_s->wpa_state < WPA_AUTHENTICATING)
197 c = wpa_s->current_ssid;
198 if (c->mode != WPAS_MODE_INFRA && c->mode != WPAS_MODE_IBSS)
201 if (!disallowed_bssid(wpa_s, wpa_s->bssid) &&
202 !disallowed_ssid(wpa_s, c->ssid, c->ssid_len))
205 wpa_printf(MSG_DEBUG, "Disconnect and try to find another network "
206 "because current AP was marked disallowed");
209 wpa_s->sme.prev_bssid_set = 0;
210 #endif /* CONFIG_SME */
211 wpa_s->reassociate = 1;
212 wpa_s->own_disconnect_req = 1;
213 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
214 wpa_supplicant_req_scan(wpa_s, 0, 0);
220 #ifndef CONFIG_NO_CONFIG_BLOBS
221 static int wpas_ctrl_set_blob(struct wpa_supplicant *wpa_s, char *pos)
224 struct wpa_config_blob *blob;
227 pos = os_strchr(pos, ' ');
231 len = os_strlen(pos);
235 wpa_printf(MSG_DEBUG, "CTRL: Set blob '%s'", name);
236 blob = os_zalloc(sizeof(*blob));
239 blob->name = os_strdup(name);
240 blob->data = os_malloc(len / 2);
241 if (blob->name == NULL || blob->data == NULL) {
242 wpa_config_free_blob(blob);
246 if (hexstr2bin(pos, blob->data, len / 2) < 0) {
247 wpa_printf(MSG_DEBUG, "CTRL: Invalid blob hex data");
248 wpa_config_free_blob(blob);
253 wpa_config_set_blob(wpa_s->conf, blob);
257 #endif /* CONFIG_NO_CONFIG_BLOBS */
260 static int wpas_ctrl_pno(struct wpa_supplicant *wpa_s, char *cmd)
268 params = os_strchr(cmd, ' ');
269 os_free(wpa_s->manual_sched_scan_freqs);
272 pos = os_strstr(params, "freq=");
274 freqs = freq_range_to_channel_list(wpa_s,
277 wpa_s->manual_sched_scan_freqs = freqs;
278 ret = wpas_start_pno(wpa_s);
280 ret = wpas_stop_pno(wpa_s);
286 static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s,
292 value = os_strchr(cmd, ' ');
297 wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value);
298 if (os_strcasecmp(cmd, "EAPOL::heldPeriod") == 0) {
299 eapol_sm_configure(wpa_s->eapol,
300 atoi(value), -1, -1, -1);
301 } else if (os_strcasecmp(cmd, "EAPOL::authPeriod") == 0) {
302 eapol_sm_configure(wpa_s->eapol,
303 -1, atoi(value), -1, -1);
304 } else if (os_strcasecmp(cmd, "EAPOL::startPeriod") == 0) {
305 eapol_sm_configure(wpa_s->eapol,
306 -1, -1, atoi(value), -1);
307 } else if (os_strcasecmp(cmd, "EAPOL::maxStart") == 0) {
308 eapol_sm_configure(wpa_s->eapol,
309 -1, -1, -1, atoi(value));
310 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKLifetime") == 0) {
311 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME,
314 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKReauthThreshold") ==
316 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD,
319 } else if (os_strcasecmp(cmd, "dot11RSNAConfigSATimeout") == 0) {
320 if (wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, atoi(value)))
322 } else if (os_strcasecmp(cmd, "wps_fragment_size") == 0) {
323 wpa_s->wps_fragment_size = atoi(value);
324 #ifdef CONFIG_WPS_TESTING
325 } else if (os_strcasecmp(cmd, "wps_version_number") == 0) {
327 val = strtol(value, NULL, 0);
328 if (val < 0 || val > 0xff) {
330 wpa_printf(MSG_DEBUG, "WPS: Invalid "
331 "wps_version_number %ld", val);
333 wps_version_number = val;
334 wpa_printf(MSG_DEBUG, "WPS: Testing - force WPS "
336 (wps_version_number & 0xf0) >> 4,
337 wps_version_number & 0x0f);
339 } else if (os_strcasecmp(cmd, "wps_testing_dummy_cred") == 0) {
340 wps_testing_dummy_cred = atoi(value);
341 wpa_printf(MSG_DEBUG, "WPS: Testing - dummy_cred=%d",
342 wps_testing_dummy_cred);
343 } else if (os_strcasecmp(cmd, "wps_corrupt_pkhash") == 0) {
344 wps_corrupt_pkhash = atoi(value);
345 wpa_printf(MSG_DEBUG, "WPS: Testing - wps_corrupt_pkhash=%d",
347 #endif /* CONFIG_WPS_TESTING */
348 } else if (os_strcasecmp(cmd, "ampdu") == 0) {
349 if (wpa_drv_ampdu(wpa_s, atoi(value)) < 0)
352 #ifdef CONFIG_TDLS_TESTING
353 } else if (os_strcasecmp(cmd, "tdls_testing") == 0) {
354 extern unsigned int tdls_testing;
355 tdls_testing = strtol(value, NULL, 0);
356 wpa_printf(MSG_DEBUG, "TDLS: tdls_testing=0x%x", tdls_testing);
357 #endif /* CONFIG_TDLS_TESTING */
358 } else if (os_strcasecmp(cmd, "tdls_disabled") == 0) {
359 int disabled = atoi(value);
360 wpa_printf(MSG_DEBUG, "TDLS: tdls_disabled=%d", disabled);
362 if (wpa_drv_tdls_oper(wpa_s, TDLS_DISABLE, NULL) < 0)
364 } else if (wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL) < 0)
366 wpa_tdls_enable(wpa_s->wpa, !disabled);
367 #endif /* CONFIG_TDLS */
368 } else if (os_strcasecmp(cmd, "pno") == 0) {
369 ret = wpas_ctrl_pno(wpa_s, value);
370 } else if (os_strcasecmp(cmd, "radio_disabled") == 0) {
371 int disabled = atoi(value);
372 if (wpa_drv_radio_disable(wpa_s, disabled) < 0)
375 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
376 } else if (os_strcasecmp(cmd, "uapsd") == 0) {
377 if (os_strcmp(value, "disable") == 0)
378 wpa_s->set_sta_uapsd = 0;
382 /* format: BE,BK,VI,VO;max SP Length */
384 pos = os_strchr(value, ',');
389 pos = os_strchr(pos, ',');
394 pos = os_strchr(pos, ',');
399 /* ignore max SP Length for now */
401 wpa_s->set_sta_uapsd = 1;
402 wpa_s->sta_uapsd = 0;
404 wpa_s->sta_uapsd |= BIT(0);
406 wpa_s->sta_uapsd |= BIT(1);
408 wpa_s->sta_uapsd |= BIT(2);
410 wpa_s->sta_uapsd |= BIT(3);
412 } else if (os_strcasecmp(cmd, "ps") == 0) {
413 ret = wpa_drv_set_p2p_powersave(wpa_s, atoi(value), -1, -1);
414 #ifdef CONFIG_WIFI_DISPLAY
415 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
416 int enabled = !!atoi(value);
417 if (enabled && !wpa_s->global->p2p)
420 wifi_display_enable(wpa_s->global, enabled);
421 #endif /* CONFIG_WIFI_DISPLAY */
422 } else if (os_strcasecmp(cmd, "bssid_filter") == 0) {
423 ret = set_bssid_filter(wpa_s, value);
424 } else if (os_strcasecmp(cmd, "disallow_aps") == 0) {
425 ret = set_disallow_aps(wpa_s, value);
426 } else if (os_strcasecmp(cmd, "no_keep_alive") == 0) {
427 wpa_s->no_keep_alive = !!atoi(value);
428 #ifdef CONFIG_TESTING_OPTIONS
429 } else if (os_strcasecmp(cmd, "ext_mgmt_frame_handling") == 0) {
430 wpa_s->ext_mgmt_frame_handling = !!atoi(value);
431 } else if (os_strcasecmp(cmd, "ext_eapol_frame_io") == 0) {
432 wpa_s->ext_eapol_frame_io = !!atoi(value);
434 if (wpa_s->ap_iface) {
435 wpa_s->ap_iface->bss[0]->ext_eapol_frame_io =
436 wpa_s->ext_eapol_frame_io;
438 #endif /* CONFIG_AP */
439 } else if (os_strcasecmp(cmd, "extra_roc_dur") == 0) {
440 wpa_s->extra_roc_dur = atoi(value);
441 } else if (os_strcasecmp(cmd, "test_failure") == 0) {
442 wpa_s->test_failure = atoi(value);
443 #endif /* CONFIG_TESTING_OPTIONS */
444 #ifndef CONFIG_NO_CONFIG_BLOBS
445 } else if (os_strcmp(cmd, "blob") == 0) {
446 ret = wpas_ctrl_set_blob(wpa_s, value);
447 #endif /* CONFIG_NO_CONFIG_BLOBS */
448 } else if (os_strcasecmp(cmd, "setband") == 0) {
449 if (os_strcmp(value, "AUTO") == 0)
450 wpa_s->setband = WPA_SETBAND_AUTO;
451 else if (os_strcmp(value, "5G") == 0)
452 wpa_s->setband = WPA_SETBAND_5G;
453 else if (os_strcmp(value, "2G") == 0)
454 wpa_s->setband = WPA_SETBAND_2G;
459 ret = wpa_config_process_global(wpa_s->conf, cmd, -1);
461 wpa_supplicant_update_config(wpa_s);
468 static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s,
469 char *cmd, char *buf, size_t buflen)
473 wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd);
475 if (os_strcmp(cmd, "version") == 0) {
476 res = os_snprintf(buf, buflen, "%s", VERSION_STR);
477 } else if (os_strcasecmp(cmd, "country") == 0) {
478 if (wpa_s->conf->country[0] && wpa_s->conf->country[1])
479 res = os_snprintf(buf, buflen, "%c%c",
480 wpa_s->conf->country[0],
481 wpa_s->conf->country[1]);
482 #ifdef CONFIG_WIFI_DISPLAY
483 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
485 if (wpa_s->global->p2p == NULL ||
486 wpa_s->global->p2p_disabled)
489 enabled = wpa_s->global->wifi_display;
490 res = os_snprintf(buf, buflen, "%d", enabled);
491 #endif /* CONFIG_WIFI_DISPLAY */
492 #ifdef CONFIG_TESTING_GET_GTK
493 } else if (os_strcmp(cmd, "gtk") == 0) {
494 if (wpa_s->last_gtk_len == 0)
496 res = wpa_snprintf_hex(buf, buflen, wpa_s->last_gtk,
497 wpa_s->last_gtk_len);
499 #endif /* CONFIG_TESTING_GET_GTK */
500 } else if (os_strcmp(cmd, "tls_library") == 0) {
501 res = tls_get_library_version(buf, buflen);
503 res = wpa_config_get_value(cmd, wpa_s->conf, buf, buflen);
506 if (os_snprintf_error(buflen, res))
512 #ifdef IEEE8021X_EAPOL
513 static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s,
517 struct wpa_ssid *ssid = wpa_s->current_ssid;
519 if (hwaddr_aton(addr, bssid)) {
520 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address "
525 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid));
526 rsn_preauth_deinit(wpa_s->wpa);
527 if (rsn_preauth_init(wpa_s->wpa, bssid, ssid ? &ssid->eap : NULL))
532 #endif /* IEEE8021X_EAPOL */
535 #ifdef CONFIG_PEERKEY
536 /* MLME-STKSTART.request(peer) */
537 static int wpa_supplicant_ctrl_iface_stkstart(
538 struct wpa_supplicant *wpa_s, char *addr)
542 if (hwaddr_aton(addr, peer)) {
543 wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART: invalid "
544 "address '%s'", addr);
548 wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART " MACSTR,
551 return wpa_sm_stkstart(wpa_s->wpa, peer);
553 #endif /* CONFIG_PEERKEY */
558 static int wpa_supplicant_ctrl_iface_tdls_discover(
559 struct wpa_supplicant *wpa_s, char *addr)
564 if (hwaddr_aton(addr, peer)) {
565 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER: invalid "
566 "address '%s'", addr);
570 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER " MACSTR,
573 if (wpa_tdls_is_external_setup(wpa_s->wpa))
574 ret = wpa_tdls_send_discovery_request(wpa_s->wpa, peer);
576 ret = wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer);
582 static int wpa_supplicant_ctrl_iface_tdls_setup(
583 struct wpa_supplicant *wpa_s, char *addr)
588 if (hwaddr_aton(addr, peer)) {
589 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP: invalid "
590 "address '%s'", addr);
594 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP " MACSTR,
597 if ((wpa_s->conf->tdls_external_control) &&
598 wpa_tdls_is_external_setup(wpa_s->wpa))
599 return wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
601 wpa_tdls_remove(wpa_s->wpa, peer);
603 if (wpa_tdls_is_external_setup(wpa_s->wpa))
604 ret = wpa_tdls_start(wpa_s->wpa, peer);
606 ret = wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
612 static int wpa_supplicant_ctrl_iface_tdls_teardown(
613 struct wpa_supplicant *wpa_s, char *addr)
618 if (os_strcmp(addr, "*") == 0) {
619 /* remove everyone */
620 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN *");
621 wpa_tdls_teardown_peers(wpa_s->wpa);
625 if (hwaddr_aton(addr, peer)) {
626 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN: invalid "
627 "address '%s'", addr);
631 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN " MACSTR,
634 if ((wpa_s->conf->tdls_external_control) &&
635 wpa_tdls_is_external_setup(wpa_s->wpa))
636 return wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
638 if (wpa_tdls_is_external_setup(wpa_s->wpa))
639 ret = wpa_tdls_teardown_link(
641 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED);
643 ret = wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
649 static int ctrl_iface_get_capability_tdls(
650 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
654 ret = os_snprintf(buf, buflen, "%s\n",
655 wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT ?
657 WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP ?
658 "EXTERNAL" : "INTERNAL") : "UNSUPPORTED");
659 if (os_snprintf_error(buflen, ret))
665 static int wpa_supplicant_ctrl_iface_tdls_chan_switch(
666 struct wpa_supplicant *wpa_s, char *cmd)
669 struct hostapd_freq_params freq_params;
673 if (!wpa_tdls_is_external_setup(wpa_s->wpa)) {
675 "tdls_chanswitch: Only supported with external setup");
679 os_memset(&freq_params, 0, sizeof(freq_params));
681 pos = os_strchr(cmd, ' ');
686 oper_class = strtol(pos, &end, 10);
689 "tdls_chanswitch: Invalid op class provided");
694 freq_params.freq = atoi(pos);
695 if (freq_params.freq == 0) {
696 wpa_printf(MSG_INFO, "tdls_chanswitch: Invalid freq provided");
700 #define SET_FREQ_SETTING(str) \
702 const char *pos2 = os_strstr(pos, " " #str "="); \
704 pos2 += sizeof(" " #str "=") - 1; \
705 freq_params.str = atoi(pos2); \
709 SET_FREQ_SETTING(center_freq1);
710 SET_FREQ_SETTING(center_freq2);
711 SET_FREQ_SETTING(bandwidth);
712 SET_FREQ_SETTING(sec_channel_offset);
713 #undef SET_FREQ_SETTING
715 freq_params.ht_enabled = !!os_strstr(pos, " ht");
716 freq_params.vht_enabled = !!os_strstr(pos, " vht");
718 if (hwaddr_aton(cmd, peer)) {
719 wpa_printf(MSG_DEBUG,
720 "CTRL_IFACE TDLS_CHAN_SWITCH: Invalid address '%s'",
725 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_CHAN_SWITCH " MACSTR
726 " OP CLASS %d FREQ %d CENTER1 %d CENTER2 %d BW %d SEC_OFFSET %d%s%s",
727 MAC2STR(peer), oper_class, freq_params.freq,
728 freq_params.center_freq1, freq_params.center_freq2,
729 freq_params.bandwidth, freq_params.sec_channel_offset,
730 freq_params.ht_enabled ? " HT" : "",
731 freq_params.vht_enabled ? " VHT" : "");
733 return wpa_tdls_enable_chan_switch(wpa_s->wpa, peer, oper_class,
738 static int wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(
739 struct wpa_supplicant *wpa_s, char *cmd)
743 if (!wpa_tdls_is_external_setup(wpa_s->wpa)) {
745 "tdls_chanswitch: Only supported with external setup");
749 if (hwaddr_aton(cmd, peer)) {
750 wpa_printf(MSG_DEBUG,
751 "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH: Invalid address '%s'",
756 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH " MACSTR,
759 return wpa_tdls_disable_chan_switch(wpa_s->wpa, peer);
762 #endif /* CONFIG_TDLS */
765 static int wmm_ac_ctrl_addts(struct wpa_supplicant *wpa_s, char *cmd)
767 char *token, *context = NULL;
768 struct wmm_ac_ts_setup_params params = {
773 while ((token = str_token(cmd, " ", &context))) {
774 if (sscanf(token, "tsid=%i", ¶ms.tsid) == 1 ||
775 sscanf(token, "up=%i", ¶ms.user_priority) == 1 ||
776 sscanf(token, "nominal_msdu_size=%i",
777 ¶ms.nominal_msdu_size) == 1 ||
778 sscanf(token, "mean_data_rate=%i",
779 ¶ms.mean_data_rate) == 1 ||
780 sscanf(token, "min_phy_rate=%i",
781 ¶ms.minimum_phy_rate) == 1 ||
782 sscanf(token, "sba=%i",
783 ¶ms.surplus_bandwidth_allowance) == 1)
786 if (os_strcasecmp(token, "downlink") == 0) {
787 params.direction = WMM_TSPEC_DIRECTION_DOWNLINK;
788 } else if (os_strcasecmp(token, "uplink") == 0) {
789 params.direction = WMM_TSPEC_DIRECTION_UPLINK;
790 } else if (os_strcasecmp(token, "bidi") == 0) {
791 params.direction = WMM_TSPEC_DIRECTION_BI_DIRECTIONAL;
792 } else if (os_strcasecmp(token, "fixed_nominal_msdu") == 0) {
793 params.fixed_nominal_msdu = 1;
795 wpa_printf(MSG_DEBUG,
796 "CTRL: Invalid WMM_AC_ADDTS parameter: '%s'",
803 return wpas_wmm_ac_addts(wpa_s, ¶ms);
807 static int wmm_ac_ctrl_delts(struct wpa_supplicant *wpa_s, char *cmd)
811 return wpas_wmm_ac_delts(wpa_s, tsid);
815 #ifdef CONFIG_IEEE80211R
816 static int wpa_supplicant_ctrl_iface_ft_ds(
817 struct wpa_supplicant *wpa_s, char *addr)
819 u8 target_ap[ETH_ALEN];
823 if (hwaddr_aton(addr, target_ap)) {
824 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid "
825 "address '%s'", addr);
829 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap));
831 bss = wpa_bss_get_bssid(wpa_s, target_ap);
833 mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN);
837 return wpa_ft_start_over_ds(wpa_s->wpa, target_ap, mdie);
839 #endif /* CONFIG_IEEE80211R */
843 static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s,
846 u8 bssid[ETH_ALEN], *_bssid = bssid;
848 u8 p2p_dev_addr[ETH_ALEN];
849 #endif /* CONFIG_P2P */
851 u8 *_p2p_dev_addr = NULL;
852 #endif /* CONFIG_AP */
854 if (cmd == NULL || os_strcmp(cmd, "any") == 0) {
857 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
858 if (hwaddr_aton(cmd + 13, p2p_dev_addr)) {
859 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid "
860 "P2P Device Address '%s'",
864 _p2p_dev_addr = p2p_dev_addr;
865 #endif /* CONFIG_P2P */
866 } else if (hwaddr_aton(cmd, bssid)) {
867 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
874 return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid, _p2p_dev_addr);
875 #endif /* CONFIG_AP */
877 return wpas_wps_start_pbc(wpa_s, _bssid, 0);
881 static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s,
882 char *cmd, char *buf,
885 u8 bssid[ETH_ALEN], *_bssid = bssid;
889 pin = os_strchr(cmd, ' ');
893 if (os_strcmp(cmd, "any") == 0)
895 else if (os_strcmp(cmd, "get") == 0) {
896 ret = wps_generate_pin();
898 } else if (hwaddr_aton(cmd, bssid)) {
899 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
905 if (wpa_s->ap_iface) {
910 pos = os_strchr(pin, ' ');
917 return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin,
918 buf, buflen, timeout);
920 #endif /* CONFIG_AP */
923 ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0,
927 ret = os_snprintf(buf, buflen, "%s", pin);
928 if (os_snprintf_error(buflen, ret))
933 ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0, DEV_PW_DEFAULT);
938 /* Return the generated PIN */
939 ret = os_snprintf(buf, buflen, "%08d", ret);
940 if (os_snprintf_error(buflen, ret))
946 static int wpa_supplicant_ctrl_iface_wps_check_pin(
947 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
954 wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN",
955 (u8 *) cmd, os_strlen(cmd));
956 for (pos = cmd, len = 0; *pos != '\0'; pos++) {
957 if (*pos < '0' || *pos > '9')
961 wpa_printf(MSG_DEBUG, "WPS: Too long PIN");
965 if (len != 4 && len != 8) {
966 wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len);
972 unsigned int pin_val;
974 if (!wps_pin_valid(pin_val)) {
975 wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit");
976 ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n");
977 if (os_snprintf_error(buflen, ret))
983 ret = os_snprintf(buf, buflen, "%s", pin);
984 if (os_snprintf_error(buflen, ret))
991 #ifdef CONFIG_WPS_NFC
993 static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant *wpa_s,
996 u8 bssid[ETH_ALEN], *_bssid = bssid;
998 if (cmd == NULL || cmd[0] == '\0')
1000 else if (hwaddr_aton(cmd, bssid))
1003 return wpas_wps_start_nfc(wpa_s, NULL, _bssid, NULL, 0, 0, NULL, NULL,
1008 static int wpa_supplicant_ctrl_iface_wps_nfc_config_token(
1009 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1016 pos = os_strchr(cmd, ' ');
1019 if (os_strcmp(cmd, "WPS") == 0)
1021 else if (os_strcmp(cmd, "NDEF") == 0)
1026 buf = wpas_wps_nfc_config_token(wpa_s, ndef, pos);
1030 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1032 reply[res++] = '\n';
1041 static int wpa_supplicant_ctrl_iface_wps_nfc_token(
1042 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1048 if (os_strcmp(cmd, "WPS") == 0)
1050 else if (os_strcmp(cmd, "NDEF") == 0)
1055 buf = wpas_wps_nfc_token(wpa_s, ndef);
1059 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1061 reply[res++] = '\n';
1070 static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
1071 struct wpa_supplicant *wpa_s, char *pos)
1077 int forced_freq = 0;
1079 freq = strstr(pos, " freq=");
1083 forced_freq = atoi(freq);
1086 len = os_strlen(pos);
1091 buf = wpabuf_alloc(len);
1094 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
1099 ret = wpas_wps_nfc_tag_read(wpa_s, buf, forced_freq);
1106 static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant *wpa_s,
1107 char *reply, size_t max_len,
1113 buf = wpas_wps_nfc_handover_req(wpa_s, ndef);
1117 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1119 reply[res++] = '\n';
1129 static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant *wpa_s,
1130 char *reply, size_t max_len,
1136 buf = wpas_p2p_nfc_handover_req(wpa_s, ndef);
1138 wpa_printf(MSG_DEBUG, "P2P: Could not generate NFC handover request");
1142 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1144 reply[res++] = '\n';
1151 #endif /* CONFIG_P2P */
1154 static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant *wpa_s,
1155 char *cmd, char *reply,
1161 pos = os_strchr(cmd, ' ');
1166 if (os_strcmp(cmd, "WPS") == 0)
1168 else if (os_strcmp(cmd, "NDEF") == 0)
1173 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
1176 return wpas_ctrl_nfc_get_handover_req_wps(
1177 wpa_s, reply, max_len, ndef);
1181 if (os_strcmp(pos, "P2P-CR") == 0) {
1182 return wpas_ctrl_nfc_get_handover_req_p2p(
1183 wpa_s, reply, max_len, ndef);
1185 #endif /* CONFIG_P2P */
1191 static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant *wpa_s,
1192 char *reply, size_t max_len,
1193 int ndef, int cr, char *uuid)
1198 buf = wpas_wps_nfc_handover_sel(wpa_s, ndef, cr, uuid);
1202 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1204 reply[res++] = '\n';
1214 static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant *wpa_s,
1215 char *reply, size_t max_len,
1221 buf = wpas_p2p_nfc_handover_sel(wpa_s, ndef, tag);
1225 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1227 reply[res++] = '\n';
1234 #endif /* CONFIG_P2P */
1237 static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant *wpa_s,
1238 char *cmd, char *reply,
1244 pos = os_strchr(cmd, ' ');
1249 if (os_strcmp(cmd, "WPS") == 0)
1251 else if (os_strcmp(cmd, "NDEF") == 0)
1256 pos2 = os_strchr(pos, ' ');
1259 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
1262 return wpas_ctrl_nfc_get_handover_sel_wps(
1263 wpa_s, reply, max_len, ndef,
1264 os_strcmp(pos, "WPS-CR") == 0, pos2);
1268 if (os_strcmp(pos, "P2P-CR") == 0) {
1269 return wpas_ctrl_nfc_get_handover_sel_p2p(
1270 wpa_s, reply, max_len, ndef, 0);
1273 if (os_strcmp(pos, "P2P-CR-TAG") == 0) {
1274 return wpas_ctrl_nfc_get_handover_sel_p2p(
1275 wpa_s, reply, max_len, ndef, 1);
1277 #endif /* CONFIG_P2P */
1283 static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant *wpa_s,
1287 struct wpabuf *req, *sel;
1289 char *pos, *role, *type, *pos2;
1292 int forced_freq = 0;
1294 freq = strstr(cmd, " freq=");
1298 forced_freq = atoi(freq);
1300 #endif /* CONFIG_P2P */
1303 pos = os_strchr(role, ' ');
1305 wpa_printf(MSG_DEBUG, "NFC: Missing type in handover report");
1311 pos = os_strchr(type, ' ');
1313 wpa_printf(MSG_DEBUG, "NFC: Missing request message in handover report");
1318 pos2 = os_strchr(pos, ' ');
1320 wpa_printf(MSG_DEBUG, "NFC: Missing select message in handover report");
1325 len = os_strlen(pos);
1327 wpa_printf(MSG_DEBUG, "NFC: Invalid request message length in handover report");
1332 req = wpabuf_alloc(len);
1334 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for request message");
1337 if (hexstr2bin(pos, wpabuf_put(req, len), len) < 0) {
1338 wpa_printf(MSG_DEBUG, "NFC: Invalid request message hexdump in handover report");
1343 len = os_strlen(pos2);
1345 wpa_printf(MSG_DEBUG, "NFC: Invalid select message length in handover report");
1351 sel = wpabuf_alloc(len);
1353 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for select message");
1357 if (hexstr2bin(pos2, wpabuf_put(sel, len), len) < 0) {
1358 wpa_printf(MSG_DEBUG, "NFC: Invalid select message hexdump in handover report");
1364 wpa_printf(MSG_DEBUG, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d",
1365 role, type, (int) wpabuf_len(req), (int) wpabuf_len(sel));
1367 if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "WPS") == 0) {
1368 ret = wpas_wps_nfc_report_handover(wpa_s, req, sel);
1370 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "WPS") == 0)
1372 ret = wpas_ap_wps_nfc_report_handover(wpa_s, req, sel);
1374 ret = wpas_er_wps_nfc_report_handover(wpa_s, req, sel);
1375 #endif /* CONFIG_AP */
1377 } else if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "P2P") == 0)
1379 ret = wpas_p2p_nfc_report_handover(wpa_s, 1, req, sel, 0);
1380 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "P2P") == 0)
1382 ret = wpas_p2p_nfc_report_handover(wpa_s, 0, req, sel,
1384 #endif /* CONFIG_P2P */
1386 wpa_printf(MSG_DEBUG, "NFC: Unsupported connection handover "
1387 "reported: role=%s type=%s", role, type);
1394 wpa_printf(MSG_DEBUG, "NFC: Failed to process reported handover messages");
1399 #endif /* CONFIG_WPS_NFC */
1402 static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s,
1411 struct wps_new_ap_settings ap;
1413 pin = os_strchr(cmd, ' ');
1418 if (hwaddr_aton(cmd, bssid)) {
1419 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
1424 new_ssid = os_strchr(pin, ' ');
1425 if (new_ssid == NULL)
1426 return wpas_wps_start_reg(wpa_s, bssid, pin, NULL);
1429 new_auth = os_strchr(new_ssid, ' ');
1430 if (new_auth == NULL)
1434 new_encr = os_strchr(new_auth, ' ');
1435 if (new_encr == NULL)
1439 new_key = os_strchr(new_encr, ' ');
1440 if (new_key == NULL)
1444 os_memset(&ap, 0, sizeof(ap));
1445 ap.ssid_hex = new_ssid;
1448 ap.key_hex = new_key;
1449 return wpas_wps_start_reg(wpa_s, bssid, pin, &ap);
1454 static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant *wpa_s,
1455 char *cmd, char *buf,
1460 const char *pin_txt;
1462 if (!wpa_s->ap_iface)
1465 pos = os_strchr(cmd, ' ');
1469 if (os_strcmp(cmd, "disable") == 0) {
1470 wpas_wps_ap_pin_disable(wpa_s);
1471 return os_snprintf(buf, buflen, "OK\n");
1474 if (os_strcmp(cmd, "random") == 0) {
1476 timeout = atoi(pos);
1477 pin_txt = wpas_wps_ap_pin_random(wpa_s, timeout);
1478 if (pin_txt == NULL)
1480 return os_snprintf(buf, buflen, "%s", pin_txt);
1483 if (os_strcmp(cmd, "get") == 0) {
1484 pin_txt = wpas_wps_ap_pin_get(wpa_s);
1485 if (pin_txt == NULL)
1487 return os_snprintf(buf, buflen, "%s", pin_txt);
1490 if (os_strcmp(cmd, "set") == 0) {
1495 pos = os_strchr(pos, ' ');
1498 timeout = atoi(pos);
1500 if (os_strlen(pin) > buflen)
1502 if (wpas_wps_ap_pin_set(wpa_s, pin, timeout) < 0)
1504 return os_snprintf(buf, buflen, "%s", pin);
1509 #endif /* CONFIG_AP */
1512 #ifdef CONFIG_WPS_ER
1513 static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant *wpa_s,
1516 char *uuid = cmd, *pin, *pos;
1517 u8 addr_buf[ETH_ALEN], *addr = NULL;
1518 pin = os_strchr(uuid, ' ');
1522 pos = os_strchr(pin, ' ');
1525 if (hwaddr_aton(pos, addr_buf) == 0)
1528 return wpas_wps_er_add_pin(wpa_s, addr, uuid, pin);
1532 static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant *wpa_s,
1535 char *uuid = cmd, *pin;
1536 pin = os_strchr(uuid, ' ');
1540 return wpas_wps_er_learn(wpa_s, uuid, pin);
1544 static int wpa_supplicant_ctrl_iface_wps_er_set_config(
1545 struct wpa_supplicant *wpa_s, char *cmd)
1547 char *uuid = cmd, *id;
1548 id = os_strchr(uuid, ' ');
1552 return wpas_wps_er_set_config(wpa_s, uuid, atoi(id));
1556 static int wpa_supplicant_ctrl_iface_wps_er_config(
1557 struct wpa_supplicant *wpa_s, char *cmd)
1564 struct wps_new_ap_settings ap;
1566 pin = os_strchr(cmd, ' ');
1571 new_ssid = os_strchr(pin, ' ');
1572 if (new_ssid == NULL)
1576 new_auth = os_strchr(new_ssid, ' ');
1577 if (new_auth == NULL)
1581 new_encr = os_strchr(new_auth, ' ');
1582 if (new_encr == NULL)
1586 new_key = os_strchr(new_encr, ' ');
1587 if (new_key == NULL)
1591 os_memset(&ap, 0, sizeof(ap));
1592 ap.ssid_hex = new_ssid;
1595 ap.key_hex = new_key;
1596 return wpas_wps_er_config(wpa_s, cmd, pin, &ap);
1600 #ifdef CONFIG_WPS_NFC
1601 static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
1602 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1609 uuid = os_strchr(cmd, ' ');
1614 if (os_strcmp(cmd, "WPS") == 0)
1616 else if (os_strcmp(cmd, "NDEF") == 0)
1621 buf = wpas_wps_er_nfc_config_token(wpa_s, ndef, uuid);
1625 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1627 reply[res++] = '\n';
1634 #endif /* CONFIG_WPS_NFC */
1635 #endif /* CONFIG_WPS_ER */
1637 #endif /* CONFIG_WPS */
1640 #ifdef CONFIG_IBSS_RSN
1641 static int wpa_supplicant_ctrl_iface_ibss_rsn(
1642 struct wpa_supplicant *wpa_s, char *addr)
1646 if (hwaddr_aton(addr, peer)) {
1647 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN: invalid "
1648 "address '%s'", addr);
1652 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN " MACSTR,
1655 return ibss_rsn_start(wpa_s->ibss_rsn, peer);
1657 #endif /* CONFIG_IBSS_RSN */
1660 static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s,
1663 #ifdef IEEE8021X_EAPOL
1666 struct wpa_ssid *ssid;
1668 pos = os_strchr(rsp, '-');
1673 pos = os_strchr(pos, ':');
1678 wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id);
1679 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
1680 (u8 *) pos, os_strlen(pos));
1682 ssid = wpa_config_get_network(wpa_s->conf, id);
1684 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
1689 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s, ssid, rsp,
1691 #else /* IEEE8021X_EAPOL */
1692 wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included");
1694 #endif /* IEEE8021X_EAPOL */
1698 static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
1700 char *buf, size_t buflen)
1702 char *pos, *end, tmp[30];
1703 int res, verbose, wps, ret;
1706 #endif /* CONFIG_HS20 */
1710 if (os_strcmp(params, "-DRIVER") == 0)
1711 return wpa_drv_status(wpa_s, buf, buflen);
1712 verbose = os_strcmp(params, "-VERBOSE") == 0;
1713 wps = os_strcmp(params, "-WPS") == 0;
1716 if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
1717 struct wpa_ssid *ssid = wpa_s->current_ssid;
1718 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
1719 MAC2STR(wpa_s->bssid));
1720 if (os_snprintf_error(end - pos, ret))
1723 ret = os_snprintf(pos, end - pos, "freq=%u\n",
1725 if (os_snprintf_error(end - pos, ret))
1729 u8 *_ssid = ssid->ssid;
1730 size_t ssid_len = ssid->ssid_len;
1731 u8 ssid_buf[MAX_SSID_LEN];
1732 if (ssid_len == 0) {
1733 int _res = wpa_drv_get_ssid(wpa_s, ssid_buf);
1740 ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n",
1741 wpa_ssid_txt(_ssid, ssid_len),
1743 if (os_snprintf_error(end - pos, ret))
1747 if (wps && ssid->passphrase &&
1748 wpa_key_mgmt_wpa_psk(ssid->key_mgmt) &&
1749 (ssid->mode == WPAS_MODE_AP ||
1750 ssid->mode == WPAS_MODE_P2P_GO)) {
1751 ret = os_snprintf(pos, end - pos,
1754 if (os_snprintf_error(end - pos, ret))
1759 ret = os_snprintf(pos, end - pos,
1762 if (os_snprintf_error(end - pos, ret))
1767 switch (ssid->mode) {
1768 case WPAS_MODE_INFRA:
1769 ret = os_snprintf(pos, end - pos,
1772 case WPAS_MODE_IBSS:
1773 ret = os_snprintf(pos, end - pos,
1777 ret = os_snprintf(pos, end - pos,
1780 case WPAS_MODE_P2P_GO:
1781 ret = os_snprintf(pos, end - pos,
1784 case WPAS_MODE_P2P_GROUP_FORMATION:
1785 ret = os_snprintf(pos, end - pos,
1786 "mode=P2P GO - group "
1793 if (os_snprintf_error(end - pos, ret))
1799 if (wpa_s->ap_iface) {
1800 pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos,
1804 #endif /* CONFIG_AP */
1805 pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose);
1808 if (wpa_s->wpa_state >= WPA_ASSOCIATED &&
1811 #endif /* CONFIG_AP */
1812 wpa_s->sme.sae.state == SAE_ACCEPTED) {
1813 ret = os_snprintf(pos, end - pos, "sae_group=%d\n",
1814 wpa_s->sme.sae.group);
1815 if (os_snprintf_error(end - pos, ret))
1819 #endif /* CONFIG_SAE */
1820 ret = os_snprintf(pos, end - pos, "wpa_state=%s\n",
1821 wpa_supplicant_state_txt(wpa_s->wpa_state));
1822 if (os_snprintf_error(end - pos, ret))
1827 l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) {
1828 ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp);
1829 if (os_snprintf_error(end - pos, ret))
1835 if (wpa_s->global->p2p) {
1836 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
1837 "\n", MAC2STR(wpa_s->global->p2p_dev_addr));
1838 if (os_snprintf_error(end - pos, ret))
1842 #endif /* CONFIG_P2P */
1844 ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n",
1845 MAC2STR(wpa_s->own_addr));
1846 if (os_snprintf_error(end - pos, ret))
1851 if (wpa_s->current_bss &&
1852 (hs20 = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1853 HS20_IE_VENDOR_TYPE)) &&
1854 wpa_s->wpa_proto == WPA_PROTO_RSN &&
1855 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1858 u8 rel_num = (hs20[6] & 0xf0) >> 4;
1859 release = rel_num + 1;
1861 ret = os_snprintf(pos, end - pos, "hs20=%d\n", release);
1862 if (os_snprintf_error(end - pos, ret))
1867 if (wpa_s->current_ssid) {
1868 struct wpa_cred *cred;
1871 for (cred = wpa_s->conf->cred; cred; cred = cred->next) {
1874 if (wpa_s->current_ssid->parent_cred != cred)
1877 if (cred->provisioning_sp) {
1878 ret = os_snprintf(pos, end - pos,
1879 "provisioning_sp=%s\n",
1880 cred->provisioning_sp);
1881 if (os_snprintf_error(end - pos, ret))
1890 if (wpa_s->current_bss && wpa_s->current_bss->anqp) {
1891 struct wpabuf *names =
1892 wpa_s->current_bss->anqp->domain_name;
1893 for (i = 0; names && i < cred->num_domain; i++)
1895 if (domain_name_list_contains(
1896 names, cred->domain[i], 1))
1899 if (i == cred->num_domain)
1900 i = 0; /* show first entry by default */
1902 ret = os_snprintf(pos, end - pos, "home_sp=%s\n",
1904 if (os_snprintf_error(end - pos, ret))
1909 if (wpa_s->current_bss == NULL ||
1910 wpa_s->current_bss->anqp == NULL)
1913 res = interworking_home_sp_cred(
1915 wpa_s->current_bss->anqp->domain_name);
1923 ret = os_snprintf(pos, end - pos, "sp_type=%s\n", type);
1924 if (os_snprintf_error(end - pos, ret))
1931 #endif /* CONFIG_HS20 */
1933 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
1934 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
1935 res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos,
1941 sess_id = eapol_sm_get_session_id(wpa_s->eapol, &sess_id_len);
1945 ret = os_snprintf(pos, end - pos, "eap_session_id=");
1946 if (os_snprintf_error(end - pos, ret))
1949 ret = wpa_snprintf_hex(pos, end - pos, sess_id, sess_id_len);
1953 ret = os_snprintf(pos, end - pos, "\n");
1954 if (os_snprintf_error(end - pos, ret))
1959 res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose);
1966 uuid_bin2str(wpa_s->wps->uuid, uuid_str, sizeof(uuid_str));
1967 ret = os_snprintf(pos, end - pos, "uuid=%s\n", uuid_str);
1968 if (os_snprintf_error(end - pos, ret))
1972 #endif /* CONFIG_WPS */
1976 * Allow using the STATUS command with default behavior, say for debug,
1977 * i.e., don't generate a "fake" CONNECTION and SUPPLICANT_STATE_CHANGE
1978 * events with STATUS-NO_EVENTS.
1980 if (os_strcmp(params, "-NO_EVENTS")) {
1981 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_STATE_CHANGE
1982 "id=%d state=%d BSSID=" MACSTR " SSID=%s",
1983 wpa_s->current_ssid ? wpa_s->current_ssid->id : -1,
1985 MAC2STR(wpa_s->bssid),
1986 wpa_s->current_ssid && wpa_s->current_ssid->ssid ?
1987 wpa_ssid_txt(wpa_s->current_ssid->ssid,
1988 wpa_s->current_ssid->ssid_len) : "");
1989 if (wpa_s->wpa_state == WPA_COMPLETED) {
1990 struct wpa_ssid *ssid = wpa_s->current_ssid;
1991 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_CONNECTED
1992 "- connection to " MACSTR
1993 " completed %s [id=%d id_str=%s]",
1994 MAC2STR(wpa_s->bssid), "(auth)",
1995 ssid ? ssid->id : -1,
1996 ssid && ssid->id_str ? ssid->id_str : "");
1999 #endif /* ANDROID */
2005 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s,
2010 struct wpa_ssid *ssid;
2013 /* cmd: "<network id> <BSSID>" */
2014 pos = os_strchr(cmd, ' ');
2019 wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos);
2020 if (hwaddr_aton(pos, bssid)) {
2021 wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos);
2025 ssid = wpa_config_get_network(wpa_s->conf, id);
2027 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
2032 os_memcpy(ssid->bssid, bssid, ETH_ALEN);
2033 ssid->bssid_set = !is_zero_ether_addr(bssid);
2039 static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant *wpa_s,
2040 char *cmd, char *buf,
2044 struct wpa_blacklist *e;
2048 /* cmd: "BLACKLIST [<BSSID>]" */
2052 e = wpa_s->blacklist;
2054 ret = os_snprintf(pos, end - pos, MACSTR "\n",
2056 if (os_snprintf_error(end - pos, ret))
2065 if (os_strncmp(cmd, "clear", 5) == 0) {
2066 wpa_blacklist_clear(wpa_s);
2067 os_memcpy(buf, "OK\n", 3);
2071 wpa_printf(MSG_DEBUG, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd);
2072 if (hwaddr_aton(cmd, bssid)) {
2073 wpa_printf(MSG_DEBUG, "CTRL_IFACE: invalid BSSID '%s'", cmd);
2078 * Add the BSSID twice, so its count will be 2, causing it to be
2079 * skipped when processing scan results.
2081 ret = wpa_blacklist_add(wpa_s, bssid);
2084 ret = wpa_blacklist_add(wpa_s, bssid);
2087 os_memcpy(buf, "OK\n", 3);
2092 static const char * debug_level_str(int level)
2113 static int str_to_debug_level(const char *s)
2115 if (os_strcasecmp(s, "EXCESSIVE") == 0)
2116 return MSG_EXCESSIVE;
2117 if (os_strcasecmp(s, "MSGDUMP") == 0)
2119 if (os_strcasecmp(s, "DEBUG") == 0)
2121 if (os_strcasecmp(s, "INFO") == 0)
2123 if (os_strcasecmp(s, "WARNING") == 0)
2125 if (os_strcasecmp(s, "ERROR") == 0)
2131 static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant *wpa_s,
2132 char *cmd, char *buf,
2135 char *pos, *end, *stamp;
2138 /* cmd: "LOG_LEVEL [<level>]" */
2142 ret = os_snprintf(pos, end - pos, "Current level: %s\n"
2144 debug_level_str(wpa_debug_level),
2145 wpa_debug_timestamp);
2146 if (os_snprintf_error(end - pos, ret))
2155 stamp = os_strchr(cmd, ' ');
2158 while (*stamp == ' ') {
2163 if (cmd && os_strlen(cmd)) {
2164 int level = str_to_debug_level(cmd);
2167 wpa_debug_level = level;
2170 if (stamp && os_strlen(stamp))
2171 wpa_debug_timestamp = atoi(stamp);
2173 os_memcpy(buf, "OK\n", 3);
2178 static int wpa_supplicant_ctrl_iface_list_networks(
2179 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
2181 char *pos, *end, *prev;
2182 struct wpa_ssid *ssid;
2187 ret = os_snprintf(pos, end - pos,
2188 "network id / ssid / bssid / flags\n");
2189 if (os_snprintf_error(end - pos, ret))
2193 ssid = wpa_s->conf->ssid;
2195 /* skip over ssids until we find next one */
2196 if (cmd != NULL && os_strncmp(cmd, "LAST_ID=", 8) == 0) {
2197 int last_id = atoi(cmd + 8);
2198 if (last_id != -1) {
2199 while (ssid != NULL && ssid->id <= last_id) {
2207 ret = os_snprintf(pos, end - pos, "%d\t%s",
2209 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
2210 if (os_snprintf_error(end - pos, ret))
2213 if (ssid->bssid_set) {
2214 ret = os_snprintf(pos, end - pos, "\t" MACSTR,
2215 MAC2STR(ssid->bssid));
2217 ret = os_snprintf(pos, end - pos, "\tany");
2219 if (os_snprintf_error(end - pos, ret))
2222 ret = os_snprintf(pos, end - pos, "\t%s%s%s%s",
2223 ssid == wpa_s->current_ssid ?
2225 ssid->disabled ? "[DISABLED]" : "",
2226 ssid->disabled_until.sec ?
2227 "[TEMP-DISABLED]" : "",
2228 ssid->disabled == 2 ? "[P2P-PERSISTENT]" :
2230 if (os_snprintf_error(end - pos, ret))
2233 ret = os_snprintf(pos, end - pos, "\n");
2234 if (os_snprintf_error(end - pos, ret))
2245 static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher)
2248 ret = os_snprintf(pos, end - pos, "-");
2249 if (os_snprintf_error(end - pos, ret))
2252 ret = wpa_write_ciphers(pos, end, cipher, "+");
2260 static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
2261 const u8 *ie, size_t ie_len)
2263 struct wpa_ie_data data;
2267 ret = os_snprintf(pos, end - pos, "[%s-", proto);
2268 if (os_snprintf_error(end - pos, ret))
2272 if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) {
2273 ret = os_snprintf(pos, end - pos, "?]");
2274 if (os_snprintf_error(end - pos, ret))
2281 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
2282 ret = os_snprintf(pos, end - pos, "%sEAP",
2283 pos == start ? "" : "+");
2284 if (os_snprintf_error(end - pos, ret))
2288 if (data.key_mgmt & WPA_KEY_MGMT_PSK) {
2289 ret = os_snprintf(pos, end - pos, "%sPSK",
2290 pos == start ? "" : "+");
2291 if (os_snprintf_error(end - pos, ret))
2295 if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
2296 ret = os_snprintf(pos, end - pos, "%sNone",
2297 pos == start ? "" : "+");
2298 if (os_snprintf_error(end - pos, ret))
2302 if (data.key_mgmt & WPA_KEY_MGMT_SAE) {
2303 ret = os_snprintf(pos, end - pos, "%sSAE",
2304 pos == start ? "" : "+");
2305 if (os_snprintf_error(end - pos, ret))
2309 #ifdef CONFIG_IEEE80211R
2310 if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
2311 ret = os_snprintf(pos, end - pos, "%sFT/EAP",
2312 pos == start ? "" : "+");
2313 if (os_snprintf_error(end - pos, ret))
2317 if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) {
2318 ret = os_snprintf(pos, end - pos, "%sFT/PSK",
2319 pos == start ? "" : "+");
2320 if (os_snprintf_error(end - pos, ret))
2324 if (data.key_mgmt & WPA_KEY_MGMT_FT_SAE) {
2325 ret = os_snprintf(pos, end - pos, "%sFT/SAE",
2326 pos == start ? "" : "+");
2327 if (os_snprintf_error(end - pos, ret))
2331 #endif /* CONFIG_IEEE80211R */
2332 #ifdef CONFIG_IEEE80211W
2333 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
2334 ret = os_snprintf(pos, end - pos, "%sEAP-SHA256",
2335 pos == start ? "" : "+");
2336 if (os_snprintf_error(end - pos, ret))
2340 if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
2341 ret = os_snprintf(pos, end - pos, "%sPSK-SHA256",
2342 pos == start ? "" : "+");
2343 if (os_snprintf_error(end - pos, ret))
2347 #endif /* CONFIG_IEEE80211W */
2349 #ifdef CONFIG_SUITEB
2350 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B) {
2351 ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B",
2352 pos == start ? "" : "+");
2353 if (os_snprintf_error(end - pos, ret))
2357 #endif /* CONFIG_SUITEB */
2359 #ifdef CONFIG_SUITEB192
2360 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) {
2361 ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B-192",
2362 pos == start ? "" : "+");
2363 if (os_snprintf_error(end - pos, ret))
2367 #endif /* CONFIG_SUITEB192 */
2369 pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher);
2371 if (data.capabilities & WPA_CAPABILITY_PREAUTH) {
2372 ret = os_snprintf(pos, end - pos, "-preauth");
2373 if (os_snprintf_error(end - pos, ret))
2378 ret = os_snprintf(pos, end - pos, "]");
2379 if (os_snprintf_error(end - pos, ret))
2388 static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s,
2389 char *pos, char *end,
2390 struct wpabuf *wps_ie)
2397 if (wps_is_selected_pbc_registrar(wps_ie))
2399 else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0))
2401 else if (wps_is_selected_pin_registrar(wps_ie))
2406 ret = os_snprintf(pos, end - pos, "%s", txt);
2407 if (!os_snprintf_error(end - pos, ret))
2409 wpabuf_free(wps_ie);
2412 #endif /* CONFIG_WPS */
2415 static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s,
2416 char *pos, char *end,
2417 const struct wpa_bss *bss)
2420 struct wpabuf *wps_ie;
2421 wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
2422 return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie);
2423 #else /* CONFIG_WPS */
2425 #endif /* CONFIG_WPS */
2429 /* Format one result on one text line into a buffer. */
2430 static int wpa_supplicant_ctrl_iface_scan_result(
2431 struct wpa_supplicant *wpa_s,
2432 const struct wpa_bss *bss, char *buf, size_t buflen)
2436 const u8 *ie, *ie2, *p2p, *mesh;
2438 mesh = wpa_bss_get_ie(bss, WLAN_EID_MESH_ID);
2439 p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
2441 p2p = wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE);
2442 if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN &&
2443 os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) ==
2445 return 0; /* Do not show P2P listen discovery results here */
2450 ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t",
2451 MAC2STR(bss->bssid), bss->freq, bss->level);
2452 if (os_snprintf_error(end - pos, ret))
2455 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
2457 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]);
2458 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
2460 pos = wpa_supplicant_ie_txt(pos, end, mesh ? "RSN" : "WPA2",
2463 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
2464 if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
2465 ret = os_snprintf(pos, end - pos, "[WEP]");
2466 if (os_snprintf_error(end - pos, ret))
2471 ret = os_snprintf(pos, end - pos, "[MESH]");
2472 if (os_snprintf_error(end - pos, ret))
2476 if (bss_is_dmg(bss)) {
2478 ret = os_snprintf(pos, end - pos, "[DMG]");
2479 if (os_snprintf_error(end - pos, ret))
2482 switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
2483 case IEEE80211_CAP_DMG_IBSS:
2486 case IEEE80211_CAP_DMG_AP:
2489 case IEEE80211_CAP_DMG_PBSS:
2496 ret = os_snprintf(pos, end - pos, "%s", s);
2497 if (os_snprintf_error(end - pos, ret))
2501 if (bss->caps & IEEE80211_CAP_IBSS) {
2502 ret = os_snprintf(pos, end - pos, "[IBSS]");
2503 if (os_snprintf_error(end - pos, ret))
2507 if (bss->caps & IEEE80211_CAP_ESS) {
2508 ret = os_snprintf(pos, end - pos, "[ESS]");
2509 if (os_snprintf_error(end - pos, ret))
2515 ret = os_snprintf(pos, end - pos, "[P2P]");
2516 if (os_snprintf_error(end - pos, ret))
2521 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE) && ie2) {
2522 ret = os_snprintf(pos, end - pos, "[HS20]");
2523 if (os_snprintf_error(end - pos, ret))
2527 #endif /* CONFIG_HS20 */
2529 ret = os_snprintf(pos, end - pos, "\t%s",
2530 wpa_ssid_txt(bss->ssid, bss->ssid_len));
2531 if (os_snprintf_error(end - pos, ret))
2535 ret = os_snprintf(pos, end - pos, "\n");
2536 if (os_snprintf_error(end - pos, ret))
2544 static int wpa_supplicant_ctrl_iface_scan_results(
2545 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
2548 struct wpa_bss *bss;
2553 ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / "
2555 if (os_snprintf_error(end - pos, ret))
2559 dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
2560 ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos,
2562 if (ret < 0 || ret >= end - pos)
2573 static int wpa_supplicant_ctrl_iface_mesh_interface_add(
2574 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
2576 char *pos, ifname[IFNAMSIZ + 1];
2580 pos = os_strstr(cmd, "ifname=");
2583 os_strlcpy(ifname, pos, sizeof(ifname));
2586 if (wpas_mesh_add_interface(wpa_s, ifname, sizeof(ifname)) < 0)
2589 os_strlcpy(reply, ifname, max_len);
2590 return os_strlen(ifname);
2594 static int wpa_supplicant_ctrl_iface_mesh_group_add(
2595 struct wpa_supplicant *wpa_s, char *cmd)
2598 struct wpa_ssid *ssid;
2601 wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_ADD id=%d", id);
2603 ssid = wpa_config_get_network(wpa_s->conf, id);
2605 wpa_printf(MSG_DEBUG,
2606 "CTRL_IFACE: Could not find network id=%d", id);
2609 if (ssid->mode != WPAS_MODE_MESH) {
2610 wpa_printf(MSG_DEBUG,
2611 "CTRL_IFACE: Cannot use MESH_GROUP_ADD on a non mesh network");
2614 if (ssid->key_mgmt != WPA_KEY_MGMT_NONE &&
2615 ssid->key_mgmt != WPA_KEY_MGMT_SAE) {
2616 wpa_printf(MSG_ERROR,
2617 "CTRL_IFACE: key_mgmt for mesh network should be open or SAE");
2622 * TODO: If necessary write our own group_add function,
2623 * for now we can reuse select_network
2625 wpa_supplicant_select_network(wpa_s, ssid);
2631 static int wpa_supplicant_ctrl_iface_mesh_group_remove(
2632 struct wpa_supplicant *wpa_s, char *cmd)
2634 struct wpa_supplicant *orig;
2635 struct wpa_global *global;
2638 wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s", cmd);
2640 global = wpa_s->global;
2643 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
2644 if (os_strcmp(wpa_s->ifname, cmd) == 0) {
2650 wpa_printf(MSG_ERROR,
2651 "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s not found",
2655 if (wpa_s->mesh_if_created && wpa_s == orig) {
2656 wpa_printf(MSG_ERROR,
2657 "CTRL_IFACE: MESH_GROUP_REMOVE can't remove itself");
2661 wpa_s->reassociate = 0;
2662 wpa_s->disconnected = 1;
2663 wpa_supplicant_cancel_sched_scan(wpa_s);
2664 wpa_supplicant_cancel_scan(wpa_s);
2667 * TODO: If necessary write our own group_remove function,
2668 * for now we can reuse deauthenticate
2670 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2672 if (wpa_s->mesh_if_created)
2673 wpa_supplicant_remove_iface(global, wpa_s, 0);
2678 #endif /* CONFIG_MESH */
2681 static int wpa_supplicant_ctrl_iface_select_network(
2682 struct wpa_supplicant *wpa_s, char *cmd)
2685 struct wpa_ssid *ssid;
2688 /* cmd: "<network id>" or "any" */
2689 if (os_strncmp(cmd, "any", 3) == 0) {
2690 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any");
2694 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id);
2696 ssid = wpa_config_get_network(wpa_s->conf, id);
2698 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2699 "network id=%d", id);
2702 if (ssid->disabled == 2) {
2703 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2704 "SELECT_NETWORK with persistent P2P group");
2709 pos = os_strstr(cmd, " freq=");
2711 int *freqs = freq_range_to_channel_list(wpa_s, pos + 6);
2713 wpa_s->scan_req = MANUAL_SCAN_REQ;
2714 os_free(wpa_s->manual_scan_freqs);
2715 wpa_s->manual_scan_freqs = freqs;
2719 wpa_supplicant_select_network(wpa_s, ssid);
2725 static int wpa_supplicant_ctrl_iface_enable_network(
2726 struct wpa_supplicant *wpa_s, char *cmd)
2729 struct wpa_ssid *ssid;
2731 /* cmd: "<network id>" or "all" */
2732 if (os_strcmp(cmd, "all") == 0) {
2733 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all");
2737 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id);
2739 ssid = wpa_config_get_network(wpa_s->conf, id);
2741 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2742 "network id=%d", id);
2745 if (ssid->disabled == 2) {
2746 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2747 "ENABLE_NETWORK with persistent P2P group");
2751 if (os_strstr(cmd, " no-connect")) {
2756 wpa_supplicant_enable_network(wpa_s, ssid);
2762 static int wpa_supplicant_ctrl_iface_disable_network(
2763 struct wpa_supplicant *wpa_s, char *cmd)
2766 struct wpa_ssid *ssid;
2768 /* cmd: "<network id>" or "all" */
2769 if (os_strcmp(cmd, "all") == 0) {
2770 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all");
2774 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id);
2776 ssid = wpa_config_get_network(wpa_s->conf, id);
2778 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2779 "network id=%d", id);
2782 if (ssid->disabled == 2) {
2783 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2784 "DISABLE_NETWORK with persistent P2P "
2789 wpa_supplicant_disable_network(wpa_s, ssid);
2795 static int wpa_supplicant_ctrl_iface_add_network(
2796 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
2798 struct wpa_ssid *ssid;
2801 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK");
2803 ssid = wpa_config_add_network(wpa_s->conf);
2807 wpas_notify_network_added(wpa_s, ssid);
2810 wpa_config_set_network_defaults(ssid);
2812 ret = os_snprintf(buf, buflen, "%d\n", ssid->id);
2813 if (os_snprintf_error(buflen, ret))
2819 static int wpa_supplicant_ctrl_iface_remove_network(
2820 struct wpa_supplicant *wpa_s, char *cmd)
2823 struct wpa_ssid *ssid;
2826 /* cmd: "<network id>" or "all" */
2827 if (os_strcmp(cmd, "all") == 0) {
2828 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all");
2829 if (wpa_s->sched_scanning)
2830 wpa_supplicant_cancel_sched_scan(wpa_s);
2832 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2833 if (wpa_s->current_ssid) {
2835 wpa_s->sme.prev_bssid_set = 0;
2836 #endif /* CONFIG_SME */
2837 wpa_sm_set_config(wpa_s->wpa, NULL);
2838 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
2839 wpa_s->own_disconnect_req = 1;
2840 wpa_supplicant_deauthenticate(
2841 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2843 ssid = wpa_s->conf->ssid;
2845 struct wpa_ssid *remove_ssid = ssid;
2848 if (wpa_s->last_ssid == remove_ssid)
2849 wpa_s->last_ssid = NULL;
2850 wpas_notify_network_removed(wpa_s, remove_ssid);
2851 wpa_config_remove_network(wpa_s->conf, id);
2857 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id);
2859 ssid = wpa_config_get_network(wpa_s->conf, id);
2861 wpas_notify_network_removed(wpa_s, ssid);
2863 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2868 if (wpa_s->last_ssid == ssid)
2869 wpa_s->last_ssid = NULL;
2871 if (ssid == wpa_s->current_ssid || wpa_s->current_ssid == NULL) {
2873 wpa_s->sme.prev_bssid_set = 0;
2874 #endif /* CONFIG_SME */
2876 * Invalidate the EAP session cache if the current or
2877 * previously used network is removed.
2879 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2882 if (ssid == wpa_s->current_ssid) {
2883 wpa_sm_set_config(wpa_s->wpa, NULL);
2884 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
2886 wpa_s->own_disconnect_req = 1;
2887 wpa_supplicant_deauthenticate(wpa_s,
2888 WLAN_REASON_DEAUTH_LEAVING);
2891 was_disabled = ssid->disabled;
2893 if (wpa_config_remove_network(wpa_s->conf, id) < 0) {
2894 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Not able to remove the "
2895 "network id=%d", id);
2899 if (!was_disabled && wpa_s->sched_scanning) {
2900 wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to remove "
2901 "network from filters");
2902 wpa_supplicant_cancel_sched_scan(wpa_s);
2903 wpa_supplicant_req_scan(wpa_s, 0, 0);
2910 static int wpa_supplicant_ctrl_iface_update_network(
2911 struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
2912 char *name, char *value)
2914 if (wpa_config_set(ssid, name, value, 0) < 0) {
2915 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network "
2916 "variable '%s'", name);
2920 if (os_strcmp(name, "bssid") != 0 &&
2921 os_strcmp(name, "priority") != 0)
2922 wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
2924 if (wpa_s->current_ssid == ssid || wpa_s->current_ssid == NULL) {
2926 * Invalidate the EAP session cache if anything in the current
2927 * or previously used configuration changes.
2929 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2932 if ((os_strcmp(name, "psk") == 0 &&
2933 value[0] == '"' && ssid->ssid_len) ||
2934 (os_strcmp(name, "ssid") == 0 && ssid->passphrase))
2935 wpa_config_update_psk(ssid);
2936 else if (os_strcmp(name, "priority") == 0)
2937 wpa_config_update_prio_list(wpa_s->conf);
2943 static int wpa_supplicant_ctrl_iface_set_network(
2944 struct wpa_supplicant *wpa_s, char *cmd)
2946 int id, ret, prev_bssid_set, prev_disabled;
2947 struct wpa_ssid *ssid;
2949 u8 prev_bssid[ETH_ALEN];
2951 /* cmd: "<network id> <variable name> <value>" */
2952 name = os_strchr(cmd, ' ');
2957 value = os_strchr(name, ' ');
2963 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
2965 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
2966 (u8 *) value, os_strlen(value));
2968 ssid = wpa_config_get_network(wpa_s->conf, id);
2970 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2975 prev_bssid_set = ssid->bssid_set;
2976 prev_disabled = ssid->disabled;
2977 os_memcpy(prev_bssid, ssid->bssid, ETH_ALEN);
2978 ret = wpa_supplicant_ctrl_iface_update_network(wpa_s, ssid, name,
2981 (ssid->bssid_set != prev_bssid_set ||
2982 os_memcmp(ssid->bssid, prev_bssid, ETH_ALEN) != 0))
2983 wpas_notify_network_bssid_set_changed(wpa_s, ssid);
2985 if (prev_disabled != ssid->disabled &&
2986 (prev_disabled == 2 || ssid->disabled == 2))
2987 wpas_notify_network_type_changed(wpa_s, ssid);
2993 static int wpa_supplicant_ctrl_iface_get_network(
2994 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
2998 struct wpa_ssid *ssid;
3001 /* cmd: "<network id> <variable name>" */
3002 name = os_strchr(cmd, ' ');
3003 if (name == NULL || buflen == 0)
3008 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
3011 ssid = wpa_config_get_network(wpa_s->conf, id);
3013 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
3018 value = wpa_config_get_no_key(ssid, name);
3019 if (value == NULL) {
3020 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
3021 "variable '%s'", name);
3025 res = os_strlcpy(buf, value, buflen);
3026 if (res >= buflen) {
3037 static int wpa_supplicant_ctrl_iface_dup_network(
3038 struct wpa_supplicant *wpa_s, char *cmd)
3040 struct wpa_ssid *ssid_s, *ssid_d;
3041 char *name, *id, *value;
3042 int id_s, id_d, ret;
3044 /* cmd: "<src network id> <dst network id> <variable name>" */
3045 id = os_strchr(cmd, ' ');
3050 name = os_strchr(id, ' ');
3057 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DUP_NETWORK id=%d -> %d name='%s'",
3060 ssid_s = wpa_config_get_network(wpa_s->conf, id_s);
3061 if (ssid_s == NULL) {
3062 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3063 "network id=%d", id_s);
3067 ssid_d = wpa_config_get_network(wpa_s->conf, id_d);
3068 if (ssid_d == NULL) {
3069 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3070 "network id=%d", id_d);
3074 value = wpa_config_get(ssid_s, name);
3075 if (value == NULL) {
3076 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
3077 "variable '%s'", name);
3081 ret = wpa_supplicant_ctrl_iface_update_network(wpa_s, ssid_d, name,
3090 static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant *wpa_s,
3091 char *buf, size_t buflen)
3094 struct wpa_cred *cred;
3099 ret = os_snprintf(pos, end - pos,
3100 "cred id / realm / username / domain / imsi\n");
3101 if (os_snprintf_error(end - pos, ret))
3105 cred = wpa_s->conf->cred;
3107 ret = os_snprintf(pos, end - pos, "%d\t%s\t%s\t%s\t%s\n",
3108 cred->id, cred->realm ? cred->realm : "",
3109 cred->username ? cred->username : "",
3110 cred->domain ? cred->domain[0] : "",
3111 cred->imsi ? cred->imsi : "");
3112 if (os_snprintf_error(end - pos, ret))
3123 static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant *wpa_s,
3124 char *buf, size_t buflen)
3126 struct wpa_cred *cred;
3129 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_CRED");
3131 cred = wpa_config_add_cred(wpa_s->conf);
3135 wpa_msg(wpa_s, MSG_INFO, CRED_ADDED "%d", cred->id);
3137 ret = os_snprintf(buf, buflen, "%d\n", cred->id);
3138 if (os_snprintf_error(buflen, ret))
3144 static int wpas_ctrl_remove_cred(struct wpa_supplicant *wpa_s,
3145 struct wpa_cred *cred)
3147 struct wpa_ssid *ssid;
3152 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred");
3157 if (wpa_config_remove_cred(wpa_s->conf, id) < 0) {
3158 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred");
3162 wpa_msg(wpa_s, MSG_INFO, CRED_REMOVED "%d", id);
3164 /* Remove any network entry created based on the removed credential */
3165 ssid = wpa_s->conf->ssid;
3167 if (ssid->parent_cred == cred) {
3170 wpa_printf(MSG_DEBUG, "Remove network id %d since it "
3171 "used the removed credential", ssid->id);
3172 res = os_snprintf(str, sizeof(str), "%d", ssid->id);
3173 if (os_snprintf_error(sizeof(str), res))
3174 str[sizeof(str) - 1] = '\0';
3176 wpa_supplicant_ctrl_iface_remove_network(wpa_s, str);
3185 static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s,
3189 struct wpa_cred *cred, *prev;
3191 /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or
3192 * "provisioning_sp=<FQDN> */
3193 if (os_strcmp(cmd, "all") == 0) {
3194 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED all");
3195 cred = wpa_s->conf->cred;
3199 wpas_ctrl_remove_cred(wpa_s, prev);
3204 if (os_strncmp(cmd, "sp_fqdn=", 8) == 0) {
3205 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
3207 cred = wpa_s->conf->cred;
3213 for (i = 0; i < prev->num_domain; i++) {
3214 if (os_strcmp(prev->domain[i], cmd + 8)
3217 wpas_ctrl_remove_cred(wpa_s, prev);
3225 if (os_strncmp(cmd, "provisioning_sp=", 16) == 0) {
3226 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'",
3228 cred = wpa_s->conf->cred;
3232 if (prev->provisioning_sp &&
3233 os_strcmp(prev->provisioning_sp, cmd + 16) == 0)
3234 wpas_ctrl_remove_cred(wpa_s, prev);
3240 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED id=%d", id);
3242 cred = wpa_config_get_cred(wpa_s->conf, id);
3243 return wpas_ctrl_remove_cred(wpa_s, cred);
3247 static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant *wpa_s,
3251 struct wpa_cred *cred;
3254 /* cmd: "<cred id> <variable name> <value>" */
3255 name = os_strchr(cmd, ' ');
3260 value = os_strchr(name, ' ');
3266 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_CRED id=%d name='%s'",
3268 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
3269 (u8 *) value, os_strlen(value));
3271 cred = wpa_config_get_cred(wpa_s->conf, id);
3273 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
3278 if (wpa_config_set_cred(cred, name, value, 0) < 0) {
3279 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set cred "
3280 "variable '%s'", name);
3284 wpa_msg(wpa_s, MSG_INFO, CRED_MODIFIED "%d %s", cred->id, name);
3290 static int wpa_supplicant_ctrl_iface_get_cred(struct wpa_supplicant *wpa_s,
3291 char *cmd, char *buf,
3296 struct wpa_cred *cred;
3299 /* cmd: "<cred id> <variable name>" */
3300 name = os_strchr(cmd, ' ');
3306 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CRED id=%d name='%s'",
3309 cred = wpa_config_get_cred(wpa_s->conf, id);
3311 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
3316 value = wpa_config_get_cred_no_key(cred, name);
3317 if (value == NULL) {
3318 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get cred variable '%s'",
3323 res = os_strlcpy(buf, value, buflen);
3324 if (res >= buflen) {
3335 #ifndef CONFIG_NO_CONFIG_WRITE
3336 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s)
3340 if (!wpa_s->conf->update_config) {
3341 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
3342 "to update configuration (update_config=0)");
3346 ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
3348 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to "
3349 "update configuration");
3351 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration"
3357 #endif /* CONFIG_NO_CONFIG_WRITE */
3360 struct cipher_info {
3366 static const struct cipher_info ciphers[] = {
3367 { WPA_DRIVER_CAPA_ENC_CCMP_256, "CCMP-256", 0 },
3368 { WPA_DRIVER_CAPA_ENC_GCMP_256, "GCMP-256", 0 },
3369 { WPA_DRIVER_CAPA_ENC_CCMP, "CCMP", 0 },
3370 { WPA_DRIVER_CAPA_ENC_GCMP, "GCMP", 0 },
3371 { WPA_DRIVER_CAPA_ENC_TKIP, "TKIP", 0 },
3372 { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE, "NONE", 0 },
3373 { WPA_DRIVER_CAPA_ENC_WEP104, "WEP104", 1 },
3374 { WPA_DRIVER_CAPA_ENC_WEP40, "WEP40", 1 }
3377 static const struct cipher_info ciphers_group_mgmt[] = {
3378 { WPA_DRIVER_CAPA_ENC_BIP, "AES-128-CMAC", 1 },
3379 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_128, "BIP-GMAC-128", 1 },
3380 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_256, "BIP-GMAC-256", 1 },
3381 { WPA_DRIVER_CAPA_ENC_BIP_CMAC_256, "BIP-CMAC-256", 1 },
3385 static int ctrl_iface_get_capability_pairwise(int res, char *strict,
3386 struct wpa_driver_capa *capa,
3387 char *buf, size_t buflen)
3400 len = os_strlcpy(buf, "CCMP TKIP NONE", buflen);
3406 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
3407 if (!ciphers[i].group_only && capa->enc & ciphers[i].capa) {
3408 ret = os_snprintf(pos, end - pos, "%s%s",
3409 pos == buf ? "" : " ",
3411 if (os_snprintf_error(end - pos, ret))
3421 static int ctrl_iface_get_capability_group(int res, char *strict,
3422 struct wpa_driver_capa *capa,
3423 char *buf, size_t buflen)
3436 len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen);
3442 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
3443 if (capa->enc & ciphers[i].capa) {
3444 ret = os_snprintf(pos, end - pos, "%s%s",
3445 pos == buf ? "" : " ",
3447 if (os_snprintf_error(end - pos, ret))
3457 static int ctrl_iface_get_capability_group_mgmt(int res, char *strict,
3458 struct wpa_driver_capa *capa,
3459 char *buf, size_t buflen)
3471 for (i = 0; i < ARRAY_SIZE(ciphers_group_mgmt); i++) {
3472 if (capa->enc & ciphers_group_mgmt[i].capa) {
3473 ret = os_snprintf(pos, end - pos, "%s%s",
3474 pos == buf ? "" : " ",
3475 ciphers_group_mgmt[i].name);
3476 if (os_snprintf_error(end - pos, ret))
3486 static int ctrl_iface_get_capability_key_mgmt(int res, char *strict,
3487 struct wpa_driver_capa *capa,
3488 char *buf, size_t buflen)
3500 len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
3507 ret = os_snprintf(pos, end - pos, "NONE IEEE8021X");
3508 if (os_snprintf_error(end - pos, ret))
3512 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
3513 WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
3514 ret = os_snprintf(pos, end - pos, " WPA-EAP");
3515 if (os_snprintf_error(end - pos, ret))
3520 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
3521 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
3522 ret = os_snprintf(pos, end - pos, " WPA-PSK");
3523 if (os_snprintf_error(end - pos, ret))
3528 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
3529 ret = os_snprintf(pos, end - pos, " WPA-NONE");
3530 if (os_snprintf_error(end - pos, ret))
3535 #ifdef CONFIG_SUITEB
3536 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B) {
3537 ret = os_snprintf(pos, end - pos, " WPA-EAP-SUITE-B");
3538 if (os_snprintf_error(end - pos, ret))
3542 #endif /* CONFIG_SUITEB */
3543 #ifdef CONFIG_SUITEB192
3544 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192) {
3545 ret = os_snprintf(pos, end - pos, " WPA-EAP-SUITE-B-192");
3546 if (os_snprintf_error(end - pos, ret))
3550 #endif /* CONFIG_SUITEB192 */
3556 static int ctrl_iface_get_capability_proto(int res, char *strict,
3557 struct wpa_driver_capa *capa,
3558 char *buf, size_t buflen)
3570 len = os_strlcpy(buf, "RSN WPA", buflen);
3576 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
3577 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
3578 ret = os_snprintf(pos, end - pos, "%sRSN",
3579 pos == buf ? "" : " ");
3580 if (os_snprintf_error(end - pos, ret))
3585 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
3586 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
3587 ret = os_snprintf(pos, end - pos, "%sWPA",
3588 pos == buf ? "" : " ");
3589 if (os_snprintf_error(end - pos, ret))
3598 static int ctrl_iface_get_capability_auth_alg(struct wpa_supplicant *wpa_s,
3599 int res, char *strict,
3600 struct wpa_driver_capa *capa,
3601 char *buf, size_t buflen)
3613 len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen);
3619 if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) {
3620 ret = os_snprintf(pos, end - pos, "%sOPEN",
3621 pos == buf ? "" : " ");
3622 if (os_snprintf_error(end - pos, ret))
3627 if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) {
3628 ret = os_snprintf(pos, end - pos, "%sSHARED",
3629 pos == buf ? "" : " ");
3630 if (os_snprintf_error(end - pos, ret))
3635 if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) {
3636 ret = os_snprintf(pos, end - pos, "%sLEAP",
3637 pos == buf ? "" : " ");
3638 if (os_snprintf_error(end - pos, ret))
3644 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE) {
3645 ret = os_snprintf(pos, end - pos, "%sSAE",
3646 pos == buf ? "" : " ");
3647 if (os_snprintf_error(end - pos, ret))
3651 #endif /* CONFIG_SAE */
3657 static int ctrl_iface_get_capability_modes(int res, char *strict,
3658 struct wpa_driver_capa *capa,
3659 char *buf, size_t buflen)
3671 len = os_strlcpy(buf, "IBSS AP", buflen);
3677 if (capa->flags & WPA_DRIVER_FLAGS_IBSS) {
3678 ret = os_snprintf(pos, end - pos, "%sIBSS",
3679 pos == buf ? "" : " ");
3680 if (os_snprintf_error(end - pos, ret))
3685 if (capa->flags & WPA_DRIVER_FLAGS_AP) {
3686 ret = os_snprintf(pos, end - pos, "%sAP",
3687 pos == buf ? "" : " ");
3688 if (os_snprintf_error(end - pos, ret))
3694 if (capa->flags & WPA_DRIVER_FLAGS_MESH) {
3695 ret = os_snprintf(pos, end - pos, "%sMESH",
3696 pos == buf ? "" : " ");
3697 if (os_snprintf_error(end - pos, ret))
3701 #endif /* CONFIG_MESH */
3707 static int ctrl_iface_get_capability_channels(struct wpa_supplicant *wpa_s,
3708 char *buf, size_t buflen)
3710 struct hostapd_channel_data *chnl;
3712 char *pos, *end, *hmode;
3717 for (j = 0; j < wpa_s->hw.num_modes; j++) {
3718 switch (wpa_s->hw.modes[j].mode) {
3719 case HOSTAPD_MODE_IEEE80211B:
3722 case HOSTAPD_MODE_IEEE80211G:
3725 case HOSTAPD_MODE_IEEE80211A:
3728 case HOSTAPD_MODE_IEEE80211AD:
3734 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:", hmode);
3735 if (os_snprintf_error(end - pos, ret))
3738 chnl = wpa_s->hw.modes[j].channels;
3739 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
3740 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
3742 ret = os_snprintf(pos, end - pos, " %d", chnl[i].chan);
3743 if (os_snprintf_error(end - pos, ret))
3747 ret = os_snprintf(pos, end - pos, "\n");
3748 if (os_snprintf_error(end - pos, ret))
3757 static int ctrl_iface_get_capability_freq(struct wpa_supplicant *wpa_s,
3758 char *buf, size_t buflen)
3760 struct hostapd_channel_data *chnl;
3762 char *pos, *end, *hmode;
3767 for (j = 0; j < wpa_s->hw.num_modes; j++) {
3768 switch (wpa_s->hw.modes[j].mode) {
3769 case HOSTAPD_MODE_IEEE80211B:
3772 case HOSTAPD_MODE_IEEE80211G:
3775 case HOSTAPD_MODE_IEEE80211A:
3778 case HOSTAPD_MODE_IEEE80211AD:
3784 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:\n",
3786 if (os_snprintf_error(end - pos, ret))
3789 chnl = wpa_s->hw.modes[j].channels;
3790 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
3791 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
3793 ret = os_snprintf(pos, end - pos, " %d = %d MHz%s%s\n",
3794 chnl[i].chan, chnl[i].freq,
3795 chnl[i].flag & HOSTAPD_CHAN_NO_IR ?
3797 chnl[i].flag & HOSTAPD_CHAN_RADAR ?
3800 if (os_snprintf_error(end - pos, ret))
3804 ret = os_snprintf(pos, end - pos, "\n");
3805 if (os_snprintf_error(end - pos, ret))
3814 static int wpa_supplicant_ctrl_iface_get_capability(
3815 struct wpa_supplicant *wpa_s, const char *_field, char *buf,
3818 struct wpa_driver_capa capa;
3824 /* Determine whether or not strict checking was requested */
3825 len = os_strlcpy(field, _field, sizeof(field));
3826 if (len >= sizeof(field))
3828 strict = os_strchr(field, ' ');
3829 if (strict != NULL) {
3831 if (os_strcmp(strict, "strict") != 0)
3835 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
3836 field, strict ? strict : "");
3838 if (os_strcmp(field, "eap") == 0) {
3839 return eap_get_names(buf, buflen);
3842 res = wpa_drv_get_capa(wpa_s, &capa);
3844 if (os_strcmp(field, "pairwise") == 0)
3845 return ctrl_iface_get_capability_pairwise(res, strict, &capa,
3848 if (os_strcmp(field, "group") == 0)
3849 return ctrl_iface_get_capability_group(res, strict, &capa,
3852 if (os_strcmp(field, "group_mgmt") == 0)
3853 return ctrl_iface_get_capability_group_mgmt(res, strict, &capa,
3856 if (os_strcmp(field, "key_mgmt") == 0)
3857 return ctrl_iface_get_capability_key_mgmt(res, strict, &capa,
3860 if (os_strcmp(field, "proto") == 0)
3861 return ctrl_iface_get_capability_proto(res, strict, &capa,
3864 if (os_strcmp(field, "auth_alg") == 0)
3865 return ctrl_iface_get_capability_auth_alg(wpa_s, res, strict,
3866 &capa, buf, buflen);
3868 if (os_strcmp(field, "modes") == 0)
3869 return ctrl_iface_get_capability_modes(res, strict, &capa,
3872 if (os_strcmp(field, "channels") == 0)
3873 return ctrl_iface_get_capability_channels(wpa_s, buf, buflen);
3875 if (os_strcmp(field, "freq") == 0)
3876 return ctrl_iface_get_capability_freq(wpa_s, buf, buflen);
3879 if (os_strcmp(field, "tdls") == 0)
3880 return ctrl_iface_get_capability_tdls(wpa_s, buf, buflen);
3881 #endif /* CONFIG_TDLS */
3884 if (os_strcmp(field, "erp") == 0) {
3885 res = os_snprintf(buf, buflen, "ERP");
3886 if (os_snprintf_error(buflen, res))
3890 #endif /* CONFIG_EPR */
3892 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
3899 #ifdef CONFIG_INTERWORKING
3900 static char * anqp_add_hex(char *pos, char *end, const char *title,
3901 struct wpabuf *data)
3911 ret = os_snprintf(pos, end - pos, "%s=", title);
3912 if (os_snprintf_error(end - pos, ret))
3916 d = wpabuf_head_u8(data);
3917 for (i = 0; i < wpabuf_len(data); i++) {
3918 ret = os_snprintf(pos, end - pos, "%02x", *d++);
3919 if (os_snprintf_error(end - pos, ret))
3924 ret = os_snprintf(pos, end - pos, "\n");
3925 if (os_snprintf_error(end - pos, ret))
3931 #endif /* CONFIG_INTERWORKING */
3934 static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
3935 unsigned long mask, char *buf, size_t buflen)
3945 if (mask & WPA_BSS_MASK_ID) {
3946 ret = os_snprintf(pos, end - pos, "id=%u\n", bss->id);
3947 if (os_snprintf_error(end - pos, ret))
3952 if (mask & WPA_BSS_MASK_BSSID) {
3953 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
3954 MAC2STR(bss->bssid));
3955 if (os_snprintf_error(end - pos, ret))
3960 if (mask & WPA_BSS_MASK_FREQ) {
3961 ret = os_snprintf(pos, end - pos, "freq=%d\n", bss->freq);
3962 if (os_snprintf_error(end - pos, ret))
3967 if (mask & WPA_BSS_MASK_BEACON_INT) {
3968 ret = os_snprintf(pos, end - pos, "beacon_int=%d\n",
3970 if (os_snprintf_error(end - pos, ret))
3975 if (mask & WPA_BSS_MASK_CAPABILITIES) {
3976 ret = os_snprintf(pos, end - pos, "capabilities=0x%04x\n",
3978 if (os_snprintf_error(end - pos, ret))
3983 if (mask & WPA_BSS_MASK_QUAL) {
3984 ret = os_snprintf(pos, end - pos, "qual=%d\n", bss->qual);
3985 if (os_snprintf_error(end - pos, ret))
3990 if (mask & WPA_BSS_MASK_NOISE) {
3991 ret = os_snprintf(pos, end - pos, "noise=%d\n", bss->noise);
3992 if (os_snprintf_error(end - pos, ret))
3997 if (mask & WPA_BSS_MASK_LEVEL) {
3998 ret = os_snprintf(pos, end - pos, "level=%d\n", bss->level);
3999 if (os_snprintf_error(end - pos, ret))
4004 if (mask & WPA_BSS_MASK_TSF) {
4005 ret = os_snprintf(pos, end - pos, "tsf=%016llu\n",
4006 (unsigned long long) bss->tsf);
4007 if (os_snprintf_error(end - pos, ret))
4012 if (mask & WPA_BSS_MASK_AGE) {
4013 struct os_reltime now;
4015 os_get_reltime(&now);
4016 ret = os_snprintf(pos, end - pos, "age=%d\n",
4017 (int) (now.sec - bss->last_update.sec));
4018 if (os_snprintf_error(end - pos, ret))
4023 if (mask & WPA_BSS_MASK_IE) {
4024 ret = os_snprintf(pos, end - pos, "ie=");
4025 if (os_snprintf_error(end - pos, ret))
4029 ie = (const u8 *) (bss + 1);
4030 for (i = 0; i < bss->ie_len; i++) {
4031 ret = os_snprintf(pos, end - pos, "%02x", *ie++);
4032 if (os_snprintf_error(end - pos, ret))
4037 ret = os_snprintf(pos, end - pos, "\n");
4038 if (os_snprintf_error(end - pos, ret))
4043 if (mask & WPA_BSS_MASK_FLAGS) {
4044 ret = os_snprintf(pos, end - pos, "flags=");
4045 if (os_snprintf_error(end - pos, ret))
4049 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
4051 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie,
4053 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
4055 pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2,
4057 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
4058 if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
4059 ret = os_snprintf(pos, end - pos, "[WEP]");
4060 if (os_snprintf_error(end - pos, ret))
4064 if (bss_is_dmg(bss)) {
4066 ret = os_snprintf(pos, end - pos, "[DMG]");
4067 if (os_snprintf_error(end - pos, ret))
4070 switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
4071 case IEEE80211_CAP_DMG_IBSS:
4074 case IEEE80211_CAP_DMG_AP:
4077 case IEEE80211_CAP_DMG_PBSS:
4084 ret = os_snprintf(pos, end - pos, "%s", s);
4085 if (os_snprintf_error(end - pos, ret))
4089 if (bss->caps & IEEE80211_CAP_IBSS) {
4090 ret = os_snprintf(pos, end - pos, "[IBSS]");
4091 if (os_snprintf_error(end - pos, ret))
4095 if (bss->caps & IEEE80211_CAP_ESS) {
4096 ret = os_snprintf(pos, end - pos, "[ESS]");
4097 if (os_snprintf_error(end - pos, ret))
4102 if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
4103 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
4104 ret = os_snprintf(pos, end - pos, "[P2P]");
4105 if (os_snprintf_error(end - pos, ret))
4110 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) {
4111 ret = os_snprintf(pos, end - pos, "[HS20]");
4112 if (os_snprintf_error(end - pos, ret))
4116 #endif /* CONFIG_HS20 */
4118 ret = os_snprintf(pos, end - pos, "\n");
4119 if (os_snprintf_error(end - pos, ret))
4124 if (mask & WPA_BSS_MASK_SSID) {
4125 ret = os_snprintf(pos, end - pos, "ssid=%s\n",
4126 wpa_ssid_txt(bss->ssid, bss->ssid_len));
4127 if (os_snprintf_error(end - pos, ret))
4133 if (mask & WPA_BSS_MASK_WPS_SCAN) {
4134 ie = (const u8 *) (bss + 1);
4135 ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end);
4136 if (ret < 0 || ret >= end - pos)
4140 #endif /* CONFIG_WPS */
4143 if (mask & WPA_BSS_MASK_P2P_SCAN) {
4144 ie = (const u8 *) (bss + 1);
4145 ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end);
4146 if (ret < 0 || ret >= end - pos)
4150 #endif /* CONFIG_P2P */
4152 #ifdef CONFIG_WIFI_DISPLAY
4153 if (mask & WPA_BSS_MASK_WIFI_DISPLAY) {
4155 ie = (const u8 *) (bss + 1);
4156 wfd = ieee802_11_vendor_ie_concat(ie, bss->ie_len,
4157 WFD_IE_VENDOR_TYPE);
4159 ret = os_snprintf(pos, end - pos, "wfd_subelems=");
4160 if (os_snprintf_error(end - pos, ret)) {
4166 pos += wpa_snprintf_hex(pos, end - pos,
4171 ret = os_snprintf(pos, end - pos, "\n");
4172 if (os_snprintf_error(end - pos, ret))
4177 #endif /* CONFIG_WIFI_DISPLAY */
4179 #ifdef CONFIG_INTERWORKING
4180 if ((mask & WPA_BSS_MASK_INTERNETW) && bss->anqp) {
4181 struct wpa_bss_anqp *anqp = bss->anqp;
4182 pos = anqp_add_hex(pos, end, "anqp_capability_list",
4183 anqp->capability_list);
4184 pos = anqp_add_hex(pos, end, "anqp_venue_name",
4186 pos = anqp_add_hex(pos, end, "anqp_network_auth_type",
4187 anqp->network_auth_type);
4188 pos = anqp_add_hex(pos, end, "anqp_roaming_consortium",
4189 anqp->roaming_consortium);
4190 pos = anqp_add_hex(pos, end, "anqp_ip_addr_type_availability",
4191 anqp->ip_addr_type_availability);
4192 pos = anqp_add_hex(pos, end, "anqp_nai_realm",
4194 pos = anqp_add_hex(pos, end, "anqp_3gpp", anqp->anqp_3gpp);
4195 pos = anqp_add_hex(pos, end, "anqp_domain_name",
4198 pos = anqp_add_hex(pos, end, "hs20_capability_list",
4199 anqp->hs20_capability_list);
4200 pos = anqp_add_hex(pos, end, "hs20_operator_friendly_name",
4201 anqp->hs20_operator_friendly_name);
4202 pos = anqp_add_hex(pos, end, "hs20_wan_metrics",
4203 anqp->hs20_wan_metrics);
4204 pos = anqp_add_hex(pos, end, "hs20_connection_capability",
4205 anqp->hs20_connection_capability);
4206 pos = anqp_add_hex(pos, end, "hs20_operating_class",
4207 anqp->hs20_operating_class);
4208 pos = anqp_add_hex(pos, end, "hs20_osu_providers_list",
4209 anqp->hs20_osu_providers_list);
4210 #endif /* CONFIG_HS20 */
4212 #endif /* CONFIG_INTERWORKING */
4215 if (mask & WPA_BSS_MASK_MESH_SCAN) {
4216 ie = (const u8 *) (bss + 1);
4217 ret = wpas_mesh_scan_result_text(ie, bss->ie_len, pos, end);
4218 if (ret < 0 || ret >= end - pos)
4222 #endif /* CONFIG_MESH */
4224 if (mask & WPA_BSS_MASK_SNR) {
4225 ret = os_snprintf(pos, end - pos, "snr=%d\n", bss->snr);
4226 if (os_snprintf_error(end - pos, ret))
4231 if (mask & WPA_BSS_MASK_EST_THROUGHPUT) {
4232 ret = os_snprintf(pos, end - pos, "est_throughput=%d\n",
4233 bss->est_throughput);
4234 if (os_snprintf_error(end - pos, ret))
4239 if (mask & WPA_BSS_MASK_DELIM) {
4240 ret = os_snprintf(pos, end - pos, "====\n");
4241 if (os_snprintf_error(end - pos, ret))
4250 static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
4251 const char *cmd, char *buf,
4256 struct wpa_bss *bss;
4257 struct wpa_bss *bsslast = NULL;
4258 struct dl_list *next;
4261 char *ctmp, *end = buf + buflen;
4262 unsigned long mask = WPA_BSS_MASK_ALL;
4264 if (os_strncmp(cmd, "RANGE=", 6) == 0) {
4265 if (os_strncmp(cmd + 6, "ALL", 3) == 0) {
4266 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss,
4268 bsslast = dl_list_last(&wpa_s->bss_id, struct wpa_bss,
4270 } else { /* N1-N2 */
4271 unsigned int id1, id2;
4273 if ((ctmp = os_strchr(cmd + 6, '-')) == NULL) {
4274 wpa_printf(MSG_INFO, "Wrong BSS range "
4279 if (*(cmd + 6) == '-')
4282 id1 = atoi(cmd + 6);
4284 if (*ctmp >= '0' && *ctmp <= '9')
4287 id2 = (unsigned int) -1;
4288 bss = wpa_bss_get_id_range(wpa_s, id1, id2);
4289 if (id2 == (unsigned int) -1)
4290 bsslast = dl_list_last(&wpa_s->bss_id,
4294 bsslast = wpa_bss_get_id(wpa_s, id2);
4295 if (bsslast == NULL && bss && id2 > id1) {
4296 struct wpa_bss *tmp = bss;
4298 next = tmp->list_id.next;
4299 if (next == &wpa_s->bss_id)
4301 tmp = dl_list_entry(
4302 next, struct wpa_bss,
4311 } else if (os_strncmp(cmd, "FIRST", 5) == 0)
4312 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, list_id);
4313 else if (os_strncmp(cmd, "LAST", 4) == 0)
4314 bss = dl_list_last(&wpa_s->bss_id, struct wpa_bss, list_id);
4315 else if (os_strncmp(cmd, "ID-", 3) == 0) {
4317 bss = wpa_bss_get_id(wpa_s, i);
4318 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
4320 bss = wpa_bss_get_id(wpa_s, i);
4322 next = bss->list_id.next;
4323 if (next == &wpa_s->bss_id)
4326 bss = dl_list_entry(next, struct wpa_bss,
4330 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
4331 if (hwaddr_aton(cmd + 13, bssid) == 0)
4332 bss = wpa_bss_get_p2p_dev_addr(wpa_s, bssid);
4335 #endif /* CONFIG_P2P */
4336 } else if (hwaddr_aton(cmd, bssid) == 0)
4337 bss = wpa_bss_get_bssid(wpa_s, bssid);
4339 struct wpa_bss *tmp;
4342 dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id)
4351 if ((ctmp = os_strstr(cmd, "MASK=")) != NULL) {
4352 mask = strtoul(ctmp + 5, NULL, 0x10);
4354 mask = WPA_BSS_MASK_ALL;
4360 if (bsslast == NULL)
4363 len = print_bss_info(wpa_s, bss, mask, buf, buflen);
4367 if (bss == bsslast) {
4368 if ((mask & WPA_BSS_MASK_DELIM) && len &&
4369 (bss == dl_list_last(&wpa_s->bss_id,
4370 struct wpa_bss, list_id))) {
4373 res = os_snprintf(buf - 5, end - buf + 5,
4375 if (os_snprintf_error(end - buf + 5, res)) {
4376 wpa_printf(MSG_DEBUG,
4377 "Could not add end delim");
4382 next = bss->list_id.next;
4383 if (next == &wpa_s->bss_id)
4385 bss = dl_list_entry(next, struct wpa_bss, list_id);
4386 } while (bss && len);
4392 static int wpa_supplicant_ctrl_iface_ap_scan(
4393 struct wpa_supplicant *wpa_s, char *cmd)
4395 int ap_scan = atoi(cmd);
4396 return wpa_supplicant_set_ap_scan(wpa_s, ap_scan);
4400 static int wpa_supplicant_ctrl_iface_scan_interval(
4401 struct wpa_supplicant *wpa_s, char *cmd)
4403 int scan_int = atoi(cmd);
4404 return wpa_supplicant_set_scan_interval(wpa_s, scan_int);
4408 static int wpa_supplicant_ctrl_iface_bss_expire_age(
4409 struct wpa_supplicant *wpa_s, char *cmd)
4411 int expire_age = atoi(cmd);
4412 return wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age);
4416 static int wpa_supplicant_ctrl_iface_bss_expire_count(
4417 struct wpa_supplicant *wpa_s, char *cmd)
4419 int expire_count = atoi(cmd);
4420 return wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count);
4424 static void wpa_supplicant_ctrl_iface_bss_flush(
4425 struct wpa_supplicant *wpa_s, char *cmd)
4427 int flush_age = atoi(cmd);
4430 wpa_bss_flush(wpa_s);
4432 wpa_bss_flush_by_age(wpa_s, flush_age);
4436 #ifdef CONFIG_TESTING_OPTIONS
4437 static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s)
4439 wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication");
4440 /* MLME-DELETEKEYS.request */
4441 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL, 0);
4442 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL, 0);
4443 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL, 0);
4444 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL, 0);
4445 #ifdef CONFIG_IEEE80211W
4446 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL, 0);
4447 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL, 0);
4448 #endif /* CONFIG_IEEE80211W */
4450 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, wpa_s->bssid, 0, 0, NULL, 0, NULL,
4452 /* MLME-SETPROTECTION.request(None) */
4453 wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid,
4454 MLME_SETPROTECTION_PROTECT_TYPE_NONE,
4455 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE);
4456 wpa_sm_drop_sa(wpa_s->wpa);
4458 #endif /* CONFIG_TESTING_OPTIONS */
4461 static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s,
4464 #ifdef CONFIG_NO_SCAN_PROCESSING
4466 #else /* CONFIG_NO_SCAN_PROCESSING */
4468 struct wpa_bss *bss;
4469 struct wpa_ssid *ssid = wpa_s->current_ssid;
4471 if (hwaddr_aton(addr, bssid)) {
4472 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid "
4473 "address '%s'", addr);
4477 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR, MAC2STR(bssid));
4480 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network "
4481 "configuration known for the target AP");
4485 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
4487 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found "
4493 * TODO: Find best network configuration block from configuration to
4494 * allow roaming to other networks
4497 wpa_s->reassociate = 1;
4498 wpa_supplicant_connect(wpa_s, bss, ssid);
4501 #endif /* CONFIG_NO_SCAN_PROCESSING */
4506 static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd)
4508 unsigned int timeout = atoi(cmd);
4509 enum p2p_discovery_type type = P2P_FIND_START_WITH_FULL;
4510 u8 dev_id[ETH_ALEN], *_dev_id = NULL;
4511 u8 dev_type[WPS_DEV_TYPE_LEN], *_dev_type = NULL;
4513 unsigned int search_delay;
4514 const char *_seek[P2P_MAX_QUERY_HASH + 1], **seek = NULL;
4518 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
4519 wpa_dbg(wpa_s, MSG_INFO,
4520 "Reject P2P_FIND since interface is disabled");
4523 if (os_strstr(cmd, "type=social"))
4524 type = P2P_FIND_ONLY_SOCIAL;
4525 else if (os_strstr(cmd, "type=progressive"))
4526 type = P2P_FIND_PROGRESSIVE;
4528 pos = os_strstr(cmd, "dev_id=");
4531 if (hwaddr_aton(pos, dev_id))
4536 pos = os_strstr(cmd, "dev_type=");
4539 if (wps_dev_type_str2bin(pos, dev_type) < 0)
4541 _dev_type = dev_type;
4544 pos = os_strstr(cmd, "delay=");
4547 search_delay = atoi(pos);
4549 search_delay = wpas_p2p_search_delay(wpa_s);
4551 /* Must be searched for last, because it adds nul termination */
4552 pos = os_strstr(cmd, " seek=");
4553 while (pos && seek_count < P2P_MAX_QUERY_HASH + 1) {
4556 term = os_strchr(pos + 1, ' ');
4557 _seek[seek_count++] = pos + 6;
4559 pos = os_strstr(pos + 6, " seek=");
4564 if (seek_count > P2P_MAX_QUERY_HASH) {
4569 pos = os_strstr(cmd, "freq=");
4577 return wpas_p2p_find(wpa_s, timeout, type, _dev_type != NULL, _dev_type,
4578 _dev_id, search_delay, seek_count, seek, freq);
4582 static struct p2ps_provision * p2p_parse_asp_provision_cmd(const char *cmd)
4584 struct p2ps_provision *p2ps_prov;
4586 size_t info_len = 0;
4588 u8 role = P2PS_SETUP_NONE;
4589 long long unsigned val;
4591 pos = os_strstr(cmd, "info=");
4594 info_len = os_strlen(pos);
4597 info = os_malloc(info_len + 1);
4599 info_len = utf8_unescape(pos, info_len,
4600 info, info_len + 1);
4606 p2ps_prov = os_zalloc(sizeof(struct p2ps_provision) + info_len + 1);
4607 if (p2ps_prov == NULL) {
4613 os_memcpy(p2ps_prov->info, info, info_len);
4614 p2ps_prov->info[info_len] = '\0';
4618 pos = os_strstr(cmd, "status=");
4620 p2ps_prov->status = atoi(pos + 7);
4622 p2ps_prov->status = -1;
4624 pos = os_strstr(cmd, "adv_id=");
4625 if (!pos || sscanf(pos + 7, "%llx", &val) != 1 || val > 0xffffffffULL)
4627 p2ps_prov->adv_id = val;
4629 pos = os_strstr(cmd, "method=");
4631 p2ps_prov->method = strtol(pos + 7, NULL, 16);
4633 p2ps_prov->method = 0;
4635 pos = os_strstr(cmd, "session=");
4636 if (!pos || sscanf(pos + 8, "%llx", &val) != 1 || val > 0xffffffffULL)
4638 p2ps_prov->session_id = val;
4640 pos = os_strstr(cmd, "adv_mac=");
4641 if (!pos || hwaddr_aton(pos + 8, p2ps_prov->adv_mac))
4644 pos = os_strstr(cmd, "session_mac=");
4645 if (!pos || hwaddr_aton(pos + 12, p2ps_prov->session_mac))
4648 /* force conncap with tstCap (no sanity checks) */
4649 pos = os_strstr(cmd, "tstCap=");
4651 role = strtol(pos + 7, NULL, 16);
4653 pos = os_strstr(cmd, "role=");
4655 role = strtol(pos + 5, NULL, 16);
4656 if (role != P2PS_SETUP_CLIENT &&
4657 role != P2PS_SETUP_GROUP_OWNER)
4658 role = P2PS_SETUP_NONE;
4661 p2ps_prov->role = role;
4671 static int p2p_ctrl_asp_provision_resp(struct wpa_supplicant *wpa_s, char *cmd)
4674 struct p2ps_provision *p2ps_prov;
4677 /* <addr> id=<adv_id> [role=<conncap>] [info=<infodata>] */
4679 wpa_printf(MSG_DEBUG, "%s: %s", __func__, cmd);
4681 if (hwaddr_aton(cmd, addr))
4688 p2ps_prov = p2p_parse_asp_provision_cmd(pos);
4692 if (p2ps_prov->status < 0) {
4697 return wpas_p2p_prov_disc(wpa_s, addr, NULL, WPAS_P2P_PD_FOR_ASP,
4702 static int p2p_ctrl_asp_provision(struct wpa_supplicant *wpa_s, char *cmd)
4705 struct p2ps_provision *p2ps_prov;
4708 /* <addr> id=<adv_id> adv_mac=<adv_mac> conncap=<conncap>
4709 * session=<ses_id> mac=<ses_mac> [info=<infodata>]
4712 wpa_printf(MSG_DEBUG, "%s: %s", __func__, cmd);
4713 if (hwaddr_aton(cmd, addr))
4720 p2ps_prov = p2p_parse_asp_provision_cmd(pos);
4724 return wpas_p2p_prov_disc(wpa_s, addr, NULL, WPAS_P2P_PD_FOR_ASP,
4729 static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd,
4730 char *buf, size_t buflen)
4735 enum p2p_wps_method wps_method;
4738 int persistent_group, persistent_id = -1;
4747 if (!wpa_s->global->p2p_init_wpa_s)
4749 if (wpa_s->global->p2p_init_wpa_s != wpa_s) {
4750 wpa_dbg(wpa_s, MSG_DEBUG, "Direct P2P_CONNECT command to %s",
4751 wpa_s->global->p2p_init_wpa_s->ifname);
4752 wpa_s = wpa_s->global->p2p_init_wpa_s;
4755 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad|p2ps]
4756 * [persistent|persistent=<network id>]
4757 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
4758 * [ht40] [vht] [auto] */
4760 if (hwaddr_aton(cmd, addr))
4768 persistent_group = os_strstr(pos, " persistent") != NULL;
4769 pos2 = os_strstr(pos, " persistent=");
4771 struct wpa_ssid *ssid;
4772 persistent_id = atoi(pos2 + 12);
4773 ssid = wpa_config_get_network(wpa_s->conf, persistent_id);
4774 if (ssid == NULL || ssid->disabled != 2 ||
4775 ssid->mode != WPAS_MODE_P2P_GO) {
4776 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
4777 "SSID id=%d for persistent P2P group (GO)",
4782 join = os_strstr(pos, " join") != NULL;
4783 auth = os_strstr(pos, " auth") != NULL;
4784 automatic = os_strstr(pos, " auto") != NULL;
4785 pd = os_strstr(pos, " provdisc") != NULL;
4786 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
4787 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
4790 pos2 = os_strstr(pos, " go_intent=");
4793 go_intent = atoi(pos2);
4794 if (go_intent < 0 || go_intent > 15)
4798 pos2 = os_strstr(pos, " freq=");
4806 if (os_strncmp(pos, "pin", 3) == 0) {
4807 /* Request random PIN (to be displayed) and enable the PIN */
4808 wps_method = WPS_PIN_DISPLAY;
4809 } else if (os_strncmp(pos, "pbc", 3) == 0) {
4810 wps_method = WPS_PBC;
4813 pos = os_strchr(pin, ' ');
4814 wps_method = WPS_PIN_KEYPAD;
4817 if (os_strncmp(pos, "display", 7) == 0)
4818 wps_method = WPS_PIN_DISPLAY;
4819 else if (os_strncmp(pos, "p2ps", 4) == 0)
4820 wps_method = WPS_P2PS;
4822 if (!wps_pin_str_valid(pin)) {
4823 os_memcpy(buf, "FAIL-INVALID-PIN\n", 17);
4828 new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method,
4829 persistent_group, automatic, join,
4830 auth, go_intent, freq, persistent_id, pd,
4832 if (new_pin == -2) {
4833 os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
4836 if (new_pin == -3) {
4837 os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
4842 if (wps_method == WPS_PIN_DISPLAY && pin == NULL) {
4843 ret = os_snprintf(buf, buflen, "%08d", new_pin);
4844 if (os_snprintf_error(buflen, ret))
4849 os_memcpy(buf, "OK\n", 3);
4854 static int p2p_ctrl_listen(struct wpa_supplicant *wpa_s, char *cmd)
4856 unsigned int timeout = atoi(cmd);
4857 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
4858 wpa_dbg(wpa_s, MSG_INFO,
4859 "Reject P2P_LISTEN since interface is disabled");
4862 return wpas_p2p_listen(wpa_s, timeout);
4866 static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd)
4870 enum wpas_p2p_prov_disc_use use = WPAS_P2P_PD_FOR_GO_NEG;
4872 /* <addr> <config method> [join|auto] */
4874 if (hwaddr_aton(cmd, addr))
4882 if (os_strstr(pos, " join") != NULL)
4883 use = WPAS_P2P_PD_FOR_JOIN;
4884 else if (os_strstr(pos, " auto") != NULL)
4885 use = WPAS_P2P_PD_AUTO;
4887 return wpas_p2p_prov_disc(wpa_s, addr, pos, use, NULL);
4891 static int p2p_get_passphrase(struct wpa_supplicant *wpa_s, char *buf,
4894 struct wpa_ssid *ssid = wpa_s->current_ssid;
4896 if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO ||
4897 ssid->passphrase == NULL)
4900 os_strlcpy(buf, ssid->passphrase, buflen);
4901 return os_strlen(buf);
4905 static int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd,
4906 char *buf, size_t buflen)
4910 u8 dst_buf[ETH_ALEN], *dst;
4911 struct wpabuf *tlvs;
4915 if (hwaddr_aton(cmd, dst_buf))
4918 if (dst[0] == 0 && dst[1] == 0 && dst[2] == 0 &&
4919 dst[3] == 0 && dst[4] == 0 && dst[5] == 0)
4926 if (os_strncmp(pos, "upnp ", 5) == 0) {
4929 if (hexstr2bin(pos, &version, 1) < 0)
4935 ref = wpas_p2p_sd_request_upnp(wpa_s, dst, version, pos);
4936 #ifdef CONFIG_WIFI_DISPLAY
4937 } else if (os_strncmp(pos, "wifi-display ", 13) == 0) {
4938 ref = wpas_p2p_sd_request_wifi_display(wpa_s, dst, pos + 13);
4939 #endif /* CONFIG_WIFI_DISPLAY */
4940 } else if (os_strncmp(pos, "asp ", 4) == 0) {
4942 char *svc_info = NULL;
4946 if (sscanf(pos, "%x", &id) != 1 || id > 0xff)
4949 pos = os_strchr(pos, ' ');
4950 if (pos == NULL || pos[1] == '\0' || pos[1] == ' ')
4955 pos = os_strchr(svc_str, ' ');
4960 /* All remaining data is the svc_info string */
4961 if (pos && pos[0] && pos[0] != ' ') {
4962 len = os_strlen(pos);
4964 /* Unescape in place */
4965 len = utf8_unescape(pos, len, pos, len);
4972 ref = wpas_p2p_sd_request_asp(wpa_s, dst, (u8) id,
4975 len = os_strlen(pos);
4979 tlvs = wpabuf_alloc(len);
4982 if (hexstr2bin(pos, wpabuf_put(tlvs, len), len) < 0) {
4987 ref = wpas_p2p_sd_request(wpa_s, dst, tlvs);
4992 res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref);
4993 if (os_snprintf_error(buflen, res))
4999 static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s,
5002 long long unsigned val;
5004 if (sscanf(cmd, "%llx", &val) != 1)
5007 return wpas_p2p_sd_cancel_request(wpa_s, req);
5011 static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant *wpa_s, char *cmd)
5016 struct wpabuf *resp_tlvs;
5020 pos = os_strchr(cmd, ' ');
5028 if (hwaddr_aton(pos, dst))
5035 pos2 = os_strchr(pos, ' ');
5039 dialog_token = atoi(pos);
5041 len = os_strlen(pos2);
5045 resp_tlvs = wpabuf_alloc(len);
5046 if (resp_tlvs == NULL)
5048 if (hexstr2bin(pos2, wpabuf_put(resp_tlvs, len), len) < 0) {
5049 wpabuf_free(resp_tlvs);
5053 wpas_p2p_sd_response(wpa_s, freq, dst, dialog_token, resp_tlvs);
5054 wpabuf_free(resp_tlvs);
5059 static int p2p_ctrl_serv_disc_external(struct wpa_supplicant *wpa_s,
5062 if (os_strcmp(cmd, "0") && os_strcmp(cmd, "1"))
5064 wpa_s->p2p_sd_over_ctrl_iface = atoi(cmd);
5069 static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant *wpa_s,
5074 struct wpabuf *query, *resp;
5076 pos = os_strchr(cmd, ' ');
5081 len = os_strlen(cmd);
5085 query = wpabuf_alloc(len);
5088 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
5093 len = os_strlen(pos);
5099 resp = wpabuf_alloc(len);
5104 if (hexstr2bin(pos, wpabuf_put(resp, len), len) < 0) {
5110 if (wpas_p2p_service_add_bonjour(wpa_s, query, resp) < 0) {
5119 static int p2p_ctrl_service_add_upnp(struct wpa_supplicant *wpa_s, char *cmd)
5124 pos = os_strchr(cmd, ' ');
5129 if (hexstr2bin(cmd, &version, 1) < 0)
5132 return wpas_p2p_service_add_upnp(wpa_s, version, pos);
5136 static int p2p_ctrl_service_add_asp(struct wpa_supplicant *wpa_s,
5137 u8 replace, char *cmd)
5141 u32 auto_accept, adv_id, svc_state, config_methods;
5142 char *svc_info = NULL;
5144 pos = os_strchr(cmd, ' ');
5149 /* Auto-Accept value is mandatory, and must be one of the
5150 * single values (0, 1, 2, 4) */
5151 auto_accept = atoi(cmd);
5152 switch (auto_accept) {
5153 case P2PS_SETUP_NONE: /* No auto-accept */
5154 case P2PS_SETUP_NEW:
5155 case P2PS_SETUP_CLIENT:
5156 case P2PS_SETUP_GROUP_OWNER:
5162 /* Advertisement ID is mandatory */
5164 pos = os_strchr(cmd, ' ');
5169 /* Handle Adv_ID == 0 (wildcard "org.wi-fi.wfds") internally. */
5170 if (sscanf(cmd, "%x", &adv_id) != 1 || adv_id == 0)
5173 /* Only allow replacements if exist, and adds if not */
5174 if (wpas_p2p_service_p2ps_id_exists(wpa_s, adv_id)) {
5182 /* svc_state between 0 - 0xff is mandatory */
5183 if (sscanf(pos, "%x", &svc_state) != 1 || svc_state > 0xff)
5186 pos = os_strchr(pos, ' ');
5190 /* config_methods is mandatory */
5192 if (sscanf(pos, "%x", &config_methods) != 1)
5195 if (!(config_methods &
5196 (WPS_CONFIG_DISPLAY | WPS_CONFIG_KEYPAD | WPS_CONFIG_P2PS)))
5199 pos = os_strchr(pos, ' ');
5206 /* Advertisement string is mandatory */
5207 if (!pos[0] || pos[0] == ' ')
5210 /* Terminate svc string */
5211 pos = os_strchr(pos, ' ');
5215 /* Service and Response Information are optional */
5216 if (pos && pos[0]) {
5219 /* Note the bare ' included, which cannot exist legally
5220 * in unescaped string. */
5221 svc_info = os_strstr(pos, "svc_info='");
5225 len = os_strlen(svc_info);
5226 utf8_unescape(svc_info, len, svc_info, len);
5230 return wpas_p2p_service_add_asp(wpa_s, auto_accept, adv_id, adv_str,
5231 (u8) svc_state, (u16) config_methods,
5236 static int p2p_ctrl_service_add(struct wpa_supplicant *wpa_s, char *cmd)
5240 pos = os_strchr(cmd, ' ');
5245 if (os_strcmp(cmd, "bonjour") == 0)
5246 return p2p_ctrl_service_add_bonjour(wpa_s, pos);
5247 if (os_strcmp(cmd, "upnp") == 0)
5248 return p2p_ctrl_service_add_upnp(wpa_s, pos);
5249 if (os_strcmp(cmd, "asp") == 0)
5250 return p2p_ctrl_service_add_asp(wpa_s, 0, pos);
5251 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
5256 static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant *wpa_s,
5260 struct wpabuf *query;
5263 len = os_strlen(cmd);
5267 query = wpabuf_alloc(len);
5270 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
5275 ret = wpas_p2p_service_del_bonjour(wpa_s, query);
5281 static int p2p_ctrl_service_del_upnp(struct wpa_supplicant *wpa_s, char *cmd)
5286 pos = os_strchr(cmd, ' ');
5291 if (hexstr2bin(cmd, &version, 1) < 0)
5294 return wpas_p2p_service_del_upnp(wpa_s, version, pos);
5298 static int p2p_ctrl_service_del_asp(struct wpa_supplicant *wpa_s, char *cmd)
5302 if (sscanf(cmd, "%x", &adv_id) != 1)
5305 return wpas_p2p_service_del_asp(wpa_s, adv_id);
5309 static int p2p_ctrl_service_del(struct wpa_supplicant *wpa_s, char *cmd)
5313 pos = os_strchr(cmd, ' ');
5318 if (os_strcmp(cmd, "bonjour") == 0)
5319 return p2p_ctrl_service_del_bonjour(wpa_s, pos);
5320 if (os_strcmp(cmd, "upnp") == 0)
5321 return p2p_ctrl_service_del_upnp(wpa_s, pos);
5322 if (os_strcmp(cmd, "asp") == 0)
5323 return p2p_ctrl_service_del_asp(wpa_s, pos);
5324 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
5329 static int p2p_ctrl_service_replace(struct wpa_supplicant *wpa_s, char *cmd)
5333 pos = os_strchr(cmd, ' ');
5338 if (os_strcmp(cmd, "asp") == 0)
5339 return p2p_ctrl_service_add_asp(wpa_s, 1, pos);
5341 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
5346 static int p2p_ctrl_reject(struct wpa_supplicant *wpa_s, char *cmd)
5352 if (hwaddr_aton(cmd, addr))
5355 return wpas_p2p_reject(wpa_s, addr);
5359 static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd)
5363 struct wpa_ssid *ssid;
5364 u8 *_peer = NULL, peer[ETH_ALEN];
5365 int freq = 0, pref_freq = 0;
5369 pos = os_strstr(cmd, " peer=");
5372 if (hwaddr_aton(pos, peer))
5376 ssid = wpa_config_get_network(wpa_s->conf, id);
5377 if (ssid == NULL || ssid->disabled != 2) {
5378 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
5379 "for persistent P2P group",
5384 pos = os_strstr(cmd, " freq=");
5392 pos = os_strstr(cmd, " pref=");
5395 pref_freq = atoi(pos);
5400 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
5401 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
5404 return wpas_p2p_invite(wpa_s, _peer, ssid, NULL, freq, ht40, vht,
5409 static int p2p_ctrl_invite_group(struct wpa_supplicant *wpa_s, char *cmd)
5412 u8 peer[ETH_ALEN], go_dev_addr[ETH_ALEN], *go_dev = NULL;
5414 pos = os_strstr(cmd, " peer=");
5420 if (hwaddr_aton(pos, peer)) {
5421 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", pos);
5425 pos = os_strstr(pos, " go_dev_addr=");
5428 if (hwaddr_aton(pos, go_dev_addr)) {
5429 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'",
5433 go_dev = go_dev_addr;
5436 return wpas_p2p_invite_group(wpa_s, cmd, peer, go_dev);
5440 static int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd)
5442 if (os_strncmp(cmd, "persistent=", 11) == 0)
5443 return p2p_ctrl_invite_persistent(wpa_s, cmd + 11);
5444 if (os_strncmp(cmd, "group=", 6) == 0)
5445 return p2p_ctrl_invite_group(wpa_s, cmd + 6);
5451 static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s,
5452 char *cmd, int freq, int ht40,
5456 struct wpa_ssid *ssid;
5459 ssid = wpa_config_get_network(wpa_s->conf, id);
5460 if (ssid == NULL || ssid->disabled != 2) {
5461 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
5462 "for persistent P2P group",
5467 return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq, 0, ht40, vht,
5472 static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd)
5474 int freq = 0, ht40, vht;
5477 pos = os_strstr(cmd, "freq=");
5479 freq = atoi(pos + 5);
5481 vht = (os_strstr(cmd, "vht") != NULL) || wpa_s->conf->p2p_go_vht;
5482 ht40 = (os_strstr(cmd, "ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
5485 if (os_strncmp(cmd, "persistent=", 11) == 0)
5486 return p2p_ctrl_group_add_persistent(wpa_s, cmd + 11, freq,
5488 if (os_strcmp(cmd, "persistent") == 0 ||
5489 os_strncmp(cmd, "persistent ", 11) == 0)
5490 return wpas_p2p_group_add(wpa_s, 1, freq, ht40, vht);
5491 if (os_strncmp(cmd, "freq=", 5) == 0)
5492 return wpas_p2p_group_add(wpa_s, 0, freq, ht40, vht);
5494 return wpas_p2p_group_add(wpa_s, 0, freq, ht40, vht);
5496 wpa_printf(MSG_DEBUG, "CTRL: Invalid P2P_GROUP_ADD parameters '%s'",
5502 static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd,
5503 char *buf, size_t buflen)
5505 u8 addr[ETH_ALEN], *addr_ptr;
5507 const struct p2p_peer_info *info;
5509 char devtype[WPS_DEV_TYPE_BUFSIZE];
5510 struct wpa_ssid *ssid;
5513 if (!wpa_s->global->p2p)
5516 if (os_strcmp(cmd, "FIRST") == 0) {
5519 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
5520 if (hwaddr_aton(cmd + 5, addr) < 0)
5525 if (hwaddr_aton(cmd, addr) < 0)
5531 info = p2p_get_peer_info(wpa_s->global->p2p, addr_ptr, next);
5538 res = os_snprintf(pos, end - pos, MACSTR "\n"
5544 "serial_number=%s\n"
5545 "config_methods=0x%x\n"
5547 "group_capab=0x%x\n"
5549 MAC2STR(info->p2p_device_addr),
5550 wps_dev_type_bin2str(info->pri_dev_type,
5551 devtype, sizeof(devtype)),
5556 info->serial_number,
5557 info->config_methods,
5561 if (os_snprintf_error(end - pos, res))
5565 for (i = 0; i < info->wps_sec_dev_type_list_len / WPS_DEV_TYPE_LEN; i++)
5568 t = &info->wps_sec_dev_type_list[i * WPS_DEV_TYPE_LEN];
5569 res = os_snprintf(pos, end - pos, "sec_dev_type=%s\n",
5570 wps_dev_type_bin2str(t, devtype,
5572 if (os_snprintf_error(end - pos, res))
5577 ssid = wpas_p2p_get_persistent(wpa_s, info->p2p_device_addr, NULL, 0);
5579 res = os_snprintf(pos, end - pos, "persistent=%d\n", ssid->id);
5580 if (os_snprintf_error(end - pos, res))
5585 res = p2p_get_peer_info_txt(info, pos, end - pos);
5590 if (info->vendor_elems) {
5591 res = os_snprintf(pos, end - pos, "vendor_elems=");
5592 if (os_snprintf_error(end - pos, res))
5596 pos += wpa_snprintf_hex(pos, end - pos,
5597 wpabuf_head(info->vendor_elems),
5598 wpabuf_len(info->vendor_elems));
5600 res = os_snprintf(pos, end - pos, "\n");
5601 if (os_snprintf_error(end - pos, res))
5610 static int p2p_ctrl_disallow_freq(struct wpa_supplicant *wpa_s,
5615 if (wpa_s->global->p2p == NULL)
5618 if (freq_range_list_parse(&wpa_s->global->p2p_disallow_freq, param) < 0)
5621 for (i = 0; i < wpa_s->global->p2p_disallow_freq.num; i++) {
5622 struct wpa_freq_range *freq;
5623 freq = &wpa_s->global->p2p_disallow_freq.range[i];
5624 wpa_printf(MSG_DEBUG, "P2P: Disallowed frequency range %u-%u",
5625 freq->min, freq->max);
5628 wpas_p2p_update_channel_list(wpa_s);
5633 static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd)
5637 if (wpa_s->global->p2p == NULL)
5640 param = os_strchr(cmd, ' ');
5645 if (os_strcmp(cmd, "discoverability") == 0) {
5646 p2p_set_client_discoverability(wpa_s->global->p2p,
5651 if (os_strcmp(cmd, "managed") == 0) {
5652 p2p_set_managed_oper(wpa_s->global->p2p, atoi(param));
5656 if (os_strcmp(cmd, "listen_channel") == 0) {
5657 return p2p_set_listen_channel(wpa_s->global->p2p, 81,
5661 if (os_strcmp(cmd, "ssid_postfix") == 0) {
5662 return p2p_set_ssid_postfix(wpa_s->global->p2p, (u8 *) param,
5666 if (os_strcmp(cmd, "noa") == 0) {
5668 int count, start, duration;
5669 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
5670 count = atoi(param);
5671 pos = os_strchr(param, ',');
5676 pos = os_strchr(pos, ',');
5680 duration = atoi(pos);
5681 if (count < 0 || count > 255 || start < 0 || duration < 0)
5683 if (count == 0 && duration > 0)
5685 wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
5686 "start=%d duration=%d", count, start, duration);
5687 return wpas_p2p_set_noa(wpa_s, count, start, duration);
5690 if (os_strcmp(cmd, "ps") == 0)
5691 return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1);
5693 if (os_strcmp(cmd, "oppps") == 0)
5694 return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1);
5696 if (os_strcmp(cmd, "ctwindow") == 0)
5697 return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param));
5699 if (os_strcmp(cmd, "disabled") == 0) {
5700 wpa_s->global->p2p_disabled = atoi(param);
5701 wpa_printf(MSG_DEBUG, "P2P functionality %s",
5702 wpa_s->global->p2p_disabled ?
5703 "disabled" : "enabled");
5704 if (wpa_s->global->p2p_disabled) {
5705 wpas_p2p_stop_find(wpa_s);
5706 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
5707 p2p_flush(wpa_s->global->p2p);
5712 if (os_strcmp(cmd, "conc_pref") == 0) {
5713 if (os_strcmp(param, "sta") == 0)
5714 wpa_s->global->conc_pref = WPA_CONC_PREF_STA;
5715 else if (os_strcmp(param, "p2p") == 0)
5716 wpa_s->global->conc_pref = WPA_CONC_PREF_P2P;
5718 wpa_printf(MSG_INFO, "Invalid conc_pref value");
5721 wpa_printf(MSG_DEBUG, "Single channel concurrency preference: "
5726 if (os_strcmp(cmd, "force_long_sd") == 0) {
5727 wpa_s->force_long_sd = atoi(param);
5731 if (os_strcmp(cmd, "peer_filter") == 0) {
5733 if (hwaddr_aton(param, addr))
5735 p2p_set_peer_filter(wpa_s->global->p2p, addr);
5739 if (os_strcmp(cmd, "cross_connect") == 0)
5740 return wpas_p2p_set_cross_connect(wpa_s, atoi(param));
5742 if (os_strcmp(cmd, "go_apsd") == 0) {
5743 if (os_strcmp(param, "disable") == 0)
5744 wpa_s->set_ap_uapsd = 0;
5746 wpa_s->set_ap_uapsd = 1;
5747 wpa_s->ap_uapsd = atoi(param);
5752 if (os_strcmp(cmd, "client_apsd") == 0) {
5753 if (os_strcmp(param, "disable") == 0)
5754 wpa_s->set_sta_uapsd = 0;
5758 /* format: BE,BK,VI,VO;max SP Length */
5760 pos = os_strchr(param, ',');
5765 pos = os_strchr(pos, ',');
5770 pos = os_strchr(pos, ',');
5775 /* ignore max SP Length for now */
5777 wpa_s->set_sta_uapsd = 1;
5778 wpa_s->sta_uapsd = 0;
5780 wpa_s->sta_uapsd |= BIT(0);
5782 wpa_s->sta_uapsd |= BIT(1);
5784 wpa_s->sta_uapsd |= BIT(2);
5786 wpa_s->sta_uapsd |= BIT(3);
5791 if (os_strcmp(cmd, "disallow_freq") == 0)
5792 return p2p_ctrl_disallow_freq(wpa_s, param);
5794 if (os_strcmp(cmd, "disc_int") == 0) {
5795 int min_disc_int, max_disc_int, max_disc_tu;
5800 min_disc_int = atoi(pos);
5801 pos = os_strchr(pos, ' ');
5806 max_disc_int = atoi(pos);
5807 pos = os_strchr(pos, ' ');
5812 max_disc_tu = atoi(pos);
5814 return p2p_set_disc_int(wpa_s->global->p2p, min_disc_int,
5815 max_disc_int, max_disc_tu);
5818 if (os_strcmp(cmd, "per_sta_psk") == 0) {
5819 wpa_s->global->p2p_per_sta_psk = !!atoi(param);
5823 #ifdef CONFIG_WPS_NFC
5824 if (os_strcmp(cmd, "nfc_tag") == 0)
5825 return wpas_p2p_nfc_tag_enabled(wpa_s, !!atoi(param));
5826 #endif /* CONFIG_WPS_NFC */
5828 if (os_strcmp(cmd, "disable_ip_addr_req") == 0) {
5829 wpa_s->p2p_disable_ip_addr_req = !!atoi(param);
5833 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
5840 static void p2p_ctrl_flush(struct wpa_supplicant *wpa_s)
5842 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
5843 wpa_s->force_long_sd = 0;
5844 wpas_p2p_stop_find(wpa_s);
5845 if (wpa_s->global->p2p)
5846 p2p_flush(wpa_s->global->p2p);
5850 static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd)
5853 unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0;
5856 pos = os_strchr(cmd, ' ');
5862 pos2 = os_strchr(pos, ' ');
5870 pos = os_strchr(pos2, ' ');
5878 return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2);
5882 static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd)
5885 unsigned int period = 0, interval = 0;
5888 pos = os_strchr(cmd, ' ');
5893 interval = atoi(pos);
5896 return wpas_p2p_ext_listen(wpa_s, period, interval);
5900 static int p2p_ctrl_remove_client(struct wpa_supplicant *wpa_s, const char *cmd)
5907 if (os_strncmp(pos, "iface=", 6) == 0) {
5911 if (hwaddr_aton(pos, peer))
5914 wpas_p2p_remove_client(wpa_s, peer, iface_addr);
5918 #endif /* CONFIG_P2P */
5921 static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s, char *val)
5923 struct wpa_freq_range_list ranges;
5925 struct hostapd_hw_modes *mode;
5928 if (wpa_s->hw.modes == NULL)
5931 os_memset(&ranges, 0, sizeof(ranges));
5932 if (freq_range_list_parse(&ranges, val) < 0)
5935 for (i = 0; i < wpa_s->hw.num_modes; i++) {
5938 mode = &wpa_s->hw.modes[i];
5939 for (j = 0; j < mode->num_channels; j++) {
5942 if (mode->channels[j].flag & HOSTAPD_CHAN_DISABLED)
5945 freq = mode->channels[j].freq;
5946 if (!freq_range_list_includes(&ranges, freq))
5949 int_array_add_unique(&freqs, freq);
5953 os_free(ranges.range);
5958 #ifdef CONFIG_INTERWORKING
5960 static int ctrl_interworking_select(struct wpa_supplicant *wpa_s, char *param)
5968 auto_sel = os_strstr(param, "auto") != NULL;
5970 pos = os_strstr(param, "freq=");
5972 freqs = freq_range_to_channel_list(wpa_s, pos + 5);
5979 return interworking_select(wpa_s, auto_sel, freqs);
5983 static int ctrl_interworking_connect(struct wpa_supplicant *wpa_s, char *dst,
5987 struct wpa_bss *bss;
5989 if (hwaddr_aton(dst, bssid)) {
5990 wpa_printf(MSG_DEBUG, "Invalid BSSID '%s'", dst);
5994 bss = wpa_bss_get_bssid(wpa_s, bssid);
5996 wpa_printf(MSG_DEBUG, "Could not find BSS " MACSTR,
6001 if (bss->ssid_len == 0) {
6004 wpa_printf(MSG_DEBUG, "Selected BSS entry for " MACSTR
6005 " does not have SSID information", MAC2STR(bssid));
6007 dl_list_for_each_reverse(bss, &wpa_s->bss, struct wpa_bss,
6009 if (os_memcmp(bss->bssid, bssid, ETH_ALEN) == 0 &&
6010 bss->ssid_len > 0) {
6018 wpa_printf(MSG_DEBUG,
6019 "Found another matching BSS entry with SSID");
6022 return interworking_connect(wpa_s, bss, only_add);
6026 static int get_anqp(struct wpa_supplicant *wpa_s, char *dst)
6028 u8 dst_addr[ETH_ALEN];
6031 #define MAX_ANQP_INFO_ID 100
6032 u16 id[MAX_ANQP_INFO_ID];
6036 used = hwaddr_aton2(dst, dst_addr);
6042 while (num_id < MAX_ANQP_INFO_ID) {
6043 if (os_strncmp(pos, "hs20:", 5) == 0) {
6045 int num = atoi(pos + 5);
6046 if (num <= 0 || num > 31)
6048 subtypes |= BIT(num);
6049 #else /* CONFIG_HS20 */
6051 #endif /* CONFIG_HS20 */
6053 id[num_id] = atoi(pos);
6057 pos = os_strchr(pos + 1, ',');
6066 return anqp_send_req(wpa_s, dst_addr, id, num_id, subtypes);
6070 static int gas_request(struct wpa_supplicant *wpa_s, char *cmd)
6072 u8 dst_addr[ETH_ALEN];
6073 struct wpabuf *advproto, *query = NULL;
6078 used = hwaddr_aton2(cmd, dst_addr);
6086 /* Advertisement Protocol ID */
6087 end = os_strchr(pos, ' ');
6091 len = os_strlen(pos);
6097 advproto = wpabuf_alloc(len);
6098 if (advproto == NULL)
6100 if (hexstr2bin(pos, wpabuf_put(advproto, len), len) < 0)
6104 /* Optional Query Request */
6109 len = os_strlen(pos);
6116 query = wpabuf_alloc(len);
6119 if (hexstr2bin(pos, wpabuf_put(query, len), len) < 0)
6124 ret = gas_send_request(wpa_s, dst_addr, advproto, query);
6127 wpabuf_free(advproto);
6134 static int gas_response_get(struct wpa_supplicant *wpa_s, char *cmd, char *buf,
6141 size_t resp_len, start, requested_len;
6142 struct wpabuf *resp;
6145 used = hwaddr_aton2(cmd, addr);
6152 dialog_token = atoi(pos);
6154 if (wpa_s->last_gas_resp &&
6155 os_memcmp(addr, wpa_s->last_gas_addr, ETH_ALEN) == 0 &&
6156 dialog_token == wpa_s->last_gas_dialog_token)
6157 resp = wpa_s->last_gas_resp;
6158 else if (wpa_s->prev_gas_resp &&
6159 os_memcmp(addr, wpa_s->prev_gas_addr, ETH_ALEN) == 0 &&
6160 dialog_token == wpa_s->prev_gas_dialog_token)
6161 resp = wpa_s->prev_gas_resp;
6165 resp_len = wpabuf_len(resp);
6167 requested_len = resp_len;
6169 pos = os_strchr(pos, ' ');
6172 if (start > resp_len)
6173 return os_snprintf(buf, buflen, "FAIL-Invalid range");
6174 pos = os_strchr(pos, ',');
6178 requested_len = atoi(pos);
6179 if (start + requested_len > resp_len)
6180 return os_snprintf(buf, buflen, "FAIL-Invalid range");
6183 if (requested_len * 2 + 1 > buflen)
6184 return os_snprintf(buf, buflen, "FAIL-Too long response");
6186 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(resp) + start,
6189 if (start + requested_len == resp_len) {
6191 * Free memory by dropping the response after it has been
6194 if (resp == wpa_s->prev_gas_resp) {
6195 wpabuf_free(wpa_s->prev_gas_resp);
6196 wpa_s->prev_gas_resp = NULL;
6198 wpabuf_free(wpa_s->last_gas_resp);
6199 wpa_s->last_gas_resp = NULL;
6205 #endif /* CONFIG_INTERWORKING */
6210 static int get_hs20_anqp(struct wpa_supplicant *wpa_s, char *dst)
6212 u8 dst_addr[ETH_ALEN];
6217 used = hwaddr_aton2(dst, dst_addr);
6224 int num = atoi(pos);
6225 if (num <= 0 || num > 31)
6227 subtypes |= BIT(num);
6228 pos = os_strchr(pos + 1, ',');
6237 return hs20_anqp_send_req(wpa_s, dst_addr, subtypes, NULL, 0);
6241 static int hs20_nai_home_realm_list(struct wpa_supplicant *wpa_s,
6242 const u8 *addr, const char *realm)
6248 rlen = os_strlen(realm);
6250 buf = os_malloc(len);
6253 buf[0] = 1; /* NAI Home Realm Count */
6254 buf[1] = 0; /* Formatted in accordance with RFC 4282 */
6256 os_memcpy(buf + 3, realm, rlen);
6258 ret = hs20_anqp_send_req(wpa_s, addr,
6259 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
6268 static int hs20_get_nai_home_realm_list(struct wpa_supplicant *wpa_s,
6271 struct wpa_cred *cred = wpa_s->conf->cred;
6272 u8 dst_addr[ETH_ALEN];
6278 used = hwaddr_aton2(dst, dst_addr);
6282 while (dst[used] == ' ')
6284 if (os_strncmp(dst + used, "realm=", 6) == 0)
6285 return hs20_nai_home_realm_list(wpa_s, dst_addr,
6288 len = os_strlen(dst + used);
6290 if (len == 0 && cred && cred->realm)
6291 return hs20_nai_home_realm_list(wpa_s, dst_addr, cred->realm);
6296 buf = os_malloc(len);
6299 if (hexstr2bin(dst + used, buf, len) < 0) {
6304 ret = hs20_anqp_send_req(wpa_s, dst_addr,
6305 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
6313 static int hs20_icon_request(struct wpa_supplicant *wpa_s, char *cmd)
6315 u8 dst_addr[ETH_ALEN];
6319 used = hwaddr_aton2(cmd, dst_addr);
6323 while (cmd[used] == ' ')
6327 wpa_s->fetch_osu_icon_in_progress = 0;
6328 return hs20_anqp_send_req(wpa_s, dst_addr, BIT(HS20_STYPE_ICON_REQUEST),
6329 (u8 *) icon, os_strlen(icon));
6332 #endif /* CONFIG_HS20 */
6335 #ifdef CONFIG_AUTOSCAN
6337 static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant *wpa_s,
6340 enum wpa_states state = wpa_s->wpa_state;
6341 char *new_params = NULL;
6343 if (os_strlen(cmd) > 0) {
6344 new_params = os_strdup(cmd);
6345 if (new_params == NULL)
6349 os_free(wpa_s->conf->autoscan);
6350 wpa_s->conf->autoscan = new_params;
6352 if (wpa_s->conf->autoscan == NULL)
6353 autoscan_deinit(wpa_s);
6354 else if (state == WPA_DISCONNECTED || state == WPA_INACTIVE)
6355 autoscan_init(wpa_s, 1);
6356 else if (state == WPA_SCANNING)
6357 wpa_supplicant_reinit_autoscan(wpa_s);
6362 #endif /* CONFIG_AUTOSCAN */
6367 static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant *wpa_s, char *cmd)
6373 struct wpabuf *tfs_req = NULL;
6375 if (os_strncmp(cmd, "enter", 5) == 0)
6377 else if (os_strncmp(cmd, "exit", 4) == 0)
6382 pos = os_strstr(cmd, " interval=");
6384 intval = atoi(pos + 10);
6386 pos = os_strstr(cmd, " tfs_req=");
6391 end = os_strchr(pos, ' ');
6395 len = os_strlen(pos);
6399 tfs_req = wpabuf_alloc(len);
6400 if (tfs_req == NULL)
6402 if (hexstr2bin(pos, wpabuf_put(tfs_req, len), len) < 0) {
6403 wpabuf_free(tfs_req);
6408 ret = ieee802_11_send_wnmsleep_req(wpa_s, enter ? WNM_SLEEP_MODE_ENTER :
6409 WNM_SLEEP_MODE_EXIT, intval,
6411 wpabuf_free(tfs_req);
6417 static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant *wpa_s, char *cmd)
6421 query_reason = atoi(cmd);
6423 wpa_printf(MSG_DEBUG, "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d",
6426 return wnm_send_bss_transition_mgmt_query(wpa_s, query_reason);
6429 #endif /* CONFIG_WNM */
6432 static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf,
6435 struct wpa_signal_info si;
6439 ret = wpa_drv_signal_poll(wpa_s, &si);
6446 ret = os_snprintf(pos, end - pos, "RSSI=%d\nLINKSPEED=%d\n"
6447 "NOISE=%d\nFREQUENCY=%u\n",
6448 si.current_signal, si.current_txrate / 1000,
6449 si.current_noise, si.frequency);
6450 if (os_snprintf_error(end - pos, ret))
6454 if (si.chanwidth != CHAN_WIDTH_UNKNOWN) {
6455 ret = os_snprintf(pos, end - pos, "WIDTH=%s\n",
6456 channel_width_to_string(si.chanwidth));
6457 if (os_snprintf_error(end - pos, ret))
6462 if (si.center_frq1 > 0 && si.center_frq2 > 0) {
6463 ret = os_snprintf(pos, end - pos,
6464 "CENTER_FRQ1=%d\nCENTER_FRQ2=%d\n",
6465 si.center_frq1, si.center_frq2);
6466 if (os_snprintf_error(end - pos, ret))
6471 if (si.avg_signal) {
6472 ret = os_snprintf(pos, end - pos,
6473 "AVG_RSSI=%d\n", si.avg_signal);
6474 if (os_snprintf_error(end - pos, ret))
6479 if (si.avg_beacon_signal) {
6480 ret = os_snprintf(pos, end - pos,
6481 "AVG_BEACON_RSSI=%d\n", si.avg_beacon_signal);
6482 if (os_snprintf_error(end - pos, ret))
6491 static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant *wpa_s, char *buf,
6494 struct hostap_sta_driver_data sta;
6497 ret = wpa_drv_pktcnt_poll(wpa_s, &sta);
6501 ret = os_snprintf(buf, buflen, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
6502 sta.tx_packets, sta.tx_retry_failed, sta.rx_packets);
6503 if (os_snprintf_error(buflen, ret))
6510 static int wpa_supplicant_driver_cmd(struct wpa_supplicant *wpa_s, char *cmd,
6511 char *buf, size_t buflen)
6515 ret = wpa_drv_driver_cmd(wpa_s, cmd, buf, buflen);
6517 if (os_strncasecmp(cmd, "COUNTRY", 7) == 0) {
6518 struct p2p_data *p2p = wpa_s->global->p2p;
6521 country[0] = cmd[8];
6522 country[1] = cmd[9];
6524 p2p_set_country(p2p, country);
6527 ret = os_snprintf(buf, buflen, "%s\n", "OK");
6528 if (os_snprintf_error(buflen, ret))
6533 #endif /* ANDROID */
6536 static int wpa_supplicant_vendor_cmd(struct wpa_supplicant *wpa_s, char *cmd,
6537 char *buf, size_t buflen)
6542 unsigned int vendor_id, subcmd;
6543 struct wpabuf *reply;
6544 size_t data_len = 0;
6546 /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */
6547 vendor_id = strtoul(cmd, &pos, 16);
6551 subcmd = strtoul(pos, &pos, 10);
6554 if (!isblank(*pos++))
6556 data_len = os_strlen(pos);
6561 data = os_malloc(data_len);
6565 if (hexstr2bin(pos, data, data_len)) {
6566 wpa_printf(MSG_DEBUG,
6567 "Vendor command: wrong parameter format");
6573 reply = wpabuf_alloc((buflen - 1) / 2);
6579 ret = wpa_drv_vendor_cmd(wpa_s, vendor_id, subcmd, data, data_len,
6583 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(reply),
6593 static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s)
6596 struct wpa_supplicant *p2p_wpa_s = wpa_s->global->p2p_init_wpa_s ?
6597 wpa_s->global->p2p_init_wpa_s : wpa_s;
6598 #endif /* CONFIG_P2P */
6600 wpa_dbg(wpa_s, MSG_DEBUG, "Flush all wpa_supplicant state");
6603 wpas_p2p_cancel(p2p_wpa_s);
6604 p2p_ctrl_flush(p2p_wpa_s);
6605 wpas_p2p_group_remove(p2p_wpa_s, "*");
6606 wpas_p2p_service_flush(p2p_wpa_s);
6607 p2p_wpa_s->global->p2p_disabled = 0;
6608 p2p_wpa_s->global->p2p_per_sta_psk = 0;
6609 p2p_wpa_s->conf->num_sec_device_types = 0;
6610 p2p_wpa_s->p2p_disable_ip_addr_req = 0;
6611 os_free(p2p_wpa_s->global->p2p_go_avoid_freq.range);
6612 p2p_wpa_s->global->p2p_go_avoid_freq.range = NULL;
6613 p2p_wpa_s->global->pending_p2ps_group = 0;
6614 #endif /* CONFIG_P2P */
6616 #ifdef CONFIG_WPS_TESTING
6617 wps_version_number = 0x20;
6618 wps_testing_dummy_cred = 0;
6619 wps_corrupt_pkhash = 0;
6620 #endif /* CONFIG_WPS_TESTING */
6622 wpa_s->wps_fragment_size = 0;
6623 wpas_wps_cancel(wpa_s);
6624 wps_registrar_flush(wpa_s->wps->registrar);
6625 #endif /* CONFIG_WPS */
6626 wpa_s->after_wps = 0;
6627 wpa_s->known_wps_freq = 0;
6630 #ifdef CONFIG_TDLS_TESTING
6631 extern unsigned int tdls_testing;
6633 #endif /* CONFIG_TDLS_TESTING */
6634 wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL);
6635 wpa_tdls_enable(wpa_s->wpa, 1);
6636 #endif /* CONFIG_TDLS */
6638 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, wpa_s, NULL);
6639 wpa_supplicant_stop_countermeasures(wpa_s, NULL);
6641 wpa_s->no_keep_alive = 0;
6642 wpa_s->own_disconnect_req = 0;
6644 os_free(wpa_s->disallow_aps_bssid);
6645 wpa_s->disallow_aps_bssid = NULL;
6646 wpa_s->disallow_aps_bssid_count = 0;
6647 os_free(wpa_s->disallow_aps_ssid);
6648 wpa_s->disallow_aps_ssid = NULL;
6649 wpa_s->disallow_aps_ssid_count = 0;
6651 wpa_s->set_sta_uapsd = 0;
6652 wpa_s->sta_uapsd = 0;
6654 wpa_drv_radio_disable(wpa_s, 0);
6655 wpa_blacklist_clear(wpa_s);
6656 wpa_s->extra_blacklist_count = 0;
6657 wpa_supplicant_ctrl_iface_remove_network(wpa_s, "all");
6658 wpa_supplicant_ctrl_iface_remove_cred(wpa_s, "all");
6659 wpa_config_flush_blobs(wpa_s->conf);
6660 wpa_s->conf->auto_interworking = 0;
6661 wpa_s->conf->okc = 0;
6663 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
6664 rsn_preauth_deinit(wpa_s->wpa);
6666 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, 43200);
6667 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, 70);
6668 wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, 60);
6669 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
6671 radio_remove_works(wpa_s, NULL, 1);
6672 wpa_s->ext_work_in_progress = 0;
6674 wpa_s->next_ssid = NULL;
6676 #ifdef CONFIG_INTERWORKING
6677 hs20_cancel_fetch_osu(wpa_s);
6678 #endif /* CONFIG_INTERWORKING */
6680 wpa_s->ext_mgmt_frame_handling = 0;
6681 wpa_s->ext_eapol_frame_io = 0;
6682 #ifdef CONFIG_TESTING_OPTIONS
6683 wpa_s->extra_roc_dur = 0;
6684 wpa_s->test_failure = WPAS_TEST_FAILURE_NONE;
6685 #endif /* CONFIG_TESTING_OPTIONS */
6687 wpa_s->disconnected = 0;
6688 os_free(wpa_s->next_scan_freqs);
6689 wpa_s->next_scan_freqs = NULL;
6691 wpa_bss_flush(wpa_s);
6692 if (!dl_list_empty(&wpa_s->bss)) {
6693 wpa_printf(MSG_DEBUG,
6694 "BSS table not empty after flush: %u entries, current_bss=%p bssid="
6695 MACSTR " pending_bssid=" MACSTR,
6696 dl_list_len(&wpa_s->bss), wpa_s->current_bss,
6697 MAC2STR(wpa_s->bssid),
6698 MAC2STR(wpa_s->pending_bssid));
6703 static int wpas_ctrl_radio_work_show(struct wpa_supplicant *wpa_s,
6704 char *buf, size_t buflen)
6706 struct wpa_radio_work *work;
6708 struct os_reltime now, diff;
6713 os_get_reltime(&now);
6715 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
6719 os_reltime_sub(&now, &work->time, &diff);
6720 ret = os_snprintf(pos, end - pos, "%s@%s:%u:%u:%ld.%06ld\n",
6721 work->type, work->wpa_s->ifname, work->freq,
6722 work->started, diff.sec, diff.usec);
6723 if (os_snprintf_error(end - pos, ret))
6732 static void wpas_ctrl_radio_work_timeout(void *eloop_ctx, void *timeout_ctx)
6734 struct wpa_radio_work *work = eloop_ctx;
6735 struct wpa_external_work *ework = work->ctx;
6737 wpa_dbg(work->wpa_s, MSG_DEBUG,
6738 "Timing out external radio work %u (%s)",
6739 ework->id, work->type);
6740 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_TIMEOUT "%u", ework->id);
6741 work->wpa_s->ext_work_in_progress = 0;
6742 radio_work_done(work);
6747 static void wpas_ctrl_radio_work_cb(struct wpa_radio_work *work, int deinit)
6749 struct wpa_external_work *ework = work->ctx;
6753 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
6760 wpa_dbg(work->wpa_s, MSG_DEBUG, "Starting external radio work %u (%s)",
6761 ework->id, ework->type);
6762 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_START "%u", ework->id);
6763 work->wpa_s->ext_work_in_progress = 1;
6764 if (!ework->timeout)
6765 ework->timeout = 10;
6766 eloop_register_timeout(ework->timeout, 0, wpas_ctrl_radio_work_timeout,
6771 static int wpas_ctrl_radio_work_add(struct wpa_supplicant *wpa_s, char *cmd,
6772 char *buf, size_t buflen)
6774 struct wpa_external_work *ework;
6778 unsigned int freq = 0;
6780 /* format: <name> [freq=<MHz>] [timeout=<seconds>] */
6782 ework = os_zalloc(sizeof(*ework));
6786 pos = os_strchr(cmd, ' ');
6788 type_len = pos - cmd;
6791 pos2 = os_strstr(pos, "freq=");
6793 freq = atoi(pos2 + 5);
6795 pos2 = os_strstr(pos, "timeout=");
6797 ework->timeout = atoi(pos2 + 8);
6799 type_len = os_strlen(cmd);
6801 if (4 + type_len >= sizeof(ework->type))
6802 type_len = sizeof(ework->type) - 4 - 1;
6803 os_strlcpy(ework->type, "ext:", sizeof(ework->type));
6804 os_memcpy(ework->type + 4, cmd, type_len);
6805 ework->type[4 + type_len] = '\0';
6807 wpa_s->ext_work_id++;
6808 if (wpa_s->ext_work_id == 0)
6809 wpa_s->ext_work_id++;
6810 ework->id = wpa_s->ext_work_id;
6812 if (radio_add_work(wpa_s, freq, ework->type, 0, wpas_ctrl_radio_work_cb,
6818 ret = os_snprintf(buf, buflen, "%u", ework->id);
6819 if (os_snprintf_error(buflen, ret))
6825 static int wpas_ctrl_radio_work_done(struct wpa_supplicant *wpa_s, char *cmd)
6827 struct wpa_radio_work *work;
6828 unsigned int id = atoi(cmd);
6830 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
6832 struct wpa_external_work *ework;
6834 if (os_strncmp(work->type, "ext:", 4) != 0)
6837 if (id && ework->id != id)
6839 wpa_dbg(wpa_s, MSG_DEBUG,
6840 "Completed external radio work %u (%s)",
6841 ework->id, ework->type);
6842 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, work, NULL);
6843 wpa_s->ext_work_in_progress = 0;
6844 radio_work_done(work);
6846 return 3; /* "OK\n" */
6853 static int wpas_ctrl_radio_work(struct wpa_supplicant *wpa_s, char *cmd,
6854 char *buf, size_t buflen)
6856 if (os_strcmp(cmd, "show") == 0)
6857 return wpas_ctrl_radio_work_show(wpa_s, buf, buflen);
6858 if (os_strncmp(cmd, "add ", 4) == 0)
6859 return wpas_ctrl_radio_work_add(wpa_s, cmd + 4, buf, buflen);
6860 if (os_strncmp(cmd, "done ", 5) == 0)
6861 return wpas_ctrl_radio_work_done(wpa_s, cmd + 4);
6866 void wpas_ctrl_radio_work_flush(struct wpa_supplicant *wpa_s)
6868 struct wpa_radio_work *work, *tmp;
6870 if (!wpa_s || !wpa_s->radio)
6873 dl_list_for_each_safe(work, tmp, &wpa_s->radio->work,
6874 struct wpa_radio_work, list) {
6875 struct wpa_external_work *ework;
6877 if (os_strncmp(work->type, "ext:", 4) != 0)
6880 wpa_dbg(wpa_s, MSG_DEBUG,
6881 "Flushing%s external radio work %u (%s)",
6882 work->started ? " started" : "", ework->id,
6885 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
6887 radio_work_done(work);
6893 static void wpas_ctrl_eapol_response(void *eloop_ctx, void *timeout_ctx)
6895 struct wpa_supplicant *wpa_s = eloop_ctx;
6896 eapol_sm_notify_ctrl_response(wpa_s->eapol);
6900 static int scan_id_list_parse(struct wpa_supplicant *wpa_s, const char *value,
6901 unsigned int *scan_id_count, int scan_id[])
6903 const char *pos = value;
6906 if (*pos == ' ' || *pos == '\0')
6908 if (*scan_id_count == MAX_SCAN_ID)
6910 scan_id[(*scan_id_count)++] = atoi(pos);
6911 pos = os_strchr(pos, ',');
6920 static void wpas_ctrl_scan(struct wpa_supplicant *wpa_s, char *params,
6921 char *reply, int reply_size, int *reply_len)
6924 unsigned int manual_scan_passive = 0;
6925 unsigned int manual_scan_use_id = 0;
6926 unsigned int manual_scan_only_new = 0;
6927 unsigned int scan_only = 0;
6928 unsigned int scan_id_count = 0;
6929 int scan_id[MAX_SCAN_ID];
6930 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
6931 struct wpa_scan_results *scan_res);
6932 int *manual_scan_freqs = NULL;
6934 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
6939 if (radio_work_pending(wpa_s, "scan")) {
6940 wpa_printf(MSG_DEBUG,
6941 "Pending scan scheduled - reject new request");
6942 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
6947 if (os_strncasecmp(params, "TYPE=ONLY", 9) == 0)
6950 pos = os_strstr(params, "freq=");
6952 manual_scan_freqs = freq_range_to_channel_list(wpa_s,
6954 if (manual_scan_freqs == NULL) {
6960 pos = os_strstr(params, "passive=");
6962 manual_scan_passive = !!atoi(pos + 8);
6964 pos = os_strstr(params, "use_id=");
6966 manual_scan_use_id = atoi(pos + 7);
6968 pos = os_strstr(params, "only_new=1");
6970 manual_scan_only_new = 1;
6972 pos = os_strstr(params, "scan_id=");
6973 if (pos && scan_id_list_parse(wpa_s, pos + 8, &scan_id_count,
6981 scan_res_handler = scan_only_handler;
6982 else if (wpa_s->scan_res_handler == scan_only_handler)
6983 scan_res_handler = NULL;
6985 scan_res_handler = wpa_s->scan_res_handler;
6987 if (!wpa_s->sched_scanning && !wpa_s->scanning &&
6988 ((wpa_s->wpa_state <= WPA_SCANNING) ||
6989 (wpa_s->wpa_state == WPA_COMPLETED))) {
6990 wpa_s->manual_scan_passive = manual_scan_passive;
6991 wpa_s->manual_scan_use_id = manual_scan_use_id;
6992 wpa_s->manual_scan_only_new = manual_scan_only_new;
6993 wpa_s->scan_id_count = scan_id_count;
6994 os_memcpy(wpa_s->scan_id, scan_id, scan_id_count * sizeof(int));
6995 wpa_s->scan_res_handler = scan_res_handler;
6996 os_free(wpa_s->manual_scan_freqs);
6997 wpa_s->manual_scan_freqs = manual_scan_freqs;
6998 manual_scan_freqs = NULL;
7000 wpa_s->normal_scans = 0;
7001 wpa_s->scan_req = MANUAL_SCAN_REQ;
7002 wpa_s->after_wps = 0;
7003 wpa_s->known_wps_freq = 0;
7004 wpa_supplicant_req_scan(wpa_s, 0, 0);
7005 if (wpa_s->manual_scan_use_id) {
7006 wpa_s->manual_scan_id++;
7007 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
7008 wpa_s->manual_scan_id);
7009 *reply_len = os_snprintf(reply, reply_size, "%u\n",
7010 wpa_s->manual_scan_id);
7012 } else if (wpa_s->sched_scanning) {
7013 wpa_s->manual_scan_passive = manual_scan_passive;
7014 wpa_s->manual_scan_use_id = manual_scan_use_id;
7015 wpa_s->manual_scan_only_new = manual_scan_only_new;
7016 wpa_s->scan_id_count = scan_id_count;
7017 os_memcpy(wpa_s->scan_id, scan_id, scan_id_count * sizeof(int));
7018 wpa_s->scan_res_handler = scan_res_handler;
7019 os_free(wpa_s->manual_scan_freqs);
7020 wpa_s->manual_scan_freqs = manual_scan_freqs;
7021 manual_scan_freqs = NULL;
7023 wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to allow requested full scan to proceed");
7024 wpa_supplicant_cancel_sched_scan(wpa_s);
7025 wpa_s->scan_req = MANUAL_SCAN_REQ;
7026 wpa_supplicant_req_scan(wpa_s, 0, 0);
7027 if (wpa_s->manual_scan_use_id) {
7028 wpa_s->manual_scan_id++;
7029 *reply_len = os_snprintf(reply, reply_size, "%u\n",
7030 wpa_s->manual_scan_id);
7031 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
7032 wpa_s->manual_scan_id);
7035 wpa_printf(MSG_DEBUG, "Ongoing scan action - reject new request");
7036 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
7040 os_free(manual_scan_freqs);
7044 #ifdef CONFIG_TESTING_OPTIONS
7046 static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant *wpa_s,
7047 unsigned int freq, const u8 *dst,
7048 const u8 *src, const u8 *bssid,
7049 const u8 *data, size_t data_len,
7050 enum offchannel_send_action_result
7053 wpa_msg(wpa_s, MSG_INFO, "MGMT-TX-STATUS freq=%u dst=" MACSTR
7054 " src=" MACSTR " bssid=" MACSTR " result=%s",
7055 freq, MAC2STR(dst), MAC2STR(src), MAC2STR(bssid),
7056 result == OFFCHANNEL_SEND_ACTION_SUCCESS ?
7057 "SUCCESS" : (result == OFFCHANNEL_SEND_ACTION_NO_ACK ?
7058 "NO_ACK" : "FAILED"));
7062 static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant *wpa_s, char *cmd)
7066 u8 *buf, da[ETH_ALEN], bssid[ETH_ALEN];
7068 int freq = 0, no_cck = 0, wait_time = 0;
7070 /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1]
7071 * <action=Action frame payload> */
7073 wpa_printf(MSG_DEBUG, "External MGMT TX: %s", cmd);
7076 used = hwaddr_aton2(pos, da);
7082 used = hwaddr_aton2(pos, bssid);
7087 param = os_strstr(pos, " freq=");
7093 param = os_strstr(pos, " no_cck=");
7096 no_cck = atoi(param);
7099 param = os_strstr(pos, " wait_time=");
7102 wait_time = atoi(param);
7105 param = os_strstr(pos, " action=");
7110 len = os_strlen(param);
7115 buf = os_malloc(len);
7119 if (hexstr2bin(param, buf, len) < 0) {
7124 res = offchannel_send_action(wpa_s, freq, da, wpa_s->own_addr, bssid,
7125 buf, len, wait_time,
7126 wpas_ctrl_iface_mgmt_tx_cb, no_cck);
7132 static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant *wpa_s)
7134 wpa_printf(MSG_DEBUG, "External MGMT TX - done waiting");
7135 offchannel_send_action_done(wpa_s);
7139 static int wpas_ctrl_iface_driver_event(struct wpa_supplicant *wpa_s, char *cmd)
7142 union wpa_event_data event;
7143 enum wpa_event_type ev;
7145 /* <event name> [parameters..] */
7147 wpa_dbg(wpa_s, MSG_DEBUG, "Testing - external driver event: %s", cmd);
7150 param = os_strchr(pos, ' ');
7154 os_memset(&event, 0, sizeof(event));
7156 if (os_strcmp(cmd, "INTERFACE_ENABLED") == 0) {
7157 ev = EVENT_INTERFACE_ENABLED;
7158 } else if (os_strcmp(cmd, "INTERFACE_DISABLED") == 0) {
7159 ev = EVENT_INTERFACE_DISABLED;
7160 } else if (os_strcmp(cmd, "AVOID_FREQUENCIES") == 0) {
7161 ev = EVENT_AVOID_FREQUENCIES;
7164 if (freq_range_list_parse(&event.freq_range, param) < 0)
7166 wpa_supplicant_event(wpa_s, ev, &event);
7167 os_free(event.freq_range.range);
7170 wpa_dbg(wpa_s, MSG_DEBUG, "Testing - unknown driver event: %s",
7175 wpa_supplicant_event(wpa_s, ev, &event);
7181 static int wpas_ctrl_iface_eapol_rx(struct wpa_supplicant *wpa_s, char *cmd)
7184 u8 src[ETH_ALEN], *buf;
7188 wpa_printf(MSG_DEBUG, "External EAPOL RX: %s", cmd);
7191 used = hwaddr_aton2(pos, src);
7198 len = os_strlen(pos);
7203 buf = os_malloc(len);
7207 if (hexstr2bin(pos, buf, len) < 0) {
7212 wpa_supplicant_rx_eapol(wpa_s, src, buf, len);
7219 static u16 ipv4_hdr_checksum(const void *buf, size_t len)
7223 const u16 *pos = buf;
7225 for (i = 0; i < len / 2; i++)
7229 sum = (sum & 0xffff) + (sum >> 16);
7231 return sum ^ 0xffff;
7235 #define HWSIM_PACKETLEN 1500
7236 #define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header))
7238 void wpas_data_test_rx(void *ctx, const u8 *src_addr, const u8 *buf, size_t len)
7240 struct wpa_supplicant *wpa_s = ctx;
7241 const struct ether_header *eth;
7242 const struct iphdr *ip;
7246 if (len != HWSIM_PACKETLEN)
7249 eth = (const struct ether_header *) buf;
7250 ip = (const struct iphdr *) (eth + 1);
7251 pos = (const u8 *) (ip + 1);
7253 if (ip->ihl != 5 || ip->version != 4 ||
7254 ntohs(ip->tot_len) != HWSIM_IP_LEN)
7257 for (i = 0; i < HWSIM_IP_LEN - sizeof(*ip); i++) {
7263 wpa_msg(wpa_s, MSG_INFO, "DATA-TEST-RX " MACSTR " " MACSTR,
7264 MAC2STR(eth->ether_dhost), MAC2STR(eth->ether_shost));
7268 static int wpas_ctrl_iface_data_test_config(struct wpa_supplicant *wpa_s,
7271 int enabled = atoi(cmd);
7274 if (wpa_s->l2_test) {
7275 l2_packet_deinit(wpa_s->l2_test);
7276 wpa_s->l2_test = NULL;
7277 wpa_dbg(wpa_s, MSG_DEBUG, "test data: Disabled");
7285 wpa_s->l2_test = l2_packet_init(wpa_s->ifname, wpa_s->own_addr,
7286 ETHERTYPE_IP, wpas_data_test_rx,
7288 if (wpa_s->l2_test == NULL)
7291 wpa_dbg(wpa_s, MSG_DEBUG, "test data: Enabled");
7297 static int wpas_ctrl_iface_data_test_tx(struct wpa_supplicant *wpa_s, char *cmd)
7299 u8 dst[ETH_ALEN], src[ETH_ALEN];
7304 u8 buf[HWSIM_PACKETLEN];
7305 struct ether_header *eth;
7310 if (wpa_s->l2_test == NULL)
7313 /* format: <dst> <src> <tos> */
7316 used = hwaddr_aton2(pos, dst);
7322 used = hwaddr_aton2(pos, src);
7327 val = strtol(pos, NULL, 0);
7328 if (val < 0 || val > 0xff)
7332 eth = (struct ether_header *) buf;
7333 os_memcpy(eth->ether_dhost, dst, ETH_ALEN);
7334 os_memcpy(eth->ether_shost, src, ETH_ALEN);
7335 eth->ether_type = htons(ETHERTYPE_IP);
7336 ip = (struct iphdr *) (eth + 1);
7337 os_memset(ip, 0, sizeof(*ip));
7342 ip->tot_len = htons(HWSIM_IP_LEN);
7344 ip->saddr = htonl(192 << 24 | 168 << 16 | 1 << 8 | 1);
7345 ip->daddr = htonl(192 << 24 | 168 << 16 | 1 << 8 | 2);
7346 ip->check = ipv4_hdr_checksum(ip, sizeof(*ip));
7347 dpos = (u8 *) (ip + 1);
7348 for (i = 0; i < HWSIM_IP_LEN - sizeof(*ip); i++)
7351 if (l2_packet_send(wpa_s->l2_test, dst, ETHERTYPE_IP, buf,
7352 HWSIM_PACKETLEN) < 0)
7355 wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX dst=" MACSTR " src=" MACSTR
7356 " tos=0x%x", MAC2STR(dst), MAC2STR(src), tos);
7362 static int wpas_ctrl_iface_data_test_frame(struct wpa_supplicant *wpa_s,
7366 struct ether_header *eth;
7367 struct l2_packet_data *l2 = NULL;
7372 len = os_strlen(cmd);
7373 if (len & 1 || len < ETH_HLEN * 2)
7377 buf = os_malloc(len);
7381 if (hexstr2bin(cmd, buf, len) < 0)
7384 eth = (struct ether_header *) buf;
7385 ethertype = ntohs(eth->ether_type);
7387 l2 = l2_packet_init(wpa_s->ifname, wpa_s->own_addr, ethertype,
7388 wpas_data_test_rx, wpa_s, 1);
7392 res = l2_packet_send(l2, eth->ether_dhost, ethertype, buf, len);
7393 wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX frame res=%d", res);
7396 l2_packet_deinit(l2);
7399 return res < 0 ? -1 : 0;
7403 static int wpas_ctrl_test_alloc_fail(struct wpa_supplicant *wpa_s, char *cmd)
7405 #ifdef WPA_TRACE_BFD
7406 extern char wpa_trace_fail_func[256];
7407 extern unsigned int wpa_trace_fail_after;
7410 wpa_trace_fail_after = atoi(cmd);
7411 pos = os_strchr(cmd, ':');
7414 os_strlcpy(wpa_trace_fail_func, pos,
7415 sizeof(wpa_trace_fail_func));
7417 wpa_trace_fail_after = 0;
7420 #else /* WPA_TRACE_BFD */
7422 #endif /* WPA_TRACE_BFD */
7426 static int wpas_ctrl_get_alloc_fail(struct wpa_supplicant *wpa_s,
7427 char *buf, size_t buflen)
7429 #ifdef WPA_TRACE_BFD
7430 extern char wpa_trace_fail_func[256];
7431 extern unsigned int wpa_trace_fail_after;
7433 return os_snprintf(buf, buflen, "%u:%s", wpa_trace_fail_after,
7434 wpa_trace_fail_func);
7435 #else /* WPA_TRACE_BFD */
7437 #endif /* WPA_TRACE_BFD */
7440 #endif /* CONFIG_TESTING_OPTIONS */
7443 static void wpas_ctrl_vendor_elem_update(struct wpa_supplicant *wpa_s)
7448 wpa_printf(MSG_DEBUG, "Update vendor elements");
7450 for (i = 0; i < NUM_VENDOR_ELEM_FRAMES; i++) {
7451 if (wpa_s->vendor_elem[i]) {
7454 res = os_snprintf(buf, sizeof(buf), "frame[%u]", i);
7455 if (!os_snprintf_error(sizeof(buf), res)) {
7456 wpa_hexdump_buf(MSG_DEBUG, buf,
7457 wpa_s->vendor_elem[i]);
7463 if (wpa_s->parent == wpa_s &&
7464 wpa_s->global->p2p &&
7465 !wpa_s->global->p2p_disabled)
7466 p2p_set_vendor_elems(wpa_s->global->p2p, wpa_s->vendor_elem);
7467 #endif /* CONFIG_P2P */
7471 static struct wpa_supplicant *
7472 wpas_ctrl_vendor_elem_iface(struct wpa_supplicant *wpa_s,
7473 enum wpa_vendor_elem_frame frame)
7477 case VENDOR_ELEM_PROBE_REQ_P2P:
7478 case VENDOR_ELEM_PROBE_RESP_P2P:
7479 case VENDOR_ELEM_PROBE_RESP_P2P_GO:
7480 case VENDOR_ELEM_BEACON_P2P_GO:
7481 case VENDOR_ELEM_P2P_PD_REQ:
7482 case VENDOR_ELEM_P2P_PD_RESP:
7483 case VENDOR_ELEM_P2P_GO_NEG_REQ:
7484 case VENDOR_ELEM_P2P_GO_NEG_RESP:
7485 case VENDOR_ELEM_P2P_GO_NEG_CONF:
7486 case VENDOR_ELEM_P2P_INV_REQ:
7487 case VENDOR_ELEM_P2P_INV_RESP:
7488 case VENDOR_ELEM_P2P_ASSOC_REQ:
7489 return wpa_s->parent;
7490 #endif /* CONFIG_P2P */
7497 static int wpas_ctrl_vendor_elem_add(struct wpa_supplicant *wpa_s, char *cmd)
7503 struct ieee802_11_elems elems;
7506 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
7508 wpa_s = wpas_ctrl_vendor_elem_iface(wpa_s, frame);
7510 pos = os_strchr(pos, ' ');
7515 len = os_strlen(pos);
7522 buf = wpabuf_alloc(len);
7526 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
7531 if (ieee802_11_parse_elems(wpabuf_head_u8(buf), len, &elems, 0) ==
7537 if (wpa_s->vendor_elem[frame] == NULL) {
7538 wpa_s->vendor_elem[frame] = buf;
7539 wpas_ctrl_vendor_elem_update(wpa_s);
7543 if (wpabuf_resize(&wpa_s->vendor_elem[frame], len) < 0) {
7548 wpabuf_put_buf(wpa_s->vendor_elem[frame], buf);
7550 wpas_ctrl_vendor_elem_update(wpa_s);
7556 static int wpas_ctrl_vendor_elem_get(struct wpa_supplicant *wpa_s, char *cmd,
7557 char *buf, size_t buflen)
7559 int frame = atoi(cmd);
7561 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
7563 wpa_s = wpas_ctrl_vendor_elem_iface(wpa_s, frame);
7565 if (wpa_s->vendor_elem[frame] == NULL)
7568 return wpa_snprintf_hex(buf, buflen,
7569 wpabuf_head_u8(wpa_s->vendor_elem[frame]),
7570 wpabuf_len(wpa_s->vendor_elem[frame]));
7574 static int wpas_ctrl_vendor_elem_remove(struct wpa_supplicant *wpa_s, char *cmd)
7580 struct ieee802_11_elems elems;
7584 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
7586 wpa_s = wpas_ctrl_vendor_elem_iface(wpa_s, frame);
7588 pos = os_strchr(pos, ' ');
7594 wpabuf_free(wpa_s->vendor_elem[frame]);
7595 wpa_s->vendor_elem[frame] = NULL;
7596 wpas_ctrl_vendor_elem_update(wpa_s);
7600 if (wpa_s->vendor_elem[frame] == NULL)
7603 len = os_strlen(pos);
7610 buf = os_malloc(len);
7614 if (hexstr2bin(pos, buf, len) < 0) {
7619 if (ieee802_11_parse_elems(buf, len, &elems, 0) == ParseFailed) {
7624 ie = wpabuf_mhead_u8(wpa_s->vendor_elem[frame]);
7625 end = ie + wpabuf_len(wpa_s->vendor_elem[frame]);
7627 for (; ie + 1 < end; ie += 2 + ie[1]) {
7630 if (os_memcmp(ie, buf, len) != 0)
7633 if (wpabuf_len(wpa_s->vendor_elem[frame]) == len) {
7634 wpabuf_free(wpa_s->vendor_elem[frame]);
7635 wpa_s->vendor_elem[frame] = NULL;
7637 os_memmove(ie, ie + len,
7639 wpa_s->vendor_elem[frame]->used -= len;
7642 wpas_ctrl_vendor_elem_update(wpa_s);
7652 static void wpas_ctrl_neighbor_rep_cb(void *ctx, struct wpabuf *neighbor_rep)
7654 struct wpa_supplicant *wpa_s = ctx;
7657 wpa_msg_ctrl(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_RXED
7659 (unsigned int) wpabuf_len(neighbor_rep));
7660 wpabuf_free(neighbor_rep);
7662 wpa_msg_ctrl(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_FAILED);
7667 static int wpas_ctrl_iface_send_neigbor_rep(struct wpa_supplicant *wpa_s,
7670 struct wpa_ssid ssid;
7671 struct wpa_ssid *ssid_p = NULL;
7674 if (os_strncmp(cmd, " ssid=", 6) == 0) {
7675 ssid.ssid_len = os_strlen(cmd + 6);
7676 if (ssid.ssid_len > 32)
7678 ssid.ssid = (u8 *) (cmd + 6);
7682 ret = wpas_rrm_send_neighbor_rep_request(wpa_s, ssid_p,
7683 wpas_ctrl_neighbor_rep_cb,
7690 static int wpas_ctrl_iface_erp_flush(struct wpa_supplicant *wpa_s)
7692 eapol_sm_erp_flush(wpa_s->eapol);
7697 static int wpas_ctrl_iface_mac_rand_scan(struct wpa_supplicant *wpa_s,
7700 char *token, *context = NULL;
7701 unsigned int enable = ~0, type = 0;
7702 u8 _addr[ETH_ALEN], _mask[ETH_ALEN];
7703 u8 *addr = NULL, *mask = NULL;
7705 while ((token = str_token(cmd, " ", &context))) {
7706 if (os_strcasecmp(token, "scan") == 0) {
7707 type |= MAC_ADDR_RAND_SCAN;
7708 } else if (os_strcasecmp(token, "sched") == 0) {
7709 type |= MAC_ADDR_RAND_SCHED_SCAN;
7710 } else if (os_strcasecmp(token, "pno") == 0) {
7711 type |= MAC_ADDR_RAND_PNO;
7712 } else if (os_strcasecmp(token, "all") == 0) {
7713 type = wpa_s->mac_addr_rand_supported;
7714 } else if (os_strncasecmp(token, "enable=", 7) == 0) {
7715 enable = atoi(token + 7);
7716 } else if (os_strncasecmp(token, "addr=", 5) == 0) {
7718 if (hwaddr_aton(token + 5, addr)) {
7719 wpa_printf(MSG_INFO,
7720 "CTRL: Invalid MAC address: %s",
7724 } else if (os_strncasecmp(token, "mask=", 5) == 0) {
7726 if (hwaddr_aton(token + 5, mask)) {
7727 wpa_printf(MSG_INFO,
7728 "CTRL: Invalid MAC address mask: %s",
7733 wpa_printf(MSG_INFO,
7734 "CTRL: Invalid MAC_RAND_SCAN parameter: %s",
7741 wpa_printf(MSG_INFO, "CTRL: MAC_RAND_SCAN no type specified");
7745 if ((wpa_s->mac_addr_rand_supported & type) != type) {
7746 wpa_printf(MSG_INFO,
7747 "CTRL: MAC_RAND_SCAN types=%u != supported=%u",
7748 type, wpa_s->mac_addr_rand_supported);
7753 wpa_printf(MSG_INFO,
7754 "CTRL: MAC_RAND_SCAN enable=<0/1> not specified");
7759 wpas_mac_addr_rand_scan_clear(wpa_s, type);
7761 if (type & MAC_ADDR_RAND_PNO) {
7762 wpas_stop_pno(wpa_s);
7763 wpas_start_pno(wpa_s);
7765 } else if (wpa_s->sched_scanning &&
7766 (type & MAC_ADDR_RAND_SCHED_SCAN)) {
7767 /* simulate timeout to restart the sched scan */
7768 wpa_s->sched_scan_timed_out = 1;
7769 wpa_s->prev_sched_ssid = NULL;
7770 wpa_supplicant_cancel_sched_scan(wpa_s);
7775 if ((addr && !mask) || (!addr && mask)) {
7776 wpa_printf(MSG_INFO,
7777 "CTRL: MAC_RAND_SCAN invalid addr/mask combination");
7781 if (addr && mask && (!(mask[0] & 0x01) || (addr[0] & 0x01))) {
7782 wpa_printf(MSG_INFO,
7783 "CTRL: MAC_RAND_SCAN cannot allow multicast address");
7787 if (type & MAC_ADDR_RAND_SCAN) {
7788 wpas_mac_addr_rand_scan_set(wpa_s, MAC_ADDR_RAND_SCAN,
7792 if (type & MAC_ADDR_RAND_SCHED_SCAN) {
7793 wpas_mac_addr_rand_scan_set(wpa_s, MAC_ADDR_RAND_SCHED_SCAN,
7796 if (wpa_s->sched_scanning && !wpa_s->pno) {
7797 /* simulate timeout to restart the sched scan */
7798 wpa_s->sched_scan_timed_out = 1;
7799 wpa_s->prev_sched_ssid = NULL;
7800 wpa_supplicant_cancel_sched_scan(wpa_s);
7804 if (type & MAC_ADDR_RAND_PNO) {
7805 wpas_mac_addr_rand_scan_set(wpa_s, MAC_ADDR_RAND_PNO,
7808 wpas_stop_pno(wpa_s);
7809 wpas_start_pno(wpa_s);
7817 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
7818 char *buf, size_t *resp_len)
7821 const int reply_size = 4096;
7824 if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 ||
7825 os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
7826 if (wpa_debug_show_keys)
7827 wpa_dbg(wpa_s, MSG_DEBUG,
7828 "Control interface command '%s'", buf);
7830 wpa_dbg(wpa_s, MSG_DEBUG,
7831 "Control interface command '%s [REMOVED]'",
7832 os_strncmp(buf, WPA_CTRL_RSP,
7833 os_strlen(WPA_CTRL_RSP)) == 0 ?
7834 WPA_CTRL_RSP : "SET_NETWORK");
7835 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ", 16) == 0 ||
7836 os_strncmp(buf, "NFC_REPORT_HANDOVER", 19) == 0) {
7837 wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface",
7838 (const u8 *) buf, os_strlen(buf));
7840 int level = MSG_DEBUG;
7841 if (os_strcmp(buf, "PING") == 0)
7842 level = MSG_EXCESSIVE;
7843 wpa_dbg(wpa_s, level, "Control interface command '%s'", buf);
7846 reply = os_malloc(reply_size);
7847 if (reply == NULL) {
7852 os_memcpy(reply, "OK\n", 3);
7855 if (os_strcmp(buf, "PING") == 0) {
7856 os_memcpy(reply, "PONG\n", 5);
7858 } else if (os_strcmp(buf, "IFNAME") == 0) {
7859 reply_len = os_strlen(wpa_s->ifname);
7860 os_memcpy(reply, wpa_s->ifname, reply_len);
7861 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
7862 if (wpa_debug_reopen_file() < 0)
7864 } else if (os_strncmp(buf, "NOTE ", 5) == 0) {
7865 wpa_printf(MSG_INFO, "NOTE: %s", buf + 5);
7866 } else if (os_strcmp(buf, "MIB") == 0) {
7867 reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size);
7868 if (reply_len >= 0) {
7869 reply_len += eapol_sm_get_mib(wpa_s->eapol,
7871 reply_size - reply_len);
7873 } else if (os_strncmp(buf, "STATUS", 6) == 0) {
7874 reply_len = wpa_supplicant_ctrl_iface_status(
7875 wpa_s, buf + 6, reply, reply_size);
7876 } else if (os_strcmp(buf, "PMKSA") == 0) {
7877 reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, reply,
7879 } else if (os_strcmp(buf, "PMKSA_FLUSH") == 0) {
7880 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
7881 } else if (os_strncmp(buf, "SET ", 4) == 0) {
7882 if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4))
7884 } else if (os_strncmp(buf, "DUMP", 4) == 0) {
7885 reply_len = wpa_config_dump_values(wpa_s->conf,
7887 } else if (os_strncmp(buf, "GET ", 4) == 0) {
7888 reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4,
7890 } else if (os_strcmp(buf, "LOGON") == 0) {
7891 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
7892 } else if (os_strcmp(buf, "LOGOFF") == 0) {
7893 eapol_sm_notify_logoff(wpa_s->eapol, TRUE);
7894 } else if (os_strcmp(buf, "REASSOCIATE") == 0) {
7895 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
7898 wpas_request_connection(wpa_s);
7899 } else if (os_strcmp(buf, "REATTACH") == 0) {
7900 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED ||
7901 !wpa_s->current_ssid)
7904 wpa_s->reattach = 1;
7905 wpas_request_connection(wpa_s);
7907 } else if (os_strcmp(buf, "RECONNECT") == 0) {
7908 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
7910 else if (wpa_s->disconnected)
7911 wpas_request_connection(wpa_s);
7912 #ifdef IEEE8021X_EAPOL
7913 } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) {
7914 if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8))
7916 #endif /* IEEE8021X_EAPOL */
7917 #ifdef CONFIG_PEERKEY
7918 } else if (os_strncmp(buf, "STKSTART ", 9) == 0) {
7919 if (wpa_supplicant_ctrl_iface_stkstart(wpa_s, buf + 9))
7921 #endif /* CONFIG_PEERKEY */
7922 #ifdef CONFIG_IEEE80211R
7923 } else if (os_strncmp(buf, "FT_DS ", 6) == 0) {
7924 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6))
7926 #endif /* CONFIG_IEEE80211R */
7928 } else if (os_strcmp(buf, "WPS_PBC") == 0) {
7929 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL);
7931 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
7935 } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) {
7936 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8);
7938 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
7942 } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {
7943 reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8,
7946 } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) {
7947 reply_len = wpa_supplicant_ctrl_iface_wps_check_pin(
7948 wpa_s, buf + 14, reply, reply_size);
7949 } else if (os_strcmp(buf, "WPS_CANCEL") == 0) {
7950 if (wpas_wps_cancel(wpa_s))
7952 #ifdef CONFIG_WPS_NFC
7953 } else if (os_strcmp(buf, "WPS_NFC") == 0) {
7954 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, NULL))
7956 } else if (os_strncmp(buf, "WPS_NFC ", 8) == 0) {
7957 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, buf + 8))
7959 } else if (os_strncmp(buf, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
7960 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_config_token(
7961 wpa_s, buf + 21, reply, reply_size);
7962 } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) {
7963 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_token(
7964 wpa_s, buf + 14, reply, reply_size);
7965 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) {
7966 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s,
7969 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
7970 reply_len = wpas_ctrl_nfc_get_handover_req(
7971 wpa_s, buf + 21, reply, reply_size);
7972 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
7973 reply_len = wpas_ctrl_nfc_get_handover_sel(
7974 wpa_s, buf + 21, reply, reply_size);
7975 } else if (os_strncmp(buf, "NFC_REPORT_HANDOVER ", 20) == 0) {
7976 if (wpas_ctrl_nfc_report_handover(wpa_s, buf + 20))
7978 #endif /* CONFIG_WPS_NFC */
7979 } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) {
7980 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8))
7983 } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) {
7984 reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin(
7985 wpa_s, buf + 11, reply, reply_size);
7986 #endif /* CONFIG_AP */
7987 #ifdef CONFIG_WPS_ER
7988 } else if (os_strcmp(buf, "WPS_ER_START") == 0) {
7989 if (wpas_wps_er_start(wpa_s, NULL))
7991 } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) {
7992 if (wpas_wps_er_start(wpa_s, buf + 13))
7994 } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) {
7995 wpas_wps_er_stop(wpa_s);
7996 } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) {
7997 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11))
7999 } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) {
8000 int ret = wpas_wps_er_pbc(wpa_s, buf + 11);
8002 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
8004 } else if (ret == -3) {
8005 os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18);
8007 } else if (ret == -4) {
8008 os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20);
8012 } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) {
8013 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13))
8015 } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) {
8016 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s,
8019 } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) {
8020 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14))
8022 #ifdef CONFIG_WPS_NFC
8023 } else if (os_strncmp(buf, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
8024 reply_len = wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
8025 wpa_s, buf + 24, reply, reply_size);
8026 #endif /* CONFIG_WPS_NFC */
8027 #endif /* CONFIG_WPS_ER */
8028 #endif /* CONFIG_WPS */
8029 #ifdef CONFIG_IBSS_RSN
8030 } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) {
8031 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9))
8033 #endif /* CONFIG_IBSS_RSN */
8035 } else if (os_strncmp(buf, "MESH_INTERFACE_ADD ", 19) == 0) {
8036 reply_len = wpa_supplicant_ctrl_iface_mesh_interface_add(
8037 wpa_s, buf + 19, reply, reply_size);
8038 } else if (os_strcmp(buf, "MESH_INTERFACE_ADD") == 0) {
8039 reply_len = wpa_supplicant_ctrl_iface_mesh_interface_add(
8040 wpa_s, "", reply, reply_size);
8041 } else if (os_strncmp(buf, "MESH_GROUP_ADD ", 15) == 0) {
8042 if (wpa_supplicant_ctrl_iface_mesh_group_add(wpa_s, buf + 15))
8044 } else if (os_strncmp(buf, "MESH_GROUP_REMOVE ", 18) == 0) {
8045 if (wpa_supplicant_ctrl_iface_mesh_group_remove(wpa_s,
8048 #endif /* CONFIG_MESH */
8050 } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) {
8051 if (p2p_ctrl_find(wpa_s, buf + 8))
8053 } else if (os_strcmp(buf, "P2P_FIND") == 0) {
8054 if (p2p_ctrl_find(wpa_s, ""))
8056 } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) {
8057 wpas_p2p_stop_find(wpa_s);
8058 } else if (os_strncmp(buf, "P2P_ASP_PROVISION ", 18) == 0) {
8059 if (p2p_ctrl_asp_provision(wpa_s, buf + 18))
8061 } else if (os_strncmp(buf, "P2P_ASP_PROVISION_RESP ", 23) == 0) {
8062 if (p2p_ctrl_asp_provision_resp(wpa_s, buf + 23))
8064 } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) {
8065 reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply,
8067 } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) {
8068 if (p2p_ctrl_listen(wpa_s, buf + 11))
8070 } else if (os_strcmp(buf, "P2P_LISTEN") == 0) {
8071 if (p2p_ctrl_listen(wpa_s, ""))
8073 } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) {
8074 if (wpas_p2p_group_remove(wpa_s, buf + 17))
8076 } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) {
8077 if (wpas_p2p_group_add(wpa_s, 0, 0, 0, 0))
8079 } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) {
8080 if (p2p_ctrl_group_add(wpa_s, buf + 14))
8082 } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) {
8083 if (p2p_ctrl_prov_disc(wpa_s, buf + 14))
8085 } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) {
8086 reply_len = p2p_get_passphrase(wpa_s, reply, reply_size);
8087 } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) {
8088 reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply,
8090 } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
8091 if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0)
8093 } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) {
8094 if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0)
8096 } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) {
8097 wpas_p2p_sd_service_update(wpa_s);
8098 } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
8099 if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0)
8101 } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) {
8102 wpas_p2p_service_flush(wpa_s);
8103 } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) {
8104 if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0)
8106 } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) {
8107 if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0)
8109 } else if (os_strncmp(buf, "P2P_SERVICE_REP ", 16) == 0) {
8110 if (p2p_ctrl_service_replace(wpa_s, buf + 16) < 0)
8112 } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) {
8113 if (p2p_ctrl_reject(wpa_s, buf + 11) < 0)
8115 } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) {
8116 if (p2p_ctrl_invite(wpa_s, buf + 11) < 0)
8118 } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) {
8119 reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply,
8121 } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) {
8122 if (p2p_ctrl_set(wpa_s, buf + 8) < 0)
8124 } else if (os_strcmp(buf, "P2P_FLUSH") == 0) {
8125 p2p_ctrl_flush(wpa_s);
8126 } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) {
8127 if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0)
8129 } else if (os_strcmp(buf, "P2P_CANCEL") == 0) {
8130 if (wpas_p2p_cancel(wpa_s))
8132 } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) {
8133 if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0)
8135 } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) {
8136 if (p2p_ctrl_presence_req(wpa_s, "") < 0)
8138 } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) {
8139 if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0)
8141 } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) {
8142 if (p2p_ctrl_ext_listen(wpa_s, "") < 0)
8144 } else if (os_strncmp(buf, "P2P_REMOVE_CLIENT ", 18) == 0) {
8145 if (p2p_ctrl_remove_client(wpa_s, buf + 18) < 0)
8147 #endif /* CONFIG_P2P */
8148 #ifdef CONFIG_WIFI_DISPLAY
8149 } else if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0) {
8150 if (wifi_display_subelem_set(wpa_s->global, buf + 16) < 0)
8152 } else if (os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) {
8153 reply_len = wifi_display_subelem_get(wpa_s->global, buf + 16,
8155 #endif /* CONFIG_WIFI_DISPLAY */
8156 #ifdef CONFIG_INTERWORKING
8157 } else if (os_strcmp(buf, "FETCH_ANQP") == 0) {
8158 if (interworking_fetch_anqp(wpa_s) < 0)
8160 } else if (os_strcmp(buf, "STOP_FETCH_ANQP") == 0) {
8161 interworking_stop_fetch_anqp(wpa_s);
8162 } else if (os_strcmp(buf, "INTERWORKING_SELECT") == 0) {
8163 if (ctrl_interworking_select(wpa_s, NULL) < 0)
8165 } else if (os_strncmp(buf, "INTERWORKING_SELECT ", 20) == 0) {
8166 if (ctrl_interworking_select(wpa_s, buf + 20) < 0)
8168 } else if (os_strncmp(buf, "INTERWORKING_CONNECT ", 21) == 0) {
8169 if (ctrl_interworking_connect(wpa_s, buf + 21, 0) < 0)
8171 } else if (os_strncmp(buf, "INTERWORKING_ADD_NETWORK ", 25) == 0) {
8174 id = ctrl_interworking_connect(wpa_s, buf + 25, 1);
8178 reply_len = os_snprintf(reply, reply_size, "%d\n", id);
8179 if (os_snprintf_error(reply_size, reply_len))
8182 } else if (os_strncmp(buf, "ANQP_GET ", 9) == 0) {
8183 if (get_anqp(wpa_s, buf + 9) < 0)
8185 } else if (os_strncmp(buf, "GAS_REQUEST ", 12) == 0) {
8186 if (gas_request(wpa_s, buf + 12) < 0)
8188 } else if (os_strncmp(buf, "GAS_RESPONSE_GET ", 17) == 0) {
8189 reply_len = gas_response_get(wpa_s, buf + 17, reply,
8191 #endif /* CONFIG_INTERWORKING */
8193 } else if (os_strncmp(buf, "HS20_ANQP_GET ", 14) == 0) {
8194 if (get_hs20_anqp(wpa_s, buf + 14) < 0)
8196 } else if (os_strncmp(buf, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
8197 if (hs20_get_nai_home_realm_list(wpa_s, buf + 29) < 0)
8199 } else if (os_strncmp(buf, "HS20_ICON_REQUEST ", 18) == 0) {
8200 if (hs20_icon_request(wpa_s, buf + 18) < 0)
8202 } else if (os_strcmp(buf, "FETCH_OSU") == 0) {
8203 if (hs20_fetch_osu(wpa_s) < 0)
8205 } else if (os_strcmp(buf, "CANCEL_FETCH_OSU") == 0) {
8206 hs20_cancel_fetch_osu(wpa_s);
8207 #endif /* CONFIG_HS20 */
8208 } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0)
8210 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
8211 wpa_s, buf + os_strlen(WPA_CTRL_RSP)))
8215 * Notify response from timeout to allow the control
8216 * interface response to be sent first.
8218 eloop_register_timeout(0, 0, wpas_ctrl_eapol_response,
8221 } else if (os_strcmp(buf, "RECONFIGURE") == 0) {
8222 if (wpa_supplicant_reload_configuration(wpa_s))
8224 } else if (os_strcmp(buf, "TERMINATE") == 0) {
8225 wpa_supplicant_terminate_proc(wpa_s->global);
8226 } else if (os_strncmp(buf, "BSSID ", 6) == 0) {
8227 if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6))
8229 } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) {
8230 reply_len = wpa_supplicant_ctrl_iface_blacklist(
8231 wpa_s, buf + 9, reply, reply_size);
8232 } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) {
8233 reply_len = wpa_supplicant_ctrl_iface_log_level(
8234 wpa_s, buf + 9, reply, reply_size);
8235 } else if (os_strncmp(buf, "LIST_NETWORKS ", 14) == 0) {
8236 reply_len = wpa_supplicant_ctrl_iface_list_networks(
8237 wpa_s, buf + 14, reply, reply_size);
8238 } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) {
8239 reply_len = wpa_supplicant_ctrl_iface_list_networks(
8240 wpa_s, NULL, reply, reply_size);
8241 } else if (os_strcmp(buf, "DISCONNECT") == 0) {
8243 wpa_s->sme.prev_bssid_set = 0;
8244 #endif /* CONFIG_SME */
8245 wpa_s->reassociate = 0;
8246 wpa_s->disconnected = 1;
8247 wpa_supplicant_cancel_sched_scan(wpa_s);
8248 wpa_supplicant_cancel_scan(wpa_s);
8249 wpa_supplicant_deauthenticate(wpa_s,
8250 WLAN_REASON_DEAUTH_LEAVING);
8251 } else if (os_strcmp(buf, "SCAN") == 0) {
8252 wpas_ctrl_scan(wpa_s, NULL, reply, reply_size, &reply_len);
8253 } else if (os_strncmp(buf, "SCAN ", 5) == 0) {
8254 wpas_ctrl_scan(wpa_s, buf + 5, reply, reply_size, &reply_len);
8255 } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) {
8256 reply_len = wpa_supplicant_ctrl_iface_scan_results(
8257 wpa_s, reply, reply_size);
8258 } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) {
8259 if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15))
8261 } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) {
8262 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15))
8264 } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) {
8265 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16))
8267 } else if (os_strcmp(buf, "ADD_NETWORK") == 0) {
8268 reply_len = wpa_supplicant_ctrl_iface_add_network(
8269 wpa_s, reply, reply_size);
8270 } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) {
8271 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15))
8273 } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
8274 if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12))
8276 } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) {
8277 reply_len = wpa_supplicant_ctrl_iface_get_network(
8278 wpa_s, buf + 12, reply, reply_size);
8279 } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) {
8280 if (wpa_supplicant_ctrl_iface_dup_network(wpa_s, buf + 12))
8282 } else if (os_strcmp(buf, "LIST_CREDS") == 0) {
8283 reply_len = wpa_supplicant_ctrl_iface_list_creds(
8284 wpa_s, reply, reply_size);
8285 } else if (os_strcmp(buf, "ADD_CRED") == 0) {
8286 reply_len = wpa_supplicant_ctrl_iface_add_cred(
8287 wpa_s, reply, reply_size);
8288 } else if (os_strncmp(buf, "REMOVE_CRED ", 12) == 0) {
8289 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s, buf + 12))
8291 } else if (os_strncmp(buf, "SET_CRED ", 9) == 0) {
8292 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s, buf + 9))
8294 } else if (os_strncmp(buf, "GET_CRED ", 9) == 0) {
8295 reply_len = wpa_supplicant_ctrl_iface_get_cred(wpa_s, buf + 9,
8298 #ifndef CONFIG_NO_CONFIG_WRITE
8299 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
8300 if (wpa_supplicant_ctrl_iface_save_config(wpa_s))
8302 #endif /* CONFIG_NO_CONFIG_WRITE */
8303 } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
8304 reply_len = wpa_supplicant_ctrl_iface_get_capability(
8305 wpa_s, buf + 15, reply, reply_size);
8306 } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) {
8307 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8))
8309 } else if (os_strncmp(buf, "SCAN_INTERVAL ", 14) == 0) {
8310 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s, buf + 14))
8312 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
8313 reply_len = wpa_supplicant_global_iface_list(
8314 wpa_s->global, reply, reply_size);
8315 } else if (os_strcmp(buf, "INTERFACES") == 0) {
8316 reply_len = wpa_supplicant_global_iface_interfaces(
8317 wpa_s->global, reply, reply_size);
8318 } else if (os_strncmp(buf, "BSS ", 4) == 0) {
8319 reply_len = wpa_supplicant_ctrl_iface_bss(
8320 wpa_s, buf + 4, reply, reply_size);
8322 } else if (os_strcmp(buf, "STA-FIRST") == 0) {
8323 reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size);
8324 } else if (os_strncmp(buf, "STA ", 4) == 0) {
8325 reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply,
8327 } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) {
8328 reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply,
8330 } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) {
8331 if (ap_ctrl_iface_sta_deauthenticate(wpa_s, buf + 15))
8333 } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) {
8334 if (ap_ctrl_iface_sta_disassociate(wpa_s, buf + 13))
8336 } else if (os_strncmp(buf, "CHAN_SWITCH ", 12) == 0) {
8337 if (ap_ctrl_iface_chanswitch(wpa_s, buf + 12))
8339 } else if (os_strcmp(buf, "STOP_AP") == 0) {
8340 if (wpas_ap_stop_ap(wpa_s))
8342 #endif /* CONFIG_AP */
8343 } else if (os_strcmp(buf, "SUSPEND") == 0) {
8344 wpas_notify_suspend(wpa_s->global);
8345 } else if (os_strcmp(buf, "RESUME") == 0) {
8346 wpas_notify_resume(wpa_s->global);
8347 #ifdef CONFIG_TESTING_OPTIONS
8348 } else if (os_strcmp(buf, "DROP_SA") == 0) {
8349 wpa_supplicant_ctrl_iface_drop_sa(wpa_s);
8350 #endif /* CONFIG_TESTING_OPTIONS */
8351 } else if (os_strncmp(buf, "ROAM ", 5) == 0) {
8352 if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5))
8354 } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) {
8355 wpa_s->auto_reconnect_disabled = atoi(buf + 16) == 0;
8356 } else if (os_strncmp(buf, "BSS_EXPIRE_AGE ", 15) == 0) {
8357 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s, buf + 15))
8359 } else if (os_strncmp(buf, "BSS_EXPIRE_COUNT ", 17) == 0) {
8360 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s,
8363 } else if (os_strncmp(buf, "BSS_FLUSH ", 10) == 0) {
8364 wpa_supplicant_ctrl_iface_bss_flush(wpa_s, buf + 10);
8366 } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) {
8367 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14))
8369 } else if (os_strncmp(buf, "TDLS_SETUP ", 11) == 0) {
8370 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s, buf + 11))
8372 } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) {
8373 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14))
8375 } else if (os_strncmp(buf, "TDLS_CHAN_SWITCH ", 17) == 0) {
8376 if (wpa_supplicant_ctrl_iface_tdls_chan_switch(wpa_s,
8379 } else if (os_strncmp(buf, "TDLS_CANCEL_CHAN_SWITCH ", 24) == 0) {
8380 if (wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(wpa_s,
8383 #endif /* CONFIG_TDLS */
8384 } else if (os_strcmp(buf, "WMM_AC_STATUS") == 0) {
8385 reply_len = wpas_wmm_ac_status(wpa_s, reply, reply_size);
8386 } else if (os_strncmp(buf, "WMM_AC_ADDTS ", 13) == 0) {
8387 if (wmm_ac_ctrl_addts(wpa_s, buf + 13))
8389 } else if (os_strncmp(buf, "WMM_AC_DELTS ", 13) == 0) {
8390 if (wmm_ac_ctrl_delts(wpa_s, buf + 13))
8392 } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) {
8393 reply_len = wpa_supplicant_signal_poll(wpa_s, reply,
8395 } else if (os_strncmp(buf, "PKTCNT_POLL", 11) == 0) {
8396 reply_len = wpa_supplicant_pktcnt_poll(wpa_s, reply,
8398 #ifdef CONFIG_AUTOSCAN
8399 } else if (os_strncmp(buf, "AUTOSCAN ", 9) == 0) {
8400 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s, buf + 9))
8402 #endif /* CONFIG_AUTOSCAN */
8404 } else if (os_strncmp(buf, "DRIVER ", 7) == 0) {
8405 reply_len = wpa_supplicant_driver_cmd(wpa_s, buf + 7, reply,
8407 #endif /* ANDROID */
8408 } else if (os_strncmp(buf, "VENDOR ", 7) == 0) {
8409 reply_len = wpa_supplicant_vendor_cmd(wpa_s, buf + 7, reply,
8411 } else if (os_strcmp(buf, "REAUTHENTICATE") == 0) {
8412 pmksa_cache_clear_current(wpa_s->wpa);
8413 eapol_sm_request_reauth(wpa_s->eapol);
8415 } else if (os_strncmp(buf, "WNM_SLEEP ", 10) == 0) {
8416 if (wpas_ctrl_iface_wnm_sleep(wpa_s, buf + 10))
8418 } else if (os_strncmp(buf, "WNM_BSS_QUERY ", 14) == 0) {
8419 if (wpas_ctrl_iface_wnm_bss_query(wpa_s, buf + 14))
8421 #endif /* CONFIG_WNM */
8422 } else if (os_strcmp(buf, "FLUSH") == 0) {
8423 wpa_supplicant_ctrl_iface_flush(wpa_s);
8424 } else if (os_strncmp(buf, "RADIO_WORK ", 11) == 0) {
8425 reply_len = wpas_ctrl_radio_work(wpa_s, buf + 11, reply,
8427 #ifdef CONFIG_TESTING_OPTIONS
8428 } else if (os_strncmp(buf, "MGMT_TX ", 8) == 0) {
8429 if (wpas_ctrl_iface_mgmt_tx(wpa_s, buf + 8) < 0)
8431 } else if (os_strcmp(buf, "MGMT_TX_DONE") == 0) {
8432 wpas_ctrl_iface_mgmt_tx_done(wpa_s);
8433 } else if (os_strncmp(buf, "DRIVER_EVENT ", 13) == 0) {
8434 if (wpas_ctrl_iface_driver_event(wpa_s, buf + 13) < 0)
8436 } else if (os_strncmp(buf, "EAPOL_RX ", 9) == 0) {
8437 if (wpas_ctrl_iface_eapol_rx(wpa_s, buf + 9) < 0)
8439 } else if (os_strncmp(buf, "DATA_TEST_CONFIG ", 17) == 0) {
8440 if (wpas_ctrl_iface_data_test_config(wpa_s, buf + 17) < 0)
8442 } else if (os_strncmp(buf, "DATA_TEST_TX ", 13) == 0) {
8443 if (wpas_ctrl_iface_data_test_tx(wpa_s, buf + 13) < 0)
8445 } else if (os_strncmp(buf, "DATA_TEST_FRAME ", 16) == 0) {
8446 if (wpas_ctrl_iface_data_test_frame(wpa_s, buf + 16) < 0)
8448 } else if (os_strncmp(buf, "TEST_ALLOC_FAIL ", 16) == 0) {
8449 if (wpas_ctrl_test_alloc_fail(wpa_s, buf + 16) < 0)
8451 } else if (os_strcmp(buf, "GET_ALLOC_FAIL") == 0) {
8452 reply_len = wpas_ctrl_get_alloc_fail(wpa_s, reply, reply_size);
8453 #endif /* CONFIG_TESTING_OPTIONS */
8454 } else if (os_strncmp(buf, "VENDOR_ELEM_ADD ", 16) == 0) {
8455 if (wpas_ctrl_vendor_elem_add(wpa_s, buf + 16) < 0)
8457 } else if (os_strncmp(buf, "VENDOR_ELEM_GET ", 16) == 0) {
8458 reply_len = wpas_ctrl_vendor_elem_get(wpa_s, buf + 16, reply,
8460 } else if (os_strncmp(buf, "VENDOR_ELEM_REMOVE ", 19) == 0) {
8461 if (wpas_ctrl_vendor_elem_remove(wpa_s, buf + 19) < 0)
8463 } else if (os_strncmp(buf, "NEIGHBOR_REP_REQUEST", 20) == 0) {
8464 if (wpas_ctrl_iface_send_neigbor_rep(wpa_s, buf + 20))
8466 } else if (os_strcmp(buf, "ERP_FLUSH") == 0) {
8467 wpas_ctrl_iface_erp_flush(wpa_s);
8468 } else if (os_strncmp(buf, "MAC_RAND_SCAN ", 14) == 0) {
8469 if (wpas_ctrl_iface_mac_rand_scan(wpa_s, buf + 14))
8472 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
8476 if (reply_len < 0) {
8477 os_memcpy(reply, "FAIL\n", 5);
8481 *resp_len = reply_len;
8486 static int wpa_supplicant_global_iface_add(struct wpa_global *global,
8489 struct wpa_interface iface;
8493 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
8494 * TAB<bridge_ifname>
8496 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd);
8498 os_memset(&iface, 0, sizeof(iface));
8501 iface.ifname = pos = cmd;
8502 pos = os_strchr(pos, '\t');
8505 if (iface.ifname[0] == '\0')
8510 iface.confname = pos;
8511 pos = os_strchr(pos, '\t');
8514 if (iface.confname[0] == '\0')
8515 iface.confname = NULL;
8520 pos = os_strchr(pos, '\t');
8523 if (iface.driver[0] == '\0')
8524 iface.driver = NULL;
8528 iface.ctrl_interface = pos;
8529 pos = os_strchr(pos, '\t');
8532 if (iface.ctrl_interface[0] == '\0')
8533 iface.ctrl_interface = NULL;
8537 iface.driver_param = pos;
8538 pos = os_strchr(pos, '\t');
8541 if (iface.driver_param[0] == '\0')
8542 iface.driver_param = NULL;
8546 iface.bridge_ifname = pos;
8547 pos = os_strchr(pos, '\t');
8550 if (iface.bridge_ifname[0] == '\0')
8551 iface.bridge_ifname = NULL;
8556 if (wpa_supplicant_get_iface(global, iface.ifname))
8559 return wpa_supplicant_add_iface(global, &iface, NULL) ? 0 : -1;
8563 static int wpa_supplicant_global_iface_remove(struct wpa_global *global,
8566 struct wpa_supplicant *wpa_s;
8568 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd);
8570 wpa_s = wpa_supplicant_get_iface(global, cmd);
8573 return wpa_supplicant_remove_iface(global, wpa_s, 0);
8577 static void wpa_free_iface_info(struct wpa_interface_info *iface)
8579 struct wpa_interface_info *prev;
8583 iface = iface->next;
8585 os_free(prev->ifname);
8586 os_free(prev->desc);
8592 static int wpa_supplicant_global_iface_list(struct wpa_global *global,
8596 struct wpa_interface_info *iface = NULL, *last = NULL, *tmp;
8599 for (i = 0; wpa_drivers[i]; i++) {
8600 struct wpa_driver_ops *drv = wpa_drivers[i];
8601 if (drv->get_interfaces == NULL)
8603 tmp = drv->get_interfaces(global->drv_priv[i]);
8617 for (tmp = iface; tmp; tmp = tmp->next) {
8618 res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n",
8619 tmp->drv_name, tmp->ifname,
8620 tmp->desc ? tmp->desc : "");
8621 if (os_snprintf_error(end - pos, res)) {
8628 wpa_free_iface_info(iface);
8634 static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
8639 struct wpa_supplicant *wpa_s;
8641 wpa_s = global->ifaces;
8646 res = os_snprintf(pos, end - pos, "%s\n", wpa_s->ifname);
8647 if (os_snprintf_error(end - pos, res)) {
8652 wpa_s = wpa_s->next;
8658 static char * wpas_global_ctrl_iface_ifname(struct wpa_global *global,
8660 char *cmd, size_t *resp_len)
8662 struct wpa_supplicant *wpa_s;
8664 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
8665 if (os_strcmp(ifname, wpa_s->ifname) == 0)
8669 if (wpa_s == NULL) {
8670 char *resp = os_strdup("FAIL-NO-IFNAME-MATCH\n");
8672 *resp_len = os_strlen(resp);
8678 return wpa_supplicant_ctrl_iface_process(wpa_s, cmd, resp_len);
8682 static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global *global,
8683 char *buf, size_t *resp_len)
8686 static const char * cmd[] = {
8692 "P2P_GET_PASSPHRASE",
8693 "P2P_SERVICE_UPDATE",
8694 "P2P_SERVICE_FLUSH",
8701 static const char * prefix[] = {
8704 #endif /* ANDROID */
8710 "P2P_GROUP_REMOVE ",
8713 "P2P_SERV_DISC_REQ ",
8714 "P2P_SERV_DISC_CANCEL_REQ ",
8715 "P2P_SERV_DISC_RESP ",
8716 "P2P_SERV_DISC_EXTERNAL ",
8725 "P2P_PRESENCE_REQ ",
8727 "P2P_REMOVE_CLIENT ",
8729 "WPS_NFC_TAG_READ ",
8730 "NFC_GET_HANDOVER_SEL ",
8731 "NFC_GET_HANDOVER_REQ ",
8732 "NFC_REPORT_HANDOVER ",
8733 "P2P_ASP_PROVISION ",
8734 "P2P_ASP_PROVISION_RESP ",
8740 if (global->p2p_init_wpa_s == NULL)
8743 for (i = 0; !found && cmd[i]; i++) {
8744 if (os_strcmp(buf, cmd[i]) == 0)
8748 for (i = 0; !found && prefix[i]; i++) {
8749 if (os_strncmp(buf, prefix[i], os_strlen(prefix[i])) == 0)
8754 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
8756 #endif /* CONFIG_P2P */
8761 static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global *global,
8762 char *buf, size_t *resp_len)
8764 #ifdef CONFIG_WIFI_DISPLAY
8765 if (global->p2p_init_wpa_s == NULL)
8767 if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0 ||
8768 os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0)
8769 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
8771 #endif /* CONFIG_WIFI_DISPLAY */
8776 static char * wpas_global_ctrl_iface_redir(struct wpa_global *global,
8777 char *buf, size_t *resp_len)
8781 ret = wpas_global_ctrl_iface_redir_p2p(global, buf, resp_len);
8785 ret = wpas_global_ctrl_iface_redir_wfd(global, buf, resp_len);
8793 static int wpas_global_ctrl_iface_set(struct wpa_global *global, char *cmd)
8797 value = os_strchr(cmd, ' ');
8802 wpa_printf(MSG_DEBUG, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd, value);
8804 #ifdef CONFIG_WIFI_DISPLAY
8805 if (os_strcasecmp(cmd, "wifi_display") == 0) {
8806 wifi_display_enable(global, !!atoi(value));
8809 #endif /* CONFIG_WIFI_DISPLAY */
8811 /* Restore cmd to its original value to allow redirection */
8818 #ifndef CONFIG_NO_CONFIG_WRITE
8819 static int wpas_global_ctrl_iface_save_config(struct wpa_global *global)
8821 int ret = 0, saved = 0;
8822 struct wpa_supplicant *wpa_s;
8824 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
8825 if (!wpa_s->conf->update_config) {
8826 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
8830 if (wpa_config_write(wpa_s->confname, wpa_s->conf)) {
8831 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
8834 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
8839 if (!saved && !ret) {
8840 wpa_dbg(wpa_s, MSG_DEBUG,
8841 "CTRL_IFACE: SAVE_CONFIG - No configuration files could be updated");
8847 #endif /* CONFIG_NO_CONFIG_WRITE */
8850 static int wpas_global_ctrl_iface_status(struct wpa_global *global,
8851 char *buf, size_t buflen)
8855 struct wpa_supplicant *wpa_s;
8861 if (global->p2p && !global->p2p_disabled) {
8862 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
8865 MAC2STR(global->p2p_dev_addr),
8866 p2p_get_state_txt(global->p2p));
8867 if (os_snprintf_error(end - pos, ret))
8870 } else if (global->p2p) {
8871 ret = os_snprintf(pos, end - pos, "p2p_state=DISABLED\n");
8872 if (os_snprintf_error(end - pos, ret))
8876 #endif /* CONFIG_P2P */
8878 #ifdef CONFIG_WIFI_DISPLAY
8879 ret = os_snprintf(pos, end - pos, "wifi_display=%d\n",
8880 !!global->wifi_display);
8881 if (os_snprintf_error(end - pos, ret))
8884 #endif /* CONFIG_WIFI_DISPLAY */
8886 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
8887 ret = os_snprintf(pos, end - pos, "ifname=%s\n"
8888 "address=" MACSTR "\n",
8889 wpa_s->ifname, MAC2STR(wpa_s->own_addr));
8890 if (os_snprintf_error(end - pos, ret))
8899 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
8900 char *buf, size_t *resp_len)
8903 const int reply_size = 2048;
8905 int level = MSG_DEBUG;
8907 if (os_strncmp(buf, "IFNAME=", 7) == 0) {
8908 char *pos = os_strchr(buf + 7, ' ');
8911 return wpas_global_ctrl_iface_ifname(global,
8917 reply = wpas_global_ctrl_iface_redir(global, buf, resp_len);
8921 if (os_strcmp(buf, "PING") == 0)
8922 level = MSG_EXCESSIVE;
8923 wpa_hexdump_ascii(level, "RX global ctrl_iface",
8924 (const u8 *) buf, os_strlen(buf));
8926 reply = os_malloc(reply_size);
8927 if (reply == NULL) {
8932 os_memcpy(reply, "OK\n", 3);
8935 if (os_strcmp(buf, "PING") == 0) {
8936 os_memcpy(reply, "PONG\n", 5);
8938 } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) {
8939 if (wpa_supplicant_global_iface_add(global, buf + 14))
8941 } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) {
8942 if (wpa_supplicant_global_iface_remove(global, buf + 17))
8944 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
8945 reply_len = wpa_supplicant_global_iface_list(
8946 global, reply, reply_size);
8947 } else if (os_strcmp(buf, "INTERFACES") == 0) {
8948 reply_len = wpa_supplicant_global_iface_interfaces(
8949 global, reply, reply_size);
8950 } else if (os_strcmp(buf, "TERMINATE") == 0) {
8951 wpa_supplicant_terminate_proc(global);
8952 } else if (os_strcmp(buf, "SUSPEND") == 0) {
8953 wpas_notify_suspend(global);
8954 } else if (os_strcmp(buf, "RESUME") == 0) {
8955 wpas_notify_resume(global);
8956 } else if (os_strncmp(buf, "SET ", 4) == 0) {
8957 if (wpas_global_ctrl_iface_set(global, buf + 4)) {
8959 if (global->p2p_init_wpa_s) {
8961 /* Check if P2P redirection would work for this
8963 return wpa_supplicant_ctrl_iface_process(
8964 global->p2p_init_wpa_s,
8967 #endif /* CONFIG_P2P */
8970 #ifndef CONFIG_NO_CONFIG_WRITE
8971 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
8972 if (wpas_global_ctrl_iface_save_config(global))
8974 #endif /* CONFIG_NO_CONFIG_WRITE */
8975 } else if (os_strcmp(buf, "STATUS") == 0) {
8976 reply_len = wpas_global_ctrl_iface_status(global, reply,
8978 #ifdef CONFIG_MODULE_TESTS
8979 } else if (os_strcmp(buf, "MODULE_TESTS") == 0) {
8980 int wpas_module_tests(void);
8981 if (wpas_module_tests() < 0)
8983 #endif /* CONFIG_MODULE_TESTS */
8984 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
8985 if (wpa_debug_reopen_file() < 0)
8988 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
8992 if (reply_len < 0) {
8993 os_memcpy(reply, "FAIL\n", 5);
8997 *resp_len = reply_len;