From patchwork Thu May 22 09:30:41 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jithu Jance X-Patchwork-Id: 351403 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from maxx.maxx.shmoo.com (maxx.shmoo.com [205.134.188.171]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 58A1B140086 for ; Thu, 22 May 2014 19:31:15 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 5C0CD9C136; Thu, 22 May 2014 05:31:10 -0400 (EDT) X-Virus-Scanned: amavisd-new at maxx.shmoo.com Received: from maxx.maxx.shmoo.com ([127.0.0.1]) by localhost (maxx.shmoo.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 6pVcuXrJesqq; Thu, 22 May 2014 05:31:10 -0400 (EDT) Received: from maxx.shmoo.com (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 69C2E9D255; Thu, 22 May 2014 05:31:04 -0400 (EDT) X-Original-To: mailman-post+hostap@maxx.shmoo.com Delivered-To: mailman-post+hostap@maxx.shmoo.com Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 96E449D255 for ; Thu, 22 May 2014 05:31:01 -0400 (EDT) X-Virus-Scanned: amavisd-new at maxx.shmoo.com Received: from maxx.maxx.shmoo.com ([127.0.0.1]) by localhost (maxx.shmoo.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id nG--ASNbutOH for ; Thu, 22 May 2014 05:30:54 -0400 (EDT) Received: from mail-gw1-out.broadcom.com (mail-gw1-out.broadcom.com [216.31.210.62]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 99C569D253 for ; Thu, 22 May 2014 05:30:54 -0400 (EDT) X-IronPort-AV: E=Sophos;i="4.98,886,1392192000"; d="scan'208";a="30974693" Received: from irvexchcas07.broadcom.com (HELO IRVEXCHCAS07.corp.ad.broadcom.com) ([10.9.208.55]) by mail-gw1-out.broadcom.com with ESMTP; 22 May 2014 02:33:51 -0700 Received: from IRVEXCHSMTP3.corp.ad.broadcom.com (10.9.207.53) by IRVEXCHCAS07.corp.ad.broadcom.com (10.9.208.55) with Microsoft SMTP Server (TLS) id 14.3.174.1; Thu, 22 May 2014 02:30:52 -0700 Received: from mail-irva-13.broadcom.com (10.10.10.20) by IRVEXCHSMTP3.corp.ad.broadcom.com (10.9.207.53) with Microsoft SMTP Server id 14.3.174.1; Thu, 22 May 2014 02:30:52 -0700 Received: from jithu?broadcom.com (lbblr-jithu01.ban.broadcom.com [10.132.24.37]) by mail-irva-13.broadcom.com (Postfix) with ESMTP id D0EE89FA37 for ; Thu, 22 May 2014 02:30:42 -0700 (PDT) Date: Thu, 22 May 2014 15:00:41 +0530 From: Jithu Jance To: Subject: [PATCH 1/1] STA: Expose command for creating and deleting virutal interface Message-ID: <68a29a8577a086ae916d9a254b5caf8e962c94f5.1400750960.git.jithu@broadcom.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-BeenThere: hostap@lists.shmoo.com X-Mailman-Version: 2.1.11 Precedence: list List-Id: HostAP Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: hostap-bounces@lists.shmoo.com Errors-To: hostap-bounces@lists.shmoo.com This would help to dynamically create an interface for AP (mode=2) or secondary STA. Signed-off-by: Jithu Jance --- wpa_supplicant/ctrl_iface.c | 36 +++++++++++++++++++++++++++++ wpa_supplicant/wpa_cli.c | 53 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) -- 1.7.9.5 - Jithu Jance 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, " \n"