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_supplicant
*ifs
;
125 struct wpa_driver_scan_params params
;
127 struct wpabuf
*wps_ie
, *ies
;
128 int social_channels
[] = { 2412, 2437, 2462, 0, 0 };
131 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
134 for (ifs
= wpa_s
->global
->ifaces
; ifs
; ifs
= ifs
->next
) {
135 if (ifs
->sta_scan_pending
&&
136 wpas_p2p_in_progress(wpa_s
) == 2) {
137 wpa_printf(MSG_DEBUG
, "Delaying P2P scan to allow "
138 "pending station mode scan to be "
139 "completed on interface %s", ifs
->ifname
);
140 wpa_s
->global
->p2p_cb_on_scan_complete
= 1;
141 wpa_supplicant_req_scan(ifs
, 0, 0);
146 os_memset(¶ms
, 0, sizeof(params
));
148 /* P2P Wildcard SSID */
149 params
.num_ssids
= 1;
150 params
.ssids
[0].ssid
= (u8
*) P2P_WILDCARD_SSID
;
151 params
.ssids
[0].ssid_len
= P2P_WILDCARD_SSID_LEN
;
153 wpa_s
->wps
->dev
.p2p
= 1;
154 wps_ie
= wps_build_probe_req_ie(pw_id
, &wpa_s
->wps
->dev
,
155 wpa_s
->wps
->uuid
, WPS_REQ_ENROLLEE
,
156 num_req_dev_types
, req_dev_types
);
160 ielen
= p2p_scan_ie_buf_len(wpa_s
->global
->p2p
);
161 ies
= wpabuf_alloc(wpabuf_len(wps_ie
) + ielen
);
166 wpabuf_put_buf(ies
, wps_ie
);
169 p2p_scan_ie(wpa_s
->global
->p2p
, ies
, dev_id
);
171 params
.p2p_probe
= 1;
172 params
.extra_ies
= wpabuf_head(ies
);
173 params
.extra_ies_len
= wpabuf_len(ies
);
176 case P2P_SCAN_SOCIAL
:
177 params
.freqs
= social_channels
;
181 case P2P_SCAN_SOCIAL_PLUS_ONE
:
182 social_channels
[3] = freq
;
183 params
.freqs
= social_channels
;
187 ret
= wpa_drv_scan(wpa_s
, ¶ms
);
192 for (ifs
= wpa_s
->global
->ifaces
; ifs
; ifs
= ifs
->next
) {
194 ifs
->scan_res_handler
== wpas_p2p_scan_res_handler
) {
195 wpa_s
->global
->p2p_cb_on_scan_complete
= 1;
201 wpa_s
->scan_res_handler
= wpas_p2p_scan_res_handler
;
207 static enum wpa_driver_if_type
wpas_p2p_if_type(int p2p_group_interface
)
209 switch (p2p_group_interface
) {
210 case P2P_GROUP_INTERFACE_PENDING
:
211 return WPA_IF_P2P_GROUP
;
212 case P2P_GROUP_INTERFACE_GO
:
213 return WPA_IF_P2P_GO
;
214 case P2P_GROUP_INTERFACE_CLIENT
:
215 return WPA_IF_P2P_CLIENT
;
218 return WPA_IF_P2P_GROUP
;
222 static struct wpa_supplicant
* wpas_get_p2p_group(struct wpa_supplicant
*wpa_s
,
224 size_t ssid_len
, int *go
)
228 for (wpa_s
= wpa_s
->global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
229 for (s
= wpa_s
->conf
->ssid
; s
; s
= s
->next
) {
230 if (s
->disabled
!= 0 || !s
->p2p_group
||
231 s
->ssid_len
!= ssid_len
||
232 os_memcmp(ssid
, s
->ssid
, ssid_len
) != 0)
234 if (s
->mode
== WPAS_MODE_P2P_GO
&&
235 s
!= wpa_s
->current_ssid
)
238 *go
= s
->mode
== WPAS_MODE_P2P_GO
;
247 static int wpas_p2p_group_delete(struct wpa_supplicant
*wpa_s
,
248 enum p2p_group_removal_reason removal_reason
)
250 struct wpa_ssid
*ssid
;
254 ssid
= wpa_s
->current_ssid
;
257 * The current SSID was not known, but there may still be a
258 * pending P2P group interface waiting for provisioning or a
259 * P2P group that is trying to reconnect.
261 ssid
= wpa_s
->conf
->ssid
;
263 if (ssid
->p2p_group
&& ssid
->disabled
!= 2)
268 wpa_s
->p2p_group_interface
== NOT_P2P_GROUP_INTERFACE
)
270 wpa_printf(MSG_ERROR
, "P2P: P2P group interface "
275 if (wpa_s
->p2p_group_interface
== P2P_GROUP_INTERFACE_GO
)
277 else if (wpa_s
->p2p_group_interface
== P2P_GROUP_INTERFACE_CLIENT
||
278 (ssid
&& ssid
->mode
== WPAS_MODE_INFRA
)) {
279 wpa_s
->reassociate
= 0;
280 wpa_s
->disconnected
= 1;
281 wpa_supplicant_deauthenticate(wpa_s
,
282 WLAN_REASON_DEAUTH_LEAVING
);
286 if (wpa_s
->cross_connect_in_use
) {
287 wpa_s
->cross_connect_in_use
= 0;
288 wpa_msg(wpa_s
->parent
, MSG_INFO
,
289 P2P_EVENT_CROSS_CONNECT_DISABLE
"%s %s",
290 wpa_s
->ifname
, wpa_s
->cross_connect_uplink
);
292 switch (removal_reason
) {
293 case P2P_GROUP_REMOVAL_REQUESTED
:
294 reason
= " reason=REQUESTED";
296 case P2P_GROUP_REMOVAL_FORMATION_FAILED
:
297 reason
= " reason=FORMATION_FAILED";
299 case P2P_GROUP_REMOVAL_IDLE_TIMEOUT
:
300 reason
= " reason=IDLE";
302 case P2P_GROUP_REMOVAL_UNAVAILABLE
:
303 reason
= " reason=UNAVAILABLE";
305 case P2P_GROUP_REMOVAL_GO_ENDING_SESSION
:
306 reason
= " reason=GO_ENDING_SESSION";
312 if (removal_reason
!= P2P_GROUP_REMOVAL_SILENT
) {
313 wpa_msg(wpa_s
->parent
, MSG_INFO
,
314 P2P_EVENT_GROUP_REMOVED
"%s %s%s",
315 wpa_s
->ifname
, gtype
, reason
);
318 if (eloop_cancel_timeout(wpas_p2p_group_idle_timeout
, wpa_s
, NULL
) > 0)
319 wpa_printf(MSG_DEBUG
, "P2P: Cancelled P2P group idle timeout");
321 if (removal_reason
!= P2P_GROUP_REMOVAL_SILENT
&& ssid
)
322 wpas_notify_p2p_group_removed(wpa_s
, ssid
, gtype
);
324 if (wpa_s
->p2p_group_interface
!= NOT_P2P_GROUP_INTERFACE
) {
325 struct wpa_global
*global
;
327 enum wpa_driver_if_type type
;
328 wpa_printf(MSG_DEBUG
, "P2P: Remove group interface %s",
330 global
= wpa_s
->global
;
331 ifname
= os_strdup(wpa_s
->ifname
);
332 type
= wpas_p2p_if_type(wpa_s
->p2p_group_interface
);
333 wpa_supplicant_remove_iface(wpa_s
->global
, wpa_s
, 0);
334 wpa_s
= global
->ifaces
;
336 wpa_drv_if_remove(wpa_s
, type
, ifname
);
341 wpa_printf(MSG_DEBUG
, "P2P: Remove temporary group network");
342 if (ssid
&& (ssid
->p2p_group
||
343 ssid
->mode
== WPAS_MODE_P2P_GROUP_FORMATION
||
344 (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
))) {
346 if (ssid
== wpa_s
->current_ssid
) {
347 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
348 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
349 wpa_s
->current_ssid
= NULL
;
352 * Networks objects created during any P2P activities are not
353 * exposed out as they might/will confuse certain non-P2P aware
354 * applications since these network objects won't behave like
357 * Likewise, we don't send out network removed signals for such
360 wpa_config_remove_network(wpa_s
->conf
, id
);
361 wpa_supplicant_clear_status(wpa_s
);
362 wpa_supplicant_cancel_sched_scan(wpa_s
);
363 wpa_s
->sta_scan_pending
= 0;
365 wpa_printf(MSG_DEBUG
, "P2P: Temporary group network not "
369 wpa_supplicant_ap_deinit(wpa_s
);
371 wpa_drv_deinit_p2p_cli(wpa_s
);
377 static int wpas_p2p_persistent_group(struct wpa_supplicant
*wpa_s
,
379 const u8
*ssid
, size_t ssid_len
)
387 if (wpa_s
->go_params
)
388 bssid
= wpa_s
->go_params
->peer_interface_addr
;
390 bssid
= wpa_s
->bssid
;
392 bss
= wpa_bss_get(wpa_s
, bssid
, ssid
, ssid_len
);
394 u8 iface_addr
[ETH_ALEN
];
395 if (p2p_get_interface_addr(wpa_s
->global
->p2p
, bssid
,
397 bss
= wpa_bss_get(wpa_s
, iface_addr
, ssid
, ssid_len
);
400 wpa_printf(MSG_DEBUG
, "P2P: Could not figure out whether "
401 "group is persistent - BSS " MACSTR
" not found",
406 p2p
= wpa_bss_get_vendor_ie_multi(bss
, P2P_IE_VENDOR_TYPE
);
408 wpa_printf(MSG_DEBUG
, "P2P: Could not figure out whether "
409 "group is persistent - BSS " MACSTR
410 " did not include P2P IE", MAC2STR(bssid
));
411 wpa_hexdump(MSG_DEBUG
, "P2P: Probe Response IEs",
412 (u8
*) (bss
+ 1), bss
->ie_len
);
413 wpa_hexdump(MSG_DEBUG
, "P2P: Beacon IEs",
414 ((u8
*) bss
+ 1) + bss
->ie_len
,
419 group_capab
= p2p_get_group_capab(p2p
);
420 addr
= p2p_get_go_dev_addr(p2p
);
421 wpa_printf(MSG_DEBUG
, "P2P: Checking whether group is persistent: "
422 "group_capab=0x%x", group_capab
);
424 os_memcpy(go_dev_addr
, addr
, ETH_ALEN
);
425 wpa_printf(MSG_DEBUG
, "P2P: GO Device Address " MACSTR
,
428 os_memset(go_dev_addr
, 0, ETH_ALEN
);
431 wpa_printf(MSG_DEBUG
, "P2P: BSS " MACSTR
" group_capab=0x%x "
432 "go_dev_addr=" MACSTR
,
433 MAC2STR(bssid
), group_capab
, MAC2STR(go_dev_addr
));
435 return group_capab
& P2P_GROUP_CAPAB_PERSISTENT_GROUP
;
439 static int wpas_p2p_store_persistent_group(struct wpa_supplicant
*wpa_s
,
440 struct wpa_ssid
*ssid
,
441 const u8
*go_dev_addr
)
446 wpa_printf(MSG_DEBUG
, "P2P: Storing credentials for a persistent "
447 "group (GO Dev Addr " MACSTR
")", MAC2STR(go_dev_addr
));
448 for (s
= wpa_s
->conf
->ssid
; s
; s
= s
->next
) {
449 if (s
->disabled
== 2 &&
450 os_memcmp(go_dev_addr
, s
->bssid
, ETH_ALEN
) == 0 &&
451 s
->ssid_len
== ssid
->ssid_len
&&
452 os_memcmp(ssid
->ssid
, s
->ssid
, ssid
->ssid_len
) == 0)
457 wpa_printf(MSG_DEBUG
, "P2P: Update existing persistent group "
459 if (ssid
->passphrase
&& !s
->passphrase
)
461 else if (ssid
->passphrase
&& s
->passphrase
&&
462 os_strcmp(ssid
->passphrase
, s
->passphrase
) != 0)
465 wpa_printf(MSG_DEBUG
, "P2P: Create a new persistent group "
468 s
= wpa_config_add_network(wpa_s
->conf
);
473 * Instead of network_added we emit persistent_group_added
474 * notification. Also to keep the defense checks in
475 * persistent_group obj registration method, we set the
476 * relevant flags in s to designate it as a persistent group.
479 s
->p2p_persistent_group
= 1;
480 wpas_notify_persistent_group_added(wpa_s
, s
);
481 wpa_config_set_network_defaults(s
);
485 s
->p2p_persistent_group
= 1;
488 os_memcpy(s
->bssid
, go_dev_addr
, ETH_ALEN
);
489 s
->mode
= ssid
->mode
;
490 s
->auth_alg
= WPA_AUTH_ALG_OPEN
;
491 s
->key_mgmt
= WPA_KEY_MGMT_PSK
;
492 s
->proto
= WPA_PROTO_RSN
;
493 s
->pairwise_cipher
= WPA_CIPHER_CCMP
;
495 if (ssid
->passphrase
) {
496 os_free(s
->passphrase
);
497 s
->passphrase
= os_strdup(ssid
->passphrase
);
501 os_memcpy(s
->psk
, ssid
->psk
, 32);
503 if (s
->passphrase
&& !s
->psk_set
)
504 wpa_config_update_psk(s
);
505 if (s
->ssid
== NULL
|| s
->ssid_len
< ssid
->ssid_len
) {
507 s
->ssid
= os_malloc(ssid
->ssid_len
);
510 s
->ssid_len
= ssid
->ssid_len
;
511 os_memcpy(s
->ssid
, ssid
->ssid
, s
->ssid_len
);
514 #ifndef CONFIG_NO_CONFIG_WRITE
515 if (changed
&& wpa_s
->conf
->update_config
&&
516 wpa_config_write(wpa_s
->confname
, wpa_s
->conf
)) {
517 wpa_printf(MSG_DEBUG
, "P2P: Failed to update configuration");
519 #endif /* CONFIG_NO_CONFIG_WRITE */
525 static void wpas_p2p_add_persistent_group_client(struct wpa_supplicant
*wpa_s
,
528 struct wpa_ssid
*ssid
, *s
;
533 ssid
= wpa_s
->current_ssid
;
534 if (ssid
== NULL
|| ssid
->mode
!= WPAS_MODE_P2P_GO
||
535 !ssid
->p2p_persistent_group
)
538 for (s
= wpa_s
->parent
->conf
->ssid
; s
; s
= s
->next
) {
539 if (s
->disabled
!= 2 || s
->mode
!= WPAS_MODE_P2P_GO
)
542 if (s
->ssid_len
== ssid
->ssid_len
&&
543 os_memcmp(s
->ssid
, ssid
->ssid
, s
->ssid_len
) == 0)
550 for (i
= 0; s
->p2p_client_list
&& i
< s
->num_p2p_clients
; i
++) {
551 if (os_memcmp(s
->p2p_client_list
+ i
* ETH_ALEN
, addr
,
555 if (i
== s
->num_p2p_clients
- 1)
556 return; /* already the most recent entry */
558 /* move the entry to mark it most recent */
559 os_memmove(s
->p2p_client_list
+ i
* ETH_ALEN
,
560 s
->p2p_client_list
+ (i
+ 1) * ETH_ALEN
,
561 (s
->num_p2p_clients
- i
- 1) * ETH_ALEN
);
562 os_memcpy(s
->p2p_client_list
+
563 (s
->num_p2p_clients
- 1) * ETH_ALEN
, addr
, ETH_ALEN
);
568 if (!found
&& s
->num_p2p_clients
< P2P_MAX_STORED_CLIENTS
) {
569 n
= os_realloc_array(s
->p2p_client_list
,
570 s
->num_p2p_clients
+ 1, ETH_ALEN
);
573 os_memcpy(n
+ s
->num_p2p_clients
* ETH_ALEN
, addr
, ETH_ALEN
);
574 s
->p2p_client_list
= n
;
575 s
->num_p2p_clients
++;
577 /* Not enough room for an additional entry - drop the oldest
579 os_memmove(s
->p2p_client_list
,
580 s
->p2p_client_list
+ ETH_ALEN
,
581 (s
->num_p2p_clients
- 1) * ETH_ALEN
);
582 os_memcpy(s
->p2p_client_list
+
583 (s
->num_p2p_clients
- 1) * ETH_ALEN
,
587 #ifndef CONFIG_NO_CONFIG_WRITE
588 if (wpa_s
->parent
->conf
->update_config
&&
589 wpa_config_write(wpa_s
->parent
->confname
, wpa_s
->parent
->conf
))
590 wpa_printf(MSG_DEBUG
, "P2P: Failed to update configuration");
591 #endif /* CONFIG_NO_CONFIG_WRITE */
595 static void wpas_group_formation_completed(struct wpa_supplicant
*wpa_s
,
598 struct wpa_ssid
*ssid
;
599 const char *ssid_txt
;
602 u8 go_dev_addr
[ETH_ALEN
];
606 * This callback is likely called for the main interface. Update wpa_s
607 * to use the group interface if a new interface was created for the
610 if (wpa_s
->global
->p2p_group_formation
)
611 wpa_s
= wpa_s
->global
->p2p_group_formation
;
612 wpa_s
->global
->p2p_group_formation
= NULL
;
613 wpa_s
->p2p_in_provisioning
= 0;
616 wpa_msg(wpa_s
->parent
, MSG_INFO
,
617 P2P_EVENT_GROUP_FORMATION_FAILURE
);
618 wpas_p2p_group_delete(wpa_s
,
619 P2P_GROUP_REMOVAL_FORMATION_FAILED
);
623 wpa_msg(wpa_s
->parent
, MSG_INFO
, P2P_EVENT_GROUP_FORMATION_SUCCESS
);
625 ssid
= wpa_s
->current_ssid
;
626 if (ssid
&& ssid
->mode
== WPAS_MODE_P2P_GROUP_FORMATION
) {
627 ssid
->mode
= WPAS_MODE_P2P_GO
;
628 p2p_group_notif_formation_done(wpa_s
->p2p_group
);
629 wpa_supplicant_ap_mac_addr_filter(wpa_s
, NULL
);
634 ssid_txt
= wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
);
635 client
= ssid
->mode
== WPAS_MODE_INFRA
;
636 if (ssid
->mode
== WPAS_MODE_P2P_GO
) {
637 persistent
= ssid
->p2p_persistent_group
;
638 os_memcpy(go_dev_addr
, wpa_s
->global
->p2p_dev_addr
,
641 persistent
= wpas_p2p_persistent_group(wpa_s
,
647 client
= wpa_s
->p2p_group_interface
==
648 P2P_GROUP_INTERFACE_CLIENT
;
649 os_memset(go_dev_addr
, 0, ETH_ALEN
);
652 wpa_s
->show_group_started
= 0;
655 * Indicate event only after successfully completed 4-way
656 * handshake, i.e., when the interface is ready for data
659 wpa_s
->show_group_started
= 1;
660 } else if (ssid
&& ssid
->passphrase
== NULL
&& ssid
->psk_set
) {
662 wpa_snprintf_hex(psk
, sizeof(psk
), ssid
->psk
, 32);
663 wpa_msg(wpa_s
->parent
, MSG_INFO
, P2P_EVENT_GROUP_STARTED
664 "%s GO ssid=\"%s\" freq=%d psk=%s go_dev_addr=" MACSTR
666 wpa_s
->ifname
, ssid_txt
, ssid
->frequency
, psk
,
667 MAC2STR(go_dev_addr
),
668 persistent
? " [PERSISTENT]" : "");
669 wpas_p2p_cross_connect_setup(wpa_s
);
670 wpas_p2p_set_group_idle_timeout(wpa_s
);
672 wpa_msg(wpa_s
->parent
, MSG_INFO
, P2P_EVENT_GROUP_STARTED
673 "%s GO ssid=\"%s\" freq=%d passphrase=\"%s\" "
674 "go_dev_addr=" MACSTR
"%s",
675 wpa_s
->ifname
, ssid_txt
, ssid
? ssid
->frequency
: 0,
676 ssid
&& ssid
->passphrase
? ssid
->passphrase
: "",
677 MAC2STR(go_dev_addr
),
678 persistent
? " [PERSISTENT]" : "");
679 wpas_p2p_cross_connect_setup(wpa_s
);
680 wpas_p2p_set_group_idle_timeout(wpa_s
);
684 network_id
= wpas_p2p_store_persistent_group(wpa_s
->parent
,
686 if (network_id
< 0 && ssid
)
687 network_id
= ssid
->id
;
689 wpas_notify_p2p_group_started(wpa_s
, ssid
, network_id
, 0);
693 static void wpas_p2p_send_action_tx_status(struct wpa_supplicant
*wpa_s
,
695 const u8
*dst
, const u8
*src
,
697 const u8
*data
, size_t data_len
,
698 enum offchannel_send_action_result
701 enum p2p_send_action_result res
= P2P_SEND_ACTION_SUCCESS
;
703 if (wpa_s
->global
->p2p
== NULL
|| wpa_s
->global
->p2p_disabled
)
705 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
)
709 case OFFCHANNEL_SEND_ACTION_SUCCESS
:
710 res
= P2P_SEND_ACTION_SUCCESS
;
712 case OFFCHANNEL_SEND_ACTION_NO_ACK
:
713 res
= P2P_SEND_ACTION_NO_ACK
;
715 case OFFCHANNEL_SEND_ACTION_FAILED
:
716 res
= P2P_SEND_ACTION_FAILED
;
720 p2p_send_action_cb(wpa_s
->global
->p2p
, freq
, dst
, src
, bssid
, res
);
722 if (result
!= OFFCHANNEL_SEND_ACTION_SUCCESS
&&
723 wpa_s
->pending_pd_before_join
&&
724 (os_memcmp(dst
, wpa_s
->pending_join_dev_addr
, ETH_ALEN
) == 0 ||
725 os_memcmp(dst
, wpa_s
->pending_join_iface_addr
, ETH_ALEN
) == 0)) {
726 wpa_s
->pending_pd_before_join
= 0;
727 if (wpa_s
->p2p_fallback_to_go_neg
) {
728 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: No ACK for PD Req "
729 "during p2p_connect-auto");
730 wpas_p2p_fallback_to_go_neg(wpa_s
, 0);
734 wpa_printf(MSG_DEBUG
, "P2P: Starting pending "
735 "join-existing-group operation (no ACK for PD "
737 wpas_p2p_join_start(wpa_s
);
742 static int wpas_send_action(void *ctx
, unsigned int freq
, const u8
*dst
,
743 const u8
*src
, const u8
*bssid
, const u8
*buf
,
744 size_t len
, unsigned int wait_time
)
746 struct wpa_supplicant
*wpa_s
= ctx
;
747 return offchannel_send_action(wpa_s
, freq
, dst
, src
, bssid
, buf
, len
,
749 wpas_p2p_send_action_tx_status
, 1);
753 static void wpas_send_action_done(void *ctx
)
755 struct wpa_supplicant
*wpa_s
= ctx
;
756 offchannel_send_action_done(wpa_s
);
760 static int wpas_copy_go_neg_results(struct wpa_supplicant
*wpa_s
,
761 struct p2p_go_neg_results
*params
)
763 if (wpa_s
->go_params
== NULL
) {
764 wpa_s
->go_params
= os_malloc(sizeof(*params
));
765 if (wpa_s
->go_params
== NULL
)
768 os_memcpy(wpa_s
->go_params
, params
, sizeof(*params
));
773 static void wpas_start_wps_enrollee(struct wpa_supplicant
*wpa_s
,
774 struct p2p_go_neg_results
*res
)
776 wpa_printf(MSG_DEBUG
, "P2P: Start WPS Enrollee for peer " MACSTR
,
777 MAC2STR(res
->peer_interface_addr
));
778 wpa_hexdump_ascii(MSG_DEBUG
, "P2P: Start WPS Enrollee for SSID",
779 res
->ssid
, res
->ssid_len
);
780 wpa_supplicant_ap_deinit(wpa_s
);
781 wpas_copy_go_neg_results(wpa_s
, res
);
782 if (res
->wps_method
== WPS_PBC
)
783 wpas_wps_start_pbc(wpa_s
, res
->peer_interface_addr
, 1);
785 u16 dev_pw_id
= DEV_PW_DEFAULT
;
786 if (wpa_s
->p2p_wps_method
== WPS_PIN_KEYPAD
)
787 dev_pw_id
= DEV_PW_REGISTRAR_SPECIFIED
;
788 wpas_wps_start_pin(wpa_s
, res
->peer_interface_addr
,
789 wpa_s
->p2p_pin
, 1, dev_pw_id
);
794 static void p2p_go_configured(void *ctx
, void *data
)
796 struct wpa_supplicant
*wpa_s
= ctx
;
797 struct p2p_go_neg_results
*params
= data
;
798 struct wpa_ssid
*ssid
;
801 ssid
= wpa_s
->current_ssid
;
802 if (ssid
&& ssid
->mode
== WPAS_MODE_P2P_GO
) {
803 wpa_printf(MSG_DEBUG
, "P2P: Group setup without provisioning");
804 if (wpa_s
->global
->p2p_group_formation
== wpa_s
)
805 wpa_s
->global
->p2p_group_formation
= NULL
;
806 wpa_msg(wpa_s
->parent
, MSG_INFO
, P2P_EVENT_GROUP_STARTED
807 "%s GO ssid=\"%s\" freq=%d passphrase=\"%s\" "
808 "go_dev_addr=" MACSTR
"%s",
810 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
),
812 params
->passphrase
? params
->passphrase
: "",
813 MAC2STR(wpa_s
->global
->p2p_dev_addr
),
814 params
->persistent_group
? " [PERSISTENT]" : "");
816 if (params
->persistent_group
)
817 network_id
= wpas_p2p_store_persistent_group(
819 wpa_s
->global
->p2p_dev_addr
);
821 network_id
= ssid
->id
;
822 wpas_notify_p2p_group_started(wpa_s
, ssid
, network_id
, 0);
823 wpas_p2p_cross_connect_setup(wpa_s
);
824 wpas_p2p_set_group_idle_timeout(wpa_s
);
828 wpa_printf(MSG_DEBUG
, "P2P: Setting up WPS for GO provisioning");
829 if (wpa_supplicant_ap_mac_addr_filter(wpa_s
,
830 params
->peer_interface_addr
)) {
831 wpa_printf(MSG_DEBUG
, "P2P: Failed to setup MAC address "
835 if (params
->wps_method
== WPS_PBC
)
836 wpa_supplicant_ap_wps_pbc(wpa_s
, params
->peer_interface_addr
,
837 params
->peer_device_addr
);
838 else if (wpa_s
->p2p_pin
[0])
839 wpa_supplicant_ap_wps_pin(wpa_s
, params
->peer_interface_addr
,
840 wpa_s
->p2p_pin
, NULL
, 0, 0);
841 os_free(wpa_s
->go_params
);
842 wpa_s
->go_params
= NULL
;
846 static void wpas_start_wps_go(struct wpa_supplicant
*wpa_s
,
847 struct p2p_go_neg_results
*params
,
850 struct wpa_ssid
*ssid
;
852 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Starting GO");
853 if (wpas_copy_go_neg_results(wpa_s
, params
) < 0) {
854 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Could not copy GO Negotiation "
859 ssid
= wpa_config_add_network(wpa_s
->conf
);
861 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Could not add network for GO");
865 wpa_s
->show_group_started
= 0;
867 wpa_config_set_network_defaults(ssid
);
870 ssid
->p2p_persistent_group
= params
->persistent_group
;
871 ssid
->mode
= group_formation
? WPAS_MODE_P2P_GROUP_FORMATION
:
873 ssid
->frequency
= params
->freq
;
874 ssid
->ht40
= params
->ht40
;
875 ssid
->ssid
= os_zalloc(params
->ssid_len
+ 1);
877 os_memcpy(ssid
->ssid
, params
->ssid
, params
->ssid_len
);
878 ssid
->ssid_len
= params
->ssid_len
;
880 ssid
->auth_alg
= WPA_AUTH_ALG_OPEN
;
881 ssid
->key_mgmt
= WPA_KEY_MGMT_PSK
;
882 ssid
->proto
= WPA_PROTO_RSN
;
883 ssid
->pairwise_cipher
= WPA_CIPHER_CCMP
;
884 ssid
->passphrase
= os_strdup(params
->passphrase
);
885 if (ssid
->passphrase
== NULL
) {
886 wpa_msg(wpa_s
, MSG_ERROR
, "P2P: Failed to copy passphrase for "
888 wpa_config_remove_network(wpa_s
->conf
, ssid
->id
);
891 wpa_config_update_psk(ssid
);
892 ssid
->ap_max_inactivity
= wpa_s
->parent
->conf
->p2p_go_max_inactivity
;
894 wpa_s
->ap_configured_cb
= p2p_go_configured
;
895 wpa_s
->ap_configured_cb_ctx
= wpa_s
;
896 wpa_s
->ap_configured_cb_data
= wpa_s
->go_params
;
897 wpa_s
->connect_without_scan
= ssid
;
898 wpa_s
->reassociate
= 1;
899 wpa_s
->disconnected
= 0;
900 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Request scan (that will be skipped) to "
902 wpa_supplicant_req_scan(wpa_s
, 0, 0);
906 static void wpas_p2p_clone_config(struct wpa_supplicant
*dst
,
907 const struct wpa_supplicant
*src
)
909 struct wpa_config
*d
;
910 const struct wpa_config
*s
;
915 #define C(n) if (s->n) d->n = os_strdup(s->n)
924 os_memcpy(d
->device_type
, s
->device_type
, WPS_DEV_TYPE_LEN
);
925 os_memcpy(d
->sec_device_type
, s
->sec_device_type
,
926 sizeof(d
->sec_device_type
));
927 d
->num_sec_device_types
= s
->num_sec_device_types
;
929 d
->p2p_group_idle
= s
->p2p_group_idle
;
930 d
->p2p_intra_bss
= s
->p2p_intra_bss
;
931 d
->persistent_reconnect
= s
->persistent_reconnect
;
932 d
->max_num_sta
= s
->max_num_sta
;
933 d
->pbc_in_m1
= s
->pbc_in_m1
;
937 static int wpas_p2p_add_group_interface(struct wpa_supplicant
*wpa_s
,
938 enum wpa_driver_if_type type
)
940 char ifname
[120], force_ifname
[120];
942 if (wpa_s
->pending_interface_name
[0]) {
943 wpa_printf(MSG_DEBUG
, "P2P: Pending virtual interface exists "
944 "- skip creation of a new one");
945 if (is_zero_ether_addr(wpa_s
->pending_interface_addr
)) {
946 wpa_printf(MSG_DEBUG
, "P2P: Pending virtual address "
947 "unknown?! ifname='%s'",
948 wpa_s
->pending_interface_name
);
954 os_snprintf(ifname
, sizeof(ifname
), "p2p-%s-%d", wpa_s
->ifname
,
955 wpa_s
->p2p_group_idx
);
956 if (os_strlen(ifname
) >= IFNAMSIZ
&&
957 os_strlen(wpa_s
->ifname
) < IFNAMSIZ
) {
958 /* Try to avoid going over the IFNAMSIZ length limit */
959 os_snprintf(ifname
, sizeof(ifname
), "p2p-%d",
960 wpa_s
->p2p_group_idx
);
962 force_ifname
[0] = '\0';
964 wpa_printf(MSG_DEBUG
, "P2P: Create a new interface %s for the group",
966 wpa_s
->p2p_group_idx
++;
968 wpa_s
->pending_interface_type
= type
;
969 if (wpa_drv_if_add(wpa_s
, type
, ifname
, NULL
, NULL
, force_ifname
,
970 wpa_s
->pending_interface_addr
, NULL
) < 0) {
971 wpa_printf(MSG_ERROR
, "P2P: Failed to create new group "
976 if (force_ifname
[0]) {
977 wpa_printf(MSG_DEBUG
, "P2P: Driver forced interface name %s",
979 os_strlcpy(wpa_s
->pending_interface_name
, force_ifname
,
980 sizeof(wpa_s
->pending_interface_name
));
982 os_strlcpy(wpa_s
->pending_interface_name
, ifname
,
983 sizeof(wpa_s
->pending_interface_name
));
984 wpa_printf(MSG_DEBUG
, "P2P: Created pending virtual interface %s addr "
985 MACSTR
, wpa_s
->pending_interface_name
,
986 MAC2STR(wpa_s
->pending_interface_addr
));
992 static void wpas_p2p_remove_pending_group_interface(
993 struct wpa_supplicant
*wpa_s
)
995 if (!wpa_s
->pending_interface_name
[0] ||
996 is_zero_ether_addr(wpa_s
->pending_interface_addr
))
997 return; /* No pending virtual interface */
999 wpa_printf(MSG_DEBUG
, "P2P: Removing pending group interface %s",
1000 wpa_s
->pending_interface_name
);
1001 wpa_drv_if_remove(wpa_s
, wpa_s
->pending_interface_type
,
1002 wpa_s
->pending_interface_name
);
1003 os_memset(wpa_s
->pending_interface_addr
, 0, ETH_ALEN
);
1004 wpa_s
->pending_interface_name
[0] = '\0';
1008 static struct wpa_supplicant
*
1009 wpas_p2p_init_group_interface(struct wpa_supplicant
*wpa_s
, int go
)
1011 struct wpa_interface iface
;
1012 struct wpa_supplicant
*group_wpa_s
;
1014 if (!wpa_s
->pending_interface_name
[0]) {
1015 wpa_printf(MSG_ERROR
, "P2P: No pending group interface");
1016 if (!wpas_p2p_create_iface(wpa_s
))
1019 * Something has forced us to remove the pending interface; try
1020 * to create a new one and hope for the best that we will get
1021 * the same local address.
1023 if (wpas_p2p_add_group_interface(wpa_s
, go
? WPA_IF_P2P_GO
:
1024 WPA_IF_P2P_CLIENT
) < 0)
1028 os_memset(&iface
, 0, sizeof(iface
));
1029 iface
.ifname
= wpa_s
->pending_interface_name
;
1030 iface
.driver
= wpa_s
->driver
->name
;
1031 iface
.ctrl_interface
= wpa_s
->conf
->ctrl_interface
;
1032 iface
.driver_param
= wpa_s
->conf
->driver_param
;
1033 group_wpa_s
= wpa_supplicant_add_iface(wpa_s
->global
, &iface
);
1034 if (group_wpa_s
== NULL
) {
1035 wpa_printf(MSG_ERROR
, "P2P: Failed to create new "
1036 "wpa_supplicant interface");
1039 wpa_s
->pending_interface_name
[0] = '\0';
1040 group_wpa_s
->parent
= wpa_s
;
1041 group_wpa_s
->p2p_group_interface
= go
? P2P_GROUP_INTERFACE_GO
:
1042 P2P_GROUP_INTERFACE_CLIENT
;
1043 wpa_s
->global
->p2p_group_formation
= group_wpa_s
;
1045 wpas_p2p_clone_config(group_wpa_s
, wpa_s
);
1051 static void wpas_p2p_group_formation_timeout(void *eloop_ctx
,
1054 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
1055 wpa_printf(MSG_DEBUG
, "P2P: Group Formation timed out");
1056 if (wpa_s
->global
->p2p
)
1057 p2p_group_formation_failed(wpa_s
->global
->p2p
);
1058 else if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
)
1059 wpa_drv_p2p_group_formation_failed(wpa_s
);
1060 wpas_group_formation_completed(wpa_s
, 0);
1064 void wpas_go_neg_completed(void *ctx
, struct p2p_go_neg_results
*res
)
1066 struct wpa_supplicant
*wpa_s
= ctx
;
1068 if (wpa_s
->off_channel_freq
|| wpa_s
->roc_waiting_drv_freq
) {
1069 wpa_drv_cancel_remain_on_channel(wpa_s
);
1070 wpa_s
->off_channel_freq
= 0;
1071 wpa_s
->roc_waiting_drv_freq
= 0;
1075 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_GO_NEG_FAILURE
"status=%d",
1077 wpas_notify_p2p_go_neg_completed(wpa_s
, res
);
1078 wpas_p2p_remove_pending_group_interface(wpa_s
);
1082 if (wpa_s
->p2p_go_ht40
)
1085 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_GO_NEG_SUCCESS
);
1086 wpas_notify_p2p_go_neg_completed(wpa_s
, res
);
1088 if (res
->role_go
&& wpa_s
->p2p_persistent_id
>= 0) {
1089 struct wpa_ssid
*ssid
;
1090 ssid
= wpa_config_get_network(wpa_s
->conf
,
1091 wpa_s
->p2p_persistent_id
);
1092 if (ssid
&& ssid
->disabled
== 2 &&
1093 ssid
->mode
== WPAS_MODE_P2P_GO
&& ssid
->passphrase
) {
1094 size_t len
= os_strlen(ssid
->passphrase
);
1095 wpa_printf(MSG_DEBUG
, "P2P: Override passphrase based "
1096 "on requested persistent group");
1097 os_memcpy(res
->passphrase
, ssid
->passphrase
, len
);
1098 res
->passphrase
[len
] = '\0';
1102 if (wpa_s
->create_p2p_iface
) {
1103 struct wpa_supplicant
*group_wpa_s
=
1104 wpas_p2p_init_group_interface(wpa_s
, res
->role_go
);
1105 if (group_wpa_s
== NULL
) {
1106 wpas_p2p_remove_pending_group_interface(wpa_s
);
1109 if (group_wpa_s
!= wpa_s
) {
1110 os_memcpy(group_wpa_s
->p2p_pin
, wpa_s
->p2p_pin
,
1111 sizeof(group_wpa_s
->p2p_pin
));
1112 group_wpa_s
->p2p_wps_method
= wpa_s
->p2p_wps_method
;
1114 os_memset(wpa_s
->pending_interface_addr
, 0, ETH_ALEN
);
1115 wpa_s
->pending_interface_name
[0] = '\0';
1116 group_wpa_s
->p2p_in_provisioning
= 1;
1119 wpas_start_wps_go(group_wpa_s
, res
, 1);
1121 wpas_start_wps_enrollee(group_wpa_s
, res
);
1123 wpa_s
->p2p_in_provisioning
= 1;
1124 wpa_s
->global
->p2p_group_formation
= wpa_s
;
1127 wpas_start_wps_go(wpa_s
, res
, 1);
1129 wpas_start_wps_enrollee(ctx
, res
);
1132 wpa_s
->p2p_long_listen
= 0;
1133 eloop_cancel_timeout(wpas_p2p_long_listen_timeout
, wpa_s
, NULL
);
1135 eloop_cancel_timeout(wpas_p2p_group_formation_timeout
, wpa_s
, NULL
);
1136 eloop_register_timeout(15 + res
->peer_config_timeout
/ 100,
1137 (res
->peer_config_timeout
% 100) * 10000,
1138 wpas_p2p_group_formation_timeout
, wpa_s
, NULL
);
1142 void wpas_go_neg_req_rx(void *ctx
, const u8
*src
, u16 dev_passwd_id
)
1144 struct wpa_supplicant
*wpa_s
= ctx
;
1145 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_GO_NEG_REQUEST MACSTR
1146 " dev_passwd_id=%u", MAC2STR(src
), dev_passwd_id
);
1148 wpas_notify_p2p_go_neg_req(wpa_s
, src
, dev_passwd_id
);
1152 void wpas_dev_found(void *ctx
, const u8
*addr
,
1153 const struct p2p_peer_info
*info
,
1156 #ifndef CONFIG_NO_STDOUT_DEBUG
1157 struct wpa_supplicant
*wpa_s
= ctx
;
1158 char devtype
[WPS_DEV_TYPE_BUFSIZE
];
1160 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_DEVICE_FOUND MACSTR
1161 " p2p_dev_addr=" MACSTR
1162 " pri_dev_type=%s name='%s' config_methods=0x%x "
1163 "dev_capab=0x%x group_capab=0x%x",
1164 MAC2STR(addr
), MAC2STR(info
->p2p_device_addr
),
1165 wps_dev_type_bin2str(info
->pri_dev_type
, devtype
,
1167 info
->device_name
, info
->config_methods
,
1168 info
->dev_capab
, info
->group_capab
);
1169 #endif /* CONFIG_NO_STDOUT_DEBUG */
1171 wpas_notify_p2p_device_found(ctx
, info
->p2p_device_addr
, new_device
);
1175 static void wpas_dev_lost(void *ctx
, const u8
*dev_addr
)
1177 struct wpa_supplicant
*wpa_s
= ctx
;
1179 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_DEVICE_LOST
1180 "p2p_dev_addr=" MACSTR
, MAC2STR(dev_addr
));
1182 wpas_notify_p2p_device_lost(wpa_s
, dev_addr
);
1186 static int wpas_start_listen(void *ctx
, unsigned int freq
,
1187 unsigned int duration
,
1188 const struct wpabuf
*probe_resp_ie
)
1190 struct wpa_supplicant
*wpa_s
= ctx
;
1192 wpa_drv_set_ap_wps_ie(wpa_s
, NULL
, probe_resp_ie
, NULL
);
1194 if (wpa_drv_probe_req_report(wpa_s
, 1) < 0) {
1195 wpa_printf(MSG_DEBUG
, "P2P: Failed to request the driver to "
1196 "report received Probe Request frames");
1200 wpa_s
->pending_listen_freq
= freq
;
1201 wpa_s
->pending_listen_duration
= duration
;
1203 if (wpa_drv_remain_on_channel(wpa_s
, freq
, duration
) < 0) {
1204 wpa_printf(MSG_DEBUG
, "P2P: Failed to request the driver "
1205 "to remain on channel (%u MHz) for Listen "
1207 wpa_s
->pending_listen_freq
= 0;
1210 wpa_s
->off_channel_freq
= 0;
1211 wpa_s
->roc_waiting_drv_freq
= freq
;
1217 static void wpas_stop_listen(void *ctx
)
1219 struct wpa_supplicant
*wpa_s
= ctx
;
1220 if (wpa_s
->off_channel_freq
|| wpa_s
->roc_waiting_drv_freq
) {
1221 wpa_drv_cancel_remain_on_channel(wpa_s
);
1222 wpa_s
->off_channel_freq
= 0;
1223 wpa_s
->roc_waiting_drv_freq
= 0;
1225 wpa_drv_set_ap_wps_ie(wpa_s
, NULL
, NULL
, NULL
);
1226 wpa_drv_probe_req_report(wpa_s
, 0);
1230 static int wpas_send_probe_resp(void *ctx
, const struct wpabuf
*buf
)
1232 struct wpa_supplicant
*wpa_s
= ctx
;
1233 return wpa_drv_send_mlme(wpa_s
, wpabuf_head(buf
), wpabuf_len(buf
), 1);
1237 static struct p2p_srv_bonjour
*
1238 wpas_p2p_service_get_bonjour(struct wpa_supplicant
*wpa_s
,
1239 const struct wpabuf
*query
)
1241 struct p2p_srv_bonjour
*bsrv
;
1244 len
= wpabuf_len(query
);
1245 dl_list_for_each(bsrv
, &wpa_s
->global
->p2p_srv_bonjour
,
1246 struct p2p_srv_bonjour
, list
) {
1247 if (len
== wpabuf_len(bsrv
->query
) &&
1248 os_memcmp(wpabuf_head(query
), wpabuf_head(bsrv
->query
),
1256 static struct p2p_srv_upnp
*
1257 wpas_p2p_service_get_upnp(struct wpa_supplicant
*wpa_s
, u8 version
,
1258 const char *service
)
1260 struct p2p_srv_upnp
*usrv
;
1262 dl_list_for_each(usrv
, &wpa_s
->global
->p2p_srv_upnp
,
1263 struct p2p_srv_upnp
, list
) {
1264 if (version
== usrv
->version
&&
1265 os_strcmp(service
, usrv
->service
) == 0)
1272 static void wpas_sd_add_proto_not_avail(struct wpabuf
*resp
, u8 srv_proto
,
1277 if (wpabuf_tailroom(resp
) < 5)
1280 /* Length (to be filled) */
1281 len_pos
= wpabuf_put(resp
, 2);
1282 wpabuf_put_u8(resp
, srv_proto
);
1283 wpabuf_put_u8(resp
, srv_trans_id
);
1285 wpabuf_put_u8(resp
, P2P_SD_PROTO_NOT_AVAILABLE
);
1286 /* Response Data: empty */
1287 WPA_PUT_LE16(len_pos
, (u8
*) wpabuf_put(resp
, 0) - len_pos
- 2);
1291 static void wpas_sd_all_bonjour(struct wpa_supplicant
*wpa_s
,
1292 struct wpabuf
*resp
, u8 srv_trans_id
)
1294 struct p2p_srv_bonjour
*bsrv
;
1297 wpa_printf(MSG_DEBUG
, "P2P: SD Request for all Bonjour services");
1299 if (dl_list_empty(&wpa_s
->global
->p2p_srv_bonjour
)) {
1300 wpa_printf(MSG_DEBUG
, "P2P: Bonjour protocol not available");
1304 dl_list_for_each(bsrv
, &wpa_s
->global
->p2p_srv_bonjour
,
1305 struct p2p_srv_bonjour
, list
) {
1306 if (wpabuf_tailroom(resp
) <
1307 5 + wpabuf_len(bsrv
->query
) + wpabuf_len(bsrv
->resp
))
1309 /* Length (to be filled) */
1310 len_pos
= wpabuf_put(resp
, 2);
1311 wpabuf_put_u8(resp
, P2P_SERV_BONJOUR
);
1312 wpabuf_put_u8(resp
, srv_trans_id
);
1314 wpabuf_put_u8(resp
, P2P_SD_SUCCESS
);
1315 wpa_hexdump_ascii(MSG_DEBUG
, "P2P: Matching Bonjour service",
1316 wpabuf_head(bsrv
->resp
),
1317 wpabuf_len(bsrv
->resp
));
1319 wpabuf_put_buf(resp
, bsrv
->query
); /* Key */
1320 wpabuf_put_buf(resp
, bsrv
->resp
); /* Value */
1321 WPA_PUT_LE16(len_pos
, (u8
*) wpabuf_put(resp
, 0) - len_pos
-
1327 static void wpas_sd_req_bonjour(struct wpa_supplicant
*wpa_s
,
1328 struct wpabuf
*resp
, u8 srv_trans_id
,
1329 const u8
*query
, size_t query_len
)
1331 struct p2p_srv_bonjour
*bsrv
;
1335 wpa_hexdump_ascii(MSG_DEBUG
, "P2P: SD Request for Bonjour",
1337 if (dl_list_empty(&wpa_s
->global
->p2p_srv_bonjour
)) {
1338 wpa_printf(MSG_DEBUG
, "P2P: Bonjour protocol not available");
1339 wpas_sd_add_proto_not_avail(resp
, P2P_SERV_BONJOUR
,
1344 if (query_len
== 0) {
1345 wpas_sd_all_bonjour(wpa_s
, resp
, srv_trans_id
);
1349 if (wpabuf_tailroom(resp
) < 5)
1351 /* Length (to be filled) */
1352 len_pos
= wpabuf_put(resp
, 2);
1353 wpabuf_put_u8(resp
, P2P_SERV_BONJOUR
);
1354 wpabuf_put_u8(resp
, srv_trans_id
);
1356 wpabuf_set(&buf
, query
, query_len
);
1357 bsrv
= wpas_p2p_service_get_bonjour(wpa_s
, &buf
);
1359 wpa_printf(MSG_DEBUG
, "P2P: Requested Bonjour service not "
1363 wpabuf_put_u8(resp
, P2P_SD_REQUESTED_INFO_NOT_AVAILABLE
);
1364 /* Response Data: empty */
1365 WPA_PUT_LE16(len_pos
, (u8
*) wpabuf_put(resp
, 0) - len_pos
-
1371 wpabuf_put_u8(resp
, P2P_SD_SUCCESS
);
1372 wpa_hexdump_ascii(MSG_DEBUG
, "P2P: Matching Bonjour service",
1373 wpabuf_head(bsrv
->resp
), wpabuf_len(bsrv
->resp
));
1375 if (wpabuf_tailroom(resp
) >=
1376 wpabuf_len(bsrv
->query
) + wpabuf_len(bsrv
->resp
)) {
1378 wpabuf_put_buf(resp
, bsrv
->query
); /* Key */
1379 wpabuf_put_buf(resp
, bsrv
->resp
); /* Value */
1381 WPA_PUT_LE16(len_pos
, (u8
*) wpabuf_put(resp
, 0) - len_pos
- 2);
1385 static void wpas_sd_all_upnp(struct wpa_supplicant
*wpa_s
,
1386 struct wpabuf
*resp
, u8 srv_trans_id
)
1388 struct p2p_srv_upnp
*usrv
;
1391 wpa_printf(MSG_DEBUG
, "P2P: SD Request for all UPnP services");
1393 if (dl_list_empty(&wpa_s
->global
->p2p_srv_upnp
)) {
1394 wpa_printf(MSG_DEBUG
, "P2P: UPnP protocol not available");
1398 dl_list_for_each(usrv
, &wpa_s
->global
->p2p_srv_upnp
,
1399 struct p2p_srv_upnp
, list
) {
1400 if (wpabuf_tailroom(resp
) < 5 + 1 + os_strlen(usrv
->service
))
1403 /* Length (to be filled) */
1404 len_pos
= wpabuf_put(resp
, 2);
1405 wpabuf_put_u8(resp
, P2P_SERV_UPNP
);
1406 wpabuf_put_u8(resp
, srv_trans_id
);
1409 wpabuf_put_u8(resp
, P2P_SD_SUCCESS
);
1411 wpabuf_put_u8(resp
, usrv
->version
);
1412 wpa_printf(MSG_DEBUG
, "P2P: Matching UPnP Service: %s",
1414 wpabuf_put_str(resp
, usrv
->service
);
1415 WPA_PUT_LE16(len_pos
, (u8
*) wpabuf_put(resp
, 0) - len_pos
-
1421 static void wpas_sd_req_upnp(struct wpa_supplicant
*wpa_s
,
1422 struct wpabuf
*resp
, u8 srv_trans_id
,
1423 const u8
*query
, size_t query_len
)
1425 struct p2p_srv_upnp
*usrv
;
1431 wpa_hexdump_ascii(MSG_DEBUG
, "P2P: SD Request for UPnP",
1434 if (dl_list_empty(&wpa_s
->global
->p2p_srv_upnp
)) {
1435 wpa_printf(MSG_DEBUG
, "P2P: UPnP protocol not available");
1436 wpas_sd_add_proto_not_avail(resp
, P2P_SERV_UPNP
,
1441 if (query_len
== 0) {
1442 wpas_sd_all_upnp(wpa_s
, resp
, srv_trans_id
);
1446 if (wpabuf_tailroom(resp
) < 5)
1449 /* Length (to be filled) */
1450 len_pos
= wpabuf_put(resp
, 2);
1451 wpabuf_put_u8(resp
, P2P_SERV_UPNP
);
1452 wpabuf_put_u8(resp
, srv_trans_id
);
1455 str
= os_malloc(query_len
);
1458 os_memcpy(str
, query
+ 1, query_len
- 1);
1459 str
[query_len
- 1] = '\0';
1461 dl_list_for_each(usrv
, &wpa_s
->global
->p2p_srv_upnp
,
1462 struct p2p_srv_upnp
, list
) {
1463 if (version
!= usrv
->version
)
1466 if (os_strcmp(str
, "ssdp:all") != 0 &&
1467 os_strstr(usrv
->service
, str
) == NULL
)
1470 if (wpabuf_tailroom(resp
) < 2)
1474 wpabuf_put_u8(resp
, P2P_SD_SUCCESS
);
1476 wpabuf_put_u8(resp
, version
);
1478 wpabuf_put_u8(resp
, ',');
1482 wpa_printf(MSG_DEBUG
, "P2P: Matching UPnP Service: %s",
1484 if (wpabuf_tailroom(resp
) < os_strlen(usrv
->service
))
1486 wpabuf_put_str(resp
, usrv
->service
);
1491 wpa_printf(MSG_DEBUG
, "P2P: Requested UPnP service not "
1494 wpabuf_put_u8(resp
, P2P_SD_REQUESTED_INFO_NOT_AVAILABLE
);
1495 /* Response Data: empty */
1498 WPA_PUT_LE16(len_pos
, (u8
*) wpabuf_put(resp
, 0) - len_pos
- 2);
1502 #ifdef CONFIG_WIFI_DISPLAY
1503 static void wpas_sd_req_wfd(struct wpa_supplicant
*wpa_s
,
1504 struct wpabuf
*resp
, u8 srv_trans_id
,
1505 const u8
*query
, size_t query_len
)
1511 wpa_hexdump(MSG_DEBUG
, "P2P: SD Request for WFD", query
, query_len
);
1513 if (!wpa_s
->global
->wifi_display
) {
1514 wpa_printf(MSG_DEBUG
, "P2P: WFD protocol not available");
1515 wpas_sd_add_proto_not_avail(resp
, P2P_SERV_WIFI_DISPLAY
,
1520 if (query_len
< 1) {
1521 wpa_printf(MSG_DEBUG
, "P2P: Missing WFD Requested Device "
1526 if (wpabuf_tailroom(resp
) < 5)
1531 wpa_printf(MSG_DEBUG
, "P2P: WSD for device role 0x%x", role
);
1533 /* TODO: role specific handling */
1535 /* Length (to be filled) */
1536 len_pos
= wpabuf_put(resp
, 2);
1537 wpabuf_put_u8(resp
, P2P_SERV_WIFI_DISPLAY
);
1538 wpabuf_put_u8(resp
, srv_trans_id
);
1539 wpabuf_put_u8(resp
, P2P_SD_SUCCESS
); /* Status Code */
1541 while (pos
< query
+ query_len
) {
1542 if (*pos
< MAX_WFD_SUBELEMS
&&
1543 wpa_s
->global
->wfd_subelem
[*pos
] &&
1544 wpabuf_tailroom(resp
) >=
1545 wpabuf_len(wpa_s
->global
->wfd_subelem
[*pos
])) {
1546 wpa_printf(MSG_DEBUG
, "P2P: Add WSD response "
1547 "subelement %u", *pos
);
1548 wpabuf_put_buf(resp
, wpa_s
->global
->wfd_subelem
[*pos
]);
1553 WPA_PUT_LE16(len_pos
, (u8
*) wpabuf_put(resp
, 0) - len_pos
- 2);
1555 #endif /* CONFIG_WIFI_DISPLAY */
1558 void wpas_sd_request(void *ctx
, int freq
, const u8
*sa
, u8 dialog_token
,
1559 u16 update_indic
, const u8
*tlvs
, size_t tlvs_len
)
1561 struct wpa_supplicant
*wpa_s
= ctx
;
1562 const u8
*pos
= tlvs
;
1563 const u8
*end
= tlvs
+ tlvs_len
;
1566 struct wpabuf
*resp
;
1567 u8 srv_proto
, srv_trans_id
;
1571 wpa_hexdump(MSG_MSGDUMP
, "P2P: Service Discovery Request TLVs",
1573 buf_len
= 2 * tlvs_len
+ 1;
1574 buf
= os_malloc(buf_len
);
1576 wpa_snprintf_hex(buf
, buf_len
, tlvs
, tlvs_len
);
1577 wpa_msg_ctrl(wpa_s
, MSG_INFO
, P2P_EVENT_SERV_DISC_REQ
"%d "
1579 freq
, MAC2STR(sa
), dialog_token
, update_indic
,
1584 if (wpa_s
->p2p_sd_over_ctrl_iface
) {
1585 wpas_notify_p2p_sd_request(wpa_s
, freq
, sa
, dialog_token
,
1586 update_indic
, tlvs
, tlvs_len
);
1587 return; /* to be processed by an external program */
1590 resp
= wpabuf_alloc(10000);
1594 while (pos
+ 1 < end
) {
1595 wpa_printf(MSG_DEBUG
, "P2P: Service Request TLV");
1596 slen
= WPA_GET_LE16(pos
);
1598 if (pos
+ slen
> end
|| slen
< 2) {
1599 wpa_printf(MSG_DEBUG
, "P2P: Unexpected Query Data "
1604 tlv_end
= pos
+ slen
;
1607 wpa_printf(MSG_DEBUG
, "P2P: Service Protocol Type %u",
1609 srv_trans_id
= *pos
++;
1610 wpa_printf(MSG_DEBUG
, "P2P: Service Transaction ID %u",
1613 wpa_hexdump(MSG_MSGDUMP
, "P2P: Query Data",
1614 pos
, tlv_end
- pos
);
1617 if (wpa_s
->force_long_sd
) {
1618 wpa_printf(MSG_DEBUG
, "P2P: SD test - force long "
1620 wpas_sd_all_bonjour(wpa_s
, resp
, srv_trans_id
);
1621 wpas_sd_all_upnp(wpa_s
, resp
, srv_trans_id
);
1625 switch (srv_proto
) {
1626 case P2P_SERV_ALL_SERVICES
:
1627 wpa_printf(MSG_DEBUG
, "P2P: Service Discovery Request "
1628 "for all services");
1629 if (dl_list_empty(&wpa_s
->global
->p2p_srv_upnp
) &&
1630 dl_list_empty(&wpa_s
->global
->p2p_srv_bonjour
)) {
1631 wpa_printf(MSG_DEBUG
, "P2P: No service "
1632 "discovery protocols available");
1633 wpas_sd_add_proto_not_avail(
1634 resp
, P2P_SERV_ALL_SERVICES
,
1638 wpas_sd_all_bonjour(wpa_s
, resp
, srv_trans_id
);
1639 wpas_sd_all_upnp(wpa_s
, resp
, srv_trans_id
);
1641 case P2P_SERV_BONJOUR
:
1642 wpas_sd_req_bonjour(wpa_s
, resp
, srv_trans_id
,
1643 pos
, tlv_end
- pos
);
1646 wpas_sd_req_upnp(wpa_s
, resp
, srv_trans_id
,
1647 pos
, tlv_end
- pos
);
1649 #ifdef CONFIG_WIFI_DISPLAY
1650 case P2P_SERV_WIFI_DISPLAY
:
1651 wpas_sd_req_wfd(wpa_s
, resp
, srv_trans_id
,
1652 pos
, tlv_end
- pos
);
1654 #endif /* CONFIG_WIFI_DISPLAY */
1656 wpa_printf(MSG_DEBUG
, "P2P: Unavailable service "
1657 "protocol %u", srv_proto
);
1658 wpas_sd_add_proto_not_avail(resp
, srv_proto
,
1667 wpas_notify_p2p_sd_request(wpa_s
, freq
, sa
, dialog_token
,
1668 update_indic
, tlvs
, tlvs_len
);
1670 wpas_p2p_sd_response(wpa_s
, freq
, sa
, dialog_token
, resp
);
1676 void wpas_sd_response(void *ctx
, const u8
*sa
, u16 update_indic
,
1677 const u8
*tlvs
, size_t tlvs_len
)
1679 struct wpa_supplicant
*wpa_s
= ctx
;
1680 const u8
*pos
= tlvs
;
1681 const u8
*end
= tlvs
+ tlvs_len
;
1687 wpa_hexdump(MSG_MSGDUMP
, "P2P: Service Discovery Response TLVs",
1689 if (tlvs_len
> 1500) {
1690 /* TODO: better way for handling this */
1691 wpa_msg_ctrl(wpa_s
, MSG_INFO
,
1692 P2P_EVENT_SERV_DISC_RESP MACSTR
1693 " %u <long response: %u bytes>",
1694 MAC2STR(sa
), update_indic
,
1695 (unsigned int) tlvs_len
);
1697 buf_len
= 2 * tlvs_len
+ 1;
1698 buf
= os_malloc(buf_len
);
1700 wpa_snprintf_hex(buf
, buf_len
, tlvs
, tlvs_len
);
1701 wpa_msg_ctrl(wpa_s
, MSG_INFO
,
1702 P2P_EVENT_SERV_DISC_RESP MACSTR
" %u %s",
1703 MAC2STR(sa
), update_indic
, buf
);
1709 u8 srv_proto
, srv_trans_id
, status
;
1711 wpa_printf(MSG_DEBUG
, "P2P: Service Response TLV");
1712 slen
= WPA_GET_LE16(pos
);
1714 if (pos
+ slen
> end
|| slen
< 3) {
1715 wpa_printf(MSG_DEBUG
, "P2P: Unexpected Response Data "
1719 tlv_end
= pos
+ slen
;
1722 wpa_printf(MSG_DEBUG
, "P2P: Service Protocol Type %u",
1724 srv_trans_id
= *pos
++;
1725 wpa_printf(MSG_DEBUG
, "P2P: Service Transaction ID %u",
1728 wpa_printf(MSG_DEBUG
, "P2P: Status Code ID %u",
1731 wpa_hexdump(MSG_MSGDUMP
, "P2P: Response Data",
1732 pos
, tlv_end
- pos
);
1737 wpas_notify_p2p_sd_response(wpa_s
, sa
, update_indic
, tlvs
, tlvs_len
);
1741 u64
wpas_p2p_sd_request(struct wpa_supplicant
*wpa_s
, const u8
*dst
,
1742 const struct wpabuf
*tlvs
)
1744 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
)
1745 return wpa_drv_p2p_sd_request(wpa_s
, dst
, tlvs
);
1746 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
1748 return (uintptr_t) p2p_sd_request(wpa_s
->global
->p2p
, dst
, tlvs
);
1752 u64
wpas_p2p_sd_request_upnp(struct wpa_supplicant
*wpa_s
, const u8
*dst
,
1753 u8 version
, const char *query
)
1755 struct wpabuf
*tlvs
;
1758 tlvs
= wpabuf_alloc(2 + 1 + 1 + 1 + os_strlen(query
));
1761 wpabuf_put_le16(tlvs
, 1 + 1 + 1 + os_strlen(query
));
1762 wpabuf_put_u8(tlvs
, P2P_SERV_UPNP
); /* Service Protocol Type */
1763 wpabuf_put_u8(tlvs
, 1); /* Service Transaction ID */
1764 wpabuf_put_u8(tlvs
, version
);
1765 wpabuf_put_str(tlvs
, query
);
1766 ret
= wpas_p2p_sd_request(wpa_s
, dst
, tlvs
);
1772 #ifdef CONFIG_WIFI_DISPLAY
1774 static u64
wpas_p2p_sd_request_wfd(struct wpa_supplicant
*wpa_s
, const u8
*dst
,
1775 const struct wpabuf
*tlvs
)
1777 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
)
1779 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
1781 return (uintptr_t) p2p_sd_request_wfd(wpa_s
->global
->p2p
, dst
, tlvs
);
1785 #define MAX_WFD_SD_SUBELEMS 20
1787 static void wfd_add_sd_req_role(struct wpabuf
*tlvs
, u8 id
, u8 role
,
1788 const char *subelems
)
1795 len
= wpabuf_put(tlvs
, 2);
1796 wpabuf_put_u8(tlvs
, P2P_SERV_WIFI_DISPLAY
); /* Service Protocol Type */
1797 wpabuf_put_u8(tlvs
, id
); /* Service Transaction ID */
1799 wpabuf_put_u8(tlvs
, role
);
1804 if (val
>= 0 && val
< 256) {
1805 wpabuf_put_u8(tlvs
, val
);
1807 if (count
== MAX_WFD_SD_SUBELEMS
)
1810 pos
= os_strchr(pos
+ 1, ',');
1816 WPA_PUT_LE16(len
, (u8
*) wpabuf_put(tlvs
, 0) - len
- 2);
1820 u64
wpas_p2p_sd_request_wifi_display(struct wpa_supplicant
*wpa_s
,
1821 const u8
*dst
, const char *role
)
1823 struct wpabuf
*tlvs
;
1825 const char *subelems
;
1828 subelems
= os_strchr(role
, ' ');
1829 if (subelems
== NULL
)
1833 tlvs
= wpabuf_alloc(4 * (2 + 1 + 1 + 1 + MAX_WFD_SD_SUBELEMS
));
1837 if (os_strstr(role
, "[source]"))
1838 wfd_add_sd_req_role(tlvs
, id
++, 0x00, subelems
);
1839 if (os_strstr(role
, "[pri-sink]"))
1840 wfd_add_sd_req_role(tlvs
, id
++, 0x01, subelems
);
1841 if (os_strstr(role
, "[sec-sink]"))
1842 wfd_add_sd_req_role(tlvs
, id
++, 0x02, subelems
);
1843 if (os_strstr(role
, "[source+sink]"))
1844 wfd_add_sd_req_role(tlvs
, id
++, 0x03, subelems
);
1846 ret
= wpas_p2p_sd_request_wfd(wpa_s
, dst
, tlvs
);
1851 #endif /* CONFIG_WIFI_DISPLAY */
1854 int wpas_p2p_sd_cancel_request(struct wpa_supplicant
*wpa_s
, u64 req
)
1856 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
)
1857 return wpa_drv_p2p_sd_cancel_request(wpa_s
, req
);
1858 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
1860 return p2p_sd_cancel_request(wpa_s
->global
->p2p
,
1861 (void *) (uintptr_t) req
);
1865 void wpas_p2p_sd_response(struct wpa_supplicant
*wpa_s
, int freq
,
1866 const u8
*dst
, u8 dialog_token
,
1867 const struct wpabuf
*resp_tlvs
)
1869 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
) {
1870 wpa_drv_p2p_sd_response(wpa_s
, freq
, dst
, dialog_token
,
1874 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
1876 p2p_sd_response(wpa_s
->global
->p2p
, freq
, dst
, dialog_token
,
1881 void wpas_p2p_sd_service_update(struct wpa_supplicant
*wpa_s
)
1883 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
) {
1884 wpa_drv_p2p_service_update(wpa_s
);
1887 if (wpa_s
->global
->p2p
)
1888 p2p_sd_service_update(wpa_s
->global
->p2p
);
1892 static void wpas_p2p_srv_bonjour_free(struct p2p_srv_bonjour
*bsrv
)
1894 dl_list_del(&bsrv
->list
);
1895 wpabuf_free(bsrv
->query
);
1896 wpabuf_free(bsrv
->resp
);
1901 static void wpas_p2p_srv_upnp_free(struct p2p_srv_upnp
*usrv
)
1903 dl_list_del(&usrv
->list
);
1904 os_free(usrv
->service
);
1909 void wpas_p2p_service_flush(struct wpa_supplicant
*wpa_s
)
1911 struct p2p_srv_bonjour
*bsrv
, *bn
;
1912 struct p2p_srv_upnp
*usrv
, *un
;
1914 dl_list_for_each_safe(bsrv
, bn
, &wpa_s
->global
->p2p_srv_bonjour
,
1915 struct p2p_srv_bonjour
, list
)
1916 wpas_p2p_srv_bonjour_free(bsrv
);
1918 dl_list_for_each_safe(usrv
, un
, &wpa_s
->global
->p2p_srv_upnp
,
1919 struct p2p_srv_upnp
, list
)
1920 wpas_p2p_srv_upnp_free(usrv
);
1922 wpas_p2p_sd_service_update(wpa_s
);
1926 int wpas_p2p_service_add_bonjour(struct wpa_supplicant
*wpa_s
,
1927 struct wpabuf
*query
, struct wpabuf
*resp
)
1929 struct p2p_srv_bonjour
*bsrv
;
1931 bsrv
= wpas_p2p_service_get_bonjour(wpa_s
, query
);
1934 wpabuf_free(bsrv
->resp
);
1939 bsrv
= os_zalloc(sizeof(*bsrv
));
1942 bsrv
->query
= query
;
1944 dl_list_add(&wpa_s
->global
->p2p_srv_bonjour
, &bsrv
->list
);
1946 wpas_p2p_sd_service_update(wpa_s
);
1951 int wpas_p2p_service_del_bonjour(struct wpa_supplicant
*wpa_s
,
1952 const struct wpabuf
*query
)
1954 struct p2p_srv_bonjour
*bsrv
;
1956 bsrv
= wpas_p2p_service_get_bonjour(wpa_s
, query
);
1959 wpas_p2p_srv_bonjour_free(bsrv
);
1960 wpas_p2p_sd_service_update(wpa_s
);
1965 int wpas_p2p_service_add_upnp(struct wpa_supplicant
*wpa_s
, u8 version
,
1966 const char *service
)
1968 struct p2p_srv_upnp
*usrv
;
1970 if (wpas_p2p_service_get_upnp(wpa_s
, version
, service
))
1971 return 0; /* Already listed */
1972 usrv
= os_zalloc(sizeof(*usrv
));
1975 usrv
->version
= version
;
1976 usrv
->service
= os_strdup(service
);
1977 if (usrv
->service
== NULL
) {
1981 dl_list_add(&wpa_s
->global
->p2p_srv_upnp
, &usrv
->list
);
1983 wpas_p2p_sd_service_update(wpa_s
);
1988 int wpas_p2p_service_del_upnp(struct wpa_supplicant
*wpa_s
, u8 version
,
1989 const char *service
)
1991 struct p2p_srv_upnp
*usrv
;
1993 usrv
= wpas_p2p_service_get_upnp(wpa_s
, version
, service
);
1996 wpas_p2p_srv_upnp_free(usrv
);
1997 wpas_p2p_sd_service_update(wpa_s
);
2002 static void wpas_prov_disc_local_display(struct wpa_supplicant
*wpa_s
,
2003 const u8
*peer
, const char *params
,
2004 unsigned int generated_pin
)
2006 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_PROV_DISC_SHOW_PIN MACSTR
" %08d%s",
2007 MAC2STR(peer
), generated_pin
, params
);
2011 static void wpas_prov_disc_local_keypad(struct wpa_supplicant
*wpa_s
,
2012 const u8
*peer
, const char *params
)
2014 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_PROV_DISC_ENTER_PIN MACSTR
"%s",
2015 MAC2STR(peer
), params
);
2019 void wpas_prov_disc_req(void *ctx
, const u8
*peer
, u16 config_methods
,
2020 const u8
*dev_addr
, const u8
*pri_dev_type
,
2021 const char *dev_name
, u16 supp_config_methods
,
2022 u8 dev_capab
, u8 group_capab
, const u8
*group_id
,
2023 size_t group_id_len
)
2025 struct wpa_supplicant
*wpa_s
= ctx
;
2026 char devtype
[WPS_DEV_TYPE_BUFSIZE
];
2028 u8 empty_dev_type
[8];
2029 unsigned int generated_pin
= 0;
2030 struct wpa_supplicant
*group
= NULL
;
2033 for (group
= wpa_s
->global
->ifaces
; group
; group
= group
->next
)
2035 struct wpa_ssid
*s
= group
->current_ssid
;
2037 s
->mode
== WPAS_MODE_P2P_GO
&&
2038 group_id_len
- ETH_ALEN
== s
->ssid_len
&&
2039 os_memcmp(group_id
+ ETH_ALEN
, s
->ssid
,
2045 if (pri_dev_type
== NULL
) {
2046 os_memset(empty_dev_type
, 0, sizeof(empty_dev_type
));
2047 pri_dev_type
= empty_dev_type
;
2049 os_snprintf(params
, sizeof(params
), " p2p_dev_addr=" MACSTR
2050 " pri_dev_type=%s name='%s' config_methods=0x%x "
2051 "dev_capab=0x%x group_capab=0x%x%s%s",
2053 wps_dev_type_bin2str(pri_dev_type
, devtype
,
2055 dev_name
, supp_config_methods
, dev_capab
, group_capab
,
2056 group
? " group=" : "",
2057 group
? group
->ifname
: "");
2058 params
[sizeof(params
) - 1] = '\0';
2060 if (config_methods
& WPS_CONFIG_DISPLAY
) {
2061 generated_pin
= wps_generate_pin();
2062 wpas_prov_disc_local_display(wpa_s
, peer
, params
,
2064 } else if (config_methods
& WPS_CONFIG_KEYPAD
)
2065 wpas_prov_disc_local_keypad(wpa_s
, peer
, params
);
2066 else if (config_methods
& WPS_CONFIG_PUSHBUTTON
)
2067 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_PROV_DISC_PBC_REQ MACSTR
2068 "%s", MAC2STR(peer
), params
);
2070 wpas_notify_p2p_provision_discovery(wpa_s
, peer
, 1 /* request */,
2071 P2P_PROV_DISC_SUCCESS
,
2072 config_methods
, generated_pin
);
2076 void wpas_prov_disc_resp(void *ctx
, const u8
*peer
, u16 config_methods
)
2078 struct wpa_supplicant
*wpa_s
= ctx
;
2079 unsigned int generated_pin
= 0;
2082 if (wpa_s
->pending_pd_before_join
&&
2083 (os_memcmp(peer
, wpa_s
->pending_join_dev_addr
, ETH_ALEN
) == 0 ||
2084 os_memcmp(peer
, wpa_s
->pending_join_iface_addr
, ETH_ALEN
) == 0)) {
2085 wpa_s
->pending_pd_before_join
= 0;
2086 wpa_printf(MSG_DEBUG
, "P2P: Starting pending "
2087 "join-existing-group operation");
2088 wpas_p2p_join_start(wpa_s
);
2092 if (wpa_s
->pending_pd_use
== AUTO_PD_JOIN
||
2093 wpa_s
->pending_pd_use
== AUTO_PD_GO_NEG
)
2094 os_snprintf(params
, sizeof(params
), " peer_go=%d",
2095 wpa_s
->pending_pd_use
== AUTO_PD_JOIN
);
2099 if (config_methods
& WPS_CONFIG_DISPLAY
)
2100 wpas_prov_disc_local_keypad(wpa_s
, peer
, params
);
2101 else if (config_methods
& WPS_CONFIG_KEYPAD
) {
2102 generated_pin
= wps_generate_pin();
2103 wpas_prov_disc_local_display(wpa_s
, peer
, params
,
2105 } else if (config_methods
& WPS_CONFIG_PUSHBUTTON
)
2106 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_PROV_DISC_PBC_RESP MACSTR
2107 "%s", MAC2STR(peer
), params
);
2109 wpas_notify_p2p_provision_discovery(wpa_s
, peer
, 0 /* response */,
2110 P2P_PROV_DISC_SUCCESS
,
2111 config_methods
, generated_pin
);
2115 static void wpas_prov_disc_fail(void *ctx
, const u8
*peer
,
2116 enum p2p_prov_disc_status status
)
2118 struct wpa_supplicant
*wpa_s
= ctx
;
2120 if (wpa_s
->p2p_fallback_to_go_neg
) {
2121 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: PD for p2p_connect-auto "
2122 "failed - fall back to GO Negotiation");
2123 wpas_p2p_fallback_to_go_neg(wpa_s
, 0);
2127 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_PROV_DISC_FAILURE
2128 " p2p_dev_addr=" MACSTR
" status=%d",
2129 MAC2STR(peer
), status
);
2131 wpas_notify_p2p_provision_discovery(wpa_s
, peer
, 0 /* response */,
2136 static u8
wpas_invitation_process(void *ctx
, const u8
*sa
, const u8
*bssid
,
2137 const u8
*go_dev_addr
, const u8
*ssid
,
2138 size_t ssid_len
, int *go
, u8
*group_bssid
,
2139 int *force_freq
, int persistent_group
)
2141 struct wpa_supplicant
*wpa_s
= ctx
;
2143 u8 cur_bssid
[ETH_ALEN
];
2145 struct wpa_supplicant
*grp
;
2147 if (!persistent_group
) {
2148 wpa_printf(MSG_DEBUG
, "P2P: Invitation from " MACSTR
2149 " to join an active group", MAC2STR(sa
));
2150 if (!is_zero_ether_addr(wpa_s
->p2p_auth_invite
) &&
2151 (os_memcmp(go_dev_addr
, wpa_s
->p2p_auth_invite
, ETH_ALEN
)
2153 os_memcmp(sa
, wpa_s
->p2p_auth_invite
, ETH_ALEN
) == 0)) {
2154 wpa_printf(MSG_DEBUG
, "P2P: Accept previously "
2155 "authorized invitation");
2159 * Do not accept the invitation automatically; notify user and
2162 return P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE
;
2165 grp
= wpas_get_p2p_group(wpa_s
, ssid
, ssid_len
, go
);
2167 wpa_printf(MSG_DEBUG
, "P2P: Accept invitation to already "
2168 "running persistent group");
2170 os_memcpy(group_bssid
, grp
->own_addr
, ETH_ALEN
);
2174 if (!wpa_s
->conf
->persistent_reconnect
)
2175 return P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE
;
2177 for (s
= wpa_s
->conf
->ssid
; s
; s
= s
->next
) {
2178 if (s
->disabled
== 2 &&
2179 os_memcmp(s
->bssid
, go_dev_addr
, ETH_ALEN
) == 0 &&
2180 s
->ssid_len
== ssid_len
&&
2181 os_memcmp(ssid
, s
->ssid
, ssid_len
) == 0)
2186 wpa_printf(MSG_DEBUG
, "P2P: Invitation from " MACSTR
2187 " requested reinvocation of an unknown group",
2189 return P2P_SC_FAIL_UNKNOWN_GROUP
;
2192 if (s
->mode
== WPAS_MODE_P2P_GO
&& !wpas_p2p_create_iface(wpa_s
)) {
2194 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
2195 wpa_printf(MSG_DEBUG
, "P2P: The only available "
2196 "interface is already in use - reject "
2198 return P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE
;
2200 os_memcpy(group_bssid
, wpa_s
->own_addr
, ETH_ALEN
);
2201 } else if (s
->mode
== WPAS_MODE_P2P_GO
) {
2203 if (wpas_p2p_add_group_interface(wpa_s
, WPA_IF_P2P_GO
) < 0)
2205 wpa_printf(MSG_ERROR
, "P2P: Failed to allocate a new "
2206 "interface address for the group");
2207 return P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE
;
2209 os_memcpy(group_bssid
, wpa_s
->pending_interface_addr
,
2214 if (wpa_s
->current_ssid
&& wpa_drv_get_bssid(wpa_s
, cur_bssid
) == 0 &&
2215 wpa_s
->assoc_freq
) {
2216 wpa_printf(MSG_DEBUG
, "P2P: Trying to force channel to match "
2217 "the channel we are already using");
2218 *force_freq
= wpa_s
->assoc_freq
;
2221 res
= wpa_drv_shared_freq(wpa_s
);
2223 wpa_printf(MSG_DEBUG
, "P2P: Trying to force channel to match "
2224 "with the channel we are already using on a "
2225 "shared interface");
2229 return P2P_SC_SUCCESS
;
2233 static void wpas_invitation_received(void *ctx
, const u8
*sa
, const u8
*bssid
,
2234 const u8
*ssid
, size_t ssid_len
,
2235 const u8
*go_dev_addr
, u8 status
,
2238 struct wpa_supplicant
*wpa_s
= ctx
;
2241 for (s
= wpa_s
->conf
->ssid
; s
; s
= s
->next
) {
2242 if (s
->disabled
== 2 &&
2243 s
->ssid_len
== ssid_len
&&
2244 os_memcmp(ssid
, s
->ssid
, ssid_len
) == 0)
2248 if (status
== P2P_SC_SUCCESS
) {
2249 wpa_printf(MSG_DEBUG
, "P2P: Invitation from peer " MACSTR
2250 " was accepted; op_freq=%d MHz",
2251 MAC2STR(sa
), op_freq
);
2253 int go
= s
->mode
== WPAS_MODE_P2P_GO
;
2254 wpas_p2p_group_add_persistent(
2255 wpa_s
, s
, go
, go
? op_freq
: 0, 0);
2257 wpas_p2p_join(wpa_s
, bssid
, go_dev_addr
,
2258 wpa_s
->p2p_wps_method
, 0);
2263 if (status
!= P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE
) {
2264 wpa_printf(MSG_DEBUG
, "P2P: Invitation from peer " MACSTR
2265 " was rejected (status %u)", MAC2STR(sa
), status
);
2271 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_INVITATION_RECEIVED
2272 "sa=" MACSTR
" go_dev_addr=" MACSTR
2273 " bssid=" MACSTR
" unknown-network",
2274 MAC2STR(sa
), MAC2STR(go_dev_addr
),
2277 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_INVITATION_RECEIVED
2278 "sa=" MACSTR
" go_dev_addr=" MACSTR
2280 MAC2STR(sa
), MAC2STR(go_dev_addr
));
2285 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_INVITATION_RECEIVED
"sa=" MACSTR
2286 " persistent=%d", MAC2STR(sa
), s
->id
);
2290 static void wpas_invitation_result(void *ctx
, int status
, const u8
*bssid
)
2292 struct wpa_supplicant
*wpa_s
= ctx
;
2293 struct wpa_ssid
*ssid
;
2296 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_INVITATION_RESULT
2297 "status=%d " MACSTR
,
2298 status
, MAC2STR(bssid
));
2300 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_INVITATION_RESULT
2301 "status=%d ", status
);
2303 wpas_notify_p2p_invitation_result(wpa_s
, status
, bssid
);
2305 if (wpa_s
->pending_invite_ssid_id
== -1)
2306 return; /* Invitation to active group */
2308 if (status
!= P2P_SC_SUCCESS
) {
2309 wpas_p2p_remove_pending_group_interface(wpa_s
);
2313 ssid
= wpa_config_get_network(wpa_s
->conf
,
2314 wpa_s
->pending_invite_ssid_id
);
2316 wpa_printf(MSG_ERROR
, "P2P: Could not find persistent group "
2317 "data matching with invitation");
2322 * The peer could have missed our ctrl::ack frame for Invitation
2323 * Response and continue retransmitting the frame. To reduce the
2324 * likelihood of the peer not getting successful TX status for the
2325 * Invitation Response frame, wait a short time here before starting
2326 * the persistent group so that we will remain on the current channel to
2327 * acknowledge any possible retransmission from the peer.
2329 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: 50 ms wait on current channel before "
2330 "starting persistent group");
2333 wpas_p2p_group_add_persistent(wpa_s
, ssid
,
2334 ssid
->mode
== WPAS_MODE_P2P_GO
,
2335 wpa_s
->p2p_persistent_go_freq
,
2336 wpa_s
->p2p_go_ht40
);
2340 static int wpas_p2p_disallowed_freq(struct wpa_global
*global
,
2345 if (global
->p2p_disallow_freq
== NULL
)
2348 for (i
= 0; i
< global
->num_p2p_disallow_freq
; i
++) {
2349 if (freq
>= global
->p2p_disallow_freq
[i
].min
&&
2350 freq
<= global
->p2p_disallow_freq
[i
].max
)
2358 static void wpas_p2p_add_chan(struct p2p_reg_class
*reg
, u8 chan
)
2360 reg
->channel
[reg
->channels
] = chan
;
2365 static int wpas_p2p_default_channels(struct wpa_supplicant
*wpa_s
,
2366 struct p2p_channels
*chan
)
2370 wpa_printf(MSG_DEBUG
, "P2P: Enable operating classes for 2.4 GHz "
2373 /* Operating class 81 - 2.4 GHz band channels 1..13 */
2374 chan
->reg_class
[cla
].reg_class
= 81;
2375 chan
->reg_class
[cla
].channels
= 0;
2376 for (i
= 0; i
< 11; i
++) {
2377 if (!wpas_p2p_disallowed_freq(wpa_s
->global
, 2412 + i
* 5))
2378 wpas_p2p_add_chan(&chan
->reg_class
[cla
], i
+ 1);
2380 if (chan
->reg_class
[cla
].channels
)
2383 wpa_printf(MSG_DEBUG
, "P2P: Enable operating classes for lower 5 GHz "
2386 /* Operating class 115 - 5 GHz, channels 36-48 */
2387 chan
->reg_class
[cla
].reg_class
= 115;
2388 chan
->reg_class
[cla
].channels
= 0;
2389 if (!wpas_p2p_disallowed_freq(wpa_s
->global
, 5000 + 36 * 5))
2390 wpas_p2p_add_chan(&chan
->reg_class
[cla
], 36);
2391 if (!wpas_p2p_disallowed_freq(wpa_s
->global
, 5000 + 40 * 5))
2392 wpas_p2p_add_chan(&chan
->reg_class
[cla
], 40);
2393 if (!wpas_p2p_disallowed_freq(wpa_s
->global
, 5000 + 44 * 5))
2394 wpas_p2p_add_chan(&chan
->reg_class
[cla
], 44);
2395 if (!wpas_p2p_disallowed_freq(wpa_s
->global
, 5000 + 48 * 5))
2396 wpas_p2p_add_chan(&chan
->reg_class
[cla
], 48);
2397 if (chan
->reg_class
[cla
].channels
)
2400 wpa_printf(MSG_DEBUG
, "P2P: Enable operating classes for higher 5 GHz "
2403 /* Operating class 124 - 5 GHz, channels 149,153,157,161 */
2404 chan
->reg_class
[cla
].reg_class
= 124;
2405 chan
->reg_class
[cla
].channels
= 0;
2406 if (!wpas_p2p_disallowed_freq(wpa_s
->global
, 5000 + 149 * 5))
2407 wpas_p2p_add_chan(&chan
->reg_class
[cla
], 149);
2408 if (!wpas_p2p_disallowed_freq(wpa_s
->global
, 5000 + 153 * 5))
2409 wpas_p2p_add_chan(&chan
->reg_class
[cla
], 153);
2410 if (!wpas_p2p_disallowed_freq(wpa_s
->global
, 5000 + 156 * 5))
2411 wpas_p2p_add_chan(&chan
->reg_class
[cla
], 157);
2412 if (!wpas_p2p_disallowed_freq(wpa_s
->global
, 5000 + 161 * 5))
2413 wpas_p2p_add_chan(&chan
->reg_class
[cla
], 161);
2414 if (chan
->reg_class
[cla
].channels
)
2417 chan
->reg_classes
= cla
;
2422 static struct hostapd_hw_modes
* get_mode(struct hostapd_hw_modes
*modes
,
2424 enum hostapd_hw_mode mode
)
2428 for (i
= 0; i
< num_modes
; i
++) {
2429 if (modes
[i
].mode
== mode
)
2437 static int has_channel(struct wpa_global
*global
,
2438 struct hostapd_hw_modes
*mode
, u8 chan
, int *flags
)
2443 freq
= (mode
->mode
== HOSTAPD_MODE_IEEE80211A
? 5000 : 2407) +
2445 if (wpas_p2p_disallowed_freq(global
, freq
))
2448 for (i
= 0; i
< mode
->num_channels
; i
++) {
2449 if (mode
->channels
[i
].chan
== chan
) {
2451 *flags
= mode
->channels
[i
].flag
;
2452 return !(mode
->channels
[i
].flag
&
2453 (HOSTAPD_CHAN_DISABLED
|
2454 HOSTAPD_CHAN_PASSIVE_SCAN
|
2455 HOSTAPD_CHAN_NO_IBSS
|
2456 HOSTAPD_CHAN_RADAR
));
2464 struct p2p_oper_class_map
{
2465 enum hostapd_hw_mode mode
;
2470 enum { BW20
, BW40PLUS
, BW40MINUS
} bw
;
2473 static struct p2p_oper_class_map op_class
[] = {
2474 { HOSTAPD_MODE_IEEE80211G
, 81, 1, 13, 1, BW20
},
2475 #if 0 /* Do not enable HT40 on 2 GHz for now */
2476 { HOSTAPD_MODE_IEEE80211G
, 83, 1, 9, 1, BW40PLUS
},
2477 { HOSTAPD_MODE_IEEE80211G
, 84, 5, 13, 1, BW40MINUS
},
2479 { HOSTAPD_MODE_IEEE80211A
, 115, 36, 48, 4, BW20
},
2480 { HOSTAPD_MODE_IEEE80211A
, 124, 149, 161, 4, BW20
},
2481 { HOSTAPD_MODE_IEEE80211A
, 116, 36, 44, 8, BW40PLUS
},
2482 { HOSTAPD_MODE_IEEE80211A
, 117, 40, 48, 8, BW40MINUS
},
2483 { HOSTAPD_MODE_IEEE80211A
, 126, 149, 157, 8, BW40PLUS
},
2484 { HOSTAPD_MODE_IEEE80211A
, 127, 153, 161, 8, BW40MINUS
},
2485 { -1, 0, 0, 0, 0, BW20
}
2489 static int wpas_p2p_verify_channel(struct wpa_supplicant
*wpa_s
,
2490 struct hostapd_hw_modes
*mode
,
2495 if (!has_channel(wpa_s
->global
, mode
, channel
, &flag
))
2497 if (bw
== BW40MINUS
&&
2498 (!(flag
& HOSTAPD_CHAN_HT40MINUS
) ||
2499 !has_channel(wpa_s
->global
, mode
, channel
- 4, NULL
)))
2501 if (bw
== BW40PLUS
&&
2502 (!(flag
& HOSTAPD_CHAN_HT40PLUS
) ||
2503 !has_channel(wpa_s
->global
, mode
, channel
+ 4, NULL
)))
2509 static int wpas_p2p_setup_channels(struct wpa_supplicant
*wpa_s
,
2510 struct p2p_channels
*chan
)
2512 struct hostapd_hw_modes
*mode
;
2515 if (wpa_s
->hw
.modes
== NULL
) {
2516 wpa_printf(MSG_DEBUG
, "P2P: Driver did not support fetching "
2517 "of all supported channels; assume dualband "
2519 return wpas_p2p_default_channels(wpa_s
, chan
);
2524 for (op
= 0; op_class
[op
].op_class
; op
++) {
2525 struct p2p_oper_class_map
*o
= &op_class
[op
];
2527 struct p2p_reg_class
*reg
= NULL
;
2529 mode
= get_mode(wpa_s
->hw
.modes
, wpa_s
->hw
.num_modes
, o
->mode
);
2532 for (ch
= o
->min_chan
; ch
<= o
->max_chan
; ch
+= o
->inc
) {
2533 if (wpas_p2p_verify_channel(wpa_s
, mode
, ch
, o
->bw
) < 1)
2536 wpa_printf(MSG_DEBUG
, "P2P: Add operating "
2537 "class %u", o
->op_class
);
2538 reg
= &chan
->reg_class
[cla
];
2540 reg
->reg_class
= o
->op_class
;
2542 reg
->channel
[reg
->channels
] = ch
;
2546 wpa_hexdump(MSG_DEBUG
, "P2P: Channels",
2547 reg
->channel
, reg
->channels
);
2551 chan
->reg_classes
= cla
;
2557 int wpas_p2p_get_ht40_mode(struct wpa_supplicant
*wpa_s
,
2558 struct hostapd_hw_modes
*mode
, u8 channel
)
2562 for (op
= 0; op_class
[op
].op_class
; op
++) {
2563 struct p2p_oper_class_map
*o
= &op_class
[op
];
2566 for (ch
= o
->min_chan
; ch
<= o
->max_chan
; ch
+= o
->inc
) {
2567 if (o
->mode
!= HOSTAPD_MODE_IEEE80211A
||
2568 o
->bw
== BW20
|| ch
!= channel
)
2570 ret
= wpas_p2p_verify_channel(wpa_s
, mode
, ch
, o
->bw
);
2574 return (o
->bw
== BW40MINUS
) ? -1 : 1;
2583 static int wpas_get_noa(void *ctx
, const u8
*interface_addr
, u8
*buf
,
2586 struct wpa_supplicant
*wpa_s
= ctx
;
2588 for (wpa_s
= wpa_s
->global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
2589 if (os_memcmp(wpa_s
->own_addr
, interface_addr
, ETH_ALEN
) == 0)
2595 return wpa_drv_get_noa(wpa_s
, buf
, buf_len
);
2599 static int wpas_go_connected(void *ctx
, const u8
*dev_addr
)
2601 struct wpa_supplicant
*wpa_s
= ctx
;
2603 for (wpa_s
= wpa_s
->global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
2604 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
2607 if (ssid
->mode
!= WPAS_MODE_INFRA
)
2609 if (wpa_s
->wpa_state
!= WPA_COMPLETED
&&
2610 wpa_s
->wpa_state
!= WPA_GROUP_HANDSHAKE
)
2612 if (os_memcmp(wpa_s
->go_dev_addr
, dev_addr
, ETH_ALEN
) == 0)
2621 * wpas_p2p_init - Initialize P2P module for %wpa_supplicant
2622 * @global: Pointer to global data from wpa_supplicant_init()
2623 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
2624 * Returns: 0 on success, -1 on failure
2626 int wpas_p2p_init(struct wpa_global
*global
, struct wpa_supplicant
*wpa_s
)
2628 struct p2p_config p2p
;
2632 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_CAPABLE
))
2638 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
) {
2639 struct p2p_params params
;
2641 wpa_printf(MSG_DEBUG
, "P2P: Use driver-based P2P management");
2642 os_memset(¶ms
, 0, sizeof(params
));
2643 params
.dev_name
= wpa_s
->conf
->device_name
;
2644 os_memcpy(params
.pri_dev_type
, wpa_s
->conf
->device_type
,
2646 params
.num_sec_dev_types
= wpa_s
->conf
->num_sec_device_types
;
2647 os_memcpy(params
.sec_dev_type
,
2648 wpa_s
->conf
->sec_device_type
,
2649 params
.num_sec_dev_types
* WPS_DEV_TYPE_LEN
);
2651 if (wpa_drv_p2p_set_params(wpa_s
, ¶ms
) < 0)
2657 os_memset(&p2p
, 0, sizeof(p2p
));
2658 p2p
.msg_ctx
= wpa_s
;
2660 p2p
.p2p_scan
= wpas_p2p_scan
;
2661 p2p
.send_action
= wpas_send_action
;
2662 p2p
.send_action_done
= wpas_send_action_done
;
2663 p2p
.go_neg_completed
= wpas_go_neg_completed
;
2664 p2p
.go_neg_req_rx
= wpas_go_neg_req_rx
;
2665 p2p
.dev_found
= wpas_dev_found
;
2666 p2p
.dev_lost
= wpas_dev_lost
;
2667 p2p
.start_listen
= wpas_start_listen
;
2668 p2p
.stop_listen
= wpas_stop_listen
;
2669 p2p
.send_probe_resp
= wpas_send_probe_resp
;
2670 p2p
.sd_request
= wpas_sd_request
;
2671 p2p
.sd_response
= wpas_sd_response
;
2672 p2p
.prov_disc_req
= wpas_prov_disc_req
;
2673 p2p
.prov_disc_resp
= wpas_prov_disc_resp
;
2674 p2p
.prov_disc_fail
= wpas_prov_disc_fail
;
2675 p2p
.invitation_process
= wpas_invitation_process
;
2676 p2p
.invitation_received
= wpas_invitation_received
;
2677 p2p
.invitation_result
= wpas_invitation_result
;
2678 p2p
.get_noa
= wpas_get_noa
;
2679 p2p
.go_connected
= wpas_go_connected
;
2681 os_memcpy(wpa_s
->global
->p2p_dev_addr
, wpa_s
->own_addr
, ETH_ALEN
);
2682 os_memcpy(p2p
.dev_addr
, wpa_s
->global
->p2p_dev_addr
, ETH_ALEN
);
2683 p2p
.dev_name
= wpa_s
->conf
->device_name
;
2684 p2p
.manufacturer
= wpa_s
->conf
->manufacturer
;
2685 p2p
.model_name
= wpa_s
->conf
->model_name
;
2686 p2p
.model_number
= wpa_s
->conf
->model_number
;
2687 p2p
.serial_number
= wpa_s
->conf
->serial_number
;
2689 os_memcpy(p2p
.uuid
, wpa_s
->wps
->uuid
, 16);
2690 p2p
.config_methods
= wpa_s
->wps
->config_methods
;
2693 if (wpa_s
->conf
->p2p_listen_reg_class
&&
2694 wpa_s
->conf
->p2p_listen_channel
) {
2695 p2p
.reg_class
= wpa_s
->conf
->p2p_listen_reg_class
;
2696 p2p
.channel
= wpa_s
->conf
->p2p_listen_channel
;
2700 * Pick one of the social channels randomly as the listen
2703 os_get_random((u8
*) &r
, sizeof(r
));
2704 p2p
.channel
= 1 + (r
% 3) * 5;
2706 wpa_printf(MSG_DEBUG
, "P2P: Own listen channel: %d", p2p
.channel
);
2708 if (wpa_s
->conf
->p2p_oper_reg_class
&&
2709 wpa_s
->conf
->p2p_oper_channel
) {
2710 p2p
.op_reg_class
= wpa_s
->conf
->p2p_oper_reg_class
;
2711 p2p
.op_channel
= wpa_s
->conf
->p2p_oper_channel
;
2712 p2p
.cfg_op_channel
= 1;
2713 wpa_printf(MSG_DEBUG
, "P2P: Configured operating channel: "
2714 "%d:%d", p2p
.op_reg_class
, p2p
.op_channel
);
2717 p2p
.op_reg_class
= 81;
2719 * Use random operation channel from (1, 6, 11) if no other
2720 * preference is indicated.
2722 os_get_random((u8
*) &r
, sizeof(r
));
2723 p2p
.op_channel
= 1 + (r
% 3) * 5;
2724 p2p
.cfg_op_channel
= 0;
2725 wpa_printf(MSG_DEBUG
, "P2P: Random operating channel: "
2726 "%d:%d", p2p
.op_reg_class
, p2p
.op_channel
);
2728 if (wpa_s
->conf
->country
[0] && wpa_s
->conf
->country
[1]) {
2729 os_memcpy(p2p
.country
, wpa_s
->conf
->country
, 2);
2730 p2p
.country
[2] = 0x04;
2732 os_memcpy(p2p
.country
, "XX\x04", 3);
2734 if (wpas_p2p_setup_channels(wpa_s
, &p2p
.channels
)) {
2735 wpa_printf(MSG_ERROR
, "P2P: Failed to configure supported "
2740 os_memcpy(p2p
.pri_dev_type
, wpa_s
->conf
->device_type
,
2743 p2p
.num_sec_dev_types
= wpa_s
->conf
->num_sec_device_types
;
2744 os_memcpy(p2p
.sec_dev_type
, wpa_s
->conf
->sec_device_type
,
2745 p2p
.num_sec_dev_types
* WPS_DEV_TYPE_LEN
);
2747 p2p
.concurrent_operations
= !!(wpa_s
->drv_flags
&
2748 WPA_DRIVER_FLAGS_P2P_CONCURRENT
);
2750 p2p
.max_peers
= 100;
2752 if (wpa_s
->conf
->p2p_ssid_postfix
) {
2753 p2p
.ssid_postfix_len
=
2754 os_strlen(wpa_s
->conf
->p2p_ssid_postfix
);
2755 if (p2p
.ssid_postfix_len
> sizeof(p2p
.ssid_postfix
))
2756 p2p
.ssid_postfix_len
= sizeof(p2p
.ssid_postfix
);
2757 os_memcpy(p2p
.ssid_postfix
, wpa_s
->conf
->p2p_ssid_postfix
,
2758 p2p
.ssid_postfix_len
);
2761 p2p
.p2p_intra_bss
= wpa_s
->conf
->p2p_intra_bss
;
2763 global
->p2p
= p2p_init(&p2p
);
2764 if (global
->p2p
== NULL
)
2766 global
->p2p_init_wpa_s
= wpa_s
;
2768 for (i
= 0; i
< MAX_WPS_VENDOR_EXT
; i
++) {
2769 if (wpa_s
->conf
->wps_vendor_ext
[i
] == NULL
)
2771 p2p_add_wps_vendor_extension(
2772 global
->p2p
, wpa_s
->conf
->wps_vendor_ext
[i
]);
2780 * wpas_p2p_deinit - Deinitialize per-interface P2P data
2781 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
2783 * This function deinitialize per-interface P2P data.
2785 void wpas_p2p_deinit(struct wpa_supplicant
*wpa_s
)
2787 if (wpa_s
->driver
&& wpa_s
->drv_priv
)
2788 wpa_drv_probe_req_report(wpa_s
, 0);
2790 if (wpa_s
->go_params
) {
2791 /* Clear any stored provisioning info */
2792 p2p_clear_provisioning_info(
2794 wpa_s
->go_params
->peer_device_addr
);
2797 os_free(wpa_s
->go_params
);
2798 wpa_s
->go_params
= NULL
;
2799 eloop_cancel_timeout(wpas_p2p_group_formation_timeout
, wpa_s
, NULL
);
2800 eloop_cancel_timeout(wpas_p2p_join_scan
, wpa_s
, NULL
);
2801 eloop_cancel_timeout(wpas_p2p_pd_before_join_timeout
, wpa_s
, NULL
);
2802 wpa_s
->p2p_long_listen
= 0;
2803 eloop_cancel_timeout(wpas_p2p_long_listen_timeout
, wpa_s
, NULL
);
2804 eloop_cancel_timeout(wpas_p2p_group_idle_timeout
, wpa_s
, NULL
);
2805 wpas_p2p_remove_pending_group_interface(wpa_s
);
2807 /* TODO: remove group interface from the driver if this wpa_s instance
2808 * is on top of a P2P group interface */
2813 * wpas_p2p_deinit_global - Deinitialize global P2P module
2814 * @global: Pointer to global data from wpa_supplicant_init()
2816 * This function deinitializes the global (per device) P2P module.
2818 void wpas_p2p_deinit_global(struct wpa_global
*global
)
2820 struct wpa_supplicant
*wpa_s
, *tmp
;
2822 wpa_s
= global
->ifaces
;
2824 wpas_p2p_service_flush(wpa_s
);
2826 if (global
->p2p
== NULL
)
2829 /* Remove remaining P2P group interfaces */
2830 while (wpa_s
&& wpa_s
->p2p_group_interface
!= NOT_P2P_GROUP_INTERFACE
)
2831 wpa_s
= wpa_s
->next
;
2833 tmp
= global
->ifaces
;
2836 tmp
->p2p_group_interface
== NOT_P2P_GROUP_INTERFACE
)) {
2841 /* Disconnect from the P2P group and deinit the interface */
2842 wpas_p2p_disconnect(tmp
);
2846 * Deinit GO data on any possibly remaining interface (if main
2847 * interface is used as GO).
2849 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
2850 if (wpa_s
->ap_iface
)
2851 wpas_p2p_group_deinit(wpa_s
);
2854 p2p_deinit(global
->p2p
);
2856 global
->p2p_init_wpa_s
= NULL
;
2860 static int wpas_p2p_create_iface(struct wpa_supplicant
*wpa_s
)
2862 if (wpa_s
->drv_flags
&
2863 (WPA_DRIVER_FLAGS_P2P_DEDICATED_INTERFACE
|
2864 WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P
))
2865 return 1; /* P2P group requires a new interface in every case
2867 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_CONCURRENT
))
2868 return 0; /* driver does not support concurrent operations */
2869 if (wpa_s
->global
->ifaces
->next
)
2870 return 1; /* more that one interface already in use */
2871 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
)
2872 return 1; /* this interface is already in use */
2877 static int wpas_p2p_start_go_neg(struct wpa_supplicant
*wpa_s
,
2878 const u8
*peer_addr
,
2879 enum p2p_wps_method wps_method
,
2880 int go_intent
, const u8
*own_interface_addr
,
2881 unsigned int force_freq
, int persistent_group
,
2882 struct wpa_ssid
*ssid
, unsigned int pref_freq
)
2884 if (persistent_group
&& wpa_s
->conf
->persistent_reconnect
)
2885 persistent_group
= 2;
2887 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
) {
2888 return wpa_drv_p2p_connect(wpa_s
, peer_addr
, wps_method
,
2889 go_intent
, own_interface_addr
,
2890 force_freq
, persistent_group
);
2894 * Increase GO config timeout if HT40 is used since it takes some time
2895 * to scan channels for coex purposes before the BSS can be started.
2897 p2p_set_config_timeout(wpa_s
->global
->p2p
,
2898 wpa_s
->p2p_go_ht40
? 255 : 100, 20);
2900 return p2p_connect(wpa_s
->global
->p2p
, peer_addr
, wps_method
,
2901 go_intent
, own_interface_addr
, force_freq
,
2902 persistent_group
, ssid
? ssid
->ssid
: NULL
,
2903 ssid
? ssid
->ssid_len
: 0,
2904 wpa_s
->p2p_pd_before_go_neg
, pref_freq
);
2908 static int wpas_p2p_auth_go_neg(struct wpa_supplicant
*wpa_s
,
2909 const u8
*peer_addr
,
2910 enum p2p_wps_method wps_method
,
2911 int go_intent
, const u8
*own_interface_addr
,
2912 unsigned int force_freq
, int persistent_group
,
2913 struct wpa_ssid
*ssid
, unsigned int pref_freq
)
2915 if (persistent_group
&& wpa_s
->conf
->persistent_reconnect
)
2916 persistent_group
= 2;
2918 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
)
2921 return p2p_authorize(wpa_s
->global
->p2p
, peer_addr
, wps_method
,
2922 go_intent
, own_interface_addr
, force_freq
,
2923 persistent_group
, ssid
? ssid
->ssid
: NULL
,
2924 ssid
? ssid
->ssid_len
: 0, pref_freq
);
2928 static void wpas_p2p_check_join_scan_limit(struct wpa_supplicant
*wpa_s
)
2930 wpa_s
->p2p_join_scan_count
++;
2931 wpa_printf(MSG_DEBUG
, "P2P: Join scan attempt %d",
2932 wpa_s
->p2p_join_scan_count
);
2933 if (wpa_s
->p2p_join_scan_count
> P2P_MAX_JOIN_SCAN_ATTEMPTS
) {
2934 wpa_printf(MSG_DEBUG
, "P2P: Failed to find GO " MACSTR
2935 " for join operationg - stop join attempt",
2936 MAC2STR(wpa_s
->pending_join_iface_addr
));
2937 eloop_cancel_timeout(wpas_p2p_join_scan
, wpa_s
, NULL
);
2938 if (wpa_s
->p2p_auto_pd
) {
2939 wpa_s
->p2p_auto_pd
= 0;
2940 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_PROV_DISC_FAILURE
2941 " p2p_dev_addr=" MACSTR
" status=N/A",
2942 MAC2STR(wpa_s
->pending_join_dev_addr
));
2945 wpa_msg(wpa_s
->parent
, MSG_INFO
,
2946 P2P_EVENT_GROUP_FORMATION_FAILURE
);
2951 static void wpas_p2p_pd_before_join_timeout(void *eloop_ctx
, void *timeout_ctx
)
2953 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
2954 if (!wpa_s
->pending_pd_before_join
)
2957 * Provision Discovery Response may have been lost - try to connect
2958 * anyway since we do not need any information from this PD.
2960 wpa_printf(MSG_DEBUG
, "P2P: PD timeout for join-existing-group - "
2961 "try to connect anyway");
2962 wpas_p2p_join_start(wpa_s
);
2966 static int wpas_check_freq_conflict(struct wpa_supplicant
*wpa_s
, int freq
)
2968 struct wpa_supplicant
*iface
;
2972 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_MULTI_CHANNEL_CONCURRENT
)
2975 for (iface
= wpa_s
->global
->ifaces
; iface
; iface
= iface
->next
) {
2976 if (!wpas_p2p_create_iface(wpa_s
) && iface
== wpa_s
)
2978 if (iface
->current_ssid
== NULL
|| iface
->assoc_freq
== 0)
2980 if (iface
->current_ssid
->mode
== WPAS_MODE_AP
||
2981 iface
->current_ssid
->mode
== WPAS_MODE_P2P_GO
)
2982 shared_freq
= iface
->current_ssid
->frequency
;
2983 else if (wpa_drv_get_bssid(iface
, bssid
) == 0)
2984 shared_freq
= iface
->assoc_freq
;
2988 if (shared_freq
&& freq
!= shared_freq
) {
2989 wpa_printf(MSG_DEBUG
, "P2P: Frequency conflict - %s "
2990 "connected on %d MHz - new connection on "
2991 "%d MHz", iface
->ifname
, shared_freq
, freq
);
2996 shared_freq
= wpa_drv_shared_freq(wpa_s
);
2997 if (shared_freq
> 0 && shared_freq
!= freq
) {
2998 wpa_printf(MSG_DEBUG
, "P2P: Frequency conflict - shared "
2999 "virtual interface connected on %d MHz - new "
3000 "connection on %d MHz", shared_freq
, freq
);
3008 static int wpas_p2p_peer_go(struct wpa_supplicant
*wpa_s
,
3009 const u8
*peer_dev_addr
)
3011 struct wpa_bss
*bss
;
3014 bss
= wpa_bss_get_p2p_dev_addr(wpa_s
, peer_dev_addr
);
3017 if (bss
->last_update_idx
< wpa_s
->bss_update_idx
) {
3018 wpa_printf(MSG_DEBUG
, "P2P: Peer BSS entry not updated in the "
3023 updated
= os_time_before(&wpa_s
->p2p_auto_started
, &bss
->last_update
);
3024 wpa_printf(MSG_DEBUG
, "P2P: Current BSS entry for peer updated at "
3025 "%ld.%06ld (%supdated in last scan)",
3026 bss
->last_update
.sec
, bss
->last_update
.usec
,
3027 updated
? "": "not ");
3033 static void wpas_p2p_scan_res_join(struct wpa_supplicant
*wpa_s
,
3034 struct wpa_scan_results
*scan_res
)
3036 struct wpa_bss
*bss
;
3038 u8 iface_addr
[ETH_ALEN
];
3040 eloop_cancel_timeout(wpas_p2p_join_scan
, wpa_s
, NULL
);
3042 if (wpa_s
->global
->p2p_disabled
)
3045 wpa_printf(MSG_DEBUG
, "P2P: Scan results received (%d BSS) for %sjoin",
3046 scan_res
? (int) scan_res
->num
: -1,
3047 wpa_s
->p2p_auto_join
? "auto_" : "");
3050 wpas_p2p_scan_res_handler(wpa_s
, scan_res
);
3052 if (wpa_s
->p2p_auto_pd
) {
3053 int join
= wpas_p2p_peer_go(wpa_s
,
3054 wpa_s
->pending_join_dev_addr
);
3056 wpa_s
->auto_pd_scan_retry
< P2P_AUTO_PD_SCAN_ATTEMPTS
) {
3057 wpa_s
->auto_pd_scan_retry
++;
3058 bss
= wpa_bss_get_bssid(wpa_s
,
3059 wpa_s
->pending_join_dev_addr
);
3062 wpa_printf(MSG_DEBUG
, "P2P: Scan retry %d for "
3063 "the peer " MACSTR
" at %d MHz",
3064 wpa_s
->auto_pd_scan_retry
,
3066 pending_join_dev_addr
),
3068 wpas_p2p_join_scan_req(wpa_s
, freq
);
3076 wpa_s
->p2p_auto_pd
= 0;
3077 wpa_s
->pending_pd_use
= join
? AUTO_PD_JOIN
: AUTO_PD_GO_NEG
;
3078 wpa_printf(MSG_DEBUG
, "P2P: Auto PD with " MACSTR
" join=%d",
3079 MAC2STR(wpa_s
->pending_join_dev_addr
), join
);
3080 if (p2p_prov_disc_req(wpa_s
->global
->p2p
,
3081 wpa_s
->pending_join_dev_addr
,
3082 wpa_s
->pending_pd_config_methods
, join
,
3084 wpa_s
->p2p_auto_pd
= 0;
3085 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_PROV_DISC_FAILURE
3086 " p2p_dev_addr=" MACSTR
" status=N/A",
3087 MAC2STR(wpa_s
->pending_join_dev_addr
));
3092 if (wpa_s
->p2p_auto_join
) {
3093 int join
= wpas_p2p_peer_go(wpa_s
,
3094 wpa_s
->pending_join_dev_addr
);
3096 wpa_printf(MSG_DEBUG
, "P2P: Peer was not found to be "
3097 "running a GO -> use GO Negotiation");
3098 wpas_p2p_connect(wpa_s
, wpa_s
->pending_join_dev_addr
,
3099 wpa_s
->p2p_pin
, wpa_s
->p2p_wps_method
,
3100 wpa_s
->p2p_persistent_group
, 0, 0, 0,
3101 wpa_s
->p2p_go_intent
,
3102 wpa_s
->p2p_connect_freq
,
3103 wpa_s
->p2p_persistent_id
,
3104 wpa_s
->p2p_pd_before_go_neg
,
3105 wpa_s
->p2p_go_ht40
);
3109 wpa_printf(MSG_DEBUG
, "P2P: Peer was found running GO%s -> "
3110 "try to join the group", join
? "" :
3113 wpa_s
->p2p_fallback_to_go_neg
= 1;
3116 freq
= p2p_get_oper_freq(wpa_s
->global
->p2p
,
3117 wpa_s
->pending_join_iface_addr
);
3119 p2p_get_interface_addr(wpa_s
->global
->p2p
,
3120 wpa_s
->pending_join_dev_addr
,
3122 os_memcmp(iface_addr
, wpa_s
->pending_join_dev_addr
, ETH_ALEN
) != 0)
3124 wpa_printf(MSG_DEBUG
, "P2P: Overwrite pending interface "
3125 "address for join from " MACSTR
" to " MACSTR
3126 " based on newly discovered P2P peer entry",
3127 MAC2STR(wpa_s
->pending_join_iface_addr
),
3128 MAC2STR(iface_addr
));
3129 os_memcpy(wpa_s
->pending_join_iface_addr
, iface_addr
,
3132 freq
= p2p_get_oper_freq(wpa_s
->global
->p2p
,
3133 wpa_s
->pending_join_iface_addr
);
3136 wpa_printf(MSG_DEBUG
, "P2P: Target GO operating frequency "
3137 "from P2P peer table: %d MHz", freq
);
3139 bss
= wpa_bss_get_bssid(wpa_s
, wpa_s
->pending_join_iface_addr
);
3142 wpa_printf(MSG_DEBUG
, "P2P: Target GO operating frequency "
3143 "from BSS table: %d MHz", freq
);
3148 if (wpas_check_freq_conflict(wpa_s
, freq
) > 0) {
3149 wpa_msg(wpa_s
->parent
, MSG_INFO
,
3150 P2P_EVENT_GROUP_FORMATION_FAILURE
3151 "reason=FREQ_CONFLICT");
3155 wpa_printf(MSG_DEBUG
, "P2P: Send Provision Discovery Request "
3156 "prior to joining an existing group (GO " MACSTR
3158 MAC2STR(wpa_s
->pending_join_dev_addr
), freq
);
3159 wpa_s
->pending_pd_before_join
= 1;
3161 switch (wpa_s
->pending_join_wps_method
) {
3162 case WPS_PIN_DISPLAY
:
3163 method
= WPS_CONFIG_KEYPAD
;
3165 case WPS_PIN_KEYPAD
:
3166 method
= WPS_CONFIG_DISPLAY
;
3169 method
= WPS_CONFIG_PUSHBUTTON
;
3176 if ((p2p_get_provisioning_info(wpa_s
->global
->p2p
,
3177 wpa_s
->pending_join_dev_addr
) ==
3180 * We have already performed provision discovery for
3181 * joining the group. Proceed directly to join
3182 * operation without duplicated provision discovery. */
3183 wpa_printf(MSG_DEBUG
, "P2P: Provision discovery "
3184 "with " MACSTR
" already done - proceed to "
3186 MAC2STR(wpa_s
->pending_join_dev_addr
));
3187 wpa_s
->pending_pd_before_join
= 0;
3191 if (p2p_prov_disc_req(wpa_s
->global
->p2p
,
3192 wpa_s
->pending_join_dev_addr
, method
, 1,
3194 wpa_printf(MSG_DEBUG
, "P2P: Failed to send Provision "
3195 "Discovery Request before joining an "
3197 wpa_s
->pending_pd_before_join
= 0;
3202 * Actual join operation will be started from the Action frame
3203 * TX status callback (if no ACK is received) or when the
3204 * Provision Discovery Response is received. Use a short
3205 * timeout as a backup mechanism should the Provision Discovery
3206 * Response be lost for any reason.
3208 eloop_cancel_timeout(wpas_p2p_pd_before_join_timeout
, wpa_s
,
3210 eloop_register_timeout(2, 0, wpas_p2p_pd_before_join_timeout
,
3215 wpa_printf(MSG_DEBUG
, "P2P: Failed to find BSS/GO - try again later");
3216 eloop_cancel_timeout(wpas_p2p_join_scan
, wpa_s
, NULL
);
3217 eloop_register_timeout(1, 0, wpas_p2p_join_scan
, wpa_s
, NULL
);
3218 wpas_p2p_check_join_scan_limit(wpa_s
);
3222 /* Start join operation immediately */
3223 wpas_p2p_join_start(wpa_s
);
3227 static void wpas_p2p_join_scan_req(struct wpa_supplicant
*wpa_s
, int freq
)
3230 struct wpa_driver_scan_params params
;
3231 struct wpabuf
*wps_ie
, *ies
;
3233 int freqs
[2] = { 0, 0 };
3235 os_memset(¶ms
, 0, sizeof(params
));
3237 /* P2P Wildcard SSID */
3238 params
.num_ssids
= 1;
3239 params
.ssids
[0].ssid
= (u8
*) P2P_WILDCARD_SSID
;
3240 params
.ssids
[0].ssid_len
= P2P_WILDCARD_SSID_LEN
;
3242 wpa_s
->wps
->dev
.p2p
= 1;
3243 wps_ie
= wps_build_probe_req_ie(DEV_PW_DEFAULT
, &wpa_s
->wps
->dev
,
3244 wpa_s
->wps
->uuid
, WPS_REQ_ENROLLEE
, 0,
3246 if (wps_ie
== NULL
) {
3247 wpas_p2p_scan_res_join(wpa_s
, NULL
);
3251 ielen
= p2p_scan_ie_buf_len(wpa_s
->global
->p2p
);
3252 ies
= wpabuf_alloc(wpabuf_len(wps_ie
) + ielen
);
3254 wpabuf_free(wps_ie
);
3255 wpas_p2p_scan_res_join(wpa_s
, NULL
);
3258 wpabuf_put_buf(ies
, wps_ie
);
3259 wpabuf_free(wps_ie
);
3261 p2p_scan_ie(wpa_s
->global
->p2p
, ies
, NULL
);
3263 params
.p2p_probe
= 1;
3264 params
.extra_ies
= wpabuf_head(ies
);
3265 params
.extra_ies_len
= wpabuf_len(ies
);
3268 params
.freqs
= freqs
;
3272 * Run a scan to update BSS table and start Provision Discovery once
3273 * the new scan results become available.
3275 ret
= wpa_drv_scan(wpa_s
, ¶ms
);
3277 wpa_s
->scan_res_handler
= wpas_p2p_scan_res_join
;
3282 wpa_printf(MSG_DEBUG
, "P2P: Failed to start scan for join - "
3284 eloop_cancel_timeout(wpas_p2p_join_scan
, wpa_s
, NULL
);
3285 eloop_register_timeout(1, 0, wpas_p2p_join_scan
, wpa_s
, NULL
);
3286 wpas_p2p_check_join_scan_limit(wpa_s
);
3291 static void wpas_p2p_join_scan(void *eloop_ctx
, void *timeout_ctx
)
3293 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
3294 wpas_p2p_join_scan_req(wpa_s
, 0);
3298 static int wpas_p2p_join(struct wpa_supplicant
*wpa_s
, const u8
*iface_addr
,
3299 const u8
*dev_addr
, enum p2p_wps_method wps_method
,
3302 wpa_printf(MSG_DEBUG
, "P2P: Request to join existing group (iface "
3303 MACSTR
" dev " MACSTR
")%s",
3304 MAC2STR(iface_addr
), MAC2STR(dev_addr
),
3305 auto_join
? " (auto_join)" : "");
3307 wpa_s
->p2p_auto_pd
= 0;
3308 wpa_s
->p2p_auto_join
= !!auto_join
;
3309 os_memcpy(wpa_s
->pending_join_iface_addr
, iface_addr
, ETH_ALEN
);
3310 os_memcpy(wpa_s
->pending_join_dev_addr
, dev_addr
, ETH_ALEN
);
3311 wpa_s
->pending_join_wps_method
= wps_method
;
3313 /* Make sure we are not running find during connection establishment */
3314 wpas_p2p_stop_find(wpa_s
);
3316 wpa_s
->p2p_join_scan_count
= 0;
3317 wpas_p2p_join_scan(wpa_s
, NULL
);
3322 static int wpas_p2p_join_start(struct wpa_supplicant
*wpa_s
)
3324 struct wpa_supplicant
*group
;
3325 struct p2p_go_neg_results res
;
3326 struct wpa_bss
*bss
;
3328 eloop_cancel_timeout(wpas_p2p_pd_before_join_timeout
, wpa_s
, NULL
);
3329 group
= wpas_p2p_get_group_iface(wpa_s
, 0, 0);
3332 if (group
!= wpa_s
) {
3333 os_memcpy(group
->p2p_pin
, wpa_s
->p2p_pin
,
3334 sizeof(group
->p2p_pin
));
3335 group
->p2p_wps_method
= wpa_s
->p2p_wps_method
;
3338 group
->p2p_in_provisioning
= 1;
3339 group
->p2p_fallback_to_go_neg
= wpa_s
->p2p_fallback_to_go_neg
;
3341 os_memset(&res
, 0, sizeof(res
));
3342 os_memcpy(res
.peer_interface_addr
, wpa_s
->pending_join_iface_addr
,
3344 res
.wps_method
= wpa_s
->pending_join_wps_method
;
3345 bss
= wpa_bss_get_bssid(wpa_s
, wpa_s
->pending_join_iface_addr
);
3347 res
.freq
= bss
->freq
;
3348 res
.ssid_len
= bss
->ssid_len
;
3349 os_memcpy(res
.ssid
, bss
->ssid
, bss
->ssid_len
);
3352 if (wpa_s
->off_channel_freq
|| wpa_s
->roc_waiting_drv_freq
) {
3353 wpa_printf(MSG_DEBUG
, "P2P: Cancel remain-on-channel prior to "
3355 wpa_drv_cancel_remain_on_channel(wpa_s
);
3356 wpa_s
->off_channel_freq
= 0;
3357 wpa_s
->roc_waiting_drv_freq
= 0;
3359 wpas_start_wps_enrollee(group
, &res
);
3362 * Allow a longer timeout for join-a-running-group than normal 15
3363 * second group formation timeout since the GO may not have authorized
3364 * our connection yet.
3366 eloop_cancel_timeout(wpas_p2p_group_formation_timeout
, wpa_s
, NULL
);
3367 eloop_register_timeout(60, 0, wpas_p2p_group_formation_timeout
,
3375 * wpas_p2p_connect - Request P2P Group Formation to be started
3376 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
3377 * @peer_addr: Address of the peer P2P Device
3378 * @pin: PIN to use during provisioning or %NULL to indicate PBC mode
3379 * @persistent_group: Whether to create a persistent group
3380 * @auto_join: Whether to select join vs. GO Negotiation automatically
3381 * @join: Whether to join an existing group (as a client) instead of starting
3382 * Group Owner negotiation; @peer_addr is BSSID in that case
3383 * @auth: Whether to only authorize the connection instead of doing that and
3384 * initiating Group Owner negotiation
3385 * @go_intent: GO Intent or -1 to use default
3386 * @freq: Frequency for the group or 0 for auto-selection
3387 * @persistent_id: Persistent group credentials to use for forcing GO
3388 * parameters or -1 to generate new values (SSID/passphrase)
3389 * @pd: Whether to send Provision Discovery prior to GO Negotiation as an
3390 * interoperability workaround when initiating group formation
3391 * @ht40: Start GO with 40 MHz channel width
3392 * Returns: 0 or new PIN (if pin was %NULL) on success, -1 on unspecified
3393 * failure, -2 on failure due to channel not currently available,
3394 * -3 if forced channel is not supported
3396 int wpas_p2p_connect(struct wpa_supplicant
*wpa_s
, const u8
*peer_addr
,
3397 const char *pin
, enum p2p_wps_method wps_method
,
3398 int persistent_group
, int auto_join
, int join
, int auth
,
3399 int go_intent
, int freq
, int persistent_id
, int pd
,
3402 int force_freq
= 0, pref_freq
= 0, oper_freq
= 0;
3405 enum wpa_driver_if_type iftype
;
3407 struct wpa_ssid
*ssid
= NULL
;
3409 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
3412 if (persistent_id
>= 0) {
3413 ssid
= wpa_config_get_network(wpa_s
->conf
, persistent_id
);
3414 if (ssid
== NULL
|| ssid
->disabled
!= 2 ||
3415 ssid
->mode
!= WPAS_MODE_P2P_GO
)
3420 go_intent
= wpa_s
->conf
->p2p_go_intent
;
3423 wpa_s
->p2p_long_listen
= 0;
3425 wpa_s
->p2p_wps_method
= wps_method
;
3426 wpa_s
->p2p_persistent_group
= !!persistent_group
;
3427 wpa_s
->p2p_persistent_id
= persistent_id
;
3428 wpa_s
->p2p_go_intent
= go_intent
;
3429 wpa_s
->p2p_connect_freq
= freq
;
3430 wpa_s
->p2p_fallback_to_go_neg
= 0;
3431 wpa_s
->p2p_pd_before_go_neg
= !!pd
;
3432 wpa_s
->p2p_go_ht40
= !!ht40
;
3435 os_strlcpy(wpa_s
->p2p_pin
, pin
, sizeof(wpa_s
->p2p_pin
));
3436 else if (wps_method
== WPS_PIN_DISPLAY
) {
3437 ret
= wps_generate_pin();
3438 os_snprintf(wpa_s
->p2p_pin
, sizeof(wpa_s
->p2p_pin
), "%08d",
3440 wpa_printf(MSG_DEBUG
, "P2P: Randomly generated PIN: %s",
3443 wpa_s
->p2p_pin
[0] = '\0';
3445 if (join
|| auto_join
) {
3446 u8 iface_addr
[ETH_ALEN
], dev_addr
[ETH_ALEN
];
3448 wpa_printf(MSG_DEBUG
, "P2P: Authorize invitation to "
3449 "connect a running group from " MACSTR
,
3450 MAC2STR(peer_addr
));
3451 os_memcpy(wpa_s
->p2p_auth_invite
, peer_addr
, ETH_ALEN
);
3454 os_memcpy(dev_addr
, peer_addr
, ETH_ALEN
);
3455 if (p2p_get_interface_addr(wpa_s
->global
->p2p
, peer_addr
,
3457 os_memcpy(iface_addr
, peer_addr
, ETH_ALEN
);
3458 p2p_get_dev_addr(wpa_s
->global
->p2p
, peer_addr
,
3462 os_get_time(&wpa_s
->p2p_auto_started
);
3463 wpa_printf(MSG_DEBUG
, "P2P: Auto join started at "
3465 wpa_s
->p2p_auto_started
.sec
,
3466 wpa_s
->p2p_auto_started
.usec
);
3468 if (wpas_p2p_join(wpa_s
, iface_addr
, dev_addr
, wps_method
,
3474 if (wpa_s
->current_ssid
&& wpa_drv_get_bssid(wpa_s
, bssid
) == 0 &&
3476 oper_freq
= wpa_s
->assoc_freq
;
3478 oper_freq
= wpa_drv_shared_freq(wpa_s
);
3484 if (!p2p_supported_freq(wpa_s
->global
->p2p
, freq
)) {
3485 wpa_printf(MSG_DEBUG
, "P2P: The forced channel "
3486 "(%u MHz) is not supported for P2P uses",
3491 if (oper_freq
> 0 && freq
!= oper_freq
&&
3492 !(wpa_s
->drv_flags
&
3493 WPA_DRIVER_FLAGS_MULTI_CHANNEL_CONCURRENT
)) {
3494 wpa_printf(MSG_DEBUG
, "P2P: Cannot start P2P group "
3495 "on %u MHz while connected on another "
3496 "channel (%u MHz)", freq
, oper_freq
);
3499 wpa_printf(MSG_DEBUG
, "P2P: Trying to force us to use the "
3500 "requested channel (%u MHz)", freq
);
3502 } else if (oper_freq
> 0 &&
3503 !p2p_supported_freq(wpa_s
->global
->p2p
, oper_freq
)) {
3504 if (!(wpa_s
->drv_flags
&
3505 WPA_DRIVER_FLAGS_MULTI_CHANNEL_CONCURRENT
)) {
3506 wpa_printf(MSG_DEBUG
, "P2P: Cannot start P2P group "
3507 "while connected on non-P2P supported "
3508 "channel (%u MHz)", oper_freq
);
3511 wpa_printf(MSG_DEBUG
, "P2P: Current operating channel "
3512 "(%u MHz) not available for P2P - try to use "
3513 "another channel", oper_freq
);
3515 } else if (oper_freq
> 0 &&
3517 WPA_DRIVER_FLAGS_MULTI_CHANNEL_CONCURRENT
)) {
3518 wpa_printf(MSG_DEBUG
, "P2P: Trying to prefer the channel we "
3519 "are already using (%u MHz) on another interface",
3521 pref_freq
= oper_freq
;
3522 } else if (oper_freq
> 0) {
3523 wpa_printf(MSG_DEBUG
, "P2P: Trying to force us to use the "
3524 "channel we are already using (%u MHz) on another "
3525 "interface", oper_freq
);
3526 force_freq
= oper_freq
;
3529 wpa_s
->create_p2p_iface
= wpas_p2p_create_iface(wpa_s
);
3531 if (wpa_s
->create_p2p_iface
) {
3532 /* Prepare to add a new interface for the group */
3533 iftype
= WPA_IF_P2P_GROUP
;
3534 if (go_intent
== 15)
3535 iftype
= WPA_IF_P2P_GO
;
3536 if (wpas_p2p_add_group_interface(wpa_s
, iftype
) < 0) {
3537 wpa_printf(MSG_ERROR
, "P2P: Failed to allocate a new "
3538 "interface for the group");
3542 if_addr
= wpa_s
->pending_interface_addr
;
3544 if_addr
= wpa_s
->own_addr
;
3547 if (wpas_p2p_auth_go_neg(wpa_s
, peer_addr
, wps_method
,
3549 force_freq
, persistent_group
, ssid
,
3555 if (wpas_p2p_start_go_neg(wpa_s
, peer_addr
, wps_method
,
3556 go_intent
, if_addr
, force_freq
,
3557 persistent_group
, ssid
, pref_freq
) < 0) {
3558 if (wpa_s
->create_p2p_iface
)
3559 wpas_p2p_remove_pending_group_interface(wpa_s
);
3567 * wpas_p2p_remain_on_channel_cb - Indication of remain-on-channel start
3568 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
3569 * @freq: Frequency of the channel in MHz
3570 * @duration: Duration of the stay on the channel in milliseconds
3572 * This callback is called when the driver indicates that it has started the
3573 * requested remain-on-channel duration.
3575 void wpas_p2p_remain_on_channel_cb(struct wpa_supplicant
*wpa_s
,
3576 unsigned int freq
, unsigned int duration
)
3578 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
3580 if (wpa_s
->off_channel_freq
== wpa_s
->pending_listen_freq
) {
3581 p2p_listen_cb(wpa_s
->global
->p2p
, wpa_s
->pending_listen_freq
,
3582 wpa_s
->pending_listen_duration
);
3583 wpa_s
->pending_listen_freq
= 0;
3588 static int wpas_p2p_listen_start(struct wpa_supplicant
*wpa_s
,
3589 unsigned int timeout
)
3591 /* Limit maximum Listen state time based on driver limitation. */
3592 if (timeout
> wpa_s
->max_remain_on_chan
)
3593 timeout
= wpa_s
->max_remain_on_chan
;
3595 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
)
3596 return wpa_drv_p2p_listen(wpa_s
, timeout
);
3598 return p2p_listen(wpa_s
->global
->p2p
, timeout
);
3603 * wpas_p2p_cancel_remain_on_channel_cb - Remain-on-channel timeout
3604 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
3605 * @freq: Frequency of the channel in MHz
3607 * This callback is called when the driver indicates that a remain-on-channel
3608 * operation has been completed, i.e., the duration on the requested channel
3611 void wpas_p2p_cancel_remain_on_channel_cb(struct wpa_supplicant
*wpa_s
,
3614 wpa_printf(MSG_DEBUG
, "P2P: Cancel remain-on-channel callback "
3615 "(p2p_long_listen=%d ms pending_action_tx=%p)",
3616 wpa_s
->p2p_long_listen
, wpa_s
->pending_action_tx
);
3617 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
3619 if (p2p_listen_end(wpa_s
->global
->p2p
, freq
) > 0)
3620 return; /* P2P module started a new operation */
3621 if (wpa_s
->pending_action_tx
)
3623 if (wpa_s
->p2p_long_listen
> 0)
3624 wpa_s
->p2p_long_listen
-= wpa_s
->max_remain_on_chan
;
3625 if (wpa_s
->p2p_long_listen
> 0) {
3626 wpa_printf(MSG_DEBUG
, "P2P: Continuing long Listen state");
3627 wpas_p2p_listen_start(wpa_s
, wpa_s
->p2p_long_listen
);
3633 * wpas_p2p_group_remove - Remove a P2P group
3634 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
3635 * @ifname: Network interface name of the group interface or "*" to remove all
3637 * Returns: 0 on success, -1 on failure
3639 * This function is used to remove a P2P group. This can be used to disconnect
3640 * from a group in which the local end is a P2P Client or to end a P2P Group in
3641 * case the local end is the Group Owner. If a virtual network interface was
3642 * created for this group, that interface will be removed. Otherwise, only the
3643 * configured P2P group network will be removed from the interface.
3645 int wpas_p2p_group_remove(struct wpa_supplicant
*wpa_s
, const char *ifname
)
3647 struct wpa_global
*global
= wpa_s
->global
;
3649 if (os_strcmp(ifname
, "*") == 0) {
3650 struct wpa_supplicant
*prev
;
3651 wpa_s
= global
->ifaces
;
3654 wpa_s
= wpa_s
->next
;
3655 wpas_p2p_disconnect(prev
);
3660 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
3661 if (os_strcmp(wpa_s
->ifname
, ifname
) == 0)
3665 return wpas_p2p_disconnect(wpa_s
);
3669 static int wpas_p2p_init_go_params(struct wpa_supplicant
*wpa_s
,
3670 struct p2p_go_neg_results
*params
,
3676 os_memset(params
, 0, sizeof(*params
));
3677 params
->role_go
= 1;
3678 params
->ht40
= ht40
;
3680 wpa_printf(MSG_DEBUG
, "P2P: Set GO freq based on forced "
3681 "frequency %d MHz", freq
);
3682 params
->freq
= freq
;
3683 } else if (wpa_s
->conf
->p2p_oper_reg_class
== 81 &&
3684 wpa_s
->conf
->p2p_oper_channel
>= 1 &&
3685 wpa_s
->conf
->p2p_oper_channel
<= 11) {
3686 params
->freq
= 2407 + 5 * wpa_s
->conf
->p2p_oper_channel
;
3687 wpa_printf(MSG_DEBUG
, "P2P: Set GO freq based on configured "
3688 "frequency %d MHz", params
->freq
);
3689 } else if (wpa_s
->conf
->p2p_oper_reg_class
== 115 ||
3690 wpa_s
->conf
->p2p_oper_reg_class
== 124) {
3691 params
->freq
= 5000 + 5 * wpa_s
->conf
->p2p_oper_channel
;
3692 wpa_printf(MSG_DEBUG
, "P2P: Set GO freq based on configured "
3693 "frequency %d MHz", params
->freq
);
3694 } else if (wpa_s
->conf
->p2p_oper_channel
== 0 &&
3695 wpa_s
->best_overall_freq
> 0 &&
3696 p2p_supported_freq(wpa_s
->global
->p2p
,
3697 wpa_s
->best_overall_freq
)) {
3698 params
->freq
= wpa_s
->best_overall_freq
;
3699 wpa_printf(MSG_DEBUG
, "P2P: Set GO freq based on best overall "
3700 "channel %d MHz", params
->freq
);
3701 } else if (wpa_s
->conf
->p2p_oper_channel
== 0 &&
3702 wpa_s
->best_24_freq
> 0 &&
3703 p2p_supported_freq(wpa_s
->global
->p2p
,
3704 wpa_s
->best_24_freq
)) {
3705 params
->freq
= wpa_s
->best_24_freq
;
3706 wpa_printf(MSG_DEBUG
, "P2P: Set GO freq based on best 2.4 GHz "
3707 "channel %d MHz", params
->freq
);
3708 } else if (wpa_s
->conf
->p2p_oper_channel
== 0 &&
3709 wpa_s
->best_5_freq
> 0 &&
3710 p2p_supported_freq(wpa_s
->global
->p2p
,
3711 wpa_s
->best_5_freq
)) {
3712 params
->freq
= wpa_s
->best_5_freq
;
3713 wpa_printf(MSG_DEBUG
, "P2P: Set GO freq based on best 5 GHz "
3714 "channel %d MHz", params
->freq
);
3717 for (chan
= 0; chan
< 11; chan
++) {
3718 params
->freq
= 2412 + chan
* 5;
3719 if (!wpas_p2p_disallowed_freq(wpa_s
->global
,
3724 wpa_printf(MSG_DEBUG
, "P2P: No 2.4 GHz channel "
3728 wpa_printf(MSG_DEBUG
, "P2P: Set GO freq %d MHz (no preference "
3729 "known)", params
->freq
);
3732 if (wpa_s
->current_ssid
&& wpa_drv_get_bssid(wpa_s
, bssid
) == 0 &&
3733 wpa_s
->assoc_freq
&& !freq
) {
3734 wpa_printf(MSG_DEBUG
, "P2P: Force GO on the channel we are "
3736 params
->freq
= wpa_s
->assoc_freq
;
3739 res
= wpa_drv_shared_freq(wpa_s
);
3740 if (res
> 0 && !freq
) {
3741 wpa_printf(MSG_DEBUG
, "P2P: Force GO on the channel we are "
3742 "already using on a shared interface");
3744 } else if (res
> 0 && freq
!= res
&&
3745 !(wpa_s
->drv_flags
&
3746 WPA_DRIVER_FLAGS_MULTI_CHANNEL_CONCURRENT
)) {
3747 wpa_printf(MSG_DEBUG
, "P2P: Cannot start P2P group on %u MHz "
3748 "while connected on another channel (%u MHz)",
3757 static struct wpa_supplicant
*
3758 wpas_p2p_get_group_iface(struct wpa_supplicant
*wpa_s
, int addr_allocated
,
3761 struct wpa_supplicant
*group_wpa_s
;
3763 if (!wpas_p2p_create_iface(wpa_s
)) {
3764 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Use same interface for group "
3769 if (wpas_p2p_add_group_interface(wpa_s
, go
? WPA_IF_P2P_GO
:
3770 WPA_IF_P2P_CLIENT
) < 0) {
3771 wpa_msg(wpa_s
, MSG_ERROR
, "P2P: Failed to add group interface");
3774 group_wpa_s
= wpas_p2p_init_group_interface(wpa_s
, go
);
3775 if (group_wpa_s
== NULL
) {
3776 wpa_msg(wpa_s
, MSG_ERROR
, "P2P: Failed to initialize group "
3778 wpas_p2p_remove_pending_group_interface(wpa_s
);
3782 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Use separate group interface %s",
3783 group_wpa_s
->ifname
);
3789 * wpas_p2p_group_add - Add a new P2P group with local end as Group Owner
3790 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
3791 * @persistent_group: Whether to create a persistent group
3792 * @freq: Frequency for the group or 0 to indicate no hardcoding
3793 * Returns: 0 on success, -1 on failure
3795 * This function creates a new P2P group with the local end as the Group Owner,
3796 * i.e., without using Group Owner Negotiation.
3798 int wpas_p2p_group_add(struct wpa_supplicant
*wpa_s
, int persistent_group
,
3801 struct p2p_go_neg_results params
;
3804 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
3807 /* Make sure we are not running find during connection establishment */
3808 wpa_printf(MSG_DEBUG
, "P2P: Stop any on-going P2P FIND");
3809 wpas_p2p_stop_find(wpa_s
);
3812 wpa_printf(MSG_DEBUG
, "P2P: Request to start GO on 2.4 GHz "
3814 if (wpa_s
->best_24_freq
> 0 &&
3815 p2p_supported_freq(wpa_s
->global
->p2p
,
3816 wpa_s
->best_24_freq
)) {
3817 freq
= wpa_s
->best_24_freq
;
3818 wpa_printf(MSG_DEBUG
, "P2P: Use best 2.4 GHz band "
3819 "channel: %d MHz", freq
);
3821 os_get_random((u8
*) &r
, sizeof(r
));
3822 freq
= 2412 + (r
% 3) * 25;
3823 wpa_printf(MSG_DEBUG
, "P2P: Use random 2.4 GHz band "
3824 "channel: %d MHz", freq
);
3829 wpa_printf(MSG_DEBUG
, "P2P: Request to start GO on 5 GHz "
3831 if (wpa_s
->best_5_freq
> 0 &&
3832 p2p_supported_freq(wpa_s
->global
->p2p
,
3833 wpa_s
->best_5_freq
)) {
3834 freq
= wpa_s
->best_5_freq
;
3835 wpa_printf(MSG_DEBUG
, "P2P: Use best 5 GHz band "
3836 "channel: %d MHz", freq
);
3838 os_get_random((u8
*) &r
, sizeof(r
));
3839 freq
= 5180 + (r
% 4) * 20;
3840 if (!p2p_supported_freq(wpa_s
->global
->p2p
, freq
)) {
3841 wpa_printf(MSG_DEBUG
, "P2P: Could not select "
3842 "5 GHz channel for P2P group");
3845 wpa_printf(MSG_DEBUG
, "P2P: Use random 5 GHz band "
3846 "channel: %d MHz", freq
);
3850 if (freq
> 0 && !p2p_supported_freq(wpa_s
->global
->p2p
, freq
)) {
3851 wpa_printf(MSG_DEBUG
, "P2P: The forced channel for GO "
3852 "(%u MHz) is not supported for P2P uses",
3857 if (wpas_p2p_init_go_params(wpa_s
, ¶ms
, freq
, ht40
))
3860 !p2p_supported_freq(wpa_s
->global
->p2p
, params
.freq
)) {
3861 wpa_printf(MSG_DEBUG
, "P2P: The selected channel for GO "
3862 "(%u MHz) is not supported for P2P uses",
3866 p2p_go_params(wpa_s
->global
->p2p
, ¶ms
);
3867 params
.persistent_group
= persistent_group
;
3869 wpa_s
= wpas_p2p_get_group_iface(wpa_s
, 0, 1);
3872 wpas_start_wps_go(wpa_s
, ¶ms
, 0);
3878 static int wpas_start_p2p_client(struct wpa_supplicant
*wpa_s
,
3879 struct wpa_ssid
*params
, int addr_allocated
)
3881 struct wpa_ssid
*ssid
;
3883 wpa_s
= wpas_p2p_get_group_iface(wpa_s
, addr_allocated
, 0);
3887 wpa_supplicant_ap_deinit(wpa_s
);
3889 ssid
= wpa_config_add_network(wpa_s
->conf
);
3892 wpa_config_set_network_defaults(ssid
);
3893 ssid
->temporary
= 1;
3894 ssid
->proto
= WPA_PROTO_RSN
;
3895 ssid
->pairwise_cipher
= WPA_CIPHER_CCMP
;
3896 ssid
->group_cipher
= WPA_CIPHER_CCMP
;
3897 ssid
->key_mgmt
= WPA_KEY_MGMT_PSK
;
3898 ssid
->ssid
= os_malloc(params
->ssid_len
);
3899 if (ssid
->ssid
== NULL
) {
3900 wpa_config_remove_network(wpa_s
->conf
, ssid
->id
);
3903 os_memcpy(ssid
->ssid
, params
->ssid
, params
->ssid_len
);
3904 ssid
->ssid_len
= params
->ssid_len
;
3905 ssid
->p2p_group
= 1;
3906 ssid
->export_keys
= 1;
3907 if (params
->psk_set
) {
3908 os_memcpy(ssid
->psk
, params
->psk
, 32);
3911 if (params
->passphrase
)
3912 ssid
->passphrase
= os_strdup(params
->passphrase
);
3914 wpa_supplicant_select_network(wpa_s
, ssid
);
3916 wpa_s
->show_group_started
= 1;
3922 int wpas_p2p_group_add_persistent(struct wpa_supplicant
*wpa_s
,
3923 struct wpa_ssid
*ssid
, int addr_allocated
,
3926 struct p2p_go_neg_results params
;
3929 if (ssid
->disabled
!= 2 || ssid
->ssid
== NULL
)
3932 if (wpas_get_p2p_group(wpa_s
, ssid
->ssid
, ssid
->ssid_len
, &go
) &&
3933 go
== (ssid
->mode
== WPAS_MODE_P2P_GO
)) {
3934 wpa_printf(MSG_DEBUG
, "P2P: Requested persistent group is "
3939 /* Make sure we are not running find during connection establishment */
3940 wpas_p2p_stop_find(wpa_s
);
3942 wpa_s
->p2p_fallback_to_go_neg
= 0;
3944 if (ssid
->mode
== WPAS_MODE_INFRA
)
3945 return wpas_start_p2p_client(wpa_s
, ssid
, addr_allocated
);
3947 if (ssid
->mode
!= WPAS_MODE_P2P_GO
)
3950 if (wpas_p2p_init_go_params(wpa_s
, ¶ms
, freq
, ht40
))
3954 if (ssid
->passphrase
== NULL
||
3955 os_strlen(ssid
->passphrase
) >= sizeof(params
.passphrase
)) {
3956 wpa_printf(MSG_DEBUG
, "P2P: Invalid passphrase in persistent "
3960 os_strlcpy(params
.passphrase
, ssid
->passphrase
,
3961 sizeof(params
.passphrase
));
3962 os_memcpy(params
.ssid
, ssid
->ssid
, ssid
->ssid_len
);
3963 params
.ssid_len
= ssid
->ssid_len
;
3964 params
.persistent_group
= 1;
3966 wpa_s
= wpas_p2p_get_group_iface(wpa_s
, addr_allocated
, 1);
3970 wpas_start_wps_go(wpa_s
, ¶ms
, 0);
3976 static void wpas_p2p_ie_update(void *ctx
, struct wpabuf
*beacon_ies
,
3977 struct wpabuf
*proberesp_ies
)
3979 struct wpa_supplicant
*wpa_s
= ctx
;
3980 if (wpa_s
->ap_iface
) {
3981 struct hostapd_data
*hapd
= wpa_s
->ap_iface
->bss
[0];
3982 if (!(hapd
->conf
->p2p
& P2P_GROUP_OWNER
)) {
3983 wpabuf_free(beacon_ies
);
3984 wpabuf_free(proberesp_ies
);
3988 wpabuf_free(hapd
->p2p_beacon_ie
);
3989 hapd
->p2p_beacon_ie
= beacon_ies
;
3991 wpabuf_free(hapd
->p2p_probe_resp_ie
);
3992 hapd
->p2p_probe_resp_ie
= proberesp_ies
;
3994 wpabuf_free(beacon_ies
);
3995 wpabuf_free(proberesp_ies
);
3997 wpa_supplicant_ap_update_beacon(wpa_s
);
4001 static void wpas_p2p_idle_update(void *ctx
, int idle
)
4003 struct wpa_supplicant
*wpa_s
= ctx
;
4004 if (!wpa_s
->ap_iface
)
4006 wpa_printf(MSG_DEBUG
, "P2P: GO - group %sidle", idle
? "" : "not ");
4008 wpas_p2p_set_group_idle_timeout(wpa_s
);
4010 eloop_cancel_timeout(wpas_p2p_group_idle_timeout
, wpa_s
, NULL
);
4014 struct p2p_group
* wpas_p2p_group_init(struct wpa_supplicant
*wpa_s
,
4015 struct wpa_ssid
*ssid
)
4017 struct p2p_group
*group
;
4018 struct p2p_group_config
*cfg
;
4020 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
)
4022 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
4025 cfg
= os_zalloc(sizeof(*cfg
));
4029 if (ssid
->p2p_persistent_group
&& wpa_s
->conf
->persistent_reconnect
)
4030 cfg
->persistent_group
= 2;
4031 else if (ssid
->p2p_persistent_group
)
4032 cfg
->persistent_group
= 1;
4033 os_memcpy(cfg
->interface_addr
, wpa_s
->own_addr
, ETH_ALEN
);
4034 if (wpa_s
->max_stations
&&
4035 wpa_s
->max_stations
< wpa_s
->conf
->max_num_sta
)
4036 cfg
->max_clients
= wpa_s
->max_stations
;
4038 cfg
->max_clients
= wpa_s
->conf
->max_num_sta
;
4039 os_memcpy(cfg
->ssid
, ssid
->ssid
, ssid
->ssid_len
);
4040 cfg
->ssid_len
= ssid
->ssid_len
;
4041 cfg
->cb_ctx
= wpa_s
;
4042 cfg
->ie_update
= wpas_p2p_ie_update
;
4043 cfg
->idle_update
= wpas_p2p_idle_update
;
4045 group
= p2p_group_init(wpa_s
->global
->p2p
, cfg
);
4048 if (ssid
->mode
!= WPAS_MODE_P2P_GROUP_FORMATION
)
4049 p2p_group_notif_formation_done(group
);
4050 wpa_s
->p2p_group
= group
;
4055 void wpas_p2p_wps_success(struct wpa_supplicant
*wpa_s
, const u8
*peer_addr
,
4058 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
4060 if (!wpa_s
->p2p_in_provisioning
) {
4061 wpa_printf(MSG_DEBUG
, "P2P: Ignore WPS success event - P2P "
4062 "provisioning not in progress");
4066 if (ssid
&& ssid
->mode
== WPAS_MODE_INFRA
) {
4067 u8 go_dev_addr
[ETH_ALEN
];
4068 os_memcpy(go_dev_addr
, wpa_s
->bssid
, ETH_ALEN
);
4069 wpas_p2p_persistent_group(wpa_s
, go_dev_addr
, ssid
->ssid
,
4071 /* Clear any stored provisioning info */
4072 p2p_clear_provisioning_info(wpa_s
->global
->p2p
, go_dev_addr
);
4075 eloop_cancel_timeout(wpas_p2p_group_formation_timeout
, wpa_s
->parent
,
4077 if (ssid
&& ssid
->mode
== WPAS_MODE_INFRA
) {
4079 * Use a separate timeout for initial data connection to
4080 * complete to allow the group to be removed automatically if
4081 * something goes wrong in this step before the P2P group idle
4082 * timeout mechanism is taken into use.
4084 eloop_register_timeout(P2P_MAX_INITIAL_CONN_WAIT
, 0,
4085 wpas_p2p_group_formation_timeout
,
4086 wpa_s
->parent
, NULL
);
4088 if (wpa_s
->global
->p2p
)
4089 p2p_wps_success_cb(wpa_s
->global
->p2p
, peer_addr
);
4090 else if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
)
4091 wpa_drv_wps_success_cb(wpa_s
, peer_addr
);
4092 wpas_group_formation_completed(wpa_s
, 1);
4096 void wpas_p2p_wps_failed(struct wpa_supplicant
*wpa_s
,
4097 struct wps_event_fail
*fail
)
4099 if (!wpa_s
->p2p_in_provisioning
) {
4100 wpa_printf(MSG_DEBUG
, "P2P: Ignore WPS fail event - P2P "
4101 "provisioning not in progress");
4105 if (wpa_s
->go_params
) {
4106 p2p_clear_provisioning_info(
4108 wpa_s
->go_params
->peer_device_addr
);
4111 wpas_notify_p2p_wps_failed(wpa_s
, fail
);
4115 int wpas_p2p_prov_disc(struct wpa_supplicant
*wpa_s
, const u8
*peer_addr
,
4116 const char *config_method
,
4117 enum wpas_p2p_prov_disc_use use
)
4121 wpa_s
->p2p_fallback_to_go_neg
= 0;
4122 wpa_s
->pending_pd_use
= NORMAL_PD
;
4123 if (os_strncmp(config_method
, "display", 7) == 0)
4124 config_methods
= WPS_CONFIG_DISPLAY
;
4125 else if (os_strncmp(config_method
, "keypad", 6) == 0)
4126 config_methods
= WPS_CONFIG_KEYPAD
;
4127 else if (os_strncmp(config_method
, "pbc", 3) == 0 ||
4128 os_strncmp(config_method
, "pushbutton", 10) == 0)
4129 config_methods
= WPS_CONFIG_PUSHBUTTON
;
4131 wpa_printf(MSG_DEBUG
, "P2P: Unknown config method");
4135 if (use
== WPAS_P2P_PD_AUTO
) {
4136 os_memcpy(wpa_s
->pending_join_dev_addr
, peer_addr
, ETH_ALEN
);
4137 wpa_s
->pending_pd_config_methods
= config_methods
;
4138 wpa_s
->p2p_auto_pd
= 1;
4139 wpa_s
->p2p_auto_join
= 0;
4140 wpa_s
->pending_pd_before_join
= 0;
4141 wpa_s
->auto_pd_scan_retry
= 0;
4142 wpas_p2p_stop_find(wpa_s
);
4143 wpa_s
->p2p_join_scan_count
= 0;
4144 os_get_time(&wpa_s
->p2p_auto_started
);
4145 wpa_printf(MSG_DEBUG
, "P2P: Auto PD started at %ld.%06ld",
4146 wpa_s
->p2p_auto_started
.sec
,
4147 wpa_s
->p2p_auto_started
.usec
);
4148 wpas_p2p_join_scan(wpa_s
, NULL
);
4152 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
) {
4153 return wpa_drv_p2p_prov_disc_req(wpa_s
, peer_addr
,
4155 use
== WPAS_P2P_PD_FOR_JOIN
);
4158 if (wpa_s
->global
->p2p
== NULL
|| wpa_s
->global
->p2p_disabled
)
4161 return p2p_prov_disc_req(wpa_s
->global
->p2p
, peer_addr
,
4162 config_methods
, use
== WPAS_P2P_PD_FOR_JOIN
,
4167 int wpas_p2p_scan_result_text(const u8
*ies
, size_t ies_len
, char *buf
,
4170 return p2p_scan_result_text(ies
, ies_len
, buf
, end
);
4174 static void wpas_p2p_clear_pending_action_tx(struct wpa_supplicant
*wpa_s
)
4176 if (!wpa_s
->pending_action_tx
)
4179 wpa_printf(MSG_DEBUG
, "P2P: Drop pending Action TX due to new "
4180 "operation request");
4181 wpabuf_free(wpa_s
->pending_action_tx
);
4182 wpa_s
->pending_action_tx
= NULL
;
4186 int wpas_p2p_find(struct wpa_supplicant
*wpa_s
, unsigned int timeout
,
4187 enum p2p_discovery_type type
,
4188 unsigned int num_req_dev_types
, const u8
*req_dev_types
,
4189 const u8
*dev_id
, unsigned int search_delay
)
4191 wpas_p2p_clear_pending_action_tx(wpa_s
);
4192 wpa_s
->p2p_long_listen
= 0;
4194 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
)
4195 return wpa_drv_p2p_find(wpa_s
, timeout
, type
);
4197 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
||
4198 wpa_s
->p2p_in_provisioning
)
4201 wpa_supplicant_cancel_sched_scan(wpa_s
);
4203 return p2p_find(wpa_s
->global
->p2p
, timeout
, type
,
4204 num_req_dev_types
, req_dev_types
, dev_id
,
4209 void wpas_p2p_stop_find(struct wpa_supplicant
*wpa_s
)
4211 wpas_p2p_clear_pending_action_tx(wpa_s
);
4212 wpa_s
->p2p_long_listen
= 0;
4213 eloop_cancel_timeout(wpas_p2p_long_listen_timeout
, wpa_s
, NULL
);
4214 eloop_cancel_timeout(wpas_p2p_join_scan
, wpa_s
, NULL
);
4215 wpa_s
->global
->p2p_cb_on_scan_complete
= 0;
4217 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
) {
4218 wpa_drv_p2p_stop_find(wpa_s
);
4222 if (wpa_s
->global
->p2p
)
4223 p2p_stop_find(wpa_s
->global
->p2p
);
4225 wpas_p2p_remove_pending_group_interface(wpa_s
);
4229 static void wpas_p2p_long_listen_timeout(void *eloop_ctx
, void *timeout_ctx
)
4231 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
4232 wpa_s
->p2p_long_listen
= 0;
4236 int wpas_p2p_listen(struct wpa_supplicant
*wpa_s
, unsigned int timeout
)
4240 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
4243 wpa_supplicant_cancel_sched_scan(wpa_s
);
4244 wpas_p2p_clear_pending_action_tx(wpa_s
);
4248 * This is a request for unlimited Listen state. However, at
4249 * least for now, this is mapped to a Listen state for one
4254 eloop_cancel_timeout(wpas_p2p_long_listen_timeout
, wpa_s
, NULL
);
4255 wpa_s
->p2p_long_listen
= 0;
4258 * Stop previous find/listen operation to avoid trying to request a new
4259 * remain-on-channel operation while the driver is still running the
4262 if (wpa_s
->global
->p2p
)
4263 p2p_stop_find(wpa_s
->global
->p2p
);
4265 res
= wpas_p2p_listen_start(wpa_s
, timeout
* 1000);
4266 if (res
== 0 && timeout
* 1000 > wpa_s
->max_remain_on_chan
) {
4267 wpa_s
->p2p_long_listen
= timeout
* 1000;
4268 eloop_register_timeout(timeout
, 0,
4269 wpas_p2p_long_listen_timeout
,
4277 int wpas_p2p_assoc_req_ie(struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
,
4278 u8
*buf
, size_t len
, int p2p_group
)
4280 struct wpabuf
*p2p_ie
;
4283 if (wpa_s
->global
->p2p_disabled
)
4285 if (wpa_s
->global
->p2p
== NULL
)
4290 p2p_ie
= wpa_bss_get_vendor_ie_multi(bss
, P2P_IE_VENDOR_TYPE
);
4291 ret
= p2p_assoc_req_ie(wpa_s
->global
->p2p
, bss
->bssid
, buf
, len
,
4293 wpabuf_free(p2p_ie
);
4299 int wpas_p2p_probe_req_rx(struct wpa_supplicant
*wpa_s
, const u8
*addr
,
4300 const u8
*dst
, const u8
*bssid
,
4301 const u8
*ie
, size_t ie_len
, int ssi_signal
)
4303 if (wpa_s
->global
->p2p_disabled
)
4305 if (wpa_s
->global
->p2p
== NULL
)
4308 switch (p2p_probe_req_rx(wpa_s
->global
->p2p
, addr
, dst
, bssid
,
4310 case P2P_PREQ_NOT_P2P
:
4311 wpas_notify_preq(wpa_s
, addr
, dst
, bssid
, ie
, ie_len
,
4314 case P2P_PREQ_MALFORMED
:
4315 case P2P_PREQ_NOT_LISTEN
:
4316 case P2P_PREQ_NOT_PROCESSED
:
4317 default: /* make gcc happy */
4319 case P2P_PREQ_PROCESSED
:
4325 void wpas_p2p_rx_action(struct wpa_supplicant
*wpa_s
, const u8
*da
,
4326 const u8
*sa
, const u8
*bssid
,
4327 u8 category
, const u8
*data
, size_t len
, int freq
)
4329 if (wpa_s
->global
->p2p_disabled
)
4331 if (wpa_s
->global
->p2p
== NULL
)
4334 p2p_rx_action(wpa_s
->global
->p2p
, da
, sa
, bssid
, category
, data
, len
,
4339 void wpas_p2p_scan_ie(struct wpa_supplicant
*wpa_s
, struct wpabuf
*ies
)
4341 if (wpa_s
->global
->p2p_disabled
)
4343 if (wpa_s
->global
->p2p
== NULL
)
4346 p2p_scan_ie(wpa_s
->global
->p2p
, ies
, NULL
);
4350 void wpas_p2p_group_deinit(struct wpa_supplicant
*wpa_s
)
4352 p2p_group_deinit(wpa_s
->p2p_group
);
4353 wpa_s
->p2p_group
= NULL
;
4355 wpa_s
->ap_configured_cb
= NULL
;
4356 wpa_s
->ap_configured_cb_ctx
= NULL
;
4357 wpa_s
->ap_configured_cb_data
= NULL
;
4358 wpa_s
->connect_without_scan
= NULL
;
4362 int wpas_p2p_reject(struct wpa_supplicant
*wpa_s
, const u8
*addr
)
4364 wpa_s
->p2p_long_listen
= 0;
4366 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
)
4367 return wpa_drv_p2p_reject(wpa_s
, addr
);
4369 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
4372 return p2p_reject(wpa_s
->global
->p2p
, addr
);
4376 /* Invite to reinvoke a persistent group */
4377 int wpas_p2p_invite(struct wpa_supplicant
*wpa_s
, const u8
*peer_addr
,
4378 struct wpa_ssid
*ssid
, const u8
*go_dev_addr
, int freq
,
4381 enum p2p_invite_role role
;
4384 wpa_s
->p2p_persistent_go_freq
= freq
;
4385 wpa_s
->p2p_go_ht40
= !!ht40
;
4386 if (ssid
->mode
== WPAS_MODE_P2P_GO
) {
4387 role
= P2P_INVITE_ROLE_GO
;
4388 if (peer_addr
== NULL
) {
4389 wpa_printf(MSG_DEBUG
, "P2P: Missing peer "
4390 "address in invitation command");
4393 if (wpas_p2p_create_iface(wpa_s
)) {
4394 if (wpas_p2p_add_group_interface(wpa_s
,
4395 WPA_IF_P2P_GO
) < 0) {
4396 wpa_printf(MSG_ERROR
, "P2P: Failed to "
4397 "allocate a new interface for the "
4401 bssid
= wpa_s
->pending_interface_addr
;
4403 bssid
= wpa_s
->own_addr
;
4405 role
= P2P_INVITE_ROLE_CLIENT
;
4406 peer_addr
= ssid
->bssid
;
4408 wpa_s
->pending_invite_ssid_id
= ssid
->id
;
4410 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
)
4411 return wpa_drv_p2p_invite(wpa_s
, peer_addr
, role
, bssid
,
4412 ssid
->ssid
, ssid
->ssid_len
,
4415 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
4418 return p2p_invite(wpa_s
->global
->p2p
, peer_addr
, role
, bssid
,
4419 ssid
->ssid
, ssid
->ssid_len
, freq
, go_dev_addr
, 1);
4423 /* Invite to join an active group */
4424 int wpas_p2p_invite_group(struct wpa_supplicant
*wpa_s
, const char *ifname
,
4425 const u8
*peer_addr
, const u8
*go_dev_addr
)
4427 struct wpa_global
*global
= wpa_s
->global
;
4428 enum p2p_invite_role role
;
4430 struct wpa_ssid
*ssid
;
4433 wpa_s
->p2p_persistent_go_freq
= 0;
4434 wpa_s
->p2p_go_ht40
= 0;
4436 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
4437 if (os_strcmp(wpa_s
->ifname
, ifname
) == 0)
4440 if (wpa_s
== NULL
) {
4441 wpa_printf(MSG_DEBUG
, "P2P: Interface '%s' not found", ifname
);
4445 ssid
= wpa_s
->current_ssid
;
4447 wpa_printf(MSG_DEBUG
, "P2P: No current SSID to use for "
4452 persistent
= ssid
->p2p_persistent_group
&&
4453 wpas_p2p_get_persistent(wpa_s
->parent
, peer_addr
,
4454 ssid
->ssid
, ssid
->ssid_len
);
4456 if (ssid
->mode
== WPAS_MODE_P2P_GO
) {
4457 role
= P2P_INVITE_ROLE_ACTIVE_GO
;
4458 bssid
= wpa_s
->own_addr
;
4459 if (go_dev_addr
== NULL
)
4460 go_dev_addr
= wpa_s
->global
->p2p_dev_addr
;
4462 role
= P2P_INVITE_ROLE_CLIENT
;
4463 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
) {
4464 wpa_printf(MSG_DEBUG
, "P2P: Not associated - cannot "
4465 "invite to current group");
4468 bssid
= wpa_s
->bssid
;
4469 if (go_dev_addr
== NULL
&&
4470 !is_zero_ether_addr(wpa_s
->go_dev_addr
))
4471 go_dev_addr
= wpa_s
->go_dev_addr
;
4473 wpa_s
->parent
->pending_invite_ssid_id
= -1;
4475 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
)
4476 return wpa_drv_p2p_invite(wpa_s
, peer_addr
, role
, bssid
,
4477 ssid
->ssid
, ssid
->ssid_len
,
4478 go_dev_addr
, persistent
);
4480 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
4483 return p2p_invite(wpa_s
->global
->p2p
, peer_addr
, role
, bssid
,
4484 ssid
->ssid
, ssid
->ssid_len
, wpa_s
->assoc_freq
,
4485 go_dev_addr
, persistent
);
4489 void wpas_p2p_completed(struct wpa_supplicant
*wpa_s
)
4491 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
4492 const char *ssid_txt
;
4493 u8 go_dev_addr
[ETH_ALEN
];
4494 int network_id
= -1;
4498 if (ssid
== NULL
|| ssid
->mode
!= WPAS_MODE_P2P_GROUP_FORMATION
) {
4499 eloop_cancel_timeout(wpas_p2p_group_formation_timeout
,
4500 wpa_s
->parent
, NULL
);
4503 if (!wpa_s
->show_group_started
|| !ssid
)
4506 wpa_s
->show_group_started
= 0;
4508 ssid_txt
= wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
);
4509 os_memset(go_dev_addr
, 0, ETH_ALEN
);
4510 if (ssid
->bssid_set
)
4511 os_memcpy(go_dev_addr
, ssid
->bssid
, ETH_ALEN
);
4512 persistent
= wpas_p2p_persistent_group(wpa_s
, go_dev_addr
, ssid
->ssid
,
4514 os_memcpy(wpa_s
->go_dev_addr
, go_dev_addr
, ETH_ALEN
);
4516 if (wpa_s
->global
->p2p_group_formation
== wpa_s
)
4517 wpa_s
->global
->p2p_group_formation
= NULL
;
4519 freq
= wpa_s
->current_bss
? wpa_s
->current_bss
->freq
:
4520 (int) wpa_s
->assoc_freq
;
4521 if (ssid
->passphrase
== NULL
&& ssid
->psk_set
) {
4523 wpa_snprintf_hex(psk
, sizeof(psk
), ssid
->psk
, 32);
4524 wpa_msg(wpa_s
->parent
, MSG_INFO
, P2P_EVENT_GROUP_STARTED
4525 "%s client ssid=\"%s\" freq=%d psk=%s go_dev_addr="
4527 wpa_s
->ifname
, ssid_txt
, freq
, psk
,
4528 MAC2STR(go_dev_addr
),
4529 persistent
? " [PERSISTENT]" : "");
4531 wpa_msg(wpa_s
->parent
, MSG_INFO
, P2P_EVENT_GROUP_STARTED
4532 "%s client ssid=\"%s\" freq=%d passphrase=\"%s\" "
4533 "go_dev_addr=" MACSTR
"%s",
4534 wpa_s
->ifname
, ssid_txt
, freq
,
4535 ssid
->passphrase
? ssid
->passphrase
: "",
4536 MAC2STR(go_dev_addr
),
4537 persistent
? " [PERSISTENT]" : "");
4541 network_id
= wpas_p2p_store_persistent_group(wpa_s
->parent
,
4544 network_id
= ssid
->id
;
4545 wpas_notify_p2p_group_started(wpa_s
, ssid
, network_id
, 1);
4548 if (wpa_s
->global
->p2p_cb_on_scan_complete
&& !wpa_s
->global
->p2p_disabled
&&
4549 wpa_s
->global
->p2p
!= NULL
) {
4550 wpa_s
->global
->p2p_cb_on_scan_complete
= 0;
4551 if (p2p_other_scan_completed(wpa_s
->global
->p2p
) == 1) {
4552 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Pending P2P operation "
4553 "continued after successful connection");
4554 p2p_increase_search_delay(
4556 wpas_p2p_search_delay(wpa_s
));
4562 int wpas_p2p_presence_req(struct wpa_supplicant
*wpa_s
, u32 duration1
,
4563 u32 interval1
, u32 duration2
, u32 interval2
)
4565 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
)
4567 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
4570 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
||
4571 wpa_s
->current_ssid
== NULL
||
4572 wpa_s
->current_ssid
->mode
!= WPAS_MODE_INFRA
)
4575 return p2p_presence_req(wpa_s
->global
->p2p
, wpa_s
->bssid
,
4576 wpa_s
->own_addr
, wpa_s
->assoc_freq
,
4577 duration1
, interval1
, duration2
, interval2
);
4581 int wpas_p2p_ext_listen(struct wpa_supplicant
*wpa_s
, unsigned int period
,
4582 unsigned int interval
)
4584 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
)
4587 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
4590 return p2p_ext_listen(wpa_s
->global
->p2p
, period
, interval
);
4594 static int wpas_p2p_is_client(struct wpa_supplicant
*wpa_s
)
4596 if (wpa_s
->current_ssid
== NULL
) {
4598 * current_ssid can be clearead when P2P client interface gets
4599 * disconnected, so assume this interface was used as P2P
4604 return wpa_s
->current_ssid
->p2p_group
&&
4605 wpa_s
->current_ssid
->mode
== WPAS_MODE_INFRA
;
4609 static void wpas_p2p_group_idle_timeout(void *eloop_ctx
, void *timeout_ctx
)
4611 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
4613 if (wpa_s
->conf
->p2p_group_idle
== 0 && !wpas_p2p_is_client(wpa_s
)) {
4614 wpa_printf(MSG_DEBUG
, "P2P: Ignore group idle timeout - "
4619 wpa_printf(MSG_DEBUG
, "P2P: Group idle timeout reached - terminate "
4621 wpas_p2p_group_delete(wpa_s
, P2P_GROUP_REMOVAL_IDLE_TIMEOUT
);
4625 static void wpas_p2p_set_group_idle_timeout(struct wpa_supplicant
*wpa_s
)
4629 if (eloop_cancel_timeout(wpas_p2p_group_idle_timeout
, wpa_s
, NULL
) > 0)
4630 wpa_printf(MSG_DEBUG
, "P2P: Cancelled P2P group idle timeout");
4632 if (wpa_s
->current_ssid
== NULL
|| !wpa_s
->current_ssid
->p2p_group
)
4635 timeout
= wpa_s
->conf
->p2p_group_idle
;
4636 if (wpa_s
->current_ssid
->mode
== WPAS_MODE_INFRA
&&
4637 (timeout
== 0 || timeout
> P2P_MAX_CLIENT_IDLE
))
4638 timeout
= P2P_MAX_CLIENT_IDLE
;
4644 if (wpa_s
->current_ssid
->mode
== WPAS_MODE_INFRA
)
4645 timeout
= 0; /* special client mode no-timeout */
4650 if (wpa_s
->p2p_in_provisioning
) {
4652 * Use the normal group formation timeout during the
4653 * provisioning phase to avoid terminating this process too
4654 * early due to group idle timeout.
4656 wpa_printf(MSG_DEBUG
, "P2P: Do not use P2P group idle timeout "
4657 "during provisioning");
4661 if (wpa_s
->show_group_started
) {
4663 * Use the normal group formation timeout between the end of
4664 * the provisioning phase and completion of 4-way handshake to
4665 * avoid terminating this process too early due to group idle
4668 wpa_printf(MSG_DEBUG
, "P2P: Do not use P2P group idle timeout "
4669 "while waiting for initial 4-way handshake to "
4674 wpa_printf(MSG_DEBUG
, "P2P: Set P2P group idle timeout to %u seconds",
4676 eloop_register_timeout(timeout
, 0, wpas_p2p_group_idle_timeout
,
4681 /* Returns 1 if the interface was removed */
4682 int wpas_p2p_deauth_notif(struct wpa_supplicant
*wpa_s
, const u8
*bssid
,
4683 u16 reason_code
, const u8
*ie
, size_t ie_len
,
4684 int locally_generated
)
4686 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
4688 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
)
4691 if (!locally_generated
)
4692 p2p_deauth_notif(wpa_s
->global
->p2p
, bssid
, reason_code
, ie
,
4695 if (reason_code
== WLAN_REASON_DEAUTH_LEAVING
&& !locally_generated
&&
4696 wpa_s
->current_ssid
&&
4697 wpa_s
->current_ssid
->p2p_group
&&
4698 wpa_s
->current_ssid
->mode
== WPAS_MODE_INFRA
) {
4699 wpa_printf(MSG_DEBUG
, "P2P: GO indicated that the P2P Group "
4700 "session is ending");
4701 if (wpas_p2p_group_delete(wpa_s
,
4702 P2P_GROUP_REMOVAL_GO_ENDING_SESSION
)
4711 void wpas_p2p_disassoc_notif(struct wpa_supplicant
*wpa_s
, const u8
*bssid
,
4712 u16 reason_code
, const u8
*ie
, size_t ie_len
,
4713 int locally_generated
)
4715 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
4717 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
)
4720 if (!locally_generated
)
4721 p2p_disassoc_notif(wpa_s
->global
->p2p
, bssid
, reason_code
, ie
,
4726 void wpas_p2p_update_config(struct wpa_supplicant
*wpa_s
)
4728 struct p2p_data
*p2p
= wpa_s
->global
->p2p
;
4733 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_CAPABLE
))
4736 if (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_DEVICE_NAME
)
4737 p2p_set_dev_name(p2p
, wpa_s
->conf
->device_name
);
4739 if (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_DEVICE_TYPE
)
4740 p2p_set_pri_dev_type(p2p
, wpa_s
->conf
->device_type
);
4743 (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_CONFIG_METHODS
))
4744 p2p_set_config_methods(p2p
, wpa_s
->wps
->config_methods
);
4746 if (wpa_s
->wps
&& (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_UUID
))
4747 p2p_set_uuid(p2p
, wpa_s
->wps
->uuid
);
4749 if (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_WPS_STRING
) {
4750 p2p_set_manufacturer(p2p
, wpa_s
->conf
->manufacturer
);
4751 p2p_set_model_name(p2p
, wpa_s
->conf
->model_name
);
4752 p2p_set_model_number(p2p
, wpa_s
->conf
->model_number
);
4753 p2p_set_serial_number(p2p
, wpa_s
->conf
->serial_number
);
4756 if (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_SEC_DEVICE_TYPE
)
4757 p2p_set_sec_dev_types(p2p
,
4758 (void *) wpa_s
->conf
->sec_device_type
,
4759 wpa_s
->conf
->num_sec_device_types
);
4761 if (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_VENDOR_EXTENSION
) {
4763 p2p_remove_wps_vendor_extensions(p2p
);
4764 for (i
= 0; i
< MAX_WPS_VENDOR_EXT
; i
++) {
4765 if (wpa_s
->conf
->wps_vendor_ext
[i
] == NULL
)
4767 p2p_add_wps_vendor_extension(
4768 p2p
, wpa_s
->conf
->wps_vendor_ext
[i
]);
4772 if ((wpa_s
->conf
->changed_parameters
& CFG_CHANGED_COUNTRY
) &&
4773 wpa_s
->conf
->country
[0] && wpa_s
->conf
->country
[1]) {
4775 country
[0] = wpa_s
->conf
->country
[0];
4776 country
[1] = wpa_s
->conf
->country
[1];
4778 p2p_set_country(p2p
, country
);
4781 if (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_P2P_SSID_POSTFIX
) {
4782 p2p_set_ssid_postfix(p2p
, (u8
*) wpa_s
->conf
->p2p_ssid_postfix
,
4783 wpa_s
->conf
->p2p_ssid_postfix
?
4784 os_strlen(wpa_s
->conf
->p2p_ssid_postfix
) :
4788 if (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_P2P_INTRA_BSS
)
4789 p2p_set_intra_bss_dist(p2p
, wpa_s
->conf
->p2p_intra_bss
);
4791 if (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_P2P_LISTEN_CHANNEL
) {
4792 u8 reg_class
, channel
;
4795 if (wpa_s
->conf
->p2p_listen_reg_class
&&
4796 wpa_s
->conf
->p2p_listen_channel
) {
4797 reg_class
= wpa_s
->conf
->p2p_listen_reg_class
;
4798 channel
= wpa_s
->conf
->p2p_listen_channel
;
4802 * Pick one of the social channels randomly as the
4805 os_get_random((u8
*) &r
, sizeof(r
));
4806 channel
= 1 + (r
% 3) * 5;
4808 ret
= p2p_set_listen_channel(p2p
, reg_class
, channel
);
4810 wpa_printf(MSG_ERROR
, "P2P: Own listen channel update "
4813 if (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_P2P_OPER_CHANNEL
) {
4814 u8 op_reg_class
, op_channel
, cfg_op_channel
;
4817 if (wpa_s
->conf
->p2p_oper_reg_class
&&
4818 wpa_s
->conf
->p2p_oper_channel
) {
4819 op_reg_class
= wpa_s
->conf
->p2p_oper_reg_class
;
4820 op_channel
= wpa_s
->conf
->p2p_oper_channel
;
4825 * Use random operation channel from (1, 6, 11)
4826 *if no other preference is indicated.
4828 os_get_random((u8
*) &r
, sizeof(r
));
4829 op_channel
= 1 + (r
% 3) * 5;
4832 ret
= p2p_set_oper_channel(p2p
, op_reg_class
, op_channel
,
4835 wpa_printf(MSG_ERROR
, "P2P: Own oper channel update "
4839 if (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_P2P_PREF_CHAN
) {
4840 if (p2p_set_pref_chan(p2p
, wpa_s
->conf
->num_p2p_pref_chan
,
4841 wpa_s
->conf
->p2p_pref_chan
) < 0) {
4842 wpa_printf(MSG_ERROR
, "P2P: Preferred channel list "
4849 int wpas_p2p_set_noa(struct wpa_supplicant
*wpa_s
, u8 count
, int start
,
4852 if (!wpa_s
->ap_iface
)
4854 return hostapd_p2p_set_noa(wpa_s
->ap_iface
->bss
[0], count
, start
,
4859 int wpas_p2p_set_cross_connect(struct wpa_supplicant
*wpa_s
, int enabled
)
4861 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
4863 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
)
4866 wpa_s
->global
->cross_connection
= enabled
;
4867 p2p_set_cross_connect(wpa_s
->global
->p2p
, enabled
);
4870 struct wpa_supplicant
*iface
;
4872 for (iface
= wpa_s
->global
->ifaces
; iface
; iface
= iface
->next
)
4874 if (iface
->cross_connect_enabled
== 0)
4877 iface
->cross_connect_enabled
= 0;
4878 iface
->cross_connect_in_use
= 0;
4879 wpa_msg(iface
->parent
, MSG_INFO
,
4880 P2P_EVENT_CROSS_CONNECT_DISABLE
"%s %s",
4881 iface
->ifname
, iface
->cross_connect_uplink
);
4889 static void wpas_p2p_enable_cross_connect(struct wpa_supplicant
*uplink
)
4891 struct wpa_supplicant
*iface
;
4893 if (!uplink
->global
->cross_connection
)
4896 for (iface
= uplink
->global
->ifaces
; iface
; iface
= iface
->next
) {
4897 if (!iface
->cross_connect_enabled
)
4899 if (os_strcmp(uplink
->ifname
, iface
->cross_connect_uplink
) !=
4902 if (iface
->ap_iface
== NULL
)
4904 if (iface
->cross_connect_in_use
)
4907 iface
->cross_connect_in_use
= 1;
4908 wpa_msg(iface
->parent
, MSG_INFO
,
4909 P2P_EVENT_CROSS_CONNECT_ENABLE
"%s %s",
4910 iface
->ifname
, iface
->cross_connect_uplink
);
4915 static void wpas_p2p_disable_cross_connect(struct wpa_supplicant
*uplink
)
4917 struct wpa_supplicant
*iface
;
4919 for (iface
= uplink
->global
->ifaces
; iface
; iface
= iface
->next
) {
4920 if (!iface
->cross_connect_enabled
)
4922 if (os_strcmp(uplink
->ifname
, iface
->cross_connect_uplink
) !=
4925 if (!iface
->cross_connect_in_use
)
4928 wpa_msg(iface
->parent
, MSG_INFO
,
4929 P2P_EVENT_CROSS_CONNECT_DISABLE
"%s %s",
4930 iface
->ifname
, iface
->cross_connect_uplink
);
4931 iface
->cross_connect_in_use
= 0;
4936 void wpas_p2p_notif_connected(struct wpa_supplicant
*wpa_s
)
4938 if (wpa_s
->ap_iface
|| wpa_s
->current_ssid
== NULL
||
4939 wpa_s
->current_ssid
->mode
!= WPAS_MODE_INFRA
||
4940 wpa_s
->cross_connect_disallowed
)
4941 wpas_p2p_disable_cross_connect(wpa_s
);
4943 wpas_p2p_enable_cross_connect(wpa_s
);
4944 if (!wpa_s
->ap_iface
&&
4945 eloop_cancel_timeout(wpas_p2p_group_idle_timeout
, wpa_s
, NULL
) > 0)
4946 wpa_printf(MSG_DEBUG
, "P2P: Cancelled P2P group idle timeout");
4950 void wpas_p2p_notif_disconnected(struct wpa_supplicant
*wpa_s
)
4952 wpas_p2p_disable_cross_connect(wpa_s
);
4953 if (!wpa_s
->ap_iface
&&
4954 !eloop_is_timeout_registered(wpas_p2p_group_idle_timeout
,
4956 wpas_p2p_set_group_idle_timeout(wpa_s
);
4960 static void wpas_p2p_cross_connect_setup(struct wpa_supplicant
*wpa_s
)
4962 struct wpa_supplicant
*iface
;
4964 if (!wpa_s
->global
->cross_connection
)
4967 for (iface
= wpa_s
->global
->ifaces
; iface
; iface
= iface
->next
) {
4970 if (iface
->drv_flags
&
4971 WPA_DRIVER_FLAGS_P2P_DEDICATED_INTERFACE
)
4973 if (iface
->drv_flags
& WPA_DRIVER_FLAGS_P2P_CAPABLE
)
4976 wpa_s
->cross_connect_enabled
= 1;
4977 os_strlcpy(wpa_s
->cross_connect_uplink
, iface
->ifname
,
4978 sizeof(wpa_s
->cross_connect_uplink
));
4979 wpa_printf(MSG_DEBUG
, "P2P: Enable cross connection from "
4980 "%s to %s whenever uplink is available",
4981 wpa_s
->ifname
, wpa_s
->cross_connect_uplink
);
4983 if (iface
->ap_iface
|| iface
->current_ssid
== NULL
||
4984 iface
->current_ssid
->mode
!= WPAS_MODE_INFRA
||
4985 iface
->cross_connect_disallowed
||
4986 iface
->wpa_state
!= WPA_COMPLETED
)
4989 wpa_s
->cross_connect_in_use
= 1;
4990 wpa_msg(wpa_s
->parent
, MSG_INFO
,
4991 P2P_EVENT_CROSS_CONNECT_ENABLE
"%s %s",
4992 wpa_s
->ifname
, wpa_s
->cross_connect_uplink
);
4998 int wpas_p2p_notif_pbc_overlap(struct wpa_supplicant
*wpa_s
)
5000 if (wpa_s
->p2p_group_interface
!= P2P_GROUP_INTERFACE_CLIENT
&&
5001 !wpa_s
->p2p_in_provisioning
)
5002 return 0; /* not P2P client operation */
5004 wpa_printf(MSG_DEBUG
, "P2P: Terminate connection due to WPS PBC "
5006 if (wpa_s
!= wpa_s
->parent
)
5007 wpa_msg_ctrl(wpa_s
->parent
, MSG_INFO
, WPS_EVENT_OVERLAP
);
5009 if (wpa_s
->global
->p2p
)
5010 p2p_group_formation_failed(wpa_s
->global
->p2p
);
5012 eloop_cancel_timeout(wpas_p2p_group_formation_timeout
,
5013 wpa_s
->parent
, NULL
);
5015 wpas_group_formation_completed(wpa_s
, 0);
5020 void wpas_p2p_update_channel_list(struct wpa_supplicant
*wpa_s
)
5022 struct p2p_channels chan
;
5024 if (wpa_s
->global
== NULL
|| wpa_s
->global
->p2p
== NULL
)
5027 os_memset(&chan
, 0, sizeof(chan
));
5028 if (wpas_p2p_setup_channels(wpa_s
, &chan
)) {
5029 wpa_printf(MSG_ERROR
, "P2P: Failed to update supported "
5034 p2p_update_channel_list(wpa_s
->global
->p2p
, &chan
);
5038 int wpas_p2p_cancel(struct wpa_supplicant
*wpa_s
)
5040 struct wpa_global
*global
= wpa_s
->global
;
5044 if (global
->p2p
== NULL
)
5047 wpa_printf(MSG_DEBUG
, "P2P: Request to cancel group formation");
5049 if (wpa_s
->pending_interface_name
[0] &&
5050 !is_zero_ether_addr(wpa_s
->pending_interface_addr
))
5053 peer
= p2p_get_go_neg_peer(global
->p2p
);
5055 wpa_printf(MSG_DEBUG
, "P2P: Unauthorize pending GO Neg peer "
5056 MACSTR
, MAC2STR(peer
));
5057 p2p_unauthorize(global
->p2p
, peer
);
5061 wpas_p2p_stop_find(wpa_s
);
5063 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
5064 if (wpa_s
== global
->p2p_group_formation
&&
5065 (wpa_s
->p2p_in_provisioning
||
5066 wpa_s
->parent
->pending_interface_type
==
5067 WPA_IF_P2P_CLIENT
)) {
5068 wpa_printf(MSG_DEBUG
, "P2P: Interface %s in group "
5069 "formation found - cancelling",
5072 eloop_cancel_timeout(wpas_p2p_group_formation_timeout
,
5073 wpa_s
->parent
, NULL
);
5074 if (wpa_s
->p2p_in_provisioning
) {
5075 wpas_group_formation_completed(wpa_s
, 0);
5078 wpas_p2p_group_delete(wpa_s
,
5079 P2P_GROUP_REMOVAL_REQUESTED
);
5085 wpa_printf(MSG_DEBUG
, "P2P: No ongoing group formation found");
5093 void wpas_p2p_interface_unavailable(struct wpa_supplicant
*wpa_s
)
5095 if (wpa_s
->current_ssid
== NULL
|| !wpa_s
->current_ssid
->p2p_group
)
5098 wpa_printf(MSG_DEBUG
, "P2P: Remove group due to driver resource not "
5099 "being available anymore");
5100 wpas_p2p_group_delete(wpa_s
, P2P_GROUP_REMOVAL_UNAVAILABLE
);
5104 void wpas_p2p_update_best_channels(struct wpa_supplicant
*wpa_s
,
5105 int freq_24
, int freq_5
, int freq_overall
)
5107 struct p2p_data
*p2p
= wpa_s
->global
->p2p
;
5108 if (p2p
== NULL
|| (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
))
5110 p2p_set_best_channels(p2p
, freq_24
, freq_5
, freq_overall
);
5114 int wpas_p2p_unauthorize(struct wpa_supplicant
*wpa_s
, const char *addr
)
5117 struct p2p_data
*p2p
= wpa_s
->global
->p2p
;
5119 if (p2p
== NULL
|| (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
))
5122 if (hwaddr_aton(addr
, peer
))
5125 return p2p_unauthorize(p2p
, peer
);
5130 * wpas_p2p_disconnect - Disconnect from a P2P Group
5131 * @wpa_s: Pointer to wpa_supplicant data
5132 * Returns: 0 on success, -1 on failure
5134 * This can be used to disconnect from a group in which the local end is a P2P
5135 * Client or to end a P2P Group in case the local end is the Group Owner. If a
5136 * virtual network interface was created for this group, that interface will be
5137 * removed. Otherwise, only the configured P2P group network will be removed
5138 * from the interface.
5140 int wpas_p2p_disconnect(struct wpa_supplicant
*wpa_s
)
5146 return wpas_p2p_group_delete(wpa_s
, P2P_GROUP_REMOVAL_REQUESTED
) < 0 ?
5151 int wpas_p2p_in_progress(struct wpa_supplicant
*wpa_s
)
5153 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
5156 return p2p_in_progress(wpa_s
->global
->p2p
);
5160 void wpas_p2p_network_removed(struct wpa_supplicant
*wpa_s
,
5161 struct wpa_ssid
*ssid
)
5163 if (wpa_s
->p2p_in_provisioning
&& ssid
->p2p_group
&&
5164 eloop_cancel_timeout(wpas_p2p_group_formation_timeout
,
5165 wpa_s
->parent
, NULL
) > 0) {
5167 * Remove the network by scheduling the group formation
5168 * timeout to happen immediately. The teardown code
5169 * needs to be scheduled to run asynch later so that we
5170 * don't delete data from under ourselves unexpectedly.
5171 * Calling wpas_p2p_group_formation_timeout directly
5172 * causes a series of crashes in WPS failure scenarios.
5174 wpa_printf(MSG_DEBUG
, "P2P: Canceled group formation due to "
5175 "P2P group network getting removed");
5176 eloop_register_timeout(0, 0, wpas_p2p_group_formation_timeout
,
5177 wpa_s
->parent
, NULL
);
5182 struct wpa_ssid
* wpas_p2p_get_persistent(struct wpa_supplicant
*wpa_s
,
5183 const u8
*addr
, const u8
*ssid
,
5189 for (s
= wpa_s
->conf
->ssid
; s
; s
= s
->next
) {
5190 if (s
->disabled
!= 2)
5193 (ssid_len
!= s
->ssid_len
||
5194 os_memcmp(ssid
, s
->ssid
, ssid_len
) != 0))
5196 if (os_memcmp(s
->bssid
, addr
, ETH_ALEN
) == 0)
5197 return s
; /* peer is GO in the persistent group */
5198 if (s
->mode
!= WPAS_MODE_P2P_GO
|| s
->p2p_client_list
== NULL
)
5200 for (i
= 0; i
< s
->num_p2p_clients
; i
++) {
5201 if (os_memcmp(s
->p2p_client_list
+ i
* ETH_ALEN
,
5202 addr
, ETH_ALEN
) == 0)
5203 return s
; /* peer is P2P client in persistent
5212 void wpas_p2p_notify_ap_sta_authorized(struct wpa_supplicant
*wpa_s
,
5217 wpas_p2p_add_persistent_group_client(wpa_s
, addr
);
5221 static void wpas_p2p_fallback_to_go_neg(struct wpa_supplicant
*wpa_s
,
5224 struct wpa_supplicant
*group
= wpa_s
;
5225 eloop_cancel_timeout(wpas_p2p_pd_before_join_timeout
, wpa_s
, NULL
);
5226 if (wpa_s
->global
->p2p_group_formation
)
5227 group
= wpa_s
->global
->p2p_group_formation
;
5228 wpa_s
= wpa_s
->parent
;
5229 offchannel_send_action_done(wpa_s
);
5231 wpas_p2p_group_delete(group
, P2P_GROUP_REMOVAL_SILENT
);
5232 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Fall back to GO Negotiation");
5233 wpas_p2p_connect(wpa_s
, wpa_s
->pending_join_dev_addr
, wpa_s
->p2p_pin
,
5234 wpa_s
->p2p_wps_method
, wpa_s
->p2p_persistent_group
, 0,
5235 0, 0, wpa_s
->p2p_go_intent
, wpa_s
->p2p_connect_freq
,
5236 wpa_s
->p2p_persistent_id
,
5237 wpa_s
->p2p_pd_before_go_neg
,
5238 wpa_s
->p2p_go_ht40
);
5242 int wpas_p2p_scan_no_go_seen(struct wpa_supplicant
*wpa_s
)
5244 if (!wpa_s
->p2p_fallback_to_go_neg
||
5245 wpa_s
->p2p_in_provisioning
<= 5)
5248 if (wpas_p2p_peer_go(wpa_s
, wpa_s
->pending_join_dev_addr
) > 0)
5249 return 0; /* peer operating as a GO */
5251 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: GO not found for p2p_connect-auto - "
5252 "fallback to GO Negotiation");
5253 wpas_p2p_fallback_to_go_neg(wpa_s
, 1);
5259 unsigned int wpas_p2p_search_delay(struct wpa_supplicant
*wpa_s
)
5261 const char *rn
, *rn2
;
5262 struct wpa_supplicant
*ifs
;
5264 if (wpa_s
->wpa_state
> WPA_SCANNING
) {
5265 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Use %u ms search delay due to "
5266 "concurrent operation",
5267 P2P_CONCURRENT_SEARCH_DELAY
);
5268 return P2P_CONCURRENT_SEARCH_DELAY
;
5271 if (!wpa_s
->driver
->get_radio_name
)
5273 rn
= wpa_s
->driver
->get_radio_name(wpa_s
->drv_priv
);
5274 if (rn
== NULL
|| rn
[0] == '\0')
5277 for (ifs
= wpa_s
->global
->ifaces
; ifs
; ifs
= ifs
->next
) {
5278 if (ifs
== wpa_s
|| !ifs
->driver
->get_radio_name
)
5281 rn2
= ifs
->driver
->get_radio_name(ifs
->drv_priv
);
5282 if (!rn2
|| os_strcmp(rn
, rn2
) != 0)
5284 if (ifs
->wpa_state
> WPA_SCANNING
) {
5285 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Use %u ms search "
5286 "delay due to concurrent operation on "
5288 P2P_CONCURRENT_SEARCH_DELAY
, ifs
->ifname
);
5289 return P2P_CONCURRENT_SEARCH_DELAY
;