3 * Copyright (c) 2009-2010, Atheros Communications
4 * Copyright (c) 2010-2014, Jouni Malinen <j@w1.fi>
6 * This software may be distributed under the terms of the BSD license.
7 * See README for more details.
14 #include "common/ieee802_11_common.h"
15 #include "common/ieee802_11_defs.h"
16 #include "common/wpa_ctrl.h"
17 #include "wps/wps_i.h"
19 #include "ap/hostapd.h"
20 #include "ap/ap_config.h"
21 #include "ap/sta_info.h"
22 #include "ap/ap_drv_ops.h"
23 #include "ap/wps_hostapd.h"
24 #include "ap/p2p_hostapd.h"
26 #include "eapol_supp/eapol_supp_sm.h"
27 #include "rsn_supp/wpa.h"
28 #include "wpa_supplicant_i.h"
31 #include "config_ssid.h"
36 #include "offchannel.h"
37 #include "wps_supplicant.h"
38 #include "p2p_supplicant.h"
39 #include "wifi_display.h"
43 * How many times to try to scan to find the GO before giving up on join
46 #define P2P_MAX_JOIN_SCAN_ATTEMPTS 10
48 #define P2P_AUTO_PD_SCAN_ATTEMPTS 5
51 * Defines time interval in seconds when a GO needs to evacuate a frequency that
52 * it is currently using, but is no longer valid for P2P use cases.
54 #define P2P_GO_FREQ_CHANGE_TIME 5
57 * Defines CSA parameters which are used when GO evacuates the no longer valid
58 * channel (and if the driver supports channel switch).
60 #define P2P_GO_CSA_COUNT 7
61 #define P2P_GO_CSA_BLOCK_TX 0
63 #ifndef P2P_MAX_CLIENT_IDLE
65 * How many seconds to try to reconnect to the GO when connection in P2P client
68 #define P2P_MAX_CLIENT_IDLE 10
69 #endif /* P2P_MAX_CLIENT_IDLE */
71 #ifndef P2P_MAX_INITIAL_CONN_WAIT
73 * How many seconds to wait for initial 4-way handshake to get completed after
74 * WPS provisioning step or after the re-invocation of a persistent group on a
77 #define P2P_MAX_INITIAL_CONN_WAIT 10
78 #endif /* P2P_MAX_INITIAL_CONN_WAIT */
80 #ifndef P2P_MAX_INITIAL_CONN_WAIT_GO
82 * How many seconds to wait for initial 4-way handshake to get completed after
83 * WPS provisioning step on the GO. This controls the extra time the P2P
84 * operation is considered to be in progress (e.g., to delay other scans) after
85 * WPS provisioning has been completed on the GO during group formation.
87 #define P2P_MAX_INITIAL_CONN_WAIT_GO 10
88 #endif /* P2P_MAX_INITIAL_CONN_WAIT_GO */
90 #ifndef P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE
92 * How many seconds to wait for initial 4-way handshake to get completed after
93 * re-invocation of a persistent group on the GO when the client is expected
94 * to connect automatically (no user interaction).
96 #define P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE 15
97 #endif /* P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE */
99 #define P2P_MGMT_DEVICE_PREFIX "p2p-dev-"
102 * How many seconds to wait to re-attempt to move GOs, in case previous attempt
105 #define P2P_RECONSIDER_GO_MOVE_DELAY 30
107 enum p2p_group_removal_reason {
108 P2P_GROUP_REMOVAL_UNKNOWN,
109 P2P_GROUP_REMOVAL_SILENT,
110 P2P_GROUP_REMOVAL_FORMATION_FAILED,
111 P2P_GROUP_REMOVAL_REQUESTED,
112 P2P_GROUP_REMOVAL_IDLE_TIMEOUT,
113 P2P_GROUP_REMOVAL_UNAVAILABLE,
114 P2P_GROUP_REMOVAL_GO_ENDING_SESSION,
115 P2P_GROUP_REMOVAL_PSK_FAILURE,
116 P2P_GROUP_REMOVAL_FREQ_CONFLICT,
117 P2P_GROUP_REMOVAL_GO_LEAVE_CHANNEL
121 static void wpas_p2p_long_listen_timeout(void *eloop_ctx, void *timeout_ctx);
122 static struct wpa_supplicant *
123 wpas_p2p_get_group_iface(struct wpa_supplicant *wpa_s, int addr_allocated,
125 static int wpas_p2p_join_start(struct wpa_supplicant *wpa_s, int freq,
126 const u8 *ssid, size_t ssid_len);
127 static void wpas_p2p_join_scan_req(struct wpa_supplicant *wpa_s, int freq,
128 const u8 *ssid, size_t ssid_len);
129 static void wpas_p2p_join_scan(void *eloop_ctx, void *timeout_ctx);
130 static int wpas_p2p_join(struct wpa_supplicant *wpa_s, const u8 *iface_addr,
131 const u8 *dev_addr, enum p2p_wps_method wps_method,
132 int auto_join, int freq,
133 const u8 *ssid, size_t ssid_len);
134 static int wpas_p2p_create_iface(struct wpa_supplicant *wpa_s);
135 static void wpas_p2p_cross_connect_setup(struct wpa_supplicant *wpa_s);
136 static void wpas_p2p_group_idle_timeout(void *eloop_ctx, void *timeout_ctx);
137 static void wpas_p2p_set_group_idle_timeout(struct wpa_supplicant *wpa_s);
138 static void wpas_p2p_group_formation_timeout(void *eloop_ctx,
140 static void wpas_p2p_group_freq_conflict(void *eloop_ctx, void *timeout_ctx);
141 static int wpas_p2p_fallback_to_go_neg(struct wpa_supplicant *wpa_s,
143 static void wpas_p2p_stop_find_oper(struct wpa_supplicant *wpa_s);
144 static void wpas_stop_listen(void *ctx);
145 static void wpas_p2p_psk_failure_removal(void *eloop_ctx, void *timeout_ctx);
146 static void wpas_p2p_group_deinit(struct wpa_supplicant *wpa_s);
147 static int wpas_p2p_add_group_interface(struct wpa_supplicant *wpa_s,
148 enum wpa_driver_if_type type);
149 static void wpas_p2p_group_formation_failed(struct wpa_supplicant *wpa_s,
150 int already_deleted);
151 static void wpas_p2p_optimize_listen_channel(struct wpa_supplicant *wpa_s,
152 struct wpa_used_freq_data *freqs,
154 static void wpas_p2p_move_go(void *eloop_ctx, void *timeout_ctx);
155 static int wpas_p2p_go_is_peer_freq(struct wpa_supplicant *wpa_s, int freq);
157 wpas_p2p_consider_moving_gos(struct wpa_supplicant *wpa_s,
158 struct wpa_used_freq_data *freqs, unsigned int num,
159 enum wpas_p2p_channel_update_trig trig);
160 static void wpas_p2p_reconsider_moving_go(void *eloop_ctx, void *timeout_ctx);
164 * Get the number of concurrent channels that the HW can operate, but that are
165 * currently not in use by any of the wpa_supplicant interfaces.
167 static int wpas_p2p_num_unused_channels(struct wpa_supplicant *wpa_s)
172 freqs = os_calloc(wpa_s->num_multichan_concurrent, sizeof(int));
176 num = get_shared_radio_freqs(wpa_s, freqs,
177 wpa_s->num_multichan_concurrent);
180 unused = wpa_s->num_multichan_concurrent - num;
181 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: num_unused_channels: %d", unused);
187 * Get the frequencies that are currently in use by one or more of the virtual
188 * interfaces, and that are also valid for P2P operation.
191 wpas_p2p_valid_oper_freqs(struct wpa_supplicant *wpa_s,
192 struct wpa_used_freq_data *p2p_freqs,
195 struct wpa_used_freq_data *freqs;
196 unsigned int num, i, j;
198 freqs = os_calloc(wpa_s->num_multichan_concurrent,
199 sizeof(struct wpa_used_freq_data));
203 num = get_shared_radio_freqs_data(wpa_s, freqs,
204 wpa_s->num_multichan_concurrent);
206 os_memset(p2p_freqs, 0, sizeof(struct wpa_used_freq_data) * len);
208 for (i = 0, j = 0; i < num && j < len; i++) {
209 if (p2p_supported_freq(wpa_s->global->p2p, freqs[i].freq))
210 p2p_freqs[j++] = freqs[i];
215 dump_freq_data(wpa_s, "valid for P2P", p2p_freqs, j);
221 static void wpas_p2p_set_own_freq_preference(struct wpa_supplicant *wpa_s,
224 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
227 /* Use the wpa_s used to control the P2P Device operation */
228 wpa_s = wpa_s->global->p2p_init_wpa_s;
230 if (wpa_s->conf->p2p_ignore_shared_freq &&
231 freq > 0 && wpa_s->num_multichan_concurrent > 1 &&
232 wpas_p2p_num_unused_channels(wpa_s) > 0) {
233 wpa_printf(MSG_DEBUG, "P2P: Ignore own channel preference %d MHz due to p2p_ignore_shared_freq=1 configuration",
237 p2p_set_own_freq_preference(wpa_s->global->p2p, freq);
241 static void wpas_p2p_scan_res_handler(struct wpa_supplicant *wpa_s,
242 struct wpa_scan_results *scan_res)
246 if (wpa_s->p2p_scan_work) {
247 struct wpa_radio_work *work = wpa_s->p2p_scan_work;
248 wpa_s->p2p_scan_work = NULL;
249 radio_work_done(work);
252 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
255 wpa_printf(MSG_DEBUG, "P2P: Scan results received (%d BSS)",
256 (int) scan_res->num);
258 for (i = 0; i < scan_res->num; i++) {
259 struct wpa_scan_res *bss = scan_res->res[i];
260 struct os_reltime time_tmp_age, entry_ts;
264 time_tmp_age.sec = bss->age / 1000;
265 time_tmp_age.usec = (bss->age % 1000) * 1000;
266 os_reltime_sub(&scan_res->fetch_time, &time_tmp_age, &entry_ts);
268 ies = (const u8 *) (bss + 1);
269 ies_len = bss->ie_len;
270 if (bss->beacon_ie_len > 0 &&
271 !wpa_scan_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) &&
272 wpa_scan_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
273 wpa_printf(MSG_DEBUG, "P2P: Use P2P IE(s) from Beacon frame since no P2P IE(s) in Probe Response frames received for "
274 MACSTR, MAC2STR(bss->bssid));
276 ies_len = bss->beacon_ie_len;
280 if (p2p_scan_res_handler(wpa_s->global->p2p, bss->bssid,
281 bss->freq, &entry_ts, bss->level,
286 p2p_scan_res_handled(wpa_s->global->p2p);
290 static void wpas_p2p_trigger_scan_cb(struct wpa_radio_work *work, int deinit)
292 struct wpa_supplicant *wpa_s = work->wpa_s;
293 struct wpa_driver_scan_params *params = work->ctx;
297 if (!work->started) {
298 wpa_scan_free_params(params);
302 wpa_s->p2p_scan_work = NULL;
306 ret = wpa_drv_scan(wpa_s, params);
307 wpa_scan_free_params(params);
310 radio_work_done(work);
311 p2p_notify_scan_trigger_status(wpa_s->global->p2p, ret);
315 p2p_notify_scan_trigger_status(wpa_s->global->p2p, ret);
316 os_get_reltime(&wpa_s->scan_trigger_time);
317 wpa_s->scan_res_handler = wpas_p2p_scan_res_handler;
318 wpa_s->own_scan_requested = 1;
319 wpa_s->p2p_scan_work = work;
323 static int wpas_p2p_search_social_channel(struct wpa_supplicant *wpa_s,
326 if (wpa_s->global->p2p_24ghz_social_channels &&
327 (freq == 2412 || freq == 2437 || freq == 2462)) {
329 * Search all social channels regardless of whether these have
330 * been disabled for P2P operating channel use to avoid missing
335 return p2p_supported_freq(wpa_s->global->p2p, freq);
339 static int wpas_p2p_scan(void *ctx, enum p2p_scan_type type, int freq,
340 unsigned int num_req_dev_types,
341 const u8 *req_dev_types, const u8 *dev_id, u16 pw_id)
343 struct wpa_supplicant *wpa_s = ctx;
344 struct wpa_driver_scan_params *params = NULL;
345 struct wpabuf *wps_ie, *ies;
346 unsigned int num_channels = 0;
347 int social_channels_freq[] = { 2412, 2437, 2462, 60480 };
351 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
354 if (wpa_s->p2p_scan_work) {
355 wpa_dbg(wpa_s, MSG_INFO, "P2P: Reject scan trigger since one is already pending");
359 params = os_zalloc(sizeof(*params));
363 /* P2P Wildcard SSID */
364 params->num_ssids = 1;
365 n = os_malloc(P2P_WILDCARD_SSID_LEN);
368 os_memcpy(n, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN);
369 params->ssids[0].ssid = n;
370 params->ssids[0].ssid_len = P2P_WILDCARD_SSID_LEN;
372 wpa_s->wps->dev.p2p = 1;
373 wps_ie = wps_build_probe_req_ie(pw_id, &wpa_s->wps->dev,
374 wpa_s->wps->uuid, WPS_REQ_ENROLLEE,
375 num_req_dev_types, req_dev_types);
379 ielen = p2p_scan_ie_buf_len(wpa_s->global->p2p);
380 ies = wpabuf_alloc(wpabuf_len(wps_ie) + ielen);
385 wpabuf_put_buf(ies, wps_ie);
388 p2p_scan_ie(wpa_s->global->p2p, ies, dev_id);
390 params->p2p_probe = 1;
391 n = os_malloc(wpabuf_len(ies));
396 os_memcpy(n, wpabuf_head(ies), wpabuf_len(ies));
397 params->extra_ies = n;
398 params->extra_ies_len = wpabuf_len(ies);
402 case P2P_SCAN_SOCIAL:
403 params->freqs = os_calloc(ARRAY_SIZE(social_channels_freq) + 1,
405 if (params->freqs == NULL)
407 for (i = 0; i < ARRAY_SIZE(social_channels_freq); i++) {
408 if (wpas_p2p_search_social_channel(
409 wpa_s, social_channels_freq[i]))
410 params->freqs[num_channels++] =
411 social_channels_freq[i];
413 params->freqs[num_channels++] = 0;
417 case P2P_SCAN_SPECIFIC:
418 params->freqs = os_calloc(2, sizeof(int));
419 if (params->freqs == NULL)
421 params->freqs[0] = freq;
422 params->freqs[1] = 0;
424 case P2P_SCAN_SOCIAL_PLUS_ONE:
425 params->freqs = os_calloc(ARRAY_SIZE(social_channels_freq) + 2,
427 if (params->freqs == NULL)
429 for (i = 0; i < ARRAY_SIZE(social_channels_freq); i++) {
430 if (wpas_p2p_search_social_channel(
431 wpa_s, social_channels_freq[i]))
432 params->freqs[num_channels++] =
433 social_channels_freq[i];
435 if (p2p_supported_freq(wpa_s->global->p2p, freq))
436 params->freqs[num_channels++] = freq;
437 params->freqs[num_channels++] = 0;
441 radio_remove_works(wpa_s, "p2p-scan", 0);
442 if (radio_add_work(wpa_s, 0, "p2p-scan", 0, wpas_p2p_trigger_scan_cb,
448 wpa_scan_free_params(params);
453 static enum wpa_driver_if_type wpas_p2p_if_type(int p2p_group_interface)
455 switch (p2p_group_interface) {
456 case P2P_GROUP_INTERFACE_PENDING:
457 return WPA_IF_P2P_GROUP;
458 case P2P_GROUP_INTERFACE_GO:
459 return WPA_IF_P2P_GO;
460 case P2P_GROUP_INTERFACE_CLIENT:
461 return WPA_IF_P2P_CLIENT;
464 return WPA_IF_P2P_GROUP;
468 static struct wpa_supplicant * wpas_get_p2p_group(struct wpa_supplicant *wpa_s,
470 size_t ssid_len, int *go)
474 for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) {
475 for (s = wpa_s->conf->ssid; s; s = s->next) {
476 if (s->disabled != 0 || !s->p2p_group ||
477 s->ssid_len != ssid_len ||
478 os_memcmp(ssid, s->ssid, ssid_len) != 0)
480 if (s->mode == WPAS_MODE_P2P_GO &&
481 s != wpa_s->current_ssid)
484 *go = s->mode == WPAS_MODE_P2P_GO;
493 static void run_wpas_p2p_disconnect(void *eloop_ctx, void *timeout_ctx)
495 struct wpa_supplicant *wpa_s = eloop_ctx;
496 wpa_printf(MSG_DEBUG,
497 "P2P: Complete previously requested removal of %s",
499 wpas_p2p_disconnect(wpa_s);
503 static int wpas_p2p_disconnect_safely(struct wpa_supplicant *wpa_s,
504 struct wpa_supplicant *calling_wpa_s)
506 if (calling_wpa_s == wpa_s && wpa_s &&
507 wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE) {
509 * The calling wpa_s instance is going to be removed. Do that
510 * from an eloop callback to keep the instance available until
511 * the caller has returned. This my be needed, e.g., to provide
512 * control interface responses on the per-interface socket.
514 if (eloop_register_timeout(0, 0, run_wpas_p2p_disconnect,
520 return wpas_p2p_disconnect(wpa_s);
524 /* Determine total number of clients in active groups where we are the GO */
525 static unsigned int p2p_group_go_member_count(struct wpa_supplicant *wpa_s)
527 unsigned int count = 0;
530 for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) {
531 for (s = wpa_s->conf->ssid; s; s = s->next) {
532 wpa_printf(MSG_DEBUG,
533 "P2P: sup:%p ssid:%p disabled:%d p2p:%d mode:%d",
534 wpa_s, s, s->disabled, s->p2p_group,
536 if (!s->disabled && s->p2p_group &&
537 s->mode == WPAS_MODE_P2P_GO) {
538 count += p2p_get_group_num_members(
548 /* Find an interface for a P2P group where we are the GO */
549 static struct wpa_supplicant *
550 wpas_p2p_get_go_group(struct wpa_supplicant *wpa_s)
552 struct wpa_supplicant *save = NULL;
558 for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) {
559 for (s = wpa_s->conf->ssid; s; s = s->next) {
560 if (s->disabled || !s->p2p_group ||
561 s->mode != WPAS_MODE_P2P_GO)
564 /* Prefer a group with connected clients */
565 if (p2p_get_group_num_members(wpa_s->p2p_group))
571 /* No group with connected clients, so pick the one without (if any) */
576 /* Find an active P2P group where we are the GO */
577 static struct wpa_ssid * wpas_p2p_group_go_ssid(struct wpa_supplicant *wpa_s,
580 struct wpa_ssid *s, *empty = NULL;
585 for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) {
586 for (s = wpa_s->conf->ssid; s; s = s->next) {
587 if (s->disabled || !s->p2p_group ||
588 s->mode != WPAS_MODE_P2P_GO)
591 os_memcpy(bssid, wpa_s->own_addr, ETH_ALEN);
592 if (p2p_get_group_num_members(wpa_s->p2p_group))
602 /* Find a persistent group where we are the GO */
603 static struct wpa_ssid *
604 wpas_p2p_get_persistent_go(struct wpa_supplicant *wpa_s)
608 for (s = wpa_s->conf->ssid; s; s = s->next) {
609 if (s->disabled == 2 && s->mode == WPAS_MODE_P2P_GO)
617 static u8 p2ps_group_capability(void *ctx, u8 incoming, u8 role)
619 struct wpa_supplicant *wpa_s = ctx, *tmp_wpa_s;
621 u8 conncap = P2PS_SETUP_NONE;
622 unsigned int owned_members = 0;
623 unsigned int owner = 0;
624 unsigned int client = 0;
625 struct wpa_supplicant *go_wpa_s;
626 struct wpa_ssid *persistent_go;
627 int p2p_no_group_iface;
629 wpa_printf(MSG_DEBUG, "P2P: Conncap - in:%d role:%d", incoming, role);
632 * For non-concurrent capable devices:
633 * If persistent_go, then no new.
634 * If GO, then no client.
635 * If client, then no GO.
637 go_wpa_s = wpas_p2p_get_go_group(wpa_s);
638 persistent_go = wpas_p2p_get_persistent_go(wpa_s);
639 p2p_no_group_iface = !wpas_p2p_create_iface(wpa_s);
641 wpa_printf(MSG_DEBUG, "P2P: GO(iface)=%p persistent(ssid)=%p",
642 go_wpa_s, persistent_go);
644 for (tmp_wpa_s = wpa_s->global->ifaces; tmp_wpa_s;
645 tmp_wpa_s = tmp_wpa_s->next) {
646 for (s = tmp_wpa_s->conf->ssid; s; s = s->next) {
647 wpa_printf(MSG_DEBUG,
648 "P2P: sup:%p ssid:%p disabled:%d p2p:%d mode:%d",
649 tmp_wpa_s, s, s->disabled,
650 s->p2p_group, s->mode);
651 if (!s->disabled && s->p2p_group) {
652 if (s->mode == WPAS_MODE_P2P_GO) {
654 p2p_get_group_num_members(
655 tmp_wpa_s->p2p_group);
663 /* If not concurrent, restrict our choices */
664 if (p2p_no_group_iface) {
665 wpa_printf(MSG_DEBUG, "P2P: p2p_no_group_iface");
668 return P2PS_SETUP_NONE;
671 if (role == P2PS_SETUP_CLIENT ||
672 incoming == P2PS_SETUP_GROUP_OWNER ||
673 p2p_client_limit_reached(go_wpa_s->p2p_group))
674 return P2PS_SETUP_NONE;
676 return P2PS_SETUP_GROUP_OWNER;
680 if (role == P2PS_SETUP_NONE || role == P2PS_SETUP_NEW) {
682 return P2PS_SETUP_GROUP_OWNER |
684 if (incoming == P2PS_SETUP_NEW) {
687 if (os_get_random(&r, sizeof(r)) < 0 ||
689 return P2PS_SETUP_CLIENT;
690 return P2PS_SETUP_GROUP_OWNER;
696 /* If a required role has been specified, handle it here */
697 if (role && role != P2PS_SETUP_NEW) {
699 case P2PS_SETUP_NONE:
701 case P2PS_SETUP_GROUP_OWNER | P2PS_SETUP_CLIENT:
702 case P2PS_SETUP_GROUP_OWNER | P2PS_SETUP_NEW:
706 case P2PS_SETUP_GROUP_OWNER:
708 * Must be a complimentary role - cannot be a client to
709 * more than one peer.
711 if (incoming == role || client)
712 return P2PS_SETUP_NONE;
714 return P2PS_SETUP_CLIENT;
716 case P2PS_SETUP_CLIENT:
717 /* Must be a complimentary role */
718 if (incoming != role) {
719 conncap = P2PS_SETUP_GROUP_OWNER;
724 return P2PS_SETUP_NONE;
729 * For now, we only will support ownership of one group, and being a
730 * client of one group. Therefore, if we have either an existing GO
731 * group, or an existing client group, we will not do a new GO
732 * negotiation, but rather try to re-use the existing groups.
735 case P2PS_SETUP_NONE:
738 conncap = P2PS_SETUP_GROUP_OWNER;
739 else if (!owned_members)
740 conncap = P2PS_SETUP_NEW;
741 else if (incoming == P2PS_SETUP_NONE)
742 conncap = P2PS_SETUP_GROUP_OWNER | P2PS_SETUP_CLIENT;
744 conncap = P2PS_SETUP_CLIENT;
747 case P2PS_SETUP_CLIENT:
748 conncap = P2PS_SETUP_GROUP_OWNER;
751 case P2PS_SETUP_GROUP_OWNER:
753 conncap = P2PS_SETUP_CLIENT;
756 case P2PS_SETUP_GROUP_OWNER | P2PS_SETUP_NEW:
757 case P2PS_SETUP_GROUP_OWNER | P2PS_SETUP_CLIENT:
759 conncap = P2PS_SETUP_GROUP_OWNER;
763 if (os_get_random(&r, sizeof(r)) < 0 ||
765 conncap = P2PS_SETUP_CLIENT;
767 conncap = P2PS_SETUP_GROUP_OWNER;
772 return P2PS_SETUP_NONE;
776 if ((conncap & P2PS_SETUP_GROUP_OWNER) ||
777 (!incoming && (conncap & P2PS_SETUP_NEW))) {
778 if (go_wpa_s && p2p_client_limit_reached(go_wpa_s->p2p_group))
779 conncap &= ~P2PS_SETUP_GROUP_OWNER;
780 wpa_printf(MSG_DEBUG, "P2P: GOs:%d members:%d conncap:%d",
781 owner, owned_members, conncap);
783 s = wpas_p2p_get_persistent_go(wpa_s);
785 if (!s && !owner && p2p_no_group_iface) {
786 p2p_set_intended_addr(wpa_s->global->p2p,
788 } else if (!s && !owner) {
789 if (wpas_p2p_add_group_interface(wpa_s,
790 WPA_IF_P2P_GO) < 0) {
791 wpa_printf(MSG_ERROR,
792 "P2P: Failed to allocate a new interface for the group");
793 return P2PS_SETUP_NONE;
795 wpa_s->global->pending_group_iface_for_p2ps = 1;
796 p2p_set_intended_addr(wpa_s->global->p2p,
797 wpa_s->pending_interface_addr);
805 static int wpas_p2p_group_delete(struct wpa_supplicant *wpa_s,
806 enum p2p_group_removal_reason removal_reason)
808 struct wpa_ssid *ssid;
812 ssid = wpa_s->current_ssid;
815 * The current SSID was not known, but there may still be a
816 * pending P2P group interface waiting for provisioning or a
817 * P2P group that is trying to reconnect.
819 ssid = wpa_s->conf->ssid;
821 if (ssid->p2p_group && ssid->disabled != 2)
826 wpa_s->p2p_group_interface == NOT_P2P_GROUP_INTERFACE)
828 wpa_printf(MSG_ERROR, "P2P: P2P group interface "
833 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO)
835 else if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT ||
836 (ssid && ssid->mode == WPAS_MODE_INFRA)) {
837 wpa_s->reassociate = 0;
838 wpa_s->disconnected = 1;
843 if (removal_reason != P2P_GROUP_REMOVAL_SILENT && ssid)
844 wpas_notify_p2p_group_removed(wpa_s, ssid, gtype);
846 if (os_strcmp(gtype, "client") == 0) {
847 wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
848 if (eloop_is_timeout_registered(wpas_p2p_psk_failure_removal,
850 wpa_printf(MSG_DEBUG,
851 "P2P: PSK failure removal was scheduled, so use PSK failure as reason for group removal");
852 removal_reason = P2P_GROUP_REMOVAL_PSK_FAILURE;
853 eloop_cancel_timeout(wpas_p2p_psk_failure_removal,
858 if (wpa_s->cross_connect_in_use) {
859 wpa_s->cross_connect_in_use = 0;
860 wpa_msg_global(wpa_s->parent, MSG_INFO,
861 P2P_EVENT_CROSS_CONNECT_DISABLE "%s %s",
862 wpa_s->ifname, wpa_s->cross_connect_uplink);
864 switch (removal_reason) {
865 case P2P_GROUP_REMOVAL_REQUESTED:
866 reason = " reason=REQUESTED";
868 case P2P_GROUP_REMOVAL_FORMATION_FAILED:
869 reason = " reason=FORMATION_FAILED";
871 case P2P_GROUP_REMOVAL_IDLE_TIMEOUT:
872 reason = " reason=IDLE";
874 case P2P_GROUP_REMOVAL_UNAVAILABLE:
875 reason = " reason=UNAVAILABLE";
877 case P2P_GROUP_REMOVAL_GO_ENDING_SESSION:
878 reason = " reason=GO_ENDING_SESSION";
880 case P2P_GROUP_REMOVAL_PSK_FAILURE:
881 reason = " reason=PSK_FAILURE";
883 case P2P_GROUP_REMOVAL_FREQ_CONFLICT:
884 reason = " reason=FREQ_CONFLICT";
890 if (removal_reason != P2P_GROUP_REMOVAL_SILENT) {
891 wpa_msg_global(wpa_s->parent, MSG_INFO,
892 P2P_EVENT_GROUP_REMOVED "%s %s%s",
893 wpa_s->ifname, gtype, reason);
896 if (eloop_cancel_timeout(wpas_p2p_group_freq_conflict, wpa_s, NULL) > 0)
897 wpa_printf(MSG_DEBUG, "P2P: Cancelled P2P group freq_conflict timeout");
898 if (eloop_cancel_timeout(wpas_p2p_group_idle_timeout, wpa_s, NULL) > 0)
899 wpa_printf(MSG_DEBUG, "P2P: Cancelled P2P group idle timeout");
900 if (eloop_cancel_timeout(wpas_p2p_group_formation_timeout,
901 wpa_s->parent, NULL) > 0) {
902 wpa_printf(MSG_DEBUG, "P2P: Cancelled P2P group formation "
904 wpa_s->p2p_in_provisioning = 0;
905 wpas_p2p_group_formation_failed(wpa_s, 1);
908 wpa_s->p2p_in_invitation = 0;
909 eloop_cancel_timeout(wpas_p2p_move_go, wpa_s, NULL);
910 eloop_cancel_timeout(wpas_p2p_reconsider_moving_go, wpa_s, NULL);
913 * Make sure wait for the first client does not remain active after the
914 * group has been removed.
916 wpa_s->global->p2p_go_wait_client.sec = 0;
918 if (wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE) {
919 struct wpa_global *global;
921 enum wpa_driver_if_type type;
922 wpa_printf(MSG_DEBUG, "P2P: Remove group interface %s",
924 global = wpa_s->global;
925 ifname = os_strdup(wpa_s->ifname);
926 type = wpas_p2p_if_type(wpa_s->p2p_group_interface);
927 eloop_cancel_timeout(run_wpas_p2p_disconnect, wpa_s, NULL);
928 wpa_supplicant_remove_iface(wpa_s->global, wpa_s, 0);
929 wpa_s = global->ifaces;
931 wpa_drv_if_remove(wpa_s, type, ifname);
936 if (!wpa_s->p2p_go_group_formation_completed) {
937 wpa_s->global->p2p_group_formation = NULL;
938 wpa_s->p2p_in_provisioning = 0;
941 wpa_s->show_group_started = 0;
942 os_free(wpa_s->go_params);
943 wpa_s->go_params = NULL;
945 os_free(wpa_s->p2p_group_common_freqs);
946 wpa_s->p2p_group_common_freqs = NULL;
947 wpa_s->p2p_group_common_freqs_num = 0;
949 wpa_s->waiting_presence_resp = 0;
951 wpa_printf(MSG_DEBUG, "P2P: Remove temporary group network");
952 if (ssid && (ssid->p2p_group ||
953 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION ||
954 (ssid->key_mgmt & WPA_KEY_MGMT_WPS))) {
956 if (ssid == wpa_s->current_ssid) {
957 wpa_sm_set_config(wpa_s->wpa, NULL);
958 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
959 wpa_s->current_ssid = NULL;
962 * Networks objects created during any P2P activities are not
963 * exposed out as they might/will confuse certain non-P2P aware
964 * applications since these network objects won't behave like
967 * Likewise, we don't send out network removed signals for such
970 wpa_config_remove_network(wpa_s->conf, id);
971 wpa_supplicant_clear_status(wpa_s);
972 wpa_supplicant_cancel_sched_scan(wpa_s);
974 wpa_printf(MSG_DEBUG, "P2P: Temporary group network not "
978 wpa_supplicant_ap_deinit(wpa_s);
980 wpa_drv_deinit_p2p_cli(wpa_s);
982 os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN);
988 static int wpas_p2p_persistent_group(struct wpa_supplicant *wpa_s,
990 const u8 *ssid, size_t ssid_len)
998 if (wpa_s->go_params)
999 bssid = wpa_s->go_params->peer_interface_addr;
1001 bssid = wpa_s->bssid;
1003 bss = wpa_bss_get(wpa_s, bssid, ssid, ssid_len);
1004 if (bss == NULL && wpa_s->go_params &&
1005 !is_zero_ether_addr(wpa_s->go_params->peer_device_addr))
1006 bss = wpa_bss_get_p2p_dev_addr(
1007 wpa_s, wpa_s->go_params->peer_device_addr);
1009 u8 iface_addr[ETH_ALEN];
1010 if (p2p_get_interface_addr(wpa_s->global->p2p, bssid,
1012 bss = wpa_bss_get(wpa_s, iface_addr, ssid, ssid_len);
1015 wpa_printf(MSG_DEBUG, "P2P: Could not figure out whether "
1016 "group is persistent - BSS " MACSTR " not found",
1021 p2p = wpa_bss_get_vendor_ie_multi(bss, P2P_IE_VENDOR_TYPE);
1023 p2p = wpa_bss_get_vendor_ie_multi_beacon(bss,
1024 P2P_IE_VENDOR_TYPE);
1026 wpa_printf(MSG_DEBUG, "P2P: Could not figure out whether "
1027 "group is persistent - BSS " MACSTR
1028 " did not include P2P IE", MAC2STR(bssid));
1029 wpa_hexdump(MSG_DEBUG, "P2P: Probe Response IEs",
1030 (u8 *) (bss + 1), bss->ie_len);
1031 wpa_hexdump(MSG_DEBUG, "P2P: Beacon IEs",
1032 ((u8 *) bss + 1) + bss->ie_len,
1033 bss->beacon_ie_len);
1037 group_capab = p2p_get_group_capab(p2p);
1038 addr = p2p_get_go_dev_addr(p2p);
1039 wpa_printf(MSG_DEBUG, "P2P: Checking whether group is persistent: "
1040 "group_capab=0x%x", group_capab);
1042 os_memcpy(go_dev_addr, addr, ETH_ALEN);
1043 wpa_printf(MSG_DEBUG, "P2P: GO Device Address " MACSTR,
1046 os_memset(go_dev_addr, 0, ETH_ALEN);
1049 wpa_printf(MSG_DEBUG, "P2P: BSS " MACSTR " group_capab=0x%x "
1050 "go_dev_addr=" MACSTR,
1051 MAC2STR(bssid), group_capab, MAC2STR(go_dev_addr));
1053 return group_capab & P2P_GROUP_CAPAB_PERSISTENT_GROUP;
1057 static int wpas_p2p_store_persistent_group(struct wpa_supplicant *wpa_s,
1058 struct wpa_ssid *ssid,
1059 const u8 *go_dev_addr)
1064 wpa_printf(MSG_DEBUG, "P2P: Storing credentials for a persistent "
1065 "group (GO Dev Addr " MACSTR ")", MAC2STR(go_dev_addr));
1066 for (s = wpa_s->conf->ssid; s; s = s->next) {
1067 if (s->disabled == 2 &&
1068 os_memcmp(go_dev_addr, s->bssid, ETH_ALEN) == 0 &&
1069 s->ssid_len == ssid->ssid_len &&
1070 os_memcmp(ssid->ssid, s->ssid, ssid->ssid_len) == 0)
1075 wpa_printf(MSG_DEBUG, "P2P: Update existing persistent group "
1077 if (ssid->passphrase && !s->passphrase)
1079 else if (ssid->passphrase && s->passphrase &&
1080 os_strcmp(ssid->passphrase, s->passphrase) != 0)
1083 wpa_printf(MSG_DEBUG, "P2P: Create a new persistent group "
1086 s = wpa_config_add_network(wpa_s->conf);
1091 * Instead of network_added we emit persistent_group_added
1092 * notification. Also to keep the defense checks in
1093 * persistent_group obj registration method, we set the
1094 * relevant flags in s to designate it as a persistent group.
1097 s->p2p_persistent_group = 1;
1098 wpas_notify_persistent_group_added(wpa_s, s);
1099 wpa_config_set_network_defaults(s);
1103 s->p2p_persistent_group = 1;
1106 os_memcpy(s->bssid, go_dev_addr, ETH_ALEN);
1107 s->mode = ssid->mode;
1108 s->auth_alg = WPA_AUTH_ALG_OPEN;
1109 s->key_mgmt = WPA_KEY_MGMT_PSK;
1110 s->proto = WPA_PROTO_RSN;
1111 s->pairwise_cipher = WPA_CIPHER_CCMP;
1113 if (ssid->passphrase) {
1114 os_free(s->passphrase);
1115 s->passphrase = os_strdup(ssid->passphrase);
1117 if (ssid->psk_set) {
1119 os_memcpy(s->psk, ssid->psk, 32);
1121 if (s->passphrase && !s->psk_set)
1122 wpa_config_update_psk(s);
1123 if (s->ssid == NULL || s->ssid_len < ssid->ssid_len) {
1125 s->ssid = os_malloc(ssid->ssid_len);
1128 s->ssid_len = ssid->ssid_len;
1129 os_memcpy(s->ssid, ssid->ssid, s->ssid_len);
1131 if (ssid->mode == WPAS_MODE_P2P_GO && wpa_s->global->add_psk) {
1132 dl_list_add(&s->psk_list, &wpa_s->global->add_psk->list);
1133 wpa_s->global->add_psk = NULL;
1137 if (changed && wpa_s->conf->update_config &&
1138 wpa_config_write(wpa_s->confname, wpa_s->conf)) {
1139 wpa_printf(MSG_DEBUG, "P2P: Failed to update configuration");
1146 static void wpas_p2p_add_persistent_group_client(struct wpa_supplicant *wpa_s,
1149 struct wpa_ssid *ssid, *s;
1153 struct wpa_supplicant *p2p_wpa_s = wpa_s->global->p2p_init_wpa_s;
1155 ssid = wpa_s->current_ssid;
1156 if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO ||
1157 !ssid->p2p_persistent_group)
1160 for (s = p2p_wpa_s->conf->ssid; s; s = s->next) {
1161 if (s->disabled != 2 || s->mode != WPAS_MODE_P2P_GO)
1164 if (s->ssid_len == ssid->ssid_len &&
1165 os_memcmp(s->ssid, ssid->ssid, s->ssid_len) == 0)
1172 for (i = 0; s->p2p_client_list && i < s->num_p2p_clients; i++) {
1173 if (os_memcmp(s->p2p_client_list + i * 2 * ETH_ALEN, addr,
1177 if (i == s->num_p2p_clients - 1)
1178 return; /* already the most recent entry */
1180 /* move the entry to mark it most recent */
1181 os_memmove(s->p2p_client_list + i * 2 * ETH_ALEN,
1182 s->p2p_client_list + (i + 1) * 2 * ETH_ALEN,
1183 (s->num_p2p_clients - i - 1) * 2 * ETH_ALEN);
1184 os_memcpy(s->p2p_client_list +
1185 (s->num_p2p_clients - 1) * 2 * ETH_ALEN, addr,
1187 os_memset(s->p2p_client_list +
1188 (s->num_p2p_clients - 1) * 2 * ETH_ALEN + ETH_ALEN,
1194 if (!found && s->num_p2p_clients < P2P_MAX_STORED_CLIENTS) {
1195 n = os_realloc_array(s->p2p_client_list,
1196 s->num_p2p_clients + 1, 2 * ETH_ALEN);
1199 os_memcpy(n + s->num_p2p_clients * 2 * ETH_ALEN, addr,
1201 os_memset(n + s->num_p2p_clients * 2 * ETH_ALEN + ETH_ALEN,
1203 s->p2p_client_list = n;
1204 s->num_p2p_clients++;
1205 } else if (!found && s->p2p_client_list) {
1206 /* Not enough room for an additional entry - drop the oldest
1208 os_memmove(s->p2p_client_list,
1209 s->p2p_client_list + 2 * ETH_ALEN,
1210 (s->num_p2p_clients - 1) * 2 * ETH_ALEN);
1211 os_memcpy(s->p2p_client_list +
1212 (s->num_p2p_clients - 1) * 2 * ETH_ALEN,
1214 os_memset(s->p2p_client_list +
1215 (s->num_p2p_clients - 1) * 2 * ETH_ALEN + ETH_ALEN,
1219 if (p2p_wpa_s->conf->update_config &&
1220 wpa_config_write(p2p_wpa_s->confname, p2p_wpa_s->conf))
1221 wpa_printf(MSG_DEBUG, "P2P: Failed to update configuration");
1225 static void wpas_p2p_group_started(struct wpa_supplicant *wpa_s,
1226 int go, struct wpa_ssid *ssid, int freq,
1227 const u8 *psk, const char *passphrase,
1228 const u8 *go_dev_addr, int persistent,
1231 const char *ssid_txt;
1235 wpa_snprintf_hex(psk_txt, sizeof(psk_txt), psk, 32);
1240 ssid_txt = wpa_ssid_txt(ssid->ssid, ssid->ssid_len);
1244 if (passphrase && passphrase[0] == '\0')
1248 * Include PSK/passphrase only in the control interface message and
1249 * leave it out from the debug log entry.
1251 wpa_msg_global_ctrl(wpa_s->parent, MSG_INFO,
1252 P2P_EVENT_GROUP_STARTED
1253 "%s %s ssid=\"%s\" freq=%d%s%s%s%s%s go_dev_addr="
1255 wpa_s->ifname, go ? "GO" : "client", ssid_txt, freq,
1256 psk ? " psk=" : "", psk_txt,
1257 passphrase ? " passphrase=\"" : "",
1258 passphrase ? passphrase : "",
1259 passphrase ? "\"" : "",
1260 MAC2STR(go_dev_addr),
1261 persistent ? " [PERSISTENT]" : "", extra);
1262 wpa_printf(MSG_INFO, P2P_EVENT_GROUP_STARTED
1263 "%s %s ssid=\"%s\" freq=%d go_dev_addr=" MACSTR "%s%s",
1264 wpa_s->ifname, go ? "GO" : "client", ssid_txt, freq,
1265 MAC2STR(go_dev_addr), persistent ? " [PERSISTENT]" : "",
1270 static void wpas_group_formation_completed(struct wpa_supplicant *wpa_s,
1271 int success, int already_deleted)
1273 struct wpa_ssid *ssid;
1276 u8 go_dev_addr[ETH_ALEN];
1277 int network_id = -1;
1280 * This callback is likely called for the main interface. Update wpa_s
1281 * to use the group interface if a new interface was created for the
1284 if (wpa_s->global->p2p_group_formation)
1285 wpa_s = wpa_s->global->p2p_group_formation;
1286 if (wpa_s->p2p_go_group_formation_completed) {
1287 wpa_s->global->p2p_group_formation = NULL;
1288 wpa_s->p2p_in_provisioning = 0;
1290 wpa_s->p2p_in_invitation = 0;
1291 wpa_s->group_formation_reported = 1;
1294 wpa_msg_global(wpa_s->parent, MSG_INFO,
1295 P2P_EVENT_GROUP_FORMATION_FAILURE);
1296 wpas_notify_p2p_group_formation_failure(wpa_s, "");
1297 if (already_deleted)
1299 wpas_p2p_group_delete(wpa_s,
1300 P2P_GROUP_REMOVAL_FORMATION_FAILED);
1304 wpa_msg_global(wpa_s->parent, MSG_INFO,
1305 P2P_EVENT_GROUP_FORMATION_SUCCESS);
1307 ssid = wpa_s->current_ssid;
1308 if (ssid && ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION) {
1309 ssid->mode = WPAS_MODE_P2P_GO;
1310 p2p_group_notif_formation_done(wpa_s->p2p_group);
1311 wpa_supplicant_ap_mac_addr_filter(wpa_s, NULL);
1316 client = ssid->mode == WPAS_MODE_INFRA;
1317 if (ssid->mode == WPAS_MODE_P2P_GO) {
1318 persistent = ssid->p2p_persistent_group;
1319 os_memcpy(go_dev_addr, wpa_s->global->p2p_dev_addr,
1322 persistent = wpas_p2p_persistent_group(wpa_s,
1327 client = wpa_s->p2p_group_interface ==
1328 P2P_GROUP_INTERFACE_CLIENT;
1329 os_memset(go_dev_addr, 0, ETH_ALEN);
1332 wpa_s->show_group_started = 0;
1335 * Indicate event only after successfully completed 4-way
1336 * handshake, i.e., when the interface is ready for data
1339 wpa_s->show_group_started = 1;
1341 wpas_p2p_group_started(wpa_s, 1, ssid,
1342 ssid ? ssid->frequency : 0,
1343 ssid && ssid->passphrase == NULL &&
1344 ssid->psk_set ? ssid->psk : NULL,
1345 ssid ? ssid->passphrase : NULL,
1346 go_dev_addr, persistent, "");
1347 wpas_p2p_cross_connect_setup(wpa_s);
1348 wpas_p2p_set_group_idle_timeout(wpa_s);
1352 network_id = wpas_p2p_store_persistent_group(wpa_s->parent,
1355 os_free(wpa_s->global->add_psk);
1356 wpa_s->global->add_psk = NULL;
1358 if (network_id < 0 && ssid)
1359 network_id = ssid->id;
1361 wpas_notify_p2p_group_started(wpa_s, ssid, network_id, 0);
1362 os_get_reltime(&wpa_s->global->p2p_go_wait_client);
1367 struct send_action_work {
1373 unsigned int wait_time;
1378 static void wpas_p2p_send_action_work_timeout(void *eloop_ctx,
1381 struct wpa_supplicant *wpa_s = eloop_ctx;
1383 if (!wpa_s->p2p_send_action_work)
1386 wpa_printf(MSG_DEBUG, "P2P: Send Action frame radio work timed out");
1387 os_free(wpa_s->p2p_send_action_work->ctx);
1388 radio_work_done(wpa_s->p2p_send_action_work);
1389 wpa_s->p2p_send_action_work = NULL;
1393 static void wpas_p2p_action_tx_clear(struct wpa_supplicant *wpa_s)
1395 if (wpa_s->p2p_send_action_work) {
1396 struct send_action_work *awork;
1397 awork = wpa_s->p2p_send_action_work->ctx;
1398 if (awork->wait_time == 0) {
1400 radio_work_done(wpa_s->p2p_send_action_work);
1401 wpa_s->p2p_send_action_work = NULL;
1404 * In theory, this should not be needed, but number of
1405 * places in the P2P code is still using non-zero wait
1406 * time for the last Action frame in the sequence and
1407 * some of these do not call send_action_done().
1409 eloop_cancel_timeout(wpas_p2p_send_action_work_timeout,
1411 eloop_register_timeout(
1412 0, awork->wait_time * 1000,
1413 wpas_p2p_send_action_work_timeout,
1420 static void wpas_p2p_send_action_tx_status(struct wpa_supplicant *wpa_s,
1422 const u8 *dst, const u8 *src,
1424 const u8 *data, size_t data_len,
1425 enum offchannel_send_action_result
1428 enum p2p_send_action_result res = P2P_SEND_ACTION_SUCCESS;
1430 wpas_p2p_action_tx_clear(wpa_s);
1432 if (wpa_s->global->p2p == NULL || wpa_s->global->p2p_disabled)
1436 case OFFCHANNEL_SEND_ACTION_SUCCESS:
1437 res = P2P_SEND_ACTION_SUCCESS;
1439 case OFFCHANNEL_SEND_ACTION_NO_ACK:
1440 res = P2P_SEND_ACTION_NO_ACK;
1442 case OFFCHANNEL_SEND_ACTION_FAILED:
1443 res = P2P_SEND_ACTION_FAILED;
1447 p2p_send_action_cb(wpa_s->global->p2p, freq, dst, src, bssid, res);
1449 if (result != OFFCHANNEL_SEND_ACTION_SUCCESS &&
1450 wpa_s->pending_pd_before_join &&
1451 (os_memcmp(dst, wpa_s->pending_join_dev_addr, ETH_ALEN) == 0 ||
1452 os_memcmp(dst, wpa_s->pending_join_iface_addr, ETH_ALEN) == 0) &&
1453 wpa_s->p2p_fallback_to_go_neg) {
1454 wpa_s->pending_pd_before_join = 0;
1455 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: No ACK for PD Req "
1456 "during p2p_connect-auto");
1457 wpa_msg_global(wpa_s->parent, MSG_INFO,
1458 P2P_EVENT_FALLBACK_TO_GO_NEG
1459 "reason=no-ACK-to-PD-Req");
1460 wpas_p2p_fallback_to_go_neg(wpa_s, 0);
1466 static void wpas_send_action_cb(struct wpa_radio_work *work, int deinit)
1468 struct wpa_supplicant *wpa_s = work->wpa_s;
1469 struct send_action_work *awork = work->ctx;
1472 if (work->started) {
1473 eloop_cancel_timeout(wpas_p2p_send_action_work_timeout,
1475 wpa_s->p2p_send_action_work = NULL;
1476 offchannel_send_action_done(wpa_s);
1482 if (offchannel_send_action(wpa_s, awork->freq, awork->dst, awork->src,
1483 awork->bssid, awork->buf, awork->len,
1485 wpas_p2p_send_action_tx_status, 1) < 0) {
1487 radio_work_done(work);
1490 wpa_s->p2p_send_action_work = work;
1494 static int wpas_send_action_work(struct wpa_supplicant *wpa_s,
1495 unsigned int freq, const u8 *dst,
1496 const u8 *src, const u8 *bssid, const u8 *buf,
1497 size_t len, unsigned int wait_time)
1499 struct send_action_work *awork;
1501 if (wpa_s->p2p_send_action_work) {
1502 wpa_printf(MSG_DEBUG, "P2P: Cannot schedule new p2p-send-action work since one is already pending");
1506 awork = os_zalloc(sizeof(*awork) + len);
1511 os_memcpy(awork->dst, dst, ETH_ALEN);
1512 os_memcpy(awork->src, src, ETH_ALEN);
1513 os_memcpy(awork->bssid, bssid, ETH_ALEN);
1515 awork->wait_time = wait_time;
1516 os_memcpy(awork->buf, buf, len);
1518 if (radio_add_work(wpa_s, freq, "p2p-send-action", 0,
1519 wpas_send_action_cb, awork) < 0) {
1528 static int wpas_send_action(void *ctx, unsigned int freq, const u8 *dst,
1529 const u8 *src, const u8 *bssid, const u8 *buf,
1530 size_t len, unsigned int wait_time)
1532 struct wpa_supplicant *wpa_s = ctx;
1533 int listen_freq = -1, send_freq = -1;
1535 if (wpa_s->p2p_listen_work)
1536 listen_freq = wpa_s->p2p_listen_work->freq;
1537 if (wpa_s->p2p_send_action_work)
1538 send_freq = wpa_s->p2p_send_action_work->freq;
1539 if (listen_freq != (int) freq && send_freq != (int) freq) {
1540 wpa_printf(MSG_DEBUG, "P2P: Schedule new radio work for Action frame TX (listen_freq=%d send_freq=%d)",
1541 listen_freq, send_freq);
1542 return wpas_send_action_work(wpa_s, freq, dst, src, bssid, buf,
1546 wpa_printf(MSG_DEBUG, "P2P: Use ongoing radio work for Action frame TX");
1547 return offchannel_send_action(wpa_s, freq, dst, src, bssid, buf, len,
1549 wpas_p2p_send_action_tx_status, 1);
1553 static void wpas_send_action_done(void *ctx)
1555 struct wpa_supplicant *wpa_s = ctx;
1557 if (wpa_s->p2p_send_action_work) {
1558 eloop_cancel_timeout(wpas_p2p_send_action_work_timeout,
1560 os_free(wpa_s->p2p_send_action_work->ctx);
1561 radio_work_done(wpa_s->p2p_send_action_work);
1562 wpa_s->p2p_send_action_work = NULL;
1565 offchannel_send_action_done(wpa_s);
1569 static int wpas_copy_go_neg_results(struct wpa_supplicant *wpa_s,
1570 struct p2p_go_neg_results *params)
1572 if (wpa_s->go_params == NULL) {
1573 wpa_s->go_params = os_malloc(sizeof(*params));
1574 if (wpa_s->go_params == NULL)
1577 os_memcpy(wpa_s->go_params, params, sizeof(*params));
1582 static void wpas_start_wps_enrollee(struct wpa_supplicant *wpa_s,
1583 struct p2p_go_neg_results *res)
1585 wpa_s->group_formation_reported = 0;
1586 wpa_printf(MSG_DEBUG, "P2P: Start WPS Enrollee for peer " MACSTR
1587 " dev_addr " MACSTR " wps_method %d",
1588 MAC2STR(res->peer_interface_addr),
1589 MAC2STR(res->peer_device_addr), res->wps_method);
1590 wpa_hexdump_ascii(MSG_DEBUG, "P2P: Start WPS Enrollee for SSID",
1591 res->ssid, res->ssid_len);
1592 wpa_supplicant_ap_deinit(wpa_s);
1593 wpas_copy_go_neg_results(wpa_s, res);
1594 if (res->wps_method == WPS_PBC) {
1595 wpas_wps_start_pbc(wpa_s, res->peer_interface_addr, 1);
1596 #ifdef CONFIG_WPS_NFC
1597 } else if (res->wps_method == WPS_NFC) {
1598 wpas_wps_start_nfc(wpa_s, res->peer_device_addr,
1599 res->peer_interface_addr,
1600 wpa_s->parent->p2p_oob_dev_pw,
1601 wpa_s->parent->p2p_oob_dev_pw_id, 1,
1602 wpa_s->parent->p2p_oob_dev_pw_id ==
1603 DEV_PW_NFC_CONNECTION_HANDOVER ?
1604 wpa_s->parent->p2p_peer_oob_pubkey_hash :
1607 #endif /* CONFIG_WPS_NFC */
1609 u16 dev_pw_id = DEV_PW_DEFAULT;
1610 if (wpa_s->p2p_wps_method == WPS_P2PS)
1611 dev_pw_id = DEV_PW_P2PS_DEFAULT;
1612 if (wpa_s->p2p_wps_method == WPS_PIN_KEYPAD)
1613 dev_pw_id = DEV_PW_REGISTRAR_SPECIFIED;
1614 wpas_wps_start_pin(wpa_s, res->peer_interface_addr,
1615 wpa_s->p2p_pin, 1, dev_pw_id);
1620 static void wpas_p2p_add_psk_list(struct wpa_supplicant *wpa_s,
1621 struct wpa_ssid *ssid)
1623 struct wpa_ssid *persistent;
1624 struct psk_list_entry *psk;
1625 struct hostapd_data *hapd;
1627 if (!wpa_s->ap_iface)
1630 persistent = wpas_p2p_get_persistent(wpa_s->parent, NULL, ssid->ssid,
1632 if (persistent == NULL)
1635 hapd = wpa_s->ap_iface->bss[0];
1637 dl_list_for_each(psk, &persistent->psk_list, struct psk_list_entry,
1639 struct hostapd_wpa_psk *hpsk;
1641 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Add persistent group PSK entry for "
1643 MAC2STR(psk->addr), psk->p2p);
1644 hpsk = os_zalloc(sizeof(*hpsk));
1647 os_memcpy(hpsk->psk, psk->psk, PMK_LEN);
1649 os_memcpy(hpsk->p2p_dev_addr, psk->addr, ETH_ALEN);
1651 os_memcpy(hpsk->addr, psk->addr, ETH_ALEN);
1652 hpsk->next = hapd->conf->ssid.wpa_psk;
1653 hapd->conf->ssid.wpa_psk = hpsk;
1658 static void p2p_go_dump_common_freqs(struct wpa_supplicant *wpa_s)
1662 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Common group frequencies (len=%u):",
1663 wpa_s->p2p_group_common_freqs_num);
1665 for (i = 0; i < wpa_s->p2p_group_common_freqs_num; i++)
1666 wpa_dbg(wpa_s, MSG_DEBUG, "freq[%u]: %d",
1667 i, wpa_s->p2p_group_common_freqs[i]);
1671 static void p2p_go_save_group_common_freqs(struct wpa_supplicant *wpa_s,
1672 struct p2p_go_neg_results *params)
1674 unsigned int i, len = int_array_len(wpa_s->go_params->freq_list);
1676 wpa_s->p2p_group_common_freqs_num = 0;
1677 os_free(wpa_s->p2p_group_common_freqs);
1678 wpa_s->p2p_group_common_freqs = os_calloc(len, sizeof(int));
1679 if (!wpa_s->p2p_group_common_freqs)
1682 for (i = 0; i < len; i++) {
1683 if (!wpa_s->go_params->freq_list[i])
1685 wpa_s->p2p_group_common_freqs[i] =
1686 wpa_s->go_params->freq_list[i];
1688 wpa_s->p2p_group_common_freqs_num = i;
1692 static void p2p_config_write(struct wpa_supplicant *wpa_s)
1694 #ifndef CONFIG_NO_CONFIG_WRITE
1695 if (wpa_s->parent->conf->update_config &&
1696 wpa_config_write(wpa_s->parent->confname, wpa_s->parent->conf))
1697 wpa_printf(MSG_DEBUG, "P2P: Failed to update configuration");
1698 #endif /* CONFIG_NO_CONFIG_WRITE */
1702 static void p2p_go_configured(void *ctx, void *data)
1704 struct wpa_supplicant *wpa_s = ctx;
1705 struct p2p_go_neg_results *params = data;
1706 struct wpa_ssid *ssid;
1707 int network_id = -1;
1709 p2p_go_save_group_common_freqs(wpa_s, params);
1710 p2p_go_dump_common_freqs(wpa_s);
1712 ssid = wpa_s->current_ssid;
1713 if (ssid && ssid->mode == WPAS_MODE_P2P_GO) {
1714 wpa_printf(MSG_DEBUG, "P2P: Group setup without provisioning");
1715 if (wpa_s->global->p2p_group_formation == wpa_s)
1716 wpa_s->global->p2p_group_formation = NULL;
1717 wpas_p2p_group_started(wpa_s, 1, ssid, ssid->frequency,
1718 params->passphrase[0] == '\0' ?
1721 wpa_s->global->p2p_dev_addr,
1722 params->persistent_group, "");
1723 wpa_s->group_formation_reported = 1;
1725 if (wpa_s->parent->p2ps_method_config_any) {
1726 if (is_zero_ether_addr(wpa_s->parent->p2ps_join_addr)) {
1727 wpa_dbg(wpa_s, MSG_DEBUG,
1728 "P2PS: Setting default PIN for ANY");
1729 wpa_supplicant_ap_wps_pin(wpa_s, NULL,
1730 "12345670", NULL, 0,
1733 wpa_dbg(wpa_s, MSG_DEBUG,
1734 "P2PS: Setting default PIN for " MACSTR,
1735 MAC2STR(wpa_s->parent->p2ps_join_addr));
1736 wpa_supplicant_ap_wps_pin(
1737 wpa_s, wpa_s->parent->p2ps_join_addr,
1738 "12345670", NULL, 0, 0);
1740 wpa_s->parent->p2ps_method_config_any = 0;
1743 os_get_reltime(&wpa_s->global->p2p_go_wait_client);
1744 if (params->persistent_group) {
1745 network_id = wpas_p2p_store_persistent_group(
1746 wpa_s->parent, ssid,
1747 wpa_s->global->p2p_dev_addr);
1748 wpas_p2p_add_psk_list(wpa_s, ssid);
1751 network_id = ssid->id;
1752 wpas_notify_p2p_group_started(wpa_s, ssid, network_id, 0);
1753 wpas_p2p_cross_connect_setup(wpa_s);
1754 wpas_p2p_set_group_idle_timeout(wpa_s);
1756 if (wpa_s->p2p_first_connection_timeout) {
1757 wpa_dbg(wpa_s, MSG_DEBUG,
1758 "P2P: Start group formation timeout of %d seconds until first data connection on GO",
1759 wpa_s->p2p_first_connection_timeout);
1760 wpa_s->p2p_go_group_formation_completed = 0;
1761 wpa_s->global->p2p_group_formation = wpa_s;
1762 eloop_cancel_timeout(wpas_p2p_group_formation_timeout,
1763 wpa_s->parent, NULL);
1764 eloop_register_timeout(
1765 wpa_s->p2p_first_connection_timeout, 0,
1766 wpas_p2p_group_formation_timeout,
1767 wpa_s->parent, NULL);
1773 wpa_printf(MSG_DEBUG, "P2P: Setting up WPS for GO provisioning");
1774 if (wpa_supplicant_ap_mac_addr_filter(wpa_s,
1775 params->peer_interface_addr)) {
1776 wpa_printf(MSG_DEBUG, "P2P: Failed to setup MAC address "
1780 if (params->wps_method == WPS_PBC) {
1781 wpa_supplicant_ap_wps_pbc(wpa_s, params->peer_interface_addr,
1782 params->peer_device_addr);
1783 #ifdef CONFIG_WPS_NFC
1784 } else if (params->wps_method == WPS_NFC) {
1785 if (wpa_s->parent->p2p_oob_dev_pw_id !=
1786 DEV_PW_NFC_CONNECTION_HANDOVER &&
1787 !wpa_s->parent->p2p_oob_dev_pw) {
1788 wpa_printf(MSG_DEBUG, "P2P: No NFC Dev Pw known");
1791 wpas_ap_wps_add_nfc_pw(
1792 wpa_s, wpa_s->parent->p2p_oob_dev_pw_id,
1793 wpa_s->parent->p2p_oob_dev_pw,
1794 wpa_s->parent->p2p_peer_oob_pk_hash_known ?
1795 wpa_s->parent->p2p_peer_oob_pubkey_hash : NULL);
1796 #endif /* CONFIG_WPS_NFC */
1797 } else if (wpa_s->p2p_pin[0])
1798 wpa_supplicant_ap_wps_pin(wpa_s, params->peer_interface_addr,
1799 wpa_s->p2p_pin, NULL, 0, 0);
1800 os_free(wpa_s->go_params);
1801 wpa_s->go_params = NULL;
1805 static void wpas_start_wps_go(struct wpa_supplicant *wpa_s,
1806 struct p2p_go_neg_results *params,
1807 int group_formation)
1809 struct wpa_ssid *ssid;
1811 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Starting GO");
1812 if (wpas_copy_go_neg_results(wpa_s, params) < 0) {
1813 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Could not copy GO Negotiation "
1818 ssid = wpa_config_add_network(wpa_s->conf);
1820 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Could not add network for GO");
1824 wpa_s->show_group_started = 0;
1825 wpa_s->p2p_go_group_formation_completed = 0;
1826 wpa_s->group_formation_reported = 0;
1827 os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN);
1829 wpa_config_set_network_defaults(ssid);
1830 ssid->temporary = 1;
1831 ssid->p2p_group = 1;
1832 ssid->p2p_persistent_group = params->persistent_group;
1833 ssid->mode = group_formation ? WPAS_MODE_P2P_GROUP_FORMATION :
1835 ssid->frequency = params->freq;
1836 ssid->ht40 = params->ht40;
1837 ssid->vht = params->vht;
1838 ssid->ssid = os_zalloc(params->ssid_len + 1);
1840 os_memcpy(ssid->ssid, params->ssid, params->ssid_len);
1841 ssid->ssid_len = params->ssid_len;
1843 ssid->auth_alg = WPA_AUTH_ALG_OPEN;
1844 ssid->key_mgmt = WPA_KEY_MGMT_PSK;
1845 ssid->proto = WPA_PROTO_RSN;
1846 ssid->pairwise_cipher = WPA_CIPHER_CCMP;
1847 ssid->group_cipher = WPA_CIPHER_CCMP;
1848 if (params->freq > 56160) {
1850 * Enable GCMP instead of CCMP as pairwise_cipher and
1851 * group_cipher in 60 GHz.
1853 ssid->pairwise_cipher = WPA_CIPHER_GCMP;
1854 ssid->group_cipher = WPA_CIPHER_GCMP;
1856 if (os_strlen(params->passphrase) > 0) {
1857 ssid->passphrase = os_strdup(params->passphrase);
1858 if (ssid->passphrase == NULL) {
1859 wpa_msg_global(wpa_s, MSG_ERROR,
1860 "P2P: Failed to copy passphrase for GO");
1861 wpa_config_remove_network(wpa_s->conf, ssid->id);
1865 ssid->passphrase = NULL;
1866 ssid->psk_set = params->psk_set;
1868 os_memcpy(ssid->psk, params->psk, sizeof(ssid->psk));
1869 else if (ssid->passphrase)
1870 wpa_config_update_psk(ssid);
1871 ssid->ap_max_inactivity = wpa_s->parent->conf->p2p_go_max_inactivity;
1873 wpa_s->ap_configured_cb = p2p_go_configured;
1874 wpa_s->ap_configured_cb_ctx = wpa_s;
1875 wpa_s->ap_configured_cb_data = wpa_s->go_params;
1876 wpa_s->scan_req = NORMAL_SCAN_REQ;
1877 wpa_s->connect_without_scan = ssid;
1878 wpa_s->reassociate = 1;
1879 wpa_s->disconnected = 0;
1880 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Request scan (that will be skipped) to "
1882 wpa_supplicant_req_scan(wpa_s, 0, 0);
1886 static void wpas_p2p_clone_config(struct wpa_supplicant *dst,
1887 const struct wpa_supplicant *src)
1889 struct wpa_config *d;
1890 const struct wpa_config *s;
1895 #define C(n) if (s->n) d->n = os_strdup(s->n)
1904 os_memcpy(d->device_type, s->device_type, WPS_DEV_TYPE_LEN);
1905 os_memcpy(d->sec_device_type, s->sec_device_type,
1906 sizeof(d->sec_device_type));
1907 d->num_sec_device_types = s->num_sec_device_types;
1909 d->p2p_group_idle = s->p2p_group_idle;
1910 d->p2p_go_freq_change_policy = s->p2p_go_freq_change_policy;
1911 d->p2p_intra_bss = s->p2p_intra_bss;
1912 d->persistent_reconnect = s->persistent_reconnect;
1913 d->max_num_sta = s->max_num_sta;
1914 d->pbc_in_m1 = s->pbc_in_m1;
1915 d->ignore_old_scan_res = s->ignore_old_scan_res;
1916 d->beacon_int = s->beacon_int;
1917 d->dtim_period = s->dtim_period;
1918 d->p2p_go_ctwindow = s->p2p_go_ctwindow;
1919 d->disassoc_low_ack = s->disassoc_low_ack;
1920 d->disable_scan_offload = s->disable_scan_offload;
1921 d->passive_scan = s->passive_scan;
1923 if (s->wps_nfc_dh_privkey && s->wps_nfc_dh_pubkey) {
1924 d->wps_nfc_dh_privkey = wpabuf_dup(s->wps_nfc_dh_privkey);
1925 d->wps_nfc_dh_pubkey = wpabuf_dup(s->wps_nfc_dh_pubkey);
1927 d->p2p_cli_probe = s->p2p_cli_probe;
1931 static void wpas_p2p_get_group_ifname(struct wpa_supplicant *wpa_s,
1932 char *ifname, size_t len)
1934 char *ifname_ptr = wpa_s->ifname;
1936 if (os_strncmp(wpa_s->ifname, P2P_MGMT_DEVICE_PREFIX,
1937 os_strlen(P2P_MGMT_DEVICE_PREFIX)) == 0) {
1938 ifname_ptr = os_strrchr(wpa_s->ifname, '-') + 1;
1941 os_snprintf(ifname, len, "p2p-%s-%d", ifname_ptr, wpa_s->p2p_group_idx);
1942 if (os_strlen(ifname) >= IFNAMSIZ &&
1943 os_strlen(wpa_s->ifname) < IFNAMSIZ) {
1946 /* Try to avoid going over the IFNAMSIZ length limit */
1947 res = os_snprintf(ifname, len, "p2p-%d", wpa_s->p2p_group_idx);
1948 if (os_snprintf_error(len, res) && len)
1949 ifname[len - 1] = '\0';
1954 static int wpas_p2p_add_group_interface(struct wpa_supplicant *wpa_s,
1955 enum wpa_driver_if_type type)
1957 char ifname[120], force_ifname[120];
1959 if (wpa_s->pending_interface_name[0]) {
1960 wpa_printf(MSG_DEBUG, "P2P: Pending virtual interface exists "
1961 "- skip creation of a new one");
1962 if (is_zero_ether_addr(wpa_s->pending_interface_addr)) {
1963 wpa_printf(MSG_DEBUG, "P2P: Pending virtual address "
1964 "unknown?! ifname='%s'",
1965 wpa_s->pending_interface_name);
1971 wpas_p2p_get_group_ifname(wpa_s, ifname, sizeof(ifname));
1972 force_ifname[0] = '\0';
1974 wpa_printf(MSG_DEBUG, "P2P: Create a new interface %s for the group",
1976 wpa_s->p2p_group_idx++;
1978 wpa_s->pending_interface_type = type;
1979 if (wpa_drv_if_add(wpa_s, type, ifname, NULL, NULL, force_ifname,
1980 wpa_s->pending_interface_addr, NULL) < 0) {
1981 wpa_printf(MSG_ERROR, "P2P: Failed to create new group "
1986 if (force_ifname[0]) {
1987 wpa_printf(MSG_DEBUG, "P2P: Driver forced interface name %s",
1989 os_strlcpy(wpa_s->pending_interface_name, force_ifname,
1990 sizeof(wpa_s->pending_interface_name));
1992 os_strlcpy(wpa_s->pending_interface_name, ifname,
1993 sizeof(wpa_s->pending_interface_name));
1994 wpa_printf(MSG_DEBUG, "P2P: Created pending virtual interface %s addr "
1995 MACSTR, wpa_s->pending_interface_name,
1996 MAC2STR(wpa_s->pending_interface_addr));
2002 static void wpas_p2p_remove_pending_group_interface(
2003 struct wpa_supplicant *wpa_s)
2005 if (!wpa_s->pending_interface_name[0] ||
2006 is_zero_ether_addr(wpa_s->pending_interface_addr))
2007 return; /* No pending virtual interface */
2009 wpa_printf(MSG_DEBUG, "P2P: Removing pending group interface %s",
2010 wpa_s->pending_interface_name);
2011 wpa_drv_if_remove(wpa_s, wpa_s->pending_interface_type,
2012 wpa_s->pending_interface_name);
2013 os_memset(wpa_s->pending_interface_addr, 0, ETH_ALEN);
2014 wpa_s->pending_interface_name[0] = '\0';
2015 wpa_s->global->pending_group_iface_for_p2ps = 0;
2019 static struct wpa_supplicant *
2020 wpas_p2p_init_group_interface(struct wpa_supplicant *wpa_s, int go)
2022 struct wpa_interface iface;
2023 struct wpa_supplicant *group_wpa_s;
2025 if (!wpa_s->pending_interface_name[0]) {
2026 wpa_printf(MSG_ERROR, "P2P: No pending group interface");
2027 if (!wpas_p2p_create_iface(wpa_s))
2030 * Something has forced us to remove the pending interface; try
2031 * to create a new one and hope for the best that we will get
2032 * the same local address.
2034 if (wpas_p2p_add_group_interface(wpa_s, go ? WPA_IF_P2P_GO :
2035 WPA_IF_P2P_CLIENT) < 0)
2039 os_memset(&iface, 0, sizeof(iface));
2040 iface.ifname = wpa_s->pending_interface_name;
2041 iface.driver = wpa_s->driver->name;
2042 if (wpa_s->conf->ctrl_interface == NULL &&
2043 wpa_s->parent != wpa_s &&
2045 (wpa_s->drv_flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE))
2046 iface.ctrl_interface = wpa_s->parent->conf->ctrl_interface;
2048 iface.ctrl_interface = wpa_s->conf->ctrl_interface;
2049 iface.driver_param = wpa_s->conf->driver_param;
2050 group_wpa_s = wpa_supplicant_add_iface(wpa_s->global, &iface, wpa_s);
2051 if (group_wpa_s == NULL) {
2052 wpa_printf(MSG_ERROR, "P2P: Failed to create new "
2053 "wpa_supplicant interface");
2056 wpa_s->pending_interface_name[0] = '\0';
2057 group_wpa_s->p2p_group_interface = go ? P2P_GROUP_INTERFACE_GO :
2058 P2P_GROUP_INTERFACE_CLIENT;
2059 wpa_s->global->p2p_group_formation = group_wpa_s;
2060 wpa_s->global->pending_group_iface_for_p2ps = 0;
2062 wpas_p2p_clone_config(group_wpa_s, wpa_s);
2068 static void wpas_p2p_group_formation_timeout(void *eloop_ctx,
2071 struct wpa_supplicant *wpa_s = eloop_ctx;
2072 wpa_printf(MSG_DEBUG, "P2P: Group Formation timed out");
2073 wpas_p2p_group_formation_failed(wpa_s, 0);
2077 static void wpas_p2p_group_formation_failed(struct wpa_supplicant *wpa_s,
2078 int already_deleted)
2080 eloop_cancel_timeout(wpas_p2p_group_formation_timeout,
2081 wpa_s->parent, NULL);
2082 if (wpa_s->global->p2p)
2083 p2p_group_formation_failed(wpa_s->global->p2p);
2084 wpas_group_formation_completed(wpa_s, 0, already_deleted);
2088 static void wpas_p2p_grpform_fail_after_wps(struct wpa_supplicant *wpa_s)
2090 wpa_printf(MSG_DEBUG, "P2P: Reject group formation due to WPS provisioning failure");
2091 eloop_cancel_timeout(wpas_p2p_group_formation_timeout,
2092 wpa_s->parent, NULL);
2093 eloop_register_timeout(0, 0, wpas_p2p_group_formation_timeout,
2094 wpa_s->parent, NULL);
2095 wpa_s->global->p2p_fail_on_wps_complete = 0;
2099 void wpas_p2p_ap_setup_failed(struct wpa_supplicant *wpa_s)
2101 if (wpa_s->global->p2p_group_formation != wpa_s)
2103 /* Speed up group formation timeout since this cannot succeed */
2104 eloop_cancel_timeout(wpas_p2p_group_formation_timeout,
2105 wpa_s->parent, NULL);
2106 eloop_register_timeout(0, 0, wpas_p2p_group_formation_timeout,
2107 wpa_s->parent, NULL);
2111 static void wpas_go_neg_completed(void *ctx, struct p2p_go_neg_results *res)
2113 struct wpa_supplicant *wpa_s = ctx;
2115 if (wpa_s->off_channel_freq || wpa_s->roc_waiting_drv_freq) {
2116 wpa_drv_cancel_remain_on_channel(wpa_s);
2117 wpa_s->off_channel_freq = 0;
2118 wpa_s->roc_waiting_drv_freq = 0;
2122 wpa_msg_global(wpa_s, MSG_INFO,
2123 P2P_EVENT_GO_NEG_FAILURE "status=%d",
2125 wpas_notify_p2p_go_neg_completed(wpa_s, res);
2126 wpas_p2p_remove_pending_group_interface(wpa_s);
2130 if (!res->role_go) {
2131 /* Inform driver of the operating channel of GO. */
2132 wpa_drv_set_prob_oper_freq(wpa_s, res->freq);
2135 if (wpa_s->p2p_go_ht40)
2137 if (wpa_s->p2p_go_vht)
2140 wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_GO_NEG_SUCCESS "role=%s "
2141 "freq=%d ht40=%d peer_dev=" MACSTR " peer_iface=" MACSTR
2143 res->role_go ? "GO" : "client", res->freq, res->ht40,
2144 MAC2STR(res->peer_device_addr),
2145 MAC2STR(res->peer_interface_addr),
2146 p2p_wps_method_text(res->wps_method));
2147 wpas_notify_p2p_go_neg_completed(wpa_s, res);
2149 if (res->role_go && wpa_s->p2p_persistent_id >= 0) {
2150 struct wpa_ssid *ssid;
2151 ssid = wpa_config_get_network(wpa_s->conf,
2152 wpa_s->p2p_persistent_id);
2153 if (ssid && ssid->disabled == 2 &&
2154 ssid->mode == WPAS_MODE_P2P_GO && ssid->passphrase) {
2155 size_t len = os_strlen(ssid->passphrase);
2156 wpa_printf(MSG_DEBUG, "P2P: Override passphrase based "
2157 "on requested persistent group");
2158 os_memcpy(res->passphrase, ssid->passphrase, len);
2159 res->passphrase[len] = '\0';
2163 if (wpa_s->create_p2p_iface) {
2164 struct wpa_supplicant *group_wpa_s =
2165 wpas_p2p_init_group_interface(wpa_s, res->role_go);
2166 if (group_wpa_s == NULL) {
2167 wpas_p2p_remove_pending_group_interface(wpa_s);
2168 eloop_cancel_timeout(wpas_p2p_long_listen_timeout,
2170 wpas_p2p_group_formation_failed(wpa_s, 1);
2173 if (group_wpa_s != wpa_s) {
2174 os_memcpy(group_wpa_s->p2p_pin, wpa_s->p2p_pin,
2175 sizeof(group_wpa_s->p2p_pin));
2176 group_wpa_s->p2p_wps_method = wpa_s->p2p_wps_method;
2178 os_memset(wpa_s->pending_interface_addr, 0, ETH_ALEN);
2179 wpa_s->pending_interface_name[0] = '\0';
2180 group_wpa_s->p2p_in_provisioning = 1;
2183 wpas_start_wps_go(group_wpa_s, res, 1);
2185 os_get_reltime(&group_wpa_s->scan_min_time);
2186 wpas_start_wps_enrollee(group_wpa_s, res);
2189 wpa_s->p2p_in_provisioning = 1;
2190 wpa_s->global->p2p_group_formation = wpa_s;
2193 wpas_start_wps_go(wpa_s, res, 1);
2195 os_get_reltime(&wpa_s->scan_min_time);
2196 wpas_start_wps_enrollee(ctx, res);
2200 wpa_s->p2p_long_listen = 0;
2201 eloop_cancel_timeout(wpas_p2p_long_listen_timeout, wpa_s, NULL);
2203 eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s, NULL);
2204 eloop_register_timeout(15 + res->peer_config_timeout / 100,
2205 (res->peer_config_timeout % 100) * 10000,
2206 wpas_p2p_group_formation_timeout, wpa_s, NULL);
2210 static void wpas_go_neg_req_rx(void *ctx, const u8 *src, u16 dev_passwd_id,
2213 struct wpa_supplicant *wpa_s = ctx;
2214 wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_GO_NEG_REQUEST MACSTR
2215 " dev_passwd_id=%u go_intent=%u", MAC2STR(src),
2216 dev_passwd_id, go_intent);
2218 wpas_notify_p2p_go_neg_req(wpa_s, src, dev_passwd_id, go_intent);
2222 static void wpas_dev_found(void *ctx, const u8 *addr,
2223 const struct p2p_peer_info *info,
2226 #ifndef CONFIG_NO_STDOUT_DEBUG
2227 struct wpa_supplicant *wpa_s = ctx;
2228 char devtype[WPS_DEV_TYPE_BUFSIZE];
2229 char *wfd_dev_info_hex = NULL;
2231 #ifdef CONFIG_WIFI_DISPLAY
2232 wfd_dev_info_hex = wifi_display_subelem_hex(info->wfd_subelems,
2233 WFD_SUBELEM_DEVICE_INFO);
2234 #endif /* CONFIG_WIFI_DISPLAY */
2236 if (info->p2ps_instance) {
2238 const u8 *buf = wpabuf_head(info->p2ps_instance);
2239 size_t len = wpabuf_len(info->p2ps_instance);
2246 if (len < 4 + 2 + 1)
2248 id = WPA_GET_LE32(buf);
2250 methods = WPA_GET_BE16(buf);
2253 if (str_len > len - 4 - 2 - 1)
2255 os_memcpy(str, buf, str_len);
2256 str[str_len] = '\0';
2258 len -= str_len + sizeof(u32) + sizeof(u16) + sizeof(u8);
2260 wpa_msg_global(wpa_s, MSG_INFO,
2261 P2P_EVENT_DEVICE_FOUND MACSTR
2262 " p2p_dev_addr=" MACSTR
2263 " pri_dev_type=%s name='%s'"
2264 " config_methods=0x%x"
2267 " adv_id=%x asp_svc=%s%s",
2269 MAC2STR(info->p2p_device_addr),
2270 wps_dev_type_bin2str(
2272 devtype, sizeof(devtype)),
2273 info->device_name, methods,
2274 info->dev_capab, info->group_capab,
2276 info->vendor_elems ?
2277 " vendor_elems=1" : "");
2282 wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_DEVICE_FOUND MACSTR
2283 " p2p_dev_addr=" MACSTR
2284 " pri_dev_type=%s name='%s' config_methods=0x%x "
2285 "dev_capab=0x%x group_capab=0x%x%s%s%s new=%d",
2286 MAC2STR(addr), MAC2STR(info->p2p_device_addr),
2287 wps_dev_type_bin2str(info->pri_dev_type, devtype,
2289 info->device_name, info->config_methods,
2290 info->dev_capab, info->group_capab,
2291 wfd_dev_info_hex ? " wfd_dev_info=0x" : "",
2292 wfd_dev_info_hex ? wfd_dev_info_hex : "",
2293 info->vendor_elems ? " vendor_elems=1" : "",
2297 os_free(wfd_dev_info_hex);
2298 #endif /* CONFIG_NO_STDOUT_DEBUG */
2300 wpas_notify_p2p_device_found(ctx, info->p2p_device_addr, new_device);
2304 static void wpas_dev_lost(void *ctx, const u8 *dev_addr)
2306 struct wpa_supplicant *wpa_s = ctx;
2308 wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_DEVICE_LOST
2309 "p2p_dev_addr=" MACSTR, MAC2STR(dev_addr));
2311 wpas_notify_p2p_device_lost(wpa_s, dev_addr);
2315 static void wpas_find_stopped(void *ctx)
2317 struct wpa_supplicant *wpa_s = ctx;
2318 wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_FIND_STOPPED);
2319 wpas_notify_p2p_find_stopped(wpa_s);
2323 struct wpas_p2p_listen_work {
2325 unsigned int duration;
2326 struct wpabuf *probe_resp_ie;
2330 static void wpas_p2p_listen_work_free(struct wpas_p2p_listen_work *lwork)
2334 wpabuf_free(lwork->probe_resp_ie);
2339 static void wpas_p2p_listen_work_done(struct wpa_supplicant *wpa_s)
2341 struct wpas_p2p_listen_work *lwork;
2343 if (!wpa_s->p2p_listen_work)
2346 lwork = wpa_s->p2p_listen_work->ctx;
2347 wpas_p2p_listen_work_free(lwork);
2348 radio_work_done(wpa_s->p2p_listen_work);
2349 wpa_s->p2p_listen_work = NULL;
2353 static void wpas_start_listen_cb(struct wpa_radio_work *work, int deinit)
2355 struct wpa_supplicant *wpa_s = work->wpa_s;
2356 struct wpas_p2p_listen_work *lwork = work->ctx;
2357 unsigned int duration;
2360 if (work->started) {
2361 wpa_s->p2p_listen_work = NULL;
2362 wpas_stop_listen(wpa_s);
2364 wpas_p2p_listen_work_free(lwork);
2368 wpa_s->p2p_listen_work = work;
2370 wpa_drv_set_ap_wps_ie(wpa_s, NULL, lwork->probe_resp_ie, NULL);
2372 if (wpa_drv_probe_req_report(wpa_s, 1) < 0) {
2373 wpa_printf(MSG_DEBUG, "P2P: Failed to request the driver to "
2374 "report received Probe Request frames");
2375 wpas_p2p_listen_work_done(wpa_s);
2379 wpa_s->pending_listen_freq = lwork->freq;
2380 wpa_s->pending_listen_duration = lwork->duration;
2382 duration = lwork->duration;
2383 #ifdef CONFIG_TESTING_OPTIONS
2384 if (wpa_s->extra_roc_dur) {
2385 wpa_printf(MSG_DEBUG, "TESTING: Increase ROC duration %u -> %u",
2386 duration, duration + wpa_s->extra_roc_dur);
2387 duration += wpa_s->extra_roc_dur;
2389 #endif /* CONFIG_TESTING_OPTIONS */
2391 if (wpa_drv_remain_on_channel(wpa_s, lwork->freq, duration) < 0) {
2392 wpa_printf(MSG_DEBUG, "P2P: Failed to request the driver "
2393 "to remain on channel (%u MHz) for Listen "
2394 "state", lwork->freq);
2395 wpas_p2p_listen_work_done(wpa_s);
2396 wpa_s->pending_listen_freq = 0;
2399 wpa_s->off_channel_freq = 0;
2400 wpa_s->roc_waiting_drv_freq = lwork->freq;
2404 static int wpas_start_listen(void *ctx, unsigned int freq,
2405 unsigned int duration,
2406 const struct wpabuf *probe_resp_ie)
2408 struct wpa_supplicant *wpa_s = ctx;
2409 struct wpas_p2p_listen_work *lwork;
2411 if (wpa_s->p2p_listen_work) {
2412 wpa_printf(MSG_DEBUG, "P2P: Reject start_listen since p2p_listen_work already exists");
2416 lwork = os_zalloc(sizeof(*lwork));
2420 lwork->duration = duration;
2421 if (probe_resp_ie) {
2422 lwork->probe_resp_ie = wpabuf_dup(probe_resp_ie);
2423 if (lwork->probe_resp_ie == NULL) {
2424 wpas_p2p_listen_work_free(lwork);
2429 if (radio_add_work(wpa_s, freq, "p2p-listen", 0, wpas_start_listen_cb,
2431 wpas_p2p_listen_work_free(lwork);
2439 static void wpas_stop_listen(void *ctx)
2441 struct wpa_supplicant *wpa_s = ctx;
2442 if (wpa_s->off_channel_freq || wpa_s->roc_waiting_drv_freq) {
2443 wpa_drv_cancel_remain_on_channel(wpa_s);
2444 wpa_s->off_channel_freq = 0;
2445 wpa_s->roc_waiting_drv_freq = 0;
2447 wpa_drv_set_ap_wps_ie(wpa_s, NULL, NULL, NULL);
2450 * Don't cancel Probe Request RX reporting for a connected P2P Client
2451 * handling Probe Request frames.
2453 if (!wpa_s->p2p_cli_probe)
2454 wpa_drv_probe_req_report(wpa_s, 0);
2456 wpas_p2p_listen_work_done(wpa_s);
2460 static int wpas_send_probe_resp(void *ctx, const struct wpabuf *buf,
2463 struct wpa_supplicant *wpa_s = ctx;
2464 return wpa_drv_send_mlme(wpa_s, wpabuf_head(buf), wpabuf_len(buf), 1,
2469 static void wpas_prov_disc_local_display(struct wpa_supplicant *wpa_s,
2470 const u8 *peer, const char *params,
2471 unsigned int generated_pin)
2473 wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_SHOW_PIN MACSTR
2474 " %08d%s", MAC2STR(peer), generated_pin, params);
2478 static void wpas_prov_disc_local_keypad(struct wpa_supplicant *wpa_s,
2479 const u8 *peer, const char *params)
2481 wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_ENTER_PIN MACSTR
2482 "%s", MAC2STR(peer), params);
2486 static void wpas_prov_disc_req(void *ctx, const u8 *peer, u16 config_methods,
2487 const u8 *dev_addr, const u8 *pri_dev_type,
2488 const char *dev_name, u16 supp_config_methods,
2489 u8 dev_capab, u8 group_capab, const u8 *group_id,
2490 size_t group_id_len)
2492 struct wpa_supplicant *wpa_s = ctx;
2493 char devtype[WPS_DEV_TYPE_BUFSIZE];
2495 u8 empty_dev_type[8];
2496 unsigned int generated_pin = 0;
2497 struct wpa_supplicant *group = NULL;
2501 for (group = wpa_s->global->ifaces; group; group = group->next)
2503 struct wpa_ssid *s = group->current_ssid;
2505 s->mode == WPAS_MODE_P2P_GO &&
2506 group_id_len - ETH_ALEN == s->ssid_len &&
2507 os_memcmp(group_id + ETH_ALEN, s->ssid,
2513 if (pri_dev_type == NULL) {
2514 os_memset(empty_dev_type, 0, sizeof(empty_dev_type));
2515 pri_dev_type = empty_dev_type;
2517 res = os_snprintf(params, sizeof(params), " p2p_dev_addr=" MACSTR
2518 " pri_dev_type=%s name='%s' config_methods=0x%x "
2519 "dev_capab=0x%x group_capab=0x%x%s%s",
2521 wps_dev_type_bin2str(pri_dev_type, devtype,
2523 dev_name, supp_config_methods, dev_capab, group_capab,
2524 group ? " group=" : "",
2525 group ? group->ifname : "");
2526 if (os_snprintf_error(sizeof(params), res))
2527 wpa_printf(MSG_DEBUG, "P2P: PD Request event truncated");
2528 params[sizeof(params) - 1] = '\0';
2530 if (config_methods & WPS_CONFIG_DISPLAY) {
2531 generated_pin = wps_generate_pin();
2532 wpas_prov_disc_local_display(wpa_s, peer, params,
2534 } else if (config_methods & WPS_CONFIG_KEYPAD)
2535 wpas_prov_disc_local_keypad(wpa_s, peer, params);
2536 else if (config_methods & WPS_CONFIG_PUSHBUTTON)
2537 wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_PBC_REQ
2538 MACSTR "%s", MAC2STR(peer), params);
2540 wpas_notify_p2p_provision_discovery(wpa_s, peer, 1 /* request */,
2541 P2P_PROV_DISC_SUCCESS,
2542 config_methods, generated_pin);
2546 static void wpas_prov_disc_resp(void *ctx, const u8 *peer, u16 config_methods)
2548 struct wpa_supplicant *wpa_s = ctx;
2549 unsigned int generated_pin = 0;
2552 if (wpa_s->pending_pd_before_join &&
2553 (os_memcmp(peer, wpa_s->pending_join_dev_addr, ETH_ALEN) == 0 ||
2554 os_memcmp(peer, wpa_s->pending_join_iface_addr, ETH_ALEN) == 0)) {
2555 wpa_s->pending_pd_before_join = 0;
2556 wpa_printf(MSG_DEBUG, "P2P: Starting pending "
2557 "join-existing-group operation");
2558 wpas_p2p_join_start(wpa_s, 0, NULL, 0);
2562 if (wpa_s->pending_pd_use == AUTO_PD_JOIN ||
2563 wpa_s->pending_pd_use == AUTO_PD_GO_NEG) {
2566 res = os_snprintf(params, sizeof(params), " peer_go=%d",
2567 wpa_s->pending_pd_use == AUTO_PD_JOIN);
2568 if (os_snprintf_error(sizeof(params), res))
2569 params[sizeof(params) - 1] = '\0';
2573 if (config_methods & WPS_CONFIG_DISPLAY)
2574 wpas_prov_disc_local_keypad(wpa_s, peer, params);
2575 else if (config_methods & WPS_CONFIG_KEYPAD) {
2576 generated_pin = wps_generate_pin();
2577 wpas_prov_disc_local_display(wpa_s, peer, params,
2579 } else if (config_methods & WPS_CONFIG_PUSHBUTTON)
2580 wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_PBC_RESP
2581 MACSTR "%s", MAC2STR(peer), params);
2583 wpas_notify_p2p_provision_discovery(wpa_s, peer, 0 /* response */,
2584 P2P_PROV_DISC_SUCCESS,
2585 config_methods, generated_pin);
2589 static void wpas_prov_disc_fail(void *ctx, const u8 *peer,
2590 enum p2p_prov_disc_status status,
2591 u32 adv_id, const u8 *adv_mac,
2592 const char *deferred_session_resp)
2594 struct wpa_supplicant *wpa_s = ctx;
2596 if (wpa_s->p2p_fallback_to_go_neg) {
2597 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: PD for p2p_connect-auto "
2598 "failed - fall back to GO Negotiation");
2599 wpa_msg_global(wpa_s->parent, MSG_INFO,
2600 P2P_EVENT_FALLBACK_TO_GO_NEG
2601 "reason=PD-failed");
2602 wpas_p2p_fallback_to_go_neg(wpa_s, 0);
2606 if (status == P2P_PROV_DISC_TIMEOUT_JOIN) {
2607 wpa_s->pending_pd_before_join = 0;
2608 wpa_printf(MSG_DEBUG, "P2P: Starting pending "
2609 "join-existing-group operation (no ACK for PD "
2611 wpas_p2p_join_start(wpa_s, 0, NULL, 0);
2615 if (adv_id && adv_mac && deferred_session_resp) {
2616 wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_FAILURE
2617 " p2p_dev_addr=" MACSTR " status=%d adv_id=%x"
2618 " deferred_session_resp='%s'",
2619 MAC2STR(peer), status, adv_id,
2620 deferred_session_resp);
2621 } else if (adv_id && adv_mac) {
2622 wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_FAILURE
2623 " p2p_dev_addr=" MACSTR " status=%d adv_id=%x",
2624 MAC2STR(peer), status, adv_id);
2626 wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_FAILURE
2627 " p2p_dev_addr=" MACSTR " status=%d",
2628 MAC2STR(peer), status);
2631 wpas_notify_p2p_provision_discovery(wpa_s, peer, 0 /* response */,
2636 static int freq_included(struct wpa_supplicant *wpa_s,
2637 const struct p2p_channels *channels,
2640 if ((channels == NULL || p2p_channels_includes_freq(channels, freq)) &&
2641 wpas_p2p_go_is_peer_freq(wpa_s, freq))
2647 static void wpas_p2p_go_update_common_freqs(struct wpa_supplicant *wpa_s)
2649 unsigned int num = P2P_MAX_CHANNELS;
2653 p2p_go_dump_common_freqs(wpa_s);
2654 common_freqs = os_calloc(num, sizeof(int));
2658 ret = p2p_group_get_common_freqs(wpa_s->p2p_group, common_freqs, &num);
2660 wpa_dbg(wpa_s, MSG_DEBUG,
2661 "P2P: Failed to get group common freqs");
2662 os_free(common_freqs);
2666 os_free(wpa_s->p2p_group_common_freqs);
2667 wpa_s->p2p_group_common_freqs = common_freqs;
2668 wpa_s->p2p_group_common_freqs_num = num;
2669 p2p_go_dump_common_freqs(wpa_s);
2674 * Check if the given frequency is one of the possible operating frequencies
2675 * set after the completion of the GO Negotiation.
2677 static int wpas_p2p_go_is_peer_freq(struct wpa_supplicant *wpa_s, int freq)
2681 p2p_go_dump_common_freqs(wpa_s);
2683 /* assume no restrictions */
2684 if (!wpa_s->p2p_group_common_freqs_num)
2687 for (i = 0; i < wpa_s->p2p_group_common_freqs_num; i++) {
2688 if (wpa_s->p2p_group_common_freqs[i] == freq)
2696 * Pick the best frequency to use from all the currently used frequencies.
2698 static int wpas_p2p_pick_best_used_freq(struct wpa_supplicant *wpa_s,
2699 struct wpa_used_freq_data *freqs,
2704 /* find a candidate freq that is supported by P2P */
2705 for (c = 0; c < num; c++)
2706 if (p2p_supported_freq(wpa_s->global->p2p, freqs[c].freq))
2712 /* once we have a candidate, try to find a 'better' one */
2713 for (i = c + 1; i < num; i++) {
2714 if (!p2p_supported_freq(wpa_s->global->p2p, freqs[i].freq))
2718 * 1. Infrastructure station interfaces have higher preference.
2719 * 2. P2P Clients have higher preference.
2722 if (freqs[i].flags & WPA_FREQ_USED_BY_INFRA_STATION) {
2727 if ((freqs[i].flags & WPA_FREQ_USED_BY_P2P_CLIENT))
2730 return freqs[c].freq;
2734 static u8 wpas_invitation_process(void *ctx, const u8 *sa, const u8 *bssid,
2735 const u8 *go_dev_addr, const u8 *ssid,
2736 size_t ssid_len, int *go, u8 *group_bssid,
2737 int *force_freq, int persistent_group,
2738 const struct p2p_channels *channels,
2741 struct wpa_supplicant *wpa_s = ctx;
2743 struct wpa_used_freq_data *freqs;
2744 struct wpa_supplicant *grp;
2747 if (!persistent_group) {
2748 wpa_printf(MSG_DEBUG, "P2P: Invitation from " MACSTR
2749 " to join an active group (SSID: %s)",
2750 MAC2STR(sa), wpa_ssid_txt(ssid, ssid_len));
2751 if (!is_zero_ether_addr(wpa_s->p2p_auth_invite) &&
2752 (os_memcmp(go_dev_addr, wpa_s->p2p_auth_invite, ETH_ALEN)
2754 os_memcmp(sa, wpa_s->p2p_auth_invite, ETH_ALEN) == 0)) {
2755 wpa_printf(MSG_DEBUG, "P2P: Accept previously "
2756 "authorized invitation");
2760 #ifdef CONFIG_WPS_NFC
2761 if (dev_pw_id >= 0 && wpa_s->p2p_nfc_tag_enabled &&
2762 dev_pw_id == wpa_s->p2p_oob_dev_pw_id) {
2763 wpa_printf(MSG_DEBUG, "P2P: Accept invitation based on local enabled NFC Tag");
2764 wpa_s->p2p_wps_method = WPS_NFC;
2765 wpa_s->pending_join_wps_method = WPS_NFC;
2766 os_memcpy(wpa_s->pending_join_dev_addr,
2767 go_dev_addr, ETH_ALEN);
2768 os_memcpy(wpa_s->pending_join_iface_addr,
2772 #endif /* CONFIG_WPS_NFC */
2775 * Do not accept the invitation automatically; notify user and
2778 return P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE;
2781 grp = wpas_get_p2p_group(wpa_s, ssid, ssid_len, go);
2783 wpa_printf(MSG_DEBUG, "P2P: Accept invitation to already "
2784 "running persistent group");
2786 os_memcpy(group_bssid, grp->own_addr, ETH_ALEN);
2790 if (!is_zero_ether_addr(wpa_s->p2p_auth_invite) &&
2791 os_memcmp(sa, wpa_s->p2p_auth_invite, ETH_ALEN) == 0) {
2792 wpa_printf(MSG_DEBUG, "P2P: Accept previously initiated "
2793 "invitation to re-invoke a persistent group");
2794 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
2795 } else if (!wpa_s->conf->persistent_reconnect)
2796 return P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE;
2798 for (s = wpa_s->conf->ssid; s; s = s->next) {
2799 if (s->disabled == 2 &&
2800 os_memcmp(s->bssid, go_dev_addr, ETH_ALEN) == 0 &&
2801 s->ssid_len == ssid_len &&
2802 os_memcmp(ssid, s->ssid, ssid_len) == 0)
2807 wpa_printf(MSG_DEBUG, "P2P: Invitation from " MACSTR
2808 " requested reinvocation of an unknown group",
2810 return P2P_SC_FAIL_UNKNOWN_GROUP;
2813 if (s->mode == WPAS_MODE_P2P_GO && !wpas_p2p_create_iface(wpa_s)) {
2815 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2816 wpa_printf(MSG_DEBUG, "P2P: The only available "
2817 "interface is already in use - reject "
2819 return P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE;
2821 os_memcpy(group_bssid, wpa_s->own_addr, ETH_ALEN);
2822 } else if (s->mode == WPAS_MODE_P2P_GO) {
2824 if (wpas_p2p_add_group_interface(wpa_s, WPA_IF_P2P_GO) < 0)
2826 wpa_printf(MSG_ERROR, "P2P: Failed to allocate a new "
2827 "interface address for the group");
2828 return P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE;
2830 os_memcpy(group_bssid, wpa_s->pending_interface_addr,
2835 wpas_p2p_set_own_freq_preference(wpa_s, 0);
2838 freqs = os_calloc(wpa_s->num_multichan_concurrent,
2839 sizeof(struct wpa_used_freq_data));
2841 int num_channels = wpa_s->num_multichan_concurrent;
2842 int num = wpas_p2p_valid_oper_freqs(wpa_s, freqs, num_channels);
2843 best_freq = wpas_p2p_pick_best_used_freq(wpa_s, freqs, num);
2847 /* Get one of the frequencies currently in use */
2848 if (best_freq > 0) {
2849 wpa_printf(MSG_DEBUG, "P2P: Trying to prefer a channel already used by one of the interfaces");
2850 wpas_p2p_set_own_freq_preference(wpa_s, best_freq);
2852 if (wpa_s->num_multichan_concurrent < 2 ||
2853 wpas_p2p_num_unused_channels(wpa_s) < 1) {
2854 wpa_printf(MSG_DEBUG, "P2P: No extra channels available - trying to force channel to match a channel already used by one of the interfaces");
2855 *force_freq = best_freq;
2859 if (*force_freq > 0 && wpa_s->num_multichan_concurrent > 1 &&
2860 wpas_p2p_num_unused_channels(wpa_s) > 0) {
2862 /* We are the client */
2863 wpa_printf(MSG_DEBUG, "P2P: Peer was found to be "
2864 "running a GO but we are capable of MCC, "
2865 "figure out the best channel to use");
2867 } else if (!freq_included(wpa_s, channels, *force_freq)) {
2868 /* We are the GO, and *force_freq is not in the
2870 wpa_printf(MSG_DEBUG, "P2P: Forced GO freq %d MHz not "
2871 "in intersection but we are capable of MCC, "
2872 "figure out the best channel to use",
2878 return P2P_SC_SUCCESS;
2882 static void wpas_invitation_received(void *ctx, const u8 *sa, const u8 *bssid,
2883 const u8 *ssid, size_t ssid_len,
2884 const u8 *go_dev_addr, u8 status,
2887 struct wpa_supplicant *wpa_s = ctx;
2890 for (s = wpa_s->conf->ssid; s; s = s->next) {
2891 if (s->disabled == 2 &&
2892 s->ssid_len == ssid_len &&
2893 os_memcmp(ssid, s->ssid, ssid_len) == 0)
2897 if (status == P2P_SC_SUCCESS) {
2898 wpa_printf(MSG_DEBUG, "P2P: Invitation from peer " MACSTR
2899 " was accepted; op_freq=%d MHz, SSID=%s",
2900 MAC2STR(sa), op_freq, wpa_ssid_txt(ssid, ssid_len));
2902 int go = s->mode == WPAS_MODE_P2P_GO;
2903 wpas_p2p_group_add_persistent(
2904 wpa_s, s, go, 0, op_freq, 0, 0, NULL,
2905 go ? P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE : 0,
2908 wpa_s->user_initiated_pd = 0;
2909 wpas_p2p_join(wpa_s, bssid, go_dev_addr,
2910 wpa_s->p2p_wps_method, 0, op_freq,
2916 if (status != P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE) {
2917 wpa_printf(MSG_DEBUG, "P2P: Invitation from peer " MACSTR
2918 " was rejected (status %u)", MAC2STR(sa), status);
2924 wpa_msg_global(wpa_s, MSG_INFO,
2925 P2P_EVENT_INVITATION_RECEIVED
2926 "sa=" MACSTR " go_dev_addr=" MACSTR
2927 " bssid=" MACSTR " unknown-network",
2928 MAC2STR(sa), MAC2STR(go_dev_addr),
2931 wpa_msg_global(wpa_s, MSG_INFO,
2932 P2P_EVENT_INVITATION_RECEIVED
2933 "sa=" MACSTR " go_dev_addr=" MACSTR
2935 MAC2STR(sa), MAC2STR(go_dev_addr));
2937 wpas_notify_p2p_invitation_received(wpa_s, sa, go_dev_addr,
2942 if (s->mode == WPAS_MODE_P2P_GO && op_freq) {
2943 wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RECEIVED
2944 "sa=" MACSTR " persistent=%d freq=%d",
2945 MAC2STR(sa), s->id, op_freq);
2947 wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RECEIVED
2948 "sa=" MACSTR " persistent=%d",
2949 MAC2STR(sa), s->id);
2951 wpas_notify_p2p_invitation_received(wpa_s, sa, go_dev_addr, bssid,
2956 static void wpas_remove_persistent_peer(struct wpa_supplicant *wpa_s,
2957 struct wpa_ssid *ssid,
2958 const u8 *peer, int inv)
2961 struct wpa_supplicant *p2p_wpa_s = wpa_s->global->p2p_init_wpa_s;
2966 for (i = 0; ssid->p2p_client_list && i < ssid->num_p2p_clients; i++) {
2967 if (os_memcmp(ssid->p2p_client_list + i * 2 * ETH_ALEN, peer,
2971 if (i >= ssid->num_p2p_clients || !ssid->p2p_client_list) {
2972 if (ssid->mode != WPAS_MODE_P2P_GO &&
2973 os_memcmp(ssid->bssid, peer, ETH_ALEN) == 0) {
2974 wpa_printf(MSG_DEBUG, "P2P: Remove persistent group %d "
2975 "due to invitation result", ssid->id);
2976 wpas_notify_network_removed(wpa_s, ssid);
2977 wpa_config_remove_network(wpa_s->conf, ssid->id);
2980 return; /* Peer not found in client list */
2983 wpa_printf(MSG_DEBUG, "P2P: Remove peer " MACSTR " from persistent "
2984 "group %d client list%s",
2985 MAC2STR(peer), ssid->id,
2986 inv ? " due to invitation result" : "");
2987 os_memmove(ssid->p2p_client_list + i * 2 * ETH_ALEN,
2988 ssid->p2p_client_list + (i + 1) * 2 * ETH_ALEN,
2989 (ssid->num_p2p_clients - i - 1) * 2 * ETH_ALEN);
2990 ssid->num_p2p_clients--;
2991 if (p2p_wpa_s->conf->update_config &&
2992 wpa_config_write(p2p_wpa_s->confname, p2p_wpa_s->conf))
2993 wpa_printf(MSG_DEBUG, "P2P: Failed to update configuration");
2997 static void wpas_remove_persistent_client(struct wpa_supplicant *wpa_s,
3000 struct wpa_ssid *ssid;
3002 wpa_s = wpa_s->global->p2p_invite_group;
3004 return; /* No known invitation group */
3005 ssid = wpa_s->current_ssid;
3006 if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO ||
3007 !ssid->p2p_persistent_group)
3008 return; /* Not operating as a GO in persistent group */
3009 ssid = wpas_p2p_get_persistent(wpa_s->parent, peer,
3010 ssid->ssid, ssid->ssid_len);
3011 wpas_remove_persistent_peer(wpa_s, ssid, peer, 1);
3015 static void wpas_invitation_result(void *ctx, int status, const u8 *bssid,
3016 const struct p2p_channels *channels,
3017 const u8 *peer, int neg_freq,
3020 struct wpa_supplicant *wpa_s = ctx;
3021 struct wpa_ssid *ssid;
3025 wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RESULT
3026 "status=%d " MACSTR,
3027 status, MAC2STR(bssid));
3029 wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RESULT
3030 "status=%d ", status);
3032 wpas_notify_p2p_invitation_result(wpa_s, status, bssid);
3034 wpa_printf(MSG_DEBUG, "P2P: Invitation result - status=%d peer=" MACSTR,
3035 status, MAC2STR(peer));
3036 if (wpa_s->pending_invite_ssid_id == -1) {
3037 if (status == P2P_SC_FAIL_UNKNOWN_GROUP)
3038 wpas_remove_persistent_client(wpa_s, peer);
3039 return; /* Invitation to active group */
3042 if (status == P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE) {
3043 wpa_printf(MSG_DEBUG, "P2P: Waiting for peer to start another "
3044 "invitation exchange to indicate readiness for "
3048 if (status != P2P_SC_SUCCESS) {
3049 if (status == P2P_SC_FAIL_UNKNOWN_GROUP) {
3050 ssid = wpa_config_get_network(
3051 wpa_s->conf, wpa_s->pending_invite_ssid_id);
3052 wpas_remove_persistent_peer(wpa_s, ssid, peer, 1);
3054 wpas_p2p_remove_pending_group_interface(wpa_s);
3058 ssid = wpa_config_get_network(wpa_s->conf,
3059 wpa_s->pending_invite_ssid_id);
3061 wpa_printf(MSG_ERROR, "P2P: Could not find persistent group "
3062 "data matching with invitation");
3067 * The peer could have missed our ctrl::ack frame for Invitation
3068 * Response and continue retransmitting the frame. To reduce the
3069 * likelihood of the peer not getting successful TX status for the
3070 * Invitation Response frame, wait a short time here before starting
3071 * the persistent group so that we will remain on the current channel to
3072 * acknowledge any possible retransmission from the peer.
3074 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: 50 ms wait on current channel before "
3075 "starting persistent group");
3078 if (neg_freq > 0 && ssid->mode == WPAS_MODE_P2P_GO &&
3079 freq_included(wpa_s, channels, neg_freq))
3081 else if (peer_oper_freq > 0 && ssid->mode != WPAS_MODE_P2P_GO &&
3082 freq_included(wpa_s, channels, peer_oper_freq))
3083 freq = peer_oper_freq;
3087 wpa_printf(MSG_DEBUG, "P2P: Persistent group invitation success - op_freq=%d MHz SSID=%s",
3088 freq, wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
3089 wpas_p2p_group_add_persistent(wpa_s, ssid,
3090 ssid->mode == WPAS_MODE_P2P_GO,
3091 wpa_s->p2p_persistent_go_freq,
3093 wpa_s->p2p_go_ht40, wpa_s->p2p_go_vht,
3095 ssid->mode == WPAS_MODE_P2P_GO ?
3096 P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE :
3101 static int wpas_p2p_disallowed_freq(struct wpa_global *global,
3104 if (freq_range_list_includes(&global->p2p_go_avoid_freq, freq))
3106 return freq_range_list_includes(&global->p2p_disallow_freq, freq);
3110 static void wpas_p2p_add_chan(struct p2p_reg_class *reg, u8 chan)
3112 reg->channel[reg->channels] = chan;
3117 static int wpas_p2p_default_channels(struct wpa_supplicant *wpa_s,
3118 struct p2p_channels *chan,
3119 struct p2p_channels *cli_chan)
3123 wpa_s->global->p2p_24ghz_social_channels = 1;
3125 os_memset(cli_chan, 0, sizeof(*cli_chan));
3127 wpa_printf(MSG_DEBUG, "P2P: Enable operating classes for 2.4 GHz "
3130 /* Operating class 81 - 2.4 GHz band channels 1..13 */
3131 chan->reg_class[cla].reg_class = 81;
3132 chan->reg_class[cla].channels = 0;
3133 for (i = 0; i < 11; i++) {
3134 if (!wpas_p2p_disallowed_freq(wpa_s->global, 2412 + i * 5))
3135 wpas_p2p_add_chan(&chan->reg_class[cla], i + 1);
3137 if (chan->reg_class[cla].channels)
3140 wpa_printf(MSG_DEBUG, "P2P: Enable operating classes for lower 5 GHz "
3143 /* Operating class 115 - 5 GHz, channels 36-48 */
3144 chan->reg_class[cla].reg_class = 115;
3145 chan->reg_class[cla].channels = 0;
3146 if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 36 * 5))
3147 wpas_p2p_add_chan(&chan->reg_class[cla], 36);
3148 if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 40 * 5))
3149 wpas_p2p_add_chan(&chan->reg_class[cla], 40);
3150 if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 44 * 5))
3151 wpas_p2p_add_chan(&chan->reg_class[cla], 44);
3152 if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 48 * 5))
3153 wpas_p2p_add_chan(&chan->reg_class[cla], 48);
3154 if (chan->reg_class[cla].channels)
3157 wpa_printf(MSG_DEBUG, "P2P: Enable operating classes for higher 5 GHz "
3160 /* Operating class 124 - 5 GHz, channels 149,153,157,161 */
3161 chan->reg_class[cla].reg_class = 124;
3162 chan->reg_class[cla].channels = 0;
3163 if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 149 * 5))
3164 wpas_p2p_add_chan(&chan->reg_class[cla], 149);
3165 if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 153 * 5))
3166 wpas_p2p_add_chan(&chan->reg_class[cla], 153);
3167 if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 156 * 5))
3168 wpas_p2p_add_chan(&chan->reg_class[cla], 157);
3169 if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 161 * 5))
3170 wpas_p2p_add_chan(&chan->reg_class[cla], 161);
3171 if (chan->reg_class[cla].channels)
3174 chan->reg_classes = cla;
3179 static struct hostapd_hw_modes * get_mode(struct hostapd_hw_modes *modes,
3181 enum hostapd_hw_mode mode)
3185 for (i = 0; i < num_modes; i++) {
3186 if (modes[i].mode == mode)
3195 NOT_ALLOWED, NO_IR, ALLOWED
3198 static int has_channel(struct wpa_global *global,
3199 struct hostapd_hw_modes *mode, u8 chan, int *flags)
3204 freq = (mode->mode == HOSTAPD_MODE_IEEE80211A ? 5000 : 2407) +
3206 if (wpas_p2p_disallowed_freq(global, freq))
3209 for (i = 0; i < mode->num_channels; i++) {
3210 if (mode->channels[i].chan == chan) {
3212 *flags = mode->channels[i].flag;
3213 if (mode->channels[i].flag &
3214 (HOSTAPD_CHAN_DISABLED |
3215 HOSTAPD_CHAN_RADAR))
3217 if (mode->channels[i].flag & HOSTAPD_CHAN_NO_IR)
3227 struct p2p_oper_class_map {
3228 enum hostapd_hw_mode mode;
3233 enum { BW20, BW40PLUS, BW40MINUS, BW80, BW2160 } bw;
3236 static const struct p2p_oper_class_map op_class[] = {
3237 { HOSTAPD_MODE_IEEE80211G, 81, 1, 13, 1, BW20 },
3238 #if 0 /* Do not enable HT40 on 2 GHz for now */
3239 { HOSTAPD_MODE_IEEE80211G, 83, 1, 9, 1, BW40PLUS },
3240 { HOSTAPD_MODE_IEEE80211G, 84, 5, 13, 1, BW40MINUS },
3242 { HOSTAPD_MODE_IEEE80211A, 115, 36, 48, 4, BW20 },
3243 { HOSTAPD_MODE_IEEE80211A, 124, 149, 161, 4, BW20 },
3244 { HOSTAPD_MODE_IEEE80211A, 125, 149, 169, 4, BW20 },
3245 { HOSTAPD_MODE_IEEE80211A, 116, 36, 44, 8, BW40PLUS },
3246 { HOSTAPD_MODE_IEEE80211A, 117, 40, 48, 8, BW40MINUS },
3247 { HOSTAPD_MODE_IEEE80211A, 126, 149, 157, 8, BW40PLUS },
3248 { HOSTAPD_MODE_IEEE80211A, 127, 153, 161, 8, BW40MINUS },
3251 * IEEE P802.11ac/D7.0 Table E-4 actually talks about channel center
3252 * frequency index 42, 58, 106, 122, 138, 155 with channel spacing of
3253 * 80 MHz, but currently use the following definition for simplicity
3254 * (these center frequencies are not actual channels, which makes
3255 * has_channel() fail). wpas_p2p_verify_80mhz() should take care of
3256 * removing invalid channels.
3258 { HOSTAPD_MODE_IEEE80211A, 128, 36, 161, 4, BW80 },
3259 { HOSTAPD_MODE_IEEE80211AD, 180, 1, 4, 1, BW2160 },
3260 { -1, 0, 0, 0, 0, BW20 }
3264 static int wpas_p2p_get_center_80mhz(struct wpa_supplicant *wpa_s,
3265 struct hostapd_hw_modes *mode,
3268 u8 center_channels[] = { 42, 58, 106, 122, 138, 155 };
3271 if (mode->mode != HOSTAPD_MODE_IEEE80211A)
3274 for (i = 0; i < ARRAY_SIZE(center_channels); i++)
3276 * In 80 MHz, the bandwidth "spans" 12 channels (e.g., 36-48),
3277 * so the center channel is 6 channels away from the start/end.
3279 if (channel >= center_channels[i] - 6 &&
3280 channel <= center_channels[i] + 6)
3281 return center_channels[i];
3287 static enum chan_allowed wpas_p2p_verify_80mhz(struct wpa_supplicant *wpa_s,
3288 struct hostapd_hw_modes *mode,
3293 enum chan_allowed res, ret = ALLOWED;
3295 center_chan = wpas_p2p_get_center_80mhz(wpa_s, mode, channel);
3298 if (center_chan >= 58 && center_chan <= 138)
3299 return NOT_ALLOWED; /* Do not allow DFS channels for P2P */
3301 /* check all the channels are available */
3302 for (i = 0; i < 4; i++) {
3303 int adj_chan = center_chan - 6 + i * 4;
3305 res = has_channel(wpa_s->global, mode, adj_chan, &flags);
3306 if (res == NOT_ALLOWED)
3311 if (i == 0 && !(flags & HOSTAPD_CHAN_VHT_10_70))
3313 if (i == 1 && !(flags & HOSTAPD_CHAN_VHT_30_50))
3315 if (i == 2 && !(flags & HOSTAPD_CHAN_VHT_50_30))
3317 if (i == 3 && !(flags & HOSTAPD_CHAN_VHT_70_10))
3325 static enum chan_allowed wpas_p2p_verify_channel(struct wpa_supplicant *wpa_s,
3326 struct hostapd_hw_modes *mode,
3330 enum chan_allowed res, res2;
3332 res2 = res = has_channel(wpa_s->global, mode, channel, &flag);
3333 if (bw == BW40MINUS) {
3334 if (!(flag & HOSTAPD_CHAN_HT40MINUS))
3336 res2 = has_channel(wpa_s->global, mode, channel - 4, NULL);
3337 } else if (bw == BW40PLUS) {
3338 if (!(flag & HOSTAPD_CHAN_HT40PLUS))
3340 res2 = has_channel(wpa_s->global, mode, channel + 4, NULL);
3341 } else if (bw == BW80) {
3342 res2 = wpas_p2p_verify_80mhz(wpa_s, mode, channel, bw);
3345 if (res == NOT_ALLOWED || res2 == NOT_ALLOWED)
3347 if (res == NO_IR || res2 == NO_IR)
3353 static int wpas_p2p_setup_channels(struct wpa_supplicant *wpa_s,
3354 struct p2p_channels *chan,
3355 struct p2p_channels *cli_chan)
3357 struct hostapd_hw_modes *mode;
3358 int cla, op, cli_cla;
3360 if (wpa_s->hw.modes == NULL) {
3361 wpa_printf(MSG_DEBUG, "P2P: Driver did not support fetching "
3362 "of all supported channels; assume dualband "
3364 return wpas_p2p_default_channels(wpa_s, chan, cli_chan);
3369 for (op = 0; op_class[op].op_class; op++) {
3370 const struct p2p_oper_class_map *o = &op_class[op];
3372 struct p2p_reg_class *reg = NULL, *cli_reg = NULL;
3374 mode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, o->mode);
3377 if (mode->mode == HOSTAPD_MODE_IEEE80211G)
3378 wpa_s->global->p2p_24ghz_social_channels = 1;
3379 for (ch = o->min_chan; ch <= o->max_chan; ch += o->inc) {
3380 enum chan_allowed res;
3381 res = wpas_p2p_verify_channel(wpa_s, mode, ch, o->bw);
3382 if (res == ALLOWED) {
3384 wpa_printf(MSG_DEBUG, "P2P: Add operating class %u",
3386 reg = &chan->reg_class[cla];
3388 reg->reg_class = o->op_class;
3390 reg->channel[reg->channels] = ch;
3392 } else if (res == NO_IR &&
3393 wpa_s->conf->p2p_add_cli_chan) {
3394 if (cli_reg == NULL) {
3395 wpa_printf(MSG_DEBUG, "P2P: Add operating class %u (client only)",
3397 cli_reg = &cli_chan->reg_class[cli_cla];
3399 cli_reg->reg_class = o->op_class;
3401 cli_reg->channel[cli_reg->channels] = ch;
3402 cli_reg->channels++;
3406 wpa_hexdump(MSG_DEBUG, "P2P: Channels",
3407 reg->channel, reg->channels);
3410 wpa_hexdump(MSG_DEBUG, "P2P: Channels (client only)",
3411 cli_reg->channel, cli_reg->channels);
3415 chan->reg_classes = cla;
3416 cli_chan->reg_classes = cli_cla;
3422 int wpas_p2p_get_ht40_mode(struct wpa_supplicant *wpa_s,
3423 struct hostapd_hw_modes *mode, u8 channel)
3426 enum chan_allowed ret;
3428 for (op = 0; op_class[op].op_class; op++) {
3429 const struct p2p_oper_class_map *o = &op_class[op];
3432 for (ch = o->min_chan; ch <= o->max_chan; ch += o->inc) {
3433 if (o->mode != HOSTAPD_MODE_IEEE80211A ||
3434 (o->bw != BW40PLUS && o->bw != BW40MINUS) ||
3437 ret = wpas_p2p_verify_channel(wpa_s, mode, ch, o->bw);
3439 return (o->bw == BW40MINUS) ? -1 : 1;
3446 int wpas_p2p_get_vht80_center(struct wpa_supplicant *wpa_s,
3447 struct hostapd_hw_modes *mode, u8 channel)
3449 if (!wpas_p2p_verify_channel(wpa_s, mode, channel, BW80))
3452 return wpas_p2p_get_center_80mhz(wpa_s, mode, channel);
3456 static int wpas_get_noa(void *ctx, const u8 *interface_addr, u8 *buf,
3459 struct wpa_supplicant *wpa_s = ctx;
3461 for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) {
3462 if (os_memcmp(wpa_s->own_addr, interface_addr, ETH_ALEN) == 0)
3468 return wpa_drv_get_noa(wpa_s, buf, buf_len);
3472 struct wpa_supplicant * wpas_get_p2p_go_iface(struct wpa_supplicant *wpa_s,
3473 const u8 *ssid, size_t ssid_len)
3475 for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) {
3476 struct wpa_ssid *s = wpa_s->current_ssid;
3479 if (s->mode != WPAS_MODE_P2P_GO &&
3480 s->mode != WPAS_MODE_AP &&
3481 s->mode != WPAS_MODE_P2P_GROUP_FORMATION)
3483 if (s->ssid_len != ssid_len ||
3484 os_memcmp(ssid, s->ssid, ssid_len) != 0)
3494 struct wpa_supplicant * wpas_get_p2p_client_iface(struct wpa_supplicant *wpa_s,
3495 const u8 *peer_dev_addr)
3497 for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) {
3498 struct wpa_ssid *ssid = wpa_s->current_ssid;
3499 if (ssid && (ssid->mode != WPAS_MODE_INFRA || !ssid->p2p_group))
3501 if (os_memcmp(wpa_s->go_dev_addr, peer_dev_addr, ETH_ALEN) == 0)
3509 static int wpas_go_connected(void *ctx, const u8 *dev_addr)
3511 struct wpa_supplicant *wpa_s = ctx;
3513 return wpas_get_p2p_client_iface(wpa_s, dev_addr) != NULL;
3517 static int wpas_is_concurrent_session_active(void *ctx)
3519 struct wpa_supplicant *wpa_s = ctx;
3520 struct wpa_supplicant *ifs;
3522 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
3525 if (ifs->wpa_state > WPA_ASSOCIATED)
3532 static void wpas_p2p_debug_print(void *ctx, int level, const char *msg)
3534 struct wpa_supplicant *wpa_s = ctx;
3535 wpa_msg_global(wpa_s, level, "P2P: %s", msg);
3539 int wpas_p2p_add_p2pdev_interface(struct wpa_supplicant *wpa_s,
3540 const char *conf_p2p_dev)
3542 struct wpa_interface iface;
3543 struct wpa_supplicant *p2pdev_wpa_s;
3545 char force_name[100];
3548 ret = os_snprintf(ifname, sizeof(ifname), P2P_MGMT_DEVICE_PREFIX "%s",
3550 if (os_snprintf_error(sizeof(ifname), ret))
3552 force_name[0] = '\0';
3553 wpa_s->pending_interface_type = WPA_IF_P2P_DEVICE;
3554 ret = wpa_drv_if_add(wpa_s, WPA_IF_P2P_DEVICE, ifname, NULL, NULL,
3555 force_name, wpa_s->pending_interface_addr, NULL);
3557 wpa_printf(MSG_DEBUG, "P2P: Failed to create P2P Device interface");
3560 os_strlcpy(wpa_s->pending_interface_name, ifname,
3561 sizeof(wpa_s->pending_interface_name));
3563 os_memset(&iface, 0, sizeof(iface));
3565 iface.ifname = wpa_s->pending_interface_name;
3566 iface.driver = wpa_s->driver->name;
3567 iface.driver_param = wpa_s->conf->driver_param;
3570 * If a P2P Device configuration file was given, use it as the interface
3571 * configuration file (instead of using parent's configuration file.
3574 iface.confname = conf_p2p_dev;
3575 iface.ctrl_interface = NULL;
3577 iface.confname = wpa_s->confname;
3578 iface.ctrl_interface = wpa_s->conf->ctrl_interface;
3581 p2pdev_wpa_s = wpa_supplicant_add_iface(wpa_s->global, &iface, wpa_s);
3582 if (!p2pdev_wpa_s) {
3583 wpa_printf(MSG_DEBUG, "P2P: Failed to add P2P Device interface");
3587 wpa_s->pending_interface_name[0] = '\0';
3592 static void wpas_presence_resp(void *ctx, const u8 *src, u8 status,
3593 const u8 *noa, size_t noa_len)
3595 struct wpa_supplicant *wpa_s, *intf = ctx;
3598 for (wpa_s = intf->global->ifaces; wpa_s; wpa_s = wpa_s->next) {
3599 if (wpa_s->waiting_presence_resp)
3603 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: No group interface was waiting for presence response");
3606 wpa_s->waiting_presence_resp = 0;
3608 wpa_snprintf_hex(hex, sizeof(hex), noa, noa_len);
3609 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_PRESENCE_RESPONSE "src=" MACSTR
3610 " status=%u noa=%s", MAC2STR(src), status, hex);
3614 static int wpas_get_persistent_group(void *ctx, const u8 *addr, const u8 *ssid,
3615 size_t ssid_len, u8 *go_dev_addr,
3616 u8 *ret_ssid, size_t *ret_ssid_len,
3617 u8 *intended_iface_addr)
3619 struct wpa_supplicant *wpa_s = ctx;
3622 s = wpas_p2p_get_persistent(wpa_s, addr, ssid, ssid_len);
3624 os_memcpy(ret_ssid, s->ssid, s->ssid_len);
3625 *ret_ssid_len = s->ssid_len;
3626 os_memcpy(go_dev_addr, s->bssid, ETH_ALEN);
3628 if (s->mode != WPAS_MODE_P2P_GO) {
3629 os_memset(intended_iface_addr, 0, ETH_ALEN);
3630 } else if (wpas_p2p_create_iface(wpa_s)) {
3631 if (wpas_p2p_add_group_interface(wpa_s, WPA_IF_P2P_GO))
3634 os_memcpy(intended_iface_addr,
3635 wpa_s->pending_interface_addr, ETH_ALEN);
3637 os_memcpy(intended_iface_addr, wpa_s->own_addr,
3647 static int wpas_get_go_info(void *ctx, u8 *intended_addr,
3648 u8 *ssid, size_t *ssid_len, int *group_iface)
3650 struct wpa_supplicant *wpa_s = ctx;
3655 * group_iface will be set to 1 only if a dedicated interface for P2P
3656 * role is required. First, we try to reuse an active GO. However,
3657 * if it is not present, we will try to reactivate an existing
3658 * persistent group and set group_iface to 1, so the caller will know
3659 * that the pending interface should be used.
3662 s = wpas_p2p_group_go_ssid(wpa_s, bssid);
3664 s = wpas_p2p_get_persistent_go(wpa_s);
3665 *group_iface = wpas_p2p_create_iface(wpa_s);
3667 os_memcpy(bssid, s->bssid, ETH_ALEN);
3672 os_memcpy(intended_addr, bssid, ETH_ALEN);
3673 os_memcpy(ssid, s->ssid, s->ssid_len);
3674 *ssid_len = s->ssid_len;
3680 static int wpas_remove_stale_groups(void *ctx, const u8 *peer, const u8 *go,
3681 const u8 *ssid, size_t ssid_len)
3683 struct wpa_supplicant *wpa_s = ctx;
3685 int save_config = 0;
3688 /* Start with our first choice of Persistent Groups */
3689 while ((s = wpas_p2p_get_persistent(wpa_s, peer, NULL, 0))) {
3690 if (go && ssid && ssid_len &&
3691 s->ssid_len == ssid_len &&
3692 os_memcmp(go, s->bssid, ETH_ALEN) == 0 &&
3693 os_memcmp(ssid, s->ssid, ssid_len) == 0)
3696 /* Remove stale persistent group */
3697 if (s->mode != WPAS_MODE_P2P_GO || s->num_p2p_clients <= 1) {
3698 wpa_config_remove_network(wpa_s->conf, s->id);
3703 for (i = 0; i < s->num_p2p_clients; i++) {
3704 if (os_memcmp(s->p2p_client_list + i * 2 * ETH_ALEN,
3705 peer, ETH_ALEN) != 0)
3708 os_memmove(s->p2p_client_list + i * 2 * ETH_ALEN,
3709 s->p2p_client_list + (i + 1) * 2 * ETH_ALEN,
3710 (s->num_p2p_clients - i - 1) * 2 * ETH_ALEN);
3713 s->num_p2p_clients--;
3718 p2p_config_write(wpa_s);
3720 /* Return TRUE if valid SSID remains */
3725 static void wpas_p2ps_get_feat_cap_str(char *buf, size_t buf_len,
3726 const u8 *feat_cap, size_t feat_cap_len)
3728 static const char pref[] = " feature_cap=";
3734 * We expect a feature capability to contain at least one byte to be
3735 * reported. The string buffer provided by the caller function is
3736 * expected to be big enough to contain all bytes of the attribute for
3737 * known specifications. This function truncates the reported bytes if
3738 * the feature capability data exceeds the string buffer size.
3740 if (!feat_cap || !feat_cap_len || buf_len < sizeof(pref) + 2)
3743 os_memcpy(buf, pref, sizeof(pref));
3744 ret = wpa_snprintf_hex(&buf[sizeof(pref) - 1],
3745 buf_len - sizeof(pref) + 1,
3746 feat_cap, feat_cap_len);
3748 if (ret != (2 * (int) feat_cap_len))
3749 wpa_printf(MSG_WARNING, "P2PS feature_cap bytes truncated");
3753 static void wpas_p2ps_prov_complete(void *ctx, u8 status, const u8 *dev,
3754 const u8 *adv_mac, const u8 *ses_mac,
3755 const u8 *grp_mac, u32 adv_id, u32 ses_id,
3756 u8 conncap, int passwd_id,
3757 const u8 *persist_ssid,
3758 size_t persist_ssid_size, int response_done,
3759 int prov_start, const char *session_info,
3760 const u8 *feat_cap, size_t feat_cap_len)
3762 struct wpa_supplicant *wpa_s = ctx;
3764 struct wpa_ssid *persistent_go, *stale, *s;
3765 int save_config = 0;
3766 struct wpa_supplicant *go_wpa_s;
3767 char feat_cap_str[256];
3772 os_memset(mac, 0, ETH_ALEN);
3780 wpas_p2ps_get_feat_cap_str(feat_cap_str, sizeof(feat_cap_str),
3781 feat_cap, feat_cap_len);
3784 if (session_info == NULL) {
3785 wpa_msg_global(wpa_s, MSG_INFO,
3786 P2P_EVENT_P2PS_PROVISION_START MACSTR
3787 " adv_id=%x conncap=%x"
3789 " session=%x mac=" MACSTR
3790 " dev_passwd_id=%d%s",
3791 MAC2STR(dev), adv_id, conncap,
3793 ses_id, MAC2STR(ses_mac),
3794 passwd_id, feat_cap_str);
3796 wpa_msg_global(wpa_s, MSG_INFO,
3797 P2P_EVENT_P2PS_PROVISION_START MACSTR
3798 " adv_id=%x conncap=%x"
3800 " session=%x mac=" MACSTR
3801 " dev_passwd_id=%d info='%s'%s",
3802 MAC2STR(dev), adv_id, conncap,
3804 ses_id, MAC2STR(ses_mac),
3805 passwd_id, session_info, feat_cap_str);
3810 go_wpa_s = wpas_p2p_get_go_group(wpa_s);
3811 persistent_go = wpas_p2p_get_persistent_go(wpa_s);
3813 if (status && status != P2P_SC_SUCCESS_DEFERRED) {
3814 if (go_wpa_s && !p2p_group_go_member_count(wpa_s))
3815 wpas_p2p_group_remove(wpa_s, go_wpa_s->ifname);
3817 if (persistent_go && !persistent_go->num_p2p_clients) {
3818 /* remove empty persistent GO */
3819 wpa_config_remove_network(wpa_s->conf,
3823 wpa_msg_global(wpa_s, MSG_INFO,
3824 P2P_EVENT_P2PS_PROVISION_DONE MACSTR
3826 " adv_id=%x adv_mac=" MACSTR
3827 " session=%x mac=" MACSTR "%s",
3828 MAC2STR(dev), status,
3829 adv_id, MAC2STR(adv_mac),
3830 ses_id, MAC2STR(ses_mac), feat_cap_str);
3834 /* Clean up stale persistent groups with this device */
3835 s = wpas_p2p_get_persistent(wpa_s, dev, persist_ssid,
3838 if (persist_ssid && s && s->mode != WPAS_MODE_P2P_GO &&
3839 is_zero_ether_addr(grp_mac)) {
3840 wpa_dbg(wpa_s, MSG_ERROR,
3841 "P2P: Peer device is a GO in a persistent group, but it did not provide the intended MAC address");
3846 stale = wpas_p2p_get_persistent(wpa_s, dev, NULL, 0);
3850 if (s && s->ssid_len == stale->ssid_len &&
3851 os_memcmp(stale->bssid, s->bssid, ETH_ALEN) == 0 &&
3852 os_memcmp(stale->ssid, s->ssid, s->ssid_len) == 0)
3855 /* Remove stale persistent group */
3856 if (stale->mode != WPAS_MODE_P2P_GO ||
3857 stale->num_p2p_clients <= 1) {
3858 wpa_config_remove_network(wpa_s->conf, stale->id);
3862 for (i = 0; i < stale->num_p2p_clients; i++) {
3863 if (os_memcmp(stale->p2p_client_list +
3865 dev, ETH_ALEN) == 0) {
3866 os_memmove(stale->p2p_client_list +
3868 stale->p2p_client_list +
3870 (stale->num_p2p_clients -
3875 stale->num_p2p_clients--;
3881 p2p_config_write(wpa_s);
3884 if (go_wpa_s && !p2p_group_go_member_count(wpa_s))
3885 wpas_p2p_group_remove(wpa_s, go_wpa_s->ifname);
3887 if (persistent_go && s != persistent_go &&
3888 !persistent_go->num_p2p_clients) {
3889 /* remove empty persistent GO */
3890 wpa_config_remove_network(wpa_s->conf,
3895 wpa_msg_global(wpa_s, MSG_INFO,
3896 P2P_EVENT_P2PS_PROVISION_DONE MACSTR
3898 " adv_id=%x adv_mac=" MACSTR
3899 " session=%x mac=" MACSTR
3901 MAC2STR(dev), status,
3902 adv_id, MAC2STR(adv_mac),
3903 ses_id, MAC2STR(ses_mac), s->id, feat_cap_str);
3907 if (conncap == P2PS_SETUP_GROUP_OWNER) {
3909 * We need to copy the interface name. Simply saving a
3910 * pointer isn't enough, since if we use pending_interface_name
3911 * it will be overwritten when the group is added.
3913 char go_ifname[100];
3915 go_ifname[0] = '\0';
3917 wpa_s->global->pending_p2ps_group = 1;
3919 if (!wpas_p2p_create_iface(wpa_s))
3920 os_memcpy(go_ifname, wpa_s->ifname,
3922 else if (wpa_s->pending_interface_name[0])
3923 os_memcpy(go_ifname,
3924 wpa_s->pending_interface_name,
3927 if (!go_ifname[0]) {
3928 wpas_p2ps_prov_complete(
3929 wpa_s, P2P_SC_FAIL_UNKNOWN_GROUP,
3930 dev, adv_mac, ses_mac,
3931 grp_mac, adv_id, ses_id, 0, 0,
3932 NULL, 0, 0, 0, NULL, NULL, 0);
3936 /* If PD Resp complete, start up the GO */
3937 if (response_done && persistent_go) {
3938 wpas_p2p_group_add_persistent(
3939 wpa_s, persistent_go,
3940 0, 0, 0, 0, 0, NULL,
3941 persistent_go->mode ==
3943 P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE :
3945 } else if (response_done) {
3946 wpas_p2p_group_add(wpa_s, 1, 0, 0, 0);
3949 if (passwd_id == DEV_PW_P2PS_DEFAULT) {
3950 os_memcpy(wpa_s->p2ps_join_addr, grp_mac,
3952 wpa_s->p2ps_method_config_any = 1;
3954 } else if (passwd_id == DEV_PW_P2PS_DEFAULT) {
3955 os_memcpy(go_ifname, go_wpa_s->ifname,
3958 if (is_zero_ether_addr(grp_mac)) {
3959 wpa_dbg(go_wpa_s, MSG_DEBUG,
3960 "P2P: Setting PIN-1 for ANY");
3961 wpa_supplicant_ap_wps_pin(go_wpa_s, NULL,
3962 "12345670", NULL, 0,
3965 wpa_dbg(go_wpa_s, MSG_DEBUG,
3966 "P2P: Setting PIN-1 for " MACSTR,
3968 wpa_supplicant_ap_wps_pin(go_wpa_s, grp_mac,
3969 "12345670", NULL, 0,
3973 os_memcpy(wpa_s->p2ps_join_addr, grp_mac, ETH_ALEN);
3974 wpa_s->p2ps_method_config_any = 1;
3977 wpa_msg_global(wpa_s, MSG_INFO,
3978 P2P_EVENT_P2PS_PROVISION_DONE MACSTR
3979 " status=%d conncap=%x"
3980 " adv_id=%x adv_mac=" MACSTR
3981 " session=%x mac=" MACSTR
3982 " dev_passwd_id=%d go=%s%s",
3983 MAC2STR(dev), status, conncap,
3984 adv_id, MAC2STR(adv_mac),
3985 ses_id, MAC2STR(ses_mac),
3986 passwd_id, go_ifname, feat_cap_str);
3990 if (go_wpa_s && !p2p_group_go_member_count(wpa_s))
3991 wpas_p2p_group_remove(wpa_s, go_wpa_s->ifname);
3993 if (persistent_go && !persistent_go->num_p2p_clients) {
3994 /* remove empty persistent GO */
3995 wpa_config_remove_network(wpa_s->conf, persistent_go->id);
3998 if (conncap == P2PS_SETUP_CLIENT) {
3999 wpa_msg_global(wpa_s, MSG_INFO,
4000 P2P_EVENT_P2PS_PROVISION_DONE MACSTR
4001 " status=%d conncap=%x"
4002 " adv_id=%x adv_mac=" MACSTR
4003 " session=%x mac=" MACSTR
4004 " dev_passwd_id=%d join=" MACSTR "%s",
4005 MAC2STR(dev), status, conncap,
4006 adv_id, MAC2STR(adv_mac),
4007 ses_id, MAC2STR(ses_mac),
4008 passwd_id, MAC2STR(grp_mac), feat_cap_str);
4010 wpa_msg_global(wpa_s, MSG_INFO,
4011 P2P_EVENT_P2PS_PROVISION_DONE MACSTR
4012 " status=%d conncap=%x"
4013 " adv_id=%x adv_mac=" MACSTR
4014 " session=%x mac=" MACSTR
4015 " dev_passwd_id=%d%s",
4016 MAC2STR(dev), status, conncap,
4017 adv_id, MAC2STR(adv_mac),
4018 ses_id, MAC2STR(ses_mac),
4019 passwd_id, feat_cap_str);
4024 static int _wpas_p2p_in_progress(void *ctx)
4026 struct wpa_supplicant *wpa_s = ctx;
4027 return wpas_p2p_in_progress(wpa_s);
4031 static int wpas_prov_disc_resp_cb(void *ctx)
4033 struct wpa_supplicant *wpa_s = ctx;
4034 struct wpa_ssid *persistent_go;
4036 if (!wpa_s->global->pending_p2ps_group)
4039 wpa_s->global->pending_p2ps_group = 0;
4041 if (wpas_p2p_get_go_group(wpa_s))
4043 persistent_go = wpas_p2p_get_persistent_go(wpa_s);
4045 if (persistent_go) {
4046 wpas_p2p_group_add_persistent(
4047 wpa_s, persistent_go, 0, 0, 0, 0, 0, NULL,
4048 persistent_go->mode == WPAS_MODE_P2P_GO ?
4049 P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE : 0, 0);
4051 wpas_p2p_group_add(wpa_s, 1, 0, 0, 0);
4058 static int wpas_p2p_get_pref_freq_list(void *ctx, int go,
4060 unsigned int *freq_list)
4062 struct wpa_supplicant *wpa_s = ctx;
4064 return wpa_drv_get_pref_freq_list(wpa_s, go ? WPA_IF_P2P_GO :
4065 WPA_IF_P2P_CLIENT, len, freq_list);
4070 * wpas_p2p_init - Initialize P2P module for %wpa_supplicant
4071 * @global: Pointer to global data from wpa_supplicant_init()
4072 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
4073 * Returns: 0 on success, -1 on failure
4075 int wpas_p2p_init(struct wpa_global *global, struct wpa_supplicant *wpa_s)
4077 struct p2p_config p2p;
4080 if (wpa_s->conf->p2p_disabled)
4083 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_CAPABLE))
4089 os_memset(&p2p, 0, sizeof(p2p));
4091 p2p.debug_print = wpas_p2p_debug_print;
4092 p2p.p2p_scan = wpas_p2p_scan;
4093 p2p.send_action = wpas_send_action;
4094 p2p.send_action_done = wpas_send_action_done;
4095 p2p.go_neg_completed = wpas_go_neg_completed;
4096 p2p.go_neg_req_rx = wpas_go_neg_req_rx;
4097 p2p.dev_found = wpas_dev_found;
4098 p2p.dev_lost = wpas_dev_lost;
4099 p2p.find_stopped = wpas_find_stopped;
4100 p2p.start_listen = wpas_start_listen;
4101 p2p.stop_listen = wpas_stop_listen;
4102 p2p.send_probe_resp = wpas_send_probe_resp;
4103 p2p.sd_request = wpas_sd_request;
4104 p2p.sd_response = wpas_sd_response;
4105 p2p.prov_disc_req = wpas_prov_disc_req;
4106 p2p.prov_disc_resp = wpas_prov_disc_resp;
4107 p2p.prov_disc_fail = wpas_prov_disc_fail;
4108 p2p.invitation_process = wpas_invitation_process;
4109 p2p.invitation_received = wpas_invitation_received;
4110 p2p.invitation_result = wpas_invitation_result;
4111 p2p.get_noa = wpas_get_noa;
4112 p2p.go_connected = wpas_go_connected;
4113 p2p.presence_resp = wpas_presence_resp;
4114 p2p.is_concurrent_session_active = wpas_is_concurrent_session_active;
4115 p2p.is_p2p_in_progress = _wpas_p2p_in_progress;
4116 p2p.get_persistent_group = wpas_get_persistent_group;
4117 p2p.get_go_info = wpas_get_go_info;
4118 p2p.remove_stale_groups = wpas_remove_stale_groups;
4119 p2p.p2ps_prov_complete = wpas_p2ps_prov_complete;
4120 p2p.prov_disc_resp_cb = wpas_prov_disc_resp_cb;
4121 p2p.p2ps_group_capability = p2ps_group_capability;
4122 p2p.get_pref_freq_list = wpas_p2p_get_pref_freq_list;
4124 os_memcpy(wpa_s->global->p2p_dev_addr, wpa_s->own_addr, ETH_ALEN);
4125 os_memcpy(p2p.dev_addr, wpa_s->global->p2p_dev_addr, ETH_ALEN);
4126 p2p.dev_name = wpa_s->conf->device_name;
4127 p2p.manufacturer = wpa_s->conf->manufacturer;
4128 p2p.model_name = wpa_s->conf->model_name;
4129 p2p.model_number = wpa_s->conf->model_number;
4130 p2p.serial_number = wpa_s->conf->serial_number;
4132 os_memcpy(p2p.uuid, wpa_s->wps->uuid, 16);
4133 p2p.config_methods = wpa_s->wps->config_methods;
4136 if (wpas_p2p_setup_channels(wpa_s, &p2p.channels, &p2p.cli_channels)) {
4137 wpa_printf(MSG_ERROR,
4138 "P2P: Failed to configure supported channel list");
4142 if (wpa_s->conf->p2p_listen_reg_class &&
4143 wpa_s->conf->p2p_listen_channel) {
4144 p2p.reg_class = wpa_s->conf->p2p_listen_reg_class;
4145 p2p.channel = wpa_s->conf->p2p_listen_channel;
4146 p2p.channel_forced = 1;
4149 * Pick one of the social channels randomly as the listen
4152 if (p2p_config_get_random_social(&p2p, &p2p.reg_class,
4153 &p2p.channel) != 0) {
4154 wpa_printf(MSG_INFO,
4155 "P2P: No social channels supported by the driver - do not enable P2P");
4158 p2p.channel_forced = 0;
4160 wpa_printf(MSG_DEBUG, "P2P: Own listen channel: %d:%d",
4161 p2p.reg_class, p2p.channel);
4163 if (wpa_s->conf->p2p_oper_reg_class &&
4164 wpa_s->conf->p2p_oper_channel) {
4165 p2p.op_reg_class = wpa_s->conf->p2p_oper_reg_class;
4166 p2p.op_channel = wpa_s->conf->p2p_oper_channel;
4167 p2p.cfg_op_channel = 1;
4168 wpa_printf(MSG_DEBUG, "P2P: Configured operating channel: "
4169 "%d:%d", p2p.op_reg_class, p2p.op_channel);
4173 * Use random operation channel from 2.4 GHz band social
4174 * channels (1, 6, 11) or band 60 GHz social channel (2) if no
4175 * other preference is indicated.
4177 if (p2p_config_get_random_social(&p2p, &p2p.op_reg_class,
4178 &p2p.op_channel) != 0) {
4179 wpa_printf(MSG_ERROR,
4180 "P2P: Failed to select random social channel as operation channel");
4183 p2p.cfg_op_channel = 0;
4184 wpa_printf(MSG_DEBUG, "P2P: Random operating channel: "
4185 "%d:%d", p2p.op_reg_class, p2p.op_channel);
4188 if (wpa_s->conf->p2p_pref_chan && wpa_s->conf->num_p2p_pref_chan) {
4189 p2p.pref_chan = wpa_s->conf->p2p_pref_chan;
4190 p2p.num_pref_chan = wpa_s->conf->num_p2p_pref_chan;
4193 if (wpa_s->conf->country[0] && wpa_s->conf->country[1]) {
4194 os_memcpy(p2p.country, wpa_s->conf->country, 2);
4195 p2p.country[2] = 0x04;
4197 os_memcpy(p2p.country, "XX\x04", 3);
4199 os_memcpy(p2p.pri_dev_type, wpa_s->conf->device_type,
4202 p2p.num_sec_dev_types = wpa_s->conf->num_sec_device_types;
4203 os_memcpy(p2p.sec_dev_type, wpa_s->conf->sec_device_type,
4204 p2p.num_sec_dev_types * WPS_DEV_TYPE_LEN);
4206 p2p.concurrent_operations = !!(wpa_s->drv_flags &
4207 WPA_DRIVER_FLAGS_P2P_CONCURRENT);
4209 p2p.max_peers = 100;
4211 if (wpa_s->conf->p2p_ssid_postfix) {
4212 p2p.ssid_postfix_len =
4213 os_strlen(wpa_s->conf->p2p_ssid_postfix);
4214 if (p2p.ssid_postfix_len > sizeof(p2p.ssid_postfix))
4215 p2p.ssid_postfix_len = sizeof(p2p.ssid_postfix);
4216 os_memcpy(p2p.ssid_postfix, wpa_s->conf->p2p_ssid_postfix,
4217 p2p.ssid_postfix_len);
4220 p2p.p2p_intra_bss = wpa_s->conf->p2p_intra_bss;
4222 p2p.max_listen = wpa_s->max_remain_on_chan;
4224 if (wpa_s->conf->p2p_passphrase_len >= 8 &&
4225 wpa_s->conf->p2p_passphrase_len <= 63)
4226 p2p.passphrase_len = wpa_s->conf->p2p_passphrase_len;
4228 p2p.passphrase_len = 8;
4230 global->p2p = p2p_init(&p2p);
4231 if (global->p2p == NULL)
4233 global->p2p_init_wpa_s = wpa_s;
4235 for (i = 0; i < MAX_WPS_VENDOR_EXT; i++) {
4236 if (wpa_s->conf->wps_vendor_ext[i] == NULL)
4238 p2p_add_wps_vendor_extension(
4239 global->p2p, wpa_s->conf->wps_vendor_ext[i]);
4242 p2p_set_no_go_freq(global->p2p, &wpa_s->conf->p2p_no_go_freq);
4249 * wpas_p2p_deinit - Deinitialize per-interface P2P data
4250 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
4252 * This function deinitialize per-interface P2P data.
4254 void wpas_p2p_deinit(struct wpa_supplicant *wpa_s)
4256 if (wpa_s->driver && wpa_s->drv_priv)
4257 wpa_drv_probe_req_report(wpa_s, 0);
4259 if (wpa_s->go_params) {
4260 /* Clear any stored provisioning info */
4261 p2p_clear_provisioning_info(
4263 wpa_s->go_params->peer_device_addr);
4266 os_free(wpa_s->go_params);
4267 wpa_s->go_params = NULL;
4268 eloop_cancel_timeout(wpas_p2p_psk_failure_removal, wpa_s, NULL);
4269 eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s, NULL);
4270 eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL);
4271 wpa_s->p2p_long_listen = 0;
4272 eloop_cancel_timeout(wpas_p2p_long_listen_timeout, wpa_s, NULL);
4273 eloop_cancel_timeout(wpas_p2p_group_idle_timeout, wpa_s, NULL);
4274 wpas_p2p_remove_pending_group_interface(wpa_s);
4275 eloop_cancel_timeout(wpas_p2p_group_freq_conflict, wpa_s, NULL);
4276 wpas_p2p_listen_work_done(wpa_s);
4277 if (wpa_s->p2p_send_action_work) {
4278 os_free(wpa_s->p2p_send_action_work->ctx);
4279 radio_work_done(wpa_s->p2p_send_action_work);
4280 wpa_s->p2p_send_action_work = NULL;
4282 eloop_cancel_timeout(wpas_p2p_send_action_work_timeout, wpa_s, NULL);
4284 wpabuf_free(wpa_s->p2p_oob_dev_pw);
4285 wpa_s->p2p_oob_dev_pw = NULL;
4287 os_free(wpa_s->p2p_group_common_freqs);
4288 wpa_s->p2p_group_common_freqs = NULL;
4289 wpa_s->p2p_group_common_freqs_num = 0;
4291 /* TODO: remove group interface from the driver if this wpa_s instance
4292 * is on top of a P2P group interface */
4297 * wpas_p2p_deinit_global - Deinitialize global P2P module
4298 * @global: Pointer to global data from wpa_supplicant_init()
4300 * This function deinitializes the global (per device) P2P module.
4302 static void wpas_p2p_deinit_global(struct wpa_global *global)
4304 struct wpa_supplicant *wpa_s, *tmp;
4306 wpa_s = global->ifaces;
4308 wpas_p2p_service_flush(global->p2p_init_wpa_s);
4310 /* Remove remaining P2P group interfaces */
4311 while (wpa_s && wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE)
4312 wpa_s = wpa_s->next;
4314 tmp = global->ifaces;
4317 tmp->p2p_group_interface == NOT_P2P_GROUP_INTERFACE)) {
4322 /* Disconnect from the P2P group and deinit the interface */
4323 wpas_p2p_disconnect(tmp);
4327 * Deinit GO data on any possibly remaining interface (if main
4328 * interface is used as GO).
4330 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
4331 if (wpa_s->ap_iface)
4332 wpas_p2p_group_deinit(wpa_s);
4335 p2p_deinit(global->p2p);
4337 global->p2p_init_wpa_s = NULL;
4341 static int wpas_p2p_create_iface(struct wpa_supplicant *wpa_s)
4343 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
4344 wpa_s->conf->p2p_no_group_iface)
4345 return 0; /* separate interface disabled per configuration */
4346 if (wpa_s->drv_flags &
4347 (WPA_DRIVER_FLAGS_P2P_DEDICATED_INTERFACE |
4348 WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P))
4349 return 1; /* P2P group requires a new interface in every case
4351 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_CONCURRENT))
4352 return 0; /* driver does not support concurrent operations */
4353 if (wpa_s->global->ifaces->next)
4354 return 1; /* more that one interface already in use */
4355 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
4356 return 1; /* this interface is already in use */
4361 static int wpas_p2p_start_go_neg(struct wpa_supplicant *wpa_s,
4362 const u8 *peer_addr,
4363 enum p2p_wps_method wps_method,
4364 int go_intent, const u8 *own_interface_addr,
4365 unsigned int force_freq, int persistent_group,
4366 struct wpa_ssid *ssid, unsigned int pref_freq)
4368 if (persistent_group && wpa_s->conf->persistent_reconnect)
4369 persistent_group = 2;
4372 * Increase GO config timeout if HT40 is used since it takes some time
4373 * to scan channels for coex purposes before the BSS can be started.
4375 p2p_set_config_timeout(wpa_s->global->p2p,
4376 wpa_s->p2p_go_ht40 ? 255 : 100, 20);
4378 return p2p_connect(wpa_s->global->p2p, peer_addr, wps_method,
4379 go_intent, own_interface_addr, force_freq,
4380 persistent_group, ssid ? ssid->ssid : NULL,
4381 ssid ? ssid->ssid_len : 0,
4382 wpa_s->p2p_pd_before_go_neg, pref_freq,
4383 wps_method == WPS_NFC ? wpa_s->p2p_oob_dev_pw_id :
4388 static int wpas_p2p_auth_go_neg(struct wpa_supplicant *wpa_s,
4389 const u8 *peer_addr,
4390 enum p2p_wps_method wps_method,
4391 int go_intent, const u8 *own_interface_addr,
4392 unsigned int force_freq, int persistent_group,
4393 struct wpa_ssid *ssid, unsigned int pref_freq)
4395 if (persistent_group && wpa_s->conf->persistent_reconnect)
4396 persistent_group = 2;
4398 return p2p_authorize(wpa_s->global->p2p, peer_addr, wps_method,
4399 go_intent, own_interface_addr, force_freq,
4400 persistent_group, ssid ? ssid->ssid : NULL,
4401 ssid ? ssid->ssid_len : 0, pref_freq,
4402 wps_method == WPS_NFC ? wpa_s->p2p_oob_dev_pw_id :
4407 static void wpas_p2p_check_join_scan_limit(struct wpa_supplicant *wpa_s)
4409 wpa_s->p2p_join_scan_count++;
4410 wpa_printf(MSG_DEBUG, "P2P: Join scan attempt %d",
4411 wpa_s->p2p_join_scan_count);
4412 if (wpa_s->p2p_join_scan_count > P2P_MAX_JOIN_SCAN_ATTEMPTS) {
4413 wpa_printf(MSG_DEBUG, "P2P: Failed to find GO " MACSTR
4414 " for join operationg - stop join attempt",
4415 MAC2STR(wpa_s->pending_join_iface_addr));
4416 eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL);
4417 if (wpa_s->p2p_auto_pd) {
4418 wpa_s->p2p_auto_pd = 0;
4419 wpa_msg_global(wpa_s, MSG_INFO,
4420 P2P_EVENT_PROV_DISC_FAILURE
4421 " p2p_dev_addr=" MACSTR " status=N/A",
4422 MAC2STR(wpa_s->pending_join_dev_addr));
4425 wpa_msg_global(wpa_s->parent, MSG_INFO,
4426 P2P_EVENT_GROUP_FORMATION_FAILURE);
4427 wpas_notify_p2p_group_formation_failure(wpa_s, "");
4432 static int wpas_check_freq_conflict(struct wpa_supplicant *wpa_s, int freq)
4435 unsigned int num, i;
4436 struct wpa_used_freq_data *freqs;
4438 if (wpas_p2p_num_unused_channels(wpa_s) > 0) {
4439 /* Multiple channels are supported and not all are in use */
4443 freqs = os_calloc(wpa_s->num_multichan_concurrent,
4444 sizeof(struct wpa_used_freq_data));
4448 num = wpas_p2p_valid_oper_freqs(wpa_s, freqs,
4449 wpa_s->num_multichan_concurrent);
4451 for (i = 0; i < num; i++) {
4452 if (freqs[i].freq == freq) {
4453 wpa_printf(MSG_DEBUG, "P2P: Frequency %d MHz in use by another virtual interface and can be used",
4460 wpa_printf(MSG_DEBUG, "P2P: No valid operating frequencies");
4469 static int wpas_p2p_peer_go(struct wpa_supplicant *wpa_s,
4470 const u8 *peer_dev_addr)
4472 struct wpa_bss *bss;
4475 bss = wpa_bss_get_p2p_dev_addr(wpa_s, peer_dev_addr);
4478 if (bss->last_update_idx < wpa_s->bss_update_idx) {
4479 wpa_printf(MSG_DEBUG, "P2P: Peer BSS entry not updated in the "
4484 updated = os_reltime_before(&wpa_s->p2p_auto_started,
4486 wpa_printf(MSG_DEBUG, "P2P: Current BSS entry for peer updated at "
4487 "%ld.%06ld (%supdated in last scan)",
4488 bss->last_update.sec, bss->last_update.usec,
4489 updated ? "": "not ");
4495 static void wpas_p2p_scan_res_join(struct wpa_supplicant *wpa_s,
4496 struct wpa_scan_results *scan_res)
4498 struct wpa_bss *bss = NULL;
4500 u8 iface_addr[ETH_ALEN];
4502 eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL);
4504 if (wpa_s->global->p2p_disabled)
4507 wpa_printf(MSG_DEBUG, "P2P: Scan results received (%d BSS) for %sjoin",
4508 scan_res ? (int) scan_res->num : -1,
4509 wpa_s->p2p_auto_join ? "auto_" : "");
4512 wpas_p2p_scan_res_handler(wpa_s, scan_res);
4514 if (wpa_s->p2p_auto_pd) {
4515 int join = wpas_p2p_peer_go(wpa_s,
4516 wpa_s->pending_join_dev_addr);
4518 wpa_s->auto_pd_scan_retry < P2P_AUTO_PD_SCAN_ATTEMPTS) {
4519 wpa_s->auto_pd_scan_retry++;
4520 bss = wpa_bss_get_bssid_latest(
4521 wpa_s, wpa_s->pending_join_dev_addr);
4524 wpa_printf(MSG_DEBUG, "P2P: Scan retry %d for "
4525 "the peer " MACSTR " at %d MHz",
4526 wpa_s->auto_pd_scan_retry,
4528 pending_join_dev_addr),
4530 wpas_p2p_join_scan_req(wpa_s, freq, NULL, 0);
4538 wpa_s->p2p_auto_pd = 0;
4539 wpa_s->pending_pd_use = join ? AUTO_PD_JOIN : AUTO_PD_GO_NEG;
4540 wpa_printf(MSG_DEBUG, "P2P: Auto PD with " MACSTR " join=%d",
4541 MAC2STR(wpa_s->pending_join_dev_addr), join);
4542 if (p2p_prov_disc_req(wpa_s->global->p2p,
4543 wpa_s->pending_join_dev_addr, NULL,
4544 wpa_s->pending_pd_config_methods, join,
4545 0, wpa_s->user_initiated_pd) < 0) {
4546 wpa_s->p2p_auto_pd = 0;
4547 wpa_msg_global(wpa_s, MSG_INFO,
4548 P2P_EVENT_PROV_DISC_FAILURE
4549 " p2p_dev_addr=" MACSTR " status=N/A",
4550 MAC2STR(wpa_s->pending_join_dev_addr));
4555 if (wpa_s->p2p_auto_join) {
4556 int join = wpas_p2p_peer_go(wpa_s,
4557 wpa_s->pending_join_dev_addr);
4559 wpa_printf(MSG_DEBUG, "P2P: Peer was not found to be "
4560 "running a GO -> use GO Negotiation");
4561 wpa_msg_global(wpa_s->parent, MSG_INFO,
4562 P2P_EVENT_FALLBACK_TO_GO_NEG
4563 "reason=peer-not-running-GO");
4564 wpas_p2p_connect(wpa_s, wpa_s->pending_join_dev_addr,
4565 wpa_s->p2p_pin, wpa_s->p2p_wps_method,
4566 wpa_s->p2p_persistent_group, 0, 0, 0,
4567 wpa_s->p2p_go_intent,
4568 wpa_s->p2p_connect_freq,
4569 wpa_s->p2p_persistent_id,
4570 wpa_s->p2p_pd_before_go_neg,
4576 wpa_printf(MSG_DEBUG, "P2P: Peer was found running GO%s -> "
4577 "try to join the group", join ? "" :
4580 wpa_msg_global(wpa_s->parent, MSG_INFO,
4581 P2P_EVENT_FALLBACK_TO_GO_NEG_ENABLED);
4582 wpa_s->p2p_fallback_to_go_neg = 1;
4586 freq = p2p_get_oper_freq(wpa_s->global->p2p,
4587 wpa_s->pending_join_iface_addr);
4589 p2p_get_interface_addr(wpa_s->global->p2p,
4590 wpa_s->pending_join_dev_addr,
4592 os_memcmp(iface_addr, wpa_s->pending_join_dev_addr, ETH_ALEN) != 0
4593 && !wpa_bss_get_bssid(wpa_s, wpa_s->pending_join_iface_addr)) {
4594 wpa_printf(MSG_DEBUG, "P2P: Overwrite pending interface "
4595 "address for join from " MACSTR " to " MACSTR
4596 " based on newly discovered P2P peer entry",
4597 MAC2STR(wpa_s->pending_join_iface_addr),
4598 MAC2STR(iface_addr));
4599 os_memcpy(wpa_s->pending_join_iface_addr, iface_addr,
4602 freq = p2p_get_oper_freq(wpa_s->global->p2p,
4603 wpa_s->pending_join_iface_addr);
4606 wpa_printf(MSG_DEBUG, "P2P: Target GO operating frequency "
4607 "from P2P peer table: %d MHz", freq);
4609 if (wpa_s->p2p_join_ssid_len) {
4610 wpa_printf(MSG_DEBUG, "P2P: Trying to find target GO BSS entry based on BSSID "
4611 MACSTR " and SSID %s",
4612 MAC2STR(wpa_s->pending_join_iface_addr),
4613 wpa_ssid_txt(wpa_s->p2p_join_ssid,
4614 wpa_s->p2p_join_ssid_len));
4615 bss = wpa_bss_get(wpa_s, wpa_s->pending_join_iface_addr,
4616 wpa_s->p2p_join_ssid,
4617 wpa_s->p2p_join_ssid_len);
4620 wpa_printf(MSG_DEBUG, "P2P: Trying to find target GO BSS entry based on BSSID "
4621 MACSTR, MAC2STR(wpa_s->pending_join_iface_addr));
4622 bss = wpa_bss_get_bssid_latest(wpa_s,
4623 wpa_s->pending_join_iface_addr);
4626 u8 dev_addr[ETH_ALEN];
4629 wpa_printf(MSG_DEBUG, "P2P: Target GO operating frequency "
4630 "from BSS table: %d MHz (SSID %s)", freq,
4631 wpa_ssid_txt(bss->ssid, bss->ssid_len));
4632 if (p2p_parse_dev_addr((const u8 *) (bss + 1), bss->ie_len,
4634 os_memcmp(wpa_s->pending_join_dev_addr,
4635 wpa_s->pending_join_iface_addr, ETH_ALEN) == 0 &&
4636 os_memcmp(dev_addr, wpa_s->pending_join_dev_addr,
4638 wpa_printf(MSG_DEBUG,
4639 "P2P: Update target GO device address based on BSS entry: " MACSTR " (was " MACSTR ")",
4641 MAC2STR(wpa_s->pending_join_dev_addr));
4642 os_memcpy(wpa_s->pending_join_dev_addr, dev_addr,
4649 if (wpas_check_freq_conflict(wpa_s, freq) > 0) {
4650 wpa_msg_global(wpa_s->parent, MSG_INFO,
4651 P2P_EVENT_GROUP_FORMATION_FAILURE
4652 "reason=FREQ_CONFLICT");
4653 wpas_notify_p2p_group_formation_failure(
4654 wpa_s, "FREQ_CONFLICT");
4658 wpa_printf(MSG_DEBUG, "P2P: Send Provision Discovery Request "
4659 "prior to joining an existing group (GO " MACSTR
4661 MAC2STR(wpa_s->pending_join_dev_addr), freq);
4662 wpa_s->pending_pd_before_join = 1;
4664 switch (wpa_s->pending_join_wps_method) {
4665 case WPS_PIN_DISPLAY:
4666 method = WPS_CONFIG_KEYPAD;
4668 case WPS_PIN_KEYPAD:
4669 method = WPS_CONFIG_DISPLAY;
4672 method = WPS_CONFIG_PUSHBUTTON;
4675 method = WPS_CONFIG_P2PS;
4682 if ((p2p_get_provisioning_info(wpa_s->global->p2p,
4683 wpa_s->pending_join_dev_addr) ==
4686 * We have already performed provision discovery for
4687 * joining the group. Proceed directly to join
4688 * operation without duplicated provision discovery. */
4689 wpa_printf(MSG_DEBUG, "P2P: Provision discovery "
4690 "with " MACSTR " already done - proceed to "
4692 MAC2STR(wpa_s->pending_join_dev_addr));
4693 wpa_s->pending_pd_before_join = 0;
4697 if (p2p_prov_disc_req(wpa_s->global->p2p,
4698 wpa_s->pending_join_dev_addr,
4700 freq, wpa_s->user_initiated_pd) < 0) {
4701 wpa_printf(MSG_DEBUG, "P2P: Failed to send Provision "
4702 "Discovery Request before joining an "
4704 wpa_s->pending_pd_before_join = 0;
4710 wpa_printf(MSG_DEBUG, "P2P: Failed to find BSS/GO - try again later");
4711 eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL);
4712 eloop_register_timeout(1, 0, wpas_p2p_join_scan, wpa_s, NULL);
4713 wpas_p2p_check_join_scan_limit(wpa_s);
4717 /* Start join operation immediately */
4718 wpas_p2p_join_start(wpa_s, 0, NULL, 0);
4722 static void wpas_p2p_join_scan_req(struct wpa_supplicant *wpa_s, int freq,
4723 const u8 *ssid, size_t ssid_len)
4726 struct wpa_driver_scan_params params;
4727 struct wpabuf *wps_ie, *ies;
4729 int freqs[2] = { 0, 0 };
4731 os_memset(¶ms, 0, sizeof(params));
4733 /* P2P Wildcard SSID */
4734 params.num_ssids = 1;
4735 if (ssid && ssid_len) {
4736 params.ssids[0].ssid = ssid;
4737 params.ssids[0].ssid_len = ssid_len;
4738 os_memcpy(wpa_s->p2p_join_ssid, ssid, ssid_len);
4739 wpa_s->p2p_join_ssid_len = ssid_len;
4741 params.ssids[0].ssid = (u8 *) P2P_WILDCARD_SSID;
4742 params.ssids[0].ssid_len = P2P_WILDCARD_SSID_LEN;
4743 wpa_s->p2p_join_ssid_len = 0;
4746 wpa_s->wps->dev.p2p = 1;
4747 wps_ie = wps_build_probe_req_ie(DEV_PW_DEFAULT, &wpa_s->wps->dev,
4748 wpa_s->wps->uuid, WPS_REQ_ENROLLEE, 0,
4750 if (wps_ie == NULL) {
4751 wpas_p2p_scan_res_join(wpa_s, NULL);
4755 ielen = p2p_scan_ie_buf_len(wpa_s->global->p2p);
4756 ies = wpabuf_alloc(wpabuf_len(wps_ie) + ielen);
4758 wpabuf_free(wps_ie);
4759 wpas_p2p_scan_res_join(wpa_s, NULL);
4762 wpabuf_put_buf(ies, wps_ie);
4763 wpabuf_free(wps_ie);
4765 p2p_scan_ie(wpa_s->global->p2p, ies, NULL);
4767 params.p2p_probe = 1;
4768 params.extra_ies = wpabuf_head(ies);
4769 params.extra_ies_len = wpabuf_len(ies);
4774 * If freq is not provided, check the operating freq of the GO
4775 * and use a single channel scan on if possible.
4777 oper_freq = p2p_get_oper_freq(wpa_s->global->p2p,
4778 wpa_s->pending_join_iface_addr);
4784 params.freqs = freqs;
4788 * Run a scan to update BSS table and start Provision Discovery once
4789 * the new scan results become available.
4791 ret = wpa_drv_scan(wpa_s, ¶ms);
4793 os_get_reltime(&wpa_s->scan_trigger_time);
4794 wpa_s->scan_res_handler = wpas_p2p_scan_res_join;
4795 wpa_s->own_scan_requested = 1;
4801 wpa_printf(MSG_DEBUG, "P2P: Failed to start scan for join - "
4803 eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL);
4804 eloop_register_timeout(1, 0, wpas_p2p_join_scan, wpa_s, NULL);
4805 wpas_p2p_check_join_scan_limit(wpa_s);
4810 static void wpas_p2p_join_scan(void *eloop_ctx, void *timeout_ctx)
4812 struct wpa_supplicant *wpa_s = eloop_ctx;
4813 wpas_p2p_join_scan_req(wpa_s, 0, NULL, 0);
4817 static int wpas_p2p_join(struct wpa_supplicant *wpa_s, const u8 *iface_addr,
4818 const u8 *dev_addr, enum p2p_wps_method wps_method,
4819 int auto_join, int op_freq,
4820 const u8 *ssid, size_t ssid_len)
4822 wpa_printf(MSG_DEBUG, "P2P: Request to join existing group (iface "
4823 MACSTR " dev " MACSTR " op_freq=%d)%s",
4824 MAC2STR(iface_addr), MAC2STR(dev_addr), op_freq,
4825 auto_join ? " (auto_join)" : "");
4826 if (ssid && ssid_len) {
4827 wpa_printf(MSG_DEBUG, "P2P: Group SSID specified: %s",
4828 wpa_ssid_txt(ssid, ssid_len));
4831 wpa_s->p2p_auto_pd = 0;
4832 wpa_s->p2p_auto_join = !!auto_join;
4833 os_memcpy(wpa_s->pending_join_iface_addr, iface_addr, ETH_ALEN);
4834 os_memcpy(wpa_s->pending_join_dev_addr, dev_addr, ETH_ALEN);
4835 wpa_s->pending_join_wps_method = wps_method;
4837 /* Make sure we are not running find during connection establishment */
4838 wpas_p2p_stop_find(wpa_s);
4840 wpa_s->p2p_join_scan_count = 0;
4841 wpas_p2p_join_scan_req(wpa_s, op_freq, ssid, ssid_len);
4846 static int wpas_p2p_join_start(struct wpa_supplicant *wpa_s, int freq,
4847 const u8 *ssid, size_t ssid_len)
4849 struct wpa_supplicant *group;
4850 struct p2p_go_neg_results res;
4851 struct wpa_bss *bss;
4853 group = wpas_p2p_get_group_iface(wpa_s, 0, 0);
4856 if (group != wpa_s) {
4857 os_memcpy(group->p2p_pin, wpa_s->p2p_pin,
4858 sizeof(group->p2p_pin));
4859 group->p2p_wps_method = wpa_s->p2p_wps_method;
4862 * Need to mark the current interface for p2p_group_formation
4863 * when a separate group interface is not used. This is needed
4864 * to allow p2p_cancel stop a pending p2p_connect-join.
4865 * wpas_p2p_init_group_interface() addresses this for the case
4866 * where a separate group interface is used.
4868 wpa_s->global->p2p_group_formation = wpa_s;
4871 group->p2p_in_provisioning = 1;
4872 group->p2p_fallback_to_go_neg = wpa_s->p2p_fallback_to_go_neg;
4874 os_memset(&res, 0, sizeof(res));
4875 os_memcpy(res.peer_device_addr, wpa_s->pending_join_dev_addr, ETH_ALEN);
4876 os_memcpy(res.peer_interface_addr, wpa_s->pending_join_iface_addr,
4878 res.wps_method = wpa_s->pending_join_wps_method;
4879 if (freq && ssid && ssid_len) {
4881 res.ssid_len = ssid_len;
4882 os_memcpy(res.ssid, ssid, ssid_len);
4884 bss = wpa_bss_get_bssid_latest(wpa_s,
4885 wpa_s->pending_join_iface_addr);
4887 res.freq = bss->freq;
4888 res.ssid_len = bss->ssid_len;
4889 os_memcpy(res.ssid, bss->ssid, bss->ssid_len);
4890 wpa_printf(MSG_DEBUG, "P2P: Join target GO operating frequency from BSS table: %d MHz (SSID %s)",
4892 wpa_ssid_txt(bss->ssid, bss->ssid_len));
4896 if (wpa_s->off_channel_freq || wpa_s->roc_waiting_drv_freq) {
4897 wpa_printf(MSG_DEBUG, "P2P: Cancel remain-on-channel prior to "
4899 wpa_drv_cancel_remain_on_channel(wpa_s);
4900 wpa_s->off_channel_freq = 0;
4901 wpa_s->roc_waiting_drv_freq = 0;
4903 wpas_start_wps_enrollee(group, &res);
4906 * Allow a longer timeout for join-a-running-group than normal 15
4907 * second group formation timeout since the GO may not have authorized
4908 * our connection yet.
4910 eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s, NULL);
4911 eloop_register_timeout(60, 0, wpas_p2p_group_formation_timeout,
4918 static int wpas_p2p_setup_freqs(struct wpa_supplicant *wpa_s, int freq,
4919 int *force_freq, int *pref_freq, int go,
4920 unsigned int *pref_freq_list,
4921 unsigned int *num_pref_freq)
4923 struct wpa_used_freq_data *freqs;
4924 int res, best_freq, num_unused;
4925 unsigned int freq_in_use = 0, num, i, max_pref_freq;
4927 max_pref_freq = *num_pref_freq;
4930 freqs = os_calloc(wpa_s->num_multichan_concurrent,
4931 sizeof(struct wpa_used_freq_data));
4935 num = wpas_p2p_valid_oper_freqs(wpa_s, freqs,
4936 wpa_s->num_multichan_concurrent);
4939 * It is possible that the total number of used frequencies is bigger
4940 * than the number of frequencies used for P2P, so get the system wide
4941 * number of unused frequencies.
4943 num_unused = wpas_p2p_num_unused_channels(wpa_s);
4945 wpa_printf(MSG_DEBUG,
4946 "P2P: Setup freqs: freq=%d num_MCC=%d shared_freqs=%u num_unused=%d",
4947 freq, wpa_s->num_multichan_concurrent, num, num_unused);
4952 ret = p2p_supported_freq(wpa_s->global->p2p, freq);
4954 ret = p2p_supported_freq_cli(wpa_s->global->p2p, freq);
4956 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) &&
4957 ieee80211_is_dfs(freq)) {
4959 * If freq is a DFS channel and DFS is offloaded
4960 * to the driver, allow P2P GO to use it.
4962 wpa_printf(MSG_DEBUG,
4963 "P2P: The forced channel for GO (%u MHz) is DFS, and DFS is offloaded to the driver",
4966 wpa_printf(MSG_DEBUG,
4967 "P2P: The forced channel (%u MHz) is not supported for P2P uses",
4974 for (i = 0; i < num; i++) {
4975 if (freqs[i].freq == freq)
4979 if (num_unused <= 0 && !freq_in_use) {
4980 wpa_printf(MSG_DEBUG, "P2P: Cannot start P2P group on %u MHz as there are no available channels",
4985 wpa_printf(MSG_DEBUG, "P2P: Trying to force us to use the "
4986 "requested channel (%u MHz)", freq);
4991 best_freq = wpas_p2p_pick_best_used_freq(wpa_s, freqs, num);
4993 if (!wpa_s->conf->num_p2p_pref_chan && *pref_freq == 0) {
4994 enum wpa_driver_if_type iface_type;
4997 iface_type = WPA_IF_P2P_GO;
4999 iface_type = WPA_IF_P2P_CLIENT;
5001 wpa_printf(MSG_DEBUG, "P2P: best_freq=%d, go=%d",
5004 res = wpa_drv_get_pref_freq_list(wpa_s, iface_type,
5007 if (!res && max_pref_freq > 0) {
5008 *num_pref_freq = max_pref_freq;
5010 while (wpas_p2p_disallowed_freq(wpa_s->global,
5011 pref_freq_list[i]) &&
5012 i < *num_pref_freq) {
5013 wpa_printf(MSG_DEBUG,
5014 "P2P: preferred_freq_list[%d]=%d is disallowed",
5015 i, pref_freq_list[i]);
5018 if (i != *num_pref_freq) {
5019 best_freq = pref_freq_list[i];
5020 wpa_printf(MSG_DEBUG,
5021 "P2P: Using preferred_freq_list[%d]=%d",
5024 wpa_printf(MSG_DEBUG,
5025 "P2P: All driver preferred frequencies are disallowed for P2P use");
5029 wpa_printf(MSG_DEBUG,
5030 "P2P: No preferred frequency list available");
5034 /* We have a candidate frequency to use */
5035 if (best_freq > 0) {
5036 if (*pref_freq == 0 && num_unused > 0) {
5037 wpa_printf(MSG_DEBUG, "P2P: Try to prefer a frequency (%u MHz) we are already using",
5039 *pref_freq = best_freq;
5041 wpa_printf(MSG_DEBUG, "P2P: Try to force us to use frequency (%u MHz) which is already in use",
5043 *force_freq = best_freq;
5045 } else if (num_unused > 0) {
5046 wpa_printf(MSG_DEBUG,
5047 "P2P: Current operating channels are not available for P2P. Try to use another channel");
5050 wpa_printf(MSG_DEBUG,
5051 "P2P: All channels are in use and none of them are P2P enabled. Cannot start P2P group");
5065 * wpas_p2p_connect - Request P2P Group Formation to be started
5066 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
5067 * @peer_addr: Address of the peer P2P Device
5068 * @pin: PIN to use during provisioning or %NULL to indicate PBC mode
5069 * @persistent_group: Whether to create a persistent group
5070 * @auto_join: Whether to select join vs. GO Negotiation automatically
5071 * @join: Whether to join an existing group (as a client) instead of starting
5072 * Group Owner negotiation; @peer_addr is BSSID in that case
5073 * @auth: Whether to only authorize the connection instead of doing that and
5074 * initiating Group Owner negotiation
5075 * @go_intent: GO Intent or -1 to use default
5076 * @freq: Frequency for the group or 0 for auto-selection
5077 * @persistent_id: Persistent group credentials to use for forcing GO
5078 * parameters or -1 to generate new values (SSID/passphrase)
5079 * @pd: Whether to send Provision Discovery prior to GO Negotiation as an
5080 * interoperability workaround when initiating group formation
5081 * @ht40: Start GO with 40 MHz channel width
5082 * @vht: Start GO with VHT support
5083 * Returns: 0 or new PIN (if pin was %NULL) on success, -1 on unspecified
5084 * failure, -2 on failure due to channel not currently available,
5085 * -3 if forced channel is not supported
5087 int wpas_p2p_connect(struct wpa_supplicant *wpa_s, const u8 *peer_addr,
5088 const char *pin, enum p2p_wps_method wps_method,
5089 int persistent_group, int auto_join, int join, int auth,
5090 int go_intent, int freq, int persistent_id, int pd,
5093 int force_freq = 0, pref_freq = 0;
5095 enum wpa_driver_if_type iftype;
5097 struct wpa_ssid *ssid = NULL;
5098 unsigned int pref_freq_list[P2P_MAX_PREF_CHANNELS], size;
5100 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
5103 if (persistent_id >= 0) {
5104 ssid = wpa_config_get_network(wpa_s->conf, persistent_id);
5105 if (ssid == NULL || ssid->disabled != 2 ||
5106 ssid->mode != WPAS_MODE_P2P_GO)
5110 os_free(wpa_s->global->add_psk);
5111 wpa_s->global->add_psk = NULL;
5113 wpa_s->global->p2p_fail_on_wps_complete = 0;
5114 wpa_s->global->pending_p2ps_group = 0;
5115 wpa_s->p2ps_method_config_any = 0;
5118 go_intent = wpa_s->conf->p2p_go_intent;
5121 wpa_s->p2p_long_listen = 0;
5123 wpa_s->p2p_wps_method = wps_method;
5124 wpa_s->p2p_persistent_group = !!persistent_group;
5125 wpa_s->p2p_persistent_id = persistent_id;
5126 wpa_s->p2p_go_intent = go_intent;
5127 wpa_s->p2p_connect_freq = freq;
5128 wpa_s->p2p_fallback_to_go_neg = 0;
5129 wpa_s->p2p_pd_before_go_neg = !!pd;
5130 wpa_s->p2p_go_ht40 = !!ht40;
5131 wpa_s->p2p_go_vht = !!vht;
5134 os_strlcpy(wpa_s->p2p_pin, pin, sizeof(wpa_s->p2p_pin));
5135 else if (wps_method == WPS_PIN_DISPLAY) {
5136 ret = wps_generate_pin();
5137 res = os_snprintf(wpa_s->p2p_pin, sizeof(wpa_s->p2p_pin),
5139 if (os_snprintf_error(sizeof(wpa_s->p2p_pin), res))
5140 wpa_s->p2p_pin[sizeof(wpa_s->p2p_pin) - 1] = '\0';
5141 wpa_printf(MSG_DEBUG, "P2P: Randomly generated PIN: %s",
5144 wpa_s->p2p_pin[0] = '\0';
5146 if (join || auto_join) {
5147 u8 iface_addr[ETH_ALEN], dev_addr[ETH_ALEN];
5149 wpa_printf(MSG_DEBUG, "P2P: Authorize invitation to "
5150 "connect a running group from " MACSTR,
5151 MAC2STR(peer_addr));
5152 os_memcpy(wpa_s->p2p_auth_invite, peer_addr, ETH_ALEN);
5155 os_memcpy(dev_addr, peer_addr, ETH_ALEN);
5156 if (p2p_get_interface_addr(wpa_s->global->p2p, peer_addr,
5158 os_memcpy(iface_addr, peer_addr, ETH_ALEN);
5159 p2p_get_dev_addr(wpa_s->global->p2p, peer_addr,
5163 os_get_reltime(&wpa_s->p2p_auto_started);
5164 wpa_printf(MSG_DEBUG, "P2P: Auto join started at "
5166 wpa_s->p2p_auto_started.sec,
5167 wpa_s->p2p_auto_started.usec);
5169 wpa_s->user_initiated_pd = 1;
5170 if (wpas_p2p_join(wpa_s, iface_addr, dev_addr, wps_method,
5171 auto_join, freq, NULL, 0) < 0)
5176 size = P2P_MAX_PREF_CHANNELS;
5177 res = wpas_p2p_setup_freqs(wpa_s, freq, &force_freq, &pref_freq,
5178 go_intent == 15, pref_freq_list, &size);
5181 wpas_p2p_set_own_freq_preference(wpa_s,
5182 force_freq ? force_freq : pref_freq);
5184 p2p_set_own_pref_freq_list(wpa_s->global->p2p, pref_freq_list, size);
5186 wpa_s->create_p2p_iface = wpas_p2p_create_iface(wpa_s);
5188 if (wpa_s->create_p2p_iface) {
5189 /* Prepare to add a new interface for the group */
5190 iftype = WPA_IF_P2P_GROUP;
5191 if (go_intent == 15)
5192 iftype = WPA_IF_P2P_GO;
5193 if (wpas_p2p_add_group_interface(wpa_s, iftype) < 0) {
5194 wpa_printf(MSG_ERROR, "P2P: Failed to allocate a new "
5195 "interface for the group");
5199 if_addr = wpa_s->pending_interface_addr;
5201 if_addr = wpa_s->own_addr;
5202 os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN);
5206 if (wpas_p2p_auth_go_neg(wpa_s, peer_addr, wps_method,
5208 force_freq, persistent_group, ssid,
5214 if (wpas_p2p_start_go_neg(wpa_s, peer_addr, wps_method,
5215 go_intent, if_addr, force_freq,
5216 persistent_group, ssid, pref_freq) < 0) {
5217 if (wpa_s->create_p2p_iface)
5218 wpas_p2p_remove_pending_group_interface(wpa_s);
5226 * wpas_p2p_remain_on_channel_cb - Indication of remain-on-channel start
5227 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
5228 * @freq: Frequency of the channel in MHz
5229 * @duration: Duration of the stay on the channel in milliseconds
5231 * This callback is called when the driver indicates that it has started the
5232 * requested remain-on-channel duration.
5234 void wpas_p2p_remain_on_channel_cb(struct wpa_supplicant *wpa_s,
5235 unsigned int freq, unsigned int duration)
5237 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
5239 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)",
5240 wpa_s->off_channel_freq, wpa_s->pending_listen_freq,
5241 wpa_s->roc_waiting_drv_freq, freq, duration);
5242 if (wpa_s->off_channel_freq &&
5243 wpa_s->off_channel_freq == wpa_s->pending_listen_freq) {
5244 p2p_listen_cb(wpa_s->global->p2p, wpa_s->pending_listen_freq,
5245 wpa_s->pending_listen_duration);
5246 wpa_s->pending_listen_freq = 0;
5248 wpa_printf(MSG_DEBUG, "P2P: Ignore remain-on-channel callback (off_channel_freq=%u pending_listen_freq=%d freq=%u duration=%u)",
5249 wpa_s->off_channel_freq, wpa_s->pending_listen_freq,
5255 int wpas_p2p_listen_start(struct wpa_supplicant *wpa_s, unsigned int timeout)
5257 /* Limit maximum Listen state time based on driver limitation. */
5258 if (timeout > wpa_s->max_remain_on_chan)
5259 timeout = wpa_s->max_remain_on_chan;
5261 return p2p_listen(wpa_s->global->p2p, timeout);
5266 * wpas_p2p_cancel_remain_on_channel_cb - Remain-on-channel timeout
5267 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
5268 * @freq: Frequency of the channel in MHz
5270 * This callback is called when the driver indicates that a remain-on-channel
5271 * operation has been completed, i.e., the duration on the requested channel
5274 void wpas_p2p_cancel_remain_on_channel_cb(struct wpa_supplicant *wpa_s,
5277 wpa_printf(MSG_DEBUG, "P2P: Cancel remain-on-channel callback "
5278 "(p2p_long_listen=%d ms pending_action_tx=%p)",
5279 wpa_s->p2p_long_listen, offchannel_pending_action_tx(wpa_s));
5280 wpas_p2p_listen_work_done(wpa_s);
5281 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
5283 if (wpa_s->p2p_long_listen > 0)
5284 wpa_s->p2p_long_listen -= wpa_s->max_remain_on_chan;
5285 if (p2p_listen_end(wpa_s->global->p2p, freq) > 0)
5286 return; /* P2P module started a new operation */
5287 if (offchannel_pending_action_tx(wpa_s))
5289 if (wpa_s->p2p_long_listen > 0) {
5290 wpa_printf(MSG_DEBUG, "P2P: Continuing long Listen state");
5291 wpas_p2p_listen_start(wpa_s, wpa_s->p2p_long_listen);
5294 * When listen duration is over, stop listen & update p2p_state
5297 p2p_stop_listen(wpa_s->global->p2p);
5303 * wpas_p2p_group_remove - Remove a P2P group
5304 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
5305 * @ifname: Network interface name of the group interface or "*" to remove all
5307 * Returns: 0 on success, -1 on failure
5309 * This function is used to remove a P2P group. This can be used to disconnect
5310 * from a group in which the local end is a P2P Client or to end a P2P Group in
5311 * case the local end is the Group Owner. If a virtual network interface was
5312 * created for this group, that interface will be removed. Otherwise, only the
5313 * configured P2P group network will be removed from the interface.
5315 int wpas_p2p_group_remove(struct wpa_supplicant *wpa_s, const char *ifname)
5317 struct wpa_global *global = wpa_s->global;
5318 struct wpa_supplicant *calling_wpa_s = wpa_s;
5320 if (os_strcmp(ifname, "*") == 0) {
5321 struct wpa_supplicant *prev;
5322 wpa_s = global->ifaces;
5325 wpa_s = wpa_s->next;
5326 if (prev->p2p_group_interface !=
5327 NOT_P2P_GROUP_INTERFACE ||
5328 (prev->current_ssid &&
5329 prev->current_ssid->p2p_group))
5330 wpas_p2p_disconnect_safely(prev, calling_wpa_s);
5335 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
5336 if (os_strcmp(wpa_s->ifname, ifname) == 0)
5340 return wpas_p2p_disconnect_safely(wpa_s, calling_wpa_s);
5344 static int wpas_p2p_select_go_freq(struct wpa_supplicant *wpa_s, int freq)
5348 if (!wpa_s->conf->num_p2p_pref_chan && !freq) {
5349 unsigned int i, size = P2P_MAX_PREF_CHANNELS;
5350 unsigned int pref_freq_list[P2P_MAX_PREF_CHANNELS];
5353 res = wpa_drv_get_pref_freq_list(wpa_s, WPA_IF_P2P_GO,
5354 &size, pref_freq_list);
5355 if (!res && size > 0) {
5357 while (wpas_p2p_disallowed_freq(wpa_s->global,
5358 pref_freq_list[i]) &&
5360 wpa_printf(MSG_DEBUG,
5361 "P2P: preferred_freq_list[%d]=%d is disallowed",
5362 i, pref_freq_list[i]);
5366 freq = pref_freq_list[i];
5367 wpa_printf(MSG_DEBUG,
5368 "P2P: Using preferred_freq_list[%d]=%d",
5371 wpa_printf(MSG_DEBUG,
5372 "P2P: All driver preferred frequencies are disallowed for P2P use");
5375 wpa_printf(MSG_DEBUG,
5376 "P2P: No preferred frequency list available");
5381 wpa_printf(MSG_DEBUG, "P2P: Request to start GO on 2.4 GHz "
5383 if (wpa_s->best_24_freq > 0 &&
5384 p2p_supported_freq_go(wpa_s->global->p2p,
5385 wpa_s->best_24_freq)) {
5386 freq = wpa_s->best_24_freq;
5387 wpa_printf(MSG_DEBUG, "P2P: Use best 2.4 GHz band "
5388 "channel: %d MHz", freq);
5390 if (os_get_random((u8 *) &r, sizeof(r)) < 0)
5392 freq = 2412 + (r % 3) * 25;
5393 wpa_printf(MSG_DEBUG, "P2P: Use random 2.4 GHz band "
5394 "channel: %d MHz", freq);
5399 wpa_printf(MSG_DEBUG, "P2P: Request to start GO on 5 GHz "
5401 if (wpa_s->best_5_freq > 0 &&
5402 p2p_supported_freq_go(wpa_s->global->p2p,
5403 wpa_s->best_5_freq)) {
5404 freq = wpa_s->best_5_freq;
5405 wpa_printf(MSG_DEBUG, "P2P: Use best 5 GHz band "
5406 "channel: %d MHz", freq);
5408 if (os_get_random((u8 *) &r, sizeof(r)) < 0)
5410 freq = 5180 + (r % 4) * 20;
5411 if (!p2p_supported_freq_go(wpa_s->global->p2p, freq)) {
5412 wpa_printf(MSG_DEBUG, "P2P: Could not select "
5413 "5 GHz channel for P2P group");
5416 wpa_printf(MSG_DEBUG, "P2P: Use random 5 GHz band "
5417 "channel: %d MHz", freq);
5421 if (freq > 0 && !p2p_supported_freq_go(wpa_s->global->p2p, freq)) {
5422 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) &&
5423 ieee80211_is_dfs(freq)) {
5425 * If freq is a DFS channel and DFS is offloaded to the
5426 * driver, allow P2P GO to use it.
5428 wpa_printf(MSG_DEBUG, "P2P: "
5429 "%s: The forced channel for GO (%u MHz) is DFS, and DFS is offloaded",
5433 wpa_printf(MSG_DEBUG, "P2P: The forced channel for GO "
5434 "(%u MHz) is not supported for P2P uses",
5443 static int wpas_p2p_supported_freq_go(struct wpa_supplicant *wpa_s,
5444 const struct p2p_channels *channels,
5447 if (!wpas_p2p_disallowed_freq(wpa_s->global, freq) &&
5448 p2p_supported_freq_go(wpa_s->global->p2p, freq) &&
5449 freq_included(wpa_s, channels, freq))
5455 static void wpas_p2p_select_go_freq_no_pref(struct wpa_supplicant *wpa_s,
5456 struct p2p_go_neg_results *params,
5457 const struct p2p_channels *channels)
5461 /* first try some random selection of the social channels */
5462 if (os_get_random((u8 *) &r, sizeof(r)) < 0)
5465 for (i = 0; i < 3; i++) {
5466 params->freq = 2412 + ((r + i) % 3) * 25;
5467 if (wpas_p2p_supported_freq_go(wpa_s, channels, params->freq))
5471 /* try all other channels in operating class 81 */
5472 for (i = 0; i < 11; i++) {
5473 params->freq = 2412 + i * 5;
5475 /* skip social channels; covered in the previous loop */
5476 if (params->freq == 2412 ||
5477 params->freq == 2437 ||
5478 params->freq == 2462)
5481 if (wpas_p2p_supported_freq_go(wpa_s, channels, params->freq))
5485 /* try all channels in operating class 115 */
5486 for (i = 0; i < 4; i++) {
5487 params->freq = 5180 + i * 20;
5488 if (!wpas_p2p_disallowed_freq(wpa_s->global, params->freq) &&
5489 freq_included(wpa_s, channels, params->freq) &&
5490 p2p_supported_freq(wpa_s->global->p2p, params->freq))
5494 /* try all channels in operating class 124 */
5495 for (i = 0; i < 4; i++) {
5496 params->freq = 5745 + i * 20;
5497 if (!wpas_p2p_disallowed_freq(wpa_s->global, params->freq) &&
5498 freq_included(wpa_s, channels, params->freq) &&
5499 p2p_supported_freq(wpa_s->global->p2p, params->freq))
5503 /* try social channel class 180 channel 2 */
5504 params->freq = 58320 + 1 * 2160;
5505 if (!wpas_p2p_disallowed_freq(wpa_s->global, params->freq) &&
5506 freq_included(wpa_s, channels, params->freq) &&
5507 p2p_supported_freq(wpa_s->global->p2p, params->freq))
5510 /* try all channels in reg. class 180 */
5511 for (i = 0; i < 4; i++) {
5512 params->freq = 58320 + i * 2160;
5513 if (!wpas_p2p_disallowed_freq(wpa_s->global, params->freq) &&
5514 freq_included(wpa_s, channels, params->freq) &&
5515 p2p_supported_freq(wpa_s->global->p2p, params->freq))
5520 wpa_printf(MSG_DEBUG, "P2P: No 2.4, 5, or 60 GHz channel allowed");
5523 wpa_printf(MSG_DEBUG, "P2P: Set GO freq %d MHz (no preference known)",
5528 static int wpas_p2p_init_go_params(struct wpa_supplicant *wpa_s,
5529 struct p2p_go_neg_results *params,
5530 int freq, int ht40, int vht,
5531 const struct p2p_channels *channels)
5533 struct wpa_used_freq_data *freqs;
5535 unsigned int num, i;
5536 int ignore_no_freqs = 0;
5538 os_memset(params, 0, sizeof(*params));
5539 params->role_go = 1;
5540 params->ht40 = ht40;
5543 freqs = os_calloc(wpa_s->num_multichan_concurrent,
5544 sizeof(struct wpa_used_freq_data));
5548 num = get_shared_radio_freqs_data(wpa_s, freqs,
5549 wpa_s->num_multichan_concurrent);
5551 if (wpa_s->current_ssid &&
5552 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO &&
5553 wpa_s->wpa_state == WPA_COMPLETED) {
5554 wpa_printf(MSG_DEBUG, "P2P: %s called for an active GO",
5558 * If the frequency selection is done for an active P2P GO that
5559 * is not sharing a frequency, allow to select a new frequency
5560 * even if there are no unused frequencies as we are about to
5561 * move the P2P GO so its frequency can be re-used.
5563 for (i = 0; i < num; i++) {
5564 if (freqs[i].freq == wpa_s->current_ssid->frequency &&
5565 freqs[i].flags == 0) {
5566 ignore_no_freqs = 1;
5572 /* try using the forced freq */
5574 if (!wpas_p2p_supported_freq_go(wpa_s, channels, freq)) {
5575 wpa_printf(MSG_DEBUG,
5576 "P2P: Forced GO freq %d MHz not accepted",
5581 for (i = 0; i < num; i++) {
5582 if (freqs[i].freq == freq) {
5583 wpa_printf(MSG_DEBUG,
5584 "P2P: forced freq (%d MHz) is also shared",
5586 params->freq = freq;
5591 if (!ignore_no_freqs &&
5592 wpas_p2p_num_unused_channels(wpa_s) <= 0) {
5593 wpa_printf(MSG_DEBUG,
5594 "P2P: Cannot force GO on freq (%d MHz) as all the channels are in use",
5599 wpa_printf(MSG_DEBUG,
5600 "P2P: force GO freq (%d MHz) on a free channel",
5602 params->freq = freq;
5606 /* consider using one of the shared frequencies */
5608 cand = wpas_p2p_pick_best_used_freq(wpa_s, freqs, num);
5609 if (wpas_p2p_supported_freq_go(wpa_s, channels, cand)) {
5610 wpa_printf(MSG_DEBUG,
5611 "P2P: Use shared freq (%d MHz) for GO",
5613 params->freq = cand;
5617 /* try using one of the shared freqs */
5618 for (i = 0; i < num; i++) {
5619 if (wpas_p2p_supported_freq_go(wpa_s, channels,
5621 wpa_printf(MSG_DEBUG,
5622 "P2P: Use shared freq (%d MHz) for GO",
5624 params->freq = freqs[i].freq;
5630 if (!ignore_no_freqs &&
5631 wpas_p2p_num_unused_channels(wpa_s) <= 0) {
5632 wpa_printf(MSG_DEBUG,
5633 "P2P: Cannot force GO on any of the channels we are already using");
5637 /* try using the setting from the configuration file */
5638 if (wpa_s->conf->p2p_oper_reg_class == 81 &&
5639 wpa_s->conf->p2p_oper_channel >= 1 &&
5640 wpa_s->conf->p2p_oper_channel <= 11 &&
5641 wpas_p2p_supported_freq_go(
5643 2407 + 5 * wpa_s->conf->p2p_oper_channel)) {
5644 params->freq = 2407 + 5 * wpa_s->conf->p2p_oper_channel;
5645 wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on configured "
5646 "frequency %d MHz", params->freq);
5650 if ((wpa_s->conf->p2p_oper_reg_class == 115 ||
5651 wpa_s->conf->p2p_oper_reg_class == 116 ||
5652 wpa_s->conf->p2p_oper_reg_class == 117 ||
5653 wpa_s->conf->p2p_oper_reg_class == 124 ||
5654 wpa_s->conf->p2p_oper_reg_class == 125 ||
5655 wpa_s->conf->p2p_oper_reg_class == 126 ||
5656 wpa_s->conf->p2p_oper_reg_class == 127) &&
5657 wpas_p2p_supported_freq_go(wpa_s, channels,
5659 5 * wpa_s->conf->p2p_oper_channel)) {
5660 params->freq = 5000 + 5 * wpa_s->conf->p2p_oper_channel;
5661 wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on configured "
5662 "frequency %d MHz", params->freq);
5666 /* Try using best channels */
5667 if (wpa_s->conf->p2p_oper_channel == 0 &&
5668 wpa_s->best_overall_freq > 0 &&
5669 wpas_p2p_supported_freq_go(wpa_s, channels,
5670 wpa_s->best_overall_freq)) {
5671 params->freq = wpa_s->best_overall_freq;
5672 wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on best overall "
5673 "channel %d MHz", params->freq);
5677 if (wpa_s->conf->p2p_oper_channel == 0 &&
5678 wpa_s->best_24_freq > 0 &&
5679 wpas_p2p_supported_freq_go(wpa_s, channels,
5680 wpa_s->best_24_freq)) {
5681 params->freq = wpa_s->best_24_freq;
5682 wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on best 2.4 GHz "
5683 "channel %d MHz", params->freq);
5687 if (wpa_s->conf->p2p_oper_channel == 0 &&
5688 wpa_s->best_5_freq > 0 &&
5689 wpas_p2p_supported_freq_go(wpa_s, channels,
5690 wpa_s->best_5_freq)) {
5691 params->freq = wpa_s->best_5_freq;
5692 wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on best 5 GHz "
5693 "channel %d MHz", params->freq);
5697 /* try using preferred channels */
5698 cand = p2p_get_pref_freq(wpa_s->global->p2p, channels);
5699 if (cand && wpas_p2p_supported_freq_go(wpa_s, channels, cand)) {
5700 params->freq = cand;
5701 wpa_printf(MSG_DEBUG, "P2P: Set GO freq %d MHz from preferred "
5702 "channels", params->freq);
5706 /* Try using one of the group common freqs */
5707 if (wpa_s->p2p_group_common_freqs) {
5708 for (i = 0; i < wpa_s->p2p_group_common_freqs_num; i++) {
5709 cand = wpa_s->p2p_group_common_freqs[i];
5710 if (wpas_p2p_supported_freq_go(wpa_s, channels, cand)) {
5711 params->freq = cand;
5712 wpa_printf(MSG_DEBUG,
5713 "P2P: Use freq %d MHz common with the peer",
5720 /* no preference, select some channel */
5721 wpas_p2p_select_go_freq_no_pref(wpa_s, params, channels);
5723 if (params->freq == 0) {
5724 wpa_printf(MSG_DEBUG, "P2P: did not find a freq for GO use");
5737 static struct wpa_supplicant *
5738 wpas_p2p_get_group_iface(struct wpa_supplicant *wpa_s, int addr_allocated,
5741 struct wpa_supplicant *group_wpa_s;
5743 if (!wpas_p2p_create_iface(wpa_s)) {
5744 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Use same interface for group "
5746 wpa_s->p2p_first_connection_timeout = 0;
5750 if (wpas_p2p_add_group_interface(wpa_s, go ? WPA_IF_P2P_GO :
5751 WPA_IF_P2P_CLIENT) < 0) {
5752 wpa_msg_global(wpa_s, MSG_ERROR,
5753 "P2P: Failed to add group interface");
5756 group_wpa_s = wpas_p2p_init_group_interface(wpa_s, go);
5757 if (group_wpa_s == NULL) {
5758 wpa_msg_global(wpa_s, MSG_ERROR,
5759 "P2P: Failed to initialize group interface");
5760 wpas_p2p_remove_pending_group_interface(wpa_s);
5764 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Use separate group interface %s",
5765 group_wpa_s->ifname);
5766 group_wpa_s->p2p_first_connection_timeout = 0;
5772 * wpas_p2p_group_add - Add a new P2P group with local end as Group Owner
5773 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
5774 * @persistent_group: Whether to create a persistent group
5775 * @freq: Frequency for the group or 0 to indicate no hardcoding
5776 * @ht40: Start GO with 40 MHz channel width
5777 * @vht: Start GO with VHT support
5778 * Returns: 0 on success, -1 on failure
5780 * This function creates a new P2P group with the local end as the Group Owner,
5781 * i.e., without using Group Owner Negotiation.
5783 int wpas_p2p_group_add(struct wpa_supplicant *wpa_s, int persistent_group,
5784 int freq, int ht40, int vht)
5786 struct p2p_go_neg_results params;
5788 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
5791 os_free(wpa_s->global->add_psk);
5792 wpa_s->global->add_psk = NULL;
5794 /* Make sure we are not running find during connection establishment */
5795 wpa_printf(MSG_DEBUG, "P2P: Stop any on-going P2P FIND");
5796 wpas_p2p_stop_find_oper(wpa_s);
5798 freq = wpas_p2p_select_go_freq(wpa_s, freq);
5802 if (wpas_p2p_init_go_params(wpa_s, ¶ms, freq, ht40, vht, NULL))
5805 !p2p_supported_freq_go(wpa_s->global->p2p, params.freq)) {
5806 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) &&
5807 ieee80211_is_dfs(params.freq)) {
5809 * If freq is a DFS channel and DFS is offloaded to the
5810 * driver, allow P2P GO to use it.
5812 wpa_printf(MSG_DEBUG,
5813 "P2P: %s: The forced channel for GO (%u MHz) is DFS, and DFS is offloaded to driver",
5814 __func__, params.freq);
5816 wpa_printf(MSG_DEBUG,
5817 "P2P: The selected channel for GO (%u MHz) is not supported for P2P uses",
5822 p2p_go_params(wpa_s->global->p2p, ¶ms);
5823 params.persistent_group = persistent_group;
5825 wpa_s = wpas_p2p_get_group_iface(wpa_s, 0, 1);
5828 wpas_start_wps_go(wpa_s, ¶ms, 0);
5834 static int wpas_start_p2p_client(struct wpa_supplicant *wpa_s,
5835 struct wpa_ssid *params, int addr_allocated,
5836 int freq, int force_scan)
5838 struct wpa_ssid *ssid;
5840 wpa_s = wpas_p2p_get_group_iface(wpa_s, addr_allocated, 0);
5844 os_get_reltime(&wpa_s->scan_min_time);
5845 wpa_s->p2p_last_4way_hs_fail = NULL;
5847 wpa_supplicant_ap_deinit(wpa_s);
5849 ssid = wpa_config_add_network(wpa_s->conf);
5852 os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN);
5853 wpa_config_set_network_defaults(ssid);
5854 ssid->temporary = 1;
5855 ssid->proto = WPA_PROTO_RSN;
5856 ssid->pairwise_cipher = WPA_CIPHER_CCMP;
5857 ssid->group_cipher = WPA_CIPHER_CCMP;
5858 ssid->key_mgmt = WPA_KEY_MGMT_PSK;
5859 ssid->ssid = os_malloc(params->ssid_len);
5860 if (ssid->ssid == NULL) {
5861 wpa_config_remove_network(wpa_s->conf, ssid->id);
5864 os_memcpy(ssid->ssid, params->ssid, params->ssid_len);
5865 ssid->ssid_len = params->ssid_len;
5866 ssid->p2p_group = 1;
5867 ssid->export_keys = 1;
5868 if (params->psk_set) {
5869 os_memcpy(ssid->psk, params->psk, 32);
5872 if (params->passphrase)
5873 ssid->passphrase = os_strdup(params->passphrase);
5875 wpa_s->show_group_started = 1;
5876 wpa_s->p2p_in_invitation = 1;
5877 wpa_s->p2p_invite_go_freq = freq;
5879 eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s->parent,
5881 eloop_register_timeout(P2P_MAX_INITIAL_CONN_WAIT, 0,
5882 wpas_p2p_group_formation_timeout,
5883 wpa_s->parent, NULL);
5884 wpa_supplicant_select_network(wpa_s, ssid);
5890 int wpas_p2p_group_add_persistent(struct wpa_supplicant *wpa_s,
5891 struct wpa_ssid *ssid, int addr_allocated,
5892 int force_freq, int neg_freq, int ht40,
5893 int vht, const struct p2p_channels *channels,
5894 int connection_timeout, int force_scan)
5896 struct p2p_go_neg_results params;
5899 if (ssid->disabled != 2 || ssid->ssid == NULL)
5902 if (wpas_get_p2p_group(wpa_s, ssid->ssid, ssid->ssid_len, &go) &&
5903 go == (ssid->mode == WPAS_MODE_P2P_GO)) {
5904 wpa_printf(MSG_DEBUG, "P2P: Requested persistent group is "
5907 eloop_cancel_timeout(wpas_p2p_group_formation_timeout,
5908 wpa_s->parent, NULL)) {
5910 * This can happen if Invitation Response frame was lost
5911 * and the peer (GO of a persistent group) tries to
5912 * invite us again. Reschedule the timeout to avoid
5913 * terminating the wait for the connection too early
5914 * since we now know that the peer is still trying to
5915 * invite us instead of having already started the GO.
5917 wpa_printf(MSG_DEBUG,
5918 "P2P: Reschedule group formation timeout since peer is still trying to invite us");
5919 eloop_register_timeout(P2P_MAX_INITIAL_CONN_WAIT, 0,
5920 wpas_p2p_group_formation_timeout,
5921 wpa_s->parent, NULL);
5926 os_free(wpa_s->global->add_psk);
5927 wpa_s->global->add_psk = NULL;
5929 /* Make sure we are not running find during connection establishment */
5930 wpas_p2p_stop_find_oper(wpa_s);
5932 wpa_s->p2p_fallback_to_go_neg = 0;
5934 if (ssid->mode == WPAS_MODE_P2P_GO) {
5935 if (force_freq > 0) {
5936 freq = wpas_p2p_select_go_freq(wpa_s, force_freq);
5940 freq = wpas_p2p_select_go_freq(wpa_s, neg_freq);
5942 (freq > 0 && !freq_included(wpa_s, channels, freq)))
5945 } else if (ssid->mode == WPAS_MODE_INFRA) {
5947 if (freq <= 0 || !freq_included(wpa_s, channels, freq)) {
5948 struct os_reltime now;
5949 struct wpa_bss *bss =
5950 wpa_bss_get_p2p_dev_addr(wpa_s, ssid->bssid);
5952 os_get_reltime(&now);
5954 !os_reltime_expired(&now, &bss->last_update, 5) &&
5955 freq_included(wpa_s, channels, bss->freq))
5961 return wpas_start_p2p_client(wpa_s, ssid, addr_allocated, freq,
5967 if (wpas_p2p_init_go_params(wpa_s, ¶ms, freq, ht40, vht, channels))
5971 params.psk_set = ssid->psk_set;
5973 os_memcpy(params.psk, ssid->psk, sizeof(params.psk));
5974 if (ssid->passphrase) {
5975 if (os_strlen(ssid->passphrase) >= sizeof(params.passphrase)) {
5976 wpa_printf(MSG_ERROR, "P2P: Invalid passphrase in "
5977 "persistent group");
5980 os_strlcpy(params.passphrase, ssid->passphrase,
5981 sizeof(params.passphrase));
5983 os_memcpy(params.ssid, ssid->ssid, ssid->ssid_len);
5984 params.ssid_len = ssid->ssid_len;
5985 params.persistent_group = 1;
5987 wpa_s = wpas_p2p_get_group_iface(wpa_s, addr_allocated, 1);
5991 p2p_channels_to_freqs(channels, params.freq_list, P2P_MAX_CHANNELS);
5993 wpa_s->p2p_first_connection_timeout = connection_timeout;
5994 wpas_start_wps_go(wpa_s, ¶ms, 0);
6000 static void wpas_p2p_ie_update(void *ctx, struct wpabuf *beacon_ies,
6001 struct wpabuf *proberesp_ies)
6003 struct wpa_supplicant *wpa_s = ctx;
6004 if (wpa_s->ap_iface) {
6005 struct hostapd_data *hapd = wpa_s->ap_iface->bss[0];
6006 if (!(hapd->conf->p2p & P2P_GROUP_OWNER)) {
6007 wpabuf_free(beacon_ies);
6008 wpabuf_free(proberesp_ies);
6012 wpabuf_free(hapd->p2p_beacon_ie);
6013 hapd->p2p_beacon_ie = beacon_ies;
6015 wpabuf_free(hapd->p2p_probe_resp_ie);
6016 hapd->p2p_probe_resp_ie = proberesp_ies;
6018 wpabuf_free(beacon_ies);
6019 wpabuf_free(proberesp_ies);
6021 wpa_supplicant_ap_update_beacon(wpa_s);
6025 static void wpas_p2p_idle_update(void *ctx, int idle)
6027 struct wpa_supplicant *wpa_s = ctx;
6028 if (!wpa_s->ap_iface)
6030 wpa_printf(MSG_DEBUG, "P2P: GO - group %sidle", idle ? "" : "not ");
6032 if (wpa_s->global->p2p_fail_on_wps_complete &&
6033 wpa_s->p2p_in_provisioning) {
6034 wpas_p2p_grpform_fail_after_wps(wpa_s);
6037 wpas_p2p_set_group_idle_timeout(wpa_s);
6039 eloop_cancel_timeout(wpas_p2p_group_idle_timeout, wpa_s, NULL);
6043 struct p2p_group * wpas_p2p_group_init(struct wpa_supplicant *wpa_s,
6044 struct wpa_ssid *ssid)
6046 struct p2p_group *group;
6047 struct p2p_group_config *cfg;
6049 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
6052 cfg = os_zalloc(sizeof(*cfg));
6056 if (ssid->p2p_persistent_group && wpa_s->conf->persistent_reconnect)
6057 cfg->persistent_group = 2;
6058 else if (ssid->p2p_persistent_group)
6059 cfg->persistent_group = 1;
6060 os_memcpy(cfg->interface_addr, wpa_s->own_addr, ETH_ALEN);
6061 if (wpa_s->max_stations &&
6062 wpa_s->max_stations < wpa_s->conf->max_num_sta)
6063 cfg->max_clients = wpa_s->max_stations;
6065 cfg->max_clients = wpa_s->conf->max_num_sta;
6066 os_memcpy(cfg->ssid, ssid->ssid, ssid->ssid_len);
6067 cfg->ssid_len = ssid->ssid_len;
6068 cfg->freq = ssid->frequency;
6069 cfg->cb_ctx = wpa_s;
6070 cfg->ie_update = wpas_p2p_ie_update;
6071 cfg->idle_update = wpas_p2p_idle_update;
6073 group = p2p_group_init(wpa_s->global->p2p, cfg);
6076 if (ssid->mode != WPAS_MODE_P2P_GROUP_FORMATION)
6077 p2p_group_notif_formation_done(group);
6078 wpa_s->p2p_group = group;
6083 void wpas_p2p_wps_success(struct wpa_supplicant *wpa_s, const u8 *peer_addr,
6086 struct wpa_ssid *ssid = wpa_s->current_ssid;
6088 if (!wpa_s->p2p_in_provisioning) {
6089 wpa_printf(MSG_DEBUG, "P2P: Ignore WPS success event - P2P "
6090 "provisioning not in progress");
6094 if (ssid && ssid->mode == WPAS_MODE_INFRA) {
6095 u8 go_dev_addr[ETH_ALEN];
6096 os_memcpy(go_dev_addr, wpa_s->bssid, ETH_ALEN);
6097 wpas_p2p_persistent_group(wpa_s, go_dev_addr, ssid->ssid,
6099 /* Clear any stored provisioning info */
6100 p2p_clear_provisioning_info(wpa_s->global->p2p, go_dev_addr);
6103 eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s->parent,
6105 wpa_s->p2p_go_group_formation_completed = 1;
6106 if (ssid && ssid->mode == WPAS_MODE_INFRA) {
6108 * Use a separate timeout for initial data connection to
6109 * complete to allow the group to be removed automatically if
6110 * something goes wrong in this step before the P2P group idle
6111 * timeout mechanism is taken into use.
6113 wpa_dbg(wpa_s, MSG_DEBUG,
6114 "P2P: Re-start group formation timeout (%d seconds) as client for initial connection",
6115 P2P_MAX_INITIAL_CONN_WAIT);
6116 eloop_register_timeout(P2P_MAX_INITIAL_CONN_WAIT, 0,
6117 wpas_p2p_group_formation_timeout,
6118 wpa_s->parent, NULL);
6121 * Use a separate timeout for initial data connection to
6122 * complete to allow the group to be removed automatically if
6123 * the client does not complete data connection successfully.
6125 wpa_dbg(wpa_s, MSG_DEBUG,
6126 "P2P: Re-start group formation timeout (%d seconds) as GO for initial connection",
6127 P2P_MAX_INITIAL_CONN_WAIT_GO);
6128 eloop_register_timeout(P2P_MAX_INITIAL_CONN_WAIT_GO, 0,
6129 wpas_p2p_group_formation_timeout,
6130 wpa_s->parent, NULL);
6132 * Complete group formation on first successful data connection
6134 wpa_s->p2p_go_group_formation_completed = 0;
6136 if (wpa_s->global->p2p)
6137 p2p_wps_success_cb(wpa_s->global->p2p, peer_addr);
6138 wpas_group_formation_completed(wpa_s, 1, 0);
6142 void wpas_p2p_wps_failed(struct wpa_supplicant *wpa_s,
6143 struct wps_event_fail *fail)
6145 if (!wpa_s->p2p_in_provisioning) {
6146 wpa_printf(MSG_DEBUG, "P2P: Ignore WPS fail event - P2P "
6147 "provisioning not in progress");
6151 if (wpa_s->go_params) {
6152 p2p_clear_provisioning_info(
6154 wpa_s->go_params->peer_device_addr);
6157 wpas_notify_p2p_wps_failed(wpa_s, fail);
6159 if (wpa_s == wpa_s->global->p2p_group_formation) {
6161 * Allow some time for the failed WPS negotiation exchange to
6162 * complete, but remove the group since group formation cannot
6163 * succeed after provisioning failure.
6165 wpa_printf(MSG_DEBUG, "P2P: WPS step failed during group formation - reject connection from timeout");
6166 wpa_s->global->p2p_fail_on_wps_complete = 1;
6167 eloop_deplete_timeout(0, 50000,
6168 wpas_p2p_group_formation_timeout,
6169 wpa_s->parent, NULL);
6174 int wpas_p2p_wps_eapol_cb(struct wpa_supplicant *wpa_s)
6176 if (!wpa_s->global->p2p_fail_on_wps_complete ||
6177 !wpa_s->p2p_in_provisioning)
6180 wpas_p2p_grpform_fail_after_wps(wpa_s);
6186 int wpas_p2p_prov_disc(struct wpa_supplicant *wpa_s, const u8 *peer_addr,
6187 const char *config_method,
6188 enum wpas_p2p_prov_disc_use use,
6189 struct p2ps_provision *p2ps_prov)
6193 wpa_s->global->pending_p2ps_group = 0;
6194 wpa_s->p2p_fallback_to_go_neg = 0;
6195 wpa_s->pending_pd_use = NORMAL_PD;
6196 if (p2ps_prov && use == WPAS_P2P_PD_FOR_ASP) {
6197 p2ps_prov->conncap = p2ps_group_capability(
6198 wpa_s, P2PS_SETUP_NONE, p2ps_prov->role);
6199 wpa_printf(MSG_DEBUG,
6200 "P2P: %s conncap: %d - ASP parsed: %x %x %d %s",
6201 __func__, p2ps_prov->conncap,
6202 p2ps_prov->adv_id, p2ps_prov->conncap,
6203 p2ps_prov->status, p2ps_prov->info);
6206 } else if (os_strncmp(config_method, "display", 7) == 0)
6207 config_methods = WPS_CONFIG_DISPLAY;
6208 else if (os_strncmp(config_method, "keypad", 6) == 0)
6209 config_methods = WPS_CONFIG_KEYPAD;
6210 else if (os_strncmp(config_method, "pbc", 3) == 0 ||
6211 os_strncmp(config_method, "pushbutton", 10) == 0)
6212 config_methods = WPS_CONFIG_PUSHBUTTON;
6214 wpa_printf(MSG_DEBUG, "P2P: Unknown config method");
6219 if (use == WPAS_P2P_PD_AUTO) {
6220 os_memcpy(wpa_s->pending_join_dev_addr, peer_addr, ETH_ALEN);
6221 wpa_s->pending_pd_config_methods = config_methods;
6222 wpa_s->p2p_auto_pd = 1;
6223 wpa_s->p2p_auto_join = 0;
6224 wpa_s->pending_pd_before_join = 0;
6225 wpa_s->auto_pd_scan_retry = 0;
6226 wpas_p2p_stop_find(wpa_s);
6227 wpa_s->p2p_join_scan_count = 0;
6228 os_get_reltime(&wpa_s->p2p_auto_started);
6229 wpa_printf(MSG_DEBUG, "P2P: Auto PD started at %ld.%06ld",
6230 wpa_s->p2p_auto_started.sec,
6231 wpa_s->p2p_auto_started.usec);
6232 wpas_p2p_join_scan(wpa_s, NULL);
6236 if (wpa_s->global->p2p == NULL || wpa_s->global->p2p_disabled) {
6241 return p2p_prov_disc_req(wpa_s->global->p2p, peer_addr, p2ps_prov,
6242 config_methods, use == WPAS_P2P_PD_FOR_JOIN,
6247 int wpas_p2p_scan_result_text(const u8 *ies, size_t ies_len, char *buf,
6250 return p2p_scan_result_text(ies, ies_len, buf, end);
6254 static void wpas_p2p_clear_pending_action_tx(struct wpa_supplicant *wpa_s)
6256 if (!offchannel_pending_action_tx(wpa_s))
6259 wpas_p2p_action_tx_clear(wpa_s);
6261 wpa_printf(MSG_DEBUG, "P2P: Drop pending Action TX due to new "
6262 "operation request");
6263 offchannel_clear_pending_action_tx(wpa_s);
6267 int wpas_p2p_find(struct wpa_supplicant *wpa_s, unsigned int timeout,
6268 enum p2p_discovery_type type,
6269 unsigned int num_req_dev_types, const u8 *req_dev_types,
6270 const u8 *dev_id, unsigned int search_delay,
6271 u8 seek_cnt, const char **seek_string, int freq)
6273 wpas_p2p_clear_pending_action_tx(wpa_s);
6274 wpa_s->p2p_long_listen = 0;
6276 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL ||
6277 wpa_s->p2p_in_provisioning)
6280 wpa_supplicant_cancel_sched_scan(wpa_s);
6282 return p2p_find(wpa_s->global->p2p, timeout, type,
6283 num_req_dev_types, req_dev_types, dev_id,
6284 search_delay, seek_cnt, seek_string, freq);
6288 static void wpas_p2p_scan_res_ignore_search(struct wpa_supplicant *wpa_s,
6289 struct wpa_scan_results *scan_res)
6291 wpa_printf(MSG_DEBUG, "P2P: Ignore scan results");
6293 if (wpa_s->p2p_scan_work) {
6294 struct wpa_radio_work *work = wpa_s->p2p_scan_work;
6295 wpa_s->p2p_scan_work = NULL;
6296 radio_work_done(work);
6299 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
6303 * Indicate that results have been processed so that the P2P module can
6304 * continue pending tasks.
6306 p2p_scan_res_handled(wpa_s->global->p2p);
6310 static void wpas_p2p_stop_find_oper(struct wpa_supplicant *wpa_s)
6312 wpas_p2p_clear_pending_action_tx(wpa_s);
6313 wpa_s->p2p_long_listen = 0;
6314 eloop_cancel_timeout(wpas_p2p_long_listen_timeout, wpa_s, NULL);
6315 eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL);
6317 if (wpa_s->global->p2p)
6318 p2p_stop_find(wpa_s->global->p2p);
6320 if (wpa_s->scan_res_handler == wpas_p2p_scan_res_handler) {
6321 wpa_printf(MSG_DEBUG,
6322 "P2P: Do not consider the scan results after stop_find");
6323 wpa_s->scan_res_handler = wpas_p2p_scan_res_ignore_search;
6328 void wpas_p2p_stop_find(struct wpa_supplicant *wpa_s)
6330 wpas_p2p_stop_find_oper(wpa_s);
6331 if (!wpa_s->global->pending_group_iface_for_p2ps)
6332 wpas_p2p_remove_pending_group_interface(wpa_s);
6336 static void wpas_p2p_long_listen_timeout(void *eloop_ctx, void *timeout_ctx)
6338 struct wpa_supplicant *wpa_s = eloop_ctx;
6339 wpa_s->p2p_long_listen = 0;
6343 int wpas_p2p_listen(struct wpa_supplicant *wpa_s, unsigned int timeout)
6347 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
6350 wpa_supplicant_cancel_sched_scan(wpa_s);
6351 wpas_p2p_clear_pending_action_tx(wpa_s);
6355 * This is a request for unlimited Listen state. However, at
6356 * least for now, this is mapped to a Listen state for one
6361 eloop_cancel_timeout(wpas_p2p_long_listen_timeout, wpa_s, NULL);
6362 wpa_s->p2p_long_listen = 0;
6365 * Stop previous find/listen operation to avoid trying to request a new
6366 * remain-on-channel operation while the driver is still running the
6369 if (wpa_s->global->p2p)
6370 p2p_stop_find(wpa_s->global->p2p);
6372 res = wpas_p2p_listen_start(wpa_s, timeout * 1000);
6373 if (res == 0 && timeout * 1000 > wpa_s->max_remain_on_chan) {
6374 wpa_s->p2p_long_listen = timeout * 1000;
6375 eloop_register_timeout(timeout, 0,
6376 wpas_p2p_long_listen_timeout,
6384 int wpas_p2p_assoc_req_ie(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
6385 u8 *buf, size_t len, int p2p_group)
6387 struct wpabuf *p2p_ie;
6390 if (wpa_s->global->p2p_disabled)
6393 * Advertize mandatory cross connection capability even on
6394 * p2p_disabled=1 interface when associating with a P2P Manager WLAN AP.
6396 if (wpa_s->conf->p2p_disabled && p2p_group)
6398 if (wpa_s->global->p2p == NULL)
6403 p2p_ie = wpa_bss_get_vendor_ie_multi(bss, P2P_IE_VENDOR_TYPE);
6404 ret = p2p_assoc_req_ie(wpa_s->global->p2p, bss->bssid, buf, len,
6406 wpabuf_free(p2p_ie);
6412 int wpas_p2p_probe_req_rx(struct wpa_supplicant *wpa_s, const u8 *addr,
6413 const u8 *dst, const u8 *bssid,
6414 const u8 *ie, size_t ie_len,
6415 unsigned int rx_freq, int ssi_signal)
6417 if (wpa_s->global->p2p_disabled)
6419 if (wpa_s->global->p2p == NULL)
6422 switch (p2p_probe_req_rx(wpa_s->global->p2p, addr, dst, bssid,
6423 ie, ie_len, rx_freq)) {
6424 case P2P_PREQ_NOT_P2P:
6425 wpas_notify_preq(wpa_s, addr, dst, bssid, ie, ie_len,
6428 case P2P_PREQ_MALFORMED:
6429 case P2P_PREQ_NOT_LISTEN:
6430 case P2P_PREQ_NOT_PROCESSED:
6431 default: /* make gcc happy */
6433 case P2P_PREQ_PROCESSED:
6439 void wpas_p2p_rx_action(struct wpa_supplicant *wpa_s, const u8 *da,
6440 const u8 *sa, const u8 *bssid,
6441 u8 category, const u8 *data, size_t len, int freq)
6443 if (wpa_s->global->p2p_disabled)
6445 if (wpa_s->global->p2p == NULL)
6448 p2p_rx_action(wpa_s->global->p2p, da, sa, bssid, category, data, len,
6453 void wpas_p2p_scan_ie(struct wpa_supplicant *wpa_s, struct wpabuf *ies)
6455 if (wpa_s->global->p2p_disabled)
6457 if (wpa_s->global->p2p == NULL)
6460 p2p_scan_ie(wpa_s->global->p2p, ies, NULL);
6464 static void wpas_p2p_group_deinit(struct wpa_supplicant *wpa_s)
6466 p2p_group_deinit(wpa_s->p2p_group);
6467 wpa_s->p2p_group = NULL;
6469 wpa_s->ap_configured_cb = NULL;
6470 wpa_s->ap_configured_cb_ctx = NULL;
6471 wpa_s->ap_configured_cb_data = NULL;
6472 wpa_s->connect_without_scan = NULL;
6476 int wpas_p2p_reject(struct wpa_supplicant *wpa_s, const u8 *addr)
6478 wpa_s->p2p_long_listen = 0;
6480 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
6483 return p2p_reject(wpa_s->global->p2p, addr);
6487 /* Invite to reinvoke a persistent group */
6488 int wpas_p2p_invite(struct wpa_supplicant *wpa_s, const u8 *peer_addr,
6489 struct wpa_ssid *ssid, const u8 *go_dev_addr, int freq,
6490 int ht40, int vht, int pref_freq)
6492 enum p2p_invite_role role;
6496 int no_pref_freq_given = pref_freq == 0;
6497 unsigned int pref_freq_list[P2P_MAX_PREF_CHANNELS], size;
6499 wpa_s->global->p2p_invite_group = NULL;
6501 os_memcpy(wpa_s->p2p_auth_invite, peer_addr, ETH_ALEN);
6503 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
6505 wpa_s->p2p_persistent_go_freq = freq;
6506 wpa_s->p2p_go_ht40 = !!ht40;
6507 if (ssid->mode == WPAS_MODE_P2P_GO) {
6508 role = P2P_INVITE_ROLE_GO;
6509 if (peer_addr == NULL) {
6510 wpa_printf(MSG_DEBUG, "P2P: Missing peer "
6511 "address in invitation command");
6514 if (wpas_p2p_create_iface(wpa_s)) {
6515 if (wpas_p2p_add_group_interface(wpa_s,
6516 WPA_IF_P2P_GO) < 0) {
6517 wpa_printf(MSG_ERROR, "P2P: Failed to "
6518 "allocate a new interface for the "
6522 bssid = wpa_s->pending_interface_addr;
6524 bssid = wpa_s->own_addr;
6526 role = P2P_INVITE_ROLE_CLIENT;
6527 peer_addr = ssid->bssid;
6529 wpa_s->pending_invite_ssid_id = ssid->id;
6531 size = P2P_MAX_PREF_CHANNELS;
6532 res = wpas_p2p_setup_freqs(wpa_s, freq, &force_freq, &pref_freq,
6533 role == P2P_INVITE_ROLE_GO,
6534 pref_freq_list, &size);
6537 p2p_set_own_pref_freq_list(wpa_s->global->p2p, pref_freq_list, size);
6539 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
6542 if (wpa_s->parent->conf->p2p_ignore_shared_freq &&
6543 no_pref_freq_given && pref_freq > 0 &&
6544 wpa_s->num_multichan_concurrent > 1 &&
6545 wpas_p2p_num_unused_channels(wpa_s) > 0) {
6546 wpa_printf(MSG_DEBUG, "P2P: Ignore own channel preference %d MHz for invitation due to p2p_ignore_shared_freq=1 configuration",
6552 * Stop any find/listen operations before invitation and possibly
6553 * connection establishment.
6555 wpas_p2p_stop_find_oper(wpa_s);
6557 return p2p_invite(wpa_s->global->p2p, peer_addr, role, bssid,
6558 ssid->ssid, ssid->ssid_len, force_freq, go_dev_addr,
6563 /* Invite to join an active group */
6564 int wpas_p2p_invite_group(struct wpa_supplicant *wpa_s, const char *ifname,
6565 const u8 *peer_addr, const u8 *go_dev_addr)
6567 struct wpa_global *global = wpa_s->global;
6568 enum p2p_invite_role role;
6570 struct wpa_ssid *ssid;
6572 int freq = 0, force_freq = 0, pref_freq = 0;
6574 unsigned int pref_freq_list[P2P_MAX_PREF_CHANNELS], size;
6576 wpa_s->p2p_persistent_go_freq = 0;
6577 wpa_s->p2p_go_ht40 = 0;
6578 wpa_s->p2p_go_vht = 0;
6580 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
6581 if (os_strcmp(wpa_s->ifname, ifname) == 0)
6584 if (wpa_s == NULL) {
6585 wpa_printf(MSG_DEBUG, "P2P: Interface '%s' not found", ifname);
6589 ssid = wpa_s->current_ssid;
6591 wpa_printf(MSG_DEBUG, "P2P: No current SSID to use for "
6596 wpa_s->global->p2p_invite_group = wpa_s;
6597 persistent = ssid->p2p_persistent_group &&
6598 wpas_p2p_get_persistent(wpa_s->parent, peer_addr,
6599 ssid->ssid, ssid->ssid_len);
6601 if (ssid->mode == WPAS_MODE_P2P_GO) {
6602 role = P2P_INVITE_ROLE_ACTIVE_GO;
6603 bssid = wpa_s->own_addr;
6604 if (go_dev_addr == NULL)
6605 go_dev_addr = wpa_s->global->p2p_dev_addr;
6606 freq = ssid->frequency;
6608 role = P2P_INVITE_ROLE_CLIENT;
6609 if (wpa_s->wpa_state < WPA_ASSOCIATED) {
6610 wpa_printf(MSG_DEBUG, "P2P: Not associated - cannot "
6611 "invite to current group");
6614 bssid = wpa_s->bssid;
6615 if (go_dev_addr == NULL &&
6616 !is_zero_ether_addr(wpa_s->go_dev_addr))
6617 go_dev_addr = wpa_s->go_dev_addr;
6618 freq = wpa_s->current_bss ? wpa_s->current_bss->freq :
6619 (int) wpa_s->assoc_freq;
6621 wpa_s->parent->pending_invite_ssid_id = -1;
6623 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
6626 size = P2P_MAX_PREF_CHANNELS;
6627 res = wpas_p2p_setup_freqs(wpa_s, freq, &force_freq, &pref_freq,
6628 role == P2P_INVITE_ROLE_ACTIVE_GO,
6629 pref_freq_list, &size);
6632 wpas_p2p_set_own_freq_preference(wpa_s, force_freq);
6634 return p2p_invite(wpa_s->global->p2p, peer_addr, role, bssid,
6635 ssid->ssid, ssid->ssid_len, force_freq,
6636 go_dev_addr, persistent, pref_freq, -1);
6640 void wpas_p2p_completed(struct wpa_supplicant *wpa_s)
6642 struct wpa_ssid *ssid = wpa_s->current_ssid;
6643 u8 go_dev_addr[ETH_ALEN];
6644 int network_id = -1;
6650 if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GROUP_FORMATION) {
6651 eloop_cancel_timeout(wpas_p2p_group_formation_timeout,
6652 wpa_s->parent, NULL);
6655 if (!wpa_s->show_group_started || !ssid)
6658 wpa_s->show_group_started = 0;
6660 os_memset(go_dev_addr, 0, ETH_ALEN);
6661 if (ssid->bssid_set)
6662 os_memcpy(go_dev_addr, ssid->bssid, ETH_ALEN);
6663 persistent = wpas_p2p_persistent_group(wpa_s, go_dev_addr, ssid->ssid,
6665 os_memcpy(wpa_s->go_dev_addr, go_dev_addr, ETH_ALEN);
6667 if (wpa_s->global->p2p_group_formation == wpa_s)
6668 wpa_s->global->p2p_group_formation = NULL;
6670 freq = wpa_s->current_bss ? wpa_s->current_bss->freq :
6671 (int) wpa_s->assoc_freq;
6674 if (wpa_sm_get_p2p_ip_addr(wpa_s->wpa, ip) == 0) {
6677 res = os_snprintf(ip_addr, sizeof(ip_addr),
6678 " ip_addr=%u.%u.%u.%u "
6679 "ip_mask=%u.%u.%u.%u go_ip_addr=%u.%u.%u.%u",
6680 ip[0], ip[1], ip[2], ip[3],
6681 ip[4], ip[5], ip[6], ip[7],
6682 ip[8], ip[9], ip[10], ip[11]);
6683 if (os_snprintf_error(sizeof(ip_addr), res))
6687 wpas_p2p_group_started(wpa_s, 0, ssid, freq,
6688 ssid->passphrase == NULL && ssid->psk_set ?
6690 ssid->passphrase, go_dev_addr, persistent,
6694 network_id = wpas_p2p_store_persistent_group(wpa_s->parent,
6697 network_id = ssid->id;
6698 wpas_notify_p2p_group_started(wpa_s, ssid, network_id, 1);
6702 int wpas_p2p_presence_req(struct wpa_supplicant *wpa_s, u32 duration1,
6703 u32 interval1, u32 duration2, u32 interval2)
6707 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
6710 if (wpa_s->wpa_state < WPA_ASSOCIATED ||
6711 wpa_s->current_ssid == NULL ||
6712 wpa_s->current_ssid->mode != WPAS_MODE_INFRA)
6715 ret = p2p_presence_req(wpa_s->global->p2p, wpa_s->bssid,
6716 wpa_s->own_addr, wpa_s->assoc_freq,
6717 duration1, interval1, duration2, interval2);
6719 wpa_s->waiting_presence_resp = 1;
6725 int wpas_p2p_ext_listen(struct wpa_supplicant *wpa_s, unsigned int period,
6726 unsigned int interval)
6728 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
6731 return p2p_ext_listen(wpa_s->global->p2p, period, interval);
6735 static int wpas_p2p_is_client(struct wpa_supplicant *wpa_s)
6737 if (wpa_s->current_ssid == NULL) {
6739 * current_ssid can be cleared when P2P client interface gets
6740 * disconnected, so assume this interface was used as P2P
6745 return wpa_s->current_ssid->p2p_group &&
6746 wpa_s->current_ssid->mode == WPAS_MODE_INFRA;
6750 static void wpas_p2p_group_idle_timeout(void *eloop_ctx, void *timeout_ctx)
6752 struct wpa_supplicant *wpa_s = eloop_ctx;
6754 if (wpa_s->conf->p2p_group_idle == 0 && !wpas_p2p_is_client(wpa_s)) {
6755 wpa_printf(MSG_DEBUG, "P2P: Ignore group idle timeout - "
6760 wpa_printf(MSG_DEBUG, "P2P: Group idle timeout reached - terminate "
6762 wpas_p2p_group_delete(wpa_s, P2P_GROUP_REMOVAL_IDLE_TIMEOUT);
6766 static void wpas_p2p_set_group_idle_timeout(struct wpa_supplicant *wpa_s)
6770 if (eloop_cancel_timeout(wpas_p2p_group_idle_timeout, wpa_s, NULL) > 0)
6771 wpa_printf(MSG_DEBUG, "P2P: Cancelled P2P group idle timeout");
6773 if (wpa_s->current_ssid == NULL || !wpa_s->current_ssid->p2p_group)
6776 timeout = wpa_s->conf->p2p_group_idle;
6777 if (wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
6778 (timeout == 0 || timeout > P2P_MAX_CLIENT_IDLE))
6779 timeout = P2P_MAX_CLIENT_IDLE;
6785 if (wpa_s->current_ssid->mode == WPAS_MODE_INFRA)
6786 timeout = 0; /* special client mode no-timeout */
6791 if (wpa_s->p2p_in_provisioning) {
6793 * Use the normal group formation timeout during the
6794 * provisioning phase to avoid terminating this process too
6795 * early due to group idle timeout.
6797 wpa_printf(MSG_DEBUG, "P2P: Do not use P2P group idle timeout "
6798 "during provisioning");
6802 if (wpa_s->show_group_started) {
6804 * Use the normal group formation timeout between the end of
6805 * the provisioning phase and completion of 4-way handshake to
6806 * avoid terminating this process too early due to group idle
6809 wpa_printf(MSG_DEBUG, "P2P: Do not use P2P group idle timeout "
6810 "while waiting for initial 4-way handshake to "
6815 wpa_printf(MSG_DEBUG, "P2P: Set P2P group idle timeout to %u seconds",
6817 eloop_register_timeout(timeout, 0, wpas_p2p_group_idle_timeout,
6822 /* Returns 1 if the interface was removed */
6823 int wpas_p2p_deauth_notif(struct wpa_supplicant *wpa_s, const u8 *bssid,
6824 u16 reason_code, const u8 *ie, size_t ie_len,
6825 int locally_generated)
6827 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
6830 if (!locally_generated)
6831 p2p_deauth_notif(wpa_s->global->p2p, bssid, reason_code, ie,
6834 if (reason_code == WLAN_REASON_DEAUTH_LEAVING && !locally_generated &&
6835 wpa_s->current_ssid &&
6836 wpa_s->current_ssid->p2p_group &&
6837 wpa_s->current_ssid->mode == WPAS_MODE_INFRA) {
6838 wpa_printf(MSG_DEBUG, "P2P: GO indicated that the P2P Group "
6839 "session is ending");
6840 if (wpas_p2p_group_delete(wpa_s,
6841 P2P_GROUP_REMOVAL_GO_ENDING_SESSION)
6850 void wpas_p2p_disassoc_notif(struct wpa_supplicant *wpa_s, const u8 *bssid,
6851 u16 reason_code, const u8 *ie, size_t ie_len,
6852 int locally_generated)
6854 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
6857 if (!locally_generated)
6858 p2p_disassoc_notif(wpa_s->global->p2p, bssid, reason_code, ie,
6863 void wpas_p2p_update_config(struct wpa_supplicant *wpa_s)
6865 struct p2p_data *p2p = wpa_s->global->p2p;
6870 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_CAPABLE))
6873 if (wpa_s->conf->changed_parameters & CFG_CHANGED_DEVICE_NAME)
6874 p2p_set_dev_name(p2p, wpa_s->conf->device_name);
6876 if (wpa_s->conf->changed_parameters & CFG_CHANGED_DEVICE_TYPE)
6877 p2p_set_pri_dev_type(p2p, wpa_s->conf->device_type);
6880 (wpa_s->conf->changed_parameters & CFG_CHANGED_CONFIG_METHODS))
6881 p2p_set_config_methods(p2p, wpa_s->wps->config_methods);
6883 if (wpa_s->wps && (wpa_s->conf->changed_parameters & CFG_CHANGED_UUID))
6884 p2p_set_uuid(p2p, wpa_s->wps->uuid);
6886 if (wpa_s->conf->changed_parameters & CFG_CHANGED_WPS_STRING) {
6887 p2p_set_manufacturer(p2p, wpa_s->conf->manufacturer);
6888 p2p_set_model_name(p2p, wpa_s->conf->model_name);
6889 p2p_set_model_number(p2p, wpa_s->conf->model_number);
6890 p2p_set_serial_number(p2p, wpa_s->conf->serial_number);
6893 if (wpa_s->conf->changed_parameters & CFG_CHANGED_SEC_DEVICE_TYPE)
6894 p2p_set_sec_dev_types(p2p,
6895 (void *) wpa_s->conf->sec_device_type,
6896 wpa_s->conf->num_sec_device_types);
6898 if (wpa_s->conf->changed_parameters & CFG_CHANGED_VENDOR_EXTENSION) {
6900 p2p_remove_wps_vendor_extensions(p2p);
6901 for (i = 0; i < MAX_WPS_VENDOR_EXT; i++) {
6902 if (wpa_s->conf->wps_vendor_ext[i] == NULL)
6904 p2p_add_wps_vendor_extension(
6905 p2p, wpa_s->conf->wps_vendor_ext[i]);
6909 if ((wpa_s->conf->changed_parameters & CFG_CHANGED_COUNTRY) &&
6910 wpa_s->conf->country[0] && wpa_s->conf->country[1]) {
6912 country[0] = wpa_s->conf->country[0];
6913 country[1] = wpa_s->conf->country[1];
6915 p2p_set_country(p2p, country);
6918 if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_SSID_POSTFIX) {
6919 p2p_set_ssid_postfix(p2p, (u8 *) wpa_s->conf->p2p_ssid_postfix,
6920 wpa_s->conf->p2p_ssid_postfix ?
6921 os_strlen(wpa_s->conf->p2p_ssid_postfix) :
6925 if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_INTRA_BSS)
6926 p2p_set_intra_bss_dist(p2p, wpa_s->conf->p2p_intra_bss);
6928 if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_LISTEN_CHANNEL) {
6929 u8 reg_class, channel;
6934 if (wpa_s->conf->p2p_listen_reg_class &&
6935 wpa_s->conf->p2p_listen_channel) {
6936 reg_class = wpa_s->conf->p2p_listen_reg_class;
6937 channel = wpa_s->conf->p2p_listen_channel;
6942 * Pick one of the social channels randomly as the
6945 if (os_get_random((u8 *) &r, sizeof(r)) < 0)
6948 channel = 1 + (r % 3) * 5;
6951 ret = p2p_set_listen_channel(p2p, reg_class, channel,
6954 wpa_printf(MSG_ERROR, "P2P: Own listen channel update "
6957 if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_OPER_CHANNEL) {
6958 u8 op_reg_class, op_channel, cfg_op_channel;
6961 if (wpa_s->conf->p2p_oper_reg_class &&
6962 wpa_s->conf->p2p_oper_channel) {
6963 op_reg_class = wpa_s->conf->p2p_oper_reg_class;
6964 op_channel = wpa_s->conf->p2p_oper_channel;
6969 * Use random operation channel from (1, 6, 11)
6970 *if no other preference is indicated.
6972 if (os_get_random((u8 *) &r, sizeof(r)) < 0)
6975 op_channel = 1 + (r % 3) * 5;
6978 ret = p2p_set_oper_channel(p2p, op_reg_class, op_channel,
6981 wpa_printf(MSG_ERROR, "P2P: Own oper channel update "
6985 if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_PREF_CHAN) {
6986 if (p2p_set_pref_chan(p2p, wpa_s->conf->num_p2p_pref_chan,
6987 wpa_s->conf->p2p_pref_chan) < 0) {
6988 wpa_printf(MSG_ERROR, "P2P: Preferred channel list "
6992 if (p2p_set_no_go_freq(p2p, &wpa_s->conf->p2p_no_go_freq) < 0) {
6993 wpa_printf(MSG_ERROR, "P2P: No GO channel list "
6998 if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_PASSPHRASE_LEN)
6999 p2p_set_passphrase_len(p2p, wpa_s->conf->p2p_passphrase_len);
7003 int wpas_p2p_set_noa(struct wpa_supplicant *wpa_s, u8 count, int start,
7006 if (!wpa_s->ap_iface)
7008 return hostapd_p2p_set_noa(wpa_s->ap_iface->bss[0], count, start,
7013 int wpas_p2p_set_cross_connect(struct wpa_supplicant *wpa_s, int enabled)
7015 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
7018 wpa_s->global->cross_connection = enabled;
7019 p2p_set_cross_connect(wpa_s->global->p2p, enabled);
7022 struct wpa_supplicant *iface;
7024 for (iface = wpa_s->global->ifaces; iface; iface = iface->next)
7026 if (iface->cross_connect_enabled == 0)
7029 iface->cross_connect_enabled = 0;
7030 iface->cross_connect_in_use = 0;
7031 wpa_msg_global(iface->parent, MSG_INFO,
7032 P2P_EVENT_CROSS_CONNECT_DISABLE "%s %s",
7034 iface->cross_connect_uplink);
7042 static void wpas_p2p_enable_cross_connect(struct wpa_supplicant *uplink)
7044 struct wpa_supplicant *iface;
7046 if (!uplink->global->cross_connection)
7049 for (iface = uplink->global->ifaces; iface; iface = iface->next) {
7050 if (!iface->cross_connect_enabled)
7052 if (os_strcmp(uplink->ifname, iface->cross_connect_uplink) !=
7055 if (iface->ap_iface == NULL)
7057 if (iface->cross_connect_in_use)
7060 iface->cross_connect_in_use = 1;
7061 wpa_msg_global(iface->parent, MSG_INFO,
7062 P2P_EVENT_CROSS_CONNECT_ENABLE "%s %s",
7063 iface->ifname, iface->cross_connect_uplink);
7068 static void wpas_p2p_disable_cross_connect(struct wpa_supplicant *uplink)
7070 struct wpa_supplicant *iface;
7072 for (iface = uplink->global->ifaces; iface; iface = iface->next) {
7073 if (!iface->cross_connect_enabled)
7075 if (os_strcmp(uplink->ifname, iface->cross_connect_uplink) !=
7078 if (!iface->cross_connect_in_use)
7081 wpa_msg_global(iface->parent, MSG_INFO,
7082 P2P_EVENT_CROSS_CONNECT_DISABLE "%s %s",
7083 iface->ifname, iface->cross_connect_uplink);
7084 iface->cross_connect_in_use = 0;
7089 void wpas_p2p_notif_connected(struct wpa_supplicant *wpa_s)
7091 if (wpa_s->ap_iface || wpa_s->current_ssid == NULL ||
7092 wpa_s->current_ssid->mode != WPAS_MODE_INFRA ||
7093 wpa_s->cross_connect_disallowed)
7094 wpas_p2p_disable_cross_connect(wpa_s);
7096 wpas_p2p_enable_cross_connect(wpa_s);
7097 if (!wpa_s->ap_iface &&
7098 eloop_cancel_timeout(wpas_p2p_group_idle_timeout, wpa_s, NULL) > 0)
7099 wpa_printf(MSG_DEBUG, "P2P: Cancelled P2P group idle timeout");
7103 void wpas_p2p_notif_disconnected(struct wpa_supplicant *wpa_s)
7105 wpas_p2p_disable_cross_connect(wpa_s);
7106 if (!wpa_s->ap_iface &&
7107 !eloop_is_timeout_registered(wpas_p2p_group_idle_timeout,
7109 wpas_p2p_set_group_idle_timeout(wpa_s);
7113 static void wpas_p2p_cross_connect_setup(struct wpa_supplicant *wpa_s)
7115 struct wpa_supplicant *iface;
7117 if (!wpa_s->global->cross_connection)
7120 for (iface = wpa_s->global->ifaces; iface; iface = iface->next) {
7123 if (iface->drv_flags &
7124 WPA_DRIVER_FLAGS_P2P_DEDICATED_INTERFACE)
7126 if ((iface->drv_flags & WPA_DRIVER_FLAGS_P2P_CAPABLE) &&
7127 iface != wpa_s->parent)
7130 wpa_s->cross_connect_enabled = 1;
7131 os_strlcpy(wpa_s->cross_connect_uplink, iface->ifname,
7132 sizeof(wpa_s->cross_connect_uplink));
7133 wpa_printf(MSG_DEBUG, "P2P: Enable cross connection from "
7134 "%s to %s whenever uplink is available",
7135 wpa_s->ifname, wpa_s->cross_connect_uplink);
7137 if (iface->ap_iface || iface->current_ssid == NULL ||
7138 iface->current_ssid->mode != WPAS_MODE_INFRA ||
7139 iface->cross_connect_disallowed ||
7140 iface->wpa_state != WPA_COMPLETED)
7143 wpa_s->cross_connect_in_use = 1;
7144 wpa_msg_global(wpa_s->parent, MSG_INFO,
7145 P2P_EVENT_CROSS_CONNECT_ENABLE "%s %s",
7146 wpa_s->ifname, wpa_s->cross_connect_uplink);
7152 int wpas_p2p_notif_pbc_overlap(struct wpa_supplicant *wpa_s)
7154 if (wpa_s->p2p_group_interface != P2P_GROUP_INTERFACE_CLIENT &&
7155 !wpa_s->p2p_in_provisioning)
7156 return 0; /* not P2P client operation */
7158 wpa_printf(MSG_DEBUG, "P2P: Terminate connection due to WPS PBC "
7160 if (wpa_s != wpa_s->parent)
7161 wpa_msg_ctrl(wpa_s->parent, MSG_INFO, WPS_EVENT_OVERLAP);
7162 wpas_p2p_group_formation_failed(wpa_s, 0);
7167 void wpas_p2p_pbc_overlap_cb(void *eloop_ctx, void *timeout_ctx)
7169 struct wpa_supplicant *wpa_s = eloop_ctx;
7170 wpas_p2p_notif_pbc_overlap(wpa_s);
7174 void wpas_p2p_update_channel_list(struct wpa_supplicant *wpa_s,
7175 enum wpas_p2p_channel_update_trig trig)
7177 struct p2p_channels chan, cli_chan;
7178 struct wpa_used_freq_data *freqs = NULL;
7179 unsigned int num = wpa_s->num_multichan_concurrent;
7181 if (wpa_s->global == NULL || wpa_s->global->p2p == NULL)
7184 freqs = os_calloc(num, sizeof(struct wpa_used_freq_data));
7188 num = get_shared_radio_freqs_data(wpa_s, freqs, num);
7190 os_memset(&chan, 0, sizeof(chan));
7191 os_memset(&cli_chan, 0, sizeof(cli_chan));
7192 if (wpas_p2p_setup_channels(wpa_s, &chan, &cli_chan)) {
7193 wpa_printf(MSG_ERROR, "P2P: Failed to update supported "
7198 p2p_update_channel_list(wpa_s->global->p2p, &chan, &cli_chan);
7200 wpas_p2p_optimize_listen_channel(wpa_s, freqs, num);
7203 * The used frequencies map changed, so it is possible that a GO is
7204 * using a channel that is no longer valid for P2P use. It is also
7205 * possible that due to policy consideration, it would be preferable to
7206 * move it to a frequency already used by other station interfaces.
7208 wpas_p2p_consider_moving_gos(wpa_s, freqs, num, trig);
7214 static void wpas_p2p_scan_res_ignore(struct wpa_supplicant *wpa_s,
7215 struct wpa_scan_results *scan_res)
7217 wpa_printf(MSG_DEBUG, "P2P: Ignore scan results");
7221 int wpas_p2p_cancel(struct wpa_supplicant *wpa_s)
7223 struct wpa_global *global = wpa_s->global;
7227 if (global->p2p == NULL)
7230 wpa_printf(MSG_DEBUG, "P2P: Request to cancel group formation");
7232 if (wpa_s->pending_interface_name[0] &&
7233 !is_zero_ether_addr(wpa_s->pending_interface_addr))
7236 peer = p2p_get_go_neg_peer(global->p2p);
7238 wpa_printf(MSG_DEBUG, "P2P: Unauthorize pending GO Neg peer "
7239 MACSTR, MAC2STR(peer));
7240 p2p_unauthorize(global->p2p, peer);
7244 if (wpa_s->scan_res_handler == wpas_p2p_scan_res_join) {
7245 wpa_printf(MSG_DEBUG, "P2P: Stop pending scan for join");
7246 wpa_s->scan_res_handler = wpas_p2p_scan_res_ignore;
7250 if (wpa_s->pending_pd_before_join) {
7251 wpa_printf(MSG_DEBUG, "P2P: Stop pending PD before join");
7252 wpa_s->pending_pd_before_join = 0;
7256 wpas_p2p_stop_find(wpa_s);
7258 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
7259 if (wpa_s == global->p2p_group_formation &&
7260 (wpa_s->p2p_in_provisioning ||
7261 wpa_s->parent->pending_interface_type ==
7262 WPA_IF_P2P_CLIENT)) {
7263 wpa_printf(MSG_DEBUG, "P2P: Interface %s in group "
7264 "formation found - cancelling",
7267 eloop_cancel_timeout(wpas_p2p_group_formation_timeout,
7268 wpa_s->parent, NULL);
7269 if (wpa_s->p2p_in_provisioning) {
7270 wpas_group_formation_completed(wpa_s, 0, 0);
7273 wpas_p2p_group_delete(wpa_s,
7274 P2P_GROUP_REMOVAL_REQUESTED);
7276 } else if (wpa_s->p2p_in_invitation) {
7277 wpa_printf(MSG_DEBUG, "P2P: Interface %s in invitation found - cancelling",
7280 wpas_p2p_group_formation_failed(wpa_s, 0);
7285 wpa_printf(MSG_DEBUG, "P2P: No ongoing group formation found");
7293 void wpas_p2p_interface_unavailable(struct wpa_supplicant *wpa_s)
7295 if (wpa_s->current_ssid == NULL || !wpa_s->current_ssid->p2p_group)
7298 wpa_printf(MSG_DEBUG, "P2P: Remove group due to driver resource not "
7299 "being available anymore");
7300 wpas_p2p_group_delete(wpa_s, P2P_GROUP_REMOVAL_UNAVAILABLE);
7304 void wpas_p2p_update_best_channels(struct wpa_supplicant *wpa_s,
7305 int freq_24, int freq_5, int freq_overall)
7307 struct p2p_data *p2p = wpa_s->global->p2p;
7310 p2p_set_best_channels(p2p, freq_24, freq_5, freq_overall);
7314 int wpas_p2p_unauthorize(struct wpa_supplicant *wpa_s, const char *addr)
7317 struct p2p_data *p2p = wpa_s->global->p2p;
7322 if (hwaddr_aton(addr, peer))
7325 return p2p_unauthorize(p2p, peer);
7330 * wpas_p2p_disconnect - Disconnect from a P2P Group
7331 * @wpa_s: Pointer to wpa_supplicant data
7332 * Returns: 0 on success, -1 on failure
7334 * This can be used to disconnect from a group in which the local end is a P2P
7335 * Client or to end a P2P Group in case the local end is the Group Owner. If a
7336 * virtual network interface was created for this group, that interface will be
7337 * removed. Otherwise, only the configured P2P group network will be removed
7338 * from the interface.
7340 int wpas_p2p_disconnect(struct wpa_supplicant *wpa_s)
7346 return wpas_p2p_group_delete(wpa_s, P2P_GROUP_REMOVAL_REQUESTED) < 0 ?
7351 int wpas_p2p_in_progress(struct wpa_supplicant *wpa_s)
7355 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
7358 ret = p2p_in_progress(wpa_s->global->p2p);
7361 * Check whether there is an ongoing WPS provisioning step (or
7362 * other parts of group formation) on another interface since
7363 * p2p_in_progress() does not report this to avoid issues for
7364 * scans during such provisioning step.
7366 if (wpa_s->global->p2p_group_formation &&
7367 wpa_s->global->p2p_group_formation != wpa_s) {
7368 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Another interface (%s) "
7369 "in group formation",
7370 wpa_s->global->p2p_group_formation->ifname);
7375 if (!ret && wpa_s->global->p2p_go_wait_client.sec) {
7376 struct os_reltime now;
7377 os_get_reltime(&now);
7378 if (os_reltime_expired(&now, &wpa_s->global->p2p_go_wait_client,
7379 P2P_MAX_INITIAL_CONN_WAIT_GO)) {
7380 /* Wait for the first client has expired */
7381 wpa_s->global->p2p_go_wait_client.sec = 0;
7383 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Waiting for initial client connection during group formation");
7392 void wpas_p2p_network_removed(struct wpa_supplicant *wpa_s,
7393 struct wpa_ssid *ssid)
7395 if (wpa_s->p2p_in_provisioning && ssid->p2p_group &&
7396 eloop_cancel_timeout(wpas_p2p_group_formation_timeout,
7397 wpa_s->parent, NULL) > 0) {
7399 * Remove the network by scheduling the group formation
7400 * timeout to happen immediately. The teardown code
7401 * needs to be scheduled to run asynch later so that we
7402 * don't delete data from under ourselves unexpectedly.
7403 * Calling wpas_p2p_group_formation_timeout directly
7404 * causes a series of crashes in WPS failure scenarios.
7406 wpa_printf(MSG_DEBUG, "P2P: Canceled group formation due to "
7407 "P2P group network getting removed");
7408 eloop_register_timeout(0, 0, wpas_p2p_group_formation_timeout,
7409 wpa_s->parent, NULL);
7414 struct wpa_ssid * wpas_p2p_get_persistent(struct wpa_supplicant *wpa_s,
7415 const u8 *addr, const u8 *ssid,
7421 for (s = wpa_s->conf->ssid; s; s = s->next) {
7422 if (s->disabled != 2)
7425 (ssid_len != s->ssid_len ||
7426 os_memcmp(ssid, s->ssid, ssid_len) != 0))
7429 if (s->mode == WPAS_MODE_P2P_GO)
7433 if (os_memcmp(s->bssid, addr, ETH_ALEN) == 0)
7434 return s; /* peer is GO in the persistent group */
7435 if (s->mode != WPAS_MODE_P2P_GO || s->p2p_client_list == NULL)
7437 for (i = 0; i < s->num_p2p_clients; i++) {
7438 if (os_memcmp(s->p2p_client_list + i * 2 * ETH_ALEN,
7439 addr, ETH_ALEN) == 0)
7440 return s; /* peer is P2P client in persistent
7449 void wpas_p2p_notify_ap_sta_authorized(struct wpa_supplicant *wpa_s,
7452 if (eloop_cancel_timeout(wpas_p2p_group_formation_timeout,
7453 wpa_s->parent, NULL) > 0) {
7455 * This can happen if WPS provisioning step is not terminated
7456 * cleanly (e.g., P2P Client does not send WSC_Done). Since the
7457 * peer was able to connect, there is no need to time out group
7458 * formation after this, though. In addition, this is used with
7459 * the initial connection wait on the GO as a separate formation
7460 * timeout and as such, expected to be hit after the initial WPS
7461 * provisioning step.
7463 wpa_printf(MSG_DEBUG, "P2P: Canceled P2P group formation timeout on data connection");
7465 if (!wpa_s->p2p_go_group_formation_completed &&
7466 !wpa_s->group_formation_reported) {
7468 * GO has not yet notified group formation success since
7469 * the WPS step was not completed cleanly. Do that
7470 * notification now since the P2P Client was able to
7471 * connect and as such, must have received the
7472 * credential from the WPS step.
7474 if (wpa_s->global->p2p)
7475 p2p_wps_success_cb(wpa_s->global->p2p, addr);
7476 wpas_group_formation_completed(wpa_s, 1, 0);
7479 if (!wpa_s->p2p_go_group_formation_completed) {
7480 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Marking group formation completed on GO on first data connection");
7481 wpa_s->p2p_go_group_formation_completed = 1;
7482 wpa_s->global->p2p_group_formation = NULL;
7483 wpa_s->p2p_in_provisioning = 0;
7484 wpa_s->p2p_in_invitation = 0;
7486 wpa_s->global->p2p_go_wait_client.sec = 0;
7489 wpas_p2p_add_persistent_group_client(wpa_s, addr);
7493 static int wpas_p2p_fallback_to_go_neg(struct wpa_supplicant *wpa_s,
7496 struct wpa_supplicant *group = wpa_s;
7499 if (wpa_s->global->p2p_group_formation)
7500 group = wpa_s->global->p2p_group_formation;
7501 wpa_s = wpa_s->global->p2p_init_wpa_s;
7502 offchannel_send_action_done(wpa_s);
7504 ret = wpas_p2p_group_delete(group, P2P_GROUP_REMOVAL_SILENT);
7505 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Fall back to GO Negotiation");
7506 wpas_p2p_connect(wpa_s, wpa_s->pending_join_dev_addr, wpa_s->p2p_pin,
7507 wpa_s->p2p_wps_method, wpa_s->p2p_persistent_group, 0,
7508 0, 0, wpa_s->p2p_go_intent, wpa_s->p2p_connect_freq,
7509 wpa_s->p2p_persistent_id,
7510 wpa_s->p2p_pd_before_go_neg,
7517 int wpas_p2p_scan_no_go_seen(struct wpa_supplicant *wpa_s)
7521 if (!wpa_s->p2p_fallback_to_go_neg ||
7522 wpa_s->p2p_in_provisioning <= 5)
7525 if (wpas_p2p_peer_go(wpa_s, wpa_s->pending_join_dev_addr) > 0)
7526 return 0; /* peer operating as a GO */
7528 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: GO not found for p2p_connect-auto - "
7529 "fallback to GO Negotiation");
7530 wpa_msg_global(wpa_s->parent, MSG_INFO, P2P_EVENT_FALLBACK_TO_GO_NEG
7531 "reason=GO-not-found");
7532 res = wpas_p2p_fallback_to_go_neg(wpa_s, 1);
7534 return res == 1 ? 2 : 1;
7538 unsigned int wpas_p2p_search_delay(struct wpa_supplicant *wpa_s)
7540 struct wpa_supplicant *ifs;
7542 if (wpa_s->wpa_state > WPA_SCANNING) {
7543 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Use %u ms search delay due to "
7544 "concurrent operation",
7545 wpa_s->conf->p2p_search_delay);
7546 return wpa_s->conf->p2p_search_delay;
7549 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
7551 if (ifs != wpa_s && ifs->wpa_state > WPA_SCANNING) {
7552 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Use %u ms search "
7553 "delay due to concurrent operation on "
7555 wpa_s->conf->p2p_search_delay,
7557 return wpa_s->conf->p2p_search_delay;
7565 static int wpas_p2p_remove_psk_entry(struct wpa_supplicant *wpa_s,
7566 struct wpa_ssid *s, const u8 *addr,
7569 struct psk_list_entry *psk, *tmp;
7572 dl_list_for_each_safe(psk, tmp, &s->psk_list, struct psk_list_entry,
7574 if ((iface_addr && !psk->p2p &&
7575 os_memcmp(addr, psk->addr, ETH_ALEN) == 0) ||
7576 (!iface_addr && psk->p2p &&
7577 os_memcmp(addr, psk->addr, ETH_ALEN) == 0)) {
7578 wpa_dbg(wpa_s, MSG_DEBUG,
7579 "P2P: Remove persistent group PSK list entry for "
7581 MAC2STR(psk->addr), psk->p2p);
7582 dl_list_del(&psk->list);
7592 void wpas_p2p_new_psk_cb(struct wpa_supplicant *wpa_s, const u8 *mac_addr,
7593 const u8 *p2p_dev_addr,
7594 const u8 *psk, size_t psk_len)
7596 struct wpa_ssid *ssid = wpa_s->current_ssid;
7597 struct wpa_ssid *persistent;
7598 struct psk_list_entry *p, *last;
7600 if (psk_len != sizeof(p->psk))
7604 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: New PSK for addr=" MACSTR
7605 " p2p_dev_addr=" MACSTR,
7606 MAC2STR(mac_addr), MAC2STR(p2p_dev_addr));
7607 if (is_zero_ether_addr(p2p_dev_addr))
7608 p2p_dev_addr = NULL;
7610 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: New PSK for addr=" MACSTR,
7614 if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION) {
7615 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: new_psk_cb during group formation");
7616 /* To be added to persistent group once created */
7617 if (wpa_s->global->add_psk == NULL) {
7618 wpa_s->global->add_psk = os_zalloc(sizeof(*p));
7619 if (wpa_s->global->add_psk == NULL)
7622 p = wpa_s->global->add_psk;
7625 os_memcpy(p->addr, p2p_dev_addr, ETH_ALEN);
7628 os_memcpy(p->addr, mac_addr, ETH_ALEN);
7630 os_memcpy(p->psk, psk, psk_len);
7634 if (ssid->mode != WPAS_MODE_P2P_GO || !ssid->p2p_persistent_group) {
7635 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Ignore new_psk_cb on not-persistent GO");
7639 persistent = wpas_p2p_get_persistent(wpa_s->parent, NULL, ssid->ssid,
7642 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Could not find persistent group information to store the new PSK");
7646 p = os_zalloc(sizeof(*p));
7651 os_memcpy(p->addr, p2p_dev_addr, ETH_ALEN);
7654 os_memcpy(p->addr, mac_addr, ETH_ALEN);
7656 os_memcpy(p->psk, psk, psk_len);
7658 if (dl_list_len(&persistent->psk_list) > P2P_MAX_STORED_CLIENTS &&
7659 (last = dl_list_last(&persistent->psk_list,
7660 struct psk_list_entry, list))) {
7661 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Remove oldest PSK entry for "
7662 MACSTR " (p2p=%u) to make room for a new one",
7663 MAC2STR(last->addr), last->p2p);
7664 dl_list_del(&last->list);
7668 wpas_p2p_remove_psk_entry(wpa_s->parent, persistent,
7669 p2p_dev_addr ? p2p_dev_addr : mac_addr,
7670 p2p_dev_addr == NULL);
7672 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Add new PSK for p2p_dev_addr="
7673 MACSTR, MAC2STR(p2p_dev_addr));
7675 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Add new PSK for addr=" MACSTR,
7678 dl_list_add(&persistent->psk_list, &p->list);
7680 if (wpa_s->parent->conf->update_config &&
7681 wpa_config_write(wpa_s->parent->confname, wpa_s->parent->conf))
7682 wpa_printf(MSG_DEBUG, "P2P: Failed to update configuration");
7686 static void wpas_p2p_remove_psk(struct wpa_supplicant *wpa_s,
7687 struct wpa_ssid *s, const u8 *addr,
7692 res = wpas_p2p_remove_psk_entry(wpa_s, s, addr, iface_addr);
7693 if (res > 0 && wpa_s->conf->update_config &&
7694 wpa_config_write(wpa_s->confname, wpa_s->conf))
7695 wpa_dbg(wpa_s, MSG_DEBUG,
7696 "P2P: Failed to update configuration");
7700 static void wpas_p2p_remove_client_go(struct wpa_supplicant *wpa_s,
7701 const u8 *peer, int iface_addr)
7703 struct hostapd_data *hapd;
7704 struct hostapd_wpa_psk *psk, *prev, *rem;
7705 struct sta_info *sta;
7707 if (wpa_s->ap_iface == NULL || wpa_s->current_ssid == NULL ||
7708 wpa_s->current_ssid->mode != WPAS_MODE_P2P_GO)
7711 /* Remove per-station PSK entry */
7712 hapd = wpa_s->ap_iface->bss[0];
7714 psk = hapd->conf->ssid.wpa_psk;
7716 if ((iface_addr && os_memcmp(peer, psk->addr, ETH_ALEN) == 0) ||
7718 os_memcmp(peer, psk->p2p_dev_addr, ETH_ALEN) == 0)) {
7719 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Remove operating group PSK entry for "
7720 MACSTR " iface_addr=%d",
7721 MAC2STR(peer), iface_addr);
7723 prev->next = psk->next;
7725 hapd->conf->ssid.wpa_psk = psk->next;
7735 /* Disconnect from group */
7737 sta = ap_get_sta(hapd, peer);
7739 sta = ap_get_sta_p2p(hapd, peer);
7741 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Disconnect peer " MACSTR
7742 " (iface_addr=%d) from group",
7743 MAC2STR(peer), iface_addr);
7744 hostapd_drv_sta_deauth(hapd, sta->addr,
7745 WLAN_REASON_DEAUTH_LEAVING);
7746 ap_sta_deauthenticate(hapd, sta, WLAN_REASON_DEAUTH_LEAVING);
7751 void wpas_p2p_remove_client(struct wpa_supplicant *wpa_s, const u8 *peer,
7755 struct wpa_supplicant *w;
7756 struct wpa_supplicant *p2p_wpa_s = wpa_s->global->p2p_init_wpa_s;
7758 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Remove client " MACSTR, MAC2STR(peer));
7760 /* Remove from any persistent group */
7761 for (s = p2p_wpa_s->conf->ssid; s; s = s->next) {
7762 if (s->disabled != 2 || s->mode != WPAS_MODE_P2P_GO)
7765 wpas_remove_persistent_peer(p2p_wpa_s, s, peer, 0);
7766 wpas_p2p_remove_psk(p2p_wpa_s, s, peer, iface_addr);
7769 /* Remove from any operating group */
7770 for (w = wpa_s->global->ifaces; w; w = w->next)
7771 wpas_p2p_remove_client_go(w, peer, iface_addr);
7775 static void wpas_p2p_psk_failure_removal(void *eloop_ctx, void *timeout_ctx)
7777 struct wpa_supplicant *wpa_s = eloop_ctx;
7778 wpas_p2p_group_delete(wpa_s, P2P_GROUP_REMOVAL_PSK_FAILURE);
7782 static void wpas_p2p_group_freq_conflict(void *eloop_ctx, void *timeout_ctx)
7784 struct wpa_supplicant *wpa_s = eloop_ctx;
7786 wpa_printf(MSG_DEBUG, "P2P: Frequency conflict - terminate group");
7787 wpas_p2p_group_delete(wpa_s, P2P_GROUP_REMOVAL_FREQ_CONFLICT);
7791 int wpas_p2p_handle_frequency_conflicts(struct wpa_supplicant *wpa_s, int freq,
7792 struct wpa_ssid *ssid)
7794 struct wpa_supplicant *iface;
7796 for (iface = wpa_s->global->ifaces; iface; iface = iface->next) {
7797 if (!iface->current_ssid ||
7798 iface->current_ssid->frequency == freq ||
7799 (iface->p2p_group_interface == NOT_P2P_GROUP_INTERFACE &&
7800 !iface->current_ssid->p2p_group))
7803 /* Remove the connection with least priority */
7804 if (!wpas_is_p2p_prioritized(iface)) {
7805 /* STA connection has priority over existing
7806 * P2P connection, so remove the interface. */
7807 wpa_printf(MSG_DEBUG, "P2P: Removing P2P connection due to single channel concurrent mode frequency conflict");
7808 eloop_register_timeout(0, 0,
7809 wpas_p2p_group_freq_conflict,
7811 /* If connection in progress is P2P connection, do not
7812 * proceed for the connection. */
7818 /* P2P connection has priority, disable the STA network
7820 wpa_supplicant_disable_network(wpa_s->global->ifaces,
7822 wpa_msg(wpa_s->global->ifaces, MSG_INFO,
7823 WPA_EVENT_FREQ_CONFLICT " id=%d", ssid->id);
7824 os_memset(wpa_s->global->ifaces->pending_bssid, 0,
7826 /* If P2P connection is in progress, continue
7839 int wpas_p2p_4way_hs_failed(struct wpa_supplicant *wpa_s)
7841 struct wpa_ssid *ssid = wpa_s->current_ssid;
7843 if (ssid == NULL || !ssid->p2p_group)
7846 if (wpa_s->p2p_last_4way_hs_fail &&
7847 wpa_s->p2p_last_4way_hs_fail == ssid) {
7848 u8 go_dev_addr[ETH_ALEN];
7849 struct wpa_ssid *persistent;
7851 if (wpas_p2p_persistent_group(wpa_s, go_dev_addr,
7853 ssid->ssid_len) <= 0) {
7854 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Could not determine whether 4-way handshake failures were for a persistent group");
7858 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Two 4-way handshake failures for a P2P group - go_dev_addr="
7859 MACSTR, MAC2STR(go_dev_addr));
7860 persistent = wpas_p2p_get_persistent(wpa_s->parent, go_dev_addr,
7863 if (persistent == NULL || persistent->mode != WPAS_MODE_INFRA) {
7864 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: No matching persistent group stored");
7867 wpa_msg_global(wpa_s->parent, MSG_INFO,
7868 P2P_EVENT_PERSISTENT_PSK_FAIL "%d",
7871 wpa_s->p2p_last_4way_hs_fail = NULL;
7873 * Remove the group from a timeout to avoid issues with caller
7874 * continuing to use the interface if this is on a P2P group
7877 eloop_register_timeout(0, 0, wpas_p2p_psk_failure_removal,
7882 wpa_s->p2p_last_4way_hs_fail = ssid;
7887 #ifdef CONFIG_WPS_NFC
7889 static struct wpabuf * wpas_p2p_nfc_handover(int ndef, struct wpabuf *wsc,
7897 wpa_printf(MSG_DEBUG, "P2P: No p2p buffer for handover");
7901 wsc_len = wsc ? wpabuf_len(wsc) : 0;
7902 ret = wpabuf_alloc(2 + wsc_len + 2 + wpabuf_len(p2p));
7909 wpabuf_put_be16(ret, wsc_len);
7911 wpabuf_put_buf(ret, wsc);
7912 wpabuf_put_be16(ret, wpabuf_len(p2p));
7913 wpabuf_put_buf(ret, p2p);
7917 wpa_hexdump_buf(MSG_DEBUG,
7918 "P2P: Generated NFC connection handover message", ret);
7922 tmp = ndef_build_p2p(ret);
7925 wpa_printf(MSG_DEBUG, "P2P: Failed to NDEF encapsulate handover request");
7935 static int wpas_p2p_cli_freq(struct wpa_supplicant *wpa_s,
7936 struct wpa_ssid **ssid, u8 *go_dev_addr)
7938 struct wpa_supplicant *iface;
7941 os_memset(go_dev_addr, 0, ETH_ALEN);
7944 for (iface = wpa_s->global->ifaces; iface; iface = iface->next) {
7945 if (iface->wpa_state < WPA_ASSOCIATING ||
7946 iface->current_ssid == NULL || iface->assoc_freq == 0 ||
7947 !iface->current_ssid->p2p_group ||
7948 iface->current_ssid->mode != WPAS_MODE_INFRA)
7951 *ssid = iface->current_ssid;
7953 os_memcpy(go_dev_addr, iface->go_dev_addr, ETH_ALEN);
7954 return iface->assoc_freq;
7960 struct wpabuf * wpas_p2p_nfc_handover_req(struct wpa_supplicant *wpa_s,
7963 struct wpabuf *wsc, *p2p;
7964 struct wpa_ssid *ssid;
7965 u8 go_dev_addr[ETH_ALEN];
7966 int cli_freq = wpas_p2p_cli_freq(wpa_s, &ssid, go_dev_addr);
7968 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) {
7969 wpa_printf(MSG_DEBUG, "P2P: P2P disabled - cannot build handover request");
7973 if (wpa_s->conf->wps_nfc_dh_pubkey == NULL &&
7974 wps_nfc_gen_dh(&wpa_s->conf->wps_nfc_dh_pubkey,
7975 &wpa_s->conf->wps_nfc_dh_privkey) < 0) {
7976 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: No DH key available for handover request");
7980 if (cli_freq == 0) {
7981 wsc = wps_build_nfc_handover_req_p2p(
7982 wpa_s->parent->wps, wpa_s->conf->wps_nfc_dh_pubkey);
7985 p2p = p2p_build_nfc_handover_req(wpa_s->global->p2p, cli_freq,
7986 go_dev_addr, ssid ? ssid->ssid : NULL,
7987 ssid ? ssid->ssid_len : 0);
7989 return wpas_p2p_nfc_handover(ndef, wsc, p2p);
7993 struct wpabuf * wpas_p2p_nfc_handover_sel(struct wpa_supplicant *wpa_s,
7996 struct wpabuf *wsc, *p2p;
7997 struct wpa_ssid *ssid;
7998 u8 go_dev_addr[ETH_ALEN];
7999 int cli_freq = wpas_p2p_cli_freq(wpa_s, &ssid, go_dev_addr);
8001 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
8004 if (!tag && wpa_s->conf->wps_nfc_dh_pubkey == NULL &&
8005 wps_nfc_gen_dh(&wpa_s->conf->wps_nfc_dh_pubkey,
8006 &wpa_s->conf->wps_nfc_dh_privkey) < 0)
8009 if (cli_freq == 0) {
8010 wsc = wps_build_nfc_handover_sel_p2p(
8012 tag ? wpa_s->conf->wps_nfc_dev_pw_id :
8013 DEV_PW_NFC_CONNECTION_HANDOVER,
8014 wpa_s->conf->wps_nfc_dh_pubkey,
8015 tag ? wpa_s->conf->wps_nfc_dev_pw : NULL);
8018 p2p = p2p_build_nfc_handover_sel(wpa_s->global->p2p, cli_freq,
8019 go_dev_addr, ssid ? ssid->ssid : NULL,
8020 ssid ? ssid->ssid_len : 0);
8022 return wpas_p2p_nfc_handover(ndef, wsc, p2p);
8026 static int wpas_p2p_nfc_join_group(struct wpa_supplicant *wpa_s,
8027 struct p2p_nfc_params *params)
8029 wpa_printf(MSG_DEBUG, "P2P: Initiate join-group based on NFC "
8030 "connection handover (freq=%d)",
8033 if (params->go_freq && params->go_ssid_len) {
8034 wpa_s->p2p_wps_method = WPS_NFC;
8035 wpa_s->pending_join_wps_method = WPS_NFC;
8036 os_memset(wpa_s->pending_join_iface_addr, 0, ETH_ALEN);
8037 os_memcpy(wpa_s->pending_join_dev_addr, params->go_dev_addr,
8039 return wpas_p2p_join_start(wpa_s, params->go_freq,
8041 params->go_ssid_len);
8044 return wpas_p2p_connect(wpa_s, params->peer->p2p_device_addr, NULL,
8045 WPS_NFC, 0, 0, 1, 0, wpa_s->conf->p2p_go_intent,
8046 params->go_freq, -1, 0, 1, 1);
8050 static int wpas_p2p_nfc_auth_join(struct wpa_supplicant *wpa_s,
8051 struct p2p_nfc_params *params, int tag)
8053 int res, persistent;
8054 struct wpa_ssid *ssid;
8056 wpa_printf(MSG_DEBUG, "P2P: Authorize join-group based on NFC "
8057 "connection handover");
8058 for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) {
8059 ssid = wpa_s->current_ssid;
8062 if (ssid->mode != WPAS_MODE_P2P_GO)
8064 if (wpa_s->ap_iface == NULL)
8068 if (wpa_s == NULL) {
8069 wpa_printf(MSG_DEBUG, "P2P: Could not find GO interface");
8073 if (wpa_s->parent->p2p_oob_dev_pw_id !=
8074 DEV_PW_NFC_CONNECTION_HANDOVER &&
8075 !wpa_s->parent->p2p_oob_dev_pw) {
8076 wpa_printf(MSG_DEBUG, "P2P: No NFC Dev Pw known");
8079 res = wpas_ap_wps_add_nfc_pw(
8080 wpa_s, wpa_s->parent->p2p_oob_dev_pw_id,
8081 wpa_s->parent->p2p_oob_dev_pw,
8082 wpa_s->parent->p2p_peer_oob_pk_hash_known ?
8083 wpa_s->parent->p2p_peer_oob_pubkey_hash : NULL);
8088 wpa_printf(MSG_DEBUG, "P2P: Negotiated handover - wait for peer to join without invitation");
8092 if (!params->peer ||
8093 !(params->peer->dev_capab & P2P_DEV_CAPAB_INVITATION_PROCEDURE))
8096 wpa_printf(MSG_DEBUG, "P2P: Static handover - invite peer " MACSTR
8097 " to join", MAC2STR(params->peer->p2p_device_addr));
8099 wpa_s->global->p2p_invite_group = wpa_s;
8100 persistent = ssid->p2p_persistent_group &&
8101 wpas_p2p_get_persistent(wpa_s->parent,
8102 params->peer->p2p_device_addr,
8103 ssid->ssid, ssid->ssid_len);
8104 wpa_s->parent->pending_invite_ssid_id = -1;
8106 return p2p_invite(wpa_s->global->p2p, params->peer->p2p_device_addr,
8107 P2P_INVITE_ROLE_ACTIVE_GO, wpa_s->own_addr,
8108 ssid->ssid, ssid->ssid_len, ssid->frequency,
8109 wpa_s->global->p2p_dev_addr, persistent, 0,
8110 wpa_s->parent->p2p_oob_dev_pw_id);
8114 static int wpas_p2p_nfc_init_go_neg(struct wpa_supplicant *wpa_s,
8115 struct p2p_nfc_params *params,
8118 wpa_printf(MSG_DEBUG, "P2P: Initiate GO Negotiation based on NFC "
8119 "connection handover");
8120 return wpas_p2p_connect(wpa_s, params->peer->p2p_device_addr, NULL,
8121 WPS_NFC, 0, 0, 0, 0, wpa_s->conf->p2p_go_intent,
8122 forced_freq, -1, 0, 1, 1);
8126 static int wpas_p2p_nfc_resp_go_neg(struct wpa_supplicant *wpa_s,
8127 struct p2p_nfc_params *params,
8132 wpa_printf(MSG_DEBUG, "P2P: Authorize GO Negotiation based on NFC "
8133 "connection handover");
8134 res = wpas_p2p_connect(wpa_s, params->peer->p2p_device_addr, NULL,
8135 WPS_NFC, 0, 0, 0, 1, wpa_s->conf->p2p_go_intent,
8136 forced_freq, -1, 0, 1, 1);
8140 res = wpas_p2p_listen(wpa_s, 60);
8142 p2p_unauthorize(wpa_s->global->p2p,
8143 params->peer->p2p_device_addr);
8150 static int wpas_p2p_nfc_connection_handover(struct wpa_supplicant *wpa_s,
8151 const struct wpabuf *data,
8152 int sel, int tag, int forced_freq)
8154 const u8 *pos, *end;
8156 struct p2p_nfc_params params;
8159 os_memset(¶ms, 0, sizeof(params));
8162 wpa_hexdump_buf(MSG_DEBUG, "P2P: Received NFC tag payload", data);
8164 pos = wpabuf_head(data);
8165 end = pos + wpabuf_len(data);
8167 if (end - pos < 2) {
8168 wpa_printf(MSG_DEBUG, "P2P: Not enough data for Length of WSC "
8172 len = WPA_GET_BE16(pos);
8174 if (len > end - pos) {
8175 wpa_printf(MSG_DEBUG, "P2P: Not enough data for WSC "
8179 params.wsc_attr = pos;
8180 params.wsc_len = len;
8183 if (end - pos < 2) {
8184 wpa_printf(MSG_DEBUG, "P2P: Not enough data for Length of P2P "
8188 len = WPA_GET_BE16(pos);
8190 if (len > end - pos) {
8191 wpa_printf(MSG_DEBUG, "P2P: Not enough data for P2P "
8195 params.p2p_attr = pos;
8196 params.p2p_len = len;
8199 wpa_hexdump(MSG_DEBUG, "P2P: WSC attributes",
8200 params.wsc_attr, params.wsc_len);
8201 wpa_hexdump(MSG_DEBUG, "P2P: P2P attributes",
8202 params.p2p_attr, params.p2p_len);
8204 wpa_hexdump(MSG_DEBUG,
8205 "P2P: Ignored extra data after P2P attributes",
8209 res = p2p_process_nfc_connection_handover(wpa_s->global->p2p, ¶ms);
8213 if (params.next_step == NO_ACTION)
8216 if (params.next_step == BOTH_GO) {
8217 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_NFC_BOTH_GO "peer=" MACSTR,
8218 MAC2STR(params.peer->p2p_device_addr));
8222 if (params.next_step == PEER_CLIENT) {
8223 if (!is_zero_ether_addr(params.go_dev_addr)) {
8224 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_NFC_PEER_CLIENT
8225 "peer=" MACSTR " freq=%d go_dev_addr=" MACSTR
8227 MAC2STR(params.peer->p2p_device_addr),
8229 MAC2STR(params.go_dev_addr),
8230 wpa_ssid_txt(params.go_ssid,
8231 params.go_ssid_len));
8233 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_NFC_PEER_CLIENT
8234 "peer=" MACSTR " freq=%d",
8235 MAC2STR(params.peer->p2p_device_addr),
8241 if (wpas_p2p_cli_freq(wpa_s, NULL, NULL)) {
8242 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_NFC_WHILE_CLIENT "peer="
8243 MACSTR, MAC2STR(params.peer->p2p_device_addr));
8247 wpabuf_free(wpa_s->p2p_oob_dev_pw);
8248 wpa_s->p2p_oob_dev_pw = NULL;
8250 if (params.oob_dev_pw_len < WPS_OOB_PUBKEY_HASH_LEN + 2) {
8251 wpa_printf(MSG_DEBUG, "P2P: No peer OOB Dev Pw "
8256 id = WPA_GET_BE16(params.oob_dev_pw + WPS_OOB_PUBKEY_HASH_LEN);
8257 wpa_printf(MSG_DEBUG, "P2P: Peer OOB Dev Pw %u", id);
8258 wpa_hexdump(MSG_DEBUG, "P2P: Peer OOB Public Key hash",
8259 params.oob_dev_pw, WPS_OOB_PUBKEY_HASH_LEN);
8260 os_memcpy(wpa_s->p2p_peer_oob_pubkey_hash,
8261 params.oob_dev_pw, WPS_OOB_PUBKEY_HASH_LEN);
8262 wpa_s->p2p_peer_oob_pk_hash_known = 1;
8266 wpa_printf(MSG_DEBUG, "P2P: Static handover - invalid "
8267 "peer OOB Device Password Id %u", id);
8270 wpa_printf(MSG_DEBUG, "P2P: Static handover - use peer OOB "
8271 "Device Password Id %u", id);
8272 wpa_hexdump_key(MSG_DEBUG, "P2P: Peer OOB Device Password",
8273 params.oob_dev_pw + WPS_OOB_PUBKEY_HASH_LEN + 2,
8274 params.oob_dev_pw_len -
8275 WPS_OOB_PUBKEY_HASH_LEN - 2);
8276 wpa_s->p2p_oob_dev_pw_id = id;
8277 wpa_s->p2p_oob_dev_pw = wpabuf_alloc_copy(
8278 params.oob_dev_pw + WPS_OOB_PUBKEY_HASH_LEN + 2,
8279 params.oob_dev_pw_len -
8280 WPS_OOB_PUBKEY_HASH_LEN - 2);
8281 if (wpa_s->p2p_oob_dev_pw == NULL)
8284 if (wpa_s->conf->wps_nfc_dh_pubkey == NULL &&
8285 wps_nfc_gen_dh(&wpa_s->conf->wps_nfc_dh_pubkey,
8286 &wpa_s->conf->wps_nfc_dh_privkey) < 0)
8289 wpa_printf(MSG_DEBUG, "P2P: Using abbreviated WPS handshake "
8290 "without Device Password");
8291 wpa_s->p2p_oob_dev_pw_id = DEV_PW_NFC_CONNECTION_HANDOVER;
8294 switch (params.next_step) {
8298 /* already covered above */
8301 return wpas_p2p_nfc_join_group(wpa_s, ¶ms);
8303 return wpas_p2p_nfc_auth_join(wpa_s, ¶ms, tag);
8305 return wpas_p2p_nfc_init_go_neg(wpa_s, ¶ms, forced_freq);
8307 /* TODO: use own OOB Dev Pw */
8308 return wpas_p2p_nfc_resp_go_neg(wpa_s, ¶ms, forced_freq);
8315 int wpas_p2p_nfc_tag_process(struct wpa_supplicant *wpa_s,
8316 const struct wpabuf *data, int forced_freq)
8318 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
8321 return wpas_p2p_nfc_connection_handover(wpa_s, data, 1, 1, forced_freq);
8325 int wpas_p2p_nfc_report_handover(struct wpa_supplicant *wpa_s, int init,
8326 const struct wpabuf *req,
8327 const struct wpabuf *sel, int forced_freq)
8332 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
8335 wpa_printf(MSG_DEBUG, "NFC: P2P connection handover reported");
8337 wpa_hexdump_ascii(MSG_DEBUG, "NFC: Req",
8338 wpabuf_head(req), wpabuf_len(req));
8339 wpa_hexdump_ascii(MSG_DEBUG, "NFC: Sel",
8340 wpabuf_head(sel), wpabuf_len(sel));
8342 wpa_printf(MSG_DEBUG, "NFC: Forced freq %d", forced_freq);
8343 tmp = ndef_parse_p2p(init ? sel : req);
8345 wpa_printf(MSG_DEBUG, "P2P: Could not parse NDEF");
8349 ret = wpas_p2p_nfc_connection_handover(wpa_s, tmp, init, 0,
8357 int wpas_p2p_nfc_tag_enabled(struct wpa_supplicant *wpa_s, int enabled)
8360 int go_intent = wpa_s->conf->p2p_go_intent;
8361 struct wpa_supplicant *iface;
8363 if (wpa_s->global->p2p == NULL)
8367 wpa_printf(MSG_DEBUG, "P2P: Disable use of own NFC Tag");
8368 for (iface = wpa_s->global->ifaces; iface; iface = iface->next)
8370 if (!iface->ap_iface)
8372 hostapd_wps_nfc_token_disable(iface->ap_iface->bss[0]);
8374 p2p_set_authorized_oob_dev_pw_id(wpa_s->global->p2p, 0,
8376 if (wpa_s->p2p_nfc_tag_enabled)
8377 wpas_p2p_remove_pending_group_interface(wpa_s);
8378 wpa_s->p2p_nfc_tag_enabled = 0;
8382 if (wpa_s->global->p2p_disabled)
8385 if (wpa_s->conf->wps_nfc_dh_pubkey == NULL ||
8386 wpa_s->conf->wps_nfc_dh_privkey == NULL ||
8387 wpa_s->conf->wps_nfc_dev_pw == NULL ||
8388 wpa_s->conf->wps_nfc_dev_pw_id < 0x10) {
8389 wpa_printf(MSG_DEBUG, "P2P: NFC password token not configured "
8390 "to allow static handover cases");
8394 wpa_printf(MSG_DEBUG, "P2P: Enable use of own NFC Tag");
8396 wpa_s->p2p_oob_dev_pw_id = wpa_s->conf->wps_nfc_dev_pw_id;
8397 wpabuf_free(wpa_s->p2p_oob_dev_pw);
8398 wpa_s->p2p_oob_dev_pw = wpabuf_dup(wpa_s->conf->wps_nfc_dev_pw);
8399 if (wpa_s->p2p_oob_dev_pw == NULL)
8401 wpa_s->p2p_peer_oob_pk_hash_known = 0;
8403 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
8404 wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT) {
8406 * P2P Group Interface present and the command came on group
8407 * interface, so enable the token for the current interface.
8409 wpa_s->create_p2p_iface = 0;
8411 wpa_s->create_p2p_iface = wpas_p2p_create_iface(wpa_s);
8414 if (wpa_s->create_p2p_iface) {
8415 enum wpa_driver_if_type iftype;
8416 /* Prepare to add a new interface for the group */
8417 iftype = WPA_IF_P2P_GROUP;
8418 if (go_intent == 15)
8419 iftype = WPA_IF_P2P_GO;
8420 if (wpas_p2p_add_group_interface(wpa_s, iftype) < 0) {
8421 wpa_printf(MSG_ERROR, "P2P: Failed to allocate a new "
8422 "interface for the group");
8426 if_addr = wpa_s->pending_interface_addr;
8428 if_addr = wpa_s->own_addr;
8430 wpa_s->p2p_nfc_tag_enabled = enabled;
8432 for (iface = wpa_s->global->ifaces; iface; iface = iface->next) {
8433 struct hostapd_data *hapd;
8434 if (iface->ap_iface == NULL)
8436 hapd = iface->ap_iface->bss[0];
8437 wpabuf_free(hapd->conf->wps_nfc_dh_pubkey);
8438 hapd->conf->wps_nfc_dh_pubkey =
8439 wpabuf_dup(wpa_s->conf->wps_nfc_dh_pubkey);
8440 wpabuf_free(hapd->conf->wps_nfc_dh_privkey);
8441 hapd->conf->wps_nfc_dh_privkey =
8442 wpabuf_dup(wpa_s->conf->wps_nfc_dh_privkey);
8443 wpabuf_free(hapd->conf->wps_nfc_dev_pw);
8444 hapd->conf->wps_nfc_dev_pw =
8445 wpabuf_dup(wpa_s->conf->wps_nfc_dev_pw);
8446 hapd->conf->wps_nfc_dev_pw_id = wpa_s->conf->wps_nfc_dev_pw_id;
8448 if (hostapd_wps_nfc_token_enable(iface->ap_iface->bss[0]) < 0) {
8449 wpa_dbg(iface, MSG_DEBUG,
8450 "P2P: Failed to enable NFC Tag for GO");
8453 p2p_set_authorized_oob_dev_pw_id(
8454 wpa_s->global->p2p, wpa_s->conf->wps_nfc_dev_pw_id, go_intent,
8460 #endif /* CONFIG_WPS_NFC */
8463 static void wpas_p2p_optimize_listen_channel(struct wpa_supplicant *wpa_s,
8464 struct wpa_used_freq_data *freqs,
8467 u8 curr_chan, cand, chan;
8471 * If possible, optimize the Listen channel to be a channel that is
8472 * already used by one of the other interfaces.
8474 if (!wpa_s->conf->p2p_optimize_listen_chan)
8477 if (!wpa_s->current_ssid || wpa_s->wpa_state != WPA_COMPLETED)
8480 curr_chan = p2p_get_listen_channel(wpa_s->global->p2p);
8481 for (i = 0, cand = 0; i < num; i++) {
8482 ieee80211_freq_to_chan(freqs[i].freq, &chan);
8483 if (curr_chan == chan) {
8488 if (chan == 1 || chan == 6 || chan == 11)
8493 wpa_dbg(wpa_s, MSG_DEBUG,
8494 "P2P: Update Listen channel to %u based on operating channel",
8496 p2p_set_listen_channel(wpa_s->global->p2p, 81, cand, 0);
8501 static int wpas_p2p_move_go_csa(struct wpa_supplicant *wpa_s)
8503 struct hostapd_config *conf;
8504 struct p2p_go_neg_results params;
8505 struct csa_settings csa_settings;
8506 struct wpa_ssid *current_ssid = wpa_s->current_ssid;
8507 int old_freq = current_ssid->frequency;
8511 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP_CSA)) {
8512 wpa_dbg(wpa_s, MSG_DEBUG, "CSA is not enabled");
8517 * TODO: This function may not always work correctly. For example,
8518 * when we have a running GO and a BSS on a DFS channel.
8520 if (wpas_p2p_init_go_params(wpa_s, ¶ms, 0, 0, 0, NULL)) {
8521 wpa_dbg(wpa_s, MSG_DEBUG,
8522 "P2P CSA: Failed to select new frequency for GO");
8526 if (current_ssid->frequency == params.freq) {
8527 wpa_dbg(wpa_s, MSG_DEBUG,
8528 "P2P CSA: Selected same frequency - not moving GO");
8532 conf = hostapd_config_defaults();
8534 wpa_dbg(wpa_s, MSG_DEBUG,
8535 "P2P CSA: Failed to allocate default config");
8539 current_ssid->frequency = params.freq;
8540 if (wpa_supplicant_conf_ap_ht(wpa_s, current_ssid, conf)) {
8541 wpa_dbg(wpa_s, MSG_DEBUG,
8542 "P2P CSA: Failed to create new GO config");
8547 if (conf->hw_mode != wpa_s->ap_iface->current_mode->mode) {
8548 wpa_dbg(wpa_s, MSG_DEBUG,
8549 "P2P CSA: CSA to a different band is not supported");
8554 os_memset(&csa_settings, 0, sizeof(csa_settings));
8555 csa_settings.cs_count = P2P_GO_CSA_COUNT;
8556 csa_settings.block_tx = P2P_GO_CSA_BLOCK_TX;
8557 csa_settings.freq_params.freq = params.freq;
8559 if (ieee80211_freq_to_channel_ext(params.freq, conf->secondary_channel,
8561 &wpa_s->ap_iface->cs_oper_class,
8562 &chan) == NUM_HOSTAPD_MODES) {
8563 wpa_dbg(wpa_s, MSG_DEBUG,
8564 "P2P CSA: Selected invalid frequency");
8569 csa_settings.freq_params.channel = chan;
8570 csa_settings.freq_params.sec_channel_offset = conf->secondary_channel;
8571 csa_settings.freq_params.ht_enabled = conf->ieee80211n;
8572 csa_settings.freq_params.bandwidth = conf->secondary_channel ? 40 : 20;
8574 if (conf->ieee80211ac) {
8575 int freq1 = 0, freq2 = 0;
8577 if (conf->vht_oper_centr_freq_seg0_idx)
8578 freq1 = ieee80211_chan_to_freq(
8579 NULL, wpa_s->ap_iface->cs_oper_class,
8580 conf->vht_oper_centr_freq_seg0_idx);
8582 if (conf->vht_oper_centr_freq_seg1_idx)
8583 freq2 = ieee80211_chan_to_freq(
8584 NULL, wpa_s->ap_iface->cs_oper_class,
8585 conf->vht_oper_centr_freq_seg1_idx);
8587 if (freq1 < 0 || freq2 < 0) {
8588 wpa_dbg(wpa_s, MSG_DEBUG,
8589 "P2P CSA: Selected invalid VHT center freqs");
8594 csa_settings.freq_params.vht_enabled = conf->ieee80211ac;
8595 csa_settings.freq_params.center_freq1 = freq1;
8596 csa_settings.freq_params.center_freq2 = freq2;
8598 switch (conf->vht_oper_chwidth) {
8599 case VHT_CHANWIDTH_80MHZ:
8600 case VHT_CHANWIDTH_80P80MHZ:
8601 csa_settings.freq_params.bandwidth = 80;
8603 case VHT_CHANWIDTH_160MHZ:
8604 csa_settings.freq_params.bandwidth = 160;
8609 ret = ap_switch_channel(wpa_s, &csa_settings);
8611 current_ssid->frequency = old_freq;
8612 hostapd_config_free(conf);
8617 static void wpas_p2p_move_go_no_csa(struct wpa_supplicant *wpa_s)
8619 struct p2p_go_neg_results params;
8620 struct wpa_ssid *current_ssid = wpa_s->current_ssid;
8622 wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_REMOVE_AND_REFORM_GROUP);
8624 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Move GO from freq=%d MHz",
8625 current_ssid->frequency);
8627 /* Stop the AP functionality */
8628 /* TODO: Should do this in a way that does not indicated to possible
8629 * P2P Clients in the group that the group is terminated. */
8630 wpa_supplicant_ap_deinit(wpa_s);
8632 /* Reselect the GO frequency */
8633 if (wpas_p2p_init_go_params(wpa_s, ¶ms, 0, 0, 0, NULL)) {
8634 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Failed to reselect freq");
8635 wpas_p2p_group_delete(wpa_s,
8636 P2P_GROUP_REMOVAL_GO_LEAVE_CHANNEL);
8639 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: New freq selected for the GO (%u MHz)",
8643 !p2p_supported_freq_go(wpa_s->global->p2p, params.freq)) {
8644 wpa_printf(MSG_DEBUG,
8645 "P2P: Selected freq (%u MHz) is not valid for P2P",
8647 wpas_p2p_group_delete(wpa_s,
8648 P2P_GROUP_REMOVAL_GO_LEAVE_CHANNEL);
8652 /* Update the frequency */
8653 current_ssid->frequency = params.freq;
8654 wpa_s->connect_without_scan = current_ssid;
8655 wpa_s->reassociate = 1;
8656 wpa_s->disconnected = 0;
8657 wpa_supplicant_req_scan(wpa_s, 0, 0);
8661 static void wpas_p2p_move_go(void *eloop_ctx, void *timeout_ctx)
8663 struct wpa_supplicant *wpa_s = eloop_ctx;
8665 if (!wpa_s->ap_iface || !wpa_s->current_ssid)
8668 wpas_p2p_go_update_common_freqs(wpa_s);
8671 * First, try a channel switch flow. If it is not supported or fails,
8672 * take down the GO and bring it up again.
8674 if (wpas_p2p_move_go_csa(wpa_s) < 0)
8675 wpas_p2p_move_go_no_csa(wpa_s);
8679 static void wpas_p2p_reconsider_moving_go(void *eloop_ctx, void *timeout_ctx)
8681 struct wpa_supplicant *wpa_s = eloop_ctx;
8682 struct wpa_used_freq_data *freqs = NULL;
8683 unsigned int num = wpa_s->num_multichan_concurrent;
8685 freqs = os_calloc(num, sizeof(struct wpa_used_freq_data));
8689 num = get_shared_radio_freqs_data(wpa_s, freqs, num);
8691 /* Previous attempt to move a GO was not possible -- try again. */
8692 wpas_p2p_consider_moving_gos(wpa_s, freqs, num,
8693 WPAS_P2P_CHANNEL_UPDATE_ANY);
8700 * Consider moving a GO from its currently used frequency:
8701 * 1. It is possible that due to regulatory consideration the frequency
8702 * can no longer be used and there is a need to evacuate the GO.
8703 * 2. It is possible that due to MCC considerations, it would be preferable
8704 * to move the GO to a channel that is currently used by some other
8705 * station interface.
8707 * In case a frequency that became invalid is once again valid, cancel a
8708 * previously initiated GO frequency change.
8710 static void wpas_p2p_consider_moving_one_go(struct wpa_supplicant *wpa_s,
8711 struct wpa_used_freq_data *freqs,
8714 unsigned int i, invalid_freq = 0, policy_move = 0, flags = 0;
8715 unsigned int timeout;
8718 wpas_p2p_go_update_common_freqs(wpa_s);
8720 freq = wpa_s->current_ssid->frequency;
8721 for (i = 0, invalid_freq = 0; i < num; i++) {
8722 if (freqs[i].freq == freq) {
8723 flags = freqs[i].flags;
8725 /* The channel is invalid, must change it */
8726 if (!p2p_supported_freq_go(wpa_s->global->p2p, freq)) {
8727 wpa_dbg(wpa_s, MSG_DEBUG,
8728 "P2P: Freq=%d MHz no longer valid for GO",
8732 } else if (freqs[i].flags == 0) {
8733 /* Freq is not used by any other station interface */
8735 } else if (!p2p_supported_freq(wpa_s->global->p2p,
8737 /* Freq is not valid for P2P use cases */
8739 } else if (wpa_s->conf->p2p_go_freq_change_policy ==
8740 P2P_GO_FREQ_MOVE_SCM) {
8742 } else if (wpa_s->conf->p2p_go_freq_change_policy ==
8743 P2P_GO_FREQ_MOVE_SCM_PEER_SUPPORTS &&
8744 wpas_p2p_go_is_peer_freq(wpa_s, freqs[i].freq)) {
8749 wpa_dbg(wpa_s, MSG_DEBUG,
8750 "P2P: GO move: invalid_freq=%u, policy_move=%u, flags=0x%X",
8751 invalid_freq, policy_move, flags);
8754 * The channel is valid, or we are going to have a policy move, so
8757 if (!invalid_freq || policy_move) {
8758 wpa_dbg(wpa_s, MSG_DEBUG,
8759 "P2P: Cancel a GO move from freq=%d MHz", freq);
8760 eloop_cancel_timeout(wpas_p2p_move_go, wpa_s, NULL);
8762 if (wpas_p2p_in_progress(wpa_s)) {
8763 wpa_dbg(wpa_s, MSG_DEBUG,
8764 "P2P: GO move: policy CS is not allowed - setting timeout to re-consider GO move");
8765 eloop_cancel_timeout(wpas_p2p_reconsider_moving_go,
8767 eloop_register_timeout(P2P_RECONSIDER_GO_MOVE_DELAY, 0,
8768 wpas_p2p_reconsider_moving_go,
8774 if (!invalid_freq && (!policy_move || flags != 0)) {
8775 wpa_dbg(wpa_s, MSG_DEBUG,
8776 "P2P: Not initiating a GO frequency change");
8780 if (invalid_freq && !wpas_p2p_disallowed_freq(wpa_s->global, freq))
8781 timeout = P2P_GO_FREQ_CHANGE_TIME;
8785 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Move GO from freq=%d MHz in %d secs",
8787 eloop_cancel_timeout(wpas_p2p_move_go, wpa_s, NULL);
8788 eloop_register_timeout(timeout, 0, wpas_p2p_move_go, wpa_s, NULL);
8792 static void wpas_p2p_consider_moving_gos(struct wpa_supplicant *wpa_s,
8793 struct wpa_used_freq_data *freqs,
8795 enum wpas_p2p_channel_update_trig trig)
8797 struct wpa_supplicant *ifs;
8799 eloop_cancel_timeout(wpas_p2p_reconsider_moving_go, ELOOP_ALL_CTX,
8803 * Travers all the radio interfaces, and for each GO interface, check
8804 * if there is a need to move the GO from the frequency it is using,
8805 * or in case the frequency is valid again, cancel the evacuation flow.
8807 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
8809 if (ifs->current_ssid == NULL ||
8810 ifs->current_ssid->mode != WPAS_MODE_P2P_GO)
8814 * The GO was just started or completed channel switch, no need
8818 (trig == WPAS_P2P_CHANNEL_UPDATE_STATE_CHANGE ||
8819 trig == WPAS_P2P_CHANNEL_UPDATE_CS)) {
8820 wpa_dbg(wpa_s, MSG_DEBUG,
8821 "P2P: GO move - schedule re-consideration");
8822 eloop_register_timeout(P2P_RECONSIDER_GO_MOVE_DELAY, 0,
8823 wpas_p2p_reconsider_moving_go,
8828 wpas_p2p_consider_moving_one_go(ifs, freqs, num);
8833 void wpas_p2p_indicate_state_change(struct wpa_supplicant *wpa_s)
8835 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
8838 wpas_p2p_update_channel_list(wpa_s,
8839 WPAS_P2P_CHANNEL_UPDATE_STATE_CHANGE);
8843 void wpas_p2p_deinit_iface(struct wpa_supplicant *wpa_s)
8845 if (wpa_s == wpa_s->global->p2p_init_wpa_s && wpa_s->global->p2p) {
8846 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Disable P2P since removing "
8847 "the management interface is being removed");
8848 wpas_p2p_deinit_global(wpa_s->global);
8853 void wpas_p2p_ap_deinit(struct wpa_supplicant *wpa_s)
8855 if (wpa_s->ap_iface->bss)
8856 wpa_s->ap_iface->bss[0]->p2p_group = NULL;
8857 wpas_p2p_group_deinit(wpa_s);