2 * WPA Supplicant / Control interface (shared code for all backends)
3 * Copyright (c) 2004-2014, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
9 #include "utils/includes.h"
10 #ifdef CONFIG_TESTING_OPTIONS
11 #include <net/ethernet.h>
12 #include <netinet/ip.h>
13 #endif /* CONFIG_TESTING_OPTIONS */
15 #include "utils/common.h"
16 #include "utils/eloop.h"
17 #include "utils/uuid.h"
18 #include "common/version.h"
19 #include "common/ieee802_11_defs.h"
20 #include "common/ieee802_11_common.h"
21 #include "common/wpa_ctrl.h"
22 #include "ap/hostapd.h"
23 #include "eap_peer/eap.h"
24 #include "eapol_supp/eapol_supp_sm.h"
25 #include "rsn_supp/wpa.h"
26 #include "rsn_supp/preauth.h"
27 #include "rsn_supp/pmksa_cache.h"
28 #include "l2_packet/l2_packet.h"
31 #include "wpa_supplicant_i.h"
33 #include "wps_supplicant.h"
36 #include "p2p_supplicant.h"
38 #include "hs20_supplicant.h"
39 #include "wifi_display.h"
43 #include "ctrl_iface.h"
44 #include "interworking.h"
45 #include "blacklist.h"
48 #include "offchannel.h"
49 #include "drivers/driver.h"
52 static int wpa_supplicant_global_iface_list(struct wpa_global *global,
54 static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
56 static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s,
59 static int set_bssid_filter(struct wpa_supplicant *wpa_s, char *val)
62 u8 addr[ETH_ALEN], *filter = NULL, *n;
69 if (hwaddr_aton(pos, addr)) {
73 n = os_realloc_array(filter, count + 1, ETH_ALEN);
79 os_memcpy(filter + count * ETH_ALEN, addr, ETH_ALEN);
82 pos = os_strchr(pos, ' ');
87 wpa_hexdump(MSG_DEBUG, "bssid_filter", filter, count * ETH_ALEN);
88 os_free(wpa_s->bssid_filter);
89 wpa_s->bssid_filter = filter;
90 wpa_s->bssid_filter_count = count;
96 static int set_disallow_aps(struct wpa_supplicant *wpa_s, char *val)
99 u8 addr[ETH_ALEN], *bssid = NULL, *n;
100 struct wpa_ssid_value *ssid = NULL, *ns;
101 size_t count = 0, ssid_count = 0;
105 * disallow_list ::= <ssid_spec> | <bssid_spec> | <disallow_list> | ""
106 * SSID_SPEC ::= ssid <SSID_HEX>
107 * BSSID_SPEC ::= bssid <BSSID_HEX>
114 if (os_strncmp(pos, "bssid ", 6) == 0) {
117 res = hwaddr_aton2(pos, addr);
121 wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
122 "BSSID value '%s'", pos);
126 n = os_realloc_array(bssid, count + 1, ETH_ALEN);
133 os_memcpy(bssid + count * ETH_ALEN, addr, ETH_ALEN);
135 } else if (os_strncmp(pos, "ssid ", 5) == 0) {
141 if (*end == '\0' || *end == ' ')
146 ns = os_realloc_array(ssid, ssid_count + 1,
147 sizeof(struct wpa_ssid_value));
155 if ((end - pos) & 0x01 || end - pos > 2 * 32 ||
156 hexstr2bin(pos, ssid[ssid_count].ssid,
157 (end - pos) / 2) < 0) {
160 wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
161 "SSID value '%s'", pos);
164 ssid[ssid_count].ssid_len = (end - pos) / 2;
165 wpa_hexdump_ascii(MSG_DEBUG, "disallow_aps SSID",
166 ssid[ssid_count].ssid,
167 ssid[ssid_count].ssid_len);
171 wpa_printf(MSG_DEBUG, "Unexpected disallow_aps value "
178 pos = os_strchr(pos, ' ');
183 wpa_hexdump(MSG_DEBUG, "disallow_aps_bssid", bssid, count * ETH_ALEN);
184 os_free(wpa_s->disallow_aps_bssid);
185 wpa_s->disallow_aps_bssid = bssid;
186 wpa_s->disallow_aps_bssid_count = count;
188 wpa_printf(MSG_DEBUG, "disallow_aps_ssid_count %d", (int) ssid_count);
189 os_free(wpa_s->disallow_aps_ssid);
190 wpa_s->disallow_aps_ssid = ssid;
191 wpa_s->disallow_aps_ssid_count = ssid_count;
193 if (!wpa_s->current_ssid || wpa_s->wpa_state < WPA_AUTHENTICATING)
196 c = wpa_s->current_ssid;
197 if (c->mode != WPAS_MODE_INFRA && c->mode != WPAS_MODE_IBSS)
200 if (!disallowed_bssid(wpa_s, wpa_s->bssid) &&
201 !disallowed_ssid(wpa_s, c->ssid, c->ssid_len))
204 wpa_printf(MSG_DEBUG, "Disconnect and try to find another network "
205 "because current AP was marked disallowed");
208 wpa_s->sme.prev_bssid_set = 0;
209 #endif /* CONFIG_SME */
210 wpa_s->reassociate = 1;
211 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
212 wpa_supplicant_req_scan(wpa_s, 0, 0);
218 #ifndef CONFIG_NO_CONFIG_BLOBS
219 static int wpas_ctrl_set_blob(struct wpa_supplicant *wpa_s, char *pos)
222 struct wpa_config_blob *blob;
225 pos = os_strchr(pos, ' ');
229 len = os_strlen(pos);
233 wpa_printf(MSG_DEBUG, "CTRL: Set blob '%s'", name);
234 blob = os_zalloc(sizeof(*blob));
237 blob->name = os_strdup(name);
238 blob->data = os_malloc(len / 2);
239 if (blob->name == NULL || blob->data == NULL) {
240 wpa_config_free_blob(blob);
244 if (hexstr2bin(pos, blob->data, len / 2) < 0) {
245 wpa_printf(MSG_DEBUG, "CTRL: Invalid blob hex data");
246 wpa_config_free_blob(blob);
251 wpa_config_set_blob(wpa_s->conf, blob);
255 #endif /* CONFIG_NO_CONFIG_BLOBS */
258 static int wpas_ctrl_pno(struct wpa_supplicant *wpa_s, char *cmd)
266 params = os_strchr(cmd, ' ');
267 os_free(wpa_s->manual_sched_scan_freqs);
270 pos = os_strstr(params, "freq=");
272 freqs = freq_range_to_channel_list(wpa_s,
275 wpa_s->manual_sched_scan_freqs = freqs;
276 ret = wpas_start_pno(wpa_s);
278 ret = wpas_stop_pno(wpa_s);
284 static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s,
290 value = os_strchr(cmd, ' ');
295 wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value);
296 if (os_strcasecmp(cmd, "EAPOL::heldPeriod") == 0) {
297 eapol_sm_configure(wpa_s->eapol,
298 atoi(value), -1, -1, -1);
299 } else if (os_strcasecmp(cmd, "EAPOL::authPeriod") == 0) {
300 eapol_sm_configure(wpa_s->eapol,
301 -1, atoi(value), -1, -1);
302 } else if (os_strcasecmp(cmd, "EAPOL::startPeriod") == 0) {
303 eapol_sm_configure(wpa_s->eapol,
304 -1, -1, atoi(value), -1);
305 } else if (os_strcasecmp(cmd, "EAPOL::maxStart") == 0) {
306 eapol_sm_configure(wpa_s->eapol,
307 -1, -1, -1, atoi(value));
308 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKLifetime") == 0) {
309 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME,
312 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKReauthThreshold") ==
314 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD,
317 } else if (os_strcasecmp(cmd, "dot11RSNAConfigSATimeout") == 0) {
318 if (wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, atoi(value)))
320 } else if (os_strcasecmp(cmd, "wps_fragment_size") == 0) {
321 wpa_s->wps_fragment_size = atoi(value);
322 #ifdef CONFIG_WPS_TESTING
323 } else if (os_strcasecmp(cmd, "wps_version_number") == 0) {
325 val = strtol(value, NULL, 0);
326 if (val < 0 || val > 0xff) {
328 wpa_printf(MSG_DEBUG, "WPS: Invalid "
329 "wps_version_number %ld", val);
331 wps_version_number = val;
332 wpa_printf(MSG_DEBUG, "WPS: Testing - force WPS "
334 (wps_version_number & 0xf0) >> 4,
335 wps_version_number & 0x0f);
337 } else if (os_strcasecmp(cmd, "wps_testing_dummy_cred") == 0) {
338 wps_testing_dummy_cred = atoi(value);
339 wpa_printf(MSG_DEBUG, "WPS: Testing - dummy_cred=%d",
340 wps_testing_dummy_cred);
341 } else if (os_strcasecmp(cmd, "wps_corrupt_pkhash") == 0) {
342 wps_corrupt_pkhash = atoi(value);
343 wpa_printf(MSG_DEBUG, "WPS: Testing - wps_corrupt_pkhash=%d",
345 #endif /* CONFIG_WPS_TESTING */
346 } else if (os_strcasecmp(cmd, "ampdu") == 0) {
347 if (wpa_drv_ampdu(wpa_s, atoi(value)) < 0)
350 #ifdef CONFIG_TDLS_TESTING
351 } else if (os_strcasecmp(cmd, "tdls_testing") == 0) {
352 extern unsigned int tdls_testing;
353 tdls_testing = strtol(value, NULL, 0);
354 wpa_printf(MSG_DEBUG, "TDLS: tdls_testing=0x%x", tdls_testing);
355 #endif /* CONFIG_TDLS_TESTING */
356 } else if (os_strcasecmp(cmd, "tdls_disabled") == 0) {
357 int disabled = atoi(value);
358 wpa_printf(MSG_DEBUG, "TDLS: tdls_disabled=%d", disabled);
360 if (wpa_drv_tdls_oper(wpa_s, TDLS_DISABLE, NULL) < 0)
362 } else if (wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL) < 0)
364 wpa_tdls_enable(wpa_s->wpa, !disabled);
365 #endif /* CONFIG_TDLS */
366 } else if (os_strcasecmp(cmd, "pno") == 0) {
367 ret = wpas_ctrl_pno(wpa_s, value);
368 } else if (os_strcasecmp(cmd, "radio_disabled") == 0) {
369 int disabled = atoi(value);
370 if (wpa_drv_radio_disable(wpa_s, disabled) < 0)
373 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
374 } else if (os_strcasecmp(cmd, "uapsd") == 0) {
375 if (os_strcmp(value, "disable") == 0)
376 wpa_s->set_sta_uapsd = 0;
380 /* format: BE,BK,VI,VO;max SP Length */
382 pos = os_strchr(value, ',');
387 pos = os_strchr(pos, ',');
392 pos = os_strchr(pos, ',');
397 /* ignore max SP Length for now */
399 wpa_s->set_sta_uapsd = 1;
400 wpa_s->sta_uapsd = 0;
402 wpa_s->sta_uapsd |= BIT(0);
404 wpa_s->sta_uapsd |= BIT(1);
406 wpa_s->sta_uapsd |= BIT(2);
408 wpa_s->sta_uapsd |= BIT(3);
410 } else if (os_strcasecmp(cmd, "ps") == 0) {
411 ret = wpa_drv_set_p2p_powersave(wpa_s, atoi(value), -1, -1);
412 #ifdef CONFIG_WIFI_DISPLAY
413 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
414 int enabled = !!atoi(value);
415 if (enabled && !wpa_s->global->p2p)
418 wifi_display_enable(wpa_s->global, enabled);
419 #endif /* CONFIG_WIFI_DISPLAY */
420 } else if (os_strcasecmp(cmd, "bssid_filter") == 0) {
421 ret = set_bssid_filter(wpa_s, value);
422 } else if (os_strcasecmp(cmd, "disallow_aps") == 0) {
423 ret = set_disallow_aps(wpa_s, value);
424 } else if (os_strcasecmp(cmd, "no_keep_alive") == 0) {
425 wpa_s->no_keep_alive = !!atoi(value);
426 #ifdef CONFIG_TESTING_OPTIONS
427 } else if (os_strcasecmp(cmd, "ext_mgmt_frame_handling") == 0) {
428 wpa_s->ext_mgmt_frame_handling = !!atoi(value);
429 } else if (os_strcasecmp(cmd, "ext_eapol_frame_io") == 0) {
430 wpa_s->ext_eapol_frame_io = !!atoi(value);
432 if (wpa_s->ap_iface) {
433 wpa_s->ap_iface->bss[0]->ext_eapol_frame_io =
434 wpa_s->ext_eapol_frame_io;
436 #endif /* CONFIG_AP */
437 } else if (os_strcasecmp(cmd, "extra_roc_dur") == 0) {
438 wpa_s->extra_roc_dur = atoi(value);
439 #endif /* CONFIG_TESTING_OPTIONS */
440 #ifndef CONFIG_NO_CONFIG_BLOBS
441 } else if (os_strcmp(cmd, "blob") == 0) {
442 ret = wpas_ctrl_set_blob(wpa_s, value);
443 #endif /* CONFIG_NO_CONFIG_BLOBS */
444 } else if (os_strcasecmp(cmd, "setband") == 0) {
445 if (os_strcmp(value, "AUTO") == 0)
446 wpa_s->setband = WPA_SETBAND_AUTO;
447 else if (os_strcmp(value, "5G") == 0)
448 wpa_s->setband = WPA_SETBAND_5G;
449 else if (os_strcmp(value, "2G") == 0)
450 wpa_s->setband = WPA_SETBAND_2G;
455 ret = wpa_config_process_global(wpa_s->conf, cmd, -1);
457 wpa_supplicant_update_config(wpa_s);
464 static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s,
465 char *cmd, char *buf, size_t buflen)
469 wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd);
471 if (os_strcmp(cmd, "version") == 0) {
472 res = os_snprintf(buf, buflen, "%s", VERSION_STR);
473 } else if (os_strcasecmp(cmd, "country") == 0) {
474 if (wpa_s->conf->country[0] && wpa_s->conf->country[1])
475 res = os_snprintf(buf, buflen, "%c%c",
476 wpa_s->conf->country[0],
477 wpa_s->conf->country[1]);
478 #ifdef CONFIG_WIFI_DISPLAY
479 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
481 if (wpa_s->global->p2p == NULL ||
482 wpa_s->global->p2p_disabled)
485 enabled = wpa_s->global->wifi_display;
486 res = os_snprintf(buf, buflen, "%d", enabled);
487 #endif /* CONFIG_WIFI_DISPLAY */
488 #ifdef CONFIG_TESTING_GET_GTK
489 } else if (os_strcmp(cmd, "gtk") == 0) {
490 if (wpa_s->last_gtk_len == 0)
492 res = wpa_snprintf_hex(buf, buflen, wpa_s->last_gtk,
493 wpa_s->last_gtk_len);
495 #endif /* CONFIG_TESTING_GET_GTK */
498 if (os_snprintf_error(buflen, res))
504 #ifdef IEEE8021X_EAPOL
505 static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s,
509 struct wpa_ssid *ssid = wpa_s->current_ssid;
511 if (hwaddr_aton(addr, bssid)) {
512 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address "
517 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid));
518 rsn_preauth_deinit(wpa_s->wpa);
519 if (rsn_preauth_init(wpa_s->wpa, bssid, ssid ? &ssid->eap : NULL))
524 #endif /* IEEE8021X_EAPOL */
527 #ifdef CONFIG_PEERKEY
528 /* MLME-STKSTART.request(peer) */
529 static int wpa_supplicant_ctrl_iface_stkstart(
530 struct wpa_supplicant *wpa_s, char *addr)
534 if (hwaddr_aton(addr, peer)) {
535 wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART: invalid "
536 "address '%s'", addr);
540 wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART " MACSTR,
543 return wpa_sm_stkstart(wpa_s->wpa, peer);
545 #endif /* CONFIG_PEERKEY */
550 static int wpa_supplicant_ctrl_iface_tdls_discover(
551 struct wpa_supplicant *wpa_s, char *addr)
556 if (hwaddr_aton(addr, peer)) {
557 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER: invalid "
558 "address '%s'", addr);
562 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER " MACSTR,
565 if (wpa_tdls_is_external_setup(wpa_s->wpa))
566 ret = wpa_tdls_send_discovery_request(wpa_s->wpa, peer);
568 ret = wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer);
574 static int wpa_supplicant_ctrl_iface_tdls_setup(
575 struct wpa_supplicant *wpa_s, char *addr)
580 if (hwaddr_aton(addr, peer)) {
581 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP: invalid "
582 "address '%s'", addr);
586 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP " MACSTR,
589 if ((wpa_s->conf->tdls_external_control) &&
590 wpa_tdls_is_external_setup(wpa_s->wpa))
591 return wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
593 wpa_tdls_remove(wpa_s->wpa, peer);
595 if (wpa_tdls_is_external_setup(wpa_s->wpa))
596 ret = wpa_tdls_start(wpa_s->wpa, peer);
598 ret = wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
604 static int wpa_supplicant_ctrl_iface_tdls_teardown(
605 struct wpa_supplicant *wpa_s, char *addr)
610 if (os_strcmp(addr, "*") == 0) {
611 /* remove everyone */
612 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN *");
613 wpa_tdls_teardown_peers(wpa_s->wpa);
617 if (hwaddr_aton(addr, peer)) {
618 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN: invalid "
619 "address '%s'", addr);
623 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN " MACSTR,
626 if ((wpa_s->conf->tdls_external_control) &&
627 wpa_tdls_is_external_setup(wpa_s->wpa))
628 return wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
630 if (wpa_tdls_is_external_setup(wpa_s->wpa))
631 ret = wpa_tdls_teardown_link(
633 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED);
635 ret = wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
641 static int ctrl_iface_get_capability_tdls(
642 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
646 ret = os_snprintf(buf, buflen, "%s\n",
647 wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT ?
649 WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP ?
650 "EXTERNAL" : "INTERNAL") : "UNSUPPORTED");
651 if (os_snprintf_error(buflen, ret))
657 static int wpa_supplicant_ctrl_iface_tdls_chan_switch(
658 struct wpa_supplicant *wpa_s, char *cmd)
661 struct hostapd_freq_params freq_params;
665 if (!wpa_tdls_is_external_setup(wpa_s->wpa)) {
667 "tdls_chanswitch: Only supported with external setup");
671 os_memset(&freq_params, 0, sizeof(freq_params));
673 pos = os_strchr(cmd, ' ');
678 oper_class = strtol(pos, &end, 10);
681 "tdls_chanswitch: Invalid op class provided");
686 freq_params.freq = atoi(pos);
687 if (freq_params.freq == 0) {
688 wpa_printf(MSG_INFO, "tdls_chanswitch: Invalid freq provided");
692 #define SET_FREQ_SETTING(str) \
694 const char *pos2 = os_strstr(pos, " " #str "="); \
696 pos2 += sizeof(" " #str "=") - 1; \
697 freq_params.str = atoi(pos2); \
701 SET_FREQ_SETTING(center_freq1);
702 SET_FREQ_SETTING(center_freq2);
703 SET_FREQ_SETTING(bandwidth);
704 SET_FREQ_SETTING(sec_channel_offset);
705 #undef SET_FREQ_SETTING
707 freq_params.ht_enabled = !!os_strstr(pos, " ht");
708 freq_params.vht_enabled = !!os_strstr(pos, " vht");
710 if (hwaddr_aton(cmd, peer)) {
711 wpa_printf(MSG_DEBUG,
712 "CTRL_IFACE TDLS_CHAN_SWITCH: Invalid address '%s'",
717 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_CHAN_SWITCH " MACSTR
718 " OP CLASS %d FREQ %d CENTER1 %d CENTER2 %d BW %d SEC_OFFSET %d%s%s",
719 MAC2STR(peer), oper_class, freq_params.freq,
720 freq_params.center_freq1, freq_params.center_freq2,
721 freq_params.bandwidth, freq_params.sec_channel_offset,
722 freq_params.ht_enabled ? " HT" : "",
723 freq_params.vht_enabled ? " VHT" : "");
725 return wpa_tdls_enable_chan_switch(wpa_s->wpa, peer, oper_class,
730 static int wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(
731 struct wpa_supplicant *wpa_s, char *cmd)
735 if (!wpa_tdls_is_external_setup(wpa_s->wpa)) {
737 "tdls_chanswitch: Only supported with external setup");
741 if (hwaddr_aton(cmd, peer)) {
742 wpa_printf(MSG_DEBUG,
743 "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH: Invalid address '%s'",
748 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH " MACSTR,
751 return wpa_tdls_disable_chan_switch(wpa_s->wpa, peer);
754 #endif /* CONFIG_TDLS */
757 static int wmm_ac_ctrl_addts(struct wpa_supplicant *wpa_s, char *cmd)
759 char *token, *context = NULL;
760 struct wmm_ac_ts_setup_params params = {
765 while ((token = str_token(cmd, " ", &context))) {
766 if (sscanf(token, "tsid=%i", ¶ms.tsid) == 1 ||
767 sscanf(token, "up=%i", ¶ms.user_priority) == 1 ||
768 sscanf(token, "nominal_msdu_size=%i",
769 ¶ms.nominal_msdu_size) == 1 ||
770 sscanf(token, "mean_data_rate=%i",
771 ¶ms.mean_data_rate) == 1 ||
772 sscanf(token, "min_phy_rate=%i",
773 ¶ms.minimum_phy_rate) == 1 ||
774 sscanf(token, "sba=%i",
775 ¶ms.surplus_bandwidth_allowance) == 1)
778 if (os_strcasecmp(token, "downlink") == 0) {
779 params.direction = WMM_TSPEC_DIRECTION_DOWNLINK;
780 } else if (os_strcasecmp(token, "uplink") == 0) {
781 params.direction = WMM_TSPEC_DIRECTION_UPLINK;
782 } else if (os_strcasecmp(token, "bidi") == 0) {
783 params.direction = WMM_TSPEC_DIRECTION_BI_DIRECTIONAL;
784 } else if (os_strcasecmp(token, "fixed_nominal_msdu") == 0) {
785 params.fixed_nominal_msdu = 1;
787 wpa_printf(MSG_DEBUG,
788 "CTRL: Invalid WMM_AC_ADDTS parameter: '%s'",
795 return wpas_wmm_ac_addts(wpa_s, ¶ms);
799 static int wmm_ac_ctrl_delts(struct wpa_supplicant *wpa_s, char *cmd)
803 return wpas_wmm_ac_delts(wpa_s, tsid);
807 #ifdef CONFIG_IEEE80211R
808 static int wpa_supplicant_ctrl_iface_ft_ds(
809 struct wpa_supplicant *wpa_s, char *addr)
811 u8 target_ap[ETH_ALEN];
815 if (hwaddr_aton(addr, target_ap)) {
816 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid "
817 "address '%s'", addr);
821 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap));
823 bss = wpa_bss_get_bssid(wpa_s, target_ap);
825 mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN);
829 return wpa_ft_start_over_ds(wpa_s->wpa, target_ap, mdie);
831 #endif /* CONFIG_IEEE80211R */
835 static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s,
838 u8 bssid[ETH_ALEN], *_bssid = bssid;
840 u8 p2p_dev_addr[ETH_ALEN];
841 #endif /* CONFIG_P2P */
843 u8 *_p2p_dev_addr = NULL;
844 #endif /* CONFIG_AP */
846 if (cmd == NULL || os_strcmp(cmd, "any") == 0) {
849 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
850 if (hwaddr_aton(cmd + 13, p2p_dev_addr)) {
851 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid "
852 "P2P Device Address '%s'",
856 _p2p_dev_addr = p2p_dev_addr;
857 #endif /* CONFIG_P2P */
858 } else if (hwaddr_aton(cmd, bssid)) {
859 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
866 return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid, _p2p_dev_addr);
867 #endif /* CONFIG_AP */
869 return wpas_wps_start_pbc(wpa_s, _bssid, 0);
873 static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s,
874 char *cmd, char *buf,
877 u8 bssid[ETH_ALEN], *_bssid = bssid;
881 pin = os_strchr(cmd, ' ');
885 if (os_strcmp(cmd, "any") == 0)
887 else if (os_strcmp(cmd, "get") == 0) {
888 ret = wps_generate_pin();
890 } else if (hwaddr_aton(cmd, bssid)) {
891 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
897 if (wpa_s->ap_iface) {
902 pos = os_strchr(pin, ' ');
909 return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin,
910 buf, buflen, timeout);
912 #endif /* CONFIG_AP */
915 ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0,
919 ret = os_snprintf(buf, buflen, "%s", pin);
920 if (os_snprintf_error(buflen, ret))
925 ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0, DEV_PW_DEFAULT);
930 /* Return the generated PIN */
931 ret = os_snprintf(buf, buflen, "%08d", ret);
932 if (os_snprintf_error(buflen, ret))
938 static int wpa_supplicant_ctrl_iface_wps_check_pin(
939 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
946 wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN",
947 (u8 *) cmd, os_strlen(cmd));
948 for (pos = cmd, len = 0; *pos != '\0'; pos++) {
949 if (*pos < '0' || *pos > '9')
953 wpa_printf(MSG_DEBUG, "WPS: Too long PIN");
957 if (len != 4 && len != 8) {
958 wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len);
964 unsigned int pin_val;
966 if (!wps_pin_valid(pin_val)) {
967 wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit");
968 ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n");
969 if (os_snprintf_error(buflen, ret))
975 ret = os_snprintf(buf, buflen, "%s", pin);
976 if (os_snprintf_error(buflen, ret))
983 #ifdef CONFIG_WPS_NFC
985 static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant *wpa_s,
988 u8 bssid[ETH_ALEN], *_bssid = bssid;
990 if (cmd == NULL || cmd[0] == '\0')
992 else if (hwaddr_aton(cmd, bssid))
995 return wpas_wps_start_nfc(wpa_s, NULL, _bssid, NULL, 0, 0, NULL, NULL,
1000 static int wpa_supplicant_ctrl_iface_wps_nfc_config_token(
1001 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1008 pos = os_strchr(cmd, ' ');
1011 if (os_strcmp(cmd, "WPS") == 0)
1013 else if (os_strcmp(cmd, "NDEF") == 0)
1018 buf = wpas_wps_nfc_config_token(wpa_s, ndef, pos);
1022 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1024 reply[res++] = '\n';
1033 static int wpa_supplicant_ctrl_iface_wps_nfc_token(
1034 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1040 if (os_strcmp(cmd, "WPS") == 0)
1042 else if (os_strcmp(cmd, "NDEF") == 0)
1047 buf = wpas_wps_nfc_token(wpa_s, ndef);
1051 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1053 reply[res++] = '\n';
1062 static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
1063 struct wpa_supplicant *wpa_s, char *pos)
1069 int forced_freq = 0;
1071 freq = strstr(pos, " freq=");
1075 forced_freq = atoi(freq);
1078 len = os_strlen(pos);
1083 buf = wpabuf_alloc(len);
1086 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
1091 ret = wpas_wps_nfc_tag_read(wpa_s, buf, forced_freq);
1098 static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant *wpa_s,
1099 char *reply, size_t max_len,
1105 buf = wpas_wps_nfc_handover_req(wpa_s, ndef);
1109 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1111 reply[res++] = '\n';
1121 static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant *wpa_s,
1122 char *reply, size_t max_len,
1128 buf = wpas_p2p_nfc_handover_req(wpa_s, ndef);
1130 wpa_printf(MSG_DEBUG, "P2P: Could not generate NFC handover request");
1134 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1136 reply[res++] = '\n';
1143 #endif /* CONFIG_P2P */
1146 static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant *wpa_s,
1147 char *cmd, char *reply,
1153 pos = os_strchr(cmd, ' ');
1158 if (os_strcmp(cmd, "WPS") == 0)
1160 else if (os_strcmp(cmd, "NDEF") == 0)
1165 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
1168 return wpas_ctrl_nfc_get_handover_req_wps(
1169 wpa_s, reply, max_len, ndef);
1173 if (os_strcmp(pos, "P2P-CR") == 0) {
1174 return wpas_ctrl_nfc_get_handover_req_p2p(
1175 wpa_s, reply, max_len, ndef);
1177 #endif /* CONFIG_P2P */
1183 static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant *wpa_s,
1184 char *reply, size_t max_len,
1185 int ndef, int cr, char *uuid)
1190 buf = wpas_wps_nfc_handover_sel(wpa_s, ndef, cr, uuid);
1194 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1196 reply[res++] = '\n';
1206 static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant *wpa_s,
1207 char *reply, size_t max_len,
1213 buf = wpas_p2p_nfc_handover_sel(wpa_s, ndef, tag);
1217 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1219 reply[res++] = '\n';
1226 #endif /* CONFIG_P2P */
1229 static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant *wpa_s,
1230 char *cmd, char *reply,
1236 pos = os_strchr(cmd, ' ');
1241 if (os_strcmp(cmd, "WPS") == 0)
1243 else if (os_strcmp(cmd, "NDEF") == 0)
1248 pos2 = os_strchr(pos, ' ');
1251 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
1254 return wpas_ctrl_nfc_get_handover_sel_wps(
1255 wpa_s, reply, max_len, ndef,
1256 os_strcmp(pos, "WPS-CR") == 0, pos2);
1260 if (os_strcmp(pos, "P2P-CR") == 0) {
1261 return wpas_ctrl_nfc_get_handover_sel_p2p(
1262 wpa_s, reply, max_len, ndef, 0);
1265 if (os_strcmp(pos, "P2P-CR-TAG") == 0) {
1266 return wpas_ctrl_nfc_get_handover_sel_p2p(
1267 wpa_s, reply, max_len, ndef, 1);
1269 #endif /* CONFIG_P2P */
1275 static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant *wpa_s,
1279 struct wpabuf *req, *sel;
1281 char *pos, *role, *type, *pos2;
1284 int forced_freq = 0;
1286 freq = strstr(cmd, " freq=");
1290 forced_freq = atoi(freq);
1292 #endif /* CONFIG_P2P */
1295 pos = os_strchr(role, ' ');
1297 wpa_printf(MSG_DEBUG, "NFC: Missing type in handover report");
1303 pos = os_strchr(type, ' ');
1305 wpa_printf(MSG_DEBUG, "NFC: Missing request message in handover report");
1310 pos2 = os_strchr(pos, ' ');
1312 wpa_printf(MSG_DEBUG, "NFC: Missing select message in handover report");
1317 len = os_strlen(pos);
1319 wpa_printf(MSG_DEBUG, "NFC: Invalid request message length in handover report");
1324 req = wpabuf_alloc(len);
1326 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for request message");
1329 if (hexstr2bin(pos, wpabuf_put(req, len), len) < 0) {
1330 wpa_printf(MSG_DEBUG, "NFC: Invalid request message hexdump in handover report");
1335 len = os_strlen(pos2);
1337 wpa_printf(MSG_DEBUG, "NFC: Invalid select message length in handover report");
1343 sel = wpabuf_alloc(len);
1345 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for select message");
1349 if (hexstr2bin(pos2, wpabuf_put(sel, len), len) < 0) {
1350 wpa_printf(MSG_DEBUG, "NFC: Invalid select message hexdump in handover report");
1356 wpa_printf(MSG_DEBUG, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d",
1357 role, type, (int) wpabuf_len(req), (int) wpabuf_len(sel));
1359 if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "WPS") == 0) {
1360 ret = wpas_wps_nfc_report_handover(wpa_s, req, sel);
1362 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "WPS") == 0)
1364 ret = wpas_ap_wps_nfc_report_handover(wpa_s, req, sel);
1366 ret = wpas_er_wps_nfc_report_handover(wpa_s, req, sel);
1367 #endif /* CONFIG_AP */
1369 } else if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "P2P") == 0)
1371 ret = wpas_p2p_nfc_report_handover(wpa_s, 1, req, sel, 0);
1372 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "P2P") == 0)
1374 ret = wpas_p2p_nfc_report_handover(wpa_s, 0, req, sel,
1376 #endif /* CONFIG_P2P */
1378 wpa_printf(MSG_DEBUG, "NFC: Unsupported connection handover "
1379 "reported: role=%s type=%s", role, type);
1386 wpa_printf(MSG_DEBUG, "NFC: Failed to process reported handover messages");
1391 #endif /* CONFIG_WPS_NFC */
1394 static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s,
1403 struct wps_new_ap_settings ap;
1405 pin = os_strchr(cmd, ' ');
1410 if (hwaddr_aton(cmd, bssid)) {
1411 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
1416 new_ssid = os_strchr(pin, ' ');
1417 if (new_ssid == NULL)
1418 return wpas_wps_start_reg(wpa_s, bssid, pin, NULL);
1421 new_auth = os_strchr(new_ssid, ' ');
1422 if (new_auth == NULL)
1426 new_encr = os_strchr(new_auth, ' ');
1427 if (new_encr == NULL)
1431 new_key = os_strchr(new_encr, ' ');
1432 if (new_key == NULL)
1436 os_memset(&ap, 0, sizeof(ap));
1437 ap.ssid_hex = new_ssid;
1440 ap.key_hex = new_key;
1441 return wpas_wps_start_reg(wpa_s, bssid, pin, &ap);
1446 static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant *wpa_s,
1447 char *cmd, char *buf,
1452 const char *pin_txt;
1454 if (!wpa_s->ap_iface)
1457 pos = os_strchr(cmd, ' ');
1461 if (os_strcmp(cmd, "disable") == 0) {
1462 wpas_wps_ap_pin_disable(wpa_s);
1463 return os_snprintf(buf, buflen, "OK\n");
1466 if (os_strcmp(cmd, "random") == 0) {
1468 timeout = atoi(pos);
1469 pin_txt = wpas_wps_ap_pin_random(wpa_s, timeout);
1470 if (pin_txt == NULL)
1472 return os_snprintf(buf, buflen, "%s", pin_txt);
1475 if (os_strcmp(cmd, "get") == 0) {
1476 pin_txt = wpas_wps_ap_pin_get(wpa_s);
1477 if (pin_txt == NULL)
1479 return os_snprintf(buf, buflen, "%s", pin_txt);
1482 if (os_strcmp(cmd, "set") == 0) {
1487 pos = os_strchr(pos, ' ');
1490 timeout = atoi(pos);
1492 if (os_strlen(pin) > buflen)
1494 if (wpas_wps_ap_pin_set(wpa_s, pin, timeout) < 0)
1496 return os_snprintf(buf, buflen, "%s", pin);
1501 #endif /* CONFIG_AP */
1504 #ifdef CONFIG_WPS_ER
1505 static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant *wpa_s,
1508 char *uuid = cmd, *pin, *pos;
1509 u8 addr_buf[ETH_ALEN], *addr = NULL;
1510 pin = os_strchr(uuid, ' ');
1514 pos = os_strchr(pin, ' ');
1517 if (hwaddr_aton(pos, addr_buf) == 0)
1520 return wpas_wps_er_add_pin(wpa_s, addr, uuid, pin);
1524 static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant *wpa_s,
1527 char *uuid = cmd, *pin;
1528 pin = os_strchr(uuid, ' ');
1532 return wpas_wps_er_learn(wpa_s, uuid, pin);
1536 static int wpa_supplicant_ctrl_iface_wps_er_set_config(
1537 struct wpa_supplicant *wpa_s, char *cmd)
1539 char *uuid = cmd, *id;
1540 id = os_strchr(uuid, ' ');
1544 return wpas_wps_er_set_config(wpa_s, uuid, atoi(id));
1548 static int wpa_supplicant_ctrl_iface_wps_er_config(
1549 struct wpa_supplicant *wpa_s, char *cmd)
1556 struct wps_new_ap_settings ap;
1558 pin = os_strchr(cmd, ' ');
1563 new_ssid = os_strchr(pin, ' ');
1564 if (new_ssid == NULL)
1568 new_auth = os_strchr(new_ssid, ' ');
1569 if (new_auth == NULL)
1573 new_encr = os_strchr(new_auth, ' ');
1574 if (new_encr == NULL)
1578 new_key = os_strchr(new_encr, ' ');
1579 if (new_key == NULL)
1583 os_memset(&ap, 0, sizeof(ap));
1584 ap.ssid_hex = new_ssid;
1587 ap.key_hex = new_key;
1588 return wpas_wps_er_config(wpa_s, cmd, pin, &ap);
1592 #ifdef CONFIG_WPS_NFC
1593 static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
1594 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1601 uuid = os_strchr(cmd, ' ');
1606 if (os_strcmp(cmd, "WPS") == 0)
1608 else if (os_strcmp(cmd, "NDEF") == 0)
1613 buf = wpas_wps_er_nfc_config_token(wpa_s, ndef, uuid);
1617 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1619 reply[res++] = '\n';
1626 #endif /* CONFIG_WPS_NFC */
1627 #endif /* CONFIG_WPS_ER */
1629 #endif /* CONFIG_WPS */
1632 #ifdef CONFIG_IBSS_RSN
1633 static int wpa_supplicant_ctrl_iface_ibss_rsn(
1634 struct wpa_supplicant *wpa_s, char *addr)
1638 if (hwaddr_aton(addr, peer)) {
1639 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN: invalid "
1640 "address '%s'", addr);
1644 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN " MACSTR,
1647 return ibss_rsn_start(wpa_s->ibss_rsn, peer);
1649 #endif /* CONFIG_IBSS_RSN */
1652 static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s,
1655 #ifdef IEEE8021X_EAPOL
1658 struct wpa_ssid *ssid;
1660 pos = os_strchr(rsp, '-');
1665 pos = os_strchr(pos, ':');
1670 wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id);
1671 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
1672 (u8 *) pos, os_strlen(pos));
1674 ssid = wpa_config_get_network(wpa_s->conf, id);
1676 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
1681 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s, ssid, rsp,
1683 #else /* IEEE8021X_EAPOL */
1684 wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included");
1686 #endif /* IEEE8021X_EAPOL */
1690 static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
1692 char *buf, size_t buflen)
1694 char *pos, *end, tmp[30];
1695 int res, verbose, wps, ret;
1698 #endif /* CONFIG_HS20 */
1700 if (os_strcmp(params, "-DRIVER") == 0)
1701 return wpa_drv_status(wpa_s, buf, buflen);
1702 verbose = os_strcmp(params, "-VERBOSE") == 0;
1703 wps = os_strcmp(params, "-WPS") == 0;
1706 if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
1707 struct wpa_ssid *ssid = wpa_s->current_ssid;
1708 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
1709 MAC2STR(wpa_s->bssid));
1710 if (os_snprintf_error(end - pos, ret))
1713 ret = os_snprintf(pos, end - pos, "freq=%u\n",
1715 if (os_snprintf_error(end - pos, ret))
1719 u8 *_ssid = ssid->ssid;
1720 size_t ssid_len = ssid->ssid_len;
1721 u8 ssid_buf[MAX_SSID_LEN];
1722 if (ssid_len == 0) {
1723 int _res = wpa_drv_get_ssid(wpa_s, ssid_buf);
1730 ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n",
1731 wpa_ssid_txt(_ssid, ssid_len),
1733 if (os_snprintf_error(end - pos, ret))
1737 if (wps && ssid->passphrase &&
1738 wpa_key_mgmt_wpa_psk(ssid->key_mgmt) &&
1739 (ssid->mode == WPAS_MODE_AP ||
1740 ssid->mode == WPAS_MODE_P2P_GO)) {
1741 ret = os_snprintf(pos, end - pos,
1744 if (os_snprintf_error(end - pos, ret))
1749 ret = os_snprintf(pos, end - pos,
1752 if (os_snprintf_error(end - pos, ret))
1757 switch (ssid->mode) {
1758 case WPAS_MODE_INFRA:
1759 ret = os_snprintf(pos, end - pos,
1762 case WPAS_MODE_IBSS:
1763 ret = os_snprintf(pos, end - pos,
1767 ret = os_snprintf(pos, end - pos,
1770 case WPAS_MODE_P2P_GO:
1771 ret = os_snprintf(pos, end - pos,
1774 case WPAS_MODE_P2P_GROUP_FORMATION:
1775 ret = os_snprintf(pos, end - pos,
1776 "mode=P2P GO - group "
1783 if (os_snprintf_error(end - pos, ret))
1789 if (wpa_s->ap_iface) {
1790 pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos,
1794 #endif /* CONFIG_AP */
1795 pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose);
1798 if (wpa_s->wpa_state >= WPA_ASSOCIATED &&
1801 #endif /* CONFIG_AP */
1802 wpa_s->sme.sae.state == SAE_ACCEPTED) {
1803 ret = os_snprintf(pos, end - pos, "sae_group=%d\n",
1804 wpa_s->sme.sae.group);
1805 if (os_snprintf_error(end - pos, ret))
1809 #endif /* CONFIG_SAE */
1810 ret = os_snprintf(pos, end - pos, "wpa_state=%s\n",
1811 wpa_supplicant_state_txt(wpa_s->wpa_state));
1812 if (os_snprintf_error(end - pos, ret))
1817 l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) {
1818 ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp);
1819 if (os_snprintf_error(end - pos, ret))
1825 if (wpa_s->global->p2p) {
1826 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
1827 "\n", MAC2STR(wpa_s->global->p2p_dev_addr));
1828 if (os_snprintf_error(end - pos, ret))
1832 #endif /* CONFIG_P2P */
1834 ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n",
1835 MAC2STR(wpa_s->own_addr));
1836 if (os_snprintf_error(end - pos, ret))
1841 if (wpa_s->current_bss &&
1842 (hs20 = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1843 HS20_IE_VENDOR_TYPE)) &&
1844 wpa_s->wpa_proto == WPA_PROTO_RSN &&
1845 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1848 u8 rel_num = (hs20[6] & 0xf0) >> 4;
1849 release = rel_num + 1;
1851 ret = os_snprintf(pos, end - pos, "hs20=%d\n", release);
1852 if (os_snprintf_error(end - pos, ret))
1857 if (wpa_s->current_ssid) {
1858 struct wpa_cred *cred;
1861 for (cred = wpa_s->conf->cred; cred; cred = cred->next) {
1864 if (wpa_s->current_ssid->parent_cred != cred)
1867 if (cred->provisioning_sp) {
1868 ret = os_snprintf(pos, end - pos,
1869 "provisioning_sp=%s\n",
1870 cred->provisioning_sp);
1871 if (os_snprintf_error(end - pos, ret))
1880 if (wpa_s->current_bss && wpa_s->current_bss->anqp) {
1881 struct wpabuf *names =
1882 wpa_s->current_bss->anqp->domain_name;
1883 for (i = 0; names && i < cred->num_domain; i++)
1885 if (domain_name_list_contains(
1886 names, cred->domain[i], 1))
1889 if (i == cred->num_domain)
1890 i = 0; /* show first entry by default */
1892 ret = os_snprintf(pos, end - pos, "home_sp=%s\n",
1894 if (os_snprintf_error(end - pos, ret))
1899 if (wpa_s->current_bss == NULL ||
1900 wpa_s->current_bss->anqp == NULL)
1903 res = interworking_home_sp_cred(
1905 wpa_s->current_bss->anqp->domain_name);
1913 ret = os_snprintf(pos, end - pos, "sp_type=%s\n", type);
1914 if (os_snprintf_error(end - pos, ret))
1921 #endif /* CONFIG_HS20 */
1923 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
1924 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
1925 res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos,
1931 res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose);
1938 uuid_bin2str(wpa_s->wps->uuid, uuid_str, sizeof(uuid_str));
1939 ret = os_snprintf(pos, end - pos, "uuid=%s\n", uuid_str);
1940 if (os_snprintf_error(end - pos, ret))
1944 #endif /* CONFIG_WPS */
1948 * Allow using the STATUS command with default behavior, say for debug,
1949 * i.e., don't generate a "fake" CONNECTION and SUPPLICANT_STATE_CHANGE
1950 * events with STATUS-NO_EVENTS.
1952 if (os_strcmp(params, "-NO_EVENTS")) {
1953 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_STATE_CHANGE
1954 "id=%d state=%d BSSID=" MACSTR " SSID=%s",
1955 wpa_s->current_ssid ? wpa_s->current_ssid->id : -1,
1957 MAC2STR(wpa_s->bssid),
1958 wpa_s->current_ssid && wpa_s->current_ssid->ssid ?
1959 wpa_ssid_txt(wpa_s->current_ssid->ssid,
1960 wpa_s->current_ssid->ssid_len) : "");
1961 if (wpa_s->wpa_state == WPA_COMPLETED) {
1962 struct wpa_ssid *ssid = wpa_s->current_ssid;
1963 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_CONNECTED
1964 "- connection to " MACSTR
1965 " completed %s [id=%d id_str=%s]",
1966 MAC2STR(wpa_s->bssid), "(auth)",
1967 ssid ? ssid->id : -1,
1968 ssid && ssid->id_str ? ssid->id_str : "");
1971 #endif /* ANDROID */
1977 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s,
1982 struct wpa_ssid *ssid;
1985 /* cmd: "<network id> <BSSID>" */
1986 pos = os_strchr(cmd, ' ');
1991 wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos);
1992 if (hwaddr_aton(pos, bssid)) {
1993 wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos);
1997 ssid = wpa_config_get_network(wpa_s->conf, id);
1999 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
2004 os_memcpy(ssid->bssid, bssid, ETH_ALEN);
2005 ssid->bssid_set = !is_zero_ether_addr(bssid);
2011 static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant *wpa_s,
2012 char *cmd, char *buf,
2016 struct wpa_blacklist *e;
2020 /* cmd: "BLACKLIST [<BSSID>]" */
2024 e = wpa_s->blacklist;
2026 ret = os_snprintf(pos, end - pos, MACSTR "\n",
2028 if (os_snprintf_error(end - pos, ret))
2037 if (os_strncmp(cmd, "clear", 5) == 0) {
2038 wpa_blacklist_clear(wpa_s);
2039 os_memcpy(buf, "OK\n", 3);
2043 wpa_printf(MSG_DEBUG, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd);
2044 if (hwaddr_aton(cmd, bssid)) {
2045 wpa_printf(MSG_DEBUG, "CTRL_IFACE: invalid BSSID '%s'", cmd);
2050 * Add the BSSID twice, so its count will be 2, causing it to be
2051 * skipped when processing scan results.
2053 ret = wpa_blacklist_add(wpa_s, bssid);
2056 ret = wpa_blacklist_add(wpa_s, bssid);
2059 os_memcpy(buf, "OK\n", 3);
2064 static const char * debug_level_str(int level)
2085 static int str_to_debug_level(const char *s)
2087 if (os_strcasecmp(s, "EXCESSIVE") == 0)
2088 return MSG_EXCESSIVE;
2089 if (os_strcasecmp(s, "MSGDUMP") == 0)
2091 if (os_strcasecmp(s, "DEBUG") == 0)
2093 if (os_strcasecmp(s, "INFO") == 0)
2095 if (os_strcasecmp(s, "WARNING") == 0)
2097 if (os_strcasecmp(s, "ERROR") == 0)
2103 static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant *wpa_s,
2104 char *cmd, char *buf,
2107 char *pos, *end, *stamp;
2110 /* cmd: "LOG_LEVEL [<level>]" */
2114 ret = os_snprintf(pos, end - pos, "Current level: %s\n"
2116 debug_level_str(wpa_debug_level),
2117 wpa_debug_timestamp);
2118 if (os_snprintf_error(end - pos, ret))
2127 stamp = os_strchr(cmd, ' ');
2130 while (*stamp == ' ') {
2135 if (cmd && os_strlen(cmd)) {
2136 int level = str_to_debug_level(cmd);
2139 wpa_debug_level = level;
2142 if (stamp && os_strlen(stamp))
2143 wpa_debug_timestamp = atoi(stamp);
2145 os_memcpy(buf, "OK\n", 3);
2150 static int wpa_supplicant_ctrl_iface_list_networks(
2151 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
2153 char *pos, *end, *prev;
2154 struct wpa_ssid *ssid;
2159 ret = os_snprintf(pos, end - pos,
2160 "network id / ssid / bssid / flags\n");
2161 if (os_snprintf_error(end - pos, ret))
2165 ssid = wpa_s->conf->ssid;
2167 /* skip over ssids until we find next one */
2168 if (cmd != NULL && os_strncmp(cmd, "LAST_ID=", 8) == 0) {
2169 int last_id = atoi(cmd + 8);
2170 if (last_id != -1) {
2171 while (ssid != NULL && ssid->id <= last_id) {
2179 ret = os_snprintf(pos, end - pos, "%d\t%s",
2181 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
2182 if (os_snprintf_error(end - pos, ret))
2185 if (ssid->bssid_set) {
2186 ret = os_snprintf(pos, end - pos, "\t" MACSTR,
2187 MAC2STR(ssid->bssid));
2189 ret = os_snprintf(pos, end - pos, "\tany");
2191 if (os_snprintf_error(end - pos, ret))
2194 ret = os_snprintf(pos, end - pos, "\t%s%s%s%s",
2195 ssid == wpa_s->current_ssid ?
2197 ssid->disabled ? "[DISABLED]" : "",
2198 ssid->disabled_until.sec ?
2199 "[TEMP-DISABLED]" : "",
2200 ssid->disabled == 2 ? "[P2P-PERSISTENT]" :
2202 if (os_snprintf_error(end - pos, ret))
2205 ret = os_snprintf(pos, end - pos, "\n");
2206 if (os_snprintf_error(end - pos, ret))
2217 static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher)
2220 ret = os_snprintf(pos, end - pos, "-");
2221 if (os_snprintf_error(end - pos, ret))
2224 ret = wpa_write_ciphers(pos, end, cipher, "+");
2232 static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
2233 const u8 *ie, size_t ie_len)
2235 struct wpa_ie_data data;
2239 ret = os_snprintf(pos, end - pos, "[%s-", proto);
2240 if (os_snprintf_error(end - pos, ret))
2244 if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) {
2245 ret = os_snprintf(pos, end - pos, "?]");
2246 if (os_snprintf_error(end - pos, ret))
2253 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
2254 ret = os_snprintf(pos, end - pos, "%sEAP",
2255 pos == start ? "" : "+");
2256 if (os_snprintf_error(end - pos, ret))
2260 if (data.key_mgmt & WPA_KEY_MGMT_PSK) {
2261 ret = os_snprintf(pos, end - pos, "%sPSK",
2262 pos == start ? "" : "+");
2263 if (os_snprintf_error(end - pos, ret))
2267 if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
2268 ret = os_snprintf(pos, end - pos, "%sNone",
2269 pos == start ? "" : "+");
2270 if (os_snprintf_error(end - pos, ret))
2274 if (data.key_mgmt & WPA_KEY_MGMT_SAE) {
2275 ret = os_snprintf(pos, end - pos, "%sSAE",
2276 pos == start ? "" : "+");
2277 if (os_snprintf_error(end - pos, ret))
2281 #ifdef CONFIG_IEEE80211R
2282 if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
2283 ret = os_snprintf(pos, end - pos, "%sFT/EAP",
2284 pos == start ? "" : "+");
2285 if (os_snprintf_error(end - pos, ret))
2289 if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) {
2290 ret = os_snprintf(pos, end - pos, "%sFT/PSK",
2291 pos == start ? "" : "+");
2292 if (os_snprintf_error(end - pos, ret))
2296 if (data.key_mgmt & WPA_KEY_MGMT_FT_SAE) {
2297 ret = os_snprintf(pos, end - pos, "%sFT/SAE",
2298 pos == start ? "" : "+");
2299 if (os_snprintf_error(end - pos, ret))
2303 #endif /* CONFIG_IEEE80211R */
2304 #ifdef CONFIG_IEEE80211W
2305 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
2306 ret = os_snprintf(pos, end - pos, "%sEAP-SHA256",
2307 pos == start ? "" : "+");
2308 if (os_snprintf_error(end - pos, ret))
2312 if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
2313 ret = os_snprintf(pos, end - pos, "%sPSK-SHA256",
2314 pos == start ? "" : "+");
2315 if (os_snprintf_error(end - pos, ret))
2319 #endif /* CONFIG_IEEE80211W */
2321 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B) {
2322 ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B",
2323 pos == start ? "" : "+");
2324 if (os_snprintf_error(end - pos, ret))
2329 pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher);
2331 if (data.capabilities & WPA_CAPABILITY_PREAUTH) {
2332 ret = os_snprintf(pos, end - pos, "-preauth");
2333 if (os_snprintf_error(end - pos, ret))
2338 ret = os_snprintf(pos, end - pos, "]");
2339 if (os_snprintf_error(end - pos, ret))
2348 static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s,
2349 char *pos, char *end,
2350 struct wpabuf *wps_ie)
2357 if (wps_is_selected_pbc_registrar(wps_ie))
2359 else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0))
2361 else if (wps_is_selected_pin_registrar(wps_ie))
2366 ret = os_snprintf(pos, end - pos, "%s", txt);
2367 if (!os_snprintf_error(end - pos, ret))
2369 wpabuf_free(wps_ie);
2372 #endif /* CONFIG_WPS */
2375 static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s,
2376 char *pos, char *end,
2377 const struct wpa_bss *bss)
2380 struct wpabuf *wps_ie;
2381 wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
2382 return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie);
2383 #else /* CONFIG_WPS */
2385 #endif /* CONFIG_WPS */
2389 /* Format one result on one text line into a buffer. */
2390 static int wpa_supplicant_ctrl_iface_scan_result(
2391 struct wpa_supplicant *wpa_s,
2392 const struct wpa_bss *bss, char *buf, size_t buflen)
2396 const u8 *ie, *ie2, *p2p, *mesh;
2398 mesh = wpa_bss_get_ie(bss, WLAN_EID_MESH_ID);
2399 p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
2401 p2p = wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE);
2402 if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN &&
2403 os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) ==
2405 return 0; /* Do not show P2P listen discovery results here */
2410 ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t",
2411 MAC2STR(bss->bssid), bss->freq, bss->level);
2412 if (os_snprintf_error(end - pos, ret))
2415 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
2417 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]);
2418 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
2420 pos = wpa_supplicant_ie_txt(pos, end, mesh ? "RSN" : "WPA2",
2423 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
2424 if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
2425 ret = os_snprintf(pos, end - pos, "[WEP]");
2426 if (os_snprintf_error(end - pos, ret))
2431 ret = os_snprintf(pos, end - pos, "[MESH]");
2432 if (os_snprintf_error(end - pos, ret))
2436 if (bss_is_dmg(bss)) {
2438 ret = os_snprintf(pos, end - pos, "[DMG]");
2439 if (os_snprintf_error(end - pos, ret))
2442 switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
2443 case IEEE80211_CAP_DMG_IBSS:
2446 case IEEE80211_CAP_DMG_AP:
2449 case IEEE80211_CAP_DMG_PBSS:
2456 ret = os_snprintf(pos, end - pos, "%s", s);
2457 if (os_snprintf_error(end - pos, ret))
2461 if (bss->caps & IEEE80211_CAP_IBSS) {
2462 ret = os_snprintf(pos, end - pos, "[IBSS]");
2463 if (os_snprintf_error(end - pos, ret))
2467 if (bss->caps & IEEE80211_CAP_ESS) {
2468 ret = os_snprintf(pos, end - pos, "[ESS]");
2469 if (os_snprintf_error(end - pos, ret))
2475 ret = os_snprintf(pos, end - pos, "[P2P]");
2476 if (os_snprintf_error(end - pos, ret))
2481 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE) && ie2) {
2482 ret = os_snprintf(pos, end - pos, "[HS20]");
2483 if (os_snprintf_error(end - pos, ret))
2487 #endif /* CONFIG_HS20 */
2489 ret = os_snprintf(pos, end - pos, "\t%s",
2490 wpa_ssid_txt(bss->ssid, bss->ssid_len));
2491 if (os_snprintf_error(end - pos, ret))
2495 ret = os_snprintf(pos, end - pos, "\n");
2496 if (os_snprintf_error(end - pos, ret))
2504 static int wpa_supplicant_ctrl_iface_scan_results(
2505 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
2508 struct wpa_bss *bss;
2513 ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / "
2515 if (os_snprintf_error(end - pos, ret))
2519 dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
2520 ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos,
2522 if (ret < 0 || ret >= end - pos)
2533 static int wpa_supplicant_ctrl_iface_mesh_interface_add(
2534 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
2536 char *pos, ifname[IFNAMSIZ + 1];
2540 pos = os_strstr(cmd, "ifname=");
2543 os_strlcpy(ifname, pos, sizeof(ifname));
2546 if (wpas_mesh_add_interface(wpa_s, ifname, sizeof(ifname)) < 0)
2549 os_strlcpy(reply, ifname, max_len);
2550 return os_strlen(ifname);
2554 static int wpa_supplicant_ctrl_iface_mesh_group_add(
2555 struct wpa_supplicant *wpa_s, char *cmd)
2558 struct wpa_ssid *ssid;
2561 wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_ADD id=%d", id);
2563 ssid = wpa_config_get_network(wpa_s->conf, id);
2565 wpa_printf(MSG_DEBUG,
2566 "CTRL_IFACE: Could not find network id=%d", id);
2569 if (ssid->mode != WPAS_MODE_MESH) {
2570 wpa_printf(MSG_DEBUG,
2571 "CTRL_IFACE: Cannot use MESH_GROUP_ADD on a non mesh network");
2574 if (ssid->key_mgmt != WPA_KEY_MGMT_NONE &&
2575 ssid->key_mgmt != WPA_KEY_MGMT_SAE) {
2576 wpa_printf(MSG_ERROR,
2577 "CTRL_IFACE: key_mgmt for mesh network should be open or SAE");
2582 * TODO: If necessary write our own group_add function,
2583 * for now we can reuse select_network
2585 wpa_supplicant_select_network(wpa_s, ssid);
2591 static int wpa_supplicant_ctrl_iface_mesh_group_remove(
2592 struct wpa_supplicant *wpa_s, char *cmd)
2594 struct wpa_supplicant *orig;
2595 struct wpa_global *global;
2598 wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s", cmd);
2600 global = wpa_s->global;
2603 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
2604 if (os_strcmp(wpa_s->ifname, cmd) == 0) {
2610 wpa_printf(MSG_ERROR,
2611 "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s not found",
2615 if (wpa_s->mesh_if_created && wpa_s == orig) {
2616 wpa_printf(MSG_ERROR,
2617 "CTRL_IFACE: MESH_GROUP_REMOVE can't remove itself");
2621 wpa_s->reassociate = 0;
2622 wpa_s->disconnected = 1;
2623 wpa_supplicant_cancel_sched_scan(wpa_s);
2624 wpa_supplicant_cancel_scan(wpa_s);
2627 * TODO: If necessary write our own group_remove function,
2628 * for now we can reuse deauthenticate
2630 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2632 if (wpa_s->mesh_if_created)
2633 wpa_supplicant_remove_iface(global, wpa_s, 0);
2638 #endif /* CONFIG_MESH */
2641 static int wpa_supplicant_ctrl_iface_select_network(
2642 struct wpa_supplicant *wpa_s, char *cmd)
2645 struct wpa_ssid *ssid;
2648 /* cmd: "<network id>" or "any" */
2649 if (os_strncmp(cmd, "any", 3) == 0) {
2650 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any");
2654 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id);
2656 ssid = wpa_config_get_network(wpa_s->conf, id);
2658 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2659 "network id=%d", id);
2662 if (ssid->disabled == 2) {
2663 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2664 "SELECT_NETWORK with persistent P2P group");
2669 pos = os_strstr(cmd, " freq=");
2671 int *freqs = freq_range_to_channel_list(wpa_s, pos + 6);
2673 wpa_s->scan_req = MANUAL_SCAN_REQ;
2674 os_free(wpa_s->manual_scan_freqs);
2675 wpa_s->manual_scan_freqs = freqs;
2679 wpa_supplicant_select_network(wpa_s, ssid);
2685 static int wpa_supplicant_ctrl_iface_enable_network(
2686 struct wpa_supplicant *wpa_s, char *cmd)
2689 struct wpa_ssid *ssid;
2691 /* cmd: "<network id>" or "all" */
2692 if (os_strcmp(cmd, "all") == 0) {
2693 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all");
2697 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id);
2699 ssid = wpa_config_get_network(wpa_s->conf, id);
2701 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2702 "network id=%d", id);
2705 if (ssid->disabled == 2) {
2706 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2707 "ENABLE_NETWORK with persistent P2P group");
2711 if (os_strstr(cmd, " no-connect")) {
2716 wpa_supplicant_enable_network(wpa_s, ssid);
2722 static int wpa_supplicant_ctrl_iface_disable_network(
2723 struct wpa_supplicant *wpa_s, char *cmd)
2726 struct wpa_ssid *ssid;
2728 /* cmd: "<network id>" or "all" */
2729 if (os_strcmp(cmd, "all") == 0) {
2730 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all");
2734 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id);
2736 ssid = wpa_config_get_network(wpa_s->conf, id);
2738 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2739 "network id=%d", id);
2742 if (ssid->disabled == 2) {
2743 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2744 "DISABLE_NETWORK with persistent P2P "
2749 wpa_supplicant_disable_network(wpa_s, ssid);
2755 static int wpa_supplicant_ctrl_iface_add_network(
2756 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
2758 struct wpa_ssid *ssid;
2761 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK");
2763 ssid = wpa_config_add_network(wpa_s->conf);
2767 wpas_notify_network_added(wpa_s, ssid);
2770 wpa_config_set_network_defaults(ssid);
2772 ret = os_snprintf(buf, buflen, "%d\n", ssid->id);
2773 if (os_snprintf_error(buflen, ret))
2779 static int wpa_supplicant_ctrl_iface_remove_network(
2780 struct wpa_supplicant *wpa_s, char *cmd)
2783 struct wpa_ssid *ssid;
2786 /* cmd: "<network id>" or "all" */
2787 if (os_strcmp(cmd, "all") == 0) {
2788 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all");
2789 if (wpa_s->sched_scanning)
2790 wpa_supplicant_cancel_sched_scan(wpa_s);
2792 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2793 if (wpa_s->current_ssid) {
2795 wpa_s->sme.prev_bssid_set = 0;
2796 #endif /* CONFIG_SME */
2797 wpa_sm_set_config(wpa_s->wpa, NULL);
2798 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
2799 wpa_supplicant_deauthenticate(
2800 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2802 ssid = wpa_s->conf->ssid;
2804 struct wpa_ssid *remove_ssid = ssid;
2807 if (wpa_s->last_ssid == remove_ssid)
2808 wpa_s->last_ssid = NULL;
2809 wpas_notify_network_removed(wpa_s, remove_ssid);
2810 wpa_config_remove_network(wpa_s->conf, id);
2816 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id);
2818 ssid = wpa_config_get_network(wpa_s->conf, id);
2820 wpas_notify_network_removed(wpa_s, ssid);
2822 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2827 if (wpa_s->last_ssid == ssid)
2828 wpa_s->last_ssid = NULL;
2830 if (ssid == wpa_s->current_ssid || wpa_s->current_ssid == NULL) {
2832 wpa_s->sme.prev_bssid_set = 0;
2833 #endif /* CONFIG_SME */
2835 * Invalidate the EAP session cache if the current or
2836 * previously used network is removed.
2838 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2841 if (ssid == wpa_s->current_ssid) {
2842 wpa_sm_set_config(wpa_s->wpa, NULL);
2843 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
2845 wpa_supplicant_deauthenticate(wpa_s,
2846 WLAN_REASON_DEAUTH_LEAVING);
2849 was_disabled = ssid->disabled;
2851 if (wpa_config_remove_network(wpa_s->conf, id) < 0) {
2852 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Not able to remove the "
2853 "network id=%d", id);
2857 if (!was_disabled && wpa_s->sched_scanning) {
2858 wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to remove "
2859 "network from filters");
2860 wpa_supplicant_cancel_sched_scan(wpa_s);
2861 wpa_supplicant_req_scan(wpa_s, 0, 0);
2868 static int wpa_supplicant_ctrl_iface_update_network(
2869 struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
2870 char *name, char *value)
2872 if (wpa_config_set(ssid, name, value, 0) < 0) {
2873 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network "
2874 "variable '%s'", name);
2878 if (os_strcmp(name, "bssid") != 0 &&
2879 os_strcmp(name, "priority") != 0)
2880 wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
2882 if (wpa_s->current_ssid == ssid || wpa_s->current_ssid == NULL) {
2884 * Invalidate the EAP session cache if anything in the current
2885 * or previously used configuration changes.
2887 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2890 if ((os_strcmp(name, "psk") == 0 &&
2891 value[0] == '"' && ssid->ssid_len) ||
2892 (os_strcmp(name, "ssid") == 0 && ssid->passphrase))
2893 wpa_config_update_psk(ssid);
2894 else if (os_strcmp(name, "priority") == 0)
2895 wpa_config_update_prio_list(wpa_s->conf);
2896 else if (os_strcmp(name, "no_auto_peer") == 0)
2897 ssid->no_auto_peer = atoi(value);
2903 static int wpa_supplicant_ctrl_iface_set_network(
2904 struct wpa_supplicant *wpa_s, char *cmd)
2906 int id, ret, prev_bssid_set;
2907 struct wpa_ssid *ssid;
2909 u8 prev_bssid[ETH_ALEN];
2911 /* cmd: "<network id> <variable name> <value>" */
2912 name = os_strchr(cmd, ' ');
2917 value = os_strchr(name, ' ');
2923 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
2925 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
2926 (u8 *) value, os_strlen(value));
2928 ssid = wpa_config_get_network(wpa_s->conf, id);
2930 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2935 prev_bssid_set = ssid->bssid_set;
2936 os_memcpy(prev_bssid, ssid->bssid, ETH_ALEN);
2937 ret = wpa_supplicant_ctrl_iface_update_network(wpa_s, ssid, name,
2940 (ssid->bssid_set != prev_bssid_set ||
2941 os_memcmp(ssid->bssid, prev_bssid, ETH_ALEN) != 0))
2942 wpas_notify_network_bssid_set_changed(wpa_s, ssid);
2947 static int wpa_supplicant_ctrl_iface_get_network(
2948 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
2952 struct wpa_ssid *ssid;
2955 /* cmd: "<network id> <variable name>" */
2956 name = os_strchr(cmd, ' ');
2957 if (name == NULL || buflen == 0)
2962 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
2965 ssid = wpa_config_get_network(wpa_s->conf, id);
2967 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2972 value = wpa_config_get_no_key(ssid, name);
2973 if (value == NULL) {
2974 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
2975 "variable '%s'", name);
2979 res = os_strlcpy(buf, value, buflen);
2980 if (res >= buflen) {
2991 static int wpa_supplicant_ctrl_iface_dup_network(
2992 struct wpa_supplicant *wpa_s, char *cmd)
2994 struct wpa_ssid *ssid_s, *ssid_d;
2995 char *name, *id, *value;
2996 int id_s, id_d, ret;
2998 /* cmd: "<src network id> <dst network id> <variable name>" */
2999 id = os_strchr(cmd, ' ');
3004 name = os_strchr(id, ' ');
3011 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DUP_NETWORK id=%d -> %d name='%s'",
3014 ssid_s = wpa_config_get_network(wpa_s->conf, id_s);
3015 if (ssid_s == NULL) {
3016 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3017 "network id=%d", id_s);
3021 ssid_d = wpa_config_get_network(wpa_s->conf, id_d);
3022 if (ssid_d == NULL) {
3023 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3024 "network id=%d", id_d);
3028 value = wpa_config_get(ssid_s, name);
3029 if (value == NULL) {
3030 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
3031 "variable '%s'", name);
3035 ret = wpa_supplicant_ctrl_iface_update_network(wpa_s, ssid_d, name,
3044 static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant *wpa_s,
3045 char *buf, size_t buflen)
3048 struct wpa_cred *cred;
3053 ret = os_snprintf(pos, end - pos,
3054 "cred id / realm / username / domain / imsi\n");
3055 if (os_snprintf_error(end - pos, ret))
3059 cred = wpa_s->conf->cred;
3061 ret = os_snprintf(pos, end - pos, "%d\t%s\t%s\t%s\t%s\n",
3062 cred->id, cred->realm ? cred->realm : "",
3063 cred->username ? cred->username : "",
3064 cred->domain ? cred->domain[0] : "",
3065 cred->imsi ? cred->imsi : "");
3066 if (os_snprintf_error(end - pos, ret))
3077 static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant *wpa_s,
3078 char *buf, size_t buflen)
3080 struct wpa_cred *cred;
3083 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_CRED");
3085 cred = wpa_config_add_cred(wpa_s->conf);
3089 wpa_msg(wpa_s, MSG_INFO, CRED_ADDED "%d", cred->id);
3091 ret = os_snprintf(buf, buflen, "%d\n", cred->id);
3092 if (os_snprintf_error(buflen, ret))
3098 static int wpas_ctrl_remove_cred(struct wpa_supplicant *wpa_s,
3099 struct wpa_cred *cred)
3101 struct wpa_ssid *ssid;
3106 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred");
3111 if (wpa_config_remove_cred(wpa_s->conf, id) < 0) {
3112 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred");
3116 wpa_msg(wpa_s, MSG_INFO, CRED_REMOVED "%d", id);
3118 /* Remove any network entry created based on the removed credential */
3119 ssid = wpa_s->conf->ssid;
3121 if (ssid->parent_cred == cred) {
3124 wpa_printf(MSG_DEBUG, "Remove network id %d since it "
3125 "used the removed credential", ssid->id);
3126 res = os_snprintf(str, sizeof(str), "%d", ssid->id);
3127 if (os_snprintf_error(sizeof(str), res))
3128 str[sizeof(str) - 1] = '\0';
3130 wpa_supplicant_ctrl_iface_remove_network(wpa_s, str);
3139 static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s,
3143 struct wpa_cred *cred, *prev;
3145 /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or
3146 * "provisioning_sp=<FQDN> */
3147 if (os_strcmp(cmd, "all") == 0) {
3148 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED all");
3149 cred = wpa_s->conf->cred;
3153 wpas_ctrl_remove_cred(wpa_s, prev);
3158 if (os_strncmp(cmd, "sp_fqdn=", 8) == 0) {
3159 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
3161 cred = wpa_s->conf->cred;
3167 for (i = 0; i < prev->num_domain; i++) {
3168 if (os_strcmp(prev->domain[i], cmd + 8)
3171 wpas_ctrl_remove_cred(wpa_s, prev);
3179 if (os_strncmp(cmd, "provisioning_sp=", 16) == 0) {
3180 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'",
3182 cred = wpa_s->conf->cred;
3186 if (prev->provisioning_sp &&
3187 os_strcmp(prev->provisioning_sp, cmd + 16) == 0)
3188 wpas_ctrl_remove_cred(wpa_s, prev);
3194 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED id=%d", id);
3196 cred = wpa_config_get_cred(wpa_s->conf, id);
3197 return wpas_ctrl_remove_cred(wpa_s, cred);
3201 static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant *wpa_s,
3205 struct wpa_cred *cred;
3208 /* cmd: "<cred id> <variable name> <value>" */
3209 name = os_strchr(cmd, ' ');
3214 value = os_strchr(name, ' ');
3220 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_CRED id=%d name='%s'",
3222 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
3223 (u8 *) value, os_strlen(value));
3225 cred = wpa_config_get_cred(wpa_s->conf, id);
3227 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
3232 if (wpa_config_set_cred(cred, name, value, 0) < 0) {
3233 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set cred "
3234 "variable '%s'", name);
3238 wpa_msg(wpa_s, MSG_INFO, CRED_MODIFIED "%d %s", cred->id, name);
3244 static int wpa_supplicant_ctrl_iface_get_cred(struct wpa_supplicant *wpa_s,
3245 char *cmd, char *buf,
3250 struct wpa_cred *cred;
3253 /* cmd: "<cred id> <variable name>" */
3254 name = os_strchr(cmd, ' ');
3260 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CRED id=%d name='%s'",
3263 cred = wpa_config_get_cred(wpa_s->conf, id);
3265 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
3270 value = wpa_config_get_cred_no_key(cred, name);
3271 if (value == NULL) {
3272 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get cred variable '%s'",
3277 res = os_strlcpy(buf, value, buflen);
3278 if (res >= buflen) {
3289 #ifndef CONFIG_NO_CONFIG_WRITE
3290 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s)
3294 if (!wpa_s->conf->update_config) {
3295 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
3296 "to update configuration (update_config=0)");
3300 ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
3302 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to "
3303 "update configuration");
3305 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration"
3311 #endif /* CONFIG_NO_CONFIG_WRITE */
3314 struct cipher_info {
3320 static const struct cipher_info ciphers[] = {
3321 { WPA_DRIVER_CAPA_ENC_CCMP_256, "CCMP-256", 0 },
3322 { WPA_DRIVER_CAPA_ENC_GCMP_256, "GCMP-256", 0 },
3323 { WPA_DRIVER_CAPA_ENC_CCMP, "CCMP", 0 },
3324 { WPA_DRIVER_CAPA_ENC_GCMP, "GCMP", 0 },
3325 { WPA_DRIVER_CAPA_ENC_TKIP, "TKIP", 0 },
3326 { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE, "NONE", 0 },
3327 { WPA_DRIVER_CAPA_ENC_WEP104, "WEP104", 1 },
3328 { WPA_DRIVER_CAPA_ENC_WEP40, "WEP40", 1 }
3332 static int ctrl_iface_get_capability_pairwise(int res, char *strict,
3333 struct wpa_driver_capa *capa,
3334 char *buf, size_t buflen)
3347 len = os_strlcpy(buf, "CCMP TKIP NONE", buflen);
3353 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
3354 if (!ciphers[i].group_only && capa->enc & ciphers[i].capa) {
3355 ret = os_snprintf(pos, end - pos, "%s%s",
3356 pos == buf ? "" : " ",
3358 if (os_snprintf_error(end - pos, ret))
3368 static int ctrl_iface_get_capability_group(int res, char *strict,
3369 struct wpa_driver_capa *capa,
3370 char *buf, size_t buflen)
3383 len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen);
3389 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
3390 if (capa->enc & ciphers[i].capa) {
3391 ret = os_snprintf(pos, end - pos, "%s%s",
3392 pos == buf ? "" : " ",
3394 if (os_snprintf_error(end - pos, ret))
3404 static int ctrl_iface_get_capability_key_mgmt(int res, char *strict,
3405 struct wpa_driver_capa *capa,
3406 char *buf, size_t buflen)
3418 len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
3425 ret = os_snprintf(pos, end - pos, "NONE IEEE8021X");
3426 if (os_snprintf_error(end - pos, ret))
3430 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
3431 WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
3432 ret = os_snprintf(pos, end - pos, " WPA-EAP");
3433 if (os_snprintf_error(end - pos, ret))
3438 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
3439 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
3440 ret = os_snprintf(pos, end - pos, " WPA-PSK");
3441 if (os_snprintf_error(end - pos, ret))
3446 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
3447 ret = os_snprintf(pos, end - pos, " WPA-NONE");
3448 if (os_snprintf_error(end - pos, ret))
3457 static int ctrl_iface_get_capability_proto(int res, char *strict,
3458 struct wpa_driver_capa *capa,
3459 char *buf, size_t buflen)
3471 len = os_strlcpy(buf, "RSN WPA", buflen);
3477 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
3478 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
3479 ret = os_snprintf(pos, end - pos, "%sRSN",
3480 pos == buf ? "" : " ");
3481 if (os_snprintf_error(end - pos, ret))
3486 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
3487 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
3488 ret = os_snprintf(pos, end - pos, "%sWPA",
3489 pos == buf ? "" : " ");
3490 if (os_snprintf_error(end - pos, ret))
3499 static int ctrl_iface_get_capability_auth_alg(int res, char *strict,
3500 struct wpa_driver_capa *capa,
3501 char *buf, size_t buflen)
3513 len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen);
3519 if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) {
3520 ret = os_snprintf(pos, end - pos, "%sOPEN",
3521 pos == buf ? "" : " ");
3522 if (os_snprintf_error(end - pos, ret))
3527 if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) {
3528 ret = os_snprintf(pos, end - pos, "%sSHARED",
3529 pos == buf ? "" : " ");
3530 if (os_snprintf_error(end - pos, ret))
3535 if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) {
3536 ret = os_snprintf(pos, end - pos, "%sLEAP",
3537 pos == buf ? "" : " ");
3538 if (os_snprintf_error(end - pos, ret))
3547 static int ctrl_iface_get_capability_modes(int res, char *strict,
3548 struct wpa_driver_capa *capa,
3549 char *buf, size_t buflen)
3561 len = os_strlcpy(buf, "IBSS AP", buflen);
3567 if (capa->flags & WPA_DRIVER_FLAGS_IBSS) {
3568 ret = os_snprintf(pos, end - pos, "%sIBSS",
3569 pos == buf ? "" : " ");
3570 if (os_snprintf_error(end - pos, ret))
3575 if (capa->flags & WPA_DRIVER_FLAGS_AP) {
3576 ret = os_snprintf(pos, end - pos, "%sAP",
3577 pos == buf ? "" : " ");
3578 if (os_snprintf_error(end - pos, ret))
3587 static int ctrl_iface_get_capability_channels(struct wpa_supplicant *wpa_s,
3588 char *buf, size_t buflen)
3590 struct hostapd_channel_data *chnl;
3592 char *pos, *end, *hmode;
3597 for (j = 0; j < wpa_s->hw.num_modes; j++) {
3598 switch (wpa_s->hw.modes[j].mode) {
3599 case HOSTAPD_MODE_IEEE80211B:
3602 case HOSTAPD_MODE_IEEE80211G:
3605 case HOSTAPD_MODE_IEEE80211A:
3608 case HOSTAPD_MODE_IEEE80211AD:
3614 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:", hmode);
3615 if (os_snprintf_error(end - pos, ret))
3618 chnl = wpa_s->hw.modes[j].channels;
3619 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
3620 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
3622 ret = os_snprintf(pos, end - pos, " %d", chnl[i].chan);
3623 if (os_snprintf_error(end - pos, ret))
3627 ret = os_snprintf(pos, end - pos, "\n");
3628 if (os_snprintf_error(end - pos, ret))
3637 static int ctrl_iface_get_capability_freq(struct wpa_supplicant *wpa_s,
3638 char *buf, size_t buflen)
3640 struct hostapd_channel_data *chnl;
3642 char *pos, *end, *hmode;
3647 for (j = 0; j < wpa_s->hw.num_modes; j++) {
3648 switch (wpa_s->hw.modes[j].mode) {
3649 case HOSTAPD_MODE_IEEE80211B:
3652 case HOSTAPD_MODE_IEEE80211G:
3655 case HOSTAPD_MODE_IEEE80211A:
3658 case HOSTAPD_MODE_IEEE80211AD:
3664 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:\n",
3666 if (os_snprintf_error(end - pos, ret))
3669 chnl = wpa_s->hw.modes[j].channels;
3670 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
3671 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
3673 ret = os_snprintf(pos, end - pos, " %d = %d MHz%s%s\n",
3674 chnl[i].chan, chnl[i].freq,
3675 chnl[i].flag & HOSTAPD_CHAN_NO_IR ?
3677 chnl[i].flag & HOSTAPD_CHAN_RADAR ?
3680 if (os_snprintf_error(end - pos, ret))
3684 ret = os_snprintf(pos, end - pos, "\n");
3685 if (os_snprintf_error(end - pos, ret))
3694 static int wpa_supplicant_ctrl_iface_get_capability(
3695 struct wpa_supplicant *wpa_s, const char *_field, char *buf,
3698 struct wpa_driver_capa capa;
3704 /* Determine whether or not strict checking was requested */
3705 len = os_strlcpy(field, _field, sizeof(field));
3706 if (len >= sizeof(field))
3708 strict = os_strchr(field, ' ');
3709 if (strict != NULL) {
3711 if (os_strcmp(strict, "strict") != 0)
3715 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
3716 field, strict ? strict : "");
3718 if (os_strcmp(field, "eap") == 0) {
3719 return eap_get_names(buf, buflen);
3722 res = wpa_drv_get_capa(wpa_s, &capa);
3724 if (os_strcmp(field, "pairwise") == 0)
3725 return ctrl_iface_get_capability_pairwise(res, strict, &capa,
3728 if (os_strcmp(field, "group") == 0)
3729 return ctrl_iface_get_capability_group(res, strict, &capa,
3732 if (os_strcmp(field, "key_mgmt") == 0)
3733 return ctrl_iface_get_capability_key_mgmt(res, strict, &capa,
3736 if (os_strcmp(field, "proto") == 0)
3737 return ctrl_iface_get_capability_proto(res, strict, &capa,
3740 if (os_strcmp(field, "auth_alg") == 0)
3741 return ctrl_iface_get_capability_auth_alg(res, strict, &capa,
3744 if (os_strcmp(field, "modes") == 0)
3745 return ctrl_iface_get_capability_modes(res, strict, &capa,
3748 if (os_strcmp(field, "channels") == 0)
3749 return ctrl_iface_get_capability_channels(wpa_s, buf, buflen);
3751 if (os_strcmp(field, "freq") == 0)
3752 return ctrl_iface_get_capability_freq(wpa_s, buf, buflen);
3755 if (os_strcmp(field, "tdls") == 0)
3756 return ctrl_iface_get_capability_tdls(wpa_s, buf, buflen);
3757 #endif /* CONFIG_TDLS */
3760 if (os_strcmp(field, "erp") == 0) {
3761 res = os_snprintf(buf, buflen, "ERP");
3762 if (os_snprintf_error(buflen, res))
3766 #endif /* CONFIG_EPR */
3768 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
3775 #ifdef CONFIG_INTERWORKING
3776 static char * anqp_add_hex(char *pos, char *end, const char *title,
3777 struct wpabuf *data)
3787 ret = os_snprintf(pos, end - pos, "%s=", title);
3788 if (os_snprintf_error(end - pos, ret))
3792 d = wpabuf_head_u8(data);
3793 for (i = 0; i < wpabuf_len(data); i++) {
3794 ret = os_snprintf(pos, end - pos, "%02x", *d++);
3795 if (os_snprintf_error(end - pos, ret))
3800 ret = os_snprintf(pos, end - pos, "\n");
3801 if (os_snprintf_error(end - pos, ret))
3807 #endif /* CONFIG_INTERWORKING */
3810 static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
3811 unsigned long mask, char *buf, size_t buflen)
3821 if (mask & WPA_BSS_MASK_ID) {
3822 ret = os_snprintf(pos, end - pos, "id=%u\n", bss->id);
3823 if (os_snprintf_error(end - pos, ret))
3828 if (mask & WPA_BSS_MASK_BSSID) {
3829 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
3830 MAC2STR(bss->bssid));
3831 if (os_snprintf_error(end - pos, ret))
3836 if (mask & WPA_BSS_MASK_FREQ) {
3837 ret = os_snprintf(pos, end - pos, "freq=%d\n", bss->freq);
3838 if (os_snprintf_error(end - pos, ret))
3843 if (mask & WPA_BSS_MASK_BEACON_INT) {
3844 ret = os_snprintf(pos, end - pos, "beacon_int=%d\n",
3846 if (os_snprintf_error(end - pos, ret))
3851 if (mask & WPA_BSS_MASK_CAPABILITIES) {
3852 ret = os_snprintf(pos, end - pos, "capabilities=0x%04x\n",
3854 if (os_snprintf_error(end - pos, ret))
3859 if (mask & WPA_BSS_MASK_QUAL) {
3860 ret = os_snprintf(pos, end - pos, "qual=%d\n", bss->qual);
3861 if (os_snprintf_error(end - pos, ret))
3866 if (mask & WPA_BSS_MASK_NOISE) {
3867 ret = os_snprintf(pos, end - pos, "noise=%d\n", bss->noise);
3868 if (os_snprintf_error(end - pos, ret))
3873 if (mask & WPA_BSS_MASK_LEVEL) {
3874 ret = os_snprintf(pos, end - pos, "level=%d\n", bss->level);
3875 if (os_snprintf_error(end - pos, ret))
3880 if (mask & WPA_BSS_MASK_TSF) {
3881 ret = os_snprintf(pos, end - pos, "tsf=%016llu\n",
3882 (unsigned long long) bss->tsf);
3883 if (os_snprintf_error(end - pos, ret))
3888 if (mask & WPA_BSS_MASK_AGE) {
3889 struct os_reltime now;
3891 os_get_reltime(&now);
3892 ret = os_snprintf(pos, end - pos, "age=%d\n",
3893 (int) (now.sec - bss->last_update.sec));
3894 if (os_snprintf_error(end - pos, ret))
3899 if (mask & WPA_BSS_MASK_IE) {
3900 ret = os_snprintf(pos, end - pos, "ie=");
3901 if (os_snprintf_error(end - pos, ret))
3905 ie = (const u8 *) (bss + 1);
3906 for (i = 0; i < bss->ie_len; i++) {
3907 ret = os_snprintf(pos, end - pos, "%02x", *ie++);
3908 if (os_snprintf_error(end - pos, ret))
3913 ret = os_snprintf(pos, end - pos, "\n");
3914 if (os_snprintf_error(end - pos, ret))
3919 if (mask & WPA_BSS_MASK_FLAGS) {
3920 ret = os_snprintf(pos, end - pos, "flags=");
3921 if (os_snprintf_error(end - pos, ret))
3925 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
3927 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie,
3929 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
3931 pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2,
3933 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
3934 if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
3935 ret = os_snprintf(pos, end - pos, "[WEP]");
3936 if (os_snprintf_error(end - pos, ret))
3940 if (bss_is_dmg(bss)) {
3942 ret = os_snprintf(pos, end - pos, "[DMG]");
3943 if (os_snprintf_error(end - pos, ret))
3946 switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
3947 case IEEE80211_CAP_DMG_IBSS:
3950 case IEEE80211_CAP_DMG_AP:
3953 case IEEE80211_CAP_DMG_PBSS:
3960 ret = os_snprintf(pos, end - pos, "%s", s);
3961 if (os_snprintf_error(end - pos, ret))
3965 if (bss->caps & IEEE80211_CAP_IBSS) {
3966 ret = os_snprintf(pos, end - pos, "[IBSS]");
3967 if (os_snprintf_error(end - pos, ret))
3971 if (bss->caps & IEEE80211_CAP_ESS) {
3972 ret = os_snprintf(pos, end - pos, "[ESS]");
3973 if (os_snprintf_error(end - pos, ret))
3978 if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
3979 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
3980 ret = os_snprintf(pos, end - pos, "[P2P]");
3981 if (os_snprintf_error(end - pos, ret))
3986 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) {
3987 ret = os_snprintf(pos, end - pos, "[HS20]");
3988 if (os_snprintf_error(end - pos, ret))
3992 #endif /* CONFIG_HS20 */
3994 ret = os_snprintf(pos, end - pos, "\n");
3995 if (os_snprintf_error(end - pos, ret))
4000 if (mask & WPA_BSS_MASK_SSID) {
4001 ret = os_snprintf(pos, end - pos, "ssid=%s\n",
4002 wpa_ssid_txt(bss->ssid, bss->ssid_len));
4003 if (os_snprintf_error(end - pos, ret))
4009 if (mask & WPA_BSS_MASK_WPS_SCAN) {
4010 ie = (const u8 *) (bss + 1);
4011 ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end);
4012 if (ret < 0 || ret >= end - pos)
4016 #endif /* CONFIG_WPS */
4019 if (mask & WPA_BSS_MASK_P2P_SCAN) {
4020 ie = (const u8 *) (bss + 1);
4021 ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end);
4022 if (ret < 0 || ret >= end - pos)
4026 #endif /* CONFIG_P2P */
4028 #ifdef CONFIG_WIFI_DISPLAY
4029 if (mask & WPA_BSS_MASK_WIFI_DISPLAY) {
4031 ie = (const u8 *) (bss + 1);
4032 wfd = ieee802_11_vendor_ie_concat(ie, bss->ie_len,
4033 WFD_IE_VENDOR_TYPE);
4035 ret = os_snprintf(pos, end - pos, "wfd_subelems=");
4036 if (os_snprintf_error(end - pos, ret)) {
4042 pos += wpa_snprintf_hex(pos, end - pos,
4047 ret = os_snprintf(pos, end - pos, "\n");
4048 if (os_snprintf_error(end - pos, ret))
4053 #endif /* CONFIG_WIFI_DISPLAY */
4055 #ifdef CONFIG_INTERWORKING
4056 if ((mask & WPA_BSS_MASK_INTERNETW) && bss->anqp) {
4057 struct wpa_bss_anqp *anqp = bss->anqp;
4058 pos = anqp_add_hex(pos, end, "anqp_venue_name",
4060 pos = anqp_add_hex(pos, end, "anqp_network_auth_type",
4061 anqp->network_auth_type);
4062 pos = anqp_add_hex(pos, end, "anqp_roaming_consortium",
4063 anqp->roaming_consortium);
4064 pos = anqp_add_hex(pos, end, "anqp_ip_addr_type_availability",
4065 anqp->ip_addr_type_availability);
4066 pos = anqp_add_hex(pos, end, "anqp_nai_realm",
4068 pos = anqp_add_hex(pos, end, "anqp_3gpp", anqp->anqp_3gpp);
4069 pos = anqp_add_hex(pos, end, "anqp_domain_name",
4072 pos = anqp_add_hex(pos, end, "hs20_operator_friendly_name",
4073 anqp->hs20_operator_friendly_name);
4074 pos = anqp_add_hex(pos, end, "hs20_wan_metrics",
4075 anqp->hs20_wan_metrics);
4076 pos = anqp_add_hex(pos, end, "hs20_connection_capability",
4077 anqp->hs20_connection_capability);
4078 pos = anqp_add_hex(pos, end, "hs20_operating_class",
4079 anqp->hs20_operating_class);
4080 pos = anqp_add_hex(pos, end, "hs20_osu_providers_list",
4081 anqp->hs20_osu_providers_list);
4082 #endif /* CONFIG_HS20 */
4084 #endif /* CONFIG_INTERWORKING */
4087 if (mask & WPA_BSS_MASK_MESH_SCAN) {
4088 ie = (const u8 *) (bss + 1);
4089 ret = wpas_mesh_scan_result_text(ie, bss->ie_len, pos, end);
4090 if (ret < 0 || ret >= end - pos)
4094 #endif /* CONFIG_MESH */
4096 if (mask & WPA_BSS_MASK_DELIM) {
4097 ret = os_snprintf(pos, end - pos, "====\n");
4098 if (os_snprintf_error(end - pos, ret))
4107 static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
4108 const char *cmd, char *buf,
4113 struct wpa_bss *bss;
4114 struct wpa_bss *bsslast = NULL;
4115 struct dl_list *next;
4118 char *ctmp, *end = buf + buflen;
4119 unsigned long mask = WPA_BSS_MASK_ALL;
4121 if (os_strncmp(cmd, "RANGE=", 6) == 0) {
4122 if (os_strncmp(cmd + 6, "ALL", 3) == 0) {
4123 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss,
4125 bsslast = dl_list_last(&wpa_s->bss_id, struct wpa_bss,
4127 } else { /* N1-N2 */
4128 unsigned int id1, id2;
4130 if ((ctmp = os_strchr(cmd + 6, '-')) == NULL) {
4131 wpa_printf(MSG_INFO, "Wrong BSS range "
4136 if (*(cmd + 6) == '-')
4139 id1 = atoi(cmd + 6);
4141 if (*ctmp >= '0' && *ctmp <= '9')
4144 id2 = (unsigned int) -1;
4145 bss = wpa_bss_get_id_range(wpa_s, id1, id2);
4146 if (id2 == (unsigned int) -1)
4147 bsslast = dl_list_last(&wpa_s->bss_id,
4151 bsslast = wpa_bss_get_id(wpa_s, id2);
4152 if (bsslast == NULL && bss && id2 > id1) {
4153 struct wpa_bss *tmp = bss;
4155 next = tmp->list_id.next;
4156 if (next == &wpa_s->bss_id)
4158 tmp = dl_list_entry(
4159 next, struct wpa_bss,
4168 } else if (os_strncmp(cmd, "FIRST", 5) == 0)
4169 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, list_id);
4170 else if (os_strncmp(cmd, "LAST", 4) == 0)
4171 bss = dl_list_last(&wpa_s->bss_id, struct wpa_bss, list_id);
4172 else if (os_strncmp(cmd, "ID-", 3) == 0) {
4174 bss = wpa_bss_get_id(wpa_s, i);
4175 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
4177 bss = wpa_bss_get_id(wpa_s, i);
4179 next = bss->list_id.next;
4180 if (next == &wpa_s->bss_id)
4183 bss = dl_list_entry(next, struct wpa_bss,
4187 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
4188 if (hwaddr_aton(cmd + 13, bssid) == 0)
4189 bss = wpa_bss_get_p2p_dev_addr(wpa_s, bssid);
4192 #endif /* CONFIG_P2P */
4193 } else if (hwaddr_aton(cmd, bssid) == 0)
4194 bss = wpa_bss_get_bssid(wpa_s, bssid);
4196 struct wpa_bss *tmp;
4199 dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id)
4208 if ((ctmp = os_strstr(cmd, "MASK=")) != NULL) {
4209 mask = strtoul(ctmp + 5, NULL, 0x10);
4211 mask = WPA_BSS_MASK_ALL;
4217 if (bsslast == NULL)
4220 len = print_bss_info(wpa_s, bss, mask, buf, buflen);
4224 if (bss == bsslast) {
4225 if ((mask & WPA_BSS_MASK_DELIM) && len &&
4226 (bss == dl_list_last(&wpa_s->bss_id,
4227 struct wpa_bss, list_id))) {
4230 res = os_snprintf(buf - 5, end - buf + 5,
4232 if (os_snprintf_error(end - buf + 5, res)) {
4233 wpa_printf(MSG_DEBUG,
4234 "Could not add end delim");
4239 next = bss->list_id.next;
4240 if (next == &wpa_s->bss_id)
4242 bss = dl_list_entry(next, struct wpa_bss, list_id);
4243 } while (bss && len);
4249 static int wpa_supplicant_ctrl_iface_ap_scan(
4250 struct wpa_supplicant *wpa_s, char *cmd)
4252 int ap_scan = atoi(cmd);
4253 return wpa_supplicant_set_ap_scan(wpa_s, ap_scan);
4257 static int wpa_supplicant_ctrl_iface_scan_interval(
4258 struct wpa_supplicant *wpa_s, char *cmd)
4260 int scan_int = atoi(cmd);
4261 return wpa_supplicant_set_scan_interval(wpa_s, scan_int);
4265 static int wpa_supplicant_ctrl_iface_bss_expire_age(
4266 struct wpa_supplicant *wpa_s, char *cmd)
4268 int expire_age = atoi(cmd);
4269 return wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age);
4273 static int wpa_supplicant_ctrl_iface_bss_expire_count(
4274 struct wpa_supplicant *wpa_s, char *cmd)
4276 int expire_count = atoi(cmd);
4277 return wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count);
4281 static void wpa_supplicant_ctrl_iface_bss_flush(
4282 struct wpa_supplicant *wpa_s, char *cmd)
4284 int flush_age = atoi(cmd);
4287 wpa_bss_flush(wpa_s);
4289 wpa_bss_flush_by_age(wpa_s, flush_age);
4293 #ifdef CONFIG_TESTING_OPTIONS
4294 static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s)
4296 wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication");
4297 /* MLME-DELETEKEYS.request */
4298 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL, 0);
4299 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL, 0);
4300 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL, 0);
4301 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL, 0);
4302 #ifdef CONFIG_IEEE80211W
4303 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL, 0);
4304 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL, 0);
4305 #endif /* CONFIG_IEEE80211W */
4307 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, wpa_s->bssid, 0, 0, NULL, 0, NULL,
4309 /* MLME-SETPROTECTION.request(None) */
4310 wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid,
4311 MLME_SETPROTECTION_PROTECT_TYPE_NONE,
4312 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE);
4313 wpa_sm_drop_sa(wpa_s->wpa);
4315 #endif /* CONFIG_TESTING_OPTIONS */
4318 static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s,
4321 #ifdef CONFIG_NO_SCAN_PROCESSING
4323 #else /* CONFIG_NO_SCAN_PROCESSING */
4325 struct wpa_bss *bss;
4326 struct wpa_ssid *ssid = wpa_s->current_ssid;
4328 if (hwaddr_aton(addr, bssid)) {
4329 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid "
4330 "address '%s'", addr);
4334 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR, MAC2STR(bssid));
4337 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network "
4338 "configuration known for the target AP");
4342 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
4344 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found "
4350 * TODO: Find best network configuration block from configuration to
4351 * allow roaming to other networks
4354 wpa_s->reassociate = 1;
4355 wpa_supplicant_connect(wpa_s, bss, ssid);
4358 #endif /* CONFIG_NO_SCAN_PROCESSING */
4363 static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd)
4365 unsigned int timeout = atoi(cmd);
4366 enum p2p_discovery_type type = P2P_FIND_START_WITH_FULL;
4367 u8 dev_id[ETH_ALEN], *_dev_id = NULL;
4368 u8 dev_type[WPS_DEV_TYPE_LEN], *_dev_type = NULL;
4370 unsigned int search_delay;
4372 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
4373 wpa_dbg(wpa_s, MSG_INFO,
4374 "Reject P2P_FIND since interface is disabled");
4377 if (os_strstr(cmd, "type=social"))
4378 type = P2P_FIND_ONLY_SOCIAL;
4379 else if (os_strstr(cmd, "type=progressive"))
4380 type = P2P_FIND_PROGRESSIVE;
4382 pos = os_strstr(cmd, "dev_id=");
4385 if (hwaddr_aton(pos, dev_id))
4390 pos = os_strstr(cmd, "dev_type=");
4393 if (wps_dev_type_str2bin(pos, dev_type) < 0)
4395 _dev_type = dev_type;
4398 pos = os_strstr(cmd, "delay=");
4401 search_delay = atoi(pos);
4403 search_delay = wpas_p2p_search_delay(wpa_s);
4405 return wpas_p2p_find(wpa_s, timeout, type, _dev_type != NULL, _dev_type,
4406 _dev_id, search_delay);
4410 static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd,
4411 char *buf, size_t buflen)
4416 enum p2p_wps_method wps_method;
4419 int persistent_group, persistent_id = -1;
4428 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad]
4429 * [persistent|persistent=<network id>]
4430 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
4433 if (hwaddr_aton(cmd, addr))
4441 persistent_group = os_strstr(pos, " persistent") != NULL;
4442 pos2 = os_strstr(pos, " persistent=");
4444 struct wpa_ssid *ssid;
4445 persistent_id = atoi(pos2 + 12);
4446 ssid = wpa_config_get_network(wpa_s->conf, persistent_id);
4447 if (ssid == NULL || ssid->disabled != 2 ||
4448 ssid->mode != WPAS_MODE_P2P_GO) {
4449 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
4450 "SSID id=%d for persistent P2P group (GO)",
4455 join = os_strstr(pos, " join") != NULL;
4456 auth = os_strstr(pos, " auth") != NULL;
4457 automatic = os_strstr(pos, " auto") != NULL;
4458 pd = os_strstr(pos, " provdisc") != NULL;
4459 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
4460 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
4463 pos2 = os_strstr(pos, " go_intent=");
4466 go_intent = atoi(pos2);
4467 if (go_intent < 0 || go_intent > 15)
4471 pos2 = os_strstr(pos, " freq=");
4479 if (os_strncmp(pos, "pin", 3) == 0) {
4480 /* Request random PIN (to be displayed) and enable the PIN */
4481 wps_method = WPS_PIN_DISPLAY;
4482 } else if (os_strncmp(pos, "pbc", 3) == 0) {
4483 wps_method = WPS_PBC;
4486 pos = os_strchr(pin, ' ');
4487 wps_method = WPS_PIN_KEYPAD;
4490 if (os_strncmp(pos, "display", 7) == 0)
4491 wps_method = WPS_PIN_DISPLAY;
4493 if (!wps_pin_str_valid(pin)) {
4494 os_memcpy(buf, "FAIL-INVALID-PIN\n", 17);
4499 new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method,
4500 persistent_group, automatic, join,
4501 auth, go_intent, freq, persistent_id, pd,
4503 if (new_pin == -2) {
4504 os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
4507 if (new_pin == -3) {
4508 os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
4513 if (wps_method == WPS_PIN_DISPLAY && pin == NULL) {
4514 ret = os_snprintf(buf, buflen, "%08d", new_pin);
4515 if (os_snprintf_error(buflen, ret))
4520 os_memcpy(buf, "OK\n", 3);
4525 static int p2p_ctrl_listen(struct wpa_supplicant *wpa_s, char *cmd)
4527 unsigned int timeout = atoi(cmd);
4528 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
4529 wpa_dbg(wpa_s, MSG_INFO,
4530 "Reject P2P_LISTEN since interface is disabled");
4533 return wpas_p2p_listen(wpa_s, timeout);
4537 static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd)
4541 enum wpas_p2p_prov_disc_use use = WPAS_P2P_PD_FOR_GO_NEG;
4543 /* <addr> <config method> [join|auto] */
4545 if (hwaddr_aton(cmd, addr))
4553 if (os_strstr(pos, " join") != NULL)
4554 use = WPAS_P2P_PD_FOR_JOIN;
4555 else if (os_strstr(pos, " auto") != NULL)
4556 use = WPAS_P2P_PD_AUTO;
4558 return wpas_p2p_prov_disc(wpa_s, addr, pos, use);
4562 static int p2p_get_passphrase(struct wpa_supplicant *wpa_s, char *buf,
4565 struct wpa_ssid *ssid = wpa_s->current_ssid;
4567 if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO ||
4568 ssid->passphrase == NULL)
4571 os_strlcpy(buf, ssid->passphrase, buflen);
4572 return os_strlen(buf);
4576 static int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd,
4577 char *buf, size_t buflen)
4581 u8 dst_buf[ETH_ALEN], *dst;
4582 struct wpabuf *tlvs;
4586 if (hwaddr_aton(cmd, dst_buf))
4589 if (dst[0] == 0 && dst[1] == 0 && dst[2] == 0 &&
4590 dst[3] == 0 && dst[4] == 0 && dst[5] == 0)
4597 if (os_strncmp(pos, "upnp ", 5) == 0) {
4600 if (hexstr2bin(pos, &version, 1) < 0)
4606 ref = wpas_p2p_sd_request_upnp(wpa_s, dst, version, pos);
4607 #ifdef CONFIG_WIFI_DISPLAY
4608 } else if (os_strncmp(pos, "wifi-display ", 13) == 0) {
4609 ref = wpas_p2p_sd_request_wifi_display(wpa_s, dst, pos + 13);
4610 #endif /* CONFIG_WIFI_DISPLAY */
4612 len = os_strlen(pos);
4616 tlvs = wpabuf_alloc(len);
4619 if (hexstr2bin(pos, wpabuf_put(tlvs, len), len) < 0) {
4624 ref = wpas_p2p_sd_request(wpa_s, dst, tlvs);
4629 res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref);
4630 if (os_snprintf_error(buflen, res))
4636 static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s,
4639 long long unsigned val;
4641 if (sscanf(cmd, "%llx", &val) != 1)
4644 return wpas_p2p_sd_cancel_request(wpa_s, req);
4648 static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant *wpa_s, char *cmd)
4653 struct wpabuf *resp_tlvs;
4657 pos = os_strchr(cmd, ' ');
4665 if (hwaddr_aton(pos, dst))
4672 pos2 = os_strchr(pos, ' ');
4676 dialog_token = atoi(pos);
4678 len = os_strlen(pos2);
4682 resp_tlvs = wpabuf_alloc(len);
4683 if (resp_tlvs == NULL)
4685 if (hexstr2bin(pos2, wpabuf_put(resp_tlvs, len), len) < 0) {
4686 wpabuf_free(resp_tlvs);
4690 wpas_p2p_sd_response(wpa_s, freq, dst, dialog_token, resp_tlvs);
4691 wpabuf_free(resp_tlvs);
4696 static int p2p_ctrl_serv_disc_external(struct wpa_supplicant *wpa_s,
4699 if (os_strcmp(cmd, "0") && os_strcmp(cmd, "1"))
4701 wpa_s->p2p_sd_over_ctrl_iface = atoi(cmd);
4706 static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant *wpa_s,
4711 struct wpabuf *query, *resp;
4713 pos = os_strchr(cmd, ' ');
4718 len = os_strlen(cmd);
4722 query = wpabuf_alloc(len);
4725 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
4730 len = os_strlen(pos);
4736 resp = wpabuf_alloc(len);
4741 if (hexstr2bin(pos, wpabuf_put(resp, len), len) < 0) {
4747 if (wpas_p2p_service_add_bonjour(wpa_s, query, resp) < 0) {
4756 static int p2p_ctrl_service_add_upnp(struct wpa_supplicant *wpa_s, char *cmd)
4761 pos = os_strchr(cmd, ' ');
4766 if (hexstr2bin(cmd, &version, 1) < 0)
4769 return wpas_p2p_service_add_upnp(wpa_s, version, pos);
4773 static int p2p_ctrl_service_add(struct wpa_supplicant *wpa_s, char *cmd)
4777 pos = os_strchr(cmd, ' ');
4782 if (os_strcmp(cmd, "bonjour") == 0)
4783 return p2p_ctrl_service_add_bonjour(wpa_s, pos);
4784 if (os_strcmp(cmd, "upnp") == 0)
4785 return p2p_ctrl_service_add_upnp(wpa_s, pos);
4786 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
4791 static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant *wpa_s,
4795 struct wpabuf *query;
4798 len = os_strlen(cmd);
4802 query = wpabuf_alloc(len);
4805 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
4810 ret = wpas_p2p_service_del_bonjour(wpa_s, query);
4816 static int p2p_ctrl_service_del_upnp(struct wpa_supplicant *wpa_s, char *cmd)
4821 pos = os_strchr(cmd, ' ');
4826 if (hexstr2bin(cmd, &version, 1) < 0)
4829 return wpas_p2p_service_del_upnp(wpa_s, version, pos);
4833 static int p2p_ctrl_service_del(struct wpa_supplicant *wpa_s, char *cmd)
4837 pos = os_strchr(cmd, ' ');
4842 if (os_strcmp(cmd, "bonjour") == 0)
4843 return p2p_ctrl_service_del_bonjour(wpa_s, pos);
4844 if (os_strcmp(cmd, "upnp") == 0)
4845 return p2p_ctrl_service_del_upnp(wpa_s, pos);
4846 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
4851 static int p2p_ctrl_reject(struct wpa_supplicant *wpa_s, char *cmd)
4857 if (hwaddr_aton(cmd, addr))
4860 return wpas_p2p_reject(wpa_s, addr);
4864 static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd)
4868 struct wpa_ssid *ssid;
4869 u8 *_peer = NULL, peer[ETH_ALEN];
4870 int freq = 0, pref_freq = 0;
4874 pos = os_strstr(cmd, " peer=");
4877 if (hwaddr_aton(pos, peer))
4881 ssid = wpa_config_get_network(wpa_s->conf, id);
4882 if (ssid == NULL || ssid->disabled != 2) {
4883 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
4884 "for persistent P2P group",
4889 pos = os_strstr(cmd, " freq=");
4897 pos = os_strstr(cmd, " pref=");
4900 pref_freq = atoi(pos);
4905 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
4906 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
4909 return wpas_p2p_invite(wpa_s, _peer, ssid, NULL, freq, ht40, vht,
4914 static int p2p_ctrl_invite_group(struct wpa_supplicant *wpa_s, char *cmd)
4917 u8 peer[ETH_ALEN], go_dev_addr[ETH_ALEN], *go_dev = NULL;
4919 pos = os_strstr(cmd, " peer=");
4925 if (hwaddr_aton(pos, peer)) {
4926 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", pos);
4930 pos = os_strstr(pos, " go_dev_addr=");
4933 if (hwaddr_aton(pos, go_dev_addr)) {
4934 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'",
4938 go_dev = go_dev_addr;
4941 return wpas_p2p_invite_group(wpa_s, cmd, peer, go_dev);
4945 static int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd)
4947 if (os_strncmp(cmd, "persistent=", 11) == 0)
4948 return p2p_ctrl_invite_persistent(wpa_s, cmd + 11);
4949 if (os_strncmp(cmd, "group=", 6) == 0)
4950 return p2p_ctrl_invite_group(wpa_s, cmd + 6);
4956 static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s,
4957 char *cmd, int freq, int ht40,
4961 struct wpa_ssid *ssid;
4964 ssid = wpa_config_get_network(wpa_s->conf, id);
4965 if (ssid == NULL || ssid->disabled != 2) {
4966 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
4967 "for persistent P2P group",
4972 return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq, 0, ht40, vht,
4977 static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd)
4979 int freq = 0, ht40, vht;
4982 pos = os_strstr(cmd, "freq=");
4984 freq = atoi(pos + 5);
4986 vht = (os_strstr(cmd, "vht") != NULL) || wpa_s->conf->p2p_go_vht;
4987 ht40 = (os_strstr(cmd, "ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
4990 if (os_strncmp(cmd, "persistent=", 11) == 0)
4991 return p2p_ctrl_group_add_persistent(wpa_s, cmd + 11, freq,
4993 if (os_strcmp(cmd, "persistent") == 0 ||
4994 os_strncmp(cmd, "persistent ", 11) == 0)
4995 return wpas_p2p_group_add(wpa_s, 1, freq, ht40, vht);
4996 if (os_strncmp(cmd, "freq=", 5) == 0)
4997 return wpas_p2p_group_add(wpa_s, 0, freq, ht40, vht);
4999 return wpas_p2p_group_add(wpa_s, 0, freq, ht40, vht);
5001 wpa_printf(MSG_DEBUG, "CTRL: Invalid P2P_GROUP_ADD parameters '%s'",
5007 static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd,
5008 char *buf, size_t buflen)
5010 u8 addr[ETH_ALEN], *addr_ptr;
5012 const struct p2p_peer_info *info;
5014 char devtype[WPS_DEV_TYPE_BUFSIZE];
5015 struct wpa_ssid *ssid;
5018 if (!wpa_s->global->p2p)
5021 if (os_strcmp(cmd, "FIRST") == 0) {
5024 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
5025 if (hwaddr_aton(cmd + 5, addr) < 0)
5030 if (hwaddr_aton(cmd, addr) < 0)
5036 info = p2p_get_peer_info(wpa_s->global->p2p, addr_ptr, next);
5043 res = os_snprintf(pos, end - pos, MACSTR "\n"
5049 "serial_number=%s\n"
5050 "config_methods=0x%x\n"
5052 "group_capab=0x%x\n"
5054 MAC2STR(info->p2p_device_addr),
5055 wps_dev_type_bin2str(info->pri_dev_type,
5056 devtype, sizeof(devtype)),
5061 info->serial_number,
5062 info->config_methods,
5066 if (os_snprintf_error(end - pos, res))
5070 for (i = 0; i < info->wps_sec_dev_type_list_len / WPS_DEV_TYPE_LEN; i++)
5073 t = &info->wps_sec_dev_type_list[i * WPS_DEV_TYPE_LEN];
5074 res = os_snprintf(pos, end - pos, "sec_dev_type=%s\n",
5075 wps_dev_type_bin2str(t, devtype,
5077 if (os_snprintf_error(end - pos, res))
5082 ssid = wpas_p2p_get_persistent(wpa_s, info->p2p_device_addr, NULL, 0);
5084 res = os_snprintf(pos, end - pos, "persistent=%d\n", ssid->id);
5085 if (os_snprintf_error(end - pos, res))
5090 res = p2p_get_peer_info_txt(info, pos, end - pos);
5095 if (info->vendor_elems) {
5096 res = os_snprintf(pos, end - pos, "vendor_elems=");
5097 if (os_snprintf_error(end - pos, res))
5101 pos += wpa_snprintf_hex(pos, end - pos,
5102 wpabuf_head(info->vendor_elems),
5103 wpabuf_len(info->vendor_elems));
5105 res = os_snprintf(pos, end - pos, "\n");
5106 if (os_snprintf_error(end - pos, res))
5115 static int p2p_ctrl_disallow_freq(struct wpa_supplicant *wpa_s,
5120 if (wpa_s->global->p2p == NULL)
5123 if (freq_range_list_parse(&wpa_s->global->p2p_disallow_freq, param) < 0)
5126 for (i = 0; i < wpa_s->global->p2p_disallow_freq.num; i++) {
5127 struct wpa_freq_range *freq;
5128 freq = &wpa_s->global->p2p_disallow_freq.range[i];
5129 wpa_printf(MSG_DEBUG, "P2P: Disallowed frequency range %u-%u",
5130 freq->min, freq->max);
5133 wpas_p2p_update_channel_list(wpa_s);
5138 static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd)
5142 if (wpa_s->global->p2p == NULL)
5145 param = os_strchr(cmd, ' ');
5150 if (os_strcmp(cmd, "discoverability") == 0) {
5151 p2p_set_client_discoverability(wpa_s->global->p2p,
5156 if (os_strcmp(cmd, "managed") == 0) {
5157 p2p_set_managed_oper(wpa_s->global->p2p, atoi(param));
5161 if (os_strcmp(cmd, "listen_channel") == 0) {
5162 return p2p_set_listen_channel(wpa_s->global->p2p, 81,
5166 if (os_strcmp(cmd, "ssid_postfix") == 0) {
5167 return p2p_set_ssid_postfix(wpa_s->global->p2p, (u8 *) param,
5171 if (os_strcmp(cmd, "noa") == 0) {
5173 int count, start, duration;
5174 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
5175 count = atoi(param);
5176 pos = os_strchr(param, ',');
5181 pos = os_strchr(pos, ',');
5185 duration = atoi(pos);
5186 if (count < 0 || count > 255 || start < 0 || duration < 0)
5188 if (count == 0 && duration > 0)
5190 wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
5191 "start=%d duration=%d", count, start, duration);
5192 return wpas_p2p_set_noa(wpa_s, count, start, duration);
5195 if (os_strcmp(cmd, "ps") == 0)
5196 return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1);
5198 if (os_strcmp(cmd, "oppps") == 0)
5199 return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1);
5201 if (os_strcmp(cmd, "ctwindow") == 0)
5202 return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param));
5204 if (os_strcmp(cmd, "disabled") == 0) {
5205 wpa_s->global->p2p_disabled = atoi(param);
5206 wpa_printf(MSG_DEBUG, "P2P functionality %s",
5207 wpa_s->global->p2p_disabled ?
5208 "disabled" : "enabled");
5209 if (wpa_s->global->p2p_disabled) {
5210 wpas_p2p_stop_find(wpa_s);
5211 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
5212 p2p_flush(wpa_s->global->p2p);
5217 if (os_strcmp(cmd, "conc_pref") == 0) {
5218 if (os_strcmp(param, "sta") == 0)
5219 wpa_s->global->conc_pref = WPA_CONC_PREF_STA;
5220 else if (os_strcmp(param, "p2p") == 0)
5221 wpa_s->global->conc_pref = WPA_CONC_PREF_P2P;
5223 wpa_printf(MSG_INFO, "Invalid conc_pref value");
5226 wpa_printf(MSG_DEBUG, "Single channel concurrency preference: "
5231 if (os_strcmp(cmd, "force_long_sd") == 0) {
5232 wpa_s->force_long_sd = atoi(param);
5236 if (os_strcmp(cmd, "peer_filter") == 0) {
5238 if (hwaddr_aton(param, addr))
5240 p2p_set_peer_filter(wpa_s->global->p2p, addr);
5244 if (os_strcmp(cmd, "cross_connect") == 0)
5245 return wpas_p2p_set_cross_connect(wpa_s, atoi(param));
5247 if (os_strcmp(cmd, "go_apsd") == 0) {
5248 if (os_strcmp(param, "disable") == 0)
5249 wpa_s->set_ap_uapsd = 0;
5251 wpa_s->set_ap_uapsd = 1;
5252 wpa_s->ap_uapsd = atoi(param);
5257 if (os_strcmp(cmd, "client_apsd") == 0) {
5258 if (os_strcmp(param, "disable") == 0)
5259 wpa_s->set_sta_uapsd = 0;
5263 /* format: BE,BK,VI,VO;max SP Length */
5265 pos = os_strchr(param, ',');
5270 pos = os_strchr(pos, ',');
5275 pos = os_strchr(pos, ',');
5280 /* ignore max SP Length for now */
5282 wpa_s->set_sta_uapsd = 1;
5283 wpa_s->sta_uapsd = 0;
5285 wpa_s->sta_uapsd |= BIT(0);
5287 wpa_s->sta_uapsd |= BIT(1);
5289 wpa_s->sta_uapsd |= BIT(2);
5291 wpa_s->sta_uapsd |= BIT(3);
5296 if (os_strcmp(cmd, "disallow_freq") == 0)
5297 return p2p_ctrl_disallow_freq(wpa_s, param);
5299 if (os_strcmp(cmd, "disc_int") == 0) {
5300 int min_disc_int, max_disc_int, max_disc_tu;
5305 min_disc_int = atoi(pos);
5306 pos = os_strchr(pos, ' ');
5311 max_disc_int = atoi(pos);
5312 pos = os_strchr(pos, ' ');
5317 max_disc_tu = atoi(pos);
5319 return p2p_set_disc_int(wpa_s->global->p2p, min_disc_int,
5320 max_disc_int, max_disc_tu);
5323 if (os_strcmp(cmd, "per_sta_psk") == 0) {
5324 wpa_s->global->p2p_per_sta_psk = !!atoi(param);
5328 #ifdef CONFIG_WPS_NFC
5329 if (os_strcmp(cmd, "nfc_tag") == 0)
5330 return wpas_p2p_nfc_tag_enabled(wpa_s, !!atoi(param));
5331 #endif /* CONFIG_WPS_NFC */
5333 if (os_strcmp(cmd, "disable_ip_addr_req") == 0) {
5334 wpa_s->p2p_disable_ip_addr_req = !!atoi(param);
5338 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
5345 static void p2p_ctrl_flush(struct wpa_supplicant *wpa_s)
5347 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
5348 wpa_s->force_long_sd = 0;
5349 wpas_p2p_stop_find(wpa_s);
5350 if (wpa_s->global->p2p)
5351 p2p_flush(wpa_s->global->p2p);
5355 static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd)
5358 unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0;
5361 pos = os_strchr(cmd, ' ');
5367 pos2 = os_strchr(pos, ' ');
5375 pos = os_strchr(pos2, ' ');
5383 return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2);
5387 static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd)
5390 unsigned int period = 0, interval = 0;
5393 pos = os_strchr(cmd, ' ');
5398 interval = atoi(pos);
5401 return wpas_p2p_ext_listen(wpa_s, period, interval);
5405 static int p2p_ctrl_remove_client(struct wpa_supplicant *wpa_s, const char *cmd)
5412 if (os_strncmp(pos, "iface=", 6) == 0) {
5416 if (hwaddr_aton(pos, peer))
5419 wpas_p2p_remove_client(wpa_s, peer, iface_addr);
5423 #endif /* CONFIG_P2P */
5426 static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s, char *val)
5428 struct wpa_freq_range_list ranges;
5430 struct hostapd_hw_modes *mode;
5433 if (wpa_s->hw.modes == NULL)
5436 os_memset(&ranges, 0, sizeof(ranges));
5437 if (freq_range_list_parse(&ranges, val) < 0)
5440 for (i = 0; i < wpa_s->hw.num_modes; i++) {
5443 mode = &wpa_s->hw.modes[i];
5444 for (j = 0; j < mode->num_channels; j++) {
5447 if (mode->channels[j].flag & HOSTAPD_CHAN_DISABLED)
5450 freq = mode->channels[j].freq;
5451 if (!freq_range_list_includes(&ranges, freq))
5454 int_array_add_unique(&freqs, freq);
5458 os_free(ranges.range);
5463 #ifdef CONFIG_INTERWORKING
5465 static int ctrl_interworking_select(struct wpa_supplicant *wpa_s, char *param)
5473 auto_sel = os_strstr(param, "auto") != NULL;
5475 pos = os_strstr(param, "freq=");
5477 freqs = freq_range_to_channel_list(wpa_s, pos + 5);
5484 return interworking_select(wpa_s, auto_sel, freqs);
5488 static int ctrl_interworking_connect(struct wpa_supplicant *wpa_s, char *dst)
5491 struct wpa_bss *bss;
5493 if (hwaddr_aton(dst, bssid)) {
5494 wpa_printf(MSG_DEBUG, "Invalid BSSID '%s'", dst);
5498 bss = wpa_bss_get_bssid(wpa_s, bssid);
5500 wpa_printf(MSG_DEBUG, "Could not find BSS " MACSTR,
5505 return interworking_connect(wpa_s, bss);
5509 static int get_anqp(struct wpa_supplicant *wpa_s, char *dst)
5511 u8 dst_addr[ETH_ALEN];
5514 #define MAX_ANQP_INFO_ID 100
5515 u16 id[MAX_ANQP_INFO_ID];
5519 used = hwaddr_aton2(dst, dst_addr);
5525 while (num_id < MAX_ANQP_INFO_ID) {
5526 if (os_strncmp(pos, "hs20:", 5) == 0) {
5528 int num = atoi(pos + 5);
5529 if (num <= 0 || num > 31)
5531 subtypes |= BIT(num);
5532 #else /* CONFIG_HS20 */
5534 #endif /* CONFIG_HS20 */
5536 id[num_id] = atoi(pos);
5540 pos = os_strchr(pos + 1, ',');
5549 return anqp_send_req(wpa_s, dst_addr, id, num_id, subtypes);
5553 static int gas_request(struct wpa_supplicant *wpa_s, char *cmd)
5555 u8 dst_addr[ETH_ALEN];
5556 struct wpabuf *advproto, *query = NULL;
5561 used = hwaddr_aton2(cmd, dst_addr);
5569 /* Advertisement Protocol ID */
5570 end = os_strchr(pos, ' ');
5574 len = os_strlen(pos);
5580 advproto = wpabuf_alloc(len);
5581 if (advproto == NULL)
5583 if (hexstr2bin(pos, wpabuf_put(advproto, len), len) < 0)
5587 /* Optional Query Request */
5592 len = os_strlen(pos);
5599 query = wpabuf_alloc(len);
5602 if (hexstr2bin(pos, wpabuf_put(query, len), len) < 0)
5607 ret = gas_send_request(wpa_s, dst_addr, advproto, query);
5610 wpabuf_free(advproto);
5617 static int gas_response_get(struct wpa_supplicant *wpa_s, char *cmd, char *buf,
5624 size_t resp_len, start, requested_len;
5625 struct wpabuf *resp;
5628 used = hwaddr_aton2(cmd, addr);
5635 dialog_token = atoi(pos);
5637 if (wpa_s->last_gas_resp &&
5638 os_memcmp(addr, wpa_s->last_gas_addr, ETH_ALEN) == 0 &&
5639 dialog_token == wpa_s->last_gas_dialog_token)
5640 resp = wpa_s->last_gas_resp;
5641 else if (wpa_s->prev_gas_resp &&
5642 os_memcmp(addr, wpa_s->prev_gas_addr, ETH_ALEN) == 0 &&
5643 dialog_token == wpa_s->prev_gas_dialog_token)
5644 resp = wpa_s->prev_gas_resp;
5648 resp_len = wpabuf_len(resp);
5650 requested_len = resp_len;
5652 pos = os_strchr(pos, ' ');
5655 if (start > resp_len)
5656 return os_snprintf(buf, buflen, "FAIL-Invalid range");
5657 pos = os_strchr(pos, ',');
5661 requested_len = atoi(pos);
5662 if (start + requested_len > resp_len)
5663 return os_snprintf(buf, buflen, "FAIL-Invalid range");
5666 if (requested_len * 2 + 1 > buflen)
5667 return os_snprintf(buf, buflen, "FAIL-Too long response");
5669 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(resp) + start,
5672 if (start + requested_len == resp_len) {
5674 * Free memory by dropping the response after it has been
5677 if (resp == wpa_s->prev_gas_resp) {
5678 wpabuf_free(wpa_s->prev_gas_resp);
5679 wpa_s->prev_gas_resp = NULL;
5681 wpabuf_free(wpa_s->last_gas_resp);
5682 wpa_s->last_gas_resp = NULL;
5688 #endif /* CONFIG_INTERWORKING */
5693 static int get_hs20_anqp(struct wpa_supplicant *wpa_s, char *dst)
5695 u8 dst_addr[ETH_ALEN];
5700 used = hwaddr_aton2(dst, dst_addr);
5707 int num = atoi(pos);
5708 if (num <= 0 || num > 31)
5710 subtypes |= BIT(num);
5711 pos = os_strchr(pos + 1, ',');
5720 return hs20_anqp_send_req(wpa_s, dst_addr, subtypes, NULL, 0);
5724 static int hs20_nai_home_realm_list(struct wpa_supplicant *wpa_s,
5725 const u8 *addr, const char *realm)
5731 rlen = os_strlen(realm);
5733 buf = os_malloc(len);
5736 buf[0] = 1; /* NAI Home Realm Count */
5737 buf[1] = 0; /* Formatted in accordance with RFC 4282 */
5739 os_memcpy(buf + 3, realm, rlen);
5741 ret = hs20_anqp_send_req(wpa_s, addr,
5742 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
5751 static int hs20_get_nai_home_realm_list(struct wpa_supplicant *wpa_s,
5754 struct wpa_cred *cred = wpa_s->conf->cred;
5755 u8 dst_addr[ETH_ALEN];
5761 used = hwaddr_aton2(dst, dst_addr);
5765 while (dst[used] == ' ')
5767 if (os_strncmp(dst + used, "realm=", 6) == 0)
5768 return hs20_nai_home_realm_list(wpa_s, dst_addr,
5771 len = os_strlen(dst + used);
5773 if (len == 0 && cred && cred->realm)
5774 return hs20_nai_home_realm_list(wpa_s, dst_addr, cred->realm);
5779 buf = os_malloc(len);
5782 if (hexstr2bin(dst + used, buf, len) < 0) {
5787 ret = hs20_anqp_send_req(wpa_s, dst_addr,
5788 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
5796 static int hs20_icon_request(struct wpa_supplicant *wpa_s, char *cmd)
5798 u8 dst_addr[ETH_ALEN];
5802 used = hwaddr_aton2(cmd, dst_addr);
5806 while (cmd[used] == ' ')
5810 wpa_s->fetch_osu_icon_in_progress = 0;
5811 return hs20_anqp_send_req(wpa_s, dst_addr, BIT(HS20_STYPE_ICON_REQUEST),
5812 (u8 *) icon, os_strlen(icon));
5815 #endif /* CONFIG_HS20 */
5818 #ifdef CONFIG_AUTOSCAN
5820 static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant *wpa_s,
5823 enum wpa_states state = wpa_s->wpa_state;
5824 char *new_params = NULL;
5826 if (os_strlen(cmd) > 0) {
5827 new_params = os_strdup(cmd);
5828 if (new_params == NULL)
5832 os_free(wpa_s->conf->autoscan);
5833 wpa_s->conf->autoscan = new_params;
5835 if (wpa_s->conf->autoscan == NULL)
5836 autoscan_deinit(wpa_s);
5837 else if (state == WPA_DISCONNECTED || state == WPA_INACTIVE)
5838 autoscan_init(wpa_s, 1);
5839 else if (state == WPA_SCANNING)
5840 wpa_supplicant_reinit_autoscan(wpa_s);
5845 #endif /* CONFIG_AUTOSCAN */
5850 static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant *wpa_s, char *cmd)
5856 struct wpabuf *tfs_req = NULL;
5858 if (os_strncmp(cmd, "enter", 5) == 0)
5860 else if (os_strncmp(cmd, "exit", 4) == 0)
5865 pos = os_strstr(cmd, " interval=");
5867 intval = atoi(pos + 10);
5869 pos = os_strstr(cmd, " tfs_req=");
5874 end = os_strchr(pos, ' ');
5878 len = os_strlen(pos);
5882 tfs_req = wpabuf_alloc(len);
5883 if (tfs_req == NULL)
5885 if (hexstr2bin(pos, wpabuf_put(tfs_req, len), len) < 0) {
5886 wpabuf_free(tfs_req);
5891 ret = ieee802_11_send_wnmsleep_req(wpa_s, enter ? WNM_SLEEP_MODE_ENTER :
5892 WNM_SLEEP_MODE_EXIT, intval,
5894 wpabuf_free(tfs_req);
5900 static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant *wpa_s, char *cmd)
5904 query_reason = atoi(cmd);
5906 wpa_printf(MSG_DEBUG, "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d",
5909 return wnm_send_bss_transition_mgmt_query(wpa_s, query_reason);
5912 #endif /* CONFIG_WNM */
5915 static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf,
5918 struct wpa_signal_info si;
5922 ret = wpa_drv_signal_poll(wpa_s, &si);
5929 ret = os_snprintf(pos, end - pos, "RSSI=%d\nLINKSPEED=%d\n"
5930 "NOISE=%d\nFREQUENCY=%u\n",
5931 si.current_signal, si.current_txrate / 1000,
5932 si.current_noise, si.frequency);
5933 if (os_snprintf_error(end - pos, ret))
5937 if (si.chanwidth != CHAN_WIDTH_UNKNOWN) {
5938 ret = os_snprintf(pos, end - pos, "WIDTH=%s\n",
5939 channel_width_to_string(si.chanwidth));
5940 if (os_snprintf_error(end - pos, ret))
5945 if (si.center_frq1 > 0 && si.center_frq2 > 0) {
5946 ret = os_snprintf(pos, end - pos,
5947 "CENTER_FRQ1=%d\nCENTER_FRQ2=%d\n",
5948 si.center_frq1, si.center_frq2);
5949 if (os_snprintf_error(end - pos, ret))
5954 if (si.avg_signal) {
5955 ret = os_snprintf(pos, end - pos,
5956 "AVG_RSSI=%d\n", si.avg_signal);
5957 if (os_snprintf_error(end - pos, ret))
5966 static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant *wpa_s, char *buf,
5969 struct hostap_sta_driver_data sta;
5972 ret = wpa_drv_pktcnt_poll(wpa_s, &sta);
5976 ret = os_snprintf(buf, buflen, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
5977 sta.tx_packets, sta.tx_retry_failed, sta.rx_packets);
5978 if (os_snprintf_error(buflen, ret))
5985 static int wpa_supplicant_driver_cmd(struct wpa_supplicant *wpa_s, char *cmd,
5986 char *buf, size_t buflen)
5990 ret = wpa_drv_driver_cmd(wpa_s, cmd, buf, buflen);
5992 if (os_strncasecmp(cmd, "COUNTRY", 7) == 0) {
5993 struct p2p_data *p2p = wpa_s->global->p2p;
5996 country[0] = cmd[8];
5997 country[1] = cmd[9];
5999 p2p_set_country(p2p, country);
6002 ret = os_snprintf(buf, buflen, "%s\n", "OK");
6003 if (os_snprintf_error(buflen, ret))
6008 #endif /* ANDROID */
6011 static int wpa_supplicant_vendor_cmd(struct wpa_supplicant *wpa_s, char *cmd,
6012 char *buf, size_t buflen)
6017 unsigned int vendor_id, subcmd;
6018 struct wpabuf *reply;
6019 size_t data_len = 0;
6021 /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */
6022 vendor_id = strtoul(cmd, &pos, 16);
6026 subcmd = strtoul(pos, &pos, 10);
6029 if (!isblank(*pos++))
6031 data_len = os_strlen(pos);
6036 data = os_malloc(data_len);
6040 if (hexstr2bin(pos, data, data_len)) {
6041 wpa_printf(MSG_DEBUG,
6042 "Vendor command: wrong parameter format");
6048 reply = wpabuf_alloc((buflen - 1) / 2);
6054 ret = wpa_drv_vendor_cmd(wpa_s, vendor_id, subcmd, data, data_len,
6058 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(reply),
6068 static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s)
6070 wpa_dbg(wpa_s, MSG_DEBUG, "Flush all wpa_supplicant state");
6073 wpas_p2p_cancel(wpa_s);
6074 wpas_p2p_stop_find(wpa_s);
6075 p2p_ctrl_flush(wpa_s);
6076 wpas_p2p_group_remove(wpa_s, "*");
6077 wpas_p2p_service_flush(wpa_s);
6078 wpa_s->global->p2p_disabled = 0;
6079 wpa_s->global->p2p_per_sta_psk = 0;
6080 wpa_s->conf->num_sec_device_types = 0;
6081 wpa_s->p2p_disable_ip_addr_req = 0;
6082 os_free(wpa_s->global->p2p_go_avoid_freq.range);
6083 wpa_s->global->p2p_go_avoid_freq.range = NULL;
6084 #endif /* CONFIG_P2P */
6086 #ifdef CONFIG_WPS_TESTING
6087 wps_version_number = 0x20;
6088 wps_testing_dummy_cred = 0;
6089 wps_corrupt_pkhash = 0;
6090 #endif /* CONFIG_WPS_TESTING */
6092 wpa_s->wps_fragment_size = 0;
6093 wpas_wps_cancel(wpa_s);
6094 wps_registrar_flush(wpa_s->wps->registrar);
6095 #endif /* CONFIG_WPS */
6096 wpa_s->after_wps = 0;
6097 wpa_s->known_wps_freq = 0;
6100 #ifdef CONFIG_TDLS_TESTING
6101 extern unsigned int tdls_testing;
6103 #endif /* CONFIG_TDLS_TESTING */
6104 wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL);
6105 wpa_tdls_enable(wpa_s->wpa, 1);
6106 #endif /* CONFIG_TDLS */
6108 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, wpa_s, NULL);
6109 wpa_supplicant_stop_countermeasures(wpa_s, NULL);
6111 wpa_s->no_keep_alive = 0;
6113 os_free(wpa_s->disallow_aps_bssid);
6114 wpa_s->disallow_aps_bssid = NULL;
6115 wpa_s->disallow_aps_bssid_count = 0;
6116 os_free(wpa_s->disallow_aps_ssid);
6117 wpa_s->disallow_aps_ssid = NULL;
6118 wpa_s->disallow_aps_ssid_count = 0;
6120 wpa_s->set_sta_uapsd = 0;
6121 wpa_s->sta_uapsd = 0;
6123 wpa_drv_radio_disable(wpa_s, 0);
6125 wpa_bss_flush(wpa_s);
6126 wpa_blacklist_clear(wpa_s);
6127 wpa_s->extra_blacklist_count = 0;
6128 wpa_supplicant_ctrl_iface_remove_network(wpa_s, "all");
6129 wpa_supplicant_ctrl_iface_remove_cred(wpa_s, "all");
6130 wpa_config_flush_blobs(wpa_s->conf);
6131 wpa_s->conf->auto_interworking = 0;
6132 wpa_s->conf->okc = 0;
6134 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
6135 rsn_preauth_deinit(wpa_s->wpa);
6137 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, 43200);
6138 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, 70);
6139 wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, 60);
6140 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
6142 radio_remove_works(wpa_s, NULL, 1);
6143 wpa_s->ext_work_in_progress = 0;
6145 wpa_s->next_ssid = NULL;
6147 #ifdef CONFIG_INTERWORKING
6148 hs20_cancel_fetch_osu(wpa_s);
6149 #endif /* CONFIG_INTERWORKING */
6151 wpa_s->ext_mgmt_frame_handling = 0;
6152 wpa_s->ext_eapol_frame_io = 0;
6153 #ifdef CONFIG_TESTING_OPTIONS
6154 wpa_s->extra_roc_dur = 0;
6155 #endif /* CONFIG_TESTING_OPTIONS */
6157 wpa_s->disconnected = 0;
6158 os_free(wpa_s->next_scan_freqs);
6159 wpa_s->next_scan_freqs = NULL;
6163 static int wpas_ctrl_radio_work_show(struct wpa_supplicant *wpa_s,
6164 char *buf, size_t buflen)
6166 struct wpa_radio_work *work;
6168 struct os_reltime now, diff;
6173 os_get_reltime(&now);
6175 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
6179 os_reltime_sub(&now, &work->time, &diff);
6180 ret = os_snprintf(pos, end - pos, "%s@%s:%u:%u:%ld.%06ld\n",
6181 work->type, work->wpa_s->ifname, work->freq,
6182 work->started, diff.sec, diff.usec);
6183 if (os_snprintf_error(end - pos, ret))
6192 static void wpas_ctrl_radio_work_timeout(void *eloop_ctx, void *timeout_ctx)
6194 struct wpa_radio_work *work = eloop_ctx;
6195 struct wpa_external_work *ework = work->ctx;
6197 wpa_dbg(work->wpa_s, MSG_DEBUG,
6198 "Timing out external radio work %u (%s)",
6199 ework->id, work->type);
6200 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_TIMEOUT "%u", ework->id);
6201 work->wpa_s->ext_work_in_progress = 0;
6202 radio_work_done(work);
6207 static void wpas_ctrl_radio_work_cb(struct wpa_radio_work *work, int deinit)
6209 struct wpa_external_work *ework = work->ctx;
6213 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
6220 wpa_dbg(work->wpa_s, MSG_DEBUG, "Starting external radio work %u (%s)",
6221 ework->id, ework->type);
6222 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_START "%u", ework->id);
6223 work->wpa_s->ext_work_in_progress = 1;
6224 if (!ework->timeout)
6225 ework->timeout = 10;
6226 eloop_register_timeout(ework->timeout, 0, wpas_ctrl_radio_work_timeout,
6231 static int wpas_ctrl_radio_work_add(struct wpa_supplicant *wpa_s, char *cmd,
6232 char *buf, size_t buflen)
6234 struct wpa_external_work *ework;
6238 unsigned int freq = 0;
6240 /* format: <name> [freq=<MHz>] [timeout=<seconds>] */
6242 ework = os_zalloc(sizeof(*ework));
6246 pos = os_strchr(cmd, ' ');
6248 type_len = pos - cmd;
6251 pos2 = os_strstr(pos, "freq=");
6253 freq = atoi(pos2 + 5);
6255 pos2 = os_strstr(pos, "timeout=");
6257 ework->timeout = atoi(pos2 + 8);
6259 type_len = os_strlen(cmd);
6261 if (4 + type_len >= sizeof(ework->type))
6262 type_len = sizeof(ework->type) - 4 - 1;
6263 os_strlcpy(ework->type, "ext:", sizeof(ework->type));
6264 os_memcpy(ework->type + 4, cmd, type_len);
6265 ework->type[4 + type_len] = '\0';
6267 wpa_s->ext_work_id++;
6268 if (wpa_s->ext_work_id == 0)
6269 wpa_s->ext_work_id++;
6270 ework->id = wpa_s->ext_work_id;
6272 if (radio_add_work(wpa_s, freq, ework->type, 0, wpas_ctrl_radio_work_cb,
6278 ret = os_snprintf(buf, buflen, "%u", ework->id);
6279 if (os_snprintf_error(buflen, ret))
6285 static int wpas_ctrl_radio_work_done(struct wpa_supplicant *wpa_s, char *cmd)
6287 struct wpa_radio_work *work;
6288 unsigned int id = atoi(cmd);
6290 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
6292 struct wpa_external_work *ework;
6294 if (os_strncmp(work->type, "ext:", 4) != 0)
6297 if (id && ework->id != id)
6299 wpa_dbg(wpa_s, MSG_DEBUG,
6300 "Completed external radio work %u (%s)",
6301 ework->id, ework->type);
6302 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, work, NULL);
6303 wpa_s->ext_work_in_progress = 0;
6304 radio_work_done(work);
6306 return 3; /* "OK\n" */
6313 static int wpas_ctrl_radio_work(struct wpa_supplicant *wpa_s, char *cmd,
6314 char *buf, size_t buflen)
6316 if (os_strcmp(cmd, "show") == 0)
6317 return wpas_ctrl_radio_work_show(wpa_s, buf, buflen);
6318 if (os_strncmp(cmd, "add ", 4) == 0)
6319 return wpas_ctrl_radio_work_add(wpa_s, cmd + 4, buf, buflen);
6320 if (os_strncmp(cmd, "done ", 5) == 0)
6321 return wpas_ctrl_radio_work_done(wpa_s, cmd + 4);
6326 void wpas_ctrl_radio_work_flush(struct wpa_supplicant *wpa_s)
6328 struct wpa_radio_work *work, *tmp;
6330 if (!wpa_s || !wpa_s->radio)
6333 dl_list_for_each_safe(work, tmp, &wpa_s->radio->work,
6334 struct wpa_radio_work, list) {
6335 struct wpa_external_work *ework;
6337 if (os_strncmp(work->type, "ext:", 4) != 0)
6340 wpa_dbg(wpa_s, MSG_DEBUG,
6341 "Flushing%s external radio work %u (%s)",
6342 work->started ? " started" : "", ework->id,
6345 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
6347 radio_work_done(work);
6353 static void wpas_ctrl_eapol_response(void *eloop_ctx, void *timeout_ctx)
6355 struct wpa_supplicant *wpa_s = eloop_ctx;
6356 eapol_sm_notify_ctrl_response(wpa_s->eapol);
6360 static int scan_id_list_parse(struct wpa_supplicant *wpa_s, const char *value,
6361 unsigned int *scan_id_count, int scan_id[])
6363 const char *pos = value;
6366 if (*pos == ' ' || *pos == '\0')
6368 if (*scan_id_count == MAX_SCAN_ID)
6370 scan_id[(*scan_id_count)++] = atoi(pos);
6371 pos = os_strchr(pos, ',');
6380 static void wpas_ctrl_scan(struct wpa_supplicant *wpa_s, char *params,
6381 char *reply, int reply_size, int *reply_len)
6384 unsigned int manual_scan_passive = 0;
6385 unsigned int manual_scan_use_id = 0;
6386 unsigned int manual_scan_only_new = 0;
6387 unsigned int scan_only = 0;
6388 unsigned int scan_id_count = 0;
6389 int scan_id[MAX_SCAN_ID];
6390 void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
6391 struct wpa_scan_results *scan_res);
6392 int *manual_scan_freqs = NULL;
6394 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
6399 if (radio_work_pending(wpa_s, "scan")) {
6400 wpa_printf(MSG_DEBUG,
6401 "Pending scan scheduled - reject new request");
6402 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
6407 if (os_strncasecmp(params, "TYPE=ONLY", 9) == 0)
6410 pos = os_strstr(params, "freq=");
6412 manual_scan_freqs = freq_range_to_channel_list(wpa_s,
6414 if (manual_scan_freqs == NULL) {
6420 pos = os_strstr(params, "passive=");
6422 manual_scan_passive = !!atoi(pos + 8);
6424 pos = os_strstr(params, "use_id=");
6426 manual_scan_use_id = atoi(pos + 7);
6428 pos = os_strstr(params, "only_new=1");
6430 manual_scan_only_new = 1;
6432 pos = os_strstr(params, "scan_id=");
6433 if (pos && scan_id_list_parse(wpa_s, pos + 8, &scan_id_count,
6441 scan_res_handler = scan_only_handler;
6442 else if (wpa_s->scan_res_handler == scan_only_handler)
6443 scan_res_handler = NULL;
6445 scan_res_handler = wpa_s->scan_res_handler;
6447 if (!wpa_s->sched_scanning && !wpa_s->scanning &&
6448 ((wpa_s->wpa_state <= WPA_SCANNING) ||
6449 (wpa_s->wpa_state == WPA_COMPLETED))) {
6450 wpa_s->manual_scan_passive = manual_scan_passive;
6451 wpa_s->manual_scan_use_id = manual_scan_use_id;
6452 wpa_s->manual_scan_only_new = manual_scan_only_new;
6453 wpa_s->scan_id_count = scan_id_count;
6454 os_memcpy(wpa_s->scan_id, scan_id, scan_id_count * sizeof(int));
6455 wpa_s->scan_res_handler = scan_res_handler;
6456 os_free(wpa_s->manual_scan_freqs);
6457 wpa_s->manual_scan_freqs = manual_scan_freqs;
6458 manual_scan_freqs = NULL;
6460 wpa_s->normal_scans = 0;
6461 wpa_s->scan_req = MANUAL_SCAN_REQ;
6462 wpa_s->after_wps = 0;
6463 wpa_s->known_wps_freq = 0;
6464 wpa_supplicant_req_scan(wpa_s, 0, 0);
6465 if (wpa_s->manual_scan_use_id) {
6466 wpa_s->manual_scan_id++;
6467 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
6468 wpa_s->manual_scan_id);
6469 *reply_len = os_snprintf(reply, reply_size, "%u\n",
6470 wpa_s->manual_scan_id);
6472 } else if (wpa_s->sched_scanning) {
6473 wpa_s->manual_scan_passive = manual_scan_passive;
6474 wpa_s->manual_scan_use_id = manual_scan_use_id;
6475 wpa_s->manual_scan_only_new = manual_scan_only_new;
6476 wpa_s->scan_id_count = scan_id_count;
6477 os_memcpy(wpa_s->scan_id, scan_id, scan_id_count * sizeof(int));
6478 wpa_s->scan_res_handler = scan_res_handler;
6479 os_free(wpa_s->manual_scan_freqs);
6480 wpa_s->manual_scan_freqs = manual_scan_freqs;
6481 manual_scan_freqs = NULL;
6483 wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to allow requested full scan to proceed");
6484 wpa_supplicant_cancel_sched_scan(wpa_s);
6485 wpa_s->scan_req = MANUAL_SCAN_REQ;
6486 wpa_supplicant_req_scan(wpa_s, 0, 0);
6487 if (wpa_s->manual_scan_use_id) {
6488 wpa_s->manual_scan_id++;
6489 *reply_len = os_snprintf(reply, reply_size, "%u\n",
6490 wpa_s->manual_scan_id);
6491 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
6492 wpa_s->manual_scan_id);
6495 wpa_printf(MSG_DEBUG, "Ongoing scan action - reject new request");
6496 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
6500 os_free(manual_scan_freqs);
6504 #ifdef CONFIG_TESTING_OPTIONS
6506 static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant *wpa_s,
6507 unsigned int freq, const u8 *dst,
6508 const u8 *src, const u8 *bssid,
6509 const u8 *data, size_t data_len,
6510 enum offchannel_send_action_result
6513 wpa_msg(wpa_s, MSG_INFO, "MGMT-TX-STATUS freq=%u dst=" MACSTR
6514 " src=" MACSTR " bssid=" MACSTR " result=%s",
6515 freq, MAC2STR(dst), MAC2STR(src), MAC2STR(bssid),
6516 result == OFFCHANNEL_SEND_ACTION_SUCCESS ?
6517 "SUCCESS" : (result == OFFCHANNEL_SEND_ACTION_NO_ACK ?
6518 "NO_ACK" : "FAILED"));
6522 static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant *wpa_s, char *cmd)
6526 u8 *buf, da[ETH_ALEN], bssid[ETH_ALEN];
6528 int freq = 0, no_cck = 0, wait_time = 0;
6530 /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1]
6531 * <action=Action frame payload> */
6533 wpa_printf(MSG_DEBUG, "External MGMT TX: %s", cmd);
6536 used = hwaddr_aton2(pos, da);
6542 used = hwaddr_aton2(pos, bssid);
6547 param = os_strstr(pos, " freq=");
6553 param = os_strstr(pos, " no_cck=");
6556 no_cck = atoi(param);
6559 param = os_strstr(pos, " wait_time=");
6562 wait_time = atoi(param);
6565 param = os_strstr(pos, " action=");
6570 len = os_strlen(param);
6575 buf = os_malloc(len);
6579 if (hexstr2bin(param, buf, len) < 0) {
6584 res = offchannel_send_action(wpa_s, freq, da, wpa_s->own_addr, bssid,
6585 buf, len, wait_time,
6586 wpas_ctrl_iface_mgmt_tx_cb, no_cck);
6592 static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant *wpa_s)
6594 wpa_printf(MSG_DEBUG, "External MGMT TX - done waiting");
6595 offchannel_send_action_done(wpa_s);
6599 static int wpas_ctrl_iface_driver_event(struct wpa_supplicant *wpa_s, char *cmd)
6602 union wpa_event_data event;
6603 enum wpa_event_type ev;
6605 /* <event name> [parameters..] */
6607 wpa_dbg(wpa_s, MSG_DEBUG, "Testing - external driver event: %s", cmd);
6610 param = os_strchr(pos, ' ');
6614 os_memset(&event, 0, sizeof(event));
6616 if (os_strcmp(cmd, "INTERFACE_ENABLED") == 0) {
6617 ev = EVENT_INTERFACE_ENABLED;
6618 } else if (os_strcmp(cmd, "INTERFACE_DISABLED") == 0) {
6619 ev = EVENT_INTERFACE_DISABLED;
6620 } else if (os_strcmp(cmd, "AVOID_FREQUENCIES") == 0) {
6621 ev = EVENT_AVOID_FREQUENCIES;
6624 if (freq_range_list_parse(&event.freq_range, param) < 0)
6626 wpa_supplicant_event(wpa_s, ev, &event);
6627 os_free(event.freq_range.range);
6630 wpa_dbg(wpa_s, MSG_DEBUG, "Testing - unknown driver event: %s",
6635 wpa_supplicant_event(wpa_s, ev, &event);
6641 static int wpas_ctrl_iface_eapol_rx(struct wpa_supplicant *wpa_s, char *cmd)
6644 u8 src[ETH_ALEN], *buf;
6648 wpa_printf(MSG_DEBUG, "External EAPOL RX: %s", cmd);
6651 used = hwaddr_aton2(pos, src);
6658 len = os_strlen(pos);
6663 buf = os_malloc(len);
6667 if (hexstr2bin(pos, buf, len) < 0) {
6672 wpa_supplicant_rx_eapol(wpa_s, src, buf, len);
6679 static u16 ipv4_hdr_checksum(const void *buf, size_t len)
6683 const u16 *pos = buf;
6685 for (i = 0; i < len / 2; i++)
6689 sum = (sum & 0xffff) + (sum >> 16);
6691 return sum ^ 0xffff;
6695 #define HWSIM_PACKETLEN 1500
6696 #define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header))
6698 void wpas_data_test_rx(void *ctx, const u8 *src_addr, const u8 *buf, size_t len)
6700 struct wpa_supplicant *wpa_s = ctx;
6701 const struct ether_header *eth;
6702 const struct iphdr *ip;
6706 if (len != HWSIM_PACKETLEN)
6709 eth = (const struct ether_header *) buf;
6710 ip = (const struct iphdr *) (eth + 1);
6711 pos = (const u8 *) (ip + 1);
6713 if (ip->ihl != 5 || ip->version != 4 ||
6714 ntohs(ip->tot_len) != HWSIM_IP_LEN)
6717 for (i = 0; i < HWSIM_IP_LEN - sizeof(*ip); i++) {
6723 wpa_msg(wpa_s, MSG_INFO, "DATA-TEST-RX " MACSTR " " MACSTR,
6724 MAC2STR(eth->ether_dhost), MAC2STR(eth->ether_shost));
6728 static int wpas_ctrl_iface_data_test_config(struct wpa_supplicant *wpa_s,
6731 int enabled = atoi(cmd);
6734 if (wpa_s->l2_test) {
6735 l2_packet_deinit(wpa_s->l2_test);
6736 wpa_s->l2_test = NULL;
6737 wpa_dbg(wpa_s, MSG_DEBUG, "test data: Disabled");
6745 wpa_s->l2_test = l2_packet_init(wpa_s->ifname, wpa_s->own_addr,
6746 ETHERTYPE_IP, wpas_data_test_rx,
6748 if (wpa_s->l2_test == NULL)
6751 wpa_dbg(wpa_s, MSG_DEBUG, "test data: Enabled");
6757 static int wpas_ctrl_iface_data_test_tx(struct wpa_supplicant *wpa_s, char *cmd)
6759 u8 dst[ETH_ALEN], src[ETH_ALEN];
6764 u8 buf[HWSIM_PACKETLEN];
6765 struct ether_header *eth;
6770 if (wpa_s->l2_test == NULL)
6773 /* format: <dst> <src> <tos> */
6776 used = hwaddr_aton2(pos, dst);
6782 used = hwaddr_aton2(pos, src);
6787 val = strtol(pos, NULL, 0);
6788 if (val < 0 || val > 0xff)
6792 eth = (struct ether_header *) buf;
6793 os_memcpy(eth->ether_dhost, dst, ETH_ALEN);
6794 os_memcpy(eth->ether_shost, src, ETH_ALEN);
6795 eth->ether_type = htons(ETHERTYPE_IP);
6796 ip = (struct iphdr *) (eth + 1);
6797 os_memset(ip, 0, sizeof(*ip));
6802 ip->tot_len = htons(HWSIM_IP_LEN);
6804 ip->saddr = htonl(192 << 24 | 168 << 16 | 1 << 8 | 1);
6805 ip->daddr = htonl(192 << 24 | 168 << 16 | 1 << 8 | 2);
6806 ip->check = ipv4_hdr_checksum(ip, sizeof(*ip));
6807 dpos = (u8 *) (ip + 1);
6808 for (i = 0; i < HWSIM_IP_LEN - sizeof(*ip); i++)
6811 if (l2_packet_send(wpa_s->l2_test, dst, ETHERTYPE_IP, buf,
6812 HWSIM_PACKETLEN) < 0)
6815 wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX dst=" MACSTR " src=" MACSTR
6816 " tos=0x%x", MAC2STR(dst), MAC2STR(src), tos);
6822 static int wpas_ctrl_iface_data_test_frame(struct wpa_supplicant *wpa_s,
6826 struct ether_header *eth;
6827 struct l2_packet_data *l2 = NULL;
6832 len = os_strlen(cmd);
6833 if (len & 1 || len < ETH_HLEN * 2)
6837 buf = os_malloc(len);
6841 if (hexstr2bin(cmd, buf, len) < 0)
6844 eth = (struct ether_header *) buf;
6845 ethertype = ntohs(eth->ether_type);
6847 l2 = l2_packet_init(wpa_s->ifname, wpa_s->own_addr, ethertype,
6848 wpas_data_test_rx, wpa_s, 1);
6852 res = l2_packet_send(l2, eth->ether_dhost, ethertype, buf, len);
6853 wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX frame res=%d", res);
6856 l2_packet_deinit(l2);
6859 return res < 0 ? -1 : 0;
6862 #endif /* CONFIG_TESTING_OPTIONS */
6865 static void wpas_ctrl_vendor_elem_update(struct wpa_supplicant *wpa_s)
6870 wpa_printf(MSG_DEBUG, "Update vendor elements");
6872 for (i = 0; i < NUM_VENDOR_ELEM_FRAMES; i++) {
6873 if (wpa_s->vendor_elem[i]) {
6876 res = os_snprintf(buf, sizeof(buf), "frame[%u]", i);
6877 if (!os_snprintf_error(sizeof(buf), res)) {
6878 wpa_hexdump_buf(MSG_DEBUG, buf,
6879 wpa_s->vendor_elem[i]);
6885 if (wpa_s->parent == wpa_s &&
6886 wpa_s->global->p2p &&
6887 !wpa_s->global->p2p_disabled)
6888 p2p_set_vendor_elems(wpa_s->global->p2p, wpa_s->vendor_elem);
6889 #endif /* CONFIG_P2P */
6893 static struct wpa_supplicant *
6894 wpas_ctrl_vendor_elem_iface(struct wpa_supplicant *wpa_s,
6895 enum wpa_vendor_elem_frame frame)
6899 case VENDOR_ELEM_PROBE_REQ_P2P:
6900 case VENDOR_ELEM_PROBE_RESP_P2P:
6901 case VENDOR_ELEM_PROBE_RESP_P2P_GO:
6902 case VENDOR_ELEM_BEACON_P2P_GO:
6903 case VENDOR_ELEM_P2P_PD_REQ:
6904 case VENDOR_ELEM_P2P_PD_RESP:
6905 case VENDOR_ELEM_P2P_GO_NEG_REQ:
6906 case VENDOR_ELEM_P2P_GO_NEG_RESP:
6907 case VENDOR_ELEM_P2P_GO_NEG_CONF:
6908 case VENDOR_ELEM_P2P_INV_REQ:
6909 case VENDOR_ELEM_P2P_INV_RESP:
6910 case VENDOR_ELEM_P2P_ASSOC_REQ:
6911 return wpa_s->parent;
6912 #endif /* CONFIG_P2P */
6919 static int wpas_ctrl_vendor_elem_add(struct wpa_supplicant *wpa_s, char *cmd)
6925 struct ieee802_11_elems elems;
6928 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
6930 wpa_s = wpas_ctrl_vendor_elem_iface(wpa_s, frame);
6932 pos = os_strchr(pos, ' ');
6937 len = os_strlen(pos);
6944 buf = wpabuf_alloc(len);
6948 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
6953 if (ieee802_11_parse_elems(wpabuf_head_u8(buf), len, &elems, 0) ==
6959 if (wpa_s->vendor_elem[frame] == NULL) {
6960 wpa_s->vendor_elem[frame] = buf;
6961 wpas_ctrl_vendor_elem_update(wpa_s);
6965 if (wpabuf_resize(&wpa_s->vendor_elem[frame], len) < 0) {
6970 wpabuf_put_buf(wpa_s->vendor_elem[frame], buf);
6972 wpas_ctrl_vendor_elem_update(wpa_s);
6978 static int wpas_ctrl_vendor_elem_get(struct wpa_supplicant *wpa_s, char *cmd,
6979 char *buf, size_t buflen)
6981 int frame = atoi(cmd);
6983 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
6985 wpa_s = wpas_ctrl_vendor_elem_iface(wpa_s, frame);
6987 if (wpa_s->vendor_elem[frame] == NULL)
6990 return wpa_snprintf_hex(buf, buflen,
6991 wpabuf_head_u8(wpa_s->vendor_elem[frame]),
6992 wpabuf_len(wpa_s->vendor_elem[frame]));
6996 static int wpas_ctrl_vendor_elem_remove(struct wpa_supplicant *wpa_s, char *cmd)
7002 struct ieee802_11_elems elems;
7006 if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
7008 wpa_s = wpas_ctrl_vendor_elem_iface(wpa_s, frame);
7010 pos = os_strchr(pos, ' ');
7016 wpabuf_free(wpa_s->vendor_elem[frame]);
7017 wpa_s->vendor_elem[frame] = NULL;
7018 wpas_ctrl_vendor_elem_update(wpa_s);
7022 if (wpa_s->vendor_elem[frame] == NULL)
7025 len = os_strlen(pos);
7032 buf = os_malloc(len);
7036 if (hexstr2bin(pos, buf, len) < 0) {
7041 if (ieee802_11_parse_elems(buf, len, &elems, 0) == ParseFailed) {
7046 ie = wpabuf_mhead_u8(wpa_s->vendor_elem[frame]);
7047 end = ie + wpabuf_len(wpa_s->vendor_elem[frame]);
7049 for (; ie + 1 < end; ie += 2 + ie[1]) {
7052 if (os_memcmp(ie, buf, len) != 0)
7055 if (wpabuf_len(wpa_s->vendor_elem[frame]) == len) {
7056 wpabuf_free(wpa_s->vendor_elem[frame]);
7057 wpa_s->vendor_elem[frame] = NULL;
7059 os_memmove(ie, ie + len,
7061 wpa_s->vendor_elem[frame]->used -= len;
7064 wpas_ctrl_vendor_elem_update(wpa_s);
7074 static void wpas_ctrl_neighbor_rep_cb(void *ctx, struct wpabuf *neighbor_rep)
7076 struct wpa_supplicant *wpa_s = ctx;
7079 wpa_msg_ctrl(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_RXED
7081 (unsigned int) wpabuf_len(neighbor_rep));
7082 wpabuf_free(neighbor_rep);
7084 wpa_msg_ctrl(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_FAILED);
7089 static int wpas_ctrl_iface_send_neigbor_rep(struct wpa_supplicant *wpa_s,
7092 struct wpa_ssid ssid;
7093 struct wpa_ssid *ssid_p = NULL;
7096 if (os_strncmp(cmd, " ssid=", 6) == 0) {
7097 ssid.ssid_len = os_strlen(cmd + 6);
7098 if (ssid.ssid_len > 32)
7100 ssid.ssid = (u8 *) (cmd + 6);
7104 ret = wpas_rrm_send_neighbor_rep_request(wpa_s, ssid_p,
7105 wpas_ctrl_neighbor_rep_cb,
7112 static int wpas_ctrl_iface_erp_flush(struct wpa_supplicant *wpa_s)
7114 eapol_sm_erp_flush(wpa_s->eapol);
7119 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
7120 char *buf, size_t *resp_len)
7123 const int reply_size = 4096;
7126 if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 ||
7127 os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
7128 if (wpa_debug_show_keys)
7129 wpa_dbg(wpa_s, MSG_DEBUG,
7130 "Control interface command '%s'", buf);
7132 wpa_dbg(wpa_s, MSG_DEBUG,
7133 "Control interface command '%s [REMOVED]'",
7134 os_strncmp(buf, WPA_CTRL_RSP,
7135 os_strlen(WPA_CTRL_RSP)) == 0 ?
7136 WPA_CTRL_RSP : "SET_NETWORK");
7137 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ", 16) == 0 ||
7138 os_strncmp(buf, "NFC_REPORT_HANDOVER", 19) == 0) {
7139 wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface",
7140 (const u8 *) buf, os_strlen(buf));
7142 int level = MSG_DEBUG;
7143 if (os_strcmp(buf, "PING") == 0)
7144 level = MSG_EXCESSIVE;
7145 wpa_dbg(wpa_s, level, "Control interface command '%s'", buf);
7148 reply = os_malloc(reply_size);
7149 if (reply == NULL) {
7154 os_memcpy(reply, "OK\n", 3);
7157 if (os_strcmp(buf, "PING") == 0) {
7158 os_memcpy(reply, "PONG\n", 5);
7160 } else if (os_strcmp(buf, "IFNAME") == 0) {
7161 reply_len = os_strlen(wpa_s->ifname);
7162 os_memcpy(reply, wpa_s->ifname, reply_len);
7163 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
7164 if (wpa_debug_reopen_file() < 0)
7166 } else if (os_strncmp(buf, "NOTE ", 5) == 0) {
7167 wpa_printf(MSG_INFO, "NOTE: %s", buf + 5);
7168 } else if (os_strcmp(buf, "MIB") == 0) {
7169 reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size);
7170 if (reply_len >= 0) {
7171 reply_len += eapol_sm_get_mib(wpa_s->eapol,
7173 reply_size - reply_len);
7175 } else if (os_strncmp(buf, "STATUS", 6) == 0) {
7176 reply_len = wpa_supplicant_ctrl_iface_status(
7177 wpa_s, buf + 6, reply, reply_size);
7178 } else if (os_strcmp(buf, "PMKSA") == 0) {
7179 reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, reply,
7181 } else if (os_strcmp(buf, "PMKSA_FLUSH") == 0) {
7182 wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
7183 } else if (os_strncmp(buf, "SET ", 4) == 0) {
7184 if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4))
7186 } else if (os_strncmp(buf, "GET ", 4) == 0) {
7187 reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4,
7189 } else if (os_strcmp(buf, "LOGON") == 0) {
7190 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
7191 } else if (os_strcmp(buf, "LOGOFF") == 0) {
7192 eapol_sm_notify_logoff(wpa_s->eapol, TRUE);
7193 } else if (os_strcmp(buf, "REASSOCIATE") == 0) {
7194 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
7197 wpas_request_connection(wpa_s);
7198 } else if (os_strcmp(buf, "REATTACH") == 0) {
7199 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED ||
7200 !wpa_s->current_ssid)
7203 wpa_s->reattach = 1;
7204 wpas_request_connection(wpa_s);
7206 } else if (os_strcmp(buf, "RECONNECT") == 0) {
7207 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
7209 else if (wpa_s->disconnected)
7210 wpas_request_connection(wpa_s);
7211 #ifdef IEEE8021X_EAPOL
7212 } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) {
7213 if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8))
7215 #endif /* IEEE8021X_EAPOL */
7216 #ifdef CONFIG_PEERKEY
7217 } else if (os_strncmp(buf, "STKSTART ", 9) == 0) {
7218 if (wpa_supplicant_ctrl_iface_stkstart(wpa_s, buf + 9))
7220 #endif /* CONFIG_PEERKEY */
7221 #ifdef CONFIG_IEEE80211R
7222 } else if (os_strncmp(buf, "FT_DS ", 6) == 0) {
7223 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6))
7225 #endif /* CONFIG_IEEE80211R */
7227 } else if (os_strcmp(buf, "WPS_PBC") == 0) {
7228 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL);
7230 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
7234 } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) {
7235 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8);
7237 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
7241 } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {
7242 reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8,
7245 } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) {
7246 reply_len = wpa_supplicant_ctrl_iface_wps_check_pin(
7247 wpa_s, buf + 14, reply, reply_size);
7248 } else if (os_strcmp(buf, "WPS_CANCEL") == 0) {
7249 if (wpas_wps_cancel(wpa_s))
7251 #ifdef CONFIG_WPS_NFC
7252 } else if (os_strcmp(buf, "WPS_NFC") == 0) {
7253 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, NULL))
7255 } else if (os_strncmp(buf, "WPS_NFC ", 8) == 0) {
7256 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, buf + 8))
7258 } else if (os_strncmp(buf, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
7259 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_config_token(
7260 wpa_s, buf + 21, reply, reply_size);
7261 } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) {
7262 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_token(
7263 wpa_s, buf + 14, reply, reply_size);
7264 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) {
7265 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s,
7268 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
7269 reply_len = wpas_ctrl_nfc_get_handover_req(
7270 wpa_s, buf + 21, reply, reply_size);
7271 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
7272 reply_len = wpas_ctrl_nfc_get_handover_sel(
7273 wpa_s, buf + 21, reply, reply_size);
7274 } else if (os_strncmp(buf, "NFC_REPORT_HANDOVER ", 20) == 0) {
7275 if (wpas_ctrl_nfc_report_handover(wpa_s, buf + 20))
7277 #endif /* CONFIG_WPS_NFC */
7278 } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) {
7279 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8))
7282 } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) {
7283 reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin(
7284 wpa_s, buf + 11, reply, reply_size);
7285 #endif /* CONFIG_AP */
7286 #ifdef CONFIG_WPS_ER
7287 } else if (os_strcmp(buf, "WPS_ER_START") == 0) {
7288 if (wpas_wps_er_start(wpa_s, NULL))
7290 } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) {
7291 if (wpas_wps_er_start(wpa_s, buf + 13))
7293 } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) {
7294 wpas_wps_er_stop(wpa_s);
7295 } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) {
7296 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11))
7298 } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) {
7299 int ret = wpas_wps_er_pbc(wpa_s, buf + 11);
7301 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
7303 } else if (ret == -3) {
7304 os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18);
7306 } else if (ret == -4) {
7307 os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20);
7311 } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) {
7312 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13))
7314 } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) {
7315 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s,
7318 } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) {
7319 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14))
7321 #ifdef CONFIG_WPS_NFC
7322 } else if (os_strncmp(buf, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
7323 reply_len = wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
7324 wpa_s, buf + 24, reply, reply_size);
7325 #endif /* CONFIG_WPS_NFC */
7326 #endif /* CONFIG_WPS_ER */
7327 #endif /* CONFIG_WPS */
7328 #ifdef CONFIG_IBSS_RSN
7329 } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) {
7330 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9))
7332 #endif /* CONFIG_IBSS_RSN */
7334 } else if (os_strncmp(buf, "MESH_INTERFACE_ADD ", 19) == 0) {
7335 reply_len = wpa_supplicant_ctrl_iface_mesh_interface_add(
7336 wpa_s, buf + 19, reply, reply_size);
7337 } else if (os_strcmp(buf, "MESH_INTERFACE_ADD") == 0) {
7338 reply_len = wpa_supplicant_ctrl_iface_mesh_interface_add(
7339 wpa_s, "", reply, reply_size);
7340 } else if (os_strncmp(buf, "MESH_GROUP_ADD ", 15) == 0) {
7341 if (wpa_supplicant_ctrl_iface_mesh_group_add(wpa_s, buf + 15))
7343 } else if (os_strncmp(buf, "MESH_GROUP_REMOVE ", 18) == 0) {
7344 if (wpa_supplicant_ctrl_iface_mesh_group_remove(wpa_s,
7347 #endif /* CONFIG_MESH */
7349 } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) {
7350 if (p2p_ctrl_find(wpa_s, buf + 9))
7352 } else if (os_strcmp(buf, "P2P_FIND") == 0) {
7353 if (p2p_ctrl_find(wpa_s, ""))
7355 } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) {
7356 wpas_p2p_stop_find(wpa_s);
7357 } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) {
7358 reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply,
7360 } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) {
7361 if (p2p_ctrl_listen(wpa_s, buf + 11))
7363 } else if (os_strcmp(buf, "P2P_LISTEN") == 0) {
7364 if (p2p_ctrl_listen(wpa_s, ""))
7366 } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) {
7367 if (wpas_p2p_group_remove(wpa_s, buf + 17))
7369 } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) {
7370 if (wpas_p2p_group_add(wpa_s, 0, 0, 0, 0))
7372 } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) {
7373 if (p2p_ctrl_group_add(wpa_s, buf + 14))
7375 } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) {
7376 if (p2p_ctrl_prov_disc(wpa_s, buf + 14))
7378 } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) {
7379 reply_len = p2p_get_passphrase(wpa_s, reply, reply_size);
7380 } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) {
7381 reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply,
7383 } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
7384 if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0)
7386 } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) {
7387 if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0)
7389 } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) {
7390 wpas_p2p_sd_service_update(wpa_s);
7391 } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
7392 if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0)
7394 } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) {
7395 wpas_p2p_service_flush(wpa_s);
7396 } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) {
7397 if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0)
7399 } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) {
7400 if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0)
7402 } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) {
7403 if (p2p_ctrl_reject(wpa_s, buf + 11) < 0)
7405 } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) {
7406 if (p2p_ctrl_invite(wpa_s, buf + 11) < 0)
7408 } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) {
7409 reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply,
7411 } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) {
7412 if (p2p_ctrl_set(wpa_s, buf + 8) < 0)
7414 } else if (os_strcmp(buf, "P2P_FLUSH") == 0) {
7415 p2p_ctrl_flush(wpa_s);
7416 } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) {
7417 if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0)
7419 } else if (os_strcmp(buf, "P2P_CANCEL") == 0) {
7420 if (wpas_p2p_cancel(wpa_s))
7422 } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) {
7423 if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0)
7425 } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) {
7426 if (p2p_ctrl_presence_req(wpa_s, "") < 0)
7428 } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) {
7429 if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0)
7431 } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) {
7432 if (p2p_ctrl_ext_listen(wpa_s, "") < 0)
7434 } else if (os_strncmp(buf, "P2P_REMOVE_CLIENT ", 18) == 0) {
7435 if (p2p_ctrl_remove_client(wpa_s, buf + 18) < 0)
7437 #endif /* CONFIG_P2P */
7438 #ifdef CONFIG_WIFI_DISPLAY
7439 } else if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0) {
7440 if (wifi_display_subelem_set(wpa_s->global, buf + 16) < 0)
7442 } else if (os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) {
7443 reply_len = wifi_display_subelem_get(wpa_s->global, buf + 16,
7445 #endif /* CONFIG_WIFI_DISPLAY */
7446 #ifdef CONFIG_INTERWORKING
7447 } else if (os_strcmp(buf, "FETCH_ANQP") == 0) {
7448 if (interworking_fetch_anqp(wpa_s) < 0)
7450 } else if (os_strcmp(buf, "STOP_FETCH_ANQP") == 0) {
7451 interworking_stop_fetch_anqp(wpa_s);
7452 } else if (os_strcmp(buf, "INTERWORKING_SELECT") == 0) {
7453 if (ctrl_interworking_select(wpa_s, NULL) < 0)
7455 } else if (os_strncmp(buf, "INTERWORKING_SELECT ", 20) == 0) {
7456 if (ctrl_interworking_select(wpa_s, buf + 20) < 0)
7458 } else if (os_strncmp(buf, "INTERWORKING_CONNECT ", 21) == 0) {
7459 if (ctrl_interworking_connect(wpa_s, buf + 21) < 0)
7461 } else if (os_strncmp(buf, "ANQP_GET ", 9) == 0) {
7462 if (get_anqp(wpa_s, buf + 9) < 0)
7464 } else if (os_strncmp(buf, "GAS_REQUEST ", 12) == 0) {
7465 if (gas_request(wpa_s, buf + 12) < 0)
7467 } else if (os_strncmp(buf, "GAS_RESPONSE_GET ", 17) == 0) {
7468 reply_len = gas_response_get(wpa_s, buf + 17, reply,
7470 #endif /* CONFIG_INTERWORKING */
7472 } else if (os_strncmp(buf, "HS20_ANQP_GET ", 14) == 0) {
7473 if (get_hs20_anqp(wpa_s, buf + 14) < 0)
7475 } else if (os_strncmp(buf, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
7476 if (hs20_get_nai_home_realm_list(wpa_s, buf + 29) < 0)
7478 } else if (os_strncmp(buf, "HS20_ICON_REQUEST ", 18) == 0) {
7479 if (hs20_icon_request(wpa_s, buf + 18) < 0)
7481 } else if (os_strcmp(buf, "FETCH_OSU") == 0) {
7482 if (hs20_fetch_osu(wpa_s) < 0)
7484 } else if (os_strcmp(buf, "CANCEL_FETCH_OSU") == 0) {
7485 hs20_cancel_fetch_osu(wpa_s);
7486 #endif /* CONFIG_HS20 */
7487 } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0)
7489 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
7490 wpa_s, buf + os_strlen(WPA_CTRL_RSP)))
7494 * Notify response from timeout to allow the control
7495 * interface response to be sent first.
7497 eloop_register_timeout(0, 0, wpas_ctrl_eapol_response,
7500 } else if (os_strcmp(buf, "RECONFIGURE") == 0) {
7501 if (wpa_supplicant_reload_configuration(wpa_s))
7503 } else if (os_strcmp(buf, "TERMINATE") == 0) {
7504 wpa_supplicant_terminate_proc(wpa_s->global);
7505 } else if (os_strncmp(buf, "BSSID ", 6) == 0) {
7506 if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6))
7508 } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) {
7509 reply_len = wpa_supplicant_ctrl_iface_blacklist(
7510 wpa_s, buf + 9, reply, reply_size);
7511 } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) {
7512 reply_len = wpa_supplicant_ctrl_iface_log_level(
7513 wpa_s, buf + 9, reply, reply_size);
7514 } else if (os_strncmp(buf, "LIST_NETWORKS ", 14) == 0) {
7515 reply_len = wpa_supplicant_ctrl_iface_list_networks(
7516 wpa_s, buf + 14, reply, reply_size);
7517 } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) {
7518 reply_len = wpa_supplicant_ctrl_iface_list_networks(
7519 wpa_s, NULL, reply, reply_size);
7520 } else if (os_strcmp(buf, "DISCONNECT") == 0) {
7522 wpa_s->sme.prev_bssid_set = 0;
7523 #endif /* CONFIG_SME */
7524 wpa_s->reassociate = 0;
7525 wpa_s->disconnected = 1;
7526 wpa_supplicant_cancel_sched_scan(wpa_s);
7527 wpa_supplicant_cancel_scan(wpa_s);
7528 wpa_supplicant_deauthenticate(wpa_s,
7529 WLAN_REASON_DEAUTH_LEAVING);
7530 } else if (os_strcmp(buf, "SCAN") == 0) {
7531 wpas_ctrl_scan(wpa_s, NULL, reply, reply_size, &reply_len);
7532 } else if (os_strncmp(buf, "SCAN ", 5) == 0) {
7533 wpas_ctrl_scan(wpa_s, buf + 5, reply, reply_size, &reply_len);
7534 } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) {
7535 reply_len = wpa_supplicant_ctrl_iface_scan_results(
7536 wpa_s, reply, reply_size);
7537 } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) {
7538 if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15))
7540 } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) {
7541 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15))
7543 } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) {
7544 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16))
7546 } else if (os_strcmp(buf, "ADD_NETWORK") == 0) {
7547 reply_len = wpa_supplicant_ctrl_iface_add_network(
7548 wpa_s, reply, reply_size);
7549 } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) {
7550 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15))
7552 } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
7553 if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12))
7555 } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) {
7556 reply_len = wpa_supplicant_ctrl_iface_get_network(
7557 wpa_s, buf + 12, reply, reply_size);
7558 } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) {
7559 if (wpa_supplicant_ctrl_iface_dup_network(wpa_s, buf + 12))
7561 } else if (os_strcmp(buf, "LIST_CREDS") == 0) {
7562 reply_len = wpa_supplicant_ctrl_iface_list_creds(
7563 wpa_s, reply, reply_size);
7564 } else if (os_strcmp(buf, "ADD_CRED") == 0) {
7565 reply_len = wpa_supplicant_ctrl_iface_add_cred(
7566 wpa_s, reply, reply_size);
7567 } else if (os_strncmp(buf, "REMOVE_CRED ", 12) == 0) {
7568 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s, buf + 12))
7570 } else if (os_strncmp(buf, "SET_CRED ", 9) == 0) {
7571 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s, buf + 9))
7573 } else if (os_strncmp(buf, "GET_CRED ", 9) == 0) {
7574 reply_len = wpa_supplicant_ctrl_iface_get_cred(wpa_s, buf + 9,
7577 #ifndef CONFIG_NO_CONFIG_WRITE
7578 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
7579 if (wpa_supplicant_ctrl_iface_save_config(wpa_s))
7581 #endif /* CONFIG_NO_CONFIG_WRITE */
7582 } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
7583 reply_len = wpa_supplicant_ctrl_iface_get_capability(
7584 wpa_s, buf + 15, reply, reply_size);
7585 } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) {
7586 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8))
7588 } else if (os_strncmp(buf, "SCAN_INTERVAL ", 14) == 0) {
7589 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s, buf + 14))
7591 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
7592 reply_len = wpa_supplicant_global_iface_list(
7593 wpa_s->global, reply, reply_size);
7594 } else if (os_strcmp(buf, "INTERFACES") == 0) {
7595 reply_len = wpa_supplicant_global_iface_interfaces(
7596 wpa_s->global, reply, reply_size);
7597 } else if (os_strncmp(buf, "BSS ", 4) == 0) {
7598 reply_len = wpa_supplicant_ctrl_iface_bss(
7599 wpa_s, buf + 4, reply, reply_size);
7601 } else if (os_strcmp(buf, "STA-FIRST") == 0) {
7602 reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size);
7603 } else if (os_strncmp(buf, "STA ", 4) == 0) {
7604 reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply,
7606 } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) {
7607 reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply,
7609 } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) {
7610 if (ap_ctrl_iface_sta_deauthenticate(wpa_s, buf + 15))
7612 } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) {
7613 if (ap_ctrl_iface_sta_disassociate(wpa_s, buf + 13))
7615 } else if (os_strncmp(buf, "CHAN_SWITCH ", 12) == 0) {
7616 if (ap_ctrl_iface_chanswitch(wpa_s, buf + 12))
7618 #endif /* CONFIG_AP */
7619 } else if (os_strcmp(buf, "SUSPEND") == 0) {
7620 wpas_notify_suspend(wpa_s->global);
7621 } else if (os_strcmp(buf, "RESUME") == 0) {
7622 wpas_notify_resume(wpa_s->global);
7623 #ifdef CONFIG_TESTING_OPTIONS
7624 } else if (os_strcmp(buf, "DROP_SA") == 0) {
7625 wpa_supplicant_ctrl_iface_drop_sa(wpa_s);
7626 #endif /* CONFIG_TESTING_OPTIONS */
7627 } else if (os_strncmp(buf, "ROAM ", 5) == 0) {
7628 if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5))
7630 } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) {
7631 wpa_s->auto_reconnect_disabled = atoi(buf + 16) == 0;
7632 } else if (os_strncmp(buf, "BSS_EXPIRE_AGE ", 15) == 0) {
7633 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s, buf + 15))
7635 } else if (os_strncmp(buf, "BSS_EXPIRE_COUNT ", 17) == 0) {
7636 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s,
7639 } else if (os_strncmp(buf, "BSS_FLUSH ", 10) == 0) {
7640 wpa_supplicant_ctrl_iface_bss_flush(wpa_s, buf + 10);
7642 } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) {
7643 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14))
7645 } else if (os_strncmp(buf, "TDLS_SETUP ", 11) == 0) {
7646 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s, buf + 11))
7648 } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) {
7649 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14))
7651 } else if (os_strncmp(buf, "TDLS_CHAN_SWITCH ", 17) == 0) {
7652 if (wpa_supplicant_ctrl_iface_tdls_chan_switch(wpa_s,
7655 } else if (os_strncmp(buf, "TDLS_CANCEL_CHAN_SWITCH ", 24) == 0) {
7656 if (wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(wpa_s,
7659 #endif /* CONFIG_TDLS */
7660 } else if (os_strcmp(buf, "WMM_AC_STATUS") == 0) {
7661 reply_len = wpas_wmm_ac_status(wpa_s, reply, reply_size);
7662 } else if (os_strncmp(buf, "WMM_AC_ADDTS ", 13) == 0) {
7663 if (wmm_ac_ctrl_addts(wpa_s, buf + 13))
7665 } else if (os_strncmp(buf, "WMM_AC_DELTS ", 13) == 0) {
7666 if (wmm_ac_ctrl_delts(wpa_s, buf + 13))
7668 } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) {
7669 reply_len = wpa_supplicant_signal_poll(wpa_s, reply,
7671 } else if (os_strncmp(buf, "PKTCNT_POLL", 11) == 0) {
7672 reply_len = wpa_supplicant_pktcnt_poll(wpa_s, reply,
7674 #ifdef CONFIG_AUTOSCAN
7675 } else if (os_strncmp(buf, "AUTOSCAN ", 9) == 0) {
7676 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s, buf + 9))
7678 #endif /* CONFIG_AUTOSCAN */
7680 } else if (os_strncmp(buf, "DRIVER ", 7) == 0) {
7681 reply_len = wpa_supplicant_driver_cmd(wpa_s, buf + 7, reply,
7683 #endif /* ANDROID */
7684 } else if (os_strncmp(buf, "VENDOR ", 7) == 0) {
7685 reply_len = wpa_supplicant_vendor_cmd(wpa_s, buf + 7, reply,
7687 } else if (os_strcmp(buf, "REAUTHENTICATE") == 0) {
7688 pmksa_cache_clear_current(wpa_s->wpa);
7689 eapol_sm_request_reauth(wpa_s->eapol);
7691 } else if (os_strncmp(buf, "WNM_SLEEP ", 10) == 0) {
7692 if (wpas_ctrl_iface_wnm_sleep(wpa_s, buf + 10))
7694 } else if (os_strncmp(buf, "WNM_BSS_QUERY ", 10) == 0) {
7695 if (wpas_ctrl_iface_wnm_bss_query(wpa_s, buf + 10))
7697 #endif /* CONFIG_WNM */
7698 } else if (os_strcmp(buf, "FLUSH") == 0) {
7699 wpa_supplicant_ctrl_iface_flush(wpa_s);
7700 } else if (os_strncmp(buf, "RADIO_WORK ", 11) == 0) {
7701 reply_len = wpas_ctrl_radio_work(wpa_s, buf + 11, reply,
7703 #ifdef CONFIG_TESTING_OPTIONS
7704 } else if (os_strncmp(buf, "MGMT_TX ", 8) == 0) {
7705 if (wpas_ctrl_iface_mgmt_tx(wpa_s, buf + 8) < 0)
7707 } else if (os_strcmp(buf, "MGMT_TX_DONE") == 0) {
7708 wpas_ctrl_iface_mgmt_tx_done(wpa_s);
7709 } else if (os_strncmp(buf, "DRIVER_EVENT ", 13) == 0) {
7710 if (wpas_ctrl_iface_driver_event(wpa_s, buf + 13) < 0)
7712 } else if (os_strncmp(buf, "EAPOL_RX ", 9) == 0) {
7713 if (wpas_ctrl_iface_eapol_rx(wpa_s, buf + 9) < 0)
7715 } else if (os_strncmp(buf, "DATA_TEST_CONFIG ", 17) == 0) {
7716 if (wpas_ctrl_iface_data_test_config(wpa_s, buf + 17) < 0)
7718 } else if (os_strncmp(buf, "DATA_TEST_TX ", 13) == 0) {
7719 if (wpas_ctrl_iface_data_test_tx(wpa_s, buf + 13) < 0)
7721 } else if (os_strncmp(buf, "DATA_TEST_FRAME ", 16) == 0) {
7722 if (wpas_ctrl_iface_data_test_frame(wpa_s, buf + 16) < 0)
7724 #endif /* CONFIG_TESTING_OPTIONS */
7725 } else if (os_strncmp(buf, "VENDOR_ELEM_ADD ", 16) == 0) {
7726 if (wpas_ctrl_vendor_elem_add(wpa_s, buf + 16) < 0)
7728 } else if (os_strncmp(buf, "VENDOR_ELEM_GET ", 16) == 0) {
7729 reply_len = wpas_ctrl_vendor_elem_get(wpa_s, buf + 16, reply,
7731 } else if (os_strncmp(buf, "VENDOR_ELEM_REMOVE ", 19) == 0) {
7732 if (wpas_ctrl_vendor_elem_remove(wpa_s, buf + 19) < 0)
7734 } else if (os_strncmp(buf, "NEIGHBOR_REP_REQUEST", 20) == 0) {
7735 if (wpas_ctrl_iface_send_neigbor_rep(wpa_s, buf + 20))
7737 } else if (os_strcmp(buf, "ERP_FLUSH") == 0) {
7738 wpas_ctrl_iface_erp_flush(wpa_s);
7740 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
7744 if (reply_len < 0) {
7745 os_memcpy(reply, "FAIL\n", 5);
7749 *resp_len = reply_len;
7754 static int wpa_supplicant_global_iface_add(struct wpa_global *global,
7757 struct wpa_interface iface;
7761 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
7762 * TAB<bridge_ifname>
7764 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd);
7766 os_memset(&iface, 0, sizeof(iface));
7769 iface.ifname = pos = cmd;
7770 pos = os_strchr(pos, '\t');
7773 if (iface.ifname[0] == '\0')
7778 iface.confname = pos;
7779 pos = os_strchr(pos, '\t');
7782 if (iface.confname[0] == '\0')
7783 iface.confname = NULL;
7788 pos = os_strchr(pos, '\t');
7791 if (iface.driver[0] == '\0')
7792 iface.driver = NULL;
7796 iface.ctrl_interface = pos;
7797 pos = os_strchr(pos, '\t');
7800 if (iface.ctrl_interface[0] == '\0')
7801 iface.ctrl_interface = NULL;
7805 iface.driver_param = pos;
7806 pos = os_strchr(pos, '\t');
7809 if (iface.driver_param[0] == '\0')
7810 iface.driver_param = NULL;
7814 iface.bridge_ifname = pos;
7815 pos = os_strchr(pos, '\t');
7818 if (iface.bridge_ifname[0] == '\0')
7819 iface.bridge_ifname = NULL;
7824 if (wpa_supplicant_get_iface(global, iface.ifname))
7827 return wpa_supplicant_add_iface(global, &iface) ? 0 : -1;
7831 static int wpa_supplicant_global_iface_remove(struct wpa_global *global,
7834 struct wpa_supplicant *wpa_s;
7836 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd);
7838 wpa_s = wpa_supplicant_get_iface(global, cmd);
7841 return wpa_supplicant_remove_iface(global, wpa_s, 0);
7845 static void wpa_free_iface_info(struct wpa_interface_info *iface)
7847 struct wpa_interface_info *prev;
7851 iface = iface->next;
7853 os_free(prev->ifname);
7854 os_free(prev->desc);
7860 static int wpa_supplicant_global_iface_list(struct wpa_global *global,
7864 struct wpa_interface_info *iface = NULL, *last = NULL, *tmp;
7867 for (i = 0; wpa_drivers[i]; i++) {
7868 struct wpa_driver_ops *drv = wpa_drivers[i];
7869 if (drv->get_interfaces == NULL)
7871 tmp = drv->get_interfaces(global->drv_priv[i]);
7885 for (tmp = iface; tmp; tmp = tmp->next) {
7886 res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n",
7887 tmp->drv_name, tmp->ifname,
7888 tmp->desc ? tmp->desc : "");
7889 if (os_snprintf_error(end - pos, res)) {
7896 wpa_free_iface_info(iface);
7902 static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
7907 struct wpa_supplicant *wpa_s;
7909 wpa_s = global->ifaces;
7914 res = os_snprintf(pos, end - pos, "%s\n", wpa_s->ifname);
7915 if (os_snprintf_error(end - pos, res)) {
7920 wpa_s = wpa_s->next;
7926 static char * wpas_global_ctrl_iface_ifname(struct wpa_global *global,
7928 char *cmd, size_t *resp_len)
7930 struct wpa_supplicant *wpa_s;
7932 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
7933 if (os_strcmp(ifname, wpa_s->ifname) == 0)
7937 if (wpa_s == NULL) {
7938 char *resp = os_strdup("FAIL-NO-IFNAME-MATCH\n");
7940 *resp_len = os_strlen(resp);
7946 return wpa_supplicant_ctrl_iface_process(wpa_s, cmd, resp_len);
7950 static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global *global,
7951 char *buf, size_t *resp_len)
7954 static const char * cmd[] = {
7960 "P2P_GET_PASSPHRASE",
7961 "P2P_SERVICE_UPDATE",
7962 "P2P_SERVICE_FLUSH",
7969 static const char * prefix[] = {
7972 #endif /* ANDROID */
7978 "P2P_GROUP_REMOVE ",
7981 "P2P_SERV_DISC_REQ ",
7982 "P2P_SERV_DISC_CANCEL_REQ ",
7983 "P2P_SERV_DISC_RESP ",
7984 "P2P_SERV_DISC_EXTERNAL ",
7992 "P2P_PRESENCE_REQ ",
7994 "P2P_REMOVE_CLIENT ",
7995 "NFC_GET_HANDOVER_SEL ",
7996 "NFC_GET_HANDOVER_REQ ",
7997 "NFC_REPORT_HANDOVER ",
8003 if (global->p2p_init_wpa_s == NULL)
8006 for (i = 0; !found && cmd[i]; i++) {
8007 if (os_strcmp(buf, cmd[i]) == 0)
8011 for (i = 0; !found && prefix[i]; i++) {
8012 if (os_strncmp(buf, prefix[i], os_strlen(prefix[i])) == 0)
8017 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
8019 #endif /* CONFIG_P2P */
8024 static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global *global,
8025 char *buf, size_t *resp_len)
8027 #ifdef CONFIG_WIFI_DISPLAY
8028 if (global->p2p_init_wpa_s == NULL)
8030 if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0 ||
8031 os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0)
8032 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
8034 #endif /* CONFIG_WIFI_DISPLAY */
8039 static char * wpas_global_ctrl_iface_redir(struct wpa_global *global,
8040 char *buf, size_t *resp_len)
8044 ret = wpas_global_ctrl_iface_redir_p2p(global, buf, resp_len);
8048 ret = wpas_global_ctrl_iface_redir_wfd(global, buf, resp_len);
8056 static int wpas_global_ctrl_iface_set(struct wpa_global *global, char *cmd)
8060 value = os_strchr(cmd, ' ');
8065 wpa_printf(MSG_DEBUG, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd, value);
8067 #ifdef CONFIG_WIFI_DISPLAY
8068 if (os_strcasecmp(cmd, "wifi_display") == 0) {
8069 wifi_display_enable(global, !!atoi(value));
8072 #endif /* CONFIG_WIFI_DISPLAY */
8074 /* Restore cmd to its original value to allow redirection */
8081 #ifndef CONFIG_NO_CONFIG_WRITE
8082 static int wpas_global_ctrl_iface_save_config(struct wpa_global *global)
8084 int ret = 0, saved = 0;
8085 struct wpa_supplicant *wpa_s;
8087 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
8088 if (!wpa_s->conf->update_config) {
8089 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
8093 if (wpa_config_write(wpa_s->confname, wpa_s->conf)) {
8094 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
8097 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
8102 if (!saved && !ret) {
8103 wpa_dbg(wpa_s, MSG_DEBUG,
8104 "CTRL_IFACE: SAVE_CONFIG - No configuration files could be updated");
8110 #endif /* CONFIG_NO_CONFIG_WRITE */
8113 static int wpas_global_ctrl_iface_status(struct wpa_global *global,
8114 char *buf, size_t buflen)
8118 struct wpa_supplicant *wpa_s;
8124 if (global->p2p && !global->p2p_disabled) {
8125 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
8128 MAC2STR(global->p2p_dev_addr),
8129 p2p_get_state_txt(global->p2p));
8130 if (os_snprintf_error(end - pos, ret))
8133 } else if (global->p2p) {
8134 ret = os_snprintf(pos, end - pos, "p2p_state=DISABLED\n");
8135 if (os_snprintf_error(end - pos, ret))
8139 #endif /* CONFIG_P2P */
8141 #ifdef CONFIG_WIFI_DISPLAY
8142 ret = os_snprintf(pos, end - pos, "wifi_display=%d\n",
8143 !!global->wifi_display);
8144 if (os_snprintf_error(end - pos, ret))
8147 #endif /* CONFIG_WIFI_DISPLAY */
8149 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
8150 ret = os_snprintf(pos, end - pos, "ifname=%s\n"
8151 "address=" MACSTR "\n",
8152 wpa_s->ifname, MAC2STR(wpa_s->own_addr));
8153 if (os_snprintf_error(end - pos, ret))
8162 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
8163 char *buf, size_t *resp_len)
8166 const int reply_size = 2048;
8168 int level = MSG_DEBUG;
8170 if (os_strncmp(buf, "IFNAME=", 7) == 0) {
8171 char *pos = os_strchr(buf + 7, ' ');
8174 return wpas_global_ctrl_iface_ifname(global,
8180 reply = wpas_global_ctrl_iface_redir(global, buf, resp_len);
8184 if (os_strcmp(buf, "PING") == 0)
8185 level = MSG_EXCESSIVE;
8186 wpa_hexdump_ascii(level, "RX global ctrl_iface",
8187 (const u8 *) buf, os_strlen(buf));
8189 reply = os_malloc(reply_size);
8190 if (reply == NULL) {
8195 os_memcpy(reply, "OK\n", 3);
8198 if (os_strcmp(buf, "PING") == 0) {
8199 os_memcpy(reply, "PONG\n", 5);
8201 } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) {
8202 if (wpa_supplicant_global_iface_add(global, buf + 14))
8204 } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) {
8205 if (wpa_supplicant_global_iface_remove(global, buf + 17))
8207 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
8208 reply_len = wpa_supplicant_global_iface_list(
8209 global, reply, reply_size);
8210 } else if (os_strcmp(buf, "INTERFACES") == 0) {
8211 reply_len = wpa_supplicant_global_iface_interfaces(
8212 global, reply, reply_size);
8213 } else if (os_strcmp(buf, "TERMINATE") == 0) {
8214 wpa_supplicant_terminate_proc(global);
8215 } else if (os_strcmp(buf, "SUSPEND") == 0) {
8216 wpas_notify_suspend(global);
8217 } else if (os_strcmp(buf, "RESUME") == 0) {
8218 wpas_notify_resume(global);
8219 } else if (os_strncmp(buf, "SET ", 4) == 0) {
8220 if (wpas_global_ctrl_iface_set(global, buf + 4)) {
8222 if (global->p2p_init_wpa_s) {
8224 /* Check if P2P redirection would work for this
8226 return wpa_supplicant_ctrl_iface_process(
8227 global->p2p_init_wpa_s,
8230 #endif /* CONFIG_P2P */
8233 #ifndef CONFIG_NO_CONFIG_WRITE
8234 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
8235 if (wpas_global_ctrl_iface_save_config(global))
8237 #endif /* CONFIG_NO_CONFIG_WRITE */
8238 } else if (os_strcmp(buf, "STATUS") == 0) {
8239 reply_len = wpas_global_ctrl_iface_status(global, reply,
8241 #ifdef CONFIG_MODULE_TESTS
8242 } else if (os_strcmp(buf, "MODULE_TESTS") == 0) {
8243 int wpas_module_tests(void);
8244 if (wpas_module_tests() < 0)
8246 #endif /* CONFIG_MODULE_TESTS */
8247 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
8248 if (wpa_debug_reopen_file() < 0)
8251 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
8255 if (reply_len < 0) {
8256 os_memcpy(reply, "FAIL\n", 5);
8260 *resp_len = reply_len;