3 * Copyright (c) 2009-2010, Atheros Communications
4 * Copyright (c) 2010-2014, Jouni Malinen <j@w1.fi>
6 * This software may be distributed under the terms of the BSD license.
7 * See README for more details.
14 #include "common/ieee802_11_common.h"
15 #include "common/ieee802_11_defs.h"
16 #include "common/wpa_ctrl.h"
17 #include "wps/wps_i.h"
19 #include "ap/hostapd.h"
20 #include "ap/ap_config.h"
21 #include "ap/sta_info.h"
22 #include "ap/ap_drv_ops.h"
23 #include "ap/wps_hostapd.h"
24 #include "ap/p2p_hostapd.h"
26 #include "eapol_supp/eapol_supp_sm.h"
27 #include "rsn_supp/wpa.h"
28 #include "wpa_supplicant_i.h"
31 #include "config_ssid.h"
36 #include "offchannel.h"
37 #include "wps_supplicant.h"
38 #include "p2p_supplicant.h"
39 #include "wifi_display.h"
43 * How many times to try to scan to find the GO before giving up on join
46 #define P2P_MAX_JOIN_SCAN_ATTEMPTS 10
48 #define P2P_AUTO_PD_SCAN_ATTEMPTS 5
51 * Defines time interval in seconds when a GO needs to evacuate a frequency that
52 * it is currently using, but is no longer valid for P2P use cases.
54 #define P2P_GO_FREQ_CHANGE_TIME 5
57 * Defines CSA parameters which are used when GO evacuates the no longer valid
58 * channel (and if the driver supports channel switch).
60 #define P2P_GO_CSA_COUNT 7
61 #define P2P_GO_CSA_BLOCK_TX 0
63 #ifndef P2P_MAX_CLIENT_IDLE
65 * How many seconds to try to reconnect to the GO when connection in P2P client
68 #define P2P_MAX_CLIENT_IDLE 10
69 #endif /* P2P_MAX_CLIENT_IDLE */
71 #ifndef P2P_MAX_INITIAL_CONN_WAIT
73 * How many seconds to wait for initial 4-way handshake to get completed after
74 * WPS provisioning step or after the re-invocation of a persistent group on a
77 #define P2P_MAX_INITIAL_CONN_WAIT 10
78 #endif /* P2P_MAX_INITIAL_CONN_WAIT */
80 #ifndef P2P_MAX_INITIAL_CONN_WAIT_GO
82 * How many seconds to wait for initial 4-way handshake to get completed after
83 * WPS provisioning step on the GO. This controls the extra time the P2P
84 * operation is considered to be in progress (e.g., to delay other scans) after
85 * WPS provisioning has been completed on the GO during group formation.
87 #define P2P_MAX_INITIAL_CONN_WAIT_GO 10
88 #endif /* P2P_MAX_INITIAL_CONN_WAIT_GO */
90 #ifndef P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE
92 * How many seconds to wait for initial 4-way handshake to get completed after
93 * re-invocation of a persistent group on the GO when the client is expected
94 * to connect automatically (no user interaction).
96 #define P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE 15
97 #endif /* P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE */
99 #define P2P_MGMT_DEVICE_PREFIX "p2p-dev-"
102 * How many seconds to wait to re-attempt to move GOs, in case previous attempt
105 #define P2P_RECONSIDER_GO_MOVE_DELAY 30
107 enum p2p_group_removal_reason
{
108 P2P_GROUP_REMOVAL_UNKNOWN
,
109 P2P_GROUP_REMOVAL_SILENT
,
110 P2P_GROUP_REMOVAL_FORMATION_FAILED
,
111 P2P_GROUP_REMOVAL_REQUESTED
,
112 P2P_GROUP_REMOVAL_IDLE_TIMEOUT
,
113 P2P_GROUP_REMOVAL_UNAVAILABLE
,
114 P2P_GROUP_REMOVAL_GO_ENDING_SESSION
,
115 P2P_GROUP_REMOVAL_PSK_FAILURE
,
116 P2P_GROUP_REMOVAL_FREQ_CONFLICT
,
117 P2P_GROUP_REMOVAL_GO_LEAVE_CHANNEL
121 static void wpas_p2p_long_listen_timeout(void *eloop_ctx
, void *timeout_ctx
);
122 static struct wpa_supplicant
*
123 wpas_p2p_get_group_iface(struct wpa_supplicant
*wpa_s
, int addr_allocated
,
125 static int wpas_p2p_join_start(struct wpa_supplicant
*wpa_s
, int freq
,
126 const u8
*ssid
, size_t ssid_len
);
127 static int wpas_p2p_setup_freqs(struct wpa_supplicant
*wpa_s
, int freq
,
128 int *force_freq
, int *pref_freq
, int go
,
129 unsigned int *pref_freq_list
,
130 unsigned int *num_pref_freq
);
131 static void wpas_p2p_join_scan_req(struct wpa_supplicant
*wpa_s
, int freq
,
132 const u8
*ssid
, size_t ssid_len
);
133 static void wpas_p2p_join_scan(void *eloop_ctx
, void *timeout_ctx
);
134 static int wpas_p2p_join(struct wpa_supplicant
*wpa_s
, const u8
*iface_addr
,
135 const u8
*dev_addr
, enum p2p_wps_method wps_method
,
136 int auto_join
, int freq
,
137 const u8
*ssid
, size_t ssid_len
);
138 static int wpas_p2p_create_iface(struct wpa_supplicant
*wpa_s
);
139 static void wpas_p2p_cross_connect_setup(struct wpa_supplicant
*wpa_s
);
140 static void wpas_p2p_group_idle_timeout(void *eloop_ctx
, void *timeout_ctx
);
141 static void wpas_p2p_set_group_idle_timeout(struct wpa_supplicant
*wpa_s
);
142 static void wpas_p2p_group_formation_timeout(void *eloop_ctx
,
144 static void wpas_p2p_group_freq_conflict(void *eloop_ctx
, void *timeout_ctx
);
145 static int wpas_p2p_fallback_to_go_neg(struct wpa_supplicant
*wpa_s
,
147 static void wpas_p2p_stop_find_oper(struct wpa_supplicant
*wpa_s
);
148 static void wpas_stop_listen(void *ctx
);
149 static void wpas_p2p_psk_failure_removal(void *eloop_ctx
, void *timeout_ctx
);
150 static void wpas_p2p_group_deinit(struct wpa_supplicant
*wpa_s
);
151 static int wpas_p2p_add_group_interface(struct wpa_supplicant
*wpa_s
,
152 enum wpa_driver_if_type type
);
153 static void wpas_p2p_group_formation_failed(struct wpa_supplicant
*wpa_s
,
154 int already_deleted
);
155 static void wpas_p2p_optimize_listen_channel(struct wpa_supplicant
*wpa_s
,
156 struct wpa_used_freq_data
*freqs
,
158 static void wpas_p2p_move_go(void *eloop_ctx
, void *timeout_ctx
);
159 static int wpas_p2p_go_is_peer_freq(struct wpa_supplicant
*wpa_s
, int freq
);
161 wpas_p2p_consider_moving_gos(struct wpa_supplicant
*wpa_s
,
162 struct wpa_used_freq_data
*freqs
, unsigned int num
,
163 enum wpas_p2p_channel_update_trig trig
);
164 static void wpas_p2p_reconsider_moving_go(void *eloop_ctx
, void *timeout_ctx
);
168 * Get the number of concurrent channels that the HW can operate, but that are
169 * currently not in use by any of the wpa_supplicant interfaces.
171 static int wpas_p2p_num_unused_channels(struct wpa_supplicant
*wpa_s
)
176 freqs
= os_calloc(wpa_s
->num_multichan_concurrent
, sizeof(int));
180 num
= get_shared_radio_freqs(wpa_s
, freqs
,
181 wpa_s
->num_multichan_concurrent
);
184 unused
= wpa_s
->num_multichan_concurrent
- num
;
185 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: num_unused_channels: %d", unused
);
191 * Get the frequencies that are currently in use by one or more of the virtual
192 * interfaces, and that are also valid for P2P operation.
195 wpas_p2p_valid_oper_freqs(struct wpa_supplicant
*wpa_s
,
196 struct wpa_used_freq_data
*p2p_freqs
,
199 struct wpa_used_freq_data
*freqs
;
200 unsigned int num
, i
, j
;
202 freqs
= os_calloc(wpa_s
->num_multichan_concurrent
,
203 sizeof(struct wpa_used_freq_data
));
207 num
= get_shared_radio_freqs_data(wpa_s
, freqs
,
208 wpa_s
->num_multichan_concurrent
);
210 os_memset(p2p_freqs
, 0, sizeof(struct wpa_used_freq_data
) * len
);
212 for (i
= 0, j
= 0; i
< num
&& j
< len
; i
++) {
213 if (p2p_supported_freq(wpa_s
->global
->p2p
, freqs
[i
].freq
))
214 p2p_freqs
[j
++] = freqs
[i
];
219 dump_freq_data(wpa_s
, "valid for P2P", p2p_freqs
, j
);
225 static void wpas_p2p_set_own_freq_preference(struct wpa_supplicant
*wpa_s
,
228 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
231 /* Use the wpa_s used to control the P2P Device operation */
232 wpa_s
= wpa_s
->global
->p2p_init_wpa_s
;
234 if (wpa_s
->conf
->p2p_ignore_shared_freq
&&
235 freq
> 0 && wpa_s
->num_multichan_concurrent
> 1 &&
236 wpas_p2p_num_unused_channels(wpa_s
) > 0) {
237 wpa_printf(MSG_DEBUG
, "P2P: Ignore own channel preference %d MHz due to p2p_ignore_shared_freq=1 configuration",
241 p2p_set_own_freq_preference(wpa_s
->global
->p2p
, freq
);
245 static void wpas_p2p_scan_res_handler(struct wpa_supplicant
*wpa_s
,
246 struct wpa_scan_results
*scan_res
)
250 if (wpa_s
->p2p_scan_work
) {
251 struct wpa_radio_work
*work
= wpa_s
->p2p_scan_work
;
252 wpa_s
->p2p_scan_work
= NULL
;
253 radio_work_done(work
);
256 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
259 wpa_printf(MSG_DEBUG
, "P2P: Scan results received (%d BSS)",
260 (int) scan_res
->num
);
262 for (i
= 0; i
< scan_res
->num
; i
++) {
263 struct wpa_scan_res
*bss
= scan_res
->res
[i
];
264 struct os_reltime time_tmp_age
, entry_ts
;
268 time_tmp_age
.sec
= bss
->age
/ 1000;
269 time_tmp_age
.usec
= (bss
->age
% 1000) * 1000;
270 os_reltime_sub(&scan_res
->fetch_time
, &time_tmp_age
, &entry_ts
);
272 ies
= (const u8
*) (bss
+ 1);
273 ies_len
= bss
->ie_len
;
274 if (bss
->beacon_ie_len
> 0 &&
275 !wpa_scan_get_vendor_ie(bss
, P2P_IE_VENDOR_TYPE
) &&
276 wpa_scan_get_vendor_ie_beacon(bss
, P2P_IE_VENDOR_TYPE
)) {
277 wpa_printf(MSG_DEBUG
, "P2P: Use P2P IE(s) from Beacon frame since no P2P IE(s) in Probe Response frames received for "
278 MACSTR
, MAC2STR(bss
->bssid
));
280 ies_len
= bss
->beacon_ie_len
;
284 if (p2p_scan_res_handler(wpa_s
->global
->p2p
, bss
->bssid
,
285 bss
->freq
, &entry_ts
, bss
->level
,
290 p2p_scan_res_handled(wpa_s
->global
->p2p
);
294 static void wpas_p2p_trigger_scan_cb(struct wpa_radio_work
*work
, int deinit
)
296 struct wpa_supplicant
*wpa_s
= work
->wpa_s
;
297 struct wpa_driver_scan_params
*params
= work
->ctx
;
301 if (!work
->started
) {
302 wpa_scan_free_params(params
);
306 wpa_s
->p2p_scan_work
= NULL
;
310 if (wpa_s
->clear_driver_scan_cache
) {
311 wpa_printf(MSG_DEBUG
,
312 "Request driver to clear scan cache due to local BSS flush");
313 params
->only_new_results
= 1;
315 ret
= wpa_drv_scan(wpa_s
, params
);
317 wpa_s
->curr_scan_cookie
= params
->scan_cookie
;
318 wpa_scan_free_params(params
);
321 radio_work_done(work
);
322 p2p_notify_scan_trigger_status(wpa_s
->global
->p2p
, ret
);
326 p2p_notify_scan_trigger_status(wpa_s
->global
->p2p
, ret
);
327 os_get_reltime(&wpa_s
->scan_trigger_time
);
328 wpa_s
->scan_res_handler
= wpas_p2p_scan_res_handler
;
329 wpa_s
->own_scan_requested
= 1;
330 wpa_s
->clear_driver_scan_cache
= 0;
331 wpa_s
->p2p_scan_work
= work
;
335 static int wpas_p2p_search_social_channel(struct wpa_supplicant
*wpa_s
,
338 if (wpa_s
->global
->p2p_24ghz_social_channels
&&
339 (freq
== 2412 || freq
== 2437 || freq
== 2462)) {
341 * Search all social channels regardless of whether these have
342 * been disabled for P2P operating channel use to avoid missing
347 return p2p_supported_freq(wpa_s
->global
->p2p
, freq
);
351 static int wpas_p2p_scan(void *ctx
, enum p2p_scan_type type
, int freq
,
352 unsigned int num_req_dev_types
,
353 const u8
*req_dev_types
, const u8
*dev_id
, u16 pw_id
)
355 struct wpa_supplicant
*wpa_s
= ctx
;
356 struct wpa_driver_scan_params
*params
= NULL
;
357 struct wpabuf
*wps_ie
, *ies
;
358 unsigned int num_channels
= 0;
359 int social_channels_freq
[] = { 2412, 2437, 2462, 60480 };
364 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
367 if (wpa_s
->p2p_scan_work
) {
368 wpa_dbg(wpa_s
, MSG_INFO
, "P2P: Reject scan trigger since one is already pending");
372 params
= os_zalloc(sizeof(*params
));
376 /* P2P Wildcard SSID */
377 params
->num_ssids
= 1;
378 n
= os_malloc(P2P_WILDCARD_SSID_LEN
);
381 os_memcpy(n
, P2P_WILDCARD_SSID
, P2P_WILDCARD_SSID_LEN
);
382 params
->ssids
[0].ssid
= n
;
383 params
->ssids
[0].ssid_len
= P2P_WILDCARD_SSID_LEN
;
385 wpa_s
->wps
->dev
.p2p
= 1;
386 wps_ie
= wps_build_probe_req_ie(pw_id
, &wpa_s
->wps
->dev
,
387 wpa_s
->wps
->uuid
, WPS_REQ_ENROLLEE
,
388 num_req_dev_types
, req_dev_types
);
393 case P2P_SCAN_SOCIAL
:
394 params
->freqs
= os_calloc(ARRAY_SIZE(social_channels_freq
) + 1,
396 if (params
->freqs
== NULL
)
398 for (i
= 0; i
< ARRAY_SIZE(social_channels_freq
); i
++) {
399 if (wpas_p2p_search_social_channel(
400 wpa_s
, social_channels_freq
[i
]))
401 params
->freqs
[num_channels
++] =
402 social_channels_freq
[i
];
404 params
->freqs
[num_channels
++] = 0;
408 case P2P_SCAN_SPECIFIC
:
409 params
->freqs
= os_calloc(2, sizeof(int));
410 if (params
->freqs
== NULL
)
412 params
->freqs
[0] = freq
;
413 params
->freqs
[1] = 0;
415 case P2P_SCAN_SOCIAL_PLUS_ONE
:
416 params
->freqs
= os_calloc(ARRAY_SIZE(social_channels_freq
) + 2,
418 if (params
->freqs
== NULL
)
420 for (i
= 0; i
< ARRAY_SIZE(social_channels_freq
); i
++) {
421 if (wpas_p2p_search_social_channel(
422 wpa_s
, social_channels_freq
[i
]))
423 params
->freqs
[num_channels
++] =
424 social_channels_freq
[i
];
426 if (p2p_supported_freq(wpa_s
->global
->p2p
, freq
))
427 params
->freqs
[num_channels
++] = freq
;
428 params
->freqs
[num_channels
++] = 0;
432 ielen
= p2p_scan_ie_buf_len(wpa_s
->global
->p2p
);
433 ies
= wpabuf_alloc(wpabuf_len(wps_ie
) + ielen
);
438 wpabuf_put_buf(ies
, wps_ie
);
441 bands
= wpas_get_bands(wpa_s
, params
->freqs
);
442 p2p_scan_ie(wpa_s
->global
->p2p
, ies
, dev_id
, bands
);
444 params
->p2p_probe
= 1;
445 n
= os_malloc(wpabuf_len(ies
));
450 os_memcpy(n
, wpabuf_head(ies
), wpabuf_len(ies
));
451 params
->extra_ies
= n
;
452 params
->extra_ies_len
= wpabuf_len(ies
);
455 radio_remove_works(wpa_s
, "p2p-scan", 0);
456 if (radio_add_work(wpa_s
, 0, "p2p-scan", 0, wpas_p2p_trigger_scan_cb
,
462 wpa_scan_free_params(params
);
467 static enum wpa_driver_if_type
wpas_p2p_if_type(int p2p_group_interface
)
469 switch (p2p_group_interface
) {
470 case P2P_GROUP_INTERFACE_PENDING
:
471 return WPA_IF_P2P_GROUP
;
472 case P2P_GROUP_INTERFACE_GO
:
473 return WPA_IF_P2P_GO
;
474 case P2P_GROUP_INTERFACE_CLIENT
:
475 return WPA_IF_P2P_CLIENT
;
478 return WPA_IF_P2P_GROUP
;
482 static struct wpa_supplicant
* wpas_get_p2p_group(struct wpa_supplicant
*wpa_s
,
484 size_t ssid_len
, int *go
)
488 for (wpa_s
= wpa_s
->global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
489 for (s
= wpa_s
->conf
->ssid
; s
; s
= s
->next
) {
490 if (s
->disabled
!= 0 || !s
->p2p_group
||
491 s
->ssid_len
!= ssid_len
||
492 os_memcmp(ssid
, s
->ssid
, ssid_len
) != 0)
494 if (s
->mode
== WPAS_MODE_P2P_GO
&&
495 s
!= wpa_s
->current_ssid
)
498 *go
= s
->mode
== WPAS_MODE_P2P_GO
;
507 static void run_wpas_p2p_disconnect(void *eloop_ctx
, void *timeout_ctx
)
509 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
510 wpa_printf(MSG_DEBUG
,
511 "P2P: Complete previously requested removal of %s",
513 wpas_p2p_disconnect(wpa_s
);
517 static int wpas_p2p_disconnect_safely(struct wpa_supplicant
*wpa_s
,
518 struct wpa_supplicant
*calling_wpa_s
)
520 if (calling_wpa_s
== wpa_s
&& wpa_s
&&
521 wpa_s
->p2p_group_interface
!= NOT_P2P_GROUP_INTERFACE
) {
523 * The calling wpa_s instance is going to be removed. Do that
524 * from an eloop callback to keep the instance available until
525 * the caller has returned. This my be needed, e.g., to provide
526 * control interface responses on the per-interface socket.
528 if (eloop_register_timeout(0, 0, run_wpas_p2p_disconnect
,
534 return wpas_p2p_disconnect(wpa_s
);
538 /* Determine total number of clients in active groups where we are the GO */
539 static unsigned int p2p_group_go_member_count(struct wpa_supplicant
*wpa_s
)
541 unsigned int count
= 0;
544 for (wpa_s
= wpa_s
->global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
545 for (s
= wpa_s
->conf
->ssid
; s
; s
= s
->next
) {
546 wpa_printf(MSG_DEBUG
,
547 "P2P: sup:%p ssid:%p disabled:%d p2p:%d mode:%d",
548 wpa_s
, s
, s
->disabled
, s
->p2p_group
,
550 if (!s
->disabled
&& s
->p2p_group
&&
551 s
->mode
== WPAS_MODE_P2P_GO
) {
552 count
+= p2p_get_group_num_members(
562 static unsigned int p2p_is_active_persistent_group(struct wpa_supplicant
*wpa_s
)
564 return !wpa_s
->p2p_mgmt
&& wpa_s
->current_ssid
&&
565 !wpa_s
->current_ssid
->disabled
&&
566 wpa_s
->current_ssid
->p2p_group
&&
567 wpa_s
->current_ssid
->p2p_persistent_group
;
571 static unsigned int p2p_is_active_persistent_go(struct wpa_supplicant
*wpa_s
)
573 return p2p_is_active_persistent_group(wpa_s
) &&
574 wpa_s
->current_ssid
->mode
== WPAS_MODE_P2P_GO
;
578 /* Find an interface for a P2P group where we are the GO */
579 static struct wpa_supplicant
*
580 wpas_p2p_get_go_group(struct wpa_supplicant
*wpa_s
)
582 struct wpa_supplicant
*save
= NULL
;
587 for (wpa_s
= wpa_s
->global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
588 if (!p2p_is_active_persistent_go(wpa_s
))
591 /* Prefer a group with connected clients */
592 if (p2p_get_group_num_members(wpa_s
->p2p_group
))
597 /* No group with connected clients, so pick the one without (if any) */
602 static unsigned int p2p_is_active_persistent_cli(struct wpa_supplicant
*wpa_s
)
604 return p2p_is_active_persistent_group(wpa_s
) &&
605 wpa_s
->current_ssid
->mode
== WPAS_MODE_INFRA
;
609 /* Find an interface for a P2P group where we are the P2P Client */
610 static struct wpa_supplicant
*
611 wpas_p2p_get_cli_group(struct wpa_supplicant
*wpa_s
)
613 for (wpa_s
= wpa_s
->global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
614 if (p2p_is_active_persistent_cli(wpa_s
))
622 /* Find a persistent group where we are the GO */
623 static struct wpa_ssid
*
624 wpas_p2p_get_persistent_go(struct wpa_supplicant
*wpa_s
)
628 for (s
= wpa_s
->conf
->ssid
; s
; s
= s
->next
) {
629 if (s
->disabled
== 2 && s
->mode
== WPAS_MODE_P2P_GO
)
637 static u8
p2ps_group_capability(void *ctx
, u8 incoming
, u8 role
,
638 unsigned int *force_freq
,
639 unsigned int *pref_freq
)
641 struct wpa_supplicant
*wpa_s
= ctx
;
643 u8 conncap
= P2PS_SETUP_NONE
;
644 unsigned int owned_members
= 0;
645 struct wpa_supplicant
*go_wpa_s
, *cli_wpa_s
;
646 struct wpa_ssid
*persistent_go
;
647 int p2p_no_group_iface
;
648 unsigned int pref_freq_list
[P2P_MAX_PREF_CHANNELS
], size
;
650 wpa_printf(MSG_DEBUG
, "P2P: Conncap - in:%d role:%d", incoming
, role
);
657 size
= P2P_MAX_PREF_CHANNELS
;
658 if (force_freq
&& pref_freq
&&
659 !wpas_p2p_setup_freqs(wpa_s
, 0, (int *) force_freq
,
660 (int *) pref_freq
, 0, pref_freq_list
, &size
))
661 wpas_p2p_set_own_freq_preference(wpa_s
,
662 *force_freq
? *force_freq
:
666 * For non-concurrent capable devices:
667 * If persistent_go, then no new.
668 * If GO, then no client.
669 * If client, then no GO.
671 go_wpa_s
= wpas_p2p_get_go_group(wpa_s
);
673 owned_members
= p2p_get_group_num_members(go_wpa_s
->p2p_group
);
674 persistent_go
= wpas_p2p_get_persistent_go(wpa_s
);
675 p2p_no_group_iface
= !wpas_p2p_create_iface(wpa_s
);
676 cli_wpa_s
= wpas_p2p_get_cli_group(wpa_s
);
678 wpa_printf(MSG_DEBUG
,
679 "P2P: GO(iface)=%p members=%u CLI(iface)=%p persistent(ssid)=%p",
680 go_wpa_s
, owned_members
, cli_wpa_s
, persistent_go
);
682 /* If not concurrent, restrict our choices */
683 if (p2p_no_group_iface
) {
684 wpa_printf(MSG_DEBUG
, "P2P: p2p_no_group_iface");
687 return P2PS_SETUP_NONE
;
690 if (role
== P2PS_SETUP_CLIENT
||
691 incoming
== P2PS_SETUP_GROUP_OWNER
||
692 p2p_client_limit_reached(go_wpa_s
->p2p_group
))
693 return P2PS_SETUP_NONE
;
695 return P2PS_SETUP_GROUP_OWNER
;
699 if (role
== P2PS_SETUP_NONE
|| role
== P2PS_SETUP_NEW
) {
701 return P2PS_SETUP_GROUP_OWNER
|
703 if (incoming
== P2PS_SETUP_NEW
) {
706 if (os_get_random(&r
, sizeof(r
)) < 0 ||
708 return P2PS_SETUP_CLIENT
;
709 return P2PS_SETUP_GROUP_OWNER
;
715 /* If a required role has been specified, handle it here */
716 if (role
&& role
!= P2PS_SETUP_NEW
) {
718 case P2PS_SETUP_GROUP_OWNER
| P2PS_SETUP_NEW
:
719 case P2PS_SETUP_GROUP_OWNER
| P2PS_SETUP_CLIENT
:
721 * Peer has an active GO, so if the role allows it and
722 * we do not have any active roles, become client.
724 if ((role
& P2PS_SETUP_CLIENT
) && !go_wpa_s
&&
726 return P2PS_SETUP_CLIENT
;
730 case P2PS_SETUP_NONE
:
735 case P2PS_SETUP_GROUP_OWNER
:
737 * Must be a complimentary role - cannot be a client to
738 * more than one peer.
740 if (incoming
== role
|| cli_wpa_s
)
741 return P2PS_SETUP_NONE
;
743 return P2PS_SETUP_CLIENT
;
745 case P2PS_SETUP_CLIENT
:
746 /* Must be a complimentary role */
747 if (incoming
!= role
) {
748 conncap
= P2PS_SETUP_GROUP_OWNER
;
754 return P2PS_SETUP_NONE
;
759 * For now, we only will support ownership of one group, and being a
760 * client of one group. Therefore, if we have either an existing GO
761 * group, or an existing client group, we will not do a new GO
762 * negotiation, but rather try to re-use the existing groups.
765 case P2PS_SETUP_NONE
:
768 conncap
= P2PS_SETUP_GROUP_OWNER
;
769 else if (!owned_members
)
770 conncap
= P2PS_SETUP_NEW
;
771 else if (incoming
== P2PS_SETUP_NONE
)
772 conncap
= P2PS_SETUP_GROUP_OWNER
| P2PS_SETUP_CLIENT
;
774 conncap
= P2PS_SETUP_CLIENT
;
777 case P2PS_SETUP_CLIENT
:
778 conncap
= P2PS_SETUP_GROUP_OWNER
;
781 case P2PS_SETUP_GROUP_OWNER
:
783 conncap
= P2PS_SETUP_CLIENT
;
786 case P2PS_SETUP_GROUP_OWNER
| P2PS_SETUP_NEW
:
787 case P2PS_SETUP_GROUP_OWNER
| P2PS_SETUP_CLIENT
:
789 conncap
= P2PS_SETUP_GROUP_OWNER
;
793 if (os_get_random(&r
, sizeof(r
)) < 0 ||
795 conncap
= P2PS_SETUP_CLIENT
;
797 conncap
= P2PS_SETUP_GROUP_OWNER
;
802 return P2PS_SETUP_NONE
;
806 if ((conncap
& P2PS_SETUP_GROUP_OWNER
) ||
807 (!incoming
&& (conncap
& P2PS_SETUP_NEW
))) {
808 if (go_wpa_s
&& p2p_client_limit_reached(go_wpa_s
->p2p_group
))
809 conncap
&= ~P2PS_SETUP_GROUP_OWNER
;
811 s
= wpas_p2p_get_persistent_go(wpa_s
);
812 if (!s
&& !go_wpa_s
&& p2p_no_group_iface
) {
813 p2p_set_intended_addr(wpa_s
->global
->p2p
,
815 wpa_s
->parent
->own_addr
:
817 } else if (!s
&& !go_wpa_s
) {
818 if (wpas_p2p_add_group_interface(wpa_s
,
819 WPA_IF_P2P_GROUP
) < 0) {
820 wpa_printf(MSG_ERROR
,
821 "P2P: Failed to allocate a new interface for the group");
822 return P2PS_SETUP_NONE
;
824 wpa_s
->global
->pending_group_iface_for_p2ps
= 1;
825 p2p_set_intended_addr(wpa_s
->global
->p2p
,
826 wpa_s
->pending_interface_addr
);
834 static int wpas_p2p_group_delete(struct wpa_supplicant
*wpa_s
,
835 enum p2p_group_removal_reason removal_reason
)
837 struct wpa_ssid
*ssid
;
841 ssid
= wpa_s
->current_ssid
;
844 * The current SSID was not known, but there may still be a
845 * pending P2P group interface waiting for provisioning or a
846 * P2P group that is trying to reconnect.
848 ssid
= wpa_s
->conf
->ssid
;
850 if (ssid
->p2p_group
&& ssid
->disabled
!= 2)
855 wpa_s
->p2p_group_interface
== NOT_P2P_GROUP_INTERFACE
)
857 wpa_printf(MSG_ERROR
, "P2P: P2P group interface "
862 if (wpa_s
->p2p_group_interface
== P2P_GROUP_INTERFACE_GO
)
864 else if (wpa_s
->p2p_group_interface
== P2P_GROUP_INTERFACE_CLIENT
||
865 (ssid
&& ssid
->mode
== WPAS_MODE_INFRA
)) {
866 wpa_s
->reassociate
= 0;
867 wpa_s
->disconnected
= 1;
872 if (removal_reason
!= P2P_GROUP_REMOVAL_SILENT
&& ssid
)
873 wpas_notify_p2p_group_removed(wpa_s
, ssid
, gtype
);
875 if (os_strcmp(gtype
, "client") == 0) {
876 wpa_supplicant_deauthenticate(wpa_s
, WLAN_REASON_DEAUTH_LEAVING
);
877 if (eloop_is_timeout_registered(wpas_p2p_psk_failure_removal
,
879 wpa_printf(MSG_DEBUG
,
880 "P2P: PSK failure removal was scheduled, so use PSK failure as reason for group removal");
881 removal_reason
= P2P_GROUP_REMOVAL_PSK_FAILURE
;
882 eloop_cancel_timeout(wpas_p2p_psk_failure_removal
,
887 if (wpa_s
->cross_connect_in_use
) {
888 wpa_s
->cross_connect_in_use
= 0;
889 wpa_msg_global(wpa_s
->p2pdev
, MSG_INFO
,
890 P2P_EVENT_CROSS_CONNECT_DISABLE
"%s %s",
891 wpa_s
->ifname
, wpa_s
->cross_connect_uplink
);
893 switch (removal_reason
) {
894 case P2P_GROUP_REMOVAL_REQUESTED
:
895 reason
= " reason=REQUESTED";
897 case P2P_GROUP_REMOVAL_FORMATION_FAILED
:
898 reason
= " reason=FORMATION_FAILED";
900 case P2P_GROUP_REMOVAL_IDLE_TIMEOUT
:
901 reason
= " reason=IDLE";
903 case P2P_GROUP_REMOVAL_UNAVAILABLE
:
904 reason
= " reason=UNAVAILABLE";
906 case P2P_GROUP_REMOVAL_GO_ENDING_SESSION
:
907 reason
= " reason=GO_ENDING_SESSION";
909 case P2P_GROUP_REMOVAL_PSK_FAILURE
:
910 reason
= " reason=PSK_FAILURE";
912 case P2P_GROUP_REMOVAL_FREQ_CONFLICT
:
913 reason
= " reason=FREQ_CONFLICT";
919 if (removal_reason
!= P2P_GROUP_REMOVAL_SILENT
) {
920 wpa_msg_global(wpa_s
->p2pdev
, MSG_INFO
,
921 P2P_EVENT_GROUP_REMOVED
"%s %s%s",
922 wpa_s
->ifname
, gtype
, reason
);
925 if (eloop_cancel_timeout(wpas_p2p_group_freq_conflict
, wpa_s
, NULL
) > 0)
926 wpa_printf(MSG_DEBUG
, "P2P: Cancelled P2P group freq_conflict timeout");
927 if (eloop_cancel_timeout(wpas_p2p_group_idle_timeout
, wpa_s
, NULL
) > 0)
928 wpa_printf(MSG_DEBUG
, "P2P: Cancelled P2P group idle timeout");
929 if (eloop_cancel_timeout(wpas_p2p_group_formation_timeout
,
930 wpa_s
->p2pdev
, NULL
) > 0) {
931 wpa_printf(MSG_DEBUG
, "P2P: Cancelled P2P group formation "
933 wpa_s
->p2p_in_provisioning
= 0;
934 wpas_p2p_group_formation_failed(wpa_s
, 1);
937 wpa_s
->p2p_in_invitation
= 0;
938 eloop_cancel_timeout(wpas_p2p_move_go
, wpa_s
, NULL
);
939 eloop_cancel_timeout(wpas_p2p_reconsider_moving_go
, wpa_s
, NULL
);
942 * Make sure wait for the first client does not remain active after the
943 * group has been removed.
945 wpa_s
->global
->p2p_go_wait_client
.sec
= 0;
947 if (wpa_s
->p2p_group_interface
!= NOT_P2P_GROUP_INTERFACE
) {
948 struct wpa_global
*global
;
950 enum wpa_driver_if_type type
;
951 wpa_printf(MSG_DEBUG
, "P2P: Remove group interface %s",
953 global
= wpa_s
->global
;
954 ifname
= os_strdup(wpa_s
->ifname
);
955 type
= wpas_p2p_if_type(wpa_s
->p2p_group_interface
);
956 eloop_cancel_timeout(run_wpas_p2p_disconnect
, wpa_s
, NULL
);
957 wpa_supplicant_remove_iface(wpa_s
->global
, wpa_s
, 0);
958 wpa_s
= global
->ifaces
;
960 wpa_drv_if_remove(wpa_s
, type
, ifname
);
966 * The primary interface was used for P2P group operations, so
967 * need to reset its p2pdev.
969 wpa_s
->p2pdev
= wpa_s
->parent
;
971 if (!wpa_s
->p2p_go_group_formation_completed
) {
972 wpa_s
->global
->p2p_group_formation
= NULL
;
973 wpa_s
->p2p_in_provisioning
= 0;
976 wpa_s
->show_group_started
= 0;
977 os_free(wpa_s
->go_params
);
978 wpa_s
->go_params
= NULL
;
980 os_free(wpa_s
->p2p_group_common_freqs
);
981 wpa_s
->p2p_group_common_freqs
= NULL
;
982 wpa_s
->p2p_group_common_freqs_num
= 0;
984 wpa_s
->waiting_presence_resp
= 0;
986 wpa_printf(MSG_DEBUG
, "P2P: Remove temporary group network");
987 if (ssid
&& (ssid
->p2p_group
||
988 ssid
->mode
== WPAS_MODE_P2P_GROUP_FORMATION
||
989 (ssid
->key_mgmt
& WPA_KEY_MGMT_WPS
))) {
991 if (ssid
== wpa_s
->current_ssid
) {
992 wpa_sm_set_config(wpa_s
->wpa
, NULL
);
993 eapol_sm_notify_config(wpa_s
->eapol
, NULL
, NULL
);
994 wpa_s
->current_ssid
= NULL
;
997 * Networks objects created during any P2P activities are not
998 * exposed out as they might/will confuse certain non-P2P aware
999 * applications since these network objects won't behave like
1002 * Likewise, we don't send out network removed signals for such
1005 wpa_config_remove_network(wpa_s
->conf
, id
);
1006 wpa_supplicant_clear_status(wpa_s
);
1007 wpa_supplicant_cancel_sched_scan(wpa_s
);
1009 wpa_printf(MSG_DEBUG
, "P2P: Temporary group network not "
1012 if (wpa_s
->ap_iface
)
1013 wpa_supplicant_ap_deinit(wpa_s
);
1015 wpa_drv_deinit_p2p_cli(wpa_s
);
1017 os_memset(wpa_s
->go_dev_addr
, 0, ETH_ALEN
);
1023 static int wpas_p2p_persistent_group(struct wpa_supplicant
*wpa_s
,
1025 const u8
*ssid
, size_t ssid_len
)
1027 struct wpa_bss
*bss
;
1033 if (wpa_s
->go_params
)
1034 bssid
= wpa_s
->go_params
->peer_interface_addr
;
1036 bssid
= wpa_s
->bssid
;
1038 bss
= wpa_bss_get(wpa_s
, bssid
, ssid
, ssid_len
);
1039 if (bss
== NULL
&& wpa_s
->go_params
&&
1040 !is_zero_ether_addr(wpa_s
->go_params
->peer_device_addr
))
1041 bss
= wpa_bss_get_p2p_dev_addr(
1042 wpa_s
, wpa_s
->go_params
->peer_device_addr
);
1044 u8 iface_addr
[ETH_ALEN
];
1045 if (p2p_get_interface_addr(wpa_s
->global
->p2p
, bssid
,
1047 bss
= wpa_bss_get(wpa_s
, iface_addr
, ssid
, ssid_len
);
1050 wpa_printf(MSG_DEBUG
, "P2P: Could not figure out whether "
1051 "group is persistent - BSS " MACSTR
" not found",
1056 p2p
= wpa_bss_get_vendor_ie_multi(bss
, P2P_IE_VENDOR_TYPE
);
1058 p2p
= wpa_bss_get_vendor_ie_multi_beacon(bss
,
1059 P2P_IE_VENDOR_TYPE
);
1061 wpa_printf(MSG_DEBUG
, "P2P: Could not figure out whether "
1062 "group is persistent - BSS " MACSTR
1063 " did not include P2P IE", MAC2STR(bssid
));
1064 wpa_hexdump(MSG_DEBUG
, "P2P: Probe Response IEs",
1065 (u8
*) (bss
+ 1), bss
->ie_len
);
1066 wpa_hexdump(MSG_DEBUG
, "P2P: Beacon IEs",
1067 ((u8
*) bss
+ 1) + bss
->ie_len
,
1068 bss
->beacon_ie_len
);
1072 group_capab
= p2p_get_group_capab(p2p
);
1073 addr
= p2p_get_go_dev_addr(p2p
);
1074 wpa_printf(MSG_DEBUG
, "P2P: Checking whether group is persistent: "
1075 "group_capab=0x%x", group_capab
);
1077 os_memcpy(go_dev_addr
, addr
, ETH_ALEN
);
1078 wpa_printf(MSG_DEBUG
, "P2P: GO Device Address " MACSTR
,
1081 os_memset(go_dev_addr
, 0, ETH_ALEN
);
1084 wpa_printf(MSG_DEBUG
, "P2P: BSS " MACSTR
" group_capab=0x%x "
1085 "go_dev_addr=" MACSTR
,
1086 MAC2STR(bssid
), group_capab
, MAC2STR(go_dev_addr
));
1088 return !!(group_capab
& P2P_GROUP_CAPAB_PERSISTENT_GROUP
);
1092 static int wpas_p2p_store_persistent_group(struct wpa_supplicant
*wpa_s
,
1093 struct wpa_ssid
*ssid
,
1094 const u8
*go_dev_addr
)
1099 wpa_printf(MSG_DEBUG
, "P2P: Storing credentials for a persistent "
1100 "group (GO Dev Addr " MACSTR
")", MAC2STR(go_dev_addr
));
1101 for (s
= wpa_s
->conf
->ssid
; s
; s
= s
->next
) {
1102 if (s
->disabled
== 2 &&
1103 os_memcmp(go_dev_addr
, s
->bssid
, ETH_ALEN
) == 0 &&
1104 s
->ssid_len
== ssid
->ssid_len
&&
1105 os_memcmp(ssid
->ssid
, s
->ssid
, ssid
->ssid_len
) == 0)
1110 wpa_printf(MSG_DEBUG
, "P2P: Update existing persistent group "
1112 if (ssid
->passphrase
&& !s
->passphrase
)
1114 else if (ssid
->passphrase
&& s
->passphrase
&&
1115 os_strcmp(ssid
->passphrase
, s
->passphrase
) != 0)
1118 wpa_printf(MSG_DEBUG
, "P2P: Create a new persistent group "
1121 s
= wpa_config_add_network(wpa_s
->conf
);
1126 * Instead of network_added we emit persistent_group_added
1127 * notification. Also to keep the defense checks in
1128 * persistent_group obj registration method, we set the
1129 * relevant flags in s to designate it as a persistent group.
1132 s
->p2p_persistent_group
= 1;
1133 wpas_notify_persistent_group_added(wpa_s
, s
);
1134 wpa_config_set_network_defaults(s
);
1138 s
->p2p_persistent_group
= 1;
1141 os_memcpy(s
->bssid
, go_dev_addr
, ETH_ALEN
);
1142 s
->mode
= ssid
->mode
;
1143 s
->auth_alg
= WPA_AUTH_ALG_OPEN
;
1144 s
->key_mgmt
= WPA_KEY_MGMT_PSK
;
1145 s
->proto
= WPA_PROTO_RSN
;
1146 s
->pbss
= ssid
->pbss
;
1147 s
->pairwise_cipher
= ssid
->pbss
? WPA_CIPHER_GCMP
: WPA_CIPHER_CCMP
;
1149 if (ssid
->passphrase
) {
1150 os_free(s
->passphrase
);
1151 s
->passphrase
= os_strdup(ssid
->passphrase
);
1153 if (ssid
->psk_set
) {
1155 os_memcpy(s
->psk
, ssid
->psk
, 32);
1157 if (s
->passphrase
&& !s
->psk_set
)
1158 wpa_config_update_psk(s
);
1159 if (s
->ssid
== NULL
|| s
->ssid_len
< ssid
->ssid_len
) {
1161 s
->ssid
= os_malloc(ssid
->ssid_len
);
1164 s
->ssid_len
= ssid
->ssid_len
;
1165 os_memcpy(s
->ssid
, ssid
->ssid
, s
->ssid_len
);
1167 if (ssid
->mode
== WPAS_MODE_P2P_GO
&& wpa_s
->global
->add_psk
) {
1168 dl_list_add(&s
->psk_list
, &wpa_s
->global
->add_psk
->list
);
1169 wpa_s
->global
->add_psk
= NULL
;
1173 if (changed
&& wpa_s
->conf
->update_config
&&
1174 wpa_config_write(wpa_s
->confname
, wpa_s
->conf
)) {
1175 wpa_printf(MSG_DEBUG
, "P2P: Failed to update configuration");
1182 static void wpas_p2p_add_persistent_group_client(struct wpa_supplicant
*wpa_s
,
1185 struct wpa_ssid
*ssid
, *s
;
1189 struct wpa_supplicant
*p2p_wpa_s
= wpa_s
->global
->p2p_init_wpa_s
;
1191 ssid
= wpa_s
->current_ssid
;
1192 if (ssid
== NULL
|| ssid
->mode
!= WPAS_MODE_P2P_GO
||
1193 !ssid
->p2p_persistent_group
)
1196 for (s
= p2p_wpa_s
->conf
->ssid
; s
; s
= s
->next
) {
1197 if (s
->disabled
!= 2 || s
->mode
!= WPAS_MODE_P2P_GO
)
1200 if (s
->ssid_len
== ssid
->ssid_len
&&
1201 os_memcmp(s
->ssid
, ssid
->ssid
, s
->ssid_len
) == 0)
1208 for (i
= 0; s
->p2p_client_list
&& i
< s
->num_p2p_clients
; i
++) {
1209 if (os_memcmp(s
->p2p_client_list
+ i
* 2 * ETH_ALEN
, addr
,
1213 if (i
== s
->num_p2p_clients
- 1)
1214 return; /* already the most recent entry */
1216 /* move the entry to mark it most recent */
1217 os_memmove(s
->p2p_client_list
+ i
* 2 * ETH_ALEN
,
1218 s
->p2p_client_list
+ (i
+ 1) * 2 * ETH_ALEN
,
1219 (s
->num_p2p_clients
- i
- 1) * 2 * ETH_ALEN
);
1220 os_memcpy(s
->p2p_client_list
+
1221 (s
->num_p2p_clients
- 1) * 2 * ETH_ALEN
, addr
,
1223 os_memset(s
->p2p_client_list
+
1224 (s
->num_p2p_clients
- 1) * 2 * ETH_ALEN
+ ETH_ALEN
,
1230 if (!found
&& s
->num_p2p_clients
< P2P_MAX_STORED_CLIENTS
) {
1231 n
= os_realloc_array(s
->p2p_client_list
,
1232 s
->num_p2p_clients
+ 1, 2 * ETH_ALEN
);
1235 os_memcpy(n
+ s
->num_p2p_clients
* 2 * ETH_ALEN
, addr
,
1237 os_memset(n
+ s
->num_p2p_clients
* 2 * ETH_ALEN
+ ETH_ALEN
,
1239 s
->p2p_client_list
= n
;
1240 s
->num_p2p_clients
++;
1241 } else if (!found
&& s
->p2p_client_list
) {
1242 /* Not enough room for an additional entry - drop the oldest
1244 os_memmove(s
->p2p_client_list
,
1245 s
->p2p_client_list
+ 2 * ETH_ALEN
,
1246 (s
->num_p2p_clients
- 1) * 2 * ETH_ALEN
);
1247 os_memcpy(s
->p2p_client_list
+
1248 (s
->num_p2p_clients
- 1) * 2 * ETH_ALEN
,
1250 os_memset(s
->p2p_client_list
+
1251 (s
->num_p2p_clients
- 1) * 2 * ETH_ALEN
+ ETH_ALEN
,
1255 if (p2p_wpa_s
->conf
->update_config
&&
1256 wpa_config_write(p2p_wpa_s
->confname
, p2p_wpa_s
->conf
))
1257 wpa_printf(MSG_DEBUG
, "P2P: Failed to update configuration");
1261 static void wpas_p2p_group_started(struct wpa_supplicant
*wpa_s
,
1262 int go
, struct wpa_ssid
*ssid
, int freq
,
1263 const u8
*psk
, const char *passphrase
,
1264 const u8
*go_dev_addr
, int persistent
,
1267 const char *ssid_txt
;
1271 wpa_snprintf_hex(psk_txt
, sizeof(psk_txt
), psk
, 32);
1276 ssid_txt
= wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
);
1280 if (passphrase
&& passphrase
[0] == '\0')
1284 * Include PSK/passphrase only in the control interface message and
1285 * leave it out from the debug log entry.
1287 wpa_msg_global_ctrl(wpa_s
->p2pdev
, MSG_INFO
,
1288 P2P_EVENT_GROUP_STARTED
1289 "%s %s ssid=\"%s\" freq=%d%s%s%s%s%s go_dev_addr="
1291 wpa_s
->ifname
, go
? "GO" : "client", ssid_txt
, freq
,
1292 psk
? " psk=" : "", psk_txt
,
1293 passphrase
? " passphrase=\"" : "",
1294 passphrase
? passphrase
: "",
1295 passphrase
? "\"" : "",
1296 MAC2STR(go_dev_addr
),
1297 persistent
? " [PERSISTENT]" : "", extra
);
1298 wpa_printf(MSG_INFO
, P2P_EVENT_GROUP_STARTED
1299 "%s %s ssid=\"%s\" freq=%d go_dev_addr=" MACSTR
"%s%s",
1300 wpa_s
->ifname
, go
? "GO" : "client", ssid_txt
, freq
,
1301 MAC2STR(go_dev_addr
), persistent
? " [PERSISTENT]" : "",
1306 static void wpas_group_formation_completed(struct wpa_supplicant
*wpa_s
,
1307 int success
, int already_deleted
)
1309 struct wpa_ssid
*ssid
;
1312 u8 go_dev_addr
[ETH_ALEN
];
1315 * This callback is likely called for the main interface. Update wpa_s
1316 * to use the group interface if a new interface was created for the
1319 if (wpa_s
->global
->p2p_group_formation
)
1320 wpa_s
= wpa_s
->global
->p2p_group_formation
;
1321 if (wpa_s
->p2p_go_group_formation_completed
) {
1322 wpa_s
->global
->p2p_group_formation
= NULL
;
1323 wpa_s
->p2p_in_provisioning
= 0;
1324 } else if (wpa_s
->p2p_in_provisioning
&& !success
) {
1325 wpa_msg(wpa_s
, MSG_DEBUG
,
1326 "P2P: Stop provisioning state due to failure");
1327 wpa_s
->p2p_in_provisioning
= 0;
1329 wpa_s
->p2p_in_invitation
= 0;
1330 wpa_s
->group_formation_reported
= 1;
1333 wpa_msg_global(wpa_s
->p2pdev
, MSG_INFO
,
1334 P2P_EVENT_GROUP_FORMATION_FAILURE
);
1335 wpas_notify_p2p_group_formation_failure(wpa_s
, "");
1336 if (already_deleted
)
1338 wpas_p2p_group_delete(wpa_s
,
1339 P2P_GROUP_REMOVAL_FORMATION_FAILED
);
1343 wpa_msg_global(wpa_s
->p2pdev
, MSG_INFO
,
1344 P2P_EVENT_GROUP_FORMATION_SUCCESS
);
1346 ssid
= wpa_s
->current_ssid
;
1347 if (ssid
&& ssid
->mode
== WPAS_MODE_P2P_GROUP_FORMATION
) {
1348 ssid
->mode
= WPAS_MODE_P2P_GO
;
1349 p2p_group_notif_formation_done(wpa_s
->p2p_group
);
1350 wpa_supplicant_ap_mac_addr_filter(wpa_s
, NULL
);
1355 client
= ssid
->mode
== WPAS_MODE_INFRA
;
1356 if (ssid
->mode
== WPAS_MODE_P2P_GO
) {
1357 persistent
= ssid
->p2p_persistent_group
;
1358 os_memcpy(go_dev_addr
, wpa_s
->global
->p2p_dev_addr
,
1361 persistent
= wpas_p2p_persistent_group(wpa_s
,
1366 client
= wpa_s
->p2p_group_interface
==
1367 P2P_GROUP_INTERFACE_CLIENT
;
1368 os_memset(go_dev_addr
, 0, ETH_ALEN
);
1371 wpa_s
->show_group_started
= 0;
1374 * Indicate event only after successfully completed 4-way
1375 * handshake, i.e., when the interface is ready for data
1378 wpa_s
->show_group_started
= 1;
1380 wpas_p2p_group_started(wpa_s
, 1, ssid
,
1381 ssid
? ssid
->frequency
: 0,
1382 ssid
&& ssid
->passphrase
== NULL
&&
1383 ssid
->psk_set
? ssid
->psk
: NULL
,
1384 ssid
? ssid
->passphrase
: NULL
,
1385 go_dev_addr
, persistent
, "");
1386 wpas_p2p_cross_connect_setup(wpa_s
);
1387 wpas_p2p_set_group_idle_timeout(wpa_s
);
1391 wpas_p2p_store_persistent_group(wpa_s
->p2pdev
,
1394 os_free(wpa_s
->global
->add_psk
);
1395 wpa_s
->global
->add_psk
= NULL
;
1399 wpas_notify_p2p_group_started(wpa_s
, ssid
, persistent
, 0, NULL
);
1400 os_get_reltime(&wpa_s
->global
->p2p_go_wait_client
);
1405 struct send_action_work
{
1411 unsigned int wait_time
;
1416 static void wpas_p2p_free_send_action_work(struct wpa_supplicant
*wpa_s
)
1418 struct send_action_work
*awork
= wpa_s
->p2p_send_action_work
->ctx
;
1420 wpa_printf(MSG_DEBUG
,
1421 "P2P: Free Action frame radio work @%p (freq=%u dst="
1422 MACSTR
" src=" MACSTR
" bssid=" MACSTR
" wait_time=%u)",
1423 wpa_s
->p2p_send_action_work
, awork
->freq
,
1424 MAC2STR(awork
->dst
), MAC2STR(awork
->src
),
1425 MAC2STR(awork
->bssid
), awork
->wait_time
);
1426 wpa_hexdump(MSG_DEBUG
, "P2P: Freeing pending Action frame",
1427 awork
->buf
, awork
->len
);
1429 wpa_s
->p2p_send_action_work
->ctx
= NULL
;
1430 radio_work_done(wpa_s
->p2p_send_action_work
);
1431 wpa_s
->p2p_send_action_work
= NULL
;
1435 static void wpas_p2p_send_action_work_timeout(void *eloop_ctx
,
1438 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
1440 if (!wpa_s
->p2p_send_action_work
)
1443 wpa_printf(MSG_DEBUG
, "P2P: Send Action frame radio work timed out");
1444 wpas_p2p_free_send_action_work(wpa_s
);
1448 static void wpas_p2p_action_tx_clear(struct wpa_supplicant
*wpa_s
)
1450 if (wpa_s
->p2p_send_action_work
) {
1451 struct send_action_work
*awork
;
1453 awork
= wpa_s
->p2p_send_action_work
->ctx
;
1454 wpa_printf(MSG_DEBUG
,
1455 "P2P: Clear Action TX work @%p (wait_time=%u)",
1456 wpa_s
->p2p_send_action_work
, awork
->wait_time
);
1457 if (awork
->wait_time
== 0) {
1458 wpas_p2p_free_send_action_work(wpa_s
);
1461 * In theory, this should not be needed, but number of
1462 * places in the P2P code is still using non-zero wait
1463 * time for the last Action frame in the sequence and
1464 * some of these do not call send_action_done().
1466 eloop_cancel_timeout(wpas_p2p_send_action_work_timeout
,
1468 eloop_register_timeout(
1469 0, awork
->wait_time
* 1000,
1470 wpas_p2p_send_action_work_timeout
,
1477 static void wpas_p2p_send_action_tx_status(struct wpa_supplicant
*wpa_s
,
1479 const u8
*dst
, const u8
*src
,
1481 const u8
*data
, size_t data_len
,
1482 enum offchannel_send_action_result
1485 enum p2p_send_action_result res
= P2P_SEND_ACTION_SUCCESS
;
1487 wpas_p2p_action_tx_clear(wpa_s
);
1489 if (wpa_s
->global
->p2p
== NULL
|| wpa_s
->global
->p2p_disabled
)
1493 case OFFCHANNEL_SEND_ACTION_SUCCESS
:
1494 res
= P2P_SEND_ACTION_SUCCESS
;
1496 case OFFCHANNEL_SEND_ACTION_NO_ACK
:
1497 res
= P2P_SEND_ACTION_NO_ACK
;
1499 case OFFCHANNEL_SEND_ACTION_FAILED
:
1500 res
= P2P_SEND_ACTION_FAILED
;
1504 p2p_send_action_cb(wpa_s
->global
->p2p
, freq
, dst
, src
, bssid
, res
);
1506 if (result
!= OFFCHANNEL_SEND_ACTION_SUCCESS
&&
1507 wpa_s
->pending_pd_before_join
&&
1508 (os_memcmp(dst
, wpa_s
->pending_join_dev_addr
, ETH_ALEN
) == 0 ||
1509 os_memcmp(dst
, wpa_s
->pending_join_iface_addr
, ETH_ALEN
) == 0) &&
1510 wpa_s
->p2p_fallback_to_go_neg
) {
1511 wpa_s
->pending_pd_before_join
= 0;
1512 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: No ACK for PD Req "
1513 "during p2p_connect-auto");
1514 wpa_msg_global(wpa_s
->p2pdev
, MSG_INFO
,
1515 P2P_EVENT_FALLBACK_TO_GO_NEG
1516 "reason=no-ACK-to-PD-Req");
1517 wpas_p2p_fallback_to_go_neg(wpa_s
, 0);
1523 static void wpas_send_action_cb(struct wpa_radio_work
*work
, int deinit
)
1525 struct wpa_supplicant
*wpa_s
= work
->wpa_s
;
1526 struct send_action_work
*awork
= work
->ctx
;
1529 if (work
->started
) {
1530 eloop_cancel_timeout(wpas_p2p_send_action_work_timeout
,
1532 wpa_s
->p2p_send_action_work
= NULL
;
1533 offchannel_send_action_done(wpa_s
);
1539 if (offchannel_send_action(wpa_s
, awork
->freq
, awork
->dst
, awork
->src
,
1540 awork
->bssid
, awork
->buf
, awork
->len
,
1542 wpas_p2p_send_action_tx_status
, 1) < 0) {
1544 radio_work_done(work
);
1547 wpa_s
->p2p_send_action_work
= work
;
1551 static int wpas_send_action_work(struct wpa_supplicant
*wpa_s
,
1552 unsigned int freq
, const u8
*dst
,
1553 const u8
*src
, const u8
*bssid
, const u8
*buf
,
1554 size_t len
, unsigned int wait_time
)
1556 struct send_action_work
*awork
;
1558 if (wpa_s
->p2p_send_action_work
) {
1559 wpa_printf(MSG_DEBUG
, "P2P: Cannot schedule new p2p-send-action work since one is already pending");
1563 awork
= os_zalloc(sizeof(*awork
) + len
);
1568 os_memcpy(awork
->dst
, dst
, ETH_ALEN
);
1569 os_memcpy(awork
->src
, src
, ETH_ALEN
);
1570 os_memcpy(awork
->bssid
, bssid
, ETH_ALEN
);
1572 awork
->wait_time
= wait_time
;
1573 os_memcpy(awork
->buf
, buf
, len
);
1575 if (radio_add_work(wpa_s
, freq
, "p2p-send-action", 0,
1576 wpas_send_action_cb
, awork
) < 0) {
1585 static int wpas_send_action(void *ctx
, unsigned int freq
, const u8
*dst
,
1586 const u8
*src
, const u8
*bssid
, const u8
*buf
,
1587 size_t len
, unsigned int wait_time
)
1589 struct wpa_supplicant
*wpa_s
= ctx
;
1590 int listen_freq
= -1, send_freq
= -1;
1592 if (wpa_s
->p2p_listen_work
)
1593 listen_freq
= wpa_s
->p2p_listen_work
->freq
;
1594 if (wpa_s
->p2p_send_action_work
)
1595 send_freq
= wpa_s
->p2p_send_action_work
->freq
;
1596 if (listen_freq
!= (int) freq
&& send_freq
!= (int) freq
) {
1597 wpa_printf(MSG_DEBUG
, "P2P: Schedule new radio work for Action frame TX (listen_freq=%d send_freq=%d)",
1598 listen_freq
, send_freq
);
1599 return wpas_send_action_work(wpa_s
, freq
, dst
, src
, bssid
, buf
,
1603 wpa_printf(MSG_DEBUG
, "P2P: Use ongoing radio work for Action frame TX");
1604 return offchannel_send_action(wpa_s
, freq
, dst
, src
, bssid
, buf
, len
,
1606 wpas_p2p_send_action_tx_status
, 1);
1610 static void wpas_send_action_done(void *ctx
)
1612 struct wpa_supplicant
*wpa_s
= ctx
;
1614 if (wpa_s
->p2p_send_action_work
) {
1615 eloop_cancel_timeout(wpas_p2p_send_action_work_timeout
,
1617 os_free(wpa_s
->p2p_send_action_work
->ctx
);
1618 radio_work_done(wpa_s
->p2p_send_action_work
);
1619 wpa_s
->p2p_send_action_work
= NULL
;
1622 offchannel_send_action_done(wpa_s
);
1626 static int wpas_copy_go_neg_results(struct wpa_supplicant
*wpa_s
,
1627 struct p2p_go_neg_results
*params
)
1629 if (wpa_s
->go_params
== NULL
) {
1630 wpa_s
->go_params
= os_malloc(sizeof(*params
));
1631 if (wpa_s
->go_params
== NULL
)
1634 os_memcpy(wpa_s
->go_params
, params
, sizeof(*params
));
1639 static void wpas_start_wps_enrollee(struct wpa_supplicant
*wpa_s
,
1640 struct p2p_go_neg_results
*res
)
1642 wpa_s
->group_formation_reported
= 0;
1643 wpa_printf(MSG_DEBUG
, "P2P: Start WPS Enrollee for peer " MACSTR
1644 " dev_addr " MACSTR
" wps_method %d",
1645 MAC2STR(res
->peer_interface_addr
),
1646 MAC2STR(res
->peer_device_addr
), res
->wps_method
);
1647 wpa_hexdump_ascii(MSG_DEBUG
, "P2P: Start WPS Enrollee for SSID",
1648 res
->ssid
, res
->ssid_len
);
1649 wpa_supplicant_ap_deinit(wpa_s
);
1650 wpas_copy_go_neg_results(wpa_s
, res
);
1651 if (res
->wps_method
== WPS_PBC
) {
1652 wpas_wps_start_pbc(wpa_s
, res
->peer_interface_addr
, 1);
1653 #ifdef CONFIG_WPS_NFC
1654 } else if (res
->wps_method
== WPS_NFC
) {
1655 wpas_wps_start_nfc(wpa_s
, res
->peer_device_addr
,
1656 res
->peer_interface_addr
,
1657 wpa_s
->p2pdev
->p2p_oob_dev_pw
,
1658 wpa_s
->p2pdev
->p2p_oob_dev_pw_id
, 1,
1659 wpa_s
->p2pdev
->p2p_oob_dev_pw_id
==
1660 DEV_PW_NFC_CONNECTION_HANDOVER
?
1661 wpa_s
->p2pdev
->p2p_peer_oob_pubkey_hash
:
1664 #endif /* CONFIG_WPS_NFC */
1666 u16 dev_pw_id
= DEV_PW_DEFAULT
;
1667 if (wpa_s
->p2p_wps_method
== WPS_P2PS
)
1668 dev_pw_id
= DEV_PW_P2PS_DEFAULT
;
1669 if (wpa_s
->p2p_wps_method
== WPS_PIN_KEYPAD
)
1670 dev_pw_id
= DEV_PW_REGISTRAR_SPECIFIED
;
1671 wpas_wps_start_pin(wpa_s
, res
->peer_interface_addr
,
1672 wpa_s
->p2p_pin
, 1, dev_pw_id
);
1677 static void wpas_p2p_add_psk_list(struct wpa_supplicant
*wpa_s
,
1678 struct wpa_ssid
*ssid
)
1680 struct wpa_ssid
*persistent
;
1681 struct psk_list_entry
*psk
;
1682 struct hostapd_data
*hapd
;
1684 if (!wpa_s
->ap_iface
)
1687 persistent
= wpas_p2p_get_persistent(wpa_s
->p2pdev
, NULL
, ssid
->ssid
,
1689 if (persistent
== NULL
)
1692 hapd
= wpa_s
->ap_iface
->bss
[0];
1694 dl_list_for_each(psk
, &persistent
->psk_list
, struct psk_list_entry
,
1696 struct hostapd_wpa_psk
*hpsk
;
1698 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Add persistent group PSK entry for "
1700 MAC2STR(psk
->addr
), psk
->p2p
);
1701 hpsk
= os_zalloc(sizeof(*hpsk
));
1704 os_memcpy(hpsk
->psk
, psk
->psk
, PMK_LEN
);
1706 os_memcpy(hpsk
->p2p_dev_addr
, psk
->addr
, ETH_ALEN
);
1708 os_memcpy(hpsk
->addr
, psk
->addr
, ETH_ALEN
);
1709 hpsk
->next
= hapd
->conf
->ssid
.wpa_psk
;
1710 hapd
->conf
->ssid
.wpa_psk
= hpsk
;
1715 static void p2p_go_dump_common_freqs(struct wpa_supplicant
*wpa_s
)
1717 char buf
[20 + P2P_MAX_CHANNELS
* 6];
1723 end
= pos
+ sizeof(buf
);
1724 for (i
= 0; i
< wpa_s
->p2p_group_common_freqs_num
; i
++) {
1725 res
= os_snprintf(pos
, end
- pos
, " %d",
1726 wpa_s
->p2p_group_common_freqs
[i
]);
1727 if (os_snprintf_error(end
- pos
, res
))
1733 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Common group frequencies:%s", buf
);
1737 static void p2p_go_save_group_common_freqs(struct wpa_supplicant
*wpa_s
,
1738 struct p2p_go_neg_results
*params
)
1740 unsigned int i
, len
= int_array_len(wpa_s
->go_params
->freq_list
);
1742 wpa_s
->p2p_group_common_freqs_num
= 0;
1743 os_free(wpa_s
->p2p_group_common_freqs
);
1744 wpa_s
->p2p_group_common_freqs
= os_calloc(len
, sizeof(int));
1745 if (!wpa_s
->p2p_group_common_freqs
)
1748 for (i
= 0; i
< len
; i
++) {
1749 if (!wpa_s
->go_params
->freq_list
[i
])
1751 wpa_s
->p2p_group_common_freqs
[i
] =
1752 wpa_s
->go_params
->freq_list
[i
];
1754 wpa_s
->p2p_group_common_freqs_num
= i
;
1758 static void p2p_config_write(struct wpa_supplicant
*wpa_s
)
1760 #ifndef CONFIG_NO_CONFIG_WRITE
1761 if (wpa_s
->p2pdev
->conf
->update_config
&&
1762 wpa_config_write(wpa_s
->p2pdev
->confname
, wpa_s
->p2pdev
->conf
))
1763 wpa_printf(MSG_DEBUG
, "P2P: Failed to update configuration");
1764 #endif /* CONFIG_NO_CONFIG_WRITE */
1768 static void p2p_go_configured(void *ctx
, void *data
)
1770 struct wpa_supplicant
*wpa_s
= ctx
;
1771 struct p2p_go_neg_results
*params
= data
;
1772 struct wpa_ssid
*ssid
;
1774 wpa_s
->ap_configured_cb
= NULL
;
1775 wpa_s
->ap_configured_cb_ctx
= NULL
;
1776 wpa_s
->ap_configured_cb_data
= NULL
;
1777 if (!wpa_s
->go_params
) {
1778 wpa_printf(MSG_ERROR
,
1779 "P2P: p2p_go_configured() called with wpa_s->go_params == NULL");
1783 p2p_go_save_group_common_freqs(wpa_s
, params
);
1784 p2p_go_dump_common_freqs(wpa_s
);
1786 ssid
= wpa_s
->current_ssid
;
1787 if (ssid
&& ssid
->mode
== WPAS_MODE_P2P_GO
) {
1788 wpa_printf(MSG_DEBUG
, "P2P: Group setup without provisioning");
1789 if (wpa_s
->global
->p2p_group_formation
== wpa_s
)
1790 wpa_s
->global
->p2p_group_formation
= NULL
;
1791 wpas_p2p_group_started(wpa_s
, 1, ssid
, ssid
->frequency
,
1792 params
->passphrase
[0] == '\0' ?
1795 wpa_s
->global
->p2p_dev_addr
,
1796 params
->persistent_group
, "");
1797 wpa_s
->group_formation_reported
= 1;
1799 if (wpa_s
->p2pdev
->p2ps_method_config_any
) {
1800 if (is_zero_ether_addr(wpa_s
->p2pdev
->p2ps_join_addr
)) {
1801 wpa_dbg(wpa_s
, MSG_DEBUG
,
1802 "P2PS: Setting default PIN for ANY");
1803 wpa_supplicant_ap_wps_pin(wpa_s
, NULL
,
1804 "12345670", NULL
, 0,
1807 wpa_dbg(wpa_s
, MSG_DEBUG
,
1808 "P2PS: Setting default PIN for " MACSTR
,
1809 MAC2STR(wpa_s
->p2pdev
->p2ps_join_addr
));
1810 wpa_supplicant_ap_wps_pin(
1811 wpa_s
, wpa_s
->p2pdev
->p2ps_join_addr
,
1812 "12345670", NULL
, 0, 0);
1814 wpa_s
->p2pdev
->p2ps_method_config_any
= 0;
1817 os_get_reltime(&wpa_s
->global
->p2p_go_wait_client
);
1818 if (params
->persistent_group
) {
1819 wpas_p2p_store_persistent_group(
1820 wpa_s
->p2pdev
, ssid
,
1821 wpa_s
->global
->p2p_dev_addr
);
1822 wpas_p2p_add_psk_list(wpa_s
, ssid
);
1825 wpas_notify_p2p_group_started(wpa_s
, ssid
,
1826 params
->persistent_group
, 0,
1828 wpas_p2p_cross_connect_setup(wpa_s
);
1829 wpas_p2p_set_group_idle_timeout(wpa_s
);
1831 if (wpa_s
->p2p_first_connection_timeout
) {
1832 wpa_dbg(wpa_s
, MSG_DEBUG
,
1833 "P2P: Start group formation timeout of %d seconds until first data connection on GO",
1834 wpa_s
->p2p_first_connection_timeout
);
1835 wpa_s
->p2p_go_group_formation_completed
= 0;
1836 wpa_s
->global
->p2p_group_formation
= wpa_s
;
1837 eloop_cancel_timeout(wpas_p2p_group_formation_timeout
,
1838 wpa_s
->p2pdev
, NULL
);
1839 eloop_register_timeout(
1840 wpa_s
->p2p_first_connection_timeout
, 0,
1841 wpas_p2p_group_formation_timeout
,
1842 wpa_s
->p2pdev
, NULL
);
1848 wpa_printf(MSG_DEBUG
, "P2P: Setting up WPS for GO provisioning");
1849 if (wpa_supplicant_ap_mac_addr_filter(wpa_s
,
1850 params
->peer_interface_addr
)) {
1851 wpa_printf(MSG_DEBUG
, "P2P: Failed to setup MAC address "
1855 if (params
->wps_method
== WPS_PBC
) {
1856 wpa_supplicant_ap_wps_pbc(wpa_s
, params
->peer_interface_addr
,
1857 params
->peer_device_addr
);
1858 #ifdef CONFIG_WPS_NFC
1859 } else if (params
->wps_method
== WPS_NFC
) {
1860 if (wpa_s
->p2pdev
->p2p_oob_dev_pw_id
!=
1861 DEV_PW_NFC_CONNECTION_HANDOVER
&&
1862 !wpa_s
->p2pdev
->p2p_oob_dev_pw
) {
1863 wpa_printf(MSG_DEBUG
, "P2P: No NFC Dev Pw known");
1866 wpas_ap_wps_add_nfc_pw(
1867 wpa_s
, wpa_s
->p2pdev
->p2p_oob_dev_pw_id
,
1868 wpa_s
->p2pdev
->p2p_oob_dev_pw
,
1869 wpa_s
->p2pdev
->p2p_peer_oob_pk_hash_known
?
1870 wpa_s
->p2pdev
->p2p_peer_oob_pubkey_hash
: NULL
);
1871 #endif /* CONFIG_WPS_NFC */
1872 } else if (wpa_s
->p2p_pin
[0])
1873 wpa_supplicant_ap_wps_pin(wpa_s
, params
->peer_interface_addr
,
1874 wpa_s
->p2p_pin
, NULL
, 0, 0);
1875 os_free(wpa_s
->go_params
);
1876 wpa_s
->go_params
= NULL
;
1880 static void wpas_start_wps_go(struct wpa_supplicant
*wpa_s
,
1881 struct p2p_go_neg_results
*params
,
1882 int group_formation
)
1884 struct wpa_ssid
*ssid
;
1886 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Starting GO");
1887 if (wpas_copy_go_neg_results(wpa_s
, params
) < 0) {
1888 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Could not copy GO Negotiation "
1893 ssid
= wpa_config_add_network(wpa_s
->conf
);
1895 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Could not add network for GO");
1899 wpa_s
->show_group_started
= 0;
1900 wpa_s
->p2p_go_group_formation_completed
= 0;
1901 wpa_s
->group_formation_reported
= 0;
1902 os_memset(wpa_s
->go_dev_addr
, 0, ETH_ALEN
);
1904 wpa_config_set_network_defaults(ssid
);
1905 ssid
->temporary
= 1;
1906 ssid
->p2p_group
= 1;
1907 ssid
->p2p_persistent_group
= !!params
->persistent_group
;
1908 ssid
->mode
= group_formation
? WPAS_MODE_P2P_GROUP_FORMATION
:
1910 ssid
->frequency
= params
->freq
;
1911 ssid
->ht40
= params
->ht40
;
1912 ssid
->vht
= params
->vht
;
1913 ssid
->max_oper_chwidth
= params
->max_oper_chwidth
;
1914 ssid
->vht_center_freq2
= params
->vht_center_freq2
;
1915 ssid
->ssid
= os_zalloc(params
->ssid_len
+ 1);
1917 os_memcpy(ssid
->ssid
, params
->ssid
, params
->ssid_len
);
1918 ssid
->ssid_len
= params
->ssid_len
;
1920 ssid
->auth_alg
= WPA_AUTH_ALG_OPEN
;
1921 ssid
->key_mgmt
= WPA_KEY_MGMT_PSK
;
1922 ssid
->proto
= WPA_PROTO_RSN
;
1923 ssid
->pairwise_cipher
= WPA_CIPHER_CCMP
;
1924 ssid
->group_cipher
= WPA_CIPHER_CCMP
;
1925 if (params
->freq
> 56160) {
1927 * Enable GCMP instead of CCMP as pairwise_cipher and
1928 * group_cipher in 60 GHz.
1930 ssid
->pairwise_cipher
= WPA_CIPHER_GCMP
;
1931 ssid
->group_cipher
= WPA_CIPHER_GCMP
;
1932 /* P2P GO in 60 GHz is always a PCP (PBSS) */
1935 if (os_strlen(params
->passphrase
) > 0) {
1936 ssid
->passphrase
= os_strdup(params
->passphrase
);
1937 if (ssid
->passphrase
== NULL
) {
1938 wpa_msg_global(wpa_s
, MSG_ERROR
,
1939 "P2P: Failed to copy passphrase for GO");
1940 wpa_config_remove_network(wpa_s
->conf
, ssid
->id
);
1944 ssid
->passphrase
= NULL
;
1945 ssid
->psk_set
= params
->psk_set
;
1947 os_memcpy(ssid
->psk
, params
->psk
, sizeof(ssid
->psk
));
1948 else if (ssid
->passphrase
)
1949 wpa_config_update_psk(ssid
);
1950 ssid
->ap_max_inactivity
= wpa_s
->p2pdev
->conf
->p2p_go_max_inactivity
;
1952 wpa_s
->ap_configured_cb
= p2p_go_configured
;
1953 wpa_s
->ap_configured_cb_ctx
= wpa_s
;
1954 wpa_s
->ap_configured_cb_data
= wpa_s
->go_params
;
1955 wpa_s
->scan_req
= NORMAL_SCAN_REQ
;
1956 wpa_s
->connect_without_scan
= ssid
;
1957 wpa_s
->reassociate
= 1;
1958 wpa_s
->disconnected
= 0;
1959 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Request scan (that will be skipped) to "
1961 wpa_supplicant_req_scan(wpa_s
, 0, 0);
1965 static void wpas_p2p_clone_config(struct wpa_supplicant
*dst
,
1966 const struct wpa_supplicant
*src
)
1968 struct wpa_config
*d
;
1969 const struct wpa_config
*s
;
1976 if (s->n && !d->n) \
1977 d->n = os_strdup(s->n); \
1988 os_memcpy(d
->device_type
, s
->device_type
, WPS_DEV_TYPE_LEN
);
1989 os_memcpy(d
->sec_device_type
, s
->sec_device_type
,
1990 sizeof(d
->sec_device_type
));
1991 d
->num_sec_device_types
= s
->num_sec_device_types
;
1993 d
->p2p_group_idle
= s
->p2p_group_idle
;
1994 d
->p2p_go_freq_change_policy
= s
->p2p_go_freq_change_policy
;
1995 d
->p2p_intra_bss
= s
->p2p_intra_bss
;
1996 d
->persistent_reconnect
= s
->persistent_reconnect
;
1997 d
->max_num_sta
= s
->max_num_sta
;
1998 d
->pbc_in_m1
= s
->pbc_in_m1
;
1999 d
->ignore_old_scan_res
= s
->ignore_old_scan_res
;
2000 d
->beacon_int
= s
->beacon_int
;
2001 d
->dtim_period
= s
->dtim_period
;
2002 d
->p2p_go_ctwindow
= s
->p2p_go_ctwindow
;
2003 d
->disassoc_low_ack
= s
->disassoc_low_ack
;
2004 d
->disable_scan_offload
= s
->disable_scan_offload
;
2005 d
->passive_scan
= s
->passive_scan
;
2007 if (s
->wps_nfc_dh_privkey
&& s
->wps_nfc_dh_pubkey
&&
2008 !d
->wps_nfc_pw_from_config
) {
2009 wpabuf_free(d
->wps_nfc_dh_privkey
);
2010 wpabuf_free(d
->wps_nfc_dh_pubkey
);
2011 d
->wps_nfc_dh_privkey
= wpabuf_dup(s
->wps_nfc_dh_privkey
);
2012 d
->wps_nfc_dh_pubkey
= wpabuf_dup(s
->wps_nfc_dh_pubkey
);
2014 d
->p2p_cli_probe
= s
->p2p_cli_probe
;
2015 d
->go_interworking
= s
->go_interworking
;
2016 d
->go_access_network_type
= s
->go_access_network_type
;
2017 d
->go_internet
= s
->go_internet
;
2018 d
->go_venue_group
= s
->go_venue_group
;
2019 d
->go_venue_type
= s
->go_venue_type
;
2023 static void wpas_p2p_get_group_ifname(struct wpa_supplicant
*wpa_s
,
2024 char *ifname
, size_t len
)
2026 char *ifname_ptr
= wpa_s
->ifname
;
2028 if (os_strncmp(wpa_s
->ifname
, P2P_MGMT_DEVICE_PREFIX
,
2029 os_strlen(P2P_MGMT_DEVICE_PREFIX
)) == 0) {
2030 ifname_ptr
= os_strrchr(wpa_s
->ifname
, '-') + 1;
2033 os_snprintf(ifname
, len
, "p2p-%s-%d", ifname_ptr
, wpa_s
->p2p_group_idx
);
2034 if (os_strlen(ifname
) >= IFNAMSIZ
&&
2035 os_strlen(wpa_s
->ifname
) < IFNAMSIZ
) {
2038 /* Try to avoid going over the IFNAMSIZ length limit */
2039 res
= os_snprintf(ifname
, len
, "p2p-%d", wpa_s
->p2p_group_idx
);
2040 if (os_snprintf_error(len
, res
) && len
)
2041 ifname
[len
- 1] = '\0';
2046 static int wpas_p2p_add_group_interface(struct wpa_supplicant
*wpa_s
,
2047 enum wpa_driver_if_type type
)
2049 char ifname
[120], force_ifname
[120];
2051 if (wpa_s
->pending_interface_name
[0]) {
2052 wpa_printf(MSG_DEBUG
, "P2P: Pending virtual interface exists "
2053 "- skip creation of a new one");
2054 if (is_zero_ether_addr(wpa_s
->pending_interface_addr
)) {
2055 wpa_printf(MSG_DEBUG
, "P2P: Pending virtual address "
2056 "unknown?! ifname='%s'",
2057 wpa_s
->pending_interface_name
);
2063 wpas_p2p_get_group_ifname(wpa_s
, ifname
, sizeof(ifname
));
2064 force_ifname
[0] = '\0';
2066 wpa_printf(MSG_DEBUG
, "P2P: Create a new interface %s for the group",
2068 wpa_s
->p2p_group_idx
++;
2070 wpa_s
->pending_interface_type
= type
;
2071 if (wpa_drv_if_add(wpa_s
, type
, ifname
, NULL
, NULL
, force_ifname
,
2072 wpa_s
->pending_interface_addr
, NULL
) < 0) {
2073 wpa_printf(MSG_ERROR
, "P2P: Failed to create new group "
2078 if (force_ifname
[0]) {
2079 wpa_printf(MSG_DEBUG
, "P2P: Driver forced interface name %s",
2081 os_strlcpy(wpa_s
->pending_interface_name
, force_ifname
,
2082 sizeof(wpa_s
->pending_interface_name
));
2084 os_strlcpy(wpa_s
->pending_interface_name
, ifname
,
2085 sizeof(wpa_s
->pending_interface_name
));
2086 wpa_printf(MSG_DEBUG
, "P2P: Created pending virtual interface %s addr "
2087 MACSTR
, wpa_s
->pending_interface_name
,
2088 MAC2STR(wpa_s
->pending_interface_addr
));
2094 static void wpas_p2p_remove_pending_group_interface(
2095 struct wpa_supplicant
*wpa_s
)
2097 if (!wpa_s
->pending_interface_name
[0] ||
2098 is_zero_ether_addr(wpa_s
->pending_interface_addr
))
2099 return; /* No pending virtual interface */
2101 wpa_printf(MSG_DEBUG
, "P2P: Removing pending group interface %s",
2102 wpa_s
->pending_interface_name
);
2103 wpa_drv_if_remove(wpa_s
, wpa_s
->pending_interface_type
,
2104 wpa_s
->pending_interface_name
);
2105 os_memset(wpa_s
->pending_interface_addr
, 0, ETH_ALEN
);
2106 wpa_s
->pending_interface_name
[0] = '\0';
2107 wpa_s
->global
->pending_group_iface_for_p2ps
= 0;
2111 static struct wpa_supplicant
*
2112 wpas_p2p_init_group_interface(struct wpa_supplicant
*wpa_s
, int go
)
2114 struct wpa_interface iface
;
2115 struct wpa_supplicant
*group_wpa_s
;
2117 if (!wpa_s
->pending_interface_name
[0]) {
2118 wpa_printf(MSG_ERROR
, "P2P: No pending group interface");
2119 if (!wpas_p2p_create_iface(wpa_s
))
2122 * Something has forced us to remove the pending interface; try
2123 * to create a new one and hope for the best that we will get
2124 * the same local address.
2126 if (wpas_p2p_add_group_interface(wpa_s
, go
? WPA_IF_P2P_GO
:
2127 WPA_IF_P2P_CLIENT
) < 0)
2131 os_memset(&iface
, 0, sizeof(iface
));
2132 iface
.ifname
= wpa_s
->pending_interface_name
;
2133 iface
.driver
= wpa_s
->driver
->name
;
2134 if (wpa_s
->conf
->ctrl_interface
== NULL
&&
2135 wpa_s
->parent
!= wpa_s
&&
2137 (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE
))
2138 iface
.ctrl_interface
= wpa_s
->parent
->conf
->ctrl_interface
;
2140 iface
.ctrl_interface
= wpa_s
->conf
->ctrl_interface
;
2141 iface
.driver_param
= wpa_s
->conf
->driver_param
;
2142 group_wpa_s
= wpa_supplicant_add_iface(wpa_s
->global
, &iface
, wpa_s
);
2143 if (group_wpa_s
== NULL
) {
2144 wpa_printf(MSG_ERROR
, "P2P: Failed to create new "
2145 "wpa_supplicant interface");
2148 wpa_s
->pending_interface_name
[0] = '\0';
2149 group_wpa_s
->p2p_group_interface
= go
? P2P_GROUP_INTERFACE_GO
:
2150 P2P_GROUP_INTERFACE_CLIENT
;
2151 wpa_s
->global
->p2p_group_formation
= group_wpa_s
;
2152 wpa_s
->global
->pending_group_iface_for_p2ps
= 0;
2154 wpas_p2p_clone_config(group_wpa_s
, wpa_s
);
2160 static void wpas_p2p_group_formation_timeout(void *eloop_ctx
,
2163 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
2164 wpa_printf(MSG_DEBUG
, "P2P: Group Formation timed out");
2165 wpas_p2p_group_formation_failed(wpa_s
, 0);
2169 static void wpas_p2p_group_formation_failed(struct wpa_supplicant
*wpa_s
,
2170 int already_deleted
)
2172 eloop_cancel_timeout(wpas_p2p_group_formation_timeout
,
2173 wpa_s
->p2pdev
, NULL
);
2174 if (wpa_s
->global
->p2p
)
2175 p2p_group_formation_failed(wpa_s
->global
->p2p
);
2176 wpas_group_formation_completed(wpa_s
, 0, already_deleted
);
2180 static void wpas_p2p_grpform_fail_after_wps(struct wpa_supplicant
*wpa_s
)
2182 wpa_printf(MSG_DEBUG
, "P2P: Reject group formation due to WPS provisioning failure");
2183 eloop_cancel_timeout(wpas_p2p_group_formation_timeout
,
2184 wpa_s
->p2pdev
, NULL
);
2185 eloop_register_timeout(0, 0, wpas_p2p_group_formation_timeout
,
2186 wpa_s
->p2pdev
, NULL
);
2187 wpa_s
->global
->p2p_fail_on_wps_complete
= 0;
2191 void wpas_p2p_ap_setup_failed(struct wpa_supplicant
*wpa_s
)
2193 if (wpa_s
->global
->p2p_group_formation
!= wpa_s
)
2195 /* Speed up group formation timeout since this cannot succeed */
2196 eloop_cancel_timeout(wpas_p2p_group_formation_timeout
,
2197 wpa_s
->p2pdev
, NULL
);
2198 eloop_register_timeout(0, 0, wpas_p2p_group_formation_timeout
,
2199 wpa_s
->p2pdev
, NULL
);
2203 static void wpas_go_neg_completed(void *ctx
, struct p2p_go_neg_results
*res
)
2205 struct wpa_supplicant
*wpa_s
= ctx
;
2206 struct wpa_supplicant
*group_wpa_s
;
2208 if (wpa_s
->off_channel_freq
|| wpa_s
->roc_waiting_drv_freq
) {
2209 wpa_drv_cancel_remain_on_channel(wpa_s
);
2210 wpa_s
->off_channel_freq
= 0;
2211 wpa_s
->roc_waiting_drv_freq
= 0;
2215 wpa_msg_global(wpa_s
, MSG_INFO
,
2216 P2P_EVENT_GO_NEG_FAILURE
"status=%d",
2218 wpas_notify_p2p_go_neg_completed(wpa_s
, res
);
2219 wpas_p2p_remove_pending_group_interface(wpa_s
);
2223 if (!res
->role_go
) {
2224 /* Inform driver of the operating channel of GO. */
2225 wpa_drv_set_prob_oper_freq(wpa_s
, res
->freq
);
2228 if (wpa_s
->p2p_go_ht40
)
2230 if (wpa_s
->p2p_go_vht
)
2232 res
->max_oper_chwidth
= wpa_s
->p2p_go_max_oper_chwidth
;
2233 res
->vht_center_freq2
= wpa_s
->p2p_go_vht_center_freq2
;
2235 wpa_msg_global(wpa_s
, MSG_INFO
, P2P_EVENT_GO_NEG_SUCCESS
"role=%s "
2236 "freq=%d ht40=%d peer_dev=" MACSTR
" peer_iface=" MACSTR
2238 res
->role_go
? "GO" : "client", res
->freq
, res
->ht40
,
2239 MAC2STR(res
->peer_device_addr
),
2240 MAC2STR(res
->peer_interface_addr
),
2241 p2p_wps_method_text(res
->wps_method
));
2242 wpas_notify_p2p_go_neg_completed(wpa_s
, res
);
2244 if (res
->role_go
&& wpa_s
->p2p_persistent_id
>= 0) {
2245 struct wpa_ssid
*ssid
;
2246 ssid
= wpa_config_get_network(wpa_s
->conf
,
2247 wpa_s
->p2p_persistent_id
);
2248 if (ssid
&& ssid
->disabled
== 2 &&
2249 ssid
->mode
== WPAS_MODE_P2P_GO
&& ssid
->passphrase
) {
2250 size_t len
= os_strlen(ssid
->passphrase
);
2251 wpa_printf(MSG_DEBUG
, "P2P: Override passphrase based "
2252 "on requested persistent group");
2253 os_memcpy(res
->passphrase
, ssid
->passphrase
, len
);
2254 res
->passphrase
[len
] = '\0';
2258 if (wpa_s
->create_p2p_iface
) {
2260 wpas_p2p_init_group_interface(wpa_s
, res
->role_go
);
2261 if (group_wpa_s
== NULL
) {
2262 wpas_p2p_remove_pending_group_interface(wpa_s
);
2263 eloop_cancel_timeout(wpas_p2p_long_listen_timeout
,
2265 wpas_p2p_group_formation_failed(wpa_s
, 1);
2268 os_memset(wpa_s
->pending_interface_addr
, 0, ETH_ALEN
);
2269 wpa_s
->pending_interface_name
[0] = '\0';
2271 group_wpa_s
= wpa_s
->parent
;
2272 wpa_s
->global
->p2p_group_formation
= group_wpa_s
;
2273 if (group_wpa_s
!= wpa_s
)
2274 wpas_p2p_clone_config(group_wpa_s
, wpa_s
);
2277 group_wpa_s
->p2p_in_provisioning
= 1;
2278 group_wpa_s
->p2pdev
= wpa_s
;
2279 if (group_wpa_s
!= wpa_s
) {
2280 os_memcpy(group_wpa_s
->p2p_pin
, wpa_s
->p2p_pin
,
2281 sizeof(group_wpa_s
->p2p_pin
));
2282 group_wpa_s
->p2p_wps_method
= wpa_s
->p2p_wps_method
;
2285 wpas_start_wps_go(group_wpa_s
, res
, 1);
2287 os_get_reltime(&group_wpa_s
->scan_min_time
);
2288 wpas_start_wps_enrollee(group_wpa_s
, res
);
2291 wpa_s
->p2p_long_listen
= 0;
2292 eloop_cancel_timeout(wpas_p2p_long_listen_timeout
, wpa_s
, NULL
);
2294 eloop_cancel_timeout(wpas_p2p_group_formation_timeout
, wpa_s
, NULL
);
2295 eloop_register_timeout(15 + res
->peer_config_timeout
/ 100,
2296 (res
->peer_config_timeout
% 100) * 10000,
2297 wpas_p2p_group_formation_timeout
, wpa_s
, NULL
);
2301 static void wpas_go_neg_req_rx(void *ctx
, const u8
*src
, u16 dev_passwd_id
,
2304 struct wpa_supplicant
*wpa_s
= ctx
;
2305 wpa_msg_global(wpa_s
, MSG_INFO
, P2P_EVENT_GO_NEG_REQUEST MACSTR
2306 " dev_passwd_id=%u go_intent=%u", MAC2STR(src
),
2307 dev_passwd_id
, go_intent
);
2309 wpas_notify_p2p_go_neg_req(wpa_s
, src
, dev_passwd_id
, go_intent
);
2313 static void wpas_dev_found(void *ctx
, const u8
*addr
,
2314 const struct p2p_peer_info
*info
,
2317 #ifndef CONFIG_NO_STDOUT_DEBUG
2318 struct wpa_supplicant
*wpa_s
= ctx
;
2319 char devtype
[WPS_DEV_TYPE_BUFSIZE
];
2320 char *wfd_dev_info_hex
= NULL
;
2322 #ifdef CONFIG_WIFI_DISPLAY
2323 wfd_dev_info_hex
= wifi_display_subelem_hex(info
->wfd_subelems
,
2324 WFD_SUBELEM_DEVICE_INFO
);
2325 #endif /* CONFIG_WIFI_DISPLAY */
2327 if (info
->p2ps_instance
) {
2329 const u8
*buf
= wpabuf_head(info
->p2ps_instance
);
2330 size_t len
= wpabuf_len(info
->p2ps_instance
);
2337 if (len
< 4 + 2 + 1)
2339 id
= WPA_GET_LE32(buf
);
2341 methods
= WPA_GET_BE16(buf
);
2344 if (str_len
> len
- 4 - 2 - 1)
2346 os_memcpy(str
, buf
, str_len
);
2347 str
[str_len
] = '\0';
2349 len
-= str_len
+ sizeof(u32
) + sizeof(u16
) + sizeof(u8
);
2351 wpa_msg_global(wpa_s
, MSG_INFO
,
2352 P2P_EVENT_DEVICE_FOUND MACSTR
2353 " p2p_dev_addr=" MACSTR
2354 " pri_dev_type=%s name='%s'"
2355 " config_methods=0x%x"
2358 " adv_id=%x asp_svc=%s%s",
2360 MAC2STR(info
->p2p_device_addr
),
2361 wps_dev_type_bin2str(
2363 devtype
, sizeof(devtype
)),
2364 info
->device_name
, methods
,
2365 info
->dev_capab
, info
->group_capab
,
2367 info
->vendor_elems
?
2368 " vendor_elems=1" : "");
2373 wpa_msg_global(wpa_s
, MSG_INFO
, P2P_EVENT_DEVICE_FOUND MACSTR
2374 " p2p_dev_addr=" MACSTR
2375 " pri_dev_type=%s name='%s' config_methods=0x%x "
2376 "dev_capab=0x%x group_capab=0x%x%s%s%s new=%d",
2377 MAC2STR(addr
), MAC2STR(info
->p2p_device_addr
),
2378 wps_dev_type_bin2str(info
->pri_dev_type
, devtype
,
2380 info
->device_name
, info
->config_methods
,
2381 info
->dev_capab
, info
->group_capab
,
2382 wfd_dev_info_hex
? " wfd_dev_info=0x" : "",
2383 wfd_dev_info_hex
? wfd_dev_info_hex
: "",
2384 info
->vendor_elems
? " vendor_elems=1" : "",
2388 os_free(wfd_dev_info_hex
);
2389 #endif /* CONFIG_NO_STDOUT_DEBUG */
2391 wpas_notify_p2p_device_found(ctx
, info
->p2p_device_addr
, new_device
);
2395 static void wpas_dev_lost(void *ctx
, const u8
*dev_addr
)
2397 struct wpa_supplicant
*wpa_s
= ctx
;
2399 wpa_msg_global(wpa_s
, MSG_INFO
, P2P_EVENT_DEVICE_LOST
2400 "p2p_dev_addr=" MACSTR
, MAC2STR(dev_addr
));
2402 wpas_notify_p2p_device_lost(wpa_s
, dev_addr
);
2406 static void wpas_find_stopped(void *ctx
)
2408 struct wpa_supplicant
*wpa_s
= ctx
;
2410 if (wpa_s
->p2p_scan_work
&& wpas_abort_ongoing_scan(wpa_s
) < 0)
2411 wpa_printf(MSG_DEBUG
, "P2P: Abort ongoing scan failed");
2413 wpa_msg_global(wpa_s
, MSG_INFO
, P2P_EVENT_FIND_STOPPED
);
2414 wpas_notify_p2p_find_stopped(wpa_s
);
2418 struct wpas_p2p_listen_work
{
2420 unsigned int duration
;
2421 struct wpabuf
*probe_resp_ie
;
2425 static void wpas_p2p_listen_work_free(struct wpas_p2p_listen_work
*lwork
)
2429 wpabuf_free(lwork
->probe_resp_ie
);
2434 static void wpas_p2p_listen_work_done(struct wpa_supplicant
*wpa_s
)
2436 struct wpas_p2p_listen_work
*lwork
;
2438 if (!wpa_s
->p2p_listen_work
)
2441 lwork
= wpa_s
->p2p_listen_work
->ctx
;
2442 wpas_p2p_listen_work_free(lwork
);
2443 radio_work_done(wpa_s
->p2p_listen_work
);
2444 wpa_s
->p2p_listen_work
= NULL
;
2448 static void wpas_start_listen_cb(struct wpa_radio_work
*work
, int deinit
)
2450 struct wpa_supplicant
*wpa_s
= work
->wpa_s
;
2451 struct wpas_p2p_listen_work
*lwork
= work
->ctx
;
2452 unsigned int duration
;
2455 if (work
->started
) {
2456 wpa_s
->p2p_listen_work
= NULL
;
2457 wpas_stop_listen(wpa_s
);
2459 wpas_p2p_listen_work_free(lwork
);
2463 wpa_s
->p2p_listen_work
= work
;
2465 wpa_drv_set_ap_wps_ie(wpa_s
, NULL
, lwork
->probe_resp_ie
, NULL
);
2467 if (wpa_drv_probe_req_report(wpa_s
, 1) < 0) {
2468 wpa_printf(MSG_DEBUG
, "P2P: Failed to request the driver to "
2469 "report received Probe Request frames");
2470 wpas_p2p_listen_work_done(wpa_s
);
2474 wpa_s
->pending_listen_freq
= lwork
->freq
;
2475 wpa_s
->pending_listen_duration
= lwork
->duration
;
2477 duration
= lwork
->duration
;
2478 #ifdef CONFIG_TESTING_OPTIONS
2479 if (wpa_s
->extra_roc_dur
) {
2480 wpa_printf(MSG_DEBUG
, "TESTING: Increase ROC duration %u -> %u",
2481 duration
, duration
+ wpa_s
->extra_roc_dur
);
2482 duration
+= wpa_s
->extra_roc_dur
;
2484 #endif /* CONFIG_TESTING_OPTIONS */
2486 if (wpa_drv_remain_on_channel(wpa_s
, lwork
->freq
, duration
) < 0) {
2487 wpa_printf(MSG_DEBUG
, "P2P: Failed to request the driver "
2488 "to remain on channel (%u MHz) for Listen "
2489 "state", lwork
->freq
);
2490 wpas_p2p_listen_work_done(wpa_s
);
2491 wpa_s
->pending_listen_freq
= 0;
2494 wpa_s
->off_channel_freq
= 0;
2495 wpa_s
->roc_waiting_drv_freq
= lwork
->freq
;
2499 static int wpas_start_listen(void *ctx
, unsigned int freq
,
2500 unsigned int duration
,
2501 const struct wpabuf
*probe_resp_ie
)
2503 struct wpa_supplicant
*wpa_s
= ctx
;
2504 struct wpas_p2p_listen_work
*lwork
;
2506 if (wpa_s
->p2p_listen_work
) {
2507 wpa_printf(MSG_DEBUG
, "P2P: Reject start_listen since p2p_listen_work already exists");
2511 lwork
= os_zalloc(sizeof(*lwork
));
2515 lwork
->duration
= duration
;
2516 if (probe_resp_ie
) {
2517 lwork
->probe_resp_ie
= wpabuf_dup(probe_resp_ie
);
2518 if (lwork
->probe_resp_ie
== NULL
) {
2519 wpas_p2p_listen_work_free(lwork
);
2524 if (radio_add_work(wpa_s
, freq
, "p2p-listen", 0, wpas_start_listen_cb
,
2526 wpas_p2p_listen_work_free(lwork
);
2534 static void wpas_stop_listen(void *ctx
)
2536 struct wpa_supplicant
*wpa_s
= ctx
;
2537 if (wpa_s
->off_channel_freq
|| wpa_s
->roc_waiting_drv_freq
) {
2538 wpa_drv_cancel_remain_on_channel(wpa_s
);
2539 wpa_s
->off_channel_freq
= 0;
2540 wpa_s
->roc_waiting_drv_freq
= 0;
2542 wpa_drv_set_ap_wps_ie(wpa_s
, NULL
, NULL
, NULL
);
2545 * Don't cancel Probe Request RX reporting for a connected P2P Client
2546 * handling Probe Request frames.
2548 if (!wpa_s
->p2p_cli_probe
)
2549 wpa_drv_probe_req_report(wpa_s
, 0);
2551 wpas_p2p_listen_work_done(wpa_s
);
2555 static int wpas_send_probe_resp(void *ctx
, const struct wpabuf
*buf
,
2558 struct wpa_supplicant
*wpa_s
= ctx
;
2559 return wpa_drv_send_mlme(wpa_s
, wpabuf_head(buf
), wpabuf_len(buf
), 1,
2564 static void wpas_prov_disc_local_display(struct wpa_supplicant
*wpa_s
,
2565 const u8
*peer
, const char *params
,
2566 unsigned int generated_pin
)
2568 wpa_msg_global(wpa_s
, MSG_INFO
, P2P_EVENT_PROV_DISC_SHOW_PIN MACSTR
2569 " %08d%s", MAC2STR(peer
), generated_pin
, params
);
2573 static void wpas_prov_disc_local_keypad(struct wpa_supplicant
*wpa_s
,
2574 const u8
*peer
, const char *params
)
2576 wpa_msg_global(wpa_s
, MSG_INFO
, P2P_EVENT_PROV_DISC_ENTER_PIN MACSTR
2577 "%s", MAC2STR(peer
), params
);
2581 static void wpas_prov_disc_req(void *ctx
, const u8
*peer
, u16 config_methods
,
2582 const u8
*dev_addr
, const u8
*pri_dev_type
,
2583 const char *dev_name
, u16 supp_config_methods
,
2584 u8 dev_capab
, u8 group_capab
, const u8
*group_id
,
2585 size_t group_id_len
)
2587 struct wpa_supplicant
*wpa_s
= ctx
;
2588 char devtype
[WPS_DEV_TYPE_BUFSIZE
];
2590 u8 empty_dev_type
[8];
2591 unsigned int generated_pin
= 0;
2592 struct wpa_supplicant
*group
= NULL
;
2596 for (group
= wpa_s
->global
->ifaces
; group
; group
= group
->next
)
2598 struct wpa_ssid
*s
= group
->current_ssid
;
2600 s
->mode
== WPAS_MODE_P2P_GO
&&
2601 group_id_len
- ETH_ALEN
== s
->ssid_len
&&
2602 os_memcmp(group_id
+ ETH_ALEN
, s
->ssid
,
2608 if (pri_dev_type
== NULL
) {
2609 os_memset(empty_dev_type
, 0, sizeof(empty_dev_type
));
2610 pri_dev_type
= empty_dev_type
;
2612 res
= os_snprintf(params
, sizeof(params
), " p2p_dev_addr=" MACSTR
2613 " pri_dev_type=%s name='%s' config_methods=0x%x "
2614 "dev_capab=0x%x group_capab=0x%x%s%s",
2616 wps_dev_type_bin2str(pri_dev_type
, devtype
,
2618 dev_name
, supp_config_methods
, dev_capab
, group_capab
,
2619 group
? " group=" : "",
2620 group
? group
->ifname
: "");
2621 if (os_snprintf_error(sizeof(params
), res
))
2622 wpa_printf(MSG_DEBUG
, "P2P: PD Request event truncated");
2623 params
[sizeof(params
) - 1] = '\0';
2625 if (config_methods
& WPS_CONFIG_DISPLAY
) {
2626 if (wps_generate_pin(&generated_pin
) < 0) {
2627 wpa_printf(MSG_DEBUG
, "P2P: Could not generate PIN");
2628 wpas_notify_p2p_provision_discovery(
2629 wpa_s
, peer
, 0 /* response */,
2630 P2P_PROV_DISC_INFO_UNAVAILABLE
, 0, 0);
2633 wpas_prov_disc_local_display(wpa_s
, peer
, params
,
2635 } else if (config_methods
& WPS_CONFIG_KEYPAD
)
2636 wpas_prov_disc_local_keypad(wpa_s
, peer
, params
);
2637 else if (config_methods
& WPS_CONFIG_PUSHBUTTON
)
2638 wpa_msg_global(wpa_s
, MSG_INFO
, P2P_EVENT_PROV_DISC_PBC_REQ
2639 MACSTR
"%s", MAC2STR(peer
), params
);
2641 wpas_notify_p2p_provision_discovery(wpa_s
, peer
, 1 /* request */,
2642 P2P_PROV_DISC_SUCCESS
,
2643 config_methods
, generated_pin
);
2647 static void wpas_prov_disc_resp(void *ctx
, const u8
*peer
, u16 config_methods
)
2649 struct wpa_supplicant
*wpa_s
= ctx
;
2650 unsigned int generated_pin
= 0;
2653 if (wpa_s
->pending_pd_before_join
&&
2654 (os_memcmp(peer
, wpa_s
->pending_join_dev_addr
, ETH_ALEN
) == 0 ||
2655 os_memcmp(peer
, wpa_s
->pending_join_iface_addr
, ETH_ALEN
) == 0)) {
2656 wpa_s
->pending_pd_before_join
= 0;
2657 wpa_printf(MSG_DEBUG
, "P2P: Starting pending "
2658 "join-existing-group operation");
2659 wpas_p2p_join_start(wpa_s
, 0, NULL
, 0);
2663 if (wpa_s
->pending_pd_use
== AUTO_PD_JOIN
||
2664 wpa_s
->pending_pd_use
== AUTO_PD_GO_NEG
) {
2667 res
= os_snprintf(params
, sizeof(params
), " peer_go=%d",
2668 wpa_s
->pending_pd_use
== AUTO_PD_JOIN
);
2669 if (os_snprintf_error(sizeof(params
), res
))
2670 params
[sizeof(params
) - 1] = '\0';
2674 if (config_methods
& WPS_CONFIG_DISPLAY
)
2675 wpas_prov_disc_local_keypad(wpa_s
, peer
, params
);
2676 else if (config_methods
& WPS_CONFIG_KEYPAD
) {
2677 if (wps_generate_pin(&generated_pin
) < 0) {
2678 wpa_printf(MSG_DEBUG
, "P2P: Could not generate PIN");
2679 wpas_notify_p2p_provision_discovery(
2680 wpa_s
, peer
, 0 /* response */,
2681 P2P_PROV_DISC_INFO_UNAVAILABLE
, 0, 0);
2684 wpas_prov_disc_local_display(wpa_s
, peer
, params
,
2686 } else if (config_methods
& WPS_CONFIG_PUSHBUTTON
)
2687 wpa_msg_global(wpa_s
, MSG_INFO
, P2P_EVENT_PROV_DISC_PBC_RESP
2688 MACSTR
"%s", MAC2STR(peer
), params
);
2690 wpas_notify_p2p_provision_discovery(wpa_s
, peer
, 0 /* response */,
2691 P2P_PROV_DISC_SUCCESS
,
2692 config_methods
, generated_pin
);
2696 static void wpas_prov_disc_fail(void *ctx
, const u8
*peer
,
2697 enum p2p_prov_disc_status status
,
2698 u32 adv_id
, const u8
*adv_mac
,
2699 const char *deferred_session_resp
)
2701 struct wpa_supplicant
*wpa_s
= ctx
;
2703 if (wpa_s
->p2p_fallback_to_go_neg
) {
2704 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: PD for p2p_connect-auto "
2705 "failed - fall back to GO Negotiation");
2706 wpa_msg_global(wpa_s
->p2pdev
, MSG_INFO
,
2707 P2P_EVENT_FALLBACK_TO_GO_NEG
2708 "reason=PD-failed");
2709 wpas_p2p_fallback_to_go_neg(wpa_s
, 0);
2713 if (status
== P2P_PROV_DISC_TIMEOUT_JOIN
) {
2714 wpa_s
->pending_pd_before_join
= 0;
2715 wpa_printf(MSG_DEBUG
, "P2P: Starting pending "
2716 "join-existing-group operation (no ACK for PD "
2718 wpas_p2p_join_start(wpa_s
, 0, NULL
, 0);
2722 if (adv_id
&& adv_mac
&& deferred_session_resp
) {
2723 wpa_msg_global(wpa_s
, MSG_INFO
, P2P_EVENT_PROV_DISC_FAILURE
2724 " p2p_dev_addr=" MACSTR
" status=%d adv_id=%x"
2725 " deferred_session_resp='%s'",
2726 MAC2STR(peer
), status
, adv_id
,
2727 deferred_session_resp
);
2728 } else if (adv_id
&& adv_mac
) {
2729 wpa_msg_global(wpa_s
, MSG_INFO
, P2P_EVENT_PROV_DISC_FAILURE
2730 " p2p_dev_addr=" MACSTR
" status=%d adv_id=%x",
2731 MAC2STR(peer
), status
, adv_id
);
2733 wpa_msg_global(wpa_s
, MSG_INFO
, P2P_EVENT_PROV_DISC_FAILURE
2734 " p2p_dev_addr=" MACSTR
" status=%d",
2735 MAC2STR(peer
), status
);
2738 wpas_notify_p2p_provision_discovery(wpa_s
, peer
, 0 /* response */,
2743 static int freq_included(struct wpa_supplicant
*wpa_s
,
2744 const struct p2p_channels
*channels
,
2747 if ((channels
== NULL
|| p2p_channels_includes_freq(channels
, freq
)) &&
2748 wpas_p2p_go_is_peer_freq(wpa_s
, freq
))
2754 static void wpas_p2p_go_update_common_freqs(struct wpa_supplicant
*wpa_s
)
2756 unsigned int num
= P2P_MAX_CHANNELS
;
2760 p2p_go_dump_common_freqs(wpa_s
);
2761 common_freqs
= os_calloc(num
, sizeof(int));
2765 ret
= p2p_group_get_common_freqs(wpa_s
->p2p_group
, common_freqs
, &num
);
2767 wpa_dbg(wpa_s
, MSG_DEBUG
,
2768 "P2P: Failed to get group common freqs");
2769 os_free(common_freqs
);
2773 os_free(wpa_s
->p2p_group_common_freqs
);
2774 wpa_s
->p2p_group_common_freqs
= common_freqs
;
2775 wpa_s
->p2p_group_common_freqs_num
= num
;
2776 p2p_go_dump_common_freqs(wpa_s
);
2781 * Check if the given frequency is one of the possible operating frequencies
2782 * set after the completion of the GO Negotiation.
2784 static int wpas_p2p_go_is_peer_freq(struct wpa_supplicant
*wpa_s
, int freq
)
2788 p2p_go_dump_common_freqs(wpa_s
);
2790 /* assume no restrictions */
2791 if (!wpa_s
->p2p_group_common_freqs_num
)
2794 for (i
= 0; i
< wpa_s
->p2p_group_common_freqs_num
; i
++) {
2795 if (wpa_s
->p2p_group_common_freqs
[i
] == freq
)
2802 static int wpas_sta_check_ecsa(struct hostapd_data
*hapd
,
2803 struct sta_info
*sta
, void *ctx
)
2805 int *ecsa_support
= ctx
;
2807 *ecsa_support
&= sta
->ecsa_supported
;
2813 /* Check if all the peers support eCSA */
2814 static int wpas_p2p_go_clients_support_ecsa(struct wpa_supplicant
*wpa_s
)
2816 int ecsa_support
= 1;
2818 ap_for_each_sta(wpa_s
->ap_iface
->bss
[0], wpas_sta_check_ecsa
,
2821 return ecsa_support
;
2826 * Pick the best frequency to use from all the currently used frequencies.
2828 static int wpas_p2p_pick_best_used_freq(struct wpa_supplicant
*wpa_s
,
2829 struct wpa_used_freq_data
*freqs
,
2834 /* find a candidate freq that is supported by P2P */
2835 for (c
= 0; c
< num
; c
++)
2836 if (p2p_supported_freq(wpa_s
->global
->p2p
, freqs
[c
].freq
))
2842 /* once we have a candidate, try to find a 'better' one */
2843 for (i
= c
+ 1; i
< num
; i
++) {
2844 if (!p2p_supported_freq(wpa_s
->global
->p2p
, freqs
[i
].freq
))
2848 * 1. Infrastructure station interfaces have higher preference.
2849 * 2. P2P Clients have higher preference.
2852 if (freqs
[i
].flags
& WPA_FREQ_USED_BY_INFRA_STATION
) {
2857 if ((freqs
[i
].flags
& WPA_FREQ_USED_BY_P2P_CLIENT
))
2860 return freqs
[c
].freq
;
2864 static u8
wpas_invitation_process(void *ctx
, const u8
*sa
, const u8
*bssid
,
2865 const u8
*go_dev_addr
, const u8
*ssid
,
2866 size_t ssid_len
, int *go
, u8
*group_bssid
,
2867 int *force_freq
, int persistent_group
,
2868 const struct p2p_channels
*channels
,
2871 struct wpa_supplicant
*wpa_s
= ctx
;
2873 struct wpa_used_freq_data
*freqs
;
2874 struct wpa_supplicant
*grp
;
2877 if (!persistent_group
) {
2878 wpa_printf(MSG_DEBUG
, "P2P: Invitation from " MACSTR
2879 " to join an active group (SSID: %s)",
2880 MAC2STR(sa
), wpa_ssid_txt(ssid
, ssid_len
));
2881 if (!is_zero_ether_addr(wpa_s
->p2p_auth_invite
) &&
2882 (os_memcmp(go_dev_addr
, wpa_s
->p2p_auth_invite
, ETH_ALEN
)
2884 os_memcmp(sa
, wpa_s
->p2p_auth_invite
, ETH_ALEN
) == 0)) {
2885 wpa_printf(MSG_DEBUG
, "P2P: Accept previously "
2886 "authorized invitation");
2890 #ifdef CONFIG_WPS_NFC
2891 if (dev_pw_id
>= 0 && wpa_s
->p2p_nfc_tag_enabled
&&
2892 dev_pw_id
== wpa_s
->p2p_oob_dev_pw_id
) {
2893 wpa_printf(MSG_DEBUG
, "P2P: Accept invitation based on local enabled NFC Tag");
2894 wpa_s
->p2p_wps_method
= WPS_NFC
;
2895 wpa_s
->pending_join_wps_method
= WPS_NFC
;
2896 os_memcpy(wpa_s
->pending_join_dev_addr
,
2897 go_dev_addr
, ETH_ALEN
);
2898 os_memcpy(wpa_s
->pending_join_iface_addr
,
2902 #endif /* CONFIG_WPS_NFC */
2905 * Do not accept the invitation automatically; notify user and
2908 return P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE
;
2911 grp
= wpas_get_p2p_group(wpa_s
, ssid
, ssid_len
, go
);
2913 wpa_printf(MSG_DEBUG
, "P2P: Accept invitation to already "
2914 "running persistent group");
2916 os_memcpy(group_bssid
, grp
->own_addr
, ETH_ALEN
);
2920 if (!is_zero_ether_addr(wpa_s
->p2p_auth_invite
) &&
2921 os_memcmp(sa
, wpa_s
->p2p_auth_invite
, ETH_ALEN
) == 0) {
2922 wpa_printf(MSG_DEBUG
, "P2P: Accept previously initiated "
2923 "invitation to re-invoke a persistent group");
2924 os_memset(wpa_s
->p2p_auth_invite
, 0, ETH_ALEN
);
2925 } else if (!wpa_s
->conf
->persistent_reconnect
)
2926 return P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE
;
2928 for (s
= wpa_s
->conf
->ssid
; s
; s
= s
->next
) {
2929 if (s
->disabled
== 2 &&
2930 os_memcmp(s
->bssid
, go_dev_addr
, ETH_ALEN
) == 0 &&
2931 s
->ssid_len
== ssid_len
&&
2932 os_memcmp(ssid
, s
->ssid
, ssid_len
) == 0)
2937 wpa_printf(MSG_DEBUG
, "P2P: Invitation from " MACSTR
2938 " requested reinvocation of an unknown group",
2940 return P2P_SC_FAIL_UNKNOWN_GROUP
;
2943 if (s
->mode
== WPAS_MODE_P2P_GO
&& !wpas_p2p_create_iface(wpa_s
)) {
2945 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
) {
2946 wpa_printf(MSG_DEBUG
, "P2P: The only available "
2947 "interface is already in use - reject "
2949 return P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE
;
2951 if (wpa_s
->p2p_mgmt
)
2952 os_memcpy(group_bssid
, wpa_s
->parent
->own_addr
,
2955 os_memcpy(group_bssid
, wpa_s
->own_addr
, ETH_ALEN
);
2956 } else if (s
->mode
== WPAS_MODE_P2P_GO
) {
2958 if (wpas_p2p_add_group_interface(wpa_s
, WPA_IF_P2P_GO
) < 0)
2960 wpa_printf(MSG_ERROR
, "P2P: Failed to allocate a new "
2961 "interface address for the group");
2962 return P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE
;
2964 os_memcpy(group_bssid
, wpa_s
->pending_interface_addr
,
2969 wpas_p2p_set_own_freq_preference(wpa_s
, 0);
2972 freqs
= os_calloc(wpa_s
->num_multichan_concurrent
,
2973 sizeof(struct wpa_used_freq_data
));
2975 int num_channels
= wpa_s
->num_multichan_concurrent
;
2976 int num
= wpas_p2p_valid_oper_freqs(wpa_s
, freqs
, num_channels
);
2977 best_freq
= wpas_p2p_pick_best_used_freq(wpa_s
, freqs
, num
);
2981 /* Get one of the frequencies currently in use */
2982 if (best_freq
> 0) {
2983 wpa_printf(MSG_DEBUG
, "P2P: Trying to prefer a channel already used by one of the interfaces");
2984 wpas_p2p_set_own_freq_preference(wpa_s
, best_freq
);
2986 if (wpa_s
->num_multichan_concurrent
< 2 ||
2987 wpas_p2p_num_unused_channels(wpa_s
) < 1) {
2988 wpa_printf(MSG_DEBUG
, "P2P: No extra channels available - trying to force channel to match a channel already used by one of the interfaces");
2989 *force_freq
= best_freq
;
2993 if (*force_freq
> 0 && wpa_s
->num_multichan_concurrent
> 1 &&
2994 wpas_p2p_num_unused_channels(wpa_s
) > 0) {
2996 /* We are the client */
2997 wpa_printf(MSG_DEBUG
, "P2P: Peer was found to be "
2998 "running a GO but we are capable of MCC, "
2999 "figure out the best channel to use");
3001 } else if (!freq_included(wpa_s
, channels
, *force_freq
)) {
3002 /* We are the GO, and *force_freq is not in the
3004 wpa_printf(MSG_DEBUG
, "P2P: Forced GO freq %d MHz not "
3005 "in intersection but we are capable of MCC, "
3006 "figure out the best channel to use",
3012 return P2P_SC_SUCCESS
;
3016 static void wpas_invitation_received(void *ctx
, const u8
*sa
, const u8
*bssid
,
3017 const u8
*ssid
, size_t ssid_len
,
3018 const u8
*go_dev_addr
, u8 status
,
3021 struct wpa_supplicant
*wpa_s
= ctx
;
3024 for (s
= wpa_s
->conf
->ssid
; s
; s
= s
->next
) {
3025 if (s
->disabled
== 2 &&
3026 s
->ssid_len
== ssid_len
&&
3027 os_memcmp(ssid
, s
->ssid
, ssid_len
) == 0)
3031 if (status
== P2P_SC_SUCCESS
) {
3032 wpa_printf(MSG_DEBUG
, "P2P: Invitation from peer " MACSTR
3033 " was accepted; op_freq=%d MHz, SSID=%s",
3034 MAC2STR(sa
), op_freq
, wpa_ssid_txt(ssid
, ssid_len
));
3036 int go
= s
->mode
== WPAS_MODE_P2P_GO
;
3038 wpa_msg_global(wpa_s
, MSG_INFO
,
3039 P2P_EVENT_INVITATION_ACCEPTED
3041 " persistent=%d freq=%d",
3042 MAC2STR(sa
), s
->id
, op_freq
);
3044 wpa_msg_global(wpa_s
, MSG_INFO
,
3045 P2P_EVENT_INVITATION_ACCEPTED
3048 MAC2STR(sa
), s
->id
);
3050 wpas_p2p_group_add_persistent(
3051 wpa_s
, s
, go
, 0, op_freq
, 0, 0, 0, 0, NULL
,
3052 go
? P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE
: 0,
3055 wpa_s
->user_initiated_pd
= 0;
3056 wpa_msg_global(wpa_s
, MSG_INFO
,
3057 P2P_EVENT_INVITATION_ACCEPTED
3058 "sa=" MACSTR
" go_dev_addr=" MACSTR
3059 " bssid=" MACSTR
" unknown-network",
3060 MAC2STR(sa
), MAC2STR(go_dev_addr
),
3062 wpas_p2p_join(wpa_s
, bssid
, go_dev_addr
,
3063 wpa_s
->p2p_wps_method
, 0, op_freq
,
3069 if (status
!= P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE
) {
3070 wpa_printf(MSG_DEBUG
, "P2P: Invitation from peer " MACSTR
3071 " was rejected (status %u)", MAC2STR(sa
), status
);
3077 wpa_msg_global(wpa_s
, MSG_INFO
,
3078 P2P_EVENT_INVITATION_RECEIVED
3079 "sa=" MACSTR
" go_dev_addr=" MACSTR
3080 " bssid=" MACSTR
" unknown-network",
3081 MAC2STR(sa
), MAC2STR(go_dev_addr
),
3084 wpa_msg_global(wpa_s
, MSG_INFO
,
3085 P2P_EVENT_INVITATION_RECEIVED
3086 "sa=" MACSTR
" go_dev_addr=" MACSTR
3088 MAC2STR(sa
), MAC2STR(go_dev_addr
));
3090 wpas_notify_p2p_invitation_received(wpa_s
, sa
, go_dev_addr
,
3095 if (s
->mode
== WPAS_MODE_P2P_GO
&& op_freq
) {
3096 wpa_msg_global(wpa_s
, MSG_INFO
, P2P_EVENT_INVITATION_RECEIVED
3097 "sa=" MACSTR
" persistent=%d freq=%d",
3098 MAC2STR(sa
), s
->id
, op_freq
);
3100 wpa_msg_global(wpa_s
, MSG_INFO
, P2P_EVENT_INVITATION_RECEIVED
3101 "sa=" MACSTR
" persistent=%d",
3102 MAC2STR(sa
), s
->id
);
3104 wpas_notify_p2p_invitation_received(wpa_s
, sa
, go_dev_addr
, bssid
,
3109 static void wpas_remove_persistent_peer(struct wpa_supplicant
*wpa_s
,
3110 struct wpa_ssid
*ssid
,
3111 const u8
*peer
, int inv
)
3114 struct wpa_supplicant
*p2p_wpa_s
= wpa_s
->global
->p2p_init_wpa_s
;
3119 for (i
= 0; ssid
->p2p_client_list
&& i
< ssid
->num_p2p_clients
; i
++) {
3120 if (os_memcmp(ssid
->p2p_client_list
+ i
* 2 * ETH_ALEN
, peer
,
3124 if (i
>= ssid
->num_p2p_clients
|| !ssid
->p2p_client_list
) {
3125 if (ssid
->mode
!= WPAS_MODE_P2P_GO
&&
3126 os_memcmp(ssid
->bssid
, peer
, ETH_ALEN
) == 0) {
3127 wpa_printf(MSG_DEBUG
, "P2P: Remove persistent group %d "
3128 "due to invitation result", ssid
->id
);
3129 wpas_notify_network_removed(wpa_s
, ssid
);
3130 wpa_config_remove_network(wpa_s
->conf
, ssid
->id
);
3133 return; /* Peer not found in client list */
3136 wpa_printf(MSG_DEBUG
, "P2P: Remove peer " MACSTR
" from persistent "
3137 "group %d client list%s",
3138 MAC2STR(peer
), ssid
->id
,
3139 inv
? " due to invitation result" : "");
3140 os_memmove(ssid
->p2p_client_list
+ i
* 2 * ETH_ALEN
,
3141 ssid
->p2p_client_list
+ (i
+ 1) * 2 * ETH_ALEN
,
3142 (ssid
->num_p2p_clients
- i
- 1) * 2 * ETH_ALEN
);
3143 ssid
->num_p2p_clients
--;
3144 if (p2p_wpa_s
->conf
->update_config
&&
3145 wpa_config_write(p2p_wpa_s
->confname
, p2p_wpa_s
->conf
))
3146 wpa_printf(MSG_DEBUG
, "P2P: Failed to update configuration");
3150 static void wpas_remove_persistent_client(struct wpa_supplicant
*wpa_s
,
3153 struct wpa_ssid
*ssid
;
3155 wpa_s
= wpa_s
->global
->p2p_invite_group
;
3157 return; /* No known invitation group */
3158 ssid
= wpa_s
->current_ssid
;
3159 if (ssid
== NULL
|| ssid
->mode
!= WPAS_MODE_P2P_GO
||
3160 !ssid
->p2p_persistent_group
)
3161 return; /* Not operating as a GO in persistent group */
3162 ssid
= wpas_p2p_get_persistent(wpa_s
->p2pdev
, peer
,
3163 ssid
->ssid
, ssid
->ssid_len
);
3164 wpas_remove_persistent_peer(wpa_s
, ssid
, peer
, 1);
3168 static void wpas_invitation_result(void *ctx
, int status
, const u8
*bssid
,
3169 const struct p2p_channels
*channels
,
3170 const u8
*peer
, int neg_freq
,
3173 struct wpa_supplicant
*wpa_s
= ctx
;
3174 struct wpa_ssid
*ssid
;
3178 wpa_msg_global(wpa_s
, MSG_INFO
, P2P_EVENT_INVITATION_RESULT
3179 "status=%d " MACSTR
,
3180 status
, MAC2STR(bssid
));
3182 wpa_msg_global(wpa_s
, MSG_INFO
, P2P_EVENT_INVITATION_RESULT
3183 "status=%d ", status
);
3185 wpas_notify_p2p_invitation_result(wpa_s
, status
, bssid
);
3187 wpa_printf(MSG_DEBUG
, "P2P: Invitation result - status=%d peer=" MACSTR
,
3188 status
, MAC2STR(peer
));
3189 if (wpa_s
->pending_invite_ssid_id
== -1) {
3190 struct wpa_supplicant
*group_if
=
3191 wpa_s
->global
->p2p_invite_group
;
3193 if (status
== P2P_SC_FAIL_UNKNOWN_GROUP
)
3194 wpas_remove_persistent_client(wpa_s
, peer
);
3197 * Invitation to an active group. If this is successful and we
3198 * are the GO, set the client wait to postpone some concurrent
3199 * operations and to allow provisioning and connection to happen
3202 if (status
== P2P_SC_SUCCESS
&&
3203 group_if
&& group_if
->current_ssid
&&
3204 group_if
->current_ssid
->mode
== WPAS_MODE_P2P_GO
) {
3205 os_get_reltime(&wpa_s
->global
->p2p_go_wait_client
);
3206 #ifdef CONFIG_TESTING_OPTIONS
3207 if (group_if
->p2p_go_csa_on_inv
) {
3208 wpa_printf(MSG_DEBUG
,
3209 "Testing: force P2P GO CSA after invitation");
3210 eloop_cancel_timeout(
3211 wpas_p2p_reconsider_moving_go
,
3213 eloop_register_timeout(
3215 wpas_p2p_reconsider_moving_go
,
3218 #endif /* CONFIG_TESTING_OPTIONS */
3223 if (status
== P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE
) {
3224 wpa_printf(MSG_DEBUG
, "P2P: Waiting for peer to start another "
3225 "invitation exchange to indicate readiness for "
3229 if (status
!= P2P_SC_SUCCESS
) {
3230 if (status
== P2P_SC_FAIL_UNKNOWN_GROUP
) {
3231 ssid
= wpa_config_get_network(
3232 wpa_s
->conf
, wpa_s
->pending_invite_ssid_id
);
3233 wpas_remove_persistent_peer(wpa_s
, ssid
, peer
, 1);
3235 wpas_p2p_remove_pending_group_interface(wpa_s
);
3239 ssid
= wpa_config_get_network(wpa_s
->conf
,
3240 wpa_s
->pending_invite_ssid_id
);
3242 wpa_printf(MSG_ERROR
, "P2P: Could not find persistent group "
3243 "data matching with invitation");
3248 * The peer could have missed our ctrl::ack frame for Invitation
3249 * Response and continue retransmitting the frame. To reduce the
3250 * likelihood of the peer not getting successful TX status for the
3251 * Invitation Response frame, wait a short time here before starting
3252 * the persistent group so that we will remain on the current channel to
3253 * acknowledge any possible retransmission from the peer.
3255 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: 50 ms wait on current channel before "
3256 "starting persistent group");
3259 if (neg_freq
> 0 && ssid
->mode
== WPAS_MODE_P2P_GO
&&
3260 freq_included(wpa_s
, channels
, neg_freq
))
3262 else if (peer_oper_freq
> 0 && ssid
->mode
!= WPAS_MODE_P2P_GO
&&
3263 freq_included(wpa_s
, channels
, peer_oper_freq
))
3264 freq
= peer_oper_freq
;
3268 wpa_printf(MSG_DEBUG
, "P2P: Persistent group invitation success - op_freq=%d MHz SSID=%s",
3269 freq
, wpa_ssid_txt(ssid
->ssid
, ssid
->ssid_len
));
3270 wpas_p2p_group_add_persistent(wpa_s
, ssid
,
3271 ssid
->mode
== WPAS_MODE_P2P_GO
,
3272 wpa_s
->p2p_persistent_go_freq
,
3274 wpa_s
->p2p_go_vht_center_freq2
,
3275 wpa_s
->p2p_go_ht40
, wpa_s
->p2p_go_vht
,
3276 wpa_s
->p2p_go_max_oper_chwidth
,
3278 ssid
->mode
== WPAS_MODE_P2P_GO
?
3279 P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE
:
3284 static int wpas_p2p_disallowed_freq(struct wpa_global
*global
,
3287 if (freq_range_list_includes(&global
->p2p_go_avoid_freq
, freq
))
3289 return freq_range_list_includes(&global
->p2p_disallow_freq
, freq
);
3293 static void wpas_p2p_add_chan(struct p2p_reg_class
*reg
, u8 chan
)
3295 reg
->channel
[reg
->channels
] = chan
;
3300 static int wpas_p2p_default_channels(struct wpa_supplicant
*wpa_s
,
3301 struct p2p_channels
*chan
,
3302 struct p2p_channels
*cli_chan
)
3306 wpa_s
->global
->p2p_24ghz_social_channels
= 1;
3308 os_memset(cli_chan
, 0, sizeof(*cli_chan
));
3310 wpa_printf(MSG_DEBUG
, "P2P: Enable operating classes for 2.4 GHz "
3313 /* Operating class 81 - 2.4 GHz band channels 1..13 */
3314 chan
->reg_class
[cla
].reg_class
= 81;
3315 chan
->reg_class
[cla
].channels
= 0;
3316 for (i
= 0; i
< 11; i
++) {
3317 if (!wpas_p2p_disallowed_freq(wpa_s
->global
, 2412 + i
* 5))
3318 wpas_p2p_add_chan(&chan
->reg_class
[cla
], i
+ 1);
3320 if (chan
->reg_class
[cla
].channels
)
3323 wpa_printf(MSG_DEBUG
, "P2P: Enable operating classes for lower 5 GHz "
3326 /* Operating class 115 - 5 GHz, channels 36-48 */
3327 chan
->reg_class
[cla
].reg_class
= 115;
3328 chan
->reg_class
[cla
].channels
= 0;
3329 if (!wpas_p2p_disallowed_freq(wpa_s
->global
, 5000 + 36 * 5))
3330 wpas_p2p_add_chan(&chan
->reg_class
[cla
], 36);
3331 if (!wpas_p2p_disallowed_freq(wpa_s
->global
, 5000 + 40 * 5))
3332 wpas_p2p_add_chan(&chan
->reg_class
[cla
], 40);
3333 if (!wpas_p2p_disallowed_freq(wpa_s
->global
, 5000 + 44 * 5))
3334 wpas_p2p_add_chan(&chan
->reg_class
[cla
], 44);
3335 if (!wpas_p2p_disallowed_freq(wpa_s
->global
, 5000 + 48 * 5))
3336 wpas_p2p_add_chan(&chan
->reg_class
[cla
], 48);
3337 if (chan
->reg_class
[cla
].channels
)
3340 wpa_printf(MSG_DEBUG
, "P2P: Enable operating classes for higher 5 GHz "
3343 /* Operating class 124 - 5 GHz, channels 149,153,157,161 */
3344 chan
->reg_class
[cla
].reg_class
= 124;
3345 chan
->reg_class
[cla
].channels
= 0;
3346 if (!wpas_p2p_disallowed_freq(wpa_s
->global
, 5000 + 149 * 5))
3347 wpas_p2p_add_chan(&chan
->reg_class
[cla
], 149);
3348 if (!wpas_p2p_disallowed_freq(wpa_s
->global
, 5000 + 153 * 5))
3349 wpas_p2p_add_chan(&chan
->reg_class
[cla
], 153);
3350 if (!wpas_p2p_disallowed_freq(wpa_s
->global
, 5000 + 156 * 5))
3351 wpas_p2p_add_chan(&chan
->reg_class
[cla
], 157);
3352 if (!wpas_p2p_disallowed_freq(wpa_s
->global
, 5000 + 161 * 5))
3353 wpas_p2p_add_chan(&chan
->reg_class
[cla
], 161);
3354 if (chan
->reg_class
[cla
].channels
)
3357 chan
->reg_classes
= cla
;
3362 static int has_channel(struct wpa_global
*global
,
3363 struct hostapd_hw_modes
*mode
, u8 chan
, int *flags
)
3368 freq
= (mode
->mode
== HOSTAPD_MODE_IEEE80211A
? 5000 : 2407) +
3370 if (wpas_p2p_disallowed_freq(global
, freq
))
3373 for (i
= 0; i
< mode
->num_channels
; i
++) {
3374 if (mode
->channels
[i
].chan
== chan
) {
3376 *flags
= mode
->channels
[i
].flag
;
3377 if (mode
->channels
[i
].flag
&
3378 (HOSTAPD_CHAN_DISABLED
|
3379 HOSTAPD_CHAN_RADAR
))
3381 if (mode
->channels
[i
].flag
& HOSTAPD_CHAN_NO_IR
)
3391 static int wpas_p2p_get_center_80mhz(struct wpa_supplicant
*wpa_s
,
3392 struct hostapd_hw_modes
*mode
,
3395 u8 center_channels
[] = { 42, 58, 106, 122, 138, 155 };
3398 if (mode
->mode
!= HOSTAPD_MODE_IEEE80211A
)
3401 for (i
= 0; i
< ARRAY_SIZE(center_channels
); i
++)
3403 * In 80 MHz, the bandwidth "spans" 12 channels (e.g., 36-48),
3404 * so the center channel is 6 channels away from the start/end.
3406 if (channel
>= center_channels
[i
] - 6 &&
3407 channel
<= center_channels
[i
] + 6)
3408 return center_channels
[i
];
3414 static enum chan_allowed
wpas_p2p_verify_80mhz(struct wpa_supplicant
*wpa_s
,
3415 struct hostapd_hw_modes
*mode
,
3420 enum chan_allowed res
, ret
= ALLOWED
;
3422 center_chan
= wpas_p2p_get_center_80mhz(wpa_s
, mode
, channel
);
3425 if (center_chan
>= 58 && center_chan
<= 138)
3426 return NOT_ALLOWED
; /* Do not allow DFS channels for P2P */
3428 /* check all the channels are available */
3429 for (i
= 0; i
< 4; i
++) {
3430 int adj_chan
= center_chan
- 6 + i
* 4;
3432 res
= has_channel(wpa_s
->global
, mode
, adj_chan
, &flags
);
3433 if (res
== NOT_ALLOWED
)
3438 if (i
== 0 && !(flags
& HOSTAPD_CHAN_VHT_10_70
))
3440 if (i
== 1 && !(flags
& HOSTAPD_CHAN_VHT_30_50
))
3442 if (i
== 2 && !(flags
& HOSTAPD_CHAN_VHT_50_30
))
3444 if (i
== 3 && !(flags
& HOSTAPD_CHAN_VHT_70_10
))
3452 static int wpas_p2p_get_center_160mhz(struct wpa_supplicant
*wpa_s
,
3453 struct hostapd_hw_modes
*mode
,
3456 u8 center_channels
[] = { 50, 114 };
3459 if (mode
->mode
!= HOSTAPD_MODE_IEEE80211A
)
3462 for (i
= 0; i
< ARRAY_SIZE(center_channels
); i
++)
3464 * In 160 MHz, the bandwidth "spans" 28 channels (e.g., 36-64),
3465 * so the center channel is 14 channels away from the start/end.
3467 if (channel
>= center_channels
[i
] - 14 &&
3468 channel
<= center_channels
[i
] + 14)
3469 return center_channels
[i
];
3475 static enum chan_allowed
wpas_p2p_verify_160mhz(struct wpa_supplicant
*wpa_s
,
3476 struct hostapd_hw_modes
*mode
,
3481 enum chan_allowed res
, ret
= ALLOWED
;
3483 center_chan
= wpas_p2p_get_center_160mhz(wpa_s
, mode
, channel
);
3486 /* VHT 160 MHz uses DFS channels in most countries. */
3488 /* Check all the channels are available */
3489 for (i
= 0; i
< 8; i
++) {
3490 int adj_chan
= center_chan
- 14 + i
* 4;
3492 res
= has_channel(wpa_s
->global
, mode
, adj_chan
, &flags
);
3493 if (res
== NOT_ALLOWED
)
3499 if (i
== 0 && !(flags
& HOSTAPD_CHAN_VHT_10_150
))
3501 if (i
== 1 && !(flags
& HOSTAPD_CHAN_VHT_30_130
))
3503 if (i
== 2 && !(flags
& HOSTAPD_CHAN_VHT_50_110
))
3505 if (i
== 3 && !(flags
& HOSTAPD_CHAN_VHT_70_90
))
3507 if (i
== 4 && !(flags
& HOSTAPD_CHAN_VHT_90_70
))
3509 if (i
== 5 && !(flags
& HOSTAPD_CHAN_VHT_110_50
))
3511 if (i
== 6 && !(flags
& HOSTAPD_CHAN_VHT_130_30
))
3513 if (i
== 7 && !(flags
& HOSTAPD_CHAN_VHT_150_10
))
3521 static enum chan_allowed
wpas_p2p_verify_channel(struct wpa_supplicant
*wpa_s
,
3522 struct hostapd_hw_modes
*mode
,
3526 enum chan_allowed res
, res2
;
3528 res2
= res
= has_channel(wpa_s
->global
, mode
, channel
, &flag
);
3529 if (bw
== BW40MINUS
) {
3530 if (!(flag
& HOSTAPD_CHAN_HT40MINUS
))
3532 res2
= has_channel(wpa_s
->global
, mode
, channel
- 4, NULL
);
3533 } else if (bw
== BW40PLUS
) {
3534 if (!(flag
& HOSTAPD_CHAN_HT40PLUS
))
3536 res2
= has_channel(wpa_s
->global
, mode
, channel
+ 4, NULL
);
3537 } else if (bw
== BW80
) {
3538 res2
= wpas_p2p_verify_80mhz(wpa_s
, mode
, channel
, bw
);
3539 } else if (bw
== BW160
) {
3540 res2
= wpas_p2p_verify_160mhz(wpa_s
, mode
, channel
, bw
);
3543 if (res
== NOT_ALLOWED
|| res2
== NOT_ALLOWED
)
3545 if (res
== NO_IR
|| res2
== NO_IR
)
3551 static int wpas_p2p_setup_channels(struct wpa_supplicant
*wpa_s
,
3552 struct p2p_channels
*chan
,
3553 struct p2p_channels
*cli_chan
)
3555 struct hostapd_hw_modes
*mode
;
3556 int cla
, op
, cli_cla
;
3558 if (wpa_s
->hw
.modes
== NULL
) {
3559 wpa_printf(MSG_DEBUG
, "P2P: Driver did not support fetching "
3560 "of all supported channels; assume dualband "
3562 return wpas_p2p_default_channels(wpa_s
, chan
, cli_chan
);
3567 for (op
= 0; global_op_class
[op
].op_class
; op
++) {
3568 const struct oper_class_map
*o
= &global_op_class
[op
];
3570 struct p2p_reg_class
*reg
= NULL
, *cli_reg
= NULL
;
3572 if (o
->p2p
== NO_P2P_SUPP
)
3575 mode
= get_mode(wpa_s
->hw
.modes
, wpa_s
->hw
.num_modes
, o
->mode
);
3578 if (mode
->mode
== HOSTAPD_MODE_IEEE80211G
)
3579 wpa_s
->global
->p2p_24ghz_social_channels
= 1;
3580 for (ch
= o
->min_chan
; ch
<= o
->max_chan
; ch
+= o
->inc
) {
3581 enum chan_allowed res
;
3582 res
= wpas_p2p_verify_channel(wpa_s
, mode
, ch
, o
->bw
);
3583 if (res
== ALLOWED
) {
3585 wpa_printf(MSG_DEBUG
, "P2P: Add operating class %u",
3587 reg
= &chan
->reg_class
[cla
];
3589 reg
->reg_class
= o
->op_class
;
3591 reg
->channel
[reg
->channels
] = ch
;
3593 } else if (res
== NO_IR
&&
3594 wpa_s
->conf
->p2p_add_cli_chan
) {
3595 if (cli_reg
== NULL
) {
3596 wpa_printf(MSG_DEBUG
, "P2P: Add operating class %u (client only)",
3598 cli_reg
= &cli_chan
->reg_class
[cli_cla
];
3600 cli_reg
->reg_class
= o
->op_class
;
3602 cli_reg
->channel
[cli_reg
->channels
] = ch
;
3603 cli_reg
->channels
++;
3607 wpa_hexdump(MSG_DEBUG
, "P2P: Channels",
3608 reg
->channel
, reg
->channels
);
3611 wpa_hexdump(MSG_DEBUG
, "P2P: Channels (client only)",
3612 cli_reg
->channel
, cli_reg
->channels
);
3616 chan
->reg_classes
= cla
;
3617 cli_chan
->reg_classes
= cli_cla
;
3623 int wpas_p2p_get_ht40_mode(struct wpa_supplicant
*wpa_s
,
3624 struct hostapd_hw_modes
*mode
, u8 channel
)
3627 enum chan_allowed ret
;
3629 for (op
= 0; global_op_class
[op
].op_class
; op
++) {
3630 const struct oper_class_map
*o
= &global_op_class
[op
];
3633 if (o
->p2p
== NO_P2P_SUPP
)
3636 for (ch
= o
->min_chan
; ch
<= o
->max_chan
; ch
+= o
->inc
) {
3637 if (o
->mode
!= HOSTAPD_MODE_IEEE80211A
||
3638 (o
->bw
!= BW40PLUS
&& o
->bw
!= BW40MINUS
) ||
3641 ret
= wpas_p2p_verify_channel(wpa_s
, mode
, ch
, o
->bw
);
3643 return (o
->bw
== BW40MINUS
) ? -1 : 1;
3650 int wpas_p2p_get_vht80_center(struct wpa_supplicant
*wpa_s
,
3651 struct hostapd_hw_modes
*mode
, u8 channel
)
3653 if (!wpas_p2p_verify_channel(wpa_s
, mode
, channel
, BW80
))
3656 return wpas_p2p_get_center_80mhz(wpa_s
, mode
, channel
);
3660 int wpas_p2p_get_vht160_center(struct wpa_supplicant
*wpa_s
,
3661 struct hostapd_hw_modes
*mode
, u8 channel
)
3663 if (!wpas_p2p_verify_channel(wpa_s
, mode
, channel
, BW160
))
3665 return wpas_p2p_get_center_160mhz(wpa_s
, mode
, channel
);
3669 static int wpas_get_noa(void *ctx
, const u8
*interface_addr
, u8
*buf
,
3672 struct wpa_supplicant
*wpa_s
= ctx
;
3674 for (wpa_s
= wpa_s
->global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
3675 if (os_memcmp(wpa_s
->own_addr
, interface_addr
, ETH_ALEN
) == 0)
3681 return wpa_drv_get_noa(wpa_s
, buf
, buf_len
);
3685 struct wpa_supplicant
* wpas_get_p2p_go_iface(struct wpa_supplicant
*wpa_s
,
3686 const u8
*ssid
, size_t ssid_len
)
3688 for (wpa_s
= wpa_s
->global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
3689 struct wpa_ssid
*s
= wpa_s
->current_ssid
;
3692 if (s
->mode
!= WPAS_MODE_P2P_GO
&&
3693 s
->mode
!= WPAS_MODE_AP
&&
3694 s
->mode
!= WPAS_MODE_P2P_GROUP_FORMATION
)
3696 if (s
->ssid_len
!= ssid_len
||
3697 os_memcmp(ssid
, s
->ssid
, ssid_len
) != 0)
3707 struct wpa_supplicant
* wpas_get_p2p_client_iface(struct wpa_supplicant
*wpa_s
,
3708 const u8
*peer_dev_addr
)
3710 for (wpa_s
= wpa_s
->global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
3711 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
3712 if (ssid
&& (ssid
->mode
!= WPAS_MODE_INFRA
|| !ssid
->p2p_group
))
3714 if (os_memcmp(wpa_s
->go_dev_addr
, peer_dev_addr
, ETH_ALEN
) == 0)
3722 static int wpas_go_connected(void *ctx
, const u8
*dev_addr
)
3724 struct wpa_supplicant
*wpa_s
= ctx
;
3726 return wpas_get_p2p_client_iface(wpa_s
, dev_addr
) != NULL
;
3730 static int wpas_is_concurrent_session_active(void *ctx
)
3732 struct wpa_supplicant
*wpa_s
= ctx
;
3733 struct wpa_supplicant
*ifs
;
3735 for (ifs
= wpa_s
->global
->ifaces
; ifs
; ifs
= ifs
->next
) {
3738 if (ifs
->wpa_state
> WPA_ASSOCIATED
)
3745 static void wpas_p2p_debug_print(void *ctx
, int level
, const char *msg
)
3747 struct wpa_supplicant
*wpa_s
= ctx
;
3748 wpa_msg_global(wpa_s
, level
, "P2P: %s", msg
);
3752 int wpas_p2p_add_p2pdev_interface(struct wpa_supplicant
*wpa_s
,
3753 const char *conf_p2p_dev
)
3755 struct wpa_interface iface
;
3756 struct wpa_supplicant
*p2pdev_wpa_s
;
3758 char force_name
[100];
3761 ret
= os_snprintf(ifname
, sizeof(ifname
), P2P_MGMT_DEVICE_PREFIX
"%s",
3763 if (os_snprintf_error(sizeof(ifname
), ret
))
3765 force_name
[0] = '\0';
3766 wpa_s
->pending_interface_type
= WPA_IF_P2P_DEVICE
;
3767 ret
= wpa_drv_if_add(wpa_s
, WPA_IF_P2P_DEVICE
, ifname
, NULL
, NULL
,
3768 force_name
, wpa_s
->pending_interface_addr
, NULL
);
3770 wpa_printf(MSG_DEBUG
, "P2P: Failed to create P2P Device interface");
3773 os_strlcpy(wpa_s
->pending_interface_name
, ifname
,
3774 sizeof(wpa_s
->pending_interface_name
));
3776 os_memset(&iface
, 0, sizeof(iface
));
3778 iface
.ifname
= wpa_s
->pending_interface_name
;
3779 iface
.driver
= wpa_s
->driver
->name
;
3780 iface
.driver_param
= wpa_s
->conf
->driver_param
;
3783 * If a P2P Device configuration file was given, use it as the interface
3784 * configuration file (instead of using parent's configuration file.
3787 iface
.confname
= conf_p2p_dev
;
3788 iface
.ctrl_interface
= NULL
;
3790 iface
.confname
= wpa_s
->confname
;
3791 iface
.ctrl_interface
= wpa_s
->conf
->ctrl_interface
;
3794 p2pdev_wpa_s
= wpa_supplicant_add_iface(wpa_s
->global
, &iface
, wpa_s
);
3795 if (!p2pdev_wpa_s
) {
3796 wpa_printf(MSG_DEBUG
, "P2P: Failed to add P2P Device interface");
3800 p2pdev_wpa_s
->p2pdev
= p2pdev_wpa_s
;
3801 wpa_s
->pending_interface_name
[0] = '\0';
3806 static void wpas_presence_resp(void *ctx
, const u8
*src
, u8 status
,
3807 const u8
*noa
, size_t noa_len
)
3809 struct wpa_supplicant
*wpa_s
, *intf
= ctx
;
3812 for (wpa_s
= intf
->global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
3813 if (wpa_s
->waiting_presence_resp
)
3817 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: No group interface was waiting for presence response");
3820 wpa_s
->waiting_presence_resp
= 0;
3822 wpa_snprintf_hex(hex
, sizeof(hex
), noa
, noa_len
);
3823 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_PRESENCE_RESPONSE
"src=" MACSTR
3824 " status=%u noa=%s", MAC2STR(src
), status
, hex
);
3828 static int wpas_get_persistent_group(void *ctx
, const u8
*addr
, const u8
*ssid
,
3829 size_t ssid_len
, u8
*go_dev_addr
,
3830 u8
*ret_ssid
, size_t *ret_ssid_len
,
3831 u8
*intended_iface_addr
)
3833 struct wpa_supplicant
*wpa_s
= ctx
;
3836 s
= wpas_p2p_get_persistent(wpa_s
, addr
, ssid
, ssid_len
);
3838 os_memcpy(ret_ssid
, s
->ssid
, s
->ssid_len
);
3839 *ret_ssid_len
= s
->ssid_len
;
3840 os_memcpy(go_dev_addr
, s
->bssid
, ETH_ALEN
);
3842 if (s
->mode
!= WPAS_MODE_P2P_GO
) {
3843 os_memset(intended_iface_addr
, 0, ETH_ALEN
);
3844 } else if (wpas_p2p_create_iface(wpa_s
)) {
3845 if (wpas_p2p_add_group_interface(wpa_s
, WPA_IF_P2P_GO
))
3848 os_memcpy(intended_iface_addr
,
3849 wpa_s
->pending_interface_addr
, ETH_ALEN
);
3851 os_memcpy(intended_iface_addr
, wpa_s
->own_addr
,
3861 static int wpas_get_go_info(void *ctx
, u8
*intended_addr
,
3862 u8
*ssid
, size_t *ssid_len
, int *group_iface
,
3865 struct wpa_supplicant
*wpa_s
= ctx
;
3866 struct wpa_supplicant
*go
;
3870 * group_iface will be set to 1 only if a dedicated interface for P2P
3871 * role is required. First, we try to reuse an active GO. However,
3872 * if it is not present, we will try to reactivate an existing
3873 * persistent group and set group_iface to 1, so the caller will know
3874 * that the pending interface should be used.
3881 go
= wpas_p2p_get_go_group(wpa_s
);
3883 s
= wpas_p2p_get_persistent_go(wpa_s
);
3884 *group_iface
= wpas_p2p_create_iface(wpa_s
);
3886 os_memcpy(intended_addr
, s
->bssid
, ETH_ALEN
);
3890 s
= go
->current_ssid
;
3891 os_memcpy(intended_addr
, go
->own_addr
, ETH_ALEN
);
3893 *freq
= go
->assoc_freq
;
3896 os_memcpy(ssid
, s
->ssid
, s
->ssid_len
);
3897 *ssid_len
= s
->ssid_len
;
3903 static int wpas_remove_stale_groups(void *ctx
, const u8
*peer
, const u8
*go
,
3904 const u8
*ssid
, size_t ssid_len
)
3906 struct wpa_supplicant
*wpa_s
= ctx
;
3908 int save_config
= 0;
3911 /* Start with our first choice of Persistent Groups */
3912 while ((s
= wpas_p2p_get_persistent(wpa_s
, peer
, NULL
, 0))) {
3913 if (go
&& ssid
&& ssid_len
&&
3914 s
->ssid_len
== ssid_len
&&
3915 os_memcmp(go
, s
->bssid
, ETH_ALEN
) == 0 &&
3916 os_memcmp(ssid
, s
->ssid
, ssid_len
) == 0)
3919 /* Remove stale persistent group */
3920 if (s
->mode
!= WPAS_MODE_P2P_GO
|| s
->num_p2p_clients
<= 1) {
3921 wpa_config_remove_network(wpa_s
->conf
, s
->id
);
3926 for (i
= 0; i
< s
->num_p2p_clients
; i
++) {
3927 if (os_memcmp(s
->p2p_client_list
+ i
* 2 * ETH_ALEN
,
3928 peer
, ETH_ALEN
) != 0)
3931 os_memmove(s
->p2p_client_list
+ i
* 2 * ETH_ALEN
,
3932 s
->p2p_client_list
+ (i
+ 1) * 2 * ETH_ALEN
,
3933 (s
->num_p2p_clients
- i
- 1) * 2 * ETH_ALEN
);
3936 s
->num_p2p_clients
--;
3941 p2p_config_write(wpa_s
);
3943 /* Return TRUE if valid SSID remains */
3948 static void wpas_p2ps_get_feat_cap_str(char *buf
, size_t buf_len
,
3949 const u8
*feat_cap
, size_t feat_cap_len
)
3951 static const char pref
[] = " feature_cap=";
3957 * We expect a feature capability to contain at least one byte to be
3958 * reported. The string buffer provided by the caller function is
3959 * expected to be big enough to contain all bytes of the attribute for
3960 * known specifications. This function truncates the reported bytes if
3961 * the feature capability data exceeds the string buffer size.
3963 if (!feat_cap
|| !feat_cap_len
|| buf_len
< sizeof(pref
) + 2)
3966 os_memcpy(buf
, pref
, sizeof(pref
));
3967 ret
= wpa_snprintf_hex(&buf
[sizeof(pref
) - 1],
3968 buf_len
- sizeof(pref
) + 1,
3969 feat_cap
, feat_cap_len
);
3971 if (ret
!= (2 * (int) feat_cap_len
))
3972 wpa_printf(MSG_WARNING
, "P2PS feature_cap bytes truncated");
3976 static void wpas_p2ps_prov_complete(void *ctx
, u8 status
, const u8
*dev
,
3977 const u8
*adv_mac
, const u8
*ses_mac
,
3978 const u8
*grp_mac
, u32 adv_id
, u32 ses_id
,
3979 u8 conncap
, int passwd_id
,
3980 const u8
*persist_ssid
,
3981 size_t persist_ssid_size
, int response_done
,
3982 int prov_start
, const char *session_info
,
3983 const u8
*feat_cap
, size_t feat_cap_len
,
3985 const u8
*group_ssid
, size_t group_ssid_len
)
3987 struct wpa_supplicant
*wpa_s
= ctx
;
3989 struct wpa_ssid
*persistent_go
, *stale
, *s
= NULL
;
3990 int save_config
= 0;
3991 struct wpa_supplicant
*go_wpa_s
;
3992 char feat_cap_str
[256];
3997 os_memset(mac
, 0, ETH_ALEN
);
4005 wpas_p2ps_get_feat_cap_str(feat_cap_str
, sizeof(feat_cap_str
),
4006 feat_cap
, feat_cap_len
);
4009 if (session_info
== NULL
) {
4010 wpa_msg_global(wpa_s
, MSG_INFO
,
4011 P2P_EVENT_P2PS_PROVISION_START MACSTR
4012 " adv_id=%x conncap=%x"
4014 " session=%x mac=" MACSTR
4015 " dev_passwd_id=%d%s",
4016 MAC2STR(dev
), adv_id
, conncap
,
4018 ses_id
, MAC2STR(ses_mac
),
4019 passwd_id
, feat_cap_str
);
4021 wpa_msg_global(wpa_s
, MSG_INFO
,
4022 P2P_EVENT_P2PS_PROVISION_START MACSTR
4023 " adv_id=%x conncap=%x"
4025 " session=%x mac=" MACSTR
4026 " dev_passwd_id=%d info='%s'%s",
4027 MAC2STR(dev
), adv_id
, conncap
,
4029 ses_id
, MAC2STR(ses_mac
),
4030 passwd_id
, session_info
, feat_cap_str
);
4035 go_wpa_s
= wpas_p2p_get_go_group(wpa_s
);
4036 persistent_go
= wpas_p2p_get_persistent_go(wpa_s
);
4038 if (status
&& status
!= P2P_SC_SUCCESS_DEFERRED
) {
4039 if (go_wpa_s
&& !p2p_group_go_member_count(wpa_s
))
4040 wpas_p2p_group_remove(wpa_s
, go_wpa_s
->ifname
);
4042 if (persistent_go
&& !persistent_go
->num_p2p_clients
) {
4043 /* remove empty persistent GO */
4044 wpa_config_remove_network(wpa_s
->conf
,
4048 wpa_msg_global(wpa_s
, MSG_INFO
,
4049 P2P_EVENT_P2PS_PROVISION_DONE MACSTR
4051 " adv_id=%x adv_mac=" MACSTR
4052 " session=%x mac=" MACSTR
"%s",
4053 MAC2STR(dev
), status
,
4054 adv_id
, MAC2STR(adv_mac
),
4055 ses_id
, MAC2STR(ses_mac
), feat_cap_str
);
4059 /* Clean up stale persistent groups with this device */
4060 if (persist_ssid
&& persist_ssid_size
)
4061 s
= wpas_p2p_get_persistent(wpa_s
, dev
, persist_ssid
,
4064 if (persist_ssid
&& s
&& s
->mode
!= WPAS_MODE_P2P_GO
&&
4065 is_zero_ether_addr(grp_mac
)) {
4066 wpa_dbg(wpa_s
, MSG_ERROR
,
4067 "P2P: Peer device is a GO in a persistent group, but it did not provide the intended MAC address");
4072 stale
= wpas_p2p_get_persistent(wpa_s
, dev
, NULL
, 0);
4076 if (s
&& s
->ssid_len
== stale
->ssid_len
&&
4077 os_memcmp(stale
->bssid
, s
->bssid
, ETH_ALEN
) == 0 &&
4078 os_memcmp(stale
->ssid
, s
->ssid
, s
->ssid_len
) == 0)
4081 /* Remove stale persistent group */
4082 if (stale
->mode
!= WPAS_MODE_P2P_GO
||
4083 stale
->num_p2p_clients
<= 1) {
4084 wpa_config_remove_network(wpa_s
->conf
, stale
->id
);
4088 for (i
= 0; i
< stale
->num_p2p_clients
; i
++) {
4089 if (os_memcmp(stale
->p2p_client_list
+
4091 dev
, ETH_ALEN
) == 0) {
4092 os_memmove(stale
->p2p_client_list
+
4094 stale
->p2p_client_list
+
4096 (stale
->num_p2p_clients
-
4101 stale
->num_p2p_clients
--;
4107 p2p_config_write(wpa_s
);
4110 if (go_wpa_s
&& !p2p_group_go_member_count(wpa_s
))
4111 wpas_p2p_group_remove(wpa_s
, go_wpa_s
->ifname
);
4113 if (persistent_go
&& s
!= persistent_go
&&
4114 !persistent_go
->num_p2p_clients
) {
4115 /* remove empty persistent GO */
4116 wpa_config_remove_network(wpa_s
->conf
,
4121 wpa_msg_global(wpa_s
, MSG_INFO
,
4122 P2P_EVENT_P2PS_PROVISION_DONE MACSTR
4124 " adv_id=%x adv_mac=" MACSTR
4125 " session=%x mac=" MACSTR
4127 MAC2STR(dev
), status
,
4128 adv_id
, MAC2STR(adv_mac
),
4129 ses_id
, MAC2STR(ses_mac
), s
->id
, feat_cap_str
);
4133 if (conncap
== P2PS_SETUP_GROUP_OWNER
) {
4135 * We need to copy the interface name. Simply saving a
4136 * pointer isn't enough, since if we use pending_interface_name
4137 * it will be overwritten when the group is added.
4139 char go_ifname
[100];
4141 go_ifname
[0] = '\0';
4143 wpa_s
->global
->pending_p2ps_group
= 1;
4144 wpa_s
->global
->pending_p2ps_group_freq
= freq
;
4146 if (!wpas_p2p_create_iface(wpa_s
))
4147 os_memcpy(go_ifname
, wpa_s
->ifname
,
4149 else if (wpa_s
->pending_interface_name
[0])
4150 os_memcpy(go_ifname
,
4151 wpa_s
->pending_interface_name
,
4154 if (!go_ifname
[0]) {
4155 wpas_p2ps_prov_complete(
4156 wpa_s
, P2P_SC_FAIL_UNKNOWN_GROUP
,
4157 dev
, adv_mac
, ses_mac
,
4158 grp_mac
, adv_id
, ses_id
, 0, 0,
4159 NULL
, 0, 0, 0, NULL
, NULL
, 0, 0,
4164 /* If PD Resp complete, start up the GO */
4165 if (response_done
&& persistent_go
) {
4166 wpas_p2p_group_add_persistent(
4167 wpa_s
, persistent_go
,
4168 0, 0, freq
, 0, 0, 0, 0, NULL
,
4169 persistent_go
->mode
==
4171 P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE
:
4173 } else if (response_done
) {
4174 wpas_p2p_group_add(wpa_s
, 1, freq
, 0, 0, 0, 0);
4177 if (passwd_id
== DEV_PW_P2PS_DEFAULT
) {
4178 os_memcpy(wpa_s
->p2ps_join_addr
, grp_mac
,
4180 wpa_s
->p2ps_method_config_any
= 1;
4182 } else if (passwd_id
== DEV_PW_P2PS_DEFAULT
) {
4183 os_memcpy(go_ifname
, go_wpa_s
->ifname
,
4186 if (is_zero_ether_addr(grp_mac
)) {
4187 wpa_dbg(go_wpa_s
, MSG_DEBUG
,
4188 "P2P: Setting PIN-1 for ANY");
4189 wpa_supplicant_ap_wps_pin(go_wpa_s
, NULL
,
4190 "12345670", NULL
, 0,
4193 wpa_dbg(go_wpa_s
, MSG_DEBUG
,
4194 "P2P: Setting PIN-1 for " MACSTR
,
4196 wpa_supplicant_ap_wps_pin(go_wpa_s
, grp_mac
,
4197 "12345670", NULL
, 0,
4201 os_memcpy(wpa_s
->p2ps_join_addr
, grp_mac
, ETH_ALEN
);
4202 wpa_s
->p2ps_method_config_any
= 1;
4205 wpa_msg_global(wpa_s
, MSG_INFO
,
4206 P2P_EVENT_P2PS_PROVISION_DONE MACSTR
4207 " status=%d conncap=%x"
4208 " adv_id=%x adv_mac=" MACSTR
4209 " session=%x mac=" MACSTR
4210 " dev_passwd_id=%d go=%s%s",
4211 MAC2STR(dev
), status
, conncap
,
4212 adv_id
, MAC2STR(adv_mac
),
4213 ses_id
, MAC2STR(ses_mac
),
4214 passwd_id
, go_ifname
, feat_cap_str
);
4218 if (go_wpa_s
&& !p2p_group_go_member_count(wpa_s
))
4219 wpas_p2p_group_remove(wpa_s
, go_wpa_s
->ifname
);
4221 if (persistent_go
&& !persistent_go
->num_p2p_clients
) {
4222 /* remove empty persistent GO */
4223 wpa_config_remove_network(wpa_s
->conf
, persistent_go
->id
);
4226 if (conncap
== P2PS_SETUP_CLIENT
) {
4227 char ssid_hex
[32 * 2 + 1];
4230 wpa_snprintf_hex(ssid_hex
, sizeof(ssid_hex
),
4231 group_ssid
, group_ssid_len
);
4234 wpa_msg_global(wpa_s
, MSG_INFO
,
4235 P2P_EVENT_P2PS_PROVISION_DONE MACSTR
4236 " status=%d conncap=%x"
4237 " adv_id=%x adv_mac=" MACSTR
4238 " session=%x mac=" MACSTR
4239 " dev_passwd_id=%d join=" MACSTR
"%s%s%s",
4240 MAC2STR(dev
), status
, conncap
,
4241 adv_id
, MAC2STR(adv_mac
),
4242 ses_id
, MAC2STR(ses_mac
),
4243 passwd_id
, MAC2STR(grp_mac
), feat_cap_str
,
4244 group_ssid
? " group_ssid=" : "", ssid_hex
);
4246 wpa_msg_global(wpa_s
, MSG_INFO
,
4247 P2P_EVENT_P2PS_PROVISION_DONE MACSTR
4248 " status=%d conncap=%x"
4249 " adv_id=%x adv_mac=" MACSTR
4250 " session=%x mac=" MACSTR
4251 " dev_passwd_id=%d%s",
4252 MAC2STR(dev
), status
, conncap
,
4253 adv_id
, MAC2STR(adv_mac
),
4254 ses_id
, MAC2STR(ses_mac
),
4255 passwd_id
, feat_cap_str
);
4260 static int _wpas_p2p_in_progress(void *ctx
)
4262 struct wpa_supplicant
*wpa_s
= ctx
;
4263 return wpas_p2p_in_progress(wpa_s
);
4267 static int wpas_prov_disc_resp_cb(void *ctx
)
4269 struct wpa_supplicant
*wpa_s
= ctx
;
4270 struct wpa_ssid
*persistent_go
;
4273 if (!wpa_s
->global
->pending_p2ps_group
)
4276 freq
= wpa_s
->global
->pending_p2ps_group_freq
;
4277 wpa_s
->global
->pending_p2ps_group_freq
= 0;
4278 wpa_s
->global
->pending_p2ps_group
= 0;
4280 if (wpas_p2p_get_go_group(wpa_s
))
4282 persistent_go
= wpas_p2p_get_persistent_go(wpa_s
);
4284 if (persistent_go
) {
4285 wpas_p2p_group_add_persistent(
4286 wpa_s
, persistent_go
, 0, 0, 0, 0, 0, 0, 0, NULL
,
4287 persistent_go
->mode
== WPAS_MODE_P2P_GO
?
4288 P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE
: 0, 0);
4290 wpas_p2p_group_add(wpa_s
, 1, freq
, 0, 0, 0, 0);
4297 static int wpas_p2p_get_pref_freq_list(void *ctx
, int go
,
4299 unsigned int *freq_list
)
4301 struct wpa_supplicant
*wpa_s
= ctx
;
4303 return wpa_drv_get_pref_freq_list(wpa_s
, go
? WPA_IF_P2P_GO
:
4304 WPA_IF_P2P_CLIENT
, len
, freq_list
);
4309 * wpas_p2p_init - Initialize P2P module for %wpa_supplicant
4310 * @global: Pointer to global data from wpa_supplicant_init()
4311 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
4312 * Returns: 0 on success, -1 on failure
4314 int wpas_p2p_init(struct wpa_global
*global
, struct wpa_supplicant
*wpa_s
)
4316 struct p2p_config p2p
;
4319 if (wpa_s
->conf
->p2p_disabled
)
4322 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_CAPABLE
))
4328 os_memset(&p2p
, 0, sizeof(p2p
));
4330 p2p
.debug_print
= wpas_p2p_debug_print
;
4331 p2p
.p2p_scan
= wpas_p2p_scan
;
4332 p2p
.send_action
= wpas_send_action
;
4333 p2p
.send_action_done
= wpas_send_action_done
;
4334 p2p
.go_neg_completed
= wpas_go_neg_completed
;
4335 p2p
.go_neg_req_rx
= wpas_go_neg_req_rx
;
4336 p2p
.dev_found
= wpas_dev_found
;
4337 p2p
.dev_lost
= wpas_dev_lost
;
4338 p2p
.find_stopped
= wpas_find_stopped
;
4339 p2p
.start_listen
= wpas_start_listen
;
4340 p2p
.stop_listen
= wpas_stop_listen
;
4341 p2p
.send_probe_resp
= wpas_send_probe_resp
;
4342 p2p
.sd_request
= wpas_sd_request
;
4343 p2p
.sd_response
= wpas_sd_response
;
4344 p2p
.prov_disc_req
= wpas_prov_disc_req
;
4345 p2p
.prov_disc_resp
= wpas_prov_disc_resp
;
4346 p2p
.prov_disc_fail
= wpas_prov_disc_fail
;
4347 p2p
.invitation_process
= wpas_invitation_process
;
4348 p2p
.invitation_received
= wpas_invitation_received
;
4349 p2p
.invitation_result
= wpas_invitation_result
;
4350 p2p
.get_noa
= wpas_get_noa
;
4351 p2p
.go_connected
= wpas_go_connected
;
4352 p2p
.presence_resp
= wpas_presence_resp
;
4353 p2p
.is_concurrent_session_active
= wpas_is_concurrent_session_active
;
4354 p2p
.is_p2p_in_progress
= _wpas_p2p_in_progress
;
4355 p2p
.get_persistent_group
= wpas_get_persistent_group
;
4356 p2p
.get_go_info
= wpas_get_go_info
;
4357 p2p
.remove_stale_groups
= wpas_remove_stale_groups
;
4358 p2p
.p2ps_prov_complete
= wpas_p2ps_prov_complete
;
4359 p2p
.prov_disc_resp_cb
= wpas_prov_disc_resp_cb
;
4360 p2p
.p2ps_group_capability
= p2ps_group_capability
;
4361 p2p
.get_pref_freq_list
= wpas_p2p_get_pref_freq_list
;
4363 os_memcpy(wpa_s
->global
->p2p_dev_addr
, wpa_s
->own_addr
, ETH_ALEN
);
4364 os_memcpy(p2p
.dev_addr
, wpa_s
->global
->p2p_dev_addr
, ETH_ALEN
);
4365 p2p
.dev_name
= wpa_s
->conf
->device_name
;
4366 p2p
.manufacturer
= wpa_s
->conf
->manufacturer
;
4367 p2p
.model_name
= wpa_s
->conf
->model_name
;
4368 p2p
.model_number
= wpa_s
->conf
->model_number
;
4369 p2p
.serial_number
= wpa_s
->conf
->serial_number
;
4371 os_memcpy(p2p
.uuid
, wpa_s
->wps
->uuid
, 16);
4372 p2p
.config_methods
= wpa_s
->wps
->config_methods
;
4375 if (wpas_p2p_setup_channels(wpa_s
, &p2p
.channels
, &p2p
.cli_channels
)) {
4376 wpa_printf(MSG_ERROR
,
4377 "P2P: Failed to configure supported channel list");
4381 if (wpa_s
->conf
->p2p_listen_reg_class
&&
4382 wpa_s
->conf
->p2p_listen_channel
) {
4383 p2p
.reg_class
= wpa_s
->conf
->p2p_listen_reg_class
;
4384 p2p
.channel
= wpa_s
->conf
->p2p_listen_channel
;
4385 p2p
.channel_forced
= 1;
4388 * Pick one of the social channels randomly as the listen
4391 if (p2p_config_get_random_social(&p2p
, &p2p
.reg_class
,
4392 &p2p
.channel
) != 0) {
4393 wpa_printf(MSG_INFO
,
4394 "P2P: No social channels supported by the driver - do not enable P2P");
4397 p2p
.channel_forced
= 0;
4399 wpa_printf(MSG_DEBUG
, "P2P: Own listen channel: %d:%d",
4400 p2p
.reg_class
, p2p
.channel
);
4402 if (wpa_s
->conf
->p2p_oper_reg_class
&&
4403 wpa_s
->conf
->p2p_oper_channel
) {
4404 p2p
.op_reg_class
= wpa_s
->conf
->p2p_oper_reg_class
;
4405 p2p
.op_channel
= wpa_s
->conf
->p2p_oper_channel
;
4406 p2p
.cfg_op_channel
= 1;
4407 wpa_printf(MSG_DEBUG
, "P2P: Configured operating channel: "
4408 "%d:%d", p2p
.op_reg_class
, p2p
.op_channel
);
4412 * Use random operation channel from 2.4 GHz band social
4413 * channels (1, 6, 11) or band 60 GHz social channel (2) if no
4414 * other preference is indicated.
4416 if (p2p_config_get_random_social(&p2p
, &p2p
.op_reg_class
,
4417 &p2p
.op_channel
) != 0) {
4418 wpa_printf(MSG_ERROR
,
4419 "P2P: Failed to select random social channel as operation channel");
4422 p2p
.cfg_op_channel
= 0;
4423 wpa_printf(MSG_DEBUG
, "P2P: Random operating channel: "
4424 "%d:%d", p2p
.op_reg_class
, p2p
.op_channel
);
4427 if (wpa_s
->conf
->p2p_pref_chan
&& wpa_s
->conf
->num_p2p_pref_chan
) {
4428 p2p
.pref_chan
= wpa_s
->conf
->p2p_pref_chan
;
4429 p2p
.num_pref_chan
= wpa_s
->conf
->num_p2p_pref_chan
;
4432 if (wpa_s
->conf
->country
[0] && wpa_s
->conf
->country
[1]) {
4433 os_memcpy(p2p
.country
, wpa_s
->conf
->country
, 2);
4434 p2p
.country
[2] = 0x04;
4436 os_memcpy(p2p
.country
, "XX\x04", 3);
4438 os_memcpy(p2p
.pri_dev_type
, wpa_s
->conf
->device_type
,
4441 p2p
.num_sec_dev_types
= wpa_s
->conf
->num_sec_device_types
;
4442 os_memcpy(p2p
.sec_dev_type
, wpa_s
->conf
->sec_device_type
,
4443 p2p
.num_sec_dev_types
* WPS_DEV_TYPE_LEN
);
4445 p2p
.concurrent_operations
= !!(wpa_s
->drv_flags
&
4446 WPA_DRIVER_FLAGS_P2P_CONCURRENT
);
4448 p2p
.max_peers
= 100;
4450 if (wpa_s
->conf
->p2p_ssid_postfix
) {
4451 p2p
.ssid_postfix_len
=
4452 os_strlen(wpa_s
->conf
->p2p_ssid_postfix
);
4453 if (p2p
.ssid_postfix_len
> sizeof(p2p
.ssid_postfix
))
4454 p2p
.ssid_postfix_len
= sizeof(p2p
.ssid_postfix
);
4455 os_memcpy(p2p
.ssid_postfix
, wpa_s
->conf
->p2p_ssid_postfix
,
4456 p2p
.ssid_postfix_len
);
4459 p2p
.p2p_intra_bss
= wpa_s
->conf
->p2p_intra_bss
;
4461 p2p
.max_listen
= wpa_s
->max_remain_on_chan
;
4463 if (wpa_s
->conf
->p2p_passphrase_len
>= 8 &&
4464 wpa_s
->conf
->p2p_passphrase_len
<= 63)
4465 p2p
.passphrase_len
= wpa_s
->conf
->p2p_passphrase_len
;
4467 p2p
.passphrase_len
= 8;
4469 global
->p2p
= p2p_init(&p2p
);
4470 if (global
->p2p
== NULL
)
4472 global
->p2p_init_wpa_s
= wpa_s
;
4474 for (i
= 0; i
< MAX_WPS_VENDOR_EXT
; i
++) {
4475 if (wpa_s
->conf
->wps_vendor_ext
[i
] == NULL
)
4477 p2p_add_wps_vendor_extension(
4478 global
->p2p
, wpa_s
->conf
->wps_vendor_ext
[i
]);
4481 p2p_set_no_go_freq(global
->p2p
, &wpa_s
->conf
->p2p_no_go_freq
);
4488 * wpas_p2p_deinit - Deinitialize per-interface P2P data
4489 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
4491 * This function deinitialize per-interface P2P data.
4493 void wpas_p2p_deinit(struct wpa_supplicant
*wpa_s
)
4495 if (wpa_s
->driver
&& wpa_s
->drv_priv
)
4496 wpa_drv_probe_req_report(wpa_s
, 0);
4498 if (wpa_s
->go_params
) {
4499 /* Clear any stored provisioning info */
4500 p2p_clear_provisioning_info(
4502 wpa_s
->go_params
->peer_device_addr
);
4505 os_free(wpa_s
->go_params
);
4506 wpa_s
->go_params
= NULL
;
4507 eloop_cancel_timeout(wpas_p2p_psk_failure_removal
, wpa_s
, NULL
);
4508 eloop_cancel_timeout(wpas_p2p_group_formation_timeout
, wpa_s
, NULL
);
4509 eloop_cancel_timeout(wpas_p2p_join_scan
, wpa_s
, NULL
);
4510 wpa_s
->p2p_long_listen
= 0;
4511 eloop_cancel_timeout(wpas_p2p_long_listen_timeout
, wpa_s
, NULL
);
4512 eloop_cancel_timeout(wpas_p2p_group_idle_timeout
, wpa_s
, NULL
);
4513 wpas_p2p_remove_pending_group_interface(wpa_s
);
4514 eloop_cancel_timeout(wpas_p2p_group_freq_conflict
, wpa_s
, NULL
);
4515 wpas_p2p_listen_work_done(wpa_s
);
4516 if (wpa_s
->p2p_send_action_work
) {
4517 os_free(wpa_s
->p2p_send_action_work
->ctx
);
4518 radio_work_done(wpa_s
->p2p_send_action_work
);
4519 wpa_s
->p2p_send_action_work
= NULL
;
4521 eloop_cancel_timeout(wpas_p2p_send_action_work_timeout
, wpa_s
, NULL
);
4523 wpabuf_free(wpa_s
->p2p_oob_dev_pw
);
4524 wpa_s
->p2p_oob_dev_pw
= NULL
;
4526 os_free(wpa_s
->p2p_group_common_freqs
);
4527 wpa_s
->p2p_group_common_freqs
= NULL
;
4528 wpa_s
->p2p_group_common_freqs_num
= 0;
4530 /* TODO: remove group interface from the driver if this wpa_s instance
4531 * is on top of a P2P group interface */
4536 * wpas_p2p_deinit_global - Deinitialize global P2P module
4537 * @global: Pointer to global data from wpa_supplicant_init()
4539 * This function deinitializes the global (per device) P2P module.
4541 static void wpas_p2p_deinit_global(struct wpa_global
*global
)
4543 struct wpa_supplicant
*wpa_s
, *tmp
;
4545 wpa_s
= global
->ifaces
;
4547 wpas_p2p_service_flush(global
->p2p_init_wpa_s
);
4549 /* Remove remaining P2P group interfaces */
4550 while (wpa_s
&& wpa_s
->p2p_group_interface
!= NOT_P2P_GROUP_INTERFACE
)
4551 wpa_s
= wpa_s
->next
;
4553 tmp
= global
->ifaces
;
4556 tmp
->p2p_group_interface
== NOT_P2P_GROUP_INTERFACE
)) {
4561 /* Disconnect from the P2P group and deinit the interface */
4562 wpas_p2p_disconnect(tmp
);
4566 * Deinit GO data on any possibly remaining interface (if main
4567 * interface is used as GO).
4569 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
4570 if (wpa_s
->ap_iface
)
4571 wpas_p2p_group_deinit(wpa_s
);
4574 p2p_deinit(global
->p2p
);
4576 global
->p2p_init_wpa_s
= NULL
;
4580 static int wpas_p2p_create_iface(struct wpa_supplicant
*wpa_s
)
4582 if (wpa_s
->conf
->p2p_no_group_iface
)
4583 return 0; /* separate interface disabled per configuration */
4584 if (wpa_s
->drv_flags
&
4585 (WPA_DRIVER_FLAGS_P2P_DEDICATED_INTERFACE
|
4586 WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P
))
4587 return 1; /* P2P group requires a new interface in every case
4589 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_CONCURRENT
))
4590 return 0; /* driver does not support concurrent operations */
4591 if (wpa_s
->global
->ifaces
->next
)
4592 return 1; /* more that one interface already in use */
4593 if (wpa_s
->wpa_state
>= WPA_AUTHENTICATING
)
4594 return 1; /* this interface is already in use */
4599 static int wpas_p2p_start_go_neg(struct wpa_supplicant
*wpa_s
,
4600 const u8
*peer_addr
,
4601 enum p2p_wps_method wps_method
,
4602 int go_intent
, const u8
*own_interface_addr
,
4603 unsigned int force_freq
, int persistent_group
,
4604 struct wpa_ssid
*ssid
, unsigned int pref_freq
)
4606 if (persistent_group
&& wpa_s
->conf
->persistent_reconnect
)
4607 persistent_group
= 2;
4610 * Increase GO config timeout if HT40 is used since it takes some time
4611 * to scan channels for coex purposes before the BSS can be started.
4613 p2p_set_config_timeout(wpa_s
->global
->p2p
,
4614 wpa_s
->p2p_go_ht40
? 255 : 100, 20);
4616 return p2p_connect(wpa_s
->global
->p2p
, peer_addr
, wps_method
,
4617 go_intent
, own_interface_addr
, force_freq
,
4618 persistent_group
, ssid
? ssid
->ssid
: NULL
,
4619 ssid
? ssid
->ssid_len
: 0,
4620 wpa_s
->p2p_pd_before_go_neg
, pref_freq
,
4621 wps_method
== WPS_NFC
? wpa_s
->p2p_oob_dev_pw_id
:
4626 static int wpas_p2p_auth_go_neg(struct wpa_supplicant
*wpa_s
,
4627 const u8
*peer_addr
,
4628 enum p2p_wps_method wps_method
,
4629 int go_intent
, const u8
*own_interface_addr
,
4630 unsigned int force_freq
, int persistent_group
,
4631 struct wpa_ssid
*ssid
, unsigned int pref_freq
)
4633 if (persistent_group
&& wpa_s
->conf
->persistent_reconnect
)
4634 persistent_group
= 2;
4636 return p2p_authorize(wpa_s
->global
->p2p
, peer_addr
, wps_method
,
4637 go_intent
, own_interface_addr
, force_freq
,
4638 persistent_group
, ssid
? ssid
->ssid
: NULL
,
4639 ssid
? ssid
->ssid_len
: 0, pref_freq
,
4640 wps_method
== WPS_NFC
? wpa_s
->p2p_oob_dev_pw_id
:
4645 static void wpas_p2p_check_join_scan_limit(struct wpa_supplicant
*wpa_s
)
4647 wpa_s
->p2p_join_scan_count
++;
4648 wpa_printf(MSG_DEBUG
, "P2P: Join scan attempt %d",
4649 wpa_s
->p2p_join_scan_count
);
4650 if (wpa_s
->p2p_join_scan_count
> P2P_MAX_JOIN_SCAN_ATTEMPTS
) {
4651 wpa_printf(MSG_DEBUG
, "P2P: Failed to find GO " MACSTR
4652 " for join operationg - stop join attempt",
4653 MAC2STR(wpa_s
->pending_join_iface_addr
));
4654 eloop_cancel_timeout(wpas_p2p_join_scan
, wpa_s
, NULL
);
4655 if (wpa_s
->p2p_auto_pd
) {
4656 wpa_s
->p2p_auto_pd
= 0;
4657 wpa_msg_global(wpa_s
, MSG_INFO
,
4658 P2P_EVENT_PROV_DISC_FAILURE
4659 " p2p_dev_addr=" MACSTR
" status=N/A",
4660 MAC2STR(wpa_s
->pending_join_dev_addr
));
4663 wpa_msg_global(wpa_s
->p2pdev
, MSG_INFO
,
4664 P2P_EVENT_GROUP_FORMATION_FAILURE
);
4665 wpas_notify_p2p_group_formation_failure(wpa_s
, "");
4670 static int wpas_check_freq_conflict(struct wpa_supplicant
*wpa_s
, int freq
)
4673 unsigned int num
, i
;
4674 struct wpa_used_freq_data
*freqs
;
4676 if (wpas_p2p_num_unused_channels(wpa_s
) > 0) {
4677 /* Multiple channels are supported and not all are in use */
4681 freqs
= os_calloc(wpa_s
->num_multichan_concurrent
,
4682 sizeof(struct wpa_used_freq_data
));
4686 num
= wpas_p2p_valid_oper_freqs(wpa_s
, freqs
,
4687 wpa_s
->num_multichan_concurrent
);
4689 for (i
= 0; i
< num
; i
++) {
4690 if (freqs
[i
].freq
== freq
) {
4691 wpa_printf(MSG_DEBUG
, "P2P: Frequency %d MHz in use by another virtual interface and can be used",
4698 wpa_printf(MSG_DEBUG
, "P2P: No valid operating frequencies");
4707 static int wpas_p2p_peer_go(struct wpa_supplicant
*wpa_s
,
4708 const u8
*peer_dev_addr
)
4710 struct wpa_bss
*bss
;
4713 bss
= wpa_bss_get_p2p_dev_addr(wpa_s
, peer_dev_addr
);
4716 if (bss
->last_update_idx
< wpa_s
->bss_update_idx
) {
4717 wpa_printf(MSG_DEBUG
, "P2P: Peer BSS entry not updated in the "
4722 updated
= os_reltime_before(&wpa_s
->p2p_auto_started
,
4724 wpa_printf(MSG_DEBUG
, "P2P: Current BSS entry for peer updated at "
4725 "%ld.%06ld (%supdated in last scan)",
4726 bss
->last_update
.sec
, bss
->last_update
.usec
,
4727 updated
? "": "not ");
4733 static void wpas_p2p_scan_res_join(struct wpa_supplicant
*wpa_s
,
4734 struct wpa_scan_results
*scan_res
)
4736 struct wpa_bss
*bss
= NULL
;
4738 u8 iface_addr
[ETH_ALEN
];
4740 eloop_cancel_timeout(wpas_p2p_join_scan
, wpa_s
, NULL
);
4742 if (wpa_s
->global
->p2p_disabled
)
4745 wpa_printf(MSG_DEBUG
, "P2P: Scan results received (%d BSS) for %sjoin",
4746 scan_res
? (int) scan_res
->num
: -1,
4747 wpa_s
->p2p_auto_join
? "auto_" : "");
4750 wpas_p2p_scan_res_handler(wpa_s
, scan_res
);
4752 if (wpa_s
->p2p_auto_pd
) {
4753 int join
= wpas_p2p_peer_go(wpa_s
,
4754 wpa_s
->pending_join_dev_addr
);
4756 wpa_s
->auto_pd_scan_retry
< P2P_AUTO_PD_SCAN_ATTEMPTS
) {
4757 wpa_s
->auto_pd_scan_retry
++;
4758 bss
= wpa_bss_get_bssid_latest(
4759 wpa_s
, wpa_s
->pending_join_dev_addr
);
4762 wpa_printf(MSG_DEBUG
, "P2P: Scan retry %d for "
4763 "the peer " MACSTR
" at %d MHz",
4764 wpa_s
->auto_pd_scan_retry
,
4766 pending_join_dev_addr
),
4768 wpas_p2p_join_scan_req(wpa_s
, freq
, NULL
, 0);
4776 wpa_s
->p2p_auto_pd
= 0;
4777 wpa_s
->pending_pd_use
= join
? AUTO_PD_JOIN
: AUTO_PD_GO_NEG
;
4778 wpa_printf(MSG_DEBUG
, "P2P: Auto PD with " MACSTR
" join=%d",
4779 MAC2STR(wpa_s
->pending_join_dev_addr
), join
);
4780 if (p2p_prov_disc_req(wpa_s
->global
->p2p
,
4781 wpa_s
->pending_join_dev_addr
, NULL
,
4782 wpa_s
->pending_pd_config_methods
, join
,
4783 0, wpa_s
->user_initiated_pd
) < 0) {
4784 wpa_s
->p2p_auto_pd
= 0;
4785 wpa_msg_global(wpa_s
, MSG_INFO
,
4786 P2P_EVENT_PROV_DISC_FAILURE
4787 " p2p_dev_addr=" MACSTR
" status=N/A",
4788 MAC2STR(wpa_s
->pending_join_dev_addr
));
4793 if (wpa_s
->p2p_auto_join
) {
4794 int join
= wpas_p2p_peer_go(wpa_s
,
4795 wpa_s
->pending_join_dev_addr
);
4797 wpa_printf(MSG_DEBUG
, "P2P: Peer was not found to be "
4798 "running a GO -> use GO Negotiation");
4799 wpa_msg_global(wpa_s
->p2pdev
, MSG_INFO
,
4800 P2P_EVENT_FALLBACK_TO_GO_NEG
4801 "reason=peer-not-running-GO");
4802 wpas_p2p_connect(wpa_s
, wpa_s
->pending_join_dev_addr
,
4803 wpa_s
->p2p_pin
, wpa_s
->p2p_wps_method
,
4804 wpa_s
->p2p_persistent_group
, 0, 0, 0,
4805 wpa_s
->p2p_go_intent
,
4806 wpa_s
->p2p_connect_freq
,
4807 wpa_s
->p2p_go_vht_center_freq2
,
4808 wpa_s
->p2p_persistent_id
,
4809 wpa_s
->p2p_pd_before_go_neg
,
4812 wpa_s
->p2p_go_max_oper_chwidth
,
4817 wpa_printf(MSG_DEBUG
, "P2P: Peer was found running GO%s -> "
4818 "try to join the group", join
? "" :
4821 wpa_msg_global(wpa_s
->p2pdev
, MSG_INFO
,
4822 P2P_EVENT_FALLBACK_TO_GO_NEG_ENABLED
);
4823 wpa_s
->p2p_fallback_to_go_neg
= 1;
4827 freq
= p2p_get_oper_freq(wpa_s
->global
->p2p
,
4828 wpa_s
->pending_join_iface_addr
);
4830 p2p_get_interface_addr(wpa_s
->global
->p2p
,
4831 wpa_s
->pending_join_dev_addr
,
4833 os_memcmp(iface_addr
, wpa_s
->pending_join_dev_addr
, ETH_ALEN
) != 0
4834 && !wpa_bss_get_bssid(wpa_s
, wpa_s
->pending_join_iface_addr
)) {
4835 wpa_printf(MSG_DEBUG
, "P2P: Overwrite pending interface "
4836 "address for join from " MACSTR
" to " MACSTR
4837 " based on newly discovered P2P peer entry",
4838 MAC2STR(wpa_s
->pending_join_iface_addr
),
4839 MAC2STR(iface_addr
));
4840 os_memcpy(wpa_s
->pending_join_iface_addr
, iface_addr
,
4843 freq
= p2p_get_oper_freq(wpa_s
->global
->p2p
,
4844 wpa_s
->pending_join_iface_addr
);
4847 wpa_printf(MSG_DEBUG
, "P2P: Target GO operating frequency "
4848 "from P2P peer table: %d MHz", freq
);
4850 if (wpa_s
->p2p_join_ssid_len
) {
4851 wpa_printf(MSG_DEBUG
, "P2P: Trying to find target GO BSS entry based on BSSID "
4852 MACSTR
" and SSID %s",
4853 MAC2STR(wpa_s
->pending_join_iface_addr
),
4854 wpa_ssid_txt(wpa_s
->p2p_join_ssid
,
4855 wpa_s
->p2p_join_ssid_len
));
4856 bss
= wpa_bss_get(wpa_s
, wpa_s
->pending_join_iface_addr
,
4857 wpa_s
->p2p_join_ssid
,
4858 wpa_s
->p2p_join_ssid_len
);
4860 wpa_printf(MSG_DEBUG
, "P2P: Trying to find target GO BSS entry based on BSSID "
4861 MACSTR
, MAC2STR(wpa_s
->pending_join_iface_addr
));
4862 bss
= wpa_bss_get_bssid_latest(wpa_s
,
4863 wpa_s
->pending_join_iface_addr
);
4866 u8 dev_addr
[ETH_ALEN
];
4869 wpa_printf(MSG_DEBUG
, "P2P: Target GO operating frequency "
4870 "from BSS table: %d MHz (SSID %s)", freq
,
4871 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
4872 if (p2p_parse_dev_addr((const u8
*) (bss
+ 1), bss
->ie_len
,
4874 os_memcmp(wpa_s
->pending_join_dev_addr
,
4875 wpa_s
->pending_join_iface_addr
, ETH_ALEN
) == 0 &&
4876 os_memcmp(dev_addr
, wpa_s
->pending_join_dev_addr
,
4878 wpa_printf(MSG_DEBUG
,
4879 "P2P: Update target GO device address based on BSS entry: " MACSTR
" (was " MACSTR
")",
4881 MAC2STR(wpa_s
->pending_join_dev_addr
));
4882 os_memcpy(wpa_s
->pending_join_dev_addr
, dev_addr
,
4889 if (wpas_check_freq_conflict(wpa_s
, freq
) > 0) {
4890 wpa_msg_global(wpa_s
->p2pdev
, MSG_INFO
,
4891 P2P_EVENT_GROUP_FORMATION_FAILURE
4892 "reason=FREQ_CONFLICT");
4893 wpas_notify_p2p_group_formation_failure(
4894 wpa_s
, "FREQ_CONFLICT");
4898 wpa_printf(MSG_DEBUG
, "P2P: Send Provision Discovery Request "
4899 "prior to joining an existing group (GO " MACSTR
4901 MAC2STR(wpa_s
->pending_join_dev_addr
), freq
);
4902 wpa_s
->pending_pd_before_join
= 1;
4904 switch (wpa_s
->pending_join_wps_method
) {
4905 case WPS_PIN_DISPLAY
:
4906 method
= WPS_CONFIG_KEYPAD
;
4908 case WPS_PIN_KEYPAD
:
4909 method
= WPS_CONFIG_DISPLAY
;
4912 method
= WPS_CONFIG_PUSHBUTTON
;
4915 method
= WPS_CONFIG_P2PS
;
4922 if ((p2p_get_provisioning_info(wpa_s
->global
->p2p
,
4923 wpa_s
->pending_join_dev_addr
) ==
4926 * We have already performed provision discovery for
4927 * joining the group. Proceed directly to join
4928 * operation without duplicated provision discovery. */
4929 wpa_printf(MSG_DEBUG
, "P2P: Provision discovery "
4930 "with " MACSTR
" already done - proceed to "
4932 MAC2STR(wpa_s
->pending_join_dev_addr
));
4933 wpa_s
->pending_pd_before_join
= 0;
4937 if (p2p_prov_disc_req(wpa_s
->global
->p2p
,
4938 wpa_s
->pending_join_dev_addr
,
4940 freq
, wpa_s
->user_initiated_pd
) < 0) {
4941 wpa_printf(MSG_DEBUG
, "P2P: Failed to send Provision "
4942 "Discovery Request before joining an "
4944 wpa_s
->pending_pd_before_join
= 0;
4950 wpa_printf(MSG_DEBUG
, "P2P: Failed to find BSS/GO - try again later");
4951 eloop_cancel_timeout(wpas_p2p_join_scan
, wpa_s
, NULL
);
4952 eloop_register_timeout(1, 0, wpas_p2p_join_scan
, wpa_s
, NULL
);
4953 wpas_p2p_check_join_scan_limit(wpa_s
);
4957 /* Start join operation immediately */
4958 wpas_p2p_join_start(wpa_s
, 0, wpa_s
->p2p_join_ssid
,
4959 wpa_s
->p2p_join_ssid_len
);
4963 static void wpas_p2p_join_scan_req(struct wpa_supplicant
*wpa_s
, int freq
,
4964 const u8
*ssid
, size_t ssid_len
)
4967 struct wpa_driver_scan_params params
;
4968 struct wpabuf
*wps_ie
, *ies
;
4970 int freqs
[2] = { 0, 0 };
4973 os_memset(¶ms
, 0, sizeof(params
));
4975 /* P2P Wildcard SSID */
4976 params
.num_ssids
= 1;
4977 if (ssid
&& ssid_len
) {
4978 params
.ssids
[0].ssid
= ssid
;
4979 params
.ssids
[0].ssid_len
= ssid_len
;
4980 os_memcpy(wpa_s
->p2p_join_ssid
, ssid
, ssid_len
);
4981 wpa_s
->p2p_join_ssid_len
= ssid_len
;
4983 params
.ssids
[0].ssid
= (u8
*) P2P_WILDCARD_SSID
;
4984 params
.ssids
[0].ssid_len
= P2P_WILDCARD_SSID_LEN
;
4985 wpa_s
->p2p_join_ssid_len
= 0;
4988 wpa_s
->wps
->dev
.p2p
= 1;
4989 wps_ie
= wps_build_probe_req_ie(DEV_PW_DEFAULT
, &wpa_s
->wps
->dev
,
4990 wpa_s
->wps
->uuid
, WPS_REQ_ENROLLEE
, 0,
4992 if (wps_ie
== NULL
) {
4993 wpas_p2p_scan_res_join(wpa_s
, NULL
);
5000 * If freq is not provided, check the operating freq of the GO
5001 * and use a single channel scan on if possible.
5003 oper_freq
= p2p_get_oper_freq(wpa_s
->global
->p2p
,
5004 wpa_s
->pending_join_iface_addr
);
5010 params
.freqs
= freqs
;
5013 ielen
= p2p_scan_ie_buf_len(wpa_s
->global
->p2p
);
5014 ies
= wpabuf_alloc(wpabuf_len(wps_ie
) + ielen
);
5016 wpabuf_free(wps_ie
);
5017 wpas_p2p_scan_res_join(wpa_s
, NULL
);
5020 wpabuf_put_buf(ies
, wps_ie
);
5021 wpabuf_free(wps_ie
);
5023 bands
= wpas_get_bands(wpa_s
, freqs
);
5024 p2p_scan_ie(wpa_s
->global
->p2p
, ies
, NULL
, bands
);
5026 params
.p2p_probe
= 1;
5027 params
.extra_ies
= wpabuf_head(ies
);
5028 params
.extra_ies_len
= wpabuf_len(ies
);
5030 if (wpa_s
->clear_driver_scan_cache
) {
5031 wpa_printf(MSG_DEBUG
,
5032 "Request driver to clear scan cache due to local BSS flush");
5033 params
.only_new_results
= 1;
5037 * Run a scan to update BSS table and start Provision Discovery once
5038 * the new scan results become available.
5040 ret
= wpa_drv_scan(wpa_s
, ¶ms
);
5042 os_get_reltime(&wpa_s
->scan_trigger_time
);
5043 wpa_s
->scan_res_handler
= wpas_p2p_scan_res_join
;
5044 wpa_s
->own_scan_requested
= 1;
5045 wpa_s
->clear_driver_scan_cache
= 0;
5051 wpa_printf(MSG_DEBUG
, "P2P: Failed to start scan for join - "
5053 eloop_cancel_timeout(wpas_p2p_join_scan
, wpa_s
, NULL
);
5054 eloop_register_timeout(1, 0, wpas_p2p_join_scan
, wpa_s
, NULL
);
5055 wpas_p2p_check_join_scan_limit(wpa_s
);
5060 static void wpas_p2p_join_scan(void *eloop_ctx
, void *timeout_ctx
)
5062 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
5063 wpas_p2p_join_scan_req(wpa_s
, 0, NULL
, 0);
5067 static int wpas_p2p_join(struct wpa_supplicant
*wpa_s
, const u8
*iface_addr
,
5068 const u8
*dev_addr
, enum p2p_wps_method wps_method
,
5069 int auto_join
, int op_freq
,
5070 const u8
*ssid
, size_t ssid_len
)
5072 wpa_printf(MSG_DEBUG
, "P2P: Request to join existing group (iface "
5073 MACSTR
" dev " MACSTR
" op_freq=%d)%s",
5074 MAC2STR(iface_addr
), MAC2STR(dev_addr
), op_freq
,
5075 auto_join
? " (auto_join)" : "");
5076 if (ssid
&& ssid_len
) {
5077 wpa_printf(MSG_DEBUG
, "P2P: Group SSID specified: %s",
5078 wpa_ssid_txt(ssid
, ssid_len
));
5081 wpa_s
->p2p_auto_pd
= 0;
5082 wpa_s
->p2p_auto_join
= !!auto_join
;
5083 os_memcpy(wpa_s
->pending_join_iface_addr
, iface_addr
, ETH_ALEN
);
5084 os_memcpy(wpa_s
->pending_join_dev_addr
, dev_addr
, ETH_ALEN
);
5085 wpa_s
->pending_join_wps_method
= wps_method
;
5087 /* Make sure we are not running find during connection establishment */
5088 wpas_p2p_stop_find(wpa_s
);
5090 wpa_s
->p2p_join_scan_count
= 0;
5091 wpas_p2p_join_scan_req(wpa_s
, op_freq
, ssid
, ssid_len
);
5096 static int wpas_p2p_join_start(struct wpa_supplicant
*wpa_s
, int freq
,
5097 const u8
*ssid
, size_t ssid_len
)
5099 struct wpa_supplicant
*group
;
5100 struct p2p_go_neg_results res
;
5101 struct wpa_bss
*bss
;
5103 group
= wpas_p2p_get_group_iface(wpa_s
, 0, 0);
5106 if (group
!= wpa_s
) {
5107 os_memcpy(group
->p2p_pin
, wpa_s
->p2p_pin
,
5108 sizeof(group
->p2p_pin
));
5109 group
->p2p_wps_method
= wpa_s
->p2p_wps_method
;
5113 * Need to mark the current interface for p2p_group_formation
5114 * when a separate group interface is not used. This is needed
5115 * to allow p2p_cancel stop a pending p2p_connect-join.
5116 * wpas_p2p_init_group_interface() addresses this for the case
5117 * where a separate group interface is used.
5119 if (group
== wpa_s
->parent
)
5120 wpa_s
->global
->p2p_group_formation
= group
;
5122 group
->p2p_in_provisioning
= 1;
5123 group
->p2p_fallback_to_go_neg
= wpa_s
->p2p_fallback_to_go_neg
;
5125 os_memset(&res
, 0, sizeof(res
));
5126 os_memcpy(res
.peer_device_addr
, wpa_s
->pending_join_dev_addr
, ETH_ALEN
);
5127 os_memcpy(res
.peer_interface_addr
, wpa_s
->pending_join_iface_addr
,
5129 res
.wps_method
= wpa_s
->pending_join_wps_method
;
5130 if (freq
&& ssid
&& ssid_len
) {
5132 res
.ssid_len
= ssid_len
;
5133 os_memcpy(res
.ssid
, ssid
, ssid_len
);
5135 if (ssid
&& ssid_len
) {
5136 bss
= wpa_bss_get(wpa_s
, wpa_s
->pending_join_iface_addr
,
5139 bss
= wpa_bss_get_bssid_latest(
5140 wpa_s
, wpa_s
->pending_join_iface_addr
);
5143 res
.freq
= bss
->freq
;
5144 res
.ssid_len
= bss
->ssid_len
;
5145 os_memcpy(res
.ssid
, bss
->ssid
, bss
->ssid_len
);
5146 wpa_printf(MSG_DEBUG
, "P2P: Join target GO operating frequency from BSS table: %d MHz (SSID %s)",
5148 wpa_ssid_txt(bss
->ssid
, bss
->ssid_len
));
5149 } else if (ssid
&& ssid_len
) {
5150 res
.ssid_len
= ssid_len
;
5151 os_memcpy(res
.ssid
, ssid
, ssid_len
);
5152 wpa_printf(MSG_DEBUG
, "P2P: Join target GO (SSID %s)",
5153 wpa_ssid_txt(ssid
, ssid_len
));
5157 if (wpa_s
->off_channel_freq
|| wpa_s
->roc_waiting_drv_freq
) {
5158 wpa_printf(MSG_DEBUG
, "P2P: Cancel remain-on-channel prior to "
5160 wpa_drv_cancel_remain_on_channel(wpa_s
);
5161 wpa_s
->off_channel_freq
= 0;
5162 wpa_s
->roc_waiting_drv_freq
= 0;
5164 wpas_start_wps_enrollee(group
, &res
);
5167 * Allow a longer timeout for join-a-running-group than normal 15
5168 * second group formation timeout since the GO may not have authorized
5169 * our connection yet.
5171 eloop_cancel_timeout(wpas_p2p_group_formation_timeout
, wpa_s
, NULL
);
5172 eloop_register_timeout(60, 0, wpas_p2p_group_formation_timeout
,
5179 static int wpas_p2p_setup_freqs(struct wpa_supplicant
*wpa_s
, int freq
,
5180 int *force_freq
, int *pref_freq
, int go
,
5181 unsigned int *pref_freq_list
,
5182 unsigned int *num_pref_freq
)
5184 struct wpa_used_freq_data
*freqs
;
5185 int res
, best_freq
, num_unused
;
5186 unsigned int freq_in_use
= 0, num
, i
, max_pref_freq
;
5188 max_pref_freq
= *num_pref_freq
;
5191 freqs
= os_calloc(wpa_s
->num_multichan_concurrent
,
5192 sizeof(struct wpa_used_freq_data
));
5196 num
= wpas_p2p_valid_oper_freqs(wpa_s
, freqs
,
5197 wpa_s
->num_multichan_concurrent
);
5200 * It is possible that the total number of used frequencies is bigger
5201 * than the number of frequencies used for P2P, so get the system wide
5202 * number of unused frequencies.
5204 num_unused
= wpas_p2p_num_unused_channels(wpa_s
);
5206 wpa_printf(MSG_DEBUG
,
5207 "P2P: Setup freqs: freq=%d num_MCC=%d shared_freqs=%u num_unused=%d",
5208 freq
, wpa_s
->num_multichan_concurrent
, num
, num_unused
);
5213 ret
= p2p_supported_freq(wpa_s
->global
->p2p
, freq
);
5215 ret
= p2p_supported_freq_cli(wpa_s
->global
->p2p
, freq
);
5217 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_DFS_OFFLOAD
) &&
5218 ieee80211_is_dfs(freq
, wpa_s
->hw
.modes
,
5219 wpa_s
->hw
.num_modes
)) {
5221 * If freq is a DFS channel and DFS is offloaded
5222 * to the driver, allow P2P GO to use it.
5224 wpa_printf(MSG_DEBUG
,
5225 "P2P: The forced channel for GO (%u MHz) is DFS, and DFS is offloaded to the driver",
5228 wpa_printf(MSG_DEBUG
,
5229 "P2P: The forced channel (%u MHz) is not supported for P2P uses",
5236 for (i
= 0; i
< num
; i
++) {
5237 if (freqs
[i
].freq
== freq
)
5241 if (num_unused
<= 0 && !freq_in_use
) {
5242 wpa_printf(MSG_DEBUG
, "P2P: Cannot start P2P group on %u MHz as there are no available channels",
5247 wpa_printf(MSG_DEBUG
, "P2P: Trying to force us to use the "
5248 "requested channel (%u MHz)", freq
);
5253 best_freq
= wpas_p2p_pick_best_used_freq(wpa_s
, freqs
, num
);
5255 if (!wpa_s
->conf
->num_p2p_pref_chan
&& *pref_freq
== 0) {
5256 enum wpa_driver_if_type iface_type
;
5259 iface_type
= WPA_IF_P2P_GO
;
5261 iface_type
= WPA_IF_P2P_CLIENT
;
5263 wpa_printf(MSG_DEBUG
, "P2P: best_freq=%d, go=%d",
5266 res
= wpa_drv_get_pref_freq_list(wpa_s
, iface_type
,
5269 if (!res
&& max_pref_freq
> 0) {
5270 *num_pref_freq
= max_pref_freq
;
5272 while (i
< *num_pref_freq
&&
5273 (!p2p_supported_freq(wpa_s
->global
->p2p
,
5274 pref_freq_list
[i
]) ||
5275 wpas_p2p_disallowed_freq(wpa_s
->global
,
5276 pref_freq_list
[i
]))) {
5277 wpa_printf(MSG_DEBUG
,
5278 "P2P: preferred_freq_list[%d]=%d is disallowed",
5279 i
, pref_freq_list
[i
]);
5282 if (i
!= *num_pref_freq
) {
5283 best_freq
= pref_freq_list
[i
];
5284 wpa_printf(MSG_DEBUG
,
5285 "P2P: Using preferred_freq_list[%d]=%d",
5288 wpa_printf(MSG_DEBUG
,
5289 "P2P: All driver preferred frequencies are disallowed for P2P use");
5293 wpa_printf(MSG_DEBUG
,
5294 "P2P: No preferred frequency list available");
5298 /* We have a candidate frequency to use */
5299 if (best_freq
> 0) {
5300 if (*pref_freq
== 0 && num_unused
> 0) {
5301 wpa_printf(MSG_DEBUG
, "P2P: Try to prefer a frequency (%u MHz) we are already using",
5303 *pref_freq
= best_freq
;
5305 wpa_printf(MSG_DEBUG
, "P2P: Try to force us to use frequency (%u MHz) which is already in use",
5307 *force_freq
= best_freq
;
5309 } else if (num_unused
> 0) {
5310 wpa_printf(MSG_DEBUG
,
5311 "P2P: Current operating channels are not available for P2P. Try to use another channel");
5314 wpa_printf(MSG_DEBUG
,
5315 "P2P: All channels are in use and none of them are P2P enabled. Cannot start P2P group");
5329 * wpas_p2p_connect - Request P2P Group Formation to be started
5330 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
5331 * @peer_addr: Address of the peer P2P Device
5332 * @pin: PIN to use during provisioning or %NULL to indicate PBC mode
5333 * @persistent_group: Whether to create a persistent group
5334 * @auto_join: Whether to select join vs. GO Negotiation automatically
5335 * @join: Whether to join an existing group (as a client) instead of starting
5336 * Group Owner negotiation; @peer_addr is BSSID in that case
5337 * @auth: Whether to only authorize the connection instead of doing that and
5338 * initiating Group Owner negotiation
5339 * @go_intent: GO Intent or -1 to use default
5340 * @freq: Frequency for the group or 0 for auto-selection
5341 * @freq2: Center frequency of segment 1 for the GO operating in VHT 80P80 mode
5342 * @persistent_id: Persistent group credentials to use for forcing GO
5343 * parameters or -1 to generate new values (SSID/passphrase)
5344 * @pd: Whether to send Provision Discovery prior to GO Negotiation as an
5345 * interoperability workaround when initiating group formation
5346 * @ht40: Start GO with 40 MHz channel width
5347 * @vht: Start GO with VHT support
5348 * @vht_chwidth: Channel width supported by GO operating with VHT support
5349 * (VHT_CHANWIDTH_*).
5350 * @group_ssid: Specific Group SSID for join or %NULL if not set
5351 * @group_ssid_len: Length of @group_ssid in octets
5352 * Returns: 0 or new PIN (if pin was %NULL) on success, -1 on unspecified
5353 * failure, -2 on failure due to channel not currently available,
5354 * -3 if forced channel is not supported
5356 int wpas_p2p_connect(struct wpa_supplicant
*wpa_s
, const u8
*peer_addr
,
5357 const char *pin
, enum p2p_wps_method wps_method
,
5358 int persistent_group
, int auto_join
, int join
, int auth
,
5359 int go_intent
, int freq
, unsigned int vht_center_freq2
,
5360 int persistent_id
, int pd
, int ht40
, int vht
,
5361 unsigned int vht_chwidth
, const u8
*group_ssid
,
5362 size_t group_ssid_len
)
5364 int force_freq
= 0, pref_freq
= 0;
5366 enum wpa_driver_if_type iftype
;
5368 struct wpa_ssid
*ssid
= NULL
;
5369 unsigned int pref_freq_list
[P2P_MAX_PREF_CHANNELS
], size
;
5371 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
5374 if (persistent_id
>= 0) {
5375 ssid
= wpa_config_get_network(wpa_s
->conf
, persistent_id
);
5376 if (ssid
== NULL
|| ssid
->disabled
!= 2 ||
5377 ssid
->mode
!= WPAS_MODE_P2P_GO
)
5381 os_free(wpa_s
->global
->add_psk
);
5382 wpa_s
->global
->add_psk
= NULL
;
5384 wpa_s
->global
->p2p_fail_on_wps_complete
= 0;
5385 wpa_s
->global
->pending_p2ps_group
= 0;
5386 wpa_s
->global
->pending_p2ps_group_freq
= 0;
5387 wpa_s
->p2ps_method_config_any
= 0;
5390 go_intent
= wpa_s
->conf
->p2p_go_intent
;
5393 wpa_s
->p2p_long_listen
= 0;
5395 wpa_s
->p2p_wps_method
= wps_method
;
5396 wpa_s
->p2p_persistent_group
= !!persistent_group
;
5397 wpa_s
->p2p_persistent_id
= persistent_id
;
5398 wpa_s
->p2p_go_intent
= go_intent
;
5399 wpa_s
->p2p_connect_freq
= freq
;
5400 wpa_s
->p2p_fallback_to_go_neg
= 0;
5401 wpa_s
->p2p_pd_before_go_neg
= !!pd
;
5402 wpa_s
->p2p_go_ht40
= !!ht40
;
5403 wpa_s
->p2p_go_vht
= !!vht
;
5404 wpa_s
->p2p_go_vht_center_freq2
= vht_center_freq2
;
5405 wpa_s
->p2p_go_max_oper_chwidth
= vht_chwidth
;
5408 os_strlcpy(wpa_s
->p2p_pin
, pin
, sizeof(wpa_s
->p2p_pin
));
5409 else if (wps_method
== WPS_PIN_DISPLAY
) {
5410 if (wps_generate_pin((unsigned int *) &ret
) < 0)
5412 res
= os_snprintf(wpa_s
->p2p_pin
, sizeof(wpa_s
->p2p_pin
),
5414 if (os_snprintf_error(sizeof(wpa_s
->p2p_pin
), res
))
5415 wpa_s
->p2p_pin
[sizeof(wpa_s
->p2p_pin
) - 1] = '\0';
5416 wpa_printf(MSG_DEBUG
, "P2P: Randomly generated PIN: %s",
5418 } else if (wps_method
== WPS_P2PS
) {
5419 /* Force the P2Ps default PIN to be used */
5420 os_strlcpy(wpa_s
->p2p_pin
, "12345670", sizeof(wpa_s
->p2p_pin
));
5422 wpa_s
->p2p_pin
[0] = '\0';
5424 if (join
|| auto_join
) {
5425 u8 iface_addr
[ETH_ALEN
], dev_addr
[ETH_ALEN
];
5427 wpa_printf(MSG_DEBUG
, "P2P: Authorize invitation to "
5428 "connect a running group from " MACSTR
,
5429 MAC2STR(peer_addr
));
5430 os_memcpy(wpa_s
->p2p_auth_invite
, peer_addr
, ETH_ALEN
);
5433 os_memcpy(dev_addr
, peer_addr
, ETH_ALEN
);
5434 if (p2p_get_interface_addr(wpa_s
->global
->p2p
, peer_addr
,
5436 os_memcpy(iface_addr
, peer_addr
, ETH_ALEN
);
5437 p2p_get_dev_addr(wpa_s
->global
->p2p
, peer_addr
,
5441 os_get_reltime(&wpa_s
->p2p_auto_started
);
5442 wpa_printf(MSG_DEBUG
, "P2P: Auto join started at "
5444 wpa_s
->p2p_auto_started
.sec
,
5445 wpa_s
->p2p_auto_started
.usec
);
5447 wpa_s
->user_initiated_pd
= 1;
5448 if (wpas_p2p_join(wpa_s
, iface_addr
, dev_addr
, wps_method
,
5450 group_ssid
, group_ssid_len
) < 0)
5455 size
= P2P_MAX_PREF_CHANNELS
;
5456 res
= wpas_p2p_setup_freqs(wpa_s
, freq
, &force_freq
, &pref_freq
,
5457 go_intent
== 15, pref_freq_list
, &size
);
5460 wpas_p2p_set_own_freq_preference(wpa_s
,
5461 force_freq
? force_freq
: pref_freq
);
5463 p2p_set_own_pref_freq_list(wpa_s
->global
->p2p
, pref_freq_list
, size
);
5465 wpa_s
->create_p2p_iface
= wpas_p2p_create_iface(wpa_s
);
5467 if (wpa_s
->create_p2p_iface
) {
5468 /* Prepare to add a new interface for the group */
5469 iftype
= WPA_IF_P2P_GROUP
;
5470 if (go_intent
== 15)
5471 iftype
= WPA_IF_P2P_GO
;
5472 if (wpas_p2p_add_group_interface(wpa_s
, iftype
) < 0) {
5473 wpa_printf(MSG_ERROR
, "P2P: Failed to allocate a new "
5474 "interface for the group");
5478 if_addr
= wpa_s
->pending_interface_addr
;
5480 if (wpa_s
->p2p_mgmt
)
5481 if_addr
= wpa_s
->parent
->own_addr
;
5483 if_addr
= wpa_s
->own_addr
;
5484 os_memset(wpa_s
->go_dev_addr
, 0, ETH_ALEN
);
5488 if (wpas_p2p_auth_go_neg(wpa_s
, peer_addr
, wps_method
,
5490 force_freq
, persistent_group
, ssid
,
5496 if (wpas_p2p_start_go_neg(wpa_s
, peer_addr
, wps_method
,
5497 go_intent
, if_addr
, force_freq
,
5498 persistent_group
, ssid
, pref_freq
) < 0) {
5499 if (wpa_s
->create_p2p_iface
)
5500 wpas_p2p_remove_pending_group_interface(wpa_s
);
5508 * wpas_p2p_remain_on_channel_cb - Indication of remain-on-channel start
5509 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
5510 * @freq: Frequency of the channel in MHz
5511 * @duration: Duration of the stay on the channel in milliseconds
5513 * This callback is called when the driver indicates that it has started the
5514 * requested remain-on-channel duration.
5516 void wpas_p2p_remain_on_channel_cb(struct wpa_supplicant
*wpa_s
,
5517 unsigned int freq
, unsigned int duration
)
5519 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
5521 wpa_printf(MSG_DEBUG
, "P2P: remain-on-channel callback (off_channel_freq=%u pending_listen_freq=%d roc_waiting_drv_freq=%d freq=%u duration=%u)",
5522 wpa_s
->off_channel_freq
, wpa_s
->pending_listen_freq
,
5523 wpa_s
->roc_waiting_drv_freq
, freq
, duration
);
5524 if (wpa_s
->off_channel_freq
&&
5525 wpa_s
->off_channel_freq
== wpa_s
->pending_listen_freq
) {
5526 p2p_listen_cb(wpa_s
->global
->p2p
, wpa_s
->pending_listen_freq
,
5527 wpa_s
->pending_listen_duration
);
5528 wpa_s
->pending_listen_freq
= 0;
5530 wpa_printf(MSG_DEBUG
, "P2P: Ignore remain-on-channel callback (off_channel_freq=%u pending_listen_freq=%d freq=%u duration=%u)",
5531 wpa_s
->off_channel_freq
, wpa_s
->pending_listen_freq
,
5537 int wpas_p2p_listen_start(struct wpa_supplicant
*wpa_s
, unsigned int timeout
)
5539 /* Limit maximum Listen state time based on driver limitation. */
5540 if (timeout
> wpa_s
->max_remain_on_chan
)
5541 timeout
= wpa_s
->max_remain_on_chan
;
5543 return p2p_listen(wpa_s
->global
->p2p
, timeout
);
5548 * wpas_p2p_cancel_remain_on_channel_cb - Remain-on-channel timeout
5549 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
5550 * @freq: Frequency of the channel in MHz
5552 * This callback is called when the driver indicates that a remain-on-channel
5553 * operation has been completed, i.e., the duration on the requested channel
5556 void wpas_p2p_cancel_remain_on_channel_cb(struct wpa_supplicant
*wpa_s
,
5559 wpa_printf(MSG_DEBUG
, "P2P: Cancel remain-on-channel callback "
5560 "(p2p_long_listen=%d ms pending_action_tx=%p)",
5561 wpa_s
->p2p_long_listen
, offchannel_pending_action_tx(wpa_s
));
5562 wpas_p2p_listen_work_done(wpa_s
);
5563 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
5565 if (wpa_s
->p2p_long_listen
> 0)
5566 wpa_s
->p2p_long_listen
-= wpa_s
->max_remain_on_chan
;
5567 if (p2p_listen_end(wpa_s
->global
->p2p
, freq
) > 0)
5568 return; /* P2P module started a new operation */
5569 if (offchannel_pending_action_tx(wpa_s
))
5571 if (wpa_s
->p2p_long_listen
> 0) {
5572 wpa_printf(MSG_DEBUG
, "P2P: Continuing long Listen state");
5573 wpas_p2p_listen_start(wpa_s
, wpa_s
->p2p_long_listen
);
5576 * When listen duration is over, stop listen & update p2p_state
5579 p2p_stop_listen(wpa_s
->global
->p2p
);
5585 * wpas_p2p_group_remove - Remove a P2P group
5586 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
5587 * @ifname: Network interface name of the group interface or "*" to remove all
5589 * Returns: 0 on success, -1 on failure
5591 * This function is used to remove a P2P group. This can be used to disconnect
5592 * from a group in which the local end is a P2P Client or to end a P2P Group in
5593 * case the local end is the Group Owner. If a virtual network interface was
5594 * created for this group, that interface will be removed. Otherwise, only the
5595 * configured P2P group network will be removed from the interface.
5597 int wpas_p2p_group_remove(struct wpa_supplicant
*wpa_s
, const char *ifname
)
5599 struct wpa_global
*global
= wpa_s
->global
;
5600 struct wpa_supplicant
*calling_wpa_s
= wpa_s
;
5602 if (os_strcmp(ifname
, "*") == 0) {
5603 struct wpa_supplicant
*prev
;
5604 wpa_s
= global
->ifaces
;
5607 wpa_s
= wpa_s
->next
;
5608 if (prev
->p2p_group_interface
!=
5609 NOT_P2P_GROUP_INTERFACE
||
5610 (prev
->current_ssid
&&
5611 prev
->current_ssid
->p2p_group
))
5612 wpas_p2p_disconnect_safely(prev
, calling_wpa_s
);
5617 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
5618 if (os_strcmp(wpa_s
->ifname
, ifname
) == 0)
5622 return wpas_p2p_disconnect_safely(wpa_s
, calling_wpa_s
);
5626 static int wpas_p2p_select_go_freq(struct wpa_supplicant
*wpa_s
, int freq
)
5630 if (!wpa_s
->conf
->num_p2p_pref_chan
&& !freq
) {
5631 unsigned int i
, size
= P2P_MAX_PREF_CHANNELS
;
5632 unsigned int pref_freq_list
[P2P_MAX_PREF_CHANNELS
];
5635 res
= wpa_drv_get_pref_freq_list(wpa_s
, WPA_IF_P2P_GO
,
5636 &size
, pref_freq_list
);
5637 if (!res
&& size
> 0) {
5640 (!p2p_supported_freq(wpa_s
->global
->p2p
,
5641 pref_freq_list
[i
]) ||
5642 wpas_p2p_disallowed_freq(wpa_s
->global
,
5643 pref_freq_list
[i
]))) {
5644 wpa_printf(MSG_DEBUG
,
5645 "P2P: preferred_freq_list[%d]=%d is disallowed",
5646 i
, pref_freq_list
[i
]);
5650 freq
= pref_freq_list
[i
];
5651 wpa_printf(MSG_DEBUG
,
5652 "P2P: Using preferred_freq_list[%d]=%d",
5655 wpa_printf(MSG_DEBUG
,
5656 "P2P: All driver preferred frequencies are disallowed for P2P use");
5659 wpa_printf(MSG_DEBUG
,
5660 "P2P: No preferred frequency list available");
5665 wpa_printf(MSG_DEBUG
, "P2P: Request to start GO on 2.4 GHz "
5667 if (wpa_s
->best_24_freq
> 0 &&
5668 p2p_supported_freq_go(wpa_s
->global
->p2p
,
5669 wpa_s
->best_24_freq
)) {
5670 freq
= wpa_s
->best_24_freq
;
5671 wpa_printf(MSG_DEBUG
, "P2P: Use best 2.4 GHz band "
5672 "channel: %d MHz", freq
);
5674 if (os_get_random((u8
*) &r
, sizeof(r
)) < 0)
5676 freq
= 2412 + (r
% 3) * 25;
5677 wpa_printf(MSG_DEBUG
, "P2P: Use random 2.4 GHz band "
5678 "channel: %d MHz", freq
);
5683 wpa_printf(MSG_DEBUG
, "P2P: Request to start GO on 5 GHz "
5685 if (wpa_s
->best_5_freq
> 0 &&
5686 p2p_supported_freq_go(wpa_s
->global
->p2p
,
5687 wpa_s
->best_5_freq
)) {
5688 freq
= wpa_s
->best_5_freq
;
5689 wpa_printf(MSG_DEBUG
, "P2P: Use best 5 GHz band "
5690 "channel: %d MHz", freq
);
5692 if (os_get_random((u8
*) &r
, sizeof(r
)) < 0)
5694 freq
= 5180 + (r
% 4) * 20;
5695 if (!p2p_supported_freq_go(wpa_s
->global
->p2p
, freq
)) {
5696 wpa_printf(MSG_DEBUG
, "P2P: Could not select "
5697 "5 GHz channel for P2P group");
5700 wpa_printf(MSG_DEBUG
, "P2P: Use random 5 GHz band "
5701 "channel: %d MHz", freq
);
5705 if (freq
> 0 && !p2p_supported_freq_go(wpa_s
->global
->p2p
, freq
)) {
5706 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_DFS_OFFLOAD
) &&
5707 ieee80211_is_dfs(freq
, wpa_s
->hw
.modes
,
5708 wpa_s
->hw
.num_modes
)) {
5710 * If freq is a DFS channel and DFS is offloaded to the
5711 * driver, allow P2P GO to use it.
5713 wpa_printf(MSG_DEBUG
, "P2P: "
5714 "%s: The forced channel for GO (%u MHz) is DFS, and DFS is offloaded",
5718 wpa_printf(MSG_DEBUG
, "P2P: The forced channel for GO "
5719 "(%u MHz) is not supported for P2P uses",
5728 static int wpas_p2p_supported_freq_go(struct wpa_supplicant
*wpa_s
,
5729 const struct p2p_channels
*channels
,
5732 if (!wpas_p2p_disallowed_freq(wpa_s
->global
, freq
) &&
5733 p2p_supported_freq_go(wpa_s
->global
->p2p
, freq
) &&
5734 freq_included(wpa_s
, channels
, freq
))
5740 static void wpas_p2p_select_go_freq_no_pref(struct wpa_supplicant
*wpa_s
,
5741 struct p2p_go_neg_results
*params
,
5742 const struct p2p_channels
*channels
)
5746 /* try all channels in operating class 115 */
5747 for (i
= 0; i
< 4; i
++) {
5748 params
->freq
= 5180 + i
* 20;
5749 if (!wpas_p2p_disallowed_freq(wpa_s
->global
, params
->freq
) &&
5750 freq_included(wpa_s
, channels
, params
->freq
) &&
5751 p2p_supported_freq(wpa_s
->global
->p2p
, params
->freq
))
5755 /* try all channels in operating class 124 */
5756 for (i
= 0; i
< 4; i
++) {
5757 params
->freq
= 5745 + i
* 20;
5758 if (!wpas_p2p_disallowed_freq(wpa_s
->global
, params
->freq
) &&
5759 freq_included(wpa_s
, channels
, params
->freq
) &&
5760 p2p_supported_freq(wpa_s
->global
->p2p
, params
->freq
))
5764 /* try social channel class 180 channel 2 */
5765 params
->freq
= 58320 + 1 * 2160;
5766 if (!wpas_p2p_disallowed_freq(wpa_s
->global
, params
->freq
) &&
5767 freq_included(wpa_s
, channels
, params
->freq
) &&
5768 p2p_supported_freq(wpa_s
->global
->p2p
, params
->freq
))
5771 /* try all channels in reg. class 180 */
5772 for (i
= 0; i
< 4; i
++) {
5773 params
->freq
= 58320 + i
* 2160;
5774 if (!wpas_p2p_disallowed_freq(wpa_s
->global
, params
->freq
) &&
5775 freq_included(wpa_s
, channels
, params
->freq
) &&
5776 p2p_supported_freq(wpa_s
->global
->p2p
, params
->freq
))
5780 /* try some random selection of the social channels */
5781 if (os_get_random((u8
*) &r
, sizeof(r
)) < 0)
5784 for (i
= 0; i
< 3; i
++) {
5785 params
->freq
= 2412 + ((r
+ i
) % 3) * 25;
5786 if (wpas_p2p_supported_freq_go(wpa_s
, channels
, params
->freq
))
5790 /* try all other channels in operating class 81 */
5791 for (i
= 0; i
< 11; i
++) {
5792 params
->freq
= 2412 + i
* 5;
5794 /* skip social channels; covered in the previous loop */
5795 if (params
->freq
== 2412 ||
5796 params
->freq
== 2437 ||
5797 params
->freq
== 2462)
5800 if (wpas_p2p_supported_freq_go(wpa_s
, channels
, params
->freq
))
5805 wpa_printf(MSG_DEBUG
, "P2P: No 2.4, 5, or 60 GHz channel allowed");
5808 wpa_printf(MSG_DEBUG
, "P2P: Set GO freq %d MHz (no preference known)",
5813 static int wpas_same_band(int freq1
, int freq2
)
5815 enum hostapd_hw_mode mode1
, mode2
;
5818 mode1
= ieee80211_freq_to_chan(freq1
, &chan1
);
5819 mode2
= ieee80211_freq_to_chan(freq2
, &chan2
);
5820 if (mode1
== NUM_HOSTAPD_MODES
)
5822 return mode1
== mode2
;
5826 static int wpas_p2p_init_go_params(struct wpa_supplicant
*wpa_s
,
5827 struct p2p_go_neg_results
*params
,
5828 int freq
, int vht_center_freq2
, int ht40
,
5829 int vht
, int max_oper_chwidth
,
5830 const struct p2p_channels
*channels
)
5832 struct wpa_used_freq_data
*freqs
;
5834 unsigned int num
, i
;
5835 int ignore_no_freqs
= 0;
5836 int unused_channels
= wpas_p2p_num_unused_channels(wpa_s
) > 0;
5838 os_memset(params
, 0, sizeof(*params
));
5839 params
->role_go
= 1;
5840 params
->ht40
= ht40
;
5842 params
->max_oper_chwidth
= max_oper_chwidth
;
5843 params
->vht_center_freq2
= vht_center_freq2
;
5845 freqs
= os_calloc(wpa_s
->num_multichan_concurrent
,
5846 sizeof(struct wpa_used_freq_data
));
5850 num
= get_shared_radio_freqs_data(wpa_s
, freqs
,
5851 wpa_s
->num_multichan_concurrent
);
5853 if (wpa_s
->current_ssid
&&
5854 wpa_s
->current_ssid
->mode
== WPAS_MODE_P2P_GO
&&
5855 wpa_s
->wpa_state
== WPA_COMPLETED
) {
5856 wpa_printf(MSG_DEBUG
, "P2P: %s called for an active GO",
5860 * If the frequency selection is done for an active P2P GO that
5861 * is not sharing a frequency, allow to select a new frequency
5862 * even if there are no unused frequencies as we are about to
5863 * move the P2P GO so its frequency can be re-used.
5865 for (i
= 0; i
< num
; i
++) {
5866 if (freqs
[i
].freq
== wpa_s
->current_ssid
->frequency
&&
5867 freqs
[i
].flags
== 0) {
5868 ignore_no_freqs
= 1;
5874 /* try using the forced freq */
5876 if (wpas_p2p_disallowed_freq(wpa_s
->global
, freq
) ||
5877 !freq_included(wpa_s
, channels
, freq
)) {
5878 wpa_printf(MSG_DEBUG
,
5879 "P2P: Forced GO freq %d MHz disallowed",
5883 if (!p2p_supported_freq_go(wpa_s
->global
->p2p
, freq
)) {
5884 if ((wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_DFS_OFFLOAD
) &&
5885 ieee80211_is_dfs(freq
, wpa_s
->hw
.modes
,
5886 wpa_s
->hw
.num_modes
)) {
5888 * If freq is a DFS channel and DFS is offloaded
5889 * to the driver, allow P2P GO to use it.
5891 wpa_printf(MSG_DEBUG
,
5892 "P2P: %s: The forced channel for GO (%u MHz) requires DFS and DFS is offloaded",
5895 wpa_printf(MSG_DEBUG
,
5896 "P2P: The forced channel for GO (%u MHz) is not supported for P2P uses",
5902 for (i
= 0; i
< num
; i
++) {
5903 if (freqs
[i
].freq
== freq
) {
5904 wpa_printf(MSG_DEBUG
,
5905 "P2P: forced freq (%d MHz) is also shared",
5907 params
->freq
= freq
;
5912 if (!ignore_no_freqs
&& !unused_channels
) {
5913 wpa_printf(MSG_DEBUG
,
5914 "P2P: Cannot force GO on freq (%d MHz) as all the channels are in use",
5919 wpa_printf(MSG_DEBUG
,
5920 "P2P: force GO freq (%d MHz) on a free channel",
5922 params
->freq
= freq
;
5926 /* consider using one of the shared frequencies */
5928 (!wpa_s
->conf
->p2p_ignore_shared_freq
|| !unused_channels
)) {
5929 cand
= wpas_p2p_pick_best_used_freq(wpa_s
, freqs
, num
);
5930 if (wpas_p2p_supported_freq_go(wpa_s
, channels
, cand
)) {
5931 wpa_printf(MSG_DEBUG
,
5932 "P2P: Use shared freq (%d MHz) for GO",
5934 params
->freq
= cand
;
5938 /* try using one of the shared freqs */
5939 for (i
= 0; i
< num
; i
++) {
5940 if (wpas_p2p_supported_freq_go(wpa_s
, channels
,
5942 wpa_printf(MSG_DEBUG
,
5943 "P2P: Use shared freq (%d MHz) for GO",
5945 params
->freq
= freqs
[i
].freq
;
5951 if (!ignore_no_freqs
&& !unused_channels
) {
5952 wpa_printf(MSG_DEBUG
,
5953 "P2P: Cannot force GO on any of the channels we are already using");
5957 /* try using the setting from the configuration file */
5958 if (wpa_s
->conf
->p2p_oper_reg_class
== 81 &&
5959 wpa_s
->conf
->p2p_oper_channel
>= 1 &&
5960 wpa_s
->conf
->p2p_oper_channel
<= 11 &&
5961 wpas_p2p_supported_freq_go(
5963 2407 + 5 * wpa_s
->conf
->p2p_oper_channel
)) {
5964 params
->freq
= 2407 + 5 * wpa_s
->conf
->p2p_oper_channel
;
5965 wpa_printf(MSG_DEBUG
, "P2P: Set GO freq based on configured "
5966 "frequency %d MHz", params
->freq
);
5970 if ((wpa_s
->conf
->p2p_oper_reg_class
== 115 ||
5971 wpa_s
->conf
->p2p_oper_reg_class
== 116 ||
5972 wpa_s
->conf
->p2p_oper_reg_class
== 117 ||
5973 wpa_s
->conf
->p2p_oper_reg_class
== 124 ||
5974 wpa_s
->conf
->p2p_oper_reg_class
== 125 ||
5975 wpa_s
->conf
->p2p_oper_reg_class
== 126 ||
5976 wpa_s
->conf
->p2p_oper_reg_class
== 127) &&
5977 wpas_p2p_supported_freq_go(wpa_s
, channels
,
5979 5 * wpa_s
->conf
->p2p_oper_channel
)) {
5980 params
->freq
= 5000 + 5 * wpa_s
->conf
->p2p_oper_channel
;
5981 wpa_printf(MSG_DEBUG
, "P2P: Set GO freq based on configured "
5982 "frequency %d MHz", params
->freq
);
5986 /* Try using best channels */
5987 if (wpa_s
->conf
->p2p_oper_channel
== 0 &&
5988 wpa_s
->best_overall_freq
> 0 &&
5989 wpas_p2p_supported_freq_go(wpa_s
, channels
,
5990 wpa_s
->best_overall_freq
)) {
5991 params
->freq
= wpa_s
->best_overall_freq
;
5992 wpa_printf(MSG_DEBUG
, "P2P: Set GO freq based on best overall "
5993 "channel %d MHz", params
->freq
);
5997 if (wpa_s
->conf
->p2p_oper_channel
== 0 &&
5998 wpa_s
->best_24_freq
> 0 &&
5999 wpas_p2p_supported_freq_go(wpa_s
, channels
,
6000 wpa_s
->best_24_freq
)) {
6001 params
->freq
= wpa_s
->best_24_freq
;
6002 wpa_printf(MSG_DEBUG
, "P2P: Set GO freq based on best 2.4 GHz "
6003 "channel %d MHz", params
->freq
);
6007 if (wpa_s
->conf
->p2p_oper_channel
== 0 &&
6008 wpa_s
->best_5_freq
> 0 &&
6009 wpas_p2p_supported_freq_go(wpa_s
, channels
,
6010 wpa_s
->best_5_freq
)) {
6011 params
->freq
= wpa_s
->best_5_freq
;
6012 wpa_printf(MSG_DEBUG
, "P2P: Set GO freq based on best 5 GHz "
6013 "channel %d MHz", params
->freq
);
6017 /* try using preferred channels */
6018 cand
= p2p_get_pref_freq(wpa_s
->global
->p2p
, channels
);
6019 if (cand
&& wpas_p2p_supported_freq_go(wpa_s
, channels
, cand
)) {
6020 params
->freq
= cand
;
6021 wpa_printf(MSG_DEBUG
, "P2P: Set GO freq %d MHz from preferred "
6022 "channels", params
->freq
);
6026 /* Try using a channel that allows VHT to be used with 80 MHz */
6027 if (wpa_s
->hw
.modes
&& wpa_s
->p2p_group_common_freqs
) {
6028 for (i
= 0; i
< wpa_s
->p2p_group_common_freqs_num
; i
++) {
6029 enum hostapd_hw_mode mode
;
6030 struct hostapd_hw_modes
*hwmode
;
6033 cand
= wpa_s
->p2p_group_common_freqs
[i
];
6034 mode
= ieee80211_freq_to_chan(cand
, &chan
);
6035 hwmode
= get_mode(wpa_s
->hw
.modes
, wpa_s
->hw
.num_modes
,
6038 wpas_p2p_verify_channel(wpa_s
, hwmode
, chan
,
6041 if (wpas_p2p_supported_freq_go(wpa_s
, channels
, cand
)) {
6042 params
->freq
= cand
;
6043 wpa_printf(MSG_DEBUG
,
6044 "P2P: Use freq %d MHz common with the peer and allowing VHT80",
6051 /* Try using a channel that allows HT to be used with 40 MHz on the same
6052 * band so that CSA can be used */
6053 if (wpa_s
->current_ssid
&& wpa_s
->hw
.modes
&&
6054 wpa_s
->p2p_group_common_freqs
) {
6055 for (i
= 0; i
< wpa_s
->p2p_group_common_freqs_num
; i
++) {
6056 enum hostapd_hw_mode mode
;
6057 struct hostapd_hw_modes
*hwmode
;
6060 cand
= wpa_s
->p2p_group_common_freqs
[i
];
6061 mode
= ieee80211_freq_to_chan(cand
, &chan
);
6062 hwmode
= get_mode(wpa_s
->hw
.modes
, wpa_s
->hw
.num_modes
,
6064 if (!wpas_same_band(wpa_s
->current_ssid
->frequency
,
6067 (wpas_p2p_verify_channel(wpa_s
, hwmode
, chan
,
6068 BW40MINUS
) != ALLOWED
&&
6069 wpas_p2p_verify_channel(wpa_s
, hwmode
, chan
,
6070 BW40PLUS
) != ALLOWED
))
6072 if (wpas_p2p_supported_freq_go(wpa_s
, channels
, cand
)) {
6073 params
->freq
= cand
;
6074 wpa_printf(MSG_DEBUG
,
6075 "P2P: Use freq %d MHz common with the peer, allowing HT40, and maintaining same band",
6082 /* Try using one of the group common freqs on the same band so that CSA
6084 if (wpa_s
->current_ssid
&& wpa_s
->p2p_group_common_freqs
) {
6085 for (i
= 0; i
< wpa_s
->p2p_group_common_freqs_num
; i
++) {
6086 cand
= wpa_s
->p2p_group_common_freqs
[i
];
6087 if (!wpas_same_band(wpa_s
->current_ssid
->frequency
,
6090 if (wpas_p2p_supported_freq_go(wpa_s
, channels
, cand
)) {
6091 params
->freq
= cand
;
6092 wpa_printf(MSG_DEBUG
,
6093 "P2P: Use freq %d MHz common with the peer and maintaining same band",
6100 /* Try using one of the group common freqs */
6101 if (wpa_s
->p2p_group_common_freqs
) {
6102 for (i
= 0; i
< wpa_s
->p2p_group_common_freqs_num
; i
++) {
6103 cand
= wpa_s
->p2p_group_common_freqs
[i
];
6104 if (wpas_p2p_supported_freq_go(wpa_s
, channels
, cand
)) {
6105 params
->freq
= cand
;
6106 wpa_printf(MSG_DEBUG
,
6107 "P2P: Use freq %d MHz common with the peer",
6114 /* no preference, select some channel */
6115 wpas_p2p_select_go_freq_no_pref(wpa_s
, params
, channels
);
6117 if (params
->freq
== 0) {
6118 wpa_printf(MSG_DEBUG
, "P2P: did not find a freq for GO use");
6131 static struct wpa_supplicant
*
6132 wpas_p2p_get_group_iface(struct wpa_supplicant
*wpa_s
, int addr_allocated
,
6135 struct wpa_supplicant
*group_wpa_s
;
6137 if (!wpas_p2p_create_iface(wpa_s
)) {
6138 if (wpa_s
->p2p_mgmt
) {
6140 * We may be called on the p2p_dev interface which
6141 * cannot be used for group operations, so always use
6142 * the primary interface.
6144 wpa_s
->parent
->p2pdev
= wpa_s
;
6145 wpa_s
= wpa_s
->parent
;
6147 wpa_dbg(wpa_s
, MSG_DEBUG
,
6148 "P2P: Use primary interface for group operations");
6149 wpa_s
->p2p_first_connection_timeout
= 0;
6150 if (wpa_s
!= wpa_s
->p2pdev
)
6151 wpas_p2p_clone_config(wpa_s
, wpa_s
->p2pdev
);
6155 if (wpas_p2p_add_group_interface(wpa_s
, go
? WPA_IF_P2P_GO
:
6156 WPA_IF_P2P_CLIENT
) < 0) {
6157 wpa_msg_global(wpa_s
, MSG_ERROR
,
6158 "P2P: Failed to add group interface");
6161 group_wpa_s
= wpas_p2p_init_group_interface(wpa_s
, go
);
6162 if (group_wpa_s
== NULL
) {
6163 wpa_msg_global(wpa_s
, MSG_ERROR
,
6164 "P2P: Failed to initialize group interface");
6165 wpas_p2p_remove_pending_group_interface(wpa_s
);
6169 if (go
&& wpa_s
->p2p_go_do_acs
) {
6170 group_wpa_s
->p2p_go_do_acs
= wpa_s
->p2p_go_do_acs
;
6171 group_wpa_s
->p2p_go_acs_band
= wpa_s
->p2p_go_acs_band
;
6172 wpa_s
->p2p_go_do_acs
= 0;
6175 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Use separate group interface %s",
6176 group_wpa_s
->ifname
);
6177 group_wpa_s
->p2p_first_connection_timeout
= 0;
6183 * wpas_p2p_group_add - Add a new P2P group with local end as Group Owner
6184 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
6185 * @persistent_group: Whether to create a persistent group
6186 * @freq: Frequency for the group or 0 to indicate no hardcoding
6187 * @vht_center_freq2: segment_1 center frequency for GO operating in VHT 80P80
6188 * @ht40: Start GO with 40 MHz channel width
6189 * @vht: Start GO with VHT support
6190 * @vht_chwidth: channel bandwidth for GO operating with VHT support
6191 * Returns: 0 on success, -1 on failure
6193 * This function creates a new P2P group with the local end as the Group Owner,
6194 * i.e., without using Group Owner Negotiation.
6196 int wpas_p2p_group_add(struct wpa_supplicant
*wpa_s
, int persistent_group
,
6197 int freq
, int vht_center_freq2
, int ht40
, int vht
,
6198 int max_oper_chwidth
)
6200 struct p2p_go_neg_results params
;
6202 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
6205 os_free(wpa_s
->global
->add_psk
);
6206 wpa_s
->global
->add_psk
= NULL
;
6208 /* Make sure we are not running find during connection establishment */
6209 wpa_printf(MSG_DEBUG
, "P2P: Stop any on-going P2P FIND");
6210 wpas_p2p_stop_find_oper(wpa_s
);
6212 if (!wpa_s
->p2p_go_do_acs
) {
6213 freq
= wpas_p2p_select_go_freq(wpa_s
, freq
);
6218 if (wpas_p2p_init_go_params(wpa_s
, ¶ms
, freq
, vht_center_freq2
,
6219 ht40
, vht
, max_oper_chwidth
, NULL
))
6222 p2p_go_params(wpa_s
->global
->p2p
, ¶ms
);
6223 params
.persistent_group
= persistent_group
;
6225 wpa_s
= wpas_p2p_get_group_iface(wpa_s
, 0, 1);
6228 wpas_start_wps_go(wpa_s
, ¶ms
, 0);
6234 static int wpas_start_p2p_client(struct wpa_supplicant
*wpa_s
,
6235 struct wpa_ssid
*params
, int addr_allocated
,
6236 int freq
, int force_scan
)
6238 struct wpa_ssid
*ssid
;
6240 wpa_s
= wpas_p2p_get_group_iface(wpa_s
, addr_allocated
, 0);
6244 os_get_reltime(&wpa_s
->scan_min_time
);
6245 wpa_s
->p2p_last_4way_hs_fail
= NULL
;
6247 wpa_supplicant_ap_deinit(wpa_s
);
6249 ssid
= wpa_config_add_network(wpa_s
->conf
);
6252 os_memset(wpa_s
->go_dev_addr
, 0, ETH_ALEN
);
6253 wpa_config_set_network_defaults(ssid
);
6254 ssid
->temporary
= 1;
6255 ssid
->proto
= WPA_PROTO_RSN
;
6256 ssid
->pbss
= params
->pbss
;
6257 ssid
->pairwise_cipher
= params
->pbss
? WPA_CIPHER_GCMP
:
6259 ssid
->group_cipher
= params
->pbss
? WPA_CIPHER_GCMP
: WPA_CIPHER_CCMP
;
6260 ssid
->key_mgmt
= WPA_KEY_MGMT_PSK
;
6261 ssid
->ssid
= os_malloc(params
->ssid_len
);
6262 if (ssid
->ssid
== NULL
) {
6263 wpa_config_remove_network(wpa_s
->conf
, ssid
->id
);
6266 os_memcpy(ssid
->ssid
, params
->ssid
, params
->ssid_len
);
6267 ssid
->ssid_len
= params
->ssid_len
;
6268 ssid
->p2p_group
= 1;
6269 ssid
->export_keys
= 1;
6270 if (params
->psk_set
) {
6271 os_memcpy(ssid
->psk
, params
->psk
, 32);
6274 if (params
->passphrase
)
6275 ssid
->passphrase
= os_strdup(params
->passphrase
);
6277 wpa_s
->show_group_started
= 1;
6278 wpa_s
->p2p_in_invitation
= 1;
6279 wpa_s
->p2p_invite_go_freq
= freq
;
6280 wpa_s
->p2p_go_group_formation_completed
= 0;
6281 wpa_s
->global
->p2p_group_formation
= wpa_s
;
6283 eloop_cancel_timeout(wpas_p2p_group_formation_timeout
, wpa_s
->p2pdev
,
6285 eloop_register_timeout(P2P_MAX_INITIAL_CONN_WAIT
, 0,
6286 wpas_p2p_group_formation_timeout
,
6287 wpa_s
->p2pdev
, NULL
);
6288 wpa_supplicant_select_network(wpa_s
, ssid
);
6294 int wpas_p2p_group_add_persistent(struct wpa_supplicant
*wpa_s
,
6295 struct wpa_ssid
*ssid
, int addr_allocated
,
6296 int force_freq
, int neg_freq
,
6297 int vht_center_freq2
, int ht40
,
6298 int vht
, int max_oper_chwidth
,
6299 const struct p2p_channels
*channels
,
6300 int connection_timeout
, int force_scan
)
6302 struct p2p_go_neg_results params
;
6305 if (ssid
->disabled
!= 2 || ssid
->ssid
== NULL
)
6308 if (wpas_get_p2p_group(wpa_s
, ssid
->ssid
, ssid
->ssid_len
, &go
) &&
6309 go
== (ssid
->mode
== WPAS_MODE_P2P_GO
)) {
6310 wpa_printf(MSG_DEBUG
, "P2P: Requested persistent group is "
6313 eloop_cancel_timeout(wpas_p2p_group_formation_timeout
,
6314 wpa_s
->p2pdev
, NULL
)) {
6316 * This can happen if Invitation Response frame was lost
6317 * and the peer (GO of a persistent group) tries to
6318 * invite us again. Reschedule the timeout to avoid
6319 * terminating the wait for the connection too early
6320 * since we now know that the peer is still trying to
6321 * invite us instead of having already started the GO.
6323 wpa_printf(MSG_DEBUG
,
6324 "P2P: Reschedule group formation timeout since peer is still trying to invite us");
6325 eloop_register_timeout(P2P_MAX_INITIAL_CONN_WAIT
, 0,
6326 wpas_p2p_group_formation_timeout
,
6327 wpa_s
->p2pdev
, NULL
);
6332 os_free(wpa_s
->global
->add_psk
);
6333 wpa_s
->global
->add_psk
= NULL
;
6335 /* Make sure we are not running find during connection establishment */
6336 wpas_p2p_stop_find_oper(wpa_s
);
6338 wpa_s
->p2p_fallback_to_go_neg
= 0;
6340 if (ssid
->mode
== WPAS_MODE_P2P_GO
) {
6341 if (force_freq
> 0) {
6342 freq
= wpas_p2p_select_go_freq(wpa_s
, force_freq
);
6346 freq
= wpas_p2p_select_go_freq(wpa_s
, neg_freq
);
6348 (freq
> 0 && !freq_included(wpa_s
, channels
, freq
)))
6351 } else if (ssid
->mode
== WPAS_MODE_INFRA
) {
6353 if (freq
<= 0 || !freq_included(wpa_s
, channels
, freq
)) {
6354 struct os_reltime now
;
6355 struct wpa_bss
*bss
=
6356 wpa_bss_get_p2p_dev_addr(wpa_s
, ssid
->bssid
);
6358 os_get_reltime(&now
);
6360 !os_reltime_expired(&now
, &bss
->last_update
, 5) &&
6361 freq_included(wpa_s
, channels
, bss
->freq
))
6367 return wpas_start_p2p_client(wpa_s
, ssid
, addr_allocated
, freq
,
6373 if (wpas_p2p_init_go_params(wpa_s
, ¶ms
, freq
, vht_center_freq2
,
6374 ht40
, vht
, max_oper_chwidth
, channels
))
6378 params
.psk_set
= ssid
->psk_set
;
6380 os_memcpy(params
.psk
, ssid
->psk
, sizeof(params
.psk
));
6381 if (ssid
->passphrase
) {
6382 if (os_strlen(ssid
->passphrase
) >= sizeof(params
.passphrase
)) {
6383 wpa_printf(MSG_ERROR
, "P2P: Invalid passphrase in "
6384 "persistent group");
6387 os_strlcpy(params
.passphrase
, ssid
->passphrase
,
6388 sizeof(params
.passphrase
));
6390 os_memcpy(params
.ssid
, ssid
->ssid
, ssid
->ssid_len
);
6391 params
.ssid_len
= ssid
->ssid_len
;
6392 params
.persistent_group
= 1;
6394 wpa_s
= wpas_p2p_get_group_iface(wpa_s
, addr_allocated
, 1);
6398 p2p_channels_to_freqs(channels
, params
.freq_list
, P2P_MAX_CHANNELS
);
6400 wpa_s
->p2p_first_connection_timeout
= connection_timeout
;
6401 wpas_start_wps_go(wpa_s
, ¶ms
, 0);
6407 static void wpas_p2p_ie_update(void *ctx
, struct wpabuf
*beacon_ies
,
6408 struct wpabuf
*proberesp_ies
)
6410 struct wpa_supplicant
*wpa_s
= ctx
;
6411 if (wpa_s
->ap_iface
) {
6412 struct hostapd_data
*hapd
= wpa_s
->ap_iface
->bss
[0];
6413 if (!(hapd
->conf
->p2p
& P2P_GROUP_OWNER
)) {
6414 wpabuf_free(beacon_ies
);
6415 wpabuf_free(proberesp_ies
);
6419 wpabuf_free(hapd
->p2p_beacon_ie
);
6420 hapd
->p2p_beacon_ie
= beacon_ies
;
6422 wpabuf_free(hapd
->p2p_probe_resp_ie
);
6423 hapd
->p2p_probe_resp_ie
= proberesp_ies
;
6425 wpabuf_free(beacon_ies
);
6426 wpabuf_free(proberesp_ies
);
6428 wpa_supplicant_ap_update_beacon(wpa_s
);
6432 static void wpas_p2p_idle_update(void *ctx
, int idle
)
6434 struct wpa_supplicant
*wpa_s
= ctx
;
6435 if (!wpa_s
->ap_iface
)
6437 wpa_printf(MSG_DEBUG
, "P2P: GO - group %sidle", idle
? "" : "not ");
6439 if (wpa_s
->global
->p2p_fail_on_wps_complete
&&
6440 wpa_s
->p2p_in_provisioning
) {
6441 wpas_p2p_grpform_fail_after_wps(wpa_s
);
6444 wpas_p2p_set_group_idle_timeout(wpa_s
);
6446 eloop_cancel_timeout(wpas_p2p_group_idle_timeout
, wpa_s
, NULL
);
6450 struct p2p_group
* wpas_p2p_group_init(struct wpa_supplicant
*wpa_s
,
6451 struct wpa_ssid
*ssid
)
6453 struct p2p_group
*group
;
6454 struct p2p_group_config
*cfg
;
6456 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
||
6460 cfg
= os_zalloc(sizeof(*cfg
));
6464 if (ssid
->p2p_persistent_group
&& wpa_s
->conf
->persistent_reconnect
)
6465 cfg
->persistent_group
= 2;
6466 else if (ssid
->p2p_persistent_group
)
6467 cfg
->persistent_group
= 1;
6468 os_memcpy(cfg
->interface_addr
, wpa_s
->own_addr
, ETH_ALEN
);
6469 if (wpa_s
->max_stations
&&
6470 wpa_s
->max_stations
< wpa_s
->conf
->max_num_sta
)
6471 cfg
->max_clients
= wpa_s
->max_stations
;
6473 cfg
->max_clients
= wpa_s
->conf
->max_num_sta
;
6474 os_memcpy(cfg
->ssid
, ssid
->ssid
, ssid
->ssid_len
);
6475 cfg
->ssid_len
= ssid
->ssid_len
;
6476 cfg
->freq
= ssid
->frequency
;
6477 cfg
->cb_ctx
= wpa_s
;
6478 cfg
->ie_update
= wpas_p2p_ie_update
;
6479 cfg
->idle_update
= wpas_p2p_idle_update
;
6480 cfg
->ip_addr_alloc
= WPA_GET_BE32(wpa_s
->p2pdev
->conf
->ip_addr_start
)
6483 group
= p2p_group_init(wpa_s
->global
->p2p
, cfg
);
6486 if (ssid
->mode
!= WPAS_MODE_P2P_GROUP_FORMATION
)
6487 p2p_group_notif_formation_done(group
);
6488 wpa_s
->p2p_group
= group
;
6493 void wpas_p2p_wps_success(struct wpa_supplicant
*wpa_s
, const u8
*peer_addr
,
6496 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
6498 if (!wpa_s
->p2p_in_provisioning
) {
6499 wpa_printf(MSG_DEBUG
, "P2P: Ignore WPS success event - P2P "
6500 "provisioning not in progress");
6504 if (ssid
&& ssid
->mode
== WPAS_MODE_INFRA
) {
6505 u8 go_dev_addr
[ETH_ALEN
];
6506 os_memcpy(go_dev_addr
, wpa_s
->bssid
, ETH_ALEN
);
6507 wpas_p2p_persistent_group(wpa_s
, go_dev_addr
, ssid
->ssid
,
6509 /* Clear any stored provisioning info */
6510 p2p_clear_provisioning_info(wpa_s
->global
->p2p
, go_dev_addr
);
6513 eloop_cancel_timeout(wpas_p2p_group_formation_timeout
, wpa_s
->p2pdev
,
6515 wpa_s
->p2p_go_group_formation_completed
= 1;
6516 if (ssid
&& ssid
->mode
== WPAS_MODE_INFRA
) {
6518 * Use a separate timeout for initial data connection to
6519 * complete to allow the group to be removed automatically if
6520 * something goes wrong in this step before the P2P group idle
6521 * timeout mechanism is taken into use.
6523 wpa_dbg(wpa_s
, MSG_DEBUG
,
6524 "P2P: Re-start group formation timeout (%d seconds) as client for initial connection",
6525 P2P_MAX_INITIAL_CONN_WAIT
);
6526 eloop_register_timeout(P2P_MAX_INITIAL_CONN_WAIT
, 0,
6527 wpas_p2p_group_formation_timeout
,
6528 wpa_s
->p2pdev
, NULL
);
6529 /* Complete group formation on successful data connection. */
6530 wpa_s
->p2p_go_group_formation_completed
= 0;
6533 * Use a separate timeout for initial data connection to
6534 * complete to allow the group to be removed automatically if
6535 * the client does not complete data connection successfully.
6537 wpa_dbg(wpa_s
, MSG_DEBUG
,
6538 "P2P: Re-start group formation timeout (%d seconds) as GO for initial connection",
6539 P2P_MAX_INITIAL_CONN_WAIT_GO
);
6540 eloop_register_timeout(P2P_MAX_INITIAL_CONN_WAIT_GO
, 0,
6541 wpas_p2p_group_formation_timeout
,
6542 wpa_s
->p2pdev
, NULL
);
6544 * Complete group formation on first successful data connection
6546 wpa_s
->p2p_go_group_formation_completed
= 0;
6548 if (wpa_s
->global
->p2p
)
6549 p2p_wps_success_cb(wpa_s
->global
->p2p
, peer_addr
);
6550 wpas_group_formation_completed(wpa_s
, 1, 0);
6554 void wpas_p2p_wps_failed(struct wpa_supplicant
*wpa_s
,
6555 struct wps_event_fail
*fail
)
6557 if (!wpa_s
->p2p_in_provisioning
) {
6558 wpa_printf(MSG_DEBUG
, "P2P: Ignore WPS fail event - P2P "
6559 "provisioning not in progress");
6563 if (wpa_s
->go_params
) {
6564 p2p_clear_provisioning_info(
6566 wpa_s
->go_params
->peer_device_addr
);
6569 wpas_notify_p2p_wps_failed(wpa_s
, fail
);
6571 if (wpa_s
== wpa_s
->global
->p2p_group_formation
) {
6573 * Allow some time for the failed WPS negotiation exchange to
6574 * complete, but remove the group since group formation cannot
6575 * succeed after provisioning failure.
6577 wpa_printf(MSG_DEBUG
, "P2P: WPS step failed during group formation - reject connection from timeout");
6578 wpa_s
->global
->p2p_fail_on_wps_complete
= 1;
6579 eloop_deplete_timeout(0, 50000,
6580 wpas_p2p_group_formation_timeout
,
6581 wpa_s
->p2pdev
, NULL
);
6586 int wpas_p2p_wps_eapol_cb(struct wpa_supplicant
*wpa_s
)
6588 if (!wpa_s
->global
->p2p_fail_on_wps_complete
||
6589 !wpa_s
->p2p_in_provisioning
)
6592 wpas_p2p_grpform_fail_after_wps(wpa_s
);
6598 int wpas_p2p_prov_disc(struct wpa_supplicant
*wpa_s
, const u8
*peer_addr
,
6599 const char *config_method
,
6600 enum wpas_p2p_prov_disc_use use
,
6601 struct p2ps_provision
*p2ps_prov
)
6605 wpa_s
->global
->pending_p2ps_group
= 0;
6606 wpa_s
->global
->pending_p2ps_group_freq
= 0;
6607 wpa_s
->p2p_fallback_to_go_neg
= 0;
6608 wpa_s
->pending_pd_use
= NORMAL_PD
;
6609 if (p2ps_prov
&& use
== WPAS_P2P_PD_FOR_ASP
) {
6610 p2ps_prov
->conncap
= p2ps_group_capability(
6611 wpa_s
, P2PS_SETUP_NONE
, p2ps_prov
->role
,
6612 &p2ps_prov
->force_freq
, &p2ps_prov
->pref_freq
);
6614 wpa_printf(MSG_DEBUG
,
6615 "P2P: %s conncap: %d - ASP parsed: %x %x %d %s",
6616 __func__
, p2ps_prov
->conncap
,
6617 p2ps_prov
->adv_id
, p2ps_prov
->conncap
,
6618 p2ps_prov
->status
, p2ps_prov
->info
);
6621 } else if (os_strncmp(config_method
, "display", 7) == 0)
6622 config_methods
= WPS_CONFIG_DISPLAY
;
6623 else if (os_strncmp(config_method
, "keypad", 6) == 0)
6624 config_methods
= WPS_CONFIG_KEYPAD
;
6625 else if (os_strncmp(config_method
, "pbc", 3) == 0 ||
6626 os_strncmp(config_method
, "pushbutton", 10) == 0)
6627 config_methods
= WPS_CONFIG_PUSHBUTTON
;
6629 wpa_printf(MSG_DEBUG
, "P2P: Unknown config method");
6634 if (use
== WPAS_P2P_PD_AUTO
) {
6635 os_memcpy(wpa_s
->pending_join_dev_addr
, peer_addr
, ETH_ALEN
);
6636 wpa_s
->pending_pd_config_methods
= config_methods
;
6637 wpa_s
->p2p_auto_pd
= 1;
6638 wpa_s
->p2p_auto_join
= 0;
6639 wpa_s
->pending_pd_before_join
= 0;
6640 wpa_s
->auto_pd_scan_retry
= 0;
6641 wpas_p2p_stop_find(wpa_s
);
6642 wpa_s
->p2p_join_scan_count
= 0;
6643 os_get_reltime(&wpa_s
->p2p_auto_started
);
6644 wpa_printf(MSG_DEBUG
, "P2P: Auto PD started at %ld.%06ld",
6645 wpa_s
->p2p_auto_started
.sec
,
6646 wpa_s
->p2p_auto_started
.usec
);
6647 wpas_p2p_join_scan(wpa_s
, NULL
);
6651 if (wpa_s
->global
->p2p
== NULL
|| wpa_s
->global
->p2p_disabled
) {
6656 return p2p_prov_disc_req(wpa_s
->global
->p2p
, peer_addr
, p2ps_prov
,
6657 config_methods
, use
== WPAS_P2P_PD_FOR_JOIN
,
6662 int wpas_p2p_scan_result_text(const u8
*ies
, size_t ies_len
, char *buf
,
6665 return p2p_scan_result_text(ies
, ies_len
, buf
, end
);
6669 static void wpas_p2p_clear_pending_action_tx(struct wpa_supplicant
*wpa_s
)
6671 if (!offchannel_pending_action_tx(wpa_s
))
6674 if (wpa_s
->p2p_send_action_work
) {
6675 wpas_p2p_free_send_action_work(wpa_s
);
6676 eloop_cancel_timeout(wpas_p2p_send_action_work_timeout
,
6678 offchannel_send_action_done(wpa_s
);
6681 wpa_printf(MSG_DEBUG
, "P2P: Drop pending Action TX due to new "
6682 "operation request");
6683 offchannel_clear_pending_action_tx(wpa_s
);
6687 int wpas_p2p_find(struct wpa_supplicant
*wpa_s
, unsigned int timeout
,
6688 enum p2p_discovery_type type
,
6689 unsigned int num_req_dev_types
, const u8
*req_dev_types
,
6690 const u8
*dev_id
, unsigned int search_delay
,
6691 u8 seek_cnt
, const char **seek_string
, int freq
)
6693 wpas_p2p_clear_pending_action_tx(wpa_s
);
6694 wpa_s
->p2p_long_listen
= 0;
6696 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
||
6697 wpa_s
->p2p_in_provisioning
) {
6698 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Reject p2p_find operation%s%s",
6699 (wpa_s
->global
->p2p_disabled
|| !wpa_s
->global
->p2p
) ?
6700 " (P2P disabled)" : "",
6701 wpa_s
->p2p_in_provisioning
?
6702 " (p2p_in_provisioning)" : "");
6706 wpa_supplicant_cancel_sched_scan(wpa_s
);
6708 return p2p_find(wpa_s
->global
->p2p
, timeout
, type
,
6709 num_req_dev_types
, req_dev_types
, dev_id
,
6710 search_delay
, seek_cnt
, seek_string
, freq
);
6714 static void wpas_p2p_scan_res_ignore_search(struct wpa_supplicant
*wpa_s
,
6715 struct wpa_scan_results
*scan_res
)
6717 wpa_printf(MSG_DEBUG
, "P2P: Ignore scan results");
6719 if (wpa_s
->p2p_scan_work
) {
6720 struct wpa_radio_work
*work
= wpa_s
->p2p_scan_work
;
6721 wpa_s
->p2p_scan_work
= NULL
;
6722 radio_work_done(work
);
6725 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
6729 * Indicate that results have been processed so that the P2P module can
6730 * continue pending tasks.
6732 p2p_scan_res_handled(wpa_s
->global
->p2p
);
6736 static void wpas_p2p_stop_find_oper(struct wpa_supplicant
*wpa_s
)
6738 wpas_p2p_clear_pending_action_tx(wpa_s
);
6739 wpa_s
->p2p_long_listen
= 0;
6740 eloop_cancel_timeout(wpas_p2p_long_listen_timeout
, wpa_s
, NULL
);
6741 eloop_cancel_timeout(wpas_p2p_join_scan
, wpa_s
, NULL
);
6743 if (wpa_s
->global
->p2p
)
6744 p2p_stop_find(wpa_s
->global
->p2p
);
6746 if (wpa_s
->scan_res_handler
== wpas_p2p_scan_res_handler
) {
6747 wpa_printf(MSG_DEBUG
,
6748 "P2P: Do not consider the scan results after stop_find");
6749 wpa_s
->scan_res_handler
= wpas_p2p_scan_res_ignore_search
;
6754 void wpas_p2p_stop_find(struct wpa_supplicant
*wpa_s
)
6756 wpas_p2p_stop_find_oper(wpa_s
);
6757 if (!wpa_s
->global
->pending_group_iface_for_p2ps
)
6758 wpas_p2p_remove_pending_group_interface(wpa_s
);
6762 static void wpas_p2p_long_listen_timeout(void *eloop_ctx
, void *timeout_ctx
)
6764 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
6765 wpa_s
->p2p_long_listen
= 0;
6769 int wpas_p2p_listen(struct wpa_supplicant
*wpa_s
, unsigned int timeout
)
6773 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
6776 if (wpa_s
->p2p_lo_started
) {
6777 wpa_printf(MSG_DEBUG
,
6778 "P2P: Cannot start P2P listen, it is offloaded");
6782 wpa_supplicant_cancel_sched_scan(wpa_s
);
6783 wpas_p2p_clear_pending_action_tx(wpa_s
);
6787 * This is a request for unlimited Listen state. However, at
6788 * least for now, this is mapped to a Listen state for one
6793 eloop_cancel_timeout(wpas_p2p_long_listen_timeout
, wpa_s
, NULL
);
6794 wpa_s
->p2p_long_listen
= 0;
6797 * Stop previous find/listen operation to avoid trying to request a new
6798 * remain-on-channel operation while the driver is still running the
6801 if (wpa_s
->global
->p2p
)
6802 p2p_stop_find(wpa_s
->global
->p2p
);
6804 res
= wpas_p2p_listen_start(wpa_s
, timeout
* 1000);
6805 if (res
== 0 && timeout
* 1000 > wpa_s
->max_remain_on_chan
) {
6806 wpa_s
->p2p_long_listen
= timeout
* 1000;
6807 eloop_register_timeout(timeout
, 0,
6808 wpas_p2p_long_listen_timeout
,
6816 int wpas_p2p_assoc_req_ie(struct wpa_supplicant
*wpa_s
, struct wpa_bss
*bss
,
6817 u8
*buf
, size_t len
, int p2p_group
)
6819 struct wpabuf
*p2p_ie
;
6822 if (wpa_s
->global
->p2p_disabled
)
6825 * Advertize mandatory cross connection capability even on
6826 * p2p_disabled=1 interface when associating with a P2P Manager WLAN AP.
6828 if (wpa_s
->conf
->p2p_disabled
&& p2p_group
)
6830 if (wpa_s
->global
->p2p
== NULL
)
6835 p2p_ie
= wpa_bss_get_vendor_ie_multi(bss
, P2P_IE_VENDOR_TYPE
);
6836 ret
= p2p_assoc_req_ie(wpa_s
->global
->p2p
, bss
->bssid
, buf
, len
,
6838 wpabuf_free(p2p_ie
);
6844 int wpas_p2p_probe_req_rx(struct wpa_supplicant
*wpa_s
, const u8
*addr
,
6845 const u8
*dst
, const u8
*bssid
,
6846 const u8
*ie
, size_t ie_len
,
6847 unsigned int rx_freq
, int ssi_signal
)
6849 if (wpa_s
->global
->p2p_disabled
)
6851 if (wpa_s
->global
->p2p
== NULL
)
6854 switch (p2p_probe_req_rx(wpa_s
->global
->p2p
, addr
, dst
, bssid
,
6855 ie
, ie_len
, rx_freq
, wpa_s
->p2p_lo_started
)) {
6856 case P2P_PREQ_NOT_P2P
:
6857 wpas_notify_preq(wpa_s
, addr
, dst
, bssid
, ie
, ie_len
,
6860 case P2P_PREQ_MALFORMED
:
6861 case P2P_PREQ_NOT_LISTEN
:
6862 case P2P_PREQ_NOT_PROCESSED
:
6863 default: /* make gcc happy */
6865 case P2P_PREQ_PROCESSED
:
6871 void wpas_p2p_rx_action(struct wpa_supplicant
*wpa_s
, const u8
*da
,
6872 const u8
*sa
, const u8
*bssid
,
6873 u8 category
, const u8
*data
, size_t len
, int freq
)
6875 if (wpa_s
->global
->p2p_disabled
)
6877 if (wpa_s
->global
->p2p
== NULL
)
6880 p2p_rx_action(wpa_s
->global
->p2p
, da
, sa
, bssid
, category
, data
, len
,
6885 void wpas_p2p_scan_ie(struct wpa_supplicant
*wpa_s
, struct wpabuf
*ies
)
6889 if (wpa_s
->global
->p2p_disabled
)
6891 if (wpa_s
->global
->p2p
== NULL
)
6894 bands
= wpas_get_bands(wpa_s
, NULL
);
6895 p2p_scan_ie(wpa_s
->global
->p2p
, ies
, NULL
, bands
);
6899 static void wpas_p2p_group_deinit(struct wpa_supplicant
*wpa_s
)
6901 p2p_group_deinit(wpa_s
->p2p_group
);
6902 wpa_s
->p2p_group
= NULL
;
6904 wpa_s
->ap_configured_cb
= NULL
;
6905 wpa_s
->ap_configured_cb_ctx
= NULL
;
6906 wpa_s
->ap_configured_cb_data
= NULL
;
6907 wpa_s
->connect_without_scan
= NULL
;
6911 int wpas_p2p_reject(struct wpa_supplicant
*wpa_s
, const u8
*addr
)
6913 wpa_s
->p2p_long_listen
= 0;
6915 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
6918 return p2p_reject(wpa_s
->global
->p2p
, addr
);
6922 /* Invite to reinvoke a persistent group */
6923 int wpas_p2p_invite(struct wpa_supplicant
*wpa_s
, const u8
*peer_addr
,
6924 struct wpa_ssid
*ssid
, const u8
*go_dev_addr
, int freq
,
6925 int vht_center_freq2
, int ht40
, int vht
, int max_chwidth
,
6928 enum p2p_invite_role role
;
6932 int no_pref_freq_given
= pref_freq
== 0;
6933 unsigned int pref_freq_list
[P2P_MAX_PREF_CHANNELS
], size
;
6935 wpa_s
->global
->p2p_invite_group
= NULL
;
6937 os_memcpy(wpa_s
->p2p_auth_invite
, peer_addr
, ETH_ALEN
);
6939 os_memset(wpa_s
->p2p_auth_invite
, 0, ETH_ALEN
);
6941 wpa_s
->p2p_persistent_go_freq
= freq
;
6942 wpa_s
->p2p_go_ht40
= !!ht40
;
6943 wpa_s
->p2p_go_vht
= !!vht
;
6944 wpa_s
->p2p_go_max_oper_chwidth
= max_chwidth
;
6945 wpa_s
->p2p_go_vht_center_freq2
= vht_center_freq2
;
6946 if (ssid
->mode
== WPAS_MODE_P2P_GO
) {
6947 role
= P2P_INVITE_ROLE_GO
;
6948 if (peer_addr
== NULL
) {
6949 wpa_printf(MSG_DEBUG
, "P2P: Missing peer "
6950 "address in invitation command");
6953 if (wpas_p2p_create_iface(wpa_s
)) {
6954 if (wpas_p2p_add_group_interface(wpa_s
,
6955 WPA_IF_P2P_GO
) < 0) {
6956 wpa_printf(MSG_ERROR
, "P2P: Failed to "
6957 "allocate a new interface for the "
6961 bssid
= wpa_s
->pending_interface_addr
;
6962 } else if (wpa_s
->p2p_mgmt
)
6963 bssid
= wpa_s
->parent
->own_addr
;
6965 bssid
= wpa_s
->own_addr
;
6967 role
= P2P_INVITE_ROLE_CLIENT
;
6968 peer_addr
= ssid
->bssid
;
6970 wpa_s
->pending_invite_ssid_id
= ssid
->id
;
6972 size
= P2P_MAX_PREF_CHANNELS
;
6973 res
= wpas_p2p_setup_freqs(wpa_s
, freq
, &force_freq
, &pref_freq
,
6974 role
== P2P_INVITE_ROLE_GO
,
6975 pref_freq_list
, &size
);
6979 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
6982 p2p_set_own_pref_freq_list(wpa_s
->global
->p2p
, pref_freq_list
, size
);
6984 if (wpa_s
->parent
->conf
->p2p_ignore_shared_freq
&&
6985 no_pref_freq_given
&& pref_freq
> 0 &&
6986 wpa_s
->num_multichan_concurrent
> 1 &&
6987 wpas_p2p_num_unused_channels(wpa_s
) > 0) {
6988 wpa_printf(MSG_DEBUG
, "P2P: Ignore own channel preference %d MHz for invitation due to p2p_ignore_shared_freq=1 configuration",
6994 * Stop any find/listen operations before invitation and possibly
6995 * connection establishment.
6997 wpas_p2p_stop_find_oper(wpa_s
);
6999 return p2p_invite(wpa_s
->global
->p2p
, peer_addr
, role
, bssid
,
7000 ssid
->ssid
, ssid
->ssid_len
, force_freq
, go_dev_addr
,
7005 /* Invite to join an active group */
7006 int wpas_p2p_invite_group(struct wpa_supplicant
*wpa_s
, const char *ifname
,
7007 const u8
*peer_addr
, const u8
*go_dev_addr
)
7009 struct wpa_global
*global
= wpa_s
->global
;
7010 enum p2p_invite_role role
;
7012 struct wpa_ssid
*ssid
;
7014 int freq
= 0, force_freq
= 0, pref_freq
= 0;
7016 unsigned int pref_freq_list
[P2P_MAX_PREF_CHANNELS
], size
;
7018 wpa_s
->p2p_persistent_go_freq
= 0;
7019 wpa_s
->p2p_go_ht40
= 0;
7020 wpa_s
->p2p_go_vht
= 0;
7021 wpa_s
->p2p_go_vht_center_freq2
= 0;
7022 wpa_s
->p2p_go_max_oper_chwidth
= 0;
7024 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
7025 if (os_strcmp(wpa_s
->ifname
, ifname
) == 0)
7028 if (wpa_s
== NULL
) {
7029 wpa_printf(MSG_DEBUG
, "P2P: Interface '%s' not found", ifname
);
7033 ssid
= wpa_s
->current_ssid
;
7035 wpa_printf(MSG_DEBUG
, "P2P: No current SSID to use for "
7040 wpa_s
->global
->p2p_invite_group
= wpa_s
;
7041 persistent
= ssid
->p2p_persistent_group
&&
7042 wpas_p2p_get_persistent(wpa_s
->p2pdev
, peer_addr
,
7043 ssid
->ssid
, ssid
->ssid_len
);
7045 if (ssid
->mode
== WPAS_MODE_P2P_GO
) {
7046 role
= P2P_INVITE_ROLE_ACTIVE_GO
;
7047 bssid
= wpa_s
->own_addr
;
7048 if (go_dev_addr
== NULL
)
7049 go_dev_addr
= wpa_s
->global
->p2p_dev_addr
;
7050 freq
= ssid
->frequency
;
7052 role
= P2P_INVITE_ROLE_CLIENT
;
7053 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
) {
7054 wpa_printf(MSG_DEBUG
, "P2P: Not associated - cannot "
7055 "invite to current group");
7058 bssid
= wpa_s
->bssid
;
7059 if (go_dev_addr
== NULL
&&
7060 !is_zero_ether_addr(wpa_s
->go_dev_addr
))
7061 go_dev_addr
= wpa_s
->go_dev_addr
;
7062 freq
= wpa_s
->current_bss
? wpa_s
->current_bss
->freq
:
7063 (int) wpa_s
->assoc_freq
;
7065 wpa_s
->p2pdev
->pending_invite_ssid_id
= -1;
7067 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
7070 size
= P2P_MAX_PREF_CHANNELS
;
7071 res
= wpas_p2p_setup_freqs(wpa_s
, freq
, &force_freq
, &pref_freq
,
7072 role
== P2P_INVITE_ROLE_ACTIVE_GO
,
7073 pref_freq_list
, &size
);
7076 wpas_p2p_set_own_freq_preference(wpa_s
, force_freq
);
7078 return p2p_invite(wpa_s
->global
->p2p
, peer_addr
, role
, bssid
,
7079 ssid
->ssid
, ssid
->ssid_len
, force_freq
,
7080 go_dev_addr
, persistent
, pref_freq
, -1);
7084 void wpas_p2p_completed(struct wpa_supplicant
*wpa_s
)
7086 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
7087 u8 go_dev_addr
[ETH_ALEN
];
7093 if (ssid
== NULL
|| ssid
->mode
!= WPAS_MODE_P2P_GROUP_FORMATION
) {
7094 eloop_cancel_timeout(wpas_p2p_group_formation_timeout
,
7095 wpa_s
->p2pdev
, NULL
);
7098 if (!wpa_s
->show_group_started
|| !ssid
)
7101 wpa_s
->show_group_started
= 0;
7102 if (!wpa_s
->p2p_go_group_formation_completed
&&
7103 wpa_s
->global
->p2p_group_formation
== wpa_s
) {
7104 wpa_dbg(wpa_s
, MSG_DEBUG
,
7105 "P2P: Marking group formation completed on client on data connection");
7106 wpa_s
->p2p_go_group_formation_completed
= 1;
7107 wpa_s
->global
->p2p_group_formation
= NULL
;
7108 wpa_s
->p2p_in_provisioning
= 0;
7109 wpa_s
->p2p_in_invitation
= 0;
7112 os_memset(go_dev_addr
, 0, ETH_ALEN
);
7113 if (ssid
->bssid_set
)
7114 os_memcpy(go_dev_addr
, ssid
->bssid
, ETH_ALEN
);
7115 persistent
= wpas_p2p_persistent_group(wpa_s
, go_dev_addr
, ssid
->ssid
,
7117 os_memcpy(wpa_s
->go_dev_addr
, go_dev_addr
, ETH_ALEN
);
7119 if (wpa_s
->global
->p2p_group_formation
== wpa_s
)
7120 wpa_s
->global
->p2p_group_formation
= NULL
;
7122 freq
= wpa_s
->current_bss
? wpa_s
->current_bss
->freq
:
7123 (int) wpa_s
->assoc_freq
;
7126 if (wpa_sm_get_p2p_ip_addr(wpa_s
->wpa
, ip
) == 0) {
7129 res
= os_snprintf(ip_addr
, sizeof(ip_addr
),
7130 " ip_addr=%u.%u.%u.%u "
7131 "ip_mask=%u.%u.%u.%u go_ip_addr=%u.%u.%u.%u",
7132 ip
[0], ip
[1], ip
[2], ip
[3],
7133 ip
[4], ip
[5], ip
[6], ip
[7],
7134 ip
[8], ip
[9], ip
[10], ip
[11]);
7135 if (os_snprintf_error(sizeof(ip_addr
), res
))
7139 wpas_p2p_group_started(wpa_s
, 0, ssid
, freq
,
7140 ssid
->passphrase
== NULL
&& ssid
->psk_set
?
7142 ssid
->passphrase
, go_dev_addr
, persistent
,
7146 wpas_p2p_store_persistent_group(wpa_s
->p2pdev
,
7149 wpas_notify_p2p_group_started(wpa_s
, ssid
, persistent
, 1, ip
);
7153 int wpas_p2p_presence_req(struct wpa_supplicant
*wpa_s
, u32 duration1
,
7154 u32 interval1
, u32 duration2
, u32 interval2
)
7158 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
7161 if (wpa_s
->wpa_state
< WPA_ASSOCIATED
||
7162 wpa_s
->current_ssid
== NULL
||
7163 wpa_s
->current_ssid
->mode
!= WPAS_MODE_INFRA
)
7166 ret
= p2p_presence_req(wpa_s
->global
->p2p
, wpa_s
->bssid
,
7167 wpa_s
->own_addr
, wpa_s
->assoc_freq
,
7168 duration1
, interval1
, duration2
, interval2
);
7170 wpa_s
->waiting_presence_resp
= 1;
7176 int wpas_p2p_ext_listen(struct wpa_supplicant
*wpa_s
, unsigned int period
,
7177 unsigned int interval
)
7179 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
7182 return p2p_ext_listen(wpa_s
->global
->p2p
, period
, interval
);
7186 static int wpas_p2p_is_client(struct wpa_supplicant
*wpa_s
)
7188 if (wpa_s
->current_ssid
== NULL
) {
7190 * current_ssid can be cleared when P2P client interface gets
7191 * disconnected, so assume this interface was used as P2P
7196 return wpa_s
->current_ssid
->p2p_group
&&
7197 wpa_s
->current_ssid
->mode
== WPAS_MODE_INFRA
;
7201 static void wpas_p2p_group_idle_timeout(void *eloop_ctx
, void *timeout_ctx
)
7203 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
7205 if (wpa_s
->conf
->p2p_group_idle
== 0 && !wpas_p2p_is_client(wpa_s
)) {
7206 wpa_printf(MSG_DEBUG
, "P2P: Ignore group idle timeout - "
7211 wpa_printf(MSG_DEBUG
, "P2P: Group idle timeout reached - terminate "
7213 wpas_p2p_group_delete(wpa_s
, P2P_GROUP_REMOVAL_IDLE_TIMEOUT
);
7217 static void wpas_p2p_set_group_idle_timeout(struct wpa_supplicant
*wpa_s
)
7221 if (eloop_cancel_timeout(wpas_p2p_group_idle_timeout
, wpa_s
, NULL
) > 0)
7222 wpa_printf(MSG_DEBUG
, "P2P: Cancelled P2P group idle timeout");
7224 if (wpa_s
->current_ssid
== NULL
|| !wpa_s
->current_ssid
->p2p_group
)
7227 timeout
= wpa_s
->conf
->p2p_group_idle
;
7228 if (wpa_s
->current_ssid
->mode
== WPAS_MODE_INFRA
&&
7229 (timeout
== 0 || timeout
> P2P_MAX_CLIENT_IDLE
))
7230 timeout
= P2P_MAX_CLIENT_IDLE
;
7236 if (wpa_s
->current_ssid
->mode
== WPAS_MODE_INFRA
)
7237 timeout
= 0; /* special client mode no-timeout */
7242 if (wpa_s
->p2p_in_provisioning
) {
7244 * Use the normal group formation timeout during the
7245 * provisioning phase to avoid terminating this process too
7246 * early due to group idle timeout.
7248 wpa_printf(MSG_DEBUG
, "P2P: Do not use P2P group idle timeout "
7249 "during provisioning");
7253 if (wpa_s
->show_group_started
) {
7255 * Use the normal group formation timeout between the end of
7256 * the provisioning phase and completion of 4-way handshake to
7257 * avoid terminating this process too early due to group idle
7260 wpa_printf(MSG_DEBUG
, "P2P: Do not use P2P group idle timeout "
7261 "while waiting for initial 4-way handshake to "
7266 wpa_printf(MSG_DEBUG
, "P2P: Set P2P group idle timeout to %u seconds",
7268 eloop_register_timeout(timeout
, 0, wpas_p2p_group_idle_timeout
,
7273 /* Returns 1 if the interface was removed */
7274 int wpas_p2p_deauth_notif(struct wpa_supplicant
*wpa_s
, const u8
*bssid
,
7275 u16 reason_code
, const u8
*ie
, size_t ie_len
,
7276 int locally_generated
)
7278 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
7281 if (!locally_generated
)
7282 p2p_deauth_notif(wpa_s
->global
->p2p
, bssid
, reason_code
, ie
,
7285 if (reason_code
== WLAN_REASON_DEAUTH_LEAVING
&& !locally_generated
&&
7286 wpa_s
->current_ssid
&&
7287 wpa_s
->current_ssid
->p2p_group
&&
7288 wpa_s
->current_ssid
->mode
== WPAS_MODE_INFRA
) {
7289 wpa_printf(MSG_DEBUG
, "P2P: GO indicated that the P2P Group "
7290 "session is ending");
7291 if (wpas_p2p_group_delete(wpa_s
,
7292 P2P_GROUP_REMOVAL_GO_ENDING_SESSION
)
7301 void wpas_p2p_disassoc_notif(struct wpa_supplicant
*wpa_s
, const u8
*bssid
,
7302 u16 reason_code
, const u8
*ie
, size_t ie_len
,
7303 int locally_generated
)
7305 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
7308 if (!locally_generated
)
7309 p2p_disassoc_notif(wpa_s
->global
->p2p
, bssid
, reason_code
, ie
,
7314 void wpas_p2p_update_config(struct wpa_supplicant
*wpa_s
)
7316 struct p2p_data
*p2p
= wpa_s
->global
->p2p
;
7321 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_CAPABLE
))
7324 if (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_DEVICE_NAME
)
7325 p2p_set_dev_name(p2p
, wpa_s
->conf
->device_name
);
7327 if (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_DEVICE_TYPE
)
7328 p2p_set_pri_dev_type(p2p
, wpa_s
->conf
->device_type
);
7331 (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_CONFIG_METHODS
))
7332 p2p_set_config_methods(p2p
, wpa_s
->wps
->config_methods
);
7334 if (wpa_s
->wps
&& (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_UUID
))
7335 p2p_set_uuid(p2p
, wpa_s
->wps
->uuid
);
7337 if (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_WPS_STRING
) {
7338 p2p_set_manufacturer(p2p
, wpa_s
->conf
->manufacturer
);
7339 p2p_set_model_name(p2p
, wpa_s
->conf
->model_name
);
7340 p2p_set_model_number(p2p
, wpa_s
->conf
->model_number
);
7341 p2p_set_serial_number(p2p
, wpa_s
->conf
->serial_number
);
7344 if (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_SEC_DEVICE_TYPE
)
7345 p2p_set_sec_dev_types(p2p
,
7346 (void *) wpa_s
->conf
->sec_device_type
,
7347 wpa_s
->conf
->num_sec_device_types
);
7349 if (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_VENDOR_EXTENSION
) {
7351 p2p_remove_wps_vendor_extensions(p2p
);
7352 for (i
= 0; i
< MAX_WPS_VENDOR_EXT
; i
++) {
7353 if (wpa_s
->conf
->wps_vendor_ext
[i
] == NULL
)
7355 p2p_add_wps_vendor_extension(
7356 p2p
, wpa_s
->conf
->wps_vendor_ext
[i
]);
7360 if ((wpa_s
->conf
->changed_parameters
& CFG_CHANGED_COUNTRY
) &&
7361 wpa_s
->conf
->country
[0] && wpa_s
->conf
->country
[1]) {
7363 country
[0] = wpa_s
->conf
->country
[0];
7364 country
[1] = wpa_s
->conf
->country
[1];
7366 p2p_set_country(p2p
, country
);
7369 if (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_P2P_SSID_POSTFIX
) {
7370 p2p_set_ssid_postfix(p2p
, (u8
*) wpa_s
->conf
->p2p_ssid_postfix
,
7371 wpa_s
->conf
->p2p_ssid_postfix
?
7372 os_strlen(wpa_s
->conf
->p2p_ssid_postfix
) :
7376 if (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_P2P_INTRA_BSS
)
7377 p2p_set_intra_bss_dist(p2p
, wpa_s
->conf
->p2p_intra_bss
);
7379 if (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_P2P_LISTEN_CHANNEL
) {
7380 u8 reg_class
, channel
;
7385 if (wpa_s
->conf
->p2p_listen_reg_class
&&
7386 wpa_s
->conf
->p2p_listen_channel
) {
7387 reg_class
= wpa_s
->conf
->p2p_listen_reg_class
;
7388 channel
= wpa_s
->conf
->p2p_listen_channel
;
7393 * Pick one of the social channels randomly as the
7396 if (os_get_random((u8
*) &r
, sizeof(r
)) < 0)
7399 channel
= 1 + (r
% 3) * 5;
7402 ret
= p2p_set_listen_channel(p2p
, reg_class
, channel
,
7405 wpa_printf(MSG_ERROR
, "P2P: Own listen channel update "
7408 if (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_P2P_OPER_CHANNEL
) {
7409 u8 op_reg_class
, op_channel
, cfg_op_channel
;
7412 if (wpa_s
->conf
->p2p_oper_reg_class
&&
7413 wpa_s
->conf
->p2p_oper_channel
) {
7414 op_reg_class
= wpa_s
->conf
->p2p_oper_reg_class
;
7415 op_channel
= wpa_s
->conf
->p2p_oper_channel
;
7420 * Use random operation channel from (1, 6, 11)
7421 *if no other preference is indicated.
7423 if (os_get_random((u8
*) &r
, sizeof(r
)) < 0)
7426 op_channel
= 1 + (r
% 3) * 5;
7429 ret
= p2p_set_oper_channel(p2p
, op_reg_class
, op_channel
,
7432 wpa_printf(MSG_ERROR
, "P2P: Own oper channel update "
7436 if (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_P2P_PREF_CHAN
) {
7437 if (p2p_set_pref_chan(p2p
, wpa_s
->conf
->num_p2p_pref_chan
,
7438 wpa_s
->conf
->p2p_pref_chan
) < 0) {
7439 wpa_printf(MSG_ERROR
, "P2P: Preferred channel list "
7443 if (p2p_set_no_go_freq(p2p
, &wpa_s
->conf
->p2p_no_go_freq
) < 0) {
7444 wpa_printf(MSG_ERROR
, "P2P: No GO channel list "
7449 if (wpa_s
->conf
->changed_parameters
& CFG_CHANGED_P2P_PASSPHRASE_LEN
)
7450 p2p_set_passphrase_len(p2p
, wpa_s
->conf
->p2p_passphrase_len
);
7454 int wpas_p2p_set_noa(struct wpa_supplicant
*wpa_s
, u8 count
, int start
,
7457 if (!wpa_s
->ap_iface
)
7459 return hostapd_p2p_set_noa(wpa_s
->ap_iface
->bss
[0], count
, start
,
7464 int wpas_p2p_set_cross_connect(struct wpa_supplicant
*wpa_s
, int enabled
)
7466 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
7469 wpa_s
->global
->cross_connection
= enabled
;
7470 p2p_set_cross_connect(wpa_s
->global
->p2p
, enabled
);
7473 struct wpa_supplicant
*iface
;
7475 for (iface
= wpa_s
->global
->ifaces
; iface
; iface
= iface
->next
)
7477 if (iface
->cross_connect_enabled
== 0)
7480 iface
->cross_connect_enabled
= 0;
7481 iface
->cross_connect_in_use
= 0;
7482 wpa_msg_global(iface
->p2pdev
, MSG_INFO
,
7483 P2P_EVENT_CROSS_CONNECT_DISABLE
"%s %s",
7485 iface
->cross_connect_uplink
);
7493 static void wpas_p2p_enable_cross_connect(struct wpa_supplicant
*uplink
)
7495 struct wpa_supplicant
*iface
;
7497 if (!uplink
->global
->cross_connection
)
7500 for (iface
= uplink
->global
->ifaces
; iface
; iface
= iface
->next
) {
7501 if (!iface
->cross_connect_enabled
)
7503 if (os_strcmp(uplink
->ifname
, iface
->cross_connect_uplink
) !=
7506 if (iface
->ap_iface
== NULL
)
7508 if (iface
->cross_connect_in_use
)
7511 iface
->cross_connect_in_use
= 1;
7512 wpa_msg_global(iface
->p2pdev
, MSG_INFO
,
7513 P2P_EVENT_CROSS_CONNECT_ENABLE
"%s %s",
7514 iface
->ifname
, iface
->cross_connect_uplink
);
7519 static void wpas_p2p_disable_cross_connect(struct wpa_supplicant
*uplink
)
7521 struct wpa_supplicant
*iface
;
7523 for (iface
= uplink
->global
->ifaces
; iface
; iface
= iface
->next
) {
7524 if (!iface
->cross_connect_enabled
)
7526 if (os_strcmp(uplink
->ifname
, iface
->cross_connect_uplink
) !=
7529 if (!iface
->cross_connect_in_use
)
7532 wpa_msg_global(iface
->p2pdev
, MSG_INFO
,
7533 P2P_EVENT_CROSS_CONNECT_DISABLE
"%s %s",
7534 iface
->ifname
, iface
->cross_connect_uplink
);
7535 iface
->cross_connect_in_use
= 0;
7540 void wpas_p2p_notif_connected(struct wpa_supplicant
*wpa_s
)
7542 if (wpa_s
->ap_iface
|| wpa_s
->current_ssid
== NULL
||
7543 wpa_s
->current_ssid
->mode
!= WPAS_MODE_INFRA
||
7544 wpa_s
->cross_connect_disallowed
)
7545 wpas_p2p_disable_cross_connect(wpa_s
);
7547 wpas_p2p_enable_cross_connect(wpa_s
);
7548 if (!wpa_s
->ap_iface
&&
7549 eloop_cancel_timeout(wpas_p2p_group_idle_timeout
, wpa_s
, NULL
) > 0)
7550 wpa_printf(MSG_DEBUG
, "P2P: Cancelled P2P group idle timeout");
7554 void wpas_p2p_notif_disconnected(struct wpa_supplicant
*wpa_s
)
7556 wpas_p2p_disable_cross_connect(wpa_s
);
7557 if (!wpa_s
->ap_iface
&&
7558 !eloop_is_timeout_registered(wpas_p2p_group_idle_timeout
,
7560 wpas_p2p_set_group_idle_timeout(wpa_s
);
7564 static void wpas_p2p_cross_connect_setup(struct wpa_supplicant
*wpa_s
)
7566 struct wpa_supplicant
*iface
;
7568 if (!wpa_s
->global
->cross_connection
)
7571 for (iface
= wpa_s
->global
->ifaces
; iface
; iface
= iface
->next
) {
7574 if (iface
->drv_flags
&
7575 WPA_DRIVER_FLAGS_P2P_DEDICATED_INTERFACE
)
7577 if ((iface
->drv_flags
& WPA_DRIVER_FLAGS_P2P_CAPABLE
) &&
7578 iface
!= wpa_s
->parent
)
7581 wpa_s
->cross_connect_enabled
= 1;
7582 os_strlcpy(wpa_s
->cross_connect_uplink
, iface
->ifname
,
7583 sizeof(wpa_s
->cross_connect_uplink
));
7584 wpa_printf(MSG_DEBUG
, "P2P: Enable cross connection from "
7585 "%s to %s whenever uplink is available",
7586 wpa_s
->ifname
, wpa_s
->cross_connect_uplink
);
7588 if (iface
->ap_iface
|| iface
->current_ssid
== NULL
||
7589 iface
->current_ssid
->mode
!= WPAS_MODE_INFRA
||
7590 iface
->cross_connect_disallowed
||
7591 iface
->wpa_state
!= WPA_COMPLETED
)
7594 wpa_s
->cross_connect_in_use
= 1;
7595 wpa_msg_global(wpa_s
->p2pdev
, MSG_INFO
,
7596 P2P_EVENT_CROSS_CONNECT_ENABLE
"%s %s",
7597 wpa_s
->ifname
, wpa_s
->cross_connect_uplink
);
7603 int wpas_p2p_notif_pbc_overlap(struct wpa_supplicant
*wpa_s
)
7605 if (wpa_s
->p2p_group_interface
!= P2P_GROUP_INTERFACE_CLIENT
&&
7606 !wpa_s
->p2p_in_provisioning
)
7607 return 0; /* not P2P client operation */
7609 wpa_printf(MSG_DEBUG
, "P2P: Terminate connection due to WPS PBC "
7611 if (wpa_s
!= wpa_s
->p2pdev
)
7612 wpa_msg_ctrl(wpa_s
->p2pdev
, MSG_INFO
, WPS_EVENT_OVERLAP
);
7613 wpas_p2p_group_formation_failed(wpa_s
, 0);
7618 void wpas_p2p_pbc_overlap_cb(void *eloop_ctx
, void *timeout_ctx
)
7620 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
7621 wpas_p2p_notif_pbc_overlap(wpa_s
);
7625 void wpas_p2p_update_channel_list(struct wpa_supplicant
*wpa_s
,
7626 enum wpas_p2p_channel_update_trig trig
)
7628 struct p2p_channels chan
, cli_chan
;
7629 struct wpa_used_freq_data
*freqs
= NULL
;
7630 unsigned int num
= wpa_s
->num_multichan_concurrent
;
7632 if (wpa_s
->global
== NULL
|| wpa_s
->global
->p2p
== NULL
)
7635 freqs
= os_calloc(num
, sizeof(struct wpa_used_freq_data
));
7639 num
= get_shared_radio_freqs_data(wpa_s
, freqs
, num
);
7641 os_memset(&chan
, 0, sizeof(chan
));
7642 os_memset(&cli_chan
, 0, sizeof(cli_chan
));
7643 if (wpas_p2p_setup_channels(wpa_s
, &chan
, &cli_chan
)) {
7644 wpa_printf(MSG_ERROR
, "P2P: Failed to update supported "
7649 p2p_update_channel_list(wpa_s
->global
->p2p
, &chan
, &cli_chan
);
7651 wpas_p2p_optimize_listen_channel(wpa_s
, freqs
, num
);
7654 * The used frequencies map changed, so it is possible that a GO is
7655 * using a channel that is no longer valid for P2P use. It is also
7656 * possible that due to policy consideration, it would be preferable to
7657 * move it to a frequency already used by other station interfaces.
7659 wpas_p2p_consider_moving_gos(wpa_s
, freqs
, num
, trig
);
7665 static void wpas_p2p_scan_res_ignore(struct wpa_supplicant
*wpa_s
,
7666 struct wpa_scan_results
*scan_res
)
7668 wpa_printf(MSG_DEBUG
, "P2P: Ignore scan results");
7672 int wpas_p2p_cancel(struct wpa_supplicant
*wpa_s
)
7674 struct wpa_global
*global
= wpa_s
->global
;
7678 if (global
->p2p
== NULL
)
7681 wpa_printf(MSG_DEBUG
, "P2P: Request to cancel group formation");
7683 if (wpa_s
->pending_interface_name
[0] &&
7684 !is_zero_ether_addr(wpa_s
->pending_interface_addr
))
7687 peer
= p2p_get_go_neg_peer(global
->p2p
);
7689 wpa_printf(MSG_DEBUG
, "P2P: Unauthorize pending GO Neg peer "
7690 MACSTR
, MAC2STR(peer
));
7691 p2p_unauthorize(global
->p2p
, peer
);
7695 if (wpa_s
->scan_res_handler
== wpas_p2p_scan_res_join
) {
7696 wpa_printf(MSG_DEBUG
, "P2P: Stop pending scan for join");
7697 wpa_s
->scan_res_handler
= wpas_p2p_scan_res_ignore
;
7701 if (wpa_s
->pending_pd_before_join
) {
7702 wpa_printf(MSG_DEBUG
, "P2P: Stop pending PD before join");
7703 wpa_s
->pending_pd_before_join
= 0;
7707 wpas_p2p_stop_find(wpa_s
);
7709 for (wpa_s
= global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
7710 if (wpa_s
== global
->p2p_group_formation
&&
7711 (wpa_s
->p2p_in_provisioning
||
7712 wpa_s
->parent
->pending_interface_type
==
7713 WPA_IF_P2P_CLIENT
)) {
7714 wpa_printf(MSG_DEBUG
, "P2P: Interface %s in group "
7715 "formation found - cancelling",
7718 eloop_cancel_timeout(wpas_p2p_group_formation_timeout
,
7719 wpa_s
->p2pdev
, NULL
);
7720 if (wpa_s
->p2p_in_provisioning
) {
7721 wpas_group_formation_completed(wpa_s
, 0, 0);
7724 wpas_p2p_group_delete(wpa_s
,
7725 P2P_GROUP_REMOVAL_REQUESTED
);
7727 } else if (wpa_s
->p2p_in_invitation
) {
7728 wpa_printf(MSG_DEBUG
, "P2P: Interface %s in invitation found - cancelling",
7731 wpas_p2p_group_formation_failed(wpa_s
, 0);
7737 wpa_printf(MSG_DEBUG
, "P2P: No ongoing group formation found");
7745 void wpas_p2p_interface_unavailable(struct wpa_supplicant
*wpa_s
)
7747 if (wpa_s
->current_ssid
== NULL
|| !wpa_s
->current_ssid
->p2p_group
)
7750 wpa_printf(MSG_DEBUG
, "P2P: Remove group due to driver resource not "
7751 "being available anymore");
7752 wpas_p2p_group_delete(wpa_s
, P2P_GROUP_REMOVAL_UNAVAILABLE
);
7756 void wpas_p2p_update_best_channels(struct wpa_supplicant
*wpa_s
,
7757 int freq_24
, int freq_5
, int freq_overall
)
7759 struct p2p_data
*p2p
= wpa_s
->global
->p2p
;
7762 p2p_set_best_channels(p2p
, freq_24
, freq_5
, freq_overall
);
7766 int wpas_p2p_unauthorize(struct wpa_supplicant
*wpa_s
, const char *addr
)
7769 struct p2p_data
*p2p
= wpa_s
->global
->p2p
;
7774 if (hwaddr_aton(addr
, peer
))
7777 return p2p_unauthorize(p2p
, peer
);
7782 * wpas_p2p_disconnect - Disconnect from a P2P Group
7783 * @wpa_s: Pointer to wpa_supplicant data
7784 * Returns: 0 on success, -1 on failure
7786 * This can be used to disconnect from a group in which the local end is a P2P
7787 * Client or to end a P2P Group in case the local end is the Group Owner. If a
7788 * virtual network interface was created for this group, that interface will be
7789 * removed. Otherwise, only the configured P2P group network will be removed
7790 * from the interface.
7792 int wpas_p2p_disconnect(struct wpa_supplicant
*wpa_s
)
7798 return wpas_p2p_group_delete(wpa_s
, P2P_GROUP_REMOVAL_REQUESTED
) < 0 ?
7803 int wpas_p2p_in_progress(struct wpa_supplicant
*wpa_s
)
7807 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
7810 ret
= p2p_in_progress(wpa_s
->global
->p2p
);
7813 * Check whether there is an ongoing WPS provisioning step (or
7814 * other parts of group formation) on another interface since
7815 * p2p_in_progress() does not report this to avoid issues for
7816 * scans during such provisioning step.
7818 if (wpa_s
->global
->p2p_group_formation
&&
7819 wpa_s
->global
->p2p_group_formation
!= wpa_s
) {
7820 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Another interface (%s) "
7821 "in group formation",
7822 wpa_s
->global
->p2p_group_formation
->ifname
);
7827 if (!ret
&& wpa_s
->global
->p2p_go_wait_client
.sec
) {
7828 struct os_reltime now
;
7829 os_get_reltime(&now
);
7830 if (os_reltime_expired(&now
, &wpa_s
->global
->p2p_go_wait_client
,
7831 P2P_MAX_INITIAL_CONN_WAIT_GO
)) {
7832 /* Wait for the first client has expired */
7833 wpa_s
->global
->p2p_go_wait_client
.sec
= 0;
7835 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Waiting for initial client connection during group formation");
7844 void wpas_p2p_network_removed(struct wpa_supplicant
*wpa_s
,
7845 struct wpa_ssid
*ssid
)
7847 if (wpa_s
->p2p_in_provisioning
&& ssid
->p2p_group
&&
7848 eloop_cancel_timeout(wpas_p2p_group_formation_timeout
,
7849 wpa_s
->p2pdev
, NULL
) > 0) {
7851 * Remove the network by scheduling the group formation
7852 * timeout to happen immediately. The teardown code
7853 * needs to be scheduled to run asynch later so that we
7854 * don't delete data from under ourselves unexpectedly.
7855 * Calling wpas_p2p_group_formation_timeout directly
7856 * causes a series of crashes in WPS failure scenarios.
7858 wpa_printf(MSG_DEBUG
, "P2P: Canceled group formation due to "
7859 "P2P group network getting removed");
7860 eloop_register_timeout(0, 0, wpas_p2p_group_formation_timeout
,
7861 wpa_s
->p2pdev
, NULL
);
7866 struct wpa_ssid
* wpas_p2p_get_persistent(struct wpa_supplicant
*wpa_s
,
7867 const u8
*addr
, const u8
*ssid
,
7873 for (s
= wpa_s
->conf
->ssid
; s
; s
= s
->next
) {
7874 if (s
->disabled
!= 2)
7877 (ssid_len
!= s
->ssid_len
||
7878 os_memcmp(ssid
, s
->ssid
, ssid_len
) != 0))
7881 if (s
->mode
== WPAS_MODE_P2P_GO
)
7885 if (os_memcmp(s
->bssid
, addr
, ETH_ALEN
) == 0)
7886 return s
; /* peer is GO in the persistent group */
7887 if (s
->mode
!= WPAS_MODE_P2P_GO
|| s
->p2p_client_list
== NULL
)
7889 for (i
= 0; i
< s
->num_p2p_clients
; i
++) {
7890 if (os_memcmp(s
->p2p_client_list
+ i
* 2 * ETH_ALEN
,
7891 addr
, ETH_ALEN
) == 0)
7892 return s
; /* peer is P2P client in persistent
7901 void wpas_p2p_notify_ap_sta_authorized(struct wpa_supplicant
*wpa_s
,
7904 if (eloop_cancel_timeout(wpas_p2p_group_formation_timeout
,
7905 wpa_s
->p2pdev
, NULL
) > 0) {
7907 * This can happen if WPS provisioning step is not terminated
7908 * cleanly (e.g., P2P Client does not send WSC_Done). Since the
7909 * peer was able to connect, there is no need to time out group
7910 * formation after this, though. In addition, this is used with
7911 * the initial connection wait on the GO as a separate formation
7912 * timeout and as such, expected to be hit after the initial WPS
7913 * provisioning step.
7915 wpa_printf(MSG_DEBUG
, "P2P: Canceled P2P group formation timeout on data connection");
7917 if (!wpa_s
->p2p_go_group_formation_completed
&&
7918 !wpa_s
->group_formation_reported
) {
7920 * GO has not yet notified group formation success since
7921 * the WPS step was not completed cleanly. Do that
7922 * notification now since the P2P Client was able to
7923 * connect and as such, must have received the
7924 * credential from the WPS step.
7926 if (wpa_s
->global
->p2p
)
7927 p2p_wps_success_cb(wpa_s
->global
->p2p
, addr
);
7928 wpas_group_formation_completed(wpa_s
, 1, 0);
7931 if (!wpa_s
->p2p_go_group_formation_completed
) {
7932 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Marking group formation completed on GO on first data connection");
7933 wpa_s
->p2p_go_group_formation_completed
= 1;
7934 wpa_s
->global
->p2p_group_formation
= NULL
;
7935 wpa_s
->p2p_in_provisioning
= 0;
7936 wpa_s
->p2p_in_invitation
= 0;
7938 wpa_s
->global
->p2p_go_wait_client
.sec
= 0;
7941 wpas_p2p_add_persistent_group_client(wpa_s
, addr
);
7945 static int wpas_p2p_fallback_to_go_neg(struct wpa_supplicant
*wpa_s
,
7948 struct wpa_supplicant
*group
= wpa_s
;
7951 if (wpa_s
->global
->p2p_group_formation
)
7952 group
= wpa_s
->global
->p2p_group_formation
;
7953 wpa_s
= wpa_s
->global
->p2p_init_wpa_s
;
7954 offchannel_send_action_done(wpa_s
);
7956 ret
= wpas_p2p_group_delete(group
, P2P_GROUP_REMOVAL_SILENT
);
7957 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Fall back to GO Negotiation");
7958 wpas_p2p_connect(wpa_s
, wpa_s
->pending_join_dev_addr
, wpa_s
->p2p_pin
,
7959 wpa_s
->p2p_wps_method
, wpa_s
->p2p_persistent_group
, 0,
7960 0, 0, wpa_s
->p2p_go_intent
, wpa_s
->p2p_connect_freq
,
7961 wpa_s
->p2p_go_vht_center_freq2
,
7962 wpa_s
->p2p_persistent_id
,
7963 wpa_s
->p2p_pd_before_go_neg
,
7966 wpa_s
->p2p_go_max_oper_chwidth
, NULL
, 0);
7971 int wpas_p2p_scan_no_go_seen(struct wpa_supplicant
*wpa_s
)
7975 if (!wpa_s
->p2p_fallback_to_go_neg
||
7976 wpa_s
->p2p_in_provisioning
<= 5)
7979 if (wpas_p2p_peer_go(wpa_s
, wpa_s
->pending_join_dev_addr
) > 0)
7980 return 0; /* peer operating as a GO */
7982 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: GO not found for p2p_connect-auto - "
7983 "fallback to GO Negotiation");
7984 wpa_msg_global(wpa_s
->p2pdev
, MSG_INFO
, P2P_EVENT_FALLBACK_TO_GO_NEG
7985 "reason=GO-not-found");
7986 res
= wpas_p2p_fallback_to_go_neg(wpa_s
, 1);
7988 return res
== 1 ? 2 : 1;
7992 unsigned int wpas_p2p_search_delay(struct wpa_supplicant
*wpa_s
)
7994 struct wpa_supplicant
*ifs
;
7996 if (wpa_s
->wpa_state
> WPA_SCANNING
) {
7997 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Use %u ms search delay due to "
7998 "concurrent operation",
7999 wpa_s
->conf
->p2p_search_delay
);
8000 return wpa_s
->conf
->p2p_search_delay
;
8003 dl_list_for_each(ifs
, &wpa_s
->radio
->ifaces
, struct wpa_supplicant
,
8005 if (ifs
!= wpa_s
&& ifs
->wpa_state
> WPA_SCANNING
) {
8006 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Use %u ms search "
8007 "delay due to concurrent operation on "
8009 wpa_s
->conf
->p2p_search_delay
,
8011 return wpa_s
->conf
->p2p_search_delay
;
8019 static int wpas_p2p_remove_psk_entry(struct wpa_supplicant
*wpa_s
,
8020 struct wpa_ssid
*s
, const u8
*addr
,
8023 struct psk_list_entry
*psk
, *tmp
;
8026 dl_list_for_each_safe(psk
, tmp
, &s
->psk_list
, struct psk_list_entry
,
8028 if ((iface_addr
&& !psk
->p2p
&&
8029 os_memcmp(addr
, psk
->addr
, ETH_ALEN
) == 0) ||
8030 (!iface_addr
&& psk
->p2p
&&
8031 os_memcmp(addr
, psk
->addr
, ETH_ALEN
) == 0)) {
8032 wpa_dbg(wpa_s
, MSG_DEBUG
,
8033 "P2P: Remove persistent group PSK list entry for "
8035 MAC2STR(psk
->addr
), psk
->p2p
);
8036 dl_list_del(&psk
->list
);
8046 void wpas_p2p_new_psk_cb(struct wpa_supplicant
*wpa_s
, const u8
*mac_addr
,
8047 const u8
*p2p_dev_addr
,
8048 const u8
*psk
, size_t psk_len
)
8050 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
8051 struct wpa_ssid
*persistent
;
8052 struct psk_list_entry
*p
, *last
;
8054 if (psk_len
!= sizeof(p
->psk
))
8058 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: New PSK for addr=" MACSTR
8059 " p2p_dev_addr=" MACSTR
,
8060 MAC2STR(mac_addr
), MAC2STR(p2p_dev_addr
));
8061 if (is_zero_ether_addr(p2p_dev_addr
))
8062 p2p_dev_addr
= NULL
;
8064 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: New PSK for addr=" MACSTR
,
8068 if (ssid
->mode
== WPAS_MODE_P2P_GROUP_FORMATION
) {
8069 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: new_psk_cb during group formation");
8070 /* To be added to persistent group once created */
8071 if (wpa_s
->global
->add_psk
== NULL
) {
8072 wpa_s
->global
->add_psk
= os_zalloc(sizeof(*p
));
8073 if (wpa_s
->global
->add_psk
== NULL
)
8076 p
= wpa_s
->global
->add_psk
;
8079 os_memcpy(p
->addr
, p2p_dev_addr
, ETH_ALEN
);
8082 os_memcpy(p
->addr
, mac_addr
, ETH_ALEN
);
8084 os_memcpy(p
->psk
, psk
, psk_len
);
8088 if (ssid
->mode
!= WPAS_MODE_P2P_GO
|| !ssid
->p2p_persistent_group
) {
8089 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Ignore new_psk_cb on not-persistent GO");
8093 persistent
= wpas_p2p_get_persistent(wpa_s
->p2pdev
, NULL
, ssid
->ssid
,
8096 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Could not find persistent group information to store the new PSK");
8100 p
= os_zalloc(sizeof(*p
));
8105 os_memcpy(p
->addr
, p2p_dev_addr
, ETH_ALEN
);
8108 os_memcpy(p
->addr
, mac_addr
, ETH_ALEN
);
8110 os_memcpy(p
->psk
, psk
, psk_len
);
8112 if (dl_list_len(&persistent
->psk_list
) > P2P_MAX_STORED_CLIENTS
&&
8113 (last
= dl_list_last(&persistent
->psk_list
,
8114 struct psk_list_entry
, list
))) {
8115 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Remove oldest PSK entry for "
8116 MACSTR
" (p2p=%u) to make room for a new one",
8117 MAC2STR(last
->addr
), last
->p2p
);
8118 dl_list_del(&last
->list
);
8122 wpas_p2p_remove_psk_entry(wpa_s
->p2pdev
, persistent
,
8123 p2p_dev_addr
? p2p_dev_addr
: mac_addr
,
8124 p2p_dev_addr
== NULL
);
8126 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Add new PSK for p2p_dev_addr="
8127 MACSTR
, MAC2STR(p2p_dev_addr
));
8129 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Add new PSK for addr=" MACSTR
,
8132 dl_list_add(&persistent
->psk_list
, &p
->list
);
8134 if (wpa_s
->p2pdev
->conf
->update_config
&&
8135 wpa_config_write(wpa_s
->p2pdev
->confname
, wpa_s
->p2pdev
->conf
))
8136 wpa_printf(MSG_DEBUG
, "P2P: Failed to update configuration");
8140 static void wpas_p2p_remove_psk(struct wpa_supplicant
*wpa_s
,
8141 struct wpa_ssid
*s
, const u8
*addr
,
8146 res
= wpas_p2p_remove_psk_entry(wpa_s
, s
, addr
, iface_addr
);
8147 if (res
> 0 && wpa_s
->conf
->update_config
&&
8148 wpa_config_write(wpa_s
->confname
, wpa_s
->conf
))
8149 wpa_dbg(wpa_s
, MSG_DEBUG
,
8150 "P2P: Failed to update configuration");
8154 static void wpas_p2p_remove_client_go(struct wpa_supplicant
*wpa_s
,
8155 const u8
*peer
, int iface_addr
)
8157 struct hostapd_data
*hapd
;
8158 struct hostapd_wpa_psk
*psk
, *prev
, *rem
;
8159 struct sta_info
*sta
;
8161 if (wpa_s
->ap_iface
== NULL
|| wpa_s
->current_ssid
== NULL
||
8162 wpa_s
->current_ssid
->mode
!= WPAS_MODE_P2P_GO
)
8165 /* Remove per-station PSK entry */
8166 hapd
= wpa_s
->ap_iface
->bss
[0];
8168 psk
= hapd
->conf
->ssid
.wpa_psk
;
8170 if ((iface_addr
&& os_memcmp(peer
, psk
->addr
, ETH_ALEN
) == 0) ||
8172 os_memcmp(peer
, psk
->p2p_dev_addr
, ETH_ALEN
) == 0)) {
8173 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Remove operating group PSK entry for "
8174 MACSTR
" iface_addr=%d",
8175 MAC2STR(peer
), iface_addr
);
8177 prev
->next
= psk
->next
;
8179 hapd
->conf
->ssid
.wpa_psk
= psk
->next
;
8189 /* Disconnect from group */
8191 sta
= ap_get_sta(hapd
, peer
);
8193 sta
= ap_get_sta_p2p(hapd
, peer
);
8195 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Disconnect peer " MACSTR
8196 " (iface_addr=%d) from group",
8197 MAC2STR(peer
), iface_addr
);
8198 hostapd_drv_sta_deauth(hapd
, sta
->addr
,
8199 WLAN_REASON_DEAUTH_LEAVING
);
8200 ap_sta_deauthenticate(hapd
, sta
, WLAN_REASON_DEAUTH_LEAVING
);
8205 void wpas_p2p_remove_client(struct wpa_supplicant
*wpa_s
, const u8
*peer
,
8209 struct wpa_supplicant
*w
;
8210 struct wpa_supplicant
*p2p_wpa_s
= wpa_s
->global
->p2p_init_wpa_s
;
8212 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Remove client " MACSTR
, MAC2STR(peer
));
8214 /* Remove from any persistent group */
8215 for (s
= p2p_wpa_s
->conf
->ssid
; s
; s
= s
->next
) {
8216 if (s
->disabled
!= 2 || s
->mode
!= WPAS_MODE_P2P_GO
)
8219 wpas_remove_persistent_peer(p2p_wpa_s
, s
, peer
, 0);
8220 wpas_p2p_remove_psk(p2p_wpa_s
, s
, peer
, iface_addr
);
8223 /* Remove from any operating group */
8224 for (w
= wpa_s
->global
->ifaces
; w
; w
= w
->next
)
8225 wpas_p2p_remove_client_go(w
, peer
, iface_addr
);
8229 static void wpas_p2p_psk_failure_removal(void *eloop_ctx
, void *timeout_ctx
)
8231 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
8232 wpas_p2p_group_delete(wpa_s
, P2P_GROUP_REMOVAL_PSK_FAILURE
);
8236 static void wpas_p2p_group_freq_conflict(void *eloop_ctx
, void *timeout_ctx
)
8238 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
8240 wpa_printf(MSG_DEBUG
, "P2P: Frequency conflict - terminate group");
8241 wpas_p2p_group_delete(wpa_s
, P2P_GROUP_REMOVAL_FREQ_CONFLICT
);
8245 int wpas_p2p_handle_frequency_conflicts(struct wpa_supplicant
*wpa_s
, int freq
,
8246 struct wpa_ssid
*ssid
)
8248 struct wpa_supplicant
*iface
;
8250 for (iface
= wpa_s
->global
->ifaces
; iface
; iface
= iface
->next
) {
8251 if (!iface
->current_ssid
||
8252 iface
->current_ssid
->frequency
== freq
||
8253 (iface
->p2p_group_interface
== NOT_P2P_GROUP_INTERFACE
&&
8254 !iface
->current_ssid
->p2p_group
))
8257 /* Remove the connection with least priority */
8258 if (!wpas_is_p2p_prioritized(iface
)) {
8259 /* STA connection has priority over existing
8260 * P2P connection, so remove the interface. */
8261 wpa_printf(MSG_DEBUG
, "P2P: Removing P2P connection due to single channel concurrent mode frequency conflict");
8262 eloop_register_timeout(0, 0,
8263 wpas_p2p_group_freq_conflict
,
8265 /* If connection in progress is P2P connection, do not
8266 * proceed for the connection. */
8272 /* P2P connection has priority, disable the STA network
8274 wpa_supplicant_disable_network(wpa_s
->global
->ifaces
,
8276 wpa_msg(wpa_s
->global
->ifaces
, MSG_INFO
,
8277 WPA_EVENT_FREQ_CONFLICT
" id=%d", ssid
->id
);
8278 os_memset(wpa_s
->global
->ifaces
->pending_bssid
, 0,
8280 /* If P2P connection is in progress, continue
8293 int wpas_p2p_4way_hs_failed(struct wpa_supplicant
*wpa_s
)
8295 struct wpa_ssid
*ssid
= wpa_s
->current_ssid
;
8297 if (ssid
== NULL
|| !ssid
->p2p_group
)
8300 if (wpa_s
->p2p_last_4way_hs_fail
&&
8301 wpa_s
->p2p_last_4way_hs_fail
== ssid
) {
8302 u8 go_dev_addr
[ETH_ALEN
];
8303 struct wpa_ssid
*persistent
;
8305 if (wpas_p2p_persistent_group(wpa_s
, go_dev_addr
,
8307 ssid
->ssid_len
) <= 0) {
8308 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Could not determine whether 4-way handshake failures were for a persistent group");
8312 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Two 4-way handshake failures for a P2P group - go_dev_addr="
8313 MACSTR
, MAC2STR(go_dev_addr
));
8314 persistent
= wpas_p2p_get_persistent(wpa_s
->p2pdev
, go_dev_addr
,
8317 if (persistent
== NULL
|| persistent
->mode
!= WPAS_MODE_INFRA
) {
8318 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: No matching persistent group stored");
8321 wpa_msg_global(wpa_s
->p2pdev
, MSG_INFO
,
8322 P2P_EVENT_PERSISTENT_PSK_FAIL
"%d",
8325 wpa_s
->p2p_last_4way_hs_fail
= NULL
;
8327 * Remove the group from a timeout to avoid issues with caller
8328 * continuing to use the interface if this is on a P2P group
8331 eloop_register_timeout(0, 0, wpas_p2p_psk_failure_removal
,
8336 wpa_s
->p2p_last_4way_hs_fail
= ssid
;
8341 #ifdef CONFIG_WPS_NFC
8343 static struct wpabuf
* wpas_p2p_nfc_handover(int ndef
, struct wpabuf
*wsc
,
8351 wpa_printf(MSG_DEBUG
, "P2P: No p2p buffer for handover");
8355 wsc_len
= wsc
? wpabuf_len(wsc
) : 0;
8356 ret
= wpabuf_alloc(2 + wsc_len
+ 2 + wpabuf_len(p2p
));
8363 wpabuf_put_be16(ret
, wsc_len
);
8365 wpabuf_put_buf(ret
, wsc
);
8366 wpabuf_put_be16(ret
, wpabuf_len(p2p
));
8367 wpabuf_put_buf(ret
, p2p
);
8371 wpa_hexdump_buf(MSG_DEBUG
,
8372 "P2P: Generated NFC connection handover message", ret
);
8376 tmp
= ndef_build_p2p(ret
);
8379 wpa_printf(MSG_DEBUG
, "P2P: Failed to NDEF encapsulate handover request");
8389 static int wpas_p2p_cli_freq(struct wpa_supplicant
*wpa_s
,
8390 struct wpa_ssid
**ssid
, u8
*go_dev_addr
)
8392 struct wpa_supplicant
*iface
;
8395 os_memset(go_dev_addr
, 0, ETH_ALEN
);
8398 for (iface
= wpa_s
->global
->ifaces
; iface
; iface
= iface
->next
) {
8399 if (iface
->wpa_state
< WPA_ASSOCIATING
||
8400 iface
->current_ssid
== NULL
|| iface
->assoc_freq
== 0 ||
8401 !iface
->current_ssid
->p2p_group
||
8402 iface
->current_ssid
->mode
!= WPAS_MODE_INFRA
)
8405 *ssid
= iface
->current_ssid
;
8407 os_memcpy(go_dev_addr
, iface
->go_dev_addr
, ETH_ALEN
);
8408 return iface
->assoc_freq
;
8414 struct wpabuf
* wpas_p2p_nfc_handover_req(struct wpa_supplicant
*wpa_s
,
8417 struct wpabuf
*wsc
, *p2p
;
8418 struct wpa_ssid
*ssid
;
8419 u8 go_dev_addr
[ETH_ALEN
];
8420 int cli_freq
= wpas_p2p_cli_freq(wpa_s
, &ssid
, go_dev_addr
);
8422 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
) {
8423 wpa_printf(MSG_DEBUG
, "P2P: P2P disabled - cannot build handover request");
8427 if (wpa_s
->conf
->wps_nfc_dh_pubkey
== NULL
&&
8428 wps_nfc_gen_dh(&wpa_s
->conf
->wps_nfc_dh_pubkey
,
8429 &wpa_s
->conf
->wps_nfc_dh_privkey
) < 0) {
8430 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: No DH key available for handover request");
8434 if (cli_freq
== 0) {
8435 wsc
= wps_build_nfc_handover_req_p2p(
8436 wpa_s
->parent
->wps
, wpa_s
->conf
->wps_nfc_dh_pubkey
);
8439 p2p
= p2p_build_nfc_handover_req(wpa_s
->global
->p2p
, cli_freq
,
8440 go_dev_addr
, ssid
? ssid
->ssid
: NULL
,
8441 ssid
? ssid
->ssid_len
: 0);
8443 return wpas_p2p_nfc_handover(ndef
, wsc
, p2p
);
8447 struct wpabuf
* wpas_p2p_nfc_handover_sel(struct wpa_supplicant
*wpa_s
,
8450 struct wpabuf
*wsc
, *p2p
;
8451 struct wpa_ssid
*ssid
;
8452 u8 go_dev_addr
[ETH_ALEN
];
8453 int cli_freq
= wpas_p2p_cli_freq(wpa_s
, &ssid
, go_dev_addr
);
8455 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
8458 if (!tag
&& wpa_s
->conf
->wps_nfc_dh_pubkey
== NULL
&&
8459 wps_nfc_gen_dh(&wpa_s
->conf
->wps_nfc_dh_pubkey
,
8460 &wpa_s
->conf
->wps_nfc_dh_privkey
) < 0)
8463 if (cli_freq
== 0) {
8464 wsc
= wps_build_nfc_handover_sel_p2p(
8466 tag
? wpa_s
->conf
->wps_nfc_dev_pw_id
:
8467 DEV_PW_NFC_CONNECTION_HANDOVER
,
8468 wpa_s
->conf
->wps_nfc_dh_pubkey
,
8469 tag
? wpa_s
->conf
->wps_nfc_dev_pw
: NULL
);
8472 p2p
= p2p_build_nfc_handover_sel(wpa_s
->global
->p2p
, cli_freq
,
8473 go_dev_addr
, ssid
? ssid
->ssid
: NULL
,
8474 ssid
? ssid
->ssid_len
: 0);
8476 return wpas_p2p_nfc_handover(ndef
, wsc
, p2p
);
8480 static int wpas_p2p_nfc_join_group(struct wpa_supplicant
*wpa_s
,
8481 struct p2p_nfc_params
*params
)
8483 wpa_printf(MSG_DEBUG
, "P2P: Initiate join-group based on NFC "
8484 "connection handover (freq=%d)",
8487 if (params
->go_freq
&& params
->go_ssid_len
) {
8488 wpa_s
->p2p_wps_method
= WPS_NFC
;
8489 wpa_s
->pending_join_wps_method
= WPS_NFC
;
8490 os_memset(wpa_s
->pending_join_iface_addr
, 0, ETH_ALEN
);
8491 os_memcpy(wpa_s
->pending_join_dev_addr
, params
->go_dev_addr
,
8493 return wpas_p2p_join_start(wpa_s
, params
->go_freq
,
8495 params
->go_ssid_len
);
8498 return wpas_p2p_connect(wpa_s
, params
->peer
->p2p_device_addr
, NULL
,
8499 WPS_NFC
, 0, 0, 1, 0, wpa_s
->conf
->p2p_go_intent
,
8500 params
->go_freq
, wpa_s
->p2p_go_vht_center_freq2
,
8501 -1, 0, 1, 1, wpa_s
->p2p_go_max_oper_chwidth
,
8502 params
->go_ssid_len
? params
->go_ssid
: NULL
,
8503 params
->go_ssid_len
);
8507 static int wpas_p2p_nfc_auth_join(struct wpa_supplicant
*wpa_s
,
8508 struct p2p_nfc_params
*params
, int tag
)
8510 int res
, persistent
;
8511 struct wpa_ssid
*ssid
;
8513 wpa_printf(MSG_DEBUG
, "P2P: Authorize join-group based on NFC "
8514 "connection handover");
8515 for (wpa_s
= wpa_s
->global
->ifaces
; wpa_s
; wpa_s
= wpa_s
->next
) {
8516 ssid
= wpa_s
->current_ssid
;
8519 if (ssid
->mode
!= WPAS_MODE_P2P_GO
)
8521 if (wpa_s
->ap_iface
== NULL
)
8525 if (wpa_s
== NULL
) {
8526 wpa_printf(MSG_DEBUG
, "P2P: Could not find GO interface");
8530 if (wpa_s
->p2pdev
->p2p_oob_dev_pw_id
!=
8531 DEV_PW_NFC_CONNECTION_HANDOVER
&&
8532 !wpa_s
->p2pdev
->p2p_oob_dev_pw
) {
8533 wpa_printf(MSG_DEBUG
, "P2P: No NFC Dev Pw known");
8536 res
= wpas_ap_wps_add_nfc_pw(
8537 wpa_s
, wpa_s
->p2pdev
->p2p_oob_dev_pw_id
,
8538 wpa_s
->p2pdev
->p2p_oob_dev_pw
,
8539 wpa_s
->p2pdev
->p2p_peer_oob_pk_hash_known
?
8540 wpa_s
->p2pdev
->p2p_peer_oob_pubkey_hash
: NULL
);
8545 wpa_printf(MSG_DEBUG
, "P2P: Negotiated handover - wait for peer to join without invitation");
8549 if (!params
->peer
||
8550 !(params
->peer
->dev_capab
& P2P_DEV_CAPAB_INVITATION_PROCEDURE
))
8553 wpa_printf(MSG_DEBUG
, "P2P: Static handover - invite peer " MACSTR
8554 " to join", MAC2STR(params
->peer
->p2p_device_addr
));
8556 wpa_s
->global
->p2p_invite_group
= wpa_s
;
8557 persistent
= ssid
->p2p_persistent_group
&&
8558 wpas_p2p_get_persistent(wpa_s
->p2pdev
,
8559 params
->peer
->p2p_device_addr
,
8560 ssid
->ssid
, ssid
->ssid_len
);
8561 wpa_s
->p2pdev
->pending_invite_ssid_id
= -1;
8563 return p2p_invite(wpa_s
->global
->p2p
, params
->peer
->p2p_device_addr
,
8564 P2P_INVITE_ROLE_ACTIVE_GO
, wpa_s
->own_addr
,
8565 ssid
->ssid
, ssid
->ssid_len
, ssid
->frequency
,
8566 wpa_s
->global
->p2p_dev_addr
, persistent
, 0,
8567 wpa_s
->p2pdev
->p2p_oob_dev_pw_id
);
8571 static int wpas_p2p_nfc_init_go_neg(struct wpa_supplicant
*wpa_s
,
8572 struct p2p_nfc_params
*params
,
8575 wpa_printf(MSG_DEBUG
, "P2P: Initiate GO Negotiation based on NFC "
8576 "connection handover");
8577 return wpas_p2p_connect(wpa_s
, params
->peer
->p2p_device_addr
, NULL
,
8578 WPS_NFC
, 0, 0, 0, 0, wpa_s
->conf
->p2p_go_intent
,
8579 forced_freq
, wpa_s
->p2p_go_vht_center_freq2
,
8580 -1, 0, 1, 1, wpa_s
->p2p_go_max_oper_chwidth
,
8585 static int wpas_p2p_nfc_resp_go_neg(struct wpa_supplicant
*wpa_s
,
8586 struct p2p_nfc_params
*params
,
8591 wpa_printf(MSG_DEBUG
, "P2P: Authorize GO Negotiation based on NFC "
8592 "connection handover");
8593 res
= wpas_p2p_connect(wpa_s
, params
->peer
->p2p_device_addr
, NULL
,
8594 WPS_NFC
, 0, 0, 0, 1, wpa_s
->conf
->p2p_go_intent
,
8595 forced_freq
, wpa_s
->p2p_go_vht_center_freq2
,
8596 -1, 0, 1, 1, wpa_s
->p2p_go_max_oper_chwidth
,
8601 res
= wpas_p2p_listen(wpa_s
, 60);
8603 p2p_unauthorize(wpa_s
->global
->p2p
,
8604 params
->peer
->p2p_device_addr
);
8611 static int wpas_p2p_nfc_connection_handover(struct wpa_supplicant
*wpa_s
,
8612 const struct wpabuf
*data
,
8613 int sel
, int tag
, int forced_freq
)
8615 const u8
*pos
, *end
;
8617 struct p2p_nfc_params params
;
8620 os_memset(¶ms
, 0, sizeof(params
));
8623 wpa_hexdump_buf(MSG_DEBUG
, "P2P: Received NFC tag payload", data
);
8625 pos
= wpabuf_head(data
);
8626 end
= pos
+ wpabuf_len(data
);
8628 if (end
- pos
< 2) {
8629 wpa_printf(MSG_DEBUG
, "P2P: Not enough data for Length of WSC "
8633 len
= WPA_GET_BE16(pos
);
8635 if (len
> end
- pos
) {
8636 wpa_printf(MSG_DEBUG
, "P2P: Not enough data for WSC "
8640 params
.wsc_attr
= pos
;
8641 params
.wsc_len
= len
;
8644 if (end
- pos
< 2) {
8645 wpa_printf(MSG_DEBUG
, "P2P: Not enough data for Length of P2P "
8649 len
= WPA_GET_BE16(pos
);
8651 if (len
> end
- pos
) {
8652 wpa_printf(MSG_DEBUG
, "P2P: Not enough data for P2P "
8656 params
.p2p_attr
= pos
;
8657 params
.p2p_len
= len
;
8660 wpa_hexdump(MSG_DEBUG
, "P2P: WSC attributes",
8661 params
.wsc_attr
, params
.wsc_len
);
8662 wpa_hexdump(MSG_DEBUG
, "P2P: P2P attributes",
8663 params
.p2p_attr
, params
.p2p_len
);
8665 wpa_hexdump(MSG_DEBUG
,
8666 "P2P: Ignored extra data after P2P attributes",
8670 res
= p2p_process_nfc_connection_handover(wpa_s
->global
->p2p
, ¶ms
);
8674 if (params
.next_step
== NO_ACTION
)
8677 if (params
.next_step
== BOTH_GO
) {
8678 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_NFC_BOTH_GO
"peer=" MACSTR
,
8679 MAC2STR(params
.peer
->p2p_device_addr
));
8683 if (params
.next_step
== PEER_CLIENT
) {
8684 if (!is_zero_ether_addr(params
.go_dev_addr
)) {
8685 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_NFC_PEER_CLIENT
8686 "peer=" MACSTR
" freq=%d go_dev_addr=" MACSTR
8688 MAC2STR(params
.peer
->p2p_device_addr
),
8690 MAC2STR(params
.go_dev_addr
),
8691 wpa_ssid_txt(params
.go_ssid
,
8692 params
.go_ssid_len
));
8694 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_NFC_PEER_CLIENT
8695 "peer=" MACSTR
" freq=%d",
8696 MAC2STR(params
.peer
->p2p_device_addr
),
8702 if (wpas_p2p_cli_freq(wpa_s
, NULL
, NULL
)) {
8703 wpa_msg(wpa_s
, MSG_INFO
, P2P_EVENT_NFC_WHILE_CLIENT
"peer="
8704 MACSTR
, MAC2STR(params
.peer
->p2p_device_addr
));
8708 wpabuf_free(wpa_s
->p2p_oob_dev_pw
);
8709 wpa_s
->p2p_oob_dev_pw
= NULL
;
8711 if (params
.oob_dev_pw_len
< WPS_OOB_PUBKEY_HASH_LEN
+ 2) {
8712 wpa_printf(MSG_DEBUG
, "P2P: No peer OOB Dev Pw "
8717 id
= WPA_GET_BE16(params
.oob_dev_pw
+ WPS_OOB_PUBKEY_HASH_LEN
);
8718 wpa_printf(MSG_DEBUG
, "P2P: Peer OOB Dev Pw %u", id
);
8719 wpa_hexdump(MSG_DEBUG
, "P2P: Peer OOB Public Key hash",
8720 params
.oob_dev_pw
, WPS_OOB_PUBKEY_HASH_LEN
);
8721 os_memcpy(wpa_s
->p2p_peer_oob_pubkey_hash
,
8722 params
.oob_dev_pw
, WPS_OOB_PUBKEY_HASH_LEN
);
8723 wpa_s
->p2p_peer_oob_pk_hash_known
= 1;
8727 wpa_printf(MSG_DEBUG
, "P2P: Static handover - invalid "
8728 "peer OOB Device Password Id %u", id
);
8731 wpa_printf(MSG_DEBUG
, "P2P: Static handover - use peer OOB "
8732 "Device Password Id %u", id
);
8733 wpa_hexdump_key(MSG_DEBUG
, "P2P: Peer OOB Device Password",
8734 params
.oob_dev_pw
+ WPS_OOB_PUBKEY_HASH_LEN
+ 2,
8735 params
.oob_dev_pw_len
-
8736 WPS_OOB_PUBKEY_HASH_LEN
- 2);
8737 wpa_s
->p2p_oob_dev_pw_id
= id
;
8738 wpa_s
->p2p_oob_dev_pw
= wpabuf_alloc_copy(
8739 params
.oob_dev_pw
+ WPS_OOB_PUBKEY_HASH_LEN
+ 2,
8740 params
.oob_dev_pw_len
-
8741 WPS_OOB_PUBKEY_HASH_LEN
- 2);
8742 if (wpa_s
->p2p_oob_dev_pw
== NULL
)
8745 if (wpa_s
->conf
->wps_nfc_dh_pubkey
== NULL
&&
8746 wps_nfc_gen_dh(&wpa_s
->conf
->wps_nfc_dh_pubkey
,
8747 &wpa_s
->conf
->wps_nfc_dh_privkey
) < 0)
8750 wpa_printf(MSG_DEBUG
, "P2P: Using abbreviated WPS handshake "
8751 "without Device Password");
8752 wpa_s
->p2p_oob_dev_pw_id
= DEV_PW_NFC_CONNECTION_HANDOVER
;
8755 switch (params
.next_step
) {
8759 /* already covered above */
8762 return wpas_p2p_nfc_join_group(wpa_s
, ¶ms
);
8764 return wpas_p2p_nfc_auth_join(wpa_s
, ¶ms
, tag
);
8766 return wpas_p2p_nfc_init_go_neg(wpa_s
, ¶ms
, forced_freq
);
8768 /* TODO: use own OOB Dev Pw */
8769 return wpas_p2p_nfc_resp_go_neg(wpa_s
, ¶ms
, forced_freq
);
8776 int wpas_p2p_nfc_tag_process(struct wpa_supplicant
*wpa_s
,
8777 const struct wpabuf
*data
, int forced_freq
)
8779 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
8782 return wpas_p2p_nfc_connection_handover(wpa_s
, data
, 1, 1, forced_freq
);
8786 int wpas_p2p_nfc_report_handover(struct wpa_supplicant
*wpa_s
, int init
,
8787 const struct wpabuf
*req
,
8788 const struct wpabuf
*sel
, int forced_freq
)
8793 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
8796 wpa_printf(MSG_DEBUG
, "NFC: P2P connection handover reported");
8798 wpa_hexdump_ascii(MSG_DEBUG
, "NFC: Req",
8799 wpabuf_head(req
), wpabuf_len(req
));
8800 wpa_hexdump_ascii(MSG_DEBUG
, "NFC: Sel",
8801 wpabuf_head(sel
), wpabuf_len(sel
));
8803 wpa_printf(MSG_DEBUG
, "NFC: Forced freq %d", forced_freq
);
8804 tmp
= ndef_parse_p2p(init
? sel
: req
);
8806 wpa_printf(MSG_DEBUG
, "P2P: Could not parse NDEF");
8810 ret
= wpas_p2p_nfc_connection_handover(wpa_s
, tmp
, init
, 0,
8818 int wpas_p2p_nfc_tag_enabled(struct wpa_supplicant
*wpa_s
, int enabled
)
8821 int go_intent
= wpa_s
->conf
->p2p_go_intent
;
8822 struct wpa_supplicant
*iface
;
8824 if (wpa_s
->global
->p2p
== NULL
)
8828 wpa_printf(MSG_DEBUG
, "P2P: Disable use of own NFC Tag");
8829 for (iface
= wpa_s
->global
->ifaces
; iface
; iface
= iface
->next
)
8831 if (!iface
->ap_iface
)
8833 hostapd_wps_nfc_token_disable(iface
->ap_iface
->bss
[0]);
8835 p2p_set_authorized_oob_dev_pw_id(wpa_s
->global
->p2p
, 0,
8837 if (wpa_s
->p2p_nfc_tag_enabled
)
8838 wpas_p2p_remove_pending_group_interface(wpa_s
);
8839 wpa_s
->p2p_nfc_tag_enabled
= 0;
8843 if (wpa_s
->global
->p2p_disabled
)
8846 if (wpa_s
->conf
->wps_nfc_dh_pubkey
== NULL
||
8847 wpa_s
->conf
->wps_nfc_dh_privkey
== NULL
||
8848 wpa_s
->conf
->wps_nfc_dev_pw
== NULL
||
8849 wpa_s
->conf
->wps_nfc_dev_pw_id
< 0x10) {
8850 wpa_printf(MSG_DEBUG
, "P2P: NFC password token not configured "
8851 "to allow static handover cases");
8855 wpa_printf(MSG_DEBUG
, "P2P: Enable use of own NFC Tag");
8857 wpa_s
->p2p_oob_dev_pw_id
= wpa_s
->conf
->wps_nfc_dev_pw_id
;
8858 wpabuf_free(wpa_s
->p2p_oob_dev_pw
);
8859 wpa_s
->p2p_oob_dev_pw
= wpabuf_dup(wpa_s
->conf
->wps_nfc_dev_pw
);
8860 if (wpa_s
->p2p_oob_dev_pw
== NULL
)
8862 wpa_s
->p2p_peer_oob_pk_hash_known
= 0;
8864 if (wpa_s
->p2p_group_interface
== P2P_GROUP_INTERFACE_GO
||
8865 wpa_s
->p2p_group_interface
== P2P_GROUP_INTERFACE_CLIENT
) {
8867 * P2P Group Interface present and the command came on group
8868 * interface, so enable the token for the current interface.
8870 wpa_s
->create_p2p_iface
= 0;
8872 wpa_s
->create_p2p_iface
= wpas_p2p_create_iface(wpa_s
);
8875 if (wpa_s
->create_p2p_iface
) {
8876 enum wpa_driver_if_type iftype
;
8877 /* Prepare to add a new interface for the group */
8878 iftype
= WPA_IF_P2P_GROUP
;
8879 if (go_intent
== 15)
8880 iftype
= WPA_IF_P2P_GO
;
8881 if (wpas_p2p_add_group_interface(wpa_s
, iftype
) < 0) {
8882 wpa_printf(MSG_ERROR
, "P2P: Failed to allocate a new "
8883 "interface for the group");
8887 if_addr
= wpa_s
->pending_interface_addr
;
8888 } else if (wpa_s
->p2p_mgmt
)
8889 if_addr
= wpa_s
->parent
->own_addr
;
8891 if_addr
= wpa_s
->own_addr
;
8893 wpa_s
->p2p_nfc_tag_enabled
= enabled
;
8895 for (iface
= wpa_s
->global
->ifaces
; iface
; iface
= iface
->next
) {
8896 struct hostapd_data
*hapd
;
8897 if (iface
->ap_iface
== NULL
)
8899 hapd
= iface
->ap_iface
->bss
[0];
8900 wpabuf_free(hapd
->conf
->wps_nfc_dh_pubkey
);
8901 hapd
->conf
->wps_nfc_dh_pubkey
=
8902 wpabuf_dup(wpa_s
->conf
->wps_nfc_dh_pubkey
);
8903 wpabuf_free(hapd
->conf
->wps_nfc_dh_privkey
);
8904 hapd
->conf
->wps_nfc_dh_privkey
=
8905 wpabuf_dup(wpa_s
->conf
->wps_nfc_dh_privkey
);
8906 wpabuf_free(hapd
->conf
->wps_nfc_dev_pw
);
8907 hapd
->conf
->wps_nfc_dev_pw
=
8908 wpabuf_dup(wpa_s
->conf
->wps_nfc_dev_pw
);
8909 hapd
->conf
->wps_nfc_dev_pw_id
= wpa_s
->conf
->wps_nfc_dev_pw_id
;
8911 if (hostapd_wps_nfc_token_enable(iface
->ap_iface
->bss
[0]) < 0) {
8912 wpa_dbg(iface
, MSG_DEBUG
,
8913 "P2P: Failed to enable NFC Tag for GO");
8916 p2p_set_authorized_oob_dev_pw_id(
8917 wpa_s
->global
->p2p
, wpa_s
->conf
->wps_nfc_dev_pw_id
, go_intent
,
8923 #endif /* CONFIG_WPS_NFC */
8926 static void wpas_p2p_optimize_listen_channel(struct wpa_supplicant
*wpa_s
,
8927 struct wpa_used_freq_data
*freqs
,
8930 u8 curr_chan
, cand
, chan
;
8934 * If possible, optimize the Listen channel to be a channel that is
8935 * already used by one of the other interfaces.
8937 if (!wpa_s
->conf
->p2p_optimize_listen_chan
)
8940 if (!wpa_s
->current_ssid
|| wpa_s
->wpa_state
!= WPA_COMPLETED
)
8943 curr_chan
= p2p_get_listen_channel(wpa_s
->global
->p2p
);
8944 for (i
= 0, cand
= 0; i
< num
; i
++) {
8945 ieee80211_freq_to_chan(freqs
[i
].freq
, &chan
);
8946 if (curr_chan
== chan
) {
8951 if (chan
== 1 || chan
== 6 || chan
== 11)
8956 wpa_dbg(wpa_s
, MSG_DEBUG
,
8957 "P2P: Update Listen channel to %u based on operating channel",
8959 p2p_set_listen_channel(wpa_s
->global
->p2p
, 81, cand
, 0);
8964 static int wpas_p2p_move_go_csa(struct wpa_supplicant
*wpa_s
)
8966 struct hostapd_config
*conf
;
8967 struct p2p_go_neg_results params
;
8968 struct csa_settings csa_settings
;
8969 struct wpa_ssid
*current_ssid
= wpa_s
->current_ssid
;
8970 int old_freq
= current_ssid
->frequency
;
8973 if (!(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_AP_CSA
)) {
8974 wpa_dbg(wpa_s
, MSG_DEBUG
, "CSA is not enabled");
8979 * TODO: This function may not always work correctly. For example,
8980 * when we have a running GO and a BSS on a DFS channel.
8982 if (wpas_p2p_init_go_params(wpa_s
, ¶ms
, 0, 0, 0, 0, 0, NULL
)) {
8983 wpa_dbg(wpa_s
, MSG_DEBUG
,
8984 "P2P CSA: Failed to select new frequency for GO");
8988 if (current_ssid
->frequency
== params
.freq
) {
8989 wpa_dbg(wpa_s
, MSG_DEBUG
,
8990 "P2P CSA: Selected same frequency - not moving GO");
8994 conf
= hostapd_config_defaults();
8996 wpa_dbg(wpa_s
, MSG_DEBUG
,
8997 "P2P CSA: Failed to allocate default config");
9001 current_ssid
->frequency
= params
.freq
;
9002 if (wpa_supplicant_conf_ap_ht(wpa_s
, current_ssid
, conf
)) {
9003 wpa_dbg(wpa_s
, MSG_DEBUG
,
9004 "P2P CSA: Failed to create new GO config");
9009 if (conf
->hw_mode
!= wpa_s
->ap_iface
->current_mode
->mode
) {
9010 wpa_dbg(wpa_s
, MSG_DEBUG
,
9011 "P2P CSA: CSA to a different band is not supported");
9016 os_memset(&csa_settings
, 0, sizeof(csa_settings
));
9017 csa_settings
.cs_count
= P2P_GO_CSA_COUNT
;
9018 csa_settings
.block_tx
= P2P_GO_CSA_BLOCK_TX
;
9019 csa_settings
.freq_params
.freq
= params
.freq
;
9020 csa_settings
.freq_params
.sec_channel_offset
= conf
->secondary_channel
;
9021 csa_settings
.freq_params
.ht_enabled
= conf
->ieee80211n
;
9022 csa_settings
.freq_params
.bandwidth
= conf
->secondary_channel
? 40 : 20;
9024 if (conf
->ieee80211ac
) {
9025 int freq1
= 0, freq2
= 0;
9028 if (ieee80211_freq_to_channel_ext(params
.freq
,
9029 conf
->secondary_channel
,
9030 conf
->vht_oper_chwidth
,
9032 NUM_HOSTAPD_MODES
) {
9033 wpa_printf(MSG_ERROR
, "P2P CSA: Bad freq");
9038 if (conf
->vht_oper_centr_freq_seg0_idx
)
9039 freq1
= ieee80211_chan_to_freq(
9041 conf
->vht_oper_centr_freq_seg0_idx
);
9043 if (conf
->vht_oper_centr_freq_seg1_idx
)
9044 freq2
= ieee80211_chan_to_freq(
9046 conf
->vht_oper_centr_freq_seg1_idx
);
9048 if (freq1
< 0 || freq2
< 0) {
9049 wpa_dbg(wpa_s
, MSG_DEBUG
,
9050 "P2P CSA: Selected invalid VHT center freqs");
9055 csa_settings
.freq_params
.vht_enabled
= conf
->ieee80211ac
;
9056 csa_settings
.freq_params
.center_freq1
= freq1
;
9057 csa_settings
.freq_params
.center_freq2
= freq2
;
9059 switch (conf
->vht_oper_chwidth
) {
9060 case VHT_CHANWIDTH_80MHZ
:
9061 case VHT_CHANWIDTH_80P80MHZ
:
9062 csa_settings
.freq_params
.bandwidth
= 80;
9064 case VHT_CHANWIDTH_160MHZ
:
9065 csa_settings
.freq_params
.bandwidth
= 160;
9070 ret
= ap_switch_channel(wpa_s
, &csa_settings
);
9072 current_ssid
->frequency
= old_freq
;
9073 hostapd_config_free(conf
);
9078 static void wpas_p2p_move_go_no_csa(struct wpa_supplicant
*wpa_s
)
9080 struct p2p_go_neg_results params
;
9081 struct wpa_ssid
*current_ssid
= wpa_s
->current_ssid
;
9083 wpa_msg_global(wpa_s
, MSG_INFO
, P2P_EVENT_REMOVE_AND_REFORM_GROUP
);
9085 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Move GO from freq=%d MHz",
9086 current_ssid
->frequency
);
9088 /* Stop the AP functionality */
9089 /* TODO: Should do this in a way that does not indicated to possible
9090 * P2P Clients in the group that the group is terminated. */
9091 wpa_supplicant_ap_deinit(wpa_s
);
9093 /* Reselect the GO frequency */
9094 if (wpas_p2p_init_go_params(wpa_s
, ¶ms
, 0, 0, 0, 0, 0, NULL
)) {
9095 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Failed to reselect freq");
9096 wpas_p2p_group_delete(wpa_s
,
9097 P2P_GROUP_REMOVAL_GO_LEAVE_CHANNEL
);
9100 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: New freq selected for the GO (%u MHz)",
9104 !p2p_supported_freq_go(wpa_s
->global
->p2p
, params
.freq
)) {
9105 wpa_printf(MSG_DEBUG
,
9106 "P2P: Selected freq (%u MHz) is not valid for P2P",
9108 wpas_p2p_group_delete(wpa_s
,
9109 P2P_GROUP_REMOVAL_GO_LEAVE_CHANNEL
);
9113 /* Update the frequency */
9114 current_ssid
->frequency
= params
.freq
;
9115 wpa_s
->connect_without_scan
= current_ssid
;
9116 wpa_s
->reassociate
= 1;
9117 wpa_s
->disconnected
= 0;
9118 wpa_supplicant_req_scan(wpa_s
, 0, 0);
9122 static void wpas_p2p_move_go(void *eloop_ctx
, void *timeout_ctx
)
9124 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
9126 if (!wpa_s
->ap_iface
|| !wpa_s
->current_ssid
)
9129 wpas_p2p_go_update_common_freqs(wpa_s
);
9131 /* Do not move GO in the middle of a CSA */
9132 if (hostapd_csa_in_progress(wpa_s
->ap_iface
)) {
9133 wpa_printf(MSG_DEBUG
,
9134 "P2P: CSA is in progress - not moving GO");
9139 * First, try a channel switch flow. If it is not supported or fails,
9140 * take down the GO and bring it up again.
9142 if (wpas_p2p_move_go_csa(wpa_s
) < 0)
9143 wpas_p2p_move_go_no_csa(wpa_s
);
9147 static void wpas_p2p_reconsider_moving_go(void *eloop_ctx
, void *timeout_ctx
)
9149 struct wpa_supplicant
*wpa_s
= eloop_ctx
;
9150 struct wpa_used_freq_data
*freqs
= NULL
;
9151 unsigned int num
= wpa_s
->num_multichan_concurrent
;
9153 freqs
= os_calloc(num
, sizeof(struct wpa_used_freq_data
));
9157 num
= get_shared_radio_freqs_data(wpa_s
, freqs
, num
);
9159 /* Previous attempt to move a GO was not possible -- try again. */
9160 wpas_p2p_consider_moving_gos(wpa_s
, freqs
, num
,
9161 WPAS_P2P_CHANNEL_UPDATE_ANY
);
9168 * Consider moving a GO from its currently used frequency:
9169 * 1. It is possible that due to regulatory consideration the frequency
9170 * can no longer be used and there is a need to evacuate the GO.
9171 * 2. It is possible that due to MCC considerations, it would be preferable
9172 * to move the GO to a channel that is currently used by some other
9173 * station interface.
9175 * In case a frequency that became invalid is once again valid, cancel a
9176 * previously initiated GO frequency change.
9178 static void wpas_p2p_consider_moving_one_go(struct wpa_supplicant
*wpa_s
,
9179 struct wpa_used_freq_data
*freqs
,
9182 unsigned int i
, invalid_freq
= 0, policy_move
= 0, flags
= 0;
9183 unsigned int timeout
;
9187 wpas_p2p_go_update_common_freqs(wpa_s
);
9189 freq
= wpa_s
->current_ssid
->frequency
;
9190 dfs_offload
= (wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_DFS_OFFLOAD
) &&
9191 ieee80211_is_dfs(freq
, wpa_s
->hw
.modes
, wpa_s
->hw
.num_modes
);
9192 for (i
= 0, invalid_freq
= 0; i
< num
; i
++) {
9193 if (freqs
[i
].freq
== freq
) {
9194 flags
= freqs
[i
].flags
;
9196 /* The channel is invalid, must change it */
9197 if (!p2p_supported_freq_go(wpa_s
->global
->p2p
, freq
) &&
9199 wpa_dbg(wpa_s
, MSG_DEBUG
,
9200 "P2P: Freq=%d MHz no longer valid for GO",
9204 } else if (freqs
[i
].flags
== 0) {
9205 /* Freq is not used by any other station interface */
9207 } else if (!p2p_supported_freq(wpa_s
->global
->p2p
,
9208 freqs
[i
].freq
) && !dfs_offload
) {
9209 /* Freq is not valid for P2P use cases */
9211 } else if (wpa_s
->conf
->p2p_go_freq_change_policy
==
9212 P2P_GO_FREQ_MOVE_SCM
) {
9214 } else if (wpa_s
->conf
->p2p_go_freq_change_policy
==
9215 P2P_GO_FREQ_MOVE_SCM_PEER_SUPPORTS
&&
9216 wpas_p2p_go_is_peer_freq(wpa_s
, freqs
[i
].freq
)) {
9218 } else if ((wpa_s
->conf
->p2p_go_freq_change_policy
==
9219 P2P_GO_FREQ_MOVE_SCM_ECSA
) &&
9220 wpas_p2p_go_is_peer_freq(wpa_s
, freqs
[i
].freq
)) {
9221 if (!p2p_get_group_num_members(wpa_s
->p2p_group
)) {
9223 } else if ((wpa_s
->drv_flags
&
9224 WPA_DRIVER_FLAGS_AP_CSA
) &&
9225 wpas_p2p_go_clients_support_ecsa(wpa_s
)) {
9229 * We do not support CSA between bands, so move
9230 * GO only within the same band.
9232 if (wpa_s
->ap_iface
->current_mode
->mode
==
9233 ieee80211_freq_to_chan(freqs
[i
].freq
,
9240 wpa_dbg(wpa_s
, MSG_DEBUG
,
9241 "P2P: GO move: invalid_freq=%u, policy_move=%u, flags=0x%X",
9242 invalid_freq
, policy_move
, flags
);
9245 * The channel is valid, or we are going to have a policy move, so
9248 if (!invalid_freq
|| policy_move
) {
9249 wpa_dbg(wpa_s
, MSG_DEBUG
,
9250 "P2P: Cancel a GO move from freq=%d MHz", freq
);
9251 eloop_cancel_timeout(wpas_p2p_move_go
, wpa_s
, NULL
);
9253 if (wpas_p2p_in_progress(wpa_s
)) {
9254 wpa_dbg(wpa_s
, MSG_DEBUG
,
9255 "P2P: GO move: policy CS is not allowed - setting timeout to re-consider GO move");
9256 eloop_cancel_timeout(wpas_p2p_reconsider_moving_go
,
9258 eloop_register_timeout(P2P_RECONSIDER_GO_MOVE_DELAY
, 0,
9259 wpas_p2p_reconsider_moving_go
,
9265 if (!invalid_freq
&& (!policy_move
|| flags
!= 0)) {
9266 wpa_dbg(wpa_s
, MSG_DEBUG
,
9267 "P2P: Not initiating a GO frequency change");
9272 * Do not consider moving GO if it is in the middle of a CSA. When the
9273 * CSA is finished this flow should be retriggered.
9275 if (hostapd_csa_in_progress(wpa_s
->ap_iface
)) {
9276 wpa_dbg(wpa_s
, MSG_DEBUG
,
9277 "P2P: Not initiating a GO frequency change - CSA is in progress");
9281 if (invalid_freq
&& !wpas_p2p_disallowed_freq(wpa_s
->global
, freq
))
9282 timeout
= P2P_GO_FREQ_CHANGE_TIME
;
9286 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Move GO from freq=%d MHz in %d secs",
9288 eloop_cancel_timeout(wpas_p2p_move_go
, wpa_s
, NULL
);
9289 eloop_register_timeout(timeout
, 0, wpas_p2p_move_go
, wpa_s
, NULL
);
9293 static void wpas_p2p_consider_moving_gos(struct wpa_supplicant
*wpa_s
,
9294 struct wpa_used_freq_data
*freqs
,
9296 enum wpas_p2p_channel_update_trig trig
)
9298 struct wpa_supplicant
*ifs
;
9300 eloop_cancel_timeout(wpas_p2p_reconsider_moving_go
, ELOOP_ALL_CTX
,
9304 * Travers all the radio interfaces, and for each GO interface, check
9305 * if there is a need to move the GO from the frequency it is using,
9306 * or in case the frequency is valid again, cancel the evacuation flow.
9308 dl_list_for_each(ifs
, &wpa_s
->radio
->ifaces
, struct wpa_supplicant
,
9310 if (ifs
->current_ssid
== NULL
||
9311 ifs
->current_ssid
->mode
!= WPAS_MODE_P2P_GO
)
9315 * The GO was just started or completed channel switch, no need
9319 (trig
== WPAS_P2P_CHANNEL_UPDATE_STATE_CHANGE
||
9320 trig
== WPAS_P2P_CHANNEL_UPDATE_CS
)) {
9321 wpa_dbg(wpa_s
, MSG_DEBUG
,
9322 "P2P: GO move - schedule re-consideration");
9323 eloop_register_timeout(P2P_RECONSIDER_GO_MOVE_DELAY
, 0,
9324 wpas_p2p_reconsider_moving_go
,
9329 wpas_p2p_consider_moving_one_go(ifs
, freqs
, num
);
9334 void wpas_p2p_indicate_state_change(struct wpa_supplicant
*wpa_s
)
9336 if (wpa_s
->global
->p2p_disabled
|| wpa_s
->global
->p2p
== NULL
)
9339 wpas_p2p_update_channel_list(wpa_s
,
9340 WPAS_P2P_CHANNEL_UPDATE_STATE_CHANGE
);
9344 void wpas_p2p_deinit_iface(struct wpa_supplicant
*wpa_s
)
9346 if (wpa_s
== wpa_s
->global
->p2p_init_wpa_s
&& wpa_s
->global
->p2p
) {
9347 wpa_dbg(wpa_s
, MSG_DEBUG
, "P2P: Disable P2P since removing "
9348 "the management interface is being removed");
9349 wpas_p2p_deinit_global(wpa_s
->global
);
9354 void wpas_p2p_ap_deinit(struct wpa_supplicant
*wpa_s
)
9356 if (wpa_s
->ap_iface
->bss
)
9357 wpa_s
->ap_iface
->bss
[0]->p2p_group
= NULL
;
9358 wpas_p2p_group_deinit(wpa_s
);
9362 int wpas_p2p_lo_start(struct wpa_supplicant
*wpa_s
, unsigned int freq
,
9363 unsigned int period
, unsigned int interval
,
9366 struct p2p_data
*p2p
= wpa_s
->global
->p2p
;
9368 size_t dev_types_len
;
9372 if (wpa_s
->p2p_lo_started
) {
9373 wpa_dbg(wpa_s
, MSG_DEBUG
,
9374 "P2P Listen offload is already started");
9378 if (wpa_s
->global
->p2p
== NULL
||
9379 !(wpa_s
->drv_flags
& WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD
)) {
9380 wpa_printf(MSG_DEBUG
, "P2P: Listen offload not supported");
9384 if (!p2p_supported_freq(wpa_s
->global
->p2p
, freq
)) {
9385 wpa_printf(MSG_ERROR
, "P2P: Input channel not supported: %u",
9390 /* Get device type */
9391 dev_types_len
= (wpa_s
->conf
->num_sec_device_types
+ 1) *
9393 device_types
= os_malloc(dev_types_len
);
9396 os_memcpy(device_types
, wpa_s
->conf
->device_type
, WPS_DEV_TYPE_LEN
);
9397 os_memcpy(&device_types
[WPS_DEV_TYPE_LEN
], wpa_s
->conf
->sec_device_type
,
9398 wpa_s
->conf
->num_sec_device_types
* WPS_DEV_TYPE_LEN
);
9400 /* Get Probe Response IE(s) */
9401 buf
= p2p_build_probe_resp_template(p2p
, freq
);
9403 os_free(device_types
);
9407 ret
= wpa_drv_p2p_lo_start(wpa_s
, freq
, period
, interval
, count
,
9408 device_types
, dev_types_len
,
9409 wpabuf_mhead_u8(buf
), wpabuf_len(buf
));
9411 wpa_dbg(wpa_s
, MSG_DEBUG
,
9412 "P2P: Failed to start P2P listen offload");
9414 os_free(device_types
);
9418 wpa_s
->p2p_lo_started
= 1;
9420 /* Stop current P2P listen if any */
9421 wpas_stop_listen(wpa_s
);
9428 int wpas_p2p_lo_stop(struct wpa_supplicant
*wpa_s
)
9432 if (!wpa_s
->p2p_lo_started
)
9435 ret
= wpa_drv_p2p_lo_stop(wpa_s
);
9437 wpa_dbg(wpa_s
, MSG_DEBUG
,
9438 "P2P: Failed to stop P2P listen offload");
9440 wpa_s
->p2p_lo_started
= 0;