[PATCH 06/20] wpa_s: p2p: create P2P Device interface if supported
Arend van Spriel
arend
Thu May 16 06:28:21 PDT 2013
If the capability flag of the driver indicates a dedicated
P2P Device is supported, a P2P Device interface is created
in wpas_p2p_init().
Signed-hostap: Arend van Spriel <arend at broadcom.com>
---
wpa_supplicant/p2p_supplicant.c | 34 ++++++++++++++++++++++++++++++++++
wpa_supplicant/p2p_supplicant.h | 1 +
wpa_supplicant/wpa_supplicant.c | 8 +++++++-
wpa_supplicant/wpa_supplicant_i.h | 7 +++++++
4 files changed, 49 insertions(+), 1 deletion(-)
diff --git a/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant/p2p_supplicant.c
index 37aa314..d87f824 100644
--- a/wpa_supplicant/p2p_supplicant.c
+++ b/wpa_supplicant/p2p_supplicant.c
@@ -2921,6 +2921,40 @@ static int wpas_go_connected(void *ctx, const u8 *dev_addr)
return 0;
}
+int wpas_p2p_add_p2pdev_interface(struct wpa_supplicant *wpa_s)
+{
+ struct wpa_interface iface;
+ struct wpa_supplicant *p2pdev_wpa_s;
+ char ifname[100];
+ char force_name[100];
+ int ret;
+
+ os_snprintf(ifname, sizeof(ifname), "p2p-dev-%s", wpa_s->ifname);
+ force_name[0] = '\0';
+ wpa_s->pending_interface_type = WPA_IF_P2P_DEVICE;
+ ret = wpa_drv_if_add(wpa_s, WPA_IF_P2P_DEVICE, ifname, NULL, NULL,
+ force_name, wpa_s->pending_interface_addr, NULL);
+ if (ret < 0) {
+ wpa_printf(MSG_DEBUG, "P2P: failed to create P2P Device interface");
+ return ret;
+ }
+ os_strlcpy(wpa_s->pending_interface_name, ifname,
+ sizeof(wpa_s->pending_interface_name));
+ os_memset(&iface, 0, sizeof(iface));
+ iface.p2p_mgmt = 1;
+ iface.ifname = wpa_s->pending_interface_name;
+ iface.driver = wpa_s->driver->name;
+ iface.ctrl_interface = wpa_s->conf->ctrl_interface;
+ iface.driver_param = wpa_s->conf->driver_param;
+ p2pdev_wpa_s = wpa_supplicant_add_iface(wpa_s->global, &iface);
+ if (!p2pdev_wpa_s) {
+ wpa_printf(MSG_DEBUG, "P2P: failed to add P2P Device interface");
+ return -1;
+ }
+
+ wpa_s->pending_interface_name[0] = '\0';
+ return 0;
+}
/**
* wpas_p2p_init - Initialize P2P module for %wpa_supplicant
diff --git a/wpa_supplicant/p2p_supplicant.h b/wpa_supplicant/p2p_supplicant.h
index 0a7212c..2157cae 100644
--- a/wpa_supplicant/p2p_supplicant.h
+++ b/wpa_supplicant/p2p_supplicant.h
@@ -18,6 +18,7 @@ struct p2p_channels;
int wpas_p2p_init(struct wpa_global *global, struct wpa_supplicant *wpa_s);
void wpas_p2p_deinit(struct wpa_supplicant *wpa_s);
void wpas_p2p_deinit_global(struct wpa_global *global);
+int wpas_p2p_add_p2pdev_interface(struct wpa_supplicant *wpa_s);
int wpas_p2p_connect(struct wpa_supplicant *wpa_s, const u8 *peer_addr,
const char *pin, enum p2p_wps_method wps_method,
int persistent_group, int auto_join, int join,
diff --git a/wpa_supplicant/wpa_supplicant.c b/wpa_supplicant/wpa_supplicant.c
index 2d05247..7c3b180 100644
--- a/wpa_supplicant/wpa_supplicant.c
+++ b/wpa_supplicant/wpa_supplicant.c
@@ -2996,7 +2996,13 @@ next_driver:
}
#ifdef CONFIG_P2P
- if (wpas_p2p_init(wpa_s->global, wpa_s) < 0) {
+ if (iface->p2p_mgmt == 0 && wpa_s->global->p2p == NULL &&
+ (wpa_s->drv_flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) {
+ if (wpas_p2p_add_p2pdev_interface(wpa_s) < 0) {
+ wpa_msg(wpa_s, MSG_ERROR, "Failed to create P2P Device");
+ return -1;
+ }
+ } else if (wpas_p2p_init(wpa_s->global, wpa_s) < 0) {
wpa_msg(wpa_s, MSG_ERROR, "Failed to init P2P");
return -1;
}
diff --git a/wpa_supplicant/wpa_supplicant_i.h b/wpa_supplicant/wpa_supplicant_i.h
index 7559a75..02e4bc6 100644
--- a/wpa_supplicant/wpa_supplicant_i.h
+++ b/wpa_supplicant/wpa_supplicant_i.h
@@ -104,6 +104,13 @@ struct wpa_interface {
* receiving of EAPOL frames from an additional interface.
*/
const char *bridge_ifname;
+
+ /**
+ * p2p_mgmt - interface used for P2P management
+ *
+ * Indicates whether wpas_p2p_init() must be called for this interface.
+ */
+ int p2p_mgmt;
};
/**
--
1.7.10.4
More information about the Hostap
mailing list