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)
2695 static int wpas_sta_check_ecsa(struct hostapd_data *hapd,
2696 struct sta_info *sta, void *ctx)
2698 int *ecsa_support = ctx;
2700 *ecsa_support &= sta->ecsa_supported;
2706 /* Check if all the peers support eCSA */
2707 static int wpas_p2p_go_clients_support_ecsa(struct wpa_supplicant *wpa_s)
2709 int ecsa_support = 1;
2711 ap_for_each_sta(wpa_s->ap_iface->bss[0], wpas_sta_check_ecsa,
2714 return ecsa_support;
2719 * Pick the best frequency to use from all the currently used frequencies.
2721 static int wpas_p2p_pick_best_used_freq(struct wpa_supplicant *wpa_s,
2722 struct wpa_used_freq_data *freqs,
2727 /* find a candidate freq that is supported by P2P */
2728 for (c = 0; c < num; c++)
2729 if (p2p_supported_freq(wpa_s->global->p2p, freqs[c].freq))
2735 /* once we have a candidate, try to find a 'better' one */
2736 for (i = c + 1; i < num; i++) {
2737 if (!p2p_supported_freq(wpa_s->global->p2p, freqs[i].freq))
2741 * 1. Infrastructure station interfaces have higher preference.
2742 * 2. P2P Clients have higher preference.
2745 if (freqs[i].flags & WPA_FREQ_USED_BY_INFRA_STATION) {
2750 if ((freqs[i].flags & WPA_FREQ_USED_BY_P2P_CLIENT))
2753 return freqs[c].freq;
2757 static u8 wpas_invitation_process(void *ctx, const u8 *sa, const u8 *bssid,
2758 const u8 *go_dev_addr, const u8 *ssid,
2759 size_t ssid_len, int *go, u8 *group_bssid,
2760 int *force_freq, int persistent_group,
2761 const struct p2p_channels *channels,
2764 struct wpa_supplicant *wpa_s = ctx;
2766 struct wpa_used_freq_data *freqs;
2767 struct wpa_supplicant *grp;
2770 if (!persistent_group) {
2771 wpa_printf(MSG_DEBUG, "P2P: Invitation from " MACSTR
2772 " to join an active group (SSID: %s)",
2773 MAC2STR(sa), wpa_ssid_txt(ssid, ssid_len));
2774 if (!is_zero_ether_addr(wpa_s->p2p_auth_invite) &&
2775 (os_memcmp(go_dev_addr, wpa_s->p2p_auth_invite, ETH_ALEN)
2777 os_memcmp(sa, wpa_s->p2p_auth_invite, ETH_ALEN) == 0)) {
2778 wpa_printf(MSG_DEBUG, "P2P: Accept previously "
2779 "authorized invitation");
2783 #ifdef CONFIG_WPS_NFC
2784 if (dev_pw_id >= 0 && wpa_s->p2p_nfc_tag_enabled &&
2785 dev_pw_id == wpa_s->p2p_oob_dev_pw_id) {
2786 wpa_printf(MSG_DEBUG, "P2P: Accept invitation based on local enabled NFC Tag");
2787 wpa_s->p2p_wps_method = WPS_NFC;
2788 wpa_s->pending_join_wps_method = WPS_NFC;
2789 os_memcpy(wpa_s->pending_join_dev_addr,
2790 go_dev_addr, ETH_ALEN);
2791 os_memcpy(wpa_s->pending_join_iface_addr,
2795 #endif /* CONFIG_WPS_NFC */
2798 * Do not accept the invitation automatically; notify user and
2801 return P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE;
2804 grp = wpas_get_p2p_group(wpa_s, ssid, ssid_len, go);
2806 wpa_printf(MSG_DEBUG, "P2P: Accept invitation to already "
2807 "running persistent group");
2809 os_memcpy(group_bssid, grp->own_addr, ETH_ALEN);
2813 if (!is_zero_ether_addr(wpa_s->p2p_auth_invite) &&
2814 os_memcmp(sa, wpa_s->p2p_auth_invite, ETH_ALEN) == 0) {
2815 wpa_printf(MSG_DEBUG, "P2P: Accept previously initiated "
2816 "invitation to re-invoke a persistent group");
2817 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
2818 } else if (!wpa_s->conf->persistent_reconnect)
2819 return P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE;
2821 for (s = wpa_s->conf->ssid; s; s = s->next) {
2822 if (s->disabled == 2 &&
2823 os_memcmp(s->bssid, go_dev_addr, ETH_ALEN) == 0 &&
2824 s->ssid_len == ssid_len &&
2825 os_memcmp(ssid, s->ssid, ssid_len) == 0)
2830 wpa_printf(MSG_DEBUG, "P2P: Invitation from " MACSTR
2831 " requested reinvocation of an unknown group",
2833 return P2P_SC_FAIL_UNKNOWN_GROUP;
2836 if (s->mode == WPAS_MODE_P2P_GO && !wpas_p2p_create_iface(wpa_s)) {
2838 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2839 wpa_printf(MSG_DEBUG, "P2P: The only available "
2840 "interface is already in use - reject "
2842 return P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE;
2844 os_memcpy(group_bssid, wpa_s->own_addr, ETH_ALEN);
2845 } else if (s->mode == WPAS_MODE_P2P_GO) {
2847 if (wpas_p2p_add_group_interface(wpa_s, WPA_IF_P2P_GO) < 0)
2849 wpa_printf(MSG_ERROR, "P2P: Failed to allocate a new "
2850 "interface address for the group");
2851 return P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE;
2853 os_memcpy(group_bssid, wpa_s->pending_interface_addr,
2858 wpas_p2p_set_own_freq_preference(wpa_s, 0);
2861 freqs = os_calloc(wpa_s->num_multichan_concurrent,
2862 sizeof(struct wpa_used_freq_data));
2864 int num_channels = wpa_s->num_multichan_concurrent;
2865 int num = wpas_p2p_valid_oper_freqs(wpa_s, freqs, num_channels);
2866 best_freq = wpas_p2p_pick_best_used_freq(wpa_s, freqs, num);
2870 /* Get one of the frequencies currently in use */
2871 if (best_freq > 0) {
2872 wpa_printf(MSG_DEBUG, "P2P: Trying to prefer a channel already used by one of the interfaces");
2873 wpas_p2p_set_own_freq_preference(wpa_s, best_freq);
2875 if (wpa_s->num_multichan_concurrent < 2 ||
2876 wpas_p2p_num_unused_channels(wpa_s) < 1) {
2877 wpa_printf(MSG_DEBUG, "P2P: No extra channels available - trying to force channel to match a channel already used by one of the interfaces");
2878 *force_freq = best_freq;
2882 if (*force_freq > 0 && wpa_s->num_multichan_concurrent > 1 &&
2883 wpas_p2p_num_unused_channels(wpa_s) > 0) {
2885 /* We are the client */
2886 wpa_printf(MSG_DEBUG, "P2P: Peer was found to be "
2887 "running a GO but we are capable of MCC, "
2888 "figure out the best channel to use");
2890 } else if (!freq_included(wpa_s, channels, *force_freq)) {
2891 /* We are the GO, and *force_freq is not in the
2893 wpa_printf(MSG_DEBUG, "P2P: Forced GO freq %d MHz not "
2894 "in intersection but we are capable of MCC, "
2895 "figure out the best channel to use",
2901 return P2P_SC_SUCCESS;
2905 static void wpas_invitation_received(void *ctx, const u8 *sa, const u8 *bssid,
2906 const u8 *ssid, size_t ssid_len,
2907 const u8 *go_dev_addr, u8 status,
2910 struct wpa_supplicant *wpa_s = ctx;
2913 for (s = wpa_s->conf->ssid; s; s = s->next) {
2914 if (s->disabled == 2 &&
2915 s->ssid_len == ssid_len &&
2916 os_memcmp(ssid, s->ssid, ssid_len) == 0)
2920 if (status == P2P_SC_SUCCESS) {
2921 wpa_printf(MSG_DEBUG, "P2P: Invitation from peer " MACSTR
2922 " was accepted; op_freq=%d MHz, SSID=%s",
2923 MAC2STR(sa), op_freq, wpa_ssid_txt(ssid, ssid_len));
2925 int go = s->mode == WPAS_MODE_P2P_GO;
2926 wpas_p2p_group_add_persistent(
2927 wpa_s, s, go, 0, op_freq, 0, 0, NULL,
2928 go ? P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE : 0,
2931 wpa_s->user_initiated_pd = 0;
2932 wpas_p2p_join(wpa_s, bssid, go_dev_addr,
2933 wpa_s->p2p_wps_method, 0, op_freq,
2939 if (status != P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE) {
2940 wpa_printf(MSG_DEBUG, "P2P: Invitation from peer " MACSTR
2941 " was rejected (status %u)", MAC2STR(sa), status);
2947 wpa_msg_global(wpa_s, MSG_INFO,
2948 P2P_EVENT_INVITATION_RECEIVED
2949 "sa=" MACSTR " go_dev_addr=" MACSTR
2950 " bssid=" MACSTR " unknown-network",
2951 MAC2STR(sa), MAC2STR(go_dev_addr),
2954 wpa_msg_global(wpa_s, MSG_INFO,
2955 P2P_EVENT_INVITATION_RECEIVED
2956 "sa=" MACSTR " go_dev_addr=" MACSTR
2958 MAC2STR(sa), MAC2STR(go_dev_addr));
2960 wpas_notify_p2p_invitation_received(wpa_s, sa, go_dev_addr,
2965 if (s->mode == WPAS_MODE_P2P_GO && op_freq) {
2966 wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RECEIVED
2967 "sa=" MACSTR " persistent=%d freq=%d",
2968 MAC2STR(sa), s->id, op_freq);
2970 wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RECEIVED
2971 "sa=" MACSTR " persistent=%d",
2972 MAC2STR(sa), s->id);
2974 wpas_notify_p2p_invitation_received(wpa_s, sa, go_dev_addr, bssid,
2979 static void wpas_remove_persistent_peer(struct wpa_supplicant *wpa_s,
2980 struct wpa_ssid *ssid,
2981 const u8 *peer, int inv)
2984 struct wpa_supplicant *p2p_wpa_s = wpa_s->global->p2p_init_wpa_s;
2989 for (i = 0; ssid->p2p_client_list && i < ssid->num_p2p_clients; i++) {
2990 if (os_memcmp(ssid->p2p_client_list + i * 2 * ETH_ALEN, peer,
2994 if (i >= ssid->num_p2p_clients || !ssid->p2p_client_list) {
2995 if (ssid->mode != WPAS_MODE_P2P_GO &&
2996 os_memcmp(ssid->bssid, peer, ETH_ALEN) == 0) {
2997 wpa_printf(MSG_DEBUG, "P2P: Remove persistent group %d "
2998 "due to invitation result", ssid->id);
2999 wpas_notify_network_removed(wpa_s, ssid);
3000 wpa_config_remove_network(wpa_s->conf, ssid->id);
3003 return; /* Peer not found in client list */
3006 wpa_printf(MSG_DEBUG, "P2P: Remove peer " MACSTR " from persistent "
3007 "group %d client list%s",
3008 MAC2STR(peer), ssid->id,
3009 inv ? " due to invitation result" : "");
3010 os_memmove(ssid->p2p_client_list + i * 2 * ETH_ALEN,
3011 ssid->p2p_client_list + (i + 1) * 2 * ETH_ALEN,
3012 (ssid->num_p2p_clients - i - 1) * 2 * ETH_ALEN);
3013 ssid->num_p2p_clients--;
3014 if (p2p_wpa_s->conf->update_config &&
3015 wpa_config_write(p2p_wpa_s->confname, p2p_wpa_s->conf))
3016 wpa_printf(MSG_DEBUG, "P2P: Failed to update configuration");
3020 static void wpas_remove_persistent_client(struct wpa_supplicant *wpa_s,
3023 struct wpa_ssid *ssid;
3025 wpa_s = wpa_s->global->p2p_invite_group;
3027 return; /* No known invitation group */
3028 ssid = wpa_s->current_ssid;
3029 if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO ||
3030 !ssid->p2p_persistent_group)
3031 return; /* Not operating as a GO in persistent group */
3032 ssid = wpas_p2p_get_persistent(wpa_s->parent, peer,
3033 ssid->ssid, ssid->ssid_len);
3034 wpas_remove_persistent_peer(wpa_s, ssid, peer, 1);
3038 static void wpas_invitation_result(void *ctx, int status, const u8 *bssid,
3039 const struct p2p_channels *channels,
3040 const u8 *peer, int neg_freq,
3043 struct wpa_supplicant *wpa_s = ctx;
3044 struct wpa_ssid *ssid;
3048 wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RESULT
3049 "status=%d " MACSTR,
3050 status, MAC2STR(bssid));
3052 wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RESULT
3053 "status=%d ", status);
3055 wpas_notify_p2p_invitation_result(wpa_s, status, bssid);
3057 wpa_printf(MSG_DEBUG, "P2P: Invitation result - status=%d peer=" MACSTR,
3058 status, MAC2STR(peer));
3059 if (wpa_s->pending_invite_ssid_id == -1) {
3060 if (status == P2P_SC_FAIL_UNKNOWN_GROUP)
3061 wpas_remove_persistent_client(wpa_s, peer);
3062 return; /* Invitation to active group */
3065 if (status == P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE) {
3066 wpa_printf(MSG_DEBUG, "P2P: Waiting for peer to start another "
3067 "invitation exchange to indicate readiness for "
3071 if (status != P2P_SC_SUCCESS) {
3072 if (status == P2P_SC_FAIL_UNKNOWN_GROUP) {
3073 ssid = wpa_config_get_network(
3074 wpa_s->conf, wpa_s->pending_invite_ssid_id);
3075 wpas_remove_persistent_peer(wpa_s, ssid, peer, 1);
3077 wpas_p2p_remove_pending_group_interface(wpa_s);
3081 ssid = wpa_config_get_network(wpa_s->conf,
3082 wpa_s->pending_invite_ssid_id);
3084 wpa_printf(MSG_ERROR, "P2P: Could not find persistent group "
3085 "data matching with invitation");
3090 * The peer could have missed our ctrl::ack frame for Invitation
3091 * Response and continue retransmitting the frame. To reduce the
3092 * likelihood of the peer not getting successful TX status for the
3093 * Invitation Response frame, wait a short time here before starting
3094 * the persistent group so that we will remain on the current channel to
3095 * acknowledge any possible retransmission from the peer.
3097 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: 50 ms wait on current channel before "
3098 "starting persistent group");
3101 if (neg_freq > 0 && ssid->mode == WPAS_MODE_P2P_GO &&
3102 freq_included(wpa_s, channels, neg_freq))
3104 else if (peer_oper_freq > 0 && ssid->mode != WPAS_MODE_P2P_GO &&
3105 freq_included(wpa_s, channels, peer_oper_freq))
3106 freq = peer_oper_freq;
3110 wpa_printf(MSG_DEBUG, "P2P: Persistent group invitation success - op_freq=%d MHz SSID=%s",
3111 freq, wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
3112 wpas_p2p_group_add_persistent(wpa_s, ssid,
3113 ssid->mode == WPAS_MODE_P2P_GO,
3114 wpa_s->p2p_persistent_go_freq,
3116 wpa_s->p2p_go_ht40, wpa_s->p2p_go_vht,
3118 ssid->mode == WPAS_MODE_P2P_GO ?
3119 P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE :
3124 static int wpas_p2p_disallowed_freq(struct wpa_global *global,
3127 if (freq_range_list_includes(&global->p2p_go_avoid_freq, freq))
3129 return freq_range_list_includes(&global->p2p_disallow_freq, freq);
3133 static void wpas_p2p_add_chan(struct p2p_reg_class *reg, u8 chan)
3135 reg->channel[reg->channels] = chan;
3140 static int wpas_p2p_default_channels(struct wpa_supplicant *wpa_s,
3141 struct p2p_channels *chan,
3142 struct p2p_channels *cli_chan)
3146 wpa_s->global->p2p_24ghz_social_channels = 1;
3148 os_memset(cli_chan, 0, sizeof(*cli_chan));
3150 wpa_printf(MSG_DEBUG, "P2P: Enable operating classes for 2.4 GHz "
3153 /* Operating class 81 - 2.4 GHz band channels 1..13 */
3154 chan->reg_class[cla].reg_class = 81;
3155 chan->reg_class[cla].channels = 0;
3156 for (i = 0; i < 11; i++) {
3157 if (!wpas_p2p_disallowed_freq(wpa_s->global, 2412 + i * 5))
3158 wpas_p2p_add_chan(&chan->reg_class[cla], i + 1);
3160 if (chan->reg_class[cla].channels)
3163 wpa_printf(MSG_DEBUG, "P2P: Enable operating classes for lower 5 GHz "
3166 /* Operating class 115 - 5 GHz, channels 36-48 */
3167 chan->reg_class[cla].reg_class = 115;
3168 chan->reg_class[cla].channels = 0;
3169 if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 36 * 5))
3170 wpas_p2p_add_chan(&chan->reg_class[cla], 36);
3171 if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 40 * 5))
3172 wpas_p2p_add_chan(&chan->reg_class[cla], 40);
3173 if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 44 * 5))
3174 wpas_p2p_add_chan(&chan->reg_class[cla], 44);
3175 if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 48 * 5))
3176 wpas_p2p_add_chan(&chan->reg_class[cla], 48);
3177 if (chan->reg_class[cla].channels)
3180 wpa_printf(MSG_DEBUG, "P2P: Enable operating classes for higher 5 GHz "
3183 /* Operating class 124 - 5 GHz, channels 149,153,157,161 */
3184 chan->reg_class[cla].reg_class = 124;
3185 chan->reg_class[cla].channels = 0;
3186 if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 149 * 5))
3187 wpas_p2p_add_chan(&chan->reg_class[cla], 149);
3188 if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 153 * 5))
3189 wpas_p2p_add_chan(&chan->reg_class[cla], 153);
3190 if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 156 * 5))
3191 wpas_p2p_add_chan(&chan->reg_class[cla], 157);
3192 if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 161 * 5))
3193 wpas_p2p_add_chan(&chan->reg_class[cla], 161);
3194 if (chan->reg_class[cla].channels)
3197 chan->reg_classes = cla;
3202 static struct hostapd_hw_modes * get_mode(struct hostapd_hw_modes *modes,
3204 enum hostapd_hw_mode mode)
3208 for (i = 0; i < num_modes; i++) {
3209 if (modes[i].mode == mode)
3218 NOT_ALLOWED, NO_IR, ALLOWED
3221 static int has_channel(struct wpa_global *global,
3222 struct hostapd_hw_modes *mode, u8 chan, int *flags)
3227 freq = (mode->mode == HOSTAPD_MODE_IEEE80211A ? 5000 : 2407) +
3229 if (wpas_p2p_disallowed_freq(global, freq))
3232 for (i = 0; i < mode->num_channels; i++) {
3233 if (mode->channels[i].chan == chan) {
3235 *flags = mode->channels[i].flag;
3236 if (mode->channels[i].flag &
3237 (HOSTAPD_CHAN_DISABLED |
3238 HOSTAPD_CHAN_RADAR))
3240 if (mode->channels[i].flag & HOSTAPD_CHAN_NO_IR)
3250 struct p2p_oper_class_map {
3251 enum hostapd_hw_mode mode;
3256 enum { BW20, BW40PLUS, BW40MINUS, BW80, BW2160 } bw;
3259 static const struct p2p_oper_class_map op_class[] = {
3260 { HOSTAPD_MODE_IEEE80211G, 81, 1, 13, 1, BW20 },
3261 #if 0 /* Do not enable HT40 on 2 GHz for now */
3262 { HOSTAPD_MODE_IEEE80211G, 83, 1, 9, 1, BW40PLUS },
3263 { HOSTAPD_MODE_IEEE80211G, 84, 5, 13, 1, BW40MINUS },
3265 { HOSTAPD_MODE_IEEE80211A, 115, 36, 48, 4, BW20 },
3266 { HOSTAPD_MODE_IEEE80211A, 124, 149, 161, 4, BW20 },
3267 { HOSTAPD_MODE_IEEE80211A, 125, 149, 169, 4, BW20 },
3268 { HOSTAPD_MODE_IEEE80211A, 116, 36, 44, 8, BW40PLUS },
3269 { HOSTAPD_MODE_IEEE80211A, 117, 40, 48, 8, BW40MINUS },
3270 { HOSTAPD_MODE_IEEE80211A, 126, 149, 157, 8, BW40PLUS },
3271 { HOSTAPD_MODE_IEEE80211A, 127, 153, 161, 8, BW40MINUS },
3274 * IEEE P802.11ac/D7.0 Table E-4 actually talks about channel center
3275 * frequency index 42, 58, 106, 122, 138, 155 with channel spacing of
3276 * 80 MHz, but currently use the following definition for simplicity
3277 * (these center frequencies are not actual channels, which makes
3278 * has_channel() fail). wpas_p2p_verify_80mhz() should take care of
3279 * removing invalid channels.
3281 { HOSTAPD_MODE_IEEE80211A, 128, 36, 161, 4, BW80 },
3282 { HOSTAPD_MODE_IEEE80211AD, 180, 1, 4, 1, BW2160 },
3283 { -1, 0, 0, 0, 0, BW20 }
3287 static int wpas_p2p_get_center_80mhz(struct wpa_supplicant *wpa_s,
3288 struct hostapd_hw_modes *mode,
3291 u8 center_channels[] = { 42, 58, 106, 122, 138, 155 };
3294 if (mode->mode != HOSTAPD_MODE_IEEE80211A)
3297 for (i = 0; i < ARRAY_SIZE(center_channels); i++)
3299 * In 80 MHz, the bandwidth "spans" 12 channels (e.g., 36-48),
3300 * so the center channel is 6 channels away from the start/end.
3302 if (channel >= center_channels[i] - 6 &&
3303 channel <= center_channels[i] + 6)
3304 return center_channels[i];
3310 static enum chan_allowed wpas_p2p_verify_80mhz(struct wpa_supplicant *wpa_s,
3311 struct hostapd_hw_modes *mode,
3316 enum chan_allowed res, ret = ALLOWED;
3318 center_chan = wpas_p2p_get_center_80mhz(wpa_s, mode, channel);
3321 if (center_chan >= 58 && center_chan <= 138)
3322 return NOT_ALLOWED; /* Do not allow DFS channels for P2P */
3324 /* check all the channels are available */
3325 for (i = 0; i < 4; i++) {
3326 int adj_chan = center_chan - 6 + i * 4;
3328 res = has_channel(wpa_s->global, mode, adj_chan, &flags);
3329 if (res == NOT_ALLOWED)
3334 if (i == 0 && !(flags & HOSTAPD_CHAN_VHT_10_70))
3336 if (i == 1 && !(flags & HOSTAPD_CHAN_VHT_30_50))
3338 if (i == 2 && !(flags & HOSTAPD_CHAN_VHT_50_30))
3340 if (i == 3 && !(flags & HOSTAPD_CHAN_VHT_70_10))
3348 static enum chan_allowed wpas_p2p_verify_channel(struct wpa_supplicant *wpa_s,
3349 struct hostapd_hw_modes *mode,
3353 enum chan_allowed res, res2;
3355 res2 = res = has_channel(wpa_s->global, mode, channel, &flag);
3356 if (bw == BW40MINUS) {
3357 if (!(flag & HOSTAPD_CHAN_HT40MINUS))
3359 res2 = has_channel(wpa_s->global, mode, channel - 4, NULL);
3360 } else if (bw == BW40PLUS) {
3361 if (!(flag & HOSTAPD_CHAN_HT40PLUS))
3363 res2 = has_channel(wpa_s->global, mode, channel + 4, NULL);
3364 } else if (bw == BW80) {
3365 res2 = wpas_p2p_verify_80mhz(wpa_s, mode, channel, bw);
3368 if (res == NOT_ALLOWED || res2 == NOT_ALLOWED)
3370 if (res == NO_IR || res2 == NO_IR)
3376 static int wpas_p2p_setup_channels(struct wpa_supplicant *wpa_s,
3377 struct p2p_channels *chan,
3378 struct p2p_channels *cli_chan)
3380 struct hostapd_hw_modes *mode;
3381 int cla, op, cli_cla;
3383 if (wpa_s->hw.modes == NULL) {
3384 wpa_printf(MSG_DEBUG, "P2P: Driver did not support fetching "
3385 "of all supported channels; assume dualband "
3387 return wpas_p2p_default_channels(wpa_s, chan, cli_chan);
3392 for (op = 0; op_class[op].op_class; op++) {
3393 const struct p2p_oper_class_map *o = &op_class[op];
3395 struct p2p_reg_class *reg = NULL, *cli_reg = NULL;
3397 mode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, o->mode);
3400 if (mode->mode == HOSTAPD_MODE_IEEE80211G)
3401 wpa_s->global->p2p_24ghz_social_channels = 1;
3402 for (ch = o->min_chan; ch <= o->max_chan; ch += o->inc) {
3403 enum chan_allowed res;
3404 res = wpas_p2p_verify_channel(wpa_s, mode, ch, o->bw);
3405 if (res == ALLOWED) {
3407 wpa_printf(MSG_DEBUG, "P2P: Add operating class %u",
3409 reg = &chan->reg_class[cla];
3411 reg->reg_class = o->op_class;
3413 reg->channel[reg->channels] = ch;
3415 } else if (res == NO_IR &&
3416 wpa_s->conf->p2p_add_cli_chan) {
3417 if (cli_reg == NULL) {
3418 wpa_printf(MSG_DEBUG, "P2P: Add operating class %u (client only)",
3420 cli_reg = &cli_chan->reg_class[cli_cla];
3422 cli_reg->reg_class = o->op_class;
3424 cli_reg->channel[cli_reg->channels] = ch;
3425 cli_reg->channels++;
3429 wpa_hexdump(MSG_DEBUG, "P2P: Channels",
3430 reg->channel, reg->channels);
3433 wpa_hexdump(MSG_DEBUG, "P2P: Channels (client only)",
3434 cli_reg->channel, cli_reg->channels);
3438 chan->reg_classes = cla;
3439 cli_chan->reg_classes = cli_cla;
3445 int wpas_p2p_get_ht40_mode(struct wpa_supplicant *wpa_s,
3446 struct hostapd_hw_modes *mode, u8 channel)
3449 enum chan_allowed ret;
3451 for (op = 0; op_class[op].op_class; op++) {
3452 const struct p2p_oper_class_map *o = &op_class[op];
3455 for (ch = o->min_chan; ch <= o->max_chan; ch += o->inc) {
3456 if (o->mode != HOSTAPD_MODE_IEEE80211A ||
3457 (o->bw != BW40PLUS && o->bw != BW40MINUS) ||
3460 ret = wpas_p2p_verify_channel(wpa_s, mode, ch, o->bw);
3462 return (o->bw == BW40MINUS) ? -1 : 1;
3469 int wpas_p2p_get_vht80_center(struct wpa_supplicant *wpa_s,
3470 struct hostapd_hw_modes *mode, u8 channel)
3472 if (!wpas_p2p_verify_channel(wpa_s, mode, channel, BW80))
3475 return wpas_p2p_get_center_80mhz(wpa_s, mode, channel);
3479 static int wpas_get_noa(void *ctx, const u8 *interface_addr, u8 *buf,
3482 struct wpa_supplicant *wpa_s = ctx;
3484 for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) {
3485 if (os_memcmp(wpa_s->own_addr, interface_addr, ETH_ALEN) == 0)
3491 return wpa_drv_get_noa(wpa_s, buf, buf_len);
3495 struct wpa_supplicant * wpas_get_p2p_go_iface(struct wpa_supplicant *wpa_s,
3496 const u8 *ssid, size_t ssid_len)
3498 for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) {
3499 struct wpa_ssid *s = wpa_s->current_ssid;
3502 if (s->mode != WPAS_MODE_P2P_GO &&
3503 s->mode != WPAS_MODE_AP &&
3504 s->mode != WPAS_MODE_P2P_GROUP_FORMATION)
3506 if (s->ssid_len != ssid_len ||
3507 os_memcmp(ssid, s->ssid, ssid_len) != 0)
3517 struct wpa_supplicant * wpas_get_p2p_client_iface(struct wpa_supplicant *wpa_s,
3518 const u8 *peer_dev_addr)
3520 for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) {
3521 struct wpa_ssid *ssid = wpa_s->current_ssid;
3522 if (ssid && (ssid->mode != WPAS_MODE_INFRA || !ssid->p2p_group))
3524 if (os_memcmp(wpa_s->go_dev_addr, peer_dev_addr, ETH_ALEN) == 0)
3532 static int wpas_go_connected(void *ctx, const u8 *dev_addr)
3534 struct wpa_supplicant *wpa_s = ctx;
3536 return wpas_get_p2p_client_iface(wpa_s, dev_addr) != NULL;
3540 static int wpas_is_concurrent_session_active(void *ctx)
3542 struct wpa_supplicant *wpa_s = ctx;
3543 struct wpa_supplicant *ifs;
3545 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
3548 if (ifs->wpa_state > WPA_ASSOCIATED)
3555 static void wpas_p2p_debug_print(void *ctx, int level, const char *msg)
3557 struct wpa_supplicant *wpa_s = ctx;
3558 wpa_msg_global(wpa_s, level, "P2P: %s", msg);
3562 int wpas_p2p_add_p2pdev_interface(struct wpa_supplicant *wpa_s,
3563 const char *conf_p2p_dev)
3565 struct wpa_interface iface;
3566 struct wpa_supplicant *p2pdev_wpa_s;
3568 char force_name[100];
3571 ret = os_snprintf(ifname, sizeof(ifname), P2P_MGMT_DEVICE_PREFIX "%s",
3573 if (os_snprintf_error(sizeof(ifname), ret))
3575 force_name[0] = '\0';
3576 wpa_s->pending_interface_type = WPA_IF_P2P_DEVICE;
3577 ret = wpa_drv_if_add(wpa_s, WPA_IF_P2P_DEVICE, ifname, NULL, NULL,
3578 force_name, wpa_s->pending_interface_addr, NULL);
3580 wpa_printf(MSG_DEBUG, "P2P: Failed to create P2P Device interface");
3583 os_strlcpy(wpa_s->pending_interface_name, ifname,
3584 sizeof(wpa_s->pending_interface_name));
3586 os_memset(&iface, 0, sizeof(iface));
3588 iface.ifname = wpa_s->pending_interface_name;
3589 iface.driver = wpa_s->driver->name;
3590 iface.driver_param = wpa_s->conf->driver_param;
3593 * If a P2P Device configuration file was given, use it as the interface
3594 * configuration file (instead of using parent's configuration file.
3597 iface.confname = conf_p2p_dev;
3598 iface.ctrl_interface = NULL;
3600 iface.confname = wpa_s->confname;
3601 iface.ctrl_interface = wpa_s->conf->ctrl_interface;
3604 p2pdev_wpa_s = wpa_supplicant_add_iface(wpa_s->global, &iface, wpa_s);
3605 if (!p2pdev_wpa_s) {
3606 wpa_printf(MSG_DEBUG, "P2P: Failed to add P2P Device interface");
3610 wpa_s->pending_interface_name[0] = '\0';
3615 static void wpas_presence_resp(void *ctx, const u8 *src, u8 status,
3616 const u8 *noa, size_t noa_len)
3618 struct wpa_supplicant *wpa_s, *intf = ctx;
3621 for (wpa_s = intf->global->ifaces; wpa_s; wpa_s = wpa_s->next) {
3622 if (wpa_s->waiting_presence_resp)
3626 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: No group interface was waiting for presence response");
3629 wpa_s->waiting_presence_resp = 0;
3631 wpa_snprintf_hex(hex, sizeof(hex), noa, noa_len);
3632 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_PRESENCE_RESPONSE "src=" MACSTR
3633 " status=%u noa=%s", MAC2STR(src), status, hex);
3637 static int wpas_get_persistent_group(void *ctx, const u8 *addr, const u8 *ssid,
3638 size_t ssid_len, u8 *go_dev_addr,
3639 u8 *ret_ssid, size_t *ret_ssid_len,
3640 u8 *intended_iface_addr)
3642 struct wpa_supplicant *wpa_s = ctx;
3645 s = wpas_p2p_get_persistent(wpa_s, addr, ssid, ssid_len);
3647 os_memcpy(ret_ssid, s->ssid, s->ssid_len);
3648 *ret_ssid_len = s->ssid_len;
3649 os_memcpy(go_dev_addr, s->bssid, ETH_ALEN);
3651 if (s->mode != WPAS_MODE_P2P_GO) {
3652 os_memset(intended_iface_addr, 0, ETH_ALEN);
3653 } else if (wpas_p2p_create_iface(wpa_s)) {
3654 if (wpas_p2p_add_group_interface(wpa_s, WPA_IF_P2P_GO))
3657 os_memcpy(intended_iface_addr,
3658 wpa_s->pending_interface_addr, ETH_ALEN);
3660 os_memcpy(intended_iface_addr, wpa_s->own_addr,
3670 static int wpas_get_go_info(void *ctx, u8 *intended_addr,
3671 u8 *ssid, size_t *ssid_len, int *group_iface)
3673 struct wpa_supplicant *wpa_s = ctx;
3678 * group_iface will be set to 1 only if a dedicated interface for P2P
3679 * role is required. First, we try to reuse an active GO. However,
3680 * if it is not present, we will try to reactivate an existing
3681 * persistent group and set group_iface to 1, so the caller will know
3682 * that the pending interface should be used.
3685 s = wpas_p2p_group_go_ssid(wpa_s, bssid);
3687 s = wpas_p2p_get_persistent_go(wpa_s);
3688 *group_iface = wpas_p2p_create_iface(wpa_s);
3690 os_memcpy(bssid, s->bssid, ETH_ALEN);
3695 os_memcpy(intended_addr, bssid, ETH_ALEN);
3696 os_memcpy(ssid, s->ssid, s->ssid_len);
3697 *ssid_len = s->ssid_len;
3703 static int wpas_remove_stale_groups(void *ctx, const u8 *peer, const u8 *go,
3704 const u8 *ssid, size_t ssid_len)
3706 struct wpa_supplicant *wpa_s = ctx;
3708 int save_config = 0;
3711 /* Start with our first choice of Persistent Groups */
3712 while ((s = wpas_p2p_get_persistent(wpa_s, peer, NULL, 0))) {
3713 if (go && ssid && ssid_len &&
3714 s->ssid_len == ssid_len &&
3715 os_memcmp(go, s->bssid, ETH_ALEN) == 0 &&
3716 os_memcmp(ssid, s->ssid, ssid_len) == 0)
3719 /* Remove stale persistent group */
3720 if (s->mode != WPAS_MODE_P2P_GO || s->num_p2p_clients <= 1) {
3721 wpa_config_remove_network(wpa_s->conf, s->id);
3726 for (i = 0; i < s->num_p2p_clients; i++) {
3727 if (os_memcmp(s->p2p_client_list + i * 2 * ETH_ALEN,
3728 peer, ETH_ALEN) != 0)
3731 os_memmove(s->p2p_client_list + i * 2 * ETH_ALEN,
3732 s->p2p_client_list + (i + 1) * 2 * ETH_ALEN,
3733 (s->num_p2p_clients - i - 1) * 2 * ETH_ALEN);
3736 s->num_p2p_clients--;
3741 p2p_config_write(wpa_s);
3743 /* Return TRUE if valid SSID remains */
3748 static void wpas_p2ps_get_feat_cap_str(char *buf, size_t buf_len,
3749 const u8 *feat_cap, size_t feat_cap_len)
3751 static const char pref[] = " feature_cap=";
3757 * We expect a feature capability to contain at least one byte to be
3758 * reported. The string buffer provided by the caller function is
3759 * expected to be big enough to contain all bytes of the attribute for
3760 * known specifications. This function truncates the reported bytes if
3761 * the feature capability data exceeds the string buffer size.
3763 if (!feat_cap || !feat_cap_len || buf_len < sizeof(pref) + 2)
3766 os_memcpy(buf, pref, sizeof(pref));
3767 ret = wpa_snprintf_hex(&buf[sizeof(pref) - 1],
3768 buf_len - sizeof(pref) + 1,
3769 feat_cap, feat_cap_len);
3771 if (ret != (2 * (int) feat_cap_len))
3772 wpa_printf(MSG_WARNING, "P2PS feature_cap bytes truncated");
3776 static void wpas_p2ps_prov_complete(void *ctx, u8 status, const u8 *dev,
3777 const u8 *adv_mac, const u8 *ses_mac,
3778 const u8 *grp_mac, u32 adv_id, u32 ses_id,
3779 u8 conncap, int passwd_id,
3780 const u8 *persist_ssid,
3781 size_t persist_ssid_size, int response_done,
3782 int prov_start, const char *session_info,
3783 const u8 *feat_cap, size_t feat_cap_len)
3785 struct wpa_supplicant *wpa_s = ctx;
3787 struct wpa_ssid *persistent_go, *stale, *s;
3788 int save_config = 0;
3789 struct wpa_supplicant *go_wpa_s;
3790 char feat_cap_str[256];
3795 os_memset(mac, 0, ETH_ALEN);
3803 wpas_p2ps_get_feat_cap_str(feat_cap_str, sizeof(feat_cap_str),
3804 feat_cap, feat_cap_len);
3807 if (session_info == NULL) {
3808 wpa_msg_global(wpa_s, MSG_INFO,
3809 P2P_EVENT_P2PS_PROVISION_START MACSTR
3810 " adv_id=%x conncap=%x"
3812 " session=%x mac=" MACSTR
3813 " dev_passwd_id=%d%s",
3814 MAC2STR(dev), adv_id, conncap,
3816 ses_id, MAC2STR(ses_mac),
3817 passwd_id, feat_cap_str);
3819 wpa_msg_global(wpa_s, MSG_INFO,
3820 P2P_EVENT_P2PS_PROVISION_START MACSTR
3821 " adv_id=%x conncap=%x"
3823 " session=%x mac=" MACSTR
3824 " dev_passwd_id=%d info='%s'%s",
3825 MAC2STR(dev), adv_id, conncap,
3827 ses_id, MAC2STR(ses_mac),
3828 passwd_id, session_info, feat_cap_str);
3833 go_wpa_s = wpas_p2p_get_go_group(wpa_s);
3834 persistent_go = wpas_p2p_get_persistent_go(wpa_s);
3836 if (status && status != P2P_SC_SUCCESS_DEFERRED) {
3837 if (go_wpa_s && !p2p_group_go_member_count(wpa_s))
3838 wpas_p2p_group_remove(wpa_s, go_wpa_s->ifname);
3840 if (persistent_go && !persistent_go->num_p2p_clients) {
3841 /* remove empty persistent GO */
3842 wpa_config_remove_network(wpa_s->conf,
3846 wpa_msg_global(wpa_s, MSG_INFO,
3847 P2P_EVENT_P2PS_PROVISION_DONE MACSTR
3849 " adv_id=%x adv_mac=" MACSTR
3850 " session=%x mac=" MACSTR "%s",
3851 MAC2STR(dev), status,
3852 adv_id, MAC2STR(adv_mac),
3853 ses_id, MAC2STR(ses_mac), feat_cap_str);
3857 /* Clean up stale persistent groups with this device */
3858 s = wpas_p2p_get_persistent(wpa_s, dev, persist_ssid,
3861 if (persist_ssid && s && s->mode != WPAS_MODE_P2P_GO &&
3862 is_zero_ether_addr(grp_mac)) {
3863 wpa_dbg(wpa_s, MSG_ERROR,
3864 "P2P: Peer device is a GO in a persistent group, but it did not provide the intended MAC address");
3869 stale = wpas_p2p_get_persistent(wpa_s, dev, NULL, 0);
3873 if (s && s->ssid_len == stale->ssid_len &&
3874 os_memcmp(stale->bssid, s->bssid, ETH_ALEN) == 0 &&
3875 os_memcmp(stale->ssid, s->ssid, s->ssid_len) == 0)
3878 /* Remove stale persistent group */
3879 if (stale->mode != WPAS_MODE_P2P_GO ||
3880 stale->num_p2p_clients <= 1) {
3881 wpa_config_remove_network(wpa_s->conf, stale->id);
3885 for (i = 0; i < stale->num_p2p_clients; i++) {
3886 if (os_memcmp(stale->p2p_client_list +
3888 dev, ETH_ALEN) == 0) {
3889 os_memmove(stale->p2p_client_list +
3891 stale->p2p_client_list +
3893 (stale->num_p2p_clients -
3898 stale->num_p2p_clients--;
3904 p2p_config_write(wpa_s);
3907 if (go_wpa_s && !p2p_group_go_member_count(wpa_s))
3908 wpas_p2p_group_remove(wpa_s, go_wpa_s->ifname);
3910 if (persistent_go && s != persistent_go &&
3911 !persistent_go->num_p2p_clients) {
3912 /* remove empty persistent GO */
3913 wpa_config_remove_network(wpa_s->conf,
3918 wpa_msg_global(wpa_s, MSG_INFO,
3919 P2P_EVENT_P2PS_PROVISION_DONE MACSTR
3921 " adv_id=%x adv_mac=" MACSTR
3922 " session=%x mac=" MACSTR
3924 MAC2STR(dev), status,
3925 adv_id, MAC2STR(adv_mac),
3926 ses_id, MAC2STR(ses_mac), s->id, feat_cap_str);
3930 if (conncap == P2PS_SETUP_GROUP_OWNER) {
3932 * We need to copy the interface name. Simply saving a
3933 * pointer isn't enough, since if we use pending_interface_name
3934 * it will be overwritten when the group is added.
3936 char go_ifname[100];
3938 go_ifname[0] = '\0';
3940 wpa_s->global->pending_p2ps_group = 1;
3942 if (!wpas_p2p_create_iface(wpa_s))
3943 os_memcpy(go_ifname, wpa_s->ifname,
3945 else if (wpa_s->pending_interface_name[0])
3946 os_memcpy(go_ifname,
3947 wpa_s->pending_interface_name,
3950 if (!go_ifname[0]) {
3951 wpas_p2ps_prov_complete(
3952 wpa_s, P2P_SC_FAIL_UNKNOWN_GROUP,
3953 dev, adv_mac, ses_mac,
3954 grp_mac, adv_id, ses_id, 0, 0,
3955 NULL, 0, 0, 0, NULL, NULL, 0);
3959 /* If PD Resp complete, start up the GO */
3960 if (response_done && persistent_go) {
3961 wpas_p2p_group_add_persistent(
3962 wpa_s, persistent_go,
3963 0, 0, 0, 0, 0, NULL,
3964 persistent_go->mode ==
3966 P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE :
3968 } else if (response_done) {
3969 wpas_p2p_group_add(wpa_s, 1, 0, 0, 0);
3972 if (passwd_id == DEV_PW_P2PS_DEFAULT) {
3973 os_memcpy(wpa_s->p2ps_join_addr, grp_mac,
3975 wpa_s->p2ps_method_config_any = 1;
3977 } else if (passwd_id == DEV_PW_P2PS_DEFAULT) {
3978 os_memcpy(go_ifname, go_wpa_s->ifname,
3981 if (is_zero_ether_addr(grp_mac)) {
3982 wpa_dbg(go_wpa_s, MSG_DEBUG,
3983 "P2P: Setting PIN-1 for ANY");
3984 wpa_supplicant_ap_wps_pin(go_wpa_s, NULL,
3985 "12345670", NULL, 0,
3988 wpa_dbg(go_wpa_s, MSG_DEBUG,
3989 "P2P: Setting PIN-1 for " MACSTR,
3991 wpa_supplicant_ap_wps_pin(go_wpa_s, grp_mac,
3992 "12345670", NULL, 0,
3996 os_memcpy(wpa_s->p2ps_join_addr, grp_mac, ETH_ALEN);
3997 wpa_s->p2ps_method_config_any = 1;
4000 wpa_msg_global(wpa_s, MSG_INFO,
4001 P2P_EVENT_P2PS_PROVISION_DONE MACSTR
4002 " status=%d conncap=%x"
4003 " adv_id=%x adv_mac=" MACSTR
4004 " session=%x mac=" MACSTR
4005 " dev_passwd_id=%d go=%s%s",
4006 MAC2STR(dev), status, conncap,
4007 adv_id, MAC2STR(adv_mac),
4008 ses_id, MAC2STR(ses_mac),
4009 passwd_id, go_ifname, feat_cap_str);
4013 if (go_wpa_s && !p2p_group_go_member_count(wpa_s))
4014 wpas_p2p_group_remove(wpa_s, go_wpa_s->ifname);
4016 if (persistent_go && !persistent_go->num_p2p_clients) {
4017 /* remove empty persistent GO */
4018 wpa_config_remove_network(wpa_s->conf, persistent_go->id);
4021 if (conncap == P2PS_SETUP_CLIENT) {
4022 wpa_msg_global(wpa_s, MSG_INFO,
4023 P2P_EVENT_P2PS_PROVISION_DONE MACSTR
4024 " status=%d conncap=%x"
4025 " adv_id=%x adv_mac=" MACSTR
4026 " session=%x mac=" MACSTR
4027 " dev_passwd_id=%d join=" MACSTR "%s",
4028 MAC2STR(dev), status, conncap,
4029 adv_id, MAC2STR(adv_mac),
4030 ses_id, MAC2STR(ses_mac),
4031 passwd_id, MAC2STR(grp_mac), feat_cap_str);
4033 wpa_msg_global(wpa_s, MSG_INFO,
4034 P2P_EVENT_P2PS_PROVISION_DONE MACSTR
4035 " status=%d conncap=%x"
4036 " adv_id=%x adv_mac=" MACSTR
4037 " session=%x mac=" MACSTR
4038 " dev_passwd_id=%d%s",
4039 MAC2STR(dev), status, conncap,
4040 adv_id, MAC2STR(adv_mac),
4041 ses_id, MAC2STR(ses_mac),
4042 passwd_id, feat_cap_str);
4047 static int _wpas_p2p_in_progress(void *ctx)
4049 struct wpa_supplicant *wpa_s = ctx;
4050 return wpas_p2p_in_progress(wpa_s);
4054 static int wpas_prov_disc_resp_cb(void *ctx)
4056 struct wpa_supplicant *wpa_s = ctx;
4057 struct wpa_ssid *persistent_go;
4059 if (!wpa_s->global->pending_p2ps_group)
4062 wpa_s->global->pending_p2ps_group = 0;
4064 if (wpas_p2p_get_go_group(wpa_s))
4066 persistent_go = wpas_p2p_get_persistent_go(wpa_s);
4068 if (persistent_go) {
4069 wpas_p2p_group_add_persistent(
4070 wpa_s, persistent_go, 0, 0, 0, 0, 0, NULL,
4071 persistent_go->mode == WPAS_MODE_P2P_GO ?
4072 P2P_MAX_INITIAL_CONN_WAIT_GO_REINVOKE : 0, 0);
4074 wpas_p2p_group_add(wpa_s, 1, 0, 0, 0);
4081 static int wpas_p2p_get_pref_freq_list(void *ctx, int go,
4083 unsigned int *freq_list)
4085 struct wpa_supplicant *wpa_s = ctx;
4087 return wpa_drv_get_pref_freq_list(wpa_s, go ? WPA_IF_P2P_GO :
4088 WPA_IF_P2P_CLIENT, len, freq_list);
4093 * wpas_p2p_init - Initialize P2P module for %wpa_supplicant
4094 * @global: Pointer to global data from wpa_supplicant_init()
4095 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
4096 * Returns: 0 on success, -1 on failure
4098 int wpas_p2p_init(struct wpa_global *global, struct wpa_supplicant *wpa_s)
4100 struct p2p_config p2p;
4103 if (wpa_s->conf->p2p_disabled)
4106 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_CAPABLE))
4112 os_memset(&p2p, 0, sizeof(p2p));
4114 p2p.debug_print = wpas_p2p_debug_print;
4115 p2p.p2p_scan = wpas_p2p_scan;
4116 p2p.send_action = wpas_send_action;
4117 p2p.send_action_done = wpas_send_action_done;
4118 p2p.go_neg_completed = wpas_go_neg_completed;
4119 p2p.go_neg_req_rx = wpas_go_neg_req_rx;
4120 p2p.dev_found = wpas_dev_found;
4121 p2p.dev_lost = wpas_dev_lost;
4122 p2p.find_stopped = wpas_find_stopped;
4123 p2p.start_listen = wpas_start_listen;
4124 p2p.stop_listen = wpas_stop_listen;
4125 p2p.send_probe_resp = wpas_send_probe_resp;
4126 p2p.sd_request = wpas_sd_request;
4127 p2p.sd_response = wpas_sd_response;
4128 p2p.prov_disc_req = wpas_prov_disc_req;
4129 p2p.prov_disc_resp = wpas_prov_disc_resp;
4130 p2p.prov_disc_fail = wpas_prov_disc_fail;
4131 p2p.invitation_process = wpas_invitation_process;
4132 p2p.invitation_received = wpas_invitation_received;
4133 p2p.invitation_result = wpas_invitation_result;
4134 p2p.get_noa = wpas_get_noa;
4135 p2p.go_connected = wpas_go_connected;
4136 p2p.presence_resp = wpas_presence_resp;
4137 p2p.is_concurrent_session_active = wpas_is_concurrent_session_active;
4138 p2p.is_p2p_in_progress = _wpas_p2p_in_progress;
4139 p2p.get_persistent_group = wpas_get_persistent_group;
4140 p2p.get_go_info = wpas_get_go_info;
4141 p2p.remove_stale_groups = wpas_remove_stale_groups;
4142 p2p.p2ps_prov_complete = wpas_p2ps_prov_complete;
4143 p2p.prov_disc_resp_cb = wpas_prov_disc_resp_cb;
4144 p2p.p2ps_group_capability = p2ps_group_capability;
4145 p2p.get_pref_freq_list = wpas_p2p_get_pref_freq_list;
4147 os_memcpy(wpa_s->global->p2p_dev_addr, wpa_s->own_addr, ETH_ALEN);
4148 os_memcpy(p2p.dev_addr, wpa_s->global->p2p_dev_addr, ETH_ALEN);
4149 p2p.dev_name = wpa_s->conf->device_name;
4150 p2p.manufacturer = wpa_s->conf->manufacturer;
4151 p2p.model_name = wpa_s->conf->model_name;
4152 p2p.model_number = wpa_s->conf->model_number;
4153 p2p.serial_number = wpa_s->conf->serial_number;
4155 os_memcpy(p2p.uuid, wpa_s->wps->uuid, 16);
4156 p2p.config_methods = wpa_s->wps->config_methods;
4159 if (wpas_p2p_setup_channels(wpa_s, &p2p.channels, &p2p.cli_channels)) {
4160 wpa_printf(MSG_ERROR,
4161 "P2P: Failed to configure supported channel list");
4165 if (wpa_s->conf->p2p_listen_reg_class &&
4166 wpa_s->conf->p2p_listen_channel) {
4167 p2p.reg_class = wpa_s->conf->p2p_listen_reg_class;
4168 p2p.channel = wpa_s->conf->p2p_listen_channel;
4169 p2p.channel_forced = 1;
4172 * Pick one of the social channels randomly as the listen
4175 if (p2p_config_get_random_social(&p2p, &p2p.reg_class,
4176 &p2p.channel) != 0) {
4177 wpa_printf(MSG_INFO,
4178 "P2P: No social channels supported by the driver - do not enable P2P");
4181 p2p.channel_forced = 0;
4183 wpa_printf(MSG_DEBUG, "P2P: Own listen channel: %d:%d",
4184 p2p.reg_class, p2p.channel);
4186 if (wpa_s->conf->p2p_oper_reg_class &&
4187 wpa_s->conf->p2p_oper_channel) {
4188 p2p.op_reg_class = wpa_s->conf->p2p_oper_reg_class;
4189 p2p.op_channel = wpa_s->conf->p2p_oper_channel;
4190 p2p.cfg_op_channel = 1;
4191 wpa_printf(MSG_DEBUG, "P2P: Configured operating channel: "
4192 "%d:%d", p2p.op_reg_class, p2p.op_channel);
4196 * Use random operation channel from 2.4 GHz band social
4197 * channels (1, 6, 11) or band 60 GHz social channel (2) if no
4198 * other preference is indicated.
4200 if (p2p_config_get_random_social(&p2p, &p2p.op_reg_class,
4201 &p2p.op_channel) != 0) {
4202 wpa_printf(MSG_ERROR,
4203 "P2P: Failed to select random social channel as operation channel");
4206 p2p.cfg_op_channel = 0;
4207 wpa_printf(MSG_DEBUG, "P2P: Random operating channel: "
4208 "%d:%d", p2p.op_reg_class, p2p.op_channel);
4211 if (wpa_s->conf->p2p_pref_chan && wpa_s->conf->num_p2p_pref_chan) {
4212 p2p.pref_chan = wpa_s->conf->p2p_pref_chan;
4213 p2p.num_pref_chan = wpa_s->conf->num_p2p_pref_chan;
4216 if (wpa_s->conf->country[0] && wpa_s->conf->country[1]) {
4217 os_memcpy(p2p.country, wpa_s->conf->country, 2);
4218 p2p.country[2] = 0x04;
4220 os_memcpy(p2p.country, "XX\x04", 3);
4222 os_memcpy(p2p.pri_dev_type, wpa_s->conf->device_type,
4225 p2p.num_sec_dev_types = wpa_s->conf->num_sec_device_types;
4226 os_memcpy(p2p.sec_dev_type, wpa_s->conf->sec_device_type,
4227 p2p.num_sec_dev_types * WPS_DEV_TYPE_LEN);
4229 p2p.concurrent_operations = !!(wpa_s->drv_flags &
4230 WPA_DRIVER_FLAGS_P2P_CONCURRENT);
4232 p2p.max_peers = 100;
4234 if (wpa_s->conf->p2p_ssid_postfix) {
4235 p2p.ssid_postfix_len =
4236 os_strlen(wpa_s->conf->p2p_ssid_postfix);
4237 if (p2p.ssid_postfix_len > sizeof(p2p.ssid_postfix))
4238 p2p.ssid_postfix_len = sizeof(p2p.ssid_postfix);
4239 os_memcpy(p2p.ssid_postfix, wpa_s->conf->p2p_ssid_postfix,
4240 p2p.ssid_postfix_len);
4243 p2p.p2p_intra_bss = wpa_s->conf->p2p_intra_bss;
4245 p2p.max_listen = wpa_s->max_remain_on_chan;
4247 if (wpa_s->conf->p2p_passphrase_len >= 8 &&
4248 wpa_s->conf->p2p_passphrase_len <= 63)
4249 p2p.passphrase_len = wpa_s->conf->p2p_passphrase_len;
4251 p2p.passphrase_len = 8;
4253 global->p2p = p2p_init(&p2p);
4254 if (global->p2p == NULL)
4256 global->p2p_init_wpa_s = wpa_s;
4258 for (i = 0; i < MAX_WPS_VENDOR_EXT; i++) {
4259 if (wpa_s->conf->wps_vendor_ext[i] == NULL)
4261 p2p_add_wps_vendor_extension(
4262 global->p2p, wpa_s->conf->wps_vendor_ext[i]);
4265 p2p_set_no_go_freq(global->p2p, &wpa_s->conf->p2p_no_go_freq);
4272 * wpas_p2p_deinit - Deinitialize per-interface P2P data
4273 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
4275 * This function deinitialize per-interface P2P data.
4277 void wpas_p2p_deinit(struct wpa_supplicant *wpa_s)
4279 if (wpa_s->driver && wpa_s->drv_priv)
4280 wpa_drv_probe_req_report(wpa_s, 0);
4282 if (wpa_s->go_params) {
4283 /* Clear any stored provisioning info */
4284 p2p_clear_provisioning_info(
4286 wpa_s->go_params->peer_device_addr);
4289 os_free(wpa_s->go_params);
4290 wpa_s->go_params = NULL;
4291 eloop_cancel_timeout(wpas_p2p_psk_failure_removal, wpa_s, NULL);
4292 eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s, NULL);
4293 eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL);
4294 wpa_s->p2p_long_listen = 0;
4295 eloop_cancel_timeout(wpas_p2p_long_listen_timeout, wpa_s, NULL);
4296 eloop_cancel_timeout(wpas_p2p_group_idle_timeout, wpa_s, NULL);
4297 wpas_p2p_remove_pending_group_interface(wpa_s);
4298 eloop_cancel_timeout(wpas_p2p_group_freq_conflict, wpa_s, NULL);
4299 wpas_p2p_listen_work_done(wpa_s);
4300 if (wpa_s->p2p_send_action_work) {
4301 os_free(wpa_s->p2p_send_action_work->ctx);
4302 radio_work_done(wpa_s->p2p_send_action_work);
4303 wpa_s->p2p_send_action_work = NULL;
4305 eloop_cancel_timeout(wpas_p2p_send_action_work_timeout, wpa_s, NULL);
4307 wpabuf_free(wpa_s->p2p_oob_dev_pw);
4308 wpa_s->p2p_oob_dev_pw = NULL;
4310 os_free(wpa_s->p2p_group_common_freqs);
4311 wpa_s->p2p_group_common_freqs = NULL;
4312 wpa_s->p2p_group_common_freqs_num = 0;
4314 /* TODO: remove group interface from the driver if this wpa_s instance
4315 * is on top of a P2P group interface */
4320 * wpas_p2p_deinit_global - Deinitialize global P2P module
4321 * @global: Pointer to global data from wpa_supplicant_init()
4323 * This function deinitializes the global (per device) P2P module.
4325 static void wpas_p2p_deinit_global(struct wpa_global *global)
4327 struct wpa_supplicant *wpa_s, *tmp;
4329 wpa_s = global->ifaces;
4331 wpas_p2p_service_flush(global->p2p_init_wpa_s);
4333 /* Remove remaining P2P group interfaces */
4334 while (wpa_s && wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE)
4335 wpa_s = wpa_s->next;
4337 tmp = global->ifaces;
4340 tmp->p2p_group_interface == NOT_P2P_GROUP_INTERFACE)) {
4345 /* Disconnect from the P2P group and deinit the interface */
4346 wpas_p2p_disconnect(tmp);
4350 * Deinit GO data on any possibly remaining interface (if main
4351 * interface is used as GO).
4353 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
4354 if (wpa_s->ap_iface)
4355 wpas_p2p_group_deinit(wpa_s);
4358 p2p_deinit(global->p2p);
4360 global->p2p_init_wpa_s = NULL;
4364 static int wpas_p2p_create_iface(struct wpa_supplicant *wpa_s)
4366 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) &&
4367 wpa_s->conf->p2p_no_group_iface)
4368 return 0; /* separate interface disabled per configuration */
4369 if (wpa_s->drv_flags &
4370 (WPA_DRIVER_FLAGS_P2P_DEDICATED_INTERFACE |
4371 WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P))
4372 return 1; /* P2P group requires a new interface in every case
4374 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_CONCURRENT))
4375 return 0; /* driver does not support concurrent operations */
4376 if (wpa_s->global->ifaces->next)
4377 return 1; /* more that one interface already in use */
4378 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
4379 return 1; /* this interface is already in use */
4384 static int wpas_p2p_start_go_neg(struct wpa_supplicant *wpa_s,
4385 const u8 *peer_addr,
4386 enum p2p_wps_method wps_method,
4387 int go_intent, const u8 *own_interface_addr,
4388 unsigned int force_freq, int persistent_group,
4389 struct wpa_ssid *ssid, unsigned int pref_freq)
4391 if (persistent_group && wpa_s->conf->persistent_reconnect)
4392 persistent_group = 2;
4395 * Increase GO config timeout if HT40 is used since it takes some time
4396 * to scan channels for coex purposes before the BSS can be started.
4398 p2p_set_config_timeout(wpa_s->global->p2p,
4399 wpa_s->p2p_go_ht40 ? 255 : 100, 20);
4401 return p2p_connect(wpa_s->global->p2p, peer_addr, wps_method,
4402 go_intent, own_interface_addr, force_freq,
4403 persistent_group, ssid ? ssid->ssid : NULL,
4404 ssid ? ssid->ssid_len : 0,
4405 wpa_s->p2p_pd_before_go_neg, pref_freq,
4406 wps_method == WPS_NFC ? wpa_s->p2p_oob_dev_pw_id :
4411 static int wpas_p2p_auth_go_neg(struct wpa_supplicant *wpa_s,
4412 const u8 *peer_addr,
4413 enum p2p_wps_method wps_method,
4414 int go_intent, const u8 *own_interface_addr,
4415 unsigned int force_freq, int persistent_group,
4416 struct wpa_ssid *ssid, unsigned int pref_freq)
4418 if (persistent_group && wpa_s->conf->persistent_reconnect)
4419 persistent_group = 2;
4421 return p2p_authorize(wpa_s->global->p2p, peer_addr, wps_method,
4422 go_intent, own_interface_addr, force_freq,
4423 persistent_group, ssid ? ssid->ssid : NULL,
4424 ssid ? ssid->ssid_len : 0, pref_freq,
4425 wps_method == WPS_NFC ? wpa_s->p2p_oob_dev_pw_id :
4430 static void wpas_p2p_check_join_scan_limit(struct wpa_supplicant *wpa_s)
4432 wpa_s->p2p_join_scan_count++;
4433 wpa_printf(MSG_DEBUG, "P2P: Join scan attempt %d",
4434 wpa_s->p2p_join_scan_count);
4435 if (wpa_s->p2p_join_scan_count > P2P_MAX_JOIN_SCAN_ATTEMPTS) {
4436 wpa_printf(MSG_DEBUG, "P2P: Failed to find GO " MACSTR
4437 " for join operationg - stop join attempt",
4438 MAC2STR(wpa_s->pending_join_iface_addr));
4439 eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL);
4440 if (wpa_s->p2p_auto_pd) {
4441 wpa_s->p2p_auto_pd = 0;
4442 wpa_msg_global(wpa_s, MSG_INFO,
4443 P2P_EVENT_PROV_DISC_FAILURE
4444 " p2p_dev_addr=" MACSTR " status=N/A",
4445 MAC2STR(wpa_s->pending_join_dev_addr));
4448 wpa_msg_global(wpa_s->parent, MSG_INFO,
4449 P2P_EVENT_GROUP_FORMATION_FAILURE);
4450 wpas_notify_p2p_group_formation_failure(wpa_s, "");
4455 static int wpas_check_freq_conflict(struct wpa_supplicant *wpa_s, int freq)
4458 unsigned int num, i;
4459 struct wpa_used_freq_data *freqs;
4461 if (wpas_p2p_num_unused_channels(wpa_s) > 0) {
4462 /* Multiple channels are supported and not all are in use */
4466 freqs = os_calloc(wpa_s->num_multichan_concurrent,
4467 sizeof(struct wpa_used_freq_data));
4471 num = wpas_p2p_valid_oper_freqs(wpa_s, freqs,
4472 wpa_s->num_multichan_concurrent);
4474 for (i = 0; i < num; i++) {
4475 if (freqs[i].freq == freq) {
4476 wpa_printf(MSG_DEBUG, "P2P: Frequency %d MHz in use by another virtual interface and can be used",
4483 wpa_printf(MSG_DEBUG, "P2P: No valid operating frequencies");
4492 static int wpas_p2p_peer_go(struct wpa_supplicant *wpa_s,
4493 const u8 *peer_dev_addr)
4495 struct wpa_bss *bss;
4498 bss = wpa_bss_get_p2p_dev_addr(wpa_s, peer_dev_addr);
4501 if (bss->last_update_idx < wpa_s->bss_update_idx) {
4502 wpa_printf(MSG_DEBUG, "P2P: Peer BSS entry not updated in the "
4507 updated = os_reltime_before(&wpa_s->p2p_auto_started,
4509 wpa_printf(MSG_DEBUG, "P2P: Current BSS entry for peer updated at "
4510 "%ld.%06ld (%supdated in last scan)",
4511 bss->last_update.sec, bss->last_update.usec,
4512 updated ? "": "not ");
4518 static void wpas_p2p_scan_res_join(struct wpa_supplicant *wpa_s,
4519 struct wpa_scan_results *scan_res)
4521 struct wpa_bss *bss = NULL;
4523 u8 iface_addr[ETH_ALEN];
4525 eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL);
4527 if (wpa_s->global->p2p_disabled)
4530 wpa_printf(MSG_DEBUG, "P2P: Scan results received (%d BSS) for %sjoin",
4531 scan_res ? (int) scan_res->num : -1,
4532 wpa_s->p2p_auto_join ? "auto_" : "");
4535 wpas_p2p_scan_res_handler(wpa_s, scan_res);
4537 if (wpa_s->p2p_auto_pd) {
4538 int join = wpas_p2p_peer_go(wpa_s,
4539 wpa_s->pending_join_dev_addr);
4541 wpa_s->auto_pd_scan_retry < P2P_AUTO_PD_SCAN_ATTEMPTS) {
4542 wpa_s->auto_pd_scan_retry++;
4543 bss = wpa_bss_get_bssid_latest(
4544 wpa_s, wpa_s->pending_join_dev_addr);
4547 wpa_printf(MSG_DEBUG, "P2P: Scan retry %d for "
4548 "the peer " MACSTR " at %d MHz",
4549 wpa_s->auto_pd_scan_retry,
4551 pending_join_dev_addr),
4553 wpas_p2p_join_scan_req(wpa_s, freq, NULL, 0);
4561 wpa_s->p2p_auto_pd = 0;
4562 wpa_s->pending_pd_use = join ? AUTO_PD_JOIN : AUTO_PD_GO_NEG;
4563 wpa_printf(MSG_DEBUG, "P2P: Auto PD with " MACSTR " join=%d",
4564 MAC2STR(wpa_s->pending_join_dev_addr), join);
4565 if (p2p_prov_disc_req(wpa_s->global->p2p,
4566 wpa_s->pending_join_dev_addr, NULL,
4567 wpa_s->pending_pd_config_methods, join,
4568 0, wpa_s->user_initiated_pd) < 0) {
4569 wpa_s->p2p_auto_pd = 0;
4570 wpa_msg_global(wpa_s, MSG_INFO,
4571 P2P_EVENT_PROV_DISC_FAILURE
4572 " p2p_dev_addr=" MACSTR " status=N/A",
4573 MAC2STR(wpa_s->pending_join_dev_addr));
4578 if (wpa_s->p2p_auto_join) {
4579 int join = wpas_p2p_peer_go(wpa_s,
4580 wpa_s->pending_join_dev_addr);
4582 wpa_printf(MSG_DEBUG, "P2P: Peer was not found to be "
4583 "running a GO -> use GO Negotiation");
4584 wpa_msg_global(wpa_s->parent, MSG_INFO,
4585 P2P_EVENT_FALLBACK_TO_GO_NEG
4586 "reason=peer-not-running-GO");
4587 wpas_p2p_connect(wpa_s, wpa_s->pending_join_dev_addr,
4588 wpa_s->p2p_pin, wpa_s->p2p_wps_method,
4589 wpa_s->p2p_persistent_group, 0, 0, 0,
4590 wpa_s->p2p_go_intent,
4591 wpa_s->p2p_connect_freq,
4592 wpa_s->p2p_persistent_id,
4593 wpa_s->p2p_pd_before_go_neg,
4599 wpa_printf(MSG_DEBUG, "P2P: Peer was found running GO%s -> "
4600 "try to join the group", join ? "" :
4603 wpa_msg_global(wpa_s->parent, MSG_INFO,
4604 P2P_EVENT_FALLBACK_TO_GO_NEG_ENABLED);
4605 wpa_s->p2p_fallback_to_go_neg = 1;
4609 freq = p2p_get_oper_freq(wpa_s->global->p2p,
4610 wpa_s->pending_join_iface_addr);
4612 p2p_get_interface_addr(wpa_s->global->p2p,
4613 wpa_s->pending_join_dev_addr,
4615 os_memcmp(iface_addr, wpa_s->pending_join_dev_addr, ETH_ALEN) != 0
4616 && !wpa_bss_get_bssid(wpa_s, wpa_s->pending_join_iface_addr)) {
4617 wpa_printf(MSG_DEBUG, "P2P: Overwrite pending interface "
4618 "address for join from " MACSTR " to " MACSTR
4619 " based on newly discovered P2P peer entry",
4620 MAC2STR(wpa_s->pending_join_iface_addr),
4621 MAC2STR(iface_addr));
4622 os_memcpy(wpa_s->pending_join_iface_addr, iface_addr,
4625 freq = p2p_get_oper_freq(wpa_s->global->p2p,
4626 wpa_s->pending_join_iface_addr);
4629 wpa_printf(MSG_DEBUG, "P2P: Target GO operating frequency "
4630 "from P2P peer table: %d MHz", freq);
4632 if (wpa_s->p2p_join_ssid_len) {
4633 wpa_printf(MSG_DEBUG, "P2P: Trying to find target GO BSS entry based on BSSID "
4634 MACSTR " and SSID %s",
4635 MAC2STR(wpa_s->pending_join_iface_addr),
4636 wpa_ssid_txt(wpa_s->p2p_join_ssid,
4637 wpa_s->p2p_join_ssid_len));
4638 bss = wpa_bss_get(wpa_s, wpa_s->pending_join_iface_addr,
4639 wpa_s->p2p_join_ssid,
4640 wpa_s->p2p_join_ssid_len);
4643 wpa_printf(MSG_DEBUG, "P2P: Trying to find target GO BSS entry based on BSSID "
4644 MACSTR, MAC2STR(wpa_s->pending_join_iface_addr));
4645 bss = wpa_bss_get_bssid_latest(wpa_s,
4646 wpa_s->pending_join_iface_addr);
4649 u8 dev_addr[ETH_ALEN];
4652 wpa_printf(MSG_DEBUG, "P2P: Target GO operating frequency "
4653 "from BSS table: %d MHz (SSID %s)", freq,
4654 wpa_ssid_txt(bss->ssid, bss->ssid_len));
4655 if (p2p_parse_dev_addr((const u8 *) (bss + 1), bss->ie_len,
4657 os_memcmp(wpa_s->pending_join_dev_addr,
4658 wpa_s->pending_join_iface_addr, ETH_ALEN) == 0 &&
4659 os_memcmp(dev_addr, wpa_s->pending_join_dev_addr,
4661 wpa_printf(MSG_DEBUG,
4662 "P2P: Update target GO device address based on BSS entry: " MACSTR " (was " MACSTR ")",
4664 MAC2STR(wpa_s->pending_join_dev_addr));
4665 os_memcpy(wpa_s->pending_join_dev_addr, dev_addr,
4672 if (wpas_check_freq_conflict(wpa_s, freq) > 0) {
4673 wpa_msg_global(wpa_s->parent, MSG_INFO,
4674 P2P_EVENT_GROUP_FORMATION_FAILURE
4675 "reason=FREQ_CONFLICT");
4676 wpas_notify_p2p_group_formation_failure(
4677 wpa_s, "FREQ_CONFLICT");
4681 wpa_printf(MSG_DEBUG, "P2P: Send Provision Discovery Request "
4682 "prior to joining an existing group (GO " MACSTR
4684 MAC2STR(wpa_s->pending_join_dev_addr), freq);
4685 wpa_s->pending_pd_before_join = 1;
4687 switch (wpa_s->pending_join_wps_method) {
4688 case WPS_PIN_DISPLAY:
4689 method = WPS_CONFIG_KEYPAD;
4691 case WPS_PIN_KEYPAD:
4692 method = WPS_CONFIG_DISPLAY;
4695 method = WPS_CONFIG_PUSHBUTTON;
4698 method = WPS_CONFIG_P2PS;
4705 if ((p2p_get_provisioning_info(wpa_s->global->p2p,
4706 wpa_s->pending_join_dev_addr) ==
4709 * We have already performed provision discovery for
4710 * joining the group. Proceed directly to join
4711 * operation without duplicated provision discovery. */
4712 wpa_printf(MSG_DEBUG, "P2P: Provision discovery "
4713 "with " MACSTR " already done - proceed to "
4715 MAC2STR(wpa_s->pending_join_dev_addr));
4716 wpa_s->pending_pd_before_join = 0;
4720 if (p2p_prov_disc_req(wpa_s->global->p2p,
4721 wpa_s->pending_join_dev_addr,
4723 freq, wpa_s->user_initiated_pd) < 0) {
4724 wpa_printf(MSG_DEBUG, "P2P: Failed to send Provision "
4725 "Discovery Request before joining an "
4727 wpa_s->pending_pd_before_join = 0;
4733 wpa_printf(MSG_DEBUG, "P2P: Failed to find BSS/GO - try again later");
4734 eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL);
4735 eloop_register_timeout(1, 0, wpas_p2p_join_scan, wpa_s, NULL);
4736 wpas_p2p_check_join_scan_limit(wpa_s);
4740 /* Start join operation immediately */
4741 wpas_p2p_join_start(wpa_s, 0, NULL, 0);
4745 static void wpas_p2p_join_scan_req(struct wpa_supplicant *wpa_s, int freq,
4746 const u8 *ssid, size_t ssid_len)
4749 struct wpa_driver_scan_params params;
4750 struct wpabuf *wps_ie, *ies;
4752 int freqs[2] = { 0, 0 };
4754 os_memset(¶ms, 0, sizeof(params));
4756 /* P2P Wildcard SSID */
4757 params.num_ssids = 1;
4758 if (ssid && ssid_len) {
4759 params.ssids[0].ssid = ssid;
4760 params.ssids[0].ssid_len = ssid_len;
4761 os_memcpy(wpa_s->p2p_join_ssid, ssid, ssid_len);
4762 wpa_s->p2p_join_ssid_len = ssid_len;
4764 params.ssids[0].ssid = (u8 *) P2P_WILDCARD_SSID;
4765 params.ssids[0].ssid_len = P2P_WILDCARD_SSID_LEN;
4766 wpa_s->p2p_join_ssid_len = 0;
4769 wpa_s->wps->dev.p2p = 1;
4770 wps_ie = wps_build_probe_req_ie(DEV_PW_DEFAULT, &wpa_s->wps->dev,
4771 wpa_s->wps->uuid, WPS_REQ_ENROLLEE, 0,
4773 if (wps_ie == NULL) {
4774 wpas_p2p_scan_res_join(wpa_s, NULL);
4778 ielen = p2p_scan_ie_buf_len(wpa_s->global->p2p);
4779 ies = wpabuf_alloc(wpabuf_len(wps_ie) + ielen);
4781 wpabuf_free(wps_ie);
4782 wpas_p2p_scan_res_join(wpa_s, NULL);
4785 wpabuf_put_buf(ies, wps_ie);
4786 wpabuf_free(wps_ie);
4788 p2p_scan_ie(wpa_s->global->p2p, ies, NULL);
4790 params.p2p_probe = 1;
4791 params.extra_ies = wpabuf_head(ies);
4792 params.extra_ies_len = wpabuf_len(ies);
4797 * If freq is not provided, check the operating freq of the GO
4798 * and use a single channel scan on if possible.
4800 oper_freq = p2p_get_oper_freq(wpa_s->global->p2p,
4801 wpa_s->pending_join_iface_addr);
4807 params.freqs = freqs;
4811 * Run a scan to update BSS table and start Provision Discovery once
4812 * the new scan results become available.
4814 ret = wpa_drv_scan(wpa_s, ¶ms);
4816 os_get_reltime(&wpa_s->scan_trigger_time);
4817 wpa_s->scan_res_handler = wpas_p2p_scan_res_join;
4818 wpa_s->own_scan_requested = 1;
4824 wpa_printf(MSG_DEBUG, "P2P: Failed to start scan for join - "
4826 eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL);
4827 eloop_register_timeout(1, 0, wpas_p2p_join_scan, wpa_s, NULL);
4828 wpas_p2p_check_join_scan_limit(wpa_s);
4833 static void wpas_p2p_join_scan(void *eloop_ctx, void *timeout_ctx)
4835 struct wpa_supplicant *wpa_s = eloop_ctx;
4836 wpas_p2p_join_scan_req(wpa_s, 0, NULL, 0);
4840 static int wpas_p2p_join(struct wpa_supplicant *wpa_s, const u8 *iface_addr,
4841 const u8 *dev_addr, enum p2p_wps_method wps_method,
4842 int auto_join, int op_freq,
4843 const u8 *ssid, size_t ssid_len)
4845 wpa_printf(MSG_DEBUG, "P2P: Request to join existing group (iface "
4846 MACSTR " dev " MACSTR " op_freq=%d)%s",
4847 MAC2STR(iface_addr), MAC2STR(dev_addr), op_freq,
4848 auto_join ? " (auto_join)" : "");
4849 if (ssid && ssid_len) {
4850 wpa_printf(MSG_DEBUG, "P2P: Group SSID specified: %s",
4851 wpa_ssid_txt(ssid, ssid_len));
4854 wpa_s->p2p_auto_pd = 0;
4855 wpa_s->p2p_auto_join = !!auto_join;
4856 os_memcpy(wpa_s->pending_join_iface_addr, iface_addr, ETH_ALEN);
4857 os_memcpy(wpa_s->pending_join_dev_addr, dev_addr, ETH_ALEN);
4858 wpa_s->pending_join_wps_method = wps_method;
4860 /* Make sure we are not running find during connection establishment */
4861 wpas_p2p_stop_find(wpa_s);
4863 wpa_s->p2p_join_scan_count = 0;
4864 wpas_p2p_join_scan_req(wpa_s, op_freq, ssid, ssid_len);
4869 static int wpas_p2p_join_start(struct wpa_supplicant *wpa_s, int freq,
4870 const u8 *ssid, size_t ssid_len)
4872 struct wpa_supplicant *group;
4873 struct p2p_go_neg_results res;
4874 struct wpa_bss *bss;
4876 group = wpas_p2p_get_group_iface(wpa_s, 0, 0);
4879 if (group != wpa_s) {
4880 os_memcpy(group->p2p_pin, wpa_s->p2p_pin,
4881 sizeof(group->p2p_pin));
4882 group->p2p_wps_method = wpa_s->p2p_wps_method;
4885 * Need to mark the current interface for p2p_group_formation
4886 * when a separate group interface is not used. This is needed
4887 * to allow p2p_cancel stop a pending p2p_connect-join.
4888 * wpas_p2p_init_group_interface() addresses this for the case
4889 * where a separate group interface is used.
4891 wpa_s->global->p2p_group_formation = wpa_s;
4894 group->p2p_in_provisioning = 1;
4895 group->p2p_fallback_to_go_neg = wpa_s->p2p_fallback_to_go_neg;
4897 os_memset(&res, 0, sizeof(res));
4898 os_memcpy(res.peer_device_addr, wpa_s->pending_join_dev_addr, ETH_ALEN);
4899 os_memcpy(res.peer_interface_addr, wpa_s->pending_join_iface_addr,
4901 res.wps_method = wpa_s->pending_join_wps_method;
4902 if (freq && ssid && ssid_len) {
4904 res.ssid_len = ssid_len;
4905 os_memcpy(res.ssid, ssid, ssid_len);
4907 bss = wpa_bss_get_bssid_latest(wpa_s,
4908 wpa_s->pending_join_iface_addr);
4910 res.freq = bss->freq;
4911 res.ssid_len = bss->ssid_len;
4912 os_memcpy(res.ssid, bss->ssid, bss->ssid_len);
4913 wpa_printf(MSG_DEBUG, "P2P: Join target GO operating frequency from BSS table: %d MHz (SSID %s)",
4915 wpa_ssid_txt(bss->ssid, bss->ssid_len));
4919 if (wpa_s->off_channel_freq || wpa_s->roc_waiting_drv_freq) {
4920 wpa_printf(MSG_DEBUG, "P2P: Cancel remain-on-channel prior to "
4922 wpa_drv_cancel_remain_on_channel(wpa_s);
4923 wpa_s->off_channel_freq = 0;
4924 wpa_s->roc_waiting_drv_freq = 0;
4926 wpas_start_wps_enrollee(group, &res);
4929 * Allow a longer timeout for join-a-running-group than normal 15
4930 * second group formation timeout since the GO may not have authorized
4931 * our connection yet.
4933 eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s, NULL);
4934 eloop_register_timeout(60, 0, wpas_p2p_group_formation_timeout,
4941 static int wpas_p2p_setup_freqs(struct wpa_supplicant *wpa_s, int freq,
4942 int *force_freq, int *pref_freq, int go,
4943 unsigned int *pref_freq_list,
4944 unsigned int *num_pref_freq)
4946 struct wpa_used_freq_data *freqs;
4947 int res, best_freq, num_unused;
4948 unsigned int freq_in_use = 0, num, i, max_pref_freq;
4950 max_pref_freq = *num_pref_freq;
4953 freqs = os_calloc(wpa_s->num_multichan_concurrent,
4954 sizeof(struct wpa_used_freq_data));
4958 num = wpas_p2p_valid_oper_freqs(wpa_s, freqs,
4959 wpa_s->num_multichan_concurrent);
4962 * It is possible that the total number of used frequencies is bigger
4963 * than the number of frequencies used for P2P, so get the system wide
4964 * number of unused frequencies.
4966 num_unused = wpas_p2p_num_unused_channels(wpa_s);
4968 wpa_printf(MSG_DEBUG,
4969 "P2P: Setup freqs: freq=%d num_MCC=%d shared_freqs=%u num_unused=%d",
4970 freq, wpa_s->num_multichan_concurrent, num, num_unused);
4975 ret = p2p_supported_freq(wpa_s->global->p2p, freq);
4977 ret = p2p_supported_freq_cli(wpa_s->global->p2p, freq);
4979 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) &&
4980 ieee80211_is_dfs(freq)) {
4982 * If freq is a DFS channel and DFS is offloaded
4983 * to the driver, allow P2P GO to use it.
4985 wpa_printf(MSG_DEBUG,
4986 "P2P: The forced channel for GO (%u MHz) is DFS, and DFS is offloaded to the driver",
4989 wpa_printf(MSG_DEBUG,
4990 "P2P: The forced channel (%u MHz) is not supported for P2P uses",
4997 for (i = 0; i < num; i++) {
4998 if (freqs[i].freq == freq)
5002 if (num_unused <= 0 && !freq_in_use) {
5003 wpa_printf(MSG_DEBUG, "P2P: Cannot start P2P group on %u MHz as there are no available channels",
5008 wpa_printf(MSG_DEBUG, "P2P: Trying to force us to use the "
5009 "requested channel (%u MHz)", freq);
5014 best_freq = wpas_p2p_pick_best_used_freq(wpa_s, freqs, num);
5016 if (!wpa_s->conf->num_p2p_pref_chan && *pref_freq == 0) {
5017 enum wpa_driver_if_type iface_type;
5020 iface_type = WPA_IF_P2P_GO;
5022 iface_type = WPA_IF_P2P_CLIENT;
5024 wpa_printf(MSG_DEBUG, "P2P: best_freq=%d, go=%d",
5027 res = wpa_drv_get_pref_freq_list(wpa_s, iface_type,
5030 if (!res && max_pref_freq > 0) {
5031 *num_pref_freq = max_pref_freq;
5033 while (wpas_p2p_disallowed_freq(wpa_s->global,
5034 pref_freq_list[i]) &&
5035 i < *num_pref_freq) {
5036 wpa_printf(MSG_DEBUG,
5037 "P2P: preferred_freq_list[%d]=%d is disallowed",
5038 i, pref_freq_list[i]);
5041 if (i != *num_pref_freq) {
5042 best_freq = pref_freq_list[i];
5043 wpa_printf(MSG_DEBUG,
5044 "P2P: Using preferred_freq_list[%d]=%d",
5047 wpa_printf(MSG_DEBUG,
5048 "P2P: All driver preferred frequencies are disallowed for P2P use");
5052 wpa_printf(MSG_DEBUG,
5053 "P2P: No preferred frequency list available");
5057 /* We have a candidate frequency to use */
5058 if (best_freq > 0) {
5059 if (*pref_freq == 0 && num_unused > 0) {
5060 wpa_printf(MSG_DEBUG, "P2P: Try to prefer a frequency (%u MHz) we are already using",
5062 *pref_freq = best_freq;
5064 wpa_printf(MSG_DEBUG, "P2P: Try to force us to use frequency (%u MHz) which is already in use",
5066 *force_freq = best_freq;
5068 } else if (num_unused > 0) {
5069 wpa_printf(MSG_DEBUG,
5070 "P2P: Current operating channels are not available for P2P. Try to use another channel");
5073 wpa_printf(MSG_DEBUG,
5074 "P2P: All channels are in use and none of them are P2P enabled. Cannot start P2P group");
5088 * wpas_p2p_connect - Request P2P Group Formation to be started
5089 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
5090 * @peer_addr: Address of the peer P2P Device
5091 * @pin: PIN to use during provisioning or %NULL to indicate PBC mode
5092 * @persistent_group: Whether to create a persistent group
5093 * @auto_join: Whether to select join vs. GO Negotiation automatically
5094 * @join: Whether to join an existing group (as a client) instead of starting
5095 * Group Owner negotiation; @peer_addr is BSSID in that case
5096 * @auth: Whether to only authorize the connection instead of doing that and
5097 * initiating Group Owner negotiation
5098 * @go_intent: GO Intent or -1 to use default
5099 * @freq: Frequency for the group or 0 for auto-selection
5100 * @persistent_id: Persistent group credentials to use for forcing GO
5101 * parameters or -1 to generate new values (SSID/passphrase)
5102 * @pd: Whether to send Provision Discovery prior to GO Negotiation as an
5103 * interoperability workaround when initiating group formation
5104 * @ht40: Start GO with 40 MHz channel width
5105 * @vht: Start GO with VHT support
5106 * Returns: 0 or new PIN (if pin was %NULL) on success, -1 on unspecified
5107 * failure, -2 on failure due to channel not currently available,
5108 * -3 if forced channel is not supported
5110 int wpas_p2p_connect(struct wpa_supplicant *wpa_s, const u8 *peer_addr,
5111 const char *pin, enum p2p_wps_method wps_method,
5112 int persistent_group, int auto_join, int join, int auth,
5113 int go_intent, int freq, int persistent_id, int pd,
5116 int force_freq = 0, pref_freq = 0;
5118 enum wpa_driver_if_type iftype;
5120 struct wpa_ssid *ssid = NULL;
5121 unsigned int pref_freq_list[P2P_MAX_PREF_CHANNELS], size;
5123 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
5126 if (persistent_id >= 0) {
5127 ssid = wpa_config_get_network(wpa_s->conf, persistent_id);
5128 if (ssid == NULL || ssid->disabled != 2 ||
5129 ssid->mode != WPAS_MODE_P2P_GO)
5133 os_free(wpa_s->global->add_psk);
5134 wpa_s->global->add_psk = NULL;
5136 wpa_s->global->p2p_fail_on_wps_complete = 0;
5137 wpa_s->global->pending_p2ps_group = 0;
5138 wpa_s->p2ps_method_config_any = 0;
5141 go_intent = wpa_s->conf->p2p_go_intent;
5144 wpa_s->p2p_long_listen = 0;
5146 wpa_s->p2p_wps_method = wps_method;
5147 wpa_s->p2p_persistent_group = !!persistent_group;
5148 wpa_s->p2p_persistent_id = persistent_id;
5149 wpa_s->p2p_go_intent = go_intent;
5150 wpa_s->p2p_connect_freq = freq;
5151 wpa_s->p2p_fallback_to_go_neg = 0;
5152 wpa_s->p2p_pd_before_go_neg = !!pd;
5153 wpa_s->p2p_go_ht40 = !!ht40;
5154 wpa_s->p2p_go_vht = !!vht;
5157 os_strlcpy(wpa_s->p2p_pin, pin, sizeof(wpa_s->p2p_pin));
5158 else if (wps_method == WPS_PIN_DISPLAY) {
5159 ret = wps_generate_pin();
5160 res = os_snprintf(wpa_s->p2p_pin, sizeof(wpa_s->p2p_pin),
5162 if (os_snprintf_error(sizeof(wpa_s->p2p_pin), res))
5163 wpa_s->p2p_pin[sizeof(wpa_s->p2p_pin) - 1] = '\0';
5164 wpa_printf(MSG_DEBUG, "P2P: Randomly generated PIN: %s",
5167 wpa_s->p2p_pin[0] = '\0';
5169 if (join || auto_join) {
5170 u8 iface_addr[ETH_ALEN], dev_addr[ETH_ALEN];
5172 wpa_printf(MSG_DEBUG, "P2P: Authorize invitation to "
5173 "connect a running group from " MACSTR,
5174 MAC2STR(peer_addr));
5175 os_memcpy(wpa_s->p2p_auth_invite, peer_addr, ETH_ALEN);
5178 os_memcpy(dev_addr, peer_addr, ETH_ALEN);
5179 if (p2p_get_interface_addr(wpa_s->global->p2p, peer_addr,
5181 os_memcpy(iface_addr, peer_addr, ETH_ALEN);
5182 p2p_get_dev_addr(wpa_s->global->p2p, peer_addr,
5186 os_get_reltime(&wpa_s->p2p_auto_started);
5187 wpa_printf(MSG_DEBUG, "P2P: Auto join started at "
5189 wpa_s->p2p_auto_started.sec,
5190 wpa_s->p2p_auto_started.usec);
5192 wpa_s->user_initiated_pd = 1;
5193 if (wpas_p2p_join(wpa_s, iface_addr, dev_addr, wps_method,
5194 auto_join, freq, NULL, 0) < 0)
5199 size = P2P_MAX_PREF_CHANNELS;
5200 res = wpas_p2p_setup_freqs(wpa_s, freq, &force_freq, &pref_freq,
5201 go_intent == 15, pref_freq_list, &size);
5204 wpas_p2p_set_own_freq_preference(wpa_s,
5205 force_freq ? force_freq : pref_freq);
5207 p2p_set_own_pref_freq_list(wpa_s->global->p2p, pref_freq_list, size);
5209 wpa_s->create_p2p_iface = wpas_p2p_create_iface(wpa_s);
5211 if (wpa_s->create_p2p_iface) {
5212 /* Prepare to add a new interface for the group */
5213 iftype = WPA_IF_P2P_GROUP;
5214 if (go_intent == 15)
5215 iftype = WPA_IF_P2P_GO;
5216 if (wpas_p2p_add_group_interface(wpa_s, iftype) < 0) {
5217 wpa_printf(MSG_ERROR, "P2P: Failed to allocate a new "
5218 "interface for the group");
5222 if_addr = wpa_s->pending_interface_addr;
5224 if_addr = wpa_s->own_addr;
5225 os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN);
5229 if (wpas_p2p_auth_go_neg(wpa_s, peer_addr, wps_method,
5231 force_freq, persistent_group, ssid,
5237 if (wpas_p2p_start_go_neg(wpa_s, peer_addr, wps_method,
5238 go_intent, if_addr, force_freq,
5239 persistent_group, ssid, pref_freq) < 0) {
5240 if (wpa_s->create_p2p_iface)
5241 wpas_p2p_remove_pending_group_interface(wpa_s);
5249 * wpas_p2p_remain_on_channel_cb - Indication of remain-on-channel start
5250 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
5251 * @freq: Frequency of the channel in MHz
5252 * @duration: Duration of the stay on the channel in milliseconds
5254 * This callback is called when the driver indicates that it has started the
5255 * requested remain-on-channel duration.
5257 void wpas_p2p_remain_on_channel_cb(struct wpa_supplicant *wpa_s,
5258 unsigned int freq, unsigned int duration)
5260 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
5262 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)",
5263 wpa_s->off_channel_freq, wpa_s->pending_listen_freq,
5264 wpa_s->roc_waiting_drv_freq, freq, duration);
5265 if (wpa_s->off_channel_freq &&
5266 wpa_s->off_channel_freq == wpa_s->pending_listen_freq) {
5267 p2p_listen_cb(wpa_s->global->p2p, wpa_s->pending_listen_freq,
5268 wpa_s->pending_listen_duration);
5269 wpa_s->pending_listen_freq = 0;
5271 wpa_printf(MSG_DEBUG, "P2P: Ignore remain-on-channel callback (off_channel_freq=%u pending_listen_freq=%d freq=%u duration=%u)",
5272 wpa_s->off_channel_freq, wpa_s->pending_listen_freq,
5278 int wpas_p2p_listen_start(struct wpa_supplicant *wpa_s, unsigned int timeout)
5280 /* Limit maximum Listen state time based on driver limitation. */
5281 if (timeout > wpa_s->max_remain_on_chan)
5282 timeout = wpa_s->max_remain_on_chan;
5284 return p2p_listen(wpa_s->global->p2p, timeout);
5289 * wpas_p2p_cancel_remain_on_channel_cb - Remain-on-channel timeout
5290 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
5291 * @freq: Frequency of the channel in MHz
5293 * This callback is called when the driver indicates that a remain-on-channel
5294 * operation has been completed, i.e., the duration on the requested channel
5297 void wpas_p2p_cancel_remain_on_channel_cb(struct wpa_supplicant *wpa_s,
5300 wpa_printf(MSG_DEBUG, "P2P: Cancel remain-on-channel callback "
5301 "(p2p_long_listen=%d ms pending_action_tx=%p)",
5302 wpa_s->p2p_long_listen, offchannel_pending_action_tx(wpa_s));
5303 wpas_p2p_listen_work_done(wpa_s);
5304 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
5306 if (wpa_s->p2p_long_listen > 0)
5307 wpa_s->p2p_long_listen -= wpa_s->max_remain_on_chan;
5308 if (p2p_listen_end(wpa_s->global->p2p, freq) > 0)
5309 return; /* P2P module started a new operation */
5310 if (offchannel_pending_action_tx(wpa_s))
5312 if (wpa_s->p2p_long_listen > 0) {
5313 wpa_printf(MSG_DEBUG, "P2P: Continuing long Listen state");
5314 wpas_p2p_listen_start(wpa_s, wpa_s->p2p_long_listen);
5317 * When listen duration is over, stop listen & update p2p_state
5320 p2p_stop_listen(wpa_s->global->p2p);
5326 * wpas_p2p_group_remove - Remove a P2P group
5327 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
5328 * @ifname: Network interface name of the group interface or "*" to remove all
5330 * Returns: 0 on success, -1 on failure
5332 * This function is used to remove a P2P group. This can be used to disconnect
5333 * from a group in which the local end is a P2P Client or to end a P2P Group in
5334 * case the local end is the Group Owner. If a virtual network interface was
5335 * created for this group, that interface will be removed. Otherwise, only the
5336 * configured P2P group network will be removed from the interface.
5338 int wpas_p2p_group_remove(struct wpa_supplicant *wpa_s, const char *ifname)
5340 struct wpa_global *global = wpa_s->global;
5341 struct wpa_supplicant *calling_wpa_s = wpa_s;
5343 if (os_strcmp(ifname, "*") == 0) {
5344 struct wpa_supplicant *prev;
5345 wpa_s = global->ifaces;
5348 wpa_s = wpa_s->next;
5349 if (prev->p2p_group_interface !=
5350 NOT_P2P_GROUP_INTERFACE ||
5351 (prev->current_ssid &&
5352 prev->current_ssid->p2p_group))
5353 wpas_p2p_disconnect_safely(prev, calling_wpa_s);
5358 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
5359 if (os_strcmp(wpa_s->ifname, ifname) == 0)
5363 return wpas_p2p_disconnect_safely(wpa_s, calling_wpa_s);
5367 static int wpas_p2p_select_go_freq(struct wpa_supplicant *wpa_s, int freq)
5371 if (!wpa_s->conf->num_p2p_pref_chan && !freq) {
5372 unsigned int i, size = P2P_MAX_PREF_CHANNELS;
5373 unsigned int pref_freq_list[P2P_MAX_PREF_CHANNELS];
5376 res = wpa_drv_get_pref_freq_list(wpa_s, WPA_IF_P2P_GO,
5377 &size, pref_freq_list);
5378 if (!res && size > 0) {
5380 while (wpas_p2p_disallowed_freq(wpa_s->global,
5381 pref_freq_list[i]) &&
5383 wpa_printf(MSG_DEBUG,
5384 "P2P: preferred_freq_list[%d]=%d is disallowed",
5385 i, pref_freq_list[i]);
5389 freq = pref_freq_list[i];
5390 wpa_printf(MSG_DEBUG,
5391 "P2P: Using preferred_freq_list[%d]=%d",
5394 wpa_printf(MSG_DEBUG,
5395 "P2P: All driver preferred frequencies are disallowed for P2P use");
5398 wpa_printf(MSG_DEBUG,
5399 "P2P: No preferred frequency list available");
5404 wpa_printf(MSG_DEBUG, "P2P: Request to start GO on 2.4 GHz "
5406 if (wpa_s->best_24_freq > 0 &&
5407 p2p_supported_freq_go(wpa_s->global->p2p,
5408 wpa_s->best_24_freq)) {
5409 freq = wpa_s->best_24_freq;
5410 wpa_printf(MSG_DEBUG, "P2P: Use best 2.4 GHz band "
5411 "channel: %d MHz", freq);
5413 if (os_get_random((u8 *) &r, sizeof(r)) < 0)
5415 freq = 2412 + (r % 3) * 25;
5416 wpa_printf(MSG_DEBUG, "P2P: Use random 2.4 GHz band "
5417 "channel: %d MHz", freq);
5422 wpa_printf(MSG_DEBUG, "P2P: Request to start GO on 5 GHz "
5424 if (wpa_s->best_5_freq > 0 &&
5425 p2p_supported_freq_go(wpa_s->global->p2p,
5426 wpa_s->best_5_freq)) {
5427 freq = wpa_s->best_5_freq;
5428 wpa_printf(MSG_DEBUG, "P2P: Use best 5 GHz band "
5429 "channel: %d MHz", freq);
5431 if (os_get_random((u8 *) &r, sizeof(r)) < 0)
5433 freq = 5180 + (r % 4) * 20;
5434 if (!p2p_supported_freq_go(wpa_s->global->p2p, freq)) {
5435 wpa_printf(MSG_DEBUG, "P2P: Could not select "
5436 "5 GHz channel for P2P group");
5439 wpa_printf(MSG_DEBUG, "P2P: Use random 5 GHz band "
5440 "channel: %d MHz", freq);
5444 if (freq > 0 && !p2p_supported_freq_go(wpa_s->global->p2p, freq)) {
5445 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) &&
5446 ieee80211_is_dfs(freq)) {
5448 * If freq is a DFS channel and DFS is offloaded to the
5449 * driver, allow P2P GO to use it.
5451 wpa_printf(MSG_DEBUG, "P2P: "
5452 "%s: The forced channel for GO (%u MHz) is DFS, and DFS is offloaded",
5456 wpa_printf(MSG_DEBUG, "P2P: The forced channel for GO "
5457 "(%u MHz) is not supported for P2P uses",
5466 static int wpas_p2p_supported_freq_go(struct wpa_supplicant *wpa_s,
5467 const struct p2p_channels *channels,
5470 if (!wpas_p2p_disallowed_freq(wpa_s->global, freq) &&
5471 p2p_supported_freq_go(wpa_s->global->p2p, freq) &&
5472 freq_included(wpa_s, channels, freq))
5478 static void wpas_p2p_select_go_freq_no_pref(struct wpa_supplicant *wpa_s,
5479 struct p2p_go_neg_results *params,
5480 const struct p2p_channels *channels)
5484 /* first try some random selection of the social channels */
5485 if (os_get_random((u8 *) &r, sizeof(r)) < 0)
5488 for (i = 0; i < 3; i++) {
5489 params->freq = 2412 + ((r + i) % 3) * 25;
5490 if (wpas_p2p_supported_freq_go(wpa_s, channels, params->freq))
5494 /* try all other channels in operating class 81 */
5495 for (i = 0; i < 11; i++) {
5496 params->freq = 2412 + i * 5;
5498 /* skip social channels; covered in the previous loop */
5499 if (params->freq == 2412 ||
5500 params->freq == 2437 ||
5501 params->freq == 2462)
5504 if (wpas_p2p_supported_freq_go(wpa_s, channels, params->freq))
5508 /* try all channels in operating class 115 */
5509 for (i = 0; i < 4; i++) {
5510 params->freq = 5180 + i * 20;
5511 if (!wpas_p2p_disallowed_freq(wpa_s->global, params->freq) &&
5512 freq_included(wpa_s, channels, params->freq) &&
5513 p2p_supported_freq(wpa_s->global->p2p, params->freq))
5517 /* try all channels in operating class 124 */
5518 for (i = 0; i < 4; i++) {
5519 params->freq = 5745 + i * 20;
5520 if (!wpas_p2p_disallowed_freq(wpa_s->global, params->freq) &&
5521 freq_included(wpa_s, channels, params->freq) &&
5522 p2p_supported_freq(wpa_s->global->p2p, params->freq))
5526 /* try social channel class 180 channel 2 */
5527 params->freq = 58320 + 1 * 2160;
5528 if (!wpas_p2p_disallowed_freq(wpa_s->global, params->freq) &&
5529 freq_included(wpa_s, channels, params->freq) &&
5530 p2p_supported_freq(wpa_s->global->p2p, params->freq))
5533 /* try all channels in reg. class 180 */
5534 for (i = 0; i < 4; i++) {
5535 params->freq = 58320 + i * 2160;
5536 if (!wpas_p2p_disallowed_freq(wpa_s->global, params->freq) &&
5537 freq_included(wpa_s, channels, params->freq) &&
5538 p2p_supported_freq(wpa_s->global->p2p, params->freq))
5543 wpa_printf(MSG_DEBUG, "P2P: No 2.4, 5, or 60 GHz channel allowed");
5546 wpa_printf(MSG_DEBUG, "P2P: Set GO freq %d MHz (no preference known)",
5551 static int wpas_p2p_init_go_params(struct wpa_supplicant *wpa_s,
5552 struct p2p_go_neg_results *params,
5553 int freq, int ht40, int vht,
5554 const struct p2p_channels *channels)
5556 struct wpa_used_freq_data *freqs;
5558 unsigned int num, i;
5559 int ignore_no_freqs = 0;
5561 os_memset(params, 0, sizeof(*params));
5562 params->role_go = 1;
5563 params->ht40 = ht40;
5566 freqs = os_calloc(wpa_s->num_multichan_concurrent,
5567 sizeof(struct wpa_used_freq_data));
5571 num = get_shared_radio_freqs_data(wpa_s, freqs,
5572 wpa_s->num_multichan_concurrent);
5574 if (wpa_s->current_ssid &&
5575 wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO &&
5576 wpa_s->wpa_state == WPA_COMPLETED) {
5577 wpa_printf(MSG_DEBUG, "P2P: %s called for an active GO",
5581 * If the frequency selection is done for an active P2P GO that
5582 * is not sharing a frequency, allow to select a new frequency
5583 * even if there are no unused frequencies as we are about to
5584 * move the P2P GO so its frequency can be re-used.
5586 for (i = 0; i < num; i++) {
5587 if (freqs[i].freq == wpa_s->current_ssid->frequency &&
5588 freqs[i].flags == 0) {
5589 ignore_no_freqs = 1;
5595 /* try using the forced freq */
5597 if (!wpas_p2p_supported_freq_go(wpa_s, channels, freq)) {
5598 wpa_printf(MSG_DEBUG,
5599 "P2P: Forced GO freq %d MHz not accepted",
5604 for (i = 0; i < num; i++) {
5605 if (freqs[i].freq == freq) {
5606 wpa_printf(MSG_DEBUG,
5607 "P2P: forced freq (%d MHz) is also shared",
5609 params->freq = freq;
5614 if (!ignore_no_freqs &&
5615 wpas_p2p_num_unused_channels(wpa_s) <= 0) {
5616 wpa_printf(MSG_DEBUG,
5617 "P2P: Cannot force GO on freq (%d MHz) as all the channels are in use",
5622 wpa_printf(MSG_DEBUG,
5623 "P2P: force GO freq (%d MHz) on a free channel",
5625 params->freq = freq;
5629 /* consider using one of the shared frequencies */
5631 cand = wpas_p2p_pick_best_used_freq(wpa_s, freqs, num);
5632 if (wpas_p2p_supported_freq_go(wpa_s, channels, cand)) {
5633 wpa_printf(MSG_DEBUG,
5634 "P2P: Use shared freq (%d MHz) for GO",
5636 params->freq = cand;
5640 /* try using one of the shared freqs */
5641 for (i = 0; i < num; i++) {
5642 if (wpas_p2p_supported_freq_go(wpa_s, channels,
5644 wpa_printf(MSG_DEBUG,
5645 "P2P: Use shared freq (%d MHz) for GO",
5647 params->freq = freqs[i].freq;
5653 if (!ignore_no_freqs &&
5654 wpas_p2p_num_unused_channels(wpa_s) <= 0) {
5655 wpa_printf(MSG_DEBUG,
5656 "P2P: Cannot force GO on any of the channels we are already using");
5660 /* try using the setting from the configuration file */
5661 if (wpa_s->conf->p2p_oper_reg_class == 81 &&
5662 wpa_s->conf->p2p_oper_channel >= 1 &&
5663 wpa_s->conf->p2p_oper_channel <= 11 &&
5664 wpas_p2p_supported_freq_go(
5666 2407 + 5 * wpa_s->conf->p2p_oper_channel)) {
5667 params->freq = 2407 + 5 * wpa_s->conf->p2p_oper_channel;
5668 wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on configured "
5669 "frequency %d MHz", params->freq);
5673 if ((wpa_s->conf->p2p_oper_reg_class == 115 ||
5674 wpa_s->conf->p2p_oper_reg_class == 116 ||
5675 wpa_s->conf->p2p_oper_reg_class == 117 ||
5676 wpa_s->conf->p2p_oper_reg_class == 124 ||
5677 wpa_s->conf->p2p_oper_reg_class == 125 ||
5678 wpa_s->conf->p2p_oper_reg_class == 126 ||
5679 wpa_s->conf->p2p_oper_reg_class == 127) &&
5680 wpas_p2p_supported_freq_go(wpa_s, channels,
5682 5 * wpa_s->conf->p2p_oper_channel)) {
5683 params->freq = 5000 + 5 * wpa_s->conf->p2p_oper_channel;
5684 wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on configured "
5685 "frequency %d MHz", params->freq);
5689 /* Try using best channels */
5690 if (wpa_s->conf->p2p_oper_channel == 0 &&
5691 wpa_s->best_overall_freq > 0 &&
5692 wpas_p2p_supported_freq_go(wpa_s, channels,
5693 wpa_s->best_overall_freq)) {
5694 params->freq = wpa_s->best_overall_freq;
5695 wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on best overall "
5696 "channel %d MHz", params->freq);
5700 if (wpa_s->conf->p2p_oper_channel == 0 &&
5701 wpa_s->best_24_freq > 0 &&
5702 wpas_p2p_supported_freq_go(wpa_s, channels,
5703 wpa_s->best_24_freq)) {
5704 params->freq = wpa_s->best_24_freq;
5705 wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on best 2.4 GHz "
5706 "channel %d MHz", params->freq);
5710 if (wpa_s->conf->p2p_oper_channel == 0 &&
5711 wpa_s->best_5_freq > 0 &&
5712 wpas_p2p_supported_freq_go(wpa_s, channels,
5713 wpa_s->best_5_freq)) {
5714 params->freq = wpa_s->best_5_freq;
5715 wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on best 5 GHz "
5716 "channel %d MHz", params->freq);
5720 /* try using preferred channels */
5721 cand = p2p_get_pref_freq(wpa_s->global->p2p, channels);
5722 if (cand && wpas_p2p_supported_freq_go(wpa_s, channels, cand)) {
5723 params->freq = cand;
5724 wpa_printf(MSG_DEBUG, "P2P: Set GO freq %d MHz from preferred "
5725 "channels", params->freq);
5729 /* Try using one of the group common freqs */
5730 if (wpa_s->p2p_group_common_freqs) {
5731 for (i = 0; i < wpa_s->p2p_group_common_freqs_num; i++) {
5732 cand = wpa_s->p2p_group_common_freqs[i];
5733 if (wpas_p2p_supported_freq_go(wpa_s, channels, cand)) {
5734 params->freq = cand;
5735 wpa_printf(MSG_DEBUG,
5736 "P2P: Use freq %d MHz common with the peer",
5743 /* no preference, select some channel */
5744 wpas_p2p_select_go_freq_no_pref(wpa_s, params, channels);
5746 if (params->freq == 0) {
5747 wpa_printf(MSG_DEBUG, "P2P: did not find a freq for GO use");
5760 static struct wpa_supplicant *
5761 wpas_p2p_get_group_iface(struct wpa_supplicant *wpa_s, int addr_allocated,
5764 struct wpa_supplicant *group_wpa_s;
5766 if (!wpas_p2p_create_iface(wpa_s)) {
5767 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Use same interface for group "
5769 wpa_s->p2p_first_connection_timeout = 0;
5773 if (wpas_p2p_add_group_interface(wpa_s, go ? WPA_IF_P2P_GO :
5774 WPA_IF_P2P_CLIENT) < 0) {
5775 wpa_msg_global(wpa_s, MSG_ERROR,
5776 "P2P: Failed to add group interface");
5779 group_wpa_s = wpas_p2p_init_group_interface(wpa_s, go);
5780 if (group_wpa_s == NULL) {
5781 wpa_msg_global(wpa_s, MSG_ERROR,
5782 "P2P: Failed to initialize group interface");
5783 wpas_p2p_remove_pending_group_interface(wpa_s);
5787 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Use separate group interface %s",
5788 group_wpa_s->ifname);
5789 group_wpa_s->p2p_first_connection_timeout = 0;
5795 * wpas_p2p_group_add - Add a new P2P group with local end as Group Owner
5796 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
5797 * @persistent_group: Whether to create a persistent group
5798 * @freq: Frequency for the group or 0 to indicate no hardcoding
5799 * @ht40: Start GO with 40 MHz channel width
5800 * @vht: Start GO with VHT support
5801 * Returns: 0 on success, -1 on failure
5803 * This function creates a new P2P group with the local end as the Group Owner,
5804 * i.e., without using Group Owner Negotiation.
5806 int wpas_p2p_group_add(struct wpa_supplicant *wpa_s, int persistent_group,
5807 int freq, int ht40, int vht)
5809 struct p2p_go_neg_results params;
5811 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
5814 os_free(wpa_s->global->add_psk);
5815 wpa_s->global->add_psk = NULL;
5817 /* Make sure we are not running find during connection establishment */
5818 wpa_printf(MSG_DEBUG, "P2P: Stop any on-going P2P FIND");
5819 wpas_p2p_stop_find_oper(wpa_s);
5821 freq = wpas_p2p_select_go_freq(wpa_s, freq);
5825 if (wpas_p2p_init_go_params(wpa_s, ¶ms, freq, ht40, vht, NULL))
5828 !p2p_supported_freq_go(wpa_s->global->p2p, params.freq)) {
5829 if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) &&
5830 ieee80211_is_dfs(params.freq)) {
5832 * If freq is a DFS channel and DFS is offloaded to the
5833 * driver, allow P2P GO to use it.
5835 wpa_printf(MSG_DEBUG,
5836 "P2P: %s: The forced channel for GO (%u MHz) is DFS, and DFS is offloaded to driver",
5837 __func__, params.freq);
5839 wpa_printf(MSG_DEBUG,
5840 "P2P: The selected channel for GO (%u MHz) is not supported for P2P uses",
5845 p2p_go_params(wpa_s->global->p2p, ¶ms);
5846 params.persistent_group = persistent_group;
5848 wpa_s = wpas_p2p_get_group_iface(wpa_s, 0, 1);
5851 wpas_start_wps_go(wpa_s, ¶ms, 0);
5857 static int wpas_start_p2p_client(struct wpa_supplicant *wpa_s,
5858 struct wpa_ssid *params, int addr_allocated,
5859 int freq, int force_scan)
5861 struct wpa_ssid *ssid;
5863 wpa_s = wpas_p2p_get_group_iface(wpa_s, addr_allocated, 0);
5867 os_get_reltime(&wpa_s->scan_min_time);
5868 wpa_s->p2p_last_4way_hs_fail = NULL;
5870 wpa_supplicant_ap_deinit(wpa_s);
5872 ssid = wpa_config_add_network(wpa_s->conf);
5875 os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN);
5876 wpa_config_set_network_defaults(ssid);
5877 ssid->temporary = 1;
5878 ssid->proto = WPA_PROTO_RSN;
5879 ssid->pairwise_cipher = WPA_CIPHER_CCMP;
5880 ssid->group_cipher = WPA_CIPHER_CCMP;
5881 ssid->key_mgmt = WPA_KEY_MGMT_PSK;
5882 ssid->ssid = os_malloc(params->ssid_len);
5883 if (ssid->ssid == NULL) {
5884 wpa_config_remove_network(wpa_s->conf, ssid->id);
5887 os_memcpy(ssid->ssid, params->ssid, params->ssid_len);
5888 ssid->ssid_len = params->ssid_len;
5889 ssid->p2p_group = 1;
5890 ssid->export_keys = 1;
5891 if (params->psk_set) {
5892 os_memcpy(ssid->psk, params->psk, 32);
5895 if (params->passphrase)
5896 ssid->passphrase = os_strdup(params->passphrase);
5898 wpa_s->show_group_started = 1;
5899 wpa_s->p2p_in_invitation = 1;
5900 wpa_s->p2p_invite_go_freq = freq;
5902 eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s->parent,
5904 eloop_register_timeout(P2P_MAX_INITIAL_CONN_WAIT, 0,
5905 wpas_p2p_group_formation_timeout,
5906 wpa_s->parent, NULL);
5907 wpa_supplicant_select_network(wpa_s, ssid);
5913 int wpas_p2p_group_add_persistent(struct wpa_supplicant *wpa_s,
5914 struct wpa_ssid *ssid, int addr_allocated,
5915 int force_freq, int neg_freq, int ht40,
5916 int vht, const struct p2p_channels *channels,
5917 int connection_timeout, int force_scan)
5919 struct p2p_go_neg_results params;
5922 if (ssid->disabled != 2 || ssid->ssid == NULL)
5925 if (wpas_get_p2p_group(wpa_s, ssid->ssid, ssid->ssid_len, &go) &&
5926 go == (ssid->mode == WPAS_MODE_P2P_GO)) {
5927 wpa_printf(MSG_DEBUG, "P2P: Requested persistent group is "
5930 eloop_cancel_timeout(wpas_p2p_group_formation_timeout,
5931 wpa_s->parent, NULL)) {
5933 * This can happen if Invitation Response frame was lost
5934 * and the peer (GO of a persistent group) tries to
5935 * invite us again. Reschedule the timeout to avoid
5936 * terminating the wait for the connection too early
5937 * since we now know that the peer is still trying to
5938 * invite us instead of having already started the GO.
5940 wpa_printf(MSG_DEBUG,
5941 "P2P: Reschedule group formation timeout since peer is still trying to invite us");
5942 eloop_register_timeout(P2P_MAX_INITIAL_CONN_WAIT, 0,
5943 wpas_p2p_group_formation_timeout,
5944 wpa_s->parent, NULL);
5949 os_free(wpa_s->global->add_psk);
5950 wpa_s->global->add_psk = NULL;
5952 /* Make sure we are not running find during connection establishment */
5953 wpas_p2p_stop_find_oper(wpa_s);
5955 wpa_s->p2p_fallback_to_go_neg = 0;
5957 if (ssid->mode == WPAS_MODE_P2P_GO) {
5958 if (force_freq > 0) {
5959 freq = wpas_p2p_select_go_freq(wpa_s, force_freq);
5963 freq = wpas_p2p_select_go_freq(wpa_s, neg_freq);
5965 (freq > 0 && !freq_included(wpa_s, channels, freq)))
5968 } else if (ssid->mode == WPAS_MODE_INFRA) {
5970 if (freq <= 0 || !freq_included(wpa_s, channels, freq)) {
5971 struct os_reltime now;
5972 struct wpa_bss *bss =
5973 wpa_bss_get_p2p_dev_addr(wpa_s, ssid->bssid);
5975 os_get_reltime(&now);
5977 !os_reltime_expired(&now, &bss->last_update, 5) &&
5978 freq_included(wpa_s, channels, bss->freq))
5984 return wpas_start_p2p_client(wpa_s, ssid, addr_allocated, freq,
5990 if (wpas_p2p_init_go_params(wpa_s, ¶ms, freq, ht40, vht, channels))
5994 params.psk_set = ssid->psk_set;
5996 os_memcpy(params.psk, ssid->psk, sizeof(params.psk));
5997 if (ssid->passphrase) {
5998 if (os_strlen(ssid->passphrase) >= sizeof(params.passphrase)) {
5999 wpa_printf(MSG_ERROR, "P2P: Invalid passphrase in "
6000 "persistent group");
6003 os_strlcpy(params.passphrase, ssid->passphrase,
6004 sizeof(params.passphrase));
6006 os_memcpy(params.ssid, ssid->ssid, ssid->ssid_len);
6007 params.ssid_len = ssid->ssid_len;
6008 params.persistent_group = 1;
6010 wpa_s = wpas_p2p_get_group_iface(wpa_s, addr_allocated, 1);
6014 p2p_channels_to_freqs(channels, params.freq_list, P2P_MAX_CHANNELS);
6016 wpa_s->p2p_first_connection_timeout = connection_timeout;
6017 wpas_start_wps_go(wpa_s, ¶ms, 0);
6023 static void wpas_p2p_ie_update(void *ctx, struct wpabuf *beacon_ies,
6024 struct wpabuf *proberesp_ies)
6026 struct wpa_supplicant *wpa_s = ctx;
6027 if (wpa_s->ap_iface) {
6028 struct hostapd_data *hapd = wpa_s->ap_iface->bss[0];
6029 if (!(hapd->conf->p2p & P2P_GROUP_OWNER)) {
6030 wpabuf_free(beacon_ies);
6031 wpabuf_free(proberesp_ies);
6035 wpabuf_free(hapd->p2p_beacon_ie);
6036 hapd->p2p_beacon_ie = beacon_ies;
6038 wpabuf_free(hapd->p2p_probe_resp_ie);
6039 hapd->p2p_probe_resp_ie = proberesp_ies;
6041 wpabuf_free(beacon_ies);
6042 wpabuf_free(proberesp_ies);
6044 wpa_supplicant_ap_update_beacon(wpa_s);
6048 static void wpas_p2p_idle_update(void *ctx, int idle)
6050 struct wpa_supplicant *wpa_s = ctx;
6051 if (!wpa_s->ap_iface)
6053 wpa_printf(MSG_DEBUG, "P2P: GO - group %sidle", idle ? "" : "not ");
6055 if (wpa_s->global->p2p_fail_on_wps_complete &&
6056 wpa_s->p2p_in_provisioning) {
6057 wpas_p2p_grpform_fail_after_wps(wpa_s);
6060 wpas_p2p_set_group_idle_timeout(wpa_s);
6062 eloop_cancel_timeout(wpas_p2p_group_idle_timeout, wpa_s, NULL);
6066 struct p2p_group * wpas_p2p_group_init(struct wpa_supplicant *wpa_s,
6067 struct wpa_ssid *ssid)
6069 struct p2p_group *group;
6070 struct p2p_group_config *cfg;
6072 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
6075 cfg = os_zalloc(sizeof(*cfg));
6079 if (ssid->p2p_persistent_group && wpa_s->conf->persistent_reconnect)
6080 cfg->persistent_group = 2;
6081 else if (ssid->p2p_persistent_group)
6082 cfg->persistent_group = 1;
6083 os_memcpy(cfg->interface_addr, wpa_s->own_addr, ETH_ALEN);
6084 if (wpa_s->max_stations &&
6085 wpa_s->max_stations < wpa_s->conf->max_num_sta)
6086 cfg->max_clients = wpa_s->max_stations;
6088 cfg->max_clients = wpa_s->conf->max_num_sta;
6089 os_memcpy(cfg->ssid, ssid->ssid, ssid->ssid_len);
6090 cfg->ssid_len = ssid->ssid_len;
6091 cfg->freq = ssid->frequency;
6092 cfg->cb_ctx = wpa_s;
6093 cfg->ie_update = wpas_p2p_ie_update;
6094 cfg->idle_update = wpas_p2p_idle_update;
6096 group = p2p_group_init(wpa_s->global->p2p, cfg);
6099 if (ssid->mode != WPAS_MODE_P2P_GROUP_FORMATION)
6100 p2p_group_notif_formation_done(group);
6101 wpa_s->p2p_group = group;
6106 void wpas_p2p_wps_success(struct wpa_supplicant *wpa_s, const u8 *peer_addr,
6109 struct wpa_ssid *ssid = wpa_s->current_ssid;
6111 if (!wpa_s->p2p_in_provisioning) {
6112 wpa_printf(MSG_DEBUG, "P2P: Ignore WPS success event - P2P "
6113 "provisioning not in progress");
6117 if (ssid && ssid->mode == WPAS_MODE_INFRA) {
6118 u8 go_dev_addr[ETH_ALEN];
6119 os_memcpy(go_dev_addr, wpa_s->bssid, ETH_ALEN);
6120 wpas_p2p_persistent_group(wpa_s, go_dev_addr, ssid->ssid,
6122 /* Clear any stored provisioning info */
6123 p2p_clear_provisioning_info(wpa_s->global->p2p, go_dev_addr);
6126 eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s->parent,
6128 wpa_s->p2p_go_group_formation_completed = 1;
6129 if (ssid && ssid->mode == WPAS_MODE_INFRA) {
6131 * Use a separate timeout for initial data connection to
6132 * complete to allow the group to be removed automatically if
6133 * something goes wrong in this step before the P2P group idle
6134 * timeout mechanism is taken into use.
6136 wpa_dbg(wpa_s, MSG_DEBUG,
6137 "P2P: Re-start group formation timeout (%d seconds) as client for initial connection",
6138 P2P_MAX_INITIAL_CONN_WAIT);
6139 eloop_register_timeout(P2P_MAX_INITIAL_CONN_WAIT, 0,
6140 wpas_p2p_group_formation_timeout,
6141 wpa_s->parent, NULL);
6144 * Use a separate timeout for initial data connection to
6145 * complete to allow the group to be removed automatically if
6146 * the client does not complete data connection successfully.
6148 wpa_dbg(wpa_s, MSG_DEBUG,
6149 "P2P: Re-start group formation timeout (%d seconds) as GO for initial connection",
6150 P2P_MAX_INITIAL_CONN_WAIT_GO);
6151 eloop_register_timeout(P2P_MAX_INITIAL_CONN_WAIT_GO, 0,
6152 wpas_p2p_group_formation_timeout,
6153 wpa_s->parent, NULL);
6155 * Complete group formation on first successful data connection
6157 wpa_s->p2p_go_group_formation_completed = 0;
6159 if (wpa_s->global->p2p)
6160 p2p_wps_success_cb(wpa_s->global->p2p, peer_addr);
6161 wpas_group_formation_completed(wpa_s, 1, 0);
6165 void wpas_p2p_wps_failed(struct wpa_supplicant *wpa_s,
6166 struct wps_event_fail *fail)
6168 if (!wpa_s->p2p_in_provisioning) {
6169 wpa_printf(MSG_DEBUG, "P2P: Ignore WPS fail event - P2P "
6170 "provisioning not in progress");
6174 if (wpa_s->go_params) {
6175 p2p_clear_provisioning_info(
6177 wpa_s->go_params->peer_device_addr);
6180 wpas_notify_p2p_wps_failed(wpa_s, fail);
6182 if (wpa_s == wpa_s->global->p2p_group_formation) {
6184 * Allow some time for the failed WPS negotiation exchange to
6185 * complete, but remove the group since group formation cannot
6186 * succeed after provisioning failure.
6188 wpa_printf(MSG_DEBUG, "P2P: WPS step failed during group formation - reject connection from timeout");
6189 wpa_s->global->p2p_fail_on_wps_complete = 1;
6190 eloop_deplete_timeout(0, 50000,
6191 wpas_p2p_group_formation_timeout,
6192 wpa_s->parent, NULL);
6197 int wpas_p2p_wps_eapol_cb(struct wpa_supplicant *wpa_s)
6199 if (!wpa_s->global->p2p_fail_on_wps_complete ||
6200 !wpa_s->p2p_in_provisioning)
6203 wpas_p2p_grpform_fail_after_wps(wpa_s);
6209 int wpas_p2p_prov_disc(struct wpa_supplicant *wpa_s, const u8 *peer_addr,
6210 const char *config_method,
6211 enum wpas_p2p_prov_disc_use use,
6212 struct p2ps_provision *p2ps_prov)
6216 wpa_s->global->pending_p2ps_group = 0;
6217 wpa_s->p2p_fallback_to_go_neg = 0;
6218 wpa_s->pending_pd_use = NORMAL_PD;
6219 if (p2ps_prov && use == WPAS_P2P_PD_FOR_ASP) {
6220 p2ps_prov->conncap = p2ps_group_capability(
6221 wpa_s, P2PS_SETUP_NONE, p2ps_prov->role);
6222 wpa_printf(MSG_DEBUG,
6223 "P2P: %s conncap: %d - ASP parsed: %x %x %d %s",
6224 __func__, p2ps_prov->conncap,
6225 p2ps_prov->adv_id, p2ps_prov->conncap,
6226 p2ps_prov->status, p2ps_prov->info);
6229 } else if (os_strncmp(config_method, "display", 7) == 0)
6230 config_methods = WPS_CONFIG_DISPLAY;
6231 else if (os_strncmp(config_method, "keypad", 6) == 0)
6232 config_methods = WPS_CONFIG_KEYPAD;
6233 else if (os_strncmp(config_method, "pbc", 3) == 0 ||
6234 os_strncmp(config_method, "pushbutton", 10) == 0)
6235 config_methods = WPS_CONFIG_PUSHBUTTON;
6237 wpa_printf(MSG_DEBUG, "P2P: Unknown config method");
6242 if (use == WPAS_P2P_PD_AUTO) {
6243 os_memcpy(wpa_s->pending_join_dev_addr, peer_addr, ETH_ALEN);
6244 wpa_s->pending_pd_config_methods = config_methods;
6245 wpa_s->p2p_auto_pd = 1;
6246 wpa_s->p2p_auto_join = 0;
6247 wpa_s->pending_pd_before_join = 0;
6248 wpa_s->auto_pd_scan_retry = 0;
6249 wpas_p2p_stop_find(wpa_s);
6250 wpa_s->p2p_join_scan_count = 0;
6251 os_get_reltime(&wpa_s->p2p_auto_started);
6252 wpa_printf(MSG_DEBUG, "P2P: Auto PD started at %ld.%06ld",
6253 wpa_s->p2p_auto_started.sec,
6254 wpa_s->p2p_auto_started.usec);
6255 wpas_p2p_join_scan(wpa_s, NULL);
6259 if (wpa_s->global->p2p == NULL || wpa_s->global->p2p_disabled) {
6264 return p2p_prov_disc_req(wpa_s->global->p2p, peer_addr, p2ps_prov,
6265 config_methods, use == WPAS_P2P_PD_FOR_JOIN,
6270 int wpas_p2p_scan_result_text(const u8 *ies, size_t ies_len, char *buf,
6273 return p2p_scan_result_text(ies, ies_len, buf, end);
6277 static void wpas_p2p_clear_pending_action_tx(struct wpa_supplicant *wpa_s)
6279 if (!offchannel_pending_action_tx(wpa_s))
6282 wpas_p2p_action_tx_clear(wpa_s);
6284 wpa_printf(MSG_DEBUG, "P2P: Drop pending Action TX due to new "
6285 "operation request");
6286 offchannel_clear_pending_action_tx(wpa_s);
6290 int wpas_p2p_find(struct wpa_supplicant *wpa_s, unsigned int timeout,
6291 enum p2p_discovery_type type,
6292 unsigned int num_req_dev_types, const u8 *req_dev_types,
6293 const u8 *dev_id, unsigned int search_delay,
6294 u8 seek_cnt, const char **seek_string, int freq)
6296 wpas_p2p_clear_pending_action_tx(wpa_s);
6297 wpa_s->p2p_long_listen = 0;
6299 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL ||
6300 wpa_s->p2p_in_provisioning)
6303 wpa_supplicant_cancel_sched_scan(wpa_s);
6305 return p2p_find(wpa_s->global->p2p, timeout, type,
6306 num_req_dev_types, req_dev_types, dev_id,
6307 search_delay, seek_cnt, seek_string, freq);
6311 static void wpas_p2p_scan_res_ignore_search(struct wpa_supplicant *wpa_s,
6312 struct wpa_scan_results *scan_res)
6314 wpa_printf(MSG_DEBUG, "P2P: Ignore scan results");
6316 if (wpa_s->p2p_scan_work) {
6317 struct wpa_radio_work *work = wpa_s->p2p_scan_work;
6318 wpa_s->p2p_scan_work = NULL;
6319 radio_work_done(work);
6322 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
6326 * Indicate that results have been processed so that the P2P module can
6327 * continue pending tasks.
6329 p2p_scan_res_handled(wpa_s->global->p2p);
6333 static void wpas_p2p_stop_find_oper(struct wpa_supplicant *wpa_s)
6335 wpas_p2p_clear_pending_action_tx(wpa_s);
6336 wpa_s->p2p_long_listen = 0;
6337 eloop_cancel_timeout(wpas_p2p_long_listen_timeout, wpa_s, NULL);
6338 eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL);
6340 if (wpa_s->global->p2p)
6341 p2p_stop_find(wpa_s->global->p2p);
6343 if (wpa_s->scan_res_handler == wpas_p2p_scan_res_handler) {
6344 wpa_printf(MSG_DEBUG,
6345 "P2P: Do not consider the scan results after stop_find");
6346 wpa_s->scan_res_handler = wpas_p2p_scan_res_ignore_search;
6351 void wpas_p2p_stop_find(struct wpa_supplicant *wpa_s)
6353 wpas_p2p_stop_find_oper(wpa_s);
6354 if (!wpa_s->global->pending_group_iface_for_p2ps)
6355 wpas_p2p_remove_pending_group_interface(wpa_s);
6359 static void wpas_p2p_long_listen_timeout(void *eloop_ctx, void *timeout_ctx)
6361 struct wpa_supplicant *wpa_s = eloop_ctx;
6362 wpa_s->p2p_long_listen = 0;
6366 int wpas_p2p_listen(struct wpa_supplicant *wpa_s, unsigned int timeout)
6370 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
6373 wpa_supplicant_cancel_sched_scan(wpa_s);
6374 wpas_p2p_clear_pending_action_tx(wpa_s);
6378 * This is a request for unlimited Listen state. However, at
6379 * least for now, this is mapped to a Listen state for one
6384 eloop_cancel_timeout(wpas_p2p_long_listen_timeout, wpa_s, NULL);
6385 wpa_s->p2p_long_listen = 0;
6388 * Stop previous find/listen operation to avoid trying to request a new
6389 * remain-on-channel operation while the driver is still running the
6392 if (wpa_s->global->p2p)
6393 p2p_stop_find(wpa_s->global->p2p);
6395 res = wpas_p2p_listen_start(wpa_s, timeout * 1000);
6396 if (res == 0 && timeout * 1000 > wpa_s->max_remain_on_chan) {
6397 wpa_s->p2p_long_listen = timeout * 1000;
6398 eloop_register_timeout(timeout, 0,
6399 wpas_p2p_long_listen_timeout,
6407 int wpas_p2p_assoc_req_ie(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
6408 u8 *buf, size_t len, int p2p_group)
6410 struct wpabuf *p2p_ie;
6413 if (wpa_s->global->p2p_disabled)
6416 * Advertize mandatory cross connection capability even on
6417 * p2p_disabled=1 interface when associating with a P2P Manager WLAN AP.
6419 if (wpa_s->conf->p2p_disabled && p2p_group)
6421 if (wpa_s->global->p2p == NULL)
6426 p2p_ie = wpa_bss_get_vendor_ie_multi(bss, P2P_IE_VENDOR_TYPE);
6427 ret = p2p_assoc_req_ie(wpa_s->global->p2p, bss->bssid, buf, len,
6429 wpabuf_free(p2p_ie);
6435 int wpas_p2p_probe_req_rx(struct wpa_supplicant *wpa_s, const u8 *addr,
6436 const u8 *dst, const u8 *bssid,
6437 const u8 *ie, size_t ie_len,
6438 unsigned int rx_freq, int ssi_signal)
6440 if (wpa_s->global->p2p_disabled)
6442 if (wpa_s->global->p2p == NULL)
6445 switch (p2p_probe_req_rx(wpa_s->global->p2p, addr, dst, bssid,
6446 ie, ie_len, rx_freq)) {
6447 case P2P_PREQ_NOT_P2P:
6448 wpas_notify_preq(wpa_s, addr, dst, bssid, ie, ie_len,
6451 case P2P_PREQ_MALFORMED:
6452 case P2P_PREQ_NOT_LISTEN:
6453 case P2P_PREQ_NOT_PROCESSED:
6454 default: /* make gcc happy */
6456 case P2P_PREQ_PROCESSED:
6462 void wpas_p2p_rx_action(struct wpa_supplicant *wpa_s, const u8 *da,
6463 const u8 *sa, const u8 *bssid,
6464 u8 category, const u8 *data, size_t len, int freq)
6466 if (wpa_s->global->p2p_disabled)
6468 if (wpa_s->global->p2p == NULL)
6471 p2p_rx_action(wpa_s->global->p2p, da, sa, bssid, category, data, len,
6476 void wpas_p2p_scan_ie(struct wpa_supplicant *wpa_s, struct wpabuf *ies)
6478 if (wpa_s->global->p2p_disabled)
6480 if (wpa_s->global->p2p == NULL)
6483 p2p_scan_ie(wpa_s->global->p2p, ies, NULL);
6487 static void wpas_p2p_group_deinit(struct wpa_supplicant *wpa_s)
6489 p2p_group_deinit(wpa_s->p2p_group);
6490 wpa_s->p2p_group = NULL;
6492 wpa_s->ap_configured_cb = NULL;
6493 wpa_s->ap_configured_cb_ctx = NULL;
6494 wpa_s->ap_configured_cb_data = NULL;
6495 wpa_s->connect_without_scan = NULL;
6499 int wpas_p2p_reject(struct wpa_supplicant *wpa_s, const u8 *addr)
6501 wpa_s->p2p_long_listen = 0;
6503 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
6506 return p2p_reject(wpa_s->global->p2p, addr);
6510 /* Invite to reinvoke a persistent group */
6511 int wpas_p2p_invite(struct wpa_supplicant *wpa_s, const u8 *peer_addr,
6512 struct wpa_ssid *ssid, const u8 *go_dev_addr, int freq,
6513 int ht40, int vht, int pref_freq)
6515 enum p2p_invite_role role;
6519 int no_pref_freq_given = pref_freq == 0;
6520 unsigned int pref_freq_list[P2P_MAX_PREF_CHANNELS], size;
6522 wpa_s->global->p2p_invite_group = NULL;
6524 os_memcpy(wpa_s->p2p_auth_invite, peer_addr, ETH_ALEN);
6526 os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
6528 wpa_s->p2p_persistent_go_freq = freq;
6529 wpa_s->p2p_go_ht40 = !!ht40;
6530 if (ssid->mode == WPAS_MODE_P2P_GO) {
6531 role = P2P_INVITE_ROLE_GO;
6532 if (peer_addr == NULL) {
6533 wpa_printf(MSG_DEBUG, "P2P: Missing peer "
6534 "address in invitation command");
6537 if (wpas_p2p_create_iface(wpa_s)) {
6538 if (wpas_p2p_add_group_interface(wpa_s,
6539 WPA_IF_P2P_GO) < 0) {
6540 wpa_printf(MSG_ERROR, "P2P: Failed to "
6541 "allocate a new interface for the "
6545 bssid = wpa_s->pending_interface_addr;
6547 bssid = wpa_s->own_addr;
6549 role = P2P_INVITE_ROLE_CLIENT;
6550 peer_addr = ssid->bssid;
6552 wpa_s->pending_invite_ssid_id = ssid->id;
6554 size = P2P_MAX_PREF_CHANNELS;
6555 res = wpas_p2p_setup_freqs(wpa_s, freq, &force_freq, &pref_freq,
6556 role == P2P_INVITE_ROLE_GO,
6557 pref_freq_list, &size);
6560 p2p_set_own_pref_freq_list(wpa_s->global->p2p, pref_freq_list, size);
6562 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
6565 if (wpa_s->parent->conf->p2p_ignore_shared_freq &&
6566 no_pref_freq_given && pref_freq > 0 &&
6567 wpa_s->num_multichan_concurrent > 1 &&
6568 wpas_p2p_num_unused_channels(wpa_s) > 0) {
6569 wpa_printf(MSG_DEBUG, "P2P: Ignore own channel preference %d MHz for invitation due to p2p_ignore_shared_freq=1 configuration",
6575 * Stop any find/listen operations before invitation and possibly
6576 * connection establishment.
6578 wpas_p2p_stop_find_oper(wpa_s);
6580 return p2p_invite(wpa_s->global->p2p, peer_addr, role, bssid,
6581 ssid->ssid, ssid->ssid_len, force_freq, go_dev_addr,
6586 /* Invite to join an active group */
6587 int wpas_p2p_invite_group(struct wpa_supplicant *wpa_s, const char *ifname,
6588 const u8 *peer_addr, const u8 *go_dev_addr)
6590 struct wpa_global *global = wpa_s->global;
6591 enum p2p_invite_role role;
6593 struct wpa_ssid *ssid;
6595 int freq = 0, force_freq = 0, pref_freq = 0;
6597 unsigned int pref_freq_list[P2P_MAX_PREF_CHANNELS], size;
6599 wpa_s->p2p_persistent_go_freq = 0;
6600 wpa_s->p2p_go_ht40 = 0;
6601 wpa_s->p2p_go_vht = 0;
6603 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
6604 if (os_strcmp(wpa_s->ifname, ifname) == 0)
6607 if (wpa_s == NULL) {
6608 wpa_printf(MSG_DEBUG, "P2P: Interface '%s' not found", ifname);
6612 ssid = wpa_s->current_ssid;
6614 wpa_printf(MSG_DEBUG, "P2P: No current SSID to use for "
6619 wpa_s->global->p2p_invite_group = wpa_s;
6620 persistent = ssid->p2p_persistent_group &&
6621 wpas_p2p_get_persistent(wpa_s->parent, peer_addr,
6622 ssid->ssid, ssid->ssid_len);
6624 if (ssid->mode == WPAS_MODE_P2P_GO) {
6625 role = P2P_INVITE_ROLE_ACTIVE_GO;
6626 bssid = wpa_s->own_addr;
6627 if (go_dev_addr == NULL)
6628 go_dev_addr = wpa_s->global->p2p_dev_addr;
6629 freq = ssid->frequency;
6631 role = P2P_INVITE_ROLE_CLIENT;
6632 if (wpa_s->wpa_state < WPA_ASSOCIATED) {
6633 wpa_printf(MSG_DEBUG, "P2P: Not associated - cannot "
6634 "invite to current group");
6637 bssid = wpa_s->bssid;
6638 if (go_dev_addr == NULL &&
6639 !is_zero_ether_addr(wpa_s->go_dev_addr))
6640 go_dev_addr = wpa_s->go_dev_addr;
6641 freq = wpa_s->current_bss ? wpa_s->current_bss->freq :
6642 (int) wpa_s->assoc_freq;
6644 wpa_s->parent->pending_invite_ssid_id = -1;
6646 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
6649 size = P2P_MAX_PREF_CHANNELS;
6650 res = wpas_p2p_setup_freqs(wpa_s, freq, &force_freq, &pref_freq,
6651 role == P2P_INVITE_ROLE_ACTIVE_GO,
6652 pref_freq_list, &size);
6655 wpas_p2p_set_own_freq_preference(wpa_s, force_freq);
6657 return p2p_invite(wpa_s->global->p2p, peer_addr, role, bssid,
6658 ssid->ssid, ssid->ssid_len, force_freq,
6659 go_dev_addr, persistent, pref_freq, -1);
6663 void wpas_p2p_completed(struct wpa_supplicant *wpa_s)
6665 struct wpa_ssid *ssid = wpa_s->current_ssid;
6666 u8 go_dev_addr[ETH_ALEN];
6667 int network_id = -1;
6673 if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GROUP_FORMATION) {
6674 eloop_cancel_timeout(wpas_p2p_group_formation_timeout,
6675 wpa_s->parent, NULL);
6678 if (!wpa_s->show_group_started || !ssid)
6681 wpa_s->show_group_started = 0;
6683 os_memset(go_dev_addr, 0, ETH_ALEN);
6684 if (ssid->bssid_set)
6685 os_memcpy(go_dev_addr, ssid->bssid, ETH_ALEN);
6686 persistent = wpas_p2p_persistent_group(wpa_s, go_dev_addr, ssid->ssid,
6688 os_memcpy(wpa_s->go_dev_addr, go_dev_addr, ETH_ALEN);
6690 if (wpa_s->global->p2p_group_formation == wpa_s)
6691 wpa_s->global->p2p_group_formation = NULL;
6693 freq = wpa_s->current_bss ? wpa_s->current_bss->freq :
6694 (int) wpa_s->assoc_freq;
6697 if (wpa_sm_get_p2p_ip_addr(wpa_s->wpa, ip) == 0) {
6700 res = os_snprintf(ip_addr, sizeof(ip_addr),
6701 " ip_addr=%u.%u.%u.%u "
6702 "ip_mask=%u.%u.%u.%u go_ip_addr=%u.%u.%u.%u",
6703 ip[0], ip[1], ip[2], ip[3],
6704 ip[4], ip[5], ip[6], ip[7],
6705 ip[8], ip[9], ip[10], ip[11]);
6706 if (os_snprintf_error(sizeof(ip_addr), res))
6710 wpas_p2p_group_started(wpa_s, 0, ssid, freq,
6711 ssid->passphrase == NULL && ssid->psk_set ?
6713 ssid->passphrase, go_dev_addr, persistent,
6717 network_id = wpas_p2p_store_persistent_group(wpa_s->parent,
6720 network_id = ssid->id;
6721 wpas_notify_p2p_group_started(wpa_s, ssid, network_id, 1);
6725 int wpas_p2p_presence_req(struct wpa_supplicant *wpa_s, u32 duration1,
6726 u32 interval1, u32 duration2, u32 interval2)
6730 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
6733 if (wpa_s->wpa_state < WPA_ASSOCIATED ||
6734 wpa_s->current_ssid == NULL ||
6735 wpa_s->current_ssid->mode != WPAS_MODE_INFRA)
6738 ret = p2p_presence_req(wpa_s->global->p2p, wpa_s->bssid,
6739 wpa_s->own_addr, wpa_s->assoc_freq,
6740 duration1, interval1, duration2, interval2);
6742 wpa_s->waiting_presence_resp = 1;
6748 int wpas_p2p_ext_listen(struct wpa_supplicant *wpa_s, unsigned int period,
6749 unsigned int interval)
6751 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
6754 return p2p_ext_listen(wpa_s->global->p2p, period, interval);
6758 static int wpas_p2p_is_client(struct wpa_supplicant *wpa_s)
6760 if (wpa_s->current_ssid == NULL) {
6762 * current_ssid can be cleared when P2P client interface gets
6763 * disconnected, so assume this interface was used as P2P
6768 return wpa_s->current_ssid->p2p_group &&
6769 wpa_s->current_ssid->mode == WPAS_MODE_INFRA;
6773 static void wpas_p2p_group_idle_timeout(void *eloop_ctx, void *timeout_ctx)
6775 struct wpa_supplicant *wpa_s = eloop_ctx;
6777 if (wpa_s->conf->p2p_group_idle == 0 && !wpas_p2p_is_client(wpa_s)) {
6778 wpa_printf(MSG_DEBUG, "P2P: Ignore group idle timeout - "
6783 wpa_printf(MSG_DEBUG, "P2P: Group idle timeout reached - terminate "
6785 wpas_p2p_group_delete(wpa_s, P2P_GROUP_REMOVAL_IDLE_TIMEOUT);
6789 static void wpas_p2p_set_group_idle_timeout(struct wpa_supplicant *wpa_s)
6793 if (eloop_cancel_timeout(wpas_p2p_group_idle_timeout, wpa_s, NULL) > 0)
6794 wpa_printf(MSG_DEBUG, "P2P: Cancelled P2P group idle timeout");
6796 if (wpa_s->current_ssid == NULL || !wpa_s->current_ssid->p2p_group)
6799 timeout = wpa_s->conf->p2p_group_idle;
6800 if (wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
6801 (timeout == 0 || timeout > P2P_MAX_CLIENT_IDLE))
6802 timeout = P2P_MAX_CLIENT_IDLE;
6808 if (wpa_s->current_ssid->mode == WPAS_MODE_INFRA)
6809 timeout = 0; /* special client mode no-timeout */
6814 if (wpa_s->p2p_in_provisioning) {
6816 * Use the normal group formation timeout during the
6817 * provisioning phase to avoid terminating this process too
6818 * early due to group idle timeout.
6820 wpa_printf(MSG_DEBUG, "P2P: Do not use P2P group idle timeout "
6821 "during provisioning");
6825 if (wpa_s->show_group_started) {
6827 * Use the normal group formation timeout between the end of
6828 * the provisioning phase and completion of 4-way handshake to
6829 * avoid terminating this process too early due to group idle
6832 wpa_printf(MSG_DEBUG, "P2P: Do not use P2P group idle timeout "
6833 "while waiting for initial 4-way handshake to "
6838 wpa_printf(MSG_DEBUG, "P2P: Set P2P group idle timeout to %u seconds",
6840 eloop_register_timeout(timeout, 0, wpas_p2p_group_idle_timeout,
6845 /* Returns 1 if the interface was removed */
6846 int wpas_p2p_deauth_notif(struct wpa_supplicant *wpa_s, const u8 *bssid,
6847 u16 reason_code, const u8 *ie, size_t ie_len,
6848 int locally_generated)
6850 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
6853 if (!locally_generated)
6854 p2p_deauth_notif(wpa_s->global->p2p, bssid, reason_code, ie,
6857 if (reason_code == WLAN_REASON_DEAUTH_LEAVING && !locally_generated &&
6858 wpa_s->current_ssid &&
6859 wpa_s->current_ssid->p2p_group &&
6860 wpa_s->current_ssid->mode == WPAS_MODE_INFRA) {
6861 wpa_printf(MSG_DEBUG, "P2P: GO indicated that the P2P Group "
6862 "session is ending");
6863 if (wpas_p2p_group_delete(wpa_s,
6864 P2P_GROUP_REMOVAL_GO_ENDING_SESSION)
6873 void wpas_p2p_disassoc_notif(struct wpa_supplicant *wpa_s, const u8 *bssid,
6874 u16 reason_code, const u8 *ie, size_t ie_len,
6875 int locally_generated)
6877 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
6880 if (!locally_generated)
6881 p2p_disassoc_notif(wpa_s->global->p2p, bssid, reason_code, ie,
6886 void wpas_p2p_update_config(struct wpa_supplicant *wpa_s)
6888 struct p2p_data *p2p = wpa_s->global->p2p;
6893 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_CAPABLE))
6896 if (wpa_s->conf->changed_parameters & CFG_CHANGED_DEVICE_NAME)
6897 p2p_set_dev_name(p2p, wpa_s->conf->device_name);
6899 if (wpa_s->conf->changed_parameters & CFG_CHANGED_DEVICE_TYPE)
6900 p2p_set_pri_dev_type(p2p, wpa_s->conf->device_type);
6903 (wpa_s->conf->changed_parameters & CFG_CHANGED_CONFIG_METHODS))
6904 p2p_set_config_methods(p2p, wpa_s->wps->config_methods);
6906 if (wpa_s->wps && (wpa_s->conf->changed_parameters & CFG_CHANGED_UUID))
6907 p2p_set_uuid(p2p, wpa_s->wps->uuid);
6909 if (wpa_s->conf->changed_parameters & CFG_CHANGED_WPS_STRING) {
6910 p2p_set_manufacturer(p2p, wpa_s->conf->manufacturer);
6911 p2p_set_model_name(p2p, wpa_s->conf->model_name);
6912 p2p_set_model_number(p2p, wpa_s->conf->model_number);
6913 p2p_set_serial_number(p2p, wpa_s->conf->serial_number);
6916 if (wpa_s->conf->changed_parameters & CFG_CHANGED_SEC_DEVICE_TYPE)
6917 p2p_set_sec_dev_types(p2p,
6918 (void *) wpa_s->conf->sec_device_type,
6919 wpa_s->conf->num_sec_device_types);
6921 if (wpa_s->conf->changed_parameters & CFG_CHANGED_VENDOR_EXTENSION) {
6923 p2p_remove_wps_vendor_extensions(p2p);
6924 for (i = 0; i < MAX_WPS_VENDOR_EXT; i++) {
6925 if (wpa_s->conf->wps_vendor_ext[i] == NULL)
6927 p2p_add_wps_vendor_extension(
6928 p2p, wpa_s->conf->wps_vendor_ext[i]);
6932 if ((wpa_s->conf->changed_parameters & CFG_CHANGED_COUNTRY) &&
6933 wpa_s->conf->country[0] && wpa_s->conf->country[1]) {
6935 country[0] = wpa_s->conf->country[0];
6936 country[1] = wpa_s->conf->country[1];
6938 p2p_set_country(p2p, country);
6941 if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_SSID_POSTFIX) {
6942 p2p_set_ssid_postfix(p2p, (u8 *) wpa_s->conf->p2p_ssid_postfix,
6943 wpa_s->conf->p2p_ssid_postfix ?
6944 os_strlen(wpa_s->conf->p2p_ssid_postfix) :
6948 if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_INTRA_BSS)
6949 p2p_set_intra_bss_dist(p2p, wpa_s->conf->p2p_intra_bss);
6951 if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_LISTEN_CHANNEL) {
6952 u8 reg_class, channel;
6957 if (wpa_s->conf->p2p_listen_reg_class &&
6958 wpa_s->conf->p2p_listen_channel) {
6959 reg_class = wpa_s->conf->p2p_listen_reg_class;
6960 channel = wpa_s->conf->p2p_listen_channel;
6965 * Pick one of the social channels randomly as the
6968 if (os_get_random((u8 *) &r, sizeof(r)) < 0)
6971 channel = 1 + (r % 3) * 5;
6974 ret = p2p_set_listen_channel(p2p, reg_class, channel,
6977 wpa_printf(MSG_ERROR, "P2P: Own listen channel update "
6980 if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_OPER_CHANNEL) {
6981 u8 op_reg_class, op_channel, cfg_op_channel;
6984 if (wpa_s->conf->p2p_oper_reg_class &&
6985 wpa_s->conf->p2p_oper_channel) {
6986 op_reg_class = wpa_s->conf->p2p_oper_reg_class;
6987 op_channel = wpa_s->conf->p2p_oper_channel;
6992 * Use random operation channel from (1, 6, 11)
6993 *if no other preference is indicated.
6995 if (os_get_random((u8 *) &r, sizeof(r)) < 0)
6998 op_channel = 1 + (r % 3) * 5;
7001 ret = p2p_set_oper_channel(p2p, op_reg_class, op_channel,
7004 wpa_printf(MSG_ERROR, "P2P: Own oper channel update "
7008 if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_PREF_CHAN) {
7009 if (p2p_set_pref_chan(p2p, wpa_s->conf->num_p2p_pref_chan,
7010 wpa_s->conf->p2p_pref_chan) < 0) {
7011 wpa_printf(MSG_ERROR, "P2P: Preferred channel list "
7015 if (p2p_set_no_go_freq(p2p, &wpa_s->conf->p2p_no_go_freq) < 0) {
7016 wpa_printf(MSG_ERROR, "P2P: No GO channel list "
7021 if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_PASSPHRASE_LEN)
7022 p2p_set_passphrase_len(p2p, wpa_s->conf->p2p_passphrase_len);
7026 int wpas_p2p_set_noa(struct wpa_supplicant *wpa_s, u8 count, int start,
7029 if (!wpa_s->ap_iface)
7031 return hostapd_p2p_set_noa(wpa_s->ap_iface->bss[0], count, start,
7036 int wpas_p2p_set_cross_connect(struct wpa_supplicant *wpa_s, int enabled)
7038 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
7041 wpa_s->global->cross_connection = enabled;
7042 p2p_set_cross_connect(wpa_s->global->p2p, enabled);
7045 struct wpa_supplicant *iface;
7047 for (iface = wpa_s->global->ifaces; iface; iface = iface->next)
7049 if (iface->cross_connect_enabled == 0)
7052 iface->cross_connect_enabled = 0;
7053 iface->cross_connect_in_use = 0;
7054 wpa_msg_global(iface->parent, MSG_INFO,
7055 P2P_EVENT_CROSS_CONNECT_DISABLE "%s %s",
7057 iface->cross_connect_uplink);
7065 static void wpas_p2p_enable_cross_connect(struct wpa_supplicant *uplink)
7067 struct wpa_supplicant *iface;
7069 if (!uplink->global->cross_connection)
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->ap_iface == NULL)
7080 if (iface->cross_connect_in_use)
7083 iface->cross_connect_in_use = 1;
7084 wpa_msg_global(iface->parent, MSG_INFO,
7085 P2P_EVENT_CROSS_CONNECT_ENABLE "%s %s",
7086 iface->ifname, iface->cross_connect_uplink);
7091 static void wpas_p2p_disable_cross_connect(struct wpa_supplicant *uplink)
7093 struct wpa_supplicant *iface;
7095 for (iface = uplink->global->ifaces; iface; iface = iface->next) {
7096 if (!iface->cross_connect_enabled)
7098 if (os_strcmp(uplink->ifname, iface->cross_connect_uplink) !=
7101 if (!iface->cross_connect_in_use)
7104 wpa_msg_global(iface->parent, MSG_INFO,
7105 P2P_EVENT_CROSS_CONNECT_DISABLE "%s %s",
7106 iface->ifname, iface->cross_connect_uplink);
7107 iface->cross_connect_in_use = 0;
7112 void wpas_p2p_notif_connected(struct wpa_supplicant *wpa_s)
7114 if (wpa_s->ap_iface || wpa_s->current_ssid == NULL ||
7115 wpa_s->current_ssid->mode != WPAS_MODE_INFRA ||
7116 wpa_s->cross_connect_disallowed)
7117 wpas_p2p_disable_cross_connect(wpa_s);
7119 wpas_p2p_enable_cross_connect(wpa_s);
7120 if (!wpa_s->ap_iface &&
7121 eloop_cancel_timeout(wpas_p2p_group_idle_timeout, wpa_s, NULL) > 0)
7122 wpa_printf(MSG_DEBUG, "P2P: Cancelled P2P group idle timeout");
7126 void wpas_p2p_notif_disconnected(struct wpa_supplicant *wpa_s)
7128 wpas_p2p_disable_cross_connect(wpa_s);
7129 if (!wpa_s->ap_iface &&
7130 !eloop_is_timeout_registered(wpas_p2p_group_idle_timeout,
7132 wpas_p2p_set_group_idle_timeout(wpa_s);
7136 static void wpas_p2p_cross_connect_setup(struct wpa_supplicant *wpa_s)
7138 struct wpa_supplicant *iface;
7140 if (!wpa_s->global->cross_connection)
7143 for (iface = wpa_s->global->ifaces; iface; iface = iface->next) {
7146 if (iface->drv_flags &
7147 WPA_DRIVER_FLAGS_P2P_DEDICATED_INTERFACE)
7149 if ((iface->drv_flags & WPA_DRIVER_FLAGS_P2P_CAPABLE) &&
7150 iface != wpa_s->parent)
7153 wpa_s->cross_connect_enabled = 1;
7154 os_strlcpy(wpa_s->cross_connect_uplink, iface->ifname,
7155 sizeof(wpa_s->cross_connect_uplink));
7156 wpa_printf(MSG_DEBUG, "P2P: Enable cross connection from "
7157 "%s to %s whenever uplink is available",
7158 wpa_s->ifname, wpa_s->cross_connect_uplink);
7160 if (iface->ap_iface || iface->current_ssid == NULL ||
7161 iface->current_ssid->mode != WPAS_MODE_INFRA ||
7162 iface->cross_connect_disallowed ||
7163 iface->wpa_state != WPA_COMPLETED)
7166 wpa_s->cross_connect_in_use = 1;
7167 wpa_msg_global(wpa_s->parent, MSG_INFO,
7168 P2P_EVENT_CROSS_CONNECT_ENABLE "%s %s",
7169 wpa_s->ifname, wpa_s->cross_connect_uplink);
7175 int wpas_p2p_notif_pbc_overlap(struct wpa_supplicant *wpa_s)
7177 if (wpa_s->p2p_group_interface != P2P_GROUP_INTERFACE_CLIENT &&
7178 !wpa_s->p2p_in_provisioning)
7179 return 0; /* not P2P client operation */
7181 wpa_printf(MSG_DEBUG, "P2P: Terminate connection due to WPS PBC "
7183 if (wpa_s != wpa_s->parent)
7184 wpa_msg_ctrl(wpa_s->parent, MSG_INFO, WPS_EVENT_OVERLAP);
7185 wpas_p2p_group_formation_failed(wpa_s, 0);
7190 void wpas_p2p_pbc_overlap_cb(void *eloop_ctx, void *timeout_ctx)
7192 struct wpa_supplicant *wpa_s = eloop_ctx;
7193 wpas_p2p_notif_pbc_overlap(wpa_s);
7197 void wpas_p2p_update_channel_list(struct wpa_supplicant *wpa_s,
7198 enum wpas_p2p_channel_update_trig trig)
7200 struct p2p_channels chan, cli_chan;
7201 struct wpa_used_freq_data *freqs = NULL;
7202 unsigned int num = wpa_s->num_multichan_concurrent;
7204 if (wpa_s->global == NULL || wpa_s->global->p2p == NULL)
7207 freqs = os_calloc(num, sizeof(struct wpa_used_freq_data));
7211 num = get_shared_radio_freqs_data(wpa_s, freqs, num);
7213 os_memset(&chan, 0, sizeof(chan));
7214 os_memset(&cli_chan, 0, sizeof(cli_chan));
7215 if (wpas_p2p_setup_channels(wpa_s, &chan, &cli_chan)) {
7216 wpa_printf(MSG_ERROR, "P2P: Failed to update supported "
7221 p2p_update_channel_list(wpa_s->global->p2p, &chan, &cli_chan);
7223 wpas_p2p_optimize_listen_channel(wpa_s, freqs, num);
7226 * The used frequencies map changed, so it is possible that a GO is
7227 * using a channel that is no longer valid for P2P use. It is also
7228 * possible that due to policy consideration, it would be preferable to
7229 * move it to a frequency already used by other station interfaces.
7231 wpas_p2p_consider_moving_gos(wpa_s, freqs, num, trig);
7237 static void wpas_p2p_scan_res_ignore(struct wpa_supplicant *wpa_s,
7238 struct wpa_scan_results *scan_res)
7240 wpa_printf(MSG_DEBUG, "P2P: Ignore scan results");
7244 int wpas_p2p_cancel(struct wpa_supplicant *wpa_s)
7246 struct wpa_global *global = wpa_s->global;
7250 if (global->p2p == NULL)
7253 wpa_printf(MSG_DEBUG, "P2P: Request to cancel group formation");
7255 if (wpa_s->pending_interface_name[0] &&
7256 !is_zero_ether_addr(wpa_s->pending_interface_addr))
7259 peer = p2p_get_go_neg_peer(global->p2p);
7261 wpa_printf(MSG_DEBUG, "P2P: Unauthorize pending GO Neg peer "
7262 MACSTR, MAC2STR(peer));
7263 p2p_unauthorize(global->p2p, peer);
7267 if (wpa_s->scan_res_handler == wpas_p2p_scan_res_join) {
7268 wpa_printf(MSG_DEBUG, "P2P: Stop pending scan for join");
7269 wpa_s->scan_res_handler = wpas_p2p_scan_res_ignore;
7273 if (wpa_s->pending_pd_before_join) {
7274 wpa_printf(MSG_DEBUG, "P2P: Stop pending PD before join");
7275 wpa_s->pending_pd_before_join = 0;
7279 wpas_p2p_stop_find(wpa_s);
7281 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
7282 if (wpa_s == global->p2p_group_formation &&
7283 (wpa_s->p2p_in_provisioning ||
7284 wpa_s->parent->pending_interface_type ==
7285 WPA_IF_P2P_CLIENT)) {
7286 wpa_printf(MSG_DEBUG, "P2P: Interface %s in group "
7287 "formation found - cancelling",
7290 eloop_cancel_timeout(wpas_p2p_group_formation_timeout,
7291 wpa_s->parent, NULL);
7292 if (wpa_s->p2p_in_provisioning) {
7293 wpas_group_formation_completed(wpa_s, 0, 0);
7296 wpas_p2p_group_delete(wpa_s,
7297 P2P_GROUP_REMOVAL_REQUESTED);
7299 } else if (wpa_s->p2p_in_invitation) {
7300 wpa_printf(MSG_DEBUG, "P2P: Interface %s in invitation found - cancelling",
7303 wpas_p2p_group_formation_failed(wpa_s, 0);
7308 wpa_printf(MSG_DEBUG, "P2P: No ongoing group formation found");
7316 void wpas_p2p_interface_unavailable(struct wpa_supplicant *wpa_s)
7318 if (wpa_s->current_ssid == NULL || !wpa_s->current_ssid->p2p_group)
7321 wpa_printf(MSG_DEBUG, "P2P: Remove group due to driver resource not "
7322 "being available anymore");
7323 wpas_p2p_group_delete(wpa_s, P2P_GROUP_REMOVAL_UNAVAILABLE);
7327 void wpas_p2p_update_best_channels(struct wpa_supplicant *wpa_s,
7328 int freq_24, int freq_5, int freq_overall)
7330 struct p2p_data *p2p = wpa_s->global->p2p;
7333 p2p_set_best_channels(p2p, freq_24, freq_5, freq_overall);
7337 int wpas_p2p_unauthorize(struct wpa_supplicant *wpa_s, const char *addr)
7340 struct p2p_data *p2p = wpa_s->global->p2p;
7345 if (hwaddr_aton(addr, peer))
7348 return p2p_unauthorize(p2p, peer);
7353 * wpas_p2p_disconnect - Disconnect from a P2P Group
7354 * @wpa_s: Pointer to wpa_supplicant data
7355 * Returns: 0 on success, -1 on failure
7357 * This can be used to disconnect from a group in which the local end is a P2P
7358 * Client or to end a P2P Group in case the local end is the Group Owner. If a
7359 * virtual network interface was created for this group, that interface will be
7360 * removed. Otherwise, only the configured P2P group network will be removed
7361 * from the interface.
7363 int wpas_p2p_disconnect(struct wpa_supplicant *wpa_s)
7369 return wpas_p2p_group_delete(wpa_s, P2P_GROUP_REMOVAL_REQUESTED) < 0 ?
7374 int wpas_p2p_in_progress(struct wpa_supplicant *wpa_s)
7378 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
7381 ret = p2p_in_progress(wpa_s->global->p2p);
7384 * Check whether there is an ongoing WPS provisioning step (or
7385 * other parts of group formation) on another interface since
7386 * p2p_in_progress() does not report this to avoid issues for
7387 * scans during such provisioning step.
7389 if (wpa_s->global->p2p_group_formation &&
7390 wpa_s->global->p2p_group_formation != wpa_s) {
7391 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Another interface (%s) "
7392 "in group formation",
7393 wpa_s->global->p2p_group_formation->ifname);
7398 if (!ret && wpa_s->global->p2p_go_wait_client.sec) {
7399 struct os_reltime now;
7400 os_get_reltime(&now);
7401 if (os_reltime_expired(&now, &wpa_s->global->p2p_go_wait_client,
7402 P2P_MAX_INITIAL_CONN_WAIT_GO)) {
7403 /* Wait for the first client has expired */
7404 wpa_s->global->p2p_go_wait_client.sec = 0;
7406 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Waiting for initial client connection during group formation");
7415 void wpas_p2p_network_removed(struct wpa_supplicant *wpa_s,
7416 struct wpa_ssid *ssid)
7418 if (wpa_s->p2p_in_provisioning && ssid->p2p_group &&
7419 eloop_cancel_timeout(wpas_p2p_group_formation_timeout,
7420 wpa_s->parent, NULL) > 0) {
7422 * Remove the network by scheduling the group formation
7423 * timeout to happen immediately. The teardown code
7424 * needs to be scheduled to run asynch later so that we
7425 * don't delete data from under ourselves unexpectedly.
7426 * Calling wpas_p2p_group_formation_timeout directly
7427 * causes a series of crashes in WPS failure scenarios.
7429 wpa_printf(MSG_DEBUG, "P2P: Canceled group formation due to "
7430 "P2P group network getting removed");
7431 eloop_register_timeout(0, 0, wpas_p2p_group_formation_timeout,
7432 wpa_s->parent, NULL);
7437 struct wpa_ssid * wpas_p2p_get_persistent(struct wpa_supplicant *wpa_s,
7438 const u8 *addr, const u8 *ssid,
7444 for (s = wpa_s->conf->ssid; s; s = s->next) {
7445 if (s->disabled != 2)
7448 (ssid_len != s->ssid_len ||
7449 os_memcmp(ssid, s->ssid, ssid_len) != 0))
7452 if (s->mode == WPAS_MODE_P2P_GO)
7456 if (os_memcmp(s->bssid, addr, ETH_ALEN) == 0)
7457 return s; /* peer is GO in the persistent group */
7458 if (s->mode != WPAS_MODE_P2P_GO || s->p2p_client_list == NULL)
7460 for (i = 0; i < s->num_p2p_clients; i++) {
7461 if (os_memcmp(s->p2p_client_list + i * 2 * ETH_ALEN,
7462 addr, ETH_ALEN) == 0)
7463 return s; /* peer is P2P client in persistent
7472 void wpas_p2p_notify_ap_sta_authorized(struct wpa_supplicant *wpa_s,
7475 if (eloop_cancel_timeout(wpas_p2p_group_formation_timeout,
7476 wpa_s->parent, NULL) > 0) {
7478 * This can happen if WPS provisioning step is not terminated
7479 * cleanly (e.g., P2P Client does not send WSC_Done). Since the
7480 * peer was able to connect, there is no need to time out group
7481 * formation after this, though. In addition, this is used with
7482 * the initial connection wait on the GO as a separate formation
7483 * timeout and as such, expected to be hit after the initial WPS
7484 * provisioning step.
7486 wpa_printf(MSG_DEBUG, "P2P: Canceled P2P group formation timeout on data connection");
7488 if (!wpa_s->p2p_go_group_formation_completed &&
7489 !wpa_s->group_formation_reported) {
7491 * GO has not yet notified group formation success since
7492 * the WPS step was not completed cleanly. Do that
7493 * notification now since the P2P Client was able to
7494 * connect and as such, must have received the
7495 * credential from the WPS step.
7497 if (wpa_s->global->p2p)
7498 p2p_wps_success_cb(wpa_s->global->p2p, addr);
7499 wpas_group_formation_completed(wpa_s, 1, 0);
7502 if (!wpa_s->p2p_go_group_formation_completed) {
7503 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Marking group formation completed on GO on first data connection");
7504 wpa_s->p2p_go_group_formation_completed = 1;
7505 wpa_s->global->p2p_group_formation = NULL;
7506 wpa_s->p2p_in_provisioning = 0;
7507 wpa_s->p2p_in_invitation = 0;
7509 wpa_s->global->p2p_go_wait_client.sec = 0;
7512 wpas_p2p_add_persistent_group_client(wpa_s, addr);
7516 static int wpas_p2p_fallback_to_go_neg(struct wpa_supplicant *wpa_s,
7519 struct wpa_supplicant *group = wpa_s;
7522 if (wpa_s->global->p2p_group_formation)
7523 group = wpa_s->global->p2p_group_formation;
7524 wpa_s = wpa_s->global->p2p_init_wpa_s;
7525 offchannel_send_action_done(wpa_s);
7527 ret = wpas_p2p_group_delete(group, P2P_GROUP_REMOVAL_SILENT);
7528 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Fall back to GO Negotiation");
7529 wpas_p2p_connect(wpa_s, wpa_s->pending_join_dev_addr, wpa_s->p2p_pin,
7530 wpa_s->p2p_wps_method, wpa_s->p2p_persistent_group, 0,
7531 0, 0, wpa_s->p2p_go_intent, wpa_s->p2p_connect_freq,
7532 wpa_s->p2p_persistent_id,
7533 wpa_s->p2p_pd_before_go_neg,
7540 int wpas_p2p_scan_no_go_seen(struct wpa_supplicant *wpa_s)
7544 if (!wpa_s->p2p_fallback_to_go_neg ||
7545 wpa_s->p2p_in_provisioning <= 5)
7548 if (wpas_p2p_peer_go(wpa_s, wpa_s->pending_join_dev_addr) > 0)
7549 return 0; /* peer operating as a GO */
7551 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: GO not found for p2p_connect-auto - "
7552 "fallback to GO Negotiation");
7553 wpa_msg_global(wpa_s->parent, MSG_INFO, P2P_EVENT_FALLBACK_TO_GO_NEG
7554 "reason=GO-not-found");
7555 res = wpas_p2p_fallback_to_go_neg(wpa_s, 1);
7557 return res == 1 ? 2 : 1;
7561 unsigned int wpas_p2p_search_delay(struct wpa_supplicant *wpa_s)
7563 struct wpa_supplicant *ifs;
7565 if (wpa_s->wpa_state > WPA_SCANNING) {
7566 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Use %u ms search delay due to "
7567 "concurrent operation",
7568 wpa_s->conf->p2p_search_delay);
7569 return wpa_s->conf->p2p_search_delay;
7572 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
7574 if (ifs != wpa_s && ifs->wpa_state > WPA_SCANNING) {
7575 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Use %u ms search "
7576 "delay due to concurrent operation on "
7578 wpa_s->conf->p2p_search_delay,
7580 return wpa_s->conf->p2p_search_delay;
7588 static int wpas_p2p_remove_psk_entry(struct wpa_supplicant *wpa_s,
7589 struct wpa_ssid *s, const u8 *addr,
7592 struct psk_list_entry *psk, *tmp;
7595 dl_list_for_each_safe(psk, tmp, &s->psk_list, struct psk_list_entry,
7597 if ((iface_addr && !psk->p2p &&
7598 os_memcmp(addr, psk->addr, ETH_ALEN) == 0) ||
7599 (!iface_addr && psk->p2p &&
7600 os_memcmp(addr, psk->addr, ETH_ALEN) == 0)) {
7601 wpa_dbg(wpa_s, MSG_DEBUG,
7602 "P2P: Remove persistent group PSK list entry for "
7604 MAC2STR(psk->addr), psk->p2p);
7605 dl_list_del(&psk->list);
7615 void wpas_p2p_new_psk_cb(struct wpa_supplicant *wpa_s, const u8 *mac_addr,
7616 const u8 *p2p_dev_addr,
7617 const u8 *psk, size_t psk_len)
7619 struct wpa_ssid *ssid = wpa_s->current_ssid;
7620 struct wpa_ssid *persistent;
7621 struct psk_list_entry *p, *last;
7623 if (psk_len != sizeof(p->psk))
7627 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: New PSK for addr=" MACSTR
7628 " p2p_dev_addr=" MACSTR,
7629 MAC2STR(mac_addr), MAC2STR(p2p_dev_addr));
7630 if (is_zero_ether_addr(p2p_dev_addr))
7631 p2p_dev_addr = NULL;
7633 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: New PSK for addr=" MACSTR,
7637 if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION) {
7638 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: new_psk_cb during group formation");
7639 /* To be added to persistent group once created */
7640 if (wpa_s->global->add_psk == NULL) {
7641 wpa_s->global->add_psk = os_zalloc(sizeof(*p));
7642 if (wpa_s->global->add_psk == NULL)
7645 p = wpa_s->global->add_psk;
7648 os_memcpy(p->addr, p2p_dev_addr, ETH_ALEN);
7651 os_memcpy(p->addr, mac_addr, ETH_ALEN);
7653 os_memcpy(p->psk, psk, psk_len);
7657 if (ssid->mode != WPAS_MODE_P2P_GO || !ssid->p2p_persistent_group) {
7658 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Ignore new_psk_cb on not-persistent GO");
7662 persistent = wpas_p2p_get_persistent(wpa_s->parent, NULL, ssid->ssid,
7665 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Could not find persistent group information to store the new PSK");
7669 p = os_zalloc(sizeof(*p));
7674 os_memcpy(p->addr, p2p_dev_addr, ETH_ALEN);
7677 os_memcpy(p->addr, mac_addr, ETH_ALEN);
7679 os_memcpy(p->psk, psk, psk_len);
7681 if (dl_list_len(&persistent->psk_list) > P2P_MAX_STORED_CLIENTS &&
7682 (last = dl_list_last(&persistent->psk_list,
7683 struct psk_list_entry, list))) {
7684 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Remove oldest PSK entry for "
7685 MACSTR " (p2p=%u) to make room for a new one",
7686 MAC2STR(last->addr), last->p2p);
7687 dl_list_del(&last->list);
7691 wpas_p2p_remove_psk_entry(wpa_s->parent, persistent,
7692 p2p_dev_addr ? p2p_dev_addr : mac_addr,
7693 p2p_dev_addr == NULL);
7695 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Add new PSK for p2p_dev_addr="
7696 MACSTR, MAC2STR(p2p_dev_addr));
7698 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Add new PSK for addr=" MACSTR,
7701 dl_list_add(&persistent->psk_list, &p->list);
7703 if (wpa_s->parent->conf->update_config &&
7704 wpa_config_write(wpa_s->parent->confname, wpa_s->parent->conf))
7705 wpa_printf(MSG_DEBUG, "P2P: Failed to update configuration");
7709 static void wpas_p2p_remove_psk(struct wpa_supplicant *wpa_s,
7710 struct wpa_ssid *s, const u8 *addr,
7715 res = wpas_p2p_remove_psk_entry(wpa_s, s, addr, iface_addr);
7716 if (res > 0 && wpa_s->conf->update_config &&
7717 wpa_config_write(wpa_s->confname, wpa_s->conf))
7718 wpa_dbg(wpa_s, MSG_DEBUG,
7719 "P2P: Failed to update configuration");
7723 static void wpas_p2p_remove_client_go(struct wpa_supplicant *wpa_s,
7724 const u8 *peer, int iface_addr)
7726 struct hostapd_data *hapd;
7727 struct hostapd_wpa_psk *psk, *prev, *rem;
7728 struct sta_info *sta;
7730 if (wpa_s->ap_iface == NULL || wpa_s->current_ssid == NULL ||
7731 wpa_s->current_ssid->mode != WPAS_MODE_P2P_GO)
7734 /* Remove per-station PSK entry */
7735 hapd = wpa_s->ap_iface->bss[0];
7737 psk = hapd->conf->ssid.wpa_psk;
7739 if ((iface_addr && os_memcmp(peer, psk->addr, ETH_ALEN) == 0) ||
7741 os_memcmp(peer, psk->p2p_dev_addr, ETH_ALEN) == 0)) {
7742 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Remove operating group PSK entry for "
7743 MACSTR " iface_addr=%d",
7744 MAC2STR(peer), iface_addr);
7746 prev->next = psk->next;
7748 hapd->conf->ssid.wpa_psk = psk->next;
7758 /* Disconnect from group */
7760 sta = ap_get_sta(hapd, peer);
7762 sta = ap_get_sta_p2p(hapd, peer);
7764 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Disconnect peer " MACSTR
7765 " (iface_addr=%d) from group",
7766 MAC2STR(peer), iface_addr);
7767 hostapd_drv_sta_deauth(hapd, sta->addr,
7768 WLAN_REASON_DEAUTH_LEAVING);
7769 ap_sta_deauthenticate(hapd, sta, WLAN_REASON_DEAUTH_LEAVING);
7774 void wpas_p2p_remove_client(struct wpa_supplicant *wpa_s, const u8 *peer,
7778 struct wpa_supplicant *w;
7779 struct wpa_supplicant *p2p_wpa_s = wpa_s->global->p2p_init_wpa_s;
7781 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Remove client " MACSTR, MAC2STR(peer));
7783 /* Remove from any persistent group */
7784 for (s = p2p_wpa_s->conf->ssid; s; s = s->next) {
7785 if (s->disabled != 2 || s->mode != WPAS_MODE_P2P_GO)
7788 wpas_remove_persistent_peer(p2p_wpa_s, s, peer, 0);
7789 wpas_p2p_remove_psk(p2p_wpa_s, s, peer, iface_addr);
7792 /* Remove from any operating group */
7793 for (w = wpa_s->global->ifaces; w; w = w->next)
7794 wpas_p2p_remove_client_go(w, peer, iface_addr);
7798 static void wpas_p2p_psk_failure_removal(void *eloop_ctx, void *timeout_ctx)
7800 struct wpa_supplicant *wpa_s = eloop_ctx;
7801 wpas_p2p_group_delete(wpa_s, P2P_GROUP_REMOVAL_PSK_FAILURE);
7805 static void wpas_p2p_group_freq_conflict(void *eloop_ctx, void *timeout_ctx)
7807 struct wpa_supplicant *wpa_s = eloop_ctx;
7809 wpa_printf(MSG_DEBUG, "P2P: Frequency conflict - terminate group");
7810 wpas_p2p_group_delete(wpa_s, P2P_GROUP_REMOVAL_FREQ_CONFLICT);
7814 int wpas_p2p_handle_frequency_conflicts(struct wpa_supplicant *wpa_s, int freq,
7815 struct wpa_ssid *ssid)
7817 struct wpa_supplicant *iface;
7819 for (iface = wpa_s->global->ifaces; iface; iface = iface->next) {
7820 if (!iface->current_ssid ||
7821 iface->current_ssid->frequency == freq ||
7822 (iface->p2p_group_interface == NOT_P2P_GROUP_INTERFACE &&
7823 !iface->current_ssid->p2p_group))
7826 /* Remove the connection with least priority */
7827 if (!wpas_is_p2p_prioritized(iface)) {
7828 /* STA connection has priority over existing
7829 * P2P connection, so remove the interface. */
7830 wpa_printf(MSG_DEBUG, "P2P: Removing P2P connection due to single channel concurrent mode frequency conflict");
7831 eloop_register_timeout(0, 0,
7832 wpas_p2p_group_freq_conflict,
7834 /* If connection in progress is P2P connection, do not
7835 * proceed for the connection. */
7841 /* P2P connection has priority, disable the STA network
7843 wpa_supplicant_disable_network(wpa_s->global->ifaces,
7845 wpa_msg(wpa_s->global->ifaces, MSG_INFO,
7846 WPA_EVENT_FREQ_CONFLICT " id=%d", ssid->id);
7847 os_memset(wpa_s->global->ifaces->pending_bssid, 0,
7849 /* If P2P connection is in progress, continue
7862 int wpas_p2p_4way_hs_failed(struct wpa_supplicant *wpa_s)
7864 struct wpa_ssid *ssid = wpa_s->current_ssid;
7866 if (ssid == NULL || !ssid->p2p_group)
7869 if (wpa_s->p2p_last_4way_hs_fail &&
7870 wpa_s->p2p_last_4way_hs_fail == ssid) {
7871 u8 go_dev_addr[ETH_ALEN];
7872 struct wpa_ssid *persistent;
7874 if (wpas_p2p_persistent_group(wpa_s, go_dev_addr,
7876 ssid->ssid_len) <= 0) {
7877 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Could not determine whether 4-way handshake failures were for a persistent group");
7881 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Two 4-way handshake failures for a P2P group - go_dev_addr="
7882 MACSTR, MAC2STR(go_dev_addr));
7883 persistent = wpas_p2p_get_persistent(wpa_s->parent, go_dev_addr,
7886 if (persistent == NULL || persistent->mode != WPAS_MODE_INFRA) {
7887 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: No matching persistent group stored");
7890 wpa_msg_global(wpa_s->parent, MSG_INFO,
7891 P2P_EVENT_PERSISTENT_PSK_FAIL "%d",
7894 wpa_s->p2p_last_4way_hs_fail = NULL;
7896 * Remove the group from a timeout to avoid issues with caller
7897 * continuing to use the interface if this is on a P2P group
7900 eloop_register_timeout(0, 0, wpas_p2p_psk_failure_removal,
7905 wpa_s->p2p_last_4way_hs_fail = ssid;
7910 #ifdef CONFIG_WPS_NFC
7912 static struct wpabuf * wpas_p2p_nfc_handover(int ndef, struct wpabuf *wsc,
7920 wpa_printf(MSG_DEBUG, "P2P: No p2p buffer for handover");
7924 wsc_len = wsc ? wpabuf_len(wsc) : 0;
7925 ret = wpabuf_alloc(2 + wsc_len + 2 + wpabuf_len(p2p));
7932 wpabuf_put_be16(ret, wsc_len);
7934 wpabuf_put_buf(ret, wsc);
7935 wpabuf_put_be16(ret, wpabuf_len(p2p));
7936 wpabuf_put_buf(ret, p2p);
7940 wpa_hexdump_buf(MSG_DEBUG,
7941 "P2P: Generated NFC connection handover message", ret);
7945 tmp = ndef_build_p2p(ret);
7948 wpa_printf(MSG_DEBUG, "P2P: Failed to NDEF encapsulate handover request");
7958 static int wpas_p2p_cli_freq(struct wpa_supplicant *wpa_s,
7959 struct wpa_ssid **ssid, u8 *go_dev_addr)
7961 struct wpa_supplicant *iface;
7964 os_memset(go_dev_addr, 0, ETH_ALEN);
7967 for (iface = wpa_s->global->ifaces; iface; iface = iface->next) {
7968 if (iface->wpa_state < WPA_ASSOCIATING ||
7969 iface->current_ssid == NULL || iface->assoc_freq == 0 ||
7970 !iface->current_ssid->p2p_group ||
7971 iface->current_ssid->mode != WPAS_MODE_INFRA)
7974 *ssid = iface->current_ssid;
7976 os_memcpy(go_dev_addr, iface->go_dev_addr, ETH_ALEN);
7977 return iface->assoc_freq;
7983 struct wpabuf * wpas_p2p_nfc_handover_req(struct wpa_supplicant *wpa_s,
7986 struct wpabuf *wsc, *p2p;
7987 struct wpa_ssid *ssid;
7988 u8 go_dev_addr[ETH_ALEN];
7989 int cli_freq = wpas_p2p_cli_freq(wpa_s, &ssid, go_dev_addr);
7991 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL) {
7992 wpa_printf(MSG_DEBUG, "P2P: P2P disabled - cannot build handover request");
7996 if (wpa_s->conf->wps_nfc_dh_pubkey == NULL &&
7997 wps_nfc_gen_dh(&wpa_s->conf->wps_nfc_dh_pubkey,
7998 &wpa_s->conf->wps_nfc_dh_privkey) < 0) {
7999 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: No DH key available for handover request");
8003 if (cli_freq == 0) {
8004 wsc = wps_build_nfc_handover_req_p2p(
8005 wpa_s->parent->wps, wpa_s->conf->wps_nfc_dh_pubkey);
8008 p2p = p2p_build_nfc_handover_req(wpa_s->global->p2p, cli_freq,
8009 go_dev_addr, ssid ? ssid->ssid : NULL,
8010 ssid ? ssid->ssid_len : 0);
8012 return wpas_p2p_nfc_handover(ndef, wsc, p2p);
8016 struct wpabuf * wpas_p2p_nfc_handover_sel(struct wpa_supplicant *wpa_s,
8019 struct wpabuf *wsc, *p2p;
8020 struct wpa_ssid *ssid;
8021 u8 go_dev_addr[ETH_ALEN];
8022 int cli_freq = wpas_p2p_cli_freq(wpa_s, &ssid, go_dev_addr);
8024 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
8027 if (!tag && wpa_s->conf->wps_nfc_dh_pubkey == NULL &&
8028 wps_nfc_gen_dh(&wpa_s->conf->wps_nfc_dh_pubkey,
8029 &wpa_s->conf->wps_nfc_dh_privkey) < 0)
8032 if (cli_freq == 0) {
8033 wsc = wps_build_nfc_handover_sel_p2p(
8035 tag ? wpa_s->conf->wps_nfc_dev_pw_id :
8036 DEV_PW_NFC_CONNECTION_HANDOVER,
8037 wpa_s->conf->wps_nfc_dh_pubkey,
8038 tag ? wpa_s->conf->wps_nfc_dev_pw : NULL);
8041 p2p = p2p_build_nfc_handover_sel(wpa_s->global->p2p, cli_freq,
8042 go_dev_addr, ssid ? ssid->ssid : NULL,
8043 ssid ? ssid->ssid_len : 0);
8045 return wpas_p2p_nfc_handover(ndef, wsc, p2p);
8049 static int wpas_p2p_nfc_join_group(struct wpa_supplicant *wpa_s,
8050 struct p2p_nfc_params *params)
8052 wpa_printf(MSG_DEBUG, "P2P: Initiate join-group based on NFC "
8053 "connection handover (freq=%d)",
8056 if (params->go_freq && params->go_ssid_len) {
8057 wpa_s->p2p_wps_method = WPS_NFC;
8058 wpa_s->pending_join_wps_method = WPS_NFC;
8059 os_memset(wpa_s->pending_join_iface_addr, 0, ETH_ALEN);
8060 os_memcpy(wpa_s->pending_join_dev_addr, params->go_dev_addr,
8062 return wpas_p2p_join_start(wpa_s, params->go_freq,
8064 params->go_ssid_len);
8067 return wpas_p2p_connect(wpa_s, params->peer->p2p_device_addr, NULL,
8068 WPS_NFC, 0, 0, 1, 0, wpa_s->conf->p2p_go_intent,
8069 params->go_freq, -1, 0, 1, 1);
8073 static int wpas_p2p_nfc_auth_join(struct wpa_supplicant *wpa_s,
8074 struct p2p_nfc_params *params, int tag)
8076 int res, persistent;
8077 struct wpa_ssid *ssid;
8079 wpa_printf(MSG_DEBUG, "P2P: Authorize join-group based on NFC "
8080 "connection handover");
8081 for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) {
8082 ssid = wpa_s->current_ssid;
8085 if (ssid->mode != WPAS_MODE_P2P_GO)
8087 if (wpa_s->ap_iface == NULL)
8091 if (wpa_s == NULL) {
8092 wpa_printf(MSG_DEBUG, "P2P: Could not find GO interface");
8096 if (wpa_s->parent->p2p_oob_dev_pw_id !=
8097 DEV_PW_NFC_CONNECTION_HANDOVER &&
8098 !wpa_s->parent->p2p_oob_dev_pw) {
8099 wpa_printf(MSG_DEBUG, "P2P: No NFC Dev Pw known");
8102 res = wpas_ap_wps_add_nfc_pw(
8103 wpa_s, wpa_s->parent->p2p_oob_dev_pw_id,
8104 wpa_s->parent->p2p_oob_dev_pw,
8105 wpa_s->parent->p2p_peer_oob_pk_hash_known ?
8106 wpa_s->parent->p2p_peer_oob_pubkey_hash : NULL);
8111 wpa_printf(MSG_DEBUG, "P2P: Negotiated handover - wait for peer to join without invitation");
8115 if (!params->peer ||
8116 !(params->peer->dev_capab & P2P_DEV_CAPAB_INVITATION_PROCEDURE))
8119 wpa_printf(MSG_DEBUG, "P2P: Static handover - invite peer " MACSTR
8120 " to join", MAC2STR(params->peer->p2p_device_addr));
8122 wpa_s->global->p2p_invite_group = wpa_s;
8123 persistent = ssid->p2p_persistent_group &&
8124 wpas_p2p_get_persistent(wpa_s->parent,
8125 params->peer->p2p_device_addr,
8126 ssid->ssid, ssid->ssid_len);
8127 wpa_s->parent->pending_invite_ssid_id = -1;
8129 return p2p_invite(wpa_s->global->p2p, params->peer->p2p_device_addr,
8130 P2P_INVITE_ROLE_ACTIVE_GO, wpa_s->own_addr,
8131 ssid->ssid, ssid->ssid_len, ssid->frequency,
8132 wpa_s->global->p2p_dev_addr, persistent, 0,
8133 wpa_s->parent->p2p_oob_dev_pw_id);
8137 static int wpas_p2p_nfc_init_go_neg(struct wpa_supplicant *wpa_s,
8138 struct p2p_nfc_params *params,
8141 wpa_printf(MSG_DEBUG, "P2P: Initiate GO Negotiation based on NFC "
8142 "connection handover");
8143 return wpas_p2p_connect(wpa_s, params->peer->p2p_device_addr, NULL,
8144 WPS_NFC, 0, 0, 0, 0, wpa_s->conf->p2p_go_intent,
8145 forced_freq, -1, 0, 1, 1);
8149 static int wpas_p2p_nfc_resp_go_neg(struct wpa_supplicant *wpa_s,
8150 struct p2p_nfc_params *params,
8155 wpa_printf(MSG_DEBUG, "P2P: Authorize GO Negotiation based on NFC "
8156 "connection handover");
8157 res = wpas_p2p_connect(wpa_s, params->peer->p2p_device_addr, NULL,
8158 WPS_NFC, 0, 0, 0, 1, wpa_s->conf->p2p_go_intent,
8159 forced_freq, -1, 0, 1, 1);
8163 res = wpas_p2p_listen(wpa_s, 60);
8165 p2p_unauthorize(wpa_s->global->p2p,
8166 params->peer->p2p_device_addr);
8173 static int wpas_p2p_nfc_connection_handover(struct wpa_supplicant *wpa_s,
8174 const struct wpabuf *data,
8175 int sel, int tag, int forced_freq)
8177 const u8 *pos, *end;
8179 struct p2p_nfc_params params;
8182 os_memset(¶ms, 0, sizeof(params));
8185 wpa_hexdump_buf(MSG_DEBUG, "P2P: Received NFC tag payload", data);
8187 pos = wpabuf_head(data);
8188 end = pos + wpabuf_len(data);
8190 if (end - pos < 2) {
8191 wpa_printf(MSG_DEBUG, "P2P: Not enough data for Length of WSC "
8195 len = WPA_GET_BE16(pos);
8197 if (len > end - pos) {
8198 wpa_printf(MSG_DEBUG, "P2P: Not enough data for WSC "
8202 params.wsc_attr = pos;
8203 params.wsc_len = len;
8206 if (end - pos < 2) {
8207 wpa_printf(MSG_DEBUG, "P2P: Not enough data for Length of P2P "
8211 len = WPA_GET_BE16(pos);
8213 if (len > end - pos) {
8214 wpa_printf(MSG_DEBUG, "P2P: Not enough data for P2P "
8218 params.p2p_attr = pos;
8219 params.p2p_len = len;
8222 wpa_hexdump(MSG_DEBUG, "P2P: WSC attributes",
8223 params.wsc_attr, params.wsc_len);
8224 wpa_hexdump(MSG_DEBUG, "P2P: P2P attributes",
8225 params.p2p_attr, params.p2p_len);
8227 wpa_hexdump(MSG_DEBUG,
8228 "P2P: Ignored extra data after P2P attributes",
8232 res = p2p_process_nfc_connection_handover(wpa_s->global->p2p, ¶ms);
8236 if (params.next_step == NO_ACTION)
8239 if (params.next_step == BOTH_GO) {
8240 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_NFC_BOTH_GO "peer=" MACSTR,
8241 MAC2STR(params.peer->p2p_device_addr));
8245 if (params.next_step == PEER_CLIENT) {
8246 if (!is_zero_ether_addr(params.go_dev_addr)) {
8247 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_NFC_PEER_CLIENT
8248 "peer=" MACSTR " freq=%d go_dev_addr=" MACSTR
8250 MAC2STR(params.peer->p2p_device_addr),
8252 MAC2STR(params.go_dev_addr),
8253 wpa_ssid_txt(params.go_ssid,
8254 params.go_ssid_len));
8256 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_NFC_PEER_CLIENT
8257 "peer=" MACSTR " freq=%d",
8258 MAC2STR(params.peer->p2p_device_addr),
8264 if (wpas_p2p_cli_freq(wpa_s, NULL, NULL)) {
8265 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_NFC_WHILE_CLIENT "peer="
8266 MACSTR, MAC2STR(params.peer->p2p_device_addr));
8270 wpabuf_free(wpa_s->p2p_oob_dev_pw);
8271 wpa_s->p2p_oob_dev_pw = NULL;
8273 if (params.oob_dev_pw_len < WPS_OOB_PUBKEY_HASH_LEN + 2) {
8274 wpa_printf(MSG_DEBUG, "P2P: No peer OOB Dev Pw "
8279 id = WPA_GET_BE16(params.oob_dev_pw + WPS_OOB_PUBKEY_HASH_LEN);
8280 wpa_printf(MSG_DEBUG, "P2P: Peer OOB Dev Pw %u", id);
8281 wpa_hexdump(MSG_DEBUG, "P2P: Peer OOB Public Key hash",
8282 params.oob_dev_pw, WPS_OOB_PUBKEY_HASH_LEN);
8283 os_memcpy(wpa_s->p2p_peer_oob_pubkey_hash,
8284 params.oob_dev_pw, WPS_OOB_PUBKEY_HASH_LEN);
8285 wpa_s->p2p_peer_oob_pk_hash_known = 1;
8289 wpa_printf(MSG_DEBUG, "P2P: Static handover - invalid "
8290 "peer OOB Device Password Id %u", id);
8293 wpa_printf(MSG_DEBUG, "P2P: Static handover - use peer OOB "
8294 "Device Password Id %u", id);
8295 wpa_hexdump_key(MSG_DEBUG, "P2P: Peer OOB Device Password",
8296 params.oob_dev_pw + WPS_OOB_PUBKEY_HASH_LEN + 2,
8297 params.oob_dev_pw_len -
8298 WPS_OOB_PUBKEY_HASH_LEN - 2);
8299 wpa_s->p2p_oob_dev_pw_id = id;
8300 wpa_s->p2p_oob_dev_pw = wpabuf_alloc_copy(
8301 params.oob_dev_pw + WPS_OOB_PUBKEY_HASH_LEN + 2,
8302 params.oob_dev_pw_len -
8303 WPS_OOB_PUBKEY_HASH_LEN - 2);
8304 if (wpa_s->p2p_oob_dev_pw == NULL)
8307 if (wpa_s->conf->wps_nfc_dh_pubkey == NULL &&
8308 wps_nfc_gen_dh(&wpa_s->conf->wps_nfc_dh_pubkey,
8309 &wpa_s->conf->wps_nfc_dh_privkey) < 0)
8312 wpa_printf(MSG_DEBUG, "P2P: Using abbreviated WPS handshake "
8313 "without Device Password");
8314 wpa_s->p2p_oob_dev_pw_id = DEV_PW_NFC_CONNECTION_HANDOVER;
8317 switch (params.next_step) {
8321 /* already covered above */
8324 return wpas_p2p_nfc_join_group(wpa_s, ¶ms);
8326 return wpas_p2p_nfc_auth_join(wpa_s, ¶ms, tag);
8328 return wpas_p2p_nfc_init_go_neg(wpa_s, ¶ms, forced_freq);
8330 /* TODO: use own OOB Dev Pw */
8331 return wpas_p2p_nfc_resp_go_neg(wpa_s, ¶ms, forced_freq);
8338 int wpas_p2p_nfc_tag_process(struct wpa_supplicant *wpa_s,
8339 const struct wpabuf *data, int forced_freq)
8341 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
8344 return wpas_p2p_nfc_connection_handover(wpa_s, data, 1, 1, forced_freq);
8348 int wpas_p2p_nfc_report_handover(struct wpa_supplicant *wpa_s, int init,
8349 const struct wpabuf *req,
8350 const struct wpabuf *sel, int forced_freq)
8355 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
8358 wpa_printf(MSG_DEBUG, "NFC: P2P connection handover reported");
8360 wpa_hexdump_ascii(MSG_DEBUG, "NFC: Req",
8361 wpabuf_head(req), wpabuf_len(req));
8362 wpa_hexdump_ascii(MSG_DEBUG, "NFC: Sel",
8363 wpabuf_head(sel), wpabuf_len(sel));
8365 wpa_printf(MSG_DEBUG, "NFC: Forced freq %d", forced_freq);
8366 tmp = ndef_parse_p2p(init ? sel : req);
8368 wpa_printf(MSG_DEBUG, "P2P: Could not parse NDEF");
8372 ret = wpas_p2p_nfc_connection_handover(wpa_s, tmp, init, 0,
8380 int wpas_p2p_nfc_tag_enabled(struct wpa_supplicant *wpa_s, int enabled)
8383 int go_intent = wpa_s->conf->p2p_go_intent;
8384 struct wpa_supplicant *iface;
8386 if (wpa_s->global->p2p == NULL)
8390 wpa_printf(MSG_DEBUG, "P2P: Disable use of own NFC Tag");
8391 for (iface = wpa_s->global->ifaces; iface; iface = iface->next)
8393 if (!iface->ap_iface)
8395 hostapd_wps_nfc_token_disable(iface->ap_iface->bss[0]);
8397 p2p_set_authorized_oob_dev_pw_id(wpa_s->global->p2p, 0,
8399 if (wpa_s->p2p_nfc_tag_enabled)
8400 wpas_p2p_remove_pending_group_interface(wpa_s);
8401 wpa_s->p2p_nfc_tag_enabled = 0;
8405 if (wpa_s->global->p2p_disabled)
8408 if (wpa_s->conf->wps_nfc_dh_pubkey == NULL ||
8409 wpa_s->conf->wps_nfc_dh_privkey == NULL ||
8410 wpa_s->conf->wps_nfc_dev_pw == NULL ||
8411 wpa_s->conf->wps_nfc_dev_pw_id < 0x10) {
8412 wpa_printf(MSG_DEBUG, "P2P: NFC password token not configured "
8413 "to allow static handover cases");
8417 wpa_printf(MSG_DEBUG, "P2P: Enable use of own NFC Tag");
8419 wpa_s->p2p_oob_dev_pw_id = wpa_s->conf->wps_nfc_dev_pw_id;
8420 wpabuf_free(wpa_s->p2p_oob_dev_pw);
8421 wpa_s->p2p_oob_dev_pw = wpabuf_dup(wpa_s->conf->wps_nfc_dev_pw);
8422 if (wpa_s->p2p_oob_dev_pw == NULL)
8424 wpa_s->p2p_peer_oob_pk_hash_known = 0;
8426 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO ||
8427 wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT) {
8429 * P2P Group Interface present and the command came on group
8430 * interface, so enable the token for the current interface.
8432 wpa_s->create_p2p_iface = 0;
8434 wpa_s->create_p2p_iface = wpas_p2p_create_iface(wpa_s);
8437 if (wpa_s->create_p2p_iface) {
8438 enum wpa_driver_if_type iftype;
8439 /* Prepare to add a new interface for the group */
8440 iftype = WPA_IF_P2P_GROUP;
8441 if (go_intent == 15)
8442 iftype = WPA_IF_P2P_GO;
8443 if (wpas_p2p_add_group_interface(wpa_s, iftype) < 0) {
8444 wpa_printf(MSG_ERROR, "P2P: Failed to allocate a new "
8445 "interface for the group");
8449 if_addr = wpa_s->pending_interface_addr;
8451 if_addr = wpa_s->own_addr;
8453 wpa_s->p2p_nfc_tag_enabled = enabled;
8455 for (iface = wpa_s->global->ifaces; iface; iface = iface->next) {
8456 struct hostapd_data *hapd;
8457 if (iface->ap_iface == NULL)
8459 hapd = iface->ap_iface->bss[0];
8460 wpabuf_free(hapd->conf->wps_nfc_dh_pubkey);
8461 hapd->conf->wps_nfc_dh_pubkey =
8462 wpabuf_dup(wpa_s->conf->wps_nfc_dh_pubkey);
8463 wpabuf_free(hapd->conf->wps_nfc_dh_privkey);
8464 hapd->conf->wps_nfc_dh_privkey =
8465 wpabuf_dup(wpa_s->conf->wps_nfc_dh_privkey);
8466 wpabuf_free(hapd->conf->wps_nfc_dev_pw);
8467 hapd->conf->wps_nfc_dev_pw =
8468 wpabuf_dup(wpa_s->conf->wps_nfc_dev_pw);
8469 hapd->conf->wps_nfc_dev_pw_id = wpa_s->conf->wps_nfc_dev_pw_id;
8471 if (hostapd_wps_nfc_token_enable(iface->ap_iface->bss[0]) < 0) {
8472 wpa_dbg(iface, MSG_DEBUG,
8473 "P2P: Failed to enable NFC Tag for GO");
8476 p2p_set_authorized_oob_dev_pw_id(
8477 wpa_s->global->p2p, wpa_s->conf->wps_nfc_dev_pw_id, go_intent,
8483 #endif /* CONFIG_WPS_NFC */
8486 static void wpas_p2p_optimize_listen_channel(struct wpa_supplicant *wpa_s,
8487 struct wpa_used_freq_data *freqs,
8490 u8 curr_chan, cand, chan;
8494 * If possible, optimize the Listen channel to be a channel that is
8495 * already used by one of the other interfaces.
8497 if (!wpa_s->conf->p2p_optimize_listen_chan)
8500 if (!wpa_s->current_ssid || wpa_s->wpa_state != WPA_COMPLETED)
8503 curr_chan = p2p_get_listen_channel(wpa_s->global->p2p);
8504 for (i = 0, cand = 0; i < num; i++) {
8505 ieee80211_freq_to_chan(freqs[i].freq, &chan);
8506 if (curr_chan == chan) {
8511 if (chan == 1 || chan == 6 || chan == 11)
8516 wpa_dbg(wpa_s, MSG_DEBUG,
8517 "P2P: Update Listen channel to %u based on operating channel",
8519 p2p_set_listen_channel(wpa_s->global->p2p, 81, cand, 0);
8524 static int wpas_p2p_move_go_csa(struct wpa_supplicant *wpa_s)
8526 struct hostapd_config *conf;
8527 struct p2p_go_neg_results params;
8528 struct csa_settings csa_settings;
8529 struct wpa_ssid *current_ssid = wpa_s->current_ssid;
8530 int old_freq = current_ssid->frequency;
8534 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP_CSA)) {
8535 wpa_dbg(wpa_s, MSG_DEBUG, "CSA is not enabled");
8540 * TODO: This function may not always work correctly. For example,
8541 * when we have a running GO and a BSS on a DFS channel.
8543 if (wpas_p2p_init_go_params(wpa_s, ¶ms, 0, 0, 0, NULL)) {
8544 wpa_dbg(wpa_s, MSG_DEBUG,
8545 "P2P CSA: Failed to select new frequency for GO");
8549 if (current_ssid->frequency == params.freq) {
8550 wpa_dbg(wpa_s, MSG_DEBUG,
8551 "P2P CSA: Selected same frequency - not moving GO");
8555 conf = hostapd_config_defaults();
8557 wpa_dbg(wpa_s, MSG_DEBUG,
8558 "P2P CSA: Failed to allocate default config");
8562 current_ssid->frequency = params.freq;
8563 if (wpa_supplicant_conf_ap_ht(wpa_s, current_ssid, conf)) {
8564 wpa_dbg(wpa_s, MSG_DEBUG,
8565 "P2P CSA: Failed to create new GO config");
8570 if (conf->hw_mode != wpa_s->ap_iface->current_mode->mode) {
8571 wpa_dbg(wpa_s, MSG_DEBUG,
8572 "P2P CSA: CSA to a different band is not supported");
8577 os_memset(&csa_settings, 0, sizeof(csa_settings));
8578 csa_settings.cs_count = P2P_GO_CSA_COUNT;
8579 csa_settings.block_tx = P2P_GO_CSA_BLOCK_TX;
8580 csa_settings.freq_params.freq = params.freq;
8582 if (ieee80211_freq_to_channel_ext(params.freq, conf->secondary_channel,
8584 &wpa_s->ap_iface->cs_oper_class,
8585 &chan) == NUM_HOSTAPD_MODES) {
8586 wpa_dbg(wpa_s, MSG_DEBUG,
8587 "P2P CSA: Selected invalid frequency");
8592 csa_settings.freq_params.channel = chan;
8593 csa_settings.freq_params.sec_channel_offset = conf->secondary_channel;
8594 csa_settings.freq_params.ht_enabled = conf->ieee80211n;
8595 csa_settings.freq_params.bandwidth = conf->secondary_channel ? 40 : 20;
8597 if (conf->ieee80211ac) {
8598 int freq1 = 0, freq2 = 0;
8600 if (conf->vht_oper_centr_freq_seg0_idx)
8601 freq1 = ieee80211_chan_to_freq(
8602 NULL, wpa_s->ap_iface->cs_oper_class,
8603 conf->vht_oper_centr_freq_seg0_idx);
8605 if (conf->vht_oper_centr_freq_seg1_idx)
8606 freq2 = ieee80211_chan_to_freq(
8607 NULL, wpa_s->ap_iface->cs_oper_class,
8608 conf->vht_oper_centr_freq_seg1_idx);
8610 if (freq1 < 0 || freq2 < 0) {
8611 wpa_dbg(wpa_s, MSG_DEBUG,
8612 "P2P CSA: Selected invalid VHT center freqs");
8617 csa_settings.freq_params.vht_enabled = conf->ieee80211ac;
8618 csa_settings.freq_params.center_freq1 = freq1;
8619 csa_settings.freq_params.center_freq2 = freq2;
8621 switch (conf->vht_oper_chwidth) {
8622 case VHT_CHANWIDTH_80MHZ:
8623 case VHT_CHANWIDTH_80P80MHZ:
8624 csa_settings.freq_params.bandwidth = 80;
8626 case VHT_CHANWIDTH_160MHZ:
8627 csa_settings.freq_params.bandwidth = 160;
8632 ret = ap_switch_channel(wpa_s, &csa_settings);
8634 current_ssid->frequency = old_freq;
8635 hostapd_config_free(conf);
8640 static void wpas_p2p_move_go_no_csa(struct wpa_supplicant *wpa_s)
8642 struct p2p_go_neg_results params;
8643 struct wpa_ssid *current_ssid = wpa_s->current_ssid;
8645 wpa_msg_global(wpa_s, MSG_INFO, P2P_EVENT_REMOVE_AND_REFORM_GROUP);
8647 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Move GO from freq=%d MHz",
8648 current_ssid->frequency);
8650 /* Stop the AP functionality */
8651 /* TODO: Should do this in a way that does not indicated to possible
8652 * P2P Clients in the group that the group is terminated. */
8653 wpa_supplicant_ap_deinit(wpa_s);
8655 /* Reselect the GO frequency */
8656 if (wpas_p2p_init_go_params(wpa_s, ¶ms, 0, 0, 0, NULL)) {
8657 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Failed to reselect freq");
8658 wpas_p2p_group_delete(wpa_s,
8659 P2P_GROUP_REMOVAL_GO_LEAVE_CHANNEL);
8662 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: New freq selected for the GO (%u MHz)",
8666 !p2p_supported_freq_go(wpa_s->global->p2p, params.freq)) {
8667 wpa_printf(MSG_DEBUG,
8668 "P2P: Selected freq (%u MHz) is not valid for P2P",
8670 wpas_p2p_group_delete(wpa_s,
8671 P2P_GROUP_REMOVAL_GO_LEAVE_CHANNEL);
8675 /* Update the frequency */
8676 current_ssid->frequency = params.freq;
8677 wpa_s->connect_without_scan = current_ssid;
8678 wpa_s->reassociate = 1;
8679 wpa_s->disconnected = 0;
8680 wpa_supplicant_req_scan(wpa_s, 0, 0);
8684 static void wpas_p2p_move_go(void *eloop_ctx, void *timeout_ctx)
8686 struct wpa_supplicant *wpa_s = eloop_ctx;
8688 if (!wpa_s->ap_iface || !wpa_s->current_ssid)
8691 wpas_p2p_go_update_common_freqs(wpa_s);
8693 /* Do not move GO in the middle of a CSA */
8694 if (hostapd_csa_in_progress(wpa_s->ap_iface)) {
8695 wpa_printf(MSG_DEBUG,
8696 "P2P: CSA is in progress - not moving GO");
8701 * First, try a channel switch flow. If it is not supported or fails,
8702 * take down the GO and bring it up again.
8704 if (wpas_p2p_move_go_csa(wpa_s) < 0)
8705 wpas_p2p_move_go_no_csa(wpa_s);
8709 static void wpas_p2p_reconsider_moving_go(void *eloop_ctx, void *timeout_ctx)
8711 struct wpa_supplicant *wpa_s = eloop_ctx;
8712 struct wpa_used_freq_data *freqs = NULL;
8713 unsigned int num = wpa_s->num_multichan_concurrent;
8715 freqs = os_calloc(num, sizeof(struct wpa_used_freq_data));
8719 num = get_shared_radio_freqs_data(wpa_s, freqs, num);
8721 /* Previous attempt to move a GO was not possible -- try again. */
8722 wpas_p2p_consider_moving_gos(wpa_s, freqs, num,
8723 WPAS_P2P_CHANNEL_UPDATE_ANY);
8730 * Consider moving a GO from its currently used frequency:
8731 * 1. It is possible that due to regulatory consideration the frequency
8732 * can no longer be used and there is a need to evacuate the GO.
8733 * 2. It is possible that due to MCC considerations, it would be preferable
8734 * to move the GO to a channel that is currently used by some other
8735 * station interface.
8737 * In case a frequency that became invalid is once again valid, cancel a
8738 * previously initiated GO frequency change.
8740 static void wpas_p2p_consider_moving_one_go(struct wpa_supplicant *wpa_s,
8741 struct wpa_used_freq_data *freqs,
8744 unsigned int i, invalid_freq = 0, policy_move = 0, flags = 0;
8745 unsigned int timeout;
8748 wpas_p2p_go_update_common_freqs(wpa_s);
8750 freq = wpa_s->current_ssid->frequency;
8751 for (i = 0, invalid_freq = 0; i < num; i++) {
8752 if (freqs[i].freq == freq) {
8753 flags = freqs[i].flags;
8755 /* The channel is invalid, must change it */
8756 if (!p2p_supported_freq_go(wpa_s->global->p2p, freq)) {
8757 wpa_dbg(wpa_s, MSG_DEBUG,
8758 "P2P: Freq=%d MHz no longer valid for GO",
8762 } else if (freqs[i].flags == 0) {
8763 /* Freq is not used by any other station interface */
8765 } else if (!p2p_supported_freq(wpa_s->global->p2p,
8767 /* Freq is not valid for P2P use cases */
8769 } else if (wpa_s->conf->p2p_go_freq_change_policy ==
8770 P2P_GO_FREQ_MOVE_SCM) {
8772 } else if (wpa_s->conf->p2p_go_freq_change_policy ==
8773 P2P_GO_FREQ_MOVE_SCM_PEER_SUPPORTS &&
8774 wpas_p2p_go_is_peer_freq(wpa_s, freqs[i].freq)) {
8776 } else if ((wpa_s->conf->p2p_go_freq_change_policy ==
8777 P2P_GO_FREQ_MOVE_SCM_ECSA) &&
8778 wpas_p2p_go_is_peer_freq(wpa_s, freqs[i].freq)) {
8779 if (!p2p_get_group_num_members(wpa_s->p2p_group)) {
8781 } else if ((wpa_s->drv_flags &
8782 WPA_DRIVER_FLAGS_AP_CSA) &&
8783 wpas_p2p_go_clients_support_ecsa(wpa_s)) {
8787 * We do not support CSA between bands, so move
8788 * GO only within the same band.
8790 if (wpa_s->ap_iface->current_mode->mode ==
8791 ieee80211_freq_to_chan(freqs[i].freq,
8798 wpa_dbg(wpa_s, MSG_DEBUG,
8799 "P2P: GO move: invalid_freq=%u, policy_move=%u, flags=0x%X",
8800 invalid_freq, policy_move, flags);
8803 * The channel is valid, or we are going to have a policy move, so
8806 if (!invalid_freq || policy_move) {
8807 wpa_dbg(wpa_s, MSG_DEBUG,
8808 "P2P: Cancel a GO move from freq=%d MHz", freq);
8809 eloop_cancel_timeout(wpas_p2p_move_go, wpa_s, NULL);
8811 if (wpas_p2p_in_progress(wpa_s)) {
8812 wpa_dbg(wpa_s, MSG_DEBUG,
8813 "P2P: GO move: policy CS is not allowed - setting timeout to re-consider GO move");
8814 eloop_cancel_timeout(wpas_p2p_reconsider_moving_go,
8816 eloop_register_timeout(P2P_RECONSIDER_GO_MOVE_DELAY, 0,
8817 wpas_p2p_reconsider_moving_go,
8823 if (!invalid_freq && (!policy_move || flags != 0)) {
8824 wpa_dbg(wpa_s, MSG_DEBUG,
8825 "P2P: Not initiating a GO frequency change");
8830 * Do not consider moving GO if it is in the middle of a CSA. When the
8831 * CSA is finished this flow should be retriggered.
8833 if (hostapd_csa_in_progress(wpa_s->ap_iface)) {
8834 wpa_dbg(wpa_s, MSG_DEBUG,
8835 "P2P: Not initiating a GO frequency change - CSA is in progress");
8839 if (invalid_freq && !wpas_p2p_disallowed_freq(wpa_s->global, freq))
8840 timeout = P2P_GO_FREQ_CHANGE_TIME;
8844 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Move GO from freq=%d MHz in %d secs",
8846 eloop_cancel_timeout(wpas_p2p_move_go, wpa_s, NULL);
8847 eloop_register_timeout(timeout, 0, wpas_p2p_move_go, wpa_s, NULL);
8851 static void wpas_p2p_consider_moving_gos(struct wpa_supplicant *wpa_s,
8852 struct wpa_used_freq_data *freqs,
8854 enum wpas_p2p_channel_update_trig trig)
8856 struct wpa_supplicant *ifs;
8858 eloop_cancel_timeout(wpas_p2p_reconsider_moving_go, ELOOP_ALL_CTX,
8862 * Travers all the radio interfaces, and for each GO interface, check
8863 * if there is a need to move the GO from the frequency it is using,
8864 * or in case the frequency is valid again, cancel the evacuation flow.
8866 dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant,
8868 if (ifs->current_ssid == NULL ||
8869 ifs->current_ssid->mode != WPAS_MODE_P2P_GO)
8873 * The GO was just started or completed channel switch, no need
8877 (trig == WPAS_P2P_CHANNEL_UPDATE_STATE_CHANGE ||
8878 trig == WPAS_P2P_CHANNEL_UPDATE_CS)) {
8879 wpa_dbg(wpa_s, MSG_DEBUG,
8880 "P2P: GO move - schedule re-consideration");
8881 eloop_register_timeout(P2P_RECONSIDER_GO_MOVE_DELAY, 0,
8882 wpas_p2p_reconsider_moving_go,
8887 wpas_p2p_consider_moving_one_go(ifs, freqs, num);
8892 void wpas_p2p_indicate_state_change(struct wpa_supplicant *wpa_s)
8894 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
8897 wpas_p2p_update_channel_list(wpa_s,
8898 WPAS_P2P_CHANNEL_UPDATE_STATE_CHANGE);
8902 void wpas_p2p_deinit_iface(struct wpa_supplicant *wpa_s)
8904 if (wpa_s == wpa_s->global->p2p_init_wpa_s && wpa_s->global->p2p) {
8905 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Disable P2P since removing "
8906 "the management interface is being removed");
8907 wpas_p2p_deinit_global(wpa_s->global);
8912 void wpas_p2p_ap_deinit(struct wpa_supplicant *wpa_s)
8914 if (wpa_s->ap_iface->bss)
8915 wpa_s->ap_iface->bss[0]->p2p_group = NULL;
8916 wpas_p2p_group_deinit(wpa_s);