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
50 #ifndef P2P_MAX_CLIENT_IDLE
52 * How many seconds to try to reconnect to the GO when connection in P2P client
55 #define P2P_MAX_CLIENT_IDLE 10
56 #endif /* P2P_MAX_CLIENT_IDLE */
58 #ifndef P2P_MAX_INITIAL_CONN_WAIT
60 * How many seconds to wait for initial 4-way handshake to get completed after
61 * WPS provisioning step or after the re-invocation of a persistent group on a
64 #define P2P_MAX_INITIAL_CONN_WAIT 10
65 #endif /* P2P_MAX_INITIAL_CONN_WAIT */
67 #ifndef P2P_MAX_INITIAL_CONN_WAIT_GO
69 * How many seconds to wait for initial 4-way handshake to get completed after
70 * WPS provisioning step on the GO. This controls the extra time the P2P
71 * operation is considered to be in progress (e.g., to delay other scans) after
72 * WPS provisioning has been completed on the GO during group formation.
74 #define P2P_MAX_INITIAL_CONN_WAIT_GO 10
75 #endif /* P2P_MAX_INITIAL_CONN_WAIT_GO */
77 #ifndef P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE
79 * How many seconds to wait for initial 4-way handshake to get completed after
80 * re-invocation of a persistent group on the GO when the client is expected
81 * to connect automatically (no user interaction).
83 #define P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE 15
84 #endif /* P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE */
86 #define P2P_MGMT_DEVICE_PREFIX "p2p-dev-"
88 enum p2p_group_removal_reason {
89 P2P_GROUP_REMOVAL_UNKNOWN,
90 P2P_GROUP_REMOVAL_SILENT,
91 P2P_GROUP_REMOVAL_FORMATION_FAILED,
92 P2P_GROUP_REMOVAL_REQUESTED,
93 P2P_GROUP_REMOVAL_IDLE_TIMEOUT,
94 P2P_GROUP_REMOVAL_UNAVAILABLE,
95 P2P_GROUP_REMOVAL_GO_ENDING_SESSION,
96 P2P_GROUP_REMOVAL_PSK_FAILURE,
97 P2P_GROUP_REMOVAL_FREQ_CONFLICT
101 static void wpas_p2p_long_listen_timeout(void *eloop_ctx, void *timeout_ctx);
102 static struct wpa_supplicant *
103 wpas_p2p_get_group_iface(struct wpa_supplicant *wpa_s, int addr_allocated,
105 static int wpas_p2p_join_start(struct wpa_supplicant *wpa_s, int freq,
106 const u8 *ssid, size_t ssid_len);
107 static void wpas_p2p_join_scan_req(struct wpa_supplicant *wpa_s, int freq,
108 const u8 *ssid, size_t ssid_len);
109 static void wpas_p2p_join_scan(void *eloop_ctx, void *timeout_ctx);
110 static int wpas_p2p_join(struct wpa_supplicant *wpa_s, const u8 *iface_addr,
111 const u8 *dev_addr, enum p2p_wps_method wps_method,
112 int auto_join, int freq,
113 const u8 *ssid, size_t ssid_len);
114 static int wpas_p2p_create_iface(struct wpa_supplicant *wpa_s);
115 static void wpas_p2p_cross_connect_setup(struct wpa_supplicant *wpa_s);
116 static void wpas_p2p_group_idle_timeout(void *eloop_ctx, void *timeout_ctx);
117 static void wpas_p2p_set_group_idle_timeout(struct wpa_supplicant *wpa_s);
118 static void wpas_p2p_group_formation_timeout(void *eloop_ctx,
120 static void wpas_p2p_group_freq_conflict(void *eloop_ctx, void *timeout_ctx);
121 static int wpas_p2p_fallback_to_go_neg(struct wpa_supplicant *wpa_s,
123 static void wpas_p2p_stop_find_oper(struct wpa_supplicant *wpa_s);
124 static void wpas_stop_listen(void *ctx);
125 static void wpas_p2p_psk_failure_removal(void *eloop_ctx, void *timeout_ctx);
126 static void wpas_p2p_group_deinit(struct wpa_supplicant *wpa_s);
127 static int wpas_p2p_add_group_interface(struct wpa_supplicant *wpa_s,
128 enum wpa_driver_if_type type);
129 static void wpas_p2p_group_formation_failed(struct wpa_supplicant *wpa_s,
130 int already_deleted);
134 * Get the number of concurrent channels that the HW can operate, but that are
135 * currently not in use by any of the wpa_supplicant interfaces.
137 static int wpas_p2p_num_unused_channels(struct wpa_supplicant *wpa_s)
142 freqs = os_calloc(wpa_s->num_multichan_concurrent, sizeof(int));
146 num = get_shared_radio_freqs(wpa_s, freqs,
147 wpa_s->num_multichan_concurrent);
150 unused = wpa_s->num_multichan_concurrent - num;
151 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: num_unused_channels: %d", unused);
157 * Get the frequencies that are currently in use by one or more of the virtual
158 * interfaces, and that are also valid for P2P operation.
161 wpas_p2p_valid_oper_freqs(struct wpa_supplicant *wpa_s,
162 struct wpa_used_freq_data *p2p_freqs,
165 struct wpa_used_freq_data *freqs;
166 unsigned int num, i, j;
168 freqs = os_calloc(wpa_s->num_multichan_concurrent,
169 sizeof(struct wpa_used_freq_data));
173 num = get_shared_radio_freqs_data(wpa_s, freqs,
174 wpa_s->num_multichan_concurrent);
176 os_memset(p2p_freqs, 0, sizeof(struct wpa_used_freq_data) * len);
178 for (i = 0, j = 0; i < num && j < len; i++) {
179 if (p2p_supported_freq(wpa_s->global->p2p, freqs[i].freq))
180 p2p_freqs[j++] = freqs[i];
185 dump_freq_data(wpa_s, "valid for P2P", p2p_freqs, j);
191 static void wpas_p2p_set_own_freq_preference(struct wpa_supplicant *wpa_s,
194 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
197 /* Use the wpa_s used to control the P2P Device operation */
198 wpa_s = wpa_s->global->p2p_init_wpa_s;
200 if (wpa_s->conf->p2p_ignore_shared_freq &&
201 freq > 0 && wpa_s->num_multichan_concurrent > 1 &&
202 wpas_p2p_num_unused_channels(wpa_s) > 0) {
203 wpa_printf(MSG_DEBUG, "P2P: Ignore own channel preference %d MHz due to p2p_ignore_shared_freq=1 configuration",
207 p2p_set_own_freq_preference(wpa_s->global->p2p, freq);
211 static void wpas_p2p_scan_res_handler(struct wpa_supplicant *wpa_s,
212 struct wpa_scan_results *scan_res)
216 if (wpa_s->p2p_scan_work) {
217 struct wpa_radio_work *work = wpa_s->p2p_scan_work;
218 wpa_s->p2p_scan_work = NULL;
219 radio_work_done(work);
222 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
225 wpa_printf(MSG_DEBUG, "P2P: Scan results received (%d BSS)",
226 (int) scan_res->num);
228 for (i = 0; i < scan_res->num; i++) {
229 struct wpa_scan_res *bss = scan_res->res[i];
230 struct os_reltime time_tmp_age, entry_ts;
234 time_tmp_age.sec = bss->age / 1000;
235 time_tmp_age.usec = (bss->age % 1000) * 1000;
236 os_reltime_sub(&scan_res->fetch_time, &time_tmp_age, &entry_ts);
238 ies = (const u8 *) (bss + 1);
239 ies_len = bss->ie_len;
240 if (bss->beacon_ie_len > 0 &&
241 !wpa_scan_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
242 wpa_scan_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
243 wpa_printf(MSG_DEBUG, "P2P: Use P2P IE(s) from Beacon frame since no P2P IE(s) in Probe Response frames received for "
244 MACSTR, MAC2STR(bss->bssid));
246 ies_len = bss->beacon_ie_len;
250 if (p2p_scan_res_handler(wpa_s->global->p2p, bss->bssid,
251 bss->freq, &entry_ts, bss->level,
256 p2p_scan_res_handled(wpa_s->global->p2p);
260 static void wpas_p2p_trigger_scan_cb(struct wpa_radio_work *work, int deinit)
262 struct wpa_supplicant *wpa_s = work->wpa_s;
263 struct wpa_driver_scan_params *params = work->ctx;
267 if (!work->started) {
268 wpa_scan_free_params(params);
272 wpa_s->p2p_scan_work = NULL;
276 ret = wpa_drv_scan(wpa_s, params);
277 wpa_scan_free_params(params);
280 radio_work_done(work);
281 p2p_notify_scan_trigger_status(wpa_s->global->p2p, ret);
285 p2p_notify_scan_trigger_status(wpa_s->global->p2p, ret);
286 os_get_reltime(&wpa_s->scan_trigger_time);
287 wpa_s->scan_res_handler = wpas_p2p_scan_res_handler;
288 wpa_s->own_scan_requested = 1;
289 wpa_s->p2p_scan_work = work;
293 static int wpas_p2p_search_social_channel(struct wpa_supplicant *wpa_s,
296 if (wpa_s->global->p2p_24ghz_social_channels &&
297 (freq == 2412 || freq == 2437 || freq == 2462)) {
299 * Search all social channels regardless of whether these have
300 * been disabled for P2P operating channel use to avoid missing
305 return p2p_supported_freq(wpa_s->global->p2p, freq);
309 static int wpas_p2p_scan(void *ctx, enum p2p_scan_type type, int freq,
310 unsigned int num_req_dev_types,
311 const u8 *req_dev_types, const u8 *dev_id, u16 pw_id)
313 struct wpa_supplicant *wpa_s = ctx;
314 struct wpa_driver_scan_params *params = NULL;
315 struct wpabuf *wps_ie, *ies;
316 unsigned int num_channels = 0;
317 int social_channels_freq[] = { 2412, 2437, 2462, 60480 };
321 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
324 if (wpa_s->p2p_scan_work) {
325 wpa_dbg(wpa_s, MSG_INFO, "P2P: Reject scan trigger since one is already pending");
329 params = os_zalloc(sizeof(*params));
333 /* P2P Wildcard SSID */
334 params->num_ssids = 1;
335 n = os_malloc(P2P_WILDCARD_SSID_LEN);
338 os_memcpy(n, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN);
339 params->ssids[0].ssid = n;
340 params->ssids[0].ssid_len = P2P_WILDCARD_SSID_LEN;
342 wpa_s->wps->dev.p2p = 1;
343 wps_ie = wps_build_probe_req_ie(pw_id, &wpa_s->wps->dev,
344 wpa_s->wps->uuid, WPS_REQ_ENROLLEE,
345 num_req_dev_types, req_dev_types);
349 ielen = p2p_scan_ie_buf_len(wpa_s->global->p2p);
350 ies = wpabuf_alloc(wpabuf_len(wps_ie) + ielen);
355 wpabuf_put_buf(ies, wps_ie);
358 p2p_scan_ie(wpa_s->global->p2p, ies, dev_id);
360 params->p2p_probe = 1;
361 n = os_malloc(wpabuf_len(ies));
366 os_memcpy(n, wpabuf_head(ies), wpabuf_len(ies));
367 params->extra_ies = n;
368 params->extra_ies_len = wpabuf_len(ies);
372 case P2P_SCAN_SOCIAL:
373 params->freqs = os_calloc(ARRAY_SIZE(social_channels_freq) + 1,
375 if (params->freqs == NULL)
377 for (i = 0; i < ARRAY_SIZE(social_channels_freq); i++) {
378 if (wpas_p2p_search_social_channel(
379 wpa_s, social_channels_freq[i]))
380 params->freqs[num_channels++] =
381 social_channels_freq[i];
383 params->freqs[num_channels++] = 0;
387 case P2P_SCAN_SPECIFIC:
388 params->freqs = os_calloc(2, sizeof(int));
389 if (params->freqs == NULL)
391 params->freqs[0] = freq;
392 params->freqs[1] = 0;
394 case P2P_SCAN_SOCIAL_PLUS_ONE:
395 params->freqs = os_calloc(ARRAY_SIZE(social_channels_freq) + 2,
397 if (params->freqs == NULL)
399 for (i = 0; i < ARRAY_SIZE(social_channels_freq); i++) {
400 if (wpas_p2p_search_social_channel(
401 wpa_s, social_channels_freq[i]))
402 params->freqs[num_channels++] =
403 social_channels_freq[i];
405 if (p2p_supported_freq(wpa_s->global->p2p, freq))
406 params->freqs[num_channels++] = freq;
407 params->freqs[num_channels++] = 0;
411 radio_remove_works(wpa_s, "p2p-scan", 0);
412 if (radio_add_work(wpa_s, 0, "p2p-scan", 0, wpas_p2p_trigger_scan_cb,
418 wpa_scan_free_params(params);
423 static enum wpa_driver_if_type wpas_p2p_if_type(int p2p_group_interface)
425 switch (p2p_group_interface) {
426 case P2P_GROUP_INTERFACE_PENDING:
427 return WPA_IF_P2P_GROUP;
428 case P2P_GROUP_INTERFACE_GO:
429 return WPA_IF_P2P_GO;
430 case P2P_GROUP_INTERFACE_CLIENT:
431 return WPA_IF_P2P_CLIENT;
434 return WPA_IF_P2P_GROUP;
438 static struct wpa_supplicant * wpas_get_p2p_group(struct wpa_supplicant *wpa_s,
440 size_t ssid_len, int *go)
444 for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) {
445 for (s = wpa_s->conf->ssid; s; s = s->next) {
446 if (s->disabled != 0 || !s->p2p_group ||
447 s->ssid_len != ssid_len ||
448 os_memcmp(ssid, s->ssid, ssid_len) != 0)
450 if (s->mode == WPAS_MODE_P2P_GO &&
451 s != wpa_s->current_ssid)
454 *go = s->mode == WPAS_MODE_P2P_GO;
463 static void run_wpas_p2p_disconnect(void *eloop_ctx, void *timeout_ctx)
465 struct wpa_supplicant *wpa_s = eloop_ctx;
466 wpa_printf(MSG_DEBUG,
467 "P2P: Complete previously requested removal of %s",
469 wpas_p2p_disconnect(wpa_s);
473 static int wpas_p2p_disconnect_safely(struct wpa_supplicant *wpa_s,
474 struct wpa_supplicant *calling_wpa_s)
476 if (calling_wpa_s == wpa_s && wpa_s &&
477 wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE) {
479 * The calling wpa_s instance is going to be removed. Do that
480 * from an eloop callback to keep the instance available until
481 * the caller has returned. This my be needed, e.g., to provide
482 * control interface responses on the per-interface socket.
484 if (eloop_register_timeout(0, 0, run_wpas_p2p_disconnect,
490 return wpas_p2p_disconnect(wpa_s);
494 /* Determine total number of clients in active groups where we are the GO */
495 static unsigned int p2p_group_go_member_count(struct wpa_supplicant *wpa_s)
497 unsigned int count = 0;
500 for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) {
501 for (s = wpa_s->conf->ssid; s; s = s->next) {
502 wpa_printf(MSG_DEBUG,
503 "P2P: sup:%p ssid:%p disabled:%d p2p:%d mode:%d",
504 wpa_s, s, s->disabled, s->p2p_group,
506 if (!s->disabled && s->p2p_group &&
507 s->mode == WPAS_MODE_P2P_GO) {
508 count += p2p_get_group_num_members(
518 /* Find an interface for a P2P group where we are the GO */
519 static struct wpa_supplicant *
520 wpas_p2p_get_go_group(struct wpa_supplicant *wpa_s)
522 struct wpa_supplicant *save = NULL;
528 for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) {
529 for (s = wpa_s->conf->ssid; s; s = s->next) {
530 if (s->disabled || !s->p2p_group ||
531 s->mode != WPAS_MODE_P2P_GO)
534 /* Prefer a group with connected clients */
535 if (p2p_get_group_num_members(wpa_s->p2p_group))
541 /* No group with connected clients, so pick the one without (if any) */
546 /* Find an active P2P group where we are the GO */
547 static struct wpa_ssid * wpas_p2p_group_go_ssid(struct wpa_supplicant *wpa_s,
550 struct wpa_ssid *s, *empty = NULL;
555 for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) {
556 for (s = wpa_s->conf->ssid; s; s = s->next) {
557 if (s->disabled || !s->p2p_group ||
558 s->mode != WPAS_MODE_P2P_GO)
561 os_memcpy(bssid, wpa_s->own_addr, ETH_ALEN);
562 if (p2p_get_group_num_members(wpa_s->p2p_group))
572 /* Find a persistent group where we are the GO */
573 static struct wpa_ssid *
574 wpas_p2p_get_persistent_go(struct wpa_supplicant *wpa_s)
578 for (s = wpa_s->conf->ssid; s; s = s->next) {
579 if (s->disabled == 2 && s->mode == WPAS_MODE_P2P_GO)
587 static u8 p2ps_group_capability(void *ctx, u8 incoming, u8 role)
589 struct wpa_supplicant *wpa_s = ctx, *tmp_wpa_s;
591 u8 conncap = P2PS_SETUP_NONE;
592 unsigned int owned_members = 0;
593 unsigned int owner = 0;
594 unsigned int client = 0;
595 struct wpa_supplicant *go_wpa_s;
596 struct wpa_ssid *persistent_go;
597 int p2p_no_group_iface;
599 wpa_printf(MSG_DEBUG, "P2P: Conncap - in:%d role:%d", incoming, role);
602 * For non-concurrent capable devices:
603 * If persistent_go, then no new.
604 * If GO, then no client.
605 * If client, then no GO.
607 go_wpa_s = wpas_p2p_get_go_group(wpa_s);
608 persistent_go = wpas_p2p_get_persistent_go(wpa_s);
609 p2p_no_group_iface = wpa_s->conf->p2p_no_group_iface;
611 wpa_printf(MSG_DEBUG, "P2P: GO(iface)=%p persistent(ssid)=%p",
612 go_wpa_s, persistent_go);
614 for (tmp_wpa_s = wpa_s->global->ifaces; tmp_wpa_s;
615 tmp_wpa_s = tmp_wpa_s->next) {
616 for (s = tmp_wpa_s->conf->ssid; s; s = s->next) {
617 wpa_printf(MSG_DEBUG,
618 "P2P: sup:%p ssid:%p disabled:%d p2p:%d mode:%d",
619 tmp_wpa_s, s, s->disabled,
620 s->p2p_group, s->mode);
621 if (!s->disabled && s->p2p_group) {
622 if (s->mode == WPAS_MODE_P2P_GO) {
624 p2p_get_group_num_members(
625 tmp_wpa_s->p2p_group);
633 /* If not concurrent, restrict our choices */
634 if (p2p_no_group_iface) {
635 wpa_printf(MSG_DEBUG, "P2P: p2p_no_group_iface");
638 return P2PS_SETUP_NONE;
641 if (role == P2PS_SETUP_CLIENT ||
642 incoming == P2PS_SETUP_GROUP_OWNER ||
643 p2p_client_limit_reached(go_wpa_s->p2p_group))
644 return P2PS_SETUP_NONE;
646 return P2PS_SETUP_GROUP_OWNER;
650 if (role == P2PS_SETUP_NONE || role == P2PS_SETUP_NEW) {
652 return P2PS_SETUP_GROUP_OWNER |
654 if (incoming == P2PS_SETUP_NEW) {
657 if (os_get_random(&r, sizeof(r)) < 0 ||
659 return P2PS_SETUP_CLIENT;
660 return P2PS_SETUP_GROUP_OWNER;
666 /* If a required role has been specified, handle it here */
667 if (role && role != P2PS_SETUP_NEW) {
669 case P2PS_SETUP_NONE:
671 case P2PS_SETUP_GROUP_OWNER | P2PS_SETUP_CLIENT:
672 case P2PS_SETUP_GROUP_OWNER | P2PS_SETUP_NEW:
676 case P2PS_SETUP_GROUP_OWNER:
678 * Must be a complimentary role - cannot be a client to
679 * more than one peer.
681 if (incoming == role || client)
682 return P2PS_SETUP_NONE;
684 return P2PS_SETUP_CLIENT;
686 case P2PS_SETUP_CLIENT:
687 /* Must be a complimentary role */
688 if (incoming != role) {
689 conncap = P2PS_SETUP_GROUP_OWNER;
694 return P2PS_SETUP_NONE;
699 * For now, we only will support ownership of one group, and being a
700 * client of one group. Therefore, if we have either an existing GO
701 * group, or an existing client group, we will not do a new GO
702 * negotiation, but rather try to re-use the existing groups.
705 case P2PS_SETUP_NONE:
708 conncap = P2PS_SETUP_GROUP_OWNER;
709 else if (!owned_members)
710 conncap = P2PS_SETUP_NEW;
711 else if (incoming == P2PS_SETUP_NONE)
712 conncap = P2PS_SETUP_GROUP_OWNER | P2PS_SETUP_CLIENT;
714 conncap = P2PS_SETUP_CLIENT;
717 case P2PS_SETUP_CLIENT:
718 conncap = P2PS_SETUP_GROUP_OWNER;
721 case P2PS_SETUP_GROUP_OWNER:
723 conncap = P2PS_SETUP_CLIENT;
726 case P2PS_SETUP_GROUP_OWNER | P2PS_SETUP_NEW:
727 case P2PS_SETUP_GROUP_OWNER | P2PS_SETUP_CLIENT:
729 conncap = P2PS_SETUP_GROUP_OWNER;
733 if (os_get_random(&r, sizeof(r)) < 0 ||
735 conncap = P2PS_SETUP_CLIENT;
737 conncap = P2PS_SETUP_GROUP_OWNER;
742 return P2PS_SETUP_NONE;
746 if ((conncap & P2PS_SETUP_GROUP_OWNER) ||
747 (!incoming && (conncap & P2PS_SETUP_NEW))) {
748 if (go_wpa_s && p2p_client_limit_reached(go_wpa_s->p2p_group))
749 conncap &= ~P2PS_SETUP_GROUP_OWNER;
750 wpa_printf(MSG_DEBUG, "P2P: GOs:%d members:%d conncap:%d",
751 owner, owned_members, conncap);
753 s = wpas_p2p_get_persistent_go(wpa_s);
755 if (!s && !owner && p2p_no_group_iface) {
756 p2p_set_intended_addr(wpa_s->global->p2p,
758 } else if (!s && !owner) {
759 if (wpas_p2p_add_group_interface(wpa_s,
760 WPA_IF_P2P_GO) < 0) {
761 wpa_printf(MSG_ERROR,
762 "P2P: Failed to allocate a new interface for the group");
763 return P2PS_SETUP_NONE;
765 wpa_s->global->pending_group_iface_for_p2ps = 1;
766 p2p_set_intended_addr(wpa_s->global->p2p,
767 wpa_s->pending_interface_addr);
775 static int wpas_p2p_group_delete(struct wpa_supplicant *wpa_s,
776 enum p2p_group_removal_reason removal_reason)
778 struct wpa_ssid *ssid;
782 ssid = wpa_s->current_ssid;
785 * The current SSID was not known, but there may still be a
786 * pending P2P group interface waiting for provisioning or a
787 * P2P group that is trying to reconnect.
789 ssid = wpa_s->conf->ssid;
791 if (ssid->p2p_group && ssid->disabled != 2)
796 wpa_s->p2p_group_interface == NOT_P2P_GROUP_INTERFACE)
798 wpa_printf(MSG_ERROR, "P2P: P2P group interface "
803 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO)
805 else if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT ||
806 (ssid && ssid->mode == WPAS_MODE_INFRA)) {
807 wpa_s->reassociate = 0;
808 wpa_s->disconnected = 1;
813 if (removal_reason != P2P_GROUP_REMOVAL_SILENT && ssid)
814 wpas_notify_p2p_group_removed(wpa_s, ssid, gtype);
816 if (os_strcmp(gtype, "client") == 0) {
817 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
818 if (eloop_is_timeout_registered(wpas_p2p_psk_failure_removal,
820 wpa_printf(MSG_DEBUG,
821 "P2P: PSK failure removal was scheduled, so use PSK failure as reason for group removal");
822 removal_reason = P2P_GROUP_REMOVAL_PSK_FAILURE;
823 eloop_cancel_timeout(wpas_p2p_psk_failure_removal,
828 if (wpa_s->cross_connect_in_use) {
829 wpa_s->cross_connect_in_use = 0;
830 wpa_msg_global(wpa_s->parent, MSG_INFO,
831 P2P_EVENT_CROSS_CONNECT_DISABLE "%s %s",
832 wpa_s->ifname, wpa_s->cross_connect_uplink);
834 switch (removal_reason) {
835 case P2P_GROUP_REMOVAL_REQUESTED:
836 reason = " reason=REQUESTED";
838 case P2P_GROUP_REMOVAL_FORMATION_FAILED:
839 reason = " reason=FORMATION_FAILED";
841 case P2P_GROUP_REMOVAL_IDLE_TIMEOUT:
842 reason = " reason=IDLE";
844 case P2P_GROUP_REMOVAL_UNAVAILABLE:
845 reason = " reason=UNAVAILABLE";
847 case P2P_GROUP_REMOVAL_GO_ENDING_SESSION:
848 reason = " reason=GO_ENDING_SESSION";
850 case P2P_GROUP_REMOVAL_PSK_FAILURE:
851 reason = " reason=PSK_FAILURE";
853 case P2P_GROUP_REMOVAL_FREQ_CONFLICT:
854 reason = " reason=FREQ_CONFLICT";
860 if (removal_reason != P2P_GROUP_REMOVAL_SILENT) {
861 wpa_msg_global(wpa_s->parent, MSG_INFO,
862 P2P_EVENT_GROUP_REMOVED "%s %s%s",
863 wpa_s->ifname, gtype, reason);
866 if (eloop_cancel_timeout(wpas_p2p_group_freq_conflict, wpa_s, NULL) > 0)
867 wpa_printf(MSG_DEBUG, "P2P: Cancelled P2P group freq_conflict timeout");
868 if (eloop_cancel_timeout(wpas_p2p_group_idle_timeout, wpa_s, NULL) > 0)
869 wpa_printf(MSG_DEBUG, "P2P: Cancelled P2P group idle timeout");
870 if (eloop_cancel_timeout(wpas_p2p_group_formation_timeout,
871 wpa_s->parent, NULL) > 0) {
872 wpa_printf(MSG_DEBUG, "P2P: Cancelled P2P group formation "
874 wpa_s->p2p_in_provisioning = 0;
877 wpa_s->p2p_in_invitation = 0;
880 * Make sure wait for the first client does not remain active after the
881 * group has been removed.
883 wpa_s->global->p2p_go_wait_client.sec = 0;
885 if (wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE) {
886 struct wpa_global *global;
888 enum wpa_driver_if_type type;
889 wpa_printf(MSG_DEBUG, "P2P: Remove group interface %s",
891 global = wpa_s->global;
892 ifname = os_strdup(wpa_s->ifname);
893 type = wpas_p2p_if_type(wpa_s->p2p_group_interface);
894 eloop_cancel_timeout(run_wpas_p2p_disconnect, wpa_s, NULL);
895 wpa_supplicant_remove_iface(wpa_s->global, wpa_s, 0);
896 wpa_s = global->ifaces;
898 wpa_drv_if_remove(wpa_s, type, ifname);
903 if (!wpa_s->p2p_go_group_formation_completed) {
904 wpa_s->global->p2p_group_formation = NULL;
905 wpa_s->p2p_in_provisioning = 0;
908 wpa_s->show_group_started = 0;
909 os_free(wpa_s->go_params);
910 wpa_s->go_params = NULL;
912 os_free(wpa_s->p2p_group_common_freqs);
913 wpa_s->p2p_group_common_freqs = NULL;
914 wpa_s->p2p_group_common_freqs_num = 0;
916 wpa_s->waiting_presence_resp = 0;
918 wpa_printf(MSG_DEBUG, "P2P: Remove temporary group network");
919 if (ssid && (ssid->p2p_group ||
920 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION ||
921 (ssid->key_mgmt & WPA_KEY_MGMT_WPS))) {
923 if (ssid == wpa_s->current_ssid) {
924 wpa_sm_set_config(wpa_s->wpa, NULL);
925 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
926 wpa_s->current_ssid = NULL;
929 * Networks objects created during any P2P activities are not
930 * exposed out as they might/will confuse certain non-P2P aware
931 * applications since these network objects won't behave like
934 * Likewise, we don't send out network removed signals for such
937 wpa_config_remove_network(wpa_s->conf, id);
938 wpa_supplicant_clear_status(wpa_s);
939 wpa_supplicant_cancel_sched_scan(wpa_s);
941 wpa_printf(MSG_DEBUG, "P2P: Temporary group network not "
945 wpa_supplicant_ap_deinit(wpa_s);
947 wpa_drv_deinit_p2p_cli(wpa_s);
953 static int wpas_p2p_persistent_group(struct wpa_supplicant *wpa_s,
955 const u8 *ssid, size_t ssid_len)
963 if (wpa_s->go_params)
964 bssid = wpa_s->go_params->peer_interface_addr;
966 bssid = wpa_s->bssid;
968 bss = wpa_bss_get(wpa_s, bssid, ssid, ssid_len);
969 if (bss == NULL && wpa_s->go_params &&
970 !is_zero_ether_addr(wpa_s->go_params->peer_device_addr))
971 bss = wpa_bss_get_p2p_dev_addr(
972 wpa_s, wpa_s->go_params->peer_device_addr);
974 u8 iface_addr[ETH_ALEN];
975 if (p2p_get_interface_addr(wpa_s->global->p2p, bssid,
977 bss = wpa_bss_get(wpa_s, iface_addr, ssid, ssid_len);
980 wpa_printf(MSG_DEBUG, "P2P: Could not figure out whether "
981 "group is persistent - BSS " MACSTR " not found",
986 p2p = wpa_bss_get_vendor_ie_multi(bss, P2P_IE_VENDOR_TYPE);
988 p2p = wpa_bss_get_vendor_ie_multi_beacon(bss,
991 wpa_printf(MSG_DEBUG, "P2P: Could not figure out whether "
992 "group is persistent - BSS " MACSTR
993 " did not include P2P IE", MAC2STR(bssid));
994 wpa_hexdump(MSG_DEBUG, "P2P: Probe Response IEs",
995 (u8 *) (bss + 1), bss->ie_len);
996 wpa_hexdump(MSG_DEBUG, "P2P: Beacon IEs",
997 ((u8 *) bss + 1) + bss->ie_len,
1002 group_capab = p2p_get_group_capab(p2p);
1003 addr = p2p_get_go_dev_addr(p2p);
1004 wpa_printf(MSG_DEBUG, "P2P: Checking whether group is persistent: "
1005 "group_capab=0x%x", group_capab);
1007 os_memcpy(go_dev_addr, addr, ETH_ALEN);
1008 wpa_printf(MSG_DEBUG, "P2P: GO Device Address " MACSTR,
1011 os_memset(go_dev_addr, 0, ETH_ALEN);
1014 wpa_printf(MSG_DEBUG, "P2P: BSS " MACSTR " group_capab=0x%x "
1015 "go_dev_addr=" MACSTR,
1016 MAC2STR(bssid), group_capab, MAC2STR(go_dev_addr));
1018 return group_capab & P2P_GROUP_CAPAB_PERSISTENT_GROUP;
1022 static int wpas_p2p_store_persistent_group(struct wpa_supplicant *wpa_s,
1023 struct wpa_ssid *ssid,
1024 const u8 *go_dev_addr)
1029 wpa_printf(MSG_DEBUG, "P2P: Storing credentials for a persistent "
1030 "group (GO Dev Addr " MACSTR ")", MAC2STR(go_dev_addr));
1031 for (s = wpa_s->conf->ssid; s; s = s->next) {
1032 if (s->disabled == 2 &&
1033 os_memcmp(go_dev_addr, s->bssid, ETH_ALEN) == 0 &&
1034 s->ssid_len == ssid->ssid_len &&
1035 os_memcmp(ssid->ssid, s->ssid, ssid->ssid_len) == 0)
1040 wpa_printf(MSG_DEBUG, "P2P: Update existing persistent group "
1042 if (ssid->passphrase && !s->passphrase)
1044 else if (ssid->passphrase && s->passphrase &&
1045 os_strcmp(ssid->passphrase, s->passphrase) != 0)
1048 wpa_printf(MSG_DEBUG, "P2P: Create a new persistent group "
1051 s = wpa_config_add_network(wpa_s->conf);
1056 * Instead of network_added we emit persistent_group_added
1057 * notification. Also to keep the defense checks in
1058 * persistent_group obj registration method, we set the
1059 * relevant flags in s to designate it as a persistent group.
1062 s->p2p_persistent_group = 1;
1063 wpas_notify_persistent_group_added(wpa_s, s);
1064 wpa_config_set_network_defaults(s);
1068 s->p2p_persistent_group = 1;
1071 os_memcpy(s->bssid, go_dev_addr, ETH_ALEN);
1072 s->mode = ssid->mode;
1073 s->auth_alg = WPA_AUTH_ALG_OPEN;
1074 s->key_mgmt = WPA_KEY_MGMT_PSK;
1075 s->proto = WPA_PROTO_RSN;
1076 s->pairwise_cipher = WPA_CIPHER_CCMP;
1078 if (ssid->passphrase) {
1079 os_free(s->passphrase);
1080 s->passphrase = os_strdup(ssid->passphrase);
1082 if (ssid->psk_set) {
1084 os_memcpy(s->psk, ssid->psk, 32);
1086 if (s->passphrase && !s->psk_set)
1087 wpa_config_update_psk(s);
1088 if (s->ssid == NULL || s->ssid_len < ssid->ssid_len) {
1090 s->ssid = os_malloc(ssid->ssid_len);
1093 s->ssid_len = ssid->ssid_len;
1094 os_memcpy(s->ssid, ssid->ssid, s->ssid_len);
1096 if (ssid->mode == WPAS_MODE_P2P_GO && wpa_s->global->add_psk) {
1097 dl_list_add(&s->psk_list, &wpa_s->global->add_psk->list);
1098 wpa_s->global->add_psk = NULL;
1102 if (changed && wpa_s->conf->update_config &&
1103 wpa_config_write(wpa_s->confname, wpa_s->conf)) {
1104 wpa_printf(MSG_DEBUG, "P2P: Failed to update configuration");
1111 static void wpas_p2p_add_persistent_group_client(struct wpa_supplicant *wpa_s,
1114 struct wpa_ssid *ssid, *s;
1118 struct wpa_supplicant *p2p_wpa_s = wpa_s->global->p2p_init_wpa_s;
1120 ssid = wpa_s->current_ssid;
1121 if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO ||
1122 !ssid->p2p_persistent_group)
1125 for (s = p2p_wpa_s->conf->ssid; s; s = s->next) {
1126 if (s->disabled != 2 || s->mode != WPAS_MODE_P2P_GO)
1129 if (s->ssid_len == ssid->ssid_len &&
1130 os_memcmp(s->ssid, ssid->ssid, s->ssid_len) == 0)
1137 for (i = 0; s->p2p_client_list && i < s->num_p2p_clients; i++) {
1138 if (os_memcmp(s->p2p_client_list + i * 2 * ETH_ALEN, addr,
1142 if (i == s->num_p2p_clients - 1)
1143 return; /* already the most recent entry */
1145 /* move the entry to mark it most recent */
1146 os_memmove(s->p2p_client_list + i * 2 * ETH_ALEN,
1147 s->p2p_client_list + (i + 1) * 2 * ETH_ALEN,
1148 (s->num_p2p_clients - i - 1) * 2 * ETH_ALEN);
1149 os_memcpy(s->p2p_client_list +
1150 (s->num_p2p_clients - 1) * 2 * ETH_ALEN, addr,
1152 os_memset(s->p2p_client_list +
1153 (s->num_p2p_clients - 1) * 2 * ETH_ALEN + ETH_ALEN,
1159 if (!found && s->num_p2p_clients < P2P_MAX_STORED_CLIENTS) {
1160 n = os_realloc_array(s->p2p_client_list,
1161 s->num_p2p_clients + 1, 2 * ETH_ALEN);
1164 os_memcpy(n + s->num_p2p_clients * 2 * ETH_ALEN, addr,
1166 os_memset(n + s->num_p2p_clients * 2 * ETH_ALEN + ETH_ALEN,
1168 s->p2p_client_list = n;
1169 s->num_p2p_clients++;
1170 } else if (!found && s->p2p_client_list) {
1171 /* Not enough room for an additional entry - drop the oldest
1173 os_memmove(s->p2p_client_list,
1174 s->p2p_client_list + 2 * ETH_ALEN,
1175 (s->num_p2p_clients - 1) * 2 * ETH_ALEN);
1176 os_memcpy(s->p2p_client_list +
1177 (s->num_p2p_clients - 1) * 2 * ETH_ALEN,
1179 os_memset(s->p2p_client_list +
1180 (s->num_p2p_clients - 1) * 2 * ETH_ALEN + ETH_ALEN,
1184 if (p2p_wpa_s->conf->update_config &&
1185 wpa_config_write(p2p_wpa_s->confname, p2p_wpa_s->conf))
1186 wpa_printf(MSG_DEBUG, "P2P: Failed to update configuration");
1190 static void wpas_p2p_group_started(struct wpa_supplicant *wpa_s,
1191 int go, struct wpa_ssid *ssid, int freq,
1192 const u8 *psk, const char *passphrase,
1193 const u8 *go_dev_addr, int persistent,
1196 const char *ssid_txt;
1200 wpa_snprintf_hex(psk_txt, sizeof(psk_txt), psk, 32);
1205 ssid_txt = wpa_ssid_txt(ssid->ssid, ssid->ssid_len);
1209 if (passphrase && passphrase[0] == '\0')
1213 * Include PSK/passphrase only in the control interface message and
1214 * leave it out from the debug log entry.
1216 wpa_msg_global_ctrl(wpa_s->parent, MSG_INFO,
1217 P2P_EVENT_GROUP_STARTED
1218 "%s %s ssid=\"%s\" freq=%d%s%s%s%s%s go_dev_addr="
1220 wpa_s->ifname, go ? "GO" : "client", ssid_txt, freq,
1221 psk ? " psk=" : "", psk_txt,
1222 passphrase ? " passphrase=\"" : "",
1223 passphrase ? passphrase : "",
1224 passphrase ? "\"" : "",
1225 MAC2STR(go_dev_addr),
1226 persistent ? " [PERSISTENT]" : "", extra);
1227 wpa_printf(MSG_INFO, P2P_EVENT_GROUP_STARTED
1228 "%s %s ssid=\"%s\" freq=%d go_dev_addr=" MACSTR "%s%s",
1229 wpa_s->ifname, go ? "GO" : "client", ssid_txt, freq,
1230 MAC2STR(go_dev_addr), persistent ? " [PERSISTENT]" : "",
1235 static void wpas_group_formation_completed(struct wpa_supplicant *wpa_s,
1236 int success, int already_deleted)
1238 struct wpa_ssid *ssid;
1241 u8 go_dev_addr[ETH_ALEN];
1242 int network_id = -1;
1245 * This callback is likely called for the main interface. Update wpa_s
1246 * to use the group interface if a new interface was created for the
1249 if (wpa_s->global->p2p_group_formation)
1250 wpa_s = wpa_s->global->p2p_group_formation;
1251 if (wpa_s->p2p_go_group_formation_completed) {
1252 wpa_s->global->p2p_group_formation = NULL;
1253 wpa_s->p2p_in_provisioning = 0;
1255 wpa_s->p2p_in_invitation = 0;
1256 wpa_s->group_formation_reported = 1;
1259 wpa_msg_global(wpa_s->parent, MSG_INFO,
1260 P2P_EVENT_GROUP_FORMATION_FAILURE);
1261 if (already_deleted)
1263 wpas_p2p_group_delete(wpa_s,
1264 P2P_GROUP_REMOVAL_FORMATION_FAILED);
1268 wpa_msg_global(wpa_s->parent, MSG_INFO,
1269 P2P_EVENT_GROUP_FORMATION_SUCCESS);
1271 ssid = wpa_s->current_ssid;
1272 if (ssid && ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION) {
1273 ssid->mode = WPAS_MODE_P2P_GO;
1274 p2p_group_notif_formation_done(wpa_s->p2p_group);
1275 wpa_supplicant_ap_mac_addr_filter(wpa_s, NULL);
1280 client = ssid->mode == WPAS_MODE_INFRA;
1281 if (ssid->mode == WPAS_MODE_P2P_GO) {
1282 persistent = ssid->p2p_persistent_group;
1283 os_memcpy(go_dev_addr, wpa_s->global->p2p_dev_addr,
1286 persistent = wpas_p2p_persistent_group(wpa_s,
1291 client = wpa_s->p2p_group_interface ==
1292 P2P_GROUP_INTERFACE_CLIENT;
1293 os_memset(go_dev_addr, 0, ETH_ALEN);
1296 wpa_s->show_group_started = 0;
1299 * Indicate event only after successfully completed 4-way
1300 * handshake, i.e., when the interface is ready for data
1303 wpa_s->show_group_started = 1;
1305 wpas_p2p_group_started(wpa_s, 1, ssid,
1306 ssid ? ssid->frequency : 0,
1307 ssid && ssid->passphrase == NULL &&
1308 ssid->psk_set ? ssid->psk : NULL,
1309 ssid ? ssid->passphrase : NULL,
1310 go_dev_addr, persistent, "");
1311 wpas_p2p_cross_connect_setup(wpa_s);
1312 wpas_p2p_set_group_idle_timeout(wpa_s);
1316 network_id = wpas_p2p_store_persistent_group(wpa_s->parent,
1319 os_free(wpa_s->global->add_psk);
1320 wpa_s->global->add_psk = NULL;
1322 if (network_id < 0 && ssid)
1323 network_id = ssid->id;
1325 wpas_notify_p2p_group_started(wpa_s, ssid, network_id, 0);
1326 os_get_reltime(&wpa_s->global->p2p_go_wait_client);
1331 struct send_action_work {
1337 unsigned int wait_time;
1342 static void wpas_p2p_send_action_work_timeout(void *eloop_ctx,
1345 struct wpa_supplicant *wpa_s = eloop_ctx;
1347 if (!wpa_s->p2p_send_action_work)
1350 wpa_printf(MSG_DEBUG, "P2P: Send Action frame radio work timed out");
1351 os_free(wpa_s->p2p_send_action_work->ctx);
1352 radio_work_done(wpa_s->p2p_send_action_work);
1353 wpa_s->p2p_send_action_work = NULL;
1357 static void wpas_p2p_action_tx_clear(struct wpa_supplicant *wpa_s)
1359 if (wpa_s->p2p_send_action_work) {
1360 struct send_action_work *awork;
1361 awork = wpa_s->p2p_send_action_work->ctx;
1362 if (awork->wait_time == 0) {
1364 radio_work_done(wpa_s->p2p_send_action_work);
1365 wpa_s->p2p_send_action_work = NULL;
1368 * In theory, this should not be needed, but number of
1369 * places in the P2P code is still using non-zero wait
1370 * time for the last Action frame in the sequence and
1371 * some of these do not call send_action_done().
1373 eloop_cancel_timeout(wpas_p2p_send_action_work_timeout,
1375 eloop_register_timeout(
1376 0, awork->wait_time * 1000,
1377 wpas_p2p_send_action_work_timeout,
1384 static void wpas_p2p_send_action_tx_status(struct wpa_supplicant *wpa_s,
1386 const u8 *dst, const u8 *src,
1388 const u8 *data, size_t data_len,
1389 enum offchannel_send_action_result
1392 enum p2p_send_action_result res = P2P_SEND_ACTION_SUCCESS;
1394 wpas_p2p_action_tx_clear(wpa_s);
1396 if (wpa_s->global->p2p == NULL || wpa_s->global->p2p_disabled)
1400 case OFFCHANNEL_SEND_ACTION_SUCCESS:
1401 res = P2P_SEND_ACTION_SUCCESS;
1403 case OFFCHANNEL_SEND_ACTION_NO_ACK:
1404 res = P2P_SEND_ACTION_NO_ACK;
1406 case OFFCHANNEL_SEND_ACTION_FAILED:
1407 res = P2P_SEND_ACTION_FAILED;
1411 p2p_send_action_cb(wpa_s->global->p2p, freq, dst, src, bssid, res);
1413 if (result != OFFCHANNEL_SEND_ACTION_SUCCESS &&
1414 wpa_s->pending_pd_before_join &&
1415 (os_memcmp(dst, wpa_s->pending_join_dev_addr, ETH_ALEN) == 0 ||
1416 os_memcmp(dst, wpa_s->pending_join_iface_addr, ETH_ALEN) == 0) &&
1417 wpa_s->p2p_fallback_to_go_neg) {
1418 wpa_s->pending_pd_before_join = 0;
1419 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: No ACK for PD Req "
1420 "during p2p_connect-auto");
1421 wpa_msg_global(wpa_s->parent, MSG_INFO,
1422 P2P_EVENT_FALLBACK_TO_GO_NEG
1423 "reason=no-ACK-to-PD-Req");
1424 wpas_p2p_fallback_to_go_neg(wpa_s, 0);
1430 static void wpas_send_action_cb(struct wpa_radio_work *work, int deinit)
1432 struct wpa_supplicant *wpa_s = work->wpa_s;
1433 struct send_action_work *awork = work->ctx;
1436 if (work->started) {
1437 eloop_cancel_timeout(wpas_p2p_send_action_work_timeout,
1439 wpa_s->p2p_send_action_work = NULL;
1440 offchannel_send_action_done(wpa_s);
1446 if (offchannel_send_action(wpa_s, awork->freq, awork->dst, awork->src,
1447 awork->bssid, awork->buf, awork->len,
1449 wpas_p2p_send_action_tx_status, 1) < 0) {
1451 radio_work_done(work);
1454 wpa_s->p2p_send_action_work = work;
1458 static int wpas_send_action_work(struct wpa_supplicant *wpa_s,
1459 unsigned int freq, const u8 *dst,
1460 const u8 *src, const u8 *bssid, const u8 *buf,
1461 size_t len, unsigned int wait_time)
1463 struct send_action_work *awork;
1465 if (wpa_s->p2p_send_action_work) {
1466 wpa_printf(MSG_DEBUG, "P2P: Cannot schedule new p2p-send-action work since one is already pending");
1470 awork = os_zalloc(sizeof(*awork) + len);
1475 os_memcpy(awork->dst, dst, ETH_ALEN);
1476 os_memcpy(awork->src, src, ETH_ALEN);
1477 os_memcpy(awork->bssid, bssid, ETH_ALEN);
1479 awork->wait_time = wait_time;
1480 os_memcpy(awork->buf, buf, len);
1482 if (radio_add_work(wpa_s, freq, "p2p-send-action", 0,
1483 wpas_send_action_cb, awork) < 0) {
1492 static int wpas_send_action(void *ctx, unsigned int freq, const u8 *dst,
1493 const u8 *src, const u8 *bssid, const u8 *buf,
1494 size_t len, unsigned int wait_time)
1496 struct wpa_supplicant *wpa_s = ctx;
1497 int listen_freq = -1, send_freq = -1;
1499 if (wpa_s->p2p_listen_work)
1500 listen_freq = wpa_s->p2p_listen_work->freq;
1501 if (wpa_s->p2p_send_action_work)
1502 send_freq = wpa_s->p2p_send_action_work->freq;
1503 if (listen_freq != (int) freq && send_freq != (int) freq) {
1504 wpa_printf(MSG_DEBUG, "P2P: Schedule new radio work for Action frame TX (listen_freq=%d send_freq=%d)",
1505 listen_freq, send_freq);
1506 return wpas_send_action_work(wpa_s, freq, dst, src, bssid, buf,
1510 wpa_printf(MSG_DEBUG, "P2P: Use ongoing radio work for Action frame TX");
1511 return offchannel_send_action(wpa_s, freq, dst, src, bssid, buf, len,
1513 wpas_p2p_send_action_tx_status, 1);
1517 static void wpas_send_action_done(void *ctx)
1519 struct wpa_supplicant *wpa_s = ctx;
1521 if (wpa_s->p2p_send_action_work) {
1522 eloop_cancel_timeout(wpas_p2p_send_action_work_timeout,
1524 os_free(wpa_s->p2p_send_action_work->ctx);
1525 radio_work_done(wpa_s->p2p_send_action_work);
1526 wpa_s->p2p_send_action_work = NULL;
1529 offchannel_send_action_done(wpa_s);
1533 static int wpas_copy_go_neg_results(struct wpa_supplicant *wpa_s,
1534 struct p2p_go_neg_results *params)
1536 if (wpa_s->go_params == NULL) {
1537 wpa_s->go_params = os_malloc(sizeof(*params));
1538 if (wpa_s->go_params == NULL)
1541 os_memcpy(wpa_s->go_params, params, sizeof(*params));
1546 static void wpas_start_wps_enrollee(struct wpa_supplicant *wpa_s,
1547 struct p2p_go_neg_results *res)
1549 wpa_s->group_formation_reported = 0;
1550 wpa_printf(MSG_DEBUG, "P2P: Start WPS Enrollee for peer " MACSTR
1551 " dev_addr " MACSTR " wps_method %d",
1552 MAC2STR(res->peer_interface_addr),
1553 MAC2STR(res->peer_device_addr), res->wps_method);
1554 wpa_hexdump_ascii(MSG_DEBUG, "P2P: Start WPS Enrollee for SSID",
1555 res->ssid, res->ssid_len);
1556 wpa_supplicant_ap_deinit(wpa_s);
1557 wpas_copy_go_neg_results(wpa_s, res);
1558 if (res->wps_method == WPS_PBC) {
1559 wpas_wps_start_pbc(wpa_s, res->peer_interface_addr, 1);
1560 #ifdef CONFIG_WPS_NFC
1561 } else if (res->wps_method == WPS_NFC) {
1562 wpas_wps_start_nfc(wpa_s, res->peer_device_addr,
1563 res->peer_interface_addr,
1564 wpa_s->parent->p2p_oob_dev_pw,
1565 wpa_s->parent->p2p_oob_dev_pw_id, 1,
1566 wpa_s->parent->p2p_oob_dev_pw_id ==
1567 DEV_PW_NFC_CONNECTION_HANDOVER ?
1568 wpa_s->parent->p2p_peer_oob_pubkey_hash :
1571 #endif /* CONFIG_WPS_NFC */
1573 u16 dev_pw_id = DEV_PW_DEFAULT;
1574 if (wpa_s->p2p_wps_method == WPS_P2PS)
1575 dev_pw_id = DEV_PW_P2PS_DEFAULT;
1576 if (wpa_s->p2p_wps_method == WPS_PIN_KEYPAD)
1577 dev_pw_id = DEV_PW_REGISTRAR_SPECIFIED;
1578 wpas_wps_start_pin(wpa_s, res->peer_interface_addr,
1579 wpa_s->p2p_pin, 1, dev_pw_id);
1584 static void wpas_p2p_add_psk_list(struct wpa_supplicant *wpa_s,
1585 struct wpa_ssid *ssid)
1587 struct wpa_ssid *persistent;
1588 struct psk_list_entry *psk;
1589 struct hostapd_data *hapd;
1591 if (!wpa_s->ap_iface)
1594 persistent = wpas_p2p_get_persistent(wpa_s->parent, NULL, ssid->ssid,
1596 if (persistent == NULL)
1599 hapd = wpa_s->ap_iface->bss[0];
1601 dl_list_for_each(psk, &persistent->psk_list, struct psk_list_entry,
1603 struct hostapd_wpa_psk *hpsk;
1605 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Add persistent group PSK entry for "
1607 MAC2STR(psk->addr), psk->p2p);
1608 hpsk = os_zalloc(sizeof(*hpsk));
1611 os_memcpy(hpsk->psk, psk->psk, PMK_LEN);
1613 os_memcpy(hpsk->p2p_dev_addr, psk->addr, ETH_ALEN);
1615 os_memcpy(hpsk->addr, psk->addr, ETH_ALEN);
1616 hpsk->next = hapd->conf->ssid.wpa_psk;
1617 hapd->conf->ssid.wpa_psk = hpsk;
1622 static void p2p_go_dump_common_freqs(struct wpa_supplicant *wpa_s)
1626 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Common group frequencies (len=%u):",
1627 wpa_s->p2p_group_common_freqs_num);
1629 for (i = 0; i < wpa_s->p2p_group_common_freqs_num; i++)
1630 wpa_dbg(wpa_s, MSG_DEBUG, "freq[%u]: %d",
1631 i, wpa_s->p2p_group_common_freqs[i]);
1635 static void p2p_go_save_group_common_freqs(struct wpa_supplicant *wpa_s,
1636 struct p2p_go_neg_results *params)
1638 unsigned int i, len = int_array_len(wpa_s->go_params->freq_list);
1640 wpa_s->p2p_group_common_freqs_num = 0;
1641 os_free(wpa_s->p2p_group_common_freqs);
1642 wpa_s->p2p_group_common_freqs = os_calloc(len, sizeof(int));
1643 if (!wpa_s->p2p_group_common_freqs)
1646 for (i = 0; i < len; i++) {
1647 if (!wpa_s->go_params->freq_list[i])
1649 wpa_s->p2p_group_common_freqs[i] =
1650 wpa_s->go_params->freq_list[i];
1652 wpa_s->p2p_group_common_freqs_num = i;
1656 static void p2p_config_write(struct wpa_supplicant *wpa_s)
1658 #ifndef CONFIG_NO_CONFIG_WRITE
1659 if (wpa_s->parent->conf->update_config &&
1660 wpa_config_write(wpa_s->parent->confname, wpa_s->parent->conf))
1661 wpa_printf(MSG_DEBUG, "P2P: Failed to update configuration");
1662 #endif /* CONFIG_NO_CONFIG_WRITE */
1666 static void p2p_go_configured(void *ctx, void *data)
1668 struct wpa_supplicant *wpa_s = ctx;
1669 struct p2p_go_neg_results *params = data;
1670 struct wpa_ssid *ssid;
1671 int network_id = -1;
1673 p2p_go_save_group_common_freqs(wpa_s, params);
1674 p2p_go_dump_common_freqs(wpa_s);
1676 ssid = wpa_s->current_ssid;
1677 if (ssid && ssid->mode == WPAS_MODE_P2P_GO) {
1678 wpa_printf(MSG_DEBUG, "P2P: Group setup without provisioning");
1679 if (wpa_s->global->p2p_group_formation == wpa_s)
1680 wpa_s->global->p2p_group_formation = NULL;
1681 wpas_p2p_group_started(wpa_s, 1, ssid, ssid->frequency,
1682 params->passphrase[0] == '\0' ?
1685 wpa_s->global->p2p_dev_addr,
1686 params->persistent_group, "");
1687 wpa_s->group_formation_reported = 1;
1689 if (wpa_s->parent->p2ps_join_addr_valid) {
1690 wpa_dbg(wpa_s, MSG_DEBUG,
1691 "P2PS: Setting default PIN for " MACSTR,
1692 MAC2STR(wpa_s->parent->p2ps_join_addr));
1693 wpa_supplicant_ap_wps_pin(wpa_s,
1694 wpa_s->parent->p2ps_join_addr,
1695 "12345670", NULL, 0, 0);
1696 wpa_s->parent->p2ps_join_addr_valid = 0;
1699 os_get_reltime(&wpa_s->global->p2p_go_wait_client);
1700 if (params->persistent_group) {
1701 network_id = wpas_p2p_store_persistent_group(
1702 wpa_s->parent, ssid,
1703 wpa_s->global->p2p_dev_addr);
1704 wpas_p2p_add_psk_list(wpa_s, ssid);
1707 network_id = ssid->id;
1708 wpas_notify_p2p_group_started(wpa_s, ssid, network_id, 0);
1709 wpas_p2p_cross_connect_setup(wpa_s);
1710 wpas_p2p_set_group_idle_timeout(wpa_s);
1712 if (wpa_s->p2p_first_connection_timeout) {
1713 wpa_dbg(wpa_s, MSG_DEBUG,
1714 "P2P: Start group formation timeout of %d seconds until first data connection on GO",
1715 wpa_s->p2p_first_connection_timeout);
1716 wpa_s->p2p_go_group_formation_completed = 0;
1717 wpa_s->global->p2p_group_formation = wpa_s;
1718 eloop_cancel_timeout(wpas_p2p_group_formation_timeout,
1719 wpa_s->parent, NULL);
1720 eloop_register_timeout(
1721 wpa_s->p2p_first_connection_timeout, 0,
1722 wpas_p2p_group_formation_timeout,
1723 wpa_s->parent, NULL);
1729 wpa_printf(MSG_DEBUG, "P2P: Setting up WPS for GO provisioning");
1730 if (wpa_supplicant_ap_mac_addr_filter(wpa_s,
1731 params->peer_interface_addr)) {
1732 wpa_printf(MSG_DEBUG, "P2P: Failed to setup MAC address "
1736 if (params->wps_method == WPS_PBC) {
1737 wpa_supplicant_ap_wps_pbc(wpa_s, params->peer_interface_addr,
1738 params->peer_device_addr);
1739 #ifdef CONFIG_WPS_NFC
1740 } else if (params->wps_method == WPS_NFC) {
1741 if (wpa_s->parent->p2p_oob_dev_pw_id !=
1742 DEV_PW_NFC_CONNECTION_HANDOVER &&
1743 !wpa_s->parent->p2p_oob_dev_pw) {
1744 wpa_printf(MSG_DEBUG, "P2P: No NFC Dev Pw known");
1747 wpas_ap_wps_add_nfc_pw(
1748 wpa_s, wpa_s->parent->p2p_oob_dev_pw_id,
1749 wpa_s->parent->p2p_oob_dev_pw,
1750 wpa_s->parent->p2p_peer_oob_pk_hash_known ?
1751 wpa_s->parent->p2p_peer_oob_pubkey_hash : NULL);
1752 #endif /* CONFIG_WPS_NFC */
1753 } else if (wpa_s->p2p_pin[0])
1754 wpa_supplicant_ap_wps_pin(wpa_s, params->peer_interface_addr,
1755 wpa_s->p2p_pin, NULL, 0, 0);
1756 os_free(wpa_s->go_params);
1757 wpa_s->go_params = NULL;
1761 static void wpas_start_wps_go(struct wpa_supplicant *wpa_s,
1762 struct p2p_go_neg_results *params,
1763 int group_formation)
1765 struct wpa_ssid *ssid;
1767 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Starting GO");
1768 if (wpas_copy_go_neg_results(wpa_s, params) < 0) {
1769 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Could not copy GO Negotiation "
1774 ssid = wpa_config_add_network(wpa_s->conf);
1776 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Could not add network for GO");
1780 wpa_s->show_group_started = 0;
1781 wpa_s->p2p_go_group_formation_completed = 0;
1782 wpa_s->group_formation_reported = 0;
1784 wpa_config_set_network_defaults(ssid);
1785 ssid->temporary = 1;
1786 ssid->p2p_group = 1;
1787 ssid->p2p_persistent_group = params->persistent_group;
1788 ssid->mode = group_formation ? WPAS_MODE_P2P_GROUP_FORMATION :
1790 ssid->frequency = params->freq;
1791 ssid->ht40 = params->ht40;
1792 ssid->vht = params->vht;
1793 ssid->ssid = os_zalloc(params->ssid_len + 1);
1795 os_memcpy(ssid->ssid, params->ssid, params->ssid_len);
1796 ssid->ssid_len = params->ssid_len;
1798 ssid->auth_alg = WPA_AUTH_ALG_OPEN;
1799 ssid->key_mgmt = WPA_KEY_MGMT_PSK;
1800 ssid->proto = WPA_PROTO_RSN;
1801 ssid->pairwise_cipher = WPA_CIPHER_CCMP;
1802 ssid->group_cipher = WPA_CIPHER_CCMP;
1803 if (params->freq > 56160) {
1805 * Enable GCMP instead of CCMP as pairwise_cipher and
1806 * group_cipher in 60 GHz.
1808 ssid->pairwise_cipher = WPA_CIPHER_GCMP;
1809 ssid->group_cipher = WPA_CIPHER_GCMP;
1811 if (os_strlen(params->passphrase) > 0) {
1812 ssid->passphrase = os_strdup(params->passphrase);
1813 if (ssid->passphrase == NULL) {
1814 wpa_msg_global(wpa_s, MSG_ERROR,
1815 "P2P: Failed to copy passphrase for GO");
1816 wpa_config_remove_network(wpa_s->conf, ssid->id);
1820 ssid->passphrase = NULL;
1821 ssid->psk_set = params->psk_set;
1823 os_memcpy(ssid->psk, params->psk, sizeof(ssid->psk));
1824 else if (ssid->passphrase)
1825 wpa_config_update_psk(ssid);
1826 ssid->ap_max_inactivity = wpa_s->parent->conf->p2p_go_max_inactivity;
1828 wpa_s->ap_configured_cb = p2p_go_configured;
1829 wpa_s->ap_configured_cb_ctx = wpa_s;
1830 wpa_s->ap_configured_cb_data = wpa_s->go_params;
1831 wpa_s->scan_req = NORMAL_SCAN_REQ;
1832 wpa_s->connect_without_scan = ssid;
1833 wpa_s->reassociate = 1;
1834 wpa_s->disconnected = 0;
1835 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Request scan (that will be skipped) to "
1837 wpa_supplicant_req_scan(wpa_s, 0, 0);
1841 static void wpas_p2p_clone_config(struct wpa_supplicant *dst,
1842 const struct wpa_supplicant *src)
1844 struct wpa_config *d;
1845 const struct wpa_config *s;
1850 #define C(n) if (s->n) d->n = os_strdup(s->n)
1859 os_memcpy(d->device_type, s->device_type, WPS_DEV_TYPE_LEN);
1860 os_memcpy(d->sec_device_type, s->sec_device_type,
1861 sizeof(d->sec_device_type));
1862 d->num_sec_device_types = s->num_sec_device_types;
1864 d->p2p_group_idle = s->p2p_group_idle;
1865 d->p2p_intra_bss = s->p2p_intra_bss;
1866 d->persistent_reconnect = s->persistent_reconnect;
1867 d->max_num_sta = s->max_num_sta;
1868 d->pbc_in_m1 = s->pbc_in_m1;
1869 d->ignore_old_scan_res = s->ignore_old_scan_res;
1870 d->beacon_int = s->beacon_int;
1871 d->dtim_period = s->dtim_period;
1872 d->p2p_go_ctwindow = s->p2p_go_ctwindow;
1873 d->disassoc_low_ack = s->disassoc_low_ack;
1874 d->disable_scan_offload = s->disable_scan_offload;
1875 d->passive_scan = s->passive_scan;
1877 if (s->wps_nfc_dh_privkey && s->wps_nfc_dh_pubkey) {
1878 d->wps_nfc_dh_privkey = wpabuf_dup(s->wps_nfc_dh_privkey);
1879 d->wps_nfc_dh_pubkey = wpabuf_dup(s->wps_nfc_dh_pubkey);
1881 d->p2p_cli_probe = s->p2p_cli_probe;
1885 static void wpas_p2p_get_group_ifname(struct wpa_supplicant *wpa_s,
1886 char *ifname, size_t len)
1888 char *ifname_ptr = wpa_s->ifname;
1890 if (os_strncmp(wpa_s->ifname, P2P_MGMT_DEVICE_PREFIX,
1891 os_strlen(P2P_MGMT_DEVICE_PREFIX)) == 0) {
1892 ifname_ptr = os_strrchr(wpa_s->ifname, '-') + 1;
1895 os_snprintf(ifname, len, "p2p-%s-%d", ifname_ptr, wpa_s->p2p_group_idx);
1896 if (os_strlen(ifname) >= IFNAMSIZ &&
1897 os_strlen(wpa_s->ifname) < IFNAMSIZ) {
1900 /* Try to avoid going over the IFNAMSIZ length limit */
1901 res = os_snprintf(ifname, len, "p2p-%d", wpa_s->p2p_group_idx);
1902 if (os_snprintf_error(len, res) && len)
1903 ifname[len - 1] = '\0';
1908 static int wpas_p2p_add_group_interface(struct wpa_supplicant *wpa_s,
1909 enum wpa_driver_if_type type)
1911 char ifname[120], force_ifname[120];
1913 if (wpa_s->pending_interface_name[0]) {
1914 wpa_printf(MSG_DEBUG, "P2P: Pending virtual interface exists "
1915 "- skip creation of a new one");
1916 if (is_zero_ether_addr(wpa_s->pending_interface_addr)) {
1917 wpa_printf(MSG_DEBUG, "P2P: Pending virtual address "
1918 "unknown?! ifname='%s'",
1919 wpa_s->pending_interface_name);
1925 wpas_p2p_get_group_ifname(wpa_s, ifname, sizeof(ifname));
1926 force_ifname[0] = '\0';
1928 wpa_printf(MSG_DEBUG, "P2P: Create a new interface %s for the group",
1930 wpa_s->p2p_group_idx++;
1932 wpa_s->pending_interface_type = type;
1933 if (wpa_drv_if_add(wpa_s, type, ifname, NULL, NULL, force_ifname,
1934 wpa_s->pending_interface_addr, NULL) < 0) {
1935 wpa_printf(MSG_ERROR, "P2P: Failed to create new group "
1940 if (force_ifname[0]) {
1941 wpa_printf(MSG_DEBUG, "P2P: Driver forced interface name %s",
1943 os_strlcpy(wpa_s->pending_interface_name, force_ifname,
1944 sizeof(wpa_s->pending_interface_name));
1946 os_strlcpy(wpa_s->pending_interface_name, ifname,
1947 sizeof(wpa_s->pending_interface_name));
1948 wpa_printf(MSG_DEBUG, "P2P: Created pending virtual interface %s addr "
1949 MACSTR, wpa_s->pending_interface_name,
1950 MAC2STR(wpa_s->pending_interface_addr));
1956 static void wpas_p2p_remove_pending_group_interface(
1957 struct wpa_supplicant *wpa_s)
1959 if (!wpa_s->pending_interface_name[0] ||
1960 is_zero_ether_addr(wpa_s->pending_interface_addr))
1961 return; /* No pending virtual interface */
1963 wpa_printf(MSG_DEBUG, "P2P: Removing pending group interface %s",
1964 wpa_s->pending_interface_name);
1965 wpa_drv_if_remove(wpa_s, wpa_s->pending_interface_type,
1966 wpa_s->pending_interface_name);
1967 os_memset(wpa_s->pending_interface_addr, 0, ETH_ALEN);
1968 wpa_s->pending_interface_name[0] = '\0';
1969 wpa_s->global->pending_group_iface_for_p2ps = 0;
1973 static struct wpa_supplicant *
1974 wpas_p2p_init_group_interface(struct wpa_supplicant *wpa_s, int go)
1976 struct wpa_interface iface;
1977 struct wpa_supplicant *group_wpa_s;
1979 if (!wpa_s->pending_interface_name[0]) {
1980 wpa_printf(MSG_ERROR, "P2P: No pending group interface");
1981 if (!wpas_p2p_create_iface(wpa_s))
1984 * Something has forced us to remove the pending interface; try
1985 * to create a new one and hope for the best that we will get
1986 * the same local address.
1988 if (wpas_p2p_add_group_interface(wpa_s, go ? WPA_IF_P2P_GO :
1989 WPA_IF_P2P_CLIENT) < 0)
1993 os_memset(&iface, 0, sizeof(iface));
1994 iface.ifname = wpa_s->pending_interface_name;
1995 iface.driver = wpa_s->driver->name;
1996 if (wpa_s->conf->ctrl_interface == NULL &&
1997 wpa_s->parent != wpa_s &&
1999 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE))
2000 iface.ctrl_interface = wpa_s->parent->conf->ctrl_interface;
2002 iface.ctrl_interface = wpa_s->conf->ctrl_interface;
2003 iface.driver_param = wpa_s->conf->driver_param;
2004 group_wpa_s = wpa_supplicant_add_iface(wpa_s->global, &iface, wpa_s);
2005 if (group_wpa_s == NULL) {
2006 wpa_printf(MSG_ERROR, "P2P: Failed to create new "
2007 "wpa_supplicant interface");
2010 wpa_s->pending_interface_name[0] = '\0';
2011 group_wpa_s->p2p_group_interface = go ? P2P_GROUP_INTERFACE_GO :
2012 P2P_GROUP_INTERFACE_CLIENT;
2013 wpa_s->global->p2p_group_formation = group_wpa_s;
2014 wpa_s->global->pending_group_iface_for_p2ps = 0;
2016 wpas_p2p_clone_config(group_wpa_s, wpa_s);
2022 static void wpas_p2p_group_formation_timeout(void *eloop_ctx,
2025 struct wpa_supplicant *wpa_s = eloop_ctx;
2026 wpa_printf(MSG_DEBUG, "P2P: Group Formation timed out");
2027 wpas_p2p_group_formation_failed(wpa_s, 0);
2031 static void wpas_p2p_group_formation_failed(struct wpa_supplicant *wpa_s,
2032 int already_deleted)
2034 eloop_cancel_timeout(wpas_p2p_group_formation_timeout,
2035 wpa_s->parent, NULL);
2036 if (wpa_s->global->p2p)
2037 p2p_group_formation_failed(wpa_s->global->p2p);
2038 wpas_group_formation_completed(wpa_s, 0, already_deleted);
2042 static void wpas_p2p_grpform_fail_after_wps(struct wpa_supplicant *wpa_s)
2044 wpa_printf(MSG_DEBUG, "P2P: Reject group formation due to WPS provisioning failure");
2045 eloop_cancel_timeout(wpas_p2p_group_formation_timeout,
2046 wpa_s->parent, NULL);
2047 eloop_register_timeout(0, 0, wpas_p2p_group_formation_timeout,
2048 wpa_s->parent, NULL);
2049 wpa_s->global->p2p_fail_on_wps_complete = 0;
2053 void wpas_p2p_ap_setup_failed(struct wpa_supplicant *wpa_s)
2055 if (wpa_s->global->p2p_group_formation != wpa_s)
2057 /* Speed up group formation timeout since this cannot succeed */
2058 eloop_cancel_timeout(wpas_p2p_group_formation_timeout,
2059 wpa_s->parent, NULL);
2060 eloop_register_timeout(0, 0, wpas_p2p_group_formation_timeout,
2061 wpa_s->parent, NULL);
2065 static void wpas_go_neg_completed(void *ctx, struct p2p_go_neg_results *res)
2067 struct wpa_supplicant *wpa_s = ctx;
2069 if (wpa_s->off_channel_freq || wpa_s->roc_waiting_drv_freq) {
2070 wpa_drv_cancel_remain_on_channel(wpa_s);
2071 wpa_s->off_channel_freq = 0;
2072 wpa_s->roc_waiting_drv_freq = 0;
2076 wpa_msg_global(wpa_s, MSG_INFO,
2077 P2P_EVENT_GO_NEG_FAILURE "status=%d",
2079 wpas_notify_p2p_go_neg_completed(wpa_s, res);
2080 wpas_p2p_remove_pending_group_interface(wpa_s);
2084 if (wpa_s->p2p_go_ht40)
2086 if (wpa_s->p2p_go_vht)
2089 wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_GO_NEG_SUCCESS "role=%s "
2090 "freq=%d ht40=%d peer_dev=" MACSTR " peer_iface=" MACSTR
2092 res->role_go ? "GO" : "client", res->freq, res->ht40,
2093 MAC2STR(res->peer_device_addr),
2094 MAC2STR(res->peer_interface_addr),
2095 p2p_wps_method_text(res->wps_method));
2096 wpas_notify_p2p_go_neg_completed(wpa_s, res);
2098 if (res->role_go && wpa_s->p2p_persistent_id >= 0) {
2099 struct wpa_ssid *ssid;
2100 ssid = wpa_config_get_network(wpa_s->conf,
2101 wpa_s->p2p_persistent_id);
2102 if (ssid && ssid->disabled == 2 &&
2103 ssid->mode == WPAS_MODE_P2P_GO && ssid->passphrase) {
2104 size_t len = os_strlen(ssid->passphrase);
2105 wpa_printf(MSG_DEBUG, "P2P: Override passphrase based "
2106 "on requested persistent group");
2107 os_memcpy(res->passphrase, ssid->passphrase, len);
2108 res->passphrase[len] = '\0';
2112 if (wpa_s->create_p2p_iface) {
2113 struct wpa_supplicant *group_wpa_s =
2114 wpas_p2p_init_group_interface(wpa_s, res->role_go);
2115 if (group_wpa_s == NULL) {
2116 wpas_p2p_remove_pending_group_interface(wpa_s);
2117 eloop_cancel_timeout(wpas_p2p_long_listen_timeout,
2119 wpas_p2p_group_formation_failed(wpa_s, 1);
2122 if (group_wpa_s != wpa_s) {
2123 os_memcpy(group_wpa_s->p2p_pin, wpa_s->p2p_pin,
2124 sizeof(group_wpa_s->p2p_pin));
2125 group_wpa_s->p2p_wps_method = wpa_s->p2p_wps_method;
2127 os_memset(wpa_s->pending_interface_addr, 0, ETH_ALEN);
2128 wpa_s->pending_interface_name[0] = '\0';
2129 group_wpa_s->p2p_in_provisioning = 1;
2132 wpas_start_wps_go(group_wpa_s, res, 1);
2134 wpas_start_wps_enrollee(group_wpa_s, res);
2136 wpa_s->p2p_in_provisioning = 1;
2137 wpa_s->global->p2p_group_formation = wpa_s;
2140 wpas_start_wps_go(wpa_s, res, 1);
2142 wpas_start_wps_enrollee(ctx, res);
2145 wpa_s->p2p_long_listen = 0;
2146 eloop_cancel_timeout(wpas_p2p_long_listen_timeout, wpa_s, NULL);
2148 eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s, NULL);
2149 eloop_register_timeout(15 + res->peer_config_timeout / 100,
2150 (res->peer_config_timeout % 100) * 10000,
2151 wpas_p2p_group_formation_timeout, wpa_s, NULL);
2155 static void wpas_go_neg_req_rx(void *ctx, const u8 *src, u16 dev_passwd_id,
2158 struct wpa_supplicant *wpa_s = ctx;
2159 wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_GO_NEG_REQUEST MACSTR
2160 " dev_passwd_id=%u go_intent=%u", MAC2STR(src),
2161 dev_passwd_id, go_intent);
2163 wpas_notify_p2p_go_neg_req(wpa_s, src, dev_passwd_id, go_intent);
2167 static void wpas_dev_found(void *ctx, const u8 *addr,
2168 const struct p2p_peer_info *info,
2171 #ifndef CONFIG_NO_STDOUT_DEBUG
2172 struct wpa_supplicant *wpa_s = ctx;
2173 char devtype[WPS_DEV_TYPE_BUFSIZE];
2174 char *wfd_dev_info_hex = NULL;
2176 #ifdef CONFIG_WIFI_DISPLAY
2177 wfd_dev_info_hex = wifi_display_subelem_hex(info->wfd_subelems,
2178 WFD_SUBELEM_DEVICE_INFO);
2179 #endif /* CONFIG_WIFI_DISPLAY */
2181 if (info->p2ps_instance) {
2183 const u8 *buf = wpabuf_head(info->p2ps_instance);
2184 size_t len = wpabuf_len(info->p2ps_instance);
2191 if (len < 4 + 2 + 1)
2193 id = WPA_GET_LE32(buf);
2195 methods = WPA_GET_BE16(buf);
2198 if (str_len > len - 4 - 2 - 1)
2200 os_memcpy(str, buf, str_len);
2201 str[str_len] = '\0';
2203 len -= str_len + sizeof(u32) + sizeof(u16) + sizeof(u8);
2205 wpa_msg_global(wpa_s, MSG_INFO,
2206 P2P_EVENT_DEVICE_FOUND MACSTR
2207 " p2p_dev_addr=" MACSTR
2208 " pri_dev_type=%s name='%s'"
2209 " config_methods=0x%x"
2212 " adv_id=%x asp_svc=%s%s",
2214 MAC2STR(info->p2p_device_addr),
2215 wps_dev_type_bin2str(
2217 devtype, sizeof(devtype)),
2218 info->device_name, methods,
2219 info->dev_capab, info->group_capab,
2221 info->vendor_elems ?
2222 " vendor_elems=1" : "");
2227 wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_DEVICE_FOUND MACSTR
2228 " p2p_dev_addr=" MACSTR
2229 " pri_dev_type=%s name='%s' config_methods=0x%x "
2230 "dev_capab=0x%x group_capab=0x%x%s%s%s new=%d",
2231 MAC2STR(addr), MAC2STR(info->p2p_device_addr),
2232 wps_dev_type_bin2str(info->pri_dev_type, devtype,
2234 info->device_name, info->config_methods,
2235 info->dev_capab, info->group_capab,
2236 wfd_dev_info_hex ? " wfd_dev_info=0x" : "",
2237 wfd_dev_info_hex ? wfd_dev_info_hex : "",
2238 info->vendor_elems ? " vendor_elems=1" : "",
2242 os_free(wfd_dev_info_hex);
2243 #endif /* CONFIG_NO_STDOUT_DEBUG */
2245 wpas_notify_p2p_device_found(ctx, info->p2p_device_addr, new_device);
2249 static void wpas_dev_lost(void *ctx, const u8 *dev_addr)
2251 struct wpa_supplicant *wpa_s = ctx;
2253 wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_DEVICE_LOST
2254 "p2p_dev_addr=" MACSTR, MAC2STR(dev_addr));
2256 wpas_notify_p2p_device_lost(wpa_s, dev_addr);
2260 static void wpas_find_stopped(void *ctx)
2262 struct wpa_supplicant *wpa_s = ctx;
2263 wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_FIND_STOPPED);
2264 wpas_notify_p2p_find_stopped(wpa_s);
2268 struct wpas_p2p_listen_work {
2270 unsigned int duration;
2271 struct wpabuf *probe_resp_ie;
2275 static void wpas_p2p_listen_work_free(struct wpas_p2p_listen_work *lwork)
2279 wpabuf_free(lwork->probe_resp_ie);
2284 static void wpas_p2p_listen_work_done(struct wpa_supplicant *wpa_s)
2286 struct wpas_p2p_listen_work *lwork;
2288 if (!wpa_s->p2p_listen_work)
2291 lwork = wpa_s->p2p_listen_work->ctx;
2292 wpas_p2p_listen_work_free(lwork);
2293 radio_work_done(wpa_s->p2p_listen_work);
2294 wpa_s->p2p_listen_work = NULL;
2298 static void wpas_start_listen_cb(struct wpa_radio_work *work, int deinit)
2300 struct wpa_supplicant *wpa_s = work->wpa_s;
2301 struct wpas_p2p_listen_work *lwork = work->ctx;
2302 unsigned int duration;
2305 if (work->started) {
2306 wpa_s->p2p_listen_work = NULL;
2307 wpas_stop_listen(wpa_s);
2309 wpas_p2p_listen_work_free(lwork);
2313 wpa_s->p2p_listen_work = work;
2315 wpa_drv_set_ap_wps_ie(wpa_s, NULL, lwork->probe_resp_ie, NULL);
2317 if (wpa_drv_probe_req_report(wpa_s, 1) < 0) {
2318 wpa_printf(MSG_DEBUG, "P2P: Failed to request the driver to "
2319 "report received Probe Request frames");
2320 wpas_p2p_listen_work_done(wpa_s);
2324 wpa_s->pending_listen_freq = lwork->freq;
2325 wpa_s->pending_listen_duration = lwork->duration;
2327 duration = lwork->duration;
2328 #ifdef CONFIG_TESTING_OPTIONS
2329 if (wpa_s->extra_roc_dur) {
2330 wpa_printf(MSG_DEBUG, "TESTING: Increase ROC duration %u -> %u",
2331 duration, duration + wpa_s->extra_roc_dur);
2332 duration += wpa_s->extra_roc_dur;
2334 #endif /* CONFIG_TESTING_OPTIONS */
2336 if (wpa_drv_remain_on_channel(wpa_s, lwork->freq, duration) < 0) {
2337 wpa_printf(MSG_DEBUG, "P2P: Failed to request the driver "
2338 "to remain on channel (%u MHz) for Listen "
2339 "state", lwork->freq);
2340 wpas_p2p_listen_work_done(wpa_s);
2341 wpa_s->pending_listen_freq = 0;
2344 wpa_s->off_channel_freq = 0;
2345 wpa_s->roc_waiting_drv_freq = lwork->freq;
2349 static int wpas_start_listen(void *ctx, unsigned int freq,
2350 unsigned int duration,
2351 const struct wpabuf *probe_resp_ie)
2353 struct wpa_supplicant *wpa_s = ctx;
2354 struct wpas_p2p_listen_work *lwork;
2356 if (wpa_s->p2p_listen_work) {
2357 wpa_printf(MSG_DEBUG, "P2P: Reject start_listen since p2p_listen_work already exists");
2361 lwork = os_zalloc(sizeof(*lwork));
2365 lwork->duration = duration;
2366 if (probe_resp_ie) {
2367 lwork->probe_resp_ie = wpabuf_dup(probe_resp_ie);
2368 if (lwork->probe_resp_ie == NULL) {
2369 wpas_p2p_listen_work_free(lwork);
2374 if (radio_add_work(wpa_s, freq, "p2p-listen", 0, wpas_start_listen_cb,
2376 wpas_p2p_listen_work_free(lwork);
2384 static void wpas_stop_listen(void *ctx)
2386 struct wpa_supplicant *wpa_s = ctx;
2387 if (wpa_s->off_channel_freq || wpa_s->roc_waiting_drv_freq) {
2388 wpa_drv_cancel_remain_on_channel(wpa_s);
2389 wpa_s->off_channel_freq = 0;
2390 wpa_s->roc_waiting_drv_freq = 0;
2392 wpa_drv_set_ap_wps_ie(wpa_s, NULL, NULL, NULL);
2395 * Don't cancel Probe Request RX reporting for a connected P2P Client
2396 * handling Probe Request frames.
2398 if (!wpa_s->p2p_cli_probe)
2399 wpa_drv_probe_req_report(wpa_s, 0);
2401 wpas_p2p_listen_work_done(wpa_s);
2405 static int wpas_send_probe_resp(void *ctx, const struct wpabuf *buf,
2408 struct wpa_supplicant *wpa_s = ctx;
2409 return wpa_drv_send_mlme(wpa_s, wpabuf_head(buf), wpabuf_len(buf), 1,
2414 static void wpas_prov_disc_local_display(struct wpa_supplicant *wpa_s,
2415 const u8 *peer, const char *params,
2416 unsigned int generated_pin)
2418 wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_SHOW_PIN MACSTR
2419 " %08d%s", MAC2STR(peer), generated_pin, params);
2423 static void wpas_prov_disc_local_keypad(struct wpa_supplicant *wpa_s,
2424 const u8 *peer, const char *params)
2426 wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_ENTER_PIN MACSTR
2427 "%s", MAC2STR(peer), params);
2431 static void wpas_prov_disc_req(void *ctx, const u8 *peer, u16 config_methods,
2432 const u8 *dev_addr, const u8 *pri_dev_type,
2433 const char *dev_name, u16 supp_config_methods,
2434 u8 dev_capab, u8 group_capab, const u8 *group_id,
2435 size_t group_id_len)
2437 struct wpa_supplicant *wpa_s = ctx;
2438 char devtype[WPS_DEV_TYPE_BUFSIZE];
2440 u8 empty_dev_type[8];
2441 unsigned int generated_pin = 0;
2442 struct wpa_supplicant *group = NULL;
2446 for (group = wpa_s->global->ifaces; group; group = group->next)
2448 struct wpa_ssid *s = group->current_ssid;
2450 s->mode == WPAS_MODE_P2P_GO &&
2451 group_id_len - ETH_ALEN == s->ssid_len &&
2452 os_memcmp(group_id + ETH_ALEN, s->ssid,
2458 if (pri_dev_type == NULL) {
2459 os_memset(empty_dev_type, 0, sizeof(empty_dev_type));
2460 pri_dev_type = empty_dev_type;
2462 res = os_snprintf(params, sizeof(params), " p2p_dev_addr=" MACSTR
2463 " pri_dev_type=%s name='%s' config_methods=0x%x "
2464 "dev_capab=0x%x group_capab=0x%x%s%s",
2466 wps_dev_type_bin2str(pri_dev_type, devtype,
2468 dev_name, supp_config_methods, dev_capab, group_capab,
2469 group ? " group=" : "",
2470 group ? group->ifname : "");
2471 if (os_snprintf_error(sizeof(params), res))
2472 wpa_printf(MSG_DEBUG, "P2P: PD Request event truncated");
2473 params[sizeof(params) - 1] = '\0';
2475 if (config_methods & WPS_CONFIG_DISPLAY) {
2476 generated_pin = wps_generate_pin();
2477 wpas_prov_disc_local_display(wpa_s, peer, params,
2479 } else if (config_methods & WPS_CONFIG_KEYPAD)
2480 wpas_prov_disc_local_keypad(wpa_s, peer, params);
2481 else if (config_methods & WPS_CONFIG_PUSHBUTTON)
2482 wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_PBC_REQ
2483 MACSTR "%s", MAC2STR(peer), params);
2485 wpas_notify_p2p_provision_discovery(wpa_s, peer, 1 /* request */,
2486 P2P_PROV_DISC_SUCCESS,
2487 config_methods, generated_pin);
2491 static void wpas_prov_disc_resp(void *ctx, const u8 *peer, u16 config_methods)
2493 struct wpa_supplicant *wpa_s = ctx;
2494 unsigned int generated_pin = 0;
2497 if (wpa_s->pending_pd_before_join &&
2498 (os_memcmp(peer, wpa_s->pending_join_dev_addr, ETH_ALEN) == 0 ||
2499 os_memcmp(peer, wpa_s->pending_join_iface_addr, ETH_ALEN) == 0)) {
2500 wpa_s->pending_pd_before_join = 0;
2501 wpa_printf(MSG_DEBUG, "P2P: Starting pending "
2502 "join-existing-group operation");
2503 wpas_p2p_join_start(wpa_s, 0, NULL, 0);
2507 if (wpa_s->pending_pd_use == AUTO_PD_JOIN ||
2508 wpa_s->pending_pd_use == AUTO_PD_GO_NEG) {
2511 res = os_snprintf(params, sizeof(params), " peer_go=%d",
2512 wpa_s->pending_pd_use == AUTO_PD_JOIN);
2513 if (os_snprintf_error(sizeof(params), res))
2514 params[sizeof(params) - 1] = '\0';
2518 if (config_methods & WPS_CONFIG_DISPLAY)
2519 wpas_prov_disc_local_keypad(wpa_s, peer, params);
2520 else if (config_methods & WPS_CONFIG_KEYPAD) {
2521 generated_pin = wps_generate_pin();
2522 wpas_prov_disc_local_display(wpa_s, peer, params,
2524 } else if (config_methods & WPS_CONFIG_PUSHBUTTON)
2525 wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_PBC_RESP
2526 MACSTR "%s", MAC2STR(peer), params);
2528 wpas_notify_p2p_provision_discovery(wpa_s, peer, 0 /* response */,
2529 P2P_PROV_DISC_SUCCESS,
2530 config_methods, generated_pin);
2534 static void wpas_prov_disc_fail(void *ctx, const u8 *peer,
2535 enum p2p_prov_disc_status status,
2536 u32 adv_id, const u8 *adv_mac,
2537 const char *deferred_session_resp)
2539 struct wpa_supplicant *wpa_s = ctx;
2541 if (wpa_s->p2p_fallback_to_go_neg) {
2542 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: PD for p2p_connect-auto "
2543 "failed - fall back to GO Negotiation");
2544 wpa_msg_global(wpa_s->parent, MSG_INFO,
2545 P2P_EVENT_FALLBACK_TO_GO_NEG
2546 "reason=PD-failed");
2547 wpas_p2p_fallback_to_go_neg(wpa_s, 0);
2551 if (status == P2P_PROV_DISC_TIMEOUT_JOIN) {
2552 wpa_s->pending_pd_before_join = 0;
2553 wpa_printf(MSG_DEBUG, "P2P: Starting pending "
2554 "join-existing-group operation (no ACK for PD "
2556 wpas_p2p_join_start(wpa_s, 0, NULL, 0);
2560 if (adv_id && adv_mac && deferred_session_resp) {
2561 wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_FAILURE
2562 " p2p_dev_addr=" MACSTR " status=%d adv_id=%x"
2563 " deferred_session_resp='%s'",
2564 MAC2STR(peer), status, adv_id,
2565 deferred_session_resp);
2566 } else if (adv_id && adv_mac) {
2567 wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_FAILURE
2568 " p2p_dev_addr=" MACSTR " status=%d adv_id=%x",
2569 MAC2STR(peer), status, adv_id);
2571 wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_FAILURE
2572 " p2p_dev_addr=" MACSTR " status=%d",
2573 MAC2STR(peer), status);
2576 wpas_notify_p2p_provision_discovery(wpa_s, peer, 0 /* response */,
2581 static int freq_included(const struct p2p_channels *channels, unsigned int freq)
2583 if (channels == NULL)
2584 return 1; /* Assume no restrictions */
2585 return p2p_channels_includes_freq(channels, freq);
2591 * Pick the best frequency to use from all the currently used frequencies.
2593 static int wpas_p2p_pick_best_used_freq(struct wpa_supplicant *wpa_s,
2594 struct wpa_used_freq_data *freqs,
2599 /* find a candidate freq that is supported by P2P */
2600 for (c = 0; c < num; c++)
2601 if (p2p_supported_freq(wpa_s->global->p2p, freqs[c].freq))
2607 /* once we have a candidate, try to find a 'better' one */
2608 for (i = c + 1; i < num; i++) {
2609 if (!p2p_supported_freq(wpa_s->global->p2p, freqs[i].freq))
2613 * 1. Infrastructure station interfaces have higher preference.
2614 * 2. P2P Clients have higher preference.
2617 if (freqs[i].flags & WPA_FREQ_USED_BY_INFRA_STATION) {
2622 if ((freqs[i].flags & WPA_FREQ_USED_BY_P2P_CLIENT))
2625 return freqs[c].freq;
2629 static u8 wpas_invitation_process(void *ctx, const u8 *sa, const u8 *bssid,
2630 const u8 *go_dev_addr, const u8 *ssid,
2631 size_t ssid_len, int *go, u8 *group_bssid,
2632 int *force_freq, int persistent_group,
2633 const struct p2p_channels *channels,
2636 struct wpa_supplicant *wpa_s = ctx;
2638 struct wpa_used_freq_data *freqs;
2639 struct wpa_supplicant *grp;
2642 if (!persistent_group) {
2643 wpa_printf(MSG_DEBUG, "P2P: Invitation from " MACSTR
2644 " to join an active group (SSID: %s)",
2645 MAC2STR(sa), wpa_ssid_txt(ssid, ssid_len));
2646 if (!is_zero_ether_addr(wpa_s->p2p_auth_invite) &&
2647 (os_memcmp(go_dev_addr, wpa_s->p2p_auth_invite, ETH_ALEN)
2649 os_memcmp(sa, wpa_s->p2p_auth_invite, ETH_ALEN) == 0)) {
2650 wpa_printf(MSG_DEBUG, "P2P: Accept previously "
2651 "authorized invitation");
2655 #ifdef CONFIG_WPS_NFC
2656 if (dev_pw_id >= 0 && wpa_s->p2p_nfc_tag_enabled &&
2657 dev_pw_id == wpa_s->p2p_oob_dev_pw_id) {
2658 wpa_printf(MSG_DEBUG, "P2P: Accept invitation based on local enabled NFC Tag");
2659 wpa_s->p2p_wps_method = WPS_NFC;
2660 wpa_s->pending_join_wps_method = WPS_NFC;
2661 os_memcpy(wpa_s->pending_join_dev_addr,
2662 go_dev_addr, ETH_ALEN);
2663 os_memcpy(wpa_s->pending_join_iface_addr,
2667 #endif /* CONFIG_WPS_NFC */
2670 * Do not accept the invitation automatically; notify user and
2673 return P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE;
2676 grp = wpas_get_p2p_group(wpa_s, ssid, ssid_len, go);
2678 wpa_printf(MSG_DEBUG, "P2P: Accept invitation to already "
2679 "running persistent group");
2681 os_memcpy(group_bssid, grp->own_addr, ETH_ALEN);
2685 if (!is_zero_ether_addr(wpa_s->p2p_auth_invite) &&
2686 os_memcmp(sa, wpa_s->p2p_auth_invite, ETH_ALEN) == 0) {
2687 wpa_printf(MSG_DEBUG, "P2P: Accept previously initiated "
2688 "invitation to re-invoke a persistent group");
2689 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
2690 } else if (!wpa_s->conf->persistent_reconnect)
2691 return P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE;
2693 for (s = wpa_s->conf->ssid; s; s = s->next) {
2694 if (s->disabled == 2 &&
2695 os_memcmp(s->bssid, go_dev_addr, ETH_ALEN) == 0 &&
2696 s->ssid_len == ssid_len &&
2697 os_memcmp(ssid, s->ssid, ssid_len) == 0)
2702 wpa_printf(MSG_DEBUG, "P2P: Invitation from " MACSTR
2703 " requested reinvocation of an unknown group",
2705 return P2P_SC_FAIL_UNKNOWN_GROUP;
2708 if (s->mode == WPAS_MODE_P2P_GO && !wpas_p2p_create_iface(wpa_s)) {
2710 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2711 wpa_printf(MSG_DEBUG, "P2P: The only available "
2712 "interface is already in use - reject "
2714 return P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE;
2716 os_memcpy(group_bssid, wpa_s->own_addr, ETH_ALEN);
2717 } else if (s->mode == WPAS_MODE_P2P_GO) {
2719 if (wpas_p2p_add_group_interface(wpa_s, WPA_IF_P2P_GO) < 0)
2721 wpa_printf(MSG_ERROR, "P2P: Failed to allocate a new "
2722 "interface address for the group");
2723 return P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE;
2725 os_memcpy(group_bssid, wpa_s->pending_interface_addr,
2730 wpas_p2p_set_own_freq_preference(wpa_s, 0);
2733 freqs = os_calloc(wpa_s->num_multichan_concurrent,
2734 sizeof(struct wpa_used_freq_data));
2736 int num_channels = wpa_s->num_multichan_concurrent;
2737 int num = wpas_p2p_valid_oper_freqs(wpa_s, freqs, num_channels);
2738 best_freq = wpas_p2p_pick_best_used_freq(wpa_s, freqs, num);
2742 /* Get one of the frequencies currently in use */
2743 if (best_freq > 0) {
2744 wpa_printf(MSG_DEBUG, "P2P: Trying to prefer a channel already used by one of the interfaces");
2745 wpas_p2p_set_own_freq_preference(wpa_s, best_freq);
2747 if (wpa_s->num_multichan_concurrent < 2 ||
2748 wpas_p2p_num_unused_channels(wpa_s) < 1) {
2749 wpa_printf(MSG_DEBUG, "P2P: No extra channels available - trying to force channel to match a channel already used by one of the interfaces");
2750 *force_freq = best_freq;
2754 if (*force_freq > 0 && wpa_s->num_multichan_concurrent > 1 &&
2755 wpas_p2p_num_unused_channels(wpa_s) > 0) {
2757 /* We are the client */
2758 wpa_printf(MSG_DEBUG, "P2P: Peer was found to be "
2759 "running a GO but we are capable of MCC, "
2760 "figure out the best channel to use");
2762 } else if (!freq_included(channels, *force_freq)) {
2763 /* We are the GO, and *force_freq is not in the
2765 wpa_printf(MSG_DEBUG, "P2P: Forced GO freq %d MHz not "
2766 "in intersection but we are capable of MCC, "
2767 "figure out the best channel to use",
2773 return P2P_SC_SUCCESS;
2777 static void wpas_invitation_received(void *ctx, const u8 *sa, const u8 *bssid,
2778 const u8 *ssid, size_t ssid_len,
2779 const u8 *go_dev_addr, u8 status,
2782 struct wpa_supplicant *wpa_s = ctx;
2785 for (s = wpa_s->conf->ssid; s; s = s->next) {
2786 if (s->disabled == 2 &&
2787 s->ssid_len == ssid_len &&
2788 os_memcmp(ssid, s->ssid, ssid_len) == 0)
2792 if (status == P2P_SC_SUCCESS) {
2793 wpa_printf(MSG_DEBUG, "P2P: Invitation from peer " MACSTR
2794 " was accepted; op_freq=%d MHz, SSID=%s",
2795 MAC2STR(sa), op_freq, wpa_ssid_txt(ssid, ssid_len));
2797 int go = s->mode == WPAS_MODE_P2P_GO;
2798 wpas_p2p_group_add_persistent(
2799 wpa_s, s, go, 0, op_freq, 0, 0, NULL,
2800 go ? P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE : 0);
2802 wpa_s->user_initiated_pd = 0;
2803 wpas_p2p_join(wpa_s, bssid, go_dev_addr,
2804 wpa_s->p2p_wps_method, 0, op_freq,
2810 if (status != P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE) {
2811 wpa_printf(MSG_DEBUG, "P2P: Invitation from peer " MACSTR
2812 " was rejected (status %u)", MAC2STR(sa), status);
2818 wpa_msg_global(wpa_s, MSG_INFO,
2819 P2P_EVENT_INVITATION_RECEIVED
2820 "sa=" MACSTR " go_dev_addr=" MACSTR
2821 " bssid=" MACSTR " unknown-network",
2822 MAC2STR(sa), MAC2STR(go_dev_addr),
2825 wpa_msg_global(wpa_s, MSG_INFO,
2826 P2P_EVENT_INVITATION_RECEIVED
2827 "sa=" MACSTR " go_dev_addr=" MACSTR
2829 MAC2STR(sa), MAC2STR(go_dev_addr));
2834 if (s->mode == WPAS_MODE_P2P_GO && op_freq) {
2835 wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RECEIVED
2836 "sa=" MACSTR " persistent=%d freq=%d",
2837 MAC2STR(sa), s->id, op_freq);
2839 wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RECEIVED
2840 "sa=" MACSTR " persistent=%d",
2841 MAC2STR(sa), s->id);
2846 static void wpas_remove_persistent_peer(struct wpa_supplicant *wpa_s,
2847 struct wpa_ssid *ssid,
2848 const u8 *peer, int inv)
2851 struct wpa_supplicant *p2p_wpa_s = wpa_s->global->p2p_init_wpa_s;
2856 for (i = 0; ssid->p2p_client_list && i < ssid->num_p2p_clients; i++) {
2857 if (os_memcmp(ssid->p2p_client_list + i * 2 * ETH_ALEN, peer,
2861 if (i >= ssid->num_p2p_clients || !ssid->p2p_client_list) {
2862 if (ssid->mode != WPAS_MODE_P2P_GO &&
2863 os_memcmp(ssid->bssid, peer, ETH_ALEN) == 0) {
2864 wpa_printf(MSG_DEBUG, "P2P: Remove persistent group %d "
2865 "due to invitation result", ssid->id);
2866 wpas_notify_network_removed(wpa_s, ssid);
2867 wpa_config_remove_network(wpa_s->conf, ssid->id);
2870 return; /* Peer not found in client list */
2873 wpa_printf(MSG_DEBUG, "P2P: Remove peer " MACSTR " from persistent "
2874 "group %d client list%s",
2875 MAC2STR(peer), ssid->id,
2876 inv ? " due to invitation result" : "");
2877 os_memmove(ssid->p2p_client_list + i * 2 * ETH_ALEN,
2878 ssid->p2p_client_list + (i + 1) * 2 * ETH_ALEN,
2879 (ssid->num_p2p_clients - i - 1) * 2 * ETH_ALEN);
2880 ssid->num_p2p_clients--;
2881 if (p2p_wpa_s->conf->update_config &&
2882 wpa_config_write(p2p_wpa_s->confname, p2p_wpa_s->conf))
2883 wpa_printf(MSG_DEBUG, "P2P: Failed to update configuration");
2887 static void wpas_remove_persistent_client(struct wpa_supplicant *wpa_s,
2890 struct wpa_ssid *ssid;
2892 wpa_s = wpa_s->global->p2p_invite_group;
2894 return; /* No known invitation group */
2895 ssid = wpa_s->current_ssid;
2896 if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO ||
2897 !ssid->p2p_persistent_group)
2898 return; /* Not operating as a GO in persistent group */
2899 ssid = wpas_p2p_get_persistent(wpa_s->parent, peer,
2900 ssid->ssid, ssid->ssid_len);
2901 wpas_remove_persistent_peer(wpa_s, ssid, peer, 1);
2905 static void wpas_invitation_result(void *ctx, int status, const u8 *bssid,
2906 const struct p2p_channels *channels,
2907 const u8 *peer, int neg_freq,
2910 struct wpa_supplicant *wpa_s = ctx;
2911 struct wpa_ssid *ssid;
2915 wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RESULT
2916 "status=%d " MACSTR,
2917 status, MAC2STR(bssid));
2919 wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RESULT
2920 "status=%d ", status);
2922 wpas_notify_p2p_invitation_result(wpa_s, status, bssid);
2924 wpa_printf(MSG_DEBUG, "P2P: Invitation result - status=%d peer=" MACSTR,
2925 status, MAC2STR(peer));
2926 if (wpa_s->pending_invite_ssid_id == -1) {
2927 if (status == P2P_SC_FAIL_UNKNOWN_GROUP)
2928 wpas_remove_persistent_client(wpa_s, peer);
2929 return; /* Invitation to active group */
2932 if (status == P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE) {
2933 wpa_printf(MSG_DEBUG, "P2P: Waiting for peer to start another "
2934 "invitation exchange to indicate readiness for "
2938 if (status != P2P_SC_SUCCESS) {
2939 if (status == P2P_SC_FAIL_UNKNOWN_GROUP) {
2940 ssid = wpa_config_get_network(
2941 wpa_s->conf, wpa_s->pending_invite_ssid_id);
2942 wpas_remove_persistent_peer(wpa_s, ssid, peer, 1);
2944 wpas_p2p_remove_pending_group_interface(wpa_s);
2948 ssid = wpa_config_get_network(wpa_s->conf,
2949 wpa_s->pending_invite_ssid_id);
2951 wpa_printf(MSG_ERROR, "P2P: Could not find persistent group "
2952 "data matching with invitation");
2957 * The peer could have missed our ctrl::ack frame for Invitation
2958 * Response and continue retransmitting the frame. To reduce the
2959 * likelihood of the peer not getting successful TX status for the
2960 * Invitation Response frame, wait a short time here before starting
2961 * the persistent group so that we will remain on the current channel to
2962 * acknowledge any possible retransmission from the peer.
2964 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: 50 ms wait on current channel before "
2965 "starting persistent group");
2968 if (neg_freq > 0 && ssid->mode == WPAS_MODE_P2P_GO &&
2969 freq_included(channels, neg_freq))
2971 else if (peer_oper_freq > 0 && ssid->mode != WPAS_MODE_P2P_GO &&
2972 freq_included(channels, peer_oper_freq))
2973 freq = peer_oper_freq;
2977 wpa_printf(MSG_DEBUG, "P2P: Persistent group invitation success - op_freq=%d MHz SSID=%s",
2978 freq, wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
2979 wpas_p2p_group_add_persistent(wpa_s, ssid,
2980 ssid->mode == WPAS_MODE_P2P_GO,
2981 wpa_s->p2p_persistent_go_freq,
2983 wpa_s->p2p_go_ht40, wpa_s->p2p_go_vht,
2985 ssid->mode == WPAS_MODE_P2P_GO ?
2986 P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE :
2991 static int wpas_p2p_disallowed_freq(struct wpa_global *global,
2994 if (freq_range_list_includes(&global->p2p_go_avoid_freq, freq))
2996 return freq_range_list_includes(&global->p2p_disallow_freq, freq);
3000 static void wpas_p2p_add_chan(struct p2p_reg_class *reg, u8 chan)
3002 reg->channel[reg->channels] = chan;
3007 static int wpas_p2p_default_channels(struct wpa_supplicant *wpa_s,
3008 struct p2p_channels *chan,
3009 struct p2p_channels *cli_chan)
3013 wpa_s->global->p2p_24ghz_social_channels = 1;
3015 os_memset(cli_chan, 0, sizeof(*cli_chan));
3017 wpa_printf(MSG_DEBUG, "P2P: Enable operating classes for 2.4 GHz "
3020 /* Operating class 81 - 2.4 GHz band channels 1..13 */
3021 chan->reg_class[cla].reg_class = 81;
3022 chan->reg_class[cla].channels = 0;
3023 for (i = 0; i < 11; i++) {
3024 if (!wpas_p2p_disallowed_freq(wpa_s->global, 2412 + i * 5))
3025 wpas_p2p_add_chan(&chan->reg_class[cla], i + 1);
3027 if (chan->reg_class[cla].channels)
3030 wpa_printf(MSG_DEBUG, "P2P: Enable operating classes for lower 5 GHz "
3033 /* Operating class 115 - 5 GHz, channels 36-48 */
3034 chan->reg_class[cla].reg_class = 115;
3035 chan->reg_class[cla].channels = 0;
3036 if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 36 * 5))
3037 wpas_p2p_add_chan(&chan->reg_class[cla], 36);
3038 if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 40 * 5))
3039 wpas_p2p_add_chan(&chan->reg_class[cla], 40);
3040 if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 44 * 5))
3041 wpas_p2p_add_chan(&chan->reg_class[cla], 44);
3042 if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 48 * 5))
3043 wpas_p2p_add_chan(&chan->reg_class[cla], 48);
3044 if (chan->reg_class[cla].channels)
3047 wpa_printf(MSG_DEBUG, "P2P: Enable operating classes for higher 5 GHz "
3050 /* Operating class 124 - 5 GHz, channels 149,153,157,161 */
3051 chan->reg_class[cla].reg_class = 124;
3052 chan->reg_class[cla].channels = 0;
3053 if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 149 * 5))
3054 wpas_p2p_add_chan(&chan->reg_class[cla], 149);
3055 if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 153 * 5))
3056 wpas_p2p_add_chan(&chan->reg_class[cla], 153);
3057 if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 156 * 5))
3058 wpas_p2p_add_chan(&chan->reg_class[cla], 157);
3059 if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 161 * 5))
3060 wpas_p2p_add_chan(&chan->reg_class[cla], 161);
3061 if (chan->reg_class[cla].channels)
3064 chan->reg_classes = cla;
3069 static struct hostapd_hw_modes * get_mode(struct hostapd_hw_modes *modes,
3071 enum hostapd_hw_mode mode)
3075 for (i = 0; i < num_modes; i++) {
3076 if (modes[i].mode == mode)
3085 NOT_ALLOWED, NO_IR, ALLOWED
3088 static int has_channel(struct wpa_global *global,
3089 struct hostapd_hw_modes *mode, u8 chan, int *flags)
3094 freq = (mode->mode == HOSTAPD_MODE_IEEE80211A ? 5000 : 2407) +
3096 if (wpas_p2p_disallowed_freq(global, freq))
3099 for (i = 0; i < mode->num_channels; i++) {
3100 if (mode->channels[i].chan == chan) {
3102 *flags = mode->channels[i].flag;
3103 if (mode->channels[i].flag &
3104 (HOSTAPD_CHAN_DISABLED |
3105 HOSTAPD_CHAN_RADAR))
3107 if (mode->channels[i].flag & HOSTAPD_CHAN_NO_IR)
3117 struct p2p_oper_class_map {
3118 enum hostapd_hw_mode mode;
3123 enum { BW20, BW40PLUS, BW40MINUS, BW80, BW2160 } bw;
3126 static const struct p2p_oper_class_map op_class[] = {
3127 { HOSTAPD_MODE_IEEE80211G, 81, 1, 13, 1, BW20 },
3128 #if 0 /* Do not enable HT40 on 2 GHz for now */
3129 { HOSTAPD_MODE_IEEE80211G, 83, 1, 9, 1, BW40PLUS },
3130 { HOSTAPD_MODE_IEEE80211G, 84, 5, 13, 1, BW40MINUS },
3132 { HOSTAPD_MODE_IEEE80211A, 115, 36, 48, 4, BW20 },
3133 { HOSTAPD_MODE_IEEE80211A, 124, 149, 161, 4, BW20 },
3134 { HOSTAPD_MODE_IEEE80211A, 125, 149, 169, 4, BW20 },
3135 { HOSTAPD_MODE_IEEE80211A, 116, 36, 44, 8, BW40PLUS },
3136 { HOSTAPD_MODE_IEEE80211A, 117, 40, 48, 8, BW40MINUS },
3137 { HOSTAPD_MODE_IEEE80211A, 126, 149, 157, 8, BW40PLUS },
3138 { HOSTAPD_MODE_IEEE80211A, 127, 153, 161, 8, BW40MINUS },
3141 * IEEE P802.11ac/D7.0 Table E-4 actually talks about channel center
3142 * frequency index 42, 58, 106, 122, 138, 155 with channel spacing of
3143 * 80 MHz, but currently use the following definition for simplicity
3144 * (these center frequencies are not actual channels, which makes
3145 * has_channel() fail). wpas_p2p_verify_80mhz() should take care of
3146 * removing invalid channels.
3148 { HOSTAPD_MODE_IEEE80211A, 128, 36, 161, 4, BW80 },
3149 { HOSTAPD_MODE_IEEE80211AD, 180, 1, 4, 1, BW2160 },
3150 { -1, 0, 0, 0, 0, BW20 }
3154 static int wpas_p2p_get_center_80mhz(struct wpa_supplicant *wpa_s,
3155 struct hostapd_hw_modes *mode,
3158 u8 center_channels[] = { 42, 58, 106, 122, 138, 155 };
3161 if (mode->mode != HOSTAPD_MODE_IEEE80211A)
3164 for (i = 0; i < ARRAY_SIZE(center_channels); i++)
3166 * In 80 MHz, the bandwidth "spans" 12 channels (e.g., 36-48),
3167 * so the center channel is 6 channels away from the start/end.
3169 if (channel >= center_channels[i] - 6 &&
3170 channel <= center_channels[i] + 6)
3171 return center_channels[i];
3177 static enum chan_allowed wpas_p2p_verify_80mhz(struct wpa_supplicant *wpa_s,
3178 struct hostapd_hw_modes *mode,
3183 enum chan_allowed res, ret = ALLOWED;
3185 center_chan = wpas_p2p_get_center_80mhz(wpa_s, mode, channel);
3188 if (center_chan >= 58 && center_chan <= 138)
3189 return NOT_ALLOWED; /* Do not allow DFS channels for P2P */
3191 /* check all the channels are available */
3192 for (i = 0; i < 4; i++) {
3193 int adj_chan = center_chan - 6 + i * 4;
3195 res = has_channel(wpa_s->global, mode, adj_chan, &flags);
3196 if (res == NOT_ALLOWED)
3201 if (i == 0 && !(flags & HOSTAPD_CHAN_VHT_10_70))
3203 if (i == 1 && !(flags & HOSTAPD_CHAN_VHT_30_50))
3205 if (i == 2 && !(flags & HOSTAPD_CHAN_VHT_50_30))
3207 if (i == 3 && !(flags & HOSTAPD_CHAN_VHT_70_10))
3215 static enum chan_allowed wpas_p2p_verify_channel(struct wpa_supplicant *wpa_s,
3216 struct hostapd_hw_modes *mode,
3220 enum chan_allowed res, res2;
3222 res2 = res = has_channel(wpa_s->global, mode, channel, &flag);
3223 if (bw == BW40MINUS) {
3224 if (!(flag & HOSTAPD_CHAN_HT40MINUS))
3226 res2 = has_channel(wpa_s->global, mode, channel - 4, NULL);
3227 } else if (bw == BW40PLUS) {
3228 if (!(flag & HOSTAPD_CHAN_HT40PLUS))
3230 res2 = has_channel(wpa_s->global, mode, channel + 4, NULL);
3231 } else if (bw == BW80) {
3232 res2 = wpas_p2p_verify_80mhz(wpa_s, mode, channel, bw);
3235 if (res == NOT_ALLOWED || res2 == NOT_ALLOWED)
3237 if (res == NO_IR || res2 == NO_IR)
3243 static int wpas_p2p_setup_channels(struct wpa_supplicant *wpa_s,
3244 struct p2p_channels *chan,
3245 struct p2p_channels *cli_chan)
3247 struct hostapd_hw_modes *mode;
3248 int cla, op, cli_cla;
3250 if (wpa_s->hw.modes == NULL) {
3251 wpa_printf(MSG_DEBUG, "P2P: Driver did not support fetching "
3252 "of all supported channels; assume dualband "
3254 return wpas_p2p_default_channels(wpa_s, chan, cli_chan);
3259 for (op = 0; op_class[op].op_class; op++) {
3260 const struct p2p_oper_class_map *o = &op_class[op];
3262 struct p2p_reg_class *reg = NULL, *cli_reg = NULL;
3264 mode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, o->mode);
3267 if (mode->mode == HOSTAPD_MODE_IEEE80211G)
3268 wpa_s->global->p2p_24ghz_social_channels = 1;
3269 for (ch = o->min_chan; ch <= o->max_chan; ch += o->inc) {
3270 enum chan_allowed res;
3271 res = wpas_p2p_verify_channel(wpa_s, mode, ch, o->bw);
3272 if (res == ALLOWED) {
3274 wpa_printf(MSG_DEBUG, "P2P: Add operating class %u",
3276 reg = &chan->reg_class[cla];
3278 reg->reg_class = o->op_class;
3280 reg->channel[reg->channels] = ch;
3282 } else if (res == NO_IR &&
3283 wpa_s->conf->p2p_add_cli_chan) {
3284 if (cli_reg == NULL) {
3285 wpa_printf(MSG_DEBUG, "P2P: Add operating class %u (client only)",
3287 cli_reg = &cli_chan->reg_class[cli_cla];
3289 cli_reg->reg_class = o->op_class;
3291 cli_reg->channel[cli_reg->channels] = ch;
3292 cli_reg->channels++;
3296 wpa_hexdump(MSG_DEBUG, "P2P: Channels",
3297 reg->channel, reg->channels);
3300 wpa_hexdump(MSG_DEBUG, "P2P: Channels (client only)",
3301 cli_reg->channel, cli_reg->channels);
3305 chan->reg_classes = cla;
3306 cli_chan->reg_classes = cli_cla;
3312 int wpas_p2p_get_ht40_mode(struct wpa_supplicant *wpa_s,
3313 struct hostapd_hw_modes *mode, u8 channel)
3316 enum chan_allowed ret;
3318 for (op = 0; op_class[op].op_class; op++) {
3319 const struct p2p_oper_class_map *o = &op_class[op];
3322 for (ch = o->min_chan; ch <= o->max_chan; ch += o->inc) {
3323 if (o->mode != HOSTAPD_MODE_IEEE80211A ||
3324 (o->bw != BW40PLUS && o->bw != BW40MINUS) ||
3327 ret = wpas_p2p_verify_channel(wpa_s, mode, ch, o->bw);
3329 return (o->bw == BW40MINUS) ? -1 : 1;
3336 int wpas_p2p_get_vht80_center(struct wpa_supplicant *wpa_s,
3337 struct hostapd_hw_modes *mode, u8 channel)
3339 if (!wpas_p2p_verify_channel(wpa_s, mode, channel, BW80))
3342 return wpas_p2p_get_center_80mhz(wpa_s, mode, channel);
3346 static int wpas_get_noa(void *ctx, const u8 *interface_addr, u8 *buf,
3349 struct wpa_supplicant *wpa_s = ctx;
3351 for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) {
3352 if (os_memcmp(wpa_s->own_addr, interface_addr, ETH_ALEN) == 0)
3358 return wpa_drv_get_noa(wpa_s, buf, buf_len);
3362 struct wpa_supplicant * wpas_get_p2p_go_iface(struct wpa_supplicant *wpa_s,
3363 const u8 *ssid, size_t ssid_len)
3365 for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) {
3366 struct wpa_ssid *s = wpa_s->current_ssid;
3369 if (s->mode != WPAS_MODE_P2P_GO &&
3370 s->mode != WPAS_MODE_AP &&
3371 s->mode != WPAS_MODE_P2P_GROUP_FORMATION)
3373 if (s->ssid_len != ssid_len ||
3374 os_memcmp(ssid, s->ssid, ssid_len) != 0)
3384 struct wpa_supplicant * wpas_get_p2p_client_iface(struct wpa_supplicant *wpa_s,
3385 const u8 *peer_dev_addr)
3387 for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) {
3388 struct wpa_ssid *ssid = wpa_s->current_ssid;
3391 if (ssid->mode != WPAS_MODE_INFRA)
3393 if (wpa_s->wpa_state != WPA_COMPLETED &&
3394 wpa_s->wpa_state != WPA_GROUP_HANDSHAKE)
3396 if (os_memcmp(wpa_s->go_dev_addr, peer_dev_addr, ETH_ALEN) == 0)
3404 static int wpas_go_connected(void *ctx, const u8 *dev_addr)
3406 struct wpa_supplicant *wpa_s = ctx;
3408 return wpas_get_p2p_client_iface(wpa_s, dev_addr) != NULL;
3412 static int wpas_is_concurrent_session_active(void *ctx)
3414 struct wpa_supplicant *wpa_s = ctx;
3415 struct wpa_supplicant *ifs;
3417 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
3420 if (ifs->wpa_state > WPA_ASSOCIATED)
3427 static void wpas_p2p_debug_print(void *ctx, int level, const char *msg)
3429 struct wpa_supplicant *wpa_s = ctx;
3430 wpa_msg_global(wpa_s, level, "P2P: %s", msg);
3434 int wpas_p2p_add_p2pdev_interface(struct wpa_supplicant *wpa_s,
3435 const char *conf_p2p_dev)
3437 struct wpa_interface iface;
3438 struct wpa_supplicant *p2pdev_wpa_s;
3440 char force_name[100];
3443 ret = os_snprintf(ifname, sizeof(ifname), P2P_MGMT_DEVICE_PREFIX "%s",
3445 if (os_snprintf_error(sizeof(ifname), ret))
3447 force_name[0] = '\0';
3448 wpa_s->pending_interface_type = WPA_IF_P2P_DEVICE;
3449 ret = wpa_drv_if_add(wpa_s, WPA_IF_P2P_DEVICE, ifname, NULL, NULL,
3450 force_name, wpa_s->pending_interface_addr, NULL);
3452 wpa_printf(MSG_DEBUG, "P2P: Failed to create P2P Device interface");
3455 os_strlcpy(wpa_s->pending_interface_name, ifname,
3456 sizeof(wpa_s->pending_interface_name));
3458 os_memset(&iface, 0, sizeof(iface));
3460 iface.ifname = wpa_s->pending_interface_name;
3461 iface.driver = wpa_s->driver->name;
3462 iface.driver_param = wpa_s->conf->driver_param;
3465 * If a P2P Device configuration file was given, use it as the interface
3466 * configuration file (instead of using parent's configuration file.
3469 iface.confname = conf_p2p_dev;
3470 iface.ctrl_interface = NULL;
3472 iface.confname = wpa_s->confname;
3473 iface.ctrl_interface = wpa_s->conf->ctrl_interface;
3475 iface.conf_p2p_dev = NULL;
3477 p2pdev_wpa_s = wpa_supplicant_add_iface(wpa_s->global, &iface, wpa_s);
3478 if (!p2pdev_wpa_s) {
3479 wpa_printf(MSG_DEBUG, "P2P: Failed to add P2P Device interface");
3483 wpa_s->pending_interface_name[0] = '\0';
3488 static void wpas_presence_resp(void *ctx, const u8 *src, u8 status,
3489 const u8 *noa, size_t noa_len)
3491 struct wpa_supplicant *wpa_s, *intf = ctx;
3494 for (wpa_s = intf->global->ifaces; wpa_s; wpa_s = wpa_s->next) {
3495 if (wpa_s->waiting_presence_resp)
3499 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: No group interface was waiting for presence response");
3502 wpa_s->waiting_presence_resp = 0;
3504 wpa_snprintf_hex(hex, sizeof(hex), noa, noa_len);
3505 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_PRESENCE_RESPONSE "src=" MACSTR
3506 " status=%u noa=%s", MAC2STR(src), status, hex);
3510 static int wpas_get_persistent_group(void *ctx, const u8 *addr, const u8 *ssid,
3511 size_t ssid_len, u8 *go_dev_addr,
3512 u8 *ret_ssid, size_t *ret_ssid_len)
3514 struct wpa_supplicant *wpa_s = ctx;
3517 s = wpas_p2p_get_persistent(wpa_s, addr, ssid, ssid_len);
3519 os_memcpy(ret_ssid, s->ssid, s->ssid_len);
3520 *ret_ssid_len = s->ssid_len;
3521 os_memcpy(go_dev_addr, s->bssid, ETH_ALEN);
3529 static int wpas_get_go_info(void *ctx, u8 *intended_addr,
3530 u8 *ssid, size_t *ssid_len, int *group_iface)
3532 struct wpa_supplicant *wpa_s = ctx;
3536 s = wpas_p2p_group_go_ssid(wpa_s, bssid);
3538 s = wpas_p2p_get_persistent_go(wpa_s);
3540 os_memcpy(bssid, s->bssid, ETH_ALEN);
3543 *group_iface = wpas_p2p_create_iface(wpa_s);
3547 os_memcpy(intended_addr, bssid, ETH_ALEN);
3548 os_memcpy(ssid, s->ssid, s->ssid_len);
3549 *ssid_len = s->ssid_len;
3555 static int wpas_remove_stale_groups(void *ctx, const u8 *peer, const u8 *go,
3556 const u8 *ssid, size_t ssid_len)
3558 struct wpa_supplicant *wpa_s = ctx;
3560 int save_config = 0;
3563 /* Start with our first choice of Persistent Groups */
3564 while ((s = wpas_p2p_get_persistent(wpa_s, peer, NULL, 0))) {
3565 if (go && ssid && ssid_len &&
3566 s->ssid_len == ssid_len &&
3567 os_memcmp(go, s->bssid, ETH_ALEN) == 0 &&
3568 os_memcmp(ssid, s->ssid, ssid_len) == 0)
3571 /* Remove stale persistent group */
3572 if (s->mode != WPAS_MODE_P2P_GO || s->num_p2p_clients <= 1) {
3573 wpa_config_remove_network(wpa_s->conf, s->id);
3578 for (i = 0; i < s->num_p2p_clients; i++) {
3579 if (os_memcmp(s->p2p_client_list + i * 2 * ETH_ALEN,
3580 peer, ETH_ALEN) != 0)
3583 os_memmove(s->p2p_client_list + i * 2 * ETH_ALEN,
3584 s->p2p_client_list + (i + 1) * 2 * ETH_ALEN,
3585 (s->num_p2p_clients - i - 1) * 2 * ETH_ALEN);
3588 s->num_p2p_clients--;
3593 p2p_config_write(wpa_s);
3595 /* Return TRUE if valid SSID remains */
3600 static void wpas_p2ps_prov_complete(void *ctx, u8 status, const u8 *dev,
3601 const u8 *adv_mac, const u8 *ses_mac,
3602 const u8 *grp_mac, u32 adv_id, u32 ses_id,
3603 u8 conncap, int passwd_id,
3604 const u8 *persist_ssid,
3605 size_t persist_ssid_size, int response_done,
3606 int prov_start, const char *session_info)
3608 struct wpa_supplicant *wpa_s = ctx;
3610 struct wpa_ssid *persistent_go, *stale, *s;
3611 int save_config = 0;
3612 struct wpa_supplicant *go_wpa_s;
3617 os_memset(mac, 0, ETH_ALEN);
3626 if (session_info == NULL) {
3627 wpa_msg_global(wpa_s, MSG_INFO,
3628 P2P_EVENT_P2PS_PROVISION_START MACSTR
3629 " adv_id=%x conncap=%x"
3631 " session=%x mac=" MACSTR
3632 " dev_passwd_id=%d",
3633 MAC2STR(dev), adv_id, conncap,
3635 ses_id, MAC2STR(ses_mac),
3638 wpa_msg_global(wpa_s, MSG_INFO,
3639 P2P_EVENT_P2PS_PROVISION_START MACSTR
3640 " adv_id=%x conncap=%x"
3642 " session=%x mac=" MACSTR
3643 " dev_passwd_id=%d info='%s'",
3644 MAC2STR(dev), adv_id, conncap,
3646 ses_id, MAC2STR(ses_mac),
3647 passwd_id, session_info);
3652 go_wpa_s = wpas_p2p_get_go_group(wpa_s);
3653 persistent_go = wpas_p2p_get_persistent_go(wpa_s);
3655 if (status && status != P2P_SC_SUCCESS_DEFERRED) {
3656 if (go_wpa_s && !p2p_group_go_member_count(wpa_s))
3657 wpas_p2p_group_remove(wpa_s, go_wpa_s->ifname);
3659 if (persistent_go && !persistent_go->num_p2p_clients) {
3660 /* remove empty persistent GO */
3661 wpa_config_remove_network(wpa_s->conf,
3665 wpa_msg_global(wpa_s, MSG_INFO,
3666 P2P_EVENT_P2PS_PROVISION_DONE MACSTR
3668 " adv_id=%x adv_mac=" MACSTR
3669 " session=%x mac=" MACSTR,
3670 MAC2STR(dev), status,
3671 adv_id, MAC2STR(adv_mac),
3672 ses_id, MAC2STR(ses_mac));
3676 /* Clean up stale persistent groups with this device */
3677 s = wpas_p2p_get_persistent(wpa_s, dev, persist_ssid,
3680 stale = wpas_p2p_get_persistent(wpa_s, dev, NULL, 0);
3684 if (s && s->ssid_len == stale->ssid_len &&
3685 os_memcmp(stale->bssid, s->bssid, ETH_ALEN) == 0 &&
3686 os_memcmp(stale->ssid, s->ssid, s->ssid_len) == 0)
3689 /* Remove stale persistent group */
3690 if (stale->mode != WPAS_MODE_P2P_GO ||
3691 stale->num_p2p_clients <= 1) {
3692 wpa_config_remove_network(wpa_s->conf, stale->id);
3696 for (i = 0; i < stale->num_p2p_clients; i++) {
3697 if (os_memcmp(stale->p2p_client_list +
3699 dev, ETH_ALEN) == 0) {
3700 os_memmove(stale->p2p_client_list +
3702 stale->p2p_client_list +
3704 (stale->num_p2p_clients -
3709 stale->num_p2p_clients--;
3715 p2p_config_write(wpa_s);
3718 if (go_wpa_s && !p2p_group_go_member_count(wpa_s))
3719 wpas_p2p_group_remove(wpa_s, go_wpa_s->ifname);
3721 if (persistent_go && s != persistent_go &&
3722 !persistent_go->num_p2p_clients) {
3723 /* remove empty persistent GO */
3724 wpa_config_remove_network(wpa_s->conf,
3729 wpa_msg_global(wpa_s, MSG_INFO,
3730 P2P_EVENT_P2PS_PROVISION_DONE MACSTR
3732 " adv_id=%x adv_mac=" MACSTR
3733 " session=%x mac=" MACSTR
3735 MAC2STR(dev), status,
3736 adv_id, MAC2STR(adv_mac),
3737 ses_id, MAC2STR(ses_mac), s->id);
3741 if (conncap == P2PS_SETUP_GROUP_OWNER) {
3742 const char *go_ifname = NULL;
3744 wpa_s->global->pending_p2ps_group = 1;
3746 if (wpa_s->conf->p2p_no_group_iface)
3747 go_ifname = wpa_s->ifname;
3748 else if (wpa_s->pending_interface_name[0])
3749 go_ifname = wpa_s->pending_interface_name;
3752 wpas_p2ps_prov_complete(
3753 wpa_s, P2P_SC_FAIL_UNKNOWN_GROUP,
3754 dev, adv_mac, ses_mac,
3755 NULL, adv_id, ses_id, 0, 0,
3756 NULL, 0, 0, 0, NULL);
3760 /* If PD Resp complete, start up the GO */
3761 if (response_done && persistent_go) {
3762 wpas_p2p_group_add_persistent(
3763 wpa_s, persistent_go,
3764 0, 0, 0, 0, 0, NULL,
3765 persistent_go->mode ==
3767 P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE :
3769 } else if (response_done) {
3770 wpas_p2p_group_add(wpa_s, 1, 0, 0, 0);
3773 if (passwd_id == DEV_PW_P2PS_DEFAULT) {
3774 os_memcpy(wpa_s->p2ps_join_addr, dev, ETH_ALEN);
3775 wpa_s->p2ps_join_addr_valid = 1;
3776 wpa_dbg(wpa_s, MSG_DEBUG,
3777 "P2PS: Saving PIN for " MACSTR,
3780 } else if (passwd_id == DEV_PW_P2PS_DEFAULT) {
3781 go_ifname = go_wpa_s->ifname;
3783 wpa_dbg(go_wpa_s, MSG_DEBUG,
3784 "P2P: Setting PIN-1 For " MACSTR, MAC2STR(dev));
3785 wpa_supplicant_ap_wps_pin(go_wpa_s, dev, "12345670",
3788 os_memcpy(wpa_s->p2ps_join_addr, dev, ETH_ALEN);
3789 wpa_s->p2ps_join_addr_valid = 1;
3790 wpa_dbg(wpa_s, MSG_DEBUG,
3791 "P2PS: Saving PIN for " MACSTR, MAC2STR(dev));
3794 wpa_msg_global(wpa_s, MSG_INFO,
3795 P2P_EVENT_P2PS_PROVISION_DONE MACSTR
3796 " status=%d conncap=%x"
3797 " adv_id=%x adv_mac=" MACSTR
3798 " session=%x mac=" MACSTR
3799 " dev_passwd_id=%d go=%s",
3800 MAC2STR(dev), status, conncap,
3801 adv_id, MAC2STR(adv_mac),
3802 ses_id, MAC2STR(ses_mac),
3803 passwd_id, go_ifname);
3807 if (go_wpa_s && !p2p_group_go_member_count(wpa_s))
3808 wpas_p2p_group_remove(wpa_s, go_wpa_s->ifname);
3810 if (persistent_go && !persistent_go->num_p2p_clients) {
3811 /* remove empty persistent GO */
3812 wpa_config_remove_network(wpa_s->conf, persistent_go->id);
3815 if (conncap == P2PS_SETUP_CLIENT) {
3816 wpa_msg_global(wpa_s, MSG_INFO,
3817 P2P_EVENT_P2PS_PROVISION_DONE MACSTR
3818 " status=%d conncap=%x"
3819 " adv_id=%x adv_mac=" MACSTR
3820 " session=%x mac=" MACSTR
3821 " dev_passwd_id=%d join=" MACSTR,
3822 MAC2STR(dev), status, conncap,
3823 adv_id, MAC2STR(adv_mac),
3824 ses_id, MAC2STR(ses_mac),
3825 passwd_id, MAC2STR(grp_mac));
3827 wpa_msg_global(wpa_s, MSG_INFO,
3828 P2P_EVENT_P2PS_PROVISION_DONE MACSTR
3829 " status=%d conncap=%x"
3830 " adv_id=%x adv_mac=" MACSTR
3831 " session=%x mac=" MACSTR
3832 " dev_passwd_id=%d",
3833 MAC2STR(dev), status, conncap,
3834 adv_id, MAC2STR(adv_mac),
3835 ses_id, MAC2STR(ses_mac),
3841 static int _wpas_p2p_in_progress(void *ctx)
3843 struct wpa_supplicant *wpa_s = ctx;
3844 return wpas_p2p_in_progress(wpa_s);
3848 static int wpas_prov_disc_resp_cb(void *ctx)
3850 struct wpa_supplicant *wpa_s = ctx;
3851 struct wpa_ssid *persistent_go;
3853 if (!wpa_s->global->pending_p2ps_group)
3856 wpa_s->global->pending_p2ps_group = 0;
3858 if (wpas_p2p_get_go_group(wpa_s))
3860 persistent_go = wpas_p2p_get_persistent_go(wpa_s);
3862 if (persistent_go) {
3863 wpas_p2p_group_add_persistent(
3864 wpa_s, persistent_go, 0, 0, 0, 0, 0, NULL,
3865 persistent_go->mode == WPAS_MODE_P2P_GO ?
3866 P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE : 0);
3868 wpas_p2p_group_add(wpa_s, 1, 0, 0, 0);
3876 * wpas_p2p_init - Initialize P2P module for %wpa_supplicant
3877 * @global: Pointer to global data from wpa_supplicant_init()
3878 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
3879 * Returns: 0 on success, -1 on failure
3881 int wpas_p2p_init(struct wpa_global *global, struct wpa_supplicant *wpa_s)
3883 struct p2p_config p2p;
3886 if (wpa_s->conf->p2p_disabled)
3889 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_CAPABLE))
3895 os_memset(&p2p, 0, sizeof(p2p));
3897 p2p.debug_print = wpas_p2p_debug_print;
3898 p2p.p2p_scan = wpas_p2p_scan;
3899 p2p.send_action = wpas_send_action;
3900 p2p.send_action_done = wpas_send_action_done;
3901 p2p.go_neg_completed = wpas_go_neg_completed;
3902 p2p.go_neg_req_rx = wpas_go_neg_req_rx;
3903 p2p.dev_found = wpas_dev_found;
3904 p2p.dev_lost = wpas_dev_lost;
3905 p2p.find_stopped = wpas_find_stopped;
3906 p2p.start_listen = wpas_start_listen;
3907 p2p.stop_listen = wpas_stop_listen;
3908 p2p.send_probe_resp = wpas_send_probe_resp;
3909 p2p.sd_request = wpas_sd_request;
3910 p2p.sd_response = wpas_sd_response;
3911 p2p.prov_disc_req = wpas_prov_disc_req;
3912 p2p.prov_disc_resp = wpas_prov_disc_resp;
3913 p2p.prov_disc_fail = wpas_prov_disc_fail;
3914 p2p.invitation_process = wpas_invitation_process;
3915 p2p.invitation_received = wpas_invitation_received;
3916 p2p.invitation_result = wpas_invitation_result;
3917 p2p.get_noa = wpas_get_noa;
3918 p2p.go_connected = wpas_go_connected;
3919 p2p.presence_resp = wpas_presence_resp;
3920 p2p.is_concurrent_session_active = wpas_is_concurrent_session_active;
3921 p2p.is_p2p_in_progress = _wpas_p2p_in_progress;
3922 p2p.get_persistent_group = wpas_get_persistent_group;
3923 p2p.get_go_info = wpas_get_go_info;
3924 p2p.remove_stale_groups = wpas_remove_stale_groups;
3925 p2p.p2ps_prov_complete = wpas_p2ps_prov_complete;
3926 p2p.prov_disc_resp_cb = wpas_prov_disc_resp_cb;
3927 p2p.p2ps_group_capability = p2ps_group_capability;
3929 os_memcpy(wpa_s->global->p2p_dev_addr, wpa_s->own_addr, ETH_ALEN);
3930 os_memcpy(p2p.dev_addr, wpa_s->global->p2p_dev_addr, ETH_ALEN);
3931 p2p.dev_name = wpa_s->conf->device_name;
3932 p2p.manufacturer = wpa_s->conf->manufacturer;
3933 p2p.model_name = wpa_s->conf->model_name;
3934 p2p.model_number = wpa_s->conf->model_number;
3935 p2p.serial_number = wpa_s->conf->serial_number;
3937 os_memcpy(p2p.uuid, wpa_s->wps->uuid, 16);
3938 p2p.config_methods = wpa_s->wps->config_methods;
3941 if (wpas_p2p_setup_channels(wpa_s, &p2p.channels, &p2p.cli_channels)) {
3942 wpa_printf(MSG_ERROR,
3943 "P2P: Failed to configure supported channel list");
3947 if (wpa_s->conf->p2p_listen_reg_class &&
3948 wpa_s->conf->p2p_listen_channel) {
3949 p2p.reg_class = wpa_s->conf->p2p_listen_reg_class;
3950 p2p.channel = wpa_s->conf->p2p_listen_channel;
3951 p2p.channel_forced = 1;
3954 * Pick one of the social channels randomly as the listen
3957 if (p2p_config_get_random_social(&p2p, &p2p.reg_class,
3958 &p2p.channel) != 0) {
3959 wpa_printf(MSG_INFO,
3960 "P2P: No social channels supported by the driver - do not enable P2P");
3963 p2p.channel_forced = 0;
3965 wpa_printf(MSG_DEBUG, "P2P: Own listen channel: %d:%d",
3966 p2p.reg_class, p2p.channel);
3968 if (wpa_s->conf->p2p_oper_reg_class &&
3969 wpa_s->conf->p2p_oper_channel) {
3970 p2p.op_reg_class = wpa_s->conf->p2p_oper_reg_class;
3971 p2p.op_channel = wpa_s->conf->p2p_oper_channel;
3972 p2p.cfg_op_channel = 1;
3973 wpa_printf(MSG_DEBUG, "P2P: Configured operating channel: "
3974 "%d:%d", p2p.op_reg_class, p2p.op_channel);
3978 * Use random operation channel from 2.4 GHz band social
3979 * channels (1, 6, 11) or band 60 GHz social channel (2) if no
3980 * other preference is indicated.
3982 if (p2p_config_get_random_social(&p2p, &p2p.op_reg_class,
3983 &p2p.op_channel) != 0) {
3984 wpa_printf(MSG_ERROR,
3985 "P2P: Failed to select random social channel as operation channel");
3988 p2p.cfg_op_channel = 0;
3989 wpa_printf(MSG_DEBUG, "P2P: Random operating channel: "
3990 "%d:%d", p2p.op_reg_class, p2p.op_channel);
3993 if (wpa_s->conf->p2p_pref_chan && wpa_s->conf->num_p2p_pref_chan) {
3994 p2p.pref_chan = wpa_s->conf->p2p_pref_chan;
3995 p2p.num_pref_chan = wpa_s->conf->num_p2p_pref_chan;
3998 if (wpa_s->conf->country[0] && wpa_s->conf->country[1]) {
3999 os_memcpy(p2p.country, wpa_s->conf->country, 2);
4000 p2p.country[2] = 0x04;
4002 os_memcpy(p2p.country, "XX\x04", 3);
4004 os_memcpy(p2p.pri_dev_type, wpa_s->conf->device_type,
4007 p2p.num_sec_dev_types = wpa_s->conf->num_sec_device_types;
4008 os_memcpy(p2p.sec_dev_type, wpa_s->conf->sec_device_type,
4009 p2p.num_sec_dev_types * WPS_DEV_TYPE_LEN);
4011 p2p.concurrent_operations = !!(wpa_s->drv_flags &
4012 WPA_DRIVER_FLAGS_P2P_CONCURRENT);
4014 p2p.max_peers = 100;
4016 if (wpa_s->conf->p2p_ssid_postfix) {
4017 p2p.ssid_postfix_len =
4018 os_strlen(wpa_s->conf->p2p_ssid_postfix);
4019 if (p2p.ssid_postfix_len > sizeof(p2p.ssid_postfix))
4020 p2p.ssid_postfix_len = sizeof(p2p.ssid_postfix);
4021 os_memcpy(p2p.ssid_postfix, wpa_s->conf->p2p_ssid_postfix,
4022 p2p.ssid_postfix_len);
4025 p2p.p2p_intra_bss = wpa_s->conf->p2p_intra_bss;
4027 p2p.max_listen = wpa_s->max_remain_on_chan;
4029 if (wpa_s->conf->p2p_passphrase_len >= 8 &&
4030 wpa_s->conf->p2p_passphrase_len <= 63)
4031 p2p.passphrase_len = wpa_s->conf->p2p_passphrase_len;
4033 p2p.passphrase_len = 8;
4035 global->p2p = p2p_init(&p2p);
4036 if (global->p2p == NULL)
4038 global->p2p_init_wpa_s = wpa_s;
4040 for (i = 0; i < MAX_WPS_VENDOR_EXT; i++) {
4041 if (wpa_s->conf->wps_vendor_ext[i] == NULL)
4043 p2p_add_wps_vendor_extension(
4044 global->p2p, wpa_s->conf->wps_vendor_ext[i]);
4047 p2p_set_no_go_freq(global->p2p, &wpa_s->conf->p2p_no_go_freq);
4054 * wpas_p2p_deinit - Deinitialize per-interface P2P data
4055 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
4057 * This function deinitialize per-interface P2P data.
4059 void wpas_p2p_deinit(struct wpa_supplicant *wpa_s)
4061 if (wpa_s->driver && wpa_s->drv_priv)
4062 wpa_drv_probe_req_report(wpa_s, 0);
4064 if (wpa_s->go_params) {
4065 /* Clear any stored provisioning info */
4066 p2p_clear_provisioning_info(
4068 wpa_s->go_params->peer_device_addr);
4071 os_free(wpa_s->go_params);
4072 wpa_s->go_params = NULL;
4073 eloop_cancel_timeout(wpas_p2p_psk_failure_removal, wpa_s, NULL);
4074 eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s, NULL);
4075 eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL);
4076 wpa_s->p2p_long_listen = 0;
4077 eloop_cancel_timeout(wpas_p2p_long_listen_timeout, wpa_s, NULL);
4078 eloop_cancel_timeout(wpas_p2p_group_idle_timeout, wpa_s, NULL);
4079 wpas_p2p_remove_pending_group_interface(wpa_s);
4080 eloop_cancel_timeout(wpas_p2p_group_freq_conflict, wpa_s, NULL);
4081 wpas_p2p_listen_work_done(wpa_s);
4082 if (wpa_s->p2p_send_action_work) {
4083 os_free(wpa_s->p2p_send_action_work->ctx);
4084 radio_work_done(wpa_s->p2p_send_action_work);
4085 wpa_s->p2p_send_action_work = NULL;
4087 eloop_cancel_timeout(wpas_p2p_send_action_work_timeout, wpa_s, NULL);
4089 wpabuf_free(wpa_s->p2p_oob_dev_pw);
4090 wpa_s->p2p_oob_dev_pw = NULL;
4092 os_free(wpa_s->p2p_group_common_freqs);
4093 wpa_s->p2p_group_common_freqs = NULL;
4094 wpa_s->p2p_group_common_freqs_num = 0;
4096 /* TODO: remove group interface from the driver if this wpa_s instance
4097 * is on top of a P2P group interface */
4102 * wpas_p2p_deinit_global - Deinitialize global P2P module
4103 * @global: Pointer to global data from wpa_supplicant_init()
4105 * This function deinitializes the global (per device) P2P module.
4107 static void wpas_p2p_deinit_global(struct wpa_global *global)
4109 struct wpa_supplicant *wpa_s, *tmp;
4111 wpa_s = global->ifaces;
4113 wpas_p2p_service_flush(global->p2p_init_wpa_s);
4115 /* Remove remaining P2P group interfaces */
4116 while (wpa_s && wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE)
4117 wpa_s = wpa_s->next;
4119 tmp = global->ifaces;
4122 tmp->p2p_group_interface == NOT_P2P_GROUP_INTERFACE)) {
4127 /* Disconnect from the P2P group and deinit the interface */
4128 wpas_p2p_disconnect(tmp);
4132 * Deinit GO data on any possibly remaining interface (if main
4133 * interface is used as GO).
4135 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
4136 if (wpa_s->ap_iface)
4137 wpas_p2p_group_deinit(wpa_s);
4140 p2p_deinit(global->p2p);
4142 global->p2p_init_wpa_s = NULL;
4146 static int wpas_p2p_create_iface(struct wpa_supplicant *wpa_s)
4148 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
4149 wpa_s->conf->p2p_no_group_iface)
4150 return 0; /* separate interface disabled per configuration */
4151 if (wpa_s->drv_flags &
4152 (WPA_DRIVER_FLAGS_P2P_DEDICATED_INTERFACE |
4153 WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P))
4154 return 1; /* P2P group requires a new interface in every case
4156 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_CONCURRENT))
4157 return 0; /* driver does not support concurrent operations */
4158 if (wpa_s->global->ifaces->next)
4159 return 1; /* more that one interface already in use */
4160 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
4161 return 1; /* this interface is already in use */
4166 static int wpas_p2p_start_go_neg(struct wpa_supplicant *wpa_s,
4167 const u8 *peer_addr,
4168 enum p2p_wps_method wps_method,
4169 int go_intent, const u8 *own_interface_addr,
4170 unsigned int force_freq, int persistent_group,
4171 struct wpa_ssid *ssid, unsigned int pref_freq)
4173 if (persistent_group && wpa_s->conf->persistent_reconnect)
4174 persistent_group = 2;
4177 * Increase GO config timeout if HT40 is used since it takes some time
4178 * to scan channels for coex purposes before the BSS can be started.
4180 p2p_set_config_timeout(wpa_s->global->p2p,
4181 wpa_s->p2p_go_ht40 ? 255 : 100, 20);
4183 return p2p_connect(wpa_s->global->p2p, peer_addr, wps_method,
4184 go_intent, own_interface_addr, force_freq,
4185 persistent_group, ssid ? ssid->ssid : NULL,
4186 ssid ? ssid->ssid_len : 0,
4187 wpa_s->p2p_pd_before_go_neg, pref_freq,
4188 wps_method == WPS_NFC ? wpa_s->p2p_oob_dev_pw_id :
4193 static int wpas_p2p_auth_go_neg(struct wpa_supplicant *wpa_s,
4194 const u8 *peer_addr,
4195 enum p2p_wps_method wps_method,
4196 int go_intent, const u8 *own_interface_addr,
4197 unsigned int force_freq, int persistent_group,
4198 struct wpa_ssid *ssid, unsigned int pref_freq)
4200 if (persistent_group && wpa_s->conf->persistent_reconnect)
4201 persistent_group = 2;
4203 return p2p_authorize(wpa_s->global->p2p, peer_addr, wps_method,
4204 go_intent, own_interface_addr, force_freq,
4205 persistent_group, ssid ? ssid->ssid : NULL,
4206 ssid ? ssid->ssid_len : 0, pref_freq,
4207 wps_method == WPS_NFC ? wpa_s->p2p_oob_dev_pw_id :
4212 static void wpas_p2p_check_join_scan_limit(struct wpa_supplicant *wpa_s)
4214 wpa_s->p2p_join_scan_count++;
4215 wpa_printf(MSG_DEBUG, "P2P: Join scan attempt %d",
4216 wpa_s->p2p_join_scan_count);
4217 if (wpa_s->p2p_join_scan_count > P2P_MAX_JOIN_SCAN_ATTEMPTS) {
4218 wpa_printf(MSG_DEBUG, "P2P: Failed to find GO " MACSTR
4219 " for join operationg - stop join attempt",
4220 MAC2STR(wpa_s->pending_join_iface_addr));
4221 eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL);
4222 if (wpa_s->p2p_auto_pd) {
4223 wpa_s->p2p_auto_pd = 0;
4224 wpa_msg_global(wpa_s, MSG_INFO,
4225 P2P_EVENT_PROV_DISC_FAILURE
4226 " p2p_dev_addr=" MACSTR " status=N/A",
4227 MAC2STR(wpa_s->pending_join_dev_addr));
4230 wpa_msg_global(wpa_s->parent, MSG_INFO,
4231 P2P_EVENT_GROUP_FORMATION_FAILURE);
4236 static int wpas_check_freq_conflict(struct wpa_supplicant *wpa_s, int freq)
4239 unsigned int num, i;
4240 struct wpa_used_freq_data *freqs;
4242 if (wpas_p2p_num_unused_channels(wpa_s) > 0) {
4243 /* Multiple channels are supported and not all are in use */
4247 freqs = os_calloc(wpa_s->num_multichan_concurrent,
4248 sizeof(struct wpa_used_freq_data));
4252 num = wpas_p2p_valid_oper_freqs(wpa_s, freqs,
4253 wpa_s->num_multichan_concurrent);
4255 for (i = 0; i < num; i++) {
4256 if (freqs[i].freq == freq) {
4257 wpa_printf(MSG_DEBUG, "P2P: Frequency %d MHz in use by another virtual interface and can be used",
4264 wpa_printf(MSG_DEBUG, "P2P: No valid operating frequencies");
4273 static int wpas_p2p_peer_go(struct wpa_supplicant *wpa_s,
4274 const u8 *peer_dev_addr)
4276 struct wpa_bss *bss;
4279 bss = wpa_bss_get_p2p_dev_addr(wpa_s, peer_dev_addr);
4282 if (bss->last_update_idx < wpa_s->bss_update_idx) {
4283 wpa_printf(MSG_DEBUG, "P2P: Peer BSS entry not updated in the "
4288 updated = os_reltime_before(&wpa_s->p2p_auto_started,
4290 wpa_printf(MSG_DEBUG, "P2P: Current BSS entry for peer updated at "
4291 "%ld.%06ld (%supdated in last scan)",
4292 bss->last_update.sec, bss->last_update.usec,
4293 updated ? "": "not ");
4299 static void wpas_p2p_scan_res_join(struct wpa_supplicant *wpa_s,
4300 struct wpa_scan_results *scan_res)
4302 struct wpa_bss *bss = NULL;
4304 u8 iface_addr[ETH_ALEN];
4306 eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL);
4308 if (wpa_s->global->p2p_disabled)
4311 wpa_printf(MSG_DEBUG, "P2P: Scan results received (%d BSS) for %sjoin",
4312 scan_res ? (int) scan_res->num : -1,
4313 wpa_s->p2p_auto_join ? "auto_" : "");
4316 wpas_p2p_scan_res_handler(wpa_s, scan_res);
4318 if (wpa_s->p2p_auto_pd) {
4319 int join = wpas_p2p_peer_go(wpa_s,
4320 wpa_s->pending_join_dev_addr);
4322 wpa_s->auto_pd_scan_retry < P2P_AUTO_PD_SCAN_ATTEMPTS) {
4323 wpa_s->auto_pd_scan_retry++;
4324 bss = wpa_bss_get_bssid_latest(
4325 wpa_s, wpa_s->pending_join_dev_addr);
4328 wpa_printf(MSG_DEBUG, "P2P: Scan retry %d for "
4329 "the peer " MACSTR " at %d MHz",
4330 wpa_s->auto_pd_scan_retry,
4332 pending_join_dev_addr),
4334 wpas_p2p_join_scan_req(wpa_s, freq, NULL, 0);
4342 wpa_s->p2p_auto_pd = 0;
4343 wpa_s->pending_pd_use = join ? AUTO_PD_JOIN : AUTO_PD_GO_NEG;
4344 wpa_printf(MSG_DEBUG, "P2P: Auto PD with " MACSTR " join=%d",
4345 MAC2STR(wpa_s->pending_join_dev_addr), join);
4346 if (p2p_prov_disc_req(wpa_s->global->p2p,
4347 wpa_s->pending_join_dev_addr, NULL,
4348 wpa_s->pending_pd_config_methods, join,
4349 0, wpa_s->user_initiated_pd) < 0) {
4350 wpa_s->p2p_auto_pd = 0;
4351 wpa_msg_global(wpa_s, MSG_INFO,
4352 P2P_EVENT_PROV_DISC_FAILURE
4353 " p2p_dev_addr=" MACSTR " status=N/A",
4354 MAC2STR(wpa_s->pending_join_dev_addr));
4359 if (wpa_s->p2p_auto_join) {
4360 int join = wpas_p2p_peer_go(wpa_s,
4361 wpa_s->pending_join_dev_addr);
4363 wpa_printf(MSG_DEBUG, "P2P: Peer was not found to be "
4364 "running a GO -> use GO Negotiation");
4365 wpa_msg_global(wpa_s->parent, MSG_INFO,
4366 P2P_EVENT_FALLBACK_TO_GO_NEG
4367 "reason=peer-not-running-GO");
4368 wpas_p2p_connect(wpa_s, wpa_s->pending_join_dev_addr,
4369 wpa_s->p2p_pin, wpa_s->p2p_wps_method,
4370 wpa_s->p2p_persistent_group, 0, 0, 0,
4371 wpa_s->p2p_go_intent,
4372 wpa_s->p2p_connect_freq,
4373 wpa_s->p2p_persistent_id,
4374 wpa_s->p2p_pd_before_go_neg,
4380 wpa_printf(MSG_DEBUG, "P2P: Peer was found running GO%s -> "
4381 "try to join the group", join ? "" :
4384 wpa_msg_global(wpa_s->parent, MSG_INFO,
4385 P2P_EVENT_FALLBACK_TO_GO_NEG_ENABLED);
4386 wpa_s->p2p_fallback_to_go_neg = 1;
4390 freq = p2p_get_oper_freq(wpa_s->global->p2p,
4391 wpa_s->pending_join_iface_addr);
4393 p2p_get_interface_addr(wpa_s->global->p2p,
4394 wpa_s->pending_join_dev_addr,
4396 os_memcmp(iface_addr, wpa_s->pending_join_dev_addr, ETH_ALEN) != 0
4397 && !wpa_bss_get_bssid(wpa_s, wpa_s->pending_join_iface_addr)) {
4398 wpa_printf(MSG_DEBUG, "P2P: Overwrite pending interface "
4399 "address for join from " MACSTR " to " MACSTR
4400 " based on newly discovered P2P peer entry",
4401 MAC2STR(wpa_s->pending_join_iface_addr),
4402 MAC2STR(iface_addr));
4403 os_memcpy(wpa_s->pending_join_iface_addr, iface_addr,
4406 freq = p2p_get_oper_freq(wpa_s->global->p2p,
4407 wpa_s->pending_join_iface_addr);
4410 wpa_printf(MSG_DEBUG, "P2P: Target GO operating frequency "
4411 "from P2P peer table: %d MHz", freq);
4413 if (wpa_s->p2p_join_ssid_len) {
4414 wpa_printf(MSG_DEBUG, "P2P: Trying to find target GO BSS entry based on BSSID "
4415 MACSTR " and SSID %s",
4416 MAC2STR(wpa_s->pending_join_iface_addr),
4417 wpa_ssid_txt(wpa_s->p2p_join_ssid,
4418 wpa_s->p2p_join_ssid_len));
4419 bss = wpa_bss_get(wpa_s, wpa_s->pending_join_iface_addr,
4420 wpa_s->p2p_join_ssid,
4421 wpa_s->p2p_join_ssid_len);
4424 wpa_printf(MSG_DEBUG, "P2P: Trying to find target GO BSS entry based on BSSID "
4425 MACSTR, MAC2STR(wpa_s->pending_join_iface_addr));
4426 bss = wpa_bss_get_bssid_latest(wpa_s,
4427 wpa_s->pending_join_iface_addr);
4430 u8 dev_addr[ETH_ALEN];
4433 wpa_printf(MSG_DEBUG, "P2P: Target GO operating frequency "
4434 "from BSS table: %d MHz (SSID %s)", freq,
4435 wpa_ssid_txt(bss->ssid, bss->ssid_len));
4436 if (p2p_parse_dev_addr((const u8 *) (bss + 1), bss->ie_len,
4438 os_memcmp(wpa_s->pending_join_dev_addr,
4439 wpa_s->pending_join_iface_addr, ETH_ALEN) == 0 &&
4440 os_memcmp(dev_addr, wpa_s->pending_join_dev_addr,
4442 wpa_printf(MSG_DEBUG,
4443 "P2P: Update target GO device address based on BSS entry: " MACSTR " (was " MACSTR ")",
4445 MAC2STR(wpa_s->pending_join_dev_addr));
4446 os_memcpy(wpa_s->pending_join_dev_addr, dev_addr,
4453 if (wpas_check_freq_conflict(wpa_s, freq) > 0) {
4454 wpa_msg_global(wpa_s->parent, MSG_INFO,
4455 P2P_EVENT_GROUP_FORMATION_FAILURE
4456 "reason=FREQ_CONFLICT");
4460 wpa_printf(MSG_DEBUG, "P2P: Send Provision Discovery Request "
4461 "prior to joining an existing group (GO " MACSTR
4463 MAC2STR(wpa_s->pending_join_dev_addr), freq);
4464 wpa_s->pending_pd_before_join = 1;
4466 switch (wpa_s->pending_join_wps_method) {
4467 case WPS_PIN_DISPLAY:
4468 method = WPS_CONFIG_KEYPAD;
4470 case WPS_PIN_KEYPAD:
4471 method = WPS_CONFIG_DISPLAY;
4474 method = WPS_CONFIG_PUSHBUTTON;
4481 if ((p2p_get_provisioning_info(wpa_s->global->p2p,
4482 wpa_s->pending_join_dev_addr) ==
4485 * We have already performed provision discovery for
4486 * joining the group. Proceed directly to join
4487 * operation without duplicated provision discovery. */
4488 wpa_printf(MSG_DEBUG, "P2P: Provision discovery "
4489 "with " MACSTR " already done - proceed to "
4491 MAC2STR(wpa_s->pending_join_dev_addr));
4492 wpa_s->pending_pd_before_join = 0;
4496 if (p2p_prov_disc_req(wpa_s->global->p2p,
4497 wpa_s->pending_join_dev_addr,
4499 freq, wpa_s->user_initiated_pd) < 0) {
4500 wpa_printf(MSG_DEBUG, "P2P: Failed to send Provision "
4501 "Discovery Request before joining an "
4503 wpa_s->pending_pd_before_join = 0;
4509 wpa_printf(MSG_DEBUG, "P2P: Failed to find BSS/GO - try again later");
4510 eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL);
4511 eloop_register_timeout(1, 0, wpas_p2p_join_scan, wpa_s, NULL);
4512 wpas_p2p_check_join_scan_limit(wpa_s);
4516 /* Start join operation immediately */
4517 wpas_p2p_join_start(wpa_s, 0, NULL, 0);
4521 static void wpas_p2p_join_scan_req(struct wpa_supplicant *wpa_s, int freq,
4522 const u8 *ssid, size_t ssid_len)
4525 struct wpa_driver_scan_params params;
4526 struct wpabuf *wps_ie, *ies;
4528 int freqs[2] = { 0, 0 };
4530 os_memset(¶ms, 0, sizeof(params));
4532 /* P2P Wildcard SSID */
4533 params.num_ssids = 1;
4534 if (ssid && ssid_len) {
4535 params.ssids[0].ssid = ssid;
4536 params.ssids[0].ssid_len = ssid_len;
4537 os_memcpy(wpa_s->p2p_join_ssid, ssid, ssid_len);
4538 wpa_s->p2p_join_ssid_len = ssid_len;
4540 params.ssids[0].ssid = (u8 *) P2P_WILDCARD_SSID;
4541 params.ssids[0].ssid_len = P2P_WILDCARD_SSID_LEN;
4542 wpa_s->p2p_join_ssid_len = 0;
4545 wpa_s->wps->dev.p2p = 1;
4546 wps_ie = wps_build_probe_req_ie(DEV_PW_DEFAULT, &wpa_s->wps->dev,
4547 wpa_s->wps->uuid, WPS_REQ_ENROLLEE, 0,
4549 if (wps_ie == NULL) {
4550 wpas_p2p_scan_res_join(wpa_s, NULL);
4554 ielen = p2p_scan_ie_buf_len(wpa_s->global->p2p);
4555 ies = wpabuf_alloc(wpabuf_len(wps_ie) + ielen);
4557 wpabuf_free(wps_ie);
4558 wpas_p2p_scan_res_join(wpa_s, NULL);
4561 wpabuf_put_buf(ies, wps_ie);
4562 wpabuf_free(wps_ie);
4564 p2p_scan_ie(wpa_s->global->p2p, ies, NULL);
4566 params.p2p_probe = 1;
4567 params.extra_ies = wpabuf_head(ies);
4568 params.extra_ies_len = wpabuf_len(ies);
4573 * If freq is not provided, check the operating freq of the GO
4574 * and use a single channel scan on if possible.
4576 oper_freq = p2p_get_oper_freq(wpa_s->global->p2p,
4577 wpa_s->pending_join_iface_addr);
4583 params.freqs = freqs;
4587 * Run a scan to update BSS table and start Provision Discovery once
4588 * the new scan results become available.
4590 ret = wpa_drv_scan(wpa_s, ¶ms);
4592 os_get_reltime(&wpa_s->scan_trigger_time);
4593 wpa_s->scan_res_handler = wpas_p2p_scan_res_join;
4594 wpa_s->own_scan_requested = 1;
4600 wpa_printf(MSG_DEBUG, "P2P: Failed to start scan for join - "
4602 eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL);
4603 eloop_register_timeout(1, 0, wpas_p2p_join_scan, wpa_s, NULL);
4604 wpas_p2p_check_join_scan_limit(wpa_s);
4609 static void wpas_p2p_join_scan(void *eloop_ctx, void *timeout_ctx)
4611 struct wpa_supplicant *wpa_s = eloop_ctx;
4612 wpas_p2p_join_scan_req(wpa_s, 0, NULL, 0);
4616 static int wpas_p2p_join(struct wpa_supplicant *wpa_s, const u8 *iface_addr,
4617 const u8 *dev_addr, enum p2p_wps_method wps_method,
4618 int auto_join, int op_freq,
4619 const u8 *ssid, size_t ssid_len)
4621 wpa_printf(MSG_DEBUG, "P2P: Request to join existing group (iface "
4622 MACSTR " dev " MACSTR " op_freq=%d)%s",
4623 MAC2STR(iface_addr), MAC2STR(dev_addr), op_freq,
4624 auto_join ? " (auto_join)" : "");
4625 if (ssid && ssid_len) {
4626 wpa_printf(MSG_DEBUG, "P2P: Group SSID specified: %s",
4627 wpa_ssid_txt(ssid, ssid_len));
4630 wpa_s->p2p_auto_pd = 0;
4631 wpa_s->p2p_auto_join = !!auto_join;
4632 os_memcpy(wpa_s->pending_join_iface_addr, iface_addr, ETH_ALEN);
4633 os_memcpy(wpa_s->pending_join_dev_addr, dev_addr, ETH_ALEN);
4634 wpa_s->pending_join_wps_method = wps_method;
4636 /* Make sure we are not running find during connection establishment */
4637 wpas_p2p_stop_find(wpa_s);
4639 wpa_s->p2p_join_scan_count = 0;
4640 wpas_p2p_join_scan_req(wpa_s, op_freq, ssid, ssid_len);
4645 static int wpas_p2p_join_start(struct wpa_supplicant *wpa_s, int freq,
4646 const u8 *ssid, size_t ssid_len)
4648 struct wpa_supplicant *group;
4649 struct p2p_go_neg_results res;
4650 struct wpa_bss *bss;
4652 group = wpas_p2p_get_group_iface(wpa_s, 0, 0);
4655 if (group != wpa_s) {
4656 os_memcpy(group->p2p_pin, wpa_s->p2p_pin,
4657 sizeof(group->p2p_pin));
4658 group->p2p_wps_method = wpa_s->p2p_wps_method;
4661 * Need to mark the current interface for p2p_group_formation
4662 * when a separate group interface is not used. This is needed
4663 * to allow p2p_cancel stop a pending p2p_connect-join.
4664 * wpas_p2p_init_group_interface() addresses this for the case
4665 * where a separate group interface is used.
4667 wpa_s->global->p2p_group_formation = wpa_s;
4670 group->p2p_in_provisioning = 1;
4671 group->p2p_fallback_to_go_neg = wpa_s->p2p_fallback_to_go_neg;
4673 os_memset(&res, 0, sizeof(res));
4674 os_memcpy(res.peer_device_addr, wpa_s->pending_join_dev_addr, ETH_ALEN);
4675 os_memcpy(res.peer_interface_addr, wpa_s->pending_join_iface_addr,
4677 res.wps_method = wpa_s->pending_join_wps_method;
4678 if (freq && ssid && ssid_len) {
4680 res.ssid_len = ssid_len;
4681 os_memcpy(res.ssid, ssid, ssid_len);
4683 bss = wpa_bss_get_bssid_latest(wpa_s,
4684 wpa_s->pending_join_iface_addr);
4686 res.freq = bss->freq;
4687 res.ssid_len = bss->ssid_len;
4688 os_memcpy(res.ssid, bss->ssid, bss->ssid_len);
4689 wpa_printf(MSG_DEBUG, "P2P: Join target GO operating frequency from BSS table: %d MHz (SSID %s)",
4691 wpa_ssid_txt(bss->ssid, bss->ssid_len));
4695 if (wpa_s->off_channel_freq || wpa_s->roc_waiting_drv_freq) {
4696 wpa_printf(MSG_DEBUG, "P2P: Cancel remain-on-channel prior to "
4698 wpa_drv_cancel_remain_on_channel(wpa_s);
4699 wpa_s->off_channel_freq = 0;
4700 wpa_s->roc_waiting_drv_freq = 0;
4702 wpas_start_wps_enrollee(group, &res);
4705 * Allow a longer timeout for join-a-running-group than normal 15
4706 * second group formation timeout since the GO may not have authorized
4707 * our connection yet.
4709 eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s, NULL);
4710 eloop_register_timeout(60, 0, wpas_p2p_group_formation_timeout,
4717 static int wpas_p2p_setup_freqs(struct wpa_supplicant *wpa_s, int freq,
4718 int *force_freq, int *pref_freq, int go)
4720 struct wpa_used_freq_data *freqs;
4721 int res, best_freq, num_unused;
4722 unsigned int freq_in_use = 0, num, i;
4724 freqs = os_calloc(wpa_s->num_multichan_concurrent,
4725 sizeof(struct wpa_used_freq_data));
4729 num = wpas_p2p_valid_oper_freqs(wpa_s, freqs,
4730 wpa_s->num_multichan_concurrent);
4733 * It is possible that the total number of used frequencies is bigger
4734 * than the number of frequencies used for P2P, so get the system wide
4735 * number of unused frequencies.
4737 num_unused = wpas_p2p_num_unused_channels(wpa_s);
4739 wpa_printf(MSG_DEBUG,
4740 "P2P: Setup freqs: freq=%d num_MCC=%d shared_freqs=%u num_unused=%d",
4741 freq, wpa_s->num_multichan_concurrent, num, num_unused);
4746 ret = p2p_supported_freq(wpa_s->global->p2p, freq);
4748 ret = p2p_supported_freq_cli(wpa_s->global->p2p, freq);
4750 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) &&
4751 ieee80211_is_dfs(freq)) {
4753 * If freq is a DFS channel and DFS is offloaded
4754 * to the driver, allow P2P GO to use it.
4756 wpa_printf(MSG_DEBUG,
4757 "P2P: The forced channel for GO (%u MHz) is DFS, and DFS is offloaded to the driver",
4760 wpa_printf(MSG_DEBUG,
4761 "P2P: The forced channel (%u MHz) is not supported for P2P uses",
4768 for (i = 0; i < num; i++) {
4769 if (freqs[i].freq == freq)
4773 if (num_unused <= 0 && !freq_in_use) {
4774 wpa_printf(MSG_DEBUG, "P2P: Cannot start P2P group on %u MHz as there are no available channels",
4779 wpa_printf(MSG_DEBUG, "P2P: Trying to force us to use the "
4780 "requested channel (%u MHz)", freq);
4785 best_freq = wpas_p2p_pick_best_used_freq(wpa_s, freqs, num);
4787 /* We have a candidate frequency to use */
4788 if (best_freq > 0) {
4789 if (*pref_freq == 0 && num_unused > 0) {
4790 wpa_printf(MSG_DEBUG, "P2P: Try to prefer a frequency (%u MHz) we are already using",
4792 *pref_freq = best_freq;
4794 wpa_printf(MSG_DEBUG, "P2P: Try to force us to use frequency (%u MHz) which is already in use",
4796 *force_freq = best_freq;
4798 } else if (num_unused > 0) {
4799 wpa_printf(MSG_DEBUG,
4800 "P2P: Current operating channels are not available for P2P. Try to use another channel");
4803 wpa_printf(MSG_DEBUG,
4804 "P2P: All channels are in use and none of them are P2P enabled. Cannot start P2P group");
4818 * wpas_p2p_connect - Request P2P Group Formation to be started
4819 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
4820 * @peer_addr: Address of the peer P2P Device
4821 * @pin: PIN to use during provisioning or %NULL to indicate PBC mode
4822 * @persistent_group: Whether to create a persistent group
4823 * @auto_join: Whether to select join vs. GO Negotiation automatically
4824 * @join: Whether to join an existing group (as a client) instead of starting
4825 * Group Owner negotiation; @peer_addr is BSSID in that case
4826 * @auth: Whether to only authorize the connection instead of doing that and
4827 * initiating Group Owner negotiation
4828 * @go_intent: GO Intent or -1 to use default
4829 * @freq: Frequency for the group or 0 for auto-selection
4830 * @persistent_id: Persistent group credentials to use for forcing GO
4831 * parameters or -1 to generate new values (SSID/passphrase)
4832 * @pd: Whether to send Provision Discovery prior to GO Negotiation as an
4833 * interoperability workaround when initiating group formation
4834 * @ht40: Start GO with 40 MHz channel width
4835 * @vht: Start GO with VHT support
4836 * Returns: 0 or new PIN (if pin was %NULL) on success, -1 on unspecified
4837 * failure, -2 on failure due to channel not currently available,
4838 * -3 if forced channel is not supported
4840 int wpas_p2p_connect(struct wpa_supplicant *wpa_s, const u8 *peer_addr,
4841 const char *pin, enum p2p_wps_method wps_method,
4842 int persistent_group, int auto_join, int join, int auth,
4843 int go_intent, int freq, int persistent_id, int pd,
4846 int force_freq = 0, pref_freq = 0;
4848 enum wpa_driver_if_type iftype;
4850 struct wpa_ssid *ssid = NULL;
4852 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
4855 if (persistent_id >= 0) {
4856 ssid = wpa_config_get_network(wpa_s->conf, persistent_id);
4857 if (ssid == NULL || ssid->disabled != 2 ||
4858 ssid->mode != WPAS_MODE_P2P_GO)
4862 os_free(wpa_s->global->add_psk);
4863 wpa_s->global->add_psk = NULL;
4865 wpa_s->global->p2p_fail_on_wps_complete = 0;
4866 wpa_s->global->pending_p2ps_group = 0;
4869 go_intent = wpa_s->conf->p2p_go_intent;
4872 wpa_s->p2p_long_listen = 0;
4874 wpa_s->p2p_wps_method = wps_method;
4875 wpa_s->p2p_persistent_group = !!persistent_group;
4876 wpa_s->p2p_persistent_id = persistent_id;
4877 wpa_s->p2p_go_intent = go_intent;
4878 wpa_s->p2p_connect_freq = freq;
4879 wpa_s->p2p_fallback_to_go_neg = 0;
4880 wpa_s->p2p_pd_before_go_neg = !!pd;
4881 wpa_s->p2p_go_ht40 = !!ht40;
4882 wpa_s->p2p_go_vht = !!vht;
4885 os_strlcpy(wpa_s->p2p_pin, pin, sizeof(wpa_s->p2p_pin));
4886 else if (wps_method == WPS_PIN_DISPLAY) {
4887 ret = wps_generate_pin();
4888 res = os_snprintf(wpa_s->p2p_pin, sizeof(wpa_s->p2p_pin),
4890 if (os_snprintf_error(sizeof(wpa_s->p2p_pin), res))
4891 wpa_s->p2p_pin[sizeof(wpa_s->p2p_pin) - 1] = '\0';
4892 wpa_printf(MSG_DEBUG, "P2P: Randomly generated PIN: %s",
4895 wpa_s->p2p_pin[0] = '\0';
4897 if (join || auto_join) {
4898 u8 iface_addr[ETH_ALEN], dev_addr[ETH_ALEN];
4900 wpa_printf(MSG_DEBUG, "P2P: Authorize invitation to "
4901 "connect a running group from " MACSTR,
4902 MAC2STR(peer_addr));
4903 os_memcpy(wpa_s->p2p_auth_invite, peer_addr, ETH_ALEN);
4906 os_memcpy(dev_addr, peer_addr, ETH_ALEN);
4907 if (p2p_get_interface_addr(wpa_s->global->p2p, peer_addr,
4909 os_memcpy(iface_addr, peer_addr, ETH_ALEN);
4910 p2p_get_dev_addr(wpa_s->global->p2p, peer_addr,
4914 os_get_reltime(&wpa_s->p2p_auto_started);
4915 wpa_printf(MSG_DEBUG, "P2P: Auto join started at "
4917 wpa_s->p2p_auto_started.sec,
4918 wpa_s->p2p_auto_started.usec);
4920 wpa_s->user_initiated_pd = 1;
4921 if (wpas_p2p_join(wpa_s, iface_addr, dev_addr, wps_method,
4922 auto_join, freq, NULL, 0) < 0)
4927 res = wpas_p2p_setup_freqs(wpa_s, freq, &force_freq, &pref_freq,
4931 wpas_p2p_set_own_freq_preference(wpa_s,
4932 force_freq ? force_freq : pref_freq);
4934 wpa_s->create_p2p_iface = wpas_p2p_create_iface(wpa_s);
4936 if (wpa_s->create_p2p_iface) {
4937 /* Prepare to add a new interface for the group */
4938 iftype = WPA_IF_P2P_GROUP;
4939 if (go_intent == 15)
4940 iftype = WPA_IF_P2P_GO;
4941 if (wpas_p2p_add_group_interface(wpa_s, iftype) < 0) {
4942 wpa_printf(MSG_ERROR, "P2P: Failed to allocate a new "
4943 "interface for the group");
4947 if_addr = wpa_s->pending_interface_addr;
4949 if_addr = wpa_s->own_addr;
4952 if (wpas_p2p_auth_go_neg(wpa_s, peer_addr, wps_method,
4954 force_freq, persistent_group, ssid,
4960 if (wpas_p2p_start_go_neg(wpa_s, peer_addr, wps_method,
4961 go_intent, if_addr, force_freq,
4962 persistent_group, ssid, pref_freq) < 0) {
4963 if (wpa_s->create_p2p_iface)
4964 wpas_p2p_remove_pending_group_interface(wpa_s);
4972 * wpas_p2p_remain_on_channel_cb - Indication of remain-on-channel start
4973 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
4974 * @freq: Frequency of the channel in MHz
4975 * @duration: Duration of the stay on the channel in milliseconds
4977 * This callback is called when the driver indicates that it has started the
4978 * requested remain-on-channel duration.
4980 void wpas_p2p_remain_on_channel_cb(struct wpa_supplicant *wpa_s,
4981 unsigned int freq, unsigned int duration)
4983 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
4985 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)",
4986 wpa_s->off_channel_freq, wpa_s->pending_listen_freq,
4987 wpa_s->roc_waiting_drv_freq, freq, duration);
4988 if (wpa_s->off_channel_freq &&
4989 wpa_s->off_channel_freq == wpa_s->pending_listen_freq) {
4990 p2p_listen_cb(wpa_s->global->p2p, wpa_s->pending_listen_freq,
4991 wpa_s->pending_listen_duration);
4992 wpa_s->pending_listen_freq = 0;
4994 wpa_printf(MSG_DEBUG, "P2P: Ignore remain-on-channel callback (off_channel_freq=%u pending_listen_freq=%d freq=%u duration=%u)",
4995 wpa_s->off_channel_freq, wpa_s->pending_listen_freq,
5001 int wpas_p2p_listen_start(struct wpa_supplicant *wpa_s, unsigned int timeout)
5003 /* Limit maximum Listen state time based on driver limitation. */
5004 if (timeout > wpa_s->max_remain_on_chan)
5005 timeout = wpa_s->max_remain_on_chan;
5007 return p2p_listen(wpa_s->global->p2p, timeout);
5012 * wpas_p2p_cancel_remain_on_channel_cb - Remain-on-channel timeout
5013 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
5014 * @freq: Frequency of the channel in MHz
5016 * This callback is called when the driver indicates that a remain-on-channel
5017 * operation has been completed, i.e., the duration on the requested channel
5020 void wpas_p2p_cancel_remain_on_channel_cb(struct wpa_supplicant *wpa_s,
5023 wpa_printf(MSG_DEBUG, "P2P: Cancel remain-on-channel callback "
5024 "(p2p_long_listen=%d ms pending_action_tx=%p)",
5025 wpa_s->p2p_long_listen, offchannel_pending_action_tx(wpa_s));
5026 wpas_p2p_listen_work_done(wpa_s);
5027 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
5029 if (wpa_s->p2p_long_listen > 0)
5030 wpa_s->p2p_long_listen -= wpa_s->max_remain_on_chan;
5031 if (p2p_listen_end(wpa_s->global->p2p, freq) > 0)
5032 return; /* P2P module started a new operation */
5033 if (offchannel_pending_action_tx(wpa_s))
5035 if (wpa_s->p2p_long_listen > 0) {
5036 wpa_printf(MSG_DEBUG, "P2P: Continuing long Listen state");
5037 wpas_p2p_listen_start(wpa_s, wpa_s->p2p_long_listen);
5040 * When listen duration is over, stop listen & update p2p_state
5043 p2p_stop_listen(wpa_s->global->p2p);
5049 * wpas_p2p_group_remove - Remove a P2P group
5050 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
5051 * @ifname: Network interface name of the group interface or "*" to remove all
5053 * Returns: 0 on success, -1 on failure
5055 * This function is used to remove a P2P group. This can be used to disconnect
5056 * from a group in which the local end is a P2P Client or to end a P2P Group in
5057 * case the local end is the Group Owner. If a virtual network interface was
5058 * created for this group, that interface will be removed. Otherwise, only the
5059 * configured P2P group network will be removed from the interface.
5061 int wpas_p2p_group_remove(struct wpa_supplicant *wpa_s, const char *ifname)
5063 struct wpa_global *global = wpa_s->global;
5064 struct wpa_supplicant *calling_wpa_s = wpa_s;
5066 if (os_strcmp(ifname, "*") == 0) {
5067 struct wpa_supplicant *prev;
5068 wpa_s = global->ifaces;
5071 wpa_s = wpa_s->next;
5072 if (prev->p2p_group_interface !=
5073 NOT_P2P_GROUP_INTERFACE ||
5074 (prev->current_ssid &&
5075 prev->current_ssid->p2p_group))
5076 wpas_p2p_disconnect_safely(prev, calling_wpa_s);
5081 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
5082 if (os_strcmp(wpa_s->ifname, ifname) == 0)
5086 return wpas_p2p_disconnect_safely(wpa_s, calling_wpa_s);
5090 static int wpas_p2p_select_go_freq(struct wpa_supplicant *wpa_s, int freq)
5095 wpa_printf(MSG_DEBUG, "P2P: Request to start GO on 2.4 GHz "
5097 if (wpa_s->best_24_freq > 0 &&
5098 p2p_supported_freq_go(wpa_s->global->p2p,
5099 wpa_s->best_24_freq)) {
5100 freq = wpa_s->best_24_freq;
5101 wpa_printf(MSG_DEBUG, "P2P: Use best 2.4 GHz band "
5102 "channel: %d MHz", freq);
5104 if (os_get_random((u8 *) &r, sizeof(r)) < 0)
5106 freq = 2412 + (r % 3) * 25;
5107 wpa_printf(MSG_DEBUG, "P2P: Use random 2.4 GHz band "
5108 "channel: %d MHz", freq);
5113 wpa_printf(MSG_DEBUG, "P2P: Request to start GO on 5 GHz "
5115 if (wpa_s->best_5_freq > 0 &&
5116 p2p_supported_freq_go(wpa_s->global->p2p,
5117 wpa_s->best_5_freq)) {
5118 freq = wpa_s->best_5_freq;
5119 wpa_printf(MSG_DEBUG, "P2P: Use best 5 GHz band "
5120 "channel: %d MHz", freq);
5122 if (os_get_random((u8 *) &r, sizeof(r)) < 0)
5124 freq = 5180 + (r % 4) * 20;
5125 if (!p2p_supported_freq_go(wpa_s->global->p2p, freq)) {
5126 wpa_printf(MSG_DEBUG, "P2P: Could not select "
5127 "5 GHz channel for P2P group");
5130 wpa_printf(MSG_DEBUG, "P2P: Use random 5 GHz band "
5131 "channel: %d MHz", freq);
5135 if (freq > 0 && !p2p_supported_freq_go(wpa_s->global->p2p, freq)) {
5136 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) &&
5137 ieee80211_is_dfs(freq)) {
5139 * If freq is a DFS channel and DFS is offloaded to the
5140 * driver, allow P2P GO to use it.
5142 wpa_printf(MSG_DEBUG, "P2P: "
5143 "%s: The forced channel for GO (%u MHz) is DFS, and DFS is offloaded",
5147 wpa_printf(MSG_DEBUG, "P2P: The forced channel for GO "
5148 "(%u MHz) is not supported for P2P uses",
5157 static int wpas_p2p_select_freq_no_pref(struct wpa_supplicant *wpa_s,
5158 struct p2p_go_neg_results *params,
5159 const struct p2p_channels *channels)
5163 /* first try some random selection of the social channels */
5164 if (os_get_random((u8 *) &r, sizeof(r)) < 0)
5167 for (i = 0; i < 3; i++) {
5168 params->freq = 2412 + ((r + i) % 3) * 25;
5169 if (!wpas_p2p_disallowed_freq(wpa_s->global, params->freq) &&
5170 freq_included(channels, params->freq) &&
5171 p2p_supported_freq(wpa_s->global->p2p, params->freq))
5175 /* try all channels in reg. class 81 */
5176 for (i = 0; i < 11; i++) {
5177 params->freq = 2412 + i * 5;
5178 if (!wpas_p2p_disallowed_freq(wpa_s->global, params->freq) &&
5179 freq_included(channels, params->freq) &&
5180 p2p_supported_freq(wpa_s->global->p2p, params->freq))
5184 /* try all channels in operating class 115 */
5185 for (i = 0; i < 4; i++) {
5186 params->freq = 5180 + i * 20;
5187 if (!wpas_p2p_disallowed_freq(wpa_s->global, params->freq) &&
5188 freq_included(channels, params->freq) &&
5189 p2p_supported_freq(wpa_s->global->p2p, params->freq))
5193 /* try all channels in operating class 124 */
5194 for (i = 0; i < 4; i++) {
5195 params->freq = 5745 + i * 20;
5196 if (!wpas_p2p_disallowed_freq(wpa_s->global, params->freq) &&
5197 freq_included(channels, params->freq) &&
5198 p2p_supported_freq(wpa_s->global->p2p, params->freq))
5202 /* try social channel class 180 channel 2 */
5203 params->freq = 58320 + 1 * 2160;
5204 if (!wpas_p2p_disallowed_freq(wpa_s->global, params->freq) &&
5205 freq_included(channels, params->freq) &&
5206 p2p_supported_freq(wpa_s->global->p2p, params->freq))
5209 /* try all channels in reg. class 180 */
5210 for (i = 0; i < 4; i++) {
5211 params->freq = 58320 + i * 2160;
5212 if (!wpas_p2p_disallowed_freq(wpa_s->global, params->freq) &&
5213 freq_included(channels, params->freq) &&
5214 p2p_supported_freq(wpa_s->global->p2p, params->freq))
5218 wpa_printf(MSG_DEBUG, "P2P: No 2.4, 5, or 60 GHz channel allowed");
5221 wpa_printf(MSG_DEBUG, "P2P: Set GO freq %d MHz (no preference known)",
5227 static int wpas_p2p_init_go_params(struct wpa_supplicant *wpa_s,
5228 struct p2p_go_neg_results *params,
5229 int freq, int ht40, int vht,
5230 const struct p2p_channels *channels)
5232 struct wpa_used_freq_data *freqs;
5233 unsigned int pref_freq, cand_freq;
5234 unsigned int num, i;
5236 os_memset(params, 0, sizeof(*params));
5237 params->role_go = 1;
5238 params->ht40 = ht40;
5241 if (!freq_included(channels, freq)) {
5242 wpa_printf(MSG_DEBUG, "P2P: Forced GO freq %d MHz not "
5246 wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on forced "
5247 "frequency %d MHz", freq);
5248 params->freq = freq;
5249 } else if (wpa_s->conf->p2p_oper_reg_class == 81 &&
5250 wpa_s->conf->p2p_oper_channel >= 1 &&
5251 wpa_s->conf->p2p_oper_channel <= 11 &&
5252 freq_included(channels,
5253 2407 + 5 * wpa_s->conf->p2p_oper_channel)) {
5254 params->freq = 2407 + 5 * wpa_s->conf->p2p_oper_channel;
5255 wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on configured "
5256 "frequency %d MHz", params->freq);
5257 } else if ((wpa_s->conf->p2p_oper_reg_class == 115 ||
5258 wpa_s->conf->p2p_oper_reg_class == 116 ||
5259 wpa_s->conf->p2p_oper_reg_class == 117 ||
5260 wpa_s->conf->p2p_oper_reg_class == 124 ||
5261 wpa_s->conf->p2p_oper_reg_class == 125 ||
5262 wpa_s->conf->p2p_oper_reg_class == 126 ||
5263 wpa_s->conf->p2p_oper_reg_class == 127) &&
5264 freq_included(channels,
5265 5000 + 5 * wpa_s->conf->p2p_oper_channel)) {
5266 params->freq = 5000 + 5 * wpa_s->conf->p2p_oper_channel;
5267 wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on configured "
5268 "frequency %d MHz", params->freq);
5269 } else if (wpa_s->conf->p2p_oper_channel == 0 &&
5270 wpa_s->best_overall_freq > 0 &&
5271 p2p_supported_freq_go(wpa_s->global->p2p,
5272 wpa_s->best_overall_freq) &&
5273 freq_included(channels, wpa_s->best_overall_freq)) {
5274 params->freq = wpa_s->best_overall_freq;
5275 wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on best overall "
5276 "channel %d MHz", params->freq);
5277 } else if (wpa_s->conf->p2p_oper_channel == 0 &&
5278 wpa_s->best_24_freq > 0 &&
5279 p2p_supported_freq_go(wpa_s->global->p2p,
5280 wpa_s->best_24_freq) &&
5281 freq_included(channels, wpa_s->best_24_freq)) {
5282 params->freq = wpa_s->best_24_freq;
5283 wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on best 2.4 GHz "
5284 "channel %d MHz", params->freq);
5285 } else if (wpa_s->conf->p2p_oper_channel == 0 &&
5286 wpa_s->best_5_freq > 0 &&
5287 p2p_supported_freq_go(wpa_s->global->p2p,
5288 wpa_s->best_5_freq) &&
5289 freq_included(channels, wpa_s->best_5_freq)) {
5290 params->freq = wpa_s->best_5_freq;
5291 wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on best 5 GHz "
5292 "channel %d MHz", params->freq);
5293 } else if ((pref_freq = p2p_get_pref_freq(wpa_s->global->p2p,
5295 params->freq = pref_freq;
5296 wpa_printf(MSG_DEBUG, "P2P: Set GO freq %d MHz from preferred "
5297 "channels", params->freq);
5299 /* no preference, select some channel */
5300 if (wpas_p2p_select_freq_no_pref(wpa_s, params, channels) < 0)
5304 freqs = os_calloc(wpa_s->num_multichan_concurrent,
5305 sizeof(struct wpa_used_freq_data));
5309 num = wpas_p2p_valid_oper_freqs(wpa_s, freqs,
5310 wpa_s->num_multichan_concurrent);
5312 cand_freq = wpas_p2p_pick_best_used_freq(wpa_s, freqs, num);
5314 /* First try the best used frequency if possible */
5315 if (!freq && cand_freq > 0 && freq_included(channels, cand_freq)) {
5316 params->freq = cand_freq;
5318 /* Try any of the used frequencies */
5319 for (i = 0; i < num; i++) {
5320 if (freq_included(channels, freqs[i].freq)) {
5321 wpa_printf(MSG_DEBUG, "P2P: Force GO on a channel we are already using (%u MHz)",
5323 params->freq = freqs[i].freq;
5329 if (wpas_p2p_num_unused_channels(wpa_s) <= 0) {
5330 wpa_printf(MSG_DEBUG, "P2P: Cannot force GO on any of the channels we are already using");
5334 wpa_printf(MSG_DEBUG, "P2P: Cannot force GO on any of the channels we are already using. Use one of the free channels");
5338 for (i = 0; i < num; i++) {
5339 if (freqs[i].freq == freq)
5344 if (wpas_p2p_num_unused_channels(wpa_s) <= 0) {
5346 wpa_printf(MSG_DEBUG, "P2P: Cannot force GO on freq (%u MHz) as all the channels are in use", freq);
5350 wpa_printf(MSG_DEBUG, "P2P: Use one of the free channels");
5360 static struct wpa_supplicant *
5361 wpas_p2p_get_group_iface(struct wpa_supplicant *wpa_s, int addr_allocated,
5364 struct wpa_supplicant *group_wpa_s;
5366 if (!wpas_p2p_create_iface(wpa_s)) {
5367 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Use same interface for group "
5369 wpa_s->p2p_first_connection_timeout = 0;
5373 if (wpas_p2p_add_group_interface(wpa_s, go ? WPA_IF_P2P_GO :
5374 WPA_IF_P2P_CLIENT) < 0) {
5375 wpa_msg_global(wpa_s, MSG_ERROR,
5376 "P2P: Failed to add group interface");
5379 group_wpa_s = wpas_p2p_init_group_interface(wpa_s, go);
5380 if (group_wpa_s == NULL) {
5381 wpa_msg_global(wpa_s, MSG_ERROR,
5382 "P2P: Failed to initialize group interface");
5383 wpas_p2p_remove_pending_group_interface(wpa_s);
5387 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Use separate group interface %s",
5388 group_wpa_s->ifname);
5389 group_wpa_s->p2p_first_connection_timeout = 0;
5395 * wpas_p2p_group_add - Add a new P2P group with local end as Group Owner
5396 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
5397 * @persistent_group: Whether to create a persistent group
5398 * @freq: Frequency for the group or 0 to indicate no hardcoding
5399 * @ht40: Start GO with 40 MHz channel width
5400 * @vht: Start GO with VHT support
5401 * Returns: 0 on success, -1 on failure
5403 * This function creates a new P2P group with the local end as the Group Owner,
5404 * i.e., without using Group Owner Negotiation.
5406 int wpas_p2p_group_add(struct wpa_supplicant *wpa_s, int persistent_group,
5407 int freq, int ht40, int vht)
5409 struct p2p_go_neg_results params;
5411 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
5414 os_free(wpa_s->global->add_psk);
5415 wpa_s->global->add_psk = NULL;
5417 /* Make sure we are not running find during connection establishment */
5418 wpa_printf(MSG_DEBUG, "P2P: Stop any on-going P2P FIND");
5419 wpas_p2p_stop_find_oper(wpa_s);
5421 freq = wpas_p2p_select_go_freq(wpa_s, freq);
5425 if (wpas_p2p_init_go_params(wpa_s, ¶ms, freq, ht40, vht, NULL))
5428 !p2p_supported_freq_go(wpa_s->global->p2p, params.freq)) {
5429 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) &&
5430 ieee80211_is_dfs(params.freq)) {
5432 * If freq is a DFS channel and DFS is offloaded to the
5433 * driver, allow P2P GO to use it.
5435 wpa_printf(MSG_DEBUG,
5436 "P2P: %s: The forced channel for GO (%u MHz) is DFS, and DFS is offloaded to driver",
5437 __func__, params.freq);
5439 wpa_printf(MSG_DEBUG,
5440 "P2P: The selected channel for GO (%u MHz) is not supported for P2P uses",
5445 p2p_go_params(wpa_s->global->p2p, ¶ms);
5446 params.persistent_group = persistent_group;
5448 wpa_s = wpas_p2p_get_group_iface(wpa_s, 0, 1);
5451 wpas_start_wps_go(wpa_s, ¶ms, 0);
5457 static int wpas_start_p2p_client(struct wpa_supplicant *wpa_s,
5458 struct wpa_ssid *params, int addr_allocated,
5461 struct wpa_ssid *ssid;
5463 wpa_s = wpas_p2p_get_group_iface(wpa_s, addr_allocated, 0);
5466 wpa_s->p2p_last_4way_hs_fail = NULL;
5468 wpa_supplicant_ap_deinit(wpa_s);
5470 ssid = wpa_config_add_network(wpa_s->conf);
5473 wpa_config_set_network_defaults(ssid);
5474 ssid->temporary = 1;
5475 ssid->proto = WPA_PROTO_RSN;
5476 ssid->pairwise_cipher = WPA_CIPHER_CCMP;
5477 ssid->group_cipher = WPA_CIPHER_CCMP;
5478 ssid->key_mgmt = WPA_KEY_MGMT_PSK;
5479 ssid->ssid = os_malloc(params->ssid_len);
5480 if (ssid->ssid == NULL) {
5481 wpa_config_remove_network(wpa_s->conf, ssid->id);
5484 os_memcpy(ssid->ssid, params->ssid, params->ssid_len);
5485 ssid->ssid_len = params->ssid_len;
5486 ssid->p2p_group = 1;
5487 ssid->export_keys = 1;
5488 if (params->psk_set) {
5489 os_memcpy(ssid->psk, params->psk, 32);
5492 if (params->passphrase)
5493 ssid->passphrase = os_strdup(params->passphrase);
5495 wpa_s->show_group_started = 1;
5496 wpa_s->p2p_in_invitation = 1;
5497 wpa_s->p2p_invite_go_freq = freq;
5499 eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s->parent,
5501 eloop_register_timeout(P2P_MAX_INITIAL_CONN_WAIT, 0,
5502 wpas_p2p_group_formation_timeout,
5503 wpa_s->parent, NULL);
5504 wpa_supplicant_select_network(wpa_s, ssid);
5510 int wpas_p2p_group_add_persistent(struct wpa_supplicant *wpa_s,
5511 struct wpa_ssid *ssid, int addr_allocated,
5512 int force_freq, int neg_freq, int ht40,
5513 int vht, const struct p2p_channels *channels,
5514 int connection_timeout)
5516 struct p2p_go_neg_results params;
5519 if (ssid->disabled != 2 || ssid->ssid == NULL)
5522 if (wpas_get_p2p_group(wpa_s, ssid->ssid, ssid->ssid_len, &go) &&
5523 go == (ssid->mode == WPAS_MODE_P2P_GO)) {
5524 wpa_printf(MSG_DEBUG, "P2P: Requested persistent group is "
5527 eloop_cancel_timeout(wpas_p2p_group_formation_timeout,
5528 wpa_s->parent, NULL)) {
5530 * This can happen if Invitation Response frame was lost
5531 * and the peer (GO of a persistent group) tries to
5532 * invite us again. Reschedule the timeout to avoid
5533 * terminating the wait for the connection too early
5534 * since we now know that the peer is still trying to
5535 * invite us instead of having already started the GO.
5537 wpa_printf(MSG_DEBUG,
5538 "P2P: Reschedule group formation timeout since peer is still trying to invite us");
5539 eloop_register_timeout(P2P_MAX_INITIAL_CONN_WAIT, 0,
5540 wpas_p2p_group_formation_timeout,
5541 wpa_s->parent, NULL);
5546 os_free(wpa_s->global->add_psk);
5547 wpa_s->global->add_psk = NULL;
5549 /* Make sure we are not running find during connection establishment */
5550 wpas_p2p_stop_find_oper(wpa_s);
5552 wpa_s->p2p_fallback_to_go_neg = 0;
5554 if (ssid->mode == WPAS_MODE_P2P_GO) {
5555 if (force_freq > 0) {
5556 freq = wpas_p2p_select_go_freq(wpa_s, force_freq);
5560 freq = wpas_p2p_select_go_freq(wpa_s, neg_freq);
5562 (freq > 0 && !freq_included(channels, freq)))
5565 } else if (ssid->mode == WPAS_MODE_INFRA) {
5567 if (freq <= 0 || !freq_included(channels, freq)) {
5568 struct os_reltime now;
5569 struct wpa_bss *bss =
5570 wpa_bss_get_p2p_dev_addr(wpa_s, ssid->bssid);
5572 os_get_reltime(&now);
5574 !os_reltime_expired(&now, &bss->last_update, 5) &&
5575 freq_included(channels, bss->freq))
5581 return wpas_start_p2p_client(wpa_s, ssid, addr_allocated, freq);
5586 if (wpas_p2p_init_go_params(wpa_s, ¶ms, freq, ht40, vht, channels))
5590 params.psk_set = ssid->psk_set;
5592 os_memcpy(params.psk, ssid->psk, sizeof(params.psk));
5593 if (ssid->passphrase) {
5594 if (os_strlen(ssid->passphrase) >= sizeof(params.passphrase)) {
5595 wpa_printf(MSG_ERROR, "P2P: Invalid passphrase in "
5596 "persistent group");
5599 os_strlcpy(params.passphrase, ssid->passphrase,
5600 sizeof(params.passphrase));
5602 os_memcpy(params.ssid, ssid->ssid, ssid->ssid_len);
5603 params.ssid_len = ssid->ssid_len;
5604 params.persistent_group = 1;
5606 wpa_s = wpas_p2p_get_group_iface(wpa_s, addr_allocated, 1);
5610 p2p_channels_to_freqs(channels, params.freq_list, P2P_MAX_CHANNELS);
5612 wpa_s->p2p_first_connection_timeout = connection_timeout;
5613 wpas_start_wps_go(wpa_s, ¶ms, 0);
5619 static void wpas_p2p_ie_update(void *ctx, struct wpabuf *beacon_ies,
5620 struct wpabuf *proberesp_ies)
5622 struct wpa_supplicant *wpa_s = ctx;
5623 if (wpa_s->ap_iface) {
5624 struct hostapd_data *hapd = wpa_s->ap_iface->bss[0];
5625 if (!(hapd->conf->p2p & P2P_GROUP_OWNER)) {
5626 wpabuf_free(beacon_ies);
5627 wpabuf_free(proberesp_ies);
5631 wpabuf_free(hapd->p2p_beacon_ie);
5632 hapd->p2p_beacon_ie = beacon_ies;
5634 wpabuf_free(hapd->p2p_probe_resp_ie);
5635 hapd->p2p_probe_resp_ie = proberesp_ies;
5637 wpabuf_free(beacon_ies);
5638 wpabuf_free(proberesp_ies);
5640 wpa_supplicant_ap_update_beacon(wpa_s);
5644 static void wpas_p2p_idle_update(void *ctx, int idle)
5646 struct wpa_supplicant *wpa_s = ctx;
5647 if (!wpa_s->ap_iface)
5649 wpa_printf(MSG_DEBUG, "P2P: GO - group %sidle", idle ? "" : "not ");
5651 if (wpa_s->global->p2p_fail_on_wps_complete &&
5652 wpa_s->p2p_in_provisioning) {
5653 wpas_p2p_grpform_fail_after_wps(wpa_s);
5656 wpas_p2p_set_group_idle_timeout(wpa_s);
5658 eloop_cancel_timeout(wpas_p2p_group_idle_timeout, wpa_s, NULL);
5662 struct p2p_group * wpas_p2p_group_init(struct wpa_supplicant *wpa_s,
5663 struct wpa_ssid *ssid)
5665 struct p2p_group *group;
5666 struct p2p_group_config *cfg;
5668 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
5671 cfg = os_zalloc(sizeof(*cfg));
5675 if (ssid->p2p_persistent_group && wpa_s->conf->persistent_reconnect)
5676 cfg->persistent_group = 2;
5677 else if (ssid->p2p_persistent_group)
5678 cfg->persistent_group = 1;
5679 os_memcpy(cfg->interface_addr, wpa_s->own_addr, ETH_ALEN);
5680 if (wpa_s->max_stations &&
5681 wpa_s->max_stations < wpa_s->conf->max_num_sta)
5682 cfg->max_clients = wpa_s->max_stations;
5684 cfg->max_clients = wpa_s->conf->max_num_sta;
5685 os_memcpy(cfg->ssid, ssid->ssid, ssid->ssid_len);
5686 cfg->ssid_len = ssid->ssid_len;
5687 cfg->freq = ssid->frequency;
5688 cfg->cb_ctx = wpa_s;
5689 cfg->ie_update = wpas_p2p_ie_update;
5690 cfg->idle_update = wpas_p2p_idle_update;
5692 group = p2p_group_init(wpa_s->global->p2p, cfg);
5695 if (ssid->mode != WPAS_MODE_P2P_GROUP_FORMATION)
5696 p2p_group_notif_formation_done(group);
5697 wpa_s->p2p_group = group;
5702 void wpas_p2p_wps_success(struct wpa_supplicant *wpa_s, const u8 *peer_addr,
5705 struct wpa_ssid *ssid = wpa_s->current_ssid;
5707 if (!wpa_s->p2p_in_provisioning) {
5708 wpa_printf(MSG_DEBUG, "P2P: Ignore WPS success event - P2P "
5709 "provisioning not in progress");
5713 if (ssid && ssid->mode == WPAS_MODE_INFRA) {
5714 u8 go_dev_addr[ETH_ALEN];
5715 os_memcpy(go_dev_addr, wpa_s->bssid, ETH_ALEN);
5716 wpas_p2p_persistent_group(wpa_s, go_dev_addr, ssid->ssid,
5718 /* Clear any stored provisioning info */
5719 p2p_clear_provisioning_info(wpa_s->global->p2p, go_dev_addr);
5722 eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s->parent,
5724 wpa_s->p2p_go_group_formation_completed = 1;
5725 if (ssid && ssid->mode == WPAS_MODE_INFRA) {
5727 * Use a separate timeout for initial data connection to
5728 * complete to allow the group to be removed automatically if
5729 * something goes wrong in this step before the P2P group idle
5730 * timeout mechanism is taken into use.
5732 wpa_dbg(wpa_s, MSG_DEBUG,
5733 "P2P: Re-start group formation timeout (%d seconds) as client for initial connection",
5734 P2P_MAX_INITIAL_CONN_WAIT);
5735 eloop_register_timeout(P2P_MAX_INITIAL_CONN_WAIT, 0,
5736 wpas_p2p_group_formation_timeout,
5737 wpa_s->parent, NULL);
5740 * Use a separate timeout for initial data connection to
5741 * complete to allow the group to be removed automatically if
5742 * the client does not complete data connection successfully.
5744 wpa_dbg(wpa_s, MSG_DEBUG,
5745 "P2P: Re-start group formation timeout (%d seconds) as GO for initial connection",
5746 P2P_MAX_INITIAL_CONN_WAIT_GO);
5747 eloop_register_timeout(P2P_MAX_INITIAL_CONN_WAIT_GO, 0,
5748 wpas_p2p_group_formation_timeout,
5749 wpa_s->parent, NULL);
5751 * Complete group formation on first successful data connection
5753 wpa_s->p2p_go_group_formation_completed = 0;
5755 if (wpa_s->global->p2p)
5756 p2p_wps_success_cb(wpa_s->global->p2p, peer_addr);
5757 wpas_group_formation_completed(wpa_s, 1, 0);
5761 void wpas_p2p_wps_failed(struct wpa_supplicant *wpa_s,
5762 struct wps_event_fail *fail)
5764 if (!wpa_s->p2p_in_provisioning) {
5765 wpa_printf(MSG_DEBUG, "P2P: Ignore WPS fail event - P2P "
5766 "provisioning not in progress");
5770 if (wpa_s->go_params) {
5771 p2p_clear_provisioning_info(
5773 wpa_s->go_params->peer_device_addr);
5776 wpas_notify_p2p_wps_failed(wpa_s, fail);
5778 if (wpa_s == wpa_s->global->p2p_group_formation) {
5780 * Allow some time for the failed WPS negotiation exchange to
5781 * complete, but remove the group since group formation cannot
5782 * succeed after provisioning failure.
5784 wpa_printf(MSG_DEBUG, "P2P: WPS step failed during group formation - reject connection from timeout");
5785 wpa_s->global->p2p_fail_on_wps_complete = 1;
5786 eloop_deplete_timeout(0, 50000,
5787 wpas_p2p_group_formation_timeout,
5788 wpa_s->parent, NULL);
5793 int wpas_p2p_wps_eapol_cb(struct wpa_supplicant *wpa_s)
5795 if (!wpa_s->global->p2p_fail_on_wps_complete ||
5796 !wpa_s->p2p_in_provisioning)
5799 wpas_p2p_grpform_fail_after_wps(wpa_s);
5805 int wpas_p2p_prov_disc(struct wpa_supplicant *wpa_s, const u8 *peer_addr,
5806 const char *config_method,
5807 enum wpas_p2p_prov_disc_use use,
5808 struct p2ps_provision *p2ps_prov)
5812 wpa_s->global->pending_p2ps_group = 0;
5813 wpa_s->p2p_fallback_to_go_neg = 0;
5814 wpa_s->pending_pd_use = NORMAL_PD;
5815 if (p2ps_prov && use == WPAS_P2P_PD_FOR_ASP) {
5816 p2ps_prov->conncap = p2ps_group_capability(
5817 wpa_s, P2PS_SETUP_NONE, p2ps_prov->role);
5818 wpa_printf(MSG_DEBUG,
5819 "P2P: %s conncap: %d - ASP parsed: %x %x %d %s",
5820 __func__, p2ps_prov->conncap,
5821 p2ps_prov->adv_id, p2ps_prov->conncap,
5822 p2ps_prov->status, p2ps_prov->info);
5825 } else if (os_strncmp(config_method, "display", 7) == 0)
5826 config_methods = WPS_CONFIG_DISPLAY;
5827 else if (os_strncmp(config_method, "keypad", 6) == 0)
5828 config_methods = WPS_CONFIG_KEYPAD;
5829 else if (os_strncmp(config_method, "pbc", 3) == 0 ||
5830 os_strncmp(config_method, "pushbutton", 10) == 0)
5831 config_methods = WPS_CONFIG_PUSHBUTTON;
5833 wpa_printf(MSG_DEBUG, "P2P: Unknown config method");
5838 if (use == WPAS_P2P_PD_AUTO) {
5839 os_memcpy(wpa_s->pending_join_dev_addr, peer_addr, ETH_ALEN);
5840 wpa_s->pending_pd_config_methods = config_methods;
5841 wpa_s->p2p_auto_pd = 1;
5842 wpa_s->p2p_auto_join = 0;
5843 wpa_s->pending_pd_before_join = 0;
5844 wpa_s->auto_pd_scan_retry = 0;
5845 wpas_p2p_stop_find(wpa_s);
5846 wpa_s->p2p_join_scan_count = 0;
5847 os_get_reltime(&wpa_s->p2p_auto_started);
5848 wpa_printf(MSG_DEBUG, "P2P: Auto PD started at %ld.%06ld",
5849 wpa_s->p2p_auto_started.sec,
5850 wpa_s->p2p_auto_started.usec);
5851 wpas_p2p_join_scan(wpa_s, NULL);
5855 if (wpa_s->global->p2p == NULL || wpa_s->global->p2p_disabled) {
5860 return p2p_prov_disc_req(wpa_s->global->p2p, peer_addr, p2ps_prov,
5861 config_methods, use == WPAS_P2P_PD_FOR_JOIN,
5866 int wpas_p2p_scan_result_text(const u8 *ies, size_t ies_len, char *buf,
5869 return p2p_scan_result_text(ies, ies_len, buf, end);
5873 static void wpas_p2p_clear_pending_action_tx(struct wpa_supplicant *wpa_s)
5875 if (!offchannel_pending_action_tx(wpa_s))
5878 wpas_p2p_action_tx_clear(wpa_s);
5880 wpa_printf(MSG_DEBUG, "P2P: Drop pending Action TX due to new "
5881 "operation request");
5882 offchannel_clear_pending_action_tx(wpa_s);
5886 int wpas_p2p_find(struct wpa_supplicant *wpa_s, unsigned int timeout,
5887 enum p2p_discovery_type type,
5888 unsigned int num_req_dev_types, const u8 *req_dev_types,
5889 const u8 *dev_id, unsigned int search_delay,
5890 u8 seek_cnt, const char **seek_string, int freq)
5892 wpas_p2p_clear_pending_action_tx(wpa_s);
5893 wpa_s->p2p_long_listen = 0;
5895 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL ||
5896 wpa_s->p2p_in_provisioning)
5899 wpa_supplicant_cancel_sched_scan(wpa_s);
5901 return p2p_find(wpa_s->global->p2p, timeout, type,
5902 num_req_dev_types, req_dev_types, dev_id,
5903 search_delay, seek_cnt, seek_string, freq);
5907 static void wpas_p2p_scan_res_ignore_search(struct wpa_supplicant *wpa_s,
5908 struct wpa_scan_results *scan_res)
5910 wpa_printf(MSG_DEBUG, "P2P: Ignore scan results");
5912 if (wpa_s->p2p_scan_work) {
5913 struct wpa_radio_work *work = wpa_s->p2p_scan_work;
5914 wpa_s->p2p_scan_work = NULL;
5915 radio_work_done(work);
5918 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
5922 * Indicate that results have been processed so that the P2P module can
5923 * continue pending tasks.
5925 p2p_scan_res_handled(wpa_s->global->p2p);
5929 static void wpas_p2p_stop_find_oper(struct wpa_supplicant *wpa_s)
5931 wpas_p2p_clear_pending_action_tx(wpa_s);
5932 wpa_s->p2p_long_listen = 0;
5933 eloop_cancel_timeout(wpas_p2p_long_listen_timeout, wpa_s, NULL);
5934 eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL);
5936 if (wpa_s->global->p2p)
5937 p2p_stop_find(wpa_s->global->p2p);
5939 if (wpa_s->scan_res_handler == wpas_p2p_scan_res_handler) {
5940 wpa_printf(MSG_DEBUG,
5941 "P2P: Do not consider the scan results after stop_find");
5942 wpa_s->scan_res_handler = wpas_p2p_scan_res_ignore_search;
5947 void wpas_p2p_stop_find(struct wpa_supplicant *wpa_s)
5949 wpas_p2p_stop_find_oper(wpa_s);
5950 if (!wpa_s->global->pending_group_iface_for_p2ps)
5951 wpas_p2p_remove_pending_group_interface(wpa_s);
5955 static void wpas_p2p_long_listen_timeout(void *eloop_ctx, void *timeout_ctx)
5957 struct wpa_supplicant *wpa_s = eloop_ctx;
5958 wpa_s->p2p_long_listen = 0;
5962 int wpas_p2p_listen(struct wpa_supplicant *wpa_s, unsigned int timeout)
5966 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
5969 wpa_supplicant_cancel_sched_scan(wpa_s);
5970 wpas_p2p_clear_pending_action_tx(wpa_s);
5974 * This is a request for unlimited Listen state. However, at
5975 * least for now, this is mapped to a Listen state for one
5980 eloop_cancel_timeout(wpas_p2p_long_listen_timeout, wpa_s, NULL);
5981 wpa_s->p2p_long_listen = 0;
5984 * Stop previous find/listen operation to avoid trying to request a new
5985 * remain-on-channel operation while the driver is still running the
5988 if (wpa_s->global->p2p)
5989 p2p_stop_find(wpa_s->global->p2p);
5991 res = wpas_p2p_listen_start(wpa_s, timeout * 1000);
5992 if (res == 0 && timeout * 1000 > wpa_s->max_remain_on_chan) {
5993 wpa_s->p2p_long_listen = timeout * 1000;
5994 eloop_register_timeout(timeout, 0,
5995 wpas_p2p_long_listen_timeout,
6003 int wpas_p2p_assoc_req_ie(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
6004 u8 *buf, size_t len, int p2p_group)
6006 struct wpabuf *p2p_ie;
6009 if (wpa_s->global->p2p_disabled)
6012 * Advertize mandatory cross connection capability even on
6013 * p2p_disabled=1 interface when associating with a P2P Manager WLAN AP.
6015 if (wpa_s->conf->p2p_disabled && p2p_group)
6017 if (wpa_s->global->p2p == NULL)
6022 p2p_ie = wpa_bss_get_vendor_ie_multi(bss, P2P_IE_VENDOR_TYPE);
6023 ret = p2p_assoc_req_ie(wpa_s->global->p2p, bss->bssid, buf, len,
6025 wpabuf_free(p2p_ie);
6031 int wpas_p2p_probe_req_rx(struct wpa_supplicant *wpa_s, const u8 *addr,
6032 const u8 *dst, const u8 *bssid,
6033 const u8 *ie, size_t ie_len,
6034 unsigned int rx_freq, int ssi_signal)
6036 if (wpa_s->global->p2p_disabled)
6038 if (wpa_s->global->p2p == NULL)
6041 switch (p2p_probe_req_rx(wpa_s->global->p2p, addr, dst, bssid,
6042 ie, ie_len, rx_freq)) {
6043 case P2P_PREQ_NOT_P2P:
6044 wpas_notify_preq(wpa_s, addr, dst, bssid, ie, ie_len,
6047 case P2P_PREQ_MALFORMED:
6048 case P2P_PREQ_NOT_LISTEN:
6049 case P2P_PREQ_NOT_PROCESSED:
6050 default: /* make gcc happy */
6052 case P2P_PREQ_PROCESSED:
6058 void wpas_p2p_rx_action(struct wpa_supplicant *wpa_s, const u8 *da,
6059 const u8 *sa, const u8 *bssid,
6060 u8 category, const u8 *data, size_t len, int freq)
6062 if (wpa_s->global->p2p_disabled)
6064 if (wpa_s->global->p2p == NULL)
6067 p2p_rx_action(wpa_s->global->p2p, da, sa, bssid, category, data, len,
6072 void wpas_p2p_scan_ie(struct wpa_supplicant *wpa_s, struct wpabuf *ies)
6074 if (wpa_s->global->p2p_disabled)
6076 if (wpa_s->global->p2p == NULL)
6079 p2p_scan_ie(wpa_s->global->p2p, ies, NULL);
6083 static void wpas_p2p_group_deinit(struct wpa_supplicant *wpa_s)
6085 p2p_group_deinit(wpa_s->p2p_group);
6086 wpa_s->p2p_group = NULL;
6088 wpa_s->ap_configured_cb = NULL;
6089 wpa_s->ap_configured_cb_ctx = NULL;
6090 wpa_s->ap_configured_cb_data = NULL;
6091 wpa_s->connect_without_scan = NULL;
6095 int wpas_p2p_reject(struct wpa_supplicant *wpa_s, const u8 *addr)
6097 wpa_s->p2p_long_listen = 0;
6099 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
6102 return p2p_reject(wpa_s->global->p2p, addr);
6106 /* Invite to reinvoke a persistent group */
6107 int wpas_p2p_invite(struct wpa_supplicant *wpa_s, const u8 *peer_addr,
6108 struct wpa_ssid *ssid, const u8 *go_dev_addr, int freq,
6109 int ht40, int vht, int pref_freq)
6111 enum p2p_invite_role role;
6115 int no_pref_freq_given = pref_freq == 0;
6117 wpa_s->global->p2p_invite_group = NULL;
6119 os_memcpy(wpa_s->p2p_auth_invite, peer_addr, ETH_ALEN);
6121 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
6123 wpa_s->p2p_persistent_go_freq = freq;
6124 wpa_s->p2p_go_ht40 = !!ht40;
6125 if (ssid->mode == WPAS_MODE_P2P_GO) {
6126 role = P2P_INVITE_ROLE_GO;
6127 if (peer_addr == NULL) {
6128 wpa_printf(MSG_DEBUG, "P2P: Missing peer "
6129 "address in invitation command");
6132 if (wpas_p2p_create_iface(wpa_s)) {
6133 if (wpas_p2p_add_group_interface(wpa_s,
6134 WPA_IF_P2P_GO) < 0) {
6135 wpa_printf(MSG_ERROR, "P2P: Failed to "
6136 "allocate a new interface for the "
6140 bssid = wpa_s->pending_interface_addr;
6142 bssid = wpa_s->own_addr;
6144 role = P2P_INVITE_ROLE_CLIENT;
6145 peer_addr = ssid->bssid;
6147 wpa_s->pending_invite_ssid_id = ssid->id;
6149 res = wpas_p2p_setup_freqs(wpa_s, freq, &force_freq, &pref_freq,
6150 role == P2P_INVITE_ROLE_GO);
6154 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
6157 if (wpa_s->parent->conf->p2p_ignore_shared_freq &&
6158 no_pref_freq_given && pref_freq > 0 &&
6159 wpa_s->num_multichan_concurrent > 1 &&
6160 wpas_p2p_num_unused_channels(wpa_s) > 0) {
6161 wpa_printf(MSG_DEBUG, "P2P: Ignore own channel preference %d MHz for invitation due to p2p_ignore_shared_freq=1 configuration",
6167 * Stop any find/listen operations before invitation and possibly
6168 * connection establishment.
6170 wpas_p2p_stop_find_oper(wpa_s);
6172 return p2p_invite(wpa_s->global->p2p, peer_addr, role, bssid,
6173 ssid->ssid, ssid->ssid_len, force_freq, go_dev_addr,
6178 /* Invite to join an active group */
6179 int wpas_p2p_invite_group(struct wpa_supplicant *wpa_s, const char *ifname,
6180 const u8 *peer_addr, const u8 *go_dev_addr)
6182 struct wpa_global *global = wpa_s->global;
6183 enum p2p_invite_role role;
6185 struct wpa_ssid *ssid;
6187 int freq = 0, force_freq = 0, pref_freq = 0;
6190 wpa_s->p2p_persistent_go_freq = 0;
6191 wpa_s->p2p_go_ht40 = 0;
6192 wpa_s->p2p_go_vht = 0;
6194 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
6195 if (os_strcmp(wpa_s->ifname, ifname) == 0)
6198 if (wpa_s == NULL) {
6199 wpa_printf(MSG_DEBUG, "P2P: Interface '%s' not found", ifname);
6203 ssid = wpa_s->current_ssid;
6205 wpa_printf(MSG_DEBUG, "P2P: No current SSID to use for "
6210 wpa_s->global->p2p_invite_group = wpa_s;
6211 persistent = ssid->p2p_persistent_group &&
6212 wpas_p2p_get_persistent(wpa_s->parent, peer_addr,
6213 ssid->ssid, ssid->ssid_len);
6215 if (ssid->mode == WPAS_MODE_P2P_GO) {
6216 role = P2P_INVITE_ROLE_ACTIVE_GO;
6217 bssid = wpa_s->own_addr;
6218 if (go_dev_addr == NULL)
6219 go_dev_addr = wpa_s->global->p2p_dev_addr;
6220 freq = ssid->frequency;
6222 role = P2P_INVITE_ROLE_CLIENT;
6223 if (wpa_s->wpa_state < WPA_ASSOCIATED) {
6224 wpa_printf(MSG_DEBUG, "P2P: Not associated - cannot "
6225 "invite to current group");
6228 bssid = wpa_s->bssid;
6229 if (go_dev_addr == NULL &&
6230 !is_zero_ether_addr(wpa_s->go_dev_addr))
6231 go_dev_addr = wpa_s->go_dev_addr;
6232 freq = wpa_s->current_bss ? wpa_s->current_bss->freq :
6233 (int) wpa_s->assoc_freq;
6235 wpa_s->parent->pending_invite_ssid_id = -1;
6237 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
6240 res = wpas_p2p_setup_freqs(wpa_s, freq, &force_freq, &pref_freq,
6241 role == P2P_INVITE_ROLE_ACTIVE_GO);
6244 wpas_p2p_set_own_freq_preference(wpa_s, force_freq);
6246 return p2p_invite(wpa_s->global->p2p, peer_addr, role, bssid,
6247 ssid->ssid, ssid->ssid_len, force_freq,
6248 go_dev_addr, persistent, pref_freq, -1);
6252 void wpas_p2p_completed(struct wpa_supplicant *wpa_s)
6254 struct wpa_ssid *ssid = wpa_s->current_ssid;
6255 u8 go_dev_addr[ETH_ALEN];
6256 int network_id = -1;
6262 if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GROUP_FORMATION) {
6263 eloop_cancel_timeout(wpas_p2p_group_formation_timeout,
6264 wpa_s->parent, NULL);
6267 if (!wpa_s->show_group_started || !ssid)
6270 wpa_s->show_group_started = 0;
6272 os_memset(go_dev_addr, 0, ETH_ALEN);
6273 if (ssid->bssid_set)
6274 os_memcpy(go_dev_addr, ssid->bssid, ETH_ALEN);
6275 persistent = wpas_p2p_persistent_group(wpa_s, go_dev_addr, ssid->ssid,
6277 os_memcpy(wpa_s->go_dev_addr, go_dev_addr, ETH_ALEN);
6279 if (wpa_s->global->p2p_group_formation == wpa_s)
6280 wpa_s->global->p2p_group_formation = NULL;
6282 freq = wpa_s->current_bss ? wpa_s->current_bss->freq :
6283 (int) wpa_s->assoc_freq;
6286 if (wpa_sm_get_p2p_ip_addr(wpa_s->wpa, ip) == 0) {
6289 res = os_snprintf(ip_addr, sizeof(ip_addr),
6290 " ip_addr=%u.%u.%u.%u "
6291 "ip_mask=%u.%u.%u.%u go_ip_addr=%u.%u.%u.%u",
6292 ip[0], ip[1], ip[2], ip[3],
6293 ip[4], ip[5], ip[6], ip[7],
6294 ip[8], ip[9], ip[10], ip[11]);
6295 if (os_snprintf_error(sizeof(ip_addr), res))
6299 wpas_p2p_group_started(wpa_s, 0, ssid, freq,
6300 ssid->passphrase == NULL && ssid->psk_set ?
6302 ssid->passphrase, go_dev_addr, persistent,
6306 network_id = wpas_p2p_store_persistent_group(wpa_s->parent,
6309 network_id = ssid->id;
6310 wpas_notify_p2p_group_started(wpa_s, ssid, network_id, 1);
6314 int wpas_p2p_presence_req(struct wpa_supplicant *wpa_s, u32 duration1,
6315 u32 interval1, u32 duration2, u32 interval2)
6319 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
6322 if (wpa_s->wpa_state < WPA_ASSOCIATED ||
6323 wpa_s->current_ssid == NULL ||
6324 wpa_s->current_ssid->mode != WPAS_MODE_INFRA)
6327 ret = p2p_presence_req(wpa_s->global->p2p, wpa_s->bssid,
6328 wpa_s->own_addr, wpa_s->assoc_freq,
6329 duration1, interval1, duration2, interval2);
6331 wpa_s->waiting_presence_resp = 1;
6337 int wpas_p2p_ext_listen(struct wpa_supplicant *wpa_s, unsigned int period,
6338 unsigned int interval)
6340 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
6343 return p2p_ext_listen(wpa_s->global->p2p, period, interval);
6347 static int wpas_p2p_is_client(struct wpa_supplicant *wpa_s)
6349 if (wpa_s->current_ssid == NULL) {
6351 * current_ssid can be cleared when P2P client interface gets
6352 * disconnected, so assume this interface was used as P2P
6357 return wpa_s->current_ssid->p2p_group &&
6358 wpa_s->current_ssid->mode == WPAS_MODE_INFRA;
6362 static void wpas_p2p_group_idle_timeout(void *eloop_ctx, void *timeout_ctx)
6364 struct wpa_supplicant *wpa_s = eloop_ctx;
6366 if (wpa_s->conf->p2p_group_idle == 0 && !wpas_p2p_is_client(wpa_s)) {
6367 wpa_printf(MSG_DEBUG, "P2P: Ignore group idle timeout - "
6372 wpa_printf(MSG_DEBUG, "P2P: Group idle timeout reached - terminate "
6374 wpas_p2p_group_delete(wpa_s, P2P_GROUP_REMOVAL_IDLE_TIMEOUT);
6378 static void wpas_p2p_set_group_idle_timeout(struct wpa_supplicant *wpa_s)
6382 if (eloop_cancel_timeout(wpas_p2p_group_idle_timeout, wpa_s, NULL) > 0)
6383 wpa_printf(MSG_DEBUG, "P2P: Cancelled P2P group idle timeout");
6385 if (wpa_s->current_ssid == NULL || !wpa_s->current_ssid->p2p_group)
6388 timeout = wpa_s->conf->p2p_group_idle;
6389 if (wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
6390 (timeout == 0 || timeout > P2P_MAX_CLIENT_IDLE))
6391 timeout = P2P_MAX_CLIENT_IDLE;
6397 if (wpa_s->current_ssid->mode == WPAS_MODE_INFRA)
6398 timeout = 0; /* special client mode no-timeout */
6403 if (wpa_s->p2p_in_provisioning) {
6405 * Use the normal group formation timeout during the
6406 * provisioning phase to avoid terminating this process too
6407 * early due to group idle timeout.
6409 wpa_printf(MSG_DEBUG, "P2P: Do not use P2P group idle timeout "
6410 "during provisioning");
6414 if (wpa_s->show_group_started) {
6416 * Use the normal group formation timeout between the end of
6417 * the provisioning phase and completion of 4-way handshake to
6418 * avoid terminating this process too early due to group idle
6421 wpa_printf(MSG_DEBUG, "P2P: Do not use P2P group idle timeout "
6422 "while waiting for initial 4-way handshake to "
6427 wpa_printf(MSG_DEBUG, "P2P: Set P2P group idle timeout to %u seconds",
6429 eloop_register_timeout(timeout, 0, wpas_p2p_group_idle_timeout,
6434 /* Returns 1 if the interface was removed */
6435 int wpas_p2p_deauth_notif(struct wpa_supplicant *wpa_s, const u8 *bssid,
6436 u16 reason_code, const u8 *ie, size_t ie_len,
6437 int locally_generated)
6439 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
6442 if (!locally_generated)
6443 p2p_deauth_notif(wpa_s->global->p2p, bssid, reason_code, ie,
6446 if (reason_code == WLAN_REASON_DEAUTH_LEAVING && !locally_generated &&
6447 wpa_s->current_ssid &&
6448 wpa_s->current_ssid->p2p_group &&
6449 wpa_s->current_ssid->mode == WPAS_MODE_INFRA) {
6450 wpa_printf(MSG_DEBUG, "P2P: GO indicated that the P2P Group "
6451 "session is ending");
6452 if (wpas_p2p_group_delete(wpa_s,
6453 P2P_GROUP_REMOVAL_GO_ENDING_SESSION)
6462 void wpas_p2p_disassoc_notif(struct wpa_supplicant *wpa_s, const u8 *bssid,
6463 u16 reason_code, const u8 *ie, size_t ie_len,
6464 int locally_generated)
6466 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
6469 if (!locally_generated)
6470 p2p_disassoc_notif(wpa_s->global->p2p, bssid, reason_code, ie,
6475 void wpas_p2p_update_config(struct wpa_supplicant *wpa_s)
6477 struct p2p_data *p2p = wpa_s->global->p2p;
6482 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_CAPABLE))
6485 if (wpa_s->conf->changed_parameters & CFG_CHANGED_DEVICE_NAME)
6486 p2p_set_dev_name(p2p, wpa_s->conf->device_name);
6488 if (wpa_s->conf->changed_parameters & CFG_CHANGED_DEVICE_TYPE)
6489 p2p_set_pri_dev_type(p2p, wpa_s->conf->device_type);
6492 (wpa_s->conf->changed_parameters & CFG_CHANGED_CONFIG_METHODS))
6493 p2p_set_config_methods(p2p, wpa_s->wps->config_methods);
6495 if (wpa_s->wps && (wpa_s->conf->changed_parameters & CFG_CHANGED_UUID))
6496 p2p_set_uuid(p2p, wpa_s->wps->uuid);
6498 if (wpa_s->conf->changed_parameters & CFG_CHANGED_WPS_STRING) {
6499 p2p_set_manufacturer(p2p, wpa_s->conf->manufacturer);
6500 p2p_set_model_name(p2p, wpa_s->conf->model_name);
6501 p2p_set_model_number(p2p, wpa_s->conf->model_number);
6502 p2p_set_serial_number(p2p, wpa_s->conf->serial_number);
6505 if (wpa_s->conf->changed_parameters & CFG_CHANGED_SEC_DEVICE_TYPE)
6506 p2p_set_sec_dev_types(p2p,
6507 (void *) wpa_s->conf->sec_device_type,
6508 wpa_s->conf->num_sec_device_types);
6510 if (wpa_s->conf->changed_parameters & CFG_CHANGED_VENDOR_EXTENSION) {
6512 p2p_remove_wps_vendor_extensions(p2p);
6513 for (i = 0; i < MAX_WPS_VENDOR_EXT; i++) {
6514 if (wpa_s->conf->wps_vendor_ext[i] == NULL)
6516 p2p_add_wps_vendor_extension(
6517 p2p, wpa_s->conf->wps_vendor_ext[i]);
6521 if ((wpa_s->conf->changed_parameters & CFG_CHANGED_COUNTRY) &&
6522 wpa_s->conf->country[0] && wpa_s->conf->country[1]) {
6524 country[0] = wpa_s->conf->country[0];
6525 country[1] = wpa_s->conf->country[1];
6527 p2p_set_country(p2p, country);
6530 if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_SSID_POSTFIX) {
6531 p2p_set_ssid_postfix(p2p, (u8 *) wpa_s->conf->p2p_ssid_postfix,
6532 wpa_s->conf->p2p_ssid_postfix ?
6533 os_strlen(wpa_s->conf->p2p_ssid_postfix) :
6537 if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_INTRA_BSS)
6538 p2p_set_intra_bss_dist(p2p, wpa_s->conf->p2p_intra_bss);
6540 if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_LISTEN_CHANNEL) {
6541 u8 reg_class, channel;
6546 if (wpa_s->conf->p2p_listen_reg_class &&
6547 wpa_s->conf->p2p_listen_channel) {
6548 reg_class = wpa_s->conf->p2p_listen_reg_class;
6549 channel = wpa_s->conf->p2p_listen_channel;
6554 * Pick one of the social channels randomly as the
6557 if (os_get_random((u8 *) &r, sizeof(r)) < 0)
6560 channel = 1 + (r % 3) * 5;
6563 ret = p2p_set_listen_channel(p2p, reg_class, channel,
6566 wpa_printf(MSG_ERROR, "P2P: Own listen channel update "
6569 if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_OPER_CHANNEL) {
6570 u8 op_reg_class, op_channel, cfg_op_channel;
6573 if (wpa_s->conf->p2p_oper_reg_class &&
6574 wpa_s->conf->p2p_oper_channel) {
6575 op_reg_class = wpa_s->conf->p2p_oper_reg_class;
6576 op_channel = wpa_s->conf->p2p_oper_channel;
6581 * Use random operation channel from (1, 6, 11)
6582 *if no other preference is indicated.
6584 if (os_get_random((u8 *) &r, sizeof(r)) < 0)
6587 op_channel = 1 + (r % 3) * 5;
6590 ret = p2p_set_oper_channel(p2p, op_reg_class, op_channel,
6593 wpa_printf(MSG_ERROR, "P2P: Own oper channel update "
6597 if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_PREF_CHAN) {
6598 if (p2p_set_pref_chan(p2p, wpa_s->conf->num_p2p_pref_chan,
6599 wpa_s->conf->p2p_pref_chan) < 0) {
6600 wpa_printf(MSG_ERROR, "P2P: Preferred channel list "
6604 if (p2p_set_no_go_freq(p2p, &wpa_s->conf->p2p_no_go_freq) < 0) {
6605 wpa_printf(MSG_ERROR, "P2P: No GO channel list "
6610 if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_PASSPHRASE_LEN)
6611 p2p_set_passphrase_len(p2p, wpa_s->conf->p2p_passphrase_len);
6615 int wpas_p2p_set_noa(struct wpa_supplicant *wpa_s, u8 count, int start,
6618 if (!wpa_s->ap_iface)
6620 return hostapd_p2p_set_noa(wpa_s->ap_iface->bss[0], count, start,
6625 int wpas_p2p_set_cross_connect(struct wpa_supplicant *wpa_s, int enabled)
6627 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
6630 wpa_s->global->cross_connection = enabled;
6631 p2p_set_cross_connect(wpa_s->global->p2p, enabled);
6634 struct wpa_supplicant *iface;
6636 for (iface = wpa_s->global->ifaces; iface; iface = iface->next)
6638 if (iface->cross_connect_enabled == 0)
6641 iface->cross_connect_enabled = 0;
6642 iface->cross_connect_in_use = 0;
6643 wpa_msg_global(iface->parent, MSG_INFO,
6644 P2P_EVENT_CROSS_CONNECT_DISABLE "%s %s",
6646 iface->cross_connect_uplink);
6654 static void wpas_p2p_enable_cross_connect(struct wpa_supplicant *uplink)
6656 struct wpa_supplicant *iface;
6658 if (!uplink->global->cross_connection)
6661 for (iface = uplink->global->ifaces; iface; iface = iface->next) {
6662 if (!iface->cross_connect_enabled)
6664 if (os_strcmp(uplink->ifname, iface->cross_connect_uplink) !=
6667 if (iface->ap_iface == NULL)
6669 if (iface->cross_connect_in_use)
6672 iface->cross_connect_in_use = 1;
6673 wpa_msg_global(iface->parent, MSG_INFO,
6674 P2P_EVENT_CROSS_CONNECT_ENABLE "%s %s",
6675 iface->ifname, iface->cross_connect_uplink);
6680 static void wpas_p2p_disable_cross_connect(struct wpa_supplicant *uplink)
6682 struct wpa_supplicant *iface;
6684 for (iface = uplink->global->ifaces; iface; iface = iface->next) {
6685 if (!iface->cross_connect_enabled)
6687 if (os_strcmp(uplink->ifname, iface->cross_connect_uplink) !=
6690 if (!iface->cross_connect_in_use)
6693 wpa_msg_global(iface->parent, MSG_INFO,
6694 P2P_EVENT_CROSS_CONNECT_DISABLE "%s %s",
6695 iface->ifname, iface->cross_connect_uplink);
6696 iface->cross_connect_in_use = 0;
6701 void wpas_p2p_notif_connected(struct wpa_supplicant *wpa_s)
6703 if (wpa_s->ap_iface || wpa_s->current_ssid == NULL ||
6704 wpa_s->current_ssid->mode != WPAS_MODE_INFRA ||
6705 wpa_s->cross_connect_disallowed)
6706 wpas_p2p_disable_cross_connect(wpa_s);
6708 wpas_p2p_enable_cross_connect(wpa_s);
6709 if (!wpa_s->ap_iface &&
6710 eloop_cancel_timeout(wpas_p2p_group_idle_timeout, wpa_s, NULL) > 0)
6711 wpa_printf(MSG_DEBUG, "P2P: Cancelled P2P group idle timeout");
6715 void wpas_p2p_notif_disconnected(struct wpa_supplicant *wpa_s)
6717 wpas_p2p_disable_cross_connect(wpa_s);
6718 if (!wpa_s->ap_iface &&
6719 !eloop_is_timeout_registered(wpas_p2p_group_idle_timeout,
6721 wpas_p2p_set_group_idle_timeout(wpa_s);
6725 static void wpas_p2p_cross_connect_setup(struct wpa_supplicant *wpa_s)
6727 struct wpa_supplicant *iface;
6729 if (!wpa_s->global->cross_connection)
6732 for (iface = wpa_s->global->ifaces; iface; iface = iface->next) {
6735 if (iface->drv_flags &
6736 WPA_DRIVER_FLAGS_P2P_DEDICATED_INTERFACE)
6738 if ((iface->drv_flags & WPA_DRIVER_FLAGS_P2P_CAPABLE) &&
6739 iface != wpa_s->parent)
6742 wpa_s->cross_connect_enabled = 1;
6743 os_strlcpy(wpa_s->cross_connect_uplink, iface->ifname,
6744 sizeof(wpa_s->cross_connect_uplink));
6745 wpa_printf(MSG_DEBUG, "P2P: Enable cross connection from "
6746 "%s to %s whenever uplink is available",
6747 wpa_s->ifname, wpa_s->cross_connect_uplink);
6749 if (iface->ap_iface || iface->current_ssid == NULL ||
6750 iface->current_ssid->mode != WPAS_MODE_INFRA ||
6751 iface->cross_connect_disallowed ||
6752 iface->wpa_state != WPA_COMPLETED)
6755 wpa_s->cross_connect_in_use = 1;
6756 wpa_msg_global(wpa_s->parent, MSG_INFO,
6757 P2P_EVENT_CROSS_CONNECT_ENABLE "%s %s",
6758 wpa_s->ifname, wpa_s->cross_connect_uplink);
6764 int wpas_p2p_notif_pbc_overlap(struct wpa_supplicant *wpa_s)
6766 if (wpa_s->p2p_group_interface != P2P_GROUP_INTERFACE_CLIENT &&
6767 !wpa_s->p2p_in_provisioning)
6768 return 0; /* not P2P client operation */
6770 wpa_printf(MSG_DEBUG, "P2P: Terminate connection due to WPS PBC "
6772 if (wpa_s != wpa_s->parent)
6773 wpa_msg_ctrl(wpa_s->parent, MSG_INFO, WPS_EVENT_OVERLAP);
6774 wpas_p2p_group_formation_failed(wpa_s, 0);
6779 void wpas_p2p_pbc_overlap_cb(void *eloop_ctx, void *timeout_ctx)
6781 struct wpa_supplicant *wpa_s = eloop_ctx;
6782 wpas_p2p_notif_pbc_overlap(wpa_s);
6786 void wpas_p2p_update_channel_list(struct wpa_supplicant *wpa_s)
6788 struct p2p_channels chan, cli_chan;
6789 struct wpa_supplicant *ifs;
6791 if (wpa_s->global == NULL || wpa_s->global->p2p == NULL)
6794 os_memset(&chan, 0, sizeof(chan));
6795 os_memset(&cli_chan, 0, sizeof(cli_chan));
6796 if (wpas_p2p_setup_channels(wpa_s, &chan, &cli_chan)) {
6797 wpa_printf(MSG_ERROR, "P2P: Failed to update supported "
6802 p2p_update_channel_list(wpa_s->global->p2p, &chan, &cli_chan);
6804 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
6806 if (!ifs->current_ssid ||
6807 !ifs->current_ssid->p2p_group ||
6808 (ifs->current_ssid->mode != WPAS_MODE_P2P_GO &&
6809 ifs->current_ssid->mode != WPAS_MODE_P2P_GROUP_FORMATION))
6811 freq = ifs->current_ssid->frequency;
6812 if (freq_included(&chan, freq)) {
6813 wpa_dbg(ifs, MSG_DEBUG,
6814 "P2P GO operating frequency %d MHz in valid range",
6819 wpa_dbg(ifs, MSG_DEBUG,
6820 "P2P GO operating in invalid frequency %d MHz", freq);
6821 /* TODO: Consider using CSA or removing the group within
6823 wpa_msg(ifs, MSG_INFO, P2P_EVENT_REMOVE_AND_REFORM_GROUP);
6828 static void wpas_p2p_scan_res_ignore(struct wpa_supplicant *wpa_s,
6829 struct wpa_scan_results *scan_res)
6831 wpa_printf(MSG_DEBUG, "P2P: Ignore scan results");
6835 int wpas_p2p_cancel(struct wpa_supplicant *wpa_s)
6837 struct wpa_global *global = wpa_s->global;
6841 if (global->p2p == NULL)
6844 wpa_printf(MSG_DEBUG, "P2P: Request to cancel group formation");
6846 if (wpa_s->pending_interface_name[0] &&
6847 !is_zero_ether_addr(wpa_s->pending_interface_addr))
6850 peer = p2p_get_go_neg_peer(global->p2p);
6852 wpa_printf(MSG_DEBUG, "P2P: Unauthorize pending GO Neg peer "
6853 MACSTR, MAC2STR(peer));
6854 p2p_unauthorize(global->p2p, peer);
6858 if (wpa_s->scan_res_handler == wpas_p2p_scan_res_join) {
6859 wpa_printf(MSG_DEBUG, "P2P: Stop pending scan for join");
6860 wpa_s->scan_res_handler = wpas_p2p_scan_res_ignore;
6864 if (wpa_s->pending_pd_before_join) {
6865 wpa_printf(MSG_DEBUG, "P2P: Stop pending PD before join");
6866 wpa_s->pending_pd_before_join = 0;
6870 wpas_p2p_stop_find(wpa_s);
6872 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
6873 if (wpa_s == global->p2p_group_formation &&
6874 (wpa_s->p2p_in_provisioning ||
6875 wpa_s->parent->pending_interface_type ==
6876 WPA_IF_P2P_CLIENT)) {
6877 wpa_printf(MSG_DEBUG, "P2P: Interface %s in group "
6878 "formation found - cancelling",
6881 eloop_cancel_timeout(wpas_p2p_group_formation_timeout,
6882 wpa_s->parent, NULL);
6883 if (wpa_s->p2p_in_provisioning) {
6884 wpas_group_formation_completed(wpa_s, 0, 0);
6887 wpas_p2p_group_delete(wpa_s,
6888 P2P_GROUP_REMOVAL_REQUESTED);
6890 } else if (wpa_s->p2p_in_invitation) {
6891 wpa_printf(MSG_DEBUG, "P2P: Interface %s in invitation found - cancelling",
6894 wpas_p2p_group_formation_failed(wpa_s, 0);
6899 wpa_printf(MSG_DEBUG, "P2P: No ongoing group formation found");
6907 void wpas_p2p_interface_unavailable(struct wpa_supplicant *wpa_s)
6909 if (wpa_s->current_ssid == NULL || !wpa_s->current_ssid->p2p_group)
6912 wpa_printf(MSG_DEBUG, "P2P: Remove group due to driver resource not "
6913 "being available anymore");
6914 wpas_p2p_group_delete(wpa_s, P2P_GROUP_REMOVAL_UNAVAILABLE);
6918 void wpas_p2p_update_best_channels(struct wpa_supplicant *wpa_s,
6919 int freq_24, int freq_5, int freq_overall)
6921 struct p2p_data *p2p = wpa_s->global->p2p;
6924 p2p_set_best_channels(p2p, freq_24, freq_5, freq_overall);
6928 int wpas_p2p_unauthorize(struct wpa_supplicant *wpa_s, const char *addr)
6931 struct p2p_data *p2p = wpa_s->global->p2p;
6936 if (hwaddr_aton(addr, peer))
6939 return p2p_unauthorize(p2p, peer);
6944 * wpas_p2p_disconnect - Disconnect from a P2P Group
6945 * @wpa_s: Pointer to wpa_supplicant data
6946 * Returns: 0 on success, -1 on failure
6948 * This can be used to disconnect from a group in which the local end is a P2P
6949 * Client or to end a P2P Group in case the local end is the Group Owner. If a
6950 * virtual network interface was created for this group, that interface will be
6951 * removed. Otherwise, only the configured P2P group network will be removed
6952 * from the interface.
6954 int wpas_p2p_disconnect(struct wpa_supplicant *wpa_s)
6960 return wpas_p2p_group_delete(wpa_s, P2P_GROUP_REMOVAL_REQUESTED) < 0 ?
6965 int wpas_p2p_in_progress(struct wpa_supplicant *wpa_s)
6969 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
6972 ret = p2p_in_progress(wpa_s->global->p2p);
6975 * Check whether there is an ongoing WPS provisioning step (or
6976 * other parts of group formation) on another interface since
6977 * p2p_in_progress() does not report this to avoid issues for
6978 * scans during such provisioning step.
6980 if (wpa_s->global->p2p_group_formation &&
6981 wpa_s->global->p2p_group_formation != wpa_s) {
6982 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Another interface (%s) "
6983 "in group formation",
6984 wpa_s->global->p2p_group_formation->ifname);
6989 if (!ret && wpa_s->global->p2p_go_wait_client.sec) {
6990 struct os_reltime now;
6991 os_get_reltime(&now);
6992 if (os_reltime_expired(&now, &wpa_s->global->p2p_go_wait_client,
6993 P2P_MAX_INITIAL_CONN_WAIT_GO)) {
6994 /* Wait for the first client has expired */
6995 wpa_s->global->p2p_go_wait_client.sec = 0;
6997 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Waiting for initial client connection during group formation");
7006 void wpas_p2p_network_removed(struct wpa_supplicant *wpa_s,
7007 struct wpa_ssid *ssid)
7009 if (wpa_s->p2p_in_provisioning && ssid->p2p_group &&
7010 eloop_cancel_timeout(wpas_p2p_group_formation_timeout,
7011 wpa_s->parent, NULL) > 0) {
7013 * Remove the network by scheduling the group formation
7014 * timeout to happen immediately. The teardown code
7015 * needs to be scheduled to run asynch later so that we
7016 * don't delete data from under ourselves unexpectedly.
7017 * Calling wpas_p2p_group_formation_timeout directly
7018 * causes a series of crashes in WPS failure scenarios.
7020 wpa_printf(MSG_DEBUG, "P2P: Canceled group formation due to "
7021 "P2P group network getting removed");
7022 eloop_register_timeout(0, 0, wpas_p2p_group_formation_timeout,
7023 wpa_s->parent, NULL);
7028 struct wpa_ssid * wpas_p2p_get_persistent(struct wpa_supplicant *wpa_s,
7029 const u8 *addr, const u8 *ssid,
7035 for (s = wpa_s->conf->ssid; s; s = s->next) {
7036 if (s->disabled != 2)
7039 (ssid_len != s->ssid_len ||
7040 os_memcmp(ssid, s->ssid, ssid_len) != 0))
7043 if (s->mode == WPAS_MODE_P2P_GO)
7047 if (os_memcmp(s->bssid, addr, ETH_ALEN) == 0)
7048 return s; /* peer is GO in the persistent group */
7049 if (s->mode != WPAS_MODE_P2P_GO || s->p2p_client_list == NULL)
7051 for (i = 0; i < s->num_p2p_clients; i++) {
7052 if (os_memcmp(s->p2p_client_list + i * 2 * ETH_ALEN,
7053 addr, ETH_ALEN) == 0)
7054 return s; /* peer is P2P client in persistent
7063 void wpas_p2p_notify_ap_sta_authorized(struct wpa_supplicant *wpa_s,
7066 if (eloop_cancel_timeout(wpas_p2p_group_formation_timeout,
7067 wpa_s->parent, NULL) > 0) {
7069 * This can happen if WPS provisioning step is not terminated
7070 * cleanly (e.g., P2P Client does not send WSC_Done). Since the
7071 * peer was able to connect, there is no need to time out group
7072 * formation after this, though. In addition, this is used with
7073 * the initial connection wait on the GO as a separate formation
7074 * timeout and as such, expected to be hit after the initial WPS
7075 * provisioning step.
7077 wpa_printf(MSG_DEBUG, "P2P: Canceled P2P group formation timeout on data connection");
7079 if (!wpa_s->p2p_go_group_formation_completed &&
7080 !wpa_s->group_formation_reported) {
7082 * GO has not yet notified group formation success since
7083 * the WPS step was not completed cleanly. Do that
7084 * notification now since the P2P Client was able to
7085 * connect and as such, must have received the
7086 * credential from the WPS step.
7088 if (wpa_s->global->p2p)
7089 p2p_wps_success_cb(wpa_s->global->p2p, addr);
7090 wpas_group_formation_completed(wpa_s, 1, 0);
7093 if (!wpa_s->p2p_go_group_formation_completed) {
7094 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Marking group formation completed on GO on first data connection");
7095 wpa_s->p2p_go_group_formation_completed = 1;
7096 wpa_s->global->p2p_group_formation = NULL;
7097 wpa_s->p2p_in_provisioning = 0;
7098 wpa_s->p2p_in_invitation = 0;
7100 wpa_s->global->p2p_go_wait_client.sec = 0;
7103 wpas_p2p_add_persistent_group_client(wpa_s, addr);
7107 static int wpas_p2p_fallback_to_go_neg(struct wpa_supplicant *wpa_s,
7110 struct wpa_supplicant *group = wpa_s;
7113 if (wpa_s->global->p2p_group_formation)
7114 group = wpa_s->global->p2p_group_formation;
7115 wpa_s = wpa_s->global->p2p_init_wpa_s;
7116 offchannel_send_action_done(wpa_s);
7118 ret = wpas_p2p_group_delete(group, P2P_GROUP_REMOVAL_SILENT);
7119 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Fall back to GO Negotiation");
7120 wpas_p2p_connect(wpa_s, wpa_s->pending_join_dev_addr, wpa_s->p2p_pin,
7121 wpa_s->p2p_wps_method, wpa_s->p2p_persistent_group, 0,
7122 0, 0, wpa_s->p2p_go_intent, wpa_s->p2p_connect_freq,
7123 wpa_s->p2p_persistent_id,
7124 wpa_s->p2p_pd_before_go_neg,
7131 int wpas_p2p_scan_no_go_seen(struct wpa_supplicant *wpa_s)
7135 if (!wpa_s->p2p_fallback_to_go_neg ||
7136 wpa_s->p2p_in_provisioning <= 5)
7139 if (wpas_p2p_peer_go(wpa_s, wpa_s->pending_join_dev_addr) > 0)
7140 return 0; /* peer operating as a GO */
7142 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: GO not found for p2p_connect-auto - "
7143 "fallback to GO Negotiation");
7144 wpa_msg_global(wpa_s->parent, MSG_INFO, P2P_EVENT_FALLBACK_TO_GO_NEG
7145 "reason=GO-not-found");
7146 res = wpas_p2p_fallback_to_go_neg(wpa_s, 1);
7148 return res == 1 ? 2 : 1;
7152 unsigned int wpas_p2p_search_delay(struct wpa_supplicant *wpa_s)
7154 struct wpa_supplicant *ifs;
7156 if (wpa_s->wpa_state > WPA_SCANNING) {
7157 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Use %u ms search delay due to "
7158 "concurrent operation",
7159 wpa_s->conf->p2p_search_delay);
7160 return wpa_s->conf->p2p_search_delay;
7163 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
7165 if (ifs != wpa_s && ifs->wpa_state > WPA_SCANNING) {
7166 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Use %u ms search "
7167 "delay due to concurrent operation on "
7169 wpa_s->conf->p2p_search_delay,
7171 return wpa_s->conf->p2p_search_delay;
7179 static int wpas_p2p_remove_psk_entry(struct wpa_supplicant *wpa_s,
7180 struct wpa_ssid *s, const u8 *addr,
7183 struct psk_list_entry *psk, *tmp;
7186 dl_list_for_each_safe(psk, tmp, &s->psk_list, struct psk_list_entry,
7188 if ((iface_addr && !psk->p2p &&
7189 os_memcmp(addr, psk->addr, ETH_ALEN) == 0) ||
7190 (!iface_addr && psk->p2p &&
7191 os_memcmp(addr, psk->addr, ETH_ALEN) == 0)) {
7192 wpa_dbg(wpa_s, MSG_DEBUG,
7193 "P2P: Remove persistent group PSK list entry for "
7195 MAC2STR(psk->addr), psk->p2p);
7196 dl_list_del(&psk->list);
7206 void wpas_p2p_new_psk_cb(struct wpa_supplicant *wpa_s, const u8 *mac_addr,
7207 const u8 *p2p_dev_addr,
7208 const u8 *psk, size_t psk_len)
7210 struct wpa_ssid *ssid = wpa_s->current_ssid;
7211 struct wpa_ssid *persistent;
7212 struct psk_list_entry *p, *last;
7214 if (psk_len != sizeof(p->psk))
7218 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: New PSK for addr=" MACSTR
7219 " p2p_dev_addr=" MACSTR,
7220 MAC2STR(mac_addr), MAC2STR(p2p_dev_addr));
7221 if (is_zero_ether_addr(p2p_dev_addr))
7222 p2p_dev_addr = NULL;
7224 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: New PSK for addr=" MACSTR,
7228 if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION) {
7229 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: new_psk_cb during group formation");
7230 /* To be added to persistent group once created */
7231 if (wpa_s->global->add_psk == NULL) {
7232 wpa_s->global->add_psk = os_zalloc(sizeof(*p));
7233 if (wpa_s->global->add_psk == NULL)
7236 p = wpa_s->global->add_psk;
7239 os_memcpy(p->addr, p2p_dev_addr, ETH_ALEN);
7242 os_memcpy(p->addr, mac_addr, ETH_ALEN);
7244 os_memcpy(p->psk, psk, psk_len);
7248 if (ssid->mode != WPAS_MODE_P2P_GO || !ssid->p2p_persistent_group) {
7249 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Ignore new_psk_cb on not-persistent GO");
7253 persistent = wpas_p2p_get_persistent(wpa_s->parent, NULL, ssid->ssid,
7256 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Could not find persistent group information to store the new PSK");
7260 p = os_zalloc(sizeof(*p));
7265 os_memcpy(p->addr, p2p_dev_addr, ETH_ALEN);
7268 os_memcpy(p->addr, mac_addr, ETH_ALEN);
7270 os_memcpy(p->psk, psk, psk_len);
7272 if (dl_list_len(&persistent->psk_list) > P2P_MAX_STORED_CLIENTS &&
7273 (last = dl_list_last(&persistent->psk_list,
7274 struct psk_list_entry, list))) {
7275 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Remove oldest PSK entry for "
7276 MACSTR " (p2p=%u) to make room for a new one",
7277 MAC2STR(last->addr), last->p2p);
7278 dl_list_del(&last->list);
7282 wpas_p2p_remove_psk_entry(wpa_s->parent, persistent,
7283 p2p_dev_addr ? p2p_dev_addr : mac_addr,
7284 p2p_dev_addr == NULL);
7286 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Add new PSK for p2p_dev_addr="
7287 MACSTR, MAC2STR(p2p_dev_addr));
7289 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Add new PSK for addr=" MACSTR,
7292 dl_list_add(&persistent->psk_list, &p->list);
7294 if (wpa_s->parent->conf->update_config &&
7295 wpa_config_write(wpa_s->parent->confname, wpa_s->parent->conf))
7296 wpa_printf(MSG_DEBUG, "P2P: Failed to update configuration");
7300 static void wpas_p2p_remove_psk(struct wpa_supplicant *wpa_s,
7301 struct wpa_ssid *s, const u8 *addr,
7306 res = wpas_p2p_remove_psk_entry(wpa_s, s, addr, iface_addr);
7307 if (res > 0 && wpa_s->conf->update_config &&
7308 wpa_config_write(wpa_s->confname, wpa_s->conf))
7309 wpa_dbg(wpa_s, MSG_DEBUG,
7310 "P2P: Failed to update configuration");
7314 static void wpas_p2p_remove_client_go(struct wpa_supplicant *wpa_s,
7315 const u8 *peer, int iface_addr)
7317 struct hostapd_data *hapd;
7318 struct hostapd_wpa_psk *psk, *prev, *rem;
7319 struct sta_info *sta;
7321 if (wpa_s->ap_iface == NULL || wpa_s->current_ssid == NULL ||
7322 wpa_s->current_ssid->mode != WPAS_MODE_P2P_GO)
7325 /* Remove per-station PSK entry */
7326 hapd = wpa_s->ap_iface->bss[0];
7328 psk = hapd->conf->ssid.wpa_psk;
7330 if ((iface_addr && os_memcmp(peer, psk->addr, ETH_ALEN) == 0) ||
7332 os_memcmp(peer, psk->p2p_dev_addr, ETH_ALEN) == 0)) {
7333 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Remove operating group PSK entry for "
7334 MACSTR " iface_addr=%d",
7335 MAC2STR(peer), iface_addr);
7337 prev->next = psk->next;
7339 hapd->conf->ssid.wpa_psk = psk->next;
7349 /* Disconnect from group */
7351 sta = ap_get_sta(hapd, peer);
7353 sta = ap_get_sta_p2p(hapd, peer);
7355 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Disconnect peer " MACSTR
7356 " (iface_addr=%d) from group",
7357 MAC2STR(peer), iface_addr);
7358 hostapd_drv_sta_deauth(hapd, sta->addr,
7359 WLAN_REASON_DEAUTH_LEAVING);
7360 ap_sta_deauthenticate(hapd, sta, WLAN_REASON_DEAUTH_LEAVING);
7365 void wpas_p2p_remove_client(struct wpa_supplicant *wpa_s, const u8 *peer,
7369 struct wpa_supplicant *w;
7370 struct wpa_supplicant *p2p_wpa_s = wpa_s->global->p2p_init_wpa_s;
7372 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Remove client " MACSTR, MAC2STR(peer));
7374 /* Remove from any persistent group */
7375 for (s = p2p_wpa_s->conf->ssid; s; s = s->next) {
7376 if (s->disabled != 2 || s->mode != WPAS_MODE_P2P_GO)
7379 wpas_remove_persistent_peer(p2p_wpa_s, s, peer, 0);
7380 wpas_p2p_remove_psk(p2p_wpa_s, s, peer, iface_addr);
7383 /* Remove from any operating group */
7384 for (w = wpa_s->global->ifaces; w; w = w->next)
7385 wpas_p2p_remove_client_go(w, peer, iface_addr);
7389 static void wpas_p2p_psk_failure_removal(void *eloop_ctx, void *timeout_ctx)
7391 struct wpa_supplicant *wpa_s = eloop_ctx;
7392 wpas_p2p_group_delete(wpa_s, P2P_GROUP_REMOVAL_PSK_FAILURE);
7396 static void wpas_p2p_group_freq_conflict(void *eloop_ctx, void *timeout_ctx)
7398 struct wpa_supplicant *wpa_s = eloop_ctx;
7400 wpa_printf(MSG_DEBUG, "P2P: Frequency conflict - terminate group");
7401 wpas_p2p_group_delete(wpa_s, P2P_GROUP_REMOVAL_FREQ_CONFLICT);
7405 int wpas_p2p_handle_frequency_conflicts(struct wpa_supplicant *wpa_s, int freq,
7406 struct wpa_ssid *ssid)
7408 struct wpa_supplicant *iface;
7410 for (iface = wpa_s->global->ifaces; iface; iface = iface->next) {
7411 if (!iface->current_ssid ||
7412 iface->current_ssid->frequency == freq ||
7413 (iface->p2p_group_interface == NOT_P2P_GROUP_INTERFACE &&
7414 !iface->current_ssid->p2p_group))
7417 /* Remove the connection with least priority */
7418 if (!wpas_is_p2p_prioritized(iface)) {
7419 /* STA connection has priority over existing
7420 * P2P connection, so remove the interface. */
7421 wpa_printf(MSG_DEBUG, "P2P: Removing P2P connection due to single channel concurrent mode frequency conflict");
7422 eloop_register_timeout(0, 0,
7423 wpas_p2p_group_freq_conflict,
7425 /* If connection in progress is P2P connection, do not
7426 * proceed for the connection. */
7432 /* P2P connection has priority, disable the STA network
7434 wpa_supplicant_disable_network(wpa_s->global->ifaces,
7436 wpa_msg(wpa_s->global->ifaces, MSG_INFO,
7437 WPA_EVENT_FREQ_CONFLICT " id=%d", ssid->id);
7438 os_memset(wpa_s->global->ifaces->pending_bssid, 0,
7440 /* If P2P connection is in progress, continue
7453 int wpas_p2p_4way_hs_failed(struct wpa_supplicant *wpa_s)
7455 struct wpa_ssid *ssid = wpa_s->current_ssid;
7457 if (ssid == NULL || !ssid->p2p_group)
7460 if (wpa_s->p2p_last_4way_hs_fail &&
7461 wpa_s->p2p_last_4way_hs_fail == ssid) {
7462 u8 go_dev_addr[ETH_ALEN];
7463 struct wpa_ssid *persistent;
7465 if (wpas_p2p_persistent_group(wpa_s, go_dev_addr,
7467 ssid->ssid_len) <= 0) {
7468 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Could not determine whether 4-way handshake failures were for a persistent group");
7472 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Two 4-way handshake failures for a P2P group - go_dev_addr="
7473 MACSTR, MAC2STR(go_dev_addr));
7474 persistent = wpas_p2p_get_persistent(wpa_s->parent, go_dev_addr,
7477 if (persistent == NULL || persistent->mode != WPAS_MODE_INFRA) {
7478 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: No matching persistent group stored");
7481 wpa_msg_global(wpa_s->parent, MSG_INFO,
7482 P2P_EVENT_PERSISTENT_PSK_FAIL "%d",
7485 wpa_s->p2p_last_4way_hs_fail = NULL;
7487 * Remove the group from a timeout to avoid issues with caller
7488 * continuing to use the interface if this is on a P2P group
7491 eloop_register_timeout(0, 0, wpas_p2p_psk_failure_removal,
7496 wpa_s->p2p_last_4way_hs_fail = ssid;
7501 #ifdef CONFIG_WPS_NFC
7503 static struct wpabuf * wpas_p2p_nfc_handover(int ndef, struct wpabuf *wsc,
7511 wpa_printf(MSG_DEBUG, "P2P: No p2p buffer for handover");
7515 wsc_len = wsc ? wpabuf_len(wsc) : 0;
7516 ret = wpabuf_alloc(2 + wsc_len + 2 + wpabuf_len(p2p));
7523 wpabuf_put_be16(ret, wsc_len);
7525 wpabuf_put_buf(ret, wsc);
7526 wpabuf_put_be16(ret, wpabuf_len(p2p));
7527 wpabuf_put_buf(ret, p2p);
7531 wpa_hexdump_buf(MSG_DEBUG,
7532 "P2P: Generated NFC connection handover message", ret);
7536 tmp = ndef_build_p2p(ret);
7539 wpa_printf(MSG_DEBUG, "P2P: Failed to NDEF encapsulate handover request");
7549 static int wpas_p2p_cli_freq(struct wpa_supplicant *wpa_s,
7550 struct wpa_ssid **ssid, u8 *go_dev_addr)
7552 struct wpa_supplicant *iface;
7555 os_memset(go_dev_addr, 0, ETH_ALEN);
7558 for (iface = wpa_s->global->ifaces; iface; iface = iface->next) {
7559 if (iface->wpa_state < WPA_ASSOCIATING ||
7560 iface->current_ssid == NULL || iface->assoc_freq == 0 ||
7561 !iface->current_ssid->p2p_group ||
7562 iface->current_ssid->mode != WPAS_MODE_INFRA)
7565 *ssid = iface->current_ssid;
7567 os_memcpy(go_dev_addr, iface->go_dev_addr, ETH_ALEN);
7568 return iface->assoc_freq;
7574 struct wpabuf * wpas_p2p_nfc_handover_req(struct wpa_supplicant *wpa_s,
7577 struct wpabuf *wsc, *p2p;
7578 struct wpa_ssid *ssid;
7579 u8 go_dev_addr[ETH_ALEN];
7580 int cli_freq = wpas_p2p_cli_freq(wpa_s, &ssid, go_dev_addr);
7582 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) {
7583 wpa_printf(MSG_DEBUG, "P2P: P2P disabled - cannot build handover request");
7587 if (wpa_s->conf->wps_nfc_dh_pubkey == NULL &&
7588 wps_nfc_gen_dh(&wpa_s->conf->wps_nfc_dh_pubkey,
7589 &wpa_s->conf->wps_nfc_dh_privkey) < 0) {
7590 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: No DH key available for handover request");
7594 if (cli_freq == 0) {
7595 wsc = wps_build_nfc_handover_req_p2p(
7596 wpa_s->parent->wps, wpa_s->conf->wps_nfc_dh_pubkey);
7599 p2p = p2p_build_nfc_handover_req(wpa_s->global->p2p, cli_freq,
7600 go_dev_addr, ssid ? ssid->ssid : NULL,
7601 ssid ? ssid->ssid_len : 0);
7603 return wpas_p2p_nfc_handover(ndef, wsc, p2p);
7607 struct wpabuf * wpas_p2p_nfc_handover_sel(struct wpa_supplicant *wpa_s,
7610 struct wpabuf *wsc, *p2p;
7611 struct wpa_ssid *ssid;
7612 u8 go_dev_addr[ETH_ALEN];
7613 int cli_freq = wpas_p2p_cli_freq(wpa_s, &ssid, go_dev_addr);
7615 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
7618 if (!tag && wpa_s->conf->wps_nfc_dh_pubkey == NULL &&
7619 wps_nfc_gen_dh(&wpa_s->conf->wps_nfc_dh_pubkey,
7620 &wpa_s->conf->wps_nfc_dh_privkey) < 0)
7623 if (cli_freq == 0) {
7624 wsc = wps_build_nfc_handover_sel_p2p(
7626 tag ? wpa_s->conf->wps_nfc_dev_pw_id :
7627 DEV_PW_NFC_CONNECTION_HANDOVER,
7628 wpa_s->conf->wps_nfc_dh_pubkey,
7629 tag ? wpa_s->conf->wps_nfc_dev_pw : NULL);
7632 p2p = p2p_build_nfc_handover_sel(wpa_s->global->p2p, cli_freq,
7633 go_dev_addr, ssid ? ssid->ssid : NULL,
7634 ssid ? ssid->ssid_len : 0);
7636 return wpas_p2p_nfc_handover(ndef, wsc, p2p);
7640 static int wpas_p2p_nfc_join_group(struct wpa_supplicant *wpa_s,
7641 struct p2p_nfc_params *params)
7643 wpa_printf(MSG_DEBUG, "P2P: Initiate join-group based on NFC "
7644 "connection handover (freq=%d)",
7647 if (params->go_freq && params->go_ssid_len) {
7648 wpa_s->p2p_wps_method = WPS_NFC;
7649 wpa_s->pending_join_wps_method = WPS_NFC;
7650 os_memset(wpa_s->pending_join_iface_addr, 0, ETH_ALEN);
7651 os_memcpy(wpa_s->pending_join_dev_addr, params->go_dev_addr,
7653 return wpas_p2p_join_start(wpa_s, params->go_freq,
7655 params->go_ssid_len);
7658 return wpas_p2p_connect(wpa_s, params->peer->p2p_device_addr, NULL,
7659 WPS_NFC, 0, 0, 1, 0, wpa_s->conf->p2p_go_intent,
7660 params->go_freq, -1, 0, 1, 1);
7664 static int wpas_p2p_nfc_auth_join(struct wpa_supplicant *wpa_s,
7665 struct p2p_nfc_params *params, int tag)
7667 int res, persistent;
7668 struct wpa_ssid *ssid;
7670 wpa_printf(MSG_DEBUG, "P2P: Authorize join-group based on NFC "
7671 "connection handover");
7672 for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) {
7673 ssid = wpa_s->current_ssid;
7676 if (ssid->mode != WPAS_MODE_P2P_GO)
7678 if (wpa_s->ap_iface == NULL)
7682 if (wpa_s == NULL) {
7683 wpa_printf(MSG_DEBUG, "P2P: Could not find GO interface");
7687 if (wpa_s->parent->p2p_oob_dev_pw_id !=
7688 DEV_PW_NFC_CONNECTION_HANDOVER &&
7689 !wpa_s->parent->p2p_oob_dev_pw) {
7690 wpa_printf(MSG_DEBUG, "P2P: No NFC Dev Pw known");
7693 res = wpas_ap_wps_add_nfc_pw(
7694 wpa_s, wpa_s->parent->p2p_oob_dev_pw_id,
7695 wpa_s->parent->p2p_oob_dev_pw,
7696 wpa_s->parent->p2p_peer_oob_pk_hash_known ?
7697 wpa_s->parent->p2p_peer_oob_pubkey_hash : NULL);
7702 wpa_printf(MSG_DEBUG, "P2P: Negotiated handover - wait for peer to join without invitation");
7706 if (!params->peer ||
7707 !(params->peer->dev_capab & P2P_DEV_CAPAB_INVITATION_PROCEDURE))
7710 wpa_printf(MSG_DEBUG, "P2P: Static handover - invite peer " MACSTR
7711 " to join", MAC2STR(params->peer->p2p_device_addr));
7713 wpa_s->global->p2p_invite_group = wpa_s;
7714 persistent = ssid->p2p_persistent_group &&
7715 wpas_p2p_get_persistent(wpa_s->parent,
7716 params->peer->p2p_device_addr,
7717 ssid->ssid, ssid->ssid_len);
7718 wpa_s->parent->pending_invite_ssid_id = -1;
7720 return p2p_invite(wpa_s->global->p2p, params->peer->p2p_device_addr,
7721 P2P_INVITE_ROLE_ACTIVE_GO, wpa_s->own_addr,
7722 ssid->ssid, ssid->ssid_len, ssid->frequency,
7723 wpa_s->global->p2p_dev_addr, persistent, 0,
7724 wpa_s->parent->p2p_oob_dev_pw_id);
7728 static int wpas_p2p_nfc_init_go_neg(struct wpa_supplicant *wpa_s,
7729 struct p2p_nfc_params *params,
7732 wpa_printf(MSG_DEBUG, "P2P: Initiate GO Negotiation based on NFC "
7733 "connection handover");
7734 return wpas_p2p_connect(wpa_s, params->peer->p2p_device_addr, NULL,
7735 WPS_NFC, 0, 0, 0, 0, wpa_s->conf->p2p_go_intent,
7736 forced_freq, -1, 0, 1, 1);
7740 static int wpas_p2p_nfc_resp_go_neg(struct wpa_supplicant *wpa_s,
7741 struct p2p_nfc_params *params,
7746 wpa_printf(MSG_DEBUG, "P2P: Authorize GO Negotiation based on NFC "
7747 "connection handover");
7748 res = wpas_p2p_connect(wpa_s, params->peer->p2p_device_addr, NULL,
7749 WPS_NFC, 0, 0, 0, 1, wpa_s->conf->p2p_go_intent,
7750 forced_freq, -1, 0, 1, 1);
7754 res = wpas_p2p_listen(wpa_s, 60);
7756 p2p_unauthorize(wpa_s->global->p2p,
7757 params->peer->p2p_device_addr);
7764 static int wpas_p2p_nfc_connection_handover(struct wpa_supplicant *wpa_s,
7765 const struct wpabuf *data,
7766 int sel, int tag, int forced_freq)
7768 const u8 *pos, *end;
7770 struct p2p_nfc_params params;
7773 os_memset(¶ms, 0, sizeof(params));
7776 wpa_hexdump_buf(MSG_DEBUG, "P2P: Received NFC tag payload", data);
7778 pos = wpabuf_head(data);
7779 end = pos + wpabuf_len(data);
7781 if (end - pos < 2) {
7782 wpa_printf(MSG_DEBUG, "P2P: Not enough data for Length of WSC "
7786 len = WPA_GET_BE16(pos);
7788 if (len > end - pos) {
7789 wpa_printf(MSG_DEBUG, "P2P: Not enough data for WSC "
7793 params.wsc_attr = pos;
7794 params.wsc_len = len;
7797 if (end - pos < 2) {
7798 wpa_printf(MSG_DEBUG, "P2P: Not enough data for Length of P2P "
7802 len = WPA_GET_BE16(pos);
7804 if (len > end - pos) {
7805 wpa_printf(MSG_DEBUG, "P2P: Not enough data for P2P "
7809 params.p2p_attr = pos;
7810 params.p2p_len = len;
7813 wpa_hexdump(MSG_DEBUG, "P2P: WSC attributes",
7814 params.wsc_attr, params.wsc_len);
7815 wpa_hexdump(MSG_DEBUG, "P2P: P2P attributes",
7816 params.p2p_attr, params.p2p_len);
7818 wpa_hexdump(MSG_DEBUG,
7819 "P2P: Ignored extra data after P2P attributes",
7823 res = p2p_process_nfc_connection_handover(wpa_s->global->p2p, ¶ms);
7827 if (params.next_step == NO_ACTION)
7830 if (params.next_step == BOTH_GO) {
7831 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_NFC_BOTH_GO "peer=" MACSTR,
7832 MAC2STR(params.peer->p2p_device_addr));
7836 if (params.next_step == PEER_CLIENT) {
7837 if (!is_zero_ether_addr(params.go_dev_addr)) {
7838 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_NFC_PEER_CLIENT
7839 "peer=" MACSTR " freq=%d go_dev_addr=" MACSTR
7841 MAC2STR(params.peer->p2p_device_addr),
7843 MAC2STR(params.go_dev_addr),
7844 wpa_ssid_txt(params.go_ssid,
7845 params.go_ssid_len));
7847 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_NFC_PEER_CLIENT
7848 "peer=" MACSTR " freq=%d",
7849 MAC2STR(params.peer->p2p_device_addr),
7855 if (wpas_p2p_cli_freq(wpa_s, NULL, NULL)) {
7856 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_NFC_WHILE_CLIENT "peer="
7857 MACSTR, MAC2STR(params.peer->p2p_device_addr));
7861 wpabuf_free(wpa_s->p2p_oob_dev_pw);
7862 wpa_s->p2p_oob_dev_pw = NULL;
7864 if (params.oob_dev_pw_len < WPS_OOB_PUBKEY_HASH_LEN + 2) {
7865 wpa_printf(MSG_DEBUG, "P2P: No peer OOB Dev Pw "
7870 id = WPA_GET_BE16(params.oob_dev_pw + WPS_OOB_PUBKEY_HASH_LEN);
7871 wpa_printf(MSG_DEBUG, "P2P: Peer OOB Dev Pw %u", id);
7872 wpa_hexdump(MSG_DEBUG, "P2P: Peer OOB Public Key hash",
7873 params.oob_dev_pw, WPS_OOB_PUBKEY_HASH_LEN);
7874 os_memcpy(wpa_s->p2p_peer_oob_pubkey_hash,
7875 params.oob_dev_pw, WPS_OOB_PUBKEY_HASH_LEN);
7876 wpa_s->p2p_peer_oob_pk_hash_known = 1;
7880 wpa_printf(MSG_DEBUG, "P2P: Static handover - invalid "
7881 "peer OOB Device Password Id %u", id);
7884 wpa_printf(MSG_DEBUG, "P2P: Static handover - use peer OOB "
7885 "Device Password Id %u", id);
7886 wpa_hexdump_key(MSG_DEBUG, "P2P: Peer OOB Device Password",
7887 params.oob_dev_pw + WPS_OOB_PUBKEY_HASH_LEN + 2,
7888 params.oob_dev_pw_len -
7889 WPS_OOB_PUBKEY_HASH_LEN - 2);
7890 wpa_s->p2p_oob_dev_pw_id = id;
7891 wpa_s->p2p_oob_dev_pw = wpabuf_alloc_copy(
7892 params.oob_dev_pw + WPS_OOB_PUBKEY_HASH_LEN + 2,
7893 params.oob_dev_pw_len -
7894 WPS_OOB_PUBKEY_HASH_LEN - 2);
7895 if (wpa_s->p2p_oob_dev_pw == NULL)
7898 if (wpa_s->conf->wps_nfc_dh_pubkey == NULL &&
7899 wps_nfc_gen_dh(&wpa_s->conf->wps_nfc_dh_pubkey,
7900 &wpa_s->conf->wps_nfc_dh_privkey) < 0)
7903 wpa_printf(MSG_DEBUG, "P2P: Using abbreviated WPS handshake "
7904 "without Device Password");
7905 wpa_s->p2p_oob_dev_pw_id = DEV_PW_NFC_CONNECTION_HANDOVER;
7908 switch (params.next_step) {
7912 /* already covered above */
7915 return wpas_p2p_nfc_join_group(wpa_s, ¶ms);
7917 return wpas_p2p_nfc_auth_join(wpa_s, ¶ms, tag);
7919 return wpas_p2p_nfc_init_go_neg(wpa_s, ¶ms, forced_freq);
7921 /* TODO: use own OOB Dev Pw */
7922 return wpas_p2p_nfc_resp_go_neg(wpa_s, ¶ms, forced_freq);
7929 int wpas_p2p_nfc_tag_process(struct wpa_supplicant *wpa_s,
7930 const struct wpabuf *data, int forced_freq)
7932 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
7935 return wpas_p2p_nfc_connection_handover(wpa_s, data, 1, 1, forced_freq);
7939 int wpas_p2p_nfc_report_handover(struct wpa_supplicant *wpa_s, int init,
7940 const struct wpabuf *req,
7941 const struct wpabuf *sel, int forced_freq)
7946 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
7949 wpa_printf(MSG_DEBUG, "NFC: P2P connection handover reported");
7951 wpa_hexdump_ascii(MSG_DEBUG, "NFC: Req",
7952 wpabuf_head(req), wpabuf_len(req));
7953 wpa_hexdump_ascii(MSG_DEBUG, "NFC: Sel",
7954 wpabuf_head(sel), wpabuf_len(sel));
7956 wpa_printf(MSG_DEBUG, "NFC: Forced freq %d", forced_freq);
7957 tmp = ndef_parse_p2p(init ? sel : req);
7959 wpa_printf(MSG_DEBUG, "P2P: Could not parse NDEF");
7963 ret = wpas_p2p_nfc_connection_handover(wpa_s, tmp, init, 0,
7971 int wpas_p2p_nfc_tag_enabled(struct wpa_supplicant *wpa_s, int enabled)
7974 int go_intent = wpa_s->conf->p2p_go_intent;
7975 struct wpa_supplicant *iface;
7977 if (wpa_s->global->p2p == NULL)
7981 wpa_printf(MSG_DEBUG, "P2P: Disable use of own NFC Tag");
7982 for (iface = wpa_s->global->ifaces; iface; iface = iface->next)
7984 if (!iface->ap_iface)
7986 hostapd_wps_nfc_token_disable(iface->ap_iface->bss[0]);
7988 p2p_set_authorized_oob_dev_pw_id(wpa_s->global->p2p, 0,
7990 if (wpa_s->p2p_nfc_tag_enabled)
7991 wpas_p2p_remove_pending_group_interface(wpa_s);
7992 wpa_s->p2p_nfc_tag_enabled = 0;
7996 if (wpa_s->global->p2p_disabled)
7999 if (wpa_s->conf->wps_nfc_dh_pubkey == NULL ||
8000 wpa_s->conf->wps_nfc_dh_privkey == NULL ||
8001 wpa_s->conf->wps_nfc_dev_pw == NULL ||
8002 wpa_s->conf->wps_nfc_dev_pw_id < 0x10) {
8003 wpa_printf(MSG_DEBUG, "P2P: NFC password token not configured "
8004 "to allow static handover cases");
8008 wpa_printf(MSG_DEBUG, "P2P: Enable use of own NFC Tag");
8010 wpa_s->p2p_oob_dev_pw_id = wpa_s->conf->wps_nfc_dev_pw_id;
8011 wpabuf_free(wpa_s->p2p_oob_dev_pw);
8012 wpa_s->p2p_oob_dev_pw = wpabuf_dup(wpa_s->conf->wps_nfc_dev_pw);
8013 if (wpa_s->p2p_oob_dev_pw == NULL)
8015 wpa_s->p2p_peer_oob_pk_hash_known = 0;
8017 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
8018 wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT) {
8020 * P2P Group Interface present and the command came on group
8021 * interface, so enable the token for the current interface.
8023 wpa_s->create_p2p_iface = 0;
8025 wpa_s->create_p2p_iface = wpas_p2p_create_iface(wpa_s);
8028 if (wpa_s->create_p2p_iface) {
8029 enum wpa_driver_if_type iftype;
8030 /* Prepare to add a new interface for the group */
8031 iftype = WPA_IF_P2P_GROUP;
8032 if (go_intent == 15)
8033 iftype = WPA_IF_P2P_GO;
8034 if (wpas_p2p_add_group_interface(wpa_s, iftype) < 0) {
8035 wpa_printf(MSG_ERROR, "P2P: Failed to allocate a new "
8036 "interface for the group");
8040 if_addr = wpa_s->pending_interface_addr;
8042 if_addr = wpa_s->own_addr;
8044 wpa_s->p2p_nfc_tag_enabled = enabled;
8046 for (iface = wpa_s->global->ifaces; iface; iface = iface->next) {
8047 struct hostapd_data *hapd;
8048 if (iface->ap_iface == NULL)
8050 hapd = iface->ap_iface->bss[0];
8051 wpabuf_free(hapd->conf->wps_nfc_dh_pubkey);
8052 hapd->conf->wps_nfc_dh_pubkey =
8053 wpabuf_dup(wpa_s->conf->wps_nfc_dh_pubkey);
8054 wpabuf_free(hapd->conf->wps_nfc_dh_privkey);
8055 hapd->conf->wps_nfc_dh_privkey =
8056 wpabuf_dup(wpa_s->conf->wps_nfc_dh_privkey);
8057 wpabuf_free(hapd->conf->wps_nfc_dev_pw);
8058 hapd->conf->wps_nfc_dev_pw =
8059 wpabuf_dup(wpa_s->conf->wps_nfc_dev_pw);
8060 hapd->conf->wps_nfc_dev_pw_id = wpa_s->conf->wps_nfc_dev_pw_id;
8062 if (hostapd_wps_nfc_token_enable(iface->ap_iface->bss[0]) < 0) {
8063 wpa_dbg(iface, MSG_DEBUG,
8064 "P2P: Failed to enable NFC Tag for GO");
8067 p2p_set_authorized_oob_dev_pw_id(
8068 wpa_s->global->p2p, wpa_s->conf->wps_nfc_dev_pw_id, go_intent,
8074 #endif /* CONFIG_WPS_NFC */
8077 static void wpas_p2p_optimize_listen_channel(struct wpa_supplicant *wpa_s,
8078 struct wpa_used_freq_data *freqs,
8081 u8 curr_chan, cand, chan;
8084 curr_chan = p2p_get_listen_channel(wpa_s->global->p2p);
8085 for (i = 0, cand = 0; i < num; i++) {
8086 ieee80211_freq_to_chan(freqs[i].freq, &chan);
8087 if (curr_chan == chan) {
8092 if (chan == 1 || chan == 6 || chan == 11)
8097 wpa_dbg(wpa_s, MSG_DEBUG,
8098 "P2P: Update Listen channel to %u based on operating channel",
8100 p2p_set_listen_channel(wpa_s->global->p2p, 81, cand, 0);
8105 void wpas_p2p_indicate_state_change(struct wpa_supplicant *wpa_s)
8107 struct wpa_used_freq_data *freqs;
8108 unsigned int num = wpa_s->num_multichan_concurrent;
8110 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
8114 * If possible, optimize the Listen channel to be a channel that is
8115 * already used by one of the other interfaces.
8117 if (!wpa_s->conf->p2p_optimize_listen_chan)
8120 if (!wpa_s->current_ssid || wpa_s->wpa_state != WPA_COMPLETED)
8123 freqs = os_calloc(num, sizeof(struct wpa_used_freq_data));
8127 num = get_shared_radio_freqs_data(wpa_s, freqs, num);
8129 wpas_p2p_optimize_listen_channel(wpa_s, freqs, num);
8134 void wpas_p2p_deinit_iface(struct wpa_supplicant *wpa_s)
8136 if (wpa_s == wpa_s->global->p2p_init_wpa_s && wpa_s->global->p2p) {
8137 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Disable P2P since removing "
8138 "the management interface is being removed");
8139 wpas_p2p_deinit_global(wpa_s->global);
8144 void wpas_p2p_ap_deinit(struct wpa_supplicant *wpa_s)
8146 if (wpa_s->ap_iface->bss)
8147 wpa_s->ap_iface->bss[0]->p2p_group = NULL;
8148 wpas_p2p_group_deinit(wpa_s);