3 * Copyright (c) 2009-2010, Atheros Communications
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
19 #include "common/ieee802_11_common.h"
20 #include "common/ieee802_11_defs.h"
21 #include "common/wpa_ctrl.h"
22 #include "wps/wps_i.h"
24 #include "ap/hostapd.h"
25 #include "ap/p2p_hostapd.h"
26 #include "wpa_supplicant_i.h"
29 #include "config_ssid.h"
35 #include "wps_supplicant.h"
36 #include "p2p_supplicant.h"
40 * How many times to try to scan to find the GO before giving up on join
43 #define P2P_MAX_JOIN_SCAN_ATTEMPTS 10
46 static void wpas_p2p_long_listen_timeout(void *eloop_ctx
, void *timeout_ctx
);
47 static struct wpa_supplicant
*
48 wpas_p2p_get_group_iface(struct wpa_supplicant
*wpa_s
, int addr_allocated
,
50 static int wpas_p2p_join_start(struct wpa_supplicant
*wpa_s
);
51 static void wpas_p2p_join_scan(void *eloop_ctx
, void *timeout_ctx
);
52 static int wpas_p2p_join(struct wpa_supplicant
*wpa_s
, const u8
*iface_addr
,
53 const u8
*dev_addr
, enum p2p_wps_method wps_method
);
54 static int wpas_p2p_create_iface(struct wpa_supplicant
*wpa_s
);
55 static void wpas_p2p_cross_connect_setup(struct wpa_supplicant
*wpa_s
);
56 static void wpas_p2p_group_idle_timeout(void *eloop_ctx
, void *timeout_ctx
);
57 static void wpas_p2p_set_group_idle_timeout(struct wpa_supplicant
*wpa_s
);
60 static void wpas_p2p_scan_res_handler(struct wpa_supplicant
*wpa_s
,
61 struct wpa_scan_results
*scan_res
)
65 if (wpa_s
->global
->p2p_disabled
)
68 wpa_printf(MSG_DEBUG
, "P2P: Scan results received (%d BSS)",
71 for (i
= 0; i
< scan_res
->num
; i
++) {
72 struct wpa_scan_res
*bss
= scan_res
->res
[i
];
73 if (p2p_scan_res_handler(wpa_s
->global
->p2p
, bss
->bssid
,
74 bss
->freq
, bss
->level
,
75 (const u8
*) (bss
+ 1),
80 p2p_scan_res_handled(wpa_s
->global
->p2p
);
84 static int wpas_p2p_scan(void *ctx
, enum p2p_scan_type type
, int freq
)
86 struct wpa_supplicant
*wpa_s
= ctx
;
87 struct wpa_driver_scan_params params
;
89 struct wpabuf
*wps_ie
, *ies
;
90 int social_channels
[] = { 2412, 2437, 2462, 0, 0 };
92 os_memset(¶ms
, 0, sizeof(params
));
94 /* P2P Wildcard SSID */
96 params
.ssids
[0].ssid
= (u8
*) P2P_WILDCARD_SSID
;
97 params
.ssids
[0].ssid_len
= P2P_WILDCARD_SSID_LEN
;
99 wpa_s
->wps
->dev
.p2p
= 1;
100 wps_ie
= wps_build_probe_req_ie(0, &wpa_s
->wps
->dev
, wpa_s
->wps
->uuid
,
105 ies
= wpabuf_alloc(wpabuf_len(wps_ie
) + 100);
110 wpabuf_put_buf(ies
, wps_ie
);
113 p2p_scan_ie(wpa_s
->global
->p2p
, ies
);
115 params
.extra_ies
= wpabuf_head(ies
);
116 params
.extra_ies_len
= wpabuf_len(ies
);
119 case P2P_SCAN_SOCIAL
:
120 params
.freqs
= social_channels
;
124 case P2P_SCAN_SPECIFIC
:
125 social_channels
[0] = freq
;
126 social_channels
[1] = 0;
127 params
.freqs
= social_channels
;
129 case P2P_SCAN_SOCIAL_PLUS_ONE
:
130 social_channels
[3] = freq
;
131 params
.freqs
= social_channels
;
135 wpa_s
->scan_res_handler
= wpas_p2p_scan_res_handler
;
136 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_USER_SPACE_MLME
)
137 ret
= ieee80211_sta_req_scan(wpa_s
, ¶ms
);
139 ret
= wpa_drv_scan(wpa_s
, ¶ms
);
147 #ifdef CONFIG_CLIENT_MLME
148 static void p2p_rx_action_mlme(void *ctx
, const u8
*buf
, size_t len
, int freq
)
150 struct wpa_supplicant
*wpa_s
= ctx
;
151 const struct ieee80211_mgmt
*mgmt
;
154 if (wpa_s
->global
->p2p_disabled
)
156 mgmt
= (const struct ieee80211_mgmt
*) buf
;
157 hdr_len
= (const u8
*) &mgmt
->u
.action
.u
.vs_public_action
.action
- buf
;
160 p2p_rx_action(wpa_s
->global
->p2p
, mgmt
->da
, mgmt
->sa
, mgmt
->bssid
,
161 mgmt
->u
.action
.category
,
162 &mgmt
->u
.action
.u
.vs_public_action
.action
,
163 len
- hdr_len
, freq
);
165 #endif /* CONFIG_CLIENT_MLME */
168 static enum wpa_driver_if_type
wpas_p2p_if_type(int p2p_group_interface
)
170 switch (p2p_group_interface
) {
171 case P2P_GROUP_INTERFACE_PENDING
:
172 return WPA_IF_P2P_GROUP
;
173 case P2P_GROUP_INTERFACE_GO
:
174 return WPA_IF_P2P_GO
;
175 case P2P_GROUP_INTERFACE_CLIENT
:
176 return WPA_IF_P2P_CLIENT
;
179 return WPA_IF_P2P_GROUP
;
183 static struct wpa_supplicant
* wpas_get_p2p_group(struct wpa_supplicant
*wpa_s
,
185 size_t ssid_len
, int *go
)
189 for (wpa_s
= wpa_s
->global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
190 for (s
= wpa_s
->conf
->ssid
; s
; s
= s
->next
) {
191 if (s
->disabled
!= 0 || !s
->p2p_group
||
192 s
->ssid_len
!= ssid_len
||
193 os_memcmp(ssid
, s
->ssid
, ssid_len
) != 0)
195 if (s
->mode
== WPAS_MODE_P2P_GO
&&
196 s
!= wpa_s
->current_ssid
)
199 *go
= s
->mode
== WPAS_MODE_P2P_GO
;
208 static void wpas_p2p_group_delete(struct wpa_supplicant
*wpa_s
)
210 struct wpa_ssid
*ssid
;
214 eloop_cancel_timeout(wpas_p2p_group_idle_timeout
, wpa_s
, NULL
);
216 ssid
= wpa_s
->current_ssid
;
219 * The current SSID was not known, but there may still be a
220 * pending P2P group interface waiting for provisioning.
222 ssid
= wpa_s
->conf
->ssid
;
224 if (ssid
->p2p_group
&&
225 (ssid
->mode
== WPAS_MODE_P2P_GROUP_FORMATION
||
226 (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)))
231 if (wpa_s
->p2p_group_interface
== P2P_GROUP_INTERFACE_GO
)
233 else if (wpa_s
->p2p_group_interface
== P2P_GROUP_INTERFACE_CLIENT
||
234 (ssid
&& ssid
->mode
== WPAS_MODE_INFRA
)) {
235 wpa_s
->reassociate
= 0;
236 wpa_s
->disconnected
= 1;
237 wpa_supplicant_deauthenticate(wpa_s
,
238 WLAN_REASON_DEAUTH_LEAVING
);
242 if (wpa_s
->cross_connect_in_use
) {
243 wpa_s
->cross_connect_in_use
= 0;
244 wpa_msg(wpa_s
->parent
, MSG_INFO
,
245 P2P_EVENT_CROSS_CONNECT_DISABLE
"%s %s",
246 wpa_s
->ifname
, wpa_s
->cross_connect_uplink
);
248 switch (wpa_s
->removal_reason
) {
249 case P2P_GROUP_REMOVAL_REQUESTED
:
250 reason
= " reason=REQUESTED";
252 case P2P_GROUP_REMOVAL_IDLE_TIMEOUT
:
253 reason
= " reason=IDLE";
255 case P2P_GROUP_REMOVAL_UNAVAILABLE
:
256 reason
= " reason=UNAVAILABLE";
262 wpa_msg(wpa_s
->parent
, MSG_INFO
, P2P_EVENT_GROUP_REMOVED
"%s %s%s",
263 wpa_s
->ifname
, gtype
, reason
);
264 if (wpa_s
->p2p_group_interface
!= NOT_P2P_GROUP_INTERFACE
) {
265 struct wpa_global
*global
;
267 enum wpa_driver_if_type type
;
268 wpa_printf(MSG_DEBUG
, "P2P: Remove group interface %s",
270 global
= wpa_s
->global
;
271 ifname
= os_strdup(wpa_s
->ifname
);
272 type
= wpas_p2p_if_type(wpa_s
->p2p_group_interface
);
273 wpa_supplicant_remove_iface(wpa_s
->global
, wpa_s
);
274 wpa_s
= global
->ifaces
;
276 wpa_drv_if_remove(wpa_s
, type
, ifname
);
281 wpa_printf(MSG_DEBUG
, "P2P: Remove temporary group network");
282 if (ssid
&& (ssid
->p2p_group
||
283 ssid
->mode
== WPAS_MODE_P2P_GROUP_FORMATION
||
284 (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
))) {
286 if (ssid
== wpa_s
->current_ssid
)
287 wpa_s
->current_ssid
= NULL
;
288 wpas_notify_network_removed(wpa_s
, ssid
);
289 wpa_config_remove_network(wpa_s
->conf
, id
);
290 wpa_supplicant_clear_status(wpa_s
);
292 wpa_printf(MSG_DEBUG
, "P2P: Temporary group network not "
295 wpa_supplicant_ap_deinit(wpa_s
);
299 static int wpas_p2p_persistent_group(struct wpa_supplicant
*wpa_s
,
301 const u8
*ssid
, size_t ssid_len
)
309 if (wpa_s
->go_params
)
310 bssid
= wpa_s
->go_params
->peer_interface_addr
;
312 bssid
= wpa_s
->bssid
;
314 bss
= wpa_bss_get(wpa_s
, bssid
, ssid
, ssid_len
);
316 u8 iface_addr
[ETH_ALEN
];
317 if (p2p_get_interface_addr(wpa_s
->global
->p2p
, bssid
,
319 bss
= wpa_bss_get(wpa_s
, iface_addr
, ssid
, ssid_len
);
322 wpa_printf(MSG_DEBUG
, "P2P: Could not figure out whether "
323 "group is persistent - BSS " MACSTR
" not found",
328 p2p
= wpa_bss_get_vendor_ie_multi(bss
, P2P_IE_VENDOR_TYPE
);
330 wpa_printf(MSG_DEBUG
, "P2P: Could not figure out whether "
331 "group is persistent - BSS " MACSTR
332 " did not include P2P IE", MAC2STR(bssid
));
333 wpa_hexdump(MSG_DEBUG
, "P2P: Probe Response IEs",
334 (u8
*) (bss
+ 1), bss
->ie_len
);
335 wpa_hexdump(MSG_DEBUG
, "P2P: Beacon IEs",
336 ((u8
*) bss
+ 1) + bss
->ie_len
,
341 group_capab
= p2p_get_group_capab(p2p
);
342 addr
= p2p_get_go_dev_addr(p2p
);
343 wpa_printf(MSG_DEBUG
, "P2P: Checking whether group is persistent: "
344 "group_capab=0x%x", group_capab
);
346 os_memcpy(go_dev_addr
, addr
, ETH_ALEN
);
347 wpa_printf(MSG_DEBUG
, "P2P: GO Device Address " MACSTR
,
350 os_memset(go_dev_addr
, 0, ETH_ALEN
);
353 wpa_printf(MSG_DEBUG
, "P2P: BSS " MACSTR
" group_capab=0x%x "
354 "go_dev_addr=" MACSTR
,
355 MAC2STR(bssid
), group_capab
, MAC2STR(go_dev_addr
));
357 return group_capab
& P2P_GROUP_CAPAB_PERSISTENT_GROUP
;
361 static void wpas_p2p_store_persistent_group(struct wpa_supplicant
*wpa_s
,
362 struct wpa_ssid
*ssid
,
363 const u8
*go_dev_addr
)
368 wpa_printf(MSG_DEBUG
, "P2P: Storing credentials for a persistent "
369 "group (GO Dev Addr " MACSTR
")", MAC2STR(go_dev_addr
));
370 for (s
= wpa_s
->conf
->ssid
; s
; s
= s
->next
) {
371 if (s
->disabled
== 2 &&
372 os_memcmp(go_dev_addr
, s
->bssid
, ETH_ALEN
) == 0 &&
373 s
->ssid_len
== ssid
->ssid_len
&&
374 os_memcmp(ssid
->ssid
, s
->ssid
, ssid
->ssid_len
) == 0)
379 wpa_printf(MSG_DEBUG
, "P2P: Update existing persistent group "
381 if (ssid
->passphrase
&& !s
->passphrase
)
383 else if (ssid
->passphrase
&& s
->passphrase
&&
384 os_strcmp(ssid
->passphrase
, s
->passphrase
) != 0)
387 wpa_printf(MSG_DEBUG
, "P2P: Create a new persistent group "
390 s
= wpa_config_add_network(wpa_s
->conf
);
393 wpa_config_set_network_defaults(s
);
397 s
->p2p_persistent_group
= 1;
400 os_memcpy(s
->bssid
, go_dev_addr
, ETH_ALEN
);
401 s
->mode
= ssid
->mode
;
402 s
->auth_alg
= WPA_AUTH_ALG_OPEN
;
403 s
->key_mgmt
= WPA_KEY_MGMT_PSK
;
404 s
->proto
= WPA_PROTO_RSN
;
405 s
->pairwise_cipher
= WPA_CIPHER_CCMP
;
406 if (ssid
->passphrase
) {
407 os_free(s
->passphrase
);
408 s
->passphrase
= os_strdup(ssid
->passphrase
);
412 os_memcpy(s
->psk
, ssid
->psk
, 32);
414 if (s
->passphrase
&& !s
->psk_set
)
415 wpa_config_update_psk(s
);
416 if (s
->ssid
== NULL
|| s
->ssid_len
< ssid
->ssid_len
) {
418 s
->ssid
= os_malloc(ssid
->ssid_len
);
421 s
->ssid_len
= ssid
->ssid_len
;
422 os_memcpy(s
->ssid
, ssid
->ssid
, s
->ssid_len
);
425 #ifndef CONFIG_NO_CONFIG_WRITE
426 if (changed
&& wpa_s
->conf
->update_config
&&
427 wpa_config_write(wpa_s
->confname
, wpa_s
->conf
)) {
428 wpa_printf(MSG_DEBUG
, "P2P: Failed to update configuration");
430 #endif /* CONFIG_NO_CONFIG_WRITE */
434 static void wpas_group_formation_completed(struct wpa_supplicant
*wpa_s
,
437 struct wpa_ssid
*ssid
;
438 const char *ssid_txt
;
441 u8 go_dev_addr
[ETH_ALEN
];
444 * This callback is likely called for the main interface. Update wpa_s
445 * to use the group interface if a new interface was created for the
448 if (wpa_s
->global
->p2p_group_formation
)
449 wpa_s
= wpa_s
->global
->p2p_group_formation
;
450 wpa_s
->global
->p2p_group_formation
= NULL
;
451 wpa_s
->p2p_in_provisioning
= 0;
454 wpa_msg(wpa_s
->parent
, MSG_INFO
,
455 P2P_EVENT_GROUP_FORMATION_FAILURE
);
456 wpas_p2p_group_delete(wpa_s
);
460 wpa_msg(wpa_s
->parent
, MSG_INFO
, P2P_EVENT_GROUP_FORMATION_SUCCESS
);
462 ssid
= wpa_s
->current_ssid
;
463 if (ssid
&& ssid
->mode
== WPAS_MODE_P2P_GROUP_FORMATION
) {
464 ssid
->mode
= WPAS_MODE_P2P_GO
;
465 p2p_group_notif_formation_done(wpa_s
->p2p_group
);
466 wpa_supplicant_ap_mac_addr_filter(wpa_s
, NULL
);
471 ssid_txt
= wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
);
472 client
= ssid
->mode
== WPAS_MODE_INFRA
;
473 if (ssid
->mode
== WPAS_MODE_P2P_GO
) {
474 persistent
= ssid
->p2p_persistent_group
;
475 os_memcpy(go_dev_addr
, wpa_s
->parent
->own_addr
,
478 persistent
= wpas_p2p_persistent_group(wpa_s
,
484 client
= wpa_s
->p2p_group_interface
==
485 P2P_GROUP_INTERFACE_CLIENT
;
488 wpa_s
->show_group_started
= 0;
491 * Indicate event only after successfully completed 4-way
492 * handshake, i.e., when the interface is ready for data
495 wpa_s
->show_group_started
= 1;
496 } else if (ssid
&& ssid
->passphrase
== NULL
&& ssid
->psk_set
) {
498 wpa_snprintf_hex(psk
, sizeof(psk
), ssid
->psk
, 32);
499 wpa_msg(wpa_s
->parent
, MSG_INFO
, P2P_EVENT_GROUP_STARTED
500 "%s GO ssid=\"%s\" freq=%d psk=%s go_dev_addr=" MACSTR
502 wpa_s
->ifname
, ssid_txt
, ssid
->frequency
, psk
,
503 MAC2STR(go_dev_addr
),
504 persistent
? " [PERSISTENT]" : "");
505 wpas_p2p_cross_connect_setup(wpa_s
);
506 wpas_p2p_set_group_idle_timeout(wpa_s
);
508 wpa_msg(wpa_s
->parent
, MSG_INFO
, P2P_EVENT_GROUP_STARTED
509 "%s GO ssid=\"%s\" freq=%d passphrase=\"%s\" "
510 "go_dev_addr=" MACSTR
"%s",
511 wpa_s
->ifname
, ssid_txt
, ssid
? ssid
->frequency
: 0,
512 ssid
&& ssid
->passphrase
? ssid
->passphrase
: "",
513 MAC2STR(go_dev_addr
),
514 persistent
? " [PERSISTENT]" : "");
515 wpas_p2p_cross_connect_setup(wpa_s
);
516 wpas_p2p_set_group_idle_timeout(wpa_s
);
520 wpas_p2p_store_persistent_group(wpa_s
->parent
, ssid
,
525 static struct wpa_supplicant
*
526 wpas_get_tx_interface(struct wpa_supplicant
*wpa_s
, const u8
*src
)
528 struct wpa_supplicant
*iface
;
530 if (os_memcmp(src
, wpa_s
->own_addr
, ETH_ALEN
) == 0)
534 * Try to find a group interface that matches with the source address.
536 iface
= wpa_s
->global
->ifaces
;
538 if (os_memcmp(wpa_s
->pending_action_src
,
539 iface
->own_addr
, ETH_ALEN
) == 0)
544 wpa_printf(MSG_DEBUG
, "P2P: Use group interface %s "
545 "instead of interface %s for Action TX",
546 iface
->ifname
, wpa_s
->ifname
);
554 static void wpas_send_action_cb(void *eloop_ctx
, void *timeout_ctx
)
556 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
557 struct wpa_supplicant
*iface
;
561 without_roc
= wpa_s
->pending_action_without_roc
;
562 wpa_s
->pending_action_without_roc
= 0;
563 wpa_printf(MSG_DEBUG
, "P2P: Send Action callback (without_roc=%d "
564 "pending_action_tx=%p)",
565 without_roc
, wpa_s
->pending_action_tx
);
567 if (wpa_s
->pending_action_tx
== NULL
)
571 * This call is likely going to be on the P2P device instance if the
572 * driver uses a separate interface for that purpose. However, some
573 * Action frames are actually sent within a P2P Group and when that is
574 * the case, we need to follow power saving (e.g., GO buffering the
575 * frame for a client in PS mode or a client following the advertised
576 * NoA from its GO). To make that easier for the driver, select the
577 * correct group interface here.
579 iface
= wpas_get_tx_interface(wpa_s
, wpa_s
->pending_action_src
);
581 if (wpa_s
->off_channel_freq
!= wpa_s
->pending_action_freq
&&
582 wpa_s
->pending_action_freq
!= 0 &&
583 wpa_s
->pending_action_freq
!= iface
->assoc_freq
) {
584 wpa_printf(MSG_DEBUG
, "P2P: Pending Action frame TX "
585 "waiting for another freq=%u (off_channel_freq=%u "
587 wpa_s
->pending_action_freq
,
588 wpa_s
->off_channel_freq
,
590 if (without_roc
&& wpa_s
->off_channel_freq
== 0) {
592 * We may get here if wpas_send_action() found us to be
593 * on the correct channel, but remain-on-channel cancel
594 * event was received before getting here.
596 wpa_printf(MSG_DEBUG
, "P2P: Schedule "
597 "remain-on-channel to send Action frame");
598 if (wpa_drv_remain_on_channel(
599 wpa_s
, wpa_s
->pending_action_freq
, 200) <
601 wpa_printf(MSG_DEBUG
, "P2P: Failed to request "
602 "driver to remain on channel (%u "
603 "MHz) for Action Frame TX",
604 wpa_s
->pending_action_freq
);
606 wpa_s
->off_channel_freq
= 0;
607 wpa_s
->roc_waiting_drv_freq
=
608 wpa_s
->pending_action_freq
;
614 wpa_printf(MSG_DEBUG
, "P2P: Sending pending Action frame to "
615 MACSTR
" using interface %s",
616 MAC2STR(wpa_s
->pending_action_dst
), iface
->ifname
);
617 res
= wpa_drv_send_action(iface
, wpa_s
->pending_action_freq
,
618 wpa_s
->pending_action_dst
,
619 wpa_s
->pending_action_src
,
620 wpa_s
->pending_action_bssid
,
621 wpabuf_head(wpa_s
->pending_action_tx
),
622 wpabuf_len(wpa_s
->pending_action_tx
));
624 wpa_printf(MSG_DEBUG
, "P2P: Failed to send the pending "
627 * Use fake TX status event to allow P2P state machine to
630 wpas_send_action_tx_status(
631 wpa_s
, wpa_s
->pending_action_dst
,
632 wpabuf_head(wpa_s
->pending_action_tx
),
633 wpabuf_len(wpa_s
->pending_action_tx
),
634 P2P_SEND_ACTION_FAILED
);
639 void wpas_send_action_tx_status(struct wpa_supplicant
*wpa_s
, const u8
*dst
,
640 const u8
*data
, size_t data_len
,
641 enum p2p_send_action_result result
)
643 if (wpa_s
->global
->p2p_disabled
)
646 if (wpa_s
->pending_action_tx
== NULL
) {
647 wpa_printf(MSG_DEBUG
, "P2P: Ignore Action TX status - no "
648 "pending operation");
652 if (os_memcmp(dst
, wpa_s
->pending_action_dst
, ETH_ALEN
) != 0) {
653 wpa_printf(MSG_DEBUG
, "P2P: Ignore Action TX status - unknown "
654 "destination address");
658 wpabuf_free(wpa_s
->pending_action_tx
);
659 wpa_s
->pending_action_tx
= NULL
;
661 p2p_send_action_cb(wpa_s
->global
->p2p
, wpa_s
->pending_action_freq
,
662 wpa_s
->pending_action_dst
,
663 wpa_s
->pending_action_src
,
664 wpa_s
->pending_action_bssid
,
667 if (wpa_s
->pending_pd_before_join
&&
668 (os_memcmp(wpa_s
->pending_action_dst
, wpa_s
->pending_join_dev_addr
,
670 os_memcmp(wpa_s
->pending_action_dst
,
671 wpa_s
->pending_join_iface_addr
, ETH_ALEN
) == 0)) {
672 wpa_s
->pending_pd_before_join
= 0;
673 wpa_printf(MSG_DEBUG
, "P2P: Starting pending "
674 "join-existing-group operation");
675 wpas_p2p_join_start(wpa_s
);
680 static int wpas_send_action(void *ctx
, unsigned int freq
, const u8
*dst
,
681 const u8
*src
, const u8
*bssid
, const u8
*buf
,
682 size_t len
, unsigned int wait_time
)
684 struct wpa_supplicant
*wpa_s
= ctx
;
686 wpa_printf(MSG_DEBUG
, "P2P: Send action frame: freq=%d dst=" MACSTR
687 " src=" MACSTR
" bssid=" MACSTR
" len=%d",
688 freq
, MAC2STR(dst
), MAC2STR(src
), MAC2STR(bssid
),
691 if (wpa_s
->pending_action_tx
) {
692 wpa_printf(MSG_DEBUG
, "P2P: Dropped pending Action frame TX "
693 "to " MACSTR
, MAC2STR(wpa_s
->pending_action_dst
));
694 wpabuf_free(wpa_s
->pending_action_tx
);
696 wpa_s
->pending_action_tx
= wpabuf_alloc(len
);
697 if (wpa_s
->pending_action_tx
== NULL
) {
698 wpa_printf(MSG_DEBUG
, "P2P: Failed to allocate Action frame "
699 "TX buffer (len=%llu)", (unsigned long long) len
);
702 wpabuf_put_data(wpa_s
->pending_action_tx
, buf
, len
);
703 os_memcpy(wpa_s
->pending_action_src
, src
, ETH_ALEN
);
704 os_memcpy(wpa_s
->pending_action_dst
, dst
, ETH_ALEN
);
705 os_memcpy(wpa_s
->pending_action_bssid
, bssid
, ETH_ALEN
);
706 wpa_s
->pending_action_freq
= freq
;
709 struct wpa_supplicant
*tx_iface
;
710 tx_iface
= wpas_get_tx_interface(wpa_s
, src
);
711 if (tx_iface
->assoc_freq
== freq
) {
712 wpa_printf(MSG_DEBUG
, "P2P: Already on requested "
713 "channel (TX interface operating channel)");
718 if (wpa_s
->off_channel_freq
== freq
|| freq
== 0) {
719 wpa_printf(MSG_DEBUG
, "P2P: Already on requested channel; "
720 "send Action frame immediately");
721 /* TODO: Would there ever be need to extend the current
722 * duration on the channel? */
723 wpa_s
->pending_action_without_roc
= 1;
724 eloop_cancel_timeout(wpas_send_action_cb
, wpa_s
, NULL
);
725 eloop_register_timeout(0, 0, wpas_send_action_cb
, wpa_s
, NULL
);
728 wpa_s
->pending_action_without_roc
= 0;
730 if (wpa_s
->roc_waiting_drv_freq
== freq
) {
731 wpa_printf(MSG_DEBUG
, "P2P: Already waiting for driver to get "
732 "to frequency %u MHz; continue waiting to send the "
733 "Action frame", freq
);
737 wpa_printf(MSG_DEBUG
, "P2P: Schedule Action frame to be transmitted "
738 "once the driver gets to the requested channel");
739 if (wait_time
> wpa_s
->max_remain_on_chan
)
740 wait_time
= wpa_s
->max_remain_on_chan
;
741 if (wpa_drv_remain_on_channel(wpa_s
, freq
, wait_time
) < 0) {
742 wpa_printf(MSG_DEBUG
, "P2P: Failed to request driver "
743 "to remain on channel (%u MHz) for Action "
747 wpa_s
->off_channel_freq
= 0;
748 wpa_s
->roc_waiting_drv_freq
= freq
;
754 static void wpas_send_action_done(void *ctx
)
756 struct wpa_supplicant
*wpa_s
= ctx
;
757 wpa_printf(MSG_DEBUG
, "P2P: Action frame sequence done notification");
758 wpabuf_free(wpa_s
->pending_action_tx
);
759 wpa_s
->pending_action_tx
= NULL
;
760 if (wpa_s
->off_channel_freq
|| wpa_s
->roc_waiting_drv_freq
) {
761 wpa_drv_cancel_remain_on_channel(wpa_s
);
762 wpa_s
->off_channel_freq
= 0;
763 wpa_s
->roc_waiting_drv_freq
= 0;
768 static int wpas_copy_go_neg_results(struct wpa_supplicant
*wpa_s
,
769 struct p2p_go_neg_results
*params
)
771 if (wpa_s
->go_params
== NULL
) {
772 wpa_s
->go_params
= os_malloc(sizeof(*params
));
773 if (wpa_s
->go_params
== NULL
)
776 os_memcpy(wpa_s
->go_params
, params
, sizeof(*params
));
781 static void wpas_start_wps_enrollee(struct wpa_supplicant
*wpa_s
,
782 struct p2p_go_neg_results
*res
)
784 wpa_printf(MSG_DEBUG
, "P2P: Start WPS Enrollee for peer " MACSTR
,
785 MAC2STR(res
->peer_interface_addr
));
786 wpa_hexdump_ascii(MSG_DEBUG
, "P2P: Start WPS Enrollee for SSID",
787 res
->ssid
, res
->ssid_len
);
788 wpa_supplicant_ap_deinit(wpa_s
);
789 wpas_copy_go_neg_results(wpa_s
, res
);
790 if (res
->wps_method
== WPS_PBC
)
791 wpas_wps_start_pbc(wpa_s
, res
->peer_interface_addr
, 1);
793 u16 dev_pw_id
= DEV_PW_DEFAULT
;
794 if (wpa_s
->p2p_wps_method
== WPS_PIN_KEYPAD
)
795 dev_pw_id
= DEV_PW_REGISTRAR_SPECIFIED
;
796 wpas_wps_start_pin(wpa_s
, res
->peer_interface_addr
,
797 wpa_s
->p2p_pin
, 1, dev_pw_id
);
802 static void p2p_go_configured(void *ctx
, void *data
)
804 struct wpa_supplicant
*wpa_s
= ctx
;
805 struct p2p_go_neg_results
*params
= data
;
806 struct wpa_ssid
*ssid
;
808 ssid
= wpa_s
->current_ssid
;
809 if (ssid
&& ssid
->mode
== WPAS_MODE_P2P_GO
) {
810 wpa_printf(MSG_DEBUG
, "P2P: Group setup without provisioning");
811 if (wpa_s
->global
->p2p_group_formation
== wpa_s
)
812 wpa_s
->global
->p2p_group_formation
= NULL
;
813 wpa_msg(wpa_s
->parent
, MSG_INFO
, P2P_EVENT_GROUP_STARTED
814 "%s GO ssid=\"%s\" freq=%d passphrase=\"%s\" "
815 "go_dev_addr=" MACSTR
"%s",
817 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
),
819 params
->passphrase
? params
->passphrase
: "",
820 MAC2STR(wpa_s
->parent
->own_addr
),
821 params
->persistent_group
? " [PERSISTENT]" : "");
822 if (params
->persistent_group
)
823 wpas_p2p_store_persistent_group(
825 wpa_s
->parent
->own_addr
);
826 wpas_p2p_cross_connect_setup(wpa_s
);
827 wpas_p2p_set_group_idle_timeout(wpa_s
);
831 wpa_printf(MSG_DEBUG
, "P2P: Setting up WPS for GO provisioning");
832 if (wpa_supplicant_ap_mac_addr_filter(wpa_s
,
833 params
->peer_interface_addr
)) {
834 wpa_printf(MSG_DEBUG
, "P2P: Failed to setup MAC address "
838 if (params
->wps_method
== WPS_PBC
)
839 wpa_supplicant_ap_wps_pbc(wpa_s
, params
->peer_interface_addr
);
840 else if (wpa_s
->p2p_pin
[0])
841 wpa_supplicant_ap_wps_pin(wpa_s
, params
->peer_interface_addr
,
842 wpa_s
->p2p_pin
, NULL
, 0);
843 os_free(wpa_s
->go_params
);
844 wpa_s
->go_params
= NULL
;
848 static void wpas_start_wps_go(struct wpa_supplicant
*wpa_s
,
849 struct p2p_go_neg_results
*params
,
852 struct wpa_ssid
*ssid
;
854 if (wpas_copy_go_neg_results(wpa_s
, params
) < 0)
857 ssid
= wpa_config_add_network(wpa_s
->conf
);
861 wpas_notify_network_added(wpa_s
, ssid
);
862 wpa_config_set_network_defaults(ssid
);
865 ssid
->p2p_persistent_group
= params
->persistent_group
;
866 ssid
->mode
= group_formation
? WPAS_MODE_P2P_GROUP_FORMATION
:
868 ssid
->frequency
= params
->freq
;
869 ssid
->ssid
= os_zalloc(params
->ssid_len
+ 1);
871 os_memcpy(ssid
->ssid
, params
->ssid
, params
->ssid_len
);
872 ssid
->ssid_len
= params
->ssid_len
;
874 ssid
->auth_alg
= WPA_AUTH_ALG_OPEN
;
875 ssid
->key_mgmt
= WPA_KEY_MGMT_PSK
;
876 ssid
->proto
= WPA_PROTO_RSN
;
877 ssid
->pairwise_cipher
= WPA_CIPHER_CCMP
;
878 ssid
->passphrase
= os_strdup(params
->passphrase
);
880 wpa_s
->ap_configured_cb
= p2p_go_configured
;
881 wpa_s
->ap_configured_cb_ctx
= wpa_s
;
882 wpa_s
->ap_configured_cb_data
= wpa_s
->go_params
;
883 wpa_s
->connect_without_scan
= 1;
884 wpa_s
->reassociate
= 1;
885 wpa_s
->disconnected
= 0;
886 wpa_supplicant_req_scan(wpa_s
, 0, 0);
890 static void wpas_p2p_clone_config(struct wpa_supplicant
*dst
,
891 const struct wpa_supplicant
*src
)
893 struct wpa_config
*d
;
894 const struct wpa_config
*s
;
899 #define C(n) if (s->n) d->n = os_strdup(s->n)
909 d
->p2p_group_idle
= s
->p2p_group_idle
;
910 d
->p2p_intra_bss
= s
->p2p_intra_bss
;
914 static int wpas_p2p_add_group_interface(struct wpa_supplicant
*wpa_s
,
915 enum wpa_driver_if_type type
)
917 char ifname
[120], force_ifname
[120];
919 if (wpa_s
->pending_interface_name
[0]) {
920 wpa_printf(MSG_DEBUG
, "P2P: Pending virtual interface exists "
921 "- skip creation of a new one");
922 if (is_zero_ether_addr(wpa_s
->pending_interface_addr
)) {
923 wpa_printf(MSG_DEBUG
, "P2P: Pending virtual address "
924 "unknown?! ifname='%s'",
925 wpa_s
->pending_interface_name
);
931 os_snprintf(ifname
, sizeof(ifname
), "p2p-%s-%d", wpa_s
->ifname
,
932 wpa_s
->p2p_group_idx
);
933 if (os_strlen(ifname
) >= IFNAMSIZ
&&
934 os_strlen(wpa_s
->ifname
) < IFNAMSIZ
) {
935 /* Try to avoid going over the IFNAMSIZ length limit */
936 os_snprintf(ifname
, sizeof(ifname
), "p2p-%d",
937 wpa_s
->p2p_group_idx
);
939 force_ifname
[0] = '\0';
941 wpa_printf(MSG_DEBUG
, "P2P: Create a new interface %s for the group",
943 wpa_s
->p2p_group_idx
++;
945 wpa_s
->pending_interface_type
= type
;
946 if (wpa_drv_if_add(wpa_s
, type
, ifname
, NULL
, NULL
, force_ifname
,
947 wpa_s
->pending_interface_addr
) < 0) {
948 wpa_printf(MSG_ERROR
, "P2P: Failed to create new group "
953 if (force_ifname
[0]) {
954 wpa_printf(MSG_DEBUG
, "P2P: Driver forced interface name %s",
956 os_strlcpy(wpa_s
->pending_interface_name
, force_ifname
,
957 sizeof(wpa_s
->pending_interface_name
));
959 os_strlcpy(wpa_s
->pending_interface_name
, ifname
,
960 sizeof(wpa_s
->pending_interface_name
));
961 wpa_printf(MSG_DEBUG
, "P2P: Created pending virtual interface %s addr "
962 MACSTR
, wpa_s
->pending_interface_name
,
963 MAC2STR(wpa_s
->pending_interface_addr
));
969 static void wpas_p2p_remove_pending_group_interface(
970 struct wpa_supplicant
*wpa_s
)
972 if (!wpa_s
->pending_interface_name
[0] ||
973 is_zero_ether_addr(wpa_s
->pending_interface_addr
))
974 return; /* No pending virtual interface */
976 wpa_printf(MSG_DEBUG
, "P2P: Removing pending group interface %s",
977 wpa_s
->pending_interface_name
);
978 wpa_drv_if_remove(wpa_s
, wpa_s
->pending_interface_type
,
979 wpa_s
->pending_interface_name
);
980 os_memset(wpa_s
->pending_interface_addr
, 0, ETH_ALEN
);
981 wpa_s
->pending_interface_name
[0] = '\0';
985 static struct wpa_supplicant
*
986 wpas_p2p_init_group_interface(struct wpa_supplicant
*wpa_s
, int go
)
988 struct wpa_interface iface
;
989 struct wpa_supplicant
*group_wpa_s
;
991 if (!wpa_s
->pending_interface_name
[0]) {
992 wpa_printf(MSG_ERROR
, "P2P: No pending group interface");
993 if (!wpas_p2p_create_iface(wpa_s
))
996 * Something has forced us to remove the pending interface; try
997 * to create a new one and hope for the best that we will get
998 * the same local address.
1000 if (wpas_p2p_add_group_interface(wpa_s
, go
? WPA_IF_P2P_GO
:
1001 WPA_IF_P2P_CLIENT
) < 0)
1005 os_memset(&iface
, 0, sizeof(iface
));
1006 iface
.ifname
= wpa_s
->pending_interface_name
;
1007 iface
.driver
= wpa_s
->driver
->name
;
1008 iface
.ctrl_interface
= wpa_s
->conf
->ctrl_interface
;
1009 iface
.driver_param
= wpa_s
->conf
->driver_param
;
1010 group_wpa_s
= wpa_supplicant_add_iface(wpa_s
->global
, &iface
);
1011 if (group_wpa_s
== NULL
) {
1012 wpa_printf(MSG_ERROR
, "P2P: Failed to create new "
1013 "wpa_supplicant interface");
1016 wpa_s
->pending_interface_name
[0] = '\0';
1017 group_wpa_s
->parent
= wpa_s
;
1018 group_wpa_s
->p2p_group_interface
= go
? P2P_GROUP_INTERFACE_GO
:
1019 P2P_GROUP_INTERFACE_CLIENT
;
1020 wpa_s
->global
->p2p_group_formation
= group_wpa_s
;
1022 wpas_p2p_clone_config(group_wpa_s
, wpa_s
);
1028 static void wpas_p2p_group_formation_timeout(void *eloop_ctx
,
1031 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
1032 wpa_printf(MSG_DEBUG
, "P2P: Group Formation timed out");
1033 if (wpa_s
->global
->p2p
)
1034 p2p_group_formation_failed(wpa_s
->global
->p2p
);
1035 wpas_group_formation_completed(wpa_s
, 0);
1039 void wpas_go_neg_completed(void *ctx
, struct p2p_go_neg_results
*res
)
1041 struct wpa_supplicant
*wpa_s
= ctx
;
1043 if (wpa_s
->off_channel_freq
|| wpa_s
->roc_waiting_drv_freq
) {
1044 wpa_drv_cancel_remain_on_channel(wpa_s
);
1045 wpa_s
->off_channel_freq
= 0;
1046 wpa_s
->roc_waiting_drv_freq
= 0;
1050 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_GO_NEG_FAILURE
"status=%d",
1052 wpas_p2p_remove_pending_group_interface(wpa_s
);
1056 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_GO_NEG_SUCCESS
);
1058 if (wpa_s
->create_p2p_iface
) {
1059 struct wpa_supplicant
*group_wpa_s
=
1060 wpas_p2p_init_group_interface(wpa_s
, res
->role_go
);
1061 if (group_wpa_s
== NULL
) {
1062 wpas_p2p_remove_pending_group_interface(wpa_s
);
1065 if (group_wpa_s
!= wpa_s
) {
1066 os_memcpy(group_wpa_s
->p2p_pin
, wpa_s
->p2p_pin
,
1067 sizeof(group_wpa_s
->p2p_pin
));
1068 group_wpa_s
->p2p_wps_method
= wpa_s
->p2p_wps_method
;
1070 os_memset(wpa_s
->pending_interface_addr
, 0, ETH_ALEN
);
1071 wpa_s
->pending_interface_name
[0] = '\0';
1072 group_wpa_s
->p2p_in_provisioning
= 1;
1075 wpas_start_wps_go(group_wpa_s
, res
, 1);
1077 wpas_start_wps_enrollee(group_wpa_s
, res
);
1079 wpa_s
->p2p_in_provisioning
= 1;
1080 wpa_s
->global
->p2p_group_formation
= wpa_s
;
1083 wpas_start_wps_go(wpa_s
, res
, 1);
1085 wpas_start_wps_enrollee(ctx
, res
);
1088 wpa_s
->p2p_long_listen
= 0;
1089 eloop_cancel_timeout(wpas_p2p_long_listen_timeout
, wpa_s
, NULL
);
1091 eloop_cancel_timeout(wpas_p2p_group_formation_timeout
, wpa_s
, NULL
);
1092 eloop_register_timeout(15 + res
->peer_config_timeout
/ 100,
1093 (res
->peer_config_timeout
% 100) * 10000,
1094 wpas_p2p_group_formation_timeout
, wpa_s
, NULL
);
1098 void wpas_go_neg_req_rx(void *ctx
, const u8
*src
, u16 dev_passwd_id
)
1100 struct wpa_supplicant
*wpa_s
= ctx
;
1101 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_GO_NEG_REQUEST MACSTR
1102 " dev_passwd_id=%u", MAC2STR(src
), dev_passwd_id
);
1106 void wpas_dev_found(void *ctx
, const u8
*addr
, const u8
*dev_addr
,
1107 const u8
*pri_dev_type
, const char *dev_name
,
1108 u16 config_methods
, u8 dev_capab
, u8 group_capab
)
1110 struct wpa_supplicant
*wpa_s
= ctx
;
1111 char devtype
[WPS_DEV_TYPE_BUFSIZE
];
1112 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_DEVICE_FOUND MACSTR
1113 " p2p_dev_addr=" MACSTR
1114 " pri_dev_type=%s name='%s' config_methods=0x%x "
1115 "dev_capab=0x%x group_capab=0x%x",
1116 MAC2STR(addr
), MAC2STR(dev_addr
),
1117 wps_dev_type_bin2str(pri_dev_type
, devtype
, sizeof(devtype
)),
1118 dev_name
, config_methods
, dev_capab
, group_capab
);
1122 static int wpas_start_listen(void *ctx
, unsigned int freq
,
1123 unsigned int duration
,
1124 const struct wpabuf
*probe_resp_ie
)
1126 struct wpa_supplicant
*wpa_s
= ctx
;
1128 wpa_drv_set_ap_wps_ie(wpa_s
, NULL
, probe_resp_ie
, NULL
);
1130 if (wpa_drv_probe_req_report(wpa_s
, 1) < 0) {
1131 wpa_printf(MSG_DEBUG
, "P2P: Failed to request the driver to "
1132 "report received Probe Request frames");
1136 wpa_s
->pending_listen_freq
= freq
;
1137 wpa_s
->pending_listen_duration
= duration
;
1139 if (wpa_drv_remain_on_channel(wpa_s
, freq
, duration
) < 0) {
1140 wpa_printf(MSG_DEBUG
, "P2P: Failed to request the driver "
1141 "to remain on channel (%u MHz) for Listen "
1143 wpa_s
->pending_listen_freq
= 0;
1146 wpa_s
->off_channel_freq
= 0;
1147 wpa_s
->roc_waiting_drv_freq
= freq
;
1153 static void wpas_stop_listen(void *ctx
)
1155 struct wpa_supplicant
*wpa_s
= ctx
;
1156 if (wpa_s
->off_channel_freq
|| wpa_s
->roc_waiting_drv_freq
) {
1157 wpa_drv_cancel_remain_on_channel(wpa_s
);
1158 wpa_s
->off_channel_freq
= 0;
1159 wpa_s
->roc_waiting_drv_freq
= 0;
1161 wpa_drv_probe_req_report(wpa_s
, 0);
1165 static int wpas_send_probe_resp(void *ctx
, const struct wpabuf
*buf
)
1167 struct wpa_supplicant
*wpa_s
= ctx
;
1168 return wpa_drv_send_mlme(wpa_s
, wpabuf_head(buf
), wpabuf_len(buf
));
1172 static struct p2p_srv_bonjour
*
1173 wpas_p2p_service_get_bonjour(struct wpa_supplicant
*wpa_s
,
1174 const struct wpabuf
*query
)
1176 struct p2p_srv_bonjour
*bsrv
;
1179 len
= wpabuf_len(query
);
1180 dl_list_for_each(bsrv
, &wpa_s
->global
->p2p_srv_bonjour
,
1181 struct p2p_srv_bonjour
, list
) {
1182 if (len
== wpabuf_len(bsrv
->query
) &&
1183 os_memcmp(wpabuf_head(query
), wpabuf_head(bsrv
->query
),
1191 static struct p2p_srv_upnp
*
1192 wpas_p2p_service_get_upnp(struct wpa_supplicant
*wpa_s
, u8 version
,
1193 const char *service
)
1195 struct p2p_srv_upnp
*usrv
;
1197 dl_list_for_each(usrv
, &wpa_s
->global
->p2p_srv_upnp
,
1198 struct p2p_srv_upnp
, list
) {
1199 if (version
== usrv
->version
&&
1200 os_strcmp(service
, usrv
->service
) == 0)
1207 static void wpas_sd_add_proto_not_avail(struct wpabuf
*resp
, u8 srv_proto
,
1212 if (wpabuf_tailroom(resp
) < 5)
1215 /* Length (to be filled) */
1216 len_pos
= wpabuf_put(resp
, 2);
1217 wpabuf_put_u8(resp
, srv_proto
);
1218 wpabuf_put_u8(resp
, srv_trans_id
);
1220 wpabuf_put_u8(resp
, P2P_SD_PROTO_NOT_AVAILABLE
);
1221 /* Response Data: empty */
1222 WPA_PUT_LE16(len_pos
, (u8
*) wpabuf_put(resp
, 0) - len_pos
- 2);
1226 static void wpas_sd_all_bonjour(struct wpa_supplicant
*wpa_s
,
1227 struct wpabuf
*resp
, u8 srv_trans_id
)
1229 struct p2p_srv_bonjour
*bsrv
;
1232 wpa_printf(MSG_DEBUG
, "P2P: SD Request for all Bonjour services");
1234 if (dl_list_empty(&wpa_s
->global
->p2p_srv_bonjour
)) {
1235 wpa_printf(MSG_DEBUG
, "P2P: Bonjour protocol not available");
1239 dl_list_for_each(bsrv
, &wpa_s
->global
->p2p_srv_bonjour
,
1240 struct p2p_srv_bonjour
, list
) {
1241 if (wpabuf_tailroom(resp
) <
1242 5 + wpabuf_len(bsrv
->query
) + wpabuf_len(bsrv
->resp
))
1244 /* Length (to be filled) */
1245 len_pos
= wpabuf_put(resp
, 2);
1246 wpabuf_put_u8(resp
, P2P_SERV_BONJOUR
);
1247 wpabuf_put_u8(resp
, srv_trans_id
);
1249 wpabuf_put_u8(resp
, P2P_SD_SUCCESS
);
1250 wpa_hexdump_ascii(MSG_DEBUG
, "P2P: Matching Bonjour service",
1251 wpabuf_head(bsrv
->resp
),
1252 wpabuf_len(bsrv
->resp
));
1254 wpabuf_put_buf(resp
, bsrv
->query
); /* Key */
1255 wpabuf_put_buf(resp
, bsrv
->resp
); /* Value */
1256 WPA_PUT_LE16(len_pos
, (u8
*) wpabuf_put(resp
, 0) - len_pos
-
1262 static void wpas_sd_req_bonjour(struct wpa_supplicant
*wpa_s
,
1263 struct wpabuf
*resp
, u8 srv_trans_id
,
1264 const u8
*query
, size_t query_len
)
1266 struct p2p_srv_bonjour
*bsrv
;
1270 wpa_hexdump_ascii(MSG_DEBUG
, "P2P: SD Request for Bonjour",
1272 if (dl_list_empty(&wpa_s
->global
->p2p_srv_bonjour
)) {
1273 wpa_printf(MSG_DEBUG
, "P2P: Bonjour protocol not available");
1274 wpas_sd_add_proto_not_avail(resp
, P2P_SERV_BONJOUR
,
1279 if (query_len
== 0) {
1280 wpas_sd_all_bonjour(wpa_s
, resp
, srv_trans_id
);
1284 if (wpabuf_tailroom(resp
) < 5)
1286 /* Length (to be filled) */
1287 len_pos
= wpabuf_put(resp
, 2);
1288 wpabuf_put_u8(resp
, P2P_SERV_BONJOUR
);
1289 wpabuf_put_u8(resp
, srv_trans_id
);
1291 wpabuf_set(&buf
, query
, query_len
);
1292 bsrv
= wpas_p2p_service_get_bonjour(wpa_s
, &buf
);
1294 wpa_printf(MSG_DEBUG
, "P2P: Requested Bonjour service not "
1298 wpabuf_put_u8(resp
, P2P_SD_REQUESTED_INFO_NOT_AVAILABLE
);
1299 /* Response Data: empty */
1300 WPA_PUT_LE16(len_pos
, (u8
*) wpabuf_put(resp
, 0) - len_pos
-
1306 wpabuf_put_u8(resp
, P2P_SD_SUCCESS
);
1307 wpa_hexdump_ascii(MSG_DEBUG
, "P2P: Matching Bonjour service",
1308 wpabuf_head(bsrv
->resp
), wpabuf_len(bsrv
->resp
));
1310 if (wpabuf_tailroom(resp
) >=
1311 wpabuf_len(bsrv
->query
) + wpabuf_len(bsrv
->resp
)) {
1313 wpabuf_put_buf(resp
, bsrv
->query
); /* Key */
1314 wpabuf_put_buf(resp
, bsrv
->resp
); /* Value */
1316 WPA_PUT_LE16(len_pos
, (u8
*) wpabuf_put(resp
, 0) - len_pos
- 2);
1320 static void wpas_sd_all_upnp(struct wpa_supplicant
*wpa_s
,
1321 struct wpabuf
*resp
, u8 srv_trans_id
)
1323 struct p2p_srv_upnp
*usrv
;
1326 wpa_printf(MSG_DEBUG
, "P2P: SD Request for all UPnP services");
1328 if (dl_list_empty(&wpa_s
->global
->p2p_srv_upnp
)) {
1329 wpa_printf(MSG_DEBUG
, "P2P: UPnP protocol not available");
1333 dl_list_for_each(usrv
, &wpa_s
->global
->p2p_srv_upnp
,
1334 struct p2p_srv_upnp
, list
) {
1335 if (wpabuf_tailroom(resp
) < 5 + 1 + os_strlen(usrv
->service
))
1338 /* Length (to be filled) */
1339 len_pos
= wpabuf_put(resp
, 2);
1340 wpabuf_put_u8(resp
, P2P_SERV_UPNP
);
1341 wpabuf_put_u8(resp
, srv_trans_id
);
1344 wpabuf_put_u8(resp
, P2P_SD_SUCCESS
);
1346 wpabuf_put_u8(resp
, usrv
->version
);
1347 wpa_printf(MSG_DEBUG
, "P2P: Matching UPnP Service: %s",
1349 wpabuf_put_str(resp
, usrv
->service
);
1350 WPA_PUT_LE16(len_pos
, (u8
*) wpabuf_put(resp
, 0) - len_pos
-
1356 static void wpas_sd_req_upnp(struct wpa_supplicant
*wpa_s
,
1357 struct wpabuf
*resp
, u8 srv_trans_id
,
1358 const u8
*query
, size_t query_len
)
1360 struct p2p_srv_upnp
*usrv
;
1366 wpa_hexdump_ascii(MSG_DEBUG
, "P2P: SD Request for UPnP",
1369 if (dl_list_empty(&wpa_s
->global
->p2p_srv_upnp
)) {
1370 wpa_printf(MSG_DEBUG
, "P2P: UPnP protocol not available");
1371 wpas_sd_add_proto_not_avail(resp
, P2P_SERV_UPNP
,
1376 if (query_len
== 0) {
1377 wpas_sd_all_upnp(wpa_s
, resp
, srv_trans_id
);
1381 if (wpabuf_tailroom(resp
) < 5)
1384 /* Length (to be filled) */
1385 len_pos
= wpabuf_put(resp
, 2);
1386 wpabuf_put_u8(resp
, P2P_SERV_UPNP
);
1387 wpabuf_put_u8(resp
, srv_trans_id
);
1390 str
= os_malloc(query_len
);
1393 os_memcpy(str
, query
+ 1, query_len
- 1);
1394 str
[query_len
- 1] = '\0';
1396 dl_list_for_each(usrv
, &wpa_s
->global
->p2p_srv_upnp
,
1397 struct p2p_srv_upnp
, list
) {
1398 if (version
!= usrv
->version
)
1401 if (os_strcmp(str
, "ssdp:all") != 0 &&
1402 os_strstr(usrv
->service
, str
) == NULL
)
1405 if (wpabuf_tailroom(resp
) < 2)
1409 wpabuf_put_u8(resp
, P2P_SD_SUCCESS
);
1411 wpabuf_put_u8(resp
, version
);
1413 wpabuf_put_u8(resp
, ',');
1417 wpa_printf(MSG_DEBUG
, "P2P: Matching UPnP Service: %s",
1419 if (wpabuf_tailroom(resp
) < os_strlen(usrv
->service
))
1421 wpabuf_put_str(resp
, usrv
->service
);
1425 wpa_printf(MSG_DEBUG
, "P2P: Requested UPnP service not "
1428 wpabuf_put_u8(resp
, P2P_SD_REQUESTED_INFO_NOT_AVAILABLE
);
1429 /* Response Data: empty */
1432 WPA_PUT_LE16(len_pos
, (u8
*) wpabuf_put(resp
, 0) - len_pos
- 2);
1436 void wpas_sd_request(void *ctx
, int freq
, const u8
*sa
, u8 dialog_token
,
1437 u16 update_indic
, const u8
*tlvs
, size_t tlvs_len
)
1439 struct wpa_supplicant
*wpa_s
= ctx
;
1440 const u8
*pos
= tlvs
;
1441 const u8
*end
= tlvs
+ tlvs_len
;
1444 struct wpabuf
*resp
;
1445 u8 srv_proto
, srv_trans_id
;
1449 wpa_hexdump(MSG_MSGDUMP
, "P2P: Service Discovery Request TLVs",
1451 buf_len
= 2 * tlvs_len
+ 1;
1452 buf
= os_malloc(buf_len
);
1454 wpa_snprintf_hex(buf
, buf_len
, tlvs
, tlvs_len
);
1455 wpa_msg_ctrl(wpa_s
, MSG_INFO
, P2P_EVENT_SERV_DISC_REQ
"%d "
1457 freq
, MAC2STR(sa
), dialog_token
, update_indic
,
1462 if (wpa_s
->p2p_sd_over_ctrl_iface
)
1463 return; /* to be processed by an external program */
1465 resp
= wpabuf_alloc(10000);
1469 while (pos
+ 1 < end
) {
1470 wpa_printf(MSG_DEBUG
, "P2P: Service Request TLV");
1471 slen
= WPA_GET_LE16(pos
);
1473 if (pos
+ slen
> end
|| slen
< 2) {
1474 wpa_printf(MSG_DEBUG
, "P2P: Unexpected Query Data "
1479 tlv_end
= pos
+ slen
;
1482 wpa_printf(MSG_DEBUG
, "P2P: Service Protocol Type %u",
1484 srv_trans_id
= *pos
++;
1485 wpa_printf(MSG_DEBUG
, "P2P: Service Transaction ID %u",
1488 wpa_hexdump(MSG_MSGDUMP
, "P2P: Query Data",
1489 pos
, tlv_end
- pos
);
1492 if (wpa_s
->force_long_sd
) {
1493 wpa_printf(MSG_DEBUG
, "P2P: SD test - force long "
1495 wpas_sd_all_bonjour(wpa_s
, resp
, srv_trans_id
);
1496 wpas_sd_all_upnp(wpa_s
, resp
, srv_trans_id
);
1500 switch (srv_proto
) {
1501 case P2P_SERV_ALL_SERVICES
:
1502 wpa_printf(MSG_DEBUG
, "P2P: Service Discovery Request "
1503 "for all services");
1504 if (dl_list_empty(&wpa_s
->global
->p2p_srv_upnp
) &&
1505 dl_list_empty(&wpa_s
->global
->p2p_srv_bonjour
)) {
1506 wpa_printf(MSG_DEBUG
, "P2P: No service "
1507 "discovery protocols available");
1508 wpas_sd_add_proto_not_avail(
1509 resp
, P2P_SERV_ALL_SERVICES
,
1513 wpas_sd_all_bonjour(wpa_s
, resp
, srv_trans_id
);
1514 wpas_sd_all_upnp(wpa_s
, resp
, srv_trans_id
);
1516 case P2P_SERV_BONJOUR
:
1517 wpas_sd_req_bonjour(wpa_s
, resp
, srv_trans_id
,
1518 pos
, tlv_end
- pos
);
1521 wpas_sd_req_upnp(wpa_s
, resp
, srv_trans_id
,
1522 pos
, tlv_end
- pos
);
1525 wpa_printf(MSG_DEBUG
, "P2P: Unavailable service "
1526 "protocol %u", srv_proto
);
1527 wpas_sd_add_proto_not_avail(resp
, srv_proto
,
1536 wpas_p2p_sd_response(wpa_s
, freq
, sa
, dialog_token
, resp
);
1542 void wpas_sd_response(void *ctx
, const u8
*sa
, u16 update_indic
,
1543 const u8
*tlvs
, size_t tlvs_len
)
1545 struct wpa_supplicant
*wpa_s
= ctx
;
1546 const u8
*pos
= tlvs
;
1547 const u8
*end
= tlvs
+ tlvs_len
;
1553 wpa_hexdump(MSG_MSGDUMP
, "P2P: Service Discovery Response TLVs",
1555 if (tlvs_len
> 1500) {
1556 /* TODO: better way for handling this */
1557 wpa_msg_ctrl(wpa_s
, MSG_INFO
,
1558 P2P_EVENT_SERV_DISC_RESP MACSTR
1559 " %u <long response: %u bytes>",
1560 MAC2STR(sa
), update_indic
,
1561 (unsigned int) tlvs_len
);
1563 buf_len
= 2 * tlvs_len
+ 1;
1564 buf
= os_malloc(buf_len
);
1566 wpa_snprintf_hex(buf
, buf_len
, tlvs
, tlvs_len
);
1567 wpa_msg_ctrl(wpa_s
, MSG_INFO
,
1568 P2P_EVENT_SERV_DISC_RESP MACSTR
" %u %s",
1569 MAC2STR(sa
), update_indic
, buf
);
1575 u8 srv_proto
, srv_trans_id
, status
;
1577 wpa_printf(MSG_DEBUG
, "P2P: Service Response TLV");
1578 slen
= WPA_GET_LE16(pos
);
1580 if (pos
+ slen
> end
|| slen
< 3) {
1581 wpa_printf(MSG_DEBUG
, "P2P: Unexpected Response Data "
1585 tlv_end
= pos
+ slen
;
1588 wpa_printf(MSG_DEBUG
, "P2P: Service Protocol Type %u",
1590 srv_trans_id
= *pos
++;
1591 wpa_printf(MSG_DEBUG
, "P2P: Service Transaction ID %u",
1594 wpa_printf(MSG_DEBUG
, "P2P: Status Code ID %u",
1597 wpa_hexdump(MSG_MSGDUMP
, "P2P: Response Data",
1598 pos
, tlv_end
- pos
);
1605 void * wpas_p2p_sd_request(struct wpa_supplicant
*wpa_s
, const u8
*dst
,
1606 const struct wpabuf
*tlvs
)
1608 return p2p_sd_request(wpa_s
->global
->p2p
, dst
, tlvs
);
1612 void * wpas_p2p_sd_request_upnp(struct wpa_supplicant
*wpa_s
, const u8
*dst
,
1613 u8 version
, const char *query
)
1615 struct wpabuf
*tlvs
;
1618 tlvs
= wpabuf_alloc(2 + 1 + 1 + 1 + os_strlen(query
));
1621 wpabuf_put_le16(tlvs
, 1 + 1 + 1 + os_strlen(query
));
1622 wpabuf_put_u8(tlvs
, P2P_SERV_UPNP
); /* Service Protocol Type */
1623 wpabuf_put_u8(tlvs
, 1); /* Service Transaction ID */
1624 wpabuf_put_u8(tlvs
, version
);
1625 wpabuf_put_str(tlvs
, query
);
1626 ret
= wpas_p2p_sd_request(wpa_s
, dst
, tlvs
);
1632 int wpas_p2p_sd_cancel_request(struct wpa_supplicant
*wpa_s
, void *req
)
1634 return p2p_sd_cancel_request(wpa_s
->global
->p2p
, req
);
1638 void wpas_p2p_sd_response(struct wpa_supplicant
*wpa_s
, int freq
,
1639 const u8
*dst
, u8 dialog_token
,
1640 const struct wpabuf
*resp_tlvs
)
1642 p2p_sd_response(wpa_s
->global
->p2p
, freq
, dst
, dialog_token
,
1647 void wpas_p2p_sd_service_update(struct wpa_supplicant
*wpa_s
)
1649 p2p_sd_service_update(wpa_s
->global
->p2p
);
1653 static void wpas_p2p_srv_bonjour_free(struct p2p_srv_bonjour
*bsrv
)
1655 dl_list_del(&bsrv
->list
);
1656 wpabuf_free(bsrv
->query
);
1657 wpabuf_free(bsrv
->resp
);
1662 static void wpas_p2p_srv_upnp_free(struct p2p_srv_upnp
*usrv
)
1664 dl_list_del(&usrv
->list
);
1665 os_free(usrv
->service
);
1670 void wpas_p2p_service_flush(struct wpa_supplicant
*wpa_s
)
1672 struct p2p_srv_bonjour
*bsrv
, *bn
;
1673 struct p2p_srv_upnp
*usrv
, *un
;
1675 dl_list_for_each_safe(bsrv
, bn
, &wpa_s
->global
->p2p_srv_bonjour
,
1676 struct p2p_srv_bonjour
, list
)
1677 wpas_p2p_srv_bonjour_free(bsrv
);
1679 dl_list_for_each_safe(usrv
, un
, &wpa_s
->global
->p2p_srv_upnp
,
1680 struct p2p_srv_upnp
, list
)
1681 wpas_p2p_srv_upnp_free(usrv
);
1683 wpas_p2p_sd_service_update(wpa_s
);
1687 int wpas_p2p_service_add_bonjour(struct wpa_supplicant
*wpa_s
,
1688 struct wpabuf
*query
, struct wpabuf
*resp
)
1690 struct p2p_srv_bonjour
*bsrv
;
1692 bsrv
= wpas_p2p_service_get_bonjour(wpa_s
, query
);
1695 wpabuf_free(bsrv
->resp
);
1700 bsrv
= os_zalloc(sizeof(*bsrv
));
1703 bsrv
->query
= query
;
1705 dl_list_add(&wpa_s
->global
->p2p_srv_bonjour
, &bsrv
->list
);
1707 wpas_p2p_sd_service_update(wpa_s
);
1712 int wpas_p2p_service_del_bonjour(struct wpa_supplicant
*wpa_s
,
1713 const struct wpabuf
*query
)
1715 struct p2p_srv_bonjour
*bsrv
;
1717 bsrv
= wpas_p2p_service_get_bonjour(wpa_s
, query
);
1720 wpas_p2p_srv_bonjour_free(bsrv
);
1721 wpas_p2p_sd_service_update(wpa_s
);
1726 int wpas_p2p_service_add_upnp(struct wpa_supplicant
*wpa_s
, u8 version
,
1727 const char *service
)
1729 struct p2p_srv_upnp
*usrv
;
1731 if (wpas_p2p_service_get_upnp(wpa_s
, version
, service
))
1732 return 0; /* Already listed */
1733 usrv
= os_zalloc(sizeof(*usrv
));
1736 usrv
->version
= version
;
1737 usrv
->service
= os_strdup(service
);
1738 if (usrv
->service
== NULL
) {
1742 dl_list_add(&wpa_s
->global
->p2p_srv_upnp
, &usrv
->list
);
1744 wpas_p2p_sd_service_update(wpa_s
);
1749 int wpas_p2p_service_del_upnp(struct wpa_supplicant
*wpa_s
, u8 version
,
1750 const char *service
)
1752 struct p2p_srv_upnp
*usrv
;
1754 usrv
= wpas_p2p_service_get_upnp(wpa_s
, version
, service
);
1757 wpas_p2p_srv_upnp_free(usrv
);
1758 wpas_p2p_sd_service_update(wpa_s
);
1763 static void wpas_prov_disc_local_display(struct wpa_supplicant
*wpa_s
,
1764 const u8
*peer
, const char *params
)
1766 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_PROV_DISC_SHOW_PIN MACSTR
" %08d%s",
1767 MAC2STR(peer
), wps_generate_pin(), params
);
1771 static void wpas_prov_disc_local_keypad(struct wpa_supplicant
*wpa_s
,
1772 const u8
*peer
, const char *params
)
1774 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_PROV_DISC_ENTER_PIN MACSTR
"%s",
1775 MAC2STR(peer
), params
);
1779 void wpas_prov_disc_req(void *ctx
, const u8
*peer
, u16 config_methods
,
1780 const u8
*dev_addr
, const u8
*pri_dev_type
,
1781 const char *dev_name
, u16 supp_config_methods
,
1782 u8 dev_capab
, u8 group_capab
)
1784 struct wpa_supplicant
*wpa_s
= ctx
;
1785 char devtype
[WPS_DEV_TYPE_BUFSIZE
];
1787 u8 empty_dev_type
[8];
1789 if (pri_dev_type
== NULL
) {
1790 os_memset(empty_dev_type
, 0, sizeof(empty_dev_type
));
1791 pri_dev_type
= empty_dev_type
;
1793 os_snprintf(params
, sizeof(params
), " p2p_dev_addr=" MACSTR
1794 " pri_dev_type=%s name='%s' config_methods=0x%x "
1795 "dev_capab=0x%x group_capab=0x%x",
1797 wps_dev_type_bin2str(pri_dev_type
, devtype
,
1799 dev_name
, supp_config_methods
, dev_capab
, group_capab
);
1800 params
[sizeof(params
) - 1] = '\0';
1802 if (config_methods
& WPS_CONFIG_DISPLAY
)
1803 wpas_prov_disc_local_display(wpa_s
, peer
, params
);
1804 else if (config_methods
& WPS_CONFIG_KEYPAD
)
1805 wpas_prov_disc_local_keypad(wpa_s
, peer
, params
);
1806 else if (config_methods
& WPS_CONFIG_PUSHBUTTON
)
1807 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_PROV_DISC_PBC_REQ MACSTR
1808 "%s", MAC2STR(peer
), params
);
1812 void wpas_prov_disc_resp(void *ctx
, const u8
*peer
, u16 config_methods
)
1814 struct wpa_supplicant
*wpa_s
= ctx
;
1815 if (config_methods
& WPS_CONFIG_DISPLAY
)
1816 wpas_prov_disc_local_keypad(wpa_s
, peer
, "");
1817 else if (config_methods
& WPS_CONFIG_KEYPAD
)
1818 wpas_prov_disc_local_display(wpa_s
, peer
, "");
1819 else if (config_methods
& WPS_CONFIG_PUSHBUTTON
)
1820 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_PROV_DISC_PBC_RESP MACSTR
,
1823 if (wpa_s
->pending_pd_before_join
&&
1824 (os_memcmp(peer
, wpa_s
->pending_join_dev_addr
, ETH_ALEN
) == 0 ||
1825 os_memcmp(peer
, wpa_s
->pending_join_iface_addr
, ETH_ALEN
) == 0)) {
1826 wpa_s
->pending_pd_before_join
= 0;
1827 wpa_printf(MSG_DEBUG
, "P2P: Starting pending "
1828 "join-existing-group operation");
1829 wpas_p2p_join_start(wpa_s
);
1834 static u8
wpas_invitation_process(void *ctx
, const u8
*sa
, const u8
*bssid
,
1835 const u8
*go_dev_addr
, const u8
*ssid
,
1836 size_t ssid_len
, int *go
, u8
*group_bssid
,
1837 int *force_freq
, int persistent_group
)
1839 struct wpa_supplicant
*wpa_s
= ctx
;
1841 u8 cur_bssid
[ETH_ALEN
];
1843 struct wpa_supplicant
*grp
;
1845 if (!persistent_group
) {
1846 wpa_printf(MSG_DEBUG
, "P2P: Invitation from " MACSTR
1847 " to join an active group", MAC2STR(sa
));
1848 if (!is_zero_ether_addr(wpa_s
->p2p_auth_invite
) &&
1849 (os_memcmp(go_dev_addr
, wpa_s
->p2p_auth_invite
, ETH_ALEN
)
1851 os_memcmp(sa
, wpa_s
->p2p_auth_invite
, ETH_ALEN
) == 0)) {
1852 wpa_printf(MSG_DEBUG
, "P2P: Accept previously "
1853 "authorized invitation");
1857 * Do not accept the invitation automatically; notify user and
1860 return P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE
;
1863 grp
= wpas_get_p2p_group(wpa_s
, ssid
, ssid_len
, go
);
1865 wpa_printf(MSG_DEBUG
, "P2P: Accept invitation to already "
1866 "running persistent group");
1868 os_memcpy(group_bssid
, grp
->own_addr
, ETH_ALEN
);
1872 if (!wpa_s
->conf
->persistent_reconnect
)
1873 return P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE
;
1875 for (s
= wpa_s
->conf
->ssid
; s
; s
= s
->next
) {
1876 if (s
->disabled
== 2 &&
1877 os_memcmp(s
->bssid
, go_dev_addr
, ETH_ALEN
) == 0 &&
1878 s
->ssid_len
== ssid_len
&&
1879 os_memcmp(ssid
, s
->ssid
, ssid_len
) == 0)
1884 wpa_printf(MSG_DEBUG
, "P2P: Invitation from " MACSTR
1885 " requested reinvocation of an unknown group",
1887 return P2P_SC_FAIL_UNKNOWN_GROUP
;
1890 if (s
->mode
== WPAS_MODE_P2P_GO
&& !wpas_p2p_create_iface(wpa_s
)) {
1892 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
1893 wpa_printf(MSG_DEBUG
, "P2P: The only available "
1894 "interface is already in use - reject "
1896 return P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE
;
1898 os_memcpy(group_bssid
, wpa_s
->own_addr
, ETH_ALEN
);
1899 } else if (s
->mode
== WPAS_MODE_P2P_GO
) {
1901 if (wpas_p2p_add_group_interface(wpa_s
, WPA_IF_P2P_GO
) < 0)
1903 wpa_printf(MSG_ERROR
, "P2P: Failed to allocate a new "
1904 "interface address for the group");
1905 return P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE
;
1907 os_memcpy(group_bssid
, wpa_s
->pending_interface_addr
,
1912 if (wpa_s
->current_ssid
&& wpa_drv_get_bssid(wpa_s
, cur_bssid
) == 0 &&
1913 wpa_s
->assoc_freq
) {
1914 wpa_printf(MSG_DEBUG
, "P2P: Trying to force channel to match "
1915 "the channel we are already using");
1916 *force_freq
= wpa_s
->assoc_freq
;
1919 res
= wpa_drv_shared_freq(wpa_s
);
1921 wpa_printf(MSG_DEBUG
, "P2P: Trying to force channel to match "
1922 "with the channel we are already using on a "
1923 "shared interface");
1927 return P2P_SC_SUCCESS
;
1931 static void wpas_invitation_received(void *ctx
, const u8
*sa
, const u8
*bssid
,
1932 const u8
*ssid
, size_t ssid_len
,
1933 const u8
*go_dev_addr
, u8 status
,
1936 struct wpa_supplicant
*wpa_s
= ctx
;
1939 for (s
= wpa_s
->conf
->ssid
; s
; s
= s
->next
) {
1940 if (s
->disabled
== 2 &&
1941 s
->ssid_len
== ssid_len
&&
1942 os_memcmp(ssid
, s
->ssid
, ssid_len
) == 0)
1946 if (status
== P2P_SC_SUCCESS
) {
1947 wpa_printf(MSG_DEBUG
, "P2P: Invitation from peer " MACSTR
1948 " was accepted; op_freq=%d MHz",
1949 MAC2STR(sa
), op_freq
);
1951 wpas_p2p_group_add_persistent(
1952 wpa_s
, s
, s
->mode
== WPAS_MODE_P2P_GO
, 0);
1954 wpas_p2p_join(wpa_s
, bssid
, go_dev_addr
,
1955 wpa_s
->p2p_wps_method
);
1960 if (status
!= P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE
) {
1961 wpa_printf(MSG_DEBUG
, "P2P: Invitation from peer " MACSTR
1962 " was rejected (status %u)", MAC2STR(sa
), status
);
1968 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_INVITATION_RECEIVED
1969 "sa=" MACSTR
" go_dev_addr=" MACSTR
1970 " bssid=" MACSTR
" unknown-network",
1971 MAC2STR(sa
), MAC2STR(go_dev_addr
),
1974 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_INVITATION_RECEIVED
1975 "sa=" MACSTR
" go_dev_addr=" MACSTR
1977 MAC2STR(sa
), MAC2STR(go_dev_addr
));
1982 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_INVITATION_RECEIVED
"sa=" MACSTR
1983 " persistent=%d", MAC2STR(sa
), s
->id
);
1987 static void wpas_invitation_result(void *ctx
, int status
, const u8
*bssid
)
1989 struct wpa_supplicant
*wpa_s
= ctx
;
1990 struct wpa_ssid
*ssid
;
1993 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_INVITATION_RESULT
1994 "status=%d " MACSTR
,
1995 status
, MAC2STR(bssid
));
1997 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_INVITATION_RESULT
1998 "status=%d ", status
);
2001 if (wpa_s
->pending_invite_ssid_id
== -1)
2002 return; /* Invitation to active group */
2004 if (status
!= P2P_SC_SUCCESS
) {
2005 wpas_p2p_remove_pending_group_interface(wpa_s
);
2009 ssid
= wpa_config_get_network(wpa_s
->conf
,
2010 wpa_s
->pending_invite_ssid_id
);
2012 wpa_printf(MSG_ERROR
, "P2P: Could not find persistent group "
2013 "data matching with invitation");
2017 wpas_p2p_group_add_persistent(wpa_s
, ssid
,
2018 ssid
->mode
== WPAS_MODE_P2P_GO
, 0);
2022 static int wpas_p2p_default_channels(struct wpa_supplicant
*wpa_s
,
2023 struct p2p_channels
*chan
)
2027 wpa_printf(MSG_DEBUG
, "P2P: Enable operating classes for 2.4 GHz "
2030 /* Operating class 81 - 2.4 GHz band channels 1..13 */
2031 chan
->reg_class
[cla
].reg_class
= 81;
2032 chan
->reg_class
[cla
].channels
= 11;
2033 for (i
= 0; i
< 11; i
++)
2034 chan
->reg_class
[cla
].channel
[i
] = i
+ 1;
2037 wpa_printf(MSG_DEBUG
, "P2P: Enable operating classes for lower 5 GHz "
2040 /* Operating class 115 - 5 GHz, channels 36-48 */
2041 chan
->reg_class
[cla
].reg_class
= 115;
2042 chan
->reg_class
[cla
].channels
= 4;
2043 chan
->reg_class
[cla
].channel
[0] = 36;
2044 chan
->reg_class
[cla
].channel
[1] = 40;
2045 chan
->reg_class
[cla
].channel
[2] = 44;
2046 chan
->reg_class
[cla
].channel
[3] = 48;
2049 wpa_printf(MSG_DEBUG
, "P2P: Enable operating classes for higher 5 GHz "
2052 /* Operating class 124 - 5 GHz, channels 149,153,157,161 */
2053 chan
->reg_class
[cla
].reg_class
= 124;
2054 chan
->reg_class
[cla
].channels
= 4;
2055 chan
->reg_class
[cla
].channel
[0] = 149;
2056 chan
->reg_class
[cla
].channel
[1] = 153;
2057 chan
->reg_class
[cla
].channel
[2] = 157;
2058 chan
->reg_class
[cla
].channel
[3] = 161;
2061 chan
->reg_classes
= cla
;
2066 static struct hostapd_hw_modes
* get_mode(struct hostapd_hw_modes
*modes
,
2068 enum hostapd_hw_mode mode
)
2072 for (i
= 0; i
< num_modes
; i
++) {
2073 if (modes
[i
].mode
== mode
)
2081 static int has_channel(struct hostapd_hw_modes
*mode
, u8 chan
, int *flags
)
2085 for (i
= 0; i
< mode
->num_channels
; i
++) {
2086 if (mode
->channels
[i
].chan
== chan
) {
2088 *flags
= mode
->channels
[i
].flag
;
2089 return !(mode
->channels
[i
].flag
&
2090 (HOSTAPD_CHAN_DISABLED
|
2091 HOSTAPD_CHAN_PASSIVE_SCAN
|
2092 HOSTAPD_CHAN_NO_IBSS
|
2093 HOSTAPD_CHAN_RADAR
));
2101 struct p2p_oper_class_map
{
2102 enum hostapd_hw_mode mode
;
2107 enum { BW20
, BW40PLUS
, BW40MINUS
} bw
;
2110 static int wpas_p2p_setup_channels(struct wpa_supplicant
*wpa_s
,
2111 struct p2p_channels
*chan
)
2113 struct hostapd_hw_modes
*modes
, *mode
;
2114 u16 num_modes
, flags
;
2116 struct p2p_oper_class_map op_class
[] = {
2117 { HOSTAPD_MODE_IEEE80211G
, 81, 1, 13, 1, BW20
},
2118 { HOSTAPD_MODE_IEEE80211G
, 82, 14, 14, 1, BW20
},
2119 #if 0 /* Do not enable HT40 on 2 GHz for now */
2120 { HOSTAPD_MODE_IEEE80211G
, 83, 1, 9, 1, BW40PLUS
},
2121 { HOSTAPD_MODE_IEEE80211G
, 84, 5, 13, 1, BW40MINUS
},
2123 { HOSTAPD_MODE_IEEE80211A
, 115, 36, 48, 4, BW20
},
2124 { HOSTAPD_MODE_IEEE80211A
, 124, 149, 161, 4, BW20
},
2125 { HOSTAPD_MODE_IEEE80211A
, 116, 36, 44, 8, BW40PLUS
},
2126 { HOSTAPD_MODE_IEEE80211A
, 117, 40, 48, 8, BW40MINUS
},
2127 { HOSTAPD_MODE_IEEE80211A
, 126, 149, 157, 8, BW40PLUS
},
2128 { HOSTAPD_MODE_IEEE80211A
, 127, 153, 161, 8, BW40MINUS
},
2129 { -1, 0, 0, 0, 0, BW20
}
2132 modes
= wpa_drv_get_hw_feature_data(wpa_s
, &num_modes
, &flags
);
2133 if (modes
== NULL
) {
2134 wpa_printf(MSG_DEBUG
, "P2P: Driver did not support fetching "
2135 "of all supported channels; assume dualband "
2137 return wpas_p2p_default_channels(wpa_s
, chan
);
2142 for (op
= 0; op_class
[op
].op_class
; op
++) {
2143 struct p2p_oper_class_map
*o
= &op_class
[op
];
2145 struct p2p_reg_class
*reg
= NULL
;
2147 mode
= get_mode(modes
, num_modes
, o
->mode
);
2150 for (ch
= o
->min_chan
; ch
<= o
->max_chan
; ch
+= o
->inc
) {
2152 if (!has_channel(mode
, ch
, &flag
))
2154 if (o
->bw
== BW40MINUS
&&
2155 (!(flag
& HOSTAPD_CHAN_HT40MINUS
) ||
2156 !has_channel(mode
, ch
- 4, NULL
)))
2158 if (o
->bw
== BW40PLUS
&&
2159 (!(flag
& HOSTAPD_CHAN_HT40PLUS
) ||
2160 !has_channel(mode
, ch
+ 4, NULL
)))
2163 wpa_printf(MSG_DEBUG
, "P2P: Add operating "
2164 "class %u", o
->op_class
);
2165 reg
= &chan
->reg_class
[cla
];
2167 reg
->reg_class
= o
->op_class
;
2169 reg
->channel
[reg
->channels
] = ch
;
2173 wpa_hexdump(MSG_DEBUG
, "P2P: Channels",
2174 reg
->channel
, reg
->channels
);
2178 chan
->reg_classes
= cla
;
2180 ieee80211_sta_free_hw_features(modes
, num_modes
);
2186 static int wpas_get_noa(void *ctx
, const u8
*interface_addr
, u8
*buf
,
2189 struct wpa_supplicant
*wpa_s
= ctx
;
2191 for (wpa_s
= wpa_s
->global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
2192 if (os_memcmp(wpa_s
->own_addr
, interface_addr
, ETH_ALEN
) == 0)
2198 return wpa_drv_get_noa(wpa_s
, buf
, buf_len
);
2203 * wpas_p2p_init - Initialize P2P module for %wpa_supplicant
2204 * @global: Pointer to global data from wpa_supplicant_init()
2205 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
2206 * Returns: 0 on success, -1 on failure
2208 int wpas_p2p_init(struct wpa_global
*global
, struct wpa_supplicant
*wpa_s
)
2210 struct p2p_config p2p
;
2214 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_CAPABLE
))
2217 #ifdef CONFIG_CLIENT_MLME
2218 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
)) {
2219 wpa_s
->mlme
.public_action_cb
= p2p_rx_action_mlme
;
2220 wpa_s
->mlme
.public_action_cb_ctx
= wpa_s
;
2222 #endif /* CONFIG_CLIENT_MLME */
2224 if (wpa_drv_disable_11b_rates(wpa_s
, 1) < 0) {
2225 wpa_printf(MSG_DEBUG
, "P2P: Failed to disable 11b rates");
2226 /* Continue anyway; this is not really a fatal error */
2232 os_memset(&p2p
, 0, sizeof(p2p
));
2233 p2p
.msg_ctx
= wpa_s
;
2235 p2p
.p2p_scan
= wpas_p2p_scan
;
2236 p2p
.send_action
= wpas_send_action
;
2237 p2p
.send_action_done
= wpas_send_action_done
;
2238 p2p
.go_neg_completed
= wpas_go_neg_completed
;
2239 p2p
.go_neg_req_rx
= wpas_go_neg_req_rx
;
2240 p2p
.dev_found
= wpas_dev_found
;
2241 p2p
.start_listen
= wpas_start_listen
;
2242 p2p
.stop_listen
= wpas_stop_listen
;
2243 p2p
.send_probe_resp
= wpas_send_probe_resp
;
2244 p2p
.sd_request
= wpas_sd_request
;
2245 p2p
.sd_response
= wpas_sd_response
;
2246 p2p
.prov_disc_req
= wpas_prov_disc_req
;
2247 p2p
.prov_disc_resp
= wpas_prov_disc_resp
;
2248 p2p
.invitation_process
= wpas_invitation_process
;
2249 p2p
.invitation_received
= wpas_invitation_received
;
2250 p2p
.invitation_result
= wpas_invitation_result
;
2251 p2p
.get_noa
= wpas_get_noa
;
2253 os_memcpy(wpa_s
->global
->p2p_dev_addr
, wpa_s
->own_addr
, ETH_ALEN
);
2254 os_memcpy(p2p
.dev_addr
, wpa_s
->own_addr
, ETH_ALEN
);
2255 p2p
.dev_name
= wpa_s
->conf
->device_name
;
2257 if (wpa_s
->conf
->p2p_listen_reg_class
&&
2258 wpa_s
->conf
->p2p_listen_channel
) {
2259 p2p
.reg_class
= wpa_s
->conf
->p2p_listen_reg_class
;
2260 p2p
.channel
= wpa_s
->conf
->p2p_listen_channel
;
2264 * Pick one of the social channels randomly as the listen
2267 os_get_random((u8
*) &r
, sizeof(r
));
2268 p2p
.channel
= 1 + (r
% 3) * 5;
2270 wpa_printf(MSG_DEBUG
, "P2P: Own listen channel: %d", p2p
.channel
);
2272 if (wpa_s
->conf
->p2p_oper_reg_class
&&
2273 wpa_s
->conf
->p2p_oper_channel
) {
2274 p2p
.op_reg_class
= wpa_s
->conf
->p2p_oper_reg_class
;
2275 p2p
.op_channel
= wpa_s
->conf
->p2p_oper_channel
;
2276 p2p
.cfg_op_channel
= 1;
2277 wpa_printf(MSG_DEBUG
, "P2P: Configured operating channel: "
2278 "%d:%d", p2p
.op_reg_class
, p2p
.op_channel
);
2281 p2p
.op_reg_class
= 81;
2283 * Use random operation channel from (1, 6, 11) if no other
2284 * preference is indicated.
2286 os_get_random((u8
*) &r
, sizeof(r
));
2287 p2p
.op_channel
= 1 + (r
% 3) * 5;
2288 p2p
.cfg_op_channel
= 0;
2289 wpa_printf(MSG_DEBUG
, "P2P: Random operating channel: "
2290 "%d:%d", p2p
.op_reg_class
, p2p
.op_channel
);
2292 if (wpa_s
->conf
->country
[0] && wpa_s
->conf
->country
[1]) {
2293 os_memcpy(p2p
.country
, wpa_s
->conf
->country
, 2);
2294 p2p
.country
[2] = 0x04;
2296 os_memcpy(p2p
.country
, "XX\x04", 3);
2298 if (wpas_p2p_setup_channels(wpa_s
, &p2p
.channels
)) {
2299 wpa_printf(MSG_ERROR
, "P2P: Failed to configure supported "
2304 if (wpa_s
->conf
->device_type
&&
2305 wps_dev_type_str2bin(wpa_s
->conf
->device_type
, p2p
.pri_dev_type
) <
2307 wpa_printf(MSG_ERROR
, "P2P: Invalid device_type");
2311 for (i
= 0; i
< MAX_SEC_DEVICE_TYPES
; i
++) {
2312 if (wpa_s
->conf
->sec_device_type
[i
] == NULL
)
2314 if (wps_dev_type_str2bin(
2315 wpa_s
->conf
->sec_device_type
[i
],
2316 p2p
.sec_dev_type
[p2p
.num_sec_dev_types
]) < 0) {
2317 wpa_printf(MSG_ERROR
, "P2P: Invalid sec_device_type");
2320 p2p
.num_sec_dev_types
++;
2321 if (p2p
.num_sec_dev_types
== P2P_SEC_DEVICE_TYPES
)
2325 p2p
.concurrent_operations
= !!(wpa_s
->drv_flags
&
2326 WPA_DRIVER_FLAGS_P2P_CONCURRENT
);
2328 p2p
.max_peers
= 100;
2330 if (wpa_s
->conf
->p2p_ssid_postfix
) {
2331 p2p
.ssid_postfix_len
=
2332 os_strlen(wpa_s
->conf
->p2p_ssid_postfix
);
2333 if (p2p
.ssid_postfix_len
> sizeof(p2p
.ssid_postfix
))
2334 p2p
.ssid_postfix_len
= sizeof(p2p
.ssid_postfix
);
2335 os_memcpy(p2p
.ssid_postfix
, wpa_s
->conf
->p2p_ssid_postfix
,
2336 p2p
.ssid_postfix_len
);
2339 p2p
.p2p_intra_bss
= wpa_s
->conf
->p2p_intra_bss
;
2341 global
->p2p
= p2p_init(&p2p
);
2342 if (global
->p2p
== NULL
)
2350 * wpas_p2p_deinit - Deinitialize per-interface P2P data
2351 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
2353 * This function deinitialize per-interface P2P data.
2355 void wpas_p2p_deinit(struct wpa_supplicant
*wpa_s
)
2357 if (wpa_s
->driver
&& wpa_s
->drv_priv
)
2358 wpa_drv_probe_req_report(wpa_s
, 0);
2359 os_free(wpa_s
->go_params
);
2360 wpa_s
->go_params
= NULL
;
2361 wpabuf_free(wpa_s
->pending_action_tx
);
2362 wpa_s
->pending_action_tx
= NULL
;
2363 eloop_cancel_timeout(wpas_send_action_cb
, wpa_s
, NULL
);
2364 eloop_cancel_timeout(wpas_p2p_group_formation_timeout
, wpa_s
, NULL
);
2365 eloop_cancel_timeout(wpas_p2p_join_scan
, wpa_s
, NULL
);
2366 wpa_s
->p2p_long_listen
= 0;
2367 eloop_cancel_timeout(wpas_p2p_long_listen_timeout
, wpa_s
, NULL
);
2368 eloop_cancel_timeout(wpas_p2p_group_idle_timeout
, wpa_s
, NULL
);
2369 wpas_p2p_remove_pending_group_interface(wpa_s
);
2371 /* TODO: remove group interface from the driver if this wpa_s instance
2372 * is on top of a P2P group interface */
2377 * wpas_p2p_deinit_global - Deinitialize global P2P module
2378 * @global: Pointer to global data from wpa_supplicant_init()
2380 * This function deinitializes the global (per device) P2P module.
2382 void wpas_p2p_deinit_global(struct wpa_global
*global
)
2384 struct wpa_supplicant
*wpa_s
, *tmp
;
2387 if (global
->p2p
== NULL
)
2390 /* Remove remaining P2P group interfaces */
2391 wpa_s
= global
->ifaces
;
2393 wpas_p2p_service_flush(wpa_s
);
2394 while (wpa_s
&& wpa_s
->p2p_group_interface
!= NOT_P2P_GROUP_INTERFACE
)
2395 wpa_s
= wpa_s
->next
;
2397 enum wpa_driver_if_type type
;
2398 tmp
= global
->ifaces
;
2401 tmp
->p2p_group_interface
== NOT_P2P_GROUP_INTERFACE
)) {
2406 ifname
= os_strdup(tmp
->ifname
);
2407 type
= wpas_p2p_if_type(tmp
->p2p_group_interface
);
2408 wpa_supplicant_remove_iface(global
, tmp
);
2410 wpa_drv_if_remove(wpa_s
, type
, ifname
);
2415 * Deinit GO data on any possibly remaining interface (if main
2416 * interface is used as GO).
2418 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
2419 if (wpa_s
->ap_iface
)
2420 wpas_p2p_group_deinit(wpa_s
);
2423 p2p_deinit(global
->p2p
);
2428 static int wpas_p2p_create_iface(struct wpa_supplicant
*wpa_s
)
2430 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_DEDICATED_INTERFACE
)
2431 return 1; /* P2P group requires a new interface in every case
2433 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_CONCURRENT
))
2434 return 0; /* driver does not support concurrent operations */
2435 if (wpa_s
->global
->ifaces
->next
)
2436 return 1; /* more that one interface already in use */
2437 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
)
2438 return 1; /* this interface is already in use */
2443 static int wpas_p2p_start_go_neg(struct wpa_supplicant
*wpa_s
,
2444 const u8
*peer_addr
,
2445 enum p2p_wps_method wps_method
,
2446 int go_intent
, const u8
*own_interface_addr
,
2447 unsigned int force_freq
, int persistent_group
)
2449 return p2p_connect(wpa_s
->global
->p2p
, peer_addr
, wps_method
,
2450 go_intent
, own_interface_addr
, force_freq
,
2455 static int wpas_p2p_auth_go_neg(struct wpa_supplicant
*wpa_s
,
2456 const u8
*peer_addr
,
2457 enum p2p_wps_method wps_method
,
2458 int go_intent
, const u8
*own_interface_addr
,
2459 unsigned int force_freq
, int persistent_group
)
2461 return p2p_authorize(wpa_s
->global
->p2p
, peer_addr
, wps_method
,
2462 go_intent
, own_interface_addr
, force_freq
,
2467 static void wpas_p2p_check_join_scan_limit(struct wpa_supplicant
*wpa_s
)
2469 wpa_s
->p2p_join_scan_count
++;
2470 wpa_printf(MSG_DEBUG
, "P2P: Join scan attempt %d",
2471 wpa_s
->p2p_join_scan_count
);
2472 if (wpa_s
->p2p_join_scan_count
> P2P_MAX_JOIN_SCAN_ATTEMPTS
) {
2473 wpa_printf(MSG_DEBUG
, "P2P: Failed to find GO " MACSTR
2474 " for join operationg - stop join attempt",
2475 MAC2STR(wpa_s
->pending_join_iface_addr
));
2476 eloop_cancel_timeout(wpas_p2p_join_scan
, wpa_s
, NULL
);
2477 wpa_msg(wpa_s
->parent
, MSG_INFO
,
2478 P2P_EVENT_GROUP_FORMATION_FAILURE
);
2483 static void wpas_p2p_scan_res_join(struct wpa_supplicant
*wpa_s
,
2484 struct wpa_scan_results
*scan_res
)
2486 struct wpa_bss
*bss
;
2488 u8 iface_addr
[ETH_ALEN
];
2490 eloop_cancel_timeout(wpas_p2p_join_scan
, wpa_s
, NULL
);
2492 if (wpa_s
->global
->p2p_disabled
)
2495 wpa_printf(MSG_DEBUG
, "P2P: Scan results received (%d BSS) for join",
2496 scan_res
? (int) scan_res
->num
: -1);
2499 wpas_p2p_scan_res_handler(wpa_s
, scan_res
);
2501 freq
= p2p_get_oper_freq(wpa_s
->global
->p2p
,
2502 wpa_s
->pending_join_iface_addr
);
2504 p2p_get_interface_addr(wpa_s
->global
->p2p
,
2505 wpa_s
->pending_join_dev_addr
,
2507 os_memcmp(iface_addr
, wpa_s
->pending_join_dev_addr
, ETH_ALEN
) != 0)
2509 wpa_printf(MSG_DEBUG
, "P2P: Overwrite pending interface "
2510 "address for join from " MACSTR
" to " MACSTR
2511 " based on newly discovered P2P peer entry",
2512 MAC2STR(wpa_s
->pending_join_iface_addr
),
2513 MAC2STR(iface_addr
));
2514 os_memcpy(wpa_s
->pending_join_iface_addr
, iface_addr
,
2517 freq
= p2p_get_oper_freq(wpa_s
->global
->p2p
,
2518 wpa_s
->pending_join_iface_addr
);
2521 wpa_printf(MSG_DEBUG
, "P2P: Target GO operating frequency "
2522 "from P2P peer table: %d MHz", freq
);
2524 bss
= wpa_bss_get_bssid(wpa_s
, wpa_s
->pending_join_iface_addr
);
2527 wpa_printf(MSG_DEBUG
, "P2P: Target GO operating frequency "
2528 "from BSS table: %d MHz", freq
);
2533 wpa_printf(MSG_DEBUG
, "P2P: Send Provision Discovery Request "
2534 "prior to joining an existing group (GO " MACSTR
2536 MAC2STR(wpa_s
->pending_join_dev_addr
), freq
);
2537 wpa_s
->pending_pd_before_join
= 1;
2539 switch (wpa_s
->pending_join_wps_method
) {
2541 case WPS_PIN_DISPLAY
:
2542 method
= WPS_CONFIG_KEYPAD
;
2544 case WPS_PIN_KEYPAD
:
2545 method
= WPS_CONFIG_DISPLAY
;
2548 method
= WPS_CONFIG_PUSHBUTTON
;
2555 if (p2p_prov_disc_req(wpa_s
->global
->p2p
,
2556 wpa_s
->pending_join_dev_addr
, method
, 1)
2558 wpa_printf(MSG_DEBUG
, "P2P: Failed to send Provision "
2559 "Discovery Request before joining an "
2561 wpa_s
->pending_pd_before_join
= 0;
2566 * Actual join operation will be started from the Action frame
2567 * TX status callback.
2572 wpa_printf(MSG_DEBUG
, "P2P: Failed to find BSS/GO - try again later");
2573 eloop_cancel_timeout(wpas_p2p_join_scan
, wpa_s
, NULL
);
2574 eloop_register_timeout(1, 0, wpas_p2p_join_scan
, wpa_s
, NULL
);
2575 wpas_p2p_check_join_scan_limit(wpa_s
);
2579 /* Start join operation immediately */
2580 wpas_p2p_join_start(wpa_s
);
2584 static void wpas_p2p_join_scan(void *eloop_ctx
, void *timeout_ctx
)
2586 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
2588 struct wpa_driver_scan_params params
;
2589 struct wpabuf
*wps_ie
, *ies
;
2591 os_memset(¶ms
, 0, sizeof(params
));
2593 /* P2P Wildcard SSID */
2594 params
.num_ssids
= 1;
2595 params
.ssids
[0].ssid
= (u8
*) P2P_WILDCARD_SSID
;
2596 params
.ssids
[0].ssid_len
= P2P_WILDCARD_SSID_LEN
;
2598 wpa_s
->wps
->dev
.p2p
= 1;
2599 wps_ie
= wps_build_probe_req_ie(0, &wpa_s
->wps
->dev
, wpa_s
->wps
->uuid
,
2601 if (wps_ie
== NULL
) {
2602 wpas_p2p_scan_res_join(wpa_s
, NULL
);
2606 ies
= wpabuf_alloc(wpabuf_len(wps_ie
) + 100);
2608 wpabuf_free(wps_ie
);
2609 wpas_p2p_scan_res_join(wpa_s
, NULL
);
2612 wpabuf_put_buf(ies
, wps_ie
);
2613 wpabuf_free(wps_ie
);
2615 p2p_scan_ie(wpa_s
->global
->p2p
, ies
);
2617 params
.extra_ies
= wpabuf_head(ies
);
2618 params
.extra_ies_len
= wpabuf_len(ies
);
2621 * Run a scan to update BSS table and start Provision Discovery once
2622 * the new scan results become available.
2624 wpa_s
->scan_res_handler
= wpas_p2p_scan_res_join
;
2625 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_USER_SPACE_MLME
)
2626 ret
= ieee80211_sta_req_scan(wpa_s
, ¶ms
);
2628 ret
= wpa_drv_scan(wpa_s
, ¶ms
);
2633 wpa_printf(MSG_DEBUG
, "P2P: Failed to start scan for join - "
2635 eloop_cancel_timeout(wpas_p2p_join_scan
, wpa_s
, NULL
);
2636 eloop_register_timeout(1, 0, wpas_p2p_join_scan
, wpa_s
, NULL
);
2637 wpas_p2p_check_join_scan_limit(wpa_s
);
2642 static int wpas_p2p_join(struct wpa_supplicant
*wpa_s
, const u8
*iface_addr
,
2643 const u8
*dev_addr
, enum p2p_wps_method wps_method
)
2645 wpa_printf(MSG_DEBUG
, "P2P: Request to join existing group (iface "
2646 MACSTR
" dev " MACSTR
")",
2647 MAC2STR(iface_addr
), MAC2STR(dev_addr
));
2649 os_memcpy(wpa_s
->pending_join_iface_addr
, iface_addr
, ETH_ALEN
);
2650 os_memcpy(wpa_s
->pending_join_dev_addr
, dev_addr
, ETH_ALEN
);
2651 wpa_s
->pending_join_wps_method
= wps_method
;
2653 /* Make sure we are not running find during connection establishment */
2654 wpas_p2p_stop_find(wpa_s
);
2656 wpa_s
->p2p_join_scan_count
= 0;
2657 wpas_p2p_join_scan(wpa_s
, NULL
);
2662 static int wpas_p2p_join_start(struct wpa_supplicant
*wpa_s
)
2664 struct wpa_supplicant
*group
;
2665 struct p2p_go_neg_results res
;
2667 group
= wpas_p2p_get_group_iface(wpa_s
, 0, 0);
2670 if (group
!= wpa_s
) {
2671 os_memcpy(group
->p2p_pin
, wpa_s
->p2p_pin
,
2672 sizeof(group
->p2p_pin
));
2673 group
->p2p_wps_method
= wpa_s
->p2p_wps_method
;
2676 group
->p2p_in_provisioning
= 1;
2678 os_memset(&res
, 0, sizeof(res
));
2679 os_memcpy(res
.peer_interface_addr
, wpa_s
->pending_join_iface_addr
,
2681 res
.wps_method
= wpa_s
->pending_join_wps_method
;
2682 wpas_start_wps_enrollee(group
, &res
);
2685 * Allow a longer timeout for join-a-running-group than normal 15
2686 * second group formation timeout since the GO may not have authorized
2687 * our connection yet.
2689 eloop_cancel_timeout(wpas_p2p_group_formation_timeout
, wpa_s
, NULL
);
2690 eloop_register_timeout(60, 0, wpas_p2p_group_formation_timeout
,
2698 * wpas_p2p_connect - Request P2P Group Formation to be started
2699 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
2700 * @peer_addr: Address of the peer P2P Device
2701 * @pin: PIN to use during provisioning or %NULL to indicate PBC mode
2702 * @persistent_group: Whether to create a persistent group
2703 * @join: Whether to join an existing group (as a client) instead of starting
2704 * Group Owner negotiation; @peer_addr is BSSID in that case
2705 * @auth: Whether to only authorize the connection instead of doing that and
2706 * initiating Group Owner negotiation
2707 * @go_intent: GO Intent or -1 to use default
2708 * @freq: Frequency for the group or 0 for auto-selection
2709 * Returns: 0 or new PIN (if pin was %NULL) on success, -1 on unspecified
2710 * failure, -2 on failure due to channel not currently available,
2711 * -3 if forced channel is not supported
2713 int wpas_p2p_connect(struct wpa_supplicant
*wpa_s
, const u8
*peer_addr
,
2714 const char *pin
, enum p2p_wps_method wps_method
,
2715 int persistent_group
, int join
, int auth
, int go_intent
,
2718 int force_freq
= 0, oper_freq
= 0;
2721 enum wpa_driver_if_type iftype
;
2724 go_intent
= wpa_s
->conf
->p2p_go_intent
;
2727 wpa_s
->p2p_long_listen
= 0;
2729 wpa_s
->p2p_wps_method
= wps_method
;
2732 os_strlcpy(wpa_s
->p2p_pin
, pin
, sizeof(wpa_s
->p2p_pin
));
2733 else if (wps_method
== WPS_PIN_DISPLAY
) {
2734 ret
= wps_generate_pin();
2735 os_snprintf(wpa_s
->p2p_pin
, sizeof(wpa_s
->p2p_pin
), "%08d",
2737 wpa_printf(MSG_DEBUG
, "P2P: Randomly generated PIN: %s",
2740 wpa_s
->p2p_pin
[0] = '\0';
2743 u8 iface_addr
[ETH_ALEN
], dev_addr
[ETH_ALEN
];
2745 wpa_printf(MSG_DEBUG
, "P2P: Authorize invitation to "
2746 "connect a running group from " MACSTR
,
2747 MAC2STR(peer_addr
));
2748 os_memcpy(wpa_s
->p2p_auth_invite
, peer_addr
, ETH_ALEN
);
2751 os_memcpy(dev_addr
, peer_addr
, ETH_ALEN
);
2752 if (p2p_get_interface_addr(wpa_s
->global
->p2p
, peer_addr
,
2754 os_memcpy(iface_addr
, peer_addr
, ETH_ALEN
);
2755 p2p_get_dev_addr(wpa_s
->global
->p2p
, peer_addr
,
2758 if (wpas_p2p_join(wpa_s
, iface_addr
, dev_addr
, wps_method
) <
2764 if (wpa_s
->current_ssid
&& wpa_drv_get_bssid(wpa_s
, bssid
) == 0 &&
2766 oper_freq
= wpa_s
->assoc_freq
;
2768 oper_freq
= wpa_drv_shared_freq(wpa_s
);
2774 if (!p2p_supported_freq(wpa_s
->global
->p2p
, freq
)) {
2775 wpa_printf(MSG_DEBUG
, "P2P: The forced channel "
2776 "(%u MHz) is not supported for P2P uses",
2781 if (oper_freq
> 0 && freq
!= oper_freq
&&
2782 !(wpa_s
->drv_flags
&
2783 WPA_DRIVER_FLAGS_MULTI_CHANNEL_CONCURRENT
)) {
2784 wpa_printf(MSG_DEBUG
, "P2P: Cannot start P2P group "
2785 "on %u MHz while connected on another "
2786 "channel (%u MHz)", freq
, oper_freq
);
2789 wpa_printf(MSG_DEBUG
, "P2P: Trying to force us to use the "
2790 "requested channel (%u MHz)", freq
);
2792 } else if (oper_freq
> 0 &&
2793 !p2p_supported_freq(wpa_s
->global
->p2p
, oper_freq
)) {
2794 if (!(wpa_s
->drv_flags
&
2795 WPA_DRIVER_FLAGS_MULTI_CHANNEL_CONCURRENT
)) {
2796 wpa_printf(MSG_DEBUG
, "P2P: Cannot start P2P group "
2797 "while connected on non-P2P supported "
2798 "channel (%u MHz)", oper_freq
);
2801 wpa_printf(MSG_DEBUG
, "P2P: Current operating channel "
2802 "(%u MHz) not available for P2P - try to use "
2803 "another channel", oper_freq
);
2805 } else if (oper_freq
> 0) {
2806 wpa_printf(MSG_DEBUG
, "P2P: Trying to force us to use the "
2807 "channel we are already using (%u MHz) on another "
2808 "interface", oper_freq
);
2809 force_freq
= oper_freq
;
2812 wpa_s
->create_p2p_iface
= wpas_p2p_create_iface(wpa_s
);
2814 if (!wpa_s
->create_p2p_iface
) {
2816 if (wpas_p2p_auth_go_neg(wpa_s
, peer_addr
, wps_method
,
2817 go_intent
, wpa_s
->own_addr
,
2818 force_freq
, persistent_group
)
2823 if (wpas_p2p_start_go_neg(wpa_s
, peer_addr
, wps_method
,
2824 go_intent
, wpa_s
->own_addr
,
2825 force_freq
, persistent_group
) < 0)
2830 /* Prepare to add a new interface for the group */
2831 iftype
= WPA_IF_P2P_GROUP
;
2833 iftype
= WPA_IF_P2P_CLIENT
;
2834 else if (go_intent
== 15)
2835 iftype
= WPA_IF_P2P_GO
;
2836 if (wpas_p2p_add_group_interface(wpa_s
, iftype
) < 0) {
2837 wpa_printf(MSG_ERROR
, "P2P: Failed to allocate a new "
2838 "interface for the group");
2843 if (wpas_p2p_auth_go_neg(wpa_s
, peer_addr
, wps_method
,
2845 wpa_s
->pending_interface_addr
,
2846 force_freq
, persistent_group
) < 0)
2850 if (wpas_p2p_start_go_neg(wpa_s
, peer_addr
, wps_method
, go_intent
,
2851 wpa_s
->pending_interface_addr
,
2852 force_freq
, persistent_group
) < 0) {
2853 wpas_p2p_remove_pending_group_interface(wpa_s
);
2861 * wpas_p2p_remain_on_channel_cb - Indication of remain-on-channel start
2862 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
2863 * @freq: Frequency of the channel in MHz
2864 * @duration: Duration of the stay on the channel in milliseconds
2866 * This callback is called when the driver indicates that it has started the
2867 * requested remain-on-channel duration.
2869 void wpas_p2p_remain_on_channel_cb(struct wpa_supplicant
*wpa_s
,
2870 unsigned int freq
, unsigned int duration
)
2872 wpa_s
->roc_waiting_drv_freq
= 0;
2873 wpa_s
->off_channel_freq
= freq
;
2874 wpas_send_action_cb(wpa_s
, NULL
);
2875 if (wpa_s
->off_channel_freq
== wpa_s
->pending_listen_freq
) {
2876 p2p_listen_cb(wpa_s
->global
->p2p
, wpa_s
->pending_listen_freq
,
2877 wpa_s
->pending_listen_duration
);
2878 wpa_s
->pending_listen_freq
= 0;
2883 static int wpas_p2p_listen_start(struct wpa_supplicant
*wpa_s
,
2884 unsigned int timeout
)
2886 /* Limit maximum Listen state time based on driver limitation. */
2887 if (timeout
> wpa_s
->max_remain_on_chan
)
2888 timeout
= wpa_s
->max_remain_on_chan
;
2890 return p2p_listen(wpa_s
->global
->p2p
, timeout
);
2895 * wpas_p2p_cancel_remain_on_channel_cb - Remain-on-channel timeout
2896 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
2897 * @freq: Frequency of the channel in MHz
2899 * This callback is called when the driver indicates that a remain-on-channel
2900 * operation has been completed, i.e., the duration on the requested channel
2903 void wpas_p2p_cancel_remain_on_channel_cb(struct wpa_supplicant
*wpa_s
,
2906 wpa_printf(MSG_DEBUG
, "P2P: Cancel remain-on-channel callback "
2907 "(p2p_long_listen=%d pending_action_tx=%p)",
2908 wpa_s
->p2p_long_listen
, wpa_s
->pending_action_tx
);
2909 wpa_s
->off_channel_freq
= 0;
2910 if (p2p_listen_end(wpa_s
->global
->p2p
, freq
) > 0)
2911 return; /* P2P module started a new operation */
2912 if (wpa_s
->pending_action_tx
)
2914 if (wpa_s
->p2p_long_listen
> 0)
2915 wpa_s
->p2p_long_listen
-= 5;
2916 if (wpa_s
->p2p_long_listen
> 0) {
2917 wpa_printf(MSG_DEBUG
, "P2P: Continuing long Listen state");
2918 wpas_p2p_listen_start(wpa_s
, wpa_s
->p2p_long_listen
* 1000);
2924 * wpas_p2p_group_remove - Remove a P2P group
2925 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
2926 * @ifname: Network interface name of the group interface or "*" to remove all
2928 * Returns: 0 on success, -1 on failure
2930 * This function is used to remove a P2P group. This can be used to disconnect
2931 * from a group in which the local end is a P2P Client or to end a P2P Group in
2932 * case the local end is the Group Owner. If a virtual network interface was
2933 * created for this group, that interface will be removed. Otherwise, only the
2934 * configured P2P group network will be removed from the interface.
2936 int wpas_p2p_group_remove(struct wpa_supplicant
*wpa_s
, const char *ifname
)
2938 struct wpa_global
*global
= wpa_s
->global
;
2940 if (os_strcmp(ifname
, "*") == 0) {
2941 struct wpa_supplicant
*prev
;
2942 wpa_s
= global
->ifaces
;
2945 wpa_s
= wpa_s
->next
;
2946 prev
->removal_reason
= P2P_GROUP_REMOVAL_REQUESTED
;
2947 wpas_p2p_group_delete(prev
);
2952 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
2953 if (os_strcmp(wpa_s
->ifname
, ifname
) == 0)
2960 wpa_s
->removal_reason
= P2P_GROUP_REMOVAL_REQUESTED
;
2961 wpas_p2p_group_delete(wpa_s
);
2967 static void wpas_p2p_init_go_params(struct wpa_supplicant
*wpa_s
,
2968 struct p2p_go_neg_results
*params
,
2974 os_memset(params
, 0, sizeof(*params
));
2975 params
->role_go
= 1;
2977 wpa_printf(MSG_DEBUG
, "P2P: Set GO freq based on forced "
2978 "frequency %d MHz", freq
);
2979 params
->freq
= freq
;
2980 } else if (wpa_s
->conf
->p2p_oper_reg_class
== 81 &&
2981 wpa_s
->conf
->p2p_oper_channel
>= 1 &&
2982 wpa_s
->conf
->p2p_oper_channel
<= 11) {
2983 params
->freq
= 2407 + 5 * wpa_s
->conf
->p2p_oper_channel
;
2984 wpa_printf(MSG_DEBUG
, "P2P: Set GO freq based on configured "
2985 "frequency %d MHz", params
->freq
);
2986 } else if (wpa_s
->conf
->p2p_oper_reg_class
== 115 ||
2987 wpa_s
->conf
->p2p_oper_reg_class
== 118) {
2988 params
->freq
= 5000 + 5 * wpa_s
->conf
->p2p_oper_channel
;
2989 wpa_printf(MSG_DEBUG
, "P2P: Set GO freq based on configured "
2990 "frequency %d MHz", params
->freq
);
2991 } else if (wpa_s
->conf
->p2p_oper_channel
== 0 &&
2992 wpa_s
->best_overall_freq
> 0 &&
2993 p2p_supported_freq(wpa_s
->global
->p2p
,
2994 wpa_s
->best_overall_freq
)) {
2995 params
->freq
= wpa_s
->best_overall_freq
;
2996 wpa_printf(MSG_DEBUG
, "P2P: Set GO freq based on best overall "
2997 "channel %d MHz", params
->freq
);
2998 } else if (wpa_s
->conf
->p2p_oper_channel
== 0 &&
2999 wpa_s
->best_24_freq
> 0 &&
3000 p2p_supported_freq(wpa_s
->global
->p2p
,
3001 wpa_s
->best_24_freq
)) {
3002 params
->freq
= wpa_s
->best_24_freq
;
3003 wpa_printf(MSG_DEBUG
, "P2P: Set GO freq based on best 2.4 GHz "
3004 "channel %d MHz", params
->freq
);
3005 } else if (wpa_s
->conf
->p2p_oper_channel
== 0 &&
3006 wpa_s
->best_5_freq
> 0 &&
3007 p2p_supported_freq(wpa_s
->global
->p2p
,
3008 wpa_s
->best_5_freq
)) {
3009 params
->freq
= wpa_s
->best_5_freq
;
3010 wpa_printf(MSG_DEBUG
, "P2P: Set GO freq based on best 5 GHz "
3011 "channel %d MHz", params
->freq
);
3013 params
->freq
= 2412;
3014 wpa_printf(MSG_DEBUG
, "P2P: Set GO freq %d MHz (no preference "
3015 "known)", params
->freq
);
3018 if (wpa_s
->current_ssid
&& wpa_drv_get_bssid(wpa_s
, bssid
) == 0 &&
3019 wpa_s
->assoc_freq
&& !freq
) {
3020 wpa_printf(MSG_DEBUG
, "P2P: Force GO on the channel we are "
3022 params
->freq
= wpa_s
->assoc_freq
;
3025 res
= wpa_drv_shared_freq(wpa_s
);
3026 if (res
> 0 && !freq
) {
3027 wpa_printf(MSG_DEBUG
, "P2P: Force GO on the channel we are "
3028 "already using on a shared interface");
3034 static struct wpa_supplicant
*
3035 wpas_p2p_get_group_iface(struct wpa_supplicant
*wpa_s
, int addr_allocated
,
3038 struct wpa_supplicant
*group_wpa_s
;
3040 if (!wpas_p2p_create_iface(wpa_s
))
3043 if (wpas_p2p_add_group_interface(wpa_s
, go
? WPA_IF_P2P_GO
:
3044 WPA_IF_P2P_CLIENT
) < 0)
3046 group_wpa_s
= wpas_p2p_init_group_interface(wpa_s
, go
);
3047 if (group_wpa_s
== NULL
) {
3048 wpas_p2p_remove_pending_group_interface(wpa_s
);
3057 * wpas_p2p_group_add - Add a new P2P group with local end as Group Owner
3058 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
3059 * @persistent_group: Whether to create a persistent group
3060 * @freq: Frequency for the group or 0 to indicate no hardcoding
3061 * Returns: 0 on success, -1 on failure
3063 * This function creates a new P2P group with the local end as the Group Owner,
3064 * i.e., without using Group Owner Negotiation.
3066 int wpas_p2p_group_add(struct wpa_supplicant
*wpa_s
, int persistent_group
,
3069 struct p2p_go_neg_results params
;
3073 wpa_printf(MSG_DEBUG
, "P2P: Request to start GO on 2.4 GHz "
3075 if (wpa_s
->best_24_freq
> 0 &&
3076 p2p_supported_freq(wpa_s
->global
->p2p
,
3077 wpa_s
->best_24_freq
)) {
3078 freq
= wpa_s
->best_24_freq
;
3079 wpa_printf(MSG_DEBUG
, "P2P: Use best 2.4 GHz band "
3080 "channel: %d MHz", freq
);
3082 os_get_random((u8
*) &r
, sizeof(r
));
3083 freq
= 2412 + (r
% 3) * 25;
3084 wpa_printf(MSG_DEBUG
, "P2P: Use random 2.4 GHz band "
3085 "channel: %d MHz", freq
);
3090 wpa_printf(MSG_DEBUG
, "P2P: Request to start GO on 5 GHz "
3092 if (wpa_s
->best_5_freq
> 0 &&
3093 p2p_supported_freq(wpa_s
->global
->p2p
,
3094 wpa_s
->best_5_freq
)) {
3095 freq
= wpa_s
->best_5_freq
;
3096 wpa_printf(MSG_DEBUG
, "P2P: Use best 5 GHz band "
3097 "channel: %d MHz", freq
);
3099 os_get_random((u8
*) &r
, sizeof(r
));
3100 freq
= 5180 + (r
% 4) * 20;
3101 if (!p2p_supported_freq(wpa_s
->global
->p2p
, freq
)) {
3102 wpa_printf(MSG_DEBUG
, "P2P: Could not select "
3103 "5 GHz channel for P2P group");
3106 wpa_printf(MSG_DEBUG
, "P2P: Use random 5 GHz band "
3107 "channel: %d MHz", freq
);
3111 if (freq
> 0 && !p2p_supported_freq(wpa_s
->global
->p2p
, freq
)) {
3112 wpa_printf(MSG_DEBUG
, "P2P: The forced channel for GO "
3113 "(%u MHz) is not supported for P2P uses",
3118 wpas_p2p_init_go_params(wpa_s
, ¶ms
, freq
);
3119 p2p_go_params(wpa_s
->global
->p2p
, ¶ms
);
3120 params
.persistent_group
= persistent_group
;
3122 wpa_s
= wpas_p2p_get_group_iface(wpa_s
, 0, 1);
3125 wpas_start_wps_go(wpa_s
, ¶ms
, 0);
3131 static int wpas_start_p2p_client(struct wpa_supplicant
*wpa_s
,
3132 struct wpa_ssid
*params
, int addr_allocated
)
3134 struct wpa_ssid
*ssid
;
3136 wpa_s
= wpas_p2p_get_group_iface(wpa_s
, addr_allocated
, 0);
3140 wpa_supplicant_ap_deinit(wpa_s
);
3142 ssid
= wpa_config_add_network(wpa_s
->conf
);
3145 wpas_notify_network_added(wpa_s
, ssid
);
3146 wpa_config_set_network_defaults(ssid
);
3147 ssid
->temporary
= 1;
3148 ssid
->proto
= WPA_PROTO_RSN
;
3149 ssid
->pairwise_cipher
= WPA_CIPHER_CCMP
;
3150 ssid
->group_cipher
= WPA_CIPHER_CCMP
;
3151 ssid
->key_mgmt
= WPA_KEY_MGMT_PSK
;
3152 ssid
->ssid
= os_malloc(params
->ssid_len
);
3153 if (ssid
->ssid
== NULL
) {
3154 wpas_notify_network_removed(wpa_s
, ssid
);
3155 wpa_config_remove_network(wpa_s
->conf
, ssid
->id
);
3158 os_memcpy(ssid
->ssid
, params
->ssid
, params
->ssid_len
);
3159 ssid
->ssid_len
= params
->ssid_len
;
3160 ssid
->p2p_group
= 1;
3161 if (params
->psk_set
) {
3162 os_memcpy(ssid
->psk
, params
->psk
, 32);
3165 if (params
->passphrase
)
3166 ssid
->passphrase
= os_strdup(params
->passphrase
);
3168 wpa_supplicant_select_network(wpa_s
, ssid
);
3170 wpa_s
->show_group_started
= 1;
3176 int wpas_p2p_group_add_persistent(struct wpa_supplicant
*wpa_s
,
3177 struct wpa_ssid
*ssid
, int addr_allocated
,
3180 struct p2p_go_neg_results params
;
3183 if (ssid
->disabled
!= 2 || ssid
->ssid
== NULL
)
3186 if (wpas_get_p2p_group(wpa_s
, ssid
->ssid
, ssid
->ssid_len
, &go
) &&
3187 go
== (ssid
->mode
== WPAS_MODE_P2P_GO
)) {
3188 wpa_printf(MSG_DEBUG
, "P2P: Requested persistent group is "
3193 /* Make sure we are not running find during connection establishment */
3194 wpas_p2p_stop_find(wpa_s
);
3196 if (ssid
->mode
== WPAS_MODE_INFRA
)
3197 return wpas_start_p2p_client(wpa_s
, ssid
, addr_allocated
);
3199 if (ssid
->mode
!= WPAS_MODE_P2P_GO
)
3202 wpas_p2p_init_go_params(wpa_s
, ¶ms
, freq
);
3205 if (ssid
->passphrase
== NULL
||
3206 os_strlen(ssid
->passphrase
) >= sizeof(params
.passphrase
)) {
3207 wpa_printf(MSG_DEBUG
, "P2P: Invalid passphrase in persistent "
3211 os_strlcpy(params
.passphrase
, ssid
->passphrase
,
3212 sizeof(params
.passphrase
));
3213 os_memcpy(params
.ssid
, ssid
->ssid
, ssid
->ssid_len
);
3214 params
.ssid_len
= ssid
->ssid_len
;
3215 params
.persistent_group
= 1;
3217 wpa_s
= wpas_p2p_get_group_iface(wpa_s
, addr_allocated
, 1);
3221 wpas_start_wps_go(wpa_s
, ¶ms
, 0);
3227 static void wpas_p2p_ie_update(void *ctx
, struct wpabuf
*beacon_ies
,
3228 struct wpabuf
*proberesp_ies
)
3230 struct wpa_supplicant
*wpa_s
= ctx
;
3231 if (wpa_s
->ap_iface
) {
3232 struct hostapd_data
*hapd
= wpa_s
->ap_iface
->bss
[0];
3234 wpabuf_free(hapd
->p2p_beacon_ie
);
3235 hapd
->p2p_beacon_ie
= beacon_ies
;
3237 wpabuf_free(hapd
->p2p_probe_resp_ie
);
3238 hapd
->p2p_probe_resp_ie
= proberesp_ies
;
3240 wpabuf_free(beacon_ies
);
3241 wpabuf_free(proberesp_ies
);
3243 wpa_supplicant_ap_update_beacon(wpa_s
);
3247 static void wpas_p2p_idle_update(void *ctx
, int idle
)
3249 struct wpa_supplicant
*wpa_s
= ctx
;
3250 if (!wpa_s
->ap_iface
)
3252 wpa_printf(MSG_DEBUG
, "P2P: GO - group %sidle", idle
? "" : "not ");
3254 wpas_p2p_set_group_idle_timeout(wpa_s
);
3256 eloop_cancel_timeout(wpas_p2p_group_idle_timeout
, wpa_s
, NULL
);
3260 struct p2p_group
* wpas_p2p_group_init(struct wpa_supplicant
*wpa_s
,
3261 int persistent_group
,
3262 int group_formation
)
3264 struct p2p_group
*group
;
3265 struct p2p_group_config
*cfg
;
3267 cfg
= os_zalloc(sizeof(*cfg
));
3271 cfg
->persistent_group
= persistent_group
;
3272 os_memcpy(cfg
->interface_addr
, wpa_s
->own_addr
, ETH_ALEN
);
3273 if (wpa_s
->max_stations
&&
3274 wpa_s
->max_stations
< wpa_s
->conf
->max_num_sta
)
3275 cfg
->max_clients
= wpa_s
->max_stations
;
3277 cfg
->max_clients
= wpa_s
->conf
->max_num_sta
;
3278 cfg
->cb_ctx
= wpa_s
;
3279 cfg
->ie_update
= wpas_p2p_ie_update
;
3280 cfg
->idle_update
= wpas_p2p_idle_update
;
3282 group
= p2p_group_init(wpa_s
->global
->p2p
, cfg
);
3285 if (!group_formation
)
3286 p2p_group_notif_formation_done(group
);
3287 wpa_s
->p2p_group
= group
;
3292 void wpas_p2p_wps_success(struct wpa_supplicant
*wpa_s
, const u8
*peer_addr
,
3295 if (!wpa_s
->p2p_in_provisioning
) {
3296 wpa_printf(MSG_DEBUG
, "P2P: Ignore WPS success event - P2P "
3297 "provisioning not in progress");
3301 eloop_cancel_timeout(wpas_p2p_group_formation_timeout
, wpa_s
->parent
,
3303 if (wpa_s
->global
->p2p
)
3304 p2p_wps_success_cb(wpa_s
->global
->p2p
, peer_addr
);
3305 wpas_group_formation_completed(wpa_s
, 1);
3309 int wpas_p2p_prov_disc(struct wpa_supplicant
*wpa_s
, const u8
*peer_addr
,
3310 const char *config_method
)
3314 if (os_strcmp(config_method
, "display") == 0)
3315 config_methods
= WPS_CONFIG_DISPLAY
;
3316 else if (os_strcmp(config_method
, "keypad") == 0)
3317 config_methods
= WPS_CONFIG_KEYPAD
;
3318 else if (os_strcmp(config_method
, "pbc") == 0 ||
3319 os_strcmp(config_method
, "pushbutton") == 0)
3320 config_methods
= WPS_CONFIG_PUSHBUTTON
;
3324 if (wpa_s
->global
->p2p
== NULL
)
3327 return p2p_prov_disc_req(wpa_s
->global
->p2p
, peer_addr
,
3332 int wpas_p2p_scan_result_text(const u8
*ies
, size_t ies_len
, char *buf
,
3335 return p2p_scan_result_text(ies
, ies_len
, buf
, end
);
3339 static void wpas_p2p_clear_pending_action_tx(struct wpa_supplicant
*wpa_s
)
3341 if (!wpa_s
->pending_action_tx
)
3344 wpa_printf(MSG_DEBUG
, "P2P: Drop pending Action TX due to new "
3345 "operation request");
3346 wpabuf_free(wpa_s
->pending_action_tx
);
3347 wpa_s
->pending_action_tx
= NULL
;
3351 int wpas_p2p_find(struct wpa_supplicant
*wpa_s
, unsigned int timeout
,
3352 enum p2p_discovery_type type
)
3354 wpas_p2p_clear_pending_action_tx(wpa_s
);
3355 wpa_s
->p2p_long_listen
= 0;
3357 return p2p_find(wpa_s
->global
->p2p
, timeout
, type
);
3361 void wpas_p2p_stop_find(struct wpa_supplicant
*wpa_s
)
3363 wpas_p2p_clear_pending_action_tx(wpa_s
);
3364 wpa_s
->p2p_long_listen
= 0;
3365 eloop_cancel_timeout(wpas_p2p_long_listen_timeout
, wpa_s
, NULL
);
3366 eloop_cancel_timeout(wpas_p2p_join_scan
, wpa_s
, NULL
);
3368 p2p_stop_find(wpa_s
->global
->p2p
);
3370 wpas_p2p_remove_pending_group_interface(wpa_s
);
3374 static void wpas_p2p_long_listen_timeout(void *eloop_ctx
, void *timeout_ctx
)
3376 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
3377 wpa_s
->p2p_long_listen
= 0;
3381 int wpas_p2p_listen(struct wpa_supplicant
*wpa_s
, unsigned int timeout
)
3385 wpas_p2p_clear_pending_action_tx(wpa_s
);
3389 * This is a request for unlimited Listen state. However, at
3390 * least for now, this is mapped to a Listen state for one
3395 eloop_cancel_timeout(wpas_p2p_long_listen_timeout
, wpa_s
, NULL
);
3396 wpa_s
->p2p_long_listen
= 0;
3398 res
= wpas_p2p_listen_start(wpa_s
, timeout
* 1000);
3399 if (res
== 0 && timeout
* 1000 > wpa_s
->max_remain_on_chan
) {
3400 wpa_s
->p2p_long_listen
= timeout
;
3401 eloop_register_timeout(timeout
, 0,
3402 wpas_p2p_long_listen_timeout
,
3410 int wpas_p2p_assoc_req_ie(struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
,
3411 u8
*buf
, size_t len
, int p2p_group
)
3413 struct wpabuf
*p2p_ie
;
3416 if (wpa_s
->global
->p2p_disabled
)
3418 if (wpa_s
->global
->p2p
== NULL
)
3423 p2p_ie
= wpa_bss_get_vendor_ie_multi(bss
, P2P_IE_VENDOR_TYPE
);
3424 ret
= p2p_assoc_req_ie(wpa_s
->global
->p2p
, bss
->bssid
, buf
, len
,
3426 wpabuf_free(p2p_ie
);
3432 int wpas_p2p_probe_req_rx(struct wpa_supplicant
*wpa_s
, const u8
*addr
,
3433 const u8
*ie
, size_t ie_len
)
3435 if (wpa_s
->global
->p2p_disabled
)
3437 if (wpa_s
->global
->p2p
== NULL
)
3440 return p2p_probe_req_rx(wpa_s
->global
->p2p
, addr
, ie
, ie_len
);
3444 void wpas_p2p_rx_action(struct wpa_supplicant
*wpa_s
, const u8
*da
,
3445 const u8
*sa
, const u8
*bssid
,
3446 u8 category
, const u8
*data
, size_t len
, int freq
)
3448 if (wpa_s
->global
->p2p_disabled
)
3450 if (wpa_s
->global
->p2p
== NULL
)
3453 p2p_rx_action(wpa_s
->global
->p2p
, da
, sa
, bssid
, category
, data
, len
,
3458 void wpas_p2p_scan_ie(struct wpa_supplicant
*wpa_s
, struct wpabuf
*ies
)
3460 if (wpa_s
->global
->p2p_disabled
)
3462 if (wpa_s
->global
->p2p
== NULL
)
3465 p2p_scan_ie(wpa_s
->global
->p2p
, ies
);
3469 void wpas_p2p_group_deinit(struct wpa_supplicant
*wpa_s
)
3471 p2p_group_deinit(wpa_s
->p2p_group
);
3472 wpa_s
->p2p_group
= NULL
;
3476 int wpas_p2p_reject(struct wpa_supplicant
*wpa_s
, const u8
*addr
)
3478 wpa_s
->p2p_long_listen
= 0;
3480 return p2p_reject(wpa_s
->global
->p2p
, addr
);
3484 /* Invite to reinvoke a persistent group */
3485 int wpas_p2p_invite(struct wpa_supplicant
*wpa_s
, const u8
*peer_addr
,
3486 struct wpa_ssid
*ssid
, const u8
*go_dev_addr
)
3488 enum p2p_invite_role role
;
3491 if (ssid
->mode
== WPAS_MODE_P2P_GO
) {
3492 role
= P2P_INVITE_ROLE_GO
;
3493 if (peer_addr
== NULL
) {
3494 wpa_printf(MSG_DEBUG
, "P2P: Missing peer "
3495 "address in invitation command");
3498 if (wpas_p2p_create_iface(wpa_s
)) {
3499 if (wpas_p2p_add_group_interface(wpa_s
,
3500 WPA_IF_P2P_GO
) < 0) {
3501 wpa_printf(MSG_ERROR
, "P2P: Failed to "
3502 "allocate a new interface for the "
3506 bssid
= wpa_s
->pending_interface_addr
;
3508 bssid
= wpa_s
->own_addr
;
3510 role
= P2P_INVITE_ROLE_CLIENT
;
3511 peer_addr
= ssid
->bssid
;
3513 wpa_s
->pending_invite_ssid_id
= ssid
->id
;
3515 return p2p_invite(wpa_s
->global
->p2p
, peer_addr
, role
, bssid
,
3516 ssid
->ssid
, ssid
->ssid_len
, 0, go_dev_addr
, 1);
3520 /* Invite to join an active group */
3521 int wpas_p2p_invite_group(struct wpa_supplicant
*wpa_s
, const char *ifname
,
3522 const u8
*peer_addr
, const u8
*go_dev_addr
)
3524 struct wpa_global
*global
= wpa_s
->global
;
3525 enum p2p_invite_role role
;
3527 struct wpa_ssid
*ssid
;
3529 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
3530 if (os_strcmp(wpa_s
->ifname
, ifname
) == 0)
3533 if (wpa_s
== NULL
) {
3534 wpa_printf(MSG_DEBUG
, "P2P: Interface '%s' not found", ifname
);
3538 ssid
= wpa_s
->current_ssid
;
3540 wpa_printf(MSG_DEBUG
, "P2P: No current SSID to use for "
3545 if (ssid
->mode
== WPAS_MODE_P2P_GO
) {
3546 role
= P2P_INVITE_ROLE_ACTIVE_GO
;
3547 bssid
= wpa_s
->own_addr
;
3548 if (go_dev_addr
== NULL
)
3549 go_dev_addr
= wpa_s
->parent
->own_addr
;
3551 role
= P2P_INVITE_ROLE_CLIENT
;
3552 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
) {
3553 wpa_printf(MSG_DEBUG
, "P2P: Not associated - cannot "
3554 "invite to current group");
3557 bssid
= wpa_s
->bssid
;
3558 if (go_dev_addr
== NULL
&&
3559 !is_zero_ether_addr(wpa_s
->go_dev_addr
))
3560 go_dev_addr
= wpa_s
->go_dev_addr
;
3562 wpa_s
->parent
->pending_invite_ssid_id
= -1;
3564 return p2p_invite(wpa_s
->global
->p2p
, peer_addr
, role
, bssid
,
3565 ssid
->ssid
, ssid
->ssid_len
, wpa_s
->assoc_freq
,
3570 void wpas_p2p_completed(struct wpa_supplicant
*wpa_s
)
3572 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
3573 const char *ssid_txt
;
3574 u8 go_dev_addr
[ETH_ALEN
];
3577 if (!wpa_s
->show_group_started
|| !ssid
)
3580 wpa_s
->show_group_started
= 0;
3582 ssid_txt
= wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
);
3583 os_memset(go_dev_addr
, 0, ETH_ALEN
);
3584 if (ssid
->bssid_set
)
3585 os_memcpy(go_dev_addr
, ssid
->bssid
, ETH_ALEN
);
3586 persistent
= wpas_p2p_persistent_group(wpa_s
, go_dev_addr
, ssid
->ssid
,
3588 os_memcpy(wpa_s
->go_dev_addr
, go_dev_addr
, ETH_ALEN
);
3590 if (wpa_s
->global
->p2p_group_formation
== wpa_s
)
3591 wpa_s
->global
->p2p_group_formation
= NULL
;
3593 if (ssid
->passphrase
== NULL
&& ssid
->psk_set
) {
3595 wpa_snprintf_hex(psk
, sizeof(psk
), ssid
->psk
, 32);
3596 wpa_msg(wpa_s
->parent
, MSG_INFO
, P2P_EVENT_GROUP_STARTED
3597 "%s client ssid=\"%s\" freq=%d psk=%s go_dev_addr="
3599 wpa_s
->ifname
, ssid_txt
, ssid
->frequency
, psk
,
3600 MAC2STR(go_dev_addr
),
3601 persistent
? " [PERSISTENT]" : "");
3603 wpa_msg(wpa_s
->parent
, MSG_INFO
, P2P_EVENT_GROUP_STARTED
3604 "%s client ssid=\"%s\" freq=%d passphrase=\"%s\" "
3605 "go_dev_addr=" MACSTR
"%s",
3606 wpa_s
->ifname
, ssid_txt
, ssid
->frequency
,
3607 ssid
->passphrase
? ssid
->passphrase
: "",
3608 MAC2STR(go_dev_addr
),
3609 persistent
? " [PERSISTENT]" : "");
3613 wpas_p2p_store_persistent_group(wpa_s
->parent
, ssid
,
3618 int wpas_p2p_presence_req(struct wpa_supplicant
*wpa_s
, u32 duration1
,
3619 u32 interval1
, u32 duration2
, u32 interval2
)
3621 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
||
3622 wpa_s
->current_ssid
== NULL
||
3623 wpa_s
->current_ssid
->mode
!= WPAS_MODE_INFRA
)
3626 return p2p_presence_req(wpa_s
->global
->p2p
, wpa_s
->bssid
,
3627 wpa_s
->own_addr
, wpa_s
->assoc_freq
,
3628 duration1
, interval1
, duration2
, interval2
);
3632 int wpas_p2p_ext_listen(struct wpa_supplicant
*wpa_s
, unsigned int period
,
3633 unsigned int interval
)
3635 return p2p_ext_listen(wpa_s
->global
->p2p
, period
, interval
);
3639 static void wpas_p2p_group_idle_timeout(void *eloop_ctx
, void *timeout_ctx
)
3641 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
3643 if (wpa_s
->conf
->p2p_group_idle
== 0) {
3644 wpa_printf(MSG_DEBUG
, "P2P: Ignore group idle timeout - "
3649 wpa_printf(MSG_DEBUG
, "P2P: Group idle timeout reached - terminate "
3651 wpa_s
->removal_reason
= P2P_GROUP_REMOVAL_IDLE_TIMEOUT
;
3652 wpas_p2p_group_delete(wpa_s
);
3656 static void wpas_p2p_set_group_idle_timeout(struct wpa_supplicant
*wpa_s
)
3658 eloop_cancel_timeout(wpas_p2p_group_idle_timeout
, wpa_s
, NULL
);
3659 if (wpa_s
->conf
->p2p_group_idle
== 0)
3662 if (wpa_s
->current_ssid
== NULL
|| !wpa_s
->current_ssid
->p2p_group
)
3665 wpa_printf(MSG_DEBUG
, "P2P: Set P2P group idle timeout to %u seconds",
3666 wpa_s
->conf
->p2p_group_idle
);
3667 eloop_register_timeout(wpa_s
->conf
->p2p_group_idle
, 0,
3668 wpas_p2p_group_idle_timeout
, wpa_s
, NULL
);
3672 void wpas_p2p_deauth_notif(struct wpa_supplicant
*wpa_s
, const u8
*bssid
,
3673 u16 reason_code
, const u8
*ie
, size_t ie_len
)
3675 if (wpa_s
->global
->p2p_disabled
)
3678 p2p_deauth_notif(wpa_s
->global
->p2p
, bssid
, reason_code
, ie
, ie_len
);
3682 void wpas_p2p_disassoc_notif(struct wpa_supplicant
*wpa_s
, const u8
*bssid
,
3683 u16 reason_code
, const u8
*ie
, size_t ie_len
)
3685 if (wpa_s
->global
->p2p_disabled
)
3688 p2p_disassoc_notif(wpa_s
->global
->p2p
, bssid
, reason_code
, ie
, ie_len
);
3692 void wpas_p2p_update_config(struct wpa_supplicant
*wpa_s
)
3694 struct p2p_data
*p2p
= wpa_s
->global
->p2p
;
3699 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_CAPABLE
))
3702 if (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_DEVICE_NAME
)
3703 p2p_set_dev_name(p2p
, wpa_s
->conf
->device_name
);
3705 if (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_DEVICE_TYPE
) {
3707 if (wpa_s
->conf
->device_type
) {
3708 if (wps_dev_type_str2bin(wpa_s
->conf
->device_type
,
3709 pri_dev_type
) < 0) {
3710 wpa_printf(MSG_ERROR
, "P2P: Invalid "
3713 p2p_set_pri_dev_type(p2p
, pri_dev_type
);
3717 if (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_SEC_DEVICE_TYPE
) {
3718 u8 sec_dev_type
[P2P_SEC_DEVICE_TYPES
][8];
3721 for (i
= 0; i
< MAX_SEC_DEVICE_TYPES
; i
++) {
3722 if (wpa_s
->conf
->sec_device_type
[i
] == NULL
)
3724 if (wps_dev_type_str2bin(
3725 wpa_s
->conf
->sec_device_type
[i
],
3726 sec_dev_type
[num
]) < 0) {
3727 wpa_printf(MSG_ERROR
, "P2P: Invalid "
3732 if (num
== P2P_SEC_DEVICE_TYPES
)
3735 p2p_set_sec_dev_types(p2p
, (void *) sec_dev_type
, num
);
3738 if ((wpa_s
->conf
->changed_parameters
& CFG_CHANGED_COUNTRY
) &&
3739 wpa_s
->conf
->country
[0] && wpa_s
->conf
->country
[1]) {
3741 country
[0] = wpa_s
->conf
->country
[0];
3742 country
[1] = wpa_s
->conf
->country
[1];
3744 p2p_set_country(p2p
, country
);
3747 if (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_P2P_SSID_POSTFIX
) {
3748 p2p_set_ssid_postfix(p2p
, (u8
*) wpa_s
->conf
->p2p_ssid_postfix
,
3749 wpa_s
->conf
->p2p_ssid_postfix
?
3750 os_strlen(wpa_s
->conf
->p2p_ssid_postfix
) :
3754 if (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_P2P_INTRA_BSS
)
3755 p2p_set_intra_bss_dist(p2p
, wpa_s
->conf
->p2p_intra_bss
);
3759 int wpas_p2p_set_noa(struct wpa_supplicant
*wpa_s
, u8 count
, int start
,
3762 if (!wpa_s
->ap_iface
)
3764 return hostapd_p2p_set_noa(wpa_s
->ap_iface
->bss
[0], count
, start
,
3769 int wpas_p2p_set_cross_connect(struct wpa_supplicant
*wpa_s
, int enabled
)
3771 if (wpa_s
->global
->p2p_disabled
)
3773 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
)
3776 wpa_s
->global
->cross_connection
= enabled
;
3777 p2p_set_cross_connect(wpa_s
->global
->p2p
, enabled
);
3780 struct wpa_supplicant
*iface
;
3782 for (iface
= wpa_s
->global
->ifaces
; iface
; iface
= iface
->next
)
3784 if (iface
->cross_connect_enabled
== 0)
3787 iface
->cross_connect_enabled
= 0;
3788 iface
->cross_connect_in_use
= 0;
3789 wpa_msg(iface
->parent
, MSG_INFO
,
3790 P2P_EVENT_CROSS_CONNECT_DISABLE
"%s %s",
3791 iface
->ifname
, iface
->cross_connect_uplink
);
3799 static void wpas_p2p_enable_cross_connect(struct wpa_supplicant
*uplink
)
3801 struct wpa_supplicant
*iface
;
3803 if (!uplink
->global
->cross_connection
)
3806 for (iface
= uplink
->global
->ifaces
; iface
; iface
= iface
->next
) {
3807 if (!iface
->cross_connect_enabled
)
3809 if (os_strcmp(uplink
->ifname
, iface
->cross_connect_uplink
) !=
3812 if (iface
->ap_iface
== NULL
)
3814 if (iface
->cross_connect_in_use
)
3817 iface
->cross_connect_in_use
= 1;
3818 wpa_msg(iface
->parent
, MSG_INFO
,
3819 P2P_EVENT_CROSS_CONNECT_ENABLE
"%s %s",
3820 iface
->ifname
, iface
->cross_connect_uplink
);
3825 static void wpas_p2p_disable_cross_connect(struct wpa_supplicant
*uplink
)
3827 struct wpa_supplicant
*iface
;
3829 for (iface
= uplink
->global
->ifaces
; iface
; iface
= iface
->next
) {
3830 if (!iface
->cross_connect_enabled
)
3832 if (os_strcmp(uplink
->ifname
, iface
->cross_connect_uplink
) !=
3835 if (!iface
->cross_connect_in_use
)
3838 wpa_msg(iface
->parent
, MSG_INFO
,
3839 P2P_EVENT_CROSS_CONNECT_DISABLE
"%s %s",
3840 iface
->ifname
, iface
->cross_connect_uplink
);
3841 iface
->cross_connect_in_use
= 0;
3846 void wpas_p2p_notif_connected(struct wpa_supplicant
*wpa_s
)
3848 if (wpa_s
->ap_iface
|| wpa_s
->current_ssid
== NULL
||
3849 wpa_s
->current_ssid
->mode
!= WPAS_MODE_INFRA
||
3850 wpa_s
->cross_connect_disallowed
)
3851 wpas_p2p_disable_cross_connect(wpa_s
);
3853 wpas_p2p_enable_cross_connect(wpa_s
);
3854 if (!wpa_s
->ap_iface
)
3855 eloop_cancel_timeout(wpas_p2p_group_idle_timeout
, wpa_s
, NULL
);
3859 void wpas_p2p_notif_disconnected(struct wpa_supplicant
*wpa_s
)
3861 wpas_p2p_disable_cross_connect(wpa_s
);
3862 if (!wpa_s
->ap_iface
)
3863 wpas_p2p_set_group_idle_timeout(wpa_s
);
3867 static void wpas_p2p_cross_connect_setup(struct wpa_supplicant
*wpa_s
)
3869 struct wpa_supplicant
*iface
;
3871 if (!wpa_s
->global
->cross_connection
)
3874 for (iface
= wpa_s
->global
->ifaces
; iface
; iface
= iface
->next
) {
3877 if (iface
->drv_flags
&
3878 WPA_DRIVER_FLAGS_P2P_DEDICATED_INTERFACE
)
3880 if (iface
->drv_flags
& WPA_DRIVER_FLAGS_P2P_CAPABLE
)
3883 wpa_s
->cross_connect_enabled
= 1;
3884 os_strlcpy(wpa_s
->cross_connect_uplink
, iface
->ifname
,
3885 sizeof(wpa_s
->cross_connect_uplink
));
3886 wpa_printf(MSG_DEBUG
, "P2P: Enable cross connection from "
3887 "%s to %s whenever uplink is available",
3888 wpa_s
->ifname
, wpa_s
->cross_connect_uplink
);
3890 if (iface
->ap_iface
|| iface
->current_ssid
== NULL
||
3891 iface
->current_ssid
->mode
!= WPAS_MODE_INFRA
||
3892 iface
->cross_connect_disallowed
||
3893 iface
->wpa_state
!= WPA_COMPLETED
)
3896 wpa_s
->cross_connect_in_use
= 1;
3897 wpa_msg(wpa_s
->parent
, MSG_INFO
,
3898 P2P_EVENT_CROSS_CONNECT_ENABLE
"%s %s",
3899 wpa_s
->ifname
, wpa_s
->cross_connect_uplink
);
3905 int wpas_p2p_notif_pbc_overlap(struct wpa_supplicant
*wpa_s
)
3907 if (wpa_s
->p2p_group_interface
!= P2P_GROUP_INTERFACE_CLIENT
&&
3908 !wpa_s
->p2p_in_provisioning
)
3909 return 0; /* not P2P client operation */
3911 wpa_printf(MSG_DEBUG
, "P2P: Terminate connection due to WPS PBC "
3913 if (wpa_s
!= wpa_s
->parent
)
3914 wpa_msg_ctrl(wpa_s
->parent
, MSG_INFO
, WPS_EVENT_OVERLAP
);
3915 wpas_group_formation_completed(wpa_s
, 0);
3920 void wpas_p2p_update_channel_list(struct wpa_supplicant
*wpa_s
)
3922 struct p2p_channels chan
;
3924 if (wpa_s
->global
== NULL
|| wpa_s
->global
->p2p
== NULL
)
3927 os_memset(&chan
, 0, sizeof(chan
));
3928 if (wpas_p2p_setup_channels(wpa_s
, &chan
)) {
3929 wpa_printf(MSG_ERROR
, "P2P: Failed to update supported "
3934 p2p_update_channel_list(wpa_s
->global
->p2p
, &chan
);
3938 int wpas_p2p_cancel(struct wpa_supplicant
*wpa_s
)
3940 struct wpa_global
*global
= wpa_s
->global
;
3943 wpa_printf(MSG_DEBUG
, "P2P: Request to cancel group formation");
3945 if (wpa_s
->pending_interface_name
[0] &&
3946 !is_zero_ether_addr(wpa_s
->pending_interface_addr
))
3949 wpas_p2p_stop_find(wpa_s
);
3951 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
3952 if (wpa_s
== global
->p2p_group_formation
&&
3953 (wpa_s
->p2p_in_provisioning
||
3954 wpa_s
->parent
->pending_interface_type
==
3955 WPA_IF_P2P_CLIENT
)) {
3956 wpa_printf(MSG_DEBUG
, "P2P: Interface %s in group "
3957 "formation found - cancelling",
3960 wpas_p2p_group_delete(wpa_s
);
3966 wpa_printf(MSG_DEBUG
, "P2P: No ongoing group formation found");
3974 void wpas_p2p_interface_unavailable(struct wpa_supplicant
*wpa_s
)
3976 if (wpa_s
->current_ssid
== NULL
|| !wpa_s
->current_ssid
->p2p_group
)
3979 wpa_printf(MSG_DEBUG
, "P2P: Remove group due to driver resource not "
3980 "being available anymore");
3981 wpa_s
->removal_reason
= P2P_GROUP_REMOVAL_UNAVAILABLE
;
3982 wpas_p2p_group_delete(wpa_s
);
3986 void wpas_p2p_update_best_channels(struct wpa_supplicant
*wpa_s
,
3987 int freq_24
, int freq_5
, int freq_overall
)
3989 struct p2p_data
*p2p
= wpa_s
->global
->p2p
;
3990 if (p2p
== NULL
|| (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
))
3992 p2p_set_best_channels(p2p
, freq_24
, freq_5
, freq_overall
);
3996 int wpas_p2p_unauthorize(struct wpa_supplicant
*wpa_s
, const char *addr
)
3999 struct p2p_data
*p2p
= wpa_s
->global
->p2p
;
4001 if (p2p
== NULL
|| (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
))
4004 if (hwaddr_aton(addr
, peer
))
4007 return p2p_unauthorize(p2p
, peer
);