2 * WPA Supplicant / Control interface (shared code for all backends)
3 * Copyright (c) 2004-2010, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
9 #include "utils/includes.h"
11 #include "utils/common.h"
12 #include "utils/eloop.h"
13 #include "common/version.h"
14 #include "common/ieee802_11_defs.h"
15 #include "common/wpa_ctrl.h"
16 #include "eap_peer/eap.h"
17 #include "eapol_supp/eapol_supp_sm.h"
18 #include "rsn_supp/wpa.h"
19 #include "rsn_supp/preauth.h"
20 #include "rsn_supp/pmksa_cache.h"
21 #include "l2_packet/l2_packet.h"
24 #include "wpa_supplicant_i.h"
26 #include "wps_supplicant.h"
29 #include "p2p_supplicant.h"
31 #include "hs20_supplicant.h"
35 #include "ctrl_iface.h"
36 #include "interworking.h"
37 #include "blacklist.h"
38 #include "wpas_glue.h"
41 extern struct wpa_driver_ops
*wpa_drivers
[];
43 static int wpa_supplicant_global_iface_list(struct wpa_global
*global
,
45 static int wpa_supplicant_global_iface_interfaces(struct wpa_global
*global
,
49 static int pno_start(struct wpa_supplicant
*wpa_s
)
53 struct wpa_ssid
*ssid
;
54 struct wpa_driver_scan_params params
;
59 os_memset(¶ms
, 0, sizeof(params
));
62 ssid
= wpa_s
->conf
->ssid
;
64 if (!wpas_network_disabled(wpa_s
, ssid
))
68 if (num_ssid
> WPAS_MAX_SCAN_SSIDS
) {
69 wpa_printf(MSG_DEBUG
, "PNO: Use only the first %u SSIDs from "
70 "%u", WPAS_MAX_SCAN_SSIDS
, (unsigned int) num_ssid
);
71 num_ssid
= WPAS_MAX_SCAN_SSIDS
;
75 wpa_printf(MSG_DEBUG
, "PNO: No configured SSIDs");
79 params
.filter_ssids
= os_malloc(sizeof(struct wpa_driver_scan_filter
) *
81 if (params
.filter_ssids
== NULL
)
84 ssid
= wpa_s
->conf
->ssid
;
86 if (!wpas_network_disabled(wpa_s
, ssid
)) {
87 params
.ssids
[i
].ssid
= ssid
->ssid
;
88 params
.ssids
[i
].ssid_len
= ssid
->ssid_len
;
90 os_memcpy(params
.filter_ssids
[i
].ssid
, ssid
->ssid
,
92 params
.filter_ssids
[i
].ssid_len
= ssid
->ssid_len
;
93 params
.num_filter_ssids
++;
101 ret
= wpa_drv_sched_scan(wpa_s
, ¶ms
, 10 * 1000);
102 os_free(params
.filter_ssids
);
109 static int pno_stop(struct wpa_supplicant
*wpa_s
)
113 return wpa_drv_stop_sched_scan(wpa_s
);
119 static int set_bssid_filter(struct wpa_supplicant
*wpa_s
, char *val
)
122 u8 addr
[ETH_ALEN
], *filter
= NULL
, *n
;
129 if (hwaddr_aton(pos
, addr
)) {
133 n
= os_realloc(filter
, (count
+ 1) * ETH_ALEN
);
139 os_memcpy(filter
+ count
* ETH_ALEN
, addr
, ETH_ALEN
);
142 pos
= os_strchr(pos
, ' ');
147 wpa_hexdump(MSG_DEBUG
, "bssid_filter", filter
, count
* ETH_ALEN
);
148 os_free(wpa_s
->bssid_filter
);
149 wpa_s
->bssid_filter
= filter
;
150 wpa_s
->bssid_filter_count
= count
;
156 static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant
*wpa_s
,
162 value
= os_strchr(cmd
, ' ');
167 wpa_printf(MSG_DEBUG
, "CTRL_IFACE SET '%s'='%s'", cmd
, value
);
168 if (os_strcasecmp(cmd
, "EAPOL::heldPeriod") == 0) {
169 eapol_sm_configure(wpa_s
->eapol
,
170 atoi(value
), -1, -1, -1);
171 } else if (os_strcasecmp(cmd
, "EAPOL::authPeriod") == 0) {
172 eapol_sm_configure(wpa_s
->eapol
,
173 -1, atoi(value
), -1, -1);
174 } else if (os_strcasecmp(cmd
, "EAPOL::startPeriod") == 0) {
175 eapol_sm_configure(wpa_s
->eapol
,
176 -1, -1, atoi(value
), -1);
177 } else if (os_strcasecmp(cmd
, "EAPOL::maxStart") == 0) {
178 eapol_sm_configure(wpa_s
->eapol
,
179 -1, -1, -1, atoi(value
));
180 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigPMKLifetime") == 0) {
181 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_LIFETIME
,
184 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigPMKReauthThreshold") ==
186 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_REAUTH_THRESHOLD
,
189 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigSATimeout") == 0) {
190 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_SA_TIMEOUT
, atoi(value
)))
192 } else if (os_strcasecmp(cmd
, "wps_fragment_size") == 0) {
193 wpa_s
->wps_fragment_size
= atoi(value
);
194 #ifdef CONFIG_WPS_TESTING
195 } else if (os_strcasecmp(cmd
, "wps_version_number") == 0) {
197 val
= strtol(value
, NULL
, 0);
198 if (val
< 0 || val
> 0xff) {
200 wpa_printf(MSG_DEBUG
, "WPS: Invalid "
201 "wps_version_number %ld", val
);
203 wps_version_number
= val
;
204 wpa_printf(MSG_DEBUG
, "WPS: Testing - force WPS "
206 (wps_version_number
& 0xf0) >> 4,
207 wps_version_number
& 0x0f);
209 } else if (os_strcasecmp(cmd
, "wps_testing_dummy_cred") == 0) {
210 wps_testing_dummy_cred
= atoi(value
);
211 wpa_printf(MSG_DEBUG
, "WPS: Testing - dummy_cred=%d",
212 wps_testing_dummy_cred
);
213 #endif /* CONFIG_WPS_TESTING */
214 } else if (os_strcasecmp(cmd
, "ampdu") == 0) {
215 if (wpa_drv_ampdu(wpa_s
, atoi(value
)) < 0)
217 #ifdef CONFIG_TDLS_TESTING
218 } else if (os_strcasecmp(cmd
, "tdls_testing") == 0) {
219 extern unsigned int tdls_testing
;
220 tdls_testing
= strtol(value
, NULL
, 0);
221 wpa_printf(MSG_DEBUG
, "TDLS: tdls_testing=0x%x", tdls_testing
);
222 #endif /* CONFIG_TDLS_TESTING */
224 } else if (os_strcasecmp(cmd
, "tdls_disabled") == 0) {
225 int disabled
= atoi(value
);
226 wpa_printf(MSG_DEBUG
, "TDLS: tdls_disabled=%d", disabled
);
228 if (wpa_drv_tdls_oper(wpa_s
, TDLS_DISABLE
, NULL
) < 0)
230 } else if (wpa_drv_tdls_oper(wpa_s
, TDLS_ENABLE
, NULL
) < 0)
232 wpa_tdls_enable(wpa_s
->wpa
, !disabled
);
233 #endif /* CONFIG_TDLS */
234 } else if (os_strcasecmp(cmd
, "pno") == 0) {
236 ret
= pno_start(wpa_s
);
238 ret
= pno_stop(wpa_s
);
239 } else if (os_strcasecmp(cmd
, "radio_disabled") == 0) {
240 int disabled
= atoi(value
);
241 if (wpa_drv_radio_disable(wpa_s
, disabled
) < 0)
244 wpa_supplicant_set_state(wpa_s
, WPA_INACTIVE
);
245 } else if (os_strcasecmp(cmd
, "uapsd") == 0) {
246 if (os_strcmp(value
, "disable") == 0)
247 wpa_s
->set_sta_uapsd
= 0;
251 /* format: BE,BK,VI,VO;max SP Length */
253 pos
= os_strchr(value
, ',');
258 pos
= os_strchr(pos
, ',');
263 pos
= os_strchr(pos
, ',');
268 /* ignore max SP Length for now */
270 wpa_s
->set_sta_uapsd
= 1;
271 wpa_s
->sta_uapsd
= 0;
273 wpa_s
->sta_uapsd
|= BIT(0);
275 wpa_s
->sta_uapsd
|= BIT(1);
277 wpa_s
->sta_uapsd
|= BIT(2);
279 wpa_s
->sta_uapsd
|= BIT(3);
281 } else if (os_strcasecmp(cmd
, "ps") == 0) {
282 ret
= wpa_drv_set_p2p_powersave(wpa_s
, atoi(value
), -1, -1);
283 } else if (os_strcasecmp(cmd
, "bssid_filter") == 0) {
284 ret
= set_bssid_filter(wpa_s
, value
);
287 ret
= wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
289 wpa_supplicant_update_config(wpa_s
);
296 static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant
*wpa_s
,
297 char *cmd
, char *buf
, size_t buflen
)
301 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GET '%s'", cmd
);
303 if (os_strcmp(cmd
, "version") == 0) {
304 res
= os_snprintf(buf
, buflen
, "%s", VERSION_STR
);
305 } else if (os_strcasecmp(cmd
, "country") == 0) {
306 if (wpa_s
->conf
->country
[0] && wpa_s
->conf
->country
[1])
307 res
= os_snprintf(buf
, buflen
, "%c%c",
308 wpa_s
->conf
->country
[0],
309 wpa_s
->conf
->country
[1]);
312 if (res
< 0 || (unsigned int) res
>= buflen
)
318 #ifdef IEEE8021X_EAPOL
319 static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant
*wpa_s
,
323 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
325 if (hwaddr_aton(addr
, bssid
)) {
326 wpa_printf(MSG_DEBUG
, "CTRL_IFACE PREAUTH: invalid address "
331 wpa_printf(MSG_DEBUG
, "CTRL_IFACE PREAUTH " MACSTR
, MAC2STR(bssid
));
332 rsn_preauth_deinit(wpa_s
->wpa
);
333 if (rsn_preauth_init(wpa_s
->wpa
, bssid
, ssid
? &ssid
->eap
: NULL
))
338 #endif /* IEEE8021X_EAPOL */
341 #ifdef CONFIG_PEERKEY
342 /* MLME-STKSTART.request(peer) */
343 static int wpa_supplicant_ctrl_iface_stkstart(
344 struct wpa_supplicant
*wpa_s
, char *addr
)
348 if (hwaddr_aton(addr
, peer
)) {
349 wpa_printf(MSG_DEBUG
, "CTRL_IFACE STKSTART: invalid "
350 "address '%s'", addr
);
354 wpa_printf(MSG_DEBUG
, "CTRL_IFACE STKSTART " MACSTR
,
357 return wpa_sm_stkstart(wpa_s
->wpa
, peer
);
359 #endif /* CONFIG_PEERKEY */
364 static int wpa_supplicant_ctrl_iface_tdls_discover(
365 struct wpa_supplicant
*wpa_s
, char *addr
)
370 if (hwaddr_aton(addr
, peer
)) {
371 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_DISCOVER: invalid "
372 "address '%s'", addr
);
376 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_DISCOVER " MACSTR
,
379 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
380 ret
= wpa_tdls_send_discovery_request(wpa_s
->wpa
, peer
);
382 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_DISCOVERY_REQ
, peer
);
388 static int wpa_supplicant_ctrl_iface_tdls_setup(
389 struct wpa_supplicant
*wpa_s
, char *addr
)
394 if (hwaddr_aton(addr
, peer
)) {
395 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_SETUP: invalid "
396 "address '%s'", addr
);
400 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_SETUP " MACSTR
,
403 ret
= wpa_tdls_reneg(wpa_s
->wpa
, peer
);
405 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
406 ret
= wpa_tdls_start(wpa_s
->wpa
, peer
);
408 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, peer
);
415 static int wpa_supplicant_ctrl_iface_tdls_teardown(
416 struct wpa_supplicant
*wpa_s
, char *addr
)
420 if (hwaddr_aton(addr
, peer
)) {
421 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN: invalid "
422 "address '%s'", addr
);
426 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN " MACSTR
,
429 return wpa_tdls_teardown_link(wpa_s
->wpa
, peer
,
430 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED
);
433 #endif /* CONFIG_TDLS */
436 #ifdef CONFIG_IEEE80211R
437 static int wpa_supplicant_ctrl_iface_ft_ds(
438 struct wpa_supplicant
*wpa_s
, char *addr
)
440 u8 target_ap
[ETH_ALEN
];
444 if (hwaddr_aton(addr
, target_ap
)) {
445 wpa_printf(MSG_DEBUG
, "CTRL_IFACE FT_DS: invalid "
446 "address '%s'", addr
);
450 wpa_printf(MSG_DEBUG
, "CTRL_IFACE FT_DS " MACSTR
, MAC2STR(target_ap
));
452 bss
= wpa_bss_get_bssid(wpa_s
, target_ap
);
454 mdie
= wpa_bss_get_ie(bss
, WLAN_EID_MOBILITY_DOMAIN
);
458 return wpa_ft_start_over_ds(wpa_s
->wpa
, target_ap
, mdie
);
460 #endif /* CONFIG_IEEE80211R */
464 static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant
*wpa_s
,
467 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
469 u8 p2p_dev_addr
[ETH_ALEN
];
470 #endif /* CONFIG_P2P */
472 u8
*_p2p_dev_addr
= NULL
;
473 #endif /* CONFIG_AP */
475 if (cmd
== NULL
|| os_strcmp(cmd
, "any") == 0) {
478 } else if (os_strncmp(cmd
, "p2p_dev_addr=", 13) == 0) {
479 if (hwaddr_aton(cmd
+ 13, p2p_dev_addr
)) {
480 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PBC: invalid "
481 "P2P Device Address '%s'",
485 _p2p_dev_addr
= p2p_dev_addr
;
486 #endif /* CONFIG_P2P */
487 } else if (hwaddr_aton(cmd
, bssid
)) {
488 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
495 return wpa_supplicant_ap_wps_pbc(wpa_s
, _bssid
, _p2p_dev_addr
);
496 #endif /* CONFIG_AP */
498 return wpas_wps_start_pbc(wpa_s
, _bssid
, 0);
502 static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant
*wpa_s
,
503 char *cmd
, char *buf
,
506 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
510 pin
= os_strchr(cmd
, ' ');
514 if (os_strcmp(cmd
, "any") == 0)
516 else if (os_strcmp(cmd
, "get") == 0) {
517 ret
= wps_generate_pin();
519 } else if (hwaddr_aton(cmd
, bssid
)) {
520 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
527 return wpa_supplicant_ap_wps_pin(wpa_s
, _bssid
, pin
,
529 #endif /* CONFIG_AP */
532 ret
= wpas_wps_start_pin(wpa_s
, _bssid
, pin
, 0,
536 ret
= os_snprintf(buf
, buflen
, "%s", pin
);
537 if (ret
< 0 || (size_t) ret
>= buflen
)
542 ret
= wpas_wps_start_pin(wpa_s
, _bssid
, NULL
, 0, DEV_PW_DEFAULT
);
547 /* Return the generated PIN */
548 ret
= os_snprintf(buf
, buflen
, "%08d", ret
);
549 if (ret
< 0 || (size_t) ret
>= buflen
)
555 static int wpa_supplicant_ctrl_iface_wps_check_pin(
556 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
563 wpa_hexdump_ascii_key(MSG_DEBUG
, "WPS_CHECK_PIN",
564 (u8
*) cmd
, os_strlen(cmd
));
565 for (pos
= cmd
, len
= 0; *pos
!= '\0'; pos
++) {
566 if (*pos
< '0' || *pos
> '9')
570 wpa_printf(MSG_DEBUG
, "WPS: Too long PIN");
574 if (len
!= 4 && len
!= 8) {
575 wpa_printf(MSG_DEBUG
, "WPS: Invalid PIN length %d", (int) len
);
581 unsigned int pin_val
;
583 if (!wps_pin_valid(pin_val
)) {
584 wpa_printf(MSG_DEBUG
, "WPS: Invalid checksum digit");
585 ret
= os_snprintf(buf
, buflen
, "FAIL-CHECKSUM\n");
586 if (ret
< 0 || (size_t) ret
>= buflen
)
592 ret
= os_snprintf(buf
, buflen
, "%s", pin
);
593 if (ret
< 0 || (size_t) ret
>= buflen
)
600 #ifdef CONFIG_WPS_OOB
601 static int wpa_supplicant_ctrl_iface_wps_oob(struct wpa_supplicant
*wpa_s
,
604 char *path
, *method
, *name
;
606 path
= os_strchr(cmd
, ' ');
611 method
= os_strchr(path
, ' ');
616 name
= os_strchr(method
, ' ');
620 return wpas_wps_start_oob(wpa_s
, cmd
, path
, method
, name
);
622 #endif /* CONFIG_WPS_OOB */
625 static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant
*wpa_s
,
634 struct wps_new_ap_settings ap
;
636 pin
= os_strchr(cmd
, ' ');
641 if (hwaddr_aton(cmd
, bssid
)) {
642 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
647 new_ssid
= os_strchr(pin
, ' ');
648 if (new_ssid
== NULL
)
649 return wpas_wps_start_reg(wpa_s
, bssid
, pin
, NULL
);
652 new_auth
= os_strchr(new_ssid
, ' ');
653 if (new_auth
== NULL
)
657 new_encr
= os_strchr(new_auth
, ' ');
658 if (new_encr
== NULL
)
662 new_key
= os_strchr(new_encr
, ' ');
667 os_memset(&ap
, 0, sizeof(ap
));
668 ap
.ssid_hex
= new_ssid
;
671 ap
.key_hex
= new_key
;
672 return wpas_wps_start_reg(wpa_s
, bssid
, pin
, &ap
);
677 static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant
*wpa_s
,
678 char *cmd
, char *buf
,
685 if (!wpa_s
->ap_iface
)
688 pos
= os_strchr(cmd
, ' ');
692 if (os_strcmp(cmd
, "disable") == 0) {
693 wpas_wps_ap_pin_disable(wpa_s
);
694 return os_snprintf(buf
, buflen
, "OK\n");
697 if (os_strcmp(cmd
, "random") == 0) {
700 pin_txt
= wpas_wps_ap_pin_random(wpa_s
, timeout
);
703 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
706 if (os_strcmp(cmd
, "get") == 0) {
707 pin_txt
= wpas_wps_ap_pin_get(wpa_s
);
710 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
713 if (os_strcmp(cmd
, "set") == 0) {
718 pos
= os_strchr(pos
, ' ');
723 if (os_strlen(pin
) > buflen
)
725 if (wpas_wps_ap_pin_set(wpa_s
, pin
, timeout
) < 0)
727 return os_snprintf(buf
, buflen
, "%s", pin
);
732 #endif /* CONFIG_AP */
736 static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant
*wpa_s
,
739 char *uuid
= cmd
, *pin
, *pos
;
740 u8 addr_buf
[ETH_ALEN
], *addr
= NULL
;
741 pin
= os_strchr(uuid
, ' ');
745 pos
= os_strchr(pin
, ' ');
748 if (hwaddr_aton(pos
, addr_buf
) == 0)
751 return wpas_wps_er_add_pin(wpa_s
, addr
, uuid
, pin
);
755 static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant
*wpa_s
,
758 char *uuid
= cmd
, *pin
;
759 pin
= os_strchr(uuid
, ' ');
763 return wpas_wps_er_learn(wpa_s
, uuid
, pin
);
767 static int wpa_supplicant_ctrl_iface_wps_er_set_config(
768 struct wpa_supplicant
*wpa_s
, char *cmd
)
770 char *uuid
= cmd
, *id
;
771 id
= os_strchr(uuid
, ' ');
775 return wpas_wps_er_set_config(wpa_s
, uuid
, atoi(id
));
779 static int wpa_supplicant_ctrl_iface_wps_er_config(
780 struct wpa_supplicant
*wpa_s
, char *cmd
)
787 struct wps_new_ap_settings ap
;
789 pin
= os_strchr(cmd
, ' ');
794 new_ssid
= os_strchr(pin
, ' ');
795 if (new_ssid
== NULL
)
799 new_auth
= os_strchr(new_ssid
, ' ');
800 if (new_auth
== NULL
)
804 new_encr
= os_strchr(new_auth
, ' ');
805 if (new_encr
== NULL
)
809 new_key
= os_strchr(new_encr
, ' ');
814 os_memset(&ap
, 0, sizeof(ap
));
815 ap
.ssid_hex
= new_ssid
;
818 ap
.key_hex
= new_key
;
819 return wpas_wps_er_config(wpa_s
, cmd
, pin
, &ap
);
821 #endif /* CONFIG_WPS_ER */
823 #endif /* CONFIG_WPS */
826 #ifdef CONFIG_IBSS_RSN
827 static int wpa_supplicant_ctrl_iface_ibss_rsn(
828 struct wpa_supplicant
*wpa_s
, char *addr
)
832 if (hwaddr_aton(addr
, peer
)) {
833 wpa_printf(MSG_DEBUG
, "CTRL_IFACE IBSS_RSN: invalid "
834 "address '%s'", addr
);
838 wpa_printf(MSG_DEBUG
, "CTRL_IFACE IBSS_RSN " MACSTR
,
841 return ibss_rsn_start(wpa_s
->ibss_rsn
, peer
);
843 #endif /* CONFIG_IBSS_RSN */
846 static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant
*wpa_s
,
849 #ifdef IEEE8021X_EAPOL
852 struct wpa_ssid
*ssid
;
854 pos
= os_strchr(rsp
, '-');
859 pos
= os_strchr(pos
, ':');
864 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: field=%s id=%d", rsp
, id
);
865 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
866 (u8
*) pos
, os_strlen(pos
));
868 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
870 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
875 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s
, ssid
, rsp
,
877 #else /* IEEE8021X_EAPOL */
878 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: 802.1X not included");
880 #endif /* IEEE8021X_EAPOL */
884 static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant
*wpa_s
,
886 char *buf
, size_t buflen
)
888 char *pos
, *end
, tmp
[30];
889 int res
, verbose
, wps
, ret
;
891 verbose
= os_strcmp(params
, "-VERBOSE") == 0;
892 wps
= os_strcmp(params
, "-WPS") == 0;
895 if (wpa_s
->wpa_state
>= WPA_ASSOCIATED
) {
896 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
897 ret
= os_snprintf(pos
, end
- pos
, "bssid=" MACSTR
"\n",
898 MAC2STR(wpa_s
->bssid
));
899 if (ret
< 0 || ret
>= end
- pos
)
903 u8
*_ssid
= ssid
->ssid
;
904 size_t ssid_len
= ssid
->ssid_len
;
905 u8 ssid_buf
[MAX_SSID_LEN
];
907 int _res
= wpa_drv_get_ssid(wpa_s
, ssid_buf
);
914 ret
= os_snprintf(pos
, end
- pos
, "ssid=%s\nid=%d\n",
915 wpa_ssid_txt(_ssid
, ssid_len
),
917 if (ret
< 0 || ret
>= end
- pos
)
921 if (wps
&& ssid
->passphrase
&&
922 wpa_key_mgmt_wpa_psk(ssid
->key_mgmt
) &&
923 (ssid
->mode
== WPAS_MODE_AP
||
924 ssid
->mode
== WPAS_MODE_P2P_GO
)) {
925 ret
= os_snprintf(pos
, end
- pos
,
928 if (ret
< 0 || ret
>= end
- pos
)
933 ret
= os_snprintf(pos
, end
- pos
,
936 if (ret
< 0 || ret
>= end
- pos
)
941 switch (ssid
->mode
) {
942 case WPAS_MODE_INFRA
:
943 ret
= os_snprintf(pos
, end
- pos
,
947 ret
= os_snprintf(pos
, end
- pos
,
951 ret
= os_snprintf(pos
, end
- pos
,
954 case WPAS_MODE_P2P_GO
:
955 ret
= os_snprintf(pos
, end
- pos
,
958 case WPAS_MODE_P2P_GROUP_FORMATION
:
959 ret
= os_snprintf(pos
, end
- pos
,
960 "mode=P2P GO - group "
967 if (ret
< 0 || ret
>= end
- pos
)
973 if (wpa_s
->ap_iface
) {
974 pos
+= ap_ctrl_iface_wpa_get_status(wpa_s
, pos
,
978 #endif /* CONFIG_AP */
979 pos
+= wpa_sm_get_status(wpa_s
->wpa
, pos
, end
- pos
, verbose
);
981 ret
= os_snprintf(pos
, end
- pos
, "wpa_state=%s\n",
982 wpa_supplicant_state_txt(wpa_s
->wpa_state
));
983 if (ret
< 0 || ret
>= end
- pos
)
988 l2_packet_get_ip_addr(wpa_s
->l2
, tmp
, sizeof(tmp
)) >= 0) {
989 ret
= os_snprintf(pos
, end
- pos
, "ip_address=%s\n", tmp
);
990 if (ret
< 0 || ret
>= end
- pos
)
996 if (wpa_s
->global
->p2p
) {
997 ret
= os_snprintf(pos
, end
- pos
, "p2p_device_address=" MACSTR
998 "\n", MAC2STR(wpa_s
->global
->p2p_dev_addr
));
999 if (ret
< 0 || ret
>= end
- pos
)
1003 #endif /* CONFIG_P2P */
1005 ret
= os_snprintf(pos
, end
- pos
, "address=" MACSTR
"\n",
1006 MAC2STR(wpa_s
->own_addr
));
1007 if (ret
< 0 || ret
>= end
- pos
)
1012 if (wpa_s
->current_bss
&&
1013 wpa_bss_get_vendor_ie(wpa_s
->current_bss
, HS20_IE_VENDOR_TYPE
)) {
1014 ret
= os_snprintf(pos
, end
- pos
, "hs20=1\n");
1015 if (ret
< 0 || ret
>= end
- pos
)
1019 #endif /* CONFIG_HS20 */
1021 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) ||
1022 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
1023 res
= eapol_sm_get_status(wpa_s
->eapol
, pos
, end
- pos
,
1029 res
= rsn_preauth_get_status(wpa_s
->wpa
, pos
, end
- pos
, verbose
);
1037 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant
*wpa_s
,
1042 struct wpa_ssid
*ssid
;
1045 /* cmd: "<network id> <BSSID>" */
1046 pos
= os_strchr(cmd
, ' ');
1051 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: id=%d bssid='%s'", id
, pos
);
1052 if (hwaddr_aton(pos
, bssid
)) {
1053 wpa_printf(MSG_DEBUG
,"CTRL_IFACE: invalid BSSID '%s'", pos
);
1057 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1059 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
1064 os_memcpy(ssid
->bssid
, bssid
, ETH_ALEN
);
1065 ssid
->bssid_set
= !is_zero_ether_addr(bssid
);
1071 static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant
*wpa_s
,
1072 char *cmd
, char *buf
,
1076 struct wpa_blacklist
*e
;
1080 /* cmd: "BLACKLIST [<BSSID>]" */
1084 e
= wpa_s
->blacklist
;
1086 ret
= os_snprintf(pos
, end
- pos
, MACSTR
"\n",
1088 if (ret
< 0 || ret
>= end
- pos
)
1097 if (os_strncmp(cmd
, "clear", 5) == 0) {
1098 wpa_blacklist_clear(wpa_s
);
1099 os_memcpy(buf
, "OK\n", 3);
1103 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd
);
1104 if (hwaddr_aton(cmd
, bssid
)) {
1105 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: invalid BSSID '%s'", cmd
);
1110 * Add the BSSID twice, so its count will be 2, causing it to be
1111 * skipped when processing scan results.
1113 ret
= wpa_blacklist_add(wpa_s
, bssid
);
1116 ret
= wpa_blacklist_add(wpa_s
, bssid
);
1119 os_memcpy(buf
, "OK\n", 3);
1124 extern int wpa_debug_level
;
1125 extern int wpa_debug_timestamp
;
1127 static const char * debug_level_str(int level
)
1148 static int str_to_debug_level(const char *s
)
1150 if (os_strcasecmp(s
, "EXCESSIVE") == 0)
1151 return MSG_EXCESSIVE
;
1152 if (os_strcasecmp(s
, "MSGDUMP") == 0)
1154 if (os_strcasecmp(s
, "DEBUG") == 0)
1156 if (os_strcasecmp(s
, "INFO") == 0)
1158 if (os_strcasecmp(s
, "WARNING") == 0)
1160 if (os_strcasecmp(s
, "ERROR") == 0)
1166 static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant
*wpa_s
,
1167 char *cmd
, char *buf
,
1170 char *pos
, *end
, *stamp
;
1177 /* cmd: "LOG_LEVEL [<level>]" */
1181 ret
= os_snprintf(pos
, end
- pos
, "Current level: %s\n"
1183 debug_level_str(wpa_debug_level
),
1184 wpa_debug_timestamp
);
1185 if (ret
< 0 || ret
>= end
- pos
)
1194 stamp
= os_strchr(cmd
, ' ');
1197 while (*stamp
== ' ') {
1202 if (cmd
&& os_strlen(cmd
)) {
1203 int level
= str_to_debug_level(cmd
);
1206 wpa_debug_level
= level
;
1209 if (stamp
&& os_strlen(stamp
))
1210 wpa_debug_timestamp
= atoi(stamp
);
1212 os_memcpy(buf
, "OK\n", 3);
1217 static int wpa_supplicant_ctrl_iface_list_networks(
1218 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
1221 struct wpa_ssid
*ssid
;
1226 ret
= os_snprintf(pos
, end
- pos
,
1227 "network id / ssid / bssid / flags\n");
1228 if (ret
< 0 || ret
>= end
- pos
)
1232 ssid
= wpa_s
->conf
->ssid
;
1234 ret
= os_snprintf(pos
, end
- pos
, "%d\t%s",
1236 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
));
1237 if (ret
< 0 || ret
>= end
- pos
)
1240 if (ssid
->bssid_set
) {
1241 ret
= os_snprintf(pos
, end
- pos
, "\t" MACSTR
,
1242 MAC2STR(ssid
->bssid
));
1244 ret
= os_snprintf(pos
, end
- pos
, "\tany");
1246 if (ret
< 0 || ret
>= end
- pos
)
1249 ret
= os_snprintf(pos
, end
- pos
, "\t%s%s%s",
1250 ssid
== wpa_s
->current_ssid
?
1252 ssid
->disabled
? "[DISABLED]" : "",
1253 ssid
->disabled
== 2 ? "[P2P-PERSISTENT]" :
1255 if (ret
< 0 || ret
>= end
- pos
)
1258 ret
= os_snprintf(pos
, end
- pos
, "\n");
1259 if (ret
< 0 || ret
>= end
- pos
)
1270 static char * wpa_supplicant_cipher_txt(char *pos
, char *end
, int cipher
)
1273 ret
= os_snprintf(pos
, end
- pos
, "-");
1274 if (ret
< 0 || ret
>= end
- pos
)
1277 if (cipher
& WPA_CIPHER_NONE
) {
1278 ret
= os_snprintf(pos
, end
- pos
, "%sNONE", first
? "" : "+");
1279 if (ret
< 0 || ret
>= end
- pos
)
1284 if (cipher
& WPA_CIPHER_WEP40
) {
1285 ret
= os_snprintf(pos
, end
- pos
, "%sWEP40", first
? "" : "+");
1286 if (ret
< 0 || ret
>= end
- pos
)
1291 if (cipher
& WPA_CIPHER_WEP104
) {
1292 ret
= os_snprintf(pos
, end
- pos
, "%sWEP104",
1294 if (ret
< 0 || ret
>= end
- pos
)
1299 if (cipher
& WPA_CIPHER_TKIP
) {
1300 ret
= os_snprintf(pos
, end
- pos
, "%sTKIP", first
? "" : "+");
1301 if (ret
< 0 || ret
>= end
- pos
)
1306 if (cipher
& WPA_CIPHER_CCMP
) {
1307 ret
= os_snprintf(pos
, end
- pos
, "%sCCMP", first
? "" : "+");
1308 if (ret
< 0 || ret
>= end
- pos
)
1317 static char * wpa_supplicant_ie_txt(char *pos
, char *end
, const char *proto
,
1318 const u8
*ie
, size_t ie_len
)
1320 struct wpa_ie_data data
;
1323 ret
= os_snprintf(pos
, end
- pos
, "[%s-", proto
);
1324 if (ret
< 0 || ret
>= end
- pos
)
1328 if (wpa_parse_wpa_ie(ie
, ie_len
, &data
) < 0) {
1329 ret
= os_snprintf(pos
, end
- pos
, "?]");
1330 if (ret
< 0 || ret
>= end
- pos
)
1337 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X
) {
1338 ret
= os_snprintf(pos
, end
- pos
, "%sEAP", first
? "" : "+");
1339 if (ret
< 0 || ret
>= end
- pos
)
1344 if (data
.key_mgmt
& WPA_KEY_MGMT_PSK
) {
1345 ret
= os_snprintf(pos
, end
- pos
, "%sPSK", first
? "" : "+");
1346 if (ret
< 0 || ret
>= end
- pos
)
1351 if (data
.key_mgmt
& WPA_KEY_MGMT_WPA_NONE
) {
1352 ret
= os_snprintf(pos
, end
- pos
, "%sNone", first
? "" : "+");
1353 if (ret
< 0 || ret
>= end
- pos
)
1358 #ifdef CONFIG_IEEE80211R
1359 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_IEEE8021X
) {
1360 ret
= os_snprintf(pos
, end
- pos
, "%sFT/EAP",
1362 if (ret
< 0 || ret
>= end
- pos
)
1367 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_PSK
) {
1368 ret
= os_snprintf(pos
, end
- pos
, "%sFT/PSK",
1370 if (ret
< 0 || ret
>= end
- pos
)
1375 #endif /* CONFIG_IEEE80211R */
1376 #ifdef CONFIG_IEEE80211W
1377 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SHA256
) {
1378 ret
= os_snprintf(pos
, end
- pos
, "%sEAP-SHA256",
1380 if (ret
< 0 || ret
>= end
- pos
)
1385 if (data
.key_mgmt
& WPA_KEY_MGMT_PSK_SHA256
) {
1386 ret
= os_snprintf(pos
, end
- pos
, "%sPSK-SHA256",
1388 if (ret
< 0 || ret
>= end
- pos
)
1393 #endif /* CONFIG_IEEE80211W */
1395 pos
= wpa_supplicant_cipher_txt(pos
, end
, data
.pairwise_cipher
);
1397 if (data
.capabilities
& WPA_CAPABILITY_PREAUTH
) {
1398 ret
= os_snprintf(pos
, end
- pos
, "-preauth");
1399 if (ret
< 0 || ret
>= end
- pos
)
1404 ret
= os_snprintf(pos
, end
- pos
, "]");
1405 if (ret
< 0 || ret
>= end
- pos
)
1414 static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant
*wpa_s
,
1415 char *pos
, char *end
,
1416 struct wpabuf
*wps_ie
)
1423 if (wps_is_selected_pbc_registrar(wps_ie
))
1426 else if (wps_is_addr_authorized(wps_ie
, wpa_s
->own_addr
, 0))
1428 #endif /* CONFIG_WPS2 */
1429 else if (wps_is_selected_pin_registrar(wps_ie
))
1434 ret
= os_snprintf(pos
, end
- pos
, "%s", txt
);
1435 if (ret
>= 0 && ret
< end
- pos
)
1437 wpabuf_free(wps_ie
);
1440 #endif /* CONFIG_WPS */
1443 static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant
*wpa_s
,
1444 char *pos
, char *end
,
1445 const struct wpa_bss
*bss
)
1448 struct wpabuf
*wps_ie
;
1449 wps_ie
= wpa_bss_get_vendor_ie_multi(bss
, WPS_IE_VENDOR_TYPE
);
1450 return wpa_supplicant_wps_ie_txt_buf(wpa_s
, pos
, end
, wps_ie
);
1451 #else /* CONFIG_WPS */
1453 #endif /* CONFIG_WPS */
1457 /* Format one result on one text line into a buffer. */
1458 static int wpa_supplicant_ctrl_iface_scan_result(
1459 struct wpa_supplicant
*wpa_s
,
1460 const struct wpa_bss
*bss
, char *buf
, size_t buflen
)
1464 const u8
*ie
, *ie2
, *p2p
;
1466 p2p
= wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
);
1467 if (p2p
&& bss
->ssid_len
== P2P_WILDCARD_SSID_LEN
&&
1468 os_memcmp(bss
->ssid
, P2P_WILDCARD_SSID
, P2P_WILDCARD_SSID_LEN
) ==
1470 return 0; /* Do not show P2P listen discovery results here */
1475 ret
= os_snprintf(pos
, end
- pos
, MACSTR
"\t%d\t%d\t",
1476 MAC2STR(bss
->bssid
), bss
->freq
, bss
->level
);
1477 if (ret
< 0 || ret
>= end
- pos
)
1480 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
1482 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA", ie
, 2 + ie
[1]);
1483 ie2
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
1485 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA2", ie2
, 2 + ie2
[1]);
1486 pos
= wpa_supplicant_wps_ie_txt(wpa_s
, pos
, end
, bss
);
1487 if (!ie
&& !ie2
&& bss
->caps
& IEEE80211_CAP_PRIVACY
) {
1488 ret
= os_snprintf(pos
, end
- pos
, "[WEP]");
1489 if (ret
< 0 || ret
>= end
- pos
)
1493 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
1494 ret
= os_snprintf(pos
, end
- pos
, "[IBSS]");
1495 if (ret
< 0 || ret
>= end
- pos
)
1499 if (bss
->caps
& IEEE80211_CAP_ESS
) {
1500 ret
= os_snprintf(pos
, end
- pos
, "[ESS]");
1501 if (ret
< 0 || ret
>= end
- pos
)
1506 ret
= os_snprintf(pos
, end
- pos
, "[P2P]");
1507 if (ret
< 0 || ret
>= end
- pos
)
1512 if (wpa_bss_get_vendor_ie(bss
, HS20_IE_VENDOR_TYPE
)) {
1513 ret
= os_snprintf(pos
, end
- pos
, "[HS20]");
1514 if (ret
< 0 || ret
>= end
- pos
)
1518 #endif /* CONFIG_HS20 */
1520 ret
= os_snprintf(pos
, end
- pos
, "\t%s",
1521 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
1522 if (ret
< 0 || ret
>= end
- pos
)
1526 ret
= os_snprintf(pos
, end
- pos
, "\n");
1527 if (ret
< 0 || ret
>= end
- pos
)
1535 static int wpa_supplicant_ctrl_iface_scan_results(
1536 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
1539 struct wpa_bss
*bss
;
1544 ret
= os_snprintf(pos
, end
- pos
, "bssid / frequency / signal level / "
1546 if (ret
< 0 || ret
>= end
- pos
)
1550 dl_list_for_each(bss
, &wpa_s
->bss_id
, struct wpa_bss
, list_id
) {
1551 ret
= wpa_supplicant_ctrl_iface_scan_result(wpa_s
, bss
, pos
,
1553 if (ret
< 0 || ret
>= end
- pos
)
1562 static int wpa_supplicant_ctrl_iface_select_network(
1563 struct wpa_supplicant
*wpa_s
, char *cmd
)
1566 struct wpa_ssid
*ssid
;
1568 /* cmd: "<network id>" or "any" */
1569 if (os_strcmp(cmd
, "any") == 0) {
1570 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SELECT_NETWORK any");
1574 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SELECT_NETWORK id=%d", id
);
1576 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1578 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
1579 "network id=%d", id
);
1582 if (ssid
->disabled
== 2) {
1583 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
1584 "SELECT_NETWORK with persistent P2P group");
1589 wpa_supplicant_select_network(wpa_s
, ssid
);
1595 static int wpa_supplicant_ctrl_iface_enable_network(
1596 struct wpa_supplicant
*wpa_s
, char *cmd
)
1599 struct wpa_ssid
*ssid
;
1601 /* cmd: "<network id>" or "all" */
1602 if (os_strcmp(cmd
, "all") == 0) {
1603 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ENABLE_NETWORK all");
1607 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ENABLE_NETWORK id=%d", id
);
1609 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1611 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
1612 "network id=%d", id
);
1615 if (ssid
->disabled
== 2) {
1616 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
1617 "ENABLE_NETWORK with persistent P2P group");
1621 if (os_strstr(cmd
, " no-connect")) {
1626 wpa_supplicant_enable_network(wpa_s
, ssid
);
1632 static int wpa_supplicant_ctrl_iface_disable_network(
1633 struct wpa_supplicant
*wpa_s
, char *cmd
)
1636 struct wpa_ssid
*ssid
;
1638 /* cmd: "<network id>" or "all" */
1639 if (os_strcmp(cmd
, "all") == 0) {
1640 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DISABLE_NETWORK all");
1644 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DISABLE_NETWORK id=%d", id
);
1646 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1648 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
1649 "network id=%d", id
);
1652 if (ssid
->disabled
== 2) {
1653 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
1654 "DISABLE_NETWORK with persistent P2P "
1659 wpa_supplicant_disable_network(wpa_s
, ssid
);
1665 static int wpa_supplicant_ctrl_iface_add_network(
1666 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
1668 struct wpa_ssid
*ssid
;
1671 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ADD_NETWORK");
1673 ssid
= wpa_config_add_network(wpa_s
->conf
);
1677 wpas_notify_network_added(wpa_s
, ssid
);
1680 wpa_config_set_network_defaults(ssid
);
1682 ret
= os_snprintf(buf
, buflen
, "%d\n", ssid
->id
);
1683 if (ret
< 0 || (size_t) ret
>= buflen
)
1689 static int wpa_supplicant_ctrl_iface_remove_network(
1690 struct wpa_supplicant
*wpa_s
, char *cmd
)
1693 struct wpa_ssid
*ssid
;
1695 /* cmd: "<network id>" or "all" */
1696 if (os_strcmp(cmd
, "all") == 0) {
1697 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_NETWORK all");
1698 ssid
= wpa_s
->conf
->ssid
;
1700 struct wpa_ssid
*remove_ssid
= ssid
;
1703 wpas_notify_network_removed(wpa_s
, remove_ssid
);
1704 wpa_config_remove_network(wpa_s
->conf
, id
);
1706 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
1707 if (wpa_s
->current_ssid
) {
1709 wpa_s
->sme
.prev_bssid_set
= 0;
1710 #endif /* CONFIG_SME */
1711 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
1712 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
1713 wpa_supplicant_disassociate(wpa_s
,
1714 WLAN_REASON_DEAUTH_LEAVING
);
1720 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_NETWORK id=%d", id
);
1722 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1724 wpas_notify_network_removed(wpa_s
, ssid
);
1726 wpa_config_remove_network(wpa_s
->conf
, id
) < 0) {
1727 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
1732 if (ssid
== wpa_s
->current_ssid
|| wpa_s
->current_ssid
== NULL
) {
1734 wpa_s
->sme
.prev_bssid_set
= 0;
1735 #endif /* CONFIG_SME */
1737 * Invalidate the EAP session cache if the current or
1738 * previously used network is removed.
1740 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
1743 if (ssid
== wpa_s
->current_ssid
) {
1744 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
1745 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
1747 wpa_supplicant_disassociate(wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1754 static int wpa_supplicant_ctrl_iface_set_network(
1755 struct wpa_supplicant
*wpa_s
, char *cmd
)
1758 struct wpa_ssid
*ssid
;
1761 /* cmd: "<network id> <variable name> <value>" */
1762 name
= os_strchr(cmd
, ' ');
1767 value
= os_strchr(name
, ' ');
1773 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
1775 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
1776 (u8
*) value
, os_strlen(value
));
1778 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1780 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
1785 if (wpa_config_set(ssid
, name
, value
, 0) < 0) {
1786 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to set network "
1787 "variable '%s'", name
);
1791 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, ssid
);
1793 if (wpa_s
->current_ssid
== ssid
|| wpa_s
->current_ssid
== NULL
) {
1795 * Invalidate the EAP session cache if anything in the current
1796 * or previously used configuration changes.
1798 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
1801 if ((os_strcmp(name
, "psk") == 0 &&
1802 value
[0] == '"' && ssid
->ssid_len
) ||
1803 (os_strcmp(name
, "ssid") == 0 && ssid
->passphrase
))
1804 wpa_config_update_psk(ssid
);
1805 else if (os_strcmp(name
, "priority") == 0)
1806 wpa_config_update_prio_list(wpa_s
->conf
);
1812 static int wpa_supplicant_ctrl_iface_get_network(
1813 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
1817 struct wpa_ssid
*ssid
;
1820 /* cmd: "<network id> <variable name>" */
1821 name
= os_strchr(cmd
, ' ');
1822 if (name
== NULL
|| buflen
== 0)
1827 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
1830 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1832 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
1837 value
= wpa_config_get_no_key(ssid
, name
);
1838 if (value
== NULL
) {
1839 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to get network "
1840 "variable '%s'", name
);
1844 res
= os_strlcpy(buf
, value
, buflen
);
1845 if (res
>= buflen
) {
1856 static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant
*wpa_s
,
1857 char *buf
, size_t buflen
)
1860 struct wpa_cred
*cred
;
1865 ret
= os_snprintf(pos
, end
- pos
,
1866 "cred id / realm / username / domain / imsi\n");
1867 if (ret
< 0 || ret
>= end
- pos
)
1871 cred
= wpa_s
->conf
->cred
;
1873 ret
= os_snprintf(pos
, end
- pos
, "%d\t%s\t%s\t%s\t%s\n",
1874 cred
->id
, cred
->realm
? cred
->realm
: "",
1875 cred
->username
? cred
->username
: "",
1876 cred
->domain
? cred
->domain
: "",
1877 cred
->imsi
? cred
->imsi
: "");
1878 if (ret
< 0 || ret
>= end
- pos
)
1889 static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant
*wpa_s
,
1890 char *buf
, size_t buflen
)
1892 struct wpa_cred
*cred
;
1895 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ADD_CRED");
1897 cred
= wpa_config_add_cred(wpa_s
->conf
);
1901 ret
= os_snprintf(buf
, buflen
, "%d\n", cred
->id
);
1902 if (ret
< 0 || (size_t) ret
>= buflen
)
1908 static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant
*wpa_s
,
1912 struct wpa_cred
*cred
;
1914 /* cmd: "<cred id>" or "all" */
1915 if (os_strcmp(cmd
, "all") == 0) {
1916 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED all");
1917 cred
= wpa_s
->conf
->cred
;
1921 wpa_config_remove_cred(wpa_s
->conf
, id
);
1927 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED id=%d", id
);
1929 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
1931 wpa_config_remove_cred(wpa_s
->conf
, id
) < 0) {
1932 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred id=%d",
1941 static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant
*wpa_s
,
1945 struct wpa_cred
*cred
;
1948 /* cmd: "<cred id> <variable name> <value>" */
1949 name
= os_strchr(cmd
, ' ');
1954 value
= os_strchr(name
, ' ');
1960 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SET_CRED id=%d name='%s'",
1962 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
1963 (u8
*) value
, os_strlen(value
));
1965 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
1967 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred id=%d",
1972 if (wpa_config_set_cred(cred
, name
, value
, 0) < 0) {
1973 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to set cred "
1974 "variable '%s'", name
);
1982 #ifndef CONFIG_NO_CONFIG_WRITE
1983 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant
*wpa_s
)
1987 if (!wpa_s
->conf
->update_config
) {
1988 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
1989 "to update configuration (update_config=0)");
1993 ret
= wpa_config_write(wpa_s
->confname
, wpa_s
->conf
);
1995 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Failed to "
1996 "update configuration");
1998 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Configuration"
2004 #endif /* CONFIG_NO_CONFIG_WRITE */
2007 static int ctrl_iface_get_capability_pairwise(int res
, char *strict
,
2008 struct wpa_driver_capa
*capa
,
2009 char *buf
, size_t buflen
)
2021 len
= os_strlcpy(buf
, "CCMP TKIP NONE", buflen
);
2027 if (capa
->enc
& WPA_DRIVER_CAPA_ENC_CCMP
) {
2028 ret
= os_snprintf(pos
, end
- pos
, "%sCCMP", first
? "" : " ");
2029 if (ret
< 0 || ret
>= end
- pos
)
2035 if (capa
->enc
& WPA_DRIVER_CAPA_ENC_TKIP
) {
2036 ret
= os_snprintf(pos
, end
- pos
, "%sTKIP", first
? "" : " ");
2037 if (ret
< 0 || ret
>= end
- pos
)
2043 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
) {
2044 ret
= os_snprintf(pos
, end
- pos
, "%sNONE", first
? "" : " ");
2045 if (ret
< 0 || ret
>= end
- pos
)
2055 static int ctrl_iface_get_capability_group(int res
, char *strict
,
2056 struct wpa_driver_capa
*capa
,
2057 char *buf
, size_t buflen
)
2069 len
= os_strlcpy(buf
, "CCMP TKIP WEP104 WEP40", buflen
);
2075 if (capa
->enc
& WPA_DRIVER_CAPA_ENC_CCMP
) {
2076 ret
= os_snprintf(pos
, end
- pos
, "%sCCMP", first
? "" : " ");
2077 if (ret
< 0 || ret
>= end
- pos
)
2083 if (capa
->enc
& WPA_DRIVER_CAPA_ENC_TKIP
) {
2084 ret
= os_snprintf(pos
, end
- pos
, "%sTKIP", first
? "" : " ");
2085 if (ret
< 0 || ret
>= end
- pos
)
2091 if (capa
->enc
& WPA_DRIVER_CAPA_ENC_WEP104
) {
2092 ret
= os_snprintf(pos
, end
- pos
, "%sWEP104",
2094 if (ret
< 0 || ret
>= end
- pos
)
2100 if (capa
->enc
& WPA_DRIVER_CAPA_ENC_WEP40
) {
2101 ret
= os_snprintf(pos
, end
- pos
, "%sWEP40", first
? "" : " ");
2102 if (ret
< 0 || ret
>= end
- pos
)
2112 static int ctrl_iface_get_capability_key_mgmt(int res
, char *strict
,
2113 struct wpa_driver_capa
*capa
,
2114 char *buf
, size_t buflen
)
2126 len
= os_strlcpy(buf
, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
2133 ret
= os_snprintf(pos
, end
- pos
, "NONE IEEE8021X");
2134 if (ret
< 0 || ret
>= end
- pos
)
2138 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
2139 WPA_DRIVER_CAPA_KEY_MGMT_WPA2
)) {
2140 ret
= os_snprintf(pos
, end
- pos
, " WPA-EAP");
2141 if (ret
< 0 || ret
>= end
- pos
)
2146 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
|
2147 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
)) {
2148 ret
= os_snprintf(pos
, end
- pos
, " WPA-PSK");
2149 if (ret
< 0 || ret
>= end
- pos
)
2154 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
) {
2155 ret
= os_snprintf(pos
, end
- pos
, " WPA-NONE");
2156 if (ret
< 0 || ret
>= end
- pos
)
2165 static int ctrl_iface_get_capability_proto(int res
, char *strict
,
2166 struct wpa_driver_capa
*capa
,
2167 char *buf
, size_t buflen
)
2179 len
= os_strlcpy(buf
, "RSN WPA", buflen
);
2185 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA2
|
2186 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
)) {
2187 ret
= os_snprintf(pos
, end
- pos
, "%sRSN", first
? "" : " ");
2188 if (ret
< 0 || ret
>= end
- pos
)
2194 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
2195 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
)) {
2196 ret
= os_snprintf(pos
, end
- pos
, "%sWPA", first
? "" : " ");
2197 if (ret
< 0 || ret
>= end
- pos
)
2207 static int ctrl_iface_get_capability_auth_alg(int res
, char *strict
,
2208 struct wpa_driver_capa
*capa
,
2209 char *buf
, size_t buflen
)
2221 len
= os_strlcpy(buf
, "OPEN SHARED LEAP", buflen
);
2227 if (capa
->auth
& (WPA_DRIVER_AUTH_OPEN
)) {
2228 ret
= os_snprintf(pos
, end
- pos
, "%sOPEN", first
? "" : " ");
2229 if (ret
< 0 || ret
>= end
- pos
)
2235 if (capa
->auth
& (WPA_DRIVER_AUTH_SHARED
)) {
2236 ret
= os_snprintf(pos
, end
- pos
, "%sSHARED",
2238 if (ret
< 0 || ret
>= end
- pos
)
2244 if (capa
->auth
& (WPA_DRIVER_AUTH_LEAP
)) {
2245 ret
= os_snprintf(pos
, end
- pos
, "%sLEAP", first
? "" : " ");
2246 if (ret
< 0 || ret
>= end
- pos
)
2256 static int wpa_supplicant_ctrl_iface_get_capability(
2257 struct wpa_supplicant
*wpa_s
, const char *_field
, char *buf
,
2260 struct wpa_driver_capa capa
;
2266 /* Determine whether or not strict checking was requested */
2267 len
= os_strlcpy(field
, _field
, sizeof(field
));
2268 if (len
>= sizeof(field
))
2270 strict
= os_strchr(field
, ' ');
2271 if (strict
!= NULL
) {
2273 if (os_strcmp(strict
, "strict") != 0)
2277 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
2278 field
, strict
? strict
: "");
2280 if (os_strcmp(field
, "eap") == 0) {
2281 return eap_get_names(buf
, buflen
);
2284 res
= wpa_drv_get_capa(wpa_s
, &capa
);
2286 if (os_strcmp(field
, "pairwise") == 0)
2287 return ctrl_iface_get_capability_pairwise(res
, strict
, &capa
,
2290 if (os_strcmp(field
, "group") == 0)
2291 return ctrl_iface_get_capability_group(res
, strict
, &capa
,
2294 if (os_strcmp(field
, "key_mgmt") == 0)
2295 return ctrl_iface_get_capability_key_mgmt(res
, strict
, &capa
,
2298 if (os_strcmp(field
, "proto") == 0)
2299 return ctrl_iface_get_capability_proto(res
, strict
, &capa
,
2302 if (os_strcmp(field
, "auth_alg") == 0)
2303 return ctrl_iface_get_capability_auth_alg(res
, strict
, &capa
,
2306 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
2313 #ifdef CONFIG_INTERWORKING
2314 static char * anqp_add_hex(char *pos
, char *end
, const char *title
,
2315 struct wpabuf
*data
)
2325 ret
= os_snprintf(pos
, end
- pos
, "%s=", title
);
2326 if (ret
< 0 || ret
>= end
- pos
)
2330 d
= wpabuf_head_u8(data
);
2331 for (i
= 0; i
< wpabuf_len(data
); i
++) {
2332 ret
= os_snprintf(pos
, end
- pos
, "%02x", *d
++);
2333 if (ret
< 0 || ret
>= end
- pos
)
2338 ret
= os_snprintf(pos
, end
- pos
, "\n");
2339 if (ret
< 0 || ret
>= end
- pos
)
2345 #endif /* CONFIG_INTERWORKING */
2348 static int print_bss_info(struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
,
2349 unsigned long mask
, char *buf
, size_t buflen
)
2359 if (mask
& WPA_BSS_MASK_ID
) {
2360 ret
= os_snprintf(pos
, end
- pos
, "id=%u\n", bss
->id
);
2361 if (ret
< 0 || ret
>= end
- pos
)
2366 if (mask
& WPA_BSS_MASK_BSSID
) {
2367 ret
= os_snprintf(pos
, end
- pos
, "bssid=" MACSTR
"\n",
2368 MAC2STR(bss
->bssid
));
2369 if (ret
< 0 || ret
>= end
- pos
)
2374 if (mask
& WPA_BSS_MASK_FREQ
) {
2375 ret
= os_snprintf(pos
, end
- pos
, "freq=%d\n", bss
->freq
);
2376 if (ret
< 0 || ret
>= end
- pos
)
2381 if (mask
& WPA_BSS_MASK_BEACON_INT
) {
2382 ret
= os_snprintf(pos
, end
- pos
, "beacon_int=%d\n",
2384 if (ret
< 0 || ret
>= end
- pos
)
2389 if (mask
& WPA_BSS_MASK_CAPABILITIES
) {
2390 ret
= os_snprintf(pos
, end
- pos
, "capabilities=0x%04x\n",
2392 if (ret
< 0 || ret
>= end
- pos
)
2397 if (mask
& WPA_BSS_MASK_QUAL
) {
2398 ret
= os_snprintf(pos
, end
- pos
, "qual=%d\n", bss
->qual
);
2399 if (ret
< 0 || ret
>= end
- pos
)
2404 if (mask
& WPA_BSS_MASK_NOISE
) {
2405 ret
= os_snprintf(pos
, end
- pos
, "noise=%d\n", bss
->noise
);
2406 if (ret
< 0 || ret
>= end
- pos
)
2411 if (mask
& WPA_BSS_MASK_LEVEL
) {
2412 ret
= os_snprintf(pos
, end
- pos
, "level=%d\n", bss
->level
);
2413 if (ret
< 0 || ret
>= end
- pos
)
2418 if (mask
& WPA_BSS_MASK_TSF
) {
2419 ret
= os_snprintf(pos
, end
- pos
, "tsf=%016llu\n",
2420 (unsigned long long) bss
->tsf
);
2421 if (ret
< 0 || ret
>= end
- pos
)
2426 if (mask
& WPA_BSS_MASK_AGE
) {
2430 ret
= os_snprintf(pos
, end
- pos
, "age=%d\n",
2431 (int) (now
.sec
- bss
->last_update
.sec
));
2432 if (ret
< 0 || ret
>= end
- pos
)
2437 if (mask
& WPA_BSS_MASK_IE
) {
2438 ret
= os_snprintf(pos
, end
- pos
, "ie=");
2439 if (ret
< 0 || ret
>= end
- pos
)
2443 ie
= (const u8
*) (bss
+ 1);
2444 for (i
= 0; i
< bss
->ie_len
; i
++) {
2445 ret
= os_snprintf(pos
, end
- pos
, "%02x", *ie
++);
2446 if (ret
< 0 || ret
>= end
- pos
)
2451 ret
= os_snprintf(pos
, end
- pos
, "\n");
2452 if (ret
< 0 || ret
>= end
- pos
)
2457 if (mask
& WPA_BSS_MASK_FLAGS
) {
2458 ret
= os_snprintf(pos
, end
- pos
, "flags=");
2459 if (ret
< 0 || ret
>= end
- pos
)
2463 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
2465 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA", ie
,
2467 ie2
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
2469 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA2", ie2
,
2471 pos
= wpa_supplicant_wps_ie_txt(wpa_s
, pos
, end
, bss
);
2472 if (!ie
&& !ie2
&& bss
->caps
& IEEE80211_CAP_PRIVACY
) {
2473 ret
= os_snprintf(pos
, end
- pos
, "[WEP]");
2474 if (ret
< 0 || ret
>= end
- pos
)
2478 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
2479 ret
= os_snprintf(pos
, end
- pos
, "[IBSS]");
2480 if (ret
< 0 || ret
>= end
- pos
)
2484 if (bss
->caps
& IEEE80211_CAP_ESS
) {
2485 ret
= os_snprintf(pos
, end
- pos
, "[ESS]");
2486 if (ret
< 0 || ret
>= end
- pos
)
2490 if (wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
)) {
2491 ret
= os_snprintf(pos
, end
- pos
, "[P2P]");
2492 if (ret
< 0 || ret
>= end
- pos
)
2497 if (wpa_bss_get_vendor_ie(bss
, HS20_IE_VENDOR_TYPE
)) {
2498 ret
= os_snprintf(pos
, end
- pos
, "[HS20]");
2499 if (ret
< 0 || ret
>= end
- pos
)
2503 #endif /* CONFIG_HS20 */
2505 ret
= os_snprintf(pos
, end
- pos
, "\n");
2506 if (ret
< 0 || ret
>= end
- pos
)
2511 if (mask
& WPA_BSS_MASK_SSID
) {
2512 ret
= os_snprintf(pos
, end
- pos
, "ssid=%s\n",
2513 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
2514 if (ret
< 0 || ret
>= end
- pos
)
2520 if (mask
& WPA_BSS_MASK_WPS_SCAN
) {
2521 ie
= (const u8
*) (bss
+ 1);
2522 ret
= wpas_wps_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
2523 if (ret
< 0 || ret
>= end
- pos
)
2527 #endif /* CONFIG_WPS */
2530 if (mask
& WPA_BSS_MASK_P2P_SCAN
) {
2531 ie
= (const u8
*) (bss
+ 1);
2532 ret
= wpas_p2p_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
2533 if (ret
< 0 || ret
>= end
- pos
)
2537 #endif /* CONFIG_P2P */
2539 #ifdef CONFIG_INTERWORKING
2540 if (mask
& WPA_BSS_MASK_INTERNETW
) {
2541 pos
= anqp_add_hex(pos
, end
, "anqp_venue_name",
2542 bss
->anqp_venue_name
);
2543 pos
= anqp_add_hex(pos
, end
, "anqp_network_auth_type",
2544 bss
->anqp_network_auth_type
);
2545 pos
= anqp_add_hex(pos
, end
, "anqp_roaming_consortium",
2546 bss
->anqp_roaming_consortium
);
2547 pos
= anqp_add_hex(pos
, end
, "anqp_ip_addr_type_availability",
2548 bss
->anqp_ip_addr_type_availability
);
2549 pos
= anqp_add_hex(pos
, end
, "anqp_nai_realm",
2550 bss
->anqp_nai_realm
);
2551 pos
= anqp_add_hex(pos
, end
, "anqp_3gpp", bss
->anqp_3gpp
);
2552 pos
= anqp_add_hex(pos
, end
, "anqp_domain_name",
2553 bss
->anqp_domain_name
);
2555 pos
= anqp_add_hex(pos
, end
, "hs20_operator_friendly_name",
2556 bss
->hs20_operator_friendly_name
);
2557 pos
= anqp_add_hex(pos
, end
, "hs20_wan_metrics",
2558 bss
->hs20_wan_metrics
);
2559 pos
= anqp_add_hex(pos
, end
, "hs20_connection_capability",
2560 bss
->hs20_connection_capability
);
2561 #endif /* CONFIG_HS20 */
2563 #endif /* CONFIG_INTERWORKING */
2569 static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant
*wpa_s
,
2570 const char *cmd
, char *buf
,
2575 struct wpa_bss
*bss
;
2576 struct wpa_bss
*bsslast
= NULL
;
2577 struct dl_list
*next
;
2581 unsigned long mask
= WPA_BSS_MASK_ALL
;
2583 if (os_strncmp(cmd
, "RANGE=", 6) == 0) {
2584 if (os_strncmp(cmd
+ 6, "ALL", 3) == 0) {
2585 bss
= dl_list_first(&wpa_s
->bss_id
, struct wpa_bss
,
2587 bsslast
= dl_list_last(&wpa_s
->bss_id
, struct wpa_bss
,
2589 } else { /* N1-N2 */
2590 unsigned int id1
, id2
;
2592 if ((ctmp
= os_strchr(cmd
+ 6, '-')) == NULL
) {
2593 wpa_printf(MSG_INFO
, "Wrong BSS range "
2598 id1
= atoi(cmd
+ 6);
2599 bss
= wpa_bss_get_id(wpa_s
, id1
);
2600 id2
= atoi(ctmp
+ 1);
2602 bsslast
= dl_list_last(&wpa_s
->bss_id
,
2606 bsslast
= wpa_bss_get_id(wpa_s
, id2
);
2607 if (bsslast
== NULL
&& bss
&& id2
> id1
) {
2608 struct wpa_bss
*tmp
= bss
;
2610 next
= tmp
->list_id
.next
;
2611 if (next
== &wpa_s
->bss_id
)
2613 tmp
= dl_list_entry(
2614 next
, struct wpa_bss
,
2623 } else if (os_strcmp(cmd
, "FIRST") == 0)
2624 bss
= dl_list_first(&wpa_s
->bss_id
, struct wpa_bss
, list_id
);
2625 else if (os_strncmp(cmd
, "ID-", 3) == 0) {
2627 bss
= wpa_bss_get_id(wpa_s
, i
);
2628 } else if (os_strncmp(cmd
, "NEXT-", 5) == 0) {
2630 bss
= wpa_bss_get_id(wpa_s
, i
);
2632 next
= bss
->list_id
.next
;
2633 if (next
== &wpa_s
->bss_id
)
2636 bss
= dl_list_entry(next
, struct wpa_bss
,
2640 } else if (os_strncmp(cmd
, "p2p_dev_addr=", 13) == 0) {
2641 if (hwaddr_aton(cmd
+ 13, bssid
) == 0)
2642 bss
= wpa_bss_get_p2p_dev_addr(wpa_s
, bssid
);
2645 #endif /* CONFIG_P2P */
2646 } else if (hwaddr_aton(cmd
, bssid
) == 0)
2647 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
2649 struct wpa_bss
*tmp
;
2652 dl_list_for_each(tmp
, &wpa_s
->bss_id
, struct wpa_bss
, list_id
)
2661 if ((ctmp
= os_strstr(cmd
, "MASK=")) != NULL
) {
2662 mask
= strtoul(ctmp
+ 5, NULL
, 0x10);
2664 mask
= WPA_BSS_MASK_ALL
;
2670 if (bsslast
== NULL
)
2673 len
= print_bss_info(wpa_s
, bss
, mask
, buf
, buflen
);
2679 next
= bss
->list_id
.next
;
2680 if (next
== &wpa_s
->bss_id
)
2682 bss
= dl_list_entry(next
, struct wpa_bss
, list_id
);
2683 } while (bss
&& len
);
2689 static int wpa_supplicant_ctrl_iface_ap_scan(
2690 struct wpa_supplicant
*wpa_s
, char *cmd
)
2692 int ap_scan
= atoi(cmd
);
2693 return wpa_supplicant_set_ap_scan(wpa_s
, ap_scan
);
2697 static int wpa_supplicant_ctrl_iface_scan_interval(
2698 struct wpa_supplicant
*wpa_s
, char *cmd
)
2700 int scan_int
= atoi(cmd
);
2701 return wpa_supplicant_set_scan_interval(wpa_s
, scan_int
);
2705 static int wpa_supplicant_ctrl_iface_bss_expire_age(
2706 struct wpa_supplicant
*wpa_s
, char *cmd
)
2708 int expire_age
= atoi(cmd
);
2709 return wpa_supplicant_set_bss_expiration_age(wpa_s
, expire_age
);
2713 static int wpa_supplicant_ctrl_iface_bss_expire_count(
2714 struct wpa_supplicant
*wpa_s
, char *cmd
)
2716 int expire_count
= atoi(cmd
);
2717 return wpa_supplicant_set_bss_expiration_count(wpa_s
, expire_count
);
2721 static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant
*wpa_s
)
2723 wpa_printf(MSG_DEBUG
, "Dropping SA without deauthentication");
2724 /* MLME-DELETEKEYS.request */
2725 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 0, 0, NULL
, 0, NULL
, 0);
2726 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 1, 0, NULL
, 0, NULL
, 0);
2727 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 2, 0, NULL
, 0, NULL
, 0);
2728 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 3, 0, NULL
, 0, NULL
, 0);
2729 #ifdef CONFIG_IEEE80211W
2730 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 4, 0, NULL
, 0, NULL
, 0);
2731 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 5, 0, NULL
, 0, NULL
, 0);
2732 #endif /* CONFIG_IEEE80211W */
2734 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, wpa_s
->bssid
, 0, 0, NULL
, 0, NULL
,
2736 /* MLME-SETPROTECTION.request(None) */
2737 wpa_drv_mlme_setprotection(wpa_s
, wpa_s
->bssid
,
2738 MLME_SETPROTECTION_PROTECT_TYPE_NONE
,
2739 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE
);
2740 wpa_sm_drop_sa(wpa_s
->wpa
);
2744 static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant
*wpa_s
,
2747 #ifdef CONFIG_NO_SCAN_PROCESSING
2749 #else /* CONFIG_NO_SCAN_PROCESSING */
2751 struct wpa_bss
*bss
;
2752 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
2754 if (hwaddr_aton(addr
, bssid
)) {
2755 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: invalid "
2756 "address '%s'", addr
);
2760 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM " MACSTR
, MAC2STR(bssid
));
2762 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
2764 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: Target AP not found "
2770 * TODO: Find best network configuration block from configuration to
2771 * allow roaming to other networks
2775 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: No network "
2776 "configuration known for the target AP");
2780 wpa_s
->reassociate
= 1;
2781 wpa_supplicant_connect(wpa_s
, bss
, ssid
);
2784 #endif /* CONFIG_NO_SCAN_PROCESSING */
2789 static int p2p_ctrl_find(struct wpa_supplicant
*wpa_s
, char *cmd
)
2791 unsigned int timeout
= atoi(cmd
);
2792 enum p2p_discovery_type type
= P2P_FIND_START_WITH_FULL
;
2793 u8 dev_id
[ETH_ALEN
], *_dev_id
= NULL
;
2796 if (os_strstr(cmd
, "type=social"))
2797 type
= P2P_FIND_ONLY_SOCIAL
;
2798 else if (os_strstr(cmd
, "type=progressive"))
2799 type
= P2P_FIND_PROGRESSIVE
;
2801 pos
= os_strstr(cmd
, "dev_id=");
2804 if (hwaddr_aton(pos
, dev_id
))
2809 return wpas_p2p_find(wpa_s
, timeout
, type
, 0, NULL
, _dev_id
);
2813 static int p2p_ctrl_connect(struct wpa_supplicant
*wpa_s
, char *cmd
,
2814 char *buf
, size_t buflen
)
2819 enum p2p_wps_method wps_method
;
2822 int persistent_group
, persistent_id
= -1;
2830 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad]
2831 * [persistent|persistent=<network id>]
2832 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc] */
2834 if (hwaddr_aton(cmd
, addr
))
2842 persistent_group
= os_strstr(pos
, " persistent") != NULL
;
2843 pos2
= os_strstr(pos
, " persistent=");
2845 struct wpa_ssid
*ssid
;
2846 persistent_id
= atoi(pos2
+ 12);
2847 ssid
= wpa_config_get_network(wpa_s
->conf
, persistent_id
);
2848 if (ssid
== NULL
|| ssid
->disabled
!= 2 ||
2849 ssid
->mode
!= WPAS_MODE_P2P_GO
) {
2850 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
2851 "SSID id=%d for persistent P2P group (GO)",
2856 join
= os_strstr(pos
, " join") != NULL
;
2857 auth
= os_strstr(pos
, " auth") != NULL
;
2858 automatic
= os_strstr(pos
, " auto") != NULL
;
2859 pd
= os_strstr(pos
, " provdisc") != NULL
;
2861 pos2
= os_strstr(pos
, " go_intent=");
2864 go_intent
= atoi(pos2
);
2865 if (go_intent
< 0 || go_intent
> 15)
2869 pos2
= os_strstr(pos
, " freq=");
2877 if (os_strncmp(pos
, "pin", 3) == 0) {
2878 /* Request random PIN (to be displayed) and enable the PIN */
2879 wps_method
= WPS_PIN_DISPLAY
;
2880 } else if (os_strncmp(pos
, "pbc", 3) == 0) {
2881 wps_method
= WPS_PBC
;
2884 pos
= os_strchr(pin
, ' ');
2885 wps_method
= WPS_PIN_KEYPAD
;
2888 if (os_strncmp(pos
, "display", 7) == 0)
2889 wps_method
= WPS_PIN_DISPLAY
;
2893 new_pin
= wpas_p2p_connect(wpa_s
, addr
, pin
, wps_method
,
2894 persistent_group
, automatic
, join
,
2895 auth
, go_intent
, freq
, persistent_id
, pd
);
2896 if (new_pin
== -2) {
2897 os_memcpy(buf
, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
2900 if (new_pin
== -3) {
2901 os_memcpy(buf
, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
2906 if (wps_method
== WPS_PIN_DISPLAY
&& pin
== NULL
) {
2907 ret
= os_snprintf(buf
, buflen
, "%08d", new_pin
);
2908 if (ret
< 0 || (size_t) ret
>= buflen
)
2913 os_memcpy(buf
, "OK\n", 3);
2918 static int p2p_ctrl_listen(struct wpa_supplicant
*wpa_s
, char *cmd
)
2920 unsigned int timeout
= atoi(cmd
);
2921 return wpas_p2p_listen(wpa_s
, timeout
);
2925 static int p2p_ctrl_prov_disc(struct wpa_supplicant
*wpa_s
, char *cmd
)
2929 enum wpas_p2p_prov_disc_use use
= WPAS_P2P_PD_FOR_GO_NEG
;
2931 /* <addr> <config method> [join|auto] */
2933 if (hwaddr_aton(cmd
, addr
))
2941 if (os_strstr(pos
, " join") != NULL
)
2942 use
= WPAS_P2P_PD_FOR_JOIN
;
2943 else if (os_strstr(pos
, " auto") != NULL
)
2944 use
= WPAS_P2P_PD_AUTO
;
2946 return wpas_p2p_prov_disc(wpa_s
, addr
, pos
, use
);
2950 static int p2p_get_passphrase(struct wpa_supplicant
*wpa_s
, char *buf
,
2953 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
2955 if (ssid
== NULL
|| ssid
->mode
!= WPAS_MODE_P2P_GO
||
2956 ssid
->passphrase
== NULL
)
2959 os_strlcpy(buf
, ssid
->passphrase
, buflen
);
2960 return os_strlen(buf
);
2964 static int p2p_ctrl_serv_disc_req(struct wpa_supplicant
*wpa_s
, char *cmd
,
2965 char *buf
, size_t buflen
)
2969 u8 dst_buf
[ETH_ALEN
], *dst
;
2970 struct wpabuf
*tlvs
;
2974 if (hwaddr_aton(cmd
, dst_buf
))
2977 if (dst
[0] == 0 && dst
[1] == 0 && dst
[2] == 0 &&
2978 dst
[3] == 0 && dst
[4] == 0 && dst
[5] == 0)
2985 if (os_strncmp(pos
, "upnp ", 5) == 0) {
2988 if (hexstr2bin(pos
, &version
, 1) < 0)
2994 ref
= wpas_p2p_sd_request_upnp(wpa_s
, dst
, version
, pos
);
2996 len
= os_strlen(pos
);
3000 tlvs
= wpabuf_alloc(len
);
3003 if (hexstr2bin(pos
, wpabuf_put(tlvs
, len
), len
) < 0) {
3008 ref
= wpas_p2p_sd_request(wpa_s
, dst
, tlvs
);
3013 res
= os_snprintf(buf
, buflen
, "%llx", (long long unsigned) ref
);
3014 if (res
< 0 || (unsigned) res
>= buflen
)
3020 static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant
*wpa_s
,
3023 long long unsigned val
;
3025 if (sscanf(cmd
, "%llx", &val
) != 1)
3028 return wpas_p2p_sd_cancel_request(wpa_s
, req
);
3032 static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant
*wpa_s
, char *cmd
)
3037 struct wpabuf
*resp_tlvs
;
3041 pos
= os_strchr(cmd
, ' ');
3049 if (hwaddr_aton(pos
, dst
))
3056 pos2
= os_strchr(pos
, ' ');
3060 dialog_token
= atoi(pos
);
3062 len
= os_strlen(pos2
);
3066 resp_tlvs
= wpabuf_alloc(len
);
3067 if (resp_tlvs
== NULL
)
3069 if (hexstr2bin(pos2
, wpabuf_put(resp_tlvs
, len
), len
) < 0) {
3070 wpabuf_free(resp_tlvs
);
3074 wpas_p2p_sd_response(wpa_s
, freq
, dst
, dialog_token
, resp_tlvs
);
3075 wpabuf_free(resp_tlvs
);
3080 static int p2p_ctrl_serv_disc_external(struct wpa_supplicant
*wpa_s
,
3083 if (os_strcmp(cmd
, "0") && os_strcmp(cmd
, "1"))
3085 wpa_s
->p2p_sd_over_ctrl_iface
= atoi(cmd
);
3090 static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant
*wpa_s
,
3095 struct wpabuf
*query
, *resp
;
3097 pos
= os_strchr(cmd
, ' ');
3102 len
= os_strlen(cmd
);
3106 query
= wpabuf_alloc(len
);
3109 if (hexstr2bin(cmd
, wpabuf_put(query
, len
), len
) < 0) {
3114 len
= os_strlen(pos
);
3120 resp
= wpabuf_alloc(len
);
3125 if (hexstr2bin(pos
, wpabuf_put(resp
, len
), len
) < 0) {
3131 if (wpas_p2p_service_add_bonjour(wpa_s
, query
, resp
) < 0) {
3140 static int p2p_ctrl_service_add_upnp(struct wpa_supplicant
*wpa_s
, char *cmd
)
3145 pos
= os_strchr(cmd
, ' ');
3150 if (hexstr2bin(cmd
, &version
, 1) < 0)
3153 return wpas_p2p_service_add_upnp(wpa_s
, version
, pos
);
3157 static int p2p_ctrl_service_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
3161 pos
= os_strchr(cmd
, ' ');
3166 if (os_strcmp(cmd
, "bonjour") == 0)
3167 return p2p_ctrl_service_add_bonjour(wpa_s
, pos
);
3168 if (os_strcmp(cmd
, "upnp") == 0)
3169 return p2p_ctrl_service_add_upnp(wpa_s
, pos
);
3170 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
3175 static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant
*wpa_s
,
3179 struct wpabuf
*query
;
3182 len
= os_strlen(cmd
);
3186 query
= wpabuf_alloc(len
);
3189 if (hexstr2bin(cmd
, wpabuf_put(query
, len
), len
) < 0) {
3194 ret
= wpas_p2p_service_del_bonjour(wpa_s
, query
);
3200 static int p2p_ctrl_service_del_upnp(struct wpa_supplicant
*wpa_s
, char *cmd
)
3205 pos
= os_strchr(cmd
, ' ');
3210 if (hexstr2bin(cmd
, &version
, 1) < 0)
3213 return wpas_p2p_service_del_upnp(wpa_s
, version
, pos
);
3217 static int p2p_ctrl_service_del(struct wpa_supplicant
*wpa_s
, char *cmd
)
3221 pos
= os_strchr(cmd
, ' ');
3226 if (os_strcmp(cmd
, "bonjour") == 0)
3227 return p2p_ctrl_service_del_bonjour(wpa_s
, pos
);
3228 if (os_strcmp(cmd
, "upnp") == 0)
3229 return p2p_ctrl_service_del_upnp(wpa_s
, pos
);
3230 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
3235 static int p2p_ctrl_reject(struct wpa_supplicant
*wpa_s
, char *cmd
)
3241 if (hwaddr_aton(cmd
, addr
))
3244 return wpas_p2p_reject(wpa_s
, addr
);
3248 static int p2p_ctrl_invite_persistent(struct wpa_supplicant
*wpa_s
, char *cmd
)
3252 struct wpa_ssid
*ssid
;
3256 pos
= os_strstr(cmd
, " peer=");
3259 if (hwaddr_aton(pos
, peer
))
3262 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3263 if (ssid
== NULL
|| ssid
->disabled
!= 2) {
3264 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
3265 "for persistent P2P group",
3270 return wpas_p2p_invite(wpa_s
, pos
? peer
: NULL
, ssid
, NULL
);
3274 static int p2p_ctrl_invite_group(struct wpa_supplicant
*wpa_s
, char *cmd
)
3277 u8 peer
[ETH_ALEN
], go_dev_addr
[ETH_ALEN
], *go_dev
= NULL
;
3279 pos
= os_strstr(cmd
, " peer=");
3285 if (hwaddr_aton(pos
, peer
)) {
3286 wpa_printf(MSG_DEBUG
, "P2P: Invalid MAC address '%s'", pos
);
3290 pos
= os_strstr(pos
, " go_dev_addr=");
3293 if (hwaddr_aton(pos
, go_dev_addr
)) {
3294 wpa_printf(MSG_DEBUG
, "P2P: Invalid MAC address '%s'",
3298 go_dev
= go_dev_addr
;
3301 return wpas_p2p_invite_group(wpa_s
, cmd
, peer
, go_dev
);
3305 static int p2p_ctrl_invite(struct wpa_supplicant
*wpa_s
, char *cmd
)
3307 if (os_strncmp(cmd
, "persistent=", 11) == 0)
3308 return p2p_ctrl_invite_persistent(wpa_s
, cmd
+ 11);
3309 if (os_strncmp(cmd
, "group=", 6) == 0)
3310 return p2p_ctrl_invite_group(wpa_s
, cmd
+ 6);
3316 static int p2p_ctrl_group_add_persistent(struct wpa_supplicant
*wpa_s
,
3317 char *cmd
, int freq
)
3320 struct wpa_ssid
*ssid
;
3323 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3324 if (ssid
== NULL
|| ssid
->disabled
!= 2) {
3325 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
3326 "for persistent P2P group",
3331 return wpas_p2p_group_add_persistent(wpa_s
, ssid
, 0, freq
);
3335 static int p2p_ctrl_group_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
3340 pos
= os_strstr(cmd
, "freq=");
3342 freq
= atoi(pos
+ 5);
3344 if (os_strncmp(cmd
, "persistent=", 11) == 0)
3345 return p2p_ctrl_group_add_persistent(wpa_s
, cmd
+ 11, freq
);
3346 if (os_strcmp(cmd
, "persistent") == 0 ||
3347 os_strncmp(cmd
, "persistent ", 11) == 0)
3348 return wpas_p2p_group_add(wpa_s
, 1, freq
);
3349 if (os_strncmp(cmd
, "freq=", 5) == 0)
3350 return wpas_p2p_group_add(wpa_s
, 0, freq
);
3352 wpa_printf(MSG_DEBUG
, "CTRL: Invalid P2P_GROUP_ADD parameters '%s'",
3358 static int p2p_ctrl_peer(struct wpa_supplicant
*wpa_s
, char *cmd
,
3359 char *buf
, size_t buflen
)
3361 u8 addr
[ETH_ALEN
], *addr_ptr
;
3363 const struct p2p_peer_info
*info
;
3365 char devtype
[WPS_DEV_TYPE_BUFSIZE
];
3366 struct wpa_ssid
*ssid
;
3368 if (!wpa_s
->global
->p2p
)
3371 if (os_strcmp(cmd
, "FIRST") == 0) {
3374 } else if (os_strncmp(cmd
, "NEXT-", 5) == 0) {
3375 if (hwaddr_aton(cmd
+ 5, addr
) < 0)
3380 if (hwaddr_aton(cmd
, addr
) < 0)
3386 info
= p2p_get_peer_info(wpa_s
->global
->p2p
, addr_ptr
, next
);
3393 res
= os_snprintf(pos
, end
- pos
, MACSTR
"\n"
3399 "serial_number=%s\n"
3400 "config_methods=0x%x\n"
3402 "group_capab=0x%x\n"
3404 MAC2STR(info
->p2p_device_addr
),
3405 wps_dev_type_bin2str(info
->pri_dev_type
,
3406 devtype
, sizeof(devtype
)),
3411 info
->serial_number
,
3412 info
->config_methods
,
3416 if (res
< 0 || res
>= end
- pos
)
3420 ssid
= wpas_p2p_get_persistent(wpa_s
, info
->p2p_device_addr
, NULL
, 0);
3422 res
= os_snprintf(pos
, end
- pos
, "persistent=%d\n", ssid
->id
);
3423 if (res
< 0 || res
>= end
- pos
)
3428 res
= p2p_get_peer_info_txt(info
, pos
, end
- pos
);
3437 static int p2p_ctrl_disallow_freq(struct wpa_supplicant
*wpa_s
,
3440 struct wpa_freq_range
*freq
= NULL
, *n
;
3441 unsigned int count
= 0, i
;
3442 const char *pos
, *pos2
, *pos3
;
3444 if (wpa_s
->global
->p2p
== NULL
)
3448 * param includes comma separated frequency range.
3449 * For example: 2412-2432,2462,5000-6000
3452 while (pos
&& pos
[0]) {
3453 n
= os_realloc(freq
,
3454 (count
+ 1) * sizeof(struct wpa_freq_range
));
3460 freq
[count
].min
= atoi(pos
);
3461 pos2
= os_strchr(pos
, '-');
3462 pos3
= os_strchr(pos
, ',');
3463 if (pos2
&& (!pos3
|| pos2
< pos3
)) {
3465 freq
[count
].max
= atoi(pos2
);
3467 freq
[count
].max
= freq
[count
].min
;
3474 for (i
= 0; i
< count
; i
++) {
3475 wpa_printf(MSG_DEBUG
, "P2P: Disallowed frequency range %u-%u",
3476 freq
[i
].min
, freq
[i
].max
);
3479 os_free(wpa_s
->global
->p2p_disallow_freq
);
3480 wpa_s
->global
->p2p_disallow_freq
= freq
;
3481 wpa_s
->global
->num_p2p_disallow_freq
= count
;
3482 wpas_p2p_update_channel_list(wpa_s
);
3487 static int p2p_ctrl_set(struct wpa_supplicant
*wpa_s
, char *cmd
)
3491 if (wpa_s
->global
->p2p
== NULL
)
3494 param
= os_strchr(cmd
, ' ');
3499 if (os_strcmp(cmd
, "discoverability") == 0) {
3500 p2p_set_client_discoverability(wpa_s
->global
->p2p
,
3505 if (os_strcmp(cmd
, "managed") == 0) {
3506 p2p_set_managed_oper(wpa_s
->global
->p2p
, atoi(param
));
3510 if (os_strcmp(cmd
, "listen_channel") == 0) {
3511 return p2p_set_listen_channel(wpa_s
->global
->p2p
, 81,
3515 if (os_strcmp(cmd
, "ssid_postfix") == 0) {
3516 return p2p_set_ssid_postfix(wpa_s
->global
->p2p
, (u8
*) param
,
3520 if (os_strcmp(cmd
, "noa") == 0) {
3522 int count
, start
, duration
;
3523 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
3524 count
= atoi(param
);
3525 pos
= os_strchr(param
, ',');
3530 pos
= os_strchr(pos
, ',');
3534 duration
= atoi(pos
);
3535 if (count
< 0 || count
> 255 || start
< 0 || duration
< 0)
3537 if (count
== 0 && duration
> 0)
3539 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
3540 "start=%d duration=%d", count
, start
, duration
);
3541 return wpas_p2p_set_noa(wpa_s
, count
, start
, duration
);
3544 if (os_strcmp(cmd
, "ps") == 0)
3545 return wpa_drv_set_p2p_powersave(wpa_s
, atoi(param
), -1, -1);
3547 if (os_strcmp(cmd
, "oppps") == 0)
3548 return wpa_drv_set_p2p_powersave(wpa_s
, -1, atoi(param
), -1);
3550 if (os_strcmp(cmd
, "ctwindow") == 0)
3551 return wpa_drv_set_p2p_powersave(wpa_s
, -1, -1, atoi(param
));
3553 if (os_strcmp(cmd
, "disabled") == 0) {
3554 wpa_s
->global
->p2p_disabled
= atoi(param
);
3555 wpa_printf(MSG_DEBUG
, "P2P functionality %s",
3556 wpa_s
->global
->p2p_disabled
?
3557 "disabled" : "enabled");
3558 if (wpa_s
->global
->p2p_disabled
) {
3559 wpas_p2p_stop_find(wpa_s
);
3560 os_memset(wpa_s
->p2p_auth_invite
, 0, ETH_ALEN
);
3561 p2p_flush(wpa_s
->global
->p2p
);
3566 if (os_strcmp(cmd
, "conc_pref") == 0) {
3567 if (os_strcmp(param
, "sta") == 0)
3568 wpa_s
->global
->conc_pref
= WPA_CONC_PREF_STA
;
3569 else if (os_strcmp(param
, "p2p") == 0)
3570 wpa_s
->global
->conc_pref
= WPA_CONC_PREF_P2P
;
3572 wpa_printf(MSG_INFO
, "Invalid conc_pref value");
3575 wpa_printf(MSG_DEBUG
, "Single channel concurrency preference: "
3580 if (os_strcmp(cmd
, "force_long_sd") == 0) {
3581 wpa_s
->force_long_sd
= atoi(param
);
3585 if (os_strcmp(cmd
, "peer_filter") == 0) {
3587 if (hwaddr_aton(param
, addr
))
3589 p2p_set_peer_filter(wpa_s
->global
->p2p
, addr
);
3593 if (os_strcmp(cmd
, "cross_connect") == 0)
3594 return wpas_p2p_set_cross_connect(wpa_s
, atoi(param
));
3596 if (os_strcmp(cmd
, "go_apsd") == 0) {
3597 if (os_strcmp(param
, "disable") == 0)
3598 wpa_s
->set_ap_uapsd
= 0;
3600 wpa_s
->set_ap_uapsd
= 1;
3601 wpa_s
->ap_uapsd
= atoi(param
);
3606 if (os_strcmp(cmd
, "client_apsd") == 0) {
3607 if (os_strcmp(param
, "disable") == 0)
3608 wpa_s
->set_sta_uapsd
= 0;
3612 /* format: BE,BK,VI,VO;max SP Length */
3614 pos
= os_strchr(param
, ',');
3619 pos
= os_strchr(pos
, ',');
3624 pos
= os_strchr(pos
, ',');
3629 /* ignore max SP Length for now */
3631 wpa_s
->set_sta_uapsd
= 1;
3632 wpa_s
->sta_uapsd
= 0;
3634 wpa_s
->sta_uapsd
|= BIT(0);
3636 wpa_s
->sta_uapsd
|= BIT(1);
3638 wpa_s
->sta_uapsd
|= BIT(2);
3640 wpa_s
->sta_uapsd
|= BIT(3);
3645 if (os_strcmp(cmd
, "disallow_freq") == 0)
3646 return p2p_ctrl_disallow_freq(wpa_s
, param
);
3648 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
3655 static int p2p_ctrl_presence_req(struct wpa_supplicant
*wpa_s
, char *cmd
)
3658 unsigned int dur1
= 0, int1
= 0, dur2
= 0, int2
= 0;
3661 pos
= os_strchr(cmd
, ' ');
3667 pos2
= os_strchr(pos
, ' ');
3675 pos
= os_strchr(pos2
, ' ');
3683 return wpas_p2p_presence_req(wpa_s
, dur1
, int1
, dur2
, int2
);
3687 static int p2p_ctrl_ext_listen(struct wpa_supplicant
*wpa_s
, char *cmd
)
3690 unsigned int period
= 0, interval
= 0;
3693 pos
= os_strchr(cmd
, ' ');
3698 interval
= atoi(pos
);
3701 return wpas_p2p_ext_listen(wpa_s
, period
, interval
);
3704 #endif /* CONFIG_P2P */
3707 #ifdef CONFIG_INTERWORKING
3708 static int ctrl_interworking_connect(struct wpa_supplicant
*wpa_s
, char *dst
)
3711 struct wpa_bss
*bss
;
3713 if (hwaddr_aton(dst
, bssid
)) {
3714 wpa_printf(MSG_DEBUG
, "Invalid BSSID '%s'", dst
);
3718 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
3720 wpa_printf(MSG_DEBUG
, "Could not find BSS " MACSTR
,
3725 return interworking_connect(wpa_s
, bss
);
3729 static int get_anqp(struct wpa_supplicant
*wpa_s
, char *dst
)
3731 u8 dst_addr
[ETH_ALEN
];
3734 #define MAX_ANQP_INFO_ID 100
3735 u16 id
[MAX_ANQP_INFO_ID
];
3738 used
= hwaddr_aton2(dst
, dst_addr
);
3742 while (num_id
< MAX_ANQP_INFO_ID
) {
3743 id
[num_id
] = atoi(pos
);
3746 pos
= os_strchr(pos
+ 1, ',');
3755 return anqp_send_req(wpa_s
, dst_addr
, id
, num_id
);
3757 #endif /* CONFIG_INTERWORKING */
3762 static int get_hs20_anqp(struct wpa_supplicant
*wpa_s
, char *dst
)
3764 u8 dst_addr
[ETH_ALEN
];
3769 used
= hwaddr_aton2(dst
, dst_addr
);
3774 int num
= atoi(pos
);
3775 if (num
<= 0 || num
> 31)
3777 subtypes
|= BIT(num
);
3778 pos
= os_strchr(pos
+ 1, ',');
3787 return hs20_anqp_send_req(wpa_s
, dst_addr
, subtypes
, NULL
, 0);
3791 static int hs20_nai_home_realm_list(struct wpa_supplicant
*wpa_s
,
3792 const u8
*addr
, const char *realm
)
3798 rlen
= os_strlen(realm
);
3800 buf
= os_malloc(len
);
3803 buf
[0] = 1; /* NAI Home Realm Count */
3804 buf
[1] = 0; /* Formatted in accordance with RFC 4282 */
3806 os_memcpy(buf
+ 3, realm
, rlen
);
3808 ret
= hs20_anqp_send_req(wpa_s
, addr
,
3809 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY
),
3818 static int hs20_get_nai_home_realm_list(struct wpa_supplicant
*wpa_s
,
3821 struct wpa_cred
*cred
= wpa_s
->conf
->cred
;
3822 u8 dst_addr
[ETH_ALEN
];
3828 used
= hwaddr_aton2(dst
, dst_addr
);
3832 while (dst
[used
] == ' ')
3834 if (os_strncmp(dst
+ used
, "realm=", 6) == 0)
3835 return hs20_nai_home_realm_list(wpa_s
, dst_addr
,
3838 len
= os_strlen(dst
+ used
);
3840 if (len
== 0 && cred
&& cred
->realm
)
3841 return hs20_nai_home_realm_list(wpa_s
, dst_addr
, cred
->realm
);
3846 buf
= os_malloc(len
);
3849 if (hexstr2bin(dst
+ used
, buf
, len
) < 0) {
3854 ret
= hs20_anqp_send_req(wpa_s
, dst_addr
,
3855 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY
),
3862 #endif /* CONFIG_HS20 */
3865 static int wpa_supplicant_ctrl_iface_sta_autoconnect(
3866 struct wpa_supplicant
*wpa_s
, char *cmd
)
3868 wpa_s
->auto_reconnect_disabled
= atoi(cmd
) == 0 ? 1 : 0;
3873 #ifdef CONFIG_AUTOSCAN
3875 static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant
*wpa_s
,
3878 enum wpa_states state
= wpa_s
->wpa_state
;
3879 char *new_params
= NULL
;
3881 if (os_strlen(cmd
) > 0) {
3882 new_params
= os_strdup(cmd
);
3883 if (new_params
== NULL
)
3887 os_free(wpa_s
->conf
->autoscan
);
3888 wpa_s
->conf
->autoscan
= new_params
;
3890 if (wpa_s
->conf
->autoscan
== NULL
)
3891 autoscan_deinit(wpa_s
);
3892 else if (state
== WPA_DISCONNECTED
|| state
== WPA_INACTIVE
)
3893 autoscan_init(wpa_s
, 1);
3898 #endif /* CONFIG_AUTOSCAN */
3901 static int wpa_supplicant_signal_poll(struct wpa_supplicant
*wpa_s
, char *buf
,
3904 struct wpa_signal_info si
;
3907 ret
= wpa_drv_signal_poll(wpa_s
, &si
);
3911 ret
= os_snprintf(buf
, buflen
, "RSSI=%d\nLINKSPEED=%d\n"
3912 "NOISE=%d\nFREQUENCY=%u\n",
3913 si
.current_signal
, si
.current_txrate
/ 1000,
3914 si
.current_noise
, si
.frequency
);
3915 if (ret
< 0 || (unsigned int) ret
> buflen
)
3921 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant
*wpa_s
,
3922 char *buf
, size_t *resp_len
)
3925 const int reply_size
= 4096;
3929 if (os_strncmp(buf
, WPA_CTRL_RSP
, os_strlen(WPA_CTRL_RSP
)) == 0 ||
3930 os_strncmp(buf
, "SET_NETWORK ", 12) == 0) {
3931 wpa_hexdump_ascii_key(MSG_DEBUG
, "RX ctrl_iface",
3932 (const u8
*) buf
, os_strlen(buf
));
3934 int level
= MSG_DEBUG
;
3935 if (os_strcmp(buf
, "PING") == 0)
3936 level
= MSG_EXCESSIVE
;
3937 wpa_hexdump_ascii(level
, "RX ctrl_iface",
3938 (const u8
*) buf
, os_strlen(buf
));
3941 reply
= os_malloc(reply_size
);
3942 if (reply
== NULL
) {
3947 os_memcpy(reply
, "OK\n", 3);
3950 if (os_strcmp(buf
, "PING") == 0) {
3951 os_memcpy(reply
, "PONG\n", 5);
3953 } else if (os_strncmp(buf
, "RELOG", 5) == 0) {
3954 if (wpa_debug_reopen_file() < 0)
3956 } else if (os_strncmp(buf
, "NOTE ", 5) == 0) {
3957 wpa_printf(MSG_INFO
, "NOTE: %s", buf
+ 5);
3958 } else if (os_strcmp(buf
, "MIB") == 0) {
3959 reply_len
= wpa_sm_get_mib(wpa_s
->wpa
, reply
, reply_size
);
3960 if (reply_len
>= 0) {
3962 res
= eapol_sm_get_mib(wpa_s
->eapol
, reply
+ reply_len
,
3963 reply_size
- reply_len
);
3969 } else if (os_strncmp(buf
, "STATUS", 6) == 0) {
3970 reply_len
= wpa_supplicant_ctrl_iface_status(
3971 wpa_s
, buf
+ 6, reply
, reply_size
);
3972 } else if (os_strcmp(buf
, "PMKSA") == 0) {
3973 reply_len
= wpa_sm_pmksa_cache_list(wpa_s
->wpa
, reply
,
3975 } else if (os_strncmp(buf
, "SET ", 4) == 0) {
3976 if (wpa_supplicant_ctrl_iface_set(wpa_s
, buf
+ 4))
3978 } else if (os_strncmp(buf
, "GET ", 4) == 0) {
3979 reply_len
= wpa_supplicant_ctrl_iface_get(wpa_s
, buf
+ 4,
3981 } else if (os_strcmp(buf
, "LOGON") == 0) {
3982 eapol_sm_notify_logoff(wpa_s
->eapol
, FALSE
);
3983 } else if (os_strcmp(buf
, "LOGOFF") == 0) {
3984 eapol_sm_notify_logoff(wpa_s
->eapol
, TRUE
);
3985 } else if (os_strcmp(buf
, "REASSOCIATE") == 0) {
3986 wpa_s
->normal_scans
= 0;
3987 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
3990 wpa_s
->disconnected
= 0;
3991 wpa_s
->reassociate
= 1;
3992 wpa_supplicant_req_scan(wpa_s
, 0, 0);
3994 } else if (os_strcmp(buf
, "RECONNECT") == 0) {
3995 wpa_s
->normal_scans
= 0;
3996 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
3998 else if (wpa_s
->disconnected
) {
3999 wpa_s
->disconnected
= 0;
4000 wpa_s
->reassociate
= 1;
4001 wpa_supplicant_req_scan(wpa_s
, 0, 0);
4003 #ifdef IEEE8021X_EAPOL
4004 } else if (os_strncmp(buf
, "PREAUTH ", 8) == 0) {
4005 if (wpa_supplicant_ctrl_iface_preauth(wpa_s
, buf
+ 8))
4007 #endif /* IEEE8021X_EAPOL */
4008 #ifdef CONFIG_PEERKEY
4009 } else if (os_strncmp(buf
, "STKSTART ", 9) == 0) {
4010 if (wpa_supplicant_ctrl_iface_stkstart(wpa_s
, buf
+ 9))
4012 #endif /* CONFIG_PEERKEY */
4013 #ifdef CONFIG_IEEE80211R
4014 } else if (os_strncmp(buf
, "FT_DS ", 6) == 0) {
4015 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s
, buf
+ 6))
4017 #endif /* CONFIG_IEEE80211R */
4019 } else if (os_strcmp(buf
, "WPS_PBC") == 0) {
4020 int res
= wpa_supplicant_ctrl_iface_wps_pbc(wpa_s
, NULL
);
4022 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
4026 } else if (os_strncmp(buf
, "WPS_PBC ", 8) == 0) {
4027 int res
= wpa_supplicant_ctrl_iface_wps_pbc(wpa_s
, buf
+ 8);
4029 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
4033 } else if (os_strncmp(buf
, "WPS_PIN ", 8) == 0) {
4034 reply_len
= wpa_supplicant_ctrl_iface_wps_pin(wpa_s
, buf
+ 8,
4037 } else if (os_strncmp(buf
, "WPS_CHECK_PIN ", 14) == 0) {
4038 reply_len
= wpa_supplicant_ctrl_iface_wps_check_pin(
4039 wpa_s
, buf
+ 14, reply
, reply_size
);
4040 } else if (os_strcmp(buf
, "WPS_CANCEL") == 0) {
4041 if (wpas_wps_cancel(wpa_s
))
4043 #ifdef CONFIG_WPS_OOB
4044 } else if (os_strncmp(buf
, "WPS_OOB ", 8) == 0) {
4045 if (wpa_supplicant_ctrl_iface_wps_oob(wpa_s
, buf
+ 8))
4047 #endif /* CONFIG_WPS_OOB */
4048 } else if (os_strncmp(buf
, "WPS_REG ", 8) == 0) {
4049 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s
, buf
+ 8))
4052 } else if (os_strncmp(buf
, "WPS_AP_PIN ", 11) == 0) {
4053 reply_len
= wpa_supplicant_ctrl_iface_wps_ap_pin(
4054 wpa_s
, buf
+ 11, reply
, reply_size
);
4055 #endif /* CONFIG_AP */
4056 #ifdef CONFIG_WPS_ER
4057 } else if (os_strcmp(buf
, "WPS_ER_START") == 0) {
4058 if (wpas_wps_er_start(wpa_s
, NULL
))
4060 } else if (os_strncmp(buf
, "WPS_ER_START ", 13) == 0) {
4061 if (wpas_wps_er_start(wpa_s
, buf
+ 13))
4063 } else if (os_strcmp(buf
, "WPS_ER_STOP") == 0) {
4064 if (wpas_wps_er_stop(wpa_s
))
4066 } else if (os_strncmp(buf
, "WPS_ER_PIN ", 11) == 0) {
4067 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s
, buf
+ 11))
4069 } else if (os_strncmp(buf
, "WPS_ER_PBC ", 11) == 0) {
4070 int ret
= wpas_wps_er_pbc(wpa_s
, buf
+ 11);
4072 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
4074 } else if (ret
== -3) {
4075 os_memcpy(reply
, "FAIL-UNKNOWN-UUID\n", 18);
4077 } else if (ret
== -4) {
4078 os_memcpy(reply
, "FAIL-NO-AP-SETTINGS\n", 20);
4082 } else if (os_strncmp(buf
, "WPS_ER_LEARN ", 13) == 0) {
4083 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s
, buf
+ 13))
4085 } else if (os_strncmp(buf
, "WPS_ER_SET_CONFIG ", 18) == 0) {
4086 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s
,
4089 } else if (os_strncmp(buf
, "WPS_ER_CONFIG ", 14) == 0) {
4090 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s
, buf
+ 14))
4092 #endif /* CONFIG_WPS_ER */
4093 #endif /* CONFIG_WPS */
4094 #ifdef CONFIG_IBSS_RSN
4095 } else if (os_strncmp(buf
, "IBSS_RSN ", 9) == 0) {
4096 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s
, buf
+ 9))
4098 #endif /* CONFIG_IBSS_RSN */
4100 } else if (os_strncmp(buf
, "P2P_FIND ", 9) == 0) {
4101 if (p2p_ctrl_find(wpa_s
, buf
+ 9))
4103 } else if (os_strcmp(buf
, "P2P_FIND") == 0) {
4104 if (p2p_ctrl_find(wpa_s
, ""))
4106 } else if (os_strcmp(buf
, "P2P_STOP_FIND") == 0) {
4107 wpas_p2p_stop_find(wpa_s
);
4108 } else if (os_strncmp(buf
, "P2P_CONNECT ", 12) == 0) {
4109 reply_len
= p2p_ctrl_connect(wpa_s
, buf
+ 12, reply
,
4111 } else if (os_strncmp(buf
, "P2P_LISTEN ", 11) == 0) {
4112 if (p2p_ctrl_listen(wpa_s
, buf
+ 11))
4114 } else if (os_strcmp(buf
, "P2P_LISTEN") == 0) {
4115 if (p2p_ctrl_listen(wpa_s
, ""))
4117 } else if (os_strncmp(buf
, "P2P_GROUP_REMOVE ", 17) == 0) {
4118 if (wpas_p2p_group_remove(wpa_s
, buf
+ 17))
4120 } else if (os_strcmp(buf
, "P2P_GROUP_ADD") == 0) {
4121 if (wpas_p2p_group_add(wpa_s
, 0, 0))
4123 } else if (os_strncmp(buf
, "P2P_GROUP_ADD ", 14) == 0) {
4124 if (p2p_ctrl_group_add(wpa_s
, buf
+ 14))
4126 } else if (os_strncmp(buf
, "P2P_PROV_DISC ", 14) == 0) {
4127 if (p2p_ctrl_prov_disc(wpa_s
, buf
+ 14))
4129 } else if (os_strcmp(buf
, "P2P_GET_PASSPHRASE") == 0) {
4130 reply_len
= p2p_get_passphrase(wpa_s
, reply
, reply_size
);
4131 } else if (os_strncmp(buf
, "P2P_SERV_DISC_REQ ", 18) == 0) {
4132 reply_len
= p2p_ctrl_serv_disc_req(wpa_s
, buf
+ 18, reply
,
4134 } else if (os_strncmp(buf
, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
4135 if (p2p_ctrl_serv_disc_cancel_req(wpa_s
, buf
+ 25) < 0)
4137 } else if (os_strncmp(buf
, "P2P_SERV_DISC_RESP ", 19) == 0) {
4138 if (p2p_ctrl_serv_disc_resp(wpa_s
, buf
+ 19) < 0)
4140 } else if (os_strcmp(buf
, "P2P_SERVICE_UPDATE") == 0) {
4141 wpas_p2p_sd_service_update(wpa_s
);
4142 } else if (os_strncmp(buf
, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
4143 if (p2p_ctrl_serv_disc_external(wpa_s
, buf
+ 23) < 0)
4145 } else if (os_strcmp(buf
, "P2P_SERVICE_FLUSH") == 0) {
4146 wpas_p2p_service_flush(wpa_s
);
4147 } else if (os_strncmp(buf
, "P2P_SERVICE_ADD ", 16) == 0) {
4148 if (p2p_ctrl_service_add(wpa_s
, buf
+ 16) < 0)
4150 } else if (os_strncmp(buf
, "P2P_SERVICE_DEL ", 16) == 0) {
4151 if (p2p_ctrl_service_del(wpa_s
, buf
+ 16) < 0)
4153 } else if (os_strncmp(buf
, "P2P_REJECT ", 11) == 0) {
4154 if (p2p_ctrl_reject(wpa_s
, buf
+ 11) < 0)
4156 } else if (os_strncmp(buf
, "P2P_INVITE ", 11) == 0) {
4157 if (p2p_ctrl_invite(wpa_s
, buf
+ 11) < 0)
4159 } else if (os_strncmp(buf
, "P2P_PEER ", 9) == 0) {
4160 reply_len
= p2p_ctrl_peer(wpa_s
, buf
+ 9, reply
,
4162 } else if (os_strncmp(buf
, "P2P_SET ", 8) == 0) {
4163 if (p2p_ctrl_set(wpa_s
, buf
+ 8) < 0)
4165 } else if (os_strcmp(buf
, "P2P_FLUSH") == 0) {
4166 os_memset(wpa_s
->p2p_auth_invite
, 0, ETH_ALEN
);
4167 wpa_s
->force_long_sd
= 0;
4168 if (wpa_s
->global
->p2p
)
4169 p2p_flush(wpa_s
->global
->p2p
);
4170 } else if (os_strncmp(buf
, "P2P_UNAUTHORIZE ", 16) == 0) {
4171 if (wpas_p2p_unauthorize(wpa_s
, buf
+ 16) < 0)
4173 } else if (os_strcmp(buf
, "P2P_CANCEL") == 0) {
4174 if (wpas_p2p_cancel(wpa_s
))
4176 } else if (os_strncmp(buf
, "P2P_PRESENCE_REQ ", 17) == 0) {
4177 if (p2p_ctrl_presence_req(wpa_s
, buf
+ 17) < 0)
4179 } else if (os_strcmp(buf
, "P2P_PRESENCE_REQ") == 0) {
4180 if (p2p_ctrl_presence_req(wpa_s
, "") < 0)
4182 } else if (os_strncmp(buf
, "P2P_EXT_LISTEN ", 15) == 0) {
4183 if (p2p_ctrl_ext_listen(wpa_s
, buf
+ 15) < 0)
4185 } else if (os_strcmp(buf
, "P2P_EXT_LISTEN") == 0) {
4186 if (p2p_ctrl_ext_listen(wpa_s
, "") < 0)
4188 #endif /* CONFIG_P2P */
4189 #ifdef CONFIG_INTERWORKING
4190 } else if (os_strcmp(buf
, "FETCH_ANQP") == 0) {
4191 if (interworking_fetch_anqp(wpa_s
) < 0)
4193 } else if (os_strcmp(buf
, "STOP_FETCH_ANQP") == 0) {
4194 interworking_stop_fetch_anqp(wpa_s
);
4195 } else if (os_strncmp(buf
, "INTERWORKING_SELECT", 19) == 0) {
4196 if (interworking_select(wpa_s
, os_strstr(buf
+ 19, "auto") !=
4199 } else if (os_strncmp(buf
, "INTERWORKING_CONNECT ", 21) == 0) {
4200 if (ctrl_interworking_connect(wpa_s
, buf
+ 21) < 0)
4202 } else if (os_strncmp(buf
, "ANQP_GET ", 9) == 0) {
4203 if (get_anqp(wpa_s
, buf
+ 9) < 0)
4205 #endif /* CONFIG_INTERWORKING */
4207 } else if (os_strncmp(buf
, "HS20_ANQP_GET ", 14) == 0) {
4208 if (get_hs20_anqp(wpa_s
, buf
+ 14) < 0)
4210 } else if (os_strncmp(buf
, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
4211 if (hs20_get_nai_home_realm_list(wpa_s
, buf
+ 29) < 0)
4213 #endif /* CONFIG_HS20 */
4214 } else if (os_strncmp(buf
, WPA_CTRL_RSP
, os_strlen(WPA_CTRL_RSP
)) == 0)
4216 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
4217 wpa_s
, buf
+ os_strlen(WPA_CTRL_RSP
)))
4221 } else if (os_strcmp(buf
, "RECONFIGURE") == 0) {
4222 if (wpa_supplicant_reload_configuration(wpa_s
))
4224 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
4225 wpa_supplicant_terminate_proc(wpa_s
->global
);
4226 } else if (os_strncmp(buf
, "BSSID ", 6) == 0) {
4227 if (wpa_supplicant_ctrl_iface_bssid(wpa_s
, buf
+ 6))
4229 } else if (os_strncmp(buf
, "BLACKLIST", 9) == 0) {
4230 reply_len
= wpa_supplicant_ctrl_iface_blacklist(
4231 wpa_s
, buf
+ 9, reply
, reply_size
);
4232 } else if (os_strncmp(buf
, "LOG_LEVEL", 9) == 0) {
4233 reply_len
= wpa_supplicant_ctrl_iface_log_level(
4234 wpa_s
, buf
+ 9, reply
, reply_size
);
4235 } else if (os_strcmp(buf
, "LIST_NETWORKS") == 0) {
4236 reply_len
= wpa_supplicant_ctrl_iface_list_networks(
4237 wpa_s
, reply
, reply_size
);
4238 } else if (os_strcmp(buf
, "DISCONNECT") == 0) {
4240 wpa_s
->sme
.prev_bssid_set
= 0;
4241 #endif /* CONFIG_SME */
4242 wpa_s
->reassociate
= 0;
4243 wpa_s
->disconnected
= 1;
4244 wpa_supplicant_cancel_sched_scan(wpa_s
);
4245 wpa_supplicant_deauthenticate(wpa_s
,
4246 WLAN_REASON_DEAUTH_LEAVING
);
4247 } else if (os_strcmp(buf
, "SCAN") == 0) {
4248 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
4251 if (!wpa_s
->scanning
&&
4252 ((wpa_s
->wpa_state
<= WPA_SCANNING
) ||
4253 (wpa_s
->wpa_state
== WPA_COMPLETED
))) {
4254 wpa_s
->normal_scans
= 0;
4255 wpa_s
->scan_req
= 2;
4256 wpa_supplicant_req_scan(wpa_s
, 0, 0);
4257 } else if (wpa_s
->sched_scanning
) {
4258 wpa_printf(MSG_DEBUG
, "Stop ongoing "
4259 "sched_scan to allow requested "
4260 "full scan to proceed");
4261 wpa_supplicant_cancel_sched_scan(wpa_s
);
4262 wpa_s
->scan_req
= 2;
4263 wpa_supplicant_req_scan(wpa_s
, 0, 0);
4265 wpa_printf(MSG_DEBUG
, "Ongoing scan action - "
4266 "reject new request");
4267 reply_len
= os_snprintf(reply
, reply_size
,
4271 } else if (os_strcmp(buf
, "SCAN_RESULTS") == 0) {
4272 reply_len
= wpa_supplicant_ctrl_iface_scan_results(
4273 wpa_s
, reply
, reply_size
);
4274 } else if (os_strncmp(buf
, "SELECT_NETWORK ", 15) == 0) {
4275 if (wpa_supplicant_ctrl_iface_select_network(wpa_s
, buf
+ 15))
4277 } else if (os_strncmp(buf
, "ENABLE_NETWORK ", 15) == 0) {
4278 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s
, buf
+ 15))
4280 } else if (os_strncmp(buf
, "DISABLE_NETWORK ", 16) == 0) {
4281 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s
, buf
+ 16))
4283 } else if (os_strcmp(buf
, "ADD_NETWORK") == 0) {
4284 reply_len
= wpa_supplicant_ctrl_iface_add_network(
4285 wpa_s
, reply
, reply_size
);
4286 } else if (os_strncmp(buf
, "REMOVE_NETWORK ", 15) == 0) {
4287 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s
, buf
+ 15))
4289 } else if (os_strncmp(buf
, "SET_NETWORK ", 12) == 0) {
4290 if (wpa_supplicant_ctrl_iface_set_network(wpa_s
, buf
+ 12))
4292 } else if (os_strncmp(buf
, "GET_NETWORK ", 12) == 0) {
4293 reply_len
= wpa_supplicant_ctrl_iface_get_network(
4294 wpa_s
, buf
+ 12, reply
, reply_size
);
4295 } else if (os_strcmp(buf
, "LIST_CREDS") == 0) {
4296 reply_len
= wpa_supplicant_ctrl_iface_list_creds(
4297 wpa_s
, reply
, reply_size
);
4298 } else if (os_strcmp(buf
, "ADD_CRED") == 0) {
4299 reply_len
= wpa_supplicant_ctrl_iface_add_cred(
4300 wpa_s
, reply
, reply_size
);
4301 } else if (os_strncmp(buf
, "REMOVE_CRED ", 12) == 0) {
4302 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s
, buf
+ 12))
4304 } else if (os_strncmp(buf
, "SET_CRED ", 9) == 0) {
4305 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s
, buf
+ 9))
4307 #ifndef CONFIG_NO_CONFIG_WRITE
4308 } else if (os_strcmp(buf
, "SAVE_CONFIG") == 0) {
4309 if (wpa_supplicant_ctrl_iface_save_config(wpa_s
))
4311 #endif /* CONFIG_NO_CONFIG_WRITE */
4312 } else if (os_strncmp(buf
, "GET_CAPABILITY ", 15) == 0) {
4313 reply_len
= wpa_supplicant_ctrl_iface_get_capability(
4314 wpa_s
, buf
+ 15, reply
, reply_size
);
4315 } else if (os_strncmp(buf
, "AP_SCAN ", 8) == 0) {
4316 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s
, buf
+ 8))
4318 } else if (os_strncmp(buf
, "SCAN_INTERVAL ", 14) == 0) {
4319 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s
, buf
+ 14))
4321 } else if (os_strcmp(buf
, "INTERFACE_LIST") == 0) {
4322 reply_len
= wpa_supplicant_global_iface_list(
4323 wpa_s
->global
, reply
, reply_size
);
4324 } else if (os_strcmp(buf
, "INTERFACES") == 0) {
4325 reply_len
= wpa_supplicant_global_iface_interfaces(
4326 wpa_s
->global
, reply
, reply_size
);
4327 } else if (os_strncmp(buf
, "BSS ", 4) == 0) {
4328 reply_len
= wpa_supplicant_ctrl_iface_bss(
4329 wpa_s
, buf
+ 4, reply
, reply_size
);
4331 } else if (os_strcmp(buf
, "STA-FIRST") == 0) {
4332 reply_len
= ap_ctrl_iface_sta_first(wpa_s
, reply
, reply_size
);
4333 } else if (os_strncmp(buf
, "STA ", 4) == 0) {
4334 reply_len
= ap_ctrl_iface_sta(wpa_s
, buf
+ 4, reply
,
4336 } else if (os_strncmp(buf
, "STA-NEXT ", 9) == 0) {
4337 reply_len
= ap_ctrl_iface_sta_next(wpa_s
, buf
+ 9, reply
,
4339 } else if (os_strncmp(buf
, "DEAUTHENTICATE ", 15) == 0) {
4340 if (ap_ctrl_iface_sta_deauthenticate(wpa_s
, buf
+ 15))
4342 } else if (os_strncmp(buf
, "DISASSOCIATE ", 13) == 0) {
4343 if (ap_ctrl_iface_sta_disassociate(wpa_s
, buf
+ 13))
4345 #endif /* CONFIG_AP */
4346 } else if (os_strcmp(buf
, "SUSPEND") == 0) {
4347 wpas_notify_suspend(wpa_s
->global
);
4348 } else if (os_strcmp(buf
, "RESUME") == 0) {
4349 wpas_notify_resume(wpa_s
->global
);
4350 } else if (os_strcmp(buf
, "DROP_SA") == 0) {
4351 wpa_supplicant_ctrl_iface_drop_sa(wpa_s
);
4352 } else if (os_strncmp(buf
, "ROAM ", 5) == 0) {
4353 if (wpa_supplicant_ctrl_iface_roam(wpa_s
, buf
+ 5))
4355 } else if (os_strncmp(buf
, "STA_AUTOCONNECT ", 16) == 0) {
4356 if (wpa_supplicant_ctrl_iface_sta_autoconnect(wpa_s
, buf
+ 16))
4358 } else if (os_strncmp(buf
, "BSS_EXPIRE_AGE ", 15) == 0) {
4359 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s
, buf
+ 15))
4361 } else if (os_strncmp(buf
, "BSS_EXPIRE_COUNT ", 17) == 0) {
4362 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s
,
4366 } else if (os_strncmp(buf
, "TDLS_DISCOVER ", 14) == 0) {
4367 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s
, buf
+ 14))
4369 } else if (os_strncmp(buf
, "TDLS_SETUP ", 11) == 0) {
4370 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s
, buf
+ 11))
4372 } else if (os_strncmp(buf
, "TDLS_TEARDOWN ", 14) == 0) {
4373 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s
, buf
+ 14))
4375 #endif /* CONFIG_TDLS */
4376 } else if (os_strncmp(buf
, "SIGNAL_POLL", 11) == 0) {
4377 reply_len
= wpa_supplicant_signal_poll(wpa_s
, reply
,
4379 #ifdef CONFIG_AUTOSCAN
4380 } else if (os_strncmp(buf
, "AUTOSCAN ", 9) == 0) {
4381 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s
, buf
+ 9))
4383 #endif /* CONFIG_AUTOSCAN */
4384 } else if (os_strcmp(buf
, "REAUTHENTICATE") == 0) {
4385 eapol_sm_request_reauth(wpa_s
->eapol
);
4387 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
4391 if (reply_len
< 0) {
4392 os_memcpy(reply
, "FAIL\n", 5);
4397 eapol_sm_notify_ctrl_response(wpa_s
->eapol
);
4399 *resp_len
= reply_len
;
4404 static int wpa_supplicant_global_iface_add(struct wpa_global
*global
,
4407 struct wpa_interface iface
;
4411 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
4412 * TAB<bridge_ifname>
4414 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd
);
4416 os_memset(&iface
, 0, sizeof(iface
));
4419 iface
.ifname
= pos
= cmd
;
4420 pos
= os_strchr(pos
, '\t');
4423 if (iface
.ifname
[0] == '\0')
4428 iface
.confname
= pos
;
4429 pos
= os_strchr(pos
, '\t');
4432 if (iface
.confname
[0] == '\0')
4433 iface
.confname
= NULL
;
4438 pos
= os_strchr(pos
, '\t');
4441 if (iface
.driver
[0] == '\0')
4442 iface
.driver
= NULL
;
4446 iface
.ctrl_interface
= pos
;
4447 pos
= os_strchr(pos
, '\t');
4450 if (iface
.ctrl_interface
[0] == '\0')
4451 iface
.ctrl_interface
= NULL
;
4455 iface
.driver_param
= pos
;
4456 pos
= os_strchr(pos
, '\t');
4459 if (iface
.driver_param
[0] == '\0')
4460 iface
.driver_param
= NULL
;
4464 iface
.bridge_ifname
= pos
;
4465 pos
= os_strchr(pos
, '\t');
4468 if (iface
.bridge_ifname
[0] == '\0')
4469 iface
.bridge_ifname
= NULL
;
4474 if (wpa_supplicant_get_iface(global
, iface
.ifname
))
4477 return wpa_supplicant_add_iface(global
, &iface
) ? 0 : -1;
4481 static int wpa_supplicant_global_iface_remove(struct wpa_global
*global
,
4484 struct wpa_supplicant
*wpa_s
;
4486 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd
);
4488 wpa_s
= wpa_supplicant_get_iface(global
, cmd
);
4491 return wpa_supplicant_remove_iface(global
, wpa_s
, 0);
4495 static void wpa_free_iface_info(struct wpa_interface_info
*iface
)
4497 struct wpa_interface_info
*prev
;
4501 iface
= iface
->next
;
4503 os_free(prev
->ifname
);
4504 os_free(prev
->desc
);
4510 static int wpa_supplicant_global_iface_list(struct wpa_global
*global
,
4514 struct wpa_interface_info
*iface
= NULL
, *last
= NULL
, *tmp
;
4517 for (i
= 0; wpa_drivers
[i
]; i
++) {
4518 struct wpa_driver_ops
*drv
= wpa_drivers
[i
];
4519 if (drv
->get_interfaces
== NULL
)
4521 tmp
= drv
->get_interfaces(global
->drv_priv
[i
]);
4535 for (tmp
= iface
; tmp
; tmp
= tmp
->next
) {
4536 res
= os_snprintf(pos
, end
- pos
, "%s\t%s\t%s\n",
4537 tmp
->drv_name
, tmp
->ifname
,
4538 tmp
->desc
? tmp
->desc
: "");
4539 if (res
< 0 || res
>= end
- pos
) {
4546 wpa_free_iface_info(iface
);
4552 static int wpa_supplicant_global_iface_interfaces(struct wpa_global
*global
,
4557 struct wpa_supplicant
*wpa_s
;
4559 wpa_s
= global
->ifaces
;
4564 res
= os_snprintf(pos
, end
- pos
, "%s\n", wpa_s
->ifname
);
4565 if (res
< 0 || res
>= end
- pos
) {
4570 wpa_s
= wpa_s
->next
;
4576 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global
*global
,
4577 char *buf
, size_t *resp_len
)
4580 const int reply_size
= 2048;
4582 int level
= MSG_DEBUG
;
4584 if (os_strcmp(buf
, "PING") == 0)
4585 level
= MSG_EXCESSIVE
;
4586 wpa_hexdump_ascii(level
, "RX global ctrl_iface",
4587 (const u8
*) buf
, os_strlen(buf
));
4589 reply
= os_malloc(reply_size
);
4590 if (reply
== NULL
) {
4595 os_memcpy(reply
, "OK\n", 3);
4598 if (os_strcmp(buf
, "PING") == 0) {
4599 os_memcpy(reply
, "PONG\n", 5);
4601 } else if (os_strncmp(buf
, "INTERFACE_ADD ", 14) == 0) {
4602 if (wpa_supplicant_global_iface_add(global
, buf
+ 14))
4604 } else if (os_strncmp(buf
, "INTERFACE_REMOVE ", 17) == 0) {
4605 if (wpa_supplicant_global_iface_remove(global
, buf
+ 17))
4607 } else if (os_strcmp(buf
, "INTERFACE_LIST") == 0) {
4608 reply_len
= wpa_supplicant_global_iface_list(
4609 global
, reply
, reply_size
);
4610 } else if (os_strcmp(buf
, "INTERFACES") == 0) {
4611 reply_len
= wpa_supplicant_global_iface_interfaces(
4612 global
, reply
, reply_size
);
4613 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
4614 wpa_supplicant_terminate_proc(global
);
4615 } else if (os_strcmp(buf
, "SUSPEND") == 0) {
4616 wpas_notify_suspend(global
);
4617 } else if (os_strcmp(buf
, "RESUME") == 0) {
4618 wpas_notify_resume(global
);
4620 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
4624 if (reply_len
< 0) {
4625 os_memcpy(reply
, "FAIL\n", 5);
4629 *resp_len
= reply_len
;