[PATCH] P2P: Add IFNAME=iface command option for interface redirection

Dmitry Shmidt dimitrysh
Tue May 14 15:50:10 PDT 2013


Change-Id: I8b7d42b52897eee014457ff1ee8c3d12d14e1b20
Signed-off-by: Dmitry Shmidt <dimitrysh at google.com>
---
 wpa_supplicant/ctrl_iface.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/wpa_supplicant/ctrl_iface.c b/wpa_supplicant/ctrl_iface.c
index a7d5965..9ef9ae6 100644
--- a/wpa_supplicant/ctrl_iface.c
+++ b/wpa_supplicant/ctrl_iface.c
@@ -5188,6 +5188,41 @@ static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s)
 }
 
 
+/*
+ * Expected command format: CMD IFNAME=ifname [rest of command]
+ */
+struct wpa_supplicant *wpa_supplicant_redir_iface(struct wpa_supplicant *wpa_s,
+						  char *buf)
+{
+	struct wpa_supplicant *wpa_r = wpa_s;
+#ifdef CONFIG_P2P
+	char *ifname, *ifend;
+
+	ifname = os_strstr(buf, "IFNAME=");
+	if (ifname != NULL) {
+		ifend = os_strchr(ifname + 7, ' ');
+		if (ifend != NULL)
+			*ifend++ = '\0';
+		else
+			*(ifname - 1) = '\0';
+		for (wpa_r=wpa_s->global->ifaces; wpa_r; wpa_r=wpa_r->next) {
+			if (os_strcmp(wpa_r->ifname, ifname + 7) == 0)
+				break;
+		}
+		if (wpa_r == NULL) {
+			wpa_printf(MSG_ERROR, "P2P: %s doesn't exist",
+				   ifname + 7);
+			wpa_r = wpa_s;
+		}
+		if (ifend != NULL)
+			os_memmove(ifname, ifend, os_strlen(ifend) + 1);
+		wpa_printf(MSG_DEBUG, "%s %s", wpa_r->ifname, buf);
+	}
+#endif
+	return wpa_r;
+}
+
+
 char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
 					 char *buf, size_t *resp_len)
 {
@@ -5196,6 +5231,8 @@ char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
 	int ctrl_rsp = 0;
 	int reply_len;
 
+	wpa_s = wpa_supplicant_redir_iface(wpa_s, buf);
+
 	if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 ||
 	    os_strncmp(buf, "SET_NETWORK ", 12) == 0 ||
 	    os_strncmp(buf, "WPS_NFC_TAG_READ", 16) == 0 ||
-- 
1.8.2.1




More information about the Hostap mailing list