3 * Copyright (c) 2009-2010, Atheros Communications
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
13 #include "common/ieee802_11_common.h"
14 #include "common/ieee802_11_defs.h"
15 #include "common/wpa_ctrl.h"
16 #include "wps/wps_i.h"
18 #include "ap/hostapd.h"
19 #include "ap/ap_config.h"
20 #include "ap/sta_info.h"
21 #include "ap/ap_drv_ops.h"
22 #include "ap/p2p_hostapd.h"
23 #include "eapol_supp/eapol_supp_sm.h"
24 #include "rsn_supp/wpa.h"
25 #include "wpa_supplicant_i.h"
28 #include "config_ssid.h"
33 #include "offchannel.h"
34 #include "wps_supplicant.h"
35 #include "p2p_supplicant.h"
39 * How many times to try to scan to find the GO before giving up on join
42 #define P2P_MAX_JOIN_SCAN_ATTEMPTS 10
44 #define P2P_AUTO_PD_SCAN_ATTEMPTS 5
46 #ifndef P2P_MAX_CLIENT_IDLE
48 * How many seconds to try to reconnect to the GO when connection in P2P client
51 #define P2P_MAX_CLIENT_IDLE 10
52 #endif /* P2P_MAX_CLIENT_IDLE */
54 #ifndef P2P_MAX_INITIAL_CONN_WAIT
56 * How many seconds to wait for initial 4-way handshake to get completed after
57 * WPS provisioning step.
59 #define P2P_MAX_INITIAL_CONN_WAIT 10
60 #endif /* P2P_MAX_INITIAL_CONN_WAIT */
62 #ifndef P2P_MAX_INITIAL_CONN_WAIT_GO
64 * How many seconds to wait for initial 4-way handshake to get completed after
65 * WPS provisioning step on the GO. This controls the extra time the P2P
66 * operation is considered to be in progress (e.g., to delay other scans) after
67 * WPS provisioning has been completed on the GO during group formation.
69 #define P2P_MAX_INITIAL_CONN_WAIT_GO 10
70 #endif /* P2P_MAX_INITIAL_CONN_WAIT_GO */
72 #ifndef P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE
74 * How many seconds to wait for initial 4-way handshake to get completed after
75 * re-invocation of a persistent group on the GO when the client is expected
76 * to connect automatically (no user interaction).
78 #define P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE 15
79 #endif /* P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE */
81 #ifndef P2P_CONCURRENT_SEARCH_DELAY
82 #define P2P_CONCURRENT_SEARCH_DELAY 500
83 #endif /* P2P_CONCURRENT_SEARCH_DELAY */
85 #define P2P_MGMT_DEVICE_PREFIX "p2p-dev-"
87 enum p2p_group_removal_reason
{
88 P2P_GROUP_REMOVAL_UNKNOWN
,
89 P2P_GROUP_REMOVAL_SILENT
,
90 P2P_GROUP_REMOVAL_FORMATION_FAILED
,
91 P2P_GROUP_REMOVAL_REQUESTED
,
92 P2P_GROUP_REMOVAL_IDLE_TIMEOUT
,
93 P2P_GROUP_REMOVAL_UNAVAILABLE
,
94 P2P_GROUP_REMOVAL_GO_ENDING_SESSION
,
95 P2P_GROUP_REMOVAL_PSK_FAILURE
99 static void wpas_p2p_long_listen_timeout(void *eloop_ctx
, void *timeout_ctx
);
100 static struct wpa_supplicant
*
101 wpas_p2p_get_group_iface(struct wpa_supplicant
*wpa_s
, int addr_allocated
,
103 static int wpas_p2p_join_start(struct wpa_supplicant
*wpa_s
);
104 static void wpas_p2p_join_scan_req(struct wpa_supplicant
*wpa_s
, int freq
);
105 static void wpas_p2p_join_scan(void *eloop_ctx
, void *timeout_ctx
);
106 static int wpas_p2p_join(struct wpa_supplicant
*wpa_s
, const u8
*iface_addr
,
107 const u8
*dev_addr
, enum p2p_wps_method wps_method
,
109 static int wpas_p2p_create_iface(struct wpa_supplicant
*wpa_s
);
110 static void wpas_p2p_cross_connect_setup(struct wpa_supplicant
*wpa_s
);
111 static void wpas_p2p_group_idle_timeout(void *eloop_ctx
, void *timeout_ctx
);
112 static void wpas_p2p_set_group_idle_timeout(struct wpa_supplicant
*wpa_s
);
113 static void wpas_p2p_group_formation_timeout(void *eloop_ctx
,
115 static void wpas_p2p_fallback_to_go_neg(struct wpa_supplicant
*wpa_s
,
117 static int wpas_p2p_stop_find_oper(struct wpa_supplicant
*wpa_s
);
121 * Get the number of concurrent channels that the HW can operate, but that are
122 * currently not in use by any of the wpa_supplicant interfaces.
124 static int wpas_p2p_num_unused_channels(struct wpa_supplicant
*wpa_s
)
129 freqs
= os_calloc(wpa_s
->num_multichan_concurrent
, sizeof(int));
133 num
= get_shared_radio_freqs(wpa_s
, freqs
,
134 wpa_s
->num_multichan_concurrent
);
137 unused
= wpa_s
->num_multichan_concurrent
- num
;
138 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: num_unused_channels: %d", unused
);
144 * Get the frequencies that are currently in use by one or more of the virtual
145 * interfaces, and that are also valid for P2P operation.
147 static int wpas_p2p_valid_oper_freqs(struct wpa_supplicant
*wpa_s
,
148 int *p2p_freqs
, unsigned int len
)
151 unsigned int num
, i
, j
;
153 freqs
= os_calloc(wpa_s
->num_multichan_concurrent
, sizeof(int));
157 num
= get_shared_radio_freqs(wpa_s
, freqs
,
158 wpa_s
->num_multichan_concurrent
);
160 os_memset(p2p_freqs
, 0, sizeof(int) * len
);
162 for (i
= 0, j
= 0; i
< num
&& j
< len
; i
++) {
163 if (p2p_supported_freq(wpa_s
->global
->p2p
, freqs
[i
]))
164 p2p_freqs
[j
++] = freqs
[i
];
169 dump_freq_array(wpa_s
, "valid for P2P", p2p_freqs
, j
);
175 static void wpas_p2p_set_own_freq_preference(struct wpa_supplicant
*wpa_s
,
178 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
180 if (freq
> 0 && wpa_s
->num_multichan_concurrent
> 1 &&
181 wpas_p2p_num_unused_channels(wpa_s
) > 0 &&
182 wpa_s
->parent
->conf
->p2p_ignore_shared_freq
)
184 p2p_set_own_freq_preference(wpa_s
->global
->p2p
, freq
);
188 static void wpas_p2p_scan_res_handler(struct wpa_supplicant
*wpa_s
,
189 struct wpa_scan_results
*scan_res
)
193 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
196 wpa_printf(MSG_DEBUG
, "P2P: Scan results received (%d BSS)",
197 (int) scan_res
->num
);
199 for (i
= 0; i
< scan_res
->num
; i
++) {
200 struct wpa_scan_res
*bss
= scan_res
->res
[i
];
201 struct os_time time_tmp_age
, entry_ts
;
205 time_tmp_age
.sec
= bss
->age
/ 1000;
206 time_tmp_age
.usec
= (bss
->age
% 1000) * 1000;
207 os_time_sub(&scan_res
->fetch_time
, &time_tmp_age
, &entry_ts
);
209 ies
= (const u8
*) (bss
+ 1);
210 ies_len
= bss
->ie_len
;
211 if (bss
->beacon_ie_len
> 0 &&
212 !wpa_scan_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
) &&
213 wpa_scan_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
)) {
214 wpa_printf(MSG_DEBUG
, "P2P: Use P2P IE(s) from Beacon frame since no P2P IE(s) in Probe Response frames received for "
215 MACSTR
, MAC2STR(bss
->bssid
));
217 ies_len
= bss
->beacon_ie_len
;
221 if (p2p_scan_res_handler(wpa_s
->global
->p2p
, bss
->bssid
,
222 bss
->freq
, &entry_ts
, bss
->level
,
227 p2p_scan_res_handled(wpa_s
->global
->p2p
);
231 static int wpas_p2p_scan(void *ctx
, enum p2p_scan_type type
, int freq
,
232 unsigned int num_req_dev_types
,
233 const u8
*req_dev_types
, const u8
*dev_id
, u16 pw_id
)
235 struct wpa_supplicant
*wpa_s
= ctx
;
236 struct wpa_supplicant
*ifs
;
237 struct wpa_driver_scan_params params
;
239 struct wpabuf
*wps_ie
, *ies
;
240 int social_channels
[] = { 2412, 2437, 2462, 0, 0 };
243 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
246 for (ifs
= wpa_s
->global
->ifaces
; ifs
; ifs
= ifs
->next
) {
247 if (ifs
->sta_scan_pending
&&
248 (wpas_scan_scheduled(ifs
) || ifs
->scanning
) &&
249 wpas_p2p_in_progress(wpa_s
) == 2) {
250 wpa_printf(MSG_DEBUG
, "Delaying P2P scan to allow "
251 "pending station mode scan to be "
252 "completed on interface %s", ifs
->ifname
);
253 wpa_s
->global
->p2p_cb_on_scan_complete
= 1;
254 wpa_supplicant_req_scan(ifs
, 0, 0);
259 os_memset(¶ms
, 0, sizeof(params
));
261 /* P2P Wildcard SSID */
262 params
.num_ssids
= 1;
263 params
.ssids
[0].ssid
= (u8
*) P2P_WILDCARD_SSID
;
264 params
.ssids
[0].ssid_len
= P2P_WILDCARD_SSID_LEN
;
266 wpa_s
->wps
->dev
.p2p
= 1;
267 wps_ie
= wps_build_probe_req_ie(pw_id
, &wpa_s
->wps
->dev
,
268 wpa_s
->wps
->uuid
, WPS_REQ_ENROLLEE
,
269 num_req_dev_types
, req_dev_types
);
273 ielen
= p2p_scan_ie_buf_len(wpa_s
->global
->p2p
);
274 ies
= wpabuf_alloc(wpabuf_len(wps_ie
) + ielen
);
279 wpabuf_put_buf(ies
, wps_ie
);
282 p2p_scan_ie(wpa_s
->global
->p2p
, ies
, dev_id
);
284 params
.p2p_probe
= 1;
285 params
.extra_ies
= wpabuf_head(ies
);
286 params
.extra_ies_len
= wpabuf_len(ies
);
289 case P2P_SCAN_SOCIAL
:
290 params
.freqs
= social_channels
;
294 case P2P_SCAN_SOCIAL_PLUS_ONE
:
295 social_channels
[3] = freq
;
296 params
.freqs
= social_channels
;
300 ret
= wpa_drv_scan(wpa_s
, ¶ms
);
305 for (ifs
= wpa_s
->global
->ifaces
; ifs
; ifs
= ifs
->next
) {
307 ifs
->scan_res_handler
== wpas_p2p_scan_res_handler
) {
308 wpa_s
->global
->p2p_cb_on_scan_complete
= 1;
314 os_get_time(&wpa_s
->scan_trigger_time
);
315 wpa_s
->scan_res_handler
= wpas_p2p_scan_res_handler
;
322 static enum wpa_driver_if_type
wpas_p2p_if_type(int p2p_group_interface
)
324 switch (p2p_group_interface
) {
325 case P2P_GROUP_INTERFACE_PENDING
:
326 return WPA_IF_P2P_GROUP
;
327 case P2P_GROUP_INTERFACE_GO
:
328 return WPA_IF_P2P_GO
;
329 case P2P_GROUP_INTERFACE_CLIENT
:
330 return WPA_IF_P2P_CLIENT
;
333 return WPA_IF_P2P_GROUP
;
337 static struct wpa_supplicant
* wpas_get_p2p_group(struct wpa_supplicant
*wpa_s
,
339 size_t ssid_len
, int *go
)
343 for (wpa_s
= wpa_s
->global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
344 for (s
= wpa_s
->conf
->ssid
; s
; s
= s
->next
) {
345 if (s
->disabled
!= 0 || !s
->p2p_group
||
346 s
->ssid_len
!= ssid_len
||
347 os_memcmp(ssid
, s
->ssid
, ssid_len
) != 0)
349 if (s
->mode
== WPAS_MODE_P2P_GO
&&
350 s
!= wpa_s
->current_ssid
)
353 *go
= s
->mode
== WPAS_MODE_P2P_GO
;
362 static int wpas_p2p_group_delete(struct wpa_supplicant
*wpa_s
,
363 enum p2p_group_removal_reason removal_reason
)
365 struct wpa_ssid
*ssid
;
369 ssid
= wpa_s
->current_ssid
;
372 * The current SSID was not known, but there may still be a
373 * pending P2P group interface waiting for provisioning or a
374 * P2P group that is trying to reconnect.
376 ssid
= wpa_s
->conf
->ssid
;
378 if (ssid
->p2p_group
&& ssid
->disabled
!= 2)
383 wpa_s
->p2p_group_interface
== NOT_P2P_GROUP_INTERFACE
)
385 wpa_printf(MSG_ERROR
, "P2P: P2P group interface "
390 if (wpa_s
->p2p_group_interface
== P2P_GROUP_INTERFACE_GO
)
392 else if (wpa_s
->p2p_group_interface
== P2P_GROUP_INTERFACE_CLIENT
||
393 (ssid
&& ssid
->mode
== WPAS_MODE_INFRA
)) {
394 wpa_s
->reassociate
= 0;
395 wpa_s
->disconnected
= 1;
396 wpa_supplicant_deauthenticate(wpa_s
,
397 WLAN_REASON_DEAUTH_LEAVING
);
401 if (wpa_s
->cross_connect_in_use
) {
402 wpa_s
->cross_connect_in_use
= 0;
403 wpa_msg_global(wpa_s
->parent
, MSG_INFO
,
404 P2P_EVENT_CROSS_CONNECT_DISABLE
"%s %s",
405 wpa_s
->ifname
, wpa_s
->cross_connect_uplink
);
407 switch (removal_reason
) {
408 case P2P_GROUP_REMOVAL_REQUESTED
:
409 reason
= " reason=REQUESTED";
411 case P2P_GROUP_REMOVAL_FORMATION_FAILED
:
412 reason
= " reason=FORMATION_FAILED";
414 case P2P_GROUP_REMOVAL_IDLE_TIMEOUT
:
415 reason
= " reason=IDLE";
417 case P2P_GROUP_REMOVAL_UNAVAILABLE
:
418 reason
= " reason=UNAVAILABLE";
420 case P2P_GROUP_REMOVAL_GO_ENDING_SESSION
:
421 reason
= " reason=GO_ENDING_SESSION";
423 case P2P_GROUP_REMOVAL_PSK_FAILURE
:
424 reason
= " reason=PSK_FAILURE";
430 if (removal_reason
!= P2P_GROUP_REMOVAL_SILENT
) {
431 wpa_msg_global(wpa_s
->parent
, MSG_INFO
,
432 P2P_EVENT_GROUP_REMOVED
"%s %s%s",
433 wpa_s
->ifname
, gtype
, reason
);
436 if (eloop_cancel_timeout(wpas_p2p_group_idle_timeout
, wpa_s
, NULL
) > 0)
437 wpa_printf(MSG_DEBUG
, "P2P: Cancelled P2P group idle timeout");
438 if (eloop_cancel_timeout(wpas_p2p_group_formation_timeout
,
439 wpa_s
->parent
, NULL
) > 0) {
440 wpa_printf(MSG_DEBUG
, "P2P: Cancelled P2P group formation "
442 wpa_s
->p2p_in_provisioning
= 0;
446 * Make sure wait for the first client does not remain active after the
447 * group has been removed.
449 wpa_s
->global
->p2p_go_wait_client
.sec
= 0;
451 if (removal_reason
!= P2P_GROUP_REMOVAL_SILENT
&& ssid
)
452 wpas_notify_p2p_group_removed(wpa_s
, ssid
, gtype
);
454 if (wpa_s
->p2p_group_interface
!= NOT_P2P_GROUP_INTERFACE
) {
455 struct wpa_global
*global
;
457 enum wpa_driver_if_type type
;
458 wpa_printf(MSG_DEBUG
, "P2P: Remove group interface %s",
460 global
= wpa_s
->global
;
461 ifname
= os_strdup(wpa_s
->ifname
);
462 type
= wpas_p2p_if_type(wpa_s
->p2p_group_interface
);
463 wpa_supplicant_remove_iface(wpa_s
->global
, wpa_s
, 0);
464 wpa_s
= global
->ifaces
;
466 wpa_drv_if_remove(wpa_s
, type
, ifname
);
471 if (!wpa_s
->p2p_go_group_formation_completed
) {
472 wpa_s
->global
->p2p_group_formation
= NULL
;
473 wpa_s
->p2p_in_provisioning
= 0;
476 wpa_s
->show_group_started
= 0;
477 os_free(wpa_s
->go_params
);
478 wpa_s
->go_params
= NULL
;
480 wpa_printf(MSG_DEBUG
, "P2P: Remove temporary group network");
481 if (ssid
&& (ssid
->p2p_group
||
482 ssid
->mode
== WPAS_MODE_P2P_GROUP_FORMATION
||
483 (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
))) {
485 if (ssid
== wpa_s
->current_ssid
) {
486 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
487 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
488 wpa_s
->current_ssid
= NULL
;
491 * Networks objects created during any P2P activities are not
492 * exposed out as they might/will confuse certain non-P2P aware
493 * applications since these network objects won't behave like
496 * Likewise, we don't send out network removed signals for such
499 wpa_config_remove_network(wpa_s
->conf
, id
);
500 wpa_supplicant_clear_status(wpa_s
);
501 wpa_supplicant_cancel_sched_scan(wpa_s
);
502 wpa_s
->sta_scan_pending
= 0;
504 wpa_printf(MSG_DEBUG
, "P2P: Temporary group network not "
508 wpa_supplicant_ap_deinit(wpa_s
);
510 wpa_drv_deinit_p2p_cli(wpa_s
);
516 static int wpas_p2p_persistent_group(struct wpa_supplicant
*wpa_s
,
518 const u8
*ssid
, size_t ssid_len
)
526 if (wpa_s
->go_params
)
527 bssid
= wpa_s
->go_params
->peer_interface_addr
;
529 bssid
= wpa_s
->bssid
;
531 bss
= wpa_bss_get(wpa_s
, bssid
, ssid
, ssid_len
);
533 u8 iface_addr
[ETH_ALEN
];
534 if (p2p_get_interface_addr(wpa_s
->global
->p2p
, bssid
,
536 bss
= wpa_bss_get(wpa_s
, iface_addr
, ssid
, ssid_len
);
539 wpa_printf(MSG_DEBUG
, "P2P: Could not figure out whether "
540 "group is persistent - BSS " MACSTR
" not found",
545 p2p
= wpa_bss_get_vendor_ie_multi(bss
, P2P_IE_VENDOR_TYPE
);
547 p2p
= wpa_bss_get_vendor_ie_multi_beacon(bss
,
550 wpa_printf(MSG_DEBUG
, "P2P: Could not figure out whether "
551 "group is persistent - BSS " MACSTR
552 " did not include P2P IE", MAC2STR(bssid
));
553 wpa_hexdump(MSG_DEBUG
, "P2P: Probe Response IEs",
554 (u8
*) (bss
+ 1), bss
->ie_len
);
555 wpa_hexdump(MSG_DEBUG
, "P2P: Beacon IEs",
556 ((u8
*) bss
+ 1) + bss
->ie_len
,
561 group_capab
= p2p_get_group_capab(p2p
);
562 addr
= p2p_get_go_dev_addr(p2p
);
563 wpa_printf(MSG_DEBUG
, "P2P: Checking whether group is persistent: "
564 "group_capab=0x%x", group_capab
);
566 os_memcpy(go_dev_addr
, addr
, ETH_ALEN
);
567 wpa_printf(MSG_DEBUG
, "P2P: GO Device Address " MACSTR
,
570 os_memset(go_dev_addr
, 0, ETH_ALEN
);
573 wpa_printf(MSG_DEBUG
, "P2P: BSS " MACSTR
" group_capab=0x%x "
574 "go_dev_addr=" MACSTR
,
575 MAC2STR(bssid
), group_capab
, MAC2STR(go_dev_addr
));
577 return group_capab
& P2P_GROUP_CAPAB_PERSISTENT_GROUP
;
581 static int wpas_p2p_store_persistent_group(struct wpa_supplicant
*wpa_s
,
582 struct wpa_ssid
*ssid
,
583 const u8
*go_dev_addr
)
588 wpa_printf(MSG_DEBUG
, "P2P: Storing credentials for a persistent "
589 "group (GO Dev Addr " MACSTR
")", MAC2STR(go_dev_addr
));
590 for (s
= wpa_s
->conf
->ssid
; s
; s
= s
->next
) {
591 if (s
->disabled
== 2 &&
592 os_memcmp(go_dev_addr
, s
->bssid
, ETH_ALEN
) == 0 &&
593 s
->ssid_len
== ssid
->ssid_len
&&
594 os_memcmp(ssid
->ssid
, s
->ssid
, ssid
->ssid_len
) == 0)
599 wpa_printf(MSG_DEBUG
, "P2P: Update existing persistent group "
601 if (ssid
->passphrase
&& !s
->passphrase
)
603 else if (ssid
->passphrase
&& s
->passphrase
&&
604 os_strcmp(ssid
->passphrase
, s
->passphrase
) != 0)
607 wpa_printf(MSG_DEBUG
, "P2P: Create a new persistent group "
610 s
= wpa_config_add_network(wpa_s
->conf
);
615 * Instead of network_added we emit persistent_group_added
616 * notification. Also to keep the defense checks in
617 * persistent_group obj registration method, we set the
618 * relevant flags in s to designate it as a persistent group.
621 s
->p2p_persistent_group
= 1;
622 wpas_notify_persistent_group_added(wpa_s
, s
);
623 wpa_config_set_network_defaults(s
);
627 s
->p2p_persistent_group
= 1;
630 os_memcpy(s
->bssid
, go_dev_addr
, ETH_ALEN
);
631 s
->mode
= ssid
->mode
;
632 s
->auth_alg
= WPA_AUTH_ALG_OPEN
;
633 s
->key_mgmt
= WPA_KEY_MGMT_PSK
;
634 s
->proto
= WPA_PROTO_RSN
;
635 s
->pairwise_cipher
= WPA_CIPHER_CCMP
;
637 if (ssid
->passphrase
) {
638 os_free(s
->passphrase
);
639 s
->passphrase
= os_strdup(ssid
->passphrase
);
643 os_memcpy(s
->psk
, ssid
->psk
, 32);
645 if (s
->passphrase
&& !s
->psk_set
)
646 wpa_config_update_psk(s
);
647 if (s
->ssid
== NULL
|| s
->ssid_len
< ssid
->ssid_len
) {
649 s
->ssid
= os_malloc(ssid
->ssid_len
);
652 s
->ssid_len
= ssid
->ssid_len
;
653 os_memcpy(s
->ssid
, ssid
->ssid
, s
->ssid_len
);
655 if (ssid
->mode
== WPAS_MODE_P2P_GO
&& wpa_s
->global
->add_psk
) {
656 dl_list_add(&s
->psk_list
, &wpa_s
->global
->add_psk
->list
);
657 wpa_s
->global
->add_psk
= NULL
;
661 #ifndef CONFIG_NO_CONFIG_WRITE
662 if (changed
&& wpa_s
->conf
->update_config
&&
663 wpa_config_write(wpa_s
->confname
, wpa_s
->conf
)) {
664 wpa_printf(MSG_DEBUG
, "P2P: Failed to update configuration");
666 #endif /* CONFIG_NO_CONFIG_WRITE */
672 static void wpas_p2p_add_persistent_group_client(struct wpa_supplicant
*wpa_s
,
675 struct wpa_ssid
*ssid
, *s
;
680 ssid
= wpa_s
->current_ssid
;
681 if (ssid
== NULL
|| ssid
->mode
!= WPAS_MODE_P2P_GO
||
682 !ssid
->p2p_persistent_group
)
685 for (s
= wpa_s
->parent
->conf
->ssid
; s
; s
= s
->next
) {
686 if (s
->disabled
!= 2 || s
->mode
!= WPAS_MODE_P2P_GO
)
689 if (s
->ssid_len
== ssid
->ssid_len
&&
690 os_memcmp(s
->ssid
, ssid
->ssid
, s
->ssid_len
) == 0)
697 for (i
= 0; s
->p2p_client_list
&& i
< s
->num_p2p_clients
; i
++) {
698 if (os_memcmp(s
->p2p_client_list
+ i
* ETH_ALEN
, addr
,
702 if (i
== s
->num_p2p_clients
- 1)
703 return; /* already the most recent entry */
705 /* move the entry to mark it most recent */
706 os_memmove(s
->p2p_client_list
+ i
* ETH_ALEN
,
707 s
->p2p_client_list
+ (i
+ 1) * ETH_ALEN
,
708 (s
->num_p2p_clients
- i
- 1) * ETH_ALEN
);
709 os_memcpy(s
->p2p_client_list
+
710 (s
->num_p2p_clients
- 1) * ETH_ALEN
, addr
, ETH_ALEN
);
715 if (!found
&& s
->num_p2p_clients
< P2P_MAX_STORED_CLIENTS
) {
716 n
= os_realloc_array(s
->p2p_client_list
,
717 s
->num_p2p_clients
+ 1, ETH_ALEN
);
720 os_memcpy(n
+ s
->num_p2p_clients
* ETH_ALEN
, addr
, ETH_ALEN
);
721 s
->p2p_client_list
= n
;
722 s
->num_p2p_clients
++;
724 /* Not enough room for an additional entry - drop the oldest
726 os_memmove(s
->p2p_client_list
,
727 s
->p2p_client_list
+ ETH_ALEN
,
728 (s
->num_p2p_clients
- 1) * ETH_ALEN
);
729 os_memcpy(s
->p2p_client_list
+
730 (s
->num_p2p_clients
- 1) * ETH_ALEN
,
734 #ifndef CONFIG_NO_CONFIG_WRITE
735 if (wpa_s
->parent
->conf
->update_config
&&
736 wpa_config_write(wpa_s
->parent
->confname
, wpa_s
->parent
->conf
))
737 wpa_printf(MSG_DEBUG
, "P2P: Failed to update configuration");
738 #endif /* CONFIG_NO_CONFIG_WRITE */
742 static void wpas_group_formation_completed(struct wpa_supplicant
*wpa_s
,
745 struct wpa_ssid
*ssid
;
746 const char *ssid_txt
;
749 u8 go_dev_addr
[ETH_ALEN
];
753 * This callback is likely called for the main interface. Update wpa_s
754 * to use the group interface if a new interface was created for the
757 if (wpa_s
->global
->p2p_group_formation
)
758 wpa_s
= wpa_s
->global
->p2p_group_formation
;
759 if (wpa_s
->p2p_go_group_formation_completed
) {
760 wpa_s
->global
->p2p_group_formation
= NULL
;
761 wpa_s
->p2p_in_provisioning
= 0;
765 wpa_msg_global(wpa_s
->parent
, MSG_INFO
,
766 P2P_EVENT_GROUP_FORMATION_FAILURE
);
767 wpas_p2p_group_delete(wpa_s
,
768 P2P_GROUP_REMOVAL_FORMATION_FAILED
);
772 wpa_msg_global(wpa_s
->parent
, MSG_INFO
,
773 P2P_EVENT_GROUP_FORMATION_SUCCESS
);
775 ssid
= wpa_s
->current_ssid
;
776 if (ssid
&& ssid
->mode
== WPAS_MODE_P2P_GROUP_FORMATION
) {
777 ssid
->mode
= WPAS_MODE_P2P_GO
;
778 p2p_group_notif_formation_done(wpa_s
->p2p_group
);
779 wpa_supplicant_ap_mac_addr_filter(wpa_s
, NULL
);
784 ssid_txt
= wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
);
785 client
= ssid
->mode
== WPAS_MODE_INFRA
;
786 if (ssid
->mode
== WPAS_MODE_P2P_GO
) {
787 persistent
= ssid
->p2p_persistent_group
;
788 os_memcpy(go_dev_addr
, wpa_s
->global
->p2p_dev_addr
,
791 persistent
= wpas_p2p_persistent_group(wpa_s
,
797 client
= wpa_s
->p2p_group_interface
==
798 P2P_GROUP_INTERFACE_CLIENT
;
799 os_memset(go_dev_addr
, 0, ETH_ALEN
);
802 wpa_s
->show_group_started
= 0;
805 * Indicate event only after successfully completed 4-way
806 * handshake, i.e., when the interface is ready for data
809 wpa_s
->show_group_started
= 1;
810 } else if (ssid
&& ssid
->passphrase
== NULL
&& ssid
->psk_set
) {
812 wpa_snprintf_hex(psk
, sizeof(psk
), ssid
->psk
, 32);
813 wpa_msg_global(wpa_s
->parent
, MSG_INFO
, P2P_EVENT_GROUP_STARTED
814 "%s GO ssid=\"%s\" freq=%d psk=%s go_dev_addr="
816 wpa_s
->ifname
, ssid_txt
, ssid
->frequency
, psk
,
817 MAC2STR(go_dev_addr
),
818 persistent
? " [PERSISTENT]" : "");
819 wpas_p2p_cross_connect_setup(wpa_s
);
820 wpas_p2p_set_group_idle_timeout(wpa_s
);
822 wpa_msg_global(wpa_s
->parent
, MSG_INFO
, P2P_EVENT_GROUP_STARTED
823 "%s GO ssid=\"%s\" freq=%d passphrase=\"%s\" "
824 "go_dev_addr=" MACSTR
"%s",
825 wpa_s
->ifname
, ssid_txt
,
826 ssid
? ssid
->frequency
: 0,
827 ssid
&& ssid
->passphrase
? ssid
->passphrase
: "",
828 MAC2STR(go_dev_addr
),
829 persistent
? " [PERSISTENT]" : "");
830 wpas_p2p_cross_connect_setup(wpa_s
);
831 wpas_p2p_set_group_idle_timeout(wpa_s
);
835 network_id
= wpas_p2p_store_persistent_group(wpa_s
->parent
,
838 os_free(wpa_s
->global
->add_psk
);
839 wpa_s
->global
->add_psk
= NULL
;
841 if (network_id
< 0 && ssid
)
842 network_id
= ssid
->id
;
844 wpas_notify_p2p_group_started(wpa_s
, ssid
, network_id
, 0);
845 os_get_time(&wpa_s
->global
->p2p_go_wait_client
);
850 static void wpas_p2p_send_action_tx_status(struct wpa_supplicant
*wpa_s
,
852 const u8
*dst
, const u8
*src
,
854 const u8
*data
, size_t data_len
,
855 enum offchannel_send_action_result
858 enum p2p_send_action_result res
= P2P_SEND_ACTION_SUCCESS
;
860 if (wpa_s
->global
->p2p
== NULL
|| wpa_s
->global
->p2p_disabled
)
862 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
)
866 case OFFCHANNEL_SEND_ACTION_SUCCESS
:
867 res
= P2P_SEND_ACTION_SUCCESS
;
869 case OFFCHANNEL_SEND_ACTION_NO_ACK
:
870 res
= P2P_SEND_ACTION_NO_ACK
;
872 case OFFCHANNEL_SEND_ACTION_FAILED
:
873 res
= P2P_SEND_ACTION_FAILED
;
877 p2p_send_action_cb(wpa_s
->global
->p2p
, freq
, dst
, src
, bssid
, res
);
879 if (result
!= OFFCHANNEL_SEND_ACTION_SUCCESS
&&
880 wpa_s
->pending_pd_before_join
&&
881 (os_memcmp(dst
, wpa_s
->pending_join_dev_addr
, ETH_ALEN
) == 0 ||
882 os_memcmp(dst
, wpa_s
->pending_join_iface_addr
, ETH_ALEN
) == 0) &&
883 wpa_s
->p2p_fallback_to_go_neg
) {
884 wpa_s
->pending_pd_before_join
= 0;
885 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: No ACK for PD Req "
886 "during p2p_connect-auto");
887 wpas_p2p_fallback_to_go_neg(wpa_s
, 0);
893 static int wpas_send_action(void *ctx
, unsigned int freq
, const u8
*dst
,
894 const u8
*src
, const u8
*bssid
, const u8
*buf
,
895 size_t len
, unsigned int wait_time
)
897 struct wpa_supplicant
*wpa_s
= ctx
;
898 return offchannel_send_action(wpa_s
, freq
, dst
, src
, bssid
, buf
, len
,
900 wpas_p2p_send_action_tx_status
, 1);
904 static void wpas_send_action_done(void *ctx
)
906 struct wpa_supplicant
*wpa_s
= ctx
;
907 offchannel_send_action_done(wpa_s
);
911 static int wpas_copy_go_neg_results(struct wpa_supplicant
*wpa_s
,
912 struct p2p_go_neg_results
*params
)
914 if (wpa_s
->go_params
== NULL
) {
915 wpa_s
->go_params
= os_malloc(sizeof(*params
));
916 if (wpa_s
->go_params
== NULL
)
919 os_memcpy(wpa_s
->go_params
, params
, sizeof(*params
));
924 static void wpas_start_wps_enrollee(struct wpa_supplicant
*wpa_s
,
925 struct p2p_go_neg_results
*res
)
927 wpa_printf(MSG_DEBUG
, "P2P: Start WPS Enrollee for peer " MACSTR
,
928 MAC2STR(res
->peer_interface_addr
));
929 wpa_hexdump_ascii(MSG_DEBUG
, "P2P: Start WPS Enrollee for SSID",
930 res
->ssid
, res
->ssid_len
);
931 wpa_supplicant_ap_deinit(wpa_s
);
932 wpas_copy_go_neg_results(wpa_s
, res
);
933 if (res
->wps_method
== WPS_PBC
)
934 wpas_wps_start_pbc(wpa_s
, res
->peer_interface_addr
, 1);
936 u16 dev_pw_id
= DEV_PW_DEFAULT
;
937 if (wpa_s
->p2p_wps_method
== WPS_PIN_KEYPAD
)
938 dev_pw_id
= DEV_PW_REGISTRAR_SPECIFIED
;
939 wpas_wps_start_pin(wpa_s
, res
->peer_interface_addr
,
940 wpa_s
->p2p_pin
, 1, dev_pw_id
);
945 static void wpas_p2p_add_psk_list(struct wpa_supplicant
*wpa_s
,
946 struct wpa_ssid
*ssid
)
948 struct wpa_ssid
*persistent
;
949 struct psk_list_entry
*psk
;
950 struct hostapd_data
*hapd
;
952 if (!wpa_s
->ap_iface
)
955 persistent
= wpas_p2p_get_persistent(wpa_s
->parent
, NULL
, ssid
->ssid
,
957 if (persistent
== NULL
)
960 hapd
= wpa_s
->ap_iface
->bss
[0];
962 dl_list_for_each(psk
, &persistent
->psk_list
, struct psk_list_entry
,
964 struct hostapd_wpa_psk
*hpsk
;
966 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Add persistent group PSK entry for "
968 MAC2STR(psk
->addr
), psk
->p2p
);
969 hpsk
= os_zalloc(sizeof(*hpsk
));
972 os_memcpy(hpsk
->psk
, psk
->psk
, PMK_LEN
);
974 os_memcpy(hpsk
->p2p_dev_addr
, psk
->addr
, ETH_ALEN
);
976 os_memcpy(hpsk
->addr
, psk
->addr
, ETH_ALEN
);
977 hpsk
->next
= hapd
->conf
->ssid
.wpa_psk
;
978 hapd
->conf
->ssid
.wpa_psk
= hpsk
;
983 static void p2p_go_configured(void *ctx
, void *data
)
985 struct wpa_supplicant
*wpa_s
= ctx
;
986 struct p2p_go_neg_results
*params
= data
;
987 struct wpa_ssid
*ssid
;
990 ssid
= wpa_s
->current_ssid
;
991 if (ssid
&& ssid
->mode
== WPAS_MODE_P2P_GO
) {
992 wpa_printf(MSG_DEBUG
, "P2P: Group setup without provisioning");
993 if (wpa_s
->global
->p2p_group_formation
== wpa_s
)
994 wpa_s
->global
->p2p_group_formation
= NULL
;
995 if (os_strlen(params
->passphrase
) > 0) {
996 wpa_msg_global(wpa_s
->parent
, MSG_INFO
,
997 P2P_EVENT_GROUP_STARTED
998 "%s GO ssid=\"%s\" freq=%d "
999 "passphrase=\"%s\" go_dev_addr=" MACSTR
1000 "%s", wpa_s
->ifname
,
1001 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
),
1002 ssid
->frequency
, params
->passphrase
,
1003 MAC2STR(wpa_s
->global
->p2p_dev_addr
),
1004 params
->persistent_group
?
1005 " [PERSISTENT]" : "");
1008 wpa_snprintf_hex(psk
, sizeof(psk
), params
->psk
,
1009 sizeof(params
->psk
));
1010 wpa_msg_global(wpa_s
->parent
, MSG_INFO
,
1011 P2P_EVENT_GROUP_STARTED
1012 "%s GO ssid=\"%s\" freq=%d psk=%s "
1013 "go_dev_addr=" MACSTR
"%s",
1015 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
),
1016 ssid
->frequency
, psk
,
1017 MAC2STR(wpa_s
->global
->p2p_dev_addr
),
1018 params
->persistent_group
?
1019 " [PERSISTENT]" : "");
1022 os_get_time(&wpa_s
->global
->p2p_go_wait_client
);
1023 if (params
->persistent_group
) {
1024 network_id
= wpas_p2p_store_persistent_group(
1025 wpa_s
->parent
, ssid
,
1026 wpa_s
->global
->p2p_dev_addr
);
1027 wpas_p2p_add_psk_list(wpa_s
, ssid
);
1030 network_id
= ssid
->id
;
1031 wpas_notify_p2p_group_started(wpa_s
, ssid
, network_id
, 0);
1032 wpas_p2p_cross_connect_setup(wpa_s
);
1033 wpas_p2p_set_group_idle_timeout(wpa_s
);
1035 if (wpa_s
->p2p_first_connection_timeout
) {
1036 wpa_dbg(wpa_s
, MSG_DEBUG
,
1037 "P2P: Start group formation timeout of %d seconds until first data connection on GO",
1038 wpa_s
->p2p_first_connection_timeout
);
1039 wpa_s
->p2p_go_group_formation_completed
= 0;
1040 wpa_s
->global
->p2p_group_formation
= wpa_s
;
1041 eloop_cancel_timeout(wpas_p2p_group_formation_timeout
,
1042 wpa_s
->parent
, NULL
);
1043 eloop_register_timeout(
1044 wpa_s
->p2p_first_connection_timeout
, 0,
1045 wpas_p2p_group_formation_timeout
,
1046 wpa_s
->parent
, NULL
);
1052 wpa_printf(MSG_DEBUG
, "P2P: Setting up WPS for GO provisioning");
1053 if (wpa_supplicant_ap_mac_addr_filter(wpa_s
,
1054 params
->peer_interface_addr
)) {
1055 wpa_printf(MSG_DEBUG
, "P2P: Failed to setup MAC address "
1059 if (params
->wps_method
== WPS_PBC
)
1060 wpa_supplicant_ap_wps_pbc(wpa_s
, params
->peer_interface_addr
,
1061 params
->peer_device_addr
);
1062 else if (wpa_s
->p2p_pin
[0])
1063 wpa_supplicant_ap_wps_pin(wpa_s
, params
->peer_interface_addr
,
1064 wpa_s
->p2p_pin
, NULL
, 0, 0);
1065 os_free(wpa_s
->go_params
);
1066 wpa_s
->go_params
= NULL
;
1070 static void wpas_start_wps_go(struct wpa_supplicant
*wpa_s
,
1071 struct p2p_go_neg_results
*params
,
1072 int group_formation
)
1074 struct wpa_ssid
*ssid
;
1076 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Starting GO");
1077 if (wpas_copy_go_neg_results(wpa_s
, params
) < 0) {
1078 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Could not copy GO Negotiation "
1083 ssid
= wpa_config_add_network(wpa_s
->conf
);
1085 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Could not add network for GO");
1089 wpa_s
->show_group_started
= 0;
1091 wpa_config_set_network_defaults(ssid
);
1092 ssid
->temporary
= 1;
1093 ssid
->p2p_group
= 1;
1094 ssid
->p2p_persistent_group
= params
->persistent_group
;
1095 ssid
->mode
= group_formation
? WPAS_MODE_P2P_GROUP_FORMATION
:
1097 ssid
->frequency
= params
->freq
;
1098 ssid
->ht40
= params
->ht40
;
1099 ssid
->vht
= params
->vht
;
1100 ssid
->ssid
= os_zalloc(params
->ssid_len
+ 1);
1102 os_memcpy(ssid
->ssid
, params
->ssid
, params
->ssid_len
);
1103 ssid
->ssid_len
= params
->ssid_len
;
1105 ssid
->auth_alg
= WPA_AUTH_ALG_OPEN
;
1106 ssid
->key_mgmt
= WPA_KEY_MGMT_PSK
;
1107 ssid
->proto
= WPA_PROTO_RSN
;
1108 ssid
->pairwise_cipher
= WPA_CIPHER_CCMP
;
1109 if (os_strlen(params
->passphrase
) > 0) {
1110 ssid
->passphrase
= os_strdup(params
->passphrase
);
1111 if (ssid
->passphrase
== NULL
) {
1112 wpa_msg_global(wpa_s
, MSG_ERROR
,
1113 "P2P: Failed to copy passphrase for GO");
1114 wpa_config_remove_network(wpa_s
->conf
, ssid
->id
);
1118 ssid
->passphrase
= NULL
;
1119 ssid
->psk_set
= params
->psk_set
;
1121 os_memcpy(ssid
->psk
, params
->psk
, sizeof(ssid
->psk
));
1122 else if (ssid
->passphrase
)
1123 wpa_config_update_psk(ssid
);
1124 ssid
->ap_max_inactivity
= wpa_s
->parent
->conf
->p2p_go_max_inactivity
;
1126 wpa_s
->ap_configured_cb
= p2p_go_configured
;
1127 wpa_s
->ap_configured_cb_ctx
= wpa_s
;
1128 wpa_s
->ap_configured_cb_data
= wpa_s
->go_params
;
1129 wpa_s
->connect_without_scan
= ssid
;
1130 wpa_s
->reassociate
= 1;
1131 wpa_s
->disconnected
= 0;
1132 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Request scan (that will be skipped) to "
1134 wpa_supplicant_req_scan(wpa_s
, 0, 0);
1138 static void wpas_p2p_clone_config(struct wpa_supplicant
*dst
,
1139 const struct wpa_supplicant
*src
)
1141 struct wpa_config
*d
;
1142 const struct wpa_config
*s
;
1147 #define C(n) if (s->n) d->n = os_strdup(s->n)
1156 os_memcpy(d
->device_type
, s
->device_type
, WPS_DEV_TYPE_LEN
);
1157 os_memcpy(d
->sec_device_type
, s
->sec_device_type
,
1158 sizeof(d
->sec_device_type
));
1159 d
->num_sec_device_types
= s
->num_sec_device_types
;
1161 d
->p2p_group_idle
= s
->p2p_group_idle
;
1162 d
->p2p_intra_bss
= s
->p2p_intra_bss
;
1163 d
->persistent_reconnect
= s
->persistent_reconnect
;
1164 d
->max_num_sta
= s
->max_num_sta
;
1165 d
->pbc_in_m1
= s
->pbc_in_m1
;
1166 d
->ignore_old_scan_res
= s
->ignore_old_scan_res
;
1167 d
->beacon_int
= s
->beacon_int
;
1168 d
->disassoc_low_ack
= s
->disassoc_low_ack
;
1169 d
->disable_scan_offload
= s
->disable_scan_offload
;
1173 static void wpas_p2p_get_group_ifname(struct wpa_supplicant
*wpa_s
,
1174 char *ifname
, size_t len
)
1176 char *ifname_ptr
= wpa_s
->ifname
;
1178 if (os_strncmp(wpa_s
->ifname
, P2P_MGMT_DEVICE_PREFIX
,
1179 os_strlen(P2P_MGMT_DEVICE_PREFIX
)) == 0) {
1180 ifname_ptr
= os_strrchr(wpa_s
->ifname
, '-') + 1;
1183 os_snprintf(ifname
, len
, "p2p-%s-%d", ifname_ptr
, wpa_s
->p2p_group_idx
);
1184 if (os_strlen(ifname
) >= IFNAMSIZ
&&
1185 os_strlen(wpa_s
->ifname
) < IFNAMSIZ
) {
1186 /* Try to avoid going over the IFNAMSIZ length limit */
1187 os_snprintf(ifname
, len
, "p2p-%d", wpa_s
->p2p_group_idx
);
1192 static int wpas_p2p_add_group_interface(struct wpa_supplicant
*wpa_s
,
1193 enum wpa_driver_if_type type
)
1195 char ifname
[120], force_ifname
[120];
1197 if (wpa_s
->pending_interface_name
[0]) {
1198 wpa_printf(MSG_DEBUG
, "P2P: Pending virtual interface exists "
1199 "- skip creation of a new one");
1200 if (is_zero_ether_addr(wpa_s
->pending_interface_addr
)) {
1201 wpa_printf(MSG_DEBUG
, "P2P: Pending virtual address "
1202 "unknown?! ifname='%s'",
1203 wpa_s
->pending_interface_name
);
1209 wpas_p2p_get_group_ifname(wpa_s
, ifname
, sizeof(ifname
));
1210 force_ifname
[0] = '\0';
1212 wpa_printf(MSG_DEBUG
, "P2P: Create a new interface %s for the group",
1214 wpa_s
->p2p_group_idx
++;
1216 wpa_s
->pending_interface_type
= type
;
1217 if (wpa_drv_if_add(wpa_s
, type
, ifname
, NULL
, NULL
, force_ifname
,
1218 wpa_s
->pending_interface_addr
, NULL
) < 0) {
1219 wpa_printf(MSG_ERROR
, "P2P: Failed to create new group "
1224 if (force_ifname
[0]) {
1225 wpa_printf(MSG_DEBUG
, "P2P: Driver forced interface name %s",
1227 os_strlcpy(wpa_s
->pending_interface_name
, force_ifname
,
1228 sizeof(wpa_s
->pending_interface_name
));
1230 os_strlcpy(wpa_s
->pending_interface_name
, ifname
,
1231 sizeof(wpa_s
->pending_interface_name
));
1232 wpa_printf(MSG_DEBUG
, "P2P: Created pending virtual interface %s addr "
1233 MACSTR
, wpa_s
->pending_interface_name
,
1234 MAC2STR(wpa_s
->pending_interface_addr
));
1240 static void wpas_p2p_remove_pending_group_interface(
1241 struct wpa_supplicant
*wpa_s
)
1243 if (!wpa_s
->pending_interface_name
[0] ||
1244 is_zero_ether_addr(wpa_s
->pending_interface_addr
))
1245 return; /* No pending virtual interface */
1247 wpa_printf(MSG_DEBUG
, "P2P: Removing pending group interface %s",
1248 wpa_s
->pending_interface_name
);
1249 wpa_drv_if_remove(wpa_s
, wpa_s
->pending_interface_type
,
1250 wpa_s
->pending_interface_name
);
1251 os_memset(wpa_s
->pending_interface_addr
, 0, ETH_ALEN
);
1252 wpa_s
->pending_interface_name
[0] = '\0';
1256 static struct wpa_supplicant
*
1257 wpas_p2p_init_group_interface(struct wpa_supplicant
*wpa_s
, int go
)
1259 struct wpa_interface iface
;
1260 struct wpa_supplicant
*group_wpa_s
;
1262 if (!wpa_s
->pending_interface_name
[0]) {
1263 wpa_printf(MSG_ERROR
, "P2P: No pending group interface");
1264 if (!wpas_p2p_create_iface(wpa_s
))
1267 * Something has forced us to remove the pending interface; try
1268 * to create a new one and hope for the best that we will get
1269 * the same local address.
1271 if (wpas_p2p_add_group_interface(wpa_s
, go
? WPA_IF_P2P_GO
:
1272 WPA_IF_P2P_CLIENT
) < 0)
1276 os_memset(&iface
, 0, sizeof(iface
));
1277 iface
.ifname
= wpa_s
->pending_interface_name
;
1278 iface
.driver
= wpa_s
->driver
->name
;
1279 if (wpa_s
->conf
->ctrl_interface
== NULL
&&
1280 wpa_s
->parent
!= wpa_s
&&
1282 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE
))
1283 iface
.ctrl_interface
= wpa_s
->parent
->conf
->ctrl_interface
;
1285 iface
.ctrl_interface
= wpa_s
->conf
->ctrl_interface
;
1286 iface
.driver_param
= wpa_s
->conf
->driver_param
;
1287 group_wpa_s
= wpa_supplicant_add_iface(wpa_s
->global
, &iface
);
1288 if (group_wpa_s
== NULL
) {
1289 wpa_printf(MSG_ERROR
, "P2P: Failed to create new "
1290 "wpa_supplicant interface");
1293 wpa_s
->pending_interface_name
[0] = '\0';
1294 group_wpa_s
->parent
= wpa_s
;
1295 group_wpa_s
->p2p_group_interface
= go
? P2P_GROUP_INTERFACE_GO
:
1296 P2P_GROUP_INTERFACE_CLIENT
;
1297 wpa_s
->global
->p2p_group_formation
= group_wpa_s
;
1299 wpas_p2p_clone_config(group_wpa_s
, wpa_s
);
1305 static void wpas_p2p_group_formation_timeout(void *eloop_ctx
,
1308 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
1309 wpa_printf(MSG_DEBUG
, "P2P: Group Formation timed out");
1310 wpas_p2p_group_formation_failed(wpa_s
);
1314 void wpas_p2p_group_formation_failed(struct wpa_supplicant
*wpa_s
)
1316 eloop_cancel_timeout(wpas_p2p_group_formation_timeout
,
1317 wpa_s
->parent
, NULL
);
1318 if (wpa_s
->global
->p2p
)
1319 p2p_group_formation_failed(wpa_s
->global
->p2p
);
1320 else if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
)
1321 wpa_drv_p2p_group_formation_failed(wpa_s
);
1322 wpas_group_formation_completed(wpa_s
, 0);
1326 void wpas_p2p_ap_setup_failed(struct wpa_supplicant
*wpa_s
)
1328 if (wpa_s
->global
->p2p_group_formation
!= wpa_s
)
1330 /* Speed up group formation timeout since this cannot succeed */
1331 eloop_cancel_timeout(wpas_p2p_group_formation_timeout
,
1332 wpa_s
->parent
, NULL
);
1333 eloop_register_timeout(0, 0, wpas_p2p_group_formation_timeout
,
1334 wpa_s
->parent
, NULL
);
1338 void wpas_go_neg_completed(void *ctx
, struct p2p_go_neg_results
*res
)
1340 struct wpa_supplicant
*wpa_s
= ctx
;
1342 if (wpa_s
->off_channel_freq
|| wpa_s
->roc_waiting_drv_freq
) {
1343 wpa_drv_cancel_remain_on_channel(wpa_s
);
1344 wpa_s
->off_channel_freq
= 0;
1345 wpa_s
->roc_waiting_drv_freq
= 0;
1349 wpa_msg_global(wpa_s
, MSG_INFO
,
1350 P2P_EVENT_GO_NEG_FAILURE
"status=%d",
1352 wpas_notify_p2p_go_neg_completed(wpa_s
, res
);
1353 wpas_p2p_remove_pending_group_interface(wpa_s
);
1357 if (wpa_s
->p2p_go_ht40
)
1359 if (wpa_s
->p2p_go_vht
)
1362 wpa_msg_global(wpa_s
, MSG_INFO
, P2P_EVENT_GO_NEG_SUCCESS
"role=%s "
1363 "freq=%d ht40=%d peer_dev=" MACSTR
" peer_iface=" MACSTR
1365 res
->role_go
? "GO" : "client", res
->freq
, res
->ht40
,
1366 MAC2STR(res
->peer_device_addr
),
1367 MAC2STR(res
->peer_interface_addr
),
1368 p2p_wps_method_text(res
->wps_method
));
1369 wpas_notify_p2p_go_neg_completed(wpa_s
, res
);
1371 if (res
->role_go
&& wpa_s
->p2p_persistent_id
>= 0) {
1372 struct wpa_ssid
*ssid
;
1373 ssid
= wpa_config_get_network(wpa_s
->conf
,
1374 wpa_s
->p2p_persistent_id
);
1375 if (ssid
&& ssid
->disabled
== 2 &&
1376 ssid
->mode
== WPAS_MODE_P2P_GO
&& ssid
->passphrase
) {
1377 size_t len
= os_strlen(ssid
->passphrase
);
1378 wpa_printf(MSG_DEBUG
, "P2P: Override passphrase based "
1379 "on requested persistent group");
1380 os_memcpy(res
->passphrase
, ssid
->passphrase
, len
);
1381 res
->passphrase
[len
] = '\0';
1385 if (wpa_s
->create_p2p_iface
) {
1386 struct wpa_supplicant
*group_wpa_s
=
1387 wpas_p2p_init_group_interface(wpa_s
, res
->role_go
);
1388 if (group_wpa_s
== NULL
) {
1389 wpas_p2p_remove_pending_group_interface(wpa_s
);
1392 if (group_wpa_s
!= wpa_s
) {
1393 os_memcpy(group_wpa_s
->p2p_pin
, wpa_s
->p2p_pin
,
1394 sizeof(group_wpa_s
->p2p_pin
));
1395 group_wpa_s
->p2p_wps_method
= wpa_s
->p2p_wps_method
;
1397 os_memset(wpa_s
->pending_interface_addr
, 0, ETH_ALEN
);
1398 wpa_s
->pending_interface_name
[0] = '\0';
1399 group_wpa_s
->p2p_in_provisioning
= 1;
1402 wpas_start_wps_go(group_wpa_s
, res
, 1);
1404 wpas_start_wps_enrollee(group_wpa_s
, res
);
1406 wpa_s
->p2p_in_provisioning
= 1;
1407 wpa_s
->global
->p2p_group_formation
= wpa_s
;
1410 wpas_start_wps_go(wpa_s
, res
, 1);
1412 wpas_start_wps_enrollee(ctx
, res
);
1415 wpa_s
->p2p_long_listen
= 0;
1416 eloop_cancel_timeout(wpas_p2p_long_listen_timeout
, wpa_s
, NULL
);
1418 eloop_cancel_timeout(wpas_p2p_group_formation_timeout
, wpa_s
, NULL
);
1419 eloop_register_timeout(15 + res
->peer_config_timeout
/ 100,
1420 (res
->peer_config_timeout
% 100) * 10000,
1421 wpas_p2p_group_formation_timeout
, wpa_s
, NULL
);
1425 void wpas_go_neg_req_rx(void *ctx
, const u8
*src
, u16 dev_passwd_id
)
1427 struct wpa_supplicant
*wpa_s
= ctx
;
1428 wpa_msg_global(wpa_s
, MSG_INFO
, P2P_EVENT_GO_NEG_REQUEST MACSTR
1429 " dev_passwd_id=%u", MAC2STR(src
), dev_passwd_id
);
1431 wpas_notify_p2p_go_neg_req(wpa_s
, src
, dev_passwd_id
);
1435 void wpas_dev_found(void *ctx
, const u8
*addr
,
1436 const struct p2p_peer_info
*info
,
1439 #ifndef CONFIG_NO_STDOUT_DEBUG
1440 struct wpa_supplicant
*wpa_s
= ctx
;
1441 char devtype
[WPS_DEV_TYPE_BUFSIZE
];
1443 wpa_msg_global(wpa_s
, MSG_INFO
, P2P_EVENT_DEVICE_FOUND MACSTR
1444 " p2p_dev_addr=" MACSTR
1445 " pri_dev_type=%s name='%s' config_methods=0x%x "
1446 "dev_capab=0x%x group_capab=0x%x",
1447 MAC2STR(addr
), MAC2STR(info
->p2p_device_addr
),
1448 wps_dev_type_bin2str(info
->pri_dev_type
, devtype
,
1450 info
->device_name
, info
->config_methods
,
1451 info
->dev_capab
, info
->group_capab
);
1452 #endif /* CONFIG_NO_STDOUT_DEBUG */
1454 wpas_notify_p2p_device_found(ctx
, info
->p2p_device_addr
, new_device
);
1458 static void wpas_dev_lost(void *ctx
, const u8
*dev_addr
)
1460 struct wpa_supplicant
*wpa_s
= ctx
;
1462 wpa_msg_global(wpa_s
, MSG_INFO
, P2P_EVENT_DEVICE_LOST
1463 "p2p_dev_addr=" MACSTR
, MAC2STR(dev_addr
));
1465 wpas_notify_p2p_device_lost(wpa_s
, dev_addr
);
1469 static void wpas_find_stopped(void *ctx
)
1471 struct wpa_supplicant
*wpa_s
= ctx
;
1472 wpa_msg_global(wpa_s
, MSG_INFO
, P2P_EVENT_FIND_STOPPED
);
1476 static int wpas_start_listen(void *ctx
, unsigned int freq
,
1477 unsigned int duration
,
1478 const struct wpabuf
*probe_resp_ie
)
1480 struct wpa_supplicant
*wpa_s
= ctx
;
1482 wpa_drv_set_ap_wps_ie(wpa_s
, NULL
, probe_resp_ie
, NULL
);
1484 if (wpa_drv_probe_req_report(wpa_s
, 1) < 0) {
1485 wpa_printf(MSG_DEBUG
, "P2P: Failed to request the driver to "
1486 "report received Probe Request frames");
1490 wpa_s
->pending_listen_freq
= freq
;
1491 wpa_s
->pending_listen_duration
= duration
;
1493 if (wpa_drv_remain_on_channel(wpa_s
, freq
, duration
) < 0) {
1494 wpa_printf(MSG_DEBUG
, "P2P: Failed to request the driver "
1495 "to remain on channel (%u MHz) for Listen "
1497 wpa_s
->pending_listen_freq
= 0;
1500 wpa_s
->off_channel_freq
= 0;
1501 wpa_s
->roc_waiting_drv_freq
= freq
;
1507 static void wpas_stop_listen(void *ctx
)
1509 struct wpa_supplicant
*wpa_s
= ctx
;
1510 if (wpa_s
->off_channel_freq
|| wpa_s
->roc_waiting_drv_freq
) {
1511 wpa_drv_cancel_remain_on_channel(wpa_s
);
1512 wpa_s
->off_channel_freq
= 0;
1513 wpa_s
->roc_waiting_drv_freq
= 0;
1515 wpa_drv_set_ap_wps_ie(wpa_s
, NULL
, NULL
, NULL
);
1516 wpa_drv_probe_req_report(wpa_s
, 0);
1520 static int wpas_send_probe_resp(void *ctx
, const struct wpabuf
*buf
)
1522 struct wpa_supplicant
*wpa_s
= ctx
;
1523 return wpa_drv_send_mlme(wpa_s
, wpabuf_head(buf
), wpabuf_len(buf
), 1);
1528 * DNS Header section is used only to calculate compression pointers, so the
1529 * contents of this data does not matter, but the length needs to be reserved
1530 * in the virtual packet.
1532 #define DNS_HEADER_LEN 12
1535 * 27-octet in-memory packet from P2P specification containing two implied
1536 * queries for _tcp.lcoal. PTR IN and _udp.local. PTR IN
1538 #define P2P_SD_IN_MEMORY_LEN 27
1540 static int p2p_sd_dns_uncompress_label(char **upos
, char *uend
, u8
*start
,
1541 u8
**spos
, const u8
*end
)
1543 while (*spos
< end
) {
1544 u8 val
= ((*spos
)[0] & 0xc0) >> 6;
1547 if (val
== 1 || val
== 2) {
1548 /* These are reserved values in RFC 1035 */
1549 wpa_printf(MSG_DEBUG
, "P2P: Invalid domain name "
1550 "sequence starting with 0x%x", val
);
1559 if (*spos
+ 2 > end
) {
1560 wpa_printf(MSG_DEBUG
, "P2P: No room for full "
1561 "DNS offset field");
1565 offset
= (((*spos
)[0] & 0x3f) << 8) | (*spos
)[1];
1566 if (offset
>= *spos
- start
) {
1567 wpa_printf(MSG_DEBUG
, "P2P: Invalid DNS "
1568 "pointer offset %u", offset
);
1573 spos_tmp
= start
+ offset
;
1574 return p2p_sd_dns_uncompress_label(upos
, uend
, start
,
1580 len
= (*spos
)[0] & 0x3f;
1585 if (*spos
+ len
> end
) {
1586 wpa_printf(MSG_DEBUG
, "P2P: Invalid domain name "
1587 "sequence - no room for label with length "
1592 if (*upos
+ len
+ 2 > uend
)
1595 os_memcpy(*upos
, *spos
, len
);
1607 /* Uncompress domain names per RFC 1035 using the P2P SD in-memory packet.
1608 * Returns -1 on parsing error (invalid input sequence), -2 if output buffer is
1609 * not large enough */
1610 static int p2p_sd_dns_uncompress(char *buf
, size_t buf_len
, const u8
*msg
,
1611 size_t msg_len
, size_t offset
)
1613 /* 27-octet in-memory packet from P2P specification */
1614 const char *prefix
= "\x04_tcp\x05local\x00\x00\x0C\x00\x01"
1615 "\x04_udp\xC0\x11\x00\x0C\x00\x01";
1616 u8
*tmp
, *end
, *spos
;
1622 if (offset
> msg_len
)
1625 tmp
= os_malloc(DNS_HEADER_LEN
+ P2P_SD_IN_MEMORY_LEN
+ msg_len
);
1628 spos
= tmp
+ DNS_HEADER_LEN
+ P2P_SD_IN_MEMORY_LEN
;
1629 end
= spos
+ msg_len
;
1632 os_memset(tmp
, 0, DNS_HEADER_LEN
);
1633 os_memcpy(tmp
+ DNS_HEADER_LEN
, prefix
, P2P_SD_IN_MEMORY_LEN
);
1634 os_memcpy(tmp
+ DNS_HEADER_LEN
+ P2P_SD_IN_MEMORY_LEN
, msg
, msg_len
);
1637 uend
= buf
+ buf_len
;
1639 ret
= p2p_sd_dns_uncompress_label(&upos
, uend
, tmp
, &spos
, end
);
1648 } else if (upos
[-1] == '.')
1656 static struct p2p_srv_bonjour
*
1657 wpas_p2p_service_get_bonjour(struct wpa_supplicant
*wpa_s
,
1658 const struct wpabuf
*query
)
1660 struct p2p_srv_bonjour
*bsrv
;
1663 len
= wpabuf_len(query
);
1664 dl_list_for_each(bsrv
, &wpa_s
->global
->p2p_srv_bonjour
,
1665 struct p2p_srv_bonjour
, list
) {
1666 if (len
== wpabuf_len(bsrv
->query
) &&
1667 os_memcmp(wpabuf_head(query
), wpabuf_head(bsrv
->query
),
1675 static struct p2p_srv_upnp
*
1676 wpas_p2p_service_get_upnp(struct wpa_supplicant
*wpa_s
, u8 version
,
1677 const char *service
)
1679 struct p2p_srv_upnp
*usrv
;
1681 dl_list_for_each(usrv
, &wpa_s
->global
->p2p_srv_upnp
,
1682 struct p2p_srv_upnp
, list
) {
1683 if (version
== usrv
->version
&&
1684 os_strcmp(service
, usrv
->service
) == 0)
1691 static void wpas_sd_add_proto_not_avail(struct wpabuf
*resp
, u8 srv_proto
,
1696 if (wpabuf_tailroom(resp
) < 5)
1699 /* Length (to be filled) */
1700 len_pos
= wpabuf_put(resp
, 2);
1701 wpabuf_put_u8(resp
, srv_proto
);
1702 wpabuf_put_u8(resp
, srv_trans_id
);
1704 wpabuf_put_u8(resp
, P2P_SD_PROTO_NOT_AVAILABLE
);
1705 /* Response Data: empty */
1706 WPA_PUT_LE16(len_pos
, (u8
*) wpabuf_put(resp
, 0) - len_pos
- 2);
1710 static void wpas_sd_all_bonjour(struct wpa_supplicant
*wpa_s
,
1711 struct wpabuf
*resp
, u8 srv_trans_id
)
1713 struct p2p_srv_bonjour
*bsrv
;
1716 wpa_printf(MSG_DEBUG
, "P2P: SD Request for all Bonjour services");
1718 if (dl_list_empty(&wpa_s
->global
->p2p_srv_bonjour
)) {
1719 wpa_printf(MSG_DEBUG
, "P2P: Bonjour protocol not available");
1723 dl_list_for_each(bsrv
, &wpa_s
->global
->p2p_srv_bonjour
,
1724 struct p2p_srv_bonjour
, list
) {
1725 if (wpabuf_tailroom(resp
) <
1726 5 + wpabuf_len(bsrv
->query
) + wpabuf_len(bsrv
->resp
))
1728 /* Length (to be filled) */
1729 len_pos
= wpabuf_put(resp
, 2);
1730 wpabuf_put_u8(resp
, P2P_SERV_BONJOUR
);
1731 wpabuf_put_u8(resp
, srv_trans_id
);
1733 wpabuf_put_u8(resp
, P2P_SD_SUCCESS
);
1734 wpa_hexdump_ascii(MSG_DEBUG
, "P2P: Matching Bonjour service",
1735 wpabuf_head(bsrv
->resp
),
1736 wpabuf_len(bsrv
->resp
));
1738 wpabuf_put_buf(resp
, bsrv
->query
); /* Key */
1739 wpabuf_put_buf(resp
, bsrv
->resp
); /* Value */
1740 WPA_PUT_LE16(len_pos
, (u8
*) wpabuf_put(resp
, 0) - len_pos
-
1746 static int match_bonjour_query(struct p2p_srv_bonjour
*bsrv
, const u8
*query
,
1749 char str_rx
[256], str_srv
[256];
1751 if (query_len
< 3 || wpabuf_len(bsrv
->query
) < 3)
1752 return 0; /* Too short to include DNS Type and Version */
1753 if (os_memcmp(query
+ query_len
- 3,
1754 wpabuf_head_u8(bsrv
->query
) + wpabuf_len(bsrv
->query
) - 3,
1756 return 0; /* Mismatch in DNS Type or Version */
1757 if (query_len
== wpabuf_len(bsrv
->query
) &&
1758 os_memcmp(query
, wpabuf_head(bsrv
->query
), query_len
- 3) == 0)
1759 return 1; /* Binary match */
1761 if (p2p_sd_dns_uncompress(str_rx
, sizeof(str_rx
), query
, query_len
- 3,
1763 return 0; /* Failed to uncompress query */
1764 if (p2p_sd_dns_uncompress(str_srv
, sizeof(str_srv
),
1765 wpabuf_head(bsrv
->query
),
1766 wpabuf_len(bsrv
->query
) - 3, 0))
1767 return 0; /* Failed to uncompress service */
1769 return os_strcmp(str_rx
, str_srv
) == 0;
1773 static void wpas_sd_req_bonjour(struct wpa_supplicant
*wpa_s
,
1774 struct wpabuf
*resp
, u8 srv_trans_id
,
1775 const u8
*query
, size_t query_len
)
1777 struct p2p_srv_bonjour
*bsrv
;
1781 wpa_hexdump_ascii(MSG_DEBUG
, "P2P: SD Request for Bonjour",
1783 if (dl_list_empty(&wpa_s
->global
->p2p_srv_bonjour
)) {
1784 wpa_printf(MSG_DEBUG
, "P2P: Bonjour protocol not available");
1785 wpas_sd_add_proto_not_avail(resp
, P2P_SERV_BONJOUR
,
1790 if (query_len
== 0) {
1791 wpas_sd_all_bonjour(wpa_s
, resp
, srv_trans_id
);
1795 dl_list_for_each(bsrv
, &wpa_s
->global
->p2p_srv_bonjour
,
1796 struct p2p_srv_bonjour
, list
) {
1797 if (!match_bonjour_query(bsrv
, query
, query_len
))
1800 if (wpabuf_tailroom(resp
) <
1801 5 + query_len
+ wpabuf_len(bsrv
->resp
))
1806 /* Length (to be filled) */
1807 len_pos
= wpabuf_put(resp
, 2);
1808 wpabuf_put_u8(resp
, P2P_SERV_BONJOUR
);
1809 wpabuf_put_u8(resp
, srv_trans_id
);
1812 wpabuf_put_u8(resp
, P2P_SD_SUCCESS
);
1813 wpa_hexdump_ascii(MSG_DEBUG
, "P2P: Matching Bonjour service",
1814 wpabuf_head(bsrv
->resp
),
1815 wpabuf_len(bsrv
->resp
));
1818 wpabuf_put_data(resp
, query
, query_len
); /* Key */
1819 wpabuf_put_buf(resp
, bsrv
->resp
); /* Value */
1821 WPA_PUT_LE16(len_pos
, (u8
*) wpabuf_put(resp
, 0) - len_pos
- 2);
1825 wpa_printf(MSG_DEBUG
, "P2P: Requested Bonjour service not "
1827 if (wpabuf_tailroom(resp
) < 5)
1830 /* Length (to be filled) */
1831 len_pos
= wpabuf_put(resp
, 2);
1832 wpabuf_put_u8(resp
, P2P_SERV_BONJOUR
);
1833 wpabuf_put_u8(resp
, srv_trans_id
);
1836 wpabuf_put_u8(resp
, P2P_SD_REQUESTED_INFO_NOT_AVAILABLE
);
1837 /* Response Data: empty */
1838 WPA_PUT_LE16(len_pos
, (u8
*) wpabuf_put(resp
, 0) - len_pos
-
1844 static void wpas_sd_all_upnp(struct wpa_supplicant
*wpa_s
,
1845 struct wpabuf
*resp
, u8 srv_trans_id
)
1847 struct p2p_srv_upnp
*usrv
;
1850 wpa_printf(MSG_DEBUG
, "P2P: SD Request for all UPnP services");
1852 if (dl_list_empty(&wpa_s
->global
->p2p_srv_upnp
)) {
1853 wpa_printf(MSG_DEBUG
, "P2P: UPnP protocol not available");
1857 dl_list_for_each(usrv
, &wpa_s
->global
->p2p_srv_upnp
,
1858 struct p2p_srv_upnp
, list
) {
1859 if (wpabuf_tailroom(resp
) < 5 + 1 + os_strlen(usrv
->service
))
1862 /* Length (to be filled) */
1863 len_pos
= wpabuf_put(resp
, 2);
1864 wpabuf_put_u8(resp
, P2P_SERV_UPNP
);
1865 wpabuf_put_u8(resp
, srv_trans_id
);
1868 wpabuf_put_u8(resp
, P2P_SD_SUCCESS
);
1870 wpabuf_put_u8(resp
, usrv
->version
);
1871 wpa_printf(MSG_DEBUG
, "P2P: Matching UPnP Service: %s",
1873 wpabuf_put_str(resp
, usrv
->service
);
1874 WPA_PUT_LE16(len_pos
, (u8
*) wpabuf_put(resp
, 0) - len_pos
-
1880 static void wpas_sd_req_upnp(struct wpa_supplicant
*wpa_s
,
1881 struct wpabuf
*resp
, u8 srv_trans_id
,
1882 const u8
*query
, size_t query_len
)
1884 struct p2p_srv_upnp
*usrv
;
1890 wpa_hexdump_ascii(MSG_DEBUG
, "P2P: SD Request for UPnP",
1893 if (dl_list_empty(&wpa_s
->global
->p2p_srv_upnp
)) {
1894 wpa_printf(MSG_DEBUG
, "P2P: UPnP protocol not available");
1895 wpas_sd_add_proto_not_avail(resp
, P2P_SERV_UPNP
,
1900 if (query_len
== 0) {
1901 wpas_sd_all_upnp(wpa_s
, resp
, srv_trans_id
);
1905 if (wpabuf_tailroom(resp
) < 5)
1908 /* Length (to be filled) */
1909 len_pos
= wpabuf_put(resp
, 2);
1910 wpabuf_put_u8(resp
, P2P_SERV_UPNP
);
1911 wpabuf_put_u8(resp
, srv_trans_id
);
1914 str
= os_malloc(query_len
);
1917 os_memcpy(str
, query
+ 1, query_len
- 1);
1918 str
[query_len
- 1] = '\0';
1920 dl_list_for_each(usrv
, &wpa_s
->global
->p2p_srv_upnp
,
1921 struct p2p_srv_upnp
, list
) {
1922 if (version
!= usrv
->version
)
1925 if (os_strcmp(str
, "ssdp:all") != 0 &&
1926 os_strstr(usrv
->service
, str
) == NULL
)
1929 if (wpabuf_tailroom(resp
) < 2)
1933 wpabuf_put_u8(resp
, P2P_SD_SUCCESS
);
1935 wpabuf_put_u8(resp
, version
);
1937 wpabuf_put_u8(resp
, ',');
1941 wpa_printf(MSG_DEBUG
, "P2P: Matching UPnP Service: %s",
1943 if (wpabuf_tailroom(resp
) < os_strlen(usrv
->service
))
1945 wpabuf_put_str(resp
, usrv
->service
);
1950 wpa_printf(MSG_DEBUG
, "P2P: Requested UPnP service not "
1953 wpabuf_put_u8(resp
, P2P_SD_REQUESTED_INFO_NOT_AVAILABLE
);
1954 /* Response Data: empty */
1957 WPA_PUT_LE16(len_pos
, (u8
*) wpabuf_put(resp
, 0) - len_pos
- 2);
1961 #ifdef CONFIG_WIFI_DISPLAY
1962 static void wpas_sd_req_wfd(struct wpa_supplicant
*wpa_s
,
1963 struct wpabuf
*resp
, u8 srv_trans_id
,
1964 const u8
*query
, size_t query_len
)
1970 wpa_hexdump(MSG_DEBUG
, "P2P: SD Request for WFD", query
, query_len
);
1972 if (!wpa_s
->global
->wifi_display
) {
1973 wpa_printf(MSG_DEBUG
, "P2P: WFD protocol not available");
1974 wpas_sd_add_proto_not_avail(resp
, P2P_SERV_WIFI_DISPLAY
,
1979 if (query_len
< 1) {
1980 wpa_printf(MSG_DEBUG
, "P2P: Missing WFD Requested Device "
1985 if (wpabuf_tailroom(resp
) < 5)
1990 wpa_printf(MSG_DEBUG
, "P2P: WSD for device role 0x%x", role
);
1992 /* TODO: role specific handling */
1994 /* Length (to be filled) */
1995 len_pos
= wpabuf_put(resp
, 2);
1996 wpabuf_put_u8(resp
, P2P_SERV_WIFI_DISPLAY
);
1997 wpabuf_put_u8(resp
, srv_trans_id
);
1998 wpabuf_put_u8(resp
, P2P_SD_SUCCESS
); /* Status Code */
2000 while (pos
< query
+ query_len
) {
2001 if (*pos
< MAX_WFD_SUBELEMS
&&
2002 wpa_s
->global
->wfd_subelem
[*pos
] &&
2003 wpabuf_tailroom(resp
) >=
2004 wpabuf_len(wpa_s
->global
->wfd_subelem
[*pos
])) {
2005 wpa_printf(MSG_DEBUG
, "P2P: Add WSD response "
2006 "subelement %u", *pos
);
2007 wpabuf_put_buf(resp
, wpa_s
->global
->wfd_subelem
[*pos
]);
2012 WPA_PUT_LE16(len_pos
, (u8
*) wpabuf_put(resp
, 0) - len_pos
- 2);
2014 #endif /* CONFIG_WIFI_DISPLAY */
2017 void wpas_sd_request(void *ctx
, int freq
, const u8
*sa
, u8 dialog_token
,
2018 u16 update_indic
, const u8
*tlvs
, size_t tlvs_len
)
2020 struct wpa_supplicant
*wpa_s
= ctx
;
2021 const u8
*pos
= tlvs
;
2022 const u8
*end
= tlvs
+ tlvs_len
;
2025 struct wpabuf
*resp
;
2026 u8 srv_proto
, srv_trans_id
;
2030 wpa_hexdump(MSG_MSGDUMP
, "P2P: Service Discovery Request TLVs",
2032 buf_len
= 2 * tlvs_len
+ 1;
2033 buf
= os_malloc(buf_len
);
2035 wpa_snprintf_hex(buf
, buf_len
, tlvs
, tlvs_len
);
2036 wpa_msg_ctrl(wpa_s
, MSG_INFO
, P2P_EVENT_SERV_DISC_REQ
"%d "
2038 freq
, MAC2STR(sa
), dialog_token
, update_indic
,
2043 if (wpa_s
->p2p_sd_over_ctrl_iface
) {
2044 wpas_notify_p2p_sd_request(wpa_s
, freq
, sa
, dialog_token
,
2045 update_indic
, tlvs
, tlvs_len
);
2046 return; /* to be processed by an external program */
2049 resp
= wpabuf_alloc(10000);
2053 while (pos
+ 1 < end
) {
2054 wpa_printf(MSG_DEBUG
, "P2P: Service Request TLV");
2055 slen
= WPA_GET_LE16(pos
);
2057 if (pos
+ slen
> end
|| slen
< 2) {
2058 wpa_printf(MSG_DEBUG
, "P2P: Unexpected Query Data "
2063 tlv_end
= pos
+ slen
;
2066 wpa_printf(MSG_DEBUG
, "P2P: Service Protocol Type %u",
2068 srv_trans_id
= *pos
++;
2069 wpa_printf(MSG_DEBUG
, "P2P: Service Transaction ID %u",
2072 wpa_hexdump(MSG_MSGDUMP
, "P2P: Query Data",
2073 pos
, tlv_end
- pos
);
2076 if (wpa_s
->force_long_sd
) {
2077 wpa_printf(MSG_DEBUG
, "P2P: SD test - force long "
2079 wpas_sd_all_bonjour(wpa_s
, resp
, srv_trans_id
);
2080 wpas_sd_all_upnp(wpa_s
, resp
, srv_trans_id
);
2084 switch (srv_proto
) {
2085 case P2P_SERV_ALL_SERVICES
:
2086 wpa_printf(MSG_DEBUG
, "P2P: Service Discovery Request "
2087 "for all services");
2088 if (dl_list_empty(&wpa_s
->global
->p2p_srv_upnp
) &&
2089 dl_list_empty(&wpa_s
->global
->p2p_srv_bonjour
)) {
2090 wpa_printf(MSG_DEBUG
, "P2P: No service "
2091 "discovery protocols available");
2092 wpas_sd_add_proto_not_avail(
2093 resp
, P2P_SERV_ALL_SERVICES
,
2097 wpas_sd_all_bonjour(wpa_s
, resp
, srv_trans_id
);
2098 wpas_sd_all_upnp(wpa_s
, resp
, srv_trans_id
);
2100 case P2P_SERV_BONJOUR
:
2101 wpas_sd_req_bonjour(wpa_s
, resp
, srv_trans_id
,
2102 pos
, tlv_end
- pos
);
2105 wpas_sd_req_upnp(wpa_s
, resp
, srv_trans_id
,
2106 pos
, tlv_end
- pos
);
2108 #ifdef CONFIG_WIFI_DISPLAY
2109 case P2P_SERV_WIFI_DISPLAY
:
2110 wpas_sd_req_wfd(wpa_s
, resp
, srv_trans_id
,
2111 pos
, tlv_end
- pos
);
2113 #endif /* CONFIG_WIFI_DISPLAY */
2115 wpa_printf(MSG_DEBUG
, "P2P: Unavailable service "
2116 "protocol %u", srv_proto
);
2117 wpas_sd_add_proto_not_avail(resp
, srv_proto
,
2126 wpas_notify_p2p_sd_request(wpa_s
, freq
, sa
, dialog_token
,
2127 update_indic
, tlvs
, tlvs_len
);
2129 wpas_p2p_sd_response(wpa_s
, freq
, sa
, dialog_token
, resp
);
2135 void wpas_sd_response(void *ctx
, const u8
*sa
, u16 update_indic
,
2136 const u8
*tlvs
, size_t tlvs_len
)
2138 struct wpa_supplicant
*wpa_s
= ctx
;
2139 const u8
*pos
= tlvs
;
2140 const u8
*end
= tlvs
+ tlvs_len
;
2146 wpa_hexdump(MSG_MSGDUMP
, "P2P: Service Discovery Response TLVs",
2148 if (tlvs_len
> 1500) {
2149 /* TODO: better way for handling this */
2150 wpa_msg_ctrl(wpa_s
, MSG_INFO
,
2151 P2P_EVENT_SERV_DISC_RESP MACSTR
2152 " %u <long response: %u bytes>",
2153 MAC2STR(sa
), update_indic
,
2154 (unsigned int) tlvs_len
);
2156 buf_len
= 2 * tlvs_len
+ 1;
2157 buf
= os_malloc(buf_len
);
2159 wpa_snprintf_hex(buf
, buf_len
, tlvs
, tlvs_len
);
2160 wpa_msg_ctrl(wpa_s
, MSG_INFO
,
2161 P2P_EVENT_SERV_DISC_RESP MACSTR
" %u %s",
2162 MAC2STR(sa
), update_indic
, buf
);
2168 u8 srv_proto
, srv_trans_id
, status
;
2170 wpa_printf(MSG_DEBUG
, "P2P: Service Response TLV");
2171 slen
= WPA_GET_LE16(pos
);
2173 if (pos
+ slen
> end
|| slen
< 3) {
2174 wpa_printf(MSG_DEBUG
, "P2P: Unexpected Response Data "
2178 tlv_end
= pos
+ slen
;
2181 wpa_printf(MSG_DEBUG
, "P2P: Service Protocol Type %u",
2183 srv_trans_id
= *pos
++;
2184 wpa_printf(MSG_DEBUG
, "P2P: Service Transaction ID %u",
2187 wpa_printf(MSG_DEBUG
, "P2P: Status Code ID %u",
2190 wpa_hexdump(MSG_MSGDUMP
, "P2P: Response Data",
2191 pos
, tlv_end
- pos
);
2196 wpas_notify_p2p_sd_response(wpa_s
, sa
, update_indic
, tlvs
, tlvs_len
);
2200 u64
wpas_p2p_sd_request(struct wpa_supplicant
*wpa_s
, const u8
*dst
,
2201 const struct wpabuf
*tlvs
)
2203 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
)
2204 return wpa_drv_p2p_sd_request(wpa_s
, dst
, tlvs
);
2205 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
2207 return (uintptr_t) p2p_sd_request(wpa_s
->global
->p2p
, dst
, tlvs
);
2211 u64
wpas_p2p_sd_request_upnp(struct wpa_supplicant
*wpa_s
, const u8
*dst
,
2212 u8 version
, const char *query
)
2214 struct wpabuf
*tlvs
;
2217 tlvs
= wpabuf_alloc(2 + 1 + 1 + 1 + os_strlen(query
));
2220 wpabuf_put_le16(tlvs
, 1 + 1 + 1 + os_strlen(query
));
2221 wpabuf_put_u8(tlvs
, P2P_SERV_UPNP
); /* Service Protocol Type */
2222 wpabuf_put_u8(tlvs
, 1); /* Service Transaction ID */
2223 wpabuf_put_u8(tlvs
, version
);
2224 wpabuf_put_str(tlvs
, query
);
2225 ret
= wpas_p2p_sd_request(wpa_s
, dst
, tlvs
);
2231 #ifdef CONFIG_WIFI_DISPLAY
2233 static u64
wpas_p2p_sd_request_wfd(struct wpa_supplicant
*wpa_s
, const u8
*dst
,
2234 const struct wpabuf
*tlvs
)
2236 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
)
2238 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
2240 return (uintptr_t) p2p_sd_request_wfd(wpa_s
->global
->p2p
, dst
, tlvs
);
2244 #define MAX_WFD_SD_SUBELEMS 20
2246 static void wfd_add_sd_req_role(struct wpabuf
*tlvs
, u8 id
, u8 role
,
2247 const char *subelems
)
2254 len
= wpabuf_put(tlvs
, 2);
2255 wpabuf_put_u8(tlvs
, P2P_SERV_WIFI_DISPLAY
); /* Service Protocol Type */
2256 wpabuf_put_u8(tlvs
, id
); /* Service Transaction ID */
2258 wpabuf_put_u8(tlvs
, role
);
2263 if (val
>= 0 && val
< 256) {
2264 wpabuf_put_u8(tlvs
, val
);
2266 if (count
== MAX_WFD_SD_SUBELEMS
)
2269 pos
= os_strchr(pos
+ 1, ',');
2275 WPA_PUT_LE16(len
, (u8
*) wpabuf_put(tlvs
, 0) - len
- 2);
2279 u64
wpas_p2p_sd_request_wifi_display(struct wpa_supplicant
*wpa_s
,
2280 const u8
*dst
, const char *role
)
2282 struct wpabuf
*tlvs
;
2284 const char *subelems
;
2287 subelems
= os_strchr(role
, ' ');
2288 if (subelems
== NULL
)
2292 tlvs
= wpabuf_alloc(4 * (2 + 1 + 1 + 1 + MAX_WFD_SD_SUBELEMS
));
2296 if (os_strstr(role
, "[source]"))
2297 wfd_add_sd_req_role(tlvs
, id
++, 0x00, subelems
);
2298 if (os_strstr(role
, "[pri-sink]"))
2299 wfd_add_sd_req_role(tlvs
, id
++, 0x01, subelems
);
2300 if (os_strstr(role
, "[sec-sink]"))
2301 wfd_add_sd_req_role(tlvs
, id
++, 0x02, subelems
);
2302 if (os_strstr(role
, "[source+sink]"))
2303 wfd_add_sd_req_role(tlvs
, id
++, 0x03, subelems
);
2305 ret
= wpas_p2p_sd_request_wfd(wpa_s
, dst
, tlvs
);
2310 #endif /* CONFIG_WIFI_DISPLAY */
2313 int wpas_p2p_sd_cancel_request(struct wpa_supplicant
*wpa_s
, u64 req
)
2315 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
)
2316 return wpa_drv_p2p_sd_cancel_request(wpa_s
, req
);
2317 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
2319 return p2p_sd_cancel_request(wpa_s
->global
->p2p
,
2320 (void *) (uintptr_t) req
);
2324 void wpas_p2p_sd_response(struct wpa_supplicant
*wpa_s
, int freq
,
2325 const u8
*dst
, u8 dialog_token
,
2326 const struct wpabuf
*resp_tlvs
)
2328 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
) {
2329 wpa_drv_p2p_sd_response(wpa_s
, freq
, dst
, dialog_token
,
2333 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
2335 p2p_sd_response(wpa_s
->global
->p2p
, freq
, dst
, dialog_token
,
2340 void wpas_p2p_sd_service_update(struct wpa_supplicant
*wpa_s
)
2342 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
) {
2343 wpa_drv_p2p_service_update(wpa_s
);
2346 if (wpa_s
->global
->p2p
)
2347 p2p_sd_service_update(wpa_s
->global
->p2p
);
2351 static void wpas_p2p_srv_bonjour_free(struct p2p_srv_bonjour
*bsrv
)
2353 dl_list_del(&bsrv
->list
);
2354 wpabuf_free(bsrv
->query
);
2355 wpabuf_free(bsrv
->resp
);
2360 static void wpas_p2p_srv_upnp_free(struct p2p_srv_upnp
*usrv
)
2362 dl_list_del(&usrv
->list
);
2363 os_free(usrv
->service
);
2368 void wpas_p2p_service_flush(struct wpa_supplicant
*wpa_s
)
2370 struct p2p_srv_bonjour
*bsrv
, *bn
;
2371 struct p2p_srv_upnp
*usrv
, *un
;
2373 dl_list_for_each_safe(bsrv
, bn
, &wpa_s
->global
->p2p_srv_bonjour
,
2374 struct p2p_srv_bonjour
, list
)
2375 wpas_p2p_srv_bonjour_free(bsrv
);
2377 dl_list_for_each_safe(usrv
, un
, &wpa_s
->global
->p2p_srv_upnp
,
2378 struct p2p_srv_upnp
, list
)
2379 wpas_p2p_srv_upnp_free(usrv
);
2381 wpas_p2p_sd_service_update(wpa_s
);
2385 int wpas_p2p_service_add_bonjour(struct wpa_supplicant
*wpa_s
,
2386 struct wpabuf
*query
, struct wpabuf
*resp
)
2388 struct p2p_srv_bonjour
*bsrv
;
2390 bsrv
= os_zalloc(sizeof(*bsrv
));
2393 bsrv
->query
= query
;
2395 dl_list_add(&wpa_s
->global
->p2p_srv_bonjour
, &bsrv
->list
);
2397 wpas_p2p_sd_service_update(wpa_s
);
2402 int wpas_p2p_service_del_bonjour(struct wpa_supplicant
*wpa_s
,
2403 const struct wpabuf
*query
)
2405 struct p2p_srv_bonjour
*bsrv
;
2407 bsrv
= wpas_p2p_service_get_bonjour(wpa_s
, query
);
2410 wpas_p2p_srv_bonjour_free(bsrv
);
2411 wpas_p2p_sd_service_update(wpa_s
);
2416 int wpas_p2p_service_add_upnp(struct wpa_supplicant
*wpa_s
, u8 version
,
2417 const char *service
)
2419 struct p2p_srv_upnp
*usrv
;
2421 if (wpas_p2p_service_get_upnp(wpa_s
, version
, service
))
2422 return 0; /* Already listed */
2423 usrv
= os_zalloc(sizeof(*usrv
));
2426 usrv
->version
= version
;
2427 usrv
->service
= os_strdup(service
);
2428 if (usrv
->service
== NULL
) {
2432 dl_list_add(&wpa_s
->global
->p2p_srv_upnp
, &usrv
->list
);
2434 wpas_p2p_sd_service_update(wpa_s
);
2439 int wpas_p2p_service_del_upnp(struct wpa_supplicant
*wpa_s
, u8 version
,
2440 const char *service
)
2442 struct p2p_srv_upnp
*usrv
;
2444 usrv
= wpas_p2p_service_get_upnp(wpa_s
, version
, service
);
2447 wpas_p2p_srv_upnp_free(usrv
);
2448 wpas_p2p_sd_service_update(wpa_s
);
2453 static void wpas_prov_disc_local_display(struct wpa_supplicant
*wpa_s
,
2454 const u8
*peer
, const char *params
,
2455 unsigned int generated_pin
)
2457 wpa_msg_global(wpa_s
, MSG_INFO
, P2P_EVENT_PROV_DISC_SHOW_PIN MACSTR
2458 " %08d%s", MAC2STR(peer
), generated_pin
, params
);
2462 static void wpas_prov_disc_local_keypad(struct wpa_supplicant
*wpa_s
,
2463 const u8
*peer
, const char *params
)
2465 wpa_msg_global(wpa_s
, MSG_INFO
, P2P_EVENT_PROV_DISC_ENTER_PIN MACSTR
2466 "%s", MAC2STR(peer
), params
);
2470 void wpas_prov_disc_req(void *ctx
, const u8
*peer
, u16 config_methods
,
2471 const u8
*dev_addr
, const u8
*pri_dev_type
,
2472 const char *dev_name
, u16 supp_config_methods
,
2473 u8 dev_capab
, u8 group_capab
, const u8
*group_id
,
2474 size_t group_id_len
)
2476 struct wpa_supplicant
*wpa_s
= ctx
;
2477 char devtype
[WPS_DEV_TYPE_BUFSIZE
];
2479 u8 empty_dev_type
[8];
2480 unsigned int generated_pin
= 0;
2481 struct wpa_supplicant
*group
= NULL
;
2484 for (group
= wpa_s
->global
->ifaces
; group
; group
= group
->next
)
2486 struct wpa_ssid
*s
= group
->current_ssid
;
2488 s
->mode
== WPAS_MODE_P2P_GO
&&
2489 group_id_len
- ETH_ALEN
== s
->ssid_len
&&
2490 os_memcmp(group_id
+ ETH_ALEN
, s
->ssid
,
2496 if (pri_dev_type
== NULL
) {
2497 os_memset(empty_dev_type
, 0, sizeof(empty_dev_type
));
2498 pri_dev_type
= empty_dev_type
;
2500 os_snprintf(params
, sizeof(params
), " p2p_dev_addr=" MACSTR
2501 " pri_dev_type=%s name='%s' config_methods=0x%x "
2502 "dev_capab=0x%x group_capab=0x%x%s%s",
2504 wps_dev_type_bin2str(pri_dev_type
, devtype
,
2506 dev_name
, supp_config_methods
, dev_capab
, group_capab
,
2507 group
? " group=" : "",
2508 group
? group
->ifname
: "");
2509 params
[sizeof(params
) - 1] = '\0';
2511 if (config_methods
& WPS_CONFIG_DISPLAY
) {
2512 generated_pin
= wps_generate_pin();
2513 wpas_prov_disc_local_display(wpa_s
, peer
, params
,
2515 } else if (config_methods
& WPS_CONFIG_KEYPAD
)
2516 wpas_prov_disc_local_keypad(wpa_s
, peer
, params
);
2517 else if (config_methods
& WPS_CONFIG_PUSHBUTTON
)
2518 wpa_msg_global(wpa_s
, MSG_INFO
, P2P_EVENT_PROV_DISC_PBC_REQ
2519 MACSTR
"%s", MAC2STR(peer
), params
);
2521 wpas_notify_p2p_provision_discovery(wpa_s
, peer
, 1 /* request */,
2522 P2P_PROV_DISC_SUCCESS
,
2523 config_methods
, generated_pin
);
2527 void wpas_prov_disc_resp(void *ctx
, const u8
*peer
, u16 config_methods
)
2529 struct wpa_supplicant
*wpa_s
= ctx
;
2530 unsigned int generated_pin
= 0;
2533 if (wpa_s
->pending_pd_before_join
&&
2534 (os_memcmp(peer
, wpa_s
->pending_join_dev_addr
, ETH_ALEN
) == 0 ||
2535 os_memcmp(peer
, wpa_s
->pending_join_iface_addr
, ETH_ALEN
) == 0)) {
2536 wpa_s
->pending_pd_before_join
= 0;
2537 wpa_printf(MSG_DEBUG
, "P2P: Starting pending "
2538 "join-existing-group operation");
2539 wpas_p2p_join_start(wpa_s
);
2543 if (wpa_s
->pending_pd_use
== AUTO_PD_JOIN
||
2544 wpa_s
->pending_pd_use
== AUTO_PD_GO_NEG
)
2545 os_snprintf(params
, sizeof(params
), " peer_go=%d",
2546 wpa_s
->pending_pd_use
== AUTO_PD_JOIN
);
2550 if (config_methods
& WPS_CONFIG_DISPLAY
)
2551 wpas_prov_disc_local_keypad(wpa_s
, peer
, params
);
2552 else if (config_methods
& WPS_CONFIG_KEYPAD
) {
2553 generated_pin
= wps_generate_pin();
2554 wpas_prov_disc_local_display(wpa_s
, peer
, params
,
2556 } else if (config_methods
& WPS_CONFIG_PUSHBUTTON
)
2557 wpa_msg_global(wpa_s
, MSG_INFO
, P2P_EVENT_PROV_DISC_PBC_RESP
2558 MACSTR
"%s", MAC2STR(peer
), params
);
2560 wpas_notify_p2p_provision_discovery(wpa_s
, peer
, 0 /* response */,
2561 P2P_PROV_DISC_SUCCESS
,
2562 config_methods
, generated_pin
);
2566 static void wpas_prov_disc_fail(void *ctx
, const u8
*peer
,
2567 enum p2p_prov_disc_status status
)
2569 struct wpa_supplicant
*wpa_s
= ctx
;
2571 if (wpa_s
->p2p_fallback_to_go_neg
) {
2572 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: PD for p2p_connect-auto "
2573 "failed - fall back to GO Negotiation");
2574 wpas_p2p_fallback_to_go_neg(wpa_s
, 0);
2578 if (status
== P2P_PROV_DISC_TIMEOUT_JOIN
) {
2579 wpa_s
->pending_pd_before_join
= 0;
2580 wpa_printf(MSG_DEBUG
, "P2P: Starting pending "
2581 "join-existing-group operation (no ACK for PD "
2583 wpas_p2p_join_start(wpa_s
);
2587 wpa_msg_global(wpa_s
, MSG_INFO
, P2P_EVENT_PROV_DISC_FAILURE
2588 " p2p_dev_addr=" MACSTR
" status=%d",
2589 MAC2STR(peer
), status
);
2591 wpas_notify_p2p_provision_discovery(wpa_s
, peer
, 0 /* response */,
2596 static int freq_included(const struct p2p_channels
*channels
, unsigned int freq
)
2598 if (channels
== NULL
)
2599 return 1; /* Assume no restrictions */
2600 return p2p_channels_includes_freq(channels
, freq
);
2605 static u8
wpas_invitation_process(void *ctx
, const u8
*sa
, const u8
*bssid
,
2606 const u8
*go_dev_addr
, const u8
*ssid
,
2607 size_t ssid_len
, int *go
, u8
*group_bssid
,
2608 int *force_freq
, int persistent_group
,
2609 const struct p2p_channels
*channels
)
2611 struct wpa_supplicant
*wpa_s
= ctx
;
2614 struct wpa_supplicant
*grp
;
2616 if (!persistent_group
) {
2617 wpa_printf(MSG_DEBUG
, "P2P: Invitation from " MACSTR
2618 " to join an active group", MAC2STR(sa
));
2619 if (!is_zero_ether_addr(wpa_s
->p2p_auth_invite
) &&
2620 (os_memcmp(go_dev_addr
, wpa_s
->p2p_auth_invite
, ETH_ALEN
)
2622 os_memcmp(sa
, wpa_s
->p2p_auth_invite
, ETH_ALEN
) == 0)) {
2623 wpa_printf(MSG_DEBUG
, "P2P: Accept previously "
2624 "authorized invitation");
2628 * Do not accept the invitation automatically; notify user and
2631 return P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE
;
2634 grp
= wpas_get_p2p_group(wpa_s
, ssid
, ssid_len
, go
);
2636 wpa_printf(MSG_DEBUG
, "P2P: Accept invitation to already "
2637 "running persistent group");
2639 os_memcpy(group_bssid
, grp
->own_addr
, ETH_ALEN
);
2643 if (!is_zero_ether_addr(wpa_s
->p2p_auth_invite
) &&
2644 os_memcmp(sa
, wpa_s
->p2p_auth_invite
, ETH_ALEN
) == 0) {
2645 wpa_printf(MSG_DEBUG
, "P2P: Accept previously initiated "
2646 "invitation to re-invoke a persistent group");
2647 } else if (!wpa_s
->conf
->persistent_reconnect
)
2648 return P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE
;
2650 for (s
= wpa_s
->conf
->ssid
; s
; s
= s
->next
) {
2651 if (s
->disabled
== 2 &&
2652 os_memcmp(s
->bssid
, go_dev_addr
, ETH_ALEN
) == 0 &&
2653 s
->ssid_len
== ssid_len
&&
2654 os_memcmp(ssid
, s
->ssid
, ssid_len
) == 0)
2659 wpa_printf(MSG_DEBUG
, "P2P: Invitation from " MACSTR
2660 " requested reinvocation of an unknown group",
2662 return P2P_SC_FAIL_UNKNOWN_GROUP
;
2665 if (s
->mode
== WPAS_MODE_P2P_GO
&& !wpas_p2p_create_iface(wpa_s
)) {
2667 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
2668 wpa_printf(MSG_DEBUG
, "P2P: The only available "
2669 "interface is already in use - reject "
2671 return P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE
;
2673 os_memcpy(group_bssid
, wpa_s
->own_addr
, ETH_ALEN
);
2674 } else if (s
->mode
== WPAS_MODE_P2P_GO
) {
2676 if (wpas_p2p_add_group_interface(wpa_s
, WPA_IF_P2P_GO
) < 0)
2678 wpa_printf(MSG_ERROR
, "P2P: Failed to allocate a new "
2679 "interface address for the group");
2680 return P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE
;
2682 os_memcpy(group_bssid
, wpa_s
->pending_interface_addr
,
2687 wpas_p2p_set_own_freq_preference(wpa_s
, 0);
2689 /* Get one of the frequencies currently in use */
2690 if (wpas_p2p_valid_oper_freqs(wpa_s
, &res
, 1) > 0) {
2691 wpa_printf(MSG_DEBUG
, "P2P: Trying to force channel to match a channel already used by one of the interfaces");
2693 wpas_p2p_set_own_freq_preference(wpa_s
, res
);
2696 if (*force_freq
> 0 && wpa_s
->num_multichan_concurrent
> 1 &&
2697 wpas_p2p_num_unused_channels(wpa_s
) > 0) {
2699 /* We are the client */
2700 wpa_printf(MSG_DEBUG
, "P2P: Peer was found to be "
2701 "running a GO but we are capable of MCC, "
2702 "figure out the best channel to use");
2704 } else if (!freq_included(channels
, *force_freq
)) {
2705 /* We are the GO, and *force_freq is not in the
2707 wpa_printf(MSG_DEBUG
, "P2P: Forced GO freq %d MHz not "
2708 "in intersection but we are capable of MCC, "
2709 "figure out the best channel to use",
2715 return P2P_SC_SUCCESS
;
2719 static void wpas_invitation_received(void *ctx
, const u8
*sa
, const u8
*bssid
,
2720 const u8
*ssid
, size_t ssid_len
,
2721 const u8
*go_dev_addr
, u8 status
,
2724 struct wpa_supplicant
*wpa_s
= ctx
;
2727 for (s
= wpa_s
->conf
->ssid
; s
; s
= s
->next
) {
2728 if (s
->disabled
== 2 &&
2729 s
->ssid_len
== ssid_len
&&
2730 os_memcmp(ssid
, s
->ssid
, ssid_len
) == 0)
2734 if (status
== P2P_SC_SUCCESS
) {
2735 wpa_printf(MSG_DEBUG
, "P2P: Invitation from peer " MACSTR
2736 " was accepted; op_freq=%d MHz",
2737 MAC2STR(sa
), op_freq
);
2739 int go
= s
->mode
== WPAS_MODE_P2P_GO
;
2740 wpas_p2p_group_add_persistent(
2741 wpa_s
, s
, go
, go
? op_freq
: 0, 0, 0, NULL
,
2742 go
? P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE
: 0);
2744 wpa_s
->user_initiated_pd
= 0;
2745 wpas_p2p_join(wpa_s
, bssid
, go_dev_addr
,
2746 wpa_s
->p2p_wps_method
, 0);
2751 if (status
!= P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE
) {
2752 wpa_printf(MSG_DEBUG
, "P2P: Invitation from peer " MACSTR
2753 " was rejected (status %u)", MAC2STR(sa
), status
);
2759 wpa_msg_global(wpa_s
, MSG_INFO
,
2760 P2P_EVENT_INVITATION_RECEIVED
2761 "sa=" MACSTR
" go_dev_addr=" MACSTR
2762 " bssid=" MACSTR
" unknown-network",
2763 MAC2STR(sa
), MAC2STR(go_dev_addr
),
2766 wpa_msg_global(wpa_s
, MSG_INFO
,
2767 P2P_EVENT_INVITATION_RECEIVED
2768 "sa=" MACSTR
" go_dev_addr=" MACSTR
2770 MAC2STR(sa
), MAC2STR(go_dev_addr
));
2775 if (s
->mode
== WPAS_MODE_P2P_GO
&& op_freq
) {
2776 wpa_msg_global(wpa_s
, MSG_INFO
, P2P_EVENT_INVITATION_RECEIVED
2777 "sa=" MACSTR
" persistent=%d freq=%d",
2778 MAC2STR(sa
), s
->id
, op_freq
);
2780 wpa_msg_global(wpa_s
, MSG_INFO
, P2P_EVENT_INVITATION_RECEIVED
2781 "sa=" MACSTR
" persistent=%d",
2782 MAC2STR(sa
), s
->id
);
2787 static void wpas_remove_persistent_peer(struct wpa_supplicant
*wpa_s
,
2788 struct wpa_ssid
*ssid
,
2789 const u8
*peer
, int inv
)
2796 for (i
= 0; ssid
->p2p_client_list
&& i
< ssid
->num_p2p_clients
; i
++) {
2797 if (os_memcmp(ssid
->p2p_client_list
+ i
* ETH_ALEN
, peer
,
2801 if (i
>= ssid
->num_p2p_clients
) {
2802 if (ssid
->mode
!= WPAS_MODE_P2P_GO
&&
2803 os_memcmp(ssid
->bssid
, peer
, ETH_ALEN
) == 0) {
2804 wpa_printf(MSG_DEBUG
, "P2P: Remove persistent group %d "
2805 "due to invitation result", ssid
->id
);
2806 wpas_notify_network_removed(wpa_s
, ssid
);
2807 wpa_config_remove_network(wpa_s
->conf
, ssid
->id
);
2810 return; /* Peer not found in client list */
2813 wpa_printf(MSG_DEBUG
, "P2P: Remove peer " MACSTR
" from persistent "
2814 "group %d client list%s",
2815 MAC2STR(peer
), ssid
->id
,
2816 inv
? " due to invitation result" : "");
2817 os_memmove(ssid
->p2p_client_list
+ i
* ETH_ALEN
,
2818 ssid
->p2p_client_list
+ (i
+ 1) * ETH_ALEN
,
2819 (ssid
->num_p2p_clients
- i
- 1) * ETH_ALEN
);
2820 ssid
->num_p2p_clients
--;
2821 #ifndef CONFIG_NO_CONFIG_WRITE
2822 if (wpa_s
->parent
->conf
->update_config
&&
2823 wpa_config_write(wpa_s
->parent
->confname
, wpa_s
->parent
->conf
))
2824 wpa_printf(MSG_DEBUG
, "P2P: Failed to update configuration");
2825 #endif /* CONFIG_NO_CONFIG_WRITE */
2829 static void wpas_remove_persistent_client(struct wpa_supplicant
*wpa_s
,
2832 struct wpa_ssid
*ssid
;
2834 wpa_s
= wpa_s
->global
->p2p_invite_group
;
2836 return; /* No known invitation group */
2837 ssid
= wpa_s
->current_ssid
;
2838 if (ssid
== NULL
|| ssid
->mode
!= WPAS_MODE_P2P_GO
||
2839 !ssid
->p2p_persistent_group
)
2840 return; /* Not operating as a GO in persistent group */
2841 ssid
= wpas_p2p_get_persistent(wpa_s
->parent
, peer
,
2842 ssid
->ssid
, ssid
->ssid_len
);
2843 wpas_remove_persistent_peer(wpa_s
, ssid
, peer
, 1);
2847 static void wpas_invitation_result(void *ctx
, int status
, const u8
*bssid
,
2848 const struct p2p_channels
*channels
,
2851 struct wpa_supplicant
*wpa_s
= ctx
;
2852 struct wpa_ssid
*ssid
;
2855 wpa_msg_global(wpa_s
, MSG_INFO
, P2P_EVENT_INVITATION_RESULT
2856 "status=%d " MACSTR
,
2857 status
, MAC2STR(bssid
));
2859 wpa_msg_global(wpa_s
, MSG_INFO
, P2P_EVENT_INVITATION_RESULT
2860 "status=%d ", status
);
2862 wpas_notify_p2p_invitation_result(wpa_s
, status
, bssid
);
2864 wpa_printf(MSG_DEBUG
, "P2P: Invitation result - status=%d peer=" MACSTR
,
2865 status
, MAC2STR(peer
));
2866 if (wpa_s
->pending_invite_ssid_id
== -1) {
2867 if (status
== P2P_SC_FAIL_UNKNOWN_GROUP
)
2868 wpas_remove_persistent_client(wpa_s
, peer
);
2869 return; /* Invitation to active group */
2872 if (status
== P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE
) {
2873 wpa_printf(MSG_DEBUG
, "P2P: Waiting for peer to start another "
2874 "invitation exchange to indicate readiness for "
2878 if (status
!= P2P_SC_SUCCESS
) {
2879 if (status
== P2P_SC_FAIL_UNKNOWN_GROUP
) {
2880 ssid
= wpa_config_get_network(
2881 wpa_s
->conf
, wpa_s
->pending_invite_ssid_id
);
2882 wpas_remove_persistent_peer(wpa_s
, ssid
, peer
, 1);
2884 wpas_p2p_remove_pending_group_interface(wpa_s
);
2888 ssid
= wpa_config_get_network(wpa_s
->conf
,
2889 wpa_s
->pending_invite_ssid_id
);
2891 wpa_printf(MSG_ERROR
, "P2P: Could not find persistent group "
2892 "data matching with invitation");
2897 * The peer could have missed our ctrl::ack frame for Invitation
2898 * Response and continue retransmitting the frame. To reduce the
2899 * likelihood of the peer not getting successful TX status for the
2900 * Invitation Response frame, wait a short time here before starting
2901 * the persistent group so that we will remain on the current channel to
2902 * acknowledge any possible retransmission from the peer.
2904 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: 50 ms wait on current channel before "
2905 "starting persistent group");
2908 wpas_p2p_group_add_persistent(wpa_s
, ssid
,
2909 ssid
->mode
== WPAS_MODE_P2P_GO
,
2910 wpa_s
->p2p_persistent_go_freq
,
2911 wpa_s
->p2p_go_ht40
, wpa_s
->p2p_go_vht
,
2913 ssid
->mode
== WPAS_MODE_P2P_GO
?
2914 P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE
:
2919 static int wpas_p2p_disallowed_freq(struct wpa_global
*global
,
2922 return freq_range_list_includes(&global
->p2p_disallow_freq
, freq
);
2926 static void wpas_p2p_add_chan(struct p2p_reg_class
*reg
, u8 chan
)
2928 reg
->channel
[reg
->channels
] = chan
;
2933 static int wpas_p2p_default_channels(struct wpa_supplicant
*wpa_s
,
2934 struct p2p_channels
*chan
,
2935 struct p2p_channels
*cli_chan
)
2939 os_memset(cli_chan
, 0, sizeof(*cli_chan
));
2941 wpa_printf(MSG_DEBUG
, "P2P: Enable operating classes for 2.4 GHz "
2944 /* Operating class 81 - 2.4 GHz band channels 1..13 */
2945 chan
->reg_class
[cla
].reg_class
= 81;
2946 chan
->reg_class
[cla
].channels
= 0;
2947 for (i
= 0; i
< 11; i
++) {
2948 if (!wpas_p2p_disallowed_freq(wpa_s
->global
, 2412 + i
* 5))
2949 wpas_p2p_add_chan(&chan
->reg_class
[cla
], i
+ 1);
2951 if (chan
->reg_class
[cla
].channels
)
2954 wpa_printf(MSG_DEBUG
, "P2P: Enable operating classes for lower 5 GHz "
2957 /* Operating class 115 - 5 GHz, channels 36-48 */
2958 chan
->reg_class
[cla
].reg_class
= 115;
2959 chan
->reg_class
[cla
].channels
= 0;
2960 if (!wpas_p2p_disallowed_freq(wpa_s
->global
, 5000 + 36 * 5))
2961 wpas_p2p_add_chan(&chan
->reg_class
[cla
], 36);
2962 if (!wpas_p2p_disallowed_freq(wpa_s
->global
, 5000 + 40 * 5))
2963 wpas_p2p_add_chan(&chan
->reg_class
[cla
], 40);
2964 if (!wpas_p2p_disallowed_freq(wpa_s
->global
, 5000 + 44 * 5))
2965 wpas_p2p_add_chan(&chan
->reg_class
[cla
], 44);
2966 if (!wpas_p2p_disallowed_freq(wpa_s
->global
, 5000 + 48 * 5))
2967 wpas_p2p_add_chan(&chan
->reg_class
[cla
], 48);
2968 if (chan
->reg_class
[cla
].channels
)
2971 wpa_printf(MSG_DEBUG
, "P2P: Enable operating classes for higher 5 GHz "
2974 /* Operating class 124 - 5 GHz, channels 149,153,157,161 */
2975 chan
->reg_class
[cla
].reg_class
= 124;
2976 chan
->reg_class
[cla
].channels
= 0;
2977 if (!wpas_p2p_disallowed_freq(wpa_s
->global
, 5000 + 149 * 5))
2978 wpas_p2p_add_chan(&chan
->reg_class
[cla
], 149);
2979 if (!wpas_p2p_disallowed_freq(wpa_s
->global
, 5000 + 153 * 5))
2980 wpas_p2p_add_chan(&chan
->reg_class
[cla
], 153);
2981 if (!wpas_p2p_disallowed_freq(wpa_s
->global
, 5000 + 156 * 5))
2982 wpas_p2p_add_chan(&chan
->reg_class
[cla
], 157);
2983 if (!wpas_p2p_disallowed_freq(wpa_s
->global
, 5000 + 161 * 5))
2984 wpas_p2p_add_chan(&chan
->reg_class
[cla
], 161);
2985 if (chan
->reg_class
[cla
].channels
)
2988 chan
->reg_classes
= cla
;
2993 static struct hostapd_hw_modes
* get_mode(struct hostapd_hw_modes
*modes
,
2995 enum hostapd_hw_mode mode
)
2999 for (i
= 0; i
< num_modes
; i
++) {
3000 if (modes
[i
].mode
== mode
)
3009 NOT_ALLOWED
, PASSIVE_ONLY
, ALLOWED
3012 static int has_channel(struct wpa_global
*global
,
3013 struct hostapd_hw_modes
*mode
, u8 chan
, int *flags
)
3018 freq
= (mode
->mode
== HOSTAPD_MODE_IEEE80211A
? 5000 : 2407) +
3020 if (wpas_p2p_disallowed_freq(global
, freq
))
3023 for (i
= 0; i
< mode
->num_channels
; i
++) {
3024 if (mode
->channels
[i
].chan
== chan
) {
3026 *flags
= mode
->channels
[i
].flag
;
3027 if (mode
->channels
[i
].flag
&
3028 (HOSTAPD_CHAN_DISABLED
|
3029 HOSTAPD_CHAN_RADAR
))
3031 if (mode
->channels
[i
].flag
&
3032 (HOSTAPD_CHAN_PASSIVE_SCAN
|
3033 HOSTAPD_CHAN_NO_IBSS
))
3034 return PASSIVE_ONLY
;
3043 struct p2p_oper_class_map
{
3044 enum hostapd_hw_mode mode
;
3049 enum { BW20
, BW40PLUS
, BW40MINUS
, BW80
} bw
;
3052 static struct p2p_oper_class_map op_class
[] = {
3053 { HOSTAPD_MODE_IEEE80211G
, 81, 1, 13, 1, BW20
},
3054 #if 0 /* Do not enable HT40 on 2 GHz for now */
3055 { HOSTAPD_MODE_IEEE80211G
, 83, 1, 9, 1, BW40PLUS
},
3056 { HOSTAPD_MODE_IEEE80211G
, 84, 5, 13, 1, BW40MINUS
},
3058 { HOSTAPD_MODE_IEEE80211A
, 115, 36, 48, 4, BW20
},
3059 { HOSTAPD_MODE_IEEE80211A
, 124, 149, 161, 4, BW20
},
3060 { HOSTAPD_MODE_IEEE80211A
, 116, 36, 44, 8, BW40PLUS
},
3061 { HOSTAPD_MODE_IEEE80211A
, 117, 40, 48, 8, BW40MINUS
},
3062 { HOSTAPD_MODE_IEEE80211A
, 126, 149, 157, 8, BW40PLUS
},
3063 { HOSTAPD_MODE_IEEE80211A
, 127, 153, 161, 8, BW40MINUS
},
3066 * IEEE P802.11ac/D7.0 Table E-4 actually talks about channel center
3067 * frequency index 42, 58, 106, 122, 138, 155 with channel spacing of
3068 * 80 MHz, but currently use the following definition for simplicity
3069 * (these center frequencies are not actual channels, which makes
3070 * has_channel() fail). wpas_p2p_verify_80mhz() should take care of
3071 * removing invalid channels.
3073 { HOSTAPD_MODE_IEEE80211A
, 128, 36, 161, 4, BW80
},
3074 { -1, 0, 0, 0, 0, BW20
}
3078 static int wpas_p2p_get_center_80mhz(struct wpa_supplicant
*wpa_s
,
3079 struct hostapd_hw_modes
*mode
,
3082 u8 center_channels
[] = { 42, 58, 106, 122, 138, 155 };
3085 if (mode
->mode
!= HOSTAPD_MODE_IEEE80211A
)
3088 for (i
= 0; i
< ARRAY_SIZE(center_channels
); i
++)
3090 * In 80 MHz, the bandwidth "spans" 12 channels (e.g., 36-48),
3091 * so the center channel is 6 channels away from the start/end.
3093 if (channel
>= center_channels
[i
] - 6 &&
3094 channel
<= center_channels
[i
] + 6)
3095 return center_channels
[i
];
3101 static enum chan_allowed
wpas_p2p_verify_80mhz(struct wpa_supplicant
*wpa_s
,
3102 struct hostapd_hw_modes
*mode
,
3107 enum chan_allowed res
, ret
= ALLOWED
;
3109 center_chan
= wpas_p2p_get_center_80mhz(wpa_s
, mode
, channel
);
3112 if (center_chan
>= 58 && center_chan
<= 138)
3113 return NOT_ALLOWED
; /* Do not allow DFS channels for P2P */
3115 /* check all the channels are available */
3116 for (i
= 0; i
< 4; i
++) {
3117 int adj_chan
= center_chan
- 6 + i
* 4;
3119 res
= has_channel(wpa_s
->global
, mode
, adj_chan
, &flags
);
3120 if (res
== NOT_ALLOWED
)
3122 if (res
== PASSIVE_ONLY
)
3125 if (i
== 0 && !(flags
& HOSTAPD_CHAN_VHT_10_70
))
3127 if (i
== 1 && !(flags
& HOSTAPD_CHAN_VHT_30_50
))
3129 if (i
== 2 && !(flags
& HOSTAPD_CHAN_VHT_50_30
))
3131 if (i
== 3 && !(flags
& HOSTAPD_CHAN_VHT_70_10
))
3139 static enum chan_allowed
wpas_p2p_verify_channel(struct wpa_supplicant
*wpa_s
,
3140 struct hostapd_hw_modes
*mode
,
3144 enum chan_allowed res
, res2
;
3146 res2
= res
= has_channel(wpa_s
->global
, mode
, channel
, &flag
);
3147 if (bw
== BW40MINUS
) {
3148 if (!(flag
& HOSTAPD_CHAN_HT40MINUS
))
3150 res2
= has_channel(wpa_s
->global
, mode
, channel
- 4, NULL
);
3151 } else if (bw
== BW40PLUS
) {
3152 if (!(flag
& HOSTAPD_CHAN_HT40PLUS
))
3154 res2
= has_channel(wpa_s
->global
, mode
, channel
+ 4, NULL
);
3155 } else if (bw
== BW80
) {
3156 res2
= wpas_p2p_verify_80mhz(wpa_s
, mode
, channel
, bw
);
3159 if (res
== NOT_ALLOWED
|| res2
== NOT_ALLOWED
)
3161 if (res
== PASSIVE_ONLY
|| res2
== PASSIVE_ONLY
)
3162 return PASSIVE_ONLY
;
3167 static int wpas_p2p_setup_channels(struct wpa_supplicant
*wpa_s
,
3168 struct p2p_channels
*chan
,
3169 struct p2p_channels
*cli_chan
)
3171 struct hostapd_hw_modes
*mode
;
3172 int cla
, op
, cli_cla
;
3174 if (wpa_s
->hw
.modes
== NULL
) {
3175 wpa_printf(MSG_DEBUG
, "P2P: Driver did not support fetching "
3176 "of all supported channels; assume dualband "
3178 return wpas_p2p_default_channels(wpa_s
, chan
, cli_chan
);
3183 for (op
= 0; op_class
[op
].op_class
; op
++) {
3184 struct p2p_oper_class_map
*o
= &op_class
[op
];
3186 struct p2p_reg_class
*reg
= NULL
, *cli_reg
= NULL
;
3188 mode
= get_mode(wpa_s
->hw
.modes
, wpa_s
->hw
.num_modes
, o
->mode
);
3191 for (ch
= o
->min_chan
; ch
<= o
->max_chan
; ch
+= o
->inc
) {
3192 enum chan_allowed res
;
3193 res
= wpas_p2p_verify_channel(wpa_s
, mode
, ch
, o
->bw
);
3194 if (res
== ALLOWED
) {
3196 wpa_printf(MSG_DEBUG
, "P2P: Add operating class %u",
3198 reg
= &chan
->reg_class
[cla
];
3200 reg
->reg_class
= o
->op_class
;
3202 reg
->channel
[reg
->channels
] = ch
;
3204 } else if (res
== PASSIVE_ONLY
&&
3205 wpa_s
->conf
->p2p_add_cli_chan
) {
3206 if (cli_reg
== NULL
) {
3207 wpa_printf(MSG_DEBUG
, "P2P: Add operating class %u (client only)",
3209 cli_reg
= &cli_chan
->reg_class
[cli_cla
];
3211 cli_reg
->reg_class
= o
->op_class
;
3213 cli_reg
->channel
[cli_reg
->channels
] = ch
;
3214 cli_reg
->channels
++;
3218 wpa_hexdump(MSG_DEBUG
, "P2P: Channels",
3219 reg
->channel
, reg
->channels
);
3222 wpa_hexdump(MSG_DEBUG
, "P2P: Channels (client only)",
3223 cli_reg
->channel
, cli_reg
->channels
);
3227 chan
->reg_classes
= cla
;
3228 cli_chan
->reg_classes
= cli_cla
;
3234 int wpas_p2p_get_ht40_mode(struct wpa_supplicant
*wpa_s
,
3235 struct hostapd_hw_modes
*mode
, u8 channel
)
3238 enum chan_allowed ret
;
3240 for (op
= 0; op_class
[op
].op_class
; op
++) {
3241 struct p2p_oper_class_map
*o
= &op_class
[op
];
3244 for (ch
= o
->min_chan
; ch
<= o
->max_chan
; ch
+= o
->inc
) {
3245 if (o
->mode
!= HOSTAPD_MODE_IEEE80211A
||
3246 o
->bw
== BW20
|| ch
!= channel
)
3248 ret
= wpas_p2p_verify_channel(wpa_s
, mode
, ch
, o
->bw
);
3250 return (o
->bw
== BW40MINUS
) ? -1 : 1;
3257 int wpas_p2p_get_vht80_center(struct wpa_supplicant
*wpa_s
,
3258 struct hostapd_hw_modes
*mode
, u8 channel
)
3260 if (!wpas_p2p_verify_channel(wpa_s
, mode
, channel
, BW80
))
3263 return wpas_p2p_get_center_80mhz(wpa_s
, mode
, channel
);
3267 static int wpas_get_noa(void *ctx
, const u8
*interface_addr
, u8
*buf
,
3270 struct wpa_supplicant
*wpa_s
= ctx
;
3272 for (wpa_s
= wpa_s
->global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
3273 if (os_memcmp(wpa_s
->own_addr
, interface_addr
, ETH_ALEN
) == 0)
3279 return wpa_drv_get_noa(wpa_s
, buf
, buf_len
);
3283 static int wpas_go_connected(void *ctx
, const u8
*dev_addr
)
3285 struct wpa_supplicant
*wpa_s
= ctx
;
3287 for (wpa_s
= wpa_s
->global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
3288 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
3291 if (ssid
->mode
!= WPAS_MODE_INFRA
)
3293 if (wpa_s
->wpa_state
!= WPA_COMPLETED
&&
3294 wpa_s
->wpa_state
!= WPA_GROUP_HANDSHAKE
)
3296 if (os_memcmp(wpa_s
->go_dev_addr
, dev_addr
, ETH_ALEN
) == 0)
3304 static void wpas_p2p_debug_print(void *ctx
, int level
, const char *msg
)
3306 struct wpa_supplicant
*wpa_s
= ctx
;
3307 wpa_msg_global(wpa_s
, level
, "P2P: %s", msg
);
3311 int wpas_p2p_add_p2pdev_interface(struct wpa_supplicant
*wpa_s
)
3313 struct wpa_interface iface
;
3314 struct wpa_supplicant
*p2pdev_wpa_s
;
3316 char force_name
[100];
3319 os_snprintf(ifname
, sizeof(ifname
), P2P_MGMT_DEVICE_PREFIX
"%s",
3321 force_name
[0] = '\0';
3322 wpa_s
->pending_interface_type
= WPA_IF_P2P_DEVICE
;
3323 ret
= wpa_drv_if_add(wpa_s
, WPA_IF_P2P_DEVICE
, ifname
, NULL
, NULL
,
3324 force_name
, wpa_s
->pending_interface_addr
, NULL
);
3326 wpa_printf(MSG_DEBUG
, "P2P: Failed to create P2P Device interface");
3329 os_strlcpy(wpa_s
->pending_interface_name
, ifname
,
3330 sizeof(wpa_s
->pending_interface_name
));
3332 os_memset(&iface
, 0, sizeof(iface
));
3334 iface
.ifname
= wpa_s
->pending_interface_name
;
3335 iface
.driver
= wpa_s
->driver
->name
;
3336 iface
.driver_param
= wpa_s
->conf
->driver_param
;
3337 iface
.confname
= wpa_s
->confname
;
3338 p2pdev_wpa_s
= wpa_supplicant_add_iface(wpa_s
->global
, &iface
);
3339 if (!p2pdev_wpa_s
) {
3340 wpa_printf(MSG_DEBUG
, "P2P: Failed to add P2P Device interface");
3343 p2pdev_wpa_s
->parent
= wpa_s
;
3345 wpa_s
->pending_interface_name
[0] = '\0';
3351 * wpas_p2p_init - Initialize P2P module for %wpa_supplicant
3352 * @global: Pointer to global data from wpa_supplicant_init()
3353 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
3354 * Returns: 0 on success, -1 on failure
3356 int wpas_p2p_init(struct wpa_global
*global
, struct wpa_supplicant
*wpa_s
)
3358 struct p2p_config p2p
;
3362 if (wpa_s
->conf
->p2p_disabled
)
3365 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_CAPABLE
))
3371 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
) {
3372 struct p2p_params params
;
3374 wpa_printf(MSG_DEBUG
, "P2P: Use driver-based P2P management");
3375 os_memset(¶ms
, 0, sizeof(params
));
3376 params
.dev_name
= wpa_s
->conf
->device_name
;
3377 os_memcpy(params
.pri_dev_type
, wpa_s
->conf
->device_type
,
3379 params
.num_sec_dev_types
= wpa_s
->conf
->num_sec_device_types
;
3380 os_memcpy(params
.sec_dev_type
,
3381 wpa_s
->conf
->sec_device_type
,
3382 params
.num_sec_dev_types
* WPS_DEV_TYPE_LEN
);
3384 if (wpa_drv_p2p_set_params(wpa_s
, ¶ms
) < 0)
3390 os_memset(&p2p
, 0, sizeof(p2p
));
3392 p2p
.debug_print
= wpas_p2p_debug_print
;
3393 p2p
.p2p_scan
= wpas_p2p_scan
;
3394 p2p
.send_action
= wpas_send_action
;
3395 p2p
.send_action_done
= wpas_send_action_done
;
3396 p2p
.go_neg_completed
= wpas_go_neg_completed
;
3397 p2p
.go_neg_req_rx
= wpas_go_neg_req_rx
;
3398 p2p
.dev_found
= wpas_dev_found
;
3399 p2p
.dev_lost
= wpas_dev_lost
;
3400 p2p
.find_stopped
= wpas_find_stopped
;
3401 p2p
.start_listen
= wpas_start_listen
;
3402 p2p
.stop_listen
= wpas_stop_listen
;
3403 p2p
.send_probe_resp
= wpas_send_probe_resp
;
3404 p2p
.sd_request
= wpas_sd_request
;
3405 p2p
.sd_response
= wpas_sd_response
;
3406 p2p
.prov_disc_req
= wpas_prov_disc_req
;
3407 p2p
.prov_disc_resp
= wpas_prov_disc_resp
;
3408 p2p
.prov_disc_fail
= wpas_prov_disc_fail
;
3409 p2p
.invitation_process
= wpas_invitation_process
;
3410 p2p
.invitation_received
= wpas_invitation_received
;
3411 p2p
.invitation_result
= wpas_invitation_result
;
3412 p2p
.get_noa
= wpas_get_noa
;
3413 p2p
.go_connected
= wpas_go_connected
;
3415 os_memcpy(wpa_s
->global
->p2p_dev_addr
, wpa_s
->own_addr
, ETH_ALEN
);
3416 os_memcpy(p2p
.dev_addr
, wpa_s
->global
->p2p_dev_addr
, ETH_ALEN
);
3417 p2p
.dev_name
= wpa_s
->conf
->device_name
;
3418 p2p
.manufacturer
= wpa_s
->conf
->manufacturer
;
3419 p2p
.model_name
= wpa_s
->conf
->model_name
;
3420 p2p
.model_number
= wpa_s
->conf
->model_number
;
3421 p2p
.serial_number
= wpa_s
->conf
->serial_number
;
3423 os_memcpy(p2p
.uuid
, wpa_s
->wps
->uuid
, 16);
3424 p2p
.config_methods
= wpa_s
->wps
->config_methods
;
3427 if (wpa_s
->conf
->p2p_listen_reg_class
&&
3428 wpa_s
->conf
->p2p_listen_channel
) {
3429 p2p
.reg_class
= wpa_s
->conf
->p2p_listen_reg_class
;
3430 p2p
.channel
= wpa_s
->conf
->p2p_listen_channel
;
3434 * Pick one of the social channels randomly as the listen
3437 os_get_random((u8
*) &r
, sizeof(r
));
3438 p2p
.channel
= 1 + (r
% 3) * 5;
3440 wpa_printf(MSG_DEBUG
, "P2P: Own listen channel: %d", p2p
.channel
);
3442 if (wpa_s
->conf
->p2p_oper_reg_class
&&
3443 wpa_s
->conf
->p2p_oper_channel
) {
3444 p2p
.op_reg_class
= wpa_s
->conf
->p2p_oper_reg_class
;
3445 p2p
.op_channel
= wpa_s
->conf
->p2p_oper_channel
;
3446 p2p
.cfg_op_channel
= 1;
3447 wpa_printf(MSG_DEBUG
, "P2P: Configured operating channel: "
3448 "%d:%d", p2p
.op_reg_class
, p2p
.op_channel
);
3451 p2p
.op_reg_class
= 81;
3453 * Use random operation channel from (1, 6, 11) if no other
3454 * preference is indicated.
3456 os_get_random((u8
*) &r
, sizeof(r
));
3457 p2p
.op_channel
= 1 + (r
% 3) * 5;
3458 p2p
.cfg_op_channel
= 0;
3459 wpa_printf(MSG_DEBUG
, "P2P: Random operating channel: "
3460 "%d:%d", p2p
.op_reg_class
, p2p
.op_channel
);
3463 if (wpa_s
->conf
->p2p_pref_chan
&& wpa_s
->conf
->num_p2p_pref_chan
) {
3464 p2p
.pref_chan
= wpa_s
->conf
->p2p_pref_chan
;
3465 p2p
.num_pref_chan
= wpa_s
->conf
->num_p2p_pref_chan
;
3468 if (wpa_s
->conf
->country
[0] && wpa_s
->conf
->country
[1]) {
3469 os_memcpy(p2p
.country
, wpa_s
->conf
->country
, 2);
3470 p2p
.country
[2] = 0x04;
3472 os_memcpy(p2p
.country
, "XX\x04", 3);
3474 if (wpas_p2p_setup_channels(wpa_s
, &p2p
.channels
, &p2p
.cli_channels
)) {
3475 wpa_printf(MSG_ERROR
, "P2P: Failed to configure supported "
3480 os_memcpy(p2p
.pri_dev_type
, wpa_s
->conf
->device_type
,
3483 p2p
.num_sec_dev_types
= wpa_s
->conf
->num_sec_device_types
;
3484 os_memcpy(p2p
.sec_dev_type
, wpa_s
->conf
->sec_device_type
,
3485 p2p
.num_sec_dev_types
* WPS_DEV_TYPE_LEN
);
3487 p2p
.concurrent_operations
= !!(wpa_s
->drv_flags
&
3488 WPA_DRIVER_FLAGS_P2P_CONCURRENT
);
3490 p2p
.max_peers
= 100;
3492 if (wpa_s
->conf
->p2p_ssid_postfix
) {
3493 p2p
.ssid_postfix_len
=
3494 os_strlen(wpa_s
->conf
->p2p_ssid_postfix
);
3495 if (p2p
.ssid_postfix_len
> sizeof(p2p
.ssid_postfix
))
3496 p2p
.ssid_postfix_len
= sizeof(p2p
.ssid_postfix
);
3497 os_memcpy(p2p
.ssid_postfix
, wpa_s
->conf
->p2p_ssid_postfix
,
3498 p2p
.ssid_postfix_len
);
3501 p2p
.p2p_intra_bss
= wpa_s
->conf
->p2p_intra_bss
;
3503 p2p
.max_listen
= wpa_s
->max_remain_on_chan
;
3505 global
->p2p
= p2p_init(&p2p
);
3506 if (global
->p2p
== NULL
)
3508 global
->p2p_init_wpa_s
= wpa_s
;
3510 for (i
= 0; i
< MAX_WPS_VENDOR_EXT
; i
++) {
3511 if (wpa_s
->conf
->wps_vendor_ext
[i
] == NULL
)
3513 p2p_add_wps_vendor_extension(
3514 global
->p2p
, wpa_s
->conf
->wps_vendor_ext
[i
]);
3517 p2p_set_no_go_freq(global
->p2p
, &wpa_s
->conf
->p2p_no_go_freq
);
3524 * wpas_p2p_deinit - Deinitialize per-interface P2P data
3525 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
3527 * This function deinitialize per-interface P2P data.
3529 void wpas_p2p_deinit(struct wpa_supplicant
*wpa_s
)
3531 if (wpa_s
->driver
&& wpa_s
->drv_priv
)
3532 wpa_drv_probe_req_report(wpa_s
, 0);
3534 if (wpa_s
->go_params
) {
3535 /* Clear any stored provisioning info */
3536 p2p_clear_provisioning_info(
3538 wpa_s
->go_params
->peer_device_addr
);
3541 os_free(wpa_s
->go_params
);
3542 wpa_s
->go_params
= NULL
;
3543 eloop_cancel_timeout(wpas_p2p_group_formation_timeout
, wpa_s
, NULL
);
3544 eloop_cancel_timeout(wpas_p2p_join_scan
, wpa_s
, NULL
);
3545 wpa_s
->p2p_long_listen
= 0;
3546 eloop_cancel_timeout(wpas_p2p_long_listen_timeout
, wpa_s
, NULL
);
3547 eloop_cancel_timeout(wpas_p2p_group_idle_timeout
, wpa_s
, NULL
);
3548 wpas_p2p_remove_pending_group_interface(wpa_s
);
3550 /* TODO: remove group interface from the driver if this wpa_s instance
3551 * is on top of a P2P group interface */
3556 * wpas_p2p_deinit_global - Deinitialize global P2P module
3557 * @global: Pointer to global data from wpa_supplicant_init()
3559 * This function deinitializes the global (per device) P2P module.
3561 void wpas_p2p_deinit_global(struct wpa_global
*global
)
3563 struct wpa_supplicant
*wpa_s
, *tmp
;
3565 wpa_s
= global
->ifaces
;
3567 wpas_p2p_service_flush(wpa_s
);
3569 if (global
->p2p
== NULL
)
3572 /* Remove remaining P2P group interfaces */
3573 while (wpa_s
&& wpa_s
->p2p_group_interface
!= NOT_P2P_GROUP_INTERFACE
)
3574 wpa_s
= wpa_s
->next
;
3576 tmp
= global
->ifaces
;
3579 tmp
->p2p_group_interface
== NOT_P2P_GROUP_INTERFACE
)) {
3584 /* Disconnect from the P2P group and deinit the interface */
3585 wpas_p2p_disconnect(tmp
);
3589 * Deinit GO data on any possibly remaining interface (if main
3590 * interface is used as GO).
3592 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
3593 if (wpa_s
->ap_iface
)
3594 wpas_p2p_group_deinit(wpa_s
);
3597 p2p_deinit(global
->p2p
);
3599 global
->p2p_init_wpa_s
= NULL
;
3603 static int wpas_p2p_create_iface(struct wpa_supplicant
*wpa_s
)
3605 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE
) &&
3606 wpa_s
->conf
->p2p_no_group_iface
)
3607 return 0; /* separate interface disabled per configuration */
3608 if (wpa_s
->drv_flags
&
3609 (WPA_DRIVER_FLAGS_P2P_DEDICATED_INTERFACE
|
3610 WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P
))
3611 return 1; /* P2P group requires a new interface in every case
3613 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_CONCURRENT
))
3614 return 0; /* driver does not support concurrent operations */
3615 if (wpa_s
->global
->ifaces
->next
)
3616 return 1; /* more that one interface already in use */
3617 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
)
3618 return 1; /* this interface is already in use */
3623 static int wpas_p2p_start_go_neg(struct wpa_supplicant
*wpa_s
,
3624 const u8
*peer_addr
,
3625 enum p2p_wps_method wps_method
,
3626 int go_intent
, const u8
*own_interface_addr
,
3627 unsigned int force_freq
, int persistent_group
,
3628 struct wpa_ssid
*ssid
, unsigned int pref_freq
)
3630 if (persistent_group
&& wpa_s
->conf
->persistent_reconnect
)
3631 persistent_group
= 2;
3633 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
) {
3634 return wpa_drv_p2p_connect(wpa_s
, peer_addr
, wps_method
,
3635 go_intent
, own_interface_addr
,
3636 force_freq
, persistent_group
);
3640 * Increase GO config timeout if HT40 is used since it takes some time
3641 * to scan channels for coex purposes before the BSS can be started.
3643 p2p_set_config_timeout(wpa_s
->global
->p2p
,
3644 wpa_s
->p2p_go_ht40
? 255 : 100, 20);
3646 return p2p_connect(wpa_s
->global
->p2p
, peer_addr
, wps_method
,
3647 go_intent
, own_interface_addr
, force_freq
,
3648 persistent_group
, ssid
? ssid
->ssid
: NULL
,
3649 ssid
? ssid
->ssid_len
: 0,
3650 wpa_s
->p2p_pd_before_go_neg
, pref_freq
);
3654 static int wpas_p2p_auth_go_neg(struct wpa_supplicant
*wpa_s
,
3655 const u8
*peer_addr
,
3656 enum p2p_wps_method wps_method
,
3657 int go_intent
, const u8
*own_interface_addr
,
3658 unsigned int force_freq
, int persistent_group
,
3659 struct wpa_ssid
*ssid
, unsigned int pref_freq
)
3661 if (persistent_group
&& wpa_s
->conf
->persistent_reconnect
)
3662 persistent_group
= 2;
3664 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
)
3667 return p2p_authorize(wpa_s
->global
->p2p
, peer_addr
, wps_method
,
3668 go_intent
, own_interface_addr
, force_freq
,
3669 persistent_group
, ssid
? ssid
->ssid
: NULL
,
3670 ssid
? ssid
->ssid_len
: 0, pref_freq
);
3674 static void wpas_p2p_check_join_scan_limit(struct wpa_supplicant
*wpa_s
)
3676 wpa_s
->p2p_join_scan_count
++;
3677 wpa_printf(MSG_DEBUG
, "P2P: Join scan attempt %d",
3678 wpa_s
->p2p_join_scan_count
);
3679 if (wpa_s
->p2p_join_scan_count
> P2P_MAX_JOIN_SCAN_ATTEMPTS
) {
3680 wpa_printf(MSG_DEBUG
, "P2P: Failed to find GO " MACSTR
3681 " for join operationg - stop join attempt",
3682 MAC2STR(wpa_s
->pending_join_iface_addr
));
3683 eloop_cancel_timeout(wpas_p2p_join_scan
, wpa_s
, NULL
);
3684 if (wpa_s
->p2p_auto_pd
) {
3685 wpa_s
->p2p_auto_pd
= 0;
3686 wpa_msg_global(wpa_s
, MSG_INFO
,
3687 P2P_EVENT_PROV_DISC_FAILURE
3688 " p2p_dev_addr=" MACSTR
" status=N/A",
3689 MAC2STR(wpa_s
->pending_join_dev_addr
));
3692 wpa_msg_global(wpa_s
->parent
, MSG_INFO
,
3693 P2P_EVENT_GROUP_FORMATION_FAILURE
);
3698 static int wpas_check_freq_conflict(struct wpa_supplicant
*wpa_s
, int freq
)
3700 int *freqs
, res
, num
, i
;
3702 if (wpas_p2p_num_unused_channels(wpa_s
) > 0) {
3703 /* Multiple channels are supported and not all are in use */
3707 freqs
= os_calloc(wpa_s
->num_multichan_concurrent
, sizeof(int));
3711 num
= wpas_p2p_valid_oper_freqs(wpa_s
, freqs
,
3712 wpa_s
->num_multichan_concurrent
);
3718 for (i
= 0; i
< num
; i
++) {
3719 if (freqs
[i
] == freq
) {
3720 wpa_printf(MSG_DEBUG
, "P2P: Frequency %d MHz in use by another virtual interface and can be used",
3735 static int wpas_p2p_peer_go(struct wpa_supplicant
*wpa_s
,
3736 const u8
*peer_dev_addr
)
3738 struct wpa_bss
*bss
;
3741 bss
= wpa_bss_get_p2p_dev_addr(wpa_s
, peer_dev_addr
);
3744 if (bss
->last_update_idx
< wpa_s
->bss_update_idx
) {
3745 wpa_printf(MSG_DEBUG
, "P2P: Peer BSS entry not updated in the "
3750 updated
= os_time_before(&wpa_s
->p2p_auto_started
, &bss
->last_update
);
3751 wpa_printf(MSG_DEBUG
, "P2P: Current BSS entry for peer updated at "
3752 "%ld.%06ld (%supdated in last scan)",
3753 bss
->last_update
.sec
, bss
->last_update
.usec
,
3754 updated
? "": "not ");
3760 static void wpas_p2p_scan_res_join(struct wpa_supplicant
*wpa_s
,
3761 struct wpa_scan_results
*scan_res
)
3763 struct wpa_bss
*bss
;
3765 u8 iface_addr
[ETH_ALEN
];
3767 eloop_cancel_timeout(wpas_p2p_join_scan
, wpa_s
, NULL
);
3769 if (wpa_s
->global
->p2p_disabled
)
3772 wpa_printf(MSG_DEBUG
, "P2P: Scan results received (%d BSS) for %sjoin",
3773 scan_res
? (int) scan_res
->num
: -1,
3774 wpa_s
->p2p_auto_join
? "auto_" : "");
3777 wpas_p2p_scan_res_handler(wpa_s
, scan_res
);
3779 if (wpa_s
->p2p_auto_pd
) {
3780 int join
= wpas_p2p_peer_go(wpa_s
,
3781 wpa_s
->pending_join_dev_addr
);
3783 wpa_s
->auto_pd_scan_retry
< P2P_AUTO_PD_SCAN_ATTEMPTS
) {
3784 wpa_s
->auto_pd_scan_retry
++;
3785 bss
= wpa_bss_get_bssid_latest(
3786 wpa_s
, wpa_s
->pending_join_dev_addr
);
3789 wpa_printf(MSG_DEBUG
, "P2P: Scan retry %d for "
3790 "the peer " MACSTR
" at %d MHz",
3791 wpa_s
->auto_pd_scan_retry
,
3793 pending_join_dev_addr
),
3795 wpas_p2p_join_scan_req(wpa_s
, freq
);
3803 wpa_s
->p2p_auto_pd
= 0;
3804 wpa_s
->pending_pd_use
= join
? AUTO_PD_JOIN
: AUTO_PD_GO_NEG
;
3805 wpa_printf(MSG_DEBUG
, "P2P: Auto PD with " MACSTR
" join=%d",
3806 MAC2STR(wpa_s
->pending_join_dev_addr
), join
);
3807 if (p2p_prov_disc_req(wpa_s
->global
->p2p
,
3808 wpa_s
->pending_join_dev_addr
,
3809 wpa_s
->pending_pd_config_methods
, join
,
3810 0, wpa_s
->user_initiated_pd
) < 0) {
3811 wpa_s
->p2p_auto_pd
= 0;
3812 wpa_msg_global(wpa_s
, MSG_INFO
,
3813 P2P_EVENT_PROV_DISC_FAILURE
3814 " p2p_dev_addr=" MACSTR
" status=N/A",
3815 MAC2STR(wpa_s
->pending_join_dev_addr
));
3820 if (wpa_s
->p2p_auto_join
) {
3821 int join
= wpas_p2p_peer_go(wpa_s
,
3822 wpa_s
->pending_join_dev_addr
);
3824 wpa_printf(MSG_DEBUG
, "P2P: Peer was not found to be "
3825 "running a GO -> use GO Negotiation");
3826 wpas_p2p_connect(wpa_s
, wpa_s
->pending_join_dev_addr
,
3827 wpa_s
->p2p_pin
, wpa_s
->p2p_wps_method
,
3828 wpa_s
->p2p_persistent_group
, 0, 0, 0,
3829 wpa_s
->p2p_go_intent
,
3830 wpa_s
->p2p_connect_freq
,
3831 wpa_s
->p2p_persistent_id
,
3832 wpa_s
->p2p_pd_before_go_neg
,
3838 wpa_printf(MSG_DEBUG
, "P2P: Peer was found running GO%s -> "
3839 "try to join the group", join
? "" :
3842 wpa_s
->p2p_fallback_to_go_neg
= 1;
3845 freq
= p2p_get_oper_freq(wpa_s
->global
->p2p
,
3846 wpa_s
->pending_join_iface_addr
);
3848 p2p_get_interface_addr(wpa_s
->global
->p2p
,
3849 wpa_s
->pending_join_dev_addr
,
3851 os_memcmp(iface_addr
, wpa_s
->pending_join_dev_addr
, ETH_ALEN
) != 0)
3853 wpa_printf(MSG_DEBUG
, "P2P: Overwrite pending interface "
3854 "address for join from " MACSTR
" to " MACSTR
3855 " based on newly discovered P2P peer entry",
3856 MAC2STR(wpa_s
->pending_join_iface_addr
),
3857 MAC2STR(iface_addr
));
3858 os_memcpy(wpa_s
->pending_join_iface_addr
, iface_addr
,
3861 freq
= p2p_get_oper_freq(wpa_s
->global
->p2p
,
3862 wpa_s
->pending_join_iface_addr
);
3865 wpa_printf(MSG_DEBUG
, "P2P: Target GO operating frequency "
3866 "from P2P peer table: %d MHz", freq
);
3868 bss
= wpa_bss_get_bssid_latest(wpa_s
, wpa_s
->pending_join_iface_addr
);
3871 wpa_printf(MSG_DEBUG
, "P2P: Target GO operating frequency "
3872 "from BSS table: %d MHz (SSID %s)", freq
,
3873 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
3878 if (wpas_check_freq_conflict(wpa_s
, freq
) > 0) {
3879 wpa_msg_global(wpa_s
->parent
, MSG_INFO
,
3880 P2P_EVENT_GROUP_FORMATION_FAILURE
3881 "reason=FREQ_CONFLICT");
3885 wpa_printf(MSG_DEBUG
, "P2P: Send Provision Discovery Request "
3886 "prior to joining an existing group (GO " MACSTR
3888 MAC2STR(wpa_s
->pending_join_dev_addr
), freq
);
3889 wpa_s
->pending_pd_before_join
= 1;
3891 switch (wpa_s
->pending_join_wps_method
) {
3892 case WPS_PIN_DISPLAY
:
3893 method
= WPS_CONFIG_KEYPAD
;
3895 case WPS_PIN_KEYPAD
:
3896 method
= WPS_CONFIG_DISPLAY
;
3899 method
= WPS_CONFIG_PUSHBUTTON
;
3906 if ((p2p_get_provisioning_info(wpa_s
->global
->p2p
,
3907 wpa_s
->pending_join_dev_addr
) ==
3910 * We have already performed provision discovery for
3911 * joining the group. Proceed directly to join
3912 * operation without duplicated provision discovery. */
3913 wpa_printf(MSG_DEBUG
, "P2P: Provision discovery "
3914 "with " MACSTR
" already done - proceed to "
3916 MAC2STR(wpa_s
->pending_join_dev_addr
));
3917 wpa_s
->pending_pd_before_join
= 0;
3921 if (p2p_prov_disc_req(wpa_s
->global
->p2p
,
3922 wpa_s
->pending_join_dev_addr
, method
, 1,
3923 freq
, wpa_s
->user_initiated_pd
) < 0) {
3924 wpa_printf(MSG_DEBUG
, "P2P: Failed to send Provision "
3925 "Discovery Request before joining an "
3927 wpa_s
->pending_pd_before_join
= 0;
3933 wpa_printf(MSG_DEBUG
, "P2P: Failed to find BSS/GO - try again later");
3934 eloop_cancel_timeout(wpas_p2p_join_scan
, wpa_s
, NULL
);
3935 eloop_register_timeout(1, 0, wpas_p2p_join_scan
, wpa_s
, NULL
);
3936 wpas_p2p_check_join_scan_limit(wpa_s
);
3940 /* Start join operation immediately */
3941 wpas_p2p_join_start(wpa_s
);
3945 static void wpas_p2p_join_scan_req(struct wpa_supplicant
*wpa_s
, int freq
)
3948 struct wpa_driver_scan_params params
;
3949 struct wpabuf
*wps_ie
, *ies
;
3951 int freqs
[2] = { 0, 0 };
3953 os_memset(¶ms
, 0, sizeof(params
));
3955 /* P2P Wildcard SSID */
3956 params
.num_ssids
= 1;
3957 params
.ssids
[0].ssid
= (u8
*) P2P_WILDCARD_SSID
;
3958 params
.ssids
[0].ssid_len
= P2P_WILDCARD_SSID_LEN
;
3960 wpa_s
->wps
->dev
.p2p
= 1;
3961 wps_ie
= wps_build_probe_req_ie(DEV_PW_DEFAULT
, &wpa_s
->wps
->dev
,
3962 wpa_s
->wps
->uuid
, WPS_REQ_ENROLLEE
, 0,
3964 if (wps_ie
== NULL
) {
3965 wpas_p2p_scan_res_join(wpa_s
, NULL
);
3969 ielen
= p2p_scan_ie_buf_len(wpa_s
->global
->p2p
);
3970 ies
= wpabuf_alloc(wpabuf_len(wps_ie
) + ielen
);
3972 wpabuf_free(wps_ie
);
3973 wpas_p2p_scan_res_join(wpa_s
, NULL
);
3976 wpabuf_put_buf(ies
, wps_ie
);
3977 wpabuf_free(wps_ie
);
3979 p2p_scan_ie(wpa_s
->global
->p2p
, ies
, NULL
);
3981 params
.p2p_probe
= 1;
3982 params
.extra_ies
= wpabuf_head(ies
);
3983 params
.extra_ies_len
= wpabuf_len(ies
);
3986 params
.freqs
= freqs
;
3990 * Run a scan to update BSS table and start Provision Discovery once
3991 * the new scan results become available.
3993 ret
= wpa_drv_scan(wpa_s
, ¶ms
);
3995 os_get_time(&wpa_s
->scan_trigger_time
);
3996 wpa_s
->scan_res_handler
= wpas_p2p_scan_res_join
;
4002 wpa_printf(MSG_DEBUG
, "P2P: Failed to start scan for join - "
4004 eloop_cancel_timeout(wpas_p2p_join_scan
, wpa_s
, NULL
);
4005 eloop_register_timeout(1, 0, wpas_p2p_join_scan
, wpa_s
, NULL
);
4006 wpas_p2p_check_join_scan_limit(wpa_s
);
4011 static void wpas_p2p_join_scan(void *eloop_ctx
, void *timeout_ctx
)
4013 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
4014 wpas_p2p_join_scan_req(wpa_s
, 0);
4018 static int wpas_p2p_join(struct wpa_supplicant
*wpa_s
, const u8
*iface_addr
,
4019 const u8
*dev_addr
, enum p2p_wps_method wps_method
,
4022 wpa_printf(MSG_DEBUG
, "P2P: Request to join existing group (iface "
4023 MACSTR
" dev " MACSTR
")%s",
4024 MAC2STR(iface_addr
), MAC2STR(dev_addr
),
4025 auto_join
? " (auto_join)" : "");
4027 wpa_s
->p2p_auto_pd
= 0;
4028 wpa_s
->p2p_auto_join
= !!auto_join
;
4029 os_memcpy(wpa_s
->pending_join_iface_addr
, iface_addr
, ETH_ALEN
);
4030 os_memcpy(wpa_s
->pending_join_dev_addr
, dev_addr
, ETH_ALEN
);
4031 wpa_s
->pending_join_wps_method
= wps_method
;
4033 /* Make sure we are not running find during connection establishment */
4034 wpas_p2p_stop_find(wpa_s
);
4036 wpa_s
->p2p_join_scan_count
= 0;
4037 wpas_p2p_join_scan(wpa_s
, NULL
);
4042 static int wpas_p2p_join_start(struct wpa_supplicant
*wpa_s
)
4044 struct wpa_supplicant
*group
;
4045 struct p2p_go_neg_results res
;
4046 struct wpa_bss
*bss
;
4048 group
= wpas_p2p_get_group_iface(wpa_s
, 0, 0);
4051 if (group
!= wpa_s
) {
4052 os_memcpy(group
->p2p_pin
, wpa_s
->p2p_pin
,
4053 sizeof(group
->p2p_pin
));
4054 group
->p2p_wps_method
= wpa_s
->p2p_wps_method
;
4057 * Need to mark the current interface for p2p_group_formation
4058 * when a separate group interface is not used. This is needed
4059 * to allow p2p_cancel stop a pending p2p_connect-join.
4060 * wpas_p2p_init_group_interface() addresses this for the case
4061 * where a separate group interface is used.
4063 wpa_s
->global
->p2p_group_formation
= wpa_s
;
4066 group
->p2p_in_provisioning
= 1;
4067 group
->p2p_fallback_to_go_neg
= wpa_s
->p2p_fallback_to_go_neg
;
4069 os_memset(&res
, 0, sizeof(res
));
4070 os_memcpy(res
.peer_interface_addr
, wpa_s
->pending_join_iface_addr
,
4072 res
.wps_method
= wpa_s
->pending_join_wps_method
;
4073 bss
= wpa_bss_get_bssid_latest(wpa_s
, wpa_s
->pending_join_iface_addr
);
4075 res
.freq
= bss
->freq
;
4076 res
.ssid_len
= bss
->ssid_len
;
4077 os_memcpy(res
.ssid
, bss
->ssid
, bss
->ssid_len
);
4078 wpa_printf(MSG_DEBUG
, "P2P: Join target GO operating frequency "
4079 "from BSS table: %d MHz (SSID %s)", bss
->freq
,
4080 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
4083 if (wpa_s
->off_channel_freq
|| wpa_s
->roc_waiting_drv_freq
) {
4084 wpa_printf(MSG_DEBUG
, "P2P: Cancel remain-on-channel prior to "
4086 wpa_drv_cancel_remain_on_channel(wpa_s
);
4087 wpa_s
->off_channel_freq
= 0;
4088 wpa_s
->roc_waiting_drv_freq
= 0;
4090 wpas_start_wps_enrollee(group
, &res
);
4093 * Allow a longer timeout for join-a-running-group than normal 15
4094 * second group formation timeout since the GO may not have authorized
4095 * our connection yet.
4097 eloop_cancel_timeout(wpas_p2p_group_formation_timeout
, wpa_s
, NULL
);
4098 eloop_register_timeout(60, 0, wpas_p2p_group_formation_timeout
,
4105 static int wpas_p2p_setup_freqs(struct wpa_supplicant
*wpa_s
, int freq
,
4106 int *force_freq
, int *pref_freq
, int go
)
4109 unsigned int freq_in_use
= 0, num
, i
;
4111 freqs
= os_calloc(wpa_s
->num_multichan_concurrent
, sizeof(int));
4115 num
= get_shared_radio_freqs(wpa_s
, freqs
,
4116 wpa_s
->num_multichan_concurrent
);
4117 wpa_printf(MSG_DEBUG
,
4118 "P2P: Setup freqs: freq=%d num_MCC=%d shared_freqs=%u",
4119 freq
, wpa_s
->num_multichan_concurrent
, num
);
4124 ret
= p2p_supported_freq(wpa_s
->global
->p2p
, freq
);
4126 ret
= p2p_supported_freq_cli(wpa_s
->global
->p2p
, freq
);
4128 wpa_printf(MSG_DEBUG
, "P2P: The forced channel "
4129 "(%u MHz) is not supported for P2P uses",
4135 for (i
= 0; i
< num
; i
++) {
4136 if (freqs
[i
] == freq
)
4140 if (num
== wpa_s
->num_multichan_concurrent
&& !freq_in_use
) {
4141 wpa_printf(MSG_DEBUG
, "P2P: Cannot start P2P group on %u MHz as there are no available channels",
4146 wpa_printf(MSG_DEBUG
, "P2P: Trying to force us to use the "
4147 "requested channel (%u MHz)", freq
);
4152 for (i
= 0; i
< num
; i
++) {
4153 if (!p2p_supported_freq(wpa_s
->global
->p2p
, freqs
[i
]))
4156 wpa_printf(MSG_DEBUG
, "P2P: Try to force us to use frequency (%u MHz) which is already in use",
4158 *force_freq
= freqs
[i
];
4160 if (*pref_freq
== 0 && num
< wpa_s
->num_multichan_concurrent
) {
4161 wpa_printf(MSG_DEBUG
, "P2P: Try to prefer a frequency we are already using");
4162 *pref_freq
= *force_freq
;
4168 if (num
< wpa_s
->num_multichan_concurrent
) {
4169 wpa_printf(MSG_DEBUG
, "P2P: Current operating channels are not available for P2P. Try to use another channel");
4172 wpa_printf(MSG_DEBUG
, "P2P: All channels are in use and none of them are P2P enabled. Cannot start P2P group");
4187 * wpas_p2p_connect - Request P2P Group Formation to be started
4188 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
4189 * @peer_addr: Address of the peer P2P Device
4190 * @pin: PIN to use during provisioning or %NULL to indicate PBC mode
4191 * @persistent_group: Whether to create a persistent group
4192 * @auto_join: Whether to select join vs. GO Negotiation automatically
4193 * @join: Whether to join an existing group (as a client) instead of starting
4194 * Group Owner negotiation; @peer_addr is BSSID in that case
4195 * @auth: Whether to only authorize the connection instead of doing that and
4196 * initiating Group Owner negotiation
4197 * @go_intent: GO Intent or -1 to use default
4198 * @freq: Frequency for the group or 0 for auto-selection
4199 * @persistent_id: Persistent group credentials to use for forcing GO
4200 * parameters or -1 to generate new values (SSID/passphrase)
4201 * @pd: Whether to send Provision Discovery prior to GO Negotiation as an
4202 * interoperability workaround when initiating group formation
4203 * @ht40: Start GO with 40 MHz channel width
4204 * @vht: Start GO with VHT support
4205 * Returns: 0 or new PIN (if pin was %NULL) on success, -1 on unspecified
4206 * failure, -2 on failure due to channel not currently available,
4207 * -3 if forced channel is not supported
4209 int wpas_p2p_connect(struct wpa_supplicant
*wpa_s
, const u8
*peer_addr
,
4210 const char *pin
, enum p2p_wps_method wps_method
,
4211 int persistent_group
, int auto_join
, int join
, int auth
,
4212 int go_intent
, int freq
, int persistent_id
, int pd
,
4215 int force_freq
= 0, pref_freq
= 0;
4217 enum wpa_driver_if_type iftype
;
4219 struct wpa_ssid
*ssid
= NULL
;
4221 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
4224 if (persistent_id
>= 0) {
4225 ssid
= wpa_config_get_network(wpa_s
->conf
, persistent_id
);
4226 if (ssid
== NULL
|| ssid
->disabled
!= 2 ||
4227 ssid
->mode
!= WPAS_MODE_P2P_GO
)
4231 os_free(wpa_s
->global
->add_psk
);
4232 wpa_s
->global
->add_psk
= NULL
;
4235 go_intent
= wpa_s
->conf
->p2p_go_intent
;
4238 wpa_s
->p2p_long_listen
= 0;
4240 wpa_s
->p2p_wps_method
= wps_method
;
4241 wpa_s
->p2p_persistent_group
= !!persistent_group
;
4242 wpa_s
->p2p_persistent_id
= persistent_id
;
4243 wpa_s
->p2p_go_intent
= go_intent
;
4244 wpa_s
->p2p_connect_freq
= freq
;
4245 wpa_s
->p2p_fallback_to_go_neg
= 0;
4246 wpa_s
->p2p_pd_before_go_neg
= !!pd
;
4247 wpa_s
->p2p_go_ht40
= !!ht40
;
4248 wpa_s
->p2p_go_vht
= !!vht
;
4251 os_strlcpy(wpa_s
->p2p_pin
, pin
, sizeof(wpa_s
->p2p_pin
));
4252 else if (wps_method
== WPS_PIN_DISPLAY
) {
4253 ret
= wps_generate_pin();
4254 os_snprintf(wpa_s
->p2p_pin
, sizeof(wpa_s
->p2p_pin
), "%08d",
4256 wpa_printf(MSG_DEBUG
, "P2P: Randomly generated PIN: %s",
4259 wpa_s
->p2p_pin
[0] = '\0';
4261 if (join
|| auto_join
) {
4262 u8 iface_addr
[ETH_ALEN
], dev_addr
[ETH_ALEN
];
4264 wpa_printf(MSG_DEBUG
, "P2P: Authorize invitation to "
4265 "connect a running group from " MACSTR
,
4266 MAC2STR(peer_addr
));
4267 os_memcpy(wpa_s
->p2p_auth_invite
, peer_addr
, ETH_ALEN
);
4270 os_memcpy(dev_addr
, peer_addr
, ETH_ALEN
);
4271 if (p2p_get_interface_addr(wpa_s
->global
->p2p
, peer_addr
,
4273 os_memcpy(iface_addr
, peer_addr
, ETH_ALEN
);
4274 p2p_get_dev_addr(wpa_s
->global
->p2p
, peer_addr
,
4278 os_get_time(&wpa_s
->p2p_auto_started
);
4279 wpa_printf(MSG_DEBUG
, "P2P: Auto join started at "
4281 wpa_s
->p2p_auto_started
.sec
,
4282 wpa_s
->p2p_auto_started
.usec
);
4284 wpa_s
->user_initiated_pd
= 1;
4285 if (wpas_p2p_join(wpa_s
, iface_addr
, dev_addr
, wps_method
,
4291 res
= wpas_p2p_setup_freqs(wpa_s
, freq
, &force_freq
, &pref_freq
,
4295 wpas_p2p_set_own_freq_preference(wpa_s
, force_freq
);
4297 wpa_s
->create_p2p_iface
= wpas_p2p_create_iface(wpa_s
);
4299 if (wpa_s
->create_p2p_iface
) {
4300 /* Prepare to add a new interface for the group */
4301 iftype
= WPA_IF_P2P_GROUP
;
4302 if (go_intent
== 15)
4303 iftype
= WPA_IF_P2P_GO
;
4304 if (wpas_p2p_add_group_interface(wpa_s
, iftype
) < 0) {
4305 wpa_printf(MSG_ERROR
, "P2P: Failed to allocate a new "
4306 "interface for the group");
4310 if_addr
= wpa_s
->pending_interface_addr
;
4312 if_addr
= wpa_s
->own_addr
;
4315 if (wpas_p2p_auth_go_neg(wpa_s
, peer_addr
, wps_method
,
4317 force_freq
, persistent_group
, ssid
,
4323 if (wpas_p2p_start_go_neg(wpa_s
, peer_addr
, wps_method
,
4324 go_intent
, if_addr
, force_freq
,
4325 persistent_group
, ssid
, pref_freq
) < 0) {
4326 if (wpa_s
->create_p2p_iface
)
4327 wpas_p2p_remove_pending_group_interface(wpa_s
);
4335 * wpas_p2p_remain_on_channel_cb - Indication of remain-on-channel start
4336 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
4337 * @freq: Frequency of the channel in MHz
4338 * @duration: Duration of the stay on the channel in milliseconds
4340 * This callback is called when the driver indicates that it has started the
4341 * requested remain-on-channel duration.
4343 void wpas_p2p_remain_on_channel_cb(struct wpa_supplicant
*wpa_s
,
4344 unsigned int freq
, unsigned int duration
)
4346 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
4348 if (wpa_s
->off_channel_freq
== wpa_s
->pending_listen_freq
) {
4349 p2p_listen_cb(wpa_s
->global
->p2p
, wpa_s
->pending_listen_freq
,
4350 wpa_s
->pending_listen_duration
);
4351 wpa_s
->pending_listen_freq
= 0;
4356 static int wpas_p2p_listen_start(struct wpa_supplicant
*wpa_s
,
4357 unsigned int timeout
)
4359 /* Limit maximum Listen state time based on driver limitation. */
4360 if (timeout
> wpa_s
->max_remain_on_chan
)
4361 timeout
= wpa_s
->max_remain_on_chan
;
4363 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
)
4364 return wpa_drv_p2p_listen(wpa_s
, timeout
);
4366 return p2p_listen(wpa_s
->global
->p2p
, timeout
);
4371 * wpas_p2p_cancel_remain_on_channel_cb - Remain-on-channel timeout
4372 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
4373 * @freq: Frequency of the channel in MHz
4375 * This callback is called when the driver indicates that a remain-on-channel
4376 * operation has been completed, i.e., the duration on the requested channel
4379 void wpas_p2p_cancel_remain_on_channel_cb(struct wpa_supplicant
*wpa_s
,
4382 wpa_printf(MSG_DEBUG
, "P2P: Cancel remain-on-channel callback "
4383 "(p2p_long_listen=%d ms pending_action_tx=%p)",
4384 wpa_s
->p2p_long_listen
, offchannel_pending_action_tx(wpa_s
));
4385 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
4387 if (p2p_listen_end(wpa_s
->global
->p2p
, freq
) > 0)
4388 return; /* P2P module started a new operation */
4389 if (offchannel_pending_action_tx(wpa_s
))
4391 if (wpa_s
->p2p_long_listen
> 0)
4392 wpa_s
->p2p_long_listen
-= wpa_s
->max_remain_on_chan
;
4393 if (wpa_s
->p2p_long_listen
> 0) {
4394 wpa_printf(MSG_DEBUG
, "P2P: Continuing long Listen state");
4395 wpas_p2p_listen_start(wpa_s
, wpa_s
->p2p_long_listen
);
4398 * When listen duration is over, stop listen & update p2p_state
4401 p2p_stop_listen(wpa_s
->global
->p2p
);
4407 * wpas_p2p_group_remove - Remove a P2P group
4408 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
4409 * @ifname: Network interface name of the group interface or "*" to remove all
4411 * Returns: 0 on success, -1 on failure
4413 * This function is used to remove a P2P group. This can be used to disconnect
4414 * from a group in which the local end is a P2P Client or to end a P2P Group in
4415 * case the local end is the Group Owner. If a virtual network interface was
4416 * created for this group, that interface will be removed. Otherwise, only the
4417 * configured P2P group network will be removed from the interface.
4419 int wpas_p2p_group_remove(struct wpa_supplicant
*wpa_s
, const char *ifname
)
4421 struct wpa_global
*global
= wpa_s
->global
;
4423 if (os_strcmp(ifname
, "*") == 0) {
4424 struct wpa_supplicant
*prev
;
4425 wpa_s
= global
->ifaces
;
4428 wpa_s
= wpa_s
->next
;
4429 if (prev
->p2p_group_interface
!=
4430 NOT_P2P_GROUP_INTERFACE
||
4431 (prev
->current_ssid
&&
4432 prev
->current_ssid
->p2p_group
))
4433 wpas_p2p_disconnect(prev
);
4438 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
4439 if (os_strcmp(wpa_s
->ifname
, ifname
) == 0)
4443 return wpas_p2p_disconnect(wpa_s
);
4447 static int wpas_p2p_select_go_freq(struct wpa_supplicant
*wpa_s
, int freq
)
4452 wpa_printf(MSG_DEBUG
, "P2P: Request to start GO on 2.4 GHz "
4454 if (wpa_s
->best_24_freq
> 0 &&
4455 p2p_supported_freq_go(wpa_s
->global
->p2p
,
4456 wpa_s
->best_24_freq
)) {
4457 freq
= wpa_s
->best_24_freq
;
4458 wpa_printf(MSG_DEBUG
, "P2P: Use best 2.4 GHz band "
4459 "channel: %d MHz", freq
);
4461 os_get_random((u8
*) &r
, sizeof(r
));
4462 freq
= 2412 + (r
% 3) * 25;
4463 wpa_printf(MSG_DEBUG
, "P2P: Use random 2.4 GHz band "
4464 "channel: %d MHz", freq
);
4469 wpa_printf(MSG_DEBUG
, "P2P: Request to start GO on 5 GHz "
4471 if (wpa_s
->best_5_freq
> 0 &&
4472 p2p_supported_freq_go(wpa_s
->global
->p2p
,
4473 wpa_s
->best_5_freq
)) {
4474 freq
= wpa_s
->best_5_freq
;
4475 wpa_printf(MSG_DEBUG
, "P2P: Use best 5 GHz band "
4476 "channel: %d MHz", freq
);
4478 os_get_random((u8
*) &r
, sizeof(r
));
4479 freq
= 5180 + (r
% 4) * 20;
4480 if (!p2p_supported_freq_go(wpa_s
->global
->p2p
, freq
)) {
4481 wpa_printf(MSG_DEBUG
, "P2P: Could not select "
4482 "5 GHz channel for P2P group");
4485 wpa_printf(MSG_DEBUG
, "P2P: Use random 5 GHz band "
4486 "channel: %d MHz", freq
);
4490 if (freq
> 0 && !p2p_supported_freq_go(wpa_s
->global
->p2p
, freq
)) {
4491 wpa_printf(MSG_DEBUG
, "P2P: The forced channel for GO "
4492 "(%u MHz) is not supported for P2P uses",
4501 static int wpas_p2p_init_go_params(struct wpa_supplicant
*wpa_s
,
4502 struct p2p_go_neg_results
*params
,
4503 int freq
, int ht40
, int vht
,
4504 const struct p2p_channels
*channels
)
4507 unsigned int pref_freq
;
4508 unsigned int num
, i
;
4510 os_memset(params
, 0, sizeof(*params
));
4511 params
->role_go
= 1;
4512 params
->ht40
= ht40
;
4515 if (!freq_included(channels
, freq
)) {
4516 wpa_printf(MSG_DEBUG
, "P2P: Forced GO freq %d MHz not "
4520 wpa_printf(MSG_DEBUG
, "P2P: Set GO freq based on forced "
4521 "frequency %d MHz", freq
);
4522 params
->freq
= freq
;
4523 } else if (wpa_s
->conf
->p2p_oper_reg_class
== 81 &&
4524 wpa_s
->conf
->p2p_oper_channel
>= 1 &&
4525 wpa_s
->conf
->p2p_oper_channel
<= 11 &&
4526 freq_included(channels
,
4527 2407 + 5 * wpa_s
->conf
->p2p_oper_channel
)) {
4528 params
->freq
= 2407 + 5 * wpa_s
->conf
->p2p_oper_channel
;
4529 wpa_printf(MSG_DEBUG
, "P2P: Set GO freq based on configured "
4530 "frequency %d MHz", params
->freq
);
4531 } else if ((wpa_s
->conf
->p2p_oper_reg_class
== 115 ||
4532 wpa_s
->conf
->p2p_oper_reg_class
== 116 ||
4533 wpa_s
->conf
->p2p_oper_reg_class
== 117 ||
4534 wpa_s
->conf
->p2p_oper_reg_class
== 124 ||
4535 wpa_s
->conf
->p2p_oper_reg_class
== 126 ||
4536 wpa_s
->conf
->p2p_oper_reg_class
== 127) &&
4537 freq_included(channels
,
4538 5000 + 5 * wpa_s
->conf
->p2p_oper_channel
)) {
4539 params
->freq
= 5000 + 5 * wpa_s
->conf
->p2p_oper_channel
;
4540 wpa_printf(MSG_DEBUG
, "P2P: Set GO freq based on configured "
4541 "frequency %d MHz", params
->freq
);
4542 } else if (wpa_s
->conf
->p2p_oper_channel
== 0 &&
4543 wpa_s
->best_overall_freq
> 0 &&
4544 p2p_supported_freq_go(wpa_s
->global
->p2p
,
4545 wpa_s
->best_overall_freq
) &&
4546 freq_included(channels
, wpa_s
->best_overall_freq
)) {
4547 params
->freq
= wpa_s
->best_overall_freq
;
4548 wpa_printf(MSG_DEBUG
, "P2P: Set GO freq based on best overall "
4549 "channel %d MHz", params
->freq
);
4550 } else if (wpa_s
->conf
->p2p_oper_channel
== 0 &&
4551 wpa_s
->best_24_freq
> 0 &&
4552 p2p_supported_freq_go(wpa_s
->global
->p2p
,
4553 wpa_s
->best_24_freq
) &&
4554 freq_included(channels
, wpa_s
->best_24_freq
)) {
4555 params
->freq
= wpa_s
->best_24_freq
;
4556 wpa_printf(MSG_DEBUG
, "P2P: Set GO freq based on best 2.4 GHz "
4557 "channel %d MHz", params
->freq
);
4558 } else if (wpa_s
->conf
->p2p_oper_channel
== 0 &&
4559 wpa_s
->best_5_freq
> 0 &&
4560 p2p_supported_freq_go(wpa_s
->global
->p2p
,
4561 wpa_s
->best_5_freq
) &&
4562 freq_included(channels
, wpa_s
->best_5_freq
)) {
4563 params
->freq
= wpa_s
->best_5_freq
;
4564 wpa_printf(MSG_DEBUG
, "P2P: Set GO freq based on best 5 GHz "
4565 "channel %d MHz", params
->freq
);
4566 } else if ((pref_freq
= p2p_get_pref_freq(wpa_s
->global
->p2p
,
4568 params
->freq
= pref_freq
;
4569 wpa_printf(MSG_DEBUG
, "P2P: Set GO freq %d MHz from preferred "
4570 "channels", params
->freq
);
4573 for (chan
= 0; chan
< 11; chan
++) {
4574 params
->freq
= 2412 + chan
* 5;
4575 if (!wpas_p2p_disallowed_freq(wpa_s
->global
,
4577 freq_included(channels
, params
->freq
))
4581 wpa_printf(MSG_DEBUG
, "P2P: No 2.4 GHz channel "
4585 wpa_printf(MSG_DEBUG
, "P2P: Set GO freq %d MHz (no preference "
4586 "known)", params
->freq
);
4589 freqs
= os_calloc(wpa_s
->num_multichan_concurrent
, sizeof(int));
4593 res
= wpas_p2p_valid_oper_freqs(wpa_s
, freqs
,
4594 wpa_s
->num_multichan_concurrent
);
4602 for (i
= 0; i
< num
; i
++) {
4603 if (freq_included(channels
, freqs
[i
])) {
4604 wpa_printf(MSG_DEBUG
, "P2P: Force GO on a channel we are already using (%u MHz)",
4606 params
->freq
= freqs
[i
];
4612 if (wpas_p2p_num_unused_channels(wpa_s
) <= 0) {
4613 wpa_printf(MSG_DEBUG
, "P2P: Cannot force GO on any of the channels we are already using");
4617 wpa_printf(MSG_DEBUG
, "P2P: Cannot force GO on any of the channels we are already using. Use one of the free channels");
4621 for (i
= 0; i
< num
; i
++) {
4622 if (freqs
[i
] == freq
)
4627 if (wpas_p2p_num_unused_channels(wpa_s
) <= 0) {
4628 wpa_printf(MSG_DEBUG
, "P2P: Cannot force GO on freq (%u MHz) as all the channels are in use", freq
);
4632 wpa_printf(MSG_DEBUG
, "P2P: Cannot force GO on any of the channels we are already using. Use one of the free channels");
4641 static struct wpa_supplicant
*
4642 wpas_p2p_get_group_iface(struct wpa_supplicant
*wpa_s
, int addr_allocated
,
4645 struct wpa_supplicant
*group_wpa_s
;
4647 if (!wpas_p2p_create_iface(wpa_s
)) {
4648 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Use same interface for group "
4650 wpa_s
->p2p_first_connection_timeout
= 0;
4654 if (wpas_p2p_add_group_interface(wpa_s
, go
? WPA_IF_P2P_GO
:
4655 WPA_IF_P2P_CLIENT
) < 0) {
4656 wpa_msg_global(wpa_s
, MSG_ERROR
,
4657 "P2P: Failed to add group interface");
4660 group_wpa_s
= wpas_p2p_init_group_interface(wpa_s
, go
);
4661 if (group_wpa_s
== NULL
) {
4662 wpa_msg_global(wpa_s
, MSG_ERROR
,
4663 "P2P: Failed to initialize group interface");
4664 wpas_p2p_remove_pending_group_interface(wpa_s
);
4668 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Use separate group interface %s",
4669 group_wpa_s
->ifname
);
4670 group_wpa_s
->p2p_first_connection_timeout
= 0;
4676 * wpas_p2p_group_add - Add a new P2P group with local end as Group Owner
4677 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
4678 * @persistent_group: Whether to create a persistent group
4679 * @freq: Frequency for the group or 0 to indicate no hardcoding
4680 * @ht40: Start GO with 40 MHz channel width
4681 * @vht: Start GO with VHT support
4682 * Returns: 0 on success, -1 on failure
4684 * This function creates a new P2P group with the local end as the Group Owner,
4685 * i.e., without using Group Owner Negotiation.
4687 int wpas_p2p_group_add(struct wpa_supplicant
*wpa_s
, int persistent_group
,
4688 int freq
, int ht40
, int vht
)
4690 struct p2p_go_neg_results params
;
4692 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
4695 os_free(wpa_s
->global
->add_psk
);
4696 wpa_s
->global
->add_psk
= NULL
;
4698 /* Make sure we are not running find during connection establishment */
4699 wpa_printf(MSG_DEBUG
, "P2P: Stop any on-going P2P FIND");
4700 wpas_p2p_stop_find_oper(wpa_s
);
4702 freq
= wpas_p2p_select_go_freq(wpa_s
, freq
);
4706 if (wpas_p2p_init_go_params(wpa_s
, ¶ms
, freq
, ht40
, vht
, NULL
))
4709 !p2p_supported_freq_go(wpa_s
->global
->p2p
, params
.freq
)) {
4710 wpa_printf(MSG_DEBUG
, "P2P: The selected channel for GO "
4711 "(%u MHz) is not supported for P2P uses",
4715 p2p_go_params(wpa_s
->global
->p2p
, ¶ms
);
4716 params
.persistent_group
= persistent_group
;
4718 wpa_s
= wpas_p2p_get_group_iface(wpa_s
, 0, 1);
4721 wpas_start_wps_go(wpa_s
, ¶ms
, 0);
4727 static int wpas_start_p2p_client(struct wpa_supplicant
*wpa_s
,
4728 struct wpa_ssid
*params
, int addr_allocated
)
4730 struct wpa_ssid
*ssid
;
4732 wpa_s
= wpas_p2p_get_group_iface(wpa_s
, addr_allocated
, 0);
4735 wpa_s
->p2p_last_4way_hs_fail
= NULL
;
4737 wpa_supplicant_ap_deinit(wpa_s
);
4739 ssid
= wpa_config_add_network(wpa_s
->conf
);
4742 wpa_config_set_network_defaults(ssid
);
4743 ssid
->temporary
= 1;
4744 ssid
->proto
= WPA_PROTO_RSN
;
4745 ssid
->pairwise_cipher
= WPA_CIPHER_CCMP
;
4746 ssid
->group_cipher
= WPA_CIPHER_CCMP
;
4747 ssid
->key_mgmt
= WPA_KEY_MGMT_PSK
;
4748 ssid
->ssid
= os_malloc(params
->ssid_len
);
4749 if (ssid
->ssid
== NULL
) {
4750 wpa_config_remove_network(wpa_s
->conf
, ssid
->id
);
4753 os_memcpy(ssid
->ssid
, params
->ssid
, params
->ssid_len
);
4754 ssid
->ssid_len
= params
->ssid_len
;
4755 ssid
->p2p_group
= 1;
4756 ssid
->export_keys
= 1;
4757 if (params
->psk_set
) {
4758 os_memcpy(ssid
->psk
, params
->psk
, 32);
4761 if (params
->passphrase
)
4762 ssid
->passphrase
= os_strdup(params
->passphrase
);
4764 wpa_supplicant_select_network(wpa_s
, ssid
);
4766 wpa_s
->show_group_started
= 1;
4772 int wpas_p2p_group_add_persistent(struct wpa_supplicant
*wpa_s
,
4773 struct wpa_ssid
*ssid
, int addr_allocated
,
4774 int freq
, int ht40
, int vht
,
4775 const struct p2p_channels
*channels
,
4776 int connection_timeout
)
4778 struct p2p_go_neg_results params
;
4781 if (ssid
->disabled
!= 2 || ssid
->ssid
== NULL
)
4784 if (wpas_get_p2p_group(wpa_s
, ssid
->ssid
, ssid
->ssid_len
, &go
) &&
4785 go
== (ssid
->mode
== WPAS_MODE_P2P_GO
)) {
4786 wpa_printf(MSG_DEBUG
, "P2P: Requested persistent group is "
4791 os_free(wpa_s
->global
->add_psk
);
4792 wpa_s
->global
->add_psk
= NULL
;
4794 /* Make sure we are not running find during connection establishment */
4795 wpas_p2p_stop_find_oper(wpa_s
);
4797 wpa_s
->p2p_fallback_to_go_neg
= 0;
4799 if (ssid
->mode
== WPAS_MODE_INFRA
)
4800 return wpas_start_p2p_client(wpa_s
, ssid
, addr_allocated
);
4802 if (ssid
->mode
!= WPAS_MODE_P2P_GO
)
4805 freq
= wpas_p2p_select_go_freq(wpa_s
, freq
);
4809 if (wpas_p2p_init_go_params(wpa_s
, ¶ms
, freq
, ht40
, vht
, channels
))
4813 params
.psk_set
= ssid
->psk_set
;
4815 os_memcpy(params
.psk
, ssid
->psk
, sizeof(params
.psk
));
4816 if (ssid
->passphrase
) {
4817 if (os_strlen(ssid
->passphrase
) >= sizeof(params
.passphrase
)) {
4818 wpa_printf(MSG_ERROR
, "P2P: Invalid passphrase in "
4819 "persistent group");
4822 os_strlcpy(params
.passphrase
, ssid
->passphrase
,
4823 sizeof(params
.passphrase
));
4825 os_memcpy(params
.ssid
, ssid
->ssid
, ssid
->ssid_len
);
4826 params
.ssid_len
= ssid
->ssid_len
;
4827 params
.persistent_group
= 1;
4829 wpa_s
= wpas_p2p_get_group_iface(wpa_s
, addr_allocated
, 1);
4833 wpa_s
->p2p_first_connection_timeout
= connection_timeout
;
4834 wpas_start_wps_go(wpa_s
, ¶ms
, 0);
4840 static void wpas_p2p_ie_update(void *ctx
, struct wpabuf
*beacon_ies
,
4841 struct wpabuf
*proberesp_ies
)
4843 struct wpa_supplicant
*wpa_s
= ctx
;
4844 if (wpa_s
->ap_iface
) {
4845 struct hostapd_data
*hapd
= wpa_s
->ap_iface
->bss
[0];
4846 if (!(hapd
->conf
->p2p
& P2P_GROUP_OWNER
)) {
4847 wpabuf_free(beacon_ies
);
4848 wpabuf_free(proberesp_ies
);
4852 wpabuf_free(hapd
->p2p_beacon_ie
);
4853 hapd
->p2p_beacon_ie
= beacon_ies
;
4855 wpabuf_free(hapd
->p2p_probe_resp_ie
);
4856 hapd
->p2p_probe_resp_ie
= proberesp_ies
;
4858 wpabuf_free(beacon_ies
);
4859 wpabuf_free(proberesp_ies
);
4861 wpa_supplicant_ap_update_beacon(wpa_s
);
4865 static void wpas_p2p_idle_update(void *ctx
, int idle
)
4867 struct wpa_supplicant
*wpa_s
= ctx
;
4868 if (!wpa_s
->ap_iface
)
4870 wpa_printf(MSG_DEBUG
, "P2P: GO - group %sidle", idle
? "" : "not ");
4872 wpas_p2p_set_group_idle_timeout(wpa_s
);
4874 eloop_cancel_timeout(wpas_p2p_group_idle_timeout
, wpa_s
, NULL
);
4878 struct p2p_group
* wpas_p2p_group_init(struct wpa_supplicant
*wpa_s
,
4879 struct wpa_ssid
*ssid
)
4881 struct p2p_group
*group
;
4882 struct p2p_group_config
*cfg
;
4884 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
)
4886 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
4889 cfg
= os_zalloc(sizeof(*cfg
));
4893 if (ssid
->p2p_persistent_group
&& wpa_s
->conf
->persistent_reconnect
)
4894 cfg
->persistent_group
= 2;
4895 else if (ssid
->p2p_persistent_group
)
4896 cfg
->persistent_group
= 1;
4897 os_memcpy(cfg
->interface_addr
, wpa_s
->own_addr
, ETH_ALEN
);
4898 if (wpa_s
->max_stations
&&
4899 wpa_s
->max_stations
< wpa_s
->conf
->max_num_sta
)
4900 cfg
->max_clients
= wpa_s
->max_stations
;
4902 cfg
->max_clients
= wpa_s
->conf
->max_num_sta
;
4903 os_memcpy(cfg
->ssid
, ssid
->ssid
, ssid
->ssid_len
);
4904 cfg
->ssid_len
= ssid
->ssid_len
;
4905 cfg
->cb_ctx
= wpa_s
;
4906 cfg
->ie_update
= wpas_p2p_ie_update
;
4907 cfg
->idle_update
= wpas_p2p_idle_update
;
4909 group
= p2p_group_init(wpa_s
->global
->p2p
, cfg
);
4912 if (ssid
->mode
!= WPAS_MODE_P2P_GROUP_FORMATION
)
4913 p2p_group_notif_formation_done(group
);
4914 wpa_s
->p2p_group
= group
;
4919 void wpas_p2p_wps_success(struct wpa_supplicant
*wpa_s
, const u8
*peer_addr
,
4922 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
4924 if (!wpa_s
->p2p_in_provisioning
) {
4925 wpa_printf(MSG_DEBUG
, "P2P: Ignore WPS success event - P2P "
4926 "provisioning not in progress");
4930 if (ssid
&& ssid
->mode
== WPAS_MODE_INFRA
) {
4931 u8 go_dev_addr
[ETH_ALEN
];
4932 os_memcpy(go_dev_addr
, wpa_s
->bssid
, ETH_ALEN
);
4933 wpas_p2p_persistent_group(wpa_s
, go_dev_addr
, ssid
->ssid
,
4935 /* Clear any stored provisioning info */
4936 p2p_clear_provisioning_info(wpa_s
->global
->p2p
, go_dev_addr
);
4939 eloop_cancel_timeout(wpas_p2p_group_formation_timeout
, wpa_s
->parent
,
4941 wpa_s
->p2p_go_group_formation_completed
= 1;
4942 if (ssid
&& ssid
->mode
== WPAS_MODE_INFRA
) {
4944 * Use a separate timeout for initial data connection to
4945 * complete to allow the group to be removed automatically if
4946 * something goes wrong in this step before the P2P group idle
4947 * timeout mechanism is taken into use.
4949 wpa_dbg(wpa_s
, MSG_DEBUG
,
4950 "P2P: Re-start group formation timeout (%d seconds) as client for initial connection",
4951 P2P_MAX_INITIAL_CONN_WAIT
);
4952 eloop_register_timeout(P2P_MAX_INITIAL_CONN_WAIT
, 0,
4953 wpas_p2p_group_formation_timeout
,
4954 wpa_s
->parent
, NULL
);
4957 * Use a separate timeout for initial data connection to
4958 * complete to allow the group to be removed automatically if
4959 * the client does not complete data connection successfully.
4961 wpa_dbg(wpa_s
, MSG_DEBUG
,
4962 "P2P: Re-start group formation timeout (%d seconds) as GO for initial connection",
4963 P2P_MAX_INITIAL_CONN_WAIT_GO
);
4964 eloop_register_timeout(P2P_MAX_INITIAL_CONN_WAIT_GO
, 0,
4965 wpas_p2p_group_formation_timeout
,
4966 wpa_s
->parent
, NULL
);
4968 * Complete group formation on first successful data connection
4970 wpa_s
->p2p_go_group_formation_completed
= 0;
4972 if (wpa_s
->global
->p2p
)
4973 p2p_wps_success_cb(wpa_s
->global
->p2p
, peer_addr
);
4974 else if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
)
4975 wpa_drv_wps_success_cb(wpa_s
, peer_addr
);
4976 wpas_group_formation_completed(wpa_s
, 1);
4980 void wpas_p2p_wps_failed(struct wpa_supplicant
*wpa_s
,
4981 struct wps_event_fail
*fail
)
4983 if (!wpa_s
->p2p_in_provisioning
) {
4984 wpa_printf(MSG_DEBUG
, "P2P: Ignore WPS fail event - P2P "
4985 "provisioning not in progress");
4989 if (wpa_s
->go_params
) {
4990 p2p_clear_provisioning_info(
4992 wpa_s
->go_params
->peer_device_addr
);
4995 wpas_notify_p2p_wps_failed(wpa_s
, fail
);
4999 int wpas_p2p_prov_disc(struct wpa_supplicant
*wpa_s
, const u8
*peer_addr
,
5000 const char *config_method
,
5001 enum wpas_p2p_prov_disc_use use
)
5005 wpa_s
->p2p_fallback_to_go_neg
= 0;
5006 wpa_s
->pending_pd_use
= NORMAL_PD
;
5007 if (os_strncmp(config_method
, "display", 7) == 0)
5008 config_methods
= WPS_CONFIG_DISPLAY
;
5009 else if (os_strncmp(config_method
, "keypad", 6) == 0)
5010 config_methods
= WPS_CONFIG_KEYPAD
;
5011 else if (os_strncmp(config_method
, "pbc", 3) == 0 ||
5012 os_strncmp(config_method
, "pushbutton", 10) == 0)
5013 config_methods
= WPS_CONFIG_PUSHBUTTON
;
5015 wpa_printf(MSG_DEBUG
, "P2P: Unknown config method");
5019 if (use
== WPAS_P2P_PD_AUTO
) {
5020 os_memcpy(wpa_s
->pending_join_dev_addr
, peer_addr
, ETH_ALEN
);
5021 wpa_s
->pending_pd_config_methods
= config_methods
;
5022 wpa_s
->p2p_auto_pd
= 1;
5023 wpa_s
->p2p_auto_join
= 0;
5024 wpa_s
->pending_pd_before_join
= 0;
5025 wpa_s
->auto_pd_scan_retry
= 0;
5026 wpas_p2p_stop_find(wpa_s
);
5027 wpa_s
->p2p_join_scan_count
= 0;
5028 os_get_time(&wpa_s
->p2p_auto_started
);
5029 wpa_printf(MSG_DEBUG
, "P2P: Auto PD started at %ld.%06ld",
5030 wpa_s
->p2p_auto_started
.sec
,
5031 wpa_s
->p2p_auto_started
.usec
);
5032 wpas_p2p_join_scan(wpa_s
, NULL
);
5036 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
) {
5037 return wpa_drv_p2p_prov_disc_req(wpa_s
, peer_addr
,
5039 use
== WPAS_P2P_PD_FOR_JOIN
);
5042 if (wpa_s
->global
->p2p
== NULL
|| wpa_s
->global
->p2p_disabled
)
5045 return p2p_prov_disc_req(wpa_s
->global
->p2p
, peer_addr
,
5046 config_methods
, use
== WPAS_P2P_PD_FOR_JOIN
,
5051 int wpas_p2p_scan_result_text(const u8
*ies
, size_t ies_len
, char *buf
,
5054 return p2p_scan_result_text(ies
, ies_len
, buf
, end
);
5058 static void wpas_p2p_clear_pending_action_tx(struct wpa_supplicant
*wpa_s
)
5060 if (!offchannel_pending_action_tx(wpa_s
))
5063 wpa_printf(MSG_DEBUG
, "P2P: Drop pending Action TX due to new "
5064 "operation request");
5065 offchannel_clear_pending_action_tx(wpa_s
);
5069 int wpas_p2p_find(struct wpa_supplicant
*wpa_s
, unsigned int timeout
,
5070 enum p2p_discovery_type type
,
5071 unsigned int num_req_dev_types
, const u8
*req_dev_types
,
5072 const u8
*dev_id
, unsigned int search_delay
)
5074 wpas_p2p_clear_pending_action_tx(wpa_s
);
5075 wpa_s
->p2p_long_listen
= 0;
5077 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
)
5078 return wpa_drv_p2p_find(wpa_s
, timeout
, type
);
5080 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
||
5081 wpa_s
->p2p_in_provisioning
)
5084 wpa_supplicant_cancel_sched_scan(wpa_s
);
5086 return p2p_find(wpa_s
->global
->p2p
, timeout
, type
,
5087 num_req_dev_types
, req_dev_types
, dev_id
,
5092 static int wpas_p2p_stop_find_oper(struct wpa_supplicant
*wpa_s
)
5094 wpas_p2p_clear_pending_action_tx(wpa_s
);
5095 wpa_s
->p2p_long_listen
= 0;
5096 eloop_cancel_timeout(wpas_p2p_long_listen_timeout
, wpa_s
, NULL
);
5097 eloop_cancel_timeout(wpas_p2p_join_scan
, wpa_s
, NULL
);
5098 wpa_s
->global
->p2p_cb_on_scan_complete
= 0;
5100 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
) {
5101 wpa_drv_p2p_stop_find(wpa_s
);
5105 if (wpa_s
->global
->p2p
)
5106 p2p_stop_find(wpa_s
->global
->p2p
);
5112 void wpas_p2p_stop_find(struct wpa_supplicant
*wpa_s
)
5114 if (wpas_p2p_stop_find_oper(wpa_s
) > 0)
5116 wpas_p2p_remove_pending_group_interface(wpa_s
);
5120 static void wpas_p2p_long_listen_timeout(void *eloop_ctx
, void *timeout_ctx
)
5122 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
5123 wpa_s
->p2p_long_listen
= 0;
5127 int wpas_p2p_listen(struct wpa_supplicant
*wpa_s
, unsigned int timeout
)
5131 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
5134 wpa_supplicant_cancel_sched_scan(wpa_s
);
5135 wpas_p2p_clear_pending_action_tx(wpa_s
);
5139 * This is a request for unlimited Listen state. However, at
5140 * least for now, this is mapped to a Listen state for one
5145 eloop_cancel_timeout(wpas_p2p_long_listen_timeout
, wpa_s
, NULL
);
5146 wpa_s
->p2p_long_listen
= 0;
5149 * Stop previous find/listen operation to avoid trying to request a new
5150 * remain-on-channel operation while the driver is still running the
5153 if (wpa_s
->global
->p2p
)
5154 p2p_stop_find(wpa_s
->global
->p2p
);
5156 res
= wpas_p2p_listen_start(wpa_s
, timeout
* 1000);
5157 if (res
== 0 && timeout
* 1000 > wpa_s
->max_remain_on_chan
) {
5158 wpa_s
->p2p_long_listen
= timeout
* 1000;
5159 eloop_register_timeout(timeout
, 0,
5160 wpas_p2p_long_listen_timeout
,
5168 int wpas_p2p_assoc_req_ie(struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
,
5169 u8
*buf
, size_t len
, int p2p_group
)
5171 struct wpabuf
*p2p_ie
;
5174 if (wpa_s
->global
->p2p_disabled
)
5176 if (wpa_s
->global
->p2p
== NULL
)
5181 p2p_ie
= wpa_bss_get_vendor_ie_multi(bss
, P2P_IE_VENDOR_TYPE
);
5182 ret
= p2p_assoc_req_ie(wpa_s
->global
->p2p
, bss
->bssid
, buf
, len
,
5184 wpabuf_free(p2p_ie
);
5190 int wpas_p2p_probe_req_rx(struct wpa_supplicant
*wpa_s
, const u8
*addr
,
5191 const u8
*dst
, const u8
*bssid
,
5192 const u8
*ie
, size_t ie_len
, int ssi_signal
)
5194 if (wpa_s
->global
->p2p_disabled
)
5196 if (wpa_s
->global
->p2p
== NULL
)
5199 switch (p2p_probe_req_rx(wpa_s
->global
->p2p
, addr
, dst
, bssid
,
5201 case P2P_PREQ_NOT_P2P
:
5202 wpas_notify_preq(wpa_s
, addr
, dst
, bssid
, ie
, ie_len
,
5205 case P2P_PREQ_MALFORMED
:
5206 case P2P_PREQ_NOT_LISTEN
:
5207 case P2P_PREQ_NOT_PROCESSED
:
5208 default: /* make gcc happy */
5210 case P2P_PREQ_PROCESSED
:
5216 void wpas_p2p_rx_action(struct wpa_supplicant
*wpa_s
, const u8
*da
,
5217 const u8
*sa
, const u8
*bssid
,
5218 u8 category
, const u8
*data
, size_t len
, int freq
)
5220 if (wpa_s
->global
->p2p_disabled
)
5222 if (wpa_s
->global
->p2p
== NULL
)
5225 p2p_rx_action(wpa_s
->global
->p2p
, da
, sa
, bssid
, category
, data
, len
,
5230 void wpas_p2p_scan_ie(struct wpa_supplicant
*wpa_s
, struct wpabuf
*ies
)
5232 if (wpa_s
->global
->p2p_disabled
)
5234 if (wpa_s
->global
->p2p
== NULL
)
5237 p2p_scan_ie(wpa_s
->global
->p2p
, ies
, NULL
);
5241 void wpas_p2p_group_deinit(struct wpa_supplicant
*wpa_s
)
5243 p2p_group_deinit(wpa_s
->p2p_group
);
5244 wpa_s
->p2p_group
= NULL
;
5246 wpa_s
->ap_configured_cb
= NULL
;
5247 wpa_s
->ap_configured_cb_ctx
= NULL
;
5248 wpa_s
->ap_configured_cb_data
= NULL
;
5249 wpa_s
->connect_without_scan
= NULL
;
5253 int wpas_p2p_reject(struct wpa_supplicant
*wpa_s
, const u8
*addr
)
5255 wpa_s
->p2p_long_listen
= 0;
5257 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
)
5258 return wpa_drv_p2p_reject(wpa_s
, addr
);
5260 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
5263 return p2p_reject(wpa_s
->global
->p2p
, addr
);
5267 /* Invite to reinvoke a persistent group */
5268 int wpas_p2p_invite(struct wpa_supplicant
*wpa_s
, const u8
*peer_addr
,
5269 struct wpa_ssid
*ssid
, const u8
*go_dev_addr
, int freq
,
5270 int ht40
, int vht
, int pref_freq
)
5272 enum p2p_invite_role role
;
5277 wpa_s
->global
->p2p_invite_group
= NULL
;
5279 os_memcpy(wpa_s
->p2p_auth_invite
, peer_addr
, ETH_ALEN
);
5281 os_memset(wpa_s
->p2p_auth_invite
, 0, ETH_ALEN
);
5283 wpa_s
->p2p_persistent_go_freq
= freq
;
5284 wpa_s
->p2p_go_ht40
= !!ht40
;
5285 if (ssid
->mode
== WPAS_MODE_P2P_GO
) {
5286 role
= P2P_INVITE_ROLE_GO
;
5287 if (peer_addr
== NULL
) {
5288 wpa_printf(MSG_DEBUG
, "P2P: Missing peer "
5289 "address in invitation command");
5292 if (wpas_p2p_create_iface(wpa_s
)) {
5293 if (wpas_p2p_add_group_interface(wpa_s
,
5294 WPA_IF_P2P_GO
) < 0) {
5295 wpa_printf(MSG_ERROR
, "P2P: Failed to "
5296 "allocate a new interface for the "
5300 bssid
= wpa_s
->pending_interface_addr
;
5302 bssid
= wpa_s
->own_addr
;
5304 role
= P2P_INVITE_ROLE_CLIENT
;
5305 peer_addr
= ssid
->bssid
;
5307 wpa_s
->pending_invite_ssid_id
= ssid
->id
;
5309 res
= wpas_p2p_setup_freqs(wpa_s
, freq
, &force_freq
, &pref_freq
,
5310 role
== P2P_INVITE_ROLE_GO
);
5314 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
)
5315 return wpa_drv_p2p_invite(wpa_s
, peer_addr
, role
, bssid
,
5316 ssid
->ssid
, ssid
->ssid_len
,
5319 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
5322 return p2p_invite(wpa_s
->global
->p2p
, peer_addr
, role
, bssid
,
5323 ssid
->ssid
, ssid
->ssid_len
, force_freq
, go_dev_addr
,
5328 /* Invite to join an active group */
5329 int wpas_p2p_invite_group(struct wpa_supplicant
*wpa_s
, const char *ifname
,
5330 const u8
*peer_addr
, const u8
*go_dev_addr
)
5332 struct wpa_global
*global
= wpa_s
->global
;
5333 enum p2p_invite_role role
;
5335 struct wpa_ssid
*ssid
;
5337 int freq
= 0, force_freq
= 0, pref_freq
= 0;
5340 wpa_s
->p2p_persistent_go_freq
= 0;
5341 wpa_s
->p2p_go_ht40
= 0;
5342 wpa_s
->p2p_go_vht
= 0;
5344 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
5345 if (os_strcmp(wpa_s
->ifname
, ifname
) == 0)
5348 if (wpa_s
== NULL
) {
5349 wpa_printf(MSG_DEBUG
, "P2P: Interface '%s' not found", ifname
);
5353 ssid
= wpa_s
->current_ssid
;
5355 wpa_printf(MSG_DEBUG
, "P2P: No current SSID to use for "
5360 wpa_s
->global
->p2p_invite_group
= wpa_s
;
5361 persistent
= ssid
->p2p_persistent_group
&&
5362 wpas_p2p_get_persistent(wpa_s
->parent
, peer_addr
,
5363 ssid
->ssid
, ssid
->ssid_len
);
5365 if (ssid
->mode
== WPAS_MODE_P2P_GO
) {
5366 role
= P2P_INVITE_ROLE_ACTIVE_GO
;
5367 bssid
= wpa_s
->own_addr
;
5368 if (go_dev_addr
== NULL
)
5369 go_dev_addr
= wpa_s
->global
->p2p_dev_addr
;
5370 freq
= ssid
->frequency
;
5372 role
= P2P_INVITE_ROLE_CLIENT
;
5373 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
) {
5374 wpa_printf(MSG_DEBUG
, "P2P: Not associated - cannot "
5375 "invite to current group");
5378 bssid
= wpa_s
->bssid
;
5379 if (go_dev_addr
== NULL
&&
5380 !is_zero_ether_addr(wpa_s
->go_dev_addr
))
5381 go_dev_addr
= wpa_s
->go_dev_addr
;
5382 freq
= wpa_s
->current_bss
? wpa_s
->current_bss
->freq
:
5383 (int) wpa_s
->assoc_freq
;
5385 wpa_s
->parent
->pending_invite_ssid_id
= -1;
5387 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
)
5388 return wpa_drv_p2p_invite(wpa_s
, peer_addr
, role
, bssid
,
5389 ssid
->ssid
, ssid
->ssid_len
,
5390 go_dev_addr
, persistent
);
5392 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
5395 res
= wpas_p2p_setup_freqs(wpa_s
, freq
, &force_freq
, &pref_freq
,
5396 role
== P2P_INVITE_ROLE_ACTIVE_GO
);
5399 wpas_p2p_set_own_freq_preference(wpa_s
, force_freq
);
5401 return p2p_invite(wpa_s
->global
->p2p
, peer_addr
, role
, bssid
,
5402 ssid
->ssid
, ssid
->ssid_len
, force_freq
,
5403 go_dev_addr
, persistent
, pref_freq
);
5407 void wpas_p2p_completed(struct wpa_supplicant
*wpa_s
)
5409 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
5410 const char *ssid_txt
;
5411 u8 go_dev_addr
[ETH_ALEN
];
5412 int network_id
= -1;
5416 if (ssid
== NULL
|| ssid
->mode
!= WPAS_MODE_P2P_GROUP_FORMATION
) {
5417 eloop_cancel_timeout(wpas_p2p_group_formation_timeout
,
5418 wpa_s
->parent
, NULL
);
5421 if (!wpa_s
->show_group_started
|| !ssid
)
5424 wpa_s
->show_group_started
= 0;
5426 ssid_txt
= wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
);
5427 os_memset(go_dev_addr
, 0, ETH_ALEN
);
5428 if (ssid
->bssid_set
)
5429 os_memcpy(go_dev_addr
, ssid
->bssid
, ETH_ALEN
);
5430 persistent
= wpas_p2p_persistent_group(wpa_s
, go_dev_addr
, ssid
->ssid
,
5432 os_memcpy(wpa_s
->go_dev_addr
, go_dev_addr
, ETH_ALEN
);
5434 if (wpa_s
->global
->p2p_group_formation
== wpa_s
)
5435 wpa_s
->global
->p2p_group_formation
= NULL
;
5437 freq
= wpa_s
->current_bss
? wpa_s
->current_bss
->freq
:
5438 (int) wpa_s
->assoc_freq
;
5439 if (ssid
->passphrase
== NULL
&& ssid
->psk_set
) {
5441 wpa_snprintf_hex(psk
, sizeof(psk
), ssid
->psk
, 32);
5442 wpa_msg_global(wpa_s
->parent
, MSG_INFO
, P2P_EVENT_GROUP_STARTED
5443 "%s client ssid=\"%s\" freq=%d psk=%s "
5444 "go_dev_addr=" MACSTR
"%s",
5445 wpa_s
->ifname
, ssid_txt
, freq
, psk
,
5446 MAC2STR(go_dev_addr
),
5447 persistent
? " [PERSISTENT]" : "");
5449 wpa_msg_global(wpa_s
->parent
, MSG_INFO
, P2P_EVENT_GROUP_STARTED
5450 "%s client ssid=\"%s\" freq=%d "
5451 "passphrase=\"%s\" go_dev_addr=" MACSTR
"%s",
5452 wpa_s
->ifname
, ssid_txt
, freq
,
5453 ssid
->passphrase
? ssid
->passphrase
: "",
5454 MAC2STR(go_dev_addr
),
5455 persistent
? " [PERSISTENT]" : "");
5459 network_id
= wpas_p2p_store_persistent_group(wpa_s
->parent
,
5462 network_id
= ssid
->id
;
5463 wpas_notify_p2p_group_started(wpa_s
, ssid
, network_id
, 1);
5466 wpas_p2p_continue_after_scan(wpa_s
);
5470 int wpas_p2p_presence_req(struct wpa_supplicant
*wpa_s
, u32 duration1
,
5471 u32 interval1
, u32 duration2
, u32 interval2
)
5473 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
)
5475 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
5478 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
||
5479 wpa_s
->current_ssid
== NULL
||
5480 wpa_s
->current_ssid
->mode
!= WPAS_MODE_INFRA
)
5483 return p2p_presence_req(wpa_s
->global
->p2p
, wpa_s
->bssid
,
5484 wpa_s
->own_addr
, wpa_s
->assoc_freq
,
5485 duration1
, interval1
, duration2
, interval2
);
5489 int wpas_p2p_ext_listen(struct wpa_supplicant
*wpa_s
, unsigned int period
,
5490 unsigned int interval
)
5492 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
)
5495 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
5498 return p2p_ext_listen(wpa_s
->global
->p2p
, period
, interval
);
5502 static int wpas_p2p_is_client(struct wpa_supplicant
*wpa_s
)
5504 if (wpa_s
->current_ssid
== NULL
) {
5506 * current_ssid can be cleared when P2P client interface gets
5507 * disconnected, so assume this interface was used as P2P
5512 return wpa_s
->current_ssid
->p2p_group
&&
5513 wpa_s
->current_ssid
->mode
== WPAS_MODE_INFRA
;
5517 static void wpas_p2p_group_idle_timeout(void *eloop_ctx
, void *timeout_ctx
)
5519 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
5521 if (wpa_s
->conf
->p2p_group_idle
== 0 && !wpas_p2p_is_client(wpa_s
)) {
5522 wpa_printf(MSG_DEBUG
, "P2P: Ignore group idle timeout - "
5527 wpa_printf(MSG_DEBUG
, "P2P: Group idle timeout reached - terminate "
5529 wpas_p2p_group_delete(wpa_s
, P2P_GROUP_REMOVAL_IDLE_TIMEOUT
);
5533 static void wpas_p2p_set_group_idle_timeout(struct wpa_supplicant
*wpa_s
)
5537 if (eloop_cancel_timeout(wpas_p2p_group_idle_timeout
, wpa_s
, NULL
) > 0)
5538 wpa_printf(MSG_DEBUG
, "P2P: Cancelled P2P group idle timeout");
5540 if (wpa_s
->current_ssid
== NULL
|| !wpa_s
->current_ssid
->p2p_group
)
5543 timeout
= wpa_s
->conf
->p2p_group_idle
;
5544 if (wpa_s
->current_ssid
->mode
== WPAS_MODE_INFRA
&&
5545 (timeout
== 0 || timeout
> P2P_MAX_CLIENT_IDLE
))
5546 timeout
= P2P_MAX_CLIENT_IDLE
;
5552 if (wpa_s
->current_ssid
->mode
== WPAS_MODE_INFRA
)
5553 timeout
= 0; /* special client mode no-timeout */
5558 if (wpa_s
->p2p_in_provisioning
) {
5560 * Use the normal group formation timeout during the
5561 * provisioning phase to avoid terminating this process too
5562 * early due to group idle timeout.
5564 wpa_printf(MSG_DEBUG
, "P2P: Do not use P2P group idle timeout "
5565 "during provisioning");
5569 if (wpa_s
->show_group_started
) {
5571 * Use the normal group formation timeout between the end of
5572 * the provisioning phase and completion of 4-way handshake to
5573 * avoid terminating this process too early due to group idle
5576 wpa_printf(MSG_DEBUG
, "P2P: Do not use P2P group idle timeout "
5577 "while waiting for initial 4-way handshake to "
5582 wpa_printf(MSG_DEBUG
, "P2P: Set P2P group idle timeout to %u seconds",
5584 eloop_register_timeout(timeout
, 0, wpas_p2p_group_idle_timeout
,
5589 /* Returns 1 if the interface was removed */
5590 int wpas_p2p_deauth_notif(struct wpa_supplicant
*wpa_s
, const u8
*bssid
,
5591 u16 reason_code
, const u8
*ie
, size_t ie_len
,
5592 int locally_generated
)
5594 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
5596 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
)
5599 if (!locally_generated
)
5600 p2p_deauth_notif(wpa_s
->global
->p2p
, bssid
, reason_code
, ie
,
5603 if (reason_code
== WLAN_REASON_DEAUTH_LEAVING
&& !locally_generated
&&
5604 wpa_s
->current_ssid
&&
5605 wpa_s
->current_ssid
->p2p_group
&&
5606 wpa_s
->current_ssid
->mode
== WPAS_MODE_INFRA
) {
5607 wpa_printf(MSG_DEBUG
, "P2P: GO indicated that the P2P Group "
5608 "session is ending");
5609 if (wpas_p2p_group_delete(wpa_s
,
5610 P2P_GROUP_REMOVAL_GO_ENDING_SESSION
)
5619 void wpas_p2p_disassoc_notif(struct wpa_supplicant
*wpa_s
, const u8
*bssid
,
5620 u16 reason_code
, const u8
*ie
, size_t ie_len
,
5621 int locally_generated
)
5623 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
5625 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
)
5628 if (!locally_generated
)
5629 p2p_disassoc_notif(wpa_s
->global
->p2p
, bssid
, reason_code
, ie
,
5634 void wpas_p2p_update_config(struct wpa_supplicant
*wpa_s
)
5636 struct p2p_data
*p2p
= wpa_s
->global
->p2p
;
5641 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_CAPABLE
))
5644 if (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_DEVICE_NAME
)
5645 p2p_set_dev_name(p2p
, wpa_s
->conf
->device_name
);
5647 if (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_DEVICE_TYPE
)
5648 p2p_set_pri_dev_type(p2p
, wpa_s
->conf
->device_type
);
5651 (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_CONFIG_METHODS
))
5652 p2p_set_config_methods(p2p
, wpa_s
->wps
->config_methods
);
5654 if (wpa_s
->wps
&& (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_UUID
))
5655 p2p_set_uuid(p2p
, wpa_s
->wps
->uuid
);
5657 if (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_WPS_STRING
) {
5658 p2p_set_manufacturer(p2p
, wpa_s
->conf
->manufacturer
);
5659 p2p_set_model_name(p2p
, wpa_s
->conf
->model_name
);
5660 p2p_set_model_number(p2p
, wpa_s
->conf
->model_number
);
5661 p2p_set_serial_number(p2p
, wpa_s
->conf
->serial_number
);
5664 if (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_SEC_DEVICE_TYPE
)
5665 p2p_set_sec_dev_types(p2p
,
5666 (void *) wpa_s
->conf
->sec_device_type
,
5667 wpa_s
->conf
->num_sec_device_types
);
5669 if (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_VENDOR_EXTENSION
) {
5671 p2p_remove_wps_vendor_extensions(p2p
);
5672 for (i
= 0; i
< MAX_WPS_VENDOR_EXT
; i
++) {
5673 if (wpa_s
->conf
->wps_vendor_ext
[i
] == NULL
)
5675 p2p_add_wps_vendor_extension(
5676 p2p
, wpa_s
->conf
->wps_vendor_ext
[i
]);
5680 if ((wpa_s
->conf
->changed_parameters
& CFG_CHANGED_COUNTRY
) &&
5681 wpa_s
->conf
->country
[0] && wpa_s
->conf
->country
[1]) {
5683 country
[0] = wpa_s
->conf
->country
[0];
5684 country
[1] = wpa_s
->conf
->country
[1];
5686 p2p_set_country(p2p
, country
);
5689 if (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_P2P_SSID_POSTFIX
) {
5690 p2p_set_ssid_postfix(p2p
, (u8
*) wpa_s
->conf
->p2p_ssid_postfix
,
5691 wpa_s
->conf
->p2p_ssid_postfix
?
5692 os_strlen(wpa_s
->conf
->p2p_ssid_postfix
) :
5696 if (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_P2P_INTRA_BSS
)
5697 p2p_set_intra_bss_dist(p2p
, wpa_s
->conf
->p2p_intra_bss
);
5699 if (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_P2P_LISTEN_CHANNEL
) {
5700 u8 reg_class
, channel
;
5703 if (wpa_s
->conf
->p2p_listen_reg_class
&&
5704 wpa_s
->conf
->p2p_listen_channel
) {
5705 reg_class
= wpa_s
->conf
->p2p_listen_reg_class
;
5706 channel
= wpa_s
->conf
->p2p_listen_channel
;
5710 * Pick one of the social channels randomly as the
5713 os_get_random((u8
*) &r
, sizeof(r
));
5714 channel
= 1 + (r
% 3) * 5;
5716 ret
= p2p_set_listen_channel(p2p
, reg_class
, channel
);
5718 wpa_printf(MSG_ERROR
, "P2P: Own listen channel update "
5721 if (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_P2P_OPER_CHANNEL
) {
5722 u8 op_reg_class
, op_channel
, cfg_op_channel
;
5725 if (wpa_s
->conf
->p2p_oper_reg_class
&&
5726 wpa_s
->conf
->p2p_oper_channel
) {
5727 op_reg_class
= wpa_s
->conf
->p2p_oper_reg_class
;
5728 op_channel
= wpa_s
->conf
->p2p_oper_channel
;
5733 * Use random operation channel from (1, 6, 11)
5734 *if no other preference is indicated.
5736 os_get_random((u8
*) &r
, sizeof(r
));
5737 op_channel
= 1 + (r
% 3) * 5;
5740 ret
= p2p_set_oper_channel(p2p
, op_reg_class
, op_channel
,
5743 wpa_printf(MSG_ERROR
, "P2P: Own oper channel update "
5747 if (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_P2P_PREF_CHAN
) {
5748 if (p2p_set_pref_chan(p2p
, wpa_s
->conf
->num_p2p_pref_chan
,
5749 wpa_s
->conf
->p2p_pref_chan
) < 0) {
5750 wpa_printf(MSG_ERROR
, "P2P: Preferred channel list "
5754 if (p2p_set_no_go_freq(p2p
, &wpa_s
->conf
->p2p_no_go_freq
) < 0) {
5755 wpa_printf(MSG_ERROR
, "P2P: No GO channel list "
5762 int wpas_p2p_set_noa(struct wpa_supplicant
*wpa_s
, u8 count
, int start
,
5765 if (!wpa_s
->ap_iface
)
5767 return hostapd_p2p_set_noa(wpa_s
->ap_iface
->bss
[0], count
, start
,
5772 int wpas_p2p_set_cross_connect(struct wpa_supplicant
*wpa_s
, int enabled
)
5774 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
5776 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
)
5779 wpa_s
->global
->cross_connection
= enabled
;
5780 p2p_set_cross_connect(wpa_s
->global
->p2p
, enabled
);
5783 struct wpa_supplicant
*iface
;
5785 for (iface
= wpa_s
->global
->ifaces
; iface
; iface
= iface
->next
)
5787 if (iface
->cross_connect_enabled
== 0)
5790 iface
->cross_connect_enabled
= 0;
5791 iface
->cross_connect_in_use
= 0;
5792 wpa_msg_global(iface
->parent
, MSG_INFO
,
5793 P2P_EVENT_CROSS_CONNECT_DISABLE
"%s %s",
5795 iface
->cross_connect_uplink
);
5803 static void wpas_p2p_enable_cross_connect(struct wpa_supplicant
*uplink
)
5805 struct wpa_supplicant
*iface
;
5807 if (!uplink
->global
->cross_connection
)
5810 for (iface
= uplink
->global
->ifaces
; iface
; iface
= iface
->next
) {
5811 if (!iface
->cross_connect_enabled
)
5813 if (os_strcmp(uplink
->ifname
, iface
->cross_connect_uplink
) !=
5816 if (iface
->ap_iface
== NULL
)
5818 if (iface
->cross_connect_in_use
)
5821 iface
->cross_connect_in_use
= 1;
5822 wpa_msg_global(iface
->parent
, MSG_INFO
,
5823 P2P_EVENT_CROSS_CONNECT_ENABLE
"%s %s",
5824 iface
->ifname
, iface
->cross_connect_uplink
);
5829 static void wpas_p2p_disable_cross_connect(struct wpa_supplicant
*uplink
)
5831 struct wpa_supplicant
*iface
;
5833 for (iface
= uplink
->global
->ifaces
; iface
; iface
= iface
->next
) {
5834 if (!iface
->cross_connect_enabled
)
5836 if (os_strcmp(uplink
->ifname
, iface
->cross_connect_uplink
) !=
5839 if (!iface
->cross_connect_in_use
)
5842 wpa_msg_global(iface
->parent
, MSG_INFO
,
5843 P2P_EVENT_CROSS_CONNECT_DISABLE
"%s %s",
5844 iface
->ifname
, iface
->cross_connect_uplink
);
5845 iface
->cross_connect_in_use
= 0;
5850 void wpas_p2p_notif_connected(struct wpa_supplicant
*wpa_s
)
5852 if (wpa_s
->ap_iface
|| wpa_s
->current_ssid
== NULL
||
5853 wpa_s
->current_ssid
->mode
!= WPAS_MODE_INFRA
||
5854 wpa_s
->cross_connect_disallowed
)
5855 wpas_p2p_disable_cross_connect(wpa_s
);
5857 wpas_p2p_enable_cross_connect(wpa_s
);
5858 if (!wpa_s
->ap_iface
&&
5859 eloop_cancel_timeout(wpas_p2p_group_idle_timeout
, wpa_s
, NULL
) > 0)
5860 wpa_printf(MSG_DEBUG
, "P2P: Cancelled P2P group idle timeout");
5864 void wpas_p2p_notif_disconnected(struct wpa_supplicant
*wpa_s
)
5866 wpas_p2p_disable_cross_connect(wpa_s
);
5867 if (!wpa_s
->ap_iface
&&
5868 !eloop_is_timeout_registered(wpas_p2p_group_idle_timeout
,
5870 wpas_p2p_set_group_idle_timeout(wpa_s
);
5874 static void wpas_p2p_cross_connect_setup(struct wpa_supplicant
*wpa_s
)
5876 struct wpa_supplicant
*iface
;
5878 if (!wpa_s
->global
->cross_connection
)
5881 for (iface
= wpa_s
->global
->ifaces
; iface
; iface
= iface
->next
) {
5884 if (iface
->drv_flags
&
5885 WPA_DRIVER_FLAGS_P2P_DEDICATED_INTERFACE
)
5887 if (iface
->drv_flags
& WPA_DRIVER_FLAGS_P2P_CAPABLE
)
5890 wpa_s
->cross_connect_enabled
= 1;
5891 os_strlcpy(wpa_s
->cross_connect_uplink
, iface
->ifname
,
5892 sizeof(wpa_s
->cross_connect_uplink
));
5893 wpa_printf(MSG_DEBUG
, "P2P: Enable cross connection from "
5894 "%s to %s whenever uplink is available",
5895 wpa_s
->ifname
, wpa_s
->cross_connect_uplink
);
5897 if (iface
->ap_iface
|| iface
->current_ssid
== NULL
||
5898 iface
->current_ssid
->mode
!= WPAS_MODE_INFRA
||
5899 iface
->cross_connect_disallowed
||
5900 iface
->wpa_state
!= WPA_COMPLETED
)
5903 wpa_s
->cross_connect_in_use
= 1;
5904 wpa_msg_global(wpa_s
->parent
, MSG_INFO
,
5905 P2P_EVENT_CROSS_CONNECT_ENABLE
"%s %s",
5906 wpa_s
->ifname
, wpa_s
->cross_connect_uplink
);
5912 int wpas_p2p_notif_pbc_overlap(struct wpa_supplicant
*wpa_s
)
5914 if (wpa_s
->p2p_group_interface
!= P2P_GROUP_INTERFACE_CLIENT
&&
5915 !wpa_s
->p2p_in_provisioning
)
5916 return 0; /* not P2P client operation */
5918 wpa_printf(MSG_DEBUG
, "P2P: Terminate connection due to WPS PBC "
5920 if (wpa_s
!= wpa_s
->parent
)
5921 wpa_msg_ctrl(wpa_s
->parent
, MSG_INFO
, WPS_EVENT_OVERLAP
);
5922 wpas_p2p_group_formation_failed(wpa_s
);
5927 void wpas_p2p_update_channel_list(struct wpa_supplicant
*wpa_s
)
5929 struct p2p_channels chan
, cli_chan
;
5931 if (wpa_s
->global
== NULL
|| wpa_s
->global
->p2p
== NULL
)
5934 os_memset(&chan
, 0, sizeof(chan
));
5935 os_memset(&cli_chan
, 0, sizeof(cli_chan
));
5936 if (wpas_p2p_setup_channels(wpa_s
, &chan
, &cli_chan
)) {
5937 wpa_printf(MSG_ERROR
, "P2P: Failed to update supported "
5942 p2p_update_channel_list(wpa_s
->global
->p2p
, &chan
, &cli_chan
);
5946 static void wpas_p2p_scan_res_ignore(struct wpa_supplicant
*wpa_s
,
5947 struct wpa_scan_results
*scan_res
)
5949 wpa_printf(MSG_DEBUG
, "P2P: Ignore scan results");
5953 int wpas_p2p_cancel(struct wpa_supplicant
*wpa_s
)
5955 struct wpa_global
*global
= wpa_s
->global
;
5959 if (global
->p2p
== NULL
)
5962 wpa_printf(MSG_DEBUG
, "P2P: Request to cancel group formation");
5964 if (wpa_s
->pending_interface_name
[0] &&
5965 !is_zero_ether_addr(wpa_s
->pending_interface_addr
))
5968 peer
= p2p_get_go_neg_peer(global
->p2p
);
5970 wpa_printf(MSG_DEBUG
, "P2P: Unauthorize pending GO Neg peer "
5971 MACSTR
, MAC2STR(peer
));
5972 p2p_unauthorize(global
->p2p
, peer
);
5976 if (wpa_s
->scan_res_handler
== wpas_p2p_scan_res_join
) {
5977 wpa_printf(MSG_DEBUG
, "P2P: Stop pending scan for join");
5978 wpa_s
->scan_res_handler
= wpas_p2p_scan_res_ignore
;
5982 if (wpa_s
->pending_pd_before_join
) {
5983 wpa_printf(MSG_DEBUG
, "P2P: Stop pending PD before join");
5984 wpa_s
->pending_pd_before_join
= 0;
5988 wpas_p2p_stop_find(wpa_s
);
5990 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
5991 if (wpa_s
== global
->p2p_group_formation
&&
5992 (wpa_s
->p2p_in_provisioning
||
5993 wpa_s
->parent
->pending_interface_type
==
5994 WPA_IF_P2P_CLIENT
)) {
5995 wpa_printf(MSG_DEBUG
, "P2P: Interface %s in group "
5996 "formation found - cancelling",
5999 eloop_cancel_timeout(wpas_p2p_group_formation_timeout
,
6000 wpa_s
->parent
, NULL
);
6001 if (wpa_s
->p2p_in_provisioning
) {
6002 wpas_group_formation_completed(wpa_s
, 0);
6005 wpas_p2p_group_delete(wpa_s
,
6006 P2P_GROUP_REMOVAL_REQUESTED
);
6012 wpa_printf(MSG_DEBUG
, "P2P: No ongoing group formation found");
6020 void wpas_p2p_interface_unavailable(struct wpa_supplicant
*wpa_s
)
6022 if (wpa_s
->current_ssid
== NULL
|| !wpa_s
->current_ssid
->p2p_group
)
6025 wpa_printf(MSG_DEBUG
, "P2P: Remove group due to driver resource not "
6026 "being available anymore");
6027 wpas_p2p_group_delete(wpa_s
, P2P_GROUP_REMOVAL_UNAVAILABLE
);
6031 void wpas_p2p_update_best_channels(struct wpa_supplicant
*wpa_s
,
6032 int freq_24
, int freq_5
, int freq_overall
)
6034 struct p2p_data
*p2p
= wpa_s
->global
->p2p
;
6035 if (p2p
== NULL
|| (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
))
6037 p2p_set_best_channels(p2p
, freq_24
, freq_5
, freq_overall
);
6041 int wpas_p2p_unauthorize(struct wpa_supplicant
*wpa_s
, const char *addr
)
6044 struct p2p_data
*p2p
= wpa_s
->global
->p2p
;
6046 if (p2p
== NULL
|| (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
))
6049 if (hwaddr_aton(addr
, peer
))
6052 return p2p_unauthorize(p2p
, peer
);
6057 * wpas_p2p_disconnect - Disconnect from a P2P Group
6058 * @wpa_s: Pointer to wpa_supplicant data
6059 * Returns: 0 on success, -1 on failure
6061 * This can be used to disconnect from a group in which the local end is a P2P
6062 * Client or to end a P2P Group in case the local end is the Group Owner. If a
6063 * virtual network interface was created for this group, that interface will be
6064 * removed. Otherwise, only the configured P2P group network will be removed
6065 * from the interface.
6067 int wpas_p2p_disconnect(struct wpa_supplicant
*wpa_s
)
6073 return wpas_p2p_group_delete(wpa_s
, P2P_GROUP_REMOVAL_REQUESTED
) < 0 ?
6078 int wpas_p2p_in_progress(struct wpa_supplicant
*wpa_s
)
6082 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
6085 ret
= p2p_in_progress(wpa_s
->global
->p2p
);
6088 * Check whether there is an ongoing WPS provisioning step (or
6089 * other parts of group formation) on another interface since
6090 * p2p_in_progress() does not report this to avoid issues for
6091 * scans during such provisioning step.
6093 if (wpa_s
->global
->p2p_group_formation
&&
6094 wpa_s
->global
->p2p_group_formation
!= wpa_s
) {
6095 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Another interface (%s) "
6096 "in group formation",
6097 wpa_s
->global
->p2p_group_formation
->ifname
);
6102 if (!ret
&& wpa_s
->global
->p2p_go_wait_client
.sec
) {
6105 if (now
.sec
> wpa_s
->global
->p2p_go_wait_client
.sec
+
6106 P2P_MAX_INITIAL_CONN_WAIT_GO
) {
6107 /* Wait for the first client has expired */
6108 wpa_s
->global
->p2p_go_wait_client
.sec
= 0;
6110 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Waiting for initial client connection during group formation");
6119 void wpas_p2p_network_removed(struct wpa_supplicant
*wpa_s
,
6120 struct wpa_ssid
*ssid
)
6122 if (wpa_s
->p2p_in_provisioning
&& ssid
->p2p_group
&&
6123 eloop_cancel_timeout(wpas_p2p_group_formation_timeout
,
6124 wpa_s
->parent
, NULL
) > 0) {
6126 * Remove the network by scheduling the group formation
6127 * timeout to happen immediately. The teardown code
6128 * needs to be scheduled to run asynch later so that we
6129 * don't delete data from under ourselves unexpectedly.
6130 * Calling wpas_p2p_group_formation_timeout directly
6131 * causes a series of crashes in WPS failure scenarios.
6133 wpa_printf(MSG_DEBUG
, "P2P: Canceled group formation due to "
6134 "P2P group network getting removed");
6135 eloop_register_timeout(0, 0, wpas_p2p_group_formation_timeout
,
6136 wpa_s
->parent
, NULL
);
6141 struct wpa_ssid
* wpas_p2p_get_persistent(struct wpa_supplicant
*wpa_s
,
6142 const u8
*addr
, const u8
*ssid
,
6148 for (s
= wpa_s
->conf
->ssid
; s
; s
= s
->next
) {
6149 if (s
->disabled
!= 2)
6152 (ssid_len
!= s
->ssid_len
||
6153 os_memcmp(ssid
, s
->ssid
, ssid_len
) != 0))
6156 if (s
->mode
== WPAS_MODE_P2P_GO
)
6160 if (os_memcmp(s
->bssid
, addr
, ETH_ALEN
) == 0)
6161 return s
; /* peer is GO in the persistent group */
6162 if (s
->mode
!= WPAS_MODE_P2P_GO
|| s
->p2p_client_list
== NULL
)
6164 for (i
= 0; i
< s
->num_p2p_clients
; i
++) {
6165 if (os_memcmp(s
->p2p_client_list
+ i
* ETH_ALEN
,
6166 addr
, ETH_ALEN
) == 0)
6167 return s
; /* peer is P2P client in persistent
6176 void wpas_p2p_notify_ap_sta_authorized(struct wpa_supplicant
*wpa_s
,
6179 if (eloop_cancel_timeout(wpas_p2p_group_formation_timeout
,
6180 wpa_s
->parent
, NULL
) > 0) {
6182 * This can happen if WPS provisioning step is not terminated
6183 * cleanly (e.g., P2P Client does not send WSC_Done). Since the
6184 * peer was able to connect, there is no need to time out group
6185 * formation after this, though. In addition, this is used with
6186 * the initial connection wait on the GO as a separate formation
6187 * timeout and as such, expected to be hit after the initial WPS
6188 * provisioning step.
6190 wpa_printf(MSG_DEBUG
, "P2P: Canceled P2P group formation timeout on data connection");
6192 if (!wpa_s
->p2p_go_group_formation_completed
) {
6193 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Marking group formation completed on GO on first data connection");
6194 wpa_s
->p2p_go_group_formation_completed
= 1;
6195 wpa_s
->global
->p2p_group_formation
= NULL
;
6196 wpa_s
->p2p_in_provisioning
= 0;
6198 wpa_s
->global
->p2p_go_wait_client
.sec
= 0;
6201 wpas_p2p_add_persistent_group_client(wpa_s
, addr
);
6205 static void wpas_p2p_fallback_to_go_neg(struct wpa_supplicant
*wpa_s
,
6208 struct wpa_supplicant
*group
= wpa_s
;
6209 if (wpa_s
->global
->p2p_group_formation
)
6210 group
= wpa_s
->global
->p2p_group_formation
;
6211 wpa_s
= wpa_s
->parent
;
6212 offchannel_send_action_done(wpa_s
);
6214 wpas_p2p_group_delete(group
, P2P_GROUP_REMOVAL_SILENT
);
6215 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Fall back to GO Negotiation");
6216 wpas_p2p_connect(wpa_s
, wpa_s
->pending_join_dev_addr
, wpa_s
->p2p_pin
,
6217 wpa_s
->p2p_wps_method
, wpa_s
->p2p_persistent_group
, 0,
6218 0, 0, wpa_s
->p2p_go_intent
, wpa_s
->p2p_connect_freq
,
6219 wpa_s
->p2p_persistent_id
,
6220 wpa_s
->p2p_pd_before_go_neg
,
6226 int wpas_p2p_scan_no_go_seen(struct wpa_supplicant
*wpa_s
)
6228 if (!wpa_s
->p2p_fallback_to_go_neg
||
6229 wpa_s
->p2p_in_provisioning
<= 5)
6232 if (wpas_p2p_peer_go(wpa_s
, wpa_s
->pending_join_dev_addr
) > 0)
6233 return 0; /* peer operating as a GO */
6235 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: GO not found for p2p_connect-auto - "
6236 "fallback to GO Negotiation");
6237 wpas_p2p_fallback_to_go_neg(wpa_s
, 1);
6243 unsigned int wpas_p2p_search_delay(struct wpa_supplicant
*wpa_s
)
6245 const char *rn
, *rn2
;
6246 struct wpa_supplicant
*ifs
;
6248 if (wpa_s
->wpa_state
> WPA_SCANNING
) {
6249 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Use %u ms search delay due to "
6250 "concurrent operation",
6251 P2P_CONCURRENT_SEARCH_DELAY
);
6252 return P2P_CONCURRENT_SEARCH_DELAY
;
6255 if (!wpa_s
->driver
->get_radio_name
)
6257 rn
= wpa_s
->driver
->get_radio_name(wpa_s
->drv_priv
);
6258 if (rn
== NULL
|| rn
[0] == '\0')
6261 for (ifs
= wpa_s
->global
->ifaces
; ifs
; ifs
= ifs
->next
) {
6262 if (ifs
== wpa_s
|| !ifs
->driver
->get_radio_name
)
6265 rn2
= ifs
->driver
->get_radio_name(ifs
->drv_priv
);
6266 if (!rn2
|| os_strcmp(rn
, rn2
) != 0)
6268 if (ifs
->wpa_state
> WPA_SCANNING
) {
6269 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Use %u ms search "
6270 "delay due to concurrent operation on "
6272 P2P_CONCURRENT_SEARCH_DELAY
, ifs
->ifname
);
6273 return P2P_CONCURRENT_SEARCH_DELAY
;
6281 void wpas_p2p_continue_after_scan(struct wpa_supplicant
*wpa_s
)
6283 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Station mode scan operation not "
6284 "pending anymore (sta_scan_pending=%d "
6285 "p2p_cb_on_scan_complete=%d)", wpa_s
->sta_scan_pending
,
6286 wpa_s
->global
->p2p_cb_on_scan_complete
);
6287 wpa_s
->sta_scan_pending
= 0;
6289 if (!wpa_s
->global
->p2p_cb_on_scan_complete
)
6291 wpa_s
->global
->p2p_cb_on_scan_complete
= 0;
6293 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
6296 if (p2p_other_scan_completed(wpa_s
->global
->p2p
) == 1) {
6297 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Pending P2P operation "
6298 "continued after successful connection");
6299 p2p_increase_search_delay(wpa_s
->global
->p2p
,
6300 wpas_p2p_search_delay(wpa_s
));
6305 static int wpas_p2p_remove_psk_entry(struct wpa_supplicant
*wpa_s
,
6306 struct wpa_ssid
*s
, const u8
*addr
,
6309 struct psk_list_entry
*psk
, *tmp
;
6312 dl_list_for_each_safe(psk
, tmp
, &s
->psk_list
, struct psk_list_entry
,
6314 if ((iface_addr
&& !psk
->p2p
&&
6315 os_memcmp(addr
, psk
->addr
, ETH_ALEN
) == 0) ||
6316 (!iface_addr
&& psk
->p2p
&&
6317 os_memcmp(addr
, psk
->addr
, ETH_ALEN
) == 0)) {
6318 wpa_dbg(wpa_s
, MSG_DEBUG
,
6319 "P2P: Remove persistent group PSK list entry for "
6321 MAC2STR(psk
->addr
), psk
->p2p
);
6322 dl_list_del(&psk
->list
);
6332 void wpas_p2p_new_psk_cb(struct wpa_supplicant
*wpa_s
, const u8
*mac_addr
,
6333 const u8
*p2p_dev_addr
,
6334 const u8
*psk
, size_t psk_len
)
6336 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
6337 struct wpa_ssid
*persistent
;
6338 struct psk_list_entry
*p
;
6340 if (psk_len
!= sizeof(p
->psk
))
6344 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: New PSK for addr=" MACSTR
6345 " p2p_dev_addr=" MACSTR
,
6346 MAC2STR(mac_addr
), MAC2STR(p2p_dev_addr
));
6347 if (is_zero_ether_addr(p2p_dev_addr
))
6348 p2p_dev_addr
= NULL
;
6350 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: New PSK for addr=" MACSTR
,
6354 if (ssid
->mode
== WPAS_MODE_P2P_GROUP_FORMATION
) {
6355 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: new_psk_cb during group formation");
6356 /* To be added to persistent group once created */
6357 if (wpa_s
->global
->add_psk
== NULL
) {
6358 wpa_s
->global
->add_psk
= os_zalloc(sizeof(*p
));
6359 if (wpa_s
->global
->add_psk
== NULL
)
6362 p
= wpa_s
->global
->add_psk
;
6365 os_memcpy(p
->addr
, p2p_dev_addr
, ETH_ALEN
);
6368 os_memcpy(p
->addr
, mac_addr
, ETH_ALEN
);
6370 os_memcpy(p
->psk
, psk
, psk_len
);
6374 if (ssid
->mode
!= WPAS_MODE_P2P_GO
|| !ssid
->p2p_persistent_group
) {
6375 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Ignore new_psk_cb on not-persistent GO");
6379 persistent
= wpas_p2p_get_persistent(wpa_s
->parent
, NULL
, ssid
->ssid
,
6382 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Could not find persistent group information to store the new PSK");
6386 p
= os_zalloc(sizeof(*p
));
6391 os_memcpy(p
->addr
, p2p_dev_addr
, ETH_ALEN
);
6394 os_memcpy(p
->addr
, mac_addr
, ETH_ALEN
);
6396 os_memcpy(p
->psk
, psk
, psk_len
);
6398 if (dl_list_len(&persistent
->psk_list
) > P2P_MAX_STORED_CLIENTS
) {
6399 struct psk_list_entry
*last
;
6400 last
= dl_list_last(&persistent
->psk_list
,
6401 struct psk_list_entry
, list
);
6402 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Remove oldest PSK entry for "
6403 MACSTR
" (p2p=%u) to make room for a new one",
6404 MAC2STR(last
->addr
), last
->p2p
);
6405 dl_list_del(&last
->list
);
6409 wpas_p2p_remove_psk_entry(wpa_s
->parent
, persistent
,
6410 p2p_dev_addr
? p2p_dev_addr
: mac_addr
,
6411 p2p_dev_addr
== NULL
);
6413 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Add new PSK for p2p_dev_addr="
6414 MACSTR
, MAC2STR(p2p_dev_addr
));
6416 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Add new PSK for addr=" MACSTR
,
6419 dl_list_add(&persistent
->psk_list
, &p
->list
);
6421 #ifndef CONFIG_NO_CONFIG_WRITE
6422 if (wpa_s
->parent
->conf
->update_config
&&
6423 wpa_config_write(wpa_s
->parent
->confname
, wpa_s
->parent
->conf
))
6424 wpa_printf(MSG_DEBUG
, "P2P: Failed to update configuration");
6425 #endif /* CONFIG_NO_CONFIG_WRITE */
6429 static void wpas_p2p_remove_psk(struct wpa_supplicant
*wpa_s
,
6430 struct wpa_ssid
*s
, const u8
*addr
,
6435 res
= wpas_p2p_remove_psk_entry(wpa_s
, s
, addr
, iface_addr
);
6437 #ifndef CONFIG_NO_CONFIG_WRITE
6438 if (wpa_s
->conf
->update_config
&&
6439 wpa_config_write(wpa_s
->confname
, wpa_s
->conf
))
6440 wpa_dbg(wpa_s
, MSG_DEBUG
,
6441 "P2P: Failed to update configuration");
6442 #endif /* CONFIG_NO_CONFIG_WRITE */
6447 static void wpas_p2p_remove_client_go(struct wpa_supplicant
*wpa_s
,
6448 const u8
*peer
, int iface_addr
)
6450 struct hostapd_data
*hapd
;
6451 struct hostapd_wpa_psk
*psk
, *prev
, *rem
;
6452 struct sta_info
*sta
;
6454 if (wpa_s
->ap_iface
== NULL
|| wpa_s
->current_ssid
== NULL
||
6455 wpa_s
->current_ssid
->mode
!= WPAS_MODE_P2P_GO
)
6458 /* Remove per-station PSK entry */
6459 hapd
= wpa_s
->ap_iface
->bss
[0];
6461 psk
= hapd
->conf
->ssid
.wpa_psk
;
6463 if ((iface_addr
&& os_memcmp(peer
, psk
->addr
, ETH_ALEN
) == 0) ||
6465 os_memcmp(peer
, psk
->p2p_dev_addr
, ETH_ALEN
) == 0)) {
6466 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Remove operating group PSK entry for "
6467 MACSTR
" iface_addr=%d",
6468 MAC2STR(peer
), iface_addr
);
6470 prev
->next
= psk
->next
;
6472 hapd
->conf
->ssid
.wpa_psk
= psk
->next
;
6482 /* Disconnect from group */
6484 sta
= ap_get_sta(hapd
, peer
);
6486 sta
= ap_get_sta_p2p(hapd
, peer
);
6488 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Disconnect peer " MACSTR
6489 " (iface_addr=%d) from group",
6490 MAC2STR(peer
), iface_addr
);
6491 hostapd_drv_sta_deauth(hapd
, sta
->addr
,
6492 WLAN_REASON_DEAUTH_LEAVING
);
6493 ap_sta_deauthenticate(hapd
, sta
, WLAN_REASON_DEAUTH_LEAVING
);
6498 void wpas_p2p_remove_client(struct wpa_supplicant
*wpa_s
, const u8
*peer
,
6502 struct wpa_supplicant
*w
;
6504 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Remove client " MACSTR
, MAC2STR(peer
));
6506 /* Remove from any persistent group */
6507 for (s
= wpa_s
->parent
->conf
->ssid
; s
; s
= s
->next
) {
6508 if (s
->disabled
!= 2 || s
->mode
!= WPAS_MODE_P2P_GO
)
6511 wpas_remove_persistent_peer(wpa_s
, s
, peer
, 0);
6512 wpas_p2p_remove_psk(wpa_s
->parent
, s
, peer
, iface_addr
);
6515 /* Remove from any operating group */
6516 for (w
= wpa_s
->global
->ifaces
; w
; w
= w
->next
)
6517 wpas_p2p_remove_client_go(w
, peer
, iface_addr
);
6521 static void wpas_p2p_psk_failure_removal(void *eloop_ctx
, void *timeout_ctx
)
6523 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
6524 wpas_p2p_group_delete(wpa_s
, P2P_GROUP_REMOVAL_PSK_FAILURE
);
6528 int wpas_p2p_4way_hs_failed(struct wpa_supplicant
*wpa_s
)
6530 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
6532 if (ssid
== NULL
|| !ssid
->p2p_group
)
6535 if (wpa_s
->p2p_last_4way_hs_fail
&&
6536 wpa_s
->p2p_last_4way_hs_fail
== ssid
) {
6537 u8 go_dev_addr
[ETH_ALEN
];
6538 struct wpa_ssid
*persistent
;
6540 if (wpas_p2p_persistent_group(wpa_s
, go_dev_addr
,
6542 ssid
->ssid_len
) <= 0) {
6543 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Could not determine whether 4-way handshake failures were for a persistent group");
6547 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Two 4-way handshake failures for a P2P group - go_dev_addr="
6548 MACSTR
, MAC2STR(go_dev_addr
));
6549 persistent
= wpas_p2p_get_persistent(wpa_s
->parent
, go_dev_addr
,
6552 if (persistent
== NULL
|| persistent
->mode
!= WPAS_MODE_INFRA
) {
6553 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: No matching persistent group stored");
6556 wpa_msg_global(wpa_s
->parent
, MSG_INFO
,
6557 P2P_EVENT_PERSISTENT_PSK_FAIL
"%d",
6560 wpa_s
->p2p_last_4way_hs_fail
= NULL
;
6562 * Remove the group from a timeout to avoid issues with caller
6563 * continuing to use the interface if this is on a P2P group
6566 eloop_register_timeout(0, 0, wpas_p2p_psk_failure_removal
,
6571 wpa_s
->p2p_last_4way_hs_fail
= ssid
;