2 * WPA Supplicant / Control interface (shared code for all backends)
3 * Copyright (c) 2004-2010, Jouni Malinen <j@w1.fi>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
15 #include "utils/includes.h"
17 #include "utils/common.h"
18 #include "utils/eloop.h"
19 #include "common/version.h"
20 #include "common/ieee802_11_defs.h"
21 #include "common/wpa_ctrl.h"
22 #include "eap_peer/eap.h"
23 #include "eapol_supp/eapol_supp_sm.h"
24 #include "rsn_supp/wpa.h"
25 #include "rsn_supp/preauth.h"
26 #include "rsn_supp/pmksa_cache.h"
27 #include "l2_packet/l2_packet.h"
30 #include "wpa_supplicant_i.h"
32 #include "wps_supplicant.h"
35 #include "p2p_supplicant.h"
40 #include "ctrl_iface.h"
42 extern struct wpa_driver_ops *wpa_drivers[];
44 static int wpa_supplicant_global_iface_list(struct wpa_global *global,
46 static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
50 static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s,
56 value = os_strchr(cmd, ' ');
61 wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value);
62 if (os_strcasecmp(cmd, "EAPOL::heldPeriod") == 0) {
63 eapol_sm_configure(wpa_s->eapol,
64 atoi(value), -1, -1, -1);
65 } else if (os_strcasecmp(cmd, "EAPOL::authPeriod") == 0) {
66 eapol_sm_configure(wpa_s->eapol,
67 -1, atoi(value), -1, -1);
68 } else if (os_strcasecmp(cmd, "EAPOL::startPeriod") == 0) {
69 eapol_sm_configure(wpa_s->eapol,
70 -1, -1, atoi(value), -1);
71 } else if (os_strcasecmp(cmd, "EAPOL::maxStart") == 0) {
72 eapol_sm_configure(wpa_s->eapol,
73 -1, -1, -1, atoi(value));
74 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKLifetime") == 0) {
75 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME,
78 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKReauthThreshold") ==
80 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD,
83 } else if (os_strcasecmp(cmd, "dot11RSNAConfigSATimeout") == 0) {
84 if (wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, atoi(value)))
86 } else if (os_strcasecmp(cmd, "wps_fragment_size") == 0) {
87 wpa_s->wps_fragment_size = atoi(value);
88 #ifdef CONFIG_WPS_TESTING
89 } else if (os_strcasecmp(cmd, "wps_version_number") == 0) {
91 val = strtol(value, NULL, 0);
92 if (val < 0 || val > 0xff) {
94 wpa_printf(MSG_DEBUG, "WPS: Invalid "
95 "wps_version_number %ld", val);
97 wps_version_number = val;
98 wpa_printf(MSG_DEBUG, "WPS: Testing - force WPS "
100 (wps_version_number & 0xf0) >> 4,
101 wps_version_number & 0x0f);
103 } else if (os_strcasecmp(cmd, "wps_testing_dummy_cred") == 0) {
104 wps_testing_dummy_cred = atoi(value);
105 wpa_printf(MSG_DEBUG, "WPS: Testing - dummy_cred=%d",
106 wps_testing_dummy_cred);
107 #endif /* CONFIG_WPS_TESTING */
108 } else if (os_strcasecmp(cmd, "ampdu") == 0) {
109 if (wpa_drv_ampdu(wpa_s, atoi(value)) < 0)
113 ret = wpa_config_process_global(wpa_s->conf, cmd, -1);
115 wpa_supplicant_update_config(wpa_s);
122 static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s,
123 char *cmd, char *buf, size_t buflen)
127 wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd);
129 if (os_strcmp(cmd, "version") == 0) {
130 res = os_snprintf(buf, buflen, "%s", VERSION_STR);
131 if (res < 0 || (unsigned int) res >= buflen)
140 #ifdef IEEE8021X_EAPOL
141 static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s,
145 struct wpa_ssid *ssid = wpa_s->current_ssid;
147 if (hwaddr_aton(addr, bssid)) {
148 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address "
153 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid));
154 rsn_preauth_deinit(wpa_s->wpa);
155 if (rsn_preauth_init(wpa_s->wpa, bssid, ssid ? &ssid->eap : NULL))
160 #endif /* IEEE8021X_EAPOL */
163 #ifdef CONFIG_PEERKEY
164 /* MLME-STKSTART.request(peer) */
165 static int wpa_supplicant_ctrl_iface_stkstart(
166 struct wpa_supplicant *wpa_s, char *addr)
170 if (hwaddr_aton(addr, peer)) {
171 wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART: invalid "
172 "address '%s'", addr);
176 wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART " MACSTR,
179 return wpa_sm_stkstart(wpa_s->wpa, peer);
181 #endif /* CONFIG_PEERKEY */
184 #ifdef CONFIG_IEEE80211R
185 static int wpa_supplicant_ctrl_iface_ft_ds(
186 struct wpa_supplicant *wpa_s, char *addr)
188 u8 target_ap[ETH_ALEN];
192 if (hwaddr_aton(addr, target_ap)) {
193 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid "
194 "address '%s'", addr);
198 wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap));
200 bss = wpa_bss_get_bssid(wpa_s, target_ap);
202 mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN);
206 return wpa_ft_start_over_ds(wpa_s->wpa, target_ap, mdie);
208 #endif /* CONFIG_IEEE80211R */
212 static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s,
215 u8 bssid[ETH_ALEN], *_bssid = bssid;
217 if (cmd == NULL || os_strcmp(cmd, "any") == 0)
219 else if (hwaddr_aton(cmd, bssid)) {
220 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
227 return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid);
228 #endif /* CONFIG_AP */
230 return wpas_wps_start_pbc(wpa_s, _bssid, 0);
234 static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s,
235 char *cmd, char *buf,
238 u8 bssid[ETH_ALEN], *_bssid = bssid;
242 pin = os_strchr(cmd, ' ');
246 if (os_strcmp(cmd, "any") == 0)
248 else if (hwaddr_aton(cmd, bssid)) {
249 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
256 return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin,
258 #endif /* CONFIG_AP */
261 ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0,
265 ret = os_snprintf(buf, buflen, "%s", pin);
266 if (ret < 0 || (size_t) ret >= buflen)
271 ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0, DEV_PW_DEFAULT);
275 /* Return the generated PIN */
276 ret = os_snprintf(buf, buflen, "%08d", ret);
277 if (ret < 0 || (size_t) ret >= buflen)
283 static int wpa_supplicant_ctrl_iface_wps_check_pin(
284 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
291 wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN",
292 (u8 *) cmd, os_strlen(cmd));
293 for (pos = cmd, len = 0; *pos != '\0'; pos++) {
294 if (*pos < '0' || *pos > '9')
298 wpa_printf(MSG_DEBUG, "WPS: Too long PIN");
302 if (len != 4 && len != 8) {
303 wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len);
309 unsigned int pin_val;
311 if (!wps_pin_valid(pin_val)) {
312 wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit");
313 ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n");
314 if (ret < 0 || (size_t) ret >= buflen)
320 ret = os_snprintf(buf, buflen, "%s", pin);
321 if (ret < 0 || (size_t) ret >= buflen)
328 #ifdef CONFIG_WPS_OOB
329 static int wpa_supplicant_ctrl_iface_wps_oob(struct wpa_supplicant *wpa_s,
332 char *path, *method, *name;
334 path = os_strchr(cmd, ' ');
339 method = os_strchr(path, ' ');
344 name = os_strchr(method, ' ');
348 return wpas_wps_start_oob(wpa_s, cmd, path, method, name);
350 #endif /* CONFIG_WPS_OOB */
353 static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s,
362 struct wps_new_ap_settings ap;
364 pin = os_strchr(cmd, ' ');
369 if (hwaddr_aton(cmd, bssid)) {
370 wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
375 new_ssid = os_strchr(pin, ' ');
376 if (new_ssid == NULL)
377 return wpas_wps_start_reg(wpa_s, bssid, pin, NULL);
380 new_auth = os_strchr(new_ssid, ' ');
381 if (new_auth == NULL)
385 new_encr = os_strchr(new_auth, ' ');
386 if (new_encr == NULL)
390 new_key = os_strchr(new_encr, ' ');
395 os_memset(&ap, 0, sizeof(ap));
396 ap.ssid_hex = new_ssid;
399 ap.key_hex = new_key;
400 return wpas_wps_start_reg(wpa_s, bssid, pin, &ap);
405 static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant *wpa_s,
406 char *cmd, char *buf,
413 if (!wpa_s->ap_iface)
416 pos = os_strchr(cmd, ' ');
420 if (os_strcmp(cmd, "disable") == 0) {
421 wpas_wps_ap_pin_disable(wpa_s);
422 return os_snprintf(buf, buflen, "OK\n");
425 if (os_strcmp(cmd, "random") == 0) {
428 pin_txt = wpas_wps_ap_pin_random(wpa_s, timeout);
431 return os_snprintf(buf, buflen, "%s", pin_txt);
434 if (os_strcmp(cmd, "get") == 0) {
435 pin_txt = wpas_wps_ap_pin_get(wpa_s);
438 return os_snprintf(buf, buflen, "%s", pin_txt);
441 if (os_strcmp(cmd, "set") == 0) {
446 pos = os_strchr(pos, ' ');
451 if (os_strlen(pin) > buflen)
453 if (wpas_wps_ap_pin_set(wpa_s, pin, timeout) < 0)
455 return os_snprintf(buf, buflen, "%s", pin);
460 #endif /* CONFIG_AP */
464 static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant *wpa_s,
467 char *uuid = cmd, *pin, *pos;
468 u8 addr_buf[ETH_ALEN], *addr = NULL;
469 pin = os_strchr(uuid, ' ');
473 pos = os_strchr(pin, ' ');
476 if (hwaddr_aton(pos, addr_buf) == 0)
479 return wpas_wps_er_add_pin(wpa_s, addr, uuid, pin);
483 static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant *wpa_s,
486 char *uuid = cmd, *pin;
487 pin = os_strchr(uuid, ' ');
491 return wpas_wps_er_learn(wpa_s, uuid, pin);
495 static int wpa_supplicant_ctrl_iface_wps_er_set_config(
496 struct wpa_supplicant *wpa_s, char *cmd)
498 char *uuid = cmd, *id;
499 id = os_strchr(uuid, ' ');
503 return wpas_wps_er_set_config(wpa_s, uuid, atoi(id));
507 static int wpa_supplicant_ctrl_iface_wps_er_config(
508 struct wpa_supplicant *wpa_s, char *cmd)
515 struct wps_new_ap_settings ap;
517 pin = os_strchr(cmd, ' ');
522 new_ssid = os_strchr(pin, ' ');
523 if (new_ssid == NULL)
527 new_auth = os_strchr(new_ssid, ' ');
528 if (new_auth == NULL)
532 new_encr = os_strchr(new_auth, ' ');
533 if (new_encr == NULL)
537 new_key = os_strchr(new_encr, ' ');
542 os_memset(&ap, 0, sizeof(ap));
543 ap.ssid_hex = new_ssid;
546 ap.key_hex = new_key;
547 return wpas_wps_er_config(wpa_s, cmd, pin, &ap);
549 #endif /* CONFIG_WPS_ER */
551 #endif /* CONFIG_WPS */
554 #ifdef CONFIG_IBSS_RSN
555 static int wpa_supplicant_ctrl_iface_ibss_rsn(
556 struct wpa_supplicant *wpa_s, char *addr)
560 if (hwaddr_aton(addr, peer)) {
561 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN: invalid "
562 "address '%s'", addr);
566 wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN " MACSTR,
569 return ibss_rsn_start(wpa_s->ibss_rsn, peer);
571 #endif /* CONFIG_IBSS_RSN */
574 static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s,
577 #ifdef IEEE8021X_EAPOL
580 struct wpa_ssid *ssid;
581 struct eap_peer_config *eap;
583 pos = os_strchr(rsp, '-');
588 pos = os_strchr(pos, ':');
593 wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id);
594 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
595 (u8 *) pos, os_strlen(pos));
597 ssid = wpa_config_get_network(wpa_s->conf, id);
599 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
605 if (os_strcmp(rsp, "IDENTITY") == 0) {
606 os_free(eap->identity);
607 eap->identity = (u8 *) os_strdup(pos);
608 eap->identity_len = os_strlen(pos);
609 eap->pending_req_identity = 0;
610 if (ssid == wpa_s->current_ssid)
611 wpa_s->reassociate = 1;
612 } else if (os_strcmp(rsp, "PASSWORD") == 0) {
613 os_free(eap->password);
614 eap->password = (u8 *) os_strdup(pos);
615 eap->password_len = os_strlen(pos);
616 eap->pending_req_password = 0;
617 if (ssid == wpa_s->current_ssid)
618 wpa_s->reassociate = 1;
619 } else if (os_strcmp(rsp, "NEW_PASSWORD") == 0) {
620 os_free(eap->new_password);
621 eap->new_password = (u8 *) os_strdup(pos);
622 eap->new_password_len = os_strlen(pos);
623 eap->pending_req_new_password = 0;
624 if (ssid == wpa_s->current_ssid)
625 wpa_s->reassociate = 1;
626 } else if (os_strcmp(rsp, "PIN") == 0) {
628 eap->pin = os_strdup(pos);
629 eap->pending_req_pin = 0;
630 if (ssid == wpa_s->current_ssid)
631 wpa_s->reassociate = 1;
632 } else if (os_strcmp(rsp, "OTP") == 0) {
634 eap->otp = (u8 *) os_strdup(pos);
635 eap->otp_len = os_strlen(pos);
636 os_free(eap->pending_req_otp);
637 eap->pending_req_otp = NULL;
638 eap->pending_req_otp_len = 0;
639 } else if (os_strcmp(rsp, "PASSPHRASE") == 0) {
640 os_free(eap->private_key_passwd);
641 eap->private_key_passwd = (u8 *) os_strdup(pos);
642 eap->pending_req_passphrase = 0;
643 if (ssid == wpa_s->current_ssid)
644 wpa_s->reassociate = 1;
646 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown field '%s'", rsp);
651 #else /* IEEE8021X_EAPOL */
652 wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included");
654 #endif /* IEEE8021X_EAPOL */
658 static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
660 char *buf, size_t buflen)
662 char *pos, *end, tmp[30];
663 int res, verbose, ret;
665 verbose = os_strcmp(params, "-VERBOSE") == 0;
668 if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
669 struct wpa_ssid *ssid = wpa_s->current_ssid;
670 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
671 MAC2STR(wpa_s->bssid));
672 if (ret < 0 || ret >= end - pos)
676 u8 *_ssid = ssid->ssid;
677 size_t ssid_len = ssid->ssid_len;
678 u8 ssid_buf[MAX_SSID_LEN];
680 int _res = wpa_drv_get_ssid(wpa_s, ssid_buf);
687 ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n",
688 wpa_ssid_txt(_ssid, ssid_len),
690 if (ret < 0 || ret >= end - pos)
695 ret = os_snprintf(pos, end - pos,
698 if (ret < 0 || ret >= end - pos)
703 switch (ssid->mode) {
704 case WPAS_MODE_INFRA:
705 ret = os_snprintf(pos, end - pos,
709 ret = os_snprintf(pos, end - pos,
713 ret = os_snprintf(pos, end - pos,
716 case WPAS_MODE_P2P_GO:
717 ret = os_snprintf(pos, end - pos,
720 case WPAS_MODE_P2P_GROUP_FORMATION:
721 ret = os_snprintf(pos, end - pos,
722 "mode=P2P GO - group "
729 if (ret < 0 || ret >= end - pos)
735 if (wpa_s->ap_iface) {
736 pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos,
740 #endif /* CONFIG_AP */
741 pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose);
743 ret = os_snprintf(pos, end - pos, "wpa_state=%s\n",
744 wpa_supplicant_state_txt(wpa_s->wpa_state));
745 if (ret < 0 || ret >= end - pos)
750 l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) {
751 ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp);
752 if (ret < 0 || ret >= end - pos)
758 if (wpa_s->global->p2p) {
759 ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
760 "\n", MAC2STR(wpa_s->global->p2p_dev_addr));
761 if (ret < 0 || ret >= end - pos)
765 #endif /* CONFIG_P2P */
767 ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n",
768 MAC2STR(wpa_s->own_addr));
769 if (ret < 0 || ret >= end - pos)
773 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
774 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
775 res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos,
781 res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose);
789 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s,
794 struct wpa_ssid *ssid;
797 /* cmd: "<network id> <BSSID>" */
798 pos = os_strchr(cmd, ' ');
803 wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos);
804 if (hwaddr_aton(pos, bssid)) {
805 wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos);
809 ssid = wpa_config_get_network(wpa_s->conf, id);
811 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
816 os_memcpy(ssid->bssid, bssid, ETH_ALEN);
817 ssid->bssid_set = !is_zero_ether_addr(bssid);
823 static int wpa_supplicant_ctrl_iface_list_networks(
824 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
827 struct wpa_ssid *ssid;
832 ret = os_snprintf(pos, end - pos,
833 "network id / ssid / bssid / flags\n");
834 if (ret < 0 || ret >= end - pos)
838 ssid = wpa_s->conf->ssid;
840 ret = os_snprintf(pos, end - pos, "%d\t%s",
842 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
843 if (ret < 0 || ret >= end - pos)
846 if (ssid->bssid_set) {
847 ret = os_snprintf(pos, end - pos, "\t" MACSTR,
848 MAC2STR(ssid->bssid));
850 ret = os_snprintf(pos, end - pos, "\tany");
852 if (ret < 0 || ret >= end - pos)
855 ret = os_snprintf(pos, end - pos, "\t%s%s%s",
856 ssid == wpa_s->current_ssid ?
858 ssid->disabled ? "[DISABLED]" : "",
859 ssid->disabled == 2 ? "[P2P-PERSISTENT]" :
861 if (ret < 0 || ret >= end - pos)
864 ret = os_snprintf(pos, end - pos, "\n");
865 if (ret < 0 || ret >= end - pos)
876 static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher)
879 ret = os_snprintf(pos, end - pos, "-");
880 if (ret < 0 || ret >= end - pos)
883 if (cipher & WPA_CIPHER_NONE) {
884 ret = os_snprintf(pos, end - pos, "%sNONE", first ? "" : "+");
885 if (ret < 0 || ret >= end - pos)
890 if (cipher & WPA_CIPHER_WEP40) {
891 ret = os_snprintf(pos, end - pos, "%sWEP40", first ? "" : "+");
892 if (ret < 0 || ret >= end - pos)
897 if (cipher & WPA_CIPHER_WEP104) {
898 ret = os_snprintf(pos, end - pos, "%sWEP104",
900 if (ret < 0 || ret >= end - pos)
905 if (cipher & WPA_CIPHER_TKIP) {
906 ret = os_snprintf(pos, end - pos, "%sTKIP", first ? "" : "+");
907 if (ret < 0 || ret >= end - pos)
912 if (cipher & WPA_CIPHER_CCMP) {
913 ret = os_snprintf(pos, end - pos, "%sCCMP", first ? "" : "+");
914 if (ret < 0 || ret >= end - pos)
923 static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
924 const u8 *ie, size_t ie_len)
926 struct wpa_ie_data data;
929 ret = os_snprintf(pos, end - pos, "[%s-", proto);
930 if (ret < 0 || ret >= end - pos)
934 if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) {
935 ret = os_snprintf(pos, end - pos, "?]");
936 if (ret < 0 || ret >= end - pos)
943 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
944 ret = os_snprintf(pos, end - pos, "%sEAP", first ? "" : "+");
945 if (ret < 0 || ret >= end - pos)
950 if (data.key_mgmt & WPA_KEY_MGMT_PSK) {
951 ret = os_snprintf(pos, end - pos, "%sPSK", first ? "" : "+");
952 if (ret < 0 || ret >= end - pos)
957 if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
958 ret = os_snprintf(pos, end - pos, "%sNone", first ? "" : "+");
959 if (ret < 0 || ret >= end - pos)
964 #ifdef CONFIG_IEEE80211R
965 if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
966 ret = os_snprintf(pos, end - pos, "%sFT/EAP",
968 if (ret < 0 || ret >= end - pos)
973 if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) {
974 ret = os_snprintf(pos, end - pos, "%sFT/PSK",
976 if (ret < 0 || ret >= end - pos)
981 #endif /* CONFIG_IEEE80211R */
982 #ifdef CONFIG_IEEE80211W
983 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
984 ret = os_snprintf(pos, end - pos, "%sEAP-SHA256",
986 if (ret < 0 || ret >= end - pos)
991 if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
992 ret = os_snprintf(pos, end - pos, "%sPSK-SHA256",
994 if (ret < 0 || ret >= end - pos)
999 #endif /* CONFIG_IEEE80211W */
1001 pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher);
1003 if (data.capabilities & WPA_CAPABILITY_PREAUTH) {
1004 ret = os_snprintf(pos, end - pos, "-preauth");
1005 if (ret < 0 || ret >= end - pos)
1010 ret = os_snprintf(pos, end - pos, "]");
1011 if (ret < 0 || ret >= end - pos)
1020 static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s,
1021 char *pos, char *end,
1022 struct wpabuf *wps_ie)
1029 if (wps_is_selected_pbc_registrar(wps_ie))
1032 else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0))
1034 #endif /* CONFIG_WPS2 */
1035 else if (wps_is_selected_pin_registrar(wps_ie))
1040 ret = os_snprintf(pos, end - pos, "%s", txt);
1041 if (ret >= 0 && ret < end - pos)
1043 wpabuf_free(wps_ie);
1046 #endif /* CONFIG_WPS */
1049 static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s,
1050 char *pos, char *end,
1051 const struct wpa_bss *bss)
1054 struct wpabuf *wps_ie;
1055 wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
1056 return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie);
1057 #else /* CONFIG_WPS */
1059 #endif /* CONFIG_WPS */
1063 /* Format one result on one text line into a buffer. */
1064 static int wpa_supplicant_ctrl_iface_scan_result(
1065 struct wpa_supplicant *wpa_s,
1066 const struct wpa_bss *bss, char *buf, size_t buflen)
1070 const u8 *ie, *ie2, *p2p;
1072 p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
1073 if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN &&
1074 os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) ==
1076 return 0; /* Do not show P2P listen discovery results here */
1081 ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t",
1082 MAC2STR(bss->bssid), bss->freq, bss->level);
1083 if (ret < 0 || ret >= end - pos)
1086 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
1088 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]);
1089 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
1091 pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2, 2 + ie2[1]);
1092 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
1093 if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
1094 ret = os_snprintf(pos, end - pos, "[WEP]");
1095 if (ret < 0 || ret >= end - pos)
1099 if (bss->caps & IEEE80211_CAP_IBSS) {
1100 ret = os_snprintf(pos, end - pos, "[IBSS]");
1101 if (ret < 0 || ret >= end - pos)
1105 if (bss->caps & IEEE80211_CAP_ESS) {
1106 ret = os_snprintf(pos, end - pos, "[ESS]");
1107 if (ret < 0 || ret >= end - pos)
1112 ret = os_snprintf(pos, end - pos, "[P2P]");
1113 if (ret < 0 || ret >= end - pos)
1118 ret = os_snprintf(pos, end - pos, "\t%s",
1119 wpa_ssid_txt(bss->ssid, bss->ssid_len));
1120 if (ret < 0 || ret >= end - pos)
1124 ret = os_snprintf(pos, end - pos, "\n");
1125 if (ret < 0 || ret >= end - pos)
1133 static int wpa_supplicant_ctrl_iface_scan_results(
1134 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
1137 struct wpa_bss *bss;
1142 ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / "
1144 if (ret < 0 || ret >= end - pos)
1148 dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
1149 ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos,
1151 if (ret < 0 || ret >= end - pos)
1160 static int wpa_supplicant_ctrl_iface_select_network(
1161 struct wpa_supplicant *wpa_s, char *cmd)
1164 struct wpa_ssid *ssid;
1166 /* cmd: "<network id>" or "any" */
1167 if (os_strcmp(cmd, "any") == 0) {
1168 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any");
1172 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id);
1174 ssid = wpa_config_get_network(wpa_s->conf, id);
1176 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
1177 "network id=%d", id);
1180 if (ssid->disabled == 2) {
1181 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
1182 "SELECT_NETWORK with persistent P2P group");
1187 wpa_supplicant_select_network(wpa_s, ssid);
1193 static int wpa_supplicant_ctrl_iface_enable_network(
1194 struct wpa_supplicant *wpa_s, char *cmd)
1197 struct wpa_ssid *ssid;
1199 /* cmd: "<network id>" or "all" */
1200 if (os_strcmp(cmd, "all") == 0) {
1201 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all");
1205 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id);
1207 ssid = wpa_config_get_network(wpa_s->conf, id);
1209 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
1210 "network id=%d", id);
1213 if (ssid->disabled == 2) {
1214 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
1215 "ENABLE_NETWORK with persistent P2P group");
1219 wpa_supplicant_enable_network(wpa_s, ssid);
1225 static int wpa_supplicant_ctrl_iface_disable_network(
1226 struct wpa_supplicant *wpa_s, char *cmd)
1229 struct wpa_ssid *ssid;
1231 /* cmd: "<network id>" or "all" */
1232 if (os_strcmp(cmd, "all") == 0) {
1233 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all");
1237 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id);
1239 ssid = wpa_config_get_network(wpa_s->conf, id);
1241 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
1242 "network id=%d", id);
1245 if (ssid->disabled == 2) {
1246 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
1247 "DISABLE_NETWORK with persistent P2P "
1252 wpa_supplicant_disable_network(wpa_s, ssid);
1258 static int wpa_supplicant_ctrl_iface_add_network(
1259 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
1261 struct wpa_ssid *ssid;
1264 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK");
1266 ssid = wpa_config_add_network(wpa_s->conf);
1270 wpas_notify_network_added(wpa_s, ssid);
1273 wpa_config_set_network_defaults(ssid);
1275 ret = os_snprintf(buf, buflen, "%d\n", ssid->id);
1276 if (ret < 0 || (size_t) ret >= buflen)
1282 static int wpa_supplicant_ctrl_iface_remove_network(
1283 struct wpa_supplicant *wpa_s, char *cmd)
1286 struct wpa_ssid *ssid;
1288 /* cmd: "<network id>" or "all" */
1289 if (os_strcmp(cmd, "all") == 0) {
1290 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all");
1291 ssid = wpa_s->conf->ssid;
1293 struct wpa_ssid *remove_ssid = ssid;
1296 wpas_notify_network_removed(wpa_s, remove_ssid);
1297 wpa_config_remove_network(wpa_s->conf, id);
1299 if (wpa_s->current_ssid) {
1300 eapol_sm_invalidate_cached_session(wpa_s->eapol);
1301 wpa_supplicant_disassociate(wpa_s,
1302 WLAN_REASON_DEAUTH_LEAVING);
1308 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id);
1310 ssid = wpa_config_get_network(wpa_s->conf, id);
1312 wpa_config_remove_network(wpa_s->conf, id) < 0) {
1313 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
1318 if (ssid == wpa_s->current_ssid) {
1320 * Invalidate the EAP session cache if the current network is
1323 eapol_sm_invalidate_cached_session(wpa_s->eapol);
1325 wpa_supplicant_disassociate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
1332 static int wpa_supplicant_ctrl_iface_set_network(
1333 struct wpa_supplicant *wpa_s, char *cmd)
1336 struct wpa_ssid *ssid;
1339 /* cmd: "<network id> <variable name> <value>" */
1340 name = os_strchr(cmd, ' ');
1345 value = os_strchr(name, ' ');
1351 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
1353 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
1354 (u8 *) value, os_strlen(value));
1356 ssid = wpa_config_get_network(wpa_s->conf, id);
1358 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
1363 if (wpa_config_set(ssid, name, value, 0) < 0) {
1364 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network "
1365 "variable '%s'", name);
1369 if (wpa_s->current_ssid == ssid) {
1371 * Invalidate the EAP session cache if anything in the current
1372 * configuration changes.
1374 eapol_sm_invalidate_cached_session(wpa_s->eapol);
1377 if ((os_strcmp(name, "psk") == 0 &&
1378 value[0] == '"' && ssid->ssid_len) ||
1379 (os_strcmp(name, "ssid") == 0 && ssid->passphrase))
1380 wpa_config_update_psk(ssid);
1381 else if (os_strcmp(name, "priority") == 0)
1382 wpa_config_update_prio_list(wpa_s->conf);
1388 static int wpa_supplicant_ctrl_iface_get_network(
1389 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
1393 struct wpa_ssid *ssid;
1396 /* cmd: "<network id> <variable name>" */
1397 name = os_strchr(cmd, ' ');
1398 if (name == NULL || buflen == 0)
1403 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
1406 ssid = wpa_config_get_network(wpa_s->conf, id);
1408 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
1413 value = wpa_config_get_no_key(ssid, name);
1414 if (value == NULL) {
1415 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
1416 "variable '%s'", name);
1420 res = os_strlcpy(buf, value, buflen);
1421 if (res >= buflen) {
1432 #ifndef CONFIG_NO_CONFIG_WRITE
1433 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s)
1437 if (!wpa_s->conf->update_config) {
1438 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
1439 "to update configuration (update_config=0)");
1443 ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
1445 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to "
1446 "update configuration");
1448 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration"
1454 #endif /* CONFIG_NO_CONFIG_WRITE */
1457 static int ctrl_iface_get_capability_pairwise(int res, char *strict,
1458 struct wpa_driver_capa *capa,
1459 char *buf, size_t buflen)
1471 len = os_strlcpy(buf, "CCMP TKIP NONE", buflen);
1477 if (capa->enc & WPA_DRIVER_CAPA_ENC_CCMP) {
1478 ret = os_snprintf(pos, end - pos, "%sCCMP", first ? "" : " ");
1479 if (ret < 0 || ret >= end - pos)
1485 if (capa->enc & WPA_DRIVER_CAPA_ENC_TKIP) {
1486 ret = os_snprintf(pos, end - pos, "%sTKIP", first ? "" : " ");
1487 if (ret < 0 || ret >= end - pos)
1493 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
1494 ret = os_snprintf(pos, end - pos, "%sNONE", first ? "" : " ");
1495 if (ret < 0 || ret >= end - pos)
1505 static int ctrl_iface_get_capability_group(int res, char *strict,
1506 struct wpa_driver_capa *capa,
1507 char *buf, size_t buflen)
1519 len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen);
1525 if (capa->enc & WPA_DRIVER_CAPA_ENC_CCMP) {
1526 ret = os_snprintf(pos, end - pos, "%sCCMP", first ? "" : " ");
1527 if (ret < 0 || ret >= end - pos)
1533 if (capa->enc & WPA_DRIVER_CAPA_ENC_TKIP) {
1534 ret = os_snprintf(pos, end - pos, "%sTKIP", first ? "" : " ");
1535 if (ret < 0 || ret >= end - pos)
1541 if (capa->enc & WPA_DRIVER_CAPA_ENC_WEP104) {
1542 ret = os_snprintf(pos, end - pos, "%sWEP104",
1544 if (ret < 0 || ret >= end - pos)
1550 if (capa->enc & WPA_DRIVER_CAPA_ENC_WEP40) {
1551 ret = os_snprintf(pos, end - pos, "%sWEP40", first ? "" : " ");
1552 if (ret < 0 || ret >= end - pos)
1562 static int ctrl_iface_get_capability_key_mgmt(int res, char *strict,
1563 struct wpa_driver_capa *capa,
1564 char *buf, size_t buflen)
1576 len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
1583 ret = os_snprintf(pos, end - pos, "NONE IEEE8021X");
1584 if (ret < 0 || ret >= end - pos)
1588 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
1589 WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
1590 ret = os_snprintf(pos, end - pos, " WPA-EAP");
1591 if (ret < 0 || ret >= end - pos)
1596 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
1597 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
1598 ret = os_snprintf(pos, end - pos, " WPA-PSK");
1599 if (ret < 0 || ret >= end - pos)
1604 if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
1605 ret = os_snprintf(pos, end - pos, " WPA-NONE");
1606 if (ret < 0 || ret >= end - pos)
1615 static int ctrl_iface_get_capability_proto(int res, char *strict,
1616 struct wpa_driver_capa *capa,
1617 char *buf, size_t buflen)
1629 len = os_strlcpy(buf, "RSN WPA", buflen);
1635 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
1636 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
1637 ret = os_snprintf(pos, end - pos, "%sRSN", first ? "" : " ");
1638 if (ret < 0 || ret >= end - pos)
1644 if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
1645 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
1646 ret = os_snprintf(pos, end - pos, "%sWPA", first ? "" : " ");
1647 if (ret < 0 || ret >= end - pos)
1657 static int ctrl_iface_get_capability_auth_alg(int res, char *strict,
1658 struct wpa_driver_capa *capa,
1659 char *buf, size_t buflen)
1671 len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen);
1677 if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) {
1678 ret = os_snprintf(pos, end - pos, "%sOPEN", first ? "" : " ");
1679 if (ret < 0 || ret >= end - pos)
1685 if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) {
1686 ret = os_snprintf(pos, end - pos, "%sSHARED",
1688 if (ret < 0 || ret >= end - pos)
1694 if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) {
1695 ret = os_snprintf(pos, end - pos, "%sLEAP", first ? "" : " ");
1696 if (ret < 0 || ret >= end - pos)
1706 static int wpa_supplicant_ctrl_iface_get_capability(
1707 struct wpa_supplicant *wpa_s, const char *_field, char *buf,
1710 struct wpa_driver_capa capa;
1716 /* Determine whether or not strict checking was requested */
1717 len = os_strlcpy(field, _field, sizeof(field));
1718 if (len >= sizeof(field))
1720 strict = os_strchr(field, ' ');
1721 if (strict != NULL) {
1723 if (os_strcmp(strict, "strict") != 0)
1727 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
1728 field, strict ? strict : "");
1730 if (os_strcmp(field, "eap") == 0) {
1731 return eap_get_names(buf, buflen);
1734 res = wpa_drv_get_capa(wpa_s, &capa);
1736 if (os_strcmp(field, "pairwise") == 0)
1737 return ctrl_iface_get_capability_pairwise(res, strict, &capa,
1740 if (os_strcmp(field, "group") == 0)
1741 return ctrl_iface_get_capability_group(res, strict, &capa,
1744 if (os_strcmp(field, "key_mgmt") == 0)
1745 return ctrl_iface_get_capability_key_mgmt(res, strict, &capa,
1748 if (os_strcmp(field, "proto") == 0)
1749 return ctrl_iface_get_capability_proto(res, strict, &capa,
1752 if (os_strcmp(field, "auth_alg") == 0)
1753 return ctrl_iface_get_capability_auth_alg(res, strict, &capa,
1756 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
1763 static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
1764 const char *cmd, char *buf,
1769 struct wpa_bss *bss;
1774 if (os_strcmp(cmd, "FIRST") == 0)
1775 bss = dl_list_first(&wpa_s->bss, struct wpa_bss, list);
1776 else if (os_strncmp(cmd, "ID-", 3) == 0) {
1778 bss = wpa_bss_get_id(wpa_s, i);
1779 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
1781 bss = wpa_bss_get_id(wpa_s, i);
1783 struct dl_list *next = bss->list_id.next;
1784 if (next == &wpa_s->bss_id)
1787 bss = dl_list_entry(next, struct wpa_bss,
1790 } else if (hwaddr_aton(cmd, bssid) == 0)
1791 bss = wpa_bss_get_bssid(wpa_s, bssid);
1793 struct wpa_bss *tmp;
1796 dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id)
1810 ret = os_snprintf(pos, end - pos,
1812 "bssid=" MACSTR "\n"
1815 "capabilities=0x%04x\n"
1822 MAC2STR(bss->bssid), bss->freq, bss->beacon_int,
1823 bss->caps, bss->qual, bss->noise, bss->level,
1824 (unsigned long long) bss->tsf);
1825 if (ret < 0 || ret >= end - pos)
1829 ie = (const u8 *) (bss + 1);
1830 for (i = 0; i < bss->ie_len; i++) {
1831 ret = os_snprintf(pos, end - pos, "%02x", *ie++);
1832 if (ret < 0 || ret >= end - pos)
1836 if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE)) {
1837 ret = os_snprintf(pos, end - pos, "[P2P]");
1838 if (ret < 0 || ret >= end - pos)
1843 ret = os_snprintf(pos, end - pos, "\n");
1844 if (ret < 0 || ret >= end - pos)
1848 ret = os_snprintf(pos, end - pos, "flags=");
1849 if (ret < 0 || ret >= end - pos)
1853 ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
1855 pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]);
1856 ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
1858 pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2, 2 + ie2[1]);
1859 pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
1860 if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
1861 ret = os_snprintf(pos, end - pos, "[WEP]");
1862 if (ret < 0 || ret >= end - pos)
1866 if (bss->caps & IEEE80211_CAP_IBSS) {
1867 ret = os_snprintf(pos, end - pos, "[IBSS]");
1868 if (ret < 0 || ret >= end - pos)
1872 if (bss->caps & IEEE80211_CAP_ESS) {
1873 ret = os_snprintf(pos, end - pos, "[ESS]");
1874 if (ret < 0 || ret >= end - pos)
1879 ret = os_snprintf(pos, end - pos, "\n");
1880 if (ret < 0 || ret >= end - pos)
1884 ret = os_snprintf(pos, end - pos, "ssid=%s\n",
1885 wpa_ssid_txt(bss->ssid, bss->ssid_len));
1886 if (ret < 0 || ret >= end - pos)
1891 ie = (const u8 *) (bss + 1);
1892 ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end);
1893 if (ret < 0 || ret >= end - pos)
1896 #endif /* CONFIG_WPS */
1899 ie = (const u8 *) (bss + 1);
1900 ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end);
1901 if (ret < 0 || ret >= end - pos)
1904 #endif /* CONFIG_P2P */
1910 static int wpa_supplicant_ctrl_iface_ap_scan(
1911 struct wpa_supplicant *wpa_s, char *cmd)
1913 int ap_scan = atoi(cmd);
1914 return wpa_supplicant_set_ap_scan(wpa_s, ap_scan);
1918 static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s)
1920 wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication");
1921 /* MLME-DELETEKEYS.request */
1922 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL, 0);
1923 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL, 0);
1924 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL, 0);
1925 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL, 0);
1926 #ifdef CONFIG_IEEE80211W
1927 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL, 0);
1928 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL, 0);
1929 #endif /* CONFIG_IEEE80211W */
1931 wpa_drv_set_key(wpa_s, WPA_ALG_NONE, wpa_s->bssid, 0, 0, NULL, 0, NULL,
1933 /* MLME-SETPROTECTION.request(None) */
1934 wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid,
1935 MLME_SETPROTECTION_PROTECT_TYPE_NONE,
1936 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE);
1937 wpa_sm_drop_sa(wpa_s->wpa);
1941 static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s,
1945 struct wpa_bss *bss;
1946 struct wpa_ssid *ssid = wpa_s->current_ssid;
1948 if (hwaddr_aton(addr, bssid)) {
1949 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid "
1950 "address '%s'", addr);
1954 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR, MAC2STR(bssid));
1956 bss = wpa_bss_get_bssid(wpa_s, bssid);
1958 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found "
1964 * TODO: Find best network configuration block from configuration to
1965 * allow roaming to other networks
1969 wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network "
1970 "configuration known for the target AP");
1974 wpa_s->reassociate = 1;
1975 wpa_supplicant_connect(wpa_s, bss, ssid);
1982 static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd)
1984 unsigned int timeout = atoi(cmd);
1985 enum p2p_discovery_type type = P2P_FIND_START_WITH_FULL;
1987 if (os_strstr(cmd, "type=social"))
1988 type = P2P_FIND_ONLY_SOCIAL;
1989 else if (os_strstr(cmd, "type=progressive"))
1990 type = P2P_FIND_PROGRESSIVE;
1992 return wpas_p2p_find(wpa_s, timeout, type);
1996 static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd,
1997 char *buf, size_t buflen)
2002 enum p2p_wps_method wps_method;
2005 int persistent_group;
2011 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad] [persistent]
2012 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] */
2014 if (hwaddr_aton(cmd, addr))
2022 persistent_group = os_strstr(pos, " persistent") != NULL;
2023 join = os_strstr(pos, " join") != NULL;
2024 auth = os_strstr(pos, " auth") != NULL;
2026 pos2 = os_strstr(pos, " go_intent=");
2029 go_intent = atoi(pos2);
2030 if (go_intent < 0 || go_intent > 15)
2034 pos2 = os_strstr(pos, " freq=");
2042 if (os_strncmp(pos, "pin", 3) == 0) {
2043 /* Request random PIN (to be displayed) and enable the PIN */
2044 wps_method = WPS_PIN_DISPLAY;
2045 } else if (os_strncmp(pos, "pbc", 3) == 0) {
2046 wps_method = WPS_PBC;
2049 pos = os_strchr(pin, ' ');
2050 wps_method = WPS_PIN_KEYPAD;
2053 if (os_strncmp(pos, "label", 5) == 0)
2054 wps_method = WPS_PIN_LABEL;
2055 else if (os_strncmp(pos, "display", 7) == 0)
2056 wps_method = WPS_PIN_DISPLAY;
2060 new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method,
2061 persistent_group, join, auth, go_intent,
2063 if (new_pin == -2) {
2064 os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
2067 if (new_pin == -3) {
2068 os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
2073 if (wps_method == WPS_PIN_DISPLAY && pin == NULL) {
2074 ret = os_snprintf(buf, buflen, "%08d", new_pin);
2075 if (ret < 0 || (size_t) ret >= buflen)
2080 os_memcpy(buf, "OK\n", 3);
2085 static int p2p_ctrl_listen(struct wpa_supplicant *wpa_s, char *cmd)
2087 unsigned int timeout = atoi(cmd);
2088 return wpas_p2p_listen(wpa_s, timeout);
2092 static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd)
2097 /* <addr> <config method> */
2099 if (hwaddr_aton(cmd, addr))
2107 return wpas_p2p_prov_disc(wpa_s, addr, pos);
2111 static int p2p_get_passphrase(struct wpa_supplicant *wpa_s, char *buf,
2114 struct wpa_ssid *ssid = wpa_s->current_ssid;
2116 if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO ||
2117 ssid->passphrase == NULL)
2120 os_strlcpy(buf, ssid->passphrase, buflen);
2121 return os_strlen(buf);
2125 static int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd,
2126 char *buf, size_t buflen)
2130 u8 dst_buf[ETH_ALEN], *dst;
2131 struct wpabuf *tlvs;
2135 if (hwaddr_aton(cmd, dst_buf))
2138 if (dst[0] == 0 && dst[1] == 0 && dst[2] == 0 &&
2139 dst[3] == 0 && dst[4] == 0 && dst[5] == 0)
2146 if (os_strncmp(pos, "upnp ", 5) == 0) {
2149 if (hexstr2bin(pos, &version, 1) < 0)
2155 ref = (unsigned long) wpas_p2p_sd_request_upnp(wpa_s, dst,
2158 len = os_strlen(pos);
2162 tlvs = wpabuf_alloc(len);
2165 if (hexstr2bin(pos, wpabuf_put(tlvs, len), len) < 0) {
2170 ref = (unsigned long) wpas_p2p_sd_request(wpa_s, dst, tlvs);
2173 res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref);
2174 if (res < 0 || (unsigned) res >= buflen)
2180 static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s,
2183 long long unsigned val;
2185 if (sscanf(cmd, "%llx", &val) != 1)
2188 return wpas_p2p_sd_cancel_request(wpa_s, (void *) (unsigned long) req);
2192 static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant *wpa_s, char *cmd)
2197 struct wpabuf *resp_tlvs;
2201 pos = os_strchr(cmd, ' ');
2209 if (hwaddr_aton(pos, dst))
2216 pos2 = os_strchr(pos, ' ');
2220 dialog_token = atoi(pos);
2222 len = os_strlen(pos2);
2226 resp_tlvs = wpabuf_alloc(len);
2227 if (resp_tlvs == NULL)
2229 if (hexstr2bin(pos2, wpabuf_put(resp_tlvs, len), len) < 0) {
2230 wpabuf_free(resp_tlvs);
2234 wpas_p2p_sd_response(wpa_s, freq, dst, dialog_token, resp_tlvs);
2235 wpabuf_free(resp_tlvs);
2240 static int p2p_ctrl_serv_disc_external(struct wpa_supplicant *wpa_s,
2243 wpa_s->p2p_sd_over_ctrl_iface = atoi(cmd);
2248 static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant *wpa_s,
2253 struct wpabuf *query, *resp;
2255 pos = os_strchr(cmd, ' ');
2260 len = os_strlen(cmd);
2264 query = wpabuf_alloc(len);
2267 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
2272 len = os_strlen(pos);
2278 resp = wpabuf_alloc(len);
2283 if (hexstr2bin(pos, wpabuf_put(resp, len), len) < 0) {
2289 if (wpas_p2p_service_add_bonjour(wpa_s, query, resp) < 0) {
2298 static int p2p_ctrl_service_add_upnp(struct wpa_supplicant *wpa_s, char *cmd)
2303 pos = os_strchr(cmd, ' ');
2308 if (hexstr2bin(cmd, &version, 1) < 0)
2311 return wpas_p2p_service_add_upnp(wpa_s, version, pos);
2315 static int p2p_ctrl_service_add(struct wpa_supplicant *wpa_s, char *cmd)
2319 pos = os_strchr(cmd, ' ');
2324 if (os_strcmp(cmd, "bonjour") == 0)
2325 return p2p_ctrl_service_add_bonjour(wpa_s, pos);
2326 if (os_strcmp(cmd, "upnp") == 0)
2327 return p2p_ctrl_service_add_upnp(wpa_s, pos);
2328 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
2333 static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant *wpa_s,
2337 struct wpabuf *query;
2340 len = os_strlen(cmd);
2344 query = wpabuf_alloc(len);
2347 if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
2352 ret = wpas_p2p_service_del_bonjour(wpa_s, query);
2358 static int p2p_ctrl_service_del_upnp(struct wpa_supplicant *wpa_s, char *cmd)
2363 pos = os_strchr(cmd, ' ');
2368 if (hexstr2bin(cmd, &version, 1) < 0)
2371 return wpas_p2p_service_del_upnp(wpa_s, version, pos);
2375 static int p2p_ctrl_service_del(struct wpa_supplicant *wpa_s, char *cmd)
2379 pos = os_strchr(cmd, ' ');
2384 if (os_strcmp(cmd, "bonjour") == 0)
2385 return p2p_ctrl_service_del_bonjour(wpa_s, pos);
2386 if (os_strcmp(cmd, "upnp") == 0)
2387 return p2p_ctrl_service_del_upnp(wpa_s, pos);
2388 wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
2393 static int p2p_ctrl_reject(struct wpa_supplicant *wpa_s, char *cmd)
2399 if (hwaddr_aton(cmd, addr))
2402 return wpas_p2p_reject(wpa_s, addr);
2406 static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd)
2410 struct wpa_ssid *ssid;
2414 pos = os_strstr(cmd, " peer=");
2417 if (hwaddr_aton(pos, peer))
2420 ssid = wpa_config_get_network(wpa_s->conf, id);
2421 if (ssid == NULL || ssid->disabled != 2) {
2422 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
2423 "for persistent P2P group",
2428 return wpas_p2p_invite(wpa_s, pos ? peer : NULL, ssid, NULL);
2432 static int p2p_ctrl_invite_group(struct wpa_supplicant *wpa_s, char *cmd)
2435 u8 peer[ETH_ALEN], go_dev_addr[ETH_ALEN], *go_dev = NULL;
2437 pos = os_strstr(cmd, " peer=");
2443 if (hwaddr_aton(pos, peer)) {
2444 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", pos);
2448 pos = os_strstr(pos, " go_dev_addr=");
2451 if (hwaddr_aton(pos, go_dev_addr)) {
2452 wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'",
2456 go_dev = go_dev_addr;
2459 return wpas_p2p_invite_group(wpa_s, cmd, peer, go_dev);
2463 static int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd)
2465 if (os_strncmp(cmd, "persistent=", 11) == 0)
2466 return p2p_ctrl_invite_persistent(wpa_s, cmd + 11);
2467 if (os_strncmp(cmd, "group=", 6) == 0)
2468 return p2p_ctrl_invite_group(wpa_s, cmd + 6);
2474 static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s,
2475 char *cmd, int freq)
2478 struct wpa_ssid *ssid;
2481 ssid = wpa_config_get_network(wpa_s->conf, id);
2482 if (ssid == NULL || ssid->disabled != 2) {
2483 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
2484 "for persistent P2P group",
2489 return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq);
2493 static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd)
2498 pos = os_strstr(cmd, "freq=");
2500 freq = atoi(pos + 5);
2502 if (os_strncmp(cmd, "persistent=", 11) == 0)
2503 return p2p_ctrl_group_add_persistent(wpa_s, cmd + 11, freq);
2504 if (os_strcmp(cmd, "persistent") == 0 ||
2505 os_strncmp(cmd, "persistent ", 11) == 0)
2506 return wpas_p2p_group_add(wpa_s, 1, freq);
2507 if (os_strncmp(cmd, "freq=", 5) == 0)
2508 return wpas_p2p_group_add(wpa_s, 0, freq);
2510 wpa_printf(MSG_DEBUG, "CTRL: Invalid P2P_GROUP_ADD parameters '%s'",
2516 static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd,
2517 char *buf, size_t buflen)
2519 u8 addr[ETH_ALEN], *addr_ptr;
2522 if (!wpa_s->global->p2p)
2525 if (os_strcmp(cmd, "FIRST") == 0) {
2528 } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
2529 if (hwaddr_aton(cmd + 5, addr) < 0)
2534 if (hwaddr_aton(cmd, addr) < 0)
2540 return p2p_get_peer_info(wpa_s->global->p2p, addr_ptr, next,
2545 static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd)
2549 if (wpa_s->global->p2p == NULL)
2552 param = os_strchr(cmd, ' ');
2557 if (os_strcmp(cmd, "discoverability") == 0) {
2558 p2p_set_client_discoverability(wpa_s->global->p2p,
2563 if (os_strcmp(cmd, "managed") == 0) {
2564 p2p_set_managed_oper(wpa_s->global->p2p, atoi(param));
2568 if (os_strcmp(cmd, "listen_channel") == 0) {
2569 return p2p_set_listen_channel(wpa_s->global->p2p, 81,
2573 if (os_strcmp(cmd, "ssid_postfix") == 0) {
2574 return p2p_set_ssid_postfix(wpa_s->global->p2p, (u8 *) param,
2578 if (os_strcmp(cmd, "noa") == 0) {
2580 int count, start, duration;
2581 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
2582 count = atoi(param);
2583 pos = os_strchr(param, ',');
2588 pos = os_strchr(pos, ',');
2592 duration = atoi(pos);
2593 if (count < 0 || count > 255 || start < 0 || duration < 0)
2595 if (count == 0 && duration > 0)
2597 wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
2598 "start=%d duration=%d", count, start, duration);
2599 return wpas_p2p_set_noa(wpa_s, count, start, duration);
2602 if (os_strcmp(cmd, "ps") == 0)
2603 return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1);
2605 if (os_strcmp(cmd, "oppps") == 0)
2606 return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1);
2608 if (os_strcmp(cmd, "ctwindow") == 0)
2609 return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param));
2611 if (os_strcmp(cmd, "disabled") == 0) {
2612 wpa_s->global->p2p_disabled = atoi(param);
2613 wpa_printf(MSG_DEBUG, "P2P functionality %s",
2614 wpa_s->global->p2p_disabled ?
2615 "disabled" : "enabled");
2616 if (wpa_s->global->p2p_disabled) {
2617 wpas_p2p_stop_find(wpa_s);
2618 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
2619 p2p_flush(wpa_s->global->p2p);
2624 if (os_strcmp(cmd, "force_long_sd") == 0) {
2625 wpa_s->force_long_sd = atoi(param);
2629 if (os_strcmp(cmd, "peer_filter") == 0) {
2631 if (hwaddr_aton(param, addr))
2633 p2p_set_peer_filter(wpa_s->global->p2p, addr);
2637 if (os_strcmp(cmd, "cross_connect") == 0)
2638 return wpas_p2p_set_cross_connect(wpa_s, atoi(param));
2640 if (os_strcmp(cmd, "go_apsd") == 0) {
2641 if (os_strcmp(param, "disable") == 0)
2642 wpa_s->set_ap_uapsd = 0;
2644 wpa_s->set_ap_uapsd = 1;
2645 wpa_s->ap_uapsd = atoi(param);
2650 if (os_strcmp(cmd, "client_apsd") == 0) {
2651 if (os_strcmp(param, "disable") == 0)
2652 wpa_s->set_sta_uapsd = 0;
2656 /* format: BE,BK,VI,VO;max SP Length */
2658 pos = os_strchr(param, ',');
2663 pos = os_strchr(pos, ',');
2668 pos = os_strchr(pos, ',');
2673 /* ignore max SP Length for now */
2675 wpa_s->set_sta_uapsd = 1;
2676 wpa_s->sta_uapsd = 0;
2678 wpa_s->sta_uapsd |= BIT(0);
2680 wpa_s->sta_uapsd |= BIT(1);
2682 wpa_s->sta_uapsd |= BIT(2);
2684 wpa_s->sta_uapsd |= BIT(3);
2689 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
2696 static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd)
2699 unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0;
2702 pos = os_strchr(cmd, ' ');
2708 pos2 = os_strchr(pos, ' ');
2716 pos = os_strchr(pos2, ' ');
2724 return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2);
2728 static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd)
2731 unsigned int period = 0, interval = 0;
2734 pos = os_strchr(cmd, ' ');
2739 interval = atoi(pos);
2742 return wpas_p2p_ext_listen(wpa_s, period, interval);
2745 #endif /* CONFIG_P2P */
2748 static int wpa_supplicant_ctrl_iface_sta_autoconnect(
2749 struct wpa_supplicant *wpa_s, char *cmd)
2751 wpa_s->auto_reconnect_disabled = atoi(cmd) == 0 ? 1 : 0;
2756 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
2757 char *buf, size_t *resp_len)
2760 const int reply_size = 4096;
2764 if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 ||
2765 os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
2766 wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface",
2767 (const u8 *) buf, os_strlen(buf));
2769 int level = MSG_DEBUG;
2770 if (os_strcmp(buf, "PING") == 0)
2771 level = MSG_EXCESSIVE;
2772 wpa_hexdump_ascii(level, "RX ctrl_iface",
2773 (const u8 *) buf, os_strlen(buf));
2776 reply = os_malloc(reply_size);
2777 if (reply == NULL) {
2782 os_memcpy(reply, "OK\n", 3);
2785 if (os_strcmp(buf, "PING") == 0) {
2786 os_memcpy(reply, "PONG\n", 5);
2788 } else if (os_strncmp(buf, "NOTE ", 5) == 0) {
2789 wpa_printf(MSG_INFO, "NOTE: %s", buf + 5);
2790 } else if (os_strcmp(buf, "MIB") == 0) {
2791 reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size);
2792 if (reply_len >= 0) {
2794 res = eapol_sm_get_mib(wpa_s->eapol, reply + reply_len,
2795 reply_size - reply_len);
2801 } else if (os_strncmp(buf, "STATUS", 6) == 0) {
2802 reply_len = wpa_supplicant_ctrl_iface_status(
2803 wpa_s, buf + 6, reply, reply_size);
2804 } else if (os_strcmp(buf, "PMKSA") == 0) {
2805 reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, reply,
2807 } else if (os_strncmp(buf, "SET ", 4) == 0) {
2808 if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4))
2810 } else if (os_strncmp(buf, "GET ", 4) == 0) {
2811 reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4,
2813 } else if (os_strcmp(buf, "LOGON") == 0) {
2814 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
2815 } else if (os_strcmp(buf, "LOGOFF") == 0) {
2816 eapol_sm_notify_logoff(wpa_s->eapol, TRUE);
2817 } else if (os_strcmp(buf, "REASSOCIATE") == 0) {
2818 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
2821 wpa_s->disconnected = 0;
2822 wpa_s->reassociate = 1;
2823 wpa_supplicant_req_scan(wpa_s, 0, 0);
2825 } else if (os_strcmp(buf, "RECONNECT") == 0) {
2826 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
2828 else if (wpa_s->disconnected) {
2829 wpa_s->disconnected = 0;
2830 wpa_s->reassociate = 1;
2831 wpa_supplicant_req_scan(wpa_s, 0, 0);
2833 #ifdef IEEE8021X_EAPOL
2834 } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) {
2835 if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8))
2837 #endif /* IEEE8021X_EAPOL */
2838 #ifdef CONFIG_PEERKEY
2839 } else if (os_strncmp(buf, "STKSTART ", 9) == 0) {
2840 if (wpa_supplicant_ctrl_iface_stkstart(wpa_s, buf + 9))
2842 #endif /* CONFIG_PEERKEY */
2843 #ifdef CONFIG_IEEE80211R
2844 } else if (os_strncmp(buf, "FT_DS ", 6) == 0) {
2845 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6))
2847 #endif /* CONFIG_IEEE80211R */
2849 } else if (os_strcmp(buf, "WPS_PBC") == 0) {
2850 if (wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL))
2852 } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) {
2853 if (wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8))
2855 } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {
2856 reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8,
2859 } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) {
2860 reply_len = wpa_supplicant_ctrl_iface_wps_check_pin(
2861 wpa_s, buf + 14, reply, reply_size);
2862 } else if (os_strcmp(buf, "WPS_CANCEL") == 0) {
2863 if (wpas_wps_cancel(wpa_s))
2865 #ifdef CONFIG_WPS_OOB
2866 } else if (os_strncmp(buf, "WPS_OOB ", 8) == 0) {
2867 if (wpa_supplicant_ctrl_iface_wps_oob(wpa_s, buf + 8))
2869 #endif /* CONFIG_WPS_OOB */
2870 } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) {
2871 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8))
2874 } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) {
2875 reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin(
2876 wpa_s, buf + 11, reply, reply_size);
2877 #endif /* CONFIG_AP */
2878 #ifdef CONFIG_WPS_ER
2879 } else if (os_strcmp(buf, "WPS_ER_START") == 0) {
2880 if (wpas_wps_er_start(wpa_s, NULL))
2882 } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) {
2883 if (wpas_wps_er_start(wpa_s, buf + 13))
2885 } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) {
2886 if (wpas_wps_er_stop(wpa_s))
2888 } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) {
2889 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11))
2891 } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) {
2892 int ret = wpas_wps_er_pbc(wpa_s, buf + 11);
2894 os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
2896 } else if (ret == -3) {
2897 os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18);
2899 } else if (ret == -4) {
2900 os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20);
2904 } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) {
2905 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13))
2907 } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) {
2908 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s,
2911 } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) {
2912 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14))
2914 #endif /* CONFIG_WPS_ER */
2915 #endif /* CONFIG_WPS */
2916 #ifdef CONFIG_IBSS_RSN
2917 } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) {
2918 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9))
2920 #endif /* CONFIG_IBSS_RSN */
2922 } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) {
2923 if (p2p_ctrl_find(wpa_s, buf + 9))
2925 } else if (os_strcmp(buf, "P2P_FIND") == 0) {
2926 if (p2p_ctrl_find(wpa_s, ""))
2928 } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) {
2929 wpas_p2p_stop_find(wpa_s);
2930 } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) {
2931 reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply,
2933 } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) {
2934 if (p2p_ctrl_listen(wpa_s, buf + 11))
2936 } else if (os_strcmp(buf, "P2P_LISTEN") == 0) {
2937 if (p2p_ctrl_listen(wpa_s, ""))
2939 } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) {
2940 if (wpas_p2p_group_remove(wpa_s, buf + 17))
2942 } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) {
2943 if (wpas_p2p_group_add(wpa_s, 0, 0))
2945 } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) {
2946 if (p2p_ctrl_group_add(wpa_s, buf + 14))
2948 } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) {
2949 if (p2p_ctrl_prov_disc(wpa_s, buf + 14))
2951 } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) {
2952 reply_len = p2p_get_passphrase(wpa_s, reply, reply_size);
2953 } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) {
2954 reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply,
2956 } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
2957 if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0)
2959 } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) {
2960 if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0)
2962 } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) {
2963 wpas_p2p_sd_service_update(wpa_s);
2964 } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
2965 if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0)
2967 } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) {
2968 wpas_p2p_service_flush(wpa_s);
2969 } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) {
2970 if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0)
2972 } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) {
2973 if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0)
2975 } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) {
2976 if (p2p_ctrl_reject(wpa_s, buf + 11) < 0)
2978 } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) {
2979 if (p2p_ctrl_invite(wpa_s, buf + 11) < 0)
2981 } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) {
2982 reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply,
2984 } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) {
2985 if (p2p_ctrl_set(wpa_s, buf + 8) < 0)
2987 } else if (os_strcmp(buf, "P2P_FLUSH") == 0) {
2988 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
2989 wpa_s->force_long_sd = 0;
2990 p2p_flush(wpa_s->global->p2p);
2991 } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) {
2992 if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0)
2994 } else if (os_strcmp(buf, "P2P_CANCEL") == 0) {
2995 if (wpas_p2p_cancel(wpa_s))
2997 } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) {
2998 if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0)
3000 } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) {
3001 if (p2p_ctrl_presence_req(wpa_s, "") < 0)
3003 } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) {
3004 if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0)
3006 } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) {
3007 if (p2p_ctrl_ext_listen(wpa_s, "") < 0)
3009 #endif /* CONFIG_P2P */
3010 } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0)
3012 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
3013 wpa_s, buf + os_strlen(WPA_CTRL_RSP)))
3017 } else if (os_strcmp(buf, "RECONFIGURE") == 0) {
3018 if (wpa_supplicant_reload_configuration(wpa_s))
3020 } else if (os_strcmp(buf, "TERMINATE") == 0) {
3021 wpa_supplicant_terminate_proc(wpa_s->global);
3022 } else if (os_strncmp(buf, "BSSID ", 6) == 0) {
3023 if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6))
3025 } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) {
3026 reply_len = wpa_supplicant_ctrl_iface_list_networks(
3027 wpa_s, reply, reply_size);
3028 } else if (os_strcmp(buf, "DISCONNECT") == 0) {
3029 wpa_s->reassociate = 0;
3030 wpa_s->disconnected = 1;
3031 wpa_supplicant_deauthenticate(wpa_s,
3032 WLAN_REASON_DEAUTH_LEAVING);
3033 } else if (os_strcmp(buf, "SCAN") == 0) {
3034 if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
3037 wpa_s->scan_req = 2;
3038 wpa_supplicant_req_scan(wpa_s, 0, 0);
3040 } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) {
3041 reply_len = wpa_supplicant_ctrl_iface_scan_results(
3042 wpa_s, reply, reply_size);
3043 } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) {
3044 if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15))
3046 } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) {
3047 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15))
3049 } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) {
3050 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16))
3052 } else if (os_strcmp(buf, "ADD_NETWORK") == 0) {
3053 reply_len = wpa_supplicant_ctrl_iface_add_network(
3054 wpa_s, reply, reply_size);
3055 } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) {
3056 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15))
3058 } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
3059 if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12))
3061 } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) {
3062 reply_len = wpa_supplicant_ctrl_iface_get_network(
3063 wpa_s, buf + 12, reply, reply_size);
3064 #ifndef CONFIG_NO_CONFIG_WRITE
3065 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
3066 if (wpa_supplicant_ctrl_iface_save_config(wpa_s))
3068 #endif /* CONFIG_NO_CONFIG_WRITE */
3069 } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
3070 reply_len = wpa_supplicant_ctrl_iface_get_capability(
3071 wpa_s, buf + 15, reply, reply_size);
3072 } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) {
3073 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8))
3075 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
3076 reply_len = wpa_supplicant_global_iface_list(
3077 wpa_s->global, reply, reply_size);
3078 } else if (os_strcmp(buf, "INTERFACES") == 0) {
3079 reply_len = wpa_supplicant_global_iface_interfaces(
3080 wpa_s->global, reply, reply_size);
3081 } else if (os_strncmp(buf, "BSS ", 4) == 0) {
3082 reply_len = wpa_supplicant_ctrl_iface_bss(
3083 wpa_s, buf + 4, reply, reply_size);
3085 } else if (os_strcmp(buf, "STA-FIRST") == 0) {
3086 reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size);
3087 } else if (os_strncmp(buf, "STA ", 4) == 0) {
3088 reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply,
3090 } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) {
3091 reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply,
3093 #endif /* CONFIG_AP */
3094 } else if (os_strcmp(buf, "SUSPEND") == 0) {
3095 wpas_notify_suspend(wpa_s->global);
3096 } else if (os_strcmp(buf, "RESUME") == 0) {
3097 wpas_notify_resume(wpa_s->global);
3098 } else if (os_strcmp(buf, "DROP_SA") == 0) {
3099 wpa_supplicant_ctrl_iface_drop_sa(wpa_s);
3100 } else if (os_strncmp(buf, "ROAM ", 5) == 0) {
3101 if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5))
3103 } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) {
3104 if (wpa_supplicant_ctrl_iface_sta_autoconnect(wpa_s, buf + 16))
3107 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
3111 if (reply_len < 0) {
3112 os_memcpy(reply, "FAIL\n", 5);
3117 eapol_sm_notify_ctrl_response(wpa_s->eapol);
3119 *resp_len = reply_len;
3124 static int wpa_supplicant_global_iface_add(struct wpa_global *global,
3127 struct wpa_interface iface;
3131 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
3132 * TAB<bridge_ifname>
3134 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd);
3136 os_memset(&iface, 0, sizeof(iface));
3139 iface.ifname = pos = cmd;
3140 pos = os_strchr(pos, '\t');
3143 if (iface.ifname[0] == '\0')
3148 iface.confname = pos;
3149 pos = os_strchr(pos, '\t');
3152 if (iface.confname[0] == '\0')
3153 iface.confname = NULL;
3158 pos = os_strchr(pos, '\t');
3161 if (iface.driver[0] == '\0')
3162 iface.driver = NULL;
3166 iface.ctrl_interface = pos;
3167 pos = os_strchr(pos, '\t');
3170 if (iface.ctrl_interface[0] == '\0')
3171 iface.ctrl_interface = NULL;
3175 iface.driver_param = pos;
3176 pos = os_strchr(pos, '\t');
3179 if (iface.driver_param[0] == '\0')
3180 iface.driver_param = NULL;
3184 iface.bridge_ifname = pos;
3185 pos = os_strchr(pos, '\t');
3188 if (iface.bridge_ifname[0] == '\0')
3189 iface.bridge_ifname = NULL;
3194 if (wpa_supplicant_get_iface(global, iface.ifname))
3197 return wpa_supplicant_add_iface(global, &iface) ? 0 : -1;
3201 static int wpa_supplicant_global_iface_remove(struct wpa_global *global,
3204 struct wpa_supplicant *wpa_s;
3206 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd);
3208 wpa_s = wpa_supplicant_get_iface(global, cmd);
3211 return wpa_supplicant_remove_iface(global, wpa_s);
3215 static void wpa_free_iface_info(struct wpa_interface_info *iface)
3217 struct wpa_interface_info *prev;
3221 iface = iface->next;
3223 os_free(prev->ifname);
3224 os_free(prev->desc);
3230 static int wpa_supplicant_global_iface_list(struct wpa_global *global,
3234 struct wpa_interface_info *iface = NULL, *last = NULL, *tmp;
3237 for (i = 0; wpa_drivers[i]; i++) {
3238 struct wpa_driver_ops *drv = wpa_drivers[i];
3239 if (drv->get_interfaces == NULL)
3241 tmp = drv->get_interfaces(global->drv_priv[i]);
3255 for (tmp = iface; tmp; tmp = tmp->next) {
3256 res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n",
3257 tmp->drv_name, tmp->ifname,
3258 tmp->desc ? tmp->desc : "");
3259 if (res < 0 || res >= end - pos) {
3266 wpa_free_iface_info(iface);
3272 static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
3277 struct wpa_supplicant *wpa_s;
3279 wpa_s = global->ifaces;
3284 res = os_snprintf(pos, end - pos, "%s\n", wpa_s->ifname);
3285 if (res < 0 || res >= end - pos) {
3290 wpa_s = wpa_s->next;
3296 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
3297 char *buf, size_t *resp_len)
3300 const int reply_size = 2048;
3303 wpa_hexdump_ascii(MSG_DEBUG, "RX global ctrl_iface",
3304 (const u8 *) buf, os_strlen(buf));
3306 reply = os_malloc(reply_size);
3307 if (reply == NULL) {
3312 os_memcpy(reply, "OK\n", 3);
3315 if (os_strcmp(buf, "PING") == 0) {
3316 os_memcpy(reply, "PONG\n", 5);
3318 } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) {
3319 if (wpa_supplicant_global_iface_add(global, buf + 14))
3321 } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) {
3322 if (wpa_supplicant_global_iface_remove(global, buf + 17))
3324 } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
3325 reply_len = wpa_supplicant_global_iface_list(
3326 global, reply, reply_size);
3327 } else if (os_strcmp(buf, "INTERFACES") == 0) {
3328 reply_len = wpa_supplicant_global_iface_interfaces(
3329 global, reply, reply_size);
3330 } else if (os_strcmp(buf, "TERMINATE") == 0) {
3331 wpa_supplicant_terminate_proc(global);
3332 } else if (os_strcmp(buf, "SUSPEND") == 0) {
3333 wpas_notify_suspend(global);
3334 } else if (os_strcmp(buf, "RESUME") == 0) {
3335 wpas_notify_resume(global);
3337 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
3341 if (reply_len < 0) {
3342 os_memcpy(reply, "FAIL\n", 5);
3346 *resp_len = reply_len;