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"
11 #include "utils/common.h"
12 #include "utils/eloop.h"
13 #include "utils/uuid.h"
14 #include "common/version.h"
15 #include "common/ieee802_11_defs.h"
16 #include "common/ieee802_11_common.h"
17 #include "common/wpa_ctrl.h"
18 #include "eap_peer/eap.h"
19 #include "eapol_supp/eapol_supp_sm.h"
20 #include "rsn_supp/wpa.h"
21 #include "rsn_supp/preauth.h"
22 #include "rsn_supp/pmksa_cache.h"
23 #include "l2_packet/l2_packet.h"
26 #include "wpa_supplicant_i.h"
28 #include "wps_supplicant.h"
31 #include "p2p_supplicant.h"
33 #include "hs20_supplicant.h"
34 #include "wifi_display.h"
38 #include "ctrl_iface.h"
39 #include "interworking.h"
40 #include "blacklist.h"
43 #include "offchannel.h"
45 static int wpa_supplicant_global_iface_list(struct wpa_global *global,
47 static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
50 static int set_bssid_filter(struct wpa_supplicant *wpa_s, char *val)
53 u8 addr[ETH_ALEN], *filter = NULL, *n;
60 if (hwaddr_aton(pos, addr)) {
64 n = os_realloc_array(filter, count + 1, ETH_ALEN);
70 os_memcpy(filter + count * ETH_ALEN, addr, ETH_ALEN);
73 pos = os_strchr(pos, ' ');
78 wpa_hexdump(MSG_DEBUG, "bssid_filter", filter, count * ETH_ALEN);
79 os_free(wpa_s->bssid_filter);
80 wpa_s->bssid_filter = filter;
81 wpa_s->bssid_filter_count = count;
87 static int set_disallow_aps(struct wpa_supplicant *wpa_s, char *val)
90 u8 addr[ETH_ALEN], *bssid = NULL, *n;
91 struct wpa_ssid_value *ssid = NULL, *ns;
92 size_t count = 0, ssid_count = 0;
96 * disallow_list ::= <ssid_spec> | <bssid_spec> | <disallow_list> | ""
97 * SSID_SPEC ::= ssid <SSID_HEX>
98 * BSSID_SPEC ::= bssid <BSSID_HEX>
105 if (os_strncmp(pos, "bssid ", 6) == 0) {
108 res = hwaddr_aton2(pos, addr);
112 wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
113 "BSSID value '%s'", pos);
117 n = os_realloc_array(bssid, count + 1, ETH_ALEN);
124 os_memcpy(bssid + count * ETH_ALEN, addr, ETH_ALEN);
126 } else if (os_strncmp(pos, "ssid ", 5) == 0) {
132 if (*end == '\0' || *end == ' ')
137 ns = os_realloc_array(ssid, ssid_count + 1,
138 sizeof(struct wpa_ssid_value));
146 if ((end - pos) & 0x01 || end - pos > 2 * 32 ||
147 hexstr2bin(pos, ssid[ssid_count].ssid,
148 (end - pos) / 2) < 0) {
151 wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
152 "SSID value '%s'", pos);
155 ssid[ssid_count].ssid_len = (end - pos) / 2;
156 wpa_hexdump_ascii(MSG_DEBUG, "disallow_aps SSID",
157 ssid[ssid_count].ssid,
158 ssid[ssid_count].ssid_len);
162 wpa_printf(MSG_DEBUG, "Unexpected disallow_aps value "
169 pos = os_strchr(pos, ' ');
174 wpa_hexdump(MSG_DEBUG, "disallow_aps_bssid", bssid, count * ETH_ALEN);
175 os_free(wpa_s->disallow_aps_bssid);
176 wpa_s->disallow_aps_bssid = bssid;
177 wpa_s->disallow_aps_bssid_count = count;
179 wpa_printf(MSG_DEBUG, "disallow_aps_ssid_count %d", (int) ssid_count);
180 os_free(wpa_s->disallow_aps_ssid);
181 wpa_s->disallow_aps_ssid = ssid;
182 wpa_s->disallow_aps_ssid_count = ssid_count;
184 if (!wpa_s->current_ssid || wpa_s->wpa_state < WPA_AUTHENTICATING)
187 c = wpa_s->current_ssid;
188 if (c->mode != WPAS_MODE_INFRA && c->mode != WPAS_MODE_IBSS)
191 if (!disallowed_bssid(wpa_s, wpa_s->bssid) &&
192 !disallowed_ssid(wpa_s, c->ssid, c->ssid_len))
195 wpa_printf(MSG_DEBUG, "Disconnect and try to find another network "
196 "because current AP was marked disallowed");
199 wpa_s->sme.prev_bssid_set = 0;
200 #endif /* CONFIG_SME */
201 wpa_s->reassociate = 1;
202 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
203 wpa_supplicant_req_scan(wpa_s, 0, 0);
209 static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s,
215 value = os_strchr(cmd, ' ');
220 wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value);
221 if (os_strcasecmp(cmd, "EAPOL::heldPeriod") == 0) {
222 eapol_sm_configure(wpa_s->eapol,
223 atoi(value), -1, -1, -1);
224 } else if (os_strcasecmp(cmd, "EAPOL::authPeriod") == 0) {
225 eapol_sm_configure(wpa_s->eapol,
226 -1, atoi(value), -1, -1);
227 } else if (os_strcasecmp(cmd, "EAPOL::startPeriod") == 0) {
228 eapol_sm_configure(wpa_s->eapol,
229 -1, -1, atoi(value), -1);
230 } else if (os_strcasecmp(cmd, "EAPOL::maxStart") == 0) {
231 eapol_sm_configure(wpa_s->eapol,
232 -1, -1, -1, atoi(value));
233 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKLifetime") == 0) {
234 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME,
237 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKReauthThreshold") ==
239 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD,
242 } else if (os_strcasecmp(cmd, "dot11RSNAConfigSATimeout") == 0) {
243 if (wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, atoi(value)))
245 } else if (os_strcasecmp(cmd, "wps_fragment_size") == 0) {
246 wpa_s->wps_fragment_size = atoi(value);
247 #ifdef CONFIG_WPS_TESTING
248 } else if (os_strcasecmp(cmd, "wps_version_number") == 0) {
250 val = strtol(value, NULL, 0);
251 if (val < 0 || val > 0xff) {
253 wpa_printf(MSG_DEBUG, "WPS: Invalid "
254 "wps_version_number %ld", val);
256 wps_version_number = val;
257 wpa_printf(MSG_DEBUG, "WPS: Testing - force WPS "
259 (wps_version_number & 0xf0) >> 4,
260 wps_version_number & 0x0f);
262 } else if (os_strcasecmp(cmd, "wps_testing_dummy_cred") == 0) {
263 wps_testing_dummy_cred = atoi(value);
264 wpa_printf(MSG_DEBUG, "WPS: Testing - dummy_cred=%d",
265 wps_testing_dummy_cred);
266 } else if (os_strcasecmp(cmd, "wps_corrupt_pkhash") == 0) {
267 wps_corrupt_pkhash = atoi(value);
268 wpa_printf(MSG_DEBUG, "WPS: Testing - wps_corrupt_pkhash=%d",
270 #endif /* CONFIG_WPS_TESTING */
271 } else if (os_strcasecmp(cmd, "ampdu") == 0) {
272 if (wpa_drv_ampdu(wpa_s, atoi(value)) < 0)
275 #ifdef CONFIG_TDLS_TESTING
276 } else if (os_strcasecmp(cmd, "tdls_testing") == 0) {
277 extern unsigned int tdls_testing;
278 tdls_testing = strtol(value, NULL, 0);
279 wpa_printf(MSG_DEBUG, "TDLS: tdls_testing=0x%x", tdls_testing);
280 #endif /* CONFIG_TDLS_TESTING */
281 } else if (os_strcasecmp(cmd, "tdls_disabled") == 0) {
282 int disabled = atoi(value);
283 wpa_printf(MSG_DEBUG, "TDLS: tdls_disabled=%d", disabled);
285 if (wpa_drv_tdls_oper(wpa_s, TDLS_DISABLE, NULL) < 0)
287 } else if (wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL) < 0)
289 wpa_tdls_enable(wpa_s->wpa, !disabled);
290 #endif /* CONFIG_TDLS */
291 } else if (os_strcasecmp(cmd, "pno") == 0) {
293 ret = wpas_start_pno(wpa_s);
295 ret = wpas_stop_pno(wpa_s);
296 } else if (os_strcasecmp(cmd, "radio_disabled") == 0) {
297 int disabled = atoi(value);
298 if (wpa_drv_radio_disable(wpa_s, disabled) < 0)
301 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
302 } else if (os_strcasecmp(cmd, "uapsd") == 0) {
303 if (os_strcmp(value, "disable") == 0)
304 wpa_s->set_sta_uapsd = 0;
308 /* format: BE,BK,VI,VO;max SP Length */
310 pos = os_strchr(value, ',');
315 pos = os_strchr(pos, ',');
320 pos = os_strchr(pos, ',');
325 /* ignore max SP Length for now */
327 wpa_s->set_sta_uapsd = 1;
328 wpa_s->sta_uapsd = 0;
330 wpa_s->sta_uapsd |= BIT(0);
332 wpa_s->sta_uapsd |= BIT(1);
334 wpa_s->sta_uapsd |= BIT(2);
336 wpa_s->sta_uapsd |= BIT(3);
338 } else if (os_strcasecmp(cmd, "ps") == 0) {
339 ret = wpa_drv_set_p2p_powersave(wpa_s, atoi(value), -1, -1);
340 #ifdef CONFIG_WIFI_DISPLAY
341 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
342 int enabled = !!atoi(value);
343 if (enabled && !wpa_s->global->p2p)
346 wifi_display_enable(wpa_s->global, enabled);
347 #endif /* CONFIG_WIFI_DISPLAY */
348 } else if (os_strcasecmp(cmd, "bssid_filter") == 0) {
349 ret = set_bssid_filter(wpa_s, value);
350 } else if (os_strcasecmp(cmd, "disallow_aps") == 0) {
351 ret = set_disallow_aps(wpa_s, value);
352 } else if (os_strcasecmp(cmd, "no_keep_alive") == 0) {
353 wpa_s->no_keep_alive = !!atoi(value);
354 #ifdef CONFIG_TESTING_OPTIONS
355 } else if (os_strcasecmp(cmd, "ext_mgmt_frame_handling") == 0) {
356 wpa_s->ext_mgmt_frame_handling = !!atoi(value);
357 #endif /* CONFIG_TESTING_OPTIONS */
360 ret = wpa_config_process_global(wpa_s->conf, cmd, -1);
362 wpa_supplicant_update_config(wpa_s);
369 static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s,
370 char *cmd, char *buf, size_t buflen)
374 wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd);
376 if (os_strcmp(cmd, "version") == 0) {
377 res = os_snprintf(buf, buflen, "%s", VERSION_STR);
378 } else if (os_strcasecmp(cmd, "country") == 0) {
379 if (wpa_s->conf->country[0] && wpa_s->conf->country[1])
380 res = os_snprintf(buf, buflen, "%c%c",
381 wpa_s->conf->country[0],
382 wpa_s->conf->country[1]);
383 #ifdef CONFIG_WIFI_DISPLAY
384 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
386 if (wpa_s->global->p2p == NULL ||
387 wpa_s->global->p2p_disabled)
390 enabled = wpa_s->global->wifi_display;
391 res = os_snprintf(buf, buflen, "%d", enabled);
392 if (res < 0 || (unsigned int) res >= buflen)
395 #endif /* CONFIG_WIFI_DISPLAY */
396 #ifdef CONFIG_TESTING_GET_GTK
397 } else if (os_strcmp(cmd, "gtk") == 0) {
398 if (wpa_s->last_gtk_len == 0)
400 res = wpa_snprintf_hex(buf, buflen, wpa_s->last_gtk,
401 wpa_s->last_gtk_len);
403 #endif /* CONFIG_TESTING_GET_GTK */
406 if (res < 0 || (unsigned int) res >= buflen)
412 #ifdef IEEE8021X_EAPOL
413 static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s,
417 struct wpa_ssid *ssid = wpa_s->current_ssid;
419 if (hwaddr_aton(addr, bssid)) {
420 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address "
425 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid));
426 rsn_preauth_deinit(wpa_s->wpa);
427 if (rsn_preauth_init(wpa_s->wpa, bssid, ssid ? &ssid->eap : NULL))
432 #endif /* IEEE8021X_EAPOL */
435 #ifdef CONFIG_PEERKEY
436 /* MLME-STKSTART.request(peer) */
437 static int wpa_supplicant_ctrl_iface_stkstart(
438 struct wpa_supplicant *wpa_s, char *addr)
442 if (hwaddr_aton(addr, peer)) {
443 wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART: invalid "
444 "address '%s'", addr);
448 wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART " MACSTR,
451 return wpa_sm_stkstart(wpa_s->wpa, peer);
453 #endif /* CONFIG_PEERKEY */
458 static int wpa_supplicant_ctrl_iface_tdls_discover(
459 struct wpa_supplicant *wpa_s, char *addr)
464 if (hwaddr_aton(addr, peer)) {
465 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER: invalid "
466 "address '%s'", addr);
470 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER " MACSTR,
473 if (wpa_tdls_is_external_setup(wpa_s->wpa))
474 ret = wpa_tdls_send_discovery_request(wpa_s->wpa, peer);
476 ret = wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer);
482 static int wpa_supplicant_ctrl_iface_tdls_setup(
483 struct wpa_supplicant *wpa_s, char *addr)
488 if (hwaddr_aton(addr, peer)) {
489 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP: invalid "
490 "address '%s'", addr);
494 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP " MACSTR,
497 if ((wpa_s->conf->tdls_external_control) &&
498 wpa_tdls_is_external_setup(wpa_s->wpa))
499 return wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
501 wpa_tdls_remove(wpa_s->wpa, peer);
503 if (wpa_tdls_is_external_setup(wpa_s->wpa))
504 ret = wpa_tdls_start(wpa_s->wpa, peer);
506 ret = wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
512 static int wpa_supplicant_ctrl_iface_tdls_teardown(
513 struct wpa_supplicant *wpa_s, char *addr)
518 if (hwaddr_aton(addr, peer)) {
519 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN: invalid "
520 "address '%s'", addr);
524 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN " MACSTR,
527 if ((wpa_s->conf->tdls_external_control) &&
528 wpa_tdls_is_external_setup(wpa_s->wpa))
529 return wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
531 if (wpa_tdls_is_external_setup(wpa_s->wpa))
532 ret = wpa_tdls_teardown_link(
534 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED);
536 ret = wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
542 static int ctrl_iface_get_capability_tdls(
543 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
547 ret = os_snprintf(buf, buflen, "%s\n",
548 wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT ?
550 WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP ?
551 "EXTERNAL" : "INTERNAL") : "UNSUPPORTED");
552 if (ret < 0 || (size_t) ret > buflen)
557 #endif /* CONFIG_TDLS */
560 #ifdef CONFIG_IEEE80211R
561 static int wpa_supplicant_ctrl_iface_ft_ds(
562 struct wpa_supplicant *wpa_s, char *addr)
564 u8 target_ap[ETH_ALEN];
568 if (hwaddr_aton(addr, target_ap)) {
569 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid "
570 "address '%s'", addr);
574 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap));
576 bss = wpa_bss_get_bssid(wpa_s, target_ap);
578 mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN);
582 return wpa_ft_start_over_ds(wpa_s->wpa, target_ap, mdie);
584 #endif /* CONFIG_IEEE80211R */
588 static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s,
591 u8 bssid[ETH_ALEN], *_bssid = bssid;
593 u8 p2p_dev_addr[ETH_ALEN];
594 #endif /* CONFIG_P2P */
596 u8 *_p2p_dev_addr = NULL;
597 #endif /* CONFIG_AP */
599 if (cmd == NULL || os_strcmp(cmd, "any") == 0) {
602 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
603 if (hwaddr_aton(cmd + 13, p2p_dev_addr)) {
604 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid "
605 "P2P Device Address '%s'",
609 _p2p_dev_addr = p2p_dev_addr;
610 #endif /* CONFIG_P2P */
611 } else if (hwaddr_aton(cmd, bssid)) {
612 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
619 return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid, _p2p_dev_addr);
620 #endif /* CONFIG_AP */
622 return wpas_wps_start_pbc(wpa_s, _bssid, 0);
626 static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s,
627 char *cmd, char *buf,
630 u8 bssid[ETH_ALEN], *_bssid = bssid;
634 pin = os_strchr(cmd, ' ');
638 if (os_strcmp(cmd, "any") == 0)
640 else if (os_strcmp(cmd, "get") == 0) {
641 ret = wps_generate_pin();
643 } else if (hwaddr_aton(cmd, bssid)) {
644 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
650 if (wpa_s->ap_iface) {
655 pos = os_strchr(pin, ' ');
662 return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin,
663 buf, buflen, timeout);
665 #endif /* CONFIG_AP */
668 ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0,
672 ret = os_snprintf(buf, buflen, "%s", pin);
673 if (ret < 0 || (size_t) ret >= buflen)
678 ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0, DEV_PW_DEFAULT);
683 /* Return the generated PIN */
684 ret = os_snprintf(buf, buflen, "%08d", ret);
685 if (ret < 0 || (size_t) ret >= buflen)
691 static int wpa_supplicant_ctrl_iface_wps_check_pin(
692 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
699 wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN",
700 (u8 *) cmd, os_strlen(cmd));
701 for (pos = cmd, len = 0; *pos != '\0'; pos++) {
702 if (*pos < '0' || *pos > '9')
706 wpa_printf(MSG_DEBUG, "WPS: Too long PIN");
710 if (len != 4 && len != 8) {
711 wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len);
717 unsigned int pin_val;
719 if (!wps_pin_valid(pin_val)) {
720 wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit");
721 ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n");
722 if (ret < 0 || (size_t) ret >= buflen)
728 ret = os_snprintf(buf, buflen, "%s", pin);
729 if (ret < 0 || (size_t) ret >= buflen)
736 #ifdef CONFIG_WPS_NFC
738 static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant *wpa_s,
741 u8 bssid[ETH_ALEN], *_bssid = bssid;
743 if (cmd == NULL || cmd[0] == '\0')
745 else if (hwaddr_aton(cmd, bssid))
748 return wpas_wps_start_nfc(wpa_s, NULL, _bssid, NULL, 0, 0, NULL, NULL,
753 static int wpa_supplicant_ctrl_iface_wps_nfc_config_token(
754 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
761 pos = os_strchr(cmd, ' ');
764 if (os_strcmp(cmd, "WPS") == 0)
766 else if (os_strcmp(cmd, "NDEF") == 0)
771 buf = wpas_wps_nfc_config_token(wpa_s, ndef, pos);
775 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
786 static int wpa_supplicant_ctrl_iface_wps_nfc_token(
787 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
793 if (os_strcmp(cmd, "WPS") == 0)
795 else if (os_strcmp(cmd, "NDEF") == 0)
800 buf = wpas_wps_nfc_token(wpa_s, ndef);
804 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
815 static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
816 struct wpa_supplicant *wpa_s, char *pos)
824 freq = strstr(pos, " freq=");
828 forced_freq = atoi(freq);
831 len = os_strlen(pos);
836 buf = wpabuf_alloc(len);
839 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
844 ret = wpas_wps_nfc_tag_read(wpa_s, buf, forced_freq);
851 static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant *wpa_s,
852 char *reply, size_t max_len,
858 buf = wpas_wps_nfc_handover_req(wpa_s, ndef);
862 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
874 static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant *wpa_s,
875 char *reply, size_t max_len,
881 buf = wpas_p2p_nfc_handover_req(wpa_s, ndef);
883 wpa_printf(MSG_DEBUG, "P2P: Could not generate NFC handover request");
887 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
896 #endif /* CONFIG_P2P */
899 static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant *wpa_s,
900 char *cmd, char *reply,
906 pos = os_strchr(cmd, ' ');
911 if (os_strcmp(cmd, "WPS") == 0)
913 else if (os_strcmp(cmd, "NDEF") == 0)
918 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
921 return wpas_ctrl_nfc_get_handover_req_wps(
922 wpa_s, reply, max_len, ndef);
926 if (os_strcmp(pos, "P2P-CR") == 0) {
927 return wpas_ctrl_nfc_get_handover_req_p2p(
928 wpa_s, reply, max_len, ndef);
930 #endif /* CONFIG_P2P */
936 static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant *wpa_s,
937 char *reply, size_t max_len,
938 int ndef, int cr, char *uuid)
943 buf = wpas_wps_nfc_handover_sel(wpa_s, ndef, cr, uuid);
947 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
959 static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant *wpa_s,
960 char *reply, size_t max_len,
966 buf = wpas_p2p_nfc_handover_sel(wpa_s, ndef, tag);
970 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
979 #endif /* CONFIG_P2P */
982 static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant *wpa_s,
983 char *cmd, char *reply,
989 pos = os_strchr(cmd, ' ');
994 if (os_strcmp(cmd, "WPS") == 0)
996 else if (os_strcmp(cmd, "NDEF") == 0)
1001 pos2 = os_strchr(pos, ' ');
1004 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
1007 return wpas_ctrl_nfc_get_handover_sel_wps(
1008 wpa_s, reply, max_len, ndef,
1009 os_strcmp(pos, "WPS-CR") == 0, pos2);
1013 if (os_strcmp(pos, "P2P-CR") == 0) {
1014 return wpas_ctrl_nfc_get_handover_sel_p2p(
1015 wpa_s, reply, max_len, ndef, 0);
1018 if (os_strcmp(pos, "P2P-CR-TAG") == 0) {
1019 return wpas_ctrl_nfc_get_handover_sel_p2p(
1020 wpa_s, reply, max_len, ndef, 1);
1022 #endif /* CONFIG_P2P */
1028 static int wpas_ctrl_nfc_rx_handover_sel(struct wpa_supplicant *wpa_s,
1035 len = os_strlen(cmd);
1040 buf = wpabuf_alloc(len);
1043 if (hexstr2bin(cmd, wpabuf_put(buf, len), len) < 0) {
1048 ret = wpas_wps_nfc_rx_handover_sel(wpa_s, buf);
1055 static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant *wpa_s,
1059 struct wpabuf *req, *sel;
1061 char *pos, *role, *type, *pos2;
1064 int forced_freq = 0;
1066 freq = strstr(cmd, " freq=");
1070 forced_freq = atoi(freq);
1072 #endif /* CONFIG_P2P */
1075 pos = os_strchr(role, ' ');
1077 wpa_printf(MSG_DEBUG, "NFC: Missing type in handover report");
1083 pos = os_strchr(type, ' ');
1085 wpa_printf(MSG_DEBUG, "NFC: Missing request message in handover report");
1090 pos2 = os_strchr(pos, ' ');
1092 wpa_printf(MSG_DEBUG, "NFC: Missing select message in handover report");
1097 len = os_strlen(pos);
1099 wpa_printf(MSG_DEBUG, "NFC: Invalid request message length in handover report");
1104 req = wpabuf_alloc(len);
1106 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for request message");
1109 if (hexstr2bin(pos, wpabuf_put(req, len), len) < 0) {
1110 wpa_printf(MSG_DEBUG, "NFC: Invalid request message hexdump in handover report");
1115 len = os_strlen(pos2);
1117 wpa_printf(MSG_DEBUG, "NFC: Invalid select message length in handover report");
1123 sel = wpabuf_alloc(len);
1125 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for select message");
1129 if (hexstr2bin(pos2, wpabuf_put(sel, len), len) < 0) {
1130 wpa_printf(MSG_DEBUG, "NFC: Invalid select message hexdump in handover report");
1136 wpa_printf(MSG_DEBUG, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d",
1137 role, type, (int) wpabuf_len(req), (int) wpabuf_len(sel));
1139 if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "WPS") == 0) {
1140 ret = wpas_wps_nfc_report_handover(wpa_s, req, sel);
1142 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "WPS") == 0)
1144 ret = wpas_ap_wps_nfc_report_handover(wpa_s, req, sel);
1146 ret = wpas_er_wps_nfc_report_handover(wpa_s, req, sel);
1147 #endif /* CONFIG_AP */
1149 } else if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "P2P") == 0)
1151 ret = wpas_p2p_nfc_report_handover(wpa_s, 1, req, sel, 0);
1152 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "P2P") == 0)
1154 ret = wpas_p2p_nfc_report_handover(wpa_s, 0, req, sel,
1156 #endif /* CONFIG_P2P */
1158 wpa_printf(MSG_DEBUG, "NFC: Unsupported connection handover "
1159 "reported: role=%s type=%s", role, type);
1166 wpa_printf(MSG_DEBUG, "NFC: Failed to process reported handover messages");
1171 #endif /* CONFIG_WPS_NFC */
1174 static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s,
1183 struct wps_new_ap_settings ap;
1185 pin = os_strchr(cmd, ' ');
1190 if (hwaddr_aton(cmd, bssid)) {
1191 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
1196 new_ssid = os_strchr(pin, ' ');
1197 if (new_ssid == NULL)
1198 return wpas_wps_start_reg(wpa_s, bssid, pin, NULL);
1201 new_auth = os_strchr(new_ssid, ' ');
1202 if (new_auth == NULL)
1206 new_encr = os_strchr(new_auth, ' ');
1207 if (new_encr == NULL)
1211 new_key = os_strchr(new_encr, ' ');
1212 if (new_key == NULL)
1216 os_memset(&ap, 0, sizeof(ap));
1217 ap.ssid_hex = new_ssid;
1220 ap.key_hex = new_key;
1221 return wpas_wps_start_reg(wpa_s, bssid, pin, &ap);
1226 static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant *wpa_s,
1227 char *cmd, char *buf,
1232 const char *pin_txt;
1234 if (!wpa_s->ap_iface)
1237 pos = os_strchr(cmd, ' ');
1241 if (os_strcmp(cmd, "disable") == 0) {
1242 wpas_wps_ap_pin_disable(wpa_s);
1243 return os_snprintf(buf, buflen, "OK\n");
1246 if (os_strcmp(cmd, "random") == 0) {
1248 timeout = atoi(pos);
1249 pin_txt = wpas_wps_ap_pin_random(wpa_s, timeout);
1250 if (pin_txt == NULL)
1252 return os_snprintf(buf, buflen, "%s", pin_txt);
1255 if (os_strcmp(cmd, "get") == 0) {
1256 pin_txt = wpas_wps_ap_pin_get(wpa_s);
1257 if (pin_txt == NULL)
1259 return os_snprintf(buf, buflen, "%s", pin_txt);
1262 if (os_strcmp(cmd, "set") == 0) {
1267 pos = os_strchr(pos, ' ');
1270 timeout = atoi(pos);
1272 if (os_strlen(pin) > buflen)
1274 if (wpas_wps_ap_pin_set(wpa_s, pin, timeout) < 0)
1276 return os_snprintf(buf, buflen, "%s", pin);
1281 #endif /* CONFIG_AP */
1284 #ifdef CONFIG_WPS_ER
1285 static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant *wpa_s,
1288 char *uuid = cmd, *pin, *pos;
1289 u8 addr_buf[ETH_ALEN], *addr = NULL;
1290 pin = os_strchr(uuid, ' ');
1294 pos = os_strchr(pin, ' ');
1297 if (hwaddr_aton(pos, addr_buf) == 0)
1300 return wpas_wps_er_add_pin(wpa_s, addr, uuid, pin);
1304 static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant *wpa_s,
1307 char *uuid = cmd, *pin;
1308 pin = os_strchr(uuid, ' ');
1312 return wpas_wps_er_learn(wpa_s, uuid, pin);
1316 static int wpa_supplicant_ctrl_iface_wps_er_set_config(
1317 struct wpa_supplicant *wpa_s, char *cmd)
1319 char *uuid = cmd, *id;
1320 id = os_strchr(uuid, ' ');
1324 return wpas_wps_er_set_config(wpa_s, uuid, atoi(id));
1328 static int wpa_supplicant_ctrl_iface_wps_er_config(
1329 struct wpa_supplicant *wpa_s, char *cmd)
1336 struct wps_new_ap_settings ap;
1338 pin = os_strchr(cmd, ' ');
1343 new_ssid = os_strchr(pin, ' ');
1344 if (new_ssid == NULL)
1348 new_auth = os_strchr(new_ssid, ' ');
1349 if (new_auth == NULL)
1353 new_encr = os_strchr(new_auth, ' ');
1354 if (new_encr == NULL)
1358 new_key = os_strchr(new_encr, ' ');
1359 if (new_key == NULL)
1363 os_memset(&ap, 0, sizeof(ap));
1364 ap.ssid_hex = new_ssid;
1367 ap.key_hex = new_key;
1368 return wpas_wps_er_config(wpa_s, cmd, pin, &ap);
1372 #ifdef CONFIG_WPS_NFC
1373 static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
1374 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1381 uuid = os_strchr(cmd, ' ');
1386 if (os_strcmp(cmd, "WPS") == 0)
1388 else if (os_strcmp(cmd, "NDEF") == 0)
1393 buf = wpas_wps_er_nfc_config_token(wpa_s, ndef, uuid);
1397 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1399 reply[res++] = '\n';
1406 #endif /* CONFIG_WPS_NFC */
1407 #endif /* CONFIG_WPS_ER */
1409 #endif /* CONFIG_WPS */
1412 #ifdef CONFIG_IBSS_RSN
1413 static int wpa_supplicant_ctrl_iface_ibss_rsn(
1414 struct wpa_supplicant *wpa_s, char *addr)
1418 if (hwaddr_aton(addr, peer)) {
1419 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN: invalid "
1420 "address '%s'", addr);
1424 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN " MACSTR,
1427 return ibss_rsn_start(wpa_s->ibss_rsn, peer);
1429 #endif /* CONFIG_IBSS_RSN */
1432 static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s,
1435 #ifdef IEEE8021X_EAPOL
1438 struct wpa_ssid *ssid;
1440 pos = os_strchr(rsp, '-');
1445 pos = os_strchr(pos, ':');
1450 wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id);
1451 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
1452 (u8 *) pos, os_strlen(pos));
1454 ssid = wpa_config_get_network(wpa_s->conf, id);
1456 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
1461 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s, ssid, rsp,
1463 #else /* IEEE8021X_EAPOL */
1464 wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included");
1466 #endif /* IEEE8021X_EAPOL */
1470 static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
1472 char *buf, size_t buflen)
1474 char *pos, *end, tmp[30];
1475 int res, verbose, wps, ret;
1478 #endif /* CONFIG_HS20 */
1480 if (os_strcmp(params, "-DRIVER") == 0)
1481 return wpa_drv_status(wpa_s, buf, buflen);
1482 verbose = os_strcmp(params, "-VERBOSE") == 0;
1483 wps = os_strcmp(params, "-WPS") == 0;
1486 if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
1487 struct wpa_ssid *ssid = wpa_s->current_ssid;
1488 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
1489 MAC2STR(wpa_s->bssid));
1490 if (ret < 0 || ret >= end - pos)
1494 u8 *_ssid = ssid->ssid;
1495 size_t ssid_len = ssid->ssid_len;
1496 u8 ssid_buf[MAX_SSID_LEN];
1497 if (ssid_len == 0) {
1498 int _res = wpa_drv_get_ssid(wpa_s, ssid_buf);
1505 ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n",
1506 wpa_ssid_txt(_ssid, ssid_len),
1508 if (ret < 0 || ret >= end - pos)
1512 if (wps && ssid->passphrase &&
1513 wpa_key_mgmt_wpa_psk(ssid->key_mgmt) &&
1514 (ssid->mode == WPAS_MODE_AP ||
1515 ssid->mode == WPAS_MODE_P2P_GO)) {
1516 ret = os_snprintf(pos, end - pos,
1519 if (ret < 0 || ret >= end - pos)
1524 ret = os_snprintf(pos, end - pos,
1527 if (ret < 0 || ret >= end - pos)
1532 switch (ssid->mode) {
1533 case WPAS_MODE_INFRA:
1534 ret = os_snprintf(pos, end - pos,
1537 case WPAS_MODE_IBSS:
1538 ret = os_snprintf(pos, end - pos,
1542 ret = os_snprintf(pos, end - pos,
1545 case WPAS_MODE_P2P_GO:
1546 ret = os_snprintf(pos, end - pos,
1549 case WPAS_MODE_P2P_GROUP_FORMATION:
1550 ret = os_snprintf(pos, end - pos,
1551 "mode=P2P GO - group "
1558 if (ret < 0 || ret >= end - pos)
1564 if (wpa_s->ap_iface) {
1565 pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos,
1569 #endif /* CONFIG_AP */
1570 pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose);
1573 if (wpa_s->wpa_state >= WPA_ASSOCIATED &&
1576 #endif /* CONFIG_AP */
1577 wpa_s->sme.sae.state == SAE_ACCEPTED) {
1578 ret = os_snprintf(pos, end - pos, "sae_group=%d\n",
1579 wpa_s->sme.sae.group);
1580 if (ret < 0 || ret >= end - pos)
1584 #endif /* CONFIG_SAE */
1585 ret = os_snprintf(pos, end - pos, "wpa_state=%s\n",
1586 wpa_supplicant_state_txt(wpa_s->wpa_state));
1587 if (ret < 0 || ret >= end - pos)
1592 l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) {
1593 ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp);
1594 if (ret < 0 || ret >= end - pos)
1600 if (wpa_s->global->p2p) {
1601 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
1602 "\n", MAC2STR(wpa_s->global->p2p_dev_addr));
1603 if (ret < 0 || ret >= end - pos)
1607 #endif /* CONFIG_P2P */
1609 ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n",
1610 MAC2STR(wpa_s->own_addr));
1611 if (ret < 0 || ret >= end - pos)
1616 if (wpa_s->current_bss &&
1617 (hs20 = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1618 HS20_IE_VENDOR_TYPE)) &&
1619 wpa_s->wpa_proto == WPA_PROTO_RSN &&
1620 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1623 u8 rel_num = (hs20[6] & 0xf0) >> 4;
1624 release = rel_num + 1;
1626 ret = os_snprintf(pos, end - pos, "hs20=%d\n", release);
1627 if (ret < 0 || ret >= end - pos)
1632 if (wpa_s->current_ssid) {
1633 struct wpa_cred *cred;
1636 for (cred = wpa_s->conf->cred; cred; cred = cred->next) {
1639 if (wpa_s->current_ssid->parent_cred != cred)
1642 if (cred->provisioning_sp) {
1643 ret = os_snprintf(pos, end - pos,
1644 "provisioning_sp=%s\n",
1645 cred->provisioning_sp);
1646 if (ret < 0 || ret >= end - pos)
1655 if (wpa_s->current_bss && wpa_s->current_bss->anqp) {
1656 struct wpabuf *names =
1657 wpa_s->current_bss->anqp->domain_name;
1658 for (i = 0; names && i < cred->num_domain; i++)
1660 if (domain_name_list_contains(
1661 names, cred->domain[i], 1))
1664 if (i == cred->num_domain)
1665 i = 0; /* show first entry by default */
1667 ret = os_snprintf(pos, end - pos, "home_sp=%s\n",
1669 if (ret < 0 || ret >= end - pos)
1674 if (wpa_s->current_bss == NULL ||
1675 wpa_s->current_bss->anqp == NULL)
1678 res = interworking_home_sp_cred(
1680 wpa_s->current_bss->anqp->domain_name);
1688 ret = os_snprintf(pos, end - pos, "sp_type=%s\n", type);
1689 if (ret < 0 || ret >= end - pos)
1696 #endif /* CONFIG_HS20 */
1698 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
1699 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
1700 res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos,
1706 res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose);
1713 uuid_bin2str(wpa_s->wps->uuid, uuid_str, sizeof(uuid_str));
1714 ret = os_snprintf(pos, end - pos, "uuid=%s\n", uuid_str);
1715 if (ret < 0 || ret >= end - pos)
1719 #endif /* CONFIG_WPS */
1722 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_STATE_CHANGE
1723 "id=%d state=%d BSSID=" MACSTR " SSID=%s",
1724 wpa_s->current_ssid ? wpa_s->current_ssid->id : -1,
1726 MAC2STR(wpa_s->bssid),
1727 wpa_s->current_ssid && wpa_s->current_ssid->ssid ?
1728 wpa_ssid_txt(wpa_s->current_ssid->ssid,
1729 wpa_s->current_ssid->ssid_len) : "");
1730 if (wpa_s->wpa_state == WPA_COMPLETED) {
1731 struct wpa_ssid *ssid = wpa_s->current_ssid;
1732 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_CONNECTED
1733 "- connection to " MACSTR
1734 " completed %s [id=%d id_str=%s]",
1735 MAC2STR(wpa_s->bssid), "(auth)",
1736 ssid ? ssid->id : -1,
1737 ssid && ssid->id_str ? ssid->id_str : "");
1739 #endif /* ANDROID */
1745 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s,
1750 struct wpa_ssid *ssid;
1753 /* cmd: "<network id> <BSSID>" */
1754 pos = os_strchr(cmd, ' ');
1759 wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos);
1760 if (hwaddr_aton(pos, bssid)) {
1761 wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos);
1765 ssid = wpa_config_get_network(wpa_s->conf, id);
1767 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
1772 os_memcpy(ssid->bssid, bssid, ETH_ALEN);
1773 ssid->bssid_set = !is_zero_ether_addr(bssid);
1779 static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant *wpa_s,
1780 char *cmd, char *buf,
1784 struct wpa_blacklist *e;
1788 /* cmd: "BLACKLIST [<BSSID>]" */
1792 e = wpa_s->blacklist;
1794 ret = os_snprintf(pos, end - pos, MACSTR "\n",
1796 if (ret < 0 || ret >= end - pos)
1805 if (os_strncmp(cmd, "clear", 5) == 0) {
1806 wpa_blacklist_clear(wpa_s);
1807 os_memcpy(buf, "OK\n", 3);
1811 wpa_printf(MSG_DEBUG, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd);
1812 if (hwaddr_aton(cmd, bssid)) {
1813 wpa_printf(MSG_DEBUG, "CTRL_IFACE: invalid BSSID '%s'", cmd);
1818 * Add the BSSID twice, so its count will be 2, causing it to be
1819 * skipped when processing scan results.
1821 ret = wpa_blacklist_add(wpa_s, bssid);
1824 ret = wpa_blacklist_add(wpa_s, bssid);
1827 os_memcpy(buf, "OK\n", 3);
1832 static const char * debug_level_str(int level)
1853 static int str_to_debug_level(const char *s)
1855 if (os_strcasecmp(s, "EXCESSIVE") == 0)
1856 return MSG_EXCESSIVE;
1857 if (os_strcasecmp(s, "MSGDUMP") == 0)
1859 if (os_strcasecmp(s, "DEBUG") == 0)
1861 if (os_strcasecmp(s, "INFO") == 0)
1863 if (os_strcasecmp(s, "WARNING") == 0)
1865 if (os_strcasecmp(s, "ERROR") == 0)
1871 static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant *wpa_s,
1872 char *cmd, char *buf,
1875 char *pos, *end, *stamp;
1882 /* cmd: "LOG_LEVEL [<level>]" */
1886 ret = os_snprintf(pos, end - pos, "Current level: %s\n"
1888 debug_level_str(wpa_debug_level),
1889 wpa_debug_timestamp);
1890 if (ret < 0 || ret >= end - pos)
1899 stamp = os_strchr(cmd, ' ');
1902 while (*stamp == ' ') {
1907 if (cmd && os_strlen(cmd)) {
1908 int level = str_to_debug_level(cmd);
1911 wpa_debug_level = level;
1914 if (stamp && os_strlen(stamp))
1915 wpa_debug_timestamp = atoi(stamp);
1917 os_memcpy(buf, "OK\n", 3);
1922 static int wpa_supplicant_ctrl_iface_list_networks(
1923 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
1926 struct wpa_ssid *ssid;
1931 ret = os_snprintf(pos, end - pos,
1932 "network id / ssid / bssid / flags\n");
1933 if (ret < 0 || ret >= end - pos)
1937 ssid = wpa_s->conf->ssid;
1939 ret = os_snprintf(pos, end - pos, "%d\t%s",
1941 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
1942 if (ret < 0 || ret >= end - pos)
1945 if (ssid->bssid_set) {
1946 ret = os_snprintf(pos, end - pos, "\t" MACSTR,
1947 MAC2STR(ssid->bssid));
1949 ret = os_snprintf(pos, end - pos, "\tany");
1951 if (ret < 0 || ret >= end - pos)
1954 ret = os_snprintf(pos, end - pos, "\t%s%s%s%s",
1955 ssid == wpa_s->current_ssid ?
1957 ssid->disabled ? "[DISABLED]" : "",
1958 ssid->disabled_until.sec ?
1959 "[TEMP-DISABLED]" : "",
1960 ssid->disabled == 2 ? "[P2P-PERSISTENT]" :
1962 if (ret < 0 || ret >= end - pos)
1965 ret = os_snprintf(pos, end - pos, "\n");
1966 if (ret < 0 || ret >= end - pos)
1977 static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher)
1980 ret = os_snprintf(pos, end - pos, "-");
1981 if (ret < 0 || ret >= end - pos)
1984 ret = wpa_write_ciphers(pos, end, cipher, "+");
1992 static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
1993 const u8 *ie, size_t ie_len)
1995 struct wpa_ie_data data;
1999 ret = os_snprintf(pos, end - pos, "[%s-", proto);
2000 if (ret < 0 || ret >= end - pos)
2004 if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) {
2005 ret = os_snprintf(pos, end - pos, "?]");
2006 if (ret < 0 || ret >= end - pos)
2013 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
2014 ret = os_snprintf(pos, end - pos, "%sEAP",
2015 pos == start ? "" : "+");
2016 if (ret < 0 || ret >= end - pos)
2020 if (data.key_mgmt & WPA_KEY_MGMT_PSK) {
2021 ret = os_snprintf(pos, end - pos, "%sPSK",
2022 pos == start ? "" : "+");
2023 if (ret < 0 || ret >= end - pos)
2027 if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
2028 ret = os_snprintf(pos, end - pos, "%sNone",
2029 pos == start ? "" : "+");
2030 if (ret < 0 || ret >= end - pos)
2034 #ifdef CONFIG_IEEE80211R
2035 if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
2036 ret = os_snprintf(pos, end - pos, "%sFT/EAP",
2037 pos == start ? "" : "+");
2038 if (ret < 0 || ret >= end - pos)
2042 if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) {
2043 ret = os_snprintf(pos, end - pos, "%sFT/PSK",
2044 pos == start ? "" : "+");
2045 if (ret < 0 || ret >= end - pos)
2049 #endif /* CONFIG_IEEE80211R */
2050 #ifdef CONFIG_IEEE80211W
2051 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
2052 ret = os_snprintf(pos, end - pos, "%sEAP-SHA256",
2053 pos == start ? "" : "+");
2054 if (ret < 0 || ret >= end - pos)
2058 if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
2059 ret = os_snprintf(pos, end - pos, "%sPSK-SHA256",
2060 pos == start ? "" : "+");
2061 if (ret < 0 || ret >= end - pos)
2065 #endif /* CONFIG_IEEE80211W */
2067 pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher);
2069 if (data.capabilities & WPA_CAPABILITY_PREAUTH) {
2070 ret = os_snprintf(pos, end - pos, "-preauth");
2071 if (ret < 0 || ret >= end - pos)
2076 ret = os_snprintf(pos, end - pos, "]");
2077 if (ret < 0 || ret >= end - pos)
2086 static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s,
2087 char *pos, char *end,
2088 struct wpabuf *wps_ie)
2095 if (wps_is_selected_pbc_registrar(wps_ie))
2098 else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0))
2100 #endif /* CONFIG_WPS2 */
2101 else if (wps_is_selected_pin_registrar(wps_ie))
2106 ret = os_snprintf(pos, end - pos, "%s", txt);
2107 if (ret >= 0 && ret < end - pos)
2109 wpabuf_free(wps_ie);
2112 #endif /* CONFIG_WPS */
2115 static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s,
2116 char *pos, char *end,
2117 const struct wpa_bss *bss)
2120 struct wpabuf *wps_ie;
2121 wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
2122 return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie);
2123 #else /* CONFIG_WPS */
2125 #endif /* CONFIG_WPS */
2129 /* Format one result on one text line into a buffer. */
2130 static int wpa_supplicant_ctrl_iface_scan_result(
2131 struct wpa_supplicant *wpa_s,
2132 const struct wpa_bss *bss, char *buf, size_t buflen)
2136 const u8 *ie, *ie2, *p2p;
2138 p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
2140 p2p = wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE);
2141 if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN &&
2142 os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) ==
2144 return 0; /* Do not show P2P listen discovery results here */
2149 ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t",
2150 MAC2STR(bss->bssid), bss->freq, bss->level);
2151 if (ret < 0 || ret >= end - pos)
2154 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
2156 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]);
2157 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
2159 pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2, 2 + ie2[1]);
2160 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
2161 if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
2162 ret = os_snprintf(pos, end - pos, "[WEP]");
2163 if (ret < 0 || ret >= end - pos)
2167 if (bss->caps & IEEE80211_CAP_IBSS) {
2168 ret = os_snprintf(pos, end - pos, "[IBSS]");
2169 if (ret < 0 || ret >= end - pos)
2173 if (bss->caps & IEEE80211_CAP_ESS) {
2174 ret = os_snprintf(pos, end - pos, "[ESS]");
2175 if (ret < 0 || ret >= end - pos)
2180 ret = os_snprintf(pos, end - pos, "[P2P]");
2181 if (ret < 0 || ret >= end - pos)
2186 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE) && ie2) {
2187 ret = os_snprintf(pos, end - pos, "[HS20]");
2188 if (ret < 0 || ret >= end - pos)
2192 #endif /* CONFIG_HS20 */
2194 ret = os_snprintf(pos, end - pos, "\t%s",
2195 wpa_ssid_txt(bss->ssid, bss->ssid_len));
2196 if (ret < 0 || ret >= end - pos)
2200 ret = os_snprintf(pos, end - pos, "\n");
2201 if (ret < 0 || ret >= end - pos)
2209 static int wpa_supplicant_ctrl_iface_scan_results(
2210 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
2213 struct wpa_bss *bss;
2218 ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / "
2220 if (ret < 0 || ret >= end - pos)
2224 dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
2225 ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos,
2227 if (ret < 0 || ret >= end - pos)
2236 static int wpa_supplicant_ctrl_iface_select_network(
2237 struct wpa_supplicant *wpa_s, char *cmd)
2240 struct wpa_ssid *ssid;
2242 /* cmd: "<network id>" or "any" */
2243 if (os_strcmp(cmd, "any") == 0) {
2244 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any");
2248 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id);
2250 ssid = wpa_config_get_network(wpa_s->conf, id);
2252 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2253 "network id=%d", id);
2256 if (ssid->disabled == 2) {
2257 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2258 "SELECT_NETWORK with persistent P2P group");
2263 wpa_supplicant_select_network(wpa_s, ssid);
2269 static int wpa_supplicant_ctrl_iface_enable_network(
2270 struct wpa_supplicant *wpa_s, char *cmd)
2273 struct wpa_ssid *ssid;
2275 /* cmd: "<network id>" or "all" */
2276 if (os_strcmp(cmd, "all") == 0) {
2277 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all");
2281 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id);
2283 ssid = wpa_config_get_network(wpa_s->conf, id);
2285 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2286 "network id=%d", id);
2289 if (ssid->disabled == 2) {
2290 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2291 "ENABLE_NETWORK with persistent P2P group");
2295 if (os_strstr(cmd, " no-connect")) {
2300 wpa_supplicant_enable_network(wpa_s, ssid);
2306 static int wpa_supplicant_ctrl_iface_disable_network(
2307 struct wpa_supplicant *wpa_s, char *cmd)
2310 struct wpa_ssid *ssid;
2312 /* cmd: "<network id>" or "all" */
2313 if (os_strcmp(cmd, "all") == 0) {
2314 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all");
2318 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id);
2320 ssid = wpa_config_get_network(wpa_s->conf, id);
2322 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2323 "network id=%d", id);
2326 if (ssid->disabled == 2) {
2327 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2328 "DISABLE_NETWORK with persistent P2P "
2333 wpa_supplicant_disable_network(wpa_s, ssid);
2339 static int wpa_supplicant_ctrl_iface_add_network(
2340 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
2342 struct wpa_ssid *ssid;
2345 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK");
2347 ssid = wpa_config_add_network(wpa_s->conf);
2351 wpas_notify_network_added(wpa_s, ssid);
2354 wpa_config_set_network_defaults(ssid);
2356 ret = os_snprintf(buf, buflen, "%d\n", ssid->id);
2357 if (ret < 0 || (size_t) ret >= buflen)
2363 static int wpa_supplicant_ctrl_iface_remove_network(
2364 struct wpa_supplicant *wpa_s, char *cmd)
2367 struct wpa_ssid *ssid;
2370 /* cmd: "<network id>" or "all" */
2371 if (os_strcmp(cmd, "all") == 0) {
2372 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all");
2373 if (wpa_s->sched_scanning)
2374 wpa_supplicant_cancel_sched_scan(wpa_s);
2376 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2377 if (wpa_s->current_ssid) {
2379 wpa_s->sme.prev_bssid_set = 0;
2380 #endif /* CONFIG_SME */
2381 wpa_sm_set_config(wpa_s->wpa, NULL);
2382 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
2383 wpa_supplicant_deauthenticate(
2384 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2386 ssid = wpa_s->conf->ssid;
2388 struct wpa_ssid *remove_ssid = ssid;
2391 wpas_notify_network_removed(wpa_s, remove_ssid);
2392 wpa_config_remove_network(wpa_s->conf, id);
2398 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id);
2400 ssid = wpa_config_get_network(wpa_s->conf, id);
2402 wpas_notify_network_removed(wpa_s, ssid);
2404 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2409 if (ssid == wpa_s->current_ssid || wpa_s->current_ssid == NULL) {
2411 wpa_s->sme.prev_bssid_set = 0;
2412 #endif /* CONFIG_SME */
2414 * Invalidate the EAP session cache if the current or
2415 * previously used network is removed.
2417 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2420 if (ssid == wpa_s->current_ssid) {
2421 wpa_sm_set_config(wpa_s->wpa, NULL);
2422 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
2424 wpa_supplicant_deauthenticate(wpa_s,
2425 WLAN_REASON_DEAUTH_LEAVING);
2428 was_disabled = ssid->disabled;
2430 if (wpa_config_remove_network(wpa_s->conf, id) < 0) {
2431 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Not able to remove the "
2432 "network id=%d", id);
2436 if (!was_disabled && wpa_s->sched_scanning) {
2437 wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to remove "
2438 "network from filters");
2439 wpa_supplicant_cancel_sched_scan(wpa_s);
2440 wpa_supplicant_req_scan(wpa_s, 0, 0);
2447 static int wpa_supplicant_ctrl_iface_set_network(
2448 struct wpa_supplicant *wpa_s, char *cmd)
2451 struct wpa_ssid *ssid;
2454 /* cmd: "<network id> <variable name> <value>" */
2455 name = os_strchr(cmd, ' ');
2460 value = os_strchr(name, ' ');
2466 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
2468 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
2469 (u8 *) value, os_strlen(value));
2471 ssid = wpa_config_get_network(wpa_s->conf, id);
2473 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2478 if (wpa_config_set(ssid, name, value, 0) < 0) {
2479 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network "
2480 "variable '%s'", name);
2484 if (os_strcmp(name, "bssid") != 0 &&
2485 os_strcmp(name, "priority") != 0)
2486 wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
2488 if (wpa_s->current_ssid == ssid || wpa_s->current_ssid == NULL) {
2490 * Invalidate the EAP session cache if anything in the current
2491 * or previously used configuration changes.
2493 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2496 if ((os_strcmp(name, "psk") == 0 &&
2497 value[0] == '"' && ssid->ssid_len) ||
2498 (os_strcmp(name, "ssid") == 0 && ssid->passphrase))
2499 wpa_config_update_psk(ssid);
2500 else if (os_strcmp(name, "priority") == 0)
2501 wpa_config_update_prio_list(wpa_s->conf);
2507 static int wpa_supplicant_ctrl_iface_get_network(
2508 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
2512 struct wpa_ssid *ssid;
2515 /* cmd: "<network id> <variable name>" */
2516 name = os_strchr(cmd, ' ');
2517 if (name == NULL || buflen == 0)
2522 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
2525 ssid = wpa_config_get_network(wpa_s->conf, id);
2527 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2532 value = wpa_config_get_no_key(ssid, name);
2533 if (value == NULL) {
2534 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
2535 "variable '%s'", name);
2539 res = os_strlcpy(buf, value, buflen);
2540 if (res >= buflen) {
2551 static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant *wpa_s,
2552 char *buf, size_t buflen)
2555 struct wpa_cred *cred;
2560 ret = os_snprintf(pos, end - pos,
2561 "cred id / realm / username / domain / imsi\n");
2562 if (ret < 0 || ret >= end - pos)
2566 cred = wpa_s->conf->cred;
2568 ret = os_snprintf(pos, end - pos, "%d\t%s\t%s\t%s\t%s\n",
2569 cred->id, cred->realm ? cred->realm : "",
2570 cred->username ? cred->username : "",
2571 cred->domain ? cred->domain[0] : "",
2572 cred->imsi ? cred->imsi : "");
2573 if (ret < 0 || ret >= end - pos)
2584 static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant *wpa_s,
2585 char *buf, size_t buflen)
2587 struct wpa_cred *cred;
2590 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_CRED");
2592 cred = wpa_config_add_cred(wpa_s->conf);
2596 ret = os_snprintf(buf, buflen, "%d\n", cred->id);
2597 if (ret < 0 || (size_t) ret >= buflen)
2603 static int wpas_ctrl_remove_cred(struct wpa_supplicant *wpa_s,
2604 struct wpa_cred *cred)
2606 struct wpa_ssid *ssid;
2609 if (cred == NULL || wpa_config_remove_cred(wpa_s->conf, cred->id) < 0) {
2610 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred");
2614 /* Remove any network entry created based on the removed credential */
2615 ssid = wpa_s->conf->ssid;
2617 if (ssid->parent_cred == cred) {
2618 wpa_printf(MSG_DEBUG, "Remove network id %d since it "
2619 "used the removed credential", ssid->id);
2620 os_snprintf(str, sizeof(str), "%d", ssid->id);
2622 wpa_supplicant_ctrl_iface_remove_network(wpa_s, str);
2631 static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s,
2635 struct wpa_cred *cred, *prev;
2637 /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or
2638 * "provisioning_sp=<FQDN> */
2639 if (os_strcmp(cmd, "all") == 0) {
2640 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED all");
2641 cred = wpa_s->conf->cred;
2645 wpas_ctrl_remove_cred(wpa_s, prev);
2650 if (os_strncmp(cmd, "sp_fqdn=", 8) == 0) {
2651 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
2653 cred = wpa_s->conf->cred;
2659 for (i = 0; i < prev->num_domain; i++) {
2660 if (os_strcmp(prev->domain[i], cmd + 8)
2663 wpas_ctrl_remove_cred(wpa_s, prev);
2671 if (os_strncmp(cmd, "provisioning_sp=", 16) == 0) {
2672 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'",
2674 cred = wpa_s->conf->cred;
2678 if (prev->provisioning_sp &&
2679 os_strcmp(prev->provisioning_sp, cmd + 16) == 0)
2680 wpas_ctrl_remove_cred(wpa_s, prev);
2686 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED id=%d", id);
2688 cred = wpa_config_get_cred(wpa_s->conf, id);
2689 return wpas_ctrl_remove_cred(wpa_s, cred);
2693 static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant *wpa_s,
2697 struct wpa_cred *cred;
2700 /* cmd: "<cred id> <variable name> <value>" */
2701 name = os_strchr(cmd, ' ');
2706 value = os_strchr(name, ' ');
2712 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_CRED id=%d name='%s'",
2714 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
2715 (u8 *) value, os_strlen(value));
2717 cred = wpa_config_get_cred(wpa_s->conf, id);
2719 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
2724 if (wpa_config_set_cred(cred, name, value, 0) < 0) {
2725 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set cred "
2726 "variable '%s'", name);
2734 #ifndef CONFIG_NO_CONFIG_WRITE
2735 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s)
2739 if (!wpa_s->conf->update_config) {
2740 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
2741 "to update configuration (update_config=0)");
2745 ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
2747 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to "
2748 "update configuration");
2750 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration"
2756 #endif /* CONFIG_NO_CONFIG_WRITE */
2759 struct cipher_info {
2765 static const struct cipher_info ciphers[] = {
2766 { WPA_DRIVER_CAPA_ENC_CCMP_256, "CCMP-256", 0 },
2767 { WPA_DRIVER_CAPA_ENC_GCMP_256, "GCMP-256", 0 },
2768 { WPA_DRIVER_CAPA_ENC_CCMP, "CCMP", 0 },
2769 { WPA_DRIVER_CAPA_ENC_GCMP, "GCMP", 0 },
2770 { WPA_DRIVER_CAPA_ENC_TKIP, "TKIP", 0 },
2771 { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE, "NONE", 0 },
2772 { WPA_DRIVER_CAPA_ENC_WEP104, "WEP104", 1 },
2773 { WPA_DRIVER_CAPA_ENC_WEP40, "WEP40", 1 }
2777 static int ctrl_iface_get_capability_pairwise(int res, char *strict,
2778 struct wpa_driver_capa *capa,
2779 char *buf, size_t buflen)
2792 len = os_strlcpy(buf, "CCMP TKIP NONE", buflen);
2798 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
2799 if (!ciphers[i].group_only && capa->enc & ciphers[i].capa) {
2800 ret = os_snprintf(pos, end - pos, "%s%s",
2801 pos == buf ? "" : " ",
2803 if (ret < 0 || ret >= end - pos)
2813 static int ctrl_iface_get_capability_group(int res, char *strict,
2814 struct wpa_driver_capa *capa,
2815 char *buf, size_t buflen)
2828 len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen);
2834 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
2835 if (capa->enc & ciphers[i].capa) {
2836 ret = os_snprintf(pos, end - pos, "%s%s",
2837 pos == buf ? "" : " ",
2839 if (ret < 0 || ret >= end - pos)
2849 static int ctrl_iface_get_capability_key_mgmt(int res, char *strict,
2850 struct wpa_driver_capa *capa,
2851 char *buf, size_t buflen)
2863 len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
2870 ret = os_snprintf(pos, end - pos, "NONE IEEE8021X");
2871 if (ret < 0 || ret >= end - pos)
2875 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
2876 WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
2877 ret = os_snprintf(pos, end - pos, " WPA-EAP");
2878 if (ret < 0 || ret >= end - pos)
2883 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
2884 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
2885 ret = os_snprintf(pos, end - pos, " WPA-PSK");
2886 if (ret < 0 || ret >= end - pos)
2891 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
2892 ret = os_snprintf(pos, end - pos, " WPA-NONE");
2893 if (ret < 0 || ret >= end - pos)
2902 static int ctrl_iface_get_capability_proto(int res, char *strict,
2903 struct wpa_driver_capa *capa,
2904 char *buf, size_t buflen)
2916 len = os_strlcpy(buf, "RSN WPA", buflen);
2922 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
2923 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
2924 ret = os_snprintf(pos, end - pos, "%sRSN",
2925 pos == buf ? "" : " ");
2926 if (ret < 0 || ret >= end - pos)
2931 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
2932 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
2933 ret = os_snprintf(pos, end - pos, "%sWPA",
2934 pos == buf ? "" : " ");
2935 if (ret < 0 || ret >= end - pos)
2944 static int ctrl_iface_get_capability_auth_alg(int res, char *strict,
2945 struct wpa_driver_capa *capa,
2946 char *buf, size_t buflen)
2958 len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen);
2964 if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) {
2965 ret = os_snprintf(pos, end - pos, "%sOPEN",
2966 pos == buf ? "" : " ");
2967 if (ret < 0 || ret >= end - pos)
2972 if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) {
2973 ret = os_snprintf(pos, end - pos, "%sSHARED",
2974 pos == buf ? "" : " ");
2975 if (ret < 0 || ret >= end - pos)
2980 if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) {
2981 ret = os_snprintf(pos, end - pos, "%sLEAP",
2982 pos == buf ? "" : " ");
2983 if (ret < 0 || ret >= end - pos)
2992 static int ctrl_iface_get_capability_modes(int res, char *strict,
2993 struct wpa_driver_capa *capa,
2994 char *buf, size_t buflen)
3006 len = os_strlcpy(buf, "IBSS AP", buflen);
3012 if (capa->flags & WPA_DRIVER_FLAGS_IBSS) {
3013 ret = os_snprintf(pos, end - pos, "%sIBSS",
3014 pos == buf ? "" : " ");
3015 if (ret < 0 || ret >= end - pos)
3020 if (capa->flags & WPA_DRIVER_FLAGS_AP) {
3021 ret = os_snprintf(pos, end - pos, "%sAP",
3022 pos == buf ? "" : " ");
3023 if (ret < 0 || ret >= end - pos)
3032 static int ctrl_iface_get_capability_channels(struct wpa_supplicant *wpa_s,
3033 char *buf, size_t buflen)
3035 struct hostapd_channel_data *chnl;
3037 char *pos, *end, *hmode;
3042 for (j = 0; j < wpa_s->hw.num_modes; j++) {
3043 switch (wpa_s->hw.modes[j].mode) {
3044 case HOSTAPD_MODE_IEEE80211B:
3047 case HOSTAPD_MODE_IEEE80211G:
3050 case HOSTAPD_MODE_IEEE80211A:
3053 case HOSTAPD_MODE_IEEE80211AD:
3059 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:", hmode);
3060 if (ret < 0 || ret >= end - pos)
3063 chnl = wpa_s->hw.modes[j].channels;
3064 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
3065 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
3067 ret = os_snprintf(pos, end - pos, " %d", chnl[i].chan);
3068 if (ret < 0 || ret >= end - pos)
3072 ret = os_snprintf(pos, end - pos, "\n");
3073 if (ret < 0 || ret >= end - pos)
3082 static int ctrl_iface_get_capability_freq(struct wpa_supplicant *wpa_s,
3083 char *buf, size_t buflen)
3085 struct hostapd_channel_data *chnl;
3087 char *pos, *end, *hmode;
3092 for (j = 0; j < wpa_s->hw.num_modes; j++) {
3093 switch (wpa_s->hw.modes[j].mode) {
3094 case HOSTAPD_MODE_IEEE80211B:
3097 case HOSTAPD_MODE_IEEE80211G:
3100 case HOSTAPD_MODE_IEEE80211A:
3103 case HOSTAPD_MODE_IEEE80211AD:
3109 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:\n",
3111 if (ret < 0 || ret >= end - pos)
3114 chnl = wpa_s->hw.modes[j].channels;
3115 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
3116 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
3118 ret = os_snprintf(pos, end - pos, " %d = %d MHz%s%s\n",
3119 chnl[i].chan, chnl[i].freq,
3120 chnl[i].flag & HOSTAPD_CHAN_NO_IBSS ?
3122 chnl[i].flag & HOSTAPD_CHAN_RADAR ?
3125 if (ret < 0 || ret >= end - pos)
3129 ret = os_snprintf(pos, end - pos, "\n");
3130 if (ret < 0 || ret >= end - pos)
3139 static int wpa_supplicant_ctrl_iface_get_capability(
3140 struct wpa_supplicant *wpa_s, const char *_field, char *buf,
3143 struct wpa_driver_capa capa;
3149 /* Determine whether or not strict checking was requested */
3150 len = os_strlcpy(field, _field, sizeof(field));
3151 if (len >= sizeof(field))
3153 strict = os_strchr(field, ' ');
3154 if (strict != NULL) {
3156 if (os_strcmp(strict, "strict") != 0)
3160 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
3161 field, strict ? strict : "");
3163 if (os_strcmp(field, "eap") == 0) {
3164 return eap_get_names(buf, buflen);
3167 res = wpa_drv_get_capa(wpa_s, &capa);
3169 if (os_strcmp(field, "pairwise") == 0)
3170 return ctrl_iface_get_capability_pairwise(res, strict, &capa,
3173 if (os_strcmp(field, "group") == 0)
3174 return ctrl_iface_get_capability_group(res, strict, &capa,
3177 if (os_strcmp(field, "key_mgmt") == 0)
3178 return ctrl_iface_get_capability_key_mgmt(res, strict, &capa,
3181 if (os_strcmp(field, "proto") == 0)
3182 return ctrl_iface_get_capability_proto(res, strict, &capa,
3185 if (os_strcmp(field, "auth_alg") == 0)
3186 return ctrl_iface_get_capability_auth_alg(res, strict, &capa,
3189 if (os_strcmp(field, "modes") == 0)
3190 return ctrl_iface_get_capability_modes(res, strict, &capa,
3193 if (os_strcmp(field, "channels") == 0)
3194 return ctrl_iface_get_capability_channels(wpa_s, buf, buflen);
3196 if (os_strcmp(field, "freq") == 0)
3197 return ctrl_iface_get_capability_freq(wpa_s, buf, buflen);
3200 if (os_strcmp(field, "tdls") == 0)
3201 return ctrl_iface_get_capability_tdls(wpa_s, buf, buflen);
3202 #endif /* CONFIG_TDLS */
3204 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
3211 #ifdef CONFIG_INTERWORKING
3212 static char * anqp_add_hex(char *pos, char *end, const char *title,
3213 struct wpabuf *data)
3223 ret = os_snprintf(pos, end - pos, "%s=", title);
3224 if (ret < 0 || ret >= end - pos)
3228 d = wpabuf_head_u8(data);
3229 for (i = 0; i < wpabuf_len(data); i++) {
3230 ret = os_snprintf(pos, end - pos, "%02x", *d++);
3231 if (ret < 0 || ret >= end - pos)
3236 ret = os_snprintf(pos, end - pos, "\n");
3237 if (ret < 0 || ret >= end - pos)
3243 #endif /* CONFIG_INTERWORKING */
3246 static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
3247 unsigned long mask, char *buf, size_t buflen)
3257 if (mask & WPA_BSS_MASK_ID) {
3258 ret = os_snprintf(pos, end - pos, "id=%u\n", bss->id);
3259 if (ret < 0 || ret >= end - pos)
3264 if (mask & WPA_BSS_MASK_BSSID) {
3265 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
3266 MAC2STR(bss->bssid));
3267 if (ret < 0 || ret >= end - pos)
3272 if (mask & WPA_BSS_MASK_FREQ) {
3273 ret = os_snprintf(pos, end - pos, "freq=%d\n", bss->freq);
3274 if (ret < 0 || ret >= end - pos)
3279 if (mask & WPA_BSS_MASK_BEACON_INT) {
3280 ret = os_snprintf(pos, end - pos, "beacon_int=%d\n",
3282 if (ret < 0 || ret >= end - pos)
3287 if (mask & WPA_BSS_MASK_CAPABILITIES) {
3288 ret = os_snprintf(pos, end - pos, "capabilities=0x%04x\n",
3290 if (ret < 0 || ret >= end - pos)
3295 if (mask & WPA_BSS_MASK_QUAL) {
3296 ret = os_snprintf(pos, end - pos, "qual=%d\n", bss->qual);
3297 if (ret < 0 || ret >= end - pos)
3302 if (mask & WPA_BSS_MASK_NOISE) {
3303 ret = os_snprintf(pos, end - pos, "noise=%d\n", bss->noise);
3304 if (ret < 0 || ret >= end - pos)
3309 if (mask & WPA_BSS_MASK_LEVEL) {
3310 ret = os_snprintf(pos, end - pos, "level=%d\n", bss->level);
3311 if (ret < 0 || ret >= end - pos)
3316 if (mask & WPA_BSS_MASK_TSF) {
3317 ret = os_snprintf(pos, end - pos, "tsf=%016llu\n",
3318 (unsigned long long) bss->tsf);
3319 if (ret < 0 || ret >= end - pos)
3324 if (mask & WPA_BSS_MASK_AGE) {
3325 struct os_reltime now;
3327 os_get_reltime(&now);
3328 ret = os_snprintf(pos, end - pos, "age=%d\n",
3329 (int) (now.sec - bss->last_update.sec));
3330 if (ret < 0 || ret >= end - pos)
3335 if (mask & WPA_BSS_MASK_IE) {
3336 ret = os_snprintf(pos, end - pos, "ie=");
3337 if (ret < 0 || ret >= end - pos)
3341 ie = (const u8 *) (bss + 1);
3342 for (i = 0; i < bss->ie_len; i++) {
3343 ret = os_snprintf(pos, end - pos, "%02x", *ie++);
3344 if (ret < 0 || ret >= end - pos)
3349 ret = os_snprintf(pos, end - pos, "\n");
3350 if (ret < 0 || ret >= end - pos)
3355 if (mask & WPA_BSS_MASK_FLAGS) {
3356 ret = os_snprintf(pos, end - pos, "flags=");
3357 if (ret < 0 || ret >= end - pos)
3361 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
3363 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie,
3365 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
3367 pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2,
3369 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
3370 if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
3371 ret = os_snprintf(pos, end - pos, "[WEP]");
3372 if (ret < 0 || ret >= end - pos)
3376 if (bss->caps & IEEE80211_CAP_IBSS) {
3377 ret = os_snprintf(pos, end - pos, "[IBSS]");
3378 if (ret < 0 || ret >= end - pos)
3382 if (bss->caps & IEEE80211_CAP_ESS) {
3383 ret = os_snprintf(pos, end - pos, "[ESS]");
3384 if (ret < 0 || ret >= end - pos)
3388 if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
3389 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
3390 ret = os_snprintf(pos, end - pos, "[P2P]");
3391 if (ret < 0 || ret >= end - pos)
3396 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) {
3397 ret = os_snprintf(pos, end - pos, "[HS20]");
3398 if (ret < 0 || ret >= end - pos)
3402 #endif /* CONFIG_HS20 */
3404 ret = os_snprintf(pos, end - pos, "\n");
3405 if (ret < 0 || ret >= end - pos)
3410 if (mask & WPA_BSS_MASK_SSID) {
3411 ret = os_snprintf(pos, end - pos, "ssid=%s\n",
3412 wpa_ssid_txt(bss->ssid, bss->ssid_len));
3413 if (ret < 0 || ret >= end - pos)
3419 if (mask & WPA_BSS_MASK_WPS_SCAN) {
3420 ie = (const u8 *) (bss + 1);
3421 ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end);
3422 if (ret < 0 || ret >= end - pos)
3426 #endif /* CONFIG_WPS */
3429 if (mask & WPA_BSS_MASK_P2P_SCAN) {
3430 ie = (const u8 *) (bss + 1);
3431 ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end);
3432 if (ret < 0 || ret >= end - pos)
3436 #endif /* CONFIG_P2P */
3438 #ifdef CONFIG_WIFI_DISPLAY
3439 if (mask & WPA_BSS_MASK_WIFI_DISPLAY) {
3441 ie = (const u8 *) (bss + 1);
3442 wfd = ieee802_11_vendor_ie_concat(ie, bss->ie_len,
3443 WFD_IE_VENDOR_TYPE);
3445 ret = os_snprintf(pos, end - pos, "wfd_subelems=");
3446 if (ret < 0 || ret >= end - pos) {
3452 pos += wpa_snprintf_hex(pos, end - pos,
3457 ret = os_snprintf(pos, end - pos, "\n");
3458 if (ret < 0 || ret >= end - pos)
3463 #endif /* CONFIG_WIFI_DISPLAY */
3465 #ifdef CONFIG_INTERWORKING
3466 if ((mask & WPA_BSS_MASK_INTERNETW) && bss->anqp) {
3467 struct wpa_bss_anqp *anqp = bss->anqp;
3468 pos = anqp_add_hex(pos, end, "anqp_venue_name",
3470 pos = anqp_add_hex(pos, end, "anqp_network_auth_type",
3471 anqp->network_auth_type);
3472 pos = anqp_add_hex(pos, end, "anqp_roaming_consortium",
3473 anqp->roaming_consortium);
3474 pos = anqp_add_hex(pos, end, "anqp_ip_addr_type_availability",
3475 anqp->ip_addr_type_availability);
3476 pos = anqp_add_hex(pos, end, "anqp_nai_realm",
3478 pos = anqp_add_hex(pos, end, "anqp_3gpp", anqp->anqp_3gpp);
3479 pos = anqp_add_hex(pos, end, "anqp_domain_name",
3482 pos = anqp_add_hex(pos, end, "hs20_operator_friendly_name",
3483 anqp->hs20_operator_friendly_name);
3484 pos = anqp_add_hex(pos, end, "hs20_wan_metrics",
3485 anqp->hs20_wan_metrics);
3486 pos = anqp_add_hex(pos, end, "hs20_connection_capability",
3487 anqp->hs20_connection_capability);
3488 pos = anqp_add_hex(pos, end, "hs20_operating_class",
3489 anqp->hs20_operating_class);
3490 pos = anqp_add_hex(pos, end, "hs20_osu_providers_list",
3491 anqp->hs20_osu_providers_list);
3492 #endif /* CONFIG_HS20 */
3494 #endif /* CONFIG_INTERWORKING */
3496 if (mask & WPA_BSS_MASK_DELIM) {
3497 ret = os_snprintf(pos, end - pos, "====\n");
3498 if (ret < 0 || ret >= end - pos)
3507 static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
3508 const char *cmd, char *buf,
3513 struct wpa_bss *bss;
3514 struct wpa_bss *bsslast = NULL;
3515 struct dl_list *next;
3519 unsigned long mask = WPA_BSS_MASK_ALL;
3521 if (os_strncmp(cmd, "RANGE=", 6) == 0) {
3522 if (os_strncmp(cmd + 6, "ALL", 3) == 0) {
3523 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss,
3525 bsslast = dl_list_last(&wpa_s->bss_id, struct wpa_bss,
3527 } else { /* N1-N2 */
3528 unsigned int id1, id2;
3530 if ((ctmp = os_strchr(cmd + 6, '-')) == NULL) {
3531 wpa_printf(MSG_INFO, "Wrong BSS range "
3536 if (*(cmd + 6) == '-')
3539 id1 = atoi(cmd + 6);
3541 if (*ctmp >= '0' && *ctmp <= '9')
3544 id2 = (unsigned int) -1;
3545 bss = wpa_bss_get_id_range(wpa_s, id1, id2);
3546 if (id2 == (unsigned int) -1)
3547 bsslast = dl_list_last(&wpa_s->bss_id,
3551 bsslast = wpa_bss_get_id(wpa_s, id2);
3552 if (bsslast == NULL && bss && id2 > id1) {
3553 struct wpa_bss *tmp = bss;
3555 next = tmp->list_id.next;
3556 if (next == &wpa_s->bss_id)
3558 tmp = dl_list_entry(
3559 next, struct wpa_bss,
3568 } else if (os_strncmp(cmd, "FIRST", 5) == 0)
3569 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, list_id);
3570 else if (os_strncmp(cmd, "LAST", 4) == 0)
3571 bss = dl_list_last(&wpa_s->bss_id, struct wpa_bss, list_id);
3572 else if (os_strncmp(cmd, "ID-", 3) == 0) {
3574 bss = wpa_bss_get_id(wpa_s, i);
3575 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
3577 bss = wpa_bss_get_id(wpa_s, i);
3579 next = bss->list_id.next;
3580 if (next == &wpa_s->bss_id)
3583 bss = dl_list_entry(next, struct wpa_bss,
3587 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
3588 if (hwaddr_aton(cmd + 13, bssid) == 0)
3589 bss = wpa_bss_get_p2p_dev_addr(wpa_s, bssid);
3592 #endif /* CONFIG_P2P */
3593 } else if (hwaddr_aton(cmd, bssid) == 0)
3594 bss = wpa_bss_get_bssid(wpa_s, bssid);
3596 struct wpa_bss *tmp;
3599 dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id)
3608 if ((ctmp = os_strstr(cmd, "MASK=")) != NULL) {
3609 mask = strtoul(ctmp + 5, NULL, 0x10);
3611 mask = WPA_BSS_MASK_ALL;
3617 if (bsslast == NULL)
3620 len = print_bss_info(wpa_s, bss, mask, buf, buflen);
3624 if (bss == bsslast) {
3625 if ((mask & WPA_BSS_MASK_DELIM) && len &&
3626 (bss == dl_list_last(&wpa_s->bss_id,
3627 struct wpa_bss, list_id)))
3628 os_snprintf(buf - 5, 5, "####\n");
3631 next = bss->list_id.next;
3632 if (next == &wpa_s->bss_id)
3634 bss = dl_list_entry(next, struct wpa_bss, list_id);
3635 } while (bss && len);
3641 static int wpa_supplicant_ctrl_iface_ap_scan(
3642 struct wpa_supplicant *wpa_s, char *cmd)
3644 int ap_scan = atoi(cmd);
3645 return wpa_supplicant_set_ap_scan(wpa_s, ap_scan);
3649 static int wpa_supplicant_ctrl_iface_scan_interval(
3650 struct wpa_supplicant *wpa_s, char *cmd)
3652 int scan_int = atoi(cmd);
3653 return wpa_supplicant_set_scan_interval(wpa_s, scan_int);
3657 static int wpa_supplicant_ctrl_iface_bss_expire_age(
3658 struct wpa_supplicant *wpa_s, char *cmd)
3660 int expire_age = atoi(cmd);
3661 return wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age);
3665 static int wpa_supplicant_ctrl_iface_bss_expire_count(
3666 struct wpa_supplicant *wpa_s, char *cmd)
3668 int expire_count = atoi(cmd);
3669 return wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count);
3673 static int wpa_supplicant_ctrl_iface_bss_flush(
3674 struct wpa_supplicant *wpa_s, char *cmd)
3676 int flush_age = atoi(cmd);
3679 wpa_bss_flush(wpa_s);
3681 wpa_bss_flush_by_age(wpa_s, flush_age);
3686 static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s)
3688 wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication");
3689 /* MLME-DELETEKEYS.request */
3690 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL, 0);
3691 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL, 0);
3692 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL, 0);
3693 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL, 0);
3694 #ifdef CONFIG_IEEE80211W
3695 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL, 0);
3696 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL, 0);
3697 #endif /* CONFIG_IEEE80211W */
3699 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, wpa_s->bssid, 0, 0, NULL, 0, NULL,
3701 /* MLME-SETPROTECTION.request(None) */
3702 wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid,
3703 MLME_SETPROTECTION_PROTECT_TYPE_NONE,
3704 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE);
3705 wpa_sm_drop_sa(wpa_s->wpa);
3709 static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s,
3712 #ifdef CONFIG_NO_SCAN_PROCESSING
3714 #else /* CONFIG_NO_SCAN_PROCESSING */
3716 struct wpa_bss *bss;
3717 struct wpa_ssid *ssid = wpa_s->current_ssid;
3719 if (hwaddr_aton(addr, bssid)) {
3720 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid "
3721 "address '%s'", addr);
3725 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR, MAC2STR(bssid));
3728 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network "
3729 "configuration known for the target AP");
3733 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
3735 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found "
3741 * TODO: Find best network configuration block from configuration to
3742 * allow roaming to other networks
3745 wpa_s->reassociate = 1;
3746 wpa_supplicant_connect(wpa_s, bss, ssid);
3749 #endif /* CONFIG_NO_SCAN_PROCESSING */
3754 static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd)
3756 unsigned int timeout = atoi(cmd);
3757 enum p2p_discovery_type type = P2P_FIND_START_WITH_FULL;
3758 u8 dev_id[ETH_ALEN], *_dev_id = NULL;
3759 u8 dev_type[WPS_DEV_TYPE_LEN], *_dev_type = NULL;
3761 unsigned int search_delay;
3763 if (os_strstr(cmd, "type=social"))
3764 type = P2P_FIND_ONLY_SOCIAL;
3765 else if (os_strstr(cmd, "type=progressive"))
3766 type = P2P_FIND_PROGRESSIVE;
3768 pos = os_strstr(cmd, "dev_id=");
3771 if (hwaddr_aton(pos, dev_id))
3776 pos = os_strstr(cmd, "dev_type=");
3779 if (wps_dev_type_str2bin(pos, dev_type) < 0)
3781 _dev_type = dev_type;
3784 pos = os_strstr(cmd, "delay=");
3787 search_delay = atoi(pos);
3789 search_delay = wpas_p2p_search_delay(wpa_s);
3791 return wpas_p2p_find(wpa_s, timeout, type, _dev_type != NULL, _dev_type,
3792 _dev_id, search_delay);
3796 static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd,
3797 char *buf, size_t buflen)
3802 enum p2p_wps_method wps_method;
3805 int persistent_group, persistent_id = -1;
3814 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad]
3815 * [persistent|persistent=<network id>]
3816 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
3819 if (hwaddr_aton(cmd, addr))
3827 persistent_group = os_strstr(pos, " persistent") != NULL;
3828 pos2 = os_strstr(pos, " persistent=");
3830 struct wpa_ssid *ssid;
3831 persistent_id = atoi(pos2 + 12);
3832 ssid = wpa_config_get_network(wpa_s->conf, persistent_id);
3833 if (ssid == NULL || ssid->disabled != 2 ||
3834 ssid->mode != WPAS_MODE_P2P_GO) {
3835 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3836 "SSID id=%d for persistent P2P group (GO)",
3841 join = os_strstr(pos, " join") != NULL;
3842 auth = os_strstr(pos, " auth") != NULL;
3843 automatic = os_strstr(pos, " auto") != NULL;
3844 pd = os_strstr(pos, " provdisc") != NULL;
3845 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
3846 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
3849 pos2 = os_strstr(pos, " go_intent=");
3852 go_intent = atoi(pos2);
3853 if (go_intent < 0 || go_intent > 15)
3857 pos2 = os_strstr(pos, " freq=");
3865 if (os_strncmp(pos, "pin", 3) == 0) {
3866 /* Request random PIN (to be displayed) and enable the PIN */
3867 wps_method = WPS_PIN_DISPLAY;
3868 } else if (os_strncmp(pos, "pbc", 3) == 0) {
3869 wps_method = WPS_PBC;
3872 pos = os_strchr(pin, ' ');
3873 wps_method = WPS_PIN_KEYPAD;
3876 if (os_strncmp(pos, "display", 7) == 0)
3877 wps_method = WPS_PIN_DISPLAY;
3879 if (!wps_pin_str_valid(pin)) {
3880 os_memcpy(buf, "FAIL-INVALID-PIN\n", 17);
3885 new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method,
3886 persistent_group, automatic, join,
3887 auth, go_intent, freq, persistent_id, pd,
3889 if (new_pin == -2) {
3890 os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
3893 if (new_pin == -3) {
3894 os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
3899 if (wps_method == WPS_PIN_DISPLAY && pin == NULL) {
3900 ret = os_snprintf(buf, buflen, "%08d", new_pin);
3901 if (ret < 0 || (size_t) ret >= buflen)
3906 os_memcpy(buf, "OK\n", 3);
3911 static int p2p_ctrl_listen(struct wpa_supplicant *wpa_s, char *cmd)
3913 unsigned int timeout = atoi(cmd);
3914 return wpas_p2p_listen(wpa_s, timeout);
3918 static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd)
3922 enum wpas_p2p_prov_disc_use use = WPAS_P2P_PD_FOR_GO_NEG;
3924 /* <addr> <config method> [join|auto] */
3926 if (hwaddr_aton(cmd, addr))
3934 if (os_strstr(pos, " join") != NULL)
3935 use = WPAS_P2P_PD_FOR_JOIN;
3936 else if (os_strstr(pos, " auto") != NULL)
3937 use = WPAS_P2P_PD_AUTO;
3939 return wpas_p2p_prov_disc(wpa_s, addr, pos, use);
3943 static int p2p_get_passphrase(struct wpa_supplicant *wpa_s, char *buf,
3946 struct wpa_ssid *ssid = wpa_s->current_ssid;
3948 if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO ||
3949 ssid->passphrase == NULL)
3952 os_strlcpy(buf, ssid->passphrase, buflen);
3953 return os_strlen(buf);
3957 static int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd,
3958 char *buf, size_t buflen)
3962 u8 dst_buf[ETH_ALEN], *dst;
3963 struct wpabuf *tlvs;
3967 if (hwaddr_aton(cmd, dst_buf))
3970 if (dst[0] == 0 && dst[1] == 0 && dst[2] == 0 &&
3971 dst[3] == 0 && dst[4] == 0 && dst[5] == 0)
3978 if (os_strncmp(pos, "upnp ", 5) == 0) {
3981 if (hexstr2bin(pos, &version, 1) < 0)
3987 ref = wpas_p2p_sd_request_upnp(wpa_s, dst, version, pos);
3988 #ifdef CONFIG_WIFI_DISPLAY
3989 } else if (os_strncmp(pos, "wifi-display ", 13) == 0) {
3990 ref = wpas_p2p_sd_request_wifi_display(wpa_s, dst, pos + 13);
3991 #endif /* CONFIG_WIFI_DISPLAY */
3993 len = os_strlen(pos);
3997 tlvs = wpabuf_alloc(len);
4000 if (hexstr2bin(pos, wpabuf_put(tlvs, len), len) < 0) {
4005 ref = wpas_p2p_sd_request(wpa_s, dst, tlvs);
4010 res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref);
4011 if (res < 0 || (unsigned) res >= buflen)
4017 static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s,
4020 long long unsigned val;
4022 if (sscanf(cmd, "%llx", &val) != 1)
4025 return wpas_p2p_sd_cancel_request(wpa_s, req);
4029 static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant *wpa_s, char *cmd)
4034 struct wpabuf *resp_tlvs;
4038 pos = os_strchr(cmd, ' ');
4046 if (hwaddr_aton(pos, dst))
4053 pos2 = os_strchr(pos, ' ');
4057 dialog_token = atoi(pos);
4059 len = os_strlen(pos2);
4063 resp_tlvs = wpabuf_alloc(len);
4064 if (resp_tlvs == NULL)
4066 if (hexstr2bin(pos2, wpabuf_put(resp_tlvs, len), len) < 0) {
4067 wpabuf_free(resp_tlvs);
4071 wpas_p2p_sd_response(wpa_s, freq, dst, dialog_token, resp_tlvs);
4072 wpabuf_free(resp_tlvs);
4077 static int p2p_ctrl_serv_disc_external(struct wpa_supplicant *wpa_s,
4080 if (os_strcmp(cmd, "0") && os_strcmp(cmd, "1"))
4082 wpa_s->p2p_sd_over_ctrl_iface = atoi(cmd);
4087 static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant *wpa_s,
4092 struct wpabuf *query, *resp;
4094 pos = os_strchr(cmd, ' ');
4099 len = os_strlen(cmd);
4103 query = wpabuf_alloc(len);
4106 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
4111 len = os_strlen(pos);
4117 resp = wpabuf_alloc(len);
4122 if (hexstr2bin(pos, wpabuf_put(resp, len), len) < 0) {
4128 if (wpas_p2p_service_add_bonjour(wpa_s, query, resp) < 0) {
4137 static int p2p_ctrl_service_add_upnp(struct wpa_supplicant *wpa_s, char *cmd)
4142 pos = os_strchr(cmd, ' ');
4147 if (hexstr2bin(cmd, &version, 1) < 0)
4150 return wpas_p2p_service_add_upnp(wpa_s, version, pos);
4154 static int p2p_ctrl_service_add(struct wpa_supplicant *wpa_s, char *cmd)
4158 pos = os_strchr(cmd, ' ');
4163 if (os_strcmp(cmd, "bonjour") == 0)
4164 return p2p_ctrl_service_add_bonjour(wpa_s, pos);
4165 if (os_strcmp(cmd, "upnp") == 0)
4166 return p2p_ctrl_service_add_upnp(wpa_s, pos);
4167 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
4172 static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant *wpa_s,
4176 struct wpabuf *query;
4179 len = os_strlen(cmd);
4183 query = wpabuf_alloc(len);
4186 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
4191 ret = wpas_p2p_service_del_bonjour(wpa_s, query);
4197 static int p2p_ctrl_service_del_upnp(struct wpa_supplicant *wpa_s, char *cmd)
4202 pos = os_strchr(cmd, ' ');
4207 if (hexstr2bin(cmd, &version, 1) < 0)
4210 return wpas_p2p_service_del_upnp(wpa_s, version, pos);
4214 static int p2p_ctrl_service_del(struct wpa_supplicant *wpa_s, char *cmd)
4218 pos = os_strchr(cmd, ' ');
4223 if (os_strcmp(cmd, "bonjour") == 0)
4224 return p2p_ctrl_service_del_bonjour(wpa_s, pos);
4225 if (os_strcmp(cmd, "upnp") == 0)
4226 return p2p_ctrl_service_del_upnp(wpa_s, pos);
4227 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
4232 static int p2p_ctrl_reject(struct wpa_supplicant *wpa_s, char *cmd)
4238 if (hwaddr_aton(cmd, addr))
4241 return wpas_p2p_reject(wpa_s, addr);
4245 static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd)
4249 struct wpa_ssid *ssid;
4250 u8 *_peer = NULL, peer[ETH_ALEN];
4251 int freq = 0, pref_freq = 0;
4255 pos = os_strstr(cmd, " peer=");
4258 if (hwaddr_aton(pos, peer))
4262 ssid = wpa_config_get_network(wpa_s->conf, id);
4263 if (ssid == NULL || ssid->disabled != 2) {
4264 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
4265 "for persistent P2P group",
4270 pos = os_strstr(cmd, " freq=");
4278 pos = os_strstr(cmd, " pref=");
4281 pref_freq = atoi(pos);
4286 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
4287 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
4290 return wpas_p2p_invite(wpa_s, _peer, ssid, NULL, freq, ht40, vht,
4295 static int p2p_ctrl_invite_group(struct wpa_supplicant *wpa_s, char *cmd)
4298 u8 peer[ETH_ALEN], go_dev_addr[ETH_ALEN], *go_dev = NULL;
4300 pos = os_strstr(cmd, " peer=");
4306 if (hwaddr_aton(pos, peer)) {
4307 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", pos);
4311 pos = os_strstr(pos, " go_dev_addr=");
4314 if (hwaddr_aton(pos, go_dev_addr)) {
4315 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'",
4319 go_dev = go_dev_addr;
4322 return wpas_p2p_invite_group(wpa_s, cmd, peer, go_dev);
4326 static int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd)
4328 if (os_strncmp(cmd, "persistent=", 11) == 0)
4329 return p2p_ctrl_invite_persistent(wpa_s, cmd + 11);
4330 if (os_strncmp(cmd, "group=", 6) == 0)
4331 return p2p_ctrl_invite_group(wpa_s, cmd + 6);
4337 static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s,
4338 char *cmd, int freq, int ht40,
4342 struct wpa_ssid *ssid;
4345 ssid = wpa_config_get_network(wpa_s->conf, id);
4346 if (ssid == NULL || ssid->disabled != 2) {
4347 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
4348 "for persistent P2P group",
4353 return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq, 0, ht40, vht,
4358 static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd)
4360 int freq = 0, ht40, vht;
4363 pos = os_strstr(cmd, "freq=");
4365 freq = atoi(pos + 5);
4367 vht = (os_strstr(cmd, "vht") != NULL) || wpa_s->conf->p2p_go_vht;
4368 ht40 = (os_strstr(cmd, "ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
4371 if (os_strncmp(cmd, "persistent=", 11) == 0)
4372 return p2p_ctrl_group_add_persistent(wpa_s, cmd + 11, freq,
4374 if (os_strcmp(cmd, "persistent") == 0 ||
4375 os_strncmp(cmd, "persistent ", 11) == 0)
4376 return wpas_p2p_group_add(wpa_s, 1, freq, ht40, vht);
4377 if (os_strncmp(cmd, "freq=", 5) == 0)
4378 return wpas_p2p_group_add(wpa_s, 0, freq, ht40, vht);
4380 return wpas_p2p_group_add(wpa_s, 0, freq, ht40, vht);
4382 wpa_printf(MSG_DEBUG, "CTRL: Invalid P2P_GROUP_ADD parameters '%s'",
4388 static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd,
4389 char *buf, size_t buflen)
4391 u8 addr[ETH_ALEN], *addr_ptr;
4393 const struct p2p_peer_info *info;
4395 char devtype[WPS_DEV_TYPE_BUFSIZE];
4396 struct wpa_ssid *ssid;
4399 if (!wpa_s->global->p2p)
4402 if (os_strcmp(cmd, "FIRST") == 0) {
4405 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
4406 if (hwaddr_aton(cmd + 5, addr) < 0)
4411 if (hwaddr_aton(cmd, addr) < 0)
4417 info = p2p_get_peer_info(wpa_s->global->p2p, addr_ptr, next);
4424 res = os_snprintf(pos, end - pos, MACSTR "\n"
4430 "serial_number=%s\n"
4431 "config_methods=0x%x\n"
4433 "group_capab=0x%x\n"
4435 MAC2STR(info->p2p_device_addr),
4436 wps_dev_type_bin2str(info->pri_dev_type,
4437 devtype, sizeof(devtype)),
4442 info->serial_number,
4443 info->config_methods,
4447 if (res < 0 || res >= end - pos)
4451 for (i = 0; i < info->wps_sec_dev_type_list_len / WPS_DEV_TYPE_LEN; i++)
4454 t = &info->wps_sec_dev_type_list[i * WPS_DEV_TYPE_LEN];
4455 res = os_snprintf(pos, end - pos, "sec_dev_type=%s\n",
4456 wps_dev_type_bin2str(t, devtype,
4458 if (res < 0 || res >= end - pos)
4463 ssid = wpas_p2p_get_persistent(wpa_s, info->p2p_device_addr, NULL, 0);
4465 res = os_snprintf(pos, end - pos, "persistent=%d\n", ssid->id);
4466 if (res < 0 || res >= end - pos)
4471 res = p2p_get_peer_info_txt(info, pos, end - pos);
4480 static int p2p_ctrl_disallow_freq(struct wpa_supplicant *wpa_s,
4485 if (wpa_s->global->p2p == NULL)
4488 if (freq_range_list_parse(&wpa_s->global->p2p_disallow_freq, param) < 0)
4491 for (i = 0; i < wpa_s->global->p2p_disallow_freq.num; i++) {
4492 struct wpa_freq_range *freq;
4493 freq = &wpa_s->global->p2p_disallow_freq.range[i];
4494 wpa_printf(MSG_DEBUG, "P2P: Disallowed frequency range %u-%u",
4495 freq->min, freq->max);
4498 wpas_p2p_update_channel_list(wpa_s);
4503 static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd)
4507 if (wpa_s->global->p2p == NULL)
4510 param = os_strchr(cmd, ' ');
4515 if (os_strcmp(cmd, "discoverability") == 0) {
4516 p2p_set_client_discoverability(wpa_s->global->p2p,
4521 if (os_strcmp(cmd, "managed") == 0) {
4522 p2p_set_managed_oper(wpa_s->global->p2p, atoi(param));
4526 if (os_strcmp(cmd, "listen_channel") == 0) {
4527 return p2p_set_listen_channel(wpa_s->global->p2p, 81,
4531 if (os_strcmp(cmd, "ssid_postfix") == 0) {
4532 return p2p_set_ssid_postfix(wpa_s->global->p2p, (u8 *) param,
4536 if (os_strcmp(cmd, "noa") == 0) {
4538 int count, start, duration;
4539 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
4540 count = atoi(param);
4541 pos = os_strchr(param, ',');
4546 pos = os_strchr(pos, ',');
4550 duration = atoi(pos);
4551 if (count < 0 || count > 255 || start < 0 || duration < 0)
4553 if (count == 0 && duration > 0)
4555 wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
4556 "start=%d duration=%d", count, start, duration);
4557 return wpas_p2p_set_noa(wpa_s, count, start, duration);
4560 if (os_strcmp(cmd, "ps") == 0)
4561 return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1);
4563 if (os_strcmp(cmd, "oppps") == 0)
4564 return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1);
4566 if (os_strcmp(cmd, "ctwindow") == 0)
4567 return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param));
4569 if (os_strcmp(cmd, "disabled") == 0) {
4570 wpa_s->global->p2p_disabled = atoi(param);
4571 wpa_printf(MSG_DEBUG, "P2P functionality %s",
4572 wpa_s->global->p2p_disabled ?
4573 "disabled" : "enabled");
4574 if (wpa_s->global->p2p_disabled) {
4575 wpas_p2p_stop_find(wpa_s);
4576 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
4577 p2p_flush(wpa_s->global->p2p);
4582 if (os_strcmp(cmd, "conc_pref") == 0) {
4583 if (os_strcmp(param, "sta") == 0)
4584 wpa_s->global->conc_pref = WPA_CONC_PREF_STA;
4585 else if (os_strcmp(param, "p2p") == 0)
4586 wpa_s->global->conc_pref = WPA_CONC_PREF_P2P;
4588 wpa_printf(MSG_INFO, "Invalid conc_pref value");
4591 wpa_printf(MSG_DEBUG, "Single channel concurrency preference: "
4596 if (os_strcmp(cmd, "force_long_sd") == 0) {
4597 wpa_s->force_long_sd = atoi(param);
4601 if (os_strcmp(cmd, "peer_filter") == 0) {
4603 if (hwaddr_aton(param, addr))
4605 p2p_set_peer_filter(wpa_s->global->p2p, addr);
4609 if (os_strcmp(cmd, "cross_connect") == 0)
4610 return wpas_p2p_set_cross_connect(wpa_s, atoi(param));
4612 if (os_strcmp(cmd, "go_apsd") == 0) {
4613 if (os_strcmp(param, "disable") == 0)
4614 wpa_s->set_ap_uapsd = 0;
4616 wpa_s->set_ap_uapsd = 1;
4617 wpa_s->ap_uapsd = atoi(param);
4622 if (os_strcmp(cmd, "client_apsd") == 0) {
4623 if (os_strcmp(param, "disable") == 0)
4624 wpa_s->set_sta_uapsd = 0;
4628 /* format: BE,BK,VI,VO;max SP Length */
4630 pos = os_strchr(param, ',');
4635 pos = os_strchr(pos, ',');
4640 pos = os_strchr(pos, ',');
4645 /* ignore max SP Length for now */
4647 wpa_s->set_sta_uapsd = 1;
4648 wpa_s->sta_uapsd = 0;
4650 wpa_s->sta_uapsd |= BIT(0);
4652 wpa_s->sta_uapsd |= BIT(1);
4654 wpa_s->sta_uapsd |= BIT(2);
4656 wpa_s->sta_uapsd |= BIT(3);
4661 if (os_strcmp(cmd, "disallow_freq") == 0)
4662 return p2p_ctrl_disallow_freq(wpa_s, param);
4664 if (os_strcmp(cmd, "disc_int") == 0) {
4665 int min_disc_int, max_disc_int, max_disc_tu;
4670 min_disc_int = atoi(pos);
4671 pos = os_strchr(pos, ' ');
4676 max_disc_int = atoi(pos);
4677 pos = os_strchr(pos, ' ');
4682 max_disc_tu = atoi(pos);
4684 return p2p_set_disc_int(wpa_s->global->p2p, min_disc_int,
4685 max_disc_int, max_disc_tu);
4688 if (os_strcmp(cmd, "per_sta_psk") == 0) {
4689 wpa_s->global->p2p_per_sta_psk = !!atoi(param);
4693 #ifdef CONFIG_WPS_NFC
4694 if (os_strcmp(cmd, "nfc_tag") == 0)
4695 return wpas_p2p_nfc_tag_enabled(wpa_s, !!atoi(param));
4696 #endif /* CONFIG_WPS_NFC */
4698 if (os_strcmp(cmd, "disable_ip_addr_req") == 0) {
4699 wpa_s->p2p_disable_ip_addr_req = !!atoi(param);
4703 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
4710 static void p2p_ctrl_flush(struct wpa_supplicant *wpa_s)
4712 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
4713 wpa_s->force_long_sd = 0;
4714 if (wpa_s->global->p2p)
4715 p2p_flush(wpa_s->global->p2p);
4719 static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd)
4722 unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0;
4725 pos = os_strchr(cmd, ' ');
4731 pos2 = os_strchr(pos, ' ');
4739 pos = os_strchr(pos2, ' ');
4747 return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2);
4751 static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd)
4754 unsigned int period = 0, interval = 0;
4757 pos = os_strchr(cmd, ' ');
4762 interval = atoi(pos);
4765 return wpas_p2p_ext_listen(wpa_s, period, interval);
4769 static int p2p_ctrl_remove_client(struct wpa_supplicant *wpa_s, const char *cmd)
4776 if (os_strncmp(pos, "iface=", 6) == 0) {
4780 if (hwaddr_aton(pos, peer))
4783 wpas_p2p_remove_client(wpa_s, peer, iface_addr);
4787 #endif /* CONFIG_P2P */
4790 static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s, char *val)
4792 struct wpa_freq_range_list ranges;
4794 struct hostapd_hw_modes *mode;
4797 if (wpa_s->hw.modes == NULL)
4800 os_memset(&ranges, 0, sizeof(ranges));
4801 if (freq_range_list_parse(&ranges, val) < 0)
4804 for (i = 0; i < wpa_s->hw.num_modes; i++) {
4807 mode = &wpa_s->hw.modes[i];
4808 for (j = 0; j < mode->num_channels; j++) {
4811 if (mode->channels[j].flag & HOSTAPD_CHAN_DISABLED)
4814 freq = mode->channels[j].freq;
4815 if (!freq_range_list_includes(&ranges, freq))
4818 int_array_add_unique(&freqs, freq);
4822 os_free(ranges.range);
4827 #ifdef CONFIG_INTERWORKING
4829 static int ctrl_interworking_select(struct wpa_supplicant *wpa_s, char *param)
4837 auto_sel = os_strstr(param, "auto") != NULL;
4839 pos = os_strstr(param, "freq=");
4841 freqs = freq_range_to_channel_list(wpa_s, pos + 5);
4848 return interworking_select(wpa_s, auto_sel, freqs);
4852 static int ctrl_interworking_connect(struct wpa_supplicant *wpa_s, char *dst)
4855 struct wpa_bss *bss;
4857 if (hwaddr_aton(dst, bssid)) {
4858 wpa_printf(MSG_DEBUG, "Invalid BSSID '%s'", dst);
4862 bss = wpa_bss_get_bssid(wpa_s, bssid);
4864 wpa_printf(MSG_DEBUG, "Could not find BSS " MACSTR,
4869 return interworking_connect(wpa_s, bss);
4873 static int get_anqp(struct wpa_supplicant *wpa_s, char *dst)
4875 u8 dst_addr[ETH_ALEN];
4878 #define MAX_ANQP_INFO_ID 100
4879 u16 id[MAX_ANQP_INFO_ID];
4882 used = hwaddr_aton2(dst, dst_addr);
4886 while (num_id < MAX_ANQP_INFO_ID) {
4887 id[num_id] = atoi(pos);
4890 pos = os_strchr(pos + 1, ',');
4899 return anqp_send_req(wpa_s, dst_addr, id, num_id);
4903 static int gas_request(struct wpa_supplicant *wpa_s, char *cmd)
4905 u8 dst_addr[ETH_ALEN];
4906 struct wpabuf *advproto, *query = NULL;
4911 used = hwaddr_aton2(cmd, dst_addr);
4919 /* Advertisement Protocol ID */
4920 end = os_strchr(pos, ' ');
4924 len = os_strlen(pos);
4930 advproto = wpabuf_alloc(len);
4931 if (advproto == NULL)
4933 if (hexstr2bin(pos, wpabuf_put(advproto, len), len) < 0)
4937 /* Optional Query Request */
4942 len = os_strlen(pos);
4949 query = wpabuf_alloc(len);
4952 if (hexstr2bin(pos, wpabuf_put(query, len), len) < 0)
4957 ret = gas_send_request(wpa_s, dst_addr, advproto, query);
4960 wpabuf_free(advproto);
4967 static int gas_response_get(struct wpa_supplicant *wpa_s, char *cmd, char *buf,
4974 size_t resp_len, start, requested_len;
4975 struct wpabuf *resp;
4978 used = hwaddr_aton2(cmd, addr);
4985 dialog_token = atoi(pos);
4987 if (wpa_s->last_gas_resp &&
4988 os_memcmp(addr, wpa_s->last_gas_addr, ETH_ALEN) == 0 &&
4989 dialog_token == wpa_s->last_gas_dialog_token)
4990 resp = wpa_s->last_gas_resp;
4991 else if (wpa_s->prev_gas_resp &&
4992 os_memcmp(addr, wpa_s->prev_gas_addr, ETH_ALEN) == 0 &&
4993 dialog_token == wpa_s->prev_gas_dialog_token)
4994 resp = wpa_s->prev_gas_resp;
4998 resp_len = wpabuf_len(resp);
5000 requested_len = resp_len;
5002 pos = os_strchr(pos, ' ');
5005 if (start > resp_len)
5006 return os_snprintf(buf, buflen, "FAIL-Invalid range");
5007 pos = os_strchr(pos, ',');
5011 requested_len = atoi(pos);
5012 if (start + requested_len > resp_len)
5013 return os_snprintf(buf, buflen, "FAIL-Invalid range");
5016 if (requested_len * 2 + 1 > buflen)
5017 return os_snprintf(buf, buflen, "FAIL-Too long response");
5019 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(resp) + start,
5022 if (start + requested_len == resp_len) {
5024 * Free memory by dropping the response after it has been
5027 if (resp == wpa_s->prev_gas_resp) {
5028 wpabuf_free(wpa_s->prev_gas_resp);
5029 wpa_s->prev_gas_resp = NULL;
5031 wpabuf_free(wpa_s->last_gas_resp);
5032 wpa_s->last_gas_resp = NULL;
5038 #endif /* CONFIG_INTERWORKING */
5043 static int get_hs20_anqp(struct wpa_supplicant *wpa_s, char *dst)
5045 u8 dst_addr[ETH_ALEN];
5050 used = hwaddr_aton2(dst, dst_addr);
5055 int num = atoi(pos);
5056 if (num <= 0 || num > 31)
5058 subtypes |= BIT(num);
5059 pos = os_strchr(pos + 1, ',');
5068 return hs20_anqp_send_req(wpa_s, dst_addr, subtypes, NULL, 0);
5072 static int hs20_nai_home_realm_list(struct wpa_supplicant *wpa_s,
5073 const u8 *addr, const char *realm)
5079 rlen = os_strlen(realm);
5081 buf = os_malloc(len);
5084 buf[0] = 1; /* NAI Home Realm Count */
5085 buf[1] = 0; /* Formatted in accordance with RFC 4282 */
5087 os_memcpy(buf + 3, realm, rlen);
5089 ret = hs20_anqp_send_req(wpa_s, addr,
5090 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
5099 static int hs20_get_nai_home_realm_list(struct wpa_supplicant *wpa_s,
5102 struct wpa_cred *cred = wpa_s->conf->cred;
5103 u8 dst_addr[ETH_ALEN];
5109 used = hwaddr_aton2(dst, dst_addr);
5113 while (dst[used] == ' ')
5115 if (os_strncmp(dst + used, "realm=", 6) == 0)
5116 return hs20_nai_home_realm_list(wpa_s, dst_addr,
5119 len = os_strlen(dst + used);
5121 if (len == 0 && cred && cred->realm)
5122 return hs20_nai_home_realm_list(wpa_s, dst_addr, cred->realm);
5127 buf = os_malloc(len);
5130 if (hexstr2bin(dst + used, buf, len) < 0) {
5135 ret = hs20_anqp_send_req(wpa_s, dst_addr,
5136 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
5144 static int hs20_icon_request(struct wpa_supplicant *wpa_s, char *cmd)
5146 u8 dst_addr[ETH_ALEN];
5150 used = hwaddr_aton2(cmd, dst_addr);
5154 while (cmd[used] == ' ')
5158 wpa_s->fetch_osu_icon_in_progress = 0;
5159 return hs20_anqp_send_req(wpa_s, dst_addr, BIT(HS20_STYPE_ICON_REQUEST),
5160 (u8 *) icon, os_strlen(icon));
5163 #endif /* CONFIG_HS20 */
5166 static int wpa_supplicant_ctrl_iface_sta_autoconnect(
5167 struct wpa_supplicant *wpa_s, char *cmd)
5169 wpa_s->auto_reconnect_disabled = atoi(cmd) == 0 ? 1 : 0;
5174 #ifdef CONFIG_AUTOSCAN
5176 static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant *wpa_s,
5179 enum wpa_states state = wpa_s->wpa_state;
5180 char *new_params = NULL;
5182 if (os_strlen(cmd) > 0) {
5183 new_params = os_strdup(cmd);
5184 if (new_params == NULL)
5188 os_free(wpa_s->conf->autoscan);
5189 wpa_s->conf->autoscan = new_params;
5191 if (wpa_s->conf->autoscan == NULL)
5192 autoscan_deinit(wpa_s);
5193 else if (state == WPA_DISCONNECTED || state == WPA_INACTIVE)
5194 autoscan_init(wpa_s, 1);
5195 else if (state == WPA_SCANNING)
5196 wpa_supplicant_reinit_autoscan(wpa_s);
5201 #endif /* CONFIG_AUTOSCAN */
5206 static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant *wpa_s, char *cmd)
5212 struct wpabuf *tfs_req = NULL;
5214 if (os_strncmp(cmd, "enter", 5) == 0)
5216 else if (os_strncmp(cmd, "exit", 4) == 0)
5221 pos = os_strstr(cmd, " interval=");
5223 intval = atoi(pos + 10);
5225 pos = os_strstr(cmd, " tfs_req=");
5230 end = os_strchr(pos, ' ');
5234 len = os_strlen(pos);
5238 tfs_req = wpabuf_alloc(len);
5239 if (tfs_req == NULL)
5241 if (hexstr2bin(pos, wpabuf_put(tfs_req, len), len) < 0) {
5242 wpabuf_free(tfs_req);
5247 ret = ieee802_11_send_wnmsleep_req(wpa_s, enter ? WNM_SLEEP_MODE_ENTER :
5248 WNM_SLEEP_MODE_EXIT, intval,
5250 wpabuf_free(tfs_req);
5256 static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant *wpa_s, char *cmd)
5260 query_reason = atoi(cmd);
5262 wpa_printf(MSG_DEBUG, "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d",
5265 return wnm_send_bss_transition_mgmt_query(wpa_s, query_reason);
5268 #endif /* CONFIG_WNM */
5271 /* Get string representation of channel width */
5272 static const char * channel_width_name(enum chan_width width)
5275 case CHAN_WIDTH_20_NOHT:
5276 return "20 MHz (no HT)";
5283 case CHAN_WIDTH_80P80:
5285 case CHAN_WIDTH_160:
5293 static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf,
5296 struct wpa_signal_info si;
5300 ret = wpa_drv_signal_poll(wpa_s, &si);
5307 ret = os_snprintf(pos, end - pos, "RSSI=%d\nLINKSPEED=%d\n"
5308 "NOISE=%d\nFREQUENCY=%u\n",
5309 si.current_signal, si.current_txrate / 1000,
5310 si.current_noise, si.frequency);
5311 if (ret < 0 || ret > end - pos)
5315 if (si.chanwidth != CHAN_WIDTH_UNKNOWN) {
5316 ret = os_snprintf(pos, end - pos, "WIDTH=%s\n",
5317 channel_width_name(si.chanwidth));
5318 if (ret < 0 || ret > end - pos)
5323 if (si.center_frq1 > 0 && si.center_frq2 > 0) {
5324 ret = os_snprintf(pos, end - pos,
5325 "CENTER_FRQ1=%d\nCENTER_FRQ2=%d\n",
5326 si.center_frq1, si.center_frq2);
5327 if (ret < 0 || ret > end - pos)
5332 if (si.avg_signal) {
5333 ret = os_snprintf(pos, end - pos,
5334 "AVG_RSSI=%d\n", si.avg_signal);
5335 if (ret < 0 || ret >= end - pos)
5344 static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant *wpa_s, char *buf,
5347 struct hostap_sta_driver_data sta;
5350 ret = wpa_drv_pktcnt_poll(wpa_s, &sta);
5354 ret = os_snprintf(buf, buflen, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
5355 sta.tx_packets, sta.tx_retry_failed, sta.rx_packets);
5356 if (ret < 0 || (size_t) ret > buflen)
5363 static int wpa_supplicant_driver_cmd(struct wpa_supplicant *wpa_s, char *cmd,
5364 char *buf, size_t buflen)
5368 ret = wpa_drv_driver_cmd(wpa_s, cmd, buf, buflen);
5370 if (os_strncasecmp(cmd, "COUNTRY", 7) == 0) {
5371 struct p2p_data *p2p = wpa_s->global->p2p;
5374 country[0] = cmd[8];
5375 country[1] = cmd[9];
5377 p2p_set_country(p2p, country);
5380 ret = os_snprintf(buf, buflen, "%s\n", "OK");
5384 #endif /* ANDROID */
5387 static int wpa_supplicant_vendor_cmd(struct wpa_supplicant *wpa_s, char *cmd,
5388 char *buf, size_t buflen)
5393 unsigned int vendor_id, subcmd;
5394 struct wpabuf *reply;
5395 size_t data_len = 0;
5397 /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */
5398 vendor_id = strtoul(cmd, &pos, 16);
5402 subcmd = strtoul(pos, &pos, 10);
5405 if (!isblank(*pos++))
5407 data_len = os_strlen(pos);
5412 data = os_malloc(data_len);
5416 if (hexstr2bin(pos, data, data_len)) {
5417 wpa_printf(MSG_DEBUG,
5418 "Vendor command: wrong parameter format");
5424 reply = wpabuf_alloc((buflen - 1) / 2);
5430 ret = wpa_drv_vendor_cmd(wpa_s, vendor_id, subcmd, data, data_len,
5434 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(reply),
5444 static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s)
5446 wpa_dbg(wpa_s, MSG_DEBUG, "Flush all wpa_supplicant state");
5449 wpas_p2p_stop_find(wpa_s);
5450 p2p_ctrl_flush(wpa_s);
5451 wpas_p2p_group_remove(wpa_s, "*");
5452 wpas_p2p_service_flush(wpa_s);
5453 wpa_s->global->p2p_disabled = 0;
5454 wpa_s->global->p2p_per_sta_psk = 0;
5455 wpa_s->conf->num_sec_device_types = 0;
5456 wpa_s->p2p_disable_ip_addr_req = 0;
5457 #endif /* CONFIG_P2P */
5459 #ifdef CONFIG_WPS_TESTING
5460 wps_version_number = 0x20;
5461 wps_testing_dummy_cred = 0;
5462 wps_corrupt_pkhash = 0;
5463 #endif /* CONFIG_WPS_TESTING */
5465 wpa_s->wps_fragment_size = 0;
5466 wpas_wps_cancel(wpa_s);
5467 #endif /* CONFIG_WPS */
5468 wpa_s->after_wps = 0;
5469 wpa_s->known_wps_freq = 0;
5472 #ifdef CONFIG_TDLS_TESTING
5473 extern unsigned int tdls_testing;
5475 #endif /* CONFIG_TDLS_TESTING */
5476 wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL);
5477 wpa_tdls_enable(wpa_s->wpa, 1);
5478 #endif /* CONFIG_TDLS */
5480 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, wpa_s, NULL);
5481 wpa_supplicant_stop_countermeasures(wpa_s, NULL);
5483 wpa_s->no_keep_alive = 0;
5485 os_free(wpa_s->disallow_aps_bssid);
5486 wpa_s->disallow_aps_bssid = NULL;
5487 wpa_s->disallow_aps_bssid_count = 0;
5488 os_free(wpa_s->disallow_aps_ssid);
5489 wpa_s->disallow_aps_ssid = NULL;
5490 wpa_s->disallow_aps_ssid_count = 0;
5492 wpa_s->set_sta_uapsd = 0;
5493 wpa_s->sta_uapsd = 0;
5495 wpa_drv_radio_disable(wpa_s, 0);
5497 wpa_bss_flush(wpa_s);
5498 wpa_blacklist_clear(wpa_s);
5499 wpa_s->extra_blacklist_count = 0;
5500 wpa_supplicant_ctrl_iface_remove_network(wpa_s, "all");
5501 wpa_supplicant_ctrl_iface_remove_cred(wpa_s, "all");
5502 wpa_config_flush_blobs(wpa_s->conf);
5503 wpa_s->conf->auto_interworking = 0;
5504 wpa_s->conf->okc = 0;
5506 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, 43200);
5507 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, 70);
5508 wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, 60);
5509 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
5511 radio_remove_works(wpa_s, NULL, 1);
5513 wpa_s->next_ssid = NULL;
5515 #ifdef CONFIG_INTERWORKING
5516 hs20_cancel_fetch_osu(wpa_s);
5517 #endif /* CONFIG_INTERWORKING */
5519 wpa_s->ext_mgmt_frame_handling = 0;
5523 static int wpas_ctrl_radio_work_show(struct wpa_supplicant *wpa_s,
5524 char *buf, size_t buflen)
5526 struct wpa_radio_work *work;
5528 struct os_reltime now, diff;
5533 os_get_reltime(&now);
5535 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
5539 os_reltime_sub(&now, &work->time, &diff);
5540 ret = os_snprintf(pos, end - pos, "%s@%s:%u:%u:%ld.%06ld\n",
5541 work->type, work->wpa_s->ifname, work->freq,
5542 work->started, diff.sec, diff.usec);
5543 if (ret < 0 || ret >= end - pos)
5552 static void wpas_ctrl_radio_work_timeout(void *eloop_ctx, void *timeout_ctx)
5554 struct wpa_radio_work *work = eloop_ctx;
5555 struct wpa_external_work *ework = work->ctx;
5557 wpa_dbg(work->wpa_s, MSG_DEBUG,
5558 "Timing out external radio work %u (%s)",
5559 ework->id, work->type);
5560 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_TIMEOUT "%u", ework->id);
5562 radio_work_done(work);
5566 static void wpas_ctrl_radio_work_cb(struct wpa_radio_work *work, int deinit)
5568 struct wpa_external_work *ework = work->ctx;
5572 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
5579 wpa_dbg(work->wpa_s, MSG_DEBUG, "Starting external radio work %u (%s)",
5580 ework->id, ework->type);
5581 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_START "%u", ework->id);
5582 if (!ework->timeout)
5583 ework->timeout = 10;
5584 eloop_register_timeout(ework->timeout, 0, wpas_ctrl_radio_work_timeout,
5589 static int wpas_ctrl_radio_work_add(struct wpa_supplicant *wpa_s, char *cmd,
5590 char *buf, size_t buflen)
5592 struct wpa_external_work *ework;
5596 unsigned int freq = 0;
5598 /* format: <name> [freq=<MHz>] [timeout=<seconds>] */
5600 ework = os_zalloc(sizeof(*ework));
5604 pos = os_strchr(cmd, ' ');
5606 type_len = pos - cmd;
5609 pos2 = os_strstr(pos, "freq=");
5611 freq = atoi(pos2 + 5);
5613 pos2 = os_strstr(pos, "timeout=");
5615 ework->timeout = atoi(pos2 + 8);
5617 type_len = os_strlen(cmd);
5619 if (4 + type_len >= sizeof(ework->type))
5620 type_len = sizeof(ework->type) - 4 - 1;
5621 os_strlcpy(ework->type, "ext:", sizeof(ework->type));
5622 os_memcpy(ework->type + 4, cmd, type_len);
5623 ework->type[4 + type_len] = '\0';
5625 wpa_s->ext_work_id++;
5626 if (wpa_s->ext_work_id == 0)
5627 wpa_s->ext_work_id++;
5628 ework->id = wpa_s->ext_work_id;
5630 if (radio_add_work(wpa_s, freq, ework->type, 0, wpas_ctrl_radio_work_cb,
5636 ret = os_snprintf(buf, buflen, "%u", ework->id);
5637 if (ret < 0 || (size_t) ret >= buflen)
5643 static int wpas_ctrl_radio_work_done(struct wpa_supplicant *wpa_s, char *cmd)
5645 struct wpa_radio_work *work;
5646 unsigned int id = atoi(cmd);
5648 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
5650 struct wpa_external_work *ework;
5652 if (os_strncmp(work->type, "ext:", 4) != 0)
5655 if (id && ework->id != id)
5657 wpa_dbg(wpa_s, MSG_DEBUG,
5658 "Completed external radio work %u (%s)",
5659 ework->id, ework->type);
5660 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, work, NULL);
5662 radio_work_done(work);
5663 return 3; /* "OK\n" */
5670 static int wpas_ctrl_radio_work(struct wpa_supplicant *wpa_s, char *cmd,
5671 char *buf, size_t buflen)
5673 if (os_strcmp(cmd, "show") == 0)
5674 return wpas_ctrl_radio_work_show(wpa_s, buf, buflen);
5675 if (os_strncmp(cmd, "add ", 4) == 0)
5676 return wpas_ctrl_radio_work_add(wpa_s, cmd + 4, buf, buflen);
5677 if (os_strncmp(cmd, "done ", 5) == 0)
5678 return wpas_ctrl_radio_work_done(wpa_s, cmd + 4);
5683 void wpas_ctrl_radio_work_flush(struct wpa_supplicant *wpa_s)
5685 struct wpa_radio_work *work, *tmp;
5687 if (!wpa_s || !wpa_s->radio)
5690 dl_list_for_each_safe(work, tmp, &wpa_s->radio->work,
5691 struct wpa_radio_work, list) {
5692 struct wpa_external_work *ework;
5694 if (os_strncmp(work->type, "ext:", 4) != 0)
5697 wpa_dbg(wpa_s, MSG_DEBUG,
5698 "Flushing %sexternal radio work %u (%s)",
5699 work->started ? " started" : "", ework->id,
5702 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
5705 radio_work_done(work);
5710 static void wpas_ctrl_eapol_response(void *eloop_ctx, void *timeout_ctx)
5712 struct wpa_supplicant *wpa_s = eloop_ctx;
5713 eapol_sm_notify_ctrl_response(wpa_s->eapol);
5717 static int set_scan_freqs(struct wpa_supplicant *wpa_s, char *val)
5721 freqs = freq_range_to_channel_list(wpa_s, val);
5725 os_free(wpa_s->manual_scan_freqs);
5726 wpa_s->manual_scan_freqs = freqs;
5732 static void wpas_ctrl_scan(struct wpa_supplicant *wpa_s, char *params,
5733 char *reply, int reply_size, int *reply_len)
5737 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
5742 wpa_s->manual_scan_passive = 0;
5743 wpa_s->manual_scan_use_id = 0;
5744 wpa_s->manual_scan_only_new = 0;
5747 if (os_strncasecmp(params, "TYPE=ONLY", 9) == 0)
5748 wpa_s->scan_res_handler = scan_only_handler;
5750 pos = os_strstr(params, "freq=");
5751 if (pos && set_scan_freqs(wpa_s, pos + 5) < 0) {
5756 pos = os_strstr(params, "passive=");
5758 wpa_s->manual_scan_passive = !!atoi(pos + 8);
5760 pos = os_strstr(params, "use_id=");
5762 wpa_s->manual_scan_use_id = atoi(pos + 7);
5764 pos = os_strstr(params, "only_new=1");
5766 wpa_s->manual_scan_only_new = 1;
5768 os_free(wpa_s->manual_scan_freqs);
5769 wpa_s->manual_scan_freqs = NULL;
5770 if (wpa_s->scan_res_handler == scan_only_handler)
5771 wpa_s->scan_res_handler = NULL;
5774 if (!wpa_s->sched_scanning && !wpa_s->scanning &&
5775 ((wpa_s->wpa_state <= WPA_SCANNING) ||
5776 (wpa_s->wpa_state == WPA_COMPLETED))) {
5777 wpa_s->normal_scans = 0;
5778 wpa_s->scan_req = MANUAL_SCAN_REQ;
5779 wpa_s->after_wps = 0;
5780 wpa_s->known_wps_freq = 0;
5781 wpa_supplicant_req_scan(wpa_s, 0, 0);
5782 if (wpa_s->manual_scan_use_id) {
5783 wpa_s->manual_scan_id++;
5784 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
5785 wpa_s->manual_scan_id);
5786 *reply_len = os_snprintf(reply, reply_size, "%u\n",
5787 wpa_s->manual_scan_id);
5789 } else if (wpa_s->sched_scanning) {
5790 wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to allow requested full scan to proceed");
5791 wpa_supplicant_cancel_sched_scan(wpa_s);
5792 wpa_s->scan_req = MANUAL_SCAN_REQ;
5793 wpa_supplicant_req_scan(wpa_s, 0, 0);
5794 if (wpa_s->manual_scan_use_id) {
5795 wpa_s->manual_scan_id++;
5796 *reply_len = os_snprintf(reply, reply_size, "%u\n",
5797 wpa_s->manual_scan_id);
5798 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
5799 wpa_s->manual_scan_id);
5802 wpa_printf(MSG_DEBUG, "Ongoing scan action - reject new request");
5803 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
5808 #ifdef CONFIG_TESTING_OPTIONS
5810 static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant *wpa_s,
5811 unsigned int freq, const u8 *dst,
5812 const u8 *src, const u8 *bssid,
5813 const u8 *data, size_t data_len,
5814 enum offchannel_send_action_result
5817 wpa_msg(wpa_s, MSG_INFO, "MGMT-TX-STATUS freq=%u dst=" MACSTR
5818 " src=" MACSTR " bssid=" MACSTR " result=%s",
5819 freq, MAC2STR(dst), MAC2STR(src), MAC2STR(bssid),
5820 result == OFFCHANNEL_SEND_ACTION_SUCCESS ?
5821 "SUCCESS" : (result == OFFCHANNEL_SEND_ACTION_NO_ACK ?
5822 "NO_ACK" : "FAILED"));
5826 static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant *wpa_s, char *cmd)
5830 u8 *buf, da[ETH_ALEN], bssid[ETH_ALEN];
5832 int freq = 0, no_cck = 0, wait_time = 0;
5834 /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1]
5835 * <action=Action frame payload> */
5837 wpa_printf(MSG_DEBUG, "External MGMT TX: %s", cmd);
5840 used = hwaddr_aton2(pos, da);
5846 used = hwaddr_aton2(pos, bssid);
5851 param = os_strstr(pos, " freq=");
5857 param = os_strstr(pos, " no_cck=");
5860 no_cck = atoi(param);
5863 param = os_strstr(pos, " wait_time=");
5866 wait_time = atoi(param);
5869 param = os_strstr(pos, " action=");
5874 len = os_strlen(param);
5879 buf = os_malloc(len);
5883 if (hexstr2bin(param, buf, len) < 0) {
5888 res = offchannel_send_action(wpa_s, freq, da, wpa_s->own_addr, bssid,
5889 buf, len, wait_time,
5890 wpas_ctrl_iface_mgmt_tx_cb, no_cck);
5896 static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant *wpa_s)
5898 wpa_printf(MSG_DEBUG, "External MGMT TX - done waiting");
5899 offchannel_send_action_done(wpa_s);
5902 #endif /* CONFIG_TESTING_OPTIONS */
5905 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
5906 char *buf, size_t *resp_len)
5909 const int reply_size = 4096;
5912 if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 ||
5913 os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
5914 if (wpa_debug_show_keys)
5915 wpa_dbg(wpa_s, MSG_DEBUG,
5916 "Control interface command '%s'", buf);
5918 wpa_dbg(wpa_s, MSG_DEBUG,
5919 "Control interface command '%s [REMOVED]'",
5920 os_strncmp(buf, WPA_CTRL_RSP,
5921 os_strlen(WPA_CTRL_RSP)) == 0 ?
5922 WPA_CTRL_RSP : "SET_NETWORK");
5923 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ", 16) == 0 ||
5924 os_strncmp(buf, "NFC_REPORT_HANDOVER", 19) == 0 ||
5925 os_strncmp(buf, "NFC_RX_HANDOVER_SEL", 19) == 0) {
5926 wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface",
5927 (const u8 *) buf, os_strlen(buf));
5929 int level = MSG_DEBUG;
5930 if (os_strcmp(buf, "PING") == 0)
5931 level = MSG_EXCESSIVE;
5932 wpa_dbg(wpa_s, level, "Control interface command '%s'", buf);
5935 reply = os_malloc(reply_size);
5936 if (reply == NULL) {
5941 os_memcpy(reply, "OK\n", 3);
5944 if (os_strcmp(buf, "PING") == 0) {
5945 os_memcpy(reply, "PONG\n", 5);
5947 } else if (os_strcmp(buf, "IFNAME") == 0) {
5948 reply_len = os_strlen(wpa_s->ifname);
5949 os_memcpy(reply, wpa_s->ifname, reply_len);
5950 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
5951 if (wpa_debug_reopen_file() < 0)
5953 } else if (os_strncmp(buf, "NOTE ", 5) == 0) {
5954 wpa_printf(MSG_INFO, "NOTE: %s", buf + 5);
5955 } else if (os_strcmp(buf, "MIB") == 0) {
5956 reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size);
5957 if (reply_len >= 0) {
5959 res = eapol_sm_get_mib(wpa_s->eapol, reply + reply_len,
5960 reply_size - reply_len);
5966 } else if (os_strncmp(buf, "STATUS", 6) == 0) {
5967 reply_len = wpa_supplicant_ctrl_iface_status(
5968 wpa_s, buf + 6, reply, reply_size);
5969 } else if (os_strcmp(buf, "PMKSA") == 0) {
5970 reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, reply,
5972 } else if (os_strncmp(buf, "SET ", 4) == 0) {
5973 if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4))
5975 } else if (os_strncmp(buf, "GET ", 4) == 0) {
5976 reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4,
5978 } else if (os_strcmp(buf, "LOGON") == 0) {
5979 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
5980 } else if (os_strcmp(buf, "LOGOFF") == 0) {
5981 eapol_sm_notify_logoff(wpa_s->eapol, TRUE);
5982 } else if (os_strcmp(buf, "REASSOCIATE") == 0) {
5983 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
5986 wpas_request_connection(wpa_s);
5987 } else if (os_strcmp(buf, "REATTACH") == 0) {
5988 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED ||
5989 !wpa_s->current_ssid)
5992 wpa_s->reattach = 1;
5993 wpas_request_connection(wpa_s);
5995 } else if (os_strcmp(buf, "RECONNECT") == 0) {
5996 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
5998 else if (wpa_s->disconnected)
5999 wpas_request_connection(wpa_s);
6000 #ifdef IEEE8021X_EAPOL
6001 } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) {
6002 if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8))
6004 #endif /* IEEE8021X_EAPOL */
6005 #ifdef CONFIG_PEERKEY
6006 } else if (os_strncmp(buf, "STKSTART ", 9) == 0) {
6007 if (wpa_supplicant_ctrl_iface_stkstart(wpa_s, buf + 9))
6009 #endif /* CONFIG_PEERKEY */
6010 #ifdef CONFIG_IEEE80211R
6011 } else if (os_strncmp(buf, "FT_DS ", 6) == 0) {
6012 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6))
6014 #endif /* CONFIG_IEEE80211R */
6016 } else if (os_strcmp(buf, "WPS_PBC") == 0) {
6017 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL);
6019 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
6023 } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) {
6024 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8);
6026 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
6030 } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {
6031 reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8,
6034 } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) {
6035 reply_len = wpa_supplicant_ctrl_iface_wps_check_pin(
6036 wpa_s, buf + 14, reply, reply_size);
6037 } else if (os_strcmp(buf, "WPS_CANCEL") == 0) {
6038 if (wpas_wps_cancel(wpa_s))
6040 #ifdef CONFIG_WPS_NFC
6041 } else if (os_strcmp(buf, "WPS_NFC") == 0) {
6042 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, NULL))
6044 } else if (os_strncmp(buf, "WPS_NFC ", 8) == 0) {
6045 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, buf + 8))
6047 } else if (os_strncmp(buf, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
6048 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_config_token(
6049 wpa_s, buf + 21, reply, reply_size);
6050 } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) {
6051 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_token(
6052 wpa_s, buf + 14, reply, reply_size);
6053 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) {
6054 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s,
6057 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
6058 reply_len = wpas_ctrl_nfc_get_handover_req(
6059 wpa_s, buf + 21, reply, reply_size);
6060 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
6061 reply_len = wpas_ctrl_nfc_get_handover_sel(
6062 wpa_s, buf + 21, reply, reply_size);
6063 } else if (os_strncmp(buf, "NFC_RX_HANDOVER_SEL ", 20) == 0) {
6064 if (wpas_ctrl_nfc_rx_handover_sel(wpa_s, buf + 20))
6066 } else if (os_strncmp(buf, "NFC_REPORT_HANDOVER ", 20) == 0) {
6067 if (wpas_ctrl_nfc_report_handover(wpa_s, buf + 20))
6069 #endif /* CONFIG_WPS_NFC */
6070 } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) {
6071 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8))
6074 } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) {
6075 reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin(
6076 wpa_s, buf + 11, reply, reply_size);
6077 #endif /* CONFIG_AP */
6078 #ifdef CONFIG_WPS_ER
6079 } else if (os_strcmp(buf, "WPS_ER_START") == 0) {
6080 if (wpas_wps_er_start(wpa_s, NULL))
6082 } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) {
6083 if (wpas_wps_er_start(wpa_s, buf + 13))
6085 } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) {
6086 if (wpas_wps_er_stop(wpa_s))
6088 } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) {
6089 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11))
6091 } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) {
6092 int ret = wpas_wps_er_pbc(wpa_s, buf + 11);
6094 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
6096 } else if (ret == -3) {
6097 os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18);
6099 } else if (ret == -4) {
6100 os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20);
6104 } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) {
6105 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13))
6107 } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) {
6108 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s,
6111 } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) {
6112 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14))
6114 #ifdef CONFIG_WPS_NFC
6115 } else if (os_strncmp(buf, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
6116 reply_len = wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
6117 wpa_s, buf + 24, reply, reply_size);
6118 #endif /* CONFIG_WPS_NFC */
6119 #endif /* CONFIG_WPS_ER */
6120 #endif /* CONFIG_WPS */
6121 #ifdef CONFIG_IBSS_RSN
6122 } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) {
6123 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9))
6125 #endif /* CONFIG_IBSS_RSN */
6127 } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) {
6128 if (p2p_ctrl_find(wpa_s, buf + 9))
6130 } else if (os_strcmp(buf, "P2P_FIND") == 0) {
6131 if (p2p_ctrl_find(wpa_s, ""))
6133 } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) {
6134 wpas_p2p_stop_find(wpa_s);
6135 } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) {
6136 reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply,
6138 } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) {
6139 if (p2p_ctrl_listen(wpa_s, buf + 11))
6141 } else if (os_strcmp(buf, "P2P_LISTEN") == 0) {
6142 if (p2p_ctrl_listen(wpa_s, ""))
6144 } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) {
6145 if (wpas_p2p_group_remove(wpa_s, buf + 17))
6147 } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) {
6148 if (wpas_p2p_group_add(wpa_s, 0, 0, 0, 0))
6150 } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) {
6151 if (p2p_ctrl_group_add(wpa_s, buf + 14))
6153 } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) {
6154 if (p2p_ctrl_prov_disc(wpa_s, buf + 14))
6156 } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) {
6157 reply_len = p2p_get_passphrase(wpa_s, reply, reply_size);
6158 } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) {
6159 reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply,
6161 } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
6162 if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0)
6164 } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) {
6165 if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0)
6167 } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) {
6168 wpas_p2p_sd_service_update(wpa_s);
6169 } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
6170 if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0)
6172 } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) {
6173 wpas_p2p_service_flush(wpa_s);
6174 } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) {
6175 if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0)
6177 } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) {
6178 if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0)
6180 } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) {
6181 if (p2p_ctrl_reject(wpa_s, buf + 11) < 0)
6183 } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) {
6184 if (p2p_ctrl_invite(wpa_s, buf + 11) < 0)
6186 } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) {
6187 reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply,
6189 } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) {
6190 if (p2p_ctrl_set(wpa_s, buf + 8) < 0)
6192 } else if (os_strcmp(buf, "P2P_FLUSH") == 0) {
6193 p2p_ctrl_flush(wpa_s);
6194 } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) {
6195 if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0)
6197 } else if (os_strcmp(buf, "P2P_CANCEL") == 0) {
6198 if (wpas_p2p_cancel(wpa_s))
6200 } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) {
6201 if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0)
6203 } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) {
6204 if (p2p_ctrl_presence_req(wpa_s, "") < 0)
6206 } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) {
6207 if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0)
6209 } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) {
6210 if (p2p_ctrl_ext_listen(wpa_s, "") < 0)
6212 } else if (os_strncmp(buf, "P2P_REMOVE_CLIENT ", 18) == 0) {
6213 if (p2p_ctrl_remove_client(wpa_s, buf + 18) < 0)
6215 #endif /* CONFIG_P2P */
6216 #ifdef CONFIG_WIFI_DISPLAY
6217 } else if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0) {
6218 if (wifi_display_subelem_set(wpa_s->global, buf + 16) < 0)
6220 } else if (os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) {
6221 reply_len = wifi_display_subelem_get(wpa_s->global, buf + 16,
6223 #endif /* CONFIG_WIFI_DISPLAY */
6224 #ifdef CONFIG_INTERWORKING
6225 } else if (os_strcmp(buf, "FETCH_ANQP") == 0) {
6226 if (interworking_fetch_anqp(wpa_s) < 0)
6228 } else if (os_strcmp(buf, "STOP_FETCH_ANQP") == 0) {
6229 interworking_stop_fetch_anqp(wpa_s);
6230 } else if (os_strcmp(buf, "INTERWORKING_SELECT") == 0) {
6231 if (ctrl_interworking_select(wpa_s, NULL) < 0)
6233 } else if (os_strncmp(buf, "INTERWORKING_SELECT ", 20) == 0) {
6234 if (ctrl_interworking_select(wpa_s, buf + 20) < 0)
6236 } else if (os_strncmp(buf, "INTERWORKING_CONNECT ", 21) == 0) {
6237 if (ctrl_interworking_connect(wpa_s, buf + 21) < 0)
6239 } else if (os_strncmp(buf, "ANQP_GET ", 9) == 0) {
6240 if (get_anqp(wpa_s, buf + 9) < 0)
6242 } else if (os_strncmp(buf, "GAS_REQUEST ", 12) == 0) {
6243 if (gas_request(wpa_s, buf + 12) < 0)
6245 } else if (os_strncmp(buf, "GAS_RESPONSE_GET ", 17) == 0) {
6246 reply_len = gas_response_get(wpa_s, buf + 17, reply,
6248 #endif /* CONFIG_INTERWORKING */
6250 } else if (os_strncmp(buf, "HS20_ANQP_GET ", 14) == 0) {
6251 if (get_hs20_anqp(wpa_s, buf + 14) < 0)
6253 } else if (os_strncmp(buf, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
6254 if (hs20_get_nai_home_realm_list(wpa_s, buf + 29) < 0)
6256 } else if (os_strncmp(buf, "HS20_ICON_REQUEST ", 18) == 0) {
6257 if (hs20_icon_request(wpa_s, buf + 18) < 0)
6259 } else if (os_strcmp(buf, "FETCH_OSU") == 0) {
6260 if (hs20_fetch_osu(wpa_s) < 0)
6262 } else if (os_strcmp(buf, "CANCEL_FETCH_OSU") == 0) {
6263 hs20_cancel_fetch_osu(wpa_s);
6264 #endif /* CONFIG_HS20 */
6265 } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0)
6267 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
6268 wpa_s, buf + os_strlen(WPA_CTRL_RSP)))
6272 * Notify response from timeout to allow the control
6273 * interface response to be sent first.
6275 eloop_register_timeout(0, 0, wpas_ctrl_eapol_response,
6278 } else if (os_strcmp(buf, "RECONFIGURE") == 0) {
6279 if (wpa_supplicant_reload_configuration(wpa_s))
6281 } else if (os_strcmp(buf, "TERMINATE") == 0) {
6282 wpa_supplicant_terminate_proc(wpa_s->global);
6283 } else if (os_strncmp(buf, "BSSID ", 6) == 0) {
6284 if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6))
6286 } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) {
6287 reply_len = wpa_supplicant_ctrl_iface_blacklist(
6288 wpa_s, buf + 9, reply, reply_size);
6289 } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) {
6290 reply_len = wpa_supplicant_ctrl_iface_log_level(
6291 wpa_s, buf + 9, reply, reply_size);
6292 } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) {
6293 reply_len = wpa_supplicant_ctrl_iface_list_networks(
6294 wpa_s, reply, reply_size);
6295 } else if (os_strcmp(buf, "DISCONNECT") == 0) {
6297 wpa_s->sme.prev_bssid_set = 0;
6298 #endif /* CONFIG_SME */
6299 wpa_s->reassociate = 0;
6300 wpa_s->disconnected = 1;
6301 wpa_supplicant_cancel_sched_scan(wpa_s);
6302 wpa_supplicant_cancel_scan(wpa_s);
6303 wpa_supplicant_deauthenticate(wpa_s,
6304 WLAN_REASON_DEAUTH_LEAVING);
6305 } else if (os_strcmp(buf, "SCAN") == 0) {
6306 wpas_ctrl_scan(wpa_s, NULL, reply, reply_size, &reply_len);
6307 } else if (os_strncmp(buf, "SCAN ", 5) == 0) {
6308 wpas_ctrl_scan(wpa_s, buf + 5, reply, reply_size, &reply_len);
6309 } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) {
6310 reply_len = wpa_supplicant_ctrl_iface_scan_results(
6311 wpa_s, reply, reply_size);
6312 } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) {
6313 if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15))
6315 } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) {
6316 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15))
6318 } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) {
6319 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16))
6321 } else if (os_strcmp(buf, "ADD_NETWORK") == 0) {
6322 reply_len = wpa_supplicant_ctrl_iface_add_network(
6323 wpa_s, reply, reply_size);
6324 } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) {
6325 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15))
6327 } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
6328 if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12))
6330 } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) {
6331 reply_len = wpa_supplicant_ctrl_iface_get_network(
6332 wpa_s, buf + 12, reply, reply_size);
6333 } else if (os_strcmp(buf, "LIST_CREDS") == 0) {
6334 reply_len = wpa_supplicant_ctrl_iface_list_creds(
6335 wpa_s, reply, reply_size);
6336 } else if (os_strcmp(buf, "ADD_CRED") == 0) {
6337 reply_len = wpa_supplicant_ctrl_iface_add_cred(
6338 wpa_s, reply, reply_size);
6339 } else if (os_strncmp(buf, "REMOVE_CRED ", 12) == 0) {
6340 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s, buf + 12))
6342 } else if (os_strncmp(buf, "SET_CRED ", 9) == 0) {
6343 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s, buf + 9))
6345 #ifndef CONFIG_NO_CONFIG_WRITE
6346 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
6347 if (wpa_supplicant_ctrl_iface_save_config(wpa_s))
6349 #endif /* CONFIG_NO_CONFIG_WRITE */
6350 } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
6351 reply_len = wpa_supplicant_ctrl_iface_get_capability(
6352 wpa_s, buf + 15, reply, reply_size);
6353 } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) {
6354 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8))
6356 } else if (os_strncmp(buf, "SCAN_INTERVAL ", 14) == 0) {
6357 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s, buf + 14))
6359 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
6360 reply_len = wpa_supplicant_global_iface_list(
6361 wpa_s->global, reply, reply_size);
6362 } else if (os_strcmp(buf, "INTERFACES") == 0) {
6363 reply_len = wpa_supplicant_global_iface_interfaces(
6364 wpa_s->global, reply, reply_size);
6365 } else if (os_strncmp(buf, "BSS ", 4) == 0) {
6366 reply_len = wpa_supplicant_ctrl_iface_bss(
6367 wpa_s, buf + 4, reply, reply_size);
6369 } else if (os_strcmp(buf, "STA-FIRST") == 0) {
6370 reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size);
6371 } else if (os_strncmp(buf, "STA ", 4) == 0) {
6372 reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply,
6374 } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) {
6375 reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply,
6377 } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) {
6378 if (ap_ctrl_iface_sta_deauthenticate(wpa_s, buf + 15))
6380 } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) {
6381 if (ap_ctrl_iface_sta_disassociate(wpa_s, buf + 13))
6383 } else if (os_strncmp(buf, "CHAN_SWITCH ", 12) == 0) {
6384 if (ap_ctrl_iface_chanswitch(wpa_s, buf + 12))
6386 #endif /* CONFIG_AP */
6387 } else if (os_strcmp(buf, "SUSPEND") == 0) {
6388 wpas_notify_suspend(wpa_s->global);
6389 } else if (os_strcmp(buf, "RESUME") == 0) {
6390 wpas_notify_resume(wpa_s->global);
6391 } else if (os_strcmp(buf, "DROP_SA") == 0) {
6392 wpa_supplicant_ctrl_iface_drop_sa(wpa_s);
6393 } else if (os_strncmp(buf, "ROAM ", 5) == 0) {
6394 if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5))
6396 } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) {
6397 if (wpa_supplicant_ctrl_iface_sta_autoconnect(wpa_s, buf + 16))
6399 } else if (os_strncmp(buf, "BSS_EXPIRE_AGE ", 15) == 0) {
6400 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s, buf + 15))
6402 } else if (os_strncmp(buf, "BSS_EXPIRE_COUNT ", 17) == 0) {
6403 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s,
6406 } else if (os_strncmp(buf, "BSS_FLUSH ", 10) == 0) {
6407 if (wpa_supplicant_ctrl_iface_bss_flush(wpa_s, buf + 10))
6410 } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) {
6411 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14))
6413 } else if (os_strncmp(buf, "TDLS_SETUP ", 11) == 0) {
6414 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s, buf + 11))
6416 } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) {
6417 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14))
6419 #endif /* CONFIG_TDLS */
6420 } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) {
6421 reply_len = wpa_supplicant_signal_poll(wpa_s, reply,
6423 } else if (os_strncmp(buf, "PKTCNT_POLL", 11) == 0) {
6424 reply_len = wpa_supplicant_pktcnt_poll(wpa_s, reply,
6426 #ifdef CONFIG_AUTOSCAN
6427 } else if (os_strncmp(buf, "AUTOSCAN ", 9) == 0) {
6428 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s, buf + 9))
6430 #endif /* CONFIG_AUTOSCAN */
6432 } else if (os_strncmp(buf, "DRIVER ", 7) == 0) {
6433 reply_len = wpa_supplicant_driver_cmd(wpa_s, buf + 7, reply,
6435 #endif /* ANDROID */
6436 } else if (os_strncmp(buf, "VENDOR ", 7) == 0) {
6437 reply_len = wpa_supplicant_vendor_cmd(wpa_s, buf + 7, reply,
6439 } else if (os_strcmp(buf, "REAUTHENTICATE") == 0) {
6440 pmksa_cache_clear_current(wpa_s->wpa);
6441 eapol_sm_request_reauth(wpa_s->eapol);
6443 } else if (os_strncmp(buf, "WNM_SLEEP ", 10) == 0) {
6444 if (wpas_ctrl_iface_wnm_sleep(wpa_s, buf + 10))
6446 } else if (os_strncmp(buf, "WNM_BSS_QUERY ", 10) == 0) {
6447 if (wpas_ctrl_iface_wnm_bss_query(wpa_s, buf + 10))
6449 #endif /* CONFIG_WNM */
6450 } else if (os_strcmp(buf, "FLUSH") == 0) {
6451 wpa_supplicant_ctrl_iface_flush(wpa_s);
6452 } else if (os_strncmp(buf, "RADIO_WORK ", 11) == 0) {
6453 reply_len = wpas_ctrl_radio_work(wpa_s, buf + 11, reply,
6455 #ifdef CONFIG_TESTING_OPTIONS
6456 } else if (os_strncmp(buf, "MGMT_TX ", 8) == 0) {
6457 if (wpas_ctrl_iface_mgmt_tx(wpa_s, buf + 8) < 0)
6459 } else if (os_strcmp(buf, "MGMT_TX_DONE") == 0) {
6460 wpas_ctrl_iface_mgmt_tx_done(wpa_s);
6461 #endif /* CONFIG_TESTING_OPTIONS */
6463 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
6467 if (reply_len < 0) {
6468 os_memcpy(reply, "FAIL\n", 5);
6472 *resp_len = reply_len;
6477 static int wpa_supplicant_global_iface_add(struct wpa_global *global,
6480 struct wpa_interface iface;
6484 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
6485 * TAB<bridge_ifname>
6487 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd);
6489 os_memset(&iface, 0, sizeof(iface));
6492 iface.ifname = pos = cmd;
6493 pos = os_strchr(pos, '\t');
6496 if (iface.ifname[0] == '\0')
6501 iface.confname = pos;
6502 pos = os_strchr(pos, '\t');
6505 if (iface.confname[0] == '\0')
6506 iface.confname = NULL;
6511 pos = os_strchr(pos, '\t');
6514 if (iface.driver[0] == '\0')
6515 iface.driver = NULL;
6519 iface.ctrl_interface = pos;
6520 pos = os_strchr(pos, '\t');
6523 if (iface.ctrl_interface[0] == '\0')
6524 iface.ctrl_interface = NULL;
6528 iface.driver_param = pos;
6529 pos = os_strchr(pos, '\t');
6532 if (iface.driver_param[0] == '\0')
6533 iface.driver_param = NULL;
6537 iface.bridge_ifname = pos;
6538 pos = os_strchr(pos, '\t');
6541 if (iface.bridge_ifname[0] == '\0')
6542 iface.bridge_ifname = NULL;
6547 if (wpa_supplicant_get_iface(global, iface.ifname))
6550 return wpa_supplicant_add_iface(global, &iface) ? 0 : -1;
6554 static int wpa_supplicant_global_iface_remove(struct wpa_global *global,
6557 struct wpa_supplicant *wpa_s;
6559 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd);
6561 wpa_s = wpa_supplicant_get_iface(global, cmd);
6564 return wpa_supplicant_remove_iface(global, wpa_s, 0);
6568 static void wpa_free_iface_info(struct wpa_interface_info *iface)
6570 struct wpa_interface_info *prev;
6574 iface = iface->next;
6576 os_free(prev->ifname);
6577 os_free(prev->desc);
6583 static int wpa_supplicant_global_iface_list(struct wpa_global *global,
6587 struct wpa_interface_info *iface = NULL, *last = NULL, *tmp;
6590 for (i = 0; wpa_drivers[i]; i++) {
6591 struct wpa_driver_ops *drv = wpa_drivers[i];
6592 if (drv->get_interfaces == NULL)
6594 tmp = drv->get_interfaces(global->drv_priv[i]);
6608 for (tmp = iface; tmp; tmp = tmp->next) {
6609 res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n",
6610 tmp->drv_name, tmp->ifname,
6611 tmp->desc ? tmp->desc : "");
6612 if (res < 0 || res >= end - pos) {
6619 wpa_free_iface_info(iface);
6625 static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
6630 struct wpa_supplicant *wpa_s;
6632 wpa_s = global->ifaces;
6637 res = os_snprintf(pos, end - pos, "%s\n", wpa_s->ifname);
6638 if (res < 0 || res >= end - pos) {
6643 wpa_s = wpa_s->next;
6649 static char * wpas_global_ctrl_iface_ifname(struct wpa_global *global,
6651 char *cmd, size_t *resp_len)
6653 struct wpa_supplicant *wpa_s;
6655 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
6656 if (os_strcmp(ifname, wpa_s->ifname) == 0)
6660 if (wpa_s == NULL) {
6661 char *resp = os_strdup("FAIL-NO-IFNAME-MATCH\n");
6663 *resp_len = os_strlen(resp);
6669 return wpa_supplicant_ctrl_iface_process(wpa_s, cmd, resp_len);
6673 static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global *global,
6674 char *buf, size_t *resp_len)
6677 static const char * cmd[] = {
6684 "P2P_GET_PASSPHRASE",
6685 "P2P_SERVICE_UPDATE",
6686 "P2P_SERVICE_FLUSH",
6693 static const char * prefix[] = {
6696 #endif /* ANDROID */
6703 "P2P_GROUP_REMOVE ",
6706 "P2P_SERV_DISC_REQ ",
6707 "P2P_SERV_DISC_CANCEL_REQ ",
6708 "P2P_SERV_DISC_RESP ",
6709 "P2P_SERV_DISC_EXTERNAL ",
6717 "P2P_PRESENCE_REQ ",
6719 "P2P_REMOVE_CLIENT ",
6725 if (global->p2p_init_wpa_s == NULL)
6728 for (i = 0; !found && cmd[i]; i++) {
6729 if (os_strcmp(buf, cmd[i]) == 0)
6733 for (i = 0; !found && prefix[i]; i++) {
6734 if (os_strncmp(buf, prefix[i], os_strlen(prefix[i])) == 0)
6739 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
6741 #endif /* CONFIG_P2P */
6746 static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global *global,
6747 char *buf, size_t *resp_len)
6749 #ifdef CONFIG_WIFI_DISPLAY
6750 if (global->p2p_init_wpa_s == NULL)
6752 if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0 ||
6753 os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0)
6754 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
6756 #endif /* CONFIG_WIFI_DISPLAY */
6761 static char * wpas_global_ctrl_iface_redir(struct wpa_global *global,
6762 char *buf, size_t *resp_len)
6766 ret = wpas_global_ctrl_iface_redir_p2p(global, buf, resp_len);
6770 ret = wpas_global_ctrl_iface_redir_wfd(global, buf, resp_len);
6778 static int wpas_global_ctrl_iface_set(struct wpa_global *global, char *cmd)
6782 value = os_strchr(cmd, ' ');
6787 wpa_printf(MSG_DEBUG, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd, value);
6789 #ifdef CONFIG_WIFI_DISPLAY
6790 if (os_strcasecmp(cmd, "wifi_display") == 0) {
6791 wifi_display_enable(global, !!atoi(value));
6794 #endif /* CONFIG_WIFI_DISPLAY */
6800 #ifndef CONFIG_NO_CONFIG_WRITE
6801 static int wpas_global_ctrl_iface_save_config(struct wpa_global *global)
6804 struct wpa_supplicant *wpa_s;
6806 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
6807 if (!wpa_s->conf->update_config) {
6808 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
6812 if (wpa_config_write(wpa_s->confname, wpa_s->conf)) {
6813 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
6816 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
6822 #endif /* CONFIG_NO_CONFIG_WRITE */
6825 static int wpas_global_ctrl_iface_status(struct wpa_global *global,
6826 char *buf, size_t buflen)
6830 struct wpa_supplicant *wpa_s;
6836 if (global->p2p && !global->p2p_disabled) {
6837 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
6840 MAC2STR(global->p2p_dev_addr),
6841 p2p_get_state_txt(global->p2p));
6842 if (ret < 0 || ret >= end - pos)
6845 } else if (global->p2p) {
6846 ret = os_snprintf(pos, end - pos, "p2p_state=DISABLED\n");
6847 if (ret < 0 || ret >= end - pos)
6851 #endif /* CONFIG_P2P */
6853 #ifdef CONFIG_WIFI_DISPLAY
6854 ret = os_snprintf(pos, end - pos, "wifi_display=%d\n",
6855 !!global->wifi_display);
6856 if (ret < 0 || ret >= end - pos)
6859 #endif /* CONFIG_WIFI_DISPLAY */
6861 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
6862 ret = os_snprintf(pos, end - pos, "ifname=%s\n"
6863 "address=" MACSTR "\n",
6864 wpa_s->ifname, MAC2STR(wpa_s->own_addr));
6865 if (ret < 0 || ret >= end - pos)
6874 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
6875 char *buf, size_t *resp_len)
6878 const int reply_size = 2048;
6880 int level = MSG_DEBUG;
6882 if (os_strncmp(buf, "IFNAME=", 7) == 0) {
6883 char *pos = os_strchr(buf + 7, ' ');
6886 return wpas_global_ctrl_iface_ifname(global,
6892 reply = wpas_global_ctrl_iface_redir(global, buf, resp_len);
6896 if (os_strcmp(buf, "PING") == 0)
6897 level = MSG_EXCESSIVE;
6898 wpa_hexdump_ascii(level, "RX global ctrl_iface",
6899 (const u8 *) buf, os_strlen(buf));
6901 reply = os_malloc(reply_size);
6902 if (reply == NULL) {
6907 os_memcpy(reply, "OK\n", 3);
6910 if (os_strcmp(buf, "PING") == 0) {
6911 os_memcpy(reply, "PONG\n", 5);
6913 } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) {
6914 if (wpa_supplicant_global_iface_add(global, buf + 14))
6916 } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) {
6917 if (wpa_supplicant_global_iface_remove(global, buf + 17))
6919 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
6920 reply_len = wpa_supplicant_global_iface_list(
6921 global, reply, reply_size);
6922 } else if (os_strcmp(buf, "INTERFACES") == 0) {
6923 reply_len = wpa_supplicant_global_iface_interfaces(
6924 global, reply, reply_size);
6925 } else if (os_strcmp(buf, "TERMINATE") == 0) {
6926 wpa_supplicant_terminate_proc(global);
6927 } else if (os_strcmp(buf, "SUSPEND") == 0) {
6928 wpas_notify_suspend(global);
6929 } else if (os_strcmp(buf, "RESUME") == 0) {
6930 wpas_notify_resume(global);
6931 } else if (os_strncmp(buf, "SET ", 4) == 0) {
6932 if (wpas_global_ctrl_iface_set(global, buf + 4))
6934 #ifndef CONFIG_NO_CONFIG_WRITE
6935 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
6936 if (wpas_global_ctrl_iface_save_config(global))
6938 #endif /* CONFIG_NO_CONFIG_WRITE */
6939 } else if (os_strcmp(buf, "STATUS") == 0) {
6940 reply_len = wpas_global_ctrl_iface_status(global, reply,
6942 #ifdef CONFIG_MODULE_TESTS
6943 } else if (os_strcmp(buf, "MODULE_TESTS") == 0) {
6944 int wpas_module_tests(void);
6945 if (wpas_module_tests() < 0)
6947 #endif /* CONFIG_MODULE_TESTS */
6949 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
6953 if (reply_len < 0) {
6954 os_memcpy(reply, "FAIL\n", 5);
6958 *resp_len = reply_len;