[PATCH 10/10] wpa_supplicant: init a dedicated P2P device interface

dvdspndl at gmail.com dvdspndl
Mon Feb 18 12:30:36 PST 2013


From: David Spinadel <david.spinadel at intel.com>

Try to init a dedicated P2P device if supported in wpas_init_p2p
and deinit it in wpas_deinit_p2p.

Signed-off-by: David Spinadel <david.spinadel at intel.com>
---
 src/p2p/p2p.c                   |    5 ++++
 src/p2p/p2p.h                   |    6 ++++
 wpa_supplicant/p2p_supplicant.c |   60 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 71 insertions(+)

diff --git a/src/p2p/p2p.c b/src/p2p/p2p.c
index 43f8673..02463cc 100644
--- a/src/p2p/p2p.c
+++ b/src/p2p/p2p.c
@@ -4328,3 +4328,8 @@ int p2p_set_disc_int(struct p2p_data *p2p, int min_disc_int, int max_disc_int,
 
 	return 0;
 }
+
+void p2p_set_dev_addr(struct p2p_data *p2p, u8 *addr)
+{
+	os_memcpy(p2p->cfg->dev_addr, addr, ETH_ALEN);
+}
diff --git a/src/p2p/p2p.h b/src/p2p/p2p.h
index 2d8b2c2..c152341 100644
--- a/src/p2p/p2p.h
+++ b/src/p2p/p2p.h
@@ -1779,5 +1779,11 @@ struct wpabuf * wifi_display_encaps(struct wpabuf *subelems);
  */
 int p2p_set_disc_int(struct p2p_data *p2p, int min_disc_int, int max_disc_int,
 		     int max_disc_tu);
+/**
+ * p2p_set_dev_addr - Set P2P device address
+ * @p2p: P2P nodule context from p2p_init()
+ * @addr: P2P device address to assign to p2p device.
+ */
+void p2p_set_dev_addr(struct p2p_data *p2p, u8 *addr);
 
 #endif /* P2P_H */
diff --git a/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant/p2p_supplicant.c
index 89ebe08..3e19783 100644
--- a/wpa_supplicant/p2p_supplicant.c
+++ b/wpa_supplicant/p2p_supplicant.c
@@ -2801,6 +2801,57 @@ static int wpas_go_connected(void *ctx, const u8 *dev_addr)
 	return 0;
 }
 
+/**
+ * wpas_p2p_dev_interface_init - Initialize P2P device interface to be used
+ * for all device related operations
+ * @wpa_s:  Pointer to wpa_supplicant data from wpa_supplicant_add_iface()
+ * @p2p: P2P module context from p2p_init()
+ * Returns: 0 on success, -1 on failure
+ */
+static int wpas_p2p_dev_interface_init(struct wpa_supplicant *wpa_s,
+				       struct p2p_data *p2p)
+{
+	char *ifname;
+	char p2p_dev_ifname[IFNAMSIZ];
+	int ifname_len;
+	u8 addr[ETH_ALEN];
+
+	if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE))
+		return 0;
+
+	if (!p2p)
+		return -1;
+
+	wpa_printf(MSG_DEBUG, "P2P: Initialize P2P device Interface");
+
+	ifname = wpa_s->ifname;
+	/**
+	 * If the name p2p-dev-$(wpa_s->ifname) is greater than IFNAMESIZ
+	 * Assume the last 4 char of the wpa_s->ifname as unique
+	 */
+	ifname_len = os_strlen(ifname);
+	if (ifname_len > (IFNAMSIZ - 9))
+		ifname += (ifname_len - 5);
+
+	os_snprintf(p2p_dev_ifname, IFNAMSIZ, "p2p-dev-%s", ifname);
+	wpa_printf(MSG_DEBUG, "Creating a P2P device interface %s for %s",
+			p2p_dev_ifname, wpa_s->ifname);
+
+	wpa_s->p2p_drv_priv = wpa_drv_init_p2p_dev(wpa_s, p2p_dev_ifname, addr);
+	if (!wpa_s->p2p_drv_priv) {
+		wpa_printf(MSG_ERROR, "P2P: Failed to create a new P2P "
+				"device interface");
+		return -1;
+	}
+
+	/* override p2p device address. */
+	os_memcpy(wpa_s->global->p2p_dev_addr, addr, ETH_ALEN);
+	p2p_set_dev_addr(p2p, addr);
+
+	wpa_printf(MSG_INFO, "P2P: Device initialization success");
+
+	return 0;
+}
 
 /**
  * wpas_p2p_init - Initialize P2P module for %wpa_supplicant
@@ -2959,6 +3010,12 @@ int wpas_p2p_init(struct wpa_global *global, struct wpa_supplicant *wpa_s)
 			global->p2p, wpa_s->conf->wps_vendor_ext[i]);
 	}
 
+	/* Try to initialize P2P device interface */
+	if (wpas_p2p_dev_interface_init(wpa_s, global->p2p)) {
+		p2p_deinit(global->p2p);
+		return -1;
+	}
+
 	return 0;
 }
 
@@ -2992,6 +3049,9 @@ void wpas_p2p_deinit(struct wpa_supplicant *wpa_s)
 
 	/* TODO: remove group interface from the driver if this wpa_s instance
 	 * is on top of a P2P group interface */
+
+	if (wpa_s->p2p_drv_priv)
+		wpa_drv_deinit_p2p_dev(wpa_s);
 }
 
 
-- 
1.7.10.msysgit.1




More information about the Hostap mailing list