3 * Copyright (c) 2009-2010, Atheros Communications
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
19 #include "common/ieee802_11_common.h"
20 #include "common/ieee802_11_defs.h"
21 #include "common/wpa_ctrl.h"
22 #include "wps/wps_i.h"
24 #include "ap/hostapd.h"
25 #include "ap/p2p_hostapd.h"
26 #include "eapol_supp/eapol_supp_sm.h"
27 #include "rsn_supp/wpa.h"
28 #include "wpa_supplicant_i.h"
31 #include "config_ssid.h"
37 #include "offchannel.h"
38 #include "wps_supplicant.h"
39 #include "p2p_supplicant.h"
43 * How many times to try to scan to find the GO before giving up on join
46 #define P2P_MAX_JOIN_SCAN_ATTEMPTS 10
49 static void wpas_p2p_long_listen_timeout(void *eloop_ctx, void *timeout_ctx);
50 static struct wpa_supplicant *
51 wpas_p2p_get_group_iface(struct wpa_supplicant *wpa_s, int addr_allocated,
53 static int wpas_p2p_join_start(struct wpa_supplicant *wpa_s);
54 static void wpas_p2p_join_scan(void *eloop_ctx, void *timeout_ctx);
55 static int wpas_p2p_join(struct wpa_supplicant *wpa_s, const u8 *iface_addr,
56 const u8 *dev_addr, enum p2p_wps_method wps_method);
57 static int wpas_p2p_create_iface(struct wpa_supplicant *wpa_s);
58 static void wpas_p2p_cross_connect_setup(struct wpa_supplicant *wpa_s);
59 static void wpas_p2p_group_idle_timeout(void *eloop_ctx, void *timeout_ctx);
60 static void wpas_p2p_set_group_idle_timeout(struct wpa_supplicant *wpa_s);
63 static void wpas_p2p_scan_res_handler(struct wpa_supplicant *wpa_s,
64 struct wpa_scan_results *scan_res)
68 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
71 wpa_printf(MSG_DEBUG, "P2P: Scan results received (%d BSS)",
74 for (i = 0; i < scan_res->num; i++) {
75 struct wpa_scan_res *bss = scan_res->res[i];
76 if (p2p_scan_res_handler(wpa_s->global->p2p, bss->bssid,
77 bss->freq, bss->level,
78 (const u8 *) (bss + 1),
83 p2p_scan_res_handled(wpa_s->global->p2p);
87 static int wpas_p2p_scan(void *ctx, enum p2p_scan_type type, int freq,
88 unsigned int num_req_dev_types,
89 const u8 *req_dev_types)
91 struct wpa_supplicant *wpa_s = ctx;
92 struct wpa_driver_scan_params params;
94 struct wpabuf *wps_ie, *ies;
95 int social_channels[] = { 2412, 2437, 2462, 0, 0 };
98 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
101 os_memset(¶ms, 0, sizeof(params));
103 /* P2P Wildcard SSID */
104 params.num_ssids = 1;
105 params.ssids[0].ssid = (u8 *) P2P_WILDCARD_SSID;
106 params.ssids[0].ssid_len = P2P_WILDCARD_SSID_LEN;
108 wpa_s->wps->dev.p2p = 1;
109 wps_ie = wps_build_probe_req_ie(0, &wpa_s->wps->dev, wpa_s->wps->uuid,
111 num_req_dev_types, req_dev_types);
115 ielen = p2p_scan_ie_buf_len(wpa_s->global->p2p);
116 ies = wpabuf_alloc(wpabuf_len(wps_ie) + ielen);
121 wpabuf_put_buf(ies, wps_ie);
124 p2p_scan_ie(wpa_s->global->p2p, ies);
126 params.p2p_probe = 1;
127 params.extra_ies = wpabuf_head(ies);
128 params.extra_ies_len = wpabuf_len(ies);
131 case P2P_SCAN_SOCIAL:
132 params.freqs = social_channels;
136 case P2P_SCAN_SPECIFIC:
137 social_channels[0] = freq;
138 social_channels[1] = 0;
139 params.freqs = social_channels;
141 case P2P_SCAN_SOCIAL_PLUS_ONE:
142 social_channels[3] = freq;
143 params.freqs = social_channels;
147 wpa_s->scan_res_handler = wpas_p2p_scan_res_handler;
148 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME)
149 ret = ieee80211_sta_req_scan(wpa_s, ¶ms);
151 ret = wpa_drv_scan(wpa_s, ¶ms);
156 wpa_s->scan_res_handler = NULL;
162 #ifdef CONFIG_CLIENT_MLME
163 static void p2p_rx_action_mlme(void *ctx, const u8 *buf, size_t len, int freq)
165 struct wpa_supplicant *wpa_s = ctx;
166 const struct ieee80211_mgmt *mgmt;
169 if (wpa_s->global->p2p == NULL || wpa_s->global->p2p_disabled)
171 mgmt = (const struct ieee80211_mgmt *) buf;
172 hdr_len = (const u8 *) &mgmt->u.action.u.vs_public_action.action - buf;
175 p2p_rx_action(wpa_s->global->p2p, mgmt->da, mgmt->sa, mgmt->bssid,
176 mgmt->u.action.category,
177 &mgmt->u.action.u.vs_public_action.action,
178 len - hdr_len, freq);
180 #endif /* CONFIG_CLIENT_MLME */
183 static enum wpa_driver_if_type wpas_p2p_if_type(int p2p_group_interface)
185 switch (p2p_group_interface) {
186 case P2P_GROUP_INTERFACE_PENDING:
187 return WPA_IF_P2P_GROUP;
188 case P2P_GROUP_INTERFACE_GO:
189 return WPA_IF_P2P_GO;
190 case P2P_GROUP_INTERFACE_CLIENT:
191 return WPA_IF_P2P_CLIENT;
194 return WPA_IF_P2P_GROUP;
198 static struct wpa_supplicant * wpas_get_p2p_group(struct wpa_supplicant *wpa_s,
200 size_t ssid_len, int *go)
204 for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) {
205 for (s = wpa_s->conf->ssid; s; s = s->next) {
206 if (s->disabled != 0 || !s->p2p_group ||
207 s->ssid_len != ssid_len ||
208 os_memcmp(ssid, s->ssid, ssid_len) != 0)
210 if (s->mode == WPAS_MODE_P2P_GO &&
211 s != wpa_s->current_ssid)
214 *go = s->mode == WPAS_MODE_P2P_GO;
223 static void wpas_p2p_group_delete(struct wpa_supplicant *wpa_s)
225 struct wpa_ssid *ssid;
229 eloop_cancel_timeout(wpas_p2p_group_idle_timeout, wpa_s, NULL);
231 ssid = wpa_s->current_ssid;
234 * The current SSID was not known, but there may still be a
235 * pending P2P group interface waiting for provisioning.
237 ssid = wpa_s->conf->ssid;
239 if (ssid->p2p_group &&
240 (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION ||
241 (ssid->key_mgmt & WPA_KEY_MGMT_WPS)))
246 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO)
248 else if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT ||
249 (ssid && ssid->mode == WPAS_MODE_INFRA)) {
250 wpa_s->reassociate = 0;
251 wpa_s->disconnected = 1;
252 wpa_supplicant_deauthenticate(wpa_s,
253 WLAN_REASON_DEAUTH_LEAVING);
257 if (wpa_s->cross_connect_in_use) {
258 wpa_s->cross_connect_in_use = 0;
259 wpa_msg(wpa_s->parent, MSG_INFO,
260 P2P_EVENT_CROSS_CONNECT_DISABLE "%s %s",
261 wpa_s->ifname, wpa_s->cross_connect_uplink);
263 switch (wpa_s->removal_reason) {
264 case P2P_GROUP_REMOVAL_REQUESTED:
265 reason = " reason=REQUESTED";
267 case P2P_GROUP_REMOVAL_IDLE_TIMEOUT:
268 reason = " reason=IDLE";
270 case P2P_GROUP_REMOVAL_UNAVAILABLE:
271 reason = " reason=UNAVAILABLE";
277 wpa_msg(wpa_s->parent, MSG_INFO, P2P_EVENT_GROUP_REMOVED "%s %s%s",
278 wpa_s->ifname, gtype, reason);
281 wpas_notify_p2p_group_removed(wpa_s, ssid, gtype);
283 if (wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE) {
284 struct wpa_global *global;
286 enum wpa_driver_if_type type;
287 wpa_printf(MSG_DEBUG, "P2P: Remove group interface %s",
289 global = wpa_s->global;
290 ifname = os_strdup(wpa_s->ifname);
291 type = wpas_p2p_if_type(wpa_s->p2p_group_interface);
292 wpa_supplicant_remove_iface(wpa_s->global, wpa_s);
293 wpa_s = global->ifaces;
295 wpa_drv_if_remove(wpa_s, type, ifname);
300 wpa_printf(MSG_DEBUG, "P2P: Remove temporary group network");
301 if (ssid && (ssid->p2p_group ||
302 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION ||
303 (ssid->key_mgmt & WPA_KEY_MGMT_WPS))) {
305 if (ssid == wpa_s->current_ssid) {
306 wpa_sm_set_config(wpa_s->wpa, NULL);
307 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
308 wpa_s->current_ssid = NULL;
311 * Networks objects created during any P2P activities are not
312 * exposed out as they might/will confuse certain non-P2P aware
313 * applications since these network objects won't behave like
316 * Likewise, we don't send out network removed signals for such
319 wpa_config_remove_network(wpa_s->conf, id);
320 wpa_supplicant_clear_status(wpa_s);
322 wpa_printf(MSG_DEBUG, "P2P: Temporary group network not "
325 wpa_supplicant_ap_deinit(wpa_s);
329 static int wpas_p2p_persistent_group(struct wpa_supplicant *wpa_s,
331 const u8 *ssid, size_t ssid_len)
339 if (wpa_s->go_params)
340 bssid = wpa_s->go_params->peer_interface_addr;
342 bssid = wpa_s->bssid;
344 bss = wpa_bss_get(wpa_s, bssid, ssid, ssid_len);
346 u8 iface_addr[ETH_ALEN];
347 if (p2p_get_interface_addr(wpa_s->global->p2p, bssid,
349 bss = wpa_bss_get(wpa_s, iface_addr, ssid, ssid_len);
352 wpa_printf(MSG_DEBUG, "P2P: Could not figure out whether "
353 "group is persistent - BSS " MACSTR " not found",
358 p2p = wpa_bss_get_vendor_ie_multi(bss, P2P_IE_VENDOR_TYPE);
360 wpa_printf(MSG_DEBUG, "P2P: Could not figure out whether "
361 "group is persistent - BSS " MACSTR
362 " did not include P2P IE", MAC2STR(bssid));
363 wpa_hexdump(MSG_DEBUG, "P2P: Probe Response IEs",
364 (u8 *) (bss + 1), bss->ie_len);
365 wpa_hexdump(MSG_DEBUG, "P2P: Beacon IEs",
366 ((u8 *) bss + 1) + bss->ie_len,
371 group_capab = p2p_get_group_capab(p2p);
372 addr = p2p_get_go_dev_addr(p2p);
373 wpa_printf(MSG_DEBUG, "P2P: Checking whether group is persistent: "
374 "group_capab=0x%x", group_capab);
376 os_memcpy(go_dev_addr, addr, ETH_ALEN);
377 wpa_printf(MSG_DEBUG, "P2P: GO Device Address " MACSTR,
380 os_memset(go_dev_addr, 0, ETH_ALEN);
383 wpa_printf(MSG_DEBUG, "P2P: BSS " MACSTR " group_capab=0x%x "
384 "go_dev_addr=" MACSTR,
385 MAC2STR(bssid), group_capab, MAC2STR(go_dev_addr));
387 return group_capab & P2P_GROUP_CAPAB_PERSISTENT_GROUP;
391 static int wpas_p2p_store_persistent_group(struct wpa_supplicant *wpa_s,
392 struct wpa_ssid *ssid,
393 const u8 *go_dev_addr)
398 wpa_printf(MSG_DEBUG, "P2P: Storing credentials for a persistent "
399 "group (GO Dev Addr " MACSTR ")", MAC2STR(go_dev_addr));
400 for (s = wpa_s->conf->ssid; s; s = s->next) {
401 if (s->disabled == 2 &&
402 os_memcmp(go_dev_addr, s->bssid, ETH_ALEN) == 0 &&
403 s->ssid_len == ssid->ssid_len &&
404 os_memcmp(ssid->ssid, s->ssid, ssid->ssid_len) == 0)
409 wpa_printf(MSG_DEBUG, "P2P: Update existing persistent group "
411 if (ssid->passphrase && !s->passphrase)
413 else if (ssid->passphrase && s->passphrase &&
414 os_strcmp(ssid->passphrase, s->passphrase) != 0)
417 wpa_printf(MSG_DEBUG, "P2P: Create a new persistent group "
420 s = wpa_config_add_network(wpa_s->conf);
425 * Instead of network_added we emit persistent_group_added
426 * notification. Also to keep the defense checks in
427 * persistent_group obj registration method, we set the
428 * relevant flags in s to designate it as a persistent group.
431 s->p2p_persistent_group = 1;
432 wpas_notify_persistent_group_added(wpa_s, s);
433 wpa_config_set_network_defaults(s);
437 s->p2p_persistent_group = 1;
440 os_memcpy(s->bssid, go_dev_addr, ETH_ALEN);
441 s->mode = ssid->mode;
442 s->auth_alg = WPA_AUTH_ALG_OPEN;
443 s->key_mgmt = WPA_KEY_MGMT_PSK;
444 s->proto = WPA_PROTO_RSN;
445 s->pairwise_cipher = WPA_CIPHER_CCMP;
447 if (ssid->passphrase) {
448 os_free(s->passphrase);
449 s->passphrase = os_strdup(ssid->passphrase);
453 os_memcpy(s->psk, ssid->psk, 32);
455 if (s->passphrase && !s->psk_set)
456 wpa_config_update_psk(s);
457 if (s->ssid == NULL || s->ssid_len < ssid->ssid_len) {
459 s->ssid = os_malloc(ssid->ssid_len);
462 s->ssid_len = ssid->ssid_len;
463 os_memcpy(s->ssid, ssid->ssid, s->ssid_len);
466 #ifndef CONFIG_NO_CONFIG_WRITE
467 if (changed && wpa_s->conf->update_config &&
468 wpa_config_write(wpa_s->confname, wpa_s->conf)) {
469 wpa_printf(MSG_DEBUG, "P2P: Failed to update configuration");
471 #endif /* CONFIG_NO_CONFIG_WRITE */
477 static void wpas_group_formation_completed(struct wpa_supplicant *wpa_s,
480 struct wpa_ssid *ssid;
481 const char *ssid_txt;
484 u8 go_dev_addr[ETH_ALEN];
488 * This callback is likely called for the main interface. Update wpa_s
489 * to use the group interface if a new interface was created for the
492 if (wpa_s->global->p2p_group_formation)
493 wpa_s = wpa_s->global->p2p_group_formation;
494 wpa_s->global->p2p_group_formation = NULL;
495 wpa_s->p2p_in_provisioning = 0;
498 wpa_msg(wpa_s->parent, MSG_INFO,
499 P2P_EVENT_GROUP_FORMATION_FAILURE);
500 wpas_p2p_group_delete(wpa_s);
504 wpa_msg(wpa_s->parent, MSG_INFO, P2P_EVENT_GROUP_FORMATION_SUCCESS);
506 ssid = wpa_s->current_ssid;
507 if (ssid && ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION) {
508 ssid->mode = WPAS_MODE_P2P_GO;
509 p2p_group_notif_formation_done(wpa_s->p2p_group);
510 wpa_supplicant_ap_mac_addr_filter(wpa_s, NULL);
515 ssid_txt = wpa_ssid_txt(ssid->ssid, ssid->ssid_len);
516 client = ssid->mode == WPAS_MODE_INFRA;
517 if (ssid->mode == WPAS_MODE_P2P_GO) {
518 persistent = ssid->p2p_persistent_group;
519 os_memcpy(go_dev_addr, wpa_s->parent->own_addr,
522 persistent = wpas_p2p_persistent_group(wpa_s,
528 client = wpa_s->p2p_group_interface ==
529 P2P_GROUP_INTERFACE_CLIENT;
530 os_memset(go_dev_addr, 0, ETH_ALEN);
533 wpa_s->show_group_started = 0;
536 * Indicate event only after successfully completed 4-way
537 * handshake, i.e., when the interface is ready for data
540 wpa_s->show_group_started = 1;
541 } else if (ssid && ssid->passphrase == NULL && ssid->psk_set) {
543 wpa_snprintf_hex(psk, sizeof(psk), ssid->psk, 32);
544 wpa_msg(wpa_s->parent, MSG_INFO, P2P_EVENT_GROUP_STARTED
545 "%s GO ssid=\"%s\" freq=%d psk=%s go_dev_addr=" MACSTR
547 wpa_s->ifname, ssid_txt, ssid->frequency, psk,
548 MAC2STR(go_dev_addr),
549 persistent ? " [PERSISTENT]" : "");
550 wpas_p2p_cross_connect_setup(wpa_s);
551 wpas_p2p_set_group_idle_timeout(wpa_s);
553 wpa_msg(wpa_s->parent, MSG_INFO, P2P_EVENT_GROUP_STARTED
554 "%s GO ssid=\"%s\" freq=%d passphrase=\"%s\" "
555 "go_dev_addr=" MACSTR "%s",
556 wpa_s->ifname, ssid_txt, ssid ? ssid->frequency : 0,
557 ssid && ssid->passphrase ? ssid->passphrase : "",
558 MAC2STR(go_dev_addr),
559 persistent ? " [PERSISTENT]" : "");
560 wpas_p2p_cross_connect_setup(wpa_s);
561 wpas_p2p_set_group_idle_timeout(wpa_s);
565 network_id = wpas_p2p_store_persistent_group(wpa_s->parent,
567 if (network_id < 0 && ssid)
568 network_id = ssid->id;
570 wpas_notify_p2p_group_started(wpa_s, ssid, network_id, 0);
574 static void wpas_p2p_send_action_tx_status(struct wpa_supplicant *wpa_s,
576 const u8 *dst, const u8 *src,
578 const u8 *data, size_t data_len,
579 enum offchannel_send_action_result
582 enum p2p_send_action_result res = P2P_SEND_ACTION_SUCCESS;
584 if (wpa_s->global->p2p == NULL || wpa_s->global->p2p_disabled)
586 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT)
590 case OFFCHANNEL_SEND_ACTION_SUCCESS:
591 res = P2P_SEND_ACTION_SUCCESS;
593 case OFFCHANNEL_SEND_ACTION_NO_ACK:
594 res = P2P_SEND_ACTION_NO_ACK;
596 case OFFCHANNEL_SEND_ACTION_FAILED:
597 res = P2P_SEND_ACTION_FAILED;
601 p2p_send_action_cb(wpa_s->global->p2p, freq, dst, src, bssid, res);
603 if (wpa_s->pending_pd_before_join &&
604 (os_memcmp(dst, wpa_s->pending_join_dev_addr, ETH_ALEN) == 0 ||
605 os_memcmp(dst, wpa_s->pending_join_iface_addr, ETH_ALEN) == 0)) {
606 wpa_s->pending_pd_before_join = 0;
607 wpa_printf(MSG_DEBUG, "P2P: Starting pending "
608 "join-existing-group operation");
609 wpas_p2p_join_start(wpa_s);
614 static int wpas_send_action(void *ctx, unsigned int freq, const u8 *dst,
615 const u8 *src, const u8 *bssid, const u8 *buf,
616 size_t len, unsigned int wait_time)
618 struct wpa_supplicant *wpa_s = ctx;
619 return offchannel_send_action(wpa_s, freq, dst, src, bssid, buf, len,
621 wpas_p2p_send_action_tx_status);
625 static void wpas_send_action_done(void *ctx)
627 struct wpa_supplicant *wpa_s = ctx;
628 offchannel_send_action_done(wpa_s);
632 static int wpas_copy_go_neg_results(struct wpa_supplicant *wpa_s,
633 struct p2p_go_neg_results *params)
635 if (wpa_s->go_params == NULL) {
636 wpa_s->go_params = os_malloc(sizeof(*params));
637 if (wpa_s->go_params == NULL)
640 os_memcpy(wpa_s->go_params, params, sizeof(*params));
645 static void wpas_start_wps_enrollee(struct wpa_supplicant *wpa_s,
646 struct p2p_go_neg_results *res)
648 wpa_printf(MSG_DEBUG, "P2P: Start WPS Enrollee for peer " MACSTR,
649 MAC2STR(res->peer_interface_addr));
650 wpa_hexdump_ascii(MSG_DEBUG, "P2P: Start WPS Enrollee for SSID",
651 res->ssid, res->ssid_len);
652 wpa_supplicant_ap_deinit(wpa_s);
653 wpas_copy_go_neg_results(wpa_s, res);
654 if (res->wps_method == WPS_PBC)
655 wpas_wps_start_pbc(wpa_s, res->peer_interface_addr, 1);
657 u16 dev_pw_id = DEV_PW_DEFAULT;
658 if (wpa_s->p2p_wps_method == WPS_PIN_KEYPAD)
659 dev_pw_id = DEV_PW_REGISTRAR_SPECIFIED;
660 wpas_wps_start_pin(wpa_s, res->peer_interface_addr,
661 wpa_s->p2p_pin, 1, dev_pw_id);
666 static void p2p_go_configured(void *ctx, void *data)
668 struct wpa_supplicant *wpa_s = ctx;
669 struct p2p_go_neg_results *params = data;
670 struct wpa_ssid *ssid;
673 ssid = wpa_s->current_ssid;
674 if (ssid && ssid->mode == WPAS_MODE_P2P_GO) {
675 wpa_printf(MSG_DEBUG, "P2P: Group setup without provisioning");
676 if (wpa_s->global->p2p_group_formation == wpa_s)
677 wpa_s->global->p2p_group_formation = NULL;
678 wpa_msg(wpa_s->parent, MSG_INFO, P2P_EVENT_GROUP_STARTED
679 "%s GO ssid=\"%s\" freq=%d passphrase=\"%s\" "
680 "go_dev_addr=" MACSTR "%s",
682 wpa_ssid_txt(ssid->ssid, ssid->ssid_len),
684 params->passphrase ? params->passphrase : "",
685 MAC2STR(wpa_s->parent->own_addr),
686 params->persistent_group ? " [PERSISTENT]" : "");
688 if (params->persistent_group)
689 network_id = wpas_p2p_store_persistent_group(
691 wpa_s->parent->own_addr);
693 network_id = ssid->id;
694 wpas_notify_p2p_group_started(wpa_s, ssid, network_id, 0);
695 wpas_p2p_cross_connect_setup(wpa_s);
696 wpas_p2p_set_group_idle_timeout(wpa_s);
700 wpa_printf(MSG_DEBUG, "P2P: Setting up WPS for GO provisioning");
701 if (wpa_supplicant_ap_mac_addr_filter(wpa_s,
702 params->peer_interface_addr)) {
703 wpa_printf(MSG_DEBUG, "P2P: Failed to setup MAC address "
707 if (params->wps_method == WPS_PBC)
708 wpa_supplicant_ap_wps_pbc(wpa_s, params->peer_interface_addr,
710 else if (wpa_s->p2p_pin[0])
711 wpa_supplicant_ap_wps_pin(wpa_s, params->peer_interface_addr,
712 wpa_s->p2p_pin, NULL, 0);
713 os_free(wpa_s->go_params);
714 wpa_s->go_params = NULL;
718 static void wpas_start_wps_go(struct wpa_supplicant *wpa_s,
719 struct p2p_go_neg_results *params,
722 struct wpa_ssid *ssid;
724 if (wpas_copy_go_neg_results(wpa_s, params) < 0)
727 ssid = wpa_config_add_network(wpa_s->conf);
731 wpa_config_set_network_defaults(ssid);
734 ssid->p2p_persistent_group = params->persistent_group;
735 ssid->mode = group_formation ? WPAS_MODE_P2P_GROUP_FORMATION :
737 ssid->frequency = params->freq;
738 ssid->ssid = os_zalloc(params->ssid_len + 1);
740 os_memcpy(ssid->ssid, params->ssid, params->ssid_len);
741 ssid->ssid_len = params->ssid_len;
743 ssid->auth_alg = WPA_AUTH_ALG_OPEN;
744 ssid->key_mgmt = WPA_KEY_MGMT_PSK;
745 ssid->proto = WPA_PROTO_RSN;
746 ssid->pairwise_cipher = WPA_CIPHER_CCMP;
747 ssid->passphrase = os_strdup(params->passphrase);
749 wpa_s->ap_configured_cb = p2p_go_configured;
750 wpa_s->ap_configured_cb_ctx = wpa_s;
751 wpa_s->ap_configured_cb_data = wpa_s->go_params;
752 wpa_s->connect_without_scan = ssid;
753 wpa_s->reassociate = 1;
754 wpa_s->disconnected = 0;
755 wpa_supplicant_req_scan(wpa_s, 0, 0);
759 static void wpas_p2p_clone_config(struct wpa_supplicant *dst,
760 const struct wpa_supplicant *src)
762 struct wpa_config *d;
763 const struct wpa_config *s;
768 #define C(n) if (s->n) d->n = os_strdup(s->n)
777 os_memcpy(d->device_type, s->device_type, WPS_DEV_TYPE_LEN);
778 os_memcpy(d->sec_device_type, s->sec_device_type,
779 sizeof(d->sec_device_type));
780 d->num_sec_device_types = s->num_sec_device_types;
782 d->p2p_group_idle = s->p2p_group_idle;
783 d->p2p_intra_bss = s->p2p_intra_bss;
787 static int wpas_p2p_add_group_interface(struct wpa_supplicant *wpa_s,
788 enum wpa_driver_if_type type)
790 char ifname[120], force_ifname[120];
792 if (wpa_s->pending_interface_name[0]) {
793 wpa_printf(MSG_DEBUG, "P2P: Pending virtual interface exists "
794 "- skip creation of a new one");
795 if (is_zero_ether_addr(wpa_s->pending_interface_addr)) {
796 wpa_printf(MSG_DEBUG, "P2P: Pending virtual address "
797 "unknown?! ifname='%s'",
798 wpa_s->pending_interface_name);
804 os_snprintf(ifname, sizeof(ifname), "p2p-%s-%d", wpa_s->ifname,
805 wpa_s->p2p_group_idx);
806 if (os_strlen(ifname) >= IFNAMSIZ &&
807 os_strlen(wpa_s->ifname) < IFNAMSIZ) {
808 /* Try to avoid going over the IFNAMSIZ length limit */
809 os_snprintf(ifname, sizeof(ifname), "p2p-%d",
810 wpa_s->p2p_group_idx);
812 force_ifname[0] = '\0';
814 wpa_printf(MSG_DEBUG, "P2P: Create a new interface %s for the group",
816 wpa_s->p2p_group_idx++;
818 wpa_s->pending_interface_type = type;
819 if (wpa_drv_if_add(wpa_s, type, ifname, NULL, NULL, force_ifname,
820 wpa_s->pending_interface_addr, NULL) < 0) {
821 wpa_printf(MSG_ERROR, "P2P: Failed to create new group "
826 if (force_ifname[0]) {
827 wpa_printf(MSG_DEBUG, "P2P: Driver forced interface name %s",
829 os_strlcpy(wpa_s->pending_interface_name, force_ifname,
830 sizeof(wpa_s->pending_interface_name));
832 os_strlcpy(wpa_s->pending_interface_name, ifname,
833 sizeof(wpa_s->pending_interface_name));
834 wpa_printf(MSG_DEBUG, "P2P: Created pending virtual interface %s addr "
835 MACSTR, wpa_s->pending_interface_name,
836 MAC2STR(wpa_s->pending_interface_addr));
842 static void wpas_p2p_remove_pending_group_interface(
843 struct wpa_supplicant *wpa_s)
845 if (!wpa_s->pending_interface_name[0] ||
846 is_zero_ether_addr(wpa_s->pending_interface_addr))
847 return; /* No pending virtual interface */
849 wpa_printf(MSG_DEBUG, "P2P: Removing pending group interface %s",
850 wpa_s->pending_interface_name);
851 wpa_drv_if_remove(wpa_s, wpa_s->pending_interface_type,
852 wpa_s->pending_interface_name);
853 os_memset(wpa_s->pending_interface_addr, 0, ETH_ALEN);
854 wpa_s->pending_interface_name[0] = '\0';
858 static struct wpa_supplicant *
859 wpas_p2p_init_group_interface(struct wpa_supplicant *wpa_s, int go)
861 struct wpa_interface iface;
862 struct wpa_supplicant *group_wpa_s;
864 if (!wpa_s->pending_interface_name[0]) {
865 wpa_printf(MSG_ERROR, "P2P: No pending group interface");
866 if (!wpas_p2p_create_iface(wpa_s))
869 * Something has forced us to remove the pending interface; try
870 * to create a new one and hope for the best that we will get
871 * the same local address.
873 if (wpas_p2p_add_group_interface(wpa_s, go ? WPA_IF_P2P_GO :
874 WPA_IF_P2P_CLIENT) < 0)
878 os_memset(&iface, 0, sizeof(iface));
879 iface.ifname = wpa_s->pending_interface_name;
880 iface.driver = wpa_s->driver->name;
881 iface.ctrl_interface = wpa_s->conf->ctrl_interface;
882 iface.driver_param = wpa_s->conf->driver_param;
883 group_wpa_s = wpa_supplicant_add_iface(wpa_s->global, &iface);
884 if (group_wpa_s == NULL) {
885 wpa_printf(MSG_ERROR, "P2P: Failed to create new "
886 "wpa_supplicant interface");
889 wpa_s->pending_interface_name[0] = '\0';
890 group_wpa_s->parent = wpa_s;
891 group_wpa_s->p2p_group_interface = go ? P2P_GROUP_INTERFACE_GO :
892 P2P_GROUP_INTERFACE_CLIENT;
893 wpa_s->global->p2p_group_formation = group_wpa_s;
895 wpas_p2p_clone_config(group_wpa_s, wpa_s);
901 static void wpas_p2p_group_formation_timeout(void *eloop_ctx,
904 struct wpa_supplicant *wpa_s = eloop_ctx;
905 wpa_printf(MSG_DEBUG, "P2P: Group Formation timed out");
906 if (wpa_s->global->p2p)
907 p2p_group_formation_failed(wpa_s->global->p2p);
908 else if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT)
909 wpa_drv_p2p_group_formation_failed(wpa_s);
910 wpas_group_formation_completed(wpa_s, 0);
914 void wpas_go_neg_completed(void *ctx, struct p2p_go_neg_results *res)
916 struct wpa_supplicant *wpa_s = ctx;
918 if (wpa_s->off_channel_freq || wpa_s->roc_waiting_drv_freq) {
919 wpa_drv_cancel_remain_on_channel(wpa_s);
920 wpa_s->off_channel_freq = 0;
921 wpa_s->roc_waiting_drv_freq = 0;
925 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_GO_NEG_FAILURE "status=%d",
927 wpas_notify_p2p_go_neg_completed(wpa_s, res->status);
928 wpas_p2p_remove_pending_group_interface(wpa_s);
932 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_GO_NEG_SUCCESS);
933 wpas_notify_p2p_go_neg_completed(wpa_s, P2P_SC_SUCCESS);
935 if (wpa_s->create_p2p_iface) {
936 struct wpa_supplicant *group_wpa_s =
937 wpas_p2p_init_group_interface(wpa_s, res->role_go);
938 if (group_wpa_s == NULL) {
939 wpas_p2p_remove_pending_group_interface(wpa_s);
942 if (group_wpa_s != wpa_s) {
943 os_memcpy(group_wpa_s->p2p_pin, wpa_s->p2p_pin,
944 sizeof(group_wpa_s->p2p_pin));
945 group_wpa_s->p2p_wps_method = wpa_s->p2p_wps_method;
947 os_memset(wpa_s->pending_interface_addr, 0, ETH_ALEN);
948 wpa_s->pending_interface_name[0] = '\0';
949 group_wpa_s->p2p_in_provisioning = 1;
952 wpas_start_wps_go(group_wpa_s, res, 1);
954 wpas_start_wps_enrollee(group_wpa_s, res);
956 wpa_s->p2p_in_provisioning = 1;
957 wpa_s->global->p2p_group_formation = wpa_s;
960 wpas_start_wps_go(wpa_s, res, 1);
962 wpas_start_wps_enrollee(ctx, res);
965 wpa_s->p2p_long_listen = 0;
966 eloop_cancel_timeout(wpas_p2p_long_listen_timeout, wpa_s, NULL);
968 eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s, NULL);
969 eloop_register_timeout(15 + res->peer_config_timeout / 100,
970 (res->peer_config_timeout % 100) * 10000,
971 wpas_p2p_group_formation_timeout, wpa_s, NULL);
975 void wpas_go_neg_req_rx(void *ctx, const u8 *src, u16 dev_passwd_id)
977 struct wpa_supplicant *wpa_s = ctx;
978 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_GO_NEG_REQUEST MACSTR
979 " dev_passwd_id=%u", MAC2STR(src), dev_passwd_id);
981 wpas_notify_p2p_go_neg_req(wpa_s, src, dev_passwd_id);
985 void wpas_dev_found(void *ctx, const u8 *addr,
986 const struct p2p_peer_info *info,
989 struct wpa_supplicant *wpa_s = ctx;
990 char devtype[WPS_DEV_TYPE_BUFSIZE];
992 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_DEVICE_FOUND MACSTR
993 " p2p_dev_addr=" MACSTR
994 " pri_dev_type=%s name='%s' config_methods=0x%x "
995 "dev_capab=0x%x group_capab=0x%x",
996 MAC2STR(addr), MAC2STR(info->p2p_device_addr),
997 wps_dev_type_bin2str(info->pri_dev_type, devtype,
999 info->device_name, info->config_methods,
1000 info->dev_capab, info->group_capab);
1002 wpas_notify_p2p_device_found(ctx, info->p2p_device_addr, new_device);
1006 static void wpas_dev_lost(void *ctx, const u8 *dev_addr)
1008 struct wpa_supplicant *wpa_s = ctx;
1010 wpas_notify_p2p_device_lost(wpa_s, dev_addr);
1014 static int wpas_start_listen(void *ctx, unsigned int freq,
1015 unsigned int duration,
1016 const struct wpabuf *probe_resp_ie)
1018 struct wpa_supplicant *wpa_s = ctx;
1020 wpa_drv_set_ap_wps_ie(wpa_s, NULL, probe_resp_ie, NULL);
1022 if (wpa_drv_probe_req_report(wpa_s, 1) < 0) {
1023 wpa_printf(MSG_DEBUG, "P2P: Failed to request the driver to "
1024 "report received Probe Request frames");
1028 wpa_s->pending_listen_freq = freq;
1029 wpa_s->pending_listen_duration = duration;
1031 if (wpa_drv_remain_on_channel(wpa_s, freq, duration) < 0) {
1032 wpa_printf(MSG_DEBUG, "P2P: Failed to request the driver "
1033 "to remain on channel (%u MHz) for Listen "
1035 wpa_s->pending_listen_freq = 0;
1038 wpa_s->off_channel_freq = 0;
1039 wpa_s->roc_waiting_drv_freq = freq;
1045 static void wpas_stop_listen(void *ctx)
1047 struct wpa_supplicant *wpa_s = ctx;
1048 if (wpa_s->off_channel_freq || wpa_s->roc_waiting_drv_freq) {
1049 wpa_drv_cancel_remain_on_channel(wpa_s);
1050 wpa_s->off_channel_freq = 0;
1051 wpa_s->roc_waiting_drv_freq = 0;
1053 wpa_drv_set_ap_wps_ie(wpa_s, NULL, NULL, NULL);
1054 wpa_drv_probe_req_report(wpa_s, 0);
1058 static int wpas_send_probe_resp(void *ctx, const struct wpabuf *buf)
1060 struct wpa_supplicant *wpa_s = ctx;
1061 return wpa_drv_send_mlme(wpa_s, wpabuf_head(buf), wpabuf_len(buf));
1065 static struct p2p_srv_bonjour *
1066 wpas_p2p_service_get_bonjour(struct wpa_supplicant *wpa_s,
1067 const struct wpabuf *query)
1069 struct p2p_srv_bonjour *bsrv;
1072 len = wpabuf_len(query);
1073 dl_list_for_each(bsrv, &wpa_s->global->p2p_srv_bonjour,
1074 struct p2p_srv_bonjour, list) {
1075 if (len == wpabuf_len(bsrv->query) &&
1076 os_memcmp(wpabuf_head(query), wpabuf_head(bsrv->query),
1084 static struct p2p_srv_upnp *
1085 wpas_p2p_service_get_upnp(struct wpa_supplicant *wpa_s, u8 version,
1086 const char *service)
1088 struct p2p_srv_upnp *usrv;
1090 dl_list_for_each(usrv, &wpa_s->global->p2p_srv_upnp,
1091 struct p2p_srv_upnp, list) {
1092 if (version == usrv->version &&
1093 os_strcmp(service, usrv->service) == 0)
1100 static void wpas_sd_add_proto_not_avail(struct wpabuf *resp, u8 srv_proto,
1105 if (wpabuf_tailroom(resp) < 5)
1108 /* Length (to be filled) */
1109 len_pos = wpabuf_put(resp, 2);
1110 wpabuf_put_u8(resp, srv_proto);
1111 wpabuf_put_u8(resp, srv_trans_id);
1113 wpabuf_put_u8(resp, P2P_SD_PROTO_NOT_AVAILABLE);
1114 /* Response Data: empty */
1115 WPA_PUT_LE16(len_pos, (u8 *) wpabuf_put(resp, 0) - len_pos - 2);
1119 static void wpas_sd_all_bonjour(struct wpa_supplicant *wpa_s,
1120 struct wpabuf *resp, u8 srv_trans_id)
1122 struct p2p_srv_bonjour *bsrv;
1125 wpa_printf(MSG_DEBUG, "P2P: SD Request for all Bonjour services");
1127 if (dl_list_empty(&wpa_s->global->p2p_srv_bonjour)) {
1128 wpa_printf(MSG_DEBUG, "P2P: Bonjour protocol not available");
1132 dl_list_for_each(bsrv, &wpa_s->global->p2p_srv_bonjour,
1133 struct p2p_srv_bonjour, list) {
1134 if (wpabuf_tailroom(resp) <
1135 5 + wpabuf_len(bsrv->query) + wpabuf_len(bsrv->resp))
1137 /* Length (to be filled) */
1138 len_pos = wpabuf_put(resp, 2);
1139 wpabuf_put_u8(resp, P2P_SERV_BONJOUR);
1140 wpabuf_put_u8(resp, srv_trans_id);
1142 wpabuf_put_u8(resp, P2P_SD_SUCCESS);
1143 wpa_hexdump_ascii(MSG_DEBUG, "P2P: Matching Bonjour service",
1144 wpabuf_head(bsrv->resp),
1145 wpabuf_len(bsrv->resp));
1147 wpabuf_put_buf(resp, bsrv->query); /* Key */
1148 wpabuf_put_buf(resp, bsrv->resp); /* Value */
1149 WPA_PUT_LE16(len_pos, (u8 *) wpabuf_put(resp, 0) - len_pos -
1155 static void wpas_sd_req_bonjour(struct wpa_supplicant *wpa_s,
1156 struct wpabuf *resp, u8 srv_trans_id,
1157 const u8 *query, size_t query_len)
1159 struct p2p_srv_bonjour *bsrv;
1163 wpa_hexdump_ascii(MSG_DEBUG, "P2P: SD Request for Bonjour",
1165 if (dl_list_empty(&wpa_s->global->p2p_srv_bonjour)) {
1166 wpa_printf(MSG_DEBUG, "P2P: Bonjour protocol not available");
1167 wpas_sd_add_proto_not_avail(resp, P2P_SERV_BONJOUR,
1172 if (query_len == 0) {
1173 wpas_sd_all_bonjour(wpa_s, resp, srv_trans_id);
1177 if (wpabuf_tailroom(resp) < 5)
1179 /* Length (to be filled) */
1180 len_pos = wpabuf_put(resp, 2);
1181 wpabuf_put_u8(resp, P2P_SERV_BONJOUR);
1182 wpabuf_put_u8(resp, srv_trans_id);
1184 wpabuf_set(&buf, query, query_len);
1185 bsrv = wpas_p2p_service_get_bonjour(wpa_s, &buf);
1187 wpa_printf(MSG_DEBUG, "P2P: Requested Bonjour service not "
1191 wpabuf_put_u8(resp, P2P_SD_REQUESTED_INFO_NOT_AVAILABLE);
1192 /* Response Data: empty */
1193 WPA_PUT_LE16(len_pos, (u8 *) wpabuf_put(resp, 0) - len_pos -
1199 wpabuf_put_u8(resp, P2P_SD_SUCCESS);
1200 wpa_hexdump_ascii(MSG_DEBUG, "P2P: Matching Bonjour service",
1201 wpabuf_head(bsrv->resp), wpabuf_len(bsrv->resp));
1203 if (wpabuf_tailroom(resp) >=
1204 wpabuf_len(bsrv->query) + wpabuf_len(bsrv->resp)) {
1206 wpabuf_put_buf(resp, bsrv->query); /* Key */
1207 wpabuf_put_buf(resp, bsrv->resp); /* Value */
1209 WPA_PUT_LE16(len_pos, (u8 *) wpabuf_put(resp, 0) - len_pos - 2);
1213 static void wpas_sd_all_upnp(struct wpa_supplicant *wpa_s,
1214 struct wpabuf *resp, u8 srv_trans_id)
1216 struct p2p_srv_upnp *usrv;
1219 wpa_printf(MSG_DEBUG, "P2P: SD Request for all UPnP services");
1221 if (dl_list_empty(&wpa_s->global->p2p_srv_upnp)) {
1222 wpa_printf(MSG_DEBUG, "P2P: UPnP protocol not available");
1226 dl_list_for_each(usrv, &wpa_s->global->p2p_srv_upnp,
1227 struct p2p_srv_upnp, list) {
1228 if (wpabuf_tailroom(resp) < 5 + 1 + os_strlen(usrv->service))
1231 /* Length (to be filled) */
1232 len_pos = wpabuf_put(resp, 2);
1233 wpabuf_put_u8(resp, P2P_SERV_UPNP);
1234 wpabuf_put_u8(resp, srv_trans_id);
1237 wpabuf_put_u8(resp, P2P_SD_SUCCESS);
1239 wpabuf_put_u8(resp, usrv->version);
1240 wpa_printf(MSG_DEBUG, "P2P: Matching UPnP Service: %s",
1242 wpabuf_put_str(resp, usrv->service);
1243 WPA_PUT_LE16(len_pos, (u8 *) wpabuf_put(resp, 0) - len_pos -
1249 static void wpas_sd_req_upnp(struct wpa_supplicant *wpa_s,
1250 struct wpabuf *resp, u8 srv_trans_id,
1251 const u8 *query, size_t query_len)
1253 struct p2p_srv_upnp *usrv;
1259 wpa_hexdump_ascii(MSG_DEBUG, "P2P: SD Request for UPnP",
1262 if (dl_list_empty(&wpa_s->global->p2p_srv_upnp)) {
1263 wpa_printf(MSG_DEBUG, "P2P: UPnP protocol not available");
1264 wpas_sd_add_proto_not_avail(resp, P2P_SERV_UPNP,
1269 if (query_len == 0) {
1270 wpas_sd_all_upnp(wpa_s, resp, srv_trans_id);
1274 if (wpabuf_tailroom(resp) < 5)
1277 /* Length (to be filled) */
1278 len_pos = wpabuf_put(resp, 2);
1279 wpabuf_put_u8(resp, P2P_SERV_UPNP);
1280 wpabuf_put_u8(resp, srv_trans_id);
1283 str = os_malloc(query_len);
1286 os_memcpy(str, query + 1, query_len - 1);
1287 str[query_len - 1] = '\0';
1289 dl_list_for_each(usrv, &wpa_s->global->p2p_srv_upnp,
1290 struct p2p_srv_upnp, list) {
1291 if (version != usrv->version)
1294 if (os_strcmp(str, "ssdp:all") != 0 &&
1295 os_strstr(usrv->service, str) == NULL)
1298 if (wpabuf_tailroom(resp) < 2)
1302 wpabuf_put_u8(resp, P2P_SD_SUCCESS);
1304 wpabuf_put_u8(resp, version);
1306 wpabuf_put_u8(resp, ',');
1310 wpa_printf(MSG_DEBUG, "P2P: Matching UPnP Service: %s",
1312 if (wpabuf_tailroom(resp) < os_strlen(usrv->service))
1314 wpabuf_put_str(resp, usrv->service);
1319 wpa_printf(MSG_DEBUG, "P2P: Requested UPnP service not "
1322 wpabuf_put_u8(resp, P2P_SD_REQUESTED_INFO_NOT_AVAILABLE);
1323 /* Response Data: empty */
1326 WPA_PUT_LE16(len_pos, (u8 *) wpabuf_put(resp, 0) - len_pos - 2);
1330 void wpas_sd_request(void *ctx, int freq, const u8 *sa, u8 dialog_token,
1331 u16 update_indic, const u8 *tlvs, size_t tlvs_len)
1333 struct wpa_supplicant *wpa_s = ctx;
1334 const u8 *pos = tlvs;
1335 const u8 *end = tlvs + tlvs_len;
1338 struct wpabuf *resp;
1339 u8 srv_proto, srv_trans_id;
1343 wpa_hexdump(MSG_MSGDUMP, "P2P: Service Discovery Request TLVs",
1345 buf_len = 2 * tlvs_len + 1;
1346 buf = os_malloc(buf_len);
1348 wpa_snprintf_hex(buf, buf_len, tlvs, tlvs_len);
1349 wpa_msg_ctrl(wpa_s, MSG_INFO, P2P_EVENT_SERV_DISC_REQ "%d "
1351 freq, MAC2STR(sa), dialog_token, update_indic,
1356 if (wpa_s->p2p_sd_over_ctrl_iface)
1357 return; /* to be processed by an external program */
1359 resp = wpabuf_alloc(10000);
1363 while (pos + 1 < end) {
1364 wpa_printf(MSG_DEBUG, "P2P: Service Request TLV");
1365 slen = WPA_GET_LE16(pos);
1367 if (pos + slen > end || slen < 2) {
1368 wpa_printf(MSG_DEBUG, "P2P: Unexpected Query Data "
1373 tlv_end = pos + slen;
1376 wpa_printf(MSG_DEBUG, "P2P: Service Protocol Type %u",
1378 srv_trans_id = *pos++;
1379 wpa_printf(MSG_DEBUG, "P2P: Service Transaction ID %u",
1382 wpa_hexdump(MSG_MSGDUMP, "P2P: Query Data",
1383 pos, tlv_end - pos);
1386 if (wpa_s->force_long_sd) {
1387 wpa_printf(MSG_DEBUG, "P2P: SD test - force long "
1389 wpas_sd_all_bonjour(wpa_s, resp, srv_trans_id);
1390 wpas_sd_all_upnp(wpa_s, resp, srv_trans_id);
1394 switch (srv_proto) {
1395 case P2P_SERV_ALL_SERVICES:
1396 wpa_printf(MSG_DEBUG, "P2P: Service Discovery Request "
1397 "for all services");
1398 if (dl_list_empty(&wpa_s->global->p2p_srv_upnp) &&
1399 dl_list_empty(&wpa_s->global->p2p_srv_bonjour)) {
1400 wpa_printf(MSG_DEBUG, "P2P: No service "
1401 "discovery protocols available");
1402 wpas_sd_add_proto_not_avail(
1403 resp, P2P_SERV_ALL_SERVICES,
1407 wpas_sd_all_bonjour(wpa_s, resp, srv_trans_id);
1408 wpas_sd_all_upnp(wpa_s, resp, srv_trans_id);
1410 case P2P_SERV_BONJOUR:
1411 wpas_sd_req_bonjour(wpa_s, resp, srv_trans_id,
1412 pos, tlv_end - pos);
1415 wpas_sd_req_upnp(wpa_s, resp, srv_trans_id,
1416 pos, tlv_end - pos);
1419 wpa_printf(MSG_DEBUG, "P2P: Unavailable service "
1420 "protocol %u", srv_proto);
1421 wpas_sd_add_proto_not_avail(resp, srv_proto,
1430 wpas_notify_p2p_sd_request(wpa_s, freq, sa, dialog_token,
1431 update_indic, tlvs, tlvs_len);
1433 wpas_p2p_sd_response(wpa_s, freq, sa, dialog_token, resp);
1439 void wpas_sd_response(void *ctx, const u8 *sa, u16 update_indic,
1440 const u8 *tlvs, size_t tlvs_len)
1442 struct wpa_supplicant *wpa_s = ctx;
1443 const u8 *pos = tlvs;
1444 const u8 *end = tlvs + tlvs_len;
1450 wpa_hexdump(MSG_MSGDUMP, "P2P: Service Discovery Response TLVs",
1452 if (tlvs_len > 1500) {
1453 /* TODO: better way for handling this */
1454 wpa_msg_ctrl(wpa_s, MSG_INFO,
1455 P2P_EVENT_SERV_DISC_RESP MACSTR
1456 " %u <long response: %u bytes>",
1457 MAC2STR(sa), update_indic,
1458 (unsigned int) tlvs_len);
1460 buf_len = 2 * tlvs_len + 1;
1461 buf = os_malloc(buf_len);
1463 wpa_snprintf_hex(buf, buf_len, tlvs, tlvs_len);
1464 wpa_msg_ctrl(wpa_s, MSG_INFO,
1465 P2P_EVENT_SERV_DISC_RESP MACSTR " %u %s",
1466 MAC2STR(sa), update_indic, buf);
1472 u8 srv_proto, srv_trans_id, status;
1474 wpa_printf(MSG_DEBUG, "P2P: Service Response TLV");
1475 slen = WPA_GET_LE16(pos);
1477 if (pos + slen > end || slen < 3) {
1478 wpa_printf(MSG_DEBUG, "P2P: Unexpected Response Data "
1482 tlv_end = pos + slen;
1485 wpa_printf(MSG_DEBUG, "P2P: Service Protocol Type %u",
1487 srv_trans_id = *pos++;
1488 wpa_printf(MSG_DEBUG, "P2P: Service Transaction ID %u",
1491 wpa_printf(MSG_DEBUG, "P2P: Status Code ID %u",
1494 wpa_hexdump(MSG_MSGDUMP, "P2P: Response Data",
1495 pos, tlv_end - pos);
1500 wpas_notify_p2p_sd_response(wpa_s, sa, update_indic, tlvs, tlvs_len);
1504 void * wpas_p2p_sd_request(struct wpa_supplicant *wpa_s, const u8 *dst,
1505 const struct wpabuf *tlvs)
1507 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT)
1508 return (void *) wpa_drv_p2p_sd_request(wpa_s, dst, tlvs);
1509 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
1511 return p2p_sd_request(wpa_s->global->p2p, dst, tlvs);
1515 void * wpas_p2p_sd_request_upnp(struct wpa_supplicant *wpa_s, const u8 *dst,
1516 u8 version, const char *query)
1518 struct wpabuf *tlvs;
1521 tlvs = wpabuf_alloc(2 + 1 + 1 + 1 + os_strlen(query));
1524 wpabuf_put_le16(tlvs, 1 + 1 + 1 + os_strlen(query));
1525 wpabuf_put_u8(tlvs, P2P_SERV_UPNP); /* Service Protocol Type */
1526 wpabuf_put_u8(tlvs, 1); /* Service Transaction ID */
1527 wpabuf_put_u8(tlvs, version);
1528 wpabuf_put_str(tlvs, query);
1529 ret = wpas_p2p_sd_request(wpa_s, dst, tlvs);
1535 int wpas_p2p_sd_cancel_request(struct wpa_supplicant *wpa_s, void *req)
1537 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT)
1538 return wpa_drv_p2p_sd_cancel_request(wpa_s, (u64) req);
1539 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
1541 return p2p_sd_cancel_request(wpa_s->global->p2p, req);
1545 void wpas_p2p_sd_response(struct wpa_supplicant *wpa_s, int freq,
1546 const u8 *dst, u8 dialog_token,
1547 const struct wpabuf *resp_tlvs)
1549 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT) {
1550 wpa_drv_p2p_sd_response(wpa_s, freq, dst, dialog_token,
1554 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
1556 p2p_sd_response(wpa_s->global->p2p, freq, dst, dialog_token,
1561 void wpas_p2p_sd_service_update(struct wpa_supplicant *wpa_s)
1563 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT) {
1564 wpa_drv_p2p_service_update(wpa_s);
1567 if (wpa_s->global->p2p)
1568 p2p_sd_service_update(wpa_s->global->p2p);
1572 static void wpas_p2p_srv_bonjour_free(struct p2p_srv_bonjour *bsrv)
1574 dl_list_del(&bsrv->list);
1575 wpabuf_free(bsrv->query);
1576 wpabuf_free(bsrv->resp);
1581 static void wpas_p2p_srv_upnp_free(struct p2p_srv_upnp *usrv)
1583 dl_list_del(&usrv->list);
1584 os_free(usrv->service);
1589 void wpas_p2p_service_flush(struct wpa_supplicant *wpa_s)
1591 struct p2p_srv_bonjour *bsrv, *bn;
1592 struct p2p_srv_upnp *usrv, *un;
1594 dl_list_for_each_safe(bsrv, bn, &wpa_s->global->p2p_srv_bonjour,
1595 struct p2p_srv_bonjour, list)
1596 wpas_p2p_srv_bonjour_free(bsrv);
1598 dl_list_for_each_safe(usrv, un, &wpa_s->global->p2p_srv_upnp,
1599 struct p2p_srv_upnp, list)
1600 wpas_p2p_srv_upnp_free(usrv);
1602 wpas_p2p_sd_service_update(wpa_s);
1606 int wpas_p2p_service_add_bonjour(struct wpa_supplicant *wpa_s,
1607 struct wpabuf *query, struct wpabuf *resp)
1609 struct p2p_srv_bonjour *bsrv;
1611 bsrv = wpas_p2p_service_get_bonjour(wpa_s, query);
1614 wpabuf_free(bsrv->resp);
1619 bsrv = os_zalloc(sizeof(*bsrv));
1622 bsrv->query = query;
1624 dl_list_add(&wpa_s->global->p2p_srv_bonjour, &bsrv->list);
1626 wpas_p2p_sd_service_update(wpa_s);
1631 int wpas_p2p_service_del_bonjour(struct wpa_supplicant *wpa_s,
1632 const struct wpabuf *query)
1634 struct p2p_srv_bonjour *bsrv;
1636 bsrv = wpas_p2p_service_get_bonjour(wpa_s, query);
1639 wpas_p2p_srv_bonjour_free(bsrv);
1640 wpas_p2p_sd_service_update(wpa_s);
1645 int wpas_p2p_service_add_upnp(struct wpa_supplicant *wpa_s, u8 version,
1646 const char *service)
1648 struct p2p_srv_upnp *usrv;
1650 if (wpas_p2p_service_get_upnp(wpa_s, version, service))
1651 return 0; /* Already listed */
1652 usrv = os_zalloc(sizeof(*usrv));
1655 usrv->version = version;
1656 usrv->service = os_strdup(service);
1657 if (usrv->service == NULL) {
1661 dl_list_add(&wpa_s->global->p2p_srv_upnp, &usrv->list);
1663 wpas_p2p_sd_service_update(wpa_s);
1668 int wpas_p2p_service_del_upnp(struct wpa_supplicant *wpa_s, u8 version,
1669 const char *service)
1671 struct p2p_srv_upnp *usrv;
1673 usrv = wpas_p2p_service_get_upnp(wpa_s, version, service);
1676 wpas_p2p_srv_upnp_free(usrv);
1677 wpas_p2p_sd_service_update(wpa_s);
1682 static void wpas_prov_disc_local_display(struct wpa_supplicant *wpa_s,
1683 const u8 *peer, const char *params,
1684 unsigned int generated_pin)
1686 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_SHOW_PIN MACSTR " %08d%s",
1687 MAC2STR(peer), generated_pin, params);
1691 static void wpas_prov_disc_local_keypad(struct wpa_supplicant *wpa_s,
1692 const u8 *peer, const char *params)
1694 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_ENTER_PIN MACSTR "%s",
1695 MAC2STR(peer), params);
1699 void wpas_prov_disc_req(void *ctx, const u8 *peer, u16 config_methods,
1700 const u8 *dev_addr, const u8 *pri_dev_type,
1701 const char *dev_name, u16 supp_config_methods,
1702 u8 dev_capab, u8 group_capab)
1704 struct wpa_supplicant *wpa_s = ctx;
1705 char devtype[WPS_DEV_TYPE_BUFSIZE];
1707 u8 empty_dev_type[8];
1708 unsigned int generated_pin = 0;
1710 if (pri_dev_type == NULL) {
1711 os_memset(empty_dev_type, 0, sizeof(empty_dev_type));
1712 pri_dev_type = empty_dev_type;
1714 os_snprintf(params, sizeof(params), " p2p_dev_addr=" MACSTR
1715 " pri_dev_type=%s name='%s' config_methods=0x%x "
1716 "dev_capab=0x%x group_capab=0x%x",
1718 wps_dev_type_bin2str(pri_dev_type, devtype,
1720 dev_name, supp_config_methods, dev_capab, group_capab);
1721 params[sizeof(params) - 1] = '\0';
1723 if (config_methods & WPS_CONFIG_DISPLAY) {
1724 generated_pin = wps_generate_pin();
1725 wpas_prov_disc_local_display(wpa_s, peer, params,
1727 } else if (config_methods & WPS_CONFIG_KEYPAD)
1728 wpas_prov_disc_local_keypad(wpa_s, peer, params);
1729 else if (config_methods & WPS_CONFIG_PUSHBUTTON)
1730 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_PBC_REQ MACSTR
1731 "%s", MAC2STR(peer), params);
1733 wpas_notify_p2p_provision_discovery(wpa_s, peer, 1 /* request */,
1734 P2P_PROV_DISC_SUCCESS,
1735 config_methods, generated_pin);
1739 void wpas_prov_disc_resp(void *ctx, const u8 *peer, u16 config_methods)
1741 struct wpa_supplicant *wpa_s = ctx;
1742 unsigned int generated_pin = 0;
1744 if (config_methods & WPS_CONFIG_DISPLAY)
1745 wpas_prov_disc_local_keypad(wpa_s, peer, "");
1746 else if (config_methods & WPS_CONFIG_KEYPAD) {
1747 generated_pin = wps_generate_pin();
1748 wpas_prov_disc_local_display(wpa_s, peer, "", generated_pin);
1749 } else if (config_methods & WPS_CONFIG_PUSHBUTTON)
1750 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_PBC_RESP MACSTR,
1753 wpas_notify_p2p_provision_discovery(wpa_s, peer, 0 /* response */,
1754 P2P_PROV_DISC_SUCCESS,
1755 config_methods, generated_pin);
1757 if (wpa_s->pending_pd_before_join &&
1758 (os_memcmp(peer, wpa_s->pending_join_dev_addr, ETH_ALEN) == 0 ||
1759 os_memcmp(peer, wpa_s->pending_join_iface_addr, ETH_ALEN) == 0)) {
1760 wpa_s->pending_pd_before_join = 0;
1761 wpa_printf(MSG_DEBUG, "P2P: Starting pending "
1762 "join-existing-group operation");
1763 wpas_p2p_join_start(wpa_s);
1768 void wpas_prov_disc_fail(void *ctx, const u8 *peer,
1769 enum p2p_prov_disc_status status)
1771 struct wpa_supplicant *wpa_s = ctx;
1773 wpas_notify_p2p_provision_discovery(wpa_s, peer, 0 /* response */,
1778 static u8 wpas_invitation_process(void *ctx, const u8 *sa, const u8 *bssid,
1779 const u8 *go_dev_addr, const u8 *ssid,
1780 size_t ssid_len, int *go, u8 *group_bssid,
1781 int *force_freq, int persistent_group)
1783 struct wpa_supplicant *wpa_s = ctx;
1785 u8 cur_bssid[ETH_ALEN];
1787 struct wpa_supplicant *grp;
1789 if (!persistent_group) {
1790 wpa_printf(MSG_DEBUG, "P2P: Invitation from " MACSTR
1791 " to join an active group", MAC2STR(sa));
1792 if (!is_zero_ether_addr(wpa_s->p2p_auth_invite) &&
1793 (os_memcmp(go_dev_addr, wpa_s->p2p_auth_invite, ETH_ALEN)
1795 os_memcmp(sa, wpa_s->p2p_auth_invite, ETH_ALEN) == 0)) {
1796 wpa_printf(MSG_DEBUG, "P2P: Accept previously "
1797 "authorized invitation");
1801 * Do not accept the invitation automatically; notify user and
1804 return P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE;
1807 grp = wpas_get_p2p_group(wpa_s, ssid, ssid_len, go);
1809 wpa_printf(MSG_DEBUG, "P2P: Accept invitation to already "
1810 "running persistent group");
1812 os_memcpy(group_bssid, grp->own_addr, ETH_ALEN);
1816 if (!wpa_s->conf->persistent_reconnect)
1817 return P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE;
1819 for (s = wpa_s->conf->ssid; s; s = s->next) {
1820 if (s->disabled == 2 &&
1821 os_memcmp(s->bssid, go_dev_addr, ETH_ALEN) == 0 &&
1822 s->ssid_len == ssid_len &&
1823 os_memcmp(ssid, s->ssid, ssid_len) == 0)
1828 wpa_printf(MSG_DEBUG, "P2P: Invitation from " MACSTR
1829 " requested reinvocation of an unknown group",
1831 return P2P_SC_FAIL_UNKNOWN_GROUP;
1834 if (s->mode == WPAS_MODE_P2P_GO && !wpas_p2p_create_iface(wpa_s)) {
1836 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
1837 wpa_printf(MSG_DEBUG, "P2P: The only available "
1838 "interface is already in use - reject "
1840 return P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE;
1842 os_memcpy(group_bssid, wpa_s->own_addr, ETH_ALEN);
1843 } else if (s->mode == WPAS_MODE_P2P_GO) {
1845 if (wpas_p2p_add_group_interface(wpa_s, WPA_IF_P2P_GO) < 0)
1847 wpa_printf(MSG_ERROR, "P2P: Failed to allocate a new "
1848 "interface address for the group");
1849 return P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE;
1851 os_memcpy(group_bssid, wpa_s->pending_interface_addr,
1856 if (wpa_s->current_ssid && wpa_drv_get_bssid(wpa_s, cur_bssid) == 0 &&
1857 wpa_s->assoc_freq) {
1858 wpa_printf(MSG_DEBUG, "P2P: Trying to force channel to match "
1859 "the channel we are already using");
1860 *force_freq = wpa_s->assoc_freq;
1863 res = wpa_drv_shared_freq(wpa_s);
1865 wpa_printf(MSG_DEBUG, "P2P: Trying to force channel to match "
1866 "with the channel we are already using on a "
1867 "shared interface");
1871 return P2P_SC_SUCCESS;
1875 static void wpas_invitation_received(void *ctx, const u8 *sa, const u8 *bssid,
1876 const u8 *ssid, size_t ssid_len,
1877 const u8 *go_dev_addr, u8 status,
1880 struct wpa_supplicant *wpa_s = ctx;
1883 for (s = wpa_s->conf->ssid; s; s = s->next) {
1884 if (s->disabled == 2 &&
1885 s->ssid_len == ssid_len &&
1886 os_memcmp(ssid, s->ssid, ssid_len) == 0)
1890 if (status == P2P_SC_SUCCESS) {
1891 wpa_printf(MSG_DEBUG, "P2P: Invitation from peer " MACSTR
1892 " was accepted; op_freq=%d MHz",
1893 MAC2STR(sa), op_freq);
1895 wpas_p2p_group_add_persistent(
1896 wpa_s, s, s->mode == WPAS_MODE_P2P_GO, 0);
1898 wpas_p2p_join(wpa_s, bssid, go_dev_addr,
1899 wpa_s->p2p_wps_method);
1904 if (status != P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE) {
1905 wpa_printf(MSG_DEBUG, "P2P: Invitation from peer " MACSTR
1906 " was rejected (status %u)", MAC2STR(sa), status);
1912 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RECEIVED
1913 "sa=" MACSTR " go_dev_addr=" MACSTR
1914 " bssid=" MACSTR " unknown-network",
1915 MAC2STR(sa), MAC2STR(go_dev_addr),
1918 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RECEIVED
1919 "sa=" MACSTR " go_dev_addr=" MACSTR
1921 MAC2STR(sa), MAC2STR(go_dev_addr));
1926 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RECEIVED "sa=" MACSTR
1927 " persistent=%d", MAC2STR(sa), s->id);
1931 static void wpas_invitation_result(void *ctx, int status, const u8 *bssid)
1933 struct wpa_supplicant *wpa_s = ctx;
1934 struct wpa_ssid *ssid;
1937 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RESULT
1938 "status=%d " MACSTR,
1939 status, MAC2STR(bssid));
1941 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RESULT
1942 "status=%d ", status);
1944 wpas_notify_p2p_invitation_result(wpa_s, status, bssid);
1946 if (wpa_s->pending_invite_ssid_id == -1)
1947 return; /* Invitation to active group */
1949 if (status != P2P_SC_SUCCESS) {
1950 wpas_p2p_remove_pending_group_interface(wpa_s);
1954 ssid = wpa_config_get_network(wpa_s->conf,
1955 wpa_s->pending_invite_ssid_id);
1957 wpa_printf(MSG_ERROR, "P2P: Could not find persistent group "
1958 "data matching with invitation");
1962 wpas_p2p_group_add_persistent(wpa_s, ssid,
1963 ssid->mode == WPAS_MODE_P2P_GO, 0);
1967 static int wpas_p2p_default_channels(struct wpa_supplicant *wpa_s,
1968 struct p2p_channels *chan)
1972 wpa_printf(MSG_DEBUG, "P2P: Enable operating classes for 2.4 GHz "
1975 /* Operating class 81 - 2.4 GHz band channels 1..13 */
1976 chan->reg_class[cla].reg_class = 81;
1977 chan->reg_class[cla].channels = 11;
1978 for (i = 0; i < 11; i++)
1979 chan->reg_class[cla].channel[i] = i + 1;
1982 wpa_printf(MSG_DEBUG, "P2P: Enable operating classes for lower 5 GHz "
1985 /* Operating class 115 - 5 GHz, channels 36-48 */
1986 chan->reg_class[cla].reg_class = 115;
1987 chan->reg_class[cla].channels = 4;
1988 chan->reg_class[cla].channel[0] = 36;
1989 chan->reg_class[cla].channel[1] = 40;
1990 chan->reg_class[cla].channel[2] = 44;
1991 chan->reg_class[cla].channel[3] = 48;
1994 wpa_printf(MSG_DEBUG, "P2P: Enable operating classes for higher 5 GHz "
1997 /* Operating class 124 - 5 GHz, channels 149,153,157,161 */
1998 chan->reg_class[cla].reg_class = 124;
1999 chan->reg_class[cla].channels = 4;
2000 chan->reg_class[cla].channel[0] = 149;
2001 chan->reg_class[cla].channel[1] = 153;
2002 chan->reg_class[cla].channel[2] = 157;
2003 chan->reg_class[cla].channel[3] = 161;
2006 chan->reg_classes = cla;
2011 static struct hostapd_hw_modes * get_mode(struct hostapd_hw_modes *modes,
2013 enum hostapd_hw_mode mode)
2017 for (i = 0; i < num_modes; i++) {
2018 if (modes[i].mode == mode)
2026 static int has_channel(struct hostapd_hw_modes *mode, u8 chan, int *flags)
2030 for (i = 0; i < mode->num_channels; i++) {
2031 if (mode->channels[i].chan == chan) {
2033 *flags = mode->channels[i].flag;
2034 return !(mode->channels[i].flag &
2035 (HOSTAPD_CHAN_DISABLED |
2036 HOSTAPD_CHAN_PASSIVE_SCAN |
2037 HOSTAPD_CHAN_NO_IBSS |
2038 HOSTAPD_CHAN_RADAR));
2046 struct p2p_oper_class_map {
2047 enum hostapd_hw_mode mode;
2052 enum { BW20, BW40PLUS, BW40MINUS } bw;
2055 static int wpas_p2p_setup_channels(struct wpa_supplicant *wpa_s,
2056 struct p2p_channels *chan)
2058 struct hostapd_hw_modes *modes, *mode;
2059 u16 num_modes, flags;
2061 struct p2p_oper_class_map op_class[] = {
2062 { HOSTAPD_MODE_IEEE80211G, 81, 1, 13, 1, BW20 },
2063 { HOSTAPD_MODE_IEEE80211G, 82, 14, 14, 1, BW20 },
2064 #if 0 /* Do not enable HT40 on 2 GHz for now */
2065 { HOSTAPD_MODE_IEEE80211G, 83, 1, 9, 1, BW40PLUS },
2066 { HOSTAPD_MODE_IEEE80211G, 84, 5, 13, 1, BW40MINUS },
2068 { HOSTAPD_MODE_IEEE80211A, 115, 36, 48, 4, BW20 },
2069 { HOSTAPD_MODE_IEEE80211A, 124, 149, 161, 4, BW20 },
2070 { HOSTAPD_MODE_IEEE80211A, 116, 36, 44, 8, BW40PLUS },
2071 { HOSTAPD_MODE_IEEE80211A, 117, 40, 48, 8, BW40MINUS },
2072 { HOSTAPD_MODE_IEEE80211A, 126, 149, 157, 8, BW40PLUS },
2073 { HOSTAPD_MODE_IEEE80211A, 127, 153, 161, 8, BW40MINUS },
2074 { -1, 0, 0, 0, 0, BW20 }
2077 modes = wpa_drv_get_hw_feature_data(wpa_s, &num_modes, &flags);
2078 if (modes == NULL) {
2079 wpa_printf(MSG_DEBUG, "P2P: Driver did not support fetching "
2080 "of all supported channels; assume dualband "
2082 return wpas_p2p_default_channels(wpa_s, chan);
2087 for (op = 0; op_class[op].op_class; op++) {
2088 struct p2p_oper_class_map *o = &op_class[op];
2090 struct p2p_reg_class *reg = NULL;
2092 mode = get_mode(modes, num_modes, o->mode);
2095 for (ch = o->min_chan; ch <= o->max_chan; ch += o->inc) {
2097 if (!has_channel(mode, ch, &flag))
2099 if (o->bw == BW40MINUS &&
2100 (!(flag & HOSTAPD_CHAN_HT40MINUS) ||
2101 !has_channel(mode, ch - 4, NULL)))
2103 if (o->bw == BW40PLUS &&
2104 (!(flag & HOSTAPD_CHAN_HT40PLUS) ||
2105 !has_channel(mode, ch + 4, NULL)))
2108 wpa_printf(MSG_DEBUG, "P2P: Add operating "
2109 "class %u", o->op_class);
2110 reg = &chan->reg_class[cla];
2112 reg->reg_class = o->op_class;
2114 reg->channel[reg->channels] = ch;
2118 wpa_hexdump(MSG_DEBUG, "P2P: Channels",
2119 reg->channel, reg->channels);
2123 chan->reg_classes = cla;
2125 ieee80211_sta_free_hw_features(modes, num_modes);
2131 static int wpas_get_noa(void *ctx, const u8 *interface_addr, u8 *buf,
2134 struct wpa_supplicant *wpa_s = ctx;
2136 for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) {
2137 if (os_memcmp(wpa_s->own_addr, interface_addr, ETH_ALEN) == 0)
2143 return wpa_drv_get_noa(wpa_s, buf, buf_len);
2148 * wpas_p2p_init - Initialize P2P module for %wpa_supplicant
2149 * @global: Pointer to global data from wpa_supplicant_init()
2150 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
2151 * Returns: 0 on success, -1 on failure
2153 int wpas_p2p_init(struct wpa_global *global, struct wpa_supplicant *wpa_s)
2155 struct p2p_config p2p;
2159 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_CAPABLE))
2162 #ifdef CONFIG_CLIENT_MLME
2163 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT)) {
2164 wpa_s->mlme.public_action_cb = p2p_rx_action_mlme;
2165 wpa_s->mlme.public_action_cb_ctx = wpa_s;
2167 #endif /* CONFIG_CLIENT_MLME */
2169 if (wpa_drv_disable_11b_rates(wpa_s, 1) < 0) {
2170 wpa_printf(MSG_DEBUG, "P2P: Failed to disable 11b rates");
2171 /* Continue anyway; this is not really a fatal error */
2177 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT) {
2178 struct p2p_params params;
2180 wpa_printf(MSG_DEBUG, "P2P: Use driver-based P2P management");
2181 os_memset(¶ms, 0, sizeof(params));
2182 params.dev_name = wpa_s->conf->device_name;
2183 os_memcpy(params.pri_dev_type, wpa_s->conf->device_type,
2185 params.num_sec_dev_types = wpa_s->conf->num_sec_device_types;
2186 os_memcpy(params.sec_dev_type,
2187 wpa_s->conf->sec_device_type,
2188 params.num_sec_dev_types * WPS_DEV_TYPE_LEN);
2190 if (wpa_drv_p2p_set_params(wpa_s, ¶ms) < 0)
2196 os_memset(&p2p, 0, sizeof(p2p));
2197 p2p.msg_ctx = wpa_s;
2199 p2p.p2p_scan = wpas_p2p_scan;
2200 p2p.send_action = wpas_send_action;
2201 p2p.send_action_done = wpas_send_action_done;
2202 p2p.go_neg_completed = wpas_go_neg_completed;
2203 p2p.go_neg_req_rx = wpas_go_neg_req_rx;
2204 p2p.dev_found = wpas_dev_found;
2205 p2p.dev_lost = wpas_dev_lost;
2206 p2p.start_listen = wpas_start_listen;
2207 p2p.stop_listen = wpas_stop_listen;
2208 p2p.send_probe_resp = wpas_send_probe_resp;
2209 p2p.sd_request = wpas_sd_request;
2210 p2p.sd_response = wpas_sd_response;
2211 p2p.prov_disc_req = wpas_prov_disc_req;
2212 p2p.prov_disc_resp = wpas_prov_disc_resp;
2213 p2p.prov_disc_fail = wpas_prov_disc_fail;
2214 p2p.invitation_process = wpas_invitation_process;
2215 p2p.invitation_received = wpas_invitation_received;
2216 p2p.invitation_result = wpas_invitation_result;
2217 p2p.get_noa = wpas_get_noa;
2219 os_memcpy(wpa_s->global->p2p_dev_addr, wpa_s->own_addr, ETH_ALEN);
2220 os_memcpy(p2p.dev_addr, wpa_s->own_addr, ETH_ALEN);
2221 p2p.dev_name = wpa_s->conf->device_name;
2222 p2p.manufacturer = wpa_s->conf->manufacturer;
2223 p2p.model_name = wpa_s->conf->model_name;
2224 p2p.model_number = wpa_s->conf->model_number;
2225 p2p.serial_number = wpa_s->conf->serial_number;
2227 os_memcpy(p2p.uuid, wpa_s->wps->uuid, 16);
2228 p2p.config_methods = wpa_s->wps->config_methods;
2231 if (wpa_s->conf->p2p_listen_reg_class &&
2232 wpa_s->conf->p2p_listen_channel) {
2233 p2p.reg_class = wpa_s->conf->p2p_listen_reg_class;
2234 p2p.channel = wpa_s->conf->p2p_listen_channel;
2238 * Pick one of the social channels randomly as the listen
2241 os_get_random((u8 *) &r, sizeof(r));
2242 p2p.channel = 1 + (r % 3) * 5;
2244 wpa_printf(MSG_DEBUG, "P2P: Own listen channel: %d", p2p.channel);
2246 if (wpa_s->conf->p2p_oper_reg_class &&
2247 wpa_s->conf->p2p_oper_channel) {
2248 p2p.op_reg_class = wpa_s->conf->p2p_oper_reg_class;
2249 p2p.op_channel = wpa_s->conf->p2p_oper_channel;
2250 p2p.cfg_op_channel = 1;
2251 wpa_printf(MSG_DEBUG, "P2P: Configured operating channel: "
2252 "%d:%d", p2p.op_reg_class, p2p.op_channel);
2255 p2p.op_reg_class = 81;
2257 * Use random operation channel from (1, 6, 11) if no other
2258 * preference is indicated.
2260 os_get_random((u8 *) &r, sizeof(r));
2261 p2p.op_channel = 1 + (r % 3) * 5;
2262 p2p.cfg_op_channel = 0;
2263 wpa_printf(MSG_DEBUG, "P2P: Random operating channel: "
2264 "%d:%d", p2p.op_reg_class, p2p.op_channel);
2266 if (wpa_s->conf->country[0] && wpa_s->conf->country[1]) {
2267 os_memcpy(p2p.country, wpa_s->conf->country, 2);
2268 p2p.country[2] = 0x04;
2270 os_memcpy(p2p.country, "XX\x04", 3);
2272 if (wpas_p2p_setup_channels(wpa_s, &p2p.channels)) {
2273 wpa_printf(MSG_ERROR, "P2P: Failed to configure supported "
2278 os_memcpy(p2p.pri_dev_type, wpa_s->conf->device_type,
2281 p2p.num_sec_dev_types = wpa_s->conf->num_sec_device_types;
2282 os_memcpy(p2p.sec_dev_type, wpa_s->conf->sec_device_type,
2283 p2p.num_sec_dev_types * WPS_DEV_TYPE_LEN);
2285 p2p.concurrent_operations = !!(wpa_s->drv_flags &
2286 WPA_DRIVER_FLAGS_P2P_CONCURRENT);
2288 p2p.max_peers = 100;
2290 if (wpa_s->conf->p2p_ssid_postfix) {
2291 p2p.ssid_postfix_len =
2292 os_strlen(wpa_s->conf->p2p_ssid_postfix);
2293 if (p2p.ssid_postfix_len > sizeof(p2p.ssid_postfix))
2294 p2p.ssid_postfix_len = sizeof(p2p.ssid_postfix);
2295 os_memcpy(p2p.ssid_postfix, wpa_s->conf->p2p_ssid_postfix,
2296 p2p.ssid_postfix_len);
2299 p2p.p2p_intra_bss = wpa_s->conf->p2p_intra_bss;
2301 global->p2p = p2p_init(&p2p);
2302 if (global->p2p == NULL)
2305 for (i = 0; i < MAX_WPS_VENDOR_EXT; i++) {
2306 if (wpa_s->conf->wps_vendor_ext[i] == NULL)
2308 p2p_add_wps_vendor_extension(
2309 global->p2p, wpa_s->conf->wps_vendor_ext[i]);
2317 * wpas_p2p_deinit - Deinitialize per-interface P2P data
2318 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
2320 * This function deinitialize per-interface P2P data.
2322 void wpas_p2p_deinit(struct wpa_supplicant *wpa_s)
2324 if (wpa_s->driver && wpa_s->drv_priv)
2325 wpa_drv_probe_req_report(wpa_s, 0);
2326 os_free(wpa_s->go_params);
2327 wpa_s->go_params = NULL;
2328 eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s, NULL);
2329 eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL);
2330 wpa_s->p2p_long_listen = 0;
2331 eloop_cancel_timeout(wpas_p2p_long_listen_timeout, wpa_s, NULL);
2332 eloop_cancel_timeout(wpas_p2p_group_idle_timeout, wpa_s, NULL);
2333 wpas_p2p_remove_pending_group_interface(wpa_s);
2335 /* TODO: remove group interface from the driver if this wpa_s instance
2336 * is on top of a P2P group interface */
2341 * wpas_p2p_deinit_global - Deinitialize global P2P module
2342 * @global: Pointer to global data from wpa_supplicant_init()
2344 * This function deinitializes the global (per device) P2P module.
2346 void wpas_p2p_deinit_global(struct wpa_global *global)
2348 struct wpa_supplicant *wpa_s, *tmp;
2351 if (global->p2p == NULL)
2354 /* Remove remaining P2P group interfaces */
2355 wpa_s = global->ifaces;
2357 wpas_p2p_service_flush(wpa_s);
2358 while (wpa_s && wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE)
2359 wpa_s = wpa_s->next;
2361 enum wpa_driver_if_type type;
2362 tmp = global->ifaces;
2365 tmp->p2p_group_interface == NOT_P2P_GROUP_INTERFACE)) {
2370 ifname = os_strdup(tmp->ifname);
2371 type = wpas_p2p_if_type(tmp->p2p_group_interface);
2372 wpa_supplicant_remove_iface(global, tmp);
2374 wpa_drv_if_remove(wpa_s, type, ifname);
2379 * Deinit GO data on any possibly remaining interface (if main
2380 * interface is used as GO).
2382 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
2383 if (wpa_s->ap_iface)
2384 wpas_p2p_group_deinit(wpa_s);
2387 p2p_deinit(global->p2p);
2392 static int wpas_p2p_create_iface(struct wpa_supplicant *wpa_s)
2394 if (wpa_s->drv_flags &
2395 (WPA_DRIVER_FLAGS_P2P_DEDICATED_INTERFACE |
2396 WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P))
2397 return 1; /* P2P group requires a new interface in every case
2399 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_CONCURRENT))
2400 return 0; /* driver does not support concurrent operations */
2401 if (wpa_s->global->ifaces->next)
2402 return 1; /* more that one interface already in use */
2403 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
2404 return 1; /* this interface is already in use */
2409 static int wpas_p2p_start_go_neg(struct wpa_supplicant *wpa_s,
2410 const u8 *peer_addr,
2411 enum p2p_wps_method wps_method,
2412 int go_intent, const u8 *own_interface_addr,
2413 unsigned int force_freq, int persistent_group)
2415 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT) {
2416 return wpa_drv_p2p_connect(wpa_s, peer_addr, wps_method,
2417 go_intent, own_interface_addr,
2418 force_freq, persistent_group);
2421 return p2p_connect(wpa_s->global->p2p, peer_addr, wps_method,
2422 go_intent, own_interface_addr, force_freq,
2427 static int wpas_p2p_auth_go_neg(struct wpa_supplicant *wpa_s,
2428 const u8 *peer_addr,
2429 enum p2p_wps_method wps_method,
2430 int go_intent, const u8 *own_interface_addr,
2431 unsigned int force_freq, int persistent_group)
2433 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT)
2436 return p2p_authorize(wpa_s->global->p2p, peer_addr, wps_method,
2437 go_intent, own_interface_addr, force_freq,
2442 static void wpas_p2p_check_join_scan_limit(struct wpa_supplicant *wpa_s)
2444 wpa_s->p2p_join_scan_count++;
2445 wpa_printf(MSG_DEBUG, "P2P: Join scan attempt %d",
2446 wpa_s->p2p_join_scan_count);
2447 if (wpa_s->p2p_join_scan_count > P2P_MAX_JOIN_SCAN_ATTEMPTS) {
2448 wpa_printf(MSG_DEBUG, "P2P: Failed to find GO " MACSTR
2449 " for join operationg - stop join attempt",
2450 MAC2STR(wpa_s->pending_join_iface_addr));
2451 eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL);
2452 wpa_msg(wpa_s->parent, MSG_INFO,
2453 P2P_EVENT_GROUP_FORMATION_FAILURE);
2458 static void wpas_p2p_scan_res_join(struct wpa_supplicant *wpa_s,
2459 struct wpa_scan_results *scan_res)
2461 struct wpa_bss *bss;
2463 u8 iface_addr[ETH_ALEN];
2465 eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL);
2467 if (wpa_s->global->p2p_disabled)
2470 wpa_printf(MSG_DEBUG, "P2P: Scan results received (%d BSS) for join",
2471 scan_res ? (int) scan_res->num : -1);
2474 wpas_p2p_scan_res_handler(wpa_s, scan_res);
2476 freq = p2p_get_oper_freq(wpa_s->global->p2p,
2477 wpa_s->pending_join_iface_addr);
2479 p2p_get_interface_addr(wpa_s->global->p2p,
2480 wpa_s->pending_join_dev_addr,
2482 os_memcmp(iface_addr, wpa_s->pending_join_dev_addr, ETH_ALEN) != 0)
2484 wpa_printf(MSG_DEBUG, "P2P: Overwrite pending interface "
2485 "address for join from " MACSTR " to " MACSTR
2486 " based on newly discovered P2P peer entry",
2487 MAC2STR(wpa_s->pending_join_iface_addr),
2488 MAC2STR(iface_addr));
2489 os_memcpy(wpa_s->pending_join_iface_addr, iface_addr,
2492 freq = p2p_get_oper_freq(wpa_s->global->p2p,
2493 wpa_s->pending_join_iface_addr);
2496 wpa_printf(MSG_DEBUG, "P2P: Target GO operating frequency "
2497 "from P2P peer table: %d MHz", freq);
2499 bss = wpa_bss_get_bssid(wpa_s, wpa_s->pending_join_iface_addr);
2502 wpa_printf(MSG_DEBUG, "P2P: Target GO operating frequency "
2503 "from BSS table: %d MHz", freq);
2508 wpa_printf(MSG_DEBUG, "P2P: Send Provision Discovery Request "
2509 "prior to joining an existing group (GO " MACSTR
2511 MAC2STR(wpa_s->pending_join_dev_addr), freq);
2512 wpa_s->pending_pd_before_join = 1;
2514 switch (wpa_s->pending_join_wps_method) {
2515 case WPS_PIN_DISPLAY:
2516 method = WPS_CONFIG_KEYPAD;
2518 case WPS_PIN_KEYPAD:
2519 method = WPS_CONFIG_DISPLAY;
2522 method = WPS_CONFIG_PUSHBUTTON;
2529 if (p2p_prov_disc_req(wpa_s->global->p2p,
2530 wpa_s->pending_join_dev_addr, method, 1)
2532 wpa_printf(MSG_DEBUG, "P2P: Failed to send Provision "
2533 "Discovery Request before joining an "
2535 wpa_s->pending_pd_before_join = 0;
2540 * Actual join operation will be started from the Action frame
2541 * TX status callback.
2546 wpa_printf(MSG_DEBUG, "P2P: Failed to find BSS/GO - try again later");
2547 eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL);
2548 eloop_register_timeout(1, 0, wpas_p2p_join_scan, wpa_s, NULL);
2549 wpas_p2p_check_join_scan_limit(wpa_s);
2553 /* Start join operation immediately */
2554 wpas_p2p_join_start(wpa_s);
2558 static void wpas_p2p_join_scan(void *eloop_ctx, void *timeout_ctx)
2560 struct wpa_supplicant *wpa_s = eloop_ctx;
2562 struct wpa_driver_scan_params params;
2563 struct wpabuf *wps_ie, *ies;
2566 os_memset(¶ms, 0, sizeof(params));
2568 /* P2P Wildcard SSID */
2569 params.num_ssids = 1;
2570 params.ssids[0].ssid = (u8 *) P2P_WILDCARD_SSID;
2571 params.ssids[0].ssid_len = P2P_WILDCARD_SSID_LEN;
2573 wpa_s->wps->dev.p2p = 1;
2574 wps_ie = wps_build_probe_req_ie(0, &wpa_s->wps->dev, wpa_s->wps->uuid,
2575 WPS_REQ_ENROLLEE, 0, NULL);
2576 if (wps_ie == NULL) {
2577 wpas_p2p_scan_res_join(wpa_s, NULL);
2581 ielen = p2p_scan_ie_buf_len(wpa_s->global->p2p);
2582 ies = wpabuf_alloc(wpabuf_len(wps_ie) + ielen);
2584 wpabuf_free(wps_ie);
2585 wpas_p2p_scan_res_join(wpa_s, NULL);
2588 wpabuf_put_buf(ies, wps_ie);
2589 wpabuf_free(wps_ie);
2591 p2p_scan_ie(wpa_s->global->p2p, ies);
2593 params.p2p_probe = 1;
2594 params.extra_ies = wpabuf_head(ies);
2595 params.extra_ies_len = wpabuf_len(ies);
2598 * Run a scan to update BSS table and start Provision Discovery once
2599 * the new scan results become available.
2601 wpa_s->scan_res_handler = wpas_p2p_scan_res_join;
2602 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_USER_SPACE_MLME)
2603 ret = ieee80211_sta_req_scan(wpa_s, ¶ms);
2605 ret = wpa_drv_scan(wpa_s, ¶ms);
2610 wpa_printf(MSG_DEBUG, "P2P: Failed to start scan for join - "
2612 eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL);
2613 eloop_register_timeout(1, 0, wpas_p2p_join_scan, wpa_s, NULL);
2614 wpas_p2p_check_join_scan_limit(wpa_s);
2619 static int wpas_p2p_join(struct wpa_supplicant *wpa_s, const u8 *iface_addr,
2620 const u8 *dev_addr, enum p2p_wps_method wps_method)
2622 wpa_printf(MSG_DEBUG, "P2P: Request to join existing group (iface "
2623 MACSTR " dev " MACSTR ")",
2624 MAC2STR(iface_addr), MAC2STR(dev_addr));
2626 os_memcpy(wpa_s->pending_join_iface_addr, iface_addr, ETH_ALEN);
2627 os_memcpy(wpa_s->pending_join_dev_addr, dev_addr, ETH_ALEN);
2628 wpa_s->pending_join_wps_method = wps_method;
2630 /* Make sure we are not running find during connection establishment */
2631 wpas_p2p_stop_find(wpa_s);
2633 wpa_s->p2p_join_scan_count = 0;
2634 wpas_p2p_join_scan(wpa_s, NULL);
2639 static int wpas_p2p_join_start(struct wpa_supplicant *wpa_s)
2641 struct wpa_supplicant *group;
2642 struct p2p_go_neg_results res;
2644 group = wpas_p2p_get_group_iface(wpa_s, 0, 0);
2647 if (group != wpa_s) {
2648 os_memcpy(group->p2p_pin, wpa_s->p2p_pin,
2649 sizeof(group->p2p_pin));
2650 group->p2p_wps_method = wpa_s->p2p_wps_method;
2653 group->p2p_in_provisioning = 1;
2655 os_memset(&res, 0, sizeof(res));
2656 os_memcpy(res.peer_interface_addr, wpa_s->pending_join_iface_addr,
2658 res.wps_method = wpa_s->pending_join_wps_method;
2659 wpas_start_wps_enrollee(group, &res);
2662 * Allow a longer timeout for join-a-running-group than normal 15
2663 * second group formation timeout since the GO may not have authorized
2664 * our connection yet.
2666 eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s, NULL);
2667 eloop_register_timeout(60, 0, wpas_p2p_group_formation_timeout,
2675 * wpas_p2p_connect - Request P2P Group Formation to be started
2676 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
2677 * @peer_addr: Address of the peer P2P Device
2678 * @pin: PIN to use during provisioning or %NULL to indicate PBC mode
2679 * @persistent_group: Whether to create a persistent group
2680 * @join: Whether to join an existing group (as a client) instead of starting
2681 * Group Owner negotiation; @peer_addr is BSSID in that case
2682 * @auth: Whether to only authorize the connection instead of doing that and
2683 * initiating Group Owner negotiation
2684 * @go_intent: GO Intent or -1 to use default
2685 * @freq: Frequency for the group or 0 for auto-selection
2686 * Returns: 0 or new PIN (if pin was %NULL) on success, -1 on unspecified
2687 * failure, -2 on failure due to channel not currently available,
2688 * -3 if forced channel is not supported
2690 int wpas_p2p_connect(struct wpa_supplicant *wpa_s, const u8 *peer_addr,
2691 const char *pin, enum p2p_wps_method wps_method,
2692 int persistent_group, int join, int auth, int go_intent,
2695 int force_freq = 0, oper_freq = 0;
2698 enum wpa_driver_if_type iftype;
2700 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
2704 go_intent = wpa_s->conf->p2p_go_intent;
2707 wpa_s->p2p_long_listen = 0;
2709 wpa_s->p2p_wps_method = wps_method;
2712 os_strlcpy(wpa_s->p2p_pin, pin, sizeof(wpa_s->p2p_pin));
2713 else if (wps_method == WPS_PIN_DISPLAY) {
2714 ret = wps_generate_pin();
2715 os_snprintf(wpa_s->p2p_pin, sizeof(wpa_s->p2p_pin), "%08d",
2717 wpa_printf(MSG_DEBUG, "P2P: Randomly generated PIN: %s",
2720 wpa_s->p2p_pin[0] = '\0';
2723 u8 iface_addr[ETH_ALEN], dev_addr[ETH_ALEN];
2725 wpa_printf(MSG_DEBUG, "P2P: Authorize invitation to "
2726 "connect a running group from " MACSTR,
2727 MAC2STR(peer_addr));
2728 os_memcpy(wpa_s->p2p_auth_invite, peer_addr, ETH_ALEN);
2731 os_memcpy(dev_addr, peer_addr, ETH_ALEN);
2732 if (p2p_get_interface_addr(wpa_s->global->p2p, peer_addr,
2734 os_memcpy(iface_addr, peer_addr, ETH_ALEN);
2735 p2p_get_dev_addr(wpa_s->global->p2p, peer_addr,
2738 if (wpas_p2p_join(wpa_s, iface_addr, dev_addr, wps_method) <
2744 if (wpa_s->current_ssid && wpa_drv_get_bssid(wpa_s, bssid) == 0 &&
2746 oper_freq = wpa_s->assoc_freq;
2748 oper_freq = wpa_drv_shared_freq(wpa_s);
2754 if (!p2p_supported_freq(wpa_s->global->p2p, freq)) {
2755 wpa_printf(MSG_DEBUG, "P2P: The forced channel "
2756 "(%u MHz) is not supported for P2P uses",
2761 if (oper_freq > 0 && freq != oper_freq &&
2762 !(wpa_s->drv_flags &
2763 WPA_DRIVER_FLAGS_MULTI_CHANNEL_CONCURRENT)) {
2764 wpa_printf(MSG_DEBUG, "P2P: Cannot start P2P group "
2765 "on %u MHz while connected on another "
2766 "channel (%u MHz)", freq, oper_freq);
2769 wpa_printf(MSG_DEBUG, "P2P: Trying to force us to use the "
2770 "requested channel (%u MHz)", freq);
2772 } else if (oper_freq > 0 &&
2773 !p2p_supported_freq(wpa_s->global->p2p, oper_freq)) {
2774 if (!(wpa_s->drv_flags &
2775 WPA_DRIVER_FLAGS_MULTI_CHANNEL_CONCURRENT)) {
2776 wpa_printf(MSG_DEBUG, "P2P: Cannot start P2P group "
2777 "while connected on non-P2P supported "
2778 "channel (%u MHz)", oper_freq);
2781 wpa_printf(MSG_DEBUG, "P2P: Current operating channel "
2782 "(%u MHz) not available for P2P - try to use "
2783 "another channel", oper_freq);
2785 } else if (oper_freq > 0) {
2786 wpa_printf(MSG_DEBUG, "P2P: Trying to force us to use the "
2787 "channel we are already using (%u MHz) on another "
2788 "interface", oper_freq);
2789 force_freq = oper_freq;
2792 wpa_s->create_p2p_iface = wpas_p2p_create_iface(wpa_s);
2794 if (!wpa_s->create_p2p_iface) {
2796 if (wpas_p2p_auth_go_neg(wpa_s, peer_addr, wps_method,
2797 go_intent, wpa_s->own_addr,
2798 force_freq, persistent_group)
2803 if (wpas_p2p_start_go_neg(wpa_s, peer_addr, wps_method,
2804 go_intent, wpa_s->own_addr,
2805 force_freq, persistent_group) < 0)
2810 /* Prepare to add a new interface for the group */
2811 iftype = WPA_IF_P2P_GROUP;
2812 if (go_intent == 15)
2813 iftype = WPA_IF_P2P_GO;
2814 if (wpas_p2p_add_group_interface(wpa_s, iftype) < 0) {
2815 wpa_printf(MSG_ERROR, "P2P: Failed to allocate a new "
2816 "interface for the group");
2821 if (wpas_p2p_auth_go_neg(wpa_s, peer_addr, wps_method,
2823 wpa_s->pending_interface_addr,
2824 force_freq, persistent_group) < 0)
2828 if (wpas_p2p_start_go_neg(wpa_s, peer_addr, wps_method, go_intent,
2829 wpa_s->pending_interface_addr,
2830 force_freq, persistent_group) < 0) {
2831 wpas_p2p_remove_pending_group_interface(wpa_s);
2839 * wpas_p2p_remain_on_channel_cb - Indication of remain-on-channel start
2840 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
2841 * @freq: Frequency of the channel in MHz
2842 * @duration: Duration of the stay on the channel in milliseconds
2844 * This callback is called when the driver indicates that it has started the
2845 * requested remain-on-channel duration.
2847 void wpas_p2p_remain_on_channel_cb(struct wpa_supplicant *wpa_s,
2848 unsigned int freq, unsigned int duration)
2850 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
2852 if (wpa_s->off_channel_freq == wpa_s->pending_listen_freq) {
2853 p2p_listen_cb(wpa_s->global->p2p, wpa_s->pending_listen_freq,
2854 wpa_s->pending_listen_duration);
2855 wpa_s->pending_listen_freq = 0;
2860 static int wpas_p2p_listen_start(struct wpa_supplicant *wpa_s,
2861 unsigned int timeout)
2863 /* Limit maximum Listen state time based on driver limitation. */
2864 if (timeout > wpa_s->max_remain_on_chan)
2865 timeout = wpa_s->max_remain_on_chan;
2867 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT)
2868 return wpa_drv_p2p_listen(wpa_s, timeout);
2870 return p2p_listen(wpa_s->global->p2p, timeout);
2875 * wpas_p2p_cancel_remain_on_channel_cb - Remain-on-channel timeout
2876 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
2877 * @freq: Frequency of the channel in MHz
2879 * This callback is called when the driver indicates that a remain-on-channel
2880 * operation has been completed, i.e., the duration on the requested channel
2883 void wpas_p2p_cancel_remain_on_channel_cb(struct wpa_supplicant *wpa_s,
2886 wpa_printf(MSG_DEBUG, "P2P: Cancel remain-on-channel callback "
2887 "(p2p_long_listen=%d ms pending_action_tx=%p)",
2888 wpa_s->p2p_long_listen, wpa_s->pending_action_tx);
2889 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
2891 if (p2p_listen_end(wpa_s->global->p2p, freq) > 0)
2892 return; /* P2P module started a new operation */
2893 if (wpa_s->pending_action_tx)
2895 if (wpa_s->p2p_long_listen > 0)
2896 wpa_s->p2p_long_listen -= wpa_s->max_remain_on_chan;
2897 if (wpa_s->p2p_long_listen > 0) {
2898 wpa_printf(MSG_DEBUG, "P2P: Continuing long Listen state");
2899 wpas_p2p_listen_start(wpa_s, wpa_s->p2p_long_listen);
2905 * wpas_p2p_group_remove - Remove a P2P group
2906 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
2907 * @ifname: Network interface name of the group interface or "*" to remove all
2909 * Returns: 0 on success, -1 on failure
2911 * This function is used to remove a P2P group. This can be used to disconnect
2912 * from a group in which the local end is a P2P Client or to end a P2P Group in
2913 * case the local end is the Group Owner. If a virtual network interface was
2914 * created for this group, that interface will be removed. Otherwise, only the
2915 * configured P2P group network will be removed from the interface.
2917 int wpas_p2p_group_remove(struct wpa_supplicant *wpa_s, const char *ifname)
2919 struct wpa_global *global = wpa_s->global;
2921 if (os_strcmp(ifname, "*") == 0) {
2922 struct wpa_supplicant *prev;
2923 wpa_s = global->ifaces;
2926 wpa_s = wpa_s->next;
2927 wpas_p2p_disconnect(prev);
2932 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
2933 if (os_strcmp(wpa_s->ifname, ifname) == 0)
2937 return wpas_p2p_disconnect(wpa_s);
2941 static void wpas_p2p_init_go_params(struct wpa_supplicant *wpa_s,
2942 struct p2p_go_neg_results *params,
2948 os_memset(params, 0, sizeof(*params));
2949 params->role_go = 1;
2951 wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on forced "
2952 "frequency %d MHz", freq);
2953 params->freq = freq;
2954 } else if (wpa_s->conf->p2p_oper_reg_class == 81 &&
2955 wpa_s->conf->p2p_oper_channel >= 1 &&
2956 wpa_s->conf->p2p_oper_channel <= 11) {
2957 params->freq = 2407 + 5 * wpa_s->conf->p2p_oper_channel;
2958 wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on configured "
2959 "frequency %d MHz", params->freq);
2960 } else if (wpa_s->conf->p2p_oper_reg_class == 115 ||
2961 wpa_s->conf->p2p_oper_reg_class == 124) {
2962 params->freq = 5000 + 5 * wpa_s->conf->p2p_oper_channel;
2963 wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on configured "
2964 "frequency %d MHz", params->freq);
2965 } else if (wpa_s->conf->p2p_oper_channel == 0 &&
2966 wpa_s->best_overall_freq > 0 &&
2967 p2p_supported_freq(wpa_s->global->p2p,
2968 wpa_s->best_overall_freq)) {
2969 params->freq = wpa_s->best_overall_freq;
2970 wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on best overall "
2971 "channel %d MHz", params->freq);
2972 } else if (wpa_s->conf->p2p_oper_channel == 0 &&
2973 wpa_s->best_24_freq > 0 &&
2974 p2p_supported_freq(wpa_s->global->p2p,
2975 wpa_s->best_24_freq)) {
2976 params->freq = wpa_s->best_24_freq;
2977 wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on best 2.4 GHz "
2978 "channel %d MHz", params->freq);
2979 } else if (wpa_s->conf->p2p_oper_channel == 0 &&
2980 wpa_s->best_5_freq > 0 &&
2981 p2p_supported_freq(wpa_s->global->p2p,
2982 wpa_s->best_5_freq)) {
2983 params->freq = wpa_s->best_5_freq;
2984 wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on best 5 GHz "
2985 "channel %d MHz", params->freq);
2987 params->freq = 2412;
2988 wpa_printf(MSG_DEBUG, "P2P: Set GO freq %d MHz (no preference "
2989 "known)", params->freq);
2992 if (wpa_s->current_ssid && wpa_drv_get_bssid(wpa_s, bssid) == 0 &&
2993 wpa_s->assoc_freq && !freq) {
2994 wpa_printf(MSG_DEBUG, "P2P: Force GO on the channel we are "
2996 params->freq = wpa_s->assoc_freq;
2999 res = wpa_drv_shared_freq(wpa_s);
3000 if (res > 0 && !freq) {
3001 wpa_printf(MSG_DEBUG, "P2P: Force GO on the channel we are "
3002 "already using on a shared interface");
3008 static struct wpa_supplicant *
3009 wpas_p2p_get_group_iface(struct wpa_supplicant *wpa_s, int addr_allocated,
3012 struct wpa_supplicant *group_wpa_s;
3014 if (!wpas_p2p_create_iface(wpa_s))
3017 if (wpas_p2p_add_group_interface(wpa_s, go ? WPA_IF_P2P_GO :
3018 WPA_IF_P2P_CLIENT) < 0)
3020 group_wpa_s = wpas_p2p_init_group_interface(wpa_s, go);
3021 if (group_wpa_s == NULL) {
3022 wpas_p2p_remove_pending_group_interface(wpa_s);
3031 * wpas_p2p_group_add - Add a new P2P group with local end as Group Owner
3032 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
3033 * @persistent_group: Whether to create a persistent group
3034 * @freq: Frequency for the group or 0 to indicate no hardcoding
3035 * Returns: 0 on success, -1 on failure
3037 * This function creates a new P2P group with the local end as the Group Owner,
3038 * i.e., without using Group Owner Negotiation.
3040 int wpas_p2p_group_add(struct wpa_supplicant *wpa_s, int persistent_group,
3043 struct p2p_go_neg_results params;
3046 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
3050 wpa_printf(MSG_DEBUG, "P2P: Request to start GO on 2.4 GHz "
3052 if (wpa_s->best_24_freq > 0 &&
3053 p2p_supported_freq(wpa_s->global->p2p,
3054 wpa_s->best_24_freq)) {
3055 freq = wpa_s->best_24_freq;
3056 wpa_printf(MSG_DEBUG, "P2P: Use best 2.4 GHz band "
3057 "channel: %d MHz", freq);
3059 os_get_random((u8 *) &r, sizeof(r));
3060 freq = 2412 + (r % 3) * 25;
3061 wpa_printf(MSG_DEBUG, "P2P: Use random 2.4 GHz band "
3062 "channel: %d MHz", freq);
3067 wpa_printf(MSG_DEBUG, "P2P: Request to start GO on 5 GHz "
3069 if (wpa_s->best_5_freq > 0 &&
3070 p2p_supported_freq(wpa_s->global->p2p,
3071 wpa_s->best_5_freq)) {
3072 freq = wpa_s->best_5_freq;
3073 wpa_printf(MSG_DEBUG, "P2P: Use best 5 GHz band "
3074 "channel: %d MHz", freq);
3076 os_get_random((u8 *) &r, sizeof(r));
3077 freq = 5180 + (r % 4) * 20;
3078 if (!p2p_supported_freq(wpa_s->global->p2p, freq)) {
3079 wpa_printf(MSG_DEBUG, "P2P: Could not select "
3080 "5 GHz channel for P2P group");
3083 wpa_printf(MSG_DEBUG, "P2P: Use random 5 GHz band "
3084 "channel: %d MHz", freq);
3088 if (freq > 0 && !p2p_supported_freq(wpa_s->global->p2p, freq)) {
3089 wpa_printf(MSG_DEBUG, "P2P: The forced channel for GO "
3090 "(%u MHz) is not supported for P2P uses",
3095 wpas_p2p_init_go_params(wpa_s, ¶ms, freq);
3096 p2p_go_params(wpa_s->global->p2p, ¶ms);
3097 params.persistent_group = persistent_group;
3099 wpa_s = wpas_p2p_get_group_iface(wpa_s, 0, 1);
3102 wpas_start_wps_go(wpa_s, ¶ms, 0);
3108 static int wpas_start_p2p_client(struct wpa_supplicant *wpa_s,
3109 struct wpa_ssid *params, int addr_allocated)
3111 struct wpa_ssid *ssid;
3113 wpa_s = wpas_p2p_get_group_iface(wpa_s, addr_allocated, 0);
3117 wpa_supplicant_ap_deinit(wpa_s);
3119 ssid = wpa_config_add_network(wpa_s->conf);
3122 wpa_config_set_network_defaults(ssid);
3123 ssid->temporary = 1;
3124 ssid->proto = WPA_PROTO_RSN;
3125 ssid->pairwise_cipher = WPA_CIPHER_CCMP;
3126 ssid->group_cipher = WPA_CIPHER_CCMP;
3127 ssid->key_mgmt = WPA_KEY_MGMT_PSK;
3128 ssid->ssid = os_malloc(params->ssid_len);
3129 if (ssid->ssid == NULL) {
3130 wpa_config_remove_network(wpa_s->conf, ssid->id);
3133 os_memcpy(ssid->ssid, params->ssid, params->ssid_len);
3134 ssid->ssid_len = params->ssid_len;
3135 ssid->p2p_group = 1;
3136 ssid->export_keys = 1;
3137 if (params->psk_set) {
3138 os_memcpy(ssid->psk, params->psk, 32);
3141 if (params->passphrase)
3142 ssid->passphrase = os_strdup(params->passphrase);
3144 wpa_supplicant_select_network(wpa_s, ssid);
3146 wpa_s->show_group_started = 1;
3152 int wpas_p2p_group_add_persistent(struct wpa_supplicant *wpa_s,
3153 struct wpa_ssid *ssid, int addr_allocated,
3156 struct p2p_go_neg_results params;
3159 if (ssid->disabled != 2 || ssid->ssid == NULL)
3162 if (wpas_get_p2p_group(wpa_s, ssid->ssid, ssid->ssid_len, &go) &&
3163 go == (ssid->mode == WPAS_MODE_P2P_GO)) {
3164 wpa_printf(MSG_DEBUG, "P2P: Requested persistent group is "
3169 /* Make sure we are not running find during connection establishment */
3170 wpas_p2p_stop_find(wpa_s);
3172 if (ssid->mode == WPAS_MODE_INFRA)
3173 return wpas_start_p2p_client(wpa_s, ssid, addr_allocated);
3175 if (ssid->mode != WPAS_MODE_P2P_GO)
3178 wpas_p2p_init_go_params(wpa_s, ¶ms, freq);
3181 if (ssid->passphrase == NULL ||
3182 os_strlen(ssid->passphrase) >= sizeof(params.passphrase)) {
3183 wpa_printf(MSG_DEBUG, "P2P: Invalid passphrase in persistent "
3187 os_strlcpy(params.passphrase, ssid->passphrase,
3188 sizeof(params.passphrase));
3189 os_memcpy(params.ssid, ssid->ssid, ssid->ssid_len);
3190 params.ssid_len = ssid->ssid_len;
3191 params.persistent_group = 1;
3193 wpa_s = wpas_p2p_get_group_iface(wpa_s, addr_allocated, 1);
3197 wpas_start_wps_go(wpa_s, ¶ms, 0);
3203 static void wpas_p2p_ie_update(void *ctx, struct wpabuf *beacon_ies,
3204 struct wpabuf *proberesp_ies)
3206 struct wpa_supplicant *wpa_s = ctx;
3207 if (wpa_s->ap_iface) {
3208 struct hostapd_data *hapd = wpa_s->ap_iface->bss[0];
3210 wpabuf_free(hapd->p2p_beacon_ie);
3211 hapd->p2p_beacon_ie = beacon_ies;
3213 wpabuf_free(hapd->p2p_probe_resp_ie);
3214 hapd->p2p_probe_resp_ie = proberesp_ies;
3216 wpabuf_free(beacon_ies);
3217 wpabuf_free(proberesp_ies);
3219 wpa_supplicant_ap_update_beacon(wpa_s);
3223 static void wpas_p2p_idle_update(void *ctx, int idle)
3225 struct wpa_supplicant *wpa_s = ctx;
3226 if (!wpa_s->ap_iface)
3228 wpa_printf(MSG_DEBUG, "P2P: GO - group %sidle", idle ? "" : "not ");
3230 wpas_p2p_set_group_idle_timeout(wpa_s);
3232 eloop_cancel_timeout(wpas_p2p_group_idle_timeout, wpa_s, NULL);
3236 struct p2p_group * wpas_p2p_group_init(struct wpa_supplicant *wpa_s,
3237 int persistent_group,
3238 int group_formation)
3240 struct p2p_group *group;
3241 struct p2p_group_config *cfg;
3243 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT)
3245 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
3248 cfg = os_zalloc(sizeof(*cfg));
3252 cfg->persistent_group = persistent_group;
3253 os_memcpy(cfg->interface_addr, wpa_s->own_addr, ETH_ALEN);
3254 if (wpa_s->max_stations &&
3255 wpa_s->max_stations < wpa_s->conf->max_num_sta)
3256 cfg->max_clients = wpa_s->max_stations;
3258 cfg->max_clients = wpa_s->conf->max_num_sta;
3259 cfg->cb_ctx = wpa_s;
3260 cfg->ie_update = wpas_p2p_ie_update;
3261 cfg->idle_update = wpas_p2p_idle_update;
3263 group = p2p_group_init(wpa_s->global->p2p, cfg);
3266 if (!group_formation)
3267 p2p_group_notif_formation_done(group);
3268 wpa_s->p2p_group = group;
3273 void wpas_p2p_wps_success(struct wpa_supplicant *wpa_s, const u8 *peer_addr,
3276 if (!wpa_s->p2p_in_provisioning) {
3277 wpa_printf(MSG_DEBUG, "P2P: Ignore WPS success event - P2P "
3278 "provisioning not in progress");
3282 eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s->parent,
3284 if (wpa_s->global->p2p)
3285 p2p_wps_success_cb(wpa_s->global->p2p, peer_addr);
3286 else if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT)
3287 wpa_drv_wps_success_cb(wpa_s, peer_addr);
3288 wpas_group_formation_completed(wpa_s, 1);
3292 void wpas_p2p_wps_failed(struct wpa_supplicant *wpa_s,
3293 struct wps_event_fail *fail)
3295 if (!wpa_s->p2p_in_provisioning) {
3296 wpa_printf(MSG_DEBUG, "P2P: Ignore WPS fail event - P2P "
3297 "provisioning not in progress");
3300 wpas_notify_p2p_wps_failed(wpa_s, fail);
3304 int wpas_p2p_prov_disc(struct wpa_supplicant *wpa_s, const u8 *peer_addr,
3305 const char *config_method)
3309 if (os_strcmp(config_method, "display") == 0)
3310 config_methods = WPS_CONFIG_DISPLAY;
3311 else if (os_strcmp(config_method, "keypad") == 0)
3312 config_methods = WPS_CONFIG_KEYPAD;
3313 else if (os_strcmp(config_method, "pbc") == 0 ||
3314 os_strcmp(config_method, "pushbutton") == 0)
3315 config_methods = WPS_CONFIG_PUSHBUTTON;
3319 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT) {
3320 return wpa_drv_p2p_prov_disc_req(wpa_s, peer_addr,
3324 if (wpa_s->global->p2p == NULL || wpa_s->global->p2p_disabled)
3327 return p2p_prov_disc_req(wpa_s->global->p2p, peer_addr,
3332 int wpas_p2p_scan_result_text(const u8 *ies, size_t ies_len, char *buf,
3335 return p2p_scan_result_text(ies, ies_len, buf, end);
3339 static void wpas_p2p_clear_pending_action_tx(struct wpa_supplicant *wpa_s)
3341 if (!wpa_s->pending_action_tx)
3344 wpa_printf(MSG_DEBUG, "P2P: Drop pending Action TX due to new "
3345 "operation request");
3346 wpabuf_free(wpa_s->pending_action_tx);
3347 wpa_s->pending_action_tx = NULL;
3351 int wpas_p2p_find(struct wpa_supplicant *wpa_s, unsigned int timeout,
3352 enum p2p_discovery_type type,
3353 unsigned int num_req_dev_types, const u8 *req_dev_types)
3355 wpas_p2p_clear_pending_action_tx(wpa_s);
3356 wpa_s->p2p_long_listen = 0;
3358 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT)
3359 return wpa_drv_p2p_find(wpa_s, timeout, type);
3361 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
3364 return p2p_find(wpa_s->global->p2p, timeout, type,
3365 num_req_dev_types, req_dev_types);
3369 void wpas_p2p_stop_find(struct wpa_supplicant *wpa_s)
3371 wpas_p2p_clear_pending_action_tx(wpa_s);
3372 wpa_s->p2p_long_listen = 0;
3373 eloop_cancel_timeout(wpas_p2p_long_listen_timeout, wpa_s, NULL);
3374 eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL);
3376 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT) {
3377 wpa_drv_p2p_stop_find(wpa_s);
3381 if (wpa_s->global->p2p)
3382 p2p_stop_find(wpa_s->global->p2p);
3384 wpas_p2p_remove_pending_group_interface(wpa_s);
3388 static void wpas_p2p_long_listen_timeout(void *eloop_ctx, void *timeout_ctx)
3390 struct wpa_supplicant *wpa_s = eloop_ctx;
3391 wpa_s->p2p_long_listen = 0;
3395 int wpas_p2p_listen(struct wpa_supplicant *wpa_s, unsigned int timeout)
3399 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
3402 wpas_p2p_clear_pending_action_tx(wpa_s);
3406 * This is a request for unlimited Listen state. However, at
3407 * least for now, this is mapped to a Listen state for one
3412 eloop_cancel_timeout(wpas_p2p_long_listen_timeout, wpa_s, NULL);
3413 wpa_s->p2p_long_listen = 0;
3415 res = wpas_p2p_listen_start(wpa_s, timeout * 1000);
3416 if (res == 0 && timeout * 1000 > wpa_s->max_remain_on_chan) {
3417 wpa_s->p2p_long_listen = timeout * 1000;
3418 eloop_register_timeout(timeout, 0,
3419 wpas_p2p_long_listen_timeout,
3427 int wpas_p2p_assoc_req_ie(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
3428 u8 *buf, size_t len, int p2p_group)
3430 struct wpabuf *p2p_ie;
3433 if (wpa_s->global->p2p_disabled)
3435 if (wpa_s->global->p2p == NULL)
3440 p2p_ie = wpa_bss_get_vendor_ie_multi(bss, P2P_IE_VENDOR_TYPE);
3441 ret = p2p_assoc_req_ie(wpa_s->global->p2p, bss->bssid, buf, len,
3443 wpabuf_free(p2p_ie);
3449 int wpas_p2p_probe_req_rx(struct wpa_supplicant *wpa_s, const u8 *addr,
3450 const u8 *dst, const u8 *bssid,
3451 const u8 *ie, size_t ie_len)
3453 if (wpa_s->global->p2p_disabled)
3455 if (wpa_s->global->p2p == NULL)
3458 return p2p_probe_req_rx(wpa_s->global->p2p, addr, dst, bssid,
3463 void wpas_p2p_rx_action(struct wpa_supplicant *wpa_s, const u8 *da,
3464 const u8 *sa, const u8 *bssid,
3465 u8 category, const u8 *data, size_t len, int freq)
3467 if (wpa_s->global->p2p_disabled)
3469 if (wpa_s->global->p2p == NULL)
3472 p2p_rx_action(wpa_s->global->p2p, da, sa, bssid, category, data, len,
3477 void wpas_p2p_scan_ie(struct wpa_supplicant *wpa_s, struct wpabuf *ies)
3479 if (wpa_s->global->p2p_disabled)
3481 if (wpa_s->global->p2p == NULL)
3484 p2p_scan_ie(wpa_s->global->p2p, ies);
3488 void wpas_p2p_group_deinit(struct wpa_supplicant *wpa_s)
3490 p2p_group_deinit(wpa_s->p2p_group);
3491 wpa_s->p2p_group = NULL;
3493 wpa_s->ap_configured_cb = NULL;
3494 wpa_s->ap_configured_cb_ctx = NULL;
3495 wpa_s->ap_configured_cb_data = NULL;
3496 wpa_s->connect_without_scan = NULL;
3500 int wpas_p2p_reject(struct wpa_supplicant *wpa_s, const u8 *addr)
3502 wpa_s->p2p_long_listen = 0;
3504 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT)
3505 return wpa_drv_p2p_reject(wpa_s, addr);
3507 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
3510 return p2p_reject(wpa_s->global->p2p, addr);
3514 /* Invite to reinvoke a persistent group */
3515 int wpas_p2p_invite(struct wpa_supplicant *wpa_s, const u8 *peer_addr,
3516 struct wpa_ssid *ssid, const u8 *go_dev_addr)
3518 enum p2p_invite_role role;
3521 if (ssid->mode == WPAS_MODE_P2P_GO) {
3522 role = P2P_INVITE_ROLE_GO;
3523 if (peer_addr == NULL) {
3524 wpa_printf(MSG_DEBUG, "P2P: Missing peer "
3525 "address in invitation command");
3528 if (wpas_p2p_create_iface(wpa_s)) {
3529 if (wpas_p2p_add_group_interface(wpa_s,
3530 WPA_IF_P2P_GO) < 0) {
3531 wpa_printf(MSG_ERROR, "P2P: Failed to "
3532 "allocate a new interface for the "
3536 bssid = wpa_s->pending_interface_addr;
3538 bssid = wpa_s->own_addr;
3540 role = P2P_INVITE_ROLE_CLIENT;
3541 peer_addr = ssid->bssid;
3543 wpa_s->pending_invite_ssid_id = ssid->id;
3545 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT)
3546 return wpa_drv_p2p_invite(wpa_s, peer_addr, role, bssid,
3547 ssid->ssid, ssid->ssid_len,
3550 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
3553 return p2p_invite(wpa_s->global->p2p, peer_addr, role, bssid,
3554 ssid->ssid, ssid->ssid_len, 0, go_dev_addr, 1);
3558 /* Invite to join an active group */
3559 int wpas_p2p_invite_group(struct wpa_supplicant *wpa_s, const char *ifname,
3560 const u8 *peer_addr, const u8 *go_dev_addr)
3562 struct wpa_global *global = wpa_s->global;
3563 enum p2p_invite_role role;
3565 struct wpa_ssid *ssid;
3567 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
3568 if (os_strcmp(wpa_s->ifname, ifname) == 0)
3571 if (wpa_s == NULL) {
3572 wpa_printf(MSG_DEBUG, "P2P: Interface '%s' not found", ifname);
3576 ssid = wpa_s->current_ssid;
3578 wpa_printf(MSG_DEBUG, "P2P: No current SSID to use for "
3583 if (ssid->mode == WPAS_MODE_P2P_GO) {
3584 role = P2P_INVITE_ROLE_ACTIVE_GO;
3585 bssid = wpa_s->own_addr;
3586 if (go_dev_addr == NULL)
3587 go_dev_addr = wpa_s->parent->own_addr;
3589 role = P2P_INVITE_ROLE_CLIENT;
3590 if (wpa_s->wpa_state < WPA_ASSOCIATED) {
3591 wpa_printf(MSG_DEBUG, "P2P: Not associated - cannot "
3592 "invite to current group");
3595 bssid = wpa_s->bssid;
3596 if (go_dev_addr == NULL &&
3597 !is_zero_ether_addr(wpa_s->go_dev_addr))
3598 go_dev_addr = wpa_s->go_dev_addr;
3600 wpa_s->parent->pending_invite_ssid_id = -1;
3602 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT)
3603 return wpa_drv_p2p_invite(wpa_s, peer_addr, role, bssid,
3604 ssid->ssid, ssid->ssid_len,
3607 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
3610 return p2p_invite(wpa_s->global->p2p, peer_addr, role, bssid,
3611 ssid->ssid, ssid->ssid_len, wpa_s->assoc_freq,
3616 void wpas_p2p_completed(struct wpa_supplicant *wpa_s)
3618 struct wpa_ssid *ssid = wpa_s->current_ssid;
3619 const char *ssid_txt;
3620 u8 go_dev_addr[ETH_ALEN];
3621 int network_id = -1;
3624 if (!wpa_s->show_group_started || !ssid)
3627 wpa_s->show_group_started = 0;
3629 ssid_txt = wpa_ssid_txt(ssid->ssid, ssid->ssid_len);
3630 os_memset(go_dev_addr, 0, ETH_ALEN);
3631 if (ssid->bssid_set)
3632 os_memcpy(go_dev_addr, ssid->bssid, ETH_ALEN);
3633 persistent = wpas_p2p_persistent_group(wpa_s, go_dev_addr, ssid->ssid,
3635 os_memcpy(wpa_s->go_dev_addr, go_dev_addr, ETH_ALEN);
3637 if (wpa_s->global->p2p_group_formation == wpa_s)
3638 wpa_s->global->p2p_group_formation = NULL;
3640 if (ssid->passphrase == NULL && ssid->psk_set) {
3642 wpa_snprintf_hex(psk, sizeof(psk), ssid->psk, 32);
3643 wpa_msg(wpa_s->parent, MSG_INFO, P2P_EVENT_GROUP_STARTED
3644 "%s client ssid=\"%s\" freq=%d psk=%s go_dev_addr="
3646 wpa_s->ifname, ssid_txt, ssid->frequency, psk,
3647 MAC2STR(go_dev_addr),
3648 persistent ? " [PERSISTENT]" : "");
3650 wpa_msg(wpa_s->parent, MSG_INFO, P2P_EVENT_GROUP_STARTED
3651 "%s client ssid=\"%s\" freq=%d passphrase=\"%s\" "
3652 "go_dev_addr=" MACSTR "%s",
3653 wpa_s->ifname, ssid_txt, ssid->frequency,
3654 ssid->passphrase ? ssid->passphrase : "",
3655 MAC2STR(go_dev_addr),
3656 persistent ? " [PERSISTENT]" : "");
3660 network_id = wpas_p2p_store_persistent_group(wpa_s->parent,
3663 network_id = ssid->id;
3664 wpas_notify_p2p_group_started(wpa_s, ssid, network_id, 1);
3668 int wpas_p2p_presence_req(struct wpa_supplicant *wpa_s, u32 duration1,
3669 u32 interval1, u32 duration2, u32 interval2)
3671 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT)
3673 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
3676 if (wpa_s->wpa_state < WPA_ASSOCIATED ||
3677 wpa_s->current_ssid == NULL ||
3678 wpa_s->current_ssid->mode != WPAS_MODE_INFRA)
3681 return p2p_presence_req(wpa_s->global->p2p, wpa_s->bssid,
3682 wpa_s->own_addr, wpa_s->assoc_freq,
3683 duration1, interval1, duration2, interval2);
3687 int wpas_p2p_ext_listen(struct wpa_supplicant *wpa_s, unsigned int period,
3688 unsigned int interval)
3690 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT)
3693 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
3696 return p2p_ext_listen(wpa_s->global->p2p, period, interval);
3700 static void wpas_p2p_group_idle_timeout(void *eloop_ctx, void *timeout_ctx)
3702 struct wpa_supplicant *wpa_s = eloop_ctx;
3704 if (wpa_s->conf->p2p_group_idle == 0) {
3705 wpa_printf(MSG_DEBUG, "P2P: Ignore group idle timeout - "
3710 wpa_printf(MSG_DEBUG, "P2P: Group idle timeout reached - terminate "
3712 wpa_s->removal_reason = P2P_GROUP_REMOVAL_IDLE_TIMEOUT;
3713 wpas_p2p_group_delete(wpa_s);
3717 static void wpas_p2p_set_group_idle_timeout(struct wpa_supplicant *wpa_s)
3719 eloop_cancel_timeout(wpas_p2p_group_idle_timeout, wpa_s, NULL);
3720 if (wpa_s->conf->p2p_group_idle == 0)
3723 if (wpa_s->current_ssid == NULL || !wpa_s->current_ssid->p2p_group)
3726 wpa_printf(MSG_DEBUG, "P2P: Set P2P group idle timeout to %u seconds",
3727 wpa_s->conf->p2p_group_idle);
3728 eloop_register_timeout(wpa_s->conf->p2p_group_idle, 0,
3729 wpas_p2p_group_idle_timeout, wpa_s, NULL);
3733 void wpas_p2p_deauth_notif(struct wpa_supplicant *wpa_s, const u8 *bssid,
3734 u16 reason_code, const u8 *ie, size_t ie_len)
3736 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
3738 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT)
3741 p2p_deauth_notif(wpa_s->global->p2p, bssid, reason_code, ie, ie_len);
3745 void wpas_p2p_disassoc_notif(struct wpa_supplicant *wpa_s, const u8 *bssid,
3746 u16 reason_code, const u8 *ie, size_t ie_len)
3748 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
3750 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT)
3753 p2p_disassoc_notif(wpa_s->global->p2p, bssid, reason_code, ie, ie_len);
3757 void wpas_p2p_update_config(struct wpa_supplicant *wpa_s)
3759 struct p2p_data *p2p = wpa_s->global->p2p;
3764 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_CAPABLE))
3767 if (wpa_s->conf->changed_parameters & CFG_CHANGED_DEVICE_NAME)
3768 p2p_set_dev_name(p2p, wpa_s->conf->device_name);
3770 if (wpa_s->conf->changed_parameters & CFG_CHANGED_DEVICE_TYPE)
3771 p2p_set_pri_dev_type(p2p, wpa_s->conf->device_type);
3774 (wpa_s->conf->changed_parameters & CFG_CHANGED_CONFIG_METHODS))
3775 p2p_set_config_methods(p2p, wpa_s->wps->config_methods);
3777 if (wpa_s->wps && (wpa_s->conf->changed_parameters & CFG_CHANGED_UUID))
3778 p2p_set_uuid(p2p, wpa_s->wps->uuid);
3780 if (wpa_s->conf->changed_parameters & CFG_CHANGED_WPS_STRING) {
3781 p2p_set_manufacturer(p2p, wpa_s->conf->manufacturer);
3782 p2p_set_model_name(p2p, wpa_s->conf->model_name);
3783 p2p_set_model_number(p2p, wpa_s->conf->model_number);
3784 p2p_set_serial_number(p2p, wpa_s->conf->serial_number);
3787 if (wpa_s->conf->changed_parameters & CFG_CHANGED_SEC_DEVICE_TYPE)
3788 p2p_set_sec_dev_types(p2p,
3789 (void *) wpa_s->conf->sec_device_type,
3790 wpa_s->conf->num_sec_device_types);
3792 if (wpa_s->conf->changed_parameters & CFG_CHANGED_VENDOR_EXTENSION) {
3794 p2p_remove_wps_vendor_extensions(p2p);
3795 for (i = 0; i < MAX_WPS_VENDOR_EXT; i++) {
3796 if (wpa_s->conf->wps_vendor_ext[i] == NULL)
3798 p2p_add_wps_vendor_extension(
3799 p2p, wpa_s->conf->wps_vendor_ext[i]);
3803 if ((wpa_s->conf->changed_parameters & CFG_CHANGED_COUNTRY) &&
3804 wpa_s->conf->country[0] && wpa_s->conf->country[1]) {
3806 country[0] = wpa_s->conf->country[0];
3807 country[1] = wpa_s->conf->country[1];
3809 p2p_set_country(p2p, country);
3812 if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_SSID_POSTFIX) {
3813 p2p_set_ssid_postfix(p2p, (u8 *) wpa_s->conf->p2p_ssid_postfix,
3814 wpa_s->conf->p2p_ssid_postfix ?
3815 os_strlen(wpa_s->conf->p2p_ssid_postfix) :
3819 if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_INTRA_BSS)
3820 p2p_set_intra_bss_dist(p2p, wpa_s->conf->p2p_intra_bss);
3822 if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_LISTEN_CHANNEL) {
3823 u8 reg_class, channel;
3826 if (wpa_s->conf->p2p_listen_reg_class &&
3827 wpa_s->conf->p2p_listen_channel) {
3828 reg_class = wpa_s->conf->p2p_listen_reg_class;
3829 channel = wpa_s->conf->p2p_listen_channel;
3833 * Pick one of the social channels randomly as the
3836 os_get_random((u8 *) &r, sizeof(r));
3837 channel = 1 + (r % 3) * 5;
3839 ret = p2p_set_listen_channel(p2p, reg_class, channel);
3841 wpa_printf(MSG_ERROR, "P2P: Own listen channel update "
3844 if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_OPER_CHANNEL) {
3845 u8 op_reg_class, op_channel, cfg_op_channel;
3848 if (wpa_s->conf->p2p_oper_reg_class &&
3849 wpa_s->conf->p2p_oper_channel) {
3850 op_reg_class = wpa_s->conf->p2p_oper_reg_class;
3851 op_channel = wpa_s->conf->p2p_oper_channel;
3856 * Use random operation channel from (1, 6, 11)
3857 *if no other preference is indicated.
3859 os_get_random((u8 *) &r, sizeof(r));
3860 op_channel = 1 + (r % 3) * 5;
3863 ret = p2p_set_oper_channel(p2p, op_reg_class, op_channel,
3866 wpa_printf(MSG_ERROR, "P2P: Own oper channel update "
3872 int wpas_p2p_set_noa(struct wpa_supplicant *wpa_s, u8 count, int start,
3875 if (!wpa_s->ap_iface)
3877 return hostapd_p2p_set_noa(wpa_s->ap_iface->bss[0], count, start,
3882 int wpas_p2p_set_cross_connect(struct wpa_supplicant *wpa_s, int enabled)
3884 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
3886 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT)
3889 wpa_s->global->cross_connection = enabled;
3890 p2p_set_cross_connect(wpa_s->global->p2p, enabled);
3893 struct wpa_supplicant *iface;
3895 for (iface = wpa_s->global->ifaces; iface; iface = iface->next)
3897 if (iface->cross_connect_enabled == 0)
3900 iface->cross_connect_enabled = 0;
3901 iface->cross_connect_in_use = 0;
3902 wpa_msg(iface->parent, MSG_INFO,
3903 P2P_EVENT_CROSS_CONNECT_DISABLE "%s %s",
3904 iface->ifname, iface->cross_connect_uplink);
3912 static void wpas_p2p_enable_cross_connect(struct wpa_supplicant *uplink)
3914 struct wpa_supplicant *iface;
3916 if (!uplink->global->cross_connection)
3919 for (iface = uplink->global->ifaces; iface; iface = iface->next) {
3920 if (!iface->cross_connect_enabled)
3922 if (os_strcmp(uplink->ifname, iface->cross_connect_uplink) !=
3925 if (iface->ap_iface == NULL)
3927 if (iface->cross_connect_in_use)
3930 iface->cross_connect_in_use = 1;
3931 wpa_msg(iface->parent, MSG_INFO,
3932 P2P_EVENT_CROSS_CONNECT_ENABLE "%s %s",
3933 iface->ifname, iface->cross_connect_uplink);
3938 static void wpas_p2p_disable_cross_connect(struct wpa_supplicant *uplink)
3940 struct wpa_supplicant *iface;
3942 for (iface = uplink->global->ifaces; iface; iface = iface->next) {
3943 if (!iface->cross_connect_enabled)
3945 if (os_strcmp(uplink->ifname, iface->cross_connect_uplink) !=
3948 if (!iface->cross_connect_in_use)
3951 wpa_msg(iface->parent, MSG_INFO,
3952 P2P_EVENT_CROSS_CONNECT_DISABLE "%s %s",
3953 iface->ifname, iface->cross_connect_uplink);
3954 iface->cross_connect_in_use = 0;
3959 void wpas_p2p_notif_connected(struct wpa_supplicant *wpa_s)
3961 if (wpa_s->ap_iface || wpa_s->current_ssid == NULL ||
3962 wpa_s->current_ssid->mode != WPAS_MODE_INFRA ||
3963 wpa_s->cross_connect_disallowed)
3964 wpas_p2p_disable_cross_connect(wpa_s);
3966 wpas_p2p_enable_cross_connect(wpa_s);
3967 if (!wpa_s->ap_iface)
3968 eloop_cancel_timeout(wpas_p2p_group_idle_timeout, wpa_s, NULL);
3972 void wpas_p2p_notif_disconnected(struct wpa_supplicant *wpa_s)
3974 wpas_p2p_disable_cross_connect(wpa_s);
3975 if (!wpa_s->ap_iface)
3976 wpas_p2p_set_group_idle_timeout(wpa_s);
3980 static void wpas_p2p_cross_connect_setup(struct wpa_supplicant *wpa_s)
3982 struct wpa_supplicant *iface;
3984 if (!wpa_s->global->cross_connection)
3987 for (iface = wpa_s->global->ifaces; iface; iface = iface->next) {
3990 if (iface->drv_flags &
3991 WPA_DRIVER_FLAGS_P2P_DEDICATED_INTERFACE)
3993 if (iface->drv_flags & WPA_DRIVER_FLAGS_P2P_CAPABLE)
3996 wpa_s->cross_connect_enabled = 1;
3997 os_strlcpy(wpa_s->cross_connect_uplink, iface->ifname,
3998 sizeof(wpa_s->cross_connect_uplink));
3999 wpa_printf(MSG_DEBUG, "P2P: Enable cross connection from "
4000 "%s to %s whenever uplink is available",
4001 wpa_s->ifname, wpa_s->cross_connect_uplink);
4003 if (iface->ap_iface || iface->current_ssid == NULL ||
4004 iface->current_ssid->mode != WPAS_MODE_INFRA ||
4005 iface->cross_connect_disallowed ||
4006 iface->wpa_state != WPA_COMPLETED)
4009 wpa_s->cross_connect_in_use = 1;
4010 wpa_msg(wpa_s->parent, MSG_INFO,
4011 P2P_EVENT_CROSS_CONNECT_ENABLE "%s %s",
4012 wpa_s->ifname, wpa_s->cross_connect_uplink);
4018 int wpas_p2p_notif_pbc_overlap(struct wpa_supplicant *wpa_s)
4020 if (wpa_s->p2p_group_interface != P2P_GROUP_INTERFACE_CLIENT &&
4021 !wpa_s->p2p_in_provisioning)
4022 return 0; /* not P2P client operation */
4024 wpa_printf(MSG_DEBUG, "P2P: Terminate connection due to WPS PBC "
4026 if (wpa_s != wpa_s->parent)
4027 wpa_msg_ctrl(wpa_s->parent, MSG_INFO, WPS_EVENT_OVERLAP);
4029 if (wpa_s->global->p2p)
4030 p2p_group_formation_failed(wpa_s->global->p2p);
4032 eloop_cancel_timeout(wpas_p2p_group_formation_timeout,
4033 wpa_s->parent, NULL);
4035 wpas_group_formation_completed(wpa_s, 0);
4040 void wpas_p2p_update_channel_list(struct wpa_supplicant *wpa_s)
4042 struct p2p_channels chan;
4044 if (wpa_s->global == NULL || wpa_s->global->p2p == NULL)
4047 os_memset(&chan, 0, sizeof(chan));
4048 if (wpas_p2p_setup_channels(wpa_s, &chan)) {
4049 wpa_printf(MSG_ERROR, "P2P: Failed to update supported "
4054 p2p_update_channel_list(wpa_s->global->p2p, &chan);
4058 int wpas_p2p_cancel(struct wpa_supplicant *wpa_s)
4060 struct wpa_global *global = wpa_s->global;
4064 if (global->p2p == NULL)
4067 wpa_printf(MSG_DEBUG, "P2P: Request to cancel group formation");
4069 if (wpa_s->pending_interface_name[0] &&
4070 !is_zero_ether_addr(wpa_s->pending_interface_addr))
4073 peer = p2p_get_go_neg_peer(global->p2p);
4075 wpa_printf(MSG_DEBUG, "P2P: Unauthorize pending GO Neg peer "
4076 MACSTR, MAC2STR(peer));
4077 p2p_unauthorize(global->p2p, peer);
4080 wpas_p2p_stop_find(wpa_s);
4082 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
4083 if (wpa_s == global->p2p_group_formation &&
4084 (wpa_s->p2p_in_provisioning ||
4085 wpa_s->parent->pending_interface_type ==
4086 WPA_IF_P2P_CLIENT)) {
4087 wpa_printf(MSG_DEBUG, "P2P: Interface %s in group "
4088 "formation found - cancelling",
4091 eloop_cancel_timeout(wpas_p2p_group_formation_timeout,
4092 wpa_s->parent, NULL);
4093 wpas_p2p_group_delete(wpa_s);
4099 wpa_printf(MSG_DEBUG, "P2P: No ongoing group formation found");
4107 void wpas_p2p_interface_unavailable(struct wpa_supplicant *wpa_s)
4109 if (wpa_s->current_ssid == NULL || !wpa_s->current_ssid->p2p_group)
4112 wpa_printf(MSG_DEBUG, "P2P: Remove group due to driver resource not "
4113 "being available anymore");
4114 wpa_s->removal_reason = P2P_GROUP_REMOVAL_UNAVAILABLE;
4115 wpas_p2p_group_delete(wpa_s);
4119 void wpas_p2p_update_best_channels(struct wpa_supplicant *wpa_s,
4120 int freq_24, int freq_5, int freq_overall)
4122 struct p2p_data *p2p = wpa_s->global->p2p;
4123 if (p2p == NULL || (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT))
4125 p2p_set_best_channels(p2p, freq_24, freq_5, freq_overall);
4129 int wpas_p2p_unauthorize(struct wpa_supplicant *wpa_s, const char *addr)
4132 struct p2p_data *p2p = wpa_s->global->p2p;
4134 if (p2p == NULL || (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT))
4137 if (hwaddr_aton(addr, peer))
4140 return p2p_unauthorize(p2p, peer);
4145 * wpas_p2p_disconnect - Disconnect from a P2P Group
4146 * @wpa_s: Pointer to wpa_supplicant data
4147 * Returns: 0 on success, -1 on failure
4149 * This can be used to disconnect from a group in which the local end is a P2P
4150 * Client or to end a P2P Group in case the local end is the Group Owner. If a
4151 * virtual network interface was created for this group, that interface will be
4152 * removed. Otherwise, only the configured P2P group network will be removed
4153 * from the interface.
4155 int wpas_p2p_disconnect(struct wpa_supplicant *wpa_s)
4161 wpa_s->removal_reason = P2P_GROUP_REMOVAL_REQUESTED;
4162 wpas_p2p_group_delete(wpa_s);
4168 int wpas_p2p_in_progress(struct wpa_supplicant *wpa_s)
4170 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
4173 return p2p_in_progress(wpa_s->global->p2p);