3 * Copyright (c) 2009-2010, Atheros Communications
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
13 #include "common/ieee802_11_common.h"
14 #include "common/ieee802_11_defs.h"
15 #include "common/wpa_ctrl.h"
16 #include "wps/wps_i.h"
18 #include "ap/hostapd.h"
19 #include "ap/ap_config.h"
20 #include "ap/p2p_hostapd.h"
21 #include "eapol_supp/eapol_supp_sm.h"
22 #include "rsn_supp/wpa.h"
23 #include "wpa_supplicant_i.h"
26 #include "config_ssid.h"
31 #include "offchannel.h"
32 #include "wps_supplicant.h"
33 #include "p2p_supplicant.h"
37 * How many times to try to scan to find the GO before giving up on join
40 #define P2P_MAX_JOIN_SCAN_ATTEMPTS 10
42 #define P2P_AUTO_PD_SCAN_ATTEMPTS 5
44 #ifndef P2P_MAX_CLIENT_IDLE
46 * How many seconds to try to reconnect to the GO when connection in P2P client
50 #define P2P_MAX_CLIENT_IDLE 20
52 #define P2P_MAX_CLIENT_IDLE 10
53 #endif /* ANDROID_P2P */
54 #endif /* P2P_MAX_CLIENT_IDLE */
56 #ifndef P2P_MAX_INITIAL_CONN_WAIT
58 * How many seconds to wait for initial 4-way handshake to get completed after
59 * WPS provisioning step.
61 #define P2P_MAX_INITIAL_CONN_WAIT 10
62 #endif /* P2P_MAX_INITIAL_CONN_WAIT */
64 #ifndef P2P_CONCURRENT_SEARCH_DELAY
65 #define P2P_CONCURRENT_SEARCH_DELAY 500
66 #endif /* P2P_CONCURRENT_SEARCH_DELAY */
68 enum p2p_group_removal_reason {
69 P2P_GROUP_REMOVAL_UNKNOWN,
70 P2P_GROUP_REMOVAL_SILENT,
71 P2P_GROUP_REMOVAL_FORMATION_FAILED,
72 P2P_GROUP_REMOVAL_REQUESTED,
73 P2P_GROUP_REMOVAL_IDLE_TIMEOUT,
74 P2P_GROUP_REMOVAL_UNAVAILABLE,
75 P2P_GROUP_REMOVAL_GO_ENDING_SESSION,
77 P2P_GROUP_REMOVAL_FREQ_CONFLICT
82 static void wpas_p2p_long_listen_timeout(void *eloop_ctx, void *timeout_ctx);
83 static struct wpa_supplicant *
84 wpas_p2p_get_group_iface(struct wpa_supplicant *wpa_s, int addr_allocated,
86 static int wpas_p2p_join_start(struct wpa_supplicant *wpa_s);
87 static void wpas_p2p_join_scan_req(struct wpa_supplicant *wpa_s, int freq);
88 static void wpas_p2p_join_scan(void *eloop_ctx, void *timeout_ctx);
89 static int wpas_p2p_join(struct wpa_supplicant *wpa_s, const u8 *iface_addr,
90 const u8 *dev_addr, enum p2p_wps_method wps_method,
92 static void wpas_p2p_pd_before_join_timeout(void *eloop_ctx,
94 static int wpas_p2p_create_iface(struct wpa_supplicant *wpa_s);
95 static void wpas_p2p_cross_connect_setup(struct wpa_supplicant *wpa_s);
96 static void wpas_p2p_group_idle_timeout(void *eloop_ctx, void *timeout_ctx);
97 static void wpas_p2p_set_group_idle_timeout(struct wpa_supplicant *wpa_s);
98 static void wpas_p2p_fallback_to_go_neg(struct wpa_supplicant *wpa_s,
102 static void wpas_p2p_scan_res_handler(struct wpa_supplicant *wpa_s,
103 struct wpa_scan_results *scan_res)
107 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
110 wpa_printf(MSG_DEBUG, "P2P: Scan results received (%d BSS)",
111 (int) scan_res->num);
113 for (i = 0; i < scan_res->num; i++) {
114 struct wpa_scan_res *bss = scan_res->res[i];
115 if (p2p_scan_res_handler(wpa_s->global->p2p, bss->bssid,
116 bss->freq, bss->level,
117 (const u8 *) (bss + 1),
122 p2p_scan_res_handled(wpa_s->global->p2p);
126 static int wpas_p2p_scan(void *ctx, enum p2p_scan_type type, int freq,
127 unsigned int num_req_dev_types,
128 const u8 *req_dev_types, const u8 *dev_id, u16 pw_id)
130 struct wpa_supplicant *wpa_s = ctx;
131 struct wpa_supplicant *ifs;
132 struct wpa_driver_scan_params params;
134 struct wpabuf *wps_ie, *ies;
135 int social_channels[] = { 2412, 2437, 2462, 0, 0 };
138 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
141 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
142 if (ifs->sta_scan_pending &&
143 wpas_p2p_in_progress(wpa_s) == 2) {
144 wpa_printf(MSG_DEBUG, "Delaying P2P scan to allow "
145 "pending station mode scan to be "
146 "completed on interface %s", ifs->ifname);
147 wpa_s->global->p2p_cb_on_scan_complete = 1;
148 wpa_supplicant_req_scan(ifs, 0, 0);
153 os_memset(¶ms, 0, sizeof(params));
155 /* P2P Wildcard SSID */
156 params.num_ssids = 1;
157 params.ssids[0].ssid = (u8 *) P2P_WILDCARD_SSID;
158 params.ssids[0].ssid_len = P2P_WILDCARD_SSID_LEN;
160 wpa_s->wps->dev.p2p = 1;
161 wps_ie = wps_build_probe_req_ie(pw_id, &wpa_s->wps->dev,
162 wpa_s->wps->uuid, WPS_REQ_ENROLLEE,
163 num_req_dev_types, req_dev_types);
167 ielen = p2p_scan_ie_buf_len(wpa_s->global->p2p);
168 ies = wpabuf_alloc(wpabuf_len(wps_ie) + ielen);
173 wpabuf_put_buf(ies, wps_ie);
176 p2p_scan_ie(wpa_s->global->p2p, ies, dev_id);
178 params.p2p_probe = 1;
179 params.extra_ies = wpabuf_head(ies);
180 params.extra_ies_len = wpabuf_len(ies);
183 case P2P_SCAN_SOCIAL:
184 params.freqs = social_channels;
188 case P2P_SCAN_SPECIFIC:
189 social_channels[0] = freq;
190 social_channels[1] = 0;
191 params.freqs = social_channels;
193 case P2P_SCAN_SOCIAL_PLUS_ONE:
194 social_channels[3] = freq;
195 params.freqs = social_channels;
199 ret = wpa_drv_scan(wpa_s, ¶ms);
204 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
206 ifs->scan_res_handler == wpas_p2p_scan_res_handler) {
207 wpa_s->global->p2p_cb_on_scan_complete = 1;
213 wpa_s->scan_res_handler = wpas_p2p_scan_res_handler;
219 static enum wpa_driver_if_type wpas_p2p_if_type(int p2p_group_interface)
221 switch (p2p_group_interface) {
222 case P2P_GROUP_INTERFACE_PENDING:
223 return WPA_IF_P2P_GROUP;
224 case P2P_GROUP_INTERFACE_GO:
225 return WPA_IF_P2P_GO;
226 case P2P_GROUP_INTERFACE_CLIENT:
227 return WPA_IF_P2P_CLIENT;
230 return WPA_IF_P2P_GROUP;
234 static struct wpa_supplicant * wpas_get_p2p_group(struct wpa_supplicant *wpa_s,
236 size_t ssid_len, int *go)
240 for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) {
241 for (s = wpa_s->conf->ssid; s; s = s->next) {
242 if (s->disabled != 0 || !s->p2p_group ||
243 s->ssid_len != ssid_len ||
244 os_memcmp(ssid, s->ssid, ssid_len) != 0)
246 if (s->mode == WPAS_MODE_P2P_GO &&
247 s != wpa_s->current_ssid)
250 *go = s->mode == WPAS_MODE_P2P_GO;
259 static int wpas_p2p_group_delete(struct wpa_supplicant *wpa_s,
260 enum p2p_group_removal_reason removal_reason)
262 struct wpa_ssid *ssid;
266 ssid = wpa_s->current_ssid;
269 * The current SSID was not known, but there may still be a
270 * pending P2P group interface waiting for provisioning or a
271 * P2P group that is trying to reconnect.
273 ssid = wpa_s->conf->ssid;
275 if (ssid->p2p_group && ssid->disabled != 2)
280 wpa_s->p2p_group_interface == NOT_P2P_GROUP_INTERFACE)
282 wpa_printf(MSG_ERROR, "P2P: P2P group interface "
287 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO)
289 else if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT ||
290 (ssid && ssid->mode == WPAS_MODE_INFRA)) {
291 wpa_s->reassociate = 0;
292 wpa_s->disconnected = 1;
293 wpa_supplicant_deauthenticate(wpa_s,
294 WLAN_REASON_DEAUTH_LEAVING);
298 if (wpa_s->cross_connect_in_use) {
299 wpa_s->cross_connect_in_use = 0;
300 wpa_msg(wpa_s->parent, MSG_INFO,
301 P2P_EVENT_CROSS_CONNECT_DISABLE "%s %s",
302 wpa_s->ifname, wpa_s->cross_connect_uplink);
304 switch (removal_reason) {
305 case P2P_GROUP_REMOVAL_REQUESTED:
306 reason = " reason=REQUESTED";
308 case P2P_GROUP_REMOVAL_FORMATION_FAILED:
309 reason = " reason=FORMATION_FAILED";
311 case P2P_GROUP_REMOVAL_IDLE_TIMEOUT:
312 reason = " reason=IDLE";
314 case P2P_GROUP_REMOVAL_UNAVAILABLE:
315 reason = " reason=UNAVAILABLE";
317 case P2P_GROUP_REMOVAL_GO_ENDING_SESSION:
318 reason = " reason=GO_ENDING_SESSION";
321 case P2P_GROUP_REMOVAL_FREQ_CONFLICT:
322 reason = " reason=FREQ_CONFLICT";
329 if (removal_reason != P2P_GROUP_REMOVAL_SILENT) {
330 wpa_msg(wpa_s->parent, MSG_INFO,
331 P2P_EVENT_GROUP_REMOVED "%s %s%s",
332 wpa_s->ifname, gtype, reason);
335 if (eloop_cancel_timeout(wpas_p2p_group_idle_timeout, wpa_s, NULL) > 0)
336 wpa_printf(MSG_DEBUG, "P2P: Cancelled P2P group idle timeout");
338 if (removal_reason != P2P_GROUP_REMOVAL_SILENT && ssid)
339 wpas_notify_p2p_group_removed(wpa_s, ssid, gtype);
341 if (wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE) {
342 struct wpa_global *global;
344 enum wpa_driver_if_type type;
345 wpa_printf(MSG_DEBUG, "P2P: Remove group interface %s",
347 global = wpa_s->global;
348 ifname = os_strdup(wpa_s->ifname);
349 type = wpas_p2p_if_type(wpa_s->p2p_group_interface);
350 wpa_supplicant_remove_iface(wpa_s->global, wpa_s, 0);
351 wpa_s = global->ifaces;
353 wpa_drv_if_remove(wpa_s, type, ifname);
358 wpa_printf(MSG_DEBUG, "P2P: Remove temporary group network");
359 if (ssid && (ssid->p2p_group ||
360 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION ||
361 (ssid->key_mgmt & WPA_KEY_MGMT_WPS))) {
363 if (ssid == wpa_s->current_ssid) {
364 wpa_sm_set_config(wpa_s->wpa, NULL);
365 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
366 wpa_s->current_ssid = NULL;
369 * Networks objects created during any P2P activities are not
370 * exposed out as they might/will confuse certain non-P2P aware
371 * applications since these network objects won't behave like
374 * Likewise, we don't send out network removed signals for such
377 wpa_config_remove_network(wpa_s->conf, id);
378 wpa_supplicant_clear_status(wpa_s);
379 wpa_supplicant_cancel_sched_scan(wpa_s);
380 wpa_s->sta_scan_pending = 0;
382 wpa_printf(MSG_DEBUG, "P2P: Temporary group network not "
386 wpa_supplicant_ap_deinit(wpa_s);
388 wpa_drv_deinit_p2p_cli(wpa_s);
394 static int wpas_p2p_persistent_group(struct wpa_supplicant *wpa_s,
396 const u8 *ssid, size_t ssid_len)
404 if (wpa_s->go_params)
405 bssid = wpa_s->go_params->peer_interface_addr;
407 bssid = wpa_s->bssid;
409 bss = wpa_bss_get(wpa_s, bssid, ssid, ssid_len);
411 u8 iface_addr[ETH_ALEN];
412 if (p2p_get_interface_addr(wpa_s->global->p2p, bssid,
414 bss = wpa_bss_get(wpa_s, iface_addr, ssid, ssid_len);
417 wpa_printf(MSG_DEBUG, "P2P: Could not figure out whether "
418 "group is persistent - BSS " MACSTR " not found",
423 p2p = wpa_bss_get_vendor_ie_multi(bss, P2P_IE_VENDOR_TYPE);
425 wpa_printf(MSG_DEBUG, "P2P: Could not figure out whether "
426 "group is persistent - BSS " MACSTR
427 " did not include P2P IE", MAC2STR(bssid));
428 wpa_hexdump(MSG_DEBUG, "P2P: Probe Response IEs",
429 (u8 *) (bss + 1), bss->ie_len);
430 wpa_hexdump(MSG_DEBUG, "P2P: Beacon IEs",
431 ((u8 *) bss + 1) + bss->ie_len,
436 group_capab = p2p_get_group_capab(p2p);
437 addr = p2p_get_go_dev_addr(p2p);
438 wpa_printf(MSG_DEBUG, "P2P: Checking whether group is persistent: "
439 "group_capab=0x%x", group_capab);
441 os_memcpy(go_dev_addr, addr, ETH_ALEN);
442 wpa_printf(MSG_DEBUG, "P2P: GO Device Address " MACSTR,
445 os_memset(go_dev_addr, 0, ETH_ALEN);
448 wpa_printf(MSG_DEBUG, "P2P: BSS " MACSTR " group_capab=0x%x "
449 "go_dev_addr=" MACSTR,
450 MAC2STR(bssid), group_capab, MAC2STR(go_dev_addr));
452 return group_capab & P2P_GROUP_CAPAB_PERSISTENT_GROUP;
456 static int wpas_p2p_store_persistent_group(struct wpa_supplicant *wpa_s,
457 struct wpa_ssid *ssid,
458 const u8 *go_dev_addr)
463 wpa_printf(MSG_DEBUG, "P2P: Storing credentials for a persistent "
464 "group (GO Dev Addr " MACSTR ")", MAC2STR(go_dev_addr));
465 for (s = wpa_s->conf->ssid; s; s = s->next) {
466 if (s->disabled == 2 &&
467 os_memcmp(go_dev_addr, s->bssid, ETH_ALEN) == 0 &&
468 s->ssid_len == ssid->ssid_len &&
469 os_memcmp(ssid->ssid, s->ssid, ssid->ssid_len) == 0)
474 wpa_printf(MSG_DEBUG, "P2P: Update existing persistent group "
476 if (ssid->passphrase && !s->passphrase)
478 else if (ssid->passphrase && s->passphrase &&
479 os_strcmp(ssid->passphrase, s->passphrase) != 0)
482 wpa_printf(MSG_DEBUG, "P2P: Create a new persistent group "
485 s = wpa_config_add_network(wpa_s->conf);
490 * Instead of network_added we emit persistent_group_added
491 * notification. Also to keep the defense checks in
492 * persistent_group obj registration method, we set the
493 * relevant flags in s to designate it as a persistent group.
496 s->p2p_persistent_group = 1;
497 wpas_notify_persistent_group_added(wpa_s, s);
498 wpa_config_set_network_defaults(s);
502 s->p2p_persistent_group = 1;
505 os_memcpy(s->bssid, go_dev_addr, ETH_ALEN);
506 s->mode = ssid->mode;
507 s->auth_alg = WPA_AUTH_ALG_OPEN;
508 s->key_mgmt = WPA_KEY_MGMT_PSK;
509 s->proto = WPA_PROTO_RSN;
510 s->pairwise_cipher = WPA_CIPHER_CCMP;
512 if (ssid->passphrase) {
513 os_free(s->passphrase);
514 s->passphrase = os_strdup(ssid->passphrase);
518 os_memcpy(s->psk, ssid->psk, 32);
520 if (s->passphrase && !s->psk_set)
521 wpa_config_update_psk(s);
522 if (s->ssid == NULL || s->ssid_len < ssid->ssid_len) {
524 s->ssid = os_malloc(ssid->ssid_len);
527 s->ssid_len = ssid->ssid_len;
528 os_memcpy(s->ssid, ssid->ssid, s->ssid_len);
531 #ifndef CONFIG_NO_CONFIG_WRITE
532 if (changed && wpa_s->conf->update_config &&
533 wpa_config_write(wpa_s->confname, wpa_s->conf)) {
534 wpa_printf(MSG_DEBUG, "P2P: Failed to update configuration");
536 #endif /* CONFIG_NO_CONFIG_WRITE */
542 static void wpas_p2p_add_persistent_group_client(struct wpa_supplicant *wpa_s,
545 struct wpa_ssid *ssid, *s;
550 ssid = wpa_s->current_ssid;
551 if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO ||
552 !ssid->p2p_persistent_group)
555 for (s = wpa_s->parent->conf->ssid; s; s = s->next) {
556 if (s->disabled != 2 || s->mode != WPAS_MODE_P2P_GO)
559 if (s->ssid_len == ssid->ssid_len &&
560 os_memcmp(s->ssid, ssid->ssid, s->ssid_len) == 0)
567 for (i = 0; s->p2p_client_list && i < s->num_p2p_clients; i++) {
568 if (os_memcmp(s->p2p_client_list + i * ETH_ALEN, addr,
572 if (i == s->num_p2p_clients - 1)
573 return; /* already the most recent entry */
575 /* move the entry to mark it most recent */
576 os_memmove(s->p2p_client_list + i * ETH_ALEN,
577 s->p2p_client_list + (i + 1) * ETH_ALEN,
578 (s->num_p2p_clients - i - 1) * ETH_ALEN);
579 os_memcpy(s->p2p_client_list +
580 (s->num_p2p_clients - 1) * ETH_ALEN, addr, ETH_ALEN);
585 if (!found && s->num_p2p_clients < P2P_MAX_STORED_CLIENTS) {
586 n = os_realloc_array(s->p2p_client_list,
587 s->num_p2p_clients + 1, ETH_ALEN);
590 os_memcpy(n + s->num_p2p_clients * ETH_ALEN, addr, ETH_ALEN);
591 s->p2p_client_list = n;
592 s->num_p2p_clients++;
594 /* Not enough room for an additional entry - drop the oldest
596 os_memmove(s->p2p_client_list,
597 s->p2p_client_list + ETH_ALEN,
598 (s->num_p2p_clients - 1) * ETH_ALEN);
599 os_memcpy(s->p2p_client_list +
600 (s->num_p2p_clients - 1) * ETH_ALEN,
604 #ifndef CONFIG_NO_CONFIG_WRITE
605 if (wpa_s->parent->conf->update_config &&
606 wpa_config_write(wpa_s->parent->confname, wpa_s->parent->conf))
607 wpa_printf(MSG_DEBUG, "P2P: Failed to update configuration");
608 #endif /* CONFIG_NO_CONFIG_WRITE */
612 static void wpas_group_formation_completed(struct wpa_supplicant *wpa_s,
615 struct wpa_ssid *ssid;
616 const char *ssid_txt;
619 u8 go_dev_addr[ETH_ALEN];
623 * This callback is likely called for the main interface. Update wpa_s
624 * to use the group interface if a new interface was created for the
627 if (wpa_s->global->p2p_group_formation)
628 wpa_s = wpa_s->global->p2p_group_formation;
629 wpa_s->global->p2p_group_formation = NULL;
630 wpa_s->p2p_in_provisioning = 0;
633 wpa_msg(wpa_s->parent, MSG_INFO,
634 P2P_EVENT_GROUP_FORMATION_FAILURE);
635 wpas_p2p_group_delete(wpa_s,
636 P2P_GROUP_REMOVAL_FORMATION_FAILED);
640 wpa_msg(wpa_s->parent, MSG_INFO, P2P_EVENT_GROUP_FORMATION_SUCCESS);
642 ssid = wpa_s->current_ssid;
643 if (ssid && ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION) {
644 ssid->mode = WPAS_MODE_P2P_GO;
645 p2p_group_notif_formation_done(wpa_s->p2p_group);
646 wpa_supplicant_ap_mac_addr_filter(wpa_s, NULL);
651 ssid_txt = wpa_ssid_txt(ssid->ssid, ssid->ssid_len);
652 client = ssid->mode == WPAS_MODE_INFRA;
653 if (ssid->mode == WPAS_MODE_P2P_GO) {
654 persistent = ssid->p2p_persistent_group;
655 os_memcpy(go_dev_addr, wpa_s->global->p2p_dev_addr,
658 persistent = wpas_p2p_persistent_group(wpa_s,
664 client = wpa_s->p2p_group_interface ==
665 P2P_GROUP_INTERFACE_CLIENT;
666 os_memset(go_dev_addr, 0, ETH_ALEN);
669 wpa_s->show_group_started = 0;
672 * Indicate event only after successfully completed 4-way
673 * handshake, i.e., when the interface is ready for data
676 wpa_s->show_group_started = 1;
678 /* For client Second phase of Group formation (4-way handshake) can be still pending
679 * So we need to restore wpa_s->global->p2p_group_formation */
680 wpa_printf(MSG_INFO, "Restoring back wpa_s->global->p2p_group_formation to wpa_s %p\n", wpa_s);
681 wpa_s->global->p2p_group_formation = wpa_s;
684 } else if (ssid && ssid->passphrase == NULL && ssid->psk_set) {
686 wpa_snprintf_hex(psk, sizeof(psk), ssid->psk, 32);
687 wpa_msg(wpa_s->parent, MSG_INFO, P2P_EVENT_GROUP_STARTED
688 "%s GO ssid=\"%s\" freq=%d psk=%s go_dev_addr=" MACSTR
690 wpa_s->ifname, ssid_txt, ssid->frequency, psk,
691 MAC2STR(go_dev_addr),
692 persistent ? " [PERSISTENT]" : "");
693 wpas_p2p_cross_connect_setup(wpa_s);
694 wpas_p2p_set_group_idle_timeout(wpa_s);
696 wpa_msg(wpa_s->parent, MSG_INFO, P2P_EVENT_GROUP_STARTED
697 "%s GO ssid=\"%s\" freq=%d passphrase=\"%s\" "
698 "go_dev_addr=" MACSTR "%s",
699 wpa_s->ifname, ssid_txt, ssid ? ssid->frequency : 0,
700 ssid && ssid->passphrase ? ssid->passphrase : "",
701 MAC2STR(go_dev_addr),
702 persistent ? " [PERSISTENT]" : "");
703 wpas_p2p_cross_connect_setup(wpa_s);
704 wpas_p2p_set_group_idle_timeout(wpa_s);
708 network_id = wpas_p2p_store_persistent_group(wpa_s->parent,
710 if (network_id < 0 && ssid)
711 network_id = ssid->id;
713 wpas_notify_p2p_group_started(wpa_s, ssid, network_id, 0);
717 static void wpas_p2p_send_action_tx_status(struct wpa_supplicant *wpa_s,
719 const u8 *dst, const u8 *src,
721 const u8 *data, size_t data_len,
722 enum offchannel_send_action_result
725 enum p2p_send_action_result res = P2P_SEND_ACTION_SUCCESS;
727 if (wpa_s->global->p2p == NULL || wpa_s->global->p2p_disabled)
729 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT)
733 case OFFCHANNEL_SEND_ACTION_SUCCESS:
734 res = P2P_SEND_ACTION_SUCCESS;
736 case OFFCHANNEL_SEND_ACTION_NO_ACK:
737 res = P2P_SEND_ACTION_NO_ACK;
739 case OFFCHANNEL_SEND_ACTION_FAILED:
740 res = P2P_SEND_ACTION_FAILED;
744 p2p_send_action_cb(wpa_s->global->p2p, freq, dst, src, bssid, res);
746 if (result != OFFCHANNEL_SEND_ACTION_SUCCESS &&
747 wpa_s->pending_pd_before_join &&
748 (os_memcmp(dst, wpa_s->pending_join_dev_addr, ETH_ALEN) == 0 ||
749 os_memcmp(dst, wpa_s->pending_join_iface_addr, ETH_ALEN) == 0)) {
750 wpa_s->pending_pd_before_join = 0;
751 if (wpa_s->p2p_fallback_to_go_neg) {
752 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: No ACK for PD Req "
753 "during p2p_connect-auto");
754 wpas_p2p_fallback_to_go_neg(wpa_s, 0);
758 wpa_printf(MSG_DEBUG, "P2P: Starting pending "
759 "join-existing-group operation (no ACK for PD "
761 wpas_p2p_join_start(wpa_s);
766 static int wpas_send_action(void *ctx, unsigned int freq, const u8 *dst,
767 const u8 *src, const u8 *bssid, const u8 *buf,
768 size_t len, unsigned int wait_time)
770 struct wpa_supplicant *wpa_s = ctx;
771 return offchannel_send_action(wpa_s, freq, dst, src, bssid, buf, len,
773 wpas_p2p_send_action_tx_status, 1);
777 static void wpas_send_action_done(void *ctx)
779 struct wpa_supplicant *wpa_s = ctx;
780 offchannel_send_action_done(wpa_s);
784 static int wpas_copy_go_neg_results(struct wpa_supplicant *wpa_s,
785 struct p2p_go_neg_results *params)
787 if (wpa_s->go_params == NULL) {
788 wpa_s->go_params = os_malloc(sizeof(*params));
789 if (wpa_s->go_params == NULL)
792 os_memcpy(wpa_s->go_params, params, sizeof(*params));
797 static void wpas_start_wps_enrollee(struct wpa_supplicant *wpa_s,
798 struct p2p_go_neg_results *res)
800 wpa_printf(MSG_DEBUG, "P2P: Start WPS Enrollee for peer " MACSTR,
801 MAC2STR(res->peer_interface_addr));
802 wpa_hexdump_ascii(MSG_DEBUG, "P2P: Start WPS Enrollee for SSID",
803 res->ssid, res->ssid_len);
804 wpa_supplicant_ap_deinit(wpa_s);
805 wpas_copy_go_neg_results(wpa_s, res);
806 if (res->wps_method == WPS_PBC)
807 wpas_wps_start_pbc(wpa_s, res->peer_interface_addr, 1);
809 u16 dev_pw_id = DEV_PW_DEFAULT;
810 if (wpa_s->p2p_wps_method == WPS_PIN_KEYPAD)
811 dev_pw_id = DEV_PW_REGISTRAR_SPECIFIED;
812 wpas_wps_start_pin(wpa_s, res->peer_interface_addr,
813 wpa_s->p2p_pin, 1, dev_pw_id);
818 static void p2p_go_configured(void *ctx, void *data)
820 struct wpa_supplicant *wpa_s = ctx;
821 struct p2p_go_neg_results *params = data;
822 struct wpa_ssid *ssid;
825 ssid = wpa_s->current_ssid;
826 if (ssid && ssid->mode == WPAS_MODE_P2P_GO) {
827 wpa_printf(MSG_DEBUG, "P2P: Group setup without provisioning");
828 if (wpa_s->global->p2p_group_formation == wpa_s)
829 wpa_s->global->p2p_group_formation = NULL;
830 wpa_msg(wpa_s->parent, MSG_INFO, P2P_EVENT_GROUP_STARTED
831 "%s GO ssid=\"%s\" freq=%d passphrase=\"%s\" "
832 "go_dev_addr=" MACSTR "%s",
834 wpa_ssid_txt(ssid->ssid, ssid->ssid_len),
836 params->passphrase ? params->passphrase : "",
837 MAC2STR(wpa_s->global->p2p_dev_addr),
838 params->persistent_group ? " [PERSISTENT]" : "");
840 if (params->persistent_group)
841 network_id = wpas_p2p_store_persistent_group(
843 wpa_s->global->p2p_dev_addr);
845 network_id = ssid->id;
846 wpas_notify_p2p_group_started(wpa_s, ssid, network_id, 0);
847 wpas_p2p_cross_connect_setup(wpa_s);
848 wpas_p2p_set_group_idle_timeout(wpa_s);
852 wpa_printf(MSG_DEBUG, "P2P: Setting up WPS for GO provisioning");
853 if (wpa_supplicant_ap_mac_addr_filter(wpa_s,
854 params->peer_interface_addr)) {
855 wpa_printf(MSG_DEBUG, "P2P: Failed to setup MAC address "
859 if (params->wps_method == WPS_PBC)
860 wpa_supplicant_ap_wps_pbc(wpa_s, params->peer_interface_addr,
861 params->peer_device_addr);
862 else if (wpa_s->p2p_pin[0])
863 wpa_supplicant_ap_wps_pin(wpa_s, params->peer_interface_addr,
864 wpa_s->p2p_pin, NULL, 0);
865 os_free(wpa_s->go_params);
866 wpa_s->go_params = NULL;
870 static void wpas_start_wps_go(struct wpa_supplicant *wpa_s,
871 struct p2p_go_neg_results *params,
874 struct wpa_ssid *ssid;
876 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Starting GO");
877 if (wpas_copy_go_neg_results(wpa_s, params) < 0) {
878 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Could not copy GO Negotiation "
883 ssid = wpa_config_add_network(wpa_s->conf);
885 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Could not add network for GO");
889 wpa_s->show_group_started = 0;
891 wpa_config_set_network_defaults(ssid);
894 ssid->p2p_persistent_group = params->persistent_group;
895 ssid->mode = group_formation ? WPAS_MODE_P2P_GROUP_FORMATION :
897 ssid->frequency = params->freq;
898 ssid->ht40 = params->ht40;
899 ssid->ssid = os_zalloc(params->ssid_len + 1);
901 os_memcpy(ssid->ssid, params->ssid, params->ssid_len);
902 ssid->ssid_len = params->ssid_len;
904 ssid->auth_alg = WPA_AUTH_ALG_OPEN;
905 ssid->key_mgmt = WPA_KEY_MGMT_PSK;
906 ssid->proto = WPA_PROTO_RSN;
907 ssid->pairwise_cipher = WPA_CIPHER_CCMP;
908 ssid->passphrase = os_strdup(params->passphrase);
909 if (ssid->passphrase == NULL) {
910 wpa_msg(wpa_s, MSG_ERROR, "P2P: Failed to copy passphrase for "
912 wpa_config_remove_network(wpa_s->conf, ssid->id);
915 wpa_config_update_psk(ssid);
916 ssid->ap_max_inactivity = wpa_s->parent->conf->p2p_go_max_inactivity;
918 wpa_s->ap_configured_cb = p2p_go_configured;
919 wpa_s->ap_configured_cb_ctx = wpa_s;
920 wpa_s->ap_configured_cb_data = wpa_s->go_params;
921 wpa_s->connect_without_scan = ssid;
922 wpa_s->reassociate = 1;
923 wpa_s->disconnected = 0;
924 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Request scan (that will be skipped) to "
926 wpa_supplicant_req_scan(wpa_s, 0, 0);
930 static void wpas_p2p_clone_config(struct wpa_supplicant *dst,
931 const struct wpa_supplicant *src)
933 struct wpa_config *d;
934 const struct wpa_config *s;
939 #define C(n) if (s->n) d->n = os_strdup(s->n)
948 os_memcpy(d->device_type, s->device_type, WPS_DEV_TYPE_LEN);
949 os_memcpy(d->sec_device_type, s->sec_device_type,
950 sizeof(d->sec_device_type));
951 d->num_sec_device_types = s->num_sec_device_types;
953 d->p2p_group_idle = s->p2p_group_idle;
954 d->p2p_intra_bss = s->p2p_intra_bss;
955 d->persistent_reconnect = s->persistent_reconnect;
956 d->max_num_sta = s->max_num_sta;
957 d->pbc_in_m1 = s->pbc_in_m1;
961 static int wpas_p2p_add_group_interface(struct wpa_supplicant *wpa_s,
962 enum wpa_driver_if_type type)
964 char ifname[120], force_ifname[120];
966 if (wpa_s->pending_interface_name[0]) {
967 wpa_printf(MSG_DEBUG, "P2P: Pending virtual interface exists "
968 "- skip creation of a new one");
969 if (is_zero_ether_addr(wpa_s->pending_interface_addr)) {
970 wpa_printf(MSG_DEBUG, "P2P: Pending virtual address "
971 "unknown?! ifname='%s'",
972 wpa_s->pending_interface_name);
978 os_snprintf(ifname, sizeof(ifname), "p2p-%s-%d", wpa_s->ifname,
979 wpa_s->p2p_group_idx);
980 if (os_strlen(ifname) >= IFNAMSIZ &&
981 os_strlen(wpa_s->ifname) < IFNAMSIZ) {
982 /* Try to avoid going over the IFNAMSIZ length limit */
983 os_snprintf(ifname, sizeof(ifname), "p2p-%d",
984 wpa_s->p2p_group_idx);
986 force_ifname[0] = '\0';
988 wpa_printf(MSG_DEBUG, "P2P: Create a new interface %s for the group",
990 wpa_s->p2p_group_idx++;
992 wpa_s->pending_interface_type = type;
993 if (wpa_drv_if_add(wpa_s, type, ifname, NULL, NULL, force_ifname,
994 wpa_s->pending_interface_addr, NULL) < 0) {
995 wpa_printf(MSG_ERROR, "P2P: Failed to create new group "
1000 if (force_ifname[0]) {
1001 wpa_printf(MSG_DEBUG, "P2P: Driver forced interface name %s",
1003 os_strlcpy(wpa_s->pending_interface_name, force_ifname,
1004 sizeof(wpa_s->pending_interface_name));
1006 os_strlcpy(wpa_s->pending_interface_name, ifname,
1007 sizeof(wpa_s->pending_interface_name));
1008 wpa_printf(MSG_DEBUG, "P2P: Created pending virtual interface %s addr "
1009 MACSTR, wpa_s->pending_interface_name,
1010 MAC2STR(wpa_s->pending_interface_addr));
1016 static void wpas_p2p_remove_pending_group_interface(
1017 struct wpa_supplicant *wpa_s)
1019 if (!wpa_s->pending_interface_name[0] ||
1020 is_zero_ether_addr(wpa_s->pending_interface_addr))
1021 return; /* No pending virtual interface */
1023 wpa_printf(MSG_DEBUG, "P2P: Removing pending group interface %s",
1024 wpa_s->pending_interface_name);
1025 wpa_drv_if_remove(wpa_s, wpa_s->pending_interface_type,
1026 wpa_s->pending_interface_name);
1027 os_memset(wpa_s->pending_interface_addr, 0, ETH_ALEN);
1028 wpa_s->pending_interface_name[0] = '\0';
1032 static struct wpa_supplicant *
1033 wpas_p2p_init_group_interface(struct wpa_supplicant *wpa_s, int go)
1035 struct wpa_interface iface;
1036 struct wpa_supplicant *group_wpa_s;
1038 if (!wpa_s->pending_interface_name[0]) {
1039 wpa_printf(MSG_ERROR, "P2P: No pending group interface");
1040 if (!wpas_p2p_create_iface(wpa_s))
1043 * Something has forced us to remove the pending interface; try
1044 * to create a new one and hope for the best that we will get
1045 * the same local address.
1047 if (wpas_p2p_add_group_interface(wpa_s, go ? WPA_IF_P2P_GO :
1048 WPA_IF_P2P_CLIENT) < 0)
1052 os_memset(&iface, 0, sizeof(iface));
1053 iface.ifname = wpa_s->pending_interface_name;
1054 iface.driver = wpa_s->driver->name;
1055 iface.ctrl_interface = wpa_s->conf->ctrl_interface;
1056 iface.driver_param = wpa_s->conf->driver_param;
1057 group_wpa_s = wpa_supplicant_add_iface(wpa_s->global, &iface);
1058 if (group_wpa_s == NULL) {
1059 wpa_printf(MSG_ERROR, "P2P: Failed to create new "
1060 "wpa_supplicant interface");
1063 wpa_s->pending_interface_name[0] = '\0';
1064 group_wpa_s->parent = wpa_s;
1065 group_wpa_s->p2p_group_interface = go ? P2P_GROUP_INTERFACE_GO :
1066 P2P_GROUP_INTERFACE_CLIENT;
1067 wpa_s->global->p2p_group_formation = group_wpa_s;
1069 wpas_p2p_clone_config(group_wpa_s, wpa_s);
1075 static void wpas_p2p_group_formation_timeout(void *eloop_ctx,
1078 struct wpa_supplicant *wpa_s = eloop_ctx;
1079 wpa_printf(MSG_DEBUG, "P2P: Group Formation timed out");
1080 if (wpa_s->global->p2p)
1081 p2p_group_formation_failed(wpa_s->global->p2p);
1082 else if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT)
1083 wpa_drv_p2p_group_formation_failed(wpa_s);
1084 wpas_group_formation_completed(wpa_s, 0);
1088 void wpas_go_neg_completed(void *ctx, struct p2p_go_neg_results *res)
1090 struct wpa_supplicant *wpa_s = ctx;
1092 if (wpa_s->off_channel_freq || wpa_s->roc_waiting_drv_freq) {
1093 wpa_drv_cancel_remain_on_channel(wpa_s);
1094 wpa_s->off_channel_freq = 0;
1095 wpa_s->roc_waiting_drv_freq = 0;
1099 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_GO_NEG_FAILURE "status=%d",
1101 wpas_notify_p2p_go_neg_completed(wpa_s, res);
1102 wpas_p2p_remove_pending_group_interface(wpa_s);
1106 if (wpa_s->p2p_go_ht40)
1109 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_GO_NEG_SUCCESS);
1110 wpas_notify_p2p_go_neg_completed(wpa_s, res);
1112 if (res->role_go && wpa_s->p2p_persistent_id >= 0) {
1113 struct wpa_ssid *ssid;
1114 ssid = wpa_config_get_network(wpa_s->conf,
1115 wpa_s->p2p_persistent_id);
1116 if (ssid && ssid->disabled == 2 &&
1117 ssid->mode == WPAS_MODE_P2P_GO && ssid->passphrase) {
1118 size_t len = os_strlen(ssid->passphrase);
1119 wpa_printf(MSG_DEBUG, "P2P: Override passphrase based "
1120 "on requested persistent group");
1121 os_memcpy(res->passphrase, ssid->passphrase, len);
1122 res->passphrase[len] = '\0';
1126 if (wpa_s->create_p2p_iface) {
1127 struct wpa_supplicant *group_wpa_s =
1128 wpas_p2p_init_group_interface(wpa_s, res->role_go);
1129 if (group_wpa_s == NULL) {
1130 wpas_p2p_remove_pending_group_interface(wpa_s);
1133 if (group_wpa_s != wpa_s) {
1134 os_memcpy(group_wpa_s->p2p_pin, wpa_s->p2p_pin,
1135 sizeof(group_wpa_s->p2p_pin));
1136 group_wpa_s->p2p_wps_method = wpa_s->p2p_wps_method;
1138 os_memset(wpa_s->pending_interface_addr, 0, ETH_ALEN);
1139 wpa_s->pending_interface_name[0] = '\0';
1140 group_wpa_s->p2p_in_provisioning = 1;
1143 wpas_start_wps_go(group_wpa_s, res, 1);
1145 wpas_start_wps_enrollee(group_wpa_s, res);
1147 wpa_s->p2p_in_provisioning = 1;
1148 wpa_s->global->p2p_group_formation = wpa_s;
1151 wpas_start_wps_go(wpa_s, res, 1);
1153 wpas_start_wps_enrollee(ctx, res);
1156 wpa_s->p2p_long_listen = 0;
1157 eloop_cancel_timeout(wpas_p2p_long_listen_timeout, wpa_s, NULL);
1159 eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s, NULL);
1160 eloop_register_timeout(15 + res->peer_config_timeout / 100,
1161 (res->peer_config_timeout % 100) * 10000,
1162 wpas_p2p_group_formation_timeout, wpa_s, NULL);
1166 void wpas_go_neg_req_rx(void *ctx, const u8 *src, u16 dev_passwd_id)
1168 struct wpa_supplicant *wpa_s = ctx;
1169 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_GO_NEG_REQUEST MACSTR
1170 " dev_passwd_id=%u", MAC2STR(src), dev_passwd_id);
1172 wpas_notify_p2p_go_neg_req(wpa_s, src, dev_passwd_id);
1176 void wpas_dev_found(void *ctx, const u8 *addr,
1177 const struct p2p_peer_info *info,
1180 #ifndef CONFIG_NO_STDOUT_DEBUG
1181 struct wpa_supplicant *wpa_s = ctx;
1182 char devtype[WPS_DEV_TYPE_BUFSIZE];
1183 #define WFD_DEV_INFO_SIZE 9
1184 char wfd_dev_info_hex[2 * WFD_DEV_INFO_SIZE + 1];
1185 os_memset(wfd_dev_info_hex, 0, sizeof(wfd_dev_info_hex));
1186 #ifdef CONFIG_WIFI_DISPLAY
1187 if (info->wfd_subelems) {
1188 wpa_snprintf_hex(wfd_dev_info_hex, sizeof(wfd_dev_info_hex),
1189 wpabuf_head(info->wfd_subelems),
1192 #endif /* CONFIG_WIFI_DISPLAY */
1193 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_DEVICE_FOUND MACSTR
1194 " p2p_dev_addr=" MACSTR
1195 " pri_dev_type=%s name='%s' config_methods=0x%x "
1196 "dev_capab=0x%x group_capab=0x%x%s%s",
1197 MAC2STR(addr), MAC2STR(info->p2p_device_addr),
1198 wps_dev_type_bin2str(info->pri_dev_type, devtype,
1200 info->device_name, info->config_methods,
1201 info->dev_capab, info->group_capab,
1202 wfd_dev_info_hex[0] ? " wfd_dev_info=0x" : "", wfd_dev_info_hex);
1203 #endif /* CONFIG_NO_STDOUT_DEBUG */
1205 wpas_notify_p2p_device_found(ctx, info->p2p_device_addr, new_device);
1209 static void wpas_dev_lost(void *ctx, const u8 *dev_addr)
1211 struct wpa_supplicant *wpa_s = ctx;
1213 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_DEVICE_LOST
1214 "p2p_dev_addr=" MACSTR, MAC2STR(dev_addr));
1216 wpas_notify_p2p_device_lost(wpa_s, dev_addr);
1220 static int wpas_start_listen(void *ctx, unsigned int freq,
1221 unsigned int duration,
1222 const struct wpabuf *probe_resp_ie)
1224 struct wpa_supplicant *wpa_s = ctx;
1226 wpa_drv_set_ap_wps_ie(wpa_s, NULL, probe_resp_ie, NULL);
1228 if (wpa_drv_probe_req_report(wpa_s, 1) < 0) {
1229 wpa_printf(MSG_DEBUG, "P2P: Failed to request the driver to "
1230 "report received Probe Request frames");
1234 wpa_s->pending_listen_freq = freq;
1235 wpa_s->pending_listen_duration = duration;
1237 if (wpa_drv_remain_on_channel(wpa_s, freq, duration) < 0) {
1238 wpa_printf(MSG_DEBUG, "P2P: Failed to request the driver "
1239 "to remain on channel (%u MHz) for Listen "
1241 wpa_s->pending_listen_freq = 0;
1244 wpa_s->off_channel_freq = 0;
1245 wpa_s->roc_waiting_drv_freq = freq;
1251 static void wpas_stop_listen(void *ctx)
1253 struct wpa_supplicant *wpa_s = ctx;
1254 if (wpa_s->off_channel_freq || wpa_s->roc_waiting_drv_freq) {
1255 wpa_drv_cancel_remain_on_channel(wpa_s);
1256 wpa_s->off_channel_freq = 0;
1257 wpa_s->roc_waiting_drv_freq = 0;
1259 wpa_drv_set_ap_wps_ie(wpa_s, NULL, NULL, NULL);
1260 wpa_drv_probe_req_report(wpa_s, 0);
1264 static int wpas_send_probe_resp(void *ctx, const struct wpabuf *buf)
1266 struct wpa_supplicant *wpa_s = ctx;
1267 return wpa_drv_send_mlme(wpa_s, wpabuf_head(buf), wpabuf_len(buf), 1);
1271 static struct p2p_srv_bonjour *
1272 wpas_p2p_service_get_bonjour(struct wpa_supplicant *wpa_s,
1273 const struct wpabuf *query)
1275 struct p2p_srv_bonjour *bsrv;
1278 len = wpabuf_len(query);
1279 dl_list_for_each(bsrv, &wpa_s->global->p2p_srv_bonjour,
1280 struct p2p_srv_bonjour, list) {
1281 if (len == wpabuf_len(bsrv->query) &&
1282 os_memcmp(wpabuf_head(query), wpabuf_head(bsrv->query),
1290 static struct p2p_srv_upnp *
1291 wpas_p2p_service_get_upnp(struct wpa_supplicant *wpa_s, u8 version,
1292 const char *service)
1294 struct p2p_srv_upnp *usrv;
1296 dl_list_for_each(usrv, &wpa_s->global->p2p_srv_upnp,
1297 struct p2p_srv_upnp, list) {
1298 if (version == usrv->version &&
1299 os_strcmp(service, usrv->service) == 0)
1306 static void wpas_sd_add_proto_not_avail(struct wpabuf *resp, u8 srv_proto,
1311 if (wpabuf_tailroom(resp) < 5)
1314 /* Length (to be filled) */
1315 len_pos = wpabuf_put(resp, 2);
1316 wpabuf_put_u8(resp, srv_proto);
1317 wpabuf_put_u8(resp, srv_trans_id);
1319 wpabuf_put_u8(resp, P2P_SD_PROTO_NOT_AVAILABLE);
1320 /* Response Data: empty */
1321 WPA_PUT_LE16(len_pos, (u8 *) wpabuf_put(resp, 0) - len_pos - 2);
1325 static void wpas_sd_all_bonjour(struct wpa_supplicant *wpa_s,
1326 struct wpabuf *resp, u8 srv_trans_id)
1328 struct p2p_srv_bonjour *bsrv;
1331 wpa_printf(MSG_DEBUG, "P2P: SD Request for all Bonjour services");
1333 if (dl_list_empty(&wpa_s->global->p2p_srv_bonjour)) {
1334 wpa_printf(MSG_DEBUG, "P2P: Bonjour protocol not available");
1338 dl_list_for_each(bsrv, &wpa_s->global->p2p_srv_bonjour,
1339 struct p2p_srv_bonjour, list) {
1340 if (wpabuf_tailroom(resp) <
1341 5 + wpabuf_len(bsrv->query) + wpabuf_len(bsrv->resp))
1343 /* Length (to be filled) */
1344 len_pos = wpabuf_put(resp, 2);
1345 wpabuf_put_u8(resp, P2P_SERV_BONJOUR);
1346 wpabuf_put_u8(resp, srv_trans_id);
1348 wpabuf_put_u8(resp, P2P_SD_SUCCESS);
1349 wpa_hexdump_ascii(MSG_DEBUG, "P2P: Matching Bonjour service",
1350 wpabuf_head(bsrv->resp),
1351 wpabuf_len(bsrv->resp));
1353 wpabuf_put_buf(resp, bsrv->query); /* Key */
1354 wpabuf_put_buf(resp, bsrv->resp); /* Value */
1355 WPA_PUT_LE16(len_pos, (u8 *) wpabuf_put(resp, 0) - len_pos -
1361 static void wpas_sd_req_bonjour(struct wpa_supplicant *wpa_s,
1362 struct wpabuf *resp, u8 srv_trans_id,
1363 const u8 *query, size_t query_len)
1365 struct p2p_srv_bonjour *bsrv;
1369 wpa_hexdump_ascii(MSG_DEBUG, "P2P: SD Request for Bonjour",
1371 if (dl_list_empty(&wpa_s->global->p2p_srv_bonjour)) {
1372 wpa_printf(MSG_DEBUG, "P2P: Bonjour protocol not available");
1373 wpas_sd_add_proto_not_avail(resp, P2P_SERV_BONJOUR,
1378 if (query_len == 0) {
1379 wpas_sd_all_bonjour(wpa_s, resp, srv_trans_id);
1383 if (wpabuf_tailroom(resp) < 5)
1385 /* Length (to be filled) */
1386 len_pos = wpabuf_put(resp, 2);
1387 wpabuf_put_u8(resp, P2P_SERV_BONJOUR);
1388 wpabuf_put_u8(resp, srv_trans_id);
1390 wpabuf_set(&buf, query, query_len);
1391 bsrv = wpas_p2p_service_get_bonjour(wpa_s, &buf);
1393 wpa_printf(MSG_DEBUG, "P2P: Requested Bonjour service not "
1397 wpabuf_put_u8(resp, P2P_SD_REQUESTED_INFO_NOT_AVAILABLE);
1398 /* Response Data: empty */
1399 WPA_PUT_LE16(len_pos, (u8 *) wpabuf_put(resp, 0) - len_pos -
1405 wpabuf_put_u8(resp, P2P_SD_SUCCESS);
1406 wpa_hexdump_ascii(MSG_DEBUG, "P2P: Matching Bonjour service",
1407 wpabuf_head(bsrv->resp), wpabuf_len(bsrv->resp));
1409 if (wpabuf_tailroom(resp) >=
1410 wpabuf_len(bsrv->query) + wpabuf_len(bsrv->resp)) {
1412 wpabuf_put_buf(resp, bsrv->query); /* Key */
1413 wpabuf_put_buf(resp, bsrv->resp); /* Value */
1415 WPA_PUT_LE16(len_pos, (u8 *) wpabuf_put(resp, 0) - len_pos - 2);
1419 static void wpas_sd_all_upnp(struct wpa_supplicant *wpa_s,
1420 struct wpabuf *resp, u8 srv_trans_id)
1422 struct p2p_srv_upnp *usrv;
1425 wpa_printf(MSG_DEBUG, "P2P: SD Request for all UPnP services");
1427 if (dl_list_empty(&wpa_s->global->p2p_srv_upnp)) {
1428 wpa_printf(MSG_DEBUG, "P2P: UPnP protocol not available");
1432 dl_list_for_each(usrv, &wpa_s->global->p2p_srv_upnp,
1433 struct p2p_srv_upnp, list) {
1434 if (wpabuf_tailroom(resp) < 5 + 1 + os_strlen(usrv->service))
1437 /* Length (to be filled) */
1438 len_pos = wpabuf_put(resp, 2);
1439 wpabuf_put_u8(resp, P2P_SERV_UPNP);
1440 wpabuf_put_u8(resp, srv_trans_id);
1443 wpabuf_put_u8(resp, P2P_SD_SUCCESS);
1445 wpabuf_put_u8(resp, usrv->version);
1446 wpa_printf(MSG_DEBUG, "P2P: Matching UPnP Service: %s",
1448 wpabuf_put_str(resp, usrv->service);
1449 WPA_PUT_LE16(len_pos, (u8 *) wpabuf_put(resp, 0) - len_pos -
1455 static void wpas_sd_req_upnp(struct wpa_supplicant *wpa_s,
1456 struct wpabuf *resp, u8 srv_trans_id,
1457 const u8 *query, size_t query_len)
1459 struct p2p_srv_upnp *usrv;
1465 wpa_hexdump_ascii(MSG_DEBUG, "P2P: SD Request for UPnP",
1468 if (dl_list_empty(&wpa_s->global->p2p_srv_upnp)) {
1469 wpa_printf(MSG_DEBUG, "P2P: UPnP protocol not available");
1470 wpas_sd_add_proto_not_avail(resp, P2P_SERV_UPNP,
1475 if (query_len == 0) {
1476 wpas_sd_all_upnp(wpa_s, resp, srv_trans_id);
1480 if (wpabuf_tailroom(resp) < 5)
1483 /* Length (to be filled) */
1484 len_pos = wpabuf_put(resp, 2);
1485 wpabuf_put_u8(resp, P2P_SERV_UPNP);
1486 wpabuf_put_u8(resp, srv_trans_id);
1489 str = os_malloc(query_len);
1492 os_memcpy(str, query + 1, query_len - 1);
1493 str[query_len - 1] = '\0';
1495 dl_list_for_each(usrv, &wpa_s->global->p2p_srv_upnp,
1496 struct p2p_srv_upnp, list) {
1497 if (version != usrv->version)
1500 if (os_strcmp(str, "ssdp:all") != 0 &&
1501 os_strstr(usrv->service, str) == NULL)
1504 if (wpabuf_tailroom(resp) < 2)
1508 wpabuf_put_u8(resp, P2P_SD_SUCCESS);
1510 wpabuf_put_u8(resp, version);
1512 wpabuf_put_u8(resp, ',');
1516 wpa_printf(MSG_DEBUG, "P2P: Matching UPnP Service: %s",
1518 if (wpabuf_tailroom(resp) < os_strlen(usrv->service))
1520 wpabuf_put_str(resp, usrv->service);
1525 wpa_printf(MSG_DEBUG, "P2P: Requested UPnP service not "
1528 wpabuf_put_u8(resp, P2P_SD_REQUESTED_INFO_NOT_AVAILABLE);
1529 /* Response Data: empty */
1532 WPA_PUT_LE16(len_pos, (u8 *) wpabuf_put(resp, 0) - len_pos - 2);
1536 #ifdef CONFIG_WIFI_DISPLAY
1537 static void wpas_sd_req_wfd(struct wpa_supplicant *wpa_s,
1538 struct wpabuf *resp, u8 srv_trans_id,
1539 const u8 *query, size_t query_len)
1545 wpa_hexdump(MSG_DEBUG, "P2P: SD Request for WFD", query, query_len);
1547 if (!wpa_s->global->wifi_display) {
1548 wpa_printf(MSG_DEBUG, "P2P: WFD protocol not available");
1549 wpas_sd_add_proto_not_avail(resp, P2P_SERV_WIFI_DISPLAY,
1554 if (query_len < 1) {
1555 wpa_printf(MSG_DEBUG, "P2P: Missing WFD Requested Device "
1560 if (wpabuf_tailroom(resp) < 5)
1565 wpa_printf(MSG_DEBUG, "P2P: WSD for device role 0x%x", role);
1567 /* TODO: role specific handling */
1569 /* Length (to be filled) */
1570 len_pos = wpabuf_put(resp, 2);
1571 wpabuf_put_u8(resp, P2P_SERV_WIFI_DISPLAY);
1572 wpabuf_put_u8(resp, srv_trans_id);
1573 wpabuf_put_u8(resp, P2P_SD_SUCCESS); /* Status Code */
1575 while (pos < query + query_len) {
1576 if (*pos < MAX_WFD_SUBELEMS &&
1577 wpa_s->global->wfd_subelem[*pos] &&
1578 wpabuf_tailroom(resp) >=
1579 wpabuf_len(wpa_s->global->wfd_subelem[*pos])) {
1580 wpa_printf(MSG_DEBUG, "P2P: Add WSD response "
1581 "subelement %u", *pos);
1582 wpabuf_put_buf(resp, wpa_s->global->wfd_subelem[*pos]);
1587 WPA_PUT_LE16(len_pos, (u8 *) wpabuf_put(resp, 0) - len_pos - 2);
1589 #endif /* CONFIG_WIFI_DISPLAY */
1592 void wpas_sd_request(void *ctx, int freq, const u8 *sa, u8 dialog_token,
1593 u16 update_indic, const u8 *tlvs, size_t tlvs_len)
1595 struct wpa_supplicant *wpa_s = ctx;
1596 const u8 *pos = tlvs;
1597 const u8 *end = tlvs + tlvs_len;
1600 struct wpabuf *resp;
1601 u8 srv_proto, srv_trans_id;
1605 wpa_hexdump(MSG_MSGDUMP, "P2P: Service Discovery Request TLVs",
1607 buf_len = 2 * tlvs_len + 1;
1608 buf = os_malloc(buf_len);
1610 wpa_snprintf_hex(buf, buf_len, tlvs, tlvs_len);
1611 wpa_msg_ctrl(wpa_s, MSG_INFO, P2P_EVENT_SERV_DISC_REQ "%d "
1613 freq, MAC2STR(sa), dialog_token, update_indic,
1618 if (wpa_s->p2p_sd_over_ctrl_iface) {
1619 wpas_notify_p2p_sd_request(wpa_s, freq, sa, dialog_token,
1620 update_indic, tlvs, tlvs_len);
1621 return; /* to be processed by an external program */
1624 resp = wpabuf_alloc(10000);
1628 while (pos + 1 < end) {
1629 wpa_printf(MSG_DEBUG, "P2P: Service Request TLV");
1630 slen = WPA_GET_LE16(pos);
1632 if (pos + slen > end || slen < 2) {
1633 wpa_printf(MSG_DEBUG, "P2P: Unexpected Query Data "
1638 tlv_end = pos + slen;
1641 wpa_printf(MSG_DEBUG, "P2P: Service Protocol Type %u",
1643 srv_trans_id = *pos++;
1644 wpa_printf(MSG_DEBUG, "P2P: Service Transaction ID %u",
1647 wpa_hexdump(MSG_MSGDUMP, "P2P: Query Data",
1648 pos, tlv_end - pos);
1651 if (wpa_s->force_long_sd) {
1652 wpa_printf(MSG_DEBUG, "P2P: SD test - force long "
1654 wpas_sd_all_bonjour(wpa_s, resp, srv_trans_id);
1655 wpas_sd_all_upnp(wpa_s, resp, srv_trans_id);
1659 switch (srv_proto) {
1660 case P2P_SERV_ALL_SERVICES:
1661 wpa_printf(MSG_DEBUG, "P2P: Service Discovery Request "
1662 "for all services");
1663 if (dl_list_empty(&wpa_s->global->p2p_srv_upnp) &&
1664 dl_list_empty(&wpa_s->global->p2p_srv_bonjour)) {
1665 wpa_printf(MSG_DEBUG, "P2P: No service "
1666 "discovery protocols available");
1667 wpas_sd_add_proto_not_avail(
1668 resp, P2P_SERV_ALL_SERVICES,
1672 wpas_sd_all_bonjour(wpa_s, resp, srv_trans_id);
1673 wpas_sd_all_upnp(wpa_s, resp, srv_trans_id);
1675 case P2P_SERV_BONJOUR:
1676 wpas_sd_req_bonjour(wpa_s, resp, srv_trans_id,
1677 pos, tlv_end - pos);
1680 wpas_sd_req_upnp(wpa_s, resp, srv_trans_id,
1681 pos, tlv_end - pos);
1683 #ifdef CONFIG_WIFI_DISPLAY
1684 case P2P_SERV_WIFI_DISPLAY:
1685 wpas_sd_req_wfd(wpa_s, resp, srv_trans_id,
1686 pos, tlv_end - pos);
1688 #endif /* CONFIG_WIFI_DISPLAY */
1690 wpa_printf(MSG_DEBUG, "P2P: Unavailable service "
1691 "protocol %u", srv_proto);
1692 wpas_sd_add_proto_not_avail(resp, srv_proto,
1701 wpas_notify_p2p_sd_request(wpa_s, freq, sa, dialog_token,
1702 update_indic, tlvs, tlvs_len);
1704 wpas_p2p_sd_response(wpa_s, freq, sa, dialog_token, resp);
1710 void wpas_sd_response(void *ctx, const u8 *sa, u16 update_indic,
1711 const u8 *tlvs, size_t tlvs_len)
1713 struct wpa_supplicant *wpa_s = ctx;
1714 const u8 *pos = tlvs;
1715 const u8 *end = tlvs + tlvs_len;
1721 wpa_hexdump(MSG_MSGDUMP, "P2P: Service Discovery Response TLVs",
1723 if (tlvs_len > 1500) {
1724 /* TODO: better way for handling this */
1725 wpa_msg_ctrl(wpa_s, MSG_INFO,
1726 P2P_EVENT_SERV_DISC_RESP MACSTR
1727 " %u <long response: %u bytes>",
1728 MAC2STR(sa), update_indic,
1729 (unsigned int) tlvs_len);
1731 buf_len = 2 * tlvs_len + 1;
1732 buf = os_malloc(buf_len);
1734 wpa_snprintf_hex(buf, buf_len, tlvs, tlvs_len);
1735 wpa_msg_ctrl(wpa_s, MSG_INFO,
1736 P2P_EVENT_SERV_DISC_RESP MACSTR " %u %s",
1737 MAC2STR(sa), update_indic, buf);
1743 u8 srv_proto, srv_trans_id, status;
1745 wpa_printf(MSG_DEBUG, "P2P: Service Response TLV");
1746 slen = WPA_GET_LE16(pos);
1748 if (pos + slen > end || slen < 3) {
1749 wpa_printf(MSG_DEBUG, "P2P: Unexpected Response Data "
1753 tlv_end = pos + slen;
1756 wpa_printf(MSG_DEBUG, "P2P: Service Protocol Type %u",
1758 srv_trans_id = *pos++;
1759 wpa_printf(MSG_DEBUG, "P2P: Service Transaction ID %u",
1762 wpa_printf(MSG_DEBUG, "P2P: Status Code ID %u",
1765 wpa_hexdump(MSG_MSGDUMP, "P2P: Response Data",
1766 pos, tlv_end - pos);
1771 wpas_notify_p2p_sd_response(wpa_s, sa, update_indic, tlvs, tlvs_len);
1775 u64 wpas_p2p_sd_request(struct wpa_supplicant *wpa_s, const u8 *dst,
1776 const struct wpabuf *tlvs)
1778 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT)
1779 return wpa_drv_p2p_sd_request(wpa_s, dst, tlvs);
1780 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
1782 return (uintptr_t) p2p_sd_request(wpa_s->global->p2p, dst, tlvs);
1786 u64 wpas_p2p_sd_request_upnp(struct wpa_supplicant *wpa_s, const u8 *dst,
1787 u8 version, const char *query)
1789 struct wpabuf *tlvs;
1792 tlvs = wpabuf_alloc(2 + 1 + 1 + 1 + os_strlen(query));
1795 wpabuf_put_le16(tlvs, 1 + 1 + 1 + os_strlen(query));
1796 wpabuf_put_u8(tlvs, P2P_SERV_UPNP); /* Service Protocol Type */
1797 wpabuf_put_u8(tlvs, 1); /* Service Transaction ID */
1798 wpabuf_put_u8(tlvs, version);
1799 wpabuf_put_str(tlvs, query);
1800 ret = wpas_p2p_sd_request(wpa_s, dst, tlvs);
1806 #ifdef CONFIG_WIFI_DISPLAY
1808 static u64 wpas_p2p_sd_request_wfd(struct wpa_supplicant *wpa_s, const u8 *dst,
1809 const struct wpabuf *tlvs)
1811 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT)
1813 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
1815 return (uintptr_t) p2p_sd_request_wfd(wpa_s->global->p2p, dst, tlvs);
1819 #define MAX_WFD_SD_SUBELEMS 20
1821 static void wfd_add_sd_req_role(struct wpabuf *tlvs, u8 id, u8 role,
1822 const char *subelems)
1829 len = wpabuf_put(tlvs, 2);
1830 wpabuf_put_u8(tlvs, P2P_SERV_WIFI_DISPLAY); /* Service Protocol Type */
1831 wpabuf_put_u8(tlvs, id); /* Service Transaction ID */
1833 wpabuf_put_u8(tlvs, role);
1838 if (val >= 0 && val < 256) {
1839 wpabuf_put_u8(tlvs, val);
1841 if (count == MAX_WFD_SD_SUBELEMS)
1844 pos = os_strchr(pos + 1, ',');
1850 WPA_PUT_LE16(len, (u8 *) wpabuf_put(tlvs, 0) - len - 2);
1854 u64 wpas_p2p_sd_request_wifi_display(struct wpa_supplicant *wpa_s,
1855 const u8 *dst, const char *role)
1857 struct wpabuf *tlvs;
1859 const char *subelems;
1862 subelems = os_strchr(role, ' ');
1863 if (subelems == NULL)
1867 tlvs = wpabuf_alloc(4 * (2 + 1 + 1 + 1 + MAX_WFD_SD_SUBELEMS));
1871 if (os_strstr(role, "[source]"))
1872 wfd_add_sd_req_role(tlvs, id++, 0x00, subelems);
1873 if (os_strstr(role, "[pri-sink]"))
1874 wfd_add_sd_req_role(tlvs, id++, 0x01, subelems);
1875 if (os_strstr(role, "[sec-sink]"))
1876 wfd_add_sd_req_role(tlvs, id++, 0x02, subelems);
1877 if (os_strstr(role, "[source+sink]"))
1878 wfd_add_sd_req_role(tlvs, id++, 0x03, subelems);
1880 ret = wpas_p2p_sd_request_wfd(wpa_s, dst, tlvs);
1885 #endif /* CONFIG_WIFI_DISPLAY */
1888 int wpas_p2p_sd_cancel_request(struct wpa_supplicant *wpa_s, u64 req)
1890 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT)
1891 return wpa_drv_p2p_sd_cancel_request(wpa_s, req);
1892 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
1894 return p2p_sd_cancel_request(wpa_s->global->p2p,
1895 (void *) (uintptr_t) req);
1899 void wpas_p2p_sd_response(struct wpa_supplicant *wpa_s, int freq,
1900 const u8 *dst, u8 dialog_token,
1901 const struct wpabuf *resp_tlvs)
1903 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT) {
1904 wpa_drv_p2p_sd_response(wpa_s, freq, dst, dialog_token,
1908 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
1910 p2p_sd_response(wpa_s->global->p2p, freq, dst, dialog_token,
1915 void wpas_p2p_sd_service_update(struct wpa_supplicant *wpa_s, int action)
1917 void wpas_p2p_sd_service_update(struct wpa_supplicant *wpa_s)
1920 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT) {
1921 wpa_drv_p2p_service_update(wpa_s);
1924 if (wpa_s->global->p2p)
1926 p2p_sd_service_update(wpa_s->global->p2p, action);
1928 p2p_sd_service_update(wpa_s->global->p2p);
1933 static void wpas_p2p_srv_bonjour_free(struct p2p_srv_bonjour *bsrv)
1935 dl_list_del(&bsrv->list);
1936 wpabuf_free(bsrv->query);
1937 wpabuf_free(bsrv->resp);
1942 static void wpas_p2p_srv_upnp_free(struct p2p_srv_upnp *usrv)
1944 dl_list_del(&usrv->list);
1945 os_free(usrv->service);
1950 void wpas_p2p_service_flush(struct wpa_supplicant *wpa_s)
1952 struct p2p_srv_bonjour *bsrv, *bn;
1953 struct p2p_srv_upnp *usrv, *un;
1955 dl_list_for_each_safe(bsrv, bn, &wpa_s->global->p2p_srv_bonjour,
1956 struct p2p_srv_bonjour, list)
1957 wpas_p2p_srv_bonjour_free(bsrv);
1959 dl_list_for_each_safe(usrv, un, &wpa_s->global->p2p_srv_upnp,
1960 struct p2p_srv_upnp, list)
1961 wpas_p2p_srv_upnp_free(usrv);
1964 wpas_p2p_sd_service_update(wpa_s, SRV_FLUSH);
1966 wpas_p2p_sd_service_update(wpa_s);
1971 int wpas_p2p_service_add_bonjour(struct wpa_supplicant *wpa_s,
1972 struct wpabuf *query, struct wpabuf *resp)
1974 struct p2p_srv_bonjour *bsrv;
1976 bsrv = wpas_p2p_service_get_bonjour(wpa_s, query);
1979 wpabuf_free(bsrv->resp);
1984 bsrv = os_zalloc(sizeof(*bsrv));
1987 bsrv->query = query;
1989 dl_list_add(&wpa_s->global->p2p_srv_bonjour, &bsrv->list);
1992 wpas_p2p_sd_service_update(wpa_s, SRV_ADD);
1994 wpas_p2p_sd_service_update(wpa_s);
2000 int wpas_p2p_service_del_bonjour(struct wpa_supplicant *wpa_s,
2001 const struct wpabuf *query)
2003 struct p2p_srv_bonjour *bsrv;
2005 bsrv = wpas_p2p_service_get_bonjour(wpa_s, query);
2008 wpas_p2p_srv_bonjour_free(bsrv);
2010 wpas_p2p_sd_service_update(wpa_s, SRV_DEL);
2012 wpas_p2p_sd_service_update(wpa_s);
2018 int wpas_p2p_service_add_upnp(struct wpa_supplicant *wpa_s, u8 version,
2019 const char *service)
2021 struct p2p_srv_upnp *usrv;
2023 if (wpas_p2p_service_get_upnp(wpa_s, version, service))
2024 return 0; /* Already listed */
2025 usrv = os_zalloc(sizeof(*usrv));
2028 usrv->version = version;
2029 usrv->service = os_strdup(service);
2030 if (usrv->service == NULL) {
2034 dl_list_add(&wpa_s->global->p2p_srv_upnp, &usrv->list);
2037 wpas_p2p_sd_service_update(wpa_s, SRV_ADD);
2039 wpas_p2p_sd_service_update(wpa_s);
2045 int wpas_p2p_service_del_upnp(struct wpa_supplicant *wpa_s, u8 version,
2046 const char *service)
2048 struct p2p_srv_upnp *usrv;
2050 usrv = wpas_p2p_service_get_upnp(wpa_s, version, service);
2053 wpas_p2p_srv_upnp_free(usrv);
2055 wpas_p2p_sd_service_update(wpa_s, SRV_DEL);
2057 wpas_p2p_sd_service_update(wpa_s);
2063 static void wpas_prov_disc_local_display(struct wpa_supplicant *wpa_s,
2064 const u8 *peer, const char *params,
2065 unsigned int generated_pin)
2067 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_SHOW_PIN MACSTR " %08d%s",
2068 MAC2STR(peer), generated_pin, params);
2072 static void wpas_prov_disc_local_keypad(struct wpa_supplicant *wpa_s,
2073 const u8 *peer, const char *params)
2075 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_ENTER_PIN MACSTR "%s",
2076 MAC2STR(peer), params);
2080 void wpas_prov_disc_req(void *ctx, const u8 *peer, u16 config_methods,
2081 const u8 *dev_addr, const u8 *pri_dev_type,
2082 const char *dev_name, u16 supp_config_methods,
2083 u8 dev_capab, u8 group_capab, const u8 *group_id,
2084 size_t group_id_len)
2086 struct wpa_supplicant *wpa_s = ctx;
2087 char devtype[WPS_DEV_TYPE_BUFSIZE];
2089 u8 empty_dev_type[8];
2090 unsigned int generated_pin = 0;
2091 struct wpa_supplicant *group = NULL;
2094 for (group = wpa_s->global->ifaces; group; group = group->next)
2096 struct wpa_ssid *s = group->current_ssid;
2098 s->mode == WPAS_MODE_P2P_GO &&
2099 group_id_len - ETH_ALEN == s->ssid_len &&
2100 os_memcmp(group_id + ETH_ALEN, s->ssid,
2106 if (pri_dev_type == NULL) {
2107 os_memset(empty_dev_type, 0, sizeof(empty_dev_type));
2108 pri_dev_type = empty_dev_type;
2110 os_snprintf(params, sizeof(params), " p2p_dev_addr=" MACSTR
2111 " pri_dev_type=%s name='%s' config_methods=0x%x "
2112 "dev_capab=0x%x group_capab=0x%x%s%s",
2114 wps_dev_type_bin2str(pri_dev_type, devtype,
2116 dev_name, supp_config_methods, dev_capab, group_capab,
2117 group ? " group=" : "",
2118 group ? group->ifname : "");
2119 params[sizeof(params) - 1] = '\0';
2121 if (config_methods & WPS_CONFIG_DISPLAY) {
2122 generated_pin = wps_generate_pin();
2123 wpas_prov_disc_local_display(wpa_s, peer, params,
2125 } else if (config_methods & WPS_CONFIG_KEYPAD)
2126 wpas_prov_disc_local_keypad(wpa_s, peer, params);
2127 else if (config_methods & WPS_CONFIG_PUSHBUTTON)
2128 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_PBC_REQ MACSTR
2129 "%s", MAC2STR(peer), params);
2131 wpas_notify_p2p_provision_discovery(wpa_s, peer, 1 /* request */,
2132 P2P_PROV_DISC_SUCCESS,
2133 config_methods, generated_pin);
2137 void wpas_prov_disc_resp(void *ctx, const u8 *peer, u16 config_methods)
2139 struct wpa_supplicant *wpa_s = ctx;
2140 unsigned int generated_pin = 0;
2143 if (wpa_s->pending_pd_before_join &&
2144 (os_memcmp(peer, wpa_s->pending_join_dev_addr, ETH_ALEN) == 0 ||
2145 os_memcmp(peer, wpa_s->pending_join_iface_addr, ETH_ALEN) == 0)) {
2146 wpa_s->pending_pd_before_join = 0;
2147 wpa_printf(MSG_DEBUG, "P2P: Starting pending "
2148 "join-existing-group operation");
2149 wpas_p2p_join_start(wpa_s);
2153 if (wpa_s->pending_pd_use == AUTO_PD_JOIN ||
2154 wpa_s->pending_pd_use == AUTO_PD_GO_NEG)
2155 os_snprintf(params, sizeof(params), " peer_go=%d",
2156 wpa_s->pending_pd_use == AUTO_PD_JOIN);
2160 if (config_methods & WPS_CONFIG_DISPLAY)
2161 wpas_prov_disc_local_keypad(wpa_s, peer, params);
2162 else if (config_methods & WPS_CONFIG_KEYPAD) {
2163 generated_pin = wps_generate_pin();
2164 wpas_prov_disc_local_display(wpa_s, peer, params,
2166 } else if (config_methods & WPS_CONFIG_PUSHBUTTON)
2167 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_PBC_RESP MACSTR
2168 "%s", MAC2STR(peer), params);
2170 wpas_notify_p2p_provision_discovery(wpa_s, peer, 0 /* response */,
2171 P2P_PROV_DISC_SUCCESS,
2172 config_methods, generated_pin);
2176 static void wpas_prov_disc_fail(void *ctx, const u8 *peer,
2177 enum p2p_prov_disc_status status)
2179 struct wpa_supplicant *wpa_s = ctx;
2181 if (wpa_s->p2p_fallback_to_go_neg) {
2182 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: PD for p2p_connect-auto "
2183 "failed - fall back to GO Negotiation");
2184 wpas_p2p_fallback_to_go_neg(wpa_s, 0);
2189 /* If provision discovery failed it is safe to cancel the timer here and
2190 * also do not start the join */
2191 if (wpa_s->pending_pd_before_join &&
2192 (os_memcmp(peer, wpa_s->pending_join_dev_addr, ETH_ALEN) == 0 ||
2193 os_memcmp(peer, wpa_s->pending_join_iface_addr, ETH_ALEN) == 0)) {
2194 wpa_s->pending_pd_before_join = 0;
2195 wpa_printf(MSG_DEBUG, "P2P: Do not Start pending "
2196 "join-existing-group operation");
2197 eloop_cancel_timeout(wpas_p2p_pd_before_join_timeout, wpa_s, NULL);
2199 #endif /* ANDROID_P2P */
2200 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_FAILURE
2201 " p2p_dev_addr=" MACSTR " status=%d",
2202 MAC2STR(peer), status);
2204 wpas_notify_p2p_provision_discovery(wpa_s, peer, 0 /* response */,
2209 static u8 wpas_invitation_process(void *ctx, const u8 *sa, const u8 *bssid,
2210 const u8 *go_dev_addr, const u8 *ssid,
2211 size_t ssid_len, int *go, u8 *group_bssid,
2212 int *force_freq, int persistent_group)
2214 struct wpa_supplicant *wpa_s = ctx;
2216 u8 cur_bssid[ETH_ALEN];
2218 struct wpa_supplicant *grp;
2220 if (!persistent_group) {
2221 wpa_printf(MSG_DEBUG, "P2P: Invitation from " MACSTR
2222 " to join an active group", MAC2STR(sa));
2223 if (!is_zero_ether_addr(wpa_s->p2p_auth_invite) &&
2224 (os_memcmp(go_dev_addr, wpa_s->p2p_auth_invite, ETH_ALEN)
2226 os_memcmp(sa, wpa_s->p2p_auth_invite, ETH_ALEN) == 0)) {
2227 wpa_printf(MSG_DEBUG, "P2P: Accept previously "
2228 "authorized invitation");
2232 * Do not accept the invitation automatically; notify user and
2235 return P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE;
2238 grp = wpas_get_p2p_group(wpa_s, ssid, ssid_len, go);
2240 wpa_printf(MSG_DEBUG, "P2P: Accept invitation to already "
2241 "running persistent group");
2243 os_memcpy(group_bssid, grp->own_addr, ETH_ALEN);
2247 if (!wpa_s->conf->persistent_reconnect)
2248 return P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE;
2250 for (s = wpa_s->conf->ssid; s; s = s->next) {
2251 if (s->disabled == 2 &&
2252 os_memcmp(s->bssid, go_dev_addr, ETH_ALEN) == 0 &&
2253 s->ssid_len == ssid_len &&
2254 os_memcmp(ssid, s->ssid, ssid_len) == 0)
2259 wpa_printf(MSG_DEBUG, "P2P: Invitation from " MACSTR
2260 " requested reinvocation of an unknown group",
2262 return P2P_SC_FAIL_UNKNOWN_GROUP;
2265 if (s->mode == WPAS_MODE_P2P_GO && !wpas_p2p_create_iface(wpa_s)) {
2267 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
2268 wpa_printf(MSG_DEBUG, "P2P: The only available "
2269 "interface is already in use - reject "
2271 return P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE;
2273 os_memcpy(group_bssid, wpa_s->own_addr, ETH_ALEN);
2274 } else if (s->mode == WPAS_MODE_P2P_GO) {
2276 if (wpas_p2p_add_group_interface(wpa_s, WPA_IF_P2P_GO) < 0)
2278 wpa_printf(MSG_ERROR, "P2P: Failed to allocate a new "
2279 "interface address for the group");
2280 return P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE;
2282 os_memcpy(group_bssid, wpa_s->pending_interface_addr,
2287 if (wpa_s->current_ssid && wpa_drv_get_bssid(wpa_s, cur_bssid) == 0 &&
2288 wpa_s->assoc_freq) {
2289 wpa_printf(MSG_DEBUG, "P2P: Trying to force channel to match "
2290 "the channel we are already using");
2291 *force_freq = wpa_s->assoc_freq;
2294 res = wpa_drv_shared_freq(wpa_s);
2296 wpa_printf(MSG_DEBUG, "P2P: Trying to force channel to match "
2297 "with the channel we are already using on a "
2298 "shared interface");
2302 return P2P_SC_SUCCESS;
2306 static void wpas_invitation_received(void *ctx, const u8 *sa, const u8 *bssid,
2307 const u8 *ssid, size_t ssid_len,
2308 const u8 *go_dev_addr, u8 status,
2311 struct wpa_supplicant *wpa_s = ctx;
2314 for (s = wpa_s->conf->ssid; s; s = s->next) {
2315 if (s->disabled == 2 &&
2316 s->ssid_len == ssid_len &&
2317 os_memcmp(ssid, s->ssid, ssid_len) == 0)
2321 if (status == P2P_SC_SUCCESS) {
2322 wpa_printf(MSG_DEBUG, "P2P: Invitation from peer " MACSTR
2323 " was accepted; op_freq=%d MHz",
2324 MAC2STR(sa), op_freq);
2326 int go = s->mode == WPAS_MODE_P2P_GO;
2327 wpas_p2p_group_add_persistent(
2328 wpa_s, s, go, go ? op_freq : 0, 0);
2330 wpas_p2p_join(wpa_s, bssid, go_dev_addr,
2331 wpa_s->p2p_wps_method, 0);
2336 if (status != P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE) {
2337 wpa_printf(MSG_DEBUG, "P2P: Invitation from peer " MACSTR
2338 " was rejected (status %u)", MAC2STR(sa), status);
2344 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RECEIVED
2345 "sa=" MACSTR " go_dev_addr=" MACSTR
2346 " bssid=" MACSTR " unknown-network",
2347 MAC2STR(sa), MAC2STR(go_dev_addr),
2350 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RECEIVED
2351 "sa=" MACSTR " go_dev_addr=" MACSTR
2353 MAC2STR(sa), MAC2STR(go_dev_addr));
2358 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RECEIVED "sa=" MACSTR
2359 " persistent=%d", MAC2STR(sa), s->id);
2363 static void wpas_invitation_result(void *ctx, int status, const u8 *bssid)
2365 struct wpa_supplicant *wpa_s = ctx;
2366 struct wpa_ssid *ssid;
2369 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RESULT
2370 "status=%d " MACSTR,
2371 status, MAC2STR(bssid));
2373 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RESULT
2374 "status=%d ", status);
2376 wpas_notify_p2p_invitation_result(wpa_s, status, bssid);
2378 if (wpa_s->pending_invite_ssid_id == -1)
2379 return; /* Invitation to active group */
2381 if (status != P2P_SC_SUCCESS) {
2382 wpas_p2p_remove_pending_group_interface(wpa_s);
2386 ssid = wpa_config_get_network(wpa_s->conf,
2387 wpa_s->pending_invite_ssid_id);
2389 wpa_printf(MSG_ERROR, "P2P: Could not find persistent group "
2390 "data matching with invitation");
2394 wpas_p2p_group_add_persistent(wpa_s, ssid,
2395 ssid->mode == WPAS_MODE_P2P_GO,
2396 wpa_s->p2p_persistent_go_freq,
2397 wpa_s->p2p_go_ht40);
2401 static int wpas_p2p_disallowed_freq(struct wpa_global *global,
2406 if (global->p2p_disallow_freq == NULL)
2409 for (i = 0; i < global->num_p2p_disallow_freq; i++) {
2410 if (freq >= global->p2p_disallow_freq[i].min &&
2411 freq <= global->p2p_disallow_freq[i].max)
2419 static void wpas_p2p_add_chan(struct p2p_reg_class *reg, u8 chan)
2421 reg->channel[reg->channels] = chan;
2426 static int wpas_p2p_default_channels(struct wpa_supplicant *wpa_s,
2427 struct p2p_channels *chan)
2431 wpa_printf(MSG_DEBUG, "P2P: Enable operating classes for 2.4 GHz "
2434 /* Operating class 81 - 2.4 GHz band channels 1..13 */
2435 chan->reg_class[cla].reg_class = 81;
2436 chan->reg_class[cla].channels = 0;
2437 for (i = 0; i < 11; i++) {
2438 if (!wpas_p2p_disallowed_freq(wpa_s->global, 2412 + i * 5))
2439 wpas_p2p_add_chan(&chan->reg_class[cla], i + 1);
2441 if (chan->reg_class[cla].channels)
2444 wpa_printf(MSG_DEBUG, "P2P: Enable operating classes for lower 5 GHz "
2447 /* Operating class 115 - 5 GHz, channels 36-48 */
2448 chan->reg_class[cla].reg_class = 115;
2449 chan->reg_class[cla].channels = 0;
2450 if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 36 * 5))
2451 wpas_p2p_add_chan(&chan->reg_class[cla], 36);
2452 if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 40 * 5))
2453 wpas_p2p_add_chan(&chan->reg_class[cla], 40);
2454 if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 44 * 5))
2455 wpas_p2p_add_chan(&chan->reg_class[cla], 44);
2456 if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 48 * 5))
2457 wpas_p2p_add_chan(&chan->reg_class[cla], 48);
2458 if (chan->reg_class[cla].channels)
2461 wpa_printf(MSG_DEBUG, "P2P: Enable operating classes for higher 5 GHz "
2464 /* Operating class 124 - 5 GHz, channels 149,153,157,161 */
2465 chan->reg_class[cla].reg_class = 124;
2466 chan->reg_class[cla].channels = 0;
2467 if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 149 * 5))
2468 wpas_p2p_add_chan(&chan->reg_class[cla], 149);
2469 if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 153 * 5))
2470 wpas_p2p_add_chan(&chan->reg_class[cla], 153);
2471 if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 156 * 5))
2472 wpas_p2p_add_chan(&chan->reg_class[cla], 157);
2473 if (!wpas_p2p_disallowed_freq(wpa_s->global, 5000 + 161 * 5))
2474 wpas_p2p_add_chan(&chan->reg_class[cla], 161);
2475 if (chan->reg_class[cla].channels)
2478 chan->reg_classes = cla;
2483 static struct hostapd_hw_modes * get_mode(struct hostapd_hw_modes *modes,
2485 enum hostapd_hw_mode mode)
2489 for (i = 0; i < num_modes; i++) {
2490 if (modes[i].mode == mode)
2498 static int has_channel(struct wpa_global *global,
2499 struct hostapd_hw_modes *mode, u8 chan, int *flags)
2504 freq = (mode->mode == HOSTAPD_MODE_IEEE80211A ? 5000 : 2407) +
2506 if (wpas_p2p_disallowed_freq(global, freq))
2509 for (i = 0; i < mode->num_channels; i++) {
2510 if (mode->channels[i].chan == chan) {
2512 *flags = mode->channels[i].flag;
2513 return !(mode->channels[i].flag &
2514 (HOSTAPD_CHAN_DISABLED |
2515 HOSTAPD_CHAN_PASSIVE_SCAN |
2516 HOSTAPD_CHAN_NO_IBSS |
2517 HOSTAPD_CHAN_RADAR));
2525 struct p2p_oper_class_map {
2526 enum hostapd_hw_mode mode;
2531 enum { BW20, BW40PLUS, BW40MINUS } bw;
2534 static struct p2p_oper_class_map op_class[] = {
2535 { HOSTAPD_MODE_IEEE80211G, 81, 1, 13, 1, BW20 },
2536 #if 0 /* Do not enable HT40 on 2 GHz for now */
2537 { HOSTAPD_MODE_IEEE80211G, 83, 1, 9, 1, BW40PLUS },
2538 { HOSTAPD_MODE_IEEE80211G, 84, 5, 13, 1, BW40MINUS },
2540 { HOSTAPD_MODE_IEEE80211A, 115, 36, 48, 4, BW20 },
2541 { HOSTAPD_MODE_IEEE80211A, 124, 149, 161, 4, BW20 },
2542 { HOSTAPD_MODE_IEEE80211A, 116, 36, 44, 8, BW40PLUS },
2543 { HOSTAPD_MODE_IEEE80211A, 117, 40, 48, 8, BW40MINUS },
2544 { HOSTAPD_MODE_IEEE80211A, 126, 149, 157, 8, BW40PLUS },
2545 { HOSTAPD_MODE_IEEE80211A, 127, 153, 161, 8, BW40MINUS },
2546 { -1, 0, 0, 0, 0, BW20 }
2550 static int wpas_p2p_verify_channel(struct wpa_supplicant *wpa_s,
2551 struct hostapd_hw_modes *mode,
2556 if (!has_channel(wpa_s->global, mode, channel, &flag))
2558 if (bw == BW40MINUS &&
2559 (!(flag & HOSTAPD_CHAN_HT40MINUS) ||
2560 !has_channel(wpa_s->global, mode, channel - 4, NULL)))
2562 if (bw == BW40PLUS &&
2563 (!(flag & HOSTAPD_CHAN_HT40PLUS) ||
2564 !has_channel(wpa_s->global, mode, channel + 4, NULL)))
2570 static int wpas_p2p_setup_channels(struct wpa_supplicant *wpa_s,
2571 struct p2p_channels *chan)
2573 struct hostapd_hw_modes *mode;
2576 if (wpa_s->hw.modes == NULL) {
2577 wpa_printf(MSG_DEBUG, "P2P: Driver did not support fetching "
2578 "of all supported channels; assume dualband "
2580 return wpas_p2p_default_channels(wpa_s, chan);
2585 for (op = 0; op_class[op].op_class; op++) {
2586 struct p2p_oper_class_map *o = &op_class[op];
2588 struct p2p_reg_class *reg = NULL;
2590 mode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, o->mode);
2593 for (ch = o->min_chan; ch <= o->max_chan; ch += o->inc) {
2594 if (wpas_p2p_verify_channel(wpa_s, mode, ch, o->bw) < 1)
2597 wpa_printf(MSG_DEBUG, "P2P: Add operating "
2598 "class %u", o->op_class);
2599 reg = &chan->reg_class[cla];
2601 reg->reg_class = o->op_class;
2603 reg->channel[reg->channels] = ch;
2607 wpa_hexdump(MSG_DEBUG, "P2P: Channels",
2608 reg->channel, reg->channels);
2612 chan->reg_classes = cla;
2618 int wpas_p2p_get_ht40_mode(struct wpa_supplicant *wpa_s,
2619 struct hostapd_hw_modes *mode, u8 channel)
2623 for (op = 0; op_class[op].op_class; op++) {
2624 struct p2p_oper_class_map *o = &op_class[op];
2627 for (ch = o->min_chan; ch <= o->max_chan; ch += o->inc) {
2628 if (o->mode != HOSTAPD_MODE_IEEE80211A ||
2629 o->bw == BW20 || ch != channel)
2631 ret = wpas_p2p_verify_channel(wpa_s, mode, ch, o->bw);
2635 return (o->bw == BW40MINUS) ? -1 : 1;
2644 static int wpas_get_noa(void *ctx, const u8 *interface_addr, u8 *buf,
2647 struct wpa_supplicant *wpa_s = ctx;
2649 for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) {
2650 if (os_memcmp(wpa_s->own_addr, interface_addr, ETH_ALEN) == 0)
2656 return wpa_drv_get_noa(wpa_s, buf, buf_len);
2660 static int wpas_go_connected(void *ctx, const u8 *dev_addr)
2662 struct wpa_supplicant *wpa_s = ctx;
2664 for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) {
2665 struct wpa_ssid *ssid = wpa_s->current_ssid;
2668 if (ssid->mode != WPAS_MODE_INFRA)
2670 if (wpa_s->wpa_state != WPA_COMPLETED &&
2671 wpa_s->wpa_state != WPA_GROUP_HANDSHAKE)
2673 if (os_memcmp(wpa_s->go_dev_addr, dev_addr, ETH_ALEN) == 0)
2682 * wpas_p2p_init - Initialize P2P module for %wpa_supplicant
2683 * @global: Pointer to global data from wpa_supplicant_init()
2684 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
2685 * Returns: 0 on success, -1 on failure
2687 int wpas_p2p_init(struct wpa_global *global, struct wpa_supplicant *wpa_s)
2689 struct p2p_config p2p;
2693 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_CAPABLE))
2699 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT) {
2700 struct p2p_params params;
2702 wpa_printf(MSG_DEBUG, "P2P: Use driver-based P2P management");
2703 os_memset(¶ms, 0, sizeof(params));
2704 params.dev_name = wpa_s->conf->device_name;
2705 os_memcpy(params.pri_dev_type, wpa_s->conf->device_type,
2707 params.num_sec_dev_types = wpa_s->conf->num_sec_device_types;
2708 os_memcpy(params.sec_dev_type,
2709 wpa_s->conf->sec_device_type,
2710 params.num_sec_dev_types * WPS_DEV_TYPE_LEN);
2712 if (wpa_drv_p2p_set_params(wpa_s, ¶ms) < 0)
2718 os_memset(&p2p, 0, sizeof(p2p));
2719 p2p.msg_ctx = wpa_s;
2721 p2p.p2p_scan = wpas_p2p_scan;
2722 p2p.send_action = wpas_send_action;
2723 p2p.send_action_done = wpas_send_action_done;
2724 p2p.go_neg_completed = wpas_go_neg_completed;
2725 p2p.go_neg_req_rx = wpas_go_neg_req_rx;
2726 p2p.dev_found = wpas_dev_found;
2727 p2p.dev_lost = wpas_dev_lost;
2728 p2p.start_listen = wpas_start_listen;
2729 p2p.stop_listen = wpas_stop_listen;
2730 p2p.send_probe_resp = wpas_send_probe_resp;
2731 p2p.sd_request = wpas_sd_request;
2732 p2p.sd_response = wpas_sd_response;
2733 p2p.prov_disc_req = wpas_prov_disc_req;
2734 p2p.prov_disc_resp = wpas_prov_disc_resp;
2735 p2p.prov_disc_fail = wpas_prov_disc_fail;
2736 p2p.invitation_process = wpas_invitation_process;
2737 p2p.invitation_received = wpas_invitation_received;
2738 p2p.invitation_result = wpas_invitation_result;
2739 p2p.get_noa = wpas_get_noa;
2740 p2p.go_connected = wpas_go_connected;
2742 os_memcpy(wpa_s->global->p2p_dev_addr, wpa_s->own_addr, ETH_ALEN);
2743 os_memcpy(p2p.dev_addr, wpa_s->global->p2p_dev_addr, ETH_ALEN);
2744 p2p.dev_name = wpa_s->conf->device_name;
2745 p2p.manufacturer = wpa_s->conf->manufacturer;
2746 p2p.model_name = wpa_s->conf->model_name;
2747 p2p.model_number = wpa_s->conf->model_number;
2748 p2p.serial_number = wpa_s->conf->serial_number;
2750 os_memcpy(p2p.uuid, wpa_s->wps->uuid, 16);
2751 p2p.config_methods = wpa_s->wps->config_methods;
2754 if (wpa_s->conf->p2p_listen_reg_class &&
2755 wpa_s->conf->p2p_listen_channel) {
2756 p2p.reg_class = wpa_s->conf->p2p_listen_reg_class;
2757 p2p.channel = wpa_s->conf->p2p_listen_channel;
2761 * Pick one of the social channels randomly as the listen
2764 os_get_random((u8 *) &r, sizeof(r));
2765 p2p.channel = 1 + (r % 3) * 5;
2767 wpa_printf(MSG_DEBUG, "P2P: Own listen channel: %d", p2p.channel);
2769 if (wpa_s->conf->p2p_oper_reg_class &&
2770 wpa_s->conf->p2p_oper_channel) {
2771 p2p.op_reg_class = wpa_s->conf->p2p_oper_reg_class;
2772 p2p.op_channel = wpa_s->conf->p2p_oper_channel;
2773 p2p.cfg_op_channel = 1;
2774 wpa_printf(MSG_DEBUG, "P2P: Configured operating channel: "
2775 "%d:%d", p2p.op_reg_class, p2p.op_channel);
2778 p2p.op_reg_class = 81;
2780 * Use random operation channel from (1, 6, 11) if no other
2781 * preference is indicated.
2783 os_get_random((u8 *) &r, sizeof(r));
2784 p2p.op_channel = 1 + (r % 3) * 5;
2785 p2p.cfg_op_channel = 0;
2786 wpa_printf(MSG_DEBUG, "P2P: Random operating channel: "
2787 "%d:%d", p2p.op_reg_class, p2p.op_channel);
2789 if (wpa_s->conf->country[0] && wpa_s->conf->country[1]) {
2790 os_memcpy(p2p.country, wpa_s->conf->country, 2);
2791 p2p.country[2] = 0x04;
2793 os_memcpy(p2p.country, "XX\x04", 3);
2795 if (wpas_p2p_setup_channels(wpa_s, &p2p.channels)) {
2796 wpa_printf(MSG_ERROR, "P2P: Failed to configure supported "
2801 os_memcpy(p2p.pri_dev_type, wpa_s->conf->device_type,
2804 p2p.num_sec_dev_types = wpa_s->conf->num_sec_device_types;
2805 os_memcpy(p2p.sec_dev_type, wpa_s->conf->sec_device_type,
2806 p2p.num_sec_dev_types * WPS_DEV_TYPE_LEN);
2808 p2p.concurrent_operations = !!(wpa_s->drv_flags &
2809 WPA_DRIVER_FLAGS_P2P_CONCURRENT);
2811 p2p.max_peers = 100;
2813 if (wpa_s->conf->p2p_ssid_postfix) {
2814 p2p.ssid_postfix_len =
2815 os_strlen(wpa_s->conf->p2p_ssid_postfix);
2816 if (p2p.ssid_postfix_len > sizeof(p2p.ssid_postfix))
2817 p2p.ssid_postfix_len = sizeof(p2p.ssid_postfix);
2818 os_memcpy(p2p.ssid_postfix, wpa_s->conf->p2p_ssid_postfix,
2819 p2p.ssid_postfix_len);
2822 p2p.p2p_intra_bss = wpa_s->conf->p2p_intra_bss;
2825 if(wpa_s->drv_flags & WPA_DRIVER_FLAGS_MULTI_CHANNEL_CONCURRENT) {
2826 p2p.p2p_concurrency = P2P_MULTI_CHANNEL_CONCURRENT;
2827 wpa_printf(MSG_DEBUG, "P2P: Multi channel concurrency support");
2829 // Add support for WPA_DRIVER_FLAGS_P2P_CONCURRENT
2830 p2p.p2p_concurrency = P2P_SINGLE_CHANNEL_CONCURRENT;
2831 wpa_printf(MSG_DEBUG, "P2P: Single channel concurrency support");
2835 global->p2p = p2p_init(&p2p);
2836 if (global->p2p == NULL)
2838 global->p2p_init_wpa_s = wpa_s;
2840 for (i = 0; i < MAX_WPS_VENDOR_EXT; i++) {
2841 if (wpa_s->conf->wps_vendor_ext[i] == NULL)
2843 p2p_add_wps_vendor_extension(
2844 global->p2p, wpa_s->conf->wps_vendor_ext[i]);
2852 * wpas_p2p_deinit - Deinitialize per-interface P2P data
2853 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
2855 * This function deinitialize per-interface P2P data.
2857 void wpas_p2p_deinit(struct wpa_supplicant *wpa_s)
2859 if (wpa_s->driver && wpa_s->drv_priv)
2860 wpa_drv_probe_req_report(wpa_s, 0);
2862 if (wpa_s->go_params) {
2863 /* Clear any stored provisioning info */
2864 p2p_clear_provisioning_info(
2866 wpa_s->go_params->peer_device_addr);
2869 os_free(wpa_s->go_params);
2870 wpa_s->go_params = NULL;
2871 eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s, NULL);
2872 eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL);
2873 eloop_cancel_timeout(wpas_p2p_pd_before_join_timeout, wpa_s, NULL);
2874 wpa_s->p2p_long_listen = 0;
2875 eloop_cancel_timeout(wpas_p2p_long_listen_timeout, wpa_s, NULL);
2876 eloop_cancel_timeout(wpas_p2p_group_idle_timeout, wpa_s, NULL);
2877 wpas_p2p_remove_pending_group_interface(wpa_s);
2879 /* TODO: remove group interface from the driver if this wpa_s instance
2880 * is on top of a P2P group interface */
2885 * wpas_p2p_deinit_global - Deinitialize global P2P module
2886 * @global: Pointer to global data from wpa_supplicant_init()
2888 * This function deinitializes the global (per device) P2P module.
2890 void wpas_p2p_deinit_global(struct wpa_global *global)
2892 struct wpa_supplicant *wpa_s, *tmp;
2894 wpa_s = global->ifaces;
2896 wpas_p2p_service_flush(wpa_s);
2898 if (global->p2p == NULL)
2901 /* Remove remaining P2P group interfaces */
2902 while (wpa_s && wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE)
2903 wpa_s = wpa_s->next;
2905 tmp = global->ifaces;
2908 tmp->p2p_group_interface == NOT_P2P_GROUP_INTERFACE)) {
2913 /* Disconnect from the P2P group and deinit the interface */
2914 wpas_p2p_disconnect(tmp);
2918 * Deinit GO data on any possibly remaining interface (if main
2919 * interface is used as GO).
2921 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
2922 if (wpa_s->ap_iface)
2923 wpas_p2p_group_deinit(wpa_s);
2926 p2p_deinit(global->p2p);
2928 global->p2p_init_wpa_s = NULL;
2932 static int wpas_p2p_create_iface(struct wpa_supplicant *wpa_s)
2934 if (wpa_s->drv_flags &
2935 (WPA_DRIVER_FLAGS_P2P_DEDICATED_INTERFACE |
2936 WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P))
2937 return 1; /* P2P group requires a new interface in every case
2939 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_CONCURRENT))
2940 return 0; /* driver does not support concurrent operations */
2941 if (wpa_s->global->ifaces->next)
2942 return 1; /* more that one interface already in use */
2943 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
2944 return 1; /* this interface is already in use */
2949 static int wpas_p2p_start_go_neg(struct wpa_supplicant *wpa_s,
2950 const u8 *peer_addr,
2951 enum p2p_wps_method wps_method,
2952 int go_intent, const u8 *own_interface_addr,
2953 unsigned int force_freq, int persistent_group,
2954 struct wpa_ssid *ssid)
2956 if (persistent_group && wpa_s->conf->persistent_reconnect)
2957 persistent_group = 2;
2959 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT) {
2960 return wpa_drv_p2p_connect(wpa_s, peer_addr, wps_method,
2961 go_intent, own_interface_addr,
2962 force_freq, persistent_group);
2966 * Increase GO config timeout if HT40 is used since it takes some time
2967 * to scan channels for coex purposes before the BSS can be started.
2969 p2p_set_config_timeout(wpa_s->global->p2p,
2970 wpa_s->p2p_go_ht40 ? 255 : 100, 20);
2972 return p2p_connect(wpa_s->global->p2p, peer_addr, wps_method,
2973 go_intent, own_interface_addr, force_freq,
2974 persistent_group, ssid ? ssid->ssid : NULL,
2975 ssid ? ssid->ssid_len : 0,
2976 wpa_s->p2p_pd_before_go_neg);
2980 static int wpas_p2p_auth_go_neg(struct wpa_supplicant *wpa_s,
2981 const u8 *peer_addr,
2982 enum p2p_wps_method wps_method,
2983 int go_intent, const u8 *own_interface_addr,
2984 unsigned int force_freq, int persistent_group,
2985 struct wpa_ssid *ssid)
2987 if (persistent_group && wpa_s->conf->persistent_reconnect)
2988 persistent_group = 2;
2990 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT)
2993 return p2p_authorize(wpa_s->global->p2p, peer_addr, wps_method,
2994 go_intent, own_interface_addr, force_freq,
2995 persistent_group, ssid ? ssid->ssid : NULL,
2996 ssid ? ssid->ssid_len : 0);
3000 static void wpas_p2p_check_join_scan_limit(struct wpa_supplicant *wpa_s)
3002 wpa_s->p2p_join_scan_count++;
3003 wpa_printf(MSG_DEBUG, "P2P: Join scan attempt %d",
3004 wpa_s->p2p_join_scan_count);
3005 if (wpa_s->p2p_join_scan_count > P2P_MAX_JOIN_SCAN_ATTEMPTS) {
3006 wpa_printf(MSG_DEBUG, "P2P: Failed to find GO " MACSTR
3007 " for join operationg - stop join attempt",
3008 MAC2STR(wpa_s->pending_join_iface_addr));
3009 eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL);
3010 if (wpa_s->p2p_auto_pd) {
3011 wpa_s->p2p_auto_pd = 0;
3012 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_FAILURE
3013 " p2p_dev_addr=" MACSTR " status=N/A",
3014 MAC2STR(wpa_s->pending_join_dev_addr));
3017 wpa_msg(wpa_s->parent, MSG_INFO,
3018 P2P_EVENT_GROUP_FORMATION_FAILURE);
3023 static void wpas_p2p_pd_before_join_timeout(void *eloop_ctx, void *timeout_ctx)
3025 struct wpa_supplicant *wpa_s = eloop_ctx;
3026 if (!wpa_s->pending_pd_before_join)
3029 * Provision Discovery Response may have been lost - try to connect
3030 * anyway since we do not need any information from this PD.
3032 wpa_printf(MSG_DEBUG, "P2P: PD timeout for join-existing-group - "
3033 "try to connect anyway");
3034 wpas_p2p_join_start(wpa_s);
3038 static int wpas_check_freq_conflict(struct wpa_supplicant *wpa_s, int freq)
3040 struct wpa_supplicant *iface;
3044 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_MULTI_CHANNEL_CONCURRENT)
3047 for (iface = wpa_s->global->ifaces; iface; iface = iface->next) {
3048 if (!wpas_p2p_create_iface(wpa_s) && iface == wpa_s)
3050 if (iface->current_ssid == NULL || iface->assoc_freq == 0)
3052 if (iface->current_ssid->mode == WPAS_MODE_AP ||
3053 iface->current_ssid->mode == WPAS_MODE_P2P_GO)
3054 shared_freq = iface->current_ssid->frequency;
3055 else if (wpa_drv_get_bssid(iface, bssid) == 0)
3056 shared_freq = iface->assoc_freq;
3060 if (shared_freq && freq != shared_freq) {
3061 wpa_printf(MSG_DEBUG, "P2P: Frequency conflict - %s "
3062 "connected on %d MHz - new connection on "
3063 "%d MHz", iface->ifname, shared_freq, freq);
3068 shared_freq = wpa_drv_shared_freq(wpa_s);
3069 if (shared_freq > 0 && shared_freq != freq) {
3070 wpa_printf(MSG_DEBUG, "P2P: Frequency conflict - shared "
3071 "virtual interface connected on %d MHz - new "
3072 "connection on %d MHz", shared_freq, freq);
3080 static int wpas_p2p_peer_go(struct wpa_supplicant *wpa_s,
3081 const u8 *peer_dev_addr)
3083 struct wpa_bss *bss;
3086 bss = wpa_bss_get_p2p_dev_addr(wpa_s, peer_dev_addr);
3089 if (bss->last_update_idx < wpa_s->bss_update_idx) {
3090 wpa_printf(MSG_DEBUG, "P2P: Peer BSS entry not updated in the "
3095 updated = os_time_before(&wpa_s->p2p_auto_started, &bss->last_update);
3096 wpa_printf(MSG_DEBUG, "P2P: Current BSS entry for peer updated at "
3097 "%ld.%06ld (%supdated in last scan)",
3098 bss->last_update.sec, bss->last_update.usec,
3099 updated ? "": "not ");
3105 static void wpas_p2p_scan_res_join(struct wpa_supplicant *wpa_s,
3106 struct wpa_scan_results *scan_res)
3108 struct wpa_bss *bss;
3110 u8 iface_addr[ETH_ALEN];
3112 eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL);
3114 if (wpa_s->global->p2p_disabled)
3117 wpa_printf(MSG_DEBUG, "P2P: Scan results received (%d BSS) for %sjoin",
3118 scan_res ? (int) scan_res->num : -1,
3119 wpa_s->p2p_auto_join ? "auto_" : "");
3122 wpas_p2p_scan_res_handler(wpa_s, scan_res);
3124 if (wpa_s->p2p_auto_pd) {
3125 int join = wpas_p2p_peer_go(wpa_s,
3126 wpa_s->pending_join_dev_addr);
3128 wpa_s->auto_pd_scan_retry < P2P_AUTO_PD_SCAN_ATTEMPTS) {
3129 wpa_s->auto_pd_scan_retry++;
3130 bss = wpa_bss_get_bssid(wpa_s,
3131 wpa_s->pending_join_dev_addr);
3134 wpa_printf(MSG_DEBUG, "P2P: Scan retry %d for "
3135 "the peer " MACSTR " at %d MHz",
3136 wpa_s->auto_pd_scan_retry,
3138 pending_join_dev_addr),
3140 wpas_p2p_join_scan_req(wpa_s, freq);
3148 wpa_s->p2p_auto_pd = 0;
3149 wpa_s->pending_pd_use = join ? AUTO_PD_JOIN : AUTO_PD_GO_NEG;
3150 wpa_printf(MSG_DEBUG, "P2P: Auto PD with " MACSTR " join=%d",
3151 MAC2STR(wpa_s->pending_join_dev_addr), join);
3152 if (p2p_prov_disc_req(wpa_s->global->p2p,
3153 wpa_s->pending_join_dev_addr,
3154 wpa_s->pending_pd_config_methods, join,
3156 wpa_s->p2p_auto_pd = 0;
3157 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_FAILURE
3158 " p2p_dev_addr=" MACSTR " status=N/A",
3159 MAC2STR(wpa_s->pending_join_dev_addr));
3164 if (wpa_s->p2p_auto_join) {
3165 int join = wpas_p2p_peer_go(wpa_s,
3166 wpa_s->pending_join_dev_addr);
3168 wpa_printf(MSG_DEBUG, "P2P: Peer was not found to be "
3169 "running a GO -> use GO Negotiation");
3170 wpas_p2p_connect(wpa_s, wpa_s->pending_join_dev_addr,
3171 wpa_s->p2p_pin, wpa_s->p2p_wps_method,
3172 wpa_s->p2p_persistent_group, 0, 0, 0,
3173 wpa_s->p2p_go_intent,
3174 wpa_s->p2p_connect_freq,
3175 wpa_s->p2p_persistent_id,
3176 wpa_s->p2p_pd_before_go_neg,
3177 wpa_s->p2p_go_ht40);
3181 wpa_printf(MSG_DEBUG, "P2P: Peer was found running GO%s -> "
3182 "try to join the group", join ? "" :
3185 wpa_s->p2p_fallback_to_go_neg = 1;
3188 freq = p2p_get_oper_freq(wpa_s->global->p2p,
3189 wpa_s->pending_join_iface_addr);
3191 p2p_get_interface_addr(wpa_s->global->p2p,
3192 wpa_s->pending_join_dev_addr,
3194 os_memcmp(iface_addr, wpa_s->pending_join_dev_addr, ETH_ALEN) != 0)
3196 wpa_printf(MSG_DEBUG, "P2P: Overwrite pending interface "
3197 "address for join from " MACSTR " to " MACSTR
3198 " based on newly discovered P2P peer entry",
3199 MAC2STR(wpa_s->pending_join_iface_addr),
3200 MAC2STR(iface_addr));
3201 os_memcpy(wpa_s->pending_join_iface_addr, iface_addr,
3204 freq = p2p_get_oper_freq(wpa_s->global->p2p,
3205 wpa_s->pending_join_iface_addr);
3208 wpa_printf(MSG_DEBUG, "P2P: Target GO operating frequency "
3209 "from P2P peer table: %d MHz", freq);
3211 bss = wpa_bss_get_bssid(wpa_s, wpa_s->pending_join_iface_addr);
3214 wpa_printf(MSG_DEBUG, "P2P: Target GO operating frequency "
3215 "from BSS table: %d MHz", freq);
3220 if (wpas_check_freq_conflict(wpa_s, freq) > 0) {
3221 wpa_msg(wpa_s->parent, MSG_INFO,
3222 P2P_EVENT_GROUP_FORMATION_FAILURE
3223 "reason=FREQ_CONFLICT");
3227 wpa_printf(MSG_DEBUG, "P2P: Send Provision Discovery Request "
3228 "prior to joining an existing group (GO " MACSTR
3230 MAC2STR(wpa_s->pending_join_dev_addr), freq);
3231 wpa_s->pending_pd_before_join = 1;
3233 switch (wpa_s->pending_join_wps_method) {
3234 case WPS_PIN_DISPLAY:
3235 method = WPS_CONFIG_KEYPAD;
3237 case WPS_PIN_KEYPAD:
3238 method = WPS_CONFIG_DISPLAY;
3241 method = WPS_CONFIG_PUSHBUTTON;
3248 if ((p2p_get_provisioning_info(wpa_s->global->p2p,
3249 wpa_s->pending_join_dev_addr) ==
3252 * We have already performed provision discovery for
3253 * joining the group. Proceed directly to join
3254 * operation without duplicated provision discovery. */
3255 wpa_printf(MSG_DEBUG, "P2P: Provision discovery "
3256 "with " MACSTR " already done - proceed to "
3258 MAC2STR(wpa_s->pending_join_dev_addr));
3259 wpa_s->pending_pd_before_join = 0;
3263 if (p2p_prov_disc_req(wpa_s->global->p2p,
3264 wpa_s->pending_join_dev_addr, method, 1,
3266 wpa_printf(MSG_DEBUG, "P2P: Failed to send Provision "
3267 "Discovery Request before joining an "
3269 wpa_s->pending_pd_before_join = 0;
3274 * Actual join operation will be started from the Action frame
3275 * TX status callback (if no ACK is received) or when the
3276 * Provision Discovery Response is received. Use a short
3277 * timeout as a backup mechanism should the Provision Discovery
3278 * Response be lost for any reason.
3280 eloop_cancel_timeout(wpas_p2p_pd_before_join_timeout, wpa_s,
3282 eloop_register_timeout(2, 0, wpas_p2p_pd_before_join_timeout,
3287 wpa_printf(MSG_DEBUG, "P2P: Failed to find BSS/GO - try again later");
3288 eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL);
3289 eloop_register_timeout(1, 0, wpas_p2p_join_scan, wpa_s, NULL);
3290 wpas_p2p_check_join_scan_limit(wpa_s);
3294 /* Start join operation immediately */
3295 wpas_p2p_join_start(wpa_s);
3299 static void wpas_p2p_join_scan_req(struct wpa_supplicant *wpa_s, int freq)
3302 struct wpa_driver_scan_params params;
3303 struct wpabuf *wps_ie, *ies;
3305 int freqs[2] = { 0, 0 };
3309 /* If freq is not provided, check the operating freq of the GO and do a
3310 * a directed scan to save time
3313 freq = (oper_freq = p2p_get_oper_freq(wpa_s->global->p2p,
3314 wpa_s->pending_join_iface_addr) == -1) ? 0 : oper_freq;
3317 os_memset(¶ms, 0, sizeof(params));
3319 /* P2P Wildcard SSID */
3320 params.num_ssids = 1;
3321 params.ssids[0].ssid = (u8 *) P2P_WILDCARD_SSID;
3322 params.ssids[0].ssid_len = P2P_WILDCARD_SSID_LEN;
3324 wpa_s->wps->dev.p2p = 1;
3325 wps_ie = wps_build_probe_req_ie(DEV_PW_DEFAULT, &wpa_s->wps->dev,
3326 wpa_s->wps->uuid, WPS_REQ_ENROLLEE, 0,
3328 if (wps_ie == NULL) {
3329 wpas_p2p_scan_res_join(wpa_s, NULL);
3333 ielen = p2p_scan_ie_buf_len(wpa_s->global->p2p);
3334 ies = wpabuf_alloc(wpabuf_len(wps_ie) + ielen);
3336 wpabuf_free(wps_ie);
3337 wpas_p2p_scan_res_join(wpa_s, NULL);
3340 wpabuf_put_buf(ies, wps_ie);
3341 wpabuf_free(wps_ie);
3343 p2p_scan_ie(wpa_s->global->p2p, ies, NULL);
3345 params.p2p_probe = 1;
3346 params.extra_ies = wpabuf_head(ies);
3347 params.extra_ies_len = wpabuf_len(ies);
3350 params.freqs = freqs;
3354 * Run a scan to update BSS table and start Provision Discovery once
3355 * the new scan results become available.
3357 ret = wpa_drv_scan(wpa_s, ¶ms);
3359 wpa_s->scan_res_handler = wpas_p2p_scan_res_join;
3364 wpa_printf(MSG_DEBUG, "P2P: Failed to start scan for join - "
3366 eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL);
3367 eloop_register_timeout(1, 0, wpas_p2p_join_scan, wpa_s, NULL);
3368 wpas_p2p_check_join_scan_limit(wpa_s);
3373 static void wpas_p2p_join_scan(void *eloop_ctx, void *timeout_ctx)
3375 struct wpa_supplicant *wpa_s = eloop_ctx;
3376 wpas_p2p_join_scan_req(wpa_s, 0);
3380 static int wpas_p2p_join(struct wpa_supplicant *wpa_s, const u8 *iface_addr,
3381 const u8 *dev_addr, enum p2p_wps_method wps_method,
3384 wpa_printf(MSG_DEBUG, "P2P: Request to join existing group (iface "
3385 MACSTR " dev " MACSTR ")%s",
3386 MAC2STR(iface_addr), MAC2STR(dev_addr),
3387 auto_join ? " (auto_join)" : "");
3389 wpa_s->p2p_auto_pd = 0;
3390 wpa_s->p2p_auto_join = !!auto_join;
3391 os_memcpy(wpa_s->pending_join_iface_addr, iface_addr, ETH_ALEN);
3392 os_memcpy(wpa_s->pending_join_dev_addr, dev_addr, ETH_ALEN);
3393 wpa_s->pending_join_wps_method = wps_method;
3395 /* Make sure we are not running find during connection establishment */
3396 wpas_p2p_stop_find(wpa_s);
3398 wpa_s->p2p_join_scan_count = 0;
3399 wpas_p2p_join_scan(wpa_s, NULL);
3404 static int wpas_p2p_join_start(struct wpa_supplicant *wpa_s)
3406 struct wpa_supplicant *group;
3407 struct p2p_go_neg_results res;
3408 struct wpa_bss *bss;
3410 eloop_cancel_timeout(wpas_p2p_pd_before_join_timeout, wpa_s, NULL);
3411 group = wpas_p2p_get_group_iface(wpa_s, 0, 0);
3414 if (group != wpa_s) {
3415 os_memcpy(group->p2p_pin, wpa_s->p2p_pin,
3416 sizeof(group->p2p_pin));
3417 group->p2p_wps_method = wpa_s->p2p_wps_method;
3420 group->p2p_in_provisioning = 1;
3421 group->p2p_fallback_to_go_neg = wpa_s->p2p_fallback_to_go_neg;
3423 os_memset(&res, 0, sizeof(res));
3424 os_memcpy(res.peer_interface_addr, wpa_s->pending_join_iface_addr,
3426 res.wps_method = wpa_s->pending_join_wps_method;
3427 bss = wpa_bss_get_bssid(wpa_s, wpa_s->pending_join_iface_addr);
3429 res.freq = bss->freq;
3430 res.ssid_len = bss->ssid_len;
3431 os_memcpy(res.ssid, bss->ssid, bss->ssid_len);
3434 if (wpa_s->off_channel_freq || wpa_s->roc_waiting_drv_freq) {
3435 wpa_printf(MSG_DEBUG, "P2P: Cancel remain-on-channel prior to "
3437 wpa_drv_cancel_remain_on_channel(wpa_s);
3438 wpa_s->off_channel_freq = 0;
3439 wpa_s->roc_waiting_drv_freq = 0;
3441 wpas_start_wps_enrollee(group, &res);
3444 * Allow a longer timeout for join-a-running-group than normal 15
3445 * second group formation timeout since the GO may not have authorized
3446 * our connection yet.
3448 eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s, NULL);
3449 eloop_register_timeout(60, 0, wpas_p2p_group_formation_timeout,
3457 * wpas_p2p_connect - Request P2P Group Formation to be started
3458 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
3459 * @peer_addr: Address of the peer P2P Device
3460 * @pin: PIN to use during provisioning or %NULL to indicate PBC mode
3461 * @persistent_group: Whether to create a persistent group
3462 * @auto_join: Whether to select join vs. GO Negotiation automatically
3463 * @join: Whether to join an existing group (as a client) instead of starting
3464 * Group Owner negotiation; @peer_addr is BSSID in that case
3465 * @auth: Whether to only authorize the connection instead of doing that and
3466 * initiating Group Owner negotiation
3467 * @go_intent: GO Intent or -1 to use default
3468 * @freq: Frequency for the group or 0 for auto-selection
3469 * @persistent_id: Persistent group credentials to use for forcing GO
3470 * parameters or -1 to generate new values (SSID/passphrase)
3471 * @pd: Whether to send Provision Discovery prior to GO Negotiation as an
3472 * interoperability workaround when initiating group formation
3473 * @ht40: Start GO with 40 MHz channel width
3474 * Returns: 0 or new PIN (if pin was %NULL) on success, -1 on unspecified
3475 * failure, -2 on failure due to channel not currently available,
3476 * -3 if forced channel is not supported
3478 int wpas_p2p_connect(struct wpa_supplicant *wpa_s, const u8 *peer_addr,
3479 const char *pin, enum p2p_wps_method wps_method,
3480 int persistent_group, int auto_join, int join, int auth,
3481 int go_intent, int freq, int persistent_id, int pd,
3484 int force_freq = 0, oper_freq = 0;
3487 enum wpa_driver_if_type iftype;
3489 struct wpa_ssid *ssid = NULL;
3491 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
3494 if (persistent_id >= 0) {
3495 ssid = wpa_config_get_network(wpa_s->conf, persistent_id);
3496 if (ssid == NULL || ssid->disabled != 2 ||
3497 ssid->mode != WPAS_MODE_P2P_GO)
3502 go_intent = wpa_s->conf->p2p_go_intent;
3505 wpa_s->p2p_long_listen = 0;
3507 wpa_s->p2p_wps_method = wps_method;
3508 wpa_s->p2p_persistent_group = !!persistent_group;
3509 wpa_s->p2p_persistent_id = persistent_id;
3510 wpa_s->p2p_go_intent = go_intent;
3511 wpa_s->p2p_connect_freq = freq;
3512 wpa_s->p2p_fallback_to_go_neg = 0;
3513 wpa_s->p2p_pd_before_go_neg = !!pd;
3514 wpa_s->p2p_go_ht40 = !!ht40;
3517 os_strlcpy(wpa_s->p2p_pin, pin, sizeof(wpa_s->p2p_pin));
3518 else if (wps_method == WPS_PIN_DISPLAY) {
3519 ret = wps_generate_pin();
3520 os_snprintf(wpa_s->p2p_pin, sizeof(wpa_s->p2p_pin), "%08d",
3522 wpa_printf(MSG_DEBUG, "P2P: Randomly generated PIN: %s",
3525 wpa_s->p2p_pin[0] = '\0';
3527 if (join || auto_join) {
3528 u8 iface_addr[ETH_ALEN], dev_addr[ETH_ALEN];
3530 wpa_printf(MSG_DEBUG, "P2P: Authorize invitation to "
3531 "connect a running group from " MACSTR,
3532 MAC2STR(peer_addr));
3533 os_memcpy(wpa_s->p2p_auth_invite, peer_addr, ETH_ALEN);
3536 os_memcpy(dev_addr, peer_addr, ETH_ALEN);
3537 if (p2p_get_interface_addr(wpa_s->global->p2p, peer_addr,
3539 os_memcpy(iface_addr, peer_addr, ETH_ALEN);
3540 p2p_get_dev_addr(wpa_s->global->p2p, peer_addr,
3544 os_get_time(&wpa_s->p2p_auto_started);
3545 wpa_printf(MSG_DEBUG, "P2P: Auto join started at "
3547 wpa_s->p2p_auto_started.sec,
3548 wpa_s->p2p_auto_started.usec);
3550 if (wpas_p2p_join(wpa_s, iface_addr, dev_addr, wps_method,
3556 if (wpa_s->current_ssid && wpa_drv_get_bssid(wpa_s, bssid) == 0 &&
3558 oper_freq = wpa_s->assoc_freq;
3560 oper_freq = wpa_drv_shared_freq(wpa_s);
3566 if (!p2p_supported_freq(wpa_s->global->p2p, freq)) {
3567 wpa_printf(MSG_DEBUG, "P2P: The forced channel "
3568 "(%u MHz) is not supported for P2P uses",
3573 if (oper_freq > 0 && freq != oper_freq &&
3574 !(wpa_s->drv_flags &
3575 WPA_DRIVER_FLAGS_MULTI_CHANNEL_CONCURRENT)) {
3576 wpa_printf(MSG_DEBUG, "P2P: Cannot start P2P group "
3577 "on %u MHz while connected on another "
3578 "channel (%u MHz)", freq, oper_freq);
3581 wpa_printf(MSG_DEBUG, "P2P: Trying to force us to use the "
3582 "requested channel (%u MHz)", freq);
3584 } else if (oper_freq > 0 &&
3585 !p2p_supported_freq(wpa_s->global->p2p, oper_freq)) {
3586 if (!(wpa_s->drv_flags &
3587 WPA_DRIVER_FLAGS_MULTI_CHANNEL_CONCURRENT)) {
3588 wpa_printf(MSG_DEBUG, "P2P: Cannot start P2P group "
3589 "while connected on non-P2P supported "
3590 "channel (%u MHz)", oper_freq);
3593 wpa_printf(MSG_DEBUG, "P2P: Current operating channel "
3594 "(%u MHz) not available for P2P - try to use "
3595 "another channel", oper_freq);
3597 } else if (oper_freq > 0) {
3598 wpa_printf(MSG_DEBUG, "P2P: Trying to force us to use the "
3599 "channel we are already using (%u MHz) on another "
3600 "interface", oper_freq);
3601 force_freq = oper_freq;
3604 wpa_s->create_p2p_iface = wpas_p2p_create_iface(wpa_s);
3606 if (wpa_s->create_p2p_iface) {
3607 /* Prepare to add a new interface for the group */
3608 iftype = WPA_IF_P2P_GROUP;
3609 if (go_intent == 15)
3610 iftype = WPA_IF_P2P_GO;
3611 if (wpas_p2p_add_group_interface(wpa_s, iftype) < 0) {
3612 wpa_printf(MSG_ERROR, "P2P: Failed to allocate a new "
3613 "interface for the group");
3617 if_addr = wpa_s->pending_interface_addr;
3619 if_addr = wpa_s->own_addr;
3622 if (wpas_p2p_auth_go_neg(wpa_s, peer_addr, wps_method,
3624 force_freq, persistent_group, ssid) <
3630 if (wpas_p2p_start_go_neg(wpa_s, peer_addr, wps_method,
3631 go_intent, if_addr, force_freq,
3632 persistent_group, ssid) < 0) {
3633 if (wpa_s->create_p2p_iface)
3634 wpas_p2p_remove_pending_group_interface(wpa_s);
3642 * wpas_p2p_remain_on_channel_cb - Indication of remain-on-channel start
3643 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
3644 * @freq: Frequency of the channel in MHz
3645 * @duration: Duration of the stay on the channel in milliseconds
3647 * This callback is called when the driver indicates that it has started the
3648 * requested remain-on-channel duration.
3650 void wpas_p2p_remain_on_channel_cb(struct wpa_supplicant *wpa_s,
3651 unsigned int freq, unsigned int duration)
3653 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
3655 if (wpa_s->off_channel_freq == wpa_s->pending_listen_freq) {
3656 p2p_listen_cb(wpa_s->global->p2p, wpa_s->pending_listen_freq,
3657 wpa_s->pending_listen_duration);
3658 wpa_s->pending_listen_freq = 0;
3663 static int wpas_p2p_listen_start(struct wpa_supplicant *wpa_s,
3664 unsigned int timeout)
3666 /* Limit maximum Listen state time based on driver limitation. */
3667 if (timeout > wpa_s->max_remain_on_chan)
3668 timeout = wpa_s->max_remain_on_chan;
3670 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT)
3671 return wpa_drv_p2p_listen(wpa_s, timeout);
3673 return p2p_listen(wpa_s->global->p2p, timeout);
3678 * wpas_p2p_cancel_remain_on_channel_cb - Remain-on-channel timeout
3679 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
3680 * @freq: Frequency of the channel in MHz
3682 * This callback is called when the driver indicates that a remain-on-channel
3683 * operation has been completed, i.e., the duration on the requested channel
3686 void wpas_p2p_cancel_remain_on_channel_cb(struct wpa_supplicant *wpa_s,
3689 wpa_printf(MSG_DEBUG, "P2P: Cancel remain-on-channel callback "
3690 "(p2p_long_listen=%d ms pending_action_tx=%p)",
3691 wpa_s->p2p_long_listen, wpa_s->pending_action_tx);
3692 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
3694 if (p2p_listen_end(wpa_s->global->p2p, freq) > 0)
3695 return; /* P2P module started a new operation */
3696 if (wpa_s->pending_action_tx)
3698 if (wpa_s->p2p_long_listen > 0)
3699 wpa_s->p2p_long_listen -= wpa_s->max_remain_on_chan;
3700 if (wpa_s->p2p_long_listen > 0) {
3701 wpa_printf(MSG_DEBUG, "P2P: Continuing long Listen state");
3702 wpas_p2p_listen_start(wpa_s, wpa_s->p2p_long_listen);
3708 * wpas_p2p_group_remove - Remove a P2P group
3709 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
3710 * @ifname: Network interface name of the group interface or "*" to remove all
3712 * Returns: 0 on success, -1 on failure
3714 * This function is used to remove a P2P group. This can be used to disconnect
3715 * from a group in which the local end is a P2P Client or to end a P2P Group in
3716 * case the local end is the Group Owner. If a virtual network interface was
3717 * created for this group, that interface will be removed. Otherwise, only the
3718 * configured P2P group network will be removed from the interface.
3720 int wpas_p2p_group_remove(struct wpa_supplicant *wpa_s, const char *ifname)
3722 struct wpa_global *global = wpa_s->global;
3724 if (os_strcmp(ifname, "*") == 0) {
3725 struct wpa_supplicant *prev;
3726 wpa_s = global->ifaces;
3729 wpa_s = wpa_s->next;
3730 wpas_p2p_disconnect(prev);
3735 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
3736 if (os_strcmp(wpa_s->ifname, ifname) == 0)
3740 return wpas_p2p_disconnect(wpa_s);
3744 static int wpas_p2p_init_go_params(struct wpa_supplicant *wpa_s,
3745 struct p2p_go_neg_results *params,
3751 os_memset(params, 0, sizeof(*params));
3752 params->role_go = 1;
3753 params->ht40 = ht40;
3755 wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on forced "
3756 "frequency %d MHz", freq);
3757 params->freq = freq;
3758 } else if (wpa_s->conf->p2p_oper_reg_class == 81 &&
3759 wpa_s->conf->p2p_oper_channel >= 1 &&
3760 wpa_s->conf->p2p_oper_channel <= 11) {
3761 params->freq = 2407 + 5 * wpa_s->conf->p2p_oper_channel;
3762 wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on configured "
3763 "frequency %d MHz", params->freq);
3764 } else if (wpa_s->conf->p2p_oper_reg_class == 115 ||
3765 wpa_s->conf->p2p_oper_reg_class == 124) {
3766 params->freq = 5000 + 5 * wpa_s->conf->p2p_oper_channel;
3767 wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on configured "
3768 "frequency %d MHz", params->freq);
3769 } else if (wpa_s->conf->p2p_oper_channel == 0 &&
3770 wpa_s->best_overall_freq > 0 &&
3771 p2p_supported_freq(wpa_s->global->p2p,
3772 wpa_s->best_overall_freq)) {
3773 params->freq = wpa_s->best_overall_freq;
3774 wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on best overall "
3775 "channel %d MHz", params->freq);
3776 } else if (wpa_s->conf->p2p_oper_channel == 0 &&
3777 wpa_s->best_24_freq > 0 &&
3778 p2p_supported_freq(wpa_s->global->p2p,
3779 wpa_s->best_24_freq)) {
3780 params->freq = wpa_s->best_24_freq;
3781 wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on best 2.4 GHz "
3782 "channel %d MHz", params->freq);
3783 } else if (wpa_s->conf->p2p_oper_channel == 0 &&
3784 wpa_s->best_5_freq > 0 &&
3785 p2p_supported_freq(wpa_s->global->p2p,
3786 wpa_s->best_5_freq)) {
3787 params->freq = wpa_s->best_5_freq;
3788 wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on best 5 GHz "
3789 "channel %d MHz", params->freq);
3792 for (chan = 0; chan < 11; chan++) {
3793 params->freq = 2412 + chan * 5;
3794 if (!wpas_p2p_disallowed_freq(wpa_s->global,
3799 wpa_printf(MSG_DEBUG, "P2P: No 2.4 GHz channel "
3803 wpa_printf(MSG_DEBUG, "P2P: Set GO freq %d MHz (no preference "
3804 "known)", params->freq);
3807 if (wpa_s->current_ssid && wpa_drv_get_bssid(wpa_s, bssid) == 0 &&
3808 wpa_s->assoc_freq && !freq) {
3809 wpa_printf(MSG_DEBUG, "P2P: Force GO on the channel we are "
3811 params->freq = wpa_s->assoc_freq;
3814 res = wpa_drv_shared_freq(wpa_s);
3815 if (res > 0 && !freq) {
3816 wpa_printf(MSG_DEBUG, "P2P: Force GO on the channel we are "
3817 "already using on a shared interface");
3819 } else if (res > 0 && freq != res &&
3820 !(wpa_s->drv_flags &
3821 WPA_DRIVER_FLAGS_MULTI_CHANNEL_CONCURRENT)) {
3822 wpa_printf(MSG_DEBUG, "P2P: Cannot start P2P group on %u MHz "
3823 "while connected on another channel (%u MHz)",
3832 static struct wpa_supplicant *
3833 wpas_p2p_get_group_iface(struct wpa_supplicant *wpa_s, int addr_allocated,
3836 struct wpa_supplicant *group_wpa_s;
3838 if (!wpas_p2p_create_iface(wpa_s)) {
3839 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Use same interface for group "
3844 if (wpas_p2p_add_group_interface(wpa_s, go ? WPA_IF_P2P_GO :
3845 WPA_IF_P2P_CLIENT) < 0) {
3846 wpa_msg(wpa_s, MSG_ERROR, "P2P: Failed to add group interface");
3849 group_wpa_s = wpas_p2p_init_group_interface(wpa_s, go);
3850 if (group_wpa_s == NULL) {
3851 wpa_msg(wpa_s, MSG_ERROR, "P2P: Failed to initialize group "
3853 wpas_p2p_remove_pending_group_interface(wpa_s);
3857 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Use separate group interface %s",
3858 group_wpa_s->ifname);
3864 * wpas_p2p_group_add - Add a new P2P group with local end as Group Owner
3865 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
3866 * @persistent_group: Whether to create a persistent group
3867 * @freq: Frequency for the group or 0 to indicate no hardcoding
3868 * Returns: 0 on success, -1 on failure
3870 * This function creates a new P2P group with the local end as the Group Owner,
3871 * i.e., without using Group Owner Negotiation.
3873 int wpas_p2p_group_add(struct wpa_supplicant *wpa_s, int persistent_group,
3876 struct p2p_go_neg_results params;
3879 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
3882 /* Make sure we are not running find during connection establishment */
3883 wpa_printf(MSG_DEBUG, "P2P: Stop any on-going P2P FIND");
3884 wpas_p2p_stop_find(wpa_s);
3887 wpa_printf(MSG_DEBUG, "P2P: Request to start GO on 2.4 GHz "
3889 if (wpa_s->best_24_freq > 0 &&
3890 p2p_supported_freq(wpa_s->global->p2p,
3891 wpa_s->best_24_freq)) {
3892 freq = wpa_s->best_24_freq;
3893 wpa_printf(MSG_DEBUG, "P2P: Use best 2.4 GHz band "
3894 "channel: %d MHz", freq);
3896 os_get_random((u8 *) &r, sizeof(r));
3897 freq = 2412 + (r % 3) * 25;
3898 wpa_printf(MSG_DEBUG, "P2P: Use random 2.4 GHz band "
3899 "channel: %d MHz", freq);
3904 wpa_printf(MSG_DEBUG, "P2P: Request to start GO on 5 GHz "
3906 if (wpa_s->best_5_freq > 0 &&
3907 p2p_supported_freq(wpa_s->global->p2p,
3908 wpa_s->best_5_freq)) {
3909 freq = wpa_s->best_5_freq;
3910 wpa_printf(MSG_DEBUG, "P2P: Use best 5 GHz band "
3911 "channel: %d MHz", freq);
3913 os_get_random((u8 *) &r, sizeof(r));
3914 freq = 5180 + (r % 4) * 20;
3915 if (!p2p_supported_freq(wpa_s->global->p2p, freq)) {
3916 wpa_printf(MSG_DEBUG, "P2P: Could not select "
3917 "5 GHz channel for P2P group");
3920 wpa_printf(MSG_DEBUG, "P2P: Use random 5 GHz band "
3921 "channel: %d MHz", freq);
3925 if (freq > 0 && !p2p_supported_freq(wpa_s->global->p2p, freq)) {
3926 wpa_printf(MSG_DEBUG, "P2P: The forced channel for GO "
3927 "(%u MHz) is not supported for P2P uses",
3932 if (wpas_p2p_init_go_params(wpa_s, ¶ms, freq, ht40))
3935 !p2p_supported_freq(wpa_s->global->p2p, params.freq)) {
3936 wpa_printf(MSG_DEBUG, "P2P: The selected channel for GO "
3937 "(%u MHz) is not supported for P2P uses",
3941 p2p_go_params(wpa_s->global->p2p, ¶ms);
3942 params.persistent_group = persistent_group;
3944 wpa_s = wpas_p2p_get_group_iface(wpa_s, 0, 1);
3947 wpas_start_wps_go(wpa_s, ¶ms, 0);
3953 static int wpas_start_p2p_client(struct wpa_supplicant *wpa_s,
3954 struct wpa_ssid *params, int addr_allocated)
3956 struct wpa_ssid *ssid;
3958 wpa_s = wpas_p2p_get_group_iface(wpa_s, addr_allocated, 0);
3962 wpa_supplicant_ap_deinit(wpa_s);
3964 ssid = wpa_config_add_network(wpa_s->conf);
3967 wpa_config_set_network_defaults(ssid);
3968 ssid->temporary = 1;
3969 ssid->proto = WPA_PROTO_RSN;
3970 ssid->pairwise_cipher = WPA_CIPHER_CCMP;
3971 ssid->group_cipher = WPA_CIPHER_CCMP;
3972 ssid->key_mgmt = WPA_KEY_MGMT_PSK;
3973 ssid->ssid = os_malloc(params->ssid_len);
3974 if (ssid->ssid == NULL) {
3975 wpa_config_remove_network(wpa_s->conf, ssid->id);
3978 os_memcpy(ssid->ssid, params->ssid, params->ssid_len);
3979 ssid->ssid_len = params->ssid_len;
3980 ssid->p2p_group = 1;
3981 ssid->export_keys = 1;
3982 if (params->psk_set) {
3983 os_memcpy(ssid->psk, params->psk, 32);
3986 if (params->passphrase)
3987 ssid->passphrase = os_strdup(params->passphrase);
3989 wpa_supplicant_select_network(wpa_s, ssid);
3991 wpa_s->show_group_started = 1;
3997 int wpas_p2p_group_add_persistent(struct wpa_supplicant *wpa_s,
3998 struct wpa_ssid *ssid, int addr_allocated,
4001 struct p2p_go_neg_results params;
4004 if (ssid->disabled != 2 || ssid->ssid == NULL)
4007 if (wpas_get_p2p_group(wpa_s, ssid->ssid, ssid->ssid_len, &go) &&
4008 go == (ssid->mode == WPAS_MODE_P2P_GO)) {
4009 wpa_printf(MSG_DEBUG, "P2P: Requested persistent group is "
4014 /* Make sure we are not running find during connection establishment */
4015 wpas_p2p_stop_find(wpa_s);
4017 wpa_s->p2p_fallback_to_go_neg = 0;
4019 if (ssid->mode == WPAS_MODE_INFRA)
4020 return wpas_start_p2p_client(wpa_s, ssid, addr_allocated);
4022 if (ssid->mode != WPAS_MODE_P2P_GO)
4025 if (wpas_p2p_init_go_params(wpa_s, ¶ms, freq, ht40))
4029 if (ssid->passphrase == NULL ||
4030 os_strlen(ssid->passphrase) >= sizeof(params.passphrase)) {
4031 wpa_printf(MSG_DEBUG, "P2P: Invalid passphrase in persistent "
4035 os_strlcpy(params.passphrase, ssid->passphrase,
4036 sizeof(params.passphrase));
4037 os_memcpy(params.ssid, ssid->ssid, ssid->ssid_len);
4038 params.ssid_len = ssid->ssid_len;
4039 params.persistent_group = 1;
4041 wpa_s = wpas_p2p_get_group_iface(wpa_s, addr_allocated, 1);
4045 wpas_start_wps_go(wpa_s, ¶ms, 0);
4051 static void wpas_p2p_ie_update(void *ctx, struct wpabuf *beacon_ies,
4052 struct wpabuf *proberesp_ies)
4054 struct wpa_supplicant *wpa_s = ctx;
4055 if (wpa_s->ap_iface) {
4056 struct hostapd_data *hapd = wpa_s->ap_iface->bss[0];
4057 if (!(hapd->conf->p2p & P2P_GROUP_OWNER)) {
4058 wpabuf_free(beacon_ies);
4059 wpabuf_free(proberesp_ies);
4063 wpabuf_free(hapd->p2p_beacon_ie);
4064 hapd->p2p_beacon_ie = beacon_ies;
4066 wpabuf_free(hapd->p2p_probe_resp_ie);
4067 hapd->p2p_probe_resp_ie = proberesp_ies;
4069 wpabuf_free(beacon_ies);
4070 wpabuf_free(proberesp_ies);
4072 wpa_supplicant_ap_update_beacon(wpa_s);
4076 static void wpas_p2p_idle_update(void *ctx, int idle)
4078 struct wpa_supplicant *wpa_s = ctx;
4079 if (!wpa_s->ap_iface)
4081 wpa_printf(MSG_DEBUG, "P2P: GO - group %sidle", idle ? "" : "not ");
4083 wpas_p2p_set_group_idle_timeout(wpa_s);
4085 eloop_cancel_timeout(wpas_p2p_group_idle_timeout, wpa_s, NULL);
4089 struct p2p_group * wpas_p2p_group_init(struct wpa_supplicant *wpa_s,
4090 struct wpa_ssid *ssid)
4092 struct p2p_group *group;
4093 struct p2p_group_config *cfg;
4095 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT)
4097 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
4100 cfg = os_zalloc(sizeof(*cfg));
4104 if (ssid->p2p_persistent_group && wpa_s->conf->persistent_reconnect)
4105 cfg->persistent_group = 2;
4106 else if (ssid->p2p_persistent_group)
4107 cfg->persistent_group = 1;
4108 os_memcpy(cfg->interface_addr, wpa_s->own_addr, ETH_ALEN);
4109 if (wpa_s->max_stations &&
4110 wpa_s->max_stations < wpa_s->conf->max_num_sta)
4111 cfg->max_clients = wpa_s->max_stations;
4113 cfg->max_clients = wpa_s->conf->max_num_sta;
4114 os_memcpy(cfg->ssid, ssid->ssid, ssid->ssid_len);
4115 cfg->ssid_len = ssid->ssid_len;
4116 cfg->cb_ctx = wpa_s;
4117 cfg->ie_update = wpas_p2p_ie_update;
4118 cfg->idle_update = wpas_p2p_idle_update;
4120 group = p2p_group_init(wpa_s->global->p2p, cfg);
4123 if (ssid->mode != WPAS_MODE_P2P_GROUP_FORMATION)
4124 p2p_group_notif_formation_done(group);
4125 wpa_s->p2p_group = group;
4130 void wpas_p2p_wps_success(struct wpa_supplicant *wpa_s, const u8 *peer_addr,
4133 struct wpa_ssid *ssid = wpa_s->current_ssid;
4135 if (!wpa_s->p2p_in_provisioning) {
4136 wpa_printf(MSG_DEBUG, "P2P: Ignore WPS success event - P2P "
4137 "provisioning not in progress");
4141 if (ssid && ssid->mode == WPAS_MODE_INFRA) {
4142 u8 go_dev_addr[ETH_ALEN];
4143 os_memcpy(go_dev_addr, wpa_s->bssid, ETH_ALEN);
4144 wpas_p2p_persistent_group(wpa_s, go_dev_addr, ssid->ssid,
4146 /* Clear any stored provisioning info */
4147 p2p_clear_provisioning_info(wpa_s->global->p2p, go_dev_addr);
4150 eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s->parent,
4152 if (ssid && ssid->mode == WPAS_MODE_INFRA) {
4154 * Use a separate timeout for initial data connection to
4155 * complete to allow the group to be removed automatically if
4156 * something goes wrong in this step before the P2P group idle
4157 * timeout mechanism is taken into use.
4159 eloop_register_timeout(P2P_MAX_INITIAL_CONN_WAIT, 0,
4160 wpas_p2p_group_formation_timeout,
4161 wpa_s->parent, NULL);
4163 if (wpa_s->global->p2p)
4164 p2p_wps_success_cb(wpa_s->global->p2p, peer_addr);
4165 else if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT)
4166 wpa_drv_wps_success_cb(wpa_s, peer_addr);
4167 wpas_group_formation_completed(wpa_s, 1);
4171 void wpas_p2p_wps_failed(struct wpa_supplicant *wpa_s,
4172 struct wps_event_fail *fail)
4174 if (!wpa_s->p2p_in_provisioning) {
4175 wpa_printf(MSG_DEBUG, "P2P: Ignore WPS fail event - P2P "
4176 "provisioning not in progress");
4180 if (wpa_s->go_params) {
4181 p2p_clear_provisioning_info(
4183 wpa_s->go_params->peer_device_addr);
4186 wpas_notify_p2p_wps_failed(wpa_s, fail);
4190 int wpas_p2p_prov_disc(struct wpa_supplicant *wpa_s, const u8 *peer_addr,
4191 const char *config_method,
4192 enum wpas_p2p_prov_disc_use use)
4196 wpa_s->p2p_fallback_to_go_neg = 0;
4197 wpa_s->pending_pd_use = NORMAL_PD;
4198 if (os_strncmp(config_method, "display", 7) == 0)
4199 config_methods = WPS_CONFIG_DISPLAY;
4200 else if (os_strncmp(config_method, "keypad", 6) == 0)
4201 config_methods = WPS_CONFIG_KEYPAD;
4202 else if (os_strncmp(config_method, "pbc", 3) == 0 ||
4203 os_strncmp(config_method, "pushbutton", 10) == 0)
4204 config_methods = WPS_CONFIG_PUSHBUTTON;
4206 wpa_printf(MSG_DEBUG, "P2P: Unknown config method");
4210 if (use == WPAS_P2P_PD_AUTO) {
4211 os_memcpy(wpa_s->pending_join_dev_addr, peer_addr, ETH_ALEN);
4212 wpa_s->pending_pd_config_methods = config_methods;
4213 wpa_s->p2p_auto_pd = 1;
4214 wpa_s->p2p_auto_join = 0;
4215 wpa_s->pending_pd_before_join = 0;
4216 wpa_s->auto_pd_scan_retry = 0;
4217 wpas_p2p_stop_find(wpa_s);
4218 wpa_s->p2p_join_scan_count = 0;
4219 os_get_time(&wpa_s->p2p_auto_started);
4220 wpa_printf(MSG_DEBUG, "P2P: Auto PD started at %ld.%06ld",
4221 wpa_s->p2p_auto_started.sec,
4222 wpa_s->p2p_auto_started.usec);
4223 wpas_p2p_join_scan(wpa_s, NULL);
4227 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT) {
4228 return wpa_drv_p2p_prov_disc_req(wpa_s, peer_addr,
4230 use == WPAS_P2P_PD_FOR_JOIN);
4233 if (wpa_s->global->p2p == NULL || wpa_s->global->p2p_disabled)
4236 return p2p_prov_disc_req(wpa_s->global->p2p, peer_addr,
4237 config_methods, use == WPAS_P2P_PD_FOR_JOIN,
4242 int wpas_p2p_scan_result_text(const u8 *ies, size_t ies_len, char *buf,
4245 return p2p_scan_result_text(ies, ies_len, buf, end);
4249 static void wpas_p2p_clear_pending_action_tx(struct wpa_supplicant *wpa_s)
4251 if (!wpa_s->pending_action_tx)
4254 wpa_printf(MSG_DEBUG, "P2P: Drop pending Action TX due to new "
4255 "operation request");
4256 wpabuf_free(wpa_s->pending_action_tx);
4257 wpa_s->pending_action_tx = NULL;
4261 int wpas_p2p_find(struct wpa_supplicant *wpa_s, unsigned int timeout,
4262 enum p2p_discovery_type type,
4263 unsigned int num_req_dev_types, const u8 *req_dev_types,
4264 const u8 *dev_id, unsigned int search_delay)
4266 wpas_p2p_clear_pending_action_tx(wpa_s);
4267 wpa_s->p2p_long_listen = 0;
4269 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT)
4270 return wpa_drv_p2p_find(wpa_s, timeout, type);
4272 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL ||
4273 wpa_s->p2p_in_provisioning)
4276 wpa_supplicant_cancel_sched_scan(wpa_s);
4278 return p2p_find(wpa_s->global->p2p, timeout, type,
4279 num_req_dev_types, req_dev_types, dev_id,
4284 void wpas_p2p_stop_find(struct wpa_supplicant *wpa_s)
4286 wpas_p2p_clear_pending_action_tx(wpa_s);
4287 wpa_s->p2p_long_listen = 0;
4288 eloop_cancel_timeout(wpas_p2p_long_listen_timeout, wpa_s, NULL);
4289 eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL);
4290 wpa_s->global->p2p_cb_on_scan_complete = 0;
4292 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT) {
4293 wpa_drv_p2p_stop_find(wpa_s);
4297 if (wpa_s->global->p2p)
4298 p2p_stop_find(wpa_s->global->p2p);
4300 wpas_p2p_remove_pending_group_interface(wpa_s);
4304 static void wpas_p2p_long_listen_timeout(void *eloop_ctx, void *timeout_ctx)
4306 struct wpa_supplicant *wpa_s = eloop_ctx;
4307 wpa_s->p2p_long_listen = 0;
4311 int wpas_p2p_listen(struct wpa_supplicant *wpa_s, unsigned int timeout)
4315 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
4318 wpa_supplicant_cancel_sched_scan(wpa_s);
4319 wpas_p2p_clear_pending_action_tx(wpa_s);
4323 * This is a request for unlimited Listen state. However, at
4324 * least for now, this is mapped to a Listen state for one
4329 eloop_cancel_timeout(wpas_p2p_long_listen_timeout, wpa_s, NULL);
4330 wpa_s->p2p_long_listen = 0;
4333 * Stop previous find/listen operation to avoid trying to request a new
4334 * remain-on-channel operation while the driver is still running the
4337 if (wpa_s->global->p2p)
4338 p2p_stop_find(wpa_s->global->p2p);
4340 res = wpas_p2p_listen_start(wpa_s, timeout * 1000);
4341 if (res == 0 && timeout * 1000 > wpa_s->max_remain_on_chan) {
4342 wpa_s->p2p_long_listen = timeout * 1000;
4343 eloop_register_timeout(timeout, 0,
4344 wpas_p2p_long_listen_timeout,
4352 int wpas_p2p_assoc_req_ie(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
4353 u8 *buf, size_t len, int p2p_group)
4355 struct wpabuf *p2p_ie;
4358 if (wpa_s->global->p2p_disabled)
4360 if (wpa_s->global->p2p == NULL)
4365 p2p_ie = wpa_bss_get_vendor_ie_multi(bss, P2P_IE_VENDOR_TYPE);
4366 ret = p2p_assoc_req_ie(wpa_s->global->p2p, bss->bssid, buf, len,
4368 wpabuf_free(p2p_ie);
4374 int wpas_p2p_probe_req_rx(struct wpa_supplicant *wpa_s, const u8 *addr,
4375 const u8 *dst, const u8 *bssid,
4376 const u8 *ie, size_t ie_len, int ssi_signal)
4378 if (wpa_s->global->p2p_disabled)
4380 if (wpa_s->global->p2p == NULL)
4383 switch (p2p_probe_req_rx(wpa_s->global->p2p, addr, dst, bssid,
4385 case P2P_PREQ_NOT_P2P:
4386 wpas_notify_preq(wpa_s, addr, dst, bssid, ie, ie_len,
4389 case P2P_PREQ_MALFORMED:
4390 case P2P_PREQ_NOT_LISTEN:
4391 case P2P_PREQ_NOT_PROCESSED:
4392 default: /* make gcc happy */
4394 case P2P_PREQ_PROCESSED:
4400 void wpas_p2p_rx_action(struct wpa_supplicant *wpa_s, const u8 *da,
4401 const u8 *sa, const u8 *bssid,
4402 u8 category, const u8 *data, size_t len, int freq)
4404 if (wpa_s->global->p2p_disabled)
4406 if (wpa_s->global->p2p == NULL)
4409 p2p_rx_action(wpa_s->global->p2p, da, sa, bssid, category, data, len,
4414 void wpas_p2p_scan_ie(struct wpa_supplicant *wpa_s, struct wpabuf *ies)
4416 if (wpa_s->global->p2p_disabled)
4418 if (wpa_s->global->p2p == NULL)
4421 p2p_scan_ie(wpa_s->global->p2p, ies, NULL);
4425 void wpas_p2p_group_deinit(struct wpa_supplicant *wpa_s)
4427 p2p_group_deinit(wpa_s->p2p_group);
4428 wpa_s->p2p_group = NULL;
4430 wpa_s->ap_configured_cb = NULL;
4431 wpa_s->ap_configured_cb_ctx = NULL;
4432 wpa_s->ap_configured_cb_data = NULL;
4433 wpa_s->connect_without_scan = NULL;
4437 int wpas_p2p_reject(struct wpa_supplicant *wpa_s, const u8 *addr)
4439 wpa_s->p2p_long_listen = 0;
4441 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT)
4442 return wpa_drv_p2p_reject(wpa_s, addr);
4444 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
4447 return p2p_reject(wpa_s->global->p2p, addr);
4451 /* Invite to reinvoke a persistent group */
4452 int wpas_p2p_invite(struct wpa_supplicant *wpa_s, const u8 *peer_addr,
4453 struct wpa_ssid *ssid, const u8 *go_dev_addr, int freq,
4456 enum p2p_invite_role role;
4459 int force_freq = 0, oper_freq = 0;
4462 wpa_s->p2p_persistent_go_freq = freq;
4463 wpa_s->p2p_go_ht40 = !!ht40;
4464 if (ssid->mode == WPAS_MODE_P2P_GO) {
4465 role = P2P_INVITE_ROLE_GO;
4466 if (peer_addr == NULL) {
4467 wpa_printf(MSG_DEBUG, "P2P: Missing peer "
4468 "address in invitation command");
4471 if (wpas_p2p_create_iface(wpa_s)) {
4472 if (wpas_p2p_add_group_interface(wpa_s,
4473 WPA_IF_P2P_GO) < 0) {
4474 wpa_printf(MSG_ERROR, "P2P: Failed to "
4475 "allocate a new interface for the "
4479 bssid = wpa_s->pending_interface_addr;
4481 bssid = wpa_s->own_addr;
4483 role = P2P_INVITE_ROLE_CLIENT;
4484 peer_addr = ssid->bssid;
4486 wpa_s->pending_invite_ssid_id = ssid->id;
4489 if (wpa_s->current_ssid && wpa_drv_get_bssid(wpa_s, bssid) == 0 &&
4491 oper_freq = wpa_s->assoc_freq;
4493 oper_freq = wpa_drv_shared_freq(wpa_s);
4499 if (!p2p_supported_freq(wpa_s->global->p2p, freq)) {
4500 wpa_printf(MSG_DEBUG, "P2P: The forced channel "
4501 "(%u MHz) is not supported for P2P uses",
4506 if (oper_freq > 0 && freq != oper_freq &&
4507 !(wpa_s->drv_flags &
4508 WPA_DRIVER_FLAGS_MULTI_CHANNEL_CONCURRENT)) {
4509 wpa_printf(MSG_DEBUG, "P2P: Cannot start P2P group "
4510 "on %u MHz while connected on another "
4511 "channel (%u MHz)", freq, oper_freq);
4514 wpa_printf(MSG_DEBUG, "P2P: Trying to force us to use the "
4515 "requested channel (%u MHz)", freq);
4517 } else if (oper_freq > 0 &&
4518 !p2p_supported_freq(wpa_s->global->p2p, oper_freq)) {
4519 if (!(wpa_s->drv_flags &
4520 WPA_DRIVER_FLAGS_MULTI_CHANNEL_CONCURRENT)) {
4521 wpa_printf(MSG_DEBUG, "P2P: Cannot start P2P group "
4522 "while connected on non-P2P supported "
4523 "channel (%u MHz)", oper_freq);
4526 wpa_printf(MSG_DEBUG, "P2P: Current operating channel "
4527 "(%u MHz) not available for P2P - try to use "
4528 "another channel", oper_freq);
4530 } else if (oper_freq > 0) {
4531 wpa_printf(MSG_DEBUG, "P2P: Trying to force us to use the "
4532 "channel we are already using (%u MHz) on another "
4533 "interface", oper_freq);
4534 force_freq = oper_freq;
4537 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT)
4538 return wpa_drv_p2p_invite(wpa_s, peer_addr, role, bssid,
4539 ssid->ssid, ssid->ssid_len,
4542 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
4546 return p2p_invite(wpa_s->global->p2p, peer_addr, role, bssid,
4547 ssid->ssid, ssid->ssid_len, force_freq, go_dev_addr, 1);
4549 return p2p_invite(wpa_s->global->p2p, peer_addr, role, bssid,
4550 ssid->ssid, ssid->ssid_len, freq, go_dev_addr, 1);
4555 /* Invite to join an active group */
4556 int wpas_p2p_invite_group(struct wpa_supplicant *wpa_s, const char *ifname,
4557 const u8 *peer_addr, const u8 *go_dev_addr)
4559 struct wpa_global *global = wpa_s->global;
4560 enum p2p_invite_role role;
4562 struct wpa_ssid *ssid;
4565 wpa_s->p2p_persistent_go_freq = 0;
4566 wpa_s->p2p_go_ht40 = 0;
4568 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
4569 if (os_strcmp(wpa_s->ifname, ifname) == 0)
4572 if (wpa_s == NULL) {
4573 wpa_printf(MSG_DEBUG, "P2P: Interface '%s' not found", ifname);
4577 ssid = wpa_s->current_ssid;
4579 wpa_printf(MSG_DEBUG, "P2P: No current SSID to use for "
4584 persistent = ssid->p2p_persistent_group &&
4585 wpas_p2p_get_persistent(wpa_s->parent, peer_addr,
4586 ssid->ssid, ssid->ssid_len);
4588 if (ssid->mode == WPAS_MODE_P2P_GO) {
4589 role = P2P_INVITE_ROLE_ACTIVE_GO;
4590 bssid = wpa_s->own_addr;
4591 if (go_dev_addr == NULL)
4592 go_dev_addr = wpa_s->global->p2p_dev_addr;
4594 role = P2P_INVITE_ROLE_CLIENT;
4595 if (wpa_s->wpa_state < WPA_ASSOCIATED) {
4596 wpa_printf(MSG_DEBUG, "P2P: Not associated - cannot "
4597 "invite to current group");
4600 bssid = wpa_s->bssid;
4601 if (go_dev_addr == NULL &&
4602 !is_zero_ether_addr(wpa_s->go_dev_addr))
4603 go_dev_addr = wpa_s->go_dev_addr;
4605 wpa_s->parent->pending_invite_ssid_id = -1;
4607 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT)
4608 return wpa_drv_p2p_invite(wpa_s, peer_addr, role, bssid,
4609 ssid->ssid, ssid->ssid_len,
4610 go_dev_addr, persistent);
4612 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
4615 return p2p_invite(wpa_s->global->p2p, peer_addr, role, bssid,
4616 ssid->ssid, ssid->ssid_len, wpa_s->assoc_freq,
4617 go_dev_addr, persistent);
4621 void wpas_p2p_completed(struct wpa_supplicant *wpa_s)
4623 struct wpa_ssid *ssid = wpa_s->current_ssid;
4624 const char *ssid_txt;
4625 u8 go_dev_addr[ETH_ALEN];
4626 int network_id = -1;
4630 if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GROUP_FORMATION) {
4631 eloop_cancel_timeout(wpas_p2p_group_formation_timeout,
4632 wpa_s->parent, NULL);
4635 if (!wpa_s->show_group_started || !ssid)
4638 wpa_s->show_group_started = 0;
4640 ssid_txt = wpa_ssid_txt(ssid->ssid, ssid->ssid_len);
4641 os_memset(go_dev_addr, 0, ETH_ALEN);
4642 if (ssid->bssid_set)
4643 os_memcpy(go_dev_addr, ssid->bssid, ETH_ALEN);
4644 persistent = wpas_p2p_persistent_group(wpa_s, go_dev_addr, ssid->ssid,
4646 os_memcpy(wpa_s->go_dev_addr, go_dev_addr, ETH_ALEN);
4648 if (wpa_s->global->p2p_group_formation == wpa_s)
4649 wpa_s->global->p2p_group_formation = NULL;
4651 freq = wpa_s->current_bss ? wpa_s->current_bss->freq :
4652 (int) wpa_s->assoc_freq;
4653 if (ssid->passphrase == NULL && ssid->psk_set) {
4655 wpa_snprintf_hex(psk, sizeof(psk), ssid->psk, 32);
4656 wpa_msg(wpa_s->parent, MSG_INFO, P2P_EVENT_GROUP_STARTED
4657 "%s client ssid=\"%s\" freq=%d psk=%s go_dev_addr="
4659 wpa_s->ifname, ssid_txt, freq, psk,
4660 MAC2STR(go_dev_addr),
4661 persistent ? " [PERSISTENT]" : "");
4663 wpa_msg(wpa_s->parent, MSG_INFO, P2P_EVENT_GROUP_STARTED
4664 "%s client ssid=\"%s\" freq=%d passphrase=\"%s\" "
4665 "go_dev_addr=" MACSTR "%s",
4666 wpa_s->ifname, ssid_txt, freq,
4667 ssid->passphrase ? ssid->passphrase : "",
4668 MAC2STR(go_dev_addr),
4669 persistent ? " [PERSISTENT]" : "");
4673 network_id = wpas_p2p_store_persistent_group(wpa_s->parent,
4676 network_id = ssid->id;
4677 wpas_notify_p2p_group_started(wpa_s, ssid, network_id, 1);
4680 if (wpa_s->global->p2p_cb_on_scan_complete && !wpa_s->global->p2p_disabled &&
4681 wpa_s->global->p2p != NULL) {
4682 wpa_s->global->p2p_cb_on_scan_complete = 0;
4683 if (p2p_other_scan_completed(wpa_s->global->p2p) == 1) {
4684 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Pending P2P operation "
4685 "continued after successful connection");
4686 p2p_increase_search_delay(
4688 wpas_p2p_search_delay(wpa_s));
4694 int wpas_p2p_presence_req(struct wpa_supplicant *wpa_s, u32 duration1,
4695 u32 interval1, u32 duration2, u32 interval2)
4697 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT)
4699 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
4702 if (wpa_s->wpa_state < WPA_ASSOCIATED ||
4703 wpa_s->current_ssid == NULL ||
4704 wpa_s->current_ssid->mode != WPAS_MODE_INFRA)
4707 return p2p_presence_req(wpa_s->global->p2p, wpa_s->bssid,
4708 wpa_s->own_addr, wpa_s->assoc_freq,
4709 duration1, interval1, duration2, interval2);
4713 int wpas_p2p_ext_listen(struct wpa_supplicant *wpa_s, unsigned int period,
4714 unsigned int interval)
4716 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT)
4719 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
4722 return p2p_ext_listen(wpa_s->global->p2p, period, interval);
4726 static int wpas_p2p_is_client(struct wpa_supplicant *wpa_s)
4728 return wpa_s->current_ssid != NULL &&
4729 wpa_s->current_ssid->p2p_group &&
4730 wpa_s->current_ssid->mode == WPAS_MODE_INFRA;
4734 static void wpas_p2p_group_idle_timeout(void *eloop_ctx, void *timeout_ctx)
4736 struct wpa_supplicant *wpa_s = eloop_ctx;
4738 if (wpa_s->conf->p2p_group_idle == 0 && !wpas_p2p_is_client(wpa_s)) {
4739 wpa_printf(MSG_DEBUG, "P2P: Ignore group idle timeout - "
4744 wpa_printf(MSG_DEBUG, "P2P: Group idle timeout reached - terminate "
4746 wpas_p2p_group_delete(wpa_s, P2P_GROUP_REMOVAL_IDLE_TIMEOUT);
4750 static void wpas_p2p_set_group_idle_timeout(struct wpa_supplicant *wpa_s)
4754 if (eloop_cancel_timeout(wpas_p2p_group_idle_timeout, wpa_s, NULL) > 0)
4755 wpa_printf(MSG_DEBUG, "P2P: Cancelled P2P group idle timeout");
4757 if (wpa_s->current_ssid == NULL || !wpa_s->current_ssid->p2p_group)
4760 timeout = wpa_s->conf->p2p_group_idle;
4761 if (wpa_s->current_ssid->mode == WPAS_MODE_INFRA &&
4762 (timeout == 0 || timeout > P2P_MAX_CLIENT_IDLE))
4763 timeout = P2P_MAX_CLIENT_IDLE;
4769 if (wpa_s->current_ssid->mode == WPAS_MODE_INFRA)
4770 timeout = 0; /* special client mode no-timeout */
4775 if (wpa_s->p2p_in_provisioning) {
4777 * Use the normal group formation timeout during the
4778 * provisioning phase to avoid terminating this process too
4779 * early due to group idle timeout.
4781 wpa_printf(MSG_DEBUG, "P2P: Do not use P2P group idle timeout "
4782 "during provisioning");
4786 if (wpa_s->show_group_started) {
4788 * Use the normal group formation timeout between the end of
4789 * the provisioning phase and completion of 4-way handshake to
4790 * avoid terminating this process too early due to group idle
4793 wpa_printf(MSG_DEBUG, "P2P: Do not use P2P group idle timeout "
4794 "while waiting for initial 4-way handshake to "
4800 wpa_printf(MSG_DEBUG, "P2P: Set P2P group idle timeout to %u seconds",
4802 eloop_register_timeout(timeout, 0, wpas_p2p_group_idle_timeout,
4807 /* Returns 1 if the interface was removed */
4808 int wpas_p2p_deauth_notif(struct wpa_supplicant *wpa_s, const u8 *bssid,
4809 u16 reason_code, const u8 *ie, size_t ie_len,
4810 int locally_generated)
4812 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
4814 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT)
4817 if (!locally_generated)
4818 p2p_deauth_notif(wpa_s->global->p2p, bssid, reason_code, ie,
4821 if (reason_code == WLAN_REASON_DEAUTH_LEAVING && !locally_generated &&
4822 wpa_s->current_ssid &&
4823 wpa_s->current_ssid->p2p_group &&
4824 wpa_s->current_ssid->mode == WPAS_MODE_INFRA) {
4825 wpa_printf(MSG_DEBUG, "P2P: GO indicated that the P2P Group "
4826 "session is ending");
4827 if (wpas_p2p_group_delete(wpa_s,
4828 P2P_GROUP_REMOVAL_GO_ENDING_SESSION)
4837 void wpas_p2p_disassoc_notif(struct wpa_supplicant *wpa_s, const u8 *bssid,
4838 u16 reason_code, const u8 *ie, size_t ie_len,
4839 int locally_generated)
4841 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
4843 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT)
4846 if (!locally_generated)
4847 p2p_disassoc_notif(wpa_s->global->p2p, bssid, reason_code, ie,
4852 void wpas_p2p_update_config(struct wpa_supplicant *wpa_s)
4854 struct p2p_data *p2p = wpa_s->global->p2p;
4859 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_CAPABLE))
4862 if (wpa_s->conf->changed_parameters & CFG_CHANGED_DEVICE_NAME)
4863 p2p_set_dev_name(p2p, wpa_s->conf->device_name);
4865 if (wpa_s->conf->changed_parameters & CFG_CHANGED_DEVICE_TYPE)
4866 p2p_set_pri_dev_type(p2p, wpa_s->conf->device_type);
4869 (wpa_s->conf->changed_parameters & CFG_CHANGED_CONFIG_METHODS))
4870 p2p_set_config_methods(p2p, wpa_s->wps->config_methods);
4872 if (wpa_s->wps && (wpa_s->conf->changed_parameters & CFG_CHANGED_UUID))
4873 p2p_set_uuid(p2p, wpa_s->wps->uuid);
4875 if (wpa_s->conf->changed_parameters & CFG_CHANGED_WPS_STRING) {
4876 p2p_set_manufacturer(p2p, wpa_s->conf->manufacturer);
4877 p2p_set_model_name(p2p, wpa_s->conf->model_name);
4878 p2p_set_model_number(p2p, wpa_s->conf->model_number);
4879 p2p_set_serial_number(p2p, wpa_s->conf->serial_number);
4882 if (wpa_s->conf->changed_parameters & CFG_CHANGED_SEC_DEVICE_TYPE)
4883 p2p_set_sec_dev_types(p2p,
4884 (void *) wpa_s->conf->sec_device_type,
4885 wpa_s->conf->num_sec_device_types);
4887 if (wpa_s->conf->changed_parameters & CFG_CHANGED_VENDOR_EXTENSION) {
4889 p2p_remove_wps_vendor_extensions(p2p);
4890 for (i = 0; i < MAX_WPS_VENDOR_EXT; i++) {
4891 if (wpa_s->conf->wps_vendor_ext[i] == NULL)
4893 p2p_add_wps_vendor_extension(
4894 p2p, wpa_s->conf->wps_vendor_ext[i]);
4898 if ((wpa_s->conf->changed_parameters & CFG_CHANGED_COUNTRY) &&
4899 wpa_s->conf->country[0] && wpa_s->conf->country[1]) {
4901 country[0] = wpa_s->conf->country[0];
4902 country[1] = wpa_s->conf->country[1];
4904 p2p_set_country(p2p, country);
4907 if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_SSID_POSTFIX) {
4908 p2p_set_ssid_postfix(p2p, (u8 *) wpa_s->conf->p2p_ssid_postfix,
4909 wpa_s->conf->p2p_ssid_postfix ?
4910 os_strlen(wpa_s->conf->p2p_ssid_postfix) :
4914 if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_INTRA_BSS)
4915 p2p_set_intra_bss_dist(p2p, wpa_s->conf->p2p_intra_bss);
4917 if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_LISTEN_CHANNEL) {
4918 u8 reg_class, channel;
4921 if (wpa_s->conf->p2p_listen_reg_class &&
4922 wpa_s->conf->p2p_listen_channel) {
4923 reg_class = wpa_s->conf->p2p_listen_reg_class;
4924 channel = wpa_s->conf->p2p_listen_channel;
4928 * Pick one of the social channels randomly as the
4931 os_get_random((u8 *) &r, sizeof(r));
4932 channel = 1 + (r % 3) * 5;
4934 ret = p2p_set_listen_channel(p2p, reg_class, channel);
4936 wpa_printf(MSG_ERROR, "P2P: Own listen channel update "
4939 if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_OPER_CHANNEL) {
4940 u8 op_reg_class, op_channel, cfg_op_channel;
4943 if (wpa_s->conf->p2p_oper_reg_class &&
4944 wpa_s->conf->p2p_oper_channel) {
4945 op_reg_class = wpa_s->conf->p2p_oper_reg_class;
4946 op_channel = wpa_s->conf->p2p_oper_channel;
4951 * Use random operation channel from (1, 6, 11)
4952 *if no other preference is indicated.
4954 os_get_random((u8 *) &r, sizeof(r));
4955 op_channel = 1 + (r % 3) * 5;
4958 ret = p2p_set_oper_channel(p2p, op_reg_class, op_channel,
4961 wpa_printf(MSG_ERROR, "P2P: Own oper channel update "
4965 if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_PREF_CHAN) {
4966 if (p2p_set_pref_chan(p2p, wpa_s->conf->num_p2p_pref_chan,
4967 wpa_s->conf->p2p_pref_chan) < 0) {
4968 wpa_printf(MSG_ERROR, "P2P: Preferred channel list "
4975 int wpas_p2p_set_noa(struct wpa_supplicant *wpa_s, u8 count, int start,
4978 if (!wpa_s->ap_iface)
4980 return hostapd_p2p_set_noa(wpa_s->ap_iface->bss[0], count, start,
4985 int wpas_p2p_set_cross_connect(struct wpa_supplicant *wpa_s, int enabled)
4987 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
4989 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT)
4992 wpa_s->global->cross_connection = enabled;
4993 p2p_set_cross_connect(wpa_s->global->p2p, enabled);
4996 struct wpa_supplicant *iface;
4998 for (iface = wpa_s->global->ifaces; iface; iface = iface->next)
5000 if (iface->cross_connect_enabled == 0)
5003 iface->cross_connect_enabled = 0;
5004 iface->cross_connect_in_use = 0;
5005 wpa_msg(iface->parent, MSG_INFO,
5006 P2P_EVENT_CROSS_CONNECT_DISABLE "%s %s",
5007 iface->ifname, iface->cross_connect_uplink);
5015 static void wpas_p2p_enable_cross_connect(struct wpa_supplicant *uplink)
5017 struct wpa_supplicant *iface;
5019 if (!uplink->global->cross_connection)
5022 for (iface = uplink->global->ifaces; iface; iface = iface->next) {
5023 if (!iface->cross_connect_enabled)
5025 if (os_strcmp(uplink->ifname, iface->cross_connect_uplink) !=
5028 if (iface->ap_iface == NULL)
5030 if (iface->cross_connect_in_use)
5033 iface->cross_connect_in_use = 1;
5034 wpa_msg(iface->parent, MSG_INFO,
5035 P2P_EVENT_CROSS_CONNECT_ENABLE "%s %s",
5036 iface->ifname, iface->cross_connect_uplink);
5041 static void wpas_p2p_disable_cross_connect(struct wpa_supplicant *uplink)
5043 struct wpa_supplicant *iface;
5045 for (iface = uplink->global->ifaces; iface; iface = iface->next) {
5046 if (!iface->cross_connect_enabled)
5048 if (os_strcmp(uplink->ifname, iface->cross_connect_uplink) !=
5051 if (!iface->cross_connect_in_use)
5054 wpa_msg(iface->parent, MSG_INFO,
5055 P2P_EVENT_CROSS_CONNECT_DISABLE "%s %s",
5056 iface->ifname, iface->cross_connect_uplink);
5057 iface->cross_connect_in_use = 0;
5062 void wpas_p2p_notif_connected(struct wpa_supplicant *wpa_s)
5064 if (wpa_s->ap_iface || wpa_s->current_ssid == NULL ||
5065 wpa_s->current_ssid->mode != WPAS_MODE_INFRA ||
5066 wpa_s->cross_connect_disallowed)
5067 wpas_p2p_disable_cross_connect(wpa_s);
5069 wpas_p2p_enable_cross_connect(wpa_s);
5070 if (!wpa_s->ap_iface &&
5071 eloop_cancel_timeout(wpas_p2p_group_idle_timeout, wpa_s, NULL) > 0)
5072 wpa_printf(MSG_DEBUG, "P2P: Cancelled P2P group idle timeout");
5076 void wpas_p2p_notif_disconnected(struct wpa_supplicant *wpa_s)
5078 wpas_p2p_disable_cross_connect(wpa_s);
5079 if (!wpa_s->ap_iface &&
5080 !eloop_is_timeout_registered(wpas_p2p_group_idle_timeout,
5082 wpas_p2p_set_group_idle_timeout(wpa_s);
5086 static void wpas_p2p_cross_connect_setup(struct wpa_supplicant *wpa_s)
5088 struct wpa_supplicant *iface;
5090 if (!wpa_s->global->cross_connection)
5093 for (iface = wpa_s->global->ifaces; iface; iface = iface->next) {
5096 if (iface->drv_flags &
5097 WPA_DRIVER_FLAGS_P2P_DEDICATED_INTERFACE)
5099 if (iface->drv_flags & WPA_DRIVER_FLAGS_P2P_CAPABLE)
5102 wpa_s->cross_connect_enabled = 1;
5103 os_strlcpy(wpa_s->cross_connect_uplink, iface->ifname,
5104 sizeof(wpa_s->cross_connect_uplink));
5105 wpa_printf(MSG_DEBUG, "P2P: Enable cross connection from "
5106 "%s to %s whenever uplink is available",
5107 wpa_s->ifname, wpa_s->cross_connect_uplink);
5109 if (iface->ap_iface || iface->current_ssid == NULL ||
5110 iface->current_ssid->mode != WPAS_MODE_INFRA ||
5111 iface->cross_connect_disallowed ||
5112 iface->wpa_state != WPA_COMPLETED)
5115 wpa_s->cross_connect_in_use = 1;
5116 wpa_msg(wpa_s->parent, MSG_INFO,
5117 P2P_EVENT_CROSS_CONNECT_ENABLE "%s %s",
5118 wpa_s->ifname, wpa_s->cross_connect_uplink);
5124 int wpas_p2p_notif_pbc_overlap(struct wpa_supplicant *wpa_s)
5126 if (wpa_s->p2p_group_interface != P2P_GROUP_INTERFACE_CLIENT &&
5127 !wpa_s->p2p_in_provisioning)
5128 return 0; /* not P2P client operation */
5130 wpa_printf(MSG_DEBUG, "P2P: Terminate connection due to WPS PBC "
5132 if (wpa_s != wpa_s->parent)
5133 wpa_msg_ctrl(wpa_s->parent, MSG_INFO, WPS_EVENT_OVERLAP);
5135 if (wpa_s->global->p2p)
5136 p2p_group_formation_failed(wpa_s->global->p2p);
5138 eloop_cancel_timeout(wpas_p2p_group_formation_timeout,
5139 wpa_s->parent, NULL);
5141 wpas_group_formation_completed(wpa_s, 0);
5146 void wpas_p2p_update_channel_list(struct wpa_supplicant *wpa_s)
5148 struct p2p_channels chan;
5150 if (wpa_s->global == NULL || wpa_s->global->p2p == NULL)
5153 os_memset(&chan, 0, sizeof(chan));
5154 if (wpas_p2p_setup_channels(wpa_s, &chan)) {
5155 wpa_printf(MSG_ERROR, "P2P: Failed to update supported "
5160 p2p_update_channel_list(wpa_s->global->p2p, &chan);
5164 int wpas_p2p_cancel(struct wpa_supplicant *wpa_s)
5166 struct wpa_global *global = wpa_s->global;
5170 if (global->p2p == NULL)
5173 wpa_printf(MSG_DEBUG, "P2P: Request to cancel group formation");
5175 if (wpa_s->pending_interface_name[0] &&
5176 !is_zero_ether_addr(wpa_s->pending_interface_addr))
5179 peer = p2p_get_go_neg_peer(global->p2p);
5181 wpa_printf(MSG_DEBUG, "P2P: Unauthorize pending GO Neg peer "
5182 MACSTR, MAC2STR(peer));
5183 p2p_unauthorize(global->p2p, peer);
5187 wpas_p2p_stop_find(wpa_s);
5189 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
5190 if (wpa_s == global->p2p_group_formation &&
5191 (wpa_s->p2p_in_provisioning ||
5192 wpa_s->parent->pending_interface_type ==
5193 WPA_IF_P2P_CLIENT)) {
5194 wpa_printf(MSG_DEBUG, "P2P: Interface %s in group "
5195 "formation found - cancelling",
5198 eloop_cancel_timeout(wpas_p2p_group_formation_timeout,
5199 wpa_s->parent, NULL);
5200 if (wpa_s->p2p_in_provisioning) {
5201 wpas_group_formation_completed(wpa_s, 0);
5204 wpas_p2p_group_delete(wpa_s,
5205 P2P_GROUP_REMOVAL_REQUESTED);
5211 wpa_printf(MSG_DEBUG, "P2P: No ongoing group formation found");
5219 void wpas_p2p_interface_unavailable(struct wpa_supplicant *wpa_s)
5221 if (wpa_s->current_ssid == NULL || !wpa_s->current_ssid->p2p_group)
5224 wpa_printf(MSG_DEBUG, "P2P: Remove group due to driver resource not "
5225 "being available anymore");
5226 wpas_p2p_group_delete(wpa_s, P2P_GROUP_REMOVAL_UNAVAILABLE);
5230 void wpas_p2p_update_best_channels(struct wpa_supplicant *wpa_s,
5231 int freq_24, int freq_5, int freq_overall)
5233 struct p2p_data *p2p = wpa_s->global->p2p;
5234 if (p2p == NULL || (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT))
5236 p2p_set_best_channels(p2p, freq_24, freq_5, freq_overall);
5240 int wpas_p2p_unauthorize(struct wpa_supplicant *wpa_s, const char *addr)
5243 struct p2p_data *p2p = wpa_s->global->p2p;
5245 if (p2p == NULL || (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT))
5248 if (hwaddr_aton(addr, peer))
5251 return p2p_unauthorize(p2p, peer);
5256 * wpas_p2p_disconnect - Disconnect from a P2P Group
5257 * @wpa_s: Pointer to wpa_supplicant data
5258 * Returns: 0 on success, -1 on failure
5260 * This can be used to disconnect from a group in which the local end is a P2P
5261 * Client or to end a P2P Group in case the local end is the Group Owner. If a
5262 * virtual network interface was created for this group, that interface will be
5263 * removed. Otherwise, only the configured P2P group network will be removed
5264 * from the interface.
5266 int wpas_p2p_disconnect(struct wpa_supplicant *wpa_s)
5272 return wpas_p2p_group_delete(wpa_s, P2P_GROUP_REMOVAL_REQUESTED) < 0 ?
5277 int wpas_p2p_in_progress(struct wpa_supplicant *wpa_s)
5279 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
5282 return p2p_in_progress(wpa_s->global->p2p);
5286 void wpas_p2p_network_removed(struct wpa_supplicant *wpa_s,
5287 struct wpa_ssid *ssid)
5289 if (wpa_s->p2p_in_provisioning && ssid->p2p_group &&
5290 eloop_cancel_timeout(wpas_p2p_group_formation_timeout,
5291 wpa_s->parent, NULL) > 0) {
5293 * Remove the network by scheduling the group formation
5294 * timeout to happen immediately. The teardown code
5295 * needs to be scheduled to run asynch later so that we
5296 * don't delete data from under ourselves unexpectedly.
5297 * Calling wpas_p2p_group_formation_timeout directly
5298 * causes a series of crashes in WPS failure scenarios.
5300 wpa_printf(MSG_DEBUG, "P2P: Canceled group formation due to "
5301 "P2P group network getting removed");
5302 eloop_register_timeout(0, 0, wpas_p2p_group_formation_timeout,
5303 wpa_s->parent, NULL);
5308 struct wpa_ssid * wpas_p2p_get_persistent(struct wpa_supplicant *wpa_s,
5309 const u8 *addr, const u8 *ssid,
5315 for (s = wpa_s->conf->ssid; s; s = s->next) {
5316 if (s->disabled != 2)
5319 (ssid_len != s->ssid_len ||
5320 os_memcmp(ssid, s->ssid, ssid_len) != 0))
5322 if (os_memcmp(s->bssid, addr, ETH_ALEN) == 0)
5323 return s; /* peer is GO in the persistent group */
5324 if (s->mode != WPAS_MODE_P2P_GO || s->p2p_client_list == NULL)
5326 for (i = 0; i < s->num_p2p_clients; i++) {
5327 if (os_memcmp(s->p2p_client_list + i * ETH_ALEN,
5328 addr, ETH_ALEN) == 0)
5329 return s; /* peer is P2P client in persistent
5338 void wpas_p2p_notify_ap_sta_authorized(struct wpa_supplicant *wpa_s,
5343 wpas_p2p_add_persistent_group_client(wpa_s, addr);
5347 static void wpas_p2p_fallback_to_go_neg(struct wpa_supplicant *wpa_s,
5350 struct wpa_supplicant *group = wpa_s;
5351 eloop_cancel_timeout(wpas_p2p_pd_before_join_timeout, wpa_s, NULL);
5352 if (wpa_s->global->p2p_group_formation)
5353 group = wpa_s->global->p2p_group_formation;
5354 wpa_s = wpa_s->parent;
5355 offchannel_send_action_done(wpa_s);
5357 wpas_p2p_group_delete(group, P2P_GROUP_REMOVAL_SILENT);
5358 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Fall back to GO Negotiation");
5359 wpas_p2p_connect(wpa_s, wpa_s->pending_join_dev_addr, wpa_s->p2p_pin,
5360 wpa_s->p2p_wps_method, wpa_s->p2p_persistent_group, 0,
5361 0, 0, wpa_s->p2p_go_intent, wpa_s->p2p_connect_freq,
5362 wpa_s->p2p_persistent_id,
5363 wpa_s->p2p_pd_before_go_neg,
5364 wpa_s->p2p_go_ht40);
5368 int wpas_p2p_scan_no_go_seen(struct wpa_supplicant *wpa_s)
5370 if (!wpa_s->p2p_fallback_to_go_neg ||
5371 wpa_s->p2p_in_provisioning <= 5)
5374 if (wpas_p2p_peer_go(wpa_s, wpa_s->pending_join_dev_addr) > 0)
5375 return 0; /* peer operating as a GO */
5377 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: GO not found for p2p_connect-auto - "
5378 "fallback to GO Negotiation");
5379 wpas_p2p_fallback_to_go_neg(wpa_s, 1);
5385 unsigned int wpas_p2p_search_delay(struct wpa_supplicant *wpa_s)
5387 const char *rn, *rn2;
5388 struct wpa_supplicant *ifs;
5390 if (wpa_s->wpa_state > WPA_SCANNING) {
5391 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Use %u ms search delay due to "
5392 "concurrent operation",
5393 P2P_CONCURRENT_SEARCH_DELAY);
5394 return P2P_CONCURRENT_SEARCH_DELAY;
5397 if (!wpa_s->driver->get_radio_name)
5399 rn = wpa_s->driver->get_radio_name(wpa_s->drv_priv);
5400 if (rn == NULL || rn[0] == '\0')
5403 for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) {
5404 if (ifs == wpa_s || !ifs->driver->get_radio_name)
5407 rn2 = ifs->driver->get_radio_name(ifs->drv_priv);
5408 if (!rn2 || os_strcmp(rn, rn2) != 0)
5410 if (ifs->wpa_state > WPA_SCANNING) {
5411 wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Use %u ms search "
5412 "delay due to concurrent operation on "
5414 P2P_CONCURRENT_SEARCH_DELAY, ifs->ifname);
5415 return P2P_CONCURRENT_SEARCH_DELAY;
5423 int wpas_p2p_handle_frequency_conflicts(struct wpa_supplicant *wpa_s, int freq)
5425 struct wpa_supplicant *iface = NULL;
5426 struct p2p_data *p2p = wpa_s->global->p2p;
5428 for (iface = wpa_s->global->ifaces; iface; iface = iface->next) {
5429 if((iface->p2p_group_interface) && (iface->current_ssid) &&
5430 (iface->current_ssid->frequency != freq)) {
5432 if (iface->p2p_group_interface == P2P_GROUP_INTERFACE_GO) {
5433 /* Try to see whether we can move the GO. If it
5434 * is not possible, remove the GO interface
5436 if(wpa_drv_switch_channel(iface, freq) == 0) {
5437 wpa_printf(MSG_ERROR, "P2P: GO Moved to freq(%d)", freq);
5438 iface->current_ssid->frequency = freq;
5443 /* If GO cannot be moved or if the conflicting interface is a
5444 * P2P Client, remove the interface depending up on the connection
5446 if(!wpas_is_p2p_prioritized(wpa_s)) {
5447 /* STA connection has priority over existing
5448 * P2P connection. So remove the interface */
5449 wpa_printf(MSG_DEBUG, "P2P: Removing P2P connection due to Single channel"
5450 "concurrent mode frequency conflict");
5451 wpas_p2p_group_delete(iface, P2P_GROUP_REMOVAL_FREQ_CONFLICT);
5453 /* Existing connection has the priority. Disable the newly
5454 * selected network and let the application know about it.