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);
541 #endif /* CONFIG_TDLS */
544 #ifdef CONFIG_IEEE80211R
545 static int wpa_supplicant_ctrl_iface_ft_ds(
546 struct wpa_supplicant *wpa_s, char *addr)
548 u8 target_ap[ETH_ALEN];
552 if (hwaddr_aton(addr, target_ap)) {
553 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid "
554 "address '%s'", addr);
558 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap));
560 bss = wpa_bss_get_bssid(wpa_s, target_ap);
562 mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN);
566 return wpa_ft_start_over_ds(wpa_s->wpa, target_ap, mdie);
568 #endif /* CONFIG_IEEE80211R */
572 static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s,
575 u8 bssid[ETH_ALEN], *_bssid = bssid;
577 u8 p2p_dev_addr[ETH_ALEN];
578 #endif /* CONFIG_P2P */
580 u8 *_p2p_dev_addr = NULL;
581 #endif /* CONFIG_AP */
583 if (cmd == NULL || os_strcmp(cmd, "any") == 0) {
586 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
587 if (hwaddr_aton(cmd + 13, p2p_dev_addr)) {
588 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid "
589 "P2P Device Address '%s'",
593 _p2p_dev_addr = p2p_dev_addr;
594 #endif /* CONFIG_P2P */
595 } else if (hwaddr_aton(cmd, bssid)) {
596 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
603 return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid, _p2p_dev_addr);
604 #endif /* CONFIG_AP */
606 return wpas_wps_start_pbc(wpa_s, _bssid, 0);
610 static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s,
611 char *cmd, char *buf,
614 u8 bssid[ETH_ALEN], *_bssid = bssid;
618 pin = os_strchr(cmd, ' ');
622 if (os_strcmp(cmd, "any") == 0)
624 else if (os_strcmp(cmd, "get") == 0) {
625 ret = wps_generate_pin();
627 } else if (hwaddr_aton(cmd, bssid)) {
628 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
634 if (wpa_s->ap_iface) {
639 pos = os_strchr(pin, ' ');
646 return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin,
647 buf, buflen, timeout);
649 #endif /* CONFIG_AP */
652 ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0,
656 ret = os_snprintf(buf, buflen, "%s", pin);
657 if (ret < 0 || (size_t) ret >= buflen)
662 ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0, DEV_PW_DEFAULT);
667 /* Return the generated PIN */
668 ret = os_snprintf(buf, buflen, "%08d", ret);
669 if (ret < 0 || (size_t) ret >= buflen)
675 static int wpa_supplicant_ctrl_iface_wps_check_pin(
676 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
683 wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN",
684 (u8 *) cmd, os_strlen(cmd));
685 for (pos = cmd, len = 0; *pos != '\0'; pos++) {
686 if (*pos < '0' || *pos > '9')
690 wpa_printf(MSG_DEBUG, "WPS: Too long PIN");
694 if (len != 4 && len != 8) {
695 wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len);
701 unsigned int pin_val;
703 if (!wps_pin_valid(pin_val)) {
704 wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit");
705 ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n");
706 if (ret < 0 || (size_t) ret >= buflen)
712 ret = os_snprintf(buf, buflen, "%s", pin);
713 if (ret < 0 || (size_t) ret >= buflen)
720 #ifdef CONFIG_WPS_NFC
722 static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant *wpa_s,
725 u8 bssid[ETH_ALEN], *_bssid = bssid;
727 if (cmd == NULL || cmd[0] == '\0')
729 else if (hwaddr_aton(cmd, bssid))
732 return wpas_wps_start_nfc(wpa_s, NULL, _bssid, NULL, 0, 0, NULL, NULL,
737 static int wpa_supplicant_ctrl_iface_wps_nfc_config_token(
738 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
745 pos = os_strchr(cmd, ' ');
748 if (os_strcmp(cmd, "WPS") == 0)
750 else if (os_strcmp(cmd, "NDEF") == 0)
755 buf = wpas_wps_nfc_config_token(wpa_s, ndef, pos);
759 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
770 static int wpa_supplicant_ctrl_iface_wps_nfc_token(
771 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
777 if (os_strcmp(cmd, "WPS") == 0)
779 else if (os_strcmp(cmd, "NDEF") == 0)
784 buf = wpas_wps_nfc_token(wpa_s, ndef);
788 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
799 static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
800 struct wpa_supplicant *wpa_s, char *pos)
808 freq = strstr(pos, " freq=");
812 forced_freq = atoi(freq);
815 len = os_strlen(pos);
820 buf = wpabuf_alloc(len);
823 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
828 ret = wpas_wps_nfc_tag_read(wpa_s, buf, forced_freq);
835 static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant *wpa_s,
836 char *reply, size_t max_len,
842 buf = wpas_wps_nfc_handover_req(wpa_s, ndef);
846 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
858 static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant *wpa_s,
859 char *reply, size_t max_len,
865 buf = wpas_p2p_nfc_handover_req(wpa_s, ndef);
867 wpa_printf(MSG_DEBUG, "P2P: Could not generate NFC handover request");
871 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
880 #endif /* CONFIG_P2P */
883 static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant *wpa_s,
884 char *cmd, char *reply,
890 pos = os_strchr(cmd, ' ');
895 if (os_strcmp(cmd, "WPS") == 0)
897 else if (os_strcmp(cmd, "NDEF") == 0)
902 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
905 return wpas_ctrl_nfc_get_handover_req_wps(
906 wpa_s, reply, max_len, ndef);
910 if (os_strcmp(pos, "P2P-CR") == 0) {
911 return wpas_ctrl_nfc_get_handover_req_p2p(
912 wpa_s, reply, max_len, ndef);
914 #endif /* CONFIG_P2P */
920 static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant *wpa_s,
921 char *reply, size_t max_len,
922 int ndef, int cr, char *uuid)
927 buf = wpas_wps_nfc_handover_sel(wpa_s, ndef, cr, uuid);
931 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
943 static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant *wpa_s,
944 char *reply, size_t max_len,
950 buf = wpas_p2p_nfc_handover_sel(wpa_s, ndef, tag);
954 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
963 #endif /* CONFIG_P2P */
966 static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant *wpa_s,
967 char *cmd, char *reply,
973 pos = os_strchr(cmd, ' ');
978 if (os_strcmp(cmd, "WPS") == 0)
980 else if (os_strcmp(cmd, "NDEF") == 0)
985 pos2 = os_strchr(pos, ' ');
988 if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
991 return wpas_ctrl_nfc_get_handover_sel_wps(
992 wpa_s, reply, max_len, ndef,
993 os_strcmp(pos, "WPS-CR") == 0, pos2);
997 if (os_strcmp(pos, "P2P-CR") == 0) {
998 return wpas_ctrl_nfc_get_handover_sel_p2p(
999 wpa_s, reply, max_len, ndef, 0);
1002 if (os_strcmp(pos, "P2P-CR-TAG") == 0) {
1003 return wpas_ctrl_nfc_get_handover_sel_p2p(
1004 wpa_s, reply, max_len, ndef, 1);
1006 #endif /* CONFIG_P2P */
1012 static int wpas_ctrl_nfc_rx_handover_sel(struct wpa_supplicant *wpa_s,
1019 len = os_strlen(cmd);
1024 buf = wpabuf_alloc(len);
1027 if (hexstr2bin(cmd, wpabuf_put(buf, len), len) < 0) {
1032 ret = wpas_wps_nfc_rx_handover_sel(wpa_s, buf);
1039 static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant *wpa_s,
1043 struct wpabuf *req, *sel;
1045 char *pos, *role, *type, *pos2;
1048 int forced_freq = 0;
1050 freq = strstr(cmd, " freq=");
1054 forced_freq = atoi(freq);
1056 #endif /* CONFIG_P2P */
1059 pos = os_strchr(role, ' ');
1061 wpa_printf(MSG_DEBUG, "NFC: Missing type in handover report");
1067 pos = os_strchr(type, ' ');
1069 wpa_printf(MSG_DEBUG, "NFC: Missing request message in handover report");
1074 pos2 = os_strchr(pos, ' ');
1076 wpa_printf(MSG_DEBUG, "NFC: Missing select message in handover report");
1081 len = os_strlen(pos);
1083 wpa_printf(MSG_DEBUG, "NFC: Invalid request message length in handover report");
1088 req = wpabuf_alloc(len);
1090 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for request message");
1093 if (hexstr2bin(pos, wpabuf_put(req, len), len) < 0) {
1094 wpa_printf(MSG_DEBUG, "NFC: Invalid request message hexdump in handover report");
1099 len = os_strlen(pos2);
1101 wpa_printf(MSG_DEBUG, "NFC: Invalid select message length in handover report");
1107 sel = wpabuf_alloc(len);
1109 wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for select message");
1113 if (hexstr2bin(pos2, wpabuf_put(sel, len), len) < 0) {
1114 wpa_printf(MSG_DEBUG, "NFC: Invalid select message hexdump in handover report");
1120 wpa_printf(MSG_DEBUG, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d",
1121 role, type, (int) wpabuf_len(req), (int) wpabuf_len(sel));
1123 if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "WPS") == 0) {
1124 ret = wpas_wps_nfc_report_handover(wpa_s, req, sel);
1126 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "WPS") == 0)
1128 ret = wpas_ap_wps_nfc_report_handover(wpa_s, req, sel);
1130 ret = wpas_er_wps_nfc_report_handover(wpa_s, req, sel);
1131 #endif /* CONFIG_AP */
1133 } else if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "P2P") == 0)
1135 ret = wpas_p2p_nfc_report_handover(wpa_s, 1, req, sel, 0);
1136 } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "P2P") == 0)
1138 ret = wpas_p2p_nfc_report_handover(wpa_s, 0, req, sel,
1140 #endif /* CONFIG_P2P */
1142 wpa_printf(MSG_DEBUG, "NFC: Unsupported connection handover "
1143 "reported: role=%s type=%s", role, type);
1150 wpa_printf(MSG_DEBUG, "NFC: Failed to process reported handover messages");
1155 #endif /* CONFIG_WPS_NFC */
1158 static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s,
1167 struct wps_new_ap_settings ap;
1169 pin = os_strchr(cmd, ' ');
1174 if (hwaddr_aton(cmd, bssid)) {
1175 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
1180 new_ssid = os_strchr(pin, ' ');
1181 if (new_ssid == NULL)
1182 return wpas_wps_start_reg(wpa_s, bssid, pin, NULL);
1185 new_auth = os_strchr(new_ssid, ' ');
1186 if (new_auth == NULL)
1190 new_encr = os_strchr(new_auth, ' ');
1191 if (new_encr == NULL)
1195 new_key = os_strchr(new_encr, ' ');
1196 if (new_key == NULL)
1200 os_memset(&ap, 0, sizeof(ap));
1201 ap.ssid_hex = new_ssid;
1204 ap.key_hex = new_key;
1205 return wpas_wps_start_reg(wpa_s, bssid, pin, &ap);
1210 static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant *wpa_s,
1211 char *cmd, char *buf,
1216 const char *pin_txt;
1218 if (!wpa_s->ap_iface)
1221 pos = os_strchr(cmd, ' ');
1225 if (os_strcmp(cmd, "disable") == 0) {
1226 wpas_wps_ap_pin_disable(wpa_s);
1227 return os_snprintf(buf, buflen, "OK\n");
1230 if (os_strcmp(cmd, "random") == 0) {
1232 timeout = atoi(pos);
1233 pin_txt = wpas_wps_ap_pin_random(wpa_s, timeout);
1234 if (pin_txt == NULL)
1236 return os_snprintf(buf, buflen, "%s", pin_txt);
1239 if (os_strcmp(cmd, "get") == 0) {
1240 pin_txt = wpas_wps_ap_pin_get(wpa_s);
1241 if (pin_txt == NULL)
1243 return os_snprintf(buf, buflen, "%s", pin_txt);
1246 if (os_strcmp(cmd, "set") == 0) {
1251 pos = os_strchr(pos, ' ');
1254 timeout = atoi(pos);
1256 if (os_strlen(pin) > buflen)
1258 if (wpas_wps_ap_pin_set(wpa_s, pin, timeout) < 0)
1260 return os_snprintf(buf, buflen, "%s", pin);
1265 #endif /* CONFIG_AP */
1268 #ifdef CONFIG_WPS_ER
1269 static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant *wpa_s,
1272 char *uuid = cmd, *pin, *pos;
1273 u8 addr_buf[ETH_ALEN], *addr = NULL;
1274 pin = os_strchr(uuid, ' ');
1278 pos = os_strchr(pin, ' ');
1281 if (hwaddr_aton(pos, addr_buf) == 0)
1284 return wpas_wps_er_add_pin(wpa_s, addr, uuid, pin);
1288 static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant *wpa_s,
1291 char *uuid = cmd, *pin;
1292 pin = os_strchr(uuid, ' ');
1296 return wpas_wps_er_learn(wpa_s, uuid, pin);
1300 static int wpa_supplicant_ctrl_iface_wps_er_set_config(
1301 struct wpa_supplicant *wpa_s, char *cmd)
1303 char *uuid = cmd, *id;
1304 id = os_strchr(uuid, ' ');
1308 return wpas_wps_er_set_config(wpa_s, uuid, atoi(id));
1312 static int wpa_supplicant_ctrl_iface_wps_er_config(
1313 struct wpa_supplicant *wpa_s, char *cmd)
1320 struct wps_new_ap_settings ap;
1322 pin = os_strchr(cmd, ' ');
1327 new_ssid = os_strchr(pin, ' ');
1328 if (new_ssid == NULL)
1332 new_auth = os_strchr(new_ssid, ' ');
1333 if (new_auth == NULL)
1337 new_encr = os_strchr(new_auth, ' ');
1338 if (new_encr == NULL)
1342 new_key = os_strchr(new_encr, ' ');
1343 if (new_key == NULL)
1347 os_memset(&ap, 0, sizeof(ap));
1348 ap.ssid_hex = new_ssid;
1351 ap.key_hex = new_key;
1352 return wpas_wps_er_config(wpa_s, cmd, pin, &ap);
1356 #ifdef CONFIG_WPS_NFC
1357 static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
1358 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
1365 uuid = os_strchr(cmd, ' ');
1370 if (os_strcmp(cmd, "WPS") == 0)
1372 else if (os_strcmp(cmd, "NDEF") == 0)
1377 buf = wpas_wps_er_nfc_config_token(wpa_s, ndef, uuid);
1381 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
1383 reply[res++] = '\n';
1390 #endif /* CONFIG_WPS_NFC */
1391 #endif /* CONFIG_WPS_ER */
1393 #endif /* CONFIG_WPS */
1396 #ifdef CONFIG_IBSS_RSN
1397 static int wpa_supplicant_ctrl_iface_ibss_rsn(
1398 struct wpa_supplicant *wpa_s, char *addr)
1402 if (hwaddr_aton(addr, peer)) {
1403 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN: invalid "
1404 "address '%s'", addr);
1408 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN " MACSTR,
1411 return ibss_rsn_start(wpa_s->ibss_rsn, peer);
1413 #endif /* CONFIG_IBSS_RSN */
1416 static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s,
1419 #ifdef IEEE8021X_EAPOL
1422 struct wpa_ssid *ssid;
1424 pos = os_strchr(rsp, '-');
1429 pos = os_strchr(pos, ':');
1434 wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id);
1435 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
1436 (u8 *) pos, os_strlen(pos));
1438 ssid = wpa_config_get_network(wpa_s->conf, id);
1440 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
1445 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s, ssid, rsp,
1447 #else /* IEEE8021X_EAPOL */
1448 wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included");
1450 #endif /* IEEE8021X_EAPOL */
1454 static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
1456 char *buf, size_t buflen)
1458 char *pos, *end, tmp[30];
1459 int res, verbose, wps, ret;
1462 #endif /* CONFIG_HS20 */
1464 if (os_strcmp(params, "-DRIVER") == 0)
1465 return wpa_drv_status(wpa_s, buf, buflen);
1466 verbose = os_strcmp(params, "-VERBOSE") == 0;
1467 wps = os_strcmp(params, "-WPS") == 0;
1470 if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
1471 struct wpa_ssid *ssid = wpa_s->current_ssid;
1472 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
1473 MAC2STR(wpa_s->bssid));
1474 if (ret < 0 || ret >= end - pos)
1478 u8 *_ssid = ssid->ssid;
1479 size_t ssid_len = ssid->ssid_len;
1480 u8 ssid_buf[MAX_SSID_LEN];
1481 if (ssid_len == 0) {
1482 int _res = wpa_drv_get_ssid(wpa_s, ssid_buf);
1489 ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n",
1490 wpa_ssid_txt(_ssid, ssid_len),
1492 if (ret < 0 || ret >= end - pos)
1496 if (wps && ssid->passphrase &&
1497 wpa_key_mgmt_wpa_psk(ssid->key_mgmt) &&
1498 (ssid->mode == WPAS_MODE_AP ||
1499 ssid->mode == WPAS_MODE_P2P_GO)) {
1500 ret = os_snprintf(pos, end - pos,
1503 if (ret < 0 || ret >= end - pos)
1508 ret = os_snprintf(pos, end - pos,
1511 if (ret < 0 || ret >= end - pos)
1516 switch (ssid->mode) {
1517 case WPAS_MODE_INFRA:
1518 ret = os_snprintf(pos, end - pos,
1521 case WPAS_MODE_IBSS:
1522 ret = os_snprintf(pos, end - pos,
1526 ret = os_snprintf(pos, end - pos,
1529 case WPAS_MODE_P2P_GO:
1530 ret = os_snprintf(pos, end - pos,
1533 case WPAS_MODE_P2P_GROUP_FORMATION:
1534 ret = os_snprintf(pos, end - pos,
1535 "mode=P2P GO - group "
1542 if (ret < 0 || ret >= end - pos)
1548 if (wpa_s->ap_iface) {
1549 pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos,
1553 #endif /* CONFIG_AP */
1554 pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose);
1557 if (wpa_s->wpa_state >= WPA_ASSOCIATED &&
1560 #endif /* CONFIG_AP */
1561 wpa_s->sme.sae.state == SAE_ACCEPTED) {
1562 ret = os_snprintf(pos, end - pos, "sae_group=%d\n",
1563 wpa_s->sme.sae.group);
1564 if (ret < 0 || ret >= end - pos)
1568 #endif /* CONFIG_SAE */
1569 ret = os_snprintf(pos, end - pos, "wpa_state=%s\n",
1570 wpa_supplicant_state_txt(wpa_s->wpa_state));
1571 if (ret < 0 || ret >= end - pos)
1576 l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) {
1577 ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp);
1578 if (ret < 0 || ret >= end - pos)
1584 if (wpa_s->global->p2p) {
1585 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
1586 "\n", MAC2STR(wpa_s->global->p2p_dev_addr));
1587 if (ret < 0 || ret >= end - pos)
1591 #endif /* CONFIG_P2P */
1593 ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n",
1594 MAC2STR(wpa_s->own_addr));
1595 if (ret < 0 || ret >= end - pos)
1600 if (wpa_s->current_bss &&
1601 (hs20 = wpa_bss_get_vendor_ie(wpa_s->current_bss,
1602 HS20_IE_VENDOR_TYPE)) &&
1603 wpa_s->wpa_proto == WPA_PROTO_RSN &&
1604 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1607 u8 rel_num = (hs20[6] & 0xf0) >> 4;
1608 release = rel_num + 1;
1610 ret = os_snprintf(pos, end - pos, "hs20=%d\n", release);
1611 if (ret < 0 || ret >= end - pos)
1616 if (wpa_s->current_ssid) {
1617 struct wpa_cred *cred;
1620 for (cred = wpa_s->conf->cred; cred; cred = cred->next) {
1623 if (wpa_s->current_ssid->parent_cred != cred)
1626 if (cred->provisioning_sp) {
1627 ret = os_snprintf(pos, end - pos,
1628 "provisioning_sp=%s\n",
1629 cred->provisioning_sp);
1630 if (ret < 0 || ret >= end - pos)
1639 if (wpa_s->current_bss && wpa_s->current_bss->anqp) {
1640 struct wpabuf *names =
1641 wpa_s->current_bss->anqp->domain_name;
1642 for (i = 0; names && i < cred->num_domain; i++)
1644 if (domain_name_list_contains(
1645 names, cred->domain[i], 1))
1648 if (i == cred->num_domain)
1649 i = 0; /* show first entry by default */
1651 ret = os_snprintf(pos, end - pos, "home_sp=%s\n",
1653 if (ret < 0 || ret >= end - pos)
1658 if (wpa_s->current_bss == NULL ||
1659 wpa_s->current_bss->anqp == NULL)
1662 res = interworking_home_sp_cred(
1664 wpa_s->current_bss->anqp->domain_name);
1672 ret = os_snprintf(pos, end - pos, "sp_type=%s\n", type);
1673 if (ret < 0 || ret >= end - pos)
1680 #endif /* CONFIG_HS20 */
1682 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
1683 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
1684 res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos,
1690 res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose);
1697 uuid_bin2str(wpa_s->wps->uuid, uuid_str, sizeof(uuid_str));
1698 ret = os_snprintf(pos, end - pos, "uuid=%s\n", uuid_str);
1699 if (ret < 0 || ret >= end - pos)
1703 #endif /* CONFIG_WPS */
1706 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_STATE_CHANGE
1707 "id=%d state=%d BSSID=" MACSTR " SSID=%s",
1708 wpa_s->current_ssid ? wpa_s->current_ssid->id : -1,
1710 MAC2STR(wpa_s->bssid),
1711 wpa_s->current_ssid && wpa_s->current_ssid->ssid ?
1712 wpa_ssid_txt(wpa_s->current_ssid->ssid,
1713 wpa_s->current_ssid->ssid_len) : "");
1714 if (wpa_s->wpa_state == WPA_COMPLETED) {
1715 struct wpa_ssid *ssid = wpa_s->current_ssid;
1716 wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_CONNECTED
1717 "- connection to " MACSTR
1718 " completed %s [id=%d id_str=%s]",
1719 MAC2STR(wpa_s->bssid), "(auth)",
1720 ssid ? ssid->id : -1,
1721 ssid && ssid->id_str ? ssid->id_str : "");
1723 #endif /* ANDROID */
1729 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s,
1734 struct wpa_ssid *ssid;
1737 /* cmd: "<network id> <BSSID>" */
1738 pos = os_strchr(cmd, ' ');
1743 wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos);
1744 if (hwaddr_aton(pos, bssid)) {
1745 wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos);
1749 ssid = wpa_config_get_network(wpa_s->conf, id);
1751 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
1756 os_memcpy(ssid->bssid, bssid, ETH_ALEN);
1757 ssid->bssid_set = !is_zero_ether_addr(bssid);
1763 static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant *wpa_s,
1764 char *cmd, char *buf,
1768 struct wpa_blacklist *e;
1772 /* cmd: "BLACKLIST [<BSSID>]" */
1776 e = wpa_s->blacklist;
1778 ret = os_snprintf(pos, end - pos, MACSTR "\n",
1780 if (ret < 0 || ret >= end - pos)
1789 if (os_strncmp(cmd, "clear", 5) == 0) {
1790 wpa_blacklist_clear(wpa_s);
1791 os_memcpy(buf, "OK\n", 3);
1795 wpa_printf(MSG_DEBUG, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd);
1796 if (hwaddr_aton(cmd, bssid)) {
1797 wpa_printf(MSG_DEBUG, "CTRL_IFACE: invalid BSSID '%s'", cmd);
1802 * Add the BSSID twice, so its count will be 2, causing it to be
1803 * skipped when processing scan results.
1805 ret = wpa_blacklist_add(wpa_s, bssid);
1808 ret = wpa_blacklist_add(wpa_s, bssid);
1811 os_memcpy(buf, "OK\n", 3);
1816 static const char * debug_level_str(int level)
1837 static int str_to_debug_level(const char *s)
1839 if (os_strcasecmp(s, "EXCESSIVE") == 0)
1840 return MSG_EXCESSIVE;
1841 if (os_strcasecmp(s, "MSGDUMP") == 0)
1843 if (os_strcasecmp(s, "DEBUG") == 0)
1845 if (os_strcasecmp(s, "INFO") == 0)
1847 if (os_strcasecmp(s, "WARNING") == 0)
1849 if (os_strcasecmp(s, "ERROR") == 0)
1855 static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant *wpa_s,
1856 char *cmd, char *buf,
1859 char *pos, *end, *stamp;
1866 /* cmd: "LOG_LEVEL [<level>]" */
1870 ret = os_snprintf(pos, end - pos, "Current level: %s\n"
1872 debug_level_str(wpa_debug_level),
1873 wpa_debug_timestamp);
1874 if (ret < 0 || ret >= end - pos)
1883 stamp = os_strchr(cmd, ' ');
1886 while (*stamp == ' ') {
1891 if (cmd && os_strlen(cmd)) {
1892 int level = str_to_debug_level(cmd);
1895 wpa_debug_level = level;
1898 if (stamp && os_strlen(stamp))
1899 wpa_debug_timestamp = atoi(stamp);
1901 os_memcpy(buf, "OK\n", 3);
1906 static int wpa_supplicant_ctrl_iface_list_networks(
1907 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
1910 struct wpa_ssid *ssid;
1915 ret = os_snprintf(pos, end - pos,
1916 "network id / ssid / bssid / flags\n");
1917 if (ret < 0 || ret >= end - pos)
1921 ssid = wpa_s->conf->ssid;
1923 ret = os_snprintf(pos, end - pos, "%d\t%s",
1925 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
1926 if (ret < 0 || ret >= end - pos)
1929 if (ssid->bssid_set) {
1930 ret = os_snprintf(pos, end - pos, "\t" MACSTR,
1931 MAC2STR(ssid->bssid));
1933 ret = os_snprintf(pos, end - pos, "\tany");
1935 if (ret < 0 || ret >= end - pos)
1938 ret = os_snprintf(pos, end - pos, "\t%s%s%s%s",
1939 ssid == wpa_s->current_ssid ?
1941 ssid->disabled ? "[DISABLED]" : "",
1942 ssid->disabled_until.sec ?
1943 "[TEMP-DISABLED]" : "",
1944 ssid->disabled == 2 ? "[P2P-PERSISTENT]" :
1946 if (ret < 0 || ret >= end - pos)
1949 ret = os_snprintf(pos, end - pos, "\n");
1950 if (ret < 0 || ret >= end - pos)
1961 static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher)
1964 ret = os_snprintf(pos, end - pos, "-");
1965 if (ret < 0 || ret >= end - pos)
1968 ret = wpa_write_ciphers(pos, end, cipher, "+");
1976 static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
1977 const u8 *ie, size_t ie_len)
1979 struct wpa_ie_data data;
1983 ret = os_snprintf(pos, end - pos, "[%s-", proto);
1984 if (ret < 0 || ret >= end - pos)
1988 if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) {
1989 ret = os_snprintf(pos, end - pos, "?]");
1990 if (ret < 0 || ret >= end - pos)
1997 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
1998 ret = os_snprintf(pos, end - pos, "%sEAP",
1999 pos == start ? "" : "+");
2000 if (ret < 0 || ret >= end - pos)
2004 if (data.key_mgmt & WPA_KEY_MGMT_PSK) {
2005 ret = os_snprintf(pos, end - pos, "%sPSK",
2006 pos == start ? "" : "+");
2007 if (ret < 0 || ret >= end - pos)
2011 if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
2012 ret = os_snprintf(pos, end - pos, "%sNone",
2013 pos == start ? "" : "+");
2014 if (ret < 0 || ret >= end - pos)
2018 #ifdef CONFIG_IEEE80211R
2019 if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
2020 ret = os_snprintf(pos, end - pos, "%sFT/EAP",
2021 pos == start ? "" : "+");
2022 if (ret < 0 || ret >= end - pos)
2026 if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) {
2027 ret = os_snprintf(pos, end - pos, "%sFT/PSK",
2028 pos == start ? "" : "+");
2029 if (ret < 0 || ret >= end - pos)
2033 #endif /* CONFIG_IEEE80211R */
2034 #ifdef CONFIG_IEEE80211W
2035 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
2036 ret = os_snprintf(pos, end - pos, "%sEAP-SHA256",
2037 pos == start ? "" : "+");
2038 if (ret < 0 || ret >= end - pos)
2042 if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
2043 ret = os_snprintf(pos, end - pos, "%sPSK-SHA256",
2044 pos == start ? "" : "+");
2045 if (ret < 0 || ret >= end - pos)
2049 #endif /* CONFIG_IEEE80211W */
2051 pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher);
2053 if (data.capabilities & WPA_CAPABILITY_PREAUTH) {
2054 ret = os_snprintf(pos, end - pos, "-preauth");
2055 if (ret < 0 || ret >= end - pos)
2060 ret = os_snprintf(pos, end - pos, "]");
2061 if (ret < 0 || ret >= end - pos)
2070 static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s,
2071 char *pos, char *end,
2072 struct wpabuf *wps_ie)
2079 if (wps_is_selected_pbc_registrar(wps_ie))
2082 else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0))
2084 #endif /* CONFIG_WPS2 */
2085 else if (wps_is_selected_pin_registrar(wps_ie))
2090 ret = os_snprintf(pos, end - pos, "%s", txt);
2091 if (ret >= 0 && ret < end - pos)
2093 wpabuf_free(wps_ie);
2096 #endif /* CONFIG_WPS */
2099 static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s,
2100 char *pos, char *end,
2101 const struct wpa_bss *bss)
2104 struct wpabuf *wps_ie;
2105 wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
2106 return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie);
2107 #else /* CONFIG_WPS */
2109 #endif /* CONFIG_WPS */
2113 /* Format one result on one text line into a buffer. */
2114 static int wpa_supplicant_ctrl_iface_scan_result(
2115 struct wpa_supplicant *wpa_s,
2116 const struct wpa_bss *bss, char *buf, size_t buflen)
2120 const u8 *ie, *ie2, *p2p;
2122 p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
2124 p2p = wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE);
2125 if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN &&
2126 os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) ==
2128 return 0; /* Do not show P2P listen discovery results here */
2133 ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t",
2134 MAC2STR(bss->bssid), bss->freq, bss->level);
2135 if (ret < 0 || ret >= end - pos)
2138 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
2140 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]);
2141 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
2143 pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2, 2 + ie2[1]);
2144 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
2145 if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
2146 ret = os_snprintf(pos, end - pos, "[WEP]");
2147 if (ret < 0 || ret >= end - pos)
2151 if (bss->caps & IEEE80211_CAP_IBSS) {
2152 ret = os_snprintf(pos, end - pos, "[IBSS]");
2153 if (ret < 0 || ret >= end - pos)
2157 if (bss->caps & IEEE80211_CAP_ESS) {
2158 ret = os_snprintf(pos, end - pos, "[ESS]");
2159 if (ret < 0 || ret >= end - pos)
2164 ret = os_snprintf(pos, end - pos, "[P2P]");
2165 if (ret < 0 || ret >= end - pos)
2170 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE) && ie2) {
2171 ret = os_snprintf(pos, end - pos, "[HS20]");
2172 if (ret < 0 || ret >= end - pos)
2176 #endif /* CONFIG_HS20 */
2178 ret = os_snprintf(pos, end - pos, "\t%s",
2179 wpa_ssid_txt(bss->ssid, bss->ssid_len));
2180 if (ret < 0 || ret >= end - pos)
2184 ret = os_snprintf(pos, end - pos, "\n");
2185 if (ret < 0 || ret >= end - pos)
2193 static int wpa_supplicant_ctrl_iface_scan_results(
2194 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
2197 struct wpa_bss *bss;
2202 ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / "
2204 if (ret < 0 || ret >= end - pos)
2208 dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
2209 ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos,
2211 if (ret < 0 || ret >= end - pos)
2220 static int wpa_supplicant_ctrl_iface_select_network(
2221 struct wpa_supplicant *wpa_s, char *cmd)
2224 struct wpa_ssid *ssid;
2226 /* cmd: "<network id>" or "any" */
2227 if (os_strcmp(cmd, "any") == 0) {
2228 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any");
2232 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id);
2234 ssid = wpa_config_get_network(wpa_s->conf, id);
2236 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2237 "network id=%d", id);
2240 if (ssid->disabled == 2) {
2241 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2242 "SELECT_NETWORK with persistent P2P group");
2247 wpa_supplicant_select_network(wpa_s, ssid);
2253 static int wpa_supplicant_ctrl_iface_enable_network(
2254 struct wpa_supplicant *wpa_s, char *cmd)
2257 struct wpa_ssid *ssid;
2259 /* cmd: "<network id>" or "all" */
2260 if (os_strcmp(cmd, "all") == 0) {
2261 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all");
2265 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id);
2267 ssid = wpa_config_get_network(wpa_s->conf, id);
2269 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2270 "network id=%d", id);
2273 if (ssid->disabled == 2) {
2274 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2275 "ENABLE_NETWORK with persistent P2P group");
2279 if (os_strstr(cmd, " no-connect")) {
2284 wpa_supplicant_enable_network(wpa_s, ssid);
2290 static int wpa_supplicant_ctrl_iface_disable_network(
2291 struct wpa_supplicant *wpa_s, char *cmd)
2294 struct wpa_ssid *ssid;
2296 /* cmd: "<network id>" or "all" */
2297 if (os_strcmp(cmd, "all") == 0) {
2298 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all");
2302 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id);
2304 ssid = wpa_config_get_network(wpa_s->conf, id);
2306 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
2307 "network id=%d", id);
2310 if (ssid->disabled == 2) {
2311 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
2312 "DISABLE_NETWORK with persistent P2P "
2317 wpa_supplicant_disable_network(wpa_s, ssid);
2323 static int wpa_supplicant_ctrl_iface_add_network(
2324 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
2326 struct wpa_ssid *ssid;
2329 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK");
2331 ssid = wpa_config_add_network(wpa_s->conf);
2335 wpas_notify_network_added(wpa_s, ssid);
2338 wpa_config_set_network_defaults(ssid);
2340 ret = os_snprintf(buf, buflen, "%d\n", ssid->id);
2341 if (ret < 0 || (size_t) ret >= buflen)
2347 static int wpa_supplicant_ctrl_iface_remove_network(
2348 struct wpa_supplicant *wpa_s, char *cmd)
2351 struct wpa_ssid *ssid;
2354 /* cmd: "<network id>" or "all" */
2355 if (os_strcmp(cmd, "all") == 0) {
2356 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all");
2357 if (wpa_s->sched_scanning)
2358 wpa_supplicant_cancel_sched_scan(wpa_s);
2360 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2361 if (wpa_s->current_ssid) {
2363 wpa_s->sme.prev_bssid_set = 0;
2364 #endif /* CONFIG_SME */
2365 wpa_sm_set_config(wpa_s->wpa, NULL);
2366 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
2367 wpa_supplicant_deauthenticate(
2368 wpa_s, WLAN_REASON_DEAUTH_LEAVING);
2370 ssid = wpa_s->conf->ssid;
2372 struct wpa_ssid *remove_ssid = ssid;
2375 wpas_notify_network_removed(wpa_s, remove_ssid);
2376 wpa_config_remove_network(wpa_s->conf, id);
2382 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id);
2384 ssid = wpa_config_get_network(wpa_s->conf, id);
2386 wpas_notify_network_removed(wpa_s, ssid);
2388 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2393 if (ssid == wpa_s->current_ssid || wpa_s->current_ssid == NULL) {
2395 wpa_s->sme.prev_bssid_set = 0;
2396 #endif /* CONFIG_SME */
2398 * Invalidate the EAP session cache if the current or
2399 * previously used network is removed.
2401 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2404 if (ssid == wpa_s->current_ssid) {
2405 wpa_sm_set_config(wpa_s->wpa, NULL);
2406 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
2408 wpa_supplicant_deauthenticate(wpa_s,
2409 WLAN_REASON_DEAUTH_LEAVING);
2412 was_disabled = ssid->disabled;
2414 if (wpa_config_remove_network(wpa_s->conf, id) < 0) {
2415 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Not able to remove the "
2416 "network id=%d", id);
2420 if (!was_disabled && wpa_s->sched_scanning) {
2421 wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to remove "
2422 "network from filters");
2423 wpa_supplicant_cancel_sched_scan(wpa_s);
2424 wpa_supplicant_req_scan(wpa_s, 0, 0);
2431 static int wpa_supplicant_ctrl_iface_set_network(
2432 struct wpa_supplicant *wpa_s, char *cmd)
2435 struct wpa_ssid *ssid;
2438 /* cmd: "<network id> <variable name> <value>" */
2439 name = os_strchr(cmd, ' ');
2444 value = os_strchr(name, ' ');
2450 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
2452 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
2453 (u8 *) value, os_strlen(value));
2455 ssid = wpa_config_get_network(wpa_s->conf, id);
2457 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2462 if (wpa_config_set(ssid, name, value, 0) < 0) {
2463 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network "
2464 "variable '%s'", name);
2468 if (os_strcmp(name, "bssid") != 0 &&
2469 os_strcmp(name, "priority") != 0)
2470 wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
2472 if (wpa_s->current_ssid == ssid || wpa_s->current_ssid == NULL) {
2474 * Invalidate the EAP session cache if anything in the current
2475 * or previously used configuration changes.
2477 eapol_sm_invalidate_cached_session(wpa_s->eapol);
2480 if ((os_strcmp(name, "psk") == 0 &&
2481 value[0] == '"' && ssid->ssid_len) ||
2482 (os_strcmp(name, "ssid") == 0 && ssid->passphrase))
2483 wpa_config_update_psk(ssid);
2484 else if (os_strcmp(name, "priority") == 0)
2485 wpa_config_update_prio_list(wpa_s->conf);
2491 static int wpa_supplicant_ctrl_iface_get_network(
2492 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
2496 struct wpa_ssid *ssid;
2499 /* cmd: "<network id> <variable name>" */
2500 name = os_strchr(cmd, ' ');
2501 if (name == NULL || buflen == 0)
2506 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
2509 ssid = wpa_config_get_network(wpa_s->conf, id);
2511 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
2516 value = wpa_config_get_no_key(ssid, name);
2517 if (value == NULL) {
2518 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
2519 "variable '%s'", name);
2523 res = os_strlcpy(buf, value, buflen);
2524 if (res >= buflen) {
2535 static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant *wpa_s,
2536 char *buf, size_t buflen)
2539 struct wpa_cred *cred;
2544 ret = os_snprintf(pos, end - pos,
2545 "cred id / realm / username / domain / imsi\n");
2546 if (ret < 0 || ret >= end - pos)
2550 cred = wpa_s->conf->cred;
2552 ret = os_snprintf(pos, end - pos, "%d\t%s\t%s\t%s\t%s\n",
2553 cred->id, cred->realm ? cred->realm : "",
2554 cred->username ? cred->username : "",
2555 cred->domain ? cred->domain[0] : "",
2556 cred->imsi ? cred->imsi : "");
2557 if (ret < 0 || ret >= end - pos)
2568 static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant *wpa_s,
2569 char *buf, size_t buflen)
2571 struct wpa_cred *cred;
2574 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_CRED");
2576 cred = wpa_config_add_cred(wpa_s->conf);
2580 ret = os_snprintf(buf, buflen, "%d\n", cred->id);
2581 if (ret < 0 || (size_t) ret >= buflen)
2587 static int wpas_ctrl_remove_cred(struct wpa_supplicant *wpa_s,
2588 struct wpa_cred *cred)
2590 struct wpa_ssid *ssid;
2593 if (cred == NULL || wpa_config_remove_cred(wpa_s->conf, cred->id) < 0) {
2594 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred");
2598 /* Remove any network entry created based on the removed credential */
2599 ssid = wpa_s->conf->ssid;
2601 if (ssid->parent_cred == cred) {
2602 wpa_printf(MSG_DEBUG, "Remove network id %d since it "
2603 "used the removed credential", ssid->id);
2604 os_snprintf(str, sizeof(str), "%d", ssid->id);
2606 wpa_supplicant_ctrl_iface_remove_network(wpa_s, str);
2615 static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s,
2619 struct wpa_cred *cred, *prev;
2621 /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or
2622 * "provisioning_sp=<FQDN> */
2623 if (os_strcmp(cmd, "all") == 0) {
2624 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED all");
2625 cred = wpa_s->conf->cred;
2629 wpas_ctrl_remove_cred(wpa_s, prev);
2634 if (os_strncmp(cmd, "sp_fqdn=", 8) == 0) {
2635 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
2637 cred = wpa_s->conf->cred;
2643 for (i = 0; i < prev->num_domain; i++) {
2644 if (os_strcmp(prev->domain[i], cmd + 8)
2647 wpas_ctrl_remove_cred(wpa_s, prev);
2655 if (os_strncmp(cmd, "provisioning_sp=", 16) == 0) {
2656 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'",
2658 cred = wpa_s->conf->cred;
2662 if (prev->provisioning_sp &&
2663 os_strcmp(prev->provisioning_sp, cmd + 16) == 0)
2664 wpas_ctrl_remove_cred(wpa_s, prev);
2670 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED id=%d", id);
2672 cred = wpa_config_get_cred(wpa_s->conf, id);
2673 return wpas_ctrl_remove_cred(wpa_s, cred);
2677 static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant *wpa_s,
2681 struct wpa_cred *cred;
2684 /* cmd: "<cred id> <variable name> <value>" */
2685 name = os_strchr(cmd, ' ');
2690 value = os_strchr(name, ' ');
2696 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_CRED id=%d name='%s'",
2698 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
2699 (u8 *) value, os_strlen(value));
2701 cred = wpa_config_get_cred(wpa_s->conf, id);
2703 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
2708 if (wpa_config_set_cred(cred, name, value, 0) < 0) {
2709 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set cred "
2710 "variable '%s'", name);
2718 #ifndef CONFIG_NO_CONFIG_WRITE
2719 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s)
2723 if (!wpa_s->conf->update_config) {
2724 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
2725 "to update configuration (update_config=0)");
2729 ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
2731 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to "
2732 "update configuration");
2734 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration"
2740 #endif /* CONFIG_NO_CONFIG_WRITE */
2743 struct cipher_info {
2749 static const struct cipher_info ciphers[] = {
2750 { WPA_DRIVER_CAPA_ENC_CCMP_256, "CCMP-256", 0 },
2751 { WPA_DRIVER_CAPA_ENC_GCMP_256, "GCMP-256", 0 },
2752 { WPA_DRIVER_CAPA_ENC_CCMP, "CCMP", 0 },
2753 { WPA_DRIVER_CAPA_ENC_GCMP, "GCMP", 0 },
2754 { WPA_DRIVER_CAPA_ENC_TKIP, "TKIP", 0 },
2755 { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE, "NONE", 0 },
2756 { WPA_DRIVER_CAPA_ENC_WEP104, "WEP104", 1 },
2757 { WPA_DRIVER_CAPA_ENC_WEP40, "WEP40", 1 }
2761 static int ctrl_iface_get_capability_pairwise(int res, char *strict,
2762 struct wpa_driver_capa *capa,
2763 char *buf, size_t buflen)
2776 len = os_strlcpy(buf, "CCMP TKIP NONE", buflen);
2782 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
2783 if (!ciphers[i].group_only && capa->enc & ciphers[i].capa) {
2784 ret = os_snprintf(pos, end - pos, "%s%s",
2785 pos == buf ? "" : " ",
2787 if (ret < 0 || ret >= end - pos)
2797 static int ctrl_iface_get_capability_group(int res, char *strict,
2798 struct wpa_driver_capa *capa,
2799 char *buf, size_t buflen)
2812 len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen);
2818 for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
2819 if (capa->enc & ciphers[i].capa) {
2820 ret = os_snprintf(pos, end - pos, "%s%s",
2821 pos == buf ? "" : " ",
2823 if (ret < 0 || ret >= end - pos)
2833 static int ctrl_iface_get_capability_key_mgmt(int res, char *strict,
2834 struct wpa_driver_capa *capa,
2835 char *buf, size_t buflen)
2847 len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
2854 ret = os_snprintf(pos, end - pos, "NONE IEEE8021X");
2855 if (ret < 0 || ret >= end - pos)
2859 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
2860 WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
2861 ret = os_snprintf(pos, end - pos, " WPA-EAP");
2862 if (ret < 0 || ret >= end - pos)
2867 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
2868 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
2869 ret = os_snprintf(pos, end - pos, " WPA-PSK");
2870 if (ret < 0 || ret >= end - pos)
2875 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
2876 ret = os_snprintf(pos, end - pos, " WPA-NONE");
2877 if (ret < 0 || ret >= end - pos)
2886 static int ctrl_iface_get_capability_proto(int res, char *strict,
2887 struct wpa_driver_capa *capa,
2888 char *buf, size_t buflen)
2900 len = os_strlcpy(buf, "RSN WPA", buflen);
2906 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
2907 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
2908 ret = os_snprintf(pos, end - pos, "%sRSN",
2909 pos == buf ? "" : " ");
2910 if (ret < 0 || ret >= end - pos)
2915 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
2916 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
2917 ret = os_snprintf(pos, end - pos, "%sWPA",
2918 pos == buf ? "" : " ");
2919 if (ret < 0 || ret >= end - pos)
2928 static int ctrl_iface_get_capability_auth_alg(int res, char *strict,
2929 struct wpa_driver_capa *capa,
2930 char *buf, size_t buflen)
2942 len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen);
2948 if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) {
2949 ret = os_snprintf(pos, end - pos, "%sOPEN",
2950 pos == buf ? "" : " ");
2951 if (ret < 0 || ret >= end - pos)
2956 if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) {
2957 ret = os_snprintf(pos, end - pos, "%sSHARED",
2958 pos == buf ? "" : " ");
2959 if (ret < 0 || ret >= end - pos)
2964 if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) {
2965 ret = os_snprintf(pos, end - pos, "%sLEAP",
2966 pos == buf ? "" : " ");
2967 if (ret < 0 || ret >= end - pos)
2976 static int ctrl_iface_get_capability_modes(int res, char *strict,
2977 struct wpa_driver_capa *capa,
2978 char *buf, size_t buflen)
2990 len = os_strlcpy(buf, "IBSS AP", buflen);
2996 if (capa->flags & WPA_DRIVER_FLAGS_IBSS) {
2997 ret = os_snprintf(pos, end - pos, "%sIBSS",
2998 pos == buf ? "" : " ");
2999 if (ret < 0 || ret >= end - pos)
3004 if (capa->flags & WPA_DRIVER_FLAGS_AP) {
3005 ret = os_snprintf(pos, end - pos, "%sAP",
3006 pos == buf ? "" : " ");
3007 if (ret < 0 || ret >= end - pos)
3016 static int ctrl_iface_get_capability_channels(struct wpa_supplicant *wpa_s,
3017 char *buf, size_t buflen)
3019 struct hostapd_channel_data *chnl;
3021 char *pos, *end, *hmode;
3026 for (j = 0; j < wpa_s->hw.num_modes; j++) {
3027 switch (wpa_s->hw.modes[j].mode) {
3028 case HOSTAPD_MODE_IEEE80211B:
3031 case HOSTAPD_MODE_IEEE80211G:
3034 case HOSTAPD_MODE_IEEE80211A:
3037 case HOSTAPD_MODE_IEEE80211AD:
3043 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:", hmode);
3044 if (ret < 0 || ret >= end - pos)
3047 chnl = wpa_s->hw.modes[j].channels;
3048 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
3049 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
3051 ret = os_snprintf(pos, end - pos, " %d", chnl[i].chan);
3052 if (ret < 0 || ret >= end - pos)
3056 ret = os_snprintf(pos, end - pos, "\n");
3057 if (ret < 0 || ret >= end - pos)
3066 static int ctrl_iface_get_capability_freq(struct wpa_supplicant *wpa_s,
3067 char *buf, size_t buflen)
3069 struct hostapd_channel_data *chnl;
3071 char *pos, *end, *hmode;
3076 for (j = 0; j < wpa_s->hw.num_modes; j++) {
3077 switch (wpa_s->hw.modes[j].mode) {
3078 case HOSTAPD_MODE_IEEE80211B:
3081 case HOSTAPD_MODE_IEEE80211G:
3084 case HOSTAPD_MODE_IEEE80211A:
3087 case HOSTAPD_MODE_IEEE80211AD:
3093 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:\n",
3095 if (ret < 0 || ret >= end - pos)
3098 chnl = wpa_s->hw.modes[j].channels;
3099 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
3100 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
3102 ret = os_snprintf(pos, end - pos, " %d = %d MHz%s%s\n",
3103 chnl[i].chan, chnl[i].freq,
3104 chnl[i].flag & HOSTAPD_CHAN_NO_IBSS ?
3106 chnl[i].flag & HOSTAPD_CHAN_RADAR ?
3109 if (ret < 0 || ret >= end - pos)
3113 ret = os_snprintf(pos, end - pos, "\n");
3114 if (ret < 0 || ret >= end - pos)
3123 static int wpa_supplicant_ctrl_iface_get_capability(
3124 struct wpa_supplicant *wpa_s, const char *_field, char *buf,
3127 struct wpa_driver_capa capa;
3133 /* Determine whether or not strict checking was requested */
3134 len = os_strlcpy(field, _field, sizeof(field));
3135 if (len >= sizeof(field))
3137 strict = os_strchr(field, ' ');
3138 if (strict != NULL) {
3140 if (os_strcmp(strict, "strict") != 0)
3144 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
3145 field, strict ? strict : "");
3147 if (os_strcmp(field, "eap") == 0) {
3148 return eap_get_names(buf, buflen);
3151 res = wpa_drv_get_capa(wpa_s, &capa);
3153 if (os_strcmp(field, "pairwise") == 0)
3154 return ctrl_iface_get_capability_pairwise(res, strict, &capa,
3157 if (os_strcmp(field, "group") == 0)
3158 return ctrl_iface_get_capability_group(res, strict, &capa,
3161 if (os_strcmp(field, "key_mgmt") == 0)
3162 return ctrl_iface_get_capability_key_mgmt(res, strict, &capa,
3165 if (os_strcmp(field, "proto") == 0)
3166 return ctrl_iface_get_capability_proto(res, strict, &capa,
3169 if (os_strcmp(field, "auth_alg") == 0)
3170 return ctrl_iface_get_capability_auth_alg(res, strict, &capa,
3173 if (os_strcmp(field, "modes") == 0)
3174 return ctrl_iface_get_capability_modes(res, strict, &capa,
3177 if (os_strcmp(field, "channels") == 0)
3178 return ctrl_iface_get_capability_channels(wpa_s, buf, buflen);
3180 if (os_strcmp(field, "freq") == 0)
3181 return ctrl_iface_get_capability_freq(wpa_s, buf, buflen);
3183 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
3190 #ifdef CONFIG_INTERWORKING
3191 static char * anqp_add_hex(char *pos, char *end, const char *title,
3192 struct wpabuf *data)
3202 ret = os_snprintf(pos, end - pos, "%s=", title);
3203 if (ret < 0 || ret >= end - pos)
3207 d = wpabuf_head_u8(data);
3208 for (i = 0; i < wpabuf_len(data); i++) {
3209 ret = os_snprintf(pos, end - pos, "%02x", *d++);
3210 if (ret < 0 || ret >= end - pos)
3215 ret = os_snprintf(pos, end - pos, "\n");
3216 if (ret < 0 || ret >= end - pos)
3222 #endif /* CONFIG_INTERWORKING */
3225 static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
3226 unsigned long mask, char *buf, size_t buflen)
3236 if (mask & WPA_BSS_MASK_ID) {
3237 ret = os_snprintf(pos, end - pos, "id=%u\n", bss->id);
3238 if (ret < 0 || ret >= end - pos)
3243 if (mask & WPA_BSS_MASK_BSSID) {
3244 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
3245 MAC2STR(bss->bssid));
3246 if (ret < 0 || ret >= end - pos)
3251 if (mask & WPA_BSS_MASK_FREQ) {
3252 ret = os_snprintf(pos, end - pos, "freq=%d\n", bss->freq);
3253 if (ret < 0 || ret >= end - pos)
3258 if (mask & WPA_BSS_MASK_BEACON_INT) {
3259 ret = os_snprintf(pos, end - pos, "beacon_int=%d\n",
3261 if (ret < 0 || ret >= end - pos)
3266 if (mask & WPA_BSS_MASK_CAPABILITIES) {
3267 ret = os_snprintf(pos, end - pos, "capabilities=0x%04x\n",
3269 if (ret < 0 || ret >= end - pos)
3274 if (mask & WPA_BSS_MASK_QUAL) {
3275 ret = os_snprintf(pos, end - pos, "qual=%d\n", bss->qual);
3276 if (ret < 0 || ret >= end - pos)
3281 if (mask & WPA_BSS_MASK_NOISE) {
3282 ret = os_snprintf(pos, end - pos, "noise=%d\n", bss->noise);
3283 if (ret < 0 || ret >= end - pos)
3288 if (mask & WPA_BSS_MASK_LEVEL) {
3289 ret = os_snprintf(pos, end - pos, "level=%d\n", bss->level);
3290 if (ret < 0 || ret >= end - pos)
3295 if (mask & WPA_BSS_MASK_TSF) {
3296 ret = os_snprintf(pos, end - pos, "tsf=%016llu\n",
3297 (unsigned long long) bss->tsf);
3298 if (ret < 0 || ret >= end - pos)
3303 if (mask & WPA_BSS_MASK_AGE) {
3304 struct os_reltime now;
3306 os_get_reltime(&now);
3307 ret = os_snprintf(pos, end - pos, "age=%d\n",
3308 (int) (now.sec - bss->last_update.sec));
3309 if (ret < 0 || ret >= end - pos)
3314 if (mask & WPA_BSS_MASK_IE) {
3315 ret = os_snprintf(pos, end - pos, "ie=");
3316 if (ret < 0 || ret >= end - pos)
3320 ie = (const u8 *) (bss + 1);
3321 for (i = 0; i < bss->ie_len; i++) {
3322 ret = os_snprintf(pos, end - pos, "%02x", *ie++);
3323 if (ret < 0 || ret >= end - pos)
3328 ret = os_snprintf(pos, end - pos, "\n");
3329 if (ret < 0 || ret >= end - pos)
3334 if (mask & WPA_BSS_MASK_FLAGS) {
3335 ret = os_snprintf(pos, end - pos, "flags=");
3336 if (ret < 0 || ret >= end - pos)
3340 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
3342 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie,
3344 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
3346 pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2,
3348 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
3349 if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
3350 ret = os_snprintf(pos, end - pos, "[WEP]");
3351 if (ret < 0 || ret >= end - pos)
3355 if (bss->caps & IEEE80211_CAP_IBSS) {
3356 ret = os_snprintf(pos, end - pos, "[IBSS]");
3357 if (ret < 0 || ret >= end - pos)
3361 if (bss->caps & IEEE80211_CAP_ESS) {
3362 ret = os_snprintf(pos, end - pos, "[ESS]");
3363 if (ret < 0 || ret >= end - pos)
3367 if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
3368 wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
3369 ret = os_snprintf(pos, end - pos, "[P2P]");
3370 if (ret < 0 || ret >= end - pos)
3375 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) {
3376 ret = os_snprintf(pos, end - pos, "[HS20]");
3377 if (ret < 0 || ret >= end - pos)
3381 #endif /* CONFIG_HS20 */
3383 ret = os_snprintf(pos, end - pos, "\n");
3384 if (ret < 0 || ret >= end - pos)
3389 if (mask & WPA_BSS_MASK_SSID) {
3390 ret = os_snprintf(pos, end - pos, "ssid=%s\n",
3391 wpa_ssid_txt(bss->ssid, bss->ssid_len));
3392 if (ret < 0 || ret >= end - pos)
3398 if (mask & WPA_BSS_MASK_WPS_SCAN) {
3399 ie = (const u8 *) (bss + 1);
3400 ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end);
3401 if (ret < 0 || ret >= end - pos)
3405 #endif /* CONFIG_WPS */
3408 if (mask & WPA_BSS_MASK_P2P_SCAN) {
3409 ie = (const u8 *) (bss + 1);
3410 ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end);
3411 if (ret < 0 || ret >= end - pos)
3415 #endif /* CONFIG_P2P */
3417 #ifdef CONFIG_WIFI_DISPLAY
3418 if (mask & WPA_BSS_MASK_WIFI_DISPLAY) {
3420 ie = (const u8 *) (bss + 1);
3421 wfd = ieee802_11_vendor_ie_concat(ie, bss->ie_len,
3422 WFD_IE_VENDOR_TYPE);
3424 ret = os_snprintf(pos, end - pos, "wfd_subelems=");
3425 if (ret < 0 || ret >= end - pos) {
3431 pos += wpa_snprintf_hex(pos, end - pos,
3436 ret = os_snprintf(pos, end - pos, "\n");
3437 if (ret < 0 || ret >= end - pos)
3442 #endif /* CONFIG_WIFI_DISPLAY */
3444 #ifdef CONFIG_INTERWORKING
3445 if ((mask & WPA_BSS_MASK_INTERNETW) && bss->anqp) {
3446 struct wpa_bss_anqp *anqp = bss->anqp;
3447 pos = anqp_add_hex(pos, end, "anqp_venue_name",
3449 pos = anqp_add_hex(pos, end, "anqp_network_auth_type",
3450 anqp->network_auth_type);
3451 pos = anqp_add_hex(pos, end, "anqp_roaming_consortium",
3452 anqp->roaming_consortium);
3453 pos = anqp_add_hex(pos, end, "anqp_ip_addr_type_availability",
3454 anqp->ip_addr_type_availability);
3455 pos = anqp_add_hex(pos, end, "anqp_nai_realm",
3457 pos = anqp_add_hex(pos, end, "anqp_3gpp", anqp->anqp_3gpp);
3458 pos = anqp_add_hex(pos, end, "anqp_domain_name",
3461 pos = anqp_add_hex(pos, end, "hs20_operator_friendly_name",
3462 anqp->hs20_operator_friendly_name);
3463 pos = anqp_add_hex(pos, end, "hs20_wan_metrics",
3464 anqp->hs20_wan_metrics);
3465 pos = anqp_add_hex(pos, end, "hs20_connection_capability",
3466 anqp->hs20_connection_capability);
3467 pos = anqp_add_hex(pos, end, "hs20_operating_class",
3468 anqp->hs20_operating_class);
3469 pos = anqp_add_hex(pos, end, "hs20_osu_providers_list",
3470 anqp->hs20_osu_providers_list);
3471 #endif /* CONFIG_HS20 */
3473 #endif /* CONFIG_INTERWORKING */
3475 if (mask & WPA_BSS_MASK_DELIM) {
3476 ret = os_snprintf(pos, end - pos, "====\n");
3477 if (ret < 0 || ret >= end - pos)
3486 static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
3487 const char *cmd, char *buf,
3492 struct wpa_bss *bss;
3493 struct wpa_bss *bsslast = NULL;
3494 struct dl_list *next;
3498 unsigned long mask = WPA_BSS_MASK_ALL;
3500 if (os_strncmp(cmd, "RANGE=", 6) == 0) {
3501 if (os_strncmp(cmd + 6, "ALL", 3) == 0) {
3502 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss,
3504 bsslast = dl_list_last(&wpa_s->bss_id, struct wpa_bss,
3506 } else { /* N1-N2 */
3507 unsigned int id1, id2;
3509 if ((ctmp = os_strchr(cmd + 6, '-')) == NULL) {
3510 wpa_printf(MSG_INFO, "Wrong BSS range "
3515 if (*(cmd + 6) == '-')
3518 id1 = atoi(cmd + 6);
3520 if (*ctmp >= '0' && *ctmp <= '9')
3523 id2 = (unsigned int) -1;
3524 bss = wpa_bss_get_id_range(wpa_s, id1, id2);
3525 if (id2 == (unsigned int) -1)
3526 bsslast = dl_list_last(&wpa_s->bss_id,
3530 bsslast = wpa_bss_get_id(wpa_s, id2);
3531 if (bsslast == NULL && bss && id2 > id1) {
3532 struct wpa_bss *tmp = bss;
3534 next = tmp->list_id.next;
3535 if (next == &wpa_s->bss_id)
3537 tmp = dl_list_entry(
3538 next, struct wpa_bss,
3547 } else if (os_strncmp(cmd, "FIRST", 5) == 0)
3548 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, list_id);
3549 else if (os_strncmp(cmd, "LAST", 4) == 0)
3550 bss = dl_list_last(&wpa_s->bss_id, struct wpa_bss, list_id);
3551 else if (os_strncmp(cmd, "ID-", 3) == 0) {
3553 bss = wpa_bss_get_id(wpa_s, i);
3554 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
3556 bss = wpa_bss_get_id(wpa_s, i);
3558 next = bss->list_id.next;
3559 if (next == &wpa_s->bss_id)
3562 bss = dl_list_entry(next, struct wpa_bss,
3566 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
3567 if (hwaddr_aton(cmd + 13, bssid) == 0)
3568 bss = wpa_bss_get_p2p_dev_addr(wpa_s, bssid);
3571 #endif /* CONFIG_P2P */
3572 } else if (hwaddr_aton(cmd, bssid) == 0)
3573 bss = wpa_bss_get_bssid(wpa_s, bssid);
3575 struct wpa_bss *tmp;
3578 dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id)
3587 if ((ctmp = os_strstr(cmd, "MASK=")) != NULL) {
3588 mask = strtoul(ctmp + 5, NULL, 0x10);
3590 mask = WPA_BSS_MASK_ALL;
3596 if (bsslast == NULL)
3599 len = print_bss_info(wpa_s, bss, mask, buf, buflen);
3603 if (bss == bsslast) {
3604 if ((mask & WPA_BSS_MASK_DELIM) && len &&
3605 (bss == dl_list_last(&wpa_s->bss_id,
3606 struct wpa_bss, list_id)))
3607 os_snprintf(buf - 5, 5, "####\n");
3610 next = bss->list_id.next;
3611 if (next == &wpa_s->bss_id)
3613 bss = dl_list_entry(next, struct wpa_bss, list_id);
3614 } while (bss && len);
3620 static int wpa_supplicant_ctrl_iface_ap_scan(
3621 struct wpa_supplicant *wpa_s, char *cmd)
3623 int ap_scan = atoi(cmd);
3624 return wpa_supplicant_set_ap_scan(wpa_s, ap_scan);
3628 static int wpa_supplicant_ctrl_iface_scan_interval(
3629 struct wpa_supplicant *wpa_s, char *cmd)
3631 int scan_int = atoi(cmd);
3632 return wpa_supplicant_set_scan_interval(wpa_s, scan_int);
3636 static int wpa_supplicant_ctrl_iface_bss_expire_age(
3637 struct wpa_supplicant *wpa_s, char *cmd)
3639 int expire_age = atoi(cmd);
3640 return wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age);
3644 static int wpa_supplicant_ctrl_iface_bss_expire_count(
3645 struct wpa_supplicant *wpa_s, char *cmd)
3647 int expire_count = atoi(cmd);
3648 return wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count);
3652 static int wpa_supplicant_ctrl_iface_bss_flush(
3653 struct wpa_supplicant *wpa_s, char *cmd)
3655 int flush_age = atoi(cmd);
3658 wpa_bss_flush(wpa_s);
3660 wpa_bss_flush_by_age(wpa_s, flush_age);
3665 static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s)
3667 wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication");
3668 /* MLME-DELETEKEYS.request */
3669 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL, 0);
3670 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL, 0);
3671 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL, 0);
3672 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL, 0);
3673 #ifdef CONFIG_IEEE80211W
3674 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL, 0);
3675 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL, 0);
3676 #endif /* CONFIG_IEEE80211W */
3678 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, wpa_s->bssid, 0, 0, NULL, 0, NULL,
3680 /* MLME-SETPROTECTION.request(None) */
3681 wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid,
3682 MLME_SETPROTECTION_PROTECT_TYPE_NONE,
3683 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE);
3684 wpa_sm_drop_sa(wpa_s->wpa);
3688 static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s,
3691 #ifdef CONFIG_NO_SCAN_PROCESSING
3693 #else /* CONFIG_NO_SCAN_PROCESSING */
3695 struct wpa_bss *bss;
3696 struct wpa_ssid *ssid = wpa_s->current_ssid;
3698 if (hwaddr_aton(addr, bssid)) {
3699 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid "
3700 "address '%s'", addr);
3704 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR, MAC2STR(bssid));
3707 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network "
3708 "configuration known for the target AP");
3712 bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
3714 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found "
3720 * TODO: Find best network configuration block from configuration to
3721 * allow roaming to other networks
3724 wpa_s->reassociate = 1;
3725 wpa_supplicant_connect(wpa_s, bss, ssid);
3728 #endif /* CONFIG_NO_SCAN_PROCESSING */
3733 static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd)
3735 unsigned int timeout = atoi(cmd);
3736 enum p2p_discovery_type type = P2P_FIND_START_WITH_FULL;
3737 u8 dev_id[ETH_ALEN], *_dev_id = NULL;
3738 u8 dev_type[WPS_DEV_TYPE_LEN], *_dev_type = NULL;
3740 unsigned int search_delay;
3742 if (os_strstr(cmd, "type=social"))
3743 type = P2P_FIND_ONLY_SOCIAL;
3744 else if (os_strstr(cmd, "type=progressive"))
3745 type = P2P_FIND_PROGRESSIVE;
3747 pos = os_strstr(cmd, "dev_id=");
3750 if (hwaddr_aton(pos, dev_id))
3755 pos = os_strstr(cmd, "dev_type=");
3758 if (wps_dev_type_str2bin(pos, dev_type) < 0)
3760 _dev_type = dev_type;
3763 pos = os_strstr(cmd, "delay=");
3766 search_delay = atoi(pos);
3768 search_delay = wpas_p2p_search_delay(wpa_s);
3770 return wpas_p2p_find(wpa_s, timeout, type, _dev_type != NULL, _dev_type,
3771 _dev_id, search_delay);
3775 static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd,
3776 char *buf, size_t buflen)
3781 enum p2p_wps_method wps_method;
3784 int persistent_group, persistent_id = -1;
3793 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad]
3794 * [persistent|persistent=<network id>]
3795 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
3798 if (hwaddr_aton(cmd, addr))
3806 persistent_group = os_strstr(pos, " persistent") != NULL;
3807 pos2 = os_strstr(pos, " persistent=");
3809 struct wpa_ssid *ssid;
3810 persistent_id = atoi(pos2 + 12);
3811 ssid = wpa_config_get_network(wpa_s->conf, persistent_id);
3812 if (ssid == NULL || ssid->disabled != 2 ||
3813 ssid->mode != WPAS_MODE_P2P_GO) {
3814 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3815 "SSID id=%d for persistent P2P group (GO)",
3820 join = os_strstr(pos, " join") != NULL;
3821 auth = os_strstr(pos, " auth") != NULL;
3822 automatic = os_strstr(pos, " auto") != NULL;
3823 pd = os_strstr(pos, " provdisc") != NULL;
3824 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
3825 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
3828 pos2 = os_strstr(pos, " go_intent=");
3831 go_intent = atoi(pos2);
3832 if (go_intent < 0 || go_intent > 15)
3836 pos2 = os_strstr(pos, " freq=");
3844 if (os_strncmp(pos, "pin", 3) == 0) {
3845 /* Request random PIN (to be displayed) and enable the PIN */
3846 wps_method = WPS_PIN_DISPLAY;
3847 } else if (os_strncmp(pos, "pbc", 3) == 0) {
3848 wps_method = WPS_PBC;
3851 pos = os_strchr(pin, ' ');
3852 wps_method = WPS_PIN_KEYPAD;
3855 if (os_strncmp(pos, "display", 7) == 0)
3856 wps_method = WPS_PIN_DISPLAY;
3858 if (!wps_pin_str_valid(pin)) {
3859 os_memcpy(buf, "FAIL-INVALID-PIN\n", 17);
3864 new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method,
3865 persistent_group, automatic, join,
3866 auth, go_intent, freq, persistent_id, pd,
3868 if (new_pin == -2) {
3869 os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
3872 if (new_pin == -3) {
3873 os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
3878 if (wps_method == WPS_PIN_DISPLAY && pin == NULL) {
3879 ret = os_snprintf(buf, buflen, "%08d", new_pin);
3880 if (ret < 0 || (size_t) ret >= buflen)
3885 os_memcpy(buf, "OK\n", 3);
3890 static int p2p_ctrl_listen(struct wpa_supplicant *wpa_s, char *cmd)
3892 unsigned int timeout = atoi(cmd);
3893 return wpas_p2p_listen(wpa_s, timeout);
3897 static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd)
3901 enum wpas_p2p_prov_disc_use use = WPAS_P2P_PD_FOR_GO_NEG;
3903 /* <addr> <config method> [join|auto] */
3905 if (hwaddr_aton(cmd, addr))
3913 if (os_strstr(pos, " join") != NULL)
3914 use = WPAS_P2P_PD_FOR_JOIN;
3915 else if (os_strstr(pos, " auto") != NULL)
3916 use = WPAS_P2P_PD_AUTO;
3918 return wpas_p2p_prov_disc(wpa_s, addr, pos, use);
3922 static int p2p_get_passphrase(struct wpa_supplicant *wpa_s, char *buf,
3925 struct wpa_ssid *ssid = wpa_s->current_ssid;
3927 if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO ||
3928 ssid->passphrase == NULL)
3931 os_strlcpy(buf, ssid->passphrase, buflen);
3932 return os_strlen(buf);
3936 static int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd,
3937 char *buf, size_t buflen)
3941 u8 dst_buf[ETH_ALEN], *dst;
3942 struct wpabuf *tlvs;
3946 if (hwaddr_aton(cmd, dst_buf))
3949 if (dst[0] == 0 && dst[1] == 0 && dst[2] == 0 &&
3950 dst[3] == 0 && dst[4] == 0 && dst[5] == 0)
3957 if (os_strncmp(pos, "upnp ", 5) == 0) {
3960 if (hexstr2bin(pos, &version, 1) < 0)
3966 ref = wpas_p2p_sd_request_upnp(wpa_s, dst, version, pos);
3967 #ifdef CONFIG_WIFI_DISPLAY
3968 } else if (os_strncmp(pos, "wifi-display ", 13) == 0) {
3969 ref = wpas_p2p_sd_request_wifi_display(wpa_s, dst, pos + 13);
3970 #endif /* CONFIG_WIFI_DISPLAY */
3972 len = os_strlen(pos);
3976 tlvs = wpabuf_alloc(len);
3979 if (hexstr2bin(pos, wpabuf_put(tlvs, len), len) < 0) {
3984 ref = wpas_p2p_sd_request(wpa_s, dst, tlvs);
3989 res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref);
3990 if (res < 0 || (unsigned) res >= buflen)
3996 static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s,
3999 long long unsigned val;
4001 if (sscanf(cmd, "%llx", &val) != 1)
4004 return wpas_p2p_sd_cancel_request(wpa_s, req);
4008 static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant *wpa_s, char *cmd)
4013 struct wpabuf *resp_tlvs;
4017 pos = os_strchr(cmd, ' ');
4025 if (hwaddr_aton(pos, dst))
4032 pos2 = os_strchr(pos, ' ');
4036 dialog_token = atoi(pos);
4038 len = os_strlen(pos2);
4042 resp_tlvs = wpabuf_alloc(len);
4043 if (resp_tlvs == NULL)
4045 if (hexstr2bin(pos2, wpabuf_put(resp_tlvs, len), len) < 0) {
4046 wpabuf_free(resp_tlvs);
4050 wpas_p2p_sd_response(wpa_s, freq, dst, dialog_token, resp_tlvs);
4051 wpabuf_free(resp_tlvs);
4056 static int p2p_ctrl_serv_disc_external(struct wpa_supplicant *wpa_s,
4059 if (os_strcmp(cmd, "0") && os_strcmp(cmd, "1"))
4061 wpa_s->p2p_sd_over_ctrl_iface = atoi(cmd);
4066 static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant *wpa_s,
4071 struct wpabuf *query, *resp;
4073 pos = os_strchr(cmd, ' ');
4078 len = os_strlen(cmd);
4082 query = wpabuf_alloc(len);
4085 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
4090 len = os_strlen(pos);
4096 resp = wpabuf_alloc(len);
4101 if (hexstr2bin(pos, wpabuf_put(resp, len), len) < 0) {
4107 if (wpas_p2p_service_add_bonjour(wpa_s, query, resp) < 0) {
4116 static int p2p_ctrl_service_add_upnp(struct wpa_supplicant *wpa_s, char *cmd)
4121 pos = os_strchr(cmd, ' ');
4126 if (hexstr2bin(cmd, &version, 1) < 0)
4129 return wpas_p2p_service_add_upnp(wpa_s, version, pos);
4133 static int p2p_ctrl_service_add(struct wpa_supplicant *wpa_s, char *cmd)
4137 pos = os_strchr(cmd, ' ');
4142 if (os_strcmp(cmd, "bonjour") == 0)
4143 return p2p_ctrl_service_add_bonjour(wpa_s, pos);
4144 if (os_strcmp(cmd, "upnp") == 0)
4145 return p2p_ctrl_service_add_upnp(wpa_s, pos);
4146 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
4151 static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant *wpa_s,
4155 struct wpabuf *query;
4158 len = os_strlen(cmd);
4162 query = wpabuf_alloc(len);
4165 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
4170 ret = wpas_p2p_service_del_bonjour(wpa_s, query);
4176 static int p2p_ctrl_service_del_upnp(struct wpa_supplicant *wpa_s, char *cmd)
4181 pos = os_strchr(cmd, ' ');
4186 if (hexstr2bin(cmd, &version, 1) < 0)
4189 return wpas_p2p_service_del_upnp(wpa_s, version, pos);
4193 static int p2p_ctrl_service_del(struct wpa_supplicant *wpa_s, char *cmd)
4197 pos = os_strchr(cmd, ' ');
4202 if (os_strcmp(cmd, "bonjour") == 0)
4203 return p2p_ctrl_service_del_bonjour(wpa_s, pos);
4204 if (os_strcmp(cmd, "upnp") == 0)
4205 return p2p_ctrl_service_del_upnp(wpa_s, pos);
4206 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
4211 static int p2p_ctrl_reject(struct wpa_supplicant *wpa_s, char *cmd)
4217 if (hwaddr_aton(cmd, addr))
4220 return wpas_p2p_reject(wpa_s, addr);
4224 static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd)
4228 struct wpa_ssid *ssid;
4229 u8 *_peer = NULL, peer[ETH_ALEN];
4230 int freq = 0, pref_freq = 0;
4234 pos = os_strstr(cmd, " peer=");
4237 if (hwaddr_aton(pos, peer))
4241 ssid = wpa_config_get_network(wpa_s->conf, id);
4242 if (ssid == NULL || ssid->disabled != 2) {
4243 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
4244 "for persistent P2P group",
4249 pos = os_strstr(cmd, " freq=");
4257 pos = os_strstr(cmd, " pref=");
4260 pref_freq = atoi(pos);
4265 vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
4266 ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
4269 return wpas_p2p_invite(wpa_s, _peer, ssid, NULL, freq, ht40, vht,
4274 static int p2p_ctrl_invite_group(struct wpa_supplicant *wpa_s, char *cmd)
4277 u8 peer[ETH_ALEN], go_dev_addr[ETH_ALEN], *go_dev = NULL;
4279 pos = os_strstr(cmd, " peer=");
4285 if (hwaddr_aton(pos, peer)) {
4286 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", pos);
4290 pos = os_strstr(pos, " go_dev_addr=");
4293 if (hwaddr_aton(pos, go_dev_addr)) {
4294 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'",
4298 go_dev = go_dev_addr;
4301 return wpas_p2p_invite_group(wpa_s, cmd, peer, go_dev);
4305 static int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd)
4307 if (os_strncmp(cmd, "persistent=", 11) == 0)
4308 return p2p_ctrl_invite_persistent(wpa_s, cmd + 11);
4309 if (os_strncmp(cmd, "group=", 6) == 0)
4310 return p2p_ctrl_invite_group(wpa_s, cmd + 6);
4316 static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s,
4317 char *cmd, int freq, int ht40,
4321 struct wpa_ssid *ssid;
4324 ssid = wpa_config_get_network(wpa_s->conf, id);
4325 if (ssid == NULL || ssid->disabled != 2) {
4326 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
4327 "for persistent P2P group",
4332 return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq, 0, ht40, vht,
4337 static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd)
4339 int freq = 0, ht40, vht;
4342 pos = os_strstr(cmd, "freq=");
4344 freq = atoi(pos + 5);
4346 vht = (os_strstr(cmd, "vht") != NULL) || wpa_s->conf->p2p_go_vht;
4347 ht40 = (os_strstr(cmd, "ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
4350 if (os_strncmp(cmd, "persistent=", 11) == 0)
4351 return p2p_ctrl_group_add_persistent(wpa_s, cmd + 11, freq,
4353 if (os_strcmp(cmd, "persistent") == 0 ||
4354 os_strncmp(cmd, "persistent ", 11) == 0)
4355 return wpas_p2p_group_add(wpa_s, 1, freq, ht40, vht);
4356 if (os_strncmp(cmd, "freq=", 5) == 0)
4357 return wpas_p2p_group_add(wpa_s, 0, freq, ht40, vht);
4359 return wpas_p2p_group_add(wpa_s, 0, freq, ht40, vht);
4361 wpa_printf(MSG_DEBUG, "CTRL: Invalid P2P_GROUP_ADD parameters '%s'",
4367 static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd,
4368 char *buf, size_t buflen)
4370 u8 addr[ETH_ALEN], *addr_ptr;
4372 const struct p2p_peer_info *info;
4374 char devtype[WPS_DEV_TYPE_BUFSIZE];
4375 struct wpa_ssid *ssid;
4378 if (!wpa_s->global->p2p)
4381 if (os_strcmp(cmd, "FIRST") == 0) {
4384 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
4385 if (hwaddr_aton(cmd + 5, addr) < 0)
4390 if (hwaddr_aton(cmd, addr) < 0)
4396 info = p2p_get_peer_info(wpa_s->global->p2p, addr_ptr, next);
4403 res = os_snprintf(pos, end - pos, MACSTR "\n"
4409 "serial_number=%s\n"
4410 "config_methods=0x%x\n"
4412 "group_capab=0x%x\n"
4414 MAC2STR(info->p2p_device_addr),
4415 wps_dev_type_bin2str(info->pri_dev_type,
4416 devtype, sizeof(devtype)),
4421 info->serial_number,
4422 info->config_methods,
4426 if (res < 0 || res >= end - pos)
4430 for (i = 0; i < info->wps_sec_dev_type_list_len / WPS_DEV_TYPE_LEN; i++)
4433 t = &info->wps_sec_dev_type_list[i * WPS_DEV_TYPE_LEN];
4434 res = os_snprintf(pos, end - pos, "sec_dev_type=%s\n",
4435 wps_dev_type_bin2str(t, devtype,
4437 if (res < 0 || res >= end - pos)
4442 ssid = wpas_p2p_get_persistent(wpa_s, info->p2p_device_addr, NULL, 0);
4444 res = os_snprintf(pos, end - pos, "persistent=%d\n", ssid->id);
4445 if (res < 0 || res >= end - pos)
4450 res = p2p_get_peer_info_txt(info, pos, end - pos);
4459 static int p2p_ctrl_disallow_freq(struct wpa_supplicant *wpa_s,
4464 if (wpa_s->global->p2p == NULL)
4467 if (freq_range_list_parse(&wpa_s->global->p2p_disallow_freq, param) < 0)
4470 for (i = 0; i < wpa_s->global->p2p_disallow_freq.num; i++) {
4471 struct wpa_freq_range *freq;
4472 freq = &wpa_s->global->p2p_disallow_freq.range[i];
4473 wpa_printf(MSG_DEBUG, "P2P: Disallowed frequency range %u-%u",
4474 freq->min, freq->max);
4477 wpas_p2p_update_channel_list(wpa_s);
4482 static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd)
4486 if (wpa_s->global->p2p == NULL)
4489 param = os_strchr(cmd, ' ');
4494 if (os_strcmp(cmd, "discoverability") == 0) {
4495 p2p_set_client_discoverability(wpa_s->global->p2p,
4500 if (os_strcmp(cmd, "managed") == 0) {
4501 p2p_set_managed_oper(wpa_s->global->p2p, atoi(param));
4505 if (os_strcmp(cmd, "listen_channel") == 0) {
4506 return p2p_set_listen_channel(wpa_s->global->p2p, 81,
4510 if (os_strcmp(cmd, "ssid_postfix") == 0) {
4511 return p2p_set_ssid_postfix(wpa_s->global->p2p, (u8 *) param,
4515 if (os_strcmp(cmd, "noa") == 0) {
4517 int count, start, duration;
4518 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
4519 count = atoi(param);
4520 pos = os_strchr(param, ',');
4525 pos = os_strchr(pos, ',');
4529 duration = atoi(pos);
4530 if (count < 0 || count > 255 || start < 0 || duration < 0)
4532 if (count == 0 && duration > 0)
4534 wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
4535 "start=%d duration=%d", count, start, duration);
4536 return wpas_p2p_set_noa(wpa_s, count, start, duration);
4539 if (os_strcmp(cmd, "ps") == 0)
4540 return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1);
4542 if (os_strcmp(cmd, "oppps") == 0)
4543 return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1);
4545 if (os_strcmp(cmd, "ctwindow") == 0)
4546 return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param));
4548 if (os_strcmp(cmd, "disabled") == 0) {
4549 wpa_s->global->p2p_disabled = atoi(param);
4550 wpa_printf(MSG_DEBUG, "P2P functionality %s",
4551 wpa_s->global->p2p_disabled ?
4552 "disabled" : "enabled");
4553 if (wpa_s->global->p2p_disabled) {
4554 wpas_p2p_stop_find(wpa_s);
4555 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
4556 p2p_flush(wpa_s->global->p2p);
4561 if (os_strcmp(cmd, "conc_pref") == 0) {
4562 if (os_strcmp(param, "sta") == 0)
4563 wpa_s->global->conc_pref = WPA_CONC_PREF_STA;
4564 else if (os_strcmp(param, "p2p") == 0)
4565 wpa_s->global->conc_pref = WPA_CONC_PREF_P2P;
4567 wpa_printf(MSG_INFO, "Invalid conc_pref value");
4570 wpa_printf(MSG_DEBUG, "Single channel concurrency preference: "
4575 if (os_strcmp(cmd, "force_long_sd") == 0) {
4576 wpa_s->force_long_sd = atoi(param);
4580 if (os_strcmp(cmd, "peer_filter") == 0) {
4582 if (hwaddr_aton(param, addr))
4584 p2p_set_peer_filter(wpa_s->global->p2p, addr);
4588 if (os_strcmp(cmd, "cross_connect") == 0)
4589 return wpas_p2p_set_cross_connect(wpa_s, atoi(param));
4591 if (os_strcmp(cmd, "go_apsd") == 0) {
4592 if (os_strcmp(param, "disable") == 0)
4593 wpa_s->set_ap_uapsd = 0;
4595 wpa_s->set_ap_uapsd = 1;
4596 wpa_s->ap_uapsd = atoi(param);
4601 if (os_strcmp(cmd, "client_apsd") == 0) {
4602 if (os_strcmp(param, "disable") == 0)
4603 wpa_s->set_sta_uapsd = 0;
4607 /* format: BE,BK,VI,VO;max SP Length */
4609 pos = os_strchr(param, ',');
4614 pos = os_strchr(pos, ',');
4619 pos = os_strchr(pos, ',');
4624 /* ignore max SP Length for now */
4626 wpa_s->set_sta_uapsd = 1;
4627 wpa_s->sta_uapsd = 0;
4629 wpa_s->sta_uapsd |= BIT(0);
4631 wpa_s->sta_uapsd |= BIT(1);
4633 wpa_s->sta_uapsd |= BIT(2);
4635 wpa_s->sta_uapsd |= BIT(3);
4640 if (os_strcmp(cmd, "disallow_freq") == 0)
4641 return p2p_ctrl_disallow_freq(wpa_s, param);
4643 if (os_strcmp(cmd, "disc_int") == 0) {
4644 int min_disc_int, max_disc_int, max_disc_tu;
4649 min_disc_int = atoi(pos);
4650 pos = os_strchr(pos, ' ');
4655 max_disc_int = atoi(pos);
4656 pos = os_strchr(pos, ' ');
4661 max_disc_tu = atoi(pos);
4663 return p2p_set_disc_int(wpa_s->global->p2p, min_disc_int,
4664 max_disc_int, max_disc_tu);
4667 if (os_strcmp(cmd, "per_sta_psk") == 0) {
4668 wpa_s->global->p2p_per_sta_psk = !!atoi(param);
4672 #ifdef CONFIG_WPS_NFC
4673 if (os_strcmp(cmd, "nfc_tag") == 0)
4674 return wpas_p2p_nfc_tag_enabled(wpa_s, !!atoi(param));
4675 #endif /* CONFIG_WPS_NFC */
4677 if (os_strcmp(cmd, "disable_ip_addr_req") == 0) {
4678 wpa_s->p2p_disable_ip_addr_req = !!atoi(param);
4682 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
4689 static void p2p_ctrl_flush(struct wpa_supplicant *wpa_s)
4691 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
4692 wpa_s->force_long_sd = 0;
4693 if (wpa_s->global->p2p)
4694 p2p_flush(wpa_s->global->p2p);
4698 static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd)
4701 unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0;
4704 pos = os_strchr(cmd, ' ');
4710 pos2 = os_strchr(pos, ' ');
4718 pos = os_strchr(pos2, ' ');
4726 return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2);
4730 static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd)
4733 unsigned int period = 0, interval = 0;
4736 pos = os_strchr(cmd, ' ');
4741 interval = atoi(pos);
4744 return wpas_p2p_ext_listen(wpa_s, period, interval);
4748 static int p2p_ctrl_remove_client(struct wpa_supplicant *wpa_s, const char *cmd)
4755 if (os_strncmp(pos, "iface=", 6) == 0) {
4759 if (hwaddr_aton(pos, peer))
4762 wpas_p2p_remove_client(wpa_s, peer, iface_addr);
4766 #endif /* CONFIG_P2P */
4769 static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s, char *val)
4771 struct wpa_freq_range_list ranges;
4773 struct hostapd_hw_modes *mode;
4776 if (wpa_s->hw.modes == NULL)
4779 os_memset(&ranges, 0, sizeof(ranges));
4780 if (freq_range_list_parse(&ranges, val) < 0)
4783 for (i = 0; i < wpa_s->hw.num_modes; i++) {
4786 mode = &wpa_s->hw.modes[i];
4787 for (j = 0; j < mode->num_channels; j++) {
4790 if (mode->channels[j].flag & HOSTAPD_CHAN_DISABLED)
4793 freq = mode->channels[j].freq;
4794 if (!freq_range_list_includes(&ranges, freq))
4797 int_array_add_unique(&freqs, freq);
4801 os_free(ranges.range);
4806 #ifdef CONFIG_INTERWORKING
4808 static int ctrl_interworking_select(struct wpa_supplicant *wpa_s, char *param)
4816 auto_sel = os_strstr(param, "auto") != NULL;
4818 pos = os_strstr(param, "freq=");
4820 freqs = freq_range_to_channel_list(wpa_s, pos + 5);
4827 return interworking_select(wpa_s, auto_sel, freqs);
4831 static int ctrl_interworking_connect(struct wpa_supplicant *wpa_s, char *dst)
4834 struct wpa_bss *bss;
4836 if (hwaddr_aton(dst, bssid)) {
4837 wpa_printf(MSG_DEBUG, "Invalid BSSID '%s'", dst);
4841 bss = wpa_bss_get_bssid(wpa_s, bssid);
4843 wpa_printf(MSG_DEBUG, "Could not find BSS " MACSTR,
4848 return interworking_connect(wpa_s, bss);
4852 static int get_anqp(struct wpa_supplicant *wpa_s, char *dst)
4854 u8 dst_addr[ETH_ALEN];
4857 #define MAX_ANQP_INFO_ID 100
4858 u16 id[MAX_ANQP_INFO_ID];
4861 used = hwaddr_aton2(dst, dst_addr);
4865 while (num_id < MAX_ANQP_INFO_ID) {
4866 id[num_id] = atoi(pos);
4869 pos = os_strchr(pos + 1, ',');
4878 return anqp_send_req(wpa_s, dst_addr, id, num_id);
4882 static int gas_request(struct wpa_supplicant *wpa_s, char *cmd)
4884 u8 dst_addr[ETH_ALEN];
4885 struct wpabuf *advproto, *query = NULL;
4890 used = hwaddr_aton2(cmd, dst_addr);
4898 /* Advertisement Protocol ID */
4899 end = os_strchr(pos, ' ');
4903 len = os_strlen(pos);
4909 advproto = wpabuf_alloc(len);
4910 if (advproto == NULL)
4912 if (hexstr2bin(pos, wpabuf_put(advproto, len), len) < 0)
4916 /* Optional Query Request */
4921 len = os_strlen(pos);
4928 query = wpabuf_alloc(len);
4931 if (hexstr2bin(pos, wpabuf_put(query, len), len) < 0)
4936 ret = gas_send_request(wpa_s, dst_addr, advproto, query);
4939 wpabuf_free(advproto);
4946 static int gas_response_get(struct wpa_supplicant *wpa_s, char *cmd, char *buf,
4953 size_t resp_len, start, requested_len;
4954 struct wpabuf *resp;
4957 used = hwaddr_aton2(cmd, addr);
4964 dialog_token = atoi(pos);
4966 if (wpa_s->last_gas_resp &&
4967 os_memcmp(addr, wpa_s->last_gas_addr, ETH_ALEN) == 0 &&
4968 dialog_token == wpa_s->last_gas_dialog_token)
4969 resp = wpa_s->last_gas_resp;
4970 else if (wpa_s->prev_gas_resp &&
4971 os_memcmp(addr, wpa_s->prev_gas_addr, ETH_ALEN) == 0 &&
4972 dialog_token == wpa_s->prev_gas_dialog_token)
4973 resp = wpa_s->prev_gas_resp;
4977 resp_len = wpabuf_len(resp);
4979 requested_len = resp_len;
4981 pos = os_strchr(pos, ' ');
4984 if (start > resp_len)
4985 return os_snprintf(buf, buflen, "FAIL-Invalid range");
4986 pos = os_strchr(pos, ',');
4990 requested_len = atoi(pos);
4991 if (start + requested_len > resp_len)
4992 return os_snprintf(buf, buflen, "FAIL-Invalid range");
4995 if (requested_len * 2 + 1 > buflen)
4996 return os_snprintf(buf, buflen, "FAIL-Too long response");
4998 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(resp) + start,
5001 if (start + requested_len == resp_len) {
5003 * Free memory by dropping the response after it has been
5006 if (resp == wpa_s->prev_gas_resp) {
5007 wpabuf_free(wpa_s->prev_gas_resp);
5008 wpa_s->prev_gas_resp = NULL;
5010 wpabuf_free(wpa_s->last_gas_resp);
5011 wpa_s->last_gas_resp = NULL;
5017 #endif /* CONFIG_INTERWORKING */
5022 static int get_hs20_anqp(struct wpa_supplicant *wpa_s, char *dst)
5024 u8 dst_addr[ETH_ALEN];
5029 used = hwaddr_aton2(dst, dst_addr);
5034 int num = atoi(pos);
5035 if (num <= 0 || num > 31)
5037 subtypes |= BIT(num);
5038 pos = os_strchr(pos + 1, ',');
5047 return hs20_anqp_send_req(wpa_s, dst_addr, subtypes, NULL, 0);
5051 static int hs20_nai_home_realm_list(struct wpa_supplicant *wpa_s,
5052 const u8 *addr, const char *realm)
5058 rlen = os_strlen(realm);
5060 buf = os_malloc(len);
5063 buf[0] = 1; /* NAI Home Realm Count */
5064 buf[1] = 0; /* Formatted in accordance with RFC 4282 */
5066 os_memcpy(buf + 3, realm, rlen);
5068 ret = hs20_anqp_send_req(wpa_s, addr,
5069 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
5078 static int hs20_get_nai_home_realm_list(struct wpa_supplicant *wpa_s,
5081 struct wpa_cred *cred = wpa_s->conf->cred;
5082 u8 dst_addr[ETH_ALEN];
5088 used = hwaddr_aton2(dst, dst_addr);
5092 while (dst[used] == ' ')
5094 if (os_strncmp(dst + used, "realm=", 6) == 0)
5095 return hs20_nai_home_realm_list(wpa_s, dst_addr,
5098 len = os_strlen(dst + used);
5100 if (len == 0 && cred && cred->realm)
5101 return hs20_nai_home_realm_list(wpa_s, dst_addr, cred->realm);
5106 buf = os_malloc(len);
5109 if (hexstr2bin(dst + used, buf, len) < 0) {
5114 ret = hs20_anqp_send_req(wpa_s, dst_addr,
5115 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
5123 static int hs20_icon_request(struct wpa_supplicant *wpa_s, char *cmd)
5125 u8 dst_addr[ETH_ALEN];
5129 used = hwaddr_aton2(cmd, dst_addr);
5133 while (cmd[used] == ' ')
5137 wpa_s->fetch_osu_icon_in_progress = 0;
5138 return hs20_anqp_send_req(wpa_s, dst_addr, BIT(HS20_STYPE_ICON_REQUEST),
5139 (u8 *) icon, os_strlen(icon));
5142 #endif /* CONFIG_HS20 */
5145 static int wpa_supplicant_ctrl_iface_sta_autoconnect(
5146 struct wpa_supplicant *wpa_s, char *cmd)
5148 wpa_s->auto_reconnect_disabled = atoi(cmd) == 0 ? 1 : 0;
5153 #ifdef CONFIG_AUTOSCAN
5155 static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant *wpa_s,
5158 enum wpa_states state = wpa_s->wpa_state;
5159 char *new_params = NULL;
5161 if (os_strlen(cmd) > 0) {
5162 new_params = os_strdup(cmd);
5163 if (new_params == NULL)
5167 os_free(wpa_s->conf->autoscan);
5168 wpa_s->conf->autoscan = new_params;
5170 if (wpa_s->conf->autoscan == NULL)
5171 autoscan_deinit(wpa_s);
5172 else if (state == WPA_DISCONNECTED || state == WPA_INACTIVE)
5173 autoscan_init(wpa_s, 1);
5174 else if (state == WPA_SCANNING)
5175 wpa_supplicant_reinit_autoscan(wpa_s);
5180 #endif /* CONFIG_AUTOSCAN */
5185 static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant *wpa_s, char *cmd)
5191 struct wpabuf *tfs_req = NULL;
5193 if (os_strncmp(cmd, "enter", 5) == 0)
5195 else if (os_strncmp(cmd, "exit", 4) == 0)
5200 pos = os_strstr(cmd, " interval=");
5202 intval = atoi(pos + 10);
5204 pos = os_strstr(cmd, " tfs_req=");
5209 end = os_strchr(pos, ' ');
5213 len = os_strlen(pos);
5217 tfs_req = wpabuf_alloc(len);
5218 if (tfs_req == NULL)
5220 if (hexstr2bin(pos, wpabuf_put(tfs_req, len), len) < 0) {
5221 wpabuf_free(tfs_req);
5226 ret = ieee802_11_send_wnmsleep_req(wpa_s, enter ? WNM_SLEEP_MODE_ENTER :
5227 WNM_SLEEP_MODE_EXIT, intval,
5229 wpabuf_free(tfs_req);
5235 static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant *wpa_s, char *cmd)
5239 query_reason = atoi(cmd);
5241 wpa_printf(MSG_DEBUG, "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d",
5244 return wnm_send_bss_transition_mgmt_query(wpa_s, query_reason);
5247 #endif /* CONFIG_WNM */
5250 /* Get string representation of channel width */
5251 static const char * channel_width_name(enum chan_width width)
5254 case CHAN_WIDTH_20_NOHT:
5255 return "20 MHz (no HT)";
5262 case CHAN_WIDTH_80P80:
5264 case CHAN_WIDTH_160:
5272 static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf,
5275 struct wpa_signal_info si;
5279 ret = wpa_drv_signal_poll(wpa_s, &si);
5286 ret = os_snprintf(pos, end - pos, "RSSI=%d\nLINKSPEED=%d\n"
5287 "NOISE=%d\nFREQUENCY=%u\n",
5288 si.current_signal, si.current_txrate / 1000,
5289 si.current_noise, si.frequency);
5290 if (ret < 0 || ret > end - pos)
5294 if (si.chanwidth != CHAN_WIDTH_UNKNOWN) {
5295 ret = os_snprintf(pos, end - pos, "WIDTH=%s\n",
5296 channel_width_name(si.chanwidth));
5297 if (ret < 0 || ret > end - pos)
5302 if (si.center_frq1 > 0 && si.center_frq2 > 0) {
5303 ret = os_snprintf(pos, end - pos,
5304 "CENTER_FRQ1=%d\nCENTER_FRQ2=%d\n",
5305 si.center_frq1, si.center_frq2);
5306 if (ret < 0 || ret > end - pos)
5311 if (si.avg_signal) {
5312 ret = os_snprintf(pos, end - pos,
5313 "AVG_RSSI=%d\n", si.avg_signal);
5314 if (ret < 0 || ret >= end - pos)
5323 static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant *wpa_s, char *buf,
5326 struct hostap_sta_driver_data sta;
5329 ret = wpa_drv_pktcnt_poll(wpa_s, &sta);
5333 ret = os_snprintf(buf, buflen, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
5334 sta.tx_packets, sta.tx_retry_failed, sta.rx_packets);
5335 if (ret < 0 || (size_t) ret > buflen)
5342 static int wpa_supplicant_driver_cmd(struct wpa_supplicant *wpa_s, char *cmd,
5343 char *buf, size_t buflen)
5347 ret = wpa_drv_driver_cmd(wpa_s, cmd, buf, buflen);
5349 if (os_strncasecmp(cmd, "COUNTRY", 7) == 0) {
5350 struct p2p_data *p2p = wpa_s->global->p2p;
5353 country[0] = cmd[8];
5354 country[1] = cmd[9];
5356 p2p_set_country(p2p, country);
5359 ret = os_snprintf(buf, buflen, "%s\n", "OK");
5363 #endif /* ANDROID */
5366 static int wpa_supplicant_vendor_cmd(struct wpa_supplicant *wpa_s, char *cmd,
5367 char *buf, size_t buflen)
5372 unsigned int vendor_id, subcmd;
5373 struct wpabuf *reply;
5374 size_t data_len = 0;
5376 /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */
5377 vendor_id = strtoul(cmd, &pos, 16);
5381 subcmd = strtoul(pos, &pos, 10);
5384 if (!isblank(*pos++))
5386 data_len = os_strlen(pos);
5391 data = os_malloc(data_len);
5395 if (hexstr2bin(pos, data, data_len)) {
5396 wpa_printf(MSG_DEBUG,
5397 "Vendor command: wrong parameter format");
5403 reply = wpabuf_alloc((buflen - 1) / 2);
5409 ret = wpa_drv_vendor_cmd(wpa_s, vendor_id, subcmd, data, data_len,
5413 ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(reply),
5423 static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s)
5425 wpa_dbg(wpa_s, MSG_DEBUG, "Flush all wpa_supplicant state");
5428 wpas_p2p_stop_find(wpa_s);
5429 p2p_ctrl_flush(wpa_s);
5430 wpas_p2p_group_remove(wpa_s, "*");
5431 wpas_p2p_service_flush(wpa_s);
5432 wpa_s->global->p2p_disabled = 0;
5433 wpa_s->global->p2p_per_sta_psk = 0;
5434 wpa_s->conf->num_sec_device_types = 0;
5435 wpa_s->p2p_disable_ip_addr_req = 0;
5436 #endif /* CONFIG_P2P */
5438 #ifdef CONFIG_WPS_TESTING
5439 wps_version_number = 0x20;
5440 wps_testing_dummy_cred = 0;
5441 wps_corrupt_pkhash = 0;
5442 #endif /* CONFIG_WPS_TESTING */
5444 wpa_s->wps_fragment_size = 0;
5445 wpas_wps_cancel(wpa_s);
5446 #endif /* CONFIG_WPS */
5447 wpa_s->after_wps = 0;
5448 wpa_s->known_wps_freq = 0;
5451 #ifdef CONFIG_TDLS_TESTING
5452 extern unsigned int tdls_testing;
5454 #endif /* CONFIG_TDLS_TESTING */
5455 wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL);
5456 wpa_tdls_enable(wpa_s->wpa, 1);
5457 #endif /* CONFIG_TDLS */
5459 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, wpa_s, NULL);
5460 wpa_supplicant_stop_countermeasures(wpa_s, NULL);
5462 wpa_s->no_keep_alive = 0;
5464 os_free(wpa_s->disallow_aps_bssid);
5465 wpa_s->disallow_aps_bssid = NULL;
5466 wpa_s->disallow_aps_bssid_count = 0;
5467 os_free(wpa_s->disallow_aps_ssid);
5468 wpa_s->disallow_aps_ssid = NULL;
5469 wpa_s->disallow_aps_ssid_count = 0;
5471 wpa_s->set_sta_uapsd = 0;
5472 wpa_s->sta_uapsd = 0;
5474 wpa_drv_radio_disable(wpa_s, 0);
5476 wpa_bss_flush(wpa_s);
5477 wpa_blacklist_clear(wpa_s);
5478 wpa_s->extra_blacklist_count = 0;
5479 wpa_supplicant_ctrl_iface_remove_network(wpa_s, "all");
5480 wpa_supplicant_ctrl_iface_remove_cred(wpa_s, "all");
5481 wpa_config_flush_blobs(wpa_s->conf);
5482 wpa_s->conf->auto_interworking = 0;
5483 wpa_s->conf->okc = 0;
5485 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, 43200);
5486 wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, 70);
5487 wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, 60);
5488 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
5490 radio_remove_works(wpa_s, NULL, 1);
5492 wpa_s->next_ssid = NULL;
5494 #ifdef CONFIG_INTERWORKING
5495 hs20_cancel_fetch_osu(wpa_s);
5496 #endif /* CONFIG_INTERWORKING */
5498 wpa_s->ext_mgmt_frame_handling = 0;
5502 static int wpas_ctrl_radio_work_show(struct wpa_supplicant *wpa_s,
5503 char *buf, size_t buflen)
5505 struct wpa_radio_work *work;
5507 struct os_reltime now, diff;
5512 os_get_reltime(&now);
5514 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
5518 os_reltime_sub(&now, &work->time, &diff);
5519 ret = os_snprintf(pos, end - pos, "%s@%s:%u:%u:%ld.%06ld\n",
5520 work->type, work->wpa_s->ifname, work->freq,
5521 work->started, diff.sec, diff.usec);
5522 if (ret < 0 || ret >= end - pos)
5531 static void wpas_ctrl_radio_work_timeout(void *eloop_ctx, void *timeout_ctx)
5533 struct wpa_radio_work *work = eloop_ctx;
5534 struct wpa_external_work *ework = work->ctx;
5536 wpa_dbg(work->wpa_s, MSG_DEBUG,
5537 "Timing out external radio work %u (%s)",
5538 ework->id, work->type);
5539 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_TIMEOUT "%u", ework->id);
5541 radio_work_done(work);
5545 static void wpas_ctrl_radio_work_cb(struct wpa_radio_work *work, int deinit)
5547 struct wpa_external_work *ework = work->ctx;
5551 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
5558 wpa_dbg(work->wpa_s, MSG_DEBUG, "Starting external radio work %u (%s)",
5559 ework->id, ework->type);
5560 wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_START "%u", ework->id);
5561 if (!ework->timeout)
5562 ework->timeout = 10;
5563 eloop_register_timeout(ework->timeout, 0, wpas_ctrl_radio_work_timeout,
5568 static int wpas_ctrl_radio_work_add(struct wpa_supplicant *wpa_s, char *cmd,
5569 char *buf, size_t buflen)
5571 struct wpa_external_work *ework;
5575 unsigned int freq = 0;
5577 /* format: <name> [freq=<MHz>] [timeout=<seconds>] */
5579 ework = os_zalloc(sizeof(*ework));
5583 pos = os_strchr(cmd, ' ');
5585 type_len = pos - cmd;
5588 pos2 = os_strstr(pos, "freq=");
5590 freq = atoi(pos2 + 5);
5592 pos2 = os_strstr(pos, "timeout=");
5594 ework->timeout = atoi(pos2 + 8);
5596 type_len = os_strlen(cmd);
5598 if (4 + type_len >= sizeof(ework->type))
5599 type_len = sizeof(ework->type) - 4 - 1;
5600 os_strlcpy(ework->type, "ext:", sizeof(ework->type));
5601 os_memcpy(ework->type + 4, cmd, type_len);
5602 ework->type[4 + type_len] = '\0';
5604 wpa_s->ext_work_id++;
5605 if (wpa_s->ext_work_id == 0)
5606 wpa_s->ext_work_id++;
5607 ework->id = wpa_s->ext_work_id;
5609 if (radio_add_work(wpa_s, freq, ework->type, 0, wpas_ctrl_radio_work_cb,
5615 ret = os_snprintf(buf, buflen, "%u", ework->id);
5616 if (ret < 0 || (size_t) ret >= buflen)
5622 static int wpas_ctrl_radio_work_done(struct wpa_supplicant *wpa_s, char *cmd)
5624 struct wpa_radio_work *work;
5625 unsigned int id = atoi(cmd);
5627 dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
5629 struct wpa_external_work *ework;
5631 if (os_strncmp(work->type, "ext:", 4) != 0)
5634 if (id && ework->id != id)
5636 wpa_dbg(wpa_s, MSG_DEBUG,
5637 "Completed external radio work %u (%s)",
5638 ework->id, ework->type);
5639 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, work, NULL);
5641 radio_work_done(work);
5642 return 3; /* "OK\n" */
5649 static int wpas_ctrl_radio_work(struct wpa_supplicant *wpa_s, char *cmd,
5650 char *buf, size_t buflen)
5652 if (os_strcmp(cmd, "show") == 0)
5653 return wpas_ctrl_radio_work_show(wpa_s, buf, buflen);
5654 if (os_strncmp(cmd, "add ", 4) == 0)
5655 return wpas_ctrl_radio_work_add(wpa_s, cmd + 4, buf, buflen);
5656 if (os_strncmp(cmd, "done ", 5) == 0)
5657 return wpas_ctrl_radio_work_done(wpa_s, cmd + 4);
5662 void wpas_ctrl_radio_work_flush(struct wpa_supplicant *wpa_s)
5664 struct wpa_radio_work *work, *tmp;
5666 if (!wpa_s || !wpa_s->radio)
5669 dl_list_for_each_safe(work, tmp, &wpa_s->radio->work,
5670 struct wpa_radio_work, list) {
5671 struct wpa_external_work *ework;
5673 if (os_strncmp(work->type, "ext:", 4) != 0)
5676 wpa_dbg(wpa_s, MSG_DEBUG,
5677 "Flushing %sexternal radio work %u (%s)",
5678 work->started ? " started" : "", ework->id,
5681 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
5684 radio_work_done(work);
5689 static void wpas_ctrl_eapol_response(void *eloop_ctx, void *timeout_ctx)
5691 struct wpa_supplicant *wpa_s = eloop_ctx;
5692 eapol_sm_notify_ctrl_response(wpa_s->eapol);
5696 static int set_scan_freqs(struct wpa_supplicant *wpa_s, char *val)
5700 freqs = freq_range_to_channel_list(wpa_s, val);
5704 os_free(wpa_s->manual_scan_freqs);
5705 wpa_s->manual_scan_freqs = freqs;
5711 static void wpas_ctrl_scan(struct wpa_supplicant *wpa_s, char *params,
5712 char *reply, int reply_size, int *reply_len)
5716 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
5721 wpa_s->manual_scan_passive = 0;
5722 wpa_s->manual_scan_use_id = 0;
5723 wpa_s->manual_scan_only_new = 0;
5726 if (os_strncasecmp(params, "TYPE=ONLY", 9) == 0)
5727 wpa_s->scan_res_handler = scan_only_handler;
5729 pos = os_strstr(params, "freq=");
5730 if (pos && set_scan_freqs(wpa_s, pos + 5) < 0) {
5735 pos = os_strstr(params, "passive=");
5737 wpa_s->manual_scan_passive = !!atoi(pos + 8);
5739 pos = os_strstr(params, "use_id=");
5741 wpa_s->manual_scan_use_id = atoi(pos + 7);
5743 pos = os_strstr(params, "only_new=1");
5745 wpa_s->manual_scan_only_new = 1;
5747 os_free(wpa_s->manual_scan_freqs);
5748 wpa_s->manual_scan_freqs = NULL;
5749 if (wpa_s->scan_res_handler == scan_only_handler)
5750 wpa_s->scan_res_handler = NULL;
5753 if (!wpa_s->sched_scanning && !wpa_s->scanning &&
5754 ((wpa_s->wpa_state <= WPA_SCANNING) ||
5755 (wpa_s->wpa_state == WPA_COMPLETED))) {
5756 wpa_s->normal_scans = 0;
5757 wpa_s->scan_req = MANUAL_SCAN_REQ;
5758 wpa_s->after_wps = 0;
5759 wpa_s->known_wps_freq = 0;
5760 wpa_supplicant_req_scan(wpa_s, 0, 0);
5761 if (wpa_s->manual_scan_use_id) {
5762 wpa_s->manual_scan_id++;
5763 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
5764 wpa_s->manual_scan_id);
5765 *reply_len = os_snprintf(reply, reply_size, "%u\n",
5766 wpa_s->manual_scan_id);
5768 } else if (wpa_s->sched_scanning) {
5769 wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to allow requested full scan to proceed");
5770 wpa_supplicant_cancel_sched_scan(wpa_s);
5771 wpa_s->scan_req = MANUAL_SCAN_REQ;
5772 wpa_supplicant_req_scan(wpa_s, 0, 0);
5773 if (wpa_s->manual_scan_use_id) {
5774 wpa_s->manual_scan_id++;
5775 *reply_len = os_snprintf(reply, reply_size, "%u\n",
5776 wpa_s->manual_scan_id);
5777 wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
5778 wpa_s->manual_scan_id);
5781 wpa_printf(MSG_DEBUG, "Ongoing scan action - reject new request");
5782 *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
5787 #ifdef CONFIG_TESTING_OPTIONS
5789 static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant *wpa_s,
5790 unsigned int freq, const u8 *dst,
5791 const u8 *src, const u8 *bssid,
5792 const u8 *data, size_t data_len,
5793 enum offchannel_send_action_result
5796 wpa_msg(wpa_s, MSG_INFO, "MGMT-TX-STATUS freq=%u dst=" MACSTR
5797 " src=" MACSTR " bssid=" MACSTR " result=%s",
5798 freq, MAC2STR(dst), MAC2STR(src), MAC2STR(bssid),
5799 result == OFFCHANNEL_SEND_ACTION_SUCCESS ?
5800 "SUCCESS" : (result == OFFCHANNEL_SEND_ACTION_NO_ACK ?
5801 "NO_ACK" : "FAILED"));
5805 static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant *wpa_s, char *cmd)
5809 u8 *buf, da[ETH_ALEN], bssid[ETH_ALEN];
5811 int freq = 0, no_cck = 0, wait_time = 0;
5813 /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1]
5814 * <action=Action frame payload> */
5816 wpa_printf(MSG_DEBUG, "External MGMT TX: %s", cmd);
5819 used = hwaddr_aton2(pos, da);
5825 used = hwaddr_aton2(pos, bssid);
5830 param = os_strstr(pos, " freq=");
5836 param = os_strstr(pos, " no_cck=");
5839 no_cck = atoi(param);
5842 param = os_strstr(pos, " wait_time=");
5845 wait_time = atoi(param);
5848 param = os_strstr(pos, " action=");
5853 len = os_strlen(param);
5858 buf = os_malloc(len);
5862 if (hexstr2bin(param, buf, len) < 0) {
5867 res = offchannel_send_action(wpa_s, freq, da, wpa_s->own_addr, bssid,
5868 buf, len, wait_time,
5869 wpas_ctrl_iface_mgmt_tx_cb, no_cck);
5875 static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant *wpa_s)
5877 wpa_printf(MSG_DEBUG, "External MGMT TX - done waiting");
5878 offchannel_send_action_done(wpa_s);
5881 #endif /* CONFIG_TESTING_OPTIONS */
5884 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
5885 char *buf, size_t *resp_len)
5888 const int reply_size = 4096;
5891 if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 ||
5892 os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
5893 if (wpa_debug_show_keys)
5894 wpa_dbg(wpa_s, MSG_DEBUG,
5895 "Control interface command '%s'", buf);
5897 wpa_dbg(wpa_s, MSG_DEBUG,
5898 "Control interface command '%s [REMOVED]'",
5899 os_strncmp(buf, WPA_CTRL_RSP,
5900 os_strlen(WPA_CTRL_RSP)) == 0 ?
5901 WPA_CTRL_RSP : "SET_NETWORK");
5902 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ", 16) == 0 ||
5903 os_strncmp(buf, "NFC_REPORT_HANDOVER", 19) == 0 ||
5904 os_strncmp(buf, "NFC_RX_HANDOVER_SEL", 19) == 0) {
5905 wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface",
5906 (const u8 *) buf, os_strlen(buf));
5908 int level = MSG_DEBUG;
5909 if (os_strcmp(buf, "PING") == 0)
5910 level = MSG_EXCESSIVE;
5911 wpa_dbg(wpa_s, level, "Control interface command '%s'", buf);
5914 reply = os_malloc(reply_size);
5915 if (reply == NULL) {
5920 os_memcpy(reply, "OK\n", 3);
5923 if (os_strcmp(buf, "PING") == 0) {
5924 os_memcpy(reply, "PONG\n", 5);
5926 } else if (os_strcmp(buf, "IFNAME") == 0) {
5927 reply_len = os_strlen(wpa_s->ifname);
5928 os_memcpy(reply, wpa_s->ifname, reply_len);
5929 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
5930 if (wpa_debug_reopen_file() < 0)
5932 } else if (os_strncmp(buf, "NOTE ", 5) == 0) {
5933 wpa_printf(MSG_INFO, "NOTE: %s", buf + 5);
5934 } else if (os_strcmp(buf, "MIB") == 0) {
5935 reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size);
5936 if (reply_len >= 0) {
5938 res = eapol_sm_get_mib(wpa_s->eapol, reply + reply_len,
5939 reply_size - reply_len);
5945 } else if (os_strncmp(buf, "STATUS", 6) == 0) {
5946 reply_len = wpa_supplicant_ctrl_iface_status(
5947 wpa_s, buf + 6, reply, reply_size);
5948 } else if (os_strcmp(buf, "PMKSA") == 0) {
5949 reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, reply,
5951 } else if (os_strncmp(buf, "SET ", 4) == 0) {
5952 if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4))
5954 } else if (os_strncmp(buf, "GET ", 4) == 0) {
5955 reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4,
5957 } else if (os_strcmp(buf, "LOGON") == 0) {
5958 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
5959 } else if (os_strcmp(buf, "LOGOFF") == 0) {
5960 eapol_sm_notify_logoff(wpa_s->eapol, TRUE);
5961 } else if (os_strcmp(buf, "REASSOCIATE") == 0) {
5962 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
5965 wpas_request_connection(wpa_s);
5966 } else if (os_strcmp(buf, "RECONNECT") == 0) {
5967 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
5969 else if (wpa_s->disconnected)
5970 wpas_request_connection(wpa_s);
5971 #ifdef IEEE8021X_EAPOL
5972 } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) {
5973 if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8))
5975 #endif /* IEEE8021X_EAPOL */
5976 #ifdef CONFIG_PEERKEY
5977 } else if (os_strncmp(buf, "STKSTART ", 9) == 0) {
5978 if (wpa_supplicant_ctrl_iface_stkstart(wpa_s, buf + 9))
5980 #endif /* CONFIG_PEERKEY */
5981 #ifdef CONFIG_IEEE80211R
5982 } else if (os_strncmp(buf, "FT_DS ", 6) == 0) {
5983 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6))
5985 #endif /* CONFIG_IEEE80211R */
5987 } else if (os_strcmp(buf, "WPS_PBC") == 0) {
5988 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL);
5990 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
5994 } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) {
5995 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8);
5997 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
6001 } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {
6002 reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8,
6005 } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) {
6006 reply_len = wpa_supplicant_ctrl_iface_wps_check_pin(
6007 wpa_s, buf + 14, reply, reply_size);
6008 } else if (os_strcmp(buf, "WPS_CANCEL") == 0) {
6009 if (wpas_wps_cancel(wpa_s))
6011 #ifdef CONFIG_WPS_NFC
6012 } else if (os_strcmp(buf, "WPS_NFC") == 0) {
6013 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, NULL))
6015 } else if (os_strncmp(buf, "WPS_NFC ", 8) == 0) {
6016 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, buf + 8))
6018 } else if (os_strncmp(buf, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
6019 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_config_token(
6020 wpa_s, buf + 21, reply, reply_size);
6021 } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) {
6022 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_token(
6023 wpa_s, buf + 14, reply, reply_size);
6024 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) {
6025 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s,
6028 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
6029 reply_len = wpas_ctrl_nfc_get_handover_req(
6030 wpa_s, buf + 21, reply, reply_size);
6031 } else if (os_strncmp(buf, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
6032 reply_len = wpas_ctrl_nfc_get_handover_sel(
6033 wpa_s, buf + 21, reply, reply_size);
6034 } else if (os_strncmp(buf, "NFC_RX_HANDOVER_SEL ", 20) == 0) {
6035 if (wpas_ctrl_nfc_rx_handover_sel(wpa_s, buf + 20))
6037 } else if (os_strncmp(buf, "NFC_REPORT_HANDOVER ", 20) == 0) {
6038 if (wpas_ctrl_nfc_report_handover(wpa_s, buf + 20))
6040 #endif /* CONFIG_WPS_NFC */
6041 } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) {
6042 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8))
6045 } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) {
6046 reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin(
6047 wpa_s, buf + 11, reply, reply_size);
6048 #endif /* CONFIG_AP */
6049 #ifdef CONFIG_WPS_ER
6050 } else if (os_strcmp(buf, "WPS_ER_START") == 0) {
6051 if (wpas_wps_er_start(wpa_s, NULL))
6053 } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) {
6054 if (wpas_wps_er_start(wpa_s, buf + 13))
6056 } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) {
6057 if (wpas_wps_er_stop(wpa_s))
6059 } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) {
6060 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11))
6062 } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) {
6063 int ret = wpas_wps_er_pbc(wpa_s, buf + 11);
6065 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
6067 } else if (ret == -3) {
6068 os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18);
6070 } else if (ret == -4) {
6071 os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20);
6075 } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) {
6076 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13))
6078 } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) {
6079 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s,
6082 } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) {
6083 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14))
6085 #ifdef CONFIG_WPS_NFC
6086 } else if (os_strncmp(buf, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
6087 reply_len = wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
6088 wpa_s, buf + 24, reply, reply_size);
6089 #endif /* CONFIG_WPS_NFC */
6090 #endif /* CONFIG_WPS_ER */
6091 #endif /* CONFIG_WPS */
6092 #ifdef CONFIG_IBSS_RSN
6093 } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) {
6094 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9))
6096 #endif /* CONFIG_IBSS_RSN */
6098 } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) {
6099 if (p2p_ctrl_find(wpa_s, buf + 9))
6101 } else if (os_strcmp(buf, "P2P_FIND") == 0) {
6102 if (p2p_ctrl_find(wpa_s, ""))
6104 } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) {
6105 wpas_p2p_stop_find(wpa_s);
6106 } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) {
6107 reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply,
6109 } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) {
6110 if (p2p_ctrl_listen(wpa_s, buf + 11))
6112 } else if (os_strcmp(buf, "P2P_LISTEN") == 0) {
6113 if (p2p_ctrl_listen(wpa_s, ""))
6115 } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) {
6116 if (wpas_p2p_group_remove(wpa_s, buf + 17))
6118 } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) {
6119 if (wpas_p2p_group_add(wpa_s, 0, 0, 0, 0))
6121 } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) {
6122 if (p2p_ctrl_group_add(wpa_s, buf + 14))
6124 } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) {
6125 if (p2p_ctrl_prov_disc(wpa_s, buf + 14))
6127 } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) {
6128 reply_len = p2p_get_passphrase(wpa_s, reply, reply_size);
6129 } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) {
6130 reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply,
6132 } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
6133 if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0)
6135 } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) {
6136 if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0)
6138 } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) {
6139 wpas_p2p_sd_service_update(wpa_s);
6140 } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
6141 if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0)
6143 } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) {
6144 wpas_p2p_service_flush(wpa_s);
6145 } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) {
6146 if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0)
6148 } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) {
6149 if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0)
6151 } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) {
6152 if (p2p_ctrl_reject(wpa_s, buf + 11) < 0)
6154 } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) {
6155 if (p2p_ctrl_invite(wpa_s, buf + 11) < 0)
6157 } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) {
6158 reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply,
6160 } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) {
6161 if (p2p_ctrl_set(wpa_s, buf + 8) < 0)
6163 } else if (os_strcmp(buf, "P2P_FLUSH") == 0) {
6164 p2p_ctrl_flush(wpa_s);
6165 } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) {
6166 if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0)
6168 } else if (os_strcmp(buf, "P2P_CANCEL") == 0) {
6169 if (wpas_p2p_cancel(wpa_s))
6171 } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) {
6172 if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0)
6174 } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) {
6175 if (p2p_ctrl_presence_req(wpa_s, "") < 0)
6177 } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) {
6178 if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0)
6180 } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) {
6181 if (p2p_ctrl_ext_listen(wpa_s, "") < 0)
6183 } else if (os_strncmp(buf, "P2P_REMOVE_CLIENT ", 18) == 0) {
6184 if (p2p_ctrl_remove_client(wpa_s, buf + 18) < 0)
6186 #endif /* CONFIG_P2P */
6187 #ifdef CONFIG_WIFI_DISPLAY
6188 } else if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0) {
6189 if (wifi_display_subelem_set(wpa_s->global, buf + 16) < 0)
6191 } else if (os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) {
6192 reply_len = wifi_display_subelem_get(wpa_s->global, buf + 16,
6194 #endif /* CONFIG_WIFI_DISPLAY */
6195 #ifdef CONFIG_INTERWORKING
6196 } else if (os_strcmp(buf, "FETCH_ANQP") == 0) {
6197 if (interworking_fetch_anqp(wpa_s) < 0)
6199 } else if (os_strcmp(buf, "STOP_FETCH_ANQP") == 0) {
6200 interworking_stop_fetch_anqp(wpa_s);
6201 } else if (os_strcmp(buf, "INTERWORKING_SELECT") == 0) {
6202 if (ctrl_interworking_select(wpa_s, NULL) < 0)
6204 } else if (os_strncmp(buf, "INTERWORKING_SELECT ", 20) == 0) {
6205 if (ctrl_interworking_select(wpa_s, buf + 20) < 0)
6207 } else if (os_strncmp(buf, "INTERWORKING_CONNECT ", 21) == 0) {
6208 if (ctrl_interworking_connect(wpa_s, buf + 21) < 0)
6210 } else if (os_strncmp(buf, "ANQP_GET ", 9) == 0) {
6211 if (get_anqp(wpa_s, buf + 9) < 0)
6213 } else if (os_strncmp(buf, "GAS_REQUEST ", 12) == 0) {
6214 if (gas_request(wpa_s, buf + 12) < 0)
6216 } else if (os_strncmp(buf, "GAS_RESPONSE_GET ", 17) == 0) {
6217 reply_len = gas_response_get(wpa_s, buf + 17, reply,
6219 #endif /* CONFIG_INTERWORKING */
6221 } else if (os_strncmp(buf, "HS20_ANQP_GET ", 14) == 0) {
6222 if (get_hs20_anqp(wpa_s, buf + 14) < 0)
6224 } else if (os_strncmp(buf, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
6225 if (hs20_get_nai_home_realm_list(wpa_s, buf + 29) < 0)
6227 } else if (os_strncmp(buf, "HS20_ICON_REQUEST ", 18) == 0) {
6228 if (hs20_icon_request(wpa_s, buf + 18) < 0)
6230 } else if (os_strcmp(buf, "FETCH_OSU") == 0) {
6231 if (hs20_fetch_osu(wpa_s) < 0)
6233 } else if (os_strcmp(buf, "CANCEL_FETCH_OSU") == 0) {
6234 hs20_cancel_fetch_osu(wpa_s);
6235 #endif /* CONFIG_HS20 */
6236 } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0)
6238 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
6239 wpa_s, buf + os_strlen(WPA_CTRL_RSP)))
6243 * Notify response from timeout to allow the control
6244 * interface response to be sent first.
6246 eloop_register_timeout(0, 0, wpas_ctrl_eapol_response,
6249 } else if (os_strcmp(buf, "RECONFIGURE") == 0) {
6250 if (wpa_supplicant_reload_configuration(wpa_s))
6252 } else if (os_strcmp(buf, "TERMINATE") == 0) {
6253 wpa_supplicant_terminate_proc(wpa_s->global);
6254 } else if (os_strncmp(buf, "BSSID ", 6) == 0) {
6255 if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6))
6257 } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) {
6258 reply_len = wpa_supplicant_ctrl_iface_blacklist(
6259 wpa_s, buf + 9, reply, reply_size);
6260 } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) {
6261 reply_len = wpa_supplicant_ctrl_iface_log_level(
6262 wpa_s, buf + 9, reply, reply_size);
6263 } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) {
6264 reply_len = wpa_supplicant_ctrl_iface_list_networks(
6265 wpa_s, reply, reply_size);
6266 } else if (os_strcmp(buf, "DISCONNECT") == 0) {
6268 wpa_s->sme.prev_bssid_set = 0;
6269 #endif /* CONFIG_SME */
6270 wpa_s->reassociate = 0;
6271 wpa_s->disconnected = 1;
6272 wpa_supplicant_cancel_sched_scan(wpa_s);
6273 wpa_supplicant_cancel_scan(wpa_s);
6274 wpa_supplicant_deauthenticate(wpa_s,
6275 WLAN_REASON_DEAUTH_LEAVING);
6276 } else if (os_strcmp(buf, "SCAN") == 0) {
6277 wpas_ctrl_scan(wpa_s, NULL, reply, reply_size, &reply_len);
6278 } else if (os_strncmp(buf, "SCAN ", 5) == 0) {
6279 wpas_ctrl_scan(wpa_s, buf + 5, reply, reply_size, &reply_len);
6280 } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) {
6281 reply_len = wpa_supplicant_ctrl_iface_scan_results(
6282 wpa_s, reply, reply_size);
6283 } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) {
6284 if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15))
6286 } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) {
6287 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15))
6289 } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) {
6290 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16))
6292 } else if (os_strcmp(buf, "ADD_NETWORK") == 0) {
6293 reply_len = wpa_supplicant_ctrl_iface_add_network(
6294 wpa_s, reply, reply_size);
6295 } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) {
6296 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15))
6298 } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
6299 if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12))
6301 } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) {
6302 reply_len = wpa_supplicant_ctrl_iface_get_network(
6303 wpa_s, buf + 12, reply, reply_size);
6304 } else if (os_strcmp(buf, "LIST_CREDS") == 0) {
6305 reply_len = wpa_supplicant_ctrl_iface_list_creds(
6306 wpa_s, reply, reply_size);
6307 } else if (os_strcmp(buf, "ADD_CRED") == 0) {
6308 reply_len = wpa_supplicant_ctrl_iface_add_cred(
6309 wpa_s, reply, reply_size);
6310 } else if (os_strncmp(buf, "REMOVE_CRED ", 12) == 0) {
6311 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s, buf + 12))
6313 } else if (os_strncmp(buf, "SET_CRED ", 9) == 0) {
6314 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s, buf + 9))
6316 #ifndef CONFIG_NO_CONFIG_WRITE
6317 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
6318 if (wpa_supplicant_ctrl_iface_save_config(wpa_s))
6320 #endif /* CONFIG_NO_CONFIG_WRITE */
6321 } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
6322 reply_len = wpa_supplicant_ctrl_iface_get_capability(
6323 wpa_s, buf + 15, reply, reply_size);
6324 } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) {
6325 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8))
6327 } else if (os_strncmp(buf, "SCAN_INTERVAL ", 14) == 0) {
6328 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s, buf + 14))
6330 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
6331 reply_len = wpa_supplicant_global_iface_list(
6332 wpa_s->global, reply, reply_size);
6333 } else if (os_strcmp(buf, "INTERFACES") == 0) {
6334 reply_len = wpa_supplicant_global_iface_interfaces(
6335 wpa_s->global, reply, reply_size);
6336 } else if (os_strncmp(buf, "BSS ", 4) == 0) {
6337 reply_len = wpa_supplicant_ctrl_iface_bss(
6338 wpa_s, buf + 4, reply, reply_size);
6340 } else if (os_strcmp(buf, "STA-FIRST") == 0) {
6341 reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size);
6342 } else if (os_strncmp(buf, "STA ", 4) == 0) {
6343 reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply,
6345 } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) {
6346 reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply,
6348 } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) {
6349 if (ap_ctrl_iface_sta_deauthenticate(wpa_s, buf + 15))
6351 } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) {
6352 if (ap_ctrl_iface_sta_disassociate(wpa_s, buf + 13))
6354 } else if (os_strncmp(buf, "CHAN_SWITCH ", 12) == 0) {
6355 if (ap_ctrl_iface_chanswitch(wpa_s, buf + 12))
6357 #endif /* CONFIG_AP */
6358 } else if (os_strcmp(buf, "SUSPEND") == 0) {
6359 wpas_notify_suspend(wpa_s->global);
6360 } else if (os_strcmp(buf, "RESUME") == 0) {
6361 wpas_notify_resume(wpa_s->global);
6362 } else if (os_strcmp(buf, "DROP_SA") == 0) {
6363 wpa_supplicant_ctrl_iface_drop_sa(wpa_s);
6364 } else if (os_strncmp(buf, "ROAM ", 5) == 0) {
6365 if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5))
6367 } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) {
6368 if (wpa_supplicant_ctrl_iface_sta_autoconnect(wpa_s, buf + 16))
6370 } else if (os_strncmp(buf, "BSS_EXPIRE_AGE ", 15) == 0) {
6371 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s, buf + 15))
6373 } else if (os_strncmp(buf, "BSS_EXPIRE_COUNT ", 17) == 0) {
6374 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s,
6377 } else if (os_strncmp(buf, "BSS_FLUSH ", 10) == 0) {
6378 if (wpa_supplicant_ctrl_iface_bss_flush(wpa_s, buf + 10))
6381 } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) {
6382 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14))
6384 } else if (os_strncmp(buf, "TDLS_SETUP ", 11) == 0) {
6385 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s, buf + 11))
6387 } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) {
6388 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14))
6390 #endif /* CONFIG_TDLS */
6391 } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) {
6392 reply_len = wpa_supplicant_signal_poll(wpa_s, reply,
6394 } else if (os_strncmp(buf, "PKTCNT_POLL", 11) == 0) {
6395 reply_len = wpa_supplicant_pktcnt_poll(wpa_s, reply,
6397 #ifdef CONFIG_AUTOSCAN
6398 } else if (os_strncmp(buf, "AUTOSCAN ", 9) == 0) {
6399 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s, buf + 9))
6401 #endif /* CONFIG_AUTOSCAN */
6403 } else if (os_strncmp(buf, "DRIVER ", 7) == 0) {
6404 reply_len = wpa_supplicant_driver_cmd(wpa_s, buf + 7, reply,
6406 #endif /* ANDROID */
6407 } else if (os_strncmp(buf, "VENDOR ", 7) == 0) {
6408 reply_len = wpa_supplicant_vendor_cmd(wpa_s, buf + 7, reply,
6410 } else if (os_strcmp(buf, "REAUTHENTICATE") == 0) {
6411 pmksa_cache_clear_current(wpa_s->wpa);
6412 eapol_sm_request_reauth(wpa_s->eapol);
6414 } else if (os_strncmp(buf, "WNM_SLEEP ", 10) == 0) {
6415 if (wpas_ctrl_iface_wnm_sleep(wpa_s, buf + 10))
6417 } else if (os_strncmp(buf, "WNM_BSS_QUERY ", 10) == 0) {
6418 if (wpas_ctrl_iface_wnm_bss_query(wpa_s, buf + 10))
6420 #endif /* CONFIG_WNM */
6421 } else if (os_strcmp(buf, "FLUSH") == 0) {
6422 wpa_supplicant_ctrl_iface_flush(wpa_s);
6423 } else if (os_strncmp(buf, "RADIO_WORK ", 11) == 0) {
6424 reply_len = wpas_ctrl_radio_work(wpa_s, buf + 11, reply,
6426 #ifdef CONFIG_TESTING_OPTIONS
6427 } else if (os_strncmp(buf, "MGMT_TX ", 8) == 0) {
6428 if (wpas_ctrl_iface_mgmt_tx(wpa_s, buf + 8) < 0)
6430 } else if (os_strcmp(buf, "MGMT_TX_DONE") == 0) {
6431 wpas_ctrl_iface_mgmt_tx_done(wpa_s);
6432 #endif /* CONFIG_TESTING_OPTIONS */
6434 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
6438 if (reply_len < 0) {
6439 os_memcpy(reply, "FAIL\n", 5);
6443 *resp_len = reply_len;
6448 static int wpa_supplicant_global_iface_add(struct wpa_global *global,
6451 struct wpa_interface iface;
6455 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
6456 * TAB<bridge_ifname>
6458 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd);
6460 os_memset(&iface, 0, sizeof(iface));
6463 iface.ifname = pos = cmd;
6464 pos = os_strchr(pos, '\t');
6467 if (iface.ifname[0] == '\0')
6472 iface.confname = pos;
6473 pos = os_strchr(pos, '\t');
6476 if (iface.confname[0] == '\0')
6477 iface.confname = NULL;
6482 pos = os_strchr(pos, '\t');
6485 if (iface.driver[0] == '\0')
6486 iface.driver = NULL;
6490 iface.ctrl_interface = pos;
6491 pos = os_strchr(pos, '\t');
6494 if (iface.ctrl_interface[0] == '\0')
6495 iface.ctrl_interface = NULL;
6499 iface.driver_param = pos;
6500 pos = os_strchr(pos, '\t');
6503 if (iface.driver_param[0] == '\0')
6504 iface.driver_param = NULL;
6508 iface.bridge_ifname = pos;
6509 pos = os_strchr(pos, '\t');
6512 if (iface.bridge_ifname[0] == '\0')
6513 iface.bridge_ifname = NULL;
6518 if (wpa_supplicant_get_iface(global, iface.ifname))
6521 return wpa_supplicant_add_iface(global, &iface) ? 0 : -1;
6525 static int wpa_supplicant_global_iface_remove(struct wpa_global *global,
6528 struct wpa_supplicant *wpa_s;
6530 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd);
6532 wpa_s = wpa_supplicant_get_iface(global, cmd);
6535 return wpa_supplicant_remove_iface(global, wpa_s, 0);
6539 static void wpa_free_iface_info(struct wpa_interface_info *iface)
6541 struct wpa_interface_info *prev;
6545 iface = iface->next;
6547 os_free(prev->ifname);
6548 os_free(prev->desc);
6554 static int wpa_supplicant_global_iface_list(struct wpa_global *global,
6558 struct wpa_interface_info *iface = NULL, *last = NULL, *tmp;
6561 for (i = 0; wpa_drivers[i]; i++) {
6562 struct wpa_driver_ops *drv = wpa_drivers[i];
6563 if (drv->get_interfaces == NULL)
6565 tmp = drv->get_interfaces(global->drv_priv[i]);
6579 for (tmp = iface; tmp; tmp = tmp->next) {
6580 res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n",
6581 tmp->drv_name, tmp->ifname,
6582 tmp->desc ? tmp->desc : "");
6583 if (res < 0 || res >= end - pos) {
6590 wpa_free_iface_info(iface);
6596 static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
6601 struct wpa_supplicant *wpa_s;
6603 wpa_s = global->ifaces;
6608 res = os_snprintf(pos, end - pos, "%s\n", wpa_s->ifname);
6609 if (res < 0 || res >= end - pos) {
6614 wpa_s = wpa_s->next;
6620 static char * wpas_global_ctrl_iface_ifname(struct wpa_global *global,
6622 char *cmd, size_t *resp_len)
6624 struct wpa_supplicant *wpa_s;
6626 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
6627 if (os_strcmp(ifname, wpa_s->ifname) == 0)
6631 if (wpa_s == NULL) {
6632 char *resp = os_strdup("FAIL-NO-IFNAME-MATCH\n");
6634 *resp_len = os_strlen(resp);
6640 return wpa_supplicant_ctrl_iface_process(wpa_s, cmd, resp_len);
6644 static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global *global,
6645 char *buf, size_t *resp_len)
6648 static const char * cmd[] = {
6655 "P2P_GET_PASSPHRASE",
6656 "P2P_SERVICE_UPDATE",
6657 "P2P_SERVICE_FLUSH",
6664 static const char * prefix[] = {
6667 #endif /* ANDROID */
6674 "P2P_GROUP_REMOVE ",
6677 "P2P_SERV_DISC_REQ ",
6678 "P2P_SERV_DISC_CANCEL_REQ ",
6679 "P2P_SERV_DISC_RESP ",
6680 "P2P_SERV_DISC_EXTERNAL ",
6688 "P2P_PRESENCE_REQ ",
6690 "P2P_REMOVE_CLIENT ",
6696 if (global->p2p_init_wpa_s == NULL)
6699 for (i = 0; !found && cmd[i]; i++) {
6700 if (os_strcmp(buf, cmd[i]) == 0)
6704 for (i = 0; !found && prefix[i]; i++) {
6705 if (os_strncmp(buf, prefix[i], os_strlen(prefix[i])) == 0)
6710 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
6712 #endif /* CONFIG_P2P */
6717 static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global *global,
6718 char *buf, size_t *resp_len)
6720 #ifdef CONFIG_WIFI_DISPLAY
6721 if (global->p2p_init_wpa_s == NULL)
6723 if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0 ||
6724 os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0)
6725 return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
6727 #endif /* CONFIG_WIFI_DISPLAY */
6732 static char * wpas_global_ctrl_iface_redir(struct wpa_global *global,
6733 char *buf, size_t *resp_len)
6737 ret = wpas_global_ctrl_iface_redir_p2p(global, buf, resp_len);
6741 ret = wpas_global_ctrl_iface_redir_wfd(global, buf, resp_len);
6749 static int wpas_global_ctrl_iface_set(struct wpa_global *global, char *cmd)
6753 value = os_strchr(cmd, ' ');
6758 wpa_printf(MSG_DEBUG, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd, value);
6760 #ifdef CONFIG_WIFI_DISPLAY
6761 if (os_strcasecmp(cmd, "wifi_display") == 0) {
6762 wifi_display_enable(global, !!atoi(value));
6765 #endif /* CONFIG_WIFI_DISPLAY */
6771 #ifndef CONFIG_NO_CONFIG_WRITE
6772 static int wpas_global_ctrl_iface_save_config(struct wpa_global *global)
6775 struct wpa_supplicant *wpa_s;
6777 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
6778 if (!wpa_s->conf->update_config) {
6779 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
6783 if (wpa_config_write(wpa_s->confname, wpa_s->conf)) {
6784 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
6787 wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
6793 #endif /* CONFIG_NO_CONFIG_WRITE */
6796 static int wpas_global_ctrl_iface_status(struct wpa_global *global,
6797 char *buf, size_t buflen)
6801 struct wpa_supplicant *wpa_s;
6807 if (global->p2p && !global->p2p_disabled) {
6808 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
6811 MAC2STR(global->p2p_dev_addr),
6812 p2p_get_state_txt(global->p2p));
6813 if (ret < 0 || ret >= end - pos)
6816 } else if (global->p2p) {
6817 ret = os_snprintf(pos, end - pos, "p2p_state=DISABLED\n");
6818 if (ret < 0 || ret >= end - pos)
6822 #endif /* CONFIG_P2P */
6824 #ifdef CONFIG_WIFI_DISPLAY
6825 ret = os_snprintf(pos, end - pos, "wifi_display=%d\n",
6826 !!global->wifi_display);
6827 if (ret < 0 || ret >= end - pos)
6830 #endif /* CONFIG_WIFI_DISPLAY */
6832 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
6833 ret = os_snprintf(pos, end - pos, "ifname=%s\n"
6834 "address=" MACSTR "\n",
6835 wpa_s->ifname, MAC2STR(wpa_s->own_addr));
6836 if (ret < 0 || ret >= end - pos)
6845 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
6846 char *buf, size_t *resp_len)
6849 const int reply_size = 2048;
6851 int level = MSG_DEBUG;
6853 if (os_strncmp(buf, "IFNAME=", 7) == 0) {
6854 char *pos = os_strchr(buf + 7, ' ');
6857 return wpas_global_ctrl_iface_ifname(global,
6863 reply = wpas_global_ctrl_iface_redir(global, buf, resp_len);
6867 if (os_strcmp(buf, "PING") == 0)
6868 level = MSG_EXCESSIVE;
6869 wpa_hexdump_ascii(level, "RX global ctrl_iface",
6870 (const u8 *) buf, os_strlen(buf));
6872 reply = os_malloc(reply_size);
6873 if (reply == NULL) {
6878 os_memcpy(reply, "OK\n", 3);
6881 if (os_strcmp(buf, "PING") == 0) {
6882 os_memcpy(reply, "PONG\n", 5);
6884 } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) {
6885 if (wpa_supplicant_global_iface_add(global, buf + 14))
6887 } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) {
6888 if (wpa_supplicant_global_iface_remove(global, buf + 17))
6890 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
6891 reply_len = wpa_supplicant_global_iface_list(
6892 global, reply, reply_size);
6893 } else if (os_strcmp(buf, "INTERFACES") == 0) {
6894 reply_len = wpa_supplicant_global_iface_interfaces(
6895 global, reply, reply_size);
6896 } else if (os_strcmp(buf, "TERMINATE") == 0) {
6897 wpa_supplicant_terminate_proc(global);
6898 } else if (os_strcmp(buf, "SUSPEND") == 0) {
6899 wpas_notify_suspend(global);
6900 } else if (os_strcmp(buf, "RESUME") == 0) {
6901 wpas_notify_resume(global);
6902 } else if (os_strncmp(buf, "SET ", 4) == 0) {
6903 if (wpas_global_ctrl_iface_set(global, buf + 4))
6905 #ifndef CONFIG_NO_CONFIG_WRITE
6906 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
6907 if (wpas_global_ctrl_iface_save_config(global))
6909 #endif /* CONFIG_NO_CONFIG_WRITE */
6910 } else if (os_strcmp(buf, "STATUS") == 0) {
6911 reply_len = wpas_global_ctrl_iface_status(global, reply,
6913 #ifdef CONFIG_MODULE_TESTS
6914 } else if (os_strcmp(buf, "MODULE_TESTS") == 0) {
6915 int wpas_module_tests(void);
6916 if (wpas_module_tests() < 0)
6918 #endif /* CONFIG_MODULE_TESTS */
6920 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
6924 if (reply_len < 0) {
6925 os_memcpy(reply, "FAIL\n", 5);
6929 *resp_len = reply_len;