Patchwork [v2,10/10] wpa_supplicant: init a dedicated P2P device interface

login
register
mail settings
Submitter dvdspndl@gmail.com
Date March 17, 2013, 8:57 p.m.
Message ID <1363553840-7844-11-git-send-email-dvdspndl@gmail.com>
Download mbox | patch
Permalink /patch/228329/
State Changes Requested
Headers show

Comments

dvdspndl@gmail.com - March 17, 2013, 8:57 p.m.
From: David Spinadel <david.spinadel@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@intel.com>
---
 src/p2p/p2p.c                   |    5 ++++
 src/p2p/p2p.h                   |    6 ++++
 wpa_supplicant/p2p_supplicant.c |   60 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 71 insertions(+)

Patch

diff --git a/src/p2p/p2p.c b/src/p2p/p2p.c
index 4418bb3..77c8f7d 100644
--- a/src/p2p/p2p.c
+++ b/src/p2p/p2p.c
@@ -4428,3 +4428,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 d2fa68c..b5d55eb 100644
--- a/src/p2p/p2p.h
+++ b/src/p2p/p2p.h
@@ -1799,5 +1799,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 518e8e4..a6f7614 100644
--- a/wpa_supplicant/p2p_supplicant.c
+++ b/wpa_supplicant/p2p_supplicant.c
@@ -2917,6 +2917,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
@@ -3075,6 +3126,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;
 }
 
@@ -3108,6 +3165,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);
 }