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"
39 static void wpas_p2p_long_listen_timeout(void *eloop_ctx
, void *timeout_ctx
);
40 static struct wpa_supplicant
*
41 wpas_p2p_get_group_iface(struct wpa_supplicant
*wpa_s
, int addr_allocated
,
43 static int wpas_p2p_join_start(struct wpa_supplicant
*wpa_s
);
44 static void wpas_p2p_join_scan(void *eloop_ctx
, void *timeout_ctx
);
45 static int wpas_p2p_join(struct wpa_supplicant
*wpa_s
, const u8
*iface_addr
,
46 const u8
*dev_addr
, enum p2p_wps_method wps_method
);
47 static int wpas_p2p_create_iface(struct wpa_supplicant
*wpa_s
);
48 static void wpas_p2p_cross_connect_setup(struct wpa_supplicant
*wpa_s
);
51 static void wpas_p2p_scan_res_handler(struct wpa_supplicant
*wpa_s
,
52 struct wpa_scan_results
*scan_res
)
56 if (wpa_s
->global
->p2p_disabled
)
59 wpa_printf(MSG_DEBUG
, "P2P: Scan results received (%d BSS)",
62 for (i
= 0; i
< scan_res
->num
; i
++) {
63 struct wpa_scan_res
*bss
= scan_res
->res
[i
];
64 if (p2p_scan_res_handler(wpa_s
->global
->p2p
, bss
->bssid
,
65 bss
->freq
, bss
->level
,
66 (const u8
*) (bss
+ 1),
71 p2p_scan_res_handled(wpa_s
->global
->p2p
);
75 static int wpas_p2p_scan(void *ctx
, enum p2p_scan_type type
, int freq
)
77 struct wpa_supplicant
*wpa_s
= ctx
;
78 struct wpa_driver_scan_params params
;
80 struct wpabuf
*wps_ie
, *ies
;
81 int social_channels
[] = { 2412, 2437, 2462, 0, 0 };
83 os_memset(¶ms
, 0, sizeof(params
));
85 /* P2P Wildcard SSID */
87 params
.ssids
[0].ssid
= (u8
*) P2P_WILDCARD_SSID
;
88 params
.ssids
[0].ssid_len
= P2P_WILDCARD_SSID_LEN
;
90 wpa_s
->wps
->dev
.p2p
= 1;
91 wps_ie
= wps_build_probe_req_ie(0, &wpa_s
->wps
->dev
, wpa_s
->wps
->uuid
,
96 ies
= wpabuf_alloc(wpabuf_len(wps_ie
) + 100);
101 wpabuf_put_buf(ies
, wps_ie
);
104 p2p_scan_ie(wpa_s
->global
->p2p
, ies
);
106 params
.extra_ies
= wpabuf_head(ies
);
107 params
.extra_ies_len
= wpabuf_len(ies
);
110 case P2P_SCAN_SOCIAL
:
111 params
.freqs
= social_channels
;
115 case P2P_SCAN_SPECIFIC
:
116 social_channels
[0] = freq
;
117 social_channels
[1] = 0;
118 params
.freqs
= social_channels
;
120 case P2P_SCAN_SOCIAL_PLUS_ONE
:
121 social_channels
[3] = freq
;
122 params
.freqs
= social_channels
;
126 wpa_s
->scan_res_handler
= wpas_p2p_scan_res_handler
;
127 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_USER_SPACE_MLME
)
128 ret
= ieee80211_sta_req_scan(wpa_s
, ¶ms
);
130 ret
= wpa_drv_scan(wpa_s
, ¶ms
);
138 #ifdef CONFIG_CLIENT_MLME
139 static void p2p_rx_action_mlme(void *ctx
, const u8
*buf
, size_t len
, int freq
)
141 struct wpa_supplicant
*wpa_s
= ctx
;
142 const struct ieee80211_mgmt
*mgmt
;
145 if (wpa_s
->global
->p2p_disabled
)
147 mgmt
= (const struct ieee80211_mgmt
*) buf
;
148 hdr_len
= (const u8
*) &mgmt
->u
.action
.u
.vs_public_action
.action
- buf
;
151 p2p_rx_action(wpa_s
->global
->p2p
, mgmt
->da
, mgmt
->sa
, mgmt
->bssid
,
152 mgmt
->u
.action
.category
,
153 &mgmt
->u
.action
.u
.vs_public_action
.action
,
154 len
- hdr_len
, freq
);
156 #endif /* CONFIG_CLIENT_MLME */
159 static enum wpa_driver_if_type
wpas_p2p_if_type(int p2p_group_interface
)
161 switch (p2p_group_interface
) {
162 case P2P_GROUP_INTERFACE_PENDING
:
163 return WPA_IF_P2P_GROUP
;
164 case P2P_GROUP_INTERFACE_GO
:
165 return WPA_IF_P2P_GO
;
166 case P2P_GROUP_INTERFACE_CLIENT
:
167 return WPA_IF_P2P_CLIENT
;
170 return WPA_IF_P2P_GROUP
;
174 static void wpas_p2p_group_delete(struct wpa_supplicant
*wpa_s
)
176 struct wpa_ssid
*ssid
;
179 ssid
= wpa_s
->current_ssid
;
182 * The current SSID was not known, but there may still be a
183 * pending P2P group interface waiting for provisioning.
185 ssid
= wpa_s
->conf
->ssid
;
187 if (ssid
->p2p_group
&&
188 (ssid
->mode
== WPAS_MODE_P2P_GROUP_FORMATION
||
189 (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
)))
194 if (wpa_s
->p2p_group_interface
== P2P_GROUP_INTERFACE_GO
)
196 else if (wpa_s
->p2p_group_interface
== P2P_GROUP_INTERFACE_CLIENT
||
197 (ssid
&& ssid
->mode
== WPAS_MODE_INFRA
)) {
198 wpa_s
->reassociate
= 0;
199 wpa_s
->disconnected
= 1;
200 wpa_supplicant_deauthenticate(wpa_s
,
201 WLAN_REASON_DEAUTH_LEAVING
);
205 if (wpa_s
->cross_connect_in_use
) {
206 wpa_s
->cross_connect_in_use
= 0;
207 wpa_msg(wpa_s
->parent
, MSG_INFO
,
208 P2P_EVENT_CROSS_CONNECT_DISABLE
"%s %s",
209 wpa_s
->ifname
, wpa_s
->cross_connect_uplink
);
211 wpa_msg(wpa_s
->parent
, MSG_INFO
, P2P_EVENT_GROUP_REMOVED
"%s %s",
212 wpa_s
->ifname
, gtype
);
213 if (wpa_s
->p2p_group_interface
!= NOT_P2P_GROUP_INTERFACE
) {
214 struct wpa_global
*global
;
216 enum wpa_driver_if_type type
;
217 wpa_printf(MSG_DEBUG
, "P2P: Remove group interface %s",
219 global
= wpa_s
->global
;
220 ifname
= os_strdup(wpa_s
->ifname
);
221 type
= wpas_p2p_if_type(wpa_s
->p2p_group_interface
);
222 wpa_supplicant_remove_iface(wpa_s
->global
, wpa_s
);
223 wpa_s
= global
->ifaces
;
225 wpa_drv_if_remove(wpa_s
, type
, ifname
);
230 wpa_printf(MSG_DEBUG
, "P2P: Remove temporary group network");
231 if (ssid
&& (ssid
->p2p_group
||
232 ssid
->mode
== WPAS_MODE_P2P_GROUP_FORMATION
||
233 (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
))) {
235 if (ssid
== wpa_s
->current_ssid
)
236 wpa_s
->current_ssid
= NULL
;
237 wpas_notify_network_removed(wpa_s
, ssid
);
238 wpa_config_remove_network(wpa_s
->conf
, id
);
239 wpa_supplicant_clear_status(wpa_s
);
241 wpa_printf(MSG_DEBUG
, "P2P: Temporary group network not "
244 wpa_supplicant_ap_deinit(wpa_s
);
248 static int wpas_p2p_persistent_group(struct wpa_supplicant
*wpa_s
,
250 const u8
*ssid
, size_t ssid_len
)
258 if (wpa_s
->go_params
)
259 bssid
= wpa_s
->go_params
->peer_interface_addr
;
261 bssid
= wpa_s
->bssid
;
263 bss
= wpa_bss_get(wpa_s
, bssid
, ssid
, ssid_len
);
265 u8 iface_addr
[ETH_ALEN
];
266 if (p2p_get_interface_addr(wpa_s
->global
->p2p
, bssid
,
268 bss
= wpa_bss_get(wpa_s
, iface_addr
, ssid
, ssid_len
);
271 wpa_printf(MSG_DEBUG
, "P2P: Could not figure out whether "
272 "group is persistent - BSS " MACSTR
" not found",
277 p2p
= wpa_bss_get_vendor_ie_multi(bss
, P2P_IE_VENDOR_TYPE
);
279 wpa_printf(MSG_DEBUG
, "P2P: Could not figure out whether "
280 "group is persistent - BSS " MACSTR
281 " did not include P2P IE", MAC2STR(bssid
));
282 wpa_hexdump(MSG_DEBUG
, "P2P: Probe Response IEs",
283 (u8
*) (bss
+ 1), bss
->ie_len
);
284 wpa_hexdump(MSG_DEBUG
, "P2P: Beacon IEs",
285 ((u8
*) bss
+ 1) + bss
->ie_len
,
290 group_capab
= p2p_get_group_capab(p2p
);
291 addr
= p2p_get_go_dev_addr(p2p
);
292 wpa_printf(MSG_DEBUG
, "P2P: Checking whether group is persistent: "
293 "group_capab=0x%x", group_capab
);
295 os_memcpy(go_dev_addr
, addr
, ETH_ALEN
);
296 wpa_printf(MSG_DEBUG
, "P2P: GO Device Address " MACSTR
,
299 os_memset(go_dev_addr
, 0, ETH_ALEN
);
302 wpa_printf(MSG_DEBUG
, "P2P: BSS " MACSTR
" group_capab=0x%x "
303 "go_dev_addr=" MACSTR
,
304 MAC2STR(bssid
), group_capab
, MAC2STR(go_dev_addr
));
306 return group_capab
& P2P_GROUP_CAPAB_PERSISTENT_GROUP
;
310 static void wpas_p2p_store_persistent_group(struct wpa_supplicant
*wpa_s
,
311 struct wpa_ssid
*ssid
,
312 const u8
*go_dev_addr
)
317 wpa_printf(MSG_DEBUG
, "P2P: Storing credentials for a persistent "
318 "group (GO Dev Addr " MACSTR
")", MAC2STR(go_dev_addr
));
319 for (s
= wpa_s
->conf
->ssid
; s
; s
= s
->next
) {
320 if (s
->disabled
== 2 &&
321 os_memcmp(go_dev_addr
, s
->bssid
, ETH_ALEN
) == 0 &&
322 s
->ssid_len
== ssid
->ssid_len
&&
323 os_memcmp(ssid
->ssid
, s
->ssid
, ssid
->ssid_len
) == 0)
328 wpa_printf(MSG_DEBUG
, "P2P: Update existing persistent group "
330 if (ssid
->passphrase
&& !s
->passphrase
)
332 else if (ssid
->passphrase
&& s
->passphrase
&&
333 os_strcmp(ssid
->passphrase
, s
->passphrase
) != 0)
336 wpa_printf(MSG_DEBUG
, "P2P: Create a new persistent group "
339 s
= wpa_config_add_network(wpa_s
->conf
);
342 wpa_config_set_network_defaults(s
);
346 s
->p2p_persistent_group
= 1;
349 os_memcpy(s
->bssid
, go_dev_addr
, ETH_ALEN
);
350 s
->mode
= ssid
->mode
;
351 s
->auth_alg
= WPA_AUTH_ALG_OPEN
;
352 s
->key_mgmt
= WPA_KEY_MGMT_PSK
;
353 s
->proto
= WPA_PROTO_RSN
;
354 s
->pairwise_cipher
= WPA_CIPHER_CCMP
;
355 if (ssid
->passphrase
) {
356 os_free(s
->passphrase
);
357 s
->passphrase
= os_strdup(ssid
->passphrase
);
361 os_memcpy(s
->psk
, ssid
->psk
, 32);
363 if (s
->passphrase
&& !s
->psk_set
)
364 wpa_config_update_psk(s
);
365 if (s
->ssid
== NULL
|| s
->ssid_len
< ssid
->ssid_len
) {
367 s
->ssid
= os_malloc(ssid
->ssid_len
);
370 s
->ssid_len
= ssid
->ssid_len
;
371 os_memcpy(s
->ssid
, ssid
->ssid
, s
->ssid_len
);
374 #ifndef CONFIG_NO_CONFIG_WRITE
375 if (changed
&& wpa_s
->conf
->update_config
&&
376 wpa_config_write(wpa_s
->confname
, wpa_s
->conf
)) {
377 wpa_printf(MSG_DEBUG
, "P2P: Failed to update configuration");
379 #endif /* CONFIG_NO_CONFIG_WRITE */
383 static void wpas_group_formation_completed(struct wpa_supplicant
*wpa_s
,
386 struct wpa_ssid
*ssid
;
387 const char *ssid_txt
;
390 u8 go_dev_addr
[ETH_ALEN
];
393 * This callback is likely called for the main interface. Update wpa_s
394 * to use the group interface if a new interface was created for the
397 if (wpa_s
->global
->p2p_group_formation
)
398 wpa_s
= wpa_s
->global
->p2p_group_formation
;
399 wpa_s
->p2p_in_provisioning
= 0;
402 wpa_msg(wpa_s
->parent
, MSG_INFO
,
403 P2P_EVENT_GROUP_FORMATION_FAILURE
);
404 wpas_p2p_group_delete(wpa_s
);
408 wpa_msg(wpa_s
->parent
, MSG_INFO
, P2P_EVENT_GROUP_FORMATION_SUCCESS
);
410 ssid
= wpa_s
->current_ssid
;
411 if (ssid
&& ssid
->mode
== WPAS_MODE_P2P_GROUP_FORMATION
) {
412 ssid
->mode
= WPAS_MODE_P2P_GO
;
413 p2p_group_notif_formation_done(wpa_s
->p2p_group
);
414 wpa_supplicant_ap_mac_addr_filter(wpa_s
, NULL
);
419 ssid_txt
= wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
);
420 client
= ssid
->mode
== WPAS_MODE_INFRA
;
421 if (ssid
->mode
== WPAS_MODE_P2P_GO
) {
422 persistent
= ssid
->p2p_persistent_group
;
423 os_memcpy(go_dev_addr
, wpa_s
->parent
->own_addr
,
426 persistent
= wpas_p2p_persistent_group(wpa_s
,
432 client
= wpa_s
->p2p_group_interface
==
433 P2P_GROUP_INTERFACE_CLIENT
;
436 wpa_s
->show_group_started
= 0;
439 * Indicate event only after successfully completed 4-way
440 * handshake, i.e., when the interface is ready for data
443 wpa_s
->show_group_started
= 1;
444 } else if (ssid
&& ssid
->passphrase
== NULL
&& ssid
->psk_set
) {
446 wpa_snprintf_hex(psk
, sizeof(psk
), ssid
->psk
, 32);
447 wpa_msg(wpa_s
->parent
, MSG_INFO
, P2P_EVENT_GROUP_STARTED
448 "%s GO ssid=\"%s\" freq=%d psk=%s go_dev_addr=" MACSTR
450 wpa_s
->ifname
, ssid_txt
, ssid
->frequency
, psk
,
451 MAC2STR(go_dev_addr
),
452 persistent
? " [PERSISTENT]" : "");
453 wpas_p2p_cross_connect_setup(wpa_s
);
455 wpa_msg(wpa_s
->parent
, MSG_INFO
, P2P_EVENT_GROUP_STARTED
456 "%s GO ssid=\"%s\" freq=%d passphrase=\"%s\" "
457 "go_dev_addr=" MACSTR
"%s",
458 wpa_s
->ifname
, ssid_txt
, ssid
->frequency
,
459 ssid
&& ssid
->passphrase
? ssid
->passphrase
: "",
460 MAC2STR(go_dev_addr
),
461 persistent
? " [PERSISTENT]" : "");
462 wpas_p2p_cross_connect_setup(wpa_s
);
466 wpas_p2p_store_persistent_group(wpa_s
->parent
, ssid
,
471 static void wpas_send_action_cb(void *eloop_ctx
, void *timeout_ctx
)
473 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
474 struct wpa_supplicant
*iface
;
478 without_roc
= wpa_s
->pending_action_without_roc
;
479 wpa_s
->pending_action_without_roc
= 0;
480 wpa_printf(MSG_DEBUG
, "P2P: Send Action callback (without_roc=%d "
481 "pending_action_tx=%p)",
482 without_roc
, wpa_s
->pending_action_tx
);
484 if (wpa_s
->pending_action_tx
== NULL
)
487 if (wpa_s
->off_channel_freq
!= wpa_s
->pending_action_freq
&&
488 wpa_s
->pending_action_freq
!= 0) {
489 wpa_printf(MSG_DEBUG
, "P2P: Pending Action frame TX "
490 "waiting for another freq=%u (off_channel_freq=%u)",
491 wpa_s
->pending_action_freq
,
492 wpa_s
->off_channel_freq
);
493 if (without_roc
&& wpa_s
->off_channel_freq
== 0) {
495 * We may get here if wpas_send_action() found us to be
496 * on the correct channel, but remain-on-channel cancel
497 * event was received before getting here.
499 wpa_printf(MSG_DEBUG
, "P2P: Schedule "
500 "remain-on-channel to send Action frame");
501 if (wpa_drv_remain_on_channel(
502 wpa_s
, wpa_s
->pending_action_freq
, 200) <
504 wpa_printf(MSG_DEBUG
, "P2P: Failed to request "
505 "driver to remain on channel (%u "
506 "MHz) for Action Frame TX",
507 wpa_s
->pending_action_freq
);
509 wpa_s
->roc_waiting_drv_freq
=
510 wpa_s
->pending_action_freq
;
516 * This call is likely going to be on the P2P device instance if the
517 * driver uses a separate interface for that purpose. However, some
518 * Action frames are actually sent within a P2P Group and when that is
519 * the case, we need to follow power saving (e.g., GO buffering the
520 * frame for a client in PS mode or a client following the advertised
521 * NoA from its GO). To make that easier for the driver, select the
522 * correct group interface here.
524 if (os_memcmp(wpa_s
->pending_action_src
, wpa_s
->own_addr
, ETH_ALEN
) !=
527 * Try to find a group interface that matches with the source
530 iface
= wpa_s
->global
->ifaces
;
532 if (os_memcmp(wpa_s
->pending_action_src
,
533 iface
->own_addr
, ETH_ALEN
) == 0)
538 wpa_printf(MSG_DEBUG
, "P2P: Use group interface %s "
539 "instead of interface %s for Action TX",
540 iface
->ifname
, wpa_s
->ifname
);
546 wpa_printf(MSG_DEBUG
, "P2P: Sending pending Action frame to "
547 MACSTR
" using interface %s",
548 MAC2STR(wpa_s
->pending_action_dst
), iface
->ifname
);
549 res
= wpa_drv_send_action(iface
, wpa_s
->pending_action_freq
,
550 wpa_s
->pending_action_dst
,
551 wpa_s
->pending_action_src
,
552 wpa_s
->pending_action_bssid
,
553 wpabuf_head(wpa_s
->pending_action_tx
),
554 wpabuf_len(wpa_s
->pending_action_tx
));
556 wpa_printf(MSG_DEBUG
, "P2P: Failed to send the pending "
559 * Use fake TX status event to allow P2P state machine to
562 wpas_send_action_tx_status(
563 wpa_s
, wpa_s
->pending_action_dst
,
564 wpabuf_head(wpa_s
->pending_action_tx
),
565 wpabuf_len(wpa_s
->pending_action_tx
), 0);
570 void wpas_send_action_tx_status(struct wpa_supplicant
*wpa_s
, const u8
*dst
,
571 const u8
*data
, size_t data_len
, int ack
)
573 if (wpa_s
->global
->p2p_disabled
)
576 if (wpa_s
->pending_action_tx
== NULL
) {
577 wpa_printf(MSG_DEBUG
, "P2P: Ignore Action TX status - no "
578 "pending operation");
582 if (os_memcmp(dst
, wpa_s
->pending_action_dst
, ETH_ALEN
) != 0) {
583 wpa_printf(MSG_DEBUG
, "P2P: Ignore Action TX status - unknown "
584 "destination address");
588 wpabuf_free(wpa_s
->pending_action_tx
);
589 wpa_s
->pending_action_tx
= NULL
;
591 p2p_send_action_cb(wpa_s
->global
->p2p
, wpa_s
->pending_action_freq
,
592 wpa_s
->pending_action_dst
,
593 wpa_s
->pending_action_src
,
594 wpa_s
->pending_action_bssid
,
597 if (wpa_s
->pending_pd_before_join
&&
598 (os_memcmp(wpa_s
->pending_action_dst
, wpa_s
->pending_join_dev_addr
,
600 os_memcmp(wpa_s
->pending_action_dst
,
601 wpa_s
->pending_join_iface_addr
, ETH_ALEN
) == 0)) {
602 wpa_s
->pending_pd_before_join
= 0;
603 wpa_printf(MSG_DEBUG
, "P2P: Starting pending "
604 "join-existing-group operation");
605 wpas_p2p_join_start(wpa_s
);
610 static int wpas_send_action(void *ctx
, unsigned int freq
, const u8
*dst
,
611 const u8
*src
, const u8
*bssid
, const u8
*buf
,
612 size_t len
, unsigned int wait_time
)
614 struct wpa_supplicant
*wpa_s
= ctx
;
616 wpa_printf(MSG_DEBUG
, "P2P: Send action frame: freq=%d dst=" MACSTR
617 " src=" MACSTR
" bssid=" MACSTR
" len=%d",
618 freq
, MAC2STR(dst
), MAC2STR(src
), MAC2STR(bssid
),
621 if (wpa_s
->pending_action_tx
) {
622 wpa_printf(MSG_DEBUG
, "P2P: Dropped pending Action frame TX "
623 "to " MACSTR
, MAC2STR(wpa_s
->pending_action_dst
));
624 wpabuf_free(wpa_s
->pending_action_tx
);
626 wpa_s
->pending_action_tx
= wpabuf_alloc(len
);
627 if (wpa_s
->pending_action_tx
== NULL
) {
628 wpa_printf(MSG_DEBUG
, "P2P: Failed to allocate Action frame "
629 "TX buffer (len=%llu)", (unsigned long long) len
);
632 wpabuf_put_data(wpa_s
->pending_action_tx
, buf
, len
);
633 os_memcpy(wpa_s
->pending_action_src
, src
, ETH_ALEN
);
634 os_memcpy(wpa_s
->pending_action_dst
, dst
, ETH_ALEN
);
635 os_memcpy(wpa_s
->pending_action_bssid
, bssid
, ETH_ALEN
);
636 wpa_s
->pending_action_freq
= freq
;
638 if (wpa_s
->off_channel_freq
== freq
|| freq
== 0) {
639 wpa_printf(MSG_DEBUG
, "P2P: Already on requested channel; "
640 "send Action frame immediately");
641 /* TODO: Would there ever be need to extend the current
642 * duration on the channel? */
643 wpa_s
->pending_action_without_roc
= 1;
644 eloop_cancel_timeout(wpas_send_action_cb
, wpa_s
, NULL
);
645 eloop_register_timeout(0, 0, wpas_send_action_cb
, wpa_s
, NULL
);
648 wpa_s
->pending_action_without_roc
= 0;
650 if (wpa_s
->roc_waiting_drv_freq
== freq
) {
651 wpa_printf(MSG_DEBUG
, "P2P: Already waiting for driver to get "
652 "to frequency %u MHz; continue waiting to send the "
653 "Action frame", freq
);
657 wpa_printf(MSG_DEBUG
, "P2P: Schedule Action frame to be transmitted "
658 "once the driver gets to the requested channel");
659 if (wait_time
> wpa_s
->max_remain_on_chan
)
660 wait_time
= wpa_s
->max_remain_on_chan
;
661 if (wpa_drv_remain_on_channel(wpa_s
, freq
, wait_time
) < 0) {
662 wpa_printf(MSG_DEBUG
, "P2P: Failed to request driver "
663 "to remain on channel (%u MHz) for Action "
667 wpa_s
->roc_waiting_drv_freq
= freq
;
673 static void wpas_send_action_done(void *ctx
)
675 struct wpa_supplicant
*wpa_s
= ctx
;
676 wpa_printf(MSG_DEBUG
, "P2P: Action frame sequence done notification");
677 wpabuf_free(wpa_s
->pending_action_tx
);
678 wpa_s
->pending_action_tx
= NULL
;
679 if (wpa_s
->off_channel_freq
) {
680 wpa_drv_cancel_remain_on_channel(wpa_s
);
681 wpa_s
->off_channel_freq
= 0;
682 wpa_s
->roc_waiting_drv_freq
= 0;
687 static int wpas_copy_go_neg_results(struct wpa_supplicant
*wpa_s
,
688 struct p2p_go_neg_results
*params
)
690 if (wpa_s
->go_params
== NULL
) {
691 wpa_s
->go_params
= os_malloc(sizeof(*params
));
692 if (wpa_s
->go_params
== NULL
)
695 os_memcpy(wpa_s
->go_params
, params
, sizeof(*params
));
700 static void wpas_start_wps_enrollee(struct wpa_supplicant
*wpa_s
,
701 struct p2p_go_neg_results
*res
)
703 wpa_printf(MSG_DEBUG
, "P2P: Start WPS Enrollee for peer " MACSTR
,
704 MAC2STR(res
->peer_interface_addr
));
705 wpa_hexdump_ascii(MSG_DEBUG
, "P2P: Start WPS Enrollee for SSID",
706 res
->ssid
, res
->ssid_len
);
707 wpa_supplicant_ap_deinit(wpa_s
);
708 wpas_copy_go_neg_results(wpa_s
, res
);
709 if (res
->wps_method
== WPS_PBC
)
710 wpas_wps_start_pbc(wpa_s
, res
->peer_interface_addr
, 1);
712 u16 dev_pw_id
= DEV_PW_DEFAULT
;
713 if (wpa_s
->p2p_wps_method
== WPS_PIN_KEYPAD
)
714 dev_pw_id
= DEV_PW_REGISTRAR_SPECIFIED
;
715 wpas_wps_start_pin(wpa_s
, res
->peer_interface_addr
,
716 wpa_s
->p2p_pin
, 1, dev_pw_id
);
721 static void p2p_go_configured(void *ctx
, void *data
)
723 struct wpa_supplicant
*wpa_s
= ctx
;
724 struct p2p_go_neg_results
*params
= data
;
725 struct wpa_ssid
*ssid
;
727 ssid
= wpa_s
->current_ssid
;
728 if (ssid
&& ssid
->mode
== WPAS_MODE_P2P_GO
) {
729 wpa_printf(MSG_DEBUG
, "P2P: Group setup without provisioning");
730 wpa_msg(wpa_s
->parent
, MSG_INFO
, P2P_EVENT_GROUP_STARTED
731 "%s GO ssid=\"%s\" freq=%d passphrase=\"%s\" "
732 "go_dev_addr=" MACSTR
"%s",
734 wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
),
736 params
->passphrase
? params
->passphrase
: "",
737 MAC2STR(wpa_s
->parent
->own_addr
),
738 params
->persistent_group
? " [PERSISTENT]" : "");
739 if (params
->persistent_group
)
740 wpas_p2p_store_persistent_group(
742 wpa_s
->parent
->own_addr
);
743 wpas_p2p_cross_connect_setup(wpa_s
);
747 wpa_printf(MSG_DEBUG
, "P2P: Setting up WPS for GO provisioning");
748 if (wpa_supplicant_ap_mac_addr_filter(wpa_s
,
749 params
->peer_interface_addr
)) {
750 wpa_printf(MSG_DEBUG
, "P2P: Failed to setup MAC address "
754 if (params
->wps_method
== WPS_PBC
)
755 wpa_supplicant_ap_wps_pbc(wpa_s
, params
->peer_interface_addr
);
756 else if (wpa_s
->p2p_pin
[0])
757 wpa_supplicant_ap_wps_pin(wpa_s
, params
->peer_interface_addr
,
758 wpa_s
->p2p_pin
, NULL
, 0);
759 os_free(wpa_s
->go_params
);
760 wpa_s
->go_params
= NULL
;
764 static void wpas_start_wps_go(struct wpa_supplicant
*wpa_s
,
765 struct p2p_go_neg_results
*params
,
768 struct wpa_ssid
*ssid
;
770 if (wpas_copy_go_neg_results(wpa_s
, params
) < 0)
773 ssid
= wpa_config_add_network(wpa_s
->conf
);
777 wpa_config_set_network_defaults(ssid
);
780 ssid
->p2p_persistent_group
= params
->persistent_group
;
781 ssid
->mode
= group_formation
? WPAS_MODE_P2P_GROUP_FORMATION
:
783 ssid
->frequency
= params
->freq
;
784 ssid
->ssid
= os_zalloc(params
->ssid_len
+ 1);
786 os_memcpy(ssid
->ssid
, params
->ssid
, params
->ssid_len
);
787 ssid
->ssid_len
= params
->ssid_len
;
789 ssid
->auth_alg
= WPA_AUTH_ALG_OPEN
;
790 ssid
->key_mgmt
= WPA_KEY_MGMT_PSK
;
791 ssid
->proto
= WPA_PROTO_RSN
;
792 ssid
->pairwise_cipher
= WPA_CIPHER_CCMP
;
793 ssid
->passphrase
= os_strdup(params
->passphrase
);
795 wpa_s
->ap_configured_cb
= p2p_go_configured
;
796 wpa_s
->ap_configured_cb_ctx
= wpa_s
;
797 wpa_s
->ap_configured_cb_data
= wpa_s
->go_params
;
798 wpa_s
->connect_without_scan
= 1;
799 wpa_s
->reassociate
= 1;
800 wpa_s
->disconnected
= 0;
801 wpa_supplicant_req_scan(wpa_s
, 0, 0);
805 static void wpas_p2p_clone_config(struct wpa_supplicant
*dst
,
806 const struct wpa_supplicant
*src
)
808 struct wpa_config
*d
;
809 const struct wpa_config
*s
;
814 #define C(n) if (s->n) d->n = os_strdup(s->n)
826 static int wpas_p2p_add_group_interface(struct wpa_supplicant
*wpa_s
,
827 enum wpa_driver_if_type type
)
829 char ifname
[120], force_ifname
[120];
831 if (wpa_s
->pending_interface_name
[0]) {
832 wpa_printf(MSG_DEBUG
, "P2P: Pending virtual interface exists "
833 "- skip creation of a new one");
834 if (is_zero_ether_addr(wpa_s
->pending_interface_addr
)) {
835 wpa_printf(MSG_DEBUG
, "P2P: Pending virtual address "
836 "unknown?! ifname='%s'",
837 wpa_s
->pending_interface_name
);
843 os_snprintf(ifname
, sizeof(ifname
), "%s-p2p-%d", wpa_s
->ifname
,
844 wpa_s
->p2p_group_idx
);
845 force_ifname
[0] = '\0';
847 wpa_printf(MSG_DEBUG
, "P2P: Create a new interface %s for the group",
849 wpa_s
->p2p_group_idx
++;
851 wpa_s
->pending_interface_type
= type
;
852 if (wpa_drv_if_add(wpa_s
, type
, ifname
, NULL
, NULL
, force_ifname
,
853 wpa_s
->pending_interface_addr
) < 0) {
854 wpa_printf(MSG_ERROR
, "P2P: Failed to create new group "
859 if (force_ifname
[0]) {
860 wpa_printf(MSG_DEBUG
, "P2P: Driver forced interface name %s",
862 os_strlcpy(wpa_s
->pending_interface_name
, force_ifname
,
863 sizeof(wpa_s
->pending_interface_name
));
865 os_strlcpy(wpa_s
->pending_interface_name
, ifname
,
866 sizeof(wpa_s
->pending_interface_name
));
867 wpa_printf(MSG_DEBUG
, "P2P: Created pending virtual interface %s addr "
868 MACSTR
, wpa_s
->pending_interface_name
,
869 MAC2STR(wpa_s
->pending_interface_addr
));
875 static void wpas_p2p_remove_pending_group_interface(
876 struct wpa_supplicant
*wpa_s
)
878 if (!wpa_s
->pending_interface_name
[0] ||
879 is_zero_ether_addr(wpa_s
->pending_interface_addr
))
880 return; /* No pending virtual interface */
882 wpa_printf(MSG_DEBUG
, "P2P: Removing pending group interface %s",
883 wpa_s
->pending_interface_name
);
884 wpa_drv_if_remove(wpa_s
, wpa_s
->pending_interface_type
,
885 wpa_s
->pending_interface_name
);
886 os_memset(wpa_s
->pending_interface_addr
, 0, ETH_ALEN
);
887 wpa_s
->pending_interface_name
[0] = '\0';
891 static struct wpa_supplicant
*
892 wpas_p2p_init_group_interface(struct wpa_supplicant
*wpa_s
, int go
)
894 struct wpa_interface iface
;
895 struct wpa_supplicant
*group_wpa_s
;
897 if (!wpa_s
->pending_interface_name
[0]) {
898 wpa_printf(MSG_ERROR
, "P2P: No pending group interface");
902 os_memset(&iface
, 0, sizeof(iface
));
903 iface
.ifname
= wpa_s
->pending_interface_name
;
904 iface
.driver
= wpa_s
->driver
->name
;
905 iface
.ctrl_interface
= wpa_s
->conf
->ctrl_interface
;
906 iface
.driver_param
= wpa_s
->conf
->driver_param
;
907 group_wpa_s
= wpa_supplicant_add_iface(wpa_s
->global
, &iface
);
908 if (group_wpa_s
== NULL
) {
909 wpa_printf(MSG_ERROR
, "P2P: Failed to create new "
910 "wpa_supplicant interface");
913 wpa_s
->pending_interface_name
[0] = '\0';
914 group_wpa_s
->parent
= wpa_s
;
915 group_wpa_s
->p2p_group_interface
= go
? P2P_GROUP_INTERFACE_GO
:
916 P2P_GROUP_INTERFACE_CLIENT
;
917 wpa_s
->global
->p2p_group_formation
= group_wpa_s
;
919 wpas_p2p_clone_config(group_wpa_s
, wpa_s
);
925 static void wpas_p2p_group_formation_timeout(void *eloop_ctx
,
928 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
929 wpa_printf(MSG_DEBUG
, "P2P: Group Formation timed out");
930 if (wpa_s
->global
->p2p
)
931 p2p_group_formation_failed(wpa_s
->global
->p2p
);
932 wpas_group_formation_completed(wpa_s
, 0);
936 void wpas_go_neg_completed(void *ctx
, struct p2p_go_neg_results
*res
)
938 struct wpa_supplicant
*wpa_s
= ctx
;
940 if (wpa_s
->off_channel_freq
) {
941 wpa_drv_cancel_remain_on_channel(wpa_s
);
942 wpa_s
->off_channel_freq
= 0;
943 wpa_s
->roc_waiting_drv_freq
= 0;
947 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_GO_NEG_FAILURE
"status=%d",
949 wpas_p2p_remove_pending_group_interface(wpa_s
);
953 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_GO_NEG_SUCCESS
);
955 if (wpa_s
->create_p2p_iface
) {
956 struct wpa_supplicant
*group_wpa_s
=
957 wpas_p2p_init_group_interface(wpa_s
, res
->role_go
);
958 if (group_wpa_s
== NULL
) {
959 wpas_p2p_remove_pending_group_interface(wpa_s
);
962 if (group_wpa_s
!= wpa_s
) {
963 os_memcpy(group_wpa_s
->p2p_pin
, wpa_s
->p2p_pin
,
964 sizeof(group_wpa_s
->p2p_pin
));
965 group_wpa_s
->p2p_wps_method
= wpa_s
->p2p_wps_method
;
967 os_memset(wpa_s
->pending_interface_addr
, 0, ETH_ALEN
);
968 wpa_s
->pending_interface_name
[0] = '\0';
969 group_wpa_s
->p2p_in_provisioning
= 1;
972 wpas_start_wps_go(group_wpa_s
, res
, 1);
974 wpas_start_wps_enrollee(group_wpa_s
, res
);
976 wpa_s
->p2p_in_provisioning
= 1;
977 wpa_s
->global
->p2p_group_formation
= wpa_s
;
980 wpas_start_wps_go(wpa_s
, res
, 1);
982 wpas_start_wps_enrollee(ctx
, res
);
985 wpa_s
->p2p_long_listen
= 0;
986 eloop_cancel_timeout(wpas_p2p_long_listen_timeout
, wpa_s
, NULL
);
988 eloop_cancel_timeout(wpas_p2p_group_formation_timeout
, wpa_s
, NULL
);
989 eloop_register_timeout(15 + res
->peer_config_timeout
/ 100,
990 (res
->peer_config_timeout
% 100) * 10000,
991 wpas_p2p_group_formation_timeout
, wpa_s
, NULL
);
995 void wpas_go_neg_req_rx(void *ctx
, const u8
*src
, u16 dev_passwd_id
)
997 struct wpa_supplicant
*wpa_s
= ctx
;
998 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_GO_NEG_REQUEST MACSTR
999 " dev_passwd_id=%u", MAC2STR(src
), dev_passwd_id
);
1003 void wpas_dev_found(void *ctx
, const u8
*addr
, const u8
*dev_addr
,
1004 const u8
*pri_dev_type
, const char *dev_name
,
1005 u16 config_methods
, u8 dev_capab
, u8 group_capab
)
1007 struct wpa_supplicant
*wpa_s
= ctx
;
1008 char devtype
[WPS_DEV_TYPE_BUFSIZE
];
1009 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_DEVICE_FOUND MACSTR
1010 " p2p_dev_addr=" MACSTR
1011 " pri_dev_type=%s name='%s' config_methods=0x%x "
1012 "dev_capab=0x%x group_capab=0x%x",
1013 MAC2STR(addr
), MAC2STR(dev_addr
),
1014 wps_dev_type_bin2str(pri_dev_type
, devtype
, sizeof(devtype
)),
1015 dev_name
, config_methods
, dev_capab
, group_capab
);
1019 static int wpas_start_listen(void *ctx
, unsigned int freq
,
1020 unsigned int duration
,
1021 const struct wpabuf
*probe_resp_ie
)
1023 struct wpa_supplicant
*wpa_s
= ctx
;
1025 wpa_drv_set_ap_wps_ie(wpa_s
, NULL
, probe_resp_ie
, NULL
);
1027 if (wpa_drv_probe_req_report(wpa_s
, 1) < 0) {
1028 wpa_printf(MSG_DEBUG
, "P2P: Failed to request the driver to "
1029 "report received Probe Request frames");
1033 wpa_s
->pending_listen_freq
= freq
;
1034 wpa_s
->pending_listen_duration
= duration
;
1036 if (wpa_drv_remain_on_channel(wpa_s
, freq
, duration
) < 0) {
1037 wpa_printf(MSG_DEBUG
, "P2P: Failed to request the driver "
1038 "to remain on channel (%u MHz) for Listen "
1040 wpa_s
->pending_listen_freq
= 0;
1043 wpa_s
->roc_waiting_drv_freq
= freq
;
1049 static void wpas_stop_listen(void *ctx
)
1051 struct wpa_supplicant
*wpa_s
= ctx
;
1052 if (wpa_s
->off_channel_freq
|| wpa_s
->roc_waiting_drv_freq
) {
1053 wpa_drv_cancel_remain_on_channel(wpa_s
);
1054 wpa_s
->off_channel_freq
= 0;
1055 wpa_s
->roc_waiting_drv_freq
= 0;
1057 wpa_drv_probe_req_report(wpa_s
, 0);
1061 static int wpas_send_probe_resp(void *ctx
, const struct wpabuf
*buf
)
1063 struct wpa_supplicant
*wpa_s
= ctx
;
1064 return wpa_drv_send_mlme(wpa_s
, wpabuf_head(buf
), wpabuf_len(buf
));
1068 static struct p2p_srv_bonjour
*
1069 wpas_p2p_service_get_bonjour(struct wpa_supplicant
*wpa_s
,
1070 const struct wpabuf
*query
)
1072 struct p2p_srv_bonjour
*bsrv
;
1075 len
= wpabuf_len(query
);
1076 dl_list_for_each(bsrv
, &wpa_s
->global
->p2p_srv_bonjour
,
1077 struct p2p_srv_bonjour
, list
) {
1078 if (len
== wpabuf_len(bsrv
->query
) &&
1079 os_memcmp(wpabuf_head(query
), wpabuf_head(bsrv
->query
),
1087 static struct p2p_srv_upnp
*
1088 wpas_p2p_service_get_upnp(struct wpa_supplicant
*wpa_s
, u8 version
,
1089 const char *service
)
1091 struct p2p_srv_upnp
*usrv
;
1093 dl_list_for_each(usrv
, &wpa_s
->global
->p2p_srv_upnp
,
1094 struct p2p_srv_upnp
, list
) {
1095 if (version
== usrv
->version
&&
1096 os_strcmp(service
, usrv
->service
) == 0)
1103 static void wpas_sd_add_proto_not_avail(struct wpabuf
*resp
, u8 srv_proto
,
1108 if (wpabuf_tailroom(resp
) < 5)
1111 /* Length (to be filled) */
1112 len_pos
= wpabuf_put(resp
, 2);
1113 wpabuf_put_u8(resp
, srv_proto
);
1114 wpabuf_put_u8(resp
, srv_trans_id
);
1116 wpabuf_put_u8(resp
, P2P_SD_PROTO_NOT_AVAILABLE
);
1117 /* Response Data: empty */
1118 WPA_PUT_LE16(len_pos
, (u8
*) wpabuf_put(resp
, 0) - len_pos
- 2);
1122 static void wpas_sd_all_bonjour(struct wpa_supplicant
*wpa_s
,
1123 struct wpabuf
*resp
, u8 srv_trans_id
)
1125 struct p2p_srv_bonjour
*bsrv
;
1128 wpa_printf(MSG_DEBUG
, "P2P: SD Request for all Bonjour services");
1130 if (dl_list_empty(&wpa_s
->global
->p2p_srv_bonjour
)) {
1131 wpa_printf(MSG_DEBUG
, "P2P: Bonjour protocol not available");
1135 dl_list_for_each(bsrv
, &wpa_s
->global
->p2p_srv_bonjour
,
1136 struct p2p_srv_bonjour
, list
) {
1137 if (wpabuf_tailroom(resp
) <
1138 5 + wpabuf_len(bsrv
->query
) + wpabuf_len(bsrv
->resp
))
1140 /* Length (to be filled) */
1141 len_pos
= wpabuf_put(resp
, 2);
1142 wpabuf_put_u8(resp
, P2P_SERV_BONJOUR
);
1143 wpabuf_put_u8(resp
, srv_trans_id
);
1145 wpabuf_put_u8(resp
, P2P_SD_SUCCESS
);
1146 wpa_hexdump_ascii(MSG_DEBUG
, "P2P: Matching Bonjour service",
1147 wpabuf_head(bsrv
->resp
),
1148 wpabuf_len(bsrv
->resp
));
1150 wpabuf_put_buf(resp
, bsrv
->query
); /* Key */
1151 wpabuf_put_buf(resp
, bsrv
->resp
); /* Value */
1152 WPA_PUT_LE16(len_pos
, (u8
*) wpabuf_put(resp
, 0) - len_pos
-
1158 static void wpas_sd_req_bonjour(struct wpa_supplicant
*wpa_s
,
1159 struct wpabuf
*resp
, u8 srv_trans_id
,
1160 const u8
*query
, size_t query_len
)
1162 struct p2p_srv_bonjour
*bsrv
;
1166 wpa_hexdump_ascii(MSG_DEBUG
, "P2P: SD Request for Bonjour",
1168 if (dl_list_empty(&wpa_s
->global
->p2p_srv_bonjour
)) {
1169 wpa_printf(MSG_DEBUG
, "P2P: Bonjour protocol not available");
1170 wpas_sd_add_proto_not_avail(resp
, P2P_SERV_BONJOUR
,
1175 if (query_len
== 0) {
1176 wpas_sd_all_bonjour(wpa_s
, resp
, srv_trans_id
);
1180 if (wpabuf_tailroom(resp
) < 5)
1182 /* Length (to be filled) */
1183 len_pos
= wpabuf_put(resp
, 2);
1184 wpabuf_put_u8(resp
, P2P_SERV_BONJOUR
);
1185 wpabuf_put_u8(resp
, srv_trans_id
);
1187 wpabuf_set(&buf
, query
, query_len
);
1188 bsrv
= wpas_p2p_service_get_bonjour(wpa_s
, &buf
);
1190 wpa_printf(MSG_DEBUG
, "P2P: Requested Bonjour service not "
1194 wpabuf_put_u8(resp
, P2P_SD_REQUESTED_INFO_NOT_AVAILABLE
);
1195 /* Response Data: empty */
1196 WPA_PUT_LE16(len_pos
, (u8
*) wpabuf_put(resp
, 0) - len_pos
-
1202 wpabuf_put_u8(resp
, P2P_SD_SUCCESS
);
1203 wpa_hexdump_ascii(MSG_DEBUG
, "P2P: Matching Bonjour service",
1204 wpabuf_head(bsrv
->resp
), wpabuf_len(bsrv
->resp
));
1206 if (wpabuf_tailroom(resp
) >=
1207 wpabuf_len(bsrv
->query
) + wpabuf_len(bsrv
->resp
)) {
1209 wpabuf_put_buf(resp
, bsrv
->query
); /* Key */
1210 wpabuf_put_buf(resp
, bsrv
->resp
); /* Value */
1212 WPA_PUT_LE16(len_pos
, (u8
*) wpabuf_put(resp
, 0) - len_pos
- 2);
1216 static void wpas_sd_all_upnp(struct wpa_supplicant
*wpa_s
,
1217 struct wpabuf
*resp
, u8 srv_trans_id
)
1219 struct p2p_srv_upnp
*usrv
;
1222 wpa_printf(MSG_DEBUG
, "P2P: SD Request for all UPnP services");
1224 if (dl_list_empty(&wpa_s
->global
->p2p_srv_upnp
)) {
1225 wpa_printf(MSG_DEBUG
, "P2P: UPnP protocol not available");
1229 dl_list_for_each(usrv
, &wpa_s
->global
->p2p_srv_upnp
,
1230 struct p2p_srv_upnp
, list
) {
1231 if (wpabuf_tailroom(resp
) < 5 + 1 + os_strlen(usrv
->service
))
1234 /* Length (to be filled) */
1235 len_pos
= wpabuf_put(resp
, 2);
1236 wpabuf_put_u8(resp
, P2P_SERV_UPNP
);
1237 wpabuf_put_u8(resp
, srv_trans_id
);
1240 wpabuf_put_u8(resp
, P2P_SD_SUCCESS
);
1242 wpabuf_put_u8(resp
, usrv
->version
);
1243 wpa_printf(MSG_DEBUG
, "P2P: Matching UPnP Service: %s",
1245 wpabuf_put_str(resp
, usrv
->service
);
1246 WPA_PUT_LE16(len_pos
, (u8
*) wpabuf_put(resp
, 0) - len_pos
-
1252 static void wpas_sd_req_upnp(struct wpa_supplicant
*wpa_s
,
1253 struct wpabuf
*resp
, u8 srv_trans_id
,
1254 const u8
*query
, size_t query_len
)
1256 struct p2p_srv_upnp
*usrv
;
1262 wpa_hexdump_ascii(MSG_DEBUG
, "P2P: SD Request for UPnP",
1265 if (dl_list_empty(&wpa_s
->global
->p2p_srv_upnp
)) {
1266 wpa_printf(MSG_DEBUG
, "P2P: UPnP protocol not available");
1267 wpas_sd_add_proto_not_avail(resp
, P2P_SERV_UPNP
,
1272 if (query_len
== 0) {
1273 wpas_sd_all_upnp(wpa_s
, resp
, srv_trans_id
);
1278 str
= os_malloc(query_len
);
1281 os_memcpy(str
, query
+ 1, query_len
- 1);
1282 str
[query_len
- 1] = '\0';
1284 if (wpabuf_tailroom(resp
) < 5)
1287 /* Length (to be filled) */
1288 len_pos
= wpabuf_put(resp
, 2);
1289 wpabuf_put_u8(resp
, P2P_SERV_UPNP
);
1290 wpabuf_put_u8(resp
, srv_trans_id
);
1292 dl_list_for_each(usrv
, &wpa_s
->global
->p2p_srv_upnp
,
1293 struct p2p_srv_upnp
, list
) {
1294 if (version
!= usrv
->version
)
1297 if (os_strcmp(str
, "ssdp:all") != 0 &&
1298 os_strstr(usrv
->service
, str
) == NULL
)
1301 if (wpabuf_tailroom(resp
) < 2)
1305 wpabuf_put_u8(resp
, P2P_SD_SUCCESS
);
1307 wpabuf_put_u8(resp
, version
);
1309 wpabuf_put_u8(resp
, ',');
1313 wpa_printf(MSG_DEBUG
, "P2P: Matching UPnP Service: %s",
1315 if (wpabuf_tailroom(resp
) < os_strlen(usrv
->service
))
1317 wpabuf_put_str(resp
, usrv
->service
);
1321 wpa_printf(MSG_DEBUG
, "P2P: Requested UPnP service not "
1324 wpabuf_put_u8(resp
, P2P_SD_REQUESTED_INFO_NOT_AVAILABLE
);
1325 /* Response Data: empty */
1328 WPA_PUT_LE16(len_pos
, (u8
*) wpabuf_put(resp
, 0) - len_pos
- 2);
1332 void wpas_sd_request(void *ctx
, int freq
, const u8
*sa
, u8 dialog_token
,
1333 u16 update_indic
, const u8
*tlvs
, size_t tlvs_len
)
1335 struct wpa_supplicant
*wpa_s
= ctx
;
1336 const u8
*pos
= tlvs
;
1337 const u8
*end
= tlvs
+ tlvs_len
;
1340 struct wpabuf
*resp
;
1341 u8 srv_proto
, srv_trans_id
;
1345 wpa_hexdump(MSG_MSGDUMP
, "P2P: Service Discovery Request TLVs",
1347 buf_len
= 2 * tlvs_len
+ 1;
1348 buf
= os_malloc(buf_len
);
1350 wpa_snprintf_hex(buf
, buf_len
, tlvs
, tlvs_len
);
1351 wpa_msg_ctrl(wpa_s
, MSG_INFO
, P2P_EVENT_SERV_DISC_REQ
"%d "
1353 freq
, MAC2STR(sa
), dialog_token
, update_indic
,
1358 if (wpa_s
->p2p_sd_over_ctrl_iface
)
1359 return; /* to be processed by an external program */
1361 resp
= wpabuf_alloc(10000);
1365 while (pos
+ 1 < end
) {
1366 wpa_printf(MSG_DEBUG
, "P2P: Service Request TLV");
1367 slen
= WPA_GET_LE16(pos
);
1369 if (pos
+ slen
> end
|| slen
< 2) {
1370 wpa_printf(MSG_DEBUG
, "P2P: Unexpected Query Data "
1375 tlv_end
= pos
+ slen
;
1378 wpa_printf(MSG_DEBUG
, "P2P: Service Protocol Type %u",
1380 srv_trans_id
= *pos
++;
1381 wpa_printf(MSG_DEBUG
, "P2P: Service Transaction ID %u",
1384 wpa_hexdump(MSG_MSGDUMP
, "P2P: Query Data",
1385 pos
, tlv_end
- pos
);
1388 if (wpa_s
->force_long_sd
) {
1389 wpa_printf(MSG_DEBUG
, "P2P: SD test - force long "
1391 wpas_sd_all_bonjour(wpa_s
, resp
, srv_trans_id
);
1392 wpas_sd_all_upnp(wpa_s
, resp
, srv_trans_id
);
1396 switch (srv_proto
) {
1397 case P2P_SERV_ALL_SERVICES
:
1398 wpa_printf(MSG_DEBUG
, "P2P: Service Discovery Request "
1399 "for all services");
1400 if (dl_list_empty(&wpa_s
->global
->p2p_srv_upnp
) &&
1401 dl_list_empty(&wpa_s
->global
->p2p_srv_bonjour
)) {
1402 wpa_printf(MSG_DEBUG
, "P2P: No service "
1403 "discovery protocols available");
1404 wpas_sd_add_proto_not_avail(
1405 resp
, P2P_SERV_ALL_SERVICES
,
1409 wpas_sd_all_bonjour(wpa_s
, resp
, srv_trans_id
);
1410 wpas_sd_all_upnp(wpa_s
, resp
, srv_trans_id
);
1412 case P2P_SERV_BONJOUR
:
1413 wpas_sd_req_bonjour(wpa_s
, resp
, srv_trans_id
,
1414 pos
, tlv_end
- pos
);
1417 wpas_sd_req_upnp(wpa_s
, resp
, srv_trans_id
,
1418 pos
, tlv_end
- pos
);
1421 wpa_printf(MSG_DEBUG
, "P2P: Unavailable service "
1422 "protocol %u", srv_proto
);
1423 wpas_sd_add_proto_not_avail(resp
, srv_proto
,
1432 wpas_p2p_sd_response(wpa_s
, freq
, sa
, dialog_token
, resp
);
1438 void wpas_sd_response(void *ctx
, const u8
*sa
, u16 update_indic
,
1439 const u8
*tlvs
, size_t tlvs_len
)
1441 struct wpa_supplicant
*wpa_s
= ctx
;
1442 const u8
*pos
= tlvs
;
1443 const u8
*end
= tlvs
+ tlvs_len
;
1449 wpa_hexdump(MSG_MSGDUMP
, "P2P: Service Discovery Response TLVs",
1451 if (tlvs_len
> 1500) {
1452 /* TODO: better way for handling this */
1453 wpa_msg_ctrl(wpa_s
, MSG_INFO
,
1454 P2P_EVENT_SERV_DISC_RESP MACSTR
1455 " %u <long response: %u bytes>",
1456 MAC2STR(sa
), update_indic
,
1457 (unsigned int) tlvs_len
);
1459 buf_len
= 2 * tlvs_len
+ 1;
1460 buf
= os_malloc(buf_len
);
1462 wpa_snprintf_hex(buf
, buf_len
, tlvs
, tlvs_len
);
1463 wpa_msg_ctrl(wpa_s
, MSG_INFO
,
1464 P2P_EVENT_SERV_DISC_RESP MACSTR
" %u %s",
1465 MAC2STR(sa
), update_indic
, buf
);
1471 u8 srv_proto
, srv_trans_id
, status
;
1473 wpa_printf(MSG_DEBUG
, "P2P: Service Response TLV");
1474 slen
= WPA_GET_LE16(pos
);
1476 if (pos
+ slen
> end
|| slen
< 3) {
1477 wpa_printf(MSG_DEBUG
, "P2P: Unexpected Response Data "
1481 tlv_end
= pos
+ slen
;
1484 wpa_printf(MSG_DEBUG
, "P2P: Service Protocol Type %u",
1486 srv_trans_id
= *pos
++;
1487 wpa_printf(MSG_DEBUG
, "P2P: Service Transaction ID %u",
1490 wpa_printf(MSG_DEBUG
, "P2P: Status Code ID %u",
1493 wpa_hexdump(MSG_MSGDUMP
, "P2P: Response Data",
1494 pos
, tlv_end
- pos
);
1501 void * wpas_p2p_sd_request(struct wpa_supplicant
*wpa_s
, const u8
*dst
,
1502 const struct wpabuf
*tlvs
)
1504 return p2p_sd_request(wpa_s
->global
->p2p
, dst
, tlvs
);
1508 void * wpas_p2p_sd_request_upnp(struct wpa_supplicant
*wpa_s
, const u8
*dst
,
1509 u8 version
, const char *query
)
1511 struct wpabuf
*tlvs
;
1514 tlvs
= wpabuf_alloc(2 + 1 + 1 + 1 + os_strlen(query
));
1517 wpabuf_put_le16(tlvs
, 1 + 1 + 1 + os_strlen(query
));
1518 wpabuf_put_u8(tlvs
, P2P_SERV_UPNP
); /* Service Protocol Type */
1519 wpabuf_put_u8(tlvs
, 1); /* Service Transaction ID */
1520 wpabuf_put_u8(tlvs
, version
);
1521 wpabuf_put_str(tlvs
, query
);
1522 ret
= wpas_p2p_sd_request(wpa_s
, dst
, tlvs
);
1528 int wpas_p2p_sd_cancel_request(struct wpa_supplicant
*wpa_s
, void *req
)
1530 return p2p_sd_cancel_request(wpa_s
->global
->p2p
, req
);
1534 void wpas_p2p_sd_response(struct wpa_supplicant
*wpa_s
, int freq
,
1535 const u8
*dst
, u8 dialog_token
,
1536 const struct wpabuf
*resp_tlvs
)
1538 p2p_sd_response(wpa_s
->global
->p2p
, freq
, dst
, dialog_token
,
1543 void wpas_p2p_sd_service_update(struct wpa_supplicant
*wpa_s
)
1545 p2p_sd_service_update(wpa_s
->global
->p2p
);
1549 static void wpas_p2p_srv_bonjour_free(struct p2p_srv_bonjour
*bsrv
)
1551 dl_list_del(&bsrv
->list
);
1552 wpabuf_free(bsrv
->query
);
1553 wpabuf_free(bsrv
->resp
);
1558 static void wpas_p2p_srv_upnp_free(struct p2p_srv_upnp
*usrv
)
1560 dl_list_del(&usrv
->list
);
1561 os_free(usrv
->service
);
1566 void wpas_p2p_service_flush(struct wpa_supplicant
*wpa_s
)
1568 struct p2p_srv_bonjour
*bsrv
, *bn
;
1569 struct p2p_srv_upnp
*usrv
, *un
;
1571 dl_list_for_each_safe(bsrv
, bn
, &wpa_s
->global
->p2p_srv_bonjour
,
1572 struct p2p_srv_bonjour
, list
)
1573 wpas_p2p_srv_bonjour_free(bsrv
);
1575 dl_list_for_each_safe(usrv
, un
, &wpa_s
->global
->p2p_srv_upnp
,
1576 struct p2p_srv_upnp
, list
)
1577 wpas_p2p_srv_upnp_free(usrv
);
1579 wpas_p2p_sd_service_update(wpa_s
);
1583 int wpas_p2p_service_add_bonjour(struct wpa_supplicant
*wpa_s
,
1584 struct wpabuf
*query
, struct wpabuf
*resp
)
1586 struct p2p_srv_bonjour
*bsrv
;
1588 bsrv
= wpas_p2p_service_get_bonjour(wpa_s
, query
);
1591 wpabuf_free(bsrv
->resp
);
1596 bsrv
= os_zalloc(sizeof(*bsrv
));
1599 bsrv
->query
= query
;
1601 dl_list_add(&wpa_s
->global
->p2p_srv_bonjour
, &bsrv
->list
);
1603 wpas_p2p_sd_service_update(wpa_s
);
1608 int wpas_p2p_service_del_bonjour(struct wpa_supplicant
*wpa_s
,
1609 const struct wpabuf
*query
)
1611 struct p2p_srv_bonjour
*bsrv
;
1613 bsrv
= wpas_p2p_service_get_bonjour(wpa_s
, query
);
1616 wpas_p2p_srv_bonjour_free(bsrv
);
1617 wpas_p2p_sd_service_update(wpa_s
);
1622 int wpas_p2p_service_add_upnp(struct wpa_supplicant
*wpa_s
, u8 version
,
1623 const char *service
)
1625 struct p2p_srv_upnp
*usrv
;
1627 if (wpas_p2p_service_get_upnp(wpa_s
, version
, service
))
1628 return 0; /* Already listed */
1629 usrv
= os_zalloc(sizeof(*usrv
));
1632 usrv
->version
= version
;
1633 usrv
->service
= os_strdup(service
);
1634 if (usrv
->service
== NULL
) {
1638 dl_list_add(&wpa_s
->global
->p2p_srv_upnp
, &usrv
->list
);
1640 wpas_p2p_sd_service_update(wpa_s
);
1645 int wpas_p2p_service_del_upnp(struct wpa_supplicant
*wpa_s
, u8 version
,
1646 const char *service
)
1648 struct p2p_srv_upnp
*usrv
;
1650 usrv
= wpas_p2p_service_get_upnp(wpa_s
, version
, service
);
1653 wpas_p2p_srv_upnp_free(usrv
);
1654 wpas_p2p_sd_service_update(wpa_s
);
1659 static void wpas_prov_disc_local_display(struct wpa_supplicant
*wpa_s
,
1660 const u8
*peer
, const char *params
)
1662 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_PROV_DISC_SHOW_PIN MACSTR
" %08d%s",
1663 MAC2STR(peer
), wps_generate_pin(), params
);
1667 static void wpas_prov_disc_local_keypad(struct wpa_supplicant
*wpa_s
,
1668 const u8
*peer
, const char *params
)
1670 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_PROV_DISC_ENTER_PIN MACSTR
"%s",
1671 MAC2STR(peer
), params
);
1675 void wpas_prov_disc_req(void *ctx
, const u8
*peer
, u16 config_methods
,
1676 const u8
*dev_addr
, const u8
*pri_dev_type
,
1677 const char *dev_name
, u16 supp_config_methods
,
1678 u8 dev_capab
, u8 group_capab
)
1680 struct wpa_supplicant
*wpa_s
= ctx
;
1681 char devtype
[WPS_DEV_TYPE_BUFSIZE
];
1683 u8 empty_dev_type
[8];
1685 if (pri_dev_type
== NULL
) {
1686 os_memset(empty_dev_type
, 0, sizeof(empty_dev_type
));
1687 pri_dev_type
= empty_dev_type
;
1689 os_snprintf(params
, sizeof(params
), " p2p_dev_addr=" MACSTR
1690 " pri_dev_type=%s name='%s' config_methods=0x%x "
1691 "dev_capab=0x%x group_capab=0x%x",
1693 wps_dev_type_bin2str(pri_dev_type
, devtype
,
1695 dev_name
, supp_config_methods
, dev_capab
, group_capab
);
1696 params
[sizeof(params
) - 1] = '\0';
1698 if (config_methods
& WPS_CONFIG_DISPLAY
)
1699 wpas_prov_disc_local_display(wpa_s
, peer
, params
);
1700 else if (config_methods
& WPS_CONFIG_KEYPAD
)
1701 wpas_prov_disc_local_keypad(wpa_s
, peer
, params
);
1702 else if (config_methods
& WPS_CONFIG_PUSHBUTTON
)
1703 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_PROV_DISC_PBC_REQ MACSTR
1704 "%s", MAC2STR(peer
), params
);
1708 void wpas_prov_disc_resp(void *ctx
, const u8
*peer
, u16 config_methods
)
1710 struct wpa_supplicant
*wpa_s
= ctx
;
1711 if (config_methods
& WPS_CONFIG_DISPLAY
)
1712 wpas_prov_disc_local_keypad(wpa_s
, peer
, "");
1713 else if (config_methods
& WPS_CONFIG_KEYPAD
)
1714 wpas_prov_disc_local_display(wpa_s
, peer
, "");
1715 else if (config_methods
& WPS_CONFIG_PUSHBUTTON
)
1716 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_PROV_DISC_PBC_RESP MACSTR
,
1719 if (wpa_s
->pending_pd_before_join
&&
1720 (os_memcmp(peer
, wpa_s
->pending_join_dev_addr
, ETH_ALEN
) == 0 ||
1721 os_memcmp(peer
, wpa_s
->pending_join_iface_addr
, ETH_ALEN
) == 0)) {
1722 wpa_s
->pending_pd_before_join
= 0;
1723 wpa_printf(MSG_DEBUG
, "P2P: Starting pending "
1724 "join-existing-group operation");
1725 wpas_p2p_join_start(wpa_s
);
1730 static u8
wpas_invitation_process(void *ctx
, const u8
*sa
, const u8
*bssid
,
1731 const u8
*go_dev_addr
, const u8
*ssid
,
1732 size_t ssid_len
, int *go
, u8
*group_bssid
,
1733 int *force_freq
, int persistent_group
)
1735 struct wpa_supplicant
*wpa_s
= ctx
;
1737 u8 cur_bssid
[ETH_ALEN
];
1740 if (!persistent_group
) {
1741 wpa_printf(MSG_DEBUG
, "P2P: Invitation from " MACSTR
1742 " to join an active group", MAC2STR(sa
));
1743 if (!is_zero_ether_addr(wpa_s
->p2p_auth_invite
) &&
1744 (os_memcmp(go_dev_addr
, wpa_s
->p2p_auth_invite
, ETH_ALEN
)
1746 os_memcmp(sa
, wpa_s
->p2p_auth_invite
, ETH_ALEN
) == 0)) {
1747 wpa_printf(MSG_DEBUG
, "P2P: Accept previously "
1748 "authorized invitation");
1752 * Do not accept the invitation automatically; notify user and
1755 return P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE
;
1758 if (!wpa_s
->conf
->persistent_reconnect
)
1759 return P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE
;
1761 for (s
= wpa_s
->conf
->ssid
; s
; s
= s
->next
) {
1762 if (s
->disabled
== 2 &&
1763 os_memcmp(s
->bssid
, go_dev_addr
, ETH_ALEN
) == 0 &&
1764 s
->ssid_len
== ssid_len
&&
1765 os_memcmp(ssid
, s
->ssid
, ssid_len
) == 0)
1770 wpa_printf(MSG_DEBUG
, "P2P: Invitation from " MACSTR
1771 " requested reinvocation of an unknown group",
1773 return P2P_SC_FAIL_UNKNOWN_GROUP
;
1776 if (s
->mode
== WPAS_MODE_P2P_GO
&& !wpas_p2p_create_iface(wpa_s
)) {
1778 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
1779 wpa_printf(MSG_DEBUG
, "P2P: The only available "
1780 "interface is already in use - reject "
1782 return P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE
;
1784 os_memcpy(group_bssid
, wpa_s
->own_addr
, ETH_ALEN
);
1785 } else if (s
->mode
== WPAS_MODE_P2P_GO
) {
1787 if (wpas_p2p_add_group_interface(wpa_s
, WPA_IF_P2P_GO
) < 0)
1789 wpa_printf(MSG_ERROR
, "P2P: Failed to allocate a new "
1790 "interface address for the group");
1791 return P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE
;
1793 os_memcpy(group_bssid
, wpa_s
->pending_interface_addr
,
1798 if (wpa_s
->current_ssid
&& wpa_drv_get_bssid(wpa_s
, cur_bssid
) == 0 &&
1799 wpa_s
->assoc_freq
) {
1800 wpa_printf(MSG_DEBUG
, "P2P: Trying to force channel to match "
1801 "the channel we are already using");
1802 *force_freq
= wpa_s
->assoc_freq
;
1805 res
= wpa_drv_shared_freq(wpa_s
);
1807 wpa_printf(MSG_DEBUG
, "P2P: Trying to force channel to match "
1808 "with the channel we are already using on a "
1809 "shared interface");
1813 return P2P_SC_SUCCESS
;
1817 static void wpas_invitation_received(void *ctx
, const u8
*sa
, const u8
*bssid
,
1818 const u8
*ssid
, size_t ssid_len
,
1819 const u8
*go_dev_addr
, u8 status
,
1822 struct wpa_supplicant
*wpa_s
= ctx
;
1825 for (s
= wpa_s
->conf
->ssid
; s
; s
= s
->next
) {
1826 if (s
->disabled
== 2 &&
1827 s
->ssid_len
== ssid_len
&&
1828 os_memcmp(ssid
, s
->ssid
, ssid_len
) == 0)
1832 if (status
== P2P_SC_SUCCESS
) {
1833 wpa_printf(MSG_DEBUG
, "P2P: Invitation from peer " MACSTR
1834 " was accepted; op_freq=%d MHz",
1835 MAC2STR(sa
), op_freq
);
1837 wpas_p2p_group_add_persistent(
1838 wpa_s
, s
, s
->mode
== WPAS_MODE_P2P_GO
, 0);
1840 wpas_p2p_join(wpa_s
, bssid
, go_dev_addr
,
1841 wpa_s
->p2p_wps_method
);
1846 if (status
!= P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE
) {
1847 wpa_printf(MSG_DEBUG
, "P2P: Invitation from peer " MACSTR
1848 " was rejected (status %u)", MAC2STR(sa
), status
);
1854 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_INVITATION_RECEIVED
1855 "sa=" MACSTR
" go_dev_addr=" MACSTR
1856 " bssid=" MACSTR
" unknown-network",
1857 MAC2STR(sa
), MAC2STR(go_dev_addr
),
1860 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_INVITATION_RECEIVED
1861 "sa=" MACSTR
" go_dev_addr=" MACSTR
1863 MAC2STR(sa
), MAC2STR(go_dev_addr
));
1868 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_INVITATION_RECEIVED
"sa=" MACSTR
1869 " persistent=%d", MAC2STR(sa
), s
->id
);
1873 static void wpas_invitation_result(void *ctx
, int status
, const u8
*bssid
)
1875 struct wpa_supplicant
*wpa_s
= ctx
;
1876 struct wpa_ssid
*ssid
;
1879 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_INVITATION_RESULT
1880 "status=%d " MACSTR
,
1881 status
, MAC2STR(bssid
));
1883 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_INVITATION_RESULT
1884 "status=%d ", status
);
1887 if (wpa_s
->pending_invite_ssid_id
== -1)
1888 return; /* Invitation to active group */
1890 if (status
!= P2P_SC_SUCCESS
) {
1891 wpas_p2p_remove_pending_group_interface(wpa_s
);
1895 ssid
= wpa_config_get_network(wpa_s
->conf
,
1896 wpa_s
->pending_invite_ssid_id
);
1898 wpa_printf(MSG_ERROR
, "P2P: Could not find persistent group "
1899 "data matching with invitation");
1903 wpas_p2p_group_add_persistent(wpa_s
, ssid
,
1904 ssid
->mode
== WPAS_MODE_P2P_GO
, 0);
1908 static int wpas_p2p_setup_channels(struct wpa_supplicant
*wpa_s
,
1909 struct p2p_config
*p2p
)
1911 struct hostapd_hw_modes
*modes
;
1912 u16 num_modes
, flags
;
1914 int band24
= 0, band5_low
= 0, band5_high
= 0;
1916 /* TODO: more detailed selection of channels within reg_class based on
1917 * driver capabilities */
1919 modes
= wpa_drv_get_hw_feature_data(wpa_s
, &num_modes
, &flags
);
1920 if (modes
== NULL
) {
1921 wpa_printf(MSG_DEBUG
, "P2P: Driver did not support fetching "
1922 "of all supported channels; assume dualband "
1924 band24
= band5_low
= band5_high
= 1;
1926 for (i
= 0; i
< num_modes
; i
++) {
1927 struct hostapd_hw_modes
*mode
;
1929 if (mode
->mode
== HOSTAPD_MODE_IEEE80211G
) {
1931 } else if (mode
->mode
== HOSTAPD_MODE_IEEE80211A
) {
1933 for (j
= 0; j
< mode
->num_channels
; j
++) {
1934 struct hostapd_channel_data
*ch
;
1935 ch
= &mode
->channels
[j
];
1938 else if (ch
->chan
== 157)
1948 wpa_printf(MSG_DEBUG
, "P2P: Enable operating classes for "
1951 /* Operating class 81 - 2.4 GHz band channels 1..13 */
1952 p2p
->channels
.reg_class
[cla
].reg_class
= 81;
1954 p2p
->channels
.reg_class
[cla
].channels
= 13;
1955 for (i
= 0; i
< 13; i
++)
1956 p2p
->channels
.reg_class
[cla
].channel
[i
] = i
+ 1;
1958 p2p
->channels
.reg_class
[cla
].channels
= 11;
1959 for (i
= 0; i
< 11; i
++)
1960 p2p
->channels
.reg_class
[cla
].channel
[i
] = i
+ 1;
1965 /* Operating class 82 - 2.4 GHz band channel 14 */
1966 p2p
->channels
.reg_class
[cla
].reg_class
= 82;
1967 p2p
->channels
.reg_class
[cla
].channels
= 1;
1968 p2p
->channels
.reg_class
[cla
].channel
[0] = 14;
1973 /* Operating class 83 - 2.4 GHz band channels 1..9; 40 MHz */
1974 p2p
->channels
.reg_class
[cla
].reg_class
= 83;
1975 p2p
->channels
.reg_class
[cla
].channels
= 9;
1976 for (i
= 0; i
< 9; i
++)
1977 p2p
->channels
.reg_class
[cla
].channel
[i
] = i
+ 1;
1980 /* Operating class 84 - 2.4 GHz band channels 5..13; 40 MHz */
1981 p2p
->channels
.reg_class
[cla
].reg_class
= 84;
1982 p2p
->channels
.reg_class
[cla
].channels
= 9;
1983 for (i
= 0; i
< 9; i
++)
1984 p2p
->channels
.reg_class
[cla
].channel
[i
] = i
+ 5;
1990 wpa_printf(MSG_DEBUG
, "P2P: Enable operating classes for "
1991 "lower 5 GHz band");
1993 /* Operating class 115 - 5 GHz, channels 36-48 */
1994 p2p
->channels
.reg_class
[cla
].reg_class
= 115;
1995 p2p
->channels
.reg_class
[cla
].channels
= 4;
1996 p2p
->channels
.reg_class
[cla
].channel
[0] = 36;
1997 p2p
->channels
.reg_class
[cla
].channel
[1] = 40;
1998 p2p
->channels
.reg_class
[cla
].channel
[2] = 44;
1999 p2p
->channels
.reg_class
[cla
].channel
[3] = 48;
2003 /* Operating class 116 - 5 GHz, channels 36,44; 40 MHz */
2004 p2p
->channels
.reg_class
[cla
].reg_class
= 116;
2005 p2p
->channels
.reg_class
[cla
].channels
= 2;
2006 p2p
->channels
.reg_class
[cla
].channel
[0] = 36;
2007 p2p
->channels
.reg_class
[cla
].channel
[1] = 44;
2010 /* Operating class 117 - 5 GHz, channels 40,48; 40 MHz */
2011 p2p
->channels
.reg_class
[cla
].reg_class
= 117;
2012 p2p
->channels
.reg_class
[cla
].channels
= 2;
2013 p2p
->channels
.reg_class
[cla
].channel
[0] = 40;
2014 p2p
->channels
.reg_class
[cla
].channel
[1] = 48;
2020 wpa_printf(MSG_DEBUG
, "P2P: Enable operating classes for "
2021 "higher 5 GHz band");
2023 /* Operating class 124 - 5 GHz, channels 149,153,157,161 */
2024 p2p
->channels
.reg_class
[cla
].reg_class
= 124;
2025 p2p
->channels
.reg_class
[cla
].channels
= 4;
2026 p2p
->channels
.reg_class
[cla
].channel
[0] = 149;
2027 p2p
->channels
.reg_class
[cla
].channel
[1] = 153;
2028 p2p
->channels
.reg_class
[cla
].channel
[2] = 157;
2029 p2p
->channels
.reg_class
[cla
].channel
[3] = 161;
2033 /* Operating class 126 - 5 GHz, channels 149,157; 40 MHz */
2034 p2p
->channels
.reg_class
[cla
].reg_class
= 126;
2035 p2p
->channels
.reg_class
[cla
].channels
= 2;
2036 p2p
->channels
.reg_class
[cla
].channel
[0] = 149;
2037 p2p
->channels
.reg_class
[cla
].channel
[1] = 157;
2040 /* Operating class 127 - 5 GHz, channels 153,161; 40 MHz */
2041 p2p
->channels
.reg_class
[cla
].reg_class
= 127;
2042 p2p
->channels
.reg_class
[cla
].channels
= 2;
2043 p2p
->channels
.reg_class
[cla
].channel
[0] = 153;
2044 p2p
->channels
.reg_class
[cla
].channel
[1] = 161;
2049 p2p
->channels
.reg_classes
= cla
;
2052 ieee80211_sta_free_hw_features(modes
, num_modes
);
2058 static int wpas_get_noa(void *ctx
, const u8
*interface_addr
, u8
*buf
,
2061 struct wpa_supplicant
*wpa_s
= ctx
;
2063 for (wpa_s
= wpa_s
->global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
2064 if (os_memcmp(wpa_s
->own_addr
, interface_addr
, ETH_ALEN
) == 0)
2070 return wpa_drv_get_noa(wpa_s
, buf
, buf_len
);
2075 * wpas_p2p_init - Initialize P2P module for %wpa_supplicant
2076 * @global: Pointer to global data from wpa_supplicant_init()
2077 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
2078 * Returns: 0 on success, -1 on failure
2080 int wpas_p2p_init(struct wpa_global
*global
, struct wpa_supplicant
*wpa_s
)
2082 struct p2p_config p2p
;
2086 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_CAPABLE
))
2089 #ifdef CONFIG_CLIENT_MLME
2090 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
)) {
2091 wpa_s
->mlme
.public_action_cb
= p2p_rx_action_mlme
;
2092 wpa_s
->mlme
.public_action_cb_ctx
= wpa_s
;
2094 #endif /* CONFIG_CLIENT_MLME */
2096 if (wpa_drv_disable_11b_rates(wpa_s
, 1) < 0) {
2097 wpa_printf(MSG_DEBUG
, "P2P: Failed to disable 11b rates");
2098 /* Continue anyway; this is not really a fatal error */
2104 os_memset(&p2p
, 0, sizeof(p2p
));
2105 p2p
.msg_ctx
= wpa_s
;
2107 p2p
.p2p_scan
= wpas_p2p_scan
;
2108 p2p
.send_action
= wpas_send_action
;
2109 p2p
.send_action_done
= wpas_send_action_done
;
2110 p2p
.go_neg_completed
= wpas_go_neg_completed
;
2111 p2p
.go_neg_req_rx
= wpas_go_neg_req_rx
;
2112 p2p
.dev_found
= wpas_dev_found
;
2113 p2p
.start_listen
= wpas_start_listen
;
2114 p2p
.stop_listen
= wpas_stop_listen
;
2115 p2p
.send_probe_resp
= wpas_send_probe_resp
;
2116 p2p
.sd_request
= wpas_sd_request
;
2117 p2p
.sd_response
= wpas_sd_response
;
2118 p2p
.prov_disc_req
= wpas_prov_disc_req
;
2119 p2p
.prov_disc_resp
= wpas_prov_disc_resp
;
2120 p2p
.invitation_process
= wpas_invitation_process
;
2121 p2p
.invitation_received
= wpas_invitation_received
;
2122 p2p
.invitation_result
= wpas_invitation_result
;
2123 p2p
.get_noa
= wpas_get_noa
;
2125 os_memcpy(wpa_s
->global
->p2p_dev_addr
, wpa_s
->own_addr
, ETH_ALEN
);
2126 os_memcpy(p2p
.dev_addr
, wpa_s
->own_addr
, ETH_ALEN
);
2127 p2p
.dev_name
= wpa_s
->conf
->device_name
;
2129 if (wpa_s
->conf
->p2p_listen_reg_class
&&
2130 wpa_s
->conf
->p2p_listen_channel
) {
2131 p2p
.reg_class
= wpa_s
->conf
->p2p_listen_reg_class
;
2132 p2p
.channel
= wpa_s
->conf
->p2p_listen_channel
;
2136 * Pick one of the social channels randomly as the listen
2139 os_get_random((u8
*) &r
, sizeof(r
));
2140 p2p
.channel
= 1 + (r
% 3) * 5;
2143 if (wpa_s
->conf
->p2p_oper_reg_class
&&
2144 wpa_s
->conf
->p2p_oper_channel
) {
2145 p2p
.op_reg_class
= wpa_s
->conf
->p2p_oper_reg_class
;
2146 p2p
.op_channel
= wpa_s
->conf
->p2p_oper_channel
;
2148 p2p
.op_reg_class
= 81;
2150 * For initial tests, pick the operation channel randomly.
2151 * TODO: Use scan results (etc.) to select the best channel.
2153 p2p
.op_channel
= 1 + r
% 11;
2155 wpa_printf(MSG_DEBUG
, "P2P: Own listen channel: %d "
2156 "Own preferred operation channel: %d",
2157 p2p
.channel
, p2p
.op_channel
);
2158 if (wpa_s
->conf
->country
[0] && wpa_s
->conf
->country
[1]) {
2159 os_memcpy(p2p
.country
, wpa_s
->conf
->country
, 2);
2160 p2p
.country
[2] = 0x04;
2162 os_memcpy(p2p
.country
, "US\x04", 3);
2164 if (wpas_p2p_setup_channels(wpa_s
, &p2p
)) {
2165 wpa_printf(MSG_ERROR
, "P2P: Failed to configure supported "
2170 if (wpa_s
->conf
->device_type
&&
2171 wps_dev_type_str2bin(wpa_s
->conf
->device_type
, p2p
.pri_dev_type
) <
2173 wpa_printf(MSG_ERROR
, "P2P: Invalid device_type");
2177 for (i
= 0; i
< MAX_SEC_DEVICE_TYPES
; i
++) {
2178 if (wpa_s
->conf
->sec_device_type
[i
] == NULL
)
2180 if (wps_dev_type_str2bin(
2181 wpa_s
->conf
->sec_device_type
[i
],
2182 p2p
.sec_dev_type
[p2p
.num_sec_dev_types
]) < 0) {
2183 wpa_printf(MSG_ERROR
, "P2P: Invalid sec_device_type");
2186 p2p
.num_sec_dev_types
++;
2187 if (p2p
.num_sec_dev_types
== P2P_SEC_DEVICE_TYPES
)
2191 p2p
.concurrent_operations
= !!(wpa_s
->drv_flags
&
2192 WPA_DRIVER_FLAGS_P2P_CONCURRENT
);
2194 p2p
.max_peers
= wpa_s
->max_stations
? wpa_s
->max_stations
: 100;
2196 if (wpa_s
->conf
->p2p_ssid_postfix
) {
2197 p2p
.ssid_postfix_len
=
2198 os_strlen(wpa_s
->conf
->p2p_ssid_postfix
);
2199 if (p2p
.ssid_postfix_len
> sizeof(p2p
.ssid_postfix
))
2200 p2p
.ssid_postfix_len
= sizeof(p2p
.ssid_postfix
);
2201 os_memcpy(p2p
.ssid_postfix
, wpa_s
->conf
->p2p_ssid_postfix
,
2202 p2p
.ssid_postfix_len
);
2205 p2p
.p2p_intra_bss
= wpa_s
->conf
->p2p_intra_bss
;
2207 global
->p2p
= p2p_init(&p2p
);
2208 if (global
->p2p
== NULL
)
2216 * wpas_p2p_deinit - Deinitialize per-interface P2P data
2217 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
2219 * This function deinitialize per-interface P2P data.
2221 void wpas_p2p_deinit(struct wpa_supplicant
*wpa_s
)
2223 if (wpa_s
->driver
&& wpa_s
->drv_priv
)
2224 wpa_drv_probe_req_report(wpa_s
, 0);
2225 os_free(wpa_s
->go_params
);
2226 wpa_s
->go_params
= NULL
;
2227 wpabuf_free(wpa_s
->pending_action_tx
);
2228 wpa_s
->pending_action_tx
= NULL
;
2229 eloop_cancel_timeout(wpas_send_action_cb
, wpa_s
, NULL
);
2230 eloop_cancel_timeout(wpas_p2p_group_formation_timeout
, wpa_s
, NULL
);
2231 eloop_cancel_timeout(wpas_p2p_join_scan
, wpa_s
, NULL
);
2232 wpa_s
->p2p_long_listen
= 0;
2233 eloop_cancel_timeout(wpas_p2p_long_listen_timeout
, wpa_s
, NULL
);
2234 wpas_p2p_remove_pending_group_interface(wpa_s
);
2236 /* TODO: remove group interface from the driver if this wpa_s instance
2237 * is on top of a P2P group interface */
2242 * wpas_p2p_deinit_global - Deinitialize global P2P module
2243 * @global: Pointer to global data from wpa_supplicant_init()
2245 * This function deinitializes the global (per device) P2P module.
2247 void wpas_p2p_deinit_global(struct wpa_global
*global
)
2249 struct wpa_supplicant
*wpa_s
, *tmp
;
2252 if (global
->p2p
== NULL
)
2255 /* Remove remaining P2P group interfaces */
2256 wpa_s
= global
->ifaces
;
2258 wpas_p2p_service_flush(wpa_s
);
2259 while (wpa_s
&& wpa_s
->p2p_group_interface
!= NOT_P2P_GROUP_INTERFACE
)
2260 wpa_s
= wpa_s
->next
;
2262 enum wpa_driver_if_type type
;
2263 tmp
= global
->ifaces
;
2266 tmp
->p2p_group_interface
== NOT_P2P_GROUP_INTERFACE
)) {
2271 ifname
= os_strdup(tmp
->ifname
);
2272 type
= wpas_p2p_if_type(tmp
->p2p_group_interface
);
2273 wpa_supplicant_remove_iface(global
, tmp
);
2275 wpa_drv_if_remove(wpa_s
, type
, ifname
);
2280 * Deinit GO data on any possibly remaining interface (if main
2281 * interface is used as GO).
2283 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
2284 if (wpa_s
->ap_iface
)
2285 wpas_p2p_group_deinit(wpa_s
);
2288 p2p_deinit(global
->p2p
);
2293 static int wpas_p2p_create_iface(struct wpa_supplicant
*wpa_s
)
2295 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_DEDICATED_INTERFACE
)
2296 return 1; /* P2P group requires a new interface in every case
2298 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_CONCURRENT
))
2299 return 0; /* driver does not support concurrent operations */
2300 if (wpa_s
->global
->ifaces
->next
)
2301 return 1; /* more that one interface already in use */
2302 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
)
2303 return 1; /* this interface is already in use */
2308 static int wpas_p2p_start_go_neg(struct wpa_supplicant
*wpa_s
,
2309 const u8
*peer_addr
,
2310 enum p2p_wps_method wps_method
,
2311 int go_intent
, const u8
*own_interface_addr
,
2312 unsigned int force_freq
, int persistent_group
)
2314 return p2p_connect(wpa_s
->global
->p2p
, peer_addr
, wps_method
,
2315 go_intent
, own_interface_addr
, force_freq
,
2320 static int wpas_p2p_auth_go_neg(struct wpa_supplicant
*wpa_s
,
2321 const u8
*peer_addr
,
2322 enum p2p_wps_method wps_method
,
2323 int go_intent
, const u8
*own_interface_addr
,
2324 unsigned int force_freq
, int persistent_group
)
2326 return p2p_authorize(wpa_s
->global
->p2p
, peer_addr
, wps_method
,
2327 go_intent
, own_interface_addr
, force_freq
,
2332 static void wpas_p2p_scan_res_join(struct wpa_supplicant
*wpa_s
,
2333 struct wpa_scan_results
*scan_res
)
2335 struct wpa_bss
*bss
;
2338 eloop_cancel_timeout(wpas_p2p_join_scan
, wpa_s
, NULL
);
2340 if (wpa_s
->global
->p2p_disabled
)
2343 wpa_printf(MSG_DEBUG
, "P2P: Scan results received (%d BSS) for join",
2344 scan_res
? (int) scan_res
->num
: -1);
2347 wpas_p2p_scan_res_handler(wpa_s
, scan_res
);
2349 freq
= p2p_get_oper_freq(wpa_s
->global
->p2p
,
2350 wpa_s
->pending_join_iface_addr
);
2352 wpa_printf(MSG_DEBUG
, "P2P: Target GO operating frequency "
2353 "from P2P peer table: %d MHz", freq
);
2355 bss
= wpa_bss_get_bssid(wpa_s
, wpa_s
->pending_join_iface_addr
);
2358 wpa_printf(MSG_DEBUG
, "P2P: Target GO operating frequency "
2359 "from BSS table: %d MHz", freq
);
2364 wpa_printf(MSG_DEBUG
, "P2P: Send Provision Discovery Request "
2365 "prior to joining an existing group (GO " MACSTR
2367 MAC2STR(wpa_s
->pending_join_dev_addr
), freq
);
2368 wpa_s
->pending_pd_before_join
= 1;
2370 switch (wpa_s
->pending_join_wps_method
) {
2372 case WPS_PIN_DISPLAY
:
2373 method
= WPS_CONFIG_KEYPAD
;
2375 case WPS_PIN_KEYPAD
:
2376 method
= WPS_CONFIG_DISPLAY
;
2379 method
= WPS_CONFIG_PUSHBUTTON
;
2386 if (p2p_prov_disc_req(wpa_s
->global
->p2p
,
2387 wpa_s
->pending_join_dev_addr
, method
, 1)
2389 wpa_printf(MSG_DEBUG
, "P2P: Failed to send Provision "
2390 "Discovery Request before joining an "
2392 wpa_s
->pending_pd_before_join
= 0;
2397 * Actual join operation will be started from the Action frame
2398 * TX status callback.
2403 wpa_printf(MSG_DEBUG
, "P2P: Target BSS/GO not yet in BSS table - "
2404 "cannot send Provision Discovery Request");
2407 /* Start join operation immediately */
2408 wpas_p2p_join_start(wpa_s
);
2412 static void wpas_p2p_join_scan(void *eloop_ctx
, void *timeout_ctx
)
2414 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
2416 struct wpa_driver_scan_params params
;
2417 struct wpabuf
*wps_ie
, *ies
;
2419 os_memset(¶ms
, 0, sizeof(params
));
2421 /* P2P Wildcard SSID */
2422 params
.num_ssids
= 1;
2423 params
.ssids
[0].ssid
= (u8
*) P2P_WILDCARD_SSID
;
2424 params
.ssids
[0].ssid_len
= P2P_WILDCARD_SSID_LEN
;
2426 wpa_s
->wps
->dev
.p2p
= 1;
2427 wps_ie
= wps_build_probe_req_ie(0, &wpa_s
->wps
->dev
, wpa_s
->wps
->uuid
,
2429 if (wps_ie
== NULL
) {
2430 wpas_p2p_scan_res_join(wpa_s
, NULL
);
2434 ies
= wpabuf_alloc(wpabuf_len(wps_ie
) + 100);
2436 wpabuf_free(wps_ie
);
2437 wpas_p2p_scan_res_join(wpa_s
, NULL
);
2440 wpabuf_put_buf(ies
, wps_ie
);
2441 wpabuf_free(wps_ie
);
2443 p2p_scan_ie(wpa_s
->global
->p2p
, ies
);
2445 params
.extra_ies
= wpabuf_head(ies
);
2446 params
.extra_ies_len
= wpabuf_len(ies
);
2449 * Run a scan to update BSS table and start Provision Discovery once
2450 * the new scan results become available.
2452 wpa_s
->scan_res_handler
= wpas_p2p_scan_res_join
;
2453 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_USER_SPACE_MLME
)
2454 ret
= ieee80211_sta_req_scan(wpa_s
, ¶ms
);
2456 ret
= wpa_drv_scan(wpa_s
, ¶ms
);
2461 wpa_printf(MSG_DEBUG
, "P2P: Failed to start scan for join - "
2463 eloop_cancel_timeout(wpas_p2p_join_scan
, wpa_s
, NULL
);
2464 eloop_register_timeout(1, 0, wpas_p2p_join_scan
, wpa_s
, NULL
);
2469 static int wpas_p2p_join(struct wpa_supplicant
*wpa_s
, const u8
*iface_addr
,
2470 const u8
*dev_addr
, enum p2p_wps_method wps_method
)
2472 wpa_printf(MSG_DEBUG
, "P2P: Request to join existing group (iface "
2473 MACSTR
" dev " MACSTR
")",
2474 MAC2STR(iface_addr
), MAC2STR(dev_addr
));
2476 os_memcpy(wpa_s
->pending_join_iface_addr
, iface_addr
, ETH_ALEN
);
2477 os_memcpy(wpa_s
->pending_join_dev_addr
, dev_addr
, ETH_ALEN
);
2478 wpa_s
->pending_join_wps_method
= wps_method
;
2480 /* Make sure we are not running find during connection establishment */
2481 wpas_p2p_stop_find(wpa_s
);
2483 wpas_p2p_join_scan(wpa_s
, NULL
);
2488 static int wpas_p2p_join_start(struct wpa_supplicant
*wpa_s
)
2490 struct wpa_supplicant
*group
;
2491 struct p2p_go_neg_results res
;
2493 group
= wpas_p2p_get_group_iface(wpa_s
, 0, 0);
2496 if (group
!= wpa_s
) {
2497 os_memcpy(group
->p2p_pin
, wpa_s
->p2p_pin
,
2498 sizeof(group
->p2p_pin
));
2499 group
->p2p_wps_method
= wpa_s
->p2p_wps_method
;
2502 group
->p2p_in_provisioning
= 1;
2504 os_memset(&res
, 0, sizeof(res
));
2505 os_memcpy(res
.peer_interface_addr
, wpa_s
->pending_join_iface_addr
,
2507 res
.wps_method
= wpa_s
->pending_join_wps_method
;
2508 wpas_start_wps_enrollee(group
, &res
);
2511 * Allow a longer timeout for join-a-running-group than normal 15
2512 * second group formation timeout since the GO may not have authorized
2513 * our connection yet.
2515 eloop_cancel_timeout(wpas_p2p_group_formation_timeout
, wpa_s
, NULL
);
2516 eloop_register_timeout(60, 0, wpas_p2p_group_formation_timeout
,
2524 * wpas_p2p_connect - Request P2P Group Formation to be started
2525 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
2526 * @peer_addr: Address of the peer P2P Device
2527 * @pin: PIN to use during provisioning or %NULL to indicate PBC mode
2528 * @persistent_group: Whether to create a persistent group
2529 * @join: Whether to join an existing group (as a client) instead of starting
2530 * Group Owner negotiation; @peer_addr is BSSID in that case
2531 * @auth: Whether to only authorize the connection instead of doing that and
2532 * initiating Group Owner negotiation
2533 * @go_intent: GO Intent or -1 to use default
2534 * @freq: Frequency for the group or 0 for auto-selection
2535 * Returns: 0 or new PIN (if pin was %NULL) on success, -1 on unspecified
2536 * failure, -2 on failure due to channel not currently available,
2537 * -3 if forced channel is not supported
2539 int wpas_p2p_connect(struct wpa_supplicant
*wpa_s
, const u8
*peer_addr
,
2540 const char *pin
, enum p2p_wps_method wps_method
,
2541 int persistent_group
, int join
, int auth
, int go_intent
,
2544 int force_freq
= 0, oper_freq
= 0;
2547 enum wpa_driver_if_type iftype
;
2550 go_intent
= wpa_s
->conf
->p2p_go_intent
;
2553 wpa_s
->p2p_long_listen
= 0;
2555 wpa_s
->p2p_wps_method
= wps_method
;
2558 os_strlcpy(wpa_s
->p2p_pin
, pin
, sizeof(wpa_s
->p2p_pin
));
2559 else if (wps_method
== WPS_PIN_DISPLAY
) {
2560 ret
= wps_generate_pin();
2561 os_snprintf(wpa_s
->p2p_pin
, sizeof(wpa_s
->p2p_pin
), "%08d",
2563 wpa_printf(MSG_DEBUG
, "P2P: Randomly generated PIN: %s",
2566 wpa_s
->p2p_pin
[0] = '\0';
2569 u8 iface_addr
[ETH_ALEN
], dev_addr
[ETH_ALEN
];
2571 wpa_printf(MSG_DEBUG
, "P2P: Authorize invitation to "
2572 "connect a running group from " MACSTR
,
2573 MAC2STR(peer_addr
));
2574 os_memcpy(wpa_s
->p2p_auth_invite
, peer_addr
, ETH_ALEN
);
2577 os_memcpy(dev_addr
, peer_addr
, ETH_ALEN
);
2578 if (p2p_get_interface_addr(wpa_s
->global
->p2p
, peer_addr
,
2580 os_memcpy(iface_addr
, peer_addr
, ETH_ALEN
);
2581 p2p_get_dev_addr(wpa_s
->global
->p2p
, peer_addr
,
2584 if (wpas_p2p_join(wpa_s
, iface_addr
, dev_addr
, wps_method
) <
2590 if (wpa_s
->current_ssid
&& wpa_drv_get_bssid(wpa_s
, bssid
) == 0 &&
2592 oper_freq
= wpa_s
->assoc_freq
;
2594 oper_freq
= wpa_drv_shared_freq(wpa_s
);
2600 if (!p2p_supported_freq(wpa_s
->global
->p2p
, freq
)) {
2601 wpa_printf(MSG_DEBUG
, "P2P: The forced channel "
2602 "(%u MHz) is not supported for P2P uses",
2607 if (oper_freq
> 0 && freq
!= oper_freq
&&
2608 !(wpa_s
->drv_flags
&
2609 WPA_DRIVER_FLAGS_MULTI_CHANNEL_CONCURRENT
)) {
2610 wpa_printf(MSG_DEBUG
, "P2P: Cannot start P2P group "
2611 "on %u MHz while connected on another "
2612 "channel (%u MHz)", freq
, oper_freq
);
2615 wpa_printf(MSG_DEBUG
, "P2P: Trying to force us to use the "
2616 "requested channel (%u MHz)", freq
);
2618 } else if (oper_freq
> 0 &&
2619 !p2p_supported_freq(wpa_s
->global
->p2p
, oper_freq
)) {
2620 if (!(wpa_s
->drv_flags
&
2621 WPA_DRIVER_FLAGS_MULTI_CHANNEL_CONCURRENT
)) {
2622 wpa_printf(MSG_DEBUG
, "P2P: Cannot start P2P group "
2623 "while connected on non-P2P supported "
2624 "channel (%u MHz)", oper_freq
);
2627 wpa_printf(MSG_DEBUG
, "P2P: Current operating channel "
2628 "(%u MHz) not available for P2P - try to use "
2629 "another channel", oper_freq
);
2631 } else if (oper_freq
> 0) {
2632 wpa_printf(MSG_DEBUG
, "P2P: Trying to force us to use the "
2633 "channel we are already using (%u MHz) on another "
2634 "interface", oper_freq
);
2635 force_freq
= oper_freq
;
2638 wpa_s
->create_p2p_iface
= wpas_p2p_create_iface(wpa_s
);
2640 if (!wpa_s
->create_p2p_iface
) {
2642 if (wpas_p2p_auth_go_neg(wpa_s
, peer_addr
, wps_method
,
2643 go_intent
, wpa_s
->own_addr
,
2644 force_freq
, persistent_group
)
2649 if (wpas_p2p_start_go_neg(wpa_s
, peer_addr
, wps_method
,
2650 go_intent
, wpa_s
->own_addr
,
2651 force_freq
, persistent_group
) < 0)
2656 /* Prepare to add a new interface for the group */
2657 iftype
= WPA_IF_P2P_GROUP
;
2659 iftype
= WPA_IF_P2P_CLIENT
;
2660 else if (go_intent
== 15)
2661 iftype
= WPA_IF_P2P_GO
;
2662 if (wpas_p2p_add_group_interface(wpa_s
, iftype
) < 0) {
2663 wpa_printf(MSG_ERROR
, "P2P: Failed to allocate a new "
2664 "interface for the group");
2669 if (wpas_p2p_auth_go_neg(wpa_s
, peer_addr
, wps_method
,
2671 wpa_s
->pending_interface_addr
,
2672 force_freq
, persistent_group
) < 0)
2676 if (wpas_p2p_start_go_neg(wpa_s
, peer_addr
, wps_method
, go_intent
,
2677 wpa_s
->pending_interface_addr
,
2678 force_freq
, persistent_group
) < 0) {
2679 wpas_p2p_remove_pending_group_interface(wpa_s
);
2687 * wpas_p2p_remain_on_channel_cb - Indication of remain-on-channel start
2688 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
2689 * @freq: Frequency of the channel in MHz
2690 * @duration: Duration of the stay on the channel in milliseconds
2692 * This callback is called when the driver indicates that it has started the
2693 * requested remain-on-channel duration.
2695 void wpas_p2p_remain_on_channel_cb(struct wpa_supplicant
*wpa_s
,
2696 unsigned int freq
, unsigned int duration
)
2698 wpa_s
->roc_waiting_drv_freq
= 0;
2699 wpa_s
->off_channel_freq
= freq
;
2700 wpas_send_action_cb(wpa_s
, NULL
);
2701 if (wpa_s
->off_channel_freq
== wpa_s
->pending_listen_freq
) {
2702 p2p_listen_cb(wpa_s
->global
->p2p
, wpa_s
->pending_listen_freq
,
2703 wpa_s
->pending_listen_duration
);
2704 wpa_s
->pending_listen_freq
= 0;
2709 static int wpas_p2p_listen_start(struct wpa_supplicant
*wpa_s
,
2710 unsigned int timeout
)
2712 /* Limit maximum Listen state time based on driver limitation. */
2713 if (timeout
> wpa_s
->max_remain_on_chan
)
2714 timeout
= wpa_s
->max_remain_on_chan
;
2716 return p2p_listen(wpa_s
->global
->p2p
, timeout
);
2721 * wpas_p2p_cancel_remain_on_channel_cb - Remain-on-channel timeout
2722 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
2723 * @freq: Frequency of the channel in MHz
2725 * This callback is called when the driver indicates that a remain-on-channel
2726 * operation has been completed, i.e., the duration on the requested channel
2729 void wpas_p2p_cancel_remain_on_channel_cb(struct wpa_supplicant
*wpa_s
,
2732 wpa_printf(MSG_DEBUG
, "P2P: Cancel remain-on-channel callback "
2733 "(p2p_long_listen=%d pending_action_tx=%p)",
2734 wpa_s
->p2p_long_listen
, wpa_s
->pending_action_tx
);
2735 wpa_s
->off_channel_freq
= 0;
2736 if (p2p_listen_end(wpa_s
->global
->p2p
, freq
) > 0)
2737 return; /* P2P module started a new operation */
2738 if (wpa_s
->pending_action_tx
)
2740 if (wpa_s
->p2p_long_listen
> 0)
2741 wpa_s
->p2p_long_listen
-= 5;
2742 if (wpa_s
->p2p_long_listen
> 0) {
2743 wpa_printf(MSG_DEBUG
, "P2P: Continuing long Listen state");
2744 wpas_p2p_listen_start(wpa_s
, wpa_s
->p2p_long_listen
* 1000);
2750 * wpas_p2p_group_remove - Remove a P2P group
2751 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
2752 * @ifname: Network interface name of the group interface or "*" to remove all
2754 * Returns: 0 on success, -1 on failure
2756 * This function is used to remove a P2P group. This can be used to disconnect
2757 * from a group in which the local end is a P2P Client or to end a P2P Group in
2758 * case the local end is the Group Owner. If a virtual network interface was
2759 * created for this group, that interface will be removed. Otherwise, only the
2760 * configured P2P group network will be removed from the interface.
2762 int wpas_p2p_group_remove(struct wpa_supplicant
*wpa_s
, const char *ifname
)
2764 struct wpa_global
*global
= wpa_s
->global
;
2766 if (os_strcmp(ifname
, "*") == 0) {
2767 struct wpa_supplicant
*prev
;
2768 wpa_s
= global
->ifaces
;
2771 wpa_s
= wpa_s
->next
;
2772 wpas_p2p_group_delete(prev
);
2777 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
2778 if (os_strcmp(wpa_s
->ifname
, ifname
) == 0)
2785 wpas_p2p_group_delete(wpa_s
);
2791 static void wpas_p2p_init_go_params(struct wpa_supplicant
*wpa_s
,
2792 struct p2p_go_neg_results
*params
,
2798 os_memset(params
, 0, sizeof(*params
));
2799 params
->role_go
= 1;
2800 params
->freq
= 2412;
2802 params
->freq
= freq
;
2803 else if (wpa_s
->conf
->p2p_oper_reg_class
== 81 &&
2804 wpa_s
->conf
->p2p_oper_channel
>= 1 &&
2805 wpa_s
->conf
->p2p_oper_channel
<= 11)
2806 params
->freq
= 2407 + 5 * wpa_s
->conf
->p2p_oper_channel
;
2807 else if (wpa_s
->conf
->p2p_oper_reg_class
== 115 ||
2808 wpa_s
->conf
->p2p_oper_reg_class
== 118)
2809 params
->freq
= 5000 + 5 * wpa_s
->conf
->p2p_oper_channel
;
2810 if (wpa_s
->current_ssid
&& wpa_drv_get_bssid(wpa_s
, bssid
) == 0 &&
2811 wpa_s
->assoc_freq
&& !freq
) {
2812 wpa_printf(MSG_DEBUG
, "P2P: Force GO on the channel we are "
2814 params
->freq
= wpa_s
->assoc_freq
;
2817 res
= wpa_drv_shared_freq(wpa_s
);
2818 if (res
> 0 && !freq
) {
2819 wpa_printf(MSG_DEBUG
, "P2P: Force GO on the channel we are "
2820 "already using on a shared interface");
2826 static struct wpa_supplicant
*
2827 wpas_p2p_get_group_iface(struct wpa_supplicant
*wpa_s
, int addr_allocated
,
2830 struct wpa_supplicant
*group_wpa_s
;
2832 if (!wpas_p2p_create_iface(wpa_s
))
2835 if (wpas_p2p_add_group_interface(wpa_s
, go
? WPA_IF_P2P_GO
:
2836 WPA_IF_P2P_CLIENT
) < 0)
2838 group_wpa_s
= wpas_p2p_init_group_interface(wpa_s
, go
);
2839 if (group_wpa_s
== NULL
) {
2840 wpas_p2p_remove_pending_group_interface(wpa_s
);
2849 * wpas_p2p_group_add - Add a new P2P group with local end as Group Owner
2850 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
2851 * @persistent_group: Whether to create a persistent group
2852 * @freq: Frequency for the group or 0 to indicate no hardcoding
2853 * Returns: 0 on success, -1 on failure
2855 * This function creates a new P2P group with the local end as the Group Owner,
2856 * i.e., without using Group Owner Negotiation.
2858 int wpas_p2p_group_add(struct wpa_supplicant
*wpa_s
, int persistent_group
,
2861 struct p2p_go_neg_results params
;
2863 if (freq
> 0 && !p2p_supported_freq(wpa_s
->global
->p2p
, freq
)) {
2864 wpa_printf(MSG_DEBUG
, "P2P: The forced channel for GO "
2865 "(%u MHz) is not supported for P2P uses",
2870 wpas_p2p_init_go_params(wpa_s
, ¶ms
, freq
);
2871 p2p_go_params(wpa_s
->global
->p2p
, ¶ms
);
2872 params
.persistent_group
= persistent_group
;
2874 wpa_s
= wpas_p2p_get_group_iface(wpa_s
, 0, 1);
2877 wpas_start_wps_go(wpa_s
, ¶ms
, 0);
2883 static int wpas_start_p2p_client(struct wpa_supplicant
*wpa_s
,
2884 struct wpa_ssid
*params
, int addr_allocated
)
2886 struct wpa_ssid
*ssid
;
2888 wpa_s
= wpas_p2p_get_group_iface(wpa_s
, addr_allocated
, 0);
2892 wpa_supplicant_ap_deinit(wpa_s
);
2894 ssid
= wpa_config_add_network(wpa_s
->conf
);
2897 wpas_notify_network_added(wpa_s
, ssid
);
2898 wpa_config_set_network_defaults(ssid
);
2899 ssid
->temporary
= 1;
2900 ssid
->proto
= WPA_PROTO_RSN
;
2901 ssid
->pairwise_cipher
= WPA_CIPHER_CCMP
;
2902 ssid
->group_cipher
= WPA_CIPHER_CCMP
;
2903 ssid
->key_mgmt
= WPA_KEY_MGMT_PSK
;
2904 ssid
->ssid
= os_malloc(params
->ssid_len
);
2905 if (ssid
->ssid
== NULL
) {
2906 wpas_notify_network_removed(wpa_s
, ssid
);
2907 wpa_config_remove_network(wpa_s
->conf
, ssid
->id
);
2910 os_memcpy(ssid
->ssid
, params
->ssid
, params
->ssid_len
);
2911 ssid
->ssid_len
= params
->ssid_len
;
2912 ssid
->p2p_group
= 1;
2913 if (params
->psk_set
) {
2914 os_memcpy(ssid
->psk
, params
->psk
, 32);
2917 if (params
->passphrase
)
2918 ssid
->passphrase
= os_strdup(params
->passphrase
);
2920 wpa_supplicant_select_network(wpa_s
, ssid
);
2922 wpa_s
->show_group_started
= 1;
2928 int wpas_p2p_group_add_persistent(struct wpa_supplicant
*wpa_s
,
2929 struct wpa_ssid
*ssid
, int addr_allocated
,
2932 struct p2p_go_neg_results params
;
2934 if (ssid
->disabled
!= 2 || ssid
->ssid
== NULL
)
2937 wpa_s
->p2p_long_listen
= 0;
2938 eloop_cancel_timeout(wpas_p2p_long_listen_timeout
, wpa_s
, NULL
);
2940 if (ssid
->mode
== WPAS_MODE_INFRA
)
2941 return wpas_start_p2p_client(wpa_s
, ssid
, addr_allocated
);
2943 if (ssid
->mode
!= WPAS_MODE_P2P_GO
)
2946 wpas_p2p_init_go_params(wpa_s
, ¶ms
, freq
);
2949 if (ssid
->passphrase
== NULL
||
2950 os_strlen(ssid
->passphrase
) >= sizeof(params
.passphrase
)) {
2951 wpa_printf(MSG_DEBUG
, "P2P: Invalid passphrase in persistent "
2955 os_strlcpy(params
.passphrase
, ssid
->passphrase
,
2956 sizeof(params
.passphrase
));
2957 os_memcpy(params
.ssid
, ssid
->ssid
, ssid
->ssid_len
);
2958 params
.ssid_len
= ssid
->ssid_len
;
2959 params
.persistent_group
= 1;
2961 wpa_s
= wpas_p2p_get_group_iface(wpa_s
, addr_allocated
, 1);
2965 wpas_start_wps_go(wpa_s
, ¶ms
, 0);
2971 static void wpas_p2p_ie_update(void *ctx
, struct wpabuf
*beacon_ies
,
2972 struct wpabuf
*proberesp_ies
)
2974 struct wpa_supplicant
*wpa_s
= ctx
;
2975 if (wpa_s
->ap_iface
) {
2976 struct hostapd_data
*hapd
= wpa_s
->ap_iface
->bss
[0];
2978 wpabuf_free(hapd
->p2p_beacon_ie
);
2979 hapd
->p2p_beacon_ie
= beacon_ies
;
2981 wpabuf_free(hapd
->p2p_probe_resp_ie
);
2982 hapd
->p2p_probe_resp_ie
= proberesp_ies
;
2984 wpabuf_free(beacon_ies
);
2985 wpabuf_free(proberesp_ies
);
2987 wpa_supplicant_ap_update_beacon(wpa_s
);
2991 struct p2p_group
* wpas_p2p_group_init(struct wpa_supplicant
*wpa_s
,
2992 int persistent_group
,
2993 int group_formation
)
2995 struct p2p_group
*group
;
2996 struct p2p_group_config
*cfg
;
2998 cfg
= os_zalloc(sizeof(*cfg
));
3002 cfg
->persistent_group
= persistent_group
;
3003 os_memcpy(cfg
->interface_addr
, wpa_s
->own_addr
, ETH_ALEN
);
3004 cfg
->cb_ctx
= wpa_s
;
3005 cfg
->ie_update
= wpas_p2p_ie_update
;
3007 group
= p2p_group_init(wpa_s
->global
->p2p
, cfg
);
3010 if (!group_formation
)
3011 p2p_group_notif_formation_done(group
);
3012 wpa_s
->p2p_group
= group
;
3017 void wpas_p2p_wps_success(struct wpa_supplicant
*wpa_s
, const u8
*peer_addr
,
3020 if (!wpa_s
->p2p_in_provisioning
) {
3021 wpa_printf(MSG_DEBUG
, "P2P: Ignore WPS success event - P2P "
3022 "provisioning not in progress");
3026 eloop_cancel_timeout(wpas_p2p_group_formation_timeout
, wpa_s
->parent
,
3028 if (wpa_s
->global
->p2p
)
3029 p2p_wps_success_cb(wpa_s
->global
->p2p
, peer_addr
);
3030 wpas_group_formation_completed(wpa_s
, 1);
3034 int wpas_p2p_prov_disc(struct wpa_supplicant
*wpa_s
, const u8
*peer_addr
,
3035 const char *config_method
)
3039 if (os_strcmp(config_method
, "display") == 0)
3040 config_methods
= WPS_CONFIG_DISPLAY
;
3041 else if (os_strcmp(config_method
, "keypad") == 0)
3042 config_methods
= WPS_CONFIG_KEYPAD
;
3043 else if (os_strcmp(config_method
, "pbc") == 0 ||
3044 os_strcmp(config_method
, "pushbutton") == 0)
3045 config_methods
= WPS_CONFIG_PUSHBUTTON
;
3049 if (wpa_s
->global
->p2p
== NULL
)
3052 return p2p_prov_disc_req(wpa_s
->global
->p2p
, peer_addr
,
3057 int wpas_p2p_scan_result_text(const u8
*ies
, size_t ies_len
, char *buf
,
3060 return p2p_scan_result_text(ies
, ies_len
, buf
, end
);
3064 static void wpas_p2p_clear_pending_action_tx(struct wpa_supplicant
*wpa_s
)
3066 if (!wpa_s
->pending_action_tx
)
3069 wpa_printf(MSG_DEBUG
, "P2P: Drop pending Action TX due to new "
3070 "operation request");
3071 wpabuf_free(wpa_s
->pending_action_tx
);
3072 wpa_s
->pending_action_tx
= NULL
;
3076 int wpas_p2p_find(struct wpa_supplicant
*wpa_s
, unsigned int timeout
,
3077 enum p2p_discovery_type type
)
3079 wpas_p2p_clear_pending_action_tx(wpa_s
);
3080 wpa_s
->p2p_long_listen
= 0;
3082 return p2p_find(wpa_s
->global
->p2p
, timeout
, type
);
3086 void wpas_p2p_stop_find(struct wpa_supplicant
*wpa_s
)
3088 wpas_p2p_clear_pending_action_tx(wpa_s
);
3089 wpa_s
->p2p_long_listen
= 0;
3090 eloop_cancel_timeout(wpas_p2p_join_scan
, wpa_s
, NULL
);
3092 p2p_stop_find(wpa_s
->global
->p2p
);
3094 wpas_p2p_remove_pending_group_interface(wpa_s
);
3098 static void wpas_p2p_long_listen_timeout(void *eloop_ctx
, void *timeout_ctx
)
3100 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
3101 wpa_s
->p2p_long_listen
= 0;
3105 int wpas_p2p_listen(struct wpa_supplicant
*wpa_s
, unsigned int timeout
)
3109 wpas_p2p_clear_pending_action_tx(wpa_s
);
3113 * This is a request for unlimited Listen state. However, at
3114 * least for now, this is mapped to a Listen state for one
3119 eloop_cancel_timeout(wpas_p2p_long_listen_timeout
, wpa_s
, NULL
);
3120 wpa_s
->p2p_long_listen
= 0;
3122 res
= wpas_p2p_listen_start(wpa_s
, timeout
* 1000);
3123 if (res
== 0 && timeout
* 1000 > wpa_s
->max_remain_on_chan
) {
3124 wpa_s
->p2p_long_listen
= timeout
;
3125 eloop_register_timeout(timeout
, 0,
3126 wpas_p2p_long_listen_timeout
,
3134 int wpas_p2p_assoc_req_ie(struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
,
3135 u8
*buf
, size_t len
, int p2p_group
)
3137 struct wpabuf
*p2p_ie
;
3140 if (wpa_s
->global
->p2p_disabled
)
3142 if (wpa_s
->global
->p2p
== NULL
)
3147 p2p_ie
= wpa_bss_get_vendor_ie_multi(bss
, P2P_IE_VENDOR_TYPE
);
3148 ret
= p2p_assoc_req_ie(wpa_s
->global
->p2p
, bss
->bssid
, buf
, len
,
3150 wpabuf_free(p2p_ie
);
3156 int wpas_p2p_probe_req_rx(struct wpa_supplicant
*wpa_s
, const u8
*addr
,
3157 const u8
*ie
, size_t ie_len
)
3159 if (wpa_s
->global
->p2p_disabled
)
3161 if (wpa_s
->global
->p2p
== NULL
)
3164 return p2p_probe_req_rx(wpa_s
->global
->p2p
, addr
, ie
, ie_len
);
3168 void wpas_p2p_rx_action(struct wpa_supplicant
*wpa_s
, const u8
*da
,
3169 const u8
*sa
, const u8
*bssid
,
3170 u8 category
, const u8
*data
, size_t len
, int freq
)
3172 if (wpa_s
->global
->p2p_disabled
)
3174 if (wpa_s
->global
->p2p
== NULL
)
3177 p2p_rx_action(wpa_s
->global
->p2p
, da
, sa
, bssid
, category
, data
, len
,
3182 void wpas_p2p_scan_ie(struct wpa_supplicant
*wpa_s
, struct wpabuf
*ies
)
3184 if (wpa_s
->global
->p2p_disabled
)
3186 if (wpa_s
->global
->p2p
== NULL
)
3189 p2p_scan_ie(wpa_s
->global
->p2p
, ies
);
3193 void wpas_p2p_group_deinit(struct wpa_supplicant
*wpa_s
)
3195 p2p_group_deinit(wpa_s
->p2p_group
);
3196 wpa_s
->p2p_group
= NULL
;
3200 int wpas_p2p_reject(struct wpa_supplicant
*wpa_s
, const u8
*addr
)
3202 wpa_s
->p2p_long_listen
= 0;
3204 return p2p_reject(wpa_s
->global
->p2p
, addr
);
3208 /* Invite to reinvoke a persistent group */
3209 int wpas_p2p_invite(struct wpa_supplicant
*wpa_s
, const u8
*peer_addr
,
3210 struct wpa_ssid
*ssid
, const u8
*go_dev_addr
)
3212 enum p2p_invite_role role
;
3215 if (ssid
->mode
== WPAS_MODE_P2P_GO
) {
3216 role
= P2P_INVITE_ROLE_GO
;
3217 if (peer_addr
== NULL
) {
3218 wpa_printf(MSG_DEBUG
, "P2P: Missing peer "
3219 "address in invitation command");
3222 if (wpas_p2p_create_iface(wpa_s
)) {
3223 if (wpas_p2p_add_group_interface(wpa_s
,
3224 WPA_IF_P2P_GO
) < 0) {
3225 wpa_printf(MSG_ERROR
, "P2P: Failed to "
3226 "allocate a new interface for the "
3230 bssid
= wpa_s
->pending_interface_addr
;
3232 bssid
= wpa_s
->own_addr
;
3234 role
= P2P_INVITE_ROLE_CLIENT
;
3235 peer_addr
= ssid
->bssid
;
3237 wpa_s
->pending_invite_ssid_id
= ssid
->id
;
3239 return p2p_invite(wpa_s
->global
->p2p
, peer_addr
, role
, bssid
,
3240 ssid
->ssid
, ssid
->ssid_len
, 0, go_dev_addr
, 1);
3244 /* Invite to join an active group */
3245 int wpas_p2p_invite_group(struct wpa_supplicant
*wpa_s
, const char *ifname
,
3246 const u8
*peer_addr
, const u8
*go_dev_addr
)
3248 struct wpa_global
*global
= wpa_s
->global
;
3249 enum p2p_invite_role role
;
3251 struct wpa_ssid
*ssid
;
3253 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
3254 if (os_strcmp(wpa_s
->ifname
, ifname
) == 0)
3257 if (wpa_s
== NULL
) {
3258 wpa_printf(MSG_DEBUG
, "P2P: Interface '%s' not found", ifname
);
3262 ssid
= wpa_s
->current_ssid
;
3264 wpa_printf(MSG_DEBUG
, "P2P: No current SSID to use for "
3269 if (ssid
->mode
== WPAS_MODE_P2P_GO
) {
3270 role
= P2P_INVITE_ROLE_ACTIVE_GO
;
3271 bssid
= wpa_s
->own_addr
;
3272 if (go_dev_addr
== NULL
)
3273 go_dev_addr
= wpa_s
->parent
->own_addr
;
3275 role
= P2P_INVITE_ROLE_CLIENT
;
3276 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
) {
3277 wpa_printf(MSG_DEBUG
, "P2P: Not associated - cannot "
3278 "invite to current group");
3281 bssid
= wpa_s
->bssid
;
3282 if (go_dev_addr
== NULL
&&
3283 !is_zero_ether_addr(wpa_s
->go_dev_addr
))
3284 go_dev_addr
= wpa_s
->go_dev_addr
;
3286 wpa_s
->pending_invite_ssid_id
= -1;
3288 return p2p_invite(wpa_s
->global
->p2p
, peer_addr
, role
, bssid
,
3289 ssid
->ssid
, ssid
->ssid_len
, wpa_s
->assoc_freq
,
3294 void wpas_p2p_completed(struct wpa_supplicant
*wpa_s
)
3296 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
3297 const char *ssid_txt
;
3298 u8 go_dev_addr
[ETH_ALEN
];
3301 if (!wpa_s
->show_group_started
|| !ssid
)
3304 wpa_s
->show_group_started
= 0;
3306 ssid_txt
= wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
);
3307 os_memset(go_dev_addr
, 0, ETH_ALEN
);
3308 if (ssid
->bssid_set
)
3309 os_memcpy(go_dev_addr
, ssid
->bssid
, ETH_ALEN
);
3310 persistent
= wpas_p2p_persistent_group(wpa_s
, go_dev_addr
, ssid
->ssid
,
3312 os_memcpy(wpa_s
->go_dev_addr
, go_dev_addr
, ETH_ALEN
);
3314 if (ssid
->passphrase
== NULL
&& ssid
->psk_set
) {
3316 wpa_snprintf_hex(psk
, sizeof(psk
), ssid
->psk
, 32);
3317 wpa_msg(wpa_s
->parent
, MSG_INFO
, P2P_EVENT_GROUP_STARTED
3318 "%s client ssid=\"%s\" freq=%d psk=%s go_dev_addr="
3320 wpa_s
->ifname
, ssid_txt
, ssid
->frequency
, psk
,
3321 MAC2STR(go_dev_addr
),
3322 persistent
? " [PERSISTENT]" : "");
3324 wpa_msg(wpa_s
->parent
, MSG_INFO
, P2P_EVENT_GROUP_STARTED
3325 "%s client ssid=\"%s\" freq=%d passphrase=\"%s\" "
3326 "go_dev_addr=" MACSTR
"%s",
3327 wpa_s
->ifname
, ssid_txt
, ssid
->frequency
,
3328 ssid
->passphrase
? ssid
->passphrase
: "",
3329 MAC2STR(go_dev_addr
),
3330 persistent
? " [PERSISTENT]" : "");
3334 wpas_p2p_store_persistent_group(wpa_s
->parent
, ssid
,
3339 int wpas_p2p_presence_req(struct wpa_supplicant
*wpa_s
, u32 duration1
,
3340 u32 interval1
, u32 duration2
, u32 interval2
)
3342 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
||
3343 wpa_s
->current_ssid
== NULL
||
3344 wpa_s
->current_ssid
->mode
!= WPAS_MODE_INFRA
)
3347 return p2p_presence_req(wpa_s
->global
->p2p
, wpa_s
->bssid
,
3348 wpa_s
->own_addr
, wpa_s
->assoc_freq
,
3349 duration1
, interval1
, duration2
, interval2
);
3353 int wpas_p2p_ext_listen(struct wpa_supplicant
*wpa_s
, unsigned int period
,
3354 unsigned int interval
)
3356 return p2p_ext_listen(wpa_s
->global
->p2p
, period
, interval
);
3360 void wpas_p2p_deauth_notif(struct wpa_supplicant
*wpa_s
, const u8
*bssid
,
3361 u16 reason_code
, const u8
*ie
, size_t ie_len
)
3363 if (wpa_s
->global
->p2p_disabled
)
3366 p2p_deauth_notif(wpa_s
->global
->p2p
, bssid
, reason_code
, ie
, ie_len
);
3370 void wpas_p2p_disassoc_notif(struct wpa_supplicant
*wpa_s
, const u8
*bssid
,
3371 u16 reason_code
, const u8
*ie
, size_t ie_len
)
3373 if (wpa_s
->global
->p2p_disabled
)
3376 p2p_disassoc_notif(wpa_s
->global
->p2p
, bssid
, reason_code
, ie
, ie_len
);
3380 void wpas_p2p_update_config(struct wpa_supplicant
*wpa_s
)
3382 struct p2p_data
*p2p
= wpa_s
->global
->p2p
;
3387 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_CAPABLE
))
3390 if (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_DEVICE_NAME
)
3391 p2p_set_dev_name(p2p
, wpa_s
->conf
->device_name
);
3393 if (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_DEVICE_TYPE
) {
3395 if (wpa_s
->conf
->device_type
) {
3396 if (wps_dev_type_str2bin(wpa_s
->conf
->device_type
,
3397 pri_dev_type
) < 0) {
3398 wpa_printf(MSG_ERROR
, "P2P: Invalid "
3401 p2p_set_pri_dev_type(p2p
, pri_dev_type
);
3405 if (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_SEC_DEVICE_TYPE
) {
3406 u8 sec_dev_type
[P2P_SEC_DEVICE_TYPES
][8];
3409 for (i
= 0; i
< MAX_SEC_DEVICE_TYPES
; i
++) {
3410 if (wpa_s
->conf
->sec_device_type
[i
] == NULL
)
3412 if (wps_dev_type_str2bin(
3413 wpa_s
->conf
->sec_device_type
[i
],
3414 sec_dev_type
[num
]) < 0) {
3415 wpa_printf(MSG_ERROR
, "P2P: Invalid "
3420 if (num
== P2P_SEC_DEVICE_TYPES
)
3423 p2p_set_sec_dev_types(p2p
, (void *) sec_dev_type
, num
);
3426 if ((wpa_s
->conf
->changed_parameters
& CFG_CHANGED_COUNTRY
) &&
3427 wpa_s
->conf
->country
[0] && wpa_s
->conf
->country
[1]) {
3429 country
[0] = wpa_s
->conf
->country
[0];
3430 country
[1] = wpa_s
->conf
->country
[1];
3432 p2p_set_country(p2p
, country
);
3435 if (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_P2P_SSID_POSTFIX
) {
3436 p2p_set_ssid_postfix(p2p
, (u8
*) wpa_s
->conf
->p2p_ssid_postfix
,
3437 wpa_s
->conf
->p2p_ssid_postfix
?
3438 os_strlen(wpa_s
->conf
->p2p_ssid_postfix
) :
3442 if (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_P2P_INTRA_BSS
)
3443 p2p_set_intra_bss_dist(p2p
, wpa_s
->conf
->p2p_intra_bss
);
3447 int wpas_p2p_set_noa(struct wpa_supplicant
*wpa_s
, u8 count
, int start
,
3450 if (!wpa_s
->ap_iface
)
3452 return hostapd_p2p_set_noa(wpa_s
->ap_iface
->bss
[0], count
, start
,
3457 int wpas_p2p_set_cross_connect(struct wpa_supplicant
*wpa_s
, int enabled
)
3459 if (wpa_s
->global
->p2p_disabled
)
3461 if (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_MGMT
)
3464 wpa_s
->global
->cross_connection
= enabled
;
3465 p2p_set_cross_connect(wpa_s
->global
->p2p
, enabled
);
3468 struct wpa_supplicant
*iface
;
3470 for (iface
= wpa_s
->global
->ifaces
; iface
; iface
= iface
->next
)
3472 if (iface
->cross_connect_enabled
== 0)
3475 iface
->cross_connect_enabled
= 0;
3476 iface
->cross_connect_in_use
= 0;
3477 wpa_msg(iface
->parent
, MSG_INFO
,
3478 P2P_EVENT_CROSS_CONNECT_DISABLE
"%s %s",
3479 iface
->ifname
, iface
->cross_connect_uplink
);
3487 static void wpas_p2p_enable_cross_connect(struct wpa_supplicant
*uplink
)
3489 struct wpa_supplicant
*iface
;
3491 if (!uplink
->global
->cross_connection
)
3494 for (iface
= uplink
->global
->ifaces
; iface
; iface
= iface
->next
) {
3495 if (!iface
->cross_connect_enabled
)
3497 if (os_strcmp(uplink
->ifname
, iface
->cross_connect_uplink
) !=
3500 if (iface
->ap_iface
== NULL
)
3502 if (iface
->cross_connect_in_use
)
3505 iface
->cross_connect_in_use
= 1;
3506 wpa_msg(iface
->parent
, MSG_INFO
,
3507 P2P_EVENT_CROSS_CONNECT_ENABLE
"%s %s",
3508 iface
->ifname
, iface
->cross_connect_uplink
);
3513 static void wpas_p2p_disable_cross_connect(struct wpa_supplicant
*uplink
)
3515 struct wpa_supplicant
*iface
;
3517 for (iface
= uplink
->global
->ifaces
; iface
; iface
= iface
->next
) {
3518 if (!iface
->cross_connect_enabled
)
3520 if (os_strcmp(uplink
->ifname
, iface
->cross_connect_uplink
) !=
3523 if (!iface
->cross_connect_in_use
)
3526 wpa_msg(iface
->parent
, MSG_INFO
,
3527 P2P_EVENT_CROSS_CONNECT_DISABLE
"%s %s",
3528 iface
->ifname
, iface
->cross_connect_uplink
);
3529 iface
->cross_connect_in_use
= 0;
3534 void wpas_p2p_notif_connected(struct wpa_supplicant
*wpa_s
)
3536 if (wpa_s
->ap_iface
|| wpa_s
->current_ssid
== NULL
||
3537 wpa_s
->current_ssid
->mode
!= WPAS_MODE_INFRA
||
3538 wpa_s
->cross_connect_disallowed
)
3539 wpas_p2p_disable_cross_connect(wpa_s
);
3541 wpas_p2p_enable_cross_connect(wpa_s
);
3545 void wpas_p2p_notif_disconnected(struct wpa_supplicant
*wpa_s
)
3547 wpas_p2p_disable_cross_connect(wpa_s
);
3551 static void wpas_p2p_cross_connect_setup(struct wpa_supplicant
*wpa_s
)
3553 struct wpa_supplicant
*iface
;
3555 if (!wpa_s
->global
->cross_connection
)
3558 for (iface
= wpa_s
->global
->ifaces
; iface
; iface
= iface
->next
) {
3561 if (iface
->drv_flags
&
3562 WPA_DRIVER_FLAGS_P2P_DEDICATED_INTERFACE
)
3564 if (iface
->drv_flags
& WPA_DRIVER_FLAGS_P2P_CAPABLE
)
3567 wpa_s
->cross_connect_enabled
= 1;
3568 os_strlcpy(wpa_s
->cross_connect_uplink
, iface
->ifname
,
3569 sizeof(wpa_s
->cross_connect_uplink
));
3570 wpa_printf(MSG_DEBUG
, "P2P: Enable cross connection from "
3571 "%s to %s whenever uplink is available",
3572 wpa_s
->ifname
, wpa_s
->cross_connect_uplink
);
3574 if (iface
->ap_iface
|| iface
->current_ssid
== NULL
||
3575 iface
->current_ssid
->mode
!= WPAS_MODE_INFRA
||
3576 iface
->cross_connect_disallowed
||
3577 iface
->wpa_state
!= WPA_COMPLETED
)
3580 wpa_s
->cross_connect_in_use
= 1;
3581 wpa_msg(wpa_s
->parent
, MSG_INFO
,
3582 P2P_EVENT_CROSS_CONNECT_ENABLE
"%s %s",
3583 wpa_s
->ifname
, wpa_s
->cross_connect_uplink
);
3589 int wpas_p2p_notif_pbc_overlap(struct wpa_supplicant
*wpa_s
)
3591 if (wpa_s
->p2p_group_interface
!= P2P_GROUP_INTERFACE_CLIENT
&&
3592 !wpa_s
->p2p_in_provisioning
)
3593 return 0; /* not P2P client operation */
3595 wpa_printf(MSG_DEBUG
, "P2P: Terminate connection due to WPS PBC "
3597 wpas_group_formation_completed(wpa_s
, 0);