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/ap_config.h"
26 #include "ap/p2p_hostapd.h"
27 #include "eapol_supp/eapol_supp_sm.h"
28 #include "rsn_supp/wpa.h"
29 #include "wpa_supplicant_i.h"
32 #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 };
99 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
102 os_memset(¶ms, 0, sizeof(params));
104 /* P2P Wildcard SSID */
105 params.num_ssids = 1;
106 params.ssids[0].ssid = (u8 *) P2P_WILDCARD_SSID;
107 params.ssids[0].ssid_len = P2P_WILDCARD_SSID_LEN;
109 wpa_s->wps->dev.p2p = 1;
110 wps_ie = wps_build_probe_req_ie(0, &wpa_s->wps->dev, wpa_s->wps->uuid,
112 num_req_dev_types, req_dev_types);
116 ielen = p2p_scan_ie_buf_len(wpa_s->global->p2p);
117 ies = wpabuf_alloc(wpabuf_len(wps_ie) + ielen);
122 wpabuf_put_buf(ies, wps_ie);
125 p2p_scan_ie(wpa_s->global->p2p, ies);
127 params.p2p_probe = 1;
128 params.extra_ies = wpabuf_head(ies);
129 params.extra_ies_len = wpabuf_len(ies);
132 case P2P_SCAN_SOCIAL:
133 params.freqs = social_channels;
137 case P2P_SCAN_SPECIFIC:
138 social_channels[0] = freq;
139 social_channels[1] = 0;
140 params.freqs = social_channels;
142 case P2P_SCAN_SOCIAL_PLUS_ONE:
143 social_channels[3] = freq;
144 params.freqs = social_channels;
148 was_in_p2p_scan = wpa_s->scan_res_handler == wpas_p2p_scan_res_handler;
149 wpa_s->scan_res_handler = wpas_p2p_scan_res_handler;
150 ret = wpa_drv_scan(wpa_s, ¶ms);
155 wpa_s->scan_res_handler = NULL;
156 if (wpa_s->scanning || was_in_p2p_scan) {
157 wpa_s->p2p_cb_on_scan_complete = 1;
166 static enum wpa_driver_if_type wpas_p2p_if_type(int p2p_group_interface)
168 switch (p2p_group_interface) {
169 case P2P_GROUP_INTERFACE_PENDING:
170 return WPA_IF_P2P_GROUP;
171 case P2P_GROUP_INTERFACE_GO:
172 return WPA_IF_P2P_GO;
173 case P2P_GROUP_INTERFACE_CLIENT:
174 return WPA_IF_P2P_CLIENT;
177 return WPA_IF_P2P_GROUP;
181 static struct wpa_supplicant * wpas_get_p2p_group(struct wpa_supplicant *wpa_s,
183 size_t ssid_len, int *go)
187 for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) {
188 for (s = wpa_s->conf->ssid; s; s = s->next) {
189 if (s->disabled != 0 || !s->p2p_group ||
190 s->ssid_len != ssid_len ||
191 os_memcmp(ssid, s->ssid, ssid_len) != 0)
193 if (s->mode == WPAS_MODE_P2P_GO &&
194 s != wpa_s->current_ssid)
197 *go = s->mode == WPAS_MODE_P2P_GO;
206 static void wpas_p2p_group_delete(struct wpa_supplicant *wpa_s)
208 struct wpa_ssid *ssid;
212 eloop_cancel_timeout(wpas_p2p_group_idle_timeout, wpa_s, NULL);
214 ssid = wpa_s->current_ssid;
217 * The current SSID was not known, but there may still be a
218 * pending P2P group interface waiting for provisioning.
220 ssid = wpa_s->conf->ssid;
222 if (ssid->p2p_group &&
223 (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION ||
224 (ssid->key_mgmt & WPA_KEY_MGMT_WPS)))
229 if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO)
231 else if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT ||
232 (ssid && ssid->mode == WPAS_MODE_INFRA)) {
233 wpa_s->reassociate = 0;
234 wpa_s->disconnected = 1;
235 wpa_supplicant_deauthenticate(wpa_s,
236 WLAN_REASON_DEAUTH_LEAVING);
240 if (wpa_s->cross_connect_in_use) {
241 wpa_s->cross_connect_in_use = 0;
242 wpa_msg(wpa_s->parent, MSG_INFO,
243 P2P_EVENT_CROSS_CONNECT_DISABLE "%s %s",
244 wpa_s->ifname, wpa_s->cross_connect_uplink);
246 switch (wpa_s->removal_reason) {
247 case P2P_GROUP_REMOVAL_REQUESTED:
248 reason = " reason=REQUESTED";
250 case P2P_GROUP_REMOVAL_IDLE_TIMEOUT:
251 reason = " reason=IDLE";
253 case P2P_GROUP_REMOVAL_UNAVAILABLE:
254 reason = " reason=UNAVAILABLE";
260 wpa_msg(wpa_s->parent, MSG_INFO, P2P_EVENT_GROUP_REMOVED "%s %s%s",
261 wpa_s->ifname, gtype, reason);
264 wpas_notify_p2p_group_removed(wpa_s, ssid, gtype);
266 if (wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE) {
267 struct wpa_global *global;
269 enum wpa_driver_if_type type;
270 wpa_printf(MSG_DEBUG, "P2P: Remove group interface %s",
272 global = wpa_s->global;
273 ifname = os_strdup(wpa_s->ifname);
274 type = wpas_p2p_if_type(wpa_s->p2p_group_interface);
275 wpa_supplicant_remove_iface(wpa_s->global, wpa_s);
276 wpa_s = global->ifaces;
278 wpa_drv_if_remove(wpa_s, type, ifname);
283 wpa_printf(MSG_DEBUG, "P2P: Remove temporary group network");
284 if (ssid && (ssid->p2p_group ||
285 ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION ||
286 (ssid->key_mgmt & WPA_KEY_MGMT_WPS))) {
288 if (ssid == wpa_s->current_ssid) {
289 wpa_sm_set_config(wpa_s->wpa, NULL);
290 eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
291 wpa_s->current_ssid = NULL;
294 * Networks objects created during any P2P activities are not
295 * exposed out as they might/will confuse certain non-P2P aware
296 * applications since these network objects won't behave like
299 * Likewise, we don't send out network removed signals for such
302 wpa_config_remove_network(wpa_s->conf, id);
303 wpa_supplicant_clear_status(wpa_s);
305 wpa_printf(MSG_DEBUG, "P2P: Temporary group network not "
308 wpa_supplicant_ap_deinit(wpa_s);
312 static int wpas_p2p_persistent_group(struct wpa_supplicant *wpa_s,
314 const u8 *ssid, size_t ssid_len)
322 if (wpa_s->go_params)
323 bssid = wpa_s->go_params->peer_interface_addr;
325 bssid = wpa_s->bssid;
327 bss = wpa_bss_get(wpa_s, bssid, ssid, ssid_len);
329 u8 iface_addr[ETH_ALEN];
330 if (p2p_get_interface_addr(wpa_s->global->p2p, bssid,
332 bss = wpa_bss_get(wpa_s, iface_addr, ssid, ssid_len);
335 wpa_printf(MSG_DEBUG, "P2P: Could not figure out whether "
336 "group is persistent - BSS " MACSTR " not found",
341 p2p = wpa_bss_get_vendor_ie_multi(bss, P2P_IE_VENDOR_TYPE);
343 wpa_printf(MSG_DEBUG, "P2P: Could not figure out whether "
344 "group is persistent - BSS " MACSTR
345 " did not include P2P IE", MAC2STR(bssid));
346 wpa_hexdump(MSG_DEBUG, "P2P: Probe Response IEs",
347 (u8 *) (bss + 1), bss->ie_len);
348 wpa_hexdump(MSG_DEBUG, "P2P: Beacon IEs",
349 ((u8 *) bss + 1) + bss->ie_len,
354 group_capab = p2p_get_group_capab(p2p);
355 addr = p2p_get_go_dev_addr(p2p);
356 wpa_printf(MSG_DEBUG, "P2P: Checking whether group is persistent: "
357 "group_capab=0x%x", group_capab);
359 os_memcpy(go_dev_addr, addr, ETH_ALEN);
360 wpa_printf(MSG_DEBUG, "P2P: GO Device Address " MACSTR,
363 os_memset(go_dev_addr, 0, ETH_ALEN);
366 wpa_printf(MSG_DEBUG, "P2P: BSS " MACSTR " group_capab=0x%x "
367 "go_dev_addr=" MACSTR,
368 MAC2STR(bssid), group_capab, MAC2STR(go_dev_addr));
370 return group_capab & P2P_GROUP_CAPAB_PERSISTENT_GROUP;
374 static int wpas_p2p_store_persistent_group(struct wpa_supplicant *wpa_s,
375 struct wpa_ssid *ssid,
376 const u8 *go_dev_addr)
381 wpa_printf(MSG_DEBUG, "P2P: Storing credentials for a persistent "
382 "group (GO Dev Addr " MACSTR ")", MAC2STR(go_dev_addr));
383 for (s = wpa_s->conf->ssid; s; s = s->next) {
384 if (s->disabled == 2 &&
385 os_memcmp(go_dev_addr, s->bssid, ETH_ALEN) == 0 &&
386 s->ssid_len == ssid->ssid_len &&
387 os_memcmp(ssid->ssid, s->ssid, ssid->ssid_len) == 0)
392 wpa_printf(MSG_DEBUG, "P2P: Update existing persistent group "
394 if (ssid->passphrase && !s->passphrase)
396 else if (ssid->passphrase && s->passphrase &&
397 os_strcmp(ssid->passphrase, s->passphrase) != 0)
400 wpa_printf(MSG_DEBUG, "P2P: Create a new persistent group "
403 s = wpa_config_add_network(wpa_s->conf);
408 * Instead of network_added we emit persistent_group_added
409 * notification. Also to keep the defense checks in
410 * persistent_group obj registration method, we set the
411 * relevant flags in s to designate it as a persistent group.
414 s->p2p_persistent_group = 1;
415 wpas_notify_persistent_group_added(wpa_s, s);
416 wpa_config_set_network_defaults(s);
420 s->p2p_persistent_group = 1;
423 os_memcpy(s->bssid, go_dev_addr, ETH_ALEN);
424 s->mode = ssid->mode;
425 s->auth_alg = WPA_AUTH_ALG_OPEN;
426 s->key_mgmt = WPA_KEY_MGMT_PSK;
427 s->proto = WPA_PROTO_RSN;
428 s->pairwise_cipher = WPA_CIPHER_CCMP;
430 if (ssid->passphrase) {
431 os_free(s->passphrase);
432 s->passphrase = os_strdup(ssid->passphrase);
436 os_memcpy(s->psk, ssid->psk, 32);
438 if (s->passphrase && !s->psk_set)
439 wpa_config_update_psk(s);
440 if (s->ssid == NULL || s->ssid_len < ssid->ssid_len) {
442 s->ssid = os_malloc(ssid->ssid_len);
445 s->ssid_len = ssid->ssid_len;
446 os_memcpy(s->ssid, ssid->ssid, s->ssid_len);
449 #ifndef CONFIG_NO_CONFIG_WRITE
450 if (changed && wpa_s->conf->update_config &&
451 wpa_config_write(wpa_s->confname, wpa_s->conf)) {
452 wpa_printf(MSG_DEBUG, "P2P: Failed to update configuration");
454 #endif /* CONFIG_NO_CONFIG_WRITE */
460 static void wpas_group_formation_completed(struct wpa_supplicant *wpa_s,
463 struct wpa_ssid *ssid;
464 const char *ssid_txt;
467 u8 go_dev_addr[ETH_ALEN];
471 * This callback is likely called for the main interface. Update wpa_s
472 * to use the group interface if a new interface was created for the
475 if (wpa_s->global->p2p_group_formation)
476 wpa_s = wpa_s->global->p2p_group_formation;
477 wpa_s->global->p2p_group_formation = NULL;
478 wpa_s->p2p_in_provisioning = 0;
481 wpa_msg(wpa_s->parent, MSG_INFO,
482 P2P_EVENT_GROUP_FORMATION_FAILURE);
483 wpas_p2p_group_delete(wpa_s);
487 wpa_msg(wpa_s->parent, MSG_INFO, P2P_EVENT_GROUP_FORMATION_SUCCESS);
489 ssid = wpa_s->current_ssid;
490 if (ssid && ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION) {
491 ssid->mode = WPAS_MODE_P2P_GO;
492 p2p_group_notif_formation_done(wpa_s->p2p_group);
493 wpa_supplicant_ap_mac_addr_filter(wpa_s, NULL);
498 ssid_txt = wpa_ssid_txt(ssid->ssid, ssid->ssid_len);
499 client = ssid->mode == WPAS_MODE_INFRA;
500 if (ssid->mode == WPAS_MODE_P2P_GO) {
501 persistent = ssid->p2p_persistent_group;
502 os_memcpy(go_dev_addr, wpa_s->parent->own_addr,
505 persistent = wpas_p2p_persistent_group(wpa_s,
511 client = wpa_s->p2p_group_interface ==
512 P2P_GROUP_INTERFACE_CLIENT;
513 os_memset(go_dev_addr, 0, ETH_ALEN);
516 wpa_s->show_group_started = 0;
519 * Indicate event only after successfully completed 4-way
520 * handshake, i.e., when the interface is ready for data
523 wpa_s->show_group_started = 1;
524 } else if (ssid && ssid->passphrase == NULL && ssid->psk_set) {
526 wpa_snprintf_hex(psk, sizeof(psk), ssid->psk, 32);
527 wpa_msg(wpa_s->parent, MSG_INFO, P2P_EVENT_GROUP_STARTED
528 "%s GO ssid=\"%s\" freq=%d psk=%s go_dev_addr=" MACSTR
530 wpa_s->ifname, ssid_txt, ssid->frequency, psk,
531 MAC2STR(go_dev_addr),
532 persistent ? " [PERSISTENT]" : "");
533 wpas_p2p_cross_connect_setup(wpa_s);
534 wpas_p2p_set_group_idle_timeout(wpa_s);
536 wpa_msg(wpa_s->parent, MSG_INFO, P2P_EVENT_GROUP_STARTED
537 "%s GO ssid=\"%s\" freq=%d passphrase=\"%s\" "
538 "go_dev_addr=" MACSTR "%s",
539 wpa_s->ifname, ssid_txt, ssid ? ssid->frequency : 0,
540 ssid && ssid->passphrase ? ssid->passphrase : "",
541 MAC2STR(go_dev_addr),
542 persistent ? " [PERSISTENT]" : "");
543 wpas_p2p_cross_connect_setup(wpa_s);
544 wpas_p2p_set_group_idle_timeout(wpa_s);
548 network_id = wpas_p2p_store_persistent_group(wpa_s->parent,
550 if (network_id < 0 && ssid)
551 network_id = ssid->id;
553 wpas_notify_p2p_group_started(wpa_s, ssid, network_id, 0);
557 static void wpas_p2p_send_action_tx_status(struct wpa_supplicant *wpa_s,
559 const u8 *dst, const u8 *src,
561 const u8 *data, size_t data_len,
562 enum offchannel_send_action_result
565 enum p2p_send_action_result res = P2P_SEND_ACTION_SUCCESS;
567 if (wpa_s->global->p2p == NULL || wpa_s->global->p2p_disabled)
569 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT)
573 case OFFCHANNEL_SEND_ACTION_SUCCESS:
574 res = P2P_SEND_ACTION_SUCCESS;
576 case OFFCHANNEL_SEND_ACTION_NO_ACK:
577 res = P2P_SEND_ACTION_NO_ACK;
579 case OFFCHANNEL_SEND_ACTION_FAILED:
580 res = P2P_SEND_ACTION_FAILED;
584 p2p_send_action_cb(wpa_s->global->p2p, freq, dst, src, bssid, res);
586 if (wpa_s->pending_pd_before_join &&
587 (os_memcmp(dst, wpa_s->pending_join_dev_addr, ETH_ALEN) == 0 ||
588 os_memcmp(dst, wpa_s->pending_join_iface_addr, ETH_ALEN) == 0)) {
589 wpa_s->pending_pd_before_join = 0;
590 wpa_printf(MSG_DEBUG, "P2P: Starting pending "
591 "join-existing-group operation");
592 wpas_p2p_join_start(wpa_s);
597 static int wpas_send_action(void *ctx, unsigned int freq, const u8 *dst,
598 const u8 *src, const u8 *bssid, const u8 *buf,
599 size_t len, unsigned int wait_time)
601 struct wpa_supplicant *wpa_s = ctx;
602 return offchannel_send_action(wpa_s, freq, dst, src, bssid, buf, len,
604 wpas_p2p_send_action_tx_status, 1);
608 static void wpas_send_action_done(void *ctx)
610 struct wpa_supplicant *wpa_s = ctx;
611 offchannel_send_action_done(wpa_s);
615 static int wpas_copy_go_neg_results(struct wpa_supplicant *wpa_s,
616 struct p2p_go_neg_results *params)
618 if (wpa_s->go_params == NULL) {
619 wpa_s->go_params = os_malloc(sizeof(*params));
620 if (wpa_s->go_params == NULL)
623 os_memcpy(wpa_s->go_params, params, sizeof(*params));
628 static void wpas_start_wps_enrollee(struct wpa_supplicant *wpa_s,
629 struct p2p_go_neg_results *res)
631 wpa_printf(MSG_DEBUG, "P2P: Start WPS Enrollee for peer " MACSTR,
632 MAC2STR(res->peer_interface_addr));
633 wpa_hexdump_ascii(MSG_DEBUG, "P2P: Start WPS Enrollee for SSID",
634 res->ssid, res->ssid_len);
635 wpa_supplicant_ap_deinit(wpa_s);
636 wpas_copy_go_neg_results(wpa_s, res);
637 if (res->wps_method == WPS_PBC)
638 wpas_wps_start_pbc(wpa_s, res->peer_interface_addr, 1);
640 u16 dev_pw_id = DEV_PW_DEFAULT;
641 if (wpa_s->p2p_wps_method == WPS_PIN_KEYPAD)
642 dev_pw_id = DEV_PW_REGISTRAR_SPECIFIED;
643 wpas_wps_start_pin(wpa_s, res->peer_interface_addr,
644 wpa_s->p2p_pin, 1, dev_pw_id);
649 static void p2p_go_configured(void *ctx, void *data)
651 struct wpa_supplicant *wpa_s = ctx;
652 struct p2p_go_neg_results *params = data;
653 struct wpa_ssid *ssid;
656 ssid = wpa_s->current_ssid;
657 if (ssid && ssid->mode == WPAS_MODE_P2P_GO) {
658 wpa_printf(MSG_DEBUG, "P2P: Group setup without provisioning");
659 if (wpa_s->global->p2p_group_formation == wpa_s)
660 wpa_s->global->p2p_group_formation = NULL;
661 wpa_msg(wpa_s->parent, MSG_INFO, P2P_EVENT_GROUP_STARTED
662 "%s GO ssid=\"%s\" freq=%d passphrase=\"%s\" "
663 "go_dev_addr=" MACSTR "%s",
665 wpa_ssid_txt(ssid->ssid, ssid->ssid_len),
667 params->passphrase ? params->passphrase : "",
668 MAC2STR(wpa_s->parent->own_addr),
669 params->persistent_group ? " [PERSISTENT]" : "");
671 if (params->persistent_group)
672 network_id = wpas_p2p_store_persistent_group(
674 wpa_s->parent->own_addr);
676 network_id = ssid->id;
677 wpas_notify_p2p_group_started(wpa_s, ssid, network_id, 0);
678 wpas_p2p_cross_connect_setup(wpa_s);
679 wpas_p2p_set_group_idle_timeout(wpa_s);
683 wpa_printf(MSG_DEBUG, "P2P: Setting up WPS for GO provisioning");
684 if (wpa_supplicant_ap_mac_addr_filter(wpa_s,
685 params->peer_interface_addr)) {
686 wpa_printf(MSG_DEBUG, "P2P: Failed to setup MAC address "
690 if (params->wps_method == WPS_PBC)
691 wpa_supplicant_ap_wps_pbc(wpa_s, params->peer_interface_addr,
693 else if (wpa_s->p2p_pin[0])
694 wpa_supplicant_ap_wps_pin(wpa_s, params->peer_interface_addr,
695 wpa_s->p2p_pin, NULL, 0);
696 os_free(wpa_s->go_params);
697 wpa_s->go_params = NULL;
701 static void wpas_start_wps_go(struct wpa_supplicant *wpa_s,
702 struct p2p_go_neg_results *params,
705 struct wpa_ssid *ssid;
707 if (wpas_copy_go_neg_results(wpa_s, params) < 0)
710 ssid = wpa_config_add_network(wpa_s->conf);
714 wpa_config_set_network_defaults(ssid);
717 ssid->p2p_persistent_group = params->persistent_group;
718 ssid->mode = group_formation ? WPAS_MODE_P2P_GROUP_FORMATION :
720 ssid->frequency = params->freq;
721 ssid->ssid = os_zalloc(params->ssid_len + 1);
723 os_memcpy(ssid->ssid, params->ssid, params->ssid_len);
724 ssid->ssid_len = params->ssid_len;
726 ssid->auth_alg = WPA_AUTH_ALG_OPEN;
727 ssid->key_mgmt = WPA_KEY_MGMT_PSK;
728 ssid->proto = WPA_PROTO_RSN;
729 ssid->pairwise_cipher = WPA_CIPHER_CCMP;
730 ssid->passphrase = os_strdup(params->passphrase);
732 wpa_s->ap_configured_cb = p2p_go_configured;
733 wpa_s->ap_configured_cb_ctx = wpa_s;
734 wpa_s->ap_configured_cb_data = wpa_s->go_params;
735 wpa_s->connect_without_scan = ssid;
736 wpa_s->reassociate = 1;
737 wpa_s->disconnected = 0;
738 wpa_supplicant_req_scan(wpa_s, 0, 0);
742 static void wpas_p2p_clone_config(struct wpa_supplicant *dst,
743 const struct wpa_supplicant *src)
745 struct wpa_config *d;
746 const struct wpa_config *s;
751 #define C(n) if (s->n) d->n = os_strdup(s->n)
760 os_memcpy(d->device_type, s->device_type, WPS_DEV_TYPE_LEN);
761 os_memcpy(d->sec_device_type, s->sec_device_type,
762 sizeof(d->sec_device_type));
763 d->num_sec_device_types = s->num_sec_device_types;
765 d->p2p_group_idle = s->p2p_group_idle;
766 d->p2p_intra_bss = s->p2p_intra_bss;
767 d->persistent_reconnect = s->persistent_reconnect;
771 static int wpas_p2p_add_group_interface(struct wpa_supplicant *wpa_s,
772 enum wpa_driver_if_type type)
774 char ifname[120], force_ifname[120];
776 if (wpa_s->pending_interface_name[0]) {
777 wpa_printf(MSG_DEBUG, "P2P: Pending virtual interface exists "
778 "- skip creation of a new one");
779 if (is_zero_ether_addr(wpa_s->pending_interface_addr)) {
780 wpa_printf(MSG_DEBUG, "P2P: Pending virtual address "
781 "unknown?! ifname='%s'",
782 wpa_s->pending_interface_name);
788 os_snprintf(ifname, sizeof(ifname), "p2p-%s-%d", wpa_s->ifname,
789 wpa_s->p2p_group_idx);
790 if (os_strlen(ifname) >= IFNAMSIZ &&
791 os_strlen(wpa_s->ifname) < IFNAMSIZ) {
792 /* Try to avoid going over the IFNAMSIZ length limit */
793 os_snprintf(ifname, sizeof(ifname), "p2p-%d",
794 wpa_s->p2p_group_idx);
796 force_ifname[0] = '\0';
798 wpa_printf(MSG_DEBUG, "P2P: Create a new interface %s for the group",
800 wpa_s->p2p_group_idx++;
802 wpa_s->pending_interface_type = type;
803 if (wpa_drv_if_add(wpa_s, type, ifname, NULL, NULL, force_ifname,
804 wpa_s->pending_interface_addr, NULL) < 0) {
805 wpa_printf(MSG_ERROR, "P2P: Failed to create new group "
810 if (force_ifname[0]) {
811 wpa_printf(MSG_DEBUG, "P2P: Driver forced interface name %s",
813 os_strlcpy(wpa_s->pending_interface_name, force_ifname,
814 sizeof(wpa_s->pending_interface_name));
816 os_strlcpy(wpa_s->pending_interface_name, ifname,
817 sizeof(wpa_s->pending_interface_name));
818 wpa_printf(MSG_DEBUG, "P2P: Created pending virtual interface %s addr "
819 MACSTR, wpa_s->pending_interface_name,
820 MAC2STR(wpa_s->pending_interface_addr));
826 static void wpas_p2p_remove_pending_group_interface(
827 struct wpa_supplicant *wpa_s)
829 if (!wpa_s->pending_interface_name[0] ||
830 is_zero_ether_addr(wpa_s->pending_interface_addr))
831 return; /* No pending virtual interface */
833 wpa_printf(MSG_DEBUG, "P2P: Removing pending group interface %s",
834 wpa_s->pending_interface_name);
835 wpa_drv_if_remove(wpa_s, wpa_s->pending_interface_type,
836 wpa_s->pending_interface_name);
837 os_memset(wpa_s->pending_interface_addr, 0, ETH_ALEN);
838 wpa_s->pending_interface_name[0] = '\0';
842 static struct wpa_supplicant *
843 wpas_p2p_init_group_interface(struct wpa_supplicant *wpa_s, int go)
845 struct wpa_interface iface;
846 struct wpa_supplicant *group_wpa_s;
848 if (!wpa_s->pending_interface_name[0]) {
849 wpa_printf(MSG_ERROR, "P2P: No pending group interface");
850 if (!wpas_p2p_create_iface(wpa_s))
853 * Something has forced us to remove the pending interface; try
854 * to create a new one and hope for the best that we will get
855 * the same local address.
857 if (wpas_p2p_add_group_interface(wpa_s, go ? WPA_IF_P2P_GO :
858 WPA_IF_P2P_CLIENT) < 0)
862 os_memset(&iface, 0, sizeof(iface));
863 iface.ifname = wpa_s->pending_interface_name;
864 iface.driver = wpa_s->driver->name;
865 iface.ctrl_interface = wpa_s->conf->ctrl_interface;
866 iface.driver_param = wpa_s->conf->driver_param;
867 group_wpa_s = wpa_supplicant_add_iface(wpa_s->global, &iface);
868 if (group_wpa_s == NULL) {
869 wpa_printf(MSG_ERROR, "P2P: Failed to create new "
870 "wpa_supplicant interface");
873 wpa_s->pending_interface_name[0] = '\0';
874 group_wpa_s->parent = wpa_s;
875 group_wpa_s->p2p_group_interface = go ? P2P_GROUP_INTERFACE_GO :
876 P2P_GROUP_INTERFACE_CLIENT;
877 wpa_s->global->p2p_group_formation = group_wpa_s;
879 wpas_p2p_clone_config(group_wpa_s, wpa_s);
885 static void wpas_p2p_group_formation_timeout(void *eloop_ctx,
888 struct wpa_supplicant *wpa_s = eloop_ctx;
889 wpa_printf(MSG_DEBUG, "P2P: Group Formation timed out");
890 if (wpa_s->global->p2p)
891 p2p_group_formation_failed(wpa_s->global->p2p);
892 else if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT)
893 wpa_drv_p2p_group_formation_failed(wpa_s);
894 wpas_group_formation_completed(wpa_s, 0);
898 void wpas_go_neg_completed(void *ctx, struct p2p_go_neg_results *res)
900 struct wpa_supplicant *wpa_s = ctx;
902 if (wpa_s->off_channel_freq || wpa_s->roc_waiting_drv_freq) {
903 wpa_drv_cancel_remain_on_channel(wpa_s);
904 wpa_s->off_channel_freq = 0;
905 wpa_s->roc_waiting_drv_freq = 0;
909 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_GO_NEG_FAILURE "status=%d",
911 wpas_notify_p2p_go_neg_completed(wpa_s, res->status);
912 wpas_p2p_remove_pending_group_interface(wpa_s);
916 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_GO_NEG_SUCCESS);
917 wpas_notify_p2p_go_neg_completed(wpa_s, P2P_SC_SUCCESS);
919 if (wpa_s->create_p2p_iface) {
920 struct wpa_supplicant *group_wpa_s =
921 wpas_p2p_init_group_interface(wpa_s, res->role_go);
922 if (group_wpa_s == NULL) {
923 wpas_p2p_remove_pending_group_interface(wpa_s);
926 if (group_wpa_s != wpa_s) {
927 os_memcpy(group_wpa_s->p2p_pin, wpa_s->p2p_pin,
928 sizeof(group_wpa_s->p2p_pin));
929 group_wpa_s->p2p_wps_method = wpa_s->p2p_wps_method;
931 os_memset(wpa_s->pending_interface_addr, 0, ETH_ALEN);
932 wpa_s->pending_interface_name[0] = '\0';
933 group_wpa_s->p2p_in_provisioning = 1;
936 wpas_start_wps_go(group_wpa_s, res, 1);
938 wpas_start_wps_enrollee(group_wpa_s, res);
940 wpa_s->p2p_in_provisioning = 1;
941 wpa_s->global->p2p_group_formation = wpa_s;
944 wpas_start_wps_go(wpa_s, res, 1);
946 wpas_start_wps_enrollee(ctx, res);
949 wpa_s->p2p_long_listen = 0;
950 eloop_cancel_timeout(wpas_p2p_long_listen_timeout, wpa_s, NULL);
952 eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s, NULL);
953 eloop_register_timeout(15 + res->peer_config_timeout / 100,
954 (res->peer_config_timeout % 100) * 10000,
955 wpas_p2p_group_formation_timeout, wpa_s, NULL);
959 void wpas_go_neg_req_rx(void *ctx, const u8 *src, u16 dev_passwd_id)
961 struct wpa_supplicant *wpa_s = ctx;
962 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_GO_NEG_REQUEST MACSTR
963 " dev_passwd_id=%u", MAC2STR(src), dev_passwd_id);
965 wpas_notify_p2p_go_neg_req(wpa_s, src, dev_passwd_id);
969 void wpas_dev_found(void *ctx, const u8 *addr,
970 const struct p2p_peer_info *info,
973 struct wpa_supplicant *wpa_s = ctx;
974 char devtype[WPS_DEV_TYPE_BUFSIZE];
976 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_DEVICE_FOUND MACSTR
977 " p2p_dev_addr=" MACSTR
978 " pri_dev_type=%s name='%s' config_methods=0x%x "
979 "dev_capab=0x%x group_capab=0x%x",
980 MAC2STR(addr), MAC2STR(info->p2p_device_addr),
981 wps_dev_type_bin2str(info->pri_dev_type, devtype,
983 info->device_name, info->config_methods,
984 info->dev_capab, info->group_capab);
986 wpas_notify_p2p_device_found(ctx, info->p2p_device_addr, new_device);
990 static void wpas_dev_lost(void *ctx, const u8 *dev_addr)
992 struct wpa_supplicant *wpa_s = ctx;
994 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_DEVICE_LOST
995 "p2p_dev_addr=" MACSTR, MAC2STR(dev_addr));
997 wpas_notify_p2p_device_lost(wpa_s, dev_addr);
1001 static int wpas_start_listen(void *ctx, unsigned int freq,
1002 unsigned int duration,
1003 const struct wpabuf *probe_resp_ie)
1005 struct wpa_supplicant *wpa_s = ctx;
1007 wpa_drv_set_ap_wps_ie(wpa_s, NULL, probe_resp_ie, NULL);
1009 if (wpa_drv_probe_req_report(wpa_s, 1) < 0) {
1010 wpa_printf(MSG_DEBUG, "P2P: Failed to request the driver to "
1011 "report received Probe Request frames");
1015 wpa_s->pending_listen_freq = freq;
1016 wpa_s->pending_listen_duration = duration;
1018 if (wpa_drv_remain_on_channel(wpa_s, freq, duration) < 0) {
1019 wpa_printf(MSG_DEBUG, "P2P: Failed to request the driver "
1020 "to remain on channel (%u MHz) for Listen "
1022 wpa_s->pending_listen_freq = 0;
1025 wpa_s->off_channel_freq = 0;
1026 wpa_s->roc_waiting_drv_freq = freq;
1032 static void wpas_stop_listen(void *ctx)
1034 struct wpa_supplicant *wpa_s = ctx;
1035 if (wpa_s->off_channel_freq || wpa_s->roc_waiting_drv_freq) {
1036 wpa_drv_cancel_remain_on_channel(wpa_s);
1037 wpa_s->off_channel_freq = 0;
1038 wpa_s->roc_waiting_drv_freq = 0;
1040 wpa_drv_set_ap_wps_ie(wpa_s, NULL, NULL, NULL);
1041 wpa_drv_probe_req_report(wpa_s, 0);
1045 static int wpas_send_probe_resp(void *ctx, const struct wpabuf *buf)
1047 struct wpa_supplicant *wpa_s = ctx;
1048 return wpa_drv_send_mlme(wpa_s, wpabuf_head(buf), wpabuf_len(buf));
1052 static struct p2p_srv_bonjour *
1053 wpas_p2p_service_get_bonjour(struct wpa_supplicant *wpa_s,
1054 const struct wpabuf *query)
1056 struct p2p_srv_bonjour *bsrv;
1059 len = wpabuf_len(query);
1060 dl_list_for_each(bsrv, &wpa_s->global->p2p_srv_bonjour,
1061 struct p2p_srv_bonjour, list) {
1062 if (len == wpabuf_len(bsrv->query) &&
1063 os_memcmp(wpabuf_head(query), wpabuf_head(bsrv->query),
1071 static struct p2p_srv_upnp *
1072 wpas_p2p_service_get_upnp(struct wpa_supplicant *wpa_s, u8 version,
1073 const char *service)
1075 struct p2p_srv_upnp *usrv;
1077 dl_list_for_each(usrv, &wpa_s->global->p2p_srv_upnp,
1078 struct p2p_srv_upnp, list) {
1079 if (version == usrv->version &&
1080 os_strcmp(service, usrv->service) == 0)
1087 static void wpas_sd_add_proto_not_avail(struct wpabuf *resp, u8 srv_proto,
1092 if (wpabuf_tailroom(resp) < 5)
1095 /* Length (to be filled) */
1096 len_pos = wpabuf_put(resp, 2);
1097 wpabuf_put_u8(resp, srv_proto);
1098 wpabuf_put_u8(resp, srv_trans_id);
1100 wpabuf_put_u8(resp, P2P_SD_PROTO_NOT_AVAILABLE);
1101 /* Response Data: empty */
1102 WPA_PUT_LE16(len_pos, (u8 *) wpabuf_put(resp, 0) - len_pos - 2);
1106 static void wpas_sd_all_bonjour(struct wpa_supplicant *wpa_s,
1107 struct wpabuf *resp, u8 srv_trans_id)
1109 struct p2p_srv_bonjour *bsrv;
1112 wpa_printf(MSG_DEBUG, "P2P: SD Request for all Bonjour services");
1114 if (dl_list_empty(&wpa_s->global->p2p_srv_bonjour)) {
1115 wpa_printf(MSG_DEBUG, "P2P: Bonjour protocol not available");
1119 dl_list_for_each(bsrv, &wpa_s->global->p2p_srv_bonjour,
1120 struct p2p_srv_bonjour, list) {
1121 if (wpabuf_tailroom(resp) <
1122 5 + wpabuf_len(bsrv->query) + wpabuf_len(bsrv->resp))
1124 /* Length (to be filled) */
1125 len_pos = wpabuf_put(resp, 2);
1126 wpabuf_put_u8(resp, P2P_SERV_BONJOUR);
1127 wpabuf_put_u8(resp, srv_trans_id);
1129 wpabuf_put_u8(resp, P2P_SD_SUCCESS);
1130 wpa_hexdump_ascii(MSG_DEBUG, "P2P: Matching Bonjour service",
1131 wpabuf_head(bsrv->resp),
1132 wpabuf_len(bsrv->resp));
1134 wpabuf_put_buf(resp, bsrv->query); /* Key */
1135 wpabuf_put_buf(resp, bsrv->resp); /* Value */
1136 WPA_PUT_LE16(len_pos, (u8 *) wpabuf_put(resp, 0) - len_pos -
1142 static void wpas_sd_req_bonjour(struct wpa_supplicant *wpa_s,
1143 struct wpabuf *resp, u8 srv_trans_id,
1144 const u8 *query, size_t query_len)
1146 struct p2p_srv_bonjour *bsrv;
1150 wpa_hexdump_ascii(MSG_DEBUG, "P2P: SD Request for Bonjour",
1152 if (dl_list_empty(&wpa_s->global->p2p_srv_bonjour)) {
1153 wpa_printf(MSG_DEBUG, "P2P: Bonjour protocol not available");
1154 wpas_sd_add_proto_not_avail(resp, P2P_SERV_BONJOUR,
1159 if (query_len == 0) {
1160 wpas_sd_all_bonjour(wpa_s, resp, srv_trans_id);
1164 if (wpabuf_tailroom(resp) < 5)
1166 /* Length (to be filled) */
1167 len_pos = wpabuf_put(resp, 2);
1168 wpabuf_put_u8(resp, P2P_SERV_BONJOUR);
1169 wpabuf_put_u8(resp, srv_trans_id);
1171 wpabuf_set(&buf, query, query_len);
1172 bsrv = wpas_p2p_service_get_bonjour(wpa_s, &buf);
1174 wpa_printf(MSG_DEBUG, "P2P: Requested Bonjour service not "
1178 wpabuf_put_u8(resp, P2P_SD_REQUESTED_INFO_NOT_AVAILABLE);
1179 /* Response Data: empty */
1180 WPA_PUT_LE16(len_pos, (u8 *) wpabuf_put(resp, 0) - len_pos -
1186 wpabuf_put_u8(resp, P2P_SD_SUCCESS);
1187 wpa_hexdump_ascii(MSG_DEBUG, "P2P: Matching Bonjour service",
1188 wpabuf_head(bsrv->resp), wpabuf_len(bsrv->resp));
1190 if (wpabuf_tailroom(resp) >=
1191 wpabuf_len(bsrv->query) + wpabuf_len(bsrv->resp)) {
1193 wpabuf_put_buf(resp, bsrv->query); /* Key */
1194 wpabuf_put_buf(resp, bsrv->resp); /* Value */
1196 WPA_PUT_LE16(len_pos, (u8 *) wpabuf_put(resp, 0) - len_pos - 2);
1200 static void wpas_sd_all_upnp(struct wpa_supplicant *wpa_s,
1201 struct wpabuf *resp, u8 srv_trans_id)
1203 struct p2p_srv_upnp *usrv;
1206 wpa_printf(MSG_DEBUG, "P2P: SD Request for all UPnP services");
1208 if (dl_list_empty(&wpa_s->global->p2p_srv_upnp)) {
1209 wpa_printf(MSG_DEBUG, "P2P: UPnP protocol not available");
1213 dl_list_for_each(usrv, &wpa_s->global->p2p_srv_upnp,
1214 struct p2p_srv_upnp, list) {
1215 if (wpabuf_tailroom(resp) < 5 + 1 + os_strlen(usrv->service))
1218 /* Length (to be filled) */
1219 len_pos = wpabuf_put(resp, 2);
1220 wpabuf_put_u8(resp, P2P_SERV_UPNP);
1221 wpabuf_put_u8(resp, srv_trans_id);
1224 wpabuf_put_u8(resp, P2P_SD_SUCCESS);
1226 wpabuf_put_u8(resp, usrv->version);
1227 wpa_printf(MSG_DEBUG, "P2P: Matching UPnP Service: %s",
1229 wpabuf_put_str(resp, usrv->service);
1230 WPA_PUT_LE16(len_pos, (u8 *) wpabuf_put(resp, 0) - len_pos -
1236 static void wpas_sd_req_upnp(struct wpa_supplicant *wpa_s,
1237 struct wpabuf *resp, u8 srv_trans_id,
1238 const u8 *query, size_t query_len)
1240 struct p2p_srv_upnp *usrv;
1246 wpa_hexdump_ascii(MSG_DEBUG, "P2P: SD Request for UPnP",
1249 if (dl_list_empty(&wpa_s->global->p2p_srv_upnp)) {
1250 wpa_printf(MSG_DEBUG, "P2P: UPnP protocol not available");
1251 wpas_sd_add_proto_not_avail(resp, P2P_SERV_UPNP,
1256 if (query_len == 0) {
1257 wpas_sd_all_upnp(wpa_s, resp, srv_trans_id);
1261 if (wpabuf_tailroom(resp) < 5)
1264 /* Length (to be filled) */
1265 len_pos = wpabuf_put(resp, 2);
1266 wpabuf_put_u8(resp, P2P_SERV_UPNP);
1267 wpabuf_put_u8(resp, srv_trans_id);
1270 str = os_malloc(query_len);
1273 os_memcpy(str, query + 1, query_len - 1);
1274 str[query_len - 1] = '\0';
1276 dl_list_for_each(usrv, &wpa_s->global->p2p_srv_upnp,
1277 struct p2p_srv_upnp, list) {
1278 if (version != usrv->version)
1281 if (os_strcmp(str, "ssdp:all") != 0 &&
1282 os_strstr(usrv->service, str) == NULL)
1285 if (wpabuf_tailroom(resp) < 2)
1289 wpabuf_put_u8(resp, P2P_SD_SUCCESS);
1291 wpabuf_put_u8(resp, version);
1293 wpabuf_put_u8(resp, ',');
1297 wpa_printf(MSG_DEBUG, "P2P: Matching UPnP Service: %s",
1299 if (wpabuf_tailroom(resp) < os_strlen(usrv->service))
1301 wpabuf_put_str(resp, usrv->service);
1306 wpa_printf(MSG_DEBUG, "P2P: Requested UPnP service not "
1309 wpabuf_put_u8(resp, P2P_SD_REQUESTED_INFO_NOT_AVAILABLE);
1310 /* Response Data: empty */
1313 WPA_PUT_LE16(len_pos, (u8 *) wpabuf_put(resp, 0) - len_pos - 2);
1317 void wpas_sd_request(void *ctx, int freq, const u8 *sa, u8 dialog_token,
1318 u16 update_indic, const u8 *tlvs, size_t tlvs_len)
1320 struct wpa_supplicant *wpa_s = ctx;
1321 const u8 *pos = tlvs;
1322 const u8 *end = tlvs + tlvs_len;
1325 struct wpabuf *resp;
1326 u8 srv_proto, srv_trans_id;
1330 wpa_hexdump(MSG_MSGDUMP, "P2P: Service Discovery Request TLVs",
1332 buf_len = 2 * tlvs_len + 1;
1333 buf = os_malloc(buf_len);
1335 wpa_snprintf_hex(buf, buf_len, tlvs, tlvs_len);
1336 wpa_msg_ctrl(wpa_s, MSG_INFO, P2P_EVENT_SERV_DISC_REQ "%d "
1338 freq, MAC2STR(sa), dialog_token, update_indic,
1343 if (wpa_s->p2p_sd_over_ctrl_iface)
1344 return; /* to be processed by an external program */
1346 resp = wpabuf_alloc(10000);
1350 while (pos + 1 < end) {
1351 wpa_printf(MSG_DEBUG, "P2P: Service Request TLV");
1352 slen = WPA_GET_LE16(pos);
1354 if (pos + slen > end || slen < 2) {
1355 wpa_printf(MSG_DEBUG, "P2P: Unexpected Query Data "
1360 tlv_end = pos + slen;
1363 wpa_printf(MSG_DEBUG, "P2P: Service Protocol Type %u",
1365 srv_trans_id = *pos++;
1366 wpa_printf(MSG_DEBUG, "P2P: Service Transaction ID %u",
1369 wpa_hexdump(MSG_MSGDUMP, "P2P: Query Data",
1370 pos, tlv_end - pos);
1373 if (wpa_s->force_long_sd) {
1374 wpa_printf(MSG_DEBUG, "P2P: SD test - force long "
1376 wpas_sd_all_bonjour(wpa_s, resp, srv_trans_id);
1377 wpas_sd_all_upnp(wpa_s, resp, srv_trans_id);
1381 switch (srv_proto) {
1382 case P2P_SERV_ALL_SERVICES:
1383 wpa_printf(MSG_DEBUG, "P2P: Service Discovery Request "
1384 "for all services");
1385 if (dl_list_empty(&wpa_s->global->p2p_srv_upnp) &&
1386 dl_list_empty(&wpa_s->global->p2p_srv_bonjour)) {
1387 wpa_printf(MSG_DEBUG, "P2P: No service "
1388 "discovery protocols available");
1389 wpas_sd_add_proto_not_avail(
1390 resp, P2P_SERV_ALL_SERVICES,
1394 wpas_sd_all_bonjour(wpa_s, resp, srv_trans_id);
1395 wpas_sd_all_upnp(wpa_s, resp, srv_trans_id);
1397 case P2P_SERV_BONJOUR:
1398 wpas_sd_req_bonjour(wpa_s, resp, srv_trans_id,
1399 pos, tlv_end - pos);
1402 wpas_sd_req_upnp(wpa_s, resp, srv_trans_id,
1403 pos, tlv_end - pos);
1406 wpa_printf(MSG_DEBUG, "P2P: Unavailable service "
1407 "protocol %u", srv_proto);
1408 wpas_sd_add_proto_not_avail(resp, srv_proto,
1417 wpas_notify_p2p_sd_request(wpa_s, freq, sa, dialog_token,
1418 update_indic, tlvs, tlvs_len);
1420 wpas_p2p_sd_response(wpa_s, freq, sa, dialog_token, resp);
1426 void wpas_sd_response(void *ctx, const u8 *sa, u16 update_indic,
1427 const u8 *tlvs, size_t tlvs_len)
1429 struct wpa_supplicant *wpa_s = ctx;
1430 const u8 *pos = tlvs;
1431 const u8 *end = tlvs + tlvs_len;
1437 wpa_hexdump(MSG_MSGDUMP, "P2P: Service Discovery Response TLVs",
1439 if (tlvs_len > 1500) {
1440 /* TODO: better way for handling this */
1441 wpa_msg_ctrl(wpa_s, MSG_INFO,
1442 P2P_EVENT_SERV_DISC_RESP MACSTR
1443 " %u <long response: %u bytes>",
1444 MAC2STR(sa), update_indic,
1445 (unsigned int) tlvs_len);
1447 buf_len = 2 * tlvs_len + 1;
1448 buf = os_malloc(buf_len);
1450 wpa_snprintf_hex(buf, buf_len, tlvs, tlvs_len);
1451 wpa_msg_ctrl(wpa_s, MSG_INFO,
1452 P2P_EVENT_SERV_DISC_RESP MACSTR " %u %s",
1453 MAC2STR(sa), update_indic, buf);
1459 u8 srv_proto, srv_trans_id, status;
1461 wpa_printf(MSG_DEBUG, "P2P: Service Response TLV");
1462 slen = WPA_GET_LE16(pos);
1464 if (pos + slen > end || slen < 3) {
1465 wpa_printf(MSG_DEBUG, "P2P: Unexpected Response Data "
1469 tlv_end = pos + slen;
1472 wpa_printf(MSG_DEBUG, "P2P: Service Protocol Type %u",
1474 srv_trans_id = *pos++;
1475 wpa_printf(MSG_DEBUG, "P2P: Service Transaction ID %u",
1478 wpa_printf(MSG_DEBUG, "P2P: Status Code ID %u",
1481 wpa_hexdump(MSG_MSGDUMP, "P2P: Response Data",
1482 pos, tlv_end - pos);
1487 wpas_notify_p2p_sd_response(wpa_s, sa, update_indic, tlvs, tlvs_len);
1491 void * wpas_p2p_sd_request(struct wpa_supplicant *wpa_s, const u8 *dst,
1492 const struct wpabuf *tlvs)
1494 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT)
1495 return (void *) wpa_drv_p2p_sd_request(wpa_s, dst, tlvs);
1496 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
1498 return p2p_sd_request(wpa_s->global->p2p, dst, tlvs);
1502 void * wpas_p2p_sd_request_upnp(struct wpa_supplicant *wpa_s, const u8 *dst,
1503 u8 version, const char *query)
1505 struct wpabuf *tlvs;
1508 tlvs = wpabuf_alloc(2 + 1 + 1 + 1 + os_strlen(query));
1511 wpabuf_put_le16(tlvs, 1 + 1 + 1 + os_strlen(query));
1512 wpabuf_put_u8(tlvs, P2P_SERV_UPNP); /* Service Protocol Type */
1513 wpabuf_put_u8(tlvs, 1); /* Service Transaction ID */
1514 wpabuf_put_u8(tlvs, version);
1515 wpabuf_put_str(tlvs, query);
1516 ret = wpas_p2p_sd_request(wpa_s, dst, tlvs);
1522 int wpas_p2p_sd_cancel_request(struct wpa_supplicant *wpa_s, void *req)
1524 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT)
1525 return wpa_drv_p2p_sd_cancel_request(wpa_s, (u64) req);
1526 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
1528 return p2p_sd_cancel_request(wpa_s->global->p2p, req);
1532 void wpas_p2p_sd_response(struct wpa_supplicant *wpa_s, int freq,
1533 const u8 *dst, u8 dialog_token,
1534 const struct wpabuf *resp_tlvs)
1536 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT) {
1537 wpa_drv_p2p_sd_response(wpa_s, freq, dst, dialog_token,
1541 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
1543 p2p_sd_response(wpa_s->global->p2p, freq, dst, dialog_token,
1548 void wpas_p2p_sd_service_update(struct wpa_supplicant *wpa_s)
1550 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT) {
1551 wpa_drv_p2p_service_update(wpa_s);
1554 if (wpa_s->global->p2p)
1555 p2p_sd_service_update(wpa_s->global->p2p);
1559 static void wpas_p2p_srv_bonjour_free(struct p2p_srv_bonjour *bsrv)
1561 dl_list_del(&bsrv->list);
1562 wpabuf_free(bsrv->query);
1563 wpabuf_free(bsrv->resp);
1568 static void wpas_p2p_srv_upnp_free(struct p2p_srv_upnp *usrv)
1570 dl_list_del(&usrv->list);
1571 os_free(usrv->service);
1576 void wpas_p2p_service_flush(struct wpa_supplicant *wpa_s)
1578 struct p2p_srv_bonjour *bsrv, *bn;
1579 struct p2p_srv_upnp *usrv, *un;
1581 dl_list_for_each_safe(bsrv, bn, &wpa_s->global->p2p_srv_bonjour,
1582 struct p2p_srv_bonjour, list)
1583 wpas_p2p_srv_bonjour_free(bsrv);
1585 dl_list_for_each_safe(usrv, un, &wpa_s->global->p2p_srv_upnp,
1586 struct p2p_srv_upnp, list)
1587 wpas_p2p_srv_upnp_free(usrv);
1589 wpas_p2p_sd_service_update(wpa_s);
1593 int wpas_p2p_service_add_bonjour(struct wpa_supplicant *wpa_s,
1594 struct wpabuf *query, struct wpabuf *resp)
1596 struct p2p_srv_bonjour *bsrv;
1598 bsrv = wpas_p2p_service_get_bonjour(wpa_s, query);
1601 wpabuf_free(bsrv->resp);
1606 bsrv = os_zalloc(sizeof(*bsrv));
1609 bsrv->query = query;
1611 dl_list_add(&wpa_s->global->p2p_srv_bonjour, &bsrv->list);
1613 wpas_p2p_sd_service_update(wpa_s);
1618 int wpas_p2p_service_del_bonjour(struct wpa_supplicant *wpa_s,
1619 const struct wpabuf *query)
1621 struct p2p_srv_bonjour *bsrv;
1623 bsrv = wpas_p2p_service_get_bonjour(wpa_s, query);
1626 wpas_p2p_srv_bonjour_free(bsrv);
1627 wpas_p2p_sd_service_update(wpa_s);
1632 int wpas_p2p_service_add_upnp(struct wpa_supplicant *wpa_s, u8 version,
1633 const char *service)
1635 struct p2p_srv_upnp *usrv;
1637 if (wpas_p2p_service_get_upnp(wpa_s, version, service))
1638 return 0; /* Already listed */
1639 usrv = os_zalloc(sizeof(*usrv));
1642 usrv->version = version;
1643 usrv->service = os_strdup(service);
1644 if (usrv->service == NULL) {
1648 dl_list_add(&wpa_s->global->p2p_srv_upnp, &usrv->list);
1650 wpas_p2p_sd_service_update(wpa_s);
1655 int wpas_p2p_service_del_upnp(struct wpa_supplicant *wpa_s, u8 version,
1656 const char *service)
1658 struct p2p_srv_upnp *usrv;
1660 usrv = wpas_p2p_service_get_upnp(wpa_s, version, service);
1663 wpas_p2p_srv_upnp_free(usrv);
1664 wpas_p2p_sd_service_update(wpa_s);
1669 static void wpas_prov_disc_local_display(struct wpa_supplicant *wpa_s,
1670 const u8 *peer, const char *params,
1671 unsigned int generated_pin)
1673 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_SHOW_PIN MACSTR " %08d%s",
1674 MAC2STR(peer), generated_pin, params);
1678 static void wpas_prov_disc_local_keypad(struct wpa_supplicant *wpa_s,
1679 const u8 *peer, const char *params)
1681 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_ENTER_PIN MACSTR "%s",
1682 MAC2STR(peer), params);
1686 void wpas_prov_disc_req(void *ctx, const u8 *peer, u16 config_methods,
1687 const u8 *dev_addr, const u8 *pri_dev_type,
1688 const char *dev_name, u16 supp_config_methods,
1689 u8 dev_capab, u8 group_capab)
1691 struct wpa_supplicant *wpa_s = ctx;
1692 char devtype[WPS_DEV_TYPE_BUFSIZE];
1694 u8 empty_dev_type[8];
1695 unsigned int generated_pin = 0;
1697 if (pri_dev_type == NULL) {
1698 os_memset(empty_dev_type, 0, sizeof(empty_dev_type));
1699 pri_dev_type = empty_dev_type;
1701 os_snprintf(params, sizeof(params), " p2p_dev_addr=" MACSTR
1702 " pri_dev_type=%s name='%s' config_methods=0x%x "
1703 "dev_capab=0x%x group_capab=0x%x",
1705 wps_dev_type_bin2str(pri_dev_type, devtype,
1707 dev_name, supp_config_methods, dev_capab, group_capab);
1708 params[sizeof(params) - 1] = '\0';
1710 if (config_methods & WPS_CONFIG_DISPLAY) {
1711 generated_pin = wps_generate_pin();
1712 wpas_prov_disc_local_display(wpa_s, peer, params,
1714 } else if (config_methods & WPS_CONFIG_KEYPAD)
1715 wpas_prov_disc_local_keypad(wpa_s, peer, params);
1716 else if (config_methods & WPS_CONFIG_PUSHBUTTON)
1717 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_PBC_REQ MACSTR
1718 "%s", MAC2STR(peer), params);
1720 wpas_notify_p2p_provision_discovery(wpa_s, peer, 1 /* request */,
1721 P2P_PROV_DISC_SUCCESS,
1722 config_methods, generated_pin);
1726 void wpas_prov_disc_resp(void *ctx, const u8 *peer, u16 config_methods)
1728 struct wpa_supplicant *wpa_s = ctx;
1729 unsigned int generated_pin = 0;
1731 if (config_methods & WPS_CONFIG_DISPLAY)
1732 wpas_prov_disc_local_keypad(wpa_s, peer, "");
1733 else if (config_methods & WPS_CONFIG_KEYPAD) {
1734 generated_pin = wps_generate_pin();
1735 wpas_prov_disc_local_display(wpa_s, peer, "", generated_pin);
1736 } else if (config_methods & WPS_CONFIG_PUSHBUTTON)
1737 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_PROV_DISC_PBC_RESP MACSTR,
1740 wpas_notify_p2p_provision_discovery(wpa_s, peer, 0 /* response */,
1741 P2P_PROV_DISC_SUCCESS,
1742 config_methods, generated_pin);
1744 if (wpa_s->pending_pd_before_join &&
1745 (os_memcmp(peer, wpa_s->pending_join_dev_addr, ETH_ALEN) == 0 ||
1746 os_memcmp(peer, wpa_s->pending_join_iface_addr, ETH_ALEN) == 0)) {
1747 wpa_s->pending_pd_before_join = 0;
1748 wpa_printf(MSG_DEBUG, "P2P: Starting pending "
1749 "join-existing-group operation");
1750 wpas_p2p_join_start(wpa_s);
1755 static void wpas_prov_disc_fail(void *ctx, const u8 *peer,
1756 enum p2p_prov_disc_status status)
1758 struct wpa_supplicant *wpa_s = ctx;
1760 wpas_notify_p2p_provision_discovery(wpa_s, peer, 0 /* response */,
1765 static u8 wpas_invitation_process(void *ctx, const u8 *sa, const u8 *bssid,
1766 const u8 *go_dev_addr, const u8 *ssid,
1767 size_t ssid_len, int *go, u8 *group_bssid,
1768 int *force_freq, int persistent_group)
1770 struct wpa_supplicant *wpa_s = ctx;
1772 u8 cur_bssid[ETH_ALEN];
1774 struct wpa_supplicant *grp;
1776 if (!persistent_group) {
1777 wpa_printf(MSG_DEBUG, "P2P: Invitation from " MACSTR
1778 " to join an active group", MAC2STR(sa));
1779 if (!is_zero_ether_addr(wpa_s->p2p_auth_invite) &&
1780 (os_memcmp(go_dev_addr, wpa_s->p2p_auth_invite, ETH_ALEN)
1782 os_memcmp(sa, wpa_s->p2p_auth_invite, ETH_ALEN) == 0)) {
1783 wpa_printf(MSG_DEBUG, "P2P: Accept previously "
1784 "authorized invitation");
1788 * Do not accept the invitation automatically; notify user and
1791 return P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE;
1794 grp = wpas_get_p2p_group(wpa_s, ssid, ssid_len, go);
1796 wpa_printf(MSG_DEBUG, "P2P: Accept invitation to already "
1797 "running persistent group");
1799 os_memcpy(group_bssid, grp->own_addr, ETH_ALEN);
1803 if (!wpa_s->conf->persistent_reconnect)
1804 return P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE;
1806 for (s = wpa_s->conf->ssid; s; s = s->next) {
1807 if (s->disabled == 2 &&
1808 os_memcmp(s->bssid, go_dev_addr, ETH_ALEN) == 0 &&
1809 s->ssid_len == ssid_len &&
1810 os_memcmp(ssid, s->ssid, ssid_len) == 0)
1815 wpa_printf(MSG_DEBUG, "P2P: Invitation from " MACSTR
1816 " requested reinvocation of an unknown group",
1818 return P2P_SC_FAIL_UNKNOWN_GROUP;
1821 if (s->mode == WPAS_MODE_P2P_GO && !wpas_p2p_create_iface(wpa_s)) {
1823 if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
1824 wpa_printf(MSG_DEBUG, "P2P: The only available "
1825 "interface is already in use - reject "
1827 return P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE;
1829 os_memcpy(group_bssid, wpa_s->own_addr, ETH_ALEN);
1830 } else if (s->mode == WPAS_MODE_P2P_GO) {
1832 if (wpas_p2p_add_group_interface(wpa_s, WPA_IF_P2P_GO) < 0)
1834 wpa_printf(MSG_ERROR, "P2P: Failed to allocate a new "
1835 "interface address for the group");
1836 return P2P_SC_FAIL_UNABLE_TO_ACCOMMODATE;
1838 os_memcpy(group_bssid, wpa_s->pending_interface_addr,
1843 if (wpa_s->current_ssid && wpa_drv_get_bssid(wpa_s, cur_bssid) == 0 &&
1844 wpa_s->assoc_freq) {
1845 wpa_printf(MSG_DEBUG, "P2P: Trying to force channel to match "
1846 "the channel we are already using");
1847 *force_freq = wpa_s->assoc_freq;
1850 res = wpa_drv_shared_freq(wpa_s);
1852 wpa_printf(MSG_DEBUG, "P2P: Trying to force channel to match "
1853 "with the channel we are already using on a "
1854 "shared interface");
1858 return P2P_SC_SUCCESS;
1862 static void wpas_invitation_received(void *ctx, const u8 *sa, const u8 *bssid,
1863 const u8 *ssid, size_t ssid_len,
1864 const u8 *go_dev_addr, u8 status,
1867 struct wpa_supplicant *wpa_s = ctx;
1870 for (s = wpa_s->conf->ssid; s; s = s->next) {
1871 if (s->disabled == 2 &&
1872 s->ssid_len == ssid_len &&
1873 os_memcmp(ssid, s->ssid, ssid_len) == 0)
1877 if (status == P2P_SC_SUCCESS) {
1878 wpa_printf(MSG_DEBUG, "P2P: Invitation from peer " MACSTR
1879 " was accepted; op_freq=%d MHz",
1880 MAC2STR(sa), op_freq);
1882 wpas_p2p_group_add_persistent(
1883 wpa_s, s, s->mode == WPAS_MODE_P2P_GO, 0);
1885 wpas_p2p_join(wpa_s, bssid, go_dev_addr,
1886 wpa_s->p2p_wps_method);
1891 if (status != P2P_SC_FAIL_INFO_CURRENTLY_UNAVAILABLE) {
1892 wpa_printf(MSG_DEBUG, "P2P: Invitation from peer " MACSTR
1893 " was rejected (status %u)", MAC2STR(sa), status);
1899 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RECEIVED
1900 "sa=" MACSTR " go_dev_addr=" MACSTR
1901 " bssid=" MACSTR " unknown-network",
1902 MAC2STR(sa), MAC2STR(go_dev_addr),
1905 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RECEIVED
1906 "sa=" MACSTR " go_dev_addr=" MACSTR
1908 MAC2STR(sa), MAC2STR(go_dev_addr));
1913 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RECEIVED "sa=" MACSTR
1914 " persistent=%d", MAC2STR(sa), s->id);
1918 static void wpas_invitation_result(void *ctx, int status, const u8 *bssid)
1920 struct wpa_supplicant *wpa_s = ctx;
1921 struct wpa_ssid *ssid;
1924 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RESULT
1925 "status=%d " MACSTR,
1926 status, MAC2STR(bssid));
1928 wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_INVITATION_RESULT
1929 "status=%d ", status);
1931 wpas_notify_p2p_invitation_result(wpa_s, status, bssid);
1933 if (wpa_s->pending_invite_ssid_id == -1)
1934 return; /* Invitation to active group */
1936 if (status != P2P_SC_SUCCESS) {
1937 wpas_p2p_remove_pending_group_interface(wpa_s);
1941 ssid = wpa_config_get_network(wpa_s->conf,
1942 wpa_s->pending_invite_ssid_id);
1944 wpa_printf(MSG_ERROR, "P2P: Could not find persistent group "
1945 "data matching with invitation");
1949 wpas_p2p_group_add_persistent(wpa_s, ssid,
1950 ssid->mode == WPAS_MODE_P2P_GO, 0);
1954 static int wpas_p2p_default_channels(struct wpa_supplicant *wpa_s,
1955 struct p2p_channels *chan)
1959 wpa_printf(MSG_DEBUG, "P2P: Enable operating classes for 2.4 GHz "
1962 /* Operating class 81 - 2.4 GHz band channels 1..13 */
1963 chan->reg_class[cla].reg_class = 81;
1964 chan->reg_class[cla].channels = 11;
1965 for (i = 0; i < 11; i++)
1966 chan->reg_class[cla].channel[i] = i + 1;
1969 wpa_printf(MSG_DEBUG, "P2P: Enable operating classes for lower 5 GHz "
1972 /* Operating class 115 - 5 GHz, channels 36-48 */
1973 chan->reg_class[cla].reg_class = 115;
1974 chan->reg_class[cla].channels = 4;
1975 chan->reg_class[cla].channel[0] = 36;
1976 chan->reg_class[cla].channel[1] = 40;
1977 chan->reg_class[cla].channel[2] = 44;
1978 chan->reg_class[cla].channel[3] = 48;
1981 wpa_printf(MSG_DEBUG, "P2P: Enable operating classes for higher 5 GHz "
1984 /* Operating class 124 - 5 GHz, channels 149,153,157,161 */
1985 chan->reg_class[cla].reg_class = 124;
1986 chan->reg_class[cla].channels = 4;
1987 chan->reg_class[cla].channel[0] = 149;
1988 chan->reg_class[cla].channel[1] = 153;
1989 chan->reg_class[cla].channel[2] = 157;
1990 chan->reg_class[cla].channel[3] = 161;
1993 chan->reg_classes = cla;
1998 static struct hostapd_hw_modes * get_mode(struct hostapd_hw_modes *modes,
2000 enum hostapd_hw_mode mode)
2004 for (i = 0; i < num_modes; i++) {
2005 if (modes[i].mode == mode)
2013 static int has_channel(struct hostapd_hw_modes *mode, u8 chan, int *flags)
2017 for (i = 0; i < mode->num_channels; i++) {
2018 if (mode->channels[i].chan == chan) {
2020 *flags = mode->channels[i].flag;
2021 return !(mode->channels[i].flag &
2022 (HOSTAPD_CHAN_DISABLED |
2023 HOSTAPD_CHAN_PASSIVE_SCAN |
2024 HOSTAPD_CHAN_NO_IBSS |
2025 HOSTAPD_CHAN_RADAR));
2033 struct p2p_oper_class_map {
2034 enum hostapd_hw_mode mode;
2039 enum { BW20, BW40PLUS, BW40MINUS } bw;
2042 static int wpas_p2p_setup_channels(struct wpa_supplicant *wpa_s,
2043 struct p2p_channels *chan)
2045 struct hostapd_hw_modes *mode;
2047 struct p2p_oper_class_map op_class[] = {
2048 { HOSTAPD_MODE_IEEE80211G, 81, 1, 13, 1, BW20 },
2049 { HOSTAPD_MODE_IEEE80211G, 82, 14, 14, 1, BW20 },
2050 #if 0 /* Do not enable HT40 on 2 GHz for now */
2051 { HOSTAPD_MODE_IEEE80211G, 83, 1, 9, 1, BW40PLUS },
2052 { HOSTAPD_MODE_IEEE80211G, 84, 5, 13, 1, BW40MINUS },
2054 { HOSTAPD_MODE_IEEE80211A, 115, 36, 48, 4, BW20 },
2055 { HOSTAPD_MODE_IEEE80211A, 124, 149, 161, 4, BW20 },
2056 { HOSTAPD_MODE_IEEE80211A, 116, 36, 44, 8, BW40PLUS },
2057 { HOSTAPD_MODE_IEEE80211A, 117, 40, 48, 8, BW40MINUS },
2058 { HOSTAPD_MODE_IEEE80211A, 126, 149, 157, 8, BW40PLUS },
2059 { HOSTAPD_MODE_IEEE80211A, 127, 153, 161, 8, BW40MINUS },
2060 { -1, 0, 0, 0, 0, BW20 }
2063 if (wpa_s->hw.modes == NULL) {
2064 wpa_printf(MSG_DEBUG, "P2P: Driver did not support fetching "
2065 "of all supported channels; assume dualband "
2067 return wpas_p2p_default_channels(wpa_s, chan);
2072 for (op = 0; op_class[op].op_class; op++) {
2073 struct p2p_oper_class_map *o = &op_class[op];
2075 struct p2p_reg_class *reg = NULL;
2077 mode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, o->mode);
2080 for (ch = o->min_chan; ch <= o->max_chan; ch += o->inc) {
2082 if (!has_channel(mode, ch, &flag))
2084 if (o->bw == BW40MINUS &&
2085 (!(flag & HOSTAPD_CHAN_HT40MINUS) ||
2086 !has_channel(mode, ch - 4, NULL)))
2088 if (o->bw == BW40PLUS &&
2089 (!(flag & HOSTAPD_CHAN_HT40PLUS) ||
2090 !has_channel(mode, ch + 4, NULL)))
2093 wpa_printf(MSG_DEBUG, "P2P: Add operating "
2094 "class %u", o->op_class);
2095 reg = &chan->reg_class[cla];
2097 reg->reg_class = o->op_class;
2099 reg->channel[reg->channels] = ch;
2103 wpa_hexdump(MSG_DEBUG, "P2P: Channels",
2104 reg->channel, reg->channels);
2108 chan->reg_classes = cla;
2114 static int wpas_get_noa(void *ctx, const u8 *interface_addr, u8 *buf,
2117 struct wpa_supplicant *wpa_s = ctx;
2119 for (wpa_s = wpa_s->global->ifaces; wpa_s; wpa_s = wpa_s->next) {
2120 if (os_memcmp(wpa_s->own_addr, interface_addr, ETH_ALEN) == 0)
2126 return wpa_drv_get_noa(wpa_s, buf, buf_len);
2131 * wpas_p2p_init - Initialize P2P module for %wpa_supplicant
2132 * @global: Pointer to global data from wpa_supplicant_init()
2133 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
2134 * Returns: 0 on success, -1 on failure
2136 int wpas_p2p_init(struct wpa_global *global, struct wpa_supplicant *wpa_s)
2138 struct p2p_config p2p;
2142 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_CAPABLE))
2148 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT) {
2149 struct p2p_params params;
2151 wpa_printf(MSG_DEBUG, "P2P: Use driver-based P2P management");
2152 os_memset(¶ms, 0, sizeof(params));
2153 params.dev_name = wpa_s->conf->device_name;
2154 os_memcpy(params.pri_dev_type, wpa_s->conf->device_type,
2156 params.num_sec_dev_types = wpa_s->conf->num_sec_device_types;
2157 os_memcpy(params.sec_dev_type,
2158 wpa_s->conf->sec_device_type,
2159 params.num_sec_dev_types * WPS_DEV_TYPE_LEN);
2161 if (wpa_drv_p2p_set_params(wpa_s, ¶ms) < 0)
2167 os_memset(&p2p, 0, sizeof(p2p));
2168 p2p.msg_ctx = wpa_s;
2170 p2p.p2p_scan = wpas_p2p_scan;
2171 p2p.send_action = wpas_send_action;
2172 p2p.send_action_done = wpas_send_action_done;
2173 p2p.go_neg_completed = wpas_go_neg_completed;
2174 p2p.go_neg_req_rx = wpas_go_neg_req_rx;
2175 p2p.dev_found = wpas_dev_found;
2176 p2p.dev_lost = wpas_dev_lost;
2177 p2p.start_listen = wpas_start_listen;
2178 p2p.stop_listen = wpas_stop_listen;
2179 p2p.send_probe_resp = wpas_send_probe_resp;
2180 p2p.sd_request = wpas_sd_request;
2181 p2p.sd_response = wpas_sd_response;
2182 p2p.prov_disc_req = wpas_prov_disc_req;
2183 p2p.prov_disc_resp = wpas_prov_disc_resp;
2184 p2p.prov_disc_fail = wpas_prov_disc_fail;
2185 p2p.invitation_process = wpas_invitation_process;
2186 p2p.invitation_received = wpas_invitation_received;
2187 p2p.invitation_result = wpas_invitation_result;
2188 p2p.get_noa = wpas_get_noa;
2190 os_memcpy(wpa_s->global->p2p_dev_addr, wpa_s->own_addr, ETH_ALEN);
2191 os_memcpy(p2p.dev_addr, wpa_s->own_addr, ETH_ALEN);
2192 p2p.dev_name = wpa_s->conf->device_name;
2193 p2p.manufacturer = wpa_s->conf->manufacturer;
2194 p2p.model_name = wpa_s->conf->model_name;
2195 p2p.model_number = wpa_s->conf->model_number;
2196 p2p.serial_number = wpa_s->conf->serial_number;
2198 os_memcpy(p2p.uuid, wpa_s->wps->uuid, 16);
2199 p2p.config_methods = wpa_s->wps->config_methods;
2202 if (wpa_s->conf->p2p_listen_reg_class &&
2203 wpa_s->conf->p2p_listen_channel) {
2204 p2p.reg_class = wpa_s->conf->p2p_listen_reg_class;
2205 p2p.channel = wpa_s->conf->p2p_listen_channel;
2209 * Pick one of the social channels randomly as the listen
2212 os_get_random((u8 *) &r, sizeof(r));
2213 p2p.channel = 1 + (r % 3) * 5;
2215 wpa_printf(MSG_DEBUG, "P2P: Own listen channel: %d", p2p.channel);
2217 if (wpa_s->conf->p2p_oper_reg_class &&
2218 wpa_s->conf->p2p_oper_channel) {
2219 p2p.op_reg_class = wpa_s->conf->p2p_oper_reg_class;
2220 p2p.op_channel = wpa_s->conf->p2p_oper_channel;
2221 p2p.cfg_op_channel = 1;
2222 wpa_printf(MSG_DEBUG, "P2P: Configured operating channel: "
2223 "%d:%d", p2p.op_reg_class, p2p.op_channel);
2226 p2p.op_reg_class = 81;
2228 * Use random operation channel from (1, 6, 11) if no other
2229 * preference is indicated.
2231 os_get_random((u8 *) &r, sizeof(r));
2232 p2p.op_channel = 1 + (r % 3) * 5;
2233 p2p.cfg_op_channel = 0;
2234 wpa_printf(MSG_DEBUG, "P2P: Random operating channel: "
2235 "%d:%d", p2p.op_reg_class, p2p.op_channel);
2237 if (wpa_s->conf->country[0] && wpa_s->conf->country[1]) {
2238 os_memcpy(p2p.country, wpa_s->conf->country, 2);
2239 p2p.country[2] = 0x04;
2241 os_memcpy(p2p.country, "XX\x04", 3);
2243 if (wpas_p2p_setup_channels(wpa_s, &p2p.channels)) {
2244 wpa_printf(MSG_ERROR, "P2P: Failed to configure supported "
2249 os_memcpy(p2p.pri_dev_type, wpa_s->conf->device_type,
2252 p2p.num_sec_dev_types = wpa_s->conf->num_sec_device_types;
2253 os_memcpy(p2p.sec_dev_type, wpa_s->conf->sec_device_type,
2254 p2p.num_sec_dev_types * WPS_DEV_TYPE_LEN);
2256 p2p.concurrent_operations = !!(wpa_s->drv_flags &
2257 WPA_DRIVER_FLAGS_P2P_CONCURRENT);
2259 p2p.max_peers = 100;
2261 if (wpa_s->conf->p2p_ssid_postfix) {
2262 p2p.ssid_postfix_len =
2263 os_strlen(wpa_s->conf->p2p_ssid_postfix);
2264 if (p2p.ssid_postfix_len > sizeof(p2p.ssid_postfix))
2265 p2p.ssid_postfix_len = sizeof(p2p.ssid_postfix);
2266 os_memcpy(p2p.ssid_postfix, wpa_s->conf->p2p_ssid_postfix,
2267 p2p.ssid_postfix_len);
2270 p2p.p2p_intra_bss = wpa_s->conf->p2p_intra_bss;
2272 global->p2p = p2p_init(&p2p);
2273 if (global->p2p == NULL)
2276 for (i = 0; i < MAX_WPS_VENDOR_EXT; i++) {
2277 if (wpa_s->conf->wps_vendor_ext[i] == NULL)
2279 p2p_add_wps_vendor_extension(
2280 global->p2p, wpa_s->conf->wps_vendor_ext[i]);
2288 * wpas_p2p_deinit - Deinitialize per-interface P2P data
2289 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
2291 * This function deinitialize per-interface P2P data.
2293 void wpas_p2p_deinit(struct wpa_supplicant *wpa_s)
2295 if (wpa_s->driver && wpa_s->drv_priv)
2296 wpa_drv_probe_req_report(wpa_s, 0);
2297 os_free(wpa_s->go_params);
2298 wpa_s->go_params = NULL;
2299 eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s, NULL);
2300 eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL);
2301 wpa_s->p2p_long_listen = 0;
2302 eloop_cancel_timeout(wpas_p2p_long_listen_timeout, wpa_s, NULL);
2303 eloop_cancel_timeout(wpas_p2p_group_idle_timeout, wpa_s, NULL);
2304 wpas_p2p_remove_pending_group_interface(wpa_s);
2306 /* TODO: remove group interface from the driver if this wpa_s instance
2307 * is on top of a P2P group interface */
2312 * wpas_p2p_deinit_global - Deinitialize global P2P module
2313 * @global: Pointer to global data from wpa_supplicant_init()
2315 * This function deinitializes the global (per device) P2P module.
2317 void wpas_p2p_deinit_global(struct wpa_global *global)
2319 struct wpa_supplicant *wpa_s, *tmp;
2322 if (global->p2p == NULL)
2325 /* Remove remaining P2P group interfaces */
2326 wpa_s = global->ifaces;
2328 wpas_p2p_service_flush(wpa_s);
2329 while (wpa_s && wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE)
2330 wpa_s = wpa_s->next;
2332 enum wpa_driver_if_type type;
2333 tmp = global->ifaces;
2336 tmp->p2p_group_interface == NOT_P2P_GROUP_INTERFACE)) {
2341 ifname = os_strdup(tmp->ifname);
2342 type = wpas_p2p_if_type(tmp->p2p_group_interface);
2343 wpa_supplicant_remove_iface(global, tmp);
2345 wpa_drv_if_remove(wpa_s, type, ifname);
2350 * Deinit GO data on any possibly remaining interface (if main
2351 * interface is used as GO).
2353 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
2354 if (wpa_s->ap_iface)
2355 wpas_p2p_group_deinit(wpa_s);
2358 p2p_deinit(global->p2p);
2363 static int wpas_p2p_create_iface(struct wpa_supplicant *wpa_s)
2365 if (wpa_s->drv_flags &
2366 (WPA_DRIVER_FLAGS_P2P_DEDICATED_INTERFACE |
2367 WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P))
2368 return 1; /* P2P group requires a new interface in every case
2370 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_CONCURRENT))
2371 return 0; /* driver does not support concurrent operations */
2372 if (wpa_s->global->ifaces->next)
2373 return 1; /* more that one interface already in use */
2374 if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
2375 return 1; /* this interface is already in use */
2380 static int wpas_p2p_start_go_neg(struct wpa_supplicant *wpa_s,
2381 const u8 *peer_addr,
2382 enum p2p_wps_method wps_method,
2383 int go_intent, const u8 *own_interface_addr,
2384 unsigned int force_freq, int persistent_group)
2386 if (persistent_group && wpa_s->conf->persistent_reconnect)
2387 persistent_group = 2;
2389 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT) {
2390 return wpa_drv_p2p_connect(wpa_s, peer_addr, wps_method,
2391 go_intent, own_interface_addr,
2392 force_freq, persistent_group);
2395 return p2p_connect(wpa_s->global->p2p, peer_addr, wps_method,
2396 go_intent, own_interface_addr, force_freq,
2401 static int wpas_p2p_auth_go_neg(struct wpa_supplicant *wpa_s,
2402 const u8 *peer_addr,
2403 enum p2p_wps_method wps_method,
2404 int go_intent, const u8 *own_interface_addr,
2405 unsigned int force_freq, int persistent_group)
2407 if (persistent_group && wpa_s->conf->persistent_reconnect)
2408 persistent_group = 2;
2410 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT)
2413 return p2p_authorize(wpa_s->global->p2p, peer_addr, wps_method,
2414 go_intent, own_interface_addr, force_freq,
2419 static void wpas_p2p_check_join_scan_limit(struct wpa_supplicant *wpa_s)
2421 wpa_s->p2p_join_scan_count++;
2422 wpa_printf(MSG_DEBUG, "P2P: Join scan attempt %d",
2423 wpa_s->p2p_join_scan_count);
2424 if (wpa_s->p2p_join_scan_count > P2P_MAX_JOIN_SCAN_ATTEMPTS) {
2425 wpa_printf(MSG_DEBUG, "P2P: Failed to find GO " MACSTR
2426 " for join operationg - stop join attempt",
2427 MAC2STR(wpa_s->pending_join_iface_addr));
2428 eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL);
2429 wpa_msg(wpa_s->parent, MSG_INFO,
2430 P2P_EVENT_GROUP_FORMATION_FAILURE);
2435 static void wpas_p2p_scan_res_join(struct wpa_supplicant *wpa_s,
2436 struct wpa_scan_results *scan_res)
2438 struct wpa_bss *bss;
2440 u8 iface_addr[ETH_ALEN];
2442 eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL);
2444 if (wpa_s->global->p2p_disabled)
2447 wpa_printf(MSG_DEBUG, "P2P: Scan results received (%d BSS) for join",
2448 scan_res ? (int) scan_res->num : -1);
2451 wpas_p2p_scan_res_handler(wpa_s, scan_res);
2453 freq = p2p_get_oper_freq(wpa_s->global->p2p,
2454 wpa_s->pending_join_iface_addr);
2456 p2p_get_interface_addr(wpa_s->global->p2p,
2457 wpa_s->pending_join_dev_addr,
2459 os_memcmp(iface_addr, wpa_s->pending_join_dev_addr, ETH_ALEN) != 0)
2461 wpa_printf(MSG_DEBUG, "P2P: Overwrite pending interface "
2462 "address for join from " MACSTR " to " MACSTR
2463 " based on newly discovered P2P peer entry",
2464 MAC2STR(wpa_s->pending_join_iface_addr),
2465 MAC2STR(iface_addr));
2466 os_memcpy(wpa_s->pending_join_iface_addr, iface_addr,
2469 freq = p2p_get_oper_freq(wpa_s->global->p2p,
2470 wpa_s->pending_join_iface_addr);
2473 wpa_printf(MSG_DEBUG, "P2P: Target GO operating frequency "
2474 "from P2P peer table: %d MHz", freq);
2476 bss = wpa_bss_get_bssid(wpa_s, wpa_s->pending_join_iface_addr);
2479 wpa_printf(MSG_DEBUG, "P2P: Target GO operating frequency "
2480 "from BSS table: %d MHz", freq);
2485 wpa_printf(MSG_DEBUG, "P2P: Send Provision Discovery Request "
2486 "prior to joining an existing group (GO " MACSTR
2488 MAC2STR(wpa_s->pending_join_dev_addr), freq);
2489 wpa_s->pending_pd_before_join = 1;
2491 switch (wpa_s->pending_join_wps_method) {
2492 case WPS_PIN_DISPLAY:
2493 method = WPS_CONFIG_KEYPAD;
2495 case WPS_PIN_KEYPAD:
2496 method = WPS_CONFIG_DISPLAY;
2499 method = WPS_CONFIG_PUSHBUTTON;
2506 if (p2p_prov_disc_req(wpa_s->global->p2p,
2507 wpa_s->pending_join_dev_addr, method, 1)
2509 wpa_printf(MSG_DEBUG, "P2P: Failed to send Provision "
2510 "Discovery Request before joining an "
2512 wpa_s->pending_pd_before_join = 0;
2517 * Actual join operation will be started from the Action frame
2518 * TX status callback.
2523 wpa_printf(MSG_DEBUG, "P2P: Failed to find BSS/GO - try again later");
2524 eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL);
2525 eloop_register_timeout(1, 0, wpas_p2p_join_scan, wpa_s, NULL);
2526 wpas_p2p_check_join_scan_limit(wpa_s);
2530 /* Start join operation immediately */
2531 wpas_p2p_join_start(wpa_s);
2535 static void wpas_p2p_join_scan(void *eloop_ctx, void *timeout_ctx)
2537 struct wpa_supplicant *wpa_s = eloop_ctx;
2539 struct wpa_driver_scan_params params;
2540 struct wpabuf *wps_ie, *ies;
2543 os_memset(¶ms, 0, sizeof(params));
2545 /* P2P Wildcard SSID */
2546 params.num_ssids = 1;
2547 params.ssids[0].ssid = (u8 *) P2P_WILDCARD_SSID;
2548 params.ssids[0].ssid_len = P2P_WILDCARD_SSID_LEN;
2550 wpa_s->wps->dev.p2p = 1;
2551 wps_ie = wps_build_probe_req_ie(0, &wpa_s->wps->dev, wpa_s->wps->uuid,
2552 WPS_REQ_ENROLLEE, 0, NULL);
2553 if (wps_ie == NULL) {
2554 wpas_p2p_scan_res_join(wpa_s, NULL);
2558 ielen = p2p_scan_ie_buf_len(wpa_s->global->p2p);
2559 ies = wpabuf_alloc(wpabuf_len(wps_ie) + ielen);
2561 wpabuf_free(wps_ie);
2562 wpas_p2p_scan_res_join(wpa_s, NULL);
2565 wpabuf_put_buf(ies, wps_ie);
2566 wpabuf_free(wps_ie);
2568 p2p_scan_ie(wpa_s->global->p2p, ies);
2570 params.p2p_probe = 1;
2571 params.extra_ies = wpabuf_head(ies);
2572 params.extra_ies_len = wpabuf_len(ies);
2575 * Run a scan to update BSS table and start Provision Discovery once
2576 * the new scan results become available.
2578 wpa_s->scan_res_handler = wpas_p2p_scan_res_join;
2579 ret = wpa_drv_scan(wpa_s, ¶ms);
2584 wpa_printf(MSG_DEBUG, "P2P: Failed to start scan for join - "
2586 eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL);
2587 eloop_register_timeout(1, 0, wpas_p2p_join_scan, wpa_s, NULL);
2588 wpas_p2p_check_join_scan_limit(wpa_s);
2593 static int wpas_p2p_join(struct wpa_supplicant *wpa_s, const u8 *iface_addr,
2594 const u8 *dev_addr, enum p2p_wps_method wps_method)
2596 wpa_printf(MSG_DEBUG, "P2P: Request to join existing group (iface "
2597 MACSTR " dev " MACSTR ")",
2598 MAC2STR(iface_addr), MAC2STR(dev_addr));
2600 os_memcpy(wpa_s->pending_join_iface_addr, iface_addr, ETH_ALEN);
2601 os_memcpy(wpa_s->pending_join_dev_addr, dev_addr, ETH_ALEN);
2602 wpa_s->pending_join_wps_method = wps_method;
2604 /* Make sure we are not running find during connection establishment */
2605 wpas_p2p_stop_find(wpa_s);
2607 wpa_s->p2p_join_scan_count = 0;
2608 wpas_p2p_join_scan(wpa_s, NULL);
2613 static int wpas_p2p_join_start(struct wpa_supplicant *wpa_s)
2615 struct wpa_supplicant *group;
2616 struct p2p_go_neg_results res;
2618 group = wpas_p2p_get_group_iface(wpa_s, 0, 0);
2621 if (group != wpa_s) {
2622 os_memcpy(group->p2p_pin, wpa_s->p2p_pin,
2623 sizeof(group->p2p_pin));
2624 group->p2p_wps_method = wpa_s->p2p_wps_method;
2627 group->p2p_in_provisioning = 1;
2629 os_memset(&res, 0, sizeof(res));
2630 os_memcpy(res.peer_interface_addr, wpa_s->pending_join_iface_addr,
2632 res.wps_method = wpa_s->pending_join_wps_method;
2633 wpas_start_wps_enrollee(group, &res);
2636 * Allow a longer timeout for join-a-running-group than normal 15
2637 * second group formation timeout since the GO may not have authorized
2638 * our connection yet.
2640 eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s, NULL);
2641 eloop_register_timeout(60, 0, wpas_p2p_group_formation_timeout,
2649 * wpas_p2p_connect - Request P2P Group Formation to be started
2650 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
2651 * @peer_addr: Address of the peer P2P Device
2652 * @pin: PIN to use during provisioning or %NULL to indicate PBC mode
2653 * @persistent_group: Whether to create a persistent group
2654 * @join: Whether to join an existing group (as a client) instead of starting
2655 * Group Owner negotiation; @peer_addr is BSSID in that case
2656 * @auth: Whether to only authorize the connection instead of doing that and
2657 * initiating Group Owner negotiation
2658 * @go_intent: GO Intent or -1 to use default
2659 * @freq: Frequency for the group or 0 for auto-selection
2660 * Returns: 0 or new PIN (if pin was %NULL) on success, -1 on unspecified
2661 * failure, -2 on failure due to channel not currently available,
2662 * -3 if forced channel is not supported
2664 int wpas_p2p_connect(struct wpa_supplicant *wpa_s, const u8 *peer_addr,
2665 const char *pin, enum p2p_wps_method wps_method,
2666 int persistent_group, int join, int auth, int go_intent,
2669 int force_freq = 0, oper_freq = 0;
2672 enum wpa_driver_if_type iftype;
2674 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
2678 go_intent = wpa_s->conf->p2p_go_intent;
2681 wpa_s->p2p_long_listen = 0;
2683 wpa_s->p2p_wps_method = wps_method;
2686 os_strlcpy(wpa_s->p2p_pin, pin, sizeof(wpa_s->p2p_pin));
2687 else if (wps_method == WPS_PIN_DISPLAY) {
2688 ret = wps_generate_pin();
2689 os_snprintf(wpa_s->p2p_pin, sizeof(wpa_s->p2p_pin), "%08d",
2691 wpa_printf(MSG_DEBUG, "P2P: Randomly generated PIN: %s",
2694 wpa_s->p2p_pin[0] = '\0';
2697 u8 iface_addr[ETH_ALEN], dev_addr[ETH_ALEN];
2699 wpa_printf(MSG_DEBUG, "P2P: Authorize invitation to "
2700 "connect a running group from " MACSTR,
2701 MAC2STR(peer_addr));
2702 os_memcpy(wpa_s->p2p_auth_invite, peer_addr, ETH_ALEN);
2705 os_memcpy(dev_addr, peer_addr, ETH_ALEN);
2706 if (p2p_get_interface_addr(wpa_s->global->p2p, peer_addr,
2708 os_memcpy(iface_addr, peer_addr, ETH_ALEN);
2709 p2p_get_dev_addr(wpa_s->global->p2p, peer_addr,
2712 if (wpas_p2p_join(wpa_s, iface_addr, dev_addr, wps_method) <
2718 if (wpa_s->current_ssid && wpa_drv_get_bssid(wpa_s, bssid) == 0 &&
2720 oper_freq = wpa_s->assoc_freq;
2722 oper_freq = wpa_drv_shared_freq(wpa_s);
2728 if (!p2p_supported_freq(wpa_s->global->p2p, freq)) {
2729 wpa_printf(MSG_DEBUG, "P2P: The forced channel "
2730 "(%u MHz) is not supported for P2P uses",
2735 if (oper_freq > 0 && freq != oper_freq &&
2736 !(wpa_s->drv_flags &
2737 WPA_DRIVER_FLAGS_MULTI_CHANNEL_CONCURRENT)) {
2738 wpa_printf(MSG_DEBUG, "P2P: Cannot start P2P group "
2739 "on %u MHz while connected on another "
2740 "channel (%u MHz)", freq, oper_freq);
2743 wpa_printf(MSG_DEBUG, "P2P: Trying to force us to use the "
2744 "requested channel (%u MHz)", freq);
2746 } else if (oper_freq > 0 &&
2747 !p2p_supported_freq(wpa_s->global->p2p, oper_freq)) {
2748 if (!(wpa_s->drv_flags &
2749 WPA_DRIVER_FLAGS_MULTI_CHANNEL_CONCURRENT)) {
2750 wpa_printf(MSG_DEBUG, "P2P: Cannot start P2P group "
2751 "while connected on non-P2P supported "
2752 "channel (%u MHz)", oper_freq);
2755 wpa_printf(MSG_DEBUG, "P2P: Current operating channel "
2756 "(%u MHz) not available for P2P - try to use "
2757 "another channel", oper_freq);
2759 } else if (oper_freq > 0) {
2760 wpa_printf(MSG_DEBUG, "P2P: Trying to force us to use the "
2761 "channel we are already using (%u MHz) on another "
2762 "interface", oper_freq);
2763 force_freq = oper_freq;
2766 wpa_s->create_p2p_iface = wpas_p2p_create_iface(wpa_s);
2768 if (!wpa_s->create_p2p_iface) {
2770 if (wpas_p2p_auth_go_neg(wpa_s, peer_addr, wps_method,
2771 go_intent, wpa_s->own_addr,
2772 force_freq, persistent_group)
2777 if (wpas_p2p_start_go_neg(wpa_s, peer_addr, wps_method,
2778 go_intent, wpa_s->own_addr,
2779 force_freq, persistent_group) < 0)
2784 /* Prepare to add a new interface for the group */
2785 iftype = WPA_IF_P2P_GROUP;
2786 if (go_intent == 15)
2787 iftype = WPA_IF_P2P_GO;
2788 if (wpas_p2p_add_group_interface(wpa_s, iftype) < 0) {
2789 wpa_printf(MSG_ERROR, "P2P: Failed to allocate a new "
2790 "interface for the group");
2795 if (wpas_p2p_auth_go_neg(wpa_s, peer_addr, wps_method,
2797 wpa_s->pending_interface_addr,
2798 force_freq, persistent_group) < 0)
2802 if (wpas_p2p_start_go_neg(wpa_s, peer_addr, wps_method, go_intent,
2803 wpa_s->pending_interface_addr,
2804 force_freq, persistent_group) < 0) {
2805 wpas_p2p_remove_pending_group_interface(wpa_s);
2813 * wpas_p2p_remain_on_channel_cb - Indication of remain-on-channel start
2814 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
2815 * @freq: Frequency of the channel in MHz
2816 * @duration: Duration of the stay on the channel in milliseconds
2818 * This callback is called when the driver indicates that it has started the
2819 * requested remain-on-channel duration.
2821 void wpas_p2p_remain_on_channel_cb(struct wpa_supplicant *wpa_s,
2822 unsigned int freq, unsigned int duration)
2824 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
2826 if (wpa_s->off_channel_freq == wpa_s->pending_listen_freq) {
2827 p2p_listen_cb(wpa_s->global->p2p, wpa_s->pending_listen_freq,
2828 wpa_s->pending_listen_duration);
2829 wpa_s->pending_listen_freq = 0;
2834 static int wpas_p2p_listen_start(struct wpa_supplicant *wpa_s,
2835 unsigned int timeout)
2837 /* Limit maximum Listen state time based on driver limitation. */
2838 if (timeout > wpa_s->max_remain_on_chan)
2839 timeout = wpa_s->max_remain_on_chan;
2841 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT)
2842 return wpa_drv_p2p_listen(wpa_s, timeout);
2844 return p2p_listen(wpa_s->global->p2p, timeout);
2849 * wpas_p2p_cancel_remain_on_channel_cb - Remain-on-channel timeout
2850 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
2851 * @freq: Frequency of the channel in MHz
2853 * This callback is called when the driver indicates that a remain-on-channel
2854 * operation has been completed, i.e., the duration on the requested channel
2857 void wpas_p2p_cancel_remain_on_channel_cb(struct wpa_supplicant *wpa_s,
2860 wpa_printf(MSG_DEBUG, "P2P: Cancel remain-on-channel callback "
2861 "(p2p_long_listen=%d ms pending_action_tx=%p)",
2862 wpa_s->p2p_long_listen, wpa_s->pending_action_tx);
2863 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
2865 if (p2p_listen_end(wpa_s->global->p2p, freq) > 0)
2866 return; /* P2P module started a new operation */
2867 if (wpa_s->pending_action_tx)
2869 if (wpa_s->p2p_long_listen > 0)
2870 wpa_s->p2p_long_listen -= wpa_s->max_remain_on_chan;
2871 if (wpa_s->p2p_long_listen > 0) {
2872 wpa_printf(MSG_DEBUG, "P2P: Continuing long Listen state");
2873 wpas_p2p_listen_start(wpa_s, wpa_s->p2p_long_listen);
2879 * wpas_p2p_group_remove - Remove a P2P group
2880 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
2881 * @ifname: Network interface name of the group interface or "*" to remove all
2883 * Returns: 0 on success, -1 on failure
2885 * This function is used to remove a P2P group. This can be used to disconnect
2886 * from a group in which the local end is a P2P Client or to end a P2P Group in
2887 * case the local end is the Group Owner. If a virtual network interface was
2888 * created for this group, that interface will be removed. Otherwise, only the
2889 * configured P2P group network will be removed from the interface.
2891 int wpas_p2p_group_remove(struct wpa_supplicant *wpa_s, const char *ifname)
2893 struct wpa_global *global = wpa_s->global;
2895 if (os_strcmp(ifname, "*") == 0) {
2896 struct wpa_supplicant *prev;
2897 wpa_s = global->ifaces;
2900 wpa_s = wpa_s->next;
2901 wpas_p2p_disconnect(prev);
2906 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
2907 if (os_strcmp(wpa_s->ifname, ifname) == 0)
2911 return wpas_p2p_disconnect(wpa_s);
2915 static void wpas_p2p_init_go_params(struct wpa_supplicant *wpa_s,
2916 struct p2p_go_neg_results *params,
2922 os_memset(params, 0, sizeof(*params));
2923 params->role_go = 1;
2925 wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on forced "
2926 "frequency %d MHz", freq);
2927 params->freq = freq;
2928 } else if (wpa_s->conf->p2p_oper_reg_class == 81 &&
2929 wpa_s->conf->p2p_oper_channel >= 1 &&
2930 wpa_s->conf->p2p_oper_channel <= 11) {
2931 params->freq = 2407 + 5 * wpa_s->conf->p2p_oper_channel;
2932 wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on configured "
2933 "frequency %d MHz", params->freq);
2934 } else if (wpa_s->conf->p2p_oper_reg_class == 115 ||
2935 wpa_s->conf->p2p_oper_reg_class == 124) {
2936 params->freq = 5000 + 5 * wpa_s->conf->p2p_oper_channel;
2937 wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on configured "
2938 "frequency %d MHz", params->freq);
2939 } else if (wpa_s->conf->p2p_oper_channel == 0 &&
2940 wpa_s->best_overall_freq > 0 &&
2941 p2p_supported_freq(wpa_s->global->p2p,
2942 wpa_s->best_overall_freq)) {
2943 params->freq = wpa_s->best_overall_freq;
2944 wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on best overall "
2945 "channel %d MHz", params->freq);
2946 } else if (wpa_s->conf->p2p_oper_channel == 0 &&
2947 wpa_s->best_24_freq > 0 &&
2948 p2p_supported_freq(wpa_s->global->p2p,
2949 wpa_s->best_24_freq)) {
2950 params->freq = wpa_s->best_24_freq;
2951 wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on best 2.4 GHz "
2952 "channel %d MHz", params->freq);
2953 } else if (wpa_s->conf->p2p_oper_channel == 0 &&
2954 wpa_s->best_5_freq > 0 &&
2955 p2p_supported_freq(wpa_s->global->p2p,
2956 wpa_s->best_5_freq)) {
2957 params->freq = wpa_s->best_5_freq;
2958 wpa_printf(MSG_DEBUG, "P2P: Set GO freq based on best 5 GHz "
2959 "channel %d MHz", params->freq);
2961 params->freq = 2412;
2962 wpa_printf(MSG_DEBUG, "P2P: Set GO freq %d MHz (no preference "
2963 "known)", params->freq);
2966 if (wpa_s->current_ssid && wpa_drv_get_bssid(wpa_s, bssid) == 0 &&
2967 wpa_s->assoc_freq && !freq) {
2968 wpa_printf(MSG_DEBUG, "P2P: Force GO on the channel we are "
2970 params->freq = wpa_s->assoc_freq;
2973 res = wpa_drv_shared_freq(wpa_s);
2974 if (res > 0 && !freq) {
2975 wpa_printf(MSG_DEBUG, "P2P: Force GO on the channel we are "
2976 "already using on a shared interface");
2982 static struct wpa_supplicant *
2983 wpas_p2p_get_group_iface(struct wpa_supplicant *wpa_s, int addr_allocated,
2986 struct wpa_supplicant *group_wpa_s;
2988 if (!wpas_p2p_create_iface(wpa_s))
2991 if (wpas_p2p_add_group_interface(wpa_s, go ? WPA_IF_P2P_GO :
2992 WPA_IF_P2P_CLIENT) < 0)
2994 group_wpa_s = wpas_p2p_init_group_interface(wpa_s, go);
2995 if (group_wpa_s == NULL) {
2996 wpas_p2p_remove_pending_group_interface(wpa_s);
3005 * wpas_p2p_group_add - Add a new P2P group with local end as Group Owner
3006 * @wpa_s: Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
3007 * @persistent_group: Whether to create a persistent group
3008 * @freq: Frequency for the group or 0 to indicate no hardcoding
3009 * Returns: 0 on success, -1 on failure
3011 * This function creates a new P2P group with the local end as the Group Owner,
3012 * i.e., without using Group Owner Negotiation.
3014 int wpas_p2p_group_add(struct wpa_supplicant *wpa_s, int persistent_group,
3017 struct p2p_go_neg_results params;
3020 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
3023 /* Make sure we are not running find during connection establishment */
3024 wpa_printf(MSG_DEBUG, "P2P: Stop any on-going P2P FIND");
3025 wpas_p2p_stop_find(wpa_s);
3028 wpa_printf(MSG_DEBUG, "P2P: Request to start GO on 2.4 GHz "
3030 if (wpa_s->best_24_freq > 0 &&
3031 p2p_supported_freq(wpa_s->global->p2p,
3032 wpa_s->best_24_freq)) {
3033 freq = wpa_s->best_24_freq;
3034 wpa_printf(MSG_DEBUG, "P2P: Use best 2.4 GHz band "
3035 "channel: %d MHz", freq);
3037 os_get_random((u8 *) &r, sizeof(r));
3038 freq = 2412 + (r % 3) * 25;
3039 wpa_printf(MSG_DEBUG, "P2P: Use random 2.4 GHz band "
3040 "channel: %d MHz", freq);
3045 wpa_printf(MSG_DEBUG, "P2P: Request to start GO on 5 GHz "
3047 if (wpa_s->best_5_freq > 0 &&
3048 p2p_supported_freq(wpa_s->global->p2p,
3049 wpa_s->best_5_freq)) {
3050 freq = wpa_s->best_5_freq;
3051 wpa_printf(MSG_DEBUG, "P2P: Use best 5 GHz band "
3052 "channel: %d MHz", freq);
3054 os_get_random((u8 *) &r, sizeof(r));
3055 freq = 5180 + (r % 4) * 20;
3056 if (!p2p_supported_freq(wpa_s->global->p2p, freq)) {
3057 wpa_printf(MSG_DEBUG, "P2P: Could not select "
3058 "5 GHz channel for P2P group");
3061 wpa_printf(MSG_DEBUG, "P2P: Use random 5 GHz band "
3062 "channel: %d MHz", freq);
3066 if (freq > 0 && !p2p_supported_freq(wpa_s->global->p2p, freq)) {
3067 wpa_printf(MSG_DEBUG, "P2P: The forced channel for GO "
3068 "(%u MHz) is not supported for P2P uses",
3073 wpas_p2p_init_go_params(wpa_s, ¶ms, freq);
3074 p2p_go_params(wpa_s->global->p2p, ¶ms);
3075 params.persistent_group = persistent_group;
3077 wpa_s = wpas_p2p_get_group_iface(wpa_s, 0, 1);
3080 wpas_start_wps_go(wpa_s, ¶ms, 0);
3086 static int wpas_start_p2p_client(struct wpa_supplicant *wpa_s,
3087 struct wpa_ssid *params, int addr_allocated)
3089 struct wpa_ssid *ssid;
3091 wpa_s = wpas_p2p_get_group_iface(wpa_s, addr_allocated, 0);
3095 wpa_supplicant_ap_deinit(wpa_s);
3097 ssid = wpa_config_add_network(wpa_s->conf);
3100 wpa_config_set_network_defaults(ssid);
3101 ssid->temporary = 1;
3102 ssid->proto = WPA_PROTO_RSN;
3103 ssid->pairwise_cipher = WPA_CIPHER_CCMP;
3104 ssid->group_cipher = WPA_CIPHER_CCMP;
3105 ssid->key_mgmt = WPA_KEY_MGMT_PSK;
3106 ssid->ssid = os_malloc(params->ssid_len);
3107 if (ssid->ssid == NULL) {
3108 wpa_config_remove_network(wpa_s->conf, ssid->id);
3111 os_memcpy(ssid->ssid, params->ssid, params->ssid_len);
3112 ssid->ssid_len = params->ssid_len;
3113 ssid->p2p_group = 1;
3114 ssid->export_keys = 1;
3115 if (params->psk_set) {
3116 os_memcpy(ssid->psk, params->psk, 32);
3119 if (params->passphrase)
3120 ssid->passphrase = os_strdup(params->passphrase);
3122 wpa_supplicant_select_network(wpa_s, ssid);
3124 wpa_s->show_group_started = 1;
3130 int wpas_p2p_group_add_persistent(struct wpa_supplicant *wpa_s,
3131 struct wpa_ssid *ssid, int addr_allocated,
3134 struct p2p_go_neg_results params;
3137 if (ssid->disabled != 2 || ssid->ssid == NULL)
3140 if (wpas_get_p2p_group(wpa_s, ssid->ssid, ssid->ssid_len, &go) &&
3141 go == (ssid->mode == WPAS_MODE_P2P_GO)) {
3142 wpa_printf(MSG_DEBUG, "P2P: Requested persistent group is "
3147 /* Make sure we are not running find during connection establishment */
3148 wpas_p2p_stop_find(wpa_s);
3150 if (ssid->mode == WPAS_MODE_INFRA)
3151 return wpas_start_p2p_client(wpa_s, ssid, addr_allocated);
3153 if (ssid->mode != WPAS_MODE_P2P_GO)
3156 wpas_p2p_init_go_params(wpa_s, ¶ms, freq);
3159 if (ssid->passphrase == NULL ||
3160 os_strlen(ssid->passphrase) >= sizeof(params.passphrase)) {
3161 wpa_printf(MSG_DEBUG, "P2P: Invalid passphrase in persistent "
3165 os_strlcpy(params.passphrase, ssid->passphrase,
3166 sizeof(params.passphrase));
3167 os_memcpy(params.ssid, ssid->ssid, ssid->ssid_len);
3168 params.ssid_len = ssid->ssid_len;
3169 params.persistent_group = 1;
3171 wpa_s = wpas_p2p_get_group_iface(wpa_s, addr_allocated, 1);
3175 wpas_start_wps_go(wpa_s, ¶ms, 0);
3181 static void wpas_p2p_ie_update(void *ctx, struct wpabuf *beacon_ies,
3182 struct wpabuf *proberesp_ies)
3184 struct wpa_supplicant *wpa_s = ctx;
3185 if (wpa_s->ap_iface) {
3186 struct hostapd_data *hapd = wpa_s->ap_iface->bss[0];
3187 if (!(hapd->conf->p2p & P2P_GROUP_OWNER)) {
3188 wpabuf_free(beacon_ies);
3189 wpabuf_free(proberesp_ies);
3193 wpabuf_free(hapd->p2p_beacon_ie);
3194 hapd->p2p_beacon_ie = beacon_ies;
3196 wpabuf_free(hapd->p2p_probe_resp_ie);
3197 hapd->p2p_probe_resp_ie = proberesp_ies;
3199 wpabuf_free(beacon_ies);
3200 wpabuf_free(proberesp_ies);
3202 wpa_supplicant_ap_update_beacon(wpa_s);
3206 static void wpas_p2p_idle_update(void *ctx, int idle)
3208 struct wpa_supplicant *wpa_s = ctx;
3209 if (!wpa_s->ap_iface)
3211 wpa_printf(MSG_DEBUG, "P2P: GO - group %sidle", idle ? "" : "not ");
3213 wpas_p2p_set_group_idle_timeout(wpa_s);
3215 eloop_cancel_timeout(wpas_p2p_group_idle_timeout, wpa_s, NULL);
3219 struct p2p_group * wpas_p2p_group_init(struct wpa_supplicant *wpa_s,
3220 int persistent_group,
3221 int group_formation)
3223 struct p2p_group *group;
3224 struct p2p_group_config *cfg;
3226 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT)
3228 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
3231 cfg = os_zalloc(sizeof(*cfg));
3235 if (persistent_group && wpa_s->conf->persistent_reconnect)
3236 cfg->persistent_group = 2;
3237 else if (persistent_group)
3238 cfg->persistent_group = 1;
3239 os_memcpy(cfg->interface_addr, wpa_s->own_addr, ETH_ALEN);
3240 if (wpa_s->max_stations &&
3241 wpa_s->max_stations < wpa_s->conf->max_num_sta)
3242 cfg->max_clients = wpa_s->max_stations;
3244 cfg->max_clients = wpa_s->conf->max_num_sta;
3245 cfg->cb_ctx = wpa_s;
3246 cfg->ie_update = wpas_p2p_ie_update;
3247 cfg->idle_update = wpas_p2p_idle_update;
3249 group = p2p_group_init(wpa_s->global->p2p, cfg);
3252 if (!group_formation)
3253 p2p_group_notif_formation_done(group);
3254 wpa_s->p2p_group = group;
3259 void wpas_p2p_wps_success(struct wpa_supplicant *wpa_s, const u8 *peer_addr,
3262 if (!wpa_s->p2p_in_provisioning) {
3263 wpa_printf(MSG_DEBUG, "P2P: Ignore WPS success event - P2P "
3264 "provisioning not in progress");
3268 eloop_cancel_timeout(wpas_p2p_group_formation_timeout, wpa_s->parent,
3270 if (wpa_s->global->p2p)
3271 p2p_wps_success_cb(wpa_s->global->p2p, peer_addr);
3272 else if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT)
3273 wpa_drv_wps_success_cb(wpa_s, peer_addr);
3274 wpas_group_formation_completed(wpa_s, 1);
3278 void wpas_p2p_wps_failed(struct wpa_supplicant *wpa_s,
3279 struct wps_event_fail *fail)
3281 if (!wpa_s->p2p_in_provisioning) {
3282 wpa_printf(MSG_DEBUG, "P2P: Ignore WPS fail event - P2P "
3283 "provisioning not in progress");
3286 wpas_notify_p2p_wps_failed(wpa_s, fail);
3290 int wpas_p2p_prov_disc(struct wpa_supplicant *wpa_s, const u8 *peer_addr,
3291 const char *config_method)
3295 if (os_strcmp(config_method, "display") == 0)
3296 config_methods = WPS_CONFIG_DISPLAY;
3297 else if (os_strcmp(config_method, "keypad") == 0)
3298 config_methods = WPS_CONFIG_KEYPAD;
3299 else if (os_strcmp(config_method, "pbc") == 0 ||
3300 os_strcmp(config_method, "pushbutton") == 0)
3301 config_methods = WPS_CONFIG_PUSHBUTTON;
3305 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT) {
3306 return wpa_drv_p2p_prov_disc_req(wpa_s, peer_addr,
3310 if (wpa_s->global->p2p == NULL || wpa_s->global->p2p_disabled)
3313 return p2p_prov_disc_req(wpa_s->global->p2p, peer_addr,
3318 int wpas_p2p_scan_result_text(const u8 *ies, size_t ies_len, char *buf,
3321 return p2p_scan_result_text(ies, ies_len, buf, end);
3325 static void wpas_p2p_clear_pending_action_tx(struct wpa_supplicant *wpa_s)
3327 if (!wpa_s->pending_action_tx)
3330 wpa_printf(MSG_DEBUG, "P2P: Drop pending Action TX due to new "
3331 "operation request");
3332 wpabuf_free(wpa_s->pending_action_tx);
3333 wpa_s->pending_action_tx = NULL;
3337 int wpas_p2p_find(struct wpa_supplicant *wpa_s, unsigned int timeout,
3338 enum p2p_discovery_type type,
3339 unsigned int num_req_dev_types, const u8 *req_dev_types)
3341 wpas_p2p_clear_pending_action_tx(wpa_s);
3342 wpa_s->p2p_long_listen = 0;
3344 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT)
3345 return wpa_drv_p2p_find(wpa_s, timeout, type);
3347 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
3350 return p2p_find(wpa_s->global->p2p, timeout, type,
3351 num_req_dev_types, req_dev_types);
3355 void wpas_p2p_stop_find(struct wpa_supplicant *wpa_s)
3357 wpas_p2p_clear_pending_action_tx(wpa_s);
3358 wpa_s->p2p_long_listen = 0;
3359 eloop_cancel_timeout(wpas_p2p_long_listen_timeout, wpa_s, NULL);
3360 eloop_cancel_timeout(wpas_p2p_join_scan, wpa_s, NULL);
3361 wpa_s->p2p_cb_on_scan_complete = 0;
3363 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT) {
3364 wpa_drv_p2p_stop_find(wpa_s);
3368 if (wpa_s->global->p2p)
3369 p2p_stop_find(wpa_s->global->p2p);
3371 wpas_p2p_remove_pending_group_interface(wpa_s);
3375 static void wpas_p2p_long_listen_timeout(void *eloop_ctx, void *timeout_ctx)
3377 struct wpa_supplicant *wpa_s = eloop_ctx;
3378 wpa_s->p2p_long_listen = 0;
3382 int wpas_p2p_listen(struct wpa_supplicant *wpa_s, unsigned int timeout)
3386 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
3389 wpas_p2p_clear_pending_action_tx(wpa_s);
3393 * This is a request for unlimited Listen state. However, at
3394 * least for now, this is mapped to a Listen state for one
3399 eloop_cancel_timeout(wpas_p2p_long_listen_timeout, wpa_s, NULL);
3400 wpa_s->p2p_long_listen = 0;
3403 * Stop previous find/listen operation to avoid trying to request a new
3404 * remain-on-channel operation while the driver is still running the
3407 if (wpa_s->global->p2p)
3408 p2p_stop_find(wpa_s->global->p2p);
3410 res = wpas_p2p_listen_start(wpa_s, timeout * 1000);
3411 if (res == 0 && timeout * 1000 > wpa_s->max_remain_on_chan) {
3412 wpa_s->p2p_long_listen = timeout * 1000;
3413 eloop_register_timeout(timeout, 0,
3414 wpas_p2p_long_listen_timeout,
3422 int wpas_p2p_assoc_req_ie(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
3423 u8 *buf, size_t len, int p2p_group)
3425 struct wpabuf *p2p_ie;
3428 if (wpa_s->global->p2p_disabled)
3430 if (wpa_s->global->p2p == NULL)
3435 p2p_ie = wpa_bss_get_vendor_ie_multi(bss, P2P_IE_VENDOR_TYPE);
3436 ret = p2p_assoc_req_ie(wpa_s->global->p2p, bss->bssid, buf, len,
3438 wpabuf_free(p2p_ie);
3444 int wpas_p2p_probe_req_rx(struct wpa_supplicant *wpa_s, const u8 *addr,
3445 const u8 *dst, const u8 *bssid,
3446 const u8 *ie, size_t ie_len)
3448 if (wpa_s->global->p2p_disabled)
3450 if (wpa_s->global->p2p == NULL)
3453 return p2p_probe_req_rx(wpa_s->global->p2p, addr, dst, bssid,
3458 void wpas_p2p_rx_action(struct wpa_supplicant *wpa_s, const u8 *da,
3459 const u8 *sa, const u8 *bssid,
3460 u8 category, const u8 *data, size_t len, int freq)
3462 if (wpa_s->global->p2p_disabled)
3464 if (wpa_s->global->p2p == NULL)
3467 p2p_rx_action(wpa_s->global->p2p, da, sa, bssid, category, data, len,
3472 void wpas_p2p_scan_ie(struct wpa_supplicant *wpa_s, struct wpabuf *ies)
3474 if (wpa_s->global->p2p_disabled)
3476 if (wpa_s->global->p2p == NULL)
3479 p2p_scan_ie(wpa_s->global->p2p, ies);
3483 void wpas_p2p_group_deinit(struct wpa_supplicant *wpa_s)
3485 p2p_group_deinit(wpa_s->p2p_group);
3486 wpa_s->p2p_group = NULL;
3488 wpa_s->ap_configured_cb = NULL;
3489 wpa_s->ap_configured_cb_ctx = NULL;
3490 wpa_s->ap_configured_cb_data = NULL;
3491 wpa_s->connect_without_scan = NULL;
3495 int wpas_p2p_reject(struct wpa_supplicant *wpa_s, const u8 *addr)
3497 wpa_s->p2p_long_listen = 0;
3499 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT)
3500 return wpa_drv_p2p_reject(wpa_s, addr);
3502 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
3505 return p2p_reject(wpa_s->global->p2p, addr);
3509 /* Invite to reinvoke a persistent group */
3510 int wpas_p2p_invite(struct wpa_supplicant *wpa_s, const u8 *peer_addr,
3511 struct wpa_ssid *ssid, const u8 *go_dev_addr)
3513 enum p2p_invite_role role;
3516 if (ssid->mode == WPAS_MODE_P2P_GO) {
3517 role = P2P_INVITE_ROLE_GO;
3518 if (peer_addr == NULL) {
3519 wpa_printf(MSG_DEBUG, "P2P: Missing peer "
3520 "address in invitation command");
3523 if (wpas_p2p_create_iface(wpa_s)) {
3524 if (wpas_p2p_add_group_interface(wpa_s,
3525 WPA_IF_P2P_GO) < 0) {
3526 wpa_printf(MSG_ERROR, "P2P: Failed to "
3527 "allocate a new interface for the "
3531 bssid = wpa_s->pending_interface_addr;
3533 bssid = wpa_s->own_addr;
3535 role = P2P_INVITE_ROLE_CLIENT;
3536 peer_addr = ssid->bssid;
3538 wpa_s->pending_invite_ssid_id = ssid->id;
3540 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT)
3541 return wpa_drv_p2p_invite(wpa_s, peer_addr, role, bssid,
3542 ssid->ssid, ssid->ssid_len,
3545 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
3548 return p2p_invite(wpa_s->global->p2p, peer_addr, role, bssid,
3549 ssid->ssid, ssid->ssid_len, 0, go_dev_addr, 1);
3553 /* Invite to join an active group */
3554 int wpas_p2p_invite_group(struct wpa_supplicant *wpa_s, const char *ifname,
3555 const u8 *peer_addr, const u8 *go_dev_addr)
3557 struct wpa_global *global = wpa_s->global;
3558 enum p2p_invite_role role;
3560 struct wpa_ssid *ssid;
3562 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
3563 if (os_strcmp(wpa_s->ifname, ifname) == 0)
3566 if (wpa_s == NULL) {
3567 wpa_printf(MSG_DEBUG, "P2P: Interface '%s' not found", ifname);
3571 ssid = wpa_s->current_ssid;
3573 wpa_printf(MSG_DEBUG, "P2P: No current SSID to use for "
3578 if (ssid->mode == WPAS_MODE_P2P_GO) {
3579 role = P2P_INVITE_ROLE_ACTIVE_GO;
3580 bssid = wpa_s->own_addr;
3581 if (go_dev_addr == NULL)
3582 go_dev_addr = wpa_s->parent->own_addr;
3584 role = P2P_INVITE_ROLE_CLIENT;
3585 if (wpa_s->wpa_state < WPA_ASSOCIATED) {
3586 wpa_printf(MSG_DEBUG, "P2P: Not associated - cannot "
3587 "invite to current group");
3590 bssid = wpa_s->bssid;
3591 if (go_dev_addr == NULL &&
3592 !is_zero_ether_addr(wpa_s->go_dev_addr))
3593 go_dev_addr = wpa_s->go_dev_addr;
3595 wpa_s->parent->pending_invite_ssid_id = -1;
3597 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT)
3598 return wpa_drv_p2p_invite(wpa_s, peer_addr, role, bssid,
3599 ssid->ssid, ssid->ssid_len,
3602 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
3605 return p2p_invite(wpa_s->global->p2p, peer_addr, role, bssid,
3606 ssid->ssid, ssid->ssid_len, wpa_s->assoc_freq,
3611 void wpas_p2p_completed(struct wpa_supplicant *wpa_s)
3613 struct wpa_ssid *ssid = wpa_s->current_ssid;
3614 const char *ssid_txt;
3615 u8 go_dev_addr[ETH_ALEN];
3616 int network_id = -1;
3620 if (!wpa_s->show_group_started || !ssid)
3623 wpa_s->show_group_started = 0;
3625 ssid_txt = wpa_ssid_txt(ssid->ssid, ssid->ssid_len);
3626 os_memset(go_dev_addr, 0, ETH_ALEN);
3627 if (ssid->bssid_set)
3628 os_memcpy(go_dev_addr, ssid->bssid, ETH_ALEN);
3629 persistent = wpas_p2p_persistent_group(wpa_s, go_dev_addr, ssid->ssid,
3631 os_memcpy(wpa_s->go_dev_addr, go_dev_addr, ETH_ALEN);
3633 if (wpa_s->global->p2p_group_formation == wpa_s)
3634 wpa_s->global->p2p_group_formation = NULL;
3636 freq = wpa_s->current_bss ? wpa_s->current_bss->freq :
3637 (int) wpa_s->assoc_freq;
3638 if (ssid->passphrase == NULL && ssid->psk_set) {
3640 wpa_snprintf_hex(psk, sizeof(psk), ssid->psk, 32);
3641 wpa_msg(wpa_s->parent, MSG_INFO, P2P_EVENT_GROUP_STARTED
3642 "%s client ssid=\"%s\" freq=%d psk=%s go_dev_addr="
3644 wpa_s->ifname, ssid_txt, freq, psk,
3645 MAC2STR(go_dev_addr),
3646 persistent ? " [PERSISTENT]" : "");
3648 wpa_msg(wpa_s->parent, MSG_INFO, P2P_EVENT_GROUP_STARTED
3649 "%s client ssid=\"%s\" freq=%d passphrase=\"%s\" "
3650 "go_dev_addr=" MACSTR "%s",
3651 wpa_s->ifname, ssid_txt, freq,
3652 ssid->passphrase ? ssid->passphrase : "",
3653 MAC2STR(go_dev_addr),
3654 persistent ? " [PERSISTENT]" : "");
3658 network_id = wpas_p2p_store_persistent_group(wpa_s->parent,
3661 network_id = ssid->id;
3662 wpas_notify_p2p_group_started(wpa_s, ssid, network_id, 1);
3666 int wpas_p2p_presence_req(struct wpa_supplicant *wpa_s, u32 duration1,
3667 u32 interval1, u32 duration2, u32 interval2)
3669 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT)
3671 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
3674 if (wpa_s->wpa_state < WPA_ASSOCIATED ||
3675 wpa_s->current_ssid == NULL ||
3676 wpa_s->current_ssid->mode != WPAS_MODE_INFRA)
3679 return p2p_presence_req(wpa_s->global->p2p, wpa_s->bssid,
3680 wpa_s->own_addr, wpa_s->assoc_freq,
3681 duration1, interval1, duration2, interval2);
3685 int wpas_p2p_ext_listen(struct wpa_supplicant *wpa_s, unsigned int period,
3686 unsigned int interval)
3688 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT)
3691 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
3694 return p2p_ext_listen(wpa_s->global->p2p, period, interval);
3698 static void wpas_p2p_group_idle_timeout(void *eloop_ctx, void *timeout_ctx)
3700 struct wpa_supplicant *wpa_s = eloop_ctx;
3702 if (wpa_s->conf->p2p_group_idle == 0) {
3703 wpa_printf(MSG_DEBUG, "P2P: Ignore group idle timeout - "
3708 wpa_printf(MSG_DEBUG, "P2P: Group idle timeout reached - terminate "
3710 wpa_s->removal_reason = P2P_GROUP_REMOVAL_IDLE_TIMEOUT;
3711 wpas_p2p_group_delete(wpa_s);
3715 static void wpas_p2p_set_group_idle_timeout(struct wpa_supplicant *wpa_s)
3717 eloop_cancel_timeout(wpas_p2p_group_idle_timeout, wpa_s, NULL);
3718 if (wpa_s->conf->p2p_group_idle == 0)
3721 if (wpa_s->current_ssid == NULL || !wpa_s->current_ssid->p2p_group)
3724 wpa_printf(MSG_DEBUG, "P2P: Set P2P group idle timeout to %u seconds",
3725 wpa_s->conf->p2p_group_idle);
3726 eloop_register_timeout(wpa_s->conf->p2p_group_idle, 0,
3727 wpas_p2p_group_idle_timeout, wpa_s, NULL);
3731 void wpas_p2p_deauth_notif(struct wpa_supplicant *wpa_s, const u8 *bssid,
3732 u16 reason_code, const u8 *ie, size_t ie_len)
3734 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
3736 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT)
3739 p2p_deauth_notif(wpa_s->global->p2p, bssid, reason_code, ie, ie_len);
3743 void wpas_p2p_disassoc_notif(struct wpa_supplicant *wpa_s, const u8 *bssid,
3744 u16 reason_code, const u8 *ie, size_t ie_len)
3746 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
3748 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT)
3751 p2p_disassoc_notif(wpa_s->global->p2p, bssid, reason_code, ie, ie_len);
3755 void wpas_p2p_update_config(struct wpa_supplicant *wpa_s)
3757 struct p2p_data *p2p = wpa_s->global->p2p;
3762 if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_CAPABLE))
3765 if (wpa_s->conf->changed_parameters & CFG_CHANGED_DEVICE_NAME)
3766 p2p_set_dev_name(p2p, wpa_s->conf->device_name);
3768 if (wpa_s->conf->changed_parameters & CFG_CHANGED_DEVICE_TYPE)
3769 p2p_set_pri_dev_type(p2p, wpa_s->conf->device_type);
3772 (wpa_s->conf->changed_parameters & CFG_CHANGED_CONFIG_METHODS))
3773 p2p_set_config_methods(p2p, wpa_s->wps->config_methods);
3775 if (wpa_s->wps && (wpa_s->conf->changed_parameters & CFG_CHANGED_UUID))
3776 p2p_set_uuid(p2p, wpa_s->wps->uuid);
3778 if (wpa_s->conf->changed_parameters & CFG_CHANGED_WPS_STRING) {
3779 p2p_set_manufacturer(p2p, wpa_s->conf->manufacturer);
3780 p2p_set_model_name(p2p, wpa_s->conf->model_name);
3781 p2p_set_model_number(p2p, wpa_s->conf->model_number);
3782 p2p_set_serial_number(p2p, wpa_s->conf->serial_number);
3785 if (wpa_s->conf->changed_parameters & CFG_CHANGED_SEC_DEVICE_TYPE)
3786 p2p_set_sec_dev_types(p2p,
3787 (void *) wpa_s->conf->sec_device_type,
3788 wpa_s->conf->num_sec_device_types);
3790 if (wpa_s->conf->changed_parameters & CFG_CHANGED_VENDOR_EXTENSION) {
3792 p2p_remove_wps_vendor_extensions(p2p);
3793 for (i = 0; i < MAX_WPS_VENDOR_EXT; i++) {
3794 if (wpa_s->conf->wps_vendor_ext[i] == NULL)
3796 p2p_add_wps_vendor_extension(
3797 p2p, wpa_s->conf->wps_vendor_ext[i]);
3801 if ((wpa_s->conf->changed_parameters & CFG_CHANGED_COUNTRY) &&
3802 wpa_s->conf->country[0] && wpa_s->conf->country[1]) {
3804 country[0] = wpa_s->conf->country[0];
3805 country[1] = wpa_s->conf->country[1];
3807 p2p_set_country(p2p, country);
3810 if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_SSID_POSTFIX) {
3811 p2p_set_ssid_postfix(p2p, (u8 *) wpa_s->conf->p2p_ssid_postfix,
3812 wpa_s->conf->p2p_ssid_postfix ?
3813 os_strlen(wpa_s->conf->p2p_ssid_postfix) :
3817 if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_INTRA_BSS)
3818 p2p_set_intra_bss_dist(p2p, wpa_s->conf->p2p_intra_bss);
3820 if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_LISTEN_CHANNEL) {
3821 u8 reg_class, channel;
3824 if (wpa_s->conf->p2p_listen_reg_class &&
3825 wpa_s->conf->p2p_listen_channel) {
3826 reg_class = wpa_s->conf->p2p_listen_reg_class;
3827 channel = wpa_s->conf->p2p_listen_channel;
3831 * Pick one of the social channels randomly as the
3834 os_get_random((u8 *) &r, sizeof(r));
3835 channel = 1 + (r % 3) * 5;
3837 ret = p2p_set_listen_channel(p2p, reg_class, channel);
3839 wpa_printf(MSG_ERROR, "P2P: Own listen channel update "
3842 if (wpa_s->conf->changed_parameters & CFG_CHANGED_P2P_OPER_CHANNEL) {
3843 u8 op_reg_class, op_channel, cfg_op_channel;
3846 if (wpa_s->conf->p2p_oper_reg_class &&
3847 wpa_s->conf->p2p_oper_channel) {
3848 op_reg_class = wpa_s->conf->p2p_oper_reg_class;
3849 op_channel = wpa_s->conf->p2p_oper_channel;
3854 * Use random operation channel from (1, 6, 11)
3855 *if no other preference is indicated.
3857 os_get_random((u8 *) &r, sizeof(r));
3858 op_channel = 1 + (r % 3) * 5;
3861 ret = p2p_set_oper_channel(p2p, op_reg_class, op_channel,
3864 wpa_printf(MSG_ERROR, "P2P: Own oper channel update "
3870 int wpas_p2p_set_noa(struct wpa_supplicant *wpa_s, u8 count, int start,
3873 if (!wpa_s->ap_iface)
3875 return hostapd_p2p_set_noa(wpa_s->ap_iface->bss[0], count, start,
3880 int wpas_p2p_set_cross_connect(struct wpa_supplicant *wpa_s, int enabled)
3882 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
3884 if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT)
3887 wpa_s->global->cross_connection = enabled;
3888 p2p_set_cross_connect(wpa_s->global->p2p, enabled);
3891 struct wpa_supplicant *iface;
3893 for (iface = wpa_s->global->ifaces; iface; iface = iface->next)
3895 if (iface->cross_connect_enabled == 0)
3898 iface->cross_connect_enabled = 0;
3899 iface->cross_connect_in_use = 0;
3900 wpa_msg(iface->parent, MSG_INFO,
3901 P2P_EVENT_CROSS_CONNECT_DISABLE "%s %s",
3902 iface->ifname, iface->cross_connect_uplink);
3910 static void wpas_p2p_enable_cross_connect(struct wpa_supplicant *uplink)
3912 struct wpa_supplicant *iface;
3914 if (!uplink->global->cross_connection)
3917 for (iface = uplink->global->ifaces; iface; iface = iface->next) {
3918 if (!iface->cross_connect_enabled)
3920 if (os_strcmp(uplink->ifname, iface->cross_connect_uplink) !=
3923 if (iface->ap_iface == NULL)
3925 if (iface->cross_connect_in_use)
3928 iface->cross_connect_in_use = 1;
3929 wpa_msg(iface->parent, MSG_INFO,
3930 P2P_EVENT_CROSS_CONNECT_ENABLE "%s %s",
3931 iface->ifname, iface->cross_connect_uplink);
3936 static void wpas_p2p_disable_cross_connect(struct wpa_supplicant *uplink)
3938 struct wpa_supplicant *iface;
3940 for (iface = uplink->global->ifaces; iface; iface = iface->next) {
3941 if (!iface->cross_connect_enabled)
3943 if (os_strcmp(uplink->ifname, iface->cross_connect_uplink) !=
3946 if (!iface->cross_connect_in_use)
3949 wpa_msg(iface->parent, MSG_INFO,
3950 P2P_EVENT_CROSS_CONNECT_DISABLE "%s %s",
3951 iface->ifname, iface->cross_connect_uplink);
3952 iface->cross_connect_in_use = 0;
3957 void wpas_p2p_notif_connected(struct wpa_supplicant *wpa_s)
3959 if (wpa_s->ap_iface || wpa_s->current_ssid == NULL ||
3960 wpa_s->current_ssid->mode != WPAS_MODE_INFRA ||
3961 wpa_s->cross_connect_disallowed)
3962 wpas_p2p_disable_cross_connect(wpa_s);
3964 wpas_p2p_enable_cross_connect(wpa_s);
3965 if (!wpa_s->ap_iface)
3966 eloop_cancel_timeout(wpas_p2p_group_idle_timeout, wpa_s, NULL);
3970 void wpas_p2p_notif_disconnected(struct wpa_supplicant *wpa_s)
3972 wpas_p2p_disable_cross_connect(wpa_s);
3973 if (!wpa_s->ap_iface)
3974 wpas_p2p_set_group_idle_timeout(wpa_s);
3978 static void wpas_p2p_cross_connect_setup(struct wpa_supplicant *wpa_s)
3980 struct wpa_supplicant *iface;
3982 if (!wpa_s->global->cross_connection)
3985 for (iface = wpa_s->global->ifaces; iface; iface = iface->next) {
3988 if (iface->drv_flags &
3989 WPA_DRIVER_FLAGS_P2P_DEDICATED_INTERFACE)
3991 if (iface->drv_flags & WPA_DRIVER_FLAGS_P2P_CAPABLE)
3994 wpa_s->cross_connect_enabled = 1;
3995 os_strlcpy(wpa_s->cross_connect_uplink, iface->ifname,
3996 sizeof(wpa_s->cross_connect_uplink));
3997 wpa_printf(MSG_DEBUG, "P2P: Enable cross connection from "
3998 "%s to %s whenever uplink is available",
3999 wpa_s->ifname, wpa_s->cross_connect_uplink);
4001 if (iface->ap_iface || iface->current_ssid == NULL ||
4002 iface->current_ssid->mode != WPAS_MODE_INFRA ||
4003 iface->cross_connect_disallowed ||
4004 iface->wpa_state != WPA_COMPLETED)
4007 wpa_s->cross_connect_in_use = 1;
4008 wpa_msg(wpa_s->parent, MSG_INFO,
4009 P2P_EVENT_CROSS_CONNECT_ENABLE "%s %s",
4010 wpa_s->ifname, wpa_s->cross_connect_uplink);
4016 int wpas_p2p_notif_pbc_overlap(struct wpa_supplicant *wpa_s)
4018 if (wpa_s->p2p_group_interface != P2P_GROUP_INTERFACE_CLIENT &&
4019 !wpa_s->p2p_in_provisioning)
4020 return 0; /* not P2P client operation */
4022 wpa_printf(MSG_DEBUG, "P2P: Terminate connection due to WPS PBC "
4024 if (wpa_s != wpa_s->parent)
4025 wpa_msg_ctrl(wpa_s->parent, MSG_INFO, WPS_EVENT_OVERLAP);
4027 if (wpa_s->global->p2p)
4028 p2p_group_formation_failed(wpa_s->global->p2p);
4030 eloop_cancel_timeout(wpas_p2p_group_formation_timeout,
4031 wpa_s->parent, NULL);
4033 wpas_group_formation_completed(wpa_s, 0);
4038 void wpas_p2p_update_channel_list(struct wpa_supplicant *wpa_s)
4040 struct p2p_channels chan;
4042 if (wpa_s->global == NULL || wpa_s->global->p2p == NULL)
4045 os_memset(&chan, 0, sizeof(chan));
4046 if (wpas_p2p_setup_channels(wpa_s, &chan)) {
4047 wpa_printf(MSG_ERROR, "P2P: Failed to update supported "
4052 p2p_update_channel_list(wpa_s->global->p2p, &chan);
4056 int wpas_p2p_cancel(struct wpa_supplicant *wpa_s)
4058 struct wpa_global *global = wpa_s->global;
4062 if (global->p2p == NULL)
4065 wpa_printf(MSG_DEBUG, "P2P: Request to cancel group formation");
4067 if (wpa_s->pending_interface_name[0] &&
4068 !is_zero_ether_addr(wpa_s->pending_interface_addr))
4071 peer = p2p_get_go_neg_peer(global->p2p);
4073 wpa_printf(MSG_DEBUG, "P2P: Unauthorize pending GO Neg peer "
4074 MACSTR, MAC2STR(peer));
4075 p2p_unauthorize(global->p2p, peer);
4078 wpas_p2p_stop_find(wpa_s);
4080 for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
4081 if (wpa_s == global->p2p_group_formation &&
4082 (wpa_s->p2p_in_provisioning ||
4083 wpa_s->parent->pending_interface_type ==
4084 WPA_IF_P2P_CLIENT)) {
4085 wpa_printf(MSG_DEBUG, "P2P: Interface %s in group "
4086 "formation found - cancelling",
4089 eloop_cancel_timeout(wpas_p2p_group_formation_timeout,
4090 wpa_s->parent, NULL);
4091 wpas_p2p_group_delete(wpa_s);
4097 wpa_printf(MSG_DEBUG, "P2P: No ongoing group formation found");
4105 void wpas_p2p_interface_unavailable(struct wpa_supplicant *wpa_s)
4107 if (wpa_s->current_ssid == NULL || !wpa_s->current_ssid->p2p_group)
4110 wpa_printf(MSG_DEBUG, "P2P: Remove group due to driver resource not "
4111 "being available anymore");
4112 wpa_s->removal_reason = P2P_GROUP_REMOVAL_UNAVAILABLE;
4113 wpas_p2p_group_delete(wpa_s);
4117 void wpas_p2p_update_best_channels(struct wpa_supplicant *wpa_s,
4118 int freq_24, int freq_5, int freq_overall)
4120 struct p2p_data *p2p = wpa_s->global->p2p;
4121 if (p2p == NULL || (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT))
4123 p2p_set_best_channels(p2p, freq_24, freq_5, freq_overall);
4127 int wpas_p2p_unauthorize(struct wpa_supplicant *wpa_s, const char *addr)
4130 struct p2p_data *p2p = wpa_s->global->p2p;
4132 if (p2p == NULL || (wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_MGMT))
4135 if (hwaddr_aton(addr, peer))
4138 return p2p_unauthorize(p2p, peer);
4143 * wpas_p2p_disconnect - Disconnect from a P2P Group
4144 * @wpa_s: Pointer to wpa_supplicant data
4145 * Returns: 0 on success, -1 on failure
4147 * This can be used to disconnect from a group in which the local end is a P2P
4148 * Client or to end a P2P Group in case the local end is the Group Owner. If a
4149 * virtual network interface was created for this group, that interface will be
4150 * removed. Otherwise, only the configured P2P group network will be removed
4151 * from the interface.
4153 int wpas_p2p_disconnect(struct wpa_supplicant *wpa_s)
4159 wpa_s->removal_reason = P2P_GROUP_REMOVAL_REQUESTED;
4160 wpas_p2p_group_delete(wpa_s);
4166 int wpas_p2p_in_progress(struct wpa_supplicant *wpa_s)
4168 if (wpa_s->global->p2p_disabled || wpa_s->global->p2p == NULL)
4171 return p2p_in_progress(wpa_s->global->p2p);