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"
43 #include "offchannel.h"
45 static int wpa_supplicant_global_iface_list(struct wpa_global
*global
,
47 static int wpa_supplicant_global_iface_interfaces(struct wpa_global
*global
,
49 static int * freq_range_to_channel_list(struct wpa_supplicant
*wpa_s
,
52 static int set_bssid_filter(struct wpa_supplicant
*wpa_s
, char *val
)
55 u8 addr
[ETH_ALEN
], *filter
= NULL
, *n
;
62 if (hwaddr_aton(pos
, addr
)) {
66 n
= os_realloc_array(filter
, count
+ 1, ETH_ALEN
);
72 os_memcpy(filter
+ count
* ETH_ALEN
, addr
, ETH_ALEN
);
75 pos
= os_strchr(pos
, ' ');
80 wpa_hexdump(MSG_DEBUG
, "bssid_filter", filter
, count
* ETH_ALEN
);
81 os_free(wpa_s
->bssid_filter
);
82 wpa_s
->bssid_filter
= filter
;
83 wpa_s
->bssid_filter_count
= count
;
89 static int set_disallow_aps(struct wpa_supplicant
*wpa_s
, char *val
)
92 u8 addr
[ETH_ALEN
], *bssid
= NULL
, *n
;
93 struct wpa_ssid_value
*ssid
= NULL
, *ns
;
94 size_t count
= 0, ssid_count
= 0;
98 * disallow_list ::= <ssid_spec> | <bssid_spec> | <disallow_list> | ""
99 * SSID_SPEC ::= ssid <SSID_HEX>
100 * BSSID_SPEC ::= bssid <BSSID_HEX>
107 if (os_strncmp(pos
, "bssid ", 6) == 0) {
110 res
= hwaddr_aton2(pos
, addr
);
114 wpa_printf(MSG_DEBUG
, "Invalid disallow_aps "
115 "BSSID value '%s'", pos
);
119 n
= os_realloc_array(bssid
, count
+ 1, ETH_ALEN
);
126 os_memcpy(bssid
+ count
* ETH_ALEN
, addr
, ETH_ALEN
);
128 } else if (os_strncmp(pos
, "ssid ", 5) == 0) {
134 if (*end
== '\0' || *end
== ' ')
139 ns
= os_realloc_array(ssid
, ssid_count
+ 1,
140 sizeof(struct wpa_ssid_value
));
148 if ((end
- pos
) & 0x01 || end
- pos
> 2 * 32 ||
149 hexstr2bin(pos
, ssid
[ssid_count
].ssid
,
150 (end
- pos
) / 2) < 0) {
153 wpa_printf(MSG_DEBUG
, "Invalid disallow_aps "
154 "SSID value '%s'", pos
);
157 ssid
[ssid_count
].ssid_len
= (end
- pos
) / 2;
158 wpa_hexdump_ascii(MSG_DEBUG
, "disallow_aps SSID",
159 ssid
[ssid_count
].ssid
,
160 ssid
[ssid_count
].ssid_len
);
164 wpa_printf(MSG_DEBUG
, "Unexpected disallow_aps value "
171 pos
= os_strchr(pos
, ' ');
176 wpa_hexdump(MSG_DEBUG
, "disallow_aps_bssid", bssid
, count
* ETH_ALEN
);
177 os_free(wpa_s
->disallow_aps_bssid
);
178 wpa_s
->disallow_aps_bssid
= bssid
;
179 wpa_s
->disallow_aps_bssid_count
= count
;
181 wpa_printf(MSG_DEBUG
, "disallow_aps_ssid_count %d", (int) ssid_count
);
182 os_free(wpa_s
->disallow_aps_ssid
);
183 wpa_s
->disallow_aps_ssid
= ssid
;
184 wpa_s
->disallow_aps_ssid_count
= ssid_count
;
186 if (!wpa_s
->current_ssid
|| wpa_s
->wpa_state
< WPA_AUTHENTICATING
)
189 c
= wpa_s
->current_ssid
;
190 if (c
->mode
!= WPAS_MODE_INFRA
&& c
->mode
!= WPAS_MODE_IBSS
)
193 if (!disallowed_bssid(wpa_s
, wpa_s
->bssid
) &&
194 !disallowed_ssid(wpa_s
, c
->ssid
, c
->ssid_len
))
197 wpa_printf(MSG_DEBUG
, "Disconnect and try to find another network "
198 "because current AP was marked disallowed");
201 wpa_s
->sme
.prev_bssid_set
= 0;
202 #endif /* CONFIG_SME */
203 wpa_s
->reassociate
= 1;
204 wpa_supplicant_deauthenticate(wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
205 wpa_supplicant_req_scan(wpa_s
, 0, 0);
211 #ifndef CONFIG_NO_CONFIG_BLOBS
212 static int wpas_ctrl_set_blob(struct wpa_supplicant
*wpa_s
, char *pos
)
215 struct wpa_config_blob
*blob
;
218 pos
= os_strchr(pos
, ' ');
222 len
= os_strlen(pos
);
226 wpa_printf(MSG_DEBUG
, "CTRL: Set blob '%s'", name
);
227 blob
= os_zalloc(sizeof(*blob
));
230 blob
->name
= os_strdup(name
);
231 blob
->data
= os_malloc(len
/ 2);
232 if (blob
->name
== NULL
|| blob
->data
== NULL
) {
233 wpa_config_free_blob(blob
);
237 if (hexstr2bin(pos
, blob
->data
, len
/ 2) < 0) {
238 wpa_printf(MSG_DEBUG
, "CTRL: Invalid blob hex data");
239 wpa_config_free_blob(blob
);
244 wpa_config_set_blob(wpa_s
->conf
, blob
);
248 #endif /* CONFIG_NO_CONFIG_BLOBS */
251 static int wpas_ctrl_pno(struct wpa_supplicant
*wpa_s
, char *cmd
)
259 params
= os_strchr(cmd
, ' ');
260 os_free(wpa_s
->manual_sched_scan_freqs
);
263 pos
= os_strstr(params
, "freq=");
265 freqs
= freq_range_to_channel_list(wpa_s
,
268 wpa_s
->manual_sched_scan_freqs
= freqs
;
269 ret
= wpas_start_pno(wpa_s
);
271 ret
= wpas_stop_pno(wpa_s
);
277 static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant
*wpa_s
,
283 value
= os_strchr(cmd
, ' ');
288 wpa_printf(MSG_DEBUG
, "CTRL_IFACE SET '%s'='%s'", cmd
, value
);
289 if (os_strcasecmp(cmd
, "EAPOL::heldPeriod") == 0) {
290 eapol_sm_configure(wpa_s
->eapol
,
291 atoi(value
), -1, -1, -1);
292 } else if (os_strcasecmp(cmd
, "EAPOL::authPeriod") == 0) {
293 eapol_sm_configure(wpa_s
->eapol
,
294 -1, atoi(value
), -1, -1);
295 } else if (os_strcasecmp(cmd
, "EAPOL::startPeriod") == 0) {
296 eapol_sm_configure(wpa_s
->eapol
,
297 -1, -1, atoi(value
), -1);
298 } else if (os_strcasecmp(cmd
, "EAPOL::maxStart") == 0) {
299 eapol_sm_configure(wpa_s
->eapol
,
300 -1, -1, -1, atoi(value
));
301 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigPMKLifetime") == 0) {
302 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_LIFETIME
,
305 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigPMKReauthThreshold") ==
307 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_REAUTH_THRESHOLD
,
310 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigSATimeout") == 0) {
311 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_SA_TIMEOUT
, atoi(value
)))
313 } else if (os_strcasecmp(cmd
, "wps_fragment_size") == 0) {
314 wpa_s
->wps_fragment_size
= atoi(value
);
315 #ifdef CONFIG_WPS_TESTING
316 } else if (os_strcasecmp(cmd
, "wps_version_number") == 0) {
318 val
= strtol(value
, NULL
, 0);
319 if (val
< 0 || val
> 0xff) {
321 wpa_printf(MSG_DEBUG
, "WPS: Invalid "
322 "wps_version_number %ld", val
);
324 wps_version_number
= val
;
325 wpa_printf(MSG_DEBUG
, "WPS: Testing - force WPS "
327 (wps_version_number
& 0xf0) >> 4,
328 wps_version_number
& 0x0f);
330 } else if (os_strcasecmp(cmd
, "wps_testing_dummy_cred") == 0) {
331 wps_testing_dummy_cred
= atoi(value
);
332 wpa_printf(MSG_DEBUG
, "WPS: Testing - dummy_cred=%d",
333 wps_testing_dummy_cred
);
334 } else if (os_strcasecmp(cmd
, "wps_corrupt_pkhash") == 0) {
335 wps_corrupt_pkhash
= atoi(value
);
336 wpa_printf(MSG_DEBUG
, "WPS: Testing - wps_corrupt_pkhash=%d",
338 #endif /* CONFIG_WPS_TESTING */
339 } else if (os_strcasecmp(cmd
, "ampdu") == 0) {
340 if (wpa_drv_ampdu(wpa_s
, atoi(value
)) < 0)
343 #ifdef CONFIG_TDLS_TESTING
344 } else if (os_strcasecmp(cmd
, "tdls_testing") == 0) {
345 extern unsigned int tdls_testing
;
346 tdls_testing
= strtol(value
, NULL
, 0);
347 wpa_printf(MSG_DEBUG
, "TDLS: tdls_testing=0x%x", tdls_testing
);
348 #endif /* CONFIG_TDLS_TESTING */
349 } else if (os_strcasecmp(cmd
, "tdls_disabled") == 0) {
350 int disabled
= atoi(value
);
351 wpa_printf(MSG_DEBUG
, "TDLS: tdls_disabled=%d", disabled
);
353 if (wpa_drv_tdls_oper(wpa_s
, TDLS_DISABLE
, NULL
) < 0)
355 } else if (wpa_drv_tdls_oper(wpa_s
, TDLS_ENABLE
, NULL
) < 0)
357 wpa_tdls_enable(wpa_s
->wpa
, !disabled
);
358 #endif /* CONFIG_TDLS */
359 } else if (os_strcasecmp(cmd
, "pno") == 0) {
360 ret
= wpas_ctrl_pno(wpa_s
, value
);
361 } else if (os_strcasecmp(cmd
, "radio_disabled") == 0) {
362 int disabled
= atoi(value
);
363 if (wpa_drv_radio_disable(wpa_s
, disabled
) < 0)
366 wpa_supplicant_set_state(wpa_s
, WPA_INACTIVE
);
367 } else if (os_strcasecmp(cmd
, "uapsd") == 0) {
368 if (os_strcmp(value
, "disable") == 0)
369 wpa_s
->set_sta_uapsd
= 0;
373 /* format: BE,BK,VI,VO;max SP Length */
375 pos
= os_strchr(value
, ',');
380 pos
= os_strchr(pos
, ',');
385 pos
= os_strchr(pos
, ',');
390 /* ignore max SP Length for now */
392 wpa_s
->set_sta_uapsd
= 1;
393 wpa_s
->sta_uapsd
= 0;
395 wpa_s
->sta_uapsd
|= BIT(0);
397 wpa_s
->sta_uapsd
|= BIT(1);
399 wpa_s
->sta_uapsd
|= BIT(2);
401 wpa_s
->sta_uapsd
|= BIT(3);
403 } else if (os_strcasecmp(cmd
, "ps") == 0) {
404 ret
= wpa_drv_set_p2p_powersave(wpa_s
, atoi(value
), -1, -1);
405 #ifdef CONFIG_WIFI_DISPLAY
406 } else if (os_strcasecmp(cmd
, "wifi_display") == 0) {
407 int enabled
= !!atoi(value
);
408 if (enabled
&& !wpa_s
->global
->p2p
)
411 wifi_display_enable(wpa_s
->global
, enabled
);
412 #endif /* CONFIG_WIFI_DISPLAY */
413 } else if (os_strcasecmp(cmd
, "bssid_filter") == 0) {
414 ret
= set_bssid_filter(wpa_s
, value
);
415 } else if (os_strcasecmp(cmd
, "disallow_aps") == 0) {
416 ret
= set_disallow_aps(wpa_s
, value
);
417 } else if (os_strcasecmp(cmd
, "no_keep_alive") == 0) {
418 wpa_s
->no_keep_alive
= !!atoi(value
);
419 #ifdef CONFIG_TESTING_OPTIONS
420 } else if (os_strcasecmp(cmd
, "ext_mgmt_frame_handling") == 0) {
421 wpa_s
->ext_mgmt_frame_handling
= !!atoi(value
);
422 #endif /* CONFIG_TESTING_OPTIONS */
423 #ifndef CONFIG_NO_CONFIG_BLOBS
424 } else if (os_strcmp(cmd
, "blob") == 0) {
425 ret
= wpas_ctrl_set_blob(wpa_s
, value
);
426 #endif /* CONFIG_NO_CONFIG_BLOBS */
429 ret
= wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
431 wpa_supplicant_update_config(wpa_s
);
438 static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant
*wpa_s
,
439 char *cmd
, char *buf
, size_t buflen
)
443 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GET '%s'", cmd
);
445 if (os_strcmp(cmd
, "version") == 0) {
446 res
= os_snprintf(buf
, buflen
, "%s", VERSION_STR
);
447 } else if (os_strcasecmp(cmd
, "country") == 0) {
448 if (wpa_s
->conf
->country
[0] && wpa_s
->conf
->country
[1])
449 res
= os_snprintf(buf
, buflen
, "%c%c",
450 wpa_s
->conf
->country
[0],
451 wpa_s
->conf
->country
[1]);
452 #ifdef CONFIG_WIFI_DISPLAY
453 } else if (os_strcasecmp(cmd
, "wifi_display") == 0) {
455 if (wpa_s
->global
->p2p
== NULL
||
456 wpa_s
->global
->p2p_disabled
)
459 enabled
= wpa_s
->global
->wifi_display
;
460 res
= os_snprintf(buf
, buflen
, "%d", enabled
);
461 if (res
< 0 || (unsigned int) res
>= buflen
)
464 #endif /* CONFIG_WIFI_DISPLAY */
465 #ifdef CONFIG_TESTING_GET_GTK
466 } else if (os_strcmp(cmd
, "gtk") == 0) {
467 if (wpa_s
->last_gtk_len
== 0)
469 res
= wpa_snprintf_hex(buf
, buflen
, wpa_s
->last_gtk
,
470 wpa_s
->last_gtk_len
);
472 #endif /* CONFIG_TESTING_GET_GTK */
475 if (res
< 0 || (unsigned int) res
>= buflen
)
481 #ifdef IEEE8021X_EAPOL
482 static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant
*wpa_s
,
486 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
488 if (hwaddr_aton(addr
, bssid
)) {
489 wpa_printf(MSG_DEBUG
, "CTRL_IFACE PREAUTH: invalid address "
494 wpa_printf(MSG_DEBUG
, "CTRL_IFACE PREAUTH " MACSTR
, MAC2STR(bssid
));
495 rsn_preauth_deinit(wpa_s
->wpa
);
496 if (rsn_preauth_init(wpa_s
->wpa
, bssid
, ssid
? &ssid
->eap
: NULL
))
501 #endif /* IEEE8021X_EAPOL */
504 #ifdef CONFIG_PEERKEY
505 /* MLME-STKSTART.request(peer) */
506 static int wpa_supplicant_ctrl_iface_stkstart(
507 struct wpa_supplicant
*wpa_s
, char *addr
)
511 if (hwaddr_aton(addr
, peer
)) {
512 wpa_printf(MSG_DEBUG
, "CTRL_IFACE STKSTART: invalid "
513 "address '%s'", addr
);
517 wpa_printf(MSG_DEBUG
, "CTRL_IFACE STKSTART " MACSTR
,
520 return wpa_sm_stkstart(wpa_s
->wpa
, peer
);
522 #endif /* CONFIG_PEERKEY */
527 static int wpa_supplicant_ctrl_iface_tdls_discover(
528 struct wpa_supplicant
*wpa_s
, char *addr
)
533 if (hwaddr_aton(addr
, peer
)) {
534 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_DISCOVER: invalid "
535 "address '%s'", addr
);
539 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_DISCOVER " MACSTR
,
542 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
543 ret
= wpa_tdls_send_discovery_request(wpa_s
->wpa
, peer
);
545 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_DISCOVERY_REQ
, peer
);
551 static int wpa_supplicant_ctrl_iface_tdls_setup(
552 struct wpa_supplicant
*wpa_s
, char *addr
)
557 if (hwaddr_aton(addr
, peer
)) {
558 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_SETUP: invalid "
559 "address '%s'", addr
);
563 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_SETUP " MACSTR
,
566 if ((wpa_s
->conf
->tdls_external_control
) &&
567 wpa_tdls_is_external_setup(wpa_s
->wpa
))
568 return wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, peer
);
570 wpa_tdls_remove(wpa_s
->wpa
, peer
);
572 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
573 ret
= wpa_tdls_start(wpa_s
->wpa
, peer
);
575 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, peer
);
581 static int wpa_supplicant_ctrl_iface_tdls_teardown(
582 struct wpa_supplicant
*wpa_s
, char *addr
)
587 if (hwaddr_aton(addr
, peer
)) {
588 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN: invalid "
589 "address '%s'", addr
);
593 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN " MACSTR
,
596 if ((wpa_s
->conf
->tdls_external_control
) &&
597 wpa_tdls_is_external_setup(wpa_s
->wpa
))
598 return wpa_drv_tdls_oper(wpa_s
, TDLS_TEARDOWN
, peer
);
600 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
601 ret
= wpa_tdls_teardown_link(
603 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED
);
605 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_TEARDOWN
, peer
);
611 static int ctrl_iface_get_capability_tdls(
612 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
616 ret
= os_snprintf(buf
, buflen
, "%s\n",
617 wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
?
619 WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP
?
620 "EXTERNAL" : "INTERNAL") : "UNSUPPORTED");
621 if (ret
< 0 || (size_t) ret
> buflen
)
626 #endif /* CONFIG_TDLS */
629 #ifdef CONFIG_IEEE80211R
630 static int wpa_supplicant_ctrl_iface_ft_ds(
631 struct wpa_supplicant
*wpa_s
, char *addr
)
633 u8 target_ap
[ETH_ALEN
];
637 if (hwaddr_aton(addr
, target_ap
)) {
638 wpa_printf(MSG_DEBUG
, "CTRL_IFACE FT_DS: invalid "
639 "address '%s'", addr
);
643 wpa_printf(MSG_DEBUG
, "CTRL_IFACE FT_DS " MACSTR
, MAC2STR(target_ap
));
645 bss
= wpa_bss_get_bssid(wpa_s
, target_ap
);
647 mdie
= wpa_bss_get_ie(bss
, WLAN_EID_MOBILITY_DOMAIN
);
651 return wpa_ft_start_over_ds(wpa_s
->wpa
, target_ap
, mdie
);
653 #endif /* CONFIG_IEEE80211R */
657 static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant
*wpa_s
,
660 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
662 u8 p2p_dev_addr
[ETH_ALEN
];
663 #endif /* CONFIG_P2P */
665 u8
*_p2p_dev_addr
= NULL
;
666 #endif /* CONFIG_AP */
668 if (cmd
== NULL
|| os_strcmp(cmd
, "any") == 0) {
671 } else if (os_strncmp(cmd
, "p2p_dev_addr=", 13) == 0) {
672 if (hwaddr_aton(cmd
+ 13, p2p_dev_addr
)) {
673 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PBC: invalid "
674 "P2P Device Address '%s'",
678 _p2p_dev_addr
= p2p_dev_addr
;
679 #endif /* CONFIG_P2P */
680 } else if (hwaddr_aton(cmd
, bssid
)) {
681 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
688 return wpa_supplicant_ap_wps_pbc(wpa_s
, _bssid
, _p2p_dev_addr
);
689 #endif /* CONFIG_AP */
691 return wpas_wps_start_pbc(wpa_s
, _bssid
, 0);
695 static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant
*wpa_s
,
696 char *cmd
, char *buf
,
699 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
703 pin
= os_strchr(cmd
, ' ');
707 if (os_strcmp(cmd
, "any") == 0)
709 else if (os_strcmp(cmd
, "get") == 0) {
710 ret
= wps_generate_pin();
712 } else if (hwaddr_aton(cmd
, bssid
)) {
713 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
719 if (wpa_s
->ap_iface
) {
724 pos
= os_strchr(pin
, ' ');
731 return wpa_supplicant_ap_wps_pin(wpa_s
, _bssid
, pin
,
732 buf
, buflen
, timeout
);
734 #endif /* CONFIG_AP */
737 ret
= wpas_wps_start_pin(wpa_s
, _bssid
, pin
, 0,
741 ret
= os_snprintf(buf
, buflen
, "%s", pin
);
742 if (ret
< 0 || (size_t) ret
>= buflen
)
747 ret
= wpas_wps_start_pin(wpa_s
, _bssid
, NULL
, 0, DEV_PW_DEFAULT
);
752 /* Return the generated PIN */
753 ret
= os_snprintf(buf
, buflen
, "%08d", ret
);
754 if (ret
< 0 || (size_t) ret
>= buflen
)
760 static int wpa_supplicant_ctrl_iface_wps_check_pin(
761 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
768 wpa_hexdump_ascii_key(MSG_DEBUG
, "WPS_CHECK_PIN",
769 (u8
*) cmd
, os_strlen(cmd
));
770 for (pos
= cmd
, len
= 0; *pos
!= '\0'; pos
++) {
771 if (*pos
< '0' || *pos
> '9')
775 wpa_printf(MSG_DEBUG
, "WPS: Too long PIN");
779 if (len
!= 4 && len
!= 8) {
780 wpa_printf(MSG_DEBUG
, "WPS: Invalid PIN length %d", (int) len
);
786 unsigned int pin_val
;
788 if (!wps_pin_valid(pin_val
)) {
789 wpa_printf(MSG_DEBUG
, "WPS: Invalid checksum digit");
790 ret
= os_snprintf(buf
, buflen
, "FAIL-CHECKSUM\n");
791 if (ret
< 0 || (size_t) ret
>= buflen
)
797 ret
= os_snprintf(buf
, buflen
, "%s", pin
);
798 if (ret
< 0 || (size_t) ret
>= buflen
)
805 #ifdef CONFIG_WPS_NFC
807 static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant
*wpa_s
,
810 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
812 if (cmd
== NULL
|| cmd
[0] == '\0')
814 else if (hwaddr_aton(cmd
, bssid
))
817 return wpas_wps_start_nfc(wpa_s
, NULL
, _bssid
, NULL
, 0, 0, NULL
, NULL
,
822 static int wpa_supplicant_ctrl_iface_wps_nfc_config_token(
823 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
830 pos
= os_strchr(cmd
, ' ');
833 if (os_strcmp(cmd
, "WPS") == 0)
835 else if (os_strcmp(cmd
, "NDEF") == 0)
840 buf
= wpas_wps_nfc_config_token(wpa_s
, ndef
, pos
);
844 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
855 static int wpa_supplicant_ctrl_iface_wps_nfc_token(
856 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
862 if (os_strcmp(cmd
, "WPS") == 0)
864 else if (os_strcmp(cmd
, "NDEF") == 0)
869 buf
= wpas_wps_nfc_token(wpa_s
, ndef
);
873 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
884 static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
885 struct wpa_supplicant
*wpa_s
, char *pos
)
893 freq
= strstr(pos
, " freq=");
897 forced_freq
= atoi(freq
);
900 len
= os_strlen(pos
);
905 buf
= wpabuf_alloc(len
);
908 if (hexstr2bin(pos
, wpabuf_put(buf
, len
), len
) < 0) {
913 ret
= wpas_wps_nfc_tag_read(wpa_s
, buf
, forced_freq
);
920 static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant
*wpa_s
,
921 char *reply
, size_t max_len
,
927 buf
= wpas_wps_nfc_handover_req(wpa_s
, ndef
);
931 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
943 static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant
*wpa_s
,
944 char *reply
, size_t max_len
,
950 buf
= wpas_p2p_nfc_handover_req(wpa_s
, ndef
);
952 wpa_printf(MSG_DEBUG
, "P2P: Could not generate NFC handover request");
956 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
965 #endif /* CONFIG_P2P */
968 static int wpas_ctrl_nfc_get_handover_req(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 if (os_strcmp(pos
, "WPS") == 0 || os_strcmp(pos
, "WPS-CR") == 0) {
990 return wpas_ctrl_nfc_get_handover_req_wps(
991 wpa_s
, reply
, max_len
, ndef
);
995 if (os_strcmp(pos
, "P2P-CR") == 0) {
996 return wpas_ctrl_nfc_get_handover_req_p2p(
997 wpa_s
, reply
, max_len
, ndef
);
999 #endif /* CONFIG_P2P */
1005 static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant
*wpa_s
,
1006 char *reply
, size_t max_len
,
1007 int ndef
, int cr
, char *uuid
)
1012 buf
= wpas_wps_nfc_handover_sel(wpa_s
, ndef
, cr
, uuid
);
1016 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1018 reply
[res
++] = '\n';
1028 static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant
*wpa_s
,
1029 char *reply
, size_t max_len
,
1035 buf
= wpas_p2p_nfc_handover_sel(wpa_s
, ndef
, tag
);
1039 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1041 reply
[res
++] = '\n';
1048 #endif /* CONFIG_P2P */
1051 static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant
*wpa_s
,
1052 char *cmd
, char *reply
,
1058 pos
= os_strchr(cmd
, ' ');
1063 if (os_strcmp(cmd
, "WPS") == 0)
1065 else if (os_strcmp(cmd
, "NDEF") == 0)
1070 pos2
= os_strchr(pos
, ' ');
1073 if (os_strcmp(pos
, "WPS") == 0 || os_strcmp(pos
, "WPS-CR") == 0) {
1076 return wpas_ctrl_nfc_get_handover_sel_wps(
1077 wpa_s
, reply
, max_len
, ndef
,
1078 os_strcmp(pos
, "WPS-CR") == 0, pos2
);
1082 if (os_strcmp(pos
, "P2P-CR") == 0) {
1083 return wpas_ctrl_nfc_get_handover_sel_p2p(
1084 wpa_s
, reply
, max_len
, ndef
, 0);
1087 if (os_strcmp(pos
, "P2P-CR-TAG") == 0) {
1088 return wpas_ctrl_nfc_get_handover_sel_p2p(
1089 wpa_s
, reply
, max_len
, ndef
, 1);
1091 #endif /* CONFIG_P2P */
1097 static int wpas_ctrl_nfc_rx_handover_sel(struct wpa_supplicant
*wpa_s
,
1104 len
= os_strlen(cmd
);
1109 buf
= wpabuf_alloc(len
);
1112 if (hexstr2bin(cmd
, wpabuf_put(buf
, len
), len
) < 0) {
1117 ret
= wpas_wps_nfc_rx_handover_sel(wpa_s
, buf
);
1124 static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant
*wpa_s
,
1128 struct wpabuf
*req
, *sel
;
1130 char *pos
, *role
, *type
, *pos2
;
1133 int forced_freq
= 0;
1135 freq
= strstr(cmd
, " freq=");
1139 forced_freq
= atoi(freq
);
1141 #endif /* CONFIG_P2P */
1144 pos
= os_strchr(role
, ' ');
1146 wpa_printf(MSG_DEBUG
, "NFC: Missing type in handover report");
1152 pos
= os_strchr(type
, ' ');
1154 wpa_printf(MSG_DEBUG
, "NFC: Missing request message in handover report");
1159 pos2
= os_strchr(pos
, ' ');
1161 wpa_printf(MSG_DEBUG
, "NFC: Missing select message in handover report");
1166 len
= os_strlen(pos
);
1168 wpa_printf(MSG_DEBUG
, "NFC: Invalid request message length in handover report");
1173 req
= wpabuf_alloc(len
);
1175 wpa_printf(MSG_DEBUG
, "NFC: Failed to allocate memory for request message");
1178 if (hexstr2bin(pos
, wpabuf_put(req
, len
), len
) < 0) {
1179 wpa_printf(MSG_DEBUG
, "NFC: Invalid request message hexdump in handover report");
1184 len
= os_strlen(pos2
);
1186 wpa_printf(MSG_DEBUG
, "NFC: Invalid select message length in handover report");
1192 sel
= wpabuf_alloc(len
);
1194 wpa_printf(MSG_DEBUG
, "NFC: Failed to allocate memory for select message");
1198 if (hexstr2bin(pos2
, wpabuf_put(sel
, len
), len
) < 0) {
1199 wpa_printf(MSG_DEBUG
, "NFC: Invalid select message hexdump in handover report");
1205 wpa_printf(MSG_DEBUG
, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d",
1206 role
, type
, (int) wpabuf_len(req
), (int) wpabuf_len(sel
));
1208 if (os_strcmp(role
, "INIT") == 0 && os_strcmp(type
, "WPS") == 0) {
1209 ret
= wpas_wps_nfc_report_handover(wpa_s
, req
, sel
);
1211 } else if (os_strcmp(role
, "RESP") == 0 && os_strcmp(type
, "WPS") == 0)
1213 ret
= wpas_ap_wps_nfc_report_handover(wpa_s
, req
, sel
);
1215 ret
= wpas_er_wps_nfc_report_handover(wpa_s
, req
, sel
);
1216 #endif /* CONFIG_AP */
1218 } else if (os_strcmp(role
, "INIT") == 0 && os_strcmp(type
, "P2P") == 0)
1220 ret
= wpas_p2p_nfc_report_handover(wpa_s
, 1, req
, sel
, 0);
1221 } else if (os_strcmp(role
, "RESP") == 0 && os_strcmp(type
, "P2P") == 0)
1223 ret
= wpas_p2p_nfc_report_handover(wpa_s
, 0, req
, sel
,
1225 #endif /* CONFIG_P2P */
1227 wpa_printf(MSG_DEBUG
, "NFC: Unsupported connection handover "
1228 "reported: role=%s type=%s", role
, type
);
1235 wpa_printf(MSG_DEBUG
, "NFC: Failed to process reported handover messages");
1240 #endif /* CONFIG_WPS_NFC */
1243 static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant
*wpa_s
,
1252 struct wps_new_ap_settings ap
;
1254 pin
= os_strchr(cmd
, ' ');
1259 if (hwaddr_aton(cmd
, bssid
)) {
1260 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
1265 new_ssid
= os_strchr(pin
, ' ');
1266 if (new_ssid
== NULL
)
1267 return wpas_wps_start_reg(wpa_s
, bssid
, pin
, NULL
);
1270 new_auth
= os_strchr(new_ssid
, ' ');
1271 if (new_auth
== NULL
)
1275 new_encr
= os_strchr(new_auth
, ' ');
1276 if (new_encr
== NULL
)
1280 new_key
= os_strchr(new_encr
, ' ');
1281 if (new_key
== NULL
)
1285 os_memset(&ap
, 0, sizeof(ap
));
1286 ap
.ssid_hex
= new_ssid
;
1289 ap
.key_hex
= new_key
;
1290 return wpas_wps_start_reg(wpa_s
, bssid
, pin
, &ap
);
1295 static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant
*wpa_s
,
1296 char *cmd
, char *buf
,
1301 const char *pin_txt
;
1303 if (!wpa_s
->ap_iface
)
1306 pos
= os_strchr(cmd
, ' ');
1310 if (os_strcmp(cmd
, "disable") == 0) {
1311 wpas_wps_ap_pin_disable(wpa_s
);
1312 return os_snprintf(buf
, buflen
, "OK\n");
1315 if (os_strcmp(cmd
, "random") == 0) {
1317 timeout
= atoi(pos
);
1318 pin_txt
= wpas_wps_ap_pin_random(wpa_s
, timeout
);
1319 if (pin_txt
== NULL
)
1321 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
1324 if (os_strcmp(cmd
, "get") == 0) {
1325 pin_txt
= wpas_wps_ap_pin_get(wpa_s
);
1326 if (pin_txt
== NULL
)
1328 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
1331 if (os_strcmp(cmd
, "set") == 0) {
1336 pos
= os_strchr(pos
, ' ');
1339 timeout
= atoi(pos
);
1341 if (os_strlen(pin
) > buflen
)
1343 if (wpas_wps_ap_pin_set(wpa_s
, pin
, timeout
) < 0)
1345 return os_snprintf(buf
, buflen
, "%s", pin
);
1350 #endif /* CONFIG_AP */
1353 #ifdef CONFIG_WPS_ER
1354 static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant
*wpa_s
,
1357 char *uuid
= cmd
, *pin
, *pos
;
1358 u8 addr_buf
[ETH_ALEN
], *addr
= NULL
;
1359 pin
= os_strchr(uuid
, ' ');
1363 pos
= os_strchr(pin
, ' ');
1366 if (hwaddr_aton(pos
, addr_buf
) == 0)
1369 return wpas_wps_er_add_pin(wpa_s
, addr
, uuid
, pin
);
1373 static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant
*wpa_s
,
1376 char *uuid
= cmd
, *pin
;
1377 pin
= os_strchr(uuid
, ' ');
1381 return wpas_wps_er_learn(wpa_s
, uuid
, pin
);
1385 static int wpa_supplicant_ctrl_iface_wps_er_set_config(
1386 struct wpa_supplicant
*wpa_s
, char *cmd
)
1388 char *uuid
= cmd
, *id
;
1389 id
= os_strchr(uuid
, ' ');
1393 return wpas_wps_er_set_config(wpa_s
, uuid
, atoi(id
));
1397 static int wpa_supplicant_ctrl_iface_wps_er_config(
1398 struct wpa_supplicant
*wpa_s
, char *cmd
)
1405 struct wps_new_ap_settings ap
;
1407 pin
= os_strchr(cmd
, ' ');
1412 new_ssid
= os_strchr(pin
, ' ');
1413 if (new_ssid
== NULL
)
1417 new_auth
= os_strchr(new_ssid
, ' ');
1418 if (new_auth
== NULL
)
1422 new_encr
= os_strchr(new_auth
, ' ');
1423 if (new_encr
== NULL
)
1427 new_key
= os_strchr(new_encr
, ' ');
1428 if (new_key
== NULL
)
1432 os_memset(&ap
, 0, sizeof(ap
));
1433 ap
.ssid_hex
= new_ssid
;
1436 ap
.key_hex
= new_key
;
1437 return wpas_wps_er_config(wpa_s
, cmd
, pin
, &ap
);
1441 #ifdef CONFIG_WPS_NFC
1442 static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
1443 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
1450 uuid
= os_strchr(cmd
, ' ');
1455 if (os_strcmp(cmd
, "WPS") == 0)
1457 else if (os_strcmp(cmd
, "NDEF") == 0)
1462 buf
= wpas_wps_er_nfc_config_token(wpa_s
, ndef
, uuid
);
1466 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1468 reply
[res
++] = '\n';
1475 #endif /* CONFIG_WPS_NFC */
1476 #endif /* CONFIG_WPS_ER */
1478 #endif /* CONFIG_WPS */
1481 #ifdef CONFIG_IBSS_RSN
1482 static int wpa_supplicant_ctrl_iface_ibss_rsn(
1483 struct wpa_supplicant
*wpa_s
, char *addr
)
1487 if (hwaddr_aton(addr
, peer
)) {
1488 wpa_printf(MSG_DEBUG
, "CTRL_IFACE IBSS_RSN: invalid "
1489 "address '%s'", addr
);
1493 wpa_printf(MSG_DEBUG
, "CTRL_IFACE IBSS_RSN " MACSTR
,
1496 return ibss_rsn_start(wpa_s
->ibss_rsn
, peer
);
1498 #endif /* CONFIG_IBSS_RSN */
1501 static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant
*wpa_s
,
1504 #ifdef IEEE8021X_EAPOL
1507 struct wpa_ssid
*ssid
;
1509 pos
= os_strchr(rsp
, '-');
1514 pos
= os_strchr(pos
, ':');
1519 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: field=%s id=%d", rsp
, id
);
1520 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
1521 (u8
*) pos
, os_strlen(pos
));
1523 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1525 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
1530 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s
, ssid
, rsp
,
1532 #else /* IEEE8021X_EAPOL */
1533 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: 802.1X not included");
1535 #endif /* IEEE8021X_EAPOL */
1539 static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant
*wpa_s
,
1541 char *buf
, size_t buflen
)
1543 char *pos
, *end
, tmp
[30];
1544 int res
, verbose
, wps
, ret
;
1547 #endif /* CONFIG_HS20 */
1549 if (os_strcmp(params
, "-DRIVER") == 0)
1550 return wpa_drv_status(wpa_s
, buf
, buflen
);
1551 verbose
= os_strcmp(params
, "-VERBOSE") == 0;
1552 wps
= os_strcmp(params
, "-WPS") == 0;
1555 if (wpa_s
->wpa_state
>= WPA_ASSOCIATED
) {
1556 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
1557 ret
= os_snprintf(pos
, end
- pos
, "bssid=" MACSTR
"\n",
1558 MAC2STR(wpa_s
->bssid
));
1559 if (ret
< 0 || ret
>= end
- pos
)
1563 u8
*_ssid
= ssid
->ssid
;
1564 size_t ssid_len
= ssid
->ssid_len
;
1565 u8 ssid_buf
[MAX_SSID_LEN
];
1566 if (ssid_len
== 0) {
1567 int _res
= wpa_drv_get_ssid(wpa_s
, ssid_buf
);
1574 ret
= os_snprintf(pos
, end
- pos
, "ssid=%s\nid=%d\n",
1575 wpa_ssid_txt(_ssid
, ssid_len
),
1577 if (ret
< 0 || ret
>= end
- pos
)
1581 if (wps
&& ssid
->passphrase
&&
1582 wpa_key_mgmt_wpa_psk(ssid
->key_mgmt
) &&
1583 (ssid
->mode
== WPAS_MODE_AP
||
1584 ssid
->mode
== WPAS_MODE_P2P_GO
)) {
1585 ret
= os_snprintf(pos
, end
- pos
,
1588 if (ret
< 0 || ret
>= end
- pos
)
1593 ret
= os_snprintf(pos
, end
- pos
,
1596 if (ret
< 0 || ret
>= end
- pos
)
1601 switch (ssid
->mode
) {
1602 case WPAS_MODE_INFRA
:
1603 ret
= os_snprintf(pos
, end
- pos
,
1606 case WPAS_MODE_IBSS
:
1607 ret
= os_snprintf(pos
, end
- pos
,
1611 ret
= os_snprintf(pos
, end
- pos
,
1614 case WPAS_MODE_P2P_GO
:
1615 ret
= os_snprintf(pos
, end
- pos
,
1618 case WPAS_MODE_P2P_GROUP_FORMATION
:
1619 ret
= os_snprintf(pos
, end
- pos
,
1620 "mode=P2P GO - group "
1627 if (ret
< 0 || ret
>= end
- pos
)
1633 if (wpa_s
->ap_iface
) {
1634 pos
+= ap_ctrl_iface_wpa_get_status(wpa_s
, pos
,
1638 #endif /* CONFIG_AP */
1639 pos
+= wpa_sm_get_status(wpa_s
->wpa
, pos
, end
- pos
, verbose
);
1642 if (wpa_s
->wpa_state
>= WPA_ASSOCIATED
&&
1645 #endif /* CONFIG_AP */
1646 wpa_s
->sme
.sae
.state
== SAE_ACCEPTED
) {
1647 ret
= os_snprintf(pos
, end
- pos
, "sae_group=%d\n",
1648 wpa_s
->sme
.sae
.group
);
1649 if (ret
< 0 || ret
>= end
- pos
)
1653 #endif /* CONFIG_SAE */
1654 ret
= os_snprintf(pos
, end
- pos
, "wpa_state=%s\n",
1655 wpa_supplicant_state_txt(wpa_s
->wpa_state
));
1656 if (ret
< 0 || ret
>= end
- pos
)
1661 l2_packet_get_ip_addr(wpa_s
->l2
, tmp
, sizeof(tmp
)) >= 0) {
1662 ret
= os_snprintf(pos
, end
- pos
, "ip_address=%s\n", tmp
);
1663 if (ret
< 0 || ret
>= end
- pos
)
1669 if (wpa_s
->global
->p2p
) {
1670 ret
= os_snprintf(pos
, end
- pos
, "p2p_device_address=" MACSTR
1671 "\n", MAC2STR(wpa_s
->global
->p2p_dev_addr
));
1672 if (ret
< 0 || ret
>= end
- pos
)
1676 #endif /* CONFIG_P2P */
1678 ret
= os_snprintf(pos
, end
- pos
, "address=" MACSTR
"\n",
1679 MAC2STR(wpa_s
->own_addr
));
1680 if (ret
< 0 || ret
>= end
- pos
)
1685 if (wpa_s
->current_bss
&&
1686 (hs20
= wpa_bss_get_vendor_ie(wpa_s
->current_bss
,
1687 HS20_IE_VENDOR_TYPE
)) &&
1688 wpa_s
->wpa_proto
== WPA_PROTO_RSN
&&
1689 wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
)) {
1692 u8 rel_num
= (hs20
[6] & 0xf0) >> 4;
1693 release
= rel_num
+ 1;
1695 ret
= os_snprintf(pos
, end
- pos
, "hs20=%d\n", release
);
1696 if (ret
< 0 || ret
>= end
- pos
)
1701 if (wpa_s
->current_ssid
) {
1702 struct wpa_cred
*cred
;
1705 for (cred
= wpa_s
->conf
->cred
; cred
; cred
= cred
->next
) {
1708 if (wpa_s
->current_ssid
->parent_cred
!= cred
)
1711 if (cred
->provisioning_sp
) {
1712 ret
= os_snprintf(pos
, end
- pos
,
1713 "provisioning_sp=%s\n",
1714 cred
->provisioning_sp
);
1715 if (ret
< 0 || ret
>= end
- pos
)
1724 if (wpa_s
->current_bss
&& wpa_s
->current_bss
->anqp
) {
1725 struct wpabuf
*names
=
1726 wpa_s
->current_bss
->anqp
->domain_name
;
1727 for (i
= 0; names
&& i
< cred
->num_domain
; i
++)
1729 if (domain_name_list_contains(
1730 names
, cred
->domain
[i
], 1))
1733 if (i
== cred
->num_domain
)
1734 i
= 0; /* show first entry by default */
1736 ret
= os_snprintf(pos
, end
- pos
, "home_sp=%s\n",
1738 if (ret
< 0 || ret
>= end
- pos
)
1743 if (wpa_s
->current_bss
== NULL
||
1744 wpa_s
->current_bss
->anqp
== NULL
)
1747 res
= interworking_home_sp_cred(
1749 wpa_s
->current_bss
->anqp
->domain_name
);
1757 ret
= os_snprintf(pos
, end
- pos
, "sp_type=%s\n", type
);
1758 if (ret
< 0 || ret
>= end
- pos
)
1765 #endif /* CONFIG_HS20 */
1767 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) ||
1768 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
1769 res
= eapol_sm_get_status(wpa_s
->eapol
, pos
, end
- pos
,
1775 res
= rsn_preauth_get_status(wpa_s
->wpa
, pos
, end
- pos
, verbose
);
1782 uuid_bin2str(wpa_s
->wps
->uuid
, uuid_str
, sizeof(uuid_str
));
1783 ret
= os_snprintf(pos
, end
- pos
, "uuid=%s\n", uuid_str
);
1784 if (ret
< 0 || ret
>= end
- pos
)
1788 #endif /* CONFIG_WPS */
1791 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_STATE_CHANGE
1792 "id=%d state=%d BSSID=" MACSTR
" SSID=%s",
1793 wpa_s
->current_ssid
? wpa_s
->current_ssid
->id
: -1,
1795 MAC2STR(wpa_s
->bssid
),
1796 wpa_s
->current_ssid
&& wpa_s
->current_ssid
->ssid
?
1797 wpa_ssid_txt(wpa_s
->current_ssid
->ssid
,
1798 wpa_s
->current_ssid
->ssid_len
) : "");
1799 if (wpa_s
->wpa_state
== WPA_COMPLETED
) {
1800 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
1801 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_CONNECTED
1802 "- connection to " MACSTR
1803 " completed %s [id=%d id_str=%s]",
1804 MAC2STR(wpa_s
->bssid
), "(auth)",
1805 ssid
? ssid
->id
: -1,
1806 ssid
&& ssid
->id_str
? ssid
->id_str
: "");
1808 #endif /* ANDROID */
1814 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant
*wpa_s
,
1819 struct wpa_ssid
*ssid
;
1822 /* cmd: "<network id> <BSSID>" */
1823 pos
= os_strchr(cmd
, ' ');
1828 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: id=%d bssid='%s'", id
, pos
);
1829 if (hwaddr_aton(pos
, bssid
)) {
1830 wpa_printf(MSG_DEBUG
,"CTRL_IFACE: invalid BSSID '%s'", pos
);
1834 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1836 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
1841 os_memcpy(ssid
->bssid
, bssid
, ETH_ALEN
);
1842 ssid
->bssid_set
= !is_zero_ether_addr(bssid
);
1848 static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant
*wpa_s
,
1849 char *cmd
, char *buf
,
1853 struct wpa_blacklist
*e
;
1857 /* cmd: "BLACKLIST [<BSSID>]" */
1861 e
= wpa_s
->blacklist
;
1863 ret
= os_snprintf(pos
, end
- pos
, MACSTR
"\n",
1865 if (ret
< 0 || ret
>= end
- pos
)
1874 if (os_strncmp(cmd
, "clear", 5) == 0) {
1875 wpa_blacklist_clear(wpa_s
);
1876 os_memcpy(buf
, "OK\n", 3);
1880 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd
);
1881 if (hwaddr_aton(cmd
, bssid
)) {
1882 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: invalid BSSID '%s'", cmd
);
1887 * Add the BSSID twice, so its count will be 2, causing it to be
1888 * skipped when processing scan results.
1890 ret
= wpa_blacklist_add(wpa_s
, bssid
);
1893 ret
= wpa_blacklist_add(wpa_s
, bssid
);
1896 os_memcpy(buf
, "OK\n", 3);
1901 static const char * debug_level_str(int level
)
1922 static int str_to_debug_level(const char *s
)
1924 if (os_strcasecmp(s
, "EXCESSIVE") == 0)
1925 return MSG_EXCESSIVE
;
1926 if (os_strcasecmp(s
, "MSGDUMP") == 0)
1928 if (os_strcasecmp(s
, "DEBUG") == 0)
1930 if (os_strcasecmp(s
, "INFO") == 0)
1932 if (os_strcasecmp(s
, "WARNING") == 0)
1934 if (os_strcasecmp(s
, "ERROR") == 0)
1940 static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant
*wpa_s
,
1941 char *cmd
, char *buf
,
1944 char *pos
, *end
, *stamp
;
1951 /* cmd: "LOG_LEVEL [<level>]" */
1955 ret
= os_snprintf(pos
, end
- pos
, "Current level: %s\n"
1957 debug_level_str(wpa_debug_level
),
1958 wpa_debug_timestamp
);
1959 if (ret
< 0 || ret
>= end
- pos
)
1968 stamp
= os_strchr(cmd
, ' ');
1971 while (*stamp
== ' ') {
1976 if (cmd
&& os_strlen(cmd
)) {
1977 int level
= str_to_debug_level(cmd
);
1980 wpa_debug_level
= level
;
1983 if (stamp
&& os_strlen(stamp
))
1984 wpa_debug_timestamp
= atoi(stamp
);
1986 os_memcpy(buf
, "OK\n", 3);
1991 static int wpa_supplicant_ctrl_iface_list_networks(
1992 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
1995 struct wpa_ssid
*ssid
;
2000 ret
= os_snprintf(pos
, end
- pos
,
2001 "network id / ssid / bssid / flags\n");
2002 if (ret
< 0 || ret
>= end
- pos
)
2006 ssid
= wpa_s
->conf
->ssid
;
2008 ret
= os_snprintf(pos
, end
- pos
, "%d\t%s",
2010 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
));
2011 if (ret
< 0 || ret
>= end
- pos
)
2014 if (ssid
->bssid_set
) {
2015 ret
= os_snprintf(pos
, end
- pos
, "\t" MACSTR
,
2016 MAC2STR(ssid
->bssid
));
2018 ret
= os_snprintf(pos
, end
- pos
, "\tany");
2020 if (ret
< 0 || ret
>= end
- pos
)
2023 ret
= os_snprintf(pos
, end
- pos
, "\t%s%s%s%s",
2024 ssid
== wpa_s
->current_ssid
?
2026 ssid
->disabled
? "[DISABLED]" : "",
2027 ssid
->disabled_until
.sec
?
2028 "[TEMP-DISABLED]" : "",
2029 ssid
->disabled
== 2 ? "[P2P-PERSISTENT]" :
2031 if (ret
< 0 || ret
>= end
- pos
)
2034 ret
= os_snprintf(pos
, end
- pos
, "\n");
2035 if (ret
< 0 || ret
>= end
- pos
)
2046 static char * wpa_supplicant_cipher_txt(char *pos
, char *end
, int cipher
)
2049 ret
= os_snprintf(pos
, end
- pos
, "-");
2050 if (ret
< 0 || ret
>= end
- pos
)
2053 ret
= wpa_write_ciphers(pos
, end
, cipher
, "+");
2061 static char * wpa_supplicant_ie_txt(char *pos
, char *end
, const char *proto
,
2062 const u8
*ie
, size_t ie_len
)
2064 struct wpa_ie_data data
;
2068 ret
= os_snprintf(pos
, end
- pos
, "[%s-", proto
);
2069 if (ret
< 0 || ret
>= end
- pos
)
2073 if (wpa_parse_wpa_ie(ie
, ie_len
, &data
) < 0) {
2074 ret
= os_snprintf(pos
, end
- pos
, "?]");
2075 if (ret
< 0 || ret
>= end
- pos
)
2082 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X
) {
2083 ret
= os_snprintf(pos
, end
- pos
, "%sEAP",
2084 pos
== start
? "" : "+");
2085 if (ret
< 0 || ret
>= end
- pos
)
2089 if (data
.key_mgmt
& WPA_KEY_MGMT_PSK
) {
2090 ret
= os_snprintf(pos
, end
- pos
, "%sPSK",
2091 pos
== start
? "" : "+");
2092 if (ret
< 0 || ret
>= end
- pos
)
2096 if (data
.key_mgmt
& WPA_KEY_MGMT_WPA_NONE
) {
2097 ret
= os_snprintf(pos
, end
- pos
, "%sNone",
2098 pos
== start
? "" : "+");
2099 if (ret
< 0 || ret
>= end
- pos
)
2103 #ifdef CONFIG_IEEE80211R
2104 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_IEEE8021X
) {
2105 ret
= os_snprintf(pos
, end
- pos
, "%sFT/EAP",
2106 pos
== start
? "" : "+");
2107 if (ret
< 0 || ret
>= end
- pos
)
2111 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_PSK
) {
2112 ret
= os_snprintf(pos
, end
- pos
, "%sFT/PSK",
2113 pos
== start
? "" : "+");
2114 if (ret
< 0 || ret
>= end
- pos
)
2118 #endif /* CONFIG_IEEE80211R */
2119 #ifdef CONFIG_IEEE80211W
2120 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SHA256
) {
2121 ret
= os_snprintf(pos
, end
- pos
, "%sEAP-SHA256",
2122 pos
== start
? "" : "+");
2123 if (ret
< 0 || ret
>= end
- pos
)
2127 if (data
.key_mgmt
& WPA_KEY_MGMT_PSK_SHA256
) {
2128 ret
= os_snprintf(pos
, end
- pos
, "%sPSK-SHA256",
2129 pos
== start
? "" : "+");
2130 if (ret
< 0 || ret
>= end
- pos
)
2134 #endif /* CONFIG_IEEE80211W */
2136 pos
= wpa_supplicant_cipher_txt(pos
, end
, data
.pairwise_cipher
);
2138 if (data
.capabilities
& WPA_CAPABILITY_PREAUTH
) {
2139 ret
= os_snprintf(pos
, end
- pos
, "-preauth");
2140 if (ret
< 0 || ret
>= end
- pos
)
2145 ret
= os_snprintf(pos
, end
- pos
, "]");
2146 if (ret
< 0 || ret
>= end
- pos
)
2155 static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant
*wpa_s
,
2156 char *pos
, char *end
,
2157 struct wpabuf
*wps_ie
)
2164 if (wps_is_selected_pbc_registrar(wps_ie
))
2166 else if (wps_is_addr_authorized(wps_ie
, wpa_s
->own_addr
, 0))
2168 else if (wps_is_selected_pin_registrar(wps_ie
))
2173 ret
= os_snprintf(pos
, end
- pos
, "%s", txt
);
2174 if (ret
>= 0 && ret
< end
- pos
)
2176 wpabuf_free(wps_ie
);
2179 #endif /* CONFIG_WPS */
2182 static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant
*wpa_s
,
2183 char *pos
, char *end
,
2184 const struct wpa_bss
*bss
)
2187 struct wpabuf
*wps_ie
;
2188 wps_ie
= wpa_bss_get_vendor_ie_multi(bss
, WPS_IE_VENDOR_TYPE
);
2189 return wpa_supplicant_wps_ie_txt_buf(wpa_s
, pos
, end
, wps_ie
);
2190 #else /* CONFIG_WPS */
2192 #endif /* CONFIG_WPS */
2196 /* Format one result on one text line into a buffer. */
2197 static int wpa_supplicant_ctrl_iface_scan_result(
2198 struct wpa_supplicant
*wpa_s
,
2199 const struct wpa_bss
*bss
, char *buf
, size_t buflen
)
2203 const u8
*ie
, *ie2
, *p2p
;
2205 p2p
= wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
);
2207 p2p
= wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
);
2208 if (p2p
&& bss
->ssid_len
== P2P_WILDCARD_SSID_LEN
&&
2209 os_memcmp(bss
->ssid
, P2P_WILDCARD_SSID
, P2P_WILDCARD_SSID_LEN
) ==
2211 return 0; /* Do not show P2P listen discovery results here */
2216 ret
= os_snprintf(pos
, end
- pos
, MACSTR
"\t%d\t%d\t",
2217 MAC2STR(bss
->bssid
), bss
->freq
, bss
->level
);
2218 if (ret
< 0 || ret
>= end
- pos
)
2221 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
2223 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA", ie
, 2 + ie
[1]);
2224 ie2
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
2226 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA2", ie2
, 2 + ie2
[1]);
2227 pos
= wpa_supplicant_wps_ie_txt(wpa_s
, pos
, end
, bss
);
2228 if (!ie
&& !ie2
&& bss
->caps
& IEEE80211_CAP_PRIVACY
) {
2229 ret
= os_snprintf(pos
, end
- pos
, "[WEP]");
2230 if (ret
< 0 || ret
>= end
- pos
)
2234 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
2235 ret
= os_snprintf(pos
, end
- pos
, "[IBSS]");
2236 if (ret
< 0 || ret
>= end
- pos
)
2240 if (bss
->caps
& IEEE80211_CAP_ESS
) {
2241 ret
= os_snprintf(pos
, end
- pos
, "[ESS]");
2242 if (ret
< 0 || ret
>= end
- pos
)
2247 ret
= os_snprintf(pos
, end
- pos
, "[P2P]");
2248 if (ret
< 0 || ret
>= end
- pos
)
2253 if (wpa_bss_get_vendor_ie(bss
, HS20_IE_VENDOR_TYPE
) && ie2
) {
2254 ret
= os_snprintf(pos
, end
- pos
, "[HS20]");
2255 if (ret
< 0 || ret
>= end
- pos
)
2259 #endif /* CONFIG_HS20 */
2261 ret
= os_snprintf(pos
, end
- pos
, "\t%s",
2262 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
2263 if (ret
< 0 || ret
>= end
- pos
)
2267 ret
= os_snprintf(pos
, end
- pos
, "\n");
2268 if (ret
< 0 || ret
>= end
- pos
)
2276 static int wpa_supplicant_ctrl_iface_scan_results(
2277 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
2280 struct wpa_bss
*bss
;
2285 ret
= os_snprintf(pos
, end
- pos
, "bssid / frequency / signal level / "
2287 if (ret
< 0 || ret
>= end
- pos
)
2291 dl_list_for_each(bss
, &wpa_s
->bss_id
, struct wpa_bss
, list_id
) {
2292 ret
= wpa_supplicant_ctrl_iface_scan_result(wpa_s
, bss
, pos
,
2294 if (ret
< 0 || ret
>= end
- pos
)
2303 static int wpa_supplicant_ctrl_iface_select_network(
2304 struct wpa_supplicant
*wpa_s
, char *cmd
)
2307 struct wpa_ssid
*ssid
;
2309 /* cmd: "<network id>" or "any" */
2310 if (os_strcmp(cmd
, "any") == 0) {
2311 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SELECT_NETWORK any");
2315 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SELECT_NETWORK id=%d", id
);
2317 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2319 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
2320 "network id=%d", id
);
2323 if (ssid
->disabled
== 2) {
2324 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
2325 "SELECT_NETWORK with persistent P2P group");
2330 wpa_supplicant_select_network(wpa_s
, ssid
);
2336 static int wpa_supplicant_ctrl_iface_enable_network(
2337 struct wpa_supplicant
*wpa_s
, char *cmd
)
2340 struct wpa_ssid
*ssid
;
2342 /* cmd: "<network id>" or "all" */
2343 if (os_strcmp(cmd
, "all") == 0) {
2344 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ENABLE_NETWORK all");
2348 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ENABLE_NETWORK id=%d", id
);
2350 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2352 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
2353 "network id=%d", id
);
2356 if (ssid
->disabled
== 2) {
2357 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
2358 "ENABLE_NETWORK with persistent P2P group");
2362 if (os_strstr(cmd
, " no-connect")) {
2367 wpa_supplicant_enable_network(wpa_s
, ssid
);
2373 static int wpa_supplicant_ctrl_iface_disable_network(
2374 struct wpa_supplicant
*wpa_s
, char *cmd
)
2377 struct wpa_ssid
*ssid
;
2379 /* cmd: "<network id>" or "all" */
2380 if (os_strcmp(cmd
, "all") == 0) {
2381 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DISABLE_NETWORK all");
2385 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DISABLE_NETWORK id=%d", id
);
2387 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2389 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
2390 "network id=%d", id
);
2393 if (ssid
->disabled
== 2) {
2394 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
2395 "DISABLE_NETWORK with persistent P2P "
2400 wpa_supplicant_disable_network(wpa_s
, ssid
);
2406 static int wpa_supplicant_ctrl_iface_add_network(
2407 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
2409 struct wpa_ssid
*ssid
;
2412 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ADD_NETWORK");
2414 ssid
= wpa_config_add_network(wpa_s
->conf
);
2418 wpas_notify_network_added(wpa_s
, ssid
);
2421 wpa_config_set_network_defaults(ssid
);
2423 ret
= os_snprintf(buf
, buflen
, "%d\n", ssid
->id
);
2424 if (ret
< 0 || (size_t) ret
>= buflen
)
2430 static int wpa_supplicant_ctrl_iface_remove_network(
2431 struct wpa_supplicant
*wpa_s
, char *cmd
)
2434 struct wpa_ssid
*ssid
;
2437 /* cmd: "<network id>" or "all" */
2438 if (os_strcmp(cmd
, "all") == 0) {
2439 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_NETWORK all");
2440 if (wpa_s
->sched_scanning
)
2441 wpa_supplicant_cancel_sched_scan(wpa_s
);
2443 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
2444 if (wpa_s
->current_ssid
) {
2446 wpa_s
->sme
.prev_bssid_set
= 0;
2447 #endif /* CONFIG_SME */
2448 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
2449 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
2450 wpa_supplicant_deauthenticate(
2451 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2453 ssid
= wpa_s
->conf
->ssid
;
2455 struct wpa_ssid
*remove_ssid
= ssid
;
2458 wpas_notify_network_removed(wpa_s
, remove_ssid
);
2459 wpa_config_remove_network(wpa_s
->conf
, id
);
2465 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_NETWORK id=%d", id
);
2467 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2469 wpas_notify_network_removed(wpa_s
, ssid
);
2471 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
2476 if (ssid
== wpa_s
->current_ssid
|| wpa_s
->current_ssid
== NULL
) {
2478 wpa_s
->sme
.prev_bssid_set
= 0;
2479 #endif /* CONFIG_SME */
2481 * Invalidate the EAP session cache if the current or
2482 * previously used network is removed.
2484 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
2487 if (ssid
== wpa_s
->current_ssid
) {
2488 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
2489 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
2491 wpa_supplicant_deauthenticate(wpa_s
,
2492 WLAN_REASON_DEAUTH_LEAVING
);
2495 was_disabled
= ssid
->disabled
;
2497 if (wpa_config_remove_network(wpa_s
->conf
, id
) < 0) {
2498 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Not able to remove the "
2499 "network id=%d", id
);
2503 if (!was_disabled
&& wpa_s
->sched_scanning
) {
2504 wpa_printf(MSG_DEBUG
, "Stop ongoing sched_scan to remove "
2505 "network from filters");
2506 wpa_supplicant_cancel_sched_scan(wpa_s
);
2507 wpa_supplicant_req_scan(wpa_s
, 0, 0);
2514 static int wpa_supplicant_ctrl_iface_set_network(
2515 struct wpa_supplicant
*wpa_s
, char *cmd
)
2518 struct wpa_ssid
*ssid
;
2521 /* cmd: "<network id> <variable name> <value>" */
2522 name
= os_strchr(cmd
, ' ');
2527 value
= os_strchr(name
, ' ');
2533 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
2535 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
2536 (u8
*) value
, os_strlen(value
));
2538 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2540 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
2545 if (wpa_config_set(ssid
, name
, value
, 0) < 0) {
2546 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to set network "
2547 "variable '%s'", name
);
2551 if (os_strcmp(name
, "bssid") != 0 &&
2552 os_strcmp(name
, "priority") != 0)
2553 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, ssid
);
2555 if (wpa_s
->current_ssid
== ssid
|| wpa_s
->current_ssid
== NULL
) {
2557 * Invalidate the EAP session cache if anything in the current
2558 * or previously used configuration changes.
2560 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
2563 if ((os_strcmp(name
, "psk") == 0 &&
2564 value
[0] == '"' && ssid
->ssid_len
) ||
2565 (os_strcmp(name
, "ssid") == 0 && ssid
->passphrase
))
2566 wpa_config_update_psk(ssid
);
2567 else if (os_strcmp(name
, "priority") == 0)
2568 wpa_config_update_prio_list(wpa_s
->conf
);
2574 static int wpa_supplicant_ctrl_iface_get_network(
2575 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
2579 struct wpa_ssid
*ssid
;
2582 /* cmd: "<network id> <variable name>" */
2583 name
= os_strchr(cmd
, ' ');
2584 if (name
== NULL
|| buflen
== 0)
2589 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
2592 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2594 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
2599 value
= wpa_config_get_no_key(ssid
, name
);
2600 if (value
== NULL
) {
2601 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to get network "
2602 "variable '%s'", name
);
2606 res
= os_strlcpy(buf
, value
, buflen
);
2607 if (res
>= buflen
) {
2618 static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant
*wpa_s
,
2619 char *buf
, size_t buflen
)
2622 struct wpa_cred
*cred
;
2627 ret
= os_snprintf(pos
, end
- pos
,
2628 "cred id / realm / username / domain / imsi\n");
2629 if (ret
< 0 || ret
>= end
- pos
)
2633 cred
= wpa_s
->conf
->cred
;
2635 ret
= os_snprintf(pos
, end
- pos
, "%d\t%s\t%s\t%s\t%s\n",
2636 cred
->id
, cred
->realm
? cred
->realm
: "",
2637 cred
->username
? cred
->username
: "",
2638 cred
->domain
? cred
->domain
[0] : "",
2639 cred
->imsi
? cred
->imsi
: "");
2640 if (ret
< 0 || ret
>= end
- pos
)
2651 static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant
*wpa_s
,
2652 char *buf
, size_t buflen
)
2654 struct wpa_cred
*cred
;
2657 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ADD_CRED");
2659 cred
= wpa_config_add_cred(wpa_s
->conf
);
2663 ret
= os_snprintf(buf
, buflen
, "%d\n", cred
->id
);
2664 if (ret
< 0 || (size_t) ret
>= buflen
)
2670 static int wpas_ctrl_remove_cred(struct wpa_supplicant
*wpa_s
,
2671 struct wpa_cred
*cred
)
2673 struct wpa_ssid
*ssid
;
2676 if (cred
== NULL
|| wpa_config_remove_cred(wpa_s
->conf
, cred
->id
) < 0) {
2677 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred");
2681 /* Remove any network entry created based on the removed credential */
2682 ssid
= wpa_s
->conf
->ssid
;
2684 if (ssid
->parent_cred
== cred
) {
2685 wpa_printf(MSG_DEBUG
, "Remove network id %d since it "
2686 "used the removed credential", ssid
->id
);
2687 os_snprintf(str
, sizeof(str
), "%d", ssid
->id
);
2689 wpa_supplicant_ctrl_iface_remove_network(wpa_s
, str
);
2698 static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant
*wpa_s
,
2702 struct wpa_cred
*cred
, *prev
;
2704 /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or
2705 * "provisioning_sp=<FQDN> */
2706 if (os_strcmp(cmd
, "all") == 0) {
2707 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED all");
2708 cred
= wpa_s
->conf
->cred
;
2712 wpas_ctrl_remove_cred(wpa_s
, prev
);
2717 if (os_strncmp(cmd
, "sp_fqdn=", 8) == 0) {
2718 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
2720 cred
= wpa_s
->conf
->cred
;
2726 for (i
= 0; i
< prev
->num_domain
; i
++) {
2727 if (os_strcmp(prev
->domain
[i
], cmd
+ 8)
2730 wpas_ctrl_remove_cred(wpa_s
, prev
);
2738 if (os_strncmp(cmd
, "provisioning_sp=", 16) == 0) {
2739 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'",
2741 cred
= wpa_s
->conf
->cred
;
2745 if (prev
->provisioning_sp
&&
2746 os_strcmp(prev
->provisioning_sp
, cmd
+ 16) == 0)
2747 wpas_ctrl_remove_cred(wpa_s
, prev
);
2753 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED id=%d", id
);
2755 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
2756 return wpas_ctrl_remove_cred(wpa_s
, cred
);
2760 static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant
*wpa_s
,
2764 struct wpa_cred
*cred
;
2767 /* cmd: "<cred id> <variable name> <value>" */
2768 name
= os_strchr(cmd
, ' ');
2773 value
= os_strchr(name
, ' ');
2779 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SET_CRED id=%d name='%s'",
2781 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
2782 (u8
*) value
, os_strlen(value
));
2784 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
2786 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred id=%d",
2791 if (wpa_config_set_cred(cred
, name
, value
, 0) < 0) {
2792 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to set cred "
2793 "variable '%s'", name
);
2801 #ifndef CONFIG_NO_CONFIG_WRITE
2802 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant
*wpa_s
)
2806 if (!wpa_s
->conf
->update_config
) {
2807 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
2808 "to update configuration (update_config=0)");
2812 ret
= wpa_config_write(wpa_s
->confname
, wpa_s
->conf
);
2814 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Failed to "
2815 "update configuration");
2817 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Configuration"
2823 #endif /* CONFIG_NO_CONFIG_WRITE */
2826 struct cipher_info
{
2832 static const struct cipher_info ciphers
[] = {
2833 { WPA_DRIVER_CAPA_ENC_CCMP_256
, "CCMP-256", 0 },
2834 { WPA_DRIVER_CAPA_ENC_GCMP_256
, "GCMP-256", 0 },
2835 { WPA_DRIVER_CAPA_ENC_CCMP
, "CCMP", 0 },
2836 { WPA_DRIVER_CAPA_ENC_GCMP
, "GCMP", 0 },
2837 { WPA_DRIVER_CAPA_ENC_TKIP
, "TKIP", 0 },
2838 { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
, "NONE", 0 },
2839 { WPA_DRIVER_CAPA_ENC_WEP104
, "WEP104", 1 },
2840 { WPA_DRIVER_CAPA_ENC_WEP40
, "WEP40", 1 }
2844 static int ctrl_iface_get_capability_pairwise(int res
, char *strict
,
2845 struct wpa_driver_capa
*capa
,
2846 char *buf
, size_t buflen
)
2859 len
= os_strlcpy(buf
, "CCMP TKIP NONE", buflen
);
2865 for (i
= 0; i
< ARRAY_SIZE(ciphers
); i
++) {
2866 if (!ciphers
[i
].group_only
&& capa
->enc
& ciphers
[i
].capa
) {
2867 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
2868 pos
== buf
? "" : " ",
2870 if (ret
< 0 || ret
>= end
- pos
)
2880 static int ctrl_iface_get_capability_group(int res
, char *strict
,
2881 struct wpa_driver_capa
*capa
,
2882 char *buf
, size_t buflen
)
2895 len
= os_strlcpy(buf
, "CCMP TKIP WEP104 WEP40", buflen
);
2901 for (i
= 0; i
< ARRAY_SIZE(ciphers
); i
++) {
2902 if (capa
->enc
& ciphers
[i
].capa
) {
2903 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
2904 pos
== buf
? "" : " ",
2906 if (ret
< 0 || ret
>= end
- pos
)
2916 static int ctrl_iface_get_capability_key_mgmt(int res
, char *strict
,
2917 struct wpa_driver_capa
*capa
,
2918 char *buf
, size_t buflen
)
2930 len
= os_strlcpy(buf
, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
2937 ret
= os_snprintf(pos
, end
- pos
, "NONE IEEE8021X");
2938 if (ret
< 0 || ret
>= end
- pos
)
2942 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
2943 WPA_DRIVER_CAPA_KEY_MGMT_WPA2
)) {
2944 ret
= os_snprintf(pos
, end
- pos
, " WPA-EAP");
2945 if (ret
< 0 || ret
>= end
- pos
)
2950 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
|
2951 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
)) {
2952 ret
= os_snprintf(pos
, end
- pos
, " WPA-PSK");
2953 if (ret
< 0 || ret
>= end
- pos
)
2958 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
) {
2959 ret
= os_snprintf(pos
, end
- pos
, " WPA-NONE");
2960 if (ret
< 0 || ret
>= end
- pos
)
2969 static int ctrl_iface_get_capability_proto(int res
, char *strict
,
2970 struct wpa_driver_capa
*capa
,
2971 char *buf
, size_t buflen
)
2983 len
= os_strlcpy(buf
, "RSN WPA", buflen
);
2989 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA2
|
2990 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
)) {
2991 ret
= os_snprintf(pos
, end
- pos
, "%sRSN",
2992 pos
== buf
? "" : " ");
2993 if (ret
< 0 || ret
>= end
- pos
)
2998 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
2999 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
)) {
3000 ret
= os_snprintf(pos
, end
- pos
, "%sWPA",
3001 pos
== buf
? "" : " ");
3002 if (ret
< 0 || ret
>= end
- pos
)
3011 static int ctrl_iface_get_capability_auth_alg(int res
, char *strict
,
3012 struct wpa_driver_capa
*capa
,
3013 char *buf
, size_t buflen
)
3025 len
= os_strlcpy(buf
, "OPEN SHARED LEAP", buflen
);
3031 if (capa
->auth
& (WPA_DRIVER_AUTH_OPEN
)) {
3032 ret
= os_snprintf(pos
, end
- pos
, "%sOPEN",
3033 pos
== buf
? "" : " ");
3034 if (ret
< 0 || ret
>= end
- pos
)
3039 if (capa
->auth
& (WPA_DRIVER_AUTH_SHARED
)) {
3040 ret
= os_snprintf(pos
, end
- pos
, "%sSHARED",
3041 pos
== buf
? "" : " ");
3042 if (ret
< 0 || ret
>= end
- pos
)
3047 if (capa
->auth
& (WPA_DRIVER_AUTH_LEAP
)) {
3048 ret
= os_snprintf(pos
, end
- pos
, "%sLEAP",
3049 pos
== buf
? "" : " ");
3050 if (ret
< 0 || ret
>= end
- pos
)
3059 static int ctrl_iface_get_capability_modes(int res
, char *strict
,
3060 struct wpa_driver_capa
*capa
,
3061 char *buf
, size_t buflen
)
3073 len
= os_strlcpy(buf
, "IBSS AP", buflen
);
3079 if (capa
->flags
& WPA_DRIVER_FLAGS_IBSS
) {
3080 ret
= os_snprintf(pos
, end
- pos
, "%sIBSS",
3081 pos
== buf
? "" : " ");
3082 if (ret
< 0 || ret
>= end
- pos
)
3087 if (capa
->flags
& WPA_DRIVER_FLAGS_AP
) {
3088 ret
= os_snprintf(pos
, end
- pos
, "%sAP",
3089 pos
== buf
? "" : " ");
3090 if (ret
< 0 || ret
>= end
- pos
)
3099 static int ctrl_iface_get_capability_channels(struct wpa_supplicant
*wpa_s
,
3100 char *buf
, size_t buflen
)
3102 struct hostapd_channel_data
*chnl
;
3104 char *pos
, *end
, *hmode
;
3109 for (j
= 0; j
< wpa_s
->hw
.num_modes
; j
++) {
3110 switch (wpa_s
->hw
.modes
[j
].mode
) {
3111 case HOSTAPD_MODE_IEEE80211B
:
3114 case HOSTAPD_MODE_IEEE80211G
:
3117 case HOSTAPD_MODE_IEEE80211A
:
3120 case HOSTAPD_MODE_IEEE80211AD
:
3126 ret
= os_snprintf(pos
, end
- pos
, "Mode[%s] Channels:", hmode
);
3127 if (ret
< 0 || ret
>= end
- pos
)
3130 chnl
= wpa_s
->hw
.modes
[j
].channels
;
3131 for (i
= 0; i
< wpa_s
->hw
.modes
[j
].num_channels
; i
++) {
3132 if (chnl
[i
].flag
& HOSTAPD_CHAN_DISABLED
)
3134 ret
= os_snprintf(pos
, end
- pos
, " %d", chnl
[i
].chan
);
3135 if (ret
< 0 || ret
>= end
- pos
)
3139 ret
= os_snprintf(pos
, end
- pos
, "\n");
3140 if (ret
< 0 || ret
>= end
- pos
)
3149 static int ctrl_iface_get_capability_freq(struct wpa_supplicant
*wpa_s
,
3150 char *buf
, size_t buflen
)
3152 struct hostapd_channel_data
*chnl
;
3154 char *pos
, *end
, *hmode
;
3159 for (j
= 0; j
< wpa_s
->hw
.num_modes
; j
++) {
3160 switch (wpa_s
->hw
.modes
[j
].mode
) {
3161 case HOSTAPD_MODE_IEEE80211B
:
3164 case HOSTAPD_MODE_IEEE80211G
:
3167 case HOSTAPD_MODE_IEEE80211A
:
3170 case HOSTAPD_MODE_IEEE80211AD
:
3176 ret
= os_snprintf(pos
, end
- pos
, "Mode[%s] Channels:\n",
3178 if (ret
< 0 || ret
>= end
- pos
)
3181 chnl
= wpa_s
->hw
.modes
[j
].channels
;
3182 for (i
= 0; i
< wpa_s
->hw
.modes
[j
].num_channels
; i
++) {
3183 if (chnl
[i
].flag
& HOSTAPD_CHAN_DISABLED
)
3185 ret
= os_snprintf(pos
, end
- pos
, " %d = %d MHz%s%s\n",
3186 chnl
[i
].chan
, chnl
[i
].freq
,
3187 chnl
[i
].flag
& HOSTAPD_CHAN_NO_IBSS
?
3189 chnl
[i
].flag
& HOSTAPD_CHAN_RADAR
?
3192 if (ret
< 0 || ret
>= end
- pos
)
3196 ret
= os_snprintf(pos
, end
- pos
, "\n");
3197 if (ret
< 0 || ret
>= end
- pos
)
3206 static int wpa_supplicant_ctrl_iface_get_capability(
3207 struct wpa_supplicant
*wpa_s
, const char *_field
, char *buf
,
3210 struct wpa_driver_capa capa
;
3216 /* Determine whether or not strict checking was requested */
3217 len
= os_strlcpy(field
, _field
, sizeof(field
));
3218 if (len
>= sizeof(field
))
3220 strict
= os_strchr(field
, ' ');
3221 if (strict
!= NULL
) {
3223 if (os_strcmp(strict
, "strict") != 0)
3227 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
3228 field
, strict
? strict
: "");
3230 if (os_strcmp(field
, "eap") == 0) {
3231 return eap_get_names(buf
, buflen
);
3234 res
= wpa_drv_get_capa(wpa_s
, &capa
);
3236 if (os_strcmp(field
, "pairwise") == 0)
3237 return ctrl_iface_get_capability_pairwise(res
, strict
, &capa
,
3240 if (os_strcmp(field
, "group") == 0)
3241 return ctrl_iface_get_capability_group(res
, strict
, &capa
,
3244 if (os_strcmp(field
, "key_mgmt") == 0)
3245 return ctrl_iface_get_capability_key_mgmt(res
, strict
, &capa
,
3248 if (os_strcmp(field
, "proto") == 0)
3249 return ctrl_iface_get_capability_proto(res
, strict
, &capa
,
3252 if (os_strcmp(field
, "auth_alg") == 0)
3253 return ctrl_iface_get_capability_auth_alg(res
, strict
, &capa
,
3256 if (os_strcmp(field
, "modes") == 0)
3257 return ctrl_iface_get_capability_modes(res
, strict
, &capa
,
3260 if (os_strcmp(field
, "channels") == 0)
3261 return ctrl_iface_get_capability_channels(wpa_s
, buf
, buflen
);
3263 if (os_strcmp(field
, "freq") == 0)
3264 return ctrl_iface_get_capability_freq(wpa_s
, buf
, buflen
);
3267 if (os_strcmp(field
, "tdls") == 0)
3268 return ctrl_iface_get_capability_tdls(wpa_s
, buf
, buflen
);
3269 #endif /* CONFIG_TDLS */
3271 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
3278 #ifdef CONFIG_INTERWORKING
3279 static char * anqp_add_hex(char *pos
, char *end
, const char *title
,
3280 struct wpabuf
*data
)
3290 ret
= os_snprintf(pos
, end
- pos
, "%s=", title
);
3291 if (ret
< 0 || ret
>= end
- pos
)
3295 d
= wpabuf_head_u8(data
);
3296 for (i
= 0; i
< wpabuf_len(data
); i
++) {
3297 ret
= os_snprintf(pos
, end
- pos
, "%02x", *d
++);
3298 if (ret
< 0 || ret
>= end
- pos
)
3303 ret
= os_snprintf(pos
, end
- pos
, "\n");
3304 if (ret
< 0 || ret
>= end
- pos
)
3310 #endif /* CONFIG_INTERWORKING */
3313 static int print_bss_info(struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
,
3314 unsigned long mask
, char *buf
, size_t buflen
)
3324 if (mask
& WPA_BSS_MASK_ID
) {
3325 ret
= os_snprintf(pos
, end
- pos
, "id=%u\n", bss
->id
);
3326 if (ret
< 0 || ret
>= end
- pos
)
3331 if (mask
& WPA_BSS_MASK_BSSID
) {
3332 ret
= os_snprintf(pos
, end
- pos
, "bssid=" MACSTR
"\n",
3333 MAC2STR(bss
->bssid
));
3334 if (ret
< 0 || ret
>= end
- pos
)
3339 if (mask
& WPA_BSS_MASK_FREQ
) {
3340 ret
= os_snprintf(pos
, end
- pos
, "freq=%d\n", bss
->freq
);
3341 if (ret
< 0 || ret
>= end
- pos
)
3346 if (mask
& WPA_BSS_MASK_BEACON_INT
) {
3347 ret
= os_snprintf(pos
, end
- pos
, "beacon_int=%d\n",
3349 if (ret
< 0 || ret
>= end
- pos
)
3354 if (mask
& WPA_BSS_MASK_CAPABILITIES
) {
3355 ret
= os_snprintf(pos
, end
- pos
, "capabilities=0x%04x\n",
3357 if (ret
< 0 || ret
>= end
- pos
)
3362 if (mask
& WPA_BSS_MASK_QUAL
) {
3363 ret
= os_snprintf(pos
, end
- pos
, "qual=%d\n", bss
->qual
);
3364 if (ret
< 0 || ret
>= end
- pos
)
3369 if (mask
& WPA_BSS_MASK_NOISE
) {
3370 ret
= os_snprintf(pos
, end
- pos
, "noise=%d\n", bss
->noise
);
3371 if (ret
< 0 || ret
>= end
- pos
)
3376 if (mask
& WPA_BSS_MASK_LEVEL
) {
3377 ret
= os_snprintf(pos
, end
- pos
, "level=%d\n", bss
->level
);
3378 if (ret
< 0 || ret
>= end
- pos
)
3383 if (mask
& WPA_BSS_MASK_TSF
) {
3384 ret
= os_snprintf(pos
, end
- pos
, "tsf=%016llu\n",
3385 (unsigned long long) bss
->tsf
);
3386 if (ret
< 0 || ret
>= end
- pos
)
3391 if (mask
& WPA_BSS_MASK_AGE
) {
3392 struct os_reltime now
;
3394 os_get_reltime(&now
);
3395 ret
= os_snprintf(pos
, end
- pos
, "age=%d\n",
3396 (int) (now
.sec
- bss
->last_update
.sec
));
3397 if (ret
< 0 || ret
>= end
- pos
)
3402 if (mask
& WPA_BSS_MASK_IE
) {
3403 ret
= os_snprintf(pos
, end
- pos
, "ie=");
3404 if (ret
< 0 || ret
>= end
- pos
)
3408 ie
= (const u8
*) (bss
+ 1);
3409 for (i
= 0; i
< bss
->ie_len
; i
++) {
3410 ret
= os_snprintf(pos
, end
- pos
, "%02x", *ie
++);
3411 if (ret
< 0 || ret
>= end
- pos
)
3416 ret
= os_snprintf(pos
, end
- pos
, "\n");
3417 if (ret
< 0 || ret
>= end
- pos
)
3422 if (mask
& WPA_BSS_MASK_FLAGS
) {
3423 ret
= os_snprintf(pos
, end
- pos
, "flags=");
3424 if (ret
< 0 || ret
>= end
- pos
)
3428 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
3430 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA", ie
,
3432 ie2
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
3434 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA2", ie2
,
3436 pos
= wpa_supplicant_wps_ie_txt(wpa_s
, pos
, end
, bss
);
3437 if (!ie
&& !ie2
&& bss
->caps
& IEEE80211_CAP_PRIVACY
) {
3438 ret
= os_snprintf(pos
, end
- pos
, "[WEP]");
3439 if (ret
< 0 || ret
>= end
- pos
)
3443 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
3444 ret
= os_snprintf(pos
, end
- pos
, "[IBSS]");
3445 if (ret
< 0 || ret
>= end
- pos
)
3449 if (bss
->caps
& IEEE80211_CAP_ESS
) {
3450 ret
= os_snprintf(pos
, end
- pos
, "[ESS]");
3451 if (ret
< 0 || ret
>= end
- pos
)
3455 if (wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
) ||
3456 wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
)) {
3457 ret
= os_snprintf(pos
, end
- pos
, "[P2P]");
3458 if (ret
< 0 || ret
>= end
- pos
)
3463 if (wpa_bss_get_vendor_ie(bss
, HS20_IE_VENDOR_TYPE
)) {
3464 ret
= os_snprintf(pos
, end
- pos
, "[HS20]");
3465 if (ret
< 0 || ret
>= end
- pos
)
3469 #endif /* CONFIG_HS20 */
3471 ret
= os_snprintf(pos
, end
- pos
, "\n");
3472 if (ret
< 0 || ret
>= end
- pos
)
3477 if (mask
& WPA_BSS_MASK_SSID
) {
3478 ret
= os_snprintf(pos
, end
- pos
, "ssid=%s\n",
3479 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
3480 if (ret
< 0 || ret
>= end
- pos
)
3486 if (mask
& WPA_BSS_MASK_WPS_SCAN
) {
3487 ie
= (const u8
*) (bss
+ 1);
3488 ret
= wpas_wps_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
3489 if (ret
< 0 || ret
>= end
- pos
)
3493 #endif /* CONFIG_WPS */
3496 if (mask
& WPA_BSS_MASK_P2P_SCAN
) {
3497 ie
= (const u8
*) (bss
+ 1);
3498 ret
= wpas_p2p_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
3499 if (ret
< 0 || ret
>= end
- pos
)
3503 #endif /* CONFIG_P2P */
3505 #ifdef CONFIG_WIFI_DISPLAY
3506 if (mask
& WPA_BSS_MASK_WIFI_DISPLAY
) {
3508 ie
= (const u8
*) (bss
+ 1);
3509 wfd
= ieee802_11_vendor_ie_concat(ie
, bss
->ie_len
,
3510 WFD_IE_VENDOR_TYPE
);
3512 ret
= os_snprintf(pos
, end
- pos
, "wfd_subelems=");
3513 if (ret
< 0 || ret
>= end
- pos
) {
3519 pos
+= wpa_snprintf_hex(pos
, end
- pos
,
3524 ret
= os_snprintf(pos
, end
- pos
, "\n");
3525 if (ret
< 0 || ret
>= end
- pos
)
3530 #endif /* CONFIG_WIFI_DISPLAY */
3532 #ifdef CONFIG_INTERWORKING
3533 if ((mask
& WPA_BSS_MASK_INTERNETW
) && bss
->anqp
) {
3534 struct wpa_bss_anqp
*anqp
= bss
->anqp
;
3535 pos
= anqp_add_hex(pos
, end
, "anqp_venue_name",
3537 pos
= anqp_add_hex(pos
, end
, "anqp_network_auth_type",
3538 anqp
->network_auth_type
);
3539 pos
= anqp_add_hex(pos
, end
, "anqp_roaming_consortium",
3540 anqp
->roaming_consortium
);
3541 pos
= anqp_add_hex(pos
, end
, "anqp_ip_addr_type_availability",
3542 anqp
->ip_addr_type_availability
);
3543 pos
= anqp_add_hex(pos
, end
, "anqp_nai_realm",
3545 pos
= anqp_add_hex(pos
, end
, "anqp_3gpp", anqp
->anqp_3gpp
);
3546 pos
= anqp_add_hex(pos
, end
, "anqp_domain_name",
3549 pos
= anqp_add_hex(pos
, end
, "hs20_operator_friendly_name",
3550 anqp
->hs20_operator_friendly_name
);
3551 pos
= anqp_add_hex(pos
, end
, "hs20_wan_metrics",
3552 anqp
->hs20_wan_metrics
);
3553 pos
= anqp_add_hex(pos
, end
, "hs20_connection_capability",
3554 anqp
->hs20_connection_capability
);
3555 pos
= anqp_add_hex(pos
, end
, "hs20_operating_class",
3556 anqp
->hs20_operating_class
);
3557 pos
= anqp_add_hex(pos
, end
, "hs20_osu_providers_list",
3558 anqp
->hs20_osu_providers_list
);
3559 #endif /* CONFIG_HS20 */
3561 #endif /* CONFIG_INTERWORKING */
3563 if (mask
& WPA_BSS_MASK_DELIM
) {
3564 ret
= os_snprintf(pos
, end
- pos
, "====\n");
3565 if (ret
< 0 || ret
>= end
- pos
)
3574 static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant
*wpa_s
,
3575 const char *cmd
, char *buf
,
3580 struct wpa_bss
*bss
;
3581 struct wpa_bss
*bsslast
= NULL
;
3582 struct dl_list
*next
;
3586 unsigned long mask
= WPA_BSS_MASK_ALL
;
3588 if (os_strncmp(cmd
, "RANGE=", 6) == 0) {
3589 if (os_strncmp(cmd
+ 6, "ALL", 3) == 0) {
3590 bss
= dl_list_first(&wpa_s
->bss_id
, struct wpa_bss
,
3592 bsslast
= dl_list_last(&wpa_s
->bss_id
, struct wpa_bss
,
3594 } else { /* N1-N2 */
3595 unsigned int id1
, id2
;
3597 if ((ctmp
= os_strchr(cmd
+ 6, '-')) == NULL
) {
3598 wpa_printf(MSG_INFO
, "Wrong BSS range "
3603 if (*(cmd
+ 6) == '-')
3606 id1
= atoi(cmd
+ 6);
3608 if (*ctmp
>= '0' && *ctmp
<= '9')
3611 id2
= (unsigned int) -1;
3612 bss
= wpa_bss_get_id_range(wpa_s
, id1
, id2
);
3613 if (id2
== (unsigned int) -1)
3614 bsslast
= dl_list_last(&wpa_s
->bss_id
,
3618 bsslast
= wpa_bss_get_id(wpa_s
, id2
);
3619 if (bsslast
== NULL
&& bss
&& id2
> id1
) {
3620 struct wpa_bss
*tmp
= bss
;
3622 next
= tmp
->list_id
.next
;
3623 if (next
== &wpa_s
->bss_id
)
3625 tmp
= dl_list_entry(
3626 next
, struct wpa_bss
,
3635 } else if (os_strncmp(cmd
, "FIRST", 5) == 0)
3636 bss
= dl_list_first(&wpa_s
->bss_id
, struct wpa_bss
, list_id
);
3637 else if (os_strncmp(cmd
, "LAST", 4) == 0)
3638 bss
= dl_list_last(&wpa_s
->bss_id
, struct wpa_bss
, list_id
);
3639 else if (os_strncmp(cmd
, "ID-", 3) == 0) {
3641 bss
= wpa_bss_get_id(wpa_s
, i
);
3642 } else if (os_strncmp(cmd
, "NEXT-", 5) == 0) {
3644 bss
= wpa_bss_get_id(wpa_s
, i
);
3646 next
= bss
->list_id
.next
;
3647 if (next
== &wpa_s
->bss_id
)
3650 bss
= dl_list_entry(next
, struct wpa_bss
,
3654 } else if (os_strncmp(cmd
, "p2p_dev_addr=", 13) == 0) {
3655 if (hwaddr_aton(cmd
+ 13, bssid
) == 0)
3656 bss
= wpa_bss_get_p2p_dev_addr(wpa_s
, bssid
);
3659 #endif /* CONFIG_P2P */
3660 } else if (hwaddr_aton(cmd
, bssid
) == 0)
3661 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
3663 struct wpa_bss
*tmp
;
3666 dl_list_for_each(tmp
, &wpa_s
->bss_id
, struct wpa_bss
, list_id
)
3675 if ((ctmp
= os_strstr(cmd
, "MASK=")) != NULL
) {
3676 mask
= strtoul(ctmp
+ 5, NULL
, 0x10);
3678 mask
= WPA_BSS_MASK_ALL
;
3684 if (bsslast
== NULL
)
3687 len
= print_bss_info(wpa_s
, bss
, mask
, buf
, buflen
);
3691 if (bss
== bsslast
) {
3692 if ((mask
& WPA_BSS_MASK_DELIM
) && len
&&
3693 (bss
== dl_list_last(&wpa_s
->bss_id
,
3694 struct wpa_bss
, list_id
)))
3695 os_snprintf(buf
- 5, 5, "####\n");
3698 next
= bss
->list_id
.next
;
3699 if (next
== &wpa_s
->bss_id
)
3701 bss
= dl_list_entry(next
, struct wpa_bss
, list_id
);
3702 } while (bss
&& len
);
3708 static int wpa_supplicant_ctrl_iface_ap_scan(
3709 struct wpa_supplicant
*wpa_s
, char *cmd
)
3711 int ap_scan
= atoi(cmd
);
3712 return wpa_supplicant_set_ap_scan(wpa_s
, ap_scan
);
3716 static int wpa_supplicant_ctrl_iface_scan_interval(
3717 struct wpa_supplicant
*wpa_s
, char *cmd
)
3719 int scan_int
= atoi(cmd
);
3720 return wpa_supplicant_set_scan_interval(wpa_s
, scan_int
);
3724 static int wpa_supplicant_ctrl_iface_bss_expire_age(
3725 struct wpa_supplicant
*wpa_s
, char *cmd
)
3727 int expire_age
= atoi(cmd
);
3728 return wpa_supplicant_set_bss_expiration_age(wpa_s
, expire_age
);
3732 static int wpa_supplicant_ctrl_iface_bss_expire_count(
3733 struct wpa_supplicant
*wpa_s
, char *cmd
)
3735 int expire_count
= atoi(cmd
);
3736 return wpa_supplicant_set_bss_expiration_count(wpa_s
, expire_count
);
3740 static int wpa_supplicant_ctrl_iface_bss_flush(
3741 struct wpa_supplicant
*wpa_s
, char *cmd
)
3743 int flush_age
= atoi(cmd
);
3746 wpa_bss_flush(wpa_s
);
3748 wpa_bss_flush_by_age(wpa_s
, flush_age
);
3753 static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant
*wpa_s
)
3755 wpa_printf(MSG_DEBUG
, "Dropping SA without deauthentication");
3756 /* MLME-DELETEKEYS.request */
3757 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 0, 0, NULL
, 0, NULL
, 0);
3758 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 1, 0, NULL
, 0, NULL
, 0);
3759 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 2, 0, NULL
, 0, NULL
, 0);
3760 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 3, 0, NULL
, 0, NULL
, 0);
3761 #ifdef CONFIG_IEEE80211W
3762 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 4, 0, NULL
, 0, NULL
, 0);
3763 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 5, 0, NULL
, 0, NULL
, 0);
3764 #endif /* CONFIG_IEEE80211W */
3766 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, wpa_s
->bssid
, 0, 0, NULL
, 0, NULL
,
3768 /* MLME-SETPROTECTION.request(None) */
3769 wpa_drv_mlme_setprotection(wpa_s
, wpa_s
->bssid
,
3770 MLME_SETPROTECTION_PROTECT_TYPE_NONE
,
3771 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE
);
3772 wpa_sm_drop_sa(wpa_s
->wpa
);
3776 static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant
*wpa_s
,
3779 #ifdef CONFIG_NO_SCAN_PROCESSING
3781 #else /* CONFIG_NO_SCAN_PROCESSING */
3783 struct wpa_bss
*bss
;
3784 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
3786 if (hwaddr_aton(addr
, bssid
)) {
3787 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: invalid "
3788 "address '%s'", addr
);
3792 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM " MACSTR
, MAC2STR(bssid
));
3795 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: No network "
3796 "configuration known for the target AP");
3800 bss
= wpa_bss_get(wpa_s
, bssid
, ssid
->ssid
, ssid
->ssid_len
);
3802 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: Target AP not found "
3808 * TODO: Find best network configuration block from configuration to
3809 * allow roaming to other networks
3812 wpa_s
->reassociate
= 1;
3813 wpa_supplicant_connect(wpa_s
, bss
, ssid
);
3816 #endif /* CONFIG_NO_SCAN_PROCESSING */
3821 static int p2p_ctrl_find(struct wpa_supplicant
*wpa_s
, char *cmd
)
3823 unsigned int timeout
= atoi(cmd
);
3824 enum p2p_discovery_type type
= P2P_FIND_START_WITH_FULL
;
3825 u8 dev_id
[ETH_ALEN
], *_dev_id
= NULL
;
3826 u8 dev_type
[WPS_DEV_TYPE_LEN
], *_dev_type
= NULL
;
3828 unsigned int search_delay
;
3830 if (os_strstr(cmd
, "type=social"))
3831 type
= P2P_FIND_ONLY_SOCIAL
;
3832 else if (os_strstr(cmd
, "type=progressive"))
3833 type
= P2P_FIND_PROGRESSIVE
;
3835 pos
= os_strstr(cmd
, "dev_id=");
3838 if (hwaddr_aton(pos
, dev_id
))
3843 pos
= os_strstr(cmd
, "dev_type=");
3846 if (wps_dev_type_str2bin(pos
, dev_type
) < 0)
3848 _dev_type
= dev_type
;
3851 pos
= os_strstr(cmd
, "delay=");
3854 search_delay
= atoi(pos
);
3856 search_delay
= wpas_p2p_search_delay(wpa_s
);
3858 return wpas_p2p_find(wpa_s
, timeout
, type
, _dev_type
!= NULL
, _dev_type
,
3859 _dev_id
, search_delay
);
3863 static int p2p_ctrl_connect(struct wpa_supplicant
*wpa_s
, char *cmd
,
3864 char *buf
, size_t buflen
)
3869 enum p2p_wps_method wps_method
;
3872 int persistent_group
, persistent_id
= -1;
3881 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad]
3882 * [persistent|persistent=<network id>]
3883 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
3886 if (hwaddr_aton(cmd
, addr
))
3894 persistent_group
= os_strstr(pos
, " persistent") != NULL
;
3895 pos2
= os_strstr(pos
, " persistent=");
3897 struct wpa_ssid
*ssid
;
3898 persistent_id
= atoi(pos2
+ 12);
3899 ssid
= wpa_config_get_network(wpa_s
->conf
, persistent_id
);
3900 if (ssid
== NULL
|| ssid
->disabled
!= 2 ||
3901 ssid
->mode
!= WPAS_MODE_P2P_GO
) {
3902 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3903 "SSID id=%d for persistent P2P group (GO)",
3908 join
= os_strstr(pos
, " join") != NULL
;
3909 auth
= os_strstr(pos
, " auth") != NULL
;
3910 automatic
= os_strstr(pos
, " auto") != NULL
;
3911 pd
= os_strstr(pos
, " provdisc") != NULL
;
3912 vht
= (os_strstr(cmd
, " vht") != NULL
) || wpa_s
->conf
->p2p_go_vht
;
3913 ht40
= (os_strstr(cmd
, " ht40") != NULL
) || wpa_s
->conf
->p2p_go_ht40
||
3916 pos2
= os_strstr(pos
, " go_intent=");
3919 go_intent
= atoi(pos2
);
3920 if (go_intent
< 0 || go_intent
> 15)
3924 pos2
= os_strstr(pos
, " freq=");
3932 if (os_strncmp(pos
, "pin", 3) == 0) {
3933 /* Request random PIN (to be displayed) and enable the PIN */
3934 wps_method
= WPS_PIN_DISPLAY
;
3935 } else if (os_strncmp(pos
, "pbc", 3) == 0) {
3936 wps_method
= WPS_PBC
;
3939 pos
= os_strchr(pin
, ' ');
3940 wps_method
= WPS_PIN_KEYPAD
;
3943 if (os_strncmp(pos
, "display", 7) == 0)
3944 wps_method
= WPS_PIN_DISPLAY
;
3946 if (!wps_pin_str_valid(pin
)) {
3947 os_memcpy(buf
, "FAIL-INVALID-PIN\n", 17);
3952 new_pin
= wpas_p2p_connect(wpa_s
, addr
, pin
, wps_method
,
3953 persistent_group
, automatic
, join
,
3954 auth
, go_intent
, freq
, persistent_id
, pd
,
3956 if (new_pin
== -2) {
3957 os_memcpy(buf
, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
3960 if (new_pin
== -3) {
3961 os_memcpy(buf
, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
3966 if (wps_method
== WPS_PIN_DISPLAY
&& pin
== NULL
) {
3967 ret
= os_snprintf(buf
, buflen
, "%08d", new_pin
);
3968 if (ret
< 0 || (size_t) ret
>= buflen
)
3973 os_memcpy(buf
, "OK\n", 3);
3978 static int p2p_ctrl_listen(struct wpa_supplicant
*wpa_s
, char *cmd
)
3980 unsigned int timeout
= atoi(cmd
);
3981 return wpas_p2p_listen(wpa_s
, timeout
);
3985 static int p2p_ctrl_prov_disc(struct wpa_supplicant
*wpa_s
, char *cmd
)
3989 enum wpas_p2p_prov_disc_use use
= WPAS_P2P_PD_FOR_GO_NEG
;
3991 /* <addr> <config method> [join|auto] */
3993 if (hwaddr_aton(cmd
, addr
))
4001 if (os_strstr(pos
, " join") != NULL
)
4002 use
= WPAS_P2P_PD_FOR_JOIN
;
4003 else if (os_strstr(pos
, " auto") != NULL
)
4004 use
= WPAS_P2P_PD_AUTO
;
4006 return wpas_p2p_prov_disc(wpa_s
, addr
, pos
, use
);
4010 static int p2p_get_passphrase(struct wpa_supplicant
*wpa_s
, char *buf
,
4013 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
4015 if (ssid
== NULL
|| ssid
->mode
!= WPAS_MODE_P2P_GO
||
4016 ssid
->passphrase
== NULL
)
4019 os_strlcpy(buf
, ssid
->passphrase
, buflen
);
4020 return os_strlen(buf
);
4024 static int p2p_ctrl_serv_disc_req(struct wpa_supplicant
*wpa_s
, char *cmd
,
4025 char *buf
, size_t buflen
)
4029 u8 dst_buf
[ETH_ALEN
], *dst
;
4030 struct wpabuf
*tlvs
;
4034 if (hwaddr_aton(cmd
, dst_buf
))
4037 if (dst
[0] == 0 && dst
[1] == 0 && dst
[2] == 0 &&
4038 dst
[3] == 0 && dst
[4] == 0 && dst
[5] == 0)
4045 if (os_strncmp(pos
, "upnp ", 5) == 0) {
4048 if (hexstr2bin(pos
, &version
, 1) < 0)
4054 ref
= wpas_p2p_sd_request_upnp(wpa_s
, dst
, version
, pos
);
4055 #ifdef CONFIG_WIFI_DISPLAY
4056 } else if (os_strncmp(pos
, "wifi-display ", 13) == 0) {
4057 ref
= wpas_p2p_sd_request_wifi_display(wpa_s
, dst
, pos
+ 13);
4058 #endif /* CONFIG_WIFI_DISPLAY */
4060 len
= os_strlen(pos
);
4064 tlvs
= wpabuf_alloc(len
);
4067 if (hexstr2bin(pos
, wpabuf_put(tlvs
, len
), len
) < 0) {
4072 ref
= wpas_p2p_sd_request(wpa_s
, dst
, tlvs
);
4077 res
= os_snprintf(buf
, buflen
, "%llx", (long long unsigned) ref
);
4078 if (res
< 0 || (unsigned) res
>= buflen
)
4084 static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant
*wpa_s
,
4087 long long unsigned val
;
4089 if (sscanf(cmd
, "%llx", &val
) != 1)
4092 return wpas_p2p_sd_cancel_request(wpa_s
, req
);
4096 static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant
*wpa_s
, char *cmd
)
4101 struct wpabuf
*resp_tlvs
;
4105 pos
= os_strchr(cmd
, ' ');
4113 if (hwaddr_aton(pos
, dst
))
4120 pos2
= os_strchr(pos
, ' ');
4124 dialog_token
= atoi(pos
);
4126 len
= os_strlen(pos2
);
4130 resp_tlvs
= wpabuf_alloc(len
);
4131 if (resp_tlvs
== NULL
)
4133 if (hexstr2bin(pos2
, wpabuf_put(resp_tlvs
, len
), len
) < 0) {
4134 wpabuf_free(resp_tlvs
);
4138 wpas_p2p_sd_response(wpa_s
, freq
, dst
, dialog_token
, resp_tlvs
);
4139 wpabuf_free(resp_tlvs
);
4144 static int p2p_ctrl_serv_disc_external(struct wpa_supplicant
*wpa_s
,
4147 if (os_strcmp(cmd
, "0") && os_strcmp(cmd
, "1"))
4149 wpa_s
->p2p_sd_over_ctrl_iface
= atoi(cmd
);
4154 static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant
*wpa_s
,
4159 struct wpabuf
*query
, *resp
;
4161 pos
= os_strchr(cmd
, ' ');
4166 len
= os_strlen(cmd
);
4170 query
= wpabuf_alloc(len
);
4173 if (hexstr2bin(cmd
, wpabuf_put(query
, len
), len
) < 0) {
4178 len
= os_strlen(pos
);
4184 resp
= wpabuf_alloc(len
);
4189 if (hexstr2bin(pos
, wpabuf_put(resp
, len
), len
) < 0) {
4195 if (wpas_p2p_service_add_bonjour(wpa_s
, query
, resp
) < 0) {
4204 static int p2p_ctrl_service_add_upnp(struct wpa_supplicant
*wpa_s
, char *cmd
)
4209 pos
= os_strchr(cmd
, ' ');
4214 if (hexstr2bin(cmd
, &version
, 1) < 0)
4217 return wpas_p2p_service_add_upnp(wpa_s
, version
, pos
);
4221 static int p2p_ctrl_service_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
4225 pos
= os_strchr(cmd
, ' ');
4230 if (os_strcmp(cmd
, "bonjour") == 0)
4231 return p2p_ctrl_service_add_bonjour(wpa_s
, pos
);
4232 if (os_strcmp(cmd
, "upnp") == 0)
4233 return p2p_ctrl_service_add_upnp(wpa_s
, pos
);
4234 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
4239 static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant
*wpa_s
,
4243 struct wpabuf
*query
;
4246 len
= os_strlen(cmd
);
4250 query
= wpabuf_alloc(len
);
4253 if (hexstr2bin(cmd
, wpabuf_put(query
, len
), len
) < 0) {
4258 ret
= wpas_p2p_service_del_bonjour(wpa_s
, query
);
4264 static int p2p_ctrl_service_del_upnp(struct wpa_supplicant
*wpa_s
, char *cmd
)
4269 pos
= os_strchr(cmd
, ' ');
4274 if (hexstr2bin(cmd
, &version
, 1) < 0)
4277 return wpas_p2p_service_del_upnp(wpa_s
, version
, pos
);
4281 static int p2p_ctrl_service_del(struct wpa_supplicant
*wpa_s
, char *cmd
)
4285 pos
= os_strchr(cmd
, ' ');
4290 if (os_strcmp(cmd
, "bonjour") == 0)
4291 return p2p_ctrl_service_del_bonjour(wpa_s
, pos
);
4292 if (os_strcmp(cmd
, "upnp") == 0)
4293 return p2p_ctrl_service_del_upnp(wpa_s
, pos
);
4294 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
4299 static int p2p_ctrl_reject(struct wpa_supplicant
*wpa_s
, char *cmd
)
4305 if (hwaddr_aton(cmd
, addr
))
4308 return wpas_p2p_reject(wpa_s
, addr
);
4312 static int p2p_ctrl_invite_persistent(struct wpa_supplicant
*wpa_s
, char *cmd
)
4316 struct wpa_ssid
*ssid
;
4317 u8
*_peer
= NULL
, peer
[ETH_ALEN
];
4318 int freq
= 0, pref_freq
= 0;
4322 pos
= os_strstr(cmd
, " peer=");
4325 if (hwaddr_aton(pos
, peer
))
4329 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
4330 if (ssid
== NULL
|| ssid
->disabled
!= 2) {
4331 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
4332 "for persistent P2P group",
4337 pos
= os_strstr(cmd
, " freq=");
4345 pos
= os_strstr(cmd
, " pref=");
4348 pref_freq
= atoi(pos
);
4353 vht
= (os_strstr(cmd
, " vht") != NULL
) || wpa_s
->conf
->p2p_go_vht
;
4354 ht40
= (os_strstr(cmd
, " ht40") != NULL
) || wpa_s
->conf
->p2p_go_ht40
||
4357 return wpas_p2p_invite(wpa_s
, _peer
, ssid
, NULL
, freq
, ht40
, vht
,
4362 static int p2p_ctrl_invite_group(struct wpa_supplicant
*wpa_s
, char *cmd
)
4365 u8 peer
[ETH_ALEN
], go_dev_addr
[ETH_ALEN
], *go_dev
= NULL
;
4367 pos
= os_strstr(cmd
, " peer=");
4373 if (hwaddr_aton(pos
, peer
)) {
4374 wpa_printf(MSG_DEBUG
, "P2P: Invalid MAC address '%s'", pos
);
4378 pos
= os_strstr(pos
, " go_dev_addr=");
4381 if (hwaddr_aton(pos
, go_dev_addr
)) {
4382 wpa_printf(MSG_DEBUG
, "P2P: Invalid MAC address '%s'",
4386 go_dev
= go_dev_addr
;
4389 return wpas_p2p_invite_group(wpa_s
, cmd
, peer
, go_dev
);
4393 static int p2p_ctrl_invite(struct wpa_supplicant
*wpa_s
, char *cmd
)
4395 if (os_strncmp(cmd
, "persistent=", 11) == 0)
4396 return p2p_ctrl_invite_persistent(wpa_s
, cmd
+ 11);
4397 if (os_strncmp(cmd
, "group=", 6) == 0)
4398 return p2p_ctrl_invite_group(wpa_s
, cmd
+ 6);
4404 static int p2p_ctrl_group_add_persistent(struct wpa_supplicant
*wpa_s
,
4405 char *cmd
, int freq
, int ht40
,
4409 struct wpa_ssid
*ssid
;
4412 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
4413 if (ssid
== NULL
|| ssid
->disabled
!= 2) {
4414 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
4415 "for persistent P2P group",
4420 return wpas_p2p_group_add_persistent(wpa_s
, ssid
, 0, freq
, 0, ht40
, vht
,
4425 static int p2p_ctrl_group_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
4427 int freq
= 0, ht40
, vht
;
4430 pos
= os_strstr(cmd
, "freq=");
4432 freq
= atoi(pos
+ 5);
4434 vht
= (os_strstr(cmd
, "vht") != NULL
) || wpa_s
->conf
->p2p_go_vht
;
4435 ht40
= (os_strstr(cmd
, "ht40") != NULL
) || wpa_s
->conf
->p2p_go_ht40
||
4438 if (os_strncmp(cmd
, "persistent=", 11) == 0)
4439 return p2p_ctrl_group_add_persistent(wpa_s
, cmd
+ 11, freq
,
4441 if (os_strcmp(cmd
, "persistent") == 0 ||
4442 os_strncmp(cmd
, "persistent ", 11) == 0)
4443 return wpas_p2p_group_add(wpa_s
, 1, freq
, ht40
, vht
);
4444 if (os_strncmp(cmd
, "freq=", 5) == 0)
4445 return wpas_p2p_group_add(wpa_s
, 0, freq
, ht40
, vht
);
4447 return wpas_p2p_group_add(wpa_s
, 0, freq
, ht40
, vht
);
4449 wpa_printf(MSG_DEBUG
, "CTRL: Invalid P2P_GROUP_ADD parameters '%s'",
4455 static int p2p_ctrl_peer(struct wpa_supplicant
*wpa_s
, char *cmd
,
4456 char *buf
, size_t buflen
)
4458 u8 addr
[ETH_ALEN
], *addr_ptr
;
4460 const struct p2p_peer_info
*info
;
4462 char devtype
[WPS_DEV_TYPE_BUFSIZE
];
4463 struct wpa_ssid
*ssid
;
4466 if (!wpa_s
->global
->p2p
)
4469 if (os_strcmp(cmd
, "FIRST") == 0) {
4472 } else if (os_strncmp(cmd
, "NEXT-", 5) == 0) {
4473 if (hwaddr_aton(cmd
+ 5, addr
) < 0)
4478 if (hwaddr_aton(cmd
, addr
) < 0)
4484 info
= p2p_get_peer_info(wpa_s
->global
->p2p
, addr_ptr
, next
);
4491 res
= os_snprintf(pos
, end
- pos
, MACSTR
"\n"
4497 "serial_number=%s\n"
4498 "config_methods=0x%x\n"
4500 "group_capab=0x%x\n"
4502 MAC2STR(info
->p2p_device_addr
),
4503 wps_dev_type_bin2str(info
->pri_dev_type
,
4504 devtype
, sizeof(devtype
)),
4509 info
->serial_number
,
4510 info
->config_methods
,
4514 if (res
< 0 || res
>= end
- pos
)
4518 for (i
= 0; i
< info
->wps_sec_dev_type_list_len
/ WPS_DEV_TYPE_LEN
; i
++)
4521 t
= &info
->wps_sec_dev_type_list
[i
* WPS_DEV_TYPE_LEN
];
4522 res
= os_snprintf(pos
, end
- pos
, "sec_dev_type=%s\n",
4523 wps_dev_type_bin2str(t
, devtype
,
4525 if (res
< 0 || res
>= end
- pos
)
4530 ssid
= wpas_p2p_get_persistent(wpa_s
, info
->p2p_device_addr
, NULL
, 0);
4532 res
= os_snprintf(pos
, end
- pos
, "persistent=%d\n", ssid
->id
);
4533 if (res
< 0 || res
>= end
- pos
)
4538 res
= p2p_get_peer_info_txt(info
, pos
, end
- pos
);
4547 static int p2p_ctrl_disallow_freq(struct wpa_supplicant
*wpa_s
,
4552 if (wpa_s
->global
->p2p
== NULL
)
4555 if (freq_range_list_parse(&wpa_s
->global
->p2p_disallow_freq
, param
) < 0)
4558 for (i
= 0; i
< wpa_s
->global
->p2p_disallow_freq
.num
; i
++) {
4559 struct wpa_freq_range
*freq
;
4560 freq
= &wpa_s
->global
->p2p_disallow_freq
.range
[i
];
4561 wpa_printf(MSG_DEBUG
, "P2P: Disallowed frequency range %u-%u",
4562 freq
->min
, freq
->max
);
4565 wpas_p2p_update_channel_list(wpa_s
);
4570 static int p2p_ctrl_set(struct wpa_supplicant
*wpa_s
, char *cmd
)
4574 if (wpa_s
->global
->p2p
== NULL
)
4577 param
= os_strchr(cmd
, ' ');
4582 if (os_strcmp(cmd
, "discoverability") == 0) {
4583 p2p_set_client_discoverability(wpa_s
->global
->p2p
,
4588 if (os_strcmp(cmd
, "managed") == 0) {
4589 p2p_set_managed_oper(wpa_s
->global
->p2p
, atoi(param
));
4593 if (os_strcmp(cmd
, "listen_channel") == 0) {
4594 return p2p_set_listen_channel(wpa_s
->global
->p2p
, 81,
4598 if (os_strcmp(cmd
, "ssid_postfix") == 0) {
4599 return p2p_set_ssid_postfix(wpa_s
->global
->p2p
, (u8
*) param
,
4603 if (os_strcmp(cmd
, "noa") == 0) {
4605 int count
, start
, duration
;
4606 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
4607 count
= atoi(param
);
4608 pos
= os_strchr(param
, ',');
4613 pos
= os_strchr(pos
, ',');
4617 duration
= atoi(pos
);
4618 if (count
< 0 || count
> 255 || start
< 0 || duration
< 0)
4620 if (count
== 0 && duration
> 0)
4622 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
4623 "start=%d duration=%d", count
, start
, duration
);
4624 return wpas_p2p_set_noa(wpa_s
, count
, start
, duration
);
4627 if (os_strcmp(cmd
, "ps") == 0)
4628 return wpa_drv_set_p2p_powersave(wpa_s
, atoi(param
), -1, -1);
4630 if (os_strcmp(cmd
, "oppps") == 0)
4631 return wpa_drv_set_p2p_powersave(wpa_s
, -1, atoi(param
), -1);
4633 if (os_strcmp(cmd
, "ctwindow") == 0)
4634 return wpa_drv_set_p2p_powersave(wpa_s
, -1, -1, atoi(param
));
4636 if (os_strcmp(cmd
, "disabled") == 0) {
4637 wpa_s
->global
->p2p_disabled
= atoi(param
);
4638 wpa_printf(MSG_DEBUG
, "P2P functionality %s",
4639 wpa_s
->global
->p2p_disabled
?
4640 "disabled" : "enabled");
4641 if (wpa_s
->global
->p2p_disabled
) {
4642 wpas_p2p_stop_find(wpa_s
);
4643 os_memset(wpa_s
->p2p_auth_invite
, 0, ETH_ALEN
);
4644 p2p_flush(wpa_s
->global
->p2p
);
4649 if (os_strcmp(cmd
, "conc_pref") == 0) {
4650 if (os_strcmp(param
, "sta") == 0)
4651 wpa_s
->global
->conc_pref
= WPA_CONC_PREF_STA
;
4652 else if (os_strcmp(param
, "p2p") == 0)
4653 wpa_s
->global
->conc_pref
= WPA_CONC_PREF_P2P
;
4655 wpa_printf(MSG_INFO
, "Invalid conc_pref value");
4658 wpa_printf(MSG_DEBUG
, "Single channel concurrency preference: "
4663 if (os_strcmp(cmd
, "force_long_sd") == 0) {
4664 wpa_s
->force_long_sd
= atoi(param
);
4668 if (os_strcmp(cmd
, "peer_filter") == 0) {
4670 if (hwaddr_aton(param
, addr
))
4672 p2p_set_peer_filter(wpa_s
->global
->p2p
, addr
);
4676 if (os_strcmp(cmd
, "cross_connect") == 0)
4677 return wpas_p2p_set_cross_connect(wpa_s
, atoi(param
));
4679 if (os_strcmp(cmd
, "go_apsd") == 0) {
4680 if (os_strcmp(param
, "disable") == 0)
4681 wpa_s
->set_ap_uapsd
= 0;
4683 wpa_s
->set_ap_uapsd
= 1;
4684 wpa_s
->ap_uapsd
= atoi(param
);
4689 if (os_strcmp(cmd
, "client_apsd") == 0) {
4690 if (os_strcmp(param
, "disable") == 0)
4691 wpa_s
->set_sta_uapsd
= 0;
4695 /* format: BE,BK,VI,VO;max SP Length */
4697 pos
= os_strchr(param
, ',');
4702 pos
= os_strchr(pos
, ',');
4707 pos
= os_strchr(pos
, ',');
4712 /* ignore max SP Length for now */
4714 wpa_s
->set_sta_uapsd
= 1;
4715 wpa_s
->sta_uapsd
= 0;
4717 wpa_s
->sta_uapsd
|= BIT(0);
4719 wpa_s
->sta_uapsd
|= BIT(1);
4721 wpa_s
->sta_uapsd
|= BIT(2);
4723 wpa_s
->sta_uapsd
|= BIT(3);
4728 if (os_strcmp(cmd
, "disallow_freq") == 0)
4729 return p2p_ctrl_disallow_freq(wpa_s
, param
);
4731 if (os_strcmp(cmd
, "disc_int") == 0) {
4732 int min_disc_int
, max_disc_int
, max_disc_tu
;
4737 min_disc_int
= atoi(pos
);
4738 pos
= os_strchr(pos
, ' ');
4743 max_disc_int
= atoi(pos
);
4744 pos
= os_strchr(pos
, ' ');
4749 max_disc_tu
= atoi(pos
);
4751 return p2p_set_disc_int(wpa_s
->global
->p2p
, min_disc_int
,
4752 max_disc_int
, max_disc_tu
);
4755 if (os_strcmp(cmd
, "per_sta_psk") == 0) {
4756 wpa_s
->global
->p2p_per_sta_psk
= !!atoi(param
);
4760 #ifdef CONFIG_WPS_NFC
4761 if (os_strcmp(cmd
, "nfc_tag") == 0)
4762 return wpas_p2p_nfc_tag_enabled(wpa_s
, !!atoi(param
));
4763 #endif /* CONFIG_WPS_NFC */
4765 if (os_strcmp(cmd
, "disable_ip_addr_req") == 0) {
4766 wpa_s
->p2p_disable_ip_addr_req
= !!atoi(param
);
4770 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
4777 static void p2p_ctrl_flush(struct wpa_supplicant
*wpa_s
)
4779 os_memset(wpa_s
->p2p_auth_invite
, 0, ETH_ALEN
);
4780 wpa_s
->force_long_sd
= 0;
4781 if (wpa_s
->global
->p2p
)
4782 p2p_flush(wpa_s
->global
->p2p
);
4786 static int p2p_ctrl_presence_req(struct wpa_supplicant
*wpa_s
, char *cmd
)
4789 unsigned int dur1
= 0, int1
= 0, dur2
= 0, int2
= 0;
4792 pos
= os_strchr(cmd
, ' ');
4798 pos2
= os_strchr(pos
, ' ');
4806 pos
= os_strchr(pos2
, ' ');
4814 return wpas_p2p_presence_req(wpa_s
, dur1
, int1
, dur2
, int2
);
4818 static int p2p_ctrl_ext_listen(struct wpa_supplicant
*wpa_s
, char *cmd
)
4821 unsigned int period
= 0, interval
= 0;
4824 pos
= os_strchr(cmd
, ' ');
4829 interval
= atoi(pos
);
4832 return wpas_p2p_ext_listen(wpa_s
, period
, interval
);
4836 static int p2p_ctrl_remove_client(struct wpa_supplicant
*wpa_s
, const char *cmd
)
4843 if (os_strncmp(pos
, "iface=", 6) == 0) {
4847 if (hwaddr_aton(pos
, peer
))
4850 wpas_p2p_remove_client(wpa_s
, peer
, iface_addr
);
4854 #endif /* CONFIG_P2P */
4857 static int * freq_range_to_channel_list(struct wpa_supplicant
*wpa_s
, char *val
)
4859 struct wpa_freq_range_list ranges
;
4861 struct hostapd_hw_modes
*mode
;
4864 if (wpa_s
->hw
.modes
== NULL
)
4867 os_memset(&ranges
, 0, sizeof(ranges
));
4868 if (freq_range_list_parse(&ranges
, val
) < 0)
4871 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
4874 mode
= &wpa_s
->hw
.modes
[i
];
4875 for (j
= 0; j
< mode
->num_channels
; j
++) {
4878 if (mode
->channels
[j
].flag
& HOSTAPD_CHAN_DISABLED
)
4881 freq
= mode
->channels
[j
].freq
;
4882 if (!freq_range_list_includes(&ranges
, freq
))
4885 int_array_add_unique(&freqs
, freq
);
4889 os_free(ranges
.range
);
4894 #ifdef CONFIG_INTERWORKING
4896 static int ctrl_interworking_select(struct wpa_supplicant
*wpa_s
, char *param
)
4904 auto_sel
= os_strstr(param
, "auto") != NULL
;
4906 pos
= os_strstr(param
, "freq=");
4908 freqs
= freq_range_to_channel_list(wpa_s
, pos
+ 5);
4915 return interworking_select(wpa_s
, auto_sel
, freqs
);
4919 static int ctrl_interworking_connect(struct wpa_supplicant
*wpa_s
, char *dst
)
4922 struct wpa_bss
*bss
;
4924 if (hwaddr_aton(dst
, bssid
)) {
4925 wpa_printf(MSG_DEBUG
, "Invalid BSSID '%s'", dst
);
4929 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
4931 wpa_printf(MSG_DEBUG
, "Could not find BSS " MACSTR
,
4936 return interworking_connect(wpa_s
, bss
);
4940 static int get_anqp(struct wpa_supplicant
*wpa_s
, char *dst
)
4942 u8 dst_addr
[ETH_ALEN
];
4945 #define MAX_ANQP_INFO_ID 100
4946 u16 id
[MAX_ANQP_INFO_ID
];
4950 used
= hwaddr_aton2(dst
, dst_addr
);
4954 while (num_id
< MAX_ANQP_INFO_ID
) {
4955 if (os_strncmp(pos
, "hs20:", 5) == 0) {
4957 int num
= atoi(pos
+ 5);
4958 if (num
<= 0 || num
> 31)
4960 subtypes
|= BIT(num
);
4961 #else /* CONFIG_HS20 */
4963 #endif /* CONFIG_HS20 */
4965 id
[num_id
] = atoi(pos
);
4969 pos
= os_strchr(pos
+ 1, ',');
4978 return anqp_send_req(wpa_s
, dst_addr
, id
, num_id
, subtypes
);
4982 static int gas_request(struct wpa_supplicant
*wpa_s
, char *cmd
)
4984 u8 dst_addr
[ETH_ALEN
];
4985 struct wpabuf
*advproto
, *query
= NULL
;
4990 used
= hwaddr_aton2(cmd
, dst_addr
);
4998 /* Advertisement Protocol ID */
4999 end
= os_strchr(pos
, ' ');
5003 len
= os_strlen(pos
);
5009 advproto
= wpabuf_alloc(len
);
5010 if (advproto
== NULL
)
5012 if (hexstr2bin(pos
, wpabuf_put(advproto
, len
), len
) < 0)
5016 /* Optional Query Request */
5021 len
= os_strlen(pos
);
5028 query
= wpabuf_alloc(len
);
5031 if (hexstr2bin(pos
, wpabuf_put(query
, len
), len
) < 0)
5036 ret
= gas_send_request(wpa_s
, dst_addr
, advproto
, query
);
5039 wpabuf_free(advproto
);
5046 static int gas_response_get(struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
,
5053 size_t resp_len
, start
, requested_len
;
5054 struct wpabuf
*resp
;
5057 used
= hwaddr_aton2(cmd
, addr
);
5064 dialog_token
= atoi(pos
);
5066 if (wpa_s
->last_gas_resp
&&
5067 os_memcmp(addr
, wpa_s
->last_gas_addr
, ETH_ALEN
) == 0 &&
5068 dialog_token
== wpa_s
->last_gas_dialog_token
)
5069 resp
= wpa_s
->last_gas_resp
;
5070 else if (wpa_s
->prev_gas_resp
&&
5071 os_memcmp(addr
, wpa_s
->prev_gas_addr
, ETH_ALEN
) == 0 &&
5072 dialog_token
== wpa_s
->prev_gas_dialog_token
)
5073 resp
= wpa_s
->prev_gas_resp
;
5077 resp_len
= wpabuf_len(resp
);
5079 requested_len
= resp_len
;
5081 pos
= os_strchr(pos
, ' ');
5084 if (start
> resp_len
)
5085 return os_snprintf(buf
, buflen
, "FAIL-Invalid range");
5086 pos
= os_strchr(pos
, ',');
5090 requested_len
= atoi(pos
);
5091 if (start
+ requested_len
> resp_len
)
5092 return os_snprintf(buf
, buflen
, "FAIL-Invalid range");
5095 if (requested_len
* 2 + 1 > buflen
)
5096 return os_snprintf(buf
, buflen
, "FAIL-Too long response");
5098 ret
= wpa_snprintf_hex(buf
, buflen
, wpabuf_head_u8(resp
) + start
,
5101 if (start
+ requested_len
== resp_len
) {
5103 * Free memory by dropping the response after it has been
5106 if (resp
== wpa_s
->prev_gas_resp
) {
5107 wpabuf_free(wpa_s
->prev_gas_resp
);
5108 wpa_s
->prev_gas_resp
= NULL
;
5110 wpabuf_free(wpa_s
->last_gas_resp
);
5111 wpa_s
->last_gas_resp
= NULL
;
5117 #endif /* CONFIG_INTERWORKING */
5122 static int get_hs20_anqp(struct wpa_supplicant
*wpa_s
, char *dst
)
5124 u8 dst_addr
[ETH_ALEN
];
5129 used
= hwaddr_aton2(dst
, dst_addr
);
5134 int num
= atoi(pos
);
5135 if (num
<= 0 || num
> 31)
5137 subtypes
|= BIT(num
);
5138 pos
= os_strchr(pos
+ 1, ',');
5147 return hs20_anqp_send_req(wpa_s
, dst_addr
, subtypes
, NULL
, 0);
5151 static int hs20_nai_home_realm_list(struct wpa_supplicant
*wpa_s
,
5152 const u8
*addr
, const char *realm
)
5158 rlen
= os_strlen(realm
);
5160 buf
= os_malloc(len
);
5163 buf
[0] = 1; /* NAI Home Realm Count */
5164 buf
[1] = 0; /* Formatted in accordance with RFC 4282 */
5166 os_memcpy(buf
+ 3, realm
, rlen
);
5168 ret
= hs20_anqp_send_req(wpa_s
, addr
,
5169 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY
),
5178 static int hs20_get_nai_home_realm_list(struct wpa_supplicant
*wpa_s
,
5181 struct wpa_cred
*cred
= wpa_s
->conf
->cred
;
5182 u8 dst_addr
[ETH_ALEN
];
5188 used
= hwaddr_aton2(dst
, dst_addr
);
5192 while (dst
[used
] == ' ')
5194 if (os_strncmp(dst
+ used
, "realm=", 6) == 0)
5195 return hs20_nai_home_realm_list(wpa_s
, dst_addr
,
5198 len
= os_strlen(dst
+ used
);
5200 if (len
== 0 && cred
&& cred
->realm
)
5201 return hs20_nai_home_realm_list(wpa_s
, dst_addr
, cred
->realm
);
5206 buf
= os_malloc(len
);
5209 if (hexstr2bin(dst
+ used
, buf
, len
) < 0) {
5214 ret
= hs20_anqp_send_req(wpa_s
, dst_addr
,
5215 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY
),
5223 static int hs20_icon_request(struct wpa_supplicant
*wpa_s
, char *cmd
)
5225 u8 dst_addr
[ETH_ALEN
];
5229 used
= hwaddr_aton2(cmd
, dst_addr
);
5233 while (cmd
[used
] == ' ')
5237 wpa_s
->fetch_osu_icon_in_progress
= 0;
5238 return hs20_anqp_send_req(wpa_s
, dst_addr
, BIT(HS20_STYPE_ICON_REQUEST
),
5239 (u8
*) icon
, os_strlen(icon
));
5242 #endif /* CONFIG_HS20 */
5245 static int wpa_supplicant_ctrl_iface_sta_autoconnect(
5246 struct wpa_supplicant
*wpa_s
, char *cmd
)
5248 wpa_s
->auto_reconnect_disabled
= atoi(cmd
) == 0 ? 1 : 0;
5253 #ifdef CONFIG_AUTOSCAN
5255 static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant
*wpa_s
,
5258 enum wpa_states state
= wpa_s
->wpa_state
;
5259 char *new_params
= NULL
;
5261 if (os_strlen(cmd
) > 0) {
5262 new_params
= os_strdup(cmd
);
5263 if (new_params
== NULL
)
5267 os_free(wpa_s
->conf
->autoscan
);
5268 wpa_s
->conf
->autoscan
= new_params
;
5270 if (wpa_s
->conf
->autoscan
== NULL
)
5271 autoscan_deinit(wpa_s
);
5272 else if (state
== WPA_DISCONNECTED
|| state
== WPA_INACTIVE
)
5273 autoscan_init(wpa_s
, 1);
5274 else if (state
== WPA_SCANNING
)
5275 wpa_supplicant_reinit_autoscan(wpa_s
);
5280 #endif /* CONFIG_AUTOSCAN */
5285 static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant
*wpa_s
, char *cmd
)
5291 struct wpabuf
*tfs_req
= NULL
;
5293 if (os_strncmp(cmd
, "enter", 5) == 0)
5295 else if (os_strncmp(cmd
, "exit", 4) == 0)
5300 pos
= os_strstr(cmd
, " interval=");
5302 intval
= atoi(pos
+ 10);
5304 pos
= os_strstr(cmd
, " tfs_req=");
5309 end
= os_strchr(pos
, ' ');
5313 len
= os_strlen(pos
);
5317 tfs_req
= wpabuf_alloc(len
);
5318 if (tfs_req
== NULL
)
5320 if (hexstr2bin(pos
, wpabuf_put(tfs_req
, len
), len
) < 0) {
5321 wpabuf_free(tfs_req
);
5326 ret
= ieee802_11_send_wnmsleep_req(wpa_s
, enter
? WNM_SLEEP_MODE_ENTER
:
5327 WNM_SLEEP_MODE_EXIT
, intval
,
5329 wpabuf_free(tfs_req
);
5335 static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant
*wpa_s
, char *cmd
)
5339 query_reason
= atoi(cmd
);
5341 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d",
5344 return wnm_send_bss_transition_mgmt_query(wpa_s
, query_reason
);
5347 #endif /* CONFIG_WNM */
5350 /* Get string representation of channel width */
5351 static const char * channel_width_name(enum chan_width width
)
5354 case CHAN_WIDTH_20_NOHT
:
5355 return "20 MHz (no HT)";
5362 case CHAN_WIDTH_80P80
:
5364 case CHAN_WIDTH_160
:
5372 static int wpa_supplicant_signal_poll(struct wpa_supplicant
*wpa_s
, char *buf
,
5375 struct wpa_signal_info si
;
5379 ret
= wpa_drv_signal_poll(wpa_s
, &si
);
5386 ret
= os_snprintf(pos
, end
- pos
, "RSSI=%d\nLINKSPEED=%d\n"
5387 "NOISE=%d\nFREQUENCY=%u\n",
5388 si
.current_signal
, si
.current_txrate
/ 1000,
5389 si
.current_noise
, si
.frequency
);
5390 if (ret
< 0 || ret
> end
- pos
)
5394 if (si
.chanwidth
!= CHAN_WIDTH_UNKNOWN
) {
5395 ret
= os_snprintf(pos
, end
- pos
, "WIDTH=%s\n",
5396 channel_width_name(si
.chanwidth
));
5397 if (ret
< 0 || ret
> end
- pos
)
5402 if (si
.center_frq1
> 0 && si
.center_frq2
> 0) {
5403 ret
= os_snprintf(pos
, end
- pos
,
5404 "CENTER_FRQ1=%d\nCENTER_FRQ2=%d\n",
5405 si
.center_frq1
, si
.center_frq2
);
5406 if (ret
< 0 || ret
> end
- pos
)
5411 if (si
.avg_signal
) {
5412 ret
= os_snprintf(pos
, end
- pos
,
5413 "AVG_RSSI=%d\n", si
.avg_signal
);
5414 if (ret
< 0 || ret
>= end
- pos
)
5423 static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant
*wpa_s
, char *buf
,
5426 struct hostap_sta_driver_data sta
;
5429 ret
= wpa_drv_pktcnt_poll(wpa_s
, &sta
);
5433 ret
= os_snprintf(buf
, buflen
, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
5434 sta
.tx_packets
, sta
.tx_retry_failed
, sta
.rx_packets
);
5435 if (ret
< 0 || (size_t) ret
> buflen
)
5442 static int wpa_supplicant_driver_cmd(struct wpa_supplicant
*wpa_s
, char *cmd
,
5443 char *buf
, size_t buflen
)
5447 ret
= wpa_drv_driver_cmd(wpa_s
, cmd
, buf
, buflen
);
5449 if (os_strncasecmp(cmd
, "COUNTRY", 7) == 0) {
5450 struct p2p_data
*p2p
= wpa_s
->global
->p2p
;
5453 country
[0] = cmd
[8];
5454 country
[1] = cmd
[9];
5456 p2p_set_country(p2p
, country
);
5459 ret
= os_snprintf(buf
, buflen
, "%s\n", "OK");
5463 #endif /* ANDROID */
5466 static int wpa_supplicant_vendor_cmd(struct wpa_supplicant
*wpa_s
, char *cmd
,
5467 char *buf
, size_t buflen
)
5472 unsigned int vendor_id
, subcmd
;
5473 struct wpabuf
*reply
;
5474 size_t data_len
= 0;
5476 /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */
5477 vendor_id
= strtoul(cmd
, &pos
, 16);
5481 subcmd
= strtoul(pos
, &pos
, 10);
5484 if (!isblank(*pos
++))
5486 data_len
= os_strlen(pos
);
5491 data
= os_malloc(data_len
);
5495 if (hexstr2bin(pos
, data
, data_len
)) {
5496 wpa_printf(MSG_DEBUG
,
5497 "Vendor command: wrong parameter format");
5503 reply
= wpabuf_alloc((buflen
- 1) / 2);
5509 ret
= wpa_drv_vendor_cmd(wpa_s
, vendor_id
, subcmd
, data
, data_len
,
5513 ret
= wpa_snprintf_hex(buf
, buflen
, wpabuf_head_u8(reply
),
5523 static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant
*wpa_s
)
5525 wpa_dbg(wpa_s
, MSG_DEBUG
, "Flush all wpa_supplicant state");
5528 wpas_p2p_stop_find(wpa_s
);
5529 p2p_ctrl_flush(wpa_s
);
5530 wpas_p2p_group_remove(wpa_s
, "*");
5531 wpas_p2p_service_flush(wpa_s
);
5532 wpa_s
->global
->p2p_disabled
= 0;
5533 wpa_s
->global
->p2p_per_sta_psk
= 0;
5534 wpa_s
->conf
->num_sec_device_types
= 0;
5535 wpa_s
->p2p_disable_ip_addr_req
= 0;
5536 #endif /* CONFIG_P2P */
5538 #ifdef CONFIG_WPS_TESTING
5539 wps_version_number
= 0x20;
5540 wps_testing_dummy_cred
= 0;
5541 wps_corrupt_pkhash
= 0;
5542 #endif /* CONFIG_WPS_TESTING */
5544 wpa_s
->wps_fragment_size
= 0;
5545 wpas_wps_cancel(wpa_s
);
5546 #endif /* CONFIG_WPS */
5547 wpa_s
->after_wps
= 0;
5548 wpa_s
->known_wps_freq
= 0;
5551 #ifdef CONFIG_TDLS_TESTING
5552 extern unsigned int tdls_testing
;
5554 #endif /* CONFIG_TDLS_TESTING */
5555 wpa_drv_tdls_oper(wpa_s
, TDLS_ENABLE
, NULL
);
5556 wpa_tdls_enable(wpa_s
->wpa
, 1);
5557 #endif /* CONFIG_TDLS */
5559 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures
, wpa_s
, NULL
);
5560 wpa_supplicant_stop_countermeasures(wpa_s
, NULL
);
5562 wpa_s
->no_keep_alive
= 0;
5564 os_free(wpa_s
->disallow_aps_bssid
);
5565 wpa_s
->disallow_aps_bssid
= NULL
;
5566 wpa_s
->disallow_aps_bssid_count
= 0;
5567 os_free(wpa_s
->disallow_aps_ssid
);
5568 wpa_s
->disallow_aps_ssid
= NULL
;
5569 wpa_s
->disallow_aps_ssid_count
= 0;
5571 wpa_s
->set_sta_uapsd
= 0;
5572 wpa_s
->sta_uapsd
= 0;
5574 wpa_drv_radio_disable(wpa_s
, 0);
5576 wpa_bss_flush(wpa_s
);
5577 wpa_blacklist_clear(wpa_s
);
5578 wpa_s
->extra_blacklist_count
= 0;
5579 wpa_supplicant_ctrl_iface_remove_network(wpa_s
, "all");
5580 wpa_supplicant_ctrl_iface_remove_cred(wpa_s
, "all");
5581 wpa_config_flush_blobs(wpa_s
->conf
);
5582 wpa_s
->conf
->auto_interworking
= 0;
5583 wpa_s
->conf
->okc
= 0;
5585 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_LIFETIME
, 43200);
5586 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_REAUTH_THRESHOLD
, 70);
5587 wpa_sm_set_param(wpa_s
->wpa
, RSNA_SA_TIMEOUT
, 60);
5588 eapol_sm_notify_logoff(wpa_s
->eapol
, FALSE
);
5590 radio_remove_works(wpa_s
, NULL
, 1);
5592 wpa_s
->next_ssid
= NULL
;
5594 #ifdef CONFIG_INTERWORKING
5595 hs20_cancel_fetch_osu(wpa_s
);
5596 #endif /* CONFIG_INTERWORKING */
5598 wpa_s
->ext_mgmt_frame_handling
= 0;
5602 static int wpas_ctrl_radio_work_show(struct wpa_supplicant
*wpa_s
,
5603 char *buf
, size_t buflen
)
5605 struct wpa_radio_work
*work
;
5607 struct os_reltime now
, diff
;
5612 os_get_reltime(&now
);
5614 dl_list_for_each(work
, &wpa_s
->radio
->work
, struct wpa_radio_work
, list
)
5618 os_reltime_sub(&now
, &work
->time
, &diff
);
5619 ret
= os_snprintf(pos
, end
- pos
, "%s@%s:%u:%u:%ld.%06ld\n",
5620 work
->type
, work
->wpa_s
->ifname
, work
->freq
,
5621 work
->started
, diff
.sec
, diff
.usec
);
5622 if (ret
< 0 || ret
>= end
- pos
)
5631 static void wpas_ctrl_radio_work_timeout(void *eloop_ctx
, void *timeout_ctx
)
5633 struct wpa_radio_work
*work
= eloop_ctx
;
5634 struct wpa_external_work
*ework
= work
->ctx
;
5636 wpa_dbg(work
->wpa_s
, MSG_DEBUG
,
5637 "Timing out external radio work %u (%s)",
5638 ework
->id
, work
->type
);
5639 wpa_msg(work
->wpa_s
, MSG_INFO
, EXT_RADIO_WORK_TIMEOUT
"%u", ework
->id
);
5641 radio_work_done(work
);
5645 static void wpas_ctrl_radio_work_cb(struct wpa_radio_work
*work
, int deinit
)
5647 struct wpa_external_work
*ework
= work
->ctx
;
5651 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
,
5658 wpa_dbg(work
->wpa_s
, MSG_DEBUG
, "Starting external radio work %u (%s)",
5659 ework
->id
, ework
->type
);
5660 wpa_msg(work
->wpa_s
, MSG_INFO
, EXT_RADIO_WORK_START
"%u", ework
->id
);
5661 if (!ework
->timeout
)
5662 ework
->timeout
= 10;
5663 eloop_register_timeout(ework
->timeout
, 0, wpas_ctrl_radio_work_timeout
,
5668 static int wpas_ctrl_radio_work_add(struct wpa_supplicant
*wpa_s
, char *cmd
,
5669 char *buf
, size_t buflen
)
5671 struct wpa_external_work
*ework
;
5675 unsigned int freq
= 0;
5677 /* format: <name> [freq=<MHz>] [timeout=<seconds>] */
5679 ework
= os_zalloc(sizeof(*ework
));
5683 pos
= os_strchr(cmd
, ' ');
5685 type_len
= pos
- cmd
;
5688 pos2
= os_strstr(pos
, "freq=");
5690 freq
= atoi(pos2
+ 5);
5692 pos2
= os_strstr(pos
, "timeout=");
5694 ework
->timeout
= atoi(pos2
+ 8);
5696 type_len
= os_strlen(cmd
);
5698 if (4 + type_len
>= sizeof(ework
->type
))
5699 type_len
= sizeof(ework
->type
) - 4 - 1;
5700 os_strlcpy(ework
->type
, "ext:", sizeof(ework
->type
));
5701 os_memcpy(ework
->type
+ 4, cmd
, type_len
);
5702 ework
->type
[4 + type_len
] = '\0';
5704 wpa_s
->ext_work_id
++;
5705 if (wpa_s
->ext_work_id
== 0)
5706 wpa_s
->ext_work_id
++;
5707 ework
->id
= wpa_s
->ext_work_id
;
5709 if (radio_add_work(wpa_s
, freq
, ework
->type
, 0, wpas_ctrl_radio_work_cb
,
5715 ret
= os_snprintf(buf
, buflen
, "%u", ework
->id
);
5716 if (ret
< 0 || (size_t) ret
>= buflen
)
5722 static int wpas_ctrl_radio_work_done(struct wpa_supplicant
*wpa_s
, char *cmd
)
5724 struct wpa_radio_work
*work
;
5725 unsigned int id
= atoi(cmd
);
5727 dl_list_for_each(work
, &wpa_s
->radio
->work
, struct wpa_radio_work
, list
)
5729 struct wpa_external_work
*ework
;
5731 if (os_strncmp(work
->type
, "ext:", 4) != 0)
5734 if (id
&& ework
->id
!= id
)
5736 wpa_dbg(wpa_s
, MSG_DEBUG
,
5737 "Completed external radio work %u (%s)",
5738 ework
->id
, ework
->type
);
5739 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
, work
, NULL
);
5740 radio_work_done(work
);
5742 return 3; /* "OK\n" */
5749 static int wpas_ctrl_radio_work(struct wpa_supplicant
*wpa_s
, char *cmd
,
5750 char *buf
, size_t buflen
)
5752 if (os_strcmp(cmd
, "show") == 0)
5753 return wpas_ctrl_radio_work_show(wpa_s
, buf
, buflen
);
5754 if (os_strncmp(cmd
, "add ", 4) == 0)
5755 return wpas_ctrl_radio_work_add(wpa_s
, cmd
+ 4, buf
, buflen
);
5756 if (os_strncmp(cmd
, "done ", 5) == 0)
5757 return wpas_ctrl_radio_work_done(wpa_s
, cmd
+ 4);
5762 void wpas_ctrl_radio_work_flush(struct wpa_supplicant
*wpa_s
)
5764 struct wpa_radio_work
*work
, *tmp
;
5766 if (!wpa_s
|| !wpa_s
->radio
)
5769 dl_list_for_each_safe(work
, tmp
, &wpa_s
->radio
->work
,
5770 struct wpa_radio_work
, list
) {
5771 struct wpa_external_work
*ework
;
5773 if (os_strncmp(work
->type
, "ext:", 4) != 0)
5776 wpa_dbg(wpa_s
, MSG_DEBUG
,
5777 "Flushing %sexternal radio work %u (%s)",
5778 work
->started
? " started" : "", ework
->id
,
5781 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
,
5784 radio_work_done(work
);
5789 static void wpas_ctrl_eapol_response(void *eloop_ctx
, void *timeout_ctx
)
5791 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
5792 eapol_sm_notify_ctrl_response(wpa_s
->eapol
);
5796 static int set_scan_freqs(struct wpa_supplicant
*wpa_s
, char *val
)
5800 freqs
= freq_range_to_channel_list(wpa_s
, val
);
5804 os_free(wpa_s
->manual_scan_freqs
);
5805 wpa_s
->manual_scan_freqs
= freqs
;
5811 static void wpas_ctrl_scan(struct wpa_supplicant
*wpa_s
, char *params
,
5812 char *reply
, int reply_size
, int *reply_len
)
5816 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
5821 wpa_s
->manual_scan_passive
= 0;
5822 wpa_s
->manual_scan_use_id
= 0;
5823 wpa_s
->manual_scan_only_new
= 0;
5826 if (os_strncasecmp(params
, "TYPE=ONLY", 9) == 0)
5827 wpa_s
->scan_res_handler
= scan_only_handler
;
5829 pos
= os_strstr(params
, "freq=");
5830 if (pos
&& set_scan_freqs(wpa_s
, pos
+ 5) < 0) {
5835 pos
= os_strstr(params
, "passive=");
5837 wpa_s
->manual_scan_passive
= !!atoi(pos
+ 8);
5839 pos
= os_strstr(params
, "use_id=");
5841 wpa_s
->manual_scan_use_id
= atoi(pos
+ 7);
5843 pos
= os_strstr(params
, "only_new=1");
5845 wpa_s
->manual_scan_only_new
= 1;
5847 os_free(wpa_s
->manual_scan_freqs
);
5848 wpa_s
->manual_scan_freqs
= NULL
;
5849 if (wpa_s
->scan_res_handler
== scan_only_handler
)
5850 wpa_s
->scan_res_handler
= NULL
;
5853 if (!wpa_s
->sched_scanning
&& !wpa_s
->scanning
&&
5854 ((wpa_s
->wpa_state
<= WPA_SCANNING
) ||
5855 (wpa_s
->wpa_state
== WPA_COMPLETED
))) {
5856 wpa_s
->normal_scans
= 0;
5857 wpa_s
->scan_req
= MANUAL_SCAN_REQ
;
5858 wpa_s
->after_wps
= 0;
5859 wpa_s
->known_wps_freq
= 0;
5860 wpa_supplicant_req_scan(wpa_s
, 0, 0);
5861 if (wpa_s
->manual_scan_use_id
) {
5862 wpa_s
->manual_scan_id
++;
5863 wpa_dbg(wpa_s
, MSG_DEBUG
, "Assigned scan id %u",
5864 wpa_s
->manual_scan_id
);
5865 *reply_len
= os_snprintf(reply
, reply_size
, "%u\n",
5866 wpa_s
->manual_scan_id
);
5868 } else if (wpa_s
->sched_scanning
) {
5869 wpa_printf(MSG_DEBUG
, "Stop ongoing sched_scan to allow requested full scan to proceed");
5870 wpa_supplicant_cancel_sched_scan(wpa_s
);
5871 wpa_s
->scan_req
= MANUAL_SCAN_REQ
;
5872 wpa_supplicant_req_scan(wpa_s
, 0, 0);
5873 if (wpa_s
->manual_scan_use_id
) {
5874 wpa_s
->manual_scan_id
++;
5875 *reply_len
= os_snprintf(reply
, reply_size
, "%u\n",
5876 wpa_s
->manual_scan_id
);
5877 wpa_dbg(wpa_s
, MSG_DEBUG
, "Assigned scan id %u",
5878 wpa_s
->manual_scan_id
);
5881 wpa_printf(MSG_DEBUG
, "Ongoing scan action - reject new request");
5882 *reply_len
= os_snprintf(reply
, reply_size
, "FAIL-BUSY\n");
5887 #ifdef CONFIG_TESTING_OPTIONS
5889 static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant
*wpa_s
,
5890 unsigned int freq
, const u8
*dst
,
5891 const u8
*src
, const u8
*bssid
,
5892 const u8
*data
, size_t data_len
,
5893 enum offchannel_send_action_result
5896 wpa_msg(wpa_s
, MSG_INFO
, "MGMT-TX-STATUS freq=%u dst=" MACSTR
5897 " src=" MACSTR
" bssid=" MACSTR
" result=%s",
5898 freq
, MAC2STR(dst
), MAC2STR(src
), MAC2STR(bssid
),
5899 result
== OFFCHANNEL_SEND_ACTION_SUCCESS
?
5900 "SUCCESS" : (result
== OFFCHANNEL_SEND_ACTION_NO_ACK
?
5901 "NO_ACK" : "FAILED"));
5905 static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant
*wpa_s
, char *cmd
)
5909 u8
*buf
, da
[ETH_ALEN
], bssid
[ETH_ALEN
];
5911 int freq
= 0, no_cck
= 0, wait_time
= 0;
5913 /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1]
5914 * <action=Action frame payload> */
5916 wpa_printf(MSG_DEBUG
, "External MGMT TX: %s", cmd
);
5919 used
= hwaddr_aton2(pos
, da
);
5925 used
= hwaddr_aton2(pos
, bssid
);
5930 param
= os_strstr(pos
, " freq=");
5936 param
= os_strstr(pos
, " no_cck=");
5939 no_cck
= atoi(param
);
5942 param
= os_strstr(pos
, " wait_time=");
5945 wait_time
= atoi(param
);
5948 param
= os_strstr(pos
, " action=");
5953 len
= os_strlen(param
);
5958 buf
= os_malloc(len
);
5962 if (hexstr2bin(param
, buf
, len
) < 0) {
5967 res
= offchannel_send_action(wpa_s
, freq
, da
, wpa_s
->own_addr
, bssid
,
5968 buf
, len
, wait_time
,
5969 wpas_ctrl_iface_mgmt_tx_cb
, no_cck
);
5975 static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant
*wpa_s
)
5977 wpa_printf(MSG_DEBUG
, "External MGMT TX - done waiting");
5978 offchannel_send_action_done(wpa_s
);
5981 #endif /* CONFIG_TESTING_OPTIONS */
5984 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant
*wpa_s
,
5985 char *buf
, size_t *resp_len
)
5988 const int reply_size
= 4096;
5991 if (os_strncmp(buf
, WPA_CTRL_RSP
, os_strlen(WPA_CTRL_RSP
)) == 0 ||
5992 os_strncmp(buf
, "SET_NETWORK ", 12) == 0) {
5993 if (wpa_debug_show_keys
)
5994 wpa_dbg(wpa_s
, MSG_DEBUG
,
5995 "Control interface command '%s'", buf
);
5997 wpa_dbg(wpa_s
, MSG_DEBUG
,
5998 "Control interface command '%s [REMOVED]'",
5999 os_strncmp(buf
, WPA_CTRL_RSP
,
6000 os_strlen(WPA_CTRL_RSP
)) == 0 ?
6001 WPA_CTRL_RSP
: "SET_NETWORK");
6002 } else if (os_strncmp(buf
, "WPS_NFC_TAG_READ", 16) == 0 ||
6003 os_strncmp(buf
, "NFC_REPORT_HANDOVER", 19) == 0 ||
6004 os_strncmp(buf
, "NFC_RX_HANDOVER_SEL", 19) == 0) {
6005 wpa_hexdump_ascii_key(MSG_DEBUG
, "RX ctrl_iface",
6006 (const u8
*) buf
, os_strlen(buf
));
6008 int level
= MSG_DEBUG
;
6009 if (os_strcmp(buf
, "PING") == 0)
6010 level
= MSG_EXCESSIVE
;
6011 wpa_dbg(wpa_s
, level
, "Control interface command '%s'", buf
);
6014 reply
= os_malloc(reply_size
);
6015 if (reply
== NULL
) {
6020 os_memcpy(reply
, "OK\n", 3);
6023 if (os_strcmp(buf
, "PING") == 0) {
6024 os_memcpy(reply
, "PONG\n", 5);
6026 } else if (os_strcmp(buf
, "IFNAME") == 0) {
6027 reply_len
= os_strlen(wpa_s
->ifname
);
6028 os_memcpy(reply
, wpa_s
->ifname
, reply_len
);
6029 } else if (os_strncmp(buf
, "RELOG", 5) == 0) {
6030 if (wpa_debug_reopen_file() < 0)
6032 } else if (os_strncmp(buf
, "NOTE ", 5) == 0) {
6033 wpa_printf(MSG_INFO
, "NOTE: %s", buf
+ 5);
6034 } else if (os_strcmp(buf
, "MIB") == 0) {
6035 reply_len
= wpa_sm_get_mib(wpa_s
->wpa
, reply
, reply_size
);
6036 if (reply_len
>= 0) {
6038 res
= eapol_sm_get_mib(wpa_s
->eapol
, reply
+ reply_len
,
6039 reply_size
- reply_len
);
6045 } else if (os_strncmp(buf
, "STATUS", 6) == 0) {
6046 reply_len
= wpa_supplicant_ctrl_iface_status(
6047 wpa_s
, buf
+ 6, reply
, reply_size
);
6048 } else if (os_strcmp(buf
, "PMKSA") == 0) {
6049 reply_len
= wpa_sm_pmksa_cache_list(wpa_s
->wpa
, reply
,
6051 } else if (os_strncmp(buf
, "SET ", 4) == 0) {
6052 if (wpa_supplicant_ctrl_iface_set(wpa_s
, buf
+ 4))
6054 } else if (os_strncmp(buf
, "GET ", 4) == 0) {
6055 reply_len
= wpa_supplicant_ctrl_iface_get(wpa_s
, buf
+ 4,
6057 } else if (os_strcmp(buf
, "LOGON") == 0) {
6058 eapol_sm_notify_logoff(wpa_s
->eapol
, FALSE
);
6059 } else if (os_strcmp(buf
, "LOGOFF") == 0) {
6060 eapol_sm_notify_logoff(wpa_s
->eapol
, TRUE
);
6061 } else if (os_strcmp(buf
, "REASSOCIATE") == 0) {
6062 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
6065 wpas_request_connection(wpa_s
);
6066 } else if (os_strcmp(buf
, "REATTACH") == 0) {
6067 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
||
6068 !wpa_s
->current_ssid
)
6071 wpa_s
->reattach
= 1;
6072 wpas_request_connection(wpa_s
);
6074 } else if (os_strcmp(buf
, "RECONNECT") == 0) {
6075 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
6077 else if (wpa_s
->disconnected
)
6078 wpas_request_connection(wpa_s
);
6079 #ifdef IEEE8021X_EAPOL
6080 } else if (os_strncmp(buf
, "PREAUTH ", 8) == 0) {
6081 if (wpa_supplicant_ctrl_iface_preauth(wpa_s
, buf
+ 8))
6083 #endif /* IEEE8021X_EAPOL */
6084 #ifdef CONFIG_PEERKEY
6085 } else if (os_strncmp(buf
, "STKSTART ", 9) == 0) {
6086 if (wpa_supplicant_ctrl_iface_stkstart(wpa_s
, buf
+ 9))
6088 #endif /* CONFIG_PEERKEY */
6089 #ifdef CONFIG_IEEE80211R
6090 } else if (os_strncmp(buf
, "FT_DS ", 6) == 0) {
6091 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s
, buf
+ 6))
6093 #endif /* CONFIG_IEEE80211R */
6095 } else if (os_strcmp(buf
, "WPS_PBC") == 0) {
6096 int res
= wpa_supplicant_ctrl_iface_wps_pbc(wpa_s
, NULL
);
6098 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
6102 } else if (os_strncmp(buf
, "WPS_PBC ", 8) == 0) {
6103 int res
= wpa_supplicant_ctrl_iface_wps_pbc(wpa_s
, buf
+ 8);
6105 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
6109 } else if (os_strncmp(buf
, "WPS_PIN ", 8) == 0) {
6110 reply_len
= wpa_supplicant_ctrl_iface_wps_pin(wpa_s
, buf
+ 8,
6113 } else if (os_strncmp(buf
, "WPS_CHECK_PIN ", 14) == 0) {
6114 reply_len
= wpa_supplicant_ctrl_iface_wps_check_pin(
6115 wpa_s
, buf
+ 14, reply
, reply_size
);
6116 } else if (os_strcmp(buf
, "WPS_CANCEL") == 0) {
6117 if (wpas_wps_cancel(wpa_s
))
6119 #ifdef CONFIG_WPS_NFC
6120 } else if (os_strcmp(buf
, "WPS_NFC") == 0) {
6121 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s
, NULL
))
6123 } else if (os_strncmp(buf
, "WPS_NFC ", 8) == 0) {
6124 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s
, buf
+ 8))
6126 } else if (os_strncmp(buf
, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
6127 reply_len
= wpa_supplicant_ctrl_iface_wps_nfc_config_token(
6128 wpa_s
, buf
+ 21, reply
, reply_size
);
6129 } else if (os_strncmp(buf
, "WPS_NFC_TOKEN ", 14) == 0) {
6130 reply_len
= wpa_supplicant_ctrl_iface_wps_nfc_token(
6131 wpa_s
, buf
+ 14, reply
, reply_size
);
6132 } else if (os_strncmp(buf
, "WPS_NFC_TAG_READ ", 17) == 0) {
6133 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s
,
6136 } else if (os_strncmp(buf
, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
6137 reply_len
= wpas_ctrl_nfc_get_handover_req(
6138 wpa_s
, buf
+ 21, reply
, reply_size
);
6139 } else if (os_strncmp(buf
, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
6140 reply_len
= wpas_ctrl_nfc_get_handover_sel(
6141 wpa_s
, buf
+ 21, reply
, reply_size
);
6142 } else if (os_strncmp(buf
, "NFC_RX_HANDOVER_SEL ", 20) == 0) {
6143 if (wpas_ctrl_nfc_rx_handover_sel(wpa_s
, buf
+ 20))
6145 } else if (os_strncmp(buf
, "NFC_REPORT_HANDOVER ", 20) == 0) {
6146 if (wpas_ctrl_nfc_report_handover(wpa_s
, buf
+ 20))
6148 #endif /* CONFIG_WPS_NFC */
6149 } else if (os_strncmp(buf
, "WPS_REG ", 8) == 0) {
6150 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s
, buf
+ 8))
6153 } else if (os_strncmp(buf
, "WPS_AP_PIN ", 11) == 0) {
6154 reply_len
= wpa_supplicant_ctrl_iface_wps_ap_pin(
6155 wpa_s
, buf
+ 11, reply
, reply_size
);
6156 #endif /* CONFIG_AP */
6157 #ifdef CONFIG_WPS_ER
6158 } else if (os_strcmp(buf
, "WPS_ER_START") == 0) {
6159 if (wpas_wps_er_start(wpa_s
, NULL
))
6161 } else if (os_strncmp(buf
, "WPS_ER_START ", 13) == 0) {
6162 if (wpas_wps_er_start(wpa_s
, buf
+ 13))
6164 } else if (os_strcmp(buf
, "WPS_ER_STOP") == 0) {
6165 if (wpas_wps_er_stop(wpa_s
))
6167 } else if (os_strncmp(buf
, "WPS_ER_PIN ", 11) == 0) {
6168 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s
, buf
+ 11))
6170 } else if (os_strncmp(buf
, "WPS_ER_PBC ", 11) == 0) {
6171 int ret
= wpas_wps_er_pbc(wpa_s
, buf
+ 11);
6173 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
6175 } else if (ret
== -3) {
6176 os_memcpy(reply
, "FAIL-UNKNOWN-UUID\n", 18);
6178 } else if (ret
== -4) {
6179 os_memcpy(reply
, "FAIL-NO-AP-SETTINGS\n", 20);
6183 } else if (os_strncmp(buf
, "WPS_ER_LEARN ", 13) == 0) {
6184 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s
, buf
+ 13))
6186 } else if (os_strncmp(buf
, "WPS_ER_SET_CONFIG ", 18) == 0) {
6187 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s
,
6190 } else if (os_strncmp(buf
, "WPS_ER_CONFIG ", 14) == 0) {
6191 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s
, buf
+ 14))
6193 #ifdef CONFIG_WPS_NFC
6194 } else if (os_strncmp(buf
, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
6195 reply_len
= wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
6196 wpa_s
, buf
+ 24, reply
, reply_size
);
6197 #endif /* CONFIG_WPS_NFC */
6198 #endif /* CONFIG_WPS_ER */
6199 #endif /* CONFIG_WPS */
6200 #ifdef CONFIG_IBSS_RSN
6201 } else if (os_strncmp(buf
, "IBSS_RSN ", 9) == 0) {
6202 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s
, buf
+ 9))
6204 #endif /* CONFIG_IBSS_RSN */
6206 } else if (os_strncmp(buf
, "P2P_FIND ", 9) == 0) {
6207 if (p2p_ctrl_find(wpa_s
, buf
+ 9))
6209 } else if (os_strcmp(buf
, "P2P_FIND") == 0) {
6210 if (p2p_ctrl_find(wpa_s
, ""))
6212 } else if (os_strcmp(buf
, "P2P_STOP_FIND") == 0) {
6213 wpas_p2p_stop_find(wpa_s
);
6214 } else if (os_strncmp(buf
, "P2P_CONNECT ", 12) == 0) {
6215 reply_len
= p2p_ctrl_connect(wpa_s
, buf
+ 12, reply
,
6217 } else if (os_strncmp(buf
, "P2P_LISTEN ", 11) == 0) {
6218 if (p2p_ctrl_listen(wpa_s
, buf
+ 11))
6220 } else if (os_strcmp(buf
, "P2P_LISTEN") == 0) {
6221 if (p2p_ctrl_listen(wpa_s
, ""))
6223 } else if (os_strncmp(buf
, "P2P_GROUP_REMOVE ", 17) == 0) {
6224 if (wpas_p2p_group_remove(wpa_s
, buf
+ 17))
6226 } else if (os_strcmp(buf
, "P2P_GROUP_ADD") == 0) {
6227 if (wpas_p2p_group_add(wpa_s
, 0, 0, 0, 0))
6229 } else if (os_strncmp(buf
, "P2P_GROUP_ADD ", 14) == 0) {
6230 if (p2p_ctrl_group_add(wpa_s
, buf
+ 14))
6232 } else if (os_strncmp(buf
, "P2P_PROV_DISC ", 14) == 0) {
6233 if (p2p_ctrl_prov_disc(wpa_s
, buf
+ 14))
6235 } else if (os_strcmp(buf
, "P2P_GET_PASSPHRASE") == 0) {
6236 reply_len
= p2p_get_passphrase(wpa_s
, reply
, reply_size
);
6237 } else if (os_strncmp(buf
, "P2P_SERV_DISC_REQ ", 18) == 0) {
6238 reply_len
= p2p_ctrl_serv_disc_req(wpa_s
, buf
+ 18, reply
,
6240 } else if (os_strncmp(buf
, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
6241 if (p2p_ctrl_serv_disc_cancel_req(wpa_s
, buf
+ 25) < 0)
6243 } else if (os_strncmp(buf
, "P2P_SERV_DISC_RESP ", 19) == 0) {
6244 if (p2p_ctrl_serv_disc_resp(wpa_s
, buf
+ 19) < 0)
6246 } else if (os_strcmp(buf
, "P2P_SERVICE_UPDATE") == 0) {
6247 wpas_p2p_sd_service_update(wpa_s
);
6248 } else if (os_strncmp(buf
, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
6249 if (p2p_ctrl_serv_disc_external(wpa_s
, buf
+ 23) < 0)
6251 } else if (os_strcmp(buf
, "P2P_SERVICE_FLUSH") == 0) {
6252 wpas_p2p_service_flush(wpa_s
);
6253 } else if (os_strncmp(buf
, "P2P_SERVICE_ADD ", 16) == 0) {
6254 if (p2p_ctrl_service_add(wpa_s
, buf
+ 16) < 0)
6256 } else if (os_strncmp(buf
, "P2P_SERVICE_DEL ", 16) == 0) {
6257 if (p2p_ctrl_service_del(wpa_s
, buf
+ 16) < 0)
6259 } else if (os_strncmp(buf
, "P2P_REJECT ", 11) == 0) {
6260 if (p2p_ctrl_reject(wpa_s
, buf
+ 11) < 0)
6262 } else if (os_strncmp(buf
, "P2P_INVITE ", 11) == 0) {
6263 if (p2p_ctrl_invite(wpa_s
, buf
+ 11) < 0)
6265 } else if (os_strncmp(buf
, "P2P_PEER ", 9) == 0) {
6266 reply_len
= p2p_ctrl_peer(wpa_s
, buf
+ 9, reply
,
6268 } else if (os_strncmp(buf
, "P2P_SET ", 8) == 0) {
6269 if (p2p_ctrl_set(wpa_s
, buf
+ 8) < 0)
6271 } else if (os_strcmp(buf
, "P2P_FLUSH") == 0) {
6272 p2p_ctrl_flush(wpa_s
);
6273 } else if (os_strncmp(buf
, "P2P_UNAUTHORIZE ", 16) == 0) {
6274 if (wpas_p2p_unauthorize(wpa_s
, buf
+ 16) < 0)
6276 } else if (os_strcmp(buf
, "P2P_CANCEL") == 0) {
6277 if (wpas_p2p_cancel(wpa_s
))
6279 } else if (os_strncmp(buf
, "P2P_PRESENCE_REQ ", 17) == 0) {
6280 if (p2p_ctrl_presence_req(wpa_s
, buf
+ 17) < 0)
6282 } else if (os_strcmp(buf
, "P2P_PRESENCE_REQ") == 0) {
6283 if (p2p_ctrl_presence_req(wpa_s
, "") < 0)
6285 } else if (os_strncmp(buf
, "P2P_EXT_LISTEN ", 15) == 0) {
6286 if (p2p_ctrl_ext_listen(wpa_s
, buf
+ 15) < 0)
6288 } else if (os_strcmp(buf
, "P2P_EXT_LISTEN") == 0) {
6289 if (p2p_ctrl_ext_listen(wpa_s
, "") < 0)
6291 } else if (os_strncmp(buf
, "P2P_REMOVE_CLIENT ", 18) == 0) {
6292 if (p2p_ctrl_remove_client(wpa_s
, buf
+ 18) < 0)
6294 #endif /* CONFIG_P2P */
6295 #ifdef CONFIG_WIFI_DISPLAY
6296 } else if (os_strncmp(buf
, "WFD_SUBELEM_SET ", 16) == 0) {
6297 if (wifi_display_subelem_set(wpa_s
->global
, buf
+ 16) < 0)
6299 } else if (os_strncmp(buf
, "WFD_SUBELEM_GET ", 16) == 0) {
6300 reply_len
= wifi_display_subelem_get(wpa_s
->global
, buf
+ 16,
6302 #endif /* CONFIG_WIFI_DISPLAY */
6303 #ifdef CONFIG_INTERWORKING
6304 } else if (os_strcmp(buf
, "FETCH_ANQP") == 0) {
6305 if (interworking_fetch_anqp(wpa_s
) < 0)
6307 } else if (os_strcmp(buf
, "STOP_FETCH_ANQP") == 0) {
6308 interworking_stop_fetch_anqp(wpa_s
);
6309 } else if (os_strcmp(buf
, "INTERWORKING_SELECT") == 0) {
6310 if (ctrl_interworking_select(wpa_s
, NULL
) < 0)
6312 } else if (os_strncmp(buf
, "INTERWORKING_SELECT ", 20) == 0) {
6313 if (ctrl_interworking_select(wpa_s
, buf
+ 20) < 0)
6315 } else if (os_strncmp(buf
, "INTERWORKING_CONNECT ", 21) == 0) {
6316 if (ctrl_interworking_connect(wpa_s
, buf
+ 21) < 0)
6318 } else if (os_strncmp(buf
, "ANQP_GET ", 9) == 0) {
6319 if (get_anqp(wpa_s
, buf
+ 9) < 0)
6321 } else if (os_strncmp(buf
, "GAS_REQUEST ", 12) == 0) {
6322 if (gas_request(wpa_s
, buf
+ 12) < 0)
6324 } else if (os_strncmp(buf
, "GAS_RESPONSE_GET ", 17) == 0) {
6325 reply_len
= gas_response_get(wpa_s
, buf
+ 17, reply
,
6327 #endif /* CONFIG_INTERWORKING */
6329 } else if (os_strncmp(buf
, "HS20_ANQP_GET ", 14) == 0) {
6330 if (get_hs20_anqp(wpa_s
, buf
+ 14) < 0)
6332 } else if (os_strncmp(buf
, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
6333 if (hs20_get_nai_home_realm_list(wpa_s
, buf
+ 29) < 0)
6335 } else if (os_strncmp(buf
, "HS20_ICON_REQUEST ", 18) == 0) {
6336 if (hs20_icon_request(wpa_s
, buf
+ 18) < 0)
6338 } else if (os_strcmp(buf
, "FETCH_OSU") == 0) {
6339 if (hs20_fetch_osu(wpa_s
) < 0)
6341 } else if (os_strcmp(buf
, "CANCEL_FETCH_OSU") == 0) {
6342 hs20_cancel_fetch_osu(wpa_s
);
6343 #endif /* CONFIG_HS20 */
6344 } else if (os_strncmp(buf
, WPA_CTRL_RSP
, os_strlen(WPA_CTRL_RSP
)) == 0)
6346 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
6347 wpa_s
, buf
+ os_strlen(WPA_CTRL_RSP
)))
6351 * Notify response from timeout to allow the control
6352 * interface response to be sent first.
6354 eloop_register_timeout(0, 0, wpas_ctrl_eapol_response
,
6357 } else if (os_strcmp(buf
, "RECONFIGURE") == 0) {
6358 if (wpa_supplicant_reload_configuration(wpa_s
))
6360 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
6361 wpa_supplicant_terminate_proc(wpa_s
->global
);
6362 } else if (os_strncmp(buf
, "BSSID ", 6) == 0) {
6363 if (wpa_supplicant_ctrl_iface_bssid(wpa_s
, buf
+ 6))
6365 } else if (os_strncmp(buf
, "BLACKLIST", 9) == 0) {
6366 reply_len
= wpa_supplicant_ctrl_iface_blacklist(
6367 wpa_s
, buf
+ 9, reply
, reply_size
);
6368 } else if (os_strncmp(buf
, "LOG_LEVEL", 9) == 0) {
6369 reply_len
= wpa_supplicant_ctrl_iface_log_level(
6370 wpa_s
, buf
+ 9, reply
, reply_size
);
6371 } else if (os_strcmp(buf
, "LIST_NETWORKS") == 0) {
6372 reply_len
= wpa_supplicant_ctrl_iface_list_networks(
6373 wpa_s
, reply
, reply_size
);
6374 } else if (os_strcmp(buf
, "DISCONNECT") == 0) {
6376 wpa_s
->sme
.prev_bssid_set
= 0;
6377 #endif /* CONFIG_SME */
6378 wpa_s
->reassociate
= 0;
6379 wpa_s
->disconnected
= 1;
6380 wpa_supplicant_cancel_sched_scan(wpa_s
);
6381 wpa_supplicant_cancel_scan(wpa_s
);
6382 wpa_supplicant_deauthenticate(wpa_s
,
6383 WLAN_REASON_DEAUTH_LEAVING
);
6384 } else if (os_strcmp(buf
, "SCAN") == 0) {
6385 wpas_ctrl_scan(wpa_s
, NULL
, reply
, reply_size
, &reply_len
);
6386 } else if (os_strncmp(buf
, "SCAN ", 5) == 0) {
6387 wpas_ctrl_scan(wpa_s
, buf
+ 5, reply
, reply_size
, &reply_len
);
6388 } else if (os_strcmp(buf
, "SCAN_RESULTS") == 0) {
6389 reply_len
= wpa_supplicant_ctrl_iface_scan_results(
6390 wpa_s
, reply
, reply_size
);
6391 } else if (os_strncmp(buf
, "SELECT_NETWORK ", 15) == 0) {
6392 if (wpa_supplicant_ctrl_iface_select_network(wpa_s
, buf
+ 15))
6394 } else if (os_strncmp(buf
, "ENABLE_NETWORK ", 15) == 0) {
6395 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s
, buf
+ 15))
6397 } else if (os_strncmp(buf
, "DISABLE_NETWORK ", 16) == 0) {
6398 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s
, buf
+ 16))
6400 } else if (os_strcmp(buf
, "ADD_NETWORK") == 0) {
6401 reply_len
= wpa_supplicant_ctrl_iface_add_network(
6402 wpa_s
, reply
, reply_size
);
6403 } else if (os_strncmp(buf
, "REMOVE_NETWORK ", 15) == 0) {
6404 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s
, buf
+ 15))
6406 } else if (os_strncmp(buf
, "SET_NETWORK ", 12) == 0) {
6407 if (wpa_supplicant_ctrl_iface_set_network(wpa_s
, buf
+ 12))
6409 } else if (os_strncmp(buf
, "GET_NETWORK ", 12) == 0) {
6410 reply_len
= wpa_supplicant_ctrl_iface_get_network(
6411 wpa_s
, buf
+ 12, reply
, reply_size
);
6412 } else if (os_strcmp(buf
, "LIST_CREDS") == 0) {
6413 reply_len
= wpa_supplicant_ctrl_iface_list_creds(
6414 wpa_s
, reply
, reply_size
);
6415 } else if (os_strcmp(buf
, "ADD_CRED") == 0) {
6416 reply_len
= wpa_supplicant_ctrl_iface_add_cred(
6417 wpa_s
, reply
, reply_size
);
6418 } else if (os_strncmp(buf
, "REMOVE_CRED ", 12) == 0) {
6419 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s
, buf
+ 12))
6421 } else if (os_strncmp(buf
, "SET_CRED ", 9) == 0) {
6422 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s
, buf
+ 9))
6424 #ifndef CONFIG_NO_CONFIG_WRITE
6425 } else if (os_strcmp(buf
, "SAVE_CONFIG") == 0) {
6426 if (wpa_supplicant_ctrl_iface_save_config(wpa_s
))
6428 #endif /* CONFIG_NO_CONFIG_WRITE */
6429 } else if (os_strncmp(buf
, "GET_CAPABILITY ", 15) == 0) {
6430 reply_len
= wpa_supplicant_ctrl_iface_get_capability(
6431 wpa_s
, buf
+ 15, reply
, reply_size
);
6432 } else if (os_strncmp(buf
, "AP_SCAN ", 8) == 0) {
6433 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s
, buf
+ 8))
6435 } else if (os_strncmp(buf
, "SCAN_INTERVAL ", 14) == 0) {
6436 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s
, buf
+ 14))
6438 } else if (os_strcmp(buf
, "INTERFACE_LIST") == 0) {
6439 reply_len
= wpa_supplicant_global_iface_list(
6440 wpa_s
->global
, reply
, reply_size
);
6441 } else if (os_strcmp(buf
, "INTERFACES") == 0) {
6442 reply_len
= wpa_supplicant_global_iface_interfaces(
6443 wpa_s
->global
, reply
, reply_size
);
6444 } else if (os_strncmp(buf
, "BSS ", 4) == 0) {
6445 reply_len
= wpa_supplicant_ctrl_iface_bss(
6446 wpa_s
, buf
+ 4, reply
, reply_size
);
6448 } else if (os_strcmp(buf
, "STA-FIRST") == 0) {
6449 reply_len
= ap_ctrl_iface_sta_first(wpa_s
, reply
, reply_size
);
6450 } else if (os_strncmp(buf
, "STA ", 4) == 0) {
6451 reply_len
= ap_ctrl_iface_sta(wpa_s
, buf
+ 4, reply
,
6453 } else if (os_strncmp(buf
, "STA-NEXT ", 9) == 0) {
6454 reply_len
= ap_ctrl_iface_sta_next(wpa_s
, buf
+ 9, reply
,
6456 } else if (os_strncmp(buf
, "DEAUTHENTICATE ", 15) == 0) {
6457 if (ap_ctrl_iface_sta_deauthenticate(wpa_s
, buf
+ 15))
6459 } else if (os_strncmp(buf
, "DISASSOCIATE ", 13) == 0) {
6460 if (ap_ctrl_iface_sta_disassociate(wpa_s
, buf
+ 13))
6462 } else if (os_strncmp(buf
, "CHAN_SWITCH ", 12) == 0) {
6463 if (ap_ctrl_iface_chanswitch(wpa_s
, buf
+ 12))
6465 #endif /* CONFIG_AP */
6466 } else if (os_strcmp(buf
, "SUSPEND") == 0) {
6467 wpas_notify_suspend(wpa_s
->global
);
6468 } else if (os_strcmp(buf
, "RESUME") == 0) {
6469 wpas_notify_resume(wpa_s
->global
);
6470 } else if (os_strcmp(buf
, "DROP_SA") == 0) {
6471 wpa_supplicant_ctrl_iface_drop_sa(wpa_s
);
6472 } else if (os_strncmp(buf
, "ROAM ", 5) == 0) {
6473 if (wpa_supplicant_ctrl_iface_roam(wpa_s
, buf
+ 5))
6475 } else if (os_strncmp(buf
, "STA_AUTOCONNECT ", 16) == 0) {
6476 if (wpa_supplicant_ctrl_iface_sta_autoconnect(wpa_s
, buf
+ 16))
6478 } else if (os_strncmp(buf
, "BSS_EXPIRE_AGE ", 15) == 0) {
6479 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s
, buf
+ 15))
6481 } else if (os_strncmp(buf
, "BSS_EXPIRE_COUNT ", 17) == 0) {
6482 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s
,
6485 } else if (os_strncmp(buf
, "BSS_FLUSH ", 10) == 0) {
6486 if (wpa_supplicant_ctrl_iface_bss_flush(wpa_s
, buf
+ 10))
6489 } else if (os_strncmp(buf
, "TDLS_DISCOVER ", 14) == 0) {
6490 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s
, buf
+ 14))
6492 } else if (os_strncmp(buf
, "TDLS_SETUP ", 11) == 0) {
6493 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s
, buf
+ 11))
6495 } else if (os_strncmp(buf
, "TDLS_TEARDOWN ", 14) == 0) {
6496 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s
, buf
+ 14))
6498 #endif /* CONFIG_TDLS */
6499 } else if (os_strncmp(buf
, "SIGNAL_POLL", 11) == 0) {
6500 reply_len
= wpa_supplicant_signal_poll(wpa_s
, reply
,
6502 } else if (os_strncmp(buf
, "PKTCNT_POLL", 11) == 0) {
6503 reply_len
= wpa_supplicant_pktcnt_poll(wpa_s
, reply
,
6505 #ifdef CONFIG_AUTOSCAN
6506 } else if (os_strncmp(buf
, "AUTOSCAN ", 9) == 0) {
6507 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s
, buf
+ 9))
6509 #endif /* CONFIG_AUTOSCAN */
6511 } else if (os_strncmp(buf
, "DRIVER ", 7) == 0) {
6512 reply_len
= wpa_supplicant_driver_cmd(wpa_s
, buf
+ 7, reply
,
6514 #endif /* ANDROID */
6515 } else if (os_strncmp(buf
, "VENDOR ", 7) == 0) {
6516 reply_len
= wpa_supplicant_vendor_cmd(wpa_s
, buf
+ 7, reply
,
6518 } else if (os_strcmp(buf
, "REAUTHENTICATE") == 0) {
6519 pmksa_cache_clear_current(wpa_s
->wpa
);
6520 eapol_sm_request_reauth(wpa_s
->eapol
);
6522 } else if (os_strncmp(buf
, "WNM_SLEEP ", 10) == 0) {
6523 if (wpas_ctrl_iface_wnm_sleep(wpa_s
, buf
+ 10))
6525 } else if (os_strncmp(buf
, "WNM_BSS_QUERY ", 10) == 0) {
6526 if (wpas_ctrl_iface_wnm_bss_query(wpa_s
, buf
+ 10))
6528 #endif /* CONFIG_WNM */
6529 } else if (os_strcmp(buf
, "FLUSH") == 0) {
6530 wpa_supplicant_ctrl_iface_flush(wpa_s
);
6531 } else if (os_strncmp(buf
, "RADIO_WORK ", 11) == 0) {
6532 reply_len
= wpas_ctrl_radio_work(wpa_s
, buf
+ 11, reply
,
6534 #ifdef CONFIG_TESTING_OPTIONS
6535 } else if (os_strncmp(buf
, "MGMT_TX ", 8) == 0) {
6536 if (wpas_ctrl_iface_mgmt_tx(wpa_s
, buf
+ 8) < 0)
6538 } else if (os_strcmp(buf
, "MGMT_TX_DONE") == 0) {
6539 wpas_ctrl_iface_mgmt_tx_done(wpa_s
);
6540 #endif /* CONFIG_TESTING_OPTIONS */
6542 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
6546 if (reply_len
< 0) {
6547 os_memcpy(reply
, "FAIL\n", 5);
6551 *resp_len
= reply_len
;
6556 static int wpa_supplicant_global_iface_add(struct wpa_global
*global
,
6559 struct wpa_interface iface
;
6563 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
6564 * TAB<bridge_ifname>
6566 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd
);
6568 os_memset(&iface
, 0, sizeof(iface
));
6571 iface
.ifname
= pos
= cmd
;
6572 pos
= os_strchr(pos
, '\t');
6575 if (iface
.ifname
[0] == '\0')
6580 iface
.confname
= pos
;
6581 pos
= os_strchr(pos
, '\t');
6584 if (iface
.confname
[0] == '\0')
6585 iface
.confname
= NULL
;
6590 pos
= os_strchr(pos
, '\t');
6593 if (iface
.driver
[0] == '\0')
6594 iface
.driver
= NULL
;
6598 iface
.ctrl_interface
= pos
;
6599 pos
= os_strchr(pos
, '\t');
6602 if (iface
.ctrl_interface
[0] == '\0')
6603 iface
.ctrl_interface
= NULL
;
6607 iface
.driver_param
= pos
;
6608 pos
= os_strchr(pos
, '\t');
6611 if (iface
.driver_param
[0] == '\0')
6612 iface
.driver_param
= NULL
;
6616 iface
.bridge_ifname
= pos
;
6617 pos
= os_strchr(pos
, '\t');
6620 if (iface
.bridge_ifname
[0] == '\0')
6621 iface
.bridge_ifname
= NULL
;
6626 if (wpa_supplicant_get_iface(global
, iface
.ifname
))
6629 return wpa_supplicant_add_iface(global
, &iface
) ? 0 : -1;
6633 static int wpa_supplicant_global_iface_remove(struct wpa_global
*global
,
6636 struct wpa_supplicant
*wpa_s
;
6638 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd
);
6640 wpa_s
= wpa_supplicant_get_iface(global
, cmd
);
6643 return wpa_supplicant_remove_iface(global
, wpa_s
, 0);
6647 static void wpa_free_iface_info(struct wpa_interface_info
*iface
)
6649 struct wpa_interface_info
*prev
;
6653 iface
= iface
->next
;
6655 os_free(prev
->ifname
);
6656 os_free(prev
->desc
);
6662 static int wpa_supplicant_global_iface_list(struct wpa_global
*global
,
6666 struct wpa_interface_info
*iface
= NULL
, *last
= NULL
, *tmp
;
6669 for (i
= 0; wpa_drivers
[i
]; i
++) {
6670 struct wpa_driver_ops
*drv
= wpa_drivers
[i
];
6671 if (drv
->get_interfaces
== NULL
)
6673 tmp
= drv
->get_interfaces(global
->drv_priv
[i
]);
6687 for (tmp
= iface
; tmp
; tmp
= tmp
->next
) {
6688 res
= os_snprintf(pos
, end
- pos
, "%s\t%s\t%s\n",
6689 tmp
->drv_name
, tmp
->ifname
,
6690 tmp
->desc
? tmp
->desc
: "");
6691 if (res
< 0 || res
>= end
- pos
) {
6698 wpa_free_iface_info(iface
);
6704 static int wpa_supplicant_global_iface_interfaces(struct wpa_global
*global
,
6709 struct wpa_supplicant
*wpa_s
;
6711 wpa_s
= global
->ifaces
;
6716 res
= os_snprintf(pos
, end
- pos
, "%s\n", wpa_s
->ifname
);
6717 if (res
< 0 || res
>= end
- pos
) {
6722 wpa_s
= wpa_s
->next
;
6728 static char * wpas_global_ctrl_iface_ifname(struct wpa_global
*global
,
6730 char *cmd
, size_t *resp_len
)
6732 struct wpa_supplicant
*wpa_s
;
6734 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
6735 if (os_strcmp(ifname
, wpa_s
->ifname
) == 0)
6739 if (wpa_s
== NULL
) {
6740 char *resp
= os_strdup("FAIL-NO-IFNAME-MATCH\n");
6742 *resp_len
= os_strlen(resp
);
6748 return wpa_supplicant_ctrl_iface_process(wpa_s
, cmd
, resp_len
);
6752 static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global
*global
,
6753 char *buf
, size_t *resp_len
)
6756 static const char * cmd
[] = {
6763 "P2P_GET_PASSPHRASE",
6764 "P2P_SERVICE_UPDATE",
6765 "P2P_SERVICE_FLUSH",
6772 static const char * prefix
[] = {
6775 #endif /* ANDROID */
6782 "P2P_GROUP_REMOVE ",
6785 "P2P_SERV_DISC_REQ ",
6786 "P2P_SERV_DISC_CANCEL_REQ ",
6787 "P2P_SERV_DISC_RESP ",
6788 "P2P_SERV_DISC_EXTERNAL ",
6796 "P2P_PRESENCE_REQ ",
6798 "P2P_REMOVE_CLIENT ",
6804 if (global
->p2p_init_wpa_s
== NULL
)
6807 for (i
= 0; !found
&& cmd
[i
]; i
++) {
6808 if (os_strcmp(buf
, cmd
[i
]) == 0)
6812 for (i
= 0; !found
&& prefix
[i
]; i
++) {
6813 if (os_strncmp(buf
, prefix
[i
], os_strlen(prefix
[i
])) == 0)
6818 return wpa_supplicant_ctrl_iface_process(global
->p2p_init_wpa_s
,
6820 #endif /* CONFIG_P2P */
6825 static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global
*global
,
6826 char *buf
, size_t *resp_len
)
6828 #ifdef CONFIG_WIFI_DISPLAY
6829 if (global
->p2p_init_wpa_s
== NULL
)
6831 if (os_strncmp(buf
, "WFD_SUBELEM_SET ", 16) == 0 ||
6832 os_strncmp(buf
, "WFD_SUBELEM_GET ", 16) == 0)
6833 return wpa_supplicant_ctrl_iface_process(global
->p2p_init_wpa_s
,
6835 #endif /* CONFIG_WIFI_DISPLAY */
6840 static char * wpas_global_ctrl_iface_redir(struct wpa_global
*global
,
6841 char *buf
, size_t *resp_len
)
6845 ret
= wpas_global_ctrl_iface_redir_p2p(global
, buf
, resp_len
);
6849 ret
= wpas_global_ctrl_iface_redir_wfd(global
, buf
, resp_len
);
6857 static int wpas_global_ctrl_iface_set(struct wpa_global
*global
, char *cmd
)
6861 value
= os_strchr(cmd
, ' ');
6866 wpa_printf(MSG_DEBUG
, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd
, value
);
6868 #ifdef CONFIG_WIFI_DISPLAY
6869 if (os_strcasecmp(cmd
, "wifi_display") == 0) {
6870 wifi_display_enable(global
, !!atoi(value
));
6873 #endif /* CONFIG_WIFI_DISPLAY */
6879 #ifndef CONFIG_NO_CONFIG_WRITE
6880 static int wpas_global_ctrl_iface_save_config(struct wpa_global
*global
)
6883 struct wpa_supplicant
*wpa_s
;
6885 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
6886 if (!wpa_s
->conf
->update_config
) {
6887 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
6891 if (wpa_config_write(wpa_s
->confname
, wpa_s
->conf
)) {
6892 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
6895 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
6901 #endif /* CONFIG_NO_CONFIG_WRITE */
6904 static int wpas_global_ctrl_iface_status(struct wpa_global
*global
,
6905 char *buf
, size_t buflen
)
6909 struct wpa_supplicant
*wpa_s
;
6915 if (global
->p2p
&& !global
->p2p_disabled
) {
6916 ret
= os_snprintf(pos
, end
- pos
, "p2p_device_address=" MACSTR
6919 MAC2STR(global
->p2p_dev_addr
),
6920 p2p_get_state_txt(global
->p2p
));
6921 if (ret
< 0 || ret
>= end
- pos
)
6924 } else if (global
->p2p
) {
6925 ret
= os_snprintf(pos
, end
- pos
, "p2p_state=DISABLED\n");
6926 if (ret
< 0 || ret
>= end
- pos
)
6930 #endif /* CONFIG_P2P */
6932 #ifdef CONFIG_WIFI_DISPLAY
6933 ret
= os_snprintf(pos
, end
- pos
, "wifi_display=%d\n",
6934 !!global
->wifi_display
);
6935 if (ret
< 0 || ret
>= end
- pos
)
6938 #endif /* CONFIG_WIFI_DISPLAY */
6940 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
6941 ret
= os_snprintf(pos
, end
- pos
, "ifname=%s\n"
6942 "address=" MACSTR
"\n",
6943 wpa_s
->ifname
, MAC2STR(wpa_s
->own_addr
));
6944 if (ret
< 0 || ret
>= end
- pos
)
6953 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global
*global
,
6954 char *buf
, size_t *resp_len
)
6957 const int reply_size
= 2048;
6959 int level
= MSG_DEBUG
;
6961 if (os_strncmp(buf
, "IFNAME=", 7) == 0) {
6962 char *pos
= os_strchr(buf
+ 7, ' ');
6965 return wpas_global_ctrl_iface_ifname(global
,
6971 reply
= wpas_global_ctrl_iface_redir(global
, buf
, resp_len
);
6975 if (os_strcmp(buf
, "PING") == 0)
6976 level
= MSG_EXCESSIVE
;
6977 wpa_hexdump_ascii(level
, "RX global ctrl_iface",
6978 (const u8
*) buf
, os_strlen(buf
));
6980 reply
= os_malloc(reply_size
);
6981 if (reply
== NULL
) {
6986 os_memcpy(reply
, "OK\n", 3);
6989 if (os_strcmp(buf
, "PING") == 0) {
6990 os_memcpy(reply
, "PONG\n", 5);
6992 } else if (os_strncmp(buf
, "INTERFACE_ADD ", 14) == 0) {
6993 if (wpa_supplicant_global_iface_add(global
, buf
+ 14))
6995 } else if (os_strncmp(buf
, "INTERFACE_REMOVE ", 17) == 0) {
6996 if (wpa_supplicant_global_iface_remove(global
, buf
+ 17))
6998 } else if (os_strcmp(buf
, "INTERFACE_LIST") == 0) {
6999 reply_len
= wpa_supplicant_global_iface_list(
7000 global
, reply
, reply_size
);
7001 } else if (os_strcmp(buf
, "INTERFACES") == 0) {
7002 reply_len
= wpa_supplicant_global_iface_interfaces(
7003 global
, reply
, reply_size
);
7004 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
7005 wpa_supplicant_terminate_proc(global
);
7006 } else if (os_strcmp(buf
, "SUSPEND") == 0) {
7007 wpas_notify_suspend(global
);
7008 } else if (os_strcmp(buf
, "RESUME") == 0) {
7009 wpas_notify_resume(global
);
7010 } else if (os_strncmp(buf
, "SET ", 4) == 0) {
7011 if (wpas_global_ctrl_iface_set(global
, buf
+ 4))
7013 #ifndef CONFIG_NO_CONFIG_WRITE
7014 } else if (os_strcmp(buf
, "SAVE_CONFIG") == 0) {
7015 if (wpas_global_ctrl_iface_save_config(global
))
7017 #endif /* CONFIG_NO_CONFIG_WRITE */
7018 } else if (os_strcmp(buf
, "STATUS") == 0) {
7019 reply_len
= wpas_global_ctrl_iface_status(global
, reply
,
7021 #ifdef CONFIG_MODULE_TESTS
7022 } else if (os_strcmp(buf
, "MODULE_TESTS") == 0) {
7023 int wpas_module_tests(void);
7024 if (wpas_module_tests() < 0)
7026 #endif /* CONFIG_MODULE_TESTS */
7028 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
7032 if (reply_len
< 0) {
7033 os_memcpy(reply
, "FAIL\n", 5);
7037 *resp_len
= reply_len
;