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
,
370 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigPMKReauthThreshold") ==
372 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_REAUTH_THRESHOLD
,
375 } else if (os_strcasecmp(cmd
, "dot11RSNAConfigSATimeout") == 0) {
376 if (wpa_sm_set_param(wpa_s
->wpa
, RSNA_SA_TIMEOUT
, atoi(value
)))
378 } else if (os_strcasecmp(cmd
, "wps_fragment_size") == 0) {
379 wpa_s
->wps_fragment_size
= atoi(value
);
380 #ifdef CONFIG_WPS_TESTING
381 } else if (os_strcasecmp(cmd
, "wps_version_number") == 0) {
383 val
= strtol(value
, NULL
, 0);
384 if (val
< 0 || val
> 0xff) {
386 wpa_printf(MSG_DEBUG
, "WPS: Invalid "
387 "wps_version_number %ld", val
);
389 wps_version_number
= val
;
390 wpa_printf(MSG_DEBUG
, "WPS: Testing - force WPS "
392 (wps_version_number
& 0xf0) >> 4,
393 wps_version_number
& 0x0f);
395 } else if (os_strcasecmp(cmd
, "wps_testing_dummy_cred") == 0) {
396 wps_testing_dummy_cred
= atoi(value
);
397 wpa_printf(MSG_DEBUG
, "WPS: Testing - dummy_cred=%d",
398 wps_testing_dummy_cred
);
399 } else if (os_strcasecmp(cmd
, "wps_corrupt_pkhash") == 0) {
400 wps_corrupt_pkhash
= atoi(value
);
401 wpa_printf(MSG_DEBUG
, "WPS: Testing - wps_corrupt_pkhash=%d",
403 } else if (os_strcasecmp(cmd
, "wps_force_auth_types") == 0) {
404 if (value
[0] == '\0') {
405 wps_force_auth_types_in_use
= 0;
407 wps_force_auth_types
= strtol(value
, NULL
, 0);
408 wps_force_auth_types_in_use
= 1;
410 } else if (os_strcasecmp(cmd
, "wps_force_encr_types") == 0) {
411 if (value
[0] == '\0') {
412 wps_force_encr_types_in_use
= 0;
414 wps_force_encr_types
= strtol(value
, NULL
, 0);
415 wps_force_encr_types_in_use
= 1;
417 #endif /* CONFIG_WPS_TESTING */
418 } else if (os_strcasecmp(cmd
, "ampdu") == 0) {
419 if (wpa_drv_ampdu(wpa_s
, atoi(value
)) < 0)
422 #ifdef CONFIG_TDLS_TESTING
423 } else if (os_strcasecmp(cmd
, "tdls_testing") == 0) {
424 tdls_testing
= strtol(value
, NULL
, 0);
425 wpa_printf(MSG_DEBUG
, "TDLS: tdls_testing=0x%x", tdls_testing
);
426 #endif /* CONFIG_TDLS_TESTING */
427 } else if (os_strcasecmp(cmd
, "tdls_disabled") == 0) {
428 int disabled
= atoi(value
);
429 wpa_printf(MSG_DEBUG
, "TDLS: tdls_disabled=%d", disabled
);
431 if (wpa_drv_tdls_oper(wpa_s
, TDLS_DISABLE
, NULL
) < 0)
433 } else if (wpa_drv_tdls_oper(wpa_s
, TDLS_ENABLE
, NULL
) < 0)
435 wpa_tdls_enable(wpa_s
->wpa
, !disabled
);
436 #endif /* CONFIG_TDLS */
437 } else if (os_strcasecmp(cmd
, "pno") == 0) {
438 ret
= wpas_ctrl_pno(wpa_s
, value
);
439 } else if (os_strcasecmp(cmd
, "radio_disabled") == 0) {
440 int disabled
= atoi(value
);
441 if (wpa_drv_radio_disable(wpa_s
, disabled
) < 0)
444 wpa_supplicant_set_state(wpa_s
, WPA_INACTIVE
);
445 } else if (os_strcasecmp(cmd
, "uapsd") == 0) {
446 if (os_strcmp(value
, "disable") == 0)
447 wpa_s
->set_sta_uapsd
= 0;
451 /* format: BE,BK,VI,VO;max SP Length */
453 pos
= os_strchr(value
, ',');
458 pos
= os_strchr(pos
, ',');
463 pos
= os_strchr(pos
, ',');
468 /* ignore max SP Length for now */
470 wpa_s
->set_sta_uapsd
= 1;
471 wpa_s
->sta_uapsd
= 0;
473 wpa_s
->sta_uapsd
|= BIT(0);
475 wpa_s
->sta_uapsd
|= BIT(1);
477 wpa_s
->sta_uapsd
|= BIT(2);
479 wpa_s
->sta_uapsd
|= BIT(3);
481 } else if (os_strcasecmp(cmd
, "ps") == 0) {
482 ret
= wpa_drv_set_p2p_powersave(wpa_s
, atoi(value
), -1, -1);
483 #ifdef CONFIG_WIFI_DISPLAY
484 } else if (os_strcasecmp(cmd
, "wifi_display") == 0) {
485 int enabled
= !!atoi(value
);
486 if (enabled
&& !wpa_s
->global
->p2p
)
489 wifi_display_enable(wpa_s
->global
, enabled
);
490 #endif /* CONFIG_WIFI_DISPLAY */
491 } else if (os_strcasecmp(cmd
, "bssid_filter") == 0) {
492 ret
= set_bssid_filter(wpa_s
, value
);
493 } else if (os_strcasecmp(cmd
, "disallow_aps") == 0) {
494 ret
= set_disallow_aps(wpa_s
, value
);
495 } else if (os_strcasecmp(cmd
, "no_keep_alive") == 0) {
496 wpa_s
->no_keep_alive
= !!atoi(value
);
497 #ifdef CONFIG_TESTING_OPTIONS
498 } else if (os_strcasecmp(cmd
, "ext_mgmt_frame_handling") == 0) {
499 wpa_s
->ext_mgmt_frame_handling
= !!atoi(value
);
500 } else if (os_strcasecmp(cmd
, "ext_eapol_frame_io") == 0) {
501 wpa_s
->ext_eapol_frame_io
= !!atoi(value
);
503 if (wpa_s
->ap_iface
) {
504 wpa_s
->ap_iface
->bss
[0]->ext_eapol_frame_io
=
505 wpa_s
->ext_eapol_frame_io
;
507 #endif /* CONFIG_AP */
508 } else if (os_strcasecmp(cmd
, "extra_roc_dur") == 0) {
509 wpa_s
->extra_roc_dur
= atoi(value
);
510 } else if (os_strcasecmp(cmd
, "test_failure") == 0) {
511 wpa_s
->test_failure
= atoi(value
);
512 } else if (os_strcasecmp(cmd
, "p2p_go_csa_on_inv") == 0) {
513 wpa_s
->p2p_go_csa_on_inv
= !!atoi(value
);
514 } else if (os_strcasecmp(cmd
, "ignore_auth_resp") == 0) {
515 wpa_s
->ignore_auth_resp
= !!atoi(value
);
516 } else if (os_strcasecmp(cmd
, "ignore_assoc_disallow") == 0) {
517 wpa_s
->ignore_assoc_disallow
= !!atoi(value
);
518 } else if (os_strcasecmp(cmd
, "reject_btm_req_reason") == 0) {
519 wpa_s
->reject_btm_req_reason
= atoi(value
);
520 #endif /* CONFIG_TESTING_OPTIONS */
521 #ifndef CONFIG_NO_CONFIG_BLOBS
522 } else if (os_strcmp(cmd
, "blob") == 0) {
523 ret
= wpas_ctrl_set_blob(wpa_s
, value
);
524 #endif /* CONFIG_NO_CONFIG_BLOBS */
525 } else if (os_strcasecmp(cmd
, "setband") == 0) {
526 ret
= wpas_ctrl_set_band(wpa_s
, value
);
528 } else if (os_strcasecmp(cmd
, "non_pref_chan") == 0) {
529 ret
= wpas_mbo_update_non_pref_chan(wpa_s
, value
);
530 } else if (os_strcasecmp(cmd
, "mbo_cell_capa") == 0) {
531 wpas_mbo_update_cell_capa(wpa_s
, atoi(value
));
532 #endif /* CONFIG_MBO */
533 } else if (os_strcasecmp(cmd
, "lci") == 0) {
534 ret
= wpas_ctrl_iface_set_lci(wpa_s
, value
);
537 ret
= wpa_config_process_global(wpa_s
->conf
, cmd
, -1);
539 wpa_supplicant_update_config(wpa_s
);
546 static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant
*wpa_s
,
547 char *cmd
, char *buf
, size_t buflen
)
551 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GET '%s'", cmd
);
553 if (os_strcmp(cmd
, "version") == 0) {
554 res
= os_snprintf(buf
, buflen
, "%s", VERSION_STR
);
555 } else if (os_strcasecmp(cmd
, "country") == 0) {
556 if (wpa_s
->conf
->country
[0] && wpa_s
->conf
->country
[1])
557 res
= os_snprintf(buf
, buflen
, "%c%c",
558 wpa_s
->conf
->country
[0],
559 wpa_s
->conf
->country
[1]);
560 #ifdef CONFIG_WIFI_DISPLAY
561 } else if (os_strcasecmp(cmd
, "wifi_display") == 0) {
563 if (wpa_s
->global
->p2p
== NULL
||
564 wpa_s
->global
->p2p_disabled
)
567 enabled
= wpa_s
->global
->wifi_display
;
568 res
= os_snprintf(buf
, buflen
, "%d", enabled
);
569 #endif /* CONFIG_WIFI_DISPLAY */
570 #ifdef CONFIG_TESTING_GET_GTK
571 } else if (os_strcmp(cmd
, "gtk") == 0) {
572 if (wpa_s
->last_gtk_len
== 0)
574 res
= wpa_snprintf_hex(buf
, buflen
, wpa_s
->last_gtk
,
575 wpa_s
->last_gtk_len
);
577 #endif /* CONFIG_TESTING_GET_GTK */
578 } else if (os_strcmp(cmd
, "tls_library") == 0) {
579 res
= tls_get_library_version(buf
, buflen
);
581 res
= wpa_config_get_value(cmd
, wpa_s
->conf
, buf
, buflen
);
584 if (os_snprintf_error(buflen
, res
))
590 #ifdef IEEE8021X_EAPOL
591 static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant
*wpa_s
,
595 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
597 if (hwaddr_aton(addr
, bssid
)) {
598 wpa_printf(MSG_DEBUG
, "CTRL_IFACE PREAUTH: invalid address "
603 wpa_printf(MSG_DEBUG
, "CTRL_IFACE PREAUTH " MACSTR
, MAC2STR(bssid
));
604 rsn_preauth_deinit(wpa_s
->wpa
);
605 if (rsn_preauth_init(wpa_s
->wpa
, bssid
, ssid
? &ssid
->eap
: NULL
))
610 #endif /* IEEE8021X_EAPOL */
613 #ifdef CONFIG_PEERKEY
614 /* MLME-STKSTART.request(peer) */
615 static int wpa_supplicant_ctrl_iface_stkstart(
616 struct wpa_supplicant
*wpa_s
, char *addr
)
620 if (hwaddr_aton(addr
, peer
)) {
621 wpa_printf(MSG_DEBUG
, "CTRL_IFACE STKSTART: invalid "
622 "address '%s'", addr
);
626 wpa_printf(MSG_DEBUG
, "CTRL_IFACE STKSTART " MACSTR
,
629 return wpa_sm_stkstart(wpa_s
->wpa
, peer
);
631 #endif /* CONFIG_PEERKEY */
636 static int wpa_supplicant_ctrl_iface_tdls_discover(
637 struct wpa_supplicant
*wpa_s
, char *addr
)
642 if (hwaddr_aton(addr
, peer
)) {
643 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_DISCOVER: invalid "
644 "address '%s'", addr
);
648 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_DISCOVER " MACSTR
,
651 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
652 ret
= wpa_tdls_send_discovery_request(wpa_s
->wpa
, peer
);
654 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_DISCOVERY_REQ
, peer
);
660 static int wpa_supplicant_ctrl_iface_tdls_setup(
661 struct wpa_supplicant
*wpa_s
, char *addr
)
666 if (hwaddr_aton(addr
, peer
)) {
667 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_SETUP: invalid "
668 "address '%s'", addr
);
672 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_SETUP " MACSTR
,
675 if ((wpa_s
->conf
->tdls_external_control
) &&
676 wpa_tdls_is_external_setup(wpa_s
->wpa
))
677 return wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, peer
);
679 wpa_tdls_remove(wpa_s
->wpa
, peer
);
681 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
682 ret
= wpa_tdls_start(wpa_s
->wpa
, peer
);
684 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_SETUP
, peer
);
690 static int wpa_supplicant_ctrl_iface_tdls_teardown(
691 struct wpa_supplicant
*wpa_s
, char *addr
)
696 if (os_strcmp(addr
, "*") == 0) {
697 /* remove everyone */
698 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN *");
699 wpa_tdls_teardown_peers(wpa_s
->wpa
);
703 if (hwaddr_aton(addr
, peer
)) {
704 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN: invalid "
705 "address '%s'", addr
);
709 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_TEARDOWN " MACSTR
,
712 if ((wpa_s
->conf
->tdls_external_control
) &&
713 wpa_tdls_is_external_setup(wpa_s
->wpa
))
714 return wpa_drv_tdls_oper(wpa_s
, TDLS_TEARDOWN
, peer
);
716 if (wpa_tdls_is_external_setup(wpa_s
->wpa
))
717 ret
= wpa_tdls_teardown_link(
719 WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED
);
721 ret
= wpa_drv_tdls_oper(wpa_s
, TDLS_TEARDOWN
, peer
);
727 static int ctrl_iface_get_capability_tdls(
728 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
732 ret
= os_snprintf(buf
, buflen
, "%s\n",
733 wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_TDLS_SUPPORT
?
735 WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP
?
736 "EXTERNAL" : "INTERNAL") : "UNSUPPORTED");
737 if (os_snprintf_error(buflen
, ret
))
743 static int wpa_supplicant_ctrl_iface_tdls_chan_switch(
744 struct wpa_supplicant
*wpa_s
, char *cmd
)
747 struct hostapd_freq_params freq_params
;
751 if (!wpa_tdls_is_external_setup(wpa_s
->wpa
)) {
753 "tdls_chanswitch: Only supported with external setup");
757 os_memset(&freq_params
, 0, sizeof(freq_params
));
759 pos
= os_strchr(cmd
, ' ');
764 oper_class
= strtol(pos
, &end
, 10);
767 "tdls_chanswitch: Invalid op class provided");
772 freq_params
.freq
= atoi(pos
);
773 if (freq_params
.freq
== 0) {
774 wpa_printf(MSG_INFO
, "tdls_chanswitch: Invalid freq provided");
778 #define SET_FREQ_SETTING(str) \
780 const char *pos2 = os_strstr(pos, " " #str "="); \
782 pos2 += sizeof(" " #str "=") - 1; \
783 freq_params.str = atoi(pos2); \
787 SET_FREQ_SETTING(center_freq1
);
788 SET_FREQ_SETTING(center_freq2
);
789 SET_FREQ_SETTING(bandwidth
);
790 SET_FREQ_SETTING(sec_channel_offset
);
791 #undef SET_FREQ_SETTING
793 freq_params
.ht_enabled
= !!os_strstr(pos
, " ht");
794 freq_params
.vht_enabled
= !!os_strstr(pos
, " vht");
796 if (hwaddr_aton(cmd
, peer
)) {
797 wpa_printf(MSG_DEBUG
,
798 "CTRL_IFACE TDLS_CHAN_SWITCH: Invalid address '%s'",
803 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_CHAN_SWITCH " MACSTR
804 " OP CLASS %d FREQ %d CENTER1 %d CENTER2 %d BW %d SEC_OFFSET %d%s%s",
805 MAC2STR(peer
), oper_class
, freq_params
.freq
,
806 freq_params
.center_freq1
, freq_params
.center_freq2
,
807 freq_params
.bandwidth
, freq_params
.sec_channel_offset
,
808 freq_params
.ht_enabled
? " HT" : "",
809 freq_params
.vht_enabled
? " VHT" : "");
811 return wpa_tdls_enable_chan_switch(wpa_s
->wpa
, peer
, oper_class
,
816 static int wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(
817 struct wpa_supplicant
*wpa_s
, char *cmd
)
821 if (!wpa_tdls_is_external_setup(wpa_s
->wpa
)) {
823 "tdls_chanswitch: Only supported with external setup");
827 if (hwaddr_aton(cmd
, peer
)) {
828 wpa_printf(MSG_DEBUG
,
829 "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH: Invalid address '%s'",
834 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH " MACSTR
,
837 return wpa_tdls_disable_chan_switch(wpa_s
->wpa
, peer
);
841 static int wpa_supplicant_ctrl_iface_tdls_link_status(
842 struct wpa_supplicant
*wpa_s
, const char *addr
,
843 char *buf
, size_t buflen
)
846 const char *tdls_status
;
849 if (hwaddr_aton(addr
, peer
)) {
850 wpa_printf(MSG_DEBUG
,
851 "CTRL_IFACE TDLS_LINK_STATUS: Invalid address '%s'",
855 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_LINK_STATUS " MACSTR
,
858 tdls_status
= wpa_tdls_get_link_status(wpa_s
->wpa
, peer
);
859 wpa_printf(MSG_DEBUG
, "CTRL_IFACE TDLS_LINK_STATUS: %s", tdls_status
);
860 ret
= os_snprintf(buf
, buflen
, "TDLS link status: %s\n", tdls_status
);
861 if (os_snprintf_error(buflen
, ret
))
867 #endif /* CONFIG_TDLS */
870 static int wmm_ac_ctrl_addts(struct wpa_supplicant
*wpa_s
, char *cmd
)
872 char *token
, *context
= NULL
;
873 struct wmm_ac_ts_setup_params params
= {
878 while ((token
= str_token(cmd
, " ", &context
))) {
879 if (sscanf(token
, "tsid=%i", ¶ms
.tsid
) == 1 ||
880 sscanf(token
, "up=%i", ¶ms
.user_priority
) == 1 ||
881 sscanf(token
, "nominal_msdu_size=%i",
882 ¶ms
.nominal_msdu_size
) == 1 ||
883 sscanf(token
, "mean_data_rate=%i",
884 ¶ms
.mean_data_rate
) == 1 ||
885 sscanf(token
, "min_phy_rate=%i",
886 ¶ms
.minimum_phy_rate
) == 1 ||
887 sscanf(token
, "sba=%i",
888 ¶ms
.surplus_bandwidth_allowance
) == 1)
891 if (os_strcasecmp(token
, "downlink") == 0) {
892 params
.direction
= WMM_TSPEC_DIRECTION_DOWNLINK
;
893 } else if (os_strcasecmp(token
, "uplink") == 0) {
894 params
.direction
= WMM_TSPEC_DIRECTION_UPLINK
;
895 } else if (os_strcasecmp(token
, "bidi") == 0) {
896 params
.direction
= WMM_TSPEC_DIRECTION_BI_DIRECTIONAL
;
897 } else if (os_strcasecmp(token
, "fixed_nominal_msdu") == 0) {
898 params
.fixed_nominal_msdu
= 1;
900 wpa_printf(MSG_DEBUG
,
901 "CTRL: Invalid WMM_AC_ADDTS parameter: '%s'",
908 return wpas_wmm_ac_addts(wpa_s
, ¶ms
);
912 static int wmm_ac_ctrl_delts(struct wpa_supplicant
*wpa_s
, char *cmd
)
916 return wpas_wmm_ac_delts(wpa_s
, tsid
);
920 #ifdef CONFIG_IEEE80211R
921 static int wpa_supplicant_ctrl_iface_ft_ds(
922 struct wpa_supplicant
*wpa_s
, char *addr
)
924 u8 target_ap
[ETH_ALEN
];
928 if (hwaddr_aton(addr
, target_ap
)) {
929 wpa_printf(MSG_DEBUG
, "CTRL_IFACE FT_DS: invalid "
930 "address '%s'", addr
);
934 wpa_printf(MSG_DEBUG
, "CTRL_IFACE FT_DS " MACSTR
, MAC2STR(target_ap
));
936 bss
= wpa_bss_get_bssid(wpa_s
, target_ap
);
938 mdie
= wpa_bss_get_ie(bss
, WLAN_EID_MOBILITY_DOMAIN
);
942 return wpa_ft_start_over_ds(wpa_s
->wpa
, target_ap
, mdie
);
944 #endif /* CONFIG_IEEE80211R */
948 static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant
*wpa_s
,
951 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
953 u8 p2p_dev_addr
[ETH_ALEN
];
954 #endif /* CONFIG_P2P */
956 u8
*_p2p_dev_addr
= NULL
;
957 #endif /* CONFIG_AP */
959 if (cmd
== NULL
|| os_strcmp(cmd
, "any") == 0) {
962 } else if (os_strncmp(cmd
, "p2p_dev_addr=", 13) == 0) {
963 if (hwaddr_aton(cmd
+ 13, p2p_dev_addr
)) {
964 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PBC: invalid "
965 "P2P Device Address '%s'",
969 _p2p_dev_addr
= p2p_dev_addr
;
970 #endif /* CONFIG_P2P */
971 } else if (hwaddr_aton(cmd
, bssid
)) {
972 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
979 return wpa_supplicant_ap_wps_pbc(wpa_s
, _bssid
, _p2p_dev_addr
);
980 #endif /* CONFIG_AP */
982 return wpas_wps_start_pbc(wpa_s
, _bssid
, 0);
986 static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant
*wpa_s
,
987 char *cmd
, char *buf
,
990 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
994 pin
= os_strchr(cmd
, ' ');
998 if (os_strcmp(cmd
, "any") == 0)
1000 else if (os_strcmp(cmd
, "get") == 0) {
1001 if (wps_generate_pin((unsigned int *) &ret
) < 0)
1004 } else if (hwaddr_aton(cmd
, bssid
)) {
1005 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
1011 if (wpa_s
->ap_iface
) {
1016 pos
= os_strchr(pin
, ' ');
1019 timeout
= atoi(pos
);
1023 return wpa_supplicant_ap_wps_pin(wpa_s
, _bssid
, pin
,
1024 buf
, buflen
, timeout
);
1026 #endif /* CONFIG_AP */
1029 ret
= wpas_wps_start_pin(wpa_s
, _bssid
, pin
, 0,
1033 ret
= os_snprintf(buf
, buflen
, "%s", pin
);
1034 if (os_snprintf_error(buflen
, ret
))
1039 ret
= wpas_wps_start_pin(wpa_s
, _bssid
, NULL
, 0, DEV_PW_DEFAULT
);
1044 /* Return the generated PIN */
1045 ret
= os_snprintf(buf
, buflen
, "%08d", ret
);
1046 if (os_snprintf_error(buflen
, ret
))
1052 static int wpa_supplicant_ctrl_iface_wps_check_pin(
1053 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
1060 wpa_hexdump_ascii_key(MSG_DEBUG
, "WPS_CHECK_PIN",
1061 (u8
*) cmd
, os_strlen(cmd
));
1062 for (pos
= cmd
, len
= 0; *pos
!= '\0'; pos
++) {
1063 if (*pos
< '0' || *pos
> '9')
1067 wpa_printf(MSG_DEBUG
, "WPS: Too long PIN");
1071 if (len
!= 4 && len
!= 8) {
1072 wpa_printf(MSG_DEBUG
, "WPS: Invalid PIN length %d", (int) len
);
1078 unsigned int pin_val
;
1079 pin_val
= atoi(pin
);
1080 if (!wps_pin_valid(pin_val
)) {
1081 wpa_printf(MSG_DEBUG
, "WPS: Invalid checksum digit");
1082 ret
= os_snprintf(buf
, buflen
, "FAIL-CHECKSUM\n");
1083 if (os_snprintf_error(buflen
, ret
))
1089 ret
= os_snprintf(buf
, buflen
, "%s", pin
);
1090 if (os_snprintf_error(buflen
, ret
))
1097 #ifdef CONFIG_WPS_NFC
1099 static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant
*wpa_s
,
1102 u8 bssid
[ETH_ALEN
], *_bssid
= bssid
;
1104 if (cmd
== NULL
|| cmd
[0] == '\0')
1106 else if (hwaddr_aton(cmd
, bssid
))
1109 return wpas_wps_start_nfc(wpa_s
, NULL
, _bssid
, NULL
, 0, 0, NULL
, NULL
,
1114 static int wpa_supplicant_ctrl_iface_wps_nfc_config_token(
1115 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
1122 pos
= os_strchr(cmd
, ' ');
1125 if (os_strcmp(cmd
, "WPS") == 0)
1127 else if (os_strcmp(cmd
, "NDEF") == 0)
1132 buf
= wpas_wps_nfc_config_token(wpa_s
, ndef
, pos
);
1136 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1138 reply
[res
++] = '\n';
1147 static int wpa_supplicant_ctrl_iface_wps_nfc_token(
1148 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
1154 if (os_strcmp(cmd
, "WPS") == 0)
1156 else if (os_strcmp(cmd
, "NDEF") == 0)
1161 buf
= wpas_wps_nfc_token(wpa_s
, ndef
);
1165 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1167 reply
[res
++] = '\n';
1176 static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
1177 struct wpa_supplicant
*wpa_s
, char *pos
)
1183 int forced_freq
= 0;
1185 freq
= strstr(pos
, " freq=");
1189 forced_freq
= atoi(freq
);
1192 len
= os_strlen(pos
);
1197 buf
= wpabuf_alloc(len
);
1200 if (hexstr2bin(pos
, wpabuf_put(buf
, len
), len
) < 0) {
1205 ret
= wpas_wps_nfc_tag_read(wpa_s
, buf
, forced_freq
);
1212 static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant
*wpa_s
,
1213 char *reply
, size_t max_len
,
1219 buf
= wpas_wps_nfc_handover_req(wpa_s
, ndef
);
1223 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1225 reply
[res
++] = '\n';
1235 static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant
*wpa_s
,
1236 char *reply
, size_t max_len
,
1242 buf
= wpas_p2p_nfc_handover_req(wpa_s
, ndef
);
1244 wpa_printf(MSG_DEBUG
, "P2P: Could not generate NFC handover request");
1248 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1250 reply
[res
++] = '\n';
1257 #endif /* CONFIG_P2P */
1260 static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant
*wpa_s
,
1261 char *cmd
, char *reply
,
1267 pos
= os_strchr(cmd
, ' ');
1272 if (os_strcmp(cmd
, "WPS") == 0)
1274 else if (os_strcmp(cmd
, "NDEF") == 0)
1279 if (os_strcmp(pos
, "WPS") == 0 || os_strcmp(pos
, "WPS-CR") == 0) {
1282 return wpas_ctrl_nfc_get_handover_req_wps(
1283 wpa_s
, reply
, max_len
, ndef
);
1287 if (os_strcmp(pos
, "P2P-CR") == 0) {
1288 return wpas_ctrl_nfc_get_handover_req_p2p(
1289 wpa_s
, reply
, max_len
, ndef
);
1291 #endif /* CONFIG_P2P */
1297 static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant
*wpa_s
,
1298 char *reply
, size_t max_len
,
1299 int ndef
, int cr
, char *uuid
)
1304 buf
= wpas_wps_nfc_handover_sel(wpa_s
, ndef
, cr
, uuid
);
1308 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1310 reply
[res
++] = '\n';
1320 static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant
*wpa_s
,
1321 char *reply
, size_t max_len
,
1327 buf
= wpas_p2p_nfc_handover_sel(wpa_s
, ndef
, tag
);
1331 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1333 reply
[res
++] = '\n';
1340 #endif /* CONFIG_P2P */
1343 static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant
*wpa_s
,
1344 char *cmd
, char *reply
,
1350 pos
= os_strchr(cmd
, ' ');
1355 if (os_strcmp(cmd
, "WPS") == 0)
1357 else if (os_strcmp(cmd
, "NDEF") == 0)
1362 pos2
= os_strchr(pos
, ' ');
1365 if (os_strcmp(pos
, "WPS") == 0 || os_strcmp(pos
, "WPS-CR") == 0) {
1368 return wpas_ctrl_nfc_get_handover_sel_wps(
1369 wpa_s
, reply
, max_len
, ndef
,
1370 os_strcmp(pos
, "WPS-CR") == 0, pos2
);
1374 if (os_strcmp(pos
, "P2P-CR") == 0) {
1375 return wpas_ctrl_nfc_get_handover_sel_p2p(
1376 wpa_s
, reply
, max_len
, ndef
, 0);
1379 if (os_strcmp(pos
, "P2P-CR-TAG") == 0) {
1380 return wpas_ctrl_nfc_get_handover_sel_p2p(
1381 wpa_s
, reply
, max_len
, ndef
, 1);
1383 #endif /* CONFIG_P2P */
1389 static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant
*wpa_s
,
1393 struct wpabuf
*req
, *sel
;
1395 char *pos
, *role
, *type
, *pos2
;
1398 int forced_freq
= 0;
1400 freq
= strstr(cmd
, " freq=");
1404 forced_freq
= atoi(freq
);
1406 #endif /* CONFIG_P2P */
1409 pos
= os_strchr(role
, ' ');
1411 wpa_printf(MSG_DEBUG
, "NFC: Missing type in handover report");
1417 pos
= os_strchr(type
, ' ');
1419 wpa_printf(MSG_DEBUG
, "NFC: Missing request message in handover report");
1424 pos2
= os_strchr(pos
, ' ');
1426 wpa_printf(MSG_DEBUG
, "NFC: Missing select message in handover report");
1431 len
= os_strlen(pos
);
1433 wpa_printf(MSG_DEBUG
, "NFC: Invalid request message length in handover report");
1438 req
= wpabuf_alloc(len
);
1440 wpa_printf(MSG_DEBUG
, "NFC: Failed to allocate memory for request message");
1443 if (hexstr2bin(pos
, wpabuf_put(req
, len
), len
) < 0) {
1444 wpa_printf(MSG_DEBUG
, "NFC: Invalid request message hexdump in handover report");
1449 len
= os_strlen(pos2
);
1451 wpa_printf(MSG_DEBUG
, "NFC: Invalid select message length in handover report");
1457 sel
= wpabuf_alloc(len
);
1459 wpa_printf(MSG_DEBUG
, "NFC: Failed to allocate memory for select message");
1463 if (hexstr2bin(pos2
, wpabuf_put(sel
, len
), len
) < 0) {
1464 wpa_printf(MSG_DEBUG
, "NFC: Invalid select message hexdump in handover report");
1470 wpa_printf(MSG_DEBUG
, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d",
1471 role
, type
, (int) wpabuf_len(req
), (int) wpabuf_len(sel
));
1473 if (os_strcmp(role
, "INIT") == 0 && os_strcmp(type
, "WPS") == 0) {
1474 ret
= wpas_wps_nfc_report_handover(wpa_s
, req
, sel
);
1476 } else if (os_strcmp(role
, "RESP") == 0 && os_strcmp(type
, "WPS") == 0)
1478 ret
= wpas_ap_wps_nfc_report_handover(wpa_s
, req
, sel
);
1480 ret
= wpas_er_wps_nfc_report_handover(wpa_s
, req
, sel
);
1481 #endif /* CONFIG_AP */
1483 } else if (os_strcmp(role
, "INIT") == 0 && os_strcmp(type
, "P2P") == 0)
1485 ret
= wpas_p2p_nfc_report_handover(wpa_s
, 1, req
, sel
, 0);
1486 } else if (os_strcmp(role
, "RESP") == 0 && os_strcmp(type
, "P2P") == 0)
1488 ret
= wpas_p2p_nfc_report_handover(wpa_s
, 0, req
, sel
,
1490 #endif /* CONFIG_P2P */
1492 wpa_printf(MSG_DEBUG
, "NFC: Unsupported connection handover "
1493 "reported: role=%s type=%s", role
, type
);
1500 wpa_printf(MSG_DEBUG
, "NFC: Failed to process reported handover messages");
1505 #endif /* CONFIG_WPS_NFC */
1508 static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant
*wpa_s
,
1517 struct wps_new_ap_settings ap
;
1519 pin
= os_strchr(cmd
, ' ');
1524 if (hwaddr_aton(cmd
, bssid
)) {
1525 wpa_printf(MSG_DEBUG
, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
1530 new_ssid
= os_strchr(pin
, ' ');
1531 if (new_ssid
== NULL
)
1532 return wpas_wps_start_reg(wpa_s
, bssid
, pin
, NULL
);
1535 new_auth
= os_strchr(new_ssid
, ' ');
1536 if (new_auth
== NULL
)
1540 new_encr
= os_strchr(new_auth
, ' ');
1541 if (new_encr
== NULL
)
1545 new_key
= os_strchr(new_encr
, ' ');
1546 if (new_key
== NULL
)
1550 os_memset(&ap
, 0, sizeof(ap
));
1551 ap
.ssid_hex
= new_ssid
;
1554 ap
.key_hex
= new_key
;
1555 return wpas_wps_start_reg(wpa_s
, bssid
, pin
, &ap
);
1560 static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant
*wpa_s
,
1561 char *cmd
, char *buf
,
1566 const char *pin_txt
;
1568 if (!wpa_s
->ap_iface
)
1571 pos
= os_strchr(cmd
, ' ');
1575 if (os_strcmp(cmd
, "disable") == 0) {
1576 wpas_wps_ap_pin_disable(wpa_s
);
1577 return os_snprintf(buf
, buflen
, "OK\n");
1580 if (os_strcmp(cmd
, "random") == 0) {
1582 timeout
= atoi(pos
);
1583 pin_txt
= wpas_wps_ap_pin_random(wpa_s
, timeout
);
1584 if (pin_txt
== NULL
)
1586 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
1589 if (os_strcmp(cmd
, "get") == 0) {
1590 pin_txt
= wpas_wps_ap_pin_get(wpa_s
);
1591 if (pin_txt
== NULL
)
1593 return os_snprintf(buf
, buflen
, "%s", pin_txt
);
1596 if (os_strcmp(cmd
, "set") == 0) {
1601 pos
= os_strchr(pos
, ' ');
1604 timeout
= atoi(pos
);
1606 if (os_strlen(pin
) > buflen
)
1608 if (wpas_wps_ap_pin_set(wpa_s
, pin
, timeout
) < 0)
1610 return os_snprintf(buf
, buflen
, "%s", pin
);
1615 #endif /* CONFIG_AP */
1618 #ifdef CONFIG_WPS_ER
1619 static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant
*wpa_s
,
1622 char *uuid
= cmd
, *pin
, *pos
;
1623 u8 addr_buf
[ETH_ALEN
], *addr
= NULL
;
1624 pin
= os_strchr(uuid
, ' ');
1628 pos
= os_strchr(pin
, ' ');
1631 if (hwaddr_aton(pos
, addr_buf
) == 0)
1634 return wpas_wps_er_add_pin(wpa_s
, addr
, uuid
, pin
);
1638 static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant
*wpa_s
,
1641 char *uuid
= cmd
, *pin
;
1642 pin
= os_strchr(uuid
, ' ');
1646 return wpas_wps_er_learn(wpa_s
, uuid
, pin
);
1650 static int wpa_supplicant_ctrl_iface_wps_er_set_config(
1651 struct wpa_supplicant
*wpa_s
, char *cmd
)
1653 char *uuid
= cmd
, *id
;
1654 id
= os_strchr(uuid
, ' ');
1658 return wpas_wps_er_set_config(wpa_s
, uuid
, atoi(id
));
1662 static int wpa_supplicant_ctrl_iface_wps_er_config(
1663 struct wpa_supplicant
*wpa_s
, char *cmd
)
1670 struct wps_new_ap_settings ap
;
1672 pin
= os_strchr(cmd
, ' ');
1677 new_ssid
= os_strchr(pin
, ' ');
1678 if (new_ssid
== NULL
)
1682 new_auth
= os_strchr(new_ssid
, ' ');
1683 if (new_auth
== NULL
)
1687 new_encr
= os_strchr(new_auth
, ' ');
1688 if (new_encr
== NULL
)
1692 new_key
= os_strchr(new_encr
, ' ');
1693 if (new_key
== NULL
)
1697 os_memset(&ap
, 0, sizeof(ap
));
1698 ap
.ssid_hex
= new_ssid
;
1701 ap
.key_hex
= new_key
;
1702 return wpas_wps_er_config(wpa_s
, cmd
, pin
, &ap
);
1706 #ifdef CONFIG_WPS_NFC
1707 static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
1708 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
1715 uuid
= os_strchr(cmd
, ' ');
1720 if (os_strcmp(cmd
, "WPS") == 0)
1722 else if (os_strcmp(cmd
, "NDEF") == 0)
1727 buf
= wpas_wps_er_nfc_config_token(wpa_s
, ndef
, uuid
);
1731 res
= wpa_snprintf_hex_uppercase(reply
, max_len
, wpabuf_head(buf
),
1733 reply
[res
++] = '\n';
1740 #endif /* CONFIG_WPS_NFC */
1741 #endif /* CONFIG_WPS_ER */
1743 #endif /* CONFIG_WPS */
1746 #ifdef CONFIG_IBSS_RSN
1747 static int wpa_supplicant_ctrl_iface_ibss_rsn(
1748 struct wpa_supplicant
*wpa_s
, char *addr
)
1752 if (hwaddr_aton(addr
, peer
)) {
1753 wpa_printf(MSG_DEBUG
, "CTRL_IFACE IBSS_RSN: invalid "
1754 "address '%s'", addr
);
1758 wpa_printf(MSG_DEBUG
, "CTRL_IFACE IBSS_RSN " MACSTR
,
1761 return ibss_rsn_start(wpa_s
->ibss_rsn
, peer
);
1763 #endif /* CONFIG_IBSS_RSN */
1766 static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant
*wpa_s
,
1769 #ifdef IEEE8021X_EAPOL
1772 struct wpa_ssid
*ssid
;
1774 pos
= os_strchr(rsp
, '-');
1779 pos
= os_strchr(pos
, ':');
1784 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: field=%s id=%d", rsp
, id
);
1785 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
1786 (u8
*) pos
, os_strlen(pos
));
1788 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
1790 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
1795 return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s
, ssid
, rsp
,
1797 #else /* IEEE8021X_EAPOL */
1798 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: 802.1X not included");
1800 #endif /* IEEE8021X_EAPOL */
1804 static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant
*wpa_s
,
1806 char *buf
, size_t buflen
)
1808 char *pos
, *end
, tmp
[30];
1809 int res
, verbose
, wps
, ret
;
1812 #endif /* CONFIG_HS20 */
1816 if (os_strcmp(params
, "-DRIVER") == 0)
1817 return wpa_drv_status(wpa_s
, buf
, buflen
);
1818 verbose
= os_strcmp(params
, "-VERBOSE") == 0;
1819 wps
= os_strcmp(params
, "-WPS") == 0;
1822 if (wpa_s
->wpa_state
>= WPA_ASSOCIATED
) {
1823 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
1824 ret
= os_snprintf(pos
, end
- pos
, "bssid=" MACSTR
"\n",
1825 MAC2STR(wpa_s
->bssid
));
1826 if (os_snprintf_error(end
- pos
, ret
))
1829 ret
= os_snprintf(pos
, end
- pos
, "freq=%u\n",
1831 if (os_snprintf_error(end
- pos
, ret
))
1835 u8
*_ssid
= ssid
->ssid
;
1836 size_t ssid_len
= ssid
->ssid_len
;
1837 u8 ssid_buf
[SSID_MAX_LEN
];
1838 if (ssid_len
== 0) {
1839 int _res
= wpa_drv_get_ssid(wpa_s
, ssid_buf
);
1846 ret
= os_snprintf(pos
, end
- pos
, "ssid=%s\nid=%d\n",
1847 wpa_ssid_txt(_ssid
, ssid_len
),
1849 if (os_snprintf_error(end
- pos
, ret
))
1853 if (wps
&& ssid
->passphrase
&&
1854 wpa_key_mgmt_wpa_psk(ssid
->key_mgmt
) &&
1855 (ssid
->mode
== WPAS_MODE_AP
||
1856 ssid
->mode
== WPAS_MODE_P2P_GO
)) {
1857 ret
= os_snprintf(pos
, end
- pos
,
1860 if (os_snprintf_error(end
- pos
, ret
))
1865 ret
= os_snprintf(pos
, end
- pos
,
1868 if (os_snprintf_error(end
- pos
, ret
))
1873 switch (ssid
->mode
) {
1874 case WPAS_MODE_INFRA
:
1875 ret
= os_snprintf(pos
, end
- pos
,
1878 case WPAS_MODE_IBSS
:
1879 ret
= os_snprintf(pos
, end
- pos
,
1883 ret
= os_snprintf(pos
, end
- pos
,
1886 case WPAS_MODE_P2P_GO
:
1887 ret
= os_snprintf(pos
, end
- pos
,
1890 case WPAS_MODE_P2P_GROUP_FORMATION
:
1891 ret
= os_snprintf(pos
, end
- pos
,
1892 "mode=P2P GO - group "
1895 case WPAS_MODE_MESH
:
1896 ret
= os_snprintf(pos
, end
- pos
,
1903 if (os_snprintf_error(end
- pos
, ret
))
1909 if (wpa_s
->ap_iface
) {
1910 pos
+= ap_ctrl_iface_wpa_get_status(wpa_s
, pos
,
1914 #endif /* CONFIG_AP */
1915 pos
+= wpa_sm_get_status(wpa_s
->wpa
, pos
, end
- pos
, verbose
);
1918 if (wpa_s
->wpa_state
>= WPA_ASSOCIATED
&&
1921 #endif /* CONFIG_AP */
1922 wpa_s
->sme
.sae
.state
== SAE_ACCEPTED
) {
1923 ret
= os_snprintf(pos
, end
- pos
, "sae_group=%d\n",
1924 wpa_s
->sme
.sae
.group
);
1925 if (os_snprintf_error(end
- pos
, ret
))
1929 #endif /* CONFIG_SAE */
1930 ret
= os_snprintf(pos
, end
- pos
, "wpa_state=%s\n",
1931 wpa_supplicant_state_txt(wpa_s
->wpa_state
));
1932 if (os_snprintf_error(end
- pos
, ret
))
1937 l2_packet_get_ip_addr(wpa_s
->l2
, tmp
, sizeof(tmp
)) >= 0) {
1938 ret
= os_snprintf(pos
, end
- pos
, "ip_address=%s\n", tmp
);
1939 if (os_snprintf_error(end
- pos
, ret
))
1945 if (wpa_s
->global
->p2p
) {
1946 ret
= os_snprintf(pos
, end
- pos
, "p2p_device_address=" MACSTR
1947 "\n", MAC2STR(wpa_s
->global
->p2p_dev_addr
));
1948 if (os_snprintf_error(end
- pos
, ret
))
1952 #endif /* CONFIG_P2P */
1954 ret
= os_snprintf(pos
, end
- pos
, "address=" MACSTR
"\n",
1955 MAC2STR(wpa_s
->own_addr
));
1956 if (os_snprintf_error(end
- pos
, ret
))
1961 if (wpa_s
->current_bss
&&
1962 (hs20
= wpa_bss_get_vendor_ie(wpa_s
->current_bss
,
1963 HS20_IE_VENDOR_TYPE
)) &&
1964 wpa_s
->wpa_proto
== WPA_PROTO_RSN
&&
1965 wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
)) {
1968 u8 rel_num
= (hs20
[6] & 0xf0) >> 4;
1969 release
= rel_num
+ 1;
1971 ret
= os_snprintf(pos
, end
- pos
, "hs20=%d\n", release
);
1972 if (os_snprintf_error(end
- pos
, ret
))
1977 if (wpa_s
->current_ssid
) {
1978 struct wpa_cred
*cred
;
1981 for (cred
= wpa_s
->conf
->cred
; cred
; cred
= cred
->next
) {
1984 if (wpa_s
->current_ssid
->parent_cred
!= cred
)
1987 if (cred
->provisioning_sp
) {
1988 ret
= os_snprintf(pos
, end
- pos
,
1989 "provisioning_sp=%s\n",
1990 cred
->provisioning_sp
);
1991 if (os_snprintf_error(end
- pos
, ret
))
2000 if (wpa_s
->current_bss
&& wpa_s
->current_bss
->anqp
) {
2001 struct wpabuf
*names
=
2002 wpa_s
->current_bss
->anqp
->domain_name
;
2003 for (i
= 0; names
&& i
< cred
->num_domain
; i
++)
2005 if (domain_name_list_contains(
2006 names
, cred
->domain
[i
], 1))
2009 if (i
== cred
->num_domain
)
2010 i
= 0; /* show first entry by default */
2012 ret
= os_snprintf(pos
, end
- pos
, "home_sp=%s\n",
2014 if (os_snprintf_error(end
- pos
, ret
))
2019 if (wpa_s
->current_bss
== NULL
||
2020 wpa_s
->current_bss
->anqp
== NULL
)
2023 res
= interworking_home_sp_cred(
2025 wpa_s
->current_bss
->anqp
->domain_name
);
2033 ret
= os_snprintf(pos
, end
- pos
, "sp_type=%s\n", type
);
2034 if (os_snprintf_error(end
- pos
, ret
))
2041 #endif /* CONFIG_HS20 */
2043 if (wpa_key_mgmt_wpa_ieee8021x(wpa_s
->key_mgmt
) ||
2044 wpa_s
->key_mgmt
== WPA_KEY_MGMT_IEEE8021X_NO_WPA
) {
2045 res
= eapol_sm_get_status(wpa_s
->eapol
, pos
, end
- pos
,
2051 sess_id
= eapol_sm_get_session_id(wpa_s
->eapol
, &sess_id_len
);
2055 ret
= os_snprintf(pos
, end
- pos
, "eap_session_id=");
2056 if (os_snprintf_error(end
- pos
, ret
))
2059 ret
= wpa_snprintf_hex(pos
, end
- pos
, sess_id
, sess_id_len
);
2063 ret
= os_snprintf(pos
, end
- pos
, "\n");
2064 if (os_snprintf_error(end
- pos
, ret
))
2069 res
= rsn_preauth_get_status(wpa_s
->wpa
, pos
, end
- pos
, verbose
);
2076 uuid_bin2str(wpa_s
->wps
->uuid
, uuid_str
, sizeof(uuid_str
));
2077 ret
= os_snprintf(pos
, end
- pos
, "uuid=%s\n", uuid_str
);
2078 if (os_snprintf_error(end
- pos
, ret
))
2082 #endif /* CONFIG_WPS */
2086 * Allow using the STATUS command with default behavior, say for debug,
2087 * i.e., don't generate a "fake" CONNECTION and SUPPLICANT_STATE_CHANGE
2088 * events with STATUS-NO_EVENTS.
2090 if (os_strcmp(params
, "-NO_EVENTS")) {
2091 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_STATE_CHANGE
2092 "id=%d state=%d BSSID=" MACSTR
" SSID=%s",
2093 wpa_s
->current_ssid
? wpa_s
->current_ssid
->id
: -1,
2095 MAC2STR(wpa_s
->bssid
),
2096 wpa_s
->current_ssid
&& wpa_s
->current_ssid
->ssid
?
2097 wpa_ssid_txt(wpa_s
->current_ssid
->ssid
,
2098 wpa_s
->current_ssid
->ssid_len
) : "");
2099 if (wpa_s
->wpa_state
== WPA_COMPLETED
) {
2100 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
2101 wpa_msg_ctrl(wpa_s
, MSG_INFO
, WPA_EVENT_CONNECTED
2102 "- connection to " MACSTR
2103 " completed %s [id=%d id_str=%s]",
2104 MAC2STR(wpa_s
->bssid
), "(auth)",
2105 ssid
? ssid
->id
: -1,
2106 ssid
&& ssid
->id_str
? ssid
->id_str
: "");
2109 #endif /* ANDROID */
2115 static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant
*wpa_s
,
2120 struct wpa_ssid
*ssid
;
2123 /* cmd: "<network id> <BSSID>" */
2124 pos
= os_strchr(cmd
, ' ');
2129 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: id=%d bssid='%s'", id
, pos
);
2130 if (hwaddr_aton(pos
, bssid
)) {
2131 wpa_printf(MSG_DEBUG
,"CTRL_IFACE: invalid BSSID '%s'", pos
);
2135 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2137 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
2142 os_memcpy(ssid
->bssid
, bssid
, ETH_ALEN
);
2143 ssid
->bssid_set
= !is_zero_ether_addr(bssid
);
2149 static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant
*wpa_s
,
2150 char *cmd
, char *buf
,
2154 struct wpa_blacklist
*e
;
2158 /* cmd: "BLACKLIST [<BSSID>]" */
2162 e
= wpa_s
->blacklist
;
2164 ret
= os_snprintf(pos
, end
- pos
, MACSTR
"\n",
2166 if (os_snprintf_error(end
- pos
, ret
))
2175 if (os_strncmp(cmd
, "clear", 5) == 0) {
2176 wpa_blacklist_clear(wpa_s
);
2177 os_memcpy(buf
, "OK\n", 3);
2181 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd
);
2182 if (hwaddr_aton(cmd
, bssid
)) {
2183 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: invalid BSSID '%s'", cmd
);
2188 * Add the BSSID twice, so its count will be 2, causing it to be
2189 * skipped when processing scan results.
2191 ret
= wpa_blacklist_add(wpa_s
, bssid
);
2194 ret
= wpa_blacklist_add(wpa_s
, bssid
);
2197 os_memcpy(buf
, "OK\n", 3);
2202 static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant
*wpa_s
,
2203 char *cmd
, char *buf
,
2206 char *pos
, *end
, *stamp
;
2209 /* cmd: "LOG_LEVEL [<level>]" */
2213 ret
= os_snprintf(pos
, end
- pos
, "Current level: %s\n"
2215 debug_level_str(wpa_debug_level
),
2216 wpa_debug_timestamp
);
2217 if (os_snprintf_error(end
- pos
, ret
))
2226 stamp
= os_strchr(cmd
, ' ');
2229 while (*stamp
== ' ') {
2234 if (os_strlen(cmd
)) {
2235 int level
= str_to_debug_level(cmd
);
2238 wpa_debug_level
= level
;
2241 if (stamp
&& os_strlen(stamp
))
2242 wpa_debug_timestamp
= atoi(stamp
);
2244 os_memcpy(buf
, "OK\n", 3);
2249 static int wpa_supplicant_ctrl_iface_list_networks(
2250 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
2252 char *pos
, *end
, *prev
;
2253 struct wpa_ssid
*ssid
;
2258 ret
= os_snprintf(pos
, end
- pos
,
2259 "network id / ssid / bssid / flags\n");
2260 if (os_snprintf_error(end
- pos
, ret
))
2264 ssid
= wpa_s
->conf
->ssid
;
2266 /* skip over ssids until we find next one */
2267 if (cmd
!= NULL
&& os_strncmp(cmd
, "LAST_ID=", 8) == 0) {
2268 int last_id
= atoi(cmd
+ 8);
2269 if (last_id
!= -1) {
2270 while (ssid
!= NULL
&& ssid
->id
<= last_id
) {
2278 ret
= os_snprintf(pos
, end
- pos
, "%d\t%s",
2280 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
));
2281 if (os_snprintf_error(end
- pos
, ret
))
2284 if (ssid
->bssid_set
) {
2285 ret
= os_snprintf(pos
, end
- pos
, "\t" MACSTR
,
2286 MAC2STR(ssid
->bssid
));
2288 ret
= os_snprintf(pos
, end
- pos
, "\tany");
2290 if (os_snprintf_error(end
- pos
, ret
))
2293 ret
= os_snprintf(pos
, end
- pos
, "\t%s%s%s%s",
2294 ssid
== wpa_s
->current_ssid
?
2296 ssid
->disabled
? "[DISABLED]" : "",
2297 ssid
->disabled_until
.sec
?
2298 "[TEMP-DISABLED]" : "",
2299 ssid
->disabled
== 2 ? "[P2P-PERSISTENT]" :
2301 if (os_snprintf_error(end
- pos
, ret
))
2304 ret
= os_snprintf(pos
, end
- pos
, "\n");
2305 if (os_snprintf_error(end
- pos
, ret
))
2316 static char * wpa_supplicant_cipher_txt(char *pos
, char *end
, int cipher
)
2319 ret
= os_snprintf(pos
, end
- pos
, "-");
2320 if (os_snprintf_error(end
- pos
, ret
))
2323 ret
= wpa_write_ciphers(pos
, end
, cipher
, "+");
2331 static char * wpa_supplicant_ie_txt(char *pos
, char *end
, const char *proto
,
2332 const u8
*ie
, size_t ie_len
)
2334 struct wpa_ie_data data
;
2338 ret
= os_snprintf(pos
, end
- pos
, "[%s-", proto
);
2339 if (os_snprintf_error(end
- pos
, ret
))
2343 if (wpa_parse_wpa_ie(ie
, ie_len
, &data
) < 0) {
2344 ret
= os_snprintf(pos
, end
- pos
, "?]");
2345 if (os_snprintf_error(end
- pos
, ret
))
2352 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X
) {
2353 ret
= os_snprintf(pos
, end
- pos
, "%sEAP",
2354 pos
== start
? "" : "+");
2355 if (os_snprintf_error(end
- pos
, ret
))
2359 if (data
.key_mgmt
& WPA_KEY_MGMT_PSK
) {
2360 ret
= os_snprintf(pos
, end
- pos
, "%sPSK",
2361 pos
== start
? "" : "+");
2362 if (os_snprintf_error(end
- pos
, ret
))
2366 if (data
.key_mgmt
& WPA_KEY_MGMT_WPA_NONE
) {
2367 ret
= os_snprintf(pos
, end
- pos
, "%sNone",
2368 pos
== start
? "" : "+");
2369 if (os_snprintf_error(end
- pos
, ret
))
2373 if (data
.key_mgmt
& WPA_KEY_MGMT_SAE
) {
2374 ret
= os_snprintf(pos
, end
- pos
, "%sSAE",
2375 pos
== start
? "" : "+");
2376 if (os_snprintf_error(end
- pos
, ret
))
2380 #ifdef CONFIG_IEEE80211R
2381 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_IEEE8021X
) {
2382 ret
= os_snprintf(pos
, end
- pos
, "%sFT/EAP",
2383 pos
== start
? "" : "+");
2384 if (os_snprintf_error(end
- pos
, ret
))
2388 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_PSK
) {
2389 ret
= os_snprintf(pos
, end
- pos
, "%sFT/PSK",
2390 pos
== start
? "" : "+");
2391 if (os_snprintf_error(end
- pos
, ret
))
2395 if (data
.key_mgmt
& WPA_KEY_MGMT_FT_SAE
) {
2396 ret
= os_snprintf(pos
, end
- pos
, "%sFT/SAE",
2397 pos
== start
? "" : "+");
2398 if (os_snprintf_error(end
- pos
, ret
))
2402 #endif /* CONFIG_IEEE80211R */
2403 #ifdef CONFIG_IEEE80211W
2404 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SHA256
) {
2405 ret
= os_snprintf(pos
, end
- pos
, "%sEAP-SHA256",
2406 pos
== start
? "" : "+");
2407 if (os_snprintf_error(end
- pos
, ret
))
2411 if (data
.key_mgmt
& WPA_KEY_MGMT_PSK_SHA256
) {
2412 ret
= os_snprintf(pos
, end
- pos
, "%sPSK-SHA256",
2413 pos
== start
? "" : "+");
2414 if (os_snprintf_error(end
- pos
, ret
))
2418 #endif /* CONFIG_IEEE80211W */
2420 #ifdef CONFIG_SUITEB
2421 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SUITE_B
) {
2422 ret
= os_snprintf(pos
, end
- pos
, "%sEAP-SUITE-B",
2423 pos
== start
? "" : "+");
2424 if (os_snprintf_error(end
- pos
, ret
))
2428 #endif /* CONFIG_SUITEB */
2430 #ifdef CONFIG_SUITEB192
2431 if (data
.key_mgmt
& WPA_KEY_MGMT_IEEE8021X_SUITE_B_192
) {
2432 ret
= os_snprintf(pos
, end
- pos
, "%sEAP-SUITE-B-192",
2433 pos
== start
? "" : "+");
2434 if (os_snprintf_error(end
- pos
, ret
))
2438 #endif /* CONFIG_SUITEB192 */
2440 if (data
.key_mgmt
& WPA_KEY_MGMT_OSEN
) {
2441 ret
= os_snprintf(pos
, end
- pos
, "%sOSEN",
2442 pos
== start
? "" : "+");
2443 if (os_snprintf_error(end
- pos
, ret
))
2448 pos
= wpa_supplicant_cipher_txt(pos
, end
, data
.pairwise_cipher
);
2450 if (data
.capabilities
& WPA_CAPABILITY_PREAUTH
) {
2451 ret
= os_snprintf(pos
, end
- pos
, "-preauth");
2452 if (os_snprintf_error(end
- pos
, ret
))
2457 ret
= os_snprintf(pos
, end
- pos
, "]");
2458 if (os_snprintf_error(end
- pos
, ret
))
2467 static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant
*wpa_s
,
2468 char *pos
, char *end
,
2469 struct wpabuf
*wps_ie
)
2476 if (wps_is_selected_pbc_registrar(wps_ie
))
2478 else if (wps_is_addr_authorized(wps_ie
, wpa_s
->own_addr
, 0))
2480 else if (wps_is_selected_pin_registrar(wps_ie
))
2485 ret
= os_snprintf(pos
, end
- pos
, "%s", txt
);
2486 if (!os_snprintf_error(end
- pos
, ret
))
2488 wpabuf_free(wps_ie
);
2491 #endif /* CONFIG_WPS */
2494 static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant
*wpa_s
,
2495 char *pos
, char *end
,
2496 const struct wpa_bss
*bss
)
2499 struct wpabuf
*wps_ie
;
2500 wps_ie
= wpa_bss_get_vendor_ie_multi(bss
, WPS_IE_VENDOR_TYPE
);
2501 return wpa_supplicant_wps_ie_txt_buf(wpa_s
, pos
, end
, wps_ie
);
2502 #else /* CONFIG_WPS */
2504 #endif /* CONFIG_WPS */
2508 /* Format one result on one text line into a buffer. */
2509 static int wpa_supplicant_ctrl_iface_scan_result(
2510 struct wpa_supplicant
*wpa_s
,
2511 const struct wpa_bss
*bss
, char *buf
, size_t buflen
)
2515 const u8
*ie
, *ie2
, *osen_ie
, *p2p
, *mesh
;
2517 mesh
= wpa_bss_get_ie(bss
, WLAN_EID_MESH_ID
);
2518 p2p
= wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
);
2520 p2p
= wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
);
2521 if (p2p
&& bss
->ssid_len
== P2P_WILDCARD_SSID_LEN
&&
2522 os_memcmp(bss
->ssid
, P2P_WILDCARD_SSID
, P2P_WILDCARD_SSID_LEN
) ==
2524 return 0; /* Do not show P2P listen discovery results here */
2529 ret
= os_snprintf(pos
, end
- pos
, MACSTR
"\t%d\t%d\t",
2530 MAC2STR(bss
->bssid
), bss
->freq
, bss
->level
);
2531 if (os_snprintf_error(end
- pos
, ret
))
2534 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
2536 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA", ie
, 2 + ie
[1]);
2537 ie2
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
2539 pos
= wpa_supplicant_ie_txt(pos
, end
, mesh
? "RSN" : "WPA2",
2542 osen_ie
= wpa_bss_get_vendor_ie(bss
, OSEN_IE_VENDOR_TYPE
);
2544 pos
= wpa_supplicant_ie_txt(pos
, end
, "OSEN",
2545 osen_ie
, 2 + osen_ie
[1]);
2546 pos
= wpa_supplicant_wps_ie_txt(wpa_s
, pos
, end
, bss
);
2547 if (!ie
&& !ie2
&& !osen_ie
&& (bss
->caps
& IEEE80211_CAP_PRIVACY
)) {
2548 ret
= os_snprintf(pos
, end
- pos
, "[WEP]");
2549 if (os_snprintf_error(end
- pos
, ret
))
2554 ret
= os_snprintf(pos
, end
- pos
, "[MESH]");
2555 if (os_snprintf_error(end
- pos
, ret
))
2559 if (bss_is_dmg(bss
)) {
2561 ret
= os_snprintf(pos
, end
- pos
, "[DMG]");
2562 if (os_snprintf_error(end
- pos
, ret
))
2565 switch (bss
->caps
& IEEE80211_CAP_DMG_MASK
) {
2566 case IEEE80211_CAP_DMG_IBSS
:
2569 case IEEE80211_CAP_DMG_AP
:
2572 case IEEE80211_CAP_DMG_PBSS
:
2579 ret
= os_snprintf(pos
, end
- pos
, "%s", s
);
2580 if (os_snprintf_error(end
- pos
, ret
))
2584 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
2585 ret
= os_snprintf(pos
, end
- pos
, "[IBSS]");
2586 if (os_snprintf_error(end
- pos
, ret
))
2590 if (bss
->caps
& IEEE80211_CAP_ESS
) {
2591 ret
= os_snprintf(pos
, end
- pos
, "[ESS]");
2592 if (os_snprintf_error(end
- pos
, ret
))
2598 ret
= os_snprintf(pos
, end
- pos
, "[P2P]");
2599 if (os_snprintf_error(end
- pos
, ret
))
2604 if (wpa_bss_get_vendor_ie(bss
, HS20_IE_VENDOR_TYPE
) && ie2
) {
2605 ret
= os_snprintf(pos
, end
- pos
, "[HS20]");
2606 if (os_snprintf_error(end
- pos
, ret
))
2610 #endif /* CONFIG_HS20 */
2612 if (wpa_bss_get_ie(bss
, WLAN_EID_MULTI_BAND
)) {
2613 ret
= os_snprintf(pos
, end
- pos
, "[FST]");
2614 if (os_snprintf_error(end
- pos
, ret
))
2618 #endif /* CONFIG_FST */
2620 ret
= os_snprintf(pos
, end
- pos
, "\t%s",
2621 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
2622 if (os_snprintf_error(end
- pos
, ret
))
2626 ret
= os_snprintf(pos
, end
- pos
, "\n");
2627 if (os_snprintf_error(end
- pos
, ret
))
2635 static int wpa_supplicant_ctrl_iface_scan_results(
2636 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
2639 struct wpa_bss
*bss
;
2644 ret
= os_snprintf(pos
, end
- pos
, "bssid / frequency / signal level / "
2646 if (os_snprintf_error(end
- pos
, ret
))
2650 dl_list_for_each(bss
, &wpa_s
->bss_id
, struct wpa_bss
, list_id
) {
2651 ret
= wpa_supplicant_ctrl_iface_scan_result(wpa_s
, bss
, pos
,
2653 if (ret
< 0 || ret
>= end
- pos
)
2664 static int wpa_supplicant_ctrl_iface_mesh_interface_add(
2665 struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
, size_t max_len
)
2667 char *pos
, ifname
[IFNAMSIZ
+ 1];
2671 pos
= os_strstr(cmd
, "ifname=");
2674 os_strlcpy(ifname
, pos
, sizeof(ifname
));
2677 if (wpas_mesh_add_interface(wpa_s
, ifname
, sizeof(ifname
)) < 0)
2680 os_strlcpy(reply
, ifname
, max_len
);
2681 return os_strlen(ifname
);
2685 static int wpa_supplicant_ctrl_iface_mesh_group_add(
2686 struct wpa_supplicant
*wpa_s
, char *cmd
)
2689 struct wpa_ssid
*ssid
;
2692 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: MESH_GROUP_ADD id=%d", id
);
2694 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2696 wpa_printf(MSG_DEBUG
,
2697 "CTRL_IFACE: Could not find network id=%d", id
);
2700 if (ssid
->mode
!= WPAS_MODE_MESH
) {
2701 wpa_printf(MSG_DEBUG
,
2702 "CTRL_IFACE: Cannot use MESH_GROUP_ADD on a non mesh network");
2705 if (ssid
->key_mgmt
!= WPA_KEY_MGMT_NONE
&&
2706 ssid
->key_mgmt
!= WPA_KEY_MGMT_SAE
) {
2707 wpa_printf(MSG_ERROR
,
2708 "CTRL_IFACE: key_mgmt for mesh network should be open or SAE");
2713 * TODO: If necessary write our own group_add function,
2714 * for now we can reuse select_network
2716 wpa_supplicant_select_network(wpa_s
, ssid
);
2722 static int wpa_supplicant_ctrl_iface_mesh_group_remove(
2723 struct wpa_supplicant
*wpa_s
, char *cmd
)
2725 struct wpa_supplicant
*orig
;
2726 struct wpa_global
*global
;
2729 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s", cmd
);
2731 global
= wpa_s
->global
;
2734 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
2735 if (os_strcmp(wpa_s
->ifname
, cmd
) == 0) {
2741 wpa_printf(MSG_ERROR
,
2742 "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s not found",
2746 if (wpa_s
->mesh_if_created
&& wpa_s
== orig
) {
2747 wpa_printf(MSG_ERROR
,
2748 "CTRL_IFACE: MESH_GROUP_REMOVE can't remove itself");
2752 wpa_s
->reassociate
= 0;
2753 wpa_s
->disconnected
= 1;
2754 wpa_supplicant_cancel_sched_scan(wpa_s
);
2755 wpa_supplicant_cancel_scan(wpa_s
);
2758 * TODO: If necessary write our own group_remove function,
2759 * for now we can reuse deauthenticate
2761 wpa_supplicant_deauthenticate(wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2763 if (wpa_s
->mesh_if_created
)
2764 wpa_supplicant_remove_iface(global
, wpa_s
, 0);
2770 static int wpa_supplicant_ctrl_iface_mesh_peer_remove(
2771 struct wpa_supplicant
*wpa_s
, char *cmd
)
2775 if (hwaddr_aton(cmd
, addr
) < 0)
2778 return wpas_mesh_peer_remove(wpa_s
, addr
);
2782 static int wpa_supplicant_ctrl_iface_mesh_peer_add(
2783 struct wpa_supplicant
*wpa_s
, char *cmd
)
2789 pos
= os_strstr(cmd
, " duration=");
2792 duration
= atoi(pos
+ 10);
2797 if (hwaddr_aton(cmd
, addr
))
2800 return wpas_mesh_peer_add(wpa_s
, addr
, duration
);
2803 #endif /* CONFIG_MESH */
2806 static int wpa_supplicant_ctrl_iface_select_network(
2807 struct wpa_supplicant
*wpa_s
, char *cmd
)
2810 struct wpa_ssid
*ssid
;
2813 /* cmd: "<network id>" or "any" */
2814 if (os_strncmp(cmd
, "any", 3) == 0) {
2815 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SELECT_NETWORK any");
2819 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SELECT_NETWORK id=%d", id
);
2821 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2823 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
2824 "network id=%d", id
);
2827 if (ssid
->disabled
== 2) {
2828 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
2829 "SELECT_NETWORK with persistent P2P group");
2834 pos
= os_strstr(cmd
, " freq=");
2836 int *freqs
= freq_range_to_channel_list(wpa_s
, pos
+ 6);
2838 wpa_s
->scan_req
= MANUAL_SCAN_REQ
;
2839 os_free(wpa_s
->manual_scan_freqs
);
2840 wpa_s
->manual_scan_freqs
= freqs
;
2844 wpa_s
->scan_min_time
.sec
= 0;
2845 wpa_s
->scan_min_time
.usec
= 0;
2846 wpa_supplicant_select_network(wpa_s
, ssid
);
2852 static int wpa_supplicant_ctrl_iface_enable_network(
2853 struct wpa_supplicant
*wpa_s
, char *cmd
)
2856 struct wpa_ssid
*ssid
;
2858 /* cmd: "<network id>" or "all" */
2859 if (os_strcmp(cmd
, "all") == 0) {
2860 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ENABLE_NETWORK all");
2864 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ENABLE_NETWORK id=%d", id
);
2866 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2868 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
2869 "network id=%d", id
);
2872 if (ssid
->disabled
== 2) {
2873 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
2874 "ENABLE_NETWORK with persistent P2P group");
2878 if (os_strstr(cmd
, " no-connect")) {
2883 wpa_s
->scan_min_time
.sec
= 0;
2884 wpa_s
->scan_min_time
.usec
= 0;
2885 wpa_supplicant_enable_network(wpa_s
, ssid
);
2891 static int wpa_supplicant_ctrl_iface_disable_network(
2892 struct wpa_supplicant
*wpa_s
, char *cmd
)
2895 struct wpa_ssid
*ssid
;
2897 /* cmd: "<network id>" or "all" */
2898 if (os_strcmp(cmd
, "all") == 0) {
2899 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DISABLE_NETWORK all");
2903 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: DISABLE_NETWORK id=%d", id
);
2905 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
2907 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
2908 "network id=%d", id
);
2911 if (ssid
->disabled
== 2) {
2912 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Cannot use "
2913 "DISABLE_NETWORK with persistent P2P "
2918 wpa_supplicant_disable_network(wpa_s
, ssid
);
2924 static int wpa_supplicant_ctrl_iface_add_network(
2925 struct wpa_supplicant
*wpa_s
, char *buf
, size_t buflen
)
2927 struct wpa_ssid
*ssid
;
2930 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ADD_NETWORK");
2932 ssid
= wpa_supplicant_add_network(wpa_s
);
2936 ret
= os_snprintf(buf
, buflen
, "%d\n", ssid
->id
);
2937 if (os_snprintf_error(buflen
, ret
))
2943 static int wpa_supplicant_ctrl_iface_remove_network(
2944 struct wpa_supplicant
*wpa_s
, char *cmd
)
2947 struct wpa_ssid
*ssid
;
2950 /* cmd: "<network id>" or "all" */
2951 if (os_strcmp(cmd
, "all") == 0) {
2952 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_NETWORK all");
2953 if (wpa_s
->sched_scanning
)
2954 wpa_supplicant_cancel_sched_scan(wpa_s
);
2956 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
2957 if (wpa_s
->current_ssid
) {
2959 wpa_s
->sme
.prev_bssid_set
= 0;
2960 #endif /* CONFIG_SME */
2961 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
2962 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
2963 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
)
2964 wpa_s
->own_disconnect_req
= 1;
2965 wpa_supplicant_deauthenticate(
2966 wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
2968 ssid
= wpa_s
->conf
->ssid
;
2970 struct wpa_ssid
*remove_ssid
= ssid
;
2973 if (wpa_s
->last_ssid
== remove_ssid
)
2974 wpa_s
->last_ssid
= NULL
;
2975 wpas_notify_network_removed(wpa_s
, remove_ssid
);
2976 wpa_config_remove_network(wpa_s
->conf
, id
);
2982 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_NETWORK id=%d", id
);
2984 result
= wpa_supplicant_remove_network(wpa_s
, id
);
2986 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
2991 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Not able to remove the "
2992 "network id=%d", id
);
2999 static int wpa_supplicant_ctrl_iface_update_network(
3000 struct wpa_supplicant
*wpa_s
, struct wpa_ssid
*ssid
,
3001 char *name
, char *value
)
3005 ret
= wpa_config_set(ssid
, name
, value
, 0);
3007 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to set network "
3008 "variable '%s'", name
);
3012 return 0; /* No change to the previously configured value */
3014 if (os_strcmp(name
, "bssid") != 0 &&
3015 os_strcmp(name
, "priority") != 0) {
3016 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, ssid
);
3018 if (wpa_s
->current_ssid
== ssid
||
3019 wpa_s
->current_ssid
== NULL
) {
3021 * Invalidate the EAP session cache if anything in the
3022 * current or previously used configuration changes.
3024 eapol_sm_invalidate_cached_session(wpa_s
->eapol
);
3028 if ((os_strcmp(name
, "psk") == 0 &&
3029 value
[0] == '"' && ssid
->ssid_len
) ||
3030 (os_strcmp(name
, "ssid") == 0 && ssid
->passphrase
))
3031 wpa_config_update_psk(ssid
);
3032 else if (os_strcmp(name
, "priority") == 0)
3033 wpa_config_update_prio_list(wpa_s
->conf
);
3039 static int wpa_supplicant_ctrl_iface_set_network(
3040 struct wpa_supplicant
*wpa_s
, char *cmd
)
3042 int id
, ret
, prev_bssid_set
, prev_disabled
;
3043 struct wpa_ssid
*ssid
;
3045 u8 prev_bssid
[ETH_ALEN
];
3047 /* cmd: "<network id> <variable name> <value>" */
3048 name
= os_strchr(cmd
, ' ');
3053 value
= os_strchr(name
, ' ');
3059 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
3061 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
3062 (u8
*) value
, os_strlen(value
));
3064 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3066 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find network "
3071 prev_bssid_set
= ssid
->bssid_set
;
3072 prev_disabled
= ssid
->disabled
;
3073 os_memcpy(prev_bssid
, ssid
->bssid
, ETH_ALEN
);
3074 ret
= wpa_supplicant_ctrl_iface_update_network(wpa_s
, ssid
, name
,
3077 (ssid
->bssid_set
!= prev_bssid_set
||
3078 os_memcmp(ssid
->bssid
, prev_bssid
, ETH_ALEN
) != 0))
3079 wpas_notify_network_bssid_set_changed(wpa_s
, ssid
);
3081 if (prev_disabled
!= ssid
->disabled
&&
3082 (prev_disabled
== 2 || ssid
->disabled
== 2))
3083 wpas_notify_network_type_changed(wpa_s
, ssid
);
3089 static int wpa_supplicant_ctrl_iface_get_network(
3090 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
3094 struct wpa_ssid
*ssid
;
3097 /* cmd: "<network id> <variable name>" */
3098 name
= os_strchr(cmd
, ' ');
3099 if (name
== NULL
|| buflen
== 0)
3104 wpa_printf(MSG_EXCESSIVE
, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
3107 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
3109 wpa_printf(MSG_EXCESSIVE
, "CTRL_IFACE: Could not find network "
3114 value
= wpa_config_get_no_key(ssid
, name
);
3115 if (value
== NULL
) {
3116 wpa_printf(MSG_EXCESSIVE
, "CTRL_IFACE: Failed to get network "
3117 "variable '%s'", name
);
3121 res
= os_strlcpy(buf
, value
, buflen
);
3122 if (res
>= buflen
) {
3133 static int wpa_supplicant_ctrl_iface_dup_network(
3134 struct wpa_supplicant
*wpa_s
, char *cmd
,
3135 struct wpa_supplicant
*dst_wpa_s
)
3137 struct wpa_ssid
*ssid_s
, *ssid_d
;
3138 char *name
, *id
, *value
;
3139 int id_s
, id_d
, ret
;
3141 /* cmd: "<src network id> <dst network id> <variable name>" */
3142 id
= os_strchr(cmd
, ' ');
3147 name
= os_strchr(id
, ' ');
3155 wpa_printf(MSG_DEBUG
,
3156 "CTRL_IFACE: DUP_NETWORK ifname=%s->%s id=%d->%d name='%s'",
3157 wpa_s
->ifname
, dst_wpa_s
->ifname
, id_s
, id_d
, name
);
3159 ssid_s
= wpa_config_get_network(wpa_s
->conf
, id_s
);
3160 if (ssid_s
== NULL
) {
3161 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3162 "network id=%d", id_s
);
3166 ssid_d
= wpa_config_get_network(dst_wpa_s
->conf
, id_d
);
3167 if (ssid_d
== NULL
) {
3168 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
3169 "network id=%d", id_d
);
3173 value
= wpa_config_get(ssid_s
, name
);
3174 if (value
== NULL
) {
3175 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to get network "
3176 "variable '%s'", name
);
3180 ret
= wpa_supplicant_ctrl_iface_update_network(dst_wpa_s
, ssid_d
, name
,
3189 static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant
*wpa_s
,
3190 char *buf
, size_t buflen
)
3193 struct wpa_cred
*cred
;
3198 ret
= os_snprintf(pos
, end
- pos
,
3199 "cred id / realm / username / domain / imsi\n");
3200 if (os_snprintf_error(end
- pos
, ret
))
3204 cred
= wpa_s
->conf
->cred
;
3206 ret
= os_snprintf(pos
, end
- pos
, "%d\t%s\t%s\t%s\t%s\n",
3207 cred
->id
, cred
->realm
? cred
->realm
: "",
3208 cred
->username
? cred
->username
: "",
3209 cred
->domain
? cred
->domain
[0] : "",
3210 cred
->imsi
? cred
->imsi
: "");
3211 if (os_snprintf_error(end
- pos
, ret
))
3222 static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant
*wpa_s
,
3223 char *buf
, size_t buflen
)
3225 struct wpa_cred
*cred
;
3228 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: ADD_CRED");
3230 cred
= wpa_config_add_cred(wpa_s
->conf
);
3234 wpa_msg(wpa_s
, MSG_INFO
, CRED_ADDED
"%d", cred
->id
);
3236 ret
= os_snprintf(buf
, buflen
, "%d\n", cred
->id
);
3237 if (os_snprintf_error(buflen
, ret
))
3243 static int wpas_ctrl_remove_cred(struct wpa_supplicant
*wpa_s
,
3244 struct wpa_cred
*cred
)
3246 struct wpa_ssid
*ssid
;
3251 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred");
3256 if (wpa_config_remove_cred(wpa_s
->conf
, id
) < 0) {
3257 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred");
3261 wpa_msg(wpa_s
, MSG_INFO
, CRED_REMOVED
"%d", id
);
3263 /* Remove any network entry created based on the removed credential */
3264 ssid
= wpa_s
->conf
->ssid
;
3266 if (ssid
->parent_cred
== cred
) {
3269 wpa_printf(MSG_DEBUG
, "Remove network id %d since it "
3270 "used the removed credential", ssid
->id
);
3271 res
= os_snprintf(str
, sizeof(str
), "%d", ssid
->id
);
3272 if (os_snprintf_error(sizeof(str
), res
))
3273 str
[sizeof(str
) - 1] = '\0';
3275 wpa_supplicant_ctrl_iface_remove_network(wpa_s
, str
);
3284 static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant
*wpa_s
,
3288 struct wpa_cred
*cred
, *prev
;
3290 /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or
3291 * "provisioning_sp=<FQDN> */
3292 if (os_strcmp(cmd
, "all") == 0) {
3293 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED all");
3294 cred
= wpa_s
->conf
->cred
;
3298 wpas_ctrl_remove_cred(wpa_s
, prev
);
3303 if (os_strncmp(cmd
, "sp_fqdn=", 8) == 0) {
3304 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
3306 cred
= wpa_s
->conf
->cred
;
3312 for (i
= 0; i
< prev
->num_domain
; i
++) {
3313 if (os_strcmp(prev
->domain
[i
], cmd
+ 8)
3316 wpas_ctrl_remove_cred(wpa_s
, prev
);
3324 if (os_strncmp(cmd
, "provisioning_sp=", 16) == 0) {
3325 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'",
3327 cred
= wpa_s
->conf
->cred
;
3331 if (prev
->provisioning_sp
&&
3332 os_strcmp(prev
->provisioning_sp
, cmd
+ 16) == 0)
3333 wpas_ctrl_remove_cred(wpa_s
, prev
);
3339 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: REMOVE_CRED id=%d", id
);
3341 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
3342 return wpas_ctrl_remove_cred(wpa_s
, cred
);
3346 static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant
*wpa_s
,
3350 struct wpa_cred
*cred
;
3353 /* cmd: "<cred id> <variable name> <value>" */
3354 name
= os_strchr(cmd
, ' ');
3359 value
= os_strchr(name
, ' ');
3365 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SET_CRED id=%d name='%s'",
3367 wpa_hexdump_ascii_key(MSG_DEBUG
, "CTRL_IFACE: value",
3368 (u8
*) value
, os_strlen(value
));
3370 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
3372 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred id=%d",
3377 if (wpa_config_set_cred(cred
, name
, value
, 0) < 0) {
3378 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to set cred "
3379 "variable '%s'", name
);
3383 wpa_msg(wpa_s
, MSG_INFO
, CRED_MODIFIED
"%d %s", cred
->id
, name
);
3389 static int wpa_supplicant_ctrl_iface_get_cred(struct wpa_supplicant
*wpa_s
,
3390 char *cmd
, char *buf
,
3395 struct wpa_cred
*cred
;
3398 /* cmd: "<cred id> <variable name>" */
3399 name
= os_strchr(cmd
, ' ');
3405 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_CRED id=%d name='%s'",
3408 cred
= wpa_config_get_cred(wpa_s
->conf
, id
);
3410 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find cred id=%d",
3415 value
= wpa_config_get_cred_no_key(cred
, name
);
3416 if (value
== NULL
) {
3417 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Failed to get cred variable '%s'",
3422 res
= os_strlcpy(buf
, value
, buflen
);
3423 if (res
>= buflen
) {
3434 #ifndef CONFIG_NO_CONFIG_WRITE
3435 static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant
*wpa_s
)
3439 if (!wpa_s
->conf
->update_config
) {
3440 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
3441 "to update configuration (update_config=0)");
3445 ret
= wpa_config_write(wpa_s
->confname
, wpa_s
->conf
);
3447 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Failed to "
3448 "update configuration");
3450 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Configuration"
3456 #endif /* CONFIG_NO_CONFIG_WRITE */
3459 struct cipher_info
{
3465 static const struct cipher_info ciphers
[] = {
3466 { WPA_DRIVER_CAPA_ENC_CCMP_256
, "CCMP-256", 0 },
3467 { WPA_DRIVER_CAPA_ENC_GCMP_256
, "GCMP-256", 0 },
3468 { WPA_DRIVER_CAPA_ENC_CCMP
, "CCMP", 0 },
3469 { WPA_DRIVER_CAPA_ENC_GCMP
, "GCMP", 0 },
3470 { WPA_DRIVER_CAPA_ENC_TKIP
, "TKIP", 0 },
3471 { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
, "NONE", 0 },
3472 { WPA_DRIVER_CAPA_ENC_WEP104
, "WEP104", 1 },
3473 { WPA_DRIVER_CAPA_ENC_WEP40
, "WEP40", 1 }
3476 static const struct cipher_info ciphers_group_mgmt
[] = {
3477 { WPA_DRIVER_CAPA_ENC_BIP
, "AES-128-CMAC", 1 },
3478 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_128
, "BIP-GMAC-128", 1 },
3479 { WPA_DRIVER_CAPA_ENC_BIP_GMAC_256
, "BIP-GMAC-256", 1 },
3480 { WPA_DRIVER_CAPA_ENC_BIP_CMAC_256
, "BIP-CMAC-256", 1 },
3484 static int ctrl_iface_get_capability_pairwise(int res
, char *strict
,
3485 struct wpa_driver_capa
*capa
,
3486 char *buf
, size_t buflen
)
3499 len
= os_strlcpy(buf
, "CCMP TKIP NONE", buflen
);
3505 for (i
= 0; i
< ARRAY_SIZE(ciphers
); i
++) {
3506 if (!ciphers
[i
].group_only
&& capa
->enc
& ciphers
[i
].capa
) {
3507 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
3508 pos
== buf
? "" : " ",
3510 if (os_snprintf_error(end
- pos
, ret
))
3520 static int ctrl_iface_get_capability_group(int res
, char *strict
,
3521 struct wpa_driver_capa
*capa
,
3522 char *buf
, size_t buflen
)
3535 len
= os_strlcpy(buf
, "CCMP TKIP WEP104 WEP40", buflen
);
3541 for (i
= 0; i
< ARRAY_SIZE(ciphers
); i
++) {
3542 if (capa
->enc
& ciphers
[i
].capa
) {
3543 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
3544 pos
== buf
? "" : " ",
3546 if (os_snprintf_error(end
- pos
, ret
))
3556 static int ctrl_iface_get_capability_group_mgmt(int res
, char *strict
,
3557 struct wpa_driver_capa
*capa
,
3558 char *buf
, size_t buflen
)
3570 for (i
= 0; i
< ARRAY_SIZE(ciphers_group_mgmt
); i
++) {
3571 if (capa
->enc
& ciphers_group_mgmt
[i
].capa
) {
3572 ret
= os_snprintf(pos
, end
- pos
, "%s%s",
3573 pos
== buf
? "" : " ",
3574 ciphers_group_mgmt
[i
].name
);
3575 if (os_snprintf_error(end
- pos
, ret
))
3585 static int ctrl_iface_get_capability_key_mgmt(int res
, char *strict
,
3586 struct wpa_driver_capa
*capa
,
3587 char *buf
, size_t buflen
)
3599 len
= os_strlcpy(buf
, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
3606 ret
= os_snprintf(pos
, end
- pos
, "NONE IEEE8021X");
3607 if (os_snprintf_error(end
- pos
, ret
))
3611 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
3612 WPA_DRIVER_CAPA_KEY_MGMT_WPA2
)) {
3613 ret
= os_snprintf(pos
, end
- pos
, " WPA-EAP");
3614 if (os_snprintf_error(end
- pos
, ret
))
3619 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
|
3620 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
)) {
3621 ret
= os_snprintf(pos
, end
- pos
, " WPA-PSK");
3622 if (os_snprintf_error(end
- pos
, ret
))
3627 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE
) {
3628 ret
= os_snprintf(pos
, end
- pos
, " WPA-NONE");
3629 if (os_snprintf_error(end
- pos
, ret
))
3634 #ifdef CONFIG_SUITEB
3635 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B
) {
3636 ret
= os_snprintf(pos
, end
- pos
, " WPA-EAP-SUITE-B");
3637 if (os_snprintf_error(end
- pos
, ret
))
3641 #endif /* CONFIG_SUITEB */
3642 #ifdef CONFIG_SUITEB192
3643 if (capa
->key_mgmt
& WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192
) {
3644 ret
= os_snprintf(pos
, end
- pos
, " WPA-EAP-SUITE-B-192");
3645 if (os_snprintf_error(end
- pos
, ret
))
3649 #endif /* CONFIG_SUITEB192 */
3655 static int ctrl_iface_get_capability_proto(int res
, char *strict
,
3656 struct wpa_driver_capa
*capa
,
3657 char *buf
, size_t buflen
)
3669 len
= os_strlcpy(buf
, "RSN WPA", buflen
);
3675 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA2
|
3676 WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK
)) {
3677 ret
= os_snprintf(pos
, end
- pos
, "%sRSN",
3678 pos
== buf
? "" : " ");
3679 if (os_snprintf_error(end
- pos
, ret
))
3684 if (capa
->key_mgmt
& (WPA_DRIVER_CAPA_KEY_MGMT_WPA
|
3685 WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK
)) {
3686 ret
= os_snprintf(pos
, end
- pos
, "%sWPA",
3687 pos
== buf
? "" : " ");
3688 if (os_snprintf_error(end
- pos
, ret
))
3697 static int ctrl_iface_get_capability_auth_alg(struct wpa_supplicant
*wpa_s
,
3698 int res
, char *strict
,
3699 struct wpa_driver_capa
*capa
,
3700 char *buf
, size_t buflen
)
3712 len
= os_strlcpy(buf
, "OPEN SHARED LEAP", buflen
);
3718 if (capa
->auth
& (WPA_DRIVER_AUTH_OPEN
)) {
3719 ret
= os_snprintf(pos
, end
- pos
, "%sOPEN",
3720 pos
== buf
? "" : " ");
3721 if (os_snprintf_error(end
- pos
, ret
))
3726 if (capa
->auth
& (WPA_DRIVER_AUTH_SHARED
)) {
3727 ret
= os_snprintf(pos
, end
- pos
, "%sSHARED",
3728 pos
== buf
? "" : " ");
3729 if (os_snprintf_error(end
- pos
, ret
))
3734 if (capa
->auth
& (WPA_DRIVER_AUTH_LEAP
)) {
3735 ret
= os_snprintf(pos
, end
- pos
, "%sLEAP",
3736 pos
== buf
? "" : " ");
3737 if (os_snprintf_error(end
- pos
, ret
))
3743 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_SAE
) {
3744 ret
= os_snprintf(pos
, end
- pos
, "%sSAE",
3745 pos
== buf
? "" : " ");
3746 if (os_snprintf_error(end
- pos
, ret
))
3750 #endif /* CONFIG_SAE */
3756 static int ctrl_iface_get_capability_modes(int res
, char *strict
,
3757 struct wpa_driver_capa
*capa
,
3758 char *buf
, size_t buflen
)
3770 len
= os_strlcpy(buf
, "IBSS AP", buflen
);
3776 if (capa
->flags
& WPA_DRIVER_FLAGS_IBSS
) {
3777 ret
= os_snprintf(pos
, end
- pos
, "%sIBSS",
3778 pos
== buf
? "" : " ");
3779 if (os_snprintf_error(end
- pos
, ret
))
3784 if (capa
->flags
& WPA_DRIVER_FLAGS_AP
) {
3785 ret
= os_snprintf(pos
, end
- pos
, "%sAP",
3786 pos
== buf
? "" : " ");
3787 if (os_snprintf_error(end
- pos
, ret
))
3793 if (capa
->flags
& WPA_DRIVER_FLAGS_MESH
) {
3794 ret
= os_snprintf(pos
, end
- pos
, "%sMESH",
3795 pos
== buf
? "" : " ");
3796 if (os_snprintf_error(end
- pos
, ret
))
3800 #endif /* CONFIG_MESH */
3806 static int ctrl_iface_get_capability_channels(struct wpa_supplicant
*wpa_s
,
3807 char *buf
, size_t buflen
)
3809 struct hostapd_channel_data
*chnl
;
3811 char *pos
, *end
, *hmode
;
3816 for (j
= 0; j
< wpa_s
->hw
.num_modes
; j
++) {
3817 switch (wpa_s
->hw
.modes
[j
].mode
) {
3818 case HOSTAPD_MODE_IEEE80211B
:
3821 case HOSTAPD_MODE_IEEE80211G
:
3824 case HOSTAPD_MODE_IEEE80211A
:
3827 case HOSTAPD_MODE_IEEE80211AD
:
3833 ret
= os_snprintf(pos
, end
- pos
, "Mode[%s] Channels:", hmode
);
3834 if (os_snprintf_error(end
- pos
, ret
))
3837 chnl
= wpa_s
->hw
.modes
[j
].channels
;
3838 for (i
= 0; i
< wpa_s
->hw
.modes
[j
].num_channels
; i
++) {
3839 if (chnl
[i
].flag
& HOSTAPD_CHAN_DISABLED
)
3841 ret
= os_snprintf(pos
, end
- pos
, " %d", chnl
[i
].chan
);
3842 if (os_snprintf_error(end
- pos
, ret
))
3846 ret
= os_snprintf(pos
, end
- pos
, "\n");
3847 if (os_snprintf_error(end
- pos
, ret
))
3856 static int ctrl_iface_get_capability_freq(struct wpa_supplicant
*wpa_s
,
3857 char *buf
, size_t buflen
)
3859 struct hostapd_channel_data
*chnl
;
3861 char *pos
, *end
, *hmode
;
3866 for (j
= 0; j
< wpa_s
->hw
.num_modes
; j
++) {
3867 switch (wpa_s
->hw
.modes
[j
].mode
) {
3868 case HOSTAPD_MODE_IEEE80211B
:
3871 case HOSTAPD_MODE_IEEE80211G
:
3874 case HOSTAPD_MODE_IEEE80211A
:
3877 case HOSTAPD_MODE_IEEE80211AD
:
3883 ret
= os_snprintf(pos
, end
- pos
, "Mode[%s] Channels:\n",
3885 if (os_snprintf_error(end
- pos
, ret
))
3888 chnl
= wpa_s
->hw
.modes
[j
].channels
;
3889 for (i
= 0; i
< wpa_s
->hw
.modes
[j
].num_channels
; i
++) {
3890 if (chnl
[i
].flag
& HOSTAPD_CHAN_DISABLED
)
3892 ret
= os_snprintf(pos
, end
- pos
, " %d = %d MHz%s%s\n",
3893 chnl
[i
].chan
, chnl
[i
].freq
,
3894 chnl
[i
].flag
& HOSTAPD_CHAN_NO_IR
?
3896 chnl
[i
].flag
& HOSTAPD_CHAN_RADAR
?
3899 if (os_snprintf_error(end
- pos
, ret
))
3903 ret
= os_snprintf(pos
, end
- pos
, "\n");
3904 if (os_snprintf_error(end
- pos
, ret
))
3913 static int wpa_supplicant_ctrl_iface_get_capability(
3914 struct wpa_supplicant
*wpa_s
, const char *_field
, char *buf
,
3917 struct wpa_driver_capa capa
;
3923 /* Determine whether or not strict checking was requested */
3924 len
= os_strlcpy(field
, _field
, sizeof(field
));
3925 if (len
>= sizeof(field
))
3927 strict
= os_strchr(field
, ' ');
3928 if (strict
!= NULL
) {
3930 if (os_strcmp(strict
, "strict") != 0)
3934 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
3935 field
, strict
? strict
: "");
3937 if (os_strcmp(field
, "eap") == 0) {
3938 return eap_get_names(buf
, buflen
);
3941 res
= wpa_drv_get_capa(wpa_s
, &capa
);
3943 if (os_strcmp(field
, "pairwise") == 0)
3944 return ctrl_iface_get_capability_pairwise(res
, strict
, &capa
,
3947 if (os_strcmp(field
, "group") == 0)
3948 return ctrl_iface_get_capability_group(res
, strict
, &capa
,
3951 if (os_strcmp(field
, "group_mgmt") == 0)
3952 return ctrl_iface_get_capability_group_mgmt(res
, strict
, &capa
,
3955 if (os_strcmp(field
, "key_mgmt") == 0)
3956 return ctrl_iface_get_capability_key_mgmt(res
, strict
, &capa
,
3959 if (os_strcmp(field
, "proto") == 0)
3960 return ctrl_iface_get_capability_proto(res
, strict
, &capa
,
3963 if (os_strcmp(field
, "auth_alg") == 0)
3964 return ctrl_iface_get_capability_auth_alg(wpa_s
, res
, strict
,
3965 &capa
, buf
, buflen
);
3967 if (os_strcmp(field
, "modes") == 0)
3968 return ctrl_iface_get_capability_modes(res
, strict
, &capa
,
3971 if (os_strcmp(field
, "channels") == 0)
3972 return ctrl_iface_get_capability_channels(wpa_s
, buf
, buflen
);
3974 if (os_strcmp(field
, "freq") == 0)
3975 return ctrl_iface_get_capability_freq(wpa_s
, buf
, buflen
);
3978 if (os_strcmp(field
, "tdls") == 0)
3979 return ctrl_iface_get_capability_tdls(wpa_s
, buf
, buflen
);
3980 #endif /* CONFIG_TDLS */
3983 if (os_strcmp(field
, "erp") == 0) {
3984 res
= os_snprintf(buf
, buflen
, "ERP");
3985 if (os_snprintf_error(buflen
, res
))
3989 #endif /* CONFIG_EPR */
3992 if (os_strcmp(field
, "fips") == 0) {
3993 res
= os_snprintf(buf
, buflen
, "FIPS");
3994 if (os_snprintf_error(buflen
, res
))
3998 #endif /* CONFIG_FIPS */
4001 if (os_strcmp(field
, "acs") == 0) {
4002 res
= os_snprintf(buf
, buflen
, "ACS");
4003 if (os_snprintf_error(buflen
, res
))
4007 #endif /* CONFIG_ACS */
4009 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
4016 #ifdef CONFIG_INTERWORKING
4017 static char * anqp_add_hex(char *pos
, char *end
, const char *title
,
4018 struct wpabuf
*data
)
4028 ret
= os_snprintf(pos
, end
- pos
, "%s=", title
);
4029 if (os_snprintf_error(end
- pos
, ret
))
4033 d
= wpabuf_head_u8(data
);
4034 for (i
= 0; i
< wpabuf_len(data
); i
++) {
4035 ret
= os_snprintf(pos
, end
- pos
, "%02x", *d
++);
4036 if (os_snprintf_error(end
- pos
, ret
))
4041 ret
= os_snprintf(pos
, end
- pos
, "\n");
4042 if (os_snprintf_error(end
- pos
, ret
))
4048 #endif /* CONFIG_INTERWORKING */
4051 static int print_bss_info(struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
,
4052 unsigned long mask
, char *buf
, size_t buflen
)
4057 const u8
*ie
, *ie2
, *osen_ie
;
4062 if (mask
& WPA_BSS_MASK_ID
) {
4063 ret
= os_snprintf(pos
, end
- pos
, "id=%u\n", bss
->id
);
4064 if (os_snprintf_error(end
- pos
, ret
))
4069 if (mask
& WPA_BSS_MASK_BSSID
) {
4070 ret
= os_snprintf(pos
, end
- pos
, "bssid=" MACSTR
"\n",
4071 MAC2STR(bss
->bssid
));
4072 if (os_snprintf_error(end
- pos
, ret
))
4077 if (mask
& WPA_BSS_MASK_FREQ
) {
4078 ret
= os_snprintf(pos
, end
- pos
, "freq=%d\n", bss
->freq
);
4079 if (os_snprintf_error(end
- pos
, ret
))
4084 if (mask
& WPA_BSS_MASK_BEACON_INT
) {
4085 ret
= os_snprintf(pos
, end
- pos
, "beacon_int=%d\n",
4087 if (os_snprintf_error(end
- pos
, ret
))
4092 if (mask
& WPA_BSS_MASK_CAPABILITIES
) {
4093 ret
= os_snprintf(pos
, end
- pos
, "capabilities=0x%04x\n",
4095 if (os_snprintf_error(end
- pos
, ret
))
4100 if (mask
& WPA_BSS_MASK_QUAL
) {
4101 ret
= os_snprintf(pos
, end
- pos
, "qual=%d\n", bss
->qual
);
4102 if (os_snprintf_error(end
- pos
, ret
))
4107 if (mask
& WPA_BSS_MASK_NOISE
) {
4108 ret
= os_snprintf(pos
, end
- pos
, "noise=%d\n", bss
->noise
);
4109 if (os_snprintf_error(end
- pos
, ret
))
4114 if (mask
& WPA_BSS_MASK_LEVEL
) {
4115 ret
= os_snprintf(pos
, end
- pos
, "level=%d\n", bss
->level
);
4116 if (os_snprintf_error(end
- pos
, ret
))
4121 if (mask
& WPA_BSS_MASK_TSF
) {
4122 ret
= os_snprintf(pos
, end
- pos
, "tsf=%016llu\n",
4123 (unsigned long long) bss
->tsf
);
4124 if (os_snprintf_error(end
- pos
, ret
))
4129 if (mask
& WPA_BSS_MASK_AGE
) {
4130 struct os_reltime now
;
4132 os_get_reltime(&now
);
4133 ret
= os_snprintf(pos
, end
- pos
, "age=%d\n",
4134 (int) (now
.sec
- bss
->last_update
.sec
));
4135 if (os_snprintf_error(end
- pos
, ret
))
4140 if (mask
& WPA_BSS_MASK_IE
) {
4141 ret
= os_snprintf(pos
, end
- pos
, "ie=");
4142 if (os_snprintf_error(end
- pos
, ret
))
4146 ie
= (const u8
*) (bss
+ 1);
4147 for (i
= 0; i
< bss
->ie_len
; i
++) {
4148 ret
= os_snprintf(pos
, end
- pos
, "%02x", *ie
++);
4149 if (os_snprintf_error(end
- pos
, ret
))
4154 ret
= os_snprintf(pos
, end
- pos
, "\n");
4155 if (os_snprintf_error(end
- pos
, ret
))
4160 if (mask
& WPA_BSS_MASK_FLAGS
) {
4161 ret
= os_snprintf(pos
, end
- pos
, "flags=");
4162 if (os_snprintf_error(end
- pos
, ret
))
4166 ie
= wpa_bss_get_vendor_ie(bss
, WPA_IE_VENDOR_TYPE
);
4168 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA", ie
,
4170 ie2
= wpa_bss_get_ie(bss
, WLAN_EID_RSN
);
4172 pos
= wpa_supplicant_ie_txt(pos
, end
, "WPA2", ie2
,
4174 osen_ie
= wpa_bss_get_vendor_ie(bss
, OSEN_IE_VENDOR_TYPE
);
4176 pos
= wpa_supplicant_ie_txt(pos
, end
, "OSEN",
4177 osen_ie
, 2 + osen_ie
[1]);
4178 pos
= wpa_supplicant_wps_ie_txt(wpa_s
, pos
, end
, bss
);
4179 if (!ie
&& !ie2
&& !osen_ie
&&
4180 (bss
->caps
& IEEE80211_CAP_PRIVACY
)) {
4181 ret
= os_snprintf(pos
, end
- pos
, "[WEP]");
4182 if (os_snprintf_error(end
- pos
, ret
))
4186 if (bss_is_dmg(bss
)) {
4188 ret
= os_snprintf(pos
, end
- pos
, "[DMG]");
4189 if (os_snprintf_error(end
- pos
, ret
))
4192 switch (bss
->caps
& IEEE80211_CAP_DMG_MASK
) {
4193 case IEEE80211_CAP_DMG_IBSS
:
4196 case IEEE80211_CAP_DMG_AP
:
4199 case IEEE80211_CAP_DMG_PBSS
:
4206 ret
= os_snprintf(pos
, end
- pos
, "%s", s
);
4207 if (os_snprintf_error(end
- pos
, ret
))
4211 if (bss
->caps
& IEEE80211_CAP_IBSS
) {
4212 ret
= os_snprintf(pos
, end
- pos
, "[IBSS]");
4213 if (os_snprintf_error(end
- pos
, ret
))
4217 if (bss
->caps
& IEEE80211_CAP_ESS
) {
4218 ret
= os_snprintf(pos
, end
- pos
, "[ESS]");
4219 if (os_snprintf_error(end
- pos
, ret
))
4224 if (wpa_bss_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
) ||
4225 wpa_bss_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
)) {
4226 ret
= os_snprintf(pos
, end
- pos
, "[P2P]");
4227 if (os_snprintf_error(end
- pos
, ret
))
4232 if (wpa_bss_get_vendor_ie(bss
, HS20_IE_VENDOR_TYPE
)) {
4233 ret
= os_snprintf(pos
, end
- pos
, "[HS20]");
4234 if (os_snprintf_error(end
- pos
, ret
))
4238 #endif /* CONFIG_HS20 */
4240 ret
= os_snprintf(pos
, end
- pos
, "\n");
4241 if (os_snprintf_error(end
- pos
, ret
))
4246 if (mask
& WPA_BSS_MASK_SSID
) {
4247 ret
= os_snprintf(pos
, end
- pos
, "ssid=%s\n",
4248 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
4249 if (os_snprintf_error(end
- pos
, ret
))
4255 if (mask
& WPA_BSS_MASK_WPS_SCAN
) {
4256 ie
= (const u8
*) (bss
+ 1);
4257 ret
= wpas_wps_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
4258 if (ret
>= end
- pos
)
4263 #endif /* CONFIG_WPS */
4266 if (mask
& WPA_BSS_MASK_P2P_SCAN
) {
4267 ie
= (const u8
*) (bss
+ 1);
4268 ret
= wpas_p2p_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
4269 if (ret
>= end
- pos
)
4274 #endif /* CONFIG_P2P */
4276 #ifdef CONFIG_WIFI_DISPLAY
4277 if (mask
& WPA_BSS_MASK_WIFI_DISPLAY
) {
4279 ie
= (const u8
*) (bss
+ 1);
4280 wfd
= ieee802_11_vendor_ie_concat(ie
, bss
->ie_len
,
4281 WFD_IE_VENDOR_TYPE
);
4283 ret
= os_snprintf(pos
, end
- pos
, "wfd_subelems=");
4284 if (os_snprintf_error(end
- pos
, ret
)) {
4290 pos
+= wpa_snprintf_hex(pos
, end
- pos
,
4295 ret
= os_snprintf(pos
, end
- pos
, "\n");
4296 if (os_snprintf_error(end
- pos
, ret
))
4301 #endif /* CONFIG_WIFI_DISPLAY */
4303 #ifdef CONFIG_INTERWORKING
4304 if ((mask
& WPA_BSS_MASK_INTERNETW
) && bss
->anqp
) {
4305 struct wpa_bss_anqp
*anqp
= bss
->anqp
;
4306 struct wpa_bss_anqp_elem
*elem
;
4308 pos
= anqp_add_hex(pos
, end
, "anqp_capability_list",
4309 anqp
->capability_list
);
4310 pos
= anqp_add_hex(pos
, end
, "anqp_venue_name",
4312 pos
= anqp_add_hex(pos
, end
, "anqp_network_auth_type",
4313 anqp
->network_auth_type
);
4314 pos
= anqp_add_hex(pos
, end
, "anqp_roaming_consortium",
4315 anqp
->roaming_consortium
);
4316 pos
= anqp_add_hex(pos
, end
, "anqp_ip_addr_type_availability",
4317 anqp
->ip_addr_type_availability
);
4318 pos
= anqp_add_hex(pos
, end
, "anqp_nai_realm",
4320 pos
= anqp_add_hex(pos
, end
, "anqp_3gpp", anqp
->anqp_3gpp
);
4321 pos
= anqp_add_hex(pos
, end
, "anqp_domain_name",
4324 pos
= anqp_add_hex(pos
, end
, "hs20_capability_list",
4325 anqp
->hs20_capability_list
);
4326 pos
= anqp_add_hex(pos
, end
, "hs20_operator_friendly_name",
4327 anqp
->hs20_operator_friendly_name
);
4328 pos
= anqp_add_hex(pos
, end
, "hs20_wan_metrics",
4329 anqp
->hs20_wan_metrics
);
4330 pos
= anqp_add_hex(pos
, end
, "hs20_connection_capability",
4331 anqp
->hs20_connection_capability
);
4332 pos
= anqp_add_hex(pos
, end
, "hs20_operating_class",
4333 anqp
->hs20_operating_class
);
4334 pos
= anqp_add_hex(pos
, end
, "hs20_osu_providers_list",
4335 anqp
->hs20_osu_providers_list
);
4336 #endif /* CONFIG_HS20 */
4338 dl_list_for_each(elem
, &anqp
->anqp_elems
,
4339 struct wpa_bss_anqp_elem
, list
) {
4342 os_snprintf(title
, sizeof(title
), "anqp[%u]",
4344 pos
= anqp_add_hex(pos
, end
, title
, elem
->payload
);
4347 #endif /* CONFIG_INTERWORKING */
4350 if (mask
& WPA_BSS_MASK_MESH_SCAN
) {
4351 ie
= (const u8
*) (bss
+ 1);
4352 ret
= wpas_mesh_scan_result_text(ie
, bss
->ie_len
, pos
, end
);
4353 if (ret
>= end
- pos
)
4358 #endif /* CONFIG_MESH */
4360 if (mask
& WPA_BSS_MASK_SNR
) {
4361 ret
= os_snprintf(pos
, end
- pos
, "snr=%d\n", bss
->snr
);
4362 if (os_snprintf_error(end
- pos
, ret
))
4367 if (mask
& WPA_BSS_MASK_EST_THROUGHPUT
) {
4368 ret
= os_snprintf(pos
, end
- pos
, "est_throughput=%d\n",
4369 bss
->est_throughput
);
4370 if (os_snprintf_error(end
- pos
, ret
))
4376 if (mask
& WPA_BSS_MASK_FST
) {
4377 ret
= fst_ctrl_iface_mb_info(bss
->bssid
, pos
, end
- pos
);
4378 if (ret
< 0 || ret
>= end
- pos
)
4382 #endif /* CONFIG_FST */
4384 if (mask
& WPA_BSS_MASK_DELIM
) {
4385 ret
= os_snprintf(pos
, end
- pos
, "====\n");
4386 if (os_snprintf_error(end
- pos
, ret
))
4395 static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant
*wpa_s
,
4396 const char *cmd
, char *buf
,
4401 struct wpa_bss
*bss
;
4402 struct wpa_bss
*bsslast
= NULL
;
4403 struct dl_list
*next
;
4406 char *ctmp
, *end
= buf
+ buflen
;
4407 unsigned long mask
= WPA_BSS_MASK_ALL
;
4409 if (os_strncmp(cmd
, "RANGE=", 6) == 0) {
4410 if (os_strncmp(cmd
+ 6, "ALL", 3) == 0) {
4411 bss
= dl_list_first(&wpa_s
->bss_id
, struct wpa_bss
,
4413 bsslast
= dl_list_last(&wpa_s
->bss_id
, struct wpa_bss
,
4415 } else { /* N1-N2 */
4416 unsigned int id1
, id2
;
4418 if ((ctmp
= os_strchr(cmd
+ 6, '-')) == NULL
) {
4419 wpa_printf(MSG_INFO
, "Wrong BSS range "
4424 if (*(cmd
+ 6) == '-')
4427 id1
= atoi(cmd
+ 6);
4429 if (*ctmp
>= '0' && *ctmp
<= '9')
4432 id2
= (unsigned int) -1;
4433 bss
= wpa_bss_get_id_range(wpa_s
, id1
, id2
);
4434 if (id2
== (unsigned int) -1)
4435 bsslast
= dl_list_last(&wpa_s
->bss_id
,
4439 bsslast
= wpa_bss_get_id(wpa_s
, id2
);
4440 if (bsslast
== NULL
&& bss
&& id2
> id1
) {
4441 struct wpa_bss
*tmp
= bss
;
4443 next
= tmp
->list_id
.next
;
4444 if (next
== &wpa_s
->bss_id
)
4446 tmp
= dl_list_entry(
4447 next
, struct wpa_bss
,
4456 } else if (os_strncmp(cmd
, "FIRST", 5) == 0)
4457 bss
= dl_list_first(&wpa_s
->bss_id
, struct wpa_bss
, list_id
);
4458 else if (os_strncmp(cmd
, "LAST", 4) == 0)
4459 bss
= dl_list_last(&wpa_s
->bss_id
, struct wpa_bss
, list_id
);
4460 else if (os_strncmp(cmd
, "ID-", 3) == 0) {
4462 bss
= wpa_bss_get_id(wpa_s
, i
);
4463 } else if (os_strncmp(cmd
, "NEXT-", 5) == 0) {
4465 bss
= wpa_bss_get_id(wpa_s
, i
);
4467 next
= bss
->list_id
.next
;
4468 if (next
== &wpa_s
->bss_id
)
4471 bss
= dl_list_entry(next
, struct wpa_bss
,
4475 } else if (os_strncmp(cmd
, "p2p_dev_addr=", 13) == 0) {
4476 if (hwaddr_aton(cmd
+ 13, bssid
) == 0)
4477 bss
= wpa_bss_get_p2p_dev_addr(wpa_s
, bssid
);
4480 #endif /* CONFIG_P2P */
4481 } else if (hwaddr_aton(cmd
, bssid
) == 0)
4482 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
4484 struct wpa_bss
*tmp
;
4487 dl_list_for_each(tmp
, &wpa_s
->bss_id
, struct wpa_bss
, list_id
)
4496 if ((ctmp
= os_strstr(cmd
, "MASK=")) != NULL
) {
4497 mask
= strtoul(ctmp
+ 5, NULL
, 0x10);
4499 mask
= WPA_BSS_MASK_ALL
;
4505 if (bsslast
== NULL
)
4508 len
= print_bss_info(wpa_s
, bss
, mask
, buf
, buflen
);
4512 if (bss
== bsslast
) {
4513 if ((mask
& WPA_BSS_MASK_DELIM
) && len
&&
4514 (bss
== dl_list_last(&wpa_s
->bss_id
,
4515 struct wpa_bss
, list_id
))) {
4518 res
= os_snprintf(buf
- 5, end
- buf
+ 5,
4520 if (os_snprintf_error(end
- buf
+ 5, res
)) {
4521 wpa_printf(MSG_DEBUG
,
4522 "Could not add end delim");
4527 next
= bss
->list_id
.next
;
4528 if (next
== &wpa_s
->bss_id
)
4530 bss
= dl_list_entry(next
, struct wpa_bss
, list_id
);
4531 } while (bss
&& len
);
4537 static int wpa_supplicant_ctrl_iface_ap_scan(
4538 struct wpa_supplicant
*wpa_s
, char *cmd
)
4540 int ap_scan
= atoi(cmd
);
4541 return wpa_supplicant_set_ap_scan(wpa_s
, ap_scan
);
4545 static int wpa_supplicant_ctrl_iface_scan_interval(
4546 struct wpa_supplicant
*wpa_s
, char *cmd
)
4548 int scan_int
= atoi(cmd
);
4549 return wpa_supplicant_set_scan_interval(wpa_s
, scan_int
);
4553 static int wpa_supplicant_ctrl_iface_bss_expire_age(
4554 struct wpa_supplicant
*wpa_s
, char *cmd
)
4556 int expire_age
= atoi(cmd
);
4557 return wpa_supplicant_set_bss_expiration_age(wpa_s
, expire_age
);
4561 static int wpa_supplicant_ctrl_iface_bss_expire_count(
4562 struct wpa_supplicant
*wpa_s
, char *cmd
)
4564 int expire_count
= atoi(cmd
);
4565 return wpa_supplicant_set_bss_expiration_count(wpa_s
, expire_count
);
4569 static void wpa_supplicant_ctrl_iface_bss_flush(
4570 struct wpa_supplicant
*wpa_s
, char *cmd
)
4572 int flush_age
= atoi(cmd
);
4575 wpa_bss_flush(wpa_s
);
4577 wpa_bss_flush_by_age(wpa_s
, flush_age
);
4581 #ifdef CONFIG_TESTING_OPTIONS
4582 static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant
*wpa_s
)
4584 wpa_printf(MSG_DEBUG
, "Dropping SA without deauthentication");
4585 /* MLME-DELETEKEYS.request */
4586 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 0, 0, NULL
, 0, NULL
, 0);
4587 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 1, 0, NULL
, 0, NULL
, 0);
4588 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 2, 0, NULL
, 0, NULL
, 0);
4589 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 3, 0, NULL
, 0, NULL
, 0);
4590 #ifdef CONFIG_IEEE80211W
4591 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 4, 0, NULL
, 0, NULL
, 0);
4592 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, NULL
, 5, 0, NULL
, 0, NULL
, 0);
4593 #endif /* CONFIG_IEEE80211W */
4595 wpa_drv_set_key(wpa_s
, WPA_ALG_NONE
, wpa_s
->bssid
, 0, 0, NULL
, 0, NULL
,
4597 /* MLME-SETPROTECTION.request(None) */
4598 wpa_drv_mlme_setprotection(wpa_s
, wpa_s
->bssid
,
4599 MLME_SETPROTECTION_PROTECT_TYPE_NONE
,
4600 MLME_SETPROTECTION_KEY_TYPE_PAIRWISE
);
4601 wpa_sm_drop_sa(wpa_s
->wpa
);
4603 #endif /* CONFIG_TESTING_OPTIONS */
4606 static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant
*wpa_s
,
4609 #ifdef CONFIG_NO_SCAN_PROCESSING
4611 #else /* CONFIG_NO_SCAN_PROCESSING */
4613 struct wpa_bss
*bss
;
4614 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
4616 if (hwaddr_aton(addr
, bssid
)) {
4617 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: invalid "
4618 "address '%s'", addr
);
4622 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM " MACSTR
, MAC2STR(bssid
));
4625 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: No network "
4626 "configuration known for the target AP");
4630 bss
= wpa_bss_get(wpa_s
, bssid
, ssid
->ssid
, ssid
->ssid_len
);
4632 wpa_printf(MSG_DEBUG
, "CTRL_IFACE ROAM: Target AP not found "
4638 * TODO: Find best network configuration block from configuration to
4639 * allow roaming to other networks
4642 wpa_s
->reassociate
= 1;
4643 wpa_supplicant_connect(wpa_s
, bss
, ssid
);
4646 #endif /* CONFIG_NO_SCAN_PROCESSING */
4651 static int p2p_ctrl_find(struct wpa_supplicant
*wpa_s
, char *cmd
)
4653 unsigned int timeout
= atoi(cmd
);
4654 enum p2p_discovery_type type
= P2P_FIND_START_WITH_FULL
;
4655 u8 dev_id
[ETH_ALEN
], *_dev_id
= NULL
;
4656 u8 dev_type
[WPS_DEV_TYPE_LEN
], *_dev_type
= NULL
;
4658 unsigned int search_delay
;
4659 const char *_seek
[P2P_MAX_QUERY_HASH
+ 1], **seek
= NULL
;
4663 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
4664 wpa_dbg(wpa_s
, MSG_INFO
,
4665 "Reject P2P_FIND since interface is disabled");
4668 if (os_strstr(cmd
, "type=social"))
4669 type
= P2P_FIND_ONLY_SOCIAL
;
4670 else if (os_strstr(cmd
, "type=progressive"))
4671 type
= P2P_FIND_PROGRESSIVE
;
4673 pos
= os_strstr(cmd
, "dev_id=");
4676 if (hwaddr_aton(pos
, dev_id
))
4681 pos
= os_strstr(cmd
, "dev_type=");
4684 if (wps_dev_type_str2bin(pos
, dev_type
) < 0)
4686 _dev_type
= dev_type
;
4689 pos
= os_strstr(cmd
, "delay=");
4692 search_delay
= atoi(pos
);
4694 search_delay
= wpas_p2p_search_delay(wpa_s
);
4696 pos
= os_strstr(cmd
, "freq=");
4704 /* Must be searched for last, because it adds nul termination */
4705 pos
= os_strstr(cmd
, " seek=");
4708 while (pos
&& seek_count
< P2P_MAX_QUERY_HASH
+ 1) {
4711 _seek
[seek_count
++] = pos
;
4713 term
= os_strchr(pos
, ' ');
4717 pos
= os_strstr(term
+ 1, "seek=");
4721 if (seek_count
> P2P_MAX_QUERY_HASH
) {
4726 return wpas_p2p_find(wpa_s
, timeout
, type
, _dev_type
!= NULL
, _dev_type
,
4727 _dev_id
, search_delay
, seek_count
, seek
, freq
);
4731 static int p2ps_ctrl_parse_cpt_priority(const char *pos
, u8
*cpt
)
4733 const char *last
= NULL
;
4738 /* Expected predefined CPT names delimited by ':' */
4739 for (i
= 0; (token
= cstr_token(pos
, ": \t", &last
)); i
++) {
4740 if (i
>= P2PS_FEATURE_CAPAB_CPT_MAX
) {
4741 wpa_printf(MSG_ERROR
,
4742 "P2PS: CPT name list is too long, expected up to %d names",
4743 P2PS_FEATURE_CAPAB_CPT_MAX
);
4748 token_len
= last
- token
;
4750 if (token_len
== 3 &&
4751 os_memcmp(token
, "UDP", token_len
) == 0) {
4752 cpt
[i
] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT
;
4753 } else if (token_len
== 3 &&
4754 os_memcmp(token
, "MAC", token_len
) == 0) {
4755 cpt
[i
] = P2PS_FEATURE_CAPAB_MAC_TRANSPORT
;
4757 wpa_printf(MSG_ERROR
,
4758 "P2PS: Unsupported CPT name '%s'", token
);
4763 if (isblank((unsigned char) *last
)) {
4773 static struct p2ps_provision
* p2p_parse_asp_provision_cmd(const char *cmd
)
4775 struct p2ps_provision
*p2ps_prov
;
4777 size_t info_len
= 0;
4779 u8 role
= P2PS_SETUP_NONE
;
4780 long long unsigned val
;
4783 pos
= os_strstr(cmd
, "info=");
4786 info_len
= os_strlen(pos
);
4789 info
= os_malloc(info_len
+ 1);
4791 info_len
= utf8_unescape(pos
, info_len
,
4792 info
, info_len
+ 1);
4798 p2ps_prov
= os_zalloc(sizeof(struct p2ps_provision
) + info_len
+ 1);
4799 if (p2ps_prov
== NULL
) {
4805 os_memcpy(p2ps_prov
->info
, info
, info_len
);
4806 p2ps_prov
->info
[info_len
] = '\0';
4810 pos
= os_strstr(cmd
, "status=");
4812 p2ps_prov
->status
= atoi(pos
+ 7);
4814 p2ps_prov
->status
= -1;
4816 pos
= os_strstr(cmd
, "adv_id=");
4817 if (!pos
|| sscanf(pos
+ 7, "%llx", &val
) != 1 || val
> 0xffffffffULL
)
4819 p2ps_prov
->adv_id
= val
;
4821 pos
= os_strstr(cmd
, "method=");
4823 p2ps_prov
->method
= strtol(pos
+ 7, NULL
, 16);
4825 p2ps_prov
->method
= 0;
4827 pos
= os_strstr(cmd
, "session=");
4828 if (!pos
|| sscanf(pos
+ 8, "%llx", &val
) != 1 || val
> 0xffffffffULL
)
4830 p2ps_prov
->session_id
= val
;
4832 pos
= os_strstr(cmd
, "adv_mac=");
4833 if (!pos
|| hwaddr_aton(pos
+ 8, p2ps_prov
->adv_mac
))
4836 pos
= os_strstr(cmd
, "session_mac=");
4837 if (!pos
|| hwaddr_aton(pos
+ 12, p2ps_prov
->session_mac
))
4840 pos
= os_strstr(cmd
, "cpt=");
4842 if (p2ps_ctrl_parse_cpt_priority(pos
+ 4,
4843 p2ps_prov
->cpt_priority
))
4846 p2ps_prov
->cpt_priority
[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT
;
4849 for (i
= 0; p2ps_prov
->cpt_priority
[i
]; i
++)
4850 p2ps_prov
->cpt_mask
|= p2ps_prov
->cpt_priority
[i
];
4852 /* force conncap with tstCap (no sanity checks) */
4853 pos
= os_strstr(cmd
, "tstCap=");
4855 role
= strtol(pos
+ 7, NULL
, 16);
4857 pos
= os_strstr(cmd
, "role=");
4859 role
= strtol(pos
+ 5, NULL
, 16);
4860 if (role
!= P2PS_SETUP_CLIENT
&&
4861 role
!= P2PS_SETUP_GROUP_OWNER
)
4862 role
= P2PS_SETUP_NONE
;
4865 p2ps_prov
->role
= role
;
4875 static int p2p_ctrl_asp_provision_resp(struct wpa_supplicant
*wpa_s
, char *cmd
)
4878 struct p2ps_provision
*p2ps_prov
;
4881 /* <addr> id=<adv_id> [role=<conncap>] [info=<infodata>] */
4883 wpa_printf(MSG_DEBUG
, "%s: %s", __func__
, cmd
);
4885 if (hwaddr_aton(cmd
, addr
))
4892 p2ps_prov
= p2p_parse_asp_provision_cmd(pos
);
4896 if (p2ps_prov
->status
< 0) {
4901 return wpas_p2p_prov_disc(wpa_s
, addr
, NULL
, WPAS_P2P_PD_FOR_ASP
,
4906 static int p2p_ctrl_asp_provision(struct wpa_supplicant
*wpa_s
, char *cmd
)
4909 struct p2ps_provision
*p2ps_prov
;
4912 /* <addr> id=<adv_id> adv_mac=<adv_mac> conncap=<conncap>
4913 * session=<ses_id> mac=<ses_mac> [info=<infodata>]
4916 wpa_printf(MSG_DEBUG
, "%s: %s", __func__
, cmd
);
4917 if (hwaddr_aton(cmd
, addr
))
4924 p2ps_prov
= p2p_parse_asp_provision_cmd(pos
);
4928 p2ps_prov
->pd_seeker
= 1;
4930 return wpas_p2p_prov_disc(wpa_s
, addr
, NULL
, WPAS_P2P_PD_FOR_ASP
,
4935 static int parse_freq(int chwidth
, int freq2
)
4940 return VHT_CHANWIDTH_80P80MHZ
;
4946 return VHT_CHANWIDTH_USE_HT
;
4948 return VHT_CHANWIDTH_80MHZ
;
4950 return VHT_CHANWIDTH_160MHZ
;
4952 wpa_printf(MSG_DEBUG
, "Unknown max oper bandwidth: %d",
4959 static int p2p_ctrl_connect(struct wpa_supplicant
*wpa_s
, char *cmd
,
4960 char *buf
, size_t buflen
)
4965 enum p2p_wps_method wps_method
;
4968 int persistent_group
, persistent_id
= -1;
4975 int ht40
, vht
, max_oper_chwidth
, chwidth
= 0, freq2
= 0;
4976 u8 _group_ssid
[SSID_MAX_LEN
], *group_ssid
= NULL
;
4977 size_t group_ssid_len
= 0;
4979 if (!wpa_s
->global
->p2p_init_wpa_s
)
4981 if (wpa_s
->global
->p2p_init_wpa_s
!= wpa_s
) {
4982 wpa_dbg(wpa_s
, MSG_DEBUG
, "Direct P2P_CONNECT command to %s",
4983 wpa_s
->global
->p2p_init_wpa_s
->ifname
);
4984 wpa_s
= wpa_s
->global
->p2p_init_wpa_s
;
4987 /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad|p2ps]
4988 * [persistent|persistent=<network id>]
4989 * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
4990 * [ht40] [vht] [auto] [ssid=<hexdump>] */
4992 if (hwaddr_aton(cmd
, addr
))
5000 persistent_group
= os_strstr(pos
, " persistent") != NULL
;
5001 pos2
= os_strstr(pos
, " persistent=");
5003 struct wpa_ssid
*ssid
;
5004 persistent_id
= atoi(pos2
+ 12);
5005 ssid
= wpa_config_get_network(wpa_s
->conf
, persistent_id
);
5006 if (ssid
== NULL
|| ssid
->disabled
!= 2 ||
5007 ssid
->mode
!= WPAS_MODE_P2P_GO
) {
5008 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find "
5009 "SSID id=%d for persistent P2P group (GO)",
5014 join
= os_strstr(pos
, " join") != NULL
;
5015 auth
= os_strstr(pos
, " auth") != NULL
;
5016 automatic
= os_strstr(pos
, " auto") != NULL
;
5017 pd
= os_strstr(pos
, " provdisc") != NULL
;
5018 vht
= (os_strstr(cmd
, " vht") != NULL
) || wpa_s
->conf
->p2p_go_vht
;
5019 ht40
= (os_strstr(cmd
, " ht40") != NULL
) || wpa_s
->conf
->p2p_go_ht40
||
5022 pos2
= os_strstr(pos
, " go_intent=");
5025 go_intent
= atoi(pos2
);
5026 if (go_intent
< 0 || go_intent
> 15)
5030 pos2
= os_strstr(pos
, " freq=");
5038 pos2
= os_strstr(pos
, " freq2=");
5040 freq2
= atoi(pos2
+ 7);
5042 pos2
= os_strstr(pos
, " max_oper_chwidth=");
5044 chwidth
= atoi(pos2
+ 18);
5046 max_oper_chwidth
= parse_freq(chwidth
, freq2
);
5047 if (max_oper_chwidth
< 0)
5050 pos2
= os_strstr(pos
, " ssid=");
5055 end
= os_strchr(pos2
, ' ');
5057 group_ssid_len
= os_strlen(pos2
) / 2;
5059 group_ssid_len
= (end
- pos2
) / 2;
5060 if (group_ssid_len
== 0 || group_ssid_len
> SSID_MAX_LEN
||
5061 hexstr2bin(pos2
, _group_ssid
, group_ssid_len
) < 0)
5063 group_ssid
= _group_ssid
;
5066 if (os_strncmp(pos
, "pin", 3) == 0) {
5067 /* Request random PIN (to be displayed) and enable the PIN */
5068 wps_method
= WPS_PIN_DISPLAY
;
5069 } else if (os_strncmp(pos
, "pbc", 3) == 0) {
5070 wps_method
= WPS_PBC
;
5071 } else if (os_strstr(pos
, "p2ps") != NULL
) {
5072 wps_method
= WPS_P2PS
;
5075 pos
= os_strchr(pin
, ' ');
5076 wps_method
= WPS_PIN_KEYPAD
;
5079 if (os_strncmp(pos
, "display", 7) == 0)
5080 wps_method
= WPS_PIN_DISPLAY
;
5082 if (!wps_pin_str_valid(pin
)) {
5083 os_memcpy(buf
, "FAIL-INVALID-PIN\n", 17);
5088 new_pin
= wpas_p2p_connect(wpa_s
, addr
, pin
, wps_method
,
5089 persistent_group
, automatic
, join
,
5090 auth
, go_intent
, freq
, freq2
, persistent_id
,
5091 pd
, ht40
, vht
, max_oper_chwidth
,
5092 group_ssid
, group_ssid_len
);
5093 if (new_pin
== -2) {
5094 os_memcpy(buf
, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
5097 if (new_pin
== -3) {
5098 os_memcpy(buf
, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
5103 if (wps_method
== WPS_PIN_DISPLAY
&& pin
== NULL
) {
5104 ret
= os_snprintf(buf
, buflen
, "%08d", new_pin
);
5105 if (os_snprintf_error(buflen
, ret
))
5110 os_memcpy(buf
, "OK\n", 3);
5115 static int p2p_ctrl_listen(struct wpa_supplicant
*wpa_s
, char *cmd
)
5117 unsigned int timeout
= atoi(cmd
);
5118 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
5119 wpa_dbg(wpa_s
, MSG_INFO
,
5120 "Reject P2P_LISTEN since interface is disabled");
5123 return wpas_p2p_listen(wpa_s
, timeout
);
5127 static int p2p_ctrl_prov_disc(struct wpa_supplicant
*wpa_s
, char *cmd
)
5131 enum wpas_p2p_prov_disc_use use
= WPAS_P2P_PD_FOR_GO_NEG
;
5133 /* <addr> <config method> [join|auto] */
5135 if (hwaddr_aton(cmd
, addr
))
5143 if (os_strstr(pos
, " join") != NULL
)
5144 use
= WPAS_P2P_PD_FOR_JOIN
;
5145 else if (os_strstr(pos
, " auto") != NULL
)
5146 use
= WPAS_P2P_PD_AUTO
;
5148 return wpas_p2p_prov_disc(wpa_s
, addr
, pos
, use
, NULL
);
5152 static int p2p_get_passphrase(struct wpa_supplicant
*wpa_s
, char *buf
,
5155 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
5157 if (ssid
== NULL
|| ssid
->mode
!= WPAS_MODE_P2P_GO
||
5158 ssid
->passphrase
== NULL
)
5161 os_strlcpy(buf
, ssid
->passphrase
, buflen
);
5162 return os_strlen(buf
);
5166 static int p2p_ctrl_serv_disc_req(struct wpa_supplicant
*wpa_s
, char *cmd
,
5167 char *buf
, size_t buflen
)
5171 u8 dst_buf
[ETH_ALEN
], *dst
;
5172 struct wpabuf
*tlvs
;
5176 if (hwaddr_aton(cmd
, dst_buf
))
5179 if (dst
[0] == 0 && dst
[1] == 0 && dst
[2] == 0 &&
5180 dst
[3] == 0 && dst
[4] == 0 && dst
[5] == 0)
5187 if (os_strncmp(pos
, "upnp ", 5) == 0) {
5190 if (hexstr2bin(pos
, &version
, 1) < 0)
5196 ref
= wpas_p2p_sd_request_upnp(wpa_s
, dst
, version
, pos
);
5197 #ifdef CONFIG_WIFI_DISPLAY
5198 } else if (os_strncmp(pos
, "wifi-display ", 13) == 0) {
5199 ref
= wpas_p2p_sd_request_wifi_display(wpa_s
, dst
, pos
+ 13);
5200 #endif /* CONFIG_WIFI_DISPLAY */
5201 } else if (os_strncmp(pos
, "asp ", 4) == 0) {
5203 char *svc_info
= NULL
;
5207 if (sscanf(pos
, "%x", &id
) != 1 || id
> 0xff)
5210 pos
= os_strchr(pos
, ' ');
5211 if (pos
== NULL
|| pos
[1] == '\0' || pos
[1] == ' ')
5216 pos
= os_strchr(svc_str
, ' ');
5221 /* All remaining data is the svc_info string */
5222 if (pos
&& pos
[0] && pos
[0] != ' ') {
5223 len
= os_strlen(pos
);
5225 /* Unescape in place */
5226 len
= utf8_unescape(pos
, len
, pos
, len
);
5233 ref
= wpas_p2p_sd_request_asp(wpa_s
, dst
, (u8
) id
,
5236 len
= os_strlen(pos
);
5240 tlvs
= wpabuf_alloc(len
);
5243 if (hexstr2bin(pos
, wpabuf_put(tlvs
, len
), len
) < 0) {
5248 ref
= wpas_p2p_sd_request(wpa_s
, dst
, tlvs
);
5253 res
= os_snprintf(buf
, buflen
, "%llx", (long long unsigned) ref
);
5254 if (os_snprintf_error(buflen
, res
))
5260 static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant
*wpa_s
,
5263 long long unsigned val
;
5265 if (sscanf(cmd
, "%llx", &val
) != 1)
5268 return wpas_p2p_sd_cancel_request(wpa_s
, req
);
5272 static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant
*wpa_s
, char *cmd
)
5277 struct wpabuf
*resp_tlvs
;
5281 pos
= os_strchr(cmd
, ' ');
5289 if (hwaddr_aton(pos
, dst
))
5296 pos2
= os_strchr(pos
, ' ');
5300 dialog_token
= atoi(pos
);
5302 len
= os_strlen(pos2
);
5306 resp_tlvs
= wpabuf_alloc(len
);
5307 if (resp_tlvs
== NULL
)
5309 if (hexstr2bin(pos2
, wpabuf_put(resp_tlvs
, len
), len
) < 0) {
5310 wpabuf_free(resp_tlvs
);
5314 wpas_p2p_sd_response(wpa_s
, freq
, dst
, dialog_token
, resp_tlvs
);
5315 wpabuf_free(resp_tlvs
);
5320 static int p2p_ctrl_serv_disc_external(struct wpa_supplicant
*wpa_s
,
5323 if (os_strcmp(cmd
, "0") && os_strcmp(cmd
, "1"))
5325 wpa_s
->p2p_sd_over_ctrl_iface
= atoi(cmd
);
5330 static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant
*wpa_s
,
5335 struct wpabuf
*query
, *resp
;
5337 pos
= os_strchr(cmd
, ' ');
5342 len
= os_strlen(cmd
);
5346 query
= wpabuf_alloc(len
);
5349 if (hexstr2bin(cmd
, wpabuf_put(query
, len
), len
) < 0) {
5354 len
= os_strlen(pos
);
5360 resp
= wpabuf_alloc(len
);
5365 if (hexstr2bin(pos
, wpabuf_put(resp
, len
), len
) < 0) {
5371 if (wpas_p2p_service_add_bonjour(wpa_s
, query
, resp
) < 0) {
5380 static int p2p_ctrl_service_add_upnp(struct wpa_supplicant
*wpa_s
, char *cmd
)
5385 pos
= os_strchr(cmd
, ' ');
5390 if (hexstr2bin(cmd
, &version
, 1) < 0)
5393 return wpas_p2p_service_add_upnp(wpa_s
, version
, pos
);
5397 static int p2p_ctrl_service_add_asp(struct wpa_supplicant
*wpa_s
,
5398 u8 replace
, char *cmd
)
5402 u32 auto_accept
, adv_id
, svc_state
, config_methods
;
5403 char *svc_info
= NULL
;
5405 u8 cpt_prio
[P2PS_FEATURE_CAPAB_CPT_MAX
+ 1];
5407 pos
= os_strchr(cmd
, ' ');
5412 /* Auto-Accept value is mandatory, and must be one of the
5413 * single values (0, 1, 2, 4) */
5414 auto_accept
= atoi(cmd
);
5415 switch (auto_accept
) {
5416 case P2PS_SETUP_NONE
: /* No auto-accept */
5417 case P2PS_SETUP_NEW
:
5418 case P2PS_SETUP_CLIENT
:
5419 case P2PS_SETUP_GROUP_OWNER
:
5425 /* Advertisement ID is mandatory */
5427 pos
= os_strchr(cmd
, ' ');
5432 /* Handle Adv_ID == 0 (wildcard "org.wi-fi.wfds") internally. */
5433 if (sscanf(cmd
, "%x", &adv_id
) != 1 || adv_id
== 0)
5436 /* Only allow replacements if exist, and adds if not */
5437 if (wpas_p2p_service_p2ps_id_exists(wpa_s
, adv_id
)) {
5445 /* svc_state between 0 - 0xff is mandatory */
5446 if (sscanf(pos
, "%x", &svc_state
) != 1 || svc_state
> 0xff)
5449 pos
= os_strchr(pos
, ' ');
5453 /* config_methods is mandatory */
5455 if (sscanf(pos
, "%x", &config_methods
) != 1)
5458 if (!(config_methods
&
5459 (WPS_CONFIG_DISPLAY
| WPS_CONFIG_KEYPAD
| WPS_CONFIG_P2PS
)))
5462 pos
= os_strchr(pos
, ' ');
5469 /* Advertisement string is mandatory */
5470 if (!pos
[0] || pos
[0] == ' ')
5473 /* Terminate svc string */
5474 pos
= os_strchr(pos
, ' ');
5478 cpt_prio_str
= (pos
&& pos
[0]) ? os_strstr(pos
, "cpt=") : NULL
;
5480 pos
= os_strchr(pos
, ' ');
5484 if (p2ps_ctrl_parse_cpt_priority(cpt_prio_str
+ 4, cpt_prio
))
5487 cpt_prio
[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT
;
5491 /* Service and Response Information are optional */
5492 if (pos
&& pos
[0]) {
5495 /* Note the bare ' included, which cannot exist legally
5496 * in unescaped string. */
5497 svc_info
= os_strstr(pos
, "svc_info='");
5501 len
= os_strlen(svc_info
);
5502 utf8_unescape(svc_info
, len
, svc_info
, len
);
5506 return wpas_p2p_service_add_asp(wpa_s
, auto_accept
, adv_id
, adv_str
,
5507 (u8
) svc_state
, (u16
) config_methods
,
5508 svc_info
, cpt_prio
);
5512 static int p2p_ctrl_service_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
5516 pos
= os_strchr(cmd
, ' ');
5521 if (os_strcmp(cmd
, "bonjour") == 0)
5522 return p2p_ctrl_service_add_bonjour(wpa_s
, pos
);
5523 if (os_strcmp(cmd
, "upnp") == 0)
5524 return p2p_ctrl_service_add_upnp(wpa_s
, pos
);
5525 if (os_strcmp(cmd
, "asp") == 0)
5526 return p2p_ctrl_service_add_asp(wpa_s
, 0, pos
);
5527 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
5532 static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant
*wpa_s
,
5536 struct wpabuf
*query
;
5539 len
= os_strlen(cmd
);
5543 query
= wpabuf_alloc(len
);
5546 if (hexstr2bin(cmd
, wpabuf_put(query
, len
), len
) < 0) {
5551 ret
= wpas_p2p_service_del_bonjour(wpa_s
, query
);
5557 static int p2p_ctrl_service_del_upnp(struct wpa_supplicant
*wpa_s
, char *cmd
)
5562 pos
= os_strchr(cmd
, ' ');
5567 if (hexstr2bin(cmd
, &version
, 1) < 0)
5570 return wpas_p2p_service_del_upnp(wpa_s
, version
, pos
);
5574 static int p2p_ctrl_service_del_asp(struct wpa_supplicant
*wpa_s
, char *cmd
)
5578 if (os_strcmp(cmd
, "all") == 0) {
5579 wpas_p2p_service_flush_asp(wpa_s
);
5583 if (sscanf(cmd
, "%x", &adv_id
) != 1)
5586 return wpas_p2p_service_del_asp(wpa_s
, adv_id
);
5590 static int p2p_ctrl_service_del(struct wpa_supplicant
*wpa_s
, char *cmd
)
5594 pos
= os_strchr(cmd
, ' ');
5599 if (os_strcmp(cmd
, "bonjour") == 0)
5600 return p2p_ctrl_service_del_bonjour(wpa_s
, pos
);
5601 if (os_strcmp(cmd
, "upnp") == 0)
5602 return p2p_ctrl_service_del_upnp(wpa_s
, pos
);
5603 if (os_strcmp(cmd
, "asp") == 0)
5604 return p2p_ctrl_service_del_asp(wpa_s
, pos
);
5605 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
5610 static int p2p_ctrl_service_replace(struct wpa_supplicant
*wpa_s
, char *cmd
)
5614 pos
= os_strchr(cmd
, ' ');
5619 if (os_strcmp(cmd
, "asp") == 0)
5620 return p2p_ctrl_service_add_asp(wpa_s
, 1, pos
);
5622 wpa_printf(MSG_DEBUG
, "Unknown service '%s'", cmd
);
5627 static int p2p_ctrl_reject(struct wpa_supplicant
*wpa_s
, char *cmd
)
5633 if (hwaddr_aton(cmd
, addr
))
5636 return wpas_p2p_reject(wpa_s
, addr
);
5640 static int p2p_ctrl_invite_persistent(struct wpa_supplicant
*wpa_s
, char *cmd
)
5644 struct wpa_ssid
*ssid
;
5645 u8
*_peer
= NULL
, peer
[ETH_ALEN
];
5646 int freq
= 0, pref_freq
= 0;
5647 int ht40
, vht
, max_oper_chwidth
, chwidth
= 0, freq2
= 0;
5650 pos
= os_strstr(cmd
, " peer=");
5653 if (hwaddr_aton(pos
, peer
))
5657 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
5658 if (ssid
== NULL
|| ssid
->disabled
!= 2) {
5659 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
5660 "for persistent P2P group",
5665 pos
= os_strstr(cmd
, " freq=");
5673 pos
= os_strstr(cmd
, " pref=");
5676 pref_freq
= atoi(pos
);
5681 vht
= (os_strstr(cmd
, " vht") != NULL
) || wpa_s
->conf
->p2p_go_vht
;
5682 ht40
= (os_strstr(cmd
, " ht40") != NULL
) || wpa_s
->conf
->p2p_go_ht40
||
5685 pos
= os_strstr(cmd
, "freq2=");
5687 freq2
= atoi(pos
+ 6);
5689 pos
= os_strstr(cmd
, " max_oper_chwidth=");
5691 chwidth
= atoi(pos
+ 18);
5693 max_oper_chwidth
= parse_freq(chwidth
, freq2
);
5694 if (max_oper_chwidth
< 0)
5697 return wpas_p2p_invite(wpa_s
, _peer
, ssid
, NULL
, freq
, freq2
, ht40
, vht
,
5698 max_oper_chwidth
, pref_freq
);
5702 static int p2p_ctrl_invite_group(struct wpa_supplicant
*wpa_s
, char *cmd
)
5705 u8 peer
[ETH_ALEN
], go_dev_addr
[ETH_ALEN
], *go_dev
= NULL
;
5707 pos
= os_strstr(cmd
, " peer=");
5713 if (hwaddr_aton(pos
, peer
)) {
5714 wpa_printf(MSG_DEBUG
, "P2P: Invalid MAC address '%s'", pos
);
5718 pos
= os_strstr(pos
, " go_dev_addr=");
5721 if (hwaddr_aton(pos
, go_dev_addr
)) {
5722 wpa_printf(MSG_DEBUG
, "P2P: Invalid MAC address '%s'",
5726 go_dev
= go_dev_addr
;
5729 return wpas_p2p_invite_group(wpa_s
, cmd
, peer
, go_dev
);
5733 static int p2p_ctrl_invite(struct wpa_supplicant
*wpa_s
, char *cmd
)
5735 if (os_strncmp(cmd
, "persistent=", 11) == 0)
5736 return p2p_ctrl_invite_persistent(wpa_s
, cmd
+ 11);
5737 if (os_strncmp(cmd
, "group=", 6) == 0)
5738 return p2p_ctrl_invite_group(wpa_s
, cmd
+ 6);
5744 static int p2p_ctrl_group_add_persistent(struct wpa_supplicant
*wpa_s
,
5745 int id
, int freq
, int vht_center_freq2
,
5746 int ht40
, int vht
, int vht_chwidth
)
5748 struct wpa_ssid
*ssid
;
5750 ssid
= wpa_config_get_network(wpa_s
->conf
, id
);
5751 if (ssid
== NULL
|| ssid
->disabled
!= 2) {
5752 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Could not find SSID id=%d "
5753 "for persistent P2P group",
5758 return wpas_p2p_group_add_persistent(wpa_s
, ssid
, 0, freq
,
5759 vht_center_freq2
, 0, ht40
, vht
,
5760 vht_chwidth
, NULL
, 0, 0);
5764 static int p2p_ctrl_group_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
5766 int freq
= 0, persistent
= 0, group_id
= -1;
5767 int vht
= wpa_s
->conf
->p2p_go_vht
;
5768 int ht40
= wpa_s
->conf
->p2p_go_ht40
|| vht
;
5769 int max_oper_chwidth
, chwidth
= 0, freq2
= 0;
5770 char *token
, *context
= NULL
;
5772 while ((token
= str_token(cmd
, " ", &context
))) {
5773 if (sscanf(token
, "freq=%d", &freq
) == 1 ||
5774 sscanf(token
, "freq2=%d", &freq2
) == 1 ||
5775 sscanf(token
, "persistent=%d", &group_id
) == 1 ||
5776 sscanf(token
, "max_oper_chwidth=%d", &chwidth
) == 1) {
5778 } else if (os_strcmp(token
, "ht40") == 0) {
5780 } else if (os_strcmp(token
, "vht") == 0) {
5783 } else if (os_strcmp(token
, "persistent") == 0) {
5786 wpa_printf(MSG_DEBUG
,
5787 "CTRL: Invalid P2P_GROUP_ADD parameter: '%s'",
5793 max_oper_chwidth
= parse_freq(chwidth
, freq2
);
5794 if (max_oper_chwidth
< 0)
5798 return p2p_ctrl_group_add_persistent(wpa_s
, group_id
,
5799 freq
, freq2
, ht40
, vht
,
5802 return wpas_p2p_group_add(wpa_s
, persistent
, freq
, freq2
, ht40
, vht
,
5807 static int p2p_ctrl_group_member(struct wpa_supplicant
*wpa_s
, const char *cmd
,
5808 char *buf
, size_t buflen
)
5810 u8 dev_addr
[ETH_ALEN
];
5811 struct wpa_ssid
*ssid
;
5815 ssid
= wpa_s
->current_ssid
;
5816 if (!wpa_s
->global
->p2p
|| !ssid
|| ssid
->mode
!= WPAS_MODE_P2P_GO
||
5817 hwaddr_aton(cmd
, dev_addr
))
5820 iaddr
= p2p_group_get_client_interface_addr(wpa_s
->p2p_group
, dev_addr
);
5823 res
= os_snprintf(buf
, buflen
, MACSTR
, MAC2STR(iaddr
));
5824 if (os_snprintf_error(buflen
, res
))
5830 static int p2p_ctrl_peer(struct wpa_supplicant
*wpa_s
, char *cmd
,
5831 char *buf
, size_t buflen
)
5833 u8 addr
[ETH_ALEN
], *addr_ptr
;
5835 const struct p2p_peer_info
*info
;
5837 char devtype
[WPS_DEV_TYPE_BUFSIZE
];
5838 struct wpa_ssid
*ssid
;
5841 if (!wpa_s
->global
->p2p
)
5844 if (os_strcmp(cmd
, "FIRST") == 0) {
5847 } else if (os_strncmp(cmd
, "NEXT-", 5) == 0) {
5848 if (hwaddr_aton(cmd
+ 5, addr
) < 0)
5853 if (hwaddr_aton(cmd
, addr
) < 0)
5859 info
= p2p_get_peer_info(wpa_s
->global
->p2p
, addr_ptr
, next
);
5866 res
= os_snprintf(pos
, end
- pos
, MACSTR
"\n"
5872 "serial_number=%s\n"
5873 "config_methods=0x%x\n"
5875 "group_capab=0x%x\n"
5877 MAC2STR(info
->p2p_device_addr
),
5878 wps_dev_type_bin2str(info
->pri_dev_type
,
5879 devtype
, sizeof(devtype
)),
5884 info
->serial_number
,
5885 info
->config_methods
,
5889 if (os_snprintf_error(end
- pos
, res
))
5893 for (i
= 0; i
< info
->wps_sec_dev_type_list_len
/ WPS_DEV_TYPE_LEN
; i
++)
5896 t
= &info
->wps_sec_dev_type_list
[i
* WPS_DEV_TYPE_LEN
];
5897 res
= os_snprintf(pos
, end
- pos
, "sec_dev_type=%s\n",
5898 wps_dev_type_bin2str(t
, devtype
,
5900 if (os_snprintf_error(end
- pos
, res
))
5905 ssid
= wpas_p2p_get_persistent(wpa_s
, info
->p2p_device_addr
, NULL
, 0);
5907 res
= os_snprintf(pos
, end
- pos
, "persistent=%d\n", ssid
->id
);
5908 if (os_snprintf_error(end
- pos
, res
))
5913 res
= p2p_get_peer_info_txt(info
, pos
, end
- pos
);
5918 if (info
->vendor_elems
) {
5919 res
= os_snprintf(pos
, end
- pos
, "vendor_elems=");
5920 if (os_snprintf_error(end
- pos
, res
))
5924 pos
+= wpa_snprintf_hex(pos
, end
- pos
,
5925 wpabuf_head(info
->vendor_elems
),
5926 wpabuf_len(info
->vendor_elems
));
5928 res
= os_snprintf(pos
, end
- pos
, "\n");
5929 if (os_snprintf_error(end
- pos
, res
))
5938 static int p2p_ctrl_disallow_freq(struct wpa_supplicant
*wpa_s
,
5943 if (wpa_s
->global
->p2p
== NULL
)
5946 if (freq_range_list_parse(&wpa_s
->global
->p2p_disallow_freq
, param
) < 0)
5949 for (i
= 0; i
< wpa_s
->global
->p2p_disallow_freq
.num
; i
++) {
5950 struct wpa_freq_range
*freq
;
5951 freq
= &wpa_s
->global
->p2p_disallow_freq
.range
[i
];
5952 wpa_printf(MSG_DEBUG
, "P2P: Disallowed frequency range %u-%u",
5953 freq
->min
, freq
->max
);
5956 wpas_p2p_update_channel_list(wpa_s
, WPAS_P2P_CHANNEL_UPDATE_DISALLOW
);
5961 static int p2p_ctrl_set(struct wpa_supplicant
*wpa_s
, char *cmd
)
5965 if (wpa_s
->global
->p2p
== NULL
)
5968 param
= os_strchr(cmd
, ' ');
5973 if (os_strcmp(cmd
, "discoverability") == 0) {
5974 p2p_set_client_discoverability(wpa_s
->global
->p2p
,
5979 if (os_strcmp(cmd
, "managed") == 0) {
5980 p2p_set_managed_oper(wpa_s
->global
->p2p
, atoi(param
));
5984 if (os_strcmp(cmd
, "listen_channel") == 0) {
5986 u8 channel
, op_class
;
5988 channel
= atoi(param
);
5989 pos
= os_strchr(param
, ' ');
5990 op_class
= pos
? atoi(pos
) : 81;
5992 return p2p_set_listen_channel(wpa_s
->global
->p2p
, op_class
,
5996 if (os_strcmp(cmd
, "ssid_postfix") == 0) {
5997 return p2p_set_ssid_postfix(wpa_s
->global
->p2p
, (u8
*) param
,
6001 if (os_strcmp(cmd
, "noa") == 0) {
6003 int count
, start
, duration
;
6004 /* GO NoA parameters: count,start_offset(ms),duration(ms) */
6005 count
= atoi(param
);
6006 pos
= os_strchr(param
, ',');
6011 pos
= os_strchr(pos
, ',');
6015 duration
= atoi(pos
);
6016 if (count
< 0 || count
> 255 || start
< 0 || duration
< 0)
6018 if (count
== 0 && duration
> 0)
6020 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
6021 "start=%d duration=%d", count
, start
, duration
);
6022 return wpas_p2p_set_noa(wpa_s
, count
, start
, duration
);
6025 if (os_strcmp(cmd
, "ps") == 0)
6026 return wpa_drv_set_p2p_powersave(wpa_s
, atoi(param
), -1, -1);
6028 if (os_strcmp(cmd
, "oppps") == 0)
6029 return wpa_drv_set_p2p_powersave(wpa_s
, -1, atoi(param
), -1);
6031 if (os_strcmp(cmd
, "ctwindow") == 0)
6032 return wpa_drv_set_p2p_powersave(wpa_s
, -1, -1, atoi(param
));
6034 if (os_strcmp(cmd
, "disabled") == 0) {
6035 wpa_s
->global
->p2p_disabled
= atoi(param
);
6036 wpa_printf(MSG_DEBUG
, "P2P functionality %s",
6037 wpa_s
->global
->p2p_disabled
?
6038 "disabled" : "enabled");
6039 if (wpa_s
->global
->p2p_disabled
) {
6040 wpas_p2p_stop_find(wpa_s
);
6041 os_memset(wpa_s
->p2p_auth_invite
, 0, ETH_ALEN
);
6042 p2p_flush(wpa_s
->global
->p2p
);
6047 if (os_strcmp(cmd
, "conc_pref") == 0) {
6048 if (os_strcmp(param
, "sta") == 0)
6049 wpa_s
->global
->conc_pref
= WPA_CONC_PREF_STA
;
6050 else if (os_strcmp(param
, "p2p") == 0)
6051 wpa_s
->global
->conc_pref
= WPA_CONC_PREF_P2P
;
6053 wpa_printf(MSG_INFO
, "Invalid conc_pref value");
6056 wpa_printf(MSG_DEBUG
, "Single channel concurrency preference: "
6061 if (os_strcmp(cmd
, "force_long_sd") == 0) {
6062 wpa_s
->force_long_sd
= atoi(param
);
6066 if (os_strcmp(cmd
, "peer_filter") == 0) {
6068 if (hwaddr_aton(param
, addr
))
6070 p2p_set_peer_filter(wpa_s
->global
->p2p
, addr
);
6074 if (os_strcmp(cmd
, "cross_connect") == 0)
6075 return wpas_p2p_set_cross_connect(wpa_s
, atoi(param
));
6077 if (os_strcmp(cmd
, "go_apsd") == 0) {
6078 if (os_strcmp(param
, "disable") == 0)
6079 wpa_s
->set_ap_uapsd
= 0;
6081 wpa_s
->set_ap_uapsd
= 1;
6082 wpa_s
->ap_uapsd
= atoi(param
);
6087 if (os_strcmp(cmd
, "client_apsd") == 0) {
6088 if (os_strcmp(param
, "disable") == 0)
6089 wpa_s
->set_sta_uapsd
= 0;
6093 /* format: BE,BK,VI,VO;max SP Length */
6095 pos
= os_strchr(param
, ',');
6100 pos
= os_strchr(pos
, ',');
6105 pos
= os_strchr(pos
, ',');
6110 /* ignore max SP Length for now */
6112 wpa_s
->set_sta_uapsd
= 1;
6113 wpa_s
->sta_uapsd
= 0;
6115 wpa_s
->sta_uapsd
|= BIT(0);
6117 wpa_s
->sta_uapsd
|= BIT(1);
6119 wpa_s
->sta_uapsd
|= BIT(2);
6121 wpa_s
->sta_uapsd
|= BIT(3);
6126 if (os_strcmp(cmd
, "disallow_freq") == 0)
6127 return p2p_ctrl_disallow_freq(wpa_s
, param
);
6129 if (os_strcmp(cmd
, "disc_int") == 0) {
6130 int min_disc_int
, max_disc_int
, max_disc_tu
;
6135 min_disc_int
= atoi(pos
);
6136 pos
= os_strchr(pos
, ' ');
6141 max_disc_int
= atoi(pos
);
6142 pos
= os_strchr(pos
, ' ');
6147 max_disc_tu
= atoi(pos
);
6149 return p2p_set_disc_int(wpa_s
->global
->p2p
, min_disc_int
,
6150 max_disc_int
, max_disc_tu
);
6153 if (os_strcmp(cmd
, "per_sta_psk") == 0) {
6154 wpa_s
->global
->p2p_per_sta_psk
= !!atoi(param
);
6158 #ifdef CONFIG_WPS_NFC
6159 if (os_strcmp(cmd
, "nfc_tag") == 0)
6160 return wpas_p2p_nfc_tag_enabled(wpa_s
, !!atoi(param
));
6161 #endif /* CONFIG_WPS_NFC */
6163 if (os_strcmp(cmd
, "disable_ip_addr_req") == 0) {
6164 wpa_s
->p2p_disable_ip_addr_req
= !!atoi(param
);
6168 wpa_printf(MSG_DEBUG
, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
6175 static void p2p_ctrl_flush(struct wpa_supplicant
*wpa_s
)
6177 os_memset(wpa_s
->p2p_auth_invite
, 0, ETH_ALEN
);
6178 wpa_s
->force_long_sd
= 0;
6179 wpas_p2p_stop_find(wpa_s
);
6180 wpa_s
->parent
->p2ps_method_config_any
= 0;
6181 if (wpa_s
->global
->p2p
)
6182 p2p_flush(wpa_s
->global
->p2p
);
6186 static int p2p_ctrl_presence_req(struct wpa_supplicant
*wpa_s
, char *cmd
)
6189 unsigned int dur1
= 0, int1
= 0, dur2
= 0, int2
= 0;
6192 pos
= os_strchr(cmd
, ' ');
6198 pos2
= os_strchr(pos
, ' ');
6206 pos
= os_strchr(pos2
, ' ');
6214 return wpas_p2p_presence_req(wpa_s
, dur1
, int1
, dur2
, int2
);
6218 static int p2p_ctrl_ext_listen(struct wpa_supplicant
*wpa_s
, char *cmd
)
6221 unsigned int period
= 0, interval
= 0;
6224 pos
= os_strchr(cmd
, ' ');
6229 interval
= atoi(pos
);
6232 return wpas_p2p_ext_listen(wpa_s
, period
, interval
);
6236 static int p2p_ctrl_remove_client(struct wpa_supplicant
*wpa_s
, const char *cmd
)
6243 if (os_strncmp(pos
, "iface=", 6) == 0) {
6247 if (hwaddr_aton(pos
, peer
))
6250 wpas_p2p_remove_client(wpa_s
, peer
, iface_addr
);
6255 static int p2p_ctrl_iface_p2p_lo_start(struct wpa_supplicant
*wpa_s
, char *cmd
)
6257 int freq
= 0, period
= 0, interval
= 0, count
= 0;
6259 if (sscanf(cmd
, "%d %d %d %d", &freq
, &period
, &interval
, &count
) != 4)
6261 wpa_printf(MSG_DEBUG
,
6262 "CTRL: Invalid P2P LO Start parameter: '%s'", cmd
);
6266 return wpas_p2p_lo_start(wpa_s
, freq
, period
, interval
, count
);
6269 #endif /* CONFIG_P2P */
6272 static int * freq_range_to_channel_list(struct wpa_supplicant
*wpa_s
, char *val
)
6274 struct wpa_freq_range_list ranges
;
6276 struct hostapd_hw_modes
*mode
;
6279 if (wpa_s
->hw
.modes
== NULL
)
6282 os_memset(&ranges
, 0, sizeof(ranges
));
6283 if (freq_range_list_parse(&ranges
, val
) < 0)
6286 for (i
= 0; i
< wpa_s
->hw
.num_modes
; i
++) {
6289 mode
= &wpa_s
->hw
.modes
[i
];
6290 for (j
= 0; j
< mode
->num_channels
; j
++) {
6293 if (mode
->channels
[j
].flag
& HOSTAPD_CHAN_DISABLED
)
6296 freq
= mode
->channels
[j
].freq
;
6297 if (!freq_range_list_includes(&ranges
, freq
))
6300 int_array_add_unique(&freqs
, freq
);
6304 os_free(ranges
.range
);
6309 #ifdef CONFIG_INTERWORKING
6311 static int ctrl_interworking_select(struct wpa_supplicant
*wpa_s
, char *param
)
6319 auto_sel
= os_strstr(param
, "auto") != NULL
;
6321 pos
= os_strstr(param
, "freq=");
6323 freqs
= freq_range_to_channel_list(wpa_s
, pos
+ 5);
6330 return interworking_select(wpa_s
, auto_sel
, freqs
);
6334 static int ctrl_interworking_connect(struct wpa_supplicant
*wpa_s
, char *dst
,
6338 struct wpa_bss
*bss
;
6340 if (hwaddr_aton(dst
, bssid
)) {
6341 wpa_printf(MSG_DEBUG
, "Invalid BSSID '%s'", dst
);
6345 bss
= wpa_bss_get_bssid(wpa_s
, bssid
);
6347 wpa_printf(MSG_DEBUG
, "Could not find BSS " MACSTR
,
6352 if (bss
->ssid_len
== 0) {
6355 wpa_printf(MSG_DEBUG
, "Selected BSS entry for " MACSTR
6356 " does not have SSID information", MAC2STR(bssid
));
6358 dl_list_for_each_reverse(bss
, &wpa_s
->bss
, struct wpa_bss
,
6360 if (os_memcmp(bss
->bssid
, bssid
, ETH_ALEN
) == 0 &&
6361 bss
->ssid_len
> 0) {
6369 wpa_printf(MSG_DEBUG
,
6370 "Found another matching BSS entry with SSID");
6373 return interworking_connect(wpa_s
, bss
, only_add
);
6377 static int get_anqp(struct wpa_supplicant
*wpa_s
, char *dst
)
6379 u8 dst_addr
[ETH_ALEN
];
6382 #define MAX_ANQP_INFO_ID 100
6383 u16 id
[MAX_ANQP_INFO_ID
];
6386 int get_cell_pref
= 0;
6388 used
= hwaddr_aton2(dst
, dst_addr
);
6394 while (num_id
< MAX_ANQP_INFO_ID
) {
6395 if (os_strncmp(pos
, "hs20:", 5) == 0) {
6397 int num
= atoi(pos
+ 5);
6398 if (num
<= 0 || num
> 31)
6400 subtypes
|= BIT(num
);
6401 #else /* CONFIG_HS20 */
6403 #endif /* CONFIG_HS20 */
6404 } else if (os_strncmp(pos
, "mbo:", 4) == 0) {
6406 int num
= atoi(pos
+ 4);
6407 if (num
!= MBO_ANQP_SUBTYPE_CELL_CONN_PREF
)
6410 #else /* CONFIG_MBO */
6412 #endif /* CONFIG_MBO */
6414 id
[num_id
] = atoi(pos
);
6418 pos
= os_strchr(pos
+ 1, ',');
6427 return anqp_send_req(wpa_s
, dst_addr
, id
, num_id
, subtypes
,
6432 static int gas_request(struct wpa_supplicant
*wpa_s
, char *cmd
)
6434 u8 dst_addr
[ETH_ALEN
];
6435 struct wpabuf
*advproto
, *query
= NULL
;
6440 used
= hwaddr_aton2(cmd
, dst_addr
);
6448 /* Advertisement Protocol ID */
6449 end
= os_strchr(pos
, ' ');
6453 len
= os_strlen(pos
);
6459 advproto
= wpabuf_alloc(len
);
6460 if (advproto
== NULL
)
6462 if (hexstr2bin(pos
, wpabuf_put(advproto
, len
), len
) < 0)
6466 /* Optional Query Request */
6471 len
= os_strlen(pos
);
6478 query
= wpabuf_alloc(len
);
6481 if (hexstr2bin(pos
, wpabuf_put(query
, len
), len
) < 0)
6486 ret
= gas_send_request(wpa_s
, dst_addr
, advproto
, query
);
6489 wpabuf_free(advproto
);
6496 static int gas_response_get(struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
,
6503 size_t resp_len
, start
, requested_len
;
6504 struct wpabuf
*resp
;
6507 used
= hwaddr_aton2(cmd
, addr
);
6514 dialog_token
= atoi(pos
);
6516 if (wpa_s
->last_gas_resp
&&
6517 os_memcmp(addr
, wpa_s
->last_gas_addr
, ETH_ALEN
) == 0 &&
6518 dialog_token
== wpa_s
->last_gas_dialog_token
)
6519 resp
= wpa_s
->last_gas_resp
;
6520 else if (wpa_s
->prev_gas_resp
&&
6521 os_memcmp(addr
, wpa_s
->prev_gas_addr
, ETH_ALEN
) == 0 &&
6522 dialog_token
== wpa_s
->prev_gas_dialog_token
)
6523 resp
= wpa_s
->prev_gas_resp
;
6527 resp_len
= wpabuf_len(resp
);
6529 requested_len
= resp_len
;
6531 pos
= os_strchr(pos
, ' ');
6534 if (start
> resp_len
)
6535 return os_snprintf(buf
, buflen
, "FAIL-Invalid range");
6536 pos
= os_strchr(pos
, ',');
6540 requested_len
= atoi(pos
);
6541 if (start
+ requested_len
> resp_len
)
6542 return os_snprintf(buf
, buflen
, "FAIL-Invalid range");
6545 if (requested_len
* 2 + 1 > buflen
)
6546 return os_snprintf(buf
, buflen
, "FAIL-Too long response");
6548 ret
= wpa_snprintf_hex(buf
, buflen
, wpabuf_head_u8(resp
) + start
,
6551 if (start
+ requested_len
== resp_len
) {
6553 * Free memory by dropping the response after it has been
6556 if (resp
== wpa_s
->prev_gas_resp
) {
6557 wpabuf_free(wpa_s
->prev_gas_resp
);
6558 wpa_s
->prev_gas_resp
= NULL
;
6560 wpabuf_free(wpa_s
->last_gas_resp
);
6561 wpa_s
->last_gas_resp
= NULL
;
6567 #endif /* CONFIG_INTERWORKING */
6572 static int get_hs20_anqp(struct wpa_supplicant
*wpa_s
, char *dst
)
6574 u8 dst_addr
[ETH_ALEN
];
6579 used
= hwaddr_aton2(dst
, dst_addr
);
6586 int num
= atoi(pos
);
6587 if (num
<= 0 || num
> 31)
6589 subtypes
|= BIT(num
);
6590 pos
= os_strchr(pos
+ 1, ',');
6599 return hs20_anqp_send_req(wpa_s
, dst_addr
, subtypes
, NULL
, 0, 0);
6603 static int hs20_nai_home_realm_list(struct wpa_supplicant
*wpa_s
,
6604 const u8
*addr
, const char *realm
)
6610 rlen
= os_strlen(realm
);
6612 buf
= os_malloc(len
);
6615 buf
[0] = 1; /* NAI Home Realm Count */
6616 buf
[1] = 0; /* Formatted in accordance with RFC 4282 */
6618 os_memcpy(buf
+ 3, realm
, rlen
);
6620 ret
= hs20_anqp_send_req(wpa_s
, addr
,
6621 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY
),
6630 static int hs20_get_nai_home_realm_list(struct wpa_supplicant
*wpa_s
,
6633 struct wpa_cred
*cred
= wpa_s
->conf
->cred
;
6634 u8 dst_addr
[ETH_ALEN
];
6640 used
= hwaddr_aton2(dst
, dst_addr
);
6644 while (dst
[used
] == ' ')
6646 if (os_strncmp(dst
+ used
, "realm=", 6) == 0)
6647 return hs20_nai_home_realm_list(wpa_s
, dst_addr
,
6650 len
= os_strlen(dst
+ used
);
6652 if (len
== 0 && cred
&& cred
->realm
)
6653 return hs20_nai_home_realm_list(wpa_s
, dst_addr
, cred
->realm
);
6658 buf
= os_malloc(len
);
6661 if (hexstr2bin(dst
+ used
, buf
, len
) < 0) {
6666 ret
= hs20_anqp_send_req(wpa_s
, dst_addr
,
6667 BIT(HS20_STYPE_NAI_HOME_REALM_QUERY
),
6675 static int get_hs20_icon(struct wpa_supplicant
*wpa_s
, char *cmd
, char *reply
,
6678 u8 dst_addr
[ETH_ALEN
];
6680 char *ctx
= NULL
, *icon
, *poffset
, *psize
;
6682 used
= hwaddr_aton2(cmd
, dst_addr
);
6687 icon
= str_token(cmd
, " ", &ctx
);
6688 poffset
= str_token(cmd
, " ", &ctx
);
6689 psize
= str_token(cmd
, " ", &ctx
);
6690 if (!icon
|| !poffset
|| !psize
)
6693 wpa_s
->fetch_osu_icon_in_progress
= 0;
6694 return hs20_get_icon(wpa_s
, dst_addr
, icon
, atoi(poffset
), atoi(psize
),
6699 static int del_hs20_icon(struct wpa_supplicant
*wpa_s
, char *cmd
)
6701 u8 dst_addr
[ETH_ALEN
];
6706 return hs20_del_icon(wpa_s
, NULL
, NULL
);
6708 used
= hwaddr_aton2(cmd
, dst_addr
);
6712 while (cmd
[used
] == ' ')
6714 icon
= cmd
[used
] ? &cmd
[used
] : NULL
;
6716 return hs20_del_icon(wpa_s
, dst_addr
, icon
);
6720 static int hs20_icon_request(struct wpa_supplicant
*wpa_s
, char *cmd
, int inmem
)
6722 u8 dst_addr
[ETH_ALEN
];
6726 used
= hwaddr_aton2(cmd
, dst_addr
);
6730 while (cmd
[used
] == ' ')
6734 wpa_s
->fetch_osu_icon_in_progress
= 0;
6735 return hs20_anqp_send_req(wpa_s
, dst_addr
, BIT(HS20_STYPE_ICON_REQUEST
),
6736 (u8
*) icon
, os_strlen(icon
), inmem
);
6739 #endif /* CONFIG_HS20 */
6742 #ifdef CONFIG_AUTOSCAN
6744 static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant
*wpa_s
,
6747 enum wpa_states state
= wpa_s
->wpa_state
;
6748 char *new_params
= NULL
;
6750 if (os_strlen(cmd
) > 0) {
6751 new_params
= os_strdup(cmd
);
6752 if (new_params
== NULL
)
6756 os_free(wpa_s
->conf
->autoscan
);
6757 wpa_s
->conf
->autoscan
= new_params
;
6759 if (wpa_s
->conf
->autoscan
== NULL
)
6760 autoscan_deinit(wpa_s
);
6761 else if (state
== WPA_DISCONNECTED
|| state
== WPA_INACTIVE
)
6762 autoscan_init(wpa_s
, 1);
6763 else if (state
== WPA_SCANNING
)
6764 wpa_supplicant_reinit_autoscan(wpa_s
);
6769 #endif /* CONFIG_AUTOSCAN */
6774 static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant
*wpa_s
, char *cmd
)
6780 struct wpabuf
*tfs_req
= NULL
;
6782 if (os_strncmp(cmd
, "enter", 5) == 0)
6784 else if (os_strncmp(cmd
, "exit", 4) == 0)
6789 pos
= os_strstr(cmd
, " interval=");
6791 intval
= atoi(pos
+ 10);
6793 pos
= os_strstr(cmd
, " tfs_req=");
6798 end
= os_strchr(pos
, ' ');
6802 len
= os_strlen(pos
);
6806 tfs_req
= wpabuf_alloc(len
);
6807 if (tfs_req
== NULL
)
6809 if (hexstr2bin(pos
, wpabuf_put(tfs_req
, len
), len
) < 0) {
6810 wpabuf_free(tfs_req
);
6815 ret
= ieee802_11_send_wnmsleep_req(wpa_s
, enter
? WNM_SLEEP_MODE_ENTER
:
6816 WNM_SLEEP_MODE_EXIT
, intval
,
6818 wpabuf_free(tfs_req
);
6824 static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant
*wpa_s
, char *cmd
)
6826 int query_reason
, list
= 0;
6828 query_reason
= atoi(cmd
);
6830 cmd
= os_strchr(cmd
, ' ');
6833 if (os_strncmp(cmd
, "list", 4) == 0) {
6836 wpa_printf(MSG_DEBUG
, "WNM Query: Invalid option %s",
6842 wpa_printf(MSG_DEBUG
,
6843 "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d%s",
6844 query_reason
, list
? " candidate list" : "");
6846 return wnm_send_bss_transition_mgmt_query(wpa_s
, query_reason
, list
);
6849 #endif /* CONFIG_WNM */
6852 static int wpa_supplicant_signal_poll(struct wpa_supplicant
*wpa_s
, char *buf
,
6855 struct wpa_signal_info si
;
6859 ret
= wpa_drv_signal_poll(wpa_s
, &si
);
6866 ret
= os_snprintf(pos
, end
- pos
, "RSSI=%d\nLINKSPEED=%d\n"
6867 "NOISE=%d\nFREQUENCY=%u\n",
6868 si
.current_signal
, si
.current_txrate
/ 1000,
6869 si
.current_noise
, si
.frequency
);
6870 if (os_snprintf_error(end
- pos
, ret
))
6874 if (si
.chanwidth
!= CHAN_WIDTH_UNKNOWN
) {
6875 ret
= os_snprintf(pos
, end
- pos
, "WIDTH=%s\n",
6876 channel_width_to_string(si
.chanwidth
));
6877 if (os_snprintf_error(end
- pos
, ret
))
6882 if (si
.center_frq1
> 0 && si
.center_frq2
> 0) {
6883 ret
= os_snprintf(pos
, end
- pos
,
6884 "CENTER_FRQ1=%d\nCENTER_FRQ2=%d\n",
6885 si
.center_frq1
, si
.center_frq2
);
6886 if (os_snprintf_error(end
- pos
, ret
))
6891 if (si
.avg_signal
) {
6892 ret
= os_snprintf(pos
, end
- pos
,
6893 "AVG_RSSI=%d\n", si
.avg_signal
);
6894 if (os_snprintf_error(end
- pos
, ret
))
6899 if (si
.avg_beacon_signal
) {
6900 ret
= os_snprintf(pos
, end
- pos
,
6901 "AVG_BEACON_RSSI=%d\n", si
.avg_beacon_signal
);
6902 if (os_snprintf_error(end
- pos
, ret
))
6911 static int wpas_ctrl_iface_signal_monitor(struct wpa_supplicant
*wpa_s
,
6918 if (wpa_s
->bgscan
&& wpa_s
->bgscan_priv
) {
6919 wpa_printf(MSG_DEBUG
,
6920 "Reject SIGNAL_MONITOR command - bgscan is active");
6923 pos
= os_strstr(cmd
, "THRESHOLD=");
6925 threshold
= atoi(pos
+ 10);
6926 pos
= os_strstr(cmd
, "HYSTERESIS=");
6928 hysteresis
= atoi(pos
+ 11);
6929 return wpa_drv_signal_monitor(wpa_s
, threshold
, hysteresis
);
6933 static int wpas_ctrl_iface_get_pref_freq_list(
6934 struct wpa_supplicant
*wpa_s
, char *cmd
, char *buf
, size_t buflen
)
6936 unsigned int freq_list
[100], num
= 100, i
;
6938 enum wpa_driver_if_type iface_type
;
6944 /* buf: "<interface_type>" */
6945 if (os_strcmp(cmd
, "STATION") == 0)
6946 iface_type
= WPA_IF_STATION
;
6947 else if (os_strcmp(cmd
, "AP") == 0)
6948 iface_type
= WPA_IF_AP_BSS
;
6949 else if (os_strcmp(cmd
, "P2P_GO") == 0)
6950 iface_type
= WPA_IF_P2P_GO
;
6951 else if (os_strcmp(cmd
, "P2P_CLIENT") == 0)
6952 iface_type
= WPA_IF_P2P_CLIENT
;
6953 else if (os_strcmp(cmd
, "IBSS") == 0)
6954 iface_type
= WPA_IF_IBSS
;
6955 else if (os_strcmp(cmd
, "TDLS") == 0)
6956 iface_type
= WPA_IF_TDLS
;
6960 wpa_printf(MSG_DEBUG
,
6961 "CTRL_IFACE: GET_PREF_FREQ_LIST iface_type=%d (%s)",
6964 ret
= wpa_drv_get_pref_freq_list(wpa_s
, iface_type
, &num
, freq_list
);
6968 for (i
= 0; i
< num
; i
++) {
6969 ret
= os_snprintf(pos
, end
- pos
, "%s%u",
6970 i
> 0 ? "," : "", freq_list
[i
]);
6971 if (os_snprintf_error(end
- pos
, ret
))
6980 static int wpas_ctrl_iface_driver_flags(struct wpa_supplicant
*wpa_s
,
6981 char *buf
, size_t buflen
)
6986 ret
= os_snprintf(buf
, buflen
, "%016llX:\n",
6987 (long long unsigned) wpa_s
->drv_flags
);
6988 if (os_snprintf_error(buflen
, ret
))
6994 for (i
= 0; i
< 64; i
++) {
6995 if (wpa_s
->drv_flags
& (1LLU << i
)) {
6996 ret
= os_snprintf(pos
, end
- pos
, "%s\n",
6997 driver_flag_to_string(1LLU << i
));
6998 if (os_snprintf_error(end
- pos
, ret
))
7008 static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant
*wpa_s
, char *buf
,
7011 struct hostap_sta_driver_data sta
;
7014 ret
= wpa_drv_pktcnt_poll(wpa_s
, &sta
);
7018 ret
= os_snprintf(buf
, buflen
, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
7019 sta
.tx_packets
, sta
.tx_retry_failed
, sta
.rx_packets
);
7020 if (os_snprintf_error(buflen
, ret
))
7027 static int wpa_supplicant_driver_cmd(struct wpa_supplicant
*wpa_s
, char *cmd
,
7028 char *buf
, size_t buflen
)
7032 ret
= wpa_drv_driver_cmd(wpa_s
, cmd
, buf
, buflen
);
7034 if (os_strncasecmp(cmd
, "COUNTRY", 7) == 0) {
7035 struct p2p_data
*p2p
= wpa_s
->global
->p2p
;
7038 country
[0] = cmd
[8];
7039 country
[1] = cmd
[9];
7041 p2p_set_country(p2p
, country
);
7044 ret
= os_snprintf(buf
, buflen
, "%s\n", "OK");
7045 if (os_snprintf_error(buflen
, ret
))
7050 #endif /* ANDROID */
7053 static int wpa_supplicant_vendor_cmd(struct wpa_supplicant
*wpa_s
, char *cmd
,
7054 char *buf
, size_t buflen
)
7059 unsigned int vendor_id
, subcmd
;
7060 struct wpabuf
*reply
;
7061 size_t data_len
= 0;
7063 /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */
7064 vendor_id
= strtoul(cmd
, &pos
, 16);
7065 if (!isblank((unsigned char) *pos
))
7068 subcmd
= strtoul(pos
, &pos
, 10);
7071 if (!isblank((unsigned char) *pos
++))
7073 data_len
= os_strlen(pos
);
7078 data
= os_malloc(data_len
);
7082 if (hexstr2bin(pos
, data
, data_len
)) {
7083 wpa_printf(MSG_DEBUG
,
7084 "Vendor command: wrong parameter format");
7090 reply
= wpabuf_alloc((buflen
- 1) / 2);
7096 ret
= wpa_drv_vendor_cmd(wpa_s
, vendor_id
, subcmd
, data
, data_len
,
7100 ret
= wpa_snprintf_hex(buf
, buflen
, wpabuf_head_u8(reply
),
7110 static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant
*wpa_s
)
7113 struct wpa_supplicant
*p2p_wpa_s
= wpa_s
->global
->p2p_init_wpa_s
?
7114 wpa_s
->global
->p2p_init_wpa_s
: wpa_s
;
7115 #endif /* CONFIG_P2P */
7117 wpa_dbg(wpa_s
, MSG_DEBUG
, "Flush all wpa_supplicant state");
7119 wpas_abort_ongoing_scan(wpa_s
);
7121 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
7123 * Avoid possible auto connect re-connection on getting
7124 * disconnected due to state flush.
7126 wpa_supplicant_set_state(wpa_s
, WPA_DISCONNECTED
);
7130 wpas_p2p_group_remove(p2p_wpa_s
, "*");
7131 wpas_p2p_cancel(p2p_wpa_s
);
7132 p2p_ctrl_flush(p2p_wpa_s
);
7133 wpas_p2p_service_flush(p2p_wpa_s
);
7134 p2p_wpa_s
->global
->p2p_disabled
= 0;
7135 p2p_wpa_s
->global
->p2p_per_sta_psk
= 0;
7136 p2p_wpa_s
->conf
->num_sec_device_types
= 0;
7137 p2p_wpa_s
->p2p_disable_ip_addr_req
= 0;
7138 os_free(p2p_wpa_s
->global
->p2p_go_avoid_freq
.range
);
7139 p2p_wpa_s
->global
->p2p_go_avoid_freq
.range
= NULL
;
7140 p2p_wpa_s
->global
->p2p_go_avoid_freq
.num
= 0;
7141 p2p_wpa_s
->global
->pending_p2ps_group
= 0;
7142 p2p_wpa_s
->global
->pending_p2ps_group_freq
= 0;
7143 #endif /* CONFIG_P2P */
7145 #ifdef CONFIG_WPS_TESTING
7146 wps_version_number
= 0x20;
7147 wps_testing_dummy_cred
= 0;
7148 wps_corrupt_pkhash
= 0;
7149 wps_force_auth_types_in_use
= 0;
7150 wps_force_encr_types_in_use
= 0;
7151 #endif /* CONFIG_WPS_TESTING */
7153 wpa_s
->wps_fragment_size
= 0;
7154 wpas_wps_cancel(wpa_s
);
7155 wps_registrar_flush(wpa_s
->wps
->registrar
);
7156 #endif /* CONFIG_WPS */
7157 wpa_s
->after_wps
= 0;
7158 wpa_s
->known_wps_freq
= 0;
7161 #ifdef CONFIG_TDLS_TESTING
7163 #endif /* CONFIG_TDLS_TESTING */
7164 wpa_drv_tdls_oper(wpa_s
, TDLS_ENABLE
, NULL
);
7165 wpa_tdls_enable(wpa_s
->wpa
, 1);
7166 #endif /* CONFIG_TDLS */
7168 eloop_cancel_timeout(wpa_supplicant_stop_countermeasures
, wpa_s
, NULL
);
7169 wpa_supplicant_stop_countermeasures(wpa_s
, NULL
);
7171 wpa_s
->no_keep_alive
= 0;
7172 wpa_s
->own_disconnect_req
= 0;
7174 os_free(wpa_s
->disallow_aps_bssid
);
7175 wpa_s
->disallow_aps_bssid
= NULL
;
7176 wpa_s
->disallow_aps_bssid_count
= 0;
7177 os_free(wpa_s
->disallow_aps_ssid
);
7178 wpa_s
->disallow_aps_ssid
= NULL
;
7179 wpa_s
->disallow_aps_ssid_count
= 0;
7181 wpa_s
->set_sta_uapsd
= 0;
7182 wpa_s
->sta_uapsd
= 0;
7184 wpa_drv_radio_disable(wpa_s
, 0);
7185 wpa_blacklist_clear(wpa_s
);
7186 wpa_s
->extra_blacklist_count
= 0;
7187 wpa_supplicant_ctrl_iface_remove_network(wpa_s
, "all");
7188 wpa_supplicant_ctrl_iface_remove_cred(wpa_s
, "all");
7189 wpa_config_flush_blobs(wpa_s
->conf
);
7190 wpa_s
->conf
->auto_interworking
= 0;
7191 wpa_s
->conf
->okc
= 0;
7193 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, NULL
);
7194 rsn_preauth_deinit(wpa_s
->wpa
);
7196 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_LIFETIME
, 43200);
7197 wpa_sm_set_param(wpa_s
->wpa
, RSNA_PMK_REAUTH_THRESHOLD
, 70);
7198 wpa_sm_set_param(wpa_s
->wpa
, RSNA_SA_TIMEOUT
, 60);
7199 eapol_sm_notify_logoff(wpa_s
->eapol
, FALSE
);
7201 radio_remove_works(wpa_s
, NULL
, 1);
7202 wpa_s
->ext_work_in_progress
= 0;
7204 wpa_s
->next_ssid
= NULL
;
7206 #ifdef CONFIG_INTERWORKING
7208 hs20_cancel_fetch_osu(wpa_s
);
7209 hs20_del_icon(wpa_s
, NULL
, NULL
);
7210 #endif /* CONFIG_HS20 */
7211 #endif /* CONFIG_INTERWORKING */
7213 wpa_s
->ext_mgmt_frame_handling
= 0;
7214 wpa_s
->ext_eapol_frame_io
= 0;
7215 #ifdef CONFIG_TESTING_OPTIONS
7216 wpa_s
->extra_roc_dur
= 0;
7217 wpa_s
->test_failure
= WPAS_TEST_FAILURE_NONE
;
7218 wpa_s
->p2p_go_csa_on_inv
= 0;
7219 wpa_s
->ignore_auth_resp
= 0;
7220 wpa_s
->ignore_assoc_disallow
= 0;
7221 wpa_s
->reject_btm_req_reason
= 0;
7222 wpa_sm_set_test_assoc_ie(wpa_s
->wpa
, NULL
);
7223 #endif /* CONFIG_TESTING_OPTIONS */
7225 wpa_s
->disconnected
= 0;
7226 os_free(wpa_s
->next_scan_freqs
);
7227 wpa_s
->next_scan_freqs
= NULL
;
7229 wpa_bss_flush(wpa_s
);
7230 if (!dl_list_empty(&wpa_s
->bss
)) {
7231 wpa_printf(MSG_DEBUG
,
7232 "BSS table not empty after flush: %u entries, current_bss=%p bssid="
7233 MACSTR
" pending_bssid=" MACSTR
,
7234 dl_list_len(&wpa_s
->bss
), wpa_s
->current_bss
,
7235 MAC2STR(wpa_s
->bssid
),
7236 MAC2STR(wpa_s
->pending_bssid
));
7239 eloop_cancel_timeout(wpas_network_reenabled
, wpa_s
, NULL
);
7240 wpa_s
->wnmsleep_used
= 0;
7243 wpa_s
->sme
.last_unprot_disconnect
.sec
= 0;
7244 #endif /* CONFIG_SME */
7248 static int wpas_ctrl_radio_work_show(struct wpa_supplicant
*wpa_s
,
7249 char *buf
, size_t buflen
)
7251 struct wpa_radio_work
*work
;
7253 struct os_reltime now
, diff
;
7258 os_get_reltime(&now
);
7260 dl_list_for_each(work
, &wpa_s
->radio
->work
, struct wpa_radio_work
, list
)
7264 os_reltime_sub(&now
, &work
->time
, &diff
);
7265 ret
= os_snprintf(pos
, end
- pos
, "%s@%s:%u:%u:%ld.%06ld\n",
7266 work
->type
, work
->wpa_s
->ifname
, work
->freq
,
7267 work
->started
, diff
.sec
, diff
.usec
);
7268 if (os_snprintf_error(end
- pos
, ret
))
7277 static void wpas_ctrl_radio_work_timeout(void *eloop_ctx
, void *timeout_ctx
)
7279 struct wpa_radio_work
*work
= eloop_ctx
;
7280 struct wpa_external_work
*ework
= work
->ctx
;
7282 wpa_dbg(work
->wpa_s
, MSG_DEBUG
,
7283 "Timing out external radio work %u (%s)",
7284 ework
->id
, work
->type
);
7285 wpa_msg(work
->wpa_s
, MSG_INFO
, EXT_RADIO_WORK_TIMEOUT
"%u", ework
->id
);
7286 work
->wpa_s
->ext_work_in_progress
= 0;
7287 radio_work_done(work
);
7292 static void wpas_ctrl_radio_work_cb(struct wpa_radio_work
*work
, int deinit
)
7294 struct wpa_external_work
*ework
= work
->ctx
;
7298 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
,
7302 * work->type points to a buffer in ework, so need to replace
7303 * that here with a fixed string to avoid use of freed memory
7306 work
->type
= "freed-ext-work";
7312 wpa_dbg(work
->wpa_s
, MSG_DEBUG
, "Starting external radio work %u (%s)",
7313 ework
->id
, ework
->type
);
7314 wpa_msg(work
->wpa_s
, MSG_INFO
, EXT_RADIO_WORK_START
"%u", ework
->id
);
7315 work
->wpa_s
->ext_work_in_progress
= 1;
7316 if (!ework
->timeout
)
7317 ework
->timeout
= 10;
7318 eloop_register_timeout(ework
->timeout
, 0, wpas_ctrl_radio_work_timeout
,
7323 static int wpas_ctrl_radio_work_add(struct wpa_supplicant
*wpa_s
, char *cmd
,
7324 char *buf
, size_t buflen
)
7326 struct wpa_external_work
*ework
;
7330 unsigned int freq
= 0;
7332 /* format: <name> [freq=<MHz>] [timeout=<seconds>] */
7334 ework
= os_zalloc(sizeof(*ework
));
7338 pos
= os_strchr(cmd
, ' ');
7340 type_len
= pos
- cmd
;
7343 pos2
= os_strstr(pos
, "freq=");
7345 freq
= atoi(pos2
+ 5);
7347 pos2
= os_strstr(pos
, "timeout=");
7349 ework
->timeout
= atoi(pos2
+ 8);
7351 type_len
= os_strlen(cmd
);
7353 if (4 + type_len
>= sizeof(ework
->type
))
7354 type_len
= sizeof(ework
->type
) - 4 - 1;
7355 os_strlcpy(ework
->type
, "ext:", sizeof(ework
->type
));
7356 os_memcpy(ework
->type
+ 4, cmd
, type_len
);
7357 ework
->type
[4 + type_len
] = '\0';
7359 wpa_s
->ext_work_id
++;
7360 if (wpa_s
->ext_work_id
== 0)
7361 wpa_s
->ext_work_id
++;
7362 ework
->id
= wpa_s
->ext_work_id
;
7364 if (radio_add_work(wpa_s
, freq
, ework
->type
, 0, wpas_ctrl_radio_work_cb
,
7370 ret
= os_snprintf(buf
, buflen
, "%u", ework
->id
);
7371 if (os_snprintf_error(buflen
, ret
))
7377 static int wpas_ctrl_radio_work_done(struct wpa_supplicant
*wpa_s
, char *cmd
)
7379 struct wpa_radio_work
*work
;
7380 unsigned int id
= atoi(cmd
);
7382 dl_list_for_each(work
, &wpa_s
->radio
->work
, struct wpa_radio_work
, list
)
7384 struct wpa_external_work
*ework
;
7386 if (os_strncmp(work
->type
, "ext:", 4) != 0)
7389 if (id
&& ework
->id
!= id
)
7391 wpa_dbg(wpa_s
, MSG_DEBUG
,
7392 "Completed external radio work %u (%s)",
7393 ework
->id
, ework
->type
);
7394 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
, work
, NULL
);
7395 wpa_s
->ext_work_in_progress
= 0;
7396 radio_work_done(work
);
7398 return 3; /* "OK\n" */
7405 static int wpas_ctrl_radio_work(struct wpa_supplicant
*wpa_s
, char *cmd
,
7406 char *buf
, size_t buflen
)
7408 if (os_strcmp(cmd
, "show") == 0)
7409 return wpas_ctrl_radio_work_show(wpa_s
, buf
, buflen
);
7410 if (os_strncmp(cmd
, "add ", 4) == 0)
7411 return wpas_ctrl_radio_work_add(wpa_s
, cmd
+ 4, buf
, buflen
);
7412 if (os_strncmp(cmd
, "done ", 5) == 0)
7413 return wpas_ctrl_radio_work_done(wpa_s
, cmd
+ 4);
7418 void wpas_ctrl_radio_work_flush(struct wpa_supplicant
*wpa_s
)
7420 struct wpa_radio_work
*work
, *tmp
;
7422 if (!wpa_s
|| !wpa_s
->radio
)
7425 dl_list_for_each_safe(work
, tmp
, &wpa_s
->radio
->work
,
7426 struct wpa_radio_work
, list
) {
7427 struct wpa_external_work
*ework
;
7429 if (os_strncmp(work
->type
, "ext:", 4) != 0)
7432 wpa_dbg(wpa_s
, MSG_DEBUG
,
7433 "Flushing%s external radio work %u (%s)",
7434 work
->started
? " started" : "", ework
->id
,
7437 eloop_cancel_timeout(wpas_ctrl_radio_work_timeout
,
7439 radio_work_done(work
);
7445 static void wpas_ctrl_eapol_response(void *eloop_ctx
, void *timeout_ctx
)
7447 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
7448 eapol_sm_notify_ctrl_response(wpa_s
->eapol
);
7452 static int scan_id_list_parse(struct wpa_supplicant
*wpa_s
, const char *value
,
7453 unsigned int *scan_id_count
, int scan_id
[])
7455 const char *pos
= value
;
7458 if (*pos
== ' ' || *pos
== '\0')
7460 if (*scan_id_count
== MAX_SCAN_ID
)
7462 scan_id
[(*scan_id_count
)++] = atoi(pos
);
7463 pos
= os_strchr(pos
, ',');
7472 static void wpas_ctrl_scan(struct wpa_supplicant
*wpa_s
, char *params
,
7473 char *reply
, int reply_size
, int *reply_len
)
7476 unsigned int manual_scan_passive
= 0;
7477 unsigned int manual_scan_use_id
= 0;
7478 unsigned int manual_scan_only_new
= 0;
7479 unsigned int scan_only
= 0;
7480 unsigned int scan_id_count
= 0;
7481 int scan_id
[MAX_SCAN_ID
];
7482 void (*scan_res_handler
)(struct wpa_supplicant
*wpa_s
,
7483 struct wpa_scan_results
*scan_res
);
7484 int *manual_scan_freqs
= NULL
;
7485 struct wpa_ssid_value
*ssid
= NULL
, *ns
;
7486 unsigned int ssid_count
= 0;
7488 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
) {
7493 if (radio_work_pending(wpa_s
, "scan")) {
7494 wpa_printf(MSG_DEBUG
,
7495 "Pending scan scheduled - reject new request");
7496 *reply_len
= os_snprintf(reply
, reply_size
, "FAIL-BUSY\n");
7500 #ifdef CONFIG_INTERWORKING
7501 if (wpa_s
->fetch_anqp_in_progress
|| wpa_s
->network_select
) {
7502 wpa_printf(MSG_DEBUG
,
7503 "Interworking select in progress - reject new scan");
7504 *reply_len
= os_snprintf(reply
, reply_size
, "FAIL-BUSY\n");
7507 #endif /* CONFIG_INTERWORKING */
7510 if (os_strncasecmp(params
, "TYPE=ONLY", 9) == 0)
7513 pos
= os_strstr(params
, "freq=");
7515 manual_scan_freqs
= freq_range_to_channel_list(wpa_s
,
7517 if (manual_scan_freqs
== NULL
) {
7523 pos
= os_strstr(params
, "passive=");
7525 manual_scan_passive
= !!atoi(pos
+ 8);
7527 pos
= os_strstr(params
, "use_id=");
7529 manual_scan_use_id
= atoi(pos
+ 7);
7531 pos
= os_strstr(params
, "only_new=1");
7533 manual_scan_only_new
= 1;
7535 pos
= os_strstr(params
, "scan_id=");
7536 if (pos
&& scan_id_list_parse(wpa_s
, pos
+ 8, &scan_id_count
,
7543 while (pos
&& *pos
!= '\0') {
7544 if (os_strncmp(pos
, "ssid ", 5) == 0) {
7550 if (*end
== '\0' || *end
== ' ')
7555 ns
= os_realloc_array(
7556 ssid
, ssid_count
+ 1,
7557 sizeof(struct wpa_ssid_value
));
7564 if ((end
- pos
) & 0x01 ||
7565 end
- pos
> 2 * SSID_MAX_LEN
||
7566 hexstr2bin(pos
, ssid
[ssid_count
].ssid
,
7567 (end
- pos
) / 2) < 0) {
7568 wpa_printf(MSG_DEBUG
,
7569 "Invalid SSID value '%s'",
7574 ssid
[ssid_count
].ssid_len
= (end
- pos
) / 2;
7575 wpa_hexdump_ascii(MSG_DEBUG
, "scan SSID",
7576 ssid
[ssid_count
].ssid
,
7577 ssid
[ssid_count
].ssid_len
);
7582 pos
= os_strchr(pos
, ' ');
7588 wpa_s
->num_ssids_from_scan_req
= ssid_count
;
7589 os_free(wpa_s
->ssids_from_scan_req
);
7591 wpa_s
->ssids_from_scan_req
= ssid
;
7594 wpa_s
->ssids_from_scan_req
= NULL
;
7598 scan_res_handler
= scan_only_handler
;
7599 else if (wpa_s
->scan_res_handler
== scan_only_handler
)
7600 scan_res_handler
= NULL
;
7602 scan_res_handler
= wpa_s
->scan_res_handler
;
7604 if (!wpa_s
->sched_scanning
&& !wpa_s
->scanning
&&
7605 ((wpa_s
->wpa_state
<= WPA_SCANNING
) ||
7606 (wpa_s
->wpa_state
== WPA_COMPLETED
))) {
7607 wpa_s
->manual_scan_passive
= manual_scan_passive
;
7608 wpa_s
->manual_scan_use_id
= manual_scan_use_id
;
7609 wpa_s
->manual_scan_only_new
= manual_scan_only_new
;
7610 wpa_s
->scan_id_count
= scan_id_count
;
7611 os_memcpy(wpa_s
->scan_id
, scan_id
, scan_id_count
* sizeof(int));
7612 wpa_s
->scan_res_handler
= scan_res_handler
;
7613 os_free(wpa_s
->manual_scan_freqs
);
7614 wpa_s
->manual_scan_freqs
= manual_scan_freqs
;
7615 manual_scan_freqs
= NULL
;
7617 wpa_s
->normal_scans
= 0;
7618 wpa_s
->scan_req
= MANUAL_SCAN_REQ
;
7619 wpa_s
->after_wps
= 0;
7620 wpa_s
->known_wps_freq
= 0;
7621 wpa_supplicant_req_scan(wpa_s
, 0, 0);
7622 if (wpa_s
->manual_scan_use_id
) {
7623 wpa_s
->manual_scan_id
++;
7624 wpa_dbg(wpa_s
, MSG_DEBUG
, "Assigned scan id %u",
7625 wpa_s
->manual_scan_id
);
7626 *reply_len
= os_snprintf(reply
, reply_size
, "%u\n",
7627 wpa_s
->manual_scan_id
);
7629 } else if (wpa_s
->sched_scanning
) {
7630 wpa_s
->manual_scan_passive
= manual_scan_passive
;
7631 wpa_s
->manual_scan_use_id
= manual_scan_use_id
;
7632 wpa_s
->manual_scan_only_new
= manual_scan_only_new
;
7633 wpa_s
->scan_id_count
= scan_id_count
;
7634 os_memcpy(wpa_s
->scan_id
, scan_id
, scan_id_count
* sizeof(int));
7635 wpa_s
->scan_res_handler
= scan_res_handler
;
7636 os_free(wpa_s
->manual_scan_freqs
);
7637 wpa_s
->manual_scan_freqs
= manual_scan_freqs
;
7638 manual_scan_freqs
= NULL
;
7640 wpa_printf(MSG_DEBUG
, "Stop ongoing sched_scan to allow requested full scan to proceed");
7641 wpa_supplicant_cancel_sched_scan(wpa_s
);
7642 wpa_s
->scan_req
= MANUAL_SCAN_REQ
;
7643 wpa_supplicant_req_scan(wpa_s
, 0, 0);
7644 if (wpa_s
->manual_scan_use_id
) {
7645 wpa_s
->manual_scan_id
++;
7646 *reply_len
= os_snprintf(reply
, reply_size
, "%u\n",
7647 wpa_s
->manual_scan_id
);
7648 wpa_dbg(wpa_s
, MSG_DEBUG
, "Assigned scan id %u",
7649 wpa_s
->manual_scan_id
);
7652 wpa_printf(MSG_DEBUG
, "Ongoing scan action - reject new request");
7653 *reply_len
= os_snprintf(reply
, reply_size
, "FAIL-BUSY\n");
7657 os_free(manual_scan_freqs
);
7662 #ifdef CONFIG_TESTING_OPTIONS
7664 static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant
*wpa_s
,
7665 unsigned int freq
, const u8
*dst
,
7666 const u8
*src
, const u8
*bssid
,
7667 const u8
*data
, size_t data_len
,
7668 enum offchannel_send_action_result
7671 wpa_msg(wpa_s
, MSG_INFO
, "MGMT-TX-STATUS freq=%u dst=" MACSTR
7672 " src=" MACSTR
" bssid=" MACSTR
" result=%s",
7673 freq
, MAC2STR(dst
), MAC2STR(src
), MAC2STR(bssid
),
7674 result
== OFFCHANNEL_SEND_ACTION_SUCCESS
?
7675 "SUCCESS" : (result
== OFFCHANNEL_SEND_ACTION_NO_ACK
?
7676 "NO_ACK" : "FAILED"));
7680 static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant
*wpa_s
, char *cmd
)
7684 u8
*buf
, da
[ETH_ALEN
], bssid
[ETH_ALEN
];
7686 int freq
= 0, no_cck
= 0, wait_time
= 0;
7688 /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1]
7689 * <action=Action frame payload> */
7691 wpa_printf(MSG_DEBUG
, "External MGMT TX: %s", cmd
);
7694 used
= hwaddr_aton2(pos
, da
);
7700 used
= hwaddr_aton2(pos
, bssid
);
7705 param
= os_strstr(pos
, " freq=");
7711 param
= os_strstr(pos
, " no_cck=");
7714 no_cck
= atoi(param
);
7717 param
= os_strstr(pos
, " wait_time=");
7720 wait_time
= atoi(param
);
7723 param
= os_strstr(pos
, " action=");
7728 len
= os_strlen(param
);
7733 buf
= os_malloc(len
);
7737 if (hexstr2bin(param
, buf
, len
) < 0) {
7742 res
= offchannel_send_action(wpa_s
, freq
, da
, wpa_s
->own_addr
, bssid
,
7743 buf
, len
, wait_time
,
7744 wpas_ctrl_iface_mgmt_tx_cb
, no_cck
);
7750 static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant
*wpa_s
)
7752 wpa_printf(MSG_DEBUG
, "External MGMT TX - done waiting");
7753 offchannel_send_action_done(wpa_s
);
7757 static int wpas_ctrl_iface_mgmt_rx_process(struct wpa_supplicant
*wpa_s
,
7763 int freq
= 0, datarate
= 0, ssi_signal
= 0;
7764 union wpa_event_data event
;
7766 if (!wpa_s
->ext_mgmt_frame_handling
)
7769 /* freq=<MHz> datarate=<val> ssi_signal=<val> frame=<frame hexdump> */
7771 wpa_printf(MSG_DEBUG
, "External MGMT RX process: %s", cmd
);
7774 param
= os_strstr(pos
, "freq=");
7780 param
= os_strstr(pos
, " datarate=");
7783 datarate
= atoi(param
);
7786 param
= os_strstr(pos
, " ssi_signal=");
7789 ssi_signal
= atoi(param
);
7792 param
= os_strstr(pos
, " frame=");
7797 len
= os_strlen(param
);
7802 buf
= os_malloc(len
);
7806 if (hexstr2bin(param
, buf
, len
) < 0) {
7811 os_memset(&event
, 0, sizeof(event
));
7812 event
.rx_mgmt
.freq
= freq
;
7813 event
.rx_mgmt
.frame
= buf
;
7814 event
.rx_mgmt
.frame_len
= len
;
7815 event
.rx_mgmt
.ssi_signal
= ssi_signal
;
7816 event
.rx_mgmt
.datarate
= datarate
;
7817 wpa_s
->ext_mgmt_frame_handling
= 0;
7818 wpa_supplicant_event(wpa_s
, EVENT_RX_MGMT
, &event
);
7819 wpa_s
->ext_mgmt_frame_handling
= 1;
7827 static int wpas_ctrl_iface_driver_event(struct wpa_supplicant
*wpa_s
, char *cmd
)
7830 union wpa_event_data event
;
7831 enum wpa_event_type ev
;
7833 /* <event name> [parameters..] */
7835 wpa_dbg(wpa_s
, MSG_DEBUG
, "Testing - external driver event: %s", cmd
);
7838 param
= os_strchr(pos
, ' ');
7842 os_memset(&event
, 0, sizeof(event
));
7844 if (os_strcmp(cmd
, "INTERFACE_ENABLED") == 0) {
7845 ev
= EVENT_INTERFACE_ENABLED
;
7846 } else if (os_strcmp(cmd
, "INTERFACE_DISABLED") == 0) {
7847 ev
= EVENT_INTERFACE_DISABLED
;
7848 } else if (os_strcmp(cmd
, "AVOID_FREQUENCIES") == 0) {
7849 ev
= EVENT_AVOID_FREQUENCIES
;
7852 if (freq_range_list_parse(&event
.freq_range
, param
) < 0)
7854 wpa_supplicant_event(wpa_s
, ev
, &event
);
7855 os_free(event
.freq_range
.range
);
7858 wpa_dbg(wpa_s
, MSG_DEBUG
, "Testing - unknown driver event: %s",
7863 wpa_supplicant_event(wpa_s
, ev
, &event
);
7869 static int wpas_ctrl_iface_eapol_rx(struct wpa_supplicant
*wpa_s
, char *cmd
)
7872 u8 src
[ETH_ALEN
], *buf
;
7876 wpa_printf(MSG_DEBUG
, "External EAPOL RX: %s", cmd
);
7879 used
= hwaddr_aton2(pos
, src
);
7886 len
= os_strlen(pos
);
7891 buf
= os_malloc(len
);
7895 if (hexstr2bin(pos
, buf
, len
) < 0) {
7900 wpa_supplicant_rx_eapol(wpa_s
, src
, buf
, len
);
7907 static u16
ipv4_hdr_checksum(const void *buf
, size_t len
)
7911 const u16
*pos
= buf
;
7913 for (i
= 0; i
< len
/ 2; i
++)
7917 sum
= (sum
& 0xffff) + (sum
>> 16);
7919 return sum
^ 0xffff;
7923 #define HWSIM_PACKETLEN 1500
7924 #define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header))
7926 static void wpas_data_test_rx(void *ctx
, const u8
*src_addr
, const u8
*buf
,
7929 struct wpa_supplicant
*wpa_s
= ctx
;
7930 const struct ether_header
*eth
;
7935 if (len
!= HWSIM_PACKETLEN
)
7938 eth
= (const struct ether_header
*) buf
;
7939 os_memcpy(&ip
, eth
+ 1, sizeof(ip
));
7940 pos
= &buf
[sizeof(*eth
) + sizeof(ip
)];
7942 if (ip
.ihl
!= 5 || ip
.version
!= 4 ||
7943 ntohs(ip
.tot_len
) != HWSIM_IP_LEN
)
7946 for (i
= 0; i
< HWSIM_IP_LEN
- sizeof(ip
); i
++) {
7952 wpa_msg(wpa_s
, MSG_INFO
, "DATA-TEST-RX " MACSTR
" " MACSTR
,
7953 MAC2STR(eth
->ether_dhost
), MAC2STR(eth
->ether_shost
));
7957 static int wpas_ctrl_iface_data_test_config(struct wpa_supplicant
*wpa_s
,
7960 int enabled
= atoi(cmd
);
7965 if (wpa_s
->l2_test
) {
7966 l2_packet_deinit(wpa_s
->l2_test
);
7967 wpa_s
->l2_test
= NULL
;
7968 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: Disabled");
7976 pos
= os_strstr(cmd
, " ifname=");
7980 ifname
= wpa_s
->ifname
;
7982 wpa_s
->l2_test
= l2_packet_init(ifname
, wpa_s
->own_addr
,
7983 ETHERTYPE_IP
, wpas_data_test_rx
,
7985 if (wpa_s
->l2_test
== NULL
)
7988 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: Enabled");
7994 static int wpas_ctrl_iface_data_test_tx(struct wpa_supplicant
*wpa_s
, char *cmd
)
7996 u8 dst
[ETH_ALEN
], src
[ETH_ALEN
];
8001 u8 buf
[2 + HWSIM_PACKETLEN
];
8002 struct ether_header
*eth
;
8007 if (wpa_s
->l2_test
== NULL
)
8010 /* format: <dst> <src> <tos> */
8013 used
= hwaddr_aton2(pos
, dst
);
8019 used
= hwaddr_aton2(pos
, src
);
8024 val
= strtol(pos
, NULL
, 0);
8025 if (val
< 0 || val
> 0xff)
8029 eth
= (struct ether_header
*) &buf
[2];
8030 os_memcpy(eth
->ether_dhost
, dst
, ETH_ALEN
);
8031 os_memcpy(eth
->ether_shost
, src
, ETH_ALEN
);
8032 eth
->ether_type
= htons(ETHERTYPE_IP
);
8033 ip
= (struct iphdr
*) (eth
+ 1);
8034 os_memset(ip
, 0, sizeof(*ip
));
8039 ip
->tot_len
= htons(HWSIM_IP_LEN
);
8041 ip
->saddr
= htonl(192U << 24 | 168 << 16 | 1 << 8 | 1);
8042 ip
->daddr
= htonl(192U << 24 | 168 << 16 | 1 << 8 | 2);
8043 ip
->check
= ipv4_hdr_checksum(ip
, sizeof(*ip
));
8044 dpos
= (u8
*) (ip
+ 1);
8045 for (i
= 0; i
< HWSIM_IP_LEN
- sizeof(*ip
); i
++)
8048 if (l2_packet_send(wpa_s
->l2_test
, dst
, ETHERTYPE_IP
, &buf
[2],
8049 HWSIM_PACKETLEN
) < 0)
8052 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: TX dst=" MACSTR
" src=" MACSTR
8053 " tos=0x%x", MAC2STR(dst
), MAC2STR(src
), tos
);
8059 static int wpas_ctrl_iface_data_test_frame(struct wpa_supplicant
*wpa_s
,
8063 struct ether_header
*eth
;
8064 struct l2_packet_data
*l2
= NULL
;
8069 len
= os_strlen(cmd
);
8070 if (len
& 1 || len
< ETH_HLEN
* 2)
8074 buf
= os_malloc(len
);
8078 if (hexstr2bin(cmd
, buf
, len
) < 0)
8081 eth
= (struct ether_header
*) buf
;
8082 ethertype
= ntohs(eth
->ether_type
);
8084 l2
= l2_packet_init(wpa_s
->ifname
, wpa_s
->own_addr
, ethertype
,
8085 wpas_data_test_rx
, wpa_s
, 1);
8089 res
= l2_packet_send(l2
, eth
->ether_dhost
, ethertype
, buf
, len
);
8090 wpa_dbg(wpa_s
, MSG_DEBUG
, "test data: TX frame res=%d", res
);
8093 l2_packet_deinit(l2
);
8096 return res
< 0 ? -1 : 0;
8100 static int wpas_ctrl_test_alloc_fail(struct wpa_supplicant
*wpa_s
, char *cmd
)
8102 #ifdef WPA_TRACE_BFD
8105 wpa_trace_fail_after
= atoi(cmd
);
8106 pos
= os_strchr(cmd
, ':');
8109 os_strlcpy(wpa_trace_fail_func
, pos
,
8110 sizeof(wpa_trace_fail_func
));
8112 wpa_trace_fail_after
= 0;
8115 #else /* WPA_TRACE_BFD */
8117 #endif /* WPA_TRACE_BFD */
8121 static int wpas_ctrl_get_alloc_fail(struct wpa_supplicant
*wpa_s
,
8122 char *buf
, size_t buflen
)
8124 #ifdef WPA_TRACE_BFD
8125 return os_snprintf(buf
, buflen
, "%u:%s", wpa_trace_fail_after
,
8126 wpa_trace_fail_func
);
8127 #else /* WPA_TRACE_BFD */
8129 #endif /* WPA_TRACE_BFD */
8133 static int wpas_ctrl_test_fail(struct wpa_supplicant
*wpa_s
, char *cmd
)
8135 #ifdef WPA_TRACE_BFD
8138 wpa_trace_test_fail_after
= atoi(cmd
);
8139 pos
= os_strchr(cmd
, ':');
8142 os_strlcpy(wpa_trace_test_fail_func
, pos
,
8143 sizeof(wpa_trace_test_fail_func
));
8145 wpa_trace_test_fail_after
= 0;
8148 #else /* WPA_TRACE_BFD */
8150 #endif /* WPA_TRACE_BFD */
8154 static int wpas_ctrl_get_fail(struct wpa_supplicant
*wpa_s
,
8155 char *buf
, size_t buflen
)
8157 #ifdef WPA_TRACE_BFD
8158 return os_snprintf(buf
, buflen
, "%u:%s", wpa_trace_test_fail_after
,
8159 wpa_trace_test_fail_func
);
8160 #else /* WPA_TRACE_BFD */
8162 #endif /* WPA_TRACE_BFD */
8166 static void wpas_ctrl_event_test_cb(void *eloop_ctx
, void *timeout_ctx
)
8168 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
8169 int i
, count
= (intptr_t) timeout_ctx
;
8171 wpa_printf(MSG_DEBUG
, "TEST: Send %d control interface event messages",
8173 for (i
= 0; i
< count
; i
++) {
8174 wpa_msg_ctrl(wpa_s
, MSG_INFO
, "TEST-EVENT-MESSAGE %d/%d",
8180 static int wpas_ctrl_event_test(struct wpa_supplicant
*wpa_s
, const char *cmd
)
8188 return eloop_register_timeout(0, 0, wpas_ctrl_event_test_cb
, wpa_s
,
8189 (void *) (intptr_t) count
);
8193 static int wpas_ctrl_test_assoc_ie(struct wpa_supplicant
*wpa_s
,
8199 len
= os_strlen(cmd
);
8207 buf
= wpabuf_alloc(len
);
8211 if (hexstr2bin(cmd
, wpabuf_put(buf
, len
), len
) < 0) {
8217 wpa_sm_set_test_assoc_ie(wpa_s
->wpa
, buf
);
8221 #endif /* CONFIG_TESTING_OPTIONS */
8224 static int wpas_ctrl_vendor_elem_add(struct wpa_supplicant
*wpa_s
, char *cmd
)
8230 struct ieee802_11_elems elems
;
8233 if (frame
< 0 || frame
>= NUM_VENDOR_ELEM_FRAMES
)
8235 wpa_s
= wpas_vendor_elem(wpa_s
, frame
);
8237 pos
= os_strchr(pos
, ' ');
8242 len
= os_strlen(pos
);
8249 buf
= wpabuf_alloc(len
);
8253 if (hexstr2bin(pos
, wpabuf_put(buf
, len
), len
) < 0) {
8258 if (ieee802_11_parse_elems(wpabuf_head_u8(buf
), len
, &elems
, 0) ==
8264 if (wpa_s
->vendor_elem
[frame
] == NULL
) {
8265 wpa_s
->vendor_elem
[frame
] = buf
;
8266 wpas_vendor_elem_update(wpa_s
);
8270 if (wpabuf_resize(&wpa_s
->vendor_elem
[frame
], len
) < 0) {
8275 wpabuf_put_buf(wpa_s
->vendor_elem
[frame
], buf
);
8277 wpas_vendor_elem_update(wpa_s
);
8283 static int wpas_ctrl_vendor_elem_get(struct wpa_supplicant
*wpa_s
, char *cmd
,
8284 char *buf
, size_t buflen
)
8286 int frame
= atoi(cmd
);
8288 if (frame
< 0 || frame
>= NUM_VENDOR_ELEM_FRAMES
)
8290 wpa_s
= wpas_vendor_elem(wpa_s
, frame
);
8292 if (wpa_s
->vendor_elem
[frame
] == NULL
)
8295 return wpa_snprintf_hex(buf
, buflen
,
8296 wpabuf_head_u8(wpa_s
->vendor_elem
[frame
]),
8297 wpabuf_len(wpa_s
->vendor_elem
[frame
]));
8301 static int wpas_ctrl_vendor_elem_remove(struct wpa_supplicant
*wpa_s
, char *cmd
)
8307 struct ieee802_11_elems elems
;
8311 if (frame
< 0 || frame
>= NUM_VENDOR_ELEM_FRAMES
)
8313 wpa_s
= wpas_vendor_elem(wpa_s
, frame
);
8315 pos
= os_strchr(pos
, ' ');
8321 wpabuf_free(wpa_s
->vendor_elem
[frame
]);
8322 wpa_s
->vendor_elem
[frame
] = NULL
;
8323 wpas_vendor_elem_update(wpa_s
);
8327 if (wpa_s
->vendor_elem
[frame
] == NULL
)
8330 len
= os_strlen(pos
);
8337 buf
= os_malloc(len
);
8341 if (hexstr2bin(pos
, buf
, len
) < 0) {
8346 if (ieee802_11_parse_elems(buf
, len
, &elems
, 0) == ParseFailed
) {
8351 res
= wpas_vendor_elem_remove(wpa_s
, frame
, buf
, len
);
8357 static void wpas_ctrl_neighbor_rep_cb(void *ctx
, struct wpabuf
*neighbor_rep
)
8359 struct wpa_supplicant
*wpa_s
= ctx
;
8364 * Neighbor Report element (IEEE P802.11-REVmc/D5.0)
8366 * BSSID Information[4]
8367 * Operating Class[1]
8370 * Optional Subelements[variable]
8372 #define NR_IE_MIN_LEN (ETH_ALEN + 4 + 1 + 1 + 1)
8374 if (!neighbor_rep
|| wpabuf_len(neighbor_rep
) == 0) {
8375 wpa_msg_ctrl(wpa_s
, MSG_INFO
, RRM_EVENT_NEIGHBOR_REP_FAILED
);
8379 data
= wpabuf_head_u8(neighbor_rep
);
8380 len
= wpabuf_len(neighbor_rep
);
8382 while (len
>= 2 + NR_IE_MIN_LEN
) {
8384 char lci
[256 * 2 + 1];
8385 char civic
[256 * 2 + 1];
8386 u8 nr_len
= data
[1];
8387 const u8
*pos
= data
, *end
;
8389 if (pos
[0] != WLAN_EID_NEIGHBOR_REPORT
||
8390 nr_len
< NR_IE_MIN_LEN
) {
8391 wpa_printf(MSG_DEBUG
,
8392 "CTRL: Invalid Neighbor Report element: id=%u len=%u",
8397 if (2U + nr_len
> len
) {
8398 wpa_printf(MSG_DEBUG
,
8399 "CTRL: Invalid Neighbor Report element: id=%u len=%zu nr_len=%u",
8400 data
[0], len
, nr_len
);
8407 pos
+= NR_IE_MIN_LEN
;
8411 while (end
- pos
> 2) {
8416 if (s_len
> end
- pos
)
8418 if (s_id
== WLAN_EID_MEASURE_REPORT
&& s_len
> 3) {
8419 /* Measurement Token[1] */
8420 /* Measurement Report Mode[1] */
8421 /* Measurement Type[1] */
8422 /* Measurement Report[variable] */
8424 case MEASURE_TYPE_LCI
:
8427 wpa_snprintf_hex(lci
, sizeof(lci
),
8430 case MEASURE_TYPE_LOCATION_CIVIC
:
8433 wpa_snprintf_hex(civic
, sizeof(civic
),
8442 wpa_msg(wpa_s
, MSG_INFO
, RRM_EVENT_NEIGHBOR_REP_RXED
8444 " info=0x%x op_class=%u chan=%u phy_type=%u%s%s%s%s",
8445 MAC2STR(nr
), WPA_GET_LE32(nr
+ ETH_ALEN
),
8446 nr
[ETH_ALEN
+ 4], nr
[ETH_ALEN
+ 5],
8448 lci
[0] ? " lci=" : "", lci
,
8449 civic
[0] ? " civic=" : "", civic
);
8456 wpabuf_free(neighbor_rep
);
8460 static int wpas_ctrl_iface_send_neighbor_rep(struct wpa_supplicant
*wpa_s
,
8463 struct wpa_ssid_value ssid
, *ssid_p
= NULL
;
8464 int ret
, lci
= 0, civic
= 0;
8467 ssid_s
= os_strstr(cmd
, "ssid=");
8469 if (ssid_parse(ssid_s
+ 5, &ssid
)) {
8470 wpa_printf(MSG_ERROR
,
8471 "CTRL: Send Neighbor Report: bad SSID");
8478 * Move cmd after the SSID text that may include "lci" or
8481 cmd
= os_strchr(ssid_s
+ 6, ssid_s
[5] == '"' ? '"' : ' ');
8487 if (cmd
&& os_strstr(cmd
, "lci"))
8490 if (cmd
&& os_strstr(cmd
, "civic"))
8493 ret
= wpas_rrm_send_neighbor_rep_request(wpa_s
, ssid_p
, lci
, civic
,
8494 wpas_ctrl_neighbor_rep_cb
,
8501 static int wpas_ctrl_iface_erp_flush(struct wpa_supplicant
*wpa_s
)
8503 eapol_sm_erp_flush(wpa_s
->eapol
);
8508 static int wpas_ctrl_iface_mac_rand_scan(struct wpa_supplicant
*wpa_s
,
8511 char *token
, *context
= NULL
;
8512 unsigned int enable
= ~0, type
= 0;
8513 u8 _addr
[ETH_ALEN
], _mask
[ETH_ALEN
];
8514 u8
*addr
= NULL
, *mask
= NULL
;
8516 while ((token
= str_token(cmd
, " ", &context
))) {
8517 if (os_strcasecmp(token
, "scan") == 0) {
8518 type
|= MAC_ADDR_RAND_SCAN
;
8519 } else if (os_strcasecmp(token
, "sched") == 0) {
8520 type
|= MAC_ADDR_RAND_SCHED_SCAN
;
8521 } else if (os_strcasecmp(token
, "pno") == 0) {
8522 type
|= MAC_ADDR_RAND_PNO
;
8523 } else if (os_strcasecmp(token
, "all") == 0) {
8524 type
= wpa_s
->mac_addr_rand_supported
;
8525 } else if (os_strncasecmp(token
, "enable=", 7) == 0) {
8526 enable
= atoi(token
+ 7);
8527 } else if (os_strncasecmp(token
, "addr=", 5) == 0) {
8529 if (hwaddr_aton(token
+ 5, addr
)) {
8530 wpa_printf(MSG_INFO
,
8531 "CTRL: Invalid MAC address: %s",
8535 } else if (os_strncasecmp(token
, "mask=", 5) == 0) {
8537 if (hwaddr_aton(token
+ 5, mask
)) {
8538 wpa_printf(MSG_INFO
,
8539 "CTRL: Invalid MAC address mask: %s",
8544 wpa_printf(MSG_INFO
,
8545 "CTRL: Invalid MAC_RAND_SCAN parameter: %s",
8552 wpa_printf(MSG_INFO
, "CTRL: MAC_RAND_SCAN no type specified");
8556 if ((wpa_s
->mac_addr_rand_supported
& type
) != type
) {
8557 wpa_printf(MSG_INFO
,
8558 "CTRL: MAC_RAND_SCAN types=%u != supported=%u",
8559 type
, wpa_s
->mac_addr_rand_supported
);
8564 wpa_printf(MSG_INFO
,
8565 "CTRL: MAC_RAND_SCAN enable=<0/1> not specified");
8570 wpas_mac_addr_rand_scan_clear(wpa_s
, type
);
8572 if (type
& MAC_ADDR_RAND_PNO
) {
8573 wpas_stop_pno(wpa_s
);
8574 wpas_start_pno(wpa_s
);
8576 } else if (wpa_s
->sched_scanning
&&
8577 (type
& MAC_ADDR_RAND_SCHED_SCAN
)) {
8578 wpas_scan_restart_sched_scan(wpa_s
);
8583 if ((addr
&& !mask
) || (!addr
&& mask
)) {
8584 wpa_printf(MSG_INFO
,
8585 "CTRL: MAC_RAND_SCAN invalid addr/mask combination");
8589 if (addr
&& mask
&& (!(mask
[0] & 0x01) || (addr
[0] & 0x01))) {
8590 wpa_printf(MSG_INFO
,
8591 "CTRL: MAC_RAND_SCAN cannot allow multicast address");
8595 if (type
& MAC_ADDR_RAND_SCAN
) {
8596 wpas_mac_addr_rand_scan_set(wpa_s
, MAC_ADDR_RAND_SCAN
,
8600 if (type
& MAC_ADDR_RAND_SCHED_SCAN
) {
8601 wpas_mac_addr_rand_scan_set(wpa_s
, MAC_ADDR_RAND_SCHED_SCAN
,
8604 if (wpa_s
->sched_scanning
&& !wpa_s
->pno
)
8605 wpas_scan_restart_sched_scan(wpa_s
);
8608 if (type
& MAC_ADDR_RAND_PNO
) {
8609 wpas_mac_addr_rand_scan_set(wpa_s
, MAC_ADDR_RAND_PNO
,
8612 wpas_stop_pno(wpa_s
);
8613 wpas_start_pno(wpa_s
);
8621 static int wpas_ctrl_iface_pmksa(struct wpa_supplicant
*wpa_s
,
8622 char *buf
, size_t buflen
)
8626 reply_len
= wpa_sm_pmksa_cache_list(wpa_s
->wpa
, buf
, buflen
);
8628 reply_len
+= wpas_ap_pmksa_cache_list(wpa_s
, &buf
[reply_len
],
8629 buflen
- reply_len
);
8630 #endif /* CONFIG_AP */
8635 static void wpas_ctrl_iface_pmksa_flush(struct wpa_supplicant
*wpa_s
)
8637 wpa_sm_pmksa_cache_flush(wpa_s
->wpa
, NULL
);
8639 wpas_ap_pmksa_cache_flush(wpa_s
);
8640 #endif /* CONFIG_AP */
8644 static int wpas_ctrl_cmd_debug_level(const char *cmd
)
8646 if (os_strcmp(cmd
, "PING") == 0 ||
8647 os_strncmp(cmd
, "BSS ", 4) == 0 ||
8648 os_strncmp(cmd
, "GET_NETWORK ", 12) == 0 ||
8649 os_strncmp(cmd
, "STATUS", 6) == 0 ||
8650 os_strncmp(cmd
, "STA ", 4) == 0 ||
8651 os_strncmp(cmd
, "STA-", 4) == 0)
8652 return MSG_EXCESSIVE
;
8657 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant
*wpa_s
,
8658 char *buf
, size_t *resp_len
)
8661 const int reply_size
= 4096;
8664 if (os_strncmp(buf
, WPA_CTRL_RSP
, os_strlen(WPA_CTRL_RSP
)) == 0 ||
8665 os_strncmp(buf
, "SET_NETWORK ", 12) == 0) {
8666 if (wpa_debug_show_keys
)
8667 wpa_dbg(wpa_s
, MSG_DEBUG
,
8668 "Control interface command '%s'", buf
);
8670 wpa_dbg(wpa_s
, MSG_DEBUG
,
8671 "Control interface command '%s [REMOVED]'",
8672 os_strncmp(buf
, WPA_CTRL_RSP
,
8673 os_strlen(WPA_CTRL_RSP
)) == 0 ?
8674 WPA_CTRL_RSP
: "SET_NETWORK");
8675 } else if (os_strncmp(buf
, "WPS_NFC_TAG_READ", 16) == 0 ||
8676 os_strncmp(buf
, "NFC_REPORT_HANDOVER", 19) == 0) {
8677 wpa_hexdump_ascii_key(MSG_DEBUG
, "RX ctrl_iface",
8678 (const u8
*) buf
, os_strlen(buf
));
8680 int level
= wpas_ctrl_cmd_debug_level(buf
);
8681 wpa_dbg(wpa_s
, level
, "Control interface command '%s'", buf
);
8684 reply
= os_malloc(reply_size
);
8685 if (reply
== NULL
) {
8690 os_memcpy(reply
, "OK\n", 3);
8693 if (os_strcmp(buf
, "PING") == 0) {
8694 os_memcpy(reply
, "PONG\n", 5);
8696 } else if (os_strcmp(buf
, "IFNAME") == 0) {
8697 reply_len
= os_strlen(wpa_s
->ifname
);
8698 os_memcpy(reply
, wpa_s
->ifname
, reply_len
);
8699 } else if (os_strncmp(buf
, "RELOG", 5) == 0) {
8700 if (wpa_debug_reopen_file() < 0)
8702 } else if (os_strncmp(buf
, "NOTE ", 5) == 0) {
8703 wpa_printf(MSG_INFO
, "NOTE: %s", buf
+ 5);
8704 } else if (os_strcmp(buf
, "MIB") == 0) {
8705 reply_len
= wpa_sm_get_mib(wpa_s
->wpa
, reply
, reply_size
);
8706 if (reply_len
>= 0) {
8707 reply_len
+= eapol_sm_get_mib(wpa_s
->eapol
,
8709 reply_size
- reply_len
);
8711 } else if (os_strncmp(buf
, "STATUS", 6) == 0) {
8712 reply_len
= wpa_supplicant_ctrl_iface_status(
8713 wpa_s
, buf
+ 6, reply
, reply_size
);
8714 } else if (os_strcmp(buf
, "PMKSA") == 0) {
8715 reply_len
= wpas_ctrl_iface_pmksa(wpa_s
, reply
, reply_size
);
8716 } else if (os_strcmp(buf
, "PMKSA_FLUSH") == 0) {
8717 wpas_ctrl_iface_pmksa_flush(wpa_s
);
8718 } else if (os_strncmp(buf
, "SET ", 4) == 0) {
8719 if (wpa_supplicant_ctrl_iface_set(wpa_s
, buf
+ 4))
8721 } else if (os_strncmp(buf
, "DUMP", 4) == 0) {
8722 reply_len
= wpa_config_dump_values(wpa_s
->conf
,
8724 } else if (os_strncmp(buf
, "GET ", 4) == 0) {
8725 reply_len
= wpa_supplicant_ctrl_iface_get(wpa_s
, buf
+ 4,
8727 } else if (os_strcmp(buf
, "LOGON") == 0) {
8728 eapol_sm_notify_logoff(wpa_s
->eapol
, FALSE
);
8729 } else if (os_strcmp(buf
, "LOGOFF") == 0) {
8730 eapol_sm_notify_logoff(wpa_s
->eapol
, TRUE
);
8731 } else if (os_strcmp(buf
, "REASSOCIATE") == 0) {
8732 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
8735 wpas_request_connection(wpa_s
);
8736 } else if (os_strcmp(buf
, "REATTACH") == 0) {
8737 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
||
8738 !wpa_s
->current_ssid
)
8741 wpa_s
->reattach
= 1;
8742 wpas_request_connection(wpa_s
);
8744 } else if (os_strcmp(buf
, "RECONNECT") == 0) {
8745 if (wpa_s
->wpa_state
== WPA_INTERFACE_DISABLED
)
8747 else if (wpa_s
->disconnected
)
8748 wpas_request_connection(wpa_s
);
8749 #ifdef IEEE8021X_EAPOL
8750 } else if (os_strncmp(buf
, "PREAUTH ", 8) == 0) {
8751 if (wpa_supplicant_ctrl_iface_preauth(wpa_s
, buf
+ 8))
8753 #endif /* IEEE8021X_EAPOL */
8754 #ifdef CONFIG_PEERKEY
8755 } else if (os_strncmp(buf
, "STKSTART ", 9) == 0) {
8756 if (wpa_supplicant_ctrl_iface_stkstart(wpa_s
, buf
+ 9))
8758 #endif /* CONFIG_PEERKEY */
8759 #ifdef CONFIG_IEEE80211R
8760 } else if (os_strncmp(buf
, "FT_DS ", 6) == 0) {
8761 if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s
, buf
+ 6))
8763 #endif /* CONFIG_IEEE80211R */
8765 } else if (os_strcmp(buf
, "WPS_PBC") == 0) {
8766 int res
= wpa_supplicant_ctrl_iface_wps_pbc(wpa_s
, NULL
);
8768 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
8772 } else if (os_strncmp(buf
, "WPS_PBC ", 8) == 0) {
8773 int res
= wpa_supplicant_ctrl_iface_wps_pbc(wpa_s
, buf
+ 8);
8775 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
8779 } else if (os_strncmp(buf
, "WPS_PIN ", 8) == 0) {
8780 reply_len
= wpa_supplicant_ctrl_iface_wps_pin(wpa_s
, buf
+ 8,
8783 } else if (os_strncmp(buf
, "WPS_CHECK_PIN ", 14) == 0) {
8784 reply_len
= wpa_supplicant_ctrl_iface_wps_check_pin(
8785 wpa_s
, buf
+ 14, reply
, reply_size
);
8786 } else if (os_strcmp(buf
, "WPS_CANCEL") == 0) {
8787 if (wpas_wps_cancel(wpa_s
))
8789 #ifdef CONFIG_WPS_NFC
8790 } else if (os_strcmp(buf
, "WPS_NFC") == 0) {
8791 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s
, NULL
))
8793 } else if (os_strncmp(buf
, "WPS_NFC ", 8) == 0) {
8794 if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s
, buf
+ 8))
8796 } else if (os_strncmp(buf
, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
8797 reply_len
= wpa_supplicant_ctrl_iface_wps_nfc_config_token(
8798 wpa_s
, buf
+ 21, reply
, reply_size
);
8799 } else if (os_strncmp(buf
, "WPS_NFC_TOKEN ", 14) == 0) {
8800 reply_len
= wpa_supplicant_ctrl_iface_wps_nfc_token(
8801 wpa_s
, buf
+ 14, reply
, reply_size
);
8802 } else if (os_strncmp(buf
, "WPS_NFC_TAG_READ ", 17) == 0) {
8803 if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s
,
8806 } else if (os_strncmp(buf
, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
8807 reply_len
= wpas_ctrl_nfc_get_handover_req(
8808 wpa_s
, buf
+ 21, reply
, reply_size
);
8809 } else if (os_strncmp(buf
, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
8810 reply_len
= wpas_ctrl_nfc_get_handover_sel(
8811 wpa_s
, buf
+ 21, reply
, reply_size
);
8812 } else if (os_strncmp(buf
, "NFC_REPORT_HANDOVER ", 20) == 0) {
8813 if (wpas_ctrl_nfc_report_handover(wpa_s
, buf
+ 20))
8815 #endif /* CONFIG_WPS_NFC */
8816 } else if (os_strncmp(buf
, "WPS_REG ", 8) == 0) {
8817 if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s
, buf
+ 8))
8820 } else if (os_strncmp(buf
, "WPS_AP_PIN ", 11) == 0) {
8821 reply_len
= wpa_supplicant_ctrl_iface_wps_ap_pin(
8822 wpa_s
, buf
+ 11, reply
, reply_size
);
8823 #endif /* CONFIG_AP */
8824 #ifdef CONFIG_WPS_ER
8825 } else if (os_strcmp(buf
, "WPS_ER_START") == 0) {
8826 if (wpas_wps_er_start(wpa_s
, NULL
))
8828 } else if (os_strncmp(buf
, "WPS_ER_START ", 13) == 0) {
8829 if (wpas_wps_er_start(wpa_s
, buf
+ 13))
8831 } else if (os_strcmp(buf
, "WPS_ER_STOP") == 0) {
8832 wpas_wps_er_stop(wpa_s
);
8833 } else if (os_strncmp(buf
, "WPS_ER_PIN ", 11) == 0) {
8834 if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s
, buf
+ 11))
8836 } else if (os_strncmp(buf
, "WPS_ER_PBC ", 11) == 0) {
8837 int ret
= wpas_wps_er_pbc(wpa_s
, buf
+ 11);
8839 os_memcpy(reply
, "FAIL-PBC-OVERLAP\n", 17);
8841 } else if (ret
== -3) {
8842 os_memcpy(reply
, "FAIL-UNKNOWN-UUID\n", 18);
8844 } else if (ret
== -4) {
8845 os_memcpy(reply
, "FAIL-NO-AP-SETTINGS\n", 20);
8849 } else if (os_strncmp(buf
, "WPS_ER_LEARN ", 13) == 0) {
8850 if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s
, buf
+ 13))
8852 } else if (os_strncmp(buf
, "WPS_ER_SET_CONFIG ", 18) == 0) {
8853 if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s
,
8856 } else if (os_strncmp(buf
, "WPS_ER_CONFIG ", 14) == 0) {
8857 if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s
, buf
+ 14))
8859 #ifdef CONFIG_WPS_NFC
8860 } else if (os_strncmp(buf
, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
8861 reply_len
= wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
8862 wpa_s
, buf
+ 24, reply
, reply_size
);
8863 #endif /* CONFIG_WPS_NFC */
8864 #endif /* CONFIG_WPS_ER */
8865 #endif /* CONFIG_WPS */
8866 #ifdef CONFIG_IBSS_RSN
8867 } else if (os_strncmp(buf
, "IBSS_RSN ", 9) == 0) {
8868 if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s
, buf
+ 9))
8870 #endif /* CONFIG_IBSS_RSN */
8872 } else if (os_strncmp(buf
, "MESH_INTERFACE_ADD ", 19) == 0) {
8873 reply_len
= wpa_supplicant_ctrl_iface_mesh_interface_add(
8874 wpa_s
, buf
+ 19, reply
, reply_size
);
8875 } else if (os_strcmp(buf
, "MESH_INTERFACE_ADD") == 0) {
8876 reply_len
= wpa_supplicant_ctrl_iface_mesh_interface_add(
8877 wpa_s
, "", reply
, reply_size
);
8878 } else if (os_strncmp(buf
, "MESH_GROUP_ADD ", 15) == 0) {
8879 if (wpa_supplicant_ctrl_iface_mesh_group_add(wpa_s
, buf
+ 15))
8881 } else if (os_strncmp(buf
, "MESH_GROUP_REMOVE ", 18) == 0) {
8882 if (wpa_supplicant_ctrl_iface_mesh_group_remove(wpa_s
,
8885 } else if (os_strncmp(buf
, "MESH_PEER_REMOVE ", 17) == 0) {
8886 if (wpa_supplicant_ctrl_iface_mesh_peer_remove(wpa_s
, buf
+ 17))
8888 } else if (os_strncmp(buf
, "MESH_PEER_ADD ", 14) == 0) {
8889 if (wpa_supplicant_ctrl_iface_mesh_peer_add(wpa_s
, buf
+ 14))
8891 #endif /* CONFIG_MESH */
8893 } else if (os_strncmp(buf
, "P2P_FIND ", 9) == 0) {
8894 if (p2p_ctrl_find(wpa_s
, buf
+ 8))
8896 } else if (os_strcmp(buf
, "P2P_FIND") == 0) {
8897 if (p2p_ctrl_find(wpa_s
, ""))
8899 } else if (os_strcmp(buf
, "P2P_STOP_FIND") == 0) {
8900 wpas_p2p_stop_find(wpa_s
);
8901 } else if (os_strncmp(buf
, "P2P_ASP_PROVISION ", 18) == 0) {
8902 if (p2p_ctrl_asp_provision(wpa_s
, buf
+ 18))
8904 } else if (os_strncmp(buf
, "P2P_ASP_PROVISION_RESP ", 23) == 0) {
8905 if (p2p_ctrl_asp_provision_resp(wpa_s
, buf
+ 23))
8907 } else if (os_strncmp(buf
, "P2P_CONNECT ", 12) == 0) {
8908 reply_len
= p2p_ctrl_connect(wpa_s
, buf
+ 12, reply
,
8910 } else if (os_strncmp(buf
, "P2P_LISTEN ", 11) == 0) {
8911 if (p2p_ctrl_listen(wpa_s
, buf
+ 11))
8913 } else if (os_strcmp(buf
, "P2P_LISTEN") == 0) {
8914 if (p2p_ctrl_listen(wpa_s
, ""))
8916 } else if (os_strncmp(buf
, "P2P_GROUP_REMOVE ", 17) == 0) {
8917 if (wpas_p2p_group_remove(wpa_s
, buf
+ 17))
8919 } else if (os_strcmp(buf
, "P2P_GROUP_ADD") == 0) {
8920 if (p2p_ctrl_group_add(wpa_s
, ""))
8922 } else if (os_strncmp(buf
, "P2P_GROUP_ADD ", 14) == 0) {
8923 if (p2p_ctrl_group_add(wpa_s
, buf
+ 14))
8925 } else if (os_strncmp(buf
, "P2P_GROUP_MEMBER ", 17) == 0) {
8926 reply_len
= p2p_ctrl_group_member(wpa_s
, buf
+ 17, reply
,
8928 } else if (os_strncmp(buf
, "P2P_PROV_DISC ", 14) == 0) {
8929 if (p2p_ctrl_prov_disc(wpa_s
, buf
+ 14))
8931 } else if (os_strcmp(buf
, "P2P_GET_PASSPHRASE") == 0) {
8932 reply_len
= p2p_get_passphrase(wpa_s
, reply
, reply_size
);
8933 } else if (os_strncmp(buf
, "P2P_SERV_DISC_REQ ", 18) == 0) {
8934 reply_len
= p2p_ctrl_serv_disc_req(wpa_s
, buf
+ 18, reply
,
8936 } else if (os_strncmp(buf
, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
8937 if (p2p_ctrl_serv_disc_cancel_req(wpa_s
, buf
+ 25) < 0)
8939 } else if (os_strncmp(buf
, "P2P_SERV_DISC_RESP ", 19) == 0) {
8940 if (p2p_ctrl_serv_disc_resp(wpa_s
, buf
+ 19) < 0)
8942 } else if (os_strcmp(buf
, "P2P_SERVICE_UPDATE") == 0) {
8943 wpas_p2p_sd_service_update(wpa_s
);
8944 } else if (os_strncmp(buf
, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
8945 if (p2p_ctrl_serv_disc_external(wpa_s
, buf
+ 23) < 0)
8947 } else if (os_strcmp(buf
, "P2P_SERVICE_FLUSH") == 0) {
8948 wpas_p2p_service_flush(wpa_s
);
8949 } else if (os_strncmp(buf
, "P2P_SERVICE_ADD ", 16) == 0) {
8950 if (p2p_ctrl_service_add(wpa_s
, buf
+ 16) < 0)
8952 } else if (os_strncmp(buf
, "P2P_SERVICE_DEL ", 16) == 0) {
8953 if (p2p_ctrl_service_del(wpa_s
, buf
+ 16) < 0)
8955 } else if (os_strncmp(buf
, "P2P_SERVICE_REP ", 16) == 0) {
8956 if (p2p_ctrl_service_replace(wpa_s
, buf
+ 16) < 0)
8958 } else if (os_strncmp(buf
, "P2P_REJECT ", 11) == 0) {
8959 if (p2p_ctrl_reject(wpa_s
, buf
+ 11) < 0)
8961 } else if (os_strncmp(buf
, "P2P_INVITE ", 11) == 0) {
8962 if (p2p_ctrl_invite(wpa_s
, buf
+ 11) < 0)
8964 } else if (os_strncmp(buf
, "P2P_PEER ", 9) == 0) {
8965 reply_len
= p2p_ctrl_peer(wpa_s
, buf
+ 9, reply
,
8967 } else if (os_strncmp(buf
, "P2P_SET ", 8) == 0) {
8968 if (p2p_ctrl_set(wpa_s
, buf
+ 8) < 0)
8970 } else if (os_strcmp(buf
, "P2P_FLUSH") == 0) {
8971 p2p_ctrl_flush(wpa_s
);
8972 } else if (os_strncmp(buf
, "P2P_UNAUTHORIZE ", 16) == 0) {
8973 if (wpas_p2p_unauthorize(wpa_s
, buf
+ 16) < 0)
8975 } else if (os_strcmp(buf
, "P2P_CANCEL") == 0) {
8976 if (wpas_p2p_cancel(wpa_s
))
8978 } else if (os_strncmp(buf
, "P2P_PRESENCE_REQ ", 17) == 0) {
8979 if (p2p_ctrl_presence_req(wpa_s
, buf
+ 17) < 0)
8981 } else if (os_strcmp(buf
, "P2P_PRESENCE_REQ") == 0) {
8982 if (p2p_ctrl_presence_req(wpa_s
, "") < 0)
8984 } else if (os_strncmp(buf
, "P2P_EXT_LISTEN ", 15) == 0) {
8985 if (p2p_ctrl_ext_listen(wpa_s
, buf
+ 15) < 0)
8987 } else if (os_strcmp(buf
, "P2P_EXT_LISTEN") == 0) {
8988 if (p2p_ctrl_ext_listen(wpa_s
, "") < 0)
8990 } else if (os_strncmp(buf
, "P2P_REMOVE_CLIENT ", 18) == 0) {
8991 if (p2p_ctrl_remove_client(wpa_s
, buf
+ 18) < 0)
8993 } else if (os_strncmp(buf
, "P2P_LO_START ", 13) == 0) {
8994 if (p2p_ctrl_iface_p2p_lo_start(wpa_s
, buf
+ 13))
8996 } else if (os_strcmp(buf
, "P2P_LO_STOP") == 0) {
8997 if (wpas_p2p_lo_stop(wpa_s
))
8999 #endif /* CONFIG_P2P */
9000 #ifdef CONFIG_WIFI_DISPLAY
9001 } else if (os_strncmp(buf
, "WFD_SUBELEM_SET ", 16) == 0) {
9002 if (wifi_display_subelem_set(wpa_s
->global
, buf
+ 16) < 0)
9004 } else if (os_strncmp(buf
, "WFD_SUBELEM_GET ", 16) == 0) {
9005 reply_len
= wifi_display_subelem_get(wpa_s
->global
, buf
+ 16,
9007 #endif /* CONFIG_WIFI_DISPLAY */
9008 #ifdef CONFIG_INTERWORKING
9009 } else if (os_strcmp(buf
, "FETCH_ANQP") == 0) {
9010 if (interworking_fetch_anqp(wpa_s
) < 0)
9012 } else if (os_strcmp(buf
, "STOP_FETCH_ANQP") == 0) {
9013 interworking_stop_fetch_anqp(wpa_s
);
9014 } else if (os_strcmp(buf
, "INTERWORKING_SELECT") == 0) {
9015 if (ctrl_interworking_select(wpa_s
, NULL
) < 0)
9017 } else if (os_strncmp(buf
, "INTERWORKING_SELECT ", 20) == 0) {
9018 if (ctrl_interworking_select(wpa_s
, buf
+ 20) < 0)
9020 } else if (os_strncmp(buf
, "INTERWORKING_CONNECT ", 21) == 0) {
9021 if (ctrl_interworking_connect(wpa_s
, buf
+ 21, 0) < 0)
9023 } else if (os_strncmp(buf
, "INTERWORKING_ADD_NETWORK ", 25) == 0) {
9026 id
= ctrl_interworking_connect(wpa_s
, buf
+ 25, 1);
9030 reply_len
= os_snprintf(reply
, reply_size
, "%d\n", id
);
9031 if (os_snprintf_error(reply_size
, reply_len
))
9034 } else if (os_strncmp(buf
, "ANQP_GET ", 9) == 0) {
9035 if (get_anqp(wpa_s
, buf
+ 9) < 0)
9037 } else if (os_strncmp(buf
, "GAS_REQUEST ", 12) == 0) {
9038 if (gas_request(wpa_s
, buf
+ 12) < 0)
9040 } else if (os_strncmp(buf
, "GAS_RESPONSE_GET ", 17) == 0) {
9041 reply_len
= gas_response_get(wpa_s
, buf
+ 17, reply
,
9043 #endif /* CONFIG_INTERWORKING */
9045 } else if (os_strncmp(buf
, "HS20_ANQP_GET ", 14) == 0) {
9046 if (get_hs20_anqp(wpa_s
, buf
+ 14) < 0)
9048 } else if (os_strncmp(buf
, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
9049 if (hs20_get_nai_home_realm_list(wpa_s
, buf
+ 29) < 0)
9051 } else if (os_strncmp(buf
, "HS20_ICON_REQUEST ", 18) == 0) {
9052 if (hs20_icon_request(wpa_s
, buf
+ 18, 0) < 0)
9054 } else if (os_strncmp(buf
, "REQ_HS20_ICON ", 14) == 0) {
9055 if (hs20_icon_request(wpa_s
, buf
+ 14, 1) < 0)
9057 } else if (os_strncmp(buf
, "GET_HS20_ICON ", 14) == 0) {
9058 reply_len
= get_hs20_icon(wpa_s
, buf
+ 14, reply
, reply_size
);
9059 } else if (os_strncmp(buf
, "DEL_HS20_ICON ", 14) == 0) {
9060 if (del_hs20_icon(wpa_s
, buf
+ 14) < 0)
9062 } else if (os_strcmp(buf
, "FETCH_OSU") == 0) {
9063 if (hs20_fetch_osu(wpa_s
, 0) < 0)
9065 } else if (os_strcmp(buf
, "FETCH_OSU no-scan") == 0) {
9066 if (hs20_fetch_osu(wpa_s
, 1) < 0)
9068 } else if (os_strcmp(buf
, "CANCEL_FETCH_OSU") == 0) {
9069 hs20_cancel_fetch_osu(wpa_s
);
9070 #endif /* CONFIG_HS20 */
9071 } else if (os_strncmp(buf
, WPA_CTRL_RSP
, os_strlen(WPA_CTRL_RSP
)) == 0)
9073 if (wpa_supplicant_ctrl_iface_ctrl_rsp(
9074 wpa_s
, buf
+ os_strlen(WPA_CTRL_RSP
)))
9078 * Notify response from timeout to allow the control
9079 * interface response to be sent first.
9081 eloop_register_timeout(0, 0, wpas_ctrl_eapol_response
,
9084 } else if (os_strcmp(buf
, "RECONFIGURE") == 0) {
9085 if (wpa_supplicant_reload_configuration(wpa_s
))
9087 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
9088 wpa_supplicant_terminate_proc(wpa_s
->global
);
9089 } else if (os_strncmp(buf
, "BSSID ", 6) == 0) {
9090 if (wpa_supplicant_ctrl_iface_bssid(wpa_s
, buf
+ 6))
9092 } else if (os_strncmp(buf
, "BLACKLIST", 9) == 0) {
9093 reply_len
= wpa_supplicant_ctrl_iface_blacklist(
9094 wpa_s
, buf
+ 9, reply
, reply_size
);
9095 } else if (os_strncmp(buf
, "LOG_LEVEL", 9) == 0) {
9096 reply_len
= wpa_supplicant_ctrl_iface_log_level(
9097 wpa_s
, buf
+ 9, reply
, reply_size
);
9098 } else if (os_strncmp(buf
, "LIST_NETWORKS ", 14) == 0) {
9099 reply_len
= wpa_supplicant_ctrl_iface_list_networks(
9100 wpa_s
, buf
+ 14, reply
, reply_size
);
9101 } else if (os_strcmp(buf
, "LIST_NETWORKS") == 0) {
9102 reply_len
= wpa_supplicant_ctrl_iface_list_networks(
9103 wpa_s
, NULL
, reply
, reply_size
);
9104 } else if (os_strcmp(buf
, "DISCONNECT") == 0) {
9105 wpas_request_disconnection(wpa_s
);
9106 } else if (os_strcmp(buf
, "SCAN") == 0) {
9107 wpas_ctrl_scan(wpa_s
, NULL
, reply
, reply_size
, &reply_len
);
9108 } else if (os_strncmp(buf
, "SCAN ", 5) == 0) {
9109 wpas_ctrl_scan(wpa_s
, buf
+ 5, reply
, reply_size
, &reply_len
);
9110 } else if (os_strcmp(buf
, "SCAN_RESULTS") == 0) {
9111 reply_len
= wpa_supplicant_ctrl_iface_scan_results(
9112 wpa_s
, reply
, reply_size
);
9113 } else if (os_strcmp(buf
, "ABORT_SCAN") == 0) {
9114 if (wpas_abort_ongoing_scan(wpa_s
) < 0)
9116 } else if (os_strncmp(buf
, "SELECT_NETWORK ", 15) == 0) {
9117 if (wpa_supplicant_ctrl_iface_select_network(wpa_s
, buf
+ 15))
9119 } else if (os_strncmp(buf
, "ENABLE_NETWORK ", 15) == 0) {
9120 if (wpa_supplicant_ctrl_iface_enable_network(wpa_s
, buf
+ 15))
9122 } else if (os_strncmp(buf
, "DISABLE_NETWORK ", 16) == 0) {
9123 if (wpa_supplicant_ctrl_iface_disable_network(wpa_s
, buf
+ 16))
9125 } else if (os_strcmp(buf
, "ADD_NETWORK") == 0) {
9126 reply_len
= wpa_supplicant_ctrl_iface_add_network(
9127 wpa_s
, reply
, reply_size
);
9128 } else if (os_strncmp(buf
, "REMOVE_NETWORK ", 15) == 0) {
9129 if (wpa_supplicant_ctrl_iface_remove_network(wpa_s
, buf
+ 15))
9131 } else if (os_strncmp(buf
, "SET_NETWORK ", 12) == 0) {
9132 if (wpa_supplicant_ctrl_iface_set_network(wpa_s
, buf
+ 12))
9134 } else if (os_strncmp(buf
, "GET_NETWORK ", 12) == 0) {
9135 reply_len
= wpa_supplicant_ctrl_iface_get_network(
9136 wpa_s
, buf
+ 12, reply
, reply_size
);
9137 } else if (os_strncmp(buf
, "DUP_NETWORK ", 12) == 0) {
9138 if (wpa_supplicant_ctrl_iface_dup_network(wpa_s
, buf
+ 12,
9141 } else if (os_strcmp(buf
, "LIST_CREDS") == 0) {
9142 reply_len
= wpa_supplicant_ctrl_iface_list_creds(
9143 wpa_s
, reply
, reply_size
);
9144 } else if (os_strcmp(buf
, "ADD_CRED") == 0) {
9145 reply_len
= wpa_supplicant_ctrl_iface_add_cred(
9146 wpa_s
, reply
, reply_size
);
9147 } else if (os_strncmp(buf
, "REMOVE_CRED ", 12) == 0) {
9148 if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s
, buf
+ 12))
9150 } else if (os_strncmp(buf
, "SET_CRED ", 9) == 0) {
9151 if (wpa_supplicant_ctrl_iface_set_cred(wpa_s
, buf
+ 9))
9153 } else if (os_strncmp(buf
, "GET_CRED ", 9) == 0) {
9154 reply_len
= wpa_supplicant_ctrl_iface_get_cred(wpa_s
, buf
+ 9,
9157 #ifndef CONFIG_NO_CONFIG_WRITE
9158 } else if (os_strcmp(buf
, "SAVE_CONFIG") == 0) {
9159 if (wpa_supplicant_ctrl_iface_save_config(wpa_s
))
9161 #endif /* CONFIG_NO_CONFIG_WRITE */
9162 } else if (os_strncmp(buf
, "GET_CAPABILITY ", 15) == 0) {
9163 reply_len
= wpa_supplicant_ctrl_iface_get_capability(
9164 wpa_s
, buf
+ 15, reply
, reply_size
);
9165 } else if (os_strncmp(buf
, "AP_SCAN ", 8) == 0) {
9166 if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s
, buf
+ 8))
9168 } else if (os_strncmp(buf
, "SCAN_INTERVAL ", 14) == 0) {
9169 if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s
, buf
+ 14))
9171 } else if (os_strcmp(buf
, "INTERFACE_LIST") == 0) {
9172 reply_len
= wpa_supplicant_global_iface_list(
9173 wpa_s
->global
, reply
, reply_size
);
9174 } else if (os_strncmp(buf
, "INTERFACES", 10) == 0) {
9175 reply_len
= wpa_supplicant_global_iface_interfaces(
9176 wpa_s
->global
, buf
+ 10, reply
, reply_size
);
9177 } else if (os_strncmp(buf
, "BSS ", 4) == 0) {
9178 reply_len
= wpa_supplicant_ctrl_iface_bss(
9179 wpa_s
, buf
+ 4, reply
, reply_size
);
9181 } else if (os_strcmp(buf
, "STA-FIRST") == 0) {
9182 reply_len
= ap_ctrl_iface_sta_first(wpa_s
, reply
, reply_size
);
9183 } else if (os_strncmp(buf
, "STA ", 4) == 0) {
9184 reply_len
= ap_ctrl_iface_sta(wpa_s
, buf
+ 4, reply
,
9186 } else if (os_strncmp(buf
, "STA-NEXT ", 9) == 0) {
9187 reply_len
= ap_ctrl_iface_sta_next(wpa_s
, buf
+ 9, reply
,
9189 } else if (os_strncmp(buf
, "DEAUTHENTICATE ", 15) == 0) {
9190 if (ap_ctrl_iface_sta_deauthenticate(wpa_s
, buf
+ 15))
9192 } else if (os_strncmp(buf
, "DISASSOCIATE ", 13) == 0) {
9193 if (ap_ctrl_iface_sta_disassociate(wpa_s
, buf
+ 13))
9195 } else if (os_strncmp(buf
, "CHAN_SWITCH ", 12) == 0) {
9196 if (ap_ctrl_iface_chanswitch(wpa_s
, buf
+ 12))
9198 } else if (os_strcmp(buf
, "STOP_AP") == 0) {
9199 if (wpas_ap_stop_ap(wpa_s
))
9201 #endif /* CONFIG_AP */
9202 } else if (os_strcmp(buf
, "SUSPEND") == 0) {
9203 wpas_notify_suspend(wpa_s
->global
);
9204 } else if (os_strcmp(buf
, "RESUME") == 0) {
9205 wpas_notify_resume(wpa_s
->global
);
9206 #ifdef CONFIG_TESTING_OPTIONS
9207 } else if (os_strcmp(buf
, "DROP_SA") == 0) {
9208 wpa_supplicant_ctrl_iface_drop_sa(wpa_s
);
9209 #endif /* CONFIG_TESTING_OPTIONS */
9210 } else if (os_strncmp(buf
, "ROAM ", 5) == 0) {
9211 if (wpa_supplicant_ctrl_iface_roam(wpa_s
, buf
+ 5))
9213 } else if (os_strncmp(buf
, "STA_AUTOCONNECT ", 16) == 0) {
9214 wpa_s
->auto_reconnect_disabled
= atoi(buf
+ 16) == 0;
9215 } else if (os_strncmp(buf
, "BSS_EXPIRE_AGE ", 15) == 0) {
9216 if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s
, buf
+ 15))
9218 } else if (os_strncmp(buf
, "BSS_EXPIRE_COUNT ", 17) == 0) {
9219 if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s
,
9222 } else if (os_strncmp(buf
, "BSS_FLUSH ", 10) == 0) {
9223 wpa_supplicant_ctrl_iface_bss_flush(wpa_s
, buf
+ 10);
9225 } else if (os_strncmp(buf
, "TDLS_DISCOVER ", 14) == 0) {
9226 if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s
, buf
+ 14))
9228 } else if (os_strncmp(buf
, "TDLS_SETUP ", 11) == 0) {
9229 if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s
, buf
+ 11))
9231 } else if (os_strncmp(buf
, "TDLS_TEARDOWN ", 14) == 0) {
9232 if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s
, buf
+ 14))
9234 } else if (os_strncmp(buf
, "TDLS_CHAN_SWITCH ", 17) == 0) {
9235 if (wpa_supplicant_ctrl_iface_tdls_chan_switch(wpa_s
,
9238 } else if (os_strncmp(buf
, "TDLS_CANCEL_CHAN_SWITCH ", 24) == 0) {
9239 if (wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(wpa_s
,
9242 } else if (os_strncmp(buf
, "TDLS_LINK_STATUS ", 17) == 0) {
9243 reply_len
= wpa_supplicant_ctrl_iface_tdls_link_status(
9244 wpa_s
, buf
+ 17, reply
, reply_size
);
9245 #endif /* CONFIG_TDLS */
9246 } else if (os_strcmp(buf
, "WMM_AC_STATUS") == 0) {
9247 reply_len
= wpas_wmm_ac_status(wpa_s
, reply
, reply_size
);
9248 } else if (os_strncmp(buf
, "WMM_AC_ADDTS ", 13) == 0) {
9249 if (wmm_ac_ctrl_addts(wpa_s
, buf
+ 13))
9251 } else if (os_strncmp(buf
, "WMM_AC_DELTS ", 13) == 0) {
9252 if (wmm_ac_ctrl_delts(wpa_s
, buf
+ 13))
9254 } else if (os_strncmp(buf
, "SIGNAL_POLL", 11) == 0) {
9255 reply_len
= wpa_supplicant_signal_poll(wpa_s
, reply
,
9257 } else if (os_strncmp(buf
, "SIGNAL_MONITOR", 14) == 0) {
9258 if (wpas_ctrl_iface_signal_monitor(wpa_s
, buf
+ 14))
9260 } else if (os_strncmp(buf
, "PKTCNT_POLL", 11) == 0) {
9261 reply_len
= wpa_supplicant_pktcnt_poll(wpa_s
, reply
,
9263 #ifdef CONFIG_AUTOSCAN
9264 } else if (os_strncmp(buf
, "AUTOSCAN ", 9) == 0) {
9265 if (wpa_supplicant_ctrl_iface_autoscan(wpa_s
, buf
+ 9))
9267 #endif /* CONFIG_AUTOSCAN */
9268 } else if (os_strcmp(buf
, "DRIVER_FLAGS") == 0) {
9269 reply_len
= wpas_ctrl_iface_driver_flags(wpa_s
, reply
,
9272 } else if (os_strncmp(buf
, "DRIVER ", 7) == 0) {
9273 reply_len
= wpa_supplicant_driver_cmd(wpa_s
, buf
+ 7, reply
,
9275 #endif /* ANDROID */
9276 } else if (os_strncmp(buf
, "VENDOR ", 7) == 0) {
9277 reply_len
= wpa_supplicant_vendor_cmd(wpa_s
, buf
+ 7, reply
,
9279 } else if (os_strcmp(buf
, "REAUTHENTICATE") == 0) {
9280 pmksa_cache_clear_current(wpa_s
->wpa
);
9281 eapol_sm_request_reauth(wpa_s
->eapol
);
9283 } else if (os_strncmp(buf
, "WNM_SLEEP ", 10) == 0) {
9284 if (wpas_ctrl_iface_wnm_sleep(wpa_s
, buf
+ 10))
9286 } else if (os_strncmp(buf
, "WNM_BSS_QUERY ", 14) == 0) {
9287 if (wpas_ctrl_iface_wnm_bss_query(wpa_s
, buf
+ 14))
9289 #endif /* CONFIG_WNM */
9290 } else if (os_strcmp(buf
, "FLUSH") == 0) {
9291 wpa_supplicant_ctrl_iface_flush(wpa_s
);
9292 } else if (os_strncmp(buf
, "RADIO_WORK ", 11) == 0) {
9293 reply_len
= wpas_ctrl_radio_work(wpa_s
, buf
+ 11, reply
,
9295 #ifdef CONFIG_TESTING_OPTIONS
9296 } else if (os_strncmp(buf
, "MGMT_TX ", 8) == 0) {
9297 if (wpas_ctrl_iface_mgmt_tx(wpa_s
, buf
+ 8) < 0)
9299 } else if (os_strcmp(buf
, "MGMT_TX_DONE") == 0) {
9300 wpas_ctrl_iface_mgmt_tx_done(wpa_s
);
9301 } else if (os_strncmp(buf
, "MGMT_RX_PROCESS ", 16) == 0) {
9302 if (wpas_ctrl_iface_mgmt_rx_process(wpa_s
, buf
+ 16) < 0)
9304 } else if (os_strncmp(buf
, "DRIVER_EVENT ", 13) == 0) {
9305 if (wpas_ctrl_iface_driver_event(wpa_s
, buf
+ 13) < 0)
9307 } else if (os_strncmp(buf
, "EAPOL_RX ", 9) == 0) {
9308 if (wpas_ctrl_iface_eapol_rx(wpa_s
, buf
+ 9) < 0)
9310 } else if (os_strncmp(buf
, "DATA_TEST_CONFIG ", 17) == 0) {
9311 if (wpas_ctrl_iface_data_test_config(wpa_s
, buf
+ 17) < 0)
9313 } else if (os_strncmp(buf
, "DATA_TEST_TX ", 13) == 0) {
9314 if (wpas_ctrl_iface_data_test_tx(wpa_s
, buf
+ 13) < 0)
9316 } else if (os_strncmp(buf
, "DATA_TEST_FRAME ", 16) == 0) {
9317 if (wpas_ctrl_iface_data_test_frame(wpa_s
, buf
+ 16) < 0)
9319 } else if (os_strncmp(buf
, "TEST_ALLOC_FAIL ", 16) == 0) {
9320 if (wpas_ctrl_test_alloc_fail(wpa_s
, buf
+ 16) < 0)
9322 } else if (os_strcmp(buf
, "GET_ALLOC_FAIL") == 0) {
9323 reply_len
= wpas_ctrl_get_alloc_fail(wpa_s
, reply
, reply_size
);
9324 } else if (os_strncmp(buf
, "TEST_FAIL ", 10) == 0) {
9325 if (wpas_ctrl_test_fail(wpa_s
, buf
+ 10) < 0)
9327 } else if (os_strcmp(buf
, "GET_FAIL") == 0) {
9328 reply_len
= wpas_ctrl_get_fail(wpa_s
, reply
, reply_size
);
9329 } else if (os_strncmp(buf
, "EVENT_TEST ", 11) == 0) {
9330 if (wpas_ctrl_event_test(wpa_s
, buf
+ 11) < 0)
9332 } else if (os_strncmp(buf
, "TEST_ASSOC_IE ", 14) == 0) {
9333 if (wpas_ctrl_test_assoc_ie(wpa_s
, buf
+ 14) < 0)
9335 #endif /* CONFIG_TESTING_OPTIONS */
9336 } else if (os_strncmp(buf
, "VENDOR_ELEM_ADD ", 16) == 0) {
9337 if (wpas_ctrl_vendor_elem_add(wpa_s
, buf
+ 16) < 0)
9339 } else if (os_strncmp(buf
, "VENDOR_ELEM_GET ", 16) == 0) {
9340 reply_len
= wpas_ctrl_vendor_elem_get(wpa_s
, buf
+ 16, reply
,
9342 } else if (os_strncmp(buf
, "VENDOR_ELEM_REMOVE ", 19) == 0) {
9343 if (wpas_ctrl_vendor_elem_remove(wpa_s
, buf
+ 19) < 0)
9345 } else if (os_strncmp(buf
, "NEIGHBOR_REP_REQUEST", 20) == 0) {
9346 if (wpas_ctrl_iface_send_neighbor_rep(wpa_s
, buf
+ 20))
9348 } else if (os_strcmp(buf
, "ERP_FLUSH") == 0) {
9349 wpas_ctrl_iface_erp_flush(wpa_s
);
9350 } else if (os_strncmp(buf
, "MAC_RAND_SCAN ", 14) == 0) {
9351 if (wpas_ctrl_iface_mac_rand_scan(wpa_s
, buf
+ 14))
9353 } else if (os_strncmp(buf
, "GET_PREF_FREQ_LIST ", 19) == 0) {
9354 reply_len
= wpas_ctrl_iface_get_pref_freq_list(
9355 wpa_s
, buf
+ 19, reply
, reply_size
);
9357 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
9361 if (reply_len
< 0) {
9362 os_memcpy(reply
, "FAIL\n", 5);
9366 *resp_len
= reply_len
;
9371 static int wpa_supplicant_global_iface_add(struct wpa_global
*global
,
9374 struct wpa_interface iface
;
9376 struct wpa_supplicant
*wpa_s
;
9377 unsigned int create_iface
= 0;
9378 u8 mac_addr
[ETH_ALEN
];
9379 enum wpa_driver_if_type type
= WPA_IF_STATION
;
9382 * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
9383 * TAB<bridge_ifname>[TAB<create>[TAB<interface_type>]]
9385 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd
);
9387 os_memset(&iface
, 0, sizeof(iface
));
9390 iface
.ifname
= pos
= cmd
;
9391 pos
= os_strchr(pos
, '\t');
9394 if (iface
.ifname
[0] == '\0')
9399 iface
.confname
= pos
;
9400 pos
= os_strchr(pos
, '\t');
9403 if (iface
.confname
[0] == '\0')
9404 iface
.confname
= NULL
;
9409 pos
= os_strchr(pos
, '\t');
9412 if (iface
.driver
[0] == '\0')
9413 iface
.driver
= NULL
;
9417 iface
.ctrl_interface
= pos
;
9418 pos
= os_strchr(pos
, '\t');
9421 if (iface
.ctrl_interface
[0] == '\0')
9422 iface
.ctrl_interface
= NULL
;
9426 iface
.driver_param
= pos
;
9427 pos
= os_strchr(pos
, '\t');
9430 if (iface
.driver_param
[0] == '\0')
9431 iface
.driver_param
= NULL
;
9435 iface
.bridge_ifname
= pos
;
9436 pos
= os_strchr(pos
, '\t');
9439 if (iface
.bridge_ifname
[0] == '\0')
9440 iface
.bridge_ifname
= NULL
;
9445 pos
= os_strchr(pos
, '\t');
9451 if (os_strcmp(extra
, "create") == 0) {
9456 if (os_strcmp(pos
, "sta") == 0) {
9457 type
= WPA_IF_STATION
;
9458 } else if (os_strcmp(pos
, "ap") == 0) {
9459 type
= WPA_IF_AP_BSS
;
9461 wpa_printf(MSG_DEBUG
,
9462 "INTERFACE_ADD unsupported interface type: '%s'",
9467 wpa_printf(MSG_DEBUG
,
9468 "INTERFACE_ADD unsupported extra parameter: '%s'",
9475 wpa_printf(MSG_DEBUG
, "CTRL_IFACE creating interface '%s'",
9477 if (!global
->ifaces
)
9479 if (wpa_drv_if_add(global
->ifaces
, type
, iface
.ifname
,
9480 NULL
, NULL
, NULL
, mac_addr
, NULL
) < 0) {
9481 wpa_printf(MSG_ERROR
,
9482 "CTRL_IFACE interface creation failed");
9486 wpa_printf(MSG_DEBUG
,
9487 "CTRL_IFACE interface '%s' created with MAC addr: "
9488 MACSTR
, iface
.ifname
, MAC2STR(mac_addr
));
9491 if (wpa_supplicant_get_iface(global
, iface
.ifname
))
9494 wpa_s
= wpa_supplicant_add_iface(global
, &iface
, NULL
);
9497 wpa_s
->added_vif
= create_iface
;
9502 wpa_drv_if_remove(global
->ifaces
, WPA_IF_STATION
, iface
.ifname
);
9507 static int wpa_supplicant_global_iface_remove(struct wpa_global
*global
,
9510 struct wpa_supplicant
*wpa_s
;
9512 unsigned int delete_iface
;
9514 wpa_printf(MSG_DEBUG
, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd
);
9516 wpa_s
= wpa_supplicant_get_iface(global
, cmd
);
9519 delete_iface
= wpa_s
->added_vif
;
9520 ret
= wpa_supplicant_remove_iface(global
, wpa_s
, 0);
9521 if (!ret
&& delete_iface
) {
9522 wpa_printf(MSG_DEBUG
, "CTRL_IFACE deleting the interface '%s'",
9524 ret
= wpa_drv_if_remove(global
->ifaces
, WPA_IF_STATION
, cmd
);
9530 static void wpa_free_iface_info(struct wpa_interface_info
*iface
)
9532 struct wpa_interface_info
*prev
;
9536 iface
= iface
->next
;
9538 os_free(prev
->ifname
);
9539 os_free(prev
->desc
);
9545 static int wpa_supplicant_global_iface_list(struct wpa_global
*global
,
9549 struct wpa_interface_info
*iface
= NULL
, *last
= NULL
, *tmp
;
9552 for (i
= 0; wpa_drivers
[i
]; i
++) {
9553 const struct wpa_driver_ops
*drv
= wpa_drivers
[i
];
9554 if (drv
->get_interfaces
== NULL
)
9556 tmp
= drv
->get_interfaces(global
->drv_priv
[i
]);
9570 for (tmp
= iface
; tmp
; tmp
= tmp
->next
) {
9571 res
= os_snprintf(pos
, end
- pos
, "%s\t%s\t%s\n",
9572 tmp
->drv_name
, tmp
->ifname
,
9573 tmp
->desc
? tmp
->desc
: "");
9574 if (os_snprintf_error(end
- pos
, res
)) {
9581 wpa_free_iface_info(iface
);
9587 static int wpa_supplicant_global_iface_interfaces(struct wpa_global
*global
,
9593 struct wpa_supplicant
*wpa_s
;
9597 show_ctrl
= !!os_strstr(input
, "ctrl");
9599 wpa_s
= global
->ifaces
;
9605 res
= os_snprintf(pos
, end
- pos
, "%s ctrl_iface=%s\n",
9607 wpa_s
->conf
->ctrl_interface
?
9608 wpa_s
->conf
->ctrl_interface
: "N/A");
9610 res
= os_snprintf(pos
, end
- pos
, "%s\n",
9613 if (os_snprintf_error(end
- pos
, res
)) {
9618 wpa_s
= wpa_s
->next
;
9624 static char * wpas_global_ctrl_iface_ifname(struct wpa_global
*global
,
9626 char *cmd
, size_t *resp_len
)
9628 struct wpa_supplicant
*wpa_s
;
9630 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
9631 if (os_strcmp(ifname
, wpa_s
->ifname
) == 0)
9635 if (wpa_s
== NULL
) {
9636 char *resp
= os_strdup("FAIL-NO-IFNAME-MATCH\n");
9638 *resp_len
= os_strlen(resp
);
9644 return wpa_supplicant_ctrl_iface_process(wpa_s
, cmd
, resp_len
);
9648 static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global
*global
,
9649 char *buf
, size_t *resp_len
)
9652 static const char * cmd
[] = {
9658 "P2P_GET_PASSPHRASE",
9659 "P2P_SERVICE_UPDATE",
9660 "P2P_SERVICE_FLUSH",
9667 static const char * prefix
[] = {
9670 #endif /* ANDROID */
9676 "P2P_GROUP_REMOVE ",
9678 "P2P_GROUP_MEMBER ",
9680 "P2P_SERV_DISC_REQ ",
9681 "P2P_SERV_DISC_CANCEL_REQ ",
9682 "P2P_SERV_DISC_RESP ",
9683 "P2P_SERV_DISC_EXTERNAL ",
9692 "P2P_PRESENCE_REQ ",
9694 "P2P_REMOVE_CLIENT ",
9696 "WPS_NFC_TAG_READ ",
9697 "NFC_GET_HANDOVER_SEL ",
9698 "NFC_GET_HANDOVER_REQ ",
9699 "NFC_REPORT_HANDOVER ",
9700 "P2P_ASP_PROVISION ",
9701 "P2P_ASP_PROVISION_RESP ",
9707 if (global
->p2p_init_wpa_s
== NULL
)
9710 for (i
= 0; !found
&& cmd
[i
]; i
++) {
9711 if (os_strcmp(buf
, cmd
[i
]) == 0)
9715 for (i
= 0; !found
&& prefix
[i
]; i
++) {
9716 if (os_strncmp(buf
, prefix
[i
], os_strlen(prefix
[i
])) == 0)
9721 return wpa_supplicant_ctrl_iface_process(global
->p2p_init_wpa_s
,
9723 #endif /* CONFIG_P2P */
9728 static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global
*global
,
9729 char *buf
, size_t *resp_len
)
9731 #ifdef CONFIG_WIFI_DISPLAY
9732 if (global
->p2p_init_wpa_s
== NULL
)
9734 if (os_strncmp(buf
, "WFD_SUBELEM_SET ", 16) == 0 ||
9735 os_strncmp(buf
, "WFD_SUBELEM_GET ", 16) == 0)
9736 return wpa_supplicant_ctrl_iface_process(global
->p2p_init_wpa_s
,
9738 #endif /* CONFIG_WIFI_DISPLAY */
9743 static char * wpas_global_ctrl_iface_redir(struct wpa_global
*global
,
9744 char *buf
, size_t *resp_len
)
9748 ret
= wpas_global_ctrl_iface_redir_p2p(global
, buf
, resp_len
);
9752 ret
= wpas_global_ctrl_iface_redir_wfd(global
, buf
, resp_len
);
9760 static int wpas_global_ctrl_iface_set(struct wpa_global
*global
, char *cmd
)
9764 value
= os_strchr(cmd
, ' ');
9769 wpa_printf(MSG_DEBUG
, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd
, value
);
9771 #ifdef CONFIG_WIFI_DISPLAY
9772 if (os_strcasecmp(cmd
, "wifi_display") == 0) {
9773 wifi_display_enable(global
, !!atoi(value
));
9776 #endif /* CONFIG_WIFI_DISPLAY */
9778 /* Restore cmd to its original value to allow redirection */
9785 static int wpas_global_ctrl_iface_dup_network(struct wpa_global
*global
,
9788 struct wpa_supplicant
*wpa_s
[2]; /* src, dst */
9792 /* cmd: "<src ifname> <dst ifname> <src network id> <dst network id>
9793 * <variable name> */
9795 for (i
= 0; i
< ARRAY_SIZE(wpa_s
) ; i
++) {
9796 p
= os_strchr(cmd
, ' ');
9801 wpa_s
[i
] = global
->ifaces
;
9802 for (; wpa_s
[i
]; wpa_s
[i
] = wpa_s
[i
]->next
) {
9803 if (os_strcmp(cmd
, wpa_s
[i
]->ifname
) == 0)
9808 wpa_printf(MSG_DEBUG
,
9809 "CTRL_IFACE: Could not find iface=%s", cmd
);
9816 return wpa_supplicant_ctrl_iface_dup_network(wpa_s
[0], cmd
, wpa_s
[1]);
9820 #ifndef CONFIG_NO_CONFIG_WRITE
9821 static int wpas_global_ctrl_iface_save_config(struct wpa_global
*global
)
9823 int ret
= 0, saved
= 0;
9824 struct wpa_supplicant
*wpa_s
;
9826 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
9827 if (!wpa_s
->conf
->update_config
) {
9828 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
9832 if (wpa_config_write(wpa_s
->confname
, wpa_s
->conf
)) {
9833 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
9836 wpa_dbg(wpa_s
, MSG_DEBUG
, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
9841 if (!saved
&& !ret
) {
9842 wpa_dbg(wpa_s
, MSG_DEBUG
,
9843 "CTRL_IFACE: SAVE_CONFIG - No configuration files could be updated");
9849 #endif /* CONFIG_NO_CONFIG_WRITE */
9852 static int wpas_global_ctrl_iface_status(struct wpa_global
*global
,
9853 char *buf
, size_t buflen
)
9857 struct wpa_supplicant
*wpa_s
;
9863 if (global
->p2p
&& !global
->p2p_disabled
) {
9864 ret
= os_snprintf(pos
, end
- pos
, "p2p_device_address=" MACSTR
9867 MAC2STR(global
->p2p_dev_addr
),
9868 p2p_get_state_txt(global
->p2p
));
9869 if (os_snprintf_error(end
- pos
, ret
))
9872 } else if (global
->p2p
) {
9873 ret
= os_snprintf(pos
, end
- pos
, "p2p_state=DISABLED\n");
9874 if (os_snprintf_error(end
- pos
, ret
))
9878 #endif /* CONFIG_P2P */
9880 #ifdef CONFIG_WIFI_DISPLAY
9881 ret
= os_snprintf(pos
, end
- pos
, "wifi_display=%d\n",
9882 !!global
->wifi_display
);
9883 if (os_snprintf_error(end
- pos
, ret
))
9886 #endif /* CONFIG_WIFI_DISPLAY */
9888 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
9889 ret
= os_snprintf(pos
, end
- pos
, "ifname=%s\n"
9890 "address=" MACSTR
"\n",
9891 wpa_s
->ifname
, MAC2STR(wpa_s
->own_addr
));
9892 if (os_snprintf_error(end
- pos
, ret
))
9903 static int wpas_global_ctrl_iface_fst_attach(struct wpa_global
*global
,
9904 char *cmd
, char *buf
,
9907 char ifname
[IFNAMSIZ
+ 1];
9908 struct fst_iface_cfg cfg
;
9909 struct wpa_supplicant
*wpa_s
;
9910 struct fst_wpa_obj iface_obj
;
9912 if (!fst_parse_attach_command(cmd
, ifname
, sizeof(ifname
), &cfg
)) {
9913 wpa_s
= wpa_supplicant_get_iface(global
, ifname
);
9916 wpa_printf(MSG_INFO
, "FST: Already attached");
9919 fst_wpa_supplicant_fill_iface_obj(wpa_s
, &iface_obj
);
9920 wpa_s
->fst
= fst_attach(ifname
, wpa_s
->own_addr
,
9923 return os_snprintf(buf
, reply_size
, "OK\n");
9931 static int wpas_global_ctrl_iface_fst_detach(struct wpa_global
*global
,
9932 char *cmd
, char *buf
,
9935 char ifname
[IFNAMSIZ
+ 1];
9936 struct wpa_supplicant
*wpa_s
;
9938 if (!fst_parse_detach_command(cmd
, ifname
, sizeof(ifname
))) {
9939 wpa_s
= wpa_supplicant_get_iface(global
, ifname
);
9941 if (!fst_iface_detach(ifname
)) {
9943 return os_snprintf(buf
, reply_size
, "OK\n");
9951 #endif /* CONFIG_FST */
9954 char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global
*global
,
9955 char *buf
, size_t *resp_len
)
9958 const int reply_size
= 2048;
9960 int level
= MSG_DEBUG
;
9962 if (os_strncmp(buf
, "IFNAME=", 7) == 0) {
9963 char *pos
= os_strchr(buf
+ 7, ' ');
9966 return wpas_global_ctrl_iface_ifname(global
,
9972 reply
= wpas_global_ctrl_iface_redir(global
, buf
, resp_len
);
9976 if (os_strcmp(buf
, "PING") == 0)
9977 level
= MSG_EXCESSIVE
;
9978 wpa_hexdump_ascii(level
, "RX global ctrl_iface",
9979 (const u8
*) buf
, os_strlen(buf
));
9981 reply
= os_malloc(reply_size
);
9982 if (reply
== NULL
) {
9987 os_memcpy(reply
, "OK\n", 3);
9990 if (os_strcmp(buf
, "PING") == 0) {
9991 os_memcpy(reply
, "PONG\n", 5);
9993 } else if (os_strncmp(buf
, "INTERFACE_ADD ", 14) == 0) {
9994 if (wpa_supplicant_global_iface_add(global
, buf
+ 14))
9996 } else if (os_strncmp(buf
, "INTERFACE_REMOVE ", 17) == 0) {
9997 if (wpa_supplicant_global_iface_remove(global
, buf
+ 17))
9999 } else if (os_strcmp(buf
, "INTERFACE_LIST") == 0) {
10000 reply_len
= wpa_supplicant_global_iface_list(
10001 global
, reply
, reply_size
);
10002 } else if (os_strncmp(buf
, "INTERFACES", 10) == 0) {
10003 reply_len
= wpa_supplicant_global_iface_interfaces(
10004 global
, buf
+ 10, reply
, reply_size
);
10006 } else if (os_strncmp(buf
, "FST-ATTACH ", 11) == 0) {
10007 reply_len
= wpas_global_ctrl_iface_fst_attach(global
, buf
+ 11,
10010 } else if (os_strncmp(buf
, "FST-DETACH ", 11) == 0) {
10011 reply_len
= wpas_global_ctrl_iface_fst_detach(global
, buf
+ 11,
10014 } else if (os_strncmp(buf
, "FST-MANAGER ", 12) == 0) {
10015 reply_len
= fst_ctrl_iface_receive(buf
+ 12, reply
, reply_size
);
10016 #endif /* CONFIG_FST */
10017 } else if (os_strcmp(buf
, "TERMINATE") == 0) {
10018 wpa_supplicant_terminate_proc(global
);
10019 } else if (os_strcmp(buf
, "SUSPEND") == 0) {
10020 wpas_notify_suspend(global
);
10021 } else if (os_strcmp(buf
, "RESUME") == 0) {
10022 wpas_notify_resume(global
);
10023 } else if (os_strncmp(buf
, "SET ", 4) == 0) {
10024 if (wpas_global_ctrl_iface_set(global
, buf
+ 4)) {
10026 if (global
->p2p_init_wpa_s
) {
10028 /* Check if P2P redirection would work for this
10030 return wpa_supplicant_ctrl_iface_process(
10031 global
->p2p_init_wpa_s
,
10034 #endif /* CONFIG_P2P */
10037 } else if (os_strncmp(buf
, "DUP_NETWORK ", 12) == 0) {
10038 if (wpas_global_ctrl_iface_dup_network(global
, buf
+ 12))
10040 #ifndef CONFIG_NO_CONFIG_WRITE
10041 } else if (os_strcmp(buf
, "SAVE_CONFIG") == 0) {
10042 if (wpas_global_ctrl_iface_save_config(global
))
10044 #endif /* CONFIG_NO_CONFIG_WRITE */
10045 } else if (os_strcmp(buf
, "STATUS") == 0) {
10046 reply_len
= wpas_global_ctrl_iface_status(global
, reply
,
10048 #ifdef CONFIG_MODULE_TESTS
10049 } else if (os_strcmp(buf
, "MODULE_TESTS") == 0) {
10050 if (wpas_module_tests() < 0)
10052 #endif /* CONFIG_MODULE_TESTS */
10053 } else if (os_strncmp(buf
, "RELOG", 5) == 0) {
10054 if (wpa_debug_reopen_file() < 0)
10057 os_memcpy(reply
, "UNKNOWN COMMAND\n", 16);
10061 if (reply_len
< 0) {
10062 os_memcpy(reply
, "FAIL\n", 5);
10066 *resp_len
= reply_len
;