2 * WPA Supplicant / Control interface (shared code for all backends)
3 * Copyright (c) 2004-2012, 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 "common/version.h"
14 #include "common/ieee802_11_defs.h"
15 #include "common/ieee802_11_common.h"
16 #include "common/wpa_ctrl.h"
17 #include "eap_peer/eap.h"
18 #include "eapol_supp/eapol_supp_sm.h"
19 #include "rsn_supp/wpa.h"
20 #include "rsn_supp/preauth.h"
21 #include "rsn_supp/pmksa_cache.h"
22 #include "l2_packet/l2_packet.h"
25 #include "wpa_supplicant_i.h"
27 #include "wps_supplicant.h"
30 #include "p2p_supplicant.h"
32 #include "hs20_supplicant.h"
33 #include "wifi_display.h"
37 #include "ctrl_iface.h"
38 #include "interworking.h"
39 #include "blacklist.h"
40 #include "wpas_glue.h"
43 extern struct wpa_driver_ops *wpa_drivers[];
45 static int wpa_supplicant_global_iface_list(struct wpa_global *global,
47 static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
51 static int pno_start(struct wpa_supplicant *wpa_s)
55 struct wpa_ssid *ssid;
56 struct wpa_driver_scan_params params;
61 os_memset(¶ms, 0, sizeof(params));
64 ssid = wpa_s->conf->ssid;
66 if (!wpas_network_disabled(wpa_s, ssid))
70 if (num_ssid > WPAS_MAX_SCAN_SSIDS) {
71 wpa_printf(MSG_DEBUG, "PNO: Use only the first %u SSIDs from "
72 "%u", WPAS_MAX_SCAN_SSIDS, (unsigned int) num_ssid);
73 num_ssid = WPAS_MAX_SCAN_SSIDS;
77 wpa_printf(MSG_DEBUG, "PNO: No configured SSIDs");
81 params.filter_ssids = os_malloc(sizeof(struct wpa_driver_scan_filter) *
83 if (params.filter_ssids == NULL)
86 ssid = wpa_s->conf->ssid;
88 if (!wpas_network_disabled(wpa_s, ssid)) {
89 params.ssids[i].ssid = ssid->ssid;
90 params.ssids[i].ssid_len = ssid->ssid_len;
92 os_memcpy(params.filter_ssids[i].ssid, ssid->ssid,
94 params.filter_ssids[i].ssid_len = ssid->ssid_len;
95 params.num_filter_ssids++;
103 if (wpa_s->conf->filter_rssi)
104 params.filter_rssi = wpa_s->conf->filter_rssi;
106 ret = wpa_drv_sched_scan(wpa_s, ¶ms, 10 * 1000);
107 os_free(params.filter_ssids);
114 static int pno_stop(struct wpa_supplicant *wpa_s)
118 return wpa_drv_stop_sched_scan(wpa_s);
124 static int set_bssid_filter(struct wpa_supplicant *wpa_s, char *val)
127 u8 addr[ETH_ALEN], *filter = NULL, *n;
134 if (hwaddr_aton(pos, addr)) {
138 n = os_realloc_array(filter, count + 1, ETH_ALEN);
144 os_memcpy(filter + count * ETH_ALEN, addr, ETH_ALEN);
147 pos = os_strchr(pos, ' ');
152 wpa_hexdump(MSG_DEBUG, "bssid_filter", filter, count * ETH_ALEN);
153 os_free(wpa_s->bssid_filter);
154 wpa_s->bssid_filter = filter;
155 wpa_s->bssid_filter_count = count;
161 static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s,
167 value = os_strchr(cmd, ' ');
172 wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value);
173 if (os_strcasecmp(cmd, "EAPOL::heldPeriod") == 0) {
174 eapol_sm_configure(wpa_s->eapol,
175 atoi(value), -1, -1, -1);
176 } else if (os_strcasecmp(cmd, "EAPOL::authPeriod") == 0) {
177 eapol_sm_configure(wpa_s->eapol,
178 -1, atoi(value), -1, -1);
179 } else if (os_strcasecmp(cmd, "EAPOL::startPeriod") == 0) {
180 eapol_sm_configure(wpa_s->eapol,
181 -1, -1, atoi(value), -1);
182 } else if (os_strcasecmp(cmd, "EAPOL::maxStart") == 0) {
183 eapol_sm_configure(wpa_s->eapol,
184 -1, -1, -1, atoi(value));
185 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKLifetime") == 0) {
186 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME,
189 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKReauthThreshold") ==
191 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD,
194 } else if (os_strcasecmp(cmd, "dot11RSNAConfigSATimeout") == 0) {
195 if (wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, atoi(value)))
197 } else if (os_strcasecmp(cmd, "wps_fragment_size") == 0) {
198 wpa_s->wps_fragment_size = atoi(value);
199 #ifdef CONFIG_WPS_TESTING
200 } else if (os_strcasecmp(cmd, "wps_version_number") == 0) {
202 val = strtol(value, NULL, 0);
203 if (val < 0 || val > 0xff) {
205 wpa_printf(MSG_DEBUG, "WPS: Invalid "
206 "wps_version_number %ld", val);
208 wps_version_number = val;
209 wpa_printf(MSG_DEBUG, "WPS: Testing - force WPS "
211 (wps_version_number & 0xf0) >> 4,
212 wps_version_number & 0x0f);
214 } else if (os_strcasecmp(cmd, "wps_testing_dummy_cred") == 0) {
215 wps_testing_dummy_cred = atoi(value);
216 wpa_printf(MSG_DEBUG, "WPS: Testing - dummy_cred=%d",
217 wps_testing_dummy_cred);
218 #endif /* CONFIG_WPS_TESTING */
219 } else if (os_strcasecmp(cmd, "ampdu") == 0) {
220 if (wpa_drv_ampdu(wpa_s, atoi(value)) < 0)
222 #ifdef CONFIG_TDLS_TESTING
223 } else if (os_strcasecmp(cmd, "tdls_testing") == 0) {
224 extern unsigned int tdls_testing;
225 tdls_testing = strtol(value, NULL, 0);
226 wpa_printf(MSG_DEBUG, "TDLS: tdls_testing=0x%x", tdls_testing);
227 #endif /* CONFIG_TDLS_TESTING */
229 } else if (os_strcasecmp(cmd, "tdls_disabled") == 0) {
230 int disabled = atoi(value);
231 wpa_printf(MSG_DEBUG, "TDLS: tdls_disabled=%d", disabled);
233 if (wpa_drv_tdls_oper(wpa_s, TDLS_DISABLE, NULL) < 0)
235 } else if (wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL) < 0)
237 wpa_tdls_enable(wpa_s->wpa, !disabled);
238 #endif /* CONFIG_TDLS */
239 } else if (os_strcasecmp(cmd, "pno") == 0) {
241 ret = pno_start(wpa_s);
243 ret = pno_stop(wpa_s);
244 } else if (os_strcasecmp(cmd, "radio_disabled") == 0) {
245 int disabled = atoi(value);
246 if (wpa_drv_radio_disable(wpa_s, disabled) < 0)
249 wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
250 } else if (os_strcasecmp(cmd, "uapsd") == 0) {
251 if (os_strcmp(value, "disable") == 0)
252 wpa_s->set_sta_uapsd = 0;
256 /* format: BE,BK,VI,VO;max SP Length */
258 pos = os_strchr(value, ',');
263 pos = os_strchr(pos, ',');
268 pos = os_strchr(pos, ',');
273 /* ignore max SP Length for now */
275 wpa_s->set_sta_uapsd = 1;
276 wpa_s->sta_uapsd = 0;
278 wpa_s->sta_uapsd |= BIT(0);
280 wpa_s->sta_uapsd |= BIT(1);
282 wpa_s->sta_uapsd |= BIT(2);
284 wpa_s->sta_uapsd |= BIT(3);
286 } else if (os_strcasecmp(cmd, "ps") == 0) {
287 ret = wpa_drv_set_p2p_powersave(wpa_s, atoi(value), -1, -1);
288 #ifdef CONFIG_WIFI_DISPLAY
289 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
290 wifi_display_enable(wpa_s->global, !!atoi(value));
291 #endif /* CONFIG_WIFI_DISPLAY */
292 } else if (os_strcasecmp(cmd, "bssid_filter") == 0) {
293 ret = set_bssid_filter(wpa_s, value);
296 ret = wpa_config_process_global(wpa_s->conf, cmd, -1);
298 wpa_supplicant_update_config(wpa_s);
305 static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s,
306 char *cmd, char *buf, size_t buflen)
310 wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd);
312 if (os_strcmp(cmd, "version") == 0) {
313 res = os_snprintf(buf, buflen, "%s", VERSION_STR);
314 } else if (os_strcasecmp(cmd, "country") == 0) {
315 if (wpa_s->conf->country[0] && wpa_s->conf->country[1])
316 res = os_snprintf(buf, buflen, "%c%c",
317 wpa_s->conf->country[0],
318 wpa_s->conf->country[1]);
319 #ifdef CONFIG_WIFI_DISPLAY
320 } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
321 res = os_snprintf(buf, buflen, "%d",
322 wpa_s->global->wifi_display);
323 if (res < 0 || (unsigned int) res >= buflen)
326 #endif /* CONFIG_WIFI_DISPLAY */
329 if (res < 0 || (unsigned int) res >= buflen)
335 #ifdef IEEE8021X_EAPOL
336 static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s,
340 struct wpa_ssid *ssid = wpa_s->current_ssid;
342 if (hwaddr_aton(addr, bssid)) {
343 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address "
348 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid));
349 rsn_preauth_deinit(wpa_s->wpa);
350 if (rsn_preauth_init(wpa_s->wpa, bssid, ssid ? &ssid->eap : NULL))
355 #endif /* IEEE8021X_EAPOL */
358 #ifdef CONFIG_PEERKEY
359 /* MLME-STKSTART.request(peer) */
360 static int wpa_supplicant_ctrl_iface_stkstart(
361 struct wpa_supplicant *wpa_s, char *addr)
365 if (hwaddr_aton(addr, peer)) {
366 wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART: invalid "
367 "address '%s'", addr);
371 wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART " MACSTR,
374 return wpa_sm_stkstart(wpa_s->wpa, peer);
376 #endif /* CONFIG_PEERKEY */
381 static int wpa_supplicant_ctrl_iface_tdls_discover(
382 struct wpa_supplicant *wpa_s, char *addr)
387 if (hwaddr_aton(addr, peer)) {
388 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER: invalid "
389 "address '%s'", addr);
393 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER " MACSTR,
396 if (wpa_tdls_is_external_setup(wpa_s->wpa))
397 ret = wpa_tdls_send_discovery_request(wpa_s->wpa, peer);
399 ret = wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer);
405 static int wpa_supplicant_ctrl_iface_tdls_setup(
406 struct wpa_supplicant *wpa_s, char *addr)
411 if (hwaddr_aton(addr, peer)) {
412 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP: invalid "
413 "address '%s'", addr);
417 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP " MACSTR,
420 ret = wpa_tdls_reneg(wpa_s->wpa, peer);
422 if (wpa_tdls_is_external_setup(wpa_s->wpa))
423 ret = wpa_tdls_start(wpa_s->wpa, peer);
425 ret = wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
432 static int wpa_supplicant_ctrl_iface_tdls_teardown(
433 struct wpa_supplicant *wpa_s, char *addr)
437 if (hwaddr_aton(addr, peer)) {
438 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN: invalid "
439 "address '%s'", addr);
443 wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN " MACSTR,
446 return wpa_tdls_teardown_link(wpa_s->wpa, peer,
447 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED);
450 #endif /* CONFIG_TDLS */
453 #ifdef CONFIG_IEEE80211R
454 static int wpa_supplicant_ctrl_iface_ft_ds(
455 struct wpa_supplicant *wpa_s, char *addr)
457 u8 target_ap[ETH_ALEN];
461 if (hwaddr_aton(addr, target_ap)) {
462 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid "
463 "address '%s'", addr);
467 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap));
469 bss = wpa_bss_get_bssid(wpa_s, target_ap);
471 mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN);
475 return wpa_ft_start_over_ds(wpa_s->wpa, target_ap, mdie);
477 #endif /* CONFIG_IEEE80211R */
481 static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s,
484 u8 bssid[ETH_ALEN], *_bssid = bssid;
486 u8 p2p_dev_addr[ETH_ALEN];
487 #endif /* CONFIG_P2P */
489 u8 *_p2p_dev_addr = NULL;
490 #endif /* CONFIG_AP */
492 if (cmd == NULL || os_strcmp(cmd, "any") == 0) {
495 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
496 if (hwaddr_aton(cmd + 13, p2p_dev_addr)) {
497 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid "
498 "P2P Device Address '%s'",
502 _p2p_dev_addr = p2p_dev_addr;
503 #endif /* CONFIG_P2P */
504 } else if (hwaddr_aton(cmd, bssid)) {
505 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
512 return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid, _p2p_dev_addr);
513 #endif /* CONFIG_AP */
515 return wpas_wps_start_pbc(wpa_s, _bssid, 0);
519 static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s,
520 char *cmd, char *buf,
523 u8 bssid[ETH_ALEN], *_bssid = bssid;
527 pin = os_strchr(cmd, ' ');
531 if (os_strcmp(cmd, "any") == 0)
533 else if (os_strcmp(cmd, "get") == 0) {
534 ret = wps_generate_pin();
536 } else if (hwaddr_aton(cmd, bssid)) {
537 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
544 return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin,
546 #endif /* CONFIG_AP */
549 ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0,
553 ret = os_snprintf(buf, buflen, "%s", pin);
554 if (ret < 0 || (size_t) ret >= buflen)
559 ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0, DEV_PW_DEFAULT);
564 /* Return the generated PIN */
565 ret = os_snprintf(buf, buflen, "%08d", ret);
566 if (ret < 0 || (size_t) ret >= buflen)
572 static int wpa_supplicant_ctrl_iface_wps_check_pin(
573 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
580 wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN",
581 (u8 *) cmd, os_strlen(cmd));
582 for (pos = cmd, len = 0; *pos != '\0'; pos++) {
583 if (*pos < '0' || *pos > '9')
587 wpa_printf(MSG_DEBUG, "WPS: Too long PIN");
591 if (len != 4 && len != 8) {
592 wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len);
598 unsigned int pin_val;
600 if (!wps_pin_valid(pin_val)) {
601 wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit");
602 ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n");
603 if (ret < 0 || (size_t) ret >= buflen)
609 ret = os_snprintf(buf, buflen, "%s", pin);
610 if (ret < 0 || (size_t) ret >= buflen)
617 #ifdef CONFIG_WPS_OOB
618 static int wpa_supplicant_ctrl_iface_wps_oob(struct wpa_supplicant *wpa_s,
621 char *path, *method, *name;
623 path = os_strchr(cmd, ' ');
628 method = os_strchr(path, ' ');
633 name = os_strchr(method, ' ');
637 return wpas_wps_start_oob(wpa_s, cmd, path, method, name);
639 #endif /* CONFIG_WPS_OOB */
642 #ifdef CONFIG_WPS_NFC
644 static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant *wpa_s,
647 u8 bssid[ETH_ALEN], *_bssid = bssid;
649 if (cmd == NULL || cmd[0] == '\0')
651 else if (hwaddr_aton(cmd, bssid))
654 return wpas_wps_start_nfc(wpa_s, _bssid);
658 static int wpa_supplicant_ctrl_iface_wps_nfc_token(
659 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
665 if (os_strcmp(cmd, "WPS") == 0)
667 else if (os_strcmp(cmd, "NDEF") == 0)
672 buf = wpas_wps_nfc_token(wpa_s, ndef);
676 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
687 static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
688 struct wpa_supplicant *wpa_s, char *pos)
694 len = os_strlen(pos);
699 buf = wpabuf_alloc(len);
702 if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
707 ret = wpas_wps_nfc_tag_read(wpa_s, buf);
713 #endif /* CONFIG_WPS_NFC */
716 static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s,
725 struct wps_new_ap_settings ap;
727 pin = os_strchr(cmd, ' ');
732 if (hwaddr_aton(cmd, bssid)) {
733 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
738 new_ssid = os_strchr(pin, ' ');
739 if (new_ssid == NULL)
740 return wpas_wps_start_reg(wpa_s, bssid, pin, NULL);
743 new_auth = os_strchr(new_ssid, ' ');
744 if (new_auth == NULL)
748 new_encr = os_strchr(new_auth, ' ');
749 if (new_encr == NULL)
753 new_key = os_strchr(new_encr, ' ');
758 os_memset(&ap, 0, sizeof(ap));
759 ap.ssid_hex = new_ssid;
762 ap.key_hex = new_key;
763 return wpas_wps_start_reg(wpa_s, bssid, pin, &ap);
768 static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant *wpa_s,
769 char *cmd, char *buf,
776 if (!wpa_s->ap_iface)
779 pos = os_strchr(cmd, ' ');
783 if (os_strcmp(cmd, "disable") == 0) {
784 wpas_wps_ap_pin_disable(wpa_s);
785 return os_snprintf(buf, buflen, "OK\n");
788 if (os_strcmp(cmd, "random") == 0) {
791 pin_txt = wpas_wps_ap_pin_random(wpa_s, timeout);
794 return os_snprintf(buf, buflen, "%s", pin_txt);
797 if (os_strcmp(cmd, "get") == 0) {
798 pin_txt = wpas_wps_ap_pin_get(wpa_s);
801 return os_snprintf(buf, buflen, "%s", pin_txt);
804 if (os_strcmp(cmd, "set") == 0) {
809 pos = os_strchr(pos, ' ');
814 if (os_strlen(pin) > buflen)
816 if (wpas_wps_ap_pin_set(wpa_s, pin, timeout) < 0)
818 return os_snprintf(buf, buflen, "%s", pin);
823 #endif /* CONFIG_AP */
827 static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant *wpa_s,
830 char *uuid = cmd, *pin, *pos;
831 u8 addr_buf[ETH_ALEN], *addr = NULL;
832 pin = os_strchr(uuid, ' ');
836 pos = os_strchr(pin, ' ');
839 if (hwaddr_aton(pos, addr_buf) == 0)
842 return wpas_wps_er_add_pin(wpa_s, addr, uuid, pin);
846 static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant *wpa_s,
849 char *uuid = cmd, *pin;
850 pin = os_strchr(uuid, ' ');
854 return wpas_wps_er_learn(wpa_s, uuid, pin);
858 static int wpa_supplicant_ctrl_iface_wps_er_set_config(
859 struct wpa_supplicant *wpa_s, char *cmd)
861 char *uuid = cmd, *id;
862 id = os_strchr(uuid, ' ');
866 return wpas_wps_er_set_config(wpa_s, uuid, atoi(id));
870 static int wpa_supplicant_ctrl_iface_wps_er_config(
871 struct wpa_supplicant *wpa_s, char *cmd)
878 struct wps_new_ap_settings ap;
880 pin = os_strchr(cmd, ' ');
885 new_ssid = os_strchr(pin, ' ');
886 if (new_ssid == NULL)
890 new_auth = os_strchr(new_ssid, ' ');
891 if (new_auth == NULL)
895 new_encr = os_strchr(new_auth, ' ');
896 if (new_encr == NULL)
900 new_key = os_strchr(new_encr, ' ');
905 os_memset(&ap, 0, sizeof(ap));
906 ap.ssid_hex = new_ssid;
909 ap.key_hex = new_key;
910 return wpas_wps_er_config(wpa_s, cmd, pin, &ap);
914 #ifdef CONFIG_WPS_NFC
915 static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
916 struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
923 uuid = os_strchr(cmd, ' ');
928 if (os_strcmp(cmd, "WPS") == 0)
930 else if (os_strcmp(cmd, "NDEF") == 0)
935 buf = wpas_wps_er_nfc_config_token(wpa_s, ndef, uuid);
939 res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
948 #endif /* CONFIG_WPS_NFC */
949 #endif /* CONFIG_WPS_ER */
951 #endif /* CONFIG_WPS */
954 #ifdef CONFIG_IBSS_RSN
955 static int wpa_supplicant_ctrl_iface_ibss_rsn(
956 struct wpa_supplicant *wpa_s, char *addr)
960 if (hwaddr_aton(addr, peer)) {
961 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN: invalid "
962 "address '%s'", addr);
966 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN " MACSTR,
969 return ibss_rsn_start(wpa_s->ibss_rsn, peer);
971 #endif /* CONFIG_IBSS_RSN */
974 static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s,
977 #ifdef IEEE8021X_EAPOL
980 struct wpa_ssid *ssid;
982 pos = os_strchr(rsp, '-');
987 pos = os_strchr(pos, ':');
992 wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id);
993 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
994 (u8 *) pos, os_strlen(pos));
996 ssid = wpa_config_get_network(wpa_s->conf, id);
998 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
1003 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s, ssid, rsp,
1005 #else /* IEEE8021X_EAPOL */
1006 wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included");
1008 #endif /* IEEE8021X_EAPOL */
1012 static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
1014 char *buf, size_t buflen)
1016 char *pos, *end, tmp[30];
1017 int res, verbose, wps, ret;
1019 verbose = os_strcmp(params, "-VERBOSE") == 0;
1020 wps = os_strcmp(params, "-WPS") == 0;
1023 if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
1024 struct wpa_ssid *ssid = wpa_s->current_ssid;
1025 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
1026 MAC2STR(wpa_s->bssid));
1027 if (ret < 0 || ret >= end - pos)
1031 u8 *_ssid = ssid->ssid;
1032 size_t ssid_len = ssid->ssid_len;
1033 u8 ssid_buf[MAX_SSID_LEN];
1034 if (ssid_len == 0) {
1035 int _res = wpa_drv_get_ssid(wpa_s, ssid_buf);
1042 ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n",
1043 wpa_ssid_txt(_ssid, ssid_len),
1045 if (ret < 0 || ret >= end - pos)
1049 if (wps && ssid->passphrase &&
1050 wpa_key_mgmt_wpa_psk(ssid->key_mgmt) &&
1051 (ssid->mode == WPAS_MODE_AP ||
1052 ssid->mode == WPAS_MODE_P2P_GO)) {
1053 ret = os_snprintf(pos, end - pos,
1056 if (ret < 0 || ret >= end - pos)
1061 ret = os_snprintf(pos, end - pos,
1064 if (ret < 0 || ret >= end - pos)
1069 switch (ssid->mode) {
1070 case WPAS_MODE_INFRA:
1071 ret = os_snprintf(pos, end - pos,
1074 case WPAS_MODE_IBSS:
1075 ret = os_snprintf(pos, end - pos,
1079 ret = os_snprintf(pos, end - pos,
1082 case WPAS_MODE_P2P_GO:
1083 ret = os_snprintf(pos, end - pos,
1086 case WPAS_MODE_P2P_GROUP_FORMATION:
1087 ret = os_snprintf(pos, end - pos,
1088 "mode=P2P GO - group "
1095 if (ret < 0 || ret >= end - pos)
1101 if (wpa_s->ap_iface) {
1102 pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos,
1106 #endif /* CONFIG_AP */
1107 pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose);
1109 ret = os_snprintf(pos, end - pos, "wpa_state=%s\n",
1110 wpa_supplicant_state_txt(wpa_s->wpa_state));
1111 if (ret < 0 || ret >= end - pos)
1116 l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) {
1117 ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp);
1118 if (ret < 0 || ret >= end - pos)
1124 if (wpa_s->global->p2p) {
1125 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
1126 "\n", MAC2STR(wpa_s->global->p2p_dev_addr));
1127 if (ret < 0 || ret >= end - pos)
1131 #endif /* CONFIG_P2P */
1133 ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n",
1134 MAC2STR(wpa_s->own_addr));
1135 if (ret < 0 || ret >= end - pos)
1140 if (wpa_s->current_bss &&
1141 wpa_bss_get_vendor_ie(wpa_s->current_bss, HS20_IE_VENDOR_TYPE) &&
1142 wpa_s->wpa_proto == WPA_PROTO_RSN &&
1143 wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
1144 ret = os_snprintf(pos, end - pos, "hs20=1\n");
1145 if (ret < 0 || ret >= end - pos)
1149 #endif /* CONFIG_HS20 */
1151 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
1152 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
1153 res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos,
1159 res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose);
1167 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s,
1172 struct wpa_ssid *ssid;
1175 /* cmd: "<network id> <BSSID>" */
1176 pos = os_strchr(cmd, ' ');
1181 wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos);
1182 if (hwaddr_aton(pos, bssid)) {
1183 wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos);
1187 ssid = wpa_config_get_network(wpa_s->conf, id);
1189 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
1194 os_memcpy(ssid->bssid, bssid, ETH_ALEN);
1195 ssid->bssid_set = !is_zero_ether_addr(bssid);
1201 static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant *wpa_s,
1202 char *cmd, char *buf,
1206 struct wpa_blacklist *e;
1210 /* cmd: "BLACKLIST [<BSSID>]" */
1214 e = wpa_s->blacklist;
1216 ret = os_snprintf(pos, end - pos, MACSTR "\n",
1218 if (ret < 0 || ret >= end - pos)
1227 if (os_strncmp(cmd, "clear", 5) == 0) {
1228 wpa_blacklist_clear(wpa_s);
1229 os_memcpy(buf, "OK\n", 3);
1233 wpa_printf(MSG_DEBUG, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd);
1234 if (hwaddr_aton(cmd, bssid)) {
1235 wpa_printf(MSG_DEBUG, "CTRL_IFACE: invalid BSSID '%s'", cmd);
1240 * Add the BSSID twice, so its count will be 2, causing it to be
1241 * skipped when processing scan results.
1243 ret = wpa_blacklist_add(wpa_s, bssid);
1246 ret = wpa_blacklist_add(wpa_s, bssid);
1249 os_memcpy(buf, "OK\n", 3);
1254 extern int wpa_debug_level;
1255 extern int wpa_debug_timestamp;
1257 static const char * debug_level_str(int level)
1278 static int str_to_debug_level(const char *s)
1280 if (os_strcasecmp(s, "EXCESSIVE") == 0)
1281 return MSG_EXCESSIVE;
1282 if (os_strcasecmp(s, "MSGDUMP") == 0)
1284 if (os_strcasecmp(s, "DEBUG") == 0)
1286 if (os_strcasecmp(s, "INFO") == 0)
1288 if (os_strcasecmp(s, "WARNING") == 0)
1290 if (os_strcasecmp(s, "ERROR") == 0)
1296 static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant *wpa_s,
1297 char *cmd, char *buf,
1300 char *pos, *end, *stamp;
1307 /* cmd: "LOG_LEVEL [<level>]" */
1311 ret = os_snprintf(pos, end - pos, "Current level: %s\n"
1313 debug_level_str(wpa_debug_level),
1314 wpa_debug_timestamp);
1315 if (ret < 0 || ret >= end - pos)
1324 stamp = os_strchr(cmd, ' ');
1327 while (*stamp == ' ') {
1332 if (cmd && os_strlen(cmd)) {
1333 int level = str_to_debug_level(cmd);
1336 wpa_debug_level = level;
1339 if (stamp && os_strlen(stamp))
1340 wpa_debug_timestamp = atoi(stamp);
1342 os_memcpy(buf, "OK\n", 3);
1347 static int wpa_supplicant_ctrl_iface_list_networks(
1348 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
1351 struct wpa_ssid *ssid;
1356 ret = os_snprintf(pos, end - pos,
1357 "network id / ssid / bssid / flags\n");
1358 if (ret < 0 || ret >= end - pos)
1362 ssid = wpa_s->conf->ssid;
1364 ret = os_snprintf(pos, end - pos, "%d\t%s",
1366 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
1367 if (ret < 0 || ret >= end - pos)
1370 if (ssid->bssid_set) {
1371 ret = os_snprintf(pos, end - pos, "\t" MACSTR,
1372 MAC2STR(ssid->bssid));
1374 ret = os_snprintf(pos, end - pos, "\tany");
1376 if (ret < 0 || ret >= end - pos)
1379 ret = os_snprintf(pos, end - pos, "\t%s%s%s%s",
1380 ssid == wpa_s->current_ssid ?
1382 ssid->disabled ? "[DISABLED]" : "",
1383 ssid->disabled_until.sec ?
1384 "[TEMP-DISABLED]" : "",
1385 ssid->disabled == 2 ? "[P2P-PERSISTENT]" :
1387 if (ret < 0 || ret >= end - pos)
1390 ret = os_snprintf(pos, end - pos, "\n");
1391 if (ret < 0 || ret >= end - pos)
1402 static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher)
1405 ret = os_snprintf(pos, end - pos, "-");
1406 if (ret < 0 || ret >= end - pos)
1409 if (cipher & WPA_CIPHER_NONE) {
1410 ret = os_snprintf(pos, end - pos, "%sNONE", first ? "" : "+");
1411 if (ret < 0 || ret >= end - pos)
1416 if (cipher & WPA_CIPHER_WEP40) {
1417 ret = os_snprintf(pos, end - pos, "%sWEP40", first ? "" : "+");
1418 if (ret < 0 || ret >= end - pos)
1423 if (cipher & WPA_CIPHER_WEP104) {
1424 ret = os_snprintf(pos, end - pos, "%sWEP104",
1426 if (ret < 0 || ret >= end - pos)
1431 if (cipher & WPA_CIPHER_TKIP) {
1432 ret = os_snprintf(pos, end - pos, "%sTKIP", first ? "" : "+");
1433 if (ret < 0 || ret >= end - pos)
1438 if (cipher & WPA_CIPHER_CCMP) {
1439 ret = os_snprintf(pos, end - pos, "%sCCMP", first ? "" : "+");
1440 if (ret < 0 || ret >= end - pos)
1445 if (cipher & WPA_CIPHER_GCMP) {
1446 ret = os_snprintf(pos, end - pos, "%sGCMP", first ? "" : "+");
1447 if (ret < 0 || ret >= end - pos)
1456 static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
1457 const u8 *ie, size_t ie_len)
1459 struct wpa_ie_data data;
1462 ret = os_snprintf(pos, end - pos, "[%s-", proto);
1463 if (ret < 0 || ret >= end - pos)
1467 if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) {
1468 ret = os_snprintf(pos, end - pos, "?]");
1469 if (ret < 0 || ret >= end - pos)
1476 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
1477 ret = os_snprintf(pos, end - pos, "%sEAP", first ? "" : "+");
1478 if (ret < 0 || ret >= end - pos)
1483 if (data.key_mgmt & WPA_KEY_MGMT_PSK) {
1484 ret = os_snprintf(pos, end - pos, "%sPSK", first ? "" : "+");
1485 if (ret < 0 || ret >= end - pos)
1490 if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
1491 ret = os_snprintf(pos, end - pos, "%sNone", first ? "" : "+");
1492 if (ret < 0 || ret >= end - pos)
1497 #ifdef CONFIG_IEEE80211R
1498 if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
1499 ret = os_snprintf(pos, end - pos, "%sFT/EAP",
1501 if (ret < 0 || ret >= end - pos)
1506 if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) {
1507 ret = os_snprintf(pos, end - pos, "%sFT/PSK",
1509 if (ret < 0 || ret >= end - pos)
1514 #endif /* CONFIG_IEEE80211R */
1515 #ifdef CONFIG_IEEE80211W
1516 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
1517 ret = os_snprintf(pos, end - pos, "%sEAP-SHA256",
1519 if (ret < 0 || ret >= end - pos)
1524 if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
1525 ret = os_snprintf(pos, end - pos, "%sPSK-SHA256",
1527 if (ret < 0 || ret >= end - pos)
1532 #endif /* CONFIG_IEEE80211W */
1534 pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher);
1536 if (data.capabilities & WPA_CAPABILITY_PREAUTH) {
1537 ret = os_snprintf(pos, end - pos, "-preauth");
1538 if (ret < 0 || ret >= end - pos)
1543 ret = os_snprintf(pos, end - pos, "]");
1544 if (ret < 0 || ret >= end - pos)
1553 static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s,
1554 char *pos, char *end,
1555 struct wpabuf *wps_ie)
1562 if (wps_is_selected_pbc_registrar(wps_ie))
1565 else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0))
1567 #endif /* CONFIG_WPS2 */
1568 else if (wps_is_selected_pin_registrar(wps_ie))
1573 ret = os_snprintf(pos, end - pos, "%s", txt);
1574 if (ret >= 0 && ret < end - pos)
1576 wpabuf_free(wps_ie);
1579 #endif /* CONFIG_WPS */
1582 static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s,
1583 char *pos, char *end,
1584 const struct wpa_bss *bss)
1587 struct wpabuf *wps_ie;
1588 wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
1589 return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie);
1590 #else /* CONFIG_WPS */
1592 #endif /* CONFIG_WPS */
1596 /* Format one result on one text line into a buffer. */
1597 static int wpa_supplicant_ctrl_iface_scan_result(
1598 struct wpa_supplicant *wpa_s,
1599 const struct wpa_bss *bss, char *buf, size_t buflen)
1603 const u8 *ie, *ie2, *p2p;
1605 p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
1606 if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN &&
1607 os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) ==
1609 return 0; /* Do not show P2P listen discovery results here */
1614 ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t",
1615 MAC2STR(bss->bssid), bss->freq, bss->level);
1616 if (ret < 0 || ret >= end - pos)
1619 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
1621 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]);
1622 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
1624 pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2, 2 + ie2[1]);
1625 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
1626 if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
1627 ret = os_snprintf(pos, end - pos, "[WEP]");
1628 if (ret < 0 || ret >= end - pos)
1632 if (bss->caps & IEEE80211_CAP_IBSS) {
1633 ret = os_snprintf(pos, end - pos, "[IBSS]");
1634 if (ret < 0 || ret >= end - pos)
1638 if (bss->caps & IEEE80211_CAP_ESS) {
1639 ret = os_snprintf(pos, end - pos, "[ESS]");
1640 if (ret < 0 || ret >= end - pos)
1645 ret = os_snprintf(pos, end - pos, "[P2P]");
1646 if (ret < 0 || ret >= end - pos)
1651 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE) && ie2) {
1652 ret = os_snprintf(pos, end - pos, "[HS20]");
1653 if (ret < 0 || ret >= end - pos)
1657 #endif /* CONFIG_HS20 */
1659 ret = os_snprintf(pos, end - pos, "\t%s",
1660 wpa_ssid_txt(bss->ssid, bss->ssid_len));
1661 if (ret < 0 || ret >= end - pos)
1665 ret = os_snprintf(pos, end - pos, "\n");
1666 if (ret < 0 || ret >= end - pos)
1674 static int wpa_supplicant_ctrl_iface_scan_results(
1675 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
1678 struct wpa_bss *bss;
1683 ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / "
1685 if (ret < 0 || ret >= end - pos)
1689 dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
1690 ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos,
1692 if (ret < 0 || ret >= end - pos)
1701 static int wpa_supplicant_ctrl_iface_select_network(
1702 struct wpa_supplicant *wpa_s, char *cmd)
1705 struct wpa_ssid *ssid;
1707 /* cmd: "<network id>" or "any" */
1708 if (os_strcmp(cmd, "any") == 0) {
1709 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any");
1713 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id);
1715 ssid = wpa_config_get_network(wpa_s->conf, id);
1717 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
1718 "network id=%d", id);
1721 if (ssid->disabled == 2) {
1722 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
1723 "SELECT_NETWORK with persistent P2P group");
1728 wpa_supplicant_select_network(wpa_s, ssid);
1734 static int wpa_supplicant_ctrl_iface_enable_network(
1735 struct wpa_supplicant *wpa_s, char *cmd)
1738 struct wpa_ssid *ssid;
1740 /* cmd: "<network id>" or "all" */
1741 if (os_strcmp(cmd, "all") == 0) {
1742 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all");
1746 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id);
1748 ssid = wpa_config_get_network(wpa_s->conf, id);
1750 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
1751 "network id=%d", id);
1754 if (ssid->disabled == 2) {
1755 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
1756 "ENABLE_NETWORK with persistent P2P group");
1760 if (os_strstr(cmd, " no-connect")) {
1765 wpa_supplicant_enable_network(wpa_s, ssid);
1771 static int wpa_supplicant_ctrl_iface_disable_network(
1772 struct wpa_supplicant *wpa_s, char *cmd)
1775 struct wpa_ssid *ssid;
1777 /* cmd: "<network id>" or "all" */
1778 if (os_strcmp(cmd, "all") == 0) {
1779 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all");
1783 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id);
1785 ssid = wpa_config_get_network(wpa_s->conf, id);
1787 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
1788 "network id=%d", id);
1791 if (ssid->disabled == 2) {
1792 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
1793 "DISABLE_NETWORK with persistent P2P "
1798 wpa_supplicant_disable_network(wpa_s, ssid);
1804 static int wpa_supplicant_ctrl_iface_add_network(
1805 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
1807 struct wpa_ssid *ssid;
1810 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK");
1812 ssid = wpa_config_add_network(wpa_s->conf);
1816 wpas_notify_network_added(wpa_s, ssid);
1819 wpa_config_set_network_defaults(ssid);
1821 ret = os_snprintf(buf, buflen, "%d\n", ssid->id);
1822 if (ret < 0 || (size_t) ret >= buflen)
1828 static int wpa_supplicant_ctrl_iface_remove_network(
1829 struct wpa_supplicant *wpa_s, char *cmd)
1832 struct wpa_ssid *ssid;
1834 /* cmd: "<network id>" or "all" */
1835 if (os_strcmp(cmd, "all") == 0) {
1836 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all");
1837 ssid = wpa_s->conf->ssid;
1839 struct wpa_ssid *remove_ssid = ssid;
1842 wpas_notify_network_removed(wpa_s, remove_ssid);
1843 wpa_config_remove_network(wpa_s->conf, id);
1845 eapol_sm_invalidate_cached_session(wpa_s->eapol);
1846 if (wpa_s->current_ssid) {
1848 wpa_s->sme.prev_bssid_set = 0;
1849 #endif /* CONFIG_SME */
1850 wpa_sm_set_config(wpa_s->wpa, NULL);
1851 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
1852 wpa_supplicant_disassociate(wpa_s,
1853 WLAN_REASON_DEAUTH_LEAVING);
1859 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id);
1861 ssid = wpa_config_get_network(wpa_s->conf, id);
1863 wpas_notify_network_removed(wpa_s, ssid);
1865 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
1870 if (ssid == wpa_s->current_ssid || wpa_s->current_ssid == NULL) {
1872 wpa_s->sme.prev_bssid_set = 0;
1873 #endif /* CONFIG_SME */
1875 * Invalidate the EAP session cache if the current or
1876 * previously used network is removed.
1878 eapol_sm_invalidate_cached_session(wpa_s->eapol);
1881 if (ssid == wpa_s->current_ssid) {
1882 wpa_sm_set_config(wpa_s->wpa, NULL);
1883 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
1885 wpa_supplicant_disassociate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1888 if (wpa_config_remove_network(wpa_s->conf, id) < 0) {
1889 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Not able to remove the "
1890 "network id=%d", id);
1898 static int wpa_supplicant_ctrl_iface_set_network(
1899 struct wpa_supplicant *wpa_s, char *cmd)
1902 struct wpa_ssid *ssid;
1905 /* cmd: "<network id> <variable name> <value>" */
1906 name = os_strchr(cmd, ' ');
1911 value = os_strchr(name, ' ');
1917 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
1919 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
1920 (u8 *) value, os_strlen(value));
1922 ssid = wpa_config_get_network(wpa_s->conf, id);
1924 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
1929 if (wpa_config_set(ssid, name, value, 0) < 0) {
1930 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network "
1931 "variable '%s'", name);
1935 wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
1937 if (wpa_s->current_ssid == ssid || wpa_s->current_ssid == NULL) {
1939 * Invalidate the EAP session cache if anything in the current
1940 * or previously used configuration changes.
1942 eapol_sm_invalidate_cached_session(wpa_s->eapol);
1945 if ((os_strcmp(name, "psk") == 0 &&
1946 value[0] == '"' && ssid->ssid_len) ||
1947 (os_strcmp(name, "ssid") == 0 && ssid->passphrase))
1948 wpa_config_update_psk(ssid);
1949 else if (os_strcmp(name, "priority") == 0)
1950 wpa_config_update_prio_list(wpa_s->conf);
1956 static int wpa_supplicant_ctrl_iface_get_network(
1957 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
1961 struct wpa_ssid *ssid;
1964 /* cmd: "<network id> <variable name>" */
1965 name = os_strchr(cmd, ' ');
1966 if (name == NULL || buflen == 0)
1971 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
1974 ssid = wpa_config_get_network(wpa_s->conf, id);
1976 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
1981 value = wpa_config_get_no_key(ssid, name);
1982 if (value == NULL) {
1983 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
1984 "variable '%s'", name);
1988 res = os_strlcpy(buf, value, buflen);
1989 if (res >= buflen) {
2000 static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant *wpa_s,
2001 char *buf, size_t buflen)
2004 struct wpa_cred *cred;
2009 ret = os_snprintf(pos, end - pos,
2010 "cred id / realm / username / domain / imsi\n");
2011 if (ret < 0 || ret >= end - pos)
2015 cred = wpa_s->conf->cred;
2017 ret = os_snprintf(pos, end - pos, "%d\t%s\t%s\t%s\t%s\n",
2018 cred->id, cred->realm ? cred->realm : "",
2019 cred->username ? cred->username : "",
2020 cred->domain ? cred->domain : "",
2021 cred->imsi ? cred->imsi : "");
2022 if (ret < 0 || ret >= end - pos)
2033 static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant *wpa_s,
2034 char *buf, size_t buflen)
2036 struct wpa_cred *cred;
2039 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_CRED");
2041 cred = wpa_config_add_cred(wpa_s->conf);
2045 ret = os_snprintf(buf, buflen, "%d\n", cred->id);
2046 if (ret < 0 || (size_t) ret >= buflen)
2052 static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s,
2056 struct wpa_cred *cred;
2058 /* cmd: "<cred id>" or "all" */
2059 if (os_strcmp(cmd, "all") == 0) {
2060 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED all");
2061 cred = wpa_s->conf->cred;
2065 wpa_config_remove_cred(wpa_s->conf, id);
2071 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED id=%d", id);
2073 cred = wpa_config_get_cred(wpa_s->conf, id);
2075 wpa_config_remove_cred(wpa_s->conf, id) < 0) {
2076 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
2085 static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant *wpa_s,
2089 struct wpa_cred *cred;
2092 /* cmd: "<cred id> <variable name> <value>" */
2093 name = os_strchr(cmd, ' ');
2098 value = os_strchr(name, ' ');
2104 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_CRED id=%d name='%s'",
2106 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
2107 (u8 *) value, os_strlen(value));
2109 cred = wpa_config_get_cred(wpa_s->conf, id);
2111 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
2116 if (wpa_config_set_cred(cred, name, value, 0) < 0) {
2117 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set cred "
2118 "variable '%s'", name);
2126 #ifndef CONFIG_NO_CONFIG_WRITE
2127 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s)
2131 if (!wpa_s->conf->update_config) {
2132 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
2133 "to update configuration (update_config=0)");
2137 ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
2139 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to "
2140 "update configuration");
2142 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration"
2148 #endif /* CONFIG_NO_CONFIG_WRITE */
2151 static int ctrl_iface_get_capability_pairwise(int res, char *strict,
2152 struct wpa_driver_capa *capa,
2153 char *buf, size_t buflen)
2165 len = os_strlcpy(buf, "CCMP TKIP NONE", buflen);
2171 if (capa->enc & WPA_DRIVER_CAPA_ENC_CCMP) {
2172 ret = os_snprintf(pos, end - pos, "%sCCMP", first ? "" : " ");
2173 if (ret < 0 || ret >= end - pos)
2179 if (capa->enc & WPA_DRIVER_CAPA_ENC_GCMP) {
2180 ret = os_snprintf(pos, end - pos, "%sGCMP", first ? "" : " ");
2181 if (ret < 0 || ret >= end - pos)
2187 if (capa->enc & WPA_DRIVER_CAPA_ENC_TKIP) {
2188 ret = os_snprintf(pos, end - pos, "%sTKIP", first ? "" : " ");
2189 if (ret < 0 || ret >= end - pos)
2195 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
2196 ret = os_snprintf(pos, end - pos, "%sNONE", first ? "" : " ");
2197 if (ret < 0 || ret >= end - pos)
2207 static int ctrl_iface_get_capability_group(int res, char *strict,
2208 struct wpa_driver_capa *capa,
2209 char *buf, size_t buflen)
2221 len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen);
2227 if (capa->enc & WPA_DRIVER_CAPA_ENC_CCMP) {
2228 ret = os_snprintf(pos, end - pos, "%sCCMP", first ? "" : " ");
2229 if (ret < 0 || ret >= end - pos)
2235 if (capa->enc & WPA_DRIVER_CAPA_ENC_GCMP) {
2236 ret = os_snprintf(pos, end - pos, "%sGCMP", first ? "" : " ");
2237 if (ret < 0 || ret >= end - pos)
2243 if (capa->enc & WPA_DRIVER_CAPA_ENC_TKIP) {
2244 ret = os_snprintf(pos, end - pos, "%sTKIP", first ? "" : " ");
2245 if (ret < 0 || ret >= end - pos)
2251 if (capa->enc & WPA_DRIVER_CAPA_ENC_WEP104) {
2252 ret = os_snprintf(pos, end - pos, "%sWEP104",
2254 if (ret < 0 || ret >= end - pos)
2260 if (capa->enc & WPA_DRIVER_CAPA_ENC_WEP40) {
2261 ret = os_snprintf(pos, end - pos, "%sWEP40", first ? "" : " ");
2262 if (ret < 0 || ret >= end - pos)
2272 static int ctrl_iface_get_capability_key_mgmt(int res, char *strict,
2273 struct wpa_driver_capa *capa,
2274 char *buf, size_t buflen)
2286 len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
2293 ret = os_snprintf(pos, end - pos, "NONE IEEE8021X");
2294 if (ret < 0 || ret >= end - pos)
2298 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
2299 WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
2300 ret = os_snprintf(pos, end - pos, " WPA-EAP");
2301 if (ret < 0 || ret >= end - pos)
2306 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
2307 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
2308 ret = os_snprintf(pos, end - pos, " WPA-PSK");
2309 if (ret < 0 || ret >= end - pos)
2314 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
2315 ret = os_snprintf(pos, end - pos, " WPA-NONE");
2316 if (ret < 0 || ret >= end - pos)
2325 static int ctrl_iface_get_capability_proto(int res, char *strict,
2326 struct wpa_driver_capa *capa,
2327 char *buf, size_t buflen)
2339 len = os_strlcpy(buf, "RSN WPA", buflen);
2345 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
2346 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
2347 ret = os_snprintf(pos, end - pos, "%sRSN", first ? "" : " ");
2348 if (ret < 0 || ret >= end - pos)
2354 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
2355 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
2356 ret = os_snprintf(pos, end - pos, "%sWPA", first ? "" : " ");
2357 if (ret < 0 || ret >= end - pos)
2367 static int ctrl_iface_get_capability_auth_alg(int res, char *strict,
2368 struct wpa_driver_capa *capa,
2369 char *buf, size_t buflen)
2381 len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen);
2387 if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) {
2388 ret = os_snprintf(pos, end - pos, "%sOPEN", first ? "" : " ");
2389 if (ret < 0 || ret >= end - pos)
2395 if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) {
2396 ret = os_snprintf(pos, end - pos, "%sSHARED",
2398 if (ret < 0 || ret >= end - pos)
2404 if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) {
2405 ret = os_snprintf(pos, end - pos, "%sLEAP", first ? "" : " ");
2406 if (ret < 0 || ret >= end - pos)
2416 static int ctrl_iface_get_capability_channels(struct wpa_supplicant *wpa_s,
2417 char *buf, size_t buflen)
2419 struct hostapd_channel_data *chnl;
2421 char *pos, *end, *hmode;
2426 for (j = 0; j < wpa_s->hw.num_modes; j++) {
2427 switch (wpa_s->hw.modes[j].mode) {
2428 case HOSTAPD_MODE_IEEE80211B:
2431 case HOSTAPD_MODE_IEEE80211G:
2434 case HOSTAPD_MODE_IEEE80211A:
2440 ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:", hmode);
2441 if (ret < 0 || ret >= end - pos)
2444 chnl = wpa_s->hw.modes[j].channels;
2445 for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
2446 if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
2448 ret = os_snprintf(pos, end - pos, " %d", chnl[i].chan);
2449 if (ret < 0 || ret >= end - pos)
2453 ret = os_snprintf(pos, end - pos, "\n");
2454 if (ret < 0 || ret >= end - pos)
2463 static int wpa_supplicant_ctrl_iface_get_capability(
2464 struct wpa_supplicant *wpa_s, const char *_field, char *buf,
2467 struct wpa_driver_capa capa;
2473 /* Determine whether or not strict checking was requested */
2474 len = os_strlcpy(field, _field, sizeof(field));
2475 if (len >= sizeof(field))
2477 strict = os_strchr(field, ' ');
2478 if (strict != NULL) {
2480 if (os_strcmp(strict, "strict") != 0)
2484 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
2485 field, strict ? strict : "");
2487 if (os_strcmp(field, "eap") == 0) {
2488 return eap_get_names(buf, buflen);
2491 res = wpa_drv_get_capa(wpa_s, &capa);
2493 if (os_strcmp(field, "pairwise") == 0)
2494 return ctrl_iface_get_capability_pairwise(res, strict, &capa,
2497 if (os_strcmp(field, "group") == 0)
2498 return ctrl_iface_get_capability_group(res, strict, &capa,
2501 if (os_strcmp(field, "key_mgmt") == 0)
2502 return ctrl_iface_get_capability_key_mgmt(res, strict, &capa,
2505 if (os_strcmp(field, "proto") == 0)
2506 return ctrl_iface_get_capability_proto(res, strict, &capa,
2509 if (os_strcmp(field, "auth_alg") == 0)
2510 return ctrl_iface_get_capability_auth_alg(res, strict, &capa,
2513 if (os_strcmp(field, "channels") == 0)
2514 return ctrl_iface_get_capability_channels(wpa_s, buf, buflen);
2516 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
2523 #ifdef CONFIG_INTERWORKING
2524 static char * anqp_add_hex(char *pos, char *end, const char *title,
2525 struct wpabuf *data)
2535 ret = os_snprintf(pos, end - pos, "%s=", title);
2536 if (ret < 0 || ret >= end - pos)
2540 d = wpabuf_head_u8(data);
2541 for (i = 0; i < wpabuf_len(data); i++) {
2542 ret = os_snprintf(pos, end - pos, "%02x", *d++);
2543 if (ret < 0 || ret >= end - pos)
2548 ret = os_snprintf(pos, end - pos, "\n");
2549 if (ret < 0 || ret >= end - pos)
2555 #endif /* CONFIG_INTERWORKING */
2558 static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
2559 unsigned long mask, char *buf, size_t buflen)
2569 if (mask & WPA_BSS_MASK_ID) {
2570 ret = os_snprintf(pos, end - pos, "id=%u\n", bss->id);
2571 if (ret < 0 || ret >= end - pos)
2576 if (mask & WPA_BSS_MASK_BSSID) {
2577 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
2578 MAC2STR(bss->bssid));
2579 if (ret < 0 || ret >= end - pos)
2584 if (mask & WPA_BSS_MASK_FREQ) {
2585 ret = os_snprintf(pos, end - pos, "freq=%d\n", bss->freq);
2586 if (ret < 0 || ret >= end - pos)
2591 if (mask & WPA_BSS_MASK_BEACON_INT) {
2592 ret = os_snprintf(pos, end - pos, "beacon_int=%d\n",
2594 if (ret < 0 || ret >= end - pos)
2599 if (mask & WPA_BSS_MASK_CAPABILITIES) {
2600 ret = os_snprintf(pos, end - pos, "capabilities=0x%04x\n",
2602 if (ret < 0 || ret >= end - pos)
2607 if (mask & WPA_BSS_MASK_QUAL) {
2608 ret = os_snprintf(pos, end - pos, "qual=%d\n", bss->qual);
2609 if (ret < 0 || ret >= end - pos)
2614 if (mask & WPA_BSS_MASK_NOISE) {
2615 ret = os_snprintf(pos, end - pos, "noise=%d\n", bss->noise);
2616 if (ret < 0 || ret >= end - pos)
2621 if (mask & WPA_BSS_MASK_LEVEL) {
2622 ret = os_snprintf(pos, end - pos, "level=%d\n", bss->level);
2623 if (ret < 0 || ret >= end - pos)
2628 if (mask & WPA_BSS_MASK_TSF) {
2629 ret = os_snprintf(pos, end - pos, "tsf=%016llu\n",
2630 (unsigned long long) bss->tsf);
2631 if (ret < 0 || ret >= end - pos)
2636 if (mask & WPA_BSS_MASK_AGE) {
2640 ret = os_snprintf(pos, end - pos, "age=%d\n",
2641 (int) (now.sec - bss->last_update.sec));
2642 if (ret < 0 || ret >= end - pos)
2647 if (mask & WPA_BSS_MASK_IE) {
2648 ret = os_snprintf(pos, end - pos, "ie=");
2649 if (ret < 0 || ret >= end - pos)
2653 ie = (const u8 *) (bss + 1);
2654 for (i = 0; i < bss->ie_len; i++) {
2655 ret = os_snprintf(pos, end - pos, "%02x", *ie++);
2656 if (ret < 0 || ret >= end - pos)
2661 ret = os_snprintf(pos, end - pos, "\n");
2662 if (ret < 0 || ret >= end - pos)
2667 if (mask & WPA_BSS_MASK_FLAGS) {
2668 ret = os_snprintf(pos, end - pos, "flags=");
2669 if (ret < 0 || ret >= end - pos)
2673 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
2675 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie,
2677 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
2679 pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2,
2681 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
2682 if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
2683 ret = os_snprintf(pos, end - pos, "[WEP]");
2684 if (ret < 0 || ret >= end - pos)
2688 if (bss->caps & IEEE80211_CAP_IBSS) {
2689 ret = os_snprintf(pos, end - pos, "[IBSS]");
2690 if (ret < 0 || ret >= end - pos)
2694 if (bss->caps & IEEE80211_CAP_ESS) {
2695 ret = os_snprintf(pos, end - pos, "[ESS]");
2696 if (ret < 0 || ret >= end - pos)
2700 if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE)) {
2701 ret = os_snprintf(pos, end - pos, "[P2P]");
2702 if (ret < 0 || ret >= end - pos)
2707 if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) {
2708 ret = os_snprintf(pos, end - pos, "[HS20]");
2709 if (ret < 0 || ret >= end - pos)
2713 #endif /* CONFIG_HS20 */
2715 ret = os_snprintf(pos, end - pos, "\n");
2716 if (ret < 0 || ret >= end - pos)
2721 if (mask & WPA_BSS_MASK_SSID) {
2722 ret = os_snprintf(pos, end - pos, "ssid=%s\n",
2723 wpa_ssid_txt(bss->ssid, bss->ssid_len));
2724 if (ret < 0 || ret >= end - pos)
2730 if (mask & WPA_BSS_MASK_WPS_SCAN) {
2731 ie = (const u8 *) (bss + 1);
2732 ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end);
2733 if (ret < 0 || ret >= end - pos)
2737 #endif /* CONFIG_WPS */
2740 if (mask & WPA_BSS_MASK_P2P_SCAN) {
2741 ie = (const u8 *) (bss + 1);
2742 ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end);
2743 if (ret < 0 || ret >= end - pos)
2747 #endif /* CONFIG_P2P */
2749 #ifdef CONFIG_WIFI_DISPLAY
2750 if (mask & WPA_BSS_MASK_WIFI_DISPLAY) {
2752 ie = (const u8 *) (bss + 1);
2753 wfd = ieee802_11_vendor_ie_concat(ie, bss->ie_len,
2754 WFD_IE_VENDOR_TYPE);
2756 ret = os_snprintf(pos, end - pos, "wfd_subelems=");
2757 if (ret < 0 || ret >= end - pos)
2761 pos += wpa_snprintf_hex(pos, end - pos,
2766 ret = os_snprintf(pos, end - pos, "\n");
2767 if (ret < 0 || ret >= end - pos)
2772 #endif /* CONFIG_WIFI_DISPLAY */
2774 #ifdef CONFIG_INTERWORKING
2775 if (mask & WPA_BSS_MASK_INTERNETW) {
2776 pos = anqp_add_hex(pos, end, "anqp_venue_name",
2777 bss->anqp_venue_name);
2778 pos = anqp_add_hex(pos, end, "anqp_network_auth_type",
2779 bss->anqp_network_auth_type);
2780 pos = anqp_add_hex(pos, end, "anqp_roaming_consortium",
2781 bss->anqp_roaming_consortium);
2782 pos = anqp_add_hex(pos, end, "anqp_ip_addr_type_availability",
2783 bss->anqp_ip_addr_type_availability);
2784 pos = anqp_add_hex(pos, end, "anqp_nai_realm",
2785 bss->anqp_nai_realm);
2786 pos = anqp_add_hex(pos, end, "anqp_3gpp", bss->anqp_3gpp);
2787 pos = anqp_add_hex(pos, end, "anqp_domain_name",
2788 bss->anqp_domain_name);
2790 pos = anqp_add_hex(pos, end, "hs20_operator_friendly_name",
2791 bss->hs20_operator_friendly_name);
2792 pos = anqp_add_hex(pos, end, "hs20_wan_metrics",
2793 bss->hs20_wan_metrics);
2794 pos = anqp_add_hex(pos, end, "hs20_connection_capability",
2795 bss->hs20_connection_capability);
2796 #endif /* CONFIG_HS20 */
2798 #endif /* CONFIG_INTERWORKING */
2804 static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
2805 const char *cmd, char *buf,
2810 struct wpa_bss *bss;
2811 struct wpa_bss *bsslast = NULL;
2812 struct dl_list *next;
2816 unsigned long mask = WPA_BSS_MASK_ALL;
2818 if (os_strncmp(cmd, "RANGE=", 6) == 0) {
2819 if (os_strncmp(cmd + 6, "ALL", 3) == 0) {
2820 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss,
2822 bsslast = dl_list_last(&wpa_s->bss_id, struct wpa_bss,
2824 } else { /* N1-N2 */
2825 unsigned int id1, id2;
2827 if ((ctmp = os_strchr(cmd + 6, '-')) == NULL) {
2828 wpa_printf(MSG_INFO, "Wrong BSS range "
2833 id1 = atoi(cmd + 6);
2834 bss = wpa_bss_get_id(wpa_s, id1);
2835 id2 = atoi(ctmp + 1);
2837 bsslast = dl_list_last(&wpa_s->bss_id,
2841 bsslast = wpa_bss_get_id(wpa_s, id2);
2842 if (bsslast == NULL && bss && id2 > id1) {
2843 struct wpa_bss *tmp = bss;
2845 next = tmp->list_id.next;
2846 if (next == &wpa_s->bss_id)
2848 tmp = dl_list_entry(
2849 next, struct wpa_bss,
2858 } else if (os_strcmp(cmd, "FIRST") == 0)
2859 bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, list_id);
2860 else if (os_strncmp(cmd, "ID-", 3) == 0) {
2862 bss = wpa_bss_get_id(wpa_s, i);
2863 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
2865 bss = wpa_bss_get_id(wpa_s, i);
2867 next = bss->list_id.next;
2868 if (next == &wpa_s->bss_id)
2871 bss = dl_list_entry(next, struct wpa_bss,
2875 } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
2876 if (hwaddr_aton(cmd + 13, bssid) == 0)
2877 bss = wpa_bss_get_p2p_dev_addr(wpa_s, bssid);
2880 #endif /* CONFIG_P2P */
2881 } else if (hwaddr_aton(cmd, bssid) == 0)
2882 bss = wpa_bss_get_bssid(wpa_s, bssid);
2884 struct wpa_bss *tmp;
2887 dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id)
2896 if ((ctmp = os_strstr(cmd, "MASK=")) != NULL) {
2897 mask = strtoul(ctmp + 5, NULL, 0x10);
2899 mask = WPA_BSS_MASK_ALL;
2905 if (bsslast == NULL)
2908 len = print_bss_info(wpa_s, bss, mask, buf, buflen);
2914 next = bss->list_id.next;
2915 if (next == &wpa_s->bss_id)
2917 bss = dl_list_entry(next, struct wpa_bss, list_id);
2918 } while (bss && len);
2924 static int wpa_supplicant_ctrl_iface_ap_scan(
2925 struct wpa_supplicant *wpa_s, char *cmd)
2927 int ap_scan = atoi(cmd);
2928 return wpa_supplicant_set_ap_scan(wpa_s, ap_scan);
2932 static int wpa_supplicant_ctrl_iface_scan_interval(
2933 struct wpa_supplicant *wpa_s, char *cmd)
2935 int scan_int = atoi(cmd);
2936 return wpa_supplicant_set_scan_interval(wpa_s, scan_int);
2940 static int wpa_supplicant_ctrl_iface_bss_expire_age(
2941 struct wpa_supplicant *wpa_s, char *cmd)
2943 int expire_age = atoi(cmd);
2944 return wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age);
2948 static int wpa_supplicant_ctrl_iface_bss_expire_count(
2949 struct wpa_supplicant *wpa_s, char *cmd)
2951 int expire_count = atoi(cmd);
2952 return wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count);
2956 static int wpa_supplicant_ctrl_iface_bss_flush(
2957 struct wpa_supplicant *wpa_s, char *cmd)
2959 int flush_age = atoi(cmd);
2962 wpa_bss_flush(wpa_s);
2964 wpa_bss_flush_by_age(wpa_s, flush_age);
2969 static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s)
2971 wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication");
2972 /* MLME-DELETEKEYS.request */
2973 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL, 0);
2974 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL, 0);
2975 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL, 0);
2976 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL, 0);
2977 #ifdef CONFIG_IEEE80211W
2978 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL, 0);
2979 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL, 0);
2980 #endif /* CONFIG_IEEE80211W */
2982 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, wpa_s->bssid, 0, 0, NULL, 0, NULL,
2984 /* MLME-SETPROTECTION.request(None) */
2985 wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid,
2986 MLME_SETPROTECTION_PROTECT_TYPE_NONE,
2987 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE);
2988 wpa_sm_drop_sa(wpa_s->wpa);
2992 static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s,
2995 #ifdef CONFIG_NO_SCAN_PROCESSING
2997 #else /* CONFIG_NO_SCAN_PROCESSING */
2999 struct wpa_bss *bss;
3000 struct wpa_ssid *ssid = wpa_s->current_ssid;
3002 if (hwaddr_aton(addr, bssid)) {
3003 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid "
3004 "address '%s'", addr);
3008 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR, MAC2STR(bssid));
3010 bss = wpa_bss_get_bssid(wpa_s, bssid);
3012 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found "
3018 * TODO: Find best network configuration block from configuration to
3019 * allow roaming to other networks
3023 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network "
3024 "configuration known for the target AP");
3028 wpa_s->reassociate = 1;
3029 wpa_supplicant_connect(wpa_s, bss, ssid);
3032 #endif /* CONFIG_NO_SCAN_PROCESSING */
3037 static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd)
3039 unsigned int timeout = atoi(cmd);
3040 enum p2p_discovery_type type = P2P_FIND_START_WITH_FULL;
3041 u8 dev_id[ETH_ALEN], *_dev_id = NULL;
3043 unsigned int search_delay;
3045 if (os_strstr(cmd, "type=social"))
3046 type = P2P_FIND_ONLY_SOCIAL;
3047 else if (os_strstr(cmd, "type=progressive"))
3048 type = P2P_FIND_PROGRESSIVE;
3050 pos = os_strstr(cmd, "dev_id=");
3053 if (hwaddr_aton(pos, dev_id))
3058 pos = os_strstr(cmd, "delay=");
3061 search_delay = atoi(pos);
3063 search_delay = wpas_p2p_search_delay(wpa_s);
3065 return wpas_p2p_find(wpa_s, timeout, type, 0, NULL, _dev_id,
3070 static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd,
3071 char *buf, size_t buflen)
3076 enum p2p_wps_method wps_method;
3079 int persistent_group, persistent_id = -1;
3088 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad]
3089 * [persistent|persistent=<network id>]
3090 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
3093 if (hwaddr_aton(cmd, addr))
3101 persistent_group = os_strstr(pos, " persistent") != NULL;
3102 pos2 = os_strstr(pos, " persistent=");
3104 struct wpa_ssid *ssid;
3105 persistent_id = atoi(pos2 + 12);
3106 ssid = wpa_config_get_network(wpa_s->conf, persistent_id);
3107 if (ssid == NULL || ssid->disabled != 2 ||
3108 ssid->mode != WPAS_MODE_P2P_GO) {
3109 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
3110 "SSID id=%d for persistent P2P group (GO)",
3115 join = os_strstr(pos, " join") != NULL;
3116 auth = os_strstr(pos, " auth") != NULL;
3117 automatic = os_strstr(pos, " auto") != NULL;
3118 pd = os_strstr(pos, " provdisc") != NULL;
3119 ht40 = os_strstr(pos, " ht40") != NULL;
3121 pos2 = os_strstr(pos, " go_intent=");
3124 go_intent = atoi(pos2);
3125 if (go_intent < 0 || go_intent > 15)
3129 pos2 = os_strstr(pos, " freq=");
3137 if (os_strncmp(pos, "pin", 3) == 0) {
3138 /* Request random PIN (to be displayed) and enable the PIN */
3139 wps_method = WPS_PIN_DISPLAY;
3140 } else if (os_strncmp(pos, "pbc", 3) == 0) {
3141 wps_method = WPS_PBC;
3144 pos = os_strchr(pin, ' ');
3145 wps_method = WPS_PIN_KEYPAD;
3148 if (os_strncmp(pos, "display", 7) == 0)
3149 wps_method = WPS_PIN_DISPLAY;
3151 if (!wps_pin_str_valid(pin)) {
3152 os_memcpy(buf, "FAIL-INVALID-PIN\n", 17);
3157 new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method,
3158 persistent_group, automatic, join,
3159 auth, go_intent, freq, persistent_id, pd,
3161 if (new_pin == -2) {
3162 os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
3165 if (new_pin == -3) {
3166 os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
3171 if (wps_method == WPS_PIN_DISPLAY && pin == NULL) {
3172 ret = os_snprintf(buf, buflen, "%08d", new_pin);
3173 if (ret < 0 || (size_t) ret >= buflen)
3178 os_memcpy(buf, "OK\n", 3);
3183 static int p2p_ctrl_listen(struct wpa_supplicant *wpa_s, char *cmd)
3185 unsigned int timeout = atoi(cmd);
3186 return wpas_p2p_listen(wpa_s, timeout);
3190 static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd)
3194 enum wpas_p2p_prov_disc_use use = WPAS_P2P_PD_FOR_GO_NEG;
3196 /* <addr> <config method> [join|auto] */
3198 if (hwaddr_aton(cmd, addr))
3206 if (os_strstr(pos, " join") != NULL)
3207 use = WPAS_P2P_PD_FOR_JOIN;
3208 else if (os_strstr(pos, " auto") != NULL)
3209 use = WPAS_P2P_PD_AUTO;
3211 return wpas_p2p_prov_disc(wpa_s, addr, pos, use);
3215 static int p2p_get_passphrase(struct wpa_supplicant *wpa_s, char *buf,
3218 struct wpa_ssid *ssid = wpa_s->current_ssid;
3220 if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO ||
3221 ssid->passphrase == NULL)
3224 os_strlcpy(buf, ssid->passphrase, buflen);
3225 return os_strlen(buf);
3229 static int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd,
3230 char *buf, size_t buflen)
3234 u8 dst_buf[ETH_ALEN], *dst;
3235 struct wpabuf *tlvs;
3239 if (hwaddr_aton(cmd, dst_buf))
3242 if (dst[0] == 0 && dst[1] == 0 && dst[2] == 0 &&
3243 dst[3] == 0 && dst[4] == 0 && dst[5] == 0)
3250 if (os_strncmp(pos, "upnp ", 5) == 0) {
3253 if (hexstr2bin(pos, &version, 1) < 0)
3259 ref = wpas_p2p_sd_request_upnp(wpa_s, dst, version, pos);
3260 #ifdef CONFIG_WIFI_DISPLAY
3261 } else if (os_strncmp(pos, "wifi-display ", 13) == 0) {
3262 ref = wpas_p2p_sd_request_wifi_display(wpa_s, dst, pos + 13);
3263 #endif /* CONFIG_WIFI_DISPLAY */
3265 len = os_strlen(pos);
3269 tlvs = wpabuf_alloc(len);
3272 if (hexstr2bin(pos, wpabuf_put(tlvs, len), len) < 0) {
3277 ref = wpas_p2p_sd_request(wpa_s, dst, tlvs);
3282 res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref);
3283 if (res < 0 || (unsigned) res >= buflen)
3289 static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s,
3292 long long unsigned val;
3294 if (sscanf(cmd, "%llx", &val) != 1)
3297 return wpas_p2p_sd_cancel_request(wpa_s, req);
3301 static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant *wpa_s, char *cmd)
3306 struct wpabuf *resp_tlvs;
3310 pos = os_strchr(cmd, ' ');
3318 if (hwaddr_aton(pos, dst))
3325 pos2 = os_strchr(pos, ' ');
3329 dialog_token = atoi(pos);
3331 len = os_strlen(pos2);
3335 resp_tlvs = wpabuf_alloc(len);
3336 if (resp_tlvs == NULL)
3338 if (hexstr2bin(pos2, wpabuf_put(resp_tlvs, len), len) < 0) {
3339 wpabuf_free(resp_tlvs);
3343 wpas_p2p_sd_response(wpa_s, freq, dst, dialog_token, resp_tlvs);
3344 wpabuf_free(resp_tlvs);
3349 static int p2p_ctrl_serv_disc_external(struct wpa_supplicant *wpa_s,
3352 if (os_strcmp(cmd, "0") && os_strcmp(cmd, "1"))
3354 wpa_s->p2p_sd_over_ctrl_iface = atoi(cmd);
3359 static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant *wpa_s,
3364 struct wpabuf *query, *resp;
3366 pos = os_strchr(cmd, ' ');
3371 len = os_strlen(cmd);
3375 query = wpabuf_alloc(len);
3378 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
3383 len = os_strlen(pos);
3389 resp = wpabuf_alloc(len);
3394 if (hexstr2bin(pos, wpabuf_put(resp, len), len) < 0) {
3400 if (wpas_p2p_service_add_bonjour(wpa_s, query, resp) < 0) {
3409 static int p2p_ctrl_service_add_upnp(struct wpa_supplicant *wpa_s, char *cmd)
3414 pos = os_strchr(cmd, ' ');
3419 if (hexstr2bin(cmd, &version, 1) < 0)
3422 return wpas_p2p_service_add_upnp(wpa_s, version, pos);
3426 static int p2p_ctrl_service_add(struct wpa_supplicant *wpa_s, char *cmd)
3430 pos = os_strchr(cmd, ' ');
3435 if (os_strcmp(cmd, "bonjour") == 0)
3436 return p2p_ctrl_service_add_bonjour(wpa_s, pos);
3437 if (os_strcmp(cmd, "upnp") == 0)
3438 return p2p_ctrl_service_add_upnp(wpa_s, pos);
3439 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
3444 static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant *wpa_s,
3448 struct wpabuf *query;
3451 len = os_strlen(cmd);
3455 query = wpabuf_alloc(len);
3458 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
3463 ret = wpas_p2p_service_del_bonjour(wpa_s, query);
3469 static int p2p_ctrl_service_del_upnp(struct wpa_supplicant *wpa_s, char *cmd)
3474 pos = os_strchr(cmd, ' ');
3479 if (hexstr2bin(cmd, &version, 1) < 0)
3482 return wpas_p2p_service_del_upnp(wpa_s, version, pos);
3486 static int p2p_ctrl_service_del(struct wpa_supplicant *wpa_s, char *cmd)
3490 pos = os_strchr(cmd, ' ');
3495 if (os_strcmp(cmd, "bonjour") == 0)
3496 return p2p_ctrl_service_del_bonjour(wpa_s, pos);
3497 if (os_strcmp(cmd, "upnp") == 0)
3498 return p2p_ctrl_service_del_upnp(wpa_s, pos);
3499 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
3504 static int p2p_ctrl_reject(struct wpa_supplicant *wpa_s, char *cmd)
3510 if (hwaddr_aton(cmd, addr))
3513 return wpas_p2p_reject(wpa_s, addr);
3517 static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd)
3521 struct wpa_ssid *ssid;
3527 pos = os_strstr(cmd, " peer=");
3530 if (hwaddr_aton(pos, peer))
3533 ssid = wpa_config_get_network(wpa_s->conf, id);
3534 if (ssid == NULL || ssid->disabled != 2) {
3535 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
3536 "for persistent P2P group",
3541 pos = os_strstr(cmd, " freq=");
3549 ht40 = os_strstr(cmd, " ht40") != NULL;
3551 return wpas_p2p_invite(wpa_s, pos ? peer : NULL, ssid, NULL, freq,
3556 static int p2p_ctrl_invite_group(struct wpa_supplicant *wpa_s, char *cmd)
3559 u8 peer[ETH_ALEN], go_dev_addr[ETH_ALEN], *go_dev = NULL;
3561 pos = os_strstr(cmd, " peer=");
3567 if (hwaddr_aton(pos, peer)) {
3568 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", pos);
3572 pos = os_strstr(pos, " go_dev_addr=");
3575 if (hwaddr_aton(pos, go_dev_addr)) {
3576 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'",
3580 go_dev = go_dev_addr;
3583 return wpas_p2p_invite_group(wpa_s, cmd, peer, go_dev);
3587 static int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd)
3589 if (os_strncmp(cmd, "persistent=", 11) == 0)
3590 return p2p_ctrl_invite_persistent(wpa_s, cmd + 11);
3591 if (os_strncmp(cmd, "group=", 6) == 0)
3592 return p2p_ctrl_invite_group(wpa_s, cmd + 6);
3598 static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s,
3599 char *cmd, int freq, int ht40)
3602 struct wpa_ssid *ssid;
3605 ssid = wpa_config_get_network(wpa_s->conf, id);
3606 if (ssid == NULL || ssid->disabled != 2) {
3607 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
3608 "for persistent P2P group",
3613 return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq, ht40);
3617 static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd)
3622 pos = os_strstr(cmd, "freq=");
3624 freq = atoi(pos + 5);
3626 ht40 = os_strstr(cmd, "ht40") != NULL;
3628 if (os_strncmp(cmd, "persistent=", 11) == 0)
3629 return p2p_ctrl_group_add_persistent(wpa_s, cmd + 11, freq,
3631 if (os_strcmp(cmd, "persistent") == 0 ||
3632 os_strncmp(cmd, "persistent ", 11) == 0)
3633 return wpas_p2p_group_add(wpa_s, 1, freq, ht40);
3634 if (os_strncmp(cmd, "freq=", 5) == 0)
3635 return wpas_p2p_group_add(wpa_s, 0, freq, ht40);
3637 return wpas_p2p_group_add(wpa_s, 0, freq, ht40);
3639 wpa_printf(MSG_DEBUG, "CTRL: Invalid P2P_GROUP_ADD parameters '%s'",
3645 static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd,
3646 char *buf, size_t buflen)
3648 u8 addr[ETH_ALEN], *addr_ptr;
3650 const struct p2p_peer_info *info;
3652 char devtype[WPS_DEV_TYPE_BUFSIZE];
3653 struct wpa_ssid *ssid;
3655 if (!wpa_s->global->p2p)
3658 if (os_strcmp(cmd, "FIRST") == 0) {
3661 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
3662 if (hwaddr_aton(cmd + 5, addr) < 0)
3667 if (hwaddr_aton(cmd, addr) < 0)
3673 info = p2p_get_peer_info(wpa_s->global->p2p, addr_ptr, next);
3680 res = os_snprintf(pos, end - pos, MACSTR "\n"
3686 "serial_number=%s\n"
3687 "config_methods=0x%x\n"
3689 "group_capab=0x%x\n"
3691 MAC2STR(info->p2p_device_addr),
3692 wps_dev_type_bin2str(info->pri_dev_type,
3693 devtype, sizeof(devtype)),
3698 info->serial_number,
3699 info->config_methods,
3703 if (res < 0 || res >= end - pos)
3707 ssid = wpas_p2p_get_persistent(wpa_s, info->p2p_device_addr, NULL, 0);
3709 res = os_snprintf(pos, end - pos, "persistent=%d\n", ssid->id);
3710 if (res < 0 || res >= end - pos)
3715 res = p2p_get_peer_info_txt(info, pos, end - pos);
3724 static int p2p_ctrl_disallow_freq(struct wpa_supplicant *wpa_s,
3727 struct wpa_freq_range *freq = NULL, *n;
3728 unsigned int count = 0, i;
3729 const char *pos, *pos2, *pos3;
3731 if (wpa_s->global->p2p == NULL)
3735 * param includes comma separated frequency range.
3736 * For example: 2412-2432,2462,5000-6000
3739 while (pos && pos[0]) {
3740 n = os_realloc_array(freq, count + 1,
3741 sizeof(struct wpa_freq_range));
3747 freq[count].min = atoi(pos);
3748 pos2 = os_strchr(pos, '-');
3749 pos3 = os_strchr(pos, ',');
3750 if (pos2 && (!pos3 || pos2 < pos3)) {
3752 freq[count].max = atoi(pos2);
3754 freq[count].max = freq[count].min;
3761 for (i = 0; i < count; i++) {
3762 wpa_printf(MSG_DEBUG, "P2P: Disallowed frequency range %u-%u",
3763 freq[i].min, freq[i].max);
3766 os_free(wpa_s->global->p2p_disallow_freq);
3767 wpa_s->global->p2p_disallow_freq = freq;
3768 wpa_s->global->num_p2p_disallow_freq = count;
3769 wpas_p2p_update_channel_list(wpa_s);
3774 static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd)
3778 if (wpa_s->global->p2p == NULL)
3781 param = os_strchr(cmd, ' ');
3786 if (os_strcmp(cmd, "discoverability") == 0) {
3787 p2p_set_client_discoverability(wpa_s->global->p2p,
3792 if (os_strcmp(cmd, "managed") == 0) {
3793 p2p_set_managed_oper(wpa_s->global->p2p, atoi(param));
3797 if (os_strcmp(cmd, "listen_channel") == 0) {
3798 return p2p_set_listen_channel(wpa_s->global->p2p, 81,
3802 if (os_strcmp(cmd, "ssid_postfix") == 0) {
3803 return p2p_set_ssid_postfix(wpa_s->global->p2p, (u8 *) param,
3807 if (os_strcmp(cmd, "noa") == 0) {
3809 int count, start, duration;
3810 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
3811 count = atoi(param);
3812 pos = os_strchr(param, ',');
3817 pos = os_strchr(pos, ',');
3821 duration = atoi(pos);
3822 if (count < 0 || count > 255 || start < 0 || duration < 0)
3824 if (count == 0 && duration > 0)
3826 wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
3827 "start=%d duration=%d", count, start, duration);
3828 return wpas_p2p_set_noa(wpa_s, count, start, duration);
3831 if (os_strcmp(cmd, "ps") == 0)
3832 return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1);
3834 if (os_strcmp(cmd, "oppps") == 0)
3835 return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1);
3837 if (os_strcmp(cmd, "ctwindow") == 0)
3838 return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param));
3840 if (os_strcmp(cmd, "disabled") == 0) {
3841 wpa_s->global->p2p_disabled = atoi(param);
3842 wpa_printf(MSG_DEBUG, "P2P functionality %s",
3843 wpa_s->global->p2p_disabled ?
3844 "disabled" : "enabled");
3845 if (wpa_s->global->p2p_disabled) {
3846 wpas_p2p_stop_find(wpa_s);
3847 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
3848 p2p_flush(wpa_s->global->p2p);
3853 if (os_strcmp(cmd, "conc_pref") == 0) {
3854 if (os_strcmp(param, "sta") == 0)
3855 wpa_s->global->conc_pref = WPA_CONC_PREF_STA;
3856 else if (os_strcmp(param, "p2p") == 0)
3857 wpa_s->global->conc_pref = WPA_CONC_PREF_P2P;
3859 wpa_printf(MSG_INFO, "Invalid conc_pref value");
3862 wpa_printf(MSG_DEBUG, "Single channel concurrency preference: "
3867 if (os_strcmp(cmd, "force_long_sd") == 0) {
3868 wpa_s->force_long_sd = atoi(param);
3872 if (os_strcmp(cmd, "peer_filter") == 0) {
3874 if (hwaddr_aton(param, addr))
3876 p2p_set_peer_filter(wpa_s->global->p2p, addr);
3880 if (os_strcmp(cmd, "cross_connect") == 0)
3881 return wpas_p2p_set_cross_connect(wpa_s, atoi(param));
3883 if (os_strcmp(cmd, "go_apsd") == 0) {
3884 if (os_strcmp(param, "disable") == 0)
3885 wpa_s->set_ap_uapsd = 0;
3887 wpa_s->set_ap_uapsd = 1;
3888 wpa_s->ap_uapsd = atoi(param);
3893 if (os_strcmp(cmd, "client_apsd") == 0) {
3894 if (os_strcmp(param, "disable") == 0)
3895 wpa_s->set_sta_uapsd = 0;
3899 /* format: BE,BK,VI,VO;max SP Length */
3901 pos = os_strchr(param, ',');
3906 pos = os_strchr(pos, ',');
3911 pos = os_strchr(pos, ',');
3916 /* ignore max SP Length for now */
3918 wpa_s->set_sta_uapsd = 1;
3919 wpa_s->sta_uapsd = 0;
3921 wpa_s->sta_uapsd |= BIT(0);
3923 wpa_s->sta_uapsd |= BIT(1);
3925 wpa_s->sta_uapsd |= BIT(2);
3927 wpa_s->sta_uapsd |= BIT(3);
3932 if (os_strcmp(cmd, "disallow_freq") == 0)
3933 return p2p_ctrl_disallow_freq(wpa_s, param);
3935 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
3942 static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd)
3945 unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0;
3948 pos = os_strchr(cmd, ' ');
3954 pos2 = os_strchr(pos, ' ');
3962 pos = os_strchr(pos2, ' ');
3970 return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2);
3974 static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd)
3977 unsigned int period = 0, interval = 0;
3980 pos = os_strchr(cmd, ' ');
3985 interval = atoi(pos);
3988 return wpas_p2p_ext_listen(wpa_s, period, interval);
3991 #endif /* CONFIG_P2P */
3994 #ifdef CONFIG_INTERWORKING
3995 static int ctrl_interworking_connect(struct wpa_supplicant *wpa_s, char *dst)
3998 struct wpa_bss *bss;
4000 if (hwaddr_aton(dst, bssid)) {
4001 wpa_printf(MSG_DEBUG, "Invalid BSSID '%s'", dst);
4005 bss = wpa_bss_get_bssid(wpa_s, bssid);
4007 wpa_printf(MSG_DEBUG, "Could not find BSS " MACSTR,
4012 return interworking_connect(wpa_s, bss);
4016 static int get_anqp(struct wpa_supplicant *wpa_s, char *dst)
4018 u8 dst_addr[ETH_ALEN];
4021 #define MAX_ANQP_INFO_ID 100
4022 u16 id[MAX_ANQP_INFO_ID];
4025 used = hwaddr_aton2(dst, dst_addr);
4029 while (num_id < MAX_ANQP_INFO_ID) {
4030 id[num_id] = atoi(pos);
4033 pos = os_strchr(pos + 1, ',');
4042 return anqp_send_req(wpa_s, dst_addr, id, num_id);
4046 static int gas_request(struct wpa_supplicant *wpa_s, char *cmd)
4048 u8 dst_addr[ETH_ALEN];
4049 struct wpabuf *advproto, *query = NULL;
4054 used = hwaddr_aton2(cmd, dst_addr);
4062 /* Advertisement Protocol ID */
4063 end = os_strchr(pos, ' ');
4067 len = os_strlen(pos);
4073 advproto = wpabuf_alloc(len);
4074 if (advproto == NULL)
4076 if (hexstr2bin(pos, wpabuf_put(advproto, len), len) < 0)
4080 /* Optional Query Request */
4085 len = os_strlen(pos);
4092 query = wpabuf_alloc(len);
4095 if (hexstr2bin(pos, wpabuf_put(query, len), len) < 0)
4100 ret = gas_send_request(wpa_s, dst_addr, advproto, query);
4103 wpabuf_free(advproto);
4110 static int gas_response_get(struct wpa_supplicant *wpa_s, char *cmd, char *buf,
4117 size_t resp_len, start, requested_len;
4119 if (!wpa_s->last_gas_resp)
4122 used = hwaddr_aton2(cmd, addr);
4129 dialog_token = atoi(pos);
4131 if (os_memcmp(addr, wpa_s->last_gas_addr, ETH_ALEN) != 0 ||
4132 dialog_token != wpa_s->last_gas_dialog_token)
4135 resp_len = wpabuf_len(wpa_s->last_gas_resp);
4137 requested_len = resp_len;
4139 pos = os_strchr(pos, ' ');
4142 if (start > resp_len)
4143 return os_snprintf(buf, buflen, "FAIL-Invalid range");
4144 pos = os_strchr(pos, ',');
4148 requested_len = atoi(pos);
4149 if (start + requested_len > resp_len)
4150 return os_snprintf(buf, buflen, "FAIL-Invalid range");
4153 if (requested_len * 2 + 1 > buflen)
4154 return os_snprintf(buf, buflen, "FAIL-Too long response");
4156 return wpa_snprintf_hex(buf, buflen,
4157 wpabuf_head_u8(wpa_s->last_gas_resp) + start,
4160 #endif /* CONFIG_INTERWORKING */
4165 static int get_hs20_anqp(struct wpa_supplicant *wpa_s, char *dst)
4167 u8 dst_addr[ETH_ALEN];
4172 used = hwaddr_aton2(dst, dst_addr);
4177 int num = atoi(pos);
4178 if (num <= 0 || num > 31)
4180 subtypes |= BIT(num);
4181 pos = os_strchr(pos + 1, ',');
4190 return hs20_anqp_send_req(wpa_s, dst_addr, subtypes, NULL, 0);
4194 static int hs20_nai_home_realm_list(struct wpa_supplicant *wpa_s,
4195 const u8 *addr, const char *realm)
4201 rlen = os_strlen(realm);
4203 buf = os_malloc(len);
4206 buf[0] = 1; /* NAI Home Realm Count */
4207 buf[1] = 0; /* Formatted in accordance with RFC 4282 */
4209 os_memcpy(buf + 3, realm, rlen);
4211 ret = hs20_anqp_send_req(wpa_s, addr,
4212 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
4221 static int hs20_get_nai_home_realm_list(struct wpa_supplicant *wpa_s,
4224 struct wpa_cred *cred = wpa_s->conf->cred;
4225 u8 dst_addr[ETH_ALEN];
4231 used = hwaddr_aton2(dst, dst_addr);
4235 while (dst[used] == ' ')
4237 if (os_strncmp(dst + used, "realm=", 6) == 0)
4238 return hs20_nai_home_realm_list(wpa_s, dst_addr,
4241 len = os_strlen(dst + used);
4243 if (len == 0 && cred && cred->realm)
4244 return hs20_nai_home_realm_list(wpa_s, dst_addr, cred->realm);
4249 buf = os_malloc(len);
4252 if (hexstr2bin(dst + used, buf, len) < 0) {
4257 ret = hs20_anqp_send_req(wpa_s, dst_addr,
4258 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
4265 #endif /* CONFIG_HS20 */
4268 static int wpa_supplicant_ctrl_iface_sta_autoconnect(
4269 struct wpa_supplicant *wpa_s, char *cmd)
4271 wpa_s->auto_reconnect_disabled = atoi(cmd) == 0 ? 1 : 0;
4276 #ifdef CONFIG_AUTOSCAN
4278 static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant *wpa_s,
4281 enum wpa_states state = wpa_s->wpa_state;
4282 char *new_params = NULL;
4284 if (os_strlen(cmd) > 0) {
4285 new_params = os_strdup(cmd);
4286 if (new_params == NULL)
4290 os_free(wpa_s->conf->autoscan);
4291 wpa_s->conf->autoscan = new_params;
4293 if (wpa_s->conf->autoscan == NULL)
4294 autoscan_deinit(wpa_s);
4295 else if (state == WPA_DISCONNECTED || state == WPA_INACTIVE)
4296 autoscan_init(wpa_s, 1);
4297 else if (state == WPA_SCANNING)
4298 wpa_supplicant_reinit_autoscan(wpa_s);
4303 #endif /* CONFIG_AUTOSCAN */
4306 static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf,
4309 struct wpa_signal_info si;
4312 ret = wpa_drv_signal_poll(wpa_s, &si);
4316 ret = os_snprintf(buf, buflen, "RSSI=%d\nLINKSPEED=%d\n"
4317 "NOISE=%d\nFREQUENCY=%u\n",
4318 si.current_signal, si.current_txrate / 1000,
4319 si.current_noise, si.frequency);
4320 if (ret < 0 || (unsigned int) ret > buflen)
4326 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
4327 char *buf, size_t *resp_len)
4330 const int reply_size = 4096;
4334 if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 ||
4335 os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
4336 wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface",
4337 (const u8 *) buf, os_strlen(buf));
4339 int level = MSG_DEBUG;
4340 if (os_strcmp(buf, "PING") == 0)
4341 level = MSG_EXCESSIVE;
4342 wpa_hexdump_ascii(level, "RX ctrl_iface",
4343 (const u8 *) buf, os_strlen(buf));
4346 reply = os_malloc(reply_size);
4347 if (reply == NULL) {
4352 os_memcpy(reply, "OK\n", 3);
4355 if (os_strcmp(buf, "PING") == 0) {
4356 os_memcpy(reply, "PONG\n", 5);
4358 } else if (os_strcmp(buf, "IFNAME") == 0) {
4359 reply_len = os_strlen(wpa_s->ifname);
4360 os_memcpy(reply, wpa_s->ifname, reply_len);
4361 } else if (os_strncmp(buf, "RELOG", 5) == 0) {
4362 if (wpa_debug_reopen_file() < 0)
4364 } else if (os_strncmp(buf, "NOTE ", 5) == 0) {
4365 wpa_printf(MSG_INFO, "NOTE: %s", buf + 5);
4366 } else if (os_strcmp(buf, "MIB") == 0) {
4367 reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size);
4368 if (reply_len >= 0) {
4370 res = eapol_sm_get_mib(wpa_s->eapol, reply + reply_len,
4371 reply_size - reply_len);
4377 } else if (os_strncmp(buf, "STATUS", 6) == 0) {
4378 reply_len = wpa_supplicant_ctrl_iface_status(
4379 wpa_s, buf + 6, reply, reply_size);
4380 } else if (os_strcmp(buf, "PMKSA") == 0) {
4381 reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, reply,
4383 } else if (os_strncmp(buf, "SET ", 4) == 0) {
4384 if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4))
4386 } else if (os_strncmp(buf, "GET ", 4) == 0) {
4387 reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4,
4389 } else if (os_strcmp(buf, "LOGON") == 0) {
4390 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
4391 } else if (os_strcmp(buf, "LOGOFF") == 0) {
4392 eapol_sm_notify_logoff(wpa_s->eapol, TRUE);
4393 } else if (os_strcmp(buf, "REASSOCIATE") == 0) {
4394 wpa_s->normal_scans = 0;
4395 wpa_supplicant_reinit_autoscan(wpa_s);
4396 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
4399 wpa_s->disconnected = 0;
4400 wpa_s->reassociate = 1;
4401 wpa_supplicant_req_scan(wpa_s, 0, 0);
4403 } else if (os_strcmp(buf, "RECONNECT") == 0) {
4404 wpa_s->normal_scans = 0;
4405 wpa_supplicant_reinit_autoscan(wpa_s);
4406 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
4408 else if (wpa_s->disconnected) {
4409 wpa_s->disconnected = 0;
4410 wpa_s->reassociate = 1;
4411 wpa_supplicant_req_scan(wpa_s, 0, 0);
4413 #ifdef IEEE8021X_EAPOL
4414 } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) {
4415 if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8))
4417 #endif /* IEEE8021X_EAPOL */
4418 #ifdef CONFIG_PEERKEY
4419 } else if (os_strncmp(buf, "STKSTART ", 9) == 0) {
4420 if (wpa_supplicant_ctrl_iface_stkstart(wpa_s, buf + 9))
4422 #endif /* CONFIG_PEERKEY */
4423 #ifdef CONFIG_IEEE80211R
4424 } else if (os_strncmp(buf, "FT_DS ", 6) == 0) {
4425 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6))
4427 #endif /* CONFIG_IEEE80211R */
4429 } else if (os_strcmp(buf, "WPS_PBC") == 0) {
4430 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL);
4432 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
4436 } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) {
4437 int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8);
4439 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
4443 } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {
4444 reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8,
4447 } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) {
4448 reply_len = wpa_supplicant_ctrl_iface_wps_check_pin(
4449 wpa_s, buf + 14, reply, reply_size);
4450 } else if (os_strcmp(buf, "WPS_CANCEL") == 0) {
4451 if (wpas_wps_cancel(wpa_s))
4453 #ifdef CONFIG_WPS_OOB
4454 } else if (os_strncmp(buf, "WPS_OOB ", 8) == 0) {
4455 if (wpa_supplicant_ctrl_iface_wps_oob(wpa_s, buf + 8))
4457 #endif /* CONFIG_WPS_OOB */
4458 #ifdef CONFIG_WPS_NFC
4459 } else if (os_strcmp(buf, "WPS_NFC") == 0) {
4460 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, NULL))
4462 } else if (os_strncmp(buf, "WPS_NFC ", 8) == 0) {
4463 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, buf + 8))
4465 } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) {
4466 reply_len = wpa_supplicant_ctrl_iface_wps_nfc_token(
4467 wpa_s, buf + 14, reply, reply_size);
4468 } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) {
4469 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s,
4472 #endif /* CONFIG_WPS_NFC */
4473 } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) {
4474 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8))
4477 } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) {
4478 reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin(
4479 wpa_s, buf + 11, reply, reply_size);
4480 #endif /* CONFIG_AP */
4481 #ifdef CONFIG_WPS_ER
4482 } else if (os_strcmp(buf, "WPS_ER_START") == 0) {
4483 if (wpas_wps_er_start(wpa_s, NULL))
4485 } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) {
4486 if (wpas_wps_er_start(wpa_s, buf + 13))
4488 } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) {
4489 if (wpas_wps_er_stop(wpa_s))
4491 } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) {
4492 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11))
4494 } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) {
4495 int ret = wpas_wps_er_pbc(wpa_s, buf + 11);
4497 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
4499 } else if (ret == -3) {
4500 os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18);
4502 } else if (ret == -4) {
4503 os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20);
4507 } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) {
4508 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13))
4510 } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) {
4511 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s,
4514 } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) {
4515 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14))
4517 #ifdef CONFIG_WPS_NFC
4518 } else if (os_strncmp(buf, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
4519 reply_len = wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
4520 wpa_s, buf + 24, reply, reply_size);
4521 #endif /* CONFIG_WPS_NFC */
4522 #endif /* CONFIG_WPS_ER */
4523 #endif /* CONFIG_WPS */
4524 #ifdef CONFIG_IBSS_RSN
4525 } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) {
4526 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9))
4528 #endif /* CONFIG_IBSS_RSN */
4530 } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) {
4531 if (p2p_ctrl_find(wpa_s, buf + 9))
4533 } else if (os_strcmp(buf, "P2P_FIND") == 0) {
4534 if (p2p_ctrl_find(wpa_s, ""))
4536 } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) {
4537 wpas_p2p_stop_find(wpa_s);
4538 } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) {
4539 reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply,
4541 } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) {
4542 if (p2p_ctrl_listen(wpa_s, buf + 11))
4544 } else if (os_strcmp(buf, "P2P_LISTEN") == 0) {
4545 if (p2p_ctrl_listen(wpa_s, ""))
4547 } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) {
4548 if (wpas_p2p_group_remove(wpa_s, buf + 17))
4550 } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) {
4551 if (wpas_p2p_group_add(wpa_s, 0, 0, 0))
4553 } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) {
4554 if (p2p_ctrl_group_add(wpa_s, buf + 14))
4556 } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) {
4557 if (p2p_ctrl_prov_disc(wpa_s, buf + 14))
4559 } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) {
4560 reply_len = p2p_get_passphrase(wpa_s, reply, reply_size);
4561 } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) {
4562 reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply,
4564 } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
4565 if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0)
4567 } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) {
4568 if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0)
4570 } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) {
4571 wpas_p2p_sd_service_update(wpa_s);
4572 } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
4573 if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0)
4575 } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) {
4576 wpas_p2p_service_flush(wpa_s);
4577 } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) {
4578 if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0)
4580 } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) {
4581 if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0)
4583 } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) {
4584 if (p2p_ctrl_reject(wpa_s, buf + 11) < 0)
4586 } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) {
4587 if (p2p_ctrl_invite(wpa_s, buf + 11) < 0)
4589 } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) {
4590 reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply,
4592 } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) {
4593 if (p2p_ctrl_set(wpa_s, buf + 8) < 0)
4595 } else if (os_strcmp(buf, "P2P_FLUSH") == 0) {
4596 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
4597 wpa_s->force_long_sd = 0;
4598 if (wpa_s->global->p2p)
4599 p2p_flush(wpa_s->global->p2p);
4600 } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) {
4601 if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0)
4603 } else if (os_strcmp(buf, "P2P_CANCEL") == 0) {
4604 if (wpas_p2p_cancel(wpa_s))
4606 } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) {
4607 if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0)
4609 } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) {
4610 if (p2p_ctrl_presence_req(wpa_s, "") < 0)
4612 } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) {
4613 if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0)
4615 } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) {
4616 if (p2p_ctrl_ext_listen(wpa_s, "") < 0)
4618 #endif /* CONFIG_P2P */
4619 #ifdef CONFIG_WIFI_DISPLAY
4620 } else if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0) {
4621 if (wifi_display_subelem_set(wpa_s->global, buf + 16) < 0)
4623 } else if (os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) {
4624 reply_len = wifi_display_subelem_get(wpa_s->global, buf + 16,
4626 #endif /* CONFIG_WIFI_DISPLAY */
4627 #ifdef CONFIG_INTERWORKING
4628 } else if (os_strcmp(buf, "FETCH_ANQP") == 0) {
4629 if (interworking_fetch_anqp(wpa_s) < 0)
4631 } else if (os_strcmp(buf, "STOP_FETCH_ANQP") == 0) {
4632 interworking_stop_fetch_anqp(wpa_s);
4633 } else if (os_strncmp(buf, "INTERWORKING_SELECT", 19) == 0) {
4634 if (interworking_select(wpa_s, os_strstr(buf + 19, "auto") !=
4637 } else if (os_strncmp(buf, "INTERWORKING_CONNECT ", 21) == 0) {
4638 if (ctrl_interworking_connect(wpa_s, buf + 21) < 0)
4640 } else if (os_strncmp(buf, "ANQP_GET ", 9) == 0) {
4641 if (get_anqp(wpa_s, buf + 9) < 0)
4643 } else if (os_strncmp(buf, "GAS_REQUEST ", 12) == 0) {
4644 if (gas_request(wpa_s, buf + 12) < 0)
4646 } else if (os_strncmp(buf, "GAS_RESPONSE_GET ", 17) == 0) {
4647 reply_len = gas_response_get(wpa_s, buf + 17, reply,
4649 #endif /* CONFIG_INTERWORKING */
4651 } else if (os_strncmp(buf, "HS20_ANQP_GET ", 14) == 0) {
4652 if (get_hs20_anqp(wpa_s, buf + 14) < 0)
4654 } else if (os_strncmp(buf, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
4655 if (hs20_get_nai_home_realm_list(wpa_s, buf + 29) < 0)
4657 #endif /* CONFIG_HS20 */
4658 } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0)
4660 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
4661 wpa_s, buf + os_strlen(WPA_CTRL_RSP)))
4665 } else if (os_strcmp(buf, "RECONFIGURE") == 0) {
4666 if (wpa_supplicant_reload_configuration(wpa_s))
4668 } else if (os_strcmp(buf, "TERMINATE") == 0) {
4669 wpa_supplicant_terminate_proc(wpa_s->global);
4670 } else if (os_strncmp(buf, "BSSID ", 6) == 0) {
4671 if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6))
4673 } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) {
4674 reply_len = wpa_supplicant_ctrl_iface_blacklist(
4675 wpa_s, buf + 9, reply, reply_size);
4676 } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) {
4677 reply_len = wpa_supplicant_ctrl_iface_log_level(
4678 wpa_s, buf + 9, reply, reply_size);
4679 } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) {
4680 reply_len = wpa_supplicant_ctrl_iface_list_networks(
4681 wpa_s, reply, reply_size);
4682 } else if (os_strcmp(buf, "DISCONNECT") == 0) {
4684 wpa_s->sme.prev_bssid_set = 0;
4685 #endif /* CONFIG_SME */
4686 wpa_s->reassociate = 0;
4687 wpa_s->disconnected = 1;
4688 wpa_supplicant_cancel_sched_scan(wpa_s);
4689 wpa_supplicant_cancel_scan(wpa_s);
4690 wpa_supplicant_deauthenticate(wpa_s,
4691 WLAN_REASON_DEAUTH_LEAVING);
4692 } else if (os_strcmp(buf, "SCAN") == 0) {
4693 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
4696 if (!wpa_s->scanning &&
4697 ((wpa_s->wpa_state <= WPA_SCANNING) ||
4698 (wpa_s->wpa_state == WPA_COMPLETED))) {
4699 wpa_s->normal_scans = 0;
4700 wpa_s->scan_req = 2;
4701 wpa_supplicant_req_scan(wpa_s, 0, 0);
4702 } else if (wpa_s->sched_scanning) {
4703 wpa_printf(MSG_DEBUG, "Stop ongoing "
4704 "sched_scan to allow requested "
4705 "full scan to proceed");
4706 wpa_supplicant_cancel_sched_scan(wpa_s);
4707 wpa_s->scan_req = 2;
4708 wpa_supplicant_req_scan(wpa_s, 0, 0);
4710 wpa_printf(MSG_DEBUG, "Ongoing scan action - "
4711 "reject new request");
4712 reply_len = os_snprintf(reply, reply_size,
4716 } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) {
4717 reply_len = wpa_supplicant_ctrl_iface_scan_results(
4718 wpa_s, reply, reply_size);
4719 } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) {
4720 if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15))
4722 } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) {
4723 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15))
4725 } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) {
4726 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16))
4728 } else if (os_strcmp(buf, "ADD_NETWORK") == 0) {
4729 reply_len = wpa_supplicant_ctrl_iface_add_network(
4730 wpa_s, reply, reply_size);
4731 } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) {
4732 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15))
4734 } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
4735 if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12))
4737 } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) {
4738 reply_len = wpa_supplicant_ctrl_iface_get_network(
4739 wpa_s, buf + 12, reply, reply_size);
4740 } else if (os_strcmp(buf, "LIST_CREDS") == 0) {
4741 reply_len = wpa_supplicant_ctrl_iface_list_creds(
4742 wpa_s, reply, reply_size);
4743 } else if (os_strcmp(buf, "ADD_CRED") == 0) {
4744 reply_len = wpa_supplicant_ctrl_iface_add_cred(
4745 wpa_s, reply, reply_size);
4746 } else if (os_strncmp(buf, "REMOVE_CRED ", 12) == 0) {
4747 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s, buf + 12))
4749 } else if (os_strncmp(buf, "SET_CRED ", 9) == 0) {
4750 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s, buf + 9))
4752 #ifndef CONFIG_NO_CONFIG_WRITE
4753 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
4754 if (wpa_supplicant_ctrl_iface_save_config(wpa_s))
4756 #endif /* CONFIG_NO_CONFIG_WRITE */
4757 } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
4758 reply_len = wpa_supplicant_ctrl_iface_get_capability(
4759 wpa_s, buf + 15, reply, reply_size);
4760 } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) {
4761 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8))
4763 } else if (os_strncmp(buf, "SCAN_INTERVAL ", 14) == 0) {
4764 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s, buf + 14))
4766 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
4767 reply_len = wpa_supplicant_global_iface_list(
4768 wpa_s->global, reply, reply_size);
4769 } else if (os_strcmp(buf, "INTERFACES") == 0) {
4770 reply_len = wpa_supplicant_global_iface_interfaces(
4771 wpa_s->global, reply, reply_size);
4772 } else if (os_strncmp(buf, "BSS ", 4) == 0) {
4773 reply_len = wpa_supplicant_ctrl_iface_bss(
4774 wpa_s, buf + 4, reply, reply_size);
4776 } else if (os_strcmp(buf, "STA-FIRST") == 0) {
4777 reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size);
4778 } else if (os_strncmp(buf, "STA ", 4) == 0) {
4779 reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply,
4781 } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) {
4782 reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply,
4784 } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) {
4785 if (ap_ctrl_iface_sta_deauthenticate(wpa_s, buf + 15))
4787 } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) {
4788 if (ap_ctrl_iface_sta_disassociate(wpa_s, buf + 13))
4790 #endif /* CONFIG_AP */
4791 } else if (os_strcmp(buf, "SUSPEND") == 0) {
4792 wpas_notify_suspend(wpa_s->global);
4793 } else if (os_strcmp(buf, "RESUME") == 0) {
4794 wpas_notify_resume(wpa_s->global);
4795 } else if (os_strcmp(buf, "DROP_SA") == 0) {
4796 wpa_supplicant_ctrl_iface_drop_sa(wpa_s);
4797 } else if (os_strncmp(buf, "ROAM ", 5) == 0) {
4798 if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5))
4800 } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) {
4801 if (wpa_supplicant_ctrl_iface_sta_autoconnect(wpa_s, buf + 16))
4803 } else if (os_strncmp(buf, "BSS_EXPIRE_AGE ", 15) == 0) {
4804 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s, buf + 15))
4806 } else if (os_strncmp(buf, "BSS_EXPIRE_COUNT ", 17) == 0) {
4807 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s,
4810 } else if (os_strncmp(buf, "BSS_FLUSH ", 10) == 0) {
4811 if (wpa_supplicant_ctrl_iface_bss_flush(wpa_s, buf + 10))
4814 } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) {
4815 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14))
4817 } else if (os_strncmp(buf, "TDLS_SETUP ", 11) == 0) {
4818 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s, buf + 11))
4820 } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) {
4821 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14))
4823 #endif /* CONFIG_TDLS */
4824 } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) {
4825 reply_len = wpa_supplicant_signal_poll(wpa_s, reply,
4827 #ifdef CONFIG_AUTOSCAN
4828 } else if (os_strncmp(buf, "AUTOSCAN ", 9) == 0) {
4829 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s, buf + 9))
4831 #endif /* CONFIG_AUTOSCAN */
4832 } else if (os_strcmp(buf, "REAUTHENTICATE") == 0) {
4833 eapol_sm_request_reauth(wpa_s->eapol);
4835 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
4839 if (reply_len < 0) {
4840 os_memcpy(reply, "FAIL\n", 5);
4845 eapol_sm_notify_ctrl_response(wpa_s->eapol);
4847 *resp_len = reply_len;
4852 static int wpa_supplicant_global_iface_add(struct wpa_global *global,
4855 struct wpa_interface iface;
4859 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
4860 * TAB<bridge_ifname>
4862 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd);
4864 os_memset(&iface, 0, sizeof(iface));
4867 iface.ifname = pos = cmd;
4868 pos = os_strchr(pos, '\t');
4871 if (iface.ifname[0] == '\0')
4876 iface.confname = pos;
4877 pos = os_strchr(pos, '\t');
4880 if (iface.confname[0] == '\0')
4881 iface.confname = NULL;
4886 pos = os_strchr(pos, '\t');
4889 if (iface.driver[0] == '\0')
4890 iface.driver = NULL;
4894 iface.ctrl_interface = pos;
4895 pos = os_strchr(pos, '\t');
4898 if (iface.ctrl_interface[0] == '\0')
4899 iface.ctrl_interface = NULL;
4903 iface.driver_param = pos;
4904 pos = os_strchr(pos, '\t');
4907 if (iface.driver_param[0] == '\0')
4908 iface.driver_param = NULL;
4912 iface.bridge_ifname = pos;
4913 pos = os_strchr(pos, '\t');
4916 if (iface.bridge_ifname[0] == '\0')
4917 iface.bridge_ifname = NULL;
4922 if (wpa_supplicant_get_iface(global, iface.ifname))
4925 return wpa_supplicant_add_iface(global, &iface) ? 0 : -1;
4929 static int wpa_supplicant_global_iface_remove(struct wpa_global *global,
4932 struct wpa_supplicant *wpa_s;
4934 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd);
4936 wpa_s = wpa_supplicant_get_iface(global, cmd);
4939 return wpa_supplicant_remove_iface(global, wpa_s, 0);
4943 static void wpa_free_iface_info(struct wpa_interface_info *iface)
4945 struct wpa_interface_info *prev;
4949 iface = iface->next;
4951 os_free(prev->ifname);
4952 os_free(prev->desc);
4958 static int wpa_supplicant_global_iface_list(struct wpa_global *global,
4962 struct wpa_interface_info *iface = NULL, *last = NULL, *tmp;
4965 for (i = 0; wpa_drivers[i]; i++) {
4966 struct wpa_driver_ops *drv = wpa_drivers[i];
4967 if (drv->get_interfaces == NULL)
4969 tmp = drv->get_interfaces(global->drv_priv[i]);
4983 for (tmp = iface; tmp; tmp = tmp->next) {
4984 res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n",
4985 tmp->drv_name, tmp->ifname,
4986 tmp->desc ? tmp->desc : "");
4987 if (res < 0 || res >= end - pos) {
4994 wpa_free_iface_info(iface);
5000 static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
5005 struct wpa_supplicant *wpa_s;
5007 wpa_s = global->ifaces;
5012 res = os_snprintf(pos, end - pos, "%s\n", wpa_s->ifname);
5013 if (res < 0 || res >= end - pos) {
5018 wpa_s = wpa_s->next;
5024 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
5025 char *buf, size_t *resp_len)
5028 const int reply_size = 2048;
5030 int level = MSG_DEBUG;
5032 if (os_strcmp(buf, "PING") == 0)
5033 level = MSG_EXCESSIVE;
5034 wpa_hexdump_ascii(level, "RX global ctrl_iface",
5035 (const u8 *) buf, os_strlen(buf));
5037 reply = os_malloc(reply_size);
5038 if (reply == NULL) {
5043 os_memcpy(reply, "OK\n", 3);
5046 if (os_strcmp(buf, "PING") == 0) {
5047 os_memcpy(reply, "PONG\n", 5);
5049 } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) {
5050 if (wpa_supplicant_global_iface_add(global, buf + 14))
5052 } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) {
5053 if (wpa_supplicant_global_iface_remove(global, buf + 17))
5055 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
5056 reply_len = wpa_supplicant_global_iface_list(
5057 global, reply, reply_size);
5058 } else if (os_strcmp(buf, "INTERFACES") == 0) {
5059 reply_len = wpa_supplicant_global_iface_interfaces(
5060 global, reply, reply_size);
5061 } else if (os_strcmp(buf, "TERMINATE") == 0) {
5062 wpa_supplicant_terminate_proc(global);
5063 } else if (os_strcmp(buf, "SUSPEND") == 0) {
5064 wpas_notify_suspend(global);
5065 } else if (os_strcmp(buf, "RESUME") == 0) {
5066 wpas_notify_resume(global);
5068 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
5072 if (reply_len < 0) {
5073 os_memcpy(reply, "FAIL\n", 5);
5077 *resp_len = reply_len;