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 #endif /* CONFIG_WPS_TESTING */
368 } else if (os_strcasecmp(cmd
, "ampdu") == 0) {
369 if (wpa_drv_ampdu(wpa_s
, atoi(value
)) < 0)
372 #ifdef CONFIG_TDLS_TESTING
373 } else if (os_strcasecmp(cmd
, "tdls_testing") == 0) {
374 extern unsigned int tdls_testing
;
375 tdls_testing
= strtol(value
, NULL
, 0);
376 wpa_printf(MSG_DEBUG
, "TDLS: tdls_testing=0x%x", tdls_testing
);
377 #endif /* CONFIG_TDLS_TESTING */
378 } else if (os_strcasecmp(cmd
, "tdls_disabled") == 0) {
379 int disabled
= atoi(value
);
380 wpa_printf(MSG_DEBUG
, "TDLS: tdls_disabled=%d", disabled
);
382 if (wpa_drv_tdls_oper(wpa_s
, TDLS_DISABLE
, NULL
) < 0)
384 } else if (wpa_drv_tdls_oper(wpa_s
, TDLS_ENABLE
, NULL
) < 0)
386 wpa_tdls_enable(wpa_s
->wpa
, !disabled
);
387 #endif /* CONFIG_TDLS */
388 } else if (os_strcasecmp(cmd
, "pno") == 0) {
390 ret
= pno_start(wpa_s
);
392 ret
= pno_stop(wpa_s
);
393 } else if (os_strcasecmp(cmd
, "radio_disabled") == 0) {
394 int disabled
= atoi(value
);
395 if (wpa_drv_radio_disable(wpa_s
, disabled
) < 0)
398 wpa_supplicant_set_state(wpa_s
, WPA_INACTIVE
);
399 } else if (os_strcasecmp(cmd
, "uapsd") == 0) {
400 if (os_strcmp(value
, "disable") == 0)
401 wpa_s
->set_sta_uapsd
= 0;
405 /* format: BE,BK,VI,VO;max SP Length */
407 pos
= os_strchr(value
, ',');
412 pos
= os_strchr(pos
, ',');
417 pos
= os_strchr(pos
, ',');
422 /* ignore max SP Length for now */
424 wpa_s
->set_sta_uapsd
= 1;
425 wpa_s
->sta_uapsd
= 0;
427 wpa_s
->sta_uapsd
|= BIT(0);
429 wpa_s
->sta_uapsd
|= BIT(1);
431 wpa_s
->sta_uapsd
|= BIT(2);
433 wpa_s
->sta_uapsd
|= BIT(3);
435 } else if (os_strcasecmp(cmd
, "ps") == 0) {
436 ret
= wpa_drv_set_p2p_powersave(wpa_s
, atoi(value
), -1, -1);
437 #ifdef CONFIG_WIFI_DISPLAY
438 } else if (os_strcasecmp(cmd
, "wifi_display") == 0) {
439 wifi_display_enable(wpa_s
->global
, !!atoi(value
));
440 #endif /* CONFIG_WIFI_DISPLAY */
441 } else if (os_strcasecmp(cmd
, "bssid_filter") == 0) {
442 ret
= set_bssid_filter(wpa_s
, value
);
443 } else if (os_strcasecmp(cmd
, "disallow_aps") == 0) {
444 ret
= set_disallow_aps(wpa_s
, value
);
445 } else if (os_strcasecmp(cmd
, "no_keep_alive") == 0) {
446 wpa_s
->no_keep_alive
= !!atoi(value
);
449 ret
= wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
451 wpa_supplicant_update_config(wpa_s
);
458 static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant
*wpa_s
,
459 char *cmd
, char *buf
, size_t buflen
)
463 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GET '%s'", cmd
);
465 if (os_strcmp(cmd
, "version") == 0) {
466 res
= os_snprintf(buf
, buflen
, "%s", VERSION_STR
);
467 } else if (os_strcasecmp(cmd
, "country") == 0) {
468 if (wpa_s
->conf
->country
[0] && wpa_s
->conf
->country
[1])
469 res
= os_snprintf(buf
, buflen
, "%c%c",
470 wpa_s
->conf
->country
[0],
471 wpa_s
->conf
->country
[1]);
472 #ifdef CONFIG_WIFI_DISPLAY
473 } else if (os_strcasecmp(cmd
, "wifi_display") == 0) {
474 res
= os_snprintf(buf
, buflen
, "%d",
475 wpa_s
->global
->wifi_display
);
476 if (res
< 0 || (unsigned int) res
>= buflen
)
479 #endif /* CONFIG_WIFI_DISPLAY */
480 #ifdef CONFIG_TESTING_GET_GTK
481 } else if (os_strcmp(cmd
, "gtk") == 0) {
482 if (wpa_s
->last_gtk_len
== 0)
484 res
= wpa_snprintf_hex(buf
, buflen
, wpa_s
->last_gtk
,
485 wpa_s
->last_gtk_len
);
487 #endif /* CONFIG_TESTING_GET_GTK */
490 if (res
< 0 || (unsigned int) res
>= buflen
)
496 #ifdef IEEE8021X_EAPOL
497 static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant
*wpa_s
,
501 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
503 if (hwaddr_aton(addr
, bssid
)) {
504 wpa_printf(MSG_DEBUG
, "CTRL_IFACE PREAUTH: invalid address "
509 wpa_printf(MSG_DEBUG
, "CTRL_IFACE PREAUTH " MACSTR
, MAC2STR(bssid
));
510 rsn_preauth_deinit(wpa_s
->wpa
);
511 if (rsn_preauth_init(wpa_s
->wpa
, bssid
, ssid
? &ssid
->eap
: NULL
))
516 #endif /* IEEE8021X_EAPOL */
519 #ifdef CONFIG_PEERKEY
520 /* MLME-STKSTART.request(peer) */
521 static int wpa_supplicant_ctrl_iface_stkstart(
522 struct wpa_supplicant
*wpa_s
, char *addr
)
526 if (hwaddr_aton(addr
, peer
)) {
527 wpa_printf(MSG_DEBUG
, "CTRL_IFACE STKSTART: invalid "
528 "address '%s'", addr
);
532 wpa_printf(MSG_DEBUG
, "CTRL_IFACE STKSTART " MACSTR
,
535 return wpa_sm_stkstart(wpa_s
->wpa
, peer
);
537 #endif /* CONFIG_PEERKEY */
542 static int wpa_supplicant_ctrl_iface_tdls_discover(
543 struct wpa_supplicant
*wpa_s
, char *addr
)
548 if (hwaddr_aton(addr
, peer
)) {
549 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_DISCOVER: invalid "
550 "address '%s'", addr
);
554 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_DISCOVER " MACSTR
,
557 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
558 ret
= wpa_tdls_send_discovery_request(wpa_s
->wpa
, peer
);
560 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_DISCOVERY_REQ
, peer
);
566 static int wpa_supplicant_ctrl_iface_tdls_setup(
567 struct wpa_supplicant
*wpa_s
, char *addr
)
572 if (hwaddr_aton(addr
, peer
)) {
573 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_SETUP: invalid "
574 "address '%s'", addr
);
578 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_SETUP " MACSTR
,
581 if ((wpa_s
->conf
->tdls_external_control
) &&
582 wpa_tdls_is_external_setup(wpa_s
->wpa
))
583 return wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, peer
);
585 wpa_tdls_remove(wpa_s
->wpa
, peer
);
587 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
588 ret
= wpa_tdls_start(wpa_s
->wpa
, peer
);
590 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, peer
);
596 static int wpa_supplicant_ctrl_iface_tdls_teardown(
597 struct wpa_supplicant
*wpa_s
, char *addr
)
602 if (hwaddr_aton(addr
, peer
)) {
603 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN: invalid "
604 "address '%s'", addr
);
608 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN " MACSTR
,
611 if ((wpa_s
->conf
->tdls_external_control
) &&
612 wpa_tdls_is_external_setup(wpa_s
->wpa
))
613 return wpa_drv_tdls_oper(wpa_s
, TDLS_TEARDOWN
, peer
);
615 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
616 ret
= wpa_tdls_teardown_link(
618 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED
);
620 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_TEARDOWN
, peer
);
625 #endif /* CONFIG_TDLS */
628 #ifdef CONFIG_IEEE80211R
629 static int wpa_supplicant_ctrl_iface_ft_ds(
630 struct wpa_supplicant
*wpa_s
, char *addr
)
632 u8 target_ap
[ETH_ALEN
];
636 if (hwaddr_aton(addr
, target_ap
)) {
637 wpa_printf(MSG_DEBUG
, "CTRL_IFACE FT_DS: invalid "
638 "address '%s'", addr
);
642 wpa_printf(MSG_DEBUG
, "CTRL_IFACE FT_DS " MACSTR
, MAC2STR(target_ap
));
644 bss
= wpa_bss_get_bssid(wpa_s
, target_ap
);
646 mdie
= wpa_bss_get_ie(bss
, WLAN_EID_MOBILITY_DOMAIN
);
650 return wpa_ft_start_over_ds(wpa_s
->wpa
, target_ap
, mdie
);
652 #endif /* CONFIG_IEEE80211R */
656 static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant
*wpa_s
,
659 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
661 u8 p2p_dev_addr
[ETH_ALEN
];
662 #endif /* CONFIG_P2P */
664 u8
*_p2p_dev_addr
= NULL
;
665 #endif /* CONFIG_AP */
667 if (cmd
== NULL
|| os_strcmp(cmd
, "any") == 0) {
670 } else if (os_strncmp(cmd
, "p2p_dev_addr=", 13) == 0) {
671 if (hwaddr_aton(cmd
+ 13, p2p_dev_addr
)) {
672 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PBC: invalid "
673 "P2P Device Address '%s'",
677 _p2p_dev_addr
= p2p_dev_addr
;
678 #endif /* CONFIG_P2P */
679 } else if (hwaddr_aton(cmd
, bssid
)) {
680 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
687 return wpa_supplicant_ap_wps_pbc(wpa_s
, _bssid
, _p2p_dev_addr
);
688 #endif /* CONFIG_AP */
690 return wpas_wps_start_pbc(wpa_s
, _bssid
, 0);
694 static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant
*wpa_s
,
695 char *cmd
, char *buf
,
698 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
702 pin
= os_strchr(cmd
, ' ');
706 if (os_strcmp(cmd
, "any") == 0)
708 else if (os_strcmp(cmd
, "get") == 0) {
709 ret
= wps_generate_pin();
711 } else if (hwaddr_aton(cmd
, bssid
)) {
712 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
718 if (wpa_s
->ap_iface
) {
723 pos
= os_strchr(pin
, ' ');
730 return wpa_supplicant_ap_wps_pin(wpa_s
, _bssid
, pin
,
731 buf
, buflen
, timeout
);
733 #endif /* CONFIG_AP */
736 ret
= wpas_wps_start_pin(wpa_s
, _bssid
, pin
, 0,
740 ret
= os_snprintf(buf
, buflen
, "%s", pin
);
741 if (ret
< 0 || (size_t) ret
>= buflen
)
746 ret
= wpas_wps_start_pin(wpa_s
, _bssid
, NULL
, 0, DEV_PW_DEFAULT
);
751 /* Return the generated PIN */
752 ret
= os_snprintf(buf
, buflen
, "%08d", ret
);
753 if (ret
< 0 || (size_t) ret
>= buflen
)
759 static int wpa_supplicant_ctrl_iface_wps_check_pin(
760 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
767 wpa_hexdump_ascii_key(MSG_DEBUG
, "WPS_CHECK_PIN",
768 (u8
*) cmd
, os_strlen(cmd
));
769 for (pos
= cmd
, len
= 0; *pos
!= '\0'; pos
++) {
770 if (*pos
< '0' || *pos
> '9')
774 wpa_printf(MSG_DEBUG
, "WPS: Too long PIN");
778 if (len
!= 4 && len
!= 8) {
779 wpa_printf(MSG_DEBUG
, "WPS: Invalid PIN length %d", (int) len
);
785 unsigned int pin_val
;
787 if (!wps_pin_valid(pin_val
)) {
788 wpa_printf(MSG_DEBUG
, "WPS: Invalid checksum digit");
789 ret
= os_snprintf(buf
, buflen
, "FAIL-CHECKSUM\n");
790 if (ret
< 0 || (size_t) ret
>= buflen
)
796 ret
= os_snprintf(buf
, buflen
, "%s", pin
);
797 if (ret
< 0 || (size_t) ret
>= buflen
)
804 #ifdef CONFIG_WPS_NFC
806 static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant
*wpa_s
,
809 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
811 if (cmd
== NULL
|| cmd
[0] == '\0')
813 else if (hwaddr_aton(cmd
, bssid
))
816 return wpas_wps_start_nfc(wpa_s
, _bssid
, NULL
, 0, 0, NULL
, NULL
, 0);
820 static int wpa_supplicant_ctrl_iface_wps_nfc_config_token(
821 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
828 pos
= os_strchr(cmd
, ' ');
831 if (os_strcmp(cmd
, "WPS") == 0)
833 else if (os_strcmp(cmd
, "NDEF") == 0)
838 buf
= wpas_wps_nfc_config_token(wpa_s
, ndef
, pos
);
842 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
853 static int wpa_supplicant_ctrl_iface_wps_nfc_token(
854 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
860 if (os_strcmp(cmd
, "WPS") == 0)
862 else if (os_strcmp(cmd
, "NDEF") == 0)
867 buf
= wpas_wps_nfc_token(wpa_s
, ndef
);
871 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
882 static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
883 struct wpa_supplicant
*wpa_s
, char *pos
)
889 len
= os_strlen(pos
);
894 buf
= wpabuf_alloc(len
);
897 if (hexstr2bin(pos
, wpabuf_put(buf
, len
), len
) < 0) {
902 ret
= wpas_wps_nfc_tag_read(wpa_s
, buf
);
909 static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant
*wpa_s
,
910 char *reply
, size_t max_len
,
916 buf
= wpas_wps_nfc_handover_req(wpa_s
, ndef
);
920 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
931 static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant
*wpa_s
,
932 char *reply
, size_t max_len
,
938 buf
= wpas_p2p_nfc_handover_req(wpa_s
, ndef
);
940 wpa_printf(MSG_DEBUG
, "P2P: Could not generate NFC handover request");
944 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
955 static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant
*wpa_s
,
956 char *cmd
, char *reply
,
962 pos
= os_strchr(cmd
, ' ');
967 if (os_strcmp(cmd
, "WPS") == 0)
969 else if (os_strcmp(cmd
, "NDEF") == 0)
974 if (os_strcmp(pos
, "WPS") == 0 || os_strcmp(pos
, "WPS-CR") == 0) {
977 return wpas_ctrl_nfc_get_handover_req_wps(
978 wpa_s
, reply
, max_len
, ndef
);
981 if (os_strcmp(pos
, "P2P-CR") == 0) {
982 return wpas_ctrl_nfc_get_handover_req_p2p(
983 wpa_s
, reply
, max_len
, ndef
);
990 static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant
*wpa_s
,
991 char *reply
, size_t max_len
,
992 int ndef
, int cr
, char *uuid
)
997 buf
= wpas_wps_nfc_handover_sel(wpa_s
, ndef
, cr
, uuid
);
1001 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1003 reply
[res
++] = '\n';
1012 static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant
*wpa_s
,
1013 char *reply
, size_t max_len
,
1019 buf
= wpas_p2p_nfc_handover_sel(wpa_s
, ndef
, tag
);
1023 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1025 reply
[res
++] = '\n';
1034 static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant
*wpa_s
,
1035 char *cmd
, char *reply
,
1041 pos
= os_strchr(cmd
, ' ');
1046 if (os_strcmp(cmd
, "WPS") == 0)
1048 else if (os_strcmp(cmd
, "NDEF") == 0)
1053 pos2
= os_strchr(pos
, ' ');
1056 if (os_strcmp(pos
, "WPS") == 0 || os_strcmp(pos
, "WPS-CR") == 0) {
1059 return wpas_ctrl_nfc_get_handover_sel_wps(
1060 wpa_s
, reply
, max_len
, ndef
,
1061 os_strcmp(pos
, "WPS-CR") == 0, pos2
);
1064 if (os_strcmp(pos
, "P2P-CR") == 0) {
1065 return wpas_ctrl_nfc_get_handover_sel_p2p(
1066 wpa_s
, reply
, max_len
, ndef
, 0);
1069 if (os_strcmp(pos
, "P2P-CR-TAG") == 0) {
1070 return wpas_ctrl_nfc_get_handover_sel_p2p(
1071 wpa_s
, reply
, max_len
, ndef
, 1);
1078 static int wpas_ctrl_nfc_rx_handover_req(struct wpa_supplicant
*wpa_s
,
1079 char *cmd
, char *reply
,
1086 len
= os_strlen(cmd
);
1091 buf
= wpabuf_alloc(len
);
1094 if (hexstr2bin(cmd
, wpabuf_put(buf
, len
), len
) < 0) {
1099 ret
= wpas_wps_nfc_rx_handover_req(wpa_s
, buf
);
1106 static int wpas_ctrl_nfc_rx_handover_sel(struct wpa_supplicant
*wpa_s
,
1113 len
= os_strlen(cmd
);
1118 buf
= wpabuf_alloc(len
);
1121 if (hexstr2bin(cmd
, wpabuf_put(buf
, len
), len
) < 0) {
1126 ret
= wpas_wps_nfc_rx_handover_sel(wpa_s
, buf
);
1133 static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant
*wpa_s
,
1137 struct wpabuf
*req
, *sel
;
1139 char *pos
, *role
, *type
, *pos2
;
1142 pos
= os_strchr(role
, ' ');
1148 pos
= os_strchr(type
, ' ');
1153 pos2
= os_strchr(pos
, ' ');
1158 len
= os_strlen(pos
);
1163 req
= wpabuf_alloc(len
);
1166 if (hexstr2bin(pos
, wpabuf_put(req
, len
), len
) < 0) {
1171 len
= os_strlen(pos2
);
1178 sel
= wpabuf_alloc(len
);
1183 if (hexstr2bin(pos2
, wpabuf_put(sel
, len
), len
) < 0) {
1189 if (os_strcmp(role
, "INIT") == 0 && os_strcmp(type
, "WPS") == 0) {
1190 ret
= wpas_wps_nfc_report_handover(wpa_s
, req
, sel
);
1191 } else if (os_strcmp(role
, "RESP") == 0 && os_strcmp(type
, "WPS") == 0)
1193 ret
= wpas_ap_wps_nfc_report_handover(wpa_s
, req
, sel
);
1195 ret
= wpas_er_wps_nfc_report_handover(wpa_s
, req
, sel
);
1196 } else if (os_strcmp(role
, "INIT") == 0 && os_strcmp(type
, "P2P") == 0)
1198 ret
= wpas_p2p_nfc_report_handover(wpa_s
, 1, req
, sel
);
1199 } else if (os_strcmp(role
, "RESP") == 0 && os_strcmp(type
, "P2P") == 0)
1201 ret
= wpas_p2p_nfc_report_handover(wpa_s
, 0, req
, sel
);
1203 wpa_printf(MSG_DEBUG
, "NFC: Unsupported connection handover "
1204 "reported: role=%s type=%s", role
, type
);
1213 #endif /* CONFIG_WPS_NFC */
1216 static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant
*wpa_s
,
1225 struct wps_new_ap_settings ap
;
1227 pin
= os_strchr(cmd
, ' ');
1232 if (hwaddr_aton(cmd
, bssid
)) {
1233 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
1238 new_ssid
= os_strchr(pin
, ' ');
1239 if (new_ssid
== NULL
)
1240 return wpas_wps_start_reg(wpa_s
, bssid
, pin
, NULL
);
1243 new_auth
= os_strchr(new_ssid
, ' ');
1244 if (new_auth
== NULL
)
1248 new_encr
= os_strchr(new_auth
, ' ');
1249 if (new_encr
== NULL
)
1253 new_key
= os_strchr(new_encr
, ' ');
1254 if (new_key
== NULL
)
1258 os_memset(&ap
, 0, sizeof(ap
));
1259 ap
.ssid_hex
= new_ssid
;
1262 ap
.key_hex
= new_key
;
1263 return wpas_wps_start_reg(wpa_s
, bssid
, pin
, &ap
);
1268 static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant
*wpa_s
,
1269 char *cmd
, char *buf
,
1274 const char *pin_txt
;
1276 if (!wpa_s
->ap_iface
)
1279 pos
= os_strchr(cmd
, ' ');
1283 if (os_strcmp(cmd
, "disable") == 0) {
1284 wpas_wps_ap_pin_disable(wpa_s
);
1285 return os_snprintf(buf
, buflen
, "OK\n");
1288 if (os_strcmp(cmd
, "random") == 0) {
1290 timeout
= atoi(pos
);
1291 pin_txt
= wpas_wps_ap_pin_random(wpa_s
, timeout
);
1292 if (pin_txt
== NULL
)
1294 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
1297 if (os_strcmp(cmd
, "get") == 0) {
1298 pin_txt
= wpas_wps_ap_pin_get(wpa_s
);
1299 if (pin_txt
== NULL
)
1301 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
1304 if (os_strcmp(cmd
, "set") == 0) {
1309 pos
= os_strchr(pos
, ' ');
1312 timeout
= atoi(pos
);
1314 if (os_strlen(pin
) > buflen
)
1316 if (wpas_wps_ap_pin_set(wpa_s
, pin
, timeout
) < 0)
1318 return os_snprintf(buf
, buflen
, "%s", pin
);
1323 #endif /* CONFIG_AP */
1326 #ifdef CONFIG_WPS_ER
1327 static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant
*wpa_s
,
1330 char *uuid
= cmd
, *pin
, *pos
;
1331 u8 addr_buf
[ETH_ALEN
], *addr
= NULL
;
1332 pin
= os_strchr(uuid
, ' ');
1336 pos
= os_strchr(pin
, ' ');
1339 if (hwaddr_aton(pos
, addr_buf
) == 0)
1342 return wpas_wps_er_add_pin(wpa_s
, addr
, uuid
, pin
);
1346 static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant
*wpa_s
,
1349 char *uuid
= cmd
, *pin
;
1350 pin
= os_strchr(uuid
, ' ');
1354 return wpas_wps_er_learn(wpa_s
, uuid
, pin
);
1358 static int wpa_supplicant_ctrl_iface_wps_er_set_config(
1359 struct wpa_supplicant
*wpa_s
, char *cmd
)
1361 char *uuid
= cmd
, *id
;
1362 id
= os_strchr(uuid
, ' ');
1366 return wpas_wps_er_set_config(wpa_s
, uuid
, atoi(id
));
1370 static int wpa_supplicant_ctrl_iface_wps_er_config(
1371 struct wpa_supplicant
*wpa_s
, char *cmd
)
1378 struct wps_new_ap_settings ap
;
1380 pin
= os_strchr(cmd
, ' ');
1385 new_ssid
= os_strchr(pin
, ' ');
1386 if (new_ssid
== NULL
)
1390 new_auth
= os_strchr(new_ssid
, ' ');
1391 if (new_auth
== NULL
)
1395 new_encr
= os_strchr(new_auth
, ' ');
1396 if (new_encr
== NULL
)
1400 new_key
= os_strchr(new_encr
, ' ');
1401 if (new_key
== NULL
)
1405 os_memset(&ap
, 0, sizeof(ap
));
1406 ap
.ssid_hex
= new_ssid
;
1409 ap
.key_hex
= new_key
;
1410 return wpas_wps_er_config(wpa_s
, cmd
, pin
, &ap
);
1414 #ifdef CONFIG_WPS_NFC
1415 static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
1416 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
1423 uuid
= os_strchr(cmd
, ' ');
1428 if (os_strcmp(cmd
, "WPS") == 0)
1430 else if (os_strcmp(cmd
, "NDEF") == 0)
1435 buf
= wpas_wps_er_nfc_config_token(wpa_s
, ndef
, uuid
);
1439 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1441 reply
[res
++] = '\n';
1448 #endif /* CONFIG_WPS_NFC */
1449 #endif /* CONFIG_WPS_ER */
1451 #endif /* CONFIG_WPS */
1454 #ifdef CONFIG_IBSS_RSN
1455 static int wpa_supplicant_ctrl_iface_ibss_rsn(
1456 struct wpa_supplicant
*wpa_s
, char *addr
)
1460 if (hwaddr_aton(addr
, peer
)) {
1461 wpa_printf(MSG_DEBUG
, "CTRL_IFACE IBSS_RSN: invalid "
1462 "address '%s'", addr
);
1466 wpa_printf(MSG_DEBUG
, "CTRL_IFACE IBSS_RSN " MACSTR
,
1469 return ibss_rsn_start(wpa_s
->ibss_rsn
, peer
);
1471 #endif /* CONFIG_IBSS_RSN */
1474 static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant
*wpa_s
,
1477 #ifdef IEEE8021X_EAPOL
1480 struct wpa_ssid
*ssid
;
1482 pos
= os_strchr(rsp
, '-');
1487 pos
= os_strchr(pos
, ':');
1492 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: field=%s id=%d", rsp
, id
);
1493 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
1494 (u8
*) pos
, os_strlen(pos
));
1496 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1498 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
1503 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s
, ssid
, rsp
,
1505 #else /* IEEE8021X_EAPOL */
1506 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: 802.1X not included");
1508 #endif /* IEEE8021X_EAPOL */
1512 static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant
*wpa_s
,
1514 char *buf
, size_t buflen
)
1516 char *pos
, *end
, tmp
[30];
1517 int res
, verbose
, wps
, ret
;
1519 if (os_strcmp(params
, "-DRIVER") == 0)
1520 return wpa_drv_status(wpa_s
, buf
, buflen
);
1521 verbose
= os_strcmp(params
, "-VERBOSE") == 0;
1522 wps
= os_strcmp(params
, "-WPS") == 0;
1525 if (wpa_s
->wpa_state
>= WPA_ASSOCIATED
) {
1526 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
1527 ret
= os_snprintf(pos
, end
- pos
, "bssid=" MACSTR
"\n",
1528 MAC2STR(wpa_s
->bssid
));
1529 if (ret
< 0 || ret
>= end
- pos
)
1533 u8
*_ssid
= ssid
->ssid
;
1534 size_t ssid_len
= ssid
->ssid_len
;
1535 u8 ssid_buf
[MAX_SSID_LEN
];
1536 if (ssid_len
== 0) {
1537 int _res
= wpa_drv_get_ssid(wpa_s
, ssid_buf
);
1544 ret
= os_snprintf(pos
, end
- pos
, "ssid=%s\nid=%d\n",
1545 wpa_ssid_txt(_ssid
, ssid_len
),
1547 if (ret
< 0 || ret
>= end
- pos
)
1551 if (wps
&& ssid
->passphrase
&&
1552 wpa_key_mgmt_wpa_psk(ssid
->key_mgmt
) &&
1553 (ssid
->mode
== WPAS_MODE_AP
||
1554 ssid
->mode
== WPAS_MODE_P2P_GO
)) {
1555 ret
= os_snprintf(pos
, end
- pos
,
1558 if (ret
< 0 || ret
>= end
- pos
)
1563 ret
= os_snprintf(pos
, end
- pos
,
1566 if (ret
< 0 || ret
>= end
- pos
)
1571 switch (ssid
->mode
) {
1572 case WPAS_MODE_INFRA
:
1573 ret
= os_snprintf(pos
, end
- pos
,
1576 case WPAS_MODE_IBSS
:
1577 ret
= os_snprintf(pos
, end
- pos
,
1581 ret
= os_snprintf(pos
, end
- pos
,
1584 case WPAS_MODE_P2P_GO
:
1585 ret
= os_snprintf(pos
, end
- pos
,
1588 case WPAS_MODE_P2P_GROUP_FORMATION
:
1589 ret
= os_snprintf(pos
, end
- pos
,
1590 "mode=P2P GO - group "
1597 if (ret
< 0 || ret
>= end
- pos
)
1603 if (wpa_s
->ap_iface
) {
1604 pos
+= ap_ctrl_iface_wpa_get_status(wpa_s
, pos
,
1608 #endif /* CONFIG_AP */
1609 pos
+= wpa_sm_get_status(wpa_s
->wpa
, pos
, end
- pos
, verbose
);
1612 if (wpa_s
->wpa_state
>= WPA_ASSOCIATED
&&
1615 #endif /* CONFIG_AP */
1616 wpa_s
->sme
.sae
.state
== SAE_ACCEPTED
) {
1617 ret
= os_snprintf(pos
, end
- pos
, "sae_group=%d\n",
1618 wpa_s
->sme
.sae
.group
);
1619 if (ret
< 0 || ret
>= end
- pos
)
1623 #endif /* CONFIG_SAE */
1624 ret
= os_snprintf(pos
, end
- pos
, "wpa_state=%s\n",
1625 wpa_supplicant_state_txt(wpa_s
->wpa_state
));
1626 if (ret
< 0 || ret
>= end
- pos
)
1631 l2_packet_get_ip_addr(wpa_s
->l2
, tmp
, sizeof(tmp
)) >= 0) {
1632 ret
= os_snprintf(pos
, end
- pos
, "ip_address=%s\n", tmp
);
1633 if (ret
< 0 || ret
>= end
- pos
)
1639 if (wpa_s
->global
->p2p
) {
1640 ret
= os_snprintf(pos
, end
- pos
, "p2p_device_address=" MACSTR
1641 "\n", MAC2STR(wpa_s
->global
->p2p_dev_addr
));
1642 if (ret
< 0 || ret
>= end
- pos
)
1646 #endif /* CONFIG_P2P */
1648 ret
= os_snprintf(pos
, end
- pos
, "address=" MACSTR
"\n",
1649 MAC2STR(wpa_s
->own_addr
));
1650 if (ret
< 0 || ret
>= end
- pos
)
1655 if (wpa_s
->current_bss
&&
1656 wpa_bss_get_vendor_ie(wpa_s
->current_bss
, HS20_IE_VENDOR_TYPE
) &&
1657 wpa_s
->wpa_proto
== WPA_PROTO_RSN
&&
1658 wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
)) {
1659 ret
= os_snprintf(pos
, end
- pos
, "hs20=1\n");
1660 if (ret
< 0 || ret
>= end
- pos
)
1665 if (wpa_s
->current_ssid
) {
1666 struct wpa_cred
*cred
;
1669 for (cred
= wpa_s
->conf
->cred
; cred
; cred
= cred
->next
) {
1672 if (wpa_s
->current_ssid
->parent_cred
!= cred
)
1675 for (i
= 0; cred
->domain
&& i
< cred
->num_domain
; i
++) {
1676 ret
= os_snprintf(pos
, end
- pos
,
1679 if (ret
< 0 || ret
>= end
- pos
)
1684 if (wpa_s
->current_bss
== NULL
||
1685 wpa_s
->current_bss
->anqp
== NULL
)
1688 res
= interworking_home_sp_cred(
1690 wpa_s
->current_bss
->anqp
->domain_name
);
1698 ret
= os_snprintf(pos
, end
- pos
, "sp_type=%s\n", type
);
1699 if (ret
< 0 || ret
>= end
- pos
)
1706 #endif /* CONFIG_HS20 */
1708 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) ||
1709 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
1710 res
= eapol_sm_get_status(wpa_s
->eapol
, pos
, end
- pos
,
1716 res
= rsn_preauth_get_status(wpa_s
->wpa
, pos
, end
- pos
, verbose
);
1723 uuid_bin2str(wpa_s
->wps
->uuid
, uuid_str
, sizeof(uuid_str
));
1724 ret
= os_snprintf(pos
, end
- pos
, "uuid=%s\n", uuid_str
);
1725 if (ret
< 0 || ret
>= end
- pos
)
1729 #endif /* CONFIG_WPS */
1732 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_STATE_CHANGE
1733 "id=%d state=%d BSSID=" MACSTR
" SSID=%s",
1734 wpa_s
->current_ssid
? wpa_s
->current_ssid
->id
: -1,
1736 MAC2STR(wpa_s
->bssid
),
1737 wpa_s
->current_ssid
&& wpa_s
->current_ssid
->ssid
?
1738 wpa_ssid_txt(wpa_s
->current_ssid
->ssid
,
1739 wpa_s
->current_ssid
->ssid_len
) : "");
1740 if (wpa_s
->wpa_state
== WPA_COMPLETED
) {
1741 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
1742 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_CONNECTED
1743 "- connection to " MACSTR
1744 " completed %s [id=%d id_str=%s]",
1745 MAC2STR(wpa_s
->bssid
), "(auth)",
1746 ssid
? ssid
->id
: -1,
1747 ssid
&& ssid
->id_str
? ssid
->id_str
: "");
1749 #endif /* ANDROID */
1755 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant
*wpa_s
,
1760 struct wpa_ssid
*ssid
;
1763 /* cmd: "<network id> <BSSID>" */
1764 pos
= os_strchr(cmd
, ' ');
1769 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: id=%d bssid='%s'", id
, pos
);
1770 if (hwaddr_aton(pos
, bssid
)) {
1771 wpa_printf(MSG_DEBUG
,"CTRL_IFACE: invalid BSSID '%s'", pos
);
1775 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1777 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
1782 os_memcpy(ssid
->bssid
, bssid
, ETH_ALEN
);
1783 ssid
->bssid_set
= !is_zero_ether_addr(bssid
);
1789 static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant
*wpa_s
,
1790 char *cmd
, char *buf
,
1794 struct wpa_blacklist
*e
;
1798 /* cmd: "BLACKLIST [<BSSID>]" */
1802 e
= wpa_s
->blacklist
;
1804 ret
= os_snprintf(pos
, end
- pos
, MACSTR
"\n",
1806 if (ret
< 0 || ret
>= end
- pos
)
1815 if (os_strncmp(cmd
, "clear", 5) == 0) {
1816 wpa_blacklist_clear(wpa_s
);
1817 os_memcpy(buf
, "OK\n", 3);
1821 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd
);
1822 if (hwaddr_aton(cmd
, bssid
)) {
1823 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: invalid BSSID '%s'", cmd
);
1828 * Add the BSSID twice, so its count will be 2, causing it to be
1829 * skipped when processing scan results.
1831 ret
= wpa_blacklist_add(wpa_s
, bssid
);
1834 ret
= wpa_blacklist_add(wpa_s
, bssid
);
1837 os_memcpy(buf
, "OK\n", 3);
1842 static const char * debug_level_str(int level
)
1863 static int str_to_debug_level(const char *s
)
1865 if (os_strcasecmp(s
, "EXCESSIVE") == 0)
1866 return MSG_EXCESSIVE
;
1867 if (os_strcasecmp(s
, "MSGDUMP") == 0)
1869 if (os_strcasecmp(s
, "DEBUG") == 0)
1871 if (os_strcasecmp(s
, "INFO") == 0)
1873 if (os_strcasecmp(s
, "WARNING") == 0)
1875 if (os_strcasecmp(s
, "ERROR") == 0)
1881 static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant
*wpa_s
,
1882 char *cmd
, char *buf
,
1885 char *pos
, *end
, *stamp
;
1892 /* cmd: "LOG_LEVEL [<level>]" */
1896 ret
= os_snprintf(pos
, end
- pos
, "Current level: %s\n"
1898 debug_level_str(wpa_debug_level
),
1899 wpa_debug_timestamp
);
1900 if (ret
< 0 || ret
>= end
- pos
)
1909 stamp
= os_strchr(cmd
, ' ');
1912 while (*stamp
== ' ') {
1917 if (cmd
&& os_strlen(cmd
)) {
1918 int level
= str_to_debug_level(cmd
);
1921 wpa_debug_level
= level
;
1924 if (stamp
&& os_strlen(stamp
))
1925 wpa_debug_timestamp
= atoi(stamp
);
1927 os_memcpy(buf
, "OK\n", 3);
1932 static int wpa_supplicant_ctrl_iface_list_networks(
1933 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
1936 struct wpa_ssid
*ssid
;
1941 ret
= os_snprintf(pos
, end
- pos
,
1942 "network id / ssid / bssid / flags\n");
1943 if (ret
< 0 || ret
>= end
- pos
)
1947 ssid
= wpa_s
->conf
->ssid
;
1949 ret
= os_snprintf(pos
, end
- pos
, "%d\t%s",
1951 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
));
1952 if (ret
< 0 || ret
>= end
- pos
)
1955 if (ssid
->bssid_set
) {
1956 ret
= os_snprintf(pos
, end
- pos
, "\t" MACSTR
,
1957 MAC2STR(ssid
->bssid
));
1959 ret
= os_snprintf(pos
, end
- pos
, "\tany");
1961 if (ret
< 0 || ret
>= end
- pos
)
1964 ret
= os_snprintf(pos
, end
- pos
, "\t%s%s%s%s",
1965 ssid
== wpa_s
->current_ssid
?
1967 ssid
->disabled
? "[DISABLED]" : "",
1968 ssid
->disabled_until
.sec
?
1969 "[TEMP-DISABLED]" : "",
1970 ssid
->disabled
== 2 ? "[P2P-PERSISTENT]" :
1972 if (ret
< 0 || ret
>= end
- pos
)
1975 ret
= os_snprintf(pos
, end
- pos
, "\n");
1976 if (ret
< 0 || ret
>= end
- pos
)
1987 static char * wpa_supplicant_cipher_txt(char *pos
, char *end
, int cipher
)
1990 ret
= os_snprintf(pos
, end
- pos
, "-");
1991 if (ret
< 0 || ret
>= end
- pos
)
1994 ret
= wpa_write_ciphers(pos
, end
, cipher
, "+");
2002 static char * wpa_supplicant_ie_txt(char *pos
, char *end
, const char *proto
,
2003 const u8
*ie
, size_t ie_len
)
2005 struct wpa_ie_data data
;
2008 ret
= os_snprintf(pos
, end
- pos
, "[%s-", proto
);
2009 if (ret
< 0 || ret
>= end
- pos
)
2013 if (wpa_parse_wpa_ie(ie
, ie_len
, &data
) < 0) {
2014 ret
= os_snprintf(pos
, end
- pos
, "?]");
2015 if (ret
< 0 || ret
>= end
- pos
)
2022 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X
) {
2023 ret
= os_snprintf(pos
, end
- pos
, "%sEAP", first
? "" : "+");
2024 if (ret
< 0 || ret
>= end
- pos
)
2029 if (data
.key_mgmt
& WPA_KEY_MGMT_PSK
) {
2030 ret
= os_snprintf(pos
, end
- pos
, "%sPSK", first
? "" : "+");
2031 if (ret
< 0 || ret
>= end
- pos
)
2036 if (data
.key_mgmt
& WPA_KEY_MGMT_WPA_NONE
) {
2037 ret
= os_snprintf(pos
, end
- pos
, "%sNone", first
? "" : "+");
2038 if (ret
< 0 || ret
>= end
- pos
)
2043 #ifdef CONFIG_IEEE80211R
2044 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_IEEE8021X
) {
2045 ret
= os_snprintf(pos
, end
- pos
, "%sFT/EAP",
2047 if (ret
< 0 || ret
>= end
- pos
)
2052 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_PSK
) {
2053 ret
= os_snprintf(pos
, end
- pos
, "%sFT/PSK",
2055 if (ret
< 0 || ret
>= end
- pos
)
2060 #endif /* CONFIG_IEEE80211R */
2061 #ifdef CONFIG_IEEE80211W
2062 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SHA256
) {
2063 ret
= os_snprintf(pos
, end
- pos
, "%sEAP-SHA256",
2065 if (ret
< 0 || ret
>= end
- pos
)
2070 if (data
.key_mgmt
& WPA_KEY_MGMT_PSK_SHA256
) {
2071 ret
= os_snprintf(pos
, end
- pos
, "%sPSK-SHA256",
2073 if (ret
< 0 || ret
>= end
- pos
)
2078 #endif /* CONFIG_IEEE80211W */
2080 pos
= wpa_supplicant_cipher_txt(pos
, end
, data
.pairwise_cipher
);
2082 if (data
.capabilities
& WPA_CAPABILITY_PREAUTH
) {
2083 ret
= os_snprintf(pos
, end
- pos
, "-preauth");
2084 if (ret
< 0 || ret
>= end
- pos
)
2089 ret
= os_snprintf(pos
, end
- pos
, "]");
2090 if (ret
< 0 || ret
>= end
- pos
)
2099 static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant
*wpa_s
,
2100 char *pos
, char *end
,
2101 struct wpabuf
*wps_ie
)
2108 if (wps_is_selected_pbc_registrar(wps_ie
))
2111 else if (wps_is_addr_authorized(wps_ie
, wpa_s
->own_addr
, 0))
2113 #endif /* CONFIG_WPS2 */
2114 else if (wps_is_selected_pin_registrar(wps_ie
))
2119 ret
= os_snprintf(pos
, end
- pos
, "%s", txt
);
2120 if (ret
>= 0 && ret
< end
- pos
)
2122 wpabuf_free(wps_ie
);
2125 #endif /* CONFIG_WPS */
2128 static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant
*wpa_s
,
2129 char *pos
, char *end
,
2130 const struct wpa_bss
*bss
)
2133 struct wpabuf
*wps_ie
;
2134 wps_ie
= wpa_bss_get_vendor_ie_multi(bss
, WPS_IE_VENDOR_TYPE
);
2135 return wpa_supplicant_wps_ie_txt_buf(wpa_s
, pos
, end
, wps_ie
);
2136 #else /* CONFIG_WPS */
2138 #endif /* CONFIG_WPS */
2142 /* Format one result on one text line into a buffer. */
2143 static int wpa_supplicant_ctrl_iface_scan_result(
2144 struct wpa_supplicant
*wpa_s
,
2145 const struct wpa_bss
*bss
, char *buf
, size_t buflen
)
2149 const u8
*ie
, *ie2
, *p2p
;
2151 p2p
= wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
);
2153 p2p
= wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
);
2154 if (p2p
&& bss
->ssid_len
== P2P_WILDCARD_SSID_LEN
&&
2155 os_memcmp(bss
->ssid
, P2P_WILDCARD_SSID
, P2P_WILDCARD_SSID_LEN
) ==
2157 return 0; /* Do not show P2P listen discovery results here */
2162 ret
= os_snprintf(pos
, end
- pos
, MACSTR
"\t%d\t%d\t",
2163 MAC2STR(bss
->bssid
), bss
->freq
, bss
->level
);
2164 if (ret
< 0 || ret
>= end
- pos
)
2167 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
2169 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA", ie
, 2 + ie
[1]);
2170 ie2
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
2172 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA2", ie2
, 2 + ie2
[1]);
2173 pos
= wpa_supplicant_wps_ie_txt(wpa_s
, pos
, end
, bss
);
2174 if (!ie
&& !ie2
&& bss
->caps
& IEEE80211_CAP_PRIVACY
) {
2175 ret
= os_snprintf(pos
, end
- pos
, "[WEP]");
2176 if (ret
< 0 || ret
>= end
- pos
)
2180 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
2181 ret
= os_snprintf(pos
, end
- pos
, "[IBSS]");
2182 if (ret
< 0 || ret
>= end
- pos
)
2186 if (bss
->caps
& IEEE80211_CAP_ESS
) {
2187 ret
= os_snprintf(pos
, end
- pos
, "[ESS]");
2188 if (ret
< 0 || ret
>= end
- pos
)
2193 ret
= os_snprintf(pos
, end
- pos
, "[P2P]");
2194 if (ret
< 0 || ret
>= end
- pos
)
2199 if (wpa_bss_get_vendor_ie(bss
, HS20_IE_VENDOR_TYPE
) && ie2
) {
2200 ret
= os_snprintf(pos
, end
- pos
, "[HS20]");
2201 if (ret
< 0 || ret
>= end
- pos
)
2205 #endif /* CONFIG_HS20 */
2207 ret
= os_snprintf(pos
, end
- pos
, "\t%s",
2208 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
2209 if (ret
< 0 || ret
>= end
- pos
)
2213 ret
= os_snprintf(pos
, end
- pos
, "\n");
2214 if (ret
< 0 || ret
>= end
- pos
)
2222 static int wpa_supplicant_ctrl_iface_scan_results(
2223 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
2226 struct wpa_bss
*bss
;
2231 ret
= os_snprintf(pos
, end
- pos
, "bssid / frequency / signal level / "
2233 if (ret
< 0 || ret
>= end
- pos
)
2237 dl_list_for_each(bss
, &wpa_s
->bss_id
, struct wpa_bss
, list_id
) {
2238 ret
= wpa_supplicant_ctrl_iface_scan_result(wpa_s
, bss
, pos
,
2240 if (ret
< 0 || ret
>= end
- pos
)
2249 static int wpa_supplicant_ctrl_iface_select_network(
2250 struct wpa_supplicant
*wpa_s
, char *cmd
)
2253 struct wpa_ssid
*ssid
;
2255 /* cmd: "<network id>" or "any" */
2256 if (os_strcmp(cmd
, "any") == 0) {
2257 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SELECT_NETWORK any");
2261 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SELECT_NETWORK id=%d", id
);
2263 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2265 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
2266 "network id=%d", id
);
2269 if (ssid
->disabled
== 2) {
2270 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
2271 "SELECT_NETWORK with persistent P2P group");
2276 wpa_supplicant_select_network(wpa_s
, ssid
);
2282 static int wpa_supplicant_ctrl_iface_enable_network(
2283 struct wpa_supplicant
*wpa_s
, char *cmd
)
2286 struct wpa_ssid
*ssid
;
2288 /* cmd: "<network id>" or "all" */
2289 if (os_strcmp(cmd
, "all") == 0) {
2290 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ENABLE_NETWORK all");
2294 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ENABLE_NETWORK id=%d", id
);
2296 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2298 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
2299 "network id=%d", id
);
2302 if (ssid
->disabled
== 2) {
2303 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
2304 "ENABLE_NETWORK with persistent P2P group");
2308 if (os_strstr(cmd
, " no-connect")) {
2313 wpa_supplicant_enable_network(wpa_s
, ssid
);
2319 static int wpa_supplicant_ctrl_iface_disable_network(
2320 struct wpa_supplicant
*wpa_s
, char *cmd
)
2323 struct wpa_ssid
*ssid
;
2325 /* cmd: "<network id>" or "all" */
2326 if (os_strcmp(cmd
, "all") == 0) {
2327 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DISABLE_NETWORK all");
2331 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DISABLE_NETWORK id=%d", id
);
2333 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2335 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
2336 "network id=%d", id
);
2339 if (ssid
->disabled
== 2) {
2340 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
2341 "DISABLE_NETWORK with persistent P2P "
2346 wpa_supplicant_disable_network(wpa_s
, ssid
);
2352 static int wpa_supplicant_ctrl_iface_add_network(
2353 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
2355 struct wpa_ssid
*ssid
;
2358 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ADD_NETWORK");
2360 ssid
= wpa_config_add_network(wpa_s
->conf
);
2364 wpas_notify_network_added(wpa_s
, ssid
);
2367 wpa_config_set_network_defaults(ssid
);
2369 ret
= os_snprintf(buf
, buflen
, "%d\n", ssid
->id
);
2370 if (ret
< 0 || (size_t) ret
>= buflen
)
2376 static int wpa_supplicant_ctrl_iface_remove_network(
2377 struct wpa_supplicant
*wpa_s
, char *cmd
)
2380 struct wpa_ssid
*ssid
;
2383 /* cmd: "<network id>" or "all" */
2384 if (os_strcmp(cmd
, "all") == 0) {
2385 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_NETWORK all");
2386 if (wpa_s
->sched_scanning
)
2387 wpa_supplicant_cancel_sched_scan(wpa_s
);
2389 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
2390 if (wpa_s
->current_ssid
) {
2392 wpa_s
->sme
.prev_bssid_set
= 0;
2393 #endif /* CONFIG_SME */
2394 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
2395 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
2396 wpa_supplicant_deauthenticate(
2397 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2399 ssid
= wpa_s
->conf
->ssid
;
2401 struct wpa_ssid
*remove_ssid
= ssid
;
2404 wpas_notify_network_removed(wpa_s
, remove_ssid
);
2405 wpa_config_remove_network(wpa_s
->conf
, id
);
2411 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_NETWORK id=%d", id
);
2413 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2415 wpas_notify_network_removed(wpa_s
, ssid
);
2417 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
2422 if (ssid
== wpa_s
->current_ssid
|| wpa_s
->current_ssid
== NULL
) {
2424 wpa_s
->sme
.prev_bssid_set
= 0;
2425 #endif /* CONFIG_SME */
2427 * Invalidate the EAP session cache if the current or
2428 * previously used network is removed.
2430 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
2433 if (ssid
== wpa_s
->current_ssid
) {
2434 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
2435 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
2437 wpa_supplicant_deauthenticate(wpa_s
,
2438 WLAN_REASON_DEAUTH_LEAVING
);
2441 was_disabled
= ssid
->disabled
;
2443 if (wpa_config_remove_network(wpa_s
->conf
, id
) < 0) {
2444 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Not able to remove the "
2445 "network id=%d", id
);
2449 if (!was_disabled
&& wpa_s
->sched_scanning
) {
2450 wpa_printf(MSG_DEBUG
, "Stop ongoing sched_scan to remove "
2451 "network from filters");
2452 wpa_supplicant_cancel_sched_scan(wpa_s
);
2453 wpa_supplicant_req_scan(wpa_s
, 0, 0);
2460 static int wpa_supplicant_ctrl_iface_set_network(
2461 struct wpa_supplicant
*wpa_s
, char *cmd
)
2464 struct wpa_ssid
*ssid
;
2467 /* cmd: "<network id> <variable name> <value>" */
2468 name
= os_strchr(cmd
, ' ');
2473 value
= os_strchr(name
, ' ');
2479 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
2481 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
2482 (u8
*) value
, os_strlen(value
));
2484 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2486 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
2491 if (wpa_config_set(ssid
, name
, value
, 0) < 0) {
2492 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to set network "
2493 "variable '%s'", name
);
2497 if (os_strcmp(name
, "bssid") != 0 &&
2498 os_strcmp(name
, "priority") != 0)
2499 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, ssid
);
2501 if (wpa_s
->current_ssid
== ssid
|| wpa_s
->current_ssid
== NULL
) {
2503 * Invalidate the EAP session cache if anything in the current
2504 * or previously used configuration changes.
2506 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
2509 if ((os_strcmp(name
, "psk") == 0 &&
2510 value
[0] == '"' && ssid
->ssid_len
) ||
2511 (os_strcmp(name
, "ssid") == 0 && ssid
->passphrase
))
2512 wpa_config_update_psk(ssid
);
2513 else if (os_strcmp(name
, "priority") == 0)
2514 wpa_config_update_prio_list(wpa_s
->conf
);
2520 static int wpa_supplicant_ctrl_iface_get_network(
2521 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
2525 struct wpa_ssid
*ssid
;
2528 /* cmd: "<network id> <variable name>" */
2529 name
= os_strchr(cmd
, ' ');
2530 if (name
== NULL
|| buflen
== 0)
2535 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
2538 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2540 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
2545 value
= wpa_config_get_no_key(ssid
, name
);
2546 if (value
== NULL
) {
2547 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to get network "
2548 "variable '%s'", name
);
2552 res
= os_strlcpy(buf
, value
, buflen
);
2553 if (res
>= buflen
) {
2564 static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant
*wpa_s
,
2565 char *buf
, size_t buflen
)
2568 struct wpa_cred
*cred
;
2573 ret
= os_snprintf(pos
, end
- pos
,
2574 "cred id / realm / username / domain / imsi\n");
2575 if (ret
< 0 || ret
>= end
- pos
)
2579 cred
= wpa_s
->conf
->cred
;
2581 ret
= os_snprintf(pos
, end
- pos
, "%d\t%s\t%s\t%s\t%s\n",
2582 cred
->id
, cred
->realm
? cred
->realm
: "",
2583 cred
->username
? cred
->username
: "",
2584 cred
->domain
? cred
->domain
[0] : "",
2585 cred
->imsi
? cred
->imsi
: "");
2586 if (ret
< 0 || ret
>= end
- pos
)
2597 static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant
*wpa_s
,
2598 char *buf
, size_t buflen
)
2600 struct wpa_cred
*cred
;
2603 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ADD_CRED");
2605 cred
= wpa_config_add_cred(wpa_s
->conf
);
2609 ret
= os_snprintf(buf
, buflen
, "%d\n", cred
->id
);
2610 if (ret
< 0 || (size_t) ret
>= buflen
)
2616 static int wpas_ctrl_remove_cred(struct wpa_supplicant
*wpa_s
,
2617 struct wpa_cred
*cred
)
2619 struct wpa_ssid
*ssid
;
2622 if (cred
== NULL
|| wpa_config_remove_cred(wpa_s
->conf
, cred
->id
) < 0) {
2623 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred");
2627 /* Remove any network entry created based on the removed credential */
2628 ssid
= wpa_s
->conf
->ssid
;
2630 if (ssid
->parent_cred
== cred
) {
2631 wpa_printf(MSG_DEBUG
, "Remove network id %d since it "
2632 "used the removed credential", ssid
->id
);
2633 os_snprintf(str
, sizeof(str
), "%d", ssid
->id
);
2635 wpa_supplicant_ctrl_iface_remove_network(wpa_s
, str
);
2644 static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant
*wpa_s
,
2648 struct wpa_cred
*cred
, *prev
;
2650 /* cmd: "<cred id>", "all", or "sp_fqdn=<FQDN>" */
2651 if (os_strcmp(cmd
, "all") == 0) {
2652 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED all");
2653 cred
= wpa_s
->conf
->cred
;
2657 wpas_ctrl_remove_cred(wpa_s
, prev
);
2662 if (os_strncmp(cmd
, "sp_fqdn=", 8) == 0) {
2663 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
2665 cred
= wpa_s
->conf
->cred
;
2671 for (i
= 0; i
< prev
->num_domain
; i
++) {
2672 if (os_strcmp(prev
->domain
[i
], cmd
+ 8)
2675 wpas_ctrl_remove_cred(wpa_s
, prev
);
2684 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED id=%d", id
);
2686 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
2687 return wpas_ctrl_remove_cred(wpa_s
, cred
);
2691 static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant
*wpa_s
,
2695 struct wpa_cred
*cred
;
2698 /* cmd: "<cred id> <variable name> <value>" */
2699 name
= os_strchr(cmd
, ' ');
2704 value
= os_strchr(name
, ' ');
2710 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SET_CRED id=%d name='%s'",
2712 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
2713 (u8
*) value
, os_strlen(value
));
2715 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
2717 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred id=%d",
2722 if (wpa_config_set_cred(cred
, name
, value
, 0) < 0) {
2723 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to set cred "
2724 "variable '%s'", name
);
2732 #ifndef CONFIG_NO_CONFIG_WRITE
2733 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant
*wpa_s
)
2737 if (!wpa_s
->conf
->update_config
) {
2738 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
2739 "to update configuration (update_config=0)");
2743 ret
= wpa_config_write(wpa_s
->confname
, wpa_s
->conf
);
2745 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Failed to "
2746 "update configuration");
2748 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Configuration"
2754 #endif /* CONFIG_NO_CONFIG_WRITE */
2757 struct cipher_info
{
2763 static const struct cipher_info ciphers
[] = {
2764 { WPA_DRIVER_CAPA_ENC_CCMP_256
, "CCMP-256", 0 },
2765 { WPA_DRIVER_CAPA_ENC_GCMP_256
, "GCMP-256", 0 },
2766 { WPA_DRIVER_CAPA_ENC_CCMP
, "CCMP", 0 },
2767 { WPA_DRIVER_CAPA_ENC_GCMP
, "GCMP", 0 },
2768 { WPA_DRIVER_CAPA_ENC_TKIP
, "TKIP", 0 },
2769 { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
, "NONE", 0 },
2770 { WPA_DRIVER_CAPA_ENC_WEP104
, "WEP104", 1 },
2771 { WPA_DRIVER_CAPA_ENC_WEP40
, "WEP40", 1 }
2775 static int ctrl_iface_get_capability_pairwise(int res
, char *strict
,
2776 struct wpa_driver_capa
*capa
,
2777 char *buf
, size_t buflen
)
2790 len
= os_strlcpy(buf
, "CCMP TKIP NONE", buflen
);
2796 for (i
= 0; i
< ARRAY_SIZE(ciphers
); i
++) {
2797 if (!ciphers
[i
].group_only
&& capa
->enc
& ciphers
[i
].capa
) {
2798 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
2799 first
? "" : " ", ciphers
[i
].name
);
2800 if (ret
< 0 || ret
>= end
- pos
)
2811 static int ctrl_iface_get_capability_group(int res
, char *strict
,
2812 struct wpa_driver_capa
*capa
,
2813 char *buf
, size_t buflen
)
2826 len
= os_strlcpy(buf
, "CCMP TKIP WEP104 WEP40", buflen
);
2832 for (i
= 0; i
< ARRAY_SIZE(ciphers
); i
++) {
2833 if (capa
->enc
& ciphers
[i
].capa
) {
2834 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
2835 first
? "" : " ", ciphers
[i
].name
);
2836 if (ret
< 0 || ret
>= end
- pos
)
2847 static int ctrl_iface_get_capability_key_mgmt(int res
, char *strict
,
2848 struct wpa_driver_capa
*capa
,
2849 char *buf
, size_t buflen
)
2861 len
= os_strlcpy(buf
, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
2868 ret
= os_snprintf(pos
, end
- pos
, "NONE IEEE8021X");
2869 if (ret
< 0 || ret
>= end
- pos
)
2873 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
2874 WPA_DRIVER_CAPA_KEY_MGMT_WPA2
)) {
2875 ret
= os_snprintf(pos
, end
- pos
, " WPA-EAP");
2876 if (ret
< 0 || ret
>= end
- pos
)
2881 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
|
2882 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
)) {
2883 ret
= os_snprintf(pos
, end
- pos
, " WPA-PSK");
2884 if (ret
< 0 || ret
>= end
- pos
)
2889 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
) {
2890 ret
= os_snprintf(pos
, end
- pos
, " WPA-NONE");
2891 if (ret
< 0 || ret
>= end
- pos
)
2900 static int ctrl_iface_get_capability_proto(int res
, char *strict
,
2901 struct wpa_driver_capa
*capa
,
2902 char *buf
, size_t buflen
)
2914 len
= os_strlcpy(buf
, "RSN WPA", buflen
);
2920 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA2
|
2921 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
)) {
2922 ret
= os_snprintf(pos
, end
- pos
, "%sRSN", first
? "" : " ");
2923 if (ret
< 0 || ret
>= end
- pos
)
2929 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
2930 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
)) {
2931 ret
= os_snprintf(pos
, end
- pos
, "%sWPA", first
? "" : " ");
2932 if (ret
< 0 || ret
>= end
- pos
)
2942 static int ctrl_iface_get_capability_auth_alg(int res
, char *strict
,
2943 struct wpa_driver_capa
*capa
,
2944 char *buf
, size_t buflen
)
2956 len
= os_strlcpy(buf
, "OPEN SHARED LEAP", buflen
);
2962 if (capa
->auth
& (WPA_DRIVER_AUTH_OPEN
)) {
2963 ret
= os_snprintf(pos
, end
- pos
, "%sOPEN", first
? "" : " ");
2964 if (ret
< 0 || ret
>= end
- pos
)
2970 if (capa
->auth
& (WPA_DRIVER_AUTH_SHARED
)) {
2971 ret
= os_snprintf(pos
, end
- pos
, "%sSHARED",
2973 if (ret
< 0 || ret
>= end
- pos
)
2979 if (capa
->auth
& (WPA_DRIVER_AUTH_LEAP
)) {
2980 ret
= os_snprintf(pos
, end
- pos
, "%sLEAP", first
? "" : " ");
2981 if (ret
< 0 || ret
>= end
- pos
)
2991 static int ctrl_iface_get_capability_modes(int res
, char *strict
,
2992 struct wpa_driver_capa
*capa
,
2993 char *buf
, size_t buflen
)
3005 len
= os_strlcpy(buf
, "IBSS AP", buflen
);
3011 if (capa
->flags
& WPA_DRIVER_FLAGS_IBSS
) {
3012 ret
= os_snprintf(pos
, end
- pos
, "%sIBSS", first
? "" : " ");
3013 if (ret
< 0 || ret
>= end
- pos
)
3019 if (capa
->flags
& WPA_DRIVER_FLAGS_AP
) {
3020 ret
= os_snprintf(pos
, end
- pos
, "%sAP", first
? "" : " ");
3021 if (ret
< 0 || ret
>= end
- pos
)
3031 static int ctrl_iface_get_capability_channels(struct wpa_supplicant
*wpa_s
,
3032 char *buf
, size_t buflen
)
3034 struct hostapd_channel_data
*chnl
;
3036 char *pos
, *end
, *hmode
;
3041 for (j
= 0; j
< wpa_s
->hw
.num_modes
; j
++) {
3042 switch (wpa_s
->hw
.modes
[j
].mode
) {
3043 case HOSTAPD_MODE_IEEE80211B
:
3046 case HOSTAPD_MODE_IEEE80211G
:
3049 case HOSTAPD_MODE_IEEE80211A
:
3052 case HOSTAPD_MODE_IEEE80211AD
:
3058 ret
= os_snprintf(pos
, end
- pos
, "Mode[%s] Channels:", hmode
);
3059 if (ret
< 0 || ret
>= end
- pos
)
3062 chnl
= wpa_s
->hw
.modes
[j
].channels
;
3063 for (i
= 0; i
< wpa_s
->hw
.modes
[j
].num_channels
; i
++) {
3064 if (chnl
[i
].flag
& HOSTAPD_CHAN_DISABLED
)
3066 ret
= os_snprintf(pos
, end
- pos
, " %d", chnl
[i
].chan
);
3067 if (ret
< 0 || ret
>= end
- pos
)
3071 ret
= os_snprintf(pos
, end
- pos
, "\n");
3072 if (ret
< 0 || ret
>= end
- pos
)
3081 static int ctrl_iface_get_capability_freq(struct wpa_supplicant
*wpa_s
,
3082 char *buf
, size_t buflen
)
3084 struct hostapd_channel_data
*chnl
;
3086 char *pos
, *end
, *hmode
;
3091 for (j
= 0; j
< wpa_s
->hw
.num_modes
; j
++) {
3092 switch (wpa_s
->hw
.modes
[j
].mode
) {
3093 case HOSTAPD_MODE_IEEE80211B
:
3096 case HOSTAPD_MODE_IEEE80211G
:
3099 case HOSTAPD_MODE_IEEE80211A
:
3102 case HOSTAPD_MODE_IEEE80211AD
:
3108 ret
= os_snprintf(pos
, end
- pos
, "Mode[%s] Channels:\n",
3110 if (ret
< 0 || ret
>= end
- pos
)
3113 chnl
= wpa_s
->hw
.modes
[j
].channels
;
3114 for (i
= 0; i
< wpa_s
->hw
.modes
[j
].num_channels
; i
++) {
3115 if (chnl
[i
].flag
& HOSTAPD_CHAN_DISABLED
)
3117 ret
= os_snprintf(pos
, end
- pos
, " %d = %d MHz%s\n",
3118 chnl
[i
].chan
, chnl
[i
].freq
,
3119 chnl
[i
].flag
& HOSTAPD_CHAN_NO_IBSS
?
3121 if (ret
< 0 || ret
>= end
- pos
)
3125 ret
= os_snprintf(pos
, end
- pos
, "\n");
3126 if (ret
< 0 || ret
>= end
- pos
)
3135 static int wpa_supplicant_ctrl_iface_get_capability(
3136 struct wpa_supplicant
*wpa_s
, const char *_field
, char *buf
,
3139 struct wpa_driver_capa capa
;
3145 /* Determine whether or not strict checking was requested */
3146 len
= os_strlcpy(field
, _field
, sizeof(field
));
3147 if (len
>= sizeof(field
))
3149 strict
= os_strchr(field
, ' ');
3150 if (strict
!= NULL
) {
3152 if (os_strcmp(strict
, "strict") != 0)
3156 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
3157 field
, strict
? strict
: "");
3159 if (os_strcmp(field
, "eap") == 0) {
3160 return eap_get_names(buf
, buflen
);
3163 res
= wpa_drv_get_capa(wpa_s
, &capa
);
3165 if (os_strcmp(field
, "pairwise") == 0)
3166 return ctrl_iface_get_capability_pairwise(res
, strict
, &capa
,
3169 if (os_strcmp(field
, "group") == 0)
3170 return ctrl_iface_get_capability_group(res
, strict
, &capa
,
3173 if (os_strcmp(field
, "key_mgmt") == 0)
3174 return ctrl_iface_get_capability_key_mgmt(res
, strict
, &capa
,
3177 if (os_strcmp(field
, "proto") == 0)
3178 return ctrl_iface_get_capability_proto(res
, strict
, &capa
,
3181 if (os_strcmp(field
, "auth_alg") == 0)
3182 return ctrl_iface_get_capability_auth_alg(res
, strict
, &capa
,
3185 if (os_strcmp(field
, "modes") == 0)
3186 return ctrl_iface_get_capability_modes(res
, strict
, &capa
,
3189 if (os_strcmp(field
, "channels") == 0)
3190 return ctrl_iface_get_capability_channels(wpa_s
, buf
, buflen
);
3192 if (os_strcmp(field
, "freq") == 0)
3193 return ctrl_iface_get_capability_freq(wpa_s
, buf
, buflen
);
3195 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
3202 #ifdef CONFIG_INTERWORKING
3203 static char * anqp_add_hex(char *pos
, char *end
, const char *title
,
3204 struct wpabuf
*data
)
3214 ret
= os_snprintf(pos
, end
- pos
, "%s=", title
);
3215 if (ret
< 0 || ret
>= end
- pos
)
3219 d
= wpabuf_head_u8(data
);
3220 for (i
= 0; i
< wpabuf_len(data
); i
++) {
3221 ret
= os_snprintf(pos
, end
- pos
, "%02x", *d
++);
3222 if (ret
< 0 || ret
>= end
- pos
)
3227 ret
= os_snprintf(pos
, end
- pos
, "\n");
3228 if (ret
< 0 || ret
>= end
- pos
)
3234 #endif /* CONFIG_INTERWORKING */
3237 static int print_bss_info(struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
,
3238 unsigned long mask
, char *buf
, size_t buflen
)
3248 if (mask
& WPA_BSS_MASK_ID
) {
3249 ret
= os_snprintf(pos
, end
- pos
, "id=%u\n", bss
->id
);
3250 if (ret
< 0 || ret
>= end
- pos
)
3255 if (mask
& WPA_BSS_MASK_BSSID
) {
3256 ret
= os_snprintf(pos
, end
- pos
, "bssid=" MACSTR
"\n",
3257 MAC2STR(bss
->bssid
));
3258 if (ret
< 0 || ret
>= end
- pos
)
3263 if (mask
& WPA_BSS_MASK_FREQ
) {
3264 ret
= os_snprintf(pos
, end
- pos
, "freq=%d\n", bss
->freq
);
3265 if (ret
< 0 || ret
>= end
- pos
)
3270 if (mask
& WPA_BSS_MASK_BEACON_INT
) {
3271 ret
= os_snprintf(pos
, end
- pos
, "beacon_int=%d\n",
3273 if (ret
< 0 || ret
>= end
- pos
)
3278 if (mask
& WPA_BSS_MASK_CAPABILITIES
) {
3279 ret
= os_snprintf(pos
, end
- pos
, "capabilities=0x%04x\n",
3281 if (ret
< 0 || ret
>= end
- pos
)
3286 if (mask
& WPA_BSS_MASK_QUAL
) {
3287 ret
= os_snprintf(pos
, end
- pos
, "qual=%d\n", bss
->qual
);
3288 if (ret
< 0 || ret
>= end
- pos
)
3293 if (mask
& WPA_BSS_MASK_NOISE
) {
3294 ret
= os_snprintf(pos
, end
- pos
, "noise=%d\n", bss
->noise
);
3295 if (ret
< 0 || ret
>= end
- pos
)
3300 if (mask
& WPA_BSS_MASK_LEVEL
) {
3301 ret
= os_snprintf(pos
, end
- pos
, "level=%d\n", bss
->level
);
3302 if (ret
< 0 || ret
>= end
- pos
)
3307 if (mask
& WPA_BSS_MASK_TSF
) {
3308 ret
= os_snprintf(pos
, end
- pos
, "tsf=%016llu\n",
3309 (unsigned long long) bss
->tsf
);
3310 if (ret
< 0 || ret
>= end
- pos
)
3315 if (mask
& WPA_BSS_MASK_AGE
) {
3316 struct os_reltime now
;
3318 os_get_reltime(&now
);
3319 ret
= os_snprintf(pos
, end
- pos
, "age=%d\n",
3320 (int) (now
.sec
- bss
->last_update
.sec
));
3321 if (ret
< 0 || ret
>= end
- pos
)
3326 if (mask
& WPA_BSS_MASK_IE
) {
3327 ret
= os_snprintf(pos
, end
- pos
, "ie=");
3328 if (ret
< 0 || ret
>= end
- pos
)
3332 ie
= (const u8
*) (bss
+ 1);
3333 for (i
= 0; i
< bss
->ie_len
; i
++) {
3334 ret
= os_snprintf(pos
, end
- pos
, "%02x", *ie
++);
3335 if (ret
< 0 || ret
>= end
- pos
)
3340 ret
= os_snprintf(pos
, end
- pos
, "\n");
3341 if (ret
< 0 || ret
>= end
- pos
)
3346 if (mask
& WPA_BSS_MASK_FLAGS
) {
3347 ret
= os_snprintf(pos
, end
- pos
, "flags=");
3348 if (ret
< 0 || ret
>= end
- pos
)
3352 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
3354 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA", ie
,
3356 ie2
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
3358 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA2", ie2
,
3360 pos
= wpa_supplicant_wps_ie_txt(wpa_s
, pos
, end
, bss
);
3361 if (!ie
&& !ie2
&& bss
->caps
& IEEE80211_CAP_PRIVACY
) {
3362 ret
= os_snprintf(pos
, end
- pos
, "[WEP]");
3363 if (ret
< 0 || ret
>= end
- pos
)
3367 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
3368 ret
= os_snprintf(pos
, end
- pos
, "[IBSS]");
3369 if (ret
< 0 || ret
>= end
- pos
)
3373 if (bss
->caps
& IEEE80211_CAP_ESS
) {
3374 ret
= os_snprintf(pos
, end
- pos
, "[ESS]");
3375 if (ret
< 0 || ret
>= end
- pos
)
3379 if (wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
) ||
3380 wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
)) {
3381 ret
= os_snprintf(pos
, end
- pos
, "[P2P]");
3382 if (ret
< 0 || ret
>= end
- pos
)
3387 if (wpa_bss_get_vendor_ie(bss
, HS20_IE_VENDOR_TYPE
)) {
3388 ret
= os_snprintf(pos
, end
- pos
, "[HS20]");
3389 if (ret
< 0 || ret
>= end
- pos
)
3393 #endif /* CONFIG_HS20 */
3395 ret
= os_snprintf(pos
, end
- pos
, "\n");
3396 if (ret
< 0 || ret
>= end
- pos
)
3401 if (mask
& WPA_BSS_MASK_SSID
) {
3402 ret
= os_snprintf(pos
, end
- pos
, "ssid=%s\n",
3403 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
3404 if (ret
< 0 || ret
>= end
- pos
)
3410 if (mask
& WPA_BSS_MASK_WPS_SCAN
) {
3411 ie
= (const u8
*) (bss
+ 1);
3412 ret
= wpas_wps_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
3413 if (ret
< 0 || ret
>= end
- pos
)
3417 #endif /* CONFIG_WPS */
3420 if (mask
& WPA_BSS_MASK_P2P_SCAN
) {
3421 ie
= (const u8
*) (bss
+ 1);
3422 ret
= wpas_p2p_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
3423 if (ret
< 0 || ret
>= end
- pos
)
3427 #endif /* CONFIG_P2P */
3429 #ifdef CONFIG_WIFI_DISPLAY
3430 if (mask
& WPA_BSS_MASK_WIFI_DISPLAY
) {
3432 ie
= (const u8
*) (bss
+ 1);
3433 wfd
= ieee802_11_vendor_ie_concat(ie
, bss
->ie_len
,
3434 WFD_IE_VENDOR_TYPE
);
3436 ret
= os_snprintf(pos
, end
- pos
, "wfd_subelems=");
3437 if (ret
< 0 || ret
>= end
- pos
)
3441 pos
+= wpa_snprintf_hex(pos
, end
- pos
,
3446 ret
= os_snprintf(pos
, end
- pos
, "\n");
3447 if (ret
< 0 || ret
>= end
- pos
)
3452 #endif /* CONFIG_WIFI_DISPLAY */
3454 #ifdef CONFIG_INTERWORKING
3455 if ((mask
& WPA_BSS_MASK_INTERNETW
) && bss
->anqp
) {
3456 struct wpa_bss_anqp
*anqp
= bss
->anqp
;
3457 pos
= anqp_add_hex(pos
, end
, "anqp_venue_name",
3459 pos
= anqp_add_hex(pos
, end
, "anqp_network_auth_type",
3460 anqp
->network_auth_type
);
3461 pos
= anqp_add_hex(pos
, end
, "anqp_roaming_consortium",
3462 anqp
->roaming_consortium
);
3463 pos
= anqp_add_hex(pos
, end
, "anqp_ip_addr_type_availability",
3464 anqp
->ip_addr_type_availability
);
3465 pos
= anqp_add_hex(pos
, end
, "anqp_nai_realm",
3467 pos
= anqp_add_hex(pos
, end
, "anqp_3gpp", anqp
->anqp_3gpp
);
3468 pos
= anqp_add_hex(pos
, end
, "anqp_domain_name",
3471 pos
= anqp_add_hex(pos
, end
, "hs20_operator_friendly_name",
3472 anqp
->hs20_operator_friendly_name
);
3473 pos
= anqp_add_hex(pos
, end
, "hs20_wan_metrics",
3474 anqp
->hs20_wan_metrics
);
3475 pos
= anqp_add_hex(pos
, end
, "hs20_connection_capability",
3476 anqp
->hs20_connection_capability
);
3477 #endif /* CONFIG_HS20 */
3479 #endif /* CONFIG_INTERWORKING */
3481 if (mask
& WPA_BSS_MASK_DELIM
) {
3482 ret
= os_snprintf(pos
, end
- pos
, "====\n");
3483 if (ret
< 0 || ret
>= end
- pos
)
3492 static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant
*wpa_s
,
3493 const char *cmd
, char *buf
,
3498 struct wpa_bss
*bss
;
3499 struct wpa_bss
*bsslast
= NULL
;
3500 struct dl_list
*next
;
3504 unsigned long mask
= WPA_BSS_MASK_ALL
;
3506 if (os_strncmp(cmd
, "RANGE=", 6) == 0) {
3507 if (os_strncmp(cmd
+ 6, "ALL", 3) == 0) {
3508 bss
= dl_list_first(&wpa_s
->bss_id
, struct wpa_bss
,
3510 bsslast
= dl_list_last(&wpa_s
->bss_id
, struct wpa_bss
,
3512 } else { /* N1-N2 */
3513 unsigned int id1
, id2
;
3515 if ((ctmp
= os_strchr(cmd
+ 6, '-')) == NULL
) {
3516 wpa_printf(MSG_INFO
, "Wrong BSS range "
3521 if (*(cmd
+ 6) == '-')
3524 id1
= atoi(cmd
+ 6);
3526 if (*ctmp
>= '0' && *ctmp
<= '9')
3529 id2
= (unsigned int) -1;
3530 bss
= wpa_bss_get_id_range(wpa_s
, id1
, id2
);
3531 if (id2
== (unsigned int) -1)
3532 bsslast
= dl_list_last(&wpa_s
->bss_id
,
3536 bsslast
= wpa_bss_get_id(wpa_s
, id2
);
3537 if (bsslast
== NULL
&& bss
&& id2
> id1
) {
3538 struct wpa_bss
*tmp
= bss
;
3540 next
= tmp
->list_id
.next
;
3541 if (next
== &wpa_s
->bss_id
)
3543 tmp
= dl_list_entry(
3544 next
, struct wpa_bss
,
3553 } else if (os_strncmp(cmd
, "FIRST", 5) == 0)
3554 bss
= dl_list_first(&wpa_s
->bss_id
, struct wpa_bss
, list_id
);
3555 else if (os_strncmp(cmd
, "LAST", 4) == 0)
3556 bss
= dl_list_last(&wpa_s
->bss_id
, struct wpa_bss
, list_id
);
3557 else if (os_strncmp(cmd
, "ID-", 3) == 0) {
3559 bss
= wpa_bss_get_id(wpa_s
, i
);
3560 } else if (os_strncmp(cmd
, "NEXT-", 5) == 0) {
3562 bss
= wpa_bss_get_id(wpa_s
, i
);
3564 next
= bss
->list_id
.next
;
3565 if (next
== &wpa_s
->bss_id
)
3568 bss
= dl_list_entry(next
, struct wpa_bss
,
3572 } else if (os_strncmp(cmd
, "p2p_dev_addr=", 13) == 0) {
3573 if (hwaddr_aton(cmd
+ 13, bssid
) == 0)
3574 bss
= wpa_bss_get_p2p_dev_addr(wpa_s
, bssid
);
3577 #endif /* CONFIG_P2P */
3578 } else if (hwaddr_aton(cmd
, bssid
) == 0)
3579 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
3581 struct wpa_bss
*tmp
;
3584 dl_list_for_each(tmp
, &wpa_s
->bss_id
, struct wpa_bss
, list_id
)
3593 if ((ctmp
= os_strstr(cmd
, "MASK=")) != NULL
) {
3594 mask
= strtoul(ctmp
+ 5, NULL
, 0x10);
3596 mask
= WPA_BSS_MASK_ALL
;
3602 if (bsslast
== NULL
)
3605 len
= print_bss_info(wpa_s
, bss
, mask
, buf
, buflen
);
3609 if (bss
== bsslast
) {
3610 if ((mask
& WPA_BSS_MASK_DELIM
) && len
&&
3611 (bss
== dl_list_last(&wpa_s
->bss_id
,
3612 struct wpa_bss
, list_id
)))
3613 os_snprintf(buf
- 5, 5, "####\n");
3616 next
= bss
->list_id
.next
;
3617 if (next
== &wpa_s
->bss_id
)
3619 bss
= dl_list_entry(next
, struct wpa_bss
, list_id
);
3620 } while (bss
&& len
);
3626 static int wpa_supplicant_ctrl_iface_ap_scan(
3627 struct wpa_supplicant
*wpa_s
, char *cmd
)
3629 int ap_scan
= atoi(cmd
);
3630 return wpa_supplicant_set_ap_scan(wpa_s
, ap_scan
);
3634 static int wpa_supplicant_ctrl_iface_scan_interval(
3635 struct wpa_supplicant
*wpa_s
, char *cmd
)
3637 int scan_int
= atoi(cmd
);
3638 return wpa_supplicant_set_scan_interval(wpa_s
, scan_int
);
3642 static int wpa_supplicant_ctrl_iface_bss_expire_age(
3643 struct wpa_supplicant
*wpa_s
, char *cmd
)
3645 int expire_age
= atoi(cmd
);
3646 return wpa_supplicant_set_bss_expiration_age(wpa_s
, expire_age
);
3650 static int wpa_supplicant_ctrl_iface_bss_expire_count(
3651 struct wpa_supplicant
*wpa_s
, char *cmd
)
3653 int expire_count
= atoi(cmd
);
3654 return wpa_supplicant_set_bss_expiration_count(wpa_s
, expire_count
);
3658 static int wpa_supplicant_ctrl_iface_bss_flush(
3659 struct wpa_supplicant
*wpa_s
, char *cmd
)
3661 int flush_age
= atoi(cmd
);
3664 wpa_bss_flush(wpa_s
);
3666 wpa_bss_flush_by_age(wpa_s
, flush_age
);
3671 static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant
*wpa_s
)
3673 wpa_printf(MSG_DEBUG
, "Dropping SA without deauthentication");
3674 /* MLME-DELETEKEYS.request */
3675 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 0, 0, NULL
, 0, NULL
, 0);
3676 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 1, 0, NULL
, 0, NULL
, 0);
3677 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 2, 0, NULL
, 0, NULL
, 0);
3678 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 3, 0, NULL
, 0, NULL
, 0);
3679 #ifdef CONFIG_IEEE80211W
3680 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 4, 0, NULL
, 0, NULL
, 0);
3681 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 5, 0, NULL
, 0, NULL
, 0);
3682 #endif /* CONFIG_IEEE80211W */
3684 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, wpa_s
->bssid
, 0, 0, NULL
, 0, NULL
,
3686 /* MLME-SETPROTECTION.request(None) */
3687 wpa_drv_mlme_setprotection(wpa_s
, wpa_s
->bssid
,
3688 MLME_SETPROTECTION_PROTECT_TYPE_NONE
,
3689 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE
);
3690 wpa_sm_drop_sa(wpa_s
->wpa
);
3694 static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant
*wpa_s
,
3697 #ifdef CONFIG_NO_SCAN_PROCESSING
3699 #else /* CONFIG_NO_SCAN_PROCESSING */
3701 struct wpa_bss
*bss
;
3702 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
3704 if (hwaddr_aton(addr
, bssid
)) {
3705 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: invalid "
3706 "address '%s'", addr
);
3710 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM " MACSTR
, MAC2STR(bssid
));
3713 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: No network "
3714 "configuration known for the target AP");
3718 bss
= wpa_bss_get(wpa_s
, bssid
, ssid
->ssid
, ssid
->ssid_len
);
3720 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: Target AP not found "
3726 * TODO: Find best network configuration block from configuration to
3727 * allow roaming to other networks
3730 wpa_s
->reassociate
= 1;
3731 wpa_supplicant_connect(wpa_s
, bss
, ssid
);
3734 #endif /* CONFIG_NO_SCAN_PROCESSING */
3739 static int p2p_ctrl_find(struct wpa_supplicant
*wpa_s
, char *cmd
)
3741 unsigned int timeout
= atoi(cmd
);
3742 enum p2p_discovery_type type
= P2P_FIND_START_WITH_FULL
;
3743 u8 dev_id
[ETH_ALEN
], *_dev_id
= NULL
;
3744 u8 dev_type
[WPS_DEV_TYPE_LEN
], *_dev_type
= NULL
;
3746 unsigned int search_delay
;
3748 if (os_strstr(cmd
, "type=social"))
3749 type
= P2P_FIND_ONLY_SOCIAL
;
3750 else if (os_strstr(cmd
, "type=progressive"))
3751 type
= P2P_FIND_PROGRESSIVE
;
3753 pos
= os_strstr(cmd
, "dev_id=");
3756 if (hwaddr_aton(pos
, dev_id
))
3761 pos
= os_strstr(cmd
, "dev_type=");
3764 if (wps_dev_type_str2bin(pos
, dev_type
) < 0)
3766 _dev_type
= dev_type
;
3769 pos
= os_strstr(cmd
, "delay=");
3772 search_delay
= atoi(pos
);
3774 search_delay
= wpas_p2p_search_delay(wpa_s
);
3776 return wpas_p2p_find(wpa_s
, timeout
, type
, _dev_type
!= NULL
, _dev_type
,
3777 _dev_id
, search_delay
);
3781 static int p2p_ctrl_connect(struct wpa_supplicant
*wpa_s
, char *cmd
,
3782 char *buf
, size_t buflen
)
3787 enum p2p_wps_method wps_method
;
3790 int persistent_group
, persistent_id
= -1;
3799 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad]
3800 * [persistent|persistent=<network id>]
3801 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
3804 if (hwaddr_aton(cmd
, addr
))
3812 persistent_group
= os_strstr(pos
, " persistent") != NULL
;
3813 pos2
= os_strstr(pos
, " persistent=");
3815 struct wpa_ssid
*ssid
;
3816 persistent_id
= atoi(pos2
+ 12);
3817 ssid
= wpa_config_get_network(wpa_s
->conf
, persistent_id
);
3818 if (ssid
== NULL
|| ssid
->disabled
!= 2 ||
3819 ssid
->mode
!= WPAS_MODE_P2P_GO
) {
3820 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3821 "SSID id=%d for persistent P2P group (GO)",
3826 join
= os_strstr(pos
, " join") != NULL
;
3827 auth
= os_strstr(pos
, " auth") != NULL
;
3828 automatic
= os_strstr(pos
, " auto") != NULL
;
3829 pd
= os_strstr(pos
, " provdisc") != NULL
;
3830 vht
= (os_strstr(cmd
, " vht") != NULL
) || wpa_s
->conf
->p2p_go_vht
;
3831 ht40
= (os_strstr(cmd
, " ht40") != NULL
) || wpa_s
->conf
->p2p_go_ht40
||
3834 pos2
= os_strstr(pos
, " go_intent=");
3837 go_intent
= atoi(pos2
);
3838 if (go_intent
< 0 || go_intent
> 15)
3842 pos2
= os_strstr(pos
, " freq=");
3850 if (os_strncmp(pos
, "pin", 3) == 0) {
3851 /* Request random PIN (to be displayed) and enable the PIN */
3852 wps_method
= WPS_PIN_DISPLAY
;
3853 } else if (os_strncmp(pos
, "pbc", 3) == 0) {
3854 wps_method
= WPS_PBC
;
3857 pos
= os_strchr(pin
, ' ');
3858 wps_method
= WPS_PIN_KEYPAD
;
3861 if (os_strncmp(pos
, "display", 7) == 0)
3862 wps_method
= WPS_PIN_DISPLAY
;
3864 if (!wps_pin_str_valid(pin
)) {
3865 os_memcpy(buf
, "FAIL-INVALID-PIN\n", 17);
3870 new_pin
= wpas_p2p_connect(wpa_s
, addr
, pin
, wps_method
,
3871 persistent_group
, automatic
, join
,
3872 auth
, go_intent
, freq
, persistent_id
, pd
,
3874 if (new_pin
== -2) {
3875 os_memcpy(buf
, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
3878 if (new_pin
== -3) {
3879 os_memcpy(buf
, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
3884 if (wps_method
== WPS_PIN_DISPLAY
&& pin
== NULL
) {
3885 ret
= os_snprintf(buf
, buflen
, "%08d", new_pin
);
3886 if (ret
< 0 || (size_t) ret
>= buflen
)
3891 os_memcpy(buf
, "OK\n", 3);
3896 static int p2p_ctrl_listen(struct wpa_supplicant
*wpa_s
, char *cmd
)
3898 unsigned int timeout
= atoi(cmd
);
3899 return wpas_p2p_listen(wpa_s
, timeout
);
3903 static int p2p_ctrl_prov_disc(struct wpa_supplicant
*wpa_s
, char *cmd
)
3907 enum wpas_p2p_prov_disc_use use
= WPAS_P2P_PD_FOR_GO_NEG
;
3909 /* <addr> <config method> [join|auto] */
3911 if (hwaddr_aton(cmd
, addr
))
3919 if (os_strstr(pos
, " join") != NULL
)
3920 use
= WPAS_P2P_PD_FOR_JOIN
;
3921 else if (os_strstr(pos
, " auto") != NULL
)
3922 use
= WPAS_P2P_PD_AUTO
;
3924 return wpas_p2p_prov_disc(wpa_s
, addr
, pos
, use
);
3928 static int p2p_get_passphrase(struct wpa_supplicant
*wpa_s
, char *buf
,
3931 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
3933 if (ssid
== NULL
|| ssid
->mode
!= WPAS_MODE_P2P_GO
||
3934 ssid
->passphrase
== NULL
)
3937 os_strlcpy(buf
, ssid
->passphrase
, buflen
);
3938 return os_strlen(buf
);
3942 static int p2p_ctrl_serv_disc_req(struct wpa_supplicant
*wpa_s
, char *cmd
,
3943 char *buf
, size_t buflen
)
3947 u8 dst_buf
[ETH_ALEN
], *dst
;
3948 struct wpabuf
*tlvs
;
3952 if (hwaddr_aton(cmd
, dst_buf
))
3955 if (dst
[0] == 0 && dst
[1] == 0 && dst
[2] == 0 &&
3956 dst
[3] == 0 && dst
[4] == 0 && dst
[5] == 0)
3963 if (os_strncmp(pos
, "upnp ", 5) == 0) {
3966 if (hexstr2bin(pos
, &version
, 1) < 0)
3972 ref
= wpas_p2p_sd_request_upnp(wpa_s
, dst
, version
, pos
);
3973 #ifdef CONFIG_WIFI_DISPLAY
3974 } else if (os_strncmp(pos
, "wifi-display ", 13) == 0) {
3975 ref
= wpas_p2p_sd_request_wifi_display(wpa_s
, dst
, pos
+ 13);
3976 #endif /* CONFIG_WIFI_DISPLAY */
3978 len
= os_strlen(pos
);
3982 tlvs
= wpabuf_alloc(len
);
3985 if (hexstr2bin(pos
, wpabuf_put(tlvs
, len
), len
) < 0) {
3990 ref
= wpas_p2p_sd_request(wpa_s
, dst
, tlvs
);
3995 res
= os_snprintf(buf
, buflen
, "%llx", (long long unsigned) ref
);
3996 if (res
< 0 || (unsigned) res
>= buflen
)
4002 static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant
*wpa_s
,
4005 long long unsigned val
;
4007 if (sscanf(cmd
, "%llx", &val
) != 1)
4010 return wpas_p2p_sd_cancel_request(wpa_s
, req
);
4014 static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant
*wpa_s
, char *cmd
)
4019 struct wpabuf
*resp_tlvs
;
4023 pos
= os_strchr(cmd
, ' ');
4031 if (hwaddr_aton(pos
, dst
))
4038 pos2
= os_strchr(pos
, ' ');
4042 dialog_token
= atoi(pos
);
4044 len
= os_strlen(pos2
);
4048 resp_tlvs
= wpabuf_alloc(len
);
4049 if (resp_tlvs
== NULL
)
4051 if (hexstr2bin(pos2
, wpabuf_put(resp_tlvs
, len
), len
) < 0) {
4052 wpabuf_free(resp_tlvs
);
4056 wpas_p2p_sd_response(wpa_s
, freq
, dst
, dialog_token
, resp_tlvs
);
4057 wpabuf_free(resp_tlvs
);
4062 static int p2p_ctrl_serv_disc_external(struct wpa_supplicant
*wpa_s
,
4065 if (os_strcmp(cmd
, "0") && os_strcmp(cmd
, "1"))
4067 wpa_s
->p2p_sd_over_ctrl_iface
= atoi(cmd
);
4072 static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant
*wpa_s
,
4077 struct wpabuf
*query
, *resp
;
4079 pos
= os_strchr(cmd
, ' ');
4084 len
= os_strlen(cmd
);
4088 query
= wpabuf_alloc(len
);
4091 if (hexstr2bin(cmd
, wpabuf_put(query
, len
), len
) < 0) {
4096 len
= os_strlen(pos
);
4102 resp
= wpabuf_alloc(len
);
4107 if (hexstr2bin(pos
, wpabuf_put(resp
, len
), len
) < 0) {
4113 if (wpas_p2p_service_add_bonjour(wpa_s
, query
, resp
) < 0) {
4122 static int p2p_ctrl_service_add_upnp(struct wpa_supplicant
*wpa_s
, char *cmd
)
4127 pos
= os_strchr(cmd
, ' ');
4132 if (hexstr2bin(cmd
, &version
, 1) < 0)
4135 return wpas_p2p_service_add_upnp(wpa_s
, version
, pos
);
4139 static int p2p_ctrl_service_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
4143 pos
= os_strchr(cmd
, ' ');
4148 if (os_strcmp(cmd
, "bonjour") == 0)
4149 return p2p_ctrl_service_add_bonjour(wpa_s
, pos
);
4150 if (os_strcmp(cmd
, "upnp") == 0)
4151 return p2p_ctrl_service_add_upnp(wpa_s
, pos
);
4152 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
4157 static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant
*wpa_s
,
4161 struct wpabuf
*query
;
4164 len
= os_strlen(cmd
);
4168 query
= wpabuf_alloc(len
);
4171 if (hexstr2bin(cmd
, wpabuf_put(query
, len
), len
) < 0) {
4176 ret
= wpas_p2p_service_del_bonjour(wpa_s
, query
);
4182 static int p2p_ctrl_service_del_upnp(struct wpa_supplicant
*wpa_s
, char *cmd
)
4187 pos
= os_strchr(cmd
, ' ');
4192 if (hexstr2bin(cmd
, &version
, 1) < 0)
4195 return wpas_p2p_service_del_upnp(wpa_s
, version
, pos
);
4199 static int p2p_ctrl_service_del(struct wpa_supplicant
*wpa_s
, char *cmd
)
4203 pos
= os_strchr(cmd
, ' ');
4208 if (os_strcmp(cmd
, "bonjour") == 0)
4209 return p2p_ctrl_service_del_bonjour(wpa_s
, pos
);
4210 if (os_strcmp(cmd
, "upnp") == 0)
4211 return p2p_ctrl_service_del_upnp(wpa_s
, pos
);
4212 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
4217 static int p2p_ctrl_reject(struct wpa_supplicant
*wpa_s
, char *cmd
)
4223 if (hwaddr_aton(cmd
, addr
))
4226 return wpas_p2p_reject(wpa_s
, addr
);
4230 static int p2p_ctrl_invite_persistent(struct wpa_supplicant
*wpa_s
, char *cmd
)
4234 struct wpa_ssid
*ssid
;
4235 u8
*_peer
= NULL
, peer
[ETH_ALEN
];
4236 int freq
= 0, pref_freq
= 0;
4240 pos
= os_strstr(cmd
, " peer=");
4243 if (hwaddr_aton(pos
, peer
))
4247 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
4248 if (ssid
== NULL
|| ssid
->disabled
!= 2) {
4249 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
4250 "for persistent P2P group",
4255 pos
= os_strstr(cmd
, " freq=");
4263 pos
= os_strstr(cmd
, " pref=");
4266 pref_freq
= atoi(pos
);
4271 vht
= (os_strstr(cmd
, " vht") != NULL
) || wpa_s
->conf
->p2p_go_vht
;
4272 ht40
= (os_strstr(cmd
, " ht40") != NULL
) || wpa_s
->conf
->p2p_go_ht40
||
4275 return wpas_p2p_invite(wpa_s
, _peer
, ssid
, NULL
, freq
, ht40
, vht
,
4280 static int p2p_ctrl_invite_group(struct wpa_supplicant
*wpa_s
, char *cmd
)
4283 u8 peer
[ETH_ALEN
], go_dev_addr
[ETH_ALEN
], *go_dev
= NULL
;
4285 pos
= os_strstr(cmd
, " peer=");
4291 if (hwaddr_aton(pos
, peer
)) {
4292 wpa_printf(MSG_DEBUG
, "P2P: Invalid MAC address '%s'", pos
);
4296 pos
= os_strstr(pos
, " go_dev_addr=");
4299 if (hwaddr_aton(pos
, go_dev_addr
)) {
4300 wpa_printf(MSG_DEBUG
, "P2P: Invalid MAC address '%s'",
4304 go_dev
= go_dev_addr
;
4307 return wpas_p2p_invite_group(wpa_s
, cmd
, peer
, go_dev
);
4311 static int p2p_ctrl_invite(struct wpa_supplicant
*wpa_s
, char *cmd
)
4313 if (os_strncmp(cmd
, "persistent=", 11) == 0)
4314 return p2p_ctrl_invite_persistent(wpa_s
, cmd
+ 11);
4315 if (os_strncmp(cmd
, "group=", 6) == 0)
4316 return p2p_ctrl_invite_group(wpa_s
, cmd
+ 6);
4322 static int p2p_ctrl_group_add_persistent(struct wpa_supplicant
*wpa_s
,
4323 char *cmd
, int freq
, int ht40
,
4327 struct wpa_ssid
*ssid
;
4330 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
4331 if (ssid
== NULL
|| ssid
->disabled
!= 2) {
4332 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
4333 "for persistent P2P group",
4338 return wpas_p2p_group_add_persistent(wpa_s
, ssid
, 0, freq
, ht40
, vht
,
4343 static int p2p_ctrl_group_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
4345 int freq
= 0, ht40
, vht
;
4348 pos
= os_strstr(cmd
, "freq=");
4350 freq
= atoi(pos
+ 5);
4352 vht
= (os_strstr(cmd
, "vht") != NULL
) || wpa_s
->conf
->p2p_go_vht
;
4353 ht40
= (os_strstr(cmd
, "ht40") != NULL
) || wpa_s
->conf
->p2p_go_ht40
||
4356 if (os_strncmp(cmd
, "persistent=", 11) == 0)
4357 return p2p_ctrl_group_add_persistent(wpa_s
, cmd
+ 11, freq
,
4359 if (os_strcmp(cmd
, "persistent") == 0 ||
4360 os_strncmp(cmd
, "persistent ", 11) == 0)
4361 return wpas_p2p_group_add(wpa_s
, 1, freq
, ht40
, vht
);
4362 if (os_strncmp(cmd
, "freq=", 5) == 0)
4363 return wpas_p2p_group_add(wpa_s
, 0, freq
, ht40
, vht
);
4365 return wpas_p2p_group_add(wpa_s
, 0, freq
, ht40
, vht
);
4367 wpa_printf(MSG_DEBUG
, "CTRL: Invalid P2P_GROUP_ADD parameters '%s'",
4373 static int p2p_ctrl_peer(struct wpa_supplicant
*wpa_s
, char *cmd
,
4374 char *buf
, size_t buflen
)
4376 u8 addr
[ETH_ALEN
], *addr_ptr
;
4378 const struct p2p_peer_info
*info
;
4380 char devtype
[WPS_DEV_TYPE_BUFSIZE
];
4381 struct wpa_ssid
*ssid
;
4384 if (!wpa_s
->global
->p2p
)
4387 if (os_strcmp(cmd
, "FIRST") == 0) {
4390 } else if (os_strncmp(cmd
, "NEXT-", 5) == 0) {
4391 if (hwaddr_aton(cmd
+ 5, addr
) < 0)
4396 if (hwaddr_aton(cmd
, addr
) < 0)
4402 info
= p2p_get_peer_info(wpa_s
->global
->p2p
, addr_ptr
, next
);
4409 res
= os_snprintf(pos
, end
- pos
, MACSTR
"\n"
4415 "serial_number=%s\n"
4416 "config_methods=0x%x\n"
4418 "group_capab=0x%x\n"
4420 MAC2STR(info
->p2p_device_addr
),
4421 wps_dev_type_bin2str(info
->pri_dev_type
,
4422 devtype
, sizeof(devtype
)),
4427 info
->serial_number
,
4428 info
->config_methods
,
4432 if (res
< 0 || res
>= end
- pos
)
4436 for (i
= 0; i
< info
->wps_sec_dev_type_list_len
/ WPS_DEV_TYPE_LEN
; i
++)
4439 t
= &info
->wps_sec_dev_type_list
[i
* WPS_DEV_TYPE_LEN
];
4440 res
= os_snprintf(pos
, end
- pos
, "sec_dev_type=%s\n",
4441 wps_dev_type_bin2str(t
, devtype
,
4443 if (res
< 0 || res
>= end
- pos
)
4448 ssid
= wpas_p2p_get_persistent(wpa_s
, info
->p2p_device_addr
, NULL
, 0);
4450 res
= os_snprintf(pos
, end
- pos
, "persistent=%d\n", ssid
->id
);
4451 if (res
< 0 || res
>= end
- pos
)
4456 res
= p2p_get_peer_info_txt(info
, pos
, end
- pos
);
4465 static int p2p_ctrl_disallow_freq(struct wpa_supplicant
*wpa_s
,
4470 if (wpa_s
->global
->p2p
== NULL
)
4473 if (freq_range_list_parse(&wpa_s
->global
->p2p_disallow_freq
, param
) < 0)
4476 for (i
= 0; i
< wpa_s
->global
->p2p_disallow_freq
.num
; i
++) {
4477 struct wpa_freq_range
*freq
;
4478 freq
= &wpa_s
->global
->p2p_disallow_freq
.range
[i
];
4479 wpa_printf(MSG_DEBUG
, "P2P: Disallowed frequency range %u-%u",
4480 freq
->min
, freq
->max
);
4483 wpas_p2p_update_channel_list(wpa_s
);
4488 static int p2p_ctrl_set(struct wpa_supplicant
*wpa_s
, char *cmd
)
4492 if (wpa_s
->global
->p2p
== NULL
)
4495 param
= os_strchr(cmd
, ' ');
4500 if (os_strcmp(cmd
, "discoverability") == 0) {
4501 p2p_set_client_discoverability(wpa_s
->global
->p2p
,
4506 if (os_strcmp(cmd
, "managed") == 0) {
4507 p2p_set_managed_oper(wpa_s
->global
->p2p
, atoi(param
));
4511 if (os_strcmp(cmd
, "listen_channel") == 0) {
4512 return p2p_set_listen_channel(wpa_s
->global
->p2p
, 81,
4516 if (os_strcmp(cmd
, "ssid_postfix") == 0) {
4517 return p2p_set_ssid_postfix(wpa_s
->global
->p2p
, (u8
*) param
,
4521 if (os_strcmp(cmd
, "noa") == 0) {
4523 int count
, start
, duration
;
4524 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
4525 count
= atoi(param
);
4526 pos
= os_strchr(param
, ',');
4531 pos
= os_strchr(pos
, ',');
4535 duration
= atoi(pos
);
4536 if (count
< 0 || count
> 255 || start
< 0 || duration
< 0)
4538 if (count
== 0 && duration
> 0)
4540 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
4541 "start=%d duration=%d", count
, start
, duration
);
4542 return wpas_p2p_set_noa(wpa_s
, count
, start
, duration
);
4545 if (os_strcmp(cmd
, "ps") == 0)
4546 return wpa_drv_set_p2p_powersave(wpa_s
, atoi(param
), -1, -1);
4548 if (os_strcmp(cmd
, "oppps") == 0)
4549 return wpa_drv_set_p2p_powersave(wpa_s
, -1, atoi(param
), -1);
4551 if (os_strcmp(cmd
, "ctwindow") == 0)
4552 return wpa_drv_set_p2p_powersave(wpa_s
, -1, -1, atoi(param
));
4554 if (os_strcmp(cmd
, "disabled") == 0) {
4555 wpa_s
->global
->p2p_disabled
= atoi(param
);
4556 wpa_printf(MSG_DEBUG
, "P2P functionality %s",
4557 wpa_s
->global
->p2p_disabled
?
4558 "disabled" : "enabled");
4559 if (wpa_s
->global
->p2p_disabled
) {
4560 wpas_p2p_stop_find(wpa_s
);
4561 os_memset(wpa_s
->p2p_auth_invite
, 0, ETH_ALEN
);
4562 p2p_flush(wpa_s
->global
->p2p
);
4567 if (os_strcmp(cmd
, "conc_pref") == 0) {
4568 if (os_strcmp(param
, "sta") == 0)
4569 wpa_s
->global
->conc_pref
= WPA_CONC_PREF_STA
;
4570 else if (os_strcmp(param
, "p2p") == 0)
4571 wpa_s
->global
->conc_pref
= WPA_CONC_PREF_P2P
;
4573 wpa_printf(MSG_INFO
, "Invalid conc_pref value");
4576 wpa_printf(MSG_DEBUG
, "Single channel concurrency preference: "
4581 if (os_strcmp(cmd
, "force_long_sd") == 0) {
4582 wpa_s
->force_long_sd
= atoi(param
);
4586 if (os_strcmp(cmd
, "peer_filter") == 0) {
4588 if (hwaddr_aton(param
, addr
))
4590 p2p_set_peer_filter(wpa_s
->global
->p2p
, addr
);
4594 if (os_strcmp(cmd
, "cross_connect") == 0)
4595 return wpas_p2p_set_cross_connect(wpa_s
, atoi(param
));
4597 if (os_strcmp(cmd
, "go_apsd") == 0) {
4598 if (os_strcmp(param
, "disable") == 0)
4599 wpa_s
->set_ap_uapsd
= 0;
4601 wpa_s
->set_ap_uapsd
= 1;
4602 wpa_s
->ap_uapsd
= atoi(param
);
4607 if (os_strcmp(cmd
, "client_apsd") == 0) {
4608 if (os_strcmp(param
, "disable") == 0)
4609 wpa_s
->set_sta_uapsd
= 0;
4613 /* format: BE,BK,VI,VO;max SP Length */
4615 pos
= os_strchr(param
, ',');
4620 pos
= os_strchr(pos
, ',');
4625 pos
= os_strchr(pos
, ',');
4630 /* ignore max SP Length for now */
4632 wpa_s
->set_sta_uapsd
= 1;
4633 wpa_s
->sta_uapsd
= 0;
4635 wpa_s
->sta_uapsd
|= BIT(0);
4637 wpa_s
->sta_uapsd
|= BIT(1);
4639 wpa_s
->sta_uapsd
|= BIT(2);
4641 wpa_s
->sta_uapsd
|= BIT(3);
4646 if (os_strcmp(cmd
, "disallow_freq") == 0)
4647 return p2p_ctrl_disallow_freq(wpa_s
, param
);
4649 if (os_strcmp(cmd
, "disc_int") == 0) {
4650 int min_disc_int
, max_disc_int
, max_disc_tu
;
4655 min_disc_int
= atoi(pos
);
4656 pos
= os_strchr(pos
, ' ');
4661 max_disc_int
= atoi(pos
);
4662 pos
= os_strchr(pos
, ' ');
4667 max_disc_tu
= atoi(pos
);
4669 return p2p_set_disc_int(wpa_s
->global
->p2p
, min_disc_int
,
4670 max_disc_int
, max_disc_tu
);
4673 if (os_strcmp(cmd
, "per_sta_psk") == 0) {
4674 wpa_s
->global
->p2p_per_sta_psk
= !!atoi(param
);
4678 #ifdef CONFIG_WPS_NFC
4679 if (os_strcmp(cmd
, "nfc_tag") == 0)
4680 return wpas_p2p_nfc_tag_enabled(wpa_s
, !!atoi(param
));
4681 #endif /* CONFIG_WPS_NFC */
4683 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
4690 static void p2p_ctrl_flush(struct wpa_supplicant
*wpa_s
)
4692 os_memset(wpa_s
->p2p_auth_invite
, 0, ETH_ALEN
);
4693 wpa_s
->force_long_sd
= 0;
4694 if (wpa_s
->global
->p2p
)
4695 p2p_flush(wpa_s
->global
->p2p
);
4699 static int p2p_ctrl_presence_req(struct wpa_supplicant
*wpa_s
, char *cmd
)
4702 unsigned int dur1
= 0, int1
= 0, dur2
= 0, int2
= 0;
4705 pos
= os_strchr(cmd
, ' ');
4711 pos2
= os_strchr(pos
, ' ');
4719 pos
= os_strchr(pos2
, ' ');
4727 return wpas_p2p_presence_req(wpa_s
, dur1
, int1
, dur2
, int2
);
4731 static int p2p_ctrl_ext_listen(struct wpa_supplicant
*wpa_s
, char *cmd
)
4734 unsigned int period
= 0, interval
= 0;
4737 pos
= os_strchr(cmd
, ' ');
4742 interval
= atoi(pos
);
4745 return wpas_p2p_ext_listen(wpa_s
, period
, interval
);
4749 static int p2p_ctrl_remove_client(struct wpa_supplicant
*wpa_s
, const char *cmd
)
4756 if (os_strncmp(pos
, "iface=", 6) == 0) {
4760 if (hwaddr_aton(pos
, peer
))
4763 wpas_p2p_remove_client(wpa_s
, peer
, iface_addr
);
4767 #endif /* CONFIG_P2P */
4770 static int * freq_range_to_channel_list(struct wpa_supplicant
*wpa_s
, char *val
)
4772 struct wpa_freq_range_list ranges
;
4774 struct hostapd_hw_modes
*mode
;
4777 if (wpa_s
->hw
.modes
== NULL
)
4780 os_memset(&ranges
, 0, sizeof(ranges
));
4781 if (freq_range_list_parse(&ranges
, val
) < 0)
4784 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
4787 mode
= &wpa_s
->hw
.modes
[i
];
4788 for (j
= 0; j
< mode
->num_channels
; j
++) {
4791 if (mode
->channels
[j
].flag
& HOSTAPD_CHAN_DISABLED
)
4794 freq
= mode
->channels
[j
].freq
;
4795 if (!freq_range_list_includes(&ranges
, freq
))
4798 int_array_add_unique(&freqs
, freq
);
4802 os_free(ranges
.range
);
4807 #ifdef CONFIG_INTERWORKING
4809 static int ctrl_interworking_select(struct wpa_supplicant
*wpa_s
, char *param
)
4817 auto_sel
= os_strstr(param
, "auto") != NULL
;
4819 pos
= os_strstr(param
, "freq=");
4821 freqs
= freq_range_to_channel_list(wpa_s
, pos
+ 5);
4828 return interworking_select(wpa_s
, auto_sel
, freqs
);
4832 static int ctrl_interworking_connect(struct wpa_supplicant
*wpa_s
, char *dst
)
4835 struct wpa_bss
*bss
;
4837 if (hwaddr_aton(dst
, bssid
)) {
4838 wpa_printf(MSG_DEBUG
, "Invalid BSSID '%s'", dst
);
4842 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
4844 wpa_printf(MSG_DEBUG
, "Could not find BSS " MACSTR
,
4849 return interworking_connect(wpa_s
, bss
);
4853 static int get_anqp(struct wpa_supplicant
*wpa_s
, char *dst
)
4855 u8 dst_addr
[ETH_ALEN
];
4858 #define MAX_ANQP_INFO_ID 100
4859 u16 id
[MAX_ANQP_INFO_ID
];
4862 used
= hwaddr_aton2(dst
, dst_addr
);
4866 while (num_id
< MAX_ANQP_INFO_ID
) {
4867 id
[num_id
] = atoi(pos
);
4870 pos
= os_strchr(pos
+ 1, ',');
4879 return anqp_send_req(wpa_s
, dst_addr
, id
, num_id
);
4883 static int gas_request(struct wpa_supplicant
*wpa_s
, char *cmd
)
4885 u8 dst_addr
[ETH_ALEN
];
4886 struct wpabuf
*advproto
, *query
= NULL
;
4891 used
= hwaddr_aton2(cmd
, dst_addr
);
4899 /* Advertisement Protocol ID */
4900 end
= os_strchr(pos
, ' ');
4904 len
= os_strlen(pos
);
4910 advproto
= wpabuf_alloc(len
);
4911 if (advproto
== NULL
)
4913 if (hexstr2bin(pos
, wpabuf_put(advproto
, len
), len
) < 0)
4917 /* Optional Query Request */
4922 len
= os_strlen(pos
);
4929 query
= wpabuf_alloc(len
);
4932 if (hexstr2bin(pos
, wpabuf_put(query
, len
), len
) < 0)
4937 ret
= gas_send_request(wpa_s
, dst_addr
, advproto
, query
);
4940 wpabuf_free(advproto
);
4947 static int gas_response_get(struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
,
4954 size_t resp_len
, start
, requested_len
;
4955 struct wpabuf
*resp
;
4958 used
= hwaddr_aton2(cmd
, addr
);
4965 dialog_token
= atoi(pos
);
4967 if (wpa_s
->last_gas_resp
&&
4968 os_memcmp(addr
, wpa_s
->last_gas_addr
, ETH_ALEN
) == 0 &&
4969 dialog_token
== wpa_s
->last_gas_dialog_token
)
4970 resp
= wpa_s
->last_gas_resp
;
4971 else if (wpa_s
->prev_gas_resp
&&
4972 os_memcmp(addr
, wpa_s
->prev_gas_addr
, ETH_ALEN
) == 0 &&
4973 dialog_token
== wpa_s
->prev_gas_dialog_token
)
4974 resp
= wpa_s
->prev_gas_resp
;
4978 resp_len
= wpabuf_len(resp
);
4980 requested_len
= resp_len
;
4982 pos
= os_strchr(pos
, ' ');
4985 if (start
> resp_len
)
4986 return os_snprintf(buf
, buflen
, "FAIL-Invalid range");
4987 pos
= os_strchr(pos
, ',');
4991 requested_len
= atoi(pos
);
4992 if (start
+ requested_len
> resp_len
)
4993 return os_snprintf(buf
, buflen
, "FAIL-Invalid range");
4996 if (requested_len
* 2 + 1 > buflen
)
4997 return os_snprintf(buf
, buflen
, "FAIL-Too long response");
4999 ret
= wpa_snprintf_hex(buf
, buflen
, wpabuf_head_u8(resp
) + start
,
5002 if (start
+ requested_len
== resp_len
) {
5004 * Free memory by dropping the response after it has been
5007 if (resp
== wpa_s
->prev_gas_resp
) {
5008 wpabuf_free(wpa_s
->prev_gas_resp
);
5009 wpa_s
->prev_gas_resp
= NULL
;
5011 wpabuf_free(wpa_s
->last_gas_resp
);
5012 wpa_s
->last_gas_resp
= NULL
;
5018 #endif /* CONFIG_INTERWORKING */
5023 static int get_hs20_anqp(struct wpa_supplicant
*wpa_s
, char *dst
)
5025 u8 dst_addr
[ETH_ALEN
];
5030 used
= hwaddr_aton2(dst
, dst_addr
);
5035 int num
= atoi(pos
);
5036 if (num
<= 0 || num
> 31)
5038 subtypes
|= BIT(num
);
5039 pos
= os_strchr(pos
+ 1, ',');
5048 return hs20_anqp_send_req(wpa_s
, dst_addr
, subtypes
, NULL
, 0);
5052 static int hs20_nai_home_realm_list(struct wpa_supplicant
*wpa_s
,
5053 const u8
*addr
, const char *realm
)
5059 rlen
= os_strlen(realm
);
5061 buf
= os_malloc(len
);
5064 buf
[0] = 1; /* NAI Home Realm Count */
5065 buf
[1] = 0; /* Formatted in accordance with RFC 4282 */
5067 os_memcpy(buf
+ 3, realm
, rlen
);
5069 ret
= hs20_anqp_send_req(wpa_s
, addr
,
5070 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY
),
5079 static int hs20_get_nai_home_realm_list(struct wpa_supplicant
*wpa_s
,
5082 struct wpa_cred
*cred
= wpa_s
->conf
->cred
;
5083 u8 dst_addr
[ETH_ALEN
];
5089 used
= hwaddr_aton2(dst
, dst_addr
);
5093 while (dst
[used
] == ' ')
5095 if (os_strncmp(dst
+ used
, "realm=", 6) == 0)
5096 return hs20_nai_home_realm_list(wpa_s
, dst_addr
,
5099 len
= os_strlen(dst
+ used
);
5101 if (len
== 0 && cred
&& cred
->realm
)
5102 return hs20_nai_home_realm_list(wpa_s
, dst_addr
, cred
->realm
);
5107 buf
= os_malloc(len
);
5110 if (hexstr2bin(dst
+ used
, buf
, len
) < 0) {
5115 ret
= hs20_anqp_send_req(wpa_s
, dst_addr
,
5116 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY
),
5123 #endif /* CONFIG_HS20 */
5126 static int wpa_supplicant_ctrl_iface_sta_autoconnect(
5127 struct wpa_supplicant
*wpa_s
, char *cmd
)
5129 wpa_s
->auto_reconnect_disabled
= atoi(cmd
) == 0 ? 1 : 0;
5134 #ifdef CONFIG_AUTOSCAN
5136 static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant
*wpa_s
,
5139 enum wpa_states state
= wpa_s
->wpa_state
;
5140 char *new_params
= NULL
;
5142 if (os_strlen(cmd
) > 0) {
5143 new_params
= os_strdup(cmd
);
5144 if (new_params
== NULL
)
5148 os_free(wpa_s
->conf
->autoscan
);
5149 wpa_s
->conf
->autoscan
= new_params
;
5151 if (wpa_s
->conf
->autoscan
== NULL
)
5152 autoscan_deinit(wpa_s
);
5153 else if (state
== WPA_DISCONNECTED
|| state
== WPA_INACTIVE
)
5154 autoscan_init(wpa_s
, 1);
5155 else if (state
== WPA_SCANNING
)
5156 wpa_supplicant_reinit_autoscan(wpa_s
);
5161 #endif /* CONFIG_AUTOSCAN */
5166 static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant
*wpa_s
, char *cmd
)
5172 struct wpabuf
*tfs_req
= NULL
;
5174 if (os_strncmp(cmd
, "enter", 5) == 0)
5176 else if (os_strncmp(cmd
, "exit", 4) == 0)
5181 pos
= os_strstr(cmd
, " interval=");
5183 intval
= atoi(pos
+ 10);
5185 pos
= os_strstr(cmd
, " tfs_req=");
5190 end
= os_strchr(pos
, ' ');
5194 len
= os_strlen(pos
);
5198 tfs_req
= wpabuf_alloc(len
);
5199 if (tfs_req
== NULL
)
5201 if (hexstr2bin(pos
, wpabuf_put(tfs_req
, len
), len
) < 0) {
5202 wpabuf_free(tfs_req
);
5207 ret
= ieee802_11_send_wnmsleep_req(wpa_s
, enter
? WNM_SLEEP_MODE_ENTER
:
5208 WNM_SLEEP_MODE_EXIT
, intval
,
5210 wpabuf_free(tfs_req
);
5216 static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant
*wpa_s
, char *cmd
)
5220 query_reason
= atoi(cmd
);
5222 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d",
5225 return wnm_send_bss_transition_mgmt_query(wpa_s
, query_reason
);
5228 #endif /* CONFIG_WNM */
5231 /* Get string representation of channel width */
5232 static const char * channel_width_name(enum chan_width width
)
5235 case CHAN_WIDTH_20_NOHT
:
5236 return "20 MHz (no HT)";
5243 case CHAN_WIDTH_80P80
:
5245 case CHAN_WIDTH_160
:
5253 static int wpa_supplicant_signal_poll(struct wpa_supplicant
*wpa_s
, char *buf
,
5256 struct wpa_signal_info si
;
5260 ret
= wpa_drv_signal_poll(wpa_s
, &si
);
5267 ret
= os_snprintf(pos
, end
- pos
, "RSSI=%d\nLINKSPEED=%d\n"
5268 "NOISE=%d\nFREQUENCY=%u\n",
5269 si
.current_signal
, si
.current_txrate
/ 1000,
5270 si
.current_noise
, si
.frequency
);
5271 if (ret
< 0 || ret
> end
- pos
)
5275 if (si
.chanwidth
!= CHAN_WIDTH_UNKNOWN
) {
5276 ret
= os_snprintf(pos
, end
- pos
, "WIDTH=%s\n",
5277 channel_width_name(si
.chanwidth
));
5278 if (ret
< 0 || ret
> end
- pos
)
5283 if (si
.center_frq1
> 0 && si
.center_frq2
> 0) {
5284 ret
= os_snprintf(pos
, end
- pos
,
5285 "CENTER_FRQ1=%d\nCENTER_FRQ2=%d\n",
5286 si
.center_frq1
, si
.center_frq2
);
5287 if (ret
< 0 || ret
> end
- pos
)
5292 if (si
.avg_signal
) {
5293 ret
= os_snprintf(pos
, end
- pos
,
5294 "AVG_RSSI=%d\n", si
.avg_signal
);
5295 if (ret
< 0 || ret
>= end
- pos
)
5304 static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant
*wpa_s
, char *buf
,
5307 struct hostap_sta_driver_data sta
;
5310 ret
= wpa_drv_pktcnt_poll(wpa_s
, &sta
);
5314 ret
= os_snprintf(buf
, buflen
, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
5315 sta
.tx_packets
, sta
.tx_retry_failed
, sta
.rx_packets
);
5316 if (ret
< 0 || (size_t) ret
> buflen
)
5323 static int wpa_supplicant_driver_cmd(struct wpa_supplicant
*wpa_s
, char *cmd
,
5324 char *buf
, size_t buflen
)
5328 ret
= wpa_drv_driver_cmd(wpa_s
, cmd
, buf
, buflen
);
5330 if (os_strncasecmp(cmd
, "COUNTRY", 7) == 0) {
5331 struct p2p_data
*p2p
= wpa_s
->global
->p2p
;
5334 country
[0] = cmd
[8];
5335 country
[1] = cmd
[9];
5337 p2p_set_country(p2p
, country
);
5340 ret
= os_snprintf(buf
, buflen
, "%s\n", "OK");
5344 #endif /* ANDROID */
5347 static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant
*wpa_s
)
5349 wpa_dbg(wpa_s
, MSG_DEBUG
, "Flush all wpa_supplicant state");
5352 wpas_p2p_stop_find(wpa_s
);
5353 p2p_ctrl_flush(wpa_s
);
5354 wpas_p2p_group_remove(wpa_s
, "*");
5355 wpas_p2p_service_flush(wpa_s
);
5356 wpa_s
->global
->p2p_disabled
= 0;
5357 wpa_s
->global
->p2p_per_sta_psk
= 0;
5358 wpa_s
->conf
->num_sec_device_types
= 0;
5359 #endif /* CONFIG_P2P */
5361 #ifdef CONFIG_WPS_TESTING
5362 wps_version_number
= 0x20;
5363 wps_testing_dummy_cred
= 0;
5364 #endif /* CONFIG_WPS_TESTING */
5366 wpa_s
->wps_fragment_size
= 0;
5367 wpas_wps_cancel(wpa_s
);
5368 #endif /* CONFIG_WPS */
5369 wpa_s
->after_wps
= 0;
5370 wpa_s
->known_wps_freq
= 0;
5373 #ifdef CONFIG_TDLS_TESTING
5374 extern unsigned int tdls_testing
;
5376 #endif /* CONFIG_TDLS_TESTING */
5377 wpa_drv_tdls_oper(wpa_s
, TDLS_ENABLE
, NULL
);
5378 wpa_tdls_enable(wpa_s
->wpa
, 1);
5379 #endif /* CONFIG_TDLS */
5381 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures
, wpa_s
, NULL
);
5382 wpa_supplicant_stop_countermeasures(wpa_s
, NULL
);
5384 wpa_s
->no_keep_alive
= 0;
5386 os_free(wpa_s
->disallow_aps_bssid
);
5387 wpa_s
->disallow_aps_bssid
= NULL
;
5388 wpa_s
->disallow_aps_bssid_count
= 0;
5389 os_free(wpa_s
->disallow_aps_ssid
);
5390 wpa_s
->disallow_aps_ssid
= NULL
;
5391 wpa_s
->disallow_aps_ssid_count
= 0;
5393 wpa_s
->set_sta_uapsd
= 0;
5394 wpa_s
->sta_uapsd
= 0;
5396 wpa_drv_radio_disable(wpa_s
, 0);
5398 wpa_bss_flush(wpa_s
);
5399 wpa_blacklist_clear(wpa_s
);
5400 wpa_s
->extra_blacklist_count
= 0;
5401 wpa_supplicant_ctrl_iface_remove_network(wpa_s
, "all");
5402 wpa_supplicant_ctrl_iface_remove_cred(wpa_s
, "all");
5403 wpa_config_flush_blobs(wpa_s
->conf
);
5404 wpa_s
->conf
->auto_interworking
= 0;
5405 wpa_s
->conf
->okc
= 0;
5406 wpa_s
->conf
->pmf
= 0;
5408 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_LIFETIME
, 43200);
5409 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_REAUTH_THRESHOLD
, 70);
5410 wpa_sm_set_param(wpa_s
->wpa
, RSNA_SA_TIMEOUT
, 60);
5411 eapol_sm_notify_logoff(wpa_s
->eapol
, FALSE
);
5413 radio_remove_unstarted_work(wpa_s
, NULL
);
5417 static int wpas_ctrl_radio_work_show(struct wpa_supplicant
*wpa_s
,
5418 char *buf
, size_t buflen
)
5420 struct wpa_radio_work
*work
;
5422 struct os_reltime now
, diff
;
5427 os_get_reltime(&now
);
5429 dl_list_for_each(work
, &wpa_s
->radio
->work
, struct wpa_radio_work
, list
)
5433 os_reltime_sub(&now
, &work
->time
, &diff
);
5434 ret
= os_snprintf(pos
, end
- pos
, "%s@%s:%u:%u:%ld.%06ld\n",
5435 work
->type
, work
->wpa_s
->ifname
, work
->freq
,
5436 work
->started
, diff
.sec
, diff
.usec
);
5437 if (ret
< 0 || ret
>= end
- pos
)
5446 static void wpas_ctrl_radio_work_timeout(void *eloop_ctx
, void *timeout_ctx
)
5448 struct wpa_radio_work
*work
= eloop_ctx
;
5449 struct wpa_external_work
*ework
= work
->ctx
;
5451 wpa_dbg(work
->wpa_s
, MSG_DEBUG
,
5452 "Timing out external radio work %u (%s)",
5453 ework
->id
, work
->type
);
5454 wpa_msg(work
->wpa_s
, MSG_INFO
, EXT_RADIO_WORK_TIMEOUT
"%u", ework
->id
);
5456 radio_work_done(work
);
5460 static void wpas_ctrl_radio_work_cb(struct wpa_radio_work
*work
, int deinit
)
5462 struct wpa_external_work
*ework
= work
->ctx
;
5469 wpa_dbg(work
->wpa_s
, MSG_DEBUG
, "Starting external radio work %u (%s)",
5470 ework
->id
, ework
->type
);
5471 wpa_msg(work
->wpa_s
, MSG_INFO
, EXT_RADIO_WORK_START
"%u", ework
->id
);
5472 if (!ework
->timeout
)
5473 ework
->timeout
= 10;
5474 eloop_register_timeout(ework
->timeout
, 0, wpas_ctrl_radio_work_timeout
,
5479 static int wpas_ctrl_radio_work_add(struct wpa_supplicant
*wpa_s
, char *cmd
,
5480 char *buf
, size_t buflen
)
5482 struct wpa_external_work
*ework
;
5486 unsigned int freq
= 0;
5488 /* format: <name> [freq=<MHz>] [timeout=<seconds>] */
5490 ework
= os_zalloc(sizeof(*ework
));
5494 pos
= os_strchr(cmd
, ' ');
5496 type_len
= pos
- cmd
;
5499 pos2
= os_strstr(pos
, "freq=");
5501 freq
= atoi(pos2
+ 5);
5503 pos2
= os_strstr(pos
, "timeout=");
5505 ework
->timeout
= atoi(pos2
+ 8);
5507 type_len
= os_strlen(cmd
);
5509 if (4 + type_len
>= sizeof(ework
->type
))
5510 type_len
= sizeof(ework
->type
) - 4 - 1;
5511 os_strlcpy(ework
->type
, "ext:", sizeof(ework
->type
));
5512 os_memcpy(ework
->type
+ 4, cmd
, type_len
);
5513 ework
->type
[4 + type_len
] = '\0';
5515 wpa_s
->ext_work_id
++;
5516 if (wpa_s
->ext_work_id
== 0)
5517 wpa_s
->ext_work_id
++;
5518 ework
->id
= wpa_s
->ext_work_id
;
5520 if (radio_add_work(wpa_s
, freq
, ework
->type
, 0, wpas_ctrl_radio_work_cb
,
5526 ret
= os_snprintf(buf
, buflen
, "%u", ework
->id
);
5527 if (ret
< 0 || (size_t) ret
>= buflen
)
5533 static int wpas_ctrl_radio_work_done(struct wpa_supplicant
*wpa_s
, char *cmd
)
5535 struct wpa_radio_work
*work
;
5536 unsigned int id
= atoi(cmd
);
5538 dl_list_for_each(work
, &wpa_s
->radio
->work
, struct wpa_radio_work
, list
)
5540 struct wpa_external_work
*ework
;
5542 if (os_strncmp(work
->type
, "ext:", 4) != 0)
5545 if (id
&& ework
->id
!= id
)
5547 wpa_dbg(wpa_s
, MSG_DEBUG
,
5548 "Completed external radio work %u (%s)",
5549 ework
->id
, ework
->type
);
5550 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
, work
, NULL
);
5552 radio_work_done(work
);
5553 return 3; /* "OK\n" */
5560 static int wpas_ctrl_radio_work(struct wpa_supplicant
*wpa_s
, char *cmd
,
5561 char *buf
, size_t buflen
)
5563 if (os_strcmp(cmd
, "show") == 0)
5564 return wpas_ctrl_radio_work_show(wpa_s
, buf
, buflen
);
5565 if (os_strncmp(cmd
, "add ", 4) == 0)
5566 return wpas_ctrl_radio_work_add(wpa_s
, cmd
+ 4, buf
, buflen
);
5567 if (os_strncmp(cmd
, "done ", 5) == 0)
5568 return wpas_ctrl_radio_work_done(wpa_s
, cmd
+ 4);
5573 void wpas_ctrl_radio_work_flush(struct wpa_supplicant
*wpa_s
)
5575 struct wpa_radio_work
*work
, *tmp
;
5577 if (!wpa_s
|| !wpa_s
->radio
)
5580 dl_list_for_each_safe(work
, tmp
, &wpa_s
->radio
->work
,
5581 struct wpa_radio_work
, list
) {
5582 struct wpa_external_work
*ework
;
5584 if (os_strncmp(work
->type
, "ext:", 4) != 0)
5587 wpa_dbg(wpa_s
, MSG_DEBUG
,
5588 "Flushing %sexternal radio work %u (%s)",
5589 work
->started
? " started" : "", ework
->id
,
5592 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
,
5595 radio_work_done(work
);
5600 static void wpas_ctrl_eapol_response(void *eloop_ctx
, void *timeout_ctx
)
5602 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
5603 eapol_sm_notify_ctrl_response(wpa_s
->eapol
);
5607 static int set_scan_freqs(struct wpa_supplicant
*wpa_s
, char *val
)
5611 freqs
= freq_range_to_channel_list(wpa_s
, val
);
5615 os_free(wpa_s
->manual_scan_freqs
);
5616 wpa_s
->manual_scan_freqs
= freqs
;
5622 static void wpas_ctrl_scan(struct wpa_supplicant
*wpa_s
, char *params
,
5623 char *reply
, int reply_size
, int *reply_len
)
5627 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
5632 wpa_s
->manual_scan_passive
= 0;
5633 wpa_s
->manual_scan_use_id
= 0;
5634 wpa_s
->manual_scan_only_new
= 0;
5637 if (os_strncasecmp(params
, "TYPE=ONLY", 9) == 0)
5638 wpa_s
->scan_res_handler
= scan_only_handler
;
5640 pos
= os_strstr(params
, "freq=");
5641 if (pos
&& set_scan_freqs(wpa_s
, pos
+ 5) < 0) {
5646 pos
= os_strstr(params
, "passive=");
5648 wpa_s
->manual_scan_passive
= !!atoi(pos
+ 8);
5650 pos
= os_strstr(params
, "use_id=");
5652 wpa_s
->manual_scan_use_id
= atoi(pos
+ 7);
5654 pos
= os_strstr(params
, "only_new=1");
5656 wpa_s
->manual_scan_only_new
= 1;
5658 os_free(wpa_s
->manual_scan_freqs
);
5659 wpa_s
->manual_scan_freqs
= NULL
;
5660 if (wpa_s
->scan_res_handler
== scan_only_handler
)
5661 wpa_s
->scan_res_handler
= NULL
;
5664 if (!wpa_s
->sched_scanning
&& !wpa_s
->scanning
&&
5665 ((wpa_s
->wpa_state
<= WPA_SCANNING
) ||
5666 (wpa_s
->wpa_state
== WPA_COMPLETED
))) {
5667 wpa_s
->normal_scans
= 0;
5668 wpa_s
->scan_req
= MANUAL_SCAN_REQ
;
5669 wpa_s
->after_wps
= 0;
5670 wpa_s
->known_wps_freq
= 0;
5671 wpa_supplicant_req_scan(wpa_s
, 0, 0);
5672 if (wpa_s
->manual_scan_use_id
) {
5673 wpa_s
->manual_scan_id
++;
5674 wpa_dbg(wpa_s
, MSG_DEBUG
, "Assigned scan id %u",
5675 wpa_s
->manual_scan_id
);
5676 *reply_len
= os_snprintf(reply
, reply_size
, "%u\n",
5677 wpa_s
->manual_scan_id
);
5679 } else if (wpa_s
->sched_scanning
) {
5680 wpa_printf(MSG_DEBUG
, "Stop ongoing sched_scan to allow requested full scan to proceed");
5681 wpa_supplicant_cancel_sched_scan(wpa_s
);
5682 wpa_s
->scan_req
= MANUAL_SCAN_REQ
;
5683 wpa_supplicant_req_scan(wpa_s
, 0, 0);
5684 if (wpa_s
->manual_scan_use_id
) {
5685 wpa_s
->manual_scan_id
++;
5686 *reply_len
= os_snprintf(reply
, reply_size
, "%u\n",
5687 wpa_s
->manual_scan_id
);
5688 wpa_dbg(wpa_s
, MSG_DEBUG
, "Assigned scan id %u",
5689 wpa_s
->manual_scan_id
);
5692 wpa_printf(MSG_DEBUG
, "Ongoing scan action - reject new request");
5693 *reply_len
= os_snprintf(reply
, reply_size
, "FAIL-BUSY\n");
5698 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant
*wpa_s
,
5699 char *buf
, size_t *resp_len
)
5702 const int reply_size
= 4096;
5705 if (os_strncmp(buf
, WPA_CTRL_RSP
, os_strlen(WPA_CTRL_RSP
)) == 0 ||
5706 os_strncmp(buf
, "SET_NETWORK ", 12) == 0) {
5707 if (wpa_debug_show_keys
)
5708 wpa_dbg(wpa_s
, MSG_DEBUG
,
5709 "Control interface command '%s'", buf
);
5711 wpa_dbg(wpa_s
, MSG_DEBUG
,
5712 "Control interface command '%s [REMOVED]'",
5713 os_strncmp(buf
, WPA_CTRL_RSP
,
5714 os_strlen(WPA_CTRL_RSP
)) == 0 ?
5715 WPA_CTRL_RSP
: "SET_NETWORK");
5716 } else if (os_strncmp(buf
, "WPS_NFC_TAG_READ", 16) == 0 ||
5717 os_strncmp(buf
, "NFC_REPORT_HANDOVER", 19) == 0 ||
5718 os_strncmp(buf
, "NFC_RX_HANDOVER_SEL", 19) == 0) {
5719 wpa_hexdump_ascii_key(MSG_DEBUG
, "RX ctrl_iface",
5720 (const u8
*) buf
, os_strlen(buf
));
5722 int level
= MSG_DEBUG
;
5723 if (os_strcmp(buf
, "PING") == 0)
5724 level
= MSG_EXCESSIVE
;
5725 wpa_dbg(wpa_s
, level
, "Control interface command '%s'", buf
);
5728 reply
= os_malloc(reply_size
);
5729 if (reply
== NULL
) {
5734 os_memcpy(reply
, "OK\n", 3);
5737 if (os_strcmp(buf
, "PING") == 0) {
5738 os_memcpy(reply
, "PONG\n", 5);
5740 } else if (os_strcmp(buf
, "IFNAME") == 0) {
5741 reply_len
= os_strlen(wpa_s
->ifname
);
5742 os_memcpy(reply
, wpa_s
->ifname
, reply_len
);
5743 } else if (os_strncmp(buf
, "RELOG", 5) == 0) {
5744 if (wpa_debug_reopen_file() < 0)
5746 } else if (os_strncmp(buf
, "NOTE ", 5) == 0) {
5747 wpa_printf(MSG_INFO
, "NOTE: %s", buf
+ 5);
5748 } else if (os_strcmp(buf
, "MIB") == 0) {
5749 reply_len
= wpa_sm_get_mib(wpa_s
->wpa
, reply
, reply_size
);
5750 if (reply_len
>= 0) {
5752 res
= eapol_sm_get_mib(wpa_s
->eapol
, reply
+ reply_len
,
5753 reply_size
- reply_len
);
5759 } else if (os_strncmp(buf
, "STATUS", 6) == 0) {
5760 reply_len
= wpa_supplicant_ctrl_iface_status(
5761 wpa_s
, buf
+ 6, reply
, reply_size
);
5762 } else if (os_strcmp(buf
, "PMKSA") == 0) {
5763 reply_len
= wpa_sm_pmksa_cache_list(wpa_s
->wpa
, reply
,
5765 } else if (os_strncmp(buf
, "SET ", 4) == 0) {
5766 if (wpa_supplicant_ctrl_iface_set(wpa_s
, buf
+ 4))
5768 } else if (os_strncmp(buf
, "GET ", 4) == 0) {
5769 reply_len
= wpa_supplicant_ctrl_iface_get(wpa_s
, buf
+ 4,
5771 } else if (os_strcmp(buf
, "LOGON") == 0) {
5772 eapol_sm_notify_logoff(wpa_s
->eapol
, FALSE
);
5773 } else if (os_strcmp(buf
, "LOGOFF") == 0) {
5774 eapol_sm_notify_logoff(wpa_s
->eapol
, TRUE
);
5775 } else if (os_strcmp(buf
, "REASSOCIATE") == 0) {
5776 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
5779 wpas_request_connection(wpa_s
);
5780 } else if (os_strcmp(buf
, "RECONNECT") == 0) {
5781 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
5783 else if (wpa_s
->disconnected
)
5784 wpas_request_connection(wpa_s
);
5785 #ifdef IEEE8021X_EAPOL
5786 } else if (os_strncmp(buf
, "PREAUTH ", 8) == 0) {
5787 if (wpa_supplicant_ctrl_iface_preauth(wpa_s
, buf
+ 8))
5789 #endif /* IEEE8021X_EAPOL */
5790 #ifdef CONFIG_PEERKEY
5791 } else if (os_strncmp(buf
, "STKSTART ", 9) == 0) {
5792 if (wpa_supplicant_ctrl_iface_stkstart(wpa_s
, buf
+ 9))
5794 #endif /* CONFIG_PEERKEY */
5795 #ifdef CONFIG_IEEE80211R
5796 } else if (os_strncmp(buf
, "FT_DS ", 6) == 0) {
5797 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s
, buf
+ 6))
5799 #endif /* CONFIG_IEEE80211R */
5801 } else if (os_strcmp(buf
, "WPS_PBC") == 0) {
5802 int res
= wpa_supplicant_ctrl_iface_wps_pbc(wpa_s
, NULL
);
5804 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
5808 } else if (os_strncmp(buf
, "WPS_PBC ", 8) == 0) {
5809 int res
= wpa_supplicant_ctrl_iface_wps_pbc(wpa_s
, buf
+ 8);
5811 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
5815 } else if (os_strncmp(buf
, "WPS_PIN ", 8) == 0) {
5816 reply_len
= wpa_supplicant_ctrl_iface_wps_pin(wpa_s
, buf
+ 8,
5819 } else if (os_strncmp(buf
, "WPS_CHECK_PIN ", 14) == 0) {
5820 reply_len
= wpa_supplicant_ctrl_iface_wps_check_pin(
5821 wpa_s
, buf
+ 14, reply
, reply_size
);
5822 } else if (os_strcmp(buf
, "WPS_CANCEL") == 0) {
5823 if (wpas_wps_cancel(wpa_s
))
5825 #ifdef CONFIG_WPS_NFC
5826 } else if (os_strcmp(buf
, "WPS_NFC") == 0) {
5827 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s
, NULL
))
5829 } else if (os_strncmp(buf
, "WPS_NFC ", 8) == 0) {
5830 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s
, buf
+ 8))
5832 } else if (os_strncmp(buf
, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
5833 reply_len
= wpa_supplicant_ctrl_iface_wps_nfc_config_token(
5834 wpa_s
, buf
+ 21, reply
, reply_size
);
5835 } else if (os_strncmp(buf
, "WPS_NFC_TOKEN ", 14) == 0) {
5836 reply_len
= wpa_supplicant_ctrl_iface_wps_nfc_token(
5837 wpa_s
, buf
+ 14, reply
, reply_size
);
5838 } else if (os_strncmp(buf
, "WPS_NFC_TAG_READ ", 17) == 0) {
5839 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s
,
5842 } else if (os_strncmp(buf
, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
5843 reply_len
= wpas_ctrl_nfc_get_handover_req(
5844 wpa_s
, buf
+ 21, reply
, reply_size
);
5845 } else if (os_strncmp(buf
, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
5846 reply_len
= wpas_ctrl_nfc_get_handover_sel(
5847 wpa_s
, buf
+ 21, reply
, reply_size
);
5848 } else if (os_strncmp(buf
, "NFC_RX_HANDOVER_REQ ", 20) == 0) {
5849 reply_len
= wpas_ctrl_nfc_rx_handover_req(
5850 wpa_s
, buf
+ 20, reply
, reply_size
);
5851 } else if (os_strncmp(buf
, "NFC_RX_HANDOVER_SEL ", 20) == 0) {
5852 if (wpas_ctrl_nfc_rx_handover_sel(wpa_s
, buf
+ 20))
5854 } else if (os_strncmp(buf
, "NFC_REPORT_HANDOVER ", 20) == 0) {
5855 if (wpas_ctrl_nfc_report_handover(wpa_s
, buf
+ 20))
5857 #endif /* CONFIG_WPS_NFC */
5858 } else if (os_strncmp(buf
, "WPS_REG ", 8) == 0) {
5859 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s
, buf
+ 8))
5862 } else if (os_strncmp(buf
, "WPS_AP_PIN ", 11) == 0) {
5863 reply_len
= wpa_supplicant_ctrl_iface_wps_ap_pin(
5864 wpa_s
, buf
+ 11, reply
, reply_size
);
5865 #endif /* CONFIG_AP */
5866 #ifdef CONFIG_WPS_ER
5867 } else if (os_strcmp(buf
, "WPS_ER_START") == 0) {
5868 if (wpas_wps_er_start(wpa_s
, NULL
))
5870 } else if (os_strncmp(buf
, "WPS_ER_START ", 13) == 0) {
5871 if (wpas_wps_er_start(wpa_s
, buf
+ 13))
5873 } else if (os_strcmp(buf
, "WPS_ER_STOP") == 0) {
5874 if (wpas_wps_er_stop(wpa_s
))
5876 } else if (os_strncmp(buf
, "WPS_ER_PIN ", 11) == 0) {
5877 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s
, buf
+ 11))
5879 } else if (os_strncmp(buf
, "WPS_ER_PBC ", 11) == 0) {
5880 int ret
= wpas_wps_er_pbc(wpa_s
, buf
+ 11);
5882 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
5884 } else if (ret
== -3) {
5885 os_memcpy(reply
, "FAIL-UNKNOWN-UUID\n", 18);
5887 } else if (ret
== -4) {
5888 os_memcpy(reply
, "FAIL-NO-AP-SETTINGS\n", 20);
5892 } else if (os_strncmp(buf
, "WPS_ER_LEARN ", 13) == 0) {
5893 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s
, buf
+ 13))
5895 } else if (os_strncmp(buf
, "WPS_ER_SET_CONFIG ", 18) == 0) {
5896 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s
,
5899 } else if (os_strncmp(buf
, "WPS_ER_CONFIG ", 14) == 0) {
5900 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s
, buf
+ 14))
5902 #ifdef CONFIG_WPS_NFC
5903 } else if (os_strncmp(buf
, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
5904 reply_len
= wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
5905 wpa_s
, buf
+ 24, reply
, reply_size
);
5906 #endif /* CONFIG_WPS_NFC */
5907 #endif /* CONFIG_WPS_ER */
5908 #endif /* CONFIG_WPS */
5909 #ifdef CONFIG_IBSS_RSN
5910 } else if (os_strncmp(buf
, "IBSS_RSN ", 9) == 0) {
5911 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s
, buf
+ 9))
5913 #endif /* CONFIG_IBSS_RSN */
5915 } else if (os_strncmp(buf
, "P2P_FIND ", 9) == 0) {
5916 if (p2p_ctrl_find(wpa_s
, buf
+ 9))
5918 } else if (os_strcmp(buf
, "P2P_FIND") == 0) {
5919 if (p2p_ctrl_find(wpa_s
, ""))
5921 } else if (os_strcmp(buf
, "P2P_STOP_FIND") == 0) {
5922 wpas_p2p_stop_find(wpa_s
);
5923 } else if (os_strncmp(buf
, "P2P_CONNECT ", 12) == 0) {
5924 reply_len
= p2p_ctrl_connect(wpa_s
, buf
+ 12, reply
,
5926 } else if (os_strncmp(buf
, "P2P_LISTEN ", 11) == 0) {
5927 if (p2p_ctrl_listen(wpa_s
, buf
+ 11))
5929 } else if (os_strcmp(buf
, "P2P_LISTEN") == 0) {
5930 if (p2p_ctrl_listen(wpa_s
, ""))
5932 } else if (os_strncmp(buf
, "P2P_GROUP_REMOVE ", 17) == 0) {
5933 if (wpas_p2p_group_remove(wpa_s
, buf
+ 17))
5935 } else if (os_strcmp(buf
, "P2P_GROUP_ADD") == 0) {
5936 if (wpas_p2p_group_add(wpa_s
, 0, 0, 0, 0))
5938 } else if (os_strncmp(buf
, "P2P_GROUP_ADD ", 14) == 0) {
5939 if (p2p_ctrl_group_add(wpa_s
, buf
+ 14))
5941 } else if (os_strncmp(buf
, "P2P_PROV_DISC ", 14) == 0) {
5942 if (p2p_ctrl_prov_disc(wpa_s
, buf
+ 14))
5944 } else if (os_strcmp(buf
, "P2P_GET_PASSPHRASE") == 0) {
5945 reply_len
= p2p_get_passphrase(wpa_s
, reply
, reply_size
);
5946 } else if (os_strncmp(buf
, "P2P_SERV_DISC_REQ ", 18) == 0) {
5947 reply_len
= p2p_ctrl_serv_disc_req(wpa_s
, buf
+ 18, reply
,
5949 } else if (os_strncmp(buf
, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
5950 if (p2p_ctrl_serv_disc_cancel_req(wpa_s
, buf
+ 25) < 0)
5952 } else if (os_strncmp(buf
, "P2P_SERV_DISC_RESP ", 19) == 0) {
5953 if (p2p_ctrl_serv_disc_resp(wpa_s
, buf
+ 19) < 0)
5955 } else if (os_strcmp(buf
, "P2P_SERVICE_UPDATE") == 0) {
5956 wpas_p2p_sd_service_update(wpa_s
);
5957 } else if (os_strncmp(buf
, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
5958 if (p2p_ctrl_serv_disc_external(wpa_s
, buf
+ 23) < 0)
5960 } else if (os_strcmp(buf
, "P2P_SERVICE_FLUSH") == 0) {
5961 wpas_p2p_service_flush(wpa_s
);
5962 } else if (os_strncmp(buf
, "P2P_SERVICE_ADD ", 16) == 0) {
5963 if (p2p_ctrl_service_add(wpa_s
, buf
+ 16) < 0)
5965 } else if (os_strncmp(buf
, "P2P_SERVICE_DEL ", 16) == 0) {
5966 if (p2p_ctrl_service_del(wpa_s
, buf
+ 16) < 0)
5968 } else if (os_strncmp(buf
, "P2P_REJECT ", 11) == 0) {
5969 if (p2p_ctrl_reject(wpa_s
, buf
+ 11) < 0)
5971 } else if (os_strncmp(buf
, "P2P_INVITE ", 11) == 0) {
5972 if (p2p_ctrl_invite(wpa_s
, buf
+ 11) < 0)
5974 } else if (os_strncmp(buf
, "P2P_PEER ", 9) == 0) {
5975 reply_len
= p2p_ctrl_peer(wpa_s
, buf
+ 9, reply
,
5977 } else if (os_strncmp(buf
, "P2P_SET ", 8) == 0) {
5978 if (p2p_ctrl_set(wpa_s
, buf
+ 8) < 0)
5980 } else if (os_strcmp(buf
, "P2P_FLUSH") == 0) {
5981 p2p_ctrl_flush(wpa_s
);
5982 } else if (os_strncmp(buf
, "P2P_UNAUTHORIZE ", 16) == 0) {
5983 if (wpas_p2p_unauthorize(wpa_s
, buf
+ 16) < 0)
5985 } else if (os_strcmp(buf
, "P2P_CANCEL") == 0) {
5986 if (wpas_p2p_cancel(wpa_s
))
5988 } else if (os_strncmp(buf
, "P2P_PRESENCE_REQ ", 17) == 0) {
5989 if (p2p_ctrl_presence_req(wpa_s
, buf
+ 17) < 0)
5991 } else if (os_strcmp(buf
, "P2P_PRESENCE_REQ") == 0) {
5992 if (p2p_ctrl_presence_req(wpa_s
, "") < 0)
5994 } else if (os_strncmp(buf
, "P2P_EXT_LISTEN ", 15) == 0) {
5995 if (p2p_ctrl_ext_listen(wpa_s
, buf
+ 15) < 0)
5997 } else if (os_strcmp(buf
, "P2P_EXT_LISTEN") == 0) {
5998 if (p2p_ctrl_ext_listen(wpa_s
, "") < 0)
6000 } else if (os_strncmp(buf
, "P2P_REMOVE_CLIENT ", 18) == 0) {
6001 if (p2p_ctrl_remove_client(wpa_s
, buf
+ 18) < 0)
6003 #endif /* CONFIG_P2P */
6004 #ifdef CONFIG_WIFI_DISPLAY
6005 } else if (os_strncmp(buf
, "WFD_SUBELEM_SET ", 16) == 0) {
6006 if (wifi_display_subelem_set(wpa_s
->global
, buf
+ 16) < 0)
6008 } else if (os_strncmp(buf
, "WFD_SUBELEM_GET ", 16) == 0) {
6009 reply_len
= wifi_display_subelem_get(wpa_s
->global
, buf
+ 16,
6011 #endif /* CONFIG_WIFI_DISPLAY */
6012 #ifdef CONFIG_INTERWORKING
6013 } else if (os_strcmp(buf
, "FETCH_ANQP") == 0) {
6014 if (interworking_fetch_anqp(wpa_s
) < 0)
6016 } else if (os_strcmp(buf
, "STOP_FETCH_ANQP") == 0) {
6017 interworking_stop_fetch_anqp(wpa_s
);
6018 } else if (os_strcmp(buf
, "INTERWORKING_SELECT") == 0) {
6019 if (ctrl_interworking_select(wpa_s
, NULL
) < 0)
6021 } else if (os_strncmp(buf
, "INTERWORKING_SELECT ", 20) == 0) {
6022 if (ctrl_interworking_select(wpa_s
, buf
+ 20) < 0)
6024 } else if (os_strncmp(buf
, "INTERWORKING_CONNECT ", 21) == 0) {
6025 if (ctrl_interworking_connect(wpa_s
, buf
+ 21) < 0)
6027 } else if (os_strncmp(buf
, "ANQP_GET ", 9) == 0) {
6028 if (get_anqp(wpa_s
, buf
+ 9) < 0)
6030 } else if (os_strncmp(buf
, "GAS_REQUEST ", 12) == 0) {
6031 if (gas_request(wpa_s
, buf
+ 12) < 0)
6033 } else if (os_strncmp(buf
, "GAS_RESPONSE_GET ", 17) == 0) {
6034 reply_len
= gas_response_get(wpa_s
, buf
+ 17, reply
,
6036 #endif /* CONFIG_INTERWORKING */
6038 } else if (os_strncmp(buf
, "HS20_ANQP_GET ", 14) == 0) {
6039 if (get_hs20_anqp(wpa_s
, buf
+ 14) < 0)
6041 } else if (os_strncmp(buf
, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
6042 if (hs20_get_nai_home_realm_list(wpa_s
, buf
+ 29) < 0)
6044 #endif /* CONFIG_HS20 */
6045 } else if (os_strncmp(buf
, WPA_CTRL_RSP
, os_strlen(WPA_CTRL_RSP
)) == 0)
6047 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
6048 wpa_s
, buf
+ os_strlen(WPA_CTRL_RSP
)))
6052 * Notify response from timeout to allow the control
6053 * interface response to be sent first.
6055 eloop_register_timeout(0, 0, wpas_ctrl_eapol_response
,
6058 } else if (os_strcmp(buf
, "RECONFIGURE") == 0) {
6059 if (wpa_supplicant_reload_configuration(wpa_s
))
6061 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
6062 wpa_supplicant_terminate_proc(wpa_s
->global
);
6063 } else if (os_strncmp(buf
, "BSSID ", 6) == 0) {
6064 if (wpa_supplicant_ctrl_iface_bssid(wpa_s
, buf
+ 6))
6066 } else if (os_strncmp(buf
, "BLACKLIST", 9) == 0) {
6067 reply_len
= wpa_supplicant_ctrl_iface_blacklist(
6068 wpa_s
, buf
+ 9, reply
, reply_size
);
6069 } else if (os_strncmp(buf
, "LOG_LEVEL", 9) == 0) {
6070 reply_len
= wpa_supplicant_ctrl_iface_log_level(
6071 wpa_s
, buf
+ 9, reply
, reply_size
);
6072 } else if (os_strcmp(buf
, "LIST_NETWORKS") == 0) {
6073 reply_len
= wpa_supplicant_ctrl_iface_list_networks(
6074 wpa_s
, reply
, reply_size
);
6075 } else if (os_strcmp(buf
, "DISCONNECT") == 0) {
6077 wpa_s
->sme
.prev_bssid_set
= 0;
6078 #endif /* CONFIG_SME */
6079 wpa_s
->reassociate
= 0;
6080 wpa_s
->disconnected
= 1;
6081 wpa_supplicant_cancel_sched_scan(wpa_s
);
6082 wpa_supplicant_cancel_scan(wpa_s
);
6083 wpa_supplicant_deauthenticate(wpa_s
,
6084 WLAN_REASON_DEAUTH_LEAVING
);
6085 } else if (os_strcmp(buf
, "SCAN") == 0) {
6086 wpas_ctrl_scan(wpa_s
, NULL
, reply
, reply_size
, &reply_len
);
6087 } else if (os_strncmp(buf
, "SCAN ", 5) == 0) {
6088 wpas_ctrl_scan(wpa_s
, buf
+ 5, reply
, reply_size
, &reply_len
);
6089 } else if (os_strcmp(buf
, "SCAN_RESULTS") == 0) {
6090 reply_len
= wpa_supplicant_ctrl_iface_scan_results(
6091 wpa_s
, reply
, reply_size
);
6092 } else if (os_strncmp(buf
, "SELECT_NETWORK ", 15) == 0) {
6093 if (wpa_supplicant_ctrl_iface_select_network(wpa_s
, buf
+ 15))
6095 } else if (os_strncmp(buf
, "ENABLE_NETWORK ", 15) == 0) {
6096 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s
, buf
+ 15))
6098 } else if (os_strncmp(buf
, "DISABLE_NETWORK ", 16) == 0) {
6099 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s
, buf
+ 16))
6101 } else if (os_strcmp(buf
, "ADD_NETWORK") == 0) {
6102 reply_len
= wpa_supplicant_ctrl_iface_add_network(
6103 wpa_s
, reply
, reply_size
);
6104 } else if (os_strncmp(buf
, "REMOVE_NETWORK ", 15) == 0) {
6105 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s
, buf
+ 15))
6107 } else if (os_strncmp(buf
, "SET_NETWORK ", 12) == 0) {
6108 if (wpa_supplicant_ctrl_iface_set_network(wpa_s
, buf
+ 12))
6110 } else if (os_strncmp(buf
, "GET_NETWORK ", 12) == 0) {
6111 reply_len
= wpa_supplicant_ctrl_iface_get_network(
6112 wpa_s
, buf
+ 12, reply
, reply_size
);
6113 } else if (os_strcmp(buf
, "LIST_CREDS") == 0) {
6114 reply_len
= wpa_supplicant_ctrl_iface_list_creds(
6115 wpa_s
, reply
, reply_size
);
6116 } else if (os_strcmp(buf
, "ADD_CRED") == 0) {
6117 reply_len
= wpa_supplicant_ctrl_iface_add_cred(
6118 wpa_s
, reply
, reply_size
);
6119 } else if (os_strncmp(buf
, "REMOVE_CRED ", 12) == 0) {
6120 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s
, buf
+ 12))
6122 } else if (os_strncmp(buf
, "SET_CRED ", 9) == 0) {
6123 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s
, buf
+ 9))
6125 #ifndef CONFIG_NO_CONFIG_WRITE
6126 } else if (os_strcmp(buf
, "SAVE_CONFIG") == 0) {
6127 if (wpa_supplicant_ctrl_iface_save_config(wpa_s
))
6129 #endif /* CONFIG_NO_CONFIG_WRITE */
6130 } else if (os_strncmp(buf
, "GET_CAPABILITY ", 15) == 0) {
6131 reply_len
= wpa_supplicant_ctrl_iface_get_capability(
6132 wpa_s
, buf
+ 15, reply
, reply_size
);
6133 } else if (os_strncmp(buf
, "AP_SCAN ", 8) == 0) {
6134 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s
, buf
+ 8))
6136 } else if (os_strncmp(buf
, "SCAN_INTERVAL ", 14) == 0) {
6137 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s
, buf
+ 14))
6139 } else if (os_strcmp(buf
, "INTERFACE_LIST") == 0) {
6140 reply_len
= wpa_supplicant_global_iface_list(
6141 wpa_s
->global
, reply
, reply_size
);
6142 } else if (os_strcmp(buf
, "INTERFACES") == 0) {
6143 reply_len
= wpa_supplicant_global_iface_interfaces(
6144 wpa_s
->global
, reply
, reply_size
);
6145 } else if (os_strncmp(buf
, "BSS ", 4) == 0) {
6146 reply_len
= wpa_supplicant_ctrl_iface_bss(
6147 wpa_s
, buf
+ 4, reply
, reply_size
);
6149 } else if (os_strcmp(buf
, "STA-FIRST") == 0) {
6150 reply_len
= ap_ctrl_iface_sta_first(wpa_s
, reply
, reply_size
);
6151 } else if (os_strncmp(buf
, "STA ", 4) == 0) {
6152 reply_len
= ap_ctrl_iface_sta(wpa_s
, buf
+ 4, reply
,
6154 } else if (os_strncmp(buf
, "STA-NEXT ", 9) == 0) {
6155 reply_len
= ap_ctrl_iface_sta_next(wpa_s
, buf
+ 9, reply
,
6157 } else if (os_strncmp(buf
, "DEAUTHENTICATE ", 15) == 0) {
6158 if (ap_ctrl_iface_sta_deauthenticate(wpa_s
, buf
+ 15))
6160 } else if (os_strncmp(buf
, "DISASSOCIATE ", 13) == 0) {
6161 if (ap_ctrl_iface_sta_disassociate(wpa_s
, buf
+ 13))
6163 } else if (os_strncmp(buf
, "CHAN_SWITCH ", 12) == 0) {
6164 if (ap_ctrl_iface_chanswitch(wpa_s
, buf
+ 12))
6166 #endif /* CONFIG_AP */
6167 } else if (os_strcmp(buf
, "SUSPEND") == 0) {
6168 wpas_notify_suspend(wpa_s
->global
);
6169 } else if (os_strcmp(buf
, "RESUME") == 0) {
6170 wpas_notify_resume(wpa_s
->global
);
6171 } else if (os_strcmp(buf
, "DROP_SA") == 0) {
6172 wpa_supplicant_ctrl_iface_drop_sa(wpa_s
);
6173 } else if (os_strncmp(buf
, "ROAM ", 5) == 0) {
6174 if (wpa_supplicant_ctrl_iface_roam(wpa_s
, buf
+ 5))
6176 } else if (os_strncmp(buf
, "STA_AUTOCONNECT ", 16) == 0) {
6177 if (wpa_supplicant_ctrl_iface_sta_autoconnect(wpa_s
, buf
+ 16))
6179 } else if (os_strncmp(buf
, "BSS_EXPIRE_AGE ", 15) == 0) {
6180 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s
, buf
+ 15))
6182 } else if (os_strncmp(buf
, "BSS_EXPIRE_COUNT ", 17) == 0) {
6183 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s
,
6186 } else if (os_strncmp(buf
, "BSS_FLUSH ", 10) == 0) {
6187 if (wpa_supplicant_ctrl_iface_bss_flush(wpa_s
, buf
+ 10))
6190 } else if (os_strncmp(buf
, "TDLS_DISCOVER ", 14) == 0) {
6191 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s
, buf
+ 14))
6193 } else if (os_strncmp(buf
, "TDLS_SETUP ", 11) == 0) {
6194 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s
, buf
+ 11))
6196 } else if (os_strncmp(buf
, "TDLS_TEARDOWN ", 14) == 0) {
6197 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s
, buf
+ 14))
6199 #endif /* CONFIG_TDLS */
6200 } else if (os_strncmp(buf
, "SIGNAL_POLL", 11) == 0) {
6201 reply_len
= wpa_supplicant_signal_poll(wpa_s
, reply
,
6203 } else if (os_strncmp(buf
, "PKTCNT_POLL", 11) == 0) {
6204 reply_len
= wpa_supplicant_pktcnt_poll(wpa_s
, reply
,
6206 #ifdef CONFIG_AUTOSCAN
6207 } else if (os_strncmp(buf
, "AUTOSCAN ", 9) == 0) {
6208 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s
, buf
+ 9))
6210 #endif /* CONFIG_AUTOSCAN */
6212 } else if (os_strncmp(buf
, "DRIVER ", 7) == 0) {
6213 reply_len
= wpa_supplicant_driver_cmd(wpa_s
, buf
+ 7, reply
,
6215 #endif /* ANDROID */
6216 } else if (os_strcmp(buf
, "REAUTHENTICATE") == 0) {
6217 pmksa_cache_clear_current(wpa_s
->wpa
);
6218 eapol_sm_request_reauth(wpa_s
->eapol
);
6220 } else if (os_strncmp(buf
, "WNM_SLEEP ", 10) == 0) {
6221 if (wpas_ctrl_iface_wnm_sleep(wpa_s
, buf
+ 10))
6223 } else if (os_strncmp(buf
, "WNM_BSS_QUERY ", 10) == 0) {
6224 if (wpas_ctrl_iface_wnm_bss_query(wpa_s
, buf
+ 10))
6226 #endif /* CONFIG_WNM */
6227 } else if (os_strcmp(buf
, "FLUSH") == 0) {
6228 wpa_supplicant_ctrl_iface_flush(wpa_s
);
6229 } else if (os_strncmp(buf
, "RADIO_WORK ", 11) == 0) {
6230 reply_len
= wpas_ctrl_radio_work(wpa_s
, buf
+ 11, reply
,
6233 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
6237 if (reply_len
< 0) {
6238 os_memcpy(reply
, "FAIL\n", 5);
6242 *resp_len
= reply_len
;
6247 static int wpa_supplicant_global_iface_add(struct wpa_global
*global
,
6250 struct wpa_interface iface
;
6254 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
6255 * TAB<bridge_ifname>
6257 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd
);
6259 os_memset(&iface
, 0, sizeof(iface
));
6262 iface
.ifname
= pos
= cmd
;
6263 pos
= os_strchr(pos
, '\t');
6266 if (iface
.ifname
[0] == '\0')
6271 iface
.confname
= pos
;
6272 pos
= os_strchr(pos
, '\t');
6275 if (iface
.confname
[0] == '\0')
6276 iface
.confname
= NULL
;
6281 pos
= os_strchr(pos
, '\t');
6284 if (iface
.driver
[0] == '\0')
6285 iface
.driver
= NULL
;
6289 iface
.ctrl_interface
= pos
;
6290 pos
= os_strchr(pos
, '\t');
6293 if (iface
.ctrl_interface
[0] == '\0')
6294 iface
.ctrl_interface
= NULL
;
6298 iface
.driver_param
= pos
;
6299 pos
= os_strchr(pos
, '\t');
6302 if (iface
.driver_param
[0] == '\0')
6303 iface
.driver_param
= NULL
;
6307 iface
.bridge_ifname
= pos
;
6308 pos
= os_strchr(pos
, '\t');
6311 if (iface
.bridge_ifname
[0] == '\0')
6312 iface
.bridge_ifname
= NULL
;
6317 if (wpa_supplicant_get_iface(global
, iface
.ifname
))
6320 return wpa_supplicant_add_iface(global
, &iface
) ? 0 : -1;
6324 static int wpa_supplicant_global_iface_remove(struct wpa_global
*global
,
6327 struct wpa_supplicant
*wpa_s
;
6329 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd
);
6331 wpa_s
= wpa_supplicant_get_iface(global
, cmd
);
6334 return wpa_supplicant_remove_iface(global
, wpa_s
, 0);
6338 static void wpa_free_iface_info(struct wpa_interface_info
*iface
)
6340 struct wpa_interface_info
*prev
;
6344 iface
= iface
->next
;
6346 os_free(prev
->ifname
);
6347 os_free(prev
->desc
);
6353 static int wpa_supplicant_global_iface_list(struct wpa_global
*global
,
6357 struct wpa_interface_info
*iface
= NULL
, *last
= NULL
, *tmp
;
6360 for (i
= 0; wpa_drivers
[i
]; i
++) {
6361 struct wpa_driver_ops
*drv
= wpa_drivers
[i
];
6362 if (drv
->get_interfaces
== NULL
)
6364 tmp
= drv
->get_interfaces(global
->drv_priv
[i
]);
6378 for (tmp
= iface
; tmp
; tmp
= tmp
->next
) {
6379 res
= os_snprintf(pos
, end
- pos
, "%s\t%s\t%s\n",
6380 tmp
->drv_name
, tmp
->ifname
,
6381 tmp
->desc
? tmp
->desc
: "");
6382 if (res
< 0 || res
>= end
- pos
) {
6389 wpa_free_iface_info(iface
);
6395 static int wpa_supplicant_global_iface_interfaces(struct wpa_global
*global
,
6400 struct wpa_supplicant
*wpa_s
;
6402 wpa_s
= global
->ifaces
;
6407 res
= os_snprintf(pos
, end
- pos
, "%s\n", wpa_s
->ifname
);
6408 if (res
< 0 || res
>= end
- pos
) {
6413 wpa_s
= wpa_s
->next
;
6419 static char * wpas_global_ctrl_iface_ifname(struct wpa_global
*global
,
6421 char *cmd
, size_t *resp_len
)
6423 struct wpa_supplicant
*wpa_s
;
6425 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
6426 if (os_strcmp(ifname
, wpa_s
->ifname
) == 0)
6430 if (wpa_s
== NULL
) {
6431 char *resp
= os_strdup("FAIL-NO-IFNAME-MATCH\n");
6433 *resp_len
= os_strlen(resp
);
6439 return wpa_supplicant_ctrl_iface_process(wpa_s
, cmd
, resp_len
);
6443 static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global
*global
,
6444 char *buf
, size_t *resp_len
)
6447 static const char * cmd
[] = {
6454 "P2P_GET_PASSPHRASE",
6455 "P2P_SERVICE_UPDATE",
6456 "P2P_SERVICE_FLUSH",
6463 static const char * prefix
[] = {
6466 #endif /* ANDROID */
6473 "P2P_GROUP_REMOVE ",
6476 "P2P_SERV_DISC_REQ ",
6477 "P2P_SERV_DISC_CANCEL_REQ ",
6478 "P2P_SERV_DISC_RESP ",
6479 "P2P_SERV_DISC_EXTERNAL ",
6487 "P2P_PRESENCE_REQ ",
6489 "P2P_REMOVE_CLIENT ",
6495 if (global
->p2p_init_wpa_s
== NULL
)
6498 for (i
= 0; !found
&& cmd
[i
]; i
++) {
6499 if (os_strcmp(buf
, cmd
[i
]) == 0)
6503 for (i
= 0; !found
&& prefix
[i
]; i
++) {
6504 if (os_strncmp(buf
, prefix
[i
], os_strlen(prefix
[i
])) == 0)
6509 return wpa_supplicant_ctrl_iface_process(global
->p2p_init_wpa_s
,
6511 #endif /* CONFIG_P2P */
6516 static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global
*global
,
6517 char *buf
, size_t *resp_len
)
6519 #ifdef CONFIG_WIFI_DISPLAY
6520 if (global
->p2p_init_wpa_s
== NULL
)
6522 if (os_strncmp(buf
, "WFD_SUBELEM_SET ", 16) == 0 ||
6523 os_strncmp(buf
, "WFD_SUBELEM_GET ", 16) == 0)
6524 return wpa_supplicant_ctrl_iface_process(global
->p2p_init_wpa_s
,
6526 #endif /* CONFIG_WIFI_DISPLAY */
6531 static char * wpas_global_ctrl_iface_redir(struct wpa_global
*global
,
6532 char *buf
, size_t *resp_len
)
6536 ret
= wpas_global_ctrl_iface_redir_p2p(global
, buf
, resp_len
);
6540 ret
= wpas_global_ctrl_iface_redir_wfd(global
, buf
, resp_len
);
6548 static int wpas_global_ctrl_iface_set(struct wpa_global
*global
, char *cmd
)
6552 value
= os_strchr(cmd
, ' ');
6557 wpa_printf(MSG_DEBUG
, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd
, value
);
6559 #ifdef CONFIG_WIFI_DISPLAY
6560 if (os_strcasecmp(cmd
, "wifi_display") == 0) {
6561 wifi_display_enable(global
, !!atoi(value
));
6564 #endif /* CONFIG_WIFI_DISPLAY */
6570 #ifndef CONFIG_NO_CONFIG_WRITE
6571 static int wpas_global_ctrl_iface_save_config(struct wpa_global
*global
)
6574 struct wpa_supplicant
*wpa_s
;
6576 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
6577 if (!wpa_s
->conf
->update_config
) {
6578 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
6582 if (wpa_config_write(wpa_s
->confname
, wpa_s
->conf
)) {
6583 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
6586 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
6592 #endif /* CONFIG_NO_CONFIG_WRITE */
6595 static int wpas_global_ctrl_iface_status(struct wpa_global
*global
,
6596 char *buf
, size_t buflen
)
6600 struct wpa_supplicant
*wpa_s
;
6606 if (global
->p2p
&& !global
->p2p_disabled
) {
6607 ret
= os_snprintf(pos
, end
- pos
, "p2p_device_address=" MACSTR
6610 MAC2STR(global
->p2p_dev_addr
),
6611 p2p_get_state_txt(global
->p2p
));
6612 if (ret
< 0 || ret
>= end
- pos
)
6615 } else if (global
->p2p
) {
6616 ret
= os_snprintf(pos
, end
- pos
, "p2p_state=DISABLED\n");
6617 if (ret
< 0 || ret
>= end
- pos
)
6621 #endif /* CONFIG_P2P */
6623 #ifdef CONFIG_WIFI_DISPLAY
6624 ret
= os_snprintf(pos
, end
- pos
, "wifi_display=%d\n",
6625 !!global
->wifi_display
);
6626 if (ret
< 0 || ret
>= end
- pos
)
6629 #endif /* CONFIG_WIFI_DISPLAY */
6631 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
6632 ret
= os_snprintf(pos
, end
- pos
, "ifname=%s\n"
6633 "address=" MACSTR
"\n",
6634 wpa_s
->ifname
, MAC2STR(wpa_s
->own_addr
));
6635 if (ret
< 0 || ret
>= end
- pos
)
6644 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global
*global
,
6645 char *buf
, size_t *resp_len
)
6648 const int reply_size
= 2048;
6650 int level
= MSG_DEBUG
;
6652 if (os_strncmp(buf
, "IFNAME=", 7) == 0) {
6653 char *pos
= os_strchr(buf
+ 7, ' ');
6656 return wpas_global_ctrl_iface_ifname(global
,
6662 reply
= wpas_global_ctrl_iface_redir(global
, buf
, resp_len
);
6666 if (os_strcmp(buf
, "PING") == 0)
6667 level
= MSG_EXCESSIVE
;
6668 wpa_hexdump_ascii(level
, "RX global ctrl_iface",
6669 (const u8
*) buf
, os_strlen(buf
));
6671 reply
= os_malloc(reply_size
);
6672 if (reply
== NULL
) {
6677 os_memcpy(reply
, "OK\n", 3);
6680 if (os_strcmp(buf
, "PING") == 0) {
6681 os_memcpy(reply
, "PONG\n", 5);
6683 } else if (os_strncmp(buf
, "INTERFACE_ADD ", 14) == 0) {
6684 if (wpa_supplicant_global_iface_add(global
, buf
+ 14))
6686 } else if (os_strncmp(buf
, "INTERFACE_REMOVE ", 17) == 0) {
6687 if (wpa_supplicant_global_iface_remove(global
, buf
+ 17))
6689 } else if (os_strcmp(buf
, "INTERFACE_LIST") == 0) {
6690 reply_len
= wpa_supplicant_global_iface_list(
6691 global
, reply
, reply_size
);
6692 } else if (os_strcmp(buf
, "INTERFACES") == 0) {
6693 reply_len
= wpa_supplicant_global_iface_interfaces(
6694 global
, reply
, reply_size
);
6695 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
6696 wpa_supplicant_terminate_proc(global
);
6697 } else if (os_strcmp(buf
, "SUSPEND") == 0) {
6698 wpas_notify_suspend(global
);
6699 } else if (os_strcmp(buf
, "RESUME") == 0) {
6700 wpas_notify_resume(global
);
6701 } else if (os_strncmp(buf
, "SET ", 4) == 0) {
6702 if (wpas_global_ctrl_iface_set(global
, buf
+ 4))
6704 #ifndef CONFIG_NO_CONFIG_WRITE
6705 } else if (os_strcmp(buf
, "SAVE_CONFIG") == 0) {
6706 if (wpas_global_ctrl_iface_save_config(global
))
6708 #endif /* CONFIG_NO_CONFIG_WRITE */
6709 } else if (os_strcmp(buf
, "STATUS") == 0) {
6710 reply_len
= wpas_global_ctrl_iface_status(global
, reply
,
6713 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
6717 if (reply_len
< 0) {
6718 os_memcpy(reply
, "FAIL\n", 5);
6722 *resp_len
= reply_len
;