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"
40 extern struct wpa_driver_ops
*wpa_drivers
[];
42 static int wpa_supplicant_global_iface_list(struct wpa_global
*global
,
44 static int wpa_supplicant_global_iface_interfaces(struct wpa_global
*global
,
48 static int pno_start(struct wpa_supplicant
*wpa_s
)
52 struct wpa_ssid
*ssid
;
53 struct wpa_driver_scan_params params
;
58 os_memset(¶ms
, 0, sizeof(params
));
61 ssid
= wpa_s
->conf
->ssid
;
63 if (!wpas_network_disabled(wpa_s
, ssid
))
67 if (num_ssid
> WPAS_MAX_SCAN_SSIDS
) {
68 wpa_printf(MSG_DEBUG
, "PNO: Use only the first %u SSIDs from "
69 "%u", WPAS_MAX_SCAN_SSIDS
, (unsigned int) num_ssid
);
70 num_ssid
= WPAS_MAX_SCAN_SSIDS
;
74 wpa_printf(MSG_DEBUG
, "PNO: No configured SSIDs");
78 params
.filter_ssids
= os_malloc(sizeof(struct wpa_driver_scan_filter
) *
80 if (params
.filter_ssids
== NULL
)
83 ssid
= wpa_s
->conf
->ssid
;
85 if (!wpas_network_disabled(wpa_s
, ssid
)) {
86 params
.ssids
[i
].ssid
= ssid
->ssid
;
87 params
.ssids
[i
].ssid_len
= ssid
->ssid_len
;
89 os_memcpy(params
.filter_ssids
[i
].ssid
, ssid
->ssid
,
91 params
.filter_ssids
[i
].ssid_len
= ssid
->ssid_len
;
92 params
.num_filter_ssids
++;
100 ret
= wpa_drv_sched_scan(wpa_s
, ¶ms
, 10 * 1000);
101 os_free(params
.filter_ssids
);
108 static int pno_stop(struct wpa_supplicant
*wpa_s
)
112 return wpa_drv_stop_sched_scan(wpa_s
);
118 static int set_bssid_filter(struct wpa_supplicant
*wpa_s
, char *val
)
121 u8 addr
[ETH_ALEN
], *filter
= NULL
, *n
;
128 if (hwaddr_aton(pos
, addr
)) {
132 n
= os_realloc(filter
, (count
+ 1) * ETH_ALEN
);
138 os_memcpy(filter
+ count
* ETH_ALEN
, addr
, ETH_ALEN
);
141 pos
= os_strchr(pos
, ' ');
146 wpa_hexdump(MSG_DEBUG
, "bssid_filter", filter
, count
* ETH_ALEN
);
147 os_free(wpa_s
->bssid_filter
);
148 wpa_s
->bssid_filter
= filter
;
149 wpa_s
->bssid_filter_count
= count
;
155 static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant
*wpa_s
,
161 value
= os_strchr(cmd
, ' ');
166 wpa_printf(MSG_DEBUG
, "CTRL_IFACE SET '%s'='%s'", cmd
, value
);
167 if (os_strcasecmp(cmd
, "EAPOL::heldPeriod") == 0) {
168 eapol_sm_configure(wpa_s
->eapol
,
169 atoi(value
), -1, -1, -1);
170 } else if (os_strcasecmp(cmd
, "EAPOL::authPeriod") == 0) {
171 eapol_sm_configure(wpa_s
->eapol
,
172 -1, atoi(value
), -1, -1);
173 } else if (os_strcasecmp(cmd
, "EAPOL::startPeriod") == 0) {
174 eapol_sm_configure(wpa_s
->eapol
,
175 -1, -1, atoi(value
), -1);
176 } else if (os_strcasecmp(cmd
, "EAPOL::maxStart") == 0) {
177 eapol_sm_configure(wpa_s
->eapol
,
178 -1, -1, -1, atoi(value
));
179 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigPMKLifetime") == 0) {
180 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_LIFETIME
,
183 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigPMKReauthThreshold") ==
185 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_REAUTH_THRESHOLD
,
188 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigSATimeout") == 0) {
189 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_SA_TIMEOUT
, atoi(value
)))
191 } else if (os_strcasecmp(cmd
, "wps_fragment_size") == 0) {
192 wpa_s
->wps_fragment_size
= atoi(value
);
193 #ifdef CONFIG_WPS_TESTING
194 } else if (os_strcasecmp(cmd
, "wps_version_number") == 0) {
196 val
= strtol(value
, NULL
, 0);
197 if (val
< 0 || val
> 0xff) {
199 wpa_printf(MSG_DEBUG
, "WPS: Invalid "
200 "wps_version_number %ld", val
);
202 wps_version_number
= val
;
203 wpa_printf(MSG_DEBUG
, "WPS: Testing - force WPS "
205 (wps_version_number
& 0xf0) >> 4,
206 wps_version_number
& 0x0f);
208 } else if (os_strcasecmp(cmd
, "wps_testing_dummy_cred") == 0) {
209 wps_testing_dummy_cred
= atoi(value
);
210 wpa_printf(MSG_DEBUG
, "WPS: Testing - dummy_cred=%d",
211 wps_testing_dummy_cred
);
212 #endif /* CONFIG_WPS_TESTING */
213 } else if (os_strcasecmp(cmd
, "ampdu") == 0) {
214 if (wpa_drv_ampdu(wpa_s
, atoi(value
)) < 0)
216 #ifdef CONFIG_TDLS_TESTING
217 } else if (os_strcasecmp(cmd
, "tdls_testing") == 0) {
218 extern unsigned int tdls_testing
;
219 tdls_testing
= strtol(value
, NULL
, 0);
220 wpa_printf(MSG_DEBUG
, "TDLS: tdls_testing=0x%x", tdls_testing
);
221 #endif /* CONFIG_TDLS_TESTING */
223 } else if (os_strcasecmp(cmd
, "tdls_disabled") == 0) {
224 int disabled
= atoi(value
);
225 wpa_printf(MSG_DEBUG
, "TDLS: tdls_disabled=%d", disabled
);
227 if (wpa_drv_tdls_oper(wpa_s
, TDLS_DISABLE
, NULL
) < 0)
229 } else if (wpa_drv_tdls_oper(wpa_s
, TDLS_ENABLE
, NULL
) < 0)
231 wpa_tdls_enable(wpa_s
->wpa
, !disabled
);
232 #endif /* CONFIG_TDLS */
233 } else if (os_strcasecmp(cmd
, "pno") == 0) {
235 ret
= pno_start(wpa_s
);
237 ret
= pno_stop(wpa_s
);
238 } else if (os_strcasecmp(cmd
, "radio_disabled") == 0) {
239 int disabled
= atoi(value
);
240 if (wpa_drv_radio_disable(wpa_s
, disabled
) < 0)
243 wpa_supplicant_set_state(wpa_s
, WPA_INACTIVE
);
244 } else if (os_strcasecmp(cmd
, "uapsd") == 0) {
245 if (os_strcmp(value
, "disable") == 0)
246 wpa_s
->set_sta_uapsd
= 0;
250 /* format: BE,BK,VI,VO;max SP Length */
252 pos
= os_strchr(value
, ',');
257 pos
= os_strchr(pos
, ',');
262 pos
= os_strchr(pos
, ',');
267 /* ignore max SP Length for now */
269 wpa_s
->set_sta_uapsd
= 1;
270 wpa_s
->sta_uapsd
= 0;
272 wpa_s
->sta_uapsd
|= BIT(0);
274 wpa_s
->sta_uapsd
|= BIT(1);
276 wpa_s
->sta_uapsd
|= BIT(2);
278 wpa_s
->sta_uapsd
|= BIT(3);
280 } else if (os_strcasecmp(cmd
, "ps") == 0) {
281 ret
= wpa_drv_set_p2p_powersave(wpa_s
, atoi(value
), -1, -1);
282 } else if (os_strcasecmp(cmd
, "bssid_filter") == 0) {
283 ret
= set_bssid_filter(wpa_s
, value
);
286 ret
= wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
288 wpa_supplicant_update_config(wpa_s
);
295 static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant
*wpa_s
,
296 char *cmd
, char *buf
, size_t buflen
)
300 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GET '%s'", cmd
);
302 if (os_strcmp(cmd
, "version") == 0) {
303 res
= os_snprintf(buf
, buflen
, "%s", VERSION_STR
);
304 } else if (os_strcasecmp(cmd
, "country") == 0) {
305 if (wpa_s
->conf
->country
[0] && wpa_s
->conf
->country
[1])
306 res
= os_snprintf(buf
, buflen
, "%c%c",
307 wpa_s
->conf
->country
[0],
308 wpa_s
->conf
->country
[1]);
311 if (res
< 0 || (unsigned int) res
>= buflen
)
317 #ifdef IEEE8021X_EAPOL
318 static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant
*wpa_s
,
322 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
324 if (hwaddr_aton(addr
, bssid
)) {
325 wpa_printf(MSG_DEBUG
, "CTRL_IFACE PREAUTH: invalid address "
330 wpa_printf(MSG_DEBUG
, "CTRL_IFACE PREAUTH " MACSTR
, MAC2STR(bssid
));
331 rsn_preauth_deinit(wpa_s
->wpa
);
332 if (rsn_preauth_init(wpa_s
->wpa
, bssid
, ssid
? &ssid
->eap
: NULL
))
337 #endif /* IEEE8021X_EAPOL */
340 #ifdef CONFIG_PEERKEY
341 /* MLME-STKSTART.request(peer) */
342 static int wpa_supplicant_ctrl_iface_stkstart(
343 struct wpa_supplicant
*wpa_s
, char *addr
)
347 if (hwaddr_aton(addr
, peer
)) {
348 wpa_printf(MSG_DEBUG
, "CTRL_IFACE STKSTART: invalid "
349 "address '%s'", addr
);
353 wpa_printf(MSG_DEBUG
, "CTRL_IFACE STKSTART " MACSTR
,
356 return wpa_sm_stkstart(wpa_s
->wpa
, peer
);
358 #endif /* CONFIG_PEERKEY */
363 static int wpa_supplicant_ctrl_iface_tdls_discover(
364 struct wpa_supplicant
*wpa_s
, char *addr
)
369 if (hwaddr_aton(addr
, peer
)) {
370 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_DISCOVER: invalid "
371 "address '%s'", addr
);
375 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_DISCOVER " MACSTR
,
378 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
379 ret
= wpa_tdls_send_discovery_request(wpa_s
->wpa
, peer
);
381 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_DISCOVERY_REQ
, peer
);
387 static int wpa_supplicant_ctrl_iface_tdls_setup(
388 struct wpa_supplicant
*wpa_s
, char *addr
)
393 if (hwaddr_aton(addr
, peer
)) {
394 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_SETUP: invalid "
395 "address '%s'", addr
);
399 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_SETUP " MACSTR
,
402 ret
= wpa_tdls_reneg(wpa_s
->wpa
, peer
);
404 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
405 ret
= wpa_tdls_start(wpa_s
->wpa
, peer
);
407 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, peer
);
414 static int wpa_supplicant_ctrl_iface_tdls_teardown(
415 struct wpa_supplicant
*wpa_s
, char *addr
)
419 if (hwaddr_aton(addr
, peer
)) {
420 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN: invalid "
421 "address '%s'", addr
);
425 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN " MACSTR
,
428 return wpa_tdls_teardown_link(wpa_s
->wpa
, peer
,
429 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED
);
432 #endif /* CONFIG_TDLS */
435 #ifdef CONFIG_IEEE80211R
436 static int wpa_supplicant_ctrl_iface_ft_ds(
437 struct wpa_supplicant
*wpa_s
, char *addr
)
439 u8 target_ap
[ETH_ALEN
];
443 if (hwaddr_aton(addr
, target_ap
)) {
444 wpa_printf(MSG_DEBUG
, "CTRL_IFACE FT_DS: invalid "
445 "address '%s'", addr
);
449 wpa_printf(MSG_DEBUG
, "CTRL_IFACE FT_DS " MACSTR
, MAC2STR(target_ap
));
451 bss
= wpa_bss_get_bssid(wpa_s
, target_ap
);
453 mdie
= wpa_bss_get_ie(bss
, WLAN_EID_MOBILITY_DOMAIN
);
457 return wpa_ft_start_over_ds(wpa_s
->wpa
, target_ap
, mdie
);
459 #endif /* CONFIG_IEEE80211R */
463 static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant
*wpa_s
,
466 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
468 u8 p2p_dev_addr
[ETH_ALEN
];
469 #endif /* CONFIG_P2P */
471 u8
*_p2p_dev_addr
= NULL
;
472 #endif /* CONFIG_AP */
474 if (cmd
== NULL
|| os_strcmp(cmd
, "any") == 0) {
477 } else if (os_strncmp(cmd
, "p2p_dev_addr=", 13) == 0) {
478 if (hwaddr_aton(cmd
+ 13, p2p_dev_addr
)) {
479 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PBC: invalid "
480 "P2P Device Address '%s'",
484 _p2p_dev_addr
= p2p_dev_addr
;
485 #endif /* CONFIG_P2P */
486 } else if (hwaddr_aton(cmd
, bssid
)) {
487 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
494 return wpa_supplicant_ap_wps_pbc(wpa_s
, _bssid
, _p2p_dev_addr
);
495 #endif /* CONFIG_AP */
497 return wpas_wps_start_pbc(wpa_s
, _bssid
, 0);
501 static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant
*wpa_s
,
502 char *cmd
, char *buf
,
505 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
509 pin
= os_strchr(cmd
, ' ');
513 if (os_strcmp(cmd
, "any") == 0)
515 else if (os_strcmp(cmd
, "get") == 0) {
516 ret
= wps_generate_pin();
518 } else if (hwaddr_aton(cmd
, bssid
)) {
519 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
526 return wpa_supplicant_ap_wps_pin(wpa_s
, _bssid
, pin
,
528 #endif /* CONFIG_AP */
531 ret
= wpas_wps_start_pin(wpa_s
, _bssid
, pin
, 0,
535 ret
= os_snprintf(buf
, buflen
, "%s", pin
);
536 if (ret
< 0 || (size_t) ret
>= buflen
)
541 ret
= wpas_wps_start_pin(wpa_s
, _bssid
, NULL
, 0, DEV_PW_DEFAULT
);
546 /* Return the generated PIN */
547 ret
= os_snprintf(buf
, buflen
, "%08d", ret
);
548 if (ret
< 0 || (size_t) ret
>= buflen
)
554 static int wpa_supplicant_ctrl_iface_wps_check_pin(
555 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
562 wpa_hexdump_ascii_key(MSG_DEBUG
, "WPS_CHECK_PIN",
563 (u8
*) cmd
, os_strlen(cmd
));
564 for (pos
= cmd
, len
= 0; *pos
!= '\0'; pos
++) {
565 if (*pos
< '0' || *pos
> '9')
569 wpa_printf(MSG_DEBUG
, "WPS: Too long PIN");
573 if (len
!= 4 && len
!= 8) {
574 wpa_printf(MSG_DEBUG
, "WPS: Invalid PIN length %d", (int) len
);
580 unsigned int pin_val
;
582 if (!wps_pin_valid(pin_val
)) {
583 wpa_printf(MSG_DEBUG
, "WPS: Invalid checksum digit");
584 ret
= os_snprintf(buf
, buflen
, "FAIL-CHECKSUM\n");
585 if (ret
< 0 || (size_t) ret
>= buflen
)
591 ret
= os_snprintf(buf
, buflen
, "%s", pin
);
592 if (ret
< 0 || (size_t) ret
>= buflen
)
599 #ifdef CONFIG_WPS_OOB
600 static int wpa_supplicant_ctrl_iface_wps_oob(struct wpa_supplicant
*wpa_s
,
603 char *path
, *method
, *name
;
605 path
= os_strchr(cmd
, ' ');
610 method
= os_strchr(path
, ' ');
615 name
= os_strchr(method
, ' ');
619 return wpas_wps_start_oob(wpa_s
, cmd
, path
, method
, name
);
621 #endif /* CONFIG_WPS_OOB */
624 static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant
*wpa_s
,
633 struct wps_new_ap_settings ap
;
635 pin
= os_strchr(cmd
, ' ');
640 if (hwaddr_aton(cmd
, bssid
)) {
641 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
646 new_ssid
= os_strchr(pin
, ' ');
647 if (new_ssid
== NULL
)
648 return wpas_wps_start_reg(wpa_s
, bssid
, pin
, NULL
);
651 new_auth
= os_strchr(new_ssid
, ' ');
652 if (new_auth
== NULL
)
656 new_encr
= os_strchr(new_auth
, ' ');
657 if (new_encr
== NULL
)
661 new_key
= os_strchr(new_encr
, ' ');
666 os_memset(&ap
, 0, sizeof(ap
));
667 ap
.ssid_hex
= new_ssid
;
670 ap
.key_hex
= new_key
;
671 return wpas_wps_start_reg(wpa_s
, bssid
, pin
, &ap
);
676 static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant
*wpa_s
,
677 char *cmd
, char *buf
,
684 if (!wpa_s
->ap_iface
)
687 pos
= os_strchr(cmd
, ' ');
691 if (os_strcmp(cmd
, "disable") == 0) {
692 wpas_wps_ap_pin_disable(wpa_s
);
693 return os_snprintf(buf
, buflen
, "OK\n");
696 if (os_strcmp(cmd
, "random") == 0) {
699 pin_txt
= wpas_wps_ap_pin_random(wpa_s
, timeout
);
702 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
705 if (os_strcmp(cmd
, "get") == 0) {
706 pin_txt
= wpas_wps_ap_pin_get(wpa_s
);
709 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
712 if (os_strcmp(cmd
, "set") == 0) {
717 pos
= os_strchr(pos
, ' ');
722 if (os_strlen(pin
) > buflen
)
724 if (wpas_wps_ap_pin_set(wpa_s
, pin
, timeout
) < 0)
726 return os_snprintf(buf
, buflen
, "%s", pin
);
731 #endif /* CONFIG_AP */
735 static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant
*wpa_s
,
738 char *uuid
= cmd
, *pin
, *pos
;
739 u8 addr_buf
[ETH_ALEN
], *addr
= NULL
;
740 pin
= os_strchr(uuid
, ' ');
744 pos
= os_strchr(pin
, ' ');
747 if (hwaddr_aton(pos
, addr_buf
) == 0)
750 return wpas_wps_er_add_pin(wpa_s
, addr
, uuid
, pin
);
754 static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant
*wpa_s
,
757 char *uuid
= cmd
, *pin
;
758 pin
= os_strchr(uuid
, ' ');
762 return wpas_wps_er_learn(wpa_s
, uuid
, pin
);
766 static int wpa_supplicant_ctrl_iface_wps_er_set_config(
767 struct wpa_supplicant
*wpa_s
, char *cmd
)
769 char *uuid
= cmd
, *id
;
770 id
= os_strchr(uuid
, ' ');
774 return wpas_wps_er_set_config(wpa_s
, uuid
, atoi(id
));
778 static int wpa_supplicant_ctrl_iface_wps_er_config(
779 struct wpa_supplicant
*wpa_s
, char *cmd
)
786 struct wps_new_ap_settings ap
;
788 pin
= os_strchr(cmd
, ' ');
793 new_ssid
= os_strchr(pin
, ' ');
794 if (new_ssid
== NULL
)
798 new_auth
= os_strchr(new_ssid
, ' ');
799 if (new_auth
== NULL
)
803 new_encr
= os_strchr(new_auth
, ' ');
804 if (new_encr
== NULL
)
808 new_key
= os_strchr(new_encr
, ' ');
813 os_memset(&ap
, 0, sizeof(ap
));
814 ap
.ssid_hex
= new_ssid
;
817 ap
.key_hex
= new_key
;
818 return wpas_wps_er_config(wpa_s
, cmd
, pin
, &ap
);
820 #endif /* CONFIG_WPS_ER */
822 #endif /* CONFIG_WPS */
825 #ifdef CONFIG_IBSS_RSN
826 static int wpa_supplicant_ctrl_iface_ibss_rsn(
827 struct wpa_supplicant
*wpa_s
, char *addr
)
831 if (hwaddr_aton(addr
, peer
)) {
832 wpa_printf(MSG_DEBUG
, "CTRL_IFACE IBSS_RSN: invalid "
833 "address '%s'", addr
);
837 wpa_printf(MSG_DEBUG
, "CTRL_IFACE IBSS_RSN " MACSTR
,
840 return ibss_rsn_start(wpa_s
->ibss_rsn
, peer
);
842 #endif /* CONFIG_IBSS_RSN */
845 static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant
*wpa_s
,
848 #ifdef IEEE8021X_EAPOL
851 struct wpa_ssid
*ssid
;
853 pos
= os_strchr(rsp
, '-');
858 pos
= os_strchr(pos
, ':');
863 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: field=%s id=%d", rsp
, id
);
864 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
865 (u8
*) pos
, os_strlen(pos
));
867 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
869 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
874 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s
, ssid
, rsp
,
876 #else /* IEEE8021X_EAPOL */
877 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: 802.1X not included");
879 #endif /* IEEE8021X_EAPOL */
883 static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant
*wpa_s
,
885 char *buf
, size_t buflen
)
887 char *pos
, *end
, tmp
[30];
888 int res
, verbose
, wps
, ret
;
890 verbose
= os_strcmp(params
, "-VERBOSE") == 0;
891 wps
= os_strcmp(params
, "-WPS") == 0;
894 if (wpa_s
->wpa_state
>= WPA_ASSOCIATED
) {
895 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
896 ret
= os_snprintf(pos
, end
- pos
, "bssid=" MACSTR
"\n",
897 MAC2STR(wpa_s
->bssid
));
898 if (ret
< 0 || ret
>= end
- pos
)
902 u8
*_ssid
= ssid
->ssid
;
903 size_t ssid_len
= ssid
->ssid_len
;
904 u8 ssid_buf
[MAX_SSID_LEN
];
906 int _res
= wpa_drv_get_ssid(wpa_s
, ssid_buf
);
913 ret
= os_snprintf(pos
, end
- pos
, "ssid=%s\nid=%d\n",
914 wpa_ssid_txt(_ssid
, ssid_len
),
916 if (ret
< 0 || ret
>= end
- pos
)
920 if (wps
&& ssid
->passphrase
&&
921 wpa_key_mgmt_wpa_psk(ssid
->key_mgmt
) &&
922 (ssid
->mode
== WPAS_MODE_AP
||
923 ssid
->mode
== WPAS_MODE_P2P_GO
)) {
924 ret
= os_snprintf(pos
, end
- pos
,
927 if (ret
< 0 || ret
>= end
- pos
)
932 ret
= os_snprintf(pos
, end
- pos
,
935 if (ret
< 0 || ret
>= end
- pos
)
940 switch (ssid
->mode
) {
941 case WPAS_MODE_INFRA
:
942 ret
= os_snprintf(pos
, end
- pos
,
946 ret
= os_snprintf(pos
, end
- pos
,
950 ret
= os_snprintf(pos
, end
- pos
,
953 case WPAS_MODE_P2P_GO
:
954 ret
= os_snprintf(pos
, end
- pos
,
957 case WPAS_MODE_P2P_GROUP_FORMATION
:
958 ret
= os_snprintf(pos
, end
- pos
,
959 "mode=P2P GO - group "
966 if (ret
< 0 || ret
>= end
- pos
)
972 if (wpa_s
->ap_iface
) {
973 pos
+= ap_ctrl_iface_wpa_get_status(wpa_s
, pos
,
977 #endif /* CONFIG_AP */
978 pos
+= wpa_sm_get_status(wpa_s
->wpa
, pos
, end
- pos
, verbose
);
980 ret
= os_snprintf(pos
, end
- pos
, "wpa_state=%s\n",
981 wpa_supplicant_state_txt(wpa_s
->wpa_state
));
982 if (ret
< 0 || ret
>= end
- pos
)
987 l2_packet_get_ip_addr(wpa_s
->l2
, tmp
, sizeof(tmp
)) >= 0) {
988 ret
= os_snprintf(pos
, end
- pos
, "ip_address=%s\n", tmp
);
989 if (ret
< 0 || ret
>= end
- pos
)
995 if (wpa_s
->global
->p2p
) {
996 ret
= os_snprintf(pos
, end
- pos
, "p2p_device_address=" MACSTR
997 "\n", MAC2STR(wpa_s
->global
->p2p_dev_addr
));
998 if (ret
< 0 || ret
>= end
- pos
)
1002 #endif /* CONFIG_P2P */
1004 ret
= os_snprintf(pos
, end
- pos
, "address=" MACSTR
"\n",
1005 MAC2STR(wpa_s
->own_addr
));
1006 if (ret
< 0 || ret
>= end
- pos
)
1011 if (wpa_s
->current_bss
&&
1012 wpa_bss_get_vendor_ie(wpa_s
->current_bss
, HS20_IE_VENDOR_TYPE
)) {
1013 ret
= os_snprintf(pos
, end
- pos
, "hs20=1\n");
1014 if (ret
< 0 || ret
>= end
- pos
)
1018 #endif /* CONFIG_HS20 */
1020 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) ||
1021 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
1022 res
= eapol_sm_get_status(wpa_s
->eapol
, pos
, end
- pos
,
1028 res
= rsn_preauth_get_status(wpa_s
->wpa
, pos
, end
- pos
, verbose
);
1036 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant
*wpa_s
,
1041 struct wpa_ssid
*ssid
;
1044 /* cmd: "<network id> <BSSID>" */
1045 pos
= os_strchr(cmd
, ' ');
1050 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: id=%d bssid='%s'", id
, pos
);
1051 if (hwaddr_aton(pos
, bssid
)) {
1052 wpa_printf(MSG_DEBUG
,"CTRL_IFACE: invalid BSSID '%s'", pos
);
1056 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1058 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
1063 os_memcpy(ssid
->bssid
, bssid
, ETH_ALEN
);
1064 ssid
->bssid_set
= !is_zero_ether_addr(bssid
);
1070 static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant
*wpa_s
,
1071 char *cmd
, char *buf
,
1075 struct wpa_blacklist
*e
;
1079 /* cmd: "BLACKLIST [<BSSID>]" */
1083 e
= wpa_s
->blacklist
;
1085 ret
= os_snprintf(pos
, end
- pos
, MACSTR
"\n",
1087 if (ret
< 0 || ret
>= end
- pos
)
1096 if (os_strncmp(cmd
, "clear", 5) == 0) {
1097 wpa_blacklist_clear(wpa_s
);
1098 os_memcpy(buf
, "OK\n", 3);
1102 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd
);
1103 if (hwaddr_aton(cmd
, bssid
)) {
1104 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: invalid BSSID '%s'", cmd
);
1109 * Add the BSSID twice, so its count will be 2, causing it to be
1110 * skipped when processing scan results.
1112 ret
= wpa_blacklist_add(wpa_s
, bssid
);
1115 ret
= wpa_blacklist_add(wpa_s
, bssid
);
1118 os_memcpy(buf
, "OK\n", 3);
1123 extern int wpa_debug_level
;
1124 extern int wpa_debug_timestamp
;
1126 static const char * debug_level_str(int level
)
1147 static int str_to_debug_level(const char *s
)
1149 if (os_strcasecmp(s
, "EXCESSIVE") == 0)
1150 return MSG_EXCESSIVE
;
1151 if (os_strcasecmp(s
, "MSGDUMP") == 0)
1153 if (os_strcasecmp(s
, "DEBUG") == 0)
1155 if (os_strcasecmp(s
, "INFO") == 0)
1157 if (os_strcasecmp(s
, "WARNING") == 0)
1159 if (os_strcasecmp(s
, "ERROR") == 0)
1165 static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant
*wpa_s
,
1166 char *cmd
, char *buf
,
1169 char *pos
, *end
, *stamp
;
1176 /* cmd: "LOG_LEVEL [<level>]" */
1180 ret
= os_snprintf(pos
, end
- pos
, "Current level: %s\n"
1182 debug_level_str(wpa_debug_level
),
1183 wpa_debug_timestamp
);
1184 if (ret
< 0 || ret
>= end
- pos
)
1193 stamp
= os_strchr(cmd
, ' ');
1196 while (*stamp
== ' ') {
1201 if (cmd
&& os_strlen(cmd
)) {
1202 int level
= str_to_debug_level(cmd
);
1205 wpa_debug_level
= level
;
1208 if (stamp
&& os_strlen(stamp
))
1209 wpa_debug_timestamp
= atoi(stamp
);
1211 os_memcpy(buf
, "OK\n", 3);
1216 static int wpa_supplicant_ctrl_iface_list_networks(
1217 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
1220 struct wpa_ssid
*ssid
;
1225 ret
= os_snprintf(pos
, end
- pos
,
1226 "network id / ssid / bssid / flags\n");
1227 if (ret
< 0 || ret
>= end
- pos
)
1231 ssid
= wpa_s
->conf
->ssid
;
1233 ret
= os_snprintf(pos
, end
- pos
, "%d\t%s",
1235 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
));
1236 if (ret
< 0 || ret
>= end
- pos
)
1239 if (ssid
->bssid_set
) {
1240 ret
= os_snprintf(pos
, end
- pos
, "\t" MACSTR
,
1241 MAC2STR(ssid
->bssid
));
1243 ret
= os_snprintf(pos
, end
- pos
, "\tany");
1245 if (ret
< 0 || ret
>= end
- pos
)
1248 ret
= os_snprintf(pos
, end
- pos
, "\t%s%s%s",
1249 ssid
== wpa_s
->current_ssid
?
1251 ssid
->disabled
? "[DISABLED]" : "",
1252 ssid
->disabled
== 2 ? "[P2P-PERSISTENT]" :
1254 if (ret
< 0 || ret
>= end
- pos
)
1257 ret
= os_snprintf(pos
, end
- pos
, "\n");
1258 if (ret
< 0 || ret
>= end
- pos
)
1269 static char * wpa_supplicant_cipher_txt(char *pos
, char *end
, int cipher
)
1272 ret
= os_snprintf(pos
, end
- pos
, "-");
1273 if (ret
< 0 || ret
>= end
- pos
)
1276 if (cipher
& WPA_CIPHER_NONE
) {
1277 ret
= os_snprintf(pos
, end
- pos
, "%sNONE", first
? "" : "+");
1278 if (ret
< 0 || ret
>= end
- pos
)
1283 if (cipher
& WPA_CIPHER_WEP40
) {
1284 ret
= os_snprintf(pos
, end
- pos
, "%sWEP40", first
? "" : "+");
1285 if (ret
< 0 || ret
>= end
- pos
)
1290 if (cipher
& WPA_CIPHER_WEP104
) {
1291 ret
= os_snprintf(pos
, end
- pos
, "%sWEP104",
1293 if (ret
< 0 || ret
>= end
- pos
)
1298 if (cipher
& WPA_CIPHER_TKIP
) {
1299 ret
= os_snprintf(pos
, end
- pos
, "%sTKIP", first
? "" : "+");
1300 if (ret
< 0 || ret
>= end
- pos
)
1305 if (cipher
& WPA_CIPHER_CCMP
) {
1306 ret
= os_snprintf(pos
, end
- pos
, "%sCCMP", first
? "" : "+");
1307 if (ret
< 0 || ret
>= end
- pos
)
1316 static char * wpa_supplicant_ie_txt(char *pos
, char *end
, const char *proto
,
1317 const u8
*ie
, size_t ie_len
)
1319 struct wpa_ie_data data
;
1322 ret
= os_snprintf(pos
, end
- pos
, "[%s-", proto
);
1323 if (ret
< 0 || ret
>= end
- pos
)
1327 if (wpa_parse_wpa_ie(ie
, ie_len
, &data
) < 0) {
1328 ret
= os_snprintf(pos
, end
- pos
, "?]");
1329 if (ret
< 0 || ret
>= end
- pos
)
1336 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X
) {
1337 ret
= os_snprintf(pos
, end
- pos
, "%sEAP", first
? "" : "+");
1338 if (ret
< 0 || ret
>= end
- pos
)
1343 if (data
.key_mgmt
& WPA_KEY_MGMT_PSK
) {
1344 ret
= os_snprintf(pos
, end
- pos
, "%sPSK", first
? "" : "+");
1345 if (ret
< 0 || ret
>= end
- pos
)
1350 if (data
.key_mgmt
& WPA_KEY_MGMT_WPA_NONE
) {
1351 ret
= os_snprintf(pos
, end
- pos
, "%sNone", first
? "" : "+");
1352 if (ret
< 0 || ret
>= end
- pos
)
1357 #ifdef CONFIG_IEEE80211R
1358 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_IEEE8021X
) {
1359 ret
= os_snprintf(pos
, end
- pos
, "%sFT/EAP",
1361 if (ret
< 0 || ret
>= end
- pos
)
1366 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_PSK
) {
1367 ret
= os_snprintf(pos
, end
- pos
, "%sFT/PSK",
1369 if (ret
< 0 || ret
>= end
- pos
)
1374 #endif /* CONFIG_IEEE80211R */
1375 #ifdef CONFIG_IEEE80211W
1376 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SHA256
) {
1377 ret
= os_snprintf(pos
, end
- pos
, "%sEAP-SHA256",
1379 if (ret
< 0 || ret
>= end
- pos
)
1384 if (data
.key_mgmt
& WPA_KEY_MGMT_PSK_SHA256
) {
1385 ret
= os_snprintf(pos
, end
- pos
, "%sPSK-SHA256",
1387 if (ret
< 0 || ret
>= end
- pos
)
1392 #endif /* CONFIG_IEEE80211W */
1394 pos
= wpa_supplicant_cipher_txt(pos
, end
, data
.pairwise_cipher
);
1396 if (data
.capabilities
& WPA_CAPABILITY_PREAUTH
) {
1397 ret
= os_snprintf(pos
, end
- pos
, "-preauth");
1398 if (ret
< 0 || ret
>= end
- pos
)
1403 ret
= os_snprintf(pos
, end
- pos
, "]");
1404 if (ret
< 0 || ret
>= end
- pos
)
1413 static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant
*wpa_s
,
1414 char *pos
, char *end
,
1415 struct wpabuf
*wps_ie
)
1422 if (wps_is_selected_pbc_registrar(wps_ie
))
1425 else if (wps_is_addr_authorized(wps_ie
, wpa_s
->own_addr
, 0))
1427 #endif /* CONFIG_WPS2 */
1428 else if (wps_is_selected_pin_registrar(wps_ie
))
1433 ret
= os_snprintf(pos
, end
- pos
, "%s", txt
);
1434 if (ret
>= 0 && ret
< end
- pos
)
1436 wpabuf_free(wps_ie
);
1439 #endif /* CONFIG_WPS */
1442 static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant
*wpa_s
,
1443 char *pos
, char *end
,
1444 const struct wpa_bss
*bss
)
1447 struct wpabuf
*wps_ie
;
1448 wps_ie
= wpa_bss_get_vendor_ie_multi(bss
, WPS_IE_VENDOR_TYPE
);
1449 return wpa_supplicant_wps_ie_txt_buf(wpa_s
, pos
, end
, wps_ie
);
1450 #else /* CONFIG_WPS */
1452 #endif /* CONFIG_WPS */
1456 /* Format one result on one text line into a buffer. */
1457 static int wpa_supplicant_ctrl_iface_scan_result(
1458 struct wpa_supplicant
*wpa_s
,
1459 const struct wpa_bss
*bss
, char *buf
, size_t buflen
)
1463 const u8
*ie
, *ie2
, *p2p
;
1465 p2p
= wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
);
1466 if (p2p
&& bss
->ssid_len
== P2P_WILDCARD_SSID_LEN
&&
1467 os_memcmp(bss
->ssid
, P2P_WILDCARD_SSID
, P2P_WILDCARD_SSID_LEN
) ==
1469 return 0; /* Do not show P2P listen discovery results here */
1474 ret
= os_snprintf(pos
, end
- pos
, MACSTR
"\t%d\t%d\t",
1475 MAC2STR(bss
->bssid
), bss
->freq
, bss
->level
);
1476 if (ret
< 0 || ret
>= end
- pos
)
1479 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
1481 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA", ie
, 2 + ie
[1]);
1482 ie2
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
1484 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA2", ie2
, 2 + ie2
[1]);
1485 pos
= wpa_supplicant_wps_ie_txt(wpa_s
, pos
, end
, bss
);
1486 if (!ie
&& !ie2
&& bss
->caps
& IEEE80211_CAP_PRIVACY
) {
1487 ret
= os_snprintf(pos
, end
- pos
, "[WEP]");
1488 if (ret
< 0 || ret
>= end
- pos
)
1492 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
1493 ret
= os_snprintf(pos
, end
- pos
, "[IBSS]");
1494 if (ret
< 0 || ret
>= end
- pos
)
1498 if (bss
->caps
& IEEE80211_CAP_ESS
) {
1499 ret
= os_snprintf(pos
, end
- pos
, "[ESS]");
1500 if (ret
< 0 || ret
>= end
- pos
)
1505 ret
= os_snprintf(pos
, end
- pos
, "[P2P]");
1506 if (ret
< 0 || ret
>= end
- pos
)
1511 if (wpa_bss_get_vendor_ie(bss
, HS20_IE_VENDOR_TYPE
)) {
1512 ret
= os_snprintf(pos
, end
- pos
, "[HS20]");
1513 if (ret
< 0 || ret
>= end
- pos
)
1517 #endif /* CONFIG_HS20 */
1519 ret
= os_snprintf(pos
, end
- pos
, "\t%s",
1520 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
1521 if (ret
< 0 || ret
>= end
- pos
)
1525 ret
= os_snprintf(pos
, end
- pos
, "\n");
1526 if (ret
< 0 || ret
>= end
- pos
)
1534 static int wpa_supplicant_ctrl_iface_scan_results(
1535 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
1538 struct wpa_bss
*bss
;
1543 ret
= os_snprintf(pos
, end
- pos
, "bssid / frequency / signal level / "
1545 if (ret
< 0 || ret
>= end
- pos
)
1549 dl_list_for_each(bss
, &wpa_s
->bss_id
, struct wpa_bss
, list_id
) {
1550 ret
= wpa_supplicant_ctrl_iface_scan_result(wpa_s
, bss
, pos
,
1552 if (ret
< 0 || ret
>= end
- pos
)
1561 static int wpa_supplicant_ctrl_iface_select_network(
1562 struct wpa_supplicant
*wpa_s
, char *cmd
)
1565 struct wpa_ssid
*ssid
;
1567 /* cmd: "<network id>" or "any" */
1568 if (os_strcmp(cmd
, "any") == 0) {
1569 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SELECT_NETWORK any");
1573 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SELECT_NETWORK id=%d", id
);
1575 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1577 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
1578 "network id=%d", id
);
1581 if (ssid
->disabled
== 2) {
1582 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
1583 "SELECT_NETWORK with persistent P2P group");
1588 wpa_supplicant_select_network(wpa_s
, ssid
);
1594 static int wpa_supplicant_ctrl_iface_enable_network(
1595 struct wpa_supplicant
*wpa_s
, char *cmd
)
1598 struct wpa_ssid
*ssid
;
1600 /* cmd: "<network id>" or "all" */
1601 if (os_strcmp(cmd
, "all") == 0) {
1602 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ENABLE_NETWORK all");
1606 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ENABLE_NETWORK id=%d", id
);
1608 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1610 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
1611 "network id=%d", id
);
1614 if (ssid
->disabled
== 2) {
1615 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
1616 "ENABLE_NETWORK with persistent P2P group");
1620 if (os_strstr(cmd
, " no-connect")) {
1625 wpa_supplicant_enable_network(wpa_s
, ssid
);
1631 static int wpa_supplicant_ctrl_iface_disable_network(
1632 struct wpa_supplicant
*wpa_s
, char *cmd
)
1635 struct wpa_ssid
*ssid
;
1637 /* cmd: "<network id>" or "all" */
1638 if (os_strcmp(cmd
, "all") == 0) {
1639 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DISABLE_NETWORK all");
1643 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DISABLE_NETWORK id=%d", id
);
1645 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1647 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
1648 "network id=%d", id
);
1651 if (ssid
->disabled
== 2) {
1652 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
1653 "DISABLE_NETWORK with persistent P2P "
1658 wpa_supplicant_disable_network(wpa_s
, ssid
);
1664 static int wpa_supplicant_ctrl_iface_add_network(
1665 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
1667 struct wpa_ssid
*ssid
;
1670 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ADD_NETWORK");
1672 ssid
= wpa_config_add_network(wpa_s
->conf
);
1676 wpas_notify_network_added(wpa_s
, ssid
);
1679 wpa_config_set_network_defaults(ssid
);
1681 ret
= os_snprintf(buf
, buflen
, "%d\n", ssid
->id
);
1682 if (ret
< 0 || (size_t) ret
>= buflen
)
1688 static int wpa_supplicant_ctrl_iface_remove_network(
1689 struct wpa_supplicant
*wpa_s
, char *cmd
)
1692 struct wpa_ssid
*ssid
;
1694 /* cmd: "<network id>" or "all" */
1695 if (os_strcmp(cmd
, "all") == 0) {
1696 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_NETWORK all");
1697 ssid
= wpa_s
->conf
->ssid
;
1699 struct wpa_ssid
*remove_ssid
= ssid
;
1702 wpas_notify_network_removed(wpa_s
, remove_ssid
);
1703 wpa_config_remove_network(wpa_s
->conf
, id
);
1705 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
1706 if (wpa_s
->current_ssid
) {
1708 wpa_s
->sme
.prev_bssid_set
= 0;
1709 #endif /* CONFIG_SME */
1710 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
1711 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
1712 wpa_supplicant_disassociate(wpa_s
,
1713 WLAN_REASON_DEAUTH_LEAVING
);
1719 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_NETWORK id=%d", id
);
1721 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1723 wpas_notify_network_removed(wpa_s
, ssid
);
1725 wpa_config_remove_network(wpa_s
->conf
, id
) < 0) {
1726 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
1731 if (ssid
== wpa_s
->current_ssid
|| wpa_s
->current_ssid
== NULL
) {
1733 wpa_s
->sme
.prev_bssid_set
= 0;
1734 #endif /* CONFIG_SME */
1736 * Invalidate the EAP session cache if the current or
1737 * previously used network is removed.
1739 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
1742 if (ssid
== wpa_s
->current_ssid
) {
1743 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
1744 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
1746 wpa_supplicant_disassociate(wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
1753 static int wpa_supplicant_ctrl_iface_set_network(
1754 struct wpa_supplicant
*wpa_s
, char *cmd
)
1757 struct wpa_ssid
*ssid
;
1760 /* cmd: "<network id> <variable name> <value>" */
1761 name
= os_strchr(cmd
, ' ');
1766 value
= os_strchr(name
, ' ');
1772 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
1774 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
1775 (u8
*) value
, os_strlen(value
));
1777 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1779 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
1784 if (wpa_config_set(ssid
, name
, value
, 0) < 0) {
1785 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to set network "
1786 "variable '%s'", name
);
1790 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, ssid
);
1792 if (wpa_s
->current_ssid
== ssid
|| wpa_s
->current_ssid
== NULL
) {
1794 * Invalidate the EAP session cache if anything in the current
1795 * or previously used configuration changes.
1797 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
1800 if ((os_strcmp(name
, "psk") == 0 &&
1801 value
[0] == '"' && ssid
->ssid_len
) ||
1802 (os_strcmp(name
, "ssid") == 0 && ssid
->passphrase
))
1803 wpa_config_update_psk(ssid
);
1804 else if (os_strcmp(name
, "priority") == 0)
1805 wpa_config_update_prio_list(wpa_s
->conf
);
1811 static int wpa_supplicant_ctrl_iface_get_network(
1812 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
1816 struct wpa_ssid
*ssid
;
1819 /* cmd: "<network id> <variable name>" */
1820 name
= os_strchr(cmd
, ' ');
1821 if (name
== NULL
|| buflen
== 0)
1826 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
1829 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1831 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
1836 value
= wpa_config_get_no_key(ssid
, name
);
1837 if (value
== NULL
) {
1838 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to get network "
1839 "variable '%s'", name
);
1843 res
= os_strlcpy(buf
, value
, buflen
);
1844 if (res
>= buflen
) {
1855 static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant
*wpa_s
,
1856 char *buf
, size_t buflen
)
1859 struct wpa_cred
*cred
;
1864 ret
= os_snprintf(pos
, end
- pos
,
1865 "cred id / realm / username / domain / imsi\n");
1866 if (ret
< 0 || ret
>= end
- pos
)
1870 cred
= wpa_s
->conf
->cred
;
1872 ret
= os_snprintf(pos
, end
- pos
, "%d\t%s\t%s\t%s\t%s\n",
1873 cred
->id
, cred
->realm
? cred
->realm
: "",
1874 cred
->username
? cred
->username
: "",
1875 cred
->domain
? cred
->domain
: "",
1876 cred
->imsi
? cred
->imsi
: "");
1877 if (ret
< 0 || ret
>= end
- pos
)
1888 static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant
*wpa_s
,
1889 char *buf
, size_t buflen
)
1891 struct wpa_cred
*cred
;
1894 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ADD_CRED");
1896 cred
= wpa_config_add_cred(wpa_s
->conf
);
1900 ret
= os_snprintf(buf
, buflen
, "%d\n", cred
->id
);
1901 if (ret
< 0 || (size_t) ret
>= buflen
)
1907 static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant
*wpa_s
,
1911 struct wpa_cred
*cred
;
1913 /* cmd: "<cred id>" or "all" */
1914 if (os_strcmp(cmd
, "all") == 0) {
1915 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED all");
1916 cred
= wpa_s
->conf
->cred
;
1920 wpa_config_remove_cred(wpa_s
->conf
, id
);
1926 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED id=%d", id
);
1928 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
1930 wpa_config_remove_cred(wpa_s
->conf
, id
) < 0) {
1931 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred id=%d",
1940 static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant
*wpa_s
,
1944 struct wpa_cred
*cred
;
1947 /* cmd: "<cred id> <variable name> <value>" */
1948 name
= os_strchr(cmd
, ' ');
1953 value
= os_strchr(name
, ' ');
1959 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SET_CRED id=%d name='%s'",
1961 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
1962 (u8
*) value
, os_strlen(value
));
1964 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
1966 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred id=%d",
1971 if (wpa_config_set_cred(cred
, name
, value
, 0) < 0) {
1972 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to set cred "
1973 "variable '%s'", name
);
1981 #ifndef CONFIG_NO_CONFIG_WRITE
1982 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant
*wpa_s
)
1986 if (!wpa_s
->conf
->update_config
) {
1987 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
1988 "to update configuration (update_config=0)");
1992 ret
= wpa_config_write(wpa_s
->confname
, wpa_s
->conf
);
1994 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Failed to "
1995 "update configuration");
1997 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Configuration"
2003 #endif /* CONFIG_NO_CONFIG_WRITE */
2006 static int ctrl_iface_get_capability_pairwise(int res
, char *strict
,
2007 struct wpa_driver_capa
*capa
,
2008 char *buf
, size_t buflen
)
2020 len
= os_strlcpy(buf
, "CCMP TKIP NONE", buflen
);
2026 if (capa
->enc
& WPA_DRIVER_CAPA_ENC_CCMP
) {
2027 ret
= os_snprintf(pos
, end
- pos
, "%sCCMP", first
? "" : " ");
2028 if (ret
< 0 || ret
>= end
- pos
)
2034 if (capa
->enc
& WPA_DRIVER_CAPA_ENC_TKIP
) {
2035 ret
= os_snprintf(pos
, end
- pos
, "%sTKIP", first
? "" : " ");
2036 if (ret
< 0 || ret
>= end
- pos
)
2042 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
) {
2043 ret
= os_snprintf(pos
, end
- pos
, "%sNONE", first
? "" : " ");
2044 if (ret
< 0 || ret
>= end
- pos
)
2054 static int ctrl_iface_get_capability_group(int res
, char *strict
,
2055 struct wpa_driver_capa
*capa
,
2056 char *buf
, size_t buflen
)
2068 len
= os_strlcpy(buf
, "CCMP TKIP WEP104 WEP40", buflen
);
2074 if (capa
->enc
& WPA_DRIVER_CAPA_ENC_CCMP
) {
2075 ret
= os_snprintf(pos
, end
- pos
, "%sCCMP", first
? "" : " ");
2076 if (ret
< 0 || ret
>= end
- pos
)
2082 if (capa
->enc
& WPA_DRIVER_CAPA_ENC_TKIP
) {
2083 ret
= os_snprintf(pos
, end
- pos
, "%sTKIP", first
? "" : " ");
2084 if (ret
< 0 || ret
>= end
- pos
)
2090 if (capa
->enc
& WPA_DRIVER_CAPA_ENC_WEP104
) {
2091 ret
= os_snprintf(pos
, end
- pos
, "%sWEP104",
2093 if (ret
< 0 || ret
>= end
- pos
)
2099 if (capa
->enc
& WPA_DRIVER_CAPA_ENC_WEP40
) {
2100 ret
= os_snprintf(pos
, end
- pos
, "%sWEP40", first
? "" : " ");
2101 if (ret
< 0 || ret
>= end
- pos
)
2111 static int ctrl_iface_get_capability_key_mgmt(int res
, char *strict
,
2112 struct wpa_driver_capa
*capa
,
2113 char *buf
, size_t buflen
)
2125 len
= os_strlcpy(buf
, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
2132 ret
= os_snprintf(pos
, end
- pos
, "NONE IEEE8021X");
2133 if (ret
< 0 || ret
>= end
- pos
)
2137 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
2138 WPA_DRIVER_CAPA_KEY_MGMT_WPA2
)) {
2139 ret
= os_snprintf(pos
, end
- pos
, " WPA-EAP");
2140 if (ret
< 0 || ret
>= end
- pos
)
2145 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
|
2146 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
)) {
2147 ret
= os_snprintf(pos
, end
- pos
, " WPA-PSK");
2148 if (ret
< 0 || ret
>= end
- pos
)
2153 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
) {
2154 ret
= os_snprintf(pos
, end
- pos
, " WPA-NONE");
2155 if (ret
< 0 || ret
>= end
- pos
)
2164 static int ctrl_iface_get_capability_proto(int res
, char *strict
,
2165 struct wpa_driver_capa
*capa
,
2166 char *buf
, size_t buflen
)
2178 len
= os_strlcpy(buf
, "RSN WPA", buflen
);
2184 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA2
|
2185 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
)) {
2186 ret
= os_snprintf(pos
, end
- pos
, "%sRSN", first
? "" : " ");
2187 if (ret
< 0 || ret
>= end
- pos
)
2193 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
2194 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
)) {
2195 ret
= os_snprintf(pos
, end
- pos
, "%sWPA", first
? "" : " ");
2196 if (ret
< 0 || ret
>= end
- pos
)
2206 static int ctrl_iface_get_capability_auth_alg(int res
, char *strict
,
2207 struct wpa_driver_capa
*capa
,
2208 char *buf
, size_t buflen
)
2220 len
= os_strlcpy(buf
, "OPEN SHARED LEAP", buflen
);
2226 if (capa
->auth
& (WPA_DRIVER_AUTH_OPEN
)) {
2227 ret
= os_snprintf(pos
, end
- pos
, "%sOPEN", first
? "" : " ");
2228 if (ret
< 0 || ret
>= end
- pos
)
2234 if (capa
->auth
& (WPA_DRIVER_AUTH_SHARED
)) {
2235 ret
= os_snprintf(pos
, end
- pos
, "%sSHARED",
2237 if (ret
< 0 || ret
>= end
- pos
)
2243 if (capa
->auth
& (WPA_DRIVER_AUTH_LEAP
)) {
2244 ret
= os_snprintf(pos
, end
- pos
, "%sLEAP", first
? "" : " ");
2245 if (ret
< 0 || ret
>= end
- pos
)
2255 static int wpa_supplicant_ctrl_iface_get_capability(
2256 struct wpa_supplicant
*wpa_s
, const char *_field
, char *buf
,
2259 struct wpa_driver_capa capa
;
2265 /* Determine whether or not strict checking was requested */
2266 len
= os_strlcpy(field
, _field
, sizeof(field
));
2267 if (len
>= sizeof(field
))
2269 strict
= os_strchr(field
, ' ');
2270 if (strict
!= NULL
) {
2272 if (os_strcmp(strict
, "strict") != 0)
2276 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
2277 field
, strict
? strict
: "");
2279 if (os_strcmp(field
, "eap") == 0) {
2280 return eap_get_names(buf
, buflen
);
2283 res
= wpa_drv_get_capa(wpa_s
, &capa
);
2285 if (os_strcmp(field
, "pairwise") == 0)
2286 return ctrl_iface_get_capability_pairwise(res
, strict
, &capa
,
2289 if (os_strcmp(field
, "group") == 0)
2290 return ctrl_iface_get_capability_group(res
, strict
, &capa
,
2293 if (os_strcmp(field
, "key_mgmt") == 0)
2294 return ctrl_iface_get_capability_key_mgmt(res
, strict
, &capa
,
2297 if (os_strcmp(field
, "proto") == 0)
2298 return ctrl_iface_get_capability_proto(res
, strict
, &capa
,
2301 if (os_strcmp(field
, "auth_alg") == 0)
2302 return ctrl_iface_get_capability_auth_alg(res
, strict
, &capa
,
2305 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
2312 #ifdef CONFIG_INTERWORKING
2313 static char * anqp_add_hex(char *pos
, char *end
, const char *title
,
2314 struct wpabuf
*data
)
2324 ret
= os_snprintf(pos
, end
- pos
, "%s=", title
);
2325 if (ret
< 0 || ret
>= end
- pos
)
2329 d
= wpabuf_head_u8(data
);
2330 for (i
= 0; i
< wpabuf_len(data
); i
++) {
2331 ret
= os_snprintf(pos
, end
- pos
, "%02x", *d
++);
2332 if (ret
< 0 || ret
>= end
- pos
)
2337 ret
= os_snprintf(pos
, end
- pos
, "\n");
2338 if (ret
< 0 || ret
>= end
- pos
)
2344 #endif /* CONFIG_INTERWORKING */
2347 static int print_bss_info(struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
,
2348 unsigned long mask
, char *buf
, size_t buflen
)
2358 if (mask
& WPA_BSS_MASK_ID
) {
2359 ret
= os_snprintf(pos
, end
- pos
, "id=%u\n", bss
->id
);
2360 if (ret
< 0 || ret
>= end
- pos
)
2365 if (mask
& WPA_BSS_MASK_BSSID
) {
2366 ret
= os_snprintf(pos
, end
- pos
, "bssid=" MACSTR
"\n",
2367 MAC2STR(bss
->bssid
));
2368 if (ret
< 0 || ret
>= end
- pos
)
2373 if (mask
& WPA_BSS_MASK_FREQ
) {
2374 ret
= os_snprintf(pos
, end
- pos
, "freq=%d\n", bss
->freq
);
2375 if (ret
< 0 || ret
>= end
- pos
)
2380 if (mask
& WPA_BSS_MASK_BEACON_INT
) {
2381 ret
= os_snprintf(pos
, end
- pos
, "beacon_int=%d\n",
2383 if (ret
< 0 || ret
>= end
- pos
)
2388 if (mask
& WPA_BSS_MASK_CAPABILITIES
) {
2389 ret
= os_snprintf(pos
, end
- pos
, "capabilities=0x%04x\n",
2391 if (ret
< 0 || ret
>= end
- pos
)
2396 if (mask
& WPA_BSS_MASK_QUAL
) {
2397 ret
= os_snprintf(pos
, end
- pos
, "qual=%d\n", bss
->qual
);
2398 if (ret
< 0 || ret
>= end
- pos
)
2403 if (mask
& WPA_BSS_MASK_NOISE
) {
2404 ret
= os_snprintf(pos
, end
- pos
, "noise=%d\n", bss
->noise
);
2405 if (ret
< 0 || ret
>= end
- pos
)
2410 if (mask
& WPA_BSS_MASK_LEVEL
) {
2411 ret
= os_snprintf(pos
, end
- pos
, "level=%d\n", bss
->level
);
2412 if (ret
< 0 || ret
>= end
- pos
)
2417 if (mask
& WPA_BSS_MASK_TSF
) {
2418 ret
= os_snprintf(pos
, end
- pos
, "tsf=%016llu\n",
2419 (unsigned long long) bss
->tsf
);
2420 if (ret
< 0 || ret
>= end
- pos
)
2425 if (mask
& WPA_BSS_MASK_AGE
) {
2429 ret
= os_snprintf(pos
, end
- pos
, "age=%d\n",
2430 (int) (now
.sec
- bss
->last_update
.sec
));
2431 if (ret
< 0 || ret
>= end
- pos
)
2436 if (mask
& WPA_BSS_MASK_IE
) {
2437 ret
= os_snprintf(pos
, end
- pos
, "ie=");
2438 if (ret
< 0 || ret
>= end
- pos
)
2442 ie
= (const u8
*) (bss
+ 1);
2443 for (i
= 0; i
< bss
->ie_len
; i
++) {
2444 ret
= os_snprintf(pos
, end
- pos
, "%02x", *ie
++);
2445 if (ret
< 0 || ret
>= end
- pos
)
2450 ret
= os_snprintf(pos
, end
- pos
, "\n");
2451 if (ret
< 0 || ret
>= end
- pos
)
2456 if (mask
& WPA_BSS_MASK_FLAGS
) {
2457 ret
= os_snprintf(pos
, end
- pos
, "flags=");
2458 if (ret
< 0 || ret
>= end
- pos
)
2462 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
2464 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA", ie
,
2466 ie2
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
2468 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA2", ie2
,
2470 pos
= wpa_supplicant_wps_ie_txt(wpa_s
, pos
, end
, bss
);
2471 if (!ie
&& !ie2
&& bss
->caps
& IEEE80211_CAP_PRIVACY
) {
2472 ret
= os_snprintf(pos
, end
- pos
, "[WEP]");
2473 if (ret
< 0 || ret
>= end
- pos
)
2477 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
2478 ret
= os_snprintf(pos
, end
- pos
, "[IBSS]");
2479 if (ret
< 0 || ret
>= end
- pos
)
2483 if (bss
->caps
& IEEE80211_CAP_ESS
) {
2484 ret
= os_snprintf(pos
, end
- pos
, "[ESS]");
2485 if (ret
< 0 || ret
>= end
- pos
)
2489 if (wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
)) {
2490 ret
= os_snprintf(pos
, end
- pos
, "[P2P]");
2491 if (ret
< 0 || ret
>= end
- pos
)
2496 if (wpa_bss_get_vendor_ie(bss
, HS20_IE_VENDOR_TYPE
)) {
2497 ret
= os_snprintf(pos
, end
- pos
, "[HS20]");
2498 if (ret
< 0 || ret
>= end
- pos
)
2502 #endif /* CONFIG_HS20 */
2504 ret
= os_snprintf(pos
, end
- pos
, "\n");
2505 if (ret
< 0 || ret
>= end
- pos
)
2510 if (mask
& WPA_BSS_MASK_SSID
) {
2511 ret
= os_snprintf(pos
, end
- pos
, "ssid=%s\n",
2512 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
2513 if (ret
< 0 || ret
>= end
- pos
)
2519 if (mask
& WPA_BSS_MASK_WPS_SCAN
) {
2520 ie
= (const u8
*) (bss
+ 1);
2521 ret
= wpas_wps_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
2522 if (ret
< 0 || ret
>= end
- pos
)
2526 #endif /* CONFIG_WPS */
2529 if (mask
& WPA_BSS_MASK_P2P_SCAN
) {
2530 ie
= (const u8
*) (bss
+ 1);
2531 ret
= wpas_p2p_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
2532 if (ret
< 0 || ret
>= end
- pos
)
2536 #endif /* CONFIG_P2P */
2538 #ifdef CONFIG_INTERWORKING
2539 if (mask
& WPA_BSS_MASK_INTERNETW
) {
2540 pos
= anqp_add_hex(pos
, end
, "anqp_venue_name",
2541 bss
->anqp_venue_name
);
2542 pos
= anqp_add_hex(pos
, end
, "anqp_network_auth_type",
2543 bss
->anqp_network_auth_type
);
2544 pos
= anqp_add_hex(pos
, end
, "anqp_roaming_consortium",
2545 bss
->anqp_roaming_consortium
);
2546 pos
= anqp_add_hex(pos
, end
, "anqp_ip_addr_type_availability",
2547 bss
->anqp_ip_addr_type_availability
);
2548 pos
= anqp_add_hex(pos
, end
, "anqp_nai_realm",
2549 bss
->anqp_nai_realm
);
2550 pos
= anqp_add_hex(pos
, end
, "anqp_3gpp", bss
->anqp_3gpp
);
2551 pos
= anqp_add_hex(pos
, end
, "anqp_domain_name",
2552 bss
->anqp_domain_name
);
2554 pos
= anqp_add_hex(pos
, end
, "hs20_operator_friendly_name",
2555 bss
->hs20_operator_friendly_name
);
2556 pos
= anqp_add_hex(pos
, end
, "hs20_wan_metrics",
2557 bss
->hs20_wan_metrics
);
2558 pos
= anqp_add_hex(pos
, end
, "hs20_connection_capability",
2559 bss
->hs20_connection_capability
);
2560 #endif /* CONFIG_HS20 */
2562 #endif /* CONFIG_INTERWORKING */
2568 static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant
*wpa_s
,
2569 const char *cmd
, char *buf
,
2574 struct wpa_bss
*bss
;
2575 struct wpa_bss
*bsslast
= NULL
;
2576 struct dl_list
*next
;
2580 unsigned long mask
= WPA_BSS_MASK_ALL
;
2582 if (os_strncmp(cmd
, "RANGE=", 6) == 0) {
2583 if (os_strncmp(cmd
+ 6, "ALL", 3) == 0) {
2584 bss
= dl_list_first(&wpa_s
->bss_id
, struct wpa_bss
,
2586 bsslast
= dl_list_last(&wpa_s
->bss_id
, struct wpa_bss
,
2588 } else { /* N1-N2 */
2589 unsigned int id1
, id2
;
2591 if ((ctmp
= os_strchr(cmd
+ 6, '-')) == NULL
) {
2592 wpa_printf(MSG_INFO
, "Wrong BSS range "
2597 id1
= atoi(cmd
+ 6);
2598 bss
= wpa_bss_get_id(wpa_s
, id1
);
2599 id2
= atoi(ctmp
+ 1);
2601 bsslast
= dl_list_last(&wpa_s
->bss_id
,
2605 bsslast
= wpa_bss_get_id(wpa_s
, id2
);
2606 if (bsslast
== NULL
&& bss
&& id2
> id1
) {
2607 struct wpa_bss
*tmp
= bss
;
2609 next
= tmp
->list_id
.next
;
2610 if (next
== &wpa_s
->bss_id
)
2612 tmp
= dl_list_entry(
2613 next
, struct wpa_bss
,
2622 } else if (os_strcmp(cmd
, "FIRST") == 0)
2623 bss
= dl_list_first(&wpa_s
->bss_id
, struct wpa_bss
, list_id
);
2624 else if (os_strncmp(cmd
, "ID-", 3) == 0) {
2626 bss
= wpa_bss_get_id(wpa_s
, i
);
2627 } else if (os_strncmp(cmd
, "NEXT-", 5) == 0) {
2629 bss
= wpa_bss_get_id(wpa_s
, i
);
2631 next
= bss
->list_id
.next
;
2632 if (next
== &wpa_s
->bss_id
)
2635 bss
= dl_list_entry(next
, struct wpa_bss
,
2639 } else if (os_strncmp(cmd
, "p2p_dev_addr=", 13) == 0) {
2640 if (hwaddr_aton(cmd
+ 13, bssid
) == 0)
2641 bss
= wpa_bss_get_p2p_dev_addr(wpa_s
, bssid
);
2644 #endif /* CONFIG_P2P */
2645 } else if (hwaddr_aton(cmd
, bssid
) == 0)
2646 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
2648 struct wpa_bss
*tmp
;
2651 dl_list_for_each(tmp
, &wpa_s
->bss_id
, struct wpa_bss
, list_id
)
2660 if ((ctmp
= os_strstr(cmd
, "MASK=")) != NULL
) {
2661 mask
= strtoul(ctmp
+ 5, NULL
, 0x10);
2663 mask
= WPA_BSS_MASK_ALL
;
2669 if (bsslast
== NULL
)
2672 len
= print_bss_info(wpa_s
, bss
, mask
, buf
, buflen
);
2678 next
= bss
->list_id
.next
;
2679 if (next
== &wpa_s
->bss_id
)
2681 bss
= dl_list_entry(next
, struct wpa_bss
, list_id
);
2682 } while (bss
&& len
);
2688 static int wpa_supplicant_ctrl_iface_ap_scan(
2689 struct wpa_supplicant
*wpa_s
, char *cmd
)
2691 int ap_scan
= atoi(cmd
);
2692 return wpa_supplicant_set_ap_scan(wpa_s
, ap_scan
);
2696 static int wpa_supplicant_ctrl_iface_scan_interval(
2697 struct wpa_supplicant
*wpa_s
, char *cmd
)
2699 int scan_int
= atoi(cmd
);
2700 return wpa_supplicant_set_scan_interval(wpa_s
, scan_int
);
2704 static int wpa_supplicant_ctrl_iface_bss_expire_age(
2705 struct wpa_supplicant
*wpa_s
, char *cmd
)
2707 int expire_age
= atoi(cmd
);
2708 return wpa_supplicant_set_bss_expiration_age(wpa_s
, expire_age
);
2712 static int wpa_supplicant_ctrl_iface_bss_expire_count(
2713 struct wpa_supplicant
*wpa_s
, char *cmd
)
2715 int expire_count
= atoi(cmd
);
2716 return wpa_supplicant_set_bss_expiration_count(wpa_s
, expire_count
);
2720 static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant
*wpa_s
)
2722 wpa_printf(MSG_DEBUG
, "Dropping SA without deauthentication");
2723 /* MLME-DELETEKEYS.request */
2724 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 0, 0, NULL
, 0, NULL
, 0);
2725 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 1, 0, NULL
, 0, NULL
, 0);
2726 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 2, 0, NULL
, 0, NULL
, 0);
2727 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 3, 0, NULL
, 0, NULL
, 0);
2728 #ifdef CONFIG_IEEE80211W
2729 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 4, 0, NULL
, 0, NULL
, 0);
2730 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 5, 0, NULL
, 0, NULL
, 0);
2731 #endif /* CONFIG_IEEE80211W */
2733 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, wpa_s
->bssid
, 0, 0, NULL
, 0, NULL
,
2735 /* MLME-SETPROTECTION.request(None) */
2736 wpa_drv_mlme_setprotection(wpa_s
, wpa_s
->bssid
,
2737 MLME_SETPROTECTION_PROTECT_TYPE_NONE
,
2738 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE
);
2739 wpa_sm_drop_sa(wpa_s
->wpa
);
2743 static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant
*wpa_s
,
2746 #ifdef CONFIG_NO_SCAN_PROCESSING
2748 #else /* CONFIG_NO_SCAN_PROCESSING */
2750 struct wpa_bss
*bss
;
2751 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
2753 if (hwaddr_aton(addr
, bssid
)) {
2754 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: invalid "
2755 "address '%s'", addr
);
2759 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM " MACSTR
, MAC2STR(bssid
));
2761 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
2763 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: Target AP not found "
2769 * TODO: Find best network configuration block from configuration to
2770 * allow roaming to other networks
2774 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: No network "
2775 "configuration known for the target AP");
2779 wpa_s
->reassociate
= 1;
2780 wpa_supplicant_connect(wpa_s
, bss
, ssid
);
2783 #endif /* CONFIG_NO_SCAN_PROCESSING */
2788 static int p2p_ctrl_find(struct wpa_supplicant
*wpa_s
, char *cmd
)
2790 unsigned int timeout
= atoi(cmd
);
2791 enum p2p_discovery_type type
= P2P_FIND_START_WITH_FULL
;
2792 u8 dev_id
[ETH_ALEN
], *_dev_id
= NULL
;
2795 if (os_strstr(cmd
, "type=social"))
2796 type
= P2P_FIND_ONLY_SOCIAL
;
2797 else if (os_strstr(cmd
, "type=progressive"))
2798 type
= P2P_FIND_PROGRESSIVE
;
2800 pos
= os_strstr(cmd
, "dev_id=");
2803 if (hwaddr_aton(pos
, dev_id
))
2808 return wpas_p2p_find(wpa_s
, timeout
, type
, 0, NULL
, _dev_id
);
2812 static int p2p_ctrl_connect(struct wpa_supplicant
*wpa_s
, char *cmd
,
2813 char *buf
, size_t buflen
)
2818 enum p2p_wps_method wps_method
;
2821 int persistent_group
, persistent_id
= -1;
2828 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad]
2829 * [persistent|persistent=<network id>]
2830 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] */
2832 if (hwaddr_aton(cmd
, addr
))
2840 persistent_group
= os_strstr(pos
, " persistent") != NULL
;
2841 pos2
= os_strstr(pos
, " persistent=");
2843 struct wpa_ssid
*ssid
;
2844 persistent_id
= atoi(pos2
+ 12);
2845 ssid
= wpa_config_get_network(wpa_s
->conf
, persistent_id
);
2846 if (ssid
== NULL
|| ssid
->disabled
!= 2 ||
2847 ssid
->mode
!= WPAS_MODE_P2P_GO
) {
2848 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
2849 "SSID id=%d for persistent P2P group (GO)",
2854 join
= os_strstr(pos
, " join") != NULL
;
2855 auth
= os_strstr(pos
, " auth") != NULL
;
2856 automatic
= os_strstr(pos
, " auto") != NULL
;
2858 pos2
= os_strstr(pos
, " go_intent=");
2861 go_intent
= atoi(pos2
);
2862 if (go_intent
< 0 || go_intent
> 15)
2866 pos2
= os_strstr(pos
, " freq=");
2874 if (os_strncmp(pos
, "pin", 3) == 0) {
2875 /* Request random PIN (to be displayed) and enable the PIN */
2876 wps_method
= WPS_PIN_DISPLAY
;
2877 } else if (os_strncmp(pos
, "pbc", 3) == 0) {
2878 wps_method
= WPS_PBC
;
2881 pos
= os_strchr(pin
, ' ');
2882 wps_method
= WPS_PIN_KEYPAD
;
2885 if (os_strncmp(pos
, "display", 7) == 0)
2886 wps_method
= WPS_PIN_DISPLAY
;
2890 new_pin
= wpas_p2p_connect(wpa_s
, addr
, pin
, wps_method
,
2891 persistent_group
, automatic
, join
,
2892 auth
, go_intent
, freq
, persistent_id
);
2893 if (new_pin
== -2) {
2894 os_memcpy(buf
, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
2897 if (new_pin
== -3) {
2898 os_memcpy(buf
, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
2903 if (wps_method
== WPS_PIN_DISPLAY
&& pin
== NULL
) {
2904 ret
= os_snprintf(buf
, buflen
, "%08d", new_pin
);
2905 if (ret
< 0 || (size_t) ret
>= buflen
)
2910 os_memcpy(buf
, "OK\n", 3);
2915 static int p2p_ctrl_listen(struct wpa_supplicant
*wpa_s
, char *cmd
)
2917 unsigned int timeout
= atoi(cmd
);
2918 return wpas_p2p_listen(wpa_s
, timeout
);
2922 static int p2p_ctrl_prov_disc(struct wpa_supplicant
*wpa_s
, char *cmd
)
2926 enum wpas_p2p_prov_disc_use use
= WPAS_P2P_PD_FOR_GO_NEG
;
2928 /* <addr> <config method> [join|auto] */
2930 if (hwaddr_aton(cmd
, addr
))
2938 if (os_strstr(pos
, " join") != NULL
)
2939 use
= WPAS_P2P_PD_FOR_JOIN
;
2940 else if (os_strstr(pos
, " auto") != NULL
)
2941 use
= WPAS_P2P_PD_AUTO
;
2943 return wpas_p2p_prov_disc(wpa_s
, addr
, pos
, use
);
2947 static int p2p_get_passphrase(struct wpa_supplicant
*wpa_s
, char *buf
,
2950 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
2952 if (ssid
== NULL
|| ssid
->mode
!= WPAS_MODE_P2P_GO
||
2953 ssid
->passphrase
== NULL
)
2956 os_strlcpy(buf
, ssid
->passphrase
, buflen
);
2957 return os_strlen(buf
);
2961 static int p2p_ctrl_serv_disc_req(struct wpa_supplicant
*wpa_s
, char *cmd
,
2962 char *buf
, size_t buflen
)
2966 u8 dst_buf
[ETH_ALEN
], *dst
;
2967 struct wpabuf
*tlvs
;
2971 if (hwaddr_aton(cmd
, dst_buf
))
2974 if (dst
[0] == 0 && dst
[1] == 0 && dst
[2] == 0 &&
2975 dst
[3] == 0 && dst
[4] == 0 && dst
[5] == 0)
2982 if (os_strncmp(pos
, "upnp ", 5) == 0) {
2985 if (hexstr2bin(pos
, &version
, 1) < 0)
2991 ref
= wpas_p2p_sd_request_upnp(wpa_s
, dst
, version
, pos
);
2993 len
= os_strlen(pos
);
2997 tlvs
= wpabuf_alloc(len
);
3000 if (hexstr2bin(pos
, wpabuf_put(tlvs
, len
), len
) < 0) {
3005 ref
= wpas_p2p_sd_request(wpa_s
, dst
, tlvs
);
3010 res
= os_snprintf(buf
, buflen
, "%llx", (long long unsigned) ref
);
3011 if (res
< 0 || (unsigned) res
>= buflen
)
3017 static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant
*wpa_s
,
3020 long long unsigned val
;
3022 if (sscanf(cmd
, "%llx", &val
) != 1)
3025 return wpas_p2p_sd_cancel_request(wpa_s
, req
);
3029 static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant
*wpa_s
, char *cmd
)
3034 struct wpabuf
*resp_tlvs
;
3038 pos
= os_strchr(cmd
, ' ');
3046 if (hwaddr_aton(pos
, dst
))
3053 pos2
= os_strchr(pos
, ' ');
3057 dialog_token
= atoi(pos
);
3059 len
= os_strlen(pos2
);
3063 resp_tlvs
= wpabuf_alloc(len
);
3064 if (resp_tlvs
== NULL
)
3066 if (hexstr2bin(pos2
, wpabuf_put(resp_tlvs
, len
), len
) < 0) {
3067 wpabuf_free(resp_tlvs
);
3071 wpas_p2p_sd_response(wpa_s
, freq
, dst
, dialog_token
, resp_tlvs
);
3072 wpabuf_free(resp_tlvs
);
3077 static int p2p_ctrl_serv_disc_external(struct wpa_supplicant
*wpa_s
,
3080 if (os_strcmp(cmd
, "0") && os_strcmp(cmd
, "1"))
3082 wpa_s
->p2p_sd_over_ctrl_iface
= atoi(cmd
);
3087 static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant
*wpa_s
,
3092 struct wpabuf
*query
, *resp
;
3094 pos
= os_strchr(cmd
, ' ');
3099 len
= os_strlen(cmd
);
3103 query
= wpabuf_alloc(len
);
3106 if (hexstr2bin(cmd
, wpabuf_put(query
, len
), len
) < 0) {
3111 len
= os_strlen(pos
);
3117 resp
= wpabuf_alloc(len
);
3122 if (hexstr2bin(pos
, wpabuf_put(resp
, len
), len
) < 0) {
3128 if (wpas_p2p_service_add_bonjour(wpa_s
, query
, resp
) < 0) {
3137 static int p2p_ctrl_service_add_upnp(struct wpa_supplicant
*wpa_s
, char *cmd
)
3142 pos
= os_strchr(cmd
, ' ');
3147 if (hexstr2bin(cmd
, &version
, 1) < 0)
3150 return wpas_p2p_service_add_upnp(wpa_s
, version
, pos
);
3154 static int p2p_ctrl_service_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
3158 pos
= os_strchr(cmd
, ' ');
3163 if (os_strcmp(cmd
, "bonjour") == 0)
3164 return p2p_ctrl_service_add_bonjour(wpa_s
, pos
);
3165 if (os_strcmp(cmd
, "upnp") == 0)
3166 return p2p_ctrl_service_add_upnp(wpa_s
, pos
);
3167 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
3172 static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant
*wpa_s
,
3176 struct wpabuf
*query
;
3179 len
= os_strlen(cmd
);
3183 query
= wpabuf_alloc(len
);
3186 if (hexstr2bin(cmd
, wpabuf_put(query
, len
), len
) < 0) {
3191 ret
= wpas_p2p_service_del_bonjour(wpa_s
, query
);
3197 static int p2p_ctrl_service_del_upnp(struct wpa_supplicant
*wpa_s
, char *cmd
)
3202 pos
= os_strchr(cmd
, ' ');
3207 if (hexstr2bin(cmd
, &version
, 1) < 0)
3210 return wpas_p2p_service_del_upnp(wpa_s
, version
, pos
);
3214 static int p2p_ctrl_service_del(struct wpa_supplicant
*wpa_s
, char *cmd
)
3218 pos
= os_strchr(cmd
, ' ');
3223 if (os_strcmp(cmd
, "bonjour") == 0)
3224 return p2p_ctrl_service_del_bonjour(wpa_s
, pos
);
3225 if (os_strcmp(cmd
, "upnp") == 0)
3226 return p2p_ctrl_service_del_upnp(wpa_s
, pos
);
3227 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
3232 static int p2p_ctrl_reject(struct wpa_supplicant
*wpa_s
, char *cmd
)
3238 if (hwaddr_aton(cmd
, addr
))
3241 return wpas_p2p_reject(wpa_s
, addr
);
3245 static int p2p_ctrl_invite_persistent(struct wpa_supplicant
*wpa_s
, char *cmd
)
3249 struct wpa_ssid
*ssid
;
3253 pos
= os_strstr(cmd
, " peer=");
3256 if (hwaddr_aton(pos
, peer
))
3259 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3260 if (ssid
== NULL
|| ssid
->disabled
!= 2) {
3261 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
3262 "for persistent P2P group",
3267 return wpas_p2p_invite(wpa_s
, pos
? peer
: NULL
, ssid
, NULL
);
3271 static int p2p_ctrl_invite_group(struct wpa_supplicant
*wpa_s
, char *cmd
)
3274 u8 peer
[ETH_ALEN
], go_dev_addr
[ETH_ALEN
], *go_dev
= NULL
;
3276 pos
= os_strstr(cmd
, " peer=");
3282 if (hwaddr_aton(pos
, peer
)) {
3283 wpa_printf(MSG_DEBUG
, "P2P: Invalid MAC address '%s'", pos
);
3287 pos
= os_strstr(pos
, " go_dev_addr=");
3290 if (hwaddr_aton(pos
, go_dev_addr
)) {
3291 wpa_printf(MSG_DEBUG
, "P2P: Invalid MAC address '%s'",
3295 go_dev
= go_dev_addr
;
3298 return wpas_p2p_invite_group(wpa_s
, cmd
, peer
, go_dev
);
3302 static int p2p_ctrl_invite(struct wpa_supplicant
*wpa_s
, char *cmd
)
3304 if (os_strncmp(cmd
, "persistent=", 11) == 0)
3305 return p2p_ctrl_invite_persistent(wpa_s
, cmd
+ 11);
3306 if (os_strncmp(cmd
, "group=", 6) == 0)
3307 return p2p_ctrl_invite_group(wpa_s
, cmd
+ 6);
3313 static int p2p_ctrl_group_add_persistent(struct wpa_supplicant
*wpa_s
,
3314 char *cmd
, int freq
)
3317 struct wpa_ssid
*ssid
;
3320 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3321 if (ssid
== NULL
|| ssid
->disabled
!= 2) {
3322 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
3323 "for persistent P2P group",
3328 return wpas_p2p_group_add_persistent(wpa_s
, ssid
, 0, freq
);
3332 static int p2p_ctrl_group_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
3337 pos
= os_strstr(cmd
, "freq=");
3339 freq
= atoi(pos
+ 5);
3341 if (os_strncmp(cmd
, "persistent=", 11) == 0)
3342 return p2p_ctrl_group_add_persistent(wpa_s
, cmd
+ 11, freq
);
3343 if (os_strcmp(cmd
, "persistent") == 0 ||
3344 os_strncmp(cmd
, "persistent ", 11) == 0)
3345 return wpas_p2p_group_add(wpa_s
, 1, freq
);
3346 if (os_strncmp(cmd
, "freq=", 5) == 0)
3347 return wpas_p2p_group_add(wpa_s
, 0, freq
);
3349 wpa_printf(MSG_DEBUG
, "CTRL: Invalid P2P_GROUP_ADD parameters '%s'",
3355 static int p2p_ctrl_peer(struct wpa_supplicant
*wpa_s
, char *cmd
,
3356 char *buf
, size_t buflen
)
3358 u8 addr
[ETH_ALEN
], *addr_ptr
;
3360 const struct p2p_peer_info
*info
;
3362 char devtype
[WPS_DEV_TYPE_BUFSIZE
];
3363 struct wpa_ssid
*ssid
;
3365 if (!wpa_s
->global
->p2p
)
3368 if (os_strcmp(cmd
, "FIRST") == 0) {
3371 } else if (os_strncmp(cmd
, "NEXT-", 5) == 0) {
3372 if (hwaddr_aton(cmd
+ 5, addr
) < 0)
3377 if (hwaddr_aton(cmd
, addr
) < 0)
3383 info
= p2p_get_peer_info(wpa_s
->global
->p2p
, addr_ptr
, next
);
3390 res
= os_snprintf(pos
, end
- pos
, MACSTR
"\n"
3396 "serial_number=%s\n"
3397 "config_methods=0x%x\n"
3399 "group_capab=0x%x\n"
3401 MAC2STR(info
->p2p_device_addr
),
3402 wps_dev_type_bin2str(info
->pri_dev_type
,
3403 devtype
, sizeof(devtype
)),
3408 info
->serial_number
,
3409 info
->config_methods
,
3413 if (res
< 0 || res
>= end
- pos
)
3417 ssid
= wpas_p2p_get_persistent(wpa_s
, info
->p2p_device_addr
, NULL
, 0);
3419 res
= os_snprintf(pos
, end
- pos
, "persistent=%d\n", ssid
->id
);
3420 if (res
< 0 || res
>= end
- pos
)
3425 res
= p2p_get_peer_info_txt(info
, pos
, end
- pos
);
3434 static int p2p_ctrl_disallow_freq(struct wpa_supplicant
*wpa_s
,
3437 struct wpa_freq_range
*freq
= NULL
, *n
;
3438 unsigned int count
= 0, i
;
3439 const char *pos
, *pos2
, *pos3
;
3441 if (wpa_s
->global
->p2p
== NULL
)
3445 * param includes comma separated frequency range.
3446 * For example: 2412-2432,2462,5000-6000
3449 while (pos
&& pos
[0]) {
3450 n
= os_realloc(freq
,
3451 (count
+ 1) * sizeof(struct wpa_freq_range
));
3457 freq
[count
].min
= atoi(pos
);
3458 pos2
= os_strchr(pos
, '-');
3459 pos3
= os_strchr(pos
, ',');
3460 if (pos2
&& (!pos3
|| pos2
< pos3
)) {
3462 freq
[count
].max
= atoi(pos2
);
3464 freq
[count
].max
= freq
[count
].min
;
3471 for (i
= 0; i
< count
; i
++) {
3472 wpa_printf(MSG_DEBUG
, "P2P: Disallowed frequency range %u-%u",
3473 freq
[i
].min
, freq
[i
].max
);
3476 os_free(wpa_s
->global
->p2p_disallow_freq
);
3477 wpa_s
->global
->p2p_disallow_freq
= freq
;
3478 wpa_s
->global
->num_p2p_disallow_freq
= count
;
3479 wpas_p2p_update_channel_list(wpa_s
);
3484 static int p2p_ctrl_set(struct wpa_supplicant
*wpa_s
, char *cmd
)
3488 if (wpa_s
->global
->p2p
== NULL
)
3491 param
= os_strchr(cmd
, ' ');
3496 if (os_strcmp(cmd
, "discoverability") == 0) {
3497 p2p_set_client_discoverability(wpa_s
->global
->p2p
,
3502 if (os_strcmp(cmd
, "managed") == 0) {
3503 p2p_set_managed_oper(wpa_s
->global
->p2p
, atoi(param
));
3507 if (os_strcmp(cmd
, "listen_channel") == 0) {
3508 return p2p_set_listen_channel(wpa_s
->global
->p2p
, 81,
3512 if (os_strcmp(cmd
, "ssid_postfix") == 0) {
3513 return p2p_set_ssid_postfix(wpa_s
->global
->p2p
, (u8
*) param
,
3517 if (os_strcmp(cmd
, "noa") == 0) {
3519 int count
, start
, duration
;
3520 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
3521 count
= atoi(param
);
3522 pos
= os_strchr(param
, ',');
3527 pos
= os_strchr(pos
, ',');
3531 duration
= atoi(pos
);
3532 if (count
< 0 || count
> 255 || start
< 0 || duration
< 0)
3534 if (count
== 0 && duration
> 0)
3536 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
3537 "start=%d duration=%d", count
, start
, duration
);
3538 return wpas_p2p_set_noa(wpa_s
, count
, start
, duration
);
3541 if (os_strcmp(cmd
, "ps") == 0)
3542 return wpa_drv_set_p2p_powersave(wpa_s
, atoi(param
), -1, -1);
3544 if (os_strcmp(cmd
, "oppps") == 0)
3545 return wpa_drv_set_p2p_powersave(wpa_s
, -1, atoi(param
), -1);
3547 if (os_strcmp(cmd
, "ctwindow") == 0)
3548 return wpa_drv_set_p2p_powersave(wpa_s
, -1, -1, atoi(param
));
3550 if (os_strcmp(cmd
, "disabled") == 0) {
3551 wpa_s
->global
->p2p_disabled
= atoi(param
);
3552 wpa_printf(MSG_DEBUG
, "P2P functionality %s",
3553 wpa_s
->global
->p2p_disabled
?
3554 "disabled" : "enabled");
3555 if (wpa_s
->global
->p2p_disabled
) {
3556 wpas_p2p_stop_find(wpa_s
);
3557 os_memset(wpa_s
->p2p_auth_invite
, 0, ETH_ALEN
);
3558 p2p_flush(wpa_s
->global
->p2p
);
3563 if (os_strcmp(cmd
, "force_long_sd") == 0) {
3564 wpa_s
->force_long_sd
= atoi(param
);
3568 if (os_strcmp(cmd
, "peer_filter") == 0) {
3570 if (hwaddr_aton(param
, addr
))
3572 p2p_set_peer_filter(wpa_s
->global
->p2p
, addr
);
3576 if (os_strcmp(cmd
, "cross_connect") == 0)
3577 return wpas_p2p_set_cross_connect(wpa_s
, atoi(param
));
3579 if (os_strcmp(cmd
, "go_apsd") == 0) {
3580 if (os_strcmp(param
, "disable") == 0)
3581 wpa_s
->set_ap_uapsd
= 0;
3583 wpa_s
->set_ap_uapsd
= 1;
3584 wpa_s
->ap_uapsd
= atoi(param
);
3589 if (os_strcmp(cmd
, "client_apsd") == 0) {
3590 if (os_strcmp(param
, "disable") == 0)
3591 wpa_s
->set_sta_uapsd
= 0;
3595 /* format: BE,BK,VI,VO;max SP Length */
3597 pos
= os_strchr(param
, ',');
3602 pos
= os_strchr(pos
, ',');
3607 pos
= os_strchr(pos
, ',');
3612 /* ignore max SP Length for now */
3614 wpa_s
->set_sta_uapsd
= 1;
3615 wpa_s
->sta_uapsd
= 0;
3617 wpa_s
->sta_uapsd
|= BIT(0);
3619 wpa_s
->sta_uapsd
|= BIT(1);
3621 wpa_s
->sta_uapsd
|= BIT(2);
3623 wpa_s
->sta_uapsd
|= BIT(3);
3628 if (os_strcmp(cmd
, "disallow_freq") == 0)
3629 return p2p_ctrl_disallow_freq(wpa_s
, param
);
3631 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
3638 static int p2p_ctrl_presence_req(struct wpa_supplicant
*wpa_s
, char *cmd
)
3641 unsigned int dur1
= 0, int1
= 0, dur2
= 0, int2
= 0;
3644 pos
= os_strchr(cmd
, ' ');
3650 pos2
= os_strchr(pos
, ' ');
3658 pos
= os_strchr(pos2
, ' ');
3666 return wpas_p2p_presence_req(wpa_s
, dur1
, int1
, dur2
, int2
);
3670 static int p2p_ctrl_ext_listen(struct wpa_supplicant
*wpa_s
, char *cmd
)
3673 unsigned int period
= 0, interval
= 0;
3676 pos
= os_strchr(cmd
, ' ');
3681 interval
= atoi(pos
);
3684 return wpas_p2p_ext_listen(wpa_s
, period
, interval
);
3687 #endif /* CONFIG_P2P */
3690 #ifdef CONFIG_INTERWORKING
3691 static int ctrl_interworking_connect(struct wpa_supplicant
*wpa_s
, char *dst
)
3694 struct wpa_bss
*bss
;
3696 if (hwaddr_aton(dst
, bssid
)) {
3697 wpa_printf(MSG_DEBUG
, "Invalid BSSID '%s'", dst
);
3701 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
3703 wpa_printf(MSG_DEBUG
, "Could not find BSS " MACSTR
,
3708 return interworking_connect(wpa_s
, bss
);
3712 static int get_anqp(struct wpa_supplicant
*wpa_s
, char *dst
)
3714 u8 dst_addr
[ETH_ALEN
];
3717 #define MAX_ANQP_INFO_ID 100
3718 u16 id
[MAX_ANQP_INFO_ID
];
3721 used
= hwaddr_aton2(dst
, dst_addr
);
3725 while (num_id
< MAX_ANQP_INFO_ID
) {
3726 id
[num_id
] = atoi(pos
);
3729 pos
= os_strchr(pos
+ 1, ',');
3738 return anqp_send_req(wpa_s
, dst_addr
, id
, num_id
);
3740 #endif /* CONFIG_INTERWORKING */
3745 static int get_hs20_anqp(struct wpa_supplicant
*wpa_s
, char *dst
)
3747 u8 dst_addr
[ETH_ALEN
];
3752 used
= hwaddr_aton2(dst
, dst_addr
);
3757 int num
= atoi(pos
);
3758 if (num
<= 0 || num
> 31)
3760 subtypes
|= BIT(num
);
3761 pos
= os_strchr(pos
+ 1, ',');
3770 return hs20_anqp_send_req(wpa_s
, dst_addr
, subtypes
, NULL
, 0);
3774 static int hs20_nai_home_realm_list(struct wpa_supplicant
*wpa_s
,
3775 const u8
*addr
, const char *realm
)
3781 rlen
= os_strlen(realm
);
3783 buf
= os_malloc(len
);
3786 buf
[0] = 1; /* NAI Home Realm Count */
3787 buf
[1] = 0; /* Formatted in accordance with RFC 4282 */
3789 os_memcpy(buf
+ 3, realm
, rlen
);
3791 ret
= hs20_anqp_send_req(wpa_s
, addr
,
3792 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY
),
3801 static int hs20_get_nai_home_realm_list(struct wpa_supplicant
*wpa_s
,
3804 struct wpa_cred
*cred
= wpa_s
->conf
->cred
;
3805 u8 dst_addr
[ETH_ALEN
];
3811 used
= hwaddr_aton2(dst
, dst_addr
);
3815 while (dst
[used
] == ' ')
3817 if (os_strncmp(dst
+ used
, "realm=", 6) == 0)
3818 return hs20_nai_home_realm_list(wpa_s
, dst_addr
,
3821 len
= os_strlen(dst
+ used
);
3823 if (len
== 0 && cred
&& cred
->realm
)
3824 return hs20_nai_home_realm_list(wpa_s
, dst_addr
, cred
->realm
);
3829 buf
= os_malloc(len
);
3832 if (hexstr2bin(dst
+ used
, buf
, len
) < 0) {
3837 ret
= hs20_anqp_send_req(wpa_s
, dst_addr
,
3838 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY
),
3845 #endif /* CONFIG_HS20 */
3848 static int wpa_supplicant_ctrl_iface_sta_autoconnect(
3849 struct wpa_supplicant
*wpa_s
, char *cmd
)
3851 wpa_s
->auto_reconnect_disabled
= atoi(cmd
) == 0 ? 1 : 0;
3856 static int wpa_supplicant_signal_poll(struct wpa_supplicant
*wpa_s
, char *buf
,
3859 struct wpa_signal_info si
;
3862 ret
= wpa_drv_signal_poll(wpa_s
, &si
);
3866 ret
= os_snprintf(buf
, buflen
, "RSSI=%d\nLINKSPEED=%d\n"
3867 "NOISE=%d\nFREQUENCY=%u\n",
3868 si
.current_signal
, si
.current_txrate
/ 1000,
3869 si
.current_noise
, si
.frequency
);
3870 if (ret
< 0 || (unsigned int) ret
> buflen
)
3876 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant
*wpa_s
,
3877 char *buf
, size_t *resp_len
)
3880 const int reply_size
= 4096;
3884 if (os_strncmp(buf
, WPA_CTRL_RSP
, os_strlen(WPA_CTRL_RSP
)) == 0 ||
3885 os_strncmp(buf
, "SET_NETWORK ", 12) == 0) {
3886 wpa_hexdump_ascii_key(MSG_DEBUG
, "RX ctrl_iface",
3887 (const u8
*) buf
, os_strlen(buf
));
3889 int level
= MSG_DEBUG
;
3890 if (os_strcmp(buf
, "PING") == 0)
3891 level
= MSG_EXCESSIVE
;
3892 wpa_hexdump_ascii(level
, "RX ctrl_iface",
3893 (const u8
*) buf
, os_strlen(buf
));
3896 reply
= os_malloc(reply_size
);
3897 if (reply
== NULL
) {
3902 os_memcpy(reply
, "OK\n", 3);
3905 if (os_strcmp(buf
, "PING") == 0) {
3906 os_memcpy(reply
, "PONG\n", 5);
3908 } else if (os_strncmp(buf
, "RELOG", 5) == 0) {
3909 if (wpa_debug_reopen_file() < 0)
3911 } else if (os_strncmp(buf
, "NOTE ", 5) == 0) {
3912 wpa_printf(MSG_INFO
, "NOTE: %s", buf
+ 5);
3913 } else if (os_strcmp(buf
, "MIB") == 0) {
3914 reply_len
= wpa_sm_get_mib(wpa_s
->wpa
, reply
, reply_size
);
3915 if (reply_len
>= 0) {
3917 res
= eapol_sm_get_mib(wpa_s
->eapol
, reply
+ reply_len
,
3918 reply_size
- reply_len
);
3924 } else if (os_strncmp(buf
, "STATUS", 6) == 0) {
3925 reply_len
= wpa_supplicant_ctrl_iface_status(
3926 wpa_s
, buf
+ 6, reply
, reply_size
);
3927 } else if (os_strcmp(buf
, "PMKSA") == 0) {
3928 reply_len
= wpa_sm_pmksa_cache_list(wpa_s
->wpa
, reply
,
3930 } else if (os_strncmp(buf
, "SET ", 4) == 0) {
3931 if (wpa_supplicant_ctrl_iface_set(wpa_s
, buf
+ 4))
3933 } else if (os_strncmp(buf
, "GET ", 4) == 0) {
3934 reply_len
= wpa_supplicant_ctrl_iface_get(wpa_s
, buf
+ 4,
3936 } else if (os_strcmp(buf
, "LOGON") == 0) {
3937 eapol_sm_notify_logoff(wpa_s
->eapol
, FALSE
);
3938 } else if (os_strcmp(buf
, "LOGOFF") == 0) {
3939 eapol_sm_notify_logoff(wpa_s
->eapol
, TRUE
);
3940 } else if (os_strcmp(buf
, "REASSOCIATE") == 0) {
3941 wpa_s
->normal_scans
= 0;
3942 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
3945 wpa_s
->disconnected
= 0;
3946 wpa_s
->reassociate
= 1;
3947 wpa_supplicant_req_scan(wpa_s
, 0, 0);
3949 } else if (os_strcmp(buf
, "RECONNECT") == 0) {
3950 wpa_s
->normal_scans
= 0;
3951 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
3953 else if (wpa_s
->disconnected
) {
3954 wpa_s
->disconnected
= 0;
3955 wpa_s
->reassociate
= 1;
3956 wpa_supplicant_req_scan(wpa_s
, 0, 0);
3958 #ifdef IEEE8021X_EAPOL
3959 } else if (os_strncmp(buf
, "PREAUTH ", 8) == 0) {
3960 if (wpa_supplicant_ctrl_iface_preauth(wpa_s
, buf
+ 8))
3962 #endif /* IEEE8021X_EAPOL */
3963 #ifdef CONFIG_PEERKEY
3964 } else if (os_strncmp(buf
, "STKSTART ", 9) == 0) {
3965 if (wpa_supplicant_ctrl_iface_stkstart(wpa_s
, buf
+ 9))
3967 #endif /* CONFIG_PEERKEY */
3968 #ifdef CONFIG_IEEE80211R
3969 } else if (os_strncmp(buf
, "FT_DS ", 6) == 0) {
3970 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s
, buf
+ 6))
3972 #endif /* CONFIG_IEEE80211R */
3974 } else if (os_strcmp(buf
, "WPS_PBC") == 0) {
3975 int res
= wpa_supplicant_ctrl_iface_wps_pbc(wpa_s
, NULL
);
3977 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
3981 } else if (os_strncmp(buf
, "WPS_PBC ", 8) == 0) {
3982 int res
= wpa_supplicant_ctrl_iface_wps_pbc(wpa_s
, buf
+ 8);
3984 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
3988 } else if (os_strncmp(buf
, "WPS_PIN ", 8) == 0) {
3989 reply_len
= wpa_supplicant_ctrl_iface_wps_pin(wpa_s
, buf
+ 8,
3992 } else if (os_strncmp(buf
, "WPS_CHECK_PIN ", 14) == 0) {
3993 reply_len
= wpa_supplicant_ctrl_iface_wps_check_pin(
3994 wpa_s
, buf
+ 14, reply
, reply_size
);
3995 } else if (os_strcmp(buf
, "WPS_CANCEL") == 0) {
3996 if (wpas_wps_cancel(wpa_s
))
3998 #ifdef CONFIG_WPS_OOB
3999 } else if (os_strncmp(buf
, "WPS_OOB ", 8) == 0) {
4000 if (wpa_supplicant_ctrl_iface_wps_oob(wpa_s
, buf
+ 8))
4002 #endif /* CONFIG_WPS_OOB */
4003 } else if (os_strncmp(buf
, "WPS_REG ", 8) == 0) {
4004 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s
, buf
+ 8))
4007 } else if (os_strncmp(buf
, "WPS_AP_PIN ", 11) == 0) {
4008 reply_len
= wpa_supplicant_ctrl_iface_wps_ap_pin(
4009 wpa_s
, buf
+ 11, reply
, reply_size
);
4010 #endif /* CONFIG_AP */
4011 #ifdef CONFIG_WPS_ER
4012 } else if (os_strcmp(buf
, "WPS_ER_START") == 0) {
4013 if (wpas_wps_er_start(wpa_s
, NULL
))
4015 } else if (os_strncmp(buf
, "WPS_ER_START ", 13) == 0) {
4016 if (wpas_wps_er_start(wpa_s
, buf
+ 13))
4018 } else if (os_strcmp(buf
, "WPS_ER_STOP") == 0) {
4019 if (wpas_wps_er_stop(wpa_s
))
4021 } else if (os_strncmp(buf
, "WPS_ER_PIN ", 11) == 0) {
4022 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s
, buf
+ 11))
4024 } else if (os_strncmp(buf
, "WPS_ER_PBC ", 11) == 0) {
4025 int ret
= wpas_wps_er_pbc(wpa_s
, buf
+ 11);
4027 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
4029 } else if (ret
== -3) {
4030 os_memcpy(reply
, "FAIL-UNKNOWN-UUID\n", 18);
4032 } else if (ret
== -4) {
4033 os_memcpy(reply
, "FAIL-NO-AP-SETTINGS\n", 20);
4037 } else if (os_strncmp(buf
, "WPS_ER_LEARN ", 13) == 0) {
4038 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s
, buf
+ 13))
4040 } else if (os_strncmp(buf
, "WPS_ER_SET_CONFIG ", 18) == 0) {
4041 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s
,
4044 } else if (os_strncmp(buf
, "WPS_ER_CONFIG ", 14) == 0) {
4045 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s
, buf
+ 14))
4047 #endif /* CONFIG_WPS_ER */
4048 #endif /* CONFIG_WPS */
4049 #ifdef CONFIG_IBSS_RSN
4050 } else if (os_strncmp(buf
, "IBSS_RSN ", 9) == 0) {
4051 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s
, buf
+ 9))
4053 #endif /* CONFIG_IBSS_RSN */
4055 } else if (os_strncmp(buf
, "P2P_FIND ", 9) == 0) {
4056 if (p2p_ctrl_find(wpa_s
, buf
+ 9))
4058 } else if (os_strcmp(buf
, "P2P_FIND") == 0) {
4059 if (p2p_ctrl_find(wpa_s
, ""))
4061 } else if (os_strcmp(buf
, "P2P_STOP_FIND") == 0) {
4062 wpas_p2p_stop_find(wpa_s
);
4063 } else if (os_strncmp(buf
, "P2P_CONNECT ", 12) == 0) {
4064 reply_len
= p2p_ctrl_connect(wpa_s
, buf
+ 12, reply
,
4066 } else if (os_strncmp(buf
, "P2P_LISTEN ", 11) == 0) {
4067 if (p2p_ctrl_listen(wpa_s
, buf
+ 11))
4069 } else if (os_strcmp(buf
, "P2P_LISTEN") == 0) {
4070 if (p2p_ctrl_listen(wpa_s
, ""))
4072 } else if (os_strncmp(buf
, "P2P_GROUP_REMOVE ", 17) == 0) {
4073 if (wpas_p2p_group_remove(wpa_s
, buf
+ 17))
4075 } else if (os_strcmp(buf
, "P2P_GROUP_ADD") == 0) {
4076 if (wpas_p2p_group_add(wpa_s
, 0, 0))
4078 } else if (os_strncmp(buf
, "P2P_GROUP_ADD ", 14) == 0) {
4079 if (p2p_ctrl_group_add(wpa_s
, buf
+ 14))
4081 } else if (os_strncmp(buf
, "P2P_PROV_DISC ", 14) == 0) {
4082 if (p2p_ctrl_prov_disc(wpa_s
, buf
+ 14))
4084 } else if (os_strcmp(buf
, "P2P_GET_PASSPHRASE") == 0) {
4085 reply_len
= p2p_get_passphrase(wpa_s
, reply
, reply_size
);
4086 } else if (os_strncmp(buf
, "P2P_SERV_DISC_REQ ", 18) == 0) {
4087 reply_len
= p2p_ctrl_serv_disc_req(wpa_s
, buf
+ 18, reply
,
4089 } else if (os_strncmp(buf
, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
4090 if (p2p_ctrl_serv_disc_cancel_req(wpa_s
, buf
+ 25) < 0)
4092 } else if (os_strncmp(buf
, "P2P_SERV_DISC_RESP ", 19) == 0) {
4093 if (p2p_ctrl_serv_disc_resp(wpa_s
, buf
+ 19) < 0)
4095 } else if (os_strcmp(buf
, "P2P_SERVICE_UPDATE") == 0) {
4096 wpas_p2p_sd_service_update(wpa_s
);
4097 } else if (os_strncmp(buf
, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
4098 if (p2p_ctrl_serv_disc_external(wpa_s
, buf
+ 23) < 0)
4100 } else if (os_strcmp(buf
, "P2P_SERVICE_FLUSH") == 0) {
4101 wpas_p2p_service_flush(wpa_s
);
4102 } else if (os_strncmp(buf
, "P2P_SERVICE_ADD ", 16) == 0) {
4103 if (p2p_ctrl_service_add(wpa_s
, buf
+ 16) < 0)
4105 } else if (os_strncmp(buf
, "P2P_SERVICE_DEL ", 16) == 0) {
4106 if (p2p_ctrl_service_del(wpa_s
, buf
+ 16) < 0)
4108 } else if (os_strncmp(buf
, "P2P_REJECT ", 11) == 0) {
4109 if (p2p_ctrl_reject(wpa_s
, buf
+ 11) < 0)
4111 } else if (os_strncmp(buf
, "P2P_INVITE ", 11) == 0) {
4112 if (p2p_ctrl_invite(wpa_s
, buf
+ 11) < 0)
4114 } else if (os_strncmp(buf
, "P2P_PEER ", 9) == 0) {
4115 reply_len
= p2p_ctrl_peer(wpa_s
, buf
+ 9, reply
,
4117 } else if (os_strncmp(buf
, "P2P_SET ", 8) == 0) {
4118 if (p2p_ctrl_set(wpa_s
, buf
+ 8) < 0)
4120 } else if (os_strcmp(buf
, "P2P_FLUSH") == 0) {
4121 os_memset(wpa_s
->p2p_auth_invite
, 0, ETH_ALEN
);
4122 wpa_s
->force_long_sd
= 0;
4123 if (wpa_s
->global
->p2p
)
4124 p2p_flush(wpa_s
->global
->p2p
);
4125 } else if (os_strncmp(buf
, "P2P_UNAUTHORIZE ", 16) == 0) {
4126 if (wpas_p2p_unauthorize(wpa_s
, buf
+ 16) < 0)
4128 } else if (os_strcmp(buf
, "P2P_CANCEL") == 0) {
4129 if (wpas_p2p_cancel(wpa_s
))
4131 } else if (os_strncmp(buf
, "P2P_PRESENCE_REQ ", 17) == 0) {
4132 if (p2p_ctrl_presence_req(wpa_s
, buf
+ 17) < 0)
4134 } else if (os_strcmp(buf
, "P2P_PRESENCE_REQ") == 0) {
4135 if (p2p_ctrl_presence_req(wpa_s
, "") < 0)
4137 } else if (os_strncmp(buf
, "P2P_EXT_LISTEN ", 15) == 0) {
4138 if (p2p_ctrl_ext_listen(wpa_s
, buf
+ 15) < 0)
4140 } else if (os_strcmp(buf
, "P2P_EXT_LISTEN") == 0) {
4141 if (p2p_ctrl_ext_listen(wpa_s
, "") < 0)
4143 #endif /* CONFIG_P2P */
4144 #ifdef CONFIG_INTERWORKING
4145 } else if (os_strcmp(buf
, "FETCH_ANQP") == 0) {
4146 if (interworking_fetch_anqp(wpa_s
) < 0)
4148 } else if (os_strcmp(buf
, "STOP_FETCH_ANQP") == 0) {
4149 interworking_stop_fetch_anqp(wpa_s
);
4150 } else if (os_strncmp(buf
, "INTERWORKING_SELECT", 19) == 0) {
4151 if (interworking_select(wpa_s
, os_strstr(buf
+ 19, "auto") !=
4154 } else if (os_strncmp(buf
, "INTERWORKING_CONNECT ", 21) == 0) {
4155 if (ctrl_interworking_connect(wpa_s
, buf
+ 21) < 0)
4157 } else if (os_strncmp(buf
, "ANQP_GET ", 9) == 0) {
4158 if (get_anqp(wpa_s
, buf
+ 9) < 0)
4160 #endif /* CONFIG_INTERWORKING */
4162 } else if (os_strncmp(buf
, "HS20_ANQP_GET ", 14) == 0) {
4163 if (get_hs20_anqp(wpa_s
, buf
+ 14) < 0)
4165 } else if (os_strncmp(buf
, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
4166 if (hs20_get_nai_home_realm_list(wpa_s
, buf
+ 29) < 0)
4168 #endif /* CONFIG_HS20 */
4169 } else if (os_strncmp(buf
, WPA_CTRL_RSP
, os_strlen(WPA_CTRL_RSP
)) == 0)
4171 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
4172 wpa_s
, buf
+ os_strlen(WPA_CTRL_RSP
)))
4176 } else if (os_strcmp(buf
, "RECONFIGURE") == 0) {
4177 if (wpa_supplicant_reload_configuration(wpa_s
))
4179 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
4180 wpa_supplicant_terminate_proc(wpa_s
->global
);
4181 } else if (os_strncmp(buf
, "BSSID ", 6) == 0) {
4182 if (wpa_supplicant_ctrl_iface_bssid(wpa_s
, buf
+ 6))
4184 } else if (os_strncmp(buf
, "BLACKLIST", 9) == 0) {
4185 reply_len
= wpa_supplicant_ctrl_iface_blacklist(
4186 wpa_s
, buf
+ 9, reply
, reply_size
);
4187 } else if (os_strncmp(buf
, "LOG_LEVEL", 9) == 0) {
4188 reply_len
= wpa_supplicant_ctrl_iface_log_level(
4189 wpa_s
, buf
+ 9, reply
, reply_size
);
4190 } else if (os_strcmp(buf
, "LIST_NETWORKS") == 0) {
4191 reply_len
= wpa_supplicant_ctrl_iface_list_networks(
4192 wpa_s
, reply
, reply_size
);
4193 } else if (os_strcmp(buf
, "DISCONNECT") == 0) {
4195 wpa_s
->sme
.prev_bssid_set
= 0;
4196 #endif /* CONFIG_SME */
4197 wpa_s
->reassociate
= 0;
4198 wpa_s
->disconnected
= 1;
4199 wpa_supplicant_cancel_sched_scan(wpa_s
);
4200 wpa_supplicant_deauthenticate(wpa_s
,
4201 WLAN_REASON_DEAUTH_LEAVING
);
4202 } else if (os_strcmp(buf
, "SCAN") == 0) {
4203 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
4206 if (!wpa_s
->scanning
&&
4207 ((wpa_s
->wpa_state
<= WPA_SCANNING
) ||
4208 (wpa_s
->wpa_state
== WPA_COMPLETED
))) {
4209 wpa_s
->normal_scans
= 0;
4210 wpa_s
->scan_req
= 2;
4211 wpa_supplicant_req_scan(wpa_s
, 0, 0);
4212 } else if (wpa_s
->sched_scanning
) {
4213 wpa_printf(MSG_DEBUG
, "Stop ongoing "
4214 "sched_scan to allow requested "
4215 "full scan to proceed");
4216 wpa_supplicant_cancel_sched_scan(wpa_s
);
4217 wpa_s
->scan_req
= 2;
4218 wpa_supplicant_req_scan(wpa_s
, 0, 0);
4220 wpa_printf(MSG_DEBUG
, "Ongoing scan action - "
4221 "reject new request");
4222 reply_len
= os_snprintf(reply
, reply_size
,
4226 } else if (os_strcmp(buf
, "SCAN_RESULTS") == 0) {
4227 reply_len
= wpa_supplicant_ctrl_iface_scan_results(
4228 wpa_s
, reply
, reply_size
);
4229 } else if (os_strncmp(buf
, "SELECT_NETWORK ", 15) == 0) {
4230 if (wpa_supplicant_ctrl_iface_select_network(wpa_s
, buf
+ 15))
4232 } else if (os_strncmp(buf
, "ENABLE_NETWORK ", 15) == 0) {
4233 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s
, buf
+ 15))
4235 } else if (os_strncmp(buf
, "DISABLE_NETWORK ", 16) == 0) {
4236 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s
, buf
+ 16))
4238 } else if (os_strcmp(buf
, "ADD_NETWORK") == 0) {
4239 reply_len
= wpa_supplicant_ctrl_iface_add_network(
4240 wpa_s
, reply
, reply_size
);
4241 } else if (os_strncmp(buf
, "REMOVE_NETWORK ", 15) == 0) {
4242 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s
, buf
+ 15))
4244 } else if (os_strncmp(buf
, "SET_NETWORK ", 12) == 0) {
4245 if (wpa_supplicant_ctrl_iface_set_network(wpa_s
, buf
+ 12))
4247 } else if (os_strncmp(buf
, "GET_NETWORK ", 12) == 0) {
4248 reply_len
= wpa_supplicant_ctrl_iface_get_network(
4249 wpa_s
, buf
+ 12, reply
, reply_size
);
4250 } else if (os_strcmp(buf
, "LIST_CREDS") == 0) {
4251 reply_len
= wpa_supplicant_ctrl_iface_list_creds(
4252 wpa_s
, reply
, reply_size
);
4253 } else if (os_strcmp(buf
, "ADD_CRED") == 0) {
4254 reply_len
= wpa_supplicant_ctrl_iface_add_cred(
4255 wpa_s
, reply
, reply_size
);
4256 } else if (os_strncmp(buf
, "REMOVE_CRED ", 12) == 0) {
4257 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s
, buf
+ 12))
4259 } else if (os_strncmp(buf
, "SET_CRED ", 9) == 0) {
4260 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s
, buf
+ 9))
4262 #ifndef CONFIG_NO_CONFIG_WRITE
4263 } else if (os_strcmp(buf
, "SAVE_CONFIG") == 0) {
4264 if (wpa_supplicant_ctrl_iface_save_config(wpa_s
))
4266 #endif /* CONFIG_NO_CONFIG_WRITE */
4267 } else if (os_strncmp(buf
, "GET_CAPABILITY ", 15) == 0) {
4268 reply_len
= wpa_supplicant_ctrl_iface_get_capability(
4269 wpa_s
, buf
+ 15, reply
, reply_size
);
4270 } else if (os_strncmp(buf
, "AP_SCAN ", 8) == 0) {
4271 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s
, buf
+ 8))
4273 } else if (os_strncmp(buf
, "SCAN_INTERVAL ", 14) == 0) {
4274 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s
, buf
+ 14))
4276 } else if (os_strcmp(buf
, "INTERFACE_LIST") == 0) {
4277 reply_len
= wpa_supplicant_global_iface_list(
4278 wpa_s
->global
, reply
, reply_size
);
4279 } else if (os_strcmp(buf
, "INTERFACES") == 0) {
4280 reply_len
= wpa_supplicant_global_iface_interfaces(
4281 wpa_s
->global
, reply
, reply_size
);
4282 } else if (os_strncmp(buf
, "BSS ", 4) == 0) {
4283 reply_len
= wpa_supplicant_ctrl_iface_bss(
4284 wpa_s
, buf
+ 4, reply
, reply_size
);
4286 } else if (os_strcmp(buf
, "STA-FIRST") == 0) {
4287 reply_len
= ap_ctrl_iface_sta_first(wpa_s
, reply
, reply_size
);
4288 } else if (os_strncmp(buf
, "STA ", 4) == 0) {
4289 reply_len
= ap_ctrl_iface_sta(wpa_s
, buf
+ 4, reply
,
4291 } else if (os_strncmp(buf
, "STA-NEXT ", 9) == 0) {
4292 reply_len
= ap_ctrl_iface_sta_next(wpa_s
, buf
+ 9, reply
,
4294 } else if (os_strncmp(buf
, "DEAUTHENTICATE ", 15) == 0) {
4295 if (ap_ctrl_iface_sta_deauthenticate(wpa_s
, buf
+ 15))
4297 } else if (os_strncmp(buf
, "DISASSOCIATE ", 13) == 0) {
4298 if (ap_ctrl_iface_sta_disassociate(wpa_s
, buf
+ 13))
4300 #endif /* CONFIG_AP */
4301 } else if (os_strcmp(buf
, "SUSPEND") == 0) {
4302 wpas_notify_suspend(wpa_s
->global
);
4303 } else if (os_strcmp(buf
, "RESUME") == 0) {
4304 wpas_notify_resume(wpa_s
->global
);
4305 } else if (os_strcmp(buf
, "DROP_SA") == 0) {
4306 wpa_supplicant_ctrl_iface_drop_sa(wpa_s
);
4307 } else if (os_strncmp(buf
, "ROAM ", 5) == 0) {
4308 if (wpa_supplicant_ctrl_iface_roam(wpa_s
, buf
+ 5))
4310 } else if (os_strncmp(buf
, "STA_AUTOCONNECT ", 16) == 0) {
4311 if (wpa_supplicant_ctrl_iface_sta_autoconnect(wpa_s
, buf
+ 16))
4313 } else if (os_strncmp(buf
, "BSS_EXPIRE_AGE ", 15) == 0) {
4314 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s
, buf
+ 15))
4316 } else if (os_strncmp(buf
, "BSS_EXPIRE_COUNT ", 17) == 0) {
4317 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s
,
4321 } else if (os_strncmp(buf
, "TDLS_DISCOVER ", 14) == 0) {
4322 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s
, buf
+ 14))
4324 } else if (os_strncmp(buf
, "TDLS_SETUP ", 11) == 0) {
4325 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s
, buf
+ 11))
4327 } else if (os_strncmp(buf
, "TDLS_TEARDOWN ", 14) == 0) {
4328 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s
, buf
+ 14))
4330 #endif /* CONFIG_TDLS */
4331 } else if (os_strncmp(buf
, "SIGNAL_POLL", 11) == 0) {
4332 reply_len
= wpa_supplicant_signal_poll(wpa_s
, reply
,
4334 } else if (os_strcmp(buf
, "REAUTHENTICATE") == 0) {
4335 eapol_sm_request_reauth(wpa_s
->eapol
);
4337 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
4341 if (reply_len
< 0) {
4342 os_memcpy(reply
, "FAIL\n", 5);
4347 eapol_sm_notify_ctrl_response(wpa_s
->eapol
);
4349 *resp_len
= reply_len
;
4354 static int wpa_supplicant_global_iface_add(struct wpa_global
*global
,
4357 struct wpa_interface iface
;
4361 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
4362 * TAB<bridge_ifname>
4364 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd
);
4366 os_memset(&iface
, 0, sizeof(iface
));
4369 iface
.ifname
= pos
= cmd
;
4370 pos
= os_strchr(pos
, '\t');
4373 if (iface
.ifname
[0] == '\0')
4378 iface
.confname
= pos
;
4379 pos
= os_strchr(pos
, '\t');
4382 if (iface
.confname
[0] == '\0')
4383 iface
.confname
= NULL
;
4388 pos
= os_strchr(pos
, '\t');
4391 if (iface
.driver
[0] == '\0')
4392 iface
.driver
= NULL
;
4396 iface
.ctrl_interface
= pos
;
4397 pos
= os_strchr(pos
, '\t');
4400 if (iface
.ctrl_interface
[0] == '\0')
4401 iface
.ctrl_interface
= NULL
;
4405 iface
.driver_param
= pos
;
4406 pos
= os_strchr(pos
, '\t');
4409 if (iface
.driver_param
[0] == '\0')
4410 iface
.driver_param
= NULL
;
4414 iface
.bridge_ifname
= pos
;
4415 pos
= os_strchr(pos
, '\t');
4418 if (iface
.bridge_ifname
[0] == '\0')
4419 iface
.bridge_ifname
= NULL
;
4424 if (wpa_supplicant_get_iface(global
, iface
.ifname
))
4427 return wpa_supplicant_add_iface(global
, &iface
) ? 0 : -1;
4431 static int wpa_supplicant_global_iface_remove(struct wpa_global
*global
,
4434 struct wpa_supplicant
*wpa_s
;
4436 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd
);
4438 wpa_s
= wpa_supplicant_get_iface(global
, cmd
);
4441 return wpa_supplicant_remove_iface(global
, wpa_s
, 0);
4445 static void wpa_free_iface_info(struct wpa_interface_info
*iface
)
4447 struct wpa_interface_info
*prev
;
4451 iface
= iface
->next
;
4453 os_free(prev
->ifname
);
4454 os_free(prev
->desc
);
4460 static int wpa_supplicant_global_iface_list(struct wpa_global
*global
,
4464 struct wpa_interface_info
*iface
= NULL
, *last
= NULL
, *tmp
;
4467 for (i
= 0; wpa_drivers
[i
]; i
++) {
4468 struct wpa_driver_ops
*drv
= wpa_drivers
[i
];
4469 if (drv
->get_interfaces
== NULL
)
4471 tmp
= drv
->get_interfaces(global
->drv_priv
[i
]);
4485 for (tmp
= iface
; tmp
; tmp
= tmp
->next
) {
4486 res
= os_snprintf(pos
, end
- pos
, "%s\t%s\t%s\n",
4487 tmp
->drv_name
, tmp
->ifname
,
4488 tmp
->desc
? tmp
->desc
: "");
4489 if (res
< 0 || res
>= end
- pos
) {
4496 wpa_free_iface_info(iface
);
4502 static int wpa_supplicant_global_iface_interfaces(struct wpa_global
*global
,
4507 struct wpa_supplicant
*wpa_s
;
4509 wpa_s
= global
->ifaces
;
4514 res
= os_snprintf(pos
, end
- pos
, "%s\n", wpa_s
->ifname
);
4515 if (res
< 0 || res
>= end
- pos
) {
4520 wpa_s
= wpa_s
->next
;
4526 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global
*global
,
4527 char *buf
, size_t *resp_len
)
4530 const int reply_size
= 2048;
4532 int level
= MSG_DEBUG
;
4534 if (os_strcmp(buf
, "PING") == 0)
4535 level
= MSG_EXCESSIVE
;
4536 wpa_hexdump_ascii(level
, "RX global ctrl_iface",
4537 (const u8
*) buf
, os_strlen(buf
));
4539 reply
= os_malloc(reply_size
);
4540 if (reply
== NULL
) {
4545 os_memcpy(reply
, "OK\n", 3);
4548 if (os_strcmp(buf
, "PING") == 0) {
4549 os_memcpy(reply
, "PONG\n", 5);
4551 } else if (os_strncmp(buf
, "INTERFACE_ADD ", 14) == 0) {
4552 if (wpa_supplicant_global_iface_add(global
, buf
+ 14))
4554 } else if (os_strncmp(buf
, "INTERFACE_REMOVE ", 17) == 0) {
4555 if (wpa_supplicant_global_iface_remove(global
, buf
+ 17))
4557 } else if (os_strcmp(buf
, "INTERFACE_LIST") == 0) {
4558 reply_len
= wpa_supplicant_global_iface_list(
4559 global
, reply
, reply_size
);
4560 } else if (os_strcmp(buf
, "INTERFACES") == 0) {
4561 reply_len
= wpa_supplicant_global_iface_interfaces(
4562 global
, reply
, reply_size
);
4563 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
4564 wpa_supplicant_terminate_proc(global
);
4565 } else if (os_strcmp(buf
, "SUSPEND") == 0) {
4566 wpas_notify_suspend(global
);
4567 } else if (os_strcmp(buf
, "RESUME") == 0) {
4568 wpas_notify_resume(global
);
4570 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
4574 if (reply_len
< 0) {
4575 os_memcpy(reply
, "FAIL\n", 5);
4579 *resp_len
= reply_len
;