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
;
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_sched_scan(wpa_s
);
68 wpa_supplicant_cancel_scan(wpa_s
);
71 os_memset(¶ms
, 0, sizeof(params
));
74 ssid
= wpa_s
->conf
->ssid
;
76 if (!wpas_network_disabled(wpa_s
, ssid
))
80 if (num_ssid
> WPAS_MAX_SCAN_SSIDS
) {
81 wpa_printf(MSG_DEBUG
, "PNO: Use only the first %u SSIDs from "
82 "%u", WPAS_MAX_SCAN_SSIDS
, (unsigned int) num_ssid
);
83 num_ssid
= WPAS_MAX_SCAN_SSIDS
;
87 wpa_printf(MSG_DEBUG
, "PNO: No configured SSIDs");
91 params
.filter_ssids
= os_malloc(sizeof(struct wpa_driver_scan_filter
) *
93 if (params
.filter_ssids
== NULL
)
96 ssid
= wpa_s
->conf
->ssid
;
98 if (!wpas_network_disabled(wpa_s
, ssid
)) {
99 params
.ssids
[i
].ssid
= ssid
->ssid
;
100 params
.ssids
[i
].ssid_len
= ssid
->ssid_len
;
102 os_memcpy(params
.filter_ssids
[i
].ssid
, ssid
->ssid
,
104 params
.filter_ssids
[i
].ssid_len
= ssid
->ssid_len
;
105 params
.num_filter_ssids
++;
113 if (wpa_s
->conf
->filter_rssi
)
114 params
.filter_rssi
= wpa_s
->conf
->filter_rssi
;
116 interval
= wpa_s
->conf
->sched_scan_interval
?
117 wpa_s
->conf
->sched_scan_interval
: 10;
119 ret
= wpa_supplicant_start_sched_scan(wpa_s
, ¶ms
, interval
);
120 os_free(params
.filter_ssids
);
127 static int pno_stop(struct wpa_supplicant
*wpa_s
)
133 ret
= wpa_supplicant_stop_sched_scan(wpa_s
);
136 if (wpa_s
->wpa_state
== WPA_SCANNING
)
137 wpa_supplicant_req_scan(wpa_s
, 0, 0);
143 static int set_bssid_filter(struct wpa_supplicant
*wpa_s
, char *val
)
146 u8 addr
[ETH_ALEN
], *filter
= NULL
, *n
;
153 if (hwaddr_aton(pos
, addr
)) {
157 n
= os_realloc_array(filter
, count
+ 1, ETH_ALEN
);
163 os_memcpy(filter
+ count
* ETH_ALEN
, addr
, ETH_ALEN
);
166 pos
= os_strchr(pos
, ' ');
171 wpa_hexdump(MSG_DEBUG
, "bssid_filter", filter
, count
* ETH_ALEN
);
172 os_free(wpa_s
->bssid_filter
);
173 wpa_s
->bssid_filter
= filter
;
174 wpa_s
->bssid_filter_count
= count
;
180 static int set_disallow_aps(struct wpa_supplicant
*wpa_s
, char *val
)
183 u8 addr
[ETH_ALEN
], *bssid
= NULL
, *n
;
184 struct wpa_ssid_value
*ssid
= NULL
, *ns
;
185 size_t count
= 0, ssid_count
= 0;
189 * disallow_list ::= <ssid_spec> | <bssid_spec> | <disallow_list> | ""
190 * SSID_SPEC ::= ssid <SSID_HEX>
191 * BSSID_SPEC ::= bssid <BSSID_HEX>
198 if (os_strncmp(pos
, "bssid ", 6) == 0) {
201 res
= hwaddr_aton2(pos
, addr
);
205 wpa_printf(MSG_DEBUG
, "Invalid disallow_aps "
206 "BSSID value '%s'", pos
);
210 n
= os_realloc_array(bssid
, count
+ 1, ETH_ALEN
);
217 os_memcpy(bssid
+ count
* ETH_ALEN
, addr
, ETH_ALEN
);
219 } else if (os_strncmp(pos
, "ssid ", 5) == 0) {
225 if (*end
== '\0' || *end
== ' ')
230 ns
= os_realloc_array(ssid
, ssid_count
+ 1,
231 sizeof(struct wpa_ssid_value
));
239 if ((end
- pos
) & 0x01 || end
- pos
> 2 * 32 ||
240 hexstr2bin(pos
, ssid
[ssid_count
].ssid
,
241 (end
- pos
) / 2) < 0) {
244 wpa_printf(MSG_DEBUG
, "Invalid disallow_aps "
245 "SSID value '%s'", pos
);
248 ssid
[ssid_count
].ssid_len
= (end
- pos
) / 2;
249 wpa_hexdump_ascii(MSG_DEBUG
, "disallow_aps SSID",
250 ssid
[ssid_count
].ssid
,
251 ssid
[ssid_count
].ssid_len
);
255 wpa_printf(MSG_DEBUG
, "Unexpected disallow_aps value "
262 pos
= os_strchr(pos
, ' ');
267 wpa_hexdump(MSG_DEBUG
, "disallow_aps_bssid", bssid
, count
* ETH_ALEN
);
268 os_free(wpa_s
->disallow_aps_bssid
);
269 wpa_s
->disallow_aps_bssid
= bssid
;
270 wpa_s
->disallow_aps_bssid_count
= count
;
272 wpa_printf(MSG_DEBUG
, "disallow_aps_ssid_count %d", (int) ssid_count
);
273 os_free(wpa_s
->disallow_aps_ssid
);
274 wpa_s
->disallow_aps_ssid
= ssid
;
275 wpa_s
->disallow_aps_ssid_count
= ssid_count
;
277 if (!wpa_s
->current_ssid
|| wpa_s
->wpa_state
< WPA_AUTHENTICATING
)
280 c
= wpa_s
->current_ssid
;
281 if (c
->mode
!= WPAS_MODE_INFRA
&& c
->mode
!= WPAS_MODE_IBSS
)
284 if (!disallowed_bssid(wpa_s
, wpa_s
->bssid
) &&
285 !disallowed_ssid(wpa_s
, c
->ssid
, c
->ssid_len
))
288 wpa_printf(MSG_DEBUG
, "Disconnect and try to find another network "
289 "because current AP was marked disallowed");
292 wpa_s
->sme
.prev_bssid_set
= 0;
293 #endif /* CONFIG_SME */
294 wpa_s
->reassociate
= 1;
295 wpa_supplicant_deauthenticate(wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
296 wpa_supplicant_req_scan(wpa_s
, 0, 0);
302 static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant
*wpa_s
,
308 value
= os_strchr(cmd
, ' ');
313 wpa_printf(MSG_DEBUG
, "CTRL_IFACE SET '%s'='%s'", cmd
, value
);
314 if (os_strcasecmp(cmd
, "EAPOL::heldPeriod") == 0) {
315 eapol_sm_configure(wpa_s
->eapol
,
316 atoi(value
), -1, -1, -1);
317 } else if (os_strcasecmp(cmd
, "EAPOL::authPeriod") == 0) {
318 eapol_sm_configure(wpa_s
->eapol
,
319 -1, atoi(value
), -1, -1);
320 } else if (os_strcasecmp(cmd
, "EAPOL::startPeriod") == 0) {
321 eapol_sm_configure(wpa_s
->eapol
,
322 -1, -1, atoi(value
), -1);
323 } else if (os_strcasecmp(cmd
, "EAPOL::maxStart") == 0) {
324 eapol_sm_configure(wpa_s
->eapol
,
325 -1, -1, -1, atoi(value
));
326 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigPMKLifetime") == 0) {
327 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_LIFETIME
,
330 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigPMKReauthThreshold") ==
332 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_REAUTH_THRESHOLD
,
335 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigSATimeout") == 0) {
336 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_SA_TIMEOUT
, atoi(value
)))
338 } else if (os_strcasecmp(cmd
, "wps_fragment_size") == 0) {
339 wpa_s
->wps_fragment_size
= atoi(value
);
340 #ifdef CONFIG_WPS_TESTING
341 } else if (os_strcasecmp(cmd
, "wps_version_number") == 0) {
343 val
= strtol(value
, NULL
, 0);
344 if (val
< 0 || val
> 0xff) {
346 wpa_printf(MSG_DEBUG
, "WPS: Invalid "
347 "wps_version_number %ld", val
);
349 wps_version_number
= val
;
350 wpa_printf(MSG_DEBUG
, "WPS: Testing - force WPS "
352 (wps_version_number
& 0xf0) >> 4,
353 wps_version_number
& 0x0f);
355 } else if (os_strcasecmp(cmd
, "wps_testing_dummy_cred") == 0) {
356 wps_testing_dummy_cred
= atoi(value
);
357 wpa_printf(MSG_DEBUG
, "WPS: Testing - dummy_cred=%d",
358 wps_testing_dummy_cred
);
359 #endif /* CONFIG_WPS_TESTING */
360 } else if (os_strcasecmp(cmd
, "ampdu") == 0) {
361 if (wpa_drv_ampdu(wpa_s
, atoi(value
)) < 0)
364 #ifdef CONFIG_TDLS_TESTING
365 } else if (os_strcasecmp(cmd
, "tdls_testing") == 0) {
366 extern unsigned int tdls_testing
;
367 tdls_testing
= strtol(value
, NULL
, 0);
368 wpa_printf(MSG_DEBUG
, "TDLS: tdls_testing=0x%x", tdls_testing
);
369 #endif /* CONFIG_TDLS_TESTING */
370 } else if (os_strcasecmp(cmd
, "tdls_disabled") == 0) {
371 int disabled
= atoi(value
);
372 wpa_printf(MSG_DEBUG
, "TDLS: tdls_disabled=%d", disabled
);
374 if (wpa_drv_tdls_oper(wpa_s
, TDLS_DISABLE
, NULL
) < 0)
376 } else if (wpa_drv_tdls_oper(wpa_s
, TDLS_ENABLE
, NULL
) < 0)
378 wpa_tdls_enable(wpa_s
->wpa
, !disabled
);
379 #endif /* CONFIG_TDLS */
380 } else if (os_strcasecmp(cmd
, "pno") == 0) {
382 ret
= pno_start(wpa_s
);
384 ret
= pno_stop(wpa_s
);
385 } else if (os_strcasecmp(cmd
, "radio_disabled") == 0) {
386 int disabled
= atoi(value
);
387 if (wpa_drv_radio_disable(wpa_s
, disabled
) < 0)
390 wpa_supplicant_set_state(wpa_s
, WPA_INACTIVE
);
391 } else if (os_strcasecmp(cmd
, "uapsd") == 0) {
392 if (os_strcmp(value
, "disable") == 0)
393 wpa_s
->set_sta_uapsd
= 0;
397 /* format: BE,BK,VI,VO;max SP Length */
399 pos
= os_strchr(value
, ',');
404 pos
= os_strchr(pos
, ',');
409 pos
= os_strchr(pos
, ',');
414 /* ignore max SP Length for now */
416 wpa_s
->set_sta_uapsd
= 1;
417 wpa_s
->sta_uapsd
= 0;
419 wpa_s
->sta_uapsd
|= BIT(0);
421 wpa_s
->sta_uapsd
|= BIT(1);
423 wpa_s
->sta_uapsd
|= BIT(2);
425 wpa_s
->sta_uapsd
|= BIT(3);
427 } else if (os_strcasecmp(cmd
, "ps") == 0) {
428 ret
= wpa_drv_set_p2p_powersave(wpa_s
, atoi(value
), -1, -1);
429 #ifdef CONFIG_WIFI_DISPLAY
430 } else if (os_strcasecmp(cmd
, "wifi_display") == 0) {
431 wifi_display_enable(wpa_s
->global
, !!atoi(value
));
432 #endif /* CONFIG_WIFI_DISPLAY */
433 } else if (os_strcasecmp(cmd
, "bssid_filter") == 0) {
434 ret
= set_bssid_filter(wpa_s
, value
);
435 } else if (os_strcasecmp(cmd
, "disallow_aps") == 0) {
436 ret
= set_disallow_aps(wpa_s
, value
);
437 } else if (os_strcasecmp(cmd
, "no_keep_alive") == 0) {
438 wpa_s
->no_keep_alive
= !!atoi(value
);
441 ret
= wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
443 wpa_supplicant_update_config(wpa_s
);
450 static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant
*wpa_s
,
451 char *cmd
, char *buf
, size_t buflen
)
455 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GET '%s'", cmd
);
457 if (os_strcmp(cmd
, "version") == 0) {
458 res
= os_snprintf(buf
, buflen
, "%s", VERSION_STR
);
459 } else if (os_strcasecmp(cmd
, "country") == 0) {
460 if (wpa_s
->conf
->country
[0] && wpa_s
->conf
->country
[1])
461 res
= os_snprintf(buf
, buflen
, "%c%c",
462 wpa_s
->conf
->country
[0],
463 wpa_s
->conf
->country
[1]);
464 #ifdef CONFIG_WIFI_DISPLAY
465 } else if (os_strcasecmp(cmd
, "wifi_display") == 0) {
466 res
= os_snprintf(buf
, buflen
, "%d",
467 wpa_s
->global
->wifi_display
);
468 if (res
< 0 || (unsigned int) res
>= buflen
)
471 #endif /* CONFIG_WIFI_DISPLAY */
472 #ifdef CONFIG_TESTING_GET_GTK
473 } else if (os_strcmp(cmd
, "gtk") == 0) {
474 if (wpa_s
->last_gtk_len
== 0)
476 res
= wpa_snprintf_hex(buf
, buflen
, wpa_s
->last_gtk
,
477 wpa_s
->last_gtk_len
);
479 #endif /* CONFIG_TESTING_GET_GTK */
482 if (res
< 0 || (unsigned int) res
>= buflen
)
488 #ifdef IEEE8021X_EAPOL
489 static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant
*wpa_s
,
493 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
495 if (hwaddr_aton(addr
, bssid
)) {
496 wpa_printf(MSG_DEBUG
, "CTRL_IFACE PREAUTH: invalid address "
501 wpa_printf(MSG_DEBUG
, "CTRL_IFACE PREAUTH " MACSTR
, MAC2STR(bssid
));
502 rsn_preauth_deinit(wpa_s
->wpa
);
503 if (rsn_preauth_init(wpa_s
->wpa
, bssid
, ssid
? &ssid
->eap
: NULL
))
508 #endif /* IEEE8021X_EAPOL */
511 #ifdef CONFIG_PEERKEY
512 /* MLME-STKSTART.request(peer) */
513 static int wpa_supplicant_ctrl_iface_stkstart(
514 struct wpa_supplicant
*wpa_s
, char *addr
)
518 if (hwaddr_aton(addr
, peer
)) {
519 wpa_printf(MSG_DEBUG
, "CTRL_IFACE STKSTART: invalid "
520 "address '%s'", addr
);
524 wpa_printf(MSG_DEBUG
, "CTRL_IFACE STKSTART " MACSTR
,
527 return wpa_sm_stkstart(wpa_s
->wpa
, peer
);
529 #endif /* CONFIG_PEERKEY */
534 static int wpa_supplicant_ctrl_iface_tdls_discover(
535 struct wpa_supplicant
*wpa_s
, char *addr
)
540 if (hwaddr_aton(addr
, peer
)) {
541 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_DISCOVER: invalid "
542 "address '%s'", addr
);
546 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_DISCOVER " MACSTR
,
549 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
550 ret
= wpa_tdls_send_discovery_request(wpa_s
->wpa
, peer
);
552 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_DISCOVERY_REQ
, peer
);
558 static int wpa_supplicant_ctrl_iface_tdls_setup(
559 struct wpa_supplicant
*wpa_s
, char *addr
)
564 if (hwaddr_aton(addr
, peer
)) {
565 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_SETUP: invalid "
566 "address '%s'", addr
);
570 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_SETUP " MACSTR
,
573 if ((wpa_s
->conf
->tdls_external_control
) &&
574 wpa_tdls_is_external_setup(wpa_s
->wpa
))
575 return wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, peer
);
577 wpa_tdls_remove(wpa_s
->wpa
, peer
);
579 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
580 ret
= wpa_tdls_start(wpa_s
->wpa
, peer
);
582 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, peer
);
588 static int wpa_supplicant_ctrl_iface_tdls_teardown(
589 struct wpa_supplicant
*wpa_s
, char *addr
)
594 if (hwaddr_aton(addr
, peer
)) {
595 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN: invalid "
596 "address '%s'", addr
);
600 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN " MACSTR
,
603 if ((wpa_s
->conf
->tdls_external_control
) &&
604 wpa_tdls_is_external_setup(wpa_s
->wpa
))
605 return wpa_drv_tdls_oper(wpa_s
, TDLS_TEARDOWN
, peer
);
607 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
608 ret
= wpa_tdls_teardown_link(
610 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED
);
612 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_TEARDOWN
, peer
);
617 #endif /* CONFIG_TDLS */
620 #ifdef CONFIG_IEEE80211R
621 static int wpa_supplicant_ctrl_iface_ft_ds(
622 struct wpa_supplicant
*wpa_s
, char *addr
)
624 u8 target_ap
[ETH_ALEN
];
628 if (hwaddr_aton(addr
, target_ap
)) {
629 wpa_printf(MSG_DEBUG
, "CTRL_IFACE FT_DS: invalid "
630 "address '%s'", addr
);
634 wpa_printf(MSG_DEBUG
, "CTRL_IFACE FT_DS " MACSTR
, MAC2STR(target_ap
));
636 bss
= wpa_bss_get_bssid(wpa_s
, target_ap
);
638 mdie
= wpa_bss_get_ie(bss
, WLAN_EID_MOBILITY_DOMAIN
);
642 return wpa_ft_start_over_ds(wpa_s
->wpa
, target_ap
, mdie
);
644 #endif /* CONFIG_IEEE80211R */
648 static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant
*wpa_s
,
651 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
653 u8 p2p_dev_addr
[ETH_ALEN
];
654 #endif /* CONFIG_P2P */
656 u8
*_p2p_dev_addr
= NULL
;
657 #endif /* CONFIG_AP */
659 if (cmd
== NULL
|| os_strcmp(cmd
, "any") == 0) {
662 } else if (os_strncmp(cmd
, "p2p_dev_addr=", 13) == 0) {
663 if (hwaddr_aton(cmd
+ 13, p2p_dev_addr
)) {
664 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PBC: invalid "
665 "P2P Device Address '%s'",
669 _p2p_dev_addr
= p2p_dev_addr
;
670 #endif /* CONFIG_P2P */
671 } else if (hwaddr_aton(cmd
, bssid
)) {
672 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
679 return wpa_supplicant_ap_wps_pbc(wpa_s
, _bssid
, _p2p_dev_addr
);
680 #endif /* CONFIG_AP */
682 return wpas_wps_start_pbc(wpa_s
, _bssid
, 0);
686 static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant
*wpa_s
,
687 char *cmd
, char *buf
,
690 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
694 pin
= os_strchr(cmd
, ' ');
698 if (os_strcmp(cmd
, "any") == 0)
700 else if (os_strcmp(cmd
, "get") == 0) {
701 ret
= wps_generate_pin();
703 } else if (hwaddr_aton(cmd
, bssid
)) {
704 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
710 if (wpa_s
->ap_iface
) {
715 pos
= os_strchr(pin
, ' ');
722 return wpa_supplicant_ap_wps_pin(wpa_s
, _bssid
, pin
,
723 buf
, buflen
, timeout
);
725 #endif /* CONFIG_AP */
728 ret
= wpas_wps_start_pin(wpa_s
, _bssid
, pin
, 0,
732 ret
= os_snprintf(buf
, buflen
, "%s", pin
);
733 if (ret
< 0 || (size_t) ret
>= buflen
)
738 ret
= wpas_wps_start_pin(wpa_s
, _bssid
, NULL
, 0, DEV_PW_DEFAULT
);
743 /* Return the generated PIN */
744 ret
= os_snprintf(buf
, buflen
, "%08d", ret
);
745 if (ret
< 0 || (size_t) ret
>= buflen
)
751 static int wpa_supplicant_ctrl_iface_wps_check_pin(
752 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
759 wpa_hexdump_ascii_key(MSG_DEBUG
, "WPS_CHECK_PIN",
760 (u8
*) cmd
, os_strlen(cmd
));
761 for (pos
= cmd
, len
= 0; *pos
!= '\0'; pos
++) {
762 if (*pos
< '0' || *pos
> '9')
766 wpa_printf(MSG_DEBUG
, "WPS: Too long PIN");
770 if (len
!= 4 && len
!= 8) {
771 wpa_printf(MSG_DEBUG
, "WPS: Invalid PIN length %d", (int) len
);
777 unsigned int pin_val
;
779 if (!wps_pin_valid(pin_val
)) {
780 wpa_printf(MSG_DEBUG
, "WPS: Invalid checksum digit");
781 ret
= os_snprintf(buf
, buflen
, "FAIL-CHECKSUM\n");
782 if (ret
< 0 || (size_t) ret
>= buflen
)
788 ret
= os_snprintf(buf
, buflen
, "%s", pin
);
789 if (ret
< 0 || (size_t) ret
>= buflen
)
796 #ifdef CONFIG_WPS_NFC
798 static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant
*wpa_s
,
801 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
803 if (cmd
== NULL
|| cmd
[0] == '\0')
805 else if (hwaddr_aton(cmd
, bssid
))
808 return wpas_wps_start_nfc(wpa_s
, _bssid
);
812 static int wpa_supplicant_ctrl_iface_wps_nfc_config_token(
813 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
820 pos
= os_strchr(cmd
, ' ');
823 if (os_strcmp(cmd
, "WPS") == 0)
825 else if (os_strcmp(cmd
, "NDEF") == 0)
830 buf
= wpas_wps_nfc_config_token(wpa_s
, ndef
, pos
);
834 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
845 static int wpa_supplicant_ctrl_iface_wps_nfc_token(
846 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
852 if (os_strcmp(cmd
, "WPS") == 0)
854 else if (os_strcmp(cmd
, "NDEF") == 0)
859 buf
= wpas_wps_nfc_token(wpa_s
, ndef
);
863 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
874 static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
875 struct wpa_supplicant
*wpa_s
, char *pos
)
881 len
= os_strlen(pos
);
886 buf
= wpabuf_alloc(len
);
889 if (hexstr2bin(pos
, wpabuf_put(buf
, len
), len
) < 0) {
894 ret
= wpas_wps_nfc_tag_read(wpa_s
, buf
);
901 static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant
*wpa_s
,
902 char *reply
, size_t max_len
,
908 buf
= wpas_wps_nfc_handover_req(wpa_s
, cr
);
912 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
923 static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant
*wpa_s
,
924 char *cmd
, char *reply
,
929 pos
= os_strchr(cmd
, ' ');
934 if (os_strcmp(cmd
, "NDEF") != 0)
937 if (os_strcmp(pos
, "WPS") == 0 || os_strcmp(pos
, "WPS-CR") == 0) {
938 return wpas_ctrl_nfc_get_handover_req_wps(
939 wpa_s
, reply
, max_len
, os_strcmp(pos
, "WPS-CR") == 0);
946 static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant
*wpa_s
,
947 char *reply
, size_t max_len
,
948 int ndef
, int cr
, char *uuid
)
953 buf
= wpas_wps_nfc_handover_sel(wpa_s
, ndef
, cr
, uuid
);
957 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
968 static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant
*wpa_s
,
969 char *cmd
, char *reply
,
975 pos
= os_strchr(cmd
, ' ');
980 if (os_strcmp(cmd
, "WPS") == 0)
982 else if (os_strcmp(cmd
, "NDEF") == 0)
987 pos2
= os_strchr(pos
, ' ');
990 if (os_strcmp(pos
, "WPS") == 0 || os_strcmp(pos
, "WPS-CR") == 0) {
991 return wpas_ctrl_nfc_get_handover_sel_wps(
992 wpa_s
, reply
, max_len
, ndef
,
993 os_strcmp(pos
, "WPS-CR") == 0, pos2
);
1000 static int wpas_ctrl_nfc_rx_handover_req(struct wpa_supplicant
*wpa_s
,
1001 char *cmd
, char *reply
,
1008 len
= os_strlen(cmd
);
1013 buf
= wpabuf_alloc(len
);
1016 if (hexstr2bin(cmd
, wpabuf_put(buf
, len
), len
) < 0) {
1021 ret
= wpas_wps_nfc_rx_handover_req(wpa_s
, buf
);
1028 static int wpas_ctrl_nfc_rx_handover_sel(struct wpa_supplicant
*wpa_s
,
1035 len
= os_strlen(cmd
);
1040 buf
= wpabuf_alloc(len
);
1043 if (hexstr2bin(cmd
, wpabuf_put(buf
, len
), len
) < 0) {
1048 ret
= wpas_wps_nfc_rx_handover_sel(wpa_s
, buf
);
1055 static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant
*wpa_s
,
1059 struct wpabuf
*req
, *sel
;
1061 char *pos
, *role
, *type
, *pos2
;
1064 pos
= os_strchr(role
, ' ');
1070 pos
= os_strchr(type
, ' ');
1075 pos2
= os_strchr(pos
, ' ');
1080 len
= os_strlen(pos
);
1085 req
= wpabuf_alloc(len
);
1088 if (hexstr2bin(pos
, wpabuf_put(req
, len
), len
) < 0) {
1093 len
= os_strlen(pos2
);
1100 sel
= wpabuf_alloc(len
);
1105 if (hexstr2bin(pos2
, wpabuf_put(sel
, len
), len
) < 0) {
1111 if (os_strcmp(role
, "INIT") == 0 && os_strcmp(type
, "WPS") == 0) {
1112 ret
= wpas_wps_nfc_report_handover(wpa_s
, req
, sel
);
1114 wpa_printf(MSG_DEBUG
, "NFC: Unsupported connection handover "
1115 "reported: role=%s type=%s", role
, type
);
1124 #endif /* CONFIG_WPS_NFC */
1127 static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant
*wpa_s
,
1136 struct wps_new_ap_settings ap
;
1138 pin
= os_strchr(cmd
, ' ');
1143 if (hwaddr_aton(cmd
, bssid
)) {
1144 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
1149 new_ssid
= os_strchr(pin
, ' ');
1150 if (new_ssid
== NULL
)
1151 return wpas_wps_start_reg(wpa_s
, bssid
, pin
, NULL
);
1154 new_auth
= os_strchr(new_ssid
, ' ');
1155 if (new_auth
== NULL
)
1159 new_encr
= os_strchr(new_auth
, ' ');
1160 if (new_encr
== NULL
)
1164 new_key
= os_strchr(new_encr
, ' ');
1165 if (new_key
== NULL
)
1169 os_memset(&ap
, 0, sizeof(ap
));
1170 ap
.ssid_hex
= new_ssid
;
1173 ap
.key_hex
= new_key
;
1174 return wpas_wps_start_reg(wpa_s
, bssid
, pin
, &ap
);
1179 static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant
*wpa_s
,
1180 char *cmd
, char *buf
,
1185 const char *pin_txt
;
1187 if (!wpa_s
->ap_iface
)
1190 pos
= os_strchr(cmd
, ' ');
1194 if (os_strcmp(cmd
, "disable") == 0) {
1195 wpas_wps_ap_pin_disable(wpa_s
);
1196 return os_snprintf(buf
, buflen
, "OK\n");
1199 if (os_strcmp(cmd
, "random") == 0) {
1201 timeout
= atoi(pos
);
1202 pin_txt
= wpas_wps_ap_pin_random(wpa_s
, timeout
);
1203 if (pin_txt
== NULL
)
1205 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
1208 if (os_strcmp(cmd
, "get") == 0) {
1209 pin_txt
= wpas_wps_ap_pin_get(wpa_s
);
1210 if (pin_txt
== NULL
)
1212 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
1215 if (os_strcmp(cmd
, "set") == 0) {
1220 pos
= os_strchr(pos
, ' ');
1223 timeout
= atoi(pos
);
1225 if (os_strlen(pin
) > buflen
)
1227 if (wpas_wps_ap_pin_set(wpa_s
, pin
, timeout
) < 0)
1229 return os_snprintf(buf
, buflen
, "%s", pin
);
1234 #endif /* CONFIG_AP */
1237 #ifdef CONFIG_WPS_ER
1238 static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant
*wpa_s
,
1241 char *uuid
= cmd
, *pin
, *pos
;
1242 u8 addr_buf
[ETH_ALEN
], *addr
= NULL
;
1243 pin
= os_strchr(uuid
, ' ');
1247 pos
= os_strchr(pin
, ' ');
1250 if (hwaddr_aton(pos
, addr_buf
) == 0)
1253 return wpas_wps_er_add_pin(wpa_s
, addr
, uuid
, pin
);
1257 static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant
*wpa_s
,
1260 char *uuid
= cmd
, *pin
;
1261 pin
= os_strchr(uuid
, ' ');
1265 return wpas_wps_er_learn(wpa_s
, uuid
, pin
);
1269 static int wpa_supplicant_ctrl_iface_wps_er_set_config(
1270 struct wpa_supplicant
*wpa_s
, char *cmd
)
1272 char *uuid
= cmd
, *id
;
1273 id
= os_strchr(uuid
, ' ');
1277 return wpas_wps_er_set_config(wpa_s
, uuid
, atoi(id
));
1281 static int wpa_supplicant_ctrl_iface_wps_er_config(
1282 struct wpa_supplicant
*wpa_s
, char *cmd
)
1289 struct wps_new_ap_settings ap
;
1291 pin
= os_strchr(cmd
, ' ');
1296 new_ssid
= os_strchr(pin
, ' ');
1297 if (new_ssid
== NULL
)
1301 new_auth
= os_strchr(new_ssid
, ' ');
1302 if (new_auth
== NULL
)
1306 new_encr
= os_strchr(new_auth
, ' ');
1307 if (new_encr
== NULL
)
1311 new_key
= os_strchr(new_encr
, ' ');
1312 if (new_key
== NULL
)
1316 os_memset(&ap
, 0, sizeof(ap
));
1317 ap
.ssid_hex
= new_ssid
;
1320 ap
.key_hex
= new_key
;
1321 return wpas_wps_er_config(wpa_s
, cmd
, pin
, &ap
);
1325 #ifdef CONFIG_WPS_NFC
1326 static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
1327 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
1334 uuid
= os_strchr(cmd
, ' ');
1339 if (os_strcmp(cmd
, "WPS") == 0)
1341 else if (os_strcmp(cmd
, "NDEF") == 0)
1346 buf
= wpas_wps_er_nfc_config_token(wpa_s
, ndef
, uuid
);
1350 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1352 reply
[res
++] = '\n';
1359 #endif /* CONFIG_WPS_NFC */
1360 #endif /* CONFIG_WPS_ER */
1362 #endif /* CONFIG_WPS */
1365 #ifdef CONFIG_IBSS_RSN
1366 static int wpa_supplicant_ctrl_iface_ibss_rsn(
1367 struct wpa_supplicant
*wpa_s
, char *addr
)
1371 if (hwaddr_aton(addr
, peer
)) {
1372 wpa_printf(MSG_DEBUG
, "CTRL_IFACE IBSS_RSN: invalid "
1373 "address '%s'", addr
);
1377 wpa_printf(MSG_DEBUG
, "CTRL_IFACE IBSS_RSN " MACSTR
,
1380 return ibss_rsn_start(wpa_s
->ibss_rsn
, peer
);
1382 #endif /* CONFIG_IBSS_RSN */
1385 static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant
*wpa_s
,
1388 #ifdef IEEE8021X_EAPOL
1391 struct wpa_ssid
*ssid
;
1393 pos
= os_strchr(rsp
, '-');
1398 pos
= os_strchr(pos
, ':');
1403 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: field=%s id=%d", rsp
, id
);
1404 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
1405 (u8
*) pos
, os_strlen(pos
));
1407 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1409 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
1414 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s
, ssid
, rsp
,
1416 #else /* IEEE8021X_EAPOL */
1417 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: 802.1X not included");
1419 #endif /* IEEE8021X_EAPOL */
1423 static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant
*wpa_s
,
1425 char *buf
, size_t buflen
)
1427 char *pos
, *end
, tmp
[30];
1428 int res
, verbose
, wps
, ret
;
1430 if (os_strcmp(params
, "-DRIVER") == 0)
1431 return wpa_drv_status(wpa_s
, buf
, buflen
);
1432 verbose
= os_strcmp(params
, "-VERBOSE") == 0;
1433 wps
= os_strcmp(params
, "-WPS") == 0;
1436 if (wpa_s
->wpa_state
>= WPA_ASSOCIATED
) {
1437 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
1438 ret
= os_snprintf(pos
, end
- pos
, "bssid=" MACSTR
"\n",
1439 MAC2STR(wpa_s
->bssid
));
1440 if (ret
< 0 || ret
>= end
- pos
)
1444 u8
*_ssid
= ssid
->ssid
;
1445 size_t ssid_len
= ssid
->ssid_len
;
1446 u8 ssid_buf
[MAX_SSID_LEN
];
1447 if (ssid_len
== 0) {
1448 int _res
= wpa_drv_get_ssid(wpa_s
, ssid_buf
);
1455 ret
= os_snprintf(pos
, end
- pos
, "ssid=%s\nid=%d\n",
1456 wpa_ssid_txt(_ssid
, ssid_len
),
1458 if (ret
< 0 || ret
>= end
- pos
)
1462 if (wps
&& ssid
->passphrase
&&
1463 wpa_key_mgmt_wpa_psk(ssid
->key_mgmt
) &&
1464 (ssid
->mode
== WPAS_MODE_AP
||
1465 ssid
->mode
== WPAS_MODE_P2P_GO
)) {
1466 ret
= os_snprintf(pos
, end
- pos
,
1469 if (ret
< 0 || ret
>= end
- pos
)
1474 ret
= os_snprintf(pos
, end
- pos
,
1477 if (ret
< 0 || ret
>= end
- pos
)
1482 switch (ssid
->mode
) {
1483 case WPAS_MODE_INFRA
:
1484 ret
= os_snprintf(pos
, end
- pos
,
1487 case WPAS_MODE_IBSS
:
1488 ret
= os_snprintf(pos
, end
- pos
,
1492 ret
= os_snprintf(pos
, end
- pos
,
1495 case WPAS_MODE_P2P_GO
:
1496 ret
= os_snprintf(pos
, end
- pos
,
1499 case WPAS_MODE_P2P_GROUP_FORMATION
:
1500 ret
= os_snprintf(pos
, end
- pos
,
1501 "mode=P2P GO - group "
1508 if (ret
< 0 || ret
>= end
- pos
)
1514 if (wpa_s
->ap_iface
) {
1515 pos
+= ap_ctrl_iface_wpa_get_status(wpa_s
, pos
,
1519 #endif /* CONFIG_AP */
1520 pos
+= wpa_sm_get_status(wpa_s
->wpa
, pos
, end
- pos
, verbose
);
1523 if (wpa_s
->wpa_state
>= WPA_ASSOCIATED
&&
1526 #endif /* CONFIG_AP */
1527 wpa_s
->sme
.sae
.state
== SAE_ACCEPTED
) {
1528 ret
= os_snprintf(pos
, end
- pos
, "sae_group=%d\n",
1529 wpa_s
->sme
.sae
.group
);
1530 if (ret
< 0 || ret
>= end
- pos
)
1534 #endif /* CONFIG_SAE */
1535 ret
= os_snprintf(pos
, end
- pos
, "wpa_state=%s\n",
1536 wpa_supplicant_state_txt(wpa_s
->wpa_state
));
1537 if (ret
< 0 || ret
>= end
- pos
)
1542 l2_packet_get_ip_addr(wpa_s
->l2
, tmp
, sizeof(tmp
)) >= 0) {
1543 ret
= os_snprintf(pos
, end
- pos
, "ip_address=%s\n", tmp
);
1544 if (ret
< 0 || ret
>= end
- pos
)
1550 if (wpa_s
->global
->p2p
) {
1551 ret
= os_snprintf(pos
, end
- pos
, "p2p_device_address=" MACSTR
1552 "\n", MAC2STR(wpa_s
->global
->p2p_dev_addr
));
1553 if (ret
< 0 || ret
>= end
- pos
)
1557 #endif /* CONFIG_P2P */
1559 ret
= os_snprintf(pos
, end
- pos
, "address=" MACSTR
"\n",
1560 MAC2STR(wpa_s
->own_addr
));
1561 if (ret
< 0 || ret
>= end
- pos
)
1566 if (wpa_s
->current_bss
&&
1567 wpa_bss_get_vendor_ie(wpa_s
->current_bss
, HS20_IE_VENDOR_TYPE
) &&
1568 wpa_s
->wpa_proto
== WPA_PROTO_RSN
&&
1569 wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
)) {
1570 ret
= os_snprintf(pos
, end
- pos
, "hs20=1\n");
1571 if (ret
< 0 || ret
>= end
- pos
)
1576 if (wpa_s
->current_ssid
) {
1577 struct wpa_cred
*cred
;
1580 for (cred
= wpa_s
->conf
->cred
; cred
; cred
= cred
->next
) {
1583 if (wpa_s
->current_ssid
->parent_cred
!= cred
)
1586 for (i
= 0; cred
->domain
&& i
< cred
->num_domain
; i
++) {
1587 ret
= os_snprintf(pos
, end
- pos
,
1590 if (ret
< 0 || ret
>= end
- pos
)
1595 if (wpa_s
->current_bss
== NULL
||
1596 wpa_s
->current_bss
->anqp
== NULL
)
1599 res
= interworking_home_sp_cred(
1601 wpa_s
->current_bss
->anqp
->domain_name
);
1609 ret
= os_snprintf(pos
, end
- pos
, "sp_type=%s\n", type
);
1610 if (ret
< 0 || ret
>= end
- pos
)
1617 #endif /* CONFIG_HS20 */
1619 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) ||
1620 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
1621 res
= eapol_sm_get_status(wpa_s
->eapol
, pos
, end
- pos
,
1627 res
= rsn_preauth_get_status(wpa_s
->wpa
, pos
, end
- pos
, verbose
);
1634 uuid_bin2str(wpa_s
->wps
->uuid
, uuid_str
, sizeof(uuid_str
));
1635 ret
= os_snprintf(pos
, end
- pos
, "uuid=%s\n", uuid_str
);
1636 if (ret
< 0 || ret
>= end
- pos
)
1640 #endif /* CONFIG_WPS */
1643 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_STATE_CHANGE
1644 "id=%d state=%d BSSID=" MACSTR
" SSID=%s",
1645 wpa_s
->current_ssid
? wpa_s
->current_ssid
->id
: -1,
1647 MAC2STR(wpa_s
->bssid
),
1648 wpa_s
->current_ssid
&& wpa_s
->current_ssid
->ssid
?
1649 wpa_ssid_txt(wpa_s
->current_ssid
->ssid
,
1650 wpa_s
->current_ssid
->ssid_len
) : "");
1651 if (wpa_s
->wpa_state
== WPA_COMPLETED
) {
1652 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
1653 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_CONNECTED
1654 "- connection to " MACSTR
1655 " completed %s [id=%d id_str=%s]",
1656 MAC2STR(wpa_s
->bssid
), "(auth)",
1657 ssid
? ssid
->id
: -1,
1658 ssid
&& ssid
->id_str
? ssid
->id_str
: "");
1660 #endif /* ANDROID */
1666 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant
*wpa_s
,
1671 struct wpa_ssid
*ssid
;
1674 /* cmd: "<network id> <BSSID>" */
1675 pos
= os_strchr(cmd
, ' ');
1680 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: id=%d bssid='%s'", id
, pos
);
1681 if (hwaddr_aton(pos
, bssid
)) {
1682 wpa_printf(MSG_DEBUG
,"CTRL_IFACE: invalid BSSID '%s'", pos
);
1686 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1688 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
1693 os_memcpy(ssid
->bssid
, bssid
, ETH_ALEN
);
1694 ssid
->bssid_set
= !is_zero_ether_addr(bssid
);
1700 static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant
*wpa_s
,
1701 char *cmd
, char *buf
,
1705 struct wpa_blacklist
*e
;
1709 /* cmd: "BLACKLIST [<BSSID>]" */
1713 e
= wpa_s
->blacklist
;
1715 ret
= os_snprintf(pos
, end
- pos
, MACSTR
"\n",
1717 if (ret
< 0 || ret
>= end
- pos
)
1726 if (os_strncmp(cmd
, "clear", 5) == 0) {
1727 wpa_blacklist_clear(wpa_s
);
1728 os_memcpy(buf
, "OK\n", 3);
1732 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd
);
1733 if (hwaddr_aton(cmd
, bssid
)) {
1734 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: invalid BSSID '%s'", cmd
);
1739 * Add the BSSID twice, so its count will be 2, causing it to be
1740 * skipped when processing scan results.
1742 ret
= wpa_blacklist_add(wpa_s
, bssid
);
1745 ret
= wpa_blacklist_add(wpa_s
, bssid
);
1748 os_memcpy(buf
, "OK\n", 3);
1753 static const char * debug_level_str(int level
)
1774 static int str_to_debug_level(const char *s
)
1776 if (os_strcasecmp(s
, "EXCESSIVE") == 0)
1777 return MSG_EXCESSIVE
;
1778 if (os_strcasecmp(s
, "MSGDUMP") == 0)
1780 if (os_strcasecmp(s
, "DEBUG") == 0)
1782 if (os_strcasecmp(s
, "INFO") == 0)
1784 if (os_strcasecmp(s
, "WARNING") == 0)
1786 if (os_strcasecmp(s
, "ERROR") == 0)
1792 static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant
*wpa_s
,
1793 char *cmd
, char *buf
,
1796 char *pos
, *end
, *stamp
;
1803 /* cmd: "LOG_LEVEL [<level>]" */
1807 ret
= os_snprintf(pos
, end
- pos
, "Current level: %s\n"
1809 debug_level_str(wpa_debug_level
),
1810 wpa_debug_timestamp
);
1811 if (ret
< 0 || ret
>= end
- pos
)
1820 stamp
= os_strchr(cmd
, ' ');
1823 while (*stamp
== ' ') {
1828 if (cmd
&& os_strlen(cmd
)) {
1829 int level
= str_to_debug_level(cmd
);
1832 wpa_debug_level
= level
;
1835 if (stamp
&& os_strlen(stamp
))
1836 wpa_debug_timestamp
= atoi(stamp
);
1838 os_memcpy(buf
, "OK\n", 3);
1843 static int wpa_supplicant_ctrl_iface_list_networks(
1844 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
1847 struct wpa_ssid
*ssid
;
1852 ret
= os_snprintf(pos
, end
- pos
,
1853 "network id / ssid / bssid / flags\n");
1854 if (ret
< 0 || ret
>= end
- pos
)
1858 ssid
= wpa_s
->conf
->ssid
;
1860 ret
= os_snprintf(pos
, end
- pos
, "%d\t%s",
1862 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
));
1863 if (ret
< 0 || ret
>= end
- pos
)
1866 if (ssid
->bssid_set
) {
1867 ret
= os_snprintf(pos
, end
- pos
, "\t" MACSTR
,
1868 MAC2STR(ssid
->bssid
));
1870 ret
= os_snprintf(pos
, end
- pos
, "\tany");
1872 if (ret
< 0 || ret
>= end
- pos
)
1875 ret
= os_snprintf(pos
, end
- pos
, "\t%s%s%s%s",
1876 ssid
== wpa_s
->current_ssid
?
1878 ssid
->disabled
? "[DISABLED]" : "",
1879 ssid
->disabled_until
.sec
?
1880 "[TEMP-DISABLED]" : "",
1881 ssid
->disabled
== 2 ? "[P2P-PERSISTENT]" :
1883 if (ret
< 0 || ret
>= end
- pos
)
1886 ret
= os_snprintf(pos
, end
- pos
, "\n");
1887 if (ret
< 0 || ret
>= end
- pos
)
1898 static char * wpa_supplicant_cipher_txt(char *pos
, char *end
, int cipher
)
1901 ret
= os_snprintf(pos
, end
- pos
, "-");
1902 if (ret
< 0 || ret
>= end
- pos
)
1905 ret
= wpa_write_ciphers(pos
, end
, cipher
, "+");
1913 static char * wpa_supplicant_ie_txt(char *pos
, char *end
, const char *proto
,
1914 const u8
*ie
, size_t ie_len
)
1916 struct wpa_ie_data data
;
1919 ret
= os_snprintf(pos
, end
- pos
, "[%s-", proto
);
1920 if (ret
< 0 || ret
>= end
- pos
)
1924 if (wpa_parse_wpa_ie(ie
, ie_len
, &data
) < 0) {
1925 ret
= os_snprintf(pos
, end
- pos
, "?]");
1926 if (ret
< 0 || ret
>= end
- pos
)
1933 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X
) {
1934 ret
= os_snprintf(pos
, end
- pos
, "%sEAP", first
? "" : "+");
1935 if (ret
< 0 || ret
>= end
- pos
)
1940 if (data
.key_mgmt
& WPA_KEY_MGMT_PSK
) {
1941 ret
= os_snprintf(pos
, end
- pos
, "%sPSK", first
? "" : "+");
1942 if (ret
< 0 || ret
>= end
- pos
)
1947 if (data
.key_mgmt
& WPA_KEY_MGMT_WPA_NONE
) {
1948 ret
= os_snprintf(pos
, end
- pos
, "%sNone", first
? "" : "+");
1949 if (ret
< 0 || ret
>= end
- pos
)
1954 #ifdef CONFIG_IEEE80211R
1955 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_IEEE8021X
) {
1956 ret
= os_snprintf(pos
, end
- pos
, "%sFT/EAP",
1958 if (ret
< 0 || ret
>= end
- pos
)
1963 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_PSK
) {
1964 ret
= os_snprintf(pos
, end
- pos
, "%sFT/PSK",
1966 if (ret
< 0 || ret
>= end
- pos
)
1971 #endif /* CONFIG_IEEE80211R */
1972 #ifdef CONFIG_IEEE80211W
1973 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SHA256
) {
1974 ret
= os_snprintf(pos
, end
- pos
, "%sEAP-SHA256",
1976 if (ret
< 0 || ret
>= end
- pos
)
1981 if (data
.key_mgmt
& WPA_KEY_MGMT_PSK_SHA256
) {
1982 ret
= os_snprintf(pos
, end
- pos
, "%sPSK-SHA256",
1984 if (ret
< 0 || ret
>= end
- pos
)
1989 #endif /* CONFIG_IEEE80211W */
1991 pos
= wpa_supplicant_cipher_txt(pos
, end
, data
.pairwise_cipher
);
1993 if (data
.capabilities
& WPA_CAPABILITY_PREAUTH
) {
1994 ret
= os_snprintf(pos
, end
- pos
, "-preauth");
1995 if (ret
< 0 || ret
>= end
- pos
)
2000 ret
= os_snprintf(pos
, end
- pos
, "]");
2001 if (ret
< 0 || ret
>= end
- pos
)
2010 static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant
*wpa_s
,
2011 char *pos
, char *end
,
2012 struct wpabuf
*wps_ie
)
2019 if (wps_is_selected_pbc_registrar(wps_ie
))
2022 else if (wps_is_addr_authorized(wps_ie
, wpa_s
->own_addr
, 0))
2024 #endif /* CONFIG_WPS2 */
2025 else if (wps_is_selected_pin_registrar(wps_ie
))
2030 ret
= os_snprintf(pos
, end
- pos
, "%s", txt
);
2031 if (ret
>= 0 && ret
< end
- pos
)
2033 wpabuf_free(wps_ie
);
2036 #endif /* CONFIG_WPS */
2039 static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant
*wpa_s
,
2040 char *pos
, char *end
,
2041 const struct wpa_bss
*bss
)
2044 struct wpabuf
*wps_ie
;
2045 wps_ie
= wpa_bss_get_vendor_ie_multi(bss
, WPS_IE_VENDOR_TYPE
);
2046 return wpa_supplicant_wps_ie_txt_buf(wpa_s
, pos
, end
, wps_ie
);
2047 #else /* CONFIG_WPS */
2049 #endif /* CONFIG_WPS */
2053 /* Format one result on one text line into a buffer. */
2054 static int wpa_supplicant_ctrl_iface_scan_result(
2055 struct wpa_supplicant
*wpa_s
,
2056 const struct wpa_bss
*bss
, char *buf
, size_t buflen
)
2060 const u8
*ie
, *ie2
, *p2p
;
2062 p2p
= wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
);
2064 p2p
= wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
);
2065 if (p2p
&& bss
->ssid_len
== P2P_WILDCARD_SSID_LEN
&&
2066 os_memcmp(bss
->ssid
, P2P_WILDCARD_SSID
, P2P_WILDCARD_SSID_LEN
) ==
2068 return 0; /* Do not show P2P listen discovery results here */
2073 ret
= os_snprintf(pos
, end
- pos
, MACSTR
"\t%d\t%d\t",
2074 MAC2STR(bss
->bssid
), bss
->freq
, bss
->level
);
2075 if (ret
< 0 || ret
>= end
- pos
)
2078 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
2080 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA", ie
, 2 + ie
[1]);
2081 ie2
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
2083 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA2", ie2
, 2 + ie2
[1]);
2084 pos
= wpa_supplicant_wps_ie_txt(wpa_s
, pos
, end
, bss
);
2085 if (!ie
&& !ie2
&& bss
->caps
& IEEE80211_CAP_PRIVACY
) {
2086 ret
= os_snprintf(pos
, end
- pos
, "[WEP]");
2087 if (ret
< 0 || ret
>= end
- pos
)
2091 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
2092 ret
= os_snprintf(pos
, end
- pos
, "[IBSS]");
2093 if (ret
< 0 || ret
>= end
- pos
)
2097 if (bss
->caps
& IEEE80211_CAP_ESS
) {
2098 ret
= os_snprintf(pos
, end
- pos
, "[ESS]");
2099 if (ret
< 0 || ret
>= end
- pos
)
2104 ret
= os_snprintf(pos
, end
- pos
, "[P2P]");
2105 if (ret
< 0 || ret
>= end
- pos
)
2110 if (wpa_bss_get_vendor_ie(bss
, HS20_IE_VENDOR_TYPE
) && ie2
) {
2111 ret
= os_snprintf(pos
, end
- pos
, "[HS20]");
2112 if (ret
< 0 || ret
>= end
- pos
)
2116 #endif /* CONFIG_HS20 */
2118 ret
= os_snprintf(pos
, end
- pos
, "\t%s",
2119 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
2120 if (ret
< 0 || ret
>= end
- pos
)
2124 ret
= os_snprintf(pos
, end
- pos
, "\n");
2125 if (ret
< 0 || ret
>= end
- pos
)
2133 static int wpa_supplicant_ctrl_iface_scan_results(
2134 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
2137 struct wpa_bss
*bss
;
2142 ret
= os_snprintf(pos
, end
- pos
, "bssid / frequency / signal level / "
2144 if (ret
< 0 || ret
>= end
- pos
)
2148 dl_list_for_each(bss
, &wpa_s
->bss_id
, struct wpa_bss
, list_id
) {
2149 ret
= wpa_supplicant_ctrl_iface_scan_result(wpa_s
, bss
, pos
,
2151 if (ret
< 0 || ret
>= end
- pos
)
2160 static int wpa_supplicant_ctrl_iface_select_network(
2161 struct wpa_supplicant
*wpa_s
, char *cmd
)
2164 struct wpa_ssid
*ssid
;
2166 /* cmd: "<network id>" or "any" */
2167 if (os_strcmp(cmd
, "any") == 0) {
2168 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SELECT_NETWORK any");
2172 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SELECT_NETWORK id=%d", id
);
2174 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2176 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
2177 "network id=%d", id
);
2180 if (ssid
->disabled
== 2) {
2181 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
2182 "SELECT_NETWORK with persistent P2P group");
2187 wpa_supplicant_select_network(wpa_s
, ssid
);
2193 static int wpa_supplicant_ctrl_iface_enable_network(
2194 struct wpa_supplicant
*wpa_s
, char *cmd
)
2197 struct wpa_ssid
*ssid
;
2199 /* cmd: "<network id>" or "all" */
2200 if (os_strcmp(cmd
, "all") == 0) {
2201 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ENABLE_NETWORK all");
2205 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ENABLE_NETWORK id=%d", id
);
2207 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2209 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
2210 "network id=%d", id
);
2213 if (ssid
->disabled
== 2) {
2214 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
2215 "ENABLE_NETWORK with persistent P2P group");
2219 if (os_strstr(cmd
, " no-connect")) {
2224 wpa_supplicant_enable_network(wpa_s
, ssid
);
2230 static int wpa_supplicant_ctrl_iface_disable_network(
2231 struct wpa_supplicant
*wpa_s
, char *cmd
)
2234 struct wpa_ssid
*ssid
;
2236 /* cmd: "<network id>" or "all" */
2237 if (os_strcmp(cmd
, "all") == 0) {
2238 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DISABLE_NETWORK all");
2242 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DISABLE_NETWORK id=%d", id
);
2244 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2246 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
2247 "network id=%d", id
);
2250 if (ssid
->disabled
== 2) {
2251 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
2252 "DISABLE_NETWORK with persistent P2P "
2257 wpa_supplicant_disable_network(wpa_s
, ssid
);
2263 static int wpa_supplicant_ctrl_iface_add_network(
2264 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
2266 struct wpa_ssid
*ssid
;
2269 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ADD_NETWORK");
2271 ssid
= wpa_config_add_network(wpa_s
->conf
);
2275 wpas_notify_network_added(wpa_s
, ssid
);
2278 wpa_config_set_network_defaults(ssid
);
2280 ret
= os_snprintf(buf
, buflen
, "%d\n", ssid
->id
);
2281 if (ret
< 0 || (size_t) ret
>= buflen
)
2287 static int wpa_supplicant_ctrl_iface_remove_network(
2288 struct wpa_supplicant
*wpa_s
, char *cmd
)
2291 struct wpa_ssid
*ssid
;
2294 /* cmd: "<network id>" or "all" */
2295 if (os_strcmp(cmd
, "all") == 0) {
2296 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_NETWORK all");
2297 if (wpa_s
->sched_scanning
)
2298 wpa_supplicant_cancel_sched_scan(wpa_s
);
2300 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
2301 if (wpa_s
->current_ssid
) {
2303 wpa_s
->sme
.prev_bssid_set
= 0;
2304 #endif /* CONFIG_SME */
2305 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
2306 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
2307 wpa_supplicant_deauthenticate(
2308 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2310 ssid
= wpa_s
->conf
->ssid
;
2312 struct wpa_ssid
*remove_ssid
= ssid
;
2315 wpas_notify_network_removed(wpa_s
, remove_ssid
);
2316 wpa_config_remove_network(wpa_s
->conf
, id
);
2322 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_NETWORK id=%d", id
);
2324 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2326 wpas_notify_network_removed(wpa_s
, ssid
);
2328 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
2333 if (ssid
== wpa_s
->current_ssid
|| wpa_s
->current_ssid
== NULL
) {
2335 wpa_s
->sme
.prev_bssid_set
= 0;
2336 #endif /* CONFIG_SME */
2338 * Invalidate the EAP session cache if the current or
2339 * previously used network is removed.
2341 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
2344 if (ssid
== wpa_s
->current_ssid
) {
2345 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
2346 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
2348 wpa_supplicant_deauthenticate(wpa_s
,
2349 WLAN_REASON_DEAUTH_LEAVING
);
2352 was_disabled
= ssid
->disabled
;
2354 if (wpa_config_remove_network(wpa_s
->conf
, id
) < 0) {
2355 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Not able to remove the "
2356 "network id=%d", id
);
2360 if (!was_disabled
&& wpa_s
->sched_scanning
) {
2361 wpa_printf(MSG_DEBUG
, "Stop ongoing sched_scan to remove "
2362 "network from filters");
2363 wpa_supplicant_cancel_sched_scan(wpa_s
);
2364 wpa_supplicant_req_scan(wpa_s
, 0, 0);
2371 static int wpa_supplicant_ctrl_iface_set_network(
2372 struct wpa_supplicant
*wpa_s
, char *cmd
)
2375 struct wpa_ssid
*ssid
;
2378 /* cmd: "<network id> <variable name> <value>" */
2379 name
= os_strchr(cmd
, ' ');
2384 value
= os_strchr(name
, ' ');
2390 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
2392 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
2393 (u8
*) value
, os_strlen(value
));
2395 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2397 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
2402 if (wpa_config_set(ssid
, name
, value
, 0) < 0) {
2403 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to set network "
2404 "variable '%s'", name
);
2408 if (os_strcmp(name
, "bssid") != 0 &&
2409 os_strcmp(name
, "priority") != 0)
2410 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, ssid
);
2412 if (wpa_s
->current_ssid
== ssid
|| wpa_s
->current_ssid
== NULL
) {
2414 * Invalidate the EAP session cache if anything in the current
2415 * or previously used configuration changes.
2417 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
2420 if ((os_strcmp(name
, "psk") == 0 &&
2421 value
[0] == '"' && ssid
->ssid_len
) ||
2422 (os_strcmp(name
, "ssid") == 0 && ssid
->passphrase
))
2423 wpa_config_update_psk(ssid
);
2424 else if (os_strcmp(name
, "priority") == 0)
2425 wpa_config_update_prio_list(wpa_s
->conf
);
2431 static int wpa_supplicant_ctrl_iface_get_network(
2432 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
2436 struct wpa_ssid
*ssid
;
2439 /* cmd: "<network id> <variable name>" */
2440 name
= os_strchr(cmd
, ' ');
2441 if (name
== NULL
|| buflen
== 0)
2446 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
2449 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2451 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
2456 value
= wpa_config_get_no_key(ssid
, name
);
2457 if (value
== NULL
) {
2458 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to get network "
2459 "variable '%s'", name
);
2463 res
= os_strlcpy(buf
, value
, buflen
);
2464 if (res
>= buflen
) {
2475 static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant
*wpa_s
,
2476 char *buf
, size_t buflen
)
2479 struct wpa_cred
*cred
;
2484 ret
= os_snprintf(pos
, end
- pos
,
2485 "cred id / realm / username / domain / imsi\n");
2486 if (ret
< 0 || ret
>= end
- pos
)
2490 cred
= wpa_s
->conf
->cred
;
2492 ret
= os_snprintf(pos
, end
- pos
, "%d\t%s\t%s\t%s\t%s\n",
2493 cred
->id
, cred
->realm
? cred
->realm
: "",
2494 cred
->username
? cred
->username
: "",
2495 cred
->domain
? cred
->domain
[0] : "",
2496 cred
->imsi
? cred
->imsi
: "");
2497 if (ret
< 0 || ret
>= end
- pos
)
2508 static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant
*wpa_s
,
2509 char *buf
, size_t buflen
)
2511 struct wpa_cred
*cred
;
2514 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ADD_CRED");
2516 cred
= wpa_config_add_cred(wpa_s
->conf
);
2520 ret
= os_snprintf(buf
, buflen
, "%d\n", cred
->id
);
2521 if (ret
< 0 || (size_t) ret
>= buflen
)
2527 static int wpas_ctrl_remove_cred(struct wpa_supplicant
*wpa_s
,
2528 struct wpa_cred
*cred
)
2530 struct wpa_ssid
*ssid
;
2533 if (cred
== NULL
|| wpa_config_remove_cred(wpa_s
->conf
, cred
->id
) < 0) {
2534 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred");
2538 /* Remove any network entry created based on the removed credential */
2539 ssid
= wpa_s
->conf
->ssid
;
2541 if (ssid
->parent_cred
== cred
) {
2542 wpa_printf(MSG_DEBUG
, "Remove network id %d since it "
2543 "used the removed credential", ssid
->id
);
2544 os_snprintf(str
, sizeof(str
), "%d", ssid
->id
);
2546 wpa_supplicant_ctrl_iface_remove_network(wpa_s
, str
);
2555 static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant
*wpa_s
,
2559 struct wpa_cred
*cred
, *prev
;
2561 /* cmd: "<cred id>", "all", or "sp_fqdn=<FQDN>" */
2562 if (os_strcmp(cmd
, "all") == 0) {
2563 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED all");
2564 cred
= wpa_s
->conf
->cred
;
2568 wpas_ctrl_remove_cred(wpa_s
, prev
);
2573 if (os_strncmp(cmd
, "sp_fqdn=", 8) == 0) {
2574 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
2576 cred
= wpa_s
->conf
->cred
;
2582 for (i
= 0; i
< prev
->num_domain
; i
++) {
2583 if (os_strcmp(prev
->domain
[i
], cmd
+ 8)
2586 wpas_ctrl_remove_cred(wpa_s
, prev
);
2595 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED id=%d", id
);
2597 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
2598 return wpas_ctrl_remove_cred(wpa_s
, cred
);
2602 static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant
*wpa_s
,
2606 struct wpa_cred
*cred
;
2609 /* cmd: "<cred id> <variable name> <value>" */
2610 name
= os_strchr(cmd
, ' ');
2615 value
= os_strchr(name
, ' ');
2621 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SET_CRED id=%d name='%s'",
2623 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
2624 (u8
*) value
, os_strlen(value
));
2626 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
2628 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred id=%d",
2633 if (wpa_config_set_cred(cred
, name
, value
, 0) < 0) {
2634 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to set cred "
2635 "variable '%s'", name
);
2643 #ifndef CONFIG_NO_CONFIG_WRITE
2644 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant
*wpa_s
)
2648 if (!wpa_s
->conf
->update_config
) {
2649 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
2650 "to update configuration (update_config=0)");
2654 ret
= wpa_config_write(wpa_s
->confname
, wpa_s
->conf
);
2656 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Failed to "
2657 "update configuration");
2659 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Configuration"
2665 #endif /* CONFIG_NO_CONFIG_WRITE */
2668 struct cipher_info
{
2674 static const struct cipher_info ciphers
[] = {
2675 { WPA_DRIVER_CAPA_ENC_CCMP_256
, "CCMP-256", 0 },
2676 { WPA_DRIVER_CAPA_ENC_GCMP_256
, "GCMP-256", 0 },
2677 { WPA_DRIVER_CAPA_ENC_CCMP
, "CCMP", 0 },
2678 { WPA_DRIVER_CAPA_ENC_GCMP
, "GCMP", 0 },
2679 { WPA_DRIVER_CAPA_ENC_TKIP
, "TKIP", 0 },
2680 { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
, "NONE", 0 },
2681 { WPA_DRIVER_CAPA_ENC_WEP104
, "WEP104", 1 },
2682 { WPA_DRIVER_CAPA_ENC_WEP40
, "WEP40", 1 }
2686 static int ctrl_iface_get_capability_pairwise(int res
, char *strict
,
2687 struct wpa_driver_capa
*capa
,
2688 char *buf
, size_t buflen
)
2701 len
= os_strlcpy(buf
, "CCMP TKIP NONE", buflen
);
2707 for (i
= 0; i
< ARRAY_SIZE(ciphers
); i
++) {
2708 if (!ciphers
[i
].group_only
&& capa
->enc
& ciphers
[i
].capa
) {
2709 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
2710 first
? "" : " ", ciphers
[i
].name
);
2711 if (ret
< 0 || ret
>= end
- pos
)
2722 static int ctrl_iface_get_capability_group(int res
, char *strict
,
2723 struct wpa_driver_capa
*capa
,
2724 char *buf
, size_t buflen
)
2737 len
= os_strlcpy(buf
, "CCMP TKIP WEP104 WEP40", buflen
);
2743 for (i
= 0; i
< ARRAY_SIZE(ciphers
); i
++) {
2744 if (capa
->enc
& ciphers
[i
].capa
) {
2745 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
2746 first
? "" : " ", ciphers
[i
].name
);
2747 if (ret
< 0 || ret
>= end
- pos
)
2758 static int ctrl_iface_get_capability_key_mgmt(int res
, char *strict
,
2759 struct wpa_driver_capa
*capa
,
2760 char *buf
, size_t buflen
)
2772 len
= os_strlcpy(buf
, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
2779 ret
= os_snprintf(pos
, end
- pos
, "NONE IEEE8021X");
2780 if (ret
< 0 || ret
>= end
- pos
)
2784 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
2785 WPA_DRIVER_CAPA_KEY_MGMT_WPA2
)) {
2786 ret
= os_snprintf(pos
, end
- pos
, " WPA-EAP");
2787 if (ret
< 0 || ret
>= end
- pos
)
2792 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
|
2793 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
)) {
2794 ret
= os_snprintf(pos
, end
- pos
, " WPA-PSK");
2795 if (ret
< 0 || ret
>= end
- pos
)
2800 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
) {
2801 ret
= os_snprintf(pos
, end
- pos
, " WPA-NONE");
2802 if (ret
< 0 || ret
>= end
- pos
)
2811 static int ctrl_iface_get_capability_proto(int res
, char *strict
,
2812 struct wpa_driver_capa
*capa
,
2813 char *buf
, size_t buflen
)
2825 len
= os_strlcpy(buf
, "RSN WPA", buflen
);
2831 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA2
|
2832 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
)) {
2833 ret
= os_snprintf(pos
, end
- pos
, "%sRSN", first
? "" : " ");
2834 if (ret
< 0 || ret
>= end
- pos
)
2840 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
2841 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
)) {
2842 ret
= os_snprintf(pos
, end
- pos
, "%sWPA", first
? "" : " ");
2843 if (ret
< 0 || ret
>= end
- pos
)
2853 static int ctrl_iface_get_capability_auth_alg(int res
, char *strict
,
2854 struct wpa_driver_capa
*capa
,
2855 char *buf
, size_t buflen
)
2867 len
= os_strlcpy(buf
, "OPEN SHARED LEAP", buflen
);
2873 if (capa
->auth
& (WPA_DRIVER_AUTH_OPEN
)) {
2874 ret
= os_snprintf(pos
, end
- pos
, "%sOPEN", first
? "" : " ");
2875 if (ret
< 0 || ret
>= end
- pos
)
2881 if (capa
->auth
& (WPA_DRIVER_AUTH_SHARED
)) {
2882 ret
= os_snprintf(pos
, end
- pos
, "%sSHARED",
2884 if (ret
< 0 || ret
>= end
- pos
)
2890 if (capa
->auth
& (WPA_DRIVER_AUTH_LEAP
)) {
2891 ret
= os_snprintf(pos
, end
- pos
, "%sLEAP", first
? "" : " ");
2892 if (ret
< 0 || ret
>= end
- pos
)
2902 static int ctrl_iface_get_capability_modes(int res
, char *strict
,
2903 struct wpa_driver_capa
*capa
,
2904 char *buf
, size_t buflen
)
2916 len
= os_strlcpy(buf
, "IBSS AP", buflen
);
2922 if (capa
->flags
& WPA_DRIVER_FLAGS_IBSS
) {
2923 ret
= os_snprintf(pos
, end
- pos
, "%sIBSS", first
? "" : " ");
2924 if (ret
< 0 || ret
>= end
- pos
)
2930 if (capa
->flags
& WPA_DRIVER_FLAGS_AP
) {
2931 ret
= os_snprintf(pos
, end
- pos
, "%sAP", first
? "" : " ");
2932 if (ret
< 0 || ret
>= end
- pos
)
2942 static int ctrl_iface_get_capability_channels(struct wpa_supplicant
*wpa_s
,
2943 char *buf
, size_t buflen
)
2945 struct hostapd_channel_data
*chnl
;
2947 char *pos
, *end
, *hmode
;
2952 for (j
= 0; j
< wpa_s
->hw
.num_modes
; j
++) {
2953 switch (wpa_s
->hw
.modes
[j
].mode
) {
2954 case HOSTAPD_MODE_IEEE80211B
:
2957 case HOSTAPD_MODE_IEEE80211G
:
2960 case HOSTAPD_MODE_IEEE80211A
:
2963 case HOSTAPD_MODE_IEEE80211AD
:
2969 ret
= os_snprintf(pos
, end
- pos
, "Mode[%s] Channels:", hmode
);
2970 if (ret
< 0 || ret
>= end
- pos
)
2973 chnl
= wpa_s
->hw
.modes
[j
].channels
;
2974 for (i
= 0; i
< wpa_s
->hw
.modes
[j
].num_channels
; i
++) {
2975 if (chnl
[i
].flag
& HOSTAPD_CHAN_DISABLED
)
2977 ret
= os_snprintf(pos
, end
- pos
, " %d", chnl
[i
].chan
);
2978 if (ret
< 0 || ret
>= end
- pos
)
2982 ret
= os_snprintf(pos
, end
- pos
, "\n");
2983 if (ret
< 0 || ret
>= end
- pos
)
2992 static int ctrl_iface_get_capability_freq(struct wpa_supplicant
*wpa_s
,
2993 char *buf
, size_t buflen
)
2995 struct hostapd_channel_data
*chnl
;
2997 char *pos
, *end
, *hmode
;
3002 for (j
= 0; j
< wpa_s
->hw
.num_modes
; j
++) {
3003 switch (wpa_s
->hw
.modes
[j
].mode
) {
3004 case HOSTAPD_MODE_IEEE80211B
:
3007 case HOSTAPD_MODE_IEEE80211G
:
3010 case HOSTAPD_MODE_IEEE80211A
:
3013 case HOSTAPD_MODE_IEEE80211AD
:
3019 ret
= os_snprintf(pos
, end
- pos
, "Mode[%s] Channels:\n",
3021 if (ret
< 0 || ret
>= end
- pos
)
3024 chnl
= wpa_s
->hw
.modes
[j
].channels
;
3025 for (i
= 0; i
< wpa_s
->hw
.modes
[j
].num_channels
; i
++) {
3026 if (chnl
[i
].flag
& HOSTAPD_CHAN_DISABLED
)
3028 ret
= os_snprintf(pos
, end
- pos
, " %d = %d MHz%s\n",
3029 chnl
[i
].chan
, chnl
[i
].freq
,
3030 chnl
[i
].flag
& HOSTAPD_CHAN_NO_IBSS
?
3032 if (ret
< 0 || ret
>= end
- pos
)
3036 ret
= os_snprintf(pos
, end
- pos
, "\n");
3037 if (ret
< 0 || ret
>= end
- pos
)
3046 static int wpa_supplicant_ctrl_iface_get_capability(
3047 struct wpa_supplicant
*wpa_s
, const char *_field
, char *buf
,
3050 struct wpa_driver_capa capa
;
3056 /* Determine whether or not strict checking was requested */
3057 len
= os_strlcpy(field
, _field
, sizeof(field
));
3058 if (len
>= sizeof(field
))
3060 strict
= os_strchr(field
, ' ');
3061 if (strict
!= NULL
) {
3063 if (os_strcmp(strict
, "strict") != 0)
3067 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
3068 field
, strict
? strict
: "");
3070 if (os_strcmp(field
, "eap") == 0) {
3071 return eap_get_names(buf
, buflen
);
3074 res
= wpa_drv_get_capa(wpa_s
, &capa
);
3076 if (os_strcmp(field
, "pairwise") == 0)
3077 return ctrl_iface_get_capability_pairwise(res
, strict
, &capa
,
3080 if (os_strcmp(field
, "group") == 0)
3081 return ctrl_iface_get_capability_group(res
, strict
, &capa
,
3084 if (os_strcmp(field
, "key_mgmt") == 0)
3085 return ctrl_iface_get_capability_key_mgmt(res
, strict
, &capa
,
3088 if (os_strcmp(field
, "proto") == 0)
3089 return ctrl_iface_get_capability_proto(res
, strict
, &capa
,
3092 if (os_strcmp(field
, "auth_alg") == 0)
3093 return ctrl_iface_get_capability_auth_alg(res
, strict
, &capa
,
3096 if (os_strcmp(field
, "modes") == 0)
3097 return ctrl_iface_get_capability_modes(res
, strict
, &capa
,
3100 if (os_strcmp(field
, "channels") == 0)
3101 return ctrl_iface_get_capability_channels(wpa_s
, buf
, buflen
);
3103 if (os_strcmp(field
, "freq") == 0)
3104 return ctrl_iface_get_capability_freq(wpa_s
, buf
, buflen
);
3106 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
3113 #ifdef CONFIG_INTERWORKING
3114 static char * anqp_add_hex(char *pos
, char *end
, const char *title
,
3115 struct wpabuf
*data
)
3125 ret
= os_snprintf(pos
, end
- pos
, "%s=", title
);
3126 if (ret
< 0 || ret
>= end
- pos
)
3130 d
= wpabuf_head_u8(data
);
3131 for (i
= 0; i
< wpabuf_len(data
); i
++) {
3132 ret
= os_snprintf(pos
, end
- pos
, "%02x", *d
++);
3133 if (ret
< 0 || ret
>= end
- pos
)
3138 ret
= os_snprintf(pos
, end
- pos
, "\n");
3139 if (ret
< 0 || ret
>= end
- pos
)
3145 #endif /* CONFIG_INTERWORKING */
3148 static int print_bss_info(struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
,
3149 unsigned long mask
, char *buf
, size_t buflen
)
3159 if (mask
& WPA_BSS_MASK_ID
) {
3160 ret
= os_snprintf(pos
, end
- pos
, "id=%u\n", bss
->id
);
3161 if (ret
< 0 || ret
>= end
- pos
)
3166 if (mask
& WPA_BSS_MASK_BSSID
) {
3167 ret
= os_snprintf(pos
, end
- pos
, "bssid=" MACSTR
"\n",
3168 MAC2STR(bss
->bssid
));
3169 if (ret
< 0 || ret
>= end
- pos
)
3174 if (mask
& WPA_BSS_MASK_FREQ
) {
3175 ret
= os_snprintf(pos
, end
- pos
, "freq=%d\n", bss
->freq
);
3176 if (ret
< 0 || ret
>= end
- pos
)
3181 if (mask
& WPA_BSS_MASK_BEACON_INT
) {
3182 ret
= os_snprintf(pos
, end
- pos
, "beacon_int=%d\n",
3184 if (ret
< 0 || ret
>= end
- pos
)
3189 if (mask
& WPA_BSS_MASK_CAPABILITIES
) {
3190 ret
= os_snprintf(pos
, end
- pos
, "capabilities=0x%04x\n",
3192 if (ret
< 0 || ret
>= end
- pos
)
3197 if (mask
& WPA_BSS_MASK_QUAL
) {
3198 ret
= os_snprintf(pos
, end
- pos
, "qual=%d\n", bss
->qual
);
3199 if (ret
< 0 || ret
>= end
- pos
)
3204 if (mask
& WPA_BSS_MASK_NOISE
) {
3205 ret
= os_snprintf(pos
, end
- pos
, "noise=%d\n", bss
->noise
);
3206 if (ret
< 0 || ret
>= end
- pos
)
3211 if (mask
& WPA_BSS_MASK_LEVEL
) {
3212 ret
= os_snprintf(pos
, end
- pos
, "level=%d\n", bss
->level
);
3213 if (ret
< 0 || ret
>= end
- pos
)
3218 if (mask
& WPA_BSS_MASK_TSF
) {
3219 ret
= os_snprintf(pos
, end
- pos
, "tsf=%016llu\n",
3220 (unsigned long long) bss
->tsf
);
3221 if (ret
< 0 || ret
>= end
- pos
)
3226 if (mask
& WPA_BSS_MASK_AGE
) {
3227 struct os_reltime now
;
3229 os_get_reltime(&now
);
3230 ret
= os_snprintf(pos
, end
- pos
, "age=%d\n",
3231 (int) (now
.sec
- bss
->last_update
.sec
));
3232 if (ret
< 0 || ret
>= end
- pos
)
3237 if (mask
& WPA_BSS_MASK_IE
) {
3238 ret
= os_snprintf(pos
, end
- pos
, "ie=");
3239 if (ret
< 0 || ret
>= end
- pos
)
3243 ie
= (const u8
*) (bss
+ 1);
3244 for (i
= 0; i
< bss
->ie_len
; i
++) {
3245 ret
= os_snprintf(pos
, end
- pos
, "%02x", *ie
++);
3246 if (ret
< 0 || ret
>= end
- pos
)
3251 ret
= os_snprintf(pos
, end
- pos
, "\n");
3252 if (ret
< 0 || ret
>= end
- pos
)
3257 if (mask
& WPA_BSS_MASK_FLAGS
) {
3258 ret
= os_snprintf(pos
, end
- pos
, "flags=");
3259 if (ret
< 0 || ret
>= end
- pos
)
3263 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
3265 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA", ie
,
3267 ie2
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
3269 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA2", ie2
,
3271 pos
= wpa_supplicant_wps_ie_txt(wpa_s
, pos
, end
, bss
);
3272 if (!ie
&& !ie2
&& bss
->caps
& IEEE80211_CAP_PRIVACY
) {
3273 ret
= os_snprintf(pos
, end
- pos
, "[WEP]");
3274 if (ret
< 0 || ret
>= end
- pos
)
3278 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
3279 ret
= os_snprintf(pos
, end
- pos
, "[IBSS]");
3280 if (ret
< 0 || ret
>= end
- pos
)
3284 if (bss
->caps
& IEEE80211_CAP_ESS
) {
3285 ret
= os_snprintf(pos
, end
- pos
, "[ESS]");
3286 if (ret
< 0 || ret
>= end
- pos
)
3290 if (wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
) ||
3291 wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
)) {
3292 ret
= os_snprintf(pos
, end
- pos
, "[P2P]");
3293 if (ret
< 0 || ret
>= end
- pos
)
3298 if (wpa_bss_get_vendor_ie(bss
, HS20_IE_VENDOR_TYPE
)) {
3299 ret
= os_snprintf(pos
, end
- pos
, "[HS20]");
3300 if (ret
< 0 || ret
>= end
- pos
)
3304 #endif /* CONFIG_HS20 */
3306 ret
= os_snprintf(pos
, end
- pos
, "\n");
3307 if (ret
< 0 || ret
>= end
- pos
)
3312 if (mask
& WPA_BSS_MASK_SSID
) {
3313 ret
= os_snprintf(pos
, end
- pos
, "ssid=%s\n",
3314 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
3315 if (ret
< 0 || ret
>= end
- pos
)
3321 if (mask
& WPA_BSS_MASK_WPS_SCAN
) {
3322 ie
= (const u8
*) (bss
+ 1);
3323 ret
= wpas_wps_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
3324 if (ret
< 0 || ret
>= end
- pos
)
3328 #endif /* CONFIG_WPS */
3331 if (mask
& WPA_BSS_MASK_P2P_SCAN
) {
3332 ie
= (const u8
*) (bss
+ 1);
3333 ret
= wpas_p2p_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
3334 if (ret
< 0 || ret
>= end
- pos
)
3338 #endif /* CONFIG_P2P */
3340 #ifdef CONFIG_WIFI_DISPLAY
3341 if (mask
& WPA_BSS_MASK_WIFI_DISPLAY
) {
3343 ie
= (const u8
*) (bss
+ 1);
3344 wfd
= ieee802_11_vendor_ie_concat(ie
, bss
->ie_len
,
3345 WFD_IE_VENDOR_TYPE
);
3347 ret
= os_snprintf(pos
, end
- pos
, "wfd_subelems=");
3348 if (ret
< 0 || ret
>= end
- pos
)
3352 pos
+= wpa_snprintf_hex(pos
, end
- pos
,
3357 ret
= os_snprintf(pos
, end
- pos
, "\n");
3358 if (ret
< 0 || ret
>= end
- pos
)
3363 #endif /* CONFIG_WIFI_DISPLAY */
3365 #ifdef CONFIG_INTERWORKING
3366 if ((mask
& WPA_BSS_MASK_INTERNETW
) && bss
->anqp
) {
3367 struct wpa_bss_anqp
*anqp
= bss
->anqp
;
3368 pos
= anqp_add_hex(pos
, end
, "anqp_venue_name",
3370 pos
= anqp_add_hex(pos
, end
, "anqp_network_auth_type",
3371 anqp
->network_auth_type
);
3372 pos
= anqp_add_hex(pos
, end
, "anqp_roaming_consortium",
3373 anqp
->roaming_consortium
);
3374 pos
= anqp_add_hex(pos
, end
, "anqp_ip_addr_type_availability",
3375 anqp
->ip_addr_type_availability
);
3376 pos
= anqp_add_hex(pos
, end
, "anqp_nai_realm",
3378 pos
= anqp_add_hex(pos
, end
, "anqp_3gpp", anqp
->anqp_3gpp
);
3379 pos
= anqp_add_hex(pos
, end
, "anqp_domain_name",
3382 pos
= anqp_add_hex(pos
, end
, "hs20_operator_friendly_name",
3383 anqp
->hs20_operator_friendly_name
);
3384 pos
= anqp_add_hex(pos
, end
, "hs20_wan_metrics",
3385 anqp
->hs20_wan_metrics
);
3386 pos
= anqp_add_hex(pos
, end
, "hs20_connection_capability",
3387 anqp
->hs20_connection_capability
);
3388 #endif /* CONFIG_HS20 */
3390 #endif /* CONFIG_INTERWORKING */
3392 if (mask
& WPA_BSS_MASK_DELIM
) {
3393 ret
= os_snprintf(pos
, end
- pos
, "====\n");
3394 if (ret
< 0 || ret
>= end
- pos
)
3403 static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant
*wpa_s
,
3404 const char *cmd
, char *buf
,
3409 struct wpa_bss
*bss
;
3410 struct wpa_bss
*bsslast
= NULL
;
3411 struct dl_list
*next
;
3415 unsigned long mask
= WPA_BSS_MASK_ALL
;
3417 if (os_strncmp(cmd
, "RANGE=", 6) == 0) {
3418 if (os_strncmp(cmd
+ 6, "ALL", 3) == 0) {
3419 bss
= dl_list_first(&wpa_s
->bss_id
, struct wpa_bss
,
3421 bsslast
= dl_list_last(&wpa_s
->bss_id
, struct wpa_bss
,
3423 } else { /* N1-N2 */
3424 unsigned int id1
, id2
;
3426 if ((ctmp
= os_strchr(cmd
+ 6, '-')) == NULL
) {
3427 wpa_printf(MSG_INFO
, "Wrong BSS range "
3432 if (*(cmd
+ 6) == '-')
3435 id1
= atoi(cmd
+ 6);
3437 if (*ctmp
>= '0' && *ctmp
<= '9')
3440 id2
= (unsigned int) -1;
3441 bss
= wpa_bss_get_id_range(wpa_s
, id1
, id2
);
3442 if (id2
== (unsigned int) -1)
3443 bsslast
= dl_list_last(&wpa_s
->bss_id
,
3447 bsslast
= wpa_bss_get_id(wpa_s
, id2
);
3448 if (bsslast
== NULL
&& bss
&& id2
> id1
) {
3449 struct wpa_bss
*tmp
= bss
;
3451 next
= tmp
->list_id
.next
;
3452 if (next
== &wpa_s
->bss_id
)
3454 tmp
= dl_list_entry(
3455 next
, struct wpa_bss
,
3464 } else if (os_strncmp(cmd
, "FIRST", 5) == 0)
3465 bss
= dl_list_first(&wpa_s
->bss_id
, struct wpa_bss
, list_id
);
3466 else if (os_strncmp(cmd
, "LAST", 4) == 0)
3467 bss
= dl_list_last(&wpa_s
->bss_id
, struct wpa_bss
, list_id
);
3468 else if (os_strncmp(cmd
, "ID-", 3) == 0) {
3470 bss
= wpa_bss_get_id(wpa_s
, i
);
3471 } else if (os_strncmp(cmd
, "NEXT-", 5) == 0) {
3473 bss
= wpa_bss_get_id(wpa_s
, i
);
3475 next
= bss
->list_id
.next
;
3476 if (next
== &wpa_s
->bss_id
)
3479 bss
= dl_list_entry(next
, struct wpa_bss
,
3483 } else if (os_strncmp(cmd
, "p2p_dev_addr=", 13) == 0) {
3484 if (hwaddr_aton(cmd
+ 13, bssid
) == 0)
3485 bss
= wpa_bss_get_p2p_dev_addr(wpa_s
, bssid
);
3488 #endif /* CONFIG_P2P */
3489 } else if (hwaddr_aton(cmd
, bssid
) == 0)
3490 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
3492 struct wpa_bss
*tmp
;
3495 dl_list_for_each(tmp
, &wpa_s
->bss_id
, struct wpa_bss
, list_id
)
3504 if ((ctmp
= os_strstr(cmd
, "MASK=")) != NULL
) {
3505 mask
= strtoul(ctmp
+ 5, NULL
, 0x10);
3507 mask
= WPA_BSS_MASK_ALL
;
3513 if (bsslast
== NULL
)
3516 len
= print_bss_info(wpa_s
, bss
, mask
, buf
, buflen
);
3520 if (bss
== bsslast
) {
3521 if ((mask
& WPA_BSS_MASK_DELIM
) && len
&&
3522 (bss
== dl_list_last(&wpa_s
->bss_id
,
3523 struct wpa_bss
, list_id
)))
3524 os_snprintf(buf
- 5, 5, "####\n");
3527 next
= bss
->list_id
.next
;
3528 if (next
== &wpa_s
->bss_id
)
3530 bss
= dl_list_entry(next
, struct wpa_bss
, list_id
);
3531 } while (bss
&& len
);
3537 static int wpa_supplicant_ctrl_iface_ap_scan(
3538 struct wpa_supplicant
*wpa_s
, char *cmd
)
3540 int ap_scan
= atoi(cmd
);
3541 return wpa_supplicant_set_ap_scan(wpa_s
, ap_scan
);
3545 static int wpa_supplicant_ctrl_iface_scan_interval(
3546 struct wpa_supplicant
*wpa_s
, char *cmd
)
3548 int scan_int
= atoi(cmd
);
3549 return wpa_supplicant_set_scan_interval(wpa_s
, scan_int
);
3553 static int wpa_supplicant_ctrl_iface_bss_expire_age(
3554 struct wpa_supplicant
*wpa_s
, char *cmd
)
3556 int expire_age
= atoi(cmd
);
3557 return wpa_supplicant_set_bss_expiration_age(wpa_s
, expire_age
);
3561 static int wpa_supplicant_ctrl_iface_bss_expire_count(
3562 struct wpa_supplicant
*wpa_s
, char *cmd
)
3564 int expire_count
= atoi(cmd
);
3565 return wpa_supplicant_set_bss_expiration_count(wpa_s
, expire_count
);
3569 static int wpa_supplicant_ctrl_iface_bss_flush(
3570 struct wpa_supplicant
*wpa_s
, char *cmd
)
3572 int flush_age
= atoi(cmd
);
3575 wpa_bss_flush(wpa_s
);
3577 wpa_bss_flush_by_age(wpa_s
, flush_age
);
3582 static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant
*wpa_s
)
3584 wpa_printf(MSG_DEBUG
, "Dropping SA without deauthentication");
3585 /* MLME-DELETEKEYS.request */
3586 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 0, 0, NULL
, 0, NULL
, 0);
3587 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 1, 0, NULL
, 0, NULL
, 0);
3588 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 2, 0, NULL
, 0, NULL
, 0);
3589 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 3, 0, NULL
, 0, NULL
, 0);
3590 #ifdef CONFIG_IEEE80211W
3591 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 4, 0, NULL
, 0, NULL
, 0);
3592 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 5, 0, NULL
, 0, NULL
, 0);
3593 #endif /* CONFIG_IEEE80211W */
3595 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, wpa_s
->bssid
, 0, 0, NULL
, 0, NULL
,
3597 /* MLME-SETPROTECTION.request(None) */
3598 wpa_drv_mlme_setprotection(wpa_s
, wpa_s
->bssid
,
3599 MLME_SETPROTECTION_PROTECT_TYPE_NONE
,
3600 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE
);
3601 wpa_sm_drop_sa(wpa_s
->wpa
);
3605 static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant
*wpa_s
,
3608 #ifdef CONFIG_NO_SCAN_PROCESSING
3610 #else /* CONFIG_NO_SCAN_PROCESSING */
3612 struct wpa_bss
*bss
;
3613 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
3615 if (hwaddr_aton(addr
, bssid
)) {
3616 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: invalid "
3617 "address '%s'", addr
);
3621 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM " MACSTR
, MAC2STR(bssid
));
3624 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: No network "
3625 "configuration known for the target AP");
3629 bss
= wpa_bss_get(wpa_s
, bssid
, ssid
->ssid
, ssid
->ssid_len
);
3631 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: Target AP not found "
3637 * TODO: Find best network configuration block from configuration to
3638 * allow roaming to other networks
3641 wpa_s
->reassociate
= 1;
3642 wpa_supplicant_connect(wpa_s
, bss
, ssid
);
3645 #endif /* CONFIG_NO_SCAN_PROCESSING */
3650 static int p2p_ctrl_find(struct wpa_supplicant
*wpa_s
, char *cmd
)
3652 unsigned int timeout
= atoi(cmd
);
3653 enum p2p_discovery_type type
= P2P_FIND_START_WITH_FULL
;
3654 u8 dev_id
[ETH_ALEN
], *_dev_id
= NULL
;
3656 unsigned int search_delay
;
3658 if (os_strstr(cmd
, "type=social"))
3659 type
= P2P_FIND_ONLY_SOCIAL
;
3660 else if (os_strstr(cmd
, "type=progressive"))
3661 type
= P2P_FIND_PROGRESSIVE
;
3663 pos
= os_strstr(cmd
, "dev_id=");
3666 if (hwaddr_aton(pos
, dev_id
))
3671 pos
= os_strstr(cmd
, "delay=");
3674 search_delay
= atoi(pos
);
3676 search_delay
= wpas_p2p_search_delay(wpa_s
);
3678 return wpas_p2p_find(wpa_s
, timeout
, type
, 0, NULL
, _dev_id
,
3683 static int p2p_ctrl_connect(struct wpa_supplicant
*wpa_s
, char *cmd
,
3684 char *buf
, size_t buflen
)
3689 enum p2p_wps_method wps_method
;
3692 int persistent_group
, persistent_id
= -1;
3701 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad]
3702 * [persistent|persistent=<network id>]
3703 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
3706 if (hwaddr_aton(cmd
, addr
))
3714 persistent_group
= os_strstr(pos
, " persistent") != NULL
;
3715 pos2
= os_strstr(pos
, " persistent=");
3717 struct wpa_ssid
*ssid
;
3718 persistent_id
= atoi(pos2
+ 12);
3719 ssid
= wpa_config_get_network(wpa_s
->conf
, persistent_id
);
3720 if (ssid
== NULL
|| ssid
->disabled
!= 2 ||
3721 ssid
->mode
!= WPAS_MODE_P2P_GO
) {
3722 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3723 "SSID id=%d for persistent P2P group (GO)",
3728 join
= os_strstr(pos
, " join") != NULL
;
3729 auth
= os_strstr(pos
, " auth") != NULL
;
3730 automatic
= os_strstr(pos
, " auto") != NULL
;
3731 pd
= os_strstr(pos
, " provdisc") != NULL
;
3732 vht
= (os_strstr(cmd
, " vht") != NULL
) || wpa_s
->conf
->p2p_go_vht
;
3733 ht40
= (os_strstr(cmd
, " ht40") != NULL
) || wpa_s
->conf
->p2p_go_ht40
||
3736 pos2
= os_strstr(pos
, " go_intent=");
3739 go_intent
= atoi(pos2
);
3740 if (go_intent
< 0 || go_intent
> 15)
3744 pos2
= os_strstr(pos
, " freq=");
3752 if (os_strncmp(pos
, "pin", 3) == 0) {
3753 /* Request random PIN (to be displayed) and enable the PIN */
3754 wps_method
= WPS_PIN_DISPLAY
;
3755 } else if (os_strncmp(pos
, "pbc", 3) == 0) {
3756 wps_method
= WPS_PBC
;
3759 pos
= os_strchr(pin
, ' ');
3760 wps_method
= WPS_PIN_KEYPAD
;
3763 if (os_strncmp(pos
, "display", 7) == 0)
3764 wps_method
= WPS_PIN_DISPLAY
;
3766 if (!wps_pin_str_valid(pin
)) {
3767 os_memcpy(buf
, "FAIL-INVALID-PIN\n", 17);
3772 new_pin
= wpas_p2p_connect(wpa_s
, addr
, pin
, wps_method
,
3773 persistent_group
, automatic
, join
,
3774 auth
, go_intent
, freq
, persistent_id
, pd
,
3776 if (new_pin
== -2) {
3777 os_memcpy(buf
, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
3780 if (new_pin
== -3) {
3781 os_memcpy(buf
, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
3786 if (wps_method
== WPS_PIN_DISPLAY
&& pin
== NULL
) {
3787 ret
= os_snprintf(buf
, buflen
, "%08d", new_pin
);
3788 if (ret
< 0 || (size_t) ret
>= buflen
)
3793 os_memcpy(buf
, "OK\n", 3);
3798 static int p2p_ctrl_listen(struct wpa_supplicant
*wpa_s
, char *cmd
)
3800 unsigned int timeout
= atoi(cmd
);
3801 return wpas_p2p_listen(wpa_s
, timeout
);
3805 static int p2p_ctrl_prov_disc(struct wpa_supplicant
*wpa_s
, char *cmd
)
3809 enum wpas_p2p_prov_disc_use use
= WPAS_P2P_PD_FOR_GO_NEG
;
3811 /* <addr> <config method> [join|auto] */
3813 if (hwaddr_aton(cmd
, addr
))
3821 if (os_strstr(pos
, " join") != NULL
)
3822 use
= WPAS_P2P_PD_FOR_JOIN
;
3823 else if (os_strstr(pos
, " auto") != NULL
)
3824 use
= WPAS_P2P_PD_AUTO
;
3826 return wpas_p2p_prov_disc(wpa_s
, addr
, pos
, use
);
3830 static int p2p_get_passphrase(struct wpa_supplicant
*wpa_s
, char *buf
,
3833 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
3835 if (ssid
== NULL
|| ssid
->mode
!= WPAS_MODE_P2P_GO
||
3836 ssid
->passphrase
== NULL
)
3839 os_strlcpy(buf
, ssid
->passphrase
, buflen
);
3840 return os_strlen(buf
);
3844 static int p2p_ctrl_serv_disc_req(struct wpa_supplicant
*wpa_s
, char *cmd
,
3845 char *buf
, size_t buflen
)
3849 u8 dst_buf
[ETH_ALEN
], *dst
;
3850 struct wpabuf
*tlvs
;
3854 if (hwaddr_aton(cmd
, dst_buf
))
3857 if (dst
[0] == 0 && dst
[1] == 0 && dst
[2] == 0 &&
3858 dst
[3] == 0 && dst
[4] == 0 && dst
[5] == 0)
3865 if (os_strncmp(pos
, "upnp ", 5) == 0) {
3868 if (hexstr2bin(pos
, &version
, 1) < 0)
3874 ref
= wpas_p2p_sd_request_upnp(wpa_s
, dst
, version
, pos
);
3875 #ifdef CONFIG_WIFI_DISPLAY
3876 } else if (os_strncmp(pos
, "wifi-display ", 13) == 0) {
3877 ref
= wpas_p2p_sd_request_wifi_display(wpa_s
, dst
, pos
+ 13);
3878 #endif /* CONFIG_WIFI_DISPLAY */
3880 len
= os_strlen(pos
);
3884 tlvs
= wpabuf_alloc(len
);
3887 if (hexstr2bin(pos
, wpabuf_put(tlvs
, len
), len
) < 0) {
3892 ref
= wpas_p2p_sd_request(wpa_s
, dst
, tlvs
);
3897 res
= os_snprintf(buf
, buflen
, "%llx", (long long unsigned) ref
);
3898 if (res
< 0 || (unsigned) res
>= buflen
)
3904 static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant
*wpa_s
,
3907 long long unsigned val
;
3909 if (sscanf(cmd
, "%llx", &val
) != 1)
3912 return wpas_p2p_sd_cancel_request(wpa_s
, req
);
3916 static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant
*wpa_s
, char *cmd
)
3921 struct wpabuf
*resp_tlvs
;
3925 pos
= os_strchr(cmd
, ' ');
3933 if (hwaddr_aton(pos
, dst
))
3940 pos2
= os_strchr(pos
, ' ');
3944 dialog_token
= atoi(pos
);
3946 len
= os_strlen(pos2
);
3950 resp_tlvs
= wpabuf_alloc(len
);
3951 if (resp_tlvs
== NULL
)
3953 if (hexstr2bin(pos2
, wpabuf_put(resp_tlvs
, len
), len
) < 0) {
3954 wpabuf_free(resp_tlvs
);
3958 wpas_p2p_sd_response(wpa_s
, freq
, dst
, dialog_token
, resp_tlvs
);
3959 wpabuf_free(resp_tlvs
);
3964 static int p2p_ctrl_serv_disc_external(struct wpa_supplicant
*wpa_s
,
3967 if (os_strcmp(cmd
, "0") && os_strcmp(cmd
, "1"))
3969 wpa_s
->p2p_sd_over_ctrl_iface
= atoi(cmd
);
3974 static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant
*wpa_s
,
3979 struct wpabuf
*query
, *resp
;
3981 pos
= os_strchr(cmd
, ' ');
3986 len
= os_strlen(cmd
);
3990 query
= wpabuf_alloc(len
);
3993 if (hexstr2bin(cmd
, wpabuf_put(query
, len
), len
) < 0) {
3998 len
= os_strlen(pos
);
4004 resp
= wpabuf_alloc(len
);
4009 if (hexstr2bin(pos
, wpabuf_put(resp
, len
), len
) < 0) {
4015 if (wpas_p2p_service_add_bonjour(wpa_s
, query
, resp
) < 0) {
4024 static int p2p_ctrl_service_add_upnp(struct wpa_supplicant
*wpa_s
, char *cmd
)
4029 pos
= os_strchr(cmd
, ' ');
4034 if (hexstr2bin(cmd
, &version
, 1) < 0)
4037 return wpas_p2p_service_add_upnp(wpa_s
, version
, pos
);
4041 static int p2p_ctrl_service_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
4045 pos
= os_strchr(cmd
, ' ');
4050 if (os_strcmp(cmd
, "bonjour") == 0)
4051 return p2p_ctrl_service_add_bonjour(wpa_s
, pos
);
4052 if (os_strcmp(cmd
, "upnp") == 0)
4053 return p2p_ctrl_service_add_upnp(wpa_s
, pos
);
4054 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
4059 static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant
*wpa_s
,
4063 struct wpabuf
*query
;
4066 len
= os_strlen(cmd
);
4070 query
= wpabuf_alloc(len
);
4073 if (hexstr2bin(cmd
, wpabuf_put(query
, len
), len
) < 0) {
4078 ret
= wpas_p2p_service_del_bonjour(wpa_s
, query
);
4084 static int p2p_ctrl_service_del_upnp(struct wpa_supplicant
*wpa_s
, char *cmd
)
4089 pos
= os_strchr(cmd
, ' ');
4094 if (hexstr2bin(cmd
, &version
, 1) < 0)
4097 return wpas_p2p_service_del_upnp(wpa_s
, version
, pos
);
4101 static int p2p_ctrl_service_del(struct wpa_supplicant
*wpa_s
, char *cmd
)
4105 pos
= os_strchr(cmd
, ' ');
4110 if (os_strcmp(cmd
, "bonjour") == 0)
4111 return p2p_ctrl_service_del_bonjour(wpa_s
, pos
);
4112 if (os_strcmp(cmd
, "upnp") == 0)
4113 return p2p_ctrl_service_del_upnp(wpa_s
, pos
);
4114 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
4119 static int p2p_ctrl_reject(struct wpa_supplicant
*wpa_s
, char *cmd
)
4125 if (hwaddr_aton(cmd
, addr
))
4128 return wpas_p2p_reject(wpa_s
, addr
);
4132 static int p2p_ctrl_invite_persistent(struct wpa_supplicant
*wpa_s
, char *cmd
)
4136 struct wpa_ssid
*ssid
;
4137 u8
*_peer
= NULL
, peer
[ETH_ALEN
];
4138 int freq
= 0, pref_freq
= 0;
4142 pos
= os_strstr(cmd
, " peer=");
4145 if (hwaddr_aton(pos
, peer
))
4149 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
4150 if (ssid
== NULL
|| ssid
->disabled
!= 2) {
4151 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
4152 "for persistent P2P group",
4157 pos
= os_strstr(cmd
, " freq=");
4165 pos
= os_strstr(cmd
, " pref=");
4168 pref_freq
= atoi(pos
);
4173 vht
= (os_strstr(cmd
, " vht") != NULL
) || wpa_s
->conf
->p2p_go_vht
;
4174 ht40
= (os_strstr(cmd
, " ht40") != NULL
) || wpa_s
->conf
->p2p_go_ht40
||
4177 return wpas_p2p_invite(wpa_s
, _peer
, ssid
, NULL
, freq
, ht40
, vht
,
4182 static int p2p_ctrl_invite_group(struct wpa_supplicant
*wpa_s
, char *cmd
)
4185 u8 peer
[ETH_ALEN
], go_dev_addr
[ETH_ALEN
], *go_dev
= NULL
;
4187 pos
= os_strstr(cmd
, " peer=");
4193 if (hwaddr_aton(pos
, peer
)) {
4194 wpa_printf(MSG_DEBUG
, "P2P: Invalid MAC address '%s'", pos
);
4198 pos
= os_strstr(pos
, " go_dev_addr=");
4201 if (hwaddr_aton(pos
, go_dev_addr
)) {
4202 wpa_printf(MSG_DEBUG
, "P2P: Invalid MAC address '%s'",
4206 go_dev
= go_dev_addr
;
4209 return wpas_p2p_invite_group(wpa_s
, cmd
, peer
, go_dev
);
4213 static int p2p_ctrl_invite(struct wpa_supplicant
*wpa_s
, char *cmd
)
4215 if (os_strncmp(cmd
, "persistent=", 11) == 0)
4216 return p2p_ctrl_invite_persistent(wpa_s
, cmd
+ 11);
4217 if (os_strncmp(cmd
, "group=", 6) == 0)
4218 return p2p_ctrl_invite_group(wpa_s
, cmd
+ 6);
4224 static int p2p_ctrl_group_add_persistent(struct wpa_supplicant
*wpa_s
,
4225 char *cmd
, int freq
, int ht40
,
4229 struct wpa_ssid
*ssid
;
4232 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
4233 if (ssid
== NULL
|| ssid
->disabled
!= 2) {
4234 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
4235 "for persistent P2P group",
4240 return wpas_p2p_group_add_persistent(wpa_s
, ssid
, 0, freq
, ht40
, vht
,
4245 static int p2p_ctrl_group_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
4247 int freq
= 0, ht40
, vht
;
4250 pos
= os_strstr(cmd
, "freq=");
4252 freq
= atoi(pos
+ 5);
4254 vht
= (os_strstr(cmd
, "vht") != NULL
) || wpa_s
->conf
->p2p_go_vht
;
4255 ht40
= (os_strstr(cmd
, "ht40") != NULL
) || wpa_s
->conf
->p2p_go_ht40
||
4258 if (os_strncmp(cmd
, "persistent=", 11) == 0)
4259 return p2p_ctrl_group_add_persistent(wpa_s
, cmd
+ 11, freq
,
4261 if (os_strcmp(cmd
, "persistent") == 0 ||
4262 os_strncmp(cmd
, "persistent ", 11) == 0)
4263 return wpas_p2p_group_add(wpa_s
, 1, freq
, ht40
, vht
);
4264 if (os_strncmp(cmd
, "freq=", 5) == 0)
4265 return wpas_p2p_group_add(wpa_s
, 0, freq
, ht40
, vht
);
4267 return wpas_p2p_group_add(wpa_s
, 0, freq
, ht40
, vht
);
4269 wpa_printf(MSG_DEBUG
, "CTRL: Invalid P2P_GROUP_ADD parameters '%s'",
4275 static int p2p_ctrl_peer(struct wpa_supplicant
*wpa_s
, char *cmd
,
4276 char *buf
, size_t buflen
)
4278 u8 addr
[ETH_ALEN
], *addr_ptr
;
4280 const struct p2p_peer_info
*info
;
4282 char devtype
[WPS_DEV_TYPE_BUFSIZE
];
4283 struct wpa_ssid
*ssid
;
4286 if (!wpa_s
->global
->p2p
)
4289 if (os_strcmp(cmd
, "FIRST") == 0) {
4292 } else if (os_strncmp(cmd
, "NEXT-", 5) == 0) {
4293 if (hwaddr_aton(cmd
+ 5, addr
) < 0)
4298 if (hwaddr_aton(cmd
, addr
) < 0)
4304 info
= p2p_get_peer_info(wpa_s
->global
->p2p
, addr_ptr
, next
);
4311 res
= os_snprintf(pos
, end
- pos
, MACSTR
"\n"
4317 "serial_number=%s\n"
4318 "config_methods=0x%x\n"
4320 "group_capab=0x%x\n"
4322 MAC2STR(info
->p2p_device_addr
),
4323 wps_dev_type_bin2str(info
->pri_dev_type
,
4324 devtype
, sizeof(devtype
)),
4329 info
->serial_number
,
4330 info
->config_methods
,
4334 if (res
< 0 || res
>= end
- pos
)
4338 for (i
= 0; i
< info
->wps_sec_dev_type_list_len
/ WPS_DEV_TYPE_LEN
; i
++)
4341 t
= &info
->wps_sec_dev_type_list
[i
* WPS_DEV_TYPE_LEN
];
4342 res
= os_snprintf(pos
, end
- pos
, "sec_dev_type=%s\n",
4343 wps_dev_type_bin2str(t
, devtype
,
4345 if (res
< 0 || res
>= end
- pos
)
4350 ssid
= wpas_p2p_get_persistent(wpa_s
, info
->p2p_device_addr
, NULL
, 0);
4352 res
= os_snprintf(pos
, end
- pos
, "persistent=%d\n", ssid
->id
);
4353 if (res
< 0 || res
>= end
- pos
)
4358 res
= p2p_get_peer_info_txt(info
, pos
, end
- pos
);
4367 static int p2p_ctrl_disallow_freq(struct wpa_supplicant
*wpa_s
,
4372 if (wpa_s
->global
->p2p
== NULL
)
4375 if (freq_range_list_parse(&wpa_s
->global
->p2p_disallow_freq
, param
) < 0)
4378 for (i
= 0; i
< wpa_s
->global
->p2p_disallow_freq
.num
; i
++) {
4379 struct wpa_freq_range
*freq
;
4380 freq
= &wpa_s
->global
->p2p_disallow_freq
.range
[i
];
4381 wpa_printf(MSG_DEBUG
, "P2P: Disallowed frequency range %u-%u",
4382 freq
->min
, freq
->max
);
4385 wpas_p2p_update_channel_list(wpa_s
);
4390 static int p2p_ctrl_set(struct wpa_supplicant
*wpa_s
, char *cmd
)
4394 if (wpa_s
->global
->p2p
== NULL
)
4397 param
= os_strchr(cmd
, ' ');
4402 if (os_strcmp(cmd
, "discoverability") == 0) {
4403 p2p_set_client_discoverability(wpa_s
->global
->p2p
,
4408 if (os_strcmp(cmd
, "managed") == 0) {
4409 p2p_set_managed_oper(wpa_s
->global
->p2p
, atoi(param
));
4413 if (os_strcmp(cmd
, "listen_channel") == 0) {
4414 return p2p_set_listen_channel(wpa_s
->global
->p2p
, 81,
4418 if (os_strcmp(cmd
, "ssid_postfix") == 0) {
4419 return p2p_set_ssid_postfix(wpa_s
->global
->p2p
, (u8
*) param
,
4423 if (os_strcmp(cmd
, "noa") == 0) {
4425 int count
, start
, duration
;
4426 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
4427 count
= atoi(param
);
4428 pos
= os_strchr(param
, ',');
4433 pos
= os_strchr(pos
, ',');
4437 duration
= atoi(pos
);
4438 if (count
< 0 || count
> 255 || start
< 0 || duration
< 0)
4440 if (count
== 0 && duration
> 0)
4442 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
4443 "start=%d duration=%d", count
, start
, duration
);
4444 return wpas_p2p_set_noa(wpa_s
, count
, start
, duration
);
4447 if (os_strcmp(cmd
, "ps") == 0)
4448 return wpa_drv_set_p2p_powersave(wpa_s
, atoi(param
), -1, -1);
4450 if (os_strcmp(cmd
, "oppps") == 0)
4451 return wpa_drv_set_p2p_powersave(wpa_s
, -1, atoi(param
), -1);
4453 if (os_strcmp(cmd
, "ctwindow") == 0)
4454 return wpa_drv_set_p2p_powersave(wpa_s
, -1, -1, atoi(param
));
4456 if (os_strcmp(cmd
, "disabled") == 0) {
4457 wpa_s
->global
->p2p_disabled
= atoi(param
);
4458 wpa_printf(MSG_DEBUG
, "P2P functionality %s",
4459 wpa_s
->global
->p2p_disabled
?
4460 "disabled" : "enabled");
4461 if (wpa_s
->global
->p2p_disabled
) {
4462 wpas_p2p_stop_find(wpa_s
);
4463 os_memset(wpa_s
->p2p_auth_invite
, 0, ETH_ALEN
);
4464 p2p_flush(wpa_s
->global
->p2p
);
4469 if (os_strcmp(cmd
, "conc_pref") == 0) {
4470 if (os_strcmp(param
, "sta") == 0)
4471 wpa_s
->global
->conc_pref
= WPA_CONC_PREF_STA
;
4472 else if (os_strcmp(param
, "p2p") == 0)
4473 wpa_s
->global
->conc_pref
= WPA_CONC_PREF_P2P
;
4475 wpa_printf(MSG_INFO
, "Invalid conc_pref value");
4478 wpa_printf(MSG_DEBUG
, "Single channel concurrency preference: "
4483 if (os_strcmp(cmd
, "force_long_sd") == 0) {
4484 wpa_s
->force_long_sd
= atoi(param
);
4488 if (os_strcmp(cmd
, "peer_filter") == 0) {
4490 if (hwaddr_aton(param
, addr
))
4492 p2p_set_peer_filter(wpa_s
->global
->p2p
, addr
);
4496 if (os_strcmp(cmd
, "cross_connect") == 0)
4497 return wpas_p2p_set_cross_connect(wpa_s
, atoi(param
));
4499 if (os_strcmp(cmd
, "go_apsd") == 0) {
4500 if (os_strcmp(param
, "disable") == 0)
4501 wpa_s
->set_ap_uapsd
= 0;
4503 wpa_s
->set_ap_uapsd
= 1;
4504 wpa_s
->ap_uapsd
= atoi(param
);
4509 if (os_strcmp(cmd
, "client_apsd") == 0) {
4510 if (os_strcmp(param
, "disable") == 0)
4511 wpa_s
->set_sta_uapsd
= 0;
4515 /* format: BE,BK,VI,VO;max SP Length */
4517 pos
= os_strchr(param
, ',');
4522 pos
= os_strchr(pos
, ',');
4527 pos
= os_strchr(pos
, ',');
4532 /* ignore max SP Length for now */
4534 wpa_s
->set_sta_uapsd
= 1;
4535 wpa_s
->sta_uapsd
= 0;
4537 wpa_s
->sta_uapsd
|= BIT(0);
4539 wpa_s
->sta_uapsd
|= BIT(1);
4541 wpa_s
->sta_uapsd
|= BIT(2);
4543 wpa_s
->sta_uapsd
|= BIT(3);
4548 if (os_strcmp(cmd
, "disallow_freq") == 0)
4549 return p2p_ctrl_disallow_freq(wpa_s
, param
);
4551 if (os_strcmp(cmd
, "disc_int") == 0) {
4552 int min_disc_int
, max_disc_int
, max_disc_tu
;
4557 min_disc_int
= atoi(pos
);
4558 pos
= os_strchr(pos
, ' ');
4563 max_disc_int
= atoi(pos
);
4564 pos
= os_strchr(pos
, ' ');
4569 max_disc_tu
= atoi(pos
);
4571 return p2p_set_disc_int(wpa_s
->global
->p2p
, min_disc_int
,
4572 max_disc_int
, max_disc_tu
);
4575 if (os_strcmp(cmd
, "per_sta_psk") == 0) {
4576 wpa_s
->global
->p2p_per_sta_psk
= !!atoi(param
);
4580 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
4587 static void p2p_ctrl_flush(struct wpa_supplicant
*wpa_s
)
4589 os_memset(wpa_s
->p2p_auth_invite
, 0, ETH_ALEN
);
4590 wpa_s
->force_long_sd
= 0;
4591 if (wpa_s
->global
->p2p
)
4592 p2p_flush(wpa_s
->global
->p2p
);
4596 static int p2p_ctrl_presence_req(struct wpa_supplicant
*wpa_s
, char *cmd
)
4599 unsigned int dur1
= 0, int1
= 0, dur2
= 0, int2
= 0;
4602 pos
= os_strchr(cmd
, ' ');
4608 pos2
= os_strchr(pos
, ' ');
4616 pos
= os_strchr(pos2
, ' ');
4624 return wpas_p2p_presence_req(wpa_s
, dur1
, int1
, dur2
, int2
);
4628 static int p2p_ctrl_ext_listen(struct wpa_supplicant
*wpa_s
, char *cmd
)
4631 unsigned int period
= 0, interval
= 0;
4634 pos
= os_strchr(cmd
, ' ');
4639 interval
= atoi(pos
);
4642 return wpas_p2p_ext_listen(wpa_s
, period
, interval
);
4646 static int p2p_ctrl_remove_client(struct wpa_supplicant
*wpa_s
, const char *cmd
)
4653 if (os_strncmp(pos
, "iface=", 6) == 0) {
4657 if (hwaddr_aton(pos
, peer
))
4660 wpas_p2p_remove_client(wpa_s
, peer
, iface_addr
);
4664 #endif /* CONFIG_P2P */
4667 #ifdef CONFIG_INTERWORKING
4668 static int ctrl_interworking_connect(struct wpa_supplicant
*wpa_s
, char *dst
)
4671 struct wpa_bss
*bss
;
4673 if (hwaddr_aton(dst
, bssid
)) {
4674 wpa_printf(MSG_DEBUG
, "Invalid BSSID '%s'", dst
);
4678 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
4680 wpa_printf(MSG_DEBUG
, "Could not find BSS " MACSTR
,
4685 return interworking_connect(wpa_s
, bss
);
4689 static int get_anqp(struct wpa_supplicant
*wpa_s
, char *dst
)
4691 u8 dst_addr
[ETH_ALEN
];
4694 #define MAX_ANQP_INFO_ID 100
4695 u16 id
[MAX_ANQP_INFO_ID
];
4698 used
= hwaddr_aton2(dst
, dst_addr
);
4702 while (num_id
< MAX_ANQP_INFO_ID
) {
4703 id
[num_id
] = atoi(pos
);
4706 pos
= os_strchr(pos
+ 1, ',');
4715 return anqp_send_req(wpa_s
, dst_addr
, id
, num_id
);
4719 static int gas_request(struct wpa_supplicant
*wpa_s
, char *cmd
)
4721 u8 dst_addr
[ETH_ALEN
];
4722 struct wpabuf
*advproto
, *query
= NULL
;
4727 used
= hwaddr_aton2(cmd
, dst_addr
);
4735 /* Advertisement Protocol ID */
4736 end
= os_strchr(pos
, ' ');
4740 len
= os_strlen(pos
);
4746 advproto
= wpabuf_alloc(len
);
4747 if (advproto
== NULL
)
4749 if (hexstr2bin(pos
, wpabuf_put(advproto
, len
), len
) < 0)
4753 /* Optional Query Request */
4758 len
= os_strlen(pos
);
4765 query
= wpabuf_alloc(len
);
4768 if (hexstr2bin(pos
, wpabuf_put(query
, len
), len
) < 0)
4773 ret
= gas_send_request(wpa_s
, dst_addr
, advproto
, query
);
4776 wpabuf_free(advproto
);
4783 static int gas_response_get(struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
,
4790 size_t resp_len
, start
, requested_len
;
4792 if (!wpa_s
->last_gas_resp
)
4795 used
= hwaddr_aton2(cmd
, addr
);
4802 dialog_token
= atoi(pos
);
4804 if (os_memcmp(addr
, wpa_s
->last_gas_addr
, ETH_ALEN
) != 0 ||
4805 dialog_token
!= wpa_s
->last_gas_dialog_token
)
4808 resp_len
= wpabuf_len(wpa_s
->last_gas_resp
);
4810 requested_len
= resp_len
;
4812 pos
= os_strchr(pos
, ' ');
4815 if (start
> resp_len
)
4816 return os_snprintf(buf
, buflen
, "FAIL-Invalid range");
4817 pos
= os_strchr(pos
, ',');
4821 requested_len
= atoi(pos
);
4822 if (start
+ requested_len
> resp_len
)
4823 return os_snprintf(buf
, buflen
, "FAIL-Invalid range");
4826 if (requested_len
* 2 + 1 > buflen
)
4827 return os_snprintf(buf
, buflen
, "FAIL-Too long response");
4829 return wpa_snprintf_hex(buf
, buflen
,
4830 wpabuf_head_u8(wpa_s
->last_gas_resp
) + start
,
4833 #endif /* CONFIG_INTERWORKING */
4838 static int get_hs20_anqp(struct wpa_supplicant
*wpa_s
, char *dst
)
4840 u8 dst_addr
[ETH_ALEN
];
4845 used
= hwaddr_aton2(dst
, dst_addr
);
4850 int num
= atoi(pos
);
4851 if (num
<= 0 || num
> 31)
4853 subtypes
|= BIT(num
);
4854 pos
= os_strchr(pos
+ 1, ',');
4863 return hs20_anqp_send_req(wpa_s
, dst_addr
, subtypes
, NULL
, 0);
4867 static int hs20_nai_home_realm_list(struct wpa_supplicant
*wpa_s
,
4868 const u8
*addr
, const char *realm
)
4874 rlen
= os_strlen(realm
);
4876 buf
= os_malloc(len
);
4879 buf
[0] = 1; /* NAI Home Realm Count */
4880 buf
[1] = 0; /* Formatted in accordance with RFC 4282 */
4882 os_memcpy(buf
+ 3, realm
, rlen
);
4884 ret
= hs20_anqp_send_req(wpa_s
, addr
,
4885 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY
),
4894 static int hs20_get_nai_home_realm_list(struct wpa_supplicant
*wpa_s
,
4897 struct wpa_cred
*cred
= wpa_s
->conf
->cred
;
4898 u8 dst_addr
[ETH_ALEN
];
4904 used
= hwaddr_aton2(dst
, dst_addr
);
4908 while (dst
[used
] == ' ')
4910 if (os_strncmp(dst
+ used
, "realm=", 6) == 0)
4911 return hs20_nai_home_realm_list(wpa_s
, dst_addr
,
4914 len
= os_strlen(dst
+ used
);
4916 if (len
== 0 && cred
&& cred
->realm
)
4917 return hs20_nai_home_realm_list(wpa_s
, dst_addr
, cred
->realm
);
4922 buf
= os_malloc(len
);
4925 if (hexstr2bin(dst
+ used
, buf
, len
) < 0) {
4930 ret
= hs20_anqp_send_req(wpa_s
, dst_addr
,
4931 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY
),
4938 #endif /* CONFIG_HS20 */
4941 static int wpa_supplicant_ctrl_iface_sta_autoconnect(
4942 struct wpa_supplicant
*wpa_s
, char *cmd
)
4944 wpa_s
->auto_reconnect_disabled
= atoi(cmd
) == 0 ? 1 : 0;
4949 #ifdef CONFIG_AUTOSCAN
4951 static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant
*wpa_s
,
4954 enum wpa_states state
= wpa_s
->wpa_state
;
4955 char *new_params
= NULL
;
4957 if (os_strlen(cmd
) > 0) {
4958 new_params
= os_strdup(cmd
);
4959 if (new_params
== NULL
)
4963 os_free(wpa_s
->conf
->autoscan
);
4964 wpa_s
->conf
->autoscan
= new_params
;
4966 if (wpa_s
->conf
->autoscan
== NULL
)
4967 autoscan_deinit(wpa_s
);
4968 else if (state
== WPA_DISCONNECTED
|| state
== WPA_INACTIVE
)
4969 autoscan_init(wpa_s
, 1);
4970 else if (state
== WPA_SCANNING
)
4971 wpa_supplicant_reinit_autoscan(wpa_s
);
4976 #endif /* CONFIG_AUTOSCAN */
4981 static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant
*wpa_s
, char *cmd
)
4987 struct wpabuf
*tfs_req
= NULL
;
4989 if (os_strncmp(cmd
, "enter", 5) == 0)
4991 else if (os_strncmp(cmd
, "exit", 4) == 0)
4996 pos
= os_strstr(cmd
, " interval=");
4998 intval
= atoi(pos
+ 10);
5000 pos
= os_strstr(cmd
, " tfs_req=");
5005 end
= os_strchr(pos
, ' ');
5009 len
= os_strlen(pos
);
5013 tfs_req
= wpabuf_alloc(len
);
5014 if (tfs_req
== NULL
)
5016 if (hexstr2bin(pos
, wpabuf_put(tfs_req
, len
), len
) < 0) {
5017 wpabuf_free(tfs_req
);
5022 ret
= ieee802_11_send_wnmsleep_req(wpa_s
, enter
? WNM_SLEEP_MODE_ENTER
:
5023 WNM_SLEEP_MODE_EXIT
, intval
,
5025 wpabuf_free(tfs_req
);
5031 static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant
*wpa_s
, char *cmd
)
5035 query_reason
= atoi(cmd
);
5037 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d",
5040 return wnm_send_bss_transition_mgmt_query(wpa_s
, query_reason
);
5043 #endif /* CONFIG_WNM */
5046 /* Get string representation of channel width */
5047 static const char * channel_width_name(enum chan_width width
)
5050 case CHAN_WIDTH_20_NOHT
:
5051 return "20 MHz (no HT)";
5058 case CHAN_WIDTH_80P80
:
5060 case CHAN_WIDTH_160
:
5068 static int wpa_supplicant_signal_poll(struct wpa_supplicant
*wpa_s
, char *buf
,
5071 struct wpa_signal_info si
;
5075 ret
= wpa_drv_signal_poll(wpa_s
, &si
);
5082 ret
= os_snprintf(pos
, end
- pos
, "RSSI=%d\nLINKSPEED=%d\n"
5083 "NOISE=%d\nFREQUENCY=%u\n",
5084 si
.current_signal
, si
.current_txrate
/ 1000,
5085 si
.current_noise
, si
.frequency
);
5086 if (ret
< 0 || ret
> end
- pos
)
5090 if (si
.chanwidth
!= CHAN_WIDTH_UNKNOWN
) {
5091 ret
= os_snprintf(pos
, end
- pos
, "WIDTH=%s\n",
5092 channel_width_name(si
.chanwidth
));
5093 if (ret
< 0 || ret
> end
- pos
)
5098 if (si
.center_frq1
> 0 && si
.center_frq2
> 0) {
5099 ret
= os_snprintf(pos
, end
- pos
,
5100 "CENTER_FRQ1=%d\nCENTER_FRQ2=%d\n",
5101 si
.center_frq1
, si
.center_frq2
);
5102 if (ret
< 0 || ret
> end
- pos
)
5107 if (si
.avg_signal
) {
5108 ret
= os_snprintf(pos
, end
- pos
,
5109 "AVG_RSSI=%d\n", si
.avg_signal
);
5110 if (ret
< 0 || ret
>= end
- pos
)
5119 static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant
*wpa_s
, char *buf
,
5122 struct hostap_sta_driver_data sta
;
5125 ret
= wpa_drv_pktcnt_poll(wpa_s
, &sta
);
5129 ret
= os_snprintf(buf
, buflen
, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
5130 sta
.tx_packets
, sta
.tx_retry_failed
, sta
.rx_packets
);
5131 if (ret
< 0 || (size_t) ret
> buflen
)
5138 static int wpa_supplicant_driver_cmd(struct wpa_supplicant
*wpa_s
, char *cmd
,
5139 char *buf
, size_t buflen
)
5143 ret
= wpa_drv_driver_cmd(wpa_s
, cmd
, buf
, buflen
);
5145 if (os_strncasecmp(cmd
, "COUNTRY", 7) == 0) {
5146 struct p2p_data
*p2p
= wpa_s
->global
->p2p
;
5149 country
[0] = cmd
[8];
5150 country
[1] = cmd
[9];
5152 p2p_set_country(p2p
, country
);
5155 ret
= os_snprintf(buf
, buflen
, "%s\n", "OK");
5159 #endif /* ANDROID */
5162 static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant
*wpa_s
)
5164 wpa_dbg(wpa_s
, MSG_DEBUG
, "Flush all wpa_supplicant state");
5167 wpas_p2p_stop_find(wpa_s
);
5168 p2p_ctrl_flush(wpa_s
);
5169 wpas_p2p_group_remove(wpa_s
, "*");
5170 wpas_p2p_service_flush(wpa_s
);
5171 #endif /* CONFIG_P2P */
5173 #ifdef CONFIG_WPS_TESTING
5174 wps_version_number
= 0x20;
5175 wps_testing_dummy_cred
= 0;
5176 #endif /* CONFIG_WPS_TESTING */
5178 wpa_s
->wps_fragment_size
= 0;
5179 wpas_wps_cancel(wpa_s
);
5180 #endif /* CONFIG_WPS */
5181 wpa_s
->after_wps
= 0;
5182 wpa_s
->known_wps_freq
= 0;
5185 #ifdef CONFIG_TDLS_TESTING
5186 extern unsigned int tdls_testing
;
5188 #endif /* CONFIG_TDLS_TESTING */
5189 wpa_drv_tdls_oper(wpa_s
, TDLS_ENABLE
, NULL
);
5190 wpa_tdls_enable(wpa_s
->wpa
, 1);
5191 #endif /* CONFIG_TDLS */
5193 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures
, wpa_s
, NULL
);
5194 wpa_supplicant_stop_countermeasures(wpa_s
, NULL
);
5196 wpa_s
->no_keep_alive
= 0;
5198 os_free(wpa_s
->disallow_aps_bssid
);
5199 wpa_s
->disallow_aps_bssid
= NULL
;
5200 wpa_s
->disallow_aps_bssid_count
= 0;
5201 os_free(wpa_s
->disallow_aps_ssid
);
5202 wpa_s
->disallow_aps_ssid
= NULL
;
5203 wpa_s
->disallow_aps_ssid_count
= 0;
5205 wpa_s
->set_sta_uapsd
= 0;
5206 wpa_s
->sta_uapsd
= 0;
5208 wpa_drv_radio_disable(wpa_s
, 0);
5210 wpa_bss_flush(wpa_s
);
5211 wpa_blacklist_clear(wpa_s
);
5212 wpa_s
->extra_blacklist_count
= 0;
5213 wpa_supplicant_ctrl_iface_remove_network(wpa_s
, "all");
5214 wpa_supplicant_ctrl_iface_remove_cred(wpa_s
, "all");
5216 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_LIFETIME
, 43200);
5217 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_REAUTH_THRESHOLD
, 70);
5218 wpa_sm_set_param(wpa_s
->wpa
, RSNA_SA_TIMEOUT
, 60);
5219 eapol_sm_notify_logoff(wpa_s
->eapol
, FALSE
);
5221 radio_remove_unstarted_work(wpa_s
, NULL
);
5225 static int wpas_ctrl_radio_work_show(struct wpa_supplicant
*wpa_s
,
5226 char *buf
, size_t buflen
)
5228 struct wpa_radio_work
*work
;
5230 struct os_reltime now
, diff
;
5235 os_get_reltime(&now
);
5237 dl_list_for_each(work
, &wpa_s
->radio
->work
, struct wpa_radio_work
, list
)
5241 os_reltime_sub(&now
, &work
->time
, &diff
);
5242 ret
= os_snprintf(pos
, end
- pos
, "%s@%s:%u:%u:%ld.%06ld\n",
5243 work
->type
, work
->wpa_s
->ifname
, work
->freq
,
5244 work
->started
, diff
.sec
, diff
.usec
);
5245 if (ret
< 0 || ret
>= end
- pos
)
5254 static void wpas_ctrl_radio_work_timeout(void *eloop_ctx
, void *timeout_ctx
)
5256 struct wpa_radio_work
*work
= eloop_ctx
;
5257 struct wpa_external_work
*ework
= work
->ctx
;
5259 wpa_dbg(work
->wpa_s
, MSG_DEBUG
,
5260 "Timing out external radio work %u (%s)",
5261 ework
->id
, work
->type
);
5262 wpa_msg(work
->wpa_s
, MSG_INFO
, EXT_RADIO_WORK_TIMEOUT
"%u", ework
->id
);
5264 radio_work_done(work
);
5268 static void wpas_ctrl_radio_work_cb(struct wpa_radio_work
*work
, int deinit
)
5270 struct wpa_external_work
*ework
= work
->ctx
;
5277 wpa_dbg(work
->wpa_s
, MSG_DEBUG
, "Starting external radio work %u (%s)",
5278 ework
->id
, ework
->type
);
5279 wpa_msg(work
->wpa_s
, MSG_INFO
, EXT_RADIO_WORK_START
"%u", ework
->id
);
5280 if (!ework
->timeout
)
5281 ework
->timeout
= 10;
5282 eloop_register_timeout(ework
->timeout
, 0, wpas_ctrl_radio_work_timeout
,
5287 static int wpas_ctrl_radio_work_add(struct wpa_supplicant
*wpa_s
, char *cmd
,
5288 char *buf
, size_t buflen
)
5290 struct wpa_external_work
*ework
;
5294 unsigned int freq
= 0;
5296 /* format: <name> [freq=<MHz>] [timeout=<seconds>] */
5298 ework
= os_zalloc(sizeof(*ework
));
5302 pos
= os_strchr(cmd
, ' ');
5304 type_len
= pos
- cmd
;
5307 pos2
= os_strstr(pos
, "freq=");
5309 freq
= atoi(pos2
+ 5);
5311 pos2
= os_strstr(pos
, "timeout=");
5313 ework
->timeout
= atoi(pos2
+ 8);
5315 type_len
= os_strlen(cmd
);
5317 if (4 + type_len
>= sizeof(ework
->type
))
5318 type_len
= sizeof(ework
->type
) - 4 - 1;
5319 os_strlcpy(ework
->type
, "ext:", sizeof(ework
->type
));
5320 os_memcpy(ework
->type
+ 4, cmd
, type_len
);
5321 ework
->type
[4 + type_len
] = '\0';
5323 wpa_s
->ext_work_id
++;
5324 if (wpa_s
->ext_work_id
== 0)
5325 wpa_s
->ext_work_id
++;
5326 ework
->id
= wpa_s
->ext_work_id
;
5328 if (radio_add_work(wpa_s
, freq
, ework
->type
, 0, wpas_ctrl_radio_work_cb
,
5334 ret
= os_snprintf(buf
, buflen
, "%u", ework
->id
);
5335 if (ret
< 0 || (size_t) ret
>= buflen
)
5341 static int wpas_ctrl_radio_work_done(struct wpa_supplicant
*wpa_s
, char *cmd
)
5343 struct wpa_radio_work
*work
;
5344 unsigned int id
= atoi(cmd
);
5346 dl_list_for_each(work
, &wpa_s
->radio
->work
, struct wpa_radio_work
, list
)
5348 struct wpa_external_work
*ework
;
5350 if (os_strncmp(work
->type
, "ext:", 4) != 0)
5353 if (id
&& ework
->id
!= id
)
5355 wpa_dbg(wpa_s
, MSG_DEBUG
,
5356 "Completed external radio work %u (%s)",
5357 ework
->id
, ework
->type
);
5358 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
, work
, NULL
);
5360 radio_work_done(work
);
5361 return 3; /* "OK\n" */
5368 static int wpas_ctrl_radio_work(struct wpa_supplicant
*wpa_s
, char *cmd
,
5369 char *buf
, size_t buflen
)
5371 if (os_strcmp(cmd
, "show") == 0)
5372 return wpas_ctrl_radio_work_show(wpa_s
, buf
, buflen
);
5373 if (os_strncmp(cmd
, "add ", 4) == 0)
5374 return wpas_ctrl_radio_work_add(wpa_s
, cmd
+ 4, buf
, buflen
);
5375 if (os_strncmp(cmd
, "done ", 5) == 0)
5376 return wpas_ctrl_radio_work_done(wpa_s
, cmd
+ 4);
5381 void wpas_ctrl_radio_work_flush(struct wpa_supplicant
*wpa_s
)
5383 struct wpa_radio_work
*work
, *tmp
;
5385 dl_list_for_each_safe(work
, tmp
, &wpa_s
->radio
->work
,
5386 struct wpa_radio_work
, list
) {
5387 struct wpa_external_work
*ework
;
5389 if (os_strncmp(work
->type
, "ext:", 4) != 0)
5392 wpa_dbg(wpa_s
, MSG_DEBUG
,
5393 "Flushing %sexternal radio work %u (%s)",
5394 work
->started
? " started" : "", ework
->id
,
5397 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
,
5400 radio_work_done(work
);
5405 static void wpas_ctrl_eapol_response(void *eloop_ctx
, void *timeout_ctx
)
5407 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
5408 eapol_sm_notify_ctrl_response(wpa_s
->eapol
);
5412 static int set_scan_freqs(struct wpa_supplicant
*wpa_s
, char *val
)
5414 struct wpa_freq_range_list ranges
;
5416 struct hostapd_hw_modes
*mode
;
5419 if (wpa_s
->hw
.modes
== NULL
)
5422 os_memset(&ranges
, 0, sizeof(ranges
));
5423 if (freq_range_list_parse(&ranges
, val
) < 0)
5426 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
5429 mode
= &wpa_s
->hw
.modes
[i
];
5430 for (j
= 0; j
< mode
->num_channels
; j
++) {
5433 if (mode
->channels
[j
].flag
& HOSTAPD_CHAN_DISABLED
)
5436 freq
= mode
->channels
[j
].freq
;
5437 if (!freq_range_list_includes(&ranges
, freq
))
5440 int_array_add_unique(&freqs
, freq
);
5444 os_free(ranges
.range
);
5445 os_free(wpa_s
->manual_scan_freqs
);
5446 wpa_s
->manual_scan_freqs
= freqs
;
5452 static void wpas_ctrl_scan(struct wpa_supplicant
*wpa_s
, char *params
,
5453 char *reply
, int reply_size
, int *reply_len
)
5457 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
5462 wpa_s
->manual_scan_passive
= 0;
5463 wpa_s
->manual_scan_use_id
= 0;
5464 wpa_s
->manual_scan_only_new
= 0;
5467 if (os_strncasecmp(params
, "TYPE=ONLY", 9) == 0)
5468 wpa_s
->scan_res_handler
= scan_only_handler
;
5470 pos
= os_strstr(params
, "freq=");
5471 if (pos
&& set_scan_freqs(wpa_s
, pos
+ 5) < 0) {
5476 pos
= os_strstr(params
, "passive=");
5478 wpa_s
->manual_scan_passive
= !!atoi(pos
+ 8);
5480 pos
= os_strstr(params
, "use_id=");
5482 wpa_s
->manual_scan_use_id
= atoi(pos
+ 7);
5484 pos
= os_strstr(params
, "only_new=1");
5486 wpa_s
->manual_scan_only_new
= 1;
5488 os_free(wpa_s
->manual_scan_freqs
);
5489 wpa_s
->manual_scan_freqs
= NULL
;
5490 if (wpa_s
->scan_res_handler
== scan_only_handler
)
5491 wpa_s
->scan_res_handler
= NULL
;
5494 if (!wpa_s
->sched_scanning
&& !wpa_s
->scanning
&&
5495 ((wpa_s
->wpa_state
<= WPA_SCANNING
) ||
5496 (wpa_s
->wpa_state
== WPA_COMPLETED
))) {
5497 wpa_s
->normal_scans
= 0;
5498 wpa_s
->scan_req
= MANUAL_SCAN_REQ
;
5499 wpa_s
->after_wps
= 0;
5500 wpa_s
->known_wps_freq
= 0;
5501 wpa_supplicant_req_scan(wpa_s
, 0, 0);
5502 if (wpa_s
->manual_scan_use_id
) {
5503 wpa_s
->manual_scan_id
++;
5504 wpa_dbg(wpa_s
, MSG_DEBUG
, "Assigned scan id %u",
5505 wpa_s
->manual_scan_id
);
5506 *reply_len
= os_snprintf(reply
, reply_size
, "%u\n",
5507 wpa_s
->manual_scan_id
);
5509 } else if (wpa_s
->sched_scanning
) {
5510 wpa_printf(MSG_DEBUG
, "Stop ongoing sched_scan to allow requested full scan to proceed");
5511 wpa_supplicant_cancel_sched_scan(wpa_s
);
5512 wpa_s
->scan_req
= MANUAL_SCAN_REQ
;
5513 wpa_supplicant_req_scan(wpa_s
, 0, 0);
5514 if (wpa_s
->manual_scan_use_id
) {
5515 wpa_s
->manual_scan_id
++;
5516 *reply_len
= os_snprintf(reply
, reply_size
, "%u\n",
5517 wpa_s
->manual_scan_id
);
5518 wpa_dbg(wpa_s
, MSG_DEBUG
, "Assigned scan id %u",
5519 wpa_s
->manual_scan_id
);
5522 wpa_printf(MSG_DEBUG
, "Ongoing scan action - reject new request");
5523 *reply_len
= os_snprintf(reply
, reply_size
, "FAIL-BUSY\n");
5528 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant
*wpa_s
,
5529 char *buf
, size_t *resp_len
)
5532 const int reply_size
= 4096;
5535 if (os_strncmp(buf
, WPA_CTRL_RSP
, os_strlen(WPA_CTRL_RSP
)) == 0 ||
5536 os_strncmp(buf
, "SET_NETWORK ", 12) == 0) {
5537 if (wpa_debug_show_keys
)
5538 wpa_dbg(wpa_s
, MSG_DEBUG
,
5539 "Control interface command '%s'", buf
);
5541 wpa_dbg(wpa_s
, MSG_DEBUG
,
5542 "Control interface command '%s [REMOVED]'",
5543 os_strncmp(buf
, WPA_CTRL_RSP
,
5544 os_strlen(WPA_CTRL_RSP
)) == 0 ?
5545 WPA_CTRL_RSP
: "SET_NETWORK");
5546 } else if (os_strncmp(buf
, "WPS_NFC_TAG_READ", 16) == 0 ||
5547 os_strncmp(buf
, "NFC_REPORT_HANDOVER", 19) == 0 ||
5548 os_strncmp(buf
, "NFC_RX_HANDOVER_SEL", 19) == 0) {
5549 wpa_hexdump_ascii_key(MSG_DEBUG
, "RX ctrl_iface",
5550 (const u8
*) buf
, os_strlen(buf
));
5552 int level
= MSG_DEBUG
;
5553 if (os_strcmp(buf
, "PING") == 0)
5554 level
= MSG_EXCESSIVE
;
5555 wpa_dbg(wpa_s
, level
, "Control interface command '%s'", buf
);
5558 reply
= os_malloc(reply_size
);
5559 if (reply
== NULL
) {
5564 os_memcpy(reply
, "OK\n", 3);
5567 if (os_strcmp(buf
, "PING") == 0) {
5568 os_memcpy(reply
, "PONG\n", 5);
5570 } else if (os_strcmp(buf
, "IFNAME") == 0) {
5571 reply_len
= os_strlen(wpa_s
->ifname
);
5572 os_memcpy(reply
, wpa_s
->ifname
, reply_len
);
5573 } else if (os_strncmp(buf
, "RELOG", 5) == 0) {
5574 if (wpa_debug_reopen_file() < 0)
5576 } else if (os_strncmp(buf
, "NOTE ", 5) == 0) {
5577 wpa_printf(MSG_INFO
, "NOTE: %s", buf
+ 5);
5578 } else if (os_strcmp(buf
, "MIB") == 0) {
5579 reply_len
= wpa_sm_get_mib(wpa_s
->wpa
, reply
, reply_size
);
5580 if (reply_len
>= 0) {
5582 res
= eapol_sm_get_mib(wpa_s
->eapol
, reply
+ reply_len
,
5583 reply_size
- reply_len
);
5589 } else if (os_strncmp(buf
, "STATUS", 6) == 0) {
5590 reply_len
= wpa_supplicant_ctrl_iface_status(
5591 wpa_s
, buf
+ 6, reply
, reply_size
);
5592 } else if (os_strcmp(buf
, "PMKSA") == 0) {
5593 reply_len
= wpa_sm_pmksa_cache_list(wpa_s
->wpa
, reply
,
5595 } else if (os_strncmp(buf
, "SET ", 4) == 0) {
5596 if (wpa_supplicant_ctrl_iface_set(wpa_s
, buf
+ 4))
5598 } else if (os_strncmp(buf
, "GET ", 4) == 0) {
5599 reply_len
= wpa_supplicant_ctrl_iface_get(wpa_s
, buf
+ 4,
5601 } else if (os_strcmp(buf
, "LOGON") == 0) {
5602 eapol_sm_notify_logoff(wpa_s
->eapol
, FALSE
);
5603 } else if (os_strcmp(buf
, "LOGOFF") == 0) {
5604 eapol_sm_notify_logoff(wpa_s
->eapol
, TRUE
);
5605 } else if (os_strcmp(buf
, "REASSOCIATE") == 0) {
5606 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
5609 wpas_request_connection(wpa_s
);
5610 } else if (os_strcmp(buf
, "RECONNECT") == 0) {
5611 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
5613 else if (wpa_s
->disconnected
)
5614 wpas_request_connection(wpa_s
);
5615 #ifdef IEEE8021X_EAPOL
5616 } else if (os_strncmp(buf
, "PREAUTH ", 8) == 0) {
5617 if (wpa_supplicant_ctrl_iface_preauth(wpa_s
, buf
+ 8))
5619 #endif /* IEEE8021X_EAPOL */
5620 #ifdef CONFIG_PEERKEY
5621 } else if (os_strncmp(buf
, "STKSTART ", 9) == 0) {
5622 if (wpa_supplicant_ctrl_iface_stkstart(wpa_s
, buf
+ 9))
5624 #endif /* CONFIG_PEERKEY */
5625 #ifdef CONFIG_IEEE80211R
5626 } else if (os_strncmp(buf
, "FT_DS ", 6) == 0) {
5627 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s
, buf
+ 6))
5629 #endif /* CONFIG_IEEE80211R */
5631 } else if (os_strcmp(buf
, "WPS_PBC") == 0) {
5632 int res
= wpa_supplicant_ctrl_iface_wps_pbc(wpa_s
, NULL
);
5634 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
5638 } else if (os_strncmp(buf
, "WPS_PBC ", 8) == 0) {
5639 int res
= wpa_supplicant_ctrl_iface_wps_pbc(wpa_s
, buf
+ 8);
5641 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
5645 } else if (os_strncmp(buf
, "WPS_PIN ", 8) == 0) {
5646 reply_len
= wpa_supplicant_ctrl_iface_wps_pin(wpa_s
, buf
+ 8,
5649 } else if (os_strncmp(buf
, "WPS_CHECK_PIN ", 14) == 0) {
5650 reply_len
= wpa_supplicant_ctrl_iface_wps_check_pin(
5651 wpa_s
, buf
+ 14, reply
, reply_size
);
5652 } else if (os_strcmp(buf
, "WPS_CANCEL") == 0) {
5653 if (wpas_wps_cancel(wpa_s
))
5655 #ifdef CONFIG_WPS_NFC
5656 } else if (os_strcmp(buf
, "WPS_NFC") == 0) {
5657 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s
, NULL
))
5659 } else if (os_strncmp(buf
, "WPS_NFC ", 8) == 0) {
5660 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s
, buf
+ 8))
5662 } else if (os_strncmp(buf
, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
5663 reply_len
= wpa_supplicant_ctrl_iface_wps_nfc_config_token(
5664 wpa_s
, buf
+ 21, reply
, reply_size
);
5665 } else if (os_strncmp(buf
, "WPS_NFC_TOKEN ", 14) == 0) {
5666 reply_len
= wpa_supplicant_ctrl_iface_wps_nfc_token(
5667 wpa_s
, buf
+ 14, reply
, reply_size
);
5668 } else if (os_strncmp(buf
, "WPS_NFC_TAG_READ ", 17) == 0) {
5669 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s
,
5672 } else if (os_strncmp(buf
, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
5673 reply_len
= wpas_ctrl_nfc_get_handover_req(
5674 wpa_s
, buf
+ 21, reply
, reply_size
);
5675 } else if (os_strncmp(buf
, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
5676 reply_len
= wpas_ctrl_nfc_get_handover_sel(
5677 wpa_s
, buf
+ 21, reply
, reply_size
);
5678 } else if (os_strncmp(buf
, "NFC_RX_HANDOVER_REQ ", 20) == 0) {
5679 reply_len
= wpas_ctrl_nfc_rx_handover_req(
5680 wpa_s
, buf
+ 20, reply
, reply_size
);
5681 } else if (os_strncmp(buf
, "NFC_RX_HANDOVER_SEL ", 20) == 0) {
5682 if (wpas_ctrl_nfc_rx_handover_sel(wpa_s
, buf
+ 20))
5684 } else if (os_strncmp(buf
, "NFC_REPORT_HANDOVER ", 20) == 0) {
5685 if (wpas_ctrl_nfc_report_handover(wpa_s
, buf
+ 20))
5687 #endif /* CONFIG_WPS_NFC */
5688 } else if (os_strncmp(buf
, "WPS_REG ", 8) == 0) {
5689 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s
, buf
+ 8))
5692 } else if (os_strncmp(buf
, "WPS_AP_PIN ", 11) == 0) {
5693 reply_len
= wpa_supplicant_ctrl_iface_wps_ap_pin(
5694 wpa_s
, buf
+ 11, reply
, reply_size
);
5695 #endif /* CONFIG_AP */
5696 #ifdef CONFIG_WPS_ER
5697 } else if (os_strcmp(buf
, "WPS_ER_START") == 0) {
5698 if (wpas_wps_er_start(wpa_s
, NULL
))
5700 } else if (os_strncmp(buf
, "WPS_ER_START ", 13) == 0) {
5701 if (wpas_wps_er_start(wpa_s
, buf
+ 13))
5703 } else if (os_strcmp(buf
, "WPS_ER_STOP") == 0) {
5704 if (wpas_wps_er_stop(wpa_s
))
5706 } else if (os_strncmp(buf
, "WPS_ER_PIN ", 11) == 0) {
5707 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s
, buf
+ 11))
5709 } else if (os_strncmp(buf
, "WPS_ER_PBC ", 11) == 0) {
5710 int ret
= wpas_wps_er_pbc(wpa_s
, buf
+ 11);
5712 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
5714 } else if (ret
== -3) {
5715 os_memcpy(reply
, "FAIL-UNKNOWN-UUID\n", 18);
5717 } else if (ret
== -4) {
5718 os_memcpy(reply
, "FAIL-NO-AP-SETTINGS\n", 20);
5722 } else if (os_strncmp(buf
, "WPS_ER_LEARN ", 13) == 0) {
5723 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s
, buf
+ 13))
5725 } else if (os_strncmp(buf
, "WPS_ER_SET_CONFIG ", 18) == 0) {
5726 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s
,
5729 } else if (os_strncmp(buf
, "WPS_ER_CONFIG ", 14) == 0) {
5730 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s
, buf
+ 14))
5732 #ifdef CONFIG_WPS_NFC
5733 } else if (os_strncmp(buf
, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
5734 reply_len
= wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
5735 wpa_s
, buf
+ 24, reply
, reply_size
);
5736 #endif /* CONFIG_WPS_NFC */
5737 #endif /* CONFIG_WPS_ER */
5738 #endif /* CONFIG_WPS */
5739 #ifdef CONFIG_IBSS_RSN
5740 } else if (os_strncmp(buf
, "IBSS_RSN ", 9) == 0) {
5741 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s
, buf
+ 9))
5743 #endif /* CONFIG_IBSS_RSN */
5745 } else if (os_strncmp(buf
, "P2P_FIND ", 9) == 0) {
5746 if (p2p_ctrl_find(wpa_s
, buf
+ 9))
5748 } else if (os_strcmp(buf
, "P2P_FIND") == 0) {
5749 if (p2p_ctrl_find(wpa_s
, ""))
5751 } else if (os_strcmp(buf
, "P2P_STOP_FIND") == 0) {
5752 wpas_p2p_stop_find(wpa_s
);
5753 } else if (os_strncmp(buf
, "P2P_CONNECT ", 12) == 0) {
5754 reply_len
= p2p_ctrl_connect(wpa_s
, buf
+ 12, reply
,
5756 } else if (os_strncmp(buf
, "P2P_LISTEN ", 11) == 0) {
5757 if (p2p_ctrl_listen(wpa_s
, buf
+ 11))
5759 } else if (os_strcmp(buf
, "P2P_LISTEN") == 0) {
5760 if (p2p_ctrl_listen(wpa_s
, ""))
5762 } else if (os_strncmp(buf
, "P2P_GROUP_REMOVE ", 17) == 0) {
5763 if (wpas_p2p_group_remove(wpa_s
, buf
+ 17))
5765 } else if (os_strcmp(buf
, "P2P_GROUP_ADD") == 0) {
5766 if (wpas_p2p_group_add(wpa_s
, 0, 0, 0, 0))
5768 } else if (os_strncmp(buf
, "P2P_GROUP_ADD ", 14) == 0) {
5769 if (p2p_ctrl_group_add(wpa_s
, buf
+ 14))
5771 } else if (os_strncmp(buf
, "P2P_PROV_DISC ", 14) == 0) {
5772 if (p2p_ctrl_prov_disc(wpa_s
, buf
+ 14))
5774 } else if (os_strcmp(buf
, "P2P_GET_PASSPHRASE") == 0) {
5775 reply_len
= p2p_get_passphrase(wpa_s
, reply
, reply_size
);
5776 } else if (os_strncmp(buf
, "P2P_SERV_DISC_REQ ", 18) == 0) {
5777 reply_len
= p2p_ctrl_serv_disc_req(wpa_s
, buf
+ 18, reply
,
5779 } else if (os_strncmp(buf
, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
5780 if (p2p_ctrl_serv_disc_cancel_req(wpa_s
, buf
+ 25) < 0)
5782 } else if (os_strncmp(buf
, "P2P_SERV_DISC_RESP ", 19) == 0) {
5783 if (p2p_ctrl_serv_disc_resp(wpa_s
, buf
+ 19) < 0)
5785 } else if (os_strcmp(buf
, "P2P_SERVICE_UPDATE") == 0) {
5786 wpas_p2p_sd_service_update(wpa_s
);
5787 } else if (os_strncmp(buf
, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
5788 if (p2p_ctrl_serv_disc_external(wpa_s
, buf
+ 23) < 0)
5790 } else if (os_strcmp(buf
, "P2P_SERVICE_FLUSH") == 0) {
5791 wpas_p2p_service_flush(wpa_s
);
5792 } else if (os_strncmp(buf
, "P2P_SERVICE_ADD ", 16) == 0) {
5793 if (p2p_ctrl_service_add(wpa_s
, buf
+ 16) < 0)
5795 } else if (os_strncmp(buf
, "P2P_SERVICE_DEL ", 16) == 0) {
5796 if (p2p_ctrl_service_del(wpa_s
, buf
+ 16) < 0)
5798 } else if (os_strncmp(buf
, "P2P_REJECT ", 11) == 0) {
5799 if (p2p_ctrl_reject(wpa_s
, buf
+ 11) < 0)
5801 } else if (os_strncmp(buf
, "P2P_INVITE ", 11) == 0) {
5802 if (p2p_ctrl_invite(wpa_s
, buf
+ 11) < 0)
5804 } else if (os_strncmp(buf
, "P2P_PEER ", 9) == 0) {
5805 reply_len
= p2p_ctrl_peer(wpa_s
, buf
+ 9, reply
,
5807 } else if (os_strncmp(buf
, "P2P_SET ", 8) == 0) {
5808 if (p2p_ctrl_set(wpa_s
, buf
+ 8) < 0)
5810 } else if (os_strcmp(buf
, "P2P_FLUSH") == 0) {
5811 p2p_ctrl_flush(wpa_s
);
5812 } else if (os_strncmp(buf
, "P2P_UNAUTHORIZE ", 16) == 0) {
5813 if (wpas_p2p_unauthorize(wpa_s
, buf
+ 16) < 0)
5815 } else if (os_strcmp(buf
, "P2P_CANCEL") == 0) {
5816 if (wpas_p2p_cancel(wpa_s
))
5818 } else if (os_strncmp(buf
, "P2P_PRESENCE_REQ ", 17) == 0) {
5819 if (p2p_ctrl_presence_req(wpa_s
, buf
+ 17) < 0)
5821 } else if (os_strcmp(buf
, "P2P_PRESENCE_REQ") == 0) {
5822 if (p2p_ctrl_presence_req(wpa_s
, "") < 0)
5824 } else if (os_strncmp(buf
, "P2P_EXT_LISTEN ", 15) == 0) {
5825 if (p2p_ctrl_ext_listen(wpa_s
, buf
+ 15) < 0)
5827 } else if (os_strcmp(buf
, "P2P_EXT_LISTEN") == 0) {
5828 if (p2p_ctrl_ext_listen(wpa_s
, "") < 0)
5830 } else if (os_strncmp(buf
, "P2P_REMOVE_CLIENT ", 18) == 0) {
5831 if (p2p_ctrl_remove_client(wpa_s
, buf
+ 18) < 0)
5833 #endif /* CONFIG_P2P */
5834 #ifdef CONFIG_WIFI_DISPLAY
5835 } else if (os_strncmp(buf
, "WFD_SUBELEM_SET ", 16) == 0) {
5836 if (wifi_display_subelem_set(wpa_s
->global
, buf
+ 16) < 0)
5838 } else if (os_strncmp(buf
, "WFD_SUBELEM_GET ", 16) == 0) {
5839 reply_len
= wifi_display_subelem_get(wpa_s
->global
, buf
+ 16,
5841 #endif /* CONFIG_WIFI_DISPLAY */
5842 #ifdef CONFIG_INTERWORKING
5843 } else if (os_strcmp(buf
, "FETCH_ANQP") == 0) {
5844 if (interworking_fetch_anqp(wpa_s
) < 0)
5846 } else if (os_strcmp(buf
, "STOP_FETCH_ANQP") == 0) {
5847 interworking_stop_fetch_anqp(wpa_s
);
5848 } else if (os_strncmp(buf
, "INTERWORKING_SELECT", 19) == 0) {
5849 if (interworking_select(wpa_s
, os_strstr(buf
+ 19, "auto") !=
5852 } else if (os_strncmp(buf
, "INTERWORKING_CONNECT ", 21) == 0) {
5853 if (ctrl_interworking_connect(wpa_s
, buf
+ 21) < 0)
5855 } else if (os_strncmp(buf
, "ANQP_GET ", 9) == 0) {
5856 if (get_anqp(wpa_s
, buf
+ 9) < 0)
5858 } else if (os_strncmp(buf
, "GAS_REQUEST ", 12) == 0) {
5859 if (gas_request(wpa_s
, buf
+ 12) < 0)
5861 } else if (os_strncmp(buf
, "GAS_RESPONSE_GET ", 17) == 0) {
5862 reply_len
= gas_response_get(wpa_s
, buf
+ 17, reply
,
5864 #endif /* CONFIG_INTERWORKING */
5866 } else if (os_strncmp(buf
, "HS20_ANQP_GET ", 14) == 0) {
5867 if (get_hs20_anqp(wpa_s
, buf
+ 14) < 0)
5869 } else if (os_strncmp(buf
, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
5870 if (hs20_get_nai_home_realm_list(wpa_s
, buf
+ 29) < 0)
5872 #endif /* CONFIG_HS20 */
5873 } else if (os_strncmp(buf
, WPA_CTRL_RSP
, os_strlen(WPA_CTRL_RSP
)) == 0)
5875 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
5876 wpa_s
, buf
+ os_strlen(WPA_CTRL_RSP
)))
5880 * Notify response from timeout to allow the control
5881 * interface response to be sent first.
5883 eloop_register_timeout(0, 0, wpas_ctrl_eapol_response
,
5886 } else if (os_strcmp(buf
, "RECONFIGURE") == 0) {
5887 if (wpa_supplicant_reload_configuration(wpa_s
))
5889 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
5890 wpa_supplicant_terminate_proc(wpa_s
->global
);
5891 } else if (os_strncmp(buf
, "BSSID ", 6) == 0) {
5892 if (wpa_supplicant_ctrl_iface_bssid(wpa_s
, buf
+ 6))
5894 } else if (os_strncmp(buf
, "BLACKLIST", 9) == 0) {
5895 reply_len
= wpa_supplicant_ctrl_iface_blacklist(
5896 wpa_s
, buf
+ 9, reply
, reply_size
);
5897 } else if (os_strncmp(buf
, "LOG_LEVEL", 9) == 0) {
5898 reply_len
= wpa_supplicant_ctrl_iface_log_level(
5899 wpa_s
, buf
+ 9, reply
, reply_size
);
5900 } else if (os_strcmp(buf
, "LIST_NETWORKS") == 0) {
5901 reply_len
= wpa_supplicant_ctrl_iface_list_networks(
5902 wpa_s
, reply
, reply_size
);
5903 } else if (os_strcmp(buf
, "DISCONNECT") == 0) {
5905 wpa_s
->sme
.prev_bssid_set
= 0;
5906 #endif /* CONFIG_SME */
5907 wpa_s
->reassociate
= 0;
5908 wpa_s
->disconnected
= 1;
5909 wpa_supplicant_cancel_sched_scan(wpa_s
);
5910 wpa_supplicant_cancel_scan(wpa_s
);
5911 wpa_supplicant_deauthenticate(wpa_s
,
5912 WLAN_REASON_DEAUTH_LEAVING
);
5913 } else if (os_strcmp(buf
, "SCAN") == 0) {
5914 wpas_ctrl_scan(wpa_s
, NULL
, reply
, reply_size
, &reply_len
);
5915 } else if (os_strncmp(buf
, "SCAN ", 5) == 0) {
5916 wpas_ctrl_scan(wpa_s
, buf
+ 5, reply
, reply_size
, &reply_len
);
5917 } else if (os_strcmp(buf
, "SCAN_RESULTS") == 0) {
5918 reply_len
= wpa_supplicant_ctrl_iface_scan_results(
5919 wpa_s
, reply
, reply_size
);
5920 } else if (os_strncmp(buf
, "SELECT_NETWORK ", 15) == 0) {
5921 if (wpa_supplicant_ctrl_iface_select_network(wpa_s
, buf
+ 15))
5923 } else if (os_strncmp(buf
, "ENABLE_NETWORK ", 15) == 0) {
5924 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s
, buf
+ 15))
5926 } else if (os_strncmp(buf
, "DISABLE_NETWORK ", 16) == 0) {
5927 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s
, buf
+ 16))
5929 } else if (os_strcmp(buf
, "ADD_NETWORK") == 0) {
5930 reply_len
= wpa_supplicant_ctrl_iface_add_network(
5931 wpa_s
, reply
, reply_size
);
5932 } else if (os_strncmp(buf
, "REMOVE_NETWORK ", 15) == 0) {
5933 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s
, buf
+ 15))
5935 } else if (os_strncmp(buf
, "SET_NETWORK ", 12) == 0) {
5936 if (wpa_supplicant_ctrl_iface_set_network(wpa_s
, buf
+ 12))
5938 } else if (os_strncmp(buf
, "GET_NETWORK ", 12) == 0) {
5939 reply_len
= wpa_supplicant_ctrl_iface_get_network(
5940 wpa_s
, buf
+ 12, reply
, reply_size
);
5941 } else if (os_strcmp(buf
, "LIST_CREDS") == 0) {
5942 reply_len
= wpa_supplicant_ctrl_iface_list_creds(
5943 wpa_s
, reply
, reply_size
);
5944 } else if (os_strcmp(buf
, "ADD_CRED") == 0) {
5945 reply_len
= wpa_supplicant_ctrl_iface_add_cred(
5946 wpa_s
, reply
, reply_size
);
5947 } else if (os_strncmp(buf
, "REMOVE_CRED ", 12) == 0) {
5948 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s
, buf
+ 12))
5950 } else if (os_strncmp(buf
, "SET_CRED ", 9) == 0) {
5951 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s
, buf
+ 9))
5953 #ifndef CONFIG_NO_CONFIG_WRITE
5954 } else if (os_strcmp(buf
, "SAVE_CONFIG") == 0) {
5955 if (wpa_supplicant_ctrl_iface_save_config(wpa_s
))
5957 #endif /* CONFIG_NO_CONFIG_WRITE */
5958 } else if (os_strncmp(buf
, "GET_CAPABILITY ", 15) == 0) {
5959 reply_len
= wpa_supplicant_ctrl_iface_get_capability(
5960 wpa_s
, buf
+ 15, reply
, reply_size
);
5961 } else if (os_strncmp(buf
, "AP_SCAN ", 8) == 0) {
5962 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s
, buf
+ 8))
5964 } else if (os_strncmp(buf
, "SCAN_INTERVAL ", 14) == 0) {
5965 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s
, buf
+ 14))
5967 } else if (os_strcmp(buf
, "INTERFACE_LIST") == 0) {
5968 reply_len
= wpa_supplicant_global_iface_list(
5969 wpa_s
->global
, reply
, reply_size
);
5970 } else if (os_strcmp(buf
, "INTERFACES") == 0) {
5971 reply_len
= wpa_supplicant_global_iface_interfaces(
5972 wpa_s
->global
, reply
, reply_size
);
5973 } else if (os_strncmp(buf
, "BSS ", 4) == 0) {
5974 reply_len
= wpa_supplicant_ctrl_iface_bss(
5975 wpa_s
, buf
+ 4, reply
, reply_size
);
5977 } else if (os_strcmp(buf
, "STA-FIRST") == 0) {
5978 reply_len
= ap_ctrl_iface_sta_first(wpa_s
, reply
, reply_size
);
5979 } else if (os_strncmp(buf
, "STA ", 4) == 0) {
5980 reply_len
= ap_ctrl_iface_sta(wpa_s
, buf
+ 4, reply
,
5982 } else if (os_strncmp(buf
, "STA-NEXT ", 9) == 0) {
5983 reply_len
= ap_ctrl_iface_sta_next(wpa_s
, buf
+ 9, reply
,
5985 } else if (os_strncmp(buf
, "DEAUTHENTICATE ", 15) == 0) {
5986 if (ap_ctrl_iface_sta_deauthenticate(wpa_s
, buf
+ 15))
5988 } else if (os_strncmp(buf
, "DISASSOCIATE ", 13) == 0) {
5989 if (ap_ctrl_iface_sta_disassociate(wpa_s
, buf
+ 13))
5991 } else if (os_strncmp(buf
, "CHAN_SWITCH ", 12) == 0) {
5992 if (ap_ctrl_iface_chanswitch(wpa_s
, buf
+ 12))
5994 #endif /* CONFIG_AP */
5995 } else if (os_strcmp(buf
, "SUSPEND") == 0) {
5996 wpas_notify_suspend(wpa_s
->global
);
5997 } else if (os_strcmp(buf
, "RESUME") == 0) {
5998 wpas_notify_resume(wpa_s
->global
);
5999 } else if (os_strcmp(buf
, "DROP_SA") == 0) {
6000 wpa_supplicant_ctrl_iface_drop_sa(wpa_s
);
6001 } else if (os_strncmp(buf
, "ROAM ", 5) == 0) {
6002 if (wpa_supplicant_ctrl_iface_roam(wpa_s
, buf
+ 5))
6004 } else if (os_strncmp(buf
, "STA_AUTOCONNECT ", 16) == 0) {
6005 if (wpa_supplicant_ctrl_iface_sta_autoconnect(wpa_s
, buf
+ 16))
6007 } else if (os_strncmp(buf
, "BSS_EXPIRE_AGE ", 15) == 0) {
6008 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s
, buf
+ 15))
6010 } else if (os_strncmp(buf
, "BSS_EXPIRE_COUNT ", 17) == 0) {
6011 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s
,
6014 } else if (os_strncmp(buf
, "BSS_FLUSH ", 10) == 0) {
6015 if (wpa_supplicant_ctrl_iface_bss_flush(wpa_s
, buf
+ 10))
6018 } else if (os_strncmp(buf
, "TDLS_DISCOVER ", 14) == 0) {
6019 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s
, buf
+ 14))
6021 } else if (os_strncmp(buf
, "TDLS_SETUP ", 11) == 0) {
6022 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s
, buf
+ 11))
6024 } else if (os_strncmp(buf
, "TDLS_TEARDOWN ", 14) == 0) {
6025 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s
, buf
+ 14))
6027 #endif /* CONFIG_TDLS */
6028 } else if (os_strncmp(buf
, "SIGNAL_POLL", 11) == 0) {
6029 reply_len
= wpa_supplicant_signal_poll(wpa_s
, reply
,
6031 } else if (os_strncmp(buf
, "PKTCNT_POLL", 11) == 0) {
6032 reply_len
= wpa_supplicant_pktcnt_poll(wpa_s
, reply
,
6034 #ifdef CONFIG_AUTOSCAN
6035 } else if (os_strncmp(buf
, "AUTOSCAN ", 9) == 0) {
6036 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s
, buf
+ 9))
6038 #endif /* CONFIG_AUTOSCAN */
6040 } else if (os_strncmp(buf
, "DRIVER ", 7) == 0) {
6041 reply_len
= wpa_supplicant_driver_cmd(wpa_s
, buf
+ 7, reply
,
6043 #endif /* ANDROID */
6044 } else if (os_strcmp(buf
, "REAUTHENTICATE") == 0) {
6045 pmksa_cache_clear_current(wpa_s
->wpa
);
6046 eapol_sm_request_reauth(wpa_s
->eapol
);
6048 } else if (os_strncmp(buf
, "WNM_SLEEP ", 10) == 0) {
6049 if (wpas_ctrl_iface_wnm_sleep(wpa_s
, buf
+ 10))
6051 } else if (os_strncmp(buf
, "WNM_BSS_QUERY ", 10) == 0) {
6052 if (wpas_ctrl_iface_wnm_bss_query(wpa_s
, buf
+ 10))
6054 #endif /* CONFIG_WNM */
6055 } else if (os_strcmp(buf
, "FLUSH") == 0) {
6056 wpa_supplicant_ctrl_iface_flush(wpa_s
);
6057 } else if (os_strncmp(buf
, "RADIO_WORK ", 11) == 0) {
6058 reply_len
= wpas_ctrl_radio_work(wpa_s
, buf
+ 11, reply
,
6061 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
6065 if (reply_len
< 0) {
6066 os_memcpy(reply
, "FAIL\n", 5);
6070 *resp_len
= reply_len
;
6075 static int wpa_supplicant_global_iface_add(struct wpa_global
*global
,
6078 struct wpa_interface iface
;
6082 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
6083 * TAB<bridge_ifname>
6085 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd
);
6087 os_memset(&iface
, 0, sizeof(iface
));
6090 iface
.ifname
= pos
= cmd
;
6091 pos
= os_strchr(pos
, '\t');
6094 if (iface
.ifname
[0] == '\0')
6099 iface
.confname
= pos
;
6100 pos
= os_strchr(pos
, '\t');
6103 if (iface
.confname
[0] == '\0')
6104 iface
.confname
= NULL
;
6109 pos
= os_strchr(pos
, '\t');
6112 if (iface
.driver
[0] == '\0')
6113 iface
.driver
= NULL
;
6117 iface
.ctrl_interface
= pos
;
6118 pos
= os_strchr(pos
, '\t');
6121 if (iface
.ctrl_interface
[0] == '\0')
6122 iface
.ctrl_interface
= NULL
;
6126 iface
.driver_param
= pos
;
6127 pos
= os_strchr(pos
, '\t');
6130 if (iface
.driver_param
[0] == '\0')
6131 iface
.driver_param
= NULL
;
6135 iface
.bridge_ifname
= pos
;
6136 pos
= os_strchr(pos
, '\t');
6139 if (iface
.bridge_ifname
[0] == '\0')
6140 iface
.bridge_ifname
= NULL
;
6145 if (wpa_supplicant_get_iface(global
, iface
.ifname
))
6148 return wpa_supplicant_add_iface(global
, &iface
) ? 0 : -1;
6152 static int wpa_supplicant_global_iface_remove(struct wpa_global
*global
,
6155 struct wpa_supplicant
*wpa_s
;
6157 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd
);
6159 wpa_s
= wpa_supplicant_get_iface(global
, cmd
);
6162 return wpa_supplicant_remove_iface(global
, wpa_s
, 0);
6166 static void wpa_free_iface_info(struct wpa_interface_info
*iface
)
6168 struct wpa_interface_info
*prev
;
6172 iface
= iface
->next
;
6174 os_free(prev
->ifname
);
6175 os_free(prev
->desc
);
6181 static int wpa_supplicant_global_iface_list(struct wpa_global
*global
,
6185 struct wpa_interface_info
*iface
= NULL
, *last
= NULL
, *tmp
;
6188 for (i
= 0; wpa_drivers
[i
]; i
++) {
6189 struct wpa_driver_ops
*drv
= wpa_drivers
[i
];
6190 if (drv
->get_interfaces
== NULL
)
6192 tmp
= drv
->get_interfaces(global
->drv_priv
[i
]);
6206 for (tmp
= iface
; tmp
; tmp
= tmp
->next
) {
6207 res
= os_snprintf(pos
, end
- pos
, "%s\t%s\t%s\n",
6208 tmp
->drv_name
, tmp
->ifname
,
6209 tmp
->desc
? tmp
->desc
: "");
6210 if (res
< 0 || res
>= end
- pos
) {
6217 wpa_free_iface_info(iface
);
6223 static int wpa_supplicant_global_iface_interfaces(struct wpa_global
*global
,
6228 struct wpa_supplicant
*wpa_s
;
6230 wpa_s
= global
->ifaces
;
6235 res
= os_snprintf(pos
, end
- pos
, "%s\n", wpa_s
->ifname
);
6236 if (res
< 0 || res
>= end
- pos
) {
6241 wpa_s
= wpa_s
->next
;
6247 static char * wpas_global_ctrl_iface_ifname(struct wpa_global
*global
,
6249 char *cmd
, size_t *resp_len
)
6251 struct wpa_supplicant
*wpa_s
;
6253 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
6254 if (os_strcmp(ifname
, wpa_s
->ifname
) == 0)
6258 if (wpa_s
== NULL
) {
6259 char *resp
= os_strdup("FAIL-NO-IFNAME-MATCH\n");
6261 *resp_len
= os_strlen(resp
);
6267 return wpa_supplicant_ctrl_iface_process(wpa_s
, cmd
, resp_len
);
6271 static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global
*global
,
6272 char *buf
, size_t *resp_len
)
6275 static const char * cmd
[] = {
6280 "P2P_GET_PASSPHRASE",
6281 "P2P_SERVICE_UPDATE",
6282 "P2P_SERVICE_FLUSH",
6289 static const char * prefix
[] = {
6293 "P2P_GROUP_REMOVE ",
6296 "P2P_SERV_DISC_REQ ",
6297 "P2P_SERV_DISC_CANCEL_REQ ",
6298 "P2P_SERV_DISC_RESP ",
6299 "P2P_SERV_DISC_EXTERNAL ",
6307 "P2P_PRESENCE_REQ ",
6309 "P2P_REMOVE_CLIENT ",
6315 if (global
->p2p_init_wpa_s
== NULL
)
6318 for (i
= 0; !found
&& cmd
[i
]; i
++) {
6319 if (os_strcmp(buf
, cmd
[i
]) == 0)
6323 for (i
= 0; !found
&& prefix
[i
]; i
++) {
6324 if (os_strncmp(buf
, prefix
[i
], os_strlen(prefix
[i
])) == 0)
6329 return wpa_supplicant_ctrl_iface_process(global
->p2p_init_wpa_s
,
6331 #endif /* CONFIG_P2P */
6336 static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global
*global
,
6337 char *buf
, size_t *resp_len
)
6339 #ifdef CONFIG_WIFI_DISPLAY
6340 if (global
->p2p_init_wpa_s
== NULL
)
6342 if (os_strncmp(buf
, "WFD_SUBELEM_SET ", 16) == 0 ||
6343 os_strncmp(buf
, "WFD_SUBELEM_GET ", 16) == 0)
6344 return wpa_supplicant_ctrl_iface_process(global
->p2p_init_wpa_s
,
6346 #endif /* CONFIG_WIFI_DISPLAY */
6351 static char * wpas_global_ctrl_iface_redir(struct wpa_global
*global
,
6352 char *buf
, size_t *resp_len
)
6356 ret
= wpas_global_ctrl_iface_redir_p2p(global
, buf
, resp_len
);
6360 ret
= wpas_global_ctrl_iface_redir_wfd(global
, buf
, resp_len
);
6368 static int wpas_global_ctrl_iface_set(struct wpa_global
*global
, char *cmd
)
6372 value
= os_strchr(cmd
, ' ');
6377 wpa_printf(MSG_DEBUG
, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd
, value
);
6379 #ifdef CONFIG_WIFI_DISPLAY
6380 if (os_strcasecmp(cmd
, "wifi_display") == 0) {
6381 wifi_display_enable(global
, !!atoi(value
));
6384 #endif /* CONFIG_WIFI_DISPLAY */
6390 #ifndef CONFIG_NO_CONFIG_WRITE
6391 static int wpas_global_ctrl_iface_save_config(struct wpa_global
*global
)
6394 struct wpa_supplicant
*wpa_s
;
6396 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
6397 if (!wpa_s
->conf
->update_config
) {
6398 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
6402 if (wpa_config_write(wpa_s
->confname
, wpa_s
->conf
)) {
6403 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
6406 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
6412 #endif /* CONFIG_NO_CONFIG_WRITE */
6415 static int wpas_global_ctrl_iface_status(struct wpa_global
*global
,
6416 char *buf
, size_t buflen
)
6420 struct wpa_supplicant
*wpa_s
;
6426 if (global
->p2p
&& !global
->p2p_disabled
) {
6427 ret
= os_snprintf(pos
, end
- pos
, "p2p_device_address=" MACSTR
6430 MAC2STR(global
->p2p_dev_addr
),
6431 p2p_get_state_txt(global
->p2p
));
6432 if (ret
< 0 || ret
>= end
- pos
)
6435 } else if (global
->p2p
) {
6436 ret
= os_snprintf(pos
, end
- pos
, "p2p_state=DISABLED\n");
6437 if (ret
< 0 || ret
>= end
- pos
)
6441 #endif /* CONFIG_P2P */
6443 #ifdef CONFIG_WIFI_DISPLAY
6444 ret
= os_snprintf(pos
, end
- pos
, "wifi_display=%d\n",
6445 !!global
->wifi_display
);
6446 if (ret
< 0 || ret
>= end
- pos
)
6449 #endif /* CONFIG_WIFI_DISPLAY */
6451 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
6452 ret
= os_snprintf(pos
, end
- pos
, "ifname=%s\n"
6453 "address=" MACSTR
"\n",
6454 wpa_s
->ifname
, MAC2STR(wpa_s
->own_addr
));
6455 if (ret
< 0 || ret
>= end
- pos
)
6464 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global
*global
,
6465 char *buf
, size_t *resp_len
)
6468 const int reply_size
= 2048;
6470 int level
= MSG_DEBUG
;
6472 if (os_strncmp(buf
, "IFNAME=", 7) == 0) {
6473 char *pos
= os_strchr(buf
+ 7, ' ');
6476 return wpas_global_ctrl_iface_ifname(global
,
6482 reply
= wpas_global_ctrl_iface_redir(global
, buf
, resp_len
);
6486 if (os_strcmp(buf
, "PING") == 0)
6487 level
= MSG_EXCESSIVE
;
6488 wpa_hexdump_ascii(level
, "RX global ctrl_iface",
6489 (const u8
*) buf
, os_strlen(buf
));
6491 reply
= os_malloc(reply_size
);
6492 if (reply
== NULL
) {
6497 os_memcpy(reply
, "OK\n", 3);
6500 if (os_strcmp(buf
, "PING") == 0) {
6501 os_memcpy(reply
, "PONG\n", 5);
6503 } else if (os_strncmp(buf
, "INTERFACE_ADD ", 14) == 0) {
6504 if (wpa_supplicant_global_iface_add(global
, buf
+ 14))
6506 } else if (os_strncmp(buf
, "INTERFACE_REMOVE ", 17) == 0) {
6507 if (wpa_supplicant_global_iface_remove(global
, buf
+ 17))
6509 } else if (os_strcmp(buf
, "INTERFACE_LIST") == 0) {
6510 reply_len
= wpa_supplicant_global_iface_list(
6511 global
, reply
, reply_size
);
6512 } else if (os_strcmp(buf
, "INTERFACES") == 0) {
6513 reply_len
= wpa_supplicant_global_iface_interfaces(
6514 global
, reply
, reply_size
);
6515 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
6516 wpa_supplicant_terminate_proc(global
);
6517 } else if (os_strcmp(buf
, "SUSPEND") == 0) {
6518 wpas_notify_suspend(global
);
6519 } else if (os_strcmp(buf
, "RESUME") == 0) {
6520 wpas_notify_resume(global
);
6521 } else if (os_strncmp(buf
, "SET ", 4) == 0) {
6522 if (wpas_global_ctrl_iface_set(global
, buf
+ 4))
6524 #ifndef CONFIG_NO_CONFIG_WRITE
6525 } else if (os_strcmp(buf
, "SAVE_CONFIG") == 0) {
6526 if (wpas_global_ctrl_iface_save_config(global
))
6528 #endif /* CONFIG_NO_CONFIG_WRITE */
6529 } else if (os_strcmp(buf
, "STATUS") == 0) {
6530 reply_len
= wpas_global_ctrl_iface_status(global
, reply
,
6533 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
6537 if (reply_len
< 0) {
6538 os_memcpy(reply
, "FAIL\n", 5);
6542 *resp_len
= reply_len
;