2 * WPA Supplicant / Control interface (shared code for all backends)
3 * Copyright (c) 2004-2014, 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 "utils/uuid.h"
14 #include "common/version.h"
15 #include "common/ieee802_11_defs.h"
16 #include "common/ieee802_11_common.h"
17 #include "common/wpa_ctrl.h"
18 #include "eap_peer/eap.h"
19 #include "eapol_supp/eapol_supp_sm.h"
20 #include "rsn_supp/wpa.h"
21 #include "rsn_supp/preauth.h"
22 #include "rsn_supp/pmksa_cache.h"
23 #include "l2_packet/l2_packet.h"
26 #include "wpa_supplicant_i.h"
28 #include "wps_supplicant.h"
31 #include "p2p_supplicant.h"
33 #include "hs20_supplicant.h"
34 #include "wifi_display.h"
38 #include "ctrl_iface.h"
39 #include "interworking.h"
40 #include "blacklist.h"
44 static int wpa_supplicant_global_iface_list(struct wpa_global
*global
,
46 static int wpa_supplicant_global_iface_interfaces(struct wpa_global
*global
,
50 static int pno_start(struct wpa_supplicant
*wpa_s
)
54 struct wpa_ssid
*ssid
;
55 struct wpa_driver_scan_params params
;
57 if (wpa_s
->pno
|| wpa_s
->pno_sched_pending
)
60 if ((wpa_s
->wpa_state
> WPA_SCANNING
) &&
61 (wpa_s
->wpa_state
<= WPA_COMPLETED
)) {
62 wpa_printf(MSG_ERROR
, "PNO: In assoc process");
66 if (wpa_s
->wpa_state
== WPA_SCANNING
) {
67 wpa_supplicant_cancel_scan(wpa_s
);
68 if (wpa_s
->sched_scanning
) {
69 wpa_printf(MSG_DEBUG
, "Schedule PNO on completion of "
70 "ongoing sched scan");
71 wpa_supplicant_cancel_sched_scan(wpa_s
);
72 wpa_s
->pno_sched_pending
= 1;
77 os_memset(¶ms
, 0, sizeof(params
));
80 ssid
= wpa_s
->conf
->ssid
;
82 if (!wpas_network_disabled(wpa_s
, ssid
))
86 if (num_ssid
> WPAS_MAX_SCAN_SSIDS
) {
87 wpa_printf(MSG_DEBUG
, "PNO: Use only the first %u SSIDs from "
88 "%u", WPAS_MAX_SCAN_SSIDS
, (unsigned int) num_ssid
);
89 num_ssid
= WPAS_MAX_SCAN_SSIDS
;
93 wpa_printf(MSG_DEBUG
, "PNO: No configured SSIDs");
97 params
.filter_ssids
= os_malloc(sizeof(struct wpa_driver_scan_filter
) *
99 if (params
.filter_ssids
== NULL
)
102 ssid
= wpa_s
->conf
->ssid
;
104 if (!wpas_network_disabled(wpa_s
, ssid
)) {
105 params
.ssids
[i
].ssid
= ssid
->ssid
;
106 params
.ssids
[i
].ssid_len
= ssid
->ssid_len
;
108 os_memcpy(params
.filter_ssids
[i
].ssid
, ssid
->ssid
,
110 params
.filter_ssids
[i
].ssid_len
= ssid
->ssid_len
;
111 params
.num_filter_ssids
++;
119 if (wpa_s
->conf
->filter_rssi
)
120 params
.filter_rssi
= wpa_s
->conf
->filter_rssi
;
122 interval
= wpa_s
->conf
->sched_scan_interval
?
123 wpa_s
->conf
->sched_scan_interval
: 10;
125 ret
= wpa_supplicant_start_sched_scan(wpa_s
, ¶ms
, interval
);
126 os_free(params
.filter_ssids
);
133 static int pno_stop(struct wpa_supplicant
*wpa_s
)
137 if (wpa_s
->pno
|| wpa_s
->sched_scanning
) {
139 ret
= wpa_supplicant_stop_sched_scan(wpa_s
);
142 wpa_s
->pno_sched_pending
= 0;
144 if (wpa_s
->wpa_state
== WPA_SCANNING
)
145 wpa_supplicant_req_scan(wpa_s
, 0, 0);
151 static int set_bssid_filter(struct wpa_supplicant
*wpa_s
, char *val
)
154 u8 addr
[ETH_ALEN
], *filter
= NULL
, *n
;
161 if (hwaddr_aton(pos
, addr
)) {
165 n
= os_realloc_array(filter
, count
+ 1, ETH_ALEN
);
171 os_memcpy(filter
+ count
* ETH_ALEN
, addr
, ETH_ALEN
);
174 pos
= os_strchr(pos
, ' ');
179 wpa_hexdump(MSG_DEBUG
, "bssid_filter", filter
, count
* ETH_ALEN
);
180 os_free(wpa_s
->bssid_filter
);
181 wpa_s
->bssid_filter
= filter
;
182 wpa_s
->bssid_filter_count
= count
;
188 static int set_disallow_aps(struct wpa_supplicant
*wpa_s
, char *val
)
191 u8 addr
[ETH_ALEN
], *bssid
= NULL
, *n
;
192 struct wpa_ssid_value
*ssid
= NULL
, *ns
;
193 size_t count
= 0, ssid_count
= 0;
197 * disallow_list ::= <ssid_spec> | <bssid_spec> | <disallow_list> | ""
198 * SSID_SPEC ::= ssid <SSID_HEX>
199 * BSSID_SPEC ::= bssid <BSSID_HEX>
206 if (os_strncmp(pos
, "bssid ", 6) == 0) {
209 res
= hwaddr_aton2(pos
, addr
);
213 wpa_printf(MSG_DEBUG
, "Invalid disallow_aps "
214 "BSSID value '%s'", pos
);
218 n
= os_realloc_array(bssid
, count
+ 1, ETH_ALEN
);
225 os_memcpy(bssid
+ count
* ETH_ALEN
, addr
, ETH_ALEN
);
227 } else if (os_strncmp(pos
, "ssid ", 5) == 0) {
233 if (*end
== '\0' || *end
== ' ')
238 ns
= os_realloc_array(ssid
, ssid_count
+ 1,
239 sizeof(struct wpa_ssid_value
));
247 if ((end
- pos
) & 0x01 || end
- pos
> 2 * 32 ||
248 hexstr2bin(pos
, ssid
[ssid_count
].ssid
,
249 (end
- pos
) / 2) < 0) {
252 wpa_printf(MSG_DEBUG
, "Invalid disallow_aps "
253 "SSID value '%s'", pos
);
256 ssid
[ssid_count
].ssid_len
= (end
- pos
) / 2;
257 wpa_hexdump_ascii(MSG_DEBUG
, "disallow_aps SSID",
258 ssid
[ssid_count
].ssid
,
259 ssid
[ssid_count
].ssid_len
);
263 wpa_printf(MSG_DEBUG
, "Unexpected disallow_aps value "
270 pos
= os_strchr(pos
, ' ');
275 wpa_hexdump(MSG_DEBUG
, "disallow_aps_bssid", bssid
, count
* ETH_ALEN
);
276 os_free(wpa_s
->disallow_aps_bssid
);
277 wpa_s
->disallow_aps_bssid
= bssid
;
278 wpa_s
->disallow_aps_bssid_count
= count
;
280 wpa_printf(MSG_DEBUG
, "disallow_aps_ssid_count %d", (int) ssid_count
);
281 os_free(wpa_s
->disallow_aps_ssid
);
282 wpa_s
->disallow_aps_ssid
= ssid
;
283 wpa_s
->disallow_aps_ssid_count
= ssid_count
;
285 if (!wpa_s
->current_ssid
|| wpa_s
->wpa_state
< WPA_AUTHENTICATING
)
288 c
= wpa_s
->current_ssid
;
289 if (c
->mode
!= WPAS_MODE_INFRA
&& c
->mode
!= WPAS_MODE_IBSS
)
292 if (!disallowed_bssid(wpa_s
, wpa_s
->bssid
) &&
293 !disallowed_ssid(wpa_s
, c
->ssid
, c
->ssid_len
))
296 wpa_printf(MSG_DEBUG
, "Disconnect and try to find another network "
297 "because current AP was marked disallowed");
300 wpa_s
->sme
.prev_bssid_set
= 0;
301 #endif /* CONFIG_SME */
302 wpa_s
->reassociate
= 1;
303 wpa_supplicant_deauthenticate(wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
304 wpa_supplicant_req_scan(wpa_s
, 0, 0);
310 static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant
*wpa_s
,
316 value
= os_strchr(cmd
, ' ');
321 wpa_printf(MSG_DEBUG
, "CTRL_IFACE SET '%s'='%s'", cmd
, value
);
322 if (os_strcasecmp(cmd
, "EAPOL::heldPeriod") == 0) {
323 eapol_sm_configure(wpa_s
->eapol
,
324 atoi(value
), -1, -1, -1);
325 } else if (os_strcasecmp(cmd
, "EAPOL::authPeriod") == 0) {
326 eapol_sm_configure(wpa_s
->eapol
,
327 -1, atoi(value
), -1, -1);
328 } else if (os_strcasecmp(cmd
, "EAPOL::startPeriod") == 0) {
329 eapol_sm_configure(wpa_s
->eapol
,
330 -1, -1, atoi(value
), -1);
331 } else if (os_strcasecmp(cmd
, "EAPOL::maxStart") == 0) {
332 eapol_sm_configure(wpa_s
->eapol
,
333 -1, -1, -1, atoi(value
));
334 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigPMKLifetime") == 0) {
335 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_LIFETIME
,
338 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigPMKReauthThreshold") ==
340 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_REAUTH_THRESHOLD
,
343 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigSATimeout") == 0) {
344 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_SA_TIMEOUT
, atoi(value
)))
346 } else if (os_strcasecmp(cmd
, "wps_fragment_size") == 0) {
347 wpa_s
->wps_fragment_size
= atoi(value
);
348 #ifdef CONFIG_WPS_TESTING
349 } else if (os_strcasecmp(cmd
, "wps_version_number") == 0) {
351 val
= strtol(value
, NULL
, 0);
352 if (val
< 0 || val
> 0xff) {
354 wpa_printf(MSG_DEBUG
, "WPS: Invalid "
355 "wps_version_number %ld", val
);
357 wps_version_number
= val
;
358 wpa_printf(MSG_DEBUG
, "WPS: Testing - force WPS "
360 (wps_version_number
& 0xf0) >> 4,
361 wps_version_number
& 0x0f);
363 } else if (os_strcasecmp(cmd
, "wps_testing_dummy_cred") == 0) {
364 wps_testing_dummy_cred
= atoi(value
);
365 wpa_printf(MSG_DEBUG
, "WPS: Testing - dummy_cred=%d",
366 wps_testing_dummy_cred
);
367 } else if (os_strcasecmp(cmd
, "wps_corrupt_pkhash") == 0) {
368 wps_corrupt_pkhash
= atoi(value
);
369 wpa_printf(MSG_DEBUG
, "WPS: Testing - wps_corrupt_pkhash=%d",
371 #endif /* CONFIG_WPS_TESTING */
372 } else if (os_strcasecmp(cmd
, "ampdu") == 0) {
373 if (wpa_drv_ampdu(wpa_s
, atoi(value
)) < 0)
376 #ifdef CONFIG_TDLS_TESTING
377 } else if (os_strcasecmp(cmd
, "tdls_testing") == 0) {
378 extern unsigned int tdls_testing
;
379 tdls_testing
= strtol(value
, NULL
, 0);
380 wpa_printf(MSG_DEBUG
, "TDLS: tdls_testing=0x%x", tdls_testing
);
381 #endif /* CONFIG_TDLS_TESTING */
382 } else if (os_strcasecmp(cmd
, "tdls_disabled") == 0) {
383 int disabled
= atoi(value
);
384 wpa_printf(MSG_DEBUG
, "TDLS: tdls_disabled=%d", disabled
);
386 if (wpa_drv_tdls_oper(wpa_s
, TDLS_DISABLE
, NULL
) < 0)
388 } else if (wpa_drv_tdls_oper(wpa_s
, TDLS_ENABLE
, NULL
) < 0)
390 wpa_tdls_enable(wpa_s
->wpa
, !disabled
);
391 #endif /* CONFIG_TDLS */
392 } else if (os_strcasecmp(cmd
, "pno") == 0) {
394 ret
= pno_start(wpa_s
);
396 ret
= pno_stop(wpa_s
);
397 } else if (os_strcasecmp(cmd
, "radio_disabled") == 0) {
398 int disabled
= atoi(value
);
399 if (wpa_drv_radio_disable(wpa_s
, disabled
) < 0)
402 wpa_supplicant_set_state(wpa_s
, WPA_INACTIVE
);
403 } else if (os_strcasecmp(cmd
, "uapsd") == 0) {
404 if (os_strcmp(value
, "disable") == 0)
405 wpa_s
->set_sta_uapsd
= 0;
409 /* format: BE,BK,VI,VO;max SP Length */
411 pos
= os_strchr(value
, ',');
416 pos
= os_strchr(pos
, ',');
421 pos
= os_strchr(pos
, ',');
426 /* ignore max SP Length for now */
428 wpa_s
->set_sta_uapsd
= 1;
429 wpa_s
->sta_uapsd
= 0;
431 wpa_s
->sta_uapsd
|= BIT(0);
433 wpa_s
->sta_uapsd
|= BIT(1);
435 wpa_s
->sta_uapsd
|= BIT(2);
437 wpa_s
->sta_uapsd
|= BIT(3);
439 } else if (os_strcasecmp(cmd
, "ps") == 0) {
440 ret
= wpa_drv_set_p2p_powersave(wpa_s
, atoi(value
), -1, -1);
441 #ifdef CONFIG_WIFI_DISPLAY
442 } else if (os_strcasecmp(cmd
, "wifi_display") == 0) {
443 int enabled
= !!atoi(value
);
444 if (enabled
&& !wpa_s
->global
->p2p
)
447 wifi_display_enable(wpa_s
->global
, enabled
);
448 #endif /* CONFIG_WIFI_DISPLAY */
449 } else if (os_strcasecmp(cmd
, "bssid_filter") == 0) {
450 ret
= set_bssid_filter(wpa_s
, value
);
451 } else if (os_strcasecmp(cmd
, "disallow_aps") == 0) {
452 ret
= set_disallow_aps(wpa_s
, value
);
453 } else if (os_strcasecmp(cmd
, "no_keep_alive") == 0) {
454 wpa_s
->no_keep_alive
= !!atoi(value
);
457 ret
= wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
459 wpa_supplicant_update_config(wpa_s
);
466 static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant
*wpa_s
,
467 char *cmd
, char *buf
, size_t buflen
)
471 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GET '%s'", cmd
);
473 if (os_strcmp(cmd
, "version") == 0) {
474 res
= os_snprintf(buf
, buflen
, "%s", VERSION_STR
);
475 } else if (os_strcasecmp(cmd
, "country") == 0) {
476 if (wpa_s
->conf
->country
[0] && wpa_s
->conf
->country
[1])
477 res
= os_snprintf(buf
, buflen
, "%c%c",
478 wpa_s
->conf
->country
[0],
479 wpa_s
->conf
->country
[1]);
480 #ifdef CONFIG_WIFI_DISPLAY
481 } else if (os_strcasecmp(cmd
, "wifi_display") == 0) {
483 if (wpa_s
->global
->p2p
== NULL
||
484 wpa_s
->global
->p2p_disabled
)
487 enabled
= wpa_s
->global
->wifi_display
;
488 res
= os_snprintf(buf
, buflen
, "%d", enabled
);
489 if (res
< 0 || (unsigned int) res
>= buflen
)
492 #endif /* CONFIG_WIFI_DISPLAY */
493 #ifdef CONFIG_TESTING_GET_GTK
494 } else if (os_strcmp(cmd
, "gtk") == 0) {
495 if (wpa_s
->last_gtk_len
== 0)
497 res
= wpa_snprintf_hex(buf
, buflen
, wpa_s
->last_gtk
,
498 wpa_s
->last_gtk_len
);
500 #endif /* CONFIG_TESTING_GET_GTK */
503 if (res
< 0 || (unsigned int) res
>= buflen
)
509 #ifdef IEEE8021X_EAPOL
510 static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant
*wpa_s
,
514 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
516 if (hwaddr_aton(addr
, bssid
)) {
517 wpa_printf(MSG_DEBUG
, "CTRL_IFACE PREAUTH: invalid address "
522 wpa_printf(MSG_DEBUG
, "CTRL_IFACE PREAUTH " MACSTR
, MAC2STR(bssid
));
523 rsn_preauth_deinit(wpa_s
->wpa
);
524 if (rsn_preauth_init(wpa_s
->wpa
, bssid
, ssid
? &ssid
->eap
: NULL
))
529 #endif /* IEEE8021X_EAPOL */
532 #ifdef CONFIG_PEERKEY
533 /* MLME-STKSTART.request(peer) */
534 static int wpa_supplicant_ctrl_iface_stkstart(
535 struct wpa_supplicant
*wpa_s
, char *addr
)
539 if (hwaddr_aton(addr
, peer
)) {
540 wpa_printf(MSG_DEBUG
, "CTRL_IFACE STKSTART: invalid "
541 "address '%s'", addr
);
545 wpa_printf(MSG_DEBUG
, "CTRL_IFACE STKSTART " MACSTR
,
548 return wpa_sm_stkstart(wpa_s
->wpa
, peer
);
550 #endif /* CONFIG_PEERKEY */
555 static int wpa_supplicant_ctrl_iface_tdls_discover(
556 struct wpa_supplicant
*wpa_s
, char *addr
)
561 if (hwaddr_aton(addr
, peer
)) {
562 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_DISCOVER: invalid "
563 "address '%s'", addr
);
567 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_DISCOVER " MACSTR
,
570 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
571 ret
= wpa_tdls_send_discovery_request(wpa_s
->wpa
, peer
);
573 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_DISCOVERY_REQ
, peer
);
579 static int wpa_supplicant_ctrl_iface_tdls_setup(
580 struct wpa_supplicant
*wpa_s
, char *addr
)
585 if (hwaddr_aton(addr
, peer
)) {
586 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_SETUP: invalid "
587 "address '%s'", addr
);
591 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_SETUP " MACSTR
,
594 if ((wpa_s
->conf
->tdls_external_control
) &&
595 wpa_tdls_is_external_setup(wpa_s
->wpa
))
596 return wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, peer
);
598 wpa_tdls_remove(wpa_s
->wpa
, peer
);
600 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
601 ret
= wpa_tdls_start(wpa_s
->wpa
, peer
);
603 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, peer
);
609 static int wpa_supplicant_ctrl_iface_tdls_teardown(
610 struct wpa_supplicant
*wpa_s
, char *addr
)
615 if (hwaddr_aton(addr
, peer
)) {
616 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN: invalid "
617 "address '%s'", addr
);
621 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN " MACSTR
,
624 if ((wpa_s
->conf
->tdls_external_control
) &&
625 wpa_tdls_is_external_setup(wpa_s
->wpa
))
626 return wpa_drv_tdls_oper(wpa_s
, TDLS_TEARDOWN
, peer
);
628 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
629 ret
= wpa_tdls_teardown_link(
631 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED
);
633 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_TEARDOWN
, peer
);
638 #endif /* CONFIG_TDLS */
641 #ifdef CONFIG_IEEE80211R
642 static int wpa_supplicant_ctrl_iface_ft_ds(
643 struct wpa_supplicant
*wpa_s
, char *addr
)
645 u8 target_ap
[ETH_ALEN
];
649 if (hwaddr_aton(addr
, target_ap
)) {
650 wpa_printf(MSG_DEBUG
, "CTRL_IFACE FT_DS: invalid "
651 "address '%s'", addr
);
655 wpa_printf(MSG_DEBUG
, "CTRL_IFACE FT_DS " MACSTR
, MAC2STR(target_ap
));
657 bss
= wpa_bss_get_bssid(wpa_s
, target_ap
);
659 mdie
= wpa_bss_get_ie(bss
, WLAN_EID_MOBILITY_DOMAIN
);
663 return wpa_ft_start_over_ds(wpa_s
->wpa
, target_ap
, mdie
);
665 #endif /* CONFIG_IEEE80211R */
669 static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant
*wpa_s
,
672 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
674 u8 p2p_dev_addr
[ETH_ALEN
];
675 #endif /* CONFIG_P2P */
677 u8
*_p2p_dev_addr
= NULL
;
678 #endif /* CONFIG_AP */
680 if (cmd
== NULL
|| os_strcmp(cmd
, "any") == 0) {
683 } else if (os_strncmp(cmd
, "p2p_dev_addr=", 13) == 0) {
684 if (hwaddr_aton(cmd
+ 13, p2p_dev_addr
)) {
685 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PBC: invalid "
686 "P2P Device Address '%s'",
690 _p2p_dev_addr
= p2p_dev_addr
;
691 #endif /* CONFIG_P2P */
692 } else if (hwaddr_aton(cmd
, bssid
)) {
693 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
700 return wpa_supplicant_ap_wps_pbc(wpa_s
, _bssid
, _p2p_dev_addr
);
701 #endif /* CONFIG_AP */
703 return wpas_wps_start_pbc(wpa_s
, _bssid
, 0);
707 static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant
*wpa_s
,
708 char *cmd
, char *buf
,
711 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
715 pin
= os_strchr(cmd
, ' ');
719 if (os_strcmp(cmd
, "any") == 0)
721 else if (os_strcmp(cmd
, "get") == 0) {
722 ret
= wps_generate_pin();
724 } else if (hwaddr_aton(cmd
, bssid
)) {
725 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
731 if (wpa_s
->ap_iface
) {
736 pos
= os_strchr(pin
, ' ');
743 return wpa_supplicant_ap_wps_pin(wpa_s
, _bssid
, pin
,
744 buf
, buflen
, timeout
);
746 #endif /* CONFIG_AP */
749 ret
= wpas_wps_start_pin(wpa_s
, _bssid
, pin
, 0,
753 ret
= os_snprintf(buf
, buflen
, "%s", pin
);
754 if (ret
< 0 || (size_t) ret
>= buflen
)
759 ret
= wpas_wps_start_pin(wpa_s
, _bssid
, NULL
, 0, DEV_PW_DEFAULT
);
764 /* Return the generated PIN */
765 ret
= os_snprintf(buf
, buflen
, "%08d", ret
);
766 if (ret
< 0 || (size_t) ret
>= buflen
)
772 static int wpa_supplicant_ctrl_iface_wps_check_pin(
773 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
780 wpa_hexdump_ascii_key(MSG_DEBUG
, "WPS_CHECK_PIN",
781 (u8
*) cmd
, os_strlen(cmd
));
782 for (pos
= cmd
, len
= 0; *pos
!= '\0'; pos
++) {
783 if (*pos
< '0' || *pos
> '9')
787 wpa_printf(MSG_DEBUG
, "WPS: Too long PIN");
791 if (len
!= 4 && len
!= 8) {
792 wpa_printf(MSG_DEBUG
, "WPS: Invalid PIN length %d", (int) len
);
798 unsigned int pin_val
;
800 if (!wps_pin_valid(pin_val
)) {
801 wpa_printf(MSG_DEBUG
, "WPS: Invalid checksum digit");
802 ret
= os_snprintf(buf
, buflen
, "FAIL-CHECKSUM\n");
803 if (ret
< 0 || (size_t) ret
>= buflen
)
809 ret
= os_snprintf(buf
, buflen
, "%s", pin
);
810 if (ret
< 0 || (size_t) ret
>= buflen
)
817 #ifdef CONFIG_WPS_NFC
819 static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant
*wpa_s
,
822 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
824 if (cmd
== NULL
|| cmd
[0] == '\0')
826 else if (hwaddr_aton(cmd
, bssid
))
829 return wpas_wps_start_nfc(wpa_s
, NULL
, _bssid
, NULL
, 0, 0, NULL
, NULL
,
834 static int wpa_supplicant_ctrl_iface_wps_nfc_config_token(
835 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
842 pos
= os_strchr(cmd
, ' ');
845 if (os_strcmp(cmd
, "WPS") == 0)
847 else if (os_strcmp(cmd
, "NDEF") == 0)
852 buf
= wpas_wps_nfc_config_token(wpa_s
, ndef
, pos
);
856 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
867 static int wpa_supplicant_ctrl_iface_wps_nfc_token(
868 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
874 if (os_strcmp(cmd
, "WPS") == 0)
876 else if (os_strcmp(cmd
, "NDEF") == 0)
881 buf
= wpas_wps_nfc_token(wpa_s
, ndef
);
885 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
896 static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
897 struct wpa_supplicant
*wpa_s
, char *pos
)
905 freq
= strstr(pos
, " freq=");
909 forced_freq
= atoi(freq
);
912 len
= os_strlen(pos
);
917 buf
= wpabuf_alloc(len
);
920 if (hexstr2bin(pos
, wpabuf_put(buf
, len
), len
) < 0) {
925 ret
= wpas_wps_nfc_tag_read(wpa_s
, buf
, forced_freq
);
932 static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant
*wpa_s
,
933 char *reply
, size_t max_len
,
939 buf
= wpas_wps_nfc_handover_req(wpa_s
, ndef
);
943 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
954 static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant
*wpa_s
,
955 char *reply
, size_t max_len
,
961 buf
= wpas_p2p_nfc_handover_req(wpa_s
, ndef
);
963 wpa_printf(MSG_DEBUG
, "P2P: Could not generate NFC handover request");
967 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
978 static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant
*wpa_s
,
979 char *cmd
, char *reply
,
985 pos
= os_strchr(cmd
, ' ');
990 if (os_strcmp(cmd
, "WPS") == 0)
992 else if (os_strcmp(cmd
, "NDEF") == 0)
997 if (os_strcmp(pos
, "WPS") == 0 || os_strcmp(pos
, "WPS-CR") == 0) {
1000 return wpas_ctrl_nfc_get_handover_req_wps(
1001 wpa_s
, reply
, max_len
, ndef
);
1004 if (os_strcmp(pos
, "P2P-CR") == 0) {
1005 return wpas_ctrl_nfc_get_handover_req_p2p(
1006 wpa_s
, reply
, max_len
, ndef
);
1013 static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant
*wpa_s
,
1014 char *reply
, size_t max_len
,
1015 int ndef
, int cr
, char *uuid
)
1020 buf
= wpas_wps_nfc_handover_sel(wpa_s
, ndef
, cr
, uuid
);
1024 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1026 reply
[res
++] = '\n';
1035 static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant
*wpa_s
,
1036 char *reply
, size_t max_len
,
1042 buf
= wpas_p2p_nfc_handover_sel(wpa_s
, ndef
, tag
);
1046 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1048 reply
[res
++] = '\n';
1057 static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant
*wpa_s
,
1058 char *cmd
, char *reply
,
1064 pos
= os_strchr(cmd
, ' ');
1069 if (os_strcmp(cmd
, "WPS") == 0)
1071 else if (os_strcmp(cmd
, "NDEF") == 0)
1076 pos2
= os_strchr(pos
, ' ');
1079 if (os_strcmp(pos
, "WPS") == 0 || os_strcmp(pos
, "WPS-CR") == 0) {
1082 return wpas_ctrl_nfc_get_handover_sel_wps(
1083 wpa_s
, reply
, max_len
, ndef
,
1084 os_strcmp(pos
, "WPS-CR") == 0, pos2
);
1087 if (os_strcmp(pos
, "P2P-CR") == 0) {
1088 return wpas_ctrl_nfc_get_handover_sel_p2p(
1089 wpa_s
, reply
, max_len
, ndef
, 0);
1092 if (os_strcmp(pos
, "P2P-CR-TAG") == 0) {
1093 return wpas_ctrl_nfc_get_handover_sel_p2p(
1094 wpa_s
, reply
, max_len
, ndef
, 1);
1101 static int wpas_ctrl_nfc_rx_handover_req(struct wpa_supplicant
*wpa_s
,
1102 char *cmd
, char *reply
,
1109 len
= os_strlen(cmd
);
1114 buf
= wpabuf_alloc(len
);
1117 if (hexstr2bin(cmd
, wpabuf_put(buf
, len
), len
) < 0) {
1122 ret
= wpas_wps_nfc_rx_handover_req(wpa_s
, buf
);
1129 static int wpas_ctrl_nfc_rx_handover_sel(struct wpa_supplicant
*wpa_s
,
1136 len
= os_strlen(cmd
);
1141 buf
= wpabuf_alloc(len
);
1144 if (hexstr2bin(cmd
, wpabuf_put(buf
, len
), len
) < 0) {
1149 ret
= wpas_wps_nfc_rx_handover_sel(wpa_s
, buf
);
1156 static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant
*wpa_s
,
1160 struct wpabuf
*req
, *sel
;
1162 char *pos
, *role
, *type
, *pos2
;
1164 int forced_freq
= 0;
1166 freq
= strstr(cmd
, " freq=");
1170 forced_freq
= atoi(freq
);
1174 pos
= os_strchr(role
, ' ');
1176 wpa_printf(MSG_DEBUG
, "NFC: Missing type in handover report");
1182 pos
= os_strchr(type
, ' ');
1184 wpa_printf(MSG_DEBUG
, "NFC: Missing request message in handover report");
1189 pos2
= os_strchr(pos
, ' ');
1191 wpa_printf(MSG_DEBUG
, "NFC: Missing select message in handover report");
1196 len
= os_strlen(pos
);
1198 wpa_printf(MSG_DEBUG
, "NFC: Invalid request message length in handover report");
1203 req
= wpabuf_alloc(len
);
1205 wpa_printf(MSG_DEBUG
, "NFC: Failed to allocate memory for request message");
1208 if (hexstr2bin(pos
, wpabuf_put(req
, len
), len
) < 0) {
1209 wpa_printf(MSG_DEBUG
, "NFC: Invalid request message hexdump in handover report");
1214 len
= os_strlen(pos2
);
1216 wpa_printf(MSG_DEBUG
, "NFC: Invalid select message length in handover report");
1222 sel
= wpabuf_alloc(len
);
1224 wpa_printf(MSG_DEBUG
, "NFC: Failed to allocate memory for select message");
1228 if (hexstr2bin(pos2
, wpabuf_put(sel
, len
), len
) < 0) {
1229 wpa_printf(MSG_DEBUG
, "NFC: Invalid select message hexdump in handover report");
1235 wpa_printf(MSG_DEBUG
, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d",
1236 role
, type
, (int) wpabuf_len(req
), (int) wpabuf_len(sel
));
1238 if (os_strcmp(role
, "INIT") == 0 && os_strcmp(type
, "WPS") == 0) {
1239 ret
= wpas_wps_nfc_report_handover(wpa_s
, req
, sel
);
1240 } else if (os_strcmp(role
, "RESP") == 0 && os_strcmp(type
, "WPS") == 0)
1242 ret
= wpas_ap_wps_nfc_report_handover(wpa_s
, req
, sel
);
1244 ret
= wpas_er_wps_nfc_report_handover(wpa_s
, req
, sel
);
1245 } else if (os_strcmp(role
, "INIT") == 0 && os_strcmp(type
, "P2P") == 0)
1247 ret
= wpas_p2p_nfc_report_handover(wpa_s
, 1, req
, sel
, 0);
1248 } else if (os_strcmp(role
, "RESP") == 0 && os_strcmp(type
, "P2P") == 0)
1250 ret
= wpas_p2p_nfc_report_handover(wpa_s
, 0, req
, sel
,
1253 wpa_printf(MSG_DEBUG
, "NFC: Unsupported connection handover "
1254 "reported: role=%s type=%s", role
, type
);
1261 wpa_printf(MSG_DEBUG
, "NFC: Failed to process reported handover messages");
1266 #endif /* CONFIG_WPS_NFC */
1269 static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant
*wpa_s
,
1278 struct wps_new_ap_settings ap
;
1280 pin
= os_strchr(cmd
, ' ');
1285 if (hwaddr_aton(cmd
, bssid
)) {
1286 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
1291 new_ssid
= os_strchr(pin
, ' ');
1292 if (new_ssid
== NULL
)
1293 return wpas_wps_start_reg(wpa_s
, bssid
, pin
, NULL
);
1296 new_auth
= os_strchr(new_ssid
, ' ');
1297 if (new_auth
== NULL
)
1301 new_encr
= os_strchr(new_auth
, ' ');
1302 if (new_encr
== NULL
)
1306 new_key
= os_strchr(new_encr
, ' ');
1307 if (new_key
== NULL
)
1311 os_memset(&ap
, 0, sizeof(ap
));
1312 ap
.ssid_hex
= new_ssid
;
1315 ap
.key_hex
= new_key
;
1316 return wpas_wps_start_reg(wpa_s
, bssid
, pin
, &ap
);
1321 static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant
*wpa_s
,
1322 char *cmd
, char *buf
,
1327 const char *pin_txt
;
1329 if (!wpa_s
->ap_iface
)
1332 pos
= os_strchr(cmd
, ' ');
1336 if (os_strcmp(cmd
, "disable") == 0) {
1337 wpas_wps_ap_pin_disable(wpa_s
);
1338 return os_snprintf(buf
, buflen
, "OK\n");
1341 if (os_strcmp(cmd
, "random") == 0) {
1343 timeout
= atoi(pos
);
1344 pin_txt
= wpas_wps_ap_pin_random(wpa_s
, timeout
);
1345 if (pin_txt
== NULL
)
1347 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
1350 if (os_strcmp(cmd
, "get") == 0) {
1351 pin_txt
= wpas_wps_ap_pin_get(wpa_s
);
1352 if (pin_txt
== NULL
)
1354 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
1357 if (os_strcmp(cmd
, "set") == 0) {
1362 pos
= os_strchr(pos
, ' ');
1365 timeout
= atoi(pos
);
1367 if (os_strlen(pin
) > buflen
)
1369 if (wpas_wps_ap_pin_set(wpa_s
, pin
, timeout
) < 0)
1371 return os_snprintf(buf
, buflen
, "%s", pin
);
1376 #endif /* CONFIG_AP */
1379 #ifdef CONFIG_WPS_ER
1380 static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant
*wpa_s
,
1383 char *uuid
= cmd
, *pin
, *pos
;
1384 u8 addr_buf
[ETH_ALEN
], *addr
= NULL
;
1385 pin
= os_strchr(uuid
, ' ');
1389 pos
= os_strchr(pin
, ' ');
1392 if (hwaddr_aton(pos
, addr_buf
) == 0)
1395 return wpas_wps_er_add_pin(wpa_s
, addr
, uuid
, pin
);
1399 static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant
*wpa_s
,
1402 char *uuid
= cmd
, *pin
;
1403 pin
= os_strchr(uuid
, ' ');
1407 return wpas_wps_er_learn(wpa_s
, uuid
, pin
);
1411 static int wpa_supplicant_ctrl_iface_wps_er_set_config(
1412 struct wpa_supplicant
*wpa_s
, char *cmd
)
1414 char *uuid
= cmd
, *id
;
1415 id
= os_strchr(uuid
, ' ');
1419 return wpas_wps_er_set_config(wpa_s
, uuid
, atoi(id
));
1423 static int wpa_supplicant_ctrl_iface_wps_er_config(
1424 struct wpa_supplicant
*wpa_s
, char *cmd
)
1431 struct wps_new_ap_settings ap
;
1433 pin
= os_strchr(cmd
, ' ');
1438 new_ssid
= os_strchr(pin
, ' ');
1439 if (new_ssid
== NULL
)
1443 new_auth
= os_strchr(new_ssid
, ' ');
1444 if (new_auth
== NULL
)
1448 new_encr
= os_strchr(new_auth
, ' ');
1449 if (new_encr
== NULL
)
1453 new_key
= os_strchr(new_encr
, ' ');
1454 if (new_key
== NULL
)
1458 os_memset(&ap
, 0, sizeof(ap
));
1459 ap
.ssid_hex
= new_ssid
;
1462 ap
.key_hex
= new_key
;
1463 return wpas_wps_er_config(wpa_s
, cmd
, pin
, &ap
);
1467 #ifdef CONFIG_WPS_NFC
1468 static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
1469 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
1476 uuid
= os_strchr(cmd
, ' ');
1481 if (os_strcmp(cmd
, "WPS") == 0)
1483 else if (os_strcmp(cmd
, "NDEF") == 0)
1488 buf
= wpas_wps_er_nfc_config_token(wpa_s
, ndef
, uuid
);
1492 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1494 reply
[res
++] = '\n';
1501 #endif /* CONFIG_WPS_NFC */
1502 #endif /* CONFIG_WPS_ER */
1504 #endif /* CONFIG_WPS */
1507 #ifdef CONFIG_IBSS_RSN
1508 static int wpa_supplicant_ctrl_iface_ibss_rsn(
1509 struct wpa_supplicant
*wpa_s
, char *addr
)
1513 if (hwaddr_aton(addr
, peer
)) {
1514 wpa_printf(MSG_DEBUG
, "CTRL_IFACE IBSS_RSN: invalid "
1515 "address '%s'", addr
);
1519 wpa_printf(MSG_DEBUG
, "CTRL_IFACE IBSS_RSN " MACSTR
,
1522 return ibss_rsn_start(wpa_s
->ibss_rsn
, peer
);
1524 #endif /* CONFIG_IBSS_RSN */
1527 static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant
*wpa_s
,
1530 #ifdef IEEE8021X_EAPOL
1533 struct wpa_ssid
*ssid
;
1535 pos
= os_strchr(rsp
, '-');
1540 pos
= os_strchr(pos
, ':');
1545 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: field=%s id=%d", rsp
, id
);
1546 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
1547 (u8
*) pos
, os_strlen(pos
));
1549 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1551 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
1556 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s
, ssid
, rsp
,
1558 #else /* IEEE8021X_EAPOL */
1559 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: 802.1X not included");
1561 #endif /* IEEE8021X_EAPOL */
1565 static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant
*wpa_s
,
1567 char *buf
, size_t buflen
)
1569 char *pos
, *end
, tmp
[30];
1570 int res
, verbose
, wps
, ret
;
1572 if (os_strcmp(params
, "-DRIVER") == 0)
1573 return wpa_drv_status(wpa_s
, buf
, buflen
);
1574 verbose
= os_strcmp(params
, "-VERBOSE") == 0;
1575 wps
= os_strcmp(params
, "-WPS") == 0;
1578 if (wpa_s
->wpa_state
>= WPA_ASSOCIATED
) {
1579 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
1580 ret
= os_snprintf(pos
, end
- pos
, "bssid=" MACSTR
"\n",
1581 MAC2STR(wpa_s
->bssid
));
1582 if (ret
< 0 || ret
>= end
- pos
)
1586 u8
*_ssid
= ssid
->ssid
;
1587 size_t ssid_len
= ssid
->ssid_len
;
1588 u8 ssid_buf
[MAX_SSID_LEN
];
1589 if (ssid_len
== 0) {
1590 int _res
= wpa_drv_get_ssid(wpa_s
, ssid_buf
);
1597 ret
= os_snprintf(pos
, end
- pos
, "ssid=%s\nid=%d\n",
1598 wpa_ssid_txt(_ssid
, ssid_len
),
1600 if (ret
< 0 || ret
>= end
- pos
)
1604 if (wps
&& ssid
->passphrase
&&
1605 wpa_key_mgmt_wpa_psk(ssid
->key_mgmt
) &&
1606 (ssid
->mode
== WPAS_MODE_AP
||
1607 ssid
->mode
== WPAS_MODE_P2P_GO
)) {
1608 ret
= os_snprintf(pos
, end
- pos
,
1611 if (ret
< 0 || ret
>= end
- pos
)
1616 ret
= os_snprintf(pos
, end
- pos
,
1619 if (ret
< 0 || ret
>= end
- pos
)
1624 switch (ssid
->mode
) {
1625 case WPAS_MODE_INFRA
:
1626 ret
= os_snprintf(pos
, end
- pos
,
1629 case WPAS_MODE_IBSS
:
1630 ret
= os_snprintf(pos
, end
- pos
,
1634 ret
= os_snprintf(pos
, end
- pos
,
1637 case WPAS_MODE_P2P_GO
:
1638 ret
= os_snprintf(pos
, end
- pos
,
1641 case WPAS_MODE_P2P_GROUP_FORMATION
:
1642 ret
= os_snprintf(pos
, end
- pos
,
1643 "mode=P2P GO - group "
1650 if (ret
< 0 || ret
>= end
- pos
)
1656 if (wpa_s
->ap_iface
) {
1657 pos
+= ap_ctrl_iface_wpa_get_status(wpa_s
, pos
,
1661 #endif /* CONFIG_AP */
1662 pos
+= wpa_sm_get_status(wpa_s
->wpa
, pos
, end
- pos
, verbose
);
1665 if (wpa_s
->wpa_state
>= WPA_ASSOCIATED
&&
1668 #endif /* CONFIG_AP */
1669 wpa_s
->sme
.sae
.state
== SAE_ACCEPTED
) {
1670 ret
= os_snprintf(pos
, end
- pos
, "sae_group=%d\n",
1671 wpa_s
->sme
.sae
.group
);
1672 if (ret
< 0 || ret
>= end
- pos
)
1676 #endif /* CONFIG_SAE */
1677 ret
= os_snprintf(pos
, end
- pos
, "wpa_state=%s\n",
1678 wpa_supplicant_state_txt(wpa_s
->wpa_state
));
1679 if (ret
< 0 || ret
>= end
- pos
)
1684 l2_packet_get_ip_addr(wpa_s
->l2
, tmp
, sizeof(tmp
)) >= 0) {
1685 ret
= os_snprintf(pos
, end
- pos
, "ip_address=%s\n", tmp
);
1686 if (ret
< 0 || ret
>= end
- pos
)
1692 if (wpa_s
->global
->p2p
) {
1693 ret
= os_snprintf(pos
, end
- pos
, "p2p_device_address=" MACSTR
1694 "\n", MAC2STR(wpa_s
->global
->p2p_dev_addr
));
1695 if (ret
< 0 || ret
>= end
- pos
)
1699 #endif /* CONFIG_P2P */
1701 ret
= os_snprintf(pos
, end
- pos
, "address=" MACSTR
"\n",
1702 MAC2STR(wpa_s
->own_addr
));
1703 if (ret
< 0 || ret
>= end
- pos
)
1708 if (wpa_s
->current_bss
&&
1709 wpa_bss_get_vendor_ie(wpa_s
->current_bss
, HS20_IE_VENDOR_TYPE
) &&
1710 wpa_s
->wpa_proto
== WPA_PROTO_RSN
&&
1711 wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
)) {
1712 ret
= os_snprintf(pos
, end
- pos
, "hs20=1\n");
1713 if (ret
< 0 || ret
>= end
- pos
)
1718 if (wpa_s
->current_ssid
) {
1719 struct wpa_cred
*cred
;
1722 for (cred
= wpa_s
->conf
->cred
; cred
; cred
= cred
->next
) {
1725 if (wpa_s
->current_ssid
->parent_cred
!= cred
)
1728 for (i
= 0; cred
->domain
&& i
< cred
->num_domain
; i
++) {
1729 ret
= os_snprintf(pos
, end
- pos
,
1732 if (ret
< 0 || ret
>= end
- pos
)
1737 if (wpa_s
->current_bss
== NULL
||
1738 wpa_s
->current_bss
->anqp
== NULL
)
1741 res
= interworking_home_sp_cred(
1743 wpa_s
->current_bss
->anqp
->domain_name
);
1751 ret
= os_snprintf(pos
, end
- pos
, "sp_type=%s\n", type
);
1752 if (ret
< 0 || ret
>= end
- pos
)
1759 #endif /* CONFIG_HS20 */
1761 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) ||
1762 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
1763 res
= eapol_sm_get_status(wpa_s
->eapol
, pos
, end
- pos
,
1769 res
= rsn_preauth_get_status(wpa_s
->wpa
, pos
, end
- pos
, verbose
);
1776 uuid_bin2str(wpa_s
->wps
->uuid
, uuid_str
, sizeof(uuid_str
));
1777 ret
= os_snprintf(pos
, end
- pos
, "uuid=%s\n", uuid_str
);
1778 if (ret
< 0 || ret
>= end
- pos
)
1782 #endif /* CONFIG_WPS */
1785 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_STATE_CHANGE
1786 "id=%d state=%d BSSID=" MACSTR
" SSID=%s",
1787 wpa_s
->current_ssid
? wpa_s
->current_ssid
->id
: -1,
1789 MAC2STR(wpa_s
->bssid
),
1790 wpa_s
->current_ssid
&& wpa_s
->current_ssid
->ssid
?
1791 wpa_ssid_txt(wpa_s
->current_ssid
->ssid
,
1792 wpa_s
->current_ssid
->ssid_len
) : "");
1793 if (wpa_s
->wpa_state
== WPA_COMPLETED
) {
1794 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
1795 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_CONNECTED
1796 "- connection to " MACSTR
1797 " completed %s [id=%d id_str=%s]",
1798 MAC2STR(wpa_s
->bssid
), "(auth)",
1799 ssid
? ssid
->id
: -1,
1800 ssid
&& ssid
->id_str
? ssid
->id_str
: "");
1802 #endif /* ANDROID */
1808 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant
*wpa_s
,
1813 struct wpa_ssid
*ssid
;
1816 /* cmd: "<network id> <BSSID>" */
1817 pos
= os_strchr(cmd
, ' ');
1822 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: id=%d bssid='%s'", id
, pos
);
1823 if (hwaddr_aton(pos
, bssid
)) {
1824 wpa_printf(MSG_DEBUG
,"CTRL_IFACE: invalid BSSID '%s'", pos
);
1828 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1830 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
1835 os_memcpy(ssid
->bssid
, bssid
, ETH_ALEN
);
1836 ssid
->bssid_set
= !is_zero_ether_addr(bssid
);
1842 static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant
*wpa_s
,
1843 char *cmd
, char *buf
,
1847 struct wpa_blacklist
*e
;
1851 /* cmd: "BLACKLIST [<BSSID>]" */
1855 e
= wpa_s
->blacklist
;
1857 ret
= os_snprintf(pos
, end
- pos
, MACSTR
"\n",
1859 if (ret
< 0 || ret
>= end
- pos
)
1868 if (os_strncmp(cmd
, "clear", 5) == 0) {
1869 wpa_blacklist_clear(wpa_s
);
1870 os_memcpy(buf
, "OK\n", 3);
1874 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd
);
1875 if (hwaddr_aton(cmd
, bssid
)) {
1876 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: invalid BSSID '%s'", cmd
);
1881 * Add the BSSID twice, so its count will be 2, causing it to be
1882 * skipped when processing scan results.
1884 ret
= wpa_blacklist_add(wpa_s
, bssid
);
1887 ret
= wpa_blacklist_add(wpa_s
, bssid
);
1890 os_memcpy(buf
, "OK\n", 3);
1895 static const char * debug_level_str(int level
)
1916 static int str_to_debug_level(const char *s
)
1918 if (os_strcasecmp(s
, "EXCESSIVE") == 0)
1919 return MSG_EXCESSIVE
;
1920 if (os_strcasecmp(s
, "MSGDUMP") == 0)
1922 if (os_strcasecmp(s
, "DEBUG") == 0)
1924 if (os_strcasecmp(s
, "INFO") == 0)
1926 if (os_strcasecmp(s
, "WARNING") == 0)
1928 if (os_strcasecmp(s
, "ERROR") == 0)
1934 static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant
*wpa_s
,
1935 char *cmd
, char *buf
,
1938 char *pos
, *end
, *stamp
;
1945 /* cmd: "LOG_LEVEL [<level>]" */
1949 ret
= os_snprintf(pos
, end
- pos
, "Current level: %s\n"
1951 debug_level_str(wpa_debug_level
),
1952 wpa_debug_timestamp
);
1953 if (ret
< 0 || ret
>= end
- pos
)
1962 stamp
= os_strchr(cmd
, ' ');
1965 while (*stamp
== ' ') {
1970 if (cmd
&& os_strlen(cmd
)) {
1971 int level
= str_to_debug_level(cmd
);
1974 wpa_debug_level
= level
;
1977 if (stamp
&& os_strlen(stamp
))
1978 wpa_debug_timestamp
= atoi(stamp
);
1980 os_memcpy(buf
, "OK\n", 3);
1985 static int wpa_supplicant_ctrl_iface_list_networks(
1986 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
1989 struct wpa_ssid
*ssid
;
1994 ret
= os_snprintf(pos
, end
- pos
,
1995 "network id / ssid / bssid / flags\n");
1996 if (ret
< 0 || ret
>= end
- pos
)
2000 ssid
= wpa_s
->conf
->ssid
;
2002 ret
= os_snprintf(pos
, end
- pos
, "%d\t%s",
2004 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
));
2005 if (ret
< 0 || ret
>= end
- pos
)
2008 if (ssid
->bssid_set
) {
2009 ret
= os_snprintf(pos
, end
- pos
, "\t" MACSTR
,
2010 MAC2STR(ssid
->bssid
));
2012 ret
= os_snprintf(pos
, end
- pos
, "\tany");
2014 if (ret
< 0 || ret
>= end
- pos
)
2017 ret
= os_snprintf(pos
, end
- pos
, "\t%s%s%s%s",
2018 ssid
== wpa_s
->current_ssid
?
2020 ssid
->disabled
? "[DISABLED]" : "",
2021 ssid
->disabled_until
.sec
?
2022 "[TEMP-DISABLED]" : "",
2023 ssid
->disabled
== 2 ? "[P2P-PERSISTENT]" :
2025 if (ret
< 0 || ret
>= end
- pos
)
2028 ret
= os_snprintf(pos
, end
- pos
, "\n");
2029 if (ret
< 0 || ret
>= end
- pos
)
2040 static char * wpa_supplicant_cipher_txt(char *pos
, char *end
, int cipher
)
2043 ret
= os_snprintf(pos
, end
- pos
, "-");
2044 if (ret
< 0 || ret
>= end
- pos
)
2047 ret
= wpa_write_ciphers(pos
, end
, cipher
, "+");
2055 static char * wpa_supplicant_ie_txt(char *pos
, char *end
, const char *proto
,
2056 const u8
*ie
, size_t ie_len
)
2058 struct wpa_ie_data data
;
2061 ret
= os_snprintf(pos
, end
- pos
, "[%s-", proto
);
2062 if (ret
< 0 || ret
>= end
- pos
)
2066 if (wpa_parse_wpa_ie(ie
, ie_len
, &data
) < 0) {
2067 ret
= os_snprintf(pos
, end
- pos
, "?]");
2068 if (ret
< 0 || ret
>= end
- pos
)
2075 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X
) {
2076 ret
= os_snprintf(pos
, end
- pos
, "%sEAP", first
? "" : "+");
2077 if (ret
< 0 || ret
>= end
- pos
)
2082 if (data
.key_mgmt
& WPA_KEY_MGMT_PSK
) {
2083 ret
= os_snprintf(pos
, end
- pos
, "%sPSK", first
? "" : "+");
2084 if (ret
< 0 || ret
>= end
- pos
)
2089 if (data
.key_mgmt
& WPA_KEY_MGMT_WPA_NONE
) {
2090 ret
= os_snprintf(pos
, end
- pos
, "%sNone", first
? "" : "+");
2091 if (ret
< 0 || ret
>= end
- pos
)
2096 #ifdef CONFIG_IEEE80211R
2097 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_IEEE8021X
) {
2098 ret
= os_snprintf(pos
, end
- pos
, "%sFT/EAP",
2100 if (ret
< 0 || ret
>= end
- pos
)
2105 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_PSK
) {
2106 ret
= os_snprintf(pos
, end
- pos
, "%sFT/PSK",
2108 if (ret
< 0 || ret
>= end
- pos
)
2113 #endif /* CONFIG_IEEE80211R */
2114 #ifdef CONFIG_IEEE80211W
2115 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SHA256
) {
2116 ret
= os_snprintf(pos
, end
- pos
, "%sEAP-SHA256",
2118 if (ret
< 0 || ret
>= end
- pos
)
2123 if (data
.key_mgmt
& WPA_KEY_MGMT_PSK_SHA256
) {
2124 ret
= os_snprintf(pos
, end
- pos
, "%sPSK-SHA256",
2126 if (ret
< 0 || ret
>= end
- pos
)
2131 #endif /* CONFIG_IEEE80211W */
2133 pos
= wpa_supplicant_cipher_txt(pos
, end
, data
.pairwise_cipher
);
2135 if (data
.capabilities
& WPA_CAPABILITY_PREAUTH
) {
2136 ret
= os_snprintf(pos
, end
- pos
, "-preauth");
2137 if (ret
< 0 || ret
>= end
- pos
)
2142 ret
= os_snprintf(pos
, end
- pos
, "]");
2143 if (ret
< 0 || ret
>= end
- pos
)
2152 static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant
*wpa_s
,
2153 char *pos
, char *end
,
2154 struct wpabuf
*wps_ie
)
2161 if (wps_is_selected_pbc_registrar(wps_ie
))
2164 else if (wps_is_addr_authorized(wps_ie
, wpa_s
->own_addr
, 0))
2166 #endif /* CONFIG_WPS2 */
2167 else if (wps_is_selected_pin_registrar(wps_ie
))
2172 ret
= os_snprintf(pos
, end
- pos
, "%s", txt
);
2173 if (ret
>= 0 && ret
< end
- pos
)
2175 wpabuf_free(wps_ie
);
2178 #endif /* CONFIG_WPS */
2181 static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant
*wpa_s
,
2182 char *pos
, char *end
,
2183 const struct wpa_bss
*bss
)
2186 struct wpabuf
*wps_ie
;
2187 wps_ie
= wpa_bss_get_vendor_ie_multi(bss
, WPS_IE_VENDOR_TYPE
);
2188 return wpa_supplicant_wps_ie_txt_buf(wpa_s
, pos
, end
, wps_ie
);
2189 #else /* CONFIG_WPS */
2191 #endif /* CONFIG_WPS */
2195 /* Format one result on one text line into a buffer. */
2196 static int wpa_supplicant_ctrl_iface_scan_result(
2197 struct wpa_supplicant
*wpa_s
,
2198 const struct wpa_bss
*bss
, char *buf
, size_t buflen
)
2202 const u8
*ie
, *ie2
, *p2p
;
2204 p2p
= wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
);
2206 p2p
= wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
);
2207 if (p2p
&& bss
->ssid_len
== P2P_WILDCARD_SSID_LEN
&&
2208 os_memcmp(bss
->ssid
, P2P_WILDCARD_SSID
, P2P_WILDCARD_SSID_LEN
) ==
2210 return 0; /* Do not show P2P listen discovery results here */
2215 ret
= os_snprintf(pos
, end
- pos
, MACSTR
"\t%d\t%d\t",
2216 MAC2STR(bss
->bssid
), bss
->freq
, bss
->level
);
2217 if (ret
< 0 || ret
>= end
- pos
)
2220 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
2222 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA", ie
, 2 + ie
[1]);
2223 ie2
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
2225 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA2", ie2
, 2 + ie2
[1]);
2226 pos
= wpa_supplicant_wps_ie_txt(wpa_s
, pos
, end
, bss
);
2227 if (!ie
&& !ie2
&& bss
->caps
& IEEE80211_CAP_PRIVACY
) {
2228 ret
= os_snprintf(pos
, end
- pos
, "[WEP]");
2229 if (ret
< 0 || ret
>= end
- pos
)
2233 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
2234 ret
= os_snprintf(pos
, end
- pos
, "[IBSS]");
2235 if (ret
< 0 || ret
>= end
- pos
)
2239 if (bss
->caps
& IEEE80211_CAP_ESS
) {
2240 ret
= os_snprintf(pos
, end
- pos
, "[ESS]");
2241 if (ret
< 0 || ret
>= end
- pos
)
2246 ret
= os_snprintf(pos
, end
- pos
, "[P2P]");
2247 if (ret
< 0 || ret
>= end
- pos
)
2252 if (wpa_bss_get_vendor_ie(bss
, HS20_IE_VENDOR_TYPE
) && ie2
) {
2253 ret
= os_snprintf(pos
, end
- pos
, "[HS20]");
2254 if (ret
< 0 || ret
>= end
- pos
)
2258 #endif /* CONFIG_HS20 */
2260 ret
= os_snprintf(pos
, end
- pos
, "\t%s",
2261 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
2262 if (ret
< 0 || ret
>= end
- pos
)
2266 ret
= os_snprintf(pos
, end
- pos
, "\n");
2267 if (ret
< 0 || ret
>= end
- pos
)
2275 static int wpa_supplicant_ctrl_iface_scan_results(
2276 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
2279 struct wpa_bss
*bss
;
2284 ret
= os_snprintf(pos
, end
- pos
, "bssid / frequency / signal level / "
2286 if (ret
< 0 || ret
>= end
- pos
)
2290 dl_list_for_each(bss
, &wpa_s
->bss_id
, struct wpa_bss
, list_id
) {
2291 ret
= wpa_supplicant_ctrl_iface_scan_result(wpa_s
, bss
, pos
,
2293 if (ret
< 0 || ret
>= end
- pos
)
2302 static int wpa_supplicant_ctrl_iface_select_network(
2303 struct wpa_supplicant
*wpa_s
, char *cmd
)
2306 struct wpa_ssid
*ssid
;
2308 /* cmd: "<network id>" or "any" */
2309 if (os_strcmp(cmd
, "any") == 0) {
2310 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SELECT_NETWORK any");
2314 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SELECT_NETWORK id=%d", id
);
2316 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2318 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
2319 "network id=%d", id
);
2322 if (ssid
->disabled
== 2) {
2323 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
2324 "SELECT_NETWORK with persistent P2P group");
2329 wpa_supplicant_select_network(wpa_s
, ssid
);
2335 static int wpa_supplicant_ctrl_iface_enable_network(
2336 struct wpa_supplicant
*wpa_s
, char *cmd
)
2339 struct wpa_ssid
*ssid
;
2341 /* cmd: "<network id>" or "all" */
2342 if (os_strcmp(cmd
, "all") == 0) {
2343 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ENABLE_NETWORK all");
2347 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ENABLE_NETWORK id=%d", id
);
2349 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2351 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
2352 "network id=%d", id
);
2355 if (ssid
->disabled
== 2) {
2356 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
2357 "ENABLE_NETWORK with persistent P2P group");
2361 if (os_strstr(cmd
, " no-connect")) {
2366 wpa_supplicant_enable_network(wpa_s
, ssid
);
2372 static int wpa_supplicant_ctrl_iface_disable_network(
2373 struct wpa_supplicant
*wpa_s
, char *cmd
)
2376 struct wpa_ssid
*ssid
;
2378 /* cmd: "<network id>" or "all" */
2379 if (os_strcmp(cmd
, "all") == 0) {
2380 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DISABLE_NETWORK all");
2384 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DISABLE_NETWORK id=%d", id
);
2386 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2388 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
2389 "network id=%d", id
);
2392 if (ssid
->disabled
== 2) {
2393 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
2394 "DISABLE_NETWORK with persistent P2P "
2399 wpa_supplicant_disable_network(wpa_s
, ssid
);
2405 static int wpa_supplicant_ctrl_iface_add_network(
2406 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
2408 struct wpa_ssid
*ssid
;
2411 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ADD_NETWORK");
2413 ssid
= wpa_config_add_network(wpa_s
->conf
);
2417 wpas_notify_network_added(wpa_s
, ssid
);
2420 wpa_config_set_network_defaults(ssid
);
2422 ret
= os_snprintf(buf
, buflen
, "%d\n", ssid
->id
);
2423 if (ret
< 0 || (size_t) ret
>= buflen
)
2429 static int wpa_supplicant_ctrl_iface_remove_network(
2430 struct wpa_supplicant
*wpa_s
, char *cmd
)
2433 struct wpa_ssid
*ssid
;
2436 /* cmd: "<network id>" or "all" */
2437 if (os_strcmp(cmd
, "all") == 0) {
2438 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_NETWORK all");
2439 if (wpa_s
->sched_scanning
)
2440 wpa_supplicant_cancel_sched_scan(wpa_s
);
2442 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
2443 if (wpa_s
->current_ssid
) {
2445 wpa_s
->sme
.prev_bssid_set
= 0;
2446 #endif /* CONFIG_SME */
2447 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
2448 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
2449 wpa_supplicant_deauthenticate(
2450 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2452 ssid
= wpa_s
->conf
->ssid
;
2454 struct wpa_ssid
*remove_ssid
= ssid
;
2457 wpas_notify_network_removed(wpa_s
, remove_ssid
);
2458 wpa_config_remove_network(wpa_s
->conf
, id
);
2464 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_NETWORK id=%d", id
);
2466 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2468 wpas_notify_network_removed(wpa_s
, ssid
);
2470 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
2475 if (ssid
== wpa_s
->current_ssid
|| wpa_s
->current_ssid
== NULL
) {
2477 wpa_s
->sme
.prev_bssid_set
= 0;
2478 #endif /* CONFIG_SME */
2480 * Invalidate the EAP session cache if the current or
2481 * previously used network is removed.
2483 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
2486 if (ssid
== wpa_s
->current_ssid
) {
2487 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
2488 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
2490 wpa_supplicant_deauthenticate(wpa_s
,
2491 WLAN_REASON_DEAUTH_LEAVING
);
2494 was_disabled
= ssid
->disabled
;
2496 if (wpa_config_remove_network(wpa_s
->conf
, id
) < 0) {
2497 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Not able to remove the "
2498 "network id=%d", id
);
2502 if (!was_disabled
&& wpa_s
->sched_scanning
) {
2503 wpa_printf(MSG_DEBUG
, "Stop ongoing sched_scan to remove "
2504 "network from filters");
2505 wpa_supplicant_cancel_sched_scan(wpa_s
);
2506 wpa_supplicant_req_scan(wpa_s
, 0, 0);
2513 static int wpa_supplicant_ctrl_iface_set_network(
2514 struct wpa_supplicant
*wpa_s
, char *cmd
)
2517 struct wpa_ssid
*ssid
;
2520 /* cmd: "<network id> <variable name> <value>" */
2521 name
= os_strchr(cmd
, ' ');
2526 value
= os_strchr(name
, ' ');
2532 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
2534 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
2535 (u8
*) value
, os_strlen(value
));
2537 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2539 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
2544 if (wpa_config_set(ssid
, name
, value
, 0) < 0) {
2545 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to set network "
2546 "variable '%s'", name
);
2550 if (os_strcmp(name
, "bssid") != 0 &&
2551 os_strcmp(name
, "priority") != 0)
2552 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, ssid
);
2554 if (wpa_s
->current_ssid
== ssid
|| wpa_s
->current_ssid
== NULL
) {
2556 * Invalidate the EAP session cache if anything in the current
2557 * or previously used configuration changes.
2559 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
2562 if ((os_strcmp(name
, "psk") == 0 &&
2563 value
[0] == '"' && ssid
->ssid_len
) ||
2564 (os_strcmp(name
, "ssid") == 0 && ssid
->passphrase
))
2565 wpa_config_update_psk(ssid
);
2566 else if (os_strcmp(name
, "priority") == 0)
2567 wpa_config_update_prio_list(wpa_s
->conf
);
2573 static int wpa_supplicant_ctrl_iface_get_network(
2574 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
2578 struct wpa_ssid
*ssid
;
2581 /* cmd: "<network id> <variable name>" */
2582 name
= os_strchr(cmd
, ' ');
2583 if (name
== NULL
|| buflen
== 0)
2588 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
2591 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2593 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
2598 value
= wpa_config_get_no_key(ssid
, name
);
2599 if (value
== NULL
) {
2600 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to get network "
2601 "variable '%s'", name
);
2605 res
= os_strlcpy(buf
, value
, buflen
);
2606 if (res
>= buflen
) {
2617 static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant
*wpa_s
,
2618 char *buf
, size_t buflen
)
2621 struct wpa_cred
*cred
;
2626 ret
= os_snprintf(pos
, end
- pos
,
2627 "cred id / realm / username / domain / imsi\n");
2628 if (ret
< 0 || ret
>= end
- pos
)
2632 cred
= wpa_s
->conf
->cred
;
2634 ret
= os_snprintf(pos
, end
- pos
, "%d\t%s\t%s\t%s\t%s\n",
2635 cred
->id
, cred
->realm
? cred
->realm
: "",
2636 cred
->username
? cred
->username
: "",
2637 cred
->domain
? cred
->domain
[0] : "",
2638 cred
->imsi
? cred
->imsi
: "");
2639 if (ret
< 0 || ret
>= end
- pos
)
2650 static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant
*wpa_s
,
2651 char *buf
, size_t buflen
)
2653 struct wpa_cred
*cred
;
2656 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ADD_CRED");
2658 cred
= wpa_config_add_cred(wpa_s
->conf
);
2662 ret
= os_snprintf(buf
, buflen
, "%d\n", cred
->id
);
2663 if (ret
< 0 || (size_t) ret
>= buflen
)
2669 static int wpas_ctrl_remove_cred(struct wpa_supplicant
*wpa_s
,
2670 struct wpa_cred
*cred
)
2672 struct wpa_ssid
*ssid
;
2675 if (cred
== NULL
|| wpa_config_remove_cred(wpa_s
->conf
, cred
->id
) < 0) {
2676 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred");
2680 /* Remove any network entry created based on the removed credential */
2681 ssid
= wpa_s
->conf
->ssid
;
2683 if (ssid
->parent_cred
== cred
) {
2684 wpa_printf(MSG_DEBUG
, "Remove network id %d since it "
2685 "used the removed credential", ssid
->id
);
2686 os_snprintf(str
, sizeof(str
), "%d", ssid
->id
);
2688 wpa_supplicant_ctrl_iface_remove_network(wpa_s
, str
);
2697 static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant
*wpa_s
,
2701 struct wpa_cred
*cred
, *prev
;
2703 /* cmd: "<cred id>", "all", or "sp_fqdn=<FQDN>" */
2704 if (os_strcmp(cmd
, "all") == 0) {
2705 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED all");
2706 cred
= wpa_s
->conf
->cred
;
2710 wpas_ctrl_remove_cred(wpa_s
, prev
);
2715 if (os_strncmp(cmd
, "sp_fqdn=", 8) == 0) {
2716 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
2718 cred
= wpa_s
->conf
->cred
;
2724 for (i
= 0; i
< prev
->num_domain
; i
++) {
2725 if (os_strcmp(prev
->domain
[i
], cmd
+ 8)
2728 wpas_ctrl_remove_cred(wpa_s
, prev
);
2737 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED id=%d", id
);
2739 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
2740 return wpas_ctrl_remove_cred(wpa_s
, cred
);
2744 static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant
*wpa_s
,
2748 struct wpa_cred
*cred
;
2751 /* cmd: "<cred id> <variable name> <value>" */
2752 name
= os_strchr(cmd
, ' ');
2757 value
= os_strchr(name
, ' ');
2763 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SET_CRED id=%d name='%s'",
2765 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
2766 (u8
*) value
, os_strlen(value
));
2768 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
2770 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred id=%d",
2775 if (wpa_config_set_cred(cred
, name
, value
, 0) < 0) {
2776 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to set cred "
2777 "variable '%s'", name
);
2785 #ifndef CONFIG_NO_CONFIG_WRITE
2786 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant
*wpa_s
)
2790 if (!wpa_s
->conf
->update_config
) {
2791 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
2792 "to update configuration (update_config=0)");
2796 ret
= wpa_config_write(wpa_s
->confname
, wpa_s
->conf
);
2798 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Failed to "
2799 "update configuration");
2801 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Configuration"
2807 #endif /* CONFIG_NO_CONFIG_WRITE */
2810 struct cipher_info
{
2816 static const struct cipher_info ciphers
[] = {
2817 { WPA_DRIVER_CAPA_ENC_CCMP_256
, "CCMP-256", 0 },
2818 { WPA_DRIVER_CAPA_ENC_GCMP_256
, "GCMP-256", 0 },
2819 { WPA_DRIVER_CAPA_ENC_CCMP
, "CCMP", 0 },
2820 { WPA_DRIVER_CAPA_ENC_GCMP
, "GCMP", 0 },
2821 { WPA_DRIVER_CAPA_ENC_TKIP
, "TKIP", 0 },
2822 { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
, "NONE", 0 },
2823 { WPA_DRIVER_CAPA_ENC_WEP104
, "WEP104", 1 },
2824 { WPA_DRIVER_CAPA_ENC_WEP40
, "WEP40", 1 }
2828 static int ctrl_iface_get_capability_pairwise(int res
, char *strict
,
2829 struct wpa_driver_capa
*capa
,
2830 char *buf
, size_t buflen
)
2843 len
= os_strlcpy(buf
, "CCMP TKIP NONE", buflen
);
2849 for (i
= 0; i
< ARRAY_SIZE(ciphers
); i
++) {
2850 if (!ciphers
[i
].group_only
&& capa
->enc
& ciphers
[i
].capa
) {
2851 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
2852 first
? "" : " ", ciphers
[i
].name
);
2853 if (ret
< 0 || ret
>= end
- pos
)
2864 static int ctrl_iface_get_capability_group(int res
, char *strict
,
2865 struct wpa_driver_capa
*capa
,
2866 char *buf
, size_t buflen
)
2879 len
= os_strlcpy(buf
, "CCMP TKIP WEP104 WEP40", buflen
);
2885 for (i
= 0; i
< ARRAY_SIZE(ciphers
); i
++) {
2886 if (capa
->enc
& ciphers
[i
].capa
) {
2887 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
2888 first
? "" : " ", ciphers
[i
].name
);
2889 if (ret
< 0 || ret
>= end
- pos
)
2900 static int ctrl_iface_get_capability_key_mgmt(int res
, char *strict
,
2901 struct wpa_driver_capa
*capa
,
2902 char *buf
, size_t buflen
)
2914 len
= os_strlcpy(buf
, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
2921 ret
= os_snprintf(pos
, end
- pos
, "NONE IEEE8021X");
2922 if (ret
< 0 || ret
>= end
- pos
)
2926 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
2927 WPA_DRIVER_CAPA_KEY_MGMT_WPA2
)) {
2928 ret
= os_snprintf(pos
, end
- pos
, " WPA-EAP");
2929 if (ret
< 0 || ret
>= end
- pos
)
2934 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
|
2935 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
)) {
2936 ret
= os_snprintf(pos
, end
- pos
, " WPA-PSK");
2937 if (ret
< 0 || ret
>= end
- pos
)
2942 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
) {
2943 ret
= os_snprintf(pos
, end
- pos
, " WPA-NONE");
2944 if (ret
< 0 || ret
>= end
- pos
)
2953 static int ctrl_iface_get_capability_proto(int res
, char *strict
,
2954 struct wpa_driver_capa
*capa
,
2955 char *buf
, size_t buflen
)
2967 len
= os_strlcpy(buf
, "RSN WPA", buflen
);
2973 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA2
|
2974 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
)) {
2975 ret
= os_snprintf(pos
, end
- pos
, "%sRSN", first
? "" : " ");
2976 if (ret
< 0 || ret
>= end
- pos
)
2982 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
2983 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
)) {
2984 ret
= os_snprintf(pos
, end
- pos
, "%sWPA", first
? "" : " ");
2985 if (ret
< 0 || ret
>= end
- pos
)
2995 static int ctrl_iface_get_capability_auth_alg(int res
, char *strict
,
2996 struct wpa_driver_capa
*capa
,
2997 char *buf
, size_t buflen
)
3009 len
= os_strlcpy(buf
, "OPEN SHARED LEAP", buflen
);
3015 if (capa
->auth
& (WPA_DRIVER_AUTH_OPEN
)) {
3016 ret
= os_snprintf(pos
, end
- pos
, "%sOPEN", first
? "" : " ");
3017 if (ret
< 0 || ret
>= end
- pos
)
3023 if (capa
->auth
& (WPA_DRIVER_AUTH_SHARED
)) {
3024 ret
= os_snprintf(pos
, end
- pos
, "%sSHARED",
3026 if (ret
< 0 || ret
>= end
- pos
)
3032 if (capa
->auth
& (WPA_DRIVER_AUTH_LEAP
)) {
3033 ret
= os_snprintf(pos
, end
- pos
, "%sLEAP", first
? "" : " ");
3034 if (ret
< 0 || ret
>= end
- pos
)
3044 static int ctrl_iface_get_capability_modes(int res
, char *strict
,
3045 struct wpa_driver_capa
*capa
,
3046 char *buf
, size_t buflen
)
3058 len
= os_strlcpy(buf
, "IBSS AP", buflen
);
3064 if (capa
->flags
& WPA_DRIVER_FLAGS_IBSS
) {
3065 ret
= os_snprintf(pos
, end
- pos
, "%sIBSS", first
? "" : " ");
3066 if (ret
< 0 || ret
>= end
- pos
)
3072 if (capa
->flags
& WPA_DRIVER_FLAGS_AP
) {
3073 ret
= os_snprintf(pos
, end
- pos
, "%sAP", first
? "" : " ");
3074 if (ret
< 0 || ret
>= end
- pos
)
3084 static int ctrl_iface_get_capability_channels(struct wpa_supplicant
*wpa_s
,
3085 char *buf
, size_t buflen
)
3087 struct hostapd_channel_data
*chnl
;
3089 char *pos
, *end
, *hmode
;
3094 for (j
= 0; j
< wpa_s
->hw
.num_modes
; j
++) {
3095 switch (wpa_s
->hw
.modes
[j
].mode
) {
3096 case HOSTAPD_MODE_IEEE80211B
:
3099 case HOSTAPD_MODE_IEEE80211G
:
3102 case HOSTAPD_MODE_IEEE80211A
:
3105 case HOSTAPD_MODE_IEEE80211AD
:
3111 ret
= os_snprintf(pos
, end
- pos
, "Mode[%s] Channels:", hmode
);
3112 if (ret
< 0 || ret
>= end
- pos
)
3115 chnl
= wpa_s
->hw
.modes
[j
].channels
;
3116 for (i
= 0; i
< wpa_s
->hw
.modes
[j
].num_channels
; i
++) {
3117 if (chnl
[i
].flag
& HOSTAPD_CHAN_DISABLED
)
3119 ret
= os_snprintf(pos
, end
- pos
, " %d", chnl
[i
].chan
);
3120 if (ret
< 0 || ret
>= end
- pos
)
3124 ret
= os_snprintf(pos
, end
- pos
, "\n");
3125 if (ret
< 0 || ret
>= end
- pos
)
3134 static int ctrl_iface_get_capability_freq(struct wpa_supplicant
*wpa_s
,
3135 char *buf
, size_t buflen
)
3137 struct hostapd_channel_data
*chnl
;
3139 char *pos
, *end
, *hmode
;
3144 for (j
= 0; j
< wpa_s
->hw
.num_modes
; j
++) {
3145 switch (wpa_s
->hw
.modes
[j
].mode
) {
3146 case HOSTAPD_MODE_IEEE80211B
:
3149 case HOSTAPD_MODE_IEEE80211G
:
3152 case HOSTAPD_MODE_IEEE80211A
:
3155 case HOSTAPD_MODE_IEEE80211AD
:
3161 ret
= os_snprintf(pos
, end
- pos
, "Mode[%s] Channels:\n",
3163 if (ret
< 0 || ret
>= end
- pos
)
3166 chnl
= wpa_s
->hw
.modes
[j
].channels
;
3167 for (i
= 0; i
< wpa_s
->hw
.modes
[j
].num_channels
; i
++) {
3168 if (chnl
[i
].flag
& HOSTAPD_CHAN_DISABLED
)
3170 ret
= os_snprintf(pos
, end
- pos
, " %d = %d MHz%s\n",
3171 chnl
[i
].chan
, chnl
[i
].freq
,
3172 chnl
[i
].flag
& HOSTAPD_CHAN_NO_IBSS
?
3174 if (ret
< 0 || ret
>= end
- pos
)
3178 ret
= os_snprintf(pos
, end
- pos
, "\n");
3179 if (ret
< 0 || ret
>= end
- pos
)
3188 static int wpa_supplicant_ctrl_iface_get_capability(
3189 struct wpa_supplicant
*wpa_s
, const char *_field
, char *buf
,
3192 struct wpa_driver_capa capa
;
3198 /* Determine whether or not strict checking was requested */
3199 len
= os_strlcpy(field
, _field
, sizeof(field
));
3200 if (len
>= sizeof(field
))
3202 strict
= os_strchr(field
, ' ');
3203 if (strict
!= NULL
) {
3205 if (os_strcmp(strict
, "strict") != 0)
3209 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
3210 field
, strict
? strict
: "");
3212 if (os_strcmp(field
, "eap") == 0) {
3213 return eap_get_names(buf
, buflen
);
3216 res
= wpa_drv_get_capa(wpa_s
, &capa
);
3218 if (os_strcmp(field
, "pairwise") == 0)
3219 return ctrl_iface_get_capability_pairwise(res
, strict
, &capa
,
3222 if (os_strcmp(field
, "group") == 0)
3223 return ctrl_iface_get_capability_group(res
, strict
, &capa
,
3226 if (os_strcmp(field
, "key_mgmt") == 0)
3227 return ctrl_iface_get_capability_key_mgmt(res
, strict
, &capa
,
3230 if (os_strcmp(field
, "proto") == 0)
3231 return ctrl_iface_get_capability_proto(res
, strict
, &capa
,
3234 if (os_strcmp(field
, "auth_alg") == 0)
3235 return ctrl_iface_get_capability_auth_alg(res
, strict
, &capa
,
3238 if (os_strcmp(field
, "modes") == 0)
3239 return ctrl_iface_get_capability_modes(res
, strict
, &capa
,
3242 if (os_strcmp(field
, "channels") == 0)
3243 return ctrl_iface_get_capability_channels(wpa_s
, buf
, buflen
);
3245 if (os_strcmp(field
, "freq") == 0)
3246 return ctrl_iface_get_capability_freq(wpa_s
, buf
, buflen
);
3248 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
3255 #ifdef CONFIG_INTERWORKING
3256 static char * anqp_add_hex(char *pos
, char *end
, const char *title
,
3257 struct wpabuf
*data
)
3267 ret
= os_snprintf(pos
, end
- pos
, "%s=", title
);
3268 if (ret
< 0 || ret
>= end
- pos
)
3272 d
= wpabuf_head_u8(data
);
3273 for (i
= 0; i
< wpabuf_len(data
); i
++) {
3274 ret
= os_snprintf(pos
, end
- pos
, "%02x", *d
++);
3275 if (ret
< 0 || ret
>= end
- pos
)
3280 ret
= os_snprintf(pos
, end
- pos
, "\n");
3281 if (ret
< 0 || ret
>= end
- pos
)
3287 #endif /* CONFIG_INTERWORKING */
3290 static int print_bss_info(struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
,
3291 unsigned long mask
, char *buf
, size_t buflen
)
3301 if (mask
& WPA_BSS_MASK_ID
) {
3302 ret
= os_snprintf(pos
, end
- pos
, "id=%u\n", bss
->id
);
3303 if (ret
< 0 || ret
>= end
- pos
)
3308 if (mask
& WPA_BSS_MASK_BSSID
) {
3309 ret
= os_snprintf(pos
, end
- pos
, "bssid=" MACSTR
"\n",
3310 MAC2STR(bss
->bssid
));
3311 if (ret
< 0 || ret
>= end
- pos
)
3316 if (mask
& WPA_BSS_MASK_FREQ
) {
3317 ret
= os_snprintf(pos
, end
- pos
, "freq=%d\n", bss
->freq
);
3318 if (ret
< 0 || ret
>= end
- pos
)
3323 if (mask
& WPA_BSS_MASK_BEACON_INT
) {
3324 ret
= os_snprintf(pos
, end
- pos
, "beacon_int=%d\n",
3326 if (ret
< 0 || ret
>= end
- pos
)
3331 if (mask
& WPA_BSS_MASK_CAPABILITIES
) {
3332 ret
= os_snprintf(pos
, end
- pos
, "capabilities=0x%04x\n",
3334 if (ret
< 0 || ret
>= end
- pos
)
3339 if (mask
& WPA_BSS_MASK_QUAL
) {
3340 ret
= os_snprintf(pos
, end
- pos
, "qual=%d\n", bss
->qual
);
3341 if (ret
< 0 || ret
>= end
- pos
)
3346 if (mask
& WPA_BSS_MASK_NOISE
) {
3347 ret
= os_snprintf(pos
, end
- pos
, "noise=%d\n", bss
->noise
);
3348 if (ret
< 0 || ret
>= end
- pos
)
3353 if (mask
& WPA_BSS_MASK_LEVEL
) {
3354 ret
= os_snprintf(pos
, end
- pos
, "level=%d\n", bss
->level
);
3355 if (ret
< 0 || ret
>= end
- pos
)
3360 if (mask
& WPA_BSS_MASK_TSF
) {
3361 ret
= os_snprintf(pos
, end
- pos
, "tsf=%016llu\n",
3362 (unsigned long long) bss
->tsf
);
3363 if (ret
< 0 || ret
>= end
- pos
)
3368 if (mask
& WPA_BSS_MASK_AGE
) {
3369 struct os_reltime now
;
3371 os_get_reltime(&now
);
3372 ret
= os_snprintf(pos
, end
- pos
, "age=%d\n",
3373 (int) (now
.sec
- bss
->last_update
.sec
));
3374 if (ret
< 0 || ret
>= end
- pos
)
3379 if (mask
& WPA_BSS_MASK_IE
) {
3380 ret
= os_snprintf(pos
, end
- pos
, "ie=");
3381 if (ret
< 0 || ret
>= end
- pos
)
3385 ie
= (const u8
*) (bss
+ 1);
3386 for (i
= 0; i
< bss
->ie_len
; i
++) {
3387 ret
= os_snprintf(pos
, end
- pos
, "%02x", *ie
++);
3388 if (ret
< 0 || ret
>= end
- pos
)
3393 ret
= os_snprintf(pos
, end
- pos
, "\n");
3394 if (ret
< 0 || ret
>= end
- pos
)
3399 if (mask
& WPA_BSS_MASK_FLAGS
) {
3400 ret
= os_snprintf(pos
, end
- pos
, "flags=");
3401 if (ret
< 0 || ret
>= end
- pos
)
3405 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
3407 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA", ie
,
3409 ie2
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
3411 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA2", ie2
,
3413 pos
= wpa_supplicant_wps_ie_txt(wpa_s
, pos
, end
, bss
);
3414 if (!ie
&& !ie2
&& bss
->caps
& IEEE80211_CAP_PRIVACY
) {
3415 ret
= os_snprintf(pos
, end
- pos
, "[WEP]");
3416 if (ret
< 0 || ret
>= end
- pos
)
3420 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
3421 ret
= os_snprintf(pos
, end
- pos
, "[IBSS]");
3422 if (ret
< 0 || ret
>= end
- pos
)
3426 if (bss
->caps
& IEEE80211_CAP_ESS
) {
3427 ret
= os_snprintf(pos
, end
- pos
, "[ESS]");
3428 if (ret
< 0 || ret
>= end
- pos
)
3432 if (wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
) ||
3433 wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
)) {
3434 ret
= os_snprintf(pos
, end
- pos
, "[P2P]");
3435 if (ret
< 0 || ret
>= end
- pos
)
3440 if (wpa_bss_get_vendor_ie(bss
, HS20_IE_VENDOR_TYPE
)) {
3441 ret
= os_snprintf(pos
, end
- pos
, "[HS20]");
3442 if (ret
< 0 || ret
>= end
- pos
)
3446 #endif /* CONFIG_HS20 */
3448 ret
= os_snprintf(pos
, end
- pos
, "\n");
3449 if (ret
< 0 || ret
>= end
- pos
)
3454 if (mask
& WPA_BSS_MASK_SSID
) {
3455 ret
= os_snprintf(pos
, end
- pos
, "ssid=%s\n",
3456 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
3457 if (ret
< 0 || ret
>= end
- pos
)
3463 if (mask
& WPA_BSS_MASK_WPS_SCAN
) {
3464 ie
= (const u8
*) (bss
+ 1);
3465 ret
= wpas_wps_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
3466 if (ret
< 0 || ret
>= end
- pos
)
3470 #endif /* CONFIG_WPS */
3473 if (mask
& WPA_BSS_MASK_P2P_SCAN
) {
3474 ie
= (const u8
*) (bss
+ 1);
3475 ret
= wpas_p2p_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
3476 if (ret
< 0 || ret
>= end
- pos
)
3480 #endif /* CONFIG_P2P */
3482 #ifdef CONFIG_WIFI_DISPLAY
3483 if (mask
& WPA_BSS_MASK_WIFI_DISPLAY
) {
3485 ie
= (const u8
*) (bss
+ 1);
3486 wfd
= ieee802_11_vendor_ie_concat(ie
, bss
->ie_len
,
3487 WFD_IE_VENDOR_TYPE
);
3489 ret
= os_snprintf(pos
, end
- pos
, "wfd_subelems=");
3490 if (ret
< 0 || ret
>= end
- pos
)
3494 pos
+= wpa_snprintf_hex(pos
, end
- pos
,
3499 ret
= os_snprintf(pos
, end
- pos
, "\n");
3500 if (ret
< 0 || ret
>= end
- pos
)
3505 #endif /* CONFIG_WIFI_DISPLAY */
3507 #ifdef CONFIG_INTERWORKING
3508 if ((mask
& WPA_BSS_MASK_INTERNETW
) && bss
->anqp
) {
3509 struct wpa_bss_anqp
*anqp
= bss
->anqp
;
3510 pos
= anqp_add_hex(pos
, end
, "anqp_venue_name",
3512 pos
= anqp_add_hex(pos
, end
, "anqp_network_auth_type",
3513 anqp
->network_auth_type
);
3514 pos
= anqp_add_hex(pos
, end
, "anqp_roaming_consortium",
3515 anqp
->roaming_consortium
);
3516 pos
= anqp_add_hex(pos
, end
, "anqp_ip_addr_type_availability",
3517 anqp
->ip_addr_type_availability
);
3518 pos
= anqp_add_hex(pos
, end
, "anqp_nai_realm",
3520 pos
= anqp_add_hex(pos
, end
, "anqp_3gpp", anqp
->anqp_3gpp
);
3521 pos
= anqp_add_hex(pos
, end
, "anqp_domain_name",
3524 pos
= anqp_add_hex(pos
, end
, "hs20_operator_friendly_name",
3525 anqp
->hs20_operator_friendly_name
);
3526 pos
= anqp_add_hex(pos
, end
, "hs20_wan_metrics",
3527 anqp
->hs20_wan_metrics
);
3528 pos
= anqp_add_hex(pos
, end
, "hs20_connection_capability",
3529 anqp
->hs20_connection_capability
);
3530 #endif /* CONFIG_HS20 */
3532 #endif /* CONFIG_INTERWORKING */
3534 if (mask
& WPA_BSS_MASK_DELIM
) {
3535 ret
= os_snprintf(pos
, end
- pos
, "====\n");
3536 if (ret
< 0 || ret
>= end
- pos
)
3545 static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant
*wpa_s
,
3546 const char *cmd
, char *buf
,
3551 struct wpa_bss
*bss
;
3552 struct wpa_bss
*bsslast
= NULL
;
3553 struct dl_list
*next
;
3557 unsigned long mask
= WPA_BSS_MASK_ALL
;
3559 if (os_strncmp(cmd
, "RANGE=", 6) == 0) {
3560 if (os_strncmp(cmd
+ 6, "ALL", 3) == 0) {
3561 bss
= dl_list_first(&wpa_s
->bss_id
, struct wpa_bss
,
3563 bsslast
= dl_list_last(&wpa_s
->bss_id
, struct wpa_bss
,
3565 } else { /* N1-N2 */
3566 unsigned int id1
, id2
;
3568 if ((ctmp
= os_strchr(cmd
+ 6, '-')) == NULL
) {
3569 wpa_printf(MSG_INFO
, "Wrong BSS range "
3574 if (*(cmd
+ 6) == '-')
3577 id1
= atoi(cmd
+ 6);
3579 if (*ctmp
>= '0' && *ctmp
<= '9')
3582 id2
= (unsigned int) -1;
3583 bss
= wpa_bss_get_id_range(wpa_s
, id1
, id2
);
3584 if (id2
== (unsigned int) -1)
3585 bsslast
= dl_list_last(&wpa_s
->bss_id
,
3589 bsslast
= wpa_bss_get_id(wpa_s
, id2
);
3590 if (bsslast
== NULL
&& bss
&& id2
> id1
) {
3591 struct wpa_bss
*tmp
= bss
;
3593 next
= tmp
->list_id
.next
;
3594 if (next
== &wpa_s
->bss_id
)
3596 tmp
= dl_list_entry(
3597 next
, struct wpa_bss
,
3606 } else if (os_strncmp(cmd
, "FIRST", 5) == 0)
3607 bss
= dl_list_first(&wpa_s
->bss_id
, struct wpa_bss
, list_id
);
3608 else if (os_strncmp(cmd
, "LAST", 4) == 0)
3609 bss
= dl_list_last(&wpa_s
->bss_id
, struct wpa_bss
, list_id
);
3610 else if (os_strncmp(cmd
, "ID-", 3) == 0) {
3612 bss
= wpa_bss_get_id(wpa_s
, i
);
3613 } else if (os_strncmp(cmd
, "NEXT-", 5) == 0) {
3615 bss
= wpa_bss_get_id(wpa_s
, i
);
3617 next
= bss
->list_id
.next
;
3618 if (next
== &wpa_s
->bss_id
)
3621 bss
= dl_list_entry(next
, struct wpa_bss
,
3625 } else if (os_strncmp(cmd
, "p2p_dev_addr=", 13) == 0) {
3626 if (hwaddr_aton(cmd
+ 13, bssid
) == 0)
3627 bss
= wpa_bss_get_p2p_dev_addr(wpa_s
, bssid
);
3630 #endif /* CONFIG_P2P */
3631 } else if (hwaddr_aton(cmd
, bssid
) == 0)
3632 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
3634 struct wpa_bss
*tmp
;
3637 dl_list_for_each(tmp
, &wpa_s
->bss_id
, struct wpa_bss
, list_id
)
3646 if ((ctmp
= os_strstr(cmd
, "MASK=")) != NULL
) {
3647 mask
= strtoul(ctmp
+ 5, NULL
, 0x10);
3649 mask
= WPA_BSS_MASK_ALL
;
3655 if (bsslast
== NULL
)
3658 len
= print_bss_info(wpa_s
, bss
, mask
, buf
, buflen
);
3662 if (bss
== bsslast
) {
3663 if ((mask
& WPA_BSS_MASK_DELIM
) && len
&&
3664 (bss
== dl_list_last(&wpa_s
->bss_id
,
3665 struct wpa_bss
, list_id
)))
3666 os_snprintf(buf
- 5, 5, "####\n");
3669 next
= bss
->list_id
.next
;
3670 if (next
== &wpa_s
->bss_id
)
3672 bss
= dl_list_entry(next
, struct wpa_bss
, list_id
);
3673 } while (bss
&& len
);
3679 static int wpa_supplicant_ctrl_iface_ap_scan(
3680 struct wpa_supplicant
*wpa_s
, char *cmd
)
3682 int ap_scan
= atoi(cmd
);
3683 return wpa_supplicant_set_ap_scan(wpa_s
, ap_scan
);
3687 static int wpa_supplicant_ctrl_iface_scan_interval(
3688 struct wpa_supplicant
*wpa_s
, char *cmd
)
3690 int scan_int
= atoi(cmd
);
3691 return wpa_supplicant_set_scan_interval(wpa_s
, scan_int
);
3695 static int wpa_supplicant_ctrl_iface_bss_expire_age(
3696 struct wpa_supplicant
*wpa_s
, char *cmd
)
3698 int expire_age
= atoi(cmd
);
3699 return wpa_supplicant_set_bss_expiration_age(wpa_s
, expire_age
);
3703 static int wpa_supplicant_ctrl_iface_bss_expire_count(
3704 struct wpa_supplicant
*wpa_s
, char *cmd
)
3706 int expire_count
= atoi(cmd
);
3707 return wpa_supplicant_set_bss_expiration_count(wpa_s
, expire_count
);
3711 static int wpa_supplicant_ctrl_iface_bss_flush(
3712 struct wpa_supplicant
*wpa_s
, char *cmd
)
3714 int flush_age
= atoi(cmd
);
3717 wpa_bss_flush(wpa_s
);
3719 wpa_bss_flush_by_age(wpa_s
, flush_age
);
3724 static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant
*wpa_s
)
3726 wpa_printf(MSG_DEBUG
, "Dropping SA without deauthentication");
3727 /* MLME-DELETEKEYS.request */
3728 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 0, 0, NULL
, 0, NULL
, 0);
3729 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 1, 0, NULL
, 0, NULL
, 0);
3730 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 2, 0, NULL
, 0, NULL
, 0);
3731 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 3, 0, NULL
, 0, NULL
, 0);
3732 #ifdef CONFIG_IEEE80211W
3733 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 4, 0, NULL
, 0, NULL
, 0);
3734 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 5, 0, NULL
, 0, NULL
, 0);
3735 #endif /* CONFIG_IEEE80211W */
3737 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, wpa_s
->bssid
, 0, 0, NULL
, 0, NULL
,
3739 /* MLME-SETPROTECTION.request(None) */
3740 wpa_drv_mlme_setprotection(wpa_s
, wpa_s
->bssid
,
3741 MLME_SETPROTECTION_PROTECT_TYPE_NONE
,
3742 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE
);
3743 wpa_sm_drop_sa(wpa_s
->wpa
);
3747 static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant
*wpa_s
,
3750 #ifdef CONFIG_NO_SCAN_PROCESSING
3752 #else /* CONFIG_NO_SCAN_PROCESSING */
3754 struct wpa_bss
*bss
;
3755 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
3757 if (hwaddr_aton(addr
, bssid
)) {
3758 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: invalid "
3759 "address '%s'", addr
);
3763 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM " MACSTR
, MAC2STR(bssid
));
3766 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: No network "
3767 "configuration known for the target AP");
3771 bss
= wpa_bss_get(wpa_s
, bssid
, ssid
->ssid
, ssid
->ssid_len
);
3773 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: Target AP not found "
3779 * TODO: Find best network configuration block from configuration to
3780 * allow roaming to other networks
3783 wpa_s
->reassociate
= 1;
3784 wpa_supplicant_connect(wpa_s
, bss
, ssid
);
3787 #endif /* CONFIG_NO_SCAN_PROCESSING */
3792 static int p2p_ctrl_find(struct wpa_supplicant
*wpa_s
, char *cmd
)
3794 unsigned int timeout
= atoi(cmd
);
3795 enum p2p_discovery_type type
= P2P_FIND_START_WITH_FULL
;
3796 u8 dev_id
[ETH_ALEN
], *_dev_id
= NULL
;
3797 u8 dev_type
[WPS_DEV_TYPE_LEN
], *_dev_type
= NULL
;
3799 unsigned int search_delay
;
3801 if (os_strstr(cmd
, "type=social"))
3802 type
= P2P_FIND_ONLY_SOCIAL
;
3803 else if (os_strstr(cmd
, "type=progressive"))
3804 type
= P2P_FIND_PROGRESSIVE
;
3806 pos
= os_strstr(cmd
, "dev_id=");
3809 if (hwaddr_aton(pos
, dev_id
))
3814 pos
= os_strstr(cmd
, "dev_type=");
3817 if (wps_dev_type_str2bin(pos
, dev_type
) < 0)
3819 _dev_type
= dev_type
;
3822 pos
= os_strstr(cmd
, "delay=");
3825 search_delay
= atoi(pos
);
3827 search_delay
= wpas_p2p_search_delay(wpa_s
);
3829 return wpas_p2p_find(wpa_s
, timeout
, type
, _dev_type
!= NULL
, _dev_type
,
3830 _dev_id
, search_delay
);
3834 static int p2p_ctrl_connect(struct wpa_supplicant
*wpa_s
, char *cmd
,
3835 char *buf
, size_t buflen
)
3840 enum p2p_wps_method wps_method
;
3843 int persistent_group
, persistent_id
= -1;
3852 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad]
3853 * [persistent|persistent=<network id>]
3854 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
3857 if (hwaddr_aton(cmd
, addr
))
3865 persistent_group
= os_strstr(pos
, " persistent") != NULL
;
3866 pos2
= os_strstr(pos
, " persistent=");
3868 struct wpa_ssid
*ssid
;
3869 persistent_id
= atoi(pos2
+ 12);
3870 ssid
= wpa_config_get_network(wpa_s
->conf
, persistent_id
);
3871 if (ssid
== NULL
|| ssid
->disabled
!= 2 ||
3872 ssid
->mode
!= WPAS_MODE_P2P_GO
) {
3873 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3874 "SSID id=%d for persistent P2P group (GO)",
3879 join
= os_strstr(pos
, " join") != NULL
;
3880 auth
= os_strstr(pos
, " auth") != NULL
;
3881 automatic
= os_strstr(pos
, " auto") != NULL
;
3882 pd
= os_strstr(pos
, " provdisc") != NULL
;
3883 vht
= (os_strstr(cmd
, " vht") != NULL
) || wpa_s
->conf
->p2p_go_vht
;
3884 ht40
= (os_strstr(cmd
, " ht40") != NULL
) || wpa_s
->conf
->p2p_go_ht40
||
3887 pos2
= os_strstr(pos
, " go_intent=");
3890 go_intent
= atoi(pos2
);
3891 if (go_intent
< 0 || go_intent
> 15)
3895 pos2
= os_strstr(pos
, " freq=");
3903 if (os_strncmp(pos
, "pin", 3) == 0) {
3904 /* Request random PIN (to be displayed) and enable the PIN */
3905 wps_method
= WPS_PIN_DISPLAY
;
3906 } else if (os_strncmp(pos
, "pbc", 3) == 0) {
3907 wps_method
= WPS_PBC
;
3910 pos
= os_strchr(pin
, ' ');
3911 wps_method
= WPS_PIN_KEYPAD
;
3914 if (os_strncmp(pos
, "display", 7) == 0)
3915 wps_method
= WPS_PIN_DISPLAY
;
3917 if (!wps_pin_str_valid(pin
)) {
3918 os_memcpy(buf
, "FAIL-INVALID-PIN\n", 17);
3923 new_pin
= wpas_p2p_connect(wpa_s
, addr
, pin
, wps_method
,
3924 persistent_group
, automatic
, join
,
3925 auth
, go_intent
, freq
, persistent_id
, pd
,
3927 if (new_pin
== -2) {
3928 os_memcpy(buf
, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
3931 if (new_pin
== -3) {
3932 os_memcpy(buf
, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
3937 if (wps_method
== WPS_PIN_DISPLAY
&& pin
== NULL
) {
3938 ret
= os_snprintf(buf
, buflen
, "%08d", new_pin
);
3939 if (ret
< 0 || (size_t) ret
>= buflen
)
3944 os_memcpy(buf
, "OK\n", 3);
3949 static int p2p_ctrl_listen(struct wpa_supplicant
*wpa_s
, char *cmd
)
3951 unsigned int timeout
= atoi(cmd
);
3952 return wpas_p2p_listen(wpa_s
, timeout
);
3956 static int p2p_ctrl_prov_disc(struct wpa_supplicant
*wpa_s
, char *cmd
)
3960 enum wpas_p2p_prov_disc_use use
= WPAS_P2P_PD_FOR_GO_NEG
;
3962 /* <addr> <config method> [join|auto] */
3964 if (hwaddr_aton(cmd
, addr
))
3972 if (os_strstr(pos
, " join") != NULL
)
3973 use
= WPAS_P2P_PD_FOR_JOIN
;
3974 else if (os_strstr(pos
, " auto") != NULL
)
3975 use
= WPAS_P2P_PD_AUTO
;
3977 return wpas_p2p_prov_disc(wpa_s
, addr
, pos
, use
);
3981 static int p2p_get_passphrase(struct wpa_supplicant
*wpa_s
, char *buf
,
3984 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
3986 if (ssid
== NULL
|| ssid
->mode
!= WPAS_MODE_P2P_GO
||
3987 ssid
->passphrase
== NULL
)
3990 os_strlcpy(buf
, ssid
->passphrase
, buflen
);
3991 return os_strlen(buf
);
3995 static int p2p_ctrl_serv_disc_req(struct wpa_supplicant
*wpa_s
, char *cmd
,
3996 char *buf
, size_t buflen
)
4000 u8 dst_buf
[ETH_ALEN
], *dst
;
4001 struct wpabuf
*tlvs
;
4005 if (hwaddr_aton(cmd
, dst_buf
))
4008 if (dst
[0] == 0 && dst
[1] == 0 && dst
[2] == 0 &&
4009 dst
[3] == 0 && dst
[4] == 0 && dst
[5] == 0)
4016 if (os_strncmp(pos
, "upnp ", 5) == 0) {
4019 if (hexstr2bin(pos
, &version
, 1) < 0)
4025 ref
= wpas_p2p_sd_request_upnp(wpa_s
, dst
, version
, pos
);
4026 #ifdef CONFIG_WIFI_DISPLAY
4027 } else if (os_strncmp(pos
, "wifi-display ", 13) == 0) {
4028 ref
= wpas_p2p_sd_request_wifi_display(wpa_s
, dst
, pos
+ 13);
4029 #endif /* CONFIG_WIFI_DISPLAY */
4031 len
= os_strlen(pos
);
4035 tlvs
= wpabuf_alloc(len
);
4038 if (hexstr2bin(pos
, wpabuf_put(tlvs
, len
), len
) < 0) {
4043 ref
= wpas_p2p_sd_request(wpa_s
, dst
, tlvs
);
4048 res
= os_snprintf(buf
, buflen
, "%llx", (long long unsigned) ref
);
4049 if (res
< 0 || (unsigned) res
>= buflen
)
4055 static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant
*wpa_s
,
4058 long long unsigned val
;
4060 if (sscanf(cmd
, "%llx", &val
) != 1)
4063 return wpas_p2p_sd_cancel_request(wpa_s
, req
);
4067 static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant
*wpa_s
, char *cmd
)
4072 struct wpabuf
*resp_tlvs
;
4076 pos
= os_strchr(cmd
, ' ');
4084 if (hwaddr_aton(pos
, dst
))
4091 pos2
= os_strchr(pos
, ' ');
4095 dialog_token
= atoi(pos
);
4097 len
= os_strlen(pos2
);
4101 resp_tlvs
= wpabuf_alloc(len
);
4102 if (resp_tlvs
== NULL
)
4104 if (hexstr2bin(pos2
, wpabuf_put(resp_tlvs
, len
), len
) < 0) {
4105 wpabuf_free(resp_tlvs
);
4109 wpas_p2p_sd_response(wpa_s
, freq
, dst
, dialog_token
, resp_tlvs
);
4110 wpabuf_free(resp_tlvs
);
4115 static int p2p_ctrl_serv_disc_external(struct wpa_supplicant
*wpa_s
,
4118 if (os_strcmp(cmd
, "0") && os_strcmp(cmd
, "1"))
4120 wpa_s
->p2p_sd_over_ctrl_iface
= atoi(cmd
);
4125 static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant
*wpa_s
,
4130 struct wpabuf
*query
, *resp
;
4132 pos
= os_strchr(cmd
, ' ');
4137 len
= os_strlen(cmd
);
4141 query
= wpabuf_alloc(len
);
4144 if (hexstr2bin(cmd
, wpabuf_put(query
, len
), len
) < 0) {
4149 len
= os_strlen(pos
);
4155 resp
= wpabuf_alloc(len
);
4160 if (hexstr2bin(pos
, wpabuf_put(resp
, len
), len
) < 0) {
4166 if (wpas_p2p_service_add_bonjour(wpa_s
, query
, resp
) < 0) {
4175 static int p2p_ctrl_service_add_upnp(struct wpa_supplicant
*wpa_s
, char *cmd
)
4180 pos
= os_strchr(cmd
, ' ');
4185 if (hexstr2bin(cmd
, &version
, 1) < 0)
4188 return wpas_p2p_service_add_upnp(wpa_s
, version
, pos
);
4192 static int p2p_ctrl_service_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
4196 pos
= os_strchr(cmd
, ' ');
4201 if (os_strcmp(cmd
, "bonjour") == 0)
4202 return p2p_ctrl_service_add_bonjour(wpa_s
, pos
);
4203 if (os_strcmp(cmd
, "upnp") == 0)
4204 return p2p_ctrl_service_add_upnp(wpa_s
, pos
);
4205 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
4210 static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant
*wpa_s
,
4214 struct wpabuf
*query
;
4217 len
= os_strlen(cmd
);
4221 query
= wpabuf_alloc(len
);
4224 if (hexstr2bin(cmd
, wpabuf_put(query
, len
), len
) < 0) {
4229 ret
= wpas_p2p_service_del_bonjour(wpa_s
, query
);
4235 static int p2p_ctrl_service_del_upnp(struct wpa_supplicant
*wpa_s
, char *cmd
)
4240 pos
= os_strchr(cmd
, ' ');
4245 if (hexstr2bin(cmd
, &version
, 1) < 0)
4248 return wpas_p2p_service_del_upnp(wpa_s
, version
, pos
);
4252 static int p2p_ctrl_service_del(struct wpa_supplicant
*wpa_s
, char *cmd
)
4256 pos
= os_strchr(cmd
, ' ');
4261 if (os_strcmp(cmd
, "bonjour") == 0)
4262 return p2p_ctrl_service_del_bonjour(wpa_s
, pos
);
4263 if (os_strcmp(cmd
, "upnp") == 0)
4264 return p2p_ctrl_service_del_upnp(wpa_s
, pos
);
4265 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
4270 static int p2p_ctrl_reject(struct wpa_supplicant
*wpa_s
, char *cmd
)
4276 if (hwaddr_aton(cmd
, addr
))
4279 return wpas_p2p_reject(wpa_s
, addr
);
4283 static int p2p_ctrl_invite_persistent(struct wpa_supplicant
*wpa_s
, char *cmd
)
4287 struct wpa_ssid
*ssid
;
4288 u8
*_peer
= NULL
, peer
[ETH_ALEN
];
4289 int freq
= 0, pref_freq
= 0;
4293 pos
= os_strstr(cmd
, " peer=");
4296 if (hwaddr_aton(pos
, peer
))
4300 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
4301 if (ssid
== NULL
|| ssid
->disabled
!= 2) {
4302 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
4303 "for persistent P2P group",
4308 pos
= os_strstr(cmd
, " freq=");
4316 pos
= os_strstr(cmd
, " pref=");
4319 pref_freq
= atoi(pos
);
4324 vht
= (os_strstr(cmd
, " vht") != NULL
) || wpa_s
->conf
->p2p_go_vht
;
4325 ht40
= (os_strstr(cmd
, " ht40") != NULL
) || wpa_s
->conf
->p2p_go_ht40
||
4328 return wpas_p2p_invite(wpa_s
, _peer
, ssid
, NULL
, freq
, ht40
, vht
,
4333 static int p2p_ctrl_invite_group(struct wpa_supplicant
*wpa_s
, char *cmd
)
4336 u8 peer
[ETH_ALEN
], go_dev_addr
[ETH_ALEN
], *go_dev
= NULL
;
4338 pos
= os_strstr(cmd
, " peer=");
4344 if (hwaddr_aton(pos
, peer
)) {
4345 wpa_printf(MSG_DEBUG
, "P2P: Invalid MAC address '%s'", pos
);
4349 pos
= os_strstr(pos
, " go_dev_addr=");
4352 if (hwaddr_aton(pos
, go_dev_addr
)) {
4353 wpa_printf(MSG_DEBUG
, "P2P: Invalid MAC address '%s'",
4357 go_dev
= go_dev_addr
;
4360 return wpas_p2p_invite_group(wpa_s
, cmd
, peer
, go_dev
);
4364 static int p2p_ctrl_invite(struct wpa_supplicant
*wpa_s
, char *cmd
)
4366 if (os_strncmp(cmd
, "persistent=", 11) == 0)
4367 return p2p_ctrl_invite_persistent(wpa_s
, cmd
+ 11);
4368 if (os_strncmp(cmd
, "group=", 6) == 0)
4369 return p2p_ctrl_invite_group(wpa_s
, cmd
+ 6);
4375 static int p2p_ctrl_group_add_persistent(struct wpa_supplicant
*wpa_s
,
4376 char *cmd
, int freq
, int ht40
,
4380 struct wpa_ssid
*ssid
;
4383 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
4384 if (ssid
== NULL
|| ssid
->disabled
!= 2) {
4385 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
4386 "for persistent P2P group",
4391 return wpas_p2p_group_add_persistent(wpa_s
, ssid
, 0, freq
, ht40
, vht
,
4396 static int p2p_ctrl_group_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
4398 int freq
= 0, ht40
, vht
;
4401 pos
= os_strstr(cmd
, "freq=");
4403 freq
= atoi(pos
+ 5);
4405 vht
= (os_strstr(cmd
, "vht") != NULL
) || wpa_s
->conf
->p2p_go_vht
;
4406 ht40
= (os_strstr(cmd
, "ht40") != NULL
) || wpa_s
->conf
->p2p_go_ht40
||
4409 if (os_strncmp(cmd
, "persistent=", 11) == 0)
4410 return p2p_ctrl_group_add_persistent(wpa_s
, cmd
+ 11, freq
,
4412 if (os_strcmp(cmd
, "persistent") == 0 ||
4413 os_strncmp(cmd
, "persistent ", 11) == 0)
4414 return wpas_p2p_group_add(wpa_s
, 1, freq
, ht40
, vht
);
4415 if (os_strncmp(cmd
, "freq=", 5) == 0)
4416 return wpas_p2p_group_add(wpa_s
, 0, freq
, ht40
, vht
);
4418 return wpas_p2p_group_add(wpa_s
, 0, freq
, ht40
, vht
);
4420 wpa_printf(MSG_DEBUG
, "CTRL: Invalid P2P_GROUP_ADD parameters '%s'",
4426 static int p2p_ctrl_peer(struct wpa_supplicant
*wpa_s
, char *cmd
,
4427 char *buf
, size_t buflen
)
4429 u8 addr
[ETH_ALEN
], *addr_ptr
;
4431 const struct p2p_peer_info
*info
;
4433 char devtype
[WPS_DEV_TYPE_BUFSIZE
];
4434 struct wpa_ssid
*ssid
;
4437 if (!wpa_s
->global
->p2p
)
4440 if (os_strcmp(cmd
, "FIRST") == 0) {
4443 } else if (os_strncmp(cmd
, "NEXT-", 5) == 0) {
4444 if (hwaddr_aton(cmd
+ 5, addr
) < 0)
4449 if (hwaddr_aton(cmd
, addr
) < 0)
4455 info
= p2p_get_peer_info(wpa_s
->global
->p2p
, addr_ptr
, next
);
4462 res
= os_snprintf(pos
, end
- pos
, MACSTR
"\n"
4468 "serial_number=%s\n"
4469 "config_methods=0x%x\n"
4471 "group_capab=0x%x\n"
4473 MAC2STR(info
->p2p_device_addr
),
4474 wps_dev_type_bin2str(info
->pri_dev_type
,
4475 devtype
, sizeof(devtype
)),
4480 info
->serial_number
,
4481 info
->config_methods
,
4485 if (res
< 0 || res
>= end
- pos
)
4489 for (i
= 0; i
< info
->wps_sec_dev_type_list_len
/ WPS_DEV_TYPE_LEN
; i
++)
4492 t
= &info
->wps_sec_dev_type_list
[i
* WPS_DEV_TYPE_LEN
];
4493 res
= os_snprintf(pos
, end
- pos
, "sec_dev_type=%s\n",
4494 wps_dev_type_bin2str(t
, devtype
,
4496 if (res
< 0 || res
>= end
- pos
)
4501 ssid
= wpas_p2p_get_persistent(wpa_s
, info
->p2p_device_addr
, NULL
, 0);
4503 res
= os_snprintf(pos
, end
- pos
, "persistent=%d\n", ssid
->id
);
4504 if (res
< 0 || res
>= end
- pos
)
4509 res
= p2p_get_peer_info_txt(info
, pos
, end
- pos
);
4518 static int p2p_ctrl_disallow_freq(struct wpa_supplicant
*wpa_s
,
4523 if (wpa_s
->global
->p2p
== NULL
)
4526 if (freq_range_list_parse(&wpa_s
->global
->p2p_disallow_freq
, param
) < 0)
4529 for (i
= 0; i
< wpa_s
->global
->p2p_disallow_freq
.num
; i
++) {
4530 struct wpa_freq_range
*freq
;
4531 freq
= &wpa_s
->global
->p2p_disallow_freq
.range
[i
];
4532 wpa_printf(MSG_DEBUG
, "P2P: Disallowed frequency range %u-%u",
4533 freq
->min
, freq
->max
);
4536 wpas_p2p_update_channel_list(wpa_s
);
4541 static int p2p_ctrl_set(struct wpa_supplicant
*wpa_s
, char *cmd
)
4545 if (wpa_s
->global
->p2p
== NULL
)
4548 param
= os_strchr(cmd
, ' ');
4553 if (os_strcmp(cmd
, "discoverability") == 0) {
4554 p2p_set_client_discoverability(wpa_s
->global
->p2p
,
4559 if (os_strcmp(cmd
, "managed") == 0) {
4560 p2p_set_managed_oper(wpa_s
->global
->p2p
, atoi(param
));
4564 if (os_strcmp(cmd
, "listen_channel") == 0) {
4565 return p2p_set_listen_channel(wpa_s
->global
->p2p
, 81,
4569 if (os_strcmp(cmd
, "ssid_postfix") == 0) {
4570 return p2p_set_ssid_postfix(wpa_s
->global
->p2p
, (u8
*) param
,
4574 if (os_strcmp(cmd
, "noa") == 0) {
4576 int count
, start
, duration
;
4577 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
4578 count
= atoi(param
);
4579 pos
= os_strchr(param
, ',');
4584 pos
= os_strchr(pos
, ',');
4588 duration
= atoi(pos
);
4589 if (count
< 0 || count
> 255 || start
< 0 || duration
< 0)
4591 if (count
== 0 && duration
> 0)
4593 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
4594 "start=%d duration=%d", count
, start
, duration
);
4595 return wpas_p2p_set_noa(wpa_s
, count
, start
, duration
);
4598 if (os_strcmp(cmd
, "ps") == 0)
4599 return wpa_drv_set_p2p_powersave(wpa_s
, atoi(param
), -1, -1);
4601 if (os_strcmp(cmd
, "oppps") == 0)
4602 return wpa_drv_set_p2p_powersave(wpa_s
, -1, atoi(param
), -1);
4604 if (os_strcmp(cmd
, "ctwindow") == 0)
4605 return wpa_drv_set_p2p_powersave(wpa_s
, -1, -1, atoi(param
));
4607 if (os_strcmp(cmd
, "disabled") == 0) {
4608 wpa_s
->global
->p2p_disabled
= atoi(param
);
4609 wpa_printf(MSG_DEBUG
, "P2P functionality %s",
4610 wpa_s
->global
->p2p_disabled
?
4611 "disabled" : "enabled");
4612 if (wpa_s
->global
->p2p_disabled
) {
4613 wpas_p2p_stop_find(wpa_s
);
4614 os_memset(wpa_s
->p2p_auth_invite
, 0, ETH_ALEN
);
4615 p2p_flush(wpa_s
->global
->p2p
);
4620 if (os_strcmp(cmd
, "conc_pref") == 0) {
4621 if (os_strcmp(param
, "sta") == 0)
4622 wpa_s
->global
->conc_pref
= WPA_CONC_PREF_STA
;
4623 else if (os_strcmp(param
, "p2p") == 0)
4624 wpa_s
->global
->conc_pref
= WPA_CONC_PREF_P2P
;
4626 wpa_printf(MSG_INFO
, "Invalid conc_pref value");
4629 wpa_printf(MSG_DEBUG
, "Single channel concurrency preference: "
4634 if (os_strcmp(cmd
, "force_long_sd") == 0) {
4635 wpa_s
->force_long_sd
= atoi(param
);
4639 if (os_strcmp(cmd
, "peer_filter") == 0) {
4641 if (hwaddr_aton(param
, addr
))
4643 p2p_set_peer_filter(wpa_s
->global
->p2p
, addr
);
4647 if (os_strcmp(cmd
, "cross_connect") == 0)
4648 return wpas_p2p_set_cross_connect(wpa_s
, atoi(param
));
4650 if (os_strcmp(cmd
, "go_apsd") == 0) {
4651 if (os_strcmp(param
, "disable") == 0)
4652 wpa_s
->set_ap_uapsd
= 0;
4654 wpa_s
->set_ap_uapsd
= 1;
4655 wpa_s
->ap_uapsd
= atoi(param
);
4660 if (os_strcmp(cmd
, "client_apsd") == 0) {
4661 if (os_strcmp(param
, "disable") == 0)
4662 wpa_s
->set_sta_uapsd
= 0;
4666 /* format: BE,BK,VI,VO;max SP Length */
4668 pos
= os_strchr(param
, ',');
4673 pos
= os_strchr(pos
, ',');
4678 pos
= os_strchr(pos
, ',');
4683 /* ignore max SP Length for now */
4685 wpa_s
->set_sta_uapsd
= 1;
4686 wpa_s
->sta_uapsd
= 0;
4688 wpa_s
->sta_uapsd
|= BIT(0);
4690 wpa_s
->sta_uapsd
|= BIT(1);
4692 wpa_s
->sta_uapsd
|= BIT(2);
4694 wpa_s
->sta_uapsd
|= BIT(3);
4699 if (os_strcmp(cmd
, "disallow_freq") == 0)
4700 return p2p_ctrl_disallow_freq(wpa_s
, param
);
4702 if (os_strcmp(cmd
, "disc_int") == 0) {
4703 int min_disc_int
, max_disc_int
, max_disc_tu
;
4708 min_disc_int
= atoi(pos
);
4709 pos
= os_strchr(pos
, ' ');
4714 max_disc_int
= atoi(pos
);
4715 pos
= os_strchr(pos
, ' ');
4720 max_disc_tu
= atoi(pos
);
4722 return p2p_set_disc_int(wpa_s
->global
->p2p
, min_disc_int
,
4723 max_disc_int
, max_disc_tu
);
4726 if (os_strcmp(cmd
, "per_sta_psk") == 0) {
4727 wpa_s
->global
->p2p_per_sta_psk
= !!atoi(param
);
4731 #ifdef CONFIG_WPS_NFC
4732 if (os_strcmp(cmd
, "nfc_tag") == 0)
4733 return wpas_p2p_nfc_tag_enabled(wpa_s
, !!atoi(param
));
4734 #endif /* CONFIG_WPS_NFC */
4736 if (os_strcmp(cmd
, "disable_ip_addr_req") == 0) {
4737 wpa_s
->p2p_disable_ip_addr_req
= !!atoi(param
);
4741 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
4748 static void p2p_ctrl_flush(struct wpa_supplicant
*wpa_s
)
4750 os_memset(wpa_s
->p2p_auth_invite
, 0, ETH_ALEN
);
4751 wpa_s
->force_long_sd
= 0;
4752 if (wpa_s
->global
->p2p
)
4753 p2p_flush(wpa_s
->global
->p2p
);
4757 static int p2p_ctrl_presence_req(struct wpa_supplicant
*wpa_s
, char *cmd
)
4760 unsigned int dur1
= 0, int1
= 0, dur2
= 0, int2
= 0;
4763 pos
= os_strchr(cmd
, ' ');
4769 pos2
= os_strchr(pos
, ' ');
4777 pos
= os_strchr(pos2
, ' ');
4785 return wpas_p2p_presence_req(wpa_s
, dur1
, int1
, dur2
, int2
);
4789 static int p2p_ctrl_ext_listen(struct wpa_supplicant
*wpa_s
, char *cmd
)
4792 unsigned int period
= 0, interval
= 0;
4795 pos
= os_strchr(cmd
, ' ');
4800 interval
= atoi(pos
);
4803 return wpas_p2p_ext_listen(wpa_s
, period
, interval
);
4807 static int p2p_ctrl_remove_client(struct wpa_supplicant
*wpa_s
, const char *cmd
)
4814 if (os_strncmp(pos
, "iface=", 6) == 0) {
4818 if (hwaddr_aton(pos
, peer
))
4821 wpas_p2p_remove_client(wpa_s
, peer
, iface_addr
);
4825 #endif /* CONFIG_P2P */
4828 static int * freq_range_to_channel_list(struct wpa_supplicant
*wpa_s
, char *val
)
4830 struct wpa_freq_range_list ranges
;
4832 struct hostapd_hw_modes
*mode
;
4835 if (wpa_s
->hw
.modes
== NULL
)
4838 os_memset(&ranges
, 0, sizeof(ranges
));
4839 if (freq_range_list_parse(&ranges
, val
) < 0)
4842 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
4845 mode
= &wpa_s
->hw
.modes
[i
];
4846 for (j
= 0; j
< mode
->num_channels
; j
++) {
4849 if (mode
->channels
[j
].flag
& HOSTAPD_CHAN_DISABLED
)
4852 freq
= mode
->channels
[j
].freq
;
4853 if (!freq_range_list_includes(&ranges
, freq
))
4856 int_array_add_unique(&freqs
, freq
);
4860 os_free(ranges
.range
);
4865 #ifdef CONFIG_INTERWORKING
4867 static int ctrl_interworking_select(struct wpa_supplicant
*wpa_s
, char *param
)
4875 auto_sel
= os_strstr(param
, "auto") != NULL
;
4877 pos
= os_strstr(param
, "freq=");
4879 freqs
= freq_range_to_channel_list(wpa_s
, pos
+ 5);
4886 return interworking_select(wpa_s
, auto_sel
, freqs
);
4890 static int ctrl_interworking_connect(struct wpa_supplicant
*wpa_s
, char *dst
)
4893 struct wpa_bss
*bss
;
4895 if (hwaddr_aton(dst
, bssid
)) {
4896 wpa_printf(MSG_DEBUG
, "Invalid BSSID '%s'", dst
);
4900 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
4902 wpa_printf(MSG_DEBUG
, "Could not find BSS " MACSTR
,
4907 return interworking_connect(wpa_s
, bss
);
4911 static int get_anqp(struct wpa_supplicant
*wpa_s
, char *dst
)
4913 u8 dst_addr
[ETH_ALEN
];
4916 #define MAX_ANQP_INFO_ID 100
4917 u16 id
[MAX_ANQP_INFO_ID
];
4920 used
= hwaddr_aton2(dst
, dst_addr
);
4924 while (num_id
< MAX_ANQP_INFO_ID
) {
4925 id
[num_id
] = atoi(pos
);
4928 pos
= os_strchr(pos
+ 1, ',');
4937 return anqp_send_req(wpa_s
, dst_addr
, id
, num_id
);
4941 static int gas_request(struct wpa_supplicant
*wpa_s
, char *cmd
)
4943 u8 dst_addr
[ETH_ALEN
];
4944 struct wpabuf
*advproto
, *query
= NULL
;
4949 used
= hwaddr_aton2(cmd
, dst_addr
);
4957 /* Advertisement Protocol ID */
4958 end
= os_strchr(pos
, ' ');
4962 len
= os_strlen(pos
);
4968 advproto
= wpabuf_alloc(len
);
4969 if (advproto
== NULL
)
4971 if (hexstr2bin(pos
, wpabuf_put(advproto
, len
), len
) < 0)
4975 /* Optional Query Request */
4980 len
= os_strlen(pos
);
4987 query
= wpabuf_alloc(len
);
4990 if (hexstr2bin(pos
, wpabuf_put(query
, len
), len
) < 0)
4995 ret
= gas_send_request(wpa_s
, dst_addr
, advproto
, query
);
4998 wpabuf_free(advproto
);
5005 static int gas_response_get(struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
,
5012 size_t resp_len
, start
, requested_len
;
5013 struct wpabuf
*resp
;
5016 used
= hwaddr_aton2(cmd
, addr
);
5023 dialog_token
= atoi(pos
);
5025 if (wpa_s
->last_gas_resp
&&
5026 os_memcmp(addr
, wpa_s
->last_gas_addr
, ETH_ALEN
) == 0 &&
5027 dialog_token
== wpa_s
->last_gas_dialog_token
)
5028 resp
= wpa_s
->last_gas_resp
;
5029 else if (wpa_s
->prev_gas_resp
&&
5030 os_memcmp(addr
, wpa_s
->prev_gas_addr
, ETH_ALEN
) == 0 &&
5031 dialog_token
== wpa_s
->prev_gas_dialog_token
)
5032 resp
= wpa_s
->prev_gas_resp
;
5036 resp_len
= wpabuf_len(resp
);
5038 requested_len
= resp_len
;
5040 pos
= os_strchr(pos
, ' ');
5043 if (start
> resp_len
)
5044 return os_snprintf(buf
, buflen
, "FAIL-Invalid range");
5045 pos
= os_strchr(pos
, ',');
5049 requested_len
= atoi(pos
);
5050 if (start
+ requested_len
> resp_len
)
5051 return os_snprintf(buf
, buflen
, "FAIL-Invalid range");
5054 if (requested_len
* 2 + 1 > buflen
)
5055 return os_snprintf(buf
, buflen
, "FAIL-Too long response");
5057 ret
= wpa_snprintf_hex(buf
, buflen
, wpabuf_head_u8(resp
) + start
,
5060 if (start
+ requested_len
== resp_len
) {
5062 * Free memory by dropping the response after it has been
5065 if (resp
== wpa_s
->prev_gas_resp
) {
5066 wpabuf_free(wpa_s
->prev_gas_resp
);
5067 wpa_s
->prev_gas_resp
= NULL
;
5069 wpabuf_free(wpa_s
->last_gas_resp
);
5070 wpa_s
->last_gas_resp
= NULL
;
5076 #endif /* CONFIG_INTERWORKING */
5081 static int get_hs20_anqp(struct wpa_supplicant
*wpa_s
, char *dst
)
5083 u8 dst_addr
[ETH_ALEN
];
5088 used
= hwaddr_aton2(dst
, dst_addr
);
5093 int num
= atoi(pos
);
5094 if (num
<= 0 || num
> 31)
5096 subtypes
|= BIT(num
);
5097 pos
= os_strchr(pos
+ 1, ',');
5106 return hs20_anqp_send_req(wpa_s
, dst_addr
, subtypes
, NULL
, 0);
5110 static int hs20_nai_home_realm_list(struct wpa_supplicant
*wpa_s
,
5111 const u8
*addr
, const char *realm
)
5117 rlen
= os_strlen(realm
);
5119 buf
= os_malloc(len
);
5122 buf
[0] = 1; /* NAI Home Realm Count */
5123 buf
[1] = 0; /* Formatted in accordance with RFC 4282 */
5125 os_memcpy(buf
+ 3, realm
, rlen
);
5127 ret
= hs20_anqp_send_req(wpa_s
, addr
,
5128 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY
),
5137 static int hs20_get_nai_home_realm_list(struct wpa_supplicant
*wpa_s
,
5140 struct wpa_cred
*cred
= wpa_s
->conf
->cred
;
5141 u8 dst_addr
[ETH_ALEN
];
5147 used
= hwaddr_aton2(dst
, dst_addr
);
5151 while (dst
[used
] == ' ')
5153 if (os_strncmp(dst
+ used
, "realm=", 6) == 0)
5154 return hs20_nai_home_realm_list(wpa_s
, dst_addr
,
5157 len
= os_strlen(dst
+ used
);
5159 if (len
== 0 && cred
&& cred
->realm
)
5160 return hs20_nai_home_realm_list(wpa_s
, dst_addr
, cred
->realm
);
5165 buf
= os_malloc(len
);
5168 if (hexstr2bin(dst
+ used
, buf
, len
) < 0) {
5173 ret
= hs20_anqp_send_req(wpa_s
, dst_addr
,
5174 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY
),
5181 #endif /* CONFIG_HS20 */
5184 static int wpa_supplicant_ctrl_iface_sta_autoconnect(
5185 struct wpa_supplicant
*wpa_s
, char *cmd
)
5187 wpa_s
->auto_reconnect_disabled
= atoi(cmd
) == 0 ? 1 : 0;
5192 #ifdef CONFIG_AUTOSCAN
5194 static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant
*wpa_s
,
5197 enum wpa_states state
= wpa_s
->wpa_state
;
5198 char *new_params
= NULL
;
5200 if (os_strlen(cmd
) > 0) {
5201 new_params
= os_strdup(cmd
);
5202 if (new_params
== NULL
)
5206 os_free(wpa_s
->conf
->autoscan
);
5207 wpa_s
->conf
->autoscan
= new_params
;
5209 if (wpa_s
->conf
->autoscan
== NULL
)
5210 autoscan_deinit(wpa_s
);
5211 else if (state
== WPA_DISCONNECTED
|| state
== WPA_INACTIVE
)
5212 autoscan_init(wpa_s
, 1);
5213 else if (state
== WPA_SCANNING
)
5214 wpa_supplicant_reinit_autoscan(wpa_s
);
5219 #endif /* CONFIG_AUTOSCAN */
5224 static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant
*wpa_s
, char *cmd
)
5230 struct wpabuf
*tfs_req
= NULL
;
5232 if (os_strncmp(cmd
, "enter", 5) == 0)
5234 else if (os_strncmp(cmd
, "exit", 4) == 0)
5239 pos
= os_strstr(cmd
, " interval=");
5241 intval
= atoi(pos
+ 10);
5243 pos
= os_strstr(cmd
, " tfs_req=");
5248 end
= os_strchr(pos
, ' ');
5252 len
= os_strlen(pos
);
5256 tfs_req
= wpabuf_alloc(len
);
5257 if (tfs_req
== NULL
)
5259 if (hexstr2bin(pos
, wpabuf_put(tfs_req
, len
), len
) < 0) {
5260 wpabuf_free(tfs_req
);
5265 ret
= ieee802_11_send_wnmsleep_req(wpa_s
, enter
? WNM_SLEEP_MODE_ENTER
:
5266 WNM_SLEEP_MODE_EXIT
, intval
,
5268 wpabuf_free(tfs_req
);
5274 static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant
*wpa_s
, char *cmd
)
5278 query_reason
= atoi(cmd
);
5280 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d",
5283 return wnm_send_bss_transition_mgmt_query(wpa_s
, query_reason
);
5286 #endif /* CONFIG_WNM */
5289 /* Get string representation of channel width */
5290 static const char * channel_width_name(enum chan_width width
)
5293 case CHAN_WIDTH_20_NOHT
:
5294 return "20 MHz (no HT)";
5301 case CHAN_WIDTH_80P80
:
5303 case CHAN_WIDTH_160
:
5311 static int wpa_supplicant_signal_poll(struct wpa_supplicant
*wpa_s
, char *buf
,
5314 struct wpa_signal_info si
;
5318 ret
= wpa_drv_signal_poll(wpa_s
, &si
);
5325 ret
= os_snprintf(pos
, end
- pos
, "RSSI=%d\nLINKSPEED=%d\n"
5326 "NOISE=%d\nFREQUENCY=%u\n",
5327 si
.current_signal
, si
.current_txrate
/ 1000,
5328 si
.current_noise
, si
.frequency
);
5329 if (ret
< 0 || ret
> end
- pos
)
5333 if (si
.chanwidth
!= CHAN_WIDTH_UNKNOWN
) {
5334 ret
= os_snprintf(pos
, end
- pos
, "WIDTH=%s\n",
5335 channel_width_name(si
.chanwidth
));
5336 if (ret
< 0 || ret
> end
- pos
)
5341 if (si
.center_frq1
> 0 && si
.center_frq2
> 0) {
5342 ret
= os_snprintf(pos
, end
- pos
,
5343 "CENTER_FRQ1=%d\nCENTER_FRQ2=%d\n",
5344 si
.center_frq1
, si
.center_frq2
);
5345 if (ret
< 0 || ret
> end
- pos
)
5350 if (si
.avg_signal
) {
5351 ret
= os_snprintf(pos
, end
- pos
,
5352 "AVG_RSSI=%d\n", si
.avg_signal
);
5353 if (ret
< 0 || ret
>= end
- pos
)
5362 static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant
*wpa_s
, char *buf
,
5365 struct hostap_sta_driver_data sta
;
5368 ret
= wpa_drv_pktcnt_poll(wpa_s
, &sta
);
5372 ret
= os_snprintf(buf
, buflen
, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
5373 sta
.tx_packets
, sta
.tx_retry_failed
, sta
.rx_packets
);
5374 if (ret
< 0 || (size_t) ret
> buflen
)
5381 static int wpa_supplicant_driver_cmd(struct wpa_supplicant
*wpa_s
, char *cmd
,
5382 char *buf
, size_t buflen
)
5386 ret
= wpa_drv_driver_cmd(wpa_s
, cmd
, buf
, buflen
);
5388 if (os_strncasecmp(cmd
, "COUNTRY", 7) == 0) {
5389 struct p2p_data
*p2p
= wpa_s
->global
->p2p
;
5392 country
[0] = cmd
[8];
5393 country
[1] = cmd
[9];
5395 p2p_set_country(p2p
, country
);
5398 ret
= os_snprintf(buf
, buflen
, "%s\n", "OK");
5402 #endif /* ANDROID */
5405 static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant
*wpa_s
)
5407 wpa_dbg(wpa_s
, MSG_DEBUG
, "Flush all wpa_supplicant state");
5410 wpas_p2p_stop_find(wpa_s
);
5411 p2p_ctrl_flush(wpa_s
);
5412 wpas_p2p_group_remove(wpa_s
, "*");
5413 wpas_p2p_service_flush(wpa_s
);
5414 wpa_s
->global
->p2p_disabled
= 0;
5415 wpa_s
->global
->p2p_per_sta_psk
= 0;
5416 wpa_s
->conf
->num_sec_device_types
= 0;
5417 wpa_s
->p2p_disable_ip_addr_req
= 0;
5418 #endif /* CONFIG_P2P */
5420 #ifdef CONFIG_WPS_TESTING
5421 wps_version_number
= 0x20;
5422 wps_testing_dummy_cred
= 0;
5423 wps_corrupt_pkhash
= 0;
5424 #endif /* CONFIG_WPS_TESTING */
5426 wpa_s
->wps_fragment_size
= 0;
5427 wpas_wps_cancel(wpa_s
);
5428 #endif /* CONFIG_WPS */
5429 wpa_s
->after_wps
= 0;
5430 wpa_s
->known_wps_freq
= 0;
5433 #ifdef CONFIG_TDLS_TESTING
5434 extern unsigned int tdls_testing
;
5436 #endif /* CONFIG_TDLS_TESTING */
5437 wpa_drv_tdls_oper(wpa_s
, TDLS_ENABLE
, NULL
);
5438 wpa_tdls_enable(wpa_s
->wpa
, 1);
5439 #endif /* CONFIG_TDLS */
5441 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures
, wpa_s
, NULL
);
5442 wpa_supplicant_stop_countermeasures(wpa_s
, NULL
);
5444 wpa_s
->no_keep_alive
= 0;
5446 os_free(wpa_s
->disallow_aps_bssid
);
5447 wpa_s
->disallow_aps_bssid
= NULL
;
5448 wpa_s
->disallow_aps_bssid_count
= 0;
5449 os_free(wpa_s
->disallow_aps_ssid
);
5450 wpa_s
->disallow_aps_ssid
= NULL
;
5451 wpa_s
->disallow_aps_ssid_count
= 0;
5453 wpa_s
->set_sta_uapsd
= 0;
5454 wpa_s
->sta_uapsd
= 0;
5456 wpa_drv_radio_disable(wpa_s
, 0);
5458 wpa_bss_flush(wpa_s
);
5459 wpa_blacklist_clear(wpa_s
);
5460 wpa_s
->extra_blacklist_count
= 0;
5461 wpa_supplicant_ctrl_iface_remove_network(wpa_s
, "all");
5462 wpa_supplicant_ctrl_iface_remove_cred(wpa_s
, "all");
5463 wpa_config_flush_blobs(wpa_s
->conf
);
5464 wpa_s
->conf
->auto_interworking
= 0;
5465 wpa_s
->conf
->okc
= 0;
5466 wpa_s
->conf
->pmf
= 0;
5468 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_LIFETIME
, 43200);
5469 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_REAUTH_THRESHOLD
, 70);
5470 wpa_sm_set_param(wpa_s
->wpa
, RSNA_SA_TIMEOUT
, 60);
5471 eapol_sm_notify_logoff(wpa_s
->eapol
, FALSE
);
5473 radio_remove_unstarted_work(wpa_s
, NULL
);
5477 static int wpas_ctrl_radio_work_show(struct wpa_supplicant
*wpa_s
,
5478 char *buf
, size_t buflen
)
5480 struct wpa_radio_work
*work
;
5482 struct os_reltime now
, diff
;
5487 os_get_reltime(&now
);
5489 dl_list_for_each(work
, &wpa_s
->radio
->work
, struct wpa_radio_work
, list
)
5493 os_reltime_sub(&now
, &work
->time
, &diff
);
5494 ret
= os_snprintf(pos
, end
- pos
, "%s@%s:%u:%u:%ld.%06ld\n",
5495 work
->type
, work
->wpa_s
->ifname
, work
->freq
,
5496 work
->started
, diff
.sec
, diff
.usec
);
5497 if (ret
< 0 || ret
>= end
- pos
)
5506 static void wpas_ctrl_radio_work_timeout(void *eloop_ctx
, void *timeout_ctx
)
5508 struct wpa_radio_work
*work
= eloop_ctx
;
5509 struct wpa_external_work
*ework
= work
->ctx
;
5511 wpa_dbg(work
->wpa_s
, MSG_DEBUG
,
5512 "Timing out external radio work %u (%s)",
5513 ework
->id
, work
->type
);
5514 wpa_msg(work
->wpa_s
, MSG_INFO
, EXT_RADIO_WORK_TIMEOUT
"%u", ework
->id
);
5516 radio_work_done(work
);
5520 static void wpas_ctrl_radio_work_cb(struct wpa_radio_work
*work
, int deinit
)
5522 struct wpa_external_work
*ework
= work
->ctx
;
5529 wpa_dbg(work
->wpa_s
, MSG_DEBUG
, "Starting external radio work %u (%s)",
5530 ework
->id
, ework
->type
);
5531 wpa_msg(work
->wpa_s
, MSG_INFO
, EXT_RADIO_WORK_START
"%u", ework
->id
);
5532 if (!ework
->timeout
)
5533 ework
->timeout
= 10;
5534 eloop_register_timeout(ework
->timeout
, 0, wpas_ctrl_radio_work_timeout
,
5539 static int wpas_ctrl_radio_work_add(struct wpa_supplicant
*wpa_s
, char *cmd
,
5540 char *buf
, size_t buflen
)
5542 struct wpa_external_work
*ework
;
5546 unsigned int freq
= 0;
5548 /* format: <name> [freq=<MHz>] [timeout=<seconds>] */
5550 ework
= os_zalloc(sizeof(*ework
));
5554 pos
= os_strchr(cmd
, ' ');
5556 type_len
= pos
- cmd
;
5559 pos2
= os_strstr(pos
, "freq=");
5561 freq
= atoi(pos2
+ 5);
5563 pos2
= os_strstr(pos
, "timeout=");
5565 ework
->timeout
= atoi(pos2
+ 8);
5567 type_len
= os_strlen(cmd
);
5569 if (4 + type_len
>= sizeof(ework
->type
))
5570 type_len
= sizeof(ework
->type
) - 4 - 1;
5571 os_strlcpy(ework
->type
, "ext:", sizeof(ework
->type
));
5572 os_memcpy(ework
->type
+ 4, cmd
, type_len
);
5573 ework
->type
[4 + type_len
] = '\0';
5575 wpa_s
->ext_work_id
++;
5576 if (wpa_s
->ext_work_id
== 0)
5577 wpa_s
->ext_work_id
++;
5578 ework
->id
= wpa_s
->ext_work_id
;
5580 if (radio_add_work(wpa_s
, freq
, ework
->type
, 0, wpas_ctrl_radio_work_cb
,
5586 ret
= os_snprintf(buf
, buflen
, "%u", ework
->id
);
5587 if (ret
< 0 || (size_t) ret
>= buflen
)
5593 static int wpas_ctrl_radio_work_done(struct wpa_supplicant
*wpa_s
, char *cmd
)
5595 struct wpa_radio_work
*work
;
5596 unsigned int id
= atoi(cmd
);
5598 dl_list_for_each(work
, &wpa_s
->radio
->work
, struct wpa_radio_work
, list
)
5600 struct wpa_external_work
*ework
;
5602 if (os_strncmp(work
->type
, "ext:", 4) != 0)
5605 if (id
&& ework
->id
!= id
)
5607 wpa_dbg(wpa_s
, MSG_DEBUG
,
5608 "Completed external radio work %u (%s)",
5609 ework
->id
, ework
->type
);
5610 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
, work
, NULL
);
5612 radio_work_done(work
);
5613 return 3; /* "OK\n" */
5620 static int wpas_ctrl_radio_work(struct wpa_supplicant
*wpa_s
, char *cmd
,
5621 char *buf
, size_t buflen
)
5623 if (os_strcmp(cmd
, "show") == 0)
5624 return wpas_ctrl_radio_work_show(wpa_s
, buf
, buflen
);
5625 if (os_strncmp(cmd
, "add ", 4) == 0)
5626 return wpas_ctrl_radio_work_add(wpa_s
, cmd
+ 4, buf
, buflen
);
5627 if (os_strncmp(cmd
, "done ", 5) == 0)
5628 return wpas_ctrl_radio_work_done(wpa_s
, cmd
+ 4);
5633 void wpas_ctrl_radio_work_flush(struct wpa_supplicant
*wpa_s
)
5635 struct wpa_radio_work
*work
, *tmp
;
5637 if (!wpa_s
|| !wpa_s
->radio
)
5640 dl_list_for_each_safe(work
, tmp
, &wpa_s
->radio
->work
,
5641 struct wpa_radio_work
, list
) {
5642 struct wpa_external_work
*ework
;
5644 if (os_strncmp(work
->type
, "ext:", 4) != 0)
5647 wpa_dbg(wpa_s
, MSG_DEBUG
,
5648 "Flushing %sexternal radio work %u (%s)",
5649 work
->started
? " started" : "", ework
->id
,
5652 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
,
5655 radio_work_done(work
);
5660 static void wpas_ctrl_eapol_response(void *eloop_ctx
, void *timeout_ctx
)
5662 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
5663 eapol_sm_notify_ctrl_response(wpa_s
->eapol
);
5667 static int set_scan_freqs(struct wpa_supplicant
*wpa_s
, char *val
)
5671 freqs
= freq_range_to_channel_list(wpa_s
, val
);
5675 os_free(wpa_s
->manual_scan_freqs
);
5676 wpa_s
->manual_scan_freqs
= freqs
;
5682 static void wpas_ctrl_scan(struct wpa_supplicant
*wpa_s
, char *params
,
5683 char *reply
, int reply_size
, int *reply_len
)
5687 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
5692 wpa_s
->manual_scan_passive
= 0;
5693 wpa_s
->manual_scan_use_id
= 0;
5694 wpa_s
->manual_scan_only_new
= 0;
5697 if (os_strncasecmp(params
, "TYPE=ONLY", 9) == 0)
5698 wpa_s
->scan_res_handler
= scan_only_handler
;
5700 pos
= os_strstr(params
, "freq=");
5701 if (pos
&& set_scan_freqs(wpa_s
, pos
+ 5) < 0) {
5706 pos
= os_strstr(params
, "passive=");
5708 wpa_s
->manual_scan_passive
= !!atoi(pos
+ 8);
5710 pos
= os_strstr(params
, "use_id=");
5712 wpa_s
->manual_scan_use_id
= atoi(pos
+ 7);
5714 pos
= os_strstr(params
, "only_new=1");
5716 wpa_s
->manual_scan_only_new
= 1;
5718 os_free(wpa_s
->manual_scan_freqs
);
5719 wpa_s
->manual_scan_freqs
= NULL
;
5720 if (wpa_s
->scan_res_handler
== scan_only_handler
)
5721 wpa_s
->scan_res_handler
= NULL
;
5724 if (!wpa_s
->sched_scanning
&& !wpa_s
->scanning
&&
5725 ((wpa_s
->wpa_state
<= WPA_SCANNING
) ||
5726 (wpa_s
->wpa_state
== WPA_COMPLETED
))) {
5727 wpa_s
->normal_scans
= 0;
5728 wpa_s
->scan_req
= MANUAL_SCAN_REQ
;
5729 wpa_s
->after_wps
= 0;
5730 wpa_s
->known_wps_freq
= 0;
5731 wpa_supplicant_req_scan(wpa_s
, 0, 0);
5732 if (wpa_s
->manual_scan_use_id
) {
5733 wpa_s
->manual_scan_id
++;
5734 wpa_dbg(wpa_s
, MSG_DEBUG
, "Assigned scan id %u",
5735 wpa_s
->manual_scan_id
);
5736 *reply_len
= os_snprintf(reply
, reply_size
, "%u\n",
5737 wpa_s
->manual_scan_id
);
5739 } else if (wpa_s
->sched_scanning
) {
5740 wpa_printf(MSG_DEBUG
, "Stop ongoing sched_scan to allow requested full scan to proceed");
5741 wpa_supplicant_cancel_sched_scan(wpa_s
);
5742 wpa_s
->scan_req
= MANUAL_SCAN_REQ
;
5743 wpa_supplicant_req_scan(wpa_s
, 0, 0);
5744 if (wpa_s
->manual_scan_use_id
) {
5745 wpa_s
->manual_scan_id
++;
5746 *reply_len
= os_snprintf(reply
, reply_size
, "%u\n",
5747 wpa_s
->manual_scan_id
);
5748 wpa_dbg(wpa_s
, MSG_DEBUG
, "Assigned scan id %u",
5749 wpa_s
->manual_scan_id
);
5752 wpa_printf(MSG_DEBUG
, "Ongoing scan action - reject new request");
5753 *reply_len
= os_snprintf(reply
, reply_size
, "FAIL-BUSY\n");
5758 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant
*wpa_s
,
5759 char *buf
, size_t *resp_len
)
5762 const int reply_size
= 4096;
5765 if (os_strncmp(buf
, WPA_CTRL_RSP
, os_strlen(WPA_CTRL_RSP
)) == 0 ||
5766 os_strncmp(buf
, "SET_NETWORK ", 12) == 0) {
5767 if (wpa_debug_show_keys
)
5768 wpa_dbg(wpa_s
, MSG_DEBUG
,
5769 "Control interface command '%s'", buf
);
5771 wpa_dbg(wpa_s
, MSG_DEBUG
,
5772 "Control interface command '%s [REMOVED]'",
5773 os_strncmp(buf
, WPA_CTRL_RSP
,
5774 os_strlen(WPA_CTRL_RSP
)) == 0 ?
5775 WPA_CTRL_RSP
: "SET_NETWORK");
5776 } else if (os_strncmp(buf
, "WPS_NFC_TAG_READ", 16) == 0 ||
5777 os_strncmp(buf
, "NFC_REPORT_HANDOVER", 19) == 0 ||
5778 os_strncmp(buf
, "NFC_RX_HANDOVER_SEL", 19) == 0) {
5779 wpa_hexdump_ascii_key(MSG_DEBUG
, "RX ctrl_iface",
5780 (const u8
*) buf
, os_strlen(buf
));
5782 int level
= MSG_DEBUG
;
5783 if (os_strcmp(buf
, "PING") == 0)
5784 level
= MSG_EXCESSIVE
;
5785 wpa_dbg(wpa_s
, level
, "Control interface command '%s'", buf
);
5788 reply
= os_malloc(reply_size
);
5789 if (reply
== NULL
) {
5794 os_memcpy(reply
, "OK\n", 3);
5797 if (os_strcmp(buf
, "PING") == 0) {
5798 os_memcpy(reply
, "PONG\n", 5);
5800 } else if (os_strcmp(buf
, "IFNAME") == 0) {
5801 reply_len
= os_strlen(wpa_s
->ifname
);
5802 os_memcpy(reply
, wpa_s
->ifname
, reply_len
);
5803 } else if (os_strncmp(buf
, "RELOG", 5) == 0) {
5804 if (wpa_debug_reopen_file() < 0)
5806 } else if (os_strncmp(buf
, "NOTE ", 5) == 0) {
5807 wpa_printf(MSG_INFO
, "NOTE: %s", buf
+ 5);
5808 } else if (os_strcmp(buf
, "MIB") == 0) {
5809 reply_len
= wpa_sm_get_mib(wpa_s
->wpa
, reply
, reply_size
);
5810 if (reply_len
>= 0) {
5812 res
= eapol_sm_get_mib(wpa_s
->eapol
, reply
+ reply_len
,
5813 reply_size
- reply_len
);
5819 } else if (os_strncmp(buf
, "STATUS", 6) == 0) {
5820 reply_len
= wpa_supplicant_ctrl_iface_status(
5821 wpa_s
, buf
+ 6, reply
, reply_size
);
5822 } else if (os_strcmp(buf
, "PMKSA") == 0) {
5823 reply_len
= wpa_sm_pmksa_cache_list(wpa_s
->wpa
, reply
,
5825 } else if (os_strncmp(buf
, "SET ", 4) == 0) {
5826 if (wpa_supplicant_ctrl_iface_set(wpa_s
, buf
+ 4))
5828 } else if (os_strncmp(buf
, "GET ", 4) == 0) {
5829 reply_len
= wpa_supplicant_ctrl_iface_get(wpa_s
, buf
+ 4,
5831 } else if (os_strcmp(buf
, "LOGON") == 0) {
5832 eapol_sm_notify_logoff(wpa_s
->eapol
, FALSE
);
5833 } else if (os_strcmp(buf
, "LOGOFF") == 0) {
5834 eapol_sm_notify_logoff(wpa_s
->eapol
, TRUE
);
5835 } else if (os_strcmp(buf
, "REASSOCIATE") == 0) {
5836 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
5839 wpas_request_connection(wpa_s
);
5840 } else if (os_strcmp(buf
, "RECONNECT") == 0) {
5841 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
5843 else if (wpa_s
->disconnected
)
5844 wpas_request_connection(wpa_s
);
5845 #ifdef IEEE8021X_EAPOL
5846 } else if (os_strncmp(buf
, "PREAUTH ", 8) == 0) {
5847 if (wpa_supplicant_ctrl_iface_preauth(wpa_s
, buf
+ 8))
5849 #endif /* IEEE8021X_EAPOL */
5850 #ifdef CONFIG_PEERKEY
5851 } else if (os_strncmp(buf
, "STKSTART ", 9) == 0) {
5852 if (wpa_supplicant_ctrl_iface_stkstart(wpa_s
, buf
+ 9))
5854 #endif /* CONFIG_PEERKEY */
5855 #ifdef CONFIG_IEEE80211R
5856 } else if (os_strncmp(buf
, "FT_DS ", 6) == 0) {
5857 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s
, buf
+ 6))
5859 #endif /* CONFIG_IEEE80211R */
5861 } else if (os_strcmp(buf
, "WPS_PBC") == 0) {
5862 int res
= wpa_supplicant_ctrl_iface_wps_pbc(wpa_s
, NULL
);
5864 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
5868 } else if (os_strncmp(buf
, "WPS_PBC ", 8) == 0) {
5869 int res
= wpa_supplicant_ctrl_iface_wps_pbc(wpa_s
, buf
+ 8);
5871 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
5875 } else if (os_strncmp(buf
, "WPS_PIN ", 8) == 0) {
5876 reply_len
= wpa_supplicant_ctrl_iface_wps_pin(wpa_s
, buf
+ 8,
5879 } else if (os_strncmp(buf
, "WPS_CHECK_PIN ", 14) == 0) {
5880 reply_len
= wpa_supplicant_ctrl_iface_wps_check_pin(
5881 wpa_s
, buf
+ 14, reply
, reply_size
);
5882 } else if (os_strcmp(buf
, "WPS_CANCEL") == 0) {
5883 if (wpas_wps_cancel(wpa_s
))
5885 #ifdef CONFIG_WPS_NFC
5886 } else if (os_strcmp(buf
, "WPS_NFC") == 0) {
5887 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s
, NULL
))
5889 } else if (os_strncmp(buf
, "WPS_NFC ", 8) == 0) {
5890 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s
, buf
+ 8))
5892 } else if (os_strncmp(buf
, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
5893 reply_len
= wpa_supplicant_ctrl_iface_wps_nfc_config_token(
5894 wpa_s
, buf
+ 21, reply
, reply_size
);
5895 } else if (os_strncmp(buf
, "WPS_NFC_TOKEN ", 14) == 0) {
5896 reply_len
= wpa_supplicant_ctrl_iface_wps_nfc_token(
5897 wpa_s
, buf
+ 14, reply
, reply_size
);
5898 } else if (os_strncmp(buf
, "WPS_NFC_TAG_READ ", 17) == 0) {
5899 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s
,
5902 } else if (os_strncmp(buf
, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
5903 reply_len
= wpas_ctrl_nfc_get_handover_req(
5904 wpa_s
, buf
+ 21, reply
, reply_size
);
5905 } else if (os_strncmp(buf
, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
5906 reply_len
= wpas_ctrl_nfc_get_handover_sel(
5907 wpa_s
, buf
+ 21, reply
, reply_size
);
5908 } else if (os_strncmp(buf
, "NFC_RX_HANDOVER_REQ ", 20) == 0) {
5909 reply_len
= wpas_ctrl_nfc_rx_handover_req(
5910 wpa_s
, buf
+ 20, reply
, reply_size
);
5911 } else if (os_strncmp(buf
, "NFC_RX_HANDOVER_SEL ", 20) == 0) {
5912 if (wpas_ctrl_nfc_rx_handover_sel(wpa_s
, buf
+ 20))
5914 } else if (os_strncmp(buf
, "NFC_REPORT_HANDOVER ", 20) == 0) {
5915 if (wpas_ctrl_nfc_report_handover(wpa_s
, buf
+ 20))
5917 #endif /* CONFIG_WPS_NFC */
5918 } else if (os_strncmp(buf
, "WPS_REG ", 8) == 0) {
5919 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s
, buf
+ 8))
5922 } else if (os_strncmp(buf
, "WPS_AP_PIN ", 11) == 0) {
5923 reply_len
= wpa_supplicant_ctrl_iface_wps_ap_pin(
5924 wpa_s
, buf
+ 11, reply
, reply_size
);
5925 #endif /* CONFIG_AP */
5926 #ifdef CONFIG_WPS_ER
5927 } else if (os_strcmp(buf
, "WPS_ER_START") == 0) {
5928 if (wpas_wps_er_start(wpa_s
, NULL
))
5930 } else if (os_strncmp(buf
, "WPS_ER_START ", 13) == 0) {
5931 if (wpas_wps_er_start(wpa_s
, buf
+ 13))
5933 } else if (os_strcmp(buf
, "WPS_ER_STOP") == 0) {
5934 if (wpas_wps_er_stop(wpa_s
))
5936 } else if (os_strncmp(buf
, "WPS_ER_PIN ", 11) == 0) {
5937 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s
, buf
+ 11))
5939 } else if (os_strncmp(buf
, "WPS_ER_PBC ", 11) == 0) {
5940 int ret
= wpas_wps_er_pbc(wpa_s
, buf
+ 11);
5942 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
5944 } else if (ret
== -3) {
5945 os_memcpy(reply
, "FAIL-UNKNOWN-UUID\n", 18);
5947 } else if (ret
== -4) {
5948 os_memcpy(reply
, "FAIL-NO-AP-SETTINGS\n", 20);
5952 } else if (os_strncmp(buf
, "WPS_ER_LEARN ", 13) == 0) {
5953 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s
, buf
+ 13))
5955 } else if (os_strncmp(buf
, "WPS_ER_SET_CONFIG ", 18) == 0) {
5956 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s
,
5959 } else if (os_strncmp(buf
, "WPS_ER_CONFIG ", 14) == 0) {
5960 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s
, buf
+ 14))
5962 #ifdef CONFIG_WPS_NFC
5963 } else if (os_strncmp(buf
, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
5964 reply_len
= wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
5965 wpa_s
, buf
+ 24, reply
, reply_size
);
5966 #endif /* CONFIG_WPS_NFC */
5967 #endif /* CONFIG_WPS_ER */
5968 #endif /* CONFIG_WPS */
5969 #ifdef CONFIG_IBSS_RSN
5970 } else if (os_strncmp(buf
, "IBSS_RSN ", 9) == 0) {
5971 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s
, buf
+ 9))
5973 #endif /* CONFIG_IBSS_RSN */
5975 } else if (os_strncmp(buf
, "P2P_FIND ", 9) == 0) {
5976 if (p2p_ctrl_find(wpa_s
, buf
+ 9))
5978 } else if (os_strcmp(buf
, "P2P_FIND") == 0) {
5979 if (p2p_ctrl_find(wpa_s
, ""))
5981 } else if (os_strcmp(buf
, "P2P_STOP_FIND") == 0) {
5982 wpas_p2p_stop_find(wpa_s
);
5983 } else if (os_strncmp(buf
, "P2P_CONNECT ", 12) == 0) {
5984 reply_len
= p2p_ctrl_connect(wpa_s
, buf
+ 12, reply
,
5986 } else if (os_strncmp(buf
, "P2P_LISTEN ", 11) == 0) {
5987 if (p2p_ctrl_listen(wpa_s
, buf
+ 11))
5989 } else if (os_strcmp(buf
, "P2P_LISTEN") == 0) {
5990 if (p2p_ctrl_listen(wpa_s
, ""))
5992 } else if (os_strncmp(buf
, "P2P_GROUP_REMOVE ", 17) == 0) {
5993 if (wpas_p2p_group_remove(wpa_s
, buf
+ 17))
5995 } else if (os_strcmp(buf
, "P2P_GROUP_ADD") == 0) {
5996 if (wpas_p2p_group_add(wpa_s
, 0, 0, 0, 0))
5998 } else if (os_strncmp(buf
, "P2P_GROUP_ADD ", 14) == 0) {
5999 if (p2p_ctrl_group_add(wpa_s
, buf
+ 14))
6001 } else if (os_strncmp(buf
, "P2P_PROV_DISC ", 14) == 0) {
6002 if (p2p_ctrl_prov_disc(wpa_s
, buf
+ 14))
6004 } else if (os_strcmp(buf
, "P2P_GET_PASSPHRASE") == 0) {
6005 reply_len
= p2p_get_passphrase(wpa_s
, reply
, reply_size
);
6006 } else if (os_strncmp(buf
, "P2P_SERV_DISC_REQ ", 18) == 0) {
6007 reply_len
= p2p_ctrl_serv_disc_req(wpa_s
, buf
+ 18, reply
,
6009 } else if (os_strncmp(buf
, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
6010 if (p2p_ctrl_serv_disc_cancel_req(wpa_s
, buf
+ 25) < 0)
6012 } else if (os_strncmp(buf
, "P2P_SERV_DISC_RESP ", 19) == 0) {
6013 if (p2p_ctrl_serv_disc_resp(wpa_s
, buf
+ 19) < 0)
6015 } else if (os_strcmp(buf
, "P2P_SERVICE_UPDATE") == 0) {
6016 wpas_p2p_sd_service_update(wpa_s
);
6017 } else if (os_strncmp(buf
, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
6018 if (p2p_ctrl_serv_disc_external(wpa_s
, buf
+ 23) < 0)
6020 } else if (os_strcmp(buf
, "P2P_SERVICE_FLUSH") == 0) {
6021 wpas_p2p_service_flush(wpa_s
);
6022 } else if (os_strncmp(buf
, "P2P_SERVICE_ADD ", 16) == 0) {
6023 if (p2p_ctrl_service_add(wpa_s
, buf
+ 16) < 0)
6025 } else if (os_strncmp(buf
, "P2P_SERVICE_DEL ", 16) == 0) {
6026 if (p2p_ctrl_service_del(wpa_s
, buf
+ 16) < 0)
6028 } else if (os_strncmp(buf
, "P2P_REJECT ", 11) == 0) {
6029 if (p2p_ctrl_reject(wpa_s
, buf
+ 11) < 0)
6031 } else if (os_strncmp(buf
, "P2P_INVITE ", 11) == 0) {
6032 if (p2p_ctrl_invite(wpa_s
, buf
+ 11) < 0)
6034 } else if (os_strncmp(buf
, "P2P_PEER ", 9) == 0) {
6035 reply_len
= p2p_ctrl_peer(wpa_s
, buf
+ 9, reply
,
6037 } else if (os_strncmp(buf
, "P2P_SET ", 8) == 0) {
6038 if (p2p_ctrl_set(wpa_s
, buf
+ 8) < 0)
6040 } else if (os_strcmp(buf
, "P2P_FLUSH") == 0) {
6041 p2p_ctrl_flush(wpa_s
);
6042 } else if (os_strncmp(buf
, "P2P_UNAUTHORIZE ", 16) == 0) {
6043 if (wpas_p2p_unauthorize(wpa_s
, buf
+ 16) < 0)
6045 } else if (os_strcmp(buf
, "P2P_CANCEL") == 0) {
6046 if (wpas_p2p_cancel(wpa_s
))
6048 } else if (os_strncmp(buf
, "P2P_PRESENCE_REQ ", 17) == 0) {
6049 if (p2p_ctrl_presence_req(wpa_s
, buf
+ 17) < 0)
6051 } else if (os_strcmp(buf
, "P2P_PRESENCE_REQ") == 0) {
6052 if (p2p_ctrl_presence_req(wpa_s
, "") < 0)
6054 } else if (os_strncmp(buf
, "P2P_EXT_LISTEN ", 15) == 0) {
6055 if (p2p_ctrl_ext_listen(wpa_s
, buf
+ 15) < 0)
6057 } else if (os_strcmp(buf
, "P2P_EXT_LISTEN") == 0) {
6058 if (p2p_ctrl_ext_listen(wpa_s
, "") < 0)
6060 } else if (os_strncmp(buf
, "P2P_REMOVE_CLIENT ", 18) == 0) {
6061 if (p2p_ctrl_remove_client(wpa_s
, buf
+ 18) < 0)
6063 #endif /* CONFIG_P2P */
6064 #ifdef CONFIG_WIFI_DISPLAY
6065 } else if (os_strncmp(buf
, "WFD_SUBELEM_SET ", 16) == 0) {
6066 if (wifi_display_subelem_set(wpa_s
->global
, buf
+ 16) < 0)
6068 } else if (os_strncmp(buf
, "WFD_SUBELEM_GET ", 16) == 0) {
6069 reply_len
= wifi_display_subelem_get(wpa_s
->global
, buf
+ 16,
6071 #endif /* CONFIG_WIFI_DISPLAY */
6072 #ifdef CONFIG_INTERWORKING
6073 } else if (os_strcmp(buf
, "FETCH_ANQP") == 0) {
6074 if (interworking_fetch_anqp(wpa_s
) < 0)
6076 } else if (os_strcmp(buf
, "STOP_FETCH_ANQP") == 0) {
6077 interworking_stop_fetch_anqp(wpa_s
);
6078 } else if (os_strcmp(buf
, "INTERWORKING_SELECT") == 0) {
6079 if (ctrl_interworking_select(wpa_s
, NULL
) < 0)
6081 } else if (os_strncmp(buf
, "INTERWORKING_SELECT ", 20) == 0) {
6082 if (ctrl_interworking_select(wpa_s
, buf
+ 20) < 0)
6084 } else if (os_strncmp(buf
, "INTERWORKING_CONNECT ", 21) == 0) {
6085 if (ctrl_interworking_connect(wpa_s
, buf
+ 21) < 0)
6087 } else if (os_strncmp(buf
, "ANQP_GET ", 9) == 0) {
6088 if (get_anqp(wpa_s
, buf
+ 9) < 0)
6090 } else if (os_strncmp(buf
, "GAS_REQUEST ", 12) == 0) {
6091 if (gas_request(wpa_s
, buf
+ 12) < 0)
6093 } else if (os_strncmp(buf
, "GAS_RESPONSE_GET ", 17) == 0) {
6094 reply_len
= gas_response_get(wpa_s
, buf
+ 17, reply
,
6096 #endif /* CONFIG_INTERWORKING */
6098 } else if (os_strncmp(buf
, "HS20_ANQP_GET ", 14) == 0) {
6099 if (get_hs20_anqp(wpa_s
, buf
+ 14) < 0)
6101 } else if (os_strncmp(buf
, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
6102 if (hs20_get_nai_home_realm_list(wpa_s
, buf
+ 29) < 0)
6104 #endif /* CONFIG_HS20 */
6105 } else if (os_strncmp(buf
, WPA_CTRL_RSP
, os_strlen(WPA_CTRL_RSP
)) == 0)
6107 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
6108 wpa_s
, buf
+ os_strlen(WPA_CTRL_RSP
)))
6112 * Notify response from timeout to allow the control
6113 * interface response to be sent first.
6115 eloop_register_timeout(0, 0, wpas_ctrl_eapol_response
,
6118 } else if (os_strcmp(buf
, "RECONFIGURE") == 0) {
6119 if (wpa_supplicant_reload_configuration(wpa_s
))
6121 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
6122 wpa_supplicant_terminate_proc(wpa_s
->global
);
6123 } else if (os_strncmp(buf
, "BSSID ", 6) == 0) {
6124 if (wpa_supplicant_ctrl_iface_bssid(wpa_s
, buf
+ 6))
6126 } else if (os_strncmp(buf
, "BLACKLIST", 9) == 0) {
6127 reply_len
= wpa_supplicant_ctrl_iface_blacklist(
6128 wpa_s
, buf
+ 9, reply
, reply_size
);
6129 } else if (os_strncmp(buf
, "LOG_LEVEL", 9) == 0) {
6130 reply_len
= wpa_supplicant_ctrl_iface_log_level(
6131 wpa_s
, buf
+ 9, reply
, reply_size
);
6132 } else if (os_strcmp(buf
, "LIST_NETWORKS") == 0) {
6133 reply_len
= wpa_supplicant_ctrl_iface_list_networks(
6134 wpa_s
, reply
, reply_size
);
6135 } else if (os_strcmp(buf
, "DISCONNECT") == 0) {
6137 wpa_s
->sme
.prev_bssid_set
= 0;
6138 #endif /* CONFIG_SME */
6139 wpa_s
->reassociate
= 0;
6140 wpa_s
->disconnected
= 1;
6141 wpa_supplicant_cancel_sched_scan(wpa_s
);
6142 wpa_supplicant_cancel_scan(wpa_s
);
6143 wpa_supplicant_deauthenticate(wpa_s
,
6144 WLAN_REASON_DEAUTH_LEAVING
);
6145 } else if (os_strcmp(buf
, "SCAN") == 0) {
6146 wpas_ctrl_scan(wpa_s
, NULL
, reply
, reply_size
, &reply_len
);
6147 } else if (os_strncmp(buf
, "SCAN ", 5) == 0) {
6148 wpas_ctrl_scan(wpa_s
, buf
+ 5, reply
, reply_size
, &reply_len
);
6149 } else if (os_strcmp(buf
, "SCAN_RESULTS") == 0) {
6150 reply_len
= wpa_supplicant_ctrl_iface_scan_results(
6151 wpa_s
, reply
, reply_size
);
6152 } else if (os_strncmp(buf
, "SELECT_NETWORK ", 15) == 0) {
6153 if (wpa_supplicant_ctrl_iface_select_network(wpa_s
, buf
+ 15))
6155 } else if (os_strncmp(buf
, "ENABLE_NETWORK ", 15) == 0) {
6156 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s
, buf
+ 15))
6158 } else if (os_strncmp(buf
, "DISABLE_NETWORK ", 16) == 0) {
6159 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s
, buf
+ 16))
6161 } else if (os_strcmp(buf
, "ADD_NETWORK") == 0) {
6162 reply_len
= wpa_supplicant_ctrl_iface_add_network(
6163 wpa_s
, reply
, reply_size
);
6164 } else if (os_strncmp(buf
, "REMOVE_NETWORK ", 15) == 0) {
6165 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s
, buf
+ 15))
6167 } else if (os_strncmp(buf
, "SET_NETWORK ", 12) == 0) {
6168 if (wpa_supplicant_ctrl_iface_set_network(wpa_s
, buf
+ 12))
6170 } else if (os_strncmp(buf
, "GET_NETWORK ", 12) == 0) {
6171 reply_len
= wpa_supplicant_ctrl_iface_get_network(
6172 wpa_s
, buf
+ 12, reply
, reply_size
);
6173 } else if (os_strcmp(buf
, "LIST_CREDS") == 0) {
6174 reply_len
= wpa_supplicant_ctrl_iface_list_creds(
6175 wpa_s
, reply
, reply_size
);
6176 } else if (os_strcmp(buf
, "ADD_CRED") == 0) {
6177 reply_len
= wpa_supplicant_ctrl_iface_add_cred(
6178 wpa_s
, reply
, reply_size
);
6179 } else if (os_strncmp(buf
, "REMOVE_CRED ", 12) == 0) {
6180 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s
, buf
+ 12))
6182 } else if (os_strncmp(buf
, "SET_CRED ", 9) == 0) {
6183 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s
, buf
+ 9))
6185 #ifndef CONFIG_NO_CONFIG_WRITE
6186 } else if (os_strcmp(buf
, "SAVE_CONFIG") == 0) {
6187 if (wpa_supplicant_ctrl_iface_save_config(wpa_s
))
6189 #endif /* CONFIG_NO_CONFIG_WRITE */
6190 } else if (os_strncmp(buf
, "GET_CAPABILITY ", 15) == 0) {
6191 reply_len
= wpa_supplicant_ctrl_iface_get_capability(
6192 wpa_s
, buf
+ 15, reply
, reply_size
);
6193 } else if (os_strncmp(buf
, "AP_SCAN ", 8) == 0) {
6194 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s
, buf
+ 8))
6196 } else if (os_strncmp(buf
, "SCAN_INTERVAL ", 14) == 0) {
6197 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s
, buf
+ 14))
6199 } else if (os_strcmp(buf
, "INTERFACE_LIST") == 0) {
6200 reply_len
= wpa_supplicant_global_iface_list(
6201 wpa_s
->global
, reply
, reply_size
);
6202 } else if (os_strcmp(buf
, "INTERFACES") == 0) {
6203 reply_len
= wpa_supplicant_global_iface_interfaces(
6204 wpa_s
->global
, reply
, reply_size
);
6205 } else if (os_strncmp(buf
, "BSS ", 4) == 0) {
6206 reply_len
= wpa_supplicant_ctrl_iface_bss(
6207 wpa_s
, buf
+ 4, reply
, reply_size
);
6209 } else if (os_strcmp(buf
, "STA-FIRST") == 0) {
6210 reply_len
= ap_ctrl_iface_sta_first(wpa_s
, reply
, reply_size
);
6211 } else if (os_strncmp(buf
, "STA ", 4) == 0) {
6212 reply_len
= ap_ctrl_iface_sta(wpa_s
, buf
+ 4, reply
,
6214 } else if (os_strncmp(buf
, "STA-NEXT ", 9) == 0) {
6215 reply_len
= ap_ctrl_iface_sta_next(wpa_s
, buf
+ 9, reply
,
6217 } else if (os_strncmp(buf
, "DEAUTHENTICATE ", 15) == 0) {
6218 if (ap_ctrl_iface_sta_deauthenticate(wpa_s
, buf
+ 15))
6220 } else if (os_strncmp(buf
, "DISASSOCIATE ", 13) == 0) {
6221 if (ap_ctrl_iface_sta_disassociate(wpa_s
, buf
+ 13))
6223 } else if (os_strncmp(buf
, "CHAN_SWITCH ", 12) == 0) {
6224 if (ap_ctrl_iface_chanswitch(wpa_s
, buf
+ 12))
6226 #endif /* CONFIG_AP */
6227 } else if (os_strcmp(buf
, "SUSPEND") == 0) {
6228 wpas_notify_suspend(wpa_s
->global
);
6229 } else if (os_strcmp(buf
, "RESUME") == 0) {
6230 wpas_notify_resume(wpa_s
->global
);
6231 } else if (os_strcmp(buf
, "DROP_SA") == 0) {
6232 wpa_supplicant_ctrl_iface_drop_sa(wpa_s
);
6233 } else if (os_strncmp(buf
, "ROAM ", 5) == 0) {
6234 if (wpa_supplicant_ctrl_iface_roam(wpa_s
, buf
+ 5))
6236 } else if (os_strncmp(buf
, "STA_AUTOCONNECT ", 16) == 0) {
6237 if (wpa_supplicant_ctrl_iface_sta_autoconnect(wpa_s
, buf
+ 16))
6239 } else if (os_strncmp(buf
, "BSS_EXPIRE_AGE ", 15) == 0) {
6240 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s
, buf
+ 15))
6242 } else if (os_strncmp(buf
, "BSS_EXPIRE_COUNT ", 17) == 0) {
6243 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s
,
6246 } else if (os_strncmp(buf
, "BSS_FLUSH ", 10) == 0) {
6247 if (wpa_supplicant_ctrl_iface_bss_flush(wpa_s
, buf
+ 10))
6250 } else if (os_strncmp(buf
, "TDLS_DISCOVER ", 14) == 0) {
6251 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s
, buf
+ 14))
6253 } else if (os_strncmp(buf
, "TDLS_SETUP ", 11) == 0) {
6254 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s
, buf
+ 11))
6256 } else if (os_strncmp(buf
, "TDLS_TEARDOWN ", 14) == 0) {
6257 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s
, buf
+ 14))
6259 #endif /* CONFIG_TDLS */
6260 } else if (os_strncmp(buf
, "SIGNAL_POLL", 11) == 0) {
6261 reply_len
= wpa_supplicant_signal_poll(wpa_s
, reply
,
6263 } else if (os_strncmp(buf
, "PKTCNT_POLL", 11) == 0) {
6264 reply_len
= wpa_supplicant_pktcnt_poll(wpa_s
, reply
,
6266 #ifdef CONFIG_AUTOSCAN
6267 } else if (os_strncmp(buf
, "AUTOSCAN ", 9) == 0) {
6268 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s
, buf
+ 9))
6270 #endif /* CONFIG_AUTOSCAN */
6272 } else if (os_strncmp(buf
, "DRIVER ", 7) == 0) {
6273 reply_len
= wpa_supplicant_driver_cmd(wpa_s
, buf
+ 7, reply
,
6275 #endif /* ANDROID */
6276 } else if (os_strcmp(buf
, "REAUTHENTICATE") == 0) {
6277 pmksa_cache_clear_current(wpa_s
->wpa
);
6278 eapol_sm_request_reauth(wpa_s
->eapol
);
6280 } else if (os_strncmp(buf
, "WNM_SLEEP ", 10) == 0) {
6281 if (wpas_ctrl_iface_wnm_sleep(wpa_s
, buf
+ 10))
6283 } else if (os_strncmp(buf
, "WNM_BSS_QUERY ", 10) == 0) {
6284 if (wpas_ctrl_iface_wnm_bss_query(wpa_s
, buf
+ 10))
6286 #endif /* CONFIG_WNM */
6287 } else if (os_strcmp(buf
, "FLUSH") == 0) {
6288 wpa_supplicant_ctrl_iface_flush(wpa_s
);
6289 } else if (os_strncmp(buf
, "RADIO_WORK ", 11) == 0) {
6290 reply_len
= wpas_ctrl_radio_work(wpa_s
, buf
+ 11, reply
,
6293 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
6297 if (reply_len
< 0) {
6298 os_memcpy(reply
, "FAIL\n", 5);
6302 *resp_len
= reply_len
;
6307 static int wpa_supplicant_global_iface_add(struct wpa_global
*global
,
6310 struct wpa_interface iface
;
6314 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
6315 * TAB<bridge_ifname>
6317 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd
);
6319 os_memset(&iface
, 0, sizeof(iface
));
6322 iface
.ifname
= pos
= cmd
;
6323 pos
= os_strchr(pos
, '\t');
6326 if (iface
.ifname
[0] == '\0')
6331 iface
.confname
= pos
;
6332 pos
= os_strchr(pos
, '\t');
6335 if (iface
.confname
[0] == '\0')
6336 iface
.confname
= NULL
;
6341 pos
= os_strchr(pos
, '\t');
6344 if (iface
.driver
[0] == '\0')
6345 iface
.driver
= NULL
;
6349 iface
.ctrl_interface
= pos
;
6350 pos
= os_strchr(pos
, '\t');
6353 if (iface
.ctrl_interface
[0] == '\0')
6354 iface
.ctrl_interface
= NULL
;
6358 iface
.driver_param
= pos
;
6359 pos
= os_strchr(pos
, '\t');
6362 if (iface
.driver_param
[0] == '\0')
6363 iface
.driver_param
= NULL
;
6367 iface
.bridge_ifname
= pos
;
6368 pos
= os_strchr(pos
, '\t');
6371 if (iface
.bridge_ifname
[0] == '\0')
6372 iface
.bridge_ifname
= NULL
;
6377 if (wpa_supplicant_get_iface(global
, iface
.ifname
))
6380 return wpa_supplicant_add_iface(global
, &iface
) ? 0 : -1;
6384 static int wpa_supplicant_global_iface_remove(struct wpa_global
*global
,
6387 struct wpa_supplicant
*wpa_s
;
6389 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd
);
6391 wpa_s
= wpa_supplicant_get_iface(global
, cmd
);
6394 return wpa_supplicant_remove_iface(global
, wpa_s
, 0);
6398 static void wpa_free_iface_info(struct wpa_interface_info
*iface
)
6400 struct wpa_interface_info
*prev
;
6404 iface
= iface
->next
;
6406 os_free(prev
->ifname
);
6407 os_free(prev
->desc
);
6413 static int wpa_supplicant_global_iface_list(struct wpa_global
*global
,
6417 struct wpa_interface_info
*iface
= NULL
, *last
= NULL
, *tmp
;
6420 for (i
= 0; wpa_drivers
[i
]; i
++) {
6421 struct wpa_driver_ops
*drv
= wpa_drivers
[i
];
6422 if (drv
->get_interfaces
== NULL
)
6424 tmp
= drv
->get_interfaces(global
->drv_priv
[i
]);
6438 for (tmp
= iface
; tmp
; tmp
= tmp
->next
) {
6439 res
= os_snprintf(pos
, end
- pos
, "%s\t%s\t%s\n",
6440 tmp
->drv_name
, tmp
->ifname
,
6441 tmp
->desc
? tmp
->desc
: "");
6442 if (res
< 0 || res
>= end
- pos
) {
6449 wpa_free_iface_info(iface
);
6455 static int wpa_supplicant_global_iface_interfaces(struct wpa_global
*global
,
6460 struct wpa_supplicant
*wpa_s
;
6462 wpa_s
= global
->ifaces
;
6467 res
= os_snprintf(pos
, end
- pos
, "%s\n", wpa_s
->ifname
);
6468 if (res
< 0 || res
>= end
- pos
) {
6473 wpa_s
= wpa_s
->next
;
6479 static char * wpas_global_ctrl_iface_ifname(struct wpa_global
*global
,
6481 char *cmd
, size_t *resp_len
)
6483 struct wpa_supplicant
*wpa_s
;
6485 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
6486 if (os_strcmp(ifname
, wpa_s
->ifname
) == 0)
6490 if (wpa_s
== NULL
) {
6491 char *resp
= os_strdup("FAIL-NO-IFNAME-MATCH\n");
6493 *resp_len
= os_strlen(resp
);
6499 return wpa_supplicant_ctrl_iface_process(wpa_s
, cmd
, resp_len
);
6503 static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global
*global
,
6504 char *buf
, size_t *resp_len
)
6507 static const char * cmd
[] = {
6514 "P2P_GET_PASSPHRASE",
6515 "P2P_SERVICE_UPDATE",
6516 "P2P_SERVICE_FLUSH",
6523 static const char * prefix
[] = {
6526 #endif /* ANDROID */
6533 "P2P_GROUP_REMOVE ",
6536 "P2P_SERV_DISC_REQ ",
6537 "P2P_SERV_DISC_CANCEL_REQ ",
6538 "P2P_SERV_DISC_RESP ",
6539 "P2P_SERV_DISC_EXTERNAL ",
6547 "P2P_PRESENCE_REQ ",
6549 "P2P_REMOVE_CLIENT ",
6555 if (global
->p2p_init_wpa_s
== NULL
)
6558 for (i
= 0; !found
&& cmd
[i
]; i
++) {
6559 if (os_strcmp(buf
, cmd
[i
]) == 0)
6563 for (i
= 0; !found
&& prefix
[i
]; i
++) {
6564 if (os_strncmp(buf
, prefix
[i
], os_strlen(prefix
[i
])) == 0)
6569 return wpa_supplicant_ctrl_iface_process(global
->p2p_init_wpa_s
,
6571 #endif /* CONFIG_P2P */
6576 static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global
*global
,
6577 char *buf
, size_t *resp_len
)
6579 #ifdef CONFIG_WIFI_DISPLAY
6580 if (global
->p2p_init_wpa_s
== NULL
)
6582 if (os_strncmp(buf
, "WFD_SUBELEM_SET ", 16) == 0 ||
6583 os_strncmp(buf
, "WFD_SUBELEM_GET ", 16) == 0)
6584 return wpa_supplicant_ctrl_iface_process(global
->p2p_init_wpa_s
,
6586 #endif /* CONFIG_WIFI_DISPLAY */
6591 static char * wpas_global_ctrl_iface_redir(struct wpa_global
*global
,
6592 char *buf
, size_t *resp_len
)
6596 ret
= wpas_global_ctrl_iface_redir_p2p(global
, buf
, resp_len
);
6600 ret
= wpas_global_ctrl_iface_redir_wfd(global
, buf
, resp_len
);
6608 static int wpas_global_ctrl_iface_set(struct wpa_global
*global
, char *cmd
)
6612 value
= os_strchr(cmd
, ' ');
6617 wpa_printf(MSG_DEBUG
, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd
, value
);
6619 #ifdef CONFIG_WIFI_DISPLAY
6620 if (os_strcasecmp(cmd
, "wifi_display") == 0) {
6621 wifi_display_enable(global
, !!atoi(value
));
6624 #endif /* CONFIG_WIFI_DISPLAY */
6630 #ifndef CONFIG_NO_CONFIG_WRITE
6631 static int wpas_global_ctrl_iface_save_config(struct wpa_global
*global
)
6634 struct wpa_supplicant
*wpa_s
;
6636 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
6637 if (!wpa_s
->conf
->update_config
) {
6638 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
6642 if (wpa_config_write(wpa_s
->confname
, wpa_s
->conf
)) {
6643 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
6646 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
6652 #endif /* CONFIG_NO_CONFIG_WRITE */
6655 static int wpas_global_ctrl_iface_status(struct wpa_global
*global
,
6656 char *buf
, size_t buflen
)
6660 struct wpa_supplicant
*wpa_s
;
6666 if (global
->p2p
&& !global
->p2p_disabled
) {
6667 ret
= os_snprintf(pos
, end
- pos
, "p2p_device_address=" MACSTR
6670 MAC2STR(global
->p2p_dev_addr
),
6671 p2p_get_state_txt(global
->p2p
));
6672 if (ret
< 0 || ret
>= end
- pos
)
6675 } else if (global
->p2p
) {
6676 ret
= os_snprintf(pos
, end
- pos
, "p2p_state=DISABLED\n");
6677 if (ret
< 0 || ret
>= end
- pos
)
6681 #endif /* CONFIG_P2P */
6683 #ifdef CONFIG_WIFI_DISPLAY
6684 ret
= os_snprintf(pos
, end
- pos
, "wifi_display=%d\n",
6685 !!global
->wifi_display
);
6686 if (ret
< 0 || ret
>= end
- pos
)
6689 #endif /* CONFIG_WIFI_DISPLAY */
6691 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
6692 ret
= os_snprintf(pos
, end
- pos
, "ifname=%s\n"
6693 "address=" MACSTR
"\n",
6694 wpa_s
->ifname
, MAC2STR(wpa_s
->own_addr
));
6695 if (ret
< 0 || ret
>= end
- pos
)
6704 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global
*global
,
6705 char *buf
, size_t *resp_len
)
6708 const int reply_size
= 2048;
6710 int level
= MSG_DEBUG
;
6712 if (os_strncmp(buf
, "IFNAME=", 7) == 0) {
6713 char *pos
= os_strchr(buf
+ 7, ' ');
6716 return wpas_global_ctrl_iface_ifname(global
,
6722 reply
= wpas_global_ctrl_iface_redir(global
, buf
, resp_len
);
6726 if (os_strcmp(buf
, "PING") == 0)
6727 level
= MSG_EXCESSIVE
;
6728 wpa_hexdump_ascii(level
, "RX global ctrl_iface",
6729 (const u8
*) buf
, os_strlen(buf
));
6731 reply
= os_malloc(reply_size
);
6732 if (reply
== NULL
) {
6737 os_memcpy(reply
, "OK\n", 3);
6740 if (os_strcmp(buf
, "PING") == 0) {
6741 os_memcpy(reply
, "PONG\n", 5);
6743 } else if (os_strncmp(buf
, "INTERFACE_ADD ", 14) == 0) {
6744 if (wpa_supplicant_global_iface_add(global
, buf
+ 14))
6746 } else if (os_strncmp(buf
, "INTERFACE_REMOVE ", 17) == 0) {
6747 if (wpa_supplicant_global_iface_remove(global
, buf
+ 17))
6749 } else if (os_strcmp(buf
, "INTERFACE_LIST") == 0) {
6750 reply_len
= wpa_supplicant_global_iface_list(
6751 global
, reply
, reply_size
);
6752 } else if (os_strcmp(buf
, "INTERFACES") == 0) {
6753 reply_len
= wpa_supplicant_global_iface_interfaces(
6754 global
, reply
, reply_size
);
6755 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
6756 wpa_supplicant_terminate_proc(global
);
6757 } else if (os_strcmp(buf
, "SUSPEND") == 0) {
6758 wpas_notify_suspend(global
);
6759 } else if (os_strcmp(buf
, "RESUME") == 0) {
6760 wpas_notify_resume(global
);
6761 } else if (os_strncmp(buf
, "SET ", 4) == 0) {
6762 if (wpas_global_ctrl_iface_set(global
, buf
+ 4))
6764 #ifndef CONFIG_NO_CONFIG_WRITE
6765 } else if (os_strcmp(buf
, "SAVE_CONFIG") == 0) {
6766 if (wpas_global_ctrl_iface_save_config(global
))
6768 #endif /* CONFIG_NO_CONFIG_WRITE */
6769 } else if (os_strcmp(buf
, "STATUS") == 0) {
6770 reply_len
= wpas_global_ctrl_iface_status(global
, reply
,
6773 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
6777 if (reply_len
< 0) {
6778 os_memcpy(reply
, "FAIL\n", 5);
6782 *resp_len
= reply_len
;