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/p2p_hostapd.h"
21 #include "eapol_supp/eapol_supp_sm.h"
22 #include "rsn_supp/wpa.h"
23 #include "wpa_supplicant_i.h"
26 #include "config_ssid.h"
31 #include "offchannel.h"
32 #include "wps_supplicant.h"
33 #include "p2p_supplicant.h"
37 * How many times to try to scan to find the GO before giving up on join
40 #define P2P_MAX_JOIN_SCAN_ATTEMPTS 10
42 #define P2P_AUTO_PD_SCAN_ATTEMPTS 5
44 #ifndef P2P_MAX_CLIENT_IDLE
46 * How many seconds to try to reconnect to the GO when connection in P2P client
49 #define P2P_MAX_CLIENT_IDLE 10
50 #endif /* P2P_MAX_CLIENT_IDLE */
52 #ifndef P2P_MAX_INITIAL_CONN_WAIT
54 * How many seconds to wait for initial 4-way handshake to get completed after
55 * WPS provisioning step.
57 #define P2P_MAX_INITIAL_CONN_WAIT 10
58 #endif /* P2P_MAX_INITIAL_CONN_WAIT */
60 #ifndef P2P_CONCURRENT_SEARCH_DELAY
61 #define P2P_CONCURRENT_SEARCH_DELAY 500
62 #endif /* P2P_CONCURRENT_SEARCH_DELAY */
64 enum p2p_group_removal_reason
{
65 P2P_GROUP_REMOVAL_UNKNOWN
,
66 P2P_GROUP_REMOVAL_SILENT
,
67 P2P_GROUP_REMOVAL_FORMATION_FAILED
,
68 P2P_GROUP_REMOVAL_REQUESTED
,
69 P2P_GROUP_REMOVAL_IDLE_TIMEOUT
,
70 P2P_GROUP_REMOVAL_UNAVAILABLE
,
71 P2P_GROUP_REMOVAL_GO_ENDING_SESSION
75 static void wpas_p2p_long_listen_timeout(void *eloop_ctx
, void *timeout_ctx
);
76 static struct wpa_supplicant
*
77 wpas_p2p_get_group_iface(struct wpa_supplicant
*wpa_s
, int addr_allocated
,
79 static int wpas_p2p_join_start(struct wpa_supplicant
*wpa_s
);
80 static void wpas_p2p_join_scan_req(struct wpa_supplicant
*wpa_s
, int freq
);
81 static void wpas_p2p_join_scan(void *eloop_ctx
, void *timeout_ctx
);
82 static int wpas_p2p_join(struct wpa_supplicant
*wpa_s
, const u8
*iface_addr
,
83 const u8
*dev_addr
, enum p2p_wps_method wps_method
,
85 static void wpas_p2p_pd_before_join_timeout(void *eloop_ctx
,
87 static int wpas_p2p_create_iface(struct wpa_supplicant
*wpa_s
);
88 static void wpas_p2p_cross_connect_setup(struct wpa_supplicant
*wpa_s
);
89 static void wpas_p2p_group_idle_timeout(void *eloop_ctx
, void *timeout_ctx
);
90 static void wpas_p2p_set_group_idle_timeout(struct wpa_supplicant
*wpa_s
);
91 static void wpas_p2p_fallback_to_go_neg(struct wpa_supplicant
*wpa_s
,
95 static void wpas_p2p_scan_res_handler(struct wpa_supplicant
*wpa_s
,
96 struct wpa_scan_results
*scan_res
)
100 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
103 wpa_printf(MSG_DEBUG
, "P2P: Scan results received (%d BSS)",
104 (int) scan_res
->num
);
106 for (i
= 0; i
< scan_res
->num
; i
++) {
107 struct wpa_scan_res
*bss
= scan_res
->res
[i
];
108 if (p2p_scan_res_handler(wpa_s
->global
->p2p
, bss
->bssid
,
109 bss
->freq
, bss
->level
,
110 (const u8
*) (bss
+ 1),
115 p2p_scan_res_handled(wpa_s
->global
->p2p
);
119 static int wpas_p2p_scan(void *ctx
, enum p2p_scan_type type
, int freq
,
120 unsigned int num_req_dev_types
,
121 const u8
*req_dev_types
, const u8
*dev_id
, u16 pw_id
)
123 struct wpa_supplicant
*wpa_s
= ctx
;
124 struct wpa_driver_scan_params params
;
126 struct wpabuf
*wps_ie
, *ies
;
127 int social_channels
[] = { 2412, 2437, 2462, 0, 0 };
130 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
133 os_memset(¶ms
, 0, sizeof(params
));
135 /* P2P Wildcard SSID */
136 params
.num_ssids
= 1;
137 params
.ssids
[0].ssid
= (u8
*) P2P_WILDCARD_SSID
;
138 params
.ssids
[0].ssid_len
= P2P_WILDCARD_SSID_LEN
;
140 wpa_s
->wps
->dev
.p2p
= 1;
141 wps_ie
= wps_build_probe_req_ie(pw_id
, &wpa_s
->wps
->dev
,
142 wpa_s
->wps
->uuid
, WPS_REQ_ENROLLEE
,
143 num_req_dev_types
, req_dev_types
);
147 ielen
= p2p_scan_ie_buf_len(wpa_s
->global
->p2p
);
148 ies
= wpabuf_alloc(wpabuf_len(wps_ie
) + ielen
);
153 wpabuf_put_buf(ies
, wps_ie
);
156 p2p_scan_ie(wpa_s
->global
->p2p
, ies
, dev_id
);
158 params
.p2p_probe
= 1;
159 params
.extra_ies
= wpabuf_head(ies
);
160 params
.extra_ies_len
= wpabuf_len(ies
);
163 case P2P_SCAN_SOCIAL
:
164 params
.freqs
= social_channels
;
168 case P2P_SCAN_SOCIAL_PLUS_ONE
:
169 social_channels
[3] = freq
;
170 params
.freqs
= social_channels
;
174 ret
= wpa_drv_scan(wpa_s
, ¶ms
);
179 if (wpa_s
->scanning
||
180 wpa_s
->scan_res_handler
== wpas_p2p_scan_res_handler
) {
181 wpa_s
->p2p_cb_on_scan_complete
= 1;
185 wpa_s
->scan_res_handler
= wpas_p2p_scan_res_handler
;
191 static enum wpa_driver_if_type
wpas_p2p_if_type(int p2p_group_interface
)
193 switch (p2p_group_interface
) {
194 case P2P_GROUP_INTERFACE_PENDING
:
195 return WPA_IF_P2P_GROUP
;
196 case P2P_GROUP_INTERFACE_GO
:
197 return WPA_IF_P2P_GO
;
198 case P2P_GROUP_INTERFACE_CLIENT
:
199 return WPA_IF_P2P_CLIENT
;
202 return WPA_IF_P2P_GROUP
;
206 static struct wpa_supplicant
* wpas_get_p2p_group(struct wpa_supplicant
*wpa_s
,
208 size_t ssid_len
, int *go
)
212 for (wpa_s
= wpa_s
->global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
213 for (s
= wpa_s
->conf
->ssid
; s
; s
= s
->next
) {
214 if (s
->disabled
!= 0 || !s
->p2p_group
||
215 s
->ssid_len
!= ssid_len
||
216 os_memcmp(ssid
, s
->ssid
, ssid_len
) != 0)
218 if (s
->mode
== WPAS_MODE_P2P_GO
&&
219 s
!= wpa_s
->current_ssid
)
222 *go
= s
->mode
== WPAS_MODE_P2P_GO
;
231 static int wpas_p2p_group_delete(struct wpa_supplicant
*wpa_s
,
232 enum p2p_group_removal_reason removal_reason
)
234 struct wpa_ssid
*ssid
;
238 ssid
= wpa_s
->current_ssid
;
241 * The current SSID was not known, but there may still be a
242 * pending P2P group interface waiting for provisioning.
244 ssid
= wpa_s
->conf
->ssid
;
246 if (ssid
->p2p_group
&&
247 (ssid
->mode
== WPAS_MODE_P2P_GROUP_FORMATION
||
248 (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)))
253 wpa_printf(MSG_ERROR
, "P2P: P2P group interface "
258 if (wpa_s
->p2p_group_interface
== P2P_GROUP_INTERFACE_GO
)
260 else if (wpa_s
->p2p_group_interface
== P2P_GROUP_INTERFACE_CLIENT
||
261 (ssid
&& ssid
->mode
== WPAS_MODE_INFRA
)) {
262 wpa_s
->reassociate
= 0;
263 wpa_s
->disconnected
= 1;
264 wpa_supplicant_deauthenticate(wpa_s
,
265 WLAN_REASON_DEAUTH_LEAVING
);
269 if (wpa_s
->cross_connect_in_use
) {
270 wpa_s
->cross_connect_in_use
= 0;
271 wpa_msg(wpa_s
->parent
, MSG_INFO
,
272 P2P_EVENT_CROSS_CONNECT_DISABLE
"%s %s",
273 wpa_s
->ifname
, wpa_s
->cross_connect_uplink
);
275 switch (removal_reason
) {
276 case P2P_GROUP_REMOVAL_REQUESTED
:
277 reason
= " reason=REQUESTED";
279 case P2P_GROUP_REMOVAL_FORMATION_FAILED
:
280 reason
= " reason=FORMATION_FAILED";
282 case P2P_GROUP_REMOVAL_IDLE_TIMEOUT
:
283 reason
= " reason=IDLE";
285 case P2P_GROUP_REMOVAL_UNAVAILABLE
:
286 reason
= " reason=UNAVAILABLE";
288 case P2P_GROUP_REMOVAL_GO_ENDING_SESSION
:
289 reason
= " reason=GO_ENDING_SESSION";
295 if (removal_reason
!= P2P_GROUP_REMOVAL_SILENT
) {
296 wpa_msg(wpa_s
->parent
, MSG_INFO
,
297 P2P_EVENT_GROUP_REMOVED
"%s %s%s",
298 wpa_s
->ifname
, gtype
, reason
);
301 if (eloop_cancel_timeout(wpas_p2p_group_idle_timeout
, wpa_s
, NULL
) > 0)
302 wpa_printf(MSG_DEBUG
, "P2P: Cancelled P2P group idle timeout");
304 if (removal_reason
!= P2P_GROUP_REMOVAL_SILENT
&& ssid
)
305 wpas_notify_p2p_group_removed(wpa_s
, ssid
, gtype
);
307 if (wpa_s
->p2p_group_interface
!= NOT_P2P_GROUP_INTERFACE
) {
308 struct wpa_global
*global
;
310 enum wpa_driver_if_type type
;
311 wpa_printf(MSG_DEBUG
, "P2P: Remove group interface %s",
313 global
= wpa_s
->global
;
314 ifname
= os_strdup(wpa_s
->ifname
);
315 type
= wpas_p2p_if_type(wpa_s
->p2p_group_interface
);
316 wpa_supplicant_remove_iface(wpa_s
->global
, wpa_s
, 0);
317 wpa_s
= global
->ifaces
;
319 wpa_drv_if_remove(wpa_s
, type
, ifname
);
324 wpa_printf(MSG_DEBUG
, "P2P: Remove temporary group network");
325 if (ssid
&& (ssid
->p2p_group
||
326 ssid
->mode
== WPAS_MODE_P2P_GROUP_FORMATION
||
327 (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
))) {
329 if (ssid
== wpa_s
->current_ssid
) {
330 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
331 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
332 wpa_s
->current_ssid
= NULL
;
335 * Networks objects created during any P2P activities are not
336 * exposed out as they might/will confuse certain non-P2P aware
337 * applications since these network objects won't behave like
340 * Likewise, we don't send out network removed signals for such
343 wpa_config_remove_network(wpa_s
->conf
, id
);
344 wpa_supplicant_clear_status(wpa_s
);
345 wpa_supplicant_cancel_sched_scan(wpa_s
);
347 wpa_printf(MSG_DEBUG
, "P2P: Temporary group network not "
351 wpa_supplicant_ap_deinit(wpa_s
);
353 wpa_drv_deinit_p2p_cli(wpa_s
);
359 static int wpas_p2p_persistent_group(struct wpa_supplicant
*wpa_s
,
361 const u8
*ssid
, size_t ssid_len
)
369 if (wpa_s
->go_params
)
370 bssid
= wpa_s
->go_params
->peer_interface_addr
;
372 bssid
= wpa_s
->bssid
;
374 bss
= wpa_bss_get(wpa_s
, bssid
, ssid
, ssid_len
);
376 u8 iface_addr
[ETH_ALEN
];
377 if (p2p_get_interface_addr(wpa_s
->global
->p2p
, bssid
,
379 bss
= wpa_bss_get(wpa_s
, iface_addr
, ssid
, ssid_len
);
382 wpa_printf(MSG_DEBUG
, "P2P: Could not figure out whether "
383 "group is persistent - BSS " MACSTR
" not found",
388 p2p
= wpa_bss_get_vendor_ie_multi(bss
, P2P_IE_VENDOR_TYPE
);
390 wpa_printf(MSG_DEBUG
, "P2P: Could not figure out whether "
391 "group is persistent - BSS " MACSTR
392 " did not include P2P IE", MAC2STR(bssid
));
393 wpa_hexdump(MSG_DEBUG
, "P2P: Probe Response IEs",
394 (u8
*) (bss
+ 1), bss
->ie_len
);
395 wpa_hexdump(MSG_DEBUG
, "P2P: Beacon IEs",
396 ((u8
*) bss
+ 1) + bss
->ie_len
,
401 group_capab
= p2p_get_group_capab(p2p
);
402 addr
= p2p_get_go_dev_addr(p2p
);
403 wpa_printf(MSG_DEBUG
, "P2P: Checking whether group is persistent: "
404 "group_capab=0x%x", group_capab
);
406 os_memcpy(go_dev_addr
, addr
, ETH_ALEN
);
407 wpa_printf(MSG_DEBUG
, "P2P: GO Device Address " MACSTR
,
410 os_memset(go_dev_addr
, 0, ETH_ALEN
);
413 wpa_printf(MSG_DEBUG
, "P2P: BSS " MACSTR
" group_capab=0x%x "
414 "go_dev_addr=" MACSTR
,
415 MAC2STR(bssid
), group_capab
, MAC2STR(go_dev_addr
));
417 return group_capab
& P2P_GROUP_CAPAB_PERSISTENT_GROUP
;
421 static int wpas_p2p_store_persistent_group(struct wpa_supplicant
*wpa_s
,
422 struct wpa_ssid
*ssid
,
423 const u8
*go_dev_addr
)
428 wpa_printf(MSG_DEBUG
, "P2P: Storing credentials for a persistent "
429 "group (GO Dev Addr " MACSTR
")", MAC2STR(go_dev_addr
));
430 for (s
= wpa_s
->conf
->ssid
; s
; s
= s
->next
) {
431 if (s
->disabled
== 2 &&
432 os_memcmp(go_dev_addr
, s
->bssid
, ETH_ALEN
) == 0 &&
433 s
->ssid_len
== ssid
->ssid_len
&&
434 os_memcmp(ssid
->ssid
, s
->ssid
, ssid
->ssid_len
) == 0)
439 wpa_printf(MSG_DEBUG
, "P2P: Update existing persistent group "
441 if (ssid
->passphrase
&& !s
->passphrase
)
443 else if (ssid
->passphrase
&& s
->passphrase
&&
444 os_strcmp(ssid
->passphrase
, s
->passphrase
) != 0)
447 wpa_printf(MSG_DEBUG
, "P2P: Create a new persistent group "
450 s
= wpa_config_add_network(wpa_s
->conf
);
455 * Instead of network_added we emit persistent_group_added
456 * notification. Also to keep the defense checks in
457 * persistent_group obj registration method, we set the
458 * relevant flags in s to designate it as a persistent group.
461 s
->p2p_persistent_group
= 1;
462 wpas_notify_persistent_group_added(wpa_s
, s
);
463 wpa_config_set_network_defaults(s
);
467 s
->p2p_persistent_group
= 1;
470 os_memcpy(s
->bssid
, go_dev_addr
, ETH_ALEN
);
471 s
->mode
= ssid
->mode
;
472 s
->auth_alg
= WPA_AUTH_ALG_OPEN
;
473 s
->key_mgmt
= WPA_KEY_MGMT_PSK
;
474 s
->proto
= WPA_PROTO_RSN
;
475 s
->pairwise_cipher
= WPA_CIPHER_CCMP
;
477 if (ssid
->passphrase
) {
478 os_free(s
->passphrase
);
479 s
->passphrase
= os_strdup(ssid
->passphrase
);
483 os_memcpy(s
->psk
, ssid
->psk
, 32);
485 if (s
->passphrase
&& !s
->psk_set
)
486 wpa_config_update_psk(s
);
487 if (s
->ssid
== NULL
|| s
->ssid_len
< ssid
->ssid_len
) {
489 s
->ssid
= os_malloc(ssid
->ssid_len
);
492 s
->ssid_len
= ssid
->ssid_len
;
493 os_memcpy(s
->ssid
, ssid
->ssid
, s
->ssid_len
);
496 #ifndef CONFIG_NO_CONFIG_WRITE
497 if (changed
&& wpa_s
->conf
->update_config
&&
498 wpa_config_write(wpa_s
->confname
, wpa_s
->conf
)) {
499 wpa_printf(MSG_DEBUG
, "P2P: Failed to update configuration");
501 #endif /* CONFIG_NO_CONFIG_WRITE */
507 static void wpas_p2p_add_persistent_group_client(struct wpa_supplicant
*wpa_s
,
510 struct wpa_ssid
*ssid
, *s
;
514 ssid
= wpa_s
->current_ssid
;
515 if (ssid
== NULL
|| ssid
->mode
!= WPAS_MODE_P2P_GO
||
516 !ssid
->p2p_persistent_group
)
519 for (s
= wpa_s
->parent
->conf
->ssid
; s
; s
= s
->next
) {
520 if (s
->disabled
!= 2 || s
->mode
!= WPAS_MODE_P2P_GO
)
523 if (s
->ssid_len
== ssid
->ssid_len
&&
524 os_memcmp(s
->ssid
, ssid
->ssid
, s
->ssid_len
) == 0)
531 for (i
= 0; s
->p2p_client_list
&& i
< s
->num_p2p_clients
; i
++) {
532 if (os_memcmp(s
->p2p_client_list
+ i
* ETH_ALEN
, addr
,
534 return; /* already in list */
537 n
= os_realloc_array(s
->p2p_client_list
, s
->num_p2p_clients
+ 1,
541 os_memcpy(n
+ s
->num_p2p_clients
* ETH_ALEN
, addr
, ETH_ALEN
);
542 s
->p2p_client_list
= n
;
543 s
->num_p2p_clients
++;
545 #ifndef CONFIG_NO_CONFIG_WRITE
546 if (wpa_s
->parent
->conf
->update_config
&&
547 wpa_config_write(wpa_s
->parent
->confname
, wpa_s
->parent
->conf
))
548 wpa_printf(MSG_DEBUG
, "P2P: Failed to update configuration");
549 #endif /* CONFIG_NO_CONFIG_WRITE */
553 static void wpas_group_formation_completed(struct wpa_supplicant
*wpa_s
,
556 struct wpa_ssid
*ssid
;
557 const char *ssid_txt
;
560 u8 go_dev_addr
[ETH_ALEN
];
564 * This callback is likely called for the main interface. Update wpa_s
565 * to use the group interface if a new interface was created for the
568 if (wpa_s
->global
->p2p_group_formation
)
569 wpa_s
= wpa_s
->global
->p2p_group_formation
;
570 wpa_s
->global
->p2p_group_formation
= NULL
;
571 wpa_s
->p2p_in_provisioning
= 0;
574 wpa_msg(wpa_s
->parent
, MSG_INFO
,
575 P2P_EVENT_GROUP_FORMATION_FAILURE
);
576 wpas_p2p_group_delete(wpa_s
,
577 P2P_GROUP_REMOVAL_FORMATION_FAILED
);
581 wpa_msg(wpa_s
->parent
, MSG_INFO
, P2P_EVENT_GROUP_FORMATION_SUCCESS
);
583 ssid
= wpa_s
->current_ssid
;
584 if (ssid
&& ssid
->mode
== WPAS_MODE_P2P_GROUP_FORMATION
) {
585 ssid
->mode
= WPAS_MODE_P2P_GO
;
586 p2p_group_notif_formation_done(wpa_s
->p2p_group
);
587 wpa_supplicant_ap_mac_addr_filter(wpa_s
, NULL
);
592 ssid_txt
= wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
);
593 client
= ssid
->mode
== WPAS_MODE_INFRA
;
594 if (ssid
->mode
== WPAS_MODE_P2P_GO
) {
595 persistent
= ssid
->p2p_persistent_group
;
596 os_memcpy(go_dev_addr
, wpa_s
->global
->p2p_dev_addr
,
599 persistent
= wpas_p2p_persistent_group(wpa_s
,
605 client
= wpa_s
->p2p_group_interface
==
606 P2P_GROUP_INTERFACE_CLIENT
;
607 os_memset(go_dev_addr
, 0, ETH_ALEN
);
610 wpa_s
->show_group_started
= 0;
613 * Indicate event only after successfully completed 4-way
614 * handshake, i.e., when the interface is ready for data
617 wpa_s
->show_group_started
= 1;
618 } else if (ssid
&& ssid
->passphrase
== NULL
&& ssid
->psk_set
) {
620 wpa_snprintf_hex(psk
, sizeof(psk
), ssid
->psk
, 32);
621 wpa_msg(wpa_s
->parent
, MSG_INFO
, P2P_EVENT_GROUP_STARTED
622 "%s GO ssid=\"%s\" freq=%d psk=%s go_dev_addr=" MACSTR
624 wpa_s
->ifname
, ssid_txt
, ssid
->frequency
, psk
,
625 MAC2STR(go_dev_addr
),
626 persistent
? " [PERSISTENT]" : "");
627 wpas_p2p_cross_connect_setup(wpa_s
);
628 wpas_p2p_set_group_idle_timeout(wpa_s
);
630 wpa_msg(wpa_s
->parent
, MSG_INFO
, P2P_EVENT_GROUP_STARTED
631 "%s GO ssid=\"%s\" freq=%d passphrase=\"%s\" "
632 "go_dev_addr=" MACSTR
"%s",
633 wpa_s
->ifname
, ssid_txt
, ssid
? ssid
->frequency
: 0,
634 ssid
&& ssid
->passphrase
? ssid
->passphrase
: "",
635 MAC2STR(go_dev_addr
),
636 persistent
? " [PERSISTENT]" : "");
637 wpas_p2p_cross_connect_setup(wpa_s
);
638 wpas_p2p_set_group_idle_timeout(wpa_s
);
642 network_id
= wpas_p2p_store_persistent_group(wpa_s
->parent
,
644 if (network_id
< 0 && ssid
)
645 network_id
= ssid
->id
;
647 wpas_notify_p2p_group_started(wpa_s
, ssid
, network_id
, 0);
651 static void wpas_p2p_send_action_tx_status(struct wpa_supplicant
*wpa_s
,
653 const u8
*dst
, const u8
*src
,
655 const u8
*data
, size_t data_len
,
656 enum offchannel_send_action_result
659 enum p2p_send_action_result res
= P2P_SEND_ACTION_SUCCESS
;
661 if (wpa_s
->global
->p2p
== NULL
|| wpa_s
->global
->p2p_disabled
)
663 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
)
667 case OFFCHANNEL_SEND_ACTION_SUCCESS
:
668 res
= P2P_SEND_ACTION_SUCCESS
;
670 case OFFCHANNEL_SEND_ACTION_NO_ACK
:
671 res
= P2P_SEND_ACTION_NO_ACK
;
673 case OFFCHANNEL_SEND_ACTION_FAILED
:
674 res
= P2P_SEND_ACTION_FAILED
;
678 p2p_send_action_cb(wpa_s
->global
->p2p
, freq
, dst
, src
, bssid
, res
);
680 if (result
!= OFFCHANNEL_SEND_ACTION_SUCCESS
&&
681 wpa_s
->pending_pd_before_join
&&
682 (os_memcmp(dst
, wpa_s
->pending_join_dev_addr
, ETH_ALEN
) == 0 ||
683 os_memcmp(dst
, wpa_s
->pending_join_iface_addr
, ETH_ALEN
) == 0)) {
684 wpa_s
->pending_pd_before_join
= 0;
685 if (wpa_s
->p2p_fallback_to_go_neg
) {
686 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: No ACK for PD Req "
687 "during p2p_connect-auto");
688 wpas_p2p_fallback_to_go_neg(wpa_s
, 0);
692 wpa_printf(MSG_DEBUG
, "P2P: Starting pending "
693 "join-existing-group operation (no ACK for PD "
695 wpas_p2p_join_start(wpa_s
);
700 static int wpas_send_action(void *ctx
, unsigned int freq
, const u8
*dst
,
701 const u8
*src
, const u8
*bssid
, const u8
*buf
,
702 size_t len
, unsigned int wait_time
)
704 struct wpa_supplicant
*wpa_s
= ctx
;
705 return offchannel_send_action(wpa_s
, freq
, dst
, src
, bssid
, buf
, len
,
707 wpas_p2p_send_action_tx_status
, 1);
711 static void wpas_send_action_done(void *ctx
)
713 struct wpa_supplicant
*wpa_s
= ctx
;
714 offchannel_send_action_done(wpa_s
);
718 static int wpas_copy_go_neg_results(struct wpa_supplicant
*wpa_s
,
719 struct p2p_go_neg_results
*params
)
721 if (wpa_s
->go_params
== NULL
) {
722 wpa_s
->go_params
= os_malloc(sizeof(*params
));
723 if (wpa_s
->go_params
== NULL
)
726 os_memcpy(wpa_s
->go_params
, params
, sizeof(*params
));
731 static void wpas_start_wps_enrollee(struct wpa_supplicant
*wpa_s
,
732 struct p2p_go_neg_results
*res
)
734 wpa_printf(MSG_DEBUG
, "P2P: Start WPS Enrollee for peer " MACSTR
,
735 MAC2STR(res
->peer_interface_addr
));
736 wpa_hexdump_ascii(MSG_DEBUG
, "P2P: Start WPS Enrollee for SSID",
737 res
->ssid
, res
->ssid_len
);
738 wpa_supplicant_ap_deinit(wpa_s
);
739 wpas_copy_go_neg_results(wpa_s
, res
);
740 if (res
->wps_method
== WPS_PBC
)
741 wpas_wps_start_pbc(wpa_s
, res
->peer_interface_addr
, 1);
743 u16 dev_pw_id
= DEV_PW_DEFAULT
;
744 if (wpa_s
->p2p_wps_method
== WPS_PIN_KEYPAD
)
745 dev_pw_id
= DEV_PW_REGISTRAR_SPECIFIED
;
746 wpas_wps_start_pin(wpa_s
, res
->peer_interface_addr
,
747 wpa_s
->p2p_pin
, 1, dev_pw_id
);
752 static void p2p_go_configured(void *ctx
, void *data
)
754 struct wpa_supplicant
*wpa_s
= ctx
;
755 struct p2p_go_neg_results
*params
= data
;
756 struct wpa_ssid
*ssid
;
759 ssid
= wpa_s
->current_ssid
;
760 if (ssid
&& ssid
->mode
== WPAS_MODE_P2P_GO
) {
761 wpa_printf(MSG_DEBUG
, "P2P: Group setup without provisioning");
762 if (wpa_s
->global
->p2p_group_formation
== wpa_s
)
763 wpa_s
->global
->p2p_group_formation
= NULL
;
764 wpa_msg(wpa_s
->parent
, MSG_INFO
, P2P_EVENT_GROUP_STARTED
765 "%s GO ssid=\"%s\" freq=%d passphrase=\"%s\" "
766 "go_dev_addr=" MACSTR
"%s",
768 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
),
770 params
->passphrase
? params
->passphrase
: "",
771 MAC2STR(wpa_s
->global
->p2p_dev_addr
),
772 params
->persistent_group
? " [PERSISTENT]" : "");
774 if (params
->persistent_group
)
775 network_id
= wpas_p2p_store_persistent_group(
777 wpa_s
->global
->p2p_dev_addr
);
779 network_id
= ssid
->id
;
780 wpas_notify_p2p_group_started(wpa_s
, ssid
, network_id
, 0);
781 wpas_p2p_cross_connect_setup(wpa_s
);
782 wpas_p2p_set_group_idle_timeout(wpa_s
);
786 wpa_printf(MSG_DEBUG
, "P2P: Setting up WPS for GO provisioning");
787 if (wpa_supplicant_ap_mac_addr_filter(wpa_s
,
788 params
->peer_interface_addr
)) {
789 wpa_printf(MSG_DEBUG
, "P2P: Failed to setup MAC address "
793 if (params
->wps_method
== WPS_PBC
)
794 wpa_supplicant_ap_wps_pbc(wpa_s
, params
->peer_interface_addr
,
795 params
->peer_device_addr
);
796 else if (wpa_s
->p2p_pin
[0])
797 wpa_supplicant_ap_wps_pin(wpa_s
, params
->peer_interface_addr
,
798 wpa_s
->p2p_pin
, NULL
, 0);
799 os_free(wpa_s
->go_params
);
800 wpa_s
->go_params
= NULL
;
804 static void wpas_start_wps_go(struct wpa_supplicant
*wpa_s
,
805 struct p2p_go_neg_results
*params
,
808 struct wpa_ssid
*ssid
;
810 if (wpas_copy_go_neg_results(wpa_s
, params
) < 0)
813 ssid
= wpa_config_add_network(wpa_s
->conf
);
817 wpa_s
->show_group_started
= 0;
819 wpa_config_set_network_defaults(ssid
);
822 ssid
->p2p_persistent_group
= params
->persistent_group
;
823 ssid
->mode
= group_formation
? WPAS_MODE_P2P_GROUP_FORMATION
:
825 ssid
->frequency
= params
->freq
;
826 ssid
->ht40
= params
->ht40
;
827 ssid
->ssid
= os_zalloc(params
->ssid_len
+ 1);
829 os_memcpy(ssid
->ssid
, params
->ssid
, params
->ssid_len
);
830 ssid
->ssid_len
= params
->ssid_len
;
832 ssid
->auth_alg
= WPA_AUTH_ALG_OPEN
;
833 ssid
->key_mgmt
= WPA_KEY_MGMT_PSK
;
834 ssid
->proto
= WPA_PROTO_RSN
;
835 ssid
->pairwise_cipher
= WPA_CIPHER_CCMP
;
836 ssid
->passphrase
= os_strdup(params
->passphrase
);
837 ssid
->ap_max_inactivity
= wpa_s
->parent
->conf
->p2p_go_max_inactivity
;
839 wpa_s
->ap_configured_cb
= p2p_go_configured
;
840 wpa_s
->ap_configured_cb_ctx
= wpa_s
;
841 wpa_s
->ap_configured_cb_data
= wpa_s
->go_params
;
842 wpa_s
->connect_without_scan
= ssid
;
843 wpa_s
->reassociate
= 1;
844 wpa_s
->disconnected
= 0;
845 wpa_supplicant_req_scan(wpa_s
, 0, 0);
849 static void wpas_p2p_clone_config(struct wpa_supplicant
*dst
,
850 const struct wpa_supplicant
*src
)
852 struct wpa_config
*d
;
853 const struct wpa_config
*s
;
858 #define C(n) if (s->n) d->n = os_strdup(s->n)
867 os_memcpy(d
->device_type
, s
->device_type
, WPS_DEV_TYPE_LEN
);
868 os_memcpy(d
->sec_device_type
, s
->sec_device_type
,
869 sizeof(d
->sec_device_type
));
870 d
->num_sec_device_types
= s
->num_sec_device_types
;
872 d
->p2p_group_idle
= s
->p2p_group_idle
;
873 d
->p2p_intra_bss
= s
->p2p_intra_bss
;
874 d
->persistent_reconnect
= s
->persistent_reconnect
;
875 d
->max_num_sta
= s
->max_num_sta
;
876 d
->pbc_in_m1
= s
->pbc_in_m1
;
880 static int wpas_p2p_add_group_interface(struct wpa_supplicant
*wpa_s
,
881 enum wpa_driver_if_type type
)
883 char ifname
[120], force_ifname
[120];
885 if (wpa_s
->pending_interface_name
[0]) {
886 wpa_printf(MSG_DEBUG
, "P2P: Pending virtual interface exists "
887 "- skip creation of a new one");
888 if (is_zero_ether_addr(wpa_s
->pending_interface_addr
)) {
889 wpa_printf(MSG_DEBUG
, "P2P: Pending virtual address "
890 "unknown?! ifname='%s'",
891 wpa_s
->pending_interface_name
);
897 os_snprintf(ifname
, sizeof(ifname
), "p2p-%s-%d", wpa_s
->ifname
,
898 wpa_s
->p2p_group_idx
);
899 if (os_strlen(ifname
) >= IFNAMSIZ
&&
900 os_strlen(wpa_s
->ifname
) < IFNAMSIZ
) {
901 /* Try to avoid going over the IFNAMSIZ length limit */
902 os_snprintf(ifname
, sizeof(ifname
), "p2p-%d",
903 wpa_s
->p2p_group_idx
);
905 force_ifname
[0] = '\0';
907 wpa_printf(MSG_DEBUG
, "P2P: Create a new interface %s for the group",
909 wpa_s
->p2p_group_idx
++;
911 wpa_s
->pending_interface_type
= type
;
912 if (wpa_drv_if_add(wpa_s
, type
, ifname
, NULL
, NULL
, force_ifname
,
913 wpa_s
->pending_interface_addr
, NULL
) < 0) {
914 wpa_printf(MSG_ERROR
, "P2P: Failed to create new group "
919 if (force_ifname
[0]) {
920 wpa_printf(MSG_DEBUG
, "P2P: Driver forced interface name %s",
922 os_strlcpy(wpa_s
->pending_interface_name
, force_ifname
,
923 sizeof(wpa_s
->pending_interface_name
));
925 os_strlcpy(wpa_s
->pending_interface_name
, ifname
,
926 sizeof(wpa_s
->pending_interface_name
));
927 wpa_printf(MSG_DEBUG
, "P2P: Created pending virtual interface %s addr "
928 MACSTR
, wpa_s
->pending_interface_name
,
929 MAC2STR(wpa_s
->pending_interface_addr
));
935 static void wpas_p2p_remove_pending_group_interface(
936 struct wpa_supplicant
*wpa_s
)
938 if (!wpa_s
->pending_interface_name
[0] ||
939 is_zero_ether_addr(wpa_s
->pending_interface_addr
))
940 return; /* No pending virtual interface */
942 wpa_printf(MSG_DEBUG
, "P2P: Removing pending group interface %s",
943 wpa_s
->pending_interface_name
);
944 wpa_drv_if_remove(wpa_s
, wpa_s
->pending_interface_type
,
945 wpa_s
->pending_interface_name
);
946 os_memset(wpa_s
->pending_interface_addr
, 0, ETH_ALEN
);
947 wpa_s
->pending_interface_name
[0] = '\0';
951 static struct wpa_supplicant
*
952 wpas_p2p_init_group_interface(struct wpa_supplicant
*wpa_s
, int go
)
954 struct wpa_interface iface
;
955 struct wpa_supplicant
*group_wpa_s
;
957 if (!wpa_s
->pending_interface_name
[0]) {
958 wpa_printf(MSG_ERROR
, "P2P: No pending group interface");
959 if (!wpas_p2p_create_iface(wpa_s
))
962 * Something has forced us to remove the pending interface; try
963 * to create a new one and hope for the best that we will get
964 * the same local address.
966 if (wpas_p2p_add_group_interface(wpa_s
, go
? WPA_IF_P2P_GO
:
967 WPA_IF_P2P_CLIENT
) < 0)
971 os_memset(&iface
, 0, sizeof(iface
));
972 iface
.ifname
= wpa_s
->pending_interface_name
;
973 iface
.driver
= wpa_s
->driver
->name
;
974 iface
.ctrl_interface
= wpa_s
->conf
->ctrl_interface
;
975 iface
.driver_param
= wpa_s
->conf
->driver_param
;
976 group_wpa_s
= wpa_supplicant_add_iface(wpa_s
->global
, &iface
);
977 if (group_wpa_s
== NULL
) {
978 wpa_printf(MSG_ERROR
, "P2P: Failed to create new "
979 "wpa_supplicant interface");
982 wpa_s
->pending_interface_name
[0] = '\0';
983 group_wpa_s
->parent
= wpa_s
;
984 group_wpa_s
->p2p_group_interface
= go
? P2P_GROUP_INTERFACE_GO
:
985 P2P_GROUP_INTERFACE_CLIENT
;
986 wpa_s
->global
->p2p_group_formation
= group_wpa_s
;
988 wpas_p2p_clone_config(group_wpa_s
, wpa_s
);
994 static void wpas_p2p_group_formation_timeout(void *eloop_ctx
,
997 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
998 wpa_printf(MSG_DEBUG
, "P2P: Group Formation timed out");
999 if (wpa_s
->global
->p2p
)
1000 p2p_group_formation_failed(wpa_s
->global
->p2p
);
1001 else if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
)
1002 wpa_drv_p2p_group_formation_failed(wpa_s
);
1003 wpas_group_formation_completed(wpa_s
, 0);
1007 void wpas_go_neg_completed(void *ctx
, struct p2p_go_neg_results
*res
)
1009 struct wpa_supplicant
*wpa_s
= ctx
;
1011 if (wpa_s
->off_channel_freq
|| wpa_s
->roc_waiting_drv_freq
) {
1012 wpa_drv_cancel_remain_on_channel(wpa_s
);
1013 wpa_s
->off_channel_freq
= 0;
1014 wpa_s
->roc_waiting_drv_freq
= 0;
1018 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_GO_NEG_FAILURE
"status=%d",
1020 wpas_notify_p2p_go_neg_completed(wpa_s
, res
);
1021 wpas_p2p_remove_pending_group_interface(wpa_s
);
1025 if (wpa_s
->p2p_go_ht40
)
1028 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_GO_NEG_SUCCESS
);
1029 wpas_notify_p2p_go_neg_completed(wpa_s
, res
);
1031 if (res
->role_go
&& wpa_s
->p2p_persistent_id
>= 0) {
1032 struct wpa_ssid
*ssid
;
1033 ssid
= wpa_config_get_network(wpa_s
->conf
,
1034 wpa_s
->p2p_persistent_id
);
1035 if (ssid
&& ssid
->disabled
== 2 &&
1036 ssid
->mode
== WPAS_MODE_P2P_GO
&& ssid
->passphrase
) {
1037 size_t len
= os_strlen(ssid
->passphrase
);
1038 wpa_printf(MSG_DEBUG
, "P2P: Override passphrase based "
1039 "on requested persistent group");
1040 os_memcpy(res
->passphrase
, ssid
->passphrase
, len
);
1041 res
->passphrase
[len
] = '\0';
1045 if (wpa_s
->create_p2p_iface
) {
1046 struct wpa_supplicant
*group_wpa_s
=
1047 wpas_p2p_init_group_interface(wpa_s
, res
->role_go
);
1048 if (group_wpa_s
== NULL
) {
1049 wpas_p2p_remove_pending_group_interface(wpa_s
);
1052 if (group_wpa_s
!= wpa_s
) {
1053 os_memcpy(group_wpa_s
->p2p_pin
, wpa_s
->p2p_pin
,
1054 sizeof(group_wpa_s
->p2p_pin
));
1055 group_wpa_s
->p2p_wps_method
= wpa_s
->p2p_wps_method
;
1057 os_memset(wpa_s
->pending_interface_addr
, 0, ETH_ALEN
);
1058 wpa_s
->pending_interface_name
[0] = '\0';
1059 group_wpa_s
->p2p_in_provisioning
= 1;
1062 wpas_start_wps_go(group_wpa_s
, res
, 1);
1064 wpas_start_wps_enrollee(group_wpa_s
, res
);
1066 wpa_s
->p2p_in_provisioning
= 1;
1067 wpa_s
->global
->p2p_group_formation
= wpa_s
;
1070 wpas_start_wps_go(wpa_s
, res
, 1);
1072 wpas_start_wps_enrollee(ctx
, res
);
1075 wpa_s
->p2p_long_listen
= 0;
1076 eloop_cancel_timeout(wpas_p2p_long_listen_timeout
, wpa_s
, NULL
);
1078 eloop_cancel_timeout(wpas_p2p_group_formation_timeout
, wpa_s
, NULL
);
1079 eloop_register_timeout(15 + res
->peer_config_timeout
/ 100,
1080 (res
->peer_config_timeout
% 100) * 10000,
1081 wpas_p2p_group_formation_timeout
, wpa_s
, NULL
);
1085 void wpas_go_neg_req_rx(void *ctx
, const u8
*src
, u16 dev_passwd_id
)
1087 struct wpa_supplicant
*wpa_s
= ctx
;
1088 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_GO_NEG_REQUEST MACSTR
1089 " dev_passwd_id=%u", MAC2STR(src
), dev_passwd_id
);
1091 wpas_notify_p2p_go_neg_req(wpa_s
, src
, dev_passwd_id
);
1095 void wpas_dev_found(void *ctx
, const u8
*addr
,
1096 const struct p2p_peer_info
*info
,
1099 #ifndef CONFIG_NO_STDOUT_DEBUG
1100 struct wpa_supplicant
*wpa_s
= ctx
;
1101 char devtype
[WPS_DEV_TYPE_BUFSIZE
];
1103 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_DEVICE_FOUND MACSTR
1104 " p2p_dev_addr=" MACSTR
1105 " pri_dev_type=%s name='%s' config_methods=0x%x "
1106 "dev_capab=0x%x group_capab=0x%x",
1107 MAC2STR(addr
), MAC2STR(info
->p2p_device_addr
),
1108 wps_dev_type_bin2str(info
->pri_dev_type
, devtype
,
1110 info
->device_name
, info
->config_methods
,
1111 info
->dev_capab
, info
->group_capab
);
1112 #endif /* CONFIG_NO_STDOUT_DEBUG */
1114 wpas_notify_p2p_device_found(ctx
, info
->p2p_device_addr
, new_device
);
1118 static void wpas_dev_lost(void *ctx
, const u8
*dev_addr
)
1120 struct wpa_supplicant
*wpa_s
= ctx
;
1122 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_DEVICE_LOST
1123 "p2p_dev_addr=" MACSTR
, MAC2STR(dev_addr
));
1125 wpas_notify_p2p_device_lost(wpa_s
, dev_addr
);
1129 static int wpas_start_listen(void *ctx
, unsigned int freq
,
1130 unsigned int duration
,
1131 const struct wpabuf
*probe_resp_ie
)
1133 struct wpa_supplicant
*wpa_s
= ctx
;
1135 wpa_drv_set_ap_wps_ie(wpa_s
, NULL
, probe_resp_ie
, NULL
);
1137 if (wpa_drv_probe_req_report(wpa_s
, 1) < 0) {
1138 wpa_printf(MSG_DEBUG
, "P2P: Failed to request the driver to "
1139 "report received Probe Request frames");
1143 wpa_s
->pending_listen_freq
= freq
;
1144 wpa_s
->pending_listen_duration
= duration
;
1146 if (wpa_drv_remain_on_channel(wpa_s
, freq
, duration
) < 0) {
1147 wpa_printf(MSG_DEBUG
, "P2P: Failed to request the driver "
1148 "to remain on channel (%u MHz) for Listen "
1150 wpa_s
->pending_listen_freq
= 0;
1153 wpa_s
->off_channel_freq
= 0;
1154 wpa_s
->roc_waiting_drv_freq
= freq
;
1160 static void wpas_stop_listen(void *ctx
)
1162 struct wpa_supplicant
*wpa_s
= ctx
;
1163 if (wpa_s
->off_channel_freq
|| wpa_s
->roc_waiting_drv_freq
) {
1164 wpa_drv_cancel_remain_on_channel(wpa_s
);
1165 wpa_s
->off_channel_freq
= 0;
1166 wpa_s
->roc_waiting_drv_freq
= 0;
1168 wpa_drv_set_ap_wps_ie(wpa_s
, NULL
, NULL
, NULL
);
1169 wpa_drv_probe_req_report(wpa_s
, 0);
1173 static int wpas_send_probe_resp(void *ctx
, const struct wpabuf
*buf
)
1175 struct wpa_supplicant
*wpa_s
= ctx
;
1176 return wpa_drv_send_mlme(wpa_s
, wpabuf_head(buf
), wpabuf_len(buf
), 1);
1180 static struct p2p_srv_bonjour
*
1181 wpas_p2p_service_get_bonjour(struct wpa_supplicant
*wpa_s
,
1182 const struct wpabuf
*query
)
1184 struct p2p_srv_bonjour
*bsrv
;
1187 len
= wpabuf_len(query
);
1188 dl_list_for_each(bsrv
, &wpa_s
->global
->p2p_srv_bonjour
,
1189 struct p2p_srv_bonjour
, list
) {
1190 if (len
== wpabuf_len(bsrv
->query
) &&
1191 os_memcmp(wpabuf_head(query
), wpabuf_head(bsrv
->query
),
1199 static struct p2p_srv_upnp
*
1200 wpas_p2p_service_get_upnp(struct wpa_supplicant
*wpa_s
, u8 version
,
1201 const char *service
)
1203 struct p2p_srv_upnp
*usrv
;
1205 dl_list_for_each(usrv
, &wpa_s
->global
->p2p_srv_upnp
,
1206 struct p2p_srv_upnp
, list
) {
1207 if (version
== usrv
->version
&&
1208 os_strcmp(service
, usrv
->service
) == 0)
1215 static void wpas_sd_add_proto_not_avail(struct wpabuf
*resp
, u8 srv_proto
,
1220 if (wpabuf_tailroom(resp
) < 5)
1223 /* Length (to be filled) */
1224 len_pos
= wpabuf_put(resp
, 2);
1225 wpabuf_put_u8(resp
, srv_proto
);
1226 wpabuf_put_u8(resp
, srv_trans_id
);
1228 wpabuf_put_u8(resp
, P2P_SD_PROTO_NOT_AVAILABLE
);
1229 /* Response Data: empty */
1230 WPA_PUT_LE16(len_pos
, (u8
*) wpabuf_put(resp
, 0) - len_pos
- 2);
1234 static void wpas_sd_all_bonjour(struct wpa_supplicant
*wpa_s
,
1235 struct wpabuf
*resp
, u8 srv_trans_id
)
1237 struct p2p_srv_bonjour
*bsrv
;
1240 wpa_printf(MSG_DEBUG
, "P2P: SD Request for all Bonjour services");
1242 if (dl_list_empty(&wpa_s
->global
->p2p_srv_bonjour
)) {
1243 wpa_printf(MSG_DEBUG
, "P2P: Bonjour protocol not available");
1247 dl_list_for_each(bsrv
, &wpa_s
->global
->p2p_srv_bonjour
,
1248 struct p2p_srv_bonjour
, list
) {
1249 if (wpabuf_tailroom(resp
) <
1250 5 + wpabuf_len(bsrv
->query
) + wpabuf_len(bsrv
->resp
))
1252 /* Length (to be filled) */
1253 len_pos
= wpabuf_put(resp
, 2);
1254 wpabuf_put_u8(resp
, P2P_SERV_BONJOUR
);
1255 wpabuf_put_u8(resp
, srv_trans_id
);
1257 wpabuf_put_u8(resp
, P2P_SD_SUCCESS
);
1258 wpa_hexdump_ascii(MSG_DEBUG
, "P2P: Matching Bonjour service",
1259 wpabuf_head(bsrv
->resp
),
1260 wpabuf_len(bsrv
->resp
));
1262 wpabuf_put_buf(resp
, bsrv
->query
); /* Key */
1263 wpabuf_put_buf(resp
, bsrv
->resp
); /* Value */
1264 WPA_PUT_LE16(len_pos
, (u8
*) wpabuf_put(resp
, 0) - len_pos
-
1270 static void wpas_sd_req_bonjour(struct wpa_supplicant
*wpa_s
,
1271 struct wpabuf
*resp
, u8 srv_trans_id
,
1272 const u8
*query
, size_t query_len
)
1274 struct p2p_srv_bonjour
*bsrv
;
1278 wpa_hexdump_ascii(MSG_DEBUG
, "P2P: SD Request for Bonjour",
1280 if (dl_list_empty(&wpa_s
->global
->p2p_srv_bonjour
)) {
1281 wpa_printf(MSG_DEBUG
, "P2P: Bonjour protocol not available");
1282 wpas_sd_add_proto_not_avail(resp
, P2P_SERV_BONJOUR
,
1287 if (query_len
== 0) {
1288 wpas_sd_all_bonjour(wpa_s
, resp
, srv_trans_id
);
1292 if (wpabuf_tailroom(resp
) < 5)
1294 /* Length (to be filled) */
1295 len_pos
= wpabuf_put(resp
, 2);
1296 wpabuf_put_u8(resp
, P2P_SERV_BONJOUR
);
1297 wpabuf_put_u8(resp
, srv_trans_id
);
1299 wpabuf_set(&buf
, query
, query_len
);
1300 bsrv
= wpas_p2p_service_get_bonjour(wpa_s
, &buf
);
1302 wpa_printf(MSG_DEBUG
, "P2P: Requested Bonjour service not "
1306 wpabuf_put_u8(resp
, P2P_SD_REQUESTED_INFO_NOT_AVAILABLE
);
1307 /* Response Data: empty */
1308 WPA_PUT_LE16(len_pos
, (u8
*) wpabuf_put(resp
, 0) - len_pos
-
1314 wpabuf_put_u8(resp
, P2P_SD_SUCCESS
);
1315 wpa_hexdump_ascii(MSG_DEBUG
, "P2P: Matching Bonjour service",
1316 wpabuf_head(bsrv
->resp
), wpabuf_len(bsrv
->resp
));
1318 if (wpabuf_tailroom(resp
) >=
1319 wpabuf_len(bsrv
->query
) + wpabuf_len(bsrv
->resp
)) {
1321 wpabuf_put_buf(resp
, bsrv
->query
); /* Key */
1322 wpabuf_put_buf(resp
, bsrv
->resp
); /* Value */
1324 WPA_PUT_LE16(len_pos
, (u8
*) wpabuf_put(resp
, 0) - len_pos
- 2);
1328 static void wpas_sd_all_upnp(struct wpa_supplicant
*wpa_s
,
1329 struct wpabuf
*resp
, u8 srv_trans_id
)
1331 struct p2p_srv_upnp
*usrv
;
1334 wpa_printf(MSG_DEBUG
, "P2P: SD Request for all UPnP services");
1336 if (dl_list_empty(&wpa_s
->global
->p2p_srv_upnp
)) {
1337 wpa_printf(MSG_DEBUG
, "P2P: UPnP protocol not available");
1341 dl_list_for_each(usrv
, &wpa_s
->global
->p2p_srv_upnp
,
1342 struct p2p_srv_upnp
, list
) {
1343 if (wpabuf_tailroom(resp
) < 5 + 1 + os_strlen(usrv
->service
))
1346 /* Length (to be filled) */
1347 len_pos
= wpabuf_put(resp
, 2);
1348 wpabuf_put_u8(resp
, P2P_SERV_UPNP
);
1349 wpabuf_put_u8(resp
, srv_trans_id
);
1352 wpabuf_put_u8(resp
, P2P_SD_SUCCESS
);
1354 wpabuf_put_u8(resp
, usrv
->version
);
1355 wpa_printf(MSG_DEBUG
, "P2P: Matching UPnP Service: %s",
1357 wpabuf_put_str(resp
, usrv
->service
);
1358 WPA_PUT_LE16(len_pos
, (u8
*) wpabuf_put(resp
, 0) - len_pos
-
1364 static void wpas_sd_req_upnp(struct wpa_supplicant
*wpa_s
,
1365 struct wpabuf
*resp
, u8 srv_trans_id
,
1366 const u8
*query
, size_t query_len
)
1368 struct p2p_srv_upnp
*usrv
;
1374 wpa_hexdump_ascii(MSG_DEBUG
, "P2P: SD Request for UPnP",
1377 if (dl_list_empty(&wpa_s
->global
->p2p_srv_upnp
)) {
1378 wpa_printf(MSG_DEBUG
, "P2P: UPnP protocol not available");
1379 wpas_sd_add_proto_not_avail(resp
, P2P_SERV_UPNP
,
1384 if (query_len
== 0) {
1385 wpas_sd_all_upnp(wpa_s
, resp
, srv_trans_id
);
1389 if (wpabuf_tailroom(resp
) < 5)
1392 /* Length (to be filled) */
1393 len_pos
= wpabuf_put(resp
, 2);
1394 wpabuf_put_u8(resp
, P2P_SERV_UPNP
);
1395 wpabuf_put_u8(resp
, srv_trans_id
);
1398 str
= os_malloc(query_len
);
1401 os_memcpy(str
, query
+ 1, query_len
- 1);
1402 str
[query_len
- 1] = '\0';
1404 dl_list_for_each(usrv
, &wpa_s
->global
->p2p_srv_upnp
,
1405 struct p2p_srv_upnp
, list
) {
1406 if (version
!= usrv
->version
)
1409 if (os_strcmp(str
, "ssdp:all") != 0 &&
1410 os_strstr(usrv
->service
, str
) == NULL
)
1413 if (wpabuf_tailroom(resp
) < 2)
1417 wpabuf_put_u8(resp
, P2P_SD_SUCCESS
);
1419 wpabuf_put_u8(resp
, version
);
1421 wpabuf_put_u8(resp
, ',');
1425 wpa_printf(MSG_DEBUG
, "P2P: Matching UPnP Service: %s",
1427 if (wpabuf_tailroom(resp
) < os_strlen(usrv
->service
))
1429 wpabuf_put_str(resp
, usrv
->service
);
1434 wpa_printf(MSG_DEBUG
, "P2P: Requested UPnP service not "
1437 wpabuf_put_u8(resp
, P2P_SD_REQUESTED_INFO_NOT_AVAILABLE
);
1438 /* Response Data: empty */
1441 WPA_PUT_LE16(len_pos
, (u8
*) wpabuf_put(resp
, 0) - len_pos
- 2);
1445 void wpas_sd_request(void *ctx
, int freq
, const u8
*sa
, u8 dialog_token
,
1446 u16 update_indic
, const u8
*tlvs
, size_t tlvs_len
)
1448 struct wpa_supplicant
*wpa_s
= ctx
;
1449 const u8
*pos
= tlvs
;
1450 const u8
*end
= tlvs
+ tlvs_len
;
1453 struct wpabuf
*resp
;
1454 u8 srv_proto
, srv_trans_id
;
1458 wpa_hexdump(MSG_MSGDUMP
, "P2P: Service Discovery Request TLVs",
1460 buf_len
= 2 * tlvs_len
+ 1;
1461 buf
= os_malloc(buf_len
);
1463 wpa_snprintf_hex(buf
, buf_len
, tlvs
, tlvs_len
);
1464 wpa_msg_ctrl(wpa_s
, MSG_INFO
, P2P_EVENT_SERV_DISC_REQ
"%d "
1466 freq
, MAC2STR(sa
), dialog_token
, update_indic
,
1471 if (wpa_s
->p2p_sd_over_ctrl_iface
) {
1472 wpas_notify_p2p_sd_request(wpa_s
, freq
, sa
, dialog_token
,
1473 update_indic
, tlvs
, tlvs_len
);
1474 return; /* to be processed by an external program */
1477 resp
= wpabuf_alloc(10000);
1481 while (pos
+ 1 < end
) {
1482 wpa_printf(MSG_DEBUG
, "P2P: Service Request TLV");
1483 slen
= WPA_GET_LE16(pos
);
1485 if (pos
+ slen
> end
|| slen
< 2) {
1486 wpa_printf(MSG_DEBUG
, "P2P: Unexpected Query Data "
1491 tlv_end
= pos
+ slen
;
1494 wpa_printf(MSG_DEBUG
, "P2P: Service Protocol Type %u",
1496 srv_trans_id
= *pos
++;
1497 wpa_printf(MSG_DEBUG
, "P2P: Service Transaction ID %u",
1500 wpa_hexdump(MSG_MSGDUMP
, "P2P: Query Data",
1501 pos
, tlv_end
- pos
);
1504 if (wpa_s
->force_long_sd
) {
1505 wpa_printf(MSG_DEBUG
, "P2P: SD test - force long "
1507 wpas_sd_all_bonjour(wpa_s
, resp
, srv_trans_id
);
1508 wpas_sd_all_upnp(wpa_s
, resp
, srv_trans_id
);
1512 switch (srv_proto
) {
1513 case P2P_SERV_ALL_SERVICES
:
1514 wpa_printf(MSG_DEBUG
, "P2P: Service Discovery Request "
1515 "for all services");
1516 if (dl_list_empty(&wpa_s
->global
->p2p_srv_upnp
) &&
1517 dl_list_empty(&wpa_s
->global
->p2p_srv_bonjour
)) {
1518 wpa_printf(MSG_DEBUG
, "P2P: No service "
1519 "discovery protocols available");
1520 wpas_sd_add_proto_not_avail(
1521 resp
, P2P_SERV_ALL_SERVICES
,
1525 wpas_sd_all_bonjour(wpa_s
, resp
, srv_trans_id
);
1526 wpas_sd_all_upnp(wpa_s
, resp
, srv_trans_id
);
1528 case P2P_SERV_BONJOUR
:
1529 wpas_sd_req_bonjour(wpa_s
, resp
, srv_trans_id
,
1530 pos
, tlv_end
- pos
);
1533 wpas_sd_req_upnp(wpa_s
, resp
, srv_trans_id
,
1534 pos
, tlv_end
- pos
);
1537 wpa_printf(MSG_DEBUG
, "P2P: Unavailable service "
1538 "protocol %u", srv_proto
);
1539 wpas_sd_add_proto_not_avail(resp
, srv_proto
,
1548 wpas_notify_p2p_sd_request(wpa_s
, freq
, sa
, dialog_token
,
1549 update_indic
, tlvs
, tlvs_len
);
1551 wpas_p2p_sd_response(wpa_s
, freq
, sa
, dialog_token
, resp
);
1557 void wpas_sd_response(void *ctx
, const u8
*sa
, u16 update_indic
,
1558 const u8
*tlvs
, size_t tlvs_len
)
1560 struct wpa_supplicant
*wpa_s
= ctx
;
1561 const u8
*pos
= tlvs
;
1562 const u8
*end
= tlvs
+ tlvs_len
;
1568 wpa_hexdump(MSG_MSGDUMP
, "P2P: Service Discovery Response TLVs",
1570 if (tlvs_len
> 1500) {
1571 /* TODO: better way for handling this */
1572 wpa_msg_ctrl(wpa_s
, MSG_INFO
,
1573 P2P_EVENT_SERV_DISC_RESP MACSTR
1574 " %u <long response: %u bytes>",
1575 MAC2STR(sa
), update_indic
,
1576 (unsigned int) tlvs_len
);
1578 buf_len
= 2 * tlvs_len
+ 1;
1579 buf
= os_malloc(buf_len
);
1581 wpa_snprintf_hex(buf
, buf_len
, tlvs
, tlvs_len
);
1582 wpa_msg_ctrl(wpa_s
, MSG_INFO
,
1583 P2P_EVENT_SERV_DISC_RESP MACSTR
" %u %s",
1584 MAC2STR(sa
), update_indic
, buf
);
1590 u8 srv_proto
, srv_trans_id
, status
;
1592 wpa_printf(MSG_DEBUG
, "P2P: Service Response TLV");
1593 slen
= WPA_GET_LE16(pos
);
1595 if (pos
+ slen
> end
|| slen
< 3) {
1596 wpa_printf(MSG_DEBUG
, "P2P: Unexpected Response Data "
1600 tlv_end
= pos
+ slen
;
1603 wpa_printf(MSG_DEBUG
, "P2P: Service Protocol Type %u",
1605 srv_trans_id
= *pos
++;
1606 wpa_printf(MSG_DEBUG
, "P2P: Service Transaction ID %u",
1609 wpa_printf(MSG_DEBUG
, "P2P: Status Code ID %u",
1612 wpa_hexdump(MSG_MSGDUMP
, "P2P: Response Data",
1613 pos
, tlv_end
- pos
);
1618 wpas_notify_p2p_sd_response(wpa_s
, sa
, update_indic
, tlvs
, tlvs_len
);
1622 u64
wpas_p2p_sd_request(struct wpa_supplicant
*wpa_s
, const u8
*dst
,
1623 const struct wpabuf
*tlvs
)
1625 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
)
1626 return wpa_drv_p2p_sd_request(wpa_s
, dst
, tlvs
);
1627 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
1629 return (uintptr_t) p2p_sd_request(wpa_s
->global
->p2p
, dst
, tlvs
);
1633 u64
wpas_p2p_sd_request_upnp(struct wpa_supplicant
*wpa_s
, const u8
*dst
,
1634 u8 version
, const char *query
)
1636 struct wpabuf
*tlvs
;
1639 tlvs
= wpabuf_alloc(2 + 1 + 1 + 1 + os_strlen(query
));
1642 wpabuf_put_le16(tlvs
, 1 + 1 + 1 + os_strlen(query
));
1643 wpabuf_put_u8(tlvs
, P2P_SERV_UPNP
); /* Service Protocol Type */
1644 wpabuf_put_u8(tlvs
, 1); /* Service Transaction ID */
1645 wpabuf_put_u8(tlvs
, version
);
1646 wpabuf_put_str(tlvs
, query
);
1647 ret
= wpas_p2p_sd_request(wpa_s
, dst
, tlvs
);
1653 int wpas_p2p_sd_cancel_request(struct wpa_supplicant
*wpa_s
, u64 req
)
1655 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
)
1656 return wpa_drv_p2p_sd_cancel_request(wpa_s
, req
);
1657 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
1659 return p2p_sd_cancel_request(wpa_s
->global
->p2p
,
1660 (void *) (uintptr_t) req
);
1664 void wpas_p2p_sd_response(struct wpa_supplicant
*wpa_s
, int freq
,
1665 const u8
*dst
, u8 dialog_token
,
1666 const struct wpabuf
*resp_tlvs
)
1668 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
) {
1669 wpa_drv_p2p_sd_response(wpa_s
, freq
, dst
, dialog_token
,
1673 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
1675 p2p_sd_response(wpa_s
->global
->p2p
, freq
, dst
, dialog_token
,
1680 void wpas_p2p_sd_service_update(struct wpa_supplicant
*wpa_s
)
1682 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
) {
1683 wpa_drv_p2p_service_update(wpa_s
);
1686 if (wpa_s
->global
->p2p
)
1687 p2p_sd_service_update(wpa_s
->global
->p2p
);
1691 static void wpas_p2p_srv_bonjour_free(struct p2p_srv_bonjour
*bsrv
)
1693 dl_list_del(&bsrv
->list
);
1694 wpabuf_free(bsrv
->query
);
1695 wpabuf_free(bsrv
->resp
);
1700 static void wpas_p2p_srv_upnp_free(struct p2p_srv_upnp
*usrv
)
1702 dl_list_del(&usrv
->list
);
1703 os_free(usrv
->service
);
1708 void wpas_p2p_service_flush(struct wpa_supplicant
*wpa_s
)
1710 struct p2p_srv_bonjour
*bsrv
, *bn
;
1711 struct p2p_srv_upnp
*usrv
, *un
;
1713 dl_list_for_each_safe(bsrv
, bn
, &wpa_s
->global
->p2p_srv_bonjour
,
1714 struct p2p_srv_bonjour
, list
)
1715 wpas_p2p_srv_bonjour_free(bsrv
);
1717 dl_list_for_each_safe(usrv
, un
, &wpa_s
->global
->p2p_srv_upnp
,
1718 struct p2p_srv_upnp
, list
)
1719 wpas_p2p_srv_upnp_free(usrv
);
1721 wpas_p2p_sd_service_update(wpa_s
);
1725 int wpas_p2p_service_add_bonjour(struct wpa_supplicant
*wpa_s
,
1726 struct wpabuf
*query
, struct wpabuf
*resp
)
1728 struct p2p_srv_bonjour
*bsrv
;
1730 bsrv
= wpas_p2p_service_get_bonjour(wpa_s
, query
);
1733 wpabuf_free(bsrv
->resp
);
1738 bsrv
= os_zalloc(sizeof(*bsrv
));
1741 bsrv
->query
= query
;
1743 dl_list_add(&wpa_s
->global
->p2p_srv_bonjour
, &bsrv
->list
);
1745 wpas_p2p_sd_service_update(wpa_s
);
1750 int wpas_p2p_service_del_bonjour(struct wpa_supplicant
*wpa_s
,
1751 const struct wpabuf
*query
)
1753 struct p2p_srv_bonjour
*bsrv
;
1755 bsrv
= wpas_p2p_service_get_bonjour(wpa_s
, query
);
1758 wpas_p2p_srv_bonjour_free(bsrv
);
1759 wpas_p2p_sd_service_update(wpa_s
);
1764 int wpas_p2p_service_add_upnp(struct wpa_supplicant
*wpa_s
, u8 version
,
1765 const char *service
)
1767 struct p2p_srv_upnp
*usrv
;
1769 if (wpas_p2p_service_get_upnp(wpa_s
, version
, service
))
1770 return 0; /* Already listed */
1771 usrv
= os_zalloc(sizeof(*usrv
));
1774 usrv
->version
= version
;
1775 usrv
->service
= os_strdup(service
);
1776 if (usrv
->service
== NULL
) {
1780 dl_list_add(&wpa_s
->global
->p2p_srv_upnp
, &usrv
->list
);
1782 wpas_p2p_sd_service_update(wpa_s
);
1787 int wpas_p2p_service_del_upnp(struct wpa_supplicant
*wpa_s
, u8 version
,
1788 const char *service
)
1790 struct p2p_srv_upnp
*usrv
;
1792 usrv
= wpas_p2p_service_get_upnp(wpa_s
, version
, service
);
1795 wpas_p2p_srv_upnp_free(usrv
);
1796 wpas_p2p_sd_service_update(wpa_s
);
1801 static void wpas_prov_disc_local_display(struct wpa_supplicant
*wpa_s
,
1802 const u8
*peer
, const char *params
,
1803 unsigned int generated_pin
)
1805 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_PROV_DISC_SHOW_PIN MACSTR
" %08d%s",
1806 MAC2STR(peer
), generated_pin
, params
);
1810 static void wpas_prov_disc_local_keypad(struct wpa_supplicant
*wpa_s
,
1811 const u8
*peer
, const char *params
)
1813 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_PROV_DISC_ENTER_PIN MACSTR
"%s",
1814 MAC2STR(peer
), params
);
1818 void wpas_prov_disc_req(void *ctx
, const u8
*peer
, u16 config_methods
,
1819 const u8
*dev_addr
, const u8
*pri_dev_type
,
1820 const char *dev_name
, u16 supp_config_methods
,
1821 u8 dev_capab
, u8 group_capab
, const u8
*group_id
,
1822 size_t group_id_len
)
1824 struct wpa_supplicant
*wpa_s
= ctx
;
1825 char devtype
[WPS_DEV_TYPE_BUFSIZE
];
1827 u8 empty_dev_type
[8];
1828 unsigned int generated_pin
= 0;
1829 struct wpa_supplicant
*group
= NULL
;
1832 for (group
= wpa_s
->global
->ifaces
; group
; group
= group
->next
)
1834 struct wpa_ssid
*s
= group
->current_ssid
;
1836 s
->mode
== WPAS_MODE_P2P_GO
&&
1837 group_id_len
- ETH_ALEN
== s
->ssid_len
&&
1838 os_memcmp(group_id
+ ETH_ALEN
, s
->ssid
,
1844 if (pri_dev_type
== NULL
) {
1845 os_memset(empty_dev_type
, 0, sizeof(empty_dev_type
));
1846 pri_dev_type
= empty_dev_type
;
1848 os_snprintf(params
, sizeof(params
), " p2p_dev_addr=" MACSTR
1849 " pri_dev_type=%s name='%s' config_methods=0x%x "
1850 "dev_capab=0x%x group_capab=0x%x%s%s",
1852 wps_dev_type_bin2str(pri_dev_type
, devtype
,
1854 dev_name
, supp_config_methods
, dev_capab
, group_capab
,
1855 group
? " group=" : "",
1856 group
? group
->ifname
: "");
1857 params
[sizeof(params
) - 1] = '\0';
1859 if (config_methods
& WPS_CONFIG_DISPLAY
) {
1860 generated_pin
= wps_generate_pin();
1861 wpas_prov_disc_local_display(wpa_s
, peer
, params
,
1863 } else if (config_methods
& WPS_CONFIG_KEYPAD
)
1864 wpas_prov_disc_local_keypad(wpa_s
, peer
, params
);
1865 else if (config_methods
& WPS_CONFIG_PUSHBUTTON
)
1866 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_PROV_DISC_PBC_REQ MACSTR
1867 "%s", MAC2STR(peer
), params
);
1869 wpas_notify_p2p_provision_discovery(wpa_s
, peer
, 1 /* request */,
1870 P2P_PROV_DISC_SUCCESS
,
1871 config_methods
, generated_pin
);
1875 void wpas_prov_disc_resp(void *ctx
, const u8
*peer
, u16 config_methods
)
1877 struct wpa_supplicant
*wpa_s
= ctx
;
1878 unsigned int generated_pin
= 0;
1881 if (wpa_s
->pending_pd_before_join
&&
1882 (os_memcmp(peer
, wpa_s
->pending_join_dev_addr
, ETH_ALEN
) == 0 ||
1883 os_memcmp(peer
, wpa_s
->pending_join_iface_addr
, ETH_ALEN
) == 0)) {
1884 wpa_s
->pending_pd_before_join
= 0;
1885 wpa_printf(MSG_DEBUG
, "P2P: Starting pending "
1886 "join-existing-group operation");
1887 wpas_p2p_join_start(wpa_s
);
1891 if (wpa_s
->pending_pd_use
== AUTO_PD_JOIN
||
1892 wpa_s
->pending_pd_use
== AUTO_PD_GO_NEG
)
1893 os_snprintf(params
, sizeof(params
), " peer_go=%d",
1894 wpa_s
->pending_pd_use
== AUTO_PD_JOIN
);
1898 if (config_methods
& WPS_CONFIG_DISPLAY
)
1899 wpas_prov_disc_local_keypad(wpa_s
, peer
, params
);
1900 else if (config_methods
& WPS_CONFIG_KEYPAD
) {
1901 generated_pin
= wps_generate_pin();
1902 wpas_prov_disc_local_display(wpa_s
, peer
, params
,
1904 } else if (config_methods
& WPS_CONFIG_PUSHBUTTON
)
1905 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_PROV_DISC_PBC_RESP MACSTR
1906 "%s", MAC2STR(peer
), params
);
1908 wpas_notify_p2p_provision_discovery(wpa_s
, peer
, 0 /* response */,
1909 P2P_PROV_DISC_SUCCESS
,
1910 config_methods
, generated_pin
);
1914 static void wpas_prov_disc_fail(void *ctx
, const u8
*peer
,
1915 enum p2p_prov_disc_status status
)
1917 struct wpa_supplicant
*wpa_s
= ctx
;
1919 if (wpa_s
->p2p_fallback_to_go_neg
) {
1920 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: PD for p2p_connect-auto "
1921 "failed - fall back to GO Negotiation");
1922 wpas_p2p_fallback_to_go_neg(wpa_s
, 0);
1926 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_PROV_DISC_FAILURE
1927 " p2p_dev_addr=" MACSTR
" status=%d",
1928 MAC2STR(peer
), status
);
1930 wpas_notify_p2p_provision_discovery(wpa_s
, peer
, 0 /* response */,
1935 static u8
wpas_invitation_process(void *ctx
, const u8
*sa
, const u8
*bssid
,
1936 const u8
*go_dev_addr
, const u8
*ssid
,
1937 size_t ssid_len
, int *go
, u8
*group_bssid
,
1938 int *force_freq
, int persistent_group
)
1940 struct wpa_supplicant
*wpa_s
= ctx
;
1942 u8 cur_bssid
[ETH_ALEN
];
1944 struct wpa_supplicant
*grp
;
1946 if (!persistent_group
) {
1947 wpa_printf(MSG_DEBUG
, "P2P: Invitation from " MACSTR
1948 " to join an active group", MAC2STR(sa
));
1949 if (!is_zero_ether_addr(wpa_s
->p2p_auth_invite
) &&
1950 (os_memcmp(go_dev_addr
, wpa_s
->p2p_auth_invite
, ETH_ALEN
)
1952 os_memcmp(sa
, wpa_s
->p2p_auth_invite
, ETH_ALEN
) == 0)) {
1953 wpa_printf(MSG_DEBUG
, "P2P: Accept previously "
1954 "authorized invitation");
1958 * Do not accept the invitation automatically; notify user and
1961 return P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE
;
1964 grp
= wpas_get_p2p_group(wpa_s
, ssid
, ssid_len
, go
);
1966 wpa_printf(MSG_DEBUG
, "P2P: Accept invitation to already "
1967 "running persistent group");
1969 os_memcpy(group_bssid
, grp
->own_addr
, ETH_ALEN
);
1973 if (!wpa_s
->conf
->persistent_reconnect
)
1974 return P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE
;
1976 for (s
= wpa_s
->conf
->ssid
; s
; s
= s
->next
) {
1977 if (s
->disabled
== 2 &&
1978 os_memcmp(s
->bssid
, go_dev_addr
, ETH_ALEN
) == 0 &&
1979 s
->ssid_len
== ssid_len
&&
1980 os_memcmp(ssid
, s
->ssid
, ssid_len
) == 0)
1985 wpa_printf(MSG_DEBUG
, "P2P: Invitation from " MACSTR
1986 " requested reinvocation of an unknown group",
1988 return P2P_SC_FAIL_UNKNOWN_GROUP
;
1991 if (s
->mode
== WPAS_MODE_P2P_GO
&& !wpas_p2p_create_iface(wpa_s
)) {
1993 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
1994 wpa_printf(MSG_DEBUG
, "P2P: The only available "
1995 "interface is already in use - reject "
1997 return P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE
;
1999 os_memcpy(group_bssid
, wpa_s
->own_addr
, ETH_ALEN
);
2000 } else if (s
->mode
== WPAS_MODE_P2P_GO
) {
2002 if (wpas_p2p_add_group_interface(wpa_s
, WPA_IF_P2P_GO
) < 0)
2004 wpa_printf(MSG_ERROR
, "P2P: Failed to allocate a new "
2005 "interface address for the group");
2006 return P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE
;
2008 os_memcpy(group_bssid
, wpa_s
->pending_interface_addr
,
2013 if (wpa_s
->current_ssid
&& wpa_drv_get_bssid(wpa_s
, cur_bssid
) == 0 &&
2014 wpa_s
->assoc_freq
) {
2015 wpa_printf(MSG_DEBUG
, "P2P: Trying to force channel to match "
2016 "the channel we are already using");
2017 *force_freq
= wpa_s
->assoc_freq
;
2020 res
= wpa_drv_shared_freq(wpa_s
);
2022 wpa_printf(MSG_DEBUG
, "P2P: Trying to force channel to match "
2023 "with the channel we are already using on a "
2024 "shared interface");
2028 return P2P_SC_SUCCESS
;
2032 static void wpas_invitation_received(void *ctx
, const u8
*sa
, const u8
*bssid
,
2033 const u8
*ssid
, size_t ssid_len
,
2034 const u8
*go_dev_addr
, u8 status
,
2037 struct wpa_supplicant
*wpa_s
= ctx
;
2040 for (s
= wpa_s
->conf
->ssid
; s
; s
= s
->next
) {
2041 if (s
->disabled
== 2 &&
2042 s
->ssid_len
== ssid_len
&&
2043 os_memcmp(ssid
, s
->ssid
, ssid_len
) == 0)
2047 if (status
== P2P_SC_SUCCESS
) {
2048 wpa_printf(MSG_DEBUG
, "P2P: Invitation from peer " MACSTR
2049 " was accepted; op_freq=%d MHz",
2050 MAC2STR(sa
), op_freq
);
2052 wpas_p2p_group_add_persistent(
2053 wpa_s
, s
, s
->mode
== WPAS_MODE_P2P_GO
, 0, 0);
2055 wpas_p2p_join(wpa_s
, bssid
, go_dev_addr
,
2056 wpa_s
->p2p_wps_method
, 0);
2061 if (status
!= P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE
) {
2062 wpa_printf(MSG_DEBUG
, "P2P: Invitation from peer " MACSTR
2063 " was rejected (status %u)", MAC2STR(sa
), status
);
2069 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_INVITATION_RECEIVED
2070 "sa=" MACSTR
" go_dev_addr=" MACSTR
2071 " bssid=" MACSTR
" unknown-network",
2072 MAC2STR(sa
), MAC2STR(go_dev_addr
),
2075 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_INVITATION_RECEIVED
2076 "sa=" MACSTR
" go_dev_addr=" MACSTR
2078 MAC2STR(sa
), MAC2STR(go_dev_addr
));
2083 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_INVITATION_RECEIVED
"sa=" MACSTR
2084 " persistent=%d", MAC2STR(sa
), s
->id
);
2088 static void wpas_invitation_result(void *ctx
, int status
, const u8
*bssid
)
2090 struct wpa_supplicant
*wpa_s
= ctx
;
2091 struct wpa_ssid
*ssid
;
2094 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_INVITATION_RESULT
2095 "status=%d " MACSTR
,
2096 status
, MAC2STR(bssid
));
2098 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_INVITATION_RESULT
2099 "status=%d ", status
);
2101 wpas_notify_p2p_invitation_result(wpa_s
, status
, bssid
);
2103 if (wpa_s
->pending_invite_ssid_id
== -1)
2104 return; /* Invitation to active group */
2106 if (status
!= P2P_SC_SUCCESS
) {
2107 wpas_p2p_remove_pending_group_interface(wpa_s
);
2111 ssid
= wpa_config_get_network(wpa_s
->conf
,
2112 wpa_s
->pending_invite_ssid_id
);
2114 wpa_printf(MSG_ERROR
, "P2P: Could not find persistent group "
2115 "data matching with invitation");
2119 wpas_p2p_group_add_persistent(wpa_s
, ssid
,
2120 ssid
->mode
== WPAS_MODE_P2P_GO
, 0, 0);
2124 static int wpas_p2p_disallowed_freq(struct wpa_global
*global
,
2129 if (global
->p2p_disallow_freq
== NULL
)
2132 for (i
= 0; i
< global
->num_p2p_disallow_freq
; i
++) {
2133 if (freq
>= global
->p2p_disallow_freq
[i
].min
&&
2134 freq
<= global
->p2p_disallow_freq
[i
].max
)
2142 static void wpas_p2p_add_chan(struct p2p_reg_class
*reg
, u8 chan
)
2144 reg
->channel
[reg
->channels
] = chan
;
2149 static int wpas_p2p_default_channels(struct wpa_supplicant
*wpa_s
,
2150 struct p2p_channels
*chan
)
2154 wpa_printf(MSG_DEBUG
, "P2P: Enable operating classes for 2.4 GHz "
2157 /* Operating class 81 - 2.4 GHz band channels 1..13 */
2158 chan
->reg_class
[cla
].reg_class
= 81;
2159 chan
->reg_class
[cla
].channels
= 0;
2160 for (i
= 0; i
< 11; i
++) {
2161 if (!wpas_p2p_disallowed_freq(wpa_s
->global
, 2412 + i
* 5))
2162 wpas_p2p_add_chan(&chan
->reg_class
[cla
], i
+ 1);
2164 if (chan
->reg_class
[cla
].channels
)
2167 wpa_printf(MSG_DEBUG
, "P2P: Enable operating classes for lower 5 GHz "
2170 /* Operating class 115 - 5 GHz, channels 36-48 */
2171 chan
->reg_class
[cla
].reg_class
= 115;
2172 chan
->reg_class
[cla
].channels
= 0;
2173 if (!wpas_p2p_disallowed_freq(wpa_s
->global
, 5000 + 36 * 5))
2174 wpas_p2p_add_chan(&chan
->reg_class
[cla
], 36);
2175 if (!wpas_p2p_disallowed_freq(wpa_s
->global
, 5000 + 40 * 5))
2176 wpas_p2p_add_chan(&chan
->reg_class
[cla
], 40);
2177 if (!wpas_p2p_disallowed_freq(wpa_s
->global
, 5000 + 44 * 5))
2178 wpas_p2p_add_chan(&chan
->reg_class
[cla
], 44);
2179 if (!wpas_p2p_disallowed_freq(wpa_s
->global
, 5000 + 48 * 5))
2180 wpas_p2p_add_chan(&chan
->reg_class
[cla
], 48);
2181 if (chan
->reg_class
[cla
].channels
)
2184 wpa_printf(MSG_DEBUG
, "P2P: Enable operating classes for higher 5 GHz "
2187 /* Operating class 124 - 5 GHz, channels 149,153,157,161 */
2188 chan
->reg_class
[cla
].reg_class
= 124;
2189 chan
->reg_class
[cla
].channels
= 0;
2190 if (!wpas_p2p_disallowed_freq(wpa_s
->global
, 5000 + 149 * 5))
2191 wpas_p2p_add_chan(&chan
->reg_class
[cla
], 149);
2192 if (!wpas_p2p_disallowed_freq(wpa_s
->global
, 5000 + 153 * 5))
2193 wpas_p2p_add_chan(&chan
->reg_class
[cla
], 153);
2194 if (!wpas_p2p_disallowed_freq(wpa_s
->global
, 5000 + 156 * 5))
2195 wpas_p2p_add_chan(&chan
->reg_class
[cla
], 157);
2196 if (!wpas_p2p_disallowed_freq(wpa_s
->global
, 5000 + 161 * 5))
2197 wpas_p2p_add_chan(&chan
->reg_class
[cla
], 161);
2198 if (chan
->reg_class
[cla
].channels
)
2201 chan
->reg_classes
= cla
;
2206 static struct hostapd_hw_modes
* get_mode(struct hostapd_hw_modes
*modes
,
2208 enum hostapd_hw_mode mode
)
2212 for (i
= 0; i
< num_modes
; i
++) {
2213 if (modes
[i
].mode
== mode
)
2221 static int has_channel(struct wpa_global
*global
,
2222 struct hostapd_hw_modes
*mode
, u8 chan
, int *flags
)
2227 freq
= (mode
->mode
== HOSTAPD_MODE_IEEE80211A
? 5000 : 2407) +
2229 if (wpas_p2p_disallowed_freq(global
, freq
))
2232 for (i
= 0; i
< mode
->num_channels
; i
++) {
2233 if (mode
->channels
[i
].chan
== chan
) {
2235 *flags
= mode
->channels
[i
].flag
;
2236 return !(mode
->channels
[i
].flag
&
2237 (HOSTAPD_CHAN_DISABLED
|
2238 HOSTAPD_CHAN_PASSIVE_SCAN
|
2239 HOSTAPD_CHAN_NO_IBSS
|
2240 HOSTAPD_CHAN_RADAR
));
2248 struct p2p_oper_class_map
{
2249 enum hostapd_hw_mode mode
;
2254 enum { BW20
, BW40PLUS
, BW40MINUS
} bw
;
2257 static struct p2p_oper_class_map op_class
[] = {
2258 { HOSTAPD_MODE_IEEE80211G
, 81, 1, 13, 1, BW20
},
2259 { HOSTAPD_MODE_IEEE80211G
, 82, 14, 14, 1, BW20
},
2260 #if 0 /* Do not enable HT40 on 2 GHz for now */
2261 { HOSTAPD_MODE_IEEE80211G
, 83, 1, 9, 1, BW40PLUS
},
2262 { HOSTAPD_MODE_IEEE80211G
, 84, 5, 13, 1, BW40MINUS
},
2264 { HOSTAPD_MODE_IEEE80211A
, 115, 36, 48, 4, BW20
},
2265 { HOSTAPD_MODE_IEEE80211A
, 124, 149, 161, 4, BW20
},
2266 { HOSTAPD_MODE_IEEE80211A
, 116, 36, 44, 8, BW40PLUS
},
2267 { HOSTAPD_MODE_IEEE80211A
, 117, 40, 48, 8, BW40MINUS
},
2268 { HOSTAPD_MODE_IEEE80211A
, 126, 149, 157, 8, BW40PLUS
},
2269 { HOSTAPD_MODE_IEEE80211A
, 127, 153, 161, 8, BW40MINUS
},
2270 { -1, 0, 0, 0, 0, BW20
}
2274 static int wpas_p2p_verify_channel(struct wpa_supplicant
*wpa_s
,
2275 struct hostapd_hw_modes
*mode
,
2280 if (!has_channel(wpa_s
->global
, mode
, channel
, &flag
))
2282 if (bw
== BW40MINUS
&&
2283 (!(flag
& HOSTAPD_CHAN_HT40MINUS
) ||
2284 !has_channel(wpa_s
->global
, mode
, channel
- 4, NULL
)))
2286 if (bw
== BW40PLUS
&&
2287 (!(flag
& HOSTAPD_CHAN_HT40PLUS
) ||
2288 !has_channel(wpa_s
->global
, mode
, channel
+ 4, NULL
)))
2294 static int wpas_p2p_setup_channels(struct wpa_supplicant
*wpa_s
,
2295 struct p2p_channels
*chan
)
2297 struct hostapd_hw_modes
*mode
;
2300 if (wpa_s
->hw
.modes
== NULL
) {
2301 wpa_printf(MSG_DEBUG
, "P2P: Driver did not support fetching "
2302 "of all supported channels; assume dualband "
2304 return wpas_p2p_default_channels(wpa_s
, chan
);
2309 for (op
= 0; op_class
[op
].op_class
; op
++) {
2310 struct p2p_oper_class_map
*o
= &op_class
[op
];
2312 struct p2p_reg_class
*reg
= NULL
;
2314 mode
= get_mode(wpa_s
->hw
.modes
, wpa_s
->hw
.num_modes
, o
->mode
);
2317 for (ch
= o
->min_chan
; ch
<= o
->max_chan
; ch
+= o
->inc
) {
2318 if (wpas_p2p_verify_channel(wpa_s
, mode
, ch
, o
->bw
) < 1)
2321 wpa_printf(MSG_DEBUG
, "P2P: Add operating "
2322 "class %u", o
->op_class
);
2323 reg
= &chan
->reg_class
[cla
];
2325 reg
->reg_class
= o
->op_class
;
2327 reg
->channel
[reg
->channels
] = ch
;
2331 wpa_hexdump(MSG_DEBUG
, "P2P: Channels",
2332 reg
->channel
, reg
->channels
);
2336 chan
->reg_classes
= cla
;
2342 int wpas_p2p_get_ht40_mode(struct wpa_supplicant
*wpa_s
,
2343 struct hostapd_hw_modes
*mode
, u8 channel
)
2347 for (op
= 0; op_class
[op
].op_class
; op
++) {
2348 struct p2p_oper_class_map
*o
= &op_class
[op
];
2351 for (ch
= o
->min_chan
; ch
<= o
->max_chan
; ch
+= o
->inc
) {
2352 if (o
->mode
!= HOSTAPD_MODE_IEEE80211A
||
2353 o
->bw
== BW20
|| ch
!= channel
)
2355 ret
= wpas_p2p_verify_channel(wpa_s
, mode
, ch
, o
->bw
);
2359 return (o
->bw
== BW40MINUS
) ? -1 : 1;
2368 static int wpas_get_noa(void *ctx
, const u8
*interface_addr
, u8
*buf
,
2371 struct wpa_supplicant
*wpa_s
= ctx
;
2373 for (wpa_s
= wpa_s
->global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
2374 if (os_memcmp(wpa_s
->own_addr
, interface_addr
, ETH_ALEN
) == 0)
2380 return wpa_drv_get_noa(wpa_s
, buf
, buf_len
);
2384 static int wpas_go_connected(void *ctx
, const u8
*dev_addr
)
2386 struct wpa_supplicant
*wpa_s
= ctx
;
2388 for (wpa_s
= wpa_s
->global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
2389 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
2392 if (ssid
->mode
!= WPAS_MODE_INFRA
)
2394 if (wpa_s
->wpa_state
!= WPA_COMPLETED
&&
2395 wpa_s
->wpa_state
!= WPA_GROUP_HANDSHAKE
)
2397 if (os_memcmp(wpa_s
->go_dev_addr
, dev_addr
, ETH_ALEN
) == 0)
2406 * wpas_p2p_init - Initialize P2P module for %wpa_supplicant
2407 * @global: Pointer to global data from wpa_supplicant_init()
2408 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
2409 * Returns: 0 on success, -1 on failure
2411 int wpas_p2p_init(struct wpa_global
*global
, struct wpa_supplicant
*wpa_s
)
2413 struct p2p_config p2p
;
2417 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_CAPABLE
))
2423 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
) {
2424 struct p2p_params params
;
2426 wpa_printf(MSG_DEBUG
, "P2P: Use driver-based P2P management");
2427 os_memset(¶ms
, 0, sizeof(params
));
2428 params
.dev_name
= wpa_s
->conf
->device_name
;
2429 os_memcpy(params
.pri_dev_type
, wpa_s
->conf
->device_type
,
2431 params
.num_sec_dev_types
= wpa_s
->conf
->num_sec_device_types
;
2432 os_memcpy(params
.sec_dev_type
,
2433 wpa_s
->conf
->sec_device_type
,
2434 params
.num_sec_dev_types
* WPS_DEV_TYPE_LEN
);
2436 if (wpa_drv_p2p_set_params(wpa_s
, ¶ms
) < 0)
2442 os_memset(&p2p
, 0, sizeof(p2p
));
2443 p2p
.msg_ctx
= wpa_s
;
2445 p2p
.p2p_scan
= wpas_p2p_scan
;
2446 p2p
.send_action
= wpas_send_action
;
2447 p2p
.send_action_done
= wpas_send_action_done
;
2448 p2p
.go_neg_completed
= wpas_go_neg_completed
;
2449 p2p
.go_neg_req_rx
= wpas_go_neg_req_rx
;
2450 p2p
.dev_found
= wpas_dev_found
;
2451 p2p
.dev_lost
= wpas_dev_lost
;
2452 p2p
.start_listen
= wpas_start_listen
;
2453 p2p
.stop_listen
= wpas_stop_listen
;
2454 p2p
.send_probe_resp
= wpas_send_probe_resp
;
2455 p2p
.sd_request
= wpas_sd_request
;
2456 p2p
.sd_response
= wpas_sd_response
;
2457 p2p
.prov_disc_req
= wpas_prov_disc_req
;
2458 p2p
.prov_disc_resp
= wpas_prov_disc_resp
;
2459 p2p
.prov_disc_fail
= wpas_prov_disc_fail
;
2460 p2p
.invitation_process
= wpas_invitation_process
;
2461 p2p
.invitation_received
= wpas_invitation_received
;
2462 p2p
.invitation_result
= wpas_invitation_result
;
2463 p2p
.get_noa
= wpas_get_noa
;
2464 p2p
.go_connected
= wpas_go_connected
;
2466 os_memcpy(wpa_s
->global
->p2p_dev_addr
, wpa_s
->own_addr
, ETH_ALEN
);
2467 os_memcpy(p2p
.dev_addr
, wpa_s
->global
->p2p_dev_addr
, ETH_ALEN
);
2468 p2p
.dev_name
= wpa_s
->conf
->device_name
;
2469 p2p
.manufacturer
= wpa_s
->conf
->manufacturer
;
2470 p2p
.model_name
= wpa_s
->conf
->model_name
;
2471 p2p
.model_number
= wpa_s
->conf
->model_number
;
2472 p2p
.serial_number
= wpa_s
->conf
->serial_number
;
2474 os_memcpy(p2p
.uuid
, wpa_s
->wps
->uuid
, 16);
2475 p2p
.config_methods
= wpa_s
->wps
->config_methods
;
2478 if (wpa_s
->conf
->p2p_listen_reg_class
&&
2479 wpa_s
->conf
->p2p_listen_channel
) {
2480 p2p
.reg_class
= wpa_s
->conf
->p2p_listen_reg_class
;
2481 p2p
.channel
= wpa_s
->conf
->p2p_listen_channel
;
2485 * Pick one of the social channels randomly as the listen
2488 os_get_random((u8
*) &r
, sizeof(r
));
2489 p2p
.channel
= 1 + (r
% 3) * 5;
2491 wpa_printf(MSG_DEBUG
, "P2P: Own listen channel: %d", p2p
.channel
);
2493 if (wpa_s
->conf
->p2p_oper_reg_class
&&
2494 wpa_s
->conf
->p2p_oper_channel
) {
2495 p2p
.op_reg_class
= wpa_s
->conf
->p2p_oper_reg_class
;
2496 p2p
.op_channel
= wpa_s
->conf
->p2p_oper_channel
;
2497 p2p
.cfg_op_channel
= 1;
2498 wpa_printf(MSG_DEBUG
, "P2P: Configured operating channel: "
2499 "%d:%d", p2p
.op_reg_class
, p2p
.op_channel
);
2502 p2p
.op_reg_class
= 81;
2504 * Use random operation channel from (1, 6, 11) if no other
2505 * preference is indicated.
2507 os_get_random((u8
*) &r
, sizeof(r
));
2508 p2p
.op_channel
= 1 + (r
% 3) * 5;
2509 p2p
.cfg_op_channel
= 0;
2510 wpa_printf(MSG_DEBUG
, "P2P: Random operating channel: "
2511 "%d:%d", p2p
.op_reg_class
, p2p
.op_channel
);
2513 if (wpa_s
->conf
->country
[0] && wpa_s
->conf
->country
[1]) {
2514 os_memcpy(p2p
.country
, wpa_s
->conf
->country
, 2);
2515 p2p
.country
[2] = 0x04;
2517 os_memcpy(p2p
.country
, "XX\x04", 3);
2519 if (wpas_p2p_setup_channels(wpa_s
, &p2p
.channels
)) {
2520 wpa_printf(MSG_ERROR
, "P2P: Failed to configure supported "
2525 os_memcpy(p2p
.pri_dev_type
, wpa_s
->conf
->device_type
,
2528 p2p
.num_sec_dev_types
= wpa_s
->conf
->num_sec_device_types
;
2529 os_memcpy(p2p
.sec_dev_type
, wpa_s
->conf
->sec_device_type
,
2530 p2p
.num_sec_dev_types
* WPS_DEV_TYPE_LEN
);
2532 p2p
.concurrent_operations
= !!(wpa_s
->drv_flags
&
2533 WPA_DRIVER_FLAGS_P2P_CONCURRENT
);
2535 p2p
.max_peers
= 100;
2537 if (wpa_s
->conf
->p2p_ssid_postfix
) {
2538 p2p
.ssid_postfix_len
=
2539 os_strlen(wpa_s
->conf
->p2p_ssid_postfix
);
2540 if (p2p
.ssid_postfix_len
> sizeof(p2p
.ssid_postfix
))
2541 p2p
.ssid_postfix_len
= sizeof(p2p
.ssid_postfix
);
2542 os_memcpy(p2p
.ssid_postfix
, wpa_s
->conf
->p2p_ssid_postfix
,
2543 p2p
.ssid_postfix_len
);
2546 p2p
.p2p_intra_bss
= wpa_s
->conf
->p2p_intra_bss
;
2548 global
->p2p
= p2p_init(&p2p
);
2549 if (global
->p2p
== NULL
)
2551 global
->p2p_init_wpa_s
= wpa_s
;
2553 for (i
= 0; i
< MAX_WPS_VENDOR_EXT
; i
++) {
2554 if (wpa_s
->conf
->wps_vendor_ext
[i
] == NULL
)
2556 p2p_add_wps_vendor_extension(
2557 global
->p2p
, wpa_s
->conf
->wps_vendor_ext
[i
]);
2565 * wpas_p2p_deinit - Deinitialize per-interface P2P data
2566 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
2568 * This function deinitialize per-interface P2P data.
2570 void wpas_p2p_deinit(struct wpa_supplicant
*wpa_s
)
2572 if (wpa_s
->driver
&& wpa_s
->drv_priv
)
2573 wpa_drv_probe_req_report(wpa_s
, 0);
2575 if (wpa_s
->go_params
) {
2576 /* Clear any stored provisioning info */
2577 p2p_clear_provisioning_info(
2579 wpa_s
->go_params
->peer_device_addr
);
2582 os_free(wpa_s
->go_params
);
2583 wpa_s
->go_params
= NULL
;
2584 eloop_cancel_timeout(wpas_p2p_group_formation_timeout
, wpa_s
, NULL
);
2585 eloop_cancel_timeout(wpas_p2p_join_scan
, wpa_s
, NULL
);
2586 eloop_cancel_timeout(wpas_p2p_pd_before_join_timeout
, wpa_s
, NULL
);
2587 wpa_s
->p2p_long_listen
= 0;
2588 eloop_cancel_timeout(wpas_p2p_long_listen_timeout
, wpa_s
, NULL
);
2589 eloop_cancel_timeout(wpas_p2p_group_idle_timeout
, wpa_s
, NULL
);
2590 wpas_p2p_remove_pending_group_interface(wpa_s
);
2592 /* TODO: remove group interface from the driver if this wpa_s instance
2593 * is on top of a P2P group interface */
2598 * wpas_p2p_deinit_global - Deinitialize global P2P module
2599 * @global: Pointer to global data from wpa_supplicant_init()
2601 * This function deinitializes the global (per device) P2P module.
2603 void wpas_p2p_deinit_global(struct wpa_global
*global
)
2605 struct wpa_supplicant
*wpa_s
, *tmp
;
2607 if (global
->p2p
== NULL
)
2610 /* Remove remaining P2P group interfaces */
2611 wpa_s
= global
->ifaces
;
2613 wpas_p2p_service_flush(wpa_s
);
2614 while (wpa_s
&& wpa_s
->p2p_group_interface
!= NOT_P2P_GROUP_INTERFACE
)
2615 wpa_s
= wpa_s
->next
;
2617 tmp
= global
->ifaces
;
2620 tmp
->p2p_group_interface
== NOT_P2P_GROUP_INTERFACE
)) {
2625 /* Disconnect from the P2P group and deinit the interface */
2626 wpas_p2p_disconnect(tmp
);
2630 * Deinit GO data on any possibly remaining interface (if main
2631 * interface is used as GO).
2633 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
2634 if (wpa_s
->ap_iface
)
2635 wpas_p2p_group_deinit(wpa_s
);
2638 p2p_deinit(global
->p2p
);
2640 global
->p2p_init_wpa_s
= NULL
;
2644 static int wpas_p2p_create_iface(struct wpa_supplicant
*wpa_s
)
2646 if (wpa_s
->drv_flags
&
2647 (WPA_DRIVER_FLAGS_P2P_DEDICATED_INTERFACE
|
2648 WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P
))
2649 return 1; /* P2P group requires a new interface in every case
2651 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_CONCURRENT
))
2652 return 0; /* driver does not support concurrent operations */
2653 if (wpa_s
->global
->ifaces
->next
)
2654 return 1; /* more that one interface already in use */
2655 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
)
2656 return 1; /* this interface is already in use */
2661 static int wpas_p2p_start_go_neg(struct wpa_supplicant
*wpa_s
,
2662 const u8
*peer_addr
,
2663 enum p2p_wps_method wps_method
,
2664 int go_intent
, const u8
*own_interface_addr
,
2665 unsigned int force_freq
, int persistent_group
,
2666 struct wpa_ssid
*ssid
)
2668 if (persistent_group
&& wpa_s
->conf
->persistent_reconnect
)
2669 persistent_group
= 2;
2671 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
) {
2672 return wpa_drv_p2p_connect(wpa_s
, peer_addr
, wps_method
,
2673 go_intent
, own_interface_addr
,
2674 force_freq
, persistent_group
);
2678 * Increase GO config timeout if HT40 is used since it takes some time
2679 * to scan channels for coex purposes before the BSS can be started.
2681 p2p_set_config_timeout(wpa_s
->global
->p2p
,
2682 wpa_s
->p2p_go_ht40
? 255 : 100, 20);
2684 return p2p_connect(wpa_s
->global
->p2p
, peer_addr
, wps_method
,
2685 go_intent
, own_interface_addr
, force_freq
,
2686 persistent_group
, ssid
? ssid
->ssid
: NULL
,
2687 ssid
? ssid
->ssid_len
: 0,
2688 wpa_s
->p2p_pd_before_go_neg
);
2692 static int wpas_p2p_auth_go_neg(struct wpa_supplicant
*wpa_s
,
2693 const u8
*peer_addr
,
2694 enum p2p_wps_method wps_method
,
2695 int go_intent
, const u8
*own_interface_addr
,
2696 unsigned int force_freq
, int persistent_group
,
2697 struct wpa_ssid
*ssid
)
2699 if (persistent_group
&& wpa_s
->conf
->persistent_reconnect
)
2700 persistent_group
= 2;
2702 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
)
2705 return p2p_authorize(wpa_s
->global
->p2p
, peer_addr
, wps_method
,
2706 go_intent
, own_interface_addr
, force_freq
,
2707 persistent_group
, ssid
? ssid
->ssid
: NULL
,
2708 ssid
? ssid
->ssid_len
: 0);
2712 static void wpas_p2p_check_join_scan_limit(struct wpa_supplicant
*wpa_s
)
2714 wpa_s
->p2p_join_scan_count
++;
2715 wpa_printf(MSG_DEBUG
, "P2P: Join scan attempt %d",
2716 wpa_s
->p2p_join_scan_count
);
2717 if (wpa_s
->p2p_join_scan_count
> P2P_MAX_JOIN_SCAN_ATTEMPTS
) {
2718 wpa_printf(MSG_DEBUG
, "P2P: Failed to find GO " MACSTR
2719 " for join operationg - stop join attempt",
2720 MAC2STR(wpa_s
->pending_join_iface_addr
));
2721 eloop_cancel_timeout(wpas_p2p_join_scan
, wpa_s
, NULL
);
2722 if (wpa_s
->p2p_auto_pd
) {
2723 wpa_s
->p2p_auto_pd
= 0;
2724 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_PROV_DISC_FAILURE
2725 " p2p_dev_addr=" MACSTR
" status=N/A",
2726 MAC2STR(wpa_s
->pending_join_dev_addr
));
2729 wpa_msg(wpa_s
->parent
, MSG_INFO
,
2730 P2P_EVENT_GROUP_FORMATION_FAILURE
);
2735 static void wpas_p2p_pd_before_join_timeout(void *eloop_ctx
, void *timeout_ctx
)
2737 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
2738 if (!wpa_s
->pending_pd_before_join
)
2741 * Provision Discovery Response may have been lost - try to connect
2742 * anyway since we do not need any information from this PD.
2744 wpa_printf(MSG_DEBUG
, "P2P: PD timeout for join-existing-group - "
2745 "try to connect anyway");
2746 wpas_p2p_join_start(wpa_s
);
2750 static int wpas_check_freq_conflict(struct wpa_supplicant
*wpa_s
, int freq
)
2752 struct wpa_supplicant
*iface
;
2756 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_MULTI_CHANNEL_CONCURRENT
)
2759 for (iface
= wpa_s
->global
->ifaces
; iface
; iface
= iface
->next
) {
2760 if (!wpas_p2p_create_iface(wpa_s
) && iface
== wpa_s
)
2762 if (iface
->current_ssid
== NULL
|| iface
->assoc_freq
== 0)
2764 if (iface
->current_ssid
->mode
== WPAS_MODE_AP
||
2765 iface
->current_ssid
->mode
== WPAS_MODE_P2P_GO
)
2766 shared_freq
= iface
->current_ssid
->frequency
;
2767 else if (wpa_drv_get_bssid(iface
, bssid
) == 0)
2768 shared_freq
= iface
->assoc_freq
;
2772 if (shared_freq
&& freq
!= shared_freq
) {
2773 wpa_printf(MSG_DEBUG
, "P2P: Frequency conflict - %s "
2774 "connected on %d MHz - new connection on "
2775 "%d MHz", iface
->ifname
, shared_freq
, freq
);
2780 shared_freq
= wpa_drv_shared_freq(wpa_s
);
2781 if (shared_freq
> 0 && shared_freq
!= freq
) {
2782 wpa_printf(MSG_DEBUG
, "P2P: Frequency conflict - shared "
2783 "virtual interface connected on %d MHz - new "
2784 "connection on %d MHz", shared_freq
, freq
);
2792 static int wpas_p2p_peer_go(struct wpa_supplicant
*wpa_s
,
2793 const u8
*peer_dev_addr
)
2795 struct wpa_bss
*bss
;
2798 bss
= wpa_bss_get_p2p_dev_addr(wpa_s
, peer_dev_addr
);
2801 if (bss
->last_update_idx
< wpa_s
->bss_update_idx
) {
2802 wpa_printf(MSG_DEBUG
, "P2P: Peer BSS entry not updated in the "
2807 updated
= os_time_before(&wpa_s
->p2p_auto_started
, &bss
->last_update
);
2808 wpa_printf(MSG_DEBUG
, "P2P: Current BSS entry for peer updated at "
2809 "%ld.%06ld (%supdated in last scan)",
2810 bss
->last_update
.sec
, bss
->last_update
.usec
,
2811 updated
? "": "not ");
2817 static void wpas_p2p_scan_res_join(struct wpa_supplicant
*wpa_s
,
2818 struct wpa_scan_results
*scan_res
)
2820 struct wpa_bss
*bss
;
2822 u8 iface_addr
[ETH_ALEN
];
2824 eloop_cancel_timeout(wpas_p2p_join_scan
, wpa_s
, NULL
);
2826 if (wpa_s
->global
->p2p_disabled
)
2829 wpa_printf(MSG_DEBUG
, "P2P: Scan results received (%d BSS) for %sjoin",
2830 scan_res
? (int) scan_res
->num
: -1,
2831 wpa_s
->p2p_auto_join
? "auto_" : "");
2834 wpas_p2p_scan_res_handler(wpa_s
, scan_res
);
2836 if (wpa_s
->p2p_auto_pd
) {
2837 int join
= wpas_p2p_peer_go(wpa_s
,
2838 wpa_s
->pending_join_dev_addr
);
2840 wpa_s
->auto_pd_scan_retry
< P2P_AUTO_PD_SCAN_ATTEMPTS
) {
2841 wpa_s
->auto_pd_scan_retry
++;
2842 bss
= wpa_bss_get_bssid(wpa_s
,
2843 wpa_s
->pending_join_dev_addr
);
2846 wpa_printf(MSG_DEBUG
, "P2P: Scan retry %d for "
2847 "the peer " MACSTR
" at %d MHz",
2848 wpa_s
->auto_pd_scan_retry
,
2850 pending_join_dev_addr
),
2852 wpas_p2p_join_scan_req(wpa_s
, freq
);
2860 wpa_s
->p2p_auto_pd
= 0;
2861 wpa_s
->pending_pd_use
= join
? AUTO_PD_JOIN
: AUTO_PD_GO_NEG
;
2862 wpa_printf(MSG_DEBUG
, "P2P: Auto PD with " MACSTR
" join=%d",
2863 MAC2STR(wpa_s
->pending_join_dev_addr
), join
);
2864 if (p2p_prov_disc_req(wpa_s
->global
->p2p
,
2865 wpa_s
->pending_join_dev_addr
,
2866 wpa_s
->pending_pd_config_methods
, join
,
2868 wpa_s
->p2p_auto_pd
= 0;
2869 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_PROV_DISC_FAILURE
2870 " p2p_dev_addr=" MACSTR
" status=N/A",
2871 MAC2STR(wpa_s
->pending_join_dev_addr
));
2876 if (wpa_s
->p2p_auto_join
) {
2877 int join
= wpas_p2p_peer_go(wpa_s
,
2878 wpa_s
->pending_join_dev_addr
);
2880 wpa_printf(MSG_DEBUG
, "P2P: Peer was not found to be "
2881 "running a GO -> use GO Negotiation");
2882 wpas_p2p_connect(wpa_s
, wpa_s
->pending_join_dev_addr
,
2883 wpa_s
->p2p_pin
, wpa_s
->p2p_wps_method
,
2884 wpa_s
->p2p_persistent_group
, 0, 0, 0,
2885 wpa_s
->p2p_go_intent
,
2886 wpa_s
->p2p_connect_freq
,
2887 wpa_s
->p2p_persistent_id
,
2888 wpa_s
->p2p_pd_before_go_neg
,
2889 wpa_s
->p2p_go_ht40
);
2893 wpa_printf(MSG_DEBUG
, "P2P: Peer was found running GO%s -> "
2894 "try to join the group", join
? "" :
2897 wpa_s
->p2p_fallback_to_go_neg
= 1;
2900 freq
= p2p_get_oper_freq(wpa_s
->global
->p2p
,
2901 wpa_s
->pending_join_iface_addr
);
2903 p2p_get_interface_addr(wpa_s
->global
->p2p
,
2904 wpa_s
->pending_join_dev_addr
,
2906 os_memcmp(iface_addr
, wpa_s
->pending_join_dev_addr
, ETH_ALEN
) != 0)
2908 wpa_printf(MSG_DEBUG
, "P2P: Overwrite pending interface "
2909 "address for join from " MACSTR
" to " MACSTR
2910 " based on newly discovered P2P peer entry",
2911 MAC2STR(wpa_s
->pending_join_iface_addr
),
2912 MAC2STR(iface_addr
));
2913 os_memcpy(wpa_s
->pending_join_iface_addr
, iface_addr
,
2916 freq
= p2p_get_oper_freq(wpa_s
->global
->p2p
,
2917 wpa_s
->pending_join_iface_addr
);
2920 wpa_printf(MSG_DEBUG
, "P2P: Target GO operating frequency "
2921 "from P2P peer table: %d MHz", freq
);
2923 bss
= wpa_bss_get_bssid(wpa_s
, wpa_s
->pending_join_iface_addr
);
2926 wpa_printf(MSG_DEBUG
, "P2P: Target GO operating frequency "
2927 "from BSS table: %d MHz", freq
);
2932 if (wpas_check_freq_conflict(wpa_s
, freq
) > 0) {
2933 wpa_msg(wpa_s
->parent
, MSG_INFO
,
2934 P2P_EVENT_GROUP_FORMATION_FAILURE
2935 "reason=FREQ_CONFLICT");
2939 wpa_printf(MSG_DEBUG
, "P2P: Send Provision Discovery Request "
2940 "prior to joining an existing group (GO " MACSTR
2942 MAC2STR(wpa_s
->pending_join_dev_addr
), freq
);
2943 wpa_s
->pending_pd_before_join
= 1;
2945 switch (wpa_s
->pending_join_wps_method
) {
2946 case WPS_PIN_DISPLAY
:
2947 method
= WPS_CONFIG_KEYPAD
;
2949 case WPS_PIN_KEYPAD
:
2950 method
= WPS_CONFIG_DISPLAY
;
2953 method
= WPS_CONFIG_PUSHBUTTON
;
2960 if ((p2p_get_provisioning_info(wpa_s
->global
->p2p
,
2961 wpa_s
->pending_join_dev_addr
) ==
2964 * We have already performed provision discovery for
2965 * joining the group. Proceed directly to join
2966 * operation without duplicated provision discovery. */
2967 wpa_printf(MSG_DEBUG
, "P2P: Provision discovery "
2968 "with " MACSTR
" already done - proceed to "
2970 MAC2STR(wpa_s
->pending_join_dev_addr
));
2971 wpa_s
->pending_pd_before_join
= 0;
2975 if (p2p_prov_disc_req(wpa_s
->global
->p2p
,
2976 wpa_s
->pending_join_dev_addr
, method
, 1,
2978 wpa_printf(MSG_DEBUG
, "P2P: Failed to send Provision "
2979 "Discovery Request before joining an "
2981 wpa_s
->pending_pd_before_join
= 0;
2986 * Actual join operation will be started from the Action frame
2987 * TX status callback (if no ACK is received) or when the
2988 * Provision Discovery Response is received. Use a short
2989 * timeout as a backup mechanism should the Provision Discovery
2990 * Response be lost for any reason.
2992 eloop_cancel_timeout(wpas_p2p_pd_before_join_timeout
, wpa_s
,
2994 eloop_register_timeout(2, 0, wpas_p2p_pd_before_join_timeout
,
2999 wpa_printf(MSG_DEBUG
, "P2P: Failed to find BSS/GO - try again later");
3000 eloop_cancel_timeout(wpas_p2p_join_scan
, wpa_s
, NULL
);
3001 eloop_register_timeout(1, 0, wpas_p2p_join_scan
, wpa_s
, NULL
);
3002 wpas_p2p_check_join_scan_limit(wpa_s
);
3006 /* Start join operation immediately */
3007 wpas_p2p_join_start(wpa_s
);
3011 static void wpas_p2p_join_scan_req(struct wpa_supplicant
*wpa_s
, int freq
)
3014 struct wpa_driver_scan_params params
;
3015 struct wpabuf
*wps_ie
, *ies
;
3017 int freqs
[2] = { 0, 0 };
3019 os_memset(¶ms
, 0, sizeof(params
));
3021 /* P2P Wildcard SSID */
3022 params
.num_ssids
= 1;
3023 params
.ssids
[0].ssid
= (u8
*) P2P_WILDCARD_SSID
;
3024 params
.ssids
[0].ssid_len
= P2P_WILDCARD_SSID_LEN
;
3026 wpa_s
->wps
->dev
.p2p
= 1;
3027 wps_ie
= wps_build_probe_req_ie(DEV_PW_DEFAULT
, &wpa_s
->wps
->dev
,
3028 wpa_s
->wps
->uuid
, WPS_REQ_ENROLLEE
, 0,
3030 if (wps_ie
== NULL
) {
3031 wpas_p2p_scan_res_join(wpa_s
, NULL
);
3035 ielen
= p2p_scan_ie_buf_len(wpa_s
->global
->p2p
);
3036 ies
= wpabuf_alloc(wpabuf_len(wps_ie
) + ielen
);
3038 wpabuf_free(wps_ie
);
3039 wpas_p2p_scan_res_join(wpa_s
, NULL
);
3042 wpabuf_put_buf(ies
, wps_ie
);
3043 wpabuf_free(wps_ie
);
3045 p2p_scan_ie(wpa_s
->global
->p2p
, ies
, NULL
);
3047 params
.p2p_probe
= 1;
3048 params
.extra_ies
= wpabuf_head(ies
);
3049 params
.extra_ies_len
= wpabuf_len(ies
);
3052 params
.freqs
= freqs
;
3056 * Run a scan to update BSS table and start Provision Discovery once
3057 * the new scan results become available.
3059 ret
= wpa_drv_scan(wpa_s
, ¶ms
);
3061 wpa_s
->scan_res_handler
= wpas_p2p_scan_res_join
;
3066 wpa_printf(MSG_DEBUG
, "P2P: Failed to start scan for join - "
3068 eloop_cancel_timeout(wpas_p2p_join_scan
, wpa_s
, NULL
);
3069 eloop_register_timeout(1, 0, wpas_p2p_join_scan
, wpa_s
, NULL
);
3070 wpas_p2p_check_join_scan_limit(wpa_s
);
3075 static void wpas_p2p_join_scan(void *eloop_ctx
, void *timeout_ctx
)
3077 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
3078 wpas_p2p_join_scan_req(wpa_s
, 0);
3082 static int wpas_p2p_join(struct wpa_supplicant
*wpa_s
, const u8
*iface_addr
,
3083 const u8
*dev_addr
, enum p2p_wps_method wps_method
,
3086 wpa_printf(MSG_DEBUG
, "P2P: Request to join existing group (iface "
3087 MACSTR
" dev " MACSTR
")%s",
3088 MAC2STR(iface_addr
), MAC2STR(dev_addr
),
3089 auto_join
? " (auto_join)" : "");
3091 wpa_s
->p2p_auto_pd
= 0;
3092 wpa_s
->p2p_auto_join
= !!auto_join
;
3093 os_memcpy(wpa_s
->pending_join_iface_addr
, iface_addr
, ETH_ALEN
);
3094 os_memcpy(wpa_s
->pending_join_dev_addr
, dev_addr
, ETH_ALEN
);
3095 wpa_s
->pending_join_wps_method
= wps_method
;
3097 /* Make sure we are not running find during connection establishment */
3098 wpas_p2p_stop_find(wpa_s
);
3100 wpa_s
->p2p_join_scan_count
= 0;
3101 wpas_p2p_join_scan(wpa_s
, NULL
);
3106 static int wpas_p2p_join_start(struct wpa_supplicant
*wpa_s
)
3108 struct wpa_supplicant
*group
;
3109 struct p2p_go_neg_results res
;
3110 struct wpa_bss
*bss
;
3112 eloop_cancel_timeout(wpas_p2p_pd_before_join_timeout
, wpa_s
, NULL
);
3113 group
= wpas_p2p_get_group_iface(wpa_s
, 0, 0);
3116 if (group
!= wpa_s
) {
3117 os_memcpy(group
->p2p_pin
, wpa_s
->p2p_pin
,
3118 sizeof(group
->p2p_pin
));
3119 group
->p2p_wps_method
= wpa_s
->p2p_wps_method
;
3122 group
->p2p_in_provisioning
= 1;
3123 group
->p2p_fallback_to_go_neg
= wpa_s
->p2p_fallback_to_go_neg
;
3125 os_memset(&res
, 0, sizeof(res
));
3126 os_memcpy(res
.peer_interface_addr
, wpa_s
->pending_join_iface_addr
,
3128 res
.wps_method
= wpa_s
->pending_join_wps_method
;
3129 bss
= wpa_bss_get_bssid(wpa_s
, wpa_s
->pending_join_iface_addr
);
3131 res
.freq
= bss
->freq
;
3132 res
.ssid_len
= bss
->ssid_len
;
3133 os_memcpy(res
.ssid
, bss
->ssid
, bss
->ssid_len
);
3136 if (wpa_s
->off_channel_freq
|| wpa_s
->roc_waiting_drv_freq
) {
3137 wpa_printf(MSG_DEBUG
, "P2P: Cancel remain-on-channel prior to "
3139 wpa_drv_cancel_remain_on_channel(wpa_s
);
3140 wpa_s
->off_channel_freq
= 0;
3141 wpa_s
->roc_waiting_drv_freq
= 0;
3143 wpas_start_wps_enrollee(group
, &res
);
3146 * Allow a longer timeout for join-a-running-group than normal 15
3147 * second group formation timeout since the GO may not have authorized
3148 * our connection yet.
3150 eloop_cancel_timeout(wpas_p2p_group_formation_timeout
, wpa_s
, NULL
);
3151 eloop_register_timeout(60, 0, wpas_p2p_group_formation_timeout
,
3159 * wpas_p2p_connect - Request P2P Group Formation to be started
3160 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
3161 * @peer_addr: Address of the peer P2P Device
3162 * @pin: PIN to use during provisioning or %NULL to indicate PBC mode
3163 * @persistent_group: Whether to create a persistent group
3164 * @auto_join: Whether to select join vs. GO Negotiation automatically
3165 * @join: Whether to join an existing group (as a client) instead of starting
3166 * Group Owner negotiation; @peer_addr is BSSID in that case
3167 * @auth: Whether to only authorize the connection instead of doing that and
3168 * initiating Group Owner negotiation
3169 * @go_intent: GO Intent or -1 to use default
3170 * @freq: Frequency for the group or 0 for auto-selection
3171 * @persistent_id: Persistent group credentials to use for forcing GO
3172 * parameters or -1 to generate new values (SSID/passphrase)
3173 * @pd: Whether to send Provision Discovery prior to GO Negotiation as an
3174 * interoperability workaround when initiating group formation
3175 * @ht40: Start GO with 40 MHz channel width
3176 * Returns: 0 or new PIN (if pin was %NULL) on success, -1 on unspecified
3177 * failure, -2 on failure due to channel not currently available,
3178 * -3 if forced channel is not supported
3180 int wpas_p2p_connect(struct wpa_supplicant
*wpa_s
, const u8
*peer_addr
,
3181 const char *pin
, enum p2p_wps_method wps_method
,
3182 int persistent_group
, int auto_join
, int join
, int auth
,
3183 int go_intent
, int freq
, int persistent_id
, int pd
,
3186 int force_freq
= 0, oper_freq
= 0;
3189 enum wpa_driver_if_type iftype
;
3191 struct wpa_ssid
*ssid
= NULL
;
3193 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
3196 if (persistent_id
>= 0) {
3197 ssid
= wpa_config_get_network(wpa_s
->conf
, persistent_id
);
3198 if (ssid
== NULL
|| ssid
->disabled
!= 2 ||
3199 ssid
->mode
!= WPAS_MODE_P2P_GO
)
3204 go_intent
= wpa_s
->conf
->p2p_go_intent
;
3207 wpa_s
->p2p_long_listen
= 0;
3209 wpa_s
->p2p_wps_method
= wps_method
;
3210 wpa_s
->p2p_persistent_group
= !!persistent_group
;
3211 wpa_s
->p2p_persistent_id
= persistent_id
;
3212 wpa_s
->p2p_go_intent
= go_intent
;
3213 wpa_s
->p2p_connect_freq
= freq
;
3214 wpa_s
->p2p_fallback_to_go_neg
= 0;
3215 wpa_s
->p2p_pd_before_go_neg
= !!pd
;
3216 wpa_s
->p2p_go_ht40
= !!ht40
;
3219 os_strlcpy(wpa_s
->p2p_pin
, pin
, sizeof(wpa_s
->p2p_pin
));
3220 else if (wps_method
== WPS_PIN_DISPLAY
) {
3221 ret
= wps_generate_pin();
3222 os_snprintf(wpa_s
->p2p_pin
, sizeof(wpa_s
->p2p_pin
), "%08d",
3224 wpa_printf(MSG_DEBUG
, "P2P: Randomly generated PIN: %s",
3227 wpa_s
->p2p_pin
[0] = '\0';
3229 if (join
|| auto_join
) {
3230 u8 iface_addr
[ETH_ALEN
], dev_addr
[ETH_ALEN
];
3232 wpa_printf(MSG_DEBUG
, "P2P: Authorize invitation to "
3233 "connect a running group from " MACSTR
,
3234 MAC2STR(peer_addr
));
3235 os_memcpy(wpa_s
->p2p_auth_invite
, peer_addr
, ETH_ALEN
);
3238 os_memcpy(dev_addr
, peer_addr
, ETH_ALEN
);
3239 if (p2p_get_interface_addr(wpa_s
->global
->p2p
, peer_addr
,
3241 os_memcpy(iface_addr
, peer_addr
, ETH_ALEN
);
3242 p2p_get_dev_addr(wpa_s
->global
->p2p
, peer_addr
,
3246 os_get_time(&wpa_s
->p2p_auto_started
);
3247 wpa_printf(MSG_DEBUG
, "P2P: Auto join started at "
3249 wpa_s
->p2p_auto_started
.sec
,
3250 wpa_s
->p2p_auto_started
.usec
);
3252 if (wpas_p2p_join(wpa_s
, iface_addr
, dev_addr
, wps_method
,
3258 if (wpa_s
->current_ssid
&& wpa_drv_get_bssid(wpa_s
, bssid
) == 0 &&
3260 oper_freq
= wpa_s
->assoc_freq
;
3262 oper_freq
= wpa_drv_shared_freq(wpa_s
);
3268 if (!p2p_supported_freq(wpa_s
->global
->p2p
, freq
)) {
3269 wpa_printf(MSG_DEBUG
, "P2P: The forced channel "
3270 "(%u MHz) is not supported for P2P uses",
3275 if (oper_freq
> 0 && freq
!= oper_freq
&&
3276 !(wpa_s
->drv_flags
&
3277 WPA_DRIVER_FLAGS_MULTI_CHANNEL_CONCURRENT
)) {
3278 wpa_printf(MSG_DEBUG
, "P2P: Cannot start P2P group "
3279 "on %u MHz while connected on another "
3280 "channel (%u MHz)", freq
, oper_freq
);
3283 wpa_printf(MSG_DEBUG
, "P2P: Trying to force us to use the "
3284 "requested channel (%u MHz)", freq
);
3286 } else if (oper_freq
> 0 &&
3287 !p2p_supported_freq(wpa_s
->global
->p2p
, oper_freq
)) {
3288 if (!(wpa_s
->drv_flags
&
3289 WPA_DRIVER_FLAGS_MULTI_CHANNEL_CONCURRENT
)) {
3290 wpa_printf(MSG_DEBUG
, "P2P: Cannot start P2P group "
3291 "while connected on non-P2P supported "
3292 "channel (%u MHz)", oper_freq
);
3295 wpa_printf(MSG_DEBUG
, "P2P: Current operating channel "
3296 "(%u MHz) not available for P2P - try to use "
3297 "another channel", oper_freq
);
3299 } else if (oper_freq
> 0) {
3300 wpa_printf(MSG_DEBUG
, "P2P: Trying to force us to use the "
3301 "channel we are already using (%u MHz) on another "
3302 "interface", oper_freq
);
3303 force_freq
= oper_freq
;
3306 wpa_s
->create_p2p_iface
= wpas_p2p_create_iface(wpa_s
);
3308 if (wpa_s
->create_p2p_iface
) {
3309 /* Prepare to add a new interface for the group */
3310 iftype
= WPA_IF_P2P_GROUP
;
3311 if (go_intent
== 15)
3312 iftype
= WPA_IF_P2P_GO
;
3313 if (wpas_p2p_add_group_interface(wpa_s
, iftype
) < 0) {
3314 wpa_printf(MSG_ERROR
, "P2P: Failed to allocate a new "
3315 "interface for the group");
3319 if_addr
= wpa_s
->pending_interface_addr
;
3321 if_addr
= wpa_s
->own_addr
;
3324 if (wpas_p2p_auth_go_neg(wpa_s
, peer_addr
, wps_method
,
3326 force_freq
, persistent_group
, ssid
) <
3332 if (wpas_p2p_start_go_neg(wpa_s
, peer_addr
, wps_method
,
3333 go_intent
, if_addr
, force_freq
,
3334 persistent_group
, ssid
) < 0) {
3335 if (wpa_s
->create_p2p_iface
)
3336 wpas_p2p_remove_pending_group_interface(wpa_s
);
3344 * wpas_p2p_remain_on_channel_cb - Indication of remain-on-channel start
3345 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
3346 * @freq: Frequency of the channel in MHz
3347 * @duration: Duration of the stay on the channel in milliseconds
3349 * This callback is called when the driver indicates that it has started the
3350 * requested remain-on-channel duration.
3352 void wpas_p2p_remain_on_channel_cb(struct wpa_supplicant
*wpa_s
,
3353 unsigned int freq
, unsigned int duration
)
3355 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
3357 if (wpa_s
->off_channel_freq
== wpa_s
->pending_listen_freq
) {
3358 p2p_listen_cb(wpa_s
->global
->p2p
, wpa_s
->pending_listen_freq
,
3359 wpa_s
->pending_listen_duration
);
3360 wpa_s
->pending_listen_freq
= 0;
3365 static int wpas_p2p_listen_start(struct wpa_supplicant
*wpa_s
,
3366 unsigned int timeout
)
3368 /* Limit maximum Listen state time based on driver limitation. */
3369 if (timeout
> wpa_s
->max_remain_on_chan
)
3370 timeout
= wpa_s
->max_remain_on_chan
;
3372 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
)
3373 return wpa_drv_p2p_listen(wpa_s
, timeout
);
3375 return p2p_listen(wpa_s
->global
->p2p
, timeout
);
3380 * wpas_p2p_cancel_remain_on_channel_cb - Remain-on-channel timeout
3381 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
3382 * @freq: Frequency of the channel in MHz
3384 * This callback is called when the driver indicates that a remain-on-channel
3385 * operation has been completed, i.e., the duration on the requested channel
3388 void wpas_p2p_cancel_remain_on_channel_cb(struct wpa_supplicant
*wpa_s
,
3391 wpa_printf(MSG_DEBUG
, "P2P: Cancel remain-on-channel callback "
3392 "(p2p_long_listen=%d ms pending_action_tx=%p)",
3393 wpa_s
->p2p_long_listen
, wpa_s
->pending_action_tx
);
3394 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
3396 if (p2p_listen_end(wpa_s
->global
->p2p
, freq
) > 0)
3397 return; /* P2P module started a new operation */
3398 if (wpa_s
->pending_action_tx
)
3400 if (wpa_s
->p2p_long_listen
> 0)
3401 wpa_s
->p2p_long_listen
-= wpa_s
->max_remain_on_chan
;
3402 if (wpa_s
->p2p_long_listen
> 0) {
3403 wpa_printf(MSG_DEBUG
, "P2P: Continuing long Listen state");
3404 wpas_p2p_listen_start(wpa_s
, wpa_s
->p2p_long_listen
);
3410 * wpas_p2p_group_remove - Remove a P2P group
3411 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
3412 * @ifname: Network interface name of the group interface or "*" to remove all
3414 * Returns: 0 on success, -1 on failure
3416 * This function is used to remove a P2P group. This can be used to disconnect
3417 * from a group in which the local end is a P2P Client or to end a P2P Group in
3418 * case the local end is the Group Owner. If a virtual network interface was
3419 * created for this group, that interface will be removed. Otherwise, only the
3420 * configured P2P group network will be removed from the interface.
3422 int wpas_p2p_group_remove(struct wpa_supplicant
*wpa_s
, const char *ifname
)
3424 struct wpa_global
*global
= wpa_s
->global
;
3426 if (os_strcmp(ifname
, "*") == 0) {
3427 struct wpa_supplicant
*prev
;
3428 wpa_s
= global
->ifaces
;
3431 wpa_s
= wpa_s
->next
;
3432 wpas_p2p_disconnect(prev
);
3437 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
3438 if (os_strcmp(wpa_s
->ifname
, ifname
) == 0)
3442 return wpas_p2p_disconnect(wpa_s
);
3446 static int wpas_p2p_init_go_params(struct wpa_supplicant
*wpa_s
,
3447 struct p2p_go_neg_results
*params
,
3453 os_memset(params
, 0, sizeof(*params
));
3454 params
->role_go
= 1;
3455 params
->ht40
= ht40
;
3457 wpa_printf(MSG_DEBUG
, "P2P: Set GO freq based on forced "
3458 "frequency %d MHz", freq
);
3459 params
->freq
= freq
;
3460 } else if (wpa_s
->conf
->p2p_oper_reg_class
== 81 &&
3461 wpa_s
->conf
->p2p_oper_channel
>= 1 &&
3462 wpa_s
->conf
->p2p_oper_channel
<= 11) {
3463 params
->freq
= 2407 + 5 * wpa_s
->conf
->p2p_oper_channel
;
3464 wpa_printf(MSG_DEBUG
, "P2P: Set GO freq based on configured "
3465 "frequency %d MHz", params
->freq
);
3466 } else if (wpa_s
->conf
->p2p_oper_reg_class
== 115 ||
3467 wpa_s
->conf
->p2p_oper_reg_class
== 124) {
3468 params
->freq
= 5000 + 5 * wpa_s
->conf
->p2p_oper_channel
;
3469 wpa_printf(MSG_DEBUG
, "P2P: Set GO freq based on configured "
3470 "frequency %d MHz", params
->freq
);
3471 } else if (wpa_s
->conf
->p2p_oper_channel
== 0 &&
3472 wpa_s
->best_overall_freq
> 0 &&
3473 p2p_supported_freq(wpa_s
->global
->p2p
,
3474 wpa_s
->best_overall_freq
)) {
3475 params
->freq
= wpa_s
->best_overall_freq
;
3476 wpa_printf(MSG_DEBUG
, "P2P: Set GO freq based on best overall "
3477 "channel %d MHz", params
->freq
);
3478 } else if (wpa_s
->conf
->p2p_oper_channel
== 0 &&
3479 wpa_s
->best_24_freq
> 0 &&
3480 p2p_supported_freq(wpa_s
->global
->p2p
,
3481 wpa_s
->best_24_freq
)) {
3482 params
->freq
= wpa_s
->best_24_freq
;
3483 wpa_printf(MSG_DEBUG
, "P2P: Set GO freq based on best 2.4 GHz "
3484 "channel %d MHz", params
->freq
);
3485 } else if (wpa_s
->conf
->p2p_oper_channel
== 0 &&
3486 wpa_s
->best_5_freq
> 0 &&
3487 p2p_supported_freq(wpa_s
->global
->p2p
,
3488 wpa_s
->best_5_freq
)) {
3489 params
->freq
= wpa_s
->best_5_freq
;
3490 wpa_printf(MSG_DEBUG
, "P2P: Set GO freq based on best 5 GHz "
3491 "channel %d MHz", params
->freq
);
3494 for (chan
= 0; chan
< 11; chan
++) {
3495 params
->freq
= 2412 + chan
* 5;
3496 if (!wpas_p2p_disallowed_freq(wpa_s
->global
,
3501 wpa_printf(MSG_DEBUG
, "P2P: No 2.4 GHz channel "
3505 wpa_printf(MSG_DEBUG
, "P2P: Set GO freq %d MHz (no preference "
3506 "known)", params
->freq
);
3509 if (wpa_s
->current_ssid
&& wpa_drv_get_bssid(wpa_s
, bssid
) == 0 &&
3510 wpa_s
->assoc_freq
&& !freq
) {
3511 wpa_printf(MSG_DEBUG
, "P2P: Force GO on the channel we are "
3513 params
->freq
= wpa_s
->assoc_freq
;
3516 res
= wpa_drv_shared_freq(wpa_s
);
3517 if (res
> 0 && !freq
) {
3518 wpa_printf(MSG_DEBUG
, "P2P: Force GO on the channel we are "
3519 "already using on a shared interface");
3521 } else if (res
> 0 && freq
!= res
&&
3522 !(wpa_s
->drv_flags
&
3523 WPA_DRIVER_FLAGS_MULTI_CHANNEL_CONCURRENT
)) {
3524 wpa_printf(MSG_DEBUG
, "P2P: Cannot start P2P group on %u MHz "
3525 "while connected on another channel (%u MHz)",
3534 static struct wpa_supplicant
*
3535 wpas_p2p_get_group_iface(struct wpa_supplicant
*wpa_s
, int addr_allocated
,
3538 struct wpa_supplicant
*group_wpa_s
;
3540 if (!wpas_p2p_create_iface(wpa_s
))
3543 if (wpas_p2p_add_group_interface(wpa_s
, go
? WPA_IF_P2P_GO
:
3544 WPA_IF_P2P_CLIENT
) < 0)
3546 group_wpa_s
= wpas_p2p_init_group_interface(wpa_s
, go
);
3547 if (group_wpa_s
== NULL
) {
3548 wpas_p2p_remove_pending_group_interface(wpa_s
);
3557 * wpas_p2p_group_add - Add a new P2P group with local end as Group Owner
3558 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
3559 * @persistent_group: Whether to create a persistent group
3560 * @freq: Frequency for the group or 0 to indicate no hardcoding
3561 * Returns: 0 on success, -1 on failure
3563 * This function creates a new P2P group with the local end as the Group Owner,
3564 * i.e., without using Group Owner Negotiation.
3566 int wpas_p2p_group_add(struct wpa_supplicant
*wpa_s
, int persistent_group
,
3569 struct p2p_go_neg_results params
;
3572 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
3575 /* Make sure we are not running find during connection establishment */
3576 wpa_printf(MSG_DEBUG
, "P2P: Stop any on-going P2P FIND");
3577 wpas_p2p_stop_find(wpa_s
);
3580 wpa_printf(MSG_DEBUG
, "P2P: Request to start GO on 2.4 GHz "
3582 if (wpa_s
->best_24_freq
> 0 &&
3583 p2p_supported_freq(wpa_s
->global
->p2p
,
3584 wpa_s
->best_24_freq
)) {
3585 freq
= wpa_s
->best_24_freq
;
3586 wpa_printf(MSG_DEBUG
, "P2P: Use best 2.4 GHz band "
3587 "channel: %d MHz", freq
);
3589 os_get_random((u8
*) &r
, sizeof(r
));
3590 freq
= 2412 + (r
% 3) * 25;
3591 wpa_printf(MSG_DEBUG
, "P2P: Use random 2.4 GHz band "
3592 "channel: %d MHz", freq
);
3597 wpa_printf(MSG_DEBUG
, "P2P: Request to start GO on 5 GHz "
3599 if (wpa_s
->best_5_freq
> 0 &&
3600 p2p_supported_freq(wpa_s
->global
->p2p
,
3601 wpa_s
->best_5_freq
)) {
3602 freq
= wpa_s
->best_5_freq
;
3603 wpa_printf(MSG_DEBUG
, "P2P: Use best 5 GHz band "
3604 "channel: %d MHz", freq
);
3606 os_get_random((u8
*) &r
, sizeof(r
));
3607 freq
= 5180 + (r
% 4) * 20;
3608 if (!p2p_supported_freq(wpa_s
->global
->p2p
, freq
)) {
3609 wpa_printf(MSG_DEBUG
, "P2P: Could not select "
3610 "5 GHz channel for P2P group");
3613 wpa_printf(MSG_DEBUG
, "P2P: Use random 5 GHz band "
3614 "channel: %d MHz", freq
);
3618 if (freq
> 0 && !p2p_supported_freq(wpa_s
->global
->p2p
, freq
)) {
3619 wpa_printf(MSG_DEBUG
, "P2P: The forced channel for GO "
3620 "(%u MHz) is not supported for P2P uses",
3625 if (wpas_p2p_init_go_params(wpa_s
, ¶ms
, freq
, ht40
))
3628 !p2p_supported_freq(wpa_s
->global
->p2p
, params
.freq
)) {
3629 wpa_printf(MSG_DEBUG
, "P2P: The selected channel for GO "
3630 "(%u MHz) is not supported for P2P uses",
3634 p2p_go_params(wpa_s
->global
->p2p
, ¶ms
);
3635 params
.persistent_group
= persistent_group
;
3637 wpa_s
= wpas_p2p_get_group_iface(wpa_s
, 0, 1);
3640 wpas_start_wps_go(wpa_s
, ¶ms
, 0);
3646 static int wpas_start_p2p_client(struct wpa_supplicant
*wpa_s
,
3647 struct wpa_ssid
*params
, int addr_allocated
)
3649 struct wpa_ssid
*ssid
;
3651 wpa_s
= wpas_p2p_get_group_iface(wpa_s
, addr_allocated
, 0);
3655 wpa_supplicant_ap_deinit(wpa_s
);
3657 ssid
= wpa_config_add_network(wpa_s
->conf
);
3660 wpa_config_set_network_defaults(ssid
);
3661 ssid
->temporary
= 1;
3662 ssid
->proto
= WPA_PROTO_RSN
;
3663 ssid
->pairwise_cipher
= WPA_CIPHER_CCMP
;
3664 ssid
->group_cipher
= WPA_CIPHER_CCMP
;
3665 ssid
->key_mgmt
= WPA_KEY_MGMT_PSK
;
3666 ssid
->ssid
= os_malloc(params
->ssid_len
);
3667 if (ssid
->ssid
== NULL
) {
3668 wpa_config_remove_network(wpa_s
->conf
, ssid
->id
);
3671 os_memcpy(ssid
->ssid
, params
->ssid
, params
->ssid_len
);
3672 ssid
->ssid_len
= params
->ssid_len
;
3673 ssid
->p2p_group
= 1;
3674 ssid
->export_keys
= 1;
3675 if (params
->psk_set
) {
3676 os_memcpy(ssid
->psk
, params
->psk
, 32);
3679 if (params
->passphrase
)
3680 ssid
->passphrase
= os_strdup(params
->passphrase
);
3682 wpa_supplicant_select_network(wpa_s
, ssid
);
3684 wpa_s
->show_group_started
= 1;
3690 int wpas_p2p_group_add_persistent(struct wpa_supplicant
*wpa_s
,
3691 struct wpa_ssid
*ssid
, int addr_allocated
,
3694 struct p2p_go_neg_results params
;
3697 if (ssid
->disabled
!= 2 || ssid
->ssid
== NULL
)
3700 if (wpas_get_p2p_group(wpa_s
, ssid
->ssid
, ssid
->ssid_len
, &go
) &&
3701 go
== (ssid
->mode
== WPAS_MODE_P2P_GO
)) {
3702 wpa_printf(MSG_DEBUG
, "P2P: Requested persistent group is "
3707 /* Make sure we are not running find during connection establishment */
3708 wpas_p2p_stop_find(wpa_s
);
3710 wpa_s
->p2p_fallback_to_go_neg
= 0;
3712 if (ssid
->mode
== WPAS_MODE_INFRA
)
3713 return wpas_start_p2p_client(wpa_s
, ssid
, addr_allocated
);
3715 if (ssid
->mode
!= WPAS_MODE_P2P_GO
)
3718 if (wpas_p2p_init_go_params(wpa_s
, ¶ms
, freq
, ht40
))
3722 if (ssid
->passphrase
== NULL
||
3723 os_strlen(ssid
->passphrase
) >= sizeof(params
.passphrase
)) {
3724 wpa_printf(MSG_DEBUG
, "P2P: Invalid passphrase in persistent "
3728 os_strlcpy(params
.passphrase
, ssid
->passphrase
,
3729 sizeof(params
.passphrase
));
3730 os_memcpy(params
.ssid
, ssid
->ssid
, ssid
->ssid_len
);
3731 params
.ssid_len
= ssid
->ssid_len
;
3732 params
.persistent_group
= 1;
3734 wpa_s
= wpas_p2p_get_group_iface(wpa_s
, addr_allocated
, 1);
3738 wpas_start_wps_go(wpa_s
, ¶ms
, 0);
3744 static void wpas_p2p_ie_update(void *ctx
, struct wpabuf
*beacon_ies
,
3745 struct wpabuf
*proberesp_ies
)
3747 struct wpa_supplicant
*wpa_s
= ctx
;
3748 if (wpa_s
->ap_iface
) {
3749 struct hostapd_data
*hapd
= wpa_s
->ap_iface
->bss
[0];
3750 if (!(hapd
->conf
->p2p
& P2P_GROUP_OWNER
)) {
3751 wpabuf_free(beacon_ies
);
3752 wpabuf_free(proberesp_ies
);
3756 wpabuf_free(hapd
->p2p_beacon_ie
);
3757 hapd
->p2p_beacon_ie
= beacon_ies
;
3759 wpabuf_free(hapd
->p2p_probe_resp_ie
);
3760 hapd
->p2p_probe_resp_ie
= proberesp_ies
;
3762 wpabuf_free(beacon_ies
);
3763 wpabuf_free(proberesp_ies
);
3765 wpa_supplicant_ap_update_beacon(wpa_s
);
3769 static void wpas_p2p_idle_update(void *ctx
, int idle
)
3771 struct wpa_supplicant
*wpa_s
= ctx
;
3772 if (!wpa_s
->ap_iface
)
3774 wpa_printf(MSG_DEBUG
, "P2P: GO - group %sidle", idle
? "" : "not ");
3776 wpas_p2p_set_group_idle_timeout(wpa_s
);
3778 eloop_cancel_timeout(wpas_p2p_group_idle_timeout
, wpa_s
, NULL
);
3782 struct p2p_group
* wpas_p2p_group_init(struct wpa_supplicant
*wpa_s
,
3783 struct wpa_ssid
*ssid
)
3785 struct p2p_group
*group
;
3786 struct p2p_group_config
*cfg
;
3788 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
)
3790 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
3793 cfg
= os_zalloc(sizeof(*cfg
));
3797 if (ssid
->p2p_persistent_group
&& wpa_s
->conf
->persistent_reconnect
)
3798 cfg
->persistent_group
= 2;
3799 else if (ssid
->p2p_persistent_group
)
3800 cfg
->persistent_group
= 1;
3801 os_memcpy(cfg
->interface_addr
, wpa_s
->own_addr
, ETH_ALEN
);
3802 if (wpa_s
->max_stations
&&
3803 wpa_s
->max_stations
< wpa_s
->conf
->max_num_sta
)
3804 cfg
->max_clients
= wpa_s
->max_stations
;
3806 cfg
->max_clients
= wpa_s
->conf
->max_num_sta
;
3807 os_memcpy(cfg
->ssid
, ssid
->ssid
, ssid
->ssid_len
);
3808 cfg
->ssid_len
= ssid
->ssid_len
;
3809 cfg
->cb_ctx
= wpa_s
;
3810 cfg
->ie_update
= wpas_p2p_ie_update
;
3811 cfg
->idle_update
= wpas_p2p_idle_update
;
3813 group
= p2p_group_init(wpa_s
->global
->p2p
, cfg
);
3816 if (ssid
->mode
!= WPAS_MODE_P2P_GROUP_FORMATION
)
3817 p2p_group_notif_formation_done(group
);
3818 wpa_s
->p2p_group
= group
;
3823 void wpas_p2p_wps_success(struct wpa_supplicant
*wpa_s
, const u8
*peer_addr
,
3826 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
3828 if (!wpa_s
->p2p_in_provisioning
) {
3829 wpa_printf(MSG_DEBUG
, "P2P: Ignore WPS success event - P2P "
3830 "provisioning not in progress");
3834 if (ssid
&& ssid
->mode
== WPAS_MODE_INFRA
) {
3835 u8 go_dev_addr
[ETH_ALEN
];
3836 os_memcpy(go_dev_addr
, wpa_s
->bssid
, ETH_ALEN
);
3837 wpas_p2p_persistent_group(wpa_s
, go_dev_addr
, ssid
->ssid
,
3839 /* Clear any stored provisioning info */
3840 p2p_clear_provisioning_info(wpa_s
->global
->p2p
, go_dev_addr
);
3843 eloop_cancel_timeout(wpas_p2p_group_formation_timeout
, wpa_s
->parent
,
3845 if (ssid
&& ssid
->mode
== WPAS_MODE_INFRA
) {
3847 * Use a separate timeout for initial data connection to
3848 * complete to allow the group to be removed automatically if
3849 * something goes wrong in this step before the P2P group idle
3850 * timeout mechanism is taken into use.
3852 eloop_register_timeout(P2P_MAX_INITIAL_CONN_WAIT
, 0,
3853 wpas_p2p_group_formation_timeout
,
3854 wpa_s
->parent
, NULL
);
3856 if (wpa_s
->global
->p2p
)
3857 p2p_wps_success_cb(wpa_s
->global
->p2p
, peer_addr
);
3858 else if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
)
3859 wpa_drv_wps_success_cb(wpa_s
, peer_addr
);
3860 wpas_group_formation_completed(wpa_s
, 1);
3864 void wpas_p2p_wps_failed(struct wpa_supplicant
*wpa_s
,
3865 struct wps_event_fail
*fail
)
3867 if (!wpa_s
->p2p_in_provisioning
) {
3868 wpa_printf(MSG_DEBUG
, "P2P: Ignore WPS fail event - P2P "
3869 "provisioning not in progress");
3873 if (wpa_s
->go_params
) {
3874 p2p_clear_provisioning_info(
3876 wpa_s
->go_params
->peer_device_addr
);
3879 wpas_notify_p2p_wps_failed(wpa_s
, fail
);
3883 int wpas_p2p_prov_disc(struct wpa_supplicant
*wpa_s
, const u8
*peer_addr
,
3884 const char *config_method
,
3885 enum wpas_p2p_prov_disc_use use
)
3889 wpa_s
->p2p_fallback_to_go_neg
= 0;
3890 wpa_s
->pending_pd_use
= NORMAL_PD
;
3891 if (os_strncmp(config_method
, "display", 7) == 0)
3892 config_methods
= WPS_CONFIG_DISPLAY
;
3893 else if (os_strncmp(config_method
, "keypad", 6) == 0)
3894 config_methods
= WPS_CONFIG_KEYPAD
;
3895 else if (os_strncmp(config_method
, "pbc", 3) == 0 ||
3896 os_strncmp(config_method
, "pushbutton", 10) == 0)
3897 config_methods
= WPS_CONFIG_PUSHBUTTON
;
3899 wpa_printf(MSG_DEBUG
, "P2P: Unknown config method");
3903 if (use
== WPAS_P2P_PD_AUTO
) {
3904 os_memcpy(wpa_s
->pending_join_dev_addr
, peer_addr
, ETH_ALEN
);
3905 wpa_s
->pending_pd_config_methods
= config_methods
;
3906 wpa_s
->p2p_auto_pd
= 1;
3907 wpa_s
->p2p_auto_join
= 0;
3908 wpa_s
->pending_pd_before_join
= 0;
3909 wpa_s
->auto_pd_scan_retry
= 0;
3910 wpas_p2p_stop_find(wpa_s
);
3911 wpa_s
->p2p_join_scan_count
= 0;
3912 os_get_time(&wpa_s
->p2p_auto_started
);
3913 wpa_printf(MSG_DEBUG
, "P2P: Auto PD started at %ld.%06ld",
3914 wpa_s
->p2p_auto_started
.sec
,
3915 wpa_s
->p2p_auto_started
.usec
);
3916 wpas_p2p_join_scan(wpa_s
, NULL
);
3920 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
) {
3921 return wpa_drv_p2p_prov_disc_req(wpa_s
, peer_addr
,
3923 use
== WPAS_P2P_PD_FOR_JOIN
);
3926 if (wpa_s
->global
->p2p
== NULL
|| wpa_s
->global
->p2p_disabled
)
3929 return p2p_prov_disc_req(wpa_s
->global
->p2p
, peer_addr
,
3930 config_methods
, use
== WPAS_P2P_PD_FOR_JOIN
,
3935 int wpas_p2p_scan_result_text(const u8
*ies
, size_t ies_len
, char *buf
,
3938 return p2p_scan_result_text(ies
, ies_len
, buf
, end
);
3942 static void wpas_p2p_clear_pending_action_tx(struct wpa_supplicant
*wpa_s
)
3944 if (!wpa_s
->pending_action_tx
)
3947 wpa_printf(MSG_DEBUG
, "P2P: Drop pending Action TX due to new "
3948 "operation request");
3949 wpabuf_free(wpa_s
->pending_action_tx
);
3950 wpa_s
->pending_action_tx
= NULL
;
3954 int wpas_p2p_find(struct wpa_supplicant
*wpa_s
, unsigned int timeout
,
3955 enum p2p_discovery_type type
,
3956 unsigned int num_req_dev_types
, const u8
*req_dev_types
,
3957 const u8
*dev_id
, unsigned int search_delay
)
3959 wpas_p2p_clear_pending_action_tx(wpa_s
);
3960 wpa_s
->p2p_long_listen
= 0;
3962 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
)
3963 return wpa_drv_p2p_find(wpa_s
, timeout
, type
);
3965 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
||
3966 wpa_s
->p2p_in_provisioning
)
3969 wpa_supplicant_cancel_sched_scan(wpa_s
);
3971 return p2p_find(wpa_s
->global
->p2p
, timeout
, type
,
3972 num_req_dev_types
, req_dev_types
, dev_id
,
3977 void wpas_p2p_stop_find(struct wpa_supplicant
*wpa_s
)
3979 wpas_p2p_clear_pending_action_tx(wpa_s
);
3980 wpa_s
->p2p_long_listen
= 0;
3981 eloop_cancel_timeout(wpas_p2p_long_listen_timeout
, wpa_s
, NULL
);
3982 eloop_cancel_timeout(wpas_p2p_join_scan
, wpa_s
, NULL
);
3983 wpa_s
->p2p_cb_on_scan_complete
= 0;
3985 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
) {
3986 wpa_drv_p2p_stop_find(wpa_s
);
3990 if (wpa_s
->global
->p2p
)
3991 p2p_stop_find(wpa_s
->global
->p2p
);
3993 wpas_p2p_remove_pending_group_interface(wpa_s
);
3997 static void wpas_p2p_long_listen_timeout(void *eloop_ctx
, void *timeout_ctx
)
3999 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
4000 wpa_s
->p2p_long_listen
= 0;
4004 int wpas_p2p_listen(struct wpa_supplicant
*wpa_s
, unsigned int timeout
)
4008 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
4011 wpa_supplicant_cancel_sched_scan(wpa_s
);
4012 wpas_p2p_clear_pending_action_tx(wpa_s
);
4016 * This is a request for unlimited Listen state. However, at
4017 * least for now, this is mapped to a Listen state for one
4022 eloop_cancel_timeout(wpas_p2p_long_listen_timeout
, wpa_s
, NULL
);
4023 wpa_s
->p2p_long_listen
= 0;
4026 * Stop previous find/listen operation to avoid trying to request a new
4027 * remain-on-channel operation while the driver is still running the
4030 if (wpa_s
->global
->p2p
)
4031 p2p_stop_find(wpa_s
->global
->p2p
);
4033 res
= wpas_p2p_listen_start(wpa_s
, timeout
* 1000);
4034 if (res
== 0 && timeout
* 1000 > wpa_s
->max_remain_on_chan
) {
4035 wpa_s
->p2p_long_listen
= timeout
* 1000;
4036 eloop_register_timeout(timeout
, 0,
4037 wpas_p2p_long_listen_timeout
,
4045 int wpas_p2p_assoc_req_ie(struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
,
4046 u8
*buf
, size_t len
, int p2p_group
)
4048 struct wpabuf
*p2p_ie
;
4051 if (wpa_s
->global
->p2p_disabled
)
4053 if (wpa_s
->global
->p2p
== NULL
)
4058 p2p_ie
= wpa_bss_get_vendor_ie_multi(bss
, P2P_IE_VENDOR_TYPE
);
4059 ret
= p2p_assoc_req_ie(wpa_s
->global
->p2p
, bss
->bssid
, buf
, len
,
4061 wpabuf_free(p2p_ie
);
4067 int wpas_p2p_probe_req_rx(struct wpa_supplicant
*wpa_s
, const u8
*addr
,
4068 const u8
*dst
, const u8
*bssid
,
4069 const u8
*ie
, size_t ie_len
, int ssi_signal
)
4071 if (wpa_s
->global
->p2p_disabled
)
4073 if (wpa_s
->global
->p2p
== NULL
)
4076 switch (p2p_probe_req_rx(wpa_s
->global
->p2p
, addr
, dst
, bssid
,
4078 case P2P_PREQ_NOT_P2P
:
4079 wpas_notify_preq(wpa_s
, addr
, dst
, bssid
, ie
, ie_len
,
4082 case P2P_PREQ_MALFORMED
:
4083 case P2P_PREQ_NOT_LISTEN
:
4084 case P2P_PREQ_NOT_PROCESSED
:
4085 default: /* make gcc happy */
4087 case P2P_PREQ_PROCESSED
:
4093 void wpas_p2p_rx_action(struct wpa_supplicant
*wpa_s
, const u8
*da
,
4094 const u8
*sa
, const u8
*bssid
,
4095 u8 category
, const u8
*data
, size_t len
, int freq
)
4097 if (wpa_s
->global
->p2p_disabled
)
4099 if (wpa_s
->global
->p2p
== NULL
)
4102 p2p_rx_action(wpa_s
->global
->p2p
, da
, sa
, bssid
, category
, data
, len
,
4107 void wpas_p2p_scan_ie(struct wpa_supplicant
*wpa_s
, struct wpabuf
*ies
)
4109 if (wpa_s
->global
->p2p_disabled
)
4111 if (wpa_s
->global
->p2p
== NULL
)
4114 p2p_scan_ie(wpa_s
->global
->p2p
, ies
, NULL
);
4118 void wpas_p2p_group_deinit(struct wpa_supplicant
*wpa_s
)
4120 p2p_group_deinit(wpa_s
->p2p_group
);
4121 wpa_s
->p2p_group
= NULL
;
4123 wpa_s
->ap_configured_cb
= NULL
;
4124 wpa_s
->ap_configured_cb_ctx
= NULL
;
4125 wpa_s
->ap_configured_cb_data
= NULL
;
4126 wpa_s
->connect_without_scan
= NULL
;
4130 int wpas_p2p_reject(struct wpa_supplicant
*wpa_s
, const u8
*addr
)
4132 wpa_s
->p2p_long_listen
= 0;
4134 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
)
4135 return wpa_drv_p2p_reject(wpa_s
, addr
);
4137 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
4140 return p2p_reject(wpa_s
->global
->p2p
, addr
);
4144 /* Invite to reinvoke a persistent group */
4145 int wpas_p2p_invite(struct wpa_supplicant
*wpa_s
, const u8
*peer_addr
,
4146 struct wpa_ssid
*ssid
, const u8
*go_dev_addr
)
4148 enum p2p_invite_role role
;
4151 if (ssid
->mode
== WPAS_MODE_P2P_GO
) {
4152 role
= P2P_INVITE_ROLE_GO
;
4153 if (peer_addr
== NULL
) {
4154 wpa_printf(MSG_DEBUG
, "P2P: Missing peer "
4155 "address in invitation command");
4158 if (wpas_p2p_create_iface(wpa_s
)) {
4159 if (wpas_p2p_add_group_interface(wpa_s
,
4160 WPA_IF_P2P_GO
) < 0) {
4161 wpa_printf(MSG_ERROR
, "P2P: Failed to "
4162 "allocate a new interface for the "
4166 bssid
= wpa_s
->pending_interface_addr
;
4168 bssid
= wpa_s
->own_addr
;
4170 role
= P2P_INVITE_ROLE_CLIENT
;
4171 peer_addr
= ssid
->bssid
;
4173 wpa_s
->pending_invite_ssid_id
= ssid
->id
;
4175 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
)
4176 return wpa_drv_p2p_invite(wpa_s
, peer_addr
, role
, bssid
,
4177 ssid
->ssid
, ssid
->ssid_len
,
4180 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
4183 return p2p_invite(wpa_s
->global
->p2p
, peer_addr
, role
, bssid
,
4184 ssid
->ssid
, ssid
->ssid_len
, 0, go_dev_addr
, 1);
4188 /* Invite to join an active group */
4189 int wpas_p2p_invite_group(struct wpa_supplicant
*wpa_s
, const char *ifname
,
4190 const u8
*peer_addr
, const u8
*go_dev_addr
)
4192 struct wpa_global
*global
= wpa_s
->global
;
4193 enum p2p_invite_role role
;
4195 struct wpa_ssid
*ssid
;
4198 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
4199 if (os_strcmp(wpa_s
->ifname
, ifname
) == 0)
4202 if (wpa_s
== NULL
) {
4203 wpa_printf(MSG_DEBUG
, "P2P: Interface '%s' not found", ifname
);
4207 ssid
= wpa_s
->current_ssid
;
4209 wpa_printf(MSG_DEBUG
, "P2P: No current SSID to use for "
4214 persistent
= ssid
->p2p_persistent_group
&&
4215 wpas_p2p_get_persistent(wpa_s
->parent
, peer_addr
,
4216 ssid
->ssid
, ssid
->ssid_len
);
4218 if (ssid
->mode
== WPAS_MODE_P2P_GO
) {
4219 role
= P2P_INVITE_ROLE_ACTIVE_GO
;
4220 bssid
= wpa_s
->own_addr
;
4221 if (go_dev_addr
== NULL
)
4222 go_dev_addr
= wpa_s
->global
->p2p_dev_addr
;
4224 role
= P2P_INVITE_ROLE_CLIENT
;
4225 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
) {
4226 wpa_printf(MSG_DEBUG
, "P2P: Not associated - cannot "
4227 "invite to current group");
4230 bssid
= wpa_s
->bssid
;
4231 if (go_dev_addr
== NULL
&&
4232 !is_zero_ether_addr(wpa_s
->go_dev_addr
))
4233 go_dev_addr
= wpa_s
->go_dev_addr
;
4235 wpa_s
->parent
->pending_invite_ssid_id
= -1;
4237 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
)
4238 return wpa_drv_p2p_invite(wpa_s
, peer_addr
, role
, bssid
,
4239 ssid
->ssid
, ssid
->ssid_len
,
4240 go_dev_addr
, persistent
);
4242 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
4245 return p2p_invite(wpa_s
->global
->p2p
, peer_addr
, role
, bssid
,
4246 ssid
->ssid
, ssid
->ssid_len
, wpa_s
->assoc_freq
,
4247 go_dev_addr
, persistent
);
4251 void wpas_p2p_completed(struct wpa_supplicant
*wpa_s
)
4253 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
4254 const char *ssid_txt
;
4255 u8 go_dev_addr
[ETH_ALEN
];
4256 int network_id
= -1;
4260 if (ssid
== NULL
|| ssid
->mode
!= WPAS_MODE_P2P_GROUP_FORMATION
) {
4261 eloop_cancel_timeout(wpas_p2p_group_formation_timeout
,
4262 wpa_s
->parent
, NULL
);
4265 if (!wpa_s
->show_group_started
|| !ssid
)
4268 wpa_s
->show_group_started
= 0;
4270 ssid_txt
= wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
);
4271 os_memset(go_dev_addr
, 0, ETH_ALEN
);
4272 if (ssid
->bssid_set
)
4273 os_memcpy(go_dev_addr
, ssid
->bssid
, ETH_ALEN
);
4274 persistent
= wpas_p2p_persistent_group(wpa_s
, go_dev_addr
, ssid
->ssid
,
4276 os_memcpy(wpa_s
->go_dev_addr
, go_dev_addr
, ETH_ALEN
);
4278 if (wpa_s
->global
->p2p_group_formation
== wpa_s
)
4279 wpa_s
->global
->p2p_group_formation
= NULL
;
4281 freq
= wpa_s
->current_bss
? wpa_s
->current_bss
->freq
:
4282 (int) wpa_s
->assoc_freq
;
4283 if (ssid
->passphrase
== NULL
&& ssid
->psk_set
) {
4285 wpa_snprintf_hex(psk
, sizeof(psk
), ssid
->psk
, 32);
4286 wpa_msg(wpa_s
->parent
, MSG_INFO
, P2P_EVENT_GROUP_STARTED
4287 "%s client ssid=\"%s\" freq=%d psk=%s go_dev_addr="
4289 wpa_s
->ifname
, ssid_txt
, freq
, psk
,
4290 MAC2STR(go_dev_addr
),
4291 persistent
? " [PERSISTENT]" : "");
4293 wpa_msg(wpa_s
->parent
, MSG_INFO
, P2P_EVENT_GROUP_STARTED
4294 "%s client ssid=\"%s\" freq=%d passphrase=\"%s\" "
4295 "go_dev_addr=" MACSTR
"%s",
4296 wpa_s
->ifname
, ssid_txt
, freq
,
4297 ssid
->passphrase
? ssid
->passphrase
: "",
4298 MAC2STR(go_dev_addr
),
4299 persistent
? " [PERSISTENT]" : "");
4303 network_id
= wpas_p2p_store_persistent_group(wpa_s
->parent
,
4306 network_id
= ssid
->id
;
4307 wpas_notify_p2p_group_started(wpa_s
, ssid
, network_id
, 1);
4311 int wpas_p2p_presence_req(struct wpa_supplicant
*wpa_s
, u32 duration1
,
4312 u32 interval1
, u32 duration2
, u32 interval2
)
4314 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
)
4316 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
4319 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
||
4320 wpa_s
->current_ssid
== NULL
||
4321 wpa_s
->current_ssid
->mode
!= WPAS_MODE_INFRA
)
4324 return p2p_presence_req(wpa_s
->global
->p2p
, wpa_s
->bssid
,
4325 wpa_s
->own_addr
, wpa_s
->assoc_freq
,
4326 duration1
, interval1
, duration2
, interval2
);
4330 int wpas_p2p_ext_listen(struct wpa_supplicant
*wpa_s
, unsigned int period
,
4331 unsigned int interval
)
4333 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
)
4336 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
4339 return p2p_ext_listen(wpa_s
->global
->p2p
, period
, interval
);
4343 static int wpas_p2p_is_client(struct wpa_supplicant
*wpa_s
)
4345 return wpa_s
->current_ssid
!= NULL
&&
4346 wpa_s
->current_ssid
->p2p_group
&&
4347 wpa_s
->current_ssid
->mode
== WPAS_MODE_INFRA
;
4351 static void wpas_p2p_group_idle_timeout(void *eloop_ctx
, void *timeout_ctx
)
4353 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
4355 if (wpa_s
->conf
->p2p_group_idle
== 0 && !wpas_p2p_is_client(wpa_s
)) {
4356 wpa_printf(MSG_DEBUG
, "P2P: Ignore group idle timeout - "
4361 wpa_printf(MSG_DEBUG
, "P2P: Group idle timeout reached - terminate "
4363 wpas_p2p_group_delete(wpa_s
, P2P_GROUP_REMOVAL_IDLE_TIMEOUT
);
4367 static void wpas_p2p_set_group_idle_timeout(struct wpa_supplicant
*wpa_s
)
4371 if (eloop_cancel_timeout(wpas_p2p_group_idle_timeout
, wpa_s
, NULL
) > 0)
4372 wpa_printf(MSG_DEBUG
, "P2P: Cancelled P2P group idle timeout");
4374 if (wpa_s
->current_ssid
== NULL
|| !wpa_s
->current_ssid
->p2p_group
)
4377 timeout
= wpa_s
->conf
->p2p_group_idle
;
4378 if (wpa_s
->current_ssid
->mode
== WPAS_MODE_INFRA
&&
4379 (timeout
== 0 || timeout
> P2P_MAX_CLIENT_IDLE
))
4380 timeout
= P2P_MAX_CLIENT_IDLE
;
4386 if (wpa_s
->current_ssid
->mode
== WPAS_MODE_INFRA
)
4387 timeout
= 0; /* special client mode no-timeout */
4392 if (wpa_s
->p2p_in_provisioning
) {
4394 * Use the normal group formation timeout during the
4395 * provisioning phase to avoid terminating this process too
4396 * early due to group idle timeout.
4398 wpa_printf(MSG_DEBUG
, "P2P: Do not use P2P group idle timeout "
4399 "during provisioning");
4403 if (wpa_s
->show_group_started
) {
4405 * Use the normal group formation timeout between the end of
4406 * the provisioning phase and completion of 4-way handshake to
4407 * avoid terminating this process too early due to group idle
4410 wpa_printf(MSG_DEBUG
, "P2P: Do not use P2P group idle timeout "
4411 "while waiting for initial 4-way handshake to "
4416 wpa_printf(MSG_DEBUG
, "P2P: Set P2P group idle timeout to %u seconds",
4418 eloop_register_timeout(timeout
, 0, wpas_p2p_group_idle_timeout
,
4423 void wpas_p2p_deauth_notif(struct wpa_supplicant
*wpa_s
, const u8
*bssid
,
4424 u16 reason_code
, const u8
*ie
, size_t ie_len
,
4425 int locally_generated
)
4427 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
4429 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
)
4432 if (!locally_generated
)
4433 p2p_deauth_notif(wpa_s
->global
->p2p
, bssid
, reason_code
, ie
,
4436 if (reason_code
== WLAN_REASON_DEAUTH_LEAVING
&& !locally_generated
&&
4437 wpa_s
->current_ssid
&&
4438 wpa_s
->current_ssid
->p2p_group
&&
4439 wpa_s
->current_ssid
->mode
== WPAS_MODE_INFRA
) {
4440 wpa_printf(MSG_DEBUG
, "P2P: GO indicated that the P2P Group "
4441 "session is ending");
4442 wpas_p2p_group_delete(wpa_s
,
4443 P2P_GROUP_REMOVAL_GO_ENDING_SESSION
);
4448 void wpas_p2p_disassoc_notif(struct wpa_supplicant
*wpa_s
, const u8
*bssid
,
4449 u16 reason_code
, const u8
*ie
, size_t ie_len
,
4450 int locally_generated
)
4452 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
4454 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
)
4457 if (!locally_generated
)
4458 p2p_disassoc_notif(wpa_s
->global
->p2p
, bssid
, reason_code
, ie
,
4463 void wpas_p2p_update_config(struct wpa_supplicant
*wpa_s
)
4465 struct p2p_data
*p2p
= wpa_s
->global
->p2p
;
4470 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_CAPABLE
))
4473 if (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_DEVICE_NAME
)
4474 p2p_set_dev_name(p2p
, wpa_s
->conf
->device_name
);
4476 if (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_DEVICE_TYPE
)
4477 p2p_set_pri_dev_type(p2p
, wpa_s
->conf
->device_type
);
4480 (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_CONFIG_METHODS
))
4481 p2p_set_config_methods(p2p
, wpa_s
->wps
->config_methods
);
4483 if (wpa_s
->wps
&& (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_UUID
))
4484 p2p_set_uuid(p2p
, wpa_s
->wps
->uuid
);
4486 if (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_WPS_STRING
) {
4487 p2p_set_manufacturer(p2p
, wpa_s
->conf
->manufacturer
);
4488 p2p_set_model_name(p2p
, wpa_s
->conf
->model_name
);
4489 p2p_set_model_number(p2p
, wpa_s
->conf
->model_number
);
4490 p2p_set_serial_number(p2p
, wpa_s
->conf
->serial_number
);
4493 if (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_SEC_DEVICE_TYPE
)
4494 p2p_set_sec_dev_types(p2p
,
4495 (void *) wpa_s
->conf
->sec_device_type
,
4496 wpa_s
->conf
->num_sec_device_types
);
4498 if (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_VENDOR_EXTENSION
) {
4500 p2p_remove_wps_vendor_extensions(p2p
);
4501 for (i
= 0; i
< MAX_WPS_VENDOR_EXT
; i
++) {
4502 if (wpa_s
->conf
->wps_vendor_ext
[i
] == NULL
)
4504 p2p_add_wps_vendor_extension(
4505 p2p
, wpa_s
->conf
->wps_vendor_ext
[i
]);
4509 if ((wpa_s
->conf
->changed_parameters
& CFG_CHANGED_COUNTRY
) &&
4510 wpa_s
->conf
->country
[0] && wpa_s
->conf
->country
[1]) {
4512 country
[0] = wpa_s
->conf
->country
[0];
4513 country
[1] = wpa_s
->conf
->country
[1];
4515 p2p_set_country(p2p
, country
);
4518 if (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_P2P_SSID_POSTFIX
) {
4519 p2p_set_ssid_postfix(p2p
, (u8
*) wpa_s
->conf
->p2p_ssid_postfix
,
4520 wpa_s
->conf
->p2p_ssid_postfix
?
4521 os_strlen(wpa_s
->conf
->p2p_ssid_postfix
) :
4525 if (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_P2P_INTRA_BSS
)
4526 p2p_set_intra_bss_dist(p2p
, wpa_s
->conf
->p2p_intra_bss
);
4528 if (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_P2P_LISTEN_CHANNEL
) {
4529 u8 reg_class
, channel
;
4532 if (wpa_s
->conf
->p2p_listen_reg_class
&&
4533 wpa_s
->conf
->p2p_listen_channel
) {
4534 reg_class
= wpa_s
->conf
->p2p_listen_reg_class
;
4535 channel
= wpa_s
->conf
->p2p_listen_channel
;
4539 * Pick one of the social channels randomly as the
4542 os_get_random((u8
*) &r
, sizeof(r
));
4543 channel
= 1 + (r
% 3) * 5;
4545 ret
= p2p_set_listen_channel(p2p
, reg_class
, channel
);
4547 wpa_printf(MSG_ERROR
, "P2P: Own listen channel update "
4550 if (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_P2P_OPER_CHANNEL
) {
4551 u8 op_reg_class
, op_channel
, cfg_op_channel
;
4554 if (wpa_s
->conf
->p2p_oper_reg_class
&&
4555 wpa_s
->conf
->p2p_oper_channel
) {
4556 op_reg_class
= wpa_s
->conf
->p2p_oper_reg_class
;
4557 op_channel
= wpa_s
->conf
->p2p_oper_channel
;
4562 * Use random operation channel from (1, 6, 11)
4563 *if no other preference is indicated.
4565 os_get_random((u8
*) &r
, sizeof(r
));
4566 op_channel
= 1 + (r
% 3) * 5;
4569 ret
= p2p_set_oper_channel(p2p
, op_reg_class
, op_channel
,
4572 wpa_printf(MSG_ERROR
, "P2P: Own oper channel update "
4576 if (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_P2P_PREF_CHAN
) {
4577 if (p2p_set_pref_chan(p2p
, wpa_s
->conf
->num_p2p_pref_chan
,
4578 wpa_s
->conf
->p2p_pref_chan
) < 0) {
4579 wpa_printf(MSG_ERROR
, "P2P: Preferred channel list "
4586 int wpas_p2p_set_noa(struct wpa_supplicant
*wpa_s
, u8 count
, int start
,
4589 if (!wpa_s
->ap_iface
)
4591 return hostapd_p2p_set_noa(wpa_s
->ap_iface
->bss
[0], count
, start
,
4596 int wpas_p2p_set_cross_connect(struct wpa_supplicant
*wpa_s
, int enabled
)
4598 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
4600 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
)
4603 wpa_s
->global
->cross_connection
= enabled
;
4604 p2p_set_cross_connect(wpa_s
->global
->p2p
, enabled
);
4607 struct wpa_supplicant
*iface
;
4609 for (iface
= wpa_s
->global
->ifaces
; iface
; iface
= iface
->next
)
4611 if (iface
->cross_connect_enabled
== 0)
4614 iface
->cross_connect_enabled
= 0;
4615 iface
->cross_connect_in_use
= 0;
4616 wpa_msg(iface
->parent
, MSG_INFO
,
4617 P2P_EVENT_CROSS_CONNECT_DISABLE
"%s %s",
4618 iface
->ifname
, iface
->cross_connect_uplink
);
4626 static void wpas_p2p_enable_cross_connect(struct wpa_supplicant
*uplink
)
4628 struct wpa_supplicant
*iface
;
4630 if (!uplink
->global
->cross_connection
)
4633 for (iface
= uplink
->global
->ifaces
; iface
; iface
= iface
->next
) {
4634 if (!iface
->cross_connect_enabled
)
4636 if (os_strcmp(uplink
->ifname
, iface
->cross_connect_uplink
) !=
4639 if (iface
->ap_iface
== NULL
)
4641 if (iface
->cross_connect_in_use
)
4644 iface
->cross_connect_in_use
= 1;
4645 wpa_msg(iface
->parent
, MSG_INFO
,
4646 P2P_EVENT_CROSS_CONNECT_ENABLE
"%s %s",
4647 iface
->ifname
, iface
->cross_connect_uplink
);
4652 static void wpas_p2p_disable_cross_connect(struct wpa_supplicant
*uplink
)
4654 struct wpa_supplicant
*iface
;
4656 for (iface
= uplink
->global
->ifaces
; iface
; iface
= iface
->next
) {
4657 if (!iface
->cross_connect_enabled
)
4659 if (os_strcmp(uplink
->ifname
, iface
->cross_connect_uplink
) !=
4662 if (!iface
->cross_connect_in_use
)
4665 wpa_msg(iface
->parent
, MSG_INFO
,
4666 P2P_EVENT_CROSS_CONNECT_DISABLE
"%s %s",
4667 iface
->ifname
, iface
->cross_connect_uplink
);
4668 iface
->cross_connect_in_use
= 0;
4673 void wpas_p2p_notif_connected(struct wpa_supplicant
*wpa_s
)
4675 if (wpa_s
->ap_iface
|| wpa_s
->current_ssid
== NULL
||
4676 wpa_s
->current_ssid
->mode
!= WPAS_MODE_INFRA
||
4677 wpa_s
->cross_connect_disallowed
)
4678 wpas_p2p_disable_cross_connect(wpa_s
);
4680 wpas_p2p_enable_cross_connect(wpa_s
);
4681 if (!wpa_s
->ap_iface
&&
4682 eloop_cancel_timeout(wpas_p2p_group_idle_timeout
, wpa_s
, NULL
) > 0)
4683 wpa_printf(MSG_DEBUG
, "P2P: Cancelled P2P group idle timeout");
4687 void wpas_p2p_notif_disconnected(struct wpa_supplicant
*wpa_s
)
4689 wpas_p2p_disable_cross_connect(wpa_s
);
4690 if (!wpa_s
->ap_iface
&&
4691 !eloop_is_timeout_registered(wpas_p2p_group_idle_timeout
,
4693 wpas_p2p_set_group_idle_timeout(wpa_s
);
4697 static void wpas_p2p_cross_connect_setup(struct wpa_supplicant
*wpa_s
)
4699 struct wpa_supplicant
*iface
;
4701 if (!wpa_s
->global
->cross_connection
)
4704 for (iface
= wpa_s
->global
->ifaces
; iface
; iface
= iface
->next
) {
4707 if (iface
->drv_flags
&
4708 WPA_DRIVER_FLAGS_P2P_DEDICATED_INTERFACE
)
4710 if (iface
->drv_flags
& WPA_DRIVER_FLAGS_P2P_CAPABLE
)
4713 wpa_s
->cross_connect_enabled
= 1;
4714 os_strlcpy(wpa_s
->cross_connect_uplink
, iface
->ifname
,
4715 sizeof(wpa_s
->cross_connect_uplink
));
4716 wpa_printf(MSG_DEBUG
, "P2P: Enable cross connection from "
4717 "%s to %s whenever uplink is available",
4718 wpa_s
->ifname
, wpa_s
->cross_connect_uplink
);
4720 if (iface
->ap_iface
|| iface
->current_ssid
== NULL
||
4721 iface
->current_ssid
->mode
!= WPAS_MODE_INFRA
||
4722 iface
->cross_connect_disallowed
||
4723 iface
->wpa_state
!= WPA_COMPLETED
)
4726 wpa_s
->cross_connect_in_use
= 1;
4727 wpa_msg(wpa_s
->parent
, MSG_INFO
,
4728 P2P_EVENT_CROSS_CONNECT_ENABLE
"%s %s",
4729 wpa_s
->ifname
, wpa_s
->cross_connect_uplink
);
4735 int wpas_p2p_notif_pbc_overlap(struct wpa_supplicant
*wpa_s
)
4737 if (wpa_s
->p2p_group_interface
!= P2P_GROUP_INTERFACE_CLIENT
&&
4738 !wpa_s
->p2p_in_provisioning
)
4739 return 0; /* not P2P client operation */
4741 wpa_printf(MSG_DEBUG
, "P2P: Terminate connection due to WPS PBC "
4743 if (wpa_s
!= wpa_s
->parent
)
4744 wpa_msg_ctrl(wpa_s
->parent
, MSG_INFO
, WPS_EVENT_OVERLAP
);
4746 if (wpa_s
->global
->p2p
)
4747 p2p_group_formation_failed(wpa_s
->global
->p2p
);
4749 eloop_cancel_timeout(wpas_p2p_group_formation_timeout
,
4750 wpa_s
->parent
, NULL
);
4752 wpas_group_formation_completed(wpa_s
, 0);
4757 void wpas_p2p_update_channel_list(struct wpa_supplicant
*wpa_s
)
4759 struct p2p_channels chan
;
4761 if (wpa_s
->global
== NULL
|| wpa_s
->global
->p2p
== NULL
)
4764 os_memset(&chan
, 0, sizeof(chan
));
4765 if (wpas_p2p_setup_channels(wpa_s
, &chan
)) {
4766 wpa_printf(MSG_ERROR
, "P2P: Failed to update supported "
4771 p2p_update_channel_list(wpa_s
->global
->p2p
, &chan
);
4775 int wpas_p2p_cancel(struct wpa_supplicant
*wpa_s
)
4777 struct wpa_global
*global
= wpa_s
->global
;
4781 if (global
->p2p
== NULL
)
4784 wpa_printf(MSG_DEBUG
, "P2P: Request to cancel group formation");
4786 if (wpa_s
->pending_interface_name
[0] &&
4787 !is_zero_ether_addr(wpa_s
->pending_interface_addr
))
4790 peer
= p2p_get_go_neg_peer(global
->p2p
);
4792 wpa_printf(MSG_DEBUG
, "P2P: Unauthorize pending GO Neg peer "
4793 MACSTR
, MAC2STR(peer
));
4794 p2p_unauthorize(global
->p2p
, peer
);
4798 wpas_p2p_stop_find(wpa_s
);
4800 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
4801 if (wpa_s
== global
->p2p_group_formation
&&
4802 (wpa_s
->p2p_in_provisioning
||
4803 wpa_s
->parent
->pending_interface_type
==
4804 WPA_IF_P2P_CLIENT
)) {
4805 wpa_printf(MSG_DEBUG
, "P2P: Interface %s in group "
4806 "formation found - cancelling",
4809 eloop_cancel_timeout(wpas_p2p_group_formation_timeout
,
4810 wpa_s
->parent
, NULL
);
4811 wpas_p2p_group_delete(wpa_s
,
4812 P2P_GROUP_REMOVAL_REQUESTED
);
4818 wpa_printf(MSG_DEBUG
, "P2P: No ongoing group formation found");
4826 void wpas_p2p_interface_unavailable(struct wpa_supplicant
*wpa_s
)
4828 if (wpa_s
->current_ssid
== NULL
|| !wpa_s
->current_ssid
->p2p_group
)
4831 wpa_printf(MSG_DEBUG
, "P2P: Remove group due to driver resource not "
4832 "being available anymore");
4833 wpas_p2p_group_delete(wpa_s
, P2P_GROUP_REMOVAL_UNAVAILABLE
);
4837 void wpas_p2p_update_best_channels(struct wpa_supplicant
*wpa_s
,
4838 int freq_24
, int freq_5
, int freq_overall
)
4840 struct p2p_data
*p2p
= wpa_s
->global
->p2p
;
4841 if (p2p
== NULL
|| (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
))
4843 p2p_set_best_channels(p2p
, freq_24
, freq_5
, freq_overall
);
4847 int wpas_p2p_unauthorize(struct wpa_supplicant
*wpa_s
, const char *addr
)
4850 struct p2p_data
*p2p
= wpa_s
->global
->p2p
;
4852 if (p2p
== NULL
|| (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
))
4855 if (hwaddr_aton(addr
, peer
))
4858 return p2p_unauthorize(p2p
, peer
);
4863 * wpas_p2p_disconnect - Disconnect from a P2P Group
4864 * @wpa_s: Pointer to wpa_supplicant data
4865 * Returns: 0 on success, -1 on failure
4867 * This can be used to disconnect from a group in which the local end is a P2P
4868 * Client or to end a P2P Group in case the local end is the Group Owner. If a
4869 * virtual network interface was created for this group, that interface will be
4870 * removed. Otherwise, only the configured P2P group network will be removed
4871 * from the interface.
4873 int wpas_p2p_disconnect(struct wpa_supplicant
*wpa_s
)
4879 return wpas_p2p_group_delete(wpa_s
, P2P_GROUP_REMOVAL_REQUESTED
);
4883 int wpas_p2p_in_progress(struct wpa_supplicant
*wpa_s
)
4885 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
4888 return p2p_in_progress(wpa_s
->global
->p2p
);
4892 void wpas_p2p_network_removed(struct wpa_supplicant
*wpa_s
,
4893 struct wpa_ssid
*ssid
)
4895 if (wpa_s
->p2p_in_provisioning
&& ssid
->p2p_group
&&
4896 eloop_cancel_timeout(wpas_p2p_group_formation_timeout
,
4897 wpa_s
->parent
, NULL
) > 0) {
4899 * Remove the network by scheduling the group formation
4900 * timeout to happen immediately. The teardown code
4901 * needs to be scheduled to run asynch later so that we
4902 * don't delete data from under ourselves unexpectedly.
4903 * Calling wpas_p2p_group_formation_timeout directly
4904 * causes a series of crashes in WPS failure scenarios.
4906 wpa_printf(MSG_DEBUG
, "P2P: Canceled group formation due to "
4907 "P2P group network getting removed");
4908 eloop_register_timeout(0, 0, wpas_p2p_group_formation_timeout
,
4909 wpa_s
->parent
, NULL
);
4914 struct wpa_ssid
* wpas_p2p_get_persistent(struct wpa_supplicant
*wpa_s
,
4915 const u8
*addr
, const u8
*ssid
,
4921 for (s
= wpa_s
->conf
->ssid
; s
; s
= s
->next
) {
4922 if (s
->disabled
!= 2)
4925 (ssid_len
!= s
->ssid_len
||
4926 os_memcmp(ssid
, s
->ssid
, ssid_len
) != 0))
4928 if (os_memcmp(s
->bssid
, addr
, ETH_ALEN
) == 0)
4929 return s
; /* peer is GO in the persistent group */
4930 if (s
->mode
!= WPAS_MODE_P2P_GO
|| s
->p2p_client_list
== NULL
)
4932 for (i
= 0; i
< s
->num_p2p_clients
; i
++) {
4933 if (os_memcmp(s
->p2p_client_list
+ i
* ETH_ALEN
,
4934 addr
, ETH_ALEN
) == 0)
4935 return s
; /* peer is P2P client in persistent
4944 void wpas_p2p_notify_ap_sta_authorized(struct wpa_supplicant
*wpa_s
,
4949 wpas_p2p_add_persistent_group_client(wpa_s
, addr
);
4953 static void wpas_p2p_fallback_to_go_neg(struct wpa_supplicant
*wpa_s
,
4956 struct wpa_supplicant
*group
= wpa_s
;
4957 eloop_cancel_timeout(wpas_p2p_pd_before_join_timeout
, wpa_s
, NULL
);
4958 if (wpa_s
->global
->p2p_group_formation
)
4959 group
= wpa_s
->global
->p2p_group_formation
;
4960 wpa_s
= wpa_s
->parent
;
4961 offchannel_send_action_done(wpa_s
);
4963 wpas_p2p_group_delete(group
, P2P_GROUP_REMOVAL_SILENT
);
4964 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Fall back to GO Negotiation");
4965 wpas_p2p_connect(wpa_s
, wpa_s
->pending_join_dev_addr
, wpa_s
->p2p_pin
,
4966 wpa_s
->p2p_wps_method
, wpa_s
->p2p_persistent_group
, 0,
4967 0, 0, wpa_s
->p2p_go_intent
, wpa_s
->p2p_connect_freq
,
4968 wpa_s
->p2p_persistent_id
,
4969 wpa_s
->p2p_pd_before_go_neg
,
4970 wpa_s
->p2p_go_ht40
);
4974 int wpas_p2p_scan_no_go_seen(struct wpa_supplicant
*wpa_s
)
4976 if (!wpa_s
->p2p_fallback_to_go_neg
||
4977 wpa_s
->p2p_in_provisioning
<= 5)
4980 if (wpas_p2p_peer_go(wpa_s
, wpa_s
->pending_join_dev_addr
) > 0)
4981 return 0; /* peer operating as a GO */
4983 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: GO not found for p2p_connect-auto - "
4984 "fallback to GO Negotiation");
4985 wpas_p2p_fallback_to_go_neg(wpa_s
, 1);
4991 unsigned int wpas_p2p_search_delay(struct wpa_supplicant
*wpa_s
)
4993 const char *rn
, *rn2
;
4994 struct wpa_supplicant
*ifs
;
4996 if (wpa_s
->wpa_state
> WPA_SCANNING
) {
4997 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Use %u ms search delay due to "
4998 "concurrent operation",
4999 P2P_CONCURRENT_SEARCH_DELAY
);
5000 return P2P_CONCURRENT_SEARCH_DELAY
;
5003 if (!wpa_s
->driver
->get_radio_name
)
5005 rn
= wpa_s
->driver
->get_radio_name(wpa_s
->drv_priv
);
5006 if (rn
== NULL
|| rn
[0] == '\0')
5009 for (ifs
= wpa_s
->global
->ifaces
; ifs
; ifs
= ifs
->next
) {
5010 if (ifs
== wpa_s
|| !ifs
->driver
->get_radio_name
)
5013 rn2
= ifs
->driver
->get_radio_name(ifs
->drv_priv
);
5014 if (!rn2
|| os_strcmp(rn
, rn2
) != 0)
5016 if (ifs
->wpa_state
> WPA_SCANNING
) {
5017 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Use %u ms search "
5018 "delay due to concurrent operation on "
5020 P2P_CONCURRENT_SEARCH_DELAY
, ifs
->ifname
);
5021 return P2P_CONCURRENT_SEARCH_DELAY
;