Patchwork [1/1] STA: Expose command for creating and deleting virutal interface

login
register
mail settings
Submitter Jithu Jance
Date May 22, 2014, 9:30 a.m.
Message ID <68a29a8577a086ae916d9a254b5caf8e962c94f5.1400750960.git.jithu@broadcom.com>
Download mbox | patch
Permalink /patch/351403/
State New
Headers show

Comments

Jithu Jance - May 22, 2014, 9:30 a.m.
This would help to dynamically create an interface for
AP (mode=2) or secondary STA.

Signed-off-by: Jithu Jance <jithu@broadcom.com>
---
 wpa_supplicant/ctrl_iface.c |   36 +++++++++++++++++++++++++++++
 wpa_supplicant/wpa_cli.c    |   53 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 89 insertions(+)

--
1.7.9.5



- Jithu Jance

Patch

diff --git a/wpa_supplicant/ctrl_iface.c b/wpa_supplicant/ctrl_iface.c
index 9f01271..281f459 100644
--- a/wpa_supplicant/ctrl_iface.c
+++ b/wpa_supplicant/ctrl_iface.c
@@ -5875,6 +5875,38 @@  static int wpas_ctrl_radio_work(struct wpa_supplicant *wpa_s, char *cmd,
 	return -1;
 }

+static int wpa_supplicant_iface_create(struct wpa_supplicant *wpa_s, char *cmd)
+{
+	char *ifname;
+	u8 mac_addr[6];
+
+	wpa_dbg(wpa_s, MSG_DEBUG, "Interface Create");
+
+	ifname = cmd;
+	if (ifname == NULL) {
+		return -1;
+	}
+
+	if (wpa_drv_if_add(wpa_s, WPA_IF_STATION, ifname, NULL, NULL, NULL,
+			mac_addr, NULL) != 0)
+		return -1;
+
+	wpa_dbg(wpa_s, MSG_DEBUG, "Virtual Interface Created"
+			"with macaddr:"MACSTR, MAC2STR(mac_addr));
+	return 0;
+}
+
+static int wpa_supplicant_iface_del(struct wpa_supplicant *wpa_s, char *cmd)
+{
+	char *ifname;
+
+	wpa_dbg(wpa_s, MSG_DEBUG, "Interface Delete");
+
+	ifname = cmd;
+
+	return wpa_drv_if_remove(wpa_s, WPA_IF_STATION, ifname);
+}
+

 void wpas_ctrl_radio_work_flush(struct wpa_supplicant *wpa_s)
 {
@@ -6696,6 +6728,10 @@  char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
 		if (wpas_ctrl_iface_driver_event(wpa_s, buf + 13) < 0)
 			reply_len = -1;
 #endif /* CONFIG_TESTING_OPTIONS */
+	} else if (os_strncmp(buf, "INTERFACE_CREATE ", 17) == 0) {
+		reply_len = wpa_supplicant_iface_create(wpa_s, buf + 17);
+	} else if (os_strncmp(buf, "INTERFACE_DEL ", 14) == 0) {
+		reply_len = wpa_supplicant_iface_del(wpa_s, buf + 14);
 	} else {
 		os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
 		reply_len = 16;
diff --git a/wpa_supplicant/wpa_cli.c b/wpa_supplicant/wpa_cli.c
index b3812ca..d61eb95 100644
--- a/wpa_supplicant/wpa_cli.c
+++ b/wpa_supplicant/wpa_cli.c
@@ -1593,6 +1593,53 @@  static int wpa_cli_cmd_terminate(struct wpa_ctrl *ctrl, int argc,
 	return wpa_ctrl_command(ctrl, "TERMINATE");
 }

+static int wpa_cli_cmd_interface_create(struct wpa_ctrl *ctrl, int argc,
+				     char *argv[])
+{
+	char cmd[256];
+	int res;
+
+	printf("Inside cmd_interface_create");
+
+	if (argc < 1) {
+		printf("Invalid INTERFACE_CREATE command: needs at least one "
+		       "argument (interface name)\n"
+		       "All arguments: ifname confname driver ctrl_interface "
+		       "driver_param bridge_name\n");
+		return -1;
+	}
+
+	res = os_snprintf(cmd, sizeof(cmd),
+			  "INTERFACE_CREATE %s", argv[0]);
+
+	if (res < 0 || (size_t) res >= sizeof(cmd))
+		return -1;
+	cmd[sizeof(cmd) - 1] = '\0';
+	return wpa_ctrl_command(ctrl, cmd);
+}
+
+static int wpa_cli_cmd_interface_del(struct wpa_ctrl *ctrl, int argc,
+				     char *argv[])
+{
+	char cmd[256];
+	int res;
+
+	if (argc < 1) {
+		printf("Invalid INTERFACE_DEL command: needs at least one "
+		       "argument (interface name)\n"
+		       "All arguments: ifname confname driver ctrl_interface "
+		       "driver_param bridge_name\n");
+		return -1;
+	}
+
+	res = os_snprintf(cmd, sizeof(cmd),
+			  "INTERFACE_DEL %s", argv[0]);
+
+	if (res < 0 || (size_t) res >= sizeof(cmd))
+		return -1;
+	cmd[sizeof(cmd) - 1] = '\0';
+	return wpa_ctrl_command(ctrl, cmd);
+}

 static int wpa_cli_cmd_interface_add(struct wpa_ctrl *ctrl, int argc,
 				     char *argv[])
@@ -2637,6 +2684,12 @@  static struct wpa_cli_cmd wpa_cli_commands[] = {
 	{ "terminate", wpa_cli_cmd_terminate, NULL,
 	  cli_cmd_flag_none,
 	  "= terminate wpa_supplicant" },
+	{ "interface_create", wpa_cli_cmd_interface_create, NULL,
+	  cli_cmd_flag_none,
+	  "= Create a new interface" },
+	{ "interface_del", wpa_cli_cmd_interface_del, NULL,
+	  cli_cmd_flag_none,
+	  "= Delete an existing interface" },
 	{ "interface_add", wpa_cli_cmd_interface_add, NULL,
 	  cli_cmd_flag_none,
 	  "<ifname> <confname> <driver> <ctrl_interface> <driver_param>\n"