2 * WPA Supplicant / Control interface (shared code for all backends)
3 * Copyright (c) 2004-2006, 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.
20 #include "wpa_supplicant.h"
23 #include "wpa_supplicant_i.h"
24 #include "ctrl_iface.h"
25 #include "l2_packet.h"
27 #include "pmksa_cache.h"
32 static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
36 static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s,
42 value = os_strchr(cmd, ' ');
47 wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value);
48 if (os_strcasecmp(cmd, "EAPOL::heldPeriod") == 0) {
49 eapol_sm_configure(wpa_s->eapol,
50 atoi(value), -1, -1, -1);
51 } else if (os_strcasecmp(cmd, "EAPOL::authPeriod") == 0) {
52 eapol_sm_configure(wpa_s->eapol,
53 -1, atoi(value), -1, -1);
54 } else if (os_strcasecmp(cmd, "EAPOL::startPeriod") == 0) {
55 eapol_sm_configure(wpa_s->eapol,
56 -1, -1, atoi(value), -1);
57 } else if (os_strcasecmp(cmd, "EAPOL::maxStart") == 0) {
58 eapol_sm_configure(wpa_s->eapol,
59 -1, -1, -1, atoi(value));
60 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKLifetime") == 0) {
61 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME,
64 } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKReauthThreshold") ==
66 if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD,
69 } else if (os_strcasecmp(cmd, "dot11RSNAConfigSATimeout") == 0) {
70 if (wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, atoi(value)))
79 static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s,
84 if (hwaddr_aton(addr, bssid)) {
85 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address "
90 wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid));
91 rsn_preauth_deinit(wpa_s->wpa);
92 if (rsn_preauth_init(wpa_s->wpa, bssid, wpa_s->current_ssid))
100 /* MLME-STKSTART.request(peer) */
101 static int wpa_supplicant_ctrl_iface_stkstart(
102 struct wpa_supplicant *wpa_s, char *addr)
106 if (hwaddr_aton(addr, peer)) {
107 wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART: invalid "
108 "address '%s'", peer);
112 wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART " MACSTR,
115 return wpa_sm_stkstart(wpa_s->wpa, peer);
117 #endif /* CONFIG_PEERKEY */
120 static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s,
123 #ifdef IEEE8021X_EAPOL
126 struct wpa_ssid *ssid;
128 pos = os_strchr(rsp, '-');
133 pos = os_strchr(pos, ':');
138 wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id);
139 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
140 (u8 *) pos, os_strlen(pos));
142 ssid = wpa_config_get_network(wpa_s->conf, id);
144 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
149 if (os_strcmp(rsp, "IDENTITY") == 0) {
150 os_free(ssid->identity);
151 ssid->identity = (u8 *) os_strdup(pos);
152 ssid->identity_len = os_strlen(pos);
153 ssid->pending_req_identity = 0;
154 if (ssid == wpa_s->current_ssid)
155 wpa_s->reassociate = 1;
156 } else if (os_strcmp(rsp, "PASSWORD") == 0) {
157 os_free(ssid->password);
158 ssid->password = (u8 *) os_strdup(pos);
159 ssid->password_len = os_strlen(pos);
160 ssid->pending_req_password = 0;
161 if (ssid == wpa_s->current_ssid)
162 wpa_s->reassociate = 1;
163 } else if (os_strcmp(rsp, "NEW_PASSWORD") == 0) {
164 os_free(ssid->new_password);
165 ssid->new_password = (u8 *) os_strdup(pos);
166 ssid->new_password_len = os_strlen(pos);
167 ssid->pending_req_new_password = 0;
168 if (ssid == wpa_s->current_ssid)
169 wpa_s->reassociate = 1;
170 } else if (os_strcmp(rsp, "PIN") == 0) {
172 ssid->pin = os_strdup(pos);
173 ssid->pending_req_pin = 0;
174 if (ssid == wpa_s->current_ssid)
175 wpa_s->reassociate = 1;
176 } else if (os_strcmp(rsp, "OTP") == 0) {
178 ssid->otp = (u8 *) os_strdup(pos);
179 ssid->otp_len = os_strlen(pos);
180 os_free(ssid->pending_req_otp);
181 ssid->pending_req_otp = NULL;
182 ssid->pending_req_otp_len = 0;
183 } else if (os_strcmp(rsp, "PASSPHRASE") == 0) {
184 os_free(ssid->private_key_passwd);
185 ssid->private_key_passwd = (u8 *) os_strdup(pos);
186 ssid->pending_req_passphrase = 0;
187 if (ssid == wpa_s->current_ssid)
188 wpa_s->reassociate = 1;
190 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown field '%s'", rsp);
195 #else /* IEEE8021X_EAPOL */
196 wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included");
198 #endif /* IEEE8021X_EAPOL */
202 static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
204 char *buf, size_t buflen)
206 char *pos, *end, tmp[30];
207 int res, verbose, ret;
209 verbose = os_strcmp(params, "-VERBOSE") == 0;
212 if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
213 struct wpa_ssid *ssid = wpa_s->current_ssid;
214 ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
215 MAC2STR(wpa_s->bssid));
216 if (ret < 0 || ret >= end - pos)
220 u8 *_ssid = ssid->ssid;
221 size_t ssid_len = ssid->ssid_len;
222 u8 ssid_buf[MAX_SSID_LEN];
224 int _res = wpa_drv_get_ssid(wpa_s, ssid_buf);
231 ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n",
232 wpa_ssid_txt(_ssid, ssid_len),
234 if (ret < 0 || ret >= end - pos)
239 ret = os_snprintf(pos, end - pos,
242 if (ret < 0 || ret >= end - pos)
248 pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose);
250 ret = os_snprintf(pos, end - pos, "wpa_state=%s\n",
251 wpa_supplicant_state_txt(wpa_s->wpa_state));
252 if (ret < 0 || ret >= end - pos)
257 l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) {
258 ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp);
259 if (ret < 0 || ret >= end - pos)
264 if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X ||
265 wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
266 res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos,
272 res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose);
280 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s,
285 struct wpa_ssid *ssid;
288 /* cmd: "<network id> <BSSID>" */
289 pos = os_strchr(cmd, ' ');
294 wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos);
295 if (hwaddr_aton(pos, bssid)) {
296 wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos);
300 ssid = wpa_config_get_network(wpa_s->conf, id);
302 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
307 os_memcpy(ssid->bssid, bssid, ETH_ALEN);
309 os_memcmp(bssid, "\x00\x00\x00\x00\x00\x00", ETH_ALEN) != 0;
316 static int wpa_supplicant_ctrl_iface_blacklist(
317 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
319 struct wpa_ssid *ssid;
321 struct wpa_blacklist *e;
325 /* cmd: "BLACKLIST [<BSSID>]" */
330 e = wpa_s->blacklist;
332 ret = os_snprintf(pos, end-pos,
333 "%02x:%02x:%02x:%02x:%02x:%02x\n",
340 if (ret < 0 || ret >= end - pos)
347 wpa_printf(MSG_DEBUG, "CTRL_IFACE: bssid='%s'", cmd);
350 if (os_strncmp(cmd, "clear", 5) == 0) {
351 wpa_blacklist_clear(wpa_s);
355 if (hwaddr_aton(cmd, bssid)) {
356 wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", cmd);
361 * Add the BSSID twice, so its count will be 2, causing it to be
362 * skipped when processing scan results.
364 ret = wpa_blacklist_add(wpa_s, bssid);
367 return wpa_blacklist_add(wpa_s, bssid);
371 static int wpa_supplicant_ctrl_iface_list_networks(
372 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
375 struct wpa_ssid *ssid;
380 ret = os_snprintf(pos, end - pos,
381 "network id / ssid / bssid / flags\n");
382 if (ret < 0 || ret >= end - pos)
386 ssid = wpa_s->conf->ssid;
388 ret = os_snprintf(pos, end - pos, "%d\t%s",
390 wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
391 if (ret < 0 || ret >= end - pos)
394 if (ssid->bssid_set) {
395 ret = os_snprintf(pos, end - pos, "\t" MACSTR,
396 MAC2STR(ssid->bssid));
398 ret = os_snprintf(pos, end - pos, "\tany");
400 if (ret < 0 || ret >= end - pos)
403 ret = os_snprintf(pos, end - pos, "\t%s%s",
404 ssid == wpa_s->current_ssid ?
406 ssid->disabled ? "[DISABLED]" : "");
407 if (ret < 0 || ret >= end - pos)
410 ret = os_snprintf(pos, end - pos, "\n");
411 if (ret < 0 || ret >= end - pos)
422 static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher)
425 ret = os_snprintf(pos, end - pos, "-");
426 if (ret < 0 || ret >= end - pos)
429 if (cipher & WPA_CIPHER_NONE) {
430 ret = os_snprintf(pos, end - pos, "%sNONE", first ? "" : "+");
431 if (ret < 0 || ret >= end - pos)
436 if (cipher & WPA_CIPHER_WEP40) {
437 ret = os_snprintf(pos, end - pos, "%sWEP40", first ? "" : "+");
438 if (ret < 0 || ret >= end - pos)
443 if (cipher & WPA_CIPHER_WEP104) {
444 ret = os_snprintf(pos, end - pos, "%sWEP104",
446 if (ret < 0 || ret >= end - pos)
451 if (cipher & WPA_CIPHER_TKIP) {
452 ret = os_snprintf(pos, end - pos, "%sTKIP", first ? "" : "+");
453 if (ret < 0 || ret >= end - pos)
458 if (cipher & WPA_CIPHER_CCMP) {
459 ret = os_snprintf(pos, end - pos, "%sCCMP", first ? "" : "+");
460 if (ret < 0 || ret >= end - pos)
469 static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
470 const u8 *ie, size_t ie_len)
472 struct wpa_ie_data data;
475 ret = os_snprintf(pos, end - pos, "[%s-", proto);
476 if (ret < 0 || ret >= end - pos)
480 if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) {
481 ret = os_snprintf(pos, end - pos, "?]");
482 if (ret < 0 || ret >= end - pos)
489 if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
490 ret = os_snprintf(pos, end - pos, "%sEAP", first ? "" : "+");
491 if (ret < 0 || ret >= end - pos)
496 if (data.key_mgmt & WPA_KEY_MGMT_PSK) {
497 ret = os_snprintf(pos, end - pos, "%sPSK", first ? "" : "+");
498 if (ret < 0 || ret >= end - pos)
503 if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
504 ret = os_snprintf(pos, end - pos, "%sNone", first ? "" : "+");
505 if (ret < 0 || ret >= end - pos)
511 pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher);
513 if (data.capabilities & WPA_CAPABILITY_PREAUTH) {
514 ret = os_snprintf(pos, end - pos, "-preauth");
515 if (ret < 0 || ret >= end - pos)
520 ret = os_snprintf(pos, end - pos, "]");
521 if (ret < 0 || ret >= end - pos)
529 static int wpa_supplicant_ctrl_iface_scan_results(
530 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
532 char *pos, *end, *retpos;
533 struct wpa_scan_result *res;
536 if (wpa_s->scan_results == NULL &&
537 wpa_supplicant_get_scan_results(wpa_s) < 0)
539 if (wpa_s->scan_results == NULL)
544 ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / "
546 if (ret < 0 || ret >= end - pos)
550 for (i = 0; i < wpa_s->num_scan_results; i++) {
552 res = &wpa_s->scan_results[i];
553 ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t",
554 MAC2STR(res->bssid), res->freq, res->level);
555 if (ret < 0 || ret >= end - pos)
558 if (res->wpa_ie_len) {
559 pos = wpa_supplicant_ie_txt(pos, end, "WPA",
563 if (res->rsn_ie_len) {
564 pos = wpa_supplicant_ie_txt(pos, end, "WPA2",
568 if (!res->wpa_ie_len && !res->rsn_ie_len &&
569 res->caps & IEEE80211_CAP_PRIVACY) {
570 ret = os_snprintf(pos, end - pos, "[WEP]");
571 if (ret < 0 || ret >= end - pos)
575 if (res->caps & IEEE80211_CAP_IBSS) {
576 ret = os_snprintf(pos, end - pos, "[IBSS]");
577 if (ret < 0 || ret >= end - pos)
581 if (!res->wpa_ie_len && !res->rsn_ie_len) {
582 ret = os_snprintf(pos, end - pos, "\t");
583 if (ret < 0 || ret >= end - pos)
588 ret = os_snprintf(pos, end - pos, "\t%s",
589 wpa_ssid_txt(res->ssid, res->ssid_len));
590 if (ret < 0 || ret >= end - pos)
594 ret = os_snprintf(pos, end - pos, "\n");
595 if (ret < 0 || ret >= end - pos)
604 static int wpa_supplicant_ctrl_iface_select_network(
605 struct wpa_supplicant *wpa_s, char *cmd)
608 struct wpa_ssid *ssid;
610 /* cmd: "<network id>" or "any" */
611 if (os_strcmp(cmd, "any") == 0) {
612 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any");
613 ssid = wpa_s->conf->ssid;
618 wpa_s->reassociate = 1;
619 wpa_supplicant_req_scan(wpa_s, 0, 0);
624 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id);
626 ssid = wpa_config_get_network(wpa_s->conf, id);
628 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
633 if (ssid != wpa_s->current_ssid && wpa_s->current_ssid)
634 wpa_supplicant_disassociate(wpa_s, REASON_DEAUTH_LEAVING);
636 /* Mark all other networks disabled and trigger reassociation */
637 ssid = wpa_s->conf->ssid;
639 ssid->disabled = id != ssid->id;
642 wpa_s->reassociate = 1;
643 wpa_supplicant_req_scan(wpa_s, 0, 0);
649 static int wpa_supplicant_ctrl_iface_enable_network(
650 struct wpa_supplicant *wpa_s, char *cmd)
653 struct wpa_ssid *ssid;
655 /* cmd: "<network id>" */
657 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id);
659 ssid = wpa_config_get_network(wpa_s->conf, id);
661 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
666 if (wpa_s->current_ssid == NULL && ssid->disabled) {
668 * Try to reassociate since there is no current configuration
669 * and a new network was made available. */
670 wpa_s->reassociate = 1;
671 wpa_supplicant_req_scan(wpa_s, 0, 0);
679 static int wpa_supplicant_ctrl_iface_disable_network(
680 struct wpa_supplicant *wpa_s, char *cmd)
683 struct wpa_ssid *ssid;
685 /* cmd: "<network id>" */
687 wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id);
689 ssid = wpa_config_get_network(wpa_s->conf, id);
691 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
696 if (ssid == wpa_s->current_ssid)
697 wpa_supplicant_disassociate(wpa_s, REASON_DEAUTH_LEAVING);
704 static int wpa_supplicant_ctrl_iface_add_network(
705 struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
707 struct wpa_ssid *ssid;
710 wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK");
712 ssid = wpa_config_add_network(wpa_s->conf);
716 wpa_config_set_network_defaults(ssid);
718 ret = os_snprintf(buf, buflen, "%d\n", ssid->id);
719 if (ret < 0 || (size_t) ret >= buflen)
725 static int wpa_supplicant_ctrl_iface_remove_network(
726 struct wpa_supplicant *wpa_s, char *cmd)
729 struct wpa_ssid *ssid;
731 /* cmd: "<network id>" */
733 wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id);
735 ssid = wpa_config_get_network(wpa_s->conf, id);
737 wpa_config_remove_network(wpa_s->conf, id) < 0) {
738 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
743 if (ssid == wpa_s->current_ssid) {
745 * Invalidate the EAP session cache if the current network is
748 eapol_sm_invalidate_cached_session(wpa_s->eapol);
750 wpa_supplicant_disassociate(wpa_s, REASON_DEAUTH_LEAVING);
757 static int wpa_supplicant_ctrl_iface_set_network(
758 struct wpa_supplicant *wpa_s, char *cmd)
761 struct wpa_ssid *ssid;
764 /* cmd: "<network id> <variable name> <value>" */
765 name = os_strchr(cmd, ' ');
770 value = os_strchr(name, ' ');
776 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
778 wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
779 (u8 *) value, os_strlen(value));
781 ssid = wpa_config_get_network(wpa_s->conf, id);
783 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
788 if (wpa_config_set(ssid, name, value, 0) < 0) {
789 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network "
790 "variable '%s'", name);
794 if (wpa_s->current_ssid == ssid) {
796 * Invalidate the EAP session cache if anything in the current
797 * configuration changes.
799 eapol_sm_invalidate_cached_session(wpa_s->eapol);
802 if ((os_strcmp(name, "psk") == 0 &&
803 value[0] == '"' && ssid->ssid_len) ||
804 (os_strcmp(name, "ssid") == 0 && ssid->passphrase))
805 wpa_config_update_psk(ssid);
811 static int wpa_supplicant_ctrl_iface_get_network(
812 struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
815 struct wpa_ssid *ssid;
818 /* cmd: "<network id> <variable name>" */
819 name = os_strchr(cmd, ' ');
820 if (name == NULL || buflen == 0)
825 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
828 ssid = wpa_config_get_network(wpa_s->conf, id);
830 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
835 value = wpa_config_get_no_key(ssid, name);
837 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
838 "variable '%s'", name);
842 os_snprintf(buf, buflen, "%s", value);
843 buf[buflen - 1] = '\0';
847 return os_strlen(buf);
851 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s)
855 if (!wpa_s->conf->update_config) {
856 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
857 "to update configuration (update_config=0)");
861 ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
863 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to "
864 "update configuration");
866 wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration"
874 static int wpa_supplicant_ctrl_iface_get_capability(
875 struct wpa_supplicant *wpa_s, const char *_field, char *buf,
878 struct wpa_driver_capa capa;
879 int res, first = 1, ret;
880 char *pos, *end, *strict;
883 /* Determine whether or not strict checking was requested */
884 os_snprintf(field, sizeof(field), "%s", _field);
885 field[sizeof(field) - 1] = '\0';
886 strict = os_strchr(field, ' ');
887 if (strict != NULL) {
889 if (os_strcmp(strict, "strict") != 0)
893 wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
894 field, strict ? strict : "");
896 if (os_strcmp(field, "eap") == 0) {
897 return eap_get_names(buf, buflen);
900 res = wpa_drv_get_capa(wpa_s, &capa);
905 if (os_strcmp(field, "pairwise") == 0) {
909 ret = os_snprintf(buf, buflen, "CCMP TKIP NONE");
910 if (ret < 0 || (size_t) ret >= buflen)
915 if (capa.enc & WPA_DRIVER_CAPA_ENC_CCMP) {
916 ret = os_snprintf(pos, end - pos, "%sCCMP",
918 if (ret < 0 || ret >= end - pos)
924 if (capa.enc & WPA_DRIVER_CAPA_ENC_TKIP) {
925 ret = os_snprintf(pos, end - pos, "%sTKIP",
927 if (ret < 0 || ret >= end - pos)
933 if (capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
934 ret = os_snprintf(pos, end - pos, "%sNONE",
936 if (ret < 0 || ret >= end - pos)
945 if (os_strcmp(field, "group") == 0) {
949 ret = os_snprintf(buf, buflen,
950 "CCMP TKIP WEP104 WEP40");
951 if (ret < 0 || (size_t) ret >= buflen)
956 if (capa.enc & WPA_DRIVER_CAPA_ENC_CCMP) {
957 ret = os_snprintf(pos, end - pos, "%sCCMP",
959 if (ret < 0 || ret >= end - pos)
965 if (capa.enc & WPA_DRIVER_CAPA_ENC_TKIP) {
966 ret = os_snprintf(pos, end - pos, "%sTKIP",
968 if (ret < 0 || ret >= end - pos)
974 if (capa.enc & WPA_DRIVER_CAPA_ENC_WEP104) {
975 ret = os_snprintf(pos, end - pos, "%sWEP104",
977 if (ret < 0 || ret >= end - pos)
983 if (capa.enc & WPA_DRIVER_CAPA_ENC_WEP40) {
984 ret = os_snprintf(pos, end - pos, "%sWEP40",
986 if (ret < 0 || ret >= end - pos)
995 if (os_strcmp(field, "key_mgmt") == 0) {
999 ret = os_snprintf(buf, buflen, "WPA-PSK WPA-EAP "
1000 "IEEE8021X WPA-NONE NONE");
1001 if (ret < 0 || (size_t) ret >= buflen)
1006 ret = os_snprintf(pos, end - pos, "NONE IEEE8021X");
1007 if (ret < 0 || ret >= end - pos)
1011 if (capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
1012 WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
1013 ret = os_snprintf(pos, end - pos, " WPA-EAP");
1014 if (ret < 0 || ret >= end - pos)
1019 if (capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
1020 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
1021 ret = os_snprintf(pos, end - pos, " WPA-PSK");
1022 if (ret < 0 || ret >= end - pos)
1027 if (capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
1028 ret = os_snprintf(pos, end - pos, " WPA-NONE");
1029 if (ret < 0 || ret >= end - pos)
1037 if (os_strcmp(field, "proto") == 0) {
1041 ret = os_snprintf(buf, buflen, "RSN WPA");
1042 if (ret < 0 || (size_t) ret >= buflen)
1047 if (capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
1048 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
1049 ret = os_snprintf(pos, end - pos, "%sRSN",
1051 if (ret < 0 || ret >= end - pos)
1057 if (capa.key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
1058 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
1059 ret = os_snprintf(pos, end - pos, "%sWPA",
1061 if (ret < 0 || ret >= end - pos)
1070 if (os_strcmp(field, "auth_alg") == 0) {
1074 ret = os_snprintf(buf, buflen, "OPEN SHARED LEAP");
1075 if (ret < 0 || (size_t) ret >= buflen)
1080 if (capa.auth & (WPA_DRIVER_AUTH_OPEN)) {
1081 ret = os_snprintf(pos, end - pos, "%sOPEN",
1083 if (ret < 0 || ret >= end - pos)
1089 if (capa.auth & (WPA_DRIVER_AUTH_SHARED)) {
1090 ret = os_snprintf(pos, end - pos, "%sSHARED",
1092 if (ret < 0 || ret >= end - pos)
1098 if (capa.auth & (WPA_DRIVER_AUTH_LEAP)) {
1099 ret = os_snprintf(pos, end - pos, "%sLEAP",
1101 if (ret < 0 || ret >= end - pos)
1110 wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
1117 static int wpa_supplicant_ctrl_iface_ap_scan(
1118 struct wpa_supplicant *wpa_s, char *cmd)
1120 int ap_scan = atoi(cmd);
1122 if (ap_scan < 0 || ap_scan > 2)
1124 wpa_s->conf->ap_scan = ap_scan;
1128 static int wpa_supplicant_driver_cmd(struct wpa_supplicant *wpa_s,
1129 char *cmd, char *buf, size_t buflen)
1133 ret = wpa_drv_driver_cmd(wpa_s, cmd, buf, buflen);
1135 ret = sprintf(buf, "%s\n", "OK");
1140 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
1141 char *buf, size_t *resp_len)
1144 const int reply_size = 4096;
1148 if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 ||
1149 os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
1150 wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface",
1151 (const u8 *) buf, os_strlen(buf));
1153 if (os_strcmp(buf, "PING") != 0)
1154 wpa_hexdump_ascii(MSG_DEBUG, "RX ctrl_iface",
1155 (const u8 *) buf, os_strlen(buf));
1158 reply = os_malloc(reply_size);
1159 if (reply == NULL) {
1164 os_memcpy(reply, "OK\n", 3);
1167 if (os_strcmp(buf, "PING") == 0) {
1168 os_memcpy(reply, "PONG\n", 5);
1170 } else if (os_strcmp(buf, "MIB") == 0) {
1171 reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size);
1172 if (reply_len >= 0) {
1174 res = eapol_sm_get_mib(wpa_s->eapol, reply + reply_len,
1175 reply_size - reply_len);
1181 } else if (os_strncmp(buf, "STATUS", 6) == 0) {
1182 reply_len = wpa_supplicant_ctrl_iface_status(
1183 wpa_s, buf + 6, reply, reply_size);
1184 } else if (os_strcmp(buf, "PMKSA") == 0) {
1185 reply_len = pmksa_cache_list(wpa_s->wpa, reply, reply_size);
1186 } else if (os_strncmp(buf, "SET ", 4) == 0) {
1187 if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4))
1189 } else if (os_strcmp(buf, "LOGON") == 0) {
1190 eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
1191 } else if (os_strcmp(buf, "LOGOFF") == 0) {
1192 eapol_sm_notify_logoff(wpa_s->eapol, TRUE);
1193 } else if (os_strcmp(buf, "REASSOCIATE") == 0) {
1194 wpa_s->disconnected = 0;
1195 wpa_s->reassociate = 1;
1196 wpa_supplicant_req_scan(wpa_s, 0, 0);
1197 } else if (os_strcmp(buf, "RECONNECT") == 0) {
1198 if (wpa_s->disconnected) {
1199 wpa_s->disconnected = 0;
1200 wpa_s->reassociate = 1;
1201 wpa_supplicant_req_scan(wpa_s, 0, 0);
1203 } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) {
1204 if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8))
1206 #ifdef CONFIG_PEERKEY
1207 } else if (os_strncmp(buf, "STKSTART ", 9) == 0) {
1208 if (wpa_supplicant_ctrl_iface_stkstart(wpa_s, buf + 9))
1210 #endif /* CONFIG_PEERKEY */
1211 } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0)
1213 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
1214 wpa_s, buf + os_strlen(WPA_CTRL_RSP)))
1218 } else if (os_strcmp(buf, "RECONFIGURE") == 0) {
1219 if (wpa_supplicant_reload_configuration(wpa_s))
1221 } else if (os_strcmp(buf, "TERMINATE") == 0) {
1223 } else if (os_strncmp(buf, "BSSID ", 6) == 0) {
1224 if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6))
1227 } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) {
1228 reply_len = wpa_supplicant_ctrl_iface_blacklist(
1229 wpa_s, buf + 9, reply, reply_size);
1230 if (os_strlen(buf) > 10 && reply_len == 0) {
1231 struct wpa_blacklist *bl = wpa_s->blacklist;
1232 if (os_strncmp(buf+10, "clear", 5) == 0 ||
1233 (bl != NULL && os_memcmp(bl->bssid, wpa_s->bssid, ETH_ALEN) == 0)) {
1234 wpa_s->disconnected = 0;
1235 wpa_s->reassociate = 1;
1236 wpa_supplicant_req_scan(wpa_s, 0, 0);
1240 } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) {
1241 reply_len = wpa_supplicant_ctrl_iface_list_networks(
1242 wpa_s, reply, reply_size);
1243 } else if (os_strcmp(buf, "DISCONNECT") == 0) {
1244 wpa_s->reassociate = 0;
1245 wpa_s->disconnected = 1;
1246 wpa_supplicant_disassociate(wpa_s, REASON_DEAUTH_LEAVING);
1247 } else if (os_strcmp(buf, "SCAN") == 0) {
1248 wpa_s->scan_req = 2;
1249 wpa_supplicant_req_scan(wpa_s, 0, 0);
1250 } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) {
1251 reply_len = wpa_supplicant_ctrl_iface_scan_results(
1252 wpa_s, reply, reply_size);
1253 } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) {
1254 if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15))
1256 } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) {
1257 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15))
1259 } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) {
1260 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16))
1262 } else if (os_strcmp(buf, "ADD_NETWORK") == 0) {
1263 reply_len = wpa_supplicant_ctrl_iface_add_network(
1264 wpa_s, reply, reply_size);
1265 } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) {
1266 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15))
1268 } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
1269 if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12))
1271 } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) {
1272 reply_len = wpa_supplicant_ctrl_iface_get_network(
1273 wpa_s, buf + 12, reply, reply_size);
1274 } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
1275 if (wpa_supplicant_ctrl_iface_save_config(wpa_s))
1277 } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
1278 reply_len = wpa_supplicant_ctrl_iface_get_capability(
1279 wpa_s, buf + 15, reply, reply_size);
1280 } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) {
1281 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8))
1283 } else if (os_strcmp(buf, "INTERFACES") == 0) {
1284 reply_len = wpa_supplicant_global_iface_interfaces(
1285 wpa_s->global, reply, reply_size);
1286 } else if (os_strncmp(buf, "DRIVER ", 7) == 0) {
1287 reply_len = wpa_supplicant_driver_cmd(wpa_s, buf + 7, reply, reply_size);
1289 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
1293 if (reply_len < 0) {
1294 os_memcpy(reply, "FAIL\n", 5);
1299 eapol_sm_notify_ctrl_response(wpa_s->eapol);
1301 *resp_len = reply_len;
1306 static int wpa_supplicant_global_iface_add(struct wpa_global *global,
1309 struct wpa_interface iface;
1313 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
1314 * TAB<bridge_ifname>
1316 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd);
1318 os_memset(&iface, 0, sizeof(iface));
1321 iface.ifname = pos = cmd;
1322 pos = os_strchr(pos, '\t');
1325 if (iface.ifname[0] == '\0')
1330 iface.confname = pos;
1331 pos = os_strchr(pos, '\t');
1334 if (iface.confname[0] == '\0')
1335 iface.confname = NULL;
1340 pos = os_strchr(pos, '\t');
1343 if (iface.driver[0] == '\0')
1344 iface.driver = NULL;
1348 iface.ctrl_interface = pos;
1349 pos = os_strchr(pos, '\t');
1352 if (iface.ctrl_interface[0] == '\0')
1353 iface.ctrl_interface = NULL;
1357 iface.driver_param = pos;
1358 pos = os_strchr(pos, '\t');
1361 if (iface.driver_param[0] == '\0')
1362 iface.driver_param = NULL;
1366 iface.bridge_ifname = pos;
1367 pos = os_strchr(pos, '\t');
1370 if (iface.bridge_ifname[0] == '\0')
1371 iface.bridge_ifname = NULL;
1376 if (wpa_supplicant_get_iface(global, iface.ifname))
1379 return wpa_supplicant_add_iface(global, &iface) ? 0 : -1;
1383 static int wpa_supplicant_global_iface_remove(struct wpa_global *global,
1386 struct wpa_supplicant *wpa_s;
1388 wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd);
1390 wpa_s = wpa_supplicant_get_iface(global, cmd);
1393 return wpa_supplicant_remove_iface(global, wpa_s);
1397 static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
1402 struct wpa_supplicant *wpa_s;
1404 wpa_s = global->ifaces;
1409 res = os_snprintf(pos, end - pos, "%s\n", wpa_s->ifname);
1410 if (res < 0 || res >= end - pos) {
1415 wpa_s = wpa_s->next;
1421 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
1422 char *buf, size_t *resp_len)
1425 const int reply_size = 4096;
1428 if (os_strcmp(buf, "PING") != 0)
1429 wpa_hexdump_ascii(MSG_DEBUG, "RX global ctrl_iface",
1430 (const u8 *) buf, os_strlen(buf));
1432 reply = os_malloc(reply_size);
1433 if (reply == NULL) {
1438 os_memcpy(reply, "OK\n", 3);
1441 if (os_strcmp(buf, "PING") == 0) {
1442 os_memcpy(reply, "PONG\n", 5);
1444 } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) {
1445 if (wpa_supplicant_global_iface_add(global, buf + 14))
1447 } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) {
1448 if (wpa_supplicant_global_iface_remove(global, buf + 17))
1450 } else if (os_strcmp(buf, "INTERFACES") == 0) {
1451 reply_len = wpa_supplicant_global_iface_interfaces(
1452 global, reply, reply_size);
1453 } else if (os_strcmp(buf, "TERMINATE") == 0) {
1456 os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
1460 if (reply_len < 0) {
1461 os_memcpy(reply, "FAIL\n", 5);
1465 *resp_len = reply_len;