2 * WPA Supplicant / Control interface (shared code for all backends)
3 * Copyright (c) 2004-2015, 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"
10 #ifdef CONFIG_TESTING_OPTIONS
11 #include <net/ethernet.h>
12 #include <netinet/ip.h>
13 #endif /* CONFIG_TESTING_OPTIONS */
15 #include "utils/common.h"
16 #include "utils/eloop.h"
17 #include "utils/uuid.h"
18 #include "utils/module_tests.h"
19 #include "common/version.h"
20 #include "common/ieee802_11_defs.h"
21 #include "common/ieee802_11_common.h"
22 #include "common/wpa_ctrl.h"
23 #include "crypto/tls.h"
24 #include "ap/hostapd.h"
25 #include "eap_peer/eap.h"
26 #include "eapol_supp/eapol_supp_sm.h"
27 #include "rsn_supp/wpa.h"
28 #include "rsn_supp/preauth.h"
29 #include "rsn_supp/pmksa_cache.h"
30 #include "l2_packet/l2_packet.h"
33 #include "fst/fst_ctrl_iface.h"
35 #include "wpa_supplicant_i.h"
37 #include "wps_supplicant.h"
40 #include "p2p_supplicant.h"
42 #include "hs20_supplicant.h"
43 #include "wifi_display.h"
47 #include "ctrl_iface.h"
48 #include "interworking.h"
49 #include "blacklist.h"
52 #include "offchannel.h"
53 #include "drivers/driver.h"
56 static int wpa_supplicant_global_iface_list(struct wpa_global
*global
,
58 static int wpa_supplicant_global_iface_interfaces(struct wpa_global
*global
,
61 static int * freq_range_to_channel_list(struct wpa_supplicant
*wpa_s
,
64 static int set_bssid_filter(struct wpa_supplicant
*wpa_s
, char *val
)
67 u8 addr
[ETH_ALEN
], *filter
= NULL
, *n
;
74 if (hwaddr_aton(pos
, addr
)) {
78 n
= os_realloc_array(filter
, count
+ 1, ETH_ALEN
);
84 os_memcpy(filter
+ count
* ETH_ALEN
, addr
, ETH_ALEN
);
87 pos
= os_strchr(pos
, ' ');
92 wpa_hexdump(MSG_DEBUG
, "bssid_filter", filter
, count
* ETH_ALEN
);
93 os_free(wpa_s
->bssid_filter
);
94 wpa_s
->bssid_filter
= filter
;
95 wpa_s
->bssid_filter_count
= count
;
101 static int set_disallow_aps(struct wpa_supplicant
*wpa_s
, char *val
)
104 u8 addr
[ETH_ALEN
], *bssid
= NULL
, *n
;
105 struct wpa_ssid_value
*ssid
= NULL
, *ns
;
106 size_t count
= 0, ssid_count
= 0;
110 * disallow_list ::= <ssid_spec> | <bssid_spec> | <disallow_list> | ""
111 * SSID_SPEC ::= ssid <SSID_HEX>
112 * BSSID_SPEC ::= bssid <BSSID_HEX>
119 if (os_strncmp(pos
, "bssid ", 6) == 0) {
122 res
= hwaddr_aton2(pos
, addr
);
126 wpa_printf(MSG_DEBUG
, "Invalid disallow_aps "
127 "BSSID value '%s'", pos
);
131 n
= os_realloc_array(bssid
, count
+ 1, ETH_ALEN
);
138 os_memcpy(bssid
+ count
* ETH_ALEN
, addr
, ETH_ALEN
);
140 } else if (os_strncmp(pos
, "ssid ", 5) == 0) {
146 if (*end
== '\0' || *end
== ' ')
151 ns
= os_realloc_array(ssid
, ssid_count
+ 1,
152 sizeof(struct wpa_ssid_value
));
160 if ((end
- pos
) & 0x01 ||
161 end
- pos
> 2 * SSID_MAX_LEN
||
162 hexstr2bin(pos
, ssid
[ssid_count
].ssid
,
163 (end
- pos
) / 2) < 0) {
166 wpa_printf(MSG_DEBUG
, "Invalid disallow_aps "
167 "SSID value '%s'", pos
);
170 ssid
[ssid_count
].ssid_len
= (end
- pos
) / 2;
171 wpa_hexdump_ascii(MSG_DEBUG
, "disallow_aps SSID",
172 ssid
[ssid_count
].ssid
,
173 ssid
[ssid_count
].ssid_len
);
177 wpa_printf(MSG_DEBUG
, "Unexpected disallow_aps value "
184 pos
= os_strchr(pos
, ' ');
189 wpa_hexdump(MSG_DEBUG
, "disallow_aps_bssid", bssid
, count
* ETH_ALEN
);
190 os_free(wpa_s
->disallow_aps_bssid
);
191 wpa_s
->disallow_aps_bssid
= bssid
;
192 wpa_s
->disallow_aps_bssid_count
= count
;
194 wpa_printf(MSG_DEBUG
, "disallow_aps_ssid_count %d", (int) ssid_count
);
195 os_free(wpa_s
->disallow_aps_ssid
);
196 wpa_s
->disallow_aps_ssid
= ssid
;
197 wpa_s
->disallow_aps_ssid_count
= ssid_count
;
199 if (!wpa_s
->current_ssid
|| wpa_s
->wpa_state
< WPA_AUTHENTICATING
)
202 c
= wpa_s
->current_ssid
;
203 if (c
->mode
!= WPAS_MODE_INFRA
&& c
->mode
!= WPAS_MODE_IBSS
)
206 if (!disallowed_bssid(wpa_s
, wpa_s
->bssid
) &&
207 !disallowed_ssid(wpa_s
, c
->ssid
, c
->ssid_len
))
210 wpa_printf(MSG_DEBUG
, "Disconnect and try to find another network "
211 "because current AP was marked disallowed");
214 wpa_s
->sme
.prev_bssid_set
= 0;
215 #endif /* CONFIG_SME */
216 wpa_s
->reassociate
= 1;
217 wpa_s
->own_disconnect_req
= 1;
218 wpa_supplicant_deauthenticate(wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
219 wpa_supplicant_req_scan(wpa_s
, 0, 0);
225 #ifndef CONFIG_NO_CONFIG_BLOBS
226 static int wpas_ctrl_set_blob(struct wpa_supplicant
*wpa_s
, char *pos
)
229 struct wpa_config_blob
*blob
;
232 pos
= os_strchr(pos
, ' ');
236 len
= os_strlen(pos
);
240 wpa_printf(MSG_DEBUG
, "CTRL: Set blob '%s'", name
);
241 blob
= os_zalloc(sizeof(*blob
));
244 blob
->name
= os_strdup(name
);
245 blob
->data
= os_malloc(len
/ 2);
246 if (blob
->name
== NULL
|| blob
->data
== NULL
) {
247 wpa_config_free_blob(blob
);
251 if (hexstr2bin(pos
, blob
->data
, len
/ 2) < 0) {
252 wpa_printf(MSG_DEBUG
, "CTRL: Invalid blob hex data");
253 wpa_config_free_blob(blob
);
258 wpa_config_set_blob(wpa_s
->conf
, blob
);
262 #endif /* CONFIG_NO_CONFIG_BLOBS */
265 static int wpas_ctrl_pno(struct wpa_supplicant
*wpa_s
, char *cmd
)
273 params
= os_strchr(cmd
, ' ');
274 os_free(wpa_s
->manual_sched_scan_freqs
);
277 pos
= os_strstr(params
, "freq=");
279 freqs
= freq_range_to_channel_list(wpa_s
,
282 wpa_s
->manual_sched_scan_freqs
= freqs
;
283 ret
= wpas_start_pno(wpa_s
);
285 ret
= wpas_stop_pno(wpa_s
);
291 static int wpas_ctrl_set_band(struct wpa_supplicant
*wpa_s
, char *band
)
293 union wpa_event_data event
;
295 if (os_strcmp(band
, "AUTO") == 0)
296 wpa_s
->setband
= WPA_SETBAND_AUTO
;
297 else if (os_strcmp(band
, "5G") == 0)
298 wpa_s
->setband
= WPA_SETBAND_5G
;
299 else if (os_strcmp(band
, "2G") == 0)
300 wpa_s
->setband
= WPA_SETBAND_2G
;
304 if (wpa_drv_setband(wpa_s
, wpa_s
->setband
) == 0) {
305 os_memset(&event
, 0, sizeof(event
));
306 event
.channel_list_changed
.initiator
= REGDOM_SET_BY_USER
;
307 event
.channel_list_changed
.type
= REGDOM_TYPE_UNKNOWN
;
308 wpa_supplicant_event(wpa_s
, EVENT_CHANNEL_LIST_CHANGED
, &event
);
315 static int wpas_ctrl_iface_set_lci(struct wpa_supplicant
*wpa_s
,
320 if (*cmd
== '\0' || os_strcmp(cmd
, "\"\"") == 0) {
321 wpabuf_free(wpa_s
->lci
);
326 lci
= wpabuf_parse_bin(cmd
);
330 if (os_get_reltime(&wpa_s
->lci_time
)) {
335 wpabuf_free(wpa_s
->lci
);
342 static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant
*wpa_s
,
348 value
= os_strchr(cmd
, ' ');
353 wpa_printf(MSG_DEBUG
, "CTRL_IFACE SET '%s'='%s'", cmd
, value
);
354 if (os_strcasecmp(cmd
, "EAPOL::heldPeriod") == 0) {
355 eapol_sm_configure(wpa_s
->eapol
,
356 atoi(value
), -1, -1, -1);
357 } else if (os_strcasecmp(cmd
, "EAPOL::authPeriod") == 0) {
358 eapol_sm_configure(wpa_s
->eapol
,
359 -1, atoi(value
), -1, -1);
360 } else if (os_strcasecmp(cmd
, "EAPOL::startPeriod") == 0) {
361 eapol_sm_configure(wpa_s
->eapol
,
362 -1, -1, atoi(value
), -1);
363 } else if (os_strcasecmp(cmd
, "EAPOL::maxStart") == 0) {
364 eapol_sm_configure(wpa_s
->eapol
,
365 -1, -1, -1, atoi(value
));
366 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigPMKLifetime") == 0) {
367 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_LIFETIME
,
372 wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
374 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigPMKReauthThreshold") ==
376 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_REAUTH_THRESHOLD
,
381 wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
383 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigSATimeout") == 0) {
384 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_SA_TIMEOUT
,
389 wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
391 } else if (os_strcasecmp(cmd
, "wps_fragment_size") == 0) {
392 wpa_s
->wps_fragment_size
= atoi(value
);
393 #ifdef CONFIG_WPS_TESTING
394 } else if (os_strcasecmp(cmd
, "wps_version_number") == 0) {
396 val
= strtol(value
, NULL
, 0);
397 if (val
< 0 || val
> 0xff) {
399 wpa_printf(MSG_DEBUG
, "WPS: Invalid "
400 "wps_version_number %ld", val
);
402 wps_version_number
= val
;
403 wpa_printf(MSG_DEBUG
, "WPS: Testing - force WPS "
405 (wps_version_number
& 0xf0) >> 4,
406 wps_version_number
& 0x0f);
408 } else if (os_strcasecmp(cmd
, "wps_testing_dummy_cred") == 0) {
409 wps_testing_dummy_cred
= atoi(value
);
410 wpa_printf(MSG_DEBUG
, "WPS: Testing - dummy_cred=%d",
411 wps_testing_dummy_cred
);
412 } else if (os_strcasecmp(cmd
, "wps_corrupt_pkhash") == 0) {
413 wps_corrupt_pkhash
= atoi(value
);
414 wpa_printf(MSG_DEBUG
, "WPS: Testing - wps_corrupt_pkhash=%d",
416 } else if (os_strcasecmp(cmd
, "wps_force_auth_types") == 0) {
417 if (value
[0] == '\0') {
418 wps_force_auth_types_in_use
= 0;
420 wps_force_auth_types
= strtol(value
, NULL
, 0);
421 wps_force_auth_types_in_use
= 1;
423 } else if (os_strcasecmp(cmd
, "wps_force_encr_types") == 0) {
424 if (value
[0] == '\0') {
425 wps_force_encr_types_in_use
= 0;
427 wps_force_encr_types
= strtol(value
, NULL
, 0);
428 wps_force_encr_types_in_use
= 1;
430 #endif /* CONFIG_WPS_TESTING */
431 } else if (os_strcasecmp(cmd
, "ampdu") == 0) {
432 if (wpa_drv_ampdu(wpa_s
, atoi(value
)) < 0)
435 #ifdef CONFIG_TDLS_TESTING
436 } else if (os_strcasecmp(cmd
, "tdls_testing") == 0) {
437 tdls_testing
= strtol(value
, NULL
, 0);
438 wpa_printf(MSG_DEBUG
, "TDLS: tdls_testing=0x%x", tdls_testing
);
439 #endif /* CONFIG_TDLS_TESTING */
440 } else if (os_strcasecmp(cmd
, "tdls_disabled") == 0) {
441 int disabled
= atoi(value
);
442 wpa_printf(MSG_DEBUG
, "TDLS: tdls_disabled=%d", disabled
);
444 if (wpa_drv_tdls_oper(wpa_s
, TDLS_DISABLE
, NULL
) < 0)
446 } else if (wpa_drv_tdls_oper(wpa_s
, TDLS_ENABLE
, NULL
) < 0)
448 wpa_tdls_enable(wpa_s
->wpa
, !disabled
);
449 #endif /* CONFIG_TDLS */
450 } else if (os_strcasecmp(cmd
, "pno") == 0) {
451 ret
= wpas_ctrl_pno(wpa_s
, value
);
452 } else if (os_strcasecmp(cmd
, "radio_disabled") == 0) {
453 int disabled
= atoi(value
);
454 if (wpa_drv_radio_disable(wpa_s
, disabled
) < 0)
457 wpa_supplicant_set_state(wpa_s
, WPA_INACTIVE
);
458 } else if (os_strcasecmp(cmd
, "uapsd") == 0) {
459 if (os_strcmp(value
, "disable") == 0)
460 wpa_s
->set_sta_uapsd
= 0;
464 /* format: BE,BK,VI,VO;max SP Length */
466 pos
= os_strchr(value
, ',');
471 pos
= os_strchr(pos
, ',');
476 pos
= os_strchr(pos
, ',');
481 /* ignore max SP Length for now */
483 wpa_s
->set_sta_uapsd
= 1;
484 wpa_s
->sta_uapsd
= 0;
486 wpa_s
->sta_uapsd
|= BIT(0);
488 wpa_s
->sta_uapsd
|= BIT(1);
490 wpa_s
->sta_uapsd
|= BIT(2);
492 wpa_s
->sta_uapsd
|= BIT(3);
494 } else if (os_strcasecmp(cmd
, "ps") == 0) {
495 ret
= wpa_drv_set_p2p_powersave(wpa_s
, atoi(value
), -1, -1);
496 #ifdef CONFIG_WIFI_DISPLAY
497 } else if (os_strcasecmp(cmd
, "wifi_display") == 0) {
498 int enabled
= !!atoi(value
);
499 if (enabled
&& !wpa_s
->global
->p2p
)
502 wifi_display_enable(wpa_s
->global
, enabled
);
503 #endif /* CONFIG_WIFI_DISPLAY */
504 } else if (os_strcasecmp(cmd
, "bssid_filter") == 0) {
505 ret
= set_bssid_filter(wpa_s
, value
);
506 } else if (os_strcasecmp(cmd
, "disallow_aps") == 0) {
507 ret
= set_disallow_aps(wpa_s
, value
);
508 } else if (os_strcasecmp(cmd
, "no_keep_alive") == 0) {
509 wpa_s
->no_keep_alive
= !!atoi(value
);
510 #ifdef CONFIG_TESTING_OPTIONS
511 } else if (os_strcasecmp(cmd
, "ext_mgmt_frame_handling") == 0) {
512 wpa_s
->ext_mgmt_frame_handling
= !!atoi(value
);
513 } else if (os_strcasecmp(cmd
, "ext_eapol_frame_io") == 0) {
514 wpa_s
->ext_eapol_frame_io
= !!atoi(value
);
516 if (wpa_s
->ap_iface
) {
517 wpa_s
->ap_iface
->bss
[0]->ext_eapol_frame_io
=
518 wpa_s
->ext_eapol_frame_io
;
520 #endif /* CONFIG_AP */
521 } else if (os_strcasecmp(cmd
, "extra_roc_dur") == 0) {
522 wpa_s
->extra_roc_dur
= atoi(value
);
523 } else if (os_strcasecmp(cmd
, "test_failure") == 0) {
524 wpa_s
->test_failure
= atoi(value
);
525 } else if (os_strcasecmp(cmd
, "p2p_go_csa_on_inv") == 0) {
526 wpa_s
->p2p_go_csa_on_inv
= !!atoi(value
);
527 } else if (os_strcasecmp(cmd
, "ignore_auth_resp") == 0) {
528 wpa_s
->ignore_auth_resp
= !!atoi(value
);
529 } else if (os_strcasecmp(cmd
, "ignore_assoc_disallow") == 0) {
530 wpa_s
->ignore_assoc_disallow
= !!atoi(value
);
531 } else if (os_strcasecmp(cmd
, "reject_btm_req_reason") == 0) {
532 wpa_s
->reject_btm_req_reason
= atoi(value
);
533 #endif /* CONFIG_TESTING_OPTIONS */
534 #ifndef CONFIG_NO_CONFIG_BLOBS
535 } else if (os_strcmp(cmd
, "blob") == 0) {
536 ret
= wpas_ctrl_set_blob(wpa_s
, value
);
537 #endif /* CONFIG_NO_CONFIG_BLOBS */
538 } else if (os_strcasecmp(cmd
, "setband") == 0) {
539 ret
= wpas_ctrl_set_band(wpa_s
, value
);
541 } else if (os_strcasecmp(cmd
, "non_pref_chan") == 0) {
542 ret
= wpas_mbo_update_non_pref_chan(wpa_s
, value
);
545 wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
547 } else if (os_strcasecmp(cmd
, "mbo_cell_capa") == 0) {
548 wpas_mbo_update_cell_capa(wpa_s
, atoi(value
));
549 #endif /* CONFIG_MBO */
550 } else if (os_strcasecmp(cmd
, "lci") == 0) {
551 ret
= wpas_ctrl_iface_set_lci(wpa_s
, value
);
552 } else if (os_strcasecmp(cmd
, "tdls_trigger_control") == 0) {
553 ret
= wpa_drv_set_tdls_mode(wpa_s
, atoi(value
));
556 ret
= wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
558 wpa_supplicant_update_config(wpa_s
);
565 static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant
*wpa_s
,
566 char *cmd
, char *buf
, size_t buflen
)
570 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GET '%s'", cmd
);
572 if (os_strcmp(cmd
, "version") == 0) {
573 res
= os_snprintf(buf
, buflen
, "%s", VERSION_STR
);
574 } else if (os_strcasecmp(cmd
, "country") == 0) {
575 if (wpa_s
->conf
->country
[0] && wpa_s
->conf
->country
[1])
576 res
= os_snprintf(buf
, buflen
, "%c%c",
577 wpa_s
->conf
->country
[0],
578 wpa_s
->conf
->country
[1]);
579 #ifdef CONFIG_WIFI_DISPLAY
580 } else if (os_strcasecmp(cmd
, "wifi_display") == 0) {
582 if (wpa_s
->global
->p2p
== NULL
||
583 wpa_s
->global
->p2p_disabled
)
586 enabled
= wpa_s
->global
->wifi_display
;
587 res
= os_snprintf(buf
, buflen
, "%d", enabled
);
588 #endif /* CONFIG_WIFI_DISPLAY */
589 #ifdef CONFIG_TESTING_GET_GTK
590 } else if (os_strcmp(cmd
, "gtk") == 0) {
591 if (wpa_s
->last_gtk_len
== 0)
593 res
= wpa_snprintf_hex(buf
, buflen
, wpa_s
->last_gtk
,
594 wpa_s
->last_gtk_len
);
596 #endif /* CONFIG_TESTING_GET_GTK */
597 } else if (os_strcmp(cmd
, "tls_library") == 0) {
598 res
= tls_get_library_version(buf
, buflen
);
600 res
= wpa_config_get_value(cmd
, wpa_s
->conf
, buf
, buflen
);
603 if (os_snprintf_error(buflen
, res
))
609 #ifdef IEEE8021X_EAPOL
610 static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant
*wpa_s
,
614 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
616 if (hwaddr_aton(addr
, bssid
)) {
617 wpa_printf(MSG_DEBUG
, "CTRL_IFACE PREAUTH: invalid address "
622 wpa_printf(MSG_DEBUG
, "CTRL_IFACE PREAUTH " MACSTR
, MAC2STR(bssid
));
623 rsn_preauth_deinit(wpa_s
->wpa
);
624 if (rsn_preauth_init(wpa_s
->wpa
, bssid
, ssid
? &ssid
->eap
: NULL
))
629 #endif /* IEEE8021X_EAPOL */
632 #ifdef CONFIG_PEERKEY
633 /* MLME-STKSTART.request(peer) */
634 static int wpa_supplicant_ctrl_iface_stkstart(
635 struct wpa_supplicant
*wpa_s
, char *addr
)
639 if (hwaddr_aton(addr
, peer
)) {
640 wpa_printf(MSG_DEBUG
, "CTRL_IFACE STKSTART: invalid "
641 "address '%s'", addr
);
645 wpa_printf(MSG_DEBUG
, "CTRL_IFACE STKSTART " MACSTR
,
648 return wpa_sm_stkstart(wpa_s
->wpa
, peer
);
650 #endif /* CONFIG_PEERKEY */
655 static int wpa_supplicant_ctrl_iface_tdls_discover(
656 struct wpa_supplicant
*wpa_s
, char *addr
)
661 if (hwaddr_aton(addr
, peer
)) {
662 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_DISCOVER: invalid "
663 "address '%s'", addr
);
667 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_DISCOVER " MACSTR
,
670 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
671 ret
= wpa_tdls_send_discovery_request(wpa_s
->wpa
, peer
);
673 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_DISCOVERY_REQ
, peer
);
679 static int wpa_supplicant_ctrl_iface_tdls_setup(
680 struct wpa_supplicant
*wpa_s
, char *addr
)
685 if (hwaddr_aton(addr
, peer
)) {
686 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_SETUP: invalid "
687 "address '%s'", addr
);
691 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_SETUP " MACSTR
,
694 if ((wpa_s
->conf
->tdls_external_control
) &&
695 wpa_tdls_is_external_setup(wpa_s
->wpa
))
696 return wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, peer
);
698 wpa_tdls_remove(wpa_s
->wpa
, peer
);
700 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
701 ret
= wpa_tdls_start(wpa_s
->wpa
, peer
);
703 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, peer
);
709 static int wpa_supplicant_ctrl_iface_tdls_teardown(
710 struct wpa_supplicant
*wpa_s
, char *addr
)
715 if (os_strcmp(addr
, "*") == 0) {
716 /* remove everyone */
717 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN *");
718 wpa_tdls_teardown_peers(wpa_s
->wpa
);
722 if (hwaddr_aton(addr
, peer
)) {
723 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN: invalid "
724 "address '%s'", addr
);
728 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN " MACSTR
,
731 if ((wpa_s
->conf
->tdls_external_control
) &&
732 wpa_tdls_is_external_setup(wpa_s
->wpa
))
733 return wpa_drv_tdls_oper(wpa_s
, TDLS_TEARDOWN
, peer
);
735 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
736 ret
= wpa_tdls_teardown_link(
738 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED
);
740 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_TEARDOWN
, peer
);
746 static int ctrl_iface_get_capability_tdls(
747 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
751 ret
= os_snprintf(buf
, buflen
, "%s\n",
752 wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
?
754 WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP
?
755 "EXTERNAL" : "INTERNAL") : "UNSUPPORTED");
756 if (os_snprintf_error(buflen
, ret
))
762 static int wpa_supplicant_ctrl_iface_tdls_chan_switch(
763 struct wpa_supplicant
*wpa_s
, char *cmd
)
766 struct hostapd_freq_params freq_params
;
770 if (!wpa_tdls_is_external_setup(wpa_s
->wpa
)) {
772 "tdls_chanswitch: Only supported with external setup");
776 os_memset(&freq_params
, 0, sizeof(freq_params
));
778 pos
= os_strchr(cmd
, ' ');
783 oper_class
= strtol(pos
, &end
, 10);
786 "tdls_chanswitch: Invalid op class provided");
791 freq_params
.freq
= atoi(pos
);
792 if (freq_params
.freq
== 0) {
793 wpa_printf(MSG_INFO
, "tdls_chanswitch: Invalid freq provided");
797 #define SET_FREQ_SETTING(str) \
799 const char *pos2 = os_strstr(pos, " " #str "="); \
801 pos2 += sizeof(" " #str "=") - 1; \
802 freq_params.str = atoi(pos2); \
806 SET_FREQ_SETTING(center_freq1
);
807 SET_FREQ_SETTING(center_freq2
);
808 SET_FREQ_SETTING(bandwidth
);
809 SET_FREQ_SETTING(sec_channel_offset
);
810 #undef SET_FREQ_SETTING
812 freq_params
.ht_enabled
= !!os_strstr(pos
, " ht");
813 freq_params
.vht_enabled
= !!os_strstr(pos
, " vht");
815 if (hwaddr_aton(cmd
, peer
)) {
816 wpa_printf(MSG_DEBUG
,
817 "CTRL_IFACE TDLS_CHAN_SWITCH: Invalid address '%s'",
822 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_CHAN_SWITCH " MACSTR
823 " OP CLASS %d FREQ %d CENTER1 %d CENTER2 %d BW %d SEC_OFFSET %d%s%s",
824 MAC2STR(peer
), oper_class
, freq_params
.freq
,
825 freq_params
.center_freq1
, freq_params
.center_freq2
,
826 freq_params
.bandwidth
, freq_params
.sec_channel_offset
,
827 freq_params
.ht_enabled
? " HT" : "",
828 freq_params
.vht_enabled
? " VHT" : "");
830 return wpa_tdls_enable_chan_switch(wpa_s
->wpa
, peer
, oper_class
,
835 static int wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(
836 struct wpa_supplicant
*wpa_s
, char *cmd
)
840 if (!wpa_tdls_is_external_setup(wpa_s
->wpa
)) {
842 "tdls_chanswitch: Only supported with external setup");
846 if (hwaddr_aton(cmd
, peer
)) {
847 wpa_printf(MSG_DEBUG
,
848 "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH: Invalid address '%s'",
853 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH " MACSTR
,
856 return wpa_tdls_disable_chan_switch(wpa_s
->wpa
, peer
);
860 static int wpa_supplicant_ctrl_iface_tdls_link_status(
861 struct wpa_supplicant
*wpa_s
, const char *addr
,
862 char *buf
, size_t buflen
)
865 const char *tdls_status
;
868 if (hwaddr_aton(addr
, peer
)) {
869 wpa_printf(MSG_DEBUG
,
870 "CTRL_IFACE TDLS_LINK_STATUS: Invalid address '%s'",
874 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_LINK_STATUS " MACSTR
,
877 tdls_status
= wpa_tdls_get_link_status(wpa_s
->wpa
, peer
);
878 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_LINK_STATUS: %s", tdls_status
);
879 ret
= os_snprintf(buf
, buflen
, "TDLS link status: %s\n", tdls_status
);
880 if (os_snprintf_error(buflen
, ret
))
886 #endif /* CONFIG_TDLS */
889 static int wmm_ac_ctrl_addts(struct wpa_supplicant
*wpa_s
, char *cmd
)
891 char *token
, *context
= NULL
;
892 struct wmm_ac_ts_setup_params params
= {
897 while ((token
= str_token(cmd
, " ", &context
))) {
898 if (sscanf(token
, "tsid=%i", ¶ms
.tsid
) == 1 ||
899 sscanf(token
, "up=%i", ¶ms
.user_priority
) == 1 ||
900 sscanf(token
, "nominal_msdu_size=%i",
901 ¶ms
.nominal_msdu_size
) == 1 ||
902 sscanf(token
, "mean_data_rate=%i",
903 ¶ms
.mean_data_rate
) == 1 ||
904 sscanf(token
, "min_phy_rate=%i",
905 ¶ms
.minimum_phy_rate
) == 1 ||
906 sscanf(token
, "sba=%i",
907 ¶ms
.surplus_bandwidth_allowance
) == 1)
910 if (os_strcasecmp(token
, "downlink") == 0) {
911 params
.direction
= WMM_TSPEC_DIRECTION_DOWNLINK
;
912 } else if (os_strcasecmp(token
, "uplink") == 0) {
913 params
.direction
= WMM_TSPEC_DIRECTION_UPLINK
;
914 } else if (os_strcasecmp(token
, "bidi") == 0) {
915 params
.direction
= WMM_TSPEC_DIRECTION_BI_DIRECTIONAL
;
916 } else if (os_strcasecmp(token
, "fixed_nominal_msdu") == 0) {
917 params
.fixed_nominal_msdu
= 1;
919 wpa_printf(MSG_DEBUG
,
920 "CTRL: Invalid WMM_AC_ADDTS parameter: '%s'",
927 return wpas_wmm_ac_addts(wpa_s
, ¶ms
);
931 static int wmm_ac_ctrl_delts(struct wpa_supplicant
*wpa_s
, char *cmd
)
935 return wpas_wmm_ac_delts(wpa_s
, tsid
);
939 #ifdef CONFIG_IEEE80211R
940 static int wpa_supplicant_ctrl_iface_ft_ds(
941 struct wpa_supplicant
*wpa_s
, char *addr
)
943 u8 target_ap
[ETH_ALEN
];
947 if (hwaddr_aton(addr
, target_ap
)) {
948 wpa_printf(MSG_DEBUG
, "CTRL_IFACE FT_DS: invalid "
949 "address '%s'", addr
);
953 wpa_printf(MSG_DEBUG
, "CTRL_IFACE FT_DS " MACSTR
, MAC2STR(target_ap
));
955 bss
= wpa_bss_get_bssid(wpa_s
, target_ap
);
957 mdie
= wpa_bss_get_ie(bss
, WLAN_EID_MOBILITY_DOMAIN
);
961 return wpa_ft_start_over_ds(wpa_s
->wpa
, target_ap
, mdie
);
963 #endif /* CONFIG_IEEE80211R */
967 static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant
*wpa_s
,
970 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
972 u8 p2p_dev_addr
[ETH_ALEN
];
973 #endif /* CONFIG_P2P */
975 u8
*_p2p_dev_addr
= NULL
;
976 #endif /* CONFIG_AP */
978 if (cmd
== NULL
|| os_strcmp(cmd
, "any") == 0) {
981 } else if (os_strncmp(cmd
, "p2p_dev_addr=", 13) == 0) {
982 if (hwaddr_aton(cmd
+ 13, p2p_dev_addr
)) {
983 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PBC: invalid "
984 "P2P Device Address '%s'",
988 _p2p_dev_addr
= p2p_dev_addr
;
989 #endif /* CONFIG_P2P */
990 } else if (hwaddr_aton(cmd
, bssid
)) {
991 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
998 return wpa_supplicant_ap_wps_pbc(wpa_s
, _bssid
, _p2p_dev_addr
);
999 #endif /* CONFIG_AP */
1001 return wpas_wps_start_pbc(wpa_s
, _bssid
, 0);
1005 static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant
*wpa_s
,
1006 char *cmd
, char *buf
,
1009 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
1013 pin
= os_strchr(cmd
, ' ');
1017 if (os_strcmp(cmd
, "any") == 0)
1019 else if (os_strcmp(cmd
, "get") == 0) {
1020 if (wps_generate_pin((unsigned int *) &ret
) < 0)
1023 } else if (hwaddr_aton(cmd
, bssid
)) {
1024 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
1030 if (wpa_s
->ap_iface
) {
1035 pos
= os_strchr(pin
, ' ');
1038 timeout
= atoi(pos
);
1042 return wpa_supplicant_ap_wps_pin(wpa_s
, _bssid
, pin
,
1043 buf
, buflen
, timeout
);
1045 #endif /* CONFIG_AP */
1048 ret
= wpas_wps_start_pin(wpa_s
, _bssid
, pin
, 0,
1052 ret
= os_snprintf(buf
, buflen
, "%s", pin
);
1053 if (os_snprintf_error(buflen
, ret
))
1058 ret
= wpas_wps_start_pin(wpa_s
, _bssid
, NULL
, 0, DEV_PW_DEFAULT
);
1063 /* Return the generated PIN */
1064 ret
= os_snprintf(buf
, buflen
, "%08d", ret
);
1065 if (os_snprintf_error(buflen
, ret
))
1071 static int wpa_supplicant_ctrl_iface_wps_check_pin(
1072 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
1079 wpa_hexdump_ascii_key(MSG_DEBUG
, "WPS_CHECK_PIN",
1080 (u8
*) cmd
, os_strlen(cmd
));
1081 for (pos
= cmd
, len
= 0; *pos
!= '\0'; pos
++) {
1082 if (*pos
< '0' || *pos
> '9')
1086 wpa_printf(MSG_DEBUG
, "WPS: Too long PIN");
1090 if (len
!= 4 && len
!= 8) {
1091 wpa_printf(MSG_DEBUG
, "WPS: Invalid PIN length %d", (int) len
);
1097 unsigned int pin_val
;
1098 pin_val
= atoi(pin
);
1099 if (!wps_pin_valid(pin_val
)) {
1100 wpa_printf(MSG_DEBUG
, "WPS: Invalid checksum digit");
1101 ret
= os_snprintf(buf
, buflen
, "FAIL-CHECKSUM\n");
1102 if (os_snprintf_error(buflen
, ret
))
1108 ret
= os_snprintf(buf
, buflen
, "%s", pin
);
1109 if (os_snprintf_error(buflen
, ret
))
1116 #ifdef CONFIG_WPS_NFC
1118 static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant
*wpa_s
,
1121 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
1123 if (cmd
== NULL
|| cmd
[0] == '\0')
1125 else if (hwaddr_aton(cmd
, bssid
))
1128 return wpas_wps_start_nfc(wpa_s
, NULL
, _bssid
, NULL
, 0, 0, NULL
, NULL
,
1133 static int wpa_supplicant_ctrl_iface_wps_nfc_config_token(
1134 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
1141 pos
= os_strchr(cmd
, ' ');
1144 if (os_strcmp(cmd
, "WPS") == 0)
1146 else if (os_strcmp(cmd
, "NDEF") == 0)
1151 buf
= wpas_wps_nfc_config_token(wpa_s
, ndef
, pos
);
1155 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1157 reply
[res
++] = '\n';
1166 static int wpa_supplicant_ctrl_iface_wps_nfc_token(
1167 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
1173 if (os_strcmp(cmd
, "WPS") == 0)
1175 else if (os_strcmp(cmd
, "NDEF") == 0)
1180 buf
= wpas_wps_nfc_token(wpa_s
, ndef
);
1184 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1186 reply
[res
++] = '\n';
1195 static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
1196 struct wpa_supplicant
*wpa_s
, char *pos
)
1202 int forced_freq
= 0;
1204 freq
= strstr(pos
, " freq=");
1208 forced_freq
= atoi(freq
);
1211 len
= os_strlen(pos
);
1216 buf
= wpabuf_alloc(len
);
1219 if (hexstr2bin(pos
, wpabuf_put(buf
, len
), len
) < 0) {
1224 ret
= wpas_wps_nfc_tag_read(wpa_s
, buf
, forced_freq
);
1231 static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant
*wpa_s
,
1232 char *reply
, size_t max_len
,
1238 buf
= wpas_wps_nfc_handover_req(wpa_s
, ndef
);
1242 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1244 reply
[res
++] = '\n';
1254 static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant
*wpa_s
,
1255 char *reply
, size_t max_len
,
1261 buf
= wpas_p2p_nfc_handover_req(wpa_s
, ndef
);
1263 wpa_printf(MSG_DEBUG
, "P2P: Could not generate NFC handover request");
1267 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1269 reply
[res
++] = '\n';
1276 #endif /* CONFIG_P2P */
1279 static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant
*wpa_s
,
1280 char *cmd
, char *reply
,
1286 pos
= os_strchr(cmd
, ' ');
1291 if (os_strcmp(cmd
, "WPS") == 0)
1293 else if (os_strcmp(cmd
, "NDEF") == 0)
1298 if (os_strcmp(pos
, "WPS") == 0 || os_strcmp(pos
, "WPS-CR") == 0) {
1301 return wpas_ctrl_nfc_get_handover_req_wps(
1302 wpa_s
, reply
, max_len
, ndef
);
1306 if (os_strcmp(pos
, "P2P-CR") == 0) {
1307 return wpas_ctrl_nfc_get_handover_req_p2p(
1308 wpa_s
, reply
, max_len
, ndef
);
1310 #endif /* CONFIG_P2P */
1316 static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant
*wpa_s
,
1317 char *reply
, size_t max_len
,
1318 int ndef
, int cr
, char *uuid
)
1323 buf
= wpas_wps_nfc_handover_sel(wpa_s
, ndef
, cr
, uuid
);
1327 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1329 reply
[res
++] = '\n';
1339 static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant
*wpa_s
,
1340 char *reply
, size_t max_len
,
1346 buf
= wpas_p2p_nfc_handover_sel(wpa_s
, ndef
, tag
);
1350 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1352 reply
[res
++] = '\n';
1359 #endif /* CONFIG_P2P */
1362 static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant
*wpa_s
,
1363 char *cmd
, char *reply
,
1369 pos
= os_strchr(cmd
, ' ');
1374 if (os_strcmp(cmd
, "WPS") == 0)
1376 else if (os_strcmp(cmd
, "NDEF") == 0)
1381 pos2
= os_strchr(pos
, ' ');
1384 if (os_strcmp(pos
, "WPS") == 0 || os_strcmp(pos
, "WPS-CR") == 0) {
1387 return wpas_ctrl_nfc_get_handover_sel_wps(
1388 wpa_s
, reply
, max_len
, ndef
,
1389 os_strcmp(pos
, "WPS-CR") == 0, pos2
);
1393 if (os_strcmp(pos
, "P2P-CR") == 0) {
1394 return wpas_ctrl_nfc_get_handover_sel_p2p(
1395 wpa_s
, reply
, max_len
, ndef
, 0);
1398 if (os_strcmp(pos
, "P2P-CR-TAG") == 0) {
1399 return wpas_ctrl_nfc_get_handover_sel_p2p(
1400 wpa_s
, reply
, max_len
, ndef
, 1);
1402 #endif /* CONFIG_P2P */
1408 static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant
*wpa_s
,
1412 struct wpabuf
*req
, *sel
;
1414 char *pos
, *role
, *type
, *pos2
;
1417 int forced_freq
= 0;
1419 freq
= strstr(cmd
, " freq=");
1423 forced_freq
= atoi(freq
);
1425 #endif /* CONFIG_P2P */
1428 pos
= os_strchr(role
, ' ');
1430 wpa_printf(MSG_DEBUG
, "NFC: Missing type in handover report");
1436 pos
= os_strchr(type
, ' ');
1438 wpa_printf(MSG_DEBUG
, "NFC: Missing request message in handover report");
1443 pos2
= os_strchr(pos
, ' ');
1445 wpa_printf(MSG_DEBUG
, "NFC: Missing select message in handover report");
1450 len
= os_strlen(pos
);
1452 wpa_printf(MSG_DEBUG
, "NFC: Invalid request message length in handover report");
1457 req
= wpabuf_alloc(len
);
1459 wpa_printf(MSG_DEBUG
, "NFC: Failed to allocate memory for request message");
1462 if (hexstr2bin(pos
, wpabuf_put(req
, len
), len
) < 0) {
1463 wpa_printf(MSG_DEBUG
, "NFC: Invalid request message hexdump in handover report");
1468 len
= os_strlen(pos2
);
1470 wpa_printf(MSG_DEBUG
, "NFC: Invalid select message length in handover report");
1476 sel
= wpabuf_alloc(len
);
1478 wpa_printf(MSG_DEBUG
, "NFC: Failed to allocate memory for select message");
1482 if (hexstr2bin(pos2
, wpabuf_put(sel
, len
), len
) < 0) {
1483 wpa_printf(MSG_DEBUG
, "NFC: Invalid select message hexdump in handover report");
1489 wpa_printf(MSG_DEBUG
, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d",
1490 role
, type
, (int) wpabuf_len(req
), (int) wpabuf_len(sel
));
1492 if (os_strcmp(role
, "INIT") == 0 && os_strcmp(type
, "WPS") == 0) {
1493 ret
= wpas_wps_nfc_report_handover(wpa_s
, req
, sel
);
1495 } else if (os_strcmp(role
, "RESP") == 0 && os_strcmp(type
, "WPS") == 0)
1497 ret
= wpas_ap_wps_nfc_report_handover(wpa_s
, req
, sel
);
1499 ret
= wpas_er_wps_nfc_report_handover(wpa_s
, req
, sel
);
1500 #endif /* CONFIG_AP */
1502 } else if (os_strcmp(role
, "INIT") == 0 && os_strcmp(type
, "P2P") == 0)
1504 ret
= wpas_p2p_nfc_report_handover(wpa_s
, 1, req
, sel
, 0);
1505 } else if (os_strcmp(role
, "RESP") == 0 && os_strcmp(type
, "P2P") == 0)
1507 ret
= wpas_p2p_nfc_report_handover(wpa_s
, 0, req
, sel
,
1509 #endif /* CONFIG_P2P */
1511 wpa_printf(MSG_DEBUG
, "NFC: Unsupported connection handover "
1512 "reported: role=%s type=%s", role
, type
);
1519 wpa_printf(MSG_DEBUG
, "NFC: Failed to process reported handover messages");
1524 #endif /* CONFIG_WPS_NFC */
1527 static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant
*wpa_s
,
1536 struct wps_new_ap_settings ap
;
1538 pin
= os_strchr(cmd
, ' ');
1543 if (hwaddr_aton(cmd
, bssid
)) {
1544 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
1549 new_ssid
= os_strchr(pin
, ' ');
1550 if (new_ssid
== NULL
)
1551 return wpas_wps_start_reg(wpa_s
, bssid
, pin
, NULL
);
1554 new_auth
= os_strchr(new_ssid
, ' ');
1555 if (new_auth
== NULL
)
1559 new_encr
= os_strchr(new_auth
, ' ');
1560 if (new_encr
== NULL
)
1564 new_key
= os_strchr(new_encr
, ' ');
1565 if (new_key
== NULL
)
1569 os_memset(&ap
, 0, sizeof(ap
));
1570 ap
.ssid_hex
= new_ssid
;
1573 ap
.key_hex
= new_key
;
1574 return wpas_wps_start_reg(wpa_s
, bssid
, pin
, &ap
);
1579 static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant
*wpa_s
,
1580 char *cmd
, char *buf
,
1585 const char *pin_txt
;
1587 if (!wpa_s
->ap_iface
)
1590 pos
= os_strchr(cmd
, ' ');
1594 if (os_strcmp(cmd
, "disable") == 0) {
1595 wpas_wps_ap_pin_disable(wpa_s
);
1596 return os_snprintf(buf
, buflen
, "OK\n");
1599 if (os_strcmp(cmd
, "random") == 0) {
1601 timeout
= atoi(pos
);
1602 pin_txt
= wpas_wps_ap_pin_random(wpa_s
, timeout
);
1603 if (pin_txt
== NULL
)
1605 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
1608 if (os_strcmp(cmd
, "get") == 0) {
1609 pin_txt
= wpas_wps_ap_pin_get(wpa_s
);
1610 if (pin_txt
== NULL
)
1612 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
1615 if (os_strcmp(cmd
, "set") == 0) {
1620 pos
= os_strchr(pos
, ' ');
1623 timeout
= atoi(pos
);
1625 if (os_strlen(pin
) > buflen
)
1627 if (wpas_wps_ap_pin_set(wpa_s
, pin
, timeout
) < 0)
1629 return os_snprintf(buf
, buflen
, "%s", pin
);
1634 #endif /* CONFIG_AP */
1637 #ifdef CONFIG_WPS_ER
1638 static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant
*wpa_s
,
1641 char *uuid
= cmd
, *pin
, *pos
;
1642 u8 addr_buf
[ETH_ALEN
], *addr
= NULL
;
1643 pin
= os_strchr(uuid
, ' ');
1647 pos
= os_strchr(pin
, ' ');
1650 if (hwaddr_aton(pos
, addr_buf
) == 0)
1653 return wpas_wps_er_add_pin(wpa_s
, addr
, uuid
, pin
);
1657 static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant
*wpa_s
,
1660 char *uuid
= cmd
, *pin
;
1661 pin
= os_strchr(uuid
, ' ');
1665 return wpas_wps_er_learn(wpa_s
, uuid
, pin
);
1669 static int wpa_supplicant_ctrl_iface_wps_er_set_config(
1670 struct wpa_supplicant
*wpa_s
, char *cmd
)
1672 char *uuid
= cmd
, *id
;
1673 id
= os_strchr(uuid
, ' ');
1677 return wpas_wps_er_set_config(wpa_s
, uuid
, atoi(id
));
1681 static int wpa_supplicant_ctrl_iface_wps_er_config(
1682 struct wpa_supplicant
*wpa_s
, char *cmd
)
1689 struct wps_new_ap_settings ap
;
1691 pin
= os_strchr(cmd
, ' ');
1696 new_ssid
= os_strchr(pin
, ' ');
1697 if (new_ssid
== NULL
)
1701 new_auth
= os_strchr(new_ssid
, ' ');
1702 if (new_auth
== NULL
)
1706 new_encr
= os_strchr(new_auth
, ' ');
1707 if (new_encr
== NULL
)
1711 new_key
= os_strchr(new_encr
, ' ');
1712 if (new_key
== NULL
)
1716 os_memset(&ap
, 0, sizeof(ap
));
1717 ap
.ssid_hex
= new_ssid
;
1720 ap
.key_hex
= new_key
;
1721 return wpas_wps_er_config(wpa_s
, cmd
, pin
, &ap
);
1725 #ifdef CONFIG_WPS_NFC
1726 static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
1727 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
1734 uuid
= os_strchr(cmd
, ' ');
1739 if (os_strcmp(cmd
, "WPS") == 0)
1741 else if (os_strcmp(cmd
, "NDEF") == 0)
1746 buf
= wpas_wps_er_nfc_config_token(wpa_s
, ndef
, uuid
);
1750 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1752 reply
[res
++] = '\n';
1759 #endif /* CONFIG_WPS_NFC */
1760 #endif /* CONFIG_WPS_ER */
1762 #endif /* CONFIG_WPS */
1765 #ifdef CONFIG_IBSS_RSN
1766 static int wpa_supplicant_ctrl_iface_ibss_rsn(
1767 struct wpa_supplicant
*wpa_s
, char *addr
)
1771 if (hwaddr_aton(addr
, peer
)) {
1772 wpa_printf(MSG_DEBUG
, "CTRL_IFACE IBSS_RSN: invalid "
1773 "address '%s'", addr
);
1777 wpa_printf(MSG_DEBUG
, "CTRL_IFACE IBSS_RSN " MACSTR
,
1780 return ibss_rsn_start(wpa_s
->ibss_rsn
, peer
);
1782 #endif /* CONFIG_IBSS_RSN */
1785 static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant
*wpa_s
,
1788 #ifdef IEEE8021X_EAPOL
1791 struct wpa_ssid
*ssid
;
1793 pos
= os_strchr(rsp
, '-');
1798 pos
= os_strchr(pos
, ':');
1803 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: field=%s id=%d", rsp
, id
);
1804 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
1805 (u8
*) pos
, os_strlen(pos
));
1807 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1809 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
1814 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s
, ssid
, rsp
,
1816 #else /* IEEE8021X_EAPOL */
1817 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: 802.1X not included");
1819 #endif /* IEEE8021X_EAPOL */
1823 static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant
*wpa_s
,
1825 char *buf
, size_t buflen
)
1827 char *pos
, *end
, tmp
[30];
1828 int res
, verbose
, wps
, ret
;
1831 #endif /* CONFIG_HS20 */
1835 if (os_strcmp(params
, "-DRIVER") == 0)
1836 return wpa_drv_status(wpa_s
, buf
, buflen
);
1837 verbose
= os_strcmp(params
, "-VERBOSE") == 0;
1838 wps
= os_strcmp(params
, "-WPS") == 0;
1841 if (wpa_s
->wpa_state
>= WPA_ASSOCIATED
) {
1842 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
1843 ret
= os_snprintf(pos
, end
- pos
, "bssid=" MACSTR
"\n",
1844 MAC2STR(wpa_s
->bssid
));
1845 if (os_snprintf_error(end
- pos
, ret
))
1848 ret
= os_snprintf(pos
, end
- pos
, "freq=%u\n",
1850 if (os_snprintf_error(end
- pos
, ret
))
1854 u8
*_ssid
= ssid
->ssid
;
1855 size_t ssid_len
= ssid
->ssid_len
;
1856 u8 ssid_buf
[SSID_MAX_LEN
];
1857 if (ssid_len
== 0) {
1858 int _res
= wpa_drv_get_ssid(wpa_s
, ssid_buf
);
1865 ret
= os_snprintf(pos
, end
- pos
, "ssid=%s\nid=%d\n",
1866 wpa_ssid_txt(_ssid
, ssid_len
),
1868 if (os_snprintf_error(end
- pos
, ret
))
1872 if (wps
&& ssid
->passphrase
&&
1873 wpa_key_mgmt_wpa_psk(ssid
->key_mgmt
) &&
1874 (ssid
->mode
== WPAS_MODE_AP
||
1875 ssid
->mode
== WPAS_MODE_P2P_GO
)) {
1876 ret
= os_snprintf(pos
, end
- pos
,
1879 if (os_snprintf_error(end
- pos
, ret
))
1884 ret
= os_snprintf(pos
, end
- pos
,
1887 if (os_snprintf_error(end
- pos
, ret
))
1892 switch (ssid
->mode
) {
1893 case WPAS_MODE_INFRA
:
1894 ret
= os_snprintf(pos
, end
- pos
,
1897 case WPAS_MODE_IBSS
:
1898 ret
= os_snprintf(pos
, end
- pos
,
1902 ret
= os_snprintf(pos
, end
- pos
,
1905 case WPAS_MODE_P2P_GO
:
1906 ret
= os_snprintf(pos
, end
- pos
,
1909 case WPAS_MODE_P2P_GROUP_FORMATION
:
1910 ret
= os_snprintf(pos
, end
- pos
,
1911 "mode=P2P GO - group "
1914 case WPAS_MODE_MESH
:
1915 ret
= os_snprintf(pos
, end
- pos
,
1922 if (os_snprintf_error(end
- pos
, ret
))
1928 if (wpa_s
->ap_iface
) {
1929 pos
+= ap_ctrl_iface_wpa_get_status(wpa_s
, pos
,
1933 #endif /* CONFIG_AP */
1934 pos
+= wpa_sm_get_status(wpa_s
->wpa
, pos
, end
- pos
, verbose
);
1938 if (wpa_s
->wpa_state
>= WPA_ASSOCIATED
&&
1941 #endif /* CONFIG_AP */
1942 wpa_s
->sme
.sae
.state
== SAE_ACCEPTED
) {
1943 ret
= os_snprintf(pos
, end
- pos
, "sae_group=%d\n",
1944 wpa_s
->sme
.sae
.group
);
1945 if (os_snprintf_error(end
- pos
, ret
))
1949 #endif /* CONFIG_SAE */
1950 #endif /* CONFIG_SME */
1951 ret
= os_snprintf(pos
, end
- pos
, "wpa_state=%s\n",
1952 wpa_supplicant_state_txt(wpa_s
->wpa_state
));
1953 if (os_snprintf_error(end
- pos
, ret
))
1958 l2_packet_get_ip_addr(wpa_s
->l2
, tmp
, sizeof(tmp
)) >= 0) {
1959 ret
= os_snprintf(pos
, end
- pos
, "ip_address=%s\n", tmp
);
1960 if (os_snprintf_error(end
- pos
, ret
))
1966 if (wpa_s
->global
->p2p
) {
1967 ret
= os_snprintf(pos
, end
- pos
, "p2p_device_address=" MACSTR
1968 "\n", MAC2STR(wpa_s
->global
->p2p_dev_addr
));
1969 if (os_snprintf_error(end
- pos
, ret
))
1973 #endif /* CONFIG_P2P */
1975 ret
= os_snprintf(pos
, end
- pos
, "address=" MACSTR
"\n",
1976 MAC2STR(wpa_s
->own_addr
));
1977 if (os_snprintf_error(end
- pos
, ret
))
1982 if (wpa_s
->current_bss
&&
1983 (hs20
= wpa_bss_get_vendor_ie(wpa_s
->current_bss
,
1984 HS20_IE_VENDOR_TYPE
)) &&
1985 wpa_s
->wpa_proto
== WPA_PROTO_RSN
&&
1986 wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
)) {
1989 u8 rel_num
= (hs20
[6] & 0xf0) >> 4;
1990 release
= rel_num
+ 1;
1992 ret
= os_snprintf(pos
, end
- pos
, "hs20=%d\n", release
);
1993 if (os_snprintf_error(end
- pos
, ret
))
1998 if (wpa_s
->current_ssid
) {
1999 struct wpa_cred
*cred
;
2002 for (cred
= wpa_s
->conf
->cred
; cred
; cred
= cred
->next
) {
2005 if (wpa_s
->current_ssid
->parent_cred
!= cred
)
2008 if (cred
->provisioning_sp
) {
2009 ret
= os_snprintf(pos
, end
- pos
,
2010 "provisioning_sp=%s\n",
2011 cred
->provisioning_sp
);
2012 if (os_snprintf_error(end
- pos
, ret
))
2021 if (wpa_s
->current_bss
&& wpa_s
->current_bss
->anqp
) {
2022 struct wpabuf
*names
=
2023 wpa_s
->current_bss
->anqp
->domain_name
;
2024 for (i
= 0; names
&& i
< cred
->num_domain
; i
++)
2026 if (domain_name_list_contains(
2027 names
, cred
->domain
[i
], 1))
2030 if (i
== cred
->num_domain
)
2031 i
= 0; /* show first entry by default */
2033 ret
= os_snprintf(pos
, end
- pos
, "home_sp=%s\n",
2035 if (os_snprintf_error(end
- pos
, ret
))
2040 if (wpa_s
->current_bss
== NULL
||
2041 wpa_s
->current_bss
->anqp
== NULL
)
2044 res
= interworking_home_sp_cred(
2046 wpa_s
->current_bss
->anqp
->domain_name
);
2054 ret
= os_snprintf(pos
, end
- pos
, "sp_type=%s\n", type
);
2055 if (os_snprintf_error(end
- pos
, ret
))
2062 #endif /* CONFIG_HS20 */
2064 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) ||
2065 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
2066 res
= eapol_sm_get_status(wpa_s
->eapol
, pos
, end
- pos
,
2072 #ifdef CONFIG_MACSEC
2073 res
= ieee802_1x_kay_get_status(wpa_s
->kay
, pos
, end
- pos
);
2076 #endif /* CONFIG_MACSEC */
2078 sess_id
= eapol_sm_get_session_id(wpa_s
->eapol
, &sess_id_len
);
2082 ret
= os_snprintf(pos
, end
- pos
, "eap_session_id=");
2083 if (os_snprintf_error(end
- pos
, ret
))
2086 ret
= wpa_snprintf_hex(pos
, end
- pos
, sess_id
, sess_id_len
);
2090 ret
= os_snprintf(pos
, end
- pos
, "\n");
2091 if (os_snprintf_error(end
- pos
, ret
))
2096 res
= rsn_preauth_get_status(wpa_s
->wpa
, pos
, end
- pos
, verbose
);
2103 uuid_bin2str(wpa_s
->wps
->uuid
, uuid_str
, sizeof(uuid_str
));
2104 ret
= os_snprintf(pos
, end
- pos
, "uuid=%s\n", uuid_str
);
2105 if (os_snprintf_error(end
- pos
, ret
))
2109 #endif /* CONFIG_WPS */
2113 * Allow using the STATUS command with default behavior, say for debug,
2114 * i.e., don't generate a "fake" CONNECTION and SUPPLICANT_STATE_CHANGE
2115 * events with STATUS-NO_EVENTS.
2117 if (os_strcmp(params
, "-NO_EVENTS")) {
2118 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_STATE_CHANGE
2119 "id=%d state=%d BSSID=" MACSTR
" SSID=%s",
2120 wpa_s
->current_ssid
? wpa_s
->current_ssid
->id
: -1,
2122 MAC2STR(wpa_s
->bssid
),
2123 wpa_s
->current_ssid
&& wpa_s
->current_ssid
->ssid
?
2124 wpa_ssid_txt(wpa_s
->current_ssid
->ssid
,
2125 wpa_s
->current_ssid
->ssid_len
) : "");
2126 if (wpa_s
->wpa_state
== WPA_COMPLETED
) {
2127 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
2128 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_CONNECTED
2129 "- connection to " MACSTR
2130 " completed %s [id=%d id_str=%s]",
2131 MAC2STR(wpa_s
->bssid
), "(auth)",
2132 ssid
? ssid
->id
: -1,
2133 ssid
&& ssid
->id_str
? ssid
->id_str
: "");
2136 #endif /* ANDROID */
2142 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant
*wpa_s
,
2147 struct wpa_ssid
*ssid
;
2150 /* cmd: "<network id> <BSSID>" */
2151 pos
= os_strchr(cmd
, ' ');
2156 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: id=%d bssid='%s'", id
, pos
);
2157 if (hwaddr_aton(pos
, bssid
)) {
2158 wpa_printf(MSG_DEBUG
,"CTRL_IFACE: invalid BSSID '%s'", pos
);
2162 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2164 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
2169 os_memcpy(ssid
->bssid
, bssid
, ETH_ALEN
);
2170 ssid
->bssid_set
= !is_zero_ether_addr(bssid
);
2176 static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant
*wpa_s
,
2177 char *cmd
, char *buf
,
2181 struct wpa_blacklist
*e
;
2185 /* cmd: "BLACKLIST [<BSSID>]" */
2189 e
= wpa_s
->blacklist
;
2191 ret
= os_snprintf(pos
, end
- pos
, MACSTR
"\n",
2193 if (os_snprintf_error(end
- pos
, ret
))
2202 if (os_strncmp(cmd
, "clear", 5) == 0) {
2203 wpa_blacklist_clear(wpa_s
);
2204 os_memcpy(buf
, "OK\n", 3);
2208 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd
);
2209 if (hwaddr_aton(cmd
, bssid
)) {
2210 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: invalid BSSID '%s'", cmd
);
2215 * Add the BSSID twice, so its count will be 2, causing it to be
2216 * skipped when processing scan results.
2218 ret
= wpa_blacklist_add(wpa_s
, bssid
);
2221 ret
= wpa_blacklist_add(wpa_s
, bssid
);
2224 os_memcpy(buf
, "OK\n", 3);
2229 static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant
*wpa_s
,
2230 char *cmd
, char *buf
,
2233 char *pos
, *end
, *stamp
;
2236 /* cmd: "LOG_LEVEL [<level>]" */
2240 ret
= os_snprintf(pos
, end
- pos
, "Current level: %s\n"
2242 debug_level_str(wpa_debug_level
),
2243 wpa_debug_timestamp
);
2244 if (os_snprintf_error(end
- pos
, ret
))
2253 stamp
= os_strchr(cmd
, ' ');
2256 while (*stamp
== ' ') {
2261 if (os_strlen(cmd
)) {
2262 int level
= str_to_debug_level(cmd
);
2265 wpa_debug_level
= level
;
2268 if (stamp
&& os_strlen(stamp
))
2269 wpa_debug_timestamp
= atoi(stamp
);
2271 os_memcpy(buf
, "OK\n", 3);
2276 static int wpa_supplicant_ctrl_iface_list_networks(
2277 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
2279 char *pos
, *end
, *prev
;
2280 struct wpa_ssid
*ssid
;
2285 ret
= os_snprintf(pos
, end
- pos
,
2286 "network id / ssid / bssid / flags\n");
2287 if (os_snprintf_error(end
- pos
, ret
))
2291 ssid
= wpa_s
->conf
->ssid
;
2293 /* skip over ssids until we find next one */
2294 if (cmd
!= NULL
&& os_strncmp(cmd
, "LAST_ID=", 8) == 0) {
2295 int last_id
= atoi(cmd
+ 8);
2296 if (last_id
!= -1) {
2297 while (ssid
!= NULL
&& ssid
->id
<= last_id
) {
2305 ret
= os_snprintf(pos
, end
- pos
, "%d\t%s",
2307 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
));
2308 if (os_snprintf_error(end
- pos
, ret
))
2311 if (ssid
->bssid_set
) {
2312 ret
= os_snprintf(pos
, end
- pos
, "\t" MACSTR
,
2313 MAC2STR(ssid
->bssid
));
2315 ret
= os_snprintf(pos
, end
- pos
, "\tany");
2317 if (os_snprintf_error(end
- pos
, ret
))
2320 ret
= os_snprintf(pos
, end
- pos
, "\t%s%s%s%s",
2321 ssid
== wpa_s
->current_ssid
?
2323 ssid
->disabled
? "[DISABLED]" : "",
2324 ssid
->disabled_until
.sec
?
2325 "[TEMP-DISABLED]" : "",
2326 ssid
->disabled
== 2 ? "[P2P-PERSISTENT]" :
2328 if (os_snprintf_error(end
- pos
, ret
))
2331 ret
= os_snprintf(pos
, end
- pos
, "\n");
2332 if (os_snprintf_error(end
- pos
, ret
))
2343 static char * wpa_supplicant_cipher_txt(char *pos
, char *end
, int cipher
)
2346 ret
= os_snprintf(pos
, end
- pos
, "-");
2347 if (os_snprintf_error(end
- pos
, ret
))
2350 ret
= wpa_write_ciphers(pos
, end
, cipher
, "+");
2358 static char * wpa_supplicant_ie_txt(char *pos
, char *end
, const char *proto
,
2359 const u8
*ie
, size_t ie_len
)
2361 struct wpa_ie_data data
;
2365 ret
= os_snprintf(pos
, end
- pos
, "[%s-", proto
);
2366 if (os_snprintf_error(end
- pos
, ret
))
2370 if (wpa_parse_wpa_ie(ie
, ie_len
, &data
) < 0) {
2371 ret
= os_snprintf(pos
, end
- pos
, "?]");
2372 if (os_snprintf_error(end
- pos
, ret
))
2379 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X
) {
2380 ret
= os_snprintf(pos
, end
- pos
, "%sEAP",
2381 pos
== start
? "" : "+");
2382 if (os_snprintf_error(end
- pos
, ret
))
2386 if (data
.key_mgmt
& WPA_KEY_MGMT_PSK
) {
2387 ret
= os_snprintf(pos
, end
- pos
, "%sPSK",
2388 pos
== start
? "" : "+");
2389 if (os_snprintf_error(end
- pos
, ret
))
2393 if (data
.key_mgmt
& WPA_KEY_MGMT_WPA_NONE
) {
2394 ret
= os_snprintf(pos
, end
- pos
, "%sNone",
2395 pos
== start
? "" : "+");
2396 if (os_snprintf_error(end
- pos
, ret
))
2400 if (data
.key_mgmt
& WPA_KEY_MGMT_SAE
) {
2401 ret
= os_snprintf(pos
, end
- pos
, "%sSAE",
2402 pos
== start
? "" : "+");
2403 if (os_snprintf_error(end
- pos
, ret
))
2407 #ifdef CONFIG_IEEE80211R
2408 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_IEEE8021X
) {
2409 ret
= os_snprintf(pos
, end
- pos
, "%sFT/EAP",
2410 pos
== start
? "" : "+");
2411 if (os_snprintf_error(end
- pos
, ret
))
2415 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_PSK
) {
2416 ret
= os_snprintf(pos
, end
- pos
, "%sFT/PSK",
2417 pos
== start
? "" : "+");
2418 if (os_snprintf_error(end
- pos
, ret
))
2422 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_SAE
) {
2423 ret
= os_snprintf(pos
, end
- pos
, "%sFT/SAE",
2424 pos
== start
? "" : "+");
2425 if (os_snprintf_error(end
- pos
, ret
))
2429 #endif /* CONFIG_IEEE80211R */
2430 #ifdef CONFIG_IEEE80211W
2431 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SHA256
) {
2432 ret
= os_snprintf(pos
, end
- pos
, "%sEAP-SHA256",
2433 pos
== start
? "" : "+");
2434 if (os_snprintf_error(end
- pos
, ret
))
2438 if (data
.key_mgmt
& WPA_KEY_MGMT_PSK_SHA256
) {
2439 ret
= os_snprintf(pos
, end
- pos
, "%sPSK-SHA256",
2440 pos
== start
? "" : "+");
2441 if (os_snprintf_error(end
- pos
, ret
))
2445 #endif /* CONFIG_IEEE80211W */
2447 #ifdef CONFIG_SUITEB
2448 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SUITE_B
) {
2449 ret
= os_snprintf(pos
, end
- pos
, "%sEAP-SUITE-B",
2450 pos
== start
? "" : "+");
2451 if (os_snprintf_error(end
- pos
, ret
))
2455 #endif /* CONFIG_SUITEB */
2457 #ifdef CONFIG_SUITEB192
2458 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SUITE_B_192
) {
2459 ret
= os_snprintf(pos
, end
- pos
, "%sEAP-SUITE-B-192",
2460 pos
== start
? "" : "+");
2461 if (os_snprintf_error(end
- pos
, ret
))
2465 #endif /* CONFIG_SUITEB192 */
2468 if (data
.key_mgmt
& WPA_KEY_MGMT_FILS_SHA256
) {
2469 ret
= os_snprintf(pos
, end
- pos
, "%sFILS-SHA256",
2470 pos
== start
? "" : "+");
2471 if (os_snprintf_error(end
- pos
, ret
))
2475 if (data
.key_mgmt
& WPA_KEY_MGMT_FILS_SHA384
) {
2476 ret
= os_snprintf(pos
, end
- pos
, "%sFILS-SHA384",
2477 pos
== start
? "" : "+");
2478 if (os_snprintf_error(end
- pos
, ret
))
2482 #ifdef CONFIG_IEEE80211R
2483 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_FILS_SHA256
) {
2484 ret
= os_snprintf(pos
, end
- pos
, "%sFT-FILS-SHA256",
2485 pos
== start
? "" : "+");
2486 if (os_snprintf_error(end
- pos
, ret
))
2490 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_FILS_SHA384
) {
2491 ret
= os_snprintf(pos
, end
- pos
, "%sFT-FILS-SHA384",
2492 pos
== start
? "" : "+");
2493 if (os_snprintf_error(end
- pos
, ret
))
2497 #endif /* CONFIG_IEEE80211R */
2498 #endif /* CONFIG_FILS */
2500 if (data
.key_mgmt
& WPA_KEY_MGMT_OSEN
) {
2501 ret
= os_snprintf(pos
, end
- pos
, "%sOSEN",
2502 pos
== start
? "" : "+");
2503 if (os_snprintf_error(end
- pos
, ret
))
2508 pos
= wpa_supplicant_cipher_txt(pos
, end
, data
.pairwise_cipher
);
2510 if (data
.capabilities
& WPA_CAPABILITY_PREAUTH
) {
2511 ret
= os_snprintf(pos
, end
- pos
, "-preauth");
2512 if (os_snprintf_error(end
- pos
, ret
))
2517 ret
= os_snprintf(pos
, end
- pos
, "]");
2518 if (os_snprintf_error(end
- pos
, ret
))
2527 static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant
*wpa_s
,
2528 char *pos
, char *end
,
2529 struct wpabuf
*wps_ie
)
2536 if (wps_is_selected_pbc_registrar(wps_ie
))
2538 else if (wps_is_addr_authorized(wps_ie
, wpa_s
->own_addr
, 0))
2540 else if (wps_is_selected_pin_registrar(wps_ie
))
2545 ret
= os_snprintf(pos
, end
- pos
, "%s", txt
);
2546 if (!os_snprintf_error(end
- pos
, ret
))
2548 wpabuf_free(wps_ie
);
2551 #endif /* CONFIG_WPS */
2554 static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant
*wpa_s
,
2555 char *pos
, char *end
,
2556 const struct wpa_bss
*bss
)
2559 struct wpabuf
*wps_ie
;
2560 wps_ie
= wpa_bss_get_vendor_ie_multi(bss
, WPS_IE_VENDOR_TYPE
);
2561 return wpa_supplicant_wps_ie_txt_buf(wpa_s
, pos
, end
, wps_ie
);
2562 #else /* CONFIG_WPS */
2564 #endif /* CONFIG_WPS */
2568 /* Format one result on one text line into a buffer. */
2569 static int wpa_supplicant_ctrl_iface_scan_result(
2570 struct wpa_supplicant
*wpa_s
,
2571 const struct wpa_bss
*bss
, char *buf
, size_t buflen
)
2575 const u8
*ie
, *ie2
, *osen_ie
, *p2p
, *mesh
;
2577 mesh
= wpa_bss_get_ie(bss
, WLAN_EID_MESH_ID
);
2578 p2p
= wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
);
2580 p2p
= wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
);
2581 if (p2p
&& bss
->ssid_len
== P2P_WILDCARD_SSID_LEN
&&
2582 os_memcmp(bss
->ssid
, P2P_WILDCARD_SSID
, P2P_WILDCARD_SSID_LEN
) ==
2584 return 0; /* Do not show P2P listen discovery results here */
2589 ret
= os_snprintf(pos
, end
- pos
, MACSTR
"\t%d\t%d\t",
2590 MAC2STR(bss
->bssid
), bss
->freq
, bss
->level
);
2591 if (os_snprintf_error(end
- pos
, ret
))
2594 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
2596 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA", ie
, 2 + ie
[1]);
2597 ie2
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
2599 pos
= wpa_supplicant_ie_txt(pos
, end
, mesh
? "RSN" : "WPA2",
2602 osen_ie
= wpa_bss_get_vendor_ie(bss
, OSEN_IE_VENDOR_TYPE
);
2604 pos
= wpa_supplicant_ie_txt(pos
, end
, "OSEN",
2605 osen_ie
, 2 + osen_ie
[1]);
2606 pos
= wpa_supplicant_wps_ie_txt(wpa_s
, pos
, end
, bss
);
2607 if (!ie
&& !ie2
&& !osen_ie
&& (bss
->caps
& IEEE80211_CAP_PRIVACY
)) {
2608 ret
= os_snprintf(pos
, end
- pos
, "[WEP]");
2609 if (os_snprintf_error(end
- pos
, ret
))
2614 ret
= os_snprintf(pos
, end
- pos
, "[MESH]");
2615 if (os_snprintf_error(end
- pos
, ret
))
2619 if (bss_is_dmg(bss
)) {
2621 ret
= os_snprintf(pos
, end
- pos
, "[DMG]");
2622 if (os_snprintf_error(end
- pos
, ret
))
2625 switch (bss
->caps
& IEEE80211_CAP_DMG_MASK
) {
2626 case IEEE80211_CAP_DMG_IBSS
:
2629 case IEEE80211_CAP_DMG_AP
:
2632 case IEEE80211_CAP_DMG_PBSS
:
2639 ret
= os_snprintf(pos
, end
- pos
, "%s", s
);
2640 if (os_snprintf_error(end
- pos
, ret
))
2644 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
2645 ret
= os_snprintf(pos
, end
- pos
, "[IBSS]");
2646 if (os_snprintf_error(end
- pos
, ret
))
2650 if (bss
->caps
& IEEE80211_CAP_ESS
) {
2651 ret
= os_snprintf(pos
, end
- pos
, "[ESS]");
2652 if (os_snprintf_error(end
- pos
, ret
))
2658 ret
= os_snprintf(pos
, end
- pos
, "[P2P]");
2659 if (os_snprintf_error(end
- pos
, ret
))
2664 if (wpa_bss_get_vendor_ie(bss
, HS20_IE_VENDOR_TYPE
) && ie2
) {
2665 ret
= os_snprintf(pos
, end
- pos
, "[HS20]");
2666 if (os_snprintf_error(end
- pos
, ret
))
2670 #endif /* CONFIG_HS20 */
2672 if (wpa_bss_get_ie(bss
, WLAN_EID_FILS_INDICATION
)) {
2673 ret
= os_snprintf(pos
, end
- pos
, "[FILS]");
2674 if (os_snprintf_error(end
- pos
, ret
))
2678 #endif /* CONFIG_FILS */
2680 if (wpa_bss_get_ie(bss
, WLAN_EID_MULTI_BAND
)) {
2681 ret
= os_snprintf(pos
, end
- pos
, "[FST]");
2682 if (os_snprintf_error(end
- pos
, ret
))
2686 #endif /* CONFIG_FST */
2688 ret
= os_snprintf(pos
, end
- pos
, "\t%s",
2689 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
2690 if (os_snprintf_error(end
- pos
, ret
))
2694 ret
= os_snprintf(pos
, end
- pos
, "\n");
2695 if (os_snprintf_error(end
- pos
, ret
))
2703 static int wpa_supplicant_ctrl_iface_scan_results(
2704 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
2707 struct wpa_bss
*bss
;
2712 ret
= os_snprintf(pos
, end
- pos
, "bssid / frequency / signal level / "
2714 if (os_snprintf_error(end
- pos
, ret
))
2718 dl_list_for_each(bss
, &wpa_s
->bss_id
, struct wpa_bss
, list_id
) {
2719 ret
= wpa_supplicant_ctrl_iface_scan_result(wpa_s
, bss
, pos
,
2721 if (ret
< 0 || ret
>= end
- pos
)
2732 static int wpa_supplicant_ctrl_iface_mesh_interface_add(
2733 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
2735 char *pos
, ifname
[IFNAMSIZ
+ 1];
2739 pos
= os_strstr(cmd
, "ifname=");
2742 os_strlcpy(ifname
, pos
, sizeof(ifname
));
2745 if (wpas_mesh_add_interface(wpa_s
, ifname
, sizeof(ifname
)) < 0)
2748 os_strlcpy(reply
, ifname
, max_len
);
2749 return os_strlen(ifname
);
2753 static int wpa_supplicant_ctrl_iface_mesh_group_add(
2754 struct wpa_supplicant
*wpa_s
, char *cmd
)
2757 struct wpa_ssid
*ssid
;
2760 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: MESH_GROUP_ADD id=%d", id
);
2762 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2764 wpa_printf(MSG_DEBUG
,
2765 "CTRL_IFACE: Could not find network id=%d", id
);
2768 if (ssid
->mode
!= WPAS_MODE_MESH
) {
2769 wpa_printf(MSG_DEBUG
,
2770 "CTRL_IFACE: Cannot use MESH_GROUP_ADD on a non mesh network");
2773 if (ssid
->key_mgmt
!= WPA_KEY_MGMT_NONE
&&
2774 ssid
->key_mgmt
!= WPA_KEY_MGMT_SAE
) {
2775 wpa_printf(MSG_ERROR
,
2776 "CTRL_IFACE: key_mgmt for mesh network should be open or SAE");
2781 * TODO: If necessary write our own group_add function,
2782 * for now we can reuse select_network
2784 wpa_supplicant_select_network(wpa_s
, ssid
);
2790 static int wpa_supplicant_ctrl_iface_mesh_group_remove(
2791 struct wpa_supplicant
*wpa_s
, char *cmd
)
2793 struct wpa_supplicant
*orig
;
2794 struct wpa_global
*global
;
2797 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s", cmd
);
2799 global
= wpa_s
->global
;
2802 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
2803 if (os_strcmp(wpa_s
->ifname
, cmd
) == 0) {
2809 wpa_printf(MSG_ERROR
,
2810 "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s not found",
2814 if (wpa_s
->mesh_if_created
&& wpa_s
== orig
) {
2815 wpa_printf(MSG_ERROR
,
2816 "CTRL_IFACE: MESH_GROUP_REMOVE can't remove itself");
2820 wpa_s
->reassociate
= 0;
2821 wpa_s
->disconnected
= 1;
2822 wpa_supplicant_cancel_sched_scan(wpa_s
);
2823 wpa_supplicant_cancel_scan(wpa_s
);
2826 * TODO: If necessary write our own group_remove function,
2827 * for now we can reuse deauthenticate
2829 wpa_supplicant_deauthenticate(wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2831 if (wpa_s
->mesh_if_created
)
2832 wpa_supplicant_remove_iface(global
, wpa_s
, 0);
2838 static int wpa_supplicant_ctrl_iface_mesh_peer_remove(
2839 struct wpa_supplicant
*wpa_s
, char *cmd
)
2843 if (hwaddr_aton(cmd
, addr
) < 0)
2846 return wpas_mesh_peer_remove(wpa_s
, addr
);
2850 static int wpa_supplicant_ctrl_iface_mesh_peer_add(
2851 struct wpa_supplicant
*wpa_s
, char *cmd
)
2857 pos
= os_strstr(cmd
, " duration=");
2860 duration
= atoi(pos
+ 10);
2865 if (hwaddr_aton(cmd
, addr
))
2868 return wpas_mesh_peer_add(wpa_s
, addr
, duration
);
2871 #endif /* CONFIG_MESH */
2874 static int wpa_supplicant_ctrl_iface_select_network(
2875 struct wpa_supplicant
*wpa_s
, char *cmd
)
2878 struct wpa_ssid
*ssid
;
2881 /* cmd: "<network id>" or "any" */
2882 if (os_strncmp(cmd
, "any", 3) == 0) {
2883 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SELECT_NETWORK any");
2887 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SELECT_NETWORK id=%d", id
);
2889 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2891 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
2892 "network id=%d", id
);
2895 if (ssid
->disabled
== 2) {
2896 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
2897 "SELECT_NETWORK with persistent P2P group");
2902 pos
= os_strstr(cmd
, " freq=");
2904 int *freqs
= freq_range_to_channel_list(wpa_s
, pos
+ 6);
2906 wpa_s
->scan_req
= MANUAL_SCAN_REQ
;
2907 os_free(wpa_s
->manual_scan_freqs
);
2908 wpa_s
->manual_scan_freqs
= freqs
;
2912 wpa_s
->scan_min_time
.sec
= 0;
2913 wpa_s
->scan_min_time
.usec
= 0;
2914 wpa_supplicant_select_network(wpa_s
, ssid
);
2920 static int wpa_supplicant_ctrl_iface_enable_network(
2921 struct wpa_supplicant
*wpa_s
, char *cmd
)
2924 struct wpa_ssid
*ssid
;
2926 /* cmd: "<network id>" or "all" */
2927 if (os_strcmp(cmd
, "all") == 0) {
2928 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ENABLE_NETWORK all");
2932 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ENABLE_NETWORK id=%d", id
);
2934 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2936 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
2937 "network id=%d", id
);
2940 if (ssid
->disabled
== 2) {
2941 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
2942 "ENABLE_NETWORK with persistent P2P group");
2946 if (os_strstr(cmd
, " no-connect")) {
2951 wpa_s
->scan_min_time
.sec
= 0;
2952 wpa_s
->scan_min_time
.usec
= 0;
2953 wpa_supplicant_enable_network(wpa_s
, ssid
);
2959 static int wpa_supplicant_ctrl_iface_disable_network(
2960 struct wpa_supplicant
*wpa_s
, char *cmd
)
2963 struct wpa_ssid
*ssid
;
2965 /* cmd: "<network id>" or "all" */
2966 if (os_strcmp(cmd
, "all") == 0) {
2967 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DISABLE_NETWORK all");
2971 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DISABLE_NETWORK id=%d", id
);
2973 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2975 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
2976 "network id=%d", id
);
2979 if (ssid
->disabled
== 2) {
2980 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
2981 "DISABLE_NETWORK with persistent P2P "
2986 wpa_supplicant_disable_network(wpa_s
, ssid
);
2992 static int wpa_supplicant_ctrl_iface_add_network(
2993 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
2995 struct wpa_ssid
*ssid
;
2998 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ADD_NETWORK");
3000 ssid
= wpa_supplicant_add_network(wpa_s
);
3004 ret
= os_snprintf(buf
, buflen
, "%d\n", ssid
->id
);
3005 if (os_snprintf_error(buflen
, ret
))
3011 static int wpa_supplicant_ctrl_iface_remove_network(
3012 struct wpa_supplicant
*wpa_s
, char *cmd
)
3015 struct wpa_ssid
*ssid
;
3018 /* cmd: "<network id>" or "all" */
3019 if (os_strcmp(cmd
, "all") == 0) {
3020 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_NETWORK all");
3021 if (wpa_s
->sched_scanning
)
3022 wpa_supplicant_cancel_sched_scan(wpa_s
);
3024 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
3025 if (wpa_s
->current_ssid
) {
3027 wpa_s
->sme
.prev_bssid_set
= 0;
3028 #endif /* CONFIG_SME */
3029 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
3030 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
3031 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
)
3032 wpa_s
->own_disconnect_req
= 1;
3033 wpa_supplicant_deauthenticate(
3034 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
3036 ssid
= wpa_s
->conf
->ssid
;
3038 struct wpa_ssid
*remove_ssid
= ssid
;
3041 if (wpa_s
->last_ssid
== remove_ssid
)
3042 wpa_s
->last_ssid
= NULL
;
3043 wpas_notify_network_removed(wpa_s
, remove_ssid
);
3044 wpa_config_remove_network(wpa_s
->conf
, id
);
3050 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_NETWORK id=%d", id
);
3052 result
= wpa_supplicant_remove_network(wpa_s
, id
);
3054 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
3059 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Not able to remove the "
3060 "network id=%d", id
);
3067 static int wpa_supplicant_ctrl_iface_update_network(
3068 struct wpa_supplicant
*wpa_s
, struct wpa_ssid
*ssid
,
3069 char *name
, char *value
)
3073 ret
= wpa_config_set(ssid
, name
, value
, 0);
3075 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to set network "
3076 "variable '%s'", name
);
3080 return 0; /* No change to the previously configured value */
3082 if (os_strcmp(name
, "bssid") != 0 &&
3083 os_strcmp(name
, "priority") != 0) {
3084 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, ssid
);
3086 if (wpa_s
->current_ssid
== ssid
||
3087 wpa_s
->current_ssid
== NULL
) {
3089 * Invalidate the EAP session cache if anything in the
3090 * current or previously used configuration changes.
3092 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
3096 if ((os_strcmp(name
, "psk") == 0 &&
3097 value
[0] == '"' && ssid
->ssid_len
) ||
3098 (os_strcmp(name
, "ssid") == 0 && ssid
->passphrase
))
3099 wpa_config_update_psk(ssid
);
3100 else if (os_strcmp(name
, "priority") == 0)
3101 wpa_config_update_prio_list(wpa_s
->conf
);
3107 static int wpa_supplicant_ctrl_iface_set_network(
3108 struct wpa_supplicant
*wpa_s
, char *cmd
)
3110 int id
, ret
, prev_bssid_set
, prev_disabled
;
3111 struct wpa_ssid
*ssid
;
3113 u8 prev_bssid
[ETH_ALEN
];
3115 /* cmd: "<network id> <variable name> <value>" */
3116 name
= os_strchr(cmd
, ' ');
3121 value
= os_strchr(name
, ' ');
3127 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
3129 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
3130 (u8
*) value
, os_strlen(value
));
3132 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3134 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
3139 prev_bssid_set
= ssid
->bssid_set
;
3140 prev_disabled
= ssid
->disabled
;
3141 os_memcpy(prev_bssid
, ssid
->bssid
, ETH_ALEN
);
3142 ret
= wpa_supplicant_ctrl_iface_update_network(wpa_s
, ssid
, name
,
3145 (ssid
->bssid_set
!= prev_bssid_set
||
3146 os_memcmp(ssid
->bssid
, prev_bssid
, ETH_ALEN
) != 0))
3147 wpas_notify_network_bssid_set_changed(wpa_s
, ssid
);
3149 if (prev_disabled
!= ssid
->disabled
&&
3150 (prev_disabled
== 2 || ssid
->disabled
== 2))
3151 wpas_notify_network_type_changed(wpa_s
, ssid
);
3157 static int wpa_supplicant_ctrl_iface_get_network(
3158 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
3162 struct wpa_ssid
*ssid
;
3165 /* cmd: "<network id> <variable name>" */
3166 name
= os_strchr(cmd
, ' ');
3167 if (name
== NULL
|| buflen
== 0)
3172 wpa_printf(MSG_EXCESSIVE
, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
3175 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3177 wpa_printf(MSG_EXCESSIVE
, "CTRL_IFACE: Could not find network "
3182 value
= wpa_config_get_no_key(ssid
, name
);
3183 if (value
== NULL
) {
3184 wpa_printf(MSG_EXCESSIVE
, "CTRL_IFACE: Failed to get network "
3185 "variable '%s'", name
);
3189 res
= os_strlcpy(buf
, value
, buflen
);
3190 if (res
>= buflen
) {
3201 static int wpa_supplicant_ctrl_iface_dup_network(
3202 struct wpa_supplicant
*wpa_s
, char *cmd
,
3203 struct wpa_supplicant
*dst_wpa_s
)
3205 struct wpa_ssid
*ssid_s
, *ssid_d
;
3206 char *name
, *id
, *value
;
3207 int id_s
, id_d
, ret
;
3209 /* cmd: "<src network id> <dst network id> <variable name>" */
3210 id
= os_strchr(cmd
, ' ');
3215 name
= os_strchr(id
, ' ');
3223 wpa_printf(MSG_DEBUG
,
3224 "CTRL_IFACE: DUP_NETWORK ifname=%s->%s id=%d->%d name='%s'",
3225 wpa_s
->ifname
, dst_wpa_s
->ifname
, id_s
, id_d
, name
);
3227 ssid_s
= wpa_config_get_network(wpa_s
->conf
, id_s
);
3228 if (ssid_s
== NULL
) {
3229 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3230 "network id=%d", id_s
);
3234 ssid_d
= wpa_config_get_network(dst_wpa_s
->conf
, id_d
);
3235 if (ssid_d
== NULL
) {
3236 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3237 "network id=%d", id_d
);
3241 value
= wpa_config_get(ssid_s
, name
);
3242 if (value
== NULL
) {
3243 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to get network "
3244 "variable '%s'", name
);
3248 ret
= wpa_supplicant_ctrl_iface_update_network(dst_wpa_s
, ssid_d
, name
,
3257 static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant
*wpa_s
,
3258 char *buf
, size_t buflen
)
3261 struct wpa_cred
*cred
;
3266 ret
= os_snprintf(pos
, end
- pos
,
3267 "cred id / realm / username / domain / imsi\n");
3268 if (os_snprintf_error(end
- pos
, ret
))
3272 cred
= wpa_s
->conf
->cred
;
3274 ret
= os_snprintf(pos
, end
- pos
, "%d\t%s\t%s\t%s\t%s\n",
3275 cred
->id
, cred
->realm
? cred
->realm
: "",
3276 cred
->username
? cred
->username
: "",
3277 cred
->domain
? cred
->domain
[0] : "",
3278 cred
->imsi
? cred
->imsi
: "");
3279 if (os_snprintf_error(end
- pos
, ret
))
3290 static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant
*wpa_s
,
3291 char *buf
, size_t buflen
)
3293 struct wpa_cred
*cred
;
3296 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ADD_CRED");
3298 cred
= wpa_config_add_cred(wpa_s
->conf
);
3302 wpa_msg(wpa_s
, MSG_INFO
, CRED_ADDED
"%d", cred
->id
);
3304 ret
= os_snprintf(buf
, buflen
, "%d\n", cred
->id
);
3305 if (os_snprintf_error(buflen
, ret
))
3311 static int wpas_ctrl_remove_cred(struct wpa_supplicant
*wpa_s
,
3312 struct wpa_cred
*cred
)
3314 struct wpa_ssid
*ssid
;
3319 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred");
3324 if (wpa_config_remove_cred(wpa_s
->conf
, id
) < 0) {
3325 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred");
3329 wpa_msg(wpa_s
, MSG_INFO
, CRED_REMOVED
"%d", id
);
3331 /* Remove any network entry created based on the removed credential */
3332 ssid
= wpa_s
->conf
->ssid
;
3334 if (ssid
->parent_cred
== cred
) {
3337 wpa_printf(MSG_DEBUG
, "Remove network id %d since it "
3338 "used the removed credential", ssid
->id
);
3339 res
= os_snprintf(str
, sizeof(str
), "%d", ssid
->id
);
3340 if (os_snprintf_error(sizeof(str
), res
))
3341 str
[sizeof(str
) - 1] = '\0';
3343 wpa_supplicant_ctrl_iface_remove_network(wpa_s
, str
);
3352 static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant
*wpa_s
,
3356 struct wpa_cred
*cred
, *prev
;
3358 /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or
3359 * "provisioning_sp=<FQDN> */
3360 if (os_strcmp(cmd
, "all") == 0) {
3361 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED all");
3362 cred
= wpa_s
->conf
->cred
;
3366 wpas_ctrl_remove_cred(wpa_s
, prev
);
3371 if (os_strncmp(cmd
, "sp_fqdn=", 8) == 0) {
3372 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
3374 cred
= wpa_s
->conf
->cred
;
3380 for (i
= 0; i
< prev
->num_domain
; i
++) {
3381 if (os_strcmp(prev
->domain
[i
], cmd
+ 8)
3384 wpas_ctrl_remove_cred(wpa_s
, prev
);
3392 if (os_strncmp(cmd
, "provisioning_sp=", 16) == 0) {
3393 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'",
3395 cred
= wpa_s
->conf
->cred
;
3399 if (prev
->provisioning_sp
&&
3400 os_strcmp(prev
->provisioning_sp
, cmd
+ 16) == 0)
3401 wpas_ctrl_remove_cred(wpa_s
, prev
);
3407 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED id=%d", id
);
3409 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
3410 return wpas_ctrl_remove_cred(wpa_s
, cred
);
3414 static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant
*wpa_s
,
3418 struct wpa_cred
*cred
;
3421 /* cmd: "<cred id> <variable name> <value>" */
3422 name
= os_strchr(cmd
, ' ');
3427 value
= os_strchr(name
, ' ');
3433 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SET_CRED id=%d name='%s'",
3435 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
3436 (u8
*) value
, os_strlen(value
));
3438 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
3440 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred id=%d",
3445 if (wpa_config_set_cred(cred
, name
, value
, 0) < 0) {
3446 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to set cred "
3447 "variable '%s'", name
);
3451 wpa_msg(wpa_s
, MSG_INFO
, CRED_MODIFIED
"%d %s", cred
->id
, name
);
3457 static int wpa_supplicant_ctrl_iface_get_cred(struct wpa_supplicant
*wpa_s
,
3458 char *cmd
, char *buf
,
3463 struct wpa_cred
*cred
;
3466 /* cmd: "<cred id> <variable name>" */
3467 name
= os_strchr(cmd
, ' ');
3473 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_CRED id=%d name='%s'",
3476 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
3478 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred id=%d",
3483 value
= wpa_config_get_cred_no_key(cred
, name
);
3484 if (value
== NULL
) {
3485 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to get cred variable '%s'",
3490 res
= os_strlcpy(buf
, value
, buflen
);
3491 if (res
>= buflen
) {
3502 #ifndef CONFIG_NO_CONFIG_WRITE
3503 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant
*wpa_s
)
3507 if (!wpa_s
->conf
->update_config
) {
3508 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
3509 "to update configuration (update_config=0)");
3513 ret
= wpa_config_write(wpa_s
->confname
, wpa_s
->conf
);
3515 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Failed to "
3516 "update configuration");
3518 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Configuration"
3524 #endif /* CONFIG_NO_CONFIG_WRITE */
3527 struct cipher_info
{
3533 static const struct cipher_info ciphers
[] = {
3534 { WPA_DRIVER_CAPA_ENC_CCMP_256
, "CCMP-256", 0 },
3535 { WPA_DRIVER_CAPA_ENC_GCMP_256
, "GCMP-256", 0 },
3536 { WPA_DRIVER_CAPA_ENC_CCMP
, "CCMP", 0 },
3537 { WPA_DRIVER_CAPA_ENC_GCMP
, "GCMP", 0 },
3538 { WPA_DRIVER_CAPA_ENC_TKIP
, "TKIP", 0 },
3539 { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
, "NONE", 0 },
3540 { WPA_DRIVER_CAPA_ENC_WEP104
, "WEP104", 1 },
3541 { WPA_DRIVER_CAPA_ENC_WEP40
, "WEP40", 1 }
3544 static const struct cipher_info ciphers_group_mgmt
[] = {
3545 { WPA_DRIVER_CAPA_ENC_BIP
, "AES-128-CMAC", 1 },
3546 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_128
, "BIP-GMAC-128", 1 },
3547 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_256
, "BIP-GMAC-256", 1 },
3548 { WPA_DRIVER_CAPA_ENC_BIP_CMAC_256
, "BIP-CMAC-256", 1 },
3552 static int ctrl_iface_get_capability_pairwise(int res
, char *strict
,
3553 struct wpa_driver_capa
*capa
,
3554 char *buf
, size_t buflen
)
3567 len
= os_strlcpy(buf
, "CCMP TKIP NONE", buflen
);
3573 for (i
= 0; i
< ARRAY_SIZE(ciphers
); i
++) {
3574 if (!ciphers
[i
].group_only
&& capa
->enc
& ciphers
[i
].capa
) {
3575 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
3576 pos
== buf
? "" : " ",
3578 if (os_snprintf_error(end
- pos
, ret
))
3588 static int ctrl_iface_get_capability_group(int res
, char *strict
,
3589 struct wpa_driver_capa
*capa
,
3590 char *buf
, size_t buflen
)
3603 len
= os_strlcpy(buf
, "CCMP TKIP WEP104 WEP40", buflen
);
3609 for (i
= 0; i
< ARRAY_SIZE(ciphers
); i
++) {
3610 if (capa
->enc
& ciphers
[i
].capa
) {
3611 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
3612 pos
== buf
? "" : " ",
3614 if (os_snprintf_error(end
- pos
, ret
))
3624 static int ctrl_iface_get_capability_group_mgmt(int res
, char *strict
,
3625 struct wpa_driver_capa
*capa
,
3626 char *buf
, size_t buflen
)
3638 for (i
= 0; i
< ARRAY_SIZE(ciphers_group_mgmt
); i
++) {
3639 if (capa
->enc
& ciphers_group_mgmt
[i
].capa
) {
3640 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
3641 pos
== buf
? "" : " ",
3642 ciphers_group_mgmt
[i
].name
);
3643 if (os_snprintf_error(end
- pos
, ret
))
3653 static int ctrl_iface_get_capability_key_mgmt(int res
, char *strict
,
3654 struct wpa_driver_capa
*capa
,
3655 char *buf
, size_t buflen
)
3667 len
= os_strlcpy(buf
, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
3674 ret
= os_snprintf(pos
, end
- pos
, "NONE IEEE8021X");
3675 if (os_snprintf_error(end
- pos
, ret
))
3679 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
3680 WPA_DRIVER_CAPA_KEY_MGMT_WPA2
)) {
3681 ret
= os_snprintf(pos
, end
- pos
, " WPA-EAP");
3682 if (os_snprintf_error(end
- pos
, ret
))
3687 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
|
3688 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
)) {
3689 ret
= os_snprintf(pos
, end
- pos
, " WPA-PSK");
3690 if (os_snprintf_error(end
- pos
, ret
))
3695 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
) {
3696 ret
= os_snprintf(pos
, end
- pos
, " WPA-NONE");
3697 if (os_snprintf_error(end
- pos
, ret
))
3702 #ifdef CONFIG_SUITEB
3703 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B
) {
3704 ret
= os_snprintf(pos
, end
- pos
, " WPA-EAP-SUITE-B");
3705 if (os_snprintf_error(end
- pos
, ret
))
3709 #endif /* CONFIG_SUITEB */
3710 #ifdef CONFIG_SUITEB192
3711 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192
) {
3712 ret
= os_snprintf(pos
, end
- pos
, " WPA-EAP-SUITE-B-192");
3713 if (os_snprintf_error(end
- pos
, ret
))
3717 #endif /* CONFIG_SUITEB192 */
3723 static int ctrl_iface_get_capability_proto(int res
, char *strict
,
3724 struct wpa_driver_capa
*capa
,
3725 char *buf
, size_t buflen
)
3737 len
= os_strlcpy(buf
, "RSN WPA", buflen
);
3743 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA2
|
3744 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
)) {
3745 ret
= os_snprintf(pos
, end
- pos
, "%sRSN",
3746 pos
== buf
? "" : " ");
3747 if (os_snprintf_error(end
- pos
, ret
))
3752 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
3753 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
)) {
3754 ret
= os_snprintf(pos
, end
- pos
, "%sWPA",
3755 pos
== buf
? "" : " ");
3756 if (os_snprintf_error(end
- pos
, ret
))
3765 static int ctrl_iface_get_capability_auth_alg(struct wpa_supplicant
*wpa_s
,
3766 int res
, char *strict
,
3767 struct wpa_driver_capa
*capa
,
3768 char *buf
, size_t buflen
)
3780 len
= os_strlcpy(buf
, "OPEN SHARED LEAP", buflen
);
3786 if (capa
->auth
& (WPA_DRIVER_AUTH_OPEN
)) {
3787 ret
= os_snprintf(pos
, end
- pos
, "%sOPEN",
3788 pos
== buf
? "" : " ");
3789 if (os_snprintf_error(end
- pos
, ret
))
3794 if (capa
->auth
& (WPA_DRIVER_AUTH_SHARED
)) {
3795 ret
= os_snprintf(pos
, end
- pos
, "%sSHARED",
3796 pos
== buf
? "" : " ");
3797 if (os_snprintf_error(end
- pos
, ret
))
3802 if (capa
->auth
& (WPA_DRIVER_AUTH_LEAP
)) {
3803 ret
= os_snprintf(pos
, end
- pos
, "%sLEAP",
3804 pos
== buf
? "" : " ");
3805 if (os_snprintf_error(end
- pos
, ret
))
3811 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SAE
) {
3812 ret
= os_snprintf(pos
, end
- pos
, "%sSAE",
3813 pos
== buf
? "" : " ");
3814 if (os_snprintf_error(end
- pos
, ret
))
3818 #endif /* CONFIG_SAE */
3824 static int ctrl_iface_get_capability_modes(int res
, char *strict
,
3825 struct wpa_driver_capa
*capa
,
3826 char *buf
, size_t buflen
)
3838 len
= os_strlcpy(buf
, "IBSS AP", buflen
);
3844 if (capa
->flags
& WPA_DRIVER_FLAGS_IBSS
) {
3845 ret
= os_snprintf(pos
, end
- pos
, "%sIBSS",
3846 pos
== buf
? "" : " ");
3847 if (os_snprintf_error(end
- pos
, ret
))
3852 if (capa
->flags
& WPA_DRIVER_FLAGS_AP
) {
3853 ret
= os_snprintf(pos
, end
- pos
, "%sAP",
3854 pos
== buf
? "" : " ");
3855 if (os_snprintf_error(end
- pos
, ret
))
3861 if (capa
->flags
& WPA_DRIVER_FLAGS_MESH
) {
3862 ret
= os_snprintf(pos
, end
- pos
, "%sMESH",
3863 pos
== buf
? "" : " ");
3864 if (os_snprintf_error(end
- pos
, ret
))
3868 #endif /* CONFIG_MESH */
3874 static int ctrl_iface_get_capability_channels(struct wpa_supplicant
*wpa_s
,
3875 char *buf
, size_t buflen
)
3877 struct hostapd_channel_data
*chnl
;
3879 char *pos
, *end
, *hmode
;
3884 for (j
= 0; j
< wpa_s
->hw
.num_modes
; j
++) {
3885 switch (wpa_s
->hw
.modes
[j
].mode
) {
3886 case HOSTAPD_MODE_IEEE80211B
:
3889 case HOSTAPD_MODE_IEEE80211G
:
3892 case HOSTAPD_MODE_IEEE80211A
:
3895 case HOSTAPD_MODE_IEEE80211AD
:
3901 ret
= os_snprintf(pos
, end
- pos
, "Mode[%s] Channels:", hmode
);
3902 if (os_snprintf_error(end
- pos
, ret
))
3905 chnl
= wpa_s
->hw
.modes
[j
].channels
;
3906 for (i
= 0; i
< wpa_s
->hw
.modes
[j
].num_channels
; i
++) {
3907 if (chnl
[i
].flag
& HOSTAPD_CHAN_DISABLED
)
3909 ret
= os_snprintf(pos
, end
- pos
, " %d", chnl
[i
].chan
);
3910 if (os_snprintf_error(end
- pos
, ret
))
3914 ret
= os_snprintf(pos
, end
- pos
, "\n");
3915 if (os_snprintf_error(end
- pos
, ret
))
3924 static int ctrl_iface_get_capability_freq(struct wpa_supplicant
*wpa_s
,
3925 char *buf
, size_t buflen
)
3927 struct hostapd_channel_data
*chnl
;
3929 char *pos
, *end
, *hmode
;
3934 for (j
= 0; j
< wpa_s
->hw
.num_modes
; j
++) {
3935 switch (wpa_s
->hw
.modes
[j
].mode
) {
3936 case HOSTAPD_MODE_IEEE80211B
:
3939 case HOSTAPD_MODE_IEEE80211G
:
3942 case HOSTAPD_MODE_IEEE80211A
:
3945 case HOSTAPD_MODE_IEEE80211AD
:
3951 ret
= os_snprintf(pos
, end
- pos
, "Mode[%s] Channels:\n",
3953 if (os_snprintf_error(end
- pos
, ret
))
3956 chnl
= wpa_s
->hw
.modes
[j
].channels
;
3957 for (i
= 0; i
< wpa_s
->hw
.modes
[j
].num_channels
; i
++) {
3958 if (chnl
[i
].flag
& HOSTAPD_CHAN_DISABLED
)
3960 ret
= os_snprintf(pos
, end
- pos
, " %d = %d MHz%s%s\n",
3961 chnl
[i
].chan
, chnl
[i
].freq
,
3962 chnl
[i
].flag
& HOSTAPD_CHAN_NO_IR
?
3964 chnl
[i
].flag
& HOSTAPD_CHAN_RADAR
?
3967 if (os_snprintf_error(end
- pos
, ret
))
3971 ret
= os_snprintf(pos
, end
- pos
, "\n");
3972 if (os_snprintf_error(end
- pos
, ret
))
3981 static int wpa_supplicant_ctrl_iface_get_capability(
3982 struct wpa_supplicant
*wpa_s
, const char *_field
, char *buf
,
3985 struct wpa_driver_capa capa
;
3991 /* Determine whether or not strict checking was requested */
3992 len
= os_strlcpy(field
, _field
, sizeof(field
));
3993 if (len
>= sizeof(field
))
3995 strict
= os_strchr(field
, ' ');
3996 if (strict
!= NULL
) {
3998 if (os_strcmp(strict
, "strict") != 0)
4002 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
4003 field
, strict
? strict
: "");
4005 if (os_strcmp(field
, "eap") == 0) {
4006 return eap_get_names(buf
, buflen
);
4009 res
= wpa_drv_get_capa(wpa_s
, &capa
);
4011 if (os_strcmp(field
, "pairwise") == 0)
4012 return ctrl_iface_get_capability_pairwise(res
, strict
, &capa
,
4015 if (os_strcmp(field
, "group") == 0)
4016 return ctrl_iface_get_capability_group(res
, strict
, &capa
,
4019 if (os_strcmp(field
, "group_mgmt") == 0)
4020 return ctrl_iface_get_capability_group_mgmt(res
, strict
, &capa
,
4023 if (os_strcmp(field
, "key_mgmt") == 0)
4024 return ctrl_iface_get_capability_key_mgmt(res
, strict
, &capa
,
4027 if (os_strcmp(field
, "proto") == 0)
4028 return ctrl_iface_get_capability_proto(res
, strict
, &capa
,
4031 if (os_strcmp(field
, "auth_alg") == 0)
4032 return ctrl_iface_get_capability_auth_alg(wpa_s
, res
, strict
,
4033 &capa
, buf
, buflen
);
4035 if (os_strcmp(field
, "modes") == 0)
4036 return ctrl_iface_get_capability_modes(res
, strict
, &capa
,
4039 if (os_strcmp(field
, "channels") == 0)
4040 return ctrl_iface_get_capability_channels(wpa_s
, buf
, buflen
);
4042 if (os_strcmp(field
, "freq") == 0)
4043 return ctrl_iface_get_capability_freq(wpa_s
, buf
, buflen
);
4046 if (os_strcmp(field
, "tdls") == 0)
4047 return ctrl_iface_get_capability_tdls(wpa_s
, buf
, buflen
);
4048 #endif /* CONFIG_TDLS */
4051 if (os_strcmp(field
, "erp") == 0) {
4052 res
= os_snprintf(buf
, buflen
, "ERP");
4053 if (os_snprintf_error(buflen
, res
))
4057 #endif /* CONFIG_EPR */
4060 if (os_strcmp(field
, "fips") == 0) {
4061 res
= os_snprintf(buf
, buflen
, "FIPS");
4062 if (os_snprintf_error(buflen
, res
))
4066 #endif /* CONFIG_FIPS */
4069 if (os_strcmp(field
, "acs") == 0) {
4070 res
= os_snprintf(buf
, buflen
, "ACS");
4071 if (os_snprintf_error(buflen
, res
))
4075 #endif /* CONFIG_ACS */
4078 if (os_strcmp(field
, "fils") == 0 &&
4079 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SUPPORT_FILS
)) {
4080 res
= os_snprintf(buf
, buflen
, "FILS");
4081 if (os_snprintf_error(buflen
, res
))
4085 #endif /* CONFIG_FILS */
4087 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
4094 #ifdef CONFIG_INTERWORKING
4095 static char * anqp_add_hex(char *pos
, char *end
, const char *title
,
4096 struct wpabuf
*data
)
4106 ret
= os_snprintf(pos
, end
- pos
, "%s=", title
);
4107 if (os_snprintf_error(end
- pos
, ret
))
4111 d
= wpabuf_head_u8(data
);
4112 for (i
= 0; i
< wpabuf_len(data
); i
++) {
4113 ret
= os_snprintf(pos
, end
- pos
, "%02x", *d
++);
4114 if (os_snprintf_error(end
- pos
, ret
))
4119 ret
= os_snprintf(pos
, end
- pos
, "\n");
4120 if (os_snprintf_error(end
- pos
, ret
))
4126 #endif /* CONFIG_INTERWORKING */
4130 static int print_fils_indication(struct wpa_bss
*bss
, char *pos
, char *end
)
4133 const u8
*ie
, *ie_end
;
4137 ie
= wpa_bss_get_ie(bss
, WLAN_EID_FILS_INDICATION
);
4140 ie_end
= ie
+ 2 + ie
[1];
4142 if (ie_end
- ie
< 2)
4145 info
= WPA_GET_LE16(ie
);
4147 ret
= os_snprintf(pos
, end
- pos
, "fils_info=%04x\n", info
);
4148 if (os_snprintf_error(end
- pos
, ret
))
4152 if (info
& BIT(7)) {
4153 /* Cache Identifier Included */
4154 if (ie_end
- ie
< 2)
4156 ret
= os_snprintf(pos
, end
- pos
, "fils_cache_id=%02x%02x\n",
4158 if (os_snprintf_error(end
- pos
, ret
))
4164 if (info
& BIT(8)) {
4165 /* HESSID Included */
4166 if (ie_end
- ie
< ETH_ALEN
)
4168 ret
= os_snprintf(pos
, end
- pos
, "fils_hessid=" MACSTR
"\n",
4170 if (os_snprintf_error(end
- pos
, ret
))
4176 realms
= (info
& (BIT(3) | BIT(4) | BIT(5))) >> 3;
4178 if (ie_end
- ie
< realms
* 2)
4180 ret
= os_snprintf(pos
, end
- pos
, "fils_realms=");
4181 if (os_snprintf_error(end
- pos
, ret
))
4185 ret
= wpa_snprintf_hex(pos
, end
- pos
, ie
, realms
* 2);
4190 ret
= os_snprintf(pos
, end
- pos
, "\n");
4191 if (os_snprintf_error(end
- pos
, ret
))
4198 #endif /* CONFIG_FILS */
4201 static int print_bss_info(struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
,
4202 unsigned long mask
, char *buf
, size_t buflen
)
4207 const u8
*ie
, *ie2
, *osen_ie
, *mesh
;
4212 if (mask
& WPA_BSS_MASK_ID
) {
4213 ret
= os_snprintf(pos
, end
- pos
, "id=%u\n", bss
->id
);
4214 if (os_snprintf_error(end
- pos
, ret
))
4219 if (mask
& WPA_BSS_MASK_BSSID
) {
4220 ret
= os_snprintf(pos
, end
- pos
, "bssid=" MACSTR
"\n",
4221 MAC2STR(bss
->bssid
));
4222 if (os_snprintf_error(end
- pos
, ret
))
4227 if (mask
& WPA_BSS_MASK_FREQ
) {
4228 ret
= os_snprintf(pos
, end
- pos
, "freq=%d\n", bss
->freq
);
4229 if (os_snprintf_error(end
- pos
, ret
))
4234 if (mask
& WPA_BSS_MASK_BEACON_INT
) {
4235 ret
= os_snprintf(pos
, end
- pos
, "beacon_int=%d\n",
4237 if (os_snprintf_error(end
- pos
, ret
))
4242 if (mask
& WPA_BSS_MASK_CAPABILITIES
) {
4243 ret
= os_snprintf(pos
, end
- pos
, "capabilities=0x%04x\n",
4245 if (os_snprintf_error(end
- pos
, ret
))
4250 if (mask
& WPA_BSS_MASK_QUAL
) {
4251 ret
= os_snprintf(pos
, end
- pos
, "qual=%d\n", bss
->qual
);
4252 if (os_snprintf_error(end
- pos
, ret
))
4257 if (mask
& WPA_BSS_MASK_NOISE
) {
4258 ret
= os_snprintf(pos
, end
- pos
, "noise=%d\n", bss
->noise
);
4259 if (os_snprintf_error(end
- pos
, ret
))
4264 if (mask
& WPA_BSS_MASK_LEVEL
) {
4265 ret
= os_snprintf(pos
, end
- pos
, "level=%d\n", bss
->level
);
4266 if (os_snprintf_error(end
- pos
, ret
))
4271 if (mask
& WPA_BSS_MASK_TSF
) {
4272 ret
= os_snprintf(pos
, end
- pos
, "tsf=%016llu\n",
4273 (unsigned long long) bss
->tsf
);
4274 if (os_snprintf_error(end
- pos
, ret
))
4279 if (mask
& WPA_BSS_MASK_AGE
) {
4280 struct os_reltime now
;
4282 os_get_reltime(&now
);
4283 ret
= os_snprintf(pos
, end
- pos
, "age=%d\n",
4284 (int) (now
.sec
- bss
->last_update
.sec
));
4285 if (os_snprintf_error(end
- pos
, ret
))
4290 if (mask
& WPA_BSS_MASK_IE
) {
4291 ret
= os_snprintf(pos
, end
- pos
, "ie=");
4292 if (os_snprintf_error(end
- pos
, ret
))
4296 ie
= (const u8
*) (bss
+ 1);
4297 for (i
= 0; i
< bss
->ie_len
; i
++) {
4298 ret
= os_snprintf(pos
, end
- pos
, "%02x", *ie
++);
4299 if (os_snprintf_error(end
- pos
, ret
))
4304 ret
= os_snprintf(pos
, end
- pos
, "\n");
4305 if (os_snprintf_error(end
- pos
, ret
))
4310 if (mask
& WPA_BSS_MASK_FLAGS
) {
4311 ret
= os_snprintf(pos
, end
- pos
, "flags=");
4312 if (os_snprintf_error(end
- pos
, ret
))
4316 mesh
= wpa_bss_get_ie(bss
, WLAN_EID_MESH_ID
);
4318 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
4320 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA", ie
,
4322 ie2
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
4324 pos
= wpa_supplicant_ie_txt(pos
, end
,
4325 mesh
? "RSN" : "WPA2", ie2
,
4327 osen_ie
= wpa_bss_get_vendor_ie(bss
, OSEN_IE_VENDOR_TYPE
);
4329 pos
= wpa_supplicant_ie_txt(pos
, end
, "OSEN",
4330 osen_ie
, 2 + osen_ie
[1]);
4331 pos
= wpa_supplicant_wps_ie_txt(wpa_s
, pos
, end
, bss
);
4332 if (!ie
&& !ie2
&& !osen_ie
&&
4333 (bss
->caps
& IEEE80211_CAP_PRIVACY
)) {
4334 ret
= os_snprintf(pos
, end
- pos
, "[WEP]");
4335 if (os_snprintf_error(end
- pos
, ret
))
4341 ret
= os_snprintf(pos
, end
- pos
, "[MESH]");
4342 if (os_snprintf_error(end
- pos
, ret
))
4347 if (bss_is_dmg(bss
)) {
4349 ret
= os_snprintf(pos
, end
- pos
, "[DMG]");
4350 if (os_snprintf_error(end
- pos
, ret
))
4353 switch (bss
->caps
& IEEE80211_CAP_DMG_MASK
) {
4354 case IEEE80211_CAP_DMG_IBSS
:
4357 case IEEE80211_CAP_DMG_AP
:
4360 case IEEE80211_CAP_DMG_PBSS
:
4367 ret
= os_snprintf(pos
, end
- pos
, "%s", s
);
4368 if (os_snprintf_error(end
- pos
, ret
))
4372 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
4373 ret
= os_snprintf(pos
, end
- pos
, "[IBSS]");
4374 if (os_snprintf_error(end
- pos
, ret
))
4378 if (bss
->caps
& IEEE80211_CAP_ESS
) {
4379 ret
= os_snprintf(pos
, end
- pos
, "[ESS]");
4380 if (os_snprintf_error(end
- pos
, ret
))
4385 if (wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
) ||
4386 wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
)) {
4387 ret
= os_snprintf(pos
, end
- pos
, "[P2P]");
4388 if (os_snprintf_error(end
- pos
, ret
))
4393 if (wpa_bss_get_vendor_ie(bss
, HS20_IE_VENDOR_TYPE
)) {
4394 ret
= os_snprintf(pos
, end
- pos
, "[HS20]");
4395 if (os_snprintf_error(end
- pos
, ret
))
4399 #endif /* CONFIG_HS20 */
4401 if (wpa_bss_get_ie(bss
, WLAN_EID_FILS_INDICATION
)) {
4402 ret
= os_snprintf(pos
, end
- pos
, "[FILS]");
4403 if (os_snprintf_error(end
- pos
, ret
))
4407 #endif /* CONFIG_FILS */
4409 ret
= os_snprintf(pos
, end
- pos
, "\n");
4410 if (os_snprintf_error(end
- pos
, ret
))
4415 if (mask
& WPA_BSS_MASK_SSID
) {
4416 ret
= os_snprintf(pos
, end
- pos
, "ssid=%s\n",
4417 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
4418 if (os_snprintf_error(end
- pos
, ret
))
4424 if (mask
& WPA_BSS_MASK_WPS_SCAN
) {
4425 ie
= (const u8
*) (bss
+ 1);
4426 ret
= wpas_wps_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
4427 if (ret
>= end
- pos
)
4432 #endif /* CONFIG_WPS */
4435 if (mask
& WPA_BSS_MASK_P2P_SCAN
) {
4436 ie
= (const u8
*) (bss
+ 1);
4437 ret
= wpas_p2p_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
4438 if (ret
>= end
- pos
)
4443 #endif /* CONFIG_P2P */
4445 #ifdef CONFIG_WIFI_DISPLAY
4446 if (mask
& WPA_BSS_MASK_WIFI_DISPLAY
) {
4448 ie
= (const u8
*) (bss
+ 1);
4449 wfd
= ieee802_11_vendor_ie_concat(ie
, bss
->ie_len
,
4450 WFD_IE_VENDOR_TYPE
);
4452 ret
= os_snprintf(pos
, end
- pos
, "wfd_subelems=");
4453 if (os_snprintf_error(end
- pos
, ret
)) {
4459 pos
+= wpa_snprintf_hex(pos
, end
- pos
,
4464 ret
= os_snprintf(pos
, end
- pos
, "\n");
4465 if (os_snprintf_error(end
- pos
, ret
))
4470 #endif /* CONFIG_WIFI_DISPLAY */
4472 #ifdef CONFIG_INTERWORKING
4473 if ((mask
& WPA_BSS_MASK_INTERNETW
) && bss
->anqp
) {
4474 struct wpa_bss_anqp
*anqp
= bss
->anqp
;
4475 struct wpa_bss_anqp_elem
*elem
;
4477 pos
= anqp_add_hex(pos
, end
, "anqp_capability_list",
4478 anqp
->capability_list
);
4479 pos
= anqp_add_hex(pos
, end
, "anqp_venue_name",
4481 pos
= anqp_add_hex(pos
, end
, "anqp_network_auth_type",
4482 anqp
->network_auth_type
);
4483 pos
= anqp_add_hex(pos
, end
, "anqp_roaming_consortium",
4484 anqp
->roaming_consortium
);
4485 pos
= anqp_add_hex(pos
, end
, "anqp_ip_addr_type_availability",
4486 anqp
->ip_addr_type_availability
);
4487 pos
= anqp_add_hex(pos
, end
, "anqp_nai_realm",
4489 pos
= anqp_add_hex(pos
, end
, "anqp_3gpp", anqp
->anqp_3gpp
);
4490 pos
= anqp_add_hex(pos
, end
, "anqp_domain_name",
4492 pos
= anqp_add_hex(pos
, end
, "anqp_fils_realm_info",
4493 anqp
->fils_realm_info
);
4495 pos
= anqp_add_hex(pos
, end
, "hs20_capability_list",
4496 anqp
->hs20_capability_list
);
4497 pos
= anqp_add_hex(pos
, end
, "hs20_operator_friendly_name",
4498 anqp
->hs20_operator_friendly_name
);
4499 pos
= anqp_add_hex(pos
, end
, "hs20_wan_metrics",
4500 anqp
->hs20_wan_metrics
);
4501 pos
= anqp_add_hex(pos
, end
, "hs20_connection_capability",
4502 anqp
->hs20_connection_capability
);
4503 pos
= anqp_add_hex(pos
, end
, "hs20_operating_class",
4504 anqp
->hs20_operating_class
);
4505 pos
= anqp_add_hex(pos
, end
, "hs20_osu_providers_list",
4506 anqp
->hs20_osu_providers_list
);
4507 #endif /* CONFIG_HS20 */
4509 dl_list_for_each(elem
, &anqp
->anqp_elems
,
4510 struct wpa_bss_anqp_elem
, list
) {
4513 os_snprintf(title
, sizeof(title
), "anqp[%u]",
4515 pos
= anqp_add_hex(pos
, end
, title
, elem
->payload
);
4518 #endif /* CONFIG_INTERWORKING */
4521 if (mask
& WPA_BSS_MASK_MESH_SCAN
) {
4522 ie
= (const u8
*) (bss
+ 1);
4523 ret
= wpas_mesh_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
4524 if (ret
>= end
- pos
)
4529 #endif /* CONFIG_MESH */
4531 if (mask
& WPA_BSS_MASK_SNR
) {
4532 ret
= os_snprintf(pos
, end
- pos
, "snr=%d\n", bss
->snr
);
4533 if (os_snprintf_error(end
- pos
, ret
))
4538 if (mask
& WPA_BSS_MASK_EST_THROUGHPUT
) {
4539 ret
= os_snprintf(pos
, end
- pos
, "est_throughput=%d\n",
4540 bss
->est_throughput
);
4541 if (os_snprintf_error(end
- pos
, ret
))
4547 if (mask
& WPA_BSS_MASK_FST
) {
4548 ret
= fst_ctrl_iface_mb_info(bss
->bssid
, pos
, end
- pos
);
4549 if (ret
< 0 || ret
>= end
- pos
)
4553 #endif /* CONFIG_FST */
4555 if (mask
& WPA_BSS_MASK_UPDATE_IDX
) {
4556 ret
= os_snprintf(pos
, end
- pos
, "update_idx=%u\n",
4557 bss
->last_update_idx
);
4558 if (os_snprintf_error(end
- pos
, ret
))
4563 if ((mask
& WPA_BSS_MASK_BEACON_IE
) && bss
->beacon_ie_len
) {
4564 ret
= os_snprintf(pos
, end
- pos
, "beacon_ie=");
4565 if (os_snprintf_error(end
- pos
, ret
))
4569 ie
= (const u8
*) (bss
+ 1);
4571 for (i
= 0; i
< bss
->beacon_ie_len
; i
++) {
4572 ret
= os_snprintf(pos
, end
- pos
, "%02x", *ie
++);
4573 if (os_snprintf_error(end
- pos
, ret
))
4578 ret
= os_snprintf(pos
, end
- pos
, "\n");
4579 if (os_snprintf_error(end
- pos
, ret
))
4585 if (mask
& WPA_BSS_MASK_FILS_INDICATION
) {
4586 ret
= print_fils_indication(bss
, pos
, end
);
4591 #endif /* CONFIG_FILS */
4593 if (mask
& WPA_BSS_MASK_DELIM
) {
4594 ret
= os_snprintf(pos
, end
- pos
, "====\n");
4595 if (os_snprintf_error(end
- pos
, ret
))
4604 static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant
*wpa_s
,
4605 const char *cmd
, char *buf
,
4610 struct wpa_bss
*bss
;
4611 struct wpa_bss
*bsslast
= NULL
;
4612 struct dl_list
*next
;
4615 char *ctmp
, *end
= buf
+ buflen
;
4616 unsigned long mask
= WPA_BSS_MASK_ALL
;
4618 if (os_strncmp(cmd
, "RANGE=", 6) == 0) {
4619 if (os_strncmp(cmd
+ 6, "ALL", 3) == 0) {
4620 bss
= dl_list_first(&wpa_s
->bss_id
, struct wpa_bss
,
4622 bsslast
= dl_list_last(&wpa_s
->bss_id
, struct wpa_bss
,
4624 } else { /* N1-N2 */
4625 unsigned int id1
, id2
;
4627 if ((ctmp
= os_strchr(cmd
+ 6, '-')) == NULL
) {
4628 wpa_printf(MSG_INFO
, "Wrong BSS range "
4633 if (*(cmd
+ 6) == '-')
4636 id1
= atoi(cmd
+ 6);
4638 if (*ctmp
>= '0' && *ctmp
<= '9')
4641 id2
= (unsigned int) -1;
4642 bss
= wpa_bss_get_id_range(wpa_s
, id1
, id2
);
4643 if (id2
== (unsigned int) -1)
4644 bsslast
= dl_list_last(&wpa_s
->bss_id
,
4648 bsslast
= wpa_bss_get_id(wpa_s
, id2
);
4649 if (bsslast
== NULL
&& bss
&& id2
> id1
) {
4650 struct wpa_bss
*tmp
= bss
;
4652 next
= tmp
->list_id
.next
;
4653 if (next
== &wpa_s
->bss_id
)
4655 tmp
= dl_list_entry(
4656 next
, struct wpa_bss
,
4665 } else if (os_strncmp(cmd
, "FIRST", 5) == 0)
4666 bss
= dl_list_first(&wpa_s
->bss_id
, struct wpa_bss
, list_id
);
4667 else if (os_strncmp(cmd
, "LAST", 4) == 0)
4668 bss
= dl_list_last(&wpa_s
->bss_id
, struct wpa_bss
, list_id
);
4669 else if (os_strncmp(cmd
, "ID-", 3) == 0) {
4671 bss
= wpa_bss_get_id(wpa_s
, i
);
4672 } else if (os_strncmp(cmd
, "NEXT-", 5) == 0) {
4674 bss
= wpa_bss_get_id(wpa_s
, i
);
4676 next
= bss
->list_id
.next
;
4677 if (next
== &wpa_s
->bss_id
)
4680 bss
= dl_list_entry(next
, struct wpa_bss
,
4683 } else if (os_strncmp(cmd
, "CURRENT", 7) == 0) {
4684 bss
= wpa_s
->current_bss
;
4686 } else if (os_strncmp(cmd
, "p2p_dev_addr=", 13) == 0) {
4687 if (hwaddr_aton(cmd
+ 13, bssid
) == 0)
4688 bss
= wpa_bss_get_p2p_dev_addr(wpa_s
, bssid
);
4691 #endif /* CONFIG_P2P */
4692 } else if (hwaddr_aton(cmd
, bssid
) == 0)
4693 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
4695 struct wpa_bss
*tmp
;
4698 dl_list_for_each(tmp
, &wpa_s
->bss_id
, struct wpa_bss
, list_id
)
4707 if ((ctmp
= os_strstr(cmd
, "MASK=")) != NULL
) {
4708 mask
= strtoul(ctmp
+ 5, NULL
, 0x10);
4710 mask
= WPA_BSS_MASK_ALL
;
4716 if (bsslast
== NULL
)
4719 len
= print_bss_info(wpa_s
, bss
, mask
, buf
, buflen
);
4723 if (bss
== bsslast
) {
4724 if ((mask
& WPA_BSS_MASK_DELIM
) && len
&&
4725 (bss
== dl_list_last(&wpa_s
->bss_id
,
4726 struct wpa_bss
, list_id
))) {
4729 res
= os_snprintf(buf
- 5, end
- buf
+ 5,
4731 if (os_snprintf_error(end
- buf
+ 5, res
)) {
4732 wpa_printf(MSG_DEBUG
,
4733 "Could not add end delim");
4738 next
= bss
->list_id
.next
;
4739 if (next
== &wpa_s
->bss_id
)
4741 bss
= dl_list_entry(next
, struct wpa_bss
, list_id
);
4742 } while (bss
&& len
);
4748 static int wpa_supplicant_ctrl_iface_ap_scan(
4749 struct wpa_supplicant
*wpa_s
, char *cmd
)
4751 int ap_scan
= atoi(cmd
);
4752 return wpa_supplicant_set_ap_scan(wpa_s
, ap_scan
);
4756 static int wpa_supplicant_ctrl_iface_scan_interval(
4757 struct wpa_supplicant
*wpa_s
, char *cmd
)
4759 int scan_int
= atoi(cmd
);
4760 return wpa_supplicant_set_scan_interval(wpa_s
, scan_int
);
4764 static int wpa_supplicant_ctrl_iface_bss_expire_age(
4765 struct wpa_supplicant
*wpa_s
, char *cmd
)
4767 int expire_age
= atoi(cmd
);
4768 return wpa_supplicant_set_bss_expiration_age(wpa_s
, expire_age
);
4772 static int wpa_supplicant_ctrl_iface_bss_expire_count(
4773 struct wpa_supplicant
*wpa_s
, char *cmd
)
4775 int expire_count
= atoi(cmd
);
4776 return wpa_supplicant_set_bss_expiration_count(wpa_s
, expire_count
);
4780 static void wpa_supplicant_ctrl_iface_bss_flush(
4781 struct wpa_supplicant
*wpa_s
, char *cmd
)
4783 int flush_age
= atoi(cmd
);
4786 wpa_bss_flush(wpa_s
);
4788 wpa_bss_flush_by_age(wpa_s
, flush_age
);
4792 #ifdef CONFIG_TESTING_OPTIONS
4793 static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant
*wpa_s
)
4795 wpa_printf(MSG_DEBUG
, "Dropping SA without deauthentication");
4796 /* MLME-DELETEKEYS.request */
4797 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 0, 0, NULL
, 0, NULL
, 0);
4798 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 1, 0, NULL
, 0, NULL
, 0);
4799 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 2, 0, NULL
, 0, NULL
, 0);
4800 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 3, 0, NULL
, 0, NULL
, 0);
4801 #ifdef CONFIG_IEEE80211W
4802 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 4, 0, NULL
, 0, NULL
, 0);
4803 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 5, 0, NULL
, 0, NULL
, 0);
4804 #endif /* CONFIG_IEEE80211W */
4806 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, wpa_s
->bssid
, 0, 0, NULL
, 0, NULL
,
4808 /* MLME-SETPROTECTION.request(None) */
4809 wpa_drv_mlme_setprotection(wpa_s
, wpa_s
->bssid
,
4810 MLME_SETPROTECTION_PROTECT_TYPE_NONE
,
4811 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE
);
4812 wpa_sm_drop_sa(wpa_s
->wpa
);
4814 #endif /* CONFIG_TESTING_OPTIONS */
4817 static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant
*wpa_s
,
4820 #ifdef CONFIG_NO_SCAN_PROCESSING
4822 #else /* CONFIG_NO_SCAN_PROCESSING */
4824 struct wpa_bss
*bss
;
4825 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
4827 if (hwaddr_aton(addr
, bssid
)) {
4828 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: invalid "
4829 "address '%s'", addr
);
4833 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM " MACSTR
, MAC2STR(bssid
));
4836 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: No network "
4837 "configuration known for the target AP");
4841 bss
= wpa_bss_get(wpa_s
, bssid
, ssid
->ssid
, ssid
->ssid_len
);
4843 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: Target AP not found "
4849 * TODO: Find best network configuration block from configuration to
4850 * allow roaming to other networks
4853 wpa_s
->reassociate
= 1;
4854 wpa_supplicant_connect(wpa_s
, bss
, ssid
);
4857 #endif /* CONFIG_NO_SCAN_PROCESSING */
4862 static int p2p_ctrl_find(struct wpa_supplicant
*wpa_s
, char *cmd
)
4864 unsigned int timeout
= atoi(cmd
);
4865 enum p2p_discovery_type type
= P2P_FIND_START_WITH_FULL
;
4866 u8 dev_id
[ETH_ALEN
], *_dev_id
= NULL
;
4867 u8 dev_type
[WPS_DEV_TYPE_LEN
], *_dev_type
= NULL
;
4869 unsigned int search_delay
;
4870 const char *_seek
[P2P_MAX_QUERY_HASH
+ 1], **seek
= NULL
;
4874 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
4875 wpa_dbg(wpa_s
, MSG_INFO
,
4876 "Reject P2P_FIND since interface is disabled");
4879 if (os_strstr(cmd
, "type=social"))
4880 type
= P2P_FIND_ONLY_SOCIAL
;
4881 else if (os_strstr(cmd
, "type=progressive"))
4882 type
= P2P_FIND_PROGRESSIVE
;
4884 pos
= os_strstr(cmd
, "dev_id=");
4887 if (hwaddr_aton(pos
, dev_id
))
4892 pos
= os_strstr(cmd
, "dev_type=");
4895 if (wps_dev_type_str2bin(pos
, dev_type
) < 0)
4897 _dev_type
= dev_type
;
4900 pos
= os_strstr(cmd
, "delay=");
4903 search_delay
= atoi(pos
);
4905 search_delay
= wpas_p2p_search_delay(wpa_s
);
4907 pos
= os_strstr(cmd
, "freq=");
4915 /* Must be searched for last, because it adds nul termination */
4916 pos
= os_strstr(cmd
, " seek=");
4919 while (pos
&& seek_count
< P2P_MAX_QUERY_HASH
+ 1) {
4922 _seek
[seek_count
++] = pos
;
4924 term
= os_strchr(pos
, ' ');
4928 pos
= os_strstr(term
+ 1, "seek=");
4932 if (seek_count
> P2P_MAX_QUERY_HASH
) {
4937 return wpas_p2p_find(wpa_s
, timeout
, type
, _dev_type
!= NULL
, _dev_type
,
4938 _dev_id
, search_delay
, seek_count
, seek
, freq
);
4942 static int p2ps_ctrl_parse_cpt_priority(const char *pos
, u8
*cpt
)
4944 const char *last
= NULL
;
4949 /* Expected predefined CPT names delimited by ':' */
4950 for (i
= 0; (token
= cstr_token(pos
, ": \t", &last
)); i
++) {
4951 if (i
>= P2PS_FEATURE_CAPAB_CPT_MAX
) {
4952 wpa_printf(MSG_ERROR
,
4953 "P2PS: CPT name list is too long, expected up to %d names",
4954 P2PS_FEATURE_CAPAB_CPT_MAX
);
4959 token_len
= last
- token
;
4961 if (token_len
== 3 &&
4962 os_memcmp(token
, "UDP", token_len
) == 0) {
4963 cpt
[i
] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT
;
4964 } else if (token_len
== 3 &&
4965 os_memcmp(token
, "MAC", token_len
) == 0) {
4966 cpt
[i
] = P2PS_FEATURE_CAPAB_MAC_TRANSPORT
;
4968 wpa_printf(MSG_ERROR
,
4969 "P2PS: Unsupported CPT name '%s'", token
);
4974 if (isblank((unsigned char) *last
)) {
4984 static struct p2ps_provision
* p2p_parse_asp_provision_cmd(const char *cmd
)
4986 struct p2ps_provision
*p2ps_prov
;
4988 size_t info_len
= 0;
4990 u8 role
= P2PS_SETUP_NONE
;
4991 long long unsigned val
;
4994 pos
= os_strstr(cmd
, "info=");
4997 info_len
= os_strlen(pos
);
5000 info
= os_malloc(info_len
+ 1);
5002 info_len
= utf8_unescape(pos
, info_len
,
5003 info
, info_len
+ 1);
5009 p2ps_prov
= os_zalloc(sizeof(struct p2ps_provision
) + info_len
+ 1);
5010 if (p2ps_prov
== NULL
) {
5016 os_memcpy(p2ps_prov
->info
, info
, info_len
);
5017 p2ps_prov
->info
[info_len
] = '\0';
5021 pos
= os_strstr(cmd
, "status=");
5023 p2ps_prov
->status
= atoi(pos
+ 7);
5025 p2ps_prov
->status
= -1;
5027 pos
= os_strstr(cmd
, "adv_id=");
5028 if (!pos
|| sscanf(pos
+ 7, "%llx", &val
) != 1 || val
> 0xffffffffULL
)
5030 p2ps_prov
->adv_id
= val
;
5032 pos
= os_strstr(cmd
, "method=");
5034 p2ps_prov
->method
= strtol(pos
+ 7, NULL
, 16);
5036 p2ps_prov
->method
= 0;
5038 pos
= os_strstr(cmd
, "session=");
5039 if (!pos
|| sscanf(pos
+ 8, "%llx", &val
) != 1 || val
> 0xffffffffULL
)
5041 p2ps_prov
->session_id
= val
;
5043 pos
= os_strstr(cmd
, "adv_mac=");
5044 if (!pos
|| hwaddr_aton(pos
+ 8, p2ps_prov
->adv_mac
))
5047 pos
= os_strstr(cmd
, "session_mac=");
5048 if (!pos
|| hwaddr_aton(pos
+ 12, p2ps_prov
->session_mac
))
5051 pos
= os_strstr(cmd
, "cpt=");
5053 if (p2ps_ctrl_parse_cpt_priority(pos
+ 4,
5054 p2ps_prov
->cpt_priority
))
5057 p2ps_prov
->cpt_priority
[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT
;
5060 for (i
= 0; p2ps_prov
->cpt_priority
[i
]; i
++)
5061 p2ps_prov
->cpt_mask
|= p2ps_prov
->cpt_priority
[i
];
5063 /* force conncap with tstCap (no sanity checks) */
5064 pos
= os_strstr(cmd
, "tstCap=");
5066 role
= strtol(pos
+ 7, NULL
, 16);
5068 pos
= os_strstr(cmd
, "role=");
5070 role
= strtol(pos
+ 5, NULL
, 16);
5071 if (role
!= P2PS_SETUP_CLIENT
&&
5072 role
!= P2PS_SETUP_GROUP_OWNER
)
5073 role
= P2PS_SETUP_NONE
;
5076 p2ps_prov
->role
= role
;
5086 static int p2p_ctrl_asp_provision_resp(struct wpa_supplicant
*wpa_s
, char *cmd
)
5089 struct p2ps_provision
*p2ps_prov
;
5092 /* <addr> id=<adv_id> [role=<conncap>] [info=<infodata>] */
5094 wpa_printf(MSG_DEBUG
, "%s: %s", __func__
, cmd
);
5096 if (hwaddr_aton(cmd
, addr
))
5103 p2ps_prov
= p2p_parse_asp_provision_cmd(pos
);
5107 if (p2ps_prov
->status
< 0) {
5112 return wpas_p2p_prov_disc(wpa_s
, addr
, NULL
, WPAS_P2P_PD_FOR_ASP
,
5117 static int p2p_ctrl_asp_provision(struct wpa_supplicant
*wpa_s
, char *cmd
)
5120 struct p2ps_provision
*p2ps_prov
;
5123 /* <addr> id=<adv_id> adv_mac=<adv_mac> conncap=<conncap>
5124 * session=<ses_id> mac=<ses_mac> [info=<infodata>]
5127 wpa_printf(MSG_DEBUG
, "%s: %s", __func__
, cmd
);
5128 if (hwaddr_aton(cmd
, addr
))
5135 p2ps_prov
= p2p_parse_asp_provision_cmd(pos
);
5139 p2ps_prov
->pd_seeker
= 1;
5141 return wpas_p2p_prov_disc(wpa_s
, addr
, NULL
, WPAS_P2P_PD_FOR_ASP
,
5146 static int parse_freq(int chwidth
, int freq2
)
5151 return VHT_CHANWIDTH_80P80MHZ
;
5157 return VHT_CHANWIDTH_USE_HT
;
5159 return VHT_CHANWIDTH_80MHZ
;
5161 return VHT_CHANWIDTH_160MHZ
;
5163 wpa_printf(MSG_DEBUG
, "Unknown max oper bandwidth: %d",
5170 static int p2p_ctrl_connect(struct wpa_supplicant
*wpa_s
, char *cmd
,
5171 char *buf
, size_t buflen
)
5176 enum p2p_wps_method wps_method
;
5179 int persistent_group
, persistent_id
= -1;
5186 int ht40
, vht
, max_oper_chwidth
, chwidth
= 0, freq2
= 0;
5187 u8 _group_ssid
[SSID_MAX_LEN
], *group_ssid
= NULL
;
5188 size_t group_ssid_len
= 0;
5190 if (!wpa_s
->global
->p2p_init_wpa_s
)
5192 if (wpa_s
->global
->p2p_init_wpa_s
!= wpa_s
) {
5193 wpa_dbg(wpa_s
, MSG_DEBUG
, "Direct P2P_CONNECT command to %s",
5194 wpa_s
->global
->p2p_init_wpa_s
->ifname
);
5195 wpa_s
= wpa_s
->global
->p2p_init_wpa_s
;
5198 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad|p2ps]
5199 * [persistent|persistent=<network id>]
5200 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
5201 * [ht40] [vht] [auto] [ssid=<hexdump>] */
5203 if (hwaddr_aton(cmd
, addr
))
5211 persistent_group
= os_strstr(pos
, " persistent") != NULL
;
5212 pos2
= os_strstr(pos
, " persistent=");
5214 struct wpa_ssid
*ssid
;
5215 persistent_id
= atoi(pos2
+ 12);
5216 ssid
= wpa_config_get_network(wpa_s
->conf
, persistent_id
);
5217 if (ssid
== NULL
|| ssid
->disabled
!= 2 ||
5218 ssid
->mode
!= WPAS_MODE_P2P_GO
) {
5219 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
5220 "SSID id=%d for persistent P2P group (GO)",
5225 join
= os_strstr(pos
, " join") != NULL
;
5226 auth
= os_strstr(pos
, " auth") != NULL
;
5227 automatic
= os_strstr(pos
, " auto") != NULL
;
5228 pd
= os_strstr(pos
, " provdisc") != NULL
;
5229 vht
= (os_strstr(cmd
, " vht") != NULL
) || wpa_s
->conf
->p2p_go_vht
;
5230 ht40
= (os_strstr(cmd
, " ht40") != NULL
) || wpa_s
->conf
->p2p_go_ht40
||
5233 pos2
= os_strstr(pos
, " go_intent=");
5236 go_intent
= atoi(pos2
);
5237 if (go_intent
< 0 || go_intent
> 15)
5241 pos2
= os_strstr(pos
, " freq=");
5249 pos2
= os_strstr(pos
, " freq2=");
5251 freq2
= atoi(pos2
+ 7);
5253 pos2
= os_strstr(pos
, " max_oper_chwidth=");
5255 chwidth
= atoi(pos2
+ 18);
5257 max_oper_chwidth
= parse_freq(chwidth
, freq2
);
5258 if (max_oper_chwidth
< 0)
5261 pos2
= os_strstr(pos
, " ssid=");
5266 end
= os_strchr(pos2
, ' ');
5268 group_ssid_len
= os_strlen(pos2
) / 2;
5270 group_ssid_len
= (end
- pos2
) / 2;
5271 if (group_ssid_len
== 0 || group_ssid_len
> SSID_MAX_LEN
||
5272 hexstr2bin(pos2
, _group_ssid
, group_ssid_len
) < 0)
5274 group_ssid
= _group_ssid
;
5277 if (os_strncmp(pos
, "pin", 3) == 0) {
5278 /* Request random PIN (to be displayed) and enable the PIN */
5279 wps_method
= WPS_PIN_DISPLAY
;
5280 } else if (os_strncmp(pos
, "pbc", 3) == 0) {
5281 wps_method
= WPS_PBC
;
5282 } else if (os_strstr(pos
, "p2ps") != NULL
) {
5283 wps_method
= WPS_P2PS
;
5286 pos
= os_strchr(pin
, ' ');
5287 wps_method
= WPS_PIN_KEYPAD
;
5290 if (os_strncmp(pos
, "display", 7) == 0)
5291 wps_method
= WPS_PIN_DISPLAY
;
5293 if (!wps_pin_str_valid(pin
)) {
5294 os_memcpy(buf
, "FAIL-INVALID-PIN\n", 17);
5299 new_pin
= wpas_p2p_connect(wpa_s
, addr
, pin
, wps_method
,
5300 persistent_group
, automatic
, join
,
5301 auth
, go_intent
, freq
, freq2
, persistent_id
,
5302 pd
, ht40
, vht
, max_oper_chwidth
,
5303 group_ssid
, group_ssid_len
);
5304 if (new_pin
== -2) {
5305 os_memcpy(buf
, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
5308 if (new_pin
== -3) {
5309 os_memcpy(buf
, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
5314 if (wps_method
== WPS_PIN_DISPLAY
&& pin
== NULL
) {
5315 ret
= os_snprintf(buf
, buflen
, "%08d", new_pin
);
5316 if (os_snprintf_error(buflen
, ret
))
5321 os_memcpy(buf
, "OK\n", 3);
5326 static int p2p_ctrl_listen(struct wpa_supplicant
*wpa_s
, char *cmd
)
5328 unsigned int timeout
= atoi(cmd
);
5329 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
5330 wpa_dbg(wpa_s
, MSG_INFO
,
5331 "Reject P2P_LISTEN since interface is disabled");
5334 return wpas_p2p_listen(wpa_s
, timeout
);
5338 static int p2p_ctrl_prov_disc(struct wpa_supplicant
*wpa_s
, char *cmd
)
5342 enum wpas_p2p_prov_disc_use use
= WPAS_P2P_PD_FOR_GO_NEG
;
5344 /* <addr> <config method> [join|auto] */
5346 if (hwaddr_aton(cmd
, addr
))
5354 if (os_strstr(pos
, " join") != NULL
)
5355 use
= WPAS_P2P_PD_FOR_JOIN
;
5356 else if (os_strstr(pos
, " auto") != NULL
)
5357 use
= WPAS_P2P_PD_AUTO
;
5359 return wpas_p2p_prov_disc(wpa_s
, addr
, pos
, use
, NULL
);
5363 static int p2p_get_passphrase(struct wpa_supplicant
*wpa_s
, char *buf
,
5366 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
5368 if (ssid
== NULL
|| ssid
->mode
!= WPAS_MODE_P2P_GO
||
5369 ssid
->passphrase
== NULL
)
5372 os_strlcpy(buf
, ssid
->passphrase
, buflen
);
5373 return os_strlen(buf
);
5377 static int p2p_ctrl_serv_disc_req(struct wpa_supplicant
*wpa_s
, char *cmd
,
5378 char *buf
, size_t buflen
)
5382 u8 dst_buf
[ETH_ALEN
], *dst
;
5383 struct wpabuf
*tlvs
;
5387 if (hwaddr_aton(cmd
, dst_buf
))
5390 if (dst
[0] == 0 && dst
[1] == 0 && dst
[2] == 0 &&
5391 dst
[3] == 0 && dst
[4] == 0 && dst
[5] == 0)
5398 if (os_strncmp(pos
, "upnp ", 5) == 0) {
5401 if (hexstr2bin(pos
, &version
, 1) < 0)
5407 ref
= wpas_p2p_sd_request_upnp(wpa_s
, dst
, version
, pos
);
5408 #ifdef CONFIG_WIFI_DISPLAY
5409 } else if (os_strncmp(pos
, "wifi-display ", 13) == 0) {
5410 ref
= wpas_p2p_sd_request_wifi_display(wpa_s
, dst
, pos
+ 13);
5411 #endif /* CONFIG_WIFI_DISPLAY */
5412 } else if (os_strncmp(pos
, "asp ", 4) == 0) {
5414 char *svc_info
= NULL
;
5418 if (sscanf(pos
, "%x", &id
) != 1 || id
> 0xff)
5421 pos
= os_strchr(pos
, ' ');
5422 if (pos
== NULL
|| pos
[1] == '\0' || pos
[1] == ' ')
5427 pos
= os_strchr(svc_str
, ' ');
5432 /* All remaining data is the svc_info string */
5433 if (pos
&& pos
[0] && pos
[0] != ' ') {
5434 len
= os_strlen(pos
);
5436 /* Unescape in place */
5437 len
= utf8_unescape(pos
, len
, pos
, len
);
5444 ref
= wpas_p2p_sd_request_asp(wpa_s
, dst
, (u8
) id
,
5447 len
= os_strlen(pos
);
5451 tlvs
= wpabuf_alloc(len
);
5454 if (hexstr2bin(pos
, wpabuf_put(tlvs
, len
), len
) < 0) {
5459 ref
= wpas_p2p_sd_request(wpa_s
, dst
, tlvs
);
5464 res
= os_snprintf(buf
, buflen
, "%llx", (long long unsigned) ref
);
5465 if (os_snprintf_error(buflen
, res
))
5471 static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant
*wpa_s
,
5474 long long unsigned val
;
5476 if (sscanf(cmd
, "%llx", &val
) != 1)
5479 return wpas_p2p_sd_cancel_request(wpa_s
, req
);
5483 static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant
*wpa_s
, char *cmd
)
5488 struct wpabuf
*resp_tlvs
;
5492 pos
= os_strchr(cmd
, ' ');
5500 if (hwaddr_aton(pos
, dst
))
5507 pos2
= os_strchr(pos
, ' ');
5511 dialog_token
= atoi(pos
);
5513 len
= os_strlen(pos2
);
5517 resp_tlvs
= wpabuf_alloc(len
);
5518 if (resp_tlvs
== NULL
)
5520 if (hexstr2bin(pos2
, wpabuf_put(resp_tlvs
, len
), len
) < 0) {
5521 wpabuf_free(resp_tlvs
);
5525 wpas_p2p_sd_response(wpa_s
, freq
, dst
, dialog_token
, resp_tlvs
);
5526 wpabuf_free(resp_tlvs
);
5531 static int p2p_ctrl_serv_disc_external(struct wpa_supplicant
*wpa_s
,
5534 if (os_strcmp(cmd
, "0") && os_strcmp(cmd
, "1"))
5536 wpa_s
->p2p_sd_over_ctrl_iface
= atoi(cmd
);
5541 static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant
*wpa_s
,
5546 struct wpabuf
*query
, *resp
;
5548 pos
= os_strchr(cmd
, ' ');
5553 len
= os_strlen(cmd
);
5557 query
= wpabuf_alloc(len
);
5560 if (hexstr2bin(cmd
, wpabuf_put(query
, len
), len
) < 0) {
5565 len
= os_strlen(pos
);
5571 resp
= wpabuf_alloc(len
);
5576 if (hexstr2bin(pos
, wpabuf_put(resp
, len
), len
) < 0) {
5582 if (wpas_p2p_service_add_bonjour(wpa_s
, query
, resp
) < 0) {
5591 static int p2p_ctrl_service_add_upnp(struct wpa_supplicant
*wpa_s
, char *cmd
)
5596 pos
= os_strchr(cmd
, ' ');
5601 if (hexstr2bin(cmd
, &version
, 1) < 0)
5604 return wpas_p2p_service_add_upnp(wpa_s
, version
, pos
);
5608 static int p2p_ctrl_service_add_asp(struct wpa_supplicant
*wpa_s
,
5609 u8 replace
, char *cmd
)
5613 u32 auto_accept
, adv_id
, svc_state
, config_methods
;
5614 char *svc_info
= NULL
;
5616 u8 cpt_prio
[P2PS_FEATURE_CAPAB_CPT_MAX
+ 1];
5618 pos
= os_strchr(cmd
, ' ');
5623 /* Auto-Accept value is mandatory, and must be one of the
5624 * single values (0, 1, 2, 4) */
5625 auto_accept
= atoi(cmd
);
5626 switch (auto_accept
) {
5627 case P2PS_SETUP_NONE
: /* No auto-accept */
5628 case P2PS_SETUP_NEW
:
5629 case P2PS_SETUP_CLIENT
:
5630 case P2PS_SETUP_GROUP_OWNER
:
5636 /* Advertisement ID is mandatory */
5638 pos
= os_strchr(cmd
, ' ');
5643 /* Handle Adv_ID == 0 (wildcard "org.wi-fi.wfds") internally. */
5644 if (sscanf(cmd
, "%x", &adv_id
) != 1 || adv_id
== 0)
5647 /* Only allow replacements if exist, and adds if not */
5648 if (wpas_p2p_service_p2ps_id_exists(wpa_s
, adv_id
)) {
5656 /* svc_state between 0 - 0xff is mandatory */
5657 if (sscanf(pos
, "%x", &svc_state
) != 1 || svc_state
> 0xff)
5660 pos
= os_strchr(pos
, ' ');
5664 /* config_methods is mandatory */
5666 if (sscanf(pos
, "%x", &config_methods
) != 1)
5669 if (!(config_methods
&
5670 (WPS_CONFIG_DISPLAY
| WPS_CONFIG_KEYPAD
| WPS_CONFIG_P2PS
)))
5673 pos
= os_strchr(pos
, ' ');
5680 /* Advertisement string is mandatory */
5681 if (!pos
[0] || pos
[0] == ' ')
5684 /* Terminate svc string */
5685 pos
= os_strchr(pos
, ' ');
5689 cpt_prio_str
= (pos
&& pos
[0]) ? os_strstr(pos
, "cpt=") : NULL
;
5691 pos
= os_strchr(pos
, ' ');
5695 if (p2ps_ctrl_parse_cpt_priority(cpt_prio_str
+ 4, cpt_prio
))
5698 cpt_prio
[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT
;
5702 /* Service and Response Information are optional */
5703 if (pos
&& pos
[0]) {
5706 /* Note the bare ' included, which cannot exist legally
5707 * in unescaped string. */
5708 svc_info
= os_strstr(pos
, "svc_info='");
5712 len
= os_strlen(svc_info
);
5713 utf8_unescape(svc_info
, len
, svc_info
, len
);
5717 return wpas_p2p_service_add_asp(wpa_s
, auto_accept
, adv_id
, adv_str
,
5718 (u8
) svc_state
, (u16
) config_methods
,
5719 svc_info
, cpt_prio
);
5723 static int p2p_ctrl_service_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
5727 pos
= os_strchr(cmd
, ' ');
5732 if (os_strcmp(cmd
, "bonjour") == 0)
5733 return p2p_ctrl_service_add_bonjour(wpa_s
, pos
);
5734 if (os_strcmp(cmd
, "upnp") == 0)
5735 return p2p_ctrl_service_add_upnp(wpa_s
, pos
);
5736 if (os_strcmp(cmd
, "asp") == 0)
5737 return p2p_ctrl_service_add_asp(wpa_s
, 0, pos
);
5738 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
5743 static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant
*wpa_s
,
5747 struct wpabuf
*query
;
5750 len
= os_strlen(cmd
);
5754 query
= wpabuf_alloc(len
);
5757 if (hexstr2bin(cmd
, wpabuf_put(query
, len
), len
) < 0) {
5762 ret
= wpas_p2p_service_del_bonjour(wpa_s
, query
);
5768 static int p2p_ctrl_service_del_upnp(struct wpa_supplicant
*wpa_s
, char *cmd
)
5773 pos
= os_strchr(cmd
, ' ');
5778 if (hexstr2bin(cmd
, &version
, 1) < 0)
5781 return wpas_p2p_service_del_upnp(wpa_s
, version
, pos
);
5785 static int p2p_ctrl_service_del_asp(struct wpa_supplicant
*wpa_s
, char *cmd
)
5789 if (os_strcmp(cmd
, "all") == 0) {
5790 wpas_p2p_service_flush_asp(wpa_s
);
5794 if (sscanf(cmd
, "%x", &adv_id
) != 1)
5797 return wpas_p2p_service_del_asp(wpa_s
, adv_id
);
5801 static int p2p_ctrl_service_del(struct wpa_supplicant
*wpa_s
, char *cmd
)
5805 pos
= os_strchr(cmd
, ' ');
5810 if (os_strcmp(cmd
, "bonjour") == 0)
5811 return p2p_ctrl_service_del_bonjour(wpa_s
, pos
);
5812 if (os_strcmp(cmd
, "upnp") == 0)
5813 return p2p_ctrl_service_del_upnp(wpa_s
, pos
);
5814 if (os_strcmp(cmd
, "asp") == 0)
5815 return p2p_ctrl_service_del_asp(wpa_s
, pos
);
5816 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
5821 static int p2p_ctrl_service_replace(struct wpa_supplicant
*wpa_s
, char *cmd
)
5825 pos
= os_strchr(cmd
, ' ');
5830 if (os_strcmp(cmd
, "asp") == 0)
5831 return p2p_ctrl_service_add_asp(wpa_s
, 1, pos
);
5833 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
5838 static int p2p_ctrl_reject(struct wpa_supplicant
*wpa_s
, char *cmd
)
5844 if (hwaddr_aton(cmd
, addr
))
5847 return wpas_p2p_reject(wpa_s
, addr
);
5851 static int p2p_ctrl_invite_persistent(struct wpa_supplicant
*wpa_s
, char *cmd
)
5855 struct wpa_ssid
*ssid
;
5856 u8
*_peer
= NULL
, peer
[ETH_ALEN
];
5857 int freq
= 0, pref_freq
= 0;
5858 int ht40
, vht
, max_oper_chwidth
, chwidth
= 0, freq2
= 0;
5861 pos
= os_strstr(cmd
, " peer=");
5864 if (hwaddr_aton(pos
, peer
))
5868 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
5869 if (ssid
== NULL
|| ssid
->disabled
!= 2) {
5870 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
5871 "for persistent P2P group",
5876 pos
= os_strstr(cmd
, " freq=");
5884 pos
= os_strstr(cmd
, " pref=");
5887 pref_freq
= atoi(pos
);
5892 vht
= (os_strstr(cmd
, " vht") != NULL
) || wpa_s
->conf
->p2p_go_vht
;
5893 ht40
= (os_strstr(cmd
, " ht40") != NULL
) || wpa_s
->conf
->p2p_go_ht40
||
5896 pos
= os_strstr(cmd
, "freq2=");
5898 freq2
= atoi(pos
+ 6);
5900 pos
= os_strstr(cmd
, " max_oper_chwidth=");
5902 chwidth
= atoi(pos
+ 18);
5904 max_oper_chwidth
= parse_freq(chwidth
, freq2
);
5905 if (max_oper_chwidth
< 0)
5908 return wpas_p2p_invite(wpa_s
, _peer
, ssid
, NULL
, freq
, freq2
, ht40
, vht
,
5909 max_oper_chwidth
, pref_freq
);
5913 static int p2p_ctrl_invite_group(struct wpa_supplicant
*wpa_s
, char *cmd
)
5916 u8 peer
[ETH_ALEN
], go_dev_addr
[ETH_ALEN
], *go_dev
= NULL
;
5918 pos
= os_strstr(cmd
, " peer=");
5924 if (hwaddr_aton(pos
, peer
)) {
5925 wpa_printf(MSG_DEBUG
, "P2P: Invalid MAC address '%s'", pos
);
5929 pos
= os_strstr(pos
, " go_dev_addr=");
5932 if (hwaddr_aton(pos
, go_dev_addr
)) {
5933 wpa_printf(MSG_DEBUG
, "P2P: Invalid MAC address '%s'",
5937 go_dev
= go_dev_addr
;
5940 return wpas_p2p_invite_group(wpa_s
, cmd
, peer
, go_dev
);
5944 static int p2p_ctrl_invite(struct wpa_supplicant
*wpa_s
, char *cmd
)
5946 if (os_strncmp(cmd
, "persistent=", 11) == 0)
5947 return p2p_ctrl_invite_persistent(wpa_s
, cmd
+ 11);
5948 if (os_strncmp(cmd
, "group=", 6) == 0)
5949 return p2p_ctrl_invite_group(wpa_s
, cmd
+ 6);
5955 static int p2p_ctrl_group_add_persistent(struct wpa_supplicant
*wpa_s
,
5956 int id
, int freq
, int vht_center_freq2
,
5957 int ht40
, int vht
, int vht_chwidth
)
5959 struct wpa_ssid
*ssid
;
5961 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
5962 if (ssid
== NULL
|| ssid
->disabled
!= 2) {
5963 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
5964 "for persistent P2P group",
5969 return wpas_p2p_group_add_persistent(wpa_s
, ssid
, 0, freq
,
5970 vht_center_freq2
, 0, ht40
, vht
,
5971 vht_chwidth
, NULL
, 0, 0);
5975 static int p2p_ctrl_group_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
5977 int freq
= 0, persistent
= 0, group_id
= -1;
5978 int vht
= wpa_s
->conf
->p2p_go_vht
;
5979 int ht40
= wpa_s
->conf
->p2p_go_ht40
|| vht
;
5980 int max_oper_chwidth
, chwidth
= 0, freq2
= 0;
5981 char *token
, *context
= NULL
;
5983 while ((token
= str_token(cmd
, " ", &context
))) {
5984 if (sscanf(token
, "freq=%d", &freq
) == 1 ||
5985 sscanf(token
, "freq2=%d", &freq2
) == 1 ||
5986 sscanf(token
, "persistent=%d", &group_id
) == 1 ||
5987 sscanf(token
, "max_oper_chwidth=%d", &chwidth
) == 1) {
5989 } else if (os_strcmp(token
, "ht40") == 0) {
5991 } else if (os_strcmp(token
, "vht") == 0) {
5994 } else if (os_strcmp(token
, "persistent") == 0) {
5997 wpa_printf(MSG_DEBUG
,
5998 "CTRL: Invalid P2P_GROUP_ADD parameter: '%s'",
6004 max_oper_chwidth
= parse_freq(chwidth
, freq2
);
6005 if (max_oper_chwidth
< 0)
6009 return p2p_ctrl_group_add_persistent(wpa_s
, group_id
,
6010 freq
, freq2
, ht40
, vht
,
6013 return wpas_p2p_group_add(wpa_s
, persistent
, freq
, freq2
, ht40
, vht
,
6018 static int p2p_ctrl_group_member(struct wpa_supplicant
*wpa_s
, const char *cmd
,
6019 char *buf
, size_t buflen
)
6021 u8 dev_addr
[ETH_ALEN
];
6022 struct wpa_ssid
*ssid
;
6026 ssid
= wpa_s
->current_ssid
;
6027 if (!wpa_s
->global
->p2p
|| !ssid
|| ssid
->mode
!= WPAS_MODE_P2P_GO
||
6028 hwaddr_aton(cmd
, dev_addr
))
6031 iaddr
= p2p_group_get_client_interface_addr(wpa_s
->p2p_group
, dev_addr
);
6034 res
= os_snprintf(buf
, buflen
, MACSTR
, MAC2STR(iaddr
));
6035 if (os_snprintf_error(buflen
, res
))
6041 static int p2p_ctrl_peer(struct wpa_supplicant
*wpa_s
, char *cmd
,
6042 char *buf
, size_t buflen
)
6044 u8 addr
[ETH_ALEN
], *addr_ptr
;
6046 const struct p2p_peer_info
*info
;
6048 char devtype
[WPS_DEV_TYPE_BUFSIZE
];
6049 struct wpa_ssid
*ssid
;
6052 if (!wpa_s
->global
->p2p
)
6055 if (os_strcmp(cmd
, "FIRST") == 0) {
6058 } else if (os_strncmp(cmd
, "NEXT-", 5) == 0) {
6059 if (hwaddr_aton(cmd
+ 5, addr
) < 0)
6064 if (hwaddr_aton(cmd
, addr
) < 0)
6070 info
= p2p_get_peer_info(wpa_s
->global
->p2p
, addr_ptr
, next
);
6077 res
= os_snprintf(pos
, end
- pos
, MACSTR
"\n"
6083 "serial_number=%s\n"
6084 "config_methods=0x%x\n"
6086 "group_capab=0x%x\n"
6088 MAC2STR(info
->p2p_device_addr
),
6089 wps_dev_type_bin2str(info
->pri_dev_type
,
6090 devtype
, sizeof(devtype
)),
6095 info
->serial_number
,
6096 info
->config_methods
,
6100 if (os_snprintf_error(end
- pos
, res
))
6104 for (i
= 0; i
< info
->wps_sec_dev_type_list_len
/ WPS_DEV_TYPE_LEN
; i
++)
6107 t
= &info
->wps_sec_dev_type_list
[i
* WPS_DEV_TYPE_LEN
];
6108 res
= os_snprintf(pos
, end
- pos
, "sec_dev_type=%s\n",
6109 wps_dev_type_bin2str(t
, devtype
,
6111 if (os_snprintf_error(end
- pos
, res
))
6116 ssid
= wpas_p2p_get_persistent(wpa_s
, info
->p2p_device_addr
, NULL
, 0);
6118 res
= os_snprintf(pos
, end
- pos
, "persistent=%d\n", ssid
->id
);
6119 if (os_snprintf_error(end
- pos
, res
))
6124 res
= p2p_get_peer_info_txt(info
, pos
, end
- pos
);
6129 if (info
->vendor_elems
) {
6130 res
= os_snprintf(pos
, end
- pos
, "vendor_elems=");
6131 if (os_snprintf_error(end
- pos
, res
))
6135 pos
+= wpa_snprintf_hex(pos
, end
- pos
,
6136 wpabuf_head(info
->vendor_elems
),
6137 wpabuf_len(info
->vendor_elems
));
6139 res
= os_snprintf(pos
, end
- pos
, "\n");
6140 if (os_snprintf_error(end
- pos
, res
))
6149 static int p2p_ctrl_disallow_freq(struct wpa_supplicant
*wpa_s
,
6154 if (wpa_s
->global
->p2p
== NULL
)
6157 if (freq_range_list_parse(&wpa_s
->global
->p2p_disallow_freq
, param
) < 0)
6160 for (i
= 0; i
< wpa_s
->global
->p2p_disallow_freq
.num
; i
++) {
6161 struct wpa_freq_range
*freq
;
6162 freq
= &wpa_s
->global
->p2p_disallow_freq
.range
[i
];
6163 wpa_printf(MSG_DEBUG
, "P2P: Disallowed frequency range %u-%u",
6164 freq
->min
, freq
->max
);
6167 wpas_p2p_update_channel_list(wpa_s
, WPAS_P2P_CHANNEL_UPDATE_DISALLOW
);
6172 static int p2p_ctrl_set(struct wpa_supplicant
*wpa_s
, char *cmd
)
6176 if (wpa_s
->global
->p2p
== NULL
)
6179 param
= os_strchr(cmd
, ' ');
6184 if (os_strcmp(cmd
, "discoverability") == 0) {
6185 p2p_set_client_discoverability(wpa_s
->global
->p2p
,
6190 if (os_strcmp(cmd
, "managed") == 0) {
6191 p2p_set_managed_oper(wpa_s
->global
->p2p
, atoi(param
));
6195 if (os_strcmp(cmd
, "listen_channel") == 0) {
6197 u8 channel
, op_class
;
6199 channel
= atoi(param
);
6200 pos
= os_strchr(param
, ' ');
6201 op_class
= pos
? atoi(pos
) : 81;
6203 return p2p_set_listen_channel(wpa_s
->global
->p2p
, op_class
,
6207 if (os_strcmp(cmd
, "ssid_postfix") == 0) {
6208 return p2p_set_ssid_postfix(wpa_s
->global
->p2p
, (u8
*) param
,
6212 if (os_strcmp(cmd
, "noa") == 0) {
6214 int count
, start
, duration
;
6215 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
6216 count
= atoi(param
);
6217 pos
= os_strchr(param
, ',');
6222 pos
= os_strchr(pos
, ',');
6226 duration
= atoi(pos
);
6227 if (count
< 0 || count
> 255 || start
< 0 || duration
< 0)
6229 if (count
== 0 && duration
> 0)
6231 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
6232 "start=%d duration=%d", count
, start
, duration
);
6233 return wpas_p2p_set_noa(wpa_s
, count
, start
, duration
);
6236 if (os_strcmp(cmd
, "ps") == 0)
6237 return wpa_drv_set_p2p_powersave(wpa_s
, atoi(param
), -1, -1);
6239 if (os_strcmp(cmd
, "oppps") == 0)
6240 return wpa_drv_set_p2p_powersave(wpa_s
, -1, atoi(param
), -1);
6242 if (os_strcmp(cmd
, "ctwindow") == 0)
6243 return wpa_drv_set_p2p_powersave(wpa_s
, -1, -1, atoi(param
));
6245 if (os_strcmp(cmd
, "disabled") == 0) {
6246 wpa_s
->global
->p2p_disabled
= atoi(param
);
6247 wpa_printf(MSG_DEBUG
, "P2P functionality %s",
6248 wpa_s
->global
->p2p_disabled
?
6249 "disabled" : "enabled");
6250 if (wpa_s
->global
->p2p_disabled
) {
6251 wpas_p2p_stop_find(wpa_s
);
6252 os_memset(wpa_s
->p2p_auth_invite
, 0, ETH_ALEN
);
6253 p2p_flush(wpa_s
->global
->p2p
);
6258 if (os_strcmp(cmd
, "conc_pref") == 0) {
6259 if (os_strcmp(param
, "sta") == 0)
6260 wpa_s
->global
->conc_pref
= WPA_CONC_PREF_STA
;
6261 else if (os_strcmp(param
, "p2p") == 0)
6262 wpa_s
->global
->conc_pref
= WPA_CONC_PREF_P2P
;
6264 wpa_printf(MSG_INFO
, "Invalid conc_pref value");
6267 wpa_printf(MSG_DEBUG
, "Single channel concurrency preference: "
6272 if (os_strcmp(cmd
, "force_long_sd") == 0) {
6273 wpa_s
->force_long_sd
= atoi(param
);
6277 if (os_strcmp(cmd
, "peer_filter") == 0) {
6279 if (hwaddr_aton(param
, addr
))
6281 p2p_set_peer_filter(wpa_s
->global
->p2p
, addr
);
6285 if (os_strcmp(cmd
, "cross_connect") == 0)
6286 return wpas_p2p_set_cross_connect(wpa_s
, atoi(param
));
6288 if (os_strcmp(cmd
, "go_apsd") == 0) {
6289 if (os_strcmp(param
, "disable") == 0)
6290 wpa_s
->set_ap_uapsd
= 0;
6292 wpa_s
->set_ap_uapsd
= 1;
6293 wpa_s
->ap_uapsd
= atoi(param
);
6298 if (os_strcmp(cmd
, "client_apsd") == 0) {
6299 if (os_strcmp(param
, "disable") == 0)
6300 wpa_s
->set_sta_uapsd
= 0;
6304 /* format: BE,BK,VI,VO;max SP Length */
6306 pos
= os_strchr(param
, ',');
6311 pos
= os_strchr(pos
, ',');
6316 pos
= os_strchr(pos
, ',');
6321 /* ignore max SP Length for now */
6323 wpa_s
->set_sta_uapsd
= 1;
6324 wpa_s
->sta_uapsd
= 0;
6326 wpa_s
->sta_uapsd
|= BIT(0);
6328 wpa_s
->sta_uapsd
|= BIT(1);
6330 wpa_s
->sta_uapsd
|= BIT(2);
6332 wpa_s
->sta_uapsd
|= BIT(3);
6337 if (os_strcmp(cmd
, "disallow_freq") == 0)
6338 return p2p_ctrl_disallow_freq(wpa_s
, param
);
6340 if (os_strcmp(cmd
, "disc_int") == 0) {
6341 int min_disc_int
, max_disc_int
, max_disc_tu
;
6346 min_disc_int
= atoi(pos
);
6347 pos
= os_strchr(pos
, ' ');
6352 max_disc_int
= atoi(pos
);
6353 pos
= os_strchr(pos
, ' ');
6358 max_disc_tu
= atoi(pos
);
6360 return p2p_set_disc_int(wpa_s
->global
->p2p
, min_disc_int
,
6361 max_disc_int
, max_disc_tu
);
6364 if (os_strcmp(cmd
, "per_sta_psk") == 0) {
6365 wpa_s
->global
->p2p_per_sta_psk
= !!atoi(param
);
6369 #ifdef CONFIG_WPS_NFC
6370 if (os_strcmp(cmd
, "nfc_tag") == 0)
6371 return wpas_p2p_nfc_tag_enabled(wpa_s
, !!atoi(param
));
6372 #endif /* CONFIG_WPS_NFC */
6374 if (os_strcmp(cmd
, "disable_ip_addr_req") == 0) {
6375 wpa_s
->p2p_disable_ip_addr_req
= !!atoi(param
);
6379 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
6386 static void p2p_ctrl_flush(struct wpa_supplicant
*wpa_s
)
6388 os_memset(wpa_s
->p2p_auth_invite
, 0, ETH_ALEN
);
6389 wpa_s
->force_long_sd
= 0;
6390 wpas_p2p_stop_find(wpa_s
);
6391 wpa_s
->parent
->p2ps_method_config_any
= 0;
6392 if (wpa_s
->global
->p2p
)
6393 p2p_flush(wpa_s
->global
->p2p
);
6397 static int p2p_ctrl_presence_req(struct wpa_supplicant
*wpa_s
, char *cmd
)
6400 unsigned int dur1
= 0, int1
= 0, dur2
= 0, int2
= 0;
6403 pos
= os_strchr(cmd
, ' ');
6409 pos2
= os_strchr(pos
, ' ');
6417 pos
= os_strchr(pos2
, ' ');
6425 return wpas_p2p_presence_req(wpa_s
, dur1
, int1
, dur2
, int2
);
6429 static int p2p_ctrl_ext_listen(struct wpa_supplicant
*wpa_s
, char *cmd
)
6432 unsigned int period
= 0, interval
= 0;
6435 pos
= os_strchr(cmd
, ' ');
6440 interval
= atoi(pos
);
6443 return wpas_p2p_ext_listen(wpa_s
, period
, interval
);
6447 static int p2p_ctrl_remove_client(struct wpa_supplicant
*wpa_s
, const char *cmd
)
6454 if (os_strncmp(pos
, "iface=", 6) == 0) {
6458 if (hwaddr_aton(pos
, peer
))
6461 wpas_p2p_remove_client(wpa_s
, peer
, iface_addr
);
6466 static int p2p_ctrl_iface_p2p_lo_start(struct wpa_supplicant
*wpa_s
, char *cmd
)
6468 int freq
= 0, period
= 0, interval
= 0, count
= 0;
6470 if (sscanf(cmd
, "%d %d %d %d", &freq
, &period
, &interval
, &count
) != 4)
6472 wpa_printf(MSG_DEBUG
,
6473 "CTRL: Invalid P2P LO Start parameter: '%s'", cmd
);
6477 return wpas_p2p_lo_start(wpa_s
, freq
, period
, interval
, count
);
6480 #endif /* CONFIG_P2P */
6483 static int * freq_range_to_channel_list(struct wpa_supplicant
*wpa_s
, char *val
)
6485 struct wpa_freq_range_list ranges
;
6487 struct hostapd_hw_modes
*mode
;
6490 if (wpa_s
->hw
.modes
== NULL
)
6493 os_memset(&ranges
, 0, sizeof(ranges
));
6494 if (freq_range_list_parse(&ranges
, val
) < 0)
6497 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
6500 mode
= &wpa_s
->hw
.modes
[i
];
6501 for (j
= 0; j
< mode
->num_channels
; j
++) {
6504 if (mode
->channels
[j
].flag
& HOSTAPD_CHAN_DISABLED
)
6507 freq
= mode
->channels
[j
].freq
;
6508 if (!freq_range_list_includes(&ranges
, freq
))
6511 int_array_add_unique(&freqs
, freq
);
6515 os_free(ranges
.range
);
6520 #ifdef CONFIG_INTERWORKING
6522 static int ctrl_interworking_select(struct wpa_supplicant
*wpa_s
, char *param
)
6530 auto_sel
= os_strstr(param
, "auto") != NULL
;
6532 pos
= os_strstr(param
, "freq=");
6534 freqs
= freq_range_to_channel_list(wpa_s
, pos
+ 5);
6541 return interworking_select(wpa_s
, auto_sel
, freqs
);
6545 static int ctrl_interworking_connect(struct wpa_supplicant
*wpa_s
, char *dst
,
6549 struct wpa_bss
*bss
;
6551 if (hwaddr_aton(dst
, bssid
)) {
6552 wpa_printf(MSG_DEBUG
, "Invalid BSSID '%s'", dst
);
6556 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
6558 wpa_printf(MSG_DEBUG
, "Could not find BSS " MACSTR
,
6563 if (bss
->ssid_len
== 0) {
6566 wpa_printf(MSG_DEBUG
, "Selected BSS entry for " MACSTR
6567 " does not have SSID information", MAC2STR(bssid
));
6569 dl_list_for_each_reverse(bss
, &wpa_s
->bss
, struct wpa_bss
,
6571 if (os_memcmp(bss
->bssid
, bssid
, ETH_ALEN
) == 0 &&
6572 bss
->ssid_len
> 0) {
6580 wpa_printf(MSG_DEBUG
,
6581 "Found another matching BSS entry with SSID");
6584 return interworking_connect(wpa_s
, bss
, only_add
);
6588 static int get_anqp(struct wpa_supplicant
*wpa_s
, char *dst
)
6590 u8 dst_addr
[ETH_ALEN
];
6593 #define MAX_ANQP_INFO_ID 100
6594 u16 id
[MAX_ANQP_INFO_ID
];
6597 int get_cell_pref
= 0;
6599 used
= hwaddr_aton2(dst
, dst_addr
);
6605 while (num_id
< MAX_ANQP_INFO_ID
) {
6606 if (os_strncmp(pos
, "hs20:", 5) == 0) {
6608 int num
= atoi(pos
+ 5);
6609 if (num
<= 0 || num
> 31)
6611 subtypes
|= BIT(num
);
6612 #else /* CONFIG_HS20 */
6614 #endif /* CONFIG_HS20 */
6615 } else if (os_strncmp(pos
, "mbo:", 4) == 0) {
6617 int num
= atoi(pos
+ 4);
6618 if (num
!= MBO_ANQP_SUBTYPE_CELL_CONN_PREF
)
6621 #else /* CONFIG_MBO */
6623 #endif /* CONFIG_MBO */
6625 id
[num_id
] = atoi(pos
);
6629 pos
= os_strchr(pos
+ 1, ',');
6638 return anqp_send_req(wpa_s
, dst_addr
, id
, num_id
, subtypes
,
6643 static int gas_request(struct wpa_supplicant
*wpa_s
, char *cmd
)
6645 u8 dst_addr
[ETH_ALEN
];
6646 struct wpabuf
*advproto
, *query
= NULL
;
6651 used
= hwaddr_aton2(cmd
, dst_addr
);
6659 /* Advertisement Protocol ID */
6660 end
= os_strchr(pos
, ' ');
6664 len
= os_strlen(pos
);
6670 advproto
= wpabuf_alloc(len
);
6671 if (advproto
== NULL
)
6673 if (hexstr2bin(pos
, wpabuf_put(advproto
, len
), len
) < 0)
6677 /* Optional Query Request */
6682 len
= os_strlen(pos
);
6689 query
= wpabuf_alloc(len
);
6692 if (hexstr2bin(pos
, wpabuf_put(query
, len
), len
) < 0)
6697 ret
= gas_send_request(wpa_s
, dst_addr
, advproto
, query
);
6700 wpabuf_free(advproto
);
6707 static int gas_response_get(struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
,
6714 size_t resp_len
, start
, requested_len
;
6715 struct wpabuf
*resp
;
6718 used
= hwaddr_aton2(cmd
, addr
);
6725 dialog_token
= atoi(pos
);
6727 if (wpa_s
->last_gas_resp
&&
6728 os_memcmp(addr
, wpa_s
->last_gas_addr
, ETH_ALEN
) == 0 &&
6729 dialog_token
== wpa_s
->last_gas_dialog_token
)
6730 resp
= wpa_s
->last_gas_resp
;
6731 else if (wpa_s
->prev_gas_resp
&&
6732 os_memcmp(addr
, wpa_s
->prev_gas_addr
, ETH_ALEN
) == 0 &&
6733 dialog_token
== wpa_s
->prev_gas_dialog_token
)
6734 resp
= wpa_s
->prev_gas_resp
;
6738 resp_len
= wpabuf_len(resp
);
6740 requested_len
= resp_len
;
6742 pos
= os_strchr(pos
, ' ');
6745 if (start
> resp_len
)
6746 return os_snprintf(buf
, buflen
, "FAIL-Invalid range");
6747 pos
= os_strchr(pos
, ',');
6751 requested_len
= atoi(pos
);
6752 if (start
+ requested_len
> resp_len
)
6753 return os_snprintf(buf
, buflen
, "FAIL-Invalid range");
6756 if (requested_len
* 2 + 1 > buflen
)
6757 return os_snprintf(buf
, buflen
, "FAIL-Too long response");
6759 ret
= wpa_snprintf_hex(buf
, buflen
, wpabuf_head_u8(resp
) + start
,
6762 if (start
+ requested_len
== resp_len
) {
6764 * Free memory by dropping the response after it has been
6767 if (resp
== wpa_s
->prev_gas_resp
) {
6768 wpabuf_free(wpa_s
->prev_gas_resp
);
6769 wpa_s
->prev_gas_resp
= NULL
;
6771 wpabuf_free(wpa_s
->last_gas_resp
);
6772 wpa_s
->last_gas_resp
= NULL
;
6778 #endif /* CONFIG_INTERWORKING */
6783 static int get_hs20_anqp(struct wpa_supplicant
*wpa_s
, char *dst
)
6785 u8 dst_addr
[ETH_ALEN
];
6790 used
= hwaddr_aton2(dst
, dst_addr
);
6797 int num
= atoi(pos
);
6798 if (num
<= 0 || num
> 31)
6800 subtypes
|= BIT(num
);
6801 pos
= os_strchr(pos
+ 1, ',');
6810 return hs20_anqp_send_req(wpa_s
, dst_addr
, subtypes
, NULL
, 0, 0);
6814 static int hs20_nai_home_realm_list(struct wpa_supplicant
*wpa_s
,
6815 const u8
*addr
, const char *realm
)
6821 rlen
= os_strlen(realm
);
6823 buf
= os_malloc(len
);
6826 buf
[0] = 1; /* NAI Home Realm Count */
6827 buf
[1] = 0; /* Formatted in accordance with RFC 4282 */
6829 os_memcpy(buf
+ 3, realm
, rlen
);
6831 ret
= hs20_anqp_send_req(wpa_s
, addr
,
6832 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY
),
6841 static int hs20_get_nai_home_realm_list(struct wpa_supplicant
*wpa_s
,
6844 struct wpa_cred
*cred
= wpa_s
->conf
->cred
;
6845 u8 dst_addr
[ETH_ALEN
];
6851 used
= hwaddr_aton2(dst
, dst_addr
);
6855 while (dst
[used
] == ' ')
6857 if (os_strncmp(dst
+ used
, "realm=", 6) == 0)
6858 return hs20_nai_home_realm_list(wpa_s
, dst_addr
,
6861 len
= os_strlen(dst
+ used
);
6863 if (len
== 0 && cred
&& cred
->realm
)
6864 return hs20_nai_home_realm_list(wpa_s
, dst_addr
, cred
->realm
);
6869 buf
= os_malloc(len
);
6872 if (hexstr2bin(dst
+ used
, buf
, len
) < 0) {
6877 ret
= hs20_anqp_send_req(wpa_s
, dst_addr
,
6878 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY
),
6886 static int get_hs20_icon(struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
,
6889 u8 dst_addr
[ETH_ALEN
];
6891 char *ctx
= NULL
, *icon
, *poffset
, *psize
;
6893 used
= hwaddr_aton2(cmd
, dst_addr
);
6898 icon
= str_token(cmd
, " ", &ctx
);
6899 poffset
= str_token(cmd
, " ", &ctx
);
6900 psize
= str_token(cmd
, " ", &ctx
);
6901 if (!icon
|| !poffset
|| !psize
)
6904 wpa_s
->fetch_osu_icon_in_progress
= 0;
6905 return hs20_get_icon(wpa_s
, dst_addr
, icon
, atoi(poffset
), atoi(psize
),
6910 static int del_hs20_icon(struct wpa_supplicant
*wpa_s
, char *cmd
)
6912 u8 dst_addr
[ETH_ALEN
];
6917 return hs20_del_icon(wpa_s
, NULL
, NULL
);
6919 used
= hwaddr_aton2(cmd
, dst_addr
);
6923 while (cmd
[used
] == ' ')
6925 icon
= cmd
[used
] ? &cmd
[used
] : NULL
;
6927 return hs20_del_icon(wpa_s
, dst_addr
, icon
);
6931 static int hs20_icon_request(struct wpa_supplicant
*wpa_s
, char *cmd
, int inmem
)
6933 u8 dst_addr
[ETH_ALEN
];
6937 used
= hwaddr_aton2(cmd
, dst_addr
);
6941 while (cmd
[used
] == ' ')
6945 wpa_s
->fetch_osu_icon_in_progress
= 0;
6946 return hs20_anqp_send_req(wpa_s
, dst_addr
, BIT(HS20_STYPE_ICON_REQUEST
),
6947 (u8
*) icon
, os_strlen(icon
), inmem
);
6950 #endif /* CONFIG_HS20 */
6953 #ifdef CONFIG_AUTOSCAN
6955 static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant
*wpa_s
,
6958 enum wpa_states state
= wpa_s
->wpa_state
;
6959 char *new_params
= NULL
;
6961 if (os_strlen(cmd
) > 0) {
6962 new_params
= os_strdup(cmd
);
6963 if (new_params
== NULL
)
6967 os_free(wpa_s
->conf
->autoscan
);
6968 wpa_s
->conf
->autoscan
= new_params
;
6970 if (wpa_s
->conf
->autoscan
== NULL
)
6971 autoscan_deinit(wpa_s
);
6972 else if (state
== WPA_DISCONNECTED
|| state
== WPA_INACTIVE
)
6973 autoscan_init(wpa_s
, 1);
6974 else if (state
== WPA_SCANNING
)
6975 wpa_supplicant_reinit_autoscan(wpa_s
);
6977 wpa_printf(MSG_DEBUG
, "No autoscan update in state %s",
6978 wpa_supplicant_state_txt(state
));
6983 #endif /* CONFIG_AUTOSCAN */
6988 static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant
*wpa_s
, char *cmd
)
6994 struct wpabuf
*tfs_req
= NULL
;
6996 if (os_strncmp(cmd
, "enter", 5) == 0)
6998 else if (os_strncmp(cmd
, "exit", 4) == 0)
7003 pos
= os_strstr(cmd
, " interval=");
7005 intval
= atoi(pos
+ 10);
7007 pos
= os_strstr(cmd
, " tfs_req=");
7012 end
= os_strchr(pos
, ' ');
7016 len
= os_strlen(pos
);
7020 tfs_req
= wpabuf_alloc(len
);
7021 if (tfs_req
== NULL
)
7023 if (hexstr2bin(pos
, wpabuf_put(tfs_req
, len
), len
) < 0) {
7024 wpabuf_free(tfs_req
);
7029 ret
= ieee802_11_send_wnmsleep_req(wpa_s
, enter
? WNM_SLEEP_MODE_ENTER
:
7030 WNM_SLEEP_MODE_EXIT
, intval
,
7032 wpabuf_free(tfs_req
);
7038 static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant
*wpa_s
, char *cmd
)
7040 int query_reason
, list
= 0;
7042 query_reason
= atoi(cmd
);
7044 cmd
= os_strchr(cmd
, ' ');
7047 if (os_strncmp(cmd
, "list", 4) == 0) {
7050 wpa_printf(MSG_DEBUG
, "WNM Query: Invalid option %s",
7056 wpa_printf(MSG_DEBUG
,
7057 "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d%s",
7058 query_reason
, list
? " candidate list" : "");
7060 return wnm_send_bss_transition_mgmt_query(wpa_s
, query_reason
, list
);
7063 #endif /* CONFIG_WNM */
7066 static int wpa_supplicant_signal_poll(struct wpa_supplicant
*wpa_s
, char *buf
,
7069 struct wpa_signal_info si
;
7073 ret
= wpa_drv_signal_poll(wpa_s
, &si
);
7080 ret
= os_snprintf(pos
, end
- pos
, "RSSI=%d\nLINKSPEED=%d\n"
7081 "NOISE=%d\nFREQUENCY=%u\n",
7082 si
.current_signal
, si
.current_txrate
/ 1000,
7083 si
.current_noise
, si
.frequency
);
7084 if (os_snprintf_error(end
- pos
, ret
))
7088 if (si
.chanwidth
!= CHAN_WIDTH_UNKNOWN
) {
7089 ret
= os_snprintf(pos
, end
- pos
, "WIDTH=%s\n",
7090 channel_width_to_string(si
.chanwidth
));
7091 if (os_snprintf_error(end
- pos
, ret
))
7096 if (si
.center_frq1
> 0 && si
.center_frq2
> 0) {
7097 ret
= os_snprintf(pos
, end
- pos
,
7098 "CENTER_FRQ1=%d\nCENTER_FRQ2=%d\n",
7099 si
.center_frq1
, si
.center_frq2
);
7100 if (os_snprintf_error(end
- pos
, ret
))
7105 if (si
.avg_signal
) {
7106 ret
= os_snprintf(pos
, end
- pos
,
7107 "AVG_RSSI=%d\n", si
.avg_signal
);
7108 if (os_snprintf_error(end
- pos
, ret
))
7113 if (si
.avg_beacon_signal
) {
7114 ret
= os_snprintf(pos
, end
- pos
,
7115 "AVG_BEACON_RSSI=%d\n", si
.avg_beacon_signal
);
7116 if (os_snprintf_error(end
- pos
, ret
))
7125 static int wpas_ctrl_iface_signal_monitor(struct wpa_supplicant
*wpa_s
,
7132 if (wpa_s
->bgscan
&& wpa_s
->bgscan_priv
) {
7133 wpa_printf(MSG_DEBUG
,
7134 "Reject SIGNAL_MONITOR command - bgscan is active");
7137 pos
= os_strstr(cmd
, "THRESHOLD=");
7139 threshold
= atoi(pos
+ 10);
7140 pos
= os_strstr(cmd
, "HYSTERESIS=");
7142 hysteresis
= atoi(pos
+ 11);
7143 return wpa_drv_signal_monitor(wpa_s
, threshold
, hysteresis
);
7147 static int wpas_ctrl_iface_get_pref_freq_list(
7148 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
7150 unsigned int freq_list
[100], num
= 100, i
;
7152 enum wpa_driver_if_type iface_type
;
7158 /* buf: "<interface_type>" */
7159 if (os_strcmp(cmd
, "STATION") == 0)
7160 iface_type
= WPA_IF_STATION
;
7161 else if (os_strcmp(cmd
, "AP") == 0)
7162 iface_type
= WPA_IF_AP_BSS
;
7163 else if (os_strcmp(cmd
, "P2P_GO") == 0)
7164 iface_type
= WPA_IF_P2P_GO
;
7165 else if (os_strcmp(cmd
, "P2P_CLIENT") == 0)
7166 iface_type
= WPA_IF_P2P_CLIENT
;
7167 else if (os_strcmp(cmd
, "IBSS") == 0)
7168 iface_type
= WPA_IF_IBSS
;
7169 else if (os_strcmp(cmd
, "TDLS") == 0)
7170 iface_type
= WPA_IF_TDLS
;
7174 wpa_printf(MSG_DEBUG
,
7175 "CTRL_IFACE: GET_PREF_FREQ_LIST iface_type=%d (%s)",
7178 ret
= wpa_drv_get_pref_freq_list(wpa_s
, iface_type
, &num
, freq_list
);
7182 for (i
= 0; i
< num
; i
++) {
7183 ret
= os_snprintf(pos
, end
- pos
, "%s%u",
7184 i
> 0 ? "," : "", freq_list
[i
]);
7185 if (os_snprintf_error(end
- pos
, ret
))
7194 static int wpas_ctrl_iface_driver_flags(struct wpa_supplicant
*wpa_s
,
7195 char *buf
, size_t buflen
)
7200 ret
= os_snprintf(buf
, buflen
, "%016llX:\n",
7201 (long long unsigned) wpa_s
->drv_flags
);
7202 if (os_snprintf_error(buflen
, ret
))
7208 for (i
= 0; i
< 64; i
++) {
7209 if (wpa_s
->drv_flags
& (1LLU << i
)) {
7210 ret
= os_snprintf(pos
, end
- pos
, "%s\n",
7211 driver_flag_to_string(1LLU << i
));
7212 if (os_snprintf_error(end
- pos
, ret
))
7222 static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant
*wpa_s
, char *buf
,
7225 struct hostap_sta_driver_data sta
;
7228 ret
= wpa_drv_pktcnt_poll(wpa_s
, &sta
);
7232 ret
= os_snprintf(buf
, buflen
, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
7233 sta
.tx_packets
, sta
.tx_retry_failed
, sta
.rx_packets
);
7234 if (os_snprintf_error(buflen
, ret
))
7241 static int wpa_supplicant_driver_cmd(struct wpa_supplicant
*wpa_s
, char *cmd
,
7242 char *buf
, size_t buflen
)
7246 ret
= wpa_drv_driver_cmd(wpa_s
, cmd
, buf
, buflen
);
7248 if (os_strncasecmp(cmd
, "COUNTRY", 7) == 0) {
7249 struct p2p_data
*p2p
= wpa_s
->global
->p2p
;
7252 country
[0] = cmd
[8];
7253 country
[1] = cmd
[9];
7255 p2p_set_country(p2p
, country
);
7258 ret
= os_snprintf(buf
, buflen
, "%s\n", "OK");
7259 if (os_snprintf_error(buflen
, ret
))
7264 #endif /* ANDROID */
7267 static int wpa_supplicant_vendor_cmd(struct wpa_supplicant
*wpa_s
, char *cmd
,
7268 char *buf
, size_t buflen
)
7273 unsigned int vendor_id
, subcmd
;
7274 struct wpabuf
*reply
;
7275 size_t data_len
= 0;
7277 /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */
7278 vendor_id
= strtoul(cmd
, &pos
, 16);
7279 if (!isblank((unsigned char) *pos
))
7282 subcmd
= strtoul(pos
, &pos
, 10);
7285 if (!isblank((unsigned char) *pos
++))
7287 data_len
= os_strlen(pos
);
7292 data
= os_malloc(data_len
);
7296 if (hexstr2bin(pos
, data
, data_len
)) {
7297 wpa_printf(MSG_DEBUG
,
7298 "Vendor command: wrong parameter format");
7304 reply
= wpabuf_alloc((buflen
- 1) / 2);
7310 ret
= wpa_drv_vendor_cmd(wpa_s
, vendor_id
, subcmd
, data
, data_len
,
7314 ret
= wpa_snprintf_hex(buf
, buflen
, wpabuf_head_u8(reply
),
7324 static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant
*wpa_s
)
7327 struct wpa_supplicant
*p2p_wpa_s
= wpa_s
->global
->p2p_init_wpa_s
?
7328 wpa_s
->global
->p2p_init_wpa_s
: wpa_s
;
7329 #endif /* CONFIG_P2P */
7331 wpa_dbg(wpa_s
, MSG_DEBUG
, "Flush all wpa_supplicant state");
7333 if (wpas_abort_ongoing_scan(wpa_s
) == 0)
7334 wpa_s
->ignore_post_flush_scan_res
= 1;
7336 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
7338 * Avoid possible auto connect re-connection on getting
7339 * disconnected due to state flush.
7341 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
7345 wpas_p2p_group_remove(p2p_wpa_s
, "*");
7346 wpas_p2p_cancel(p2p_wpa_s
);
7347 p2p_ctrl_flush(p2p_wpa_s
);
7348 wpas_p2p_service_flush(p2p_wpa_s
);
7349 p2p_wpa_s
->global
->p2p_disabled
= 0;
7350 p2p_wpa_s
->global
->p2p_per_sta_psk
= 0;
7351 p2p_wpa_s
->conf
->num_sec_device_types
= 0;
7352 p2p_wpa_s
->p2p_disable_ip_addr_req
= 0;
7353 os_free(p2p_wpa_s
->global
->p2p_go_avoid_freq
.range
);
7354 p2p_wpa_s
->global
->p2p_go_avoid_freq
.range
= NULL
;
7355 p2p_wpa_s
->global
->p2p_go_avoid_freq
.num
= 0;
7356 p2p_wpa_s
->global
->pending_p2ps_group
= 0;
7357 p2p_wpa_s
->global
->pending_p2ps_group_freq
= 0;
7358 #endif /* CONFIG_P2P */
7360 #ifdef CONFIG_WPS_TESTING
7361 wps_version_number
= 0x20;
7362 wps_testing_dummy_cred
= 0;
7363 wps_corrupt_pkhash
= 0;
7364 wps_force_auth_types_in_use
= 0;
7365 wps_force_encr_types_in_use
= 0;
7366 #endif /* CONFIG_WPS_TESTING */
7368 wpa_s
->wps_fragment_size
= 0;
7369 wpas_wps_cancel(wpa_s
);
7370 wps_registrar_flush(wpa_s
->wps
->registrar
);
7371 #endif /* CONFIG_WPS */
7372 wpa_s
->after_wps
= 0;
7373 wpa_s
->known_wps_freq
= 0;
7376 #ifdef CONFIG_TDLS_TESTING
7378 #endif /* CONFIG_TDLS_TESTING */
7379 wpa_drv_tdls_oper(wpa_s
, TDLS_ENABLE
, NULL
);
7380 wpa_tdls_enable(wpa_s
->wpa
, 1);
7381 #endif /* CONFIG_TDLS */
7383 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures
, wpa_s
, NULL
);
7384 wpa_supplicant_stop_countermeasures(wpa_s
, NULL
);
7386 wpa_s
->no_keep_alive
= 0;
7387 wpa_s
->own_disconnect_req
= 0;
7389 os_free(wpa_s
->disallow_aps_bssid
);
7390 wpa_s
->disallow_aps_bssid
= NULL
;
7391 wpa_s
->disallow_aps_bssid_count
= 0;
7392 os_free(wpa_s
->disallow_aps_ssid
);
7393 wpa_s
->disallow_aps_ssid
= NULL
;
7394 wpa_s
->disallow_aps_ssid_count
= 0;
7396 wpa_s
->set_sta_uapsd
= 0;
7397 wpa_s
->sta_uapsd
= 0;
7399 wpa_drv_radio_disable(wpa_s
, 0);
7400 wpa_blacklist_clear(wpa_s
);
7401 wpa_s
->extra_blacklist_count
= 0;
7402 wpa_supplicant_ctrl_iface_remove_network(wpa_s
, "all");
7403 wpa_supplicant_ctrl_iface_remove_cred(wpa_s
, "all");
7404 wpa_config_flush_blobs(wpa_s
->conf
);
7405 wpa_s
->conf
->auto_interworking
= 0;
7406 wpa_s
->conf
->okc
= 0;
7408 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, NULL
);
7409 rsn_preauth_deinit(wpa_s
->wpa
);
7411 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_LIFETIME
, 43200);
7412 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_REAUTH_THRESHOLD
, 70);
7413 wpa_sm_set_param(wpa_s
->wpa
, RSNA_SA_TIMEOUT
, 60);
7414 eapol_sm_notify_logoff(wpa_s
->eapol
, FALSE
);
7416 radio_remove_works(wpa_s
, NULL
, 1);
7417 wpa_s
->ext_work_in_progress
= 0;
7419 wpa_s
->next_ssid
= NULL
;
7421 #ifdef CONFIG_INTERWORKING
7423 hs20_cancel_fetch_osu(wpa_s
);
7424 hs20_del_icon(wpa_s
, NULL
, NULL
);
7425 #endif /* CONFIG_HS20 */
7426 #endif /* CONFIG_INTERWORKING */
7428 wpa_s
->ext_mgmt_frame_handling
= 0;
7429 wpa_s
->ext_eapol_frame_io
= 0;
7430 #ifdef CONFIG_TESTING_OPTIONS
7431 wpa_s
->extra_roc_dur
= 0;
7432 wpa_s
->test_failure
= WPAS_TEST_FAILURE_NONE
;
7433 wpa_s
->p2p_go_csa_on_inv
= 0;
7434 wpa_s
->ignore_auth_resp
= 0;
7435 wpa_s
->ignore_assoc_disallow
= 0;
7436 wpa_s
->reject_btm_req_reason
= 0;
7437 wpa_sm_set_test_assoc_ie(wpa_s
->wpa
, NULL
);
7438 #endif /* CONFIG_TESTING_OPTIONS */
7440 wpa_s
->disconnected
= 0;
7441 os_free(wpa_s
->next_scan_freqs
);
7442 wpa_s
->next_scan_freqs
= NULL
;
7444 wpa_bss_flush(wpa_s
);
7445 if (!dl_list_empty(&wpa_s
->bss
)) {
7446 wpa_printf(MSG_DEBUG
,
7447 "BSS table not empty after flush: %u entries, current_bss=%p bssid="
7448 MACSTR
" pending_bssid=" MACSTR
,
7449 dl_list_len(&wpa_s
->bss
), wpa_s
->current_bss
,
7450 MAC2STR(wpa_s
->bssid
),
7451 MAC2STR(wpa_s
->pending_bssid
));
7454 eloop_cancel_timeout(wpas_network_reenabled
, wpa_s
, NULL
);
7455 wpa_s
->wnmsleep_used
= 0;
7458 wpa_s
->sme
.last_unprot_disconnect
.sec
= 0;
7459 #endif /* CONFIG_SME */
7463 static int wpas_ctrl_radio_work_show(struct wpa_supplicant
*wpa_s
,
7464 char *buf
, size_t buflen
)
7466 struct wpa_radio_work
*work
;
7468 struct os_reltime now
, diff
;
7473 os_get_reltime(&now
);
7475 dl_list_for_each(work
, &wpa_s
->radio
->work
, struct wpa_radio_work
, list
)
7479 os_reltime_sub(&now
, &work
->time
, &diff
);
7480 ret
= os_snprintf(pos
, end
- pos
, "%s@%s:%u:%u:%ld.%06ld\n",
7481 work
->type
, work
->wpa_s
->ifname
, work
->freq
,
7482 work
->started
, diff
.sec
, diff
.usec
);
7483 if (os_snprintf_error(end
- pos
, ret
))
7492 static void wpas_ctrl_radio_work_timeout(void *eloop_ctx
, void *timeout_ctx
)
7494 struct wpa_radio_work
*work
= eloop_ctx
;
7495 struct wpa_external_work
*ework
= work
->ctx
;
7497 wpa_dbg(work
->wpa_s
, MSG_DEBUG
,
7498 "Timing out external radio work %u (%s)",
7499 ework
->id
, work
->type
);
7500 wpa_msg(work
->wpa_s
, MSG_INFO
, EXT_RADIO_WORK_TIMEOUT
"%u", ework
->id
);
7501 work
->wpa_s
->ext_work_in_progress
= 0;
7502 radio_work_done(work
);
7507 static void wpas_ctrl_radio_work_cb(struct wpa_radio_work
*work
, int deinit
)
7509 struct wpa_external_work
*ework
= work
->ctx
;
7513 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
,
7517 * work->type points to a buffer in ework, so need to replace
7518 * that here with a fixed string to avoid use of freed memory
7521 work
->type
= "freed-ext-work";
7527 wpa_dbg(work
->wpa_s
, MSG_DEBUG
, "Starting external radio work %u (%s)",
7528 ework
->id
, ework
->type
);
7529 wpa_msg(work
->wpa_s
, MSG_INFO
, EXT_RADIO_WORK_START
"%u", ework
->id
);
7530 work
->wpa_s
->ext_work_in_progress
= 1;
7531 if (!ework
->timeout
)
7532 ework
->timeout
= 10;
7533 eloop_register_timeout(ework
->timeout
, 0, wpas_ctrl_radio_work_timeout
,
7538 static int wpas_ctrl_radio_work_add(struct wpa_supplicant
*wpa_s
, char *cmd
,
7539 char *buf
, size_t buflen
)
7541 struct wpa_external_work
*ework
;
7545 unsigned int freq
= 0;
7547 /* format: <name> [freq=<MHz>] [timeout=<seconds>] */
7549 ework
= os_zalloc(sizeof(*ework
));
7553 pos
= os_strchr(cmd
, ' ');
7555 type_len
= pos
- cmd
;
7558 pos2
= os_strstr(pos
, "freq=");
7560 freq
= atoi(pos2
+ 5);
7562 pos2
= os_strstr(pos
, "timeout=");
7564 ework
->timeout
= atoi(pos2
+ 8);
7566 type_len
= os_strlen(cmd
);
7568 if (4 + type_len
>= sizeof(ework
->type
))
7569 type_len
= sizeof(ework
->type
) - 4 - 1;
7570 os_strlcpy(ework
->type
, "ext:", sizeof(ework
->type
));
7571 os_memcpy(ework
->type
+ 4, cmd
, type_len
);
7572 ework
->type
[4 + type_len
] = '\0';
7574 wpa_s
->ext_work_id
++;
7575 if (wpa_s
->ext_work_id
== 0)
7576 wpa_s
->ext_work_id
++;
7577 ework
->id
= wpa_s
->ext_work_id
;
7579 if (radio_add_work(wpa_s
, freq
, ework
->type
, 0, wpas_ctrl_radio_work_cb
,
7585 ret
= os_snprintf(buf
, buflen
, "%u", ework
->id
);
7586 if (os_snprintf_error(buflen
, ret
))
7592 static int wpas_ctrl_radio_work_done(struct wpa_supplicant
*wpa_s
, char *cmd
)
7594 struct wpa_radio_work
*work
;
7595 unsigned int id
= atoi(cmd
);
7597 dl_list_for_each(work
, &wpa_s
->radio
->work
, struct wpa_radio_work
, list
)
7599 struct wpa_external_work
*ework
;
7601 if (os_strncmp(work
->type
, "ext:", 4) != 0)
7604 if (id
&& ework
->id
!= id
)
7606 wpa_dbg(wpa_s
, MSG_DEBUG
,
7607 "Completed external radio work %u (%s)",
7608 ework
->id
, ework
->type
);
7609 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
, work
, NULL
);
7610 wpa_s
->ext_work_in_progress
= 0;
7611 radio_work_done(work
);
7613 return 3; /* "OK\n" */
7620 static int wpas_ctrl_radio_work(struct wpa_supplicant
*wpa_s
, char *cmd
,
7621 char *buf
, size_t buflen
)
7623 if (os_strcmp(cmd
, "show") == 0)
7624 return wpas_ctrl_radio_work_show(wpa_s
, buf
, buflen
);
7625 if (os_strncmp(cmd
, "add ", 4) == 0)
7626 return wpas_ctrl_radio_work_add(wpa_s
, cmd
+ 4, buf
, buflen
);
7627 if (os_strncmp(cmd
, "done ", 5) == 0)
7628 return wpas_ctrl_radio_work_done(wpa_s
, cmd
+ 4);
7633 void wpas_ctrl_radio_work_flush(struct wpa_supplicant
*wpa_s
)
7635 struct wpa_radio_work
*work
, *tmp
;
7637 if (!wpa_s
|| !wpa_s
->radio
)
7640 dl_list_for_each_safe(work
, tmp
, &wpa_s
->radio
->work
,
7641 struct wpa_radio_work
, list
) {
7642 struct wpa_external_work
*ework
;
7644 if (os_strncmp(work
->type
, "ext:", 4) != 0)
7647 wpa_dbg(wpa_s
, MSG_DEBUG
,
7648 "Flushing%s external radio work %u (%s)",
7649 work
->started
? " started" : "", ework
->id
,
7652 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
,
7654 radio_work_done(work
);
7660 static void wpas_ctrl_eapol_response(void *eloop_ctx
, void *timeout_ctx
)
7662 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
7663 eapol_sm_notify_ctrl_response(wpa_s
->eapol
);
7667 static int scan_id_list_parse(struct wpa_supplicant
*wpa_s
, const char *value
,
7668 unsigned int *scan_id_count
, int scan_id
[])
7670 const char *pos
= value
;
7673 if (*pos
== ' ' || *pos
== '\0')
7675 if (*scan_id_count
== MAX_SCAN_ID
)
7677 scan_id
[(*scan_id_count
)++] = atoi(pos
);
7678 pos
= os_strchr(pos
, ',');
7687 static void wpas_ctrl_scan(struct wpa_supplicant
*wpa_s
, char *params
,
7688 char *reply
, int reply_size
, int *reply_len
)
7691 unsigned int manual_scan_passive
= 0;
7692 unsigned int manual_scan_use_id
= 0;
7693 unsigned int manual_scan_only_new
= 0;
7694 unsigned int scan_only
= 0;
7695 unsigned int scan_id_count
= 0;
7696 int scan_id
[MAX_SCAN_ID
];
7697 void (*scan_res_handler
)(struct wpa_supplicant
*wpa_s
,
7698 struct wpa_scan_results
*scan_res
);
7699 int *manual_scan_freqs
= NULL
;
7700 struct wpa_ssid_value
*ssid
= NULL
, *ns
;
7701 unsigned int ssid_count
= 0;
7703 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
7708 if (radio_work_pending(wpa_s
, "scan")) {
7709 wpa_printf(MSG_DEBUG
,
7710 "Pending scan scheduled - reject new request");
7711 *reply_len
= os_snprintf(reply
, reply_size
, "FAIL-BUSY\n");
7715 #ifdef CONFIG_INTERWORKING
7716 if (wpa_s
->fetch_anqp_in_progress
|| wpa_s
->network_select
) {
7717 wpa_printf(MSG_DEBUG
,
7718 "Interworking select in progress - reject new scan");
7719 *reply_len
= os_snprintf(reply
, reply_size
, "FAIL-BUSY\n");
7722 #endif /* CONFIG_INTERWORKING */
7725 if (os_strncasecmp(params
, "TYPE=ONLY", 9) == 0)
7728 pos
= os_strstr(params
, "freq=");
7730 manual_scan_freqs
= freq_range_to_channel_list(wpa_s
,
7732 if (manual_scan_freqs
== NULL
) {
7738 pos
= os_strstr(params
, "passive=");
7740 manual_scan_passive
= !!atoi(pos
+ 8);
7742 pos
= os_strstr(params
, "use_id=");
7744 manual_scan_use_id
= atoi(pos
+ 7);
7746 pos
= os_strstr(params
, "only_new=1");
7748 manual_scan_only_new
= 1;
7750 pos
= os_strstr(params
, "scan_id=");
7751 if (pos
&& scan_id_list_parse(wpa_s
, pos
+ 8, &scan_id_count
,
7758 while (pos
&& *pos
!= '\0') {
7759 if (os_strncmp(pos
, "ssid ", 5) == 0) {
7765 if (*end
== '\0' || *end
== ' ')
7770 ns
= os_realloc_array(
7771 ssid
, ssid_count
+ 1,
7772 sizeof(struct wpa_ssid_value
));
7779 if ((end
- pos
) & 0x01 ||
7780 end
- pos
> 2 * SSID_MAX_LEN
||
7781 hexstr2bin(pos
, ssid
[ssid_count
].ssid
,
7782 (end
- pos
) / 2) < 0) {
7783 wpa_printf(MSG_DEBUG
,
7784 "Invalid SSID value '%s'",
7789 ssid
[ssid_count
].ssid_len
= (end
- pos
) / 2;
7790 wpa_hexdump_ascii(MSG_DEBUG
, "scan SSID",
7791 ssid
[ssid_count
].ssid
,
7792 ssid
[ssid_count
].ssid_len
);
7797 pos
= os_strchr(pos
, ' ');
7803 wpa_s
->num_ssids_from_scan_req
= ssid_count
;
7804 os_free(wpa_s
->ssids_from_scan_req
);
7806 wpa_s
->ssids_from_scan_req
= ssid
;
7809 wpa_s
->ssids_from_scan_req
= NULL
;
7813 scan_res_handler
= scan_only_handler
;
7814 else if (wpa_s
->scan_res_handler
== scan_only_handler
)
7815 scan_res_handler
= NULL
;
7817 scan_res_handler
= wpa_s
->scan_res_handler
;
7819 if (!wpa_s
->sched_scanning
&& !wpa_s
->scanning
&&
7820 ((wpa_s
->wpa_state
<= WPA_SCANNING
) ||
7821 (wpa_s
->wpa_state
== WPA_COMPLETED
))) {
7822 wpa_s
->manual_scan_passive
= manual_scan_passive
;
7823 wpa_s
->manual_scan_use_id
= manual_scan_use_id
;
7824 wpa_s
->manual_scan_only_new
= manual_scan_only_new
;
7825 wpa_s
->scan_id_count
= scan_id_count
;
7826 os_memcpy(wpa_s
->scan_id
, scan_id
, scan_id_count
* sizeof(int));
7827 wpa_s
->scan_res_handler
= scan_res_handler
;
7828 os_free(wpa_s
->manual_scan_freqs
);
7829 wpa_s
->manual_scan_freqs
= manual_scan_freqs
;
7830 manual_scan_freqs
= NULL
;
7832 wpa_s
->normal_scans
= 0;
7833 wpa_s
->scan_req
= MANUAL_SCAN_REQ
;
7834 wpa_s
->after_wps
= 0;
7835 wpa_s
->known_wps_freq
= 0;
7836 wpa_supplicant_req_scan(wpa_s
, 0, 0);
7837 if (wpa_s
->manual_scan_use_id
) {
7838 wpa_s
->manual_scan_id
++;
7839 wpa_dbg(wpa_s
, MSG_DEBUG
, "Assigned scan id %u",
7840 wpa_s
->manual_scan_id
);
7841 *reply_len
= os_snprintf(reply
, reply_size
, "%u\n",
7842 wpa_s
->manual_scan_id
);
7844 } else if (wpa_s
->sched_scanning
) {
7845 wpa_s
->manual_scan_passive
= manual_scan_passive
;
7846 wpa_s
->manual_scan_use_id
= manual_scan_use_id
;
7847 wpa_s
->manual_scan_only_new
= manual_scan_only_new
;
7848 wpa_s
->scan_id_count
= scan_id_count
;
7849 os_memcpy(wpa_s
->scan_id
, scan_id
, scan_id_count
* sizeof(int));
7850 wpa_s
->scan_res_handler
= scan_res_handler
;
7851 os_free(wpa_s
->manual_scan_freqs
);
7852 wpa_s
->manual_scan_freqs
= manual_scan_freqs
;
7853 manual_scan_freqs
= NULL
;
7855 wpa_printf(MSG_DEBUG
, "Stop ongoing sched_scan to allow requested full scan to proceed");
7856 wpa_supplicant_cancel_sched_scan(wpa_s
);
7857 wpa_s
->scan_req
= MANUAL_SCAN_REQ
;
7858 wpa_supplicant_req_scan(wpa_s
, 0, 0);
7859 if (wpa_s
->manual_scan_use_id
) {
7860 wpa_s
->manual_scan_id
++;
7861 *reply_len
= os_snprintf(reply
, reply_size
, "%u\n",
7862 wpa_s
->manual_scan_id
);
7863 wpa_dbg(wpa_s
, MSG_DEBUG
, "Assigned scan id %u",
7864 wpa_s
->manual_scan_id
);
7867 wpa_printf(MSG_DEBUG
, "Ongoing scan action - reject new request");
7868 *reply_len
= os_snprintf(reply
, reply_size
, "FAIL-BUSY\n");
7872 os_free(manual_scan_freqs
);
7877 #ifdef CONFIG_TESTING_OPTIONS
7879 static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant
*wpa_s
,
7880 unsigned int freq
, const u8
*dst
,
7881 const u8
*src
, const u8
*bssid
,
7882 const u8
*data
, size_t data_len
,
7883 enum offchannel_send_action_result
7886 wpa_msg(wpa_s
, MSG_INFO
, "MGMT-TX-STATUS freq=%u dst=" MACSTR
7887 " src=" MACSTR
" bssid=" MACSTR
" result=%s",
7888 freq
, MAC2STR(dst
), MAC2STR(src
), MAC2STR(bssid
),
7889 result
== OFFCHANNEL_SEND_ACTION_SUCCESS
?
7890 "SUCCESS" : (result
== OFFCHANNEL_SEND_ACTION_NO_ACK
?
7891 "NO_ACK" : "FAILED"));
7895 static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant
*wpa_s
, char *cmd
)
7899 u8
*buf
, da
[ETH_ALEN
], bssid
[ETH_ALEN
];
7901 int freq
= 0, no_cck
= 0, wait_time
= 0;
7903 /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1]
7904 * <action=Action frame payload> */
7906 wpa_printf(MSG_DEBUG
, "External MGMT TX: %s", cmd
);
7909 used
= hwaddr_aton2(pos
, da
);
7915 used
= hwaddr_aton2(pos
, bssid
);
7920 param
= os_strstr(pos
, " freq=");
7926 param
= os_strstr(pos
, " no_cck=");
7929 no_cck
= atoi(param
);
7932 param
= os_strstr(pos
, " wait_time=");
7935 wait_time
= atoi(param
);
7938 param
= os_strstr(pos
, " action=");
7943 len
= os_strlen(param
);
7948 buf
= os_malloc(len
);
7952 if (hexstr2bin(param
, buf
, len
) < 0) {
7957 res
= offchannel_send_action(wpa_s
, freq
, da
, wpa_s
->own_addr
, bssid
,
7958 buf
, len
, wait_time
,
7959 wpas_ctrl_iface_mgmt_tx_cb
, no_cck
);
7965 static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant
*wpa_s
)
7967 wpa_printf(MSG_DEBUG
, "External MGMT TX - done waiting");
7968 offchannel_send_action_done(wpa_s
);
7972 static int wpas_ctrl_iface_mgmt_rx_process(struct wpa_supplicant
*wpa_s
,
7978 int freq
= 0, datarate
= 0, ssi_signal
= 0;
7979 union wpa_event_data event
;
7981 if (!wpa_s
->ext_mgmt_frame_handling
)
7984 /* freq=<MHz> datarate=<val> ssi_signal=<val> frame=<frame hexdump> */
7986 wpa_printf(MSG_DEBUG
, "External MGMT RX process: %s", cmd
);
7989 param
= os_strstr(pos
, "freq=");
7995 param
= os_strstr(pos
, " datarate=");
7998 datarate
= atoi(param
);
8001 param
= os_strstr(pos
, " ssi_signal=");
8004 ssi_signal
= atoi(param
);
8007 param
= os_strstr(pos
, " frame=");
8012 len
= os_strlen(param
);
8017 buf
= os_malloc(len
);
8021 if (hexstr2bin(param
, buf
, len
) < 0) {
8026 os_memset(&event
, 0, sizeof(event
));
8027 event
.rx_mgmt
.freq
= freq
;
8028 event
.rx_mgmt
.frame
= buf
;
8029 event
.rx_mgmt
.frame_len
= len
;
8030 event
.rx_mgmt
.ssi_signal
= ssi_signal
;
8031 event
.rx_mgmt
.datarate
= datarate
;
8032 wpa_s
->ext_mgmt_frame_handling
= 0;
8033 wpa_supplicant_event(wpa_s
, EVENT_RX_MGMT
, &event
);
8034 wpa_s
->ext_mgmt_frame_handling
= 1;
8042 static int wpas_ctrl_iface_driver_scan_res(struct wpa_supplicant
*wpa_s
,
8045 struct wpa_scan_res
*res
;
8046 struct os_reltime now
;
8053 if (os_strcmp(param
, "START") == 0) {
8054 wpa_bss_update_start(wpa_s
);
8058 if (os_strcmp(param
, "END") == 0) {
8059 wpa_bss_update_end(wpa_s
, NULL
, 1);
8063 if (os_strncmp(param
, "BSS ", 4) != 0)
8067 res
= os_zalloc(sizeof(*res
) + os_strlen(param
) / 2);
8071 pos
= os_strstr(param
, " flags=");
8073 res
->flags
= strtol(pos
+ 7, NULL
, 16);
8075 pos
= os_strstr(param
, " bssid=");
8076 if (pos
&& hwaddr_aton(pos
+ 7, res
->bssid
))
8079 pos
= os_strstr(param
, " freq=");
8081 res
->freq
= atoi(pos
+ 6);
8083 pos
= os_strstr(param
, " beacon_int=");
8085 res
->beacon_int
= atoi(pos
+ 12);
8087 pos
= os_strstr(param
, " caps=");
8089 res
->caps
= strtol(pos
+ 6, NULL
, 16);
8091 pos
= os_strstr(param
, " qual=");
8093 res
->qual
= atoi(pos
+ 6);
8095 pos
= os_strstr(param
, " noise=");
8097 res
->noise
= atoi(pos
+ 7);
8099 pos
= os_strstr(param
, " level=");
8101 res
->level
= atoi(pos
+ 7);
8103 pos
= os_strstr(param
, " tsf=");
8105 res
->tsf
= strtoll(pos
+ 5, NULL
, 16);
8107 pos
= os_strstr(param
, " age=");
8109 res
->age
= atoi(pos
+ 5);
8111 pos
= os_strstr(param
, " est_throughput=");
8113 res
->est_throughput
= atoi(pos
+ 16);
8115 pos
= os_strstr(param
, " snr=");
8117 res
->snr
= atoi(pos
+ 5);
8119 pos
= os_strstr(param
, " parent_tsf=");
8121 res
->parent_tsf
= strtoll(pos
+ 7, NULL
, 16);
8123 pos
= os_strstr(param
, " tsf_bssid=");
8124 if (pos
&& hwaddr_aton(pos
+ 11, res
->tsf_bssid
))
8127 pos
= os_strstr(param
, " ie=");
8130 end
= os_strchr(pos
, ' ');
8132 end
= pos
+ os_strlen(pos
);
8133 res
->ie_len
= (end
- pos
) / 2;
8134 if (hexstr2bin(pos
, (u8
*) (res
+ 1), res
->ie_len
))
8138 pos
= os_strstr(param
, " beacon_ie=");
8141 end
= os_strchr(pos
, ' ');
8143 end
= pos
+ os_strlen(pos
);
8144 res
->beacon_ie_len
= (end
- pos
) / 2;
8145 if (hexstr2bin(pos
, ((u8
*) (res
+ 1)) + res
->ie_len
,
8146 res
->beacon_ie_len
))
8150 os_get_reltime(&now
);
8151 wpa_bss_update_scan_res(wpa_s
, res
, &now
);
8160 static int wpas_ctrl_iface_driver_event(struct wpa_supplicant
*wpa_s
, char *cmd
)
8163 union wpa_event_data event
;
8164 enum wpa_event_type ev
;
8166 /* <event name> [parameters..] */
8168 wpa_dbg(wpa_s
, MSG_DEBUG
, "Testing - external driver event: %s", cmd
);
8171 param
= os_strchr(pos
, ' ');
8175 os_memset(&event
, 0, sizeof(event
));
8177 if (os_strcmp(cmd
, "INTERFACE_ENABLED") == 0) {
8178 ev
= EVENT_INTERFACE_ENABLED
;
8179 } else if (os_strcmp(cmd
, "INTERFACE_DISABLED") == 0) {
8180 ev
= EVENT_INTERFACE_DISABLED
;
8181 } else if (os_strcmp(cmd
, "AVOID_FREQUENCIES") == 0) {
8182 ev
= EVENT_AVOID_FREQUENCIES
;
8185 if (freq_range_list_parse(&event
.freq_range
, param
) < 0)
8187 wpa_supplicant_event(wpa_s
, ev
, &event
);
8188 os_free(event
.freq_range
.range
);
8190 } else if (os_strcmp(cmd
, "SCAN_RES") == 0) {
8191 return wpas_ctrl_iface_driver_scan_res(wpa_s
, param
);
8193 wpa_dbg(wpa_s
, MSG_DEBUG
, "Testing - unknown driver event: %s",
8198 wpa_supplicant_event(wpa_s
, ev
, &event
);
8204 static int wpas_ctrl_iface_eapol_rx(struct wpa_supplicant
*wpa_s
, char *cmd
)
8207 u8 src
[ETH_ALEN
], *buf
;
8211 wpa_printf(MSG_DEBUG
, "External EAPOL RX: %s", cmd
);
8214 used
= hwaddr_aton2(pos
, src
);
8221 len
= os_strlen(pos
);
8226 buf
= os_malloc(len
);
8230 if (hexstr2bin(pos
, buf
, len
) < 0) {
8235 wpa_supplicant_rx_eapol(wpa_s
, src
, buf
, len
);
8242 static u16
ipv4_hdr_checksum(const void *buf
, size_t len
)
8246 const u16
*pos
= buf
;
8248 for (i
= 0; i
< len
/ 2; i
++)
8252 sum
= (sum
& 0xffff) + (sum
>> 16);
8254 return sum
^ 0xffff;
8258 #define HWSIM_PACKETLEN 1500
8259 #define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header))
8261 static void wpas_data_test_rx(void *ctx
, const u8
*src_addr
, const u8
*buf
,
8264 struct wpa_supplicant
*wpa_s
= ctx
;
8265 const struct ether_header
*eth
;
8270 if (len
!= HWSIM_PACKETLEN
)
8273 eth
= (const struct ether_header
*) buf
;
8274 os_memcpy(&ip
, eth
+ 1, sizeof(ip
));
8275 pos
= &buf
[sizeof(*eth
) + sizeof(ip
)];
8277 if (ip
.ihl
!= 5 || ip
.version
!= 4 ||
8278 ntohs(ip
.tot_len
) != HWSIM_IP_LEN
)
8281 for (i
= 0; i
< HWSIM_IP_LEN
- sizeof(ip
); i
++) {
8287 wpa_msg(wpa_s
, MSG_INFO
, "DATA-TEST-RX " MACSTR
" " MACSTR
,
8288 MAC2STR(eth
->ether_dhost
), MAC2STR(eth
->ether_shost
));
8292 static int wpas_ctrl_iface_data_test_config(struct wpa_supplicant
*wpa_s
,
8295 int enabled
= atoi(cmd
);
8300 if (wpa_s
->l2_test
) {
8301 l2_packet_deinit(wpa_s
->l2_test
);
8302 wpa_s
->l2_test
= NULL
;
8303 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: Disabled");
8311 pos
= os_strstr(cmd
, " ifname=");
8315 ifname
= wpa_s
->ifname
;
8317 wpa_s
->l2_test
= l2_packet_init(ifname
, wpa_s
->own_addr
,
8318 ETHERTYPE_IP
, wpas_data_test_rx
,
8320 if (wpa_s
->l2_test
== NULL
)
8323 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: Enabled");
8329 static int wpas_ctrl_iface_data_test_tx(struct wpa_supplicant
*wpa_s
, char *cmd
)
8331 u8 dst
[ETH_ALEN
], src
[ETH_ALEN
];
8336 u8 buf
[2 + HWSIM_PACKETLEN
];
8337 struct ether_header
*eth
;
8342 if (wpa_s
->l2_test
== NULL
)
8345 /* format: <dst> <src> <tos> */
8348 used
= hwaddr_aton2(pos
, dst
);
8354 used
= hwaddr_aton2(pos
, src
);
8359 val
= strtol(pos
, NULL
, 0);
8360 if (val
< 0 || val
> 0xff)
8364 eth
= (struct ether_header
*) &buf
[2];
8365 os_memcpy(eth
->ether_dhost
, dst
, ETH_ALEN
);
8366 os_memcpy(eth
->ether_shost
, src
, ETH_ALEN
);
8367 eth
->ether_type
= htons(ETHERTYPE_IP
);
8368 ip
= (struct iphdr
*) (eth
+ 1);
8369 os_memset(ip
, 0, sizeof(*ip
));
8374 ip
->tot_len
= htons(HWSIM_IP_LEN
);
8376 ip
->saddr
= htonl(192U << 24 | 168 << 16 | 1 << 8 | 1);
8377 ip
->daddr
= htonl(192U << 24 | 168 << 16 | 1 << 8 | 2);
8378 ip
->check
= ipv4_hdr_checksum(ip
, sizeof(*ip
));
8379 dpos
= (u8
*) (ip
+ 1);
8380 for (i
= 0; i
< HWSIM_IP_LEN
- sizeof(*ip
); i
++)
8383 if (l2_packet_send(wpa_s
->l2_test
, dst
, ETHERTYPE_IP
, &buf
[2],
8384 HWSIM_PACKETLEN
) < 0)
8387 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: TX dst=" MACSTR
" src=" MACSTR
8388 " tos=0x%x", MAC2STR(dst
), MAC2STR(src
), tos
);
8394 static int wpas_ctrl_iface_data_test_frame(struct wpa_supplicant
*wpa_s
,
8398 struct ether_header
*eth
;
8399 struct l2_packet_data
*l2
= NULL
;
8404 len
= os_strlen(cmd
);
8405 if (len
& 1 || len
< ETH_HLEN
* 2)
8409 buf
= os_malloc(len
);
8413 if (hexstr2bin(cmd
, buf
, len
) < 0)
8416 eth
= (struct ether_header
*) buf
;
8417 ethertype
= ntohs(eth
->ether_type
);
8419 l2
= l2_packet_init(wpa_s
->ifname
, wpa_s
->own_addr
, ethertype
,
8420 wpas_data_test_rx
, wpa_s
, 1);
8424 res
= l2_packet_send(l2
, eth
->ether_dhost
, ethertype
, buf
, len
);
8425 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: TX frame res=%d", res
);
8428 l2_packet_deinit(l2
);
8431 return res
< 0 ? -1 : 0;
8435 static int wpas_ctrl_test_alloc_fail(struct wpa_supplicant
*wpa_s
, char *cmd
)
8437 #ifdef WPA_TRACE_BFD
8440 wpa_trace_fail_after
= atoi(cmd
);
8441 pos
= os_strchr(cmd
, ':');
8444 os_strlcpy(wpa_trace_fail_func
, pos
,
8445 sizeof(wpa_trace_fail_func
));
8447 wpa_trace_fail_after
= 0;
8450 #else /* WPA_TRACE_BFD */
8452 #endif /* WPA_TRACE_BFD */
8456 static int wpas_ctrl_get_alloc_fail(struct wpa_supplicant
*wpa_s
,
8457 char *buf
, size_t buflen
)
8459 #ifdef WPA_TRACE_BFD
8460 return os_snprintf(buf
, buflen
, "%u:%s", wpa_trace_fail_after
,
8461 wpa_trace_fail_func
);
8462 #else /* WPA_TRACE_BFD */
8464 #endif /* WPA_TRACE_BFD */
8468 static int wpas_ctrl_test_fail(struct wpa_supplicant
*wpa_s
, char *cmd
)
8470 #ifdef WPA_TRACE_BFD
8473 wpa_trace_test_fail_after
= atoi(cmd
);
8474 pos
= os_strchr(cmd
, ':');
8477 os_strlcpy(wpa_trace_test_fail_func
, pos
,
8478 sizeof(wpa_trace_test_fail_func
));
8480 wpa_trace_test_fail_after
= 0;
8483 #else /* WPA_TRACE_BFD */
8485 #endif /* WPA_TRACE_BFD */
8489 static int wpas_ctrl_get_fail(struct wpa_supplicant
*wpa_s
,
8490 char *buf
, size_t buflen
)
8492 #ifdef WPA_TRACE_BFD
8493 return os_snprintf(buf
, buflen
, "%u:%s", wpa_trace_test_fail_after
,
8494 wpa_trace_test_fail_func
);
8495 #else /* WPA_TRACE_BFD */
8497 #endif /* WPA_TRACE_BFD */
8501 static void wpas_ctrl_event_test_cb(void *eloop_ctx
, void *timeout_ctx
)
8503 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
8504 int i
, count
= (intptr_t) timeout_ctx
;
8506 wpa_printf(MSG_DEBUG
, "TEST: Send %d control interface event messages",
8508 for (i
= 0; i
< count
; i
++) {
8509 wpa_msg_ctrl(wpa_s
, MSG_INFO
, "TEST-EVENT-MESSAGE %d/%d",
8515 static int wpas_ctrl_event_test(struct wpa_supplicant
*wpa_s
, const char *cmd
)
8523 return eloop_register_timeout(0, 0, wpas_ctrl_event_test_cb
, wpa_s
,
8524 (void *) (intptr_t) count
);
8528 static int wpas_ctrl_test_assoc_ie(struct wpa_supplicant
*wpa_s
,
8534 len
= os_strlen(cmd
);
8542 buf
= wpabuf_alloc(len
);
8546 if (hexstr2bin(cmd
, wpabuf_put(buf
, len
), len
) < 0) {
8552 wpa_sm_set_test_assoc_ie(wpa_s
->wpa
, buf
);
8556 #endif /* CONFIG_TESTING_OPTIONS */
8559 static int wpas_ctrl_vendor_elem_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
8565 struct ieee802_11_elems elems
;
8568 if (frame
< 0 || frame
>= NUM_VENDOR_ELEM_FRAMES
)
8570 wpa_s
= wpas_vendor_elem(wpa_s
, frame
);
8572 pos
= os_strchr(pos
, ' ');
8577 len
= os_strlen(pos
);
8584 buf
= wpabuf_alloc(len
);
8588 if (hexstr2bin(pos
, wpabuf_put(buf
, len
), len
) < 0) {
8593 if (ieee802_11_parse_elems(wpabuf_head_u8(buf
), len
, &elems
, 0) ==
8599 if (wpa_s
->vendor_elem
[frame
] == NULL
) {
8600 wpa_s
->vendor_elem
[frame
] = buf
;
8601 wpas_vendor_elem_update(wpa_s
);
8605 if (wpabuf_resize(&wpa_s
->vendor_elem
[frame
], len
) < 0) {
8610 wpabuf_put_buf(wpa_s
->vendor_elem
[frame
], buf
);
8612 wpas_vendor_elem_update(wpa_s
);
8618 static int wpas_ctrl_vendor_elem_get(struct wpa_supplicant
*wpa_s
, char *cmd
,
8619 char *buf
, size_t buflen
)
8621 int frame
= atoi(cmd
);
8623 if (frame
< 0 || frame
>= NUM_VENDOR_ELEM_FRAMES
)
8625 wpa_s
= wpas_vendor_elem(wpa_s
, frame
);
8627 if (wpa_s
->vendor_elem
[frame
] == NULL
)
8630 return wpa_snprintf_hex(buf
, buflen
,
8631 wpabuf_head_u8(wpa_s
->vendor_elem
[frame
]),
8632 wpabuf_len(wpa_s
->vendor_elem
[frame
]));
8636 static int wpas_ctrl_vendor_elem_remove(struct wpa_supplicant
*wpa_s
, char *cmd
)
8642 struct ieee802_11_elems elems
;
8646 if (frame
< 0 || frame
>= NUM_VENDOR_ELEM_FRAMES
)
8648 wpa_s
= wpas_vendor_elem(wpa_s
, frame
);
8650 pos
= os_strchr(pos
, ' ');
8656 wpabuf_free(wpa_s
->vendor_elem
[frame
]);
8657 wpa_s
->vendor_elem
[frame
] = NULL
;
8658 wpas_vendor_elem_update(wpa_s
);
8662 if (wpa_s
->vendor_elem
[frame
] == NULL
)
8665 len
= os_strlen(pos
);
8672 buf
= os_malloc(len
);
8676 if (hexstr2bin(pos
, buf
, len
) < 0) {
8681 if (ieee802_11_parse_elems(buf
, len
, &elems
, 0) == ParseFailed
) {
8686 res
= wpas_vendor_elem_remove(wpa_s
, frame
, buf
, len
);
8692 static void wpas_ctrl_neighbor_rep_cb(void *ctx
, struct wpabuf
*neighbor_rep
)
8694 struct wpa_supplicant
*wpa_s
= ctx
;
8699 * Neighbor Report element (IEEE P802.11-REVmc/D5.0)
8701 * BSSID Information[4]
8702 * Operating Class[1]
8705 * Optional Subelements[variable]
8707 #define NR_IE_MIN_LEN (ETH_ALEN + 4 + 1 + 1 + 1)
8709 if (!neighbor_rep
|| wpabuf_len(neighbor_rep
) == 0) {
8710 wpa_msg_ctrl(wpa_s
, MSG_INFO
, RRM_EVENT_NEIGHBOR_REP_FAILED
);
8714 data
= wpabuf_head_u8(neighbor_rep
);
8715 len
= wpabuf_len(neighbor_rep
);
8717 while (len
>= 2 + NR_IE_MIN_LEN
) {
8719 char lci
[256 * 2 + 1];
8720 char civic
[256 * 2 + 1];
8721 u8 nr_len
= data
[1];
8722 const u8
*pos
= data
, *end
;
8724 if (pos
[0] != WLAN_EID_NEIGHBOR_REPORT
||
8725 nr_len
< NR_IE_MIN_LEN
) {
8726 wpa_printf(MSG_DEBUG
,
8727 "CTRL: Invalid Neighbor Report element: id=%u len=%u",
8732 if (2U + nr_len
> len
) {
8733 wpa_printf(MSG_DEBUG
,
8734 "CTRL: Invalid Neighbor Report element: id=%u len=%zu nr_len=%u",
8735 data
[0], len
, nr_len
);
8742 pos
+= NR_IE_MIN_LEN
;
8746 while (end
- pos
> 2) {
8751 if (s_len
> end
- pos
)
8753 if (s_id
== WLAN_EID_MEASURE_REPORT
&& s_len
> 3) {
8754 /* Measurement Token[1] */
8755 /* Measurement Report Mode[1] */
8756 /* Measurement Type[1] */
8757 /* Measurement Report[variable] */
8759 case MEASURE_TYPE_LCI
:
8762 wpa_snprintf_hex(lci
, sizeof(lci
),
8765 case MEASURE_TYPE_LOCATION_CIVIC
:
8768 wpa_snprintf_hex(civic
, sizeof(civic
),
8777 wpa_msg(wpa_s
, MSG_INFO
, RRM_EVENT_NEIGHBOR_REP_RXED
8779 " info=0x%x op_class=%u chan=%u phy_type=%u%s%s%s%s",
8780 MAC2STR(nr
), WPA_GET_LE32(nr
+ ETH_ALEN
),
8781 nr
[ETH_ALEN
+ 4], nr
[ETH_ALEN
+ 5],
8783 lci
[0] ? " lci=" : "", lci
,
8784 civic
[0] ? " civic=" : "", civic
);
8791 wpabuf_free(neighbor_rep
);
8795 static int wpas_ctrl_iface_send_neighbor_rep(struct wpa_supplicant
*wpa_s
,
8798 struct wpa_ssid_value ssid
, *ssid_p
= NULL
;
8799 int ret
, lci
= 0, civic
= 0;
8802 ssid_s
= os_strstr(cmd
, "ssid=");
8804 if (ssid_parse(ssid_s
+ 5, &ssid
)) {
8805 wpa_printf(MSG_ERROR
,
8806 "CTRL: Send Neighbor Report: bad SSID");
8813 * Move cmd after the SSID text that may include "lci" or
8816 cmd
= os_strchr(ssid_s
+ 6, ssid_s
[5] == '"' ? '"' : ' ');
8822 if (cmd
&& os_strstr(cmd
, "lci"))
8825 if (cmd
&& os_strstr(cmd
, "civic"))
8828 ret
= wpas_rrm_send_neighbor_rep_request(wpa_s
, ssid_p
, lci
, civic
,
8829 wpas_ctrl_neighbor_rep_cb
,
8836 static int wpas_ctrl_iface_erp_flush(struct wpa_supplicant
*wpa_s
)
8838 eapol_sm_erp_flush(wpa_s
->eapol
);
8843 static int wpas_ctrl_iface_mac_rand_scan(struct wpa_supplicant
*wpa_s
,
8846 char *token
, *context
= NULL
;
8847 unsigned int enable
= ~0, type
= 0;
8848 u8 _addr
[ETH_ALEN
], _mask
[ETH_ALEN
];
8849 u8
*addr
= NULL
, *mask
= NULL
;
8851 while ((token
= str_token(cmd
, " ", &context
))) {
8852 if (os_strcasecmp(token
, "scan") == 0) {
8853 type
|= MAC_ADDR_RAND_SCAN
;
8854 } else if (os_strcasecmp(token
, "sched") == 0) {
8855 type
|= MAC_ADDR_RAND_SCHED_SCAN
;
8856 } else if (os_strcasecmp(token
, "pno") == 0) {
8857 type
|= MAC_ADDR_RAND_PNO
;
8858 } else if (os_strcasecmp(token
, "all") == 0) {
8859 type
= wpa_s
->mac_addr_rand_supported
;
8860 } else if (os_strncasecmp(token
, "enable=", 7) == 0) {
8861 enable
= atoi(token
+ 7);
8862 } else if (os_strncasecmp(token
, "addr=", 5) == 0) {
8864 if (hwaddr_aton(token
+ 5, addr
)) {
8865 wpa_printf(MSG_INFO
,
8866 "CTRL: Invalid MAC address: %s",
8870 } else if (os_strncasecmp(token
, "mask=", 5) == 0) {
8872 if (hwaddr_aton(token
+ 5, mask
)) {
8873 wpa_printf(MSG_INFO
,
8874 "CTRL: Invalid MAC address mask: %s",
8879 wpa_printf(MSG_INFO
,
8880 "CTRL: Invalid MAC_RAND_SCAN parameter: %s",
8887 wpa_printf(MSG_INFO
, "CTRL: MAC_RAND_SCAN no type specified");
8891 if ((wpa_s
->mac_addr_rand_supported
& type
) != type
) {
8892 wpa_printf(MSG_INFO
,
8893 "CTRL: MAC_RAND_SCAN types=%u != supported=%u",
8894 type
, wpa_s
->mac_addr_rand_supported
);
8899 wpa_printf(MSG_INFO
,
8900 "CTRL: MAC_RAND_SCAN enable=<0/1> not specified");
8905 wpas_mac_addr_rand_scan_clear(wpa_s
, type
);
8907 if (type
& MAC_ADDR_RAND_PNO
) {
8908 wpas_stop_pno(wpa_s
);
8909 wpas_start_pno(wpa_s
);
8911 } else if (wpa_s
->sched_scanning
&&
8912 (type
& MAC_ADDR_RAND_SCHED_SCAN
)) {
8913 wpas_scan_restart_sched_scan(wpa_s
);
8918 if ((addr
&& !mask
) || (!addr
&& mask
)) {
8919 wpa_printf(MSG_INFO
,
8920 "CTRL: MAC_RAND_SCAN invalid addr/mask combination");
8924 if (addr
&& mask
&& (!(mask
[0] & 0x01) || (addr
[0] & 0x01))) {
8925 wpa_printf(MSG_INFO
,
8926 "CTRL: MAC_RAND_SCAN cannot allow multicast address");
8930 if (type
& MAC_ADDR_RAND_SCAN
) {
8931 wpas_mac_addr_rand_scan_set(wpa_s
, MAC_ADDR_RAND_SCAN
,
8935 if (type
& MAC_ADDR_RAND_SCHED_SCAN
) {
8936 wpas_mac_addr_rand_scan_set(wpa_s
, MAC_ADDR_RAND_SCHED_SCAN
,
8939 if (wpa_s
->sched_scanning
&& !wpa_s
->pno
)
8940 wpas_scan_restart_sched_scan(wpa_s
);
8943 if (type
& MAC_ADDR_RAND_PNO
) {
8944 wpas_mac_addr_rand_scan_set(wpa_s
, MAC_ADDR_RAND_PNO
,
8947 wpas_stop_pno(wpa_s
);
8948 wpas_start_pno(wpa_s
);
8956 static int wpas_ctrl_iface_pmksa(struct wpa_supplicant
*wpa_s
,
8957 char *buf
, size_t buflen
)
8961 reply_len
= wpa_sm_pmksa_cache_list(wpa_s
->wpa
, buf
, buflen
);
8963 reply_len
+= wpas_ap_pmksa_cache_list(wpa_s
, &buf
[reply_len
],
8964 buflen
- reply_len
);
8965 #endif /* CONFIG_AP */
8970 static void wpas_ctrl_iface_pmksa_flush(struct wpa_supplicant
*wpa_s
)
8972 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, NULL
);
8974 wpas_ap_pmksa_cache_flush(wpa_s
);
8975 #endif /* CONFIG_AP */
8979 #ifdef CONFIG_PMKSA_CACHE_EXTERNAL
8981 static int wpas_ctrl_iface_pmksa_get(struct wpa_supplicant
*wpa_s
,
8982 const char *cmd
, char *buf
, size_t buflen
)
8984 struct rsn_pmksa_cache_entry
*entry
;
8985 struct wpa_ssid
*ssid
;
8986 char *pos
, *pos2
, *end
;
8988 struct os_reltime now
;
8990 ssid
= wpa_config_get_network(wpa_s
->conf
, atoi(cmd
));
8997 os_get_reltime(&now
);
9001 * <BSSID> <PMKID> <PMK> <reauth_time in seconds>
9002 * <expiration in seconds> <akmp> <opportunistic>
9005 for (entry
= wpa_sm_pmksa_cache_head(wpa_s
->wpa
); entry
;
9006 entry
= entry
->next
) {
9007 if (entry
->network_ctx
!= ssid
)
9011 ret
= os_snprintf(pos2
, end
- pos2
, MACSTR
" ",
9012 MAC2STR(entry
->aa
));
9013 if (os_snprintf_error(end
- pos2
, ret
))
9017 pos2
+= wpa_snprintf_hex(pos2
, end
- pos2
, entry
->pmkid
,
9020 ret
= os_snprintf(pos2
, end
- pos2
, " ");
9021 if (os_snprintf_error(end
- pos2
, ret
))
9025 pos2
+= wpa_snprintf_hex(pos2
, end
- pos2
, entry
->pmk
,
9028 ret
= os_snprintf(pos2
, end
- pos2
, " %d %d %d %d",
9029 (int) (entry
->reauth_time
- now
.sec
),
9030 (int) (entry
->expiration
- now
.sec
),
9032 entry
->opportunistic
);
9033 if (os_snprintf_error(end
- pos2
, ret
))
9037 ret
= os_snprintf(pos2
, end
- pos2
, "\n");
9038 if (os_snprintf_error(end
- pos2
, ret
))
9049 static int wpas_ctrl_iface_pmksa_add(struct wpa_supplicant
*wpa_s
,
9052 struct rsn_pmksa_cache_entry
*entry
;
9053 struct wpa_ssid
*ssid
;
9056 struct os_reltime now
;
9057 int reauth_time
= 0, expiration
= 0;
9061 * <network_id> <BSSID> <PMKID> <PMK> <reauth_time in seconds>
9062 * <expiration in seconds> <akmp> <opportunistic>
9065 ssid
= wpa_config_get_network(wpa_s
->conf
, atoi(cmd
));
9069 pos
= os_strchr(cmd
, ' ');
9074 entry
= os_zalloc(sizeof(*entry
));
9078 if (hwaddr_aton(pos
, entry
->aa
))
9081 pos
= os_strchr(pos
, ' ');
9086 if (hexstr2bin(pos
, entry
->pmkid
, PMKID_LEN
) < 0)
9089 pos
= os_strchr(pos
, ' ');
9094 pos2
= os_strchr(pos
, ' ');
9097 entry
->pmk_len
= (pos2
- pos
) / 2;
9098 if (entry
->pmk_len
< PMK_LEN
|| entry
->pmk_len
> PMK_LEN_MAX
||
9099 hexstr2bin(pos
, entry
->pmk
, entry
->pmk_len
) < 0)
9102 pos
= os_strchr(pos
, ' ');
9107 if (sscanf(pos
, "%d %d %d %d", &reauth_time
, &expiration
,
9108 &entry
->akmp
, &entry
->opportunistic
) != 4)
9110 os_get_reltime(&now
);
9111 entry
->expiration
= now
.sec
+ expiration
;
9112 entry
->reauth_time
= now
.sec
+ reauth_time
;
9114 entry
->network_ctx
= ssid
;
9116 wpa_sm_pmksa_cache_add_entry(wpa_s
->wpa
, entry
);
9127 static int wpas_ctrl_iface_mesh_pmksa_get(struct wpa_supplicant
*wpa_s
,
9128 const char *cmd
, char *buf
,
9136 if (os_strcasecmp(cmd
, "any") == 0)
9137 return wpas_ap_pmksa_cache_list_mesh(wpa_s
, NULL
, buf
, buflen
);
9139 if (hwaddr_aton(cmd
, spa
))
9142 return wpas_ap_pmksa_cache_list_mesh(wpa_s
, spa
, buf
, buflen
);
9146 static int wpas_ctrl_iface_mesh_pmksa_add(struct wpa_supplicant
*wpa_s
,
9150 * We do not check mesh interface existance because PMKSA should be
9151 * stored before wpa_s->ifmsh creation to suppress commit message
9154 return wpas_ap_pmksa_cache_add_external(wpa_s
, cmd
);
9157 #endif /* CONFIG_MESH */
9158 #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
9162 static int wpas_ctrl_iface_fils_hlp_req_add(struct wpa_supplicant
*wpa_s
,
9165 struct fils_hlp_req
*req
;
9168 /* format: <dst> <packet starting from ethertype> */
9170 req
= os_zalloc(sizeof(*req
));
9174 if (hwaddr_aton(cmd
, req
->dst
))
9177 pos
= os_strchr(cmd
, ' ');
9181 req
->pkt
= wpabuf_parse_bin(pos
);
9185 dl_list_add_tail(&wpa_s
->fils_hlp_req
, &req
->list
);
9188 wpabuf_free(req
->pkt
);
9192 #endif /* CONFIG_FILS */
9195 static int wpas_ctrl_cmd_debug_level(const char *cmd
)
9197 if (os_strcmp(cmd
, "PING") == 0 ||
9198 os_strncmp(cmd
, "BSS ", 4) == 0 ||
9199 os_strncmp(cmd
, "GET_NETWORK ", 12) == 0 ||
9200 os_strncmp(cmd
, "STATUS", 6) == 0 ||
9201 os_strncmp(cmd
, "STA ", 4) == 0 ||
9202 os_strncmp(cmd
, "STA-", 4) == 0)
9203 return MSG_EXCESSIVE
;
9208 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant
*wpa_s
,
9209 char *buf
, size_t *resp_len
)
9212 const int reply_size
= 4096;
9215 if (os_strncmp(buf
, WPA_CTRL_RSP
, os_strlen(WPA_CTRL_RSP
)) == 0 ||
9216 os_strncmp(buf
, "SET_NETWORK ", 12) == 0) {
9217 if (wpa_debug_show_keys
)
9218 wpa_dbg(wpa_s
, MSG_DEBUG
,
9219 "Control interface command '%s'", buf
);
9221 wpa_dbg(wpa_s
, MSG_DEBUG
,
9222 "Control interface command '%s [REMOVED]'",
9223 os_strncmp(buf
, WPA_CTRL_RSP
,
9224 os_strlen(WPA_CTRL_RSP
)) == 0 ?
9225 WPA_CTRL_RSP
: "SET_NETWORK");
9226 } else if (os_strncmp(buf
, "WPS_NFC_TAG_READ", 16) == 0 ||
9227 os_strncmp(buf
, "NFC_REPORT_HANDOVER", 19) == 0) {
9228 wpa_hexdump_ascii_key(MSG_DEBUG
, "RX ctrl_iface",
9229 (const u8
*) buf
, os_strlen(buf
));
9231 int level
= wpas_ctrl_cmd_debug_level(buf
);
9232 wpa_dbg(wpa_s
, level
, "Control interface command '%s'", buf
);
9235 reply
= os_malloc(reply_size
);
9236 if (reply
== NULL
) {
9241 os_memcpy(reply
, "OK\n", 3);
9244 if (os_strcmp(buf
, "PING") == 0) {
9245 os_memcpy(reply
, "PONG\n", 5);
9247 } else if (os_strcmp(buf
, "IFNAME") == 0) {
9248 reply_len
= os_strlen(wpa_s
->ifname
);
9249 os_memcpy(reply
, wpa_s
->ifname
, reply_len
);
9250 } else if (os_strncmp(buf
, "RELOG", 5) == 0) {
9251 if (wpa_debug_reopen_file() < 0)
9253 } else if (os_strncmp(buf
, "NOTE ", 5) == 0) {
9254 wpa_printf(MSG_INFO
, "NOTE: %s", buf
+ 5);
9255 } else if (os_strcmp(buf
, "MIB") == 0) {
9256 reply_len
= wpa_sm_get_mib(wpa_s
->wpa
, reply
, reply_size
);
9257 if (reply_len
>= 0) {
9258 reply_len
+= eapol_sm_get_mib(wpa_s
->eapol
,
9260 reply_size
- reply_len
);
9262 } else if (os_strncmp(buf
, "STATUS", 6) == 0) {
9263 reply_len
= wpa_supplicant_ctrl_iface_status(
9264 wpa_s
, buf
+ 6, reply
, reply_size
);
9265 } else if (os_strcmp(buf
, "PMKSA") == 0) {
9266 reply_len
= wpas_ctrl_iface_pmksa(wpa_s
, reply
, reply_size
);
9267 } else if (os_strcmp(buf
, "PMKSA_FLUSH") == 0) {
9268 wpas_ctrl_iface_pmksa_flush(wpa_s
);
9269 #ifdef CONFIG_PMKSA_CACHE_EXTERNAL
9270 } else if (os_strncmp(buf
, "PMKSA_GET ", 10) == 0) {
9271 reply_len
= wpas_ctrl_iface_pmksa_get(wpa_s
, buf
+ 10,
9273 } else if (os_strncmp(buf
, "PMKSA_ADD ", 10) == 0) {
9274 if (wpas_ctrl_iface_pmksa_add(wpa_s
, buf
+ 10) < 0)
9277 } else if (os_strncmp(buf
, "MESH_PMKSA_GET ", 15) == 0) {
9278 reply_len
= wpas_ctrl_iface_mesh_pmksa_get(wpa_s
, buf
+ 15,
9280 } else if (os_strncmp(buf
, "MESH_PMKSA_ADD ", 15) == 0) {
9281 if (wpas_ctrl_iface_mesh_pmksa_add(wpa_s
, buf
+ 15) < 0)
9283 #endif /* CONFIG_MESH */
9284 #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
9285 } else if (os_strncmp(buf
, "SET ", 4) == 0) {
9286 if (wpa_supplicant_ctrl_iface_set(wpa_s
, buf
+ 4))
9288 } else if (os_strncmp(buf
, "DUMP", 4) == 0) {
9289 reply_len
= wpa_config_dump_values(wpa_s
->conf
,
9291 } else if (os_strncmp(buf
, "GET ", 4) == 0) {
9292 reply_len
= wpa_supplicant_ctrl_iface_get(wpa_s
, buf
+ 4,
9294 } else if (os_strcmp(buf
, "LOGON") == 0) {
9295 eapol_sm_notify_logoff(wpa_s
->eapol
, FALSE
);
9296 } else if (os_strcmp(buf
, "LOGOFF") == 0) {
9297 eapol_sm_notify_logoff(wpa_s
->eapol
, TRUE
);
9298 } else if (os_strcmp(buf
, "REASSOCIATE") == 0) {
9299 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
9302 wpas_request_connection(wpa_s
);
9303 } else if (os_strcmp(buf
, "REATTACH") == 0) {
9304 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
||
9305 !wpa_s
->current_ssid
)
9308 wpa_s
->reattach
= 1;
9309 wpas_request_connection(wpa_s
);
9311 } else if (os_strcmp(buf
, "RECONNECT") == 0) {
9312 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
9314 else if (wpa_s
->disconnected
)
9315 wpas_request_connection(wpa_s
);
9316 #ifdef IEEE8021X_EAPOL
9317 } else if (os_strncmp(buf
, "PREAUTH ", 8) == 0) {
9318 if (wpa_supplicant_ctrl_iface_preauth(wpa_s
, buf
+ 8))
9320 #endif /* IEEE8021X_EAPOL */
9321 #ifdef CONFIG_PEERKEY
9322 } else if (os_strncmp(buf
, "STKSTART ", 9) == 0) {
9323 if (wpa_supplicant_ctrl_iface_stkstart(wpa_s
, buf
+ 9))
9325 #endif /* CONFIG_PEERKEY */
9326 #ifdef CONFIG_IEEE80211R
9327 } else if (os_strncmp(buf
, "FT_DS ", 6) == 0) {
9328 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s
, buf
+ 6))
9330 #endif /* CONFIG_IEEE80211R */
9332 } else if (os_strcmp(buf
, "WPS_PBC") == 0) {
9333 int res
= wpa_supplicant_ctrl_iface_wps_pbc(wpa_s
, NULL
);
9335 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
9339 } else if (os_strncmp(buf
, "WPS_PBC ", 8) == 0) {
9340 int res
= wpa_supplicant_ctrl_iface_wps_pbc(wpa_s
, buf
+ 8);
9342 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
9346 } else if (os_strncmp(buf
, "WPS_PIN ", 8) == 0) {
9347 reply_len
= wpa_supplicant_ctrl_iface_wps_pin(wpa_s
, buf
+ 8,
9350 } else if (os_strncmp(buf
, "WPS_CHECK_PIN ", 14) == 0) {
9351 reply_len
= wpa_supplicant_ctrl_iface_wps_check_pin(
9352 wpa_s
, buf
+ 14, reply
, reply_size
);
9353 } else if (os_strcmp(buf
, "WPS_CANCEL") == 0) {
9354 if (wpas_wps_cancel(wpa_s
))
9356 #ifdef CONFIG_WPS_NFC
9357 } else if (os_strcmp(buf
, "WPS_NFC") == 0) {
9358 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s
, NULL
))
9360 } else if (os_strncmp(buf
, "WPS_NFC ", 8) == 0) {
9361 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s
, buf
+ 8))
9363 } else if (os_strncmp(buf
, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
9364 reply_len
= wpa_supplicant_ctrl_iface_wps_nfc_config_token(
9365 wpa_s
, buf
+ 21, reply
, reply_size
);
9366 } else if (os_strncmp(buf
, "WPS_NFC_TOKEN ", 14) == 0) {
9367 reply_len
= wpa_supplicant_ctrl_iface_wps_nfc_token(
9368 wpa_s
, buf
+ 14, reply
, reply_size
);
9369 } else if (os_strncmp(buf
, "WPS_NFC_TAG_READ ", 17) == 0) {
9370 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s
,
9373 } else if (os_strncmp(buf
, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
9374 reply_len
= wpas_ctrl_nfc_get_handover_req(
9375 wpa_s
, buf
+ 21, reply
, reply_size
);
9376 } else if (os_strncmp(buf
, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
9377 reply_len
= wpas_ctrl_nfc_get_handover_sel(
9378 wpa_s
, buf
+ 21, reply
, reply_size
);
9379 } else if (os_strncmp(buf
, "NFC_REPORT_HANDOVER ", 20) == 0) {
9380 if (wpas_ctrl_nfc_report_handover(wpa_s
, buf
+ 20))
9382 #endif /* CONFIG_WPS_NFC */
9383 } else if (os_strncmp(buf
, "WPS_REG ", 8) == 0) {
9384 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s
, buf
+ 8))
9387 } else if (os_strncmp(buf
, "WPS_AP_PIN ", 11) == 0) {
9388 reply_len
= wpa_supplicant_ctrl_iface_wps_ap_pin(
9389 wpa_s
, buf
+ 11, reply
, reply_size
);
9390 #endif /* CONFIG_AP */
9391 #ifdef CONFIG_WPS_ER
9392 } else if (os_strcmp(buf
, "WPS_ER_START") == 0) {
9393 if (wpas_wps_er_start(wpa_s
, NULL
))
9395 } else if (os_strncmp(buf
, "WPS_ER_START ", 13) == 0) {
9396 if (wpas_wps_er_start(wpa_s
, buf
+ 13))
9398 } else if (os_strcmp(buf
, "WPS_ER_STOP") == 0) {
9399 wpas_wps_er_stop(wpa_s
);
9400 } else if (os_strncmp(buf
, "WPS_ER_PIN ", 11) == 0) {
9401 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s
, buf
+ 11))
9403 } else if (os_strncmp(buf
, "WPS_ER_PBC ", 11) == 0) {
9404 int ret
= wpas_wps_er_pbc(wpa_s
, buf
+ 11);
9406 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
9408 } else if (ret
== -3) {
9409 os_memcpy(reply
, "FAIL-UNKNOWN-UUID\n", 18);
9411 } else if (ret
== -4) {
9412 os_memcpy(reply
, "FAIL-NO-AP-SETTINGS\n", 20);
9416 } else if (os_strncmp(buf
, "WPS_ER_LEARN ", 13) == 0) {
9417 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s
, buf
+ 13))
9419 } else if (os_strncmp(buf
, "WPS_ER_SET_CONFIG ", 18) == 0) {
9420 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s
,
9423 } else if (os_strncmp(buf
, "WPS_ER_CONFIG ", 14) == 0) {
9424 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s
, buf
+ 14))
9426 #ifdef CONFIG_WPS_NFC
9427 } else if (os_strncmp(buf
, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
9428 reply_len
= wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
9429 wpa_s
, buf
+ 24, reply
, reply_size
);
9430 #endif /* CONFIG_WPS_NFC */
9431 #endif /* CONFIG_WPS_ER */
9432 #endif /* CONFIG_WPS */
9433 #ifdef CONFIG_IBSS_RSN
9434 } else if (os_strncmp(buf
, "IBSS_RSN ", 9) == 0) {
9435 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s
, buf
+ 9))
9437 #endif /* CONFIG_IBSS_RSN */
9439 } else if (os_strncmp(buf
, "MESH_INTERFACE_ADD ", 19) == 0) {
9440 reply_len
= wpa_supplicant_ctrl_iface_mesh_interface_add(
9441 wpa_s
, buf
+ 19, reply
, reply_size
);
9442 } else if (os_strcmp(buf
, "MESH_INTERFACE_ADD") == 0) {
9443 reply_len
= wpa_supplicant_ctrl_iface_mesh_interface_add(
9444 wpa_s
, "", reply
, reply_size
);
9445 } else if (os_strncmp(buf
, "MESH_GROUP_ADD ", 15) == 0) {
9446 if (wpa_supplicant_ctrl_iface_mesh_group_add(wpa_s
, buf
+ 15))
9448 } else if (os_strncmp(buf
, "MESH_GROUP_REMOVE ", 18) == 0) {
9449 if (wpa_supplicant_ctrl_iface_mesh_group_remove(wpa_s
,
9452 } else if (os_strncmp(buf
, "MESH_PEER_REMOVE ", 17) == 0) {
9453 if (wpa_supplicant_ctrl_iface_mesh_peer_remove(wpa_s
, buf
+ 17))
9455 } else if (os_strncmp(buf
, "MESH_PEER_ADD ", 14) == 0) {
9456 if (wpa_supplicant_ctrl_iface_mesh_peer_add(wpa_s
, buf
+ 14))
9458 #endif /* CONFIG_MESH */
9460 } else if (os_strncmp(buf
, "P2P_FIND ", 9) == 0) {
9461 if (p2p_ctrl_find(wpa_s
, buf
+ 8))
9463 } else if (os_strcmp(buf
, "P2P_FIND") == 0) {
9464 if (p2p_ctrl_find(wpa_s
, ""))
9466 } else if (os_strcmp(buf
, "P2P_STOP_FIND") == 0) {
9467 wpas_p2p_stop_find(wpa_s
);
9468 } else if (os_strncmp(buf
, "P2P_ASP_PROVISION ", 18) == 0) {
9469 if (p2p_ctrl_asp_provision(wpa_s
, buf
+ 18))
9471 } else if (os_strncmp(buf
, "P2P_ASP_PROVISION_RESP ", 23) == 0) {
9472 if (p2p_ctrl_asp_provision_resp(wpa_s
, buf
+ 23))
9474 } else if (os_strncmp(buf
, "P2P_CONNECT ", 12) == 0) {
9475 reply_len
= p2p_ctrl_connect(wpa_s
, buf
+ 12, reply
,
9477 } else if (os_strncmp(buf
, "P2P_LISTEN ", 11) == 0) {
9478 if (p2p_ctrl_listen(wpa_s
, buf
+ 11))
9480 } else if (os_strcmp(buf
, "P2P_LISTEN") == 0) {
9481 if (p2p_ctrl_listen(wpa_s
, ""))
9483 } else if (os_strncmp(buf
, "P2P_GROUP_REMOVE ", 17) == 0) {
9484 if (wpas_p2p_group_remove(wpa_s
, buf
+ 17))
9486 } else if (os_strcmp(buf
, "P2P_GROUP_ADD") == 0) {
9487 if (p2p_ctrl_group_add(wpa_s
, ""))
9489 } else if (os_strncmp(buf
, "P2P_GROUP_ADD ", 14) == 0) {
9490 if (p2p_ctrl_group_add(wpa_s
, buf
+ 14))
9492 } else if (os_strncmp(buf
, "P2P_GROUP_MEMBER ", 17) == 0) {
9493 reply_len
= p2p_ctrl_group_member(wpa_s
, buf
+ 17, reply
,
9495 } else if (os_strncmp(buf
, "P2P_PROV_DISC ", 14) == 0) {
9496 if (p2p_ctrl_prov_disc(wpa_s
, buf
+ 14))
9498 } else if (os_strcmp(buf
, "P2P_GET_PASSPHRASE") == 0) {
9499 reply_len
= p2p_get_passphrase(wpa_s
, reply
, reply_size
);
9500 } else if (os_strncmp(buf
, "P2P_SERV_DISC_REQ ", 18) == 0) {
9501 reply_len
= p2p_ctrl_serv_disc_req(wpa_s
, buf
+ 18, reply
,
9503 } else if (os_strncmp(buf
, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
9504 if (p2p_ctrl_serv_disc_cancel_req(wpa_s
, buf
+ 25) < 0)
9506 } else if (os_strncmp(buf
, "P2P_SERV_DISC_RESP ", 19) == 0) {
9507 if (p2p_ctrl_serv_disc_resp(wpa_s
, buf
+ 19) < 0)
9509 } else if (os_strcmp(buf
, "P2P_SERVICE_UPDATE") == 0) {
9510 wpas_p2p_sd_service_update(wpa_s
);
9511 } else if (os_strncmp(buf
, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
9512 if (p2p_ctrl_serv_disc_external(wpa_s
, buf
+ 23) < 0)
9514 } else if (os_strcmp(buf
, "P2P_SERVICE_FLUSH") == 0) {
9515 wpas_p2p_service_flush(wpa_s
);
9516 } else if (os_strncmp(buf
, "P2P_SERVICE_ADD ", 16) == 0) {
9517 if (p2p_ctrl_service_add(wpa_s
, buf
+ 16) < 0)
9519 } else if (os_strncmp(buf
, "P2P_SERVICE_DEL ", 16) == 0) {
9520 if (p2p_ctrl_service_del(wpa_s
, buf
+ 16) < 0)
9522 } else if (os_strncmp(buf
, "P2P_SERVICE_REP ", 16) == 0) {
9523 if (p2p_ctrl_service_replace(wpa_s
, buf
+ 16) < 0)
9525 } else if (os_strncmp(buf
, "P2P_REJECT ", 11) == 0) {
9526 if (p2p_ctrl_reject(wpa_s
, buf
+ 11) < 0)
9528 } else if (os_strncmp(buf
, "P2P_INVITE ", 11) == 0) {
9529 if (p2p_ctrl_invite(wpa_s
, buf
+ 11) < 0)
9531 } else if (os_strncmp(buf
, "P2P_PEER ", 9) == 0) {
9532 reply_len
= p2p_ctrl_peer(wpa_s
, buf
+ 9, reply
,
9534 } else if (os_strncmp(buf
, "P2P_SET ", 8) == 0) {
9535 if (p2p_ctrl_set(wpa_s
, buf
+ 8) < 0)
9537 } else if (os_strcmp(buf
, "P2P_FLUSH") == 0) {
9538 p2p_ctrl_flush(wpa_s
);
9539 } else if (os_strncmp(buf
, "P2P_UNAUTHORIZE ", 16) == 0) {
9540 if (wpas_p2p_unauthorize(wpa_s
, buf
+ 16) < 0)
9542 } else if (os_strcmp(buf
, "P2P_CANCEL") == 0) {
9543 if (wpas_p2p_cancel(wpa_s
))
9545 } else if (os_strncmp(buf
, "P2P_PRESENCE_REQ ", 17) == 0) {
9546 if (p2p_ctrl_presence_req(wpa_s
, buf
+ 17) < 0)
9548 } else if (os_strcmp(buf
, "P2P_PRESENCE_REQ") == 0) {
9549 if (p2p_ctrl_presence_req(wpa_s
, "") < 0)
9551 } else if (os_strncmp(buf
, "P2P_EXT_LISTEN ", 15) == 0) {
9552 if (p2p_ctrl_ext_listen(wpa_s
, buf
+ 15) < 0)
9554 } else if (os_strcmp(buf
, "P2P_EXT_LISTEN") == 0) {
9555 if (p2p_ctrl_ext_listen(wpa_s
, "") < 0)
9557 } else if (os_strncmp(buf
, "P2P_REMOVE_CLIENT ", 18) == 0) {
9558 if (p2p_ctrl_remove_client(wpa_s
, buf
+ 18) < 0)
9560 } else if (os_strncmp(buf
, "P2P_LO_START ", 13) == 0) {
9561 if (p2p_ctrl_iface_p2p_lo_start(wpa_s
, buf
+ 13))
9563 } else if (os_strcmp(buf
, "P2P_LO_STOP") == 0) {
9564 if (wpas_p2p_lo_stop(wpa_s
))
9566 #endif /* CONFIG_P2P */
9567 #ifdef CONFIG_WIFI_DISPLAY
9568 } else if (os_strncmp(buf
, "WFD_SUBELEM_SET ", 16) == 0) {
9569 if (wifi_display_subelem_set(wpa_s
->global
, buf
+ 16) < 0)
9571 } else if (os_strncmp(buf
, "WFD_SUBELEM_GET ", 16) == 0) {
9572 reply_len
= wifi_display_subelem_get(wpa_s
->global
, buf
+ 16,
9574 #endif /* CONFIG_WIFI_DISPLAY */
9575 #ifdef CONFIG_INTERWORKING
9576 } else if (os_strcmp(buf
, "FETCH_ANQP") == 0) {
9577 if (interworking_fetch_anqp(wpa_s
) < 0)
9579 } else if (os_strcmp(buf
, "STOP_FETCH_ANQP") == 0) {
9580 interworking_stop_fetch_anqp(wpa_s
);
9581 } else if (os_strcmp(buf
, "INTERWORKING_SELECT") == 0) {
9582 if (ctrl_interworking_select(wpa_s
, NULL
) < 0)
9584 } else if (os_strncmp(buf
, "INTERWORKING_SELECT ", 20) == 0) {
9585 if (ctrl_interworking_select(wpa_s
, buf
+ 20) < 0)
9587 } else if (os_strncmp(buf
, "INTERWORKING_CONNECT ", 21) == 0) {
9588 if (ctrl_interworking_connect(wpa_s
, buf
+ 21, 0) < 0)
9590 } else if (os_strncmp(buf
, "INTERWORKING_ADD_NETWORK ", 25) == 0) {
9593 id
= ctrl_interworking_connect(wpa_s
, buf
+ 25, 1);
9597 reply_len
= os_snprintf(reply
, reply_size
, "%d\n", id
);
9598 if (os_snprintf_error(reply_size
, reply_len
))
9601 } else if (os_strncmp(buf
, "ANQP_GET ", 9) == 0) {
9602 if (get_anqp(wpa_s
, buf
+ 9) < 0)
9604 } else if (os_strncmp(buf
, "GAS_REQUEST ", 12) == 0) {
9605 if (gas_request(wpa_s
, buf
+ 12) < 0)
9607 } else if (os_strncmp(buf
, "GAS_RESPONSE_GET ", 17) == 0) {
9608 reply_len
= gas_response_get(wpa_s
, buf
+ 17, reply
,
9610 #endif /* CONFIG_INTERWORKING */
9612 } else if (os_strncmp(buf
, "HS20_ANQP_GET ", 14) == 0) {
9613 if (get_hs20_anqp(wpa_s
, buf
+ 14) < 0)
9615 } else if (os_strncmp(buf
, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
9616 if (hs20_get_nai_home_realm_list(wpa_s
, buf
+ 29) < 0)
9618 } else if (os_strncmp(buf
, "HS20_ICON_REQUEST ", 18) == 0) {
9619 if (hs20_icon_request(wpa_s
, buf
+ 18, 0) < 0)
9621 } else if (os_strncmp(buf
, "REQ_HS20_ICON ", 14) == 0) {
9622 if (hs20_icon_request(wpa_s
, buf
+ 14, 1) < 0)
9624 } else if (os_strncmp(buf
, "GET_HS20_ICON ", 14) == 0) {
9625 reply_len
= get_hs20_icon(wpa_s
, buf
+ 14, reply
, reply_size
);
9626 } else if (os_strncmp(buf
, "DEL_HS20_ICON ", 14) == 0) {
9627 if (del_hs20_icon(wpa_s
, buf
+ 14) < 0)
9629 } else if (os_strcmp(buf
, "FETCH_OSU") == 0) {
9630 if (hs20_fetch_osu(wpa_s
, 0) < 0)
9632 } else if (os_strcmp(buf
, "FETCH_OSU no-scan") == 0) {
9633 if (hs20_fetch_osu(wpa_s
, 1) < 0)
9635 } else if (os_strcmp(buf
, "CANCEL_FETCH_OSU") == 0) {
9636 hs20_cancel_fetch_osu(wpa_s
);
9637 #endif /* CONFIG_HS20 */
9638 } else if (os_strncmp(buf
, WPA_CTRL_RSP
, os_strlen(WPA_CTRL_RSP
)) == 0)
9640 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
9641 wpa_s
, buf
+ os_strlen(WPA_CTRL_RSP
)))
9645 * Notify response from timeout to allow the control
9646 * interface response to be sent first.
9648 eloop_register_timeout(0, 0, wpas_ctrl_eapol_response
,
9651 } else if (os_strcmp(buf
, "RECONFIGURE") == 0) {
9652 if (wpa_supplicant_reload_configuration(wpa_s
))
9654 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
9655 wpa_supplicant_terminate_proc(wpa_s
->global
);
9656 } else if (os_strncmp(buf
, "BSSID ", 6) == 0) {
9657 if (wpa_supplicant_ctrl_iface_bssid(wpa_s
, buf
+ 6))
9659 } else if (os_strncmp(buf
, "BLACKLIST", 9) == 0) {
9660 reply_len
= wpa_supplicant_ctrl_iface_blacklist(
9661 wpa_s
, buf
+ 9, reply
, reply_size
);
9662 } else if (os_strncmp(buf
, "LOG_LEVEL", 9) == 0) {
9663 reply_len
= wpa_supplicant_ctrl_iface_log_level(
9664 wpa_s
, buf
+ 9, reply
, reply_size
);
9665 } else if (os_strncmp(buf
, "LIST_NETWORKS ", 14) == 0) {
9666 reply_len
= wpa_supplicant_ctrl_iface_list_networks(
9667 wpa_s
, buf
+ 14, reply
, reply_size
);
9668 } else if (os_strcmp(buf
, "LIST_NETWORKS") == 0) {
9669 reply_len
= wpa_supplicant_ctrl_iface_list_networks(
9670 wpa_s
, NULL
, reply
, reply_size
);
9671 } else if (os_strcmp(buf
, "DISCONNECT") == 0) {
9672 wpas_request_disconnection(wpa_s
);
9673 } else if (os_strcmp(buf
, "SCAN") == 0) {
9674 wpas_ctrl_scan(wpa_s
, NULL
, reply
, reply_size
, &reply_len
);
9675 } else if (os_strncmp(buf
, "SCAN ", 5) == 0) {
9676 wpas_ctrl_scan(wpa_s
, buf
+ 5, reply
, reply_size
, &reply_len
);
9677 } else if (os_strcmp(buf
, "SCAN_RESULTS") == 0) {
9678 reply_len
= wpa_supplicant_ctrl_iface_scan_results(
9679 wpa_s
, reply
, reply_size
);
9680 } else if (os_strcmp(buf
, "ABORT_SCAN") == 0) {
9681 if (wpas_abort_ongoing_scan(wpa_s
) < 0)
9683 } else if (os_strncmp(buf
, "SELECT_NETWORK ", 15) == 0) {
9684 if (wpa_supplicant_ctrl_iface_select_network(wpa_s
, buf
+ 15))
9686 } else if (os_strncmp(buf
, "ENABLE_NETWORK ", 15) == 0) {
9687 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s
, buf
+ 15))
9689 } else if (os_strncmp(buf
, "DISABLE_NETWORK ", 16) == 0) {
9690 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s
, buf
+ 16))
9692 } else if (os_strcmp(buf
, "ADD_NETWORK") == 0) {
9693 reply_len
= wpa_supplicant_ctrl_iface_add_network(
9694 wpa_s
, reply
, reply_size
);
9695 } else if (os_strncmp(buf
, "REMOVE_NETWORK ", 15) == 0) {
9696 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s
, buf
+ 15))
9698 } else if (os_strncmp(buf
, "SET_NETWORK ", 12) == 0) {
9699 if (wpa_supplicant_ctrl_iface_set_network(wpa_s
, buf
+ 12))
9701 } else if (os_strncmp(buf
, "GET_NETWORK ", 12) == 0) {
9702 reply_len
= wpa_supplicant_ctrl_iface_get_network(
9703 wpa_s
, buf
+ 12, reply
, reply_size
);
9704 } else if (os_strncmp(buf
, "DUP_NETWORK ", 12) == 0) {
9705 if (wpa_supplicant_ctrl_iface_dup_network(wpa_s
, buf
+ 12,
9708 } else if (os_strcmp(buf
, "LIST_CREDS") == 0) {
9709 reply_len
= wpa_supplicant_ctrl_iface_list_creds(
9710 wpa_s
, reply
, reply_size
);
9711 } else if (os_strcmp(buf
, "ADD_CRED") == 0) {
9712 reply_len
= wpa_supplicant_ctrl_iface_add_cred(
9713 wpa_s
, reply
, reply_size
);
9714 } else if (os_strncmp(buf
, "REMOVE_CRED ", 12) == 0) {
9715 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s
, buf
+ 12))
9717 } else if (os_strncmp(buf
, "SET_CRED ", 9) == 0) {
9718 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s
, buf
+ 9))
9720 } else if (os_strncmp(buf
, "GET_CRED ", 9) == 0) {
9721 reply_len
= wpa_supplicant_ctrl_iface_get_cred(wpa_s
, buf
+ 9,
9724 #ifndef CONFIG_NO_CONFIG_WRITE
9725 } else if (os_strcmp(buf
, "SAVE_CONFIG") == 0) {
9726 if (wpa_supplicant_ctrl_iface_save_config(wpa_s
))
9728 #endif /* CONFIG_NO_CONFIG_WRITE */
9729 } else if (os_strncmp(buf
, "GET_CAPABILITY ", 15) == 0) {
9730 reply_len
= wpa_supplicant_ctrl_iface_get_capability(
9731 wpa_s
, buf
+ 15, reply
, reply_size
);
9732 } else if (os_strncmp(buf
, "AP_SCAN ", 8) == 0) {
9733 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s
, buf
+ 8))
9735 } else if (os_strncmp(buf
, "SCAN_INTERVAL ", 14) == 0) {
9736 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s
, buf
+ 14))
9738 } else if (os_strcmp(buf
, "INTERFACE_LIST") == 0) {
9739 reply_len
= wpa_supplicant_global_iface_list(
9740 wpa_s
->global
, reply
, reply_size
);
9741 } else if (os_strncmp(buf
, "INTERFACES", 10) == 0) {
9742 reply_len
= wpa_supplicant_global_iface_interfaces(
9743 wpa_s
->global
, buf
+ 10, reply
, reply_size
);
9744 } else if (os_strncmp(buf
, "BSS ", 4) == 0) {
9745 reply_len
= wpa_supplicant_ctrl_iface_bss(
9746 wpa_s
, buf
+ 4, reply
, reply_size
);
9748 } else if (os_strcmp(buf
, "STA-FIRST") == 0) {
9749 reply_len
= ap_ctrl_iface_sta_first(wpa_s
, reply
, reply_size
);
9750 } else if (os_strncmp(buf
, "STA ", 4) == 0) {
9751 reply_len
= ap_ctrl_iface_sta(wpa_s
, buf
+ 4, reply
,
9753 } else if (os_strncmp(buf
, "STA-NEXT ", 9) == 0) {
9754 reply_len
= ap_ctrl_iface_sta_next(wpa_s
, buf
+ 9, reply
,
9756 } else if (os_strncmp(buf
, "DEAUTHENTICATE ", 15) == 0) {
9757 if (ap_ctrl_iface_sta_deauthenticate(wpa_s
, buf
+ 15))
9759 } else if (os_strncmp(buf
, "DISASSOCIATE ", 13) == 0) {
9760 if (ap_ctrl_iface_sta_disassociate(wpa_s
, buf
+ 13))
9762 } else if (os_strncmp(buf
, "CHAN_SWITCH ", 12) == 0) {
9763 if (ap_ctrl_iface_chanswitch(wpa_s
, buf
+ 12))
9765 } else if (os_strcmp(buf
, "STOP_AP") == 0) {
9766 if (wpas_ap_stop_ap(wpa_s
))
9768 #endif /* CONFIG_AP */
9769 } else if (os_strcmp(buf
, "SUSPEND") == 0) {
9770 wpas_notify_suspend(wpa_s
->global
);
9771 } else if (os_strcmp(buf
, "RESUME") == 0) {
9772 wpas_notify_resume(wpa_s
->global
);
9773 #ifdef CONFIG_TESTING_OPTIONS
9774 } else if (os_strcmp(buf
, "DROP_SA") == 0) {
9775 wpa_supplicant_ctrl_iface_drop_sa(wpa_s
);
9776 #endif /* CONFIG_TESTING_OPTIONS */
9777 } else if (os_strncmp(buf
, "ROAM ", 5) == 0) {
9778 if (wpa_supplicant_ctrl_iface_roam(wpa_s
, buf
+ 5))
9780 } else if (os_strncmp(buf
, "STA_AUTOCONNECT ", 16) == 0) {
9781 wpa_s
->auto_reconnect_disabled
= atoi(buf
+ 16) == 0;
9782 } else if (os_strncmp(buf
, "BSS_EXPIRE_AGE ", 15) == 0) {
9783 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s
, buf
+ 15))
9785 } else if (os_strncmp(buf
, "BSS_EXPIRE_COUNT ", 17) == 0) {
9786 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s
,
9789 } else if (os_strncmp(buf
, "BSS_FLUSH ", 10) == 0) {
9790 wpa_supplicant_ctrl_iface_bss_flush(wpa_s
, buf
+ 10);
9792 } else if (os_strncmp(buf
, "TDLS_DISCOVER ", 14) == 0) {
9793 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s
, buf
+ 14))
9795 } else if (os_strncmp(buf
, "TDLS_SETUP ", 11) == 0) {
9796 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s
, buf
+ 11))
9798 } else if (os_strncmp(buf
, "TDLS_TEARDOWN ", 14) == 0) {
9799 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s
, buf
+ 14))
9801 } else if (os_strncmp(buf
, "TDLS_CHAN_SWITCH ", 17) == 0) {
9802 if (wpa_supplicant_ctrl_iface_tdls_chan_switch(wpa_s
,
9805 } else if (os_strncmp(buf
, "TDLS_CANCEL_CHAN_SWITCH ", 24) == 0) {
9806 if (wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(wpa_s
,
9809 } else if (os_strncmp(buf
, "TDLS_LINK_STATUS ", 17) == 0) {
9810 reply_len
= wpa_supplicant_ctrl_iface_tdls_link_status(
9811 wpa_s
, buf
+ 17, reply
, reply_size
);
9812 #endif /* CONFIG_TDLS */
9813 } else if (os_strcmp(buf
, "WMM_AC_STATUS") == 0) {
9814 reply_len
= wpas_wmm_ac_status(wpa_s
, reply
, reply_size
);
9815 } else if (os_strncmp(buf
, "WMM_AC_ADDTS ", 13) == 0) {
9816 if (wmm_ac_ctrl_addts(wpa_s
, buf
+ 13))
9818 } else if (os_strncmp(buf
, "WMM_AC_DELTS ", 13) == 0) {
9819 if (wmm_ac_ctrl_delts(wpa_s
, buf
+ 13))
9821 } else if (os_strncmp(buf
, "SIGNAL_POLL", 11) == 0) {
9822 reply_len
= wpa_supplicant_signal_poll(wpa_s
, reply
,
9824 } else if (os_strncmp(buf
, "SIGNAL_MONITOR", 14) == 0) {
9825 if (wpas_ctrl_iface_signal_monitor(wpa_s
, buf
+ 14))
9827 } else if (os_strncmp(buf
, "PKTCNT_POLL", 11) == 0) {
9828 reply_len
= wpa_supplicant_pktcnt_poll(wpa_s
, reply
,
9830 #ifdef CONFIG_AUTOSCAN
9831 } else if (os_strncmp(buf
, "AUTOSCAN ", 9) == 0) {
9832 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s
, buf
+ 9))
9834 #endif /* CONFIG_AUTOSCAN */
9835 } else if (os_strcmp(buf
, "DRIVER_FLAGS") == 0) {
9836 reply_len
= wpas_ctrl_iface_driver_flags(wpa_s
, reply
,
9839 } else if (os_strncmp(buf
, "DRIVER ", 7) == 0) {
9840 reply_len
= wpa_supplicant_driver_cmd(wpa_s
, buf
+ 7, reply
,
9842 #endif /* ANDROID */
9843 } else if (os_strncmp(buf
, "VENDOR ", 7) == 0) {
9844 reply_len
= wpa_supplicant_vendor_cmd(wpa_s
, buf
+ 7, reply
,
9846 } else if (os_strcmp(buf
, "REAUTHENTICATE") == 0) {
9847 pmksa_cache_clear_current(wpa_s
->wpa
);
9848 eapol_sm_request_reauth(wpa_s
->eapol
);
9850 } else if (os_strncmp(buf
, "WNM_SLEEP ", 10) == 0) {
9851 if (wpas_ctrl_iface_wnm_sleep(wpa_s
, buf
+ 10))
9853 } else if (os_strncmp(buf
, "WNM_BSS_QUERY ", 14) == 0) {
9854 if (wpas_ctrl_iface_wnm_bss_query(wpa_s
, buf
+ 14))
9856 #endif /* CONFIG_WNM */
9857 } else if (os_strcmp(buf
, "FLUSH") == 0) {
9858 wpa_supplicant_ctrl_iface_flush(wpa_s
);
9859 } else if (os_strncmp(buf
, "RADIO_WORK ", 11) == 0) {
9860 reply_len
= wpas_ctrl_radio_work(wpa_s
, buf
+ 11, reply
,
9862 #ifdef CONFIG_TESTING_OPTIONS
9863 } else if (os_strncmp(buf
, "MGMT_TX ", 8) == 0) {
9864 if (wpas_ctrl_iface_mgmt_tx(wpa_s
, buf
+ 8) < 0)
9866 } else if (os_strcmp(buf
, "MGMT_TX_DONE") == 0) {
9867 wpas_ctrl_iface_mgmt_tx_done(wpa_s
);
9868 } else if (os_strncmp(buf
, "MGMT_RX_PROCESS ", 16) == 0) {
9869 if (wpas_ctrl_iface_mgmt_rx_process(wpa_s
, buf
+ 16) < 0)
9871 } else if (os_strncmp(buf
, "DRIVER_EVENT ", 13) == 0) {
9872 if (wpas_ctrl_iface_driver_event(wpa_s
, buf
+ 13) < 0)
9874 } else if (os_strncmp(buf
, "EAPOL_RX ", 9) == 0) {
9875 if (wpas_ctrl_iface_eapol_rx(wpa_s
, buf
+ 9) < 0)
9877 } else if (os_strncmp(buf
, "DATA_TEST_CONFIG ", 17) == 0) {
9878 if (wpas_ctrl_iface_data_test_config(wpa_s
, buf
+ 17) < 0)
9880 } else if (os_strncmp(buf
, "DATA_TEST_TX ", 13) == 0) {
9881 if (wpas_ctrl_iface_data_test_tx(wpa_s
, buf
+ 13) < 0)
9883 } else if (os_strncmp(buf
, "DATA_TEST_FRAME ", 16) == 0) {
9884 if (wpas_ctrl_iface_data_test_frame(wpa_s
, buf
+ 16) < 0)
9886 } else if (os_strncmp(buf
, "TEST_ALLOC_FAIL ", 16) == 0) {
9887 if (wpas_ctrl_test_alloc_fail(wpa_s
, buf
+ 16) < 0)
9889 } else if (os_strcmp(buf
, "GET_ALLOC_FAIL") == 0) {
9890 reply_len
= wpas_ctrl_get_alloc_fail(wpa_s
, reply
, reply_size
);
9891 } else if (os_strncmp(buf
, "TEST_FAIL ", 10) == 0) {
9892 if (wpas_ctrl_test_fail(wpa_s
, buf
+ 10) < 0)
9894 } else if (os_strcmp(buf
, "GET_FAIL") == 0) {
9895 reply_len
= wpas_ctrl_get_fail(wpa_s
, reply
, reply_size
);
9896 } else if (os_strncmp(buf
, "EVENT_TEST ", 11) == 0) {
9897 if (wpas_ctrl_event_test(wpa_s
, buf
+ 11) < 0)
9899 } else if (os_strncmp(buf
, "TEST_ASSOC_IE ", 14) == 0) {
9900 if (wpas_ctrl_test_assoc_ie(wpa_s
, buf
+ 14) < 0)
9902 #endif /* CONFIG_TESTING_OPTIONS */
9903 } else if (os_strncmp(buf
, "VENDOR_ELEM_ADD ", 16) == 0) {
9904 if (wpas_ctrl_vendor_elem_add(wpa_s
, buf
+ 16) < 0)
9906 } else if (os_strncmp(buf
, "VENDOR_ELEM_GET ", 16) == 0) {
9907 reply_len
= wpas_ctrl_vendor_elem_get(wpa_s
, buf
+ 16, reply
,
9909 } else if (os_strncmp(buf
, "VENDOR_ELEM_REMOVE ", 19) == 0) {
9910 if (wpas_ctrl_vendor_elem_remove(wpa_s
, buf
+ 19) < 0)
9912 } else if (os_strncmp(buf
, "NEIGHBOR_REP_REQUEST", 20) == 0) {
9913 if (wpas_ctrl_iface_send_neighbor_rep(wpa_s
, buf
+ 20))
9915 } else if (os_strcmp(buf
, "ERP_FLUSH") == 0) {
9916 wpas_ctrl_iface_erp_flush(wpa_s
);
9917 } else if (os_strncmp(buf
, "MAC_RAND_SCAN ", 14) == 0) {
9918 if (wpas_ctrl_iface_mac_rand_scan(wpa_s
, buf
+ 14))
9920 } else if (os_strncmp(buf
, "GET_PREF_FREQ_LIST ", 19) == 0) {
9921 reply_len
= wpas_ctrl_iface_get_pref_freq_list(
9922 wpa_s
, buf
+ 19, reply
, reply_size
);
9924 } else if (os_strncmp(buf
, "FILS_HLP_REQ_ADD ", 17) == 0) {
9925 if (wpas_ctrl_iface_fils_hlp_req_add(wpa_s
, buf
+ 17))
9927 } else if (os_strcmp(buf
, "FILS_HLP_REQ_FLUSH") == 0) {
9928 wpas_flush_fils_hlp_req(wpa_s
);
9929 #endif /* CONFIG_FILS */
9931 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
9935 if (reply_len
< 0) {
9936 os_memcpy(reply
, "FAIL\n", 5);
9940 *resp_len
= reply_len
;
9945 static int wpa_supplicant_global_iface_add(struct wpa_global
*global
,
9948 struct wpa_interface iface
;
9950 struct wpa_supplicant
*wpa_s
;
9951 unsigned int create_iface
= 0;
9952 u8 mac_addr
[ETH_ALEN
];
9953 enum wpa_driver_if_type type
= WPA_IF_STATION
;
9956 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
9957 * TAB<bridge_ifname>[TAB<create>[TAB<interface_type>]]
9959 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd
);
9961 os_memset(&iface
, 0, sizeof(iface
));
9964 iface
.ifname
= pos
= cmd
;
9965 pos
= os_strchr(pos
, '\t');
9968 if (iface
.ifname
[0] == '\0')
9973 iface
.confname
= pos
;
9974 pos
= os_strchr(pos
, '\t');
9977 if (iface
.confname
[0] == '\0')
9978 iface
.confname
= NULL
;
9983 pos
= os_strchr(pos
, '\t');
9986 if (iface
.driver
[0] == '\0')
9987 iface
.driver
= NULL
;
9991 iface
.ctrl_interface
= pos
;
9992 pos
= os_strchr(pos
, '\t');
9995 if (iface
.ctrl_interface
[0] == '\0')
9996 iface
.ctrl_interface
= NULL
;
10000 iface
.driver_param
= pos
;
10001 pos
= os_strchr(pos
, '\t');
10004 if (iface
.driver_param
[0] == '\0')
10005 iface
.driver_param
= NULL
;
10009 iface
.bridge_ifname
= pos
;
10010 pos
= os_strchr(pos
, '\t');
10013 if (iface
.bridge_ifname
[0] == '\0')
10014 iface
.bridge_ifname
= NULL
;
10019 pos
= os_strchr(pos
, '\t');
10025 if (os_strcmp(extra
, "create") == 0) {
10030 if (os_strcmp(pos
, "sta") == 0) {
10031 type
= WPA_IF_STATION
;
10032 } else if (os_strcmp(pos
, "ap") == 0) {
10033 type
= WPA_IF_AP_BSS
;
10035 wpa_printf(MSG_DEBUG
,
10036 "INTERFACE_ADD unsupported interface type: '%s'",
10041 wpa_printf(MSG_DEBUG
,
10042 "INTERFACE_ADD unsupported extra parameter: '%s'",
10048 if (create_iface
) {
10049 wpa_printf(MSG_DEBUG
, "CTRL_IFACE creating interface '%s'",
10051 if (!global
->ifaces
)
10053 if (wpa_drv_if_add(global
->ifaces
, type
, iface
.ifname
,
10054 NULL
, NULL
, NULL
, mac_addr
, NULL
) < 0) {
10055 wpa_printf(MSG_ERROR
,
10056 "CTRL_IFACE interface creation failed");
10060 wpa_printf(MSG_DEBUG
,
10061 "CTRL_IFACE interface '%s' created with MAC addr: "
10062 MACSTR
, iface
.ifname
, MAC2STR(mac_addr
));
10065 if (wpa_supplicant_get_iface(global
, iface
.ifname
))
10068 wpa_s
= wpa_supplicant_add_iface(global
, &iface
, NULL
);
10071 wpa_s
->added_vif
= create_iface
;
10076 wpa_drv_if_remove(global
->ifaces
, WPA_IF_STATION
, iface
.ifname
);
10081 static int wpa_supplicant_global_iface_remove(struct wpa_global
*global
,
10084 struct wpa_supplicant
*wpa_s
;
10086 unsigned int delete_iface
;
10088 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd
);
10090 wpa_s
= wpa_supplicant_get_iface(global
, cmd
);
10093 delete_iface
= wpa_s
->added_vif
;
10094 ret
= wpa_supplicant_remove_iface(global
, wpa_s
, 0);
10095 if (!ret
&& delete_iface
) {
10096 wpa_printf(MSG_DEBUG
, "CTRL_IFACE deleting the interface '%s'",
10098 ret
= wpa_drv_if_remove(global
->ifaces
, WPA_IF_STATION
, cmd
);
10104 static void wpa_free_iface_info(struct wpa_interface_info
*iface
)
10106 struct wpa_interface_info
*prev
;
10110 iface
= iface
->next
;
10112 os_free(prev
->ifname
);
10113 os_free(prev
->desc
);
10119 static int wpa_supplicant_global_iface_list(struct wpa_global
*global
,
10120 char *buf
, int len
)
10123 struct wpa_interface_info
*iface
= NULL
, *last
= NULL
, *tmp
;
10126 for (i
= 0; wpa_drivers
[i
]; i
++) {
10127 const struct wpa_driver_ops
*drv
= wpa_drivers
[i
];
10128 if (drv
->get_interfaces
== NULL
)
10130 tmp
= drv
->get_interfaces(global
->drv_priv
[i
]);
10135 iface
= last
= tmp
;
10144 for (tmp
= iface
; tmp
; tmp
= tmp
->next
) {
10145 res
= os_snprintf(pos
, end
- pos
, "%s\t%s\t%s\n",
10146 tmp
->drv_name
, tmp
->ifname
,
10147 tmp
->desc
? tmp
->desc
: "");
10148 if (os_snprintf_error(end
- pos
, res
)) {
10155 wpa_free_iface_info(iface
);
10161 static int wpa_supplicant_global_iface_interfaces(struct wpa_global
*global
,
10163 char *buf
, int len
)
10167 struct wpa_supplicant
*wpa_s
;
10171 show_ctrl
= !!os_strstr(input
, "ctrl");
10173 wpa_s
= global
->ifaces
;
10179 res
= os_snprintf(pos
, end
- pos
, "%s ctrl_iface=%s\n",
10181 wpa_s
->conf
->ctrl_interface
?
10182 wpa_s
->conf
->ctrl_interface
: "N/A");
10184 res
= os_snprintf(pos
, end
- pos
, "%s\n",
10187 if (os_snprintf_error(end
- pos
, res
)) {
10192 wpa_s
= wpa_s
->next
;
10198 static char * wpas_global_ctrl_iface_ifname(struct wpa_global
*global
,
10199 const char *ifname
,
10200 char *cmd
, size_t *resp_len
)
10202 struct wpa_supplicant
*wpa_s
;
10204 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
10205 if (os_strcmp(ifname
, wpa_s
->ifname
) == 0)
10209 if (wpa_s
== NULL
) {
10210 char *resp
= os_strdup("FAIL-NO-IFNAME-MATCH\n");
10212 *resp_len
= os_strlen(resp
);
10218 return wpa_supplicant_ctrl_iface_process(wpa_s
, cmd
, resp_len
);
10222 static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global
*global
,
10223 char *buf
, size_t *resp_len
)
10226 static const char * cmd
[] = {
10232 "P2P_GET_PASSPHRASE",
10233 "P2P_SERVICE_UPDATE",
10234 "P2P_SERVICE_FLUSH",
10237 "P2P_PRESENCE_REQ",
10241 #endif /* CONFIG_AP */
10244 static const char * prefix
[] = {
10247 #endif /* ANDROID */
10253 "P2P_GROUP_REMOVE ",
10255 "P2P_GROUP_MEMBER ",
10257 "P2P_SERV_DISC_REQ ",
10258 "P2P_SERV_DISC_CANCEL_REQ ",
10259 "P2P_SERV_DISC_RESP ",
10260 "P2P_SERV_DISC_EXTERNAL ",
10261 "P2P_SERVICE_ADD ",
10262 "P2P_SERVICE_DEL ",
10263 "P2P_SERVICE_REP ",
10268 "P2P_UNAUTHORIZE ",
10269 "P2P_PRESENCE_REQ ",
10271 "P2P_REMOVE_CLIENT ",
10273 "WPS_NFC_TAG_READ ",
10274 "NFC_GET_HANDOVER_SEL ",
10275 "NFC_GET_HANDOVER_REQ ",
10276 "NFC_REPORT_HANDOVER ",
10277 "P2P_ASP_PROVISION ",
10278 "P2P_ASP_PROVISION_RESP ",
10282 #endif /* CONFIG_AP */
10288 if (global
->p2p_init_wpa_s
== NULL
)
10291 for (i
= 0; !found
&& cmd
[i
]; i
++) {
10292 if (os_strcmp(buf
, cmd
[i
]) == 0)
10296 for (i
= 0; !found
&& prefix
[i
]; i
++) {
10297 if (os_strncmp(buf
, prefix
[i
], os_strlen(prefix
[i
])) == 0)
10302 return wpa_supplicant_ctrl_iface_process(global
->p2p_init_wpa_s
,
10304 #endif /* CONFIG_P2P */
10309 static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global
*global
,
10310 char *buf
, size_t *resp_len
)
10312 #ifdef CONFIG_WIFI_DISPLAY
10313 if (global
->p2p_init_wpa_s
== NULL
)
10315 if (os_strncmp(buf
, "WFD_SUBELEM_SET ", 16) == 0 ||
10316 os_strncmp(buf
, "WFD_SUBELEM_GET ", 16) == 0)
10317 return wpa_supplicant_ctrl_iface_process(global
->p2p_init_wpa_s
,
10319 #endif /* CONFIG_WIFI_DISPLAY */
10324 static char * wpas_global_ctrl_iface_redir(struct wpa_global
*global
,
10325 char *buf
, size_t *resp_len
)
10329 ret
= wpas_global_ctrl_iface_redir_p2p(global
, buf
, resp_len
);
10333 ret
= wpas_global_ctrl_iface_redir_wfd(global
, buf
, resp_len
);
10341 static int wpas_global_ctrl_iface_set(struct wpa_global
*global
, char *cmd
)
10345 value
= os_strchr(cmd
, ' ');
10350 wpa_printf(MSG_DEBUG
, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd
, value
);
10352 #ifdef CONFIG_WIFI_DISPLAY
10353 if (os_strcasecmp(cmd
, "wifi_display") == 0) {
10354 wifi_display_enable(global
, !!atoi(value
));
10357 #endif /* CONFIG_WIFI_DISPLAY */
10359 /* Restore cmd to its original value to allow redirection */
10366 static int wpas_global_ctrl_iface_dup_network(struct wpa_global
*global
,
10369 struct wpa_supplicant
*wpa_s
[2]; /* src, dst */
10373 /* cmd: "<src ifname> <dst ifname> <src network id> <dst network id>
10374 * <variable name> */
10376 for (i
= 0; i
< ARRAY_SIZE(wpa_s
) ; i
++) {
10377 p
= os_strchr(cmd
, ' ');
10382 wpa_s
[i
] = global
->ifaces
;
10383 for (; wpa_s
[i
]; wpa_s
[i
] = wpa_s
[i
]->next
) {
10384 if (os_strcmp(cmd
, wpa_s
[i
]->ifname
) == 0)
10389 wpa_printf(MSG_DEBUG
,
10390 "CTRL_IFACE: Could not find iface=%s", cmd
);
10397 return wpa_supplicant_ctrl_iface_dup_network(wpa_s
[0], cmd
, wpa_s
[1]);
10401 #ifndef CONFIG_NO_CONFIG_WRITE
10402 static int wpas_global_ctrl_iface_save_config(struct wpa_global
*global
)
10404 int ret
= 0, saved
= 0;
10405 struct wpa_supplicant
*wpa_s
;
10407 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
10408 if (!wpa_s
->conf
->update_config
) {
10409 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
10413 if (wpa_config_write(wpa_s
->confname
, wpa_s
->conf
)) {
10414 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
10417 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
10422 if (!saved
&& !ret
) {
10423 wpa_dbg(wpa_s
, MSG_DEBUG
,
10424 "CTRL_IFACE: SAVE_CONFIG - No configuration files could be updated");
10430 #endif /* CONFIG_NO_CONFIG_WRITE */
10433 static int wpas_global_ctrl_iface_status(struct wpa_global
*global
,
10434 char *buf
, size_t buflen
)
10438 struct wpa_supplicant
*wpa_s
;
10441 end
= buf
+ buflen
;
10444 if (global
->p2p
&& !global
->p2p_disabled
) {
10445 ret
= os_snprintf(pos
, end
- pos
, "p2p_device_address=" MACSTR
10448 MAC2STR(global
->p2p_dev_addr
),
10449 p2p_get_state_txt(global
->p2p
));
10450 if (os_snprintf_error(end
- pos
, ret
))
10453 } else if (global
->p2p
) {
10454 ret
= os_snprintf(pos
, end
- pos
, "p2p_state=DISABLED\n");
10455 if (os_snprintf_error(end
- pos
, ret
))
10459 #endif /* CONFIG_P2P */
10461 #ifdef CONFIG_WIFI_DISPLAY
10462 ret
= os_snprintf(pos
, end
- pos
, "wifi_display=%d\n",
10463 !!global
->wifi_display
);
10464 if (os_snprintf_error(end
- pos
, ret
))
10467 #endif /* CONFIG_WIFI_DISPLAY */
10469 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
10470 ret
= os_snprintf(pos
, end
- pos
, "ifname=%s\n"
10471 "address=" MACSTR
"\n",
10472 wpa_s
->ifname
, MAC2STR(wpa_s
->own_addr
));
10473 if (os_snprintf_error(end
- pos
, ret
))
10484 static int wpas_global_ctrl_iface_fst_attach(struct wpa_global
*global
,
10485 char *cmd
, char *buf
,
10488 char ifname
[IFNAMSIZ
+ 1];
10489 struct fst_iface_cfg cfg
;
10490 struct wpa_supplicant
*wpa_s
;
10491 struct fst_wpa_obj iface_obj
;
10493 if (!fst_parse_attach_command(cmd
, ifname
, sizeof(ifname
), &cfg
)) {
10494 wpa_s
= wpa_supplicant_get_iface(global
, ifname
);
10497 wpa_printf(MSG_INFO
, "FST: Already attached");
10500 fst_wpa_supplicant_fill_iface_obj(wpa_s
, &iface_obj
);
10501 wpa_s
->fst
= fst_attach(ifname
, wpa_s
->own_addr
,
10504 return os_snprintf(buf
, reply_size
, "OK\n");
10512 static int wpas_global_ctrl_iface_fst_detach(struct wpa_global
*global
,
10513 char *cmd
, char *buf
,
10516 char ifname
[IFNAMSIZ
+ 1];
10517 struct wpa_supplicant
*wpa_s
;
10519 if (!fst_parse_detach_command(cmd
, ifname
, sizeof(ifname
))) {
10520 wpa_s
= wpa_supplicant_get_iface(global
, ifname
);
10522 if (!fst_iface_detach(ifname
)) {
10524 return os_snprintf(buf
, reply_size
, "OK\n");
10532 #endif /* CONFIG_FST */
10535 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global
*global
,
10536 char *buf
, size_t *resp_len
)
10539 const int reply_size
= 2048;
10541 int level
= MSG_DEBUG
;
10543 if (os_strncmp(buf
, "IFNAME=", 7) == 0) {
10544 char *pos
= os_strchr(buf
+ 7, ' ');
10547 return wpas_global_ctrl_iface_ifname(global
,
10553 reply
= wpas_global_ctrl_iface_redir(global
, buf
, resp_len
);
10557 if (os_strcmp(buf
, "PING") == 0)
10558 level
= MSG_EXCESSIVE
;
10559 wpa_hexdump_ascii(level
, "RX global ctrl_iface",
10560 (const u8
*) buf
, os_strlen(buf
));
10562 reply
= os_malloc(reply_size
);
10563 if (reply
== NULL
) {
10568 os_memcpy(reply
, "OK\n", 3);
10571 if (os_strcmp(buf
, "PING") == 0) {
10572 os_memcpy(reply
, "PONG\n", 5);
10574 } else if (os_strncmp(buf
, "INTERFACE_ADD ", 14) == 0) {
10575 if (wpa_supplicant_global_iface_add(global
, buf
+ 14))
10577 } else if (os_strncmp(buf
, "INTERFACE_REMOVE ", 17) == 0) {
10578 if (wpa_supplicant_global_iface_remove(global
, buf
+ 17))
10580 } else if (os_strcmp(buf
, "INTERFACE_LIST") == 0) {
10581 reply_len
= wpa_supplicant_global_iface_list(
10582 global
, reply
, reply_size
);
10583 } else if (os_strncmp(buf
, "INTERFACES", 10) == 0) {
10584 reply_len
= wpa_supplicant_global_iface_interfaces(
10585 global
, buf
+ 10, reply
, reply_size
);
10587 } else if (os_strncmp(buf
, "FST-ATTACH ", 11) == 0) {
10588 reply_len
= wpas_global_ctrl_iface_fst_attach(global
, buf
+ 11,
10591 } else if (os_strncmp(buf
, "FST-DETACH ", 11) == 0) {
10592 reply_len
= wpas_global_ctrl_iface_fst_detach(global
, buf
+ 11,
10595 } else if (os_strncmp(buf
, "FST-MANAGER ", 12) == 0) {
10596 reply_len
= fst_ctrl_iface_receive(buf
+ 12, reply
, reply_size
);
10597 #endif /* CONFIG_FST */
10598 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
10599 wpa_supplicant_terminate_proc(global
);
10600 } else if (os_strcmp(buf
, "SUSPEND") == 0) {
10601 wpas_notify_suspend(global
);
10602 } else if (os_strcmp(buf
, "RESUME") == 0) {
10603 wpas_notify_resume(global
);
10604 } else if (os_strncmp(buf
, "SET ", 4) == 0) {
10605 if (wpas_global_ctrl_iface_set(global
, buf
+ 4)) {
10607 if (global
->p2p_init_wpa_s
) {
10609 /* Check if P2P redirection would work for this
10611 return wpa_supplicant_ctrl_iface_process(
10612 global
->p2p_init_wpa_s
,
10615 #endif /* CONFIG_P2P */
10618 } else if (os_strncmp(buf
, "DUP_NETWORK ", 12) == 0) {
10619 if (wpas_global_ctrl_iface_dup_network(global
, buf
+ 12))
10621 #ifndef CONFIG_NO_CONFIG_WRITE
10622 } else if (os_strcmp(buf
, "SAVE_CONFIG") == 0) {
10623 if (wpas_global_ctrl_iface_save_config(global
))
10625 #endif /* CONFIG_NO_CONFIG_WRITE */
10626 } else if (os_strcmp(buf
, "STATUS") == 0) {
10627 reply_len
= wpas_global_ctrl_iface_status(global
, reply
,
10629 #ifdef CONFIG_MODULE_TESTS
10630 } else if (os_strcmp(buf
, "MODULE_TESTS") == 0) {
10631 if (wpas_module_tests() < 0)
10633 #endif /* CONFIG_MODULE_TESTS */
10634 } else if (os_strncmp(buf
, "RELOG", 5) == 0) {
10635 if (wpa_debug_reopen_file() < 0)
10638 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
10642 if (reply_len
< 0) {
10643 os_memcpy(reply
, "FAIL\n", 5);
10647 *resp_len
= reply_len
;