From patchwork Mon Jul 14 05:19:19 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bob Copeland X-Patchwork-Id: 369492 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 2772914008F for ; Mon, 14 Jul 2014 15:25:20 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 596659D323; Mon, 14 Jul 2014 01:24:32 -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 Zjk9cMURNOk8; Mon, 14 Jul 2014 01:24:32 -0400 (EDT) Received: from maxx.shmoo.com (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 1087B17C06E; Mon, 14 Jul 2014 01:21:56 -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 BD9BF17C06E for ; Mon, 14 Jul 2014 01:21:54 -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 kw7-7+eZS4yV for ; Mon, 14 Jul 2014 01:21:48 -0400 (EDT) Received: from mail-ie0-f172.google.com (mail-ie0-f172.google.com [209.85.223.172]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (not verified)) by maxx.maxx.shmoo.com (Postfix) with ESMTPS id BED719D323 for ; Mon, 14 Jul 2014 01:21:14 -0400 (EDT) Received: by mail-ie0-f172.google.com with SMTP id lx4so803888iec.17 for ; Sun, 13 Jul 2014 22:21:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=zlYElJyaWjBCs9HCQANrwVxGnN7VZM3a8f9ss1Un5RA=; b=DmdtviKr85LdZtCZ2UpchxncYHc5mWgK4HkOjVK89Xviwbcyz/XJxcoBhKXZ2U7oi4 gN9PhumsOOFRA/sx1g6WsvQDQiE9IR/dG/6y35pBX3Dxmz9XFMBGf8xmGFK4qKmi4VJp crr8xPW1PDKBceaLQyvYdCyLjWZvrDrFnhvLFAdnMtKrSrUlaInGeC9VL7Nwp4qAjGX0 TwTM1MW3iPyvHlX7bvDnxGuD80kXrWyM4j++ExsGCC2vfnlP3Whd2Wc5rewWHaJbMhwj zN1L19WphGqLZxfC2/T0XC74wE+jfwZJ9TZiOcgkAa4DS96HOsZk7sJ/8huCWz7/0j2c 7pgw== X-Gm-Message-State: ALoCoQl7OlfiCZhvvvwNg/nfj6qZkO4774/J7C4WtPy/Nn2iRj30v306jAavWQ6e7JRzAZ06Zwn4 X-Received: by 10.51.16.197 with SMTP id fy5mr21617255igd.47.1405315274350; Sun, 13 Jul 2014 22:21:14 -0700 (PDT) Received: from hash ([2001:470:1d:6db:230:48ff:fe9d:9c89]) by mx.google.com with ESMTPSA id t2sm21709570igs.3.2014.07.13.22.21.08 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sun, 13 Jul 2014 22:21:09 -0700 (PDT) Received: from glass.local ([192.168.1.51] helo=glass.lan) by hash with esmtp (Exim 4.80) (envelope-from ) id 1X6YhG-0005TR-BU; Mon, 14 Jul 2014 01:21:06 -0400 Received: from bob by glass.lan with local (Exim 4.82_1-5b7a7c0-XX) (envelope-from ) id 1X6YhH-0002VB-38; Mon, 14 Jul 2014 01:21:07 -0400 From: Bob Copeland To: hostap@lists.shmoo.com Subject: [PATCH/RFC 14/18] wpa_s, ctrl_iface: Add mesh_group_{add,remove} Date: Mon, 14 Jul 2014 01:19:19 -0400 Message-Id: <1405315163-9492-15-git-send-email-me@bobcopeland.com> X-Mailer: git-send-email 2.0.0.rc2 In-Reply-To: <1405315163-9492-1-git-send-email-me@bobcopeland.com> References: <1405315163-9492-1-git-send-email-me@bobcopeland.com> Cc: devel@lists.open80211s.org, Javier Lopez 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: , MIME-Version: 1.0 Sender: hostap-bounces@lists.shmoo.com Errors-To: hostap-bounces@lists.shmoo.com From: Javier Lopez Parse MESH_GROUP_ADD/REMOVE commands on ctrl interface and call wpa_supplicant routines. These commands are used to start or join a mesh network. The mesh id is given in the configuration file, therefore there is no need to scan before joining a mesh network. We reuse the connect_without_scan construct used by p2p for that same purpose. Signed-off-by: Javier Cardona Signed-hostap: Javier Lopez --- wpa_supplicant/ctrl_iface.c | 74 +++++++++++++++++++++++++++++++++++++++++ wpa_supplicant/wpa_cli.c | 21 ++++++++++++ wpa_supplicant/wpa_supplicant.c | 55 +++++++++++++++++++++++++++--- 3 files changed, 146 insertions(+), 4 deletions(-) diff --git a/wpa_supplicant/ctrl_iface.c b/wpa_supplicant/ctrl_iface.c index 874e0c8..130449a 100644 --- a/wpa_supplicant/ctrl_iface.c +++ b/wpa_supplicant/ctrl_iface.c @@ -2331,6 +2331,71 @@ static int wpa_supplicant_ctrl_iface_scan_results( return pos - buf; } +#ifdef CONFIG_MESH +static int wpa_supplicant_ctrl_iface_mesh_group_add( + struct wpa_supplicant *wpa_s, char *cmd) +{ + int id; + struct wpa_ssid *ssid; + + id = atoi(cmd); + wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_ADD id=%d", id); + + ssid = wpa_config_get_network(wpa_s->conf, id); + if (ssid == NULL) { + wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find " + "network id=%d", id); + return -1; + } + if (ssid->mode != 5) { + wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use " + "MESH_GROUP_ADD on a non mesh network"); + return -1; + } + + /* + * TODO: If necessary write our own group_add function, + * for now we can reuse select_network + */ + wpa_supplicant_select_network(wpa_s, ssid); + return 0; +} + +static int wpa_supplicant_ctrl_iface_mesh_group_remove( + struct wpa_supplicant *wpa_s, char *cmd) +{ + if (!cmd) { + wpa_printf(MSG_ERROR, "CTRL_IFACE: MESH_GROUP_REMOVE ifname " + "cannot be empty"); + return -1; + } + + /* + * TODO: Support a multiple mesh and other iface type combinations + */ + if (os_strcmp(cmd, wpa_s->ifname) != 0) { + wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_REMOVE unknown " + "interface name: %s", cmd); + return -1; + } + + wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s", cmd); + + wpa_s->reassociate = 0; + wpa_s->disconnected = 1; + wpa_supplicant_cancel_sched_scan(wpa_s); + wpa_supplicant_cancel_scan(wpa_s); + + /* + * TODO: If necessary write our own group_remove function, + * for now we can reuse deauthenticate + */ + wpa_supplicant_deauthenticate(wpa_s, + WLAN_REASON_DEAUTH_LEAVING); + + return 0; +} +#endif /* CONFIG_MESH */ static int wpa_supplicant_ctrl_iface_select_network( struct wpa_supplicant *wpa_s, char *cmd) @@ -6692,6 +6757,15 @@ char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s, if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9)) reply_len = -1; #endif /* CONFIG_IBSS_RSN */ +#ifdef CONFIG_MESH + } else if (os_strncmp(buf, "MESH_GROUP_ADD ", 15) == 0) { + if (wpa_supplicant_ctrl_iface_mesh_group_add(wpa_s, buf + 15)) + reply_len = -1; + } else if (os_strncmp(buf, "MESH_GROUP_REMOVE ", 18) == 0) { + if (wpa_supplicant_ctrl_iface_mesh_group_remove(wpa_s, + buf + 18)) + reply_len = -1; +#endif /* CONFIG_MESH */ #ifdef CONFIG_P2P } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) { if (p2p_ctrl_find(wpa_s, buf + 9)) diff --git a/wpa_supplicant/wpa_cli.c b/wpa_supplicant/wpa_cli.c index 8811d6f..1848266 100644 --- a/wpa_supplicant/wpa_cli.c +++ b/wpa_supplicant/wpa_cli.c @@ -1743,6 +1743,19 @@ static int wpa_cli_cmd_roam(struct wpa_ctrl *ctrl, int argc, char *argv[]) return wpa_cli_cmd(ctrl, "ROAM", 1, argc, argv); } +#ifdef CONFIG_MESH +static int wpa_cli_cmd_mesh_group_add(struct wpa_ctrl *ctrl, int argc, + char *argv[]) +{ + return wpa_cli_cmd(ctrl, "MESH_GROUP_ADD", 1, argc, argv); +} + +static int wpa_cli_cmd_mesh_group_remove(struct wpa_ctrl *ctrl, int argc, + char *argv[]) +{ + return wpa_cli_cmd(ctrl, "MESH_GROUP_REMOVE", 1, argc, argv); +} +#endif /* CONFIG_MESH */ #ifdef CONFIG_P2P @@ -2770,6 +2783,14 @@ static struct wpa_cli_cmd wpa_cli_commands[] = { { "roam", wpa_cli_cmd_roam, wpa_cli_complete_bss, cli_cmd_flag_none, " = roam to the specified BSS" }, +#ifdef CONFIG_MESH + { "mesh_group_add", wpa_cli_cmd_mesh_group_add, NULL, + cli_cmd_flag_none, + " = join a mesh network (disable others)" }, + { "mesh_group_remove", wpa_cli_cmd_mesh_group_remove, NULL, + cli_cmd_flag_none, + " = Remove Mesh group interface" }, +#endif /* CONFIG_MESH */ #ifdef CONFIG_P2P { "p2p_find", wpa_cli_cmd_p2p_find, wpa_cli_complete_p2p_find, cli_cmd_flag_none, diff --git a/wpa_supplicant/wpa_supplicant.c b/wpa_supplicant/wpa_supplicant.c index 9414e8f..02b4bcf 100644 --- a/wpa_supplicant/wpa_supplicant.c +++ b/wpa_supplicant/wpa_supplicant.c @@ -52,6 +52,7 @@ #include "hs20_supplicant.h" #include "wnm_sta.h" #include "wpas_kay.h" +#include "mesh.h" const char *wpa_supplicant_version = "wpa_supplicant v" VERSION_STR "\n" @@ -1421,6 +1422,31 @@ void wpa_supplicant_associate(struct wpa_supplicant *wpa_s, return; } + if (ssid->mode == WPAS_MODE_MESH) { +#ifdef CONFIG_MESH + if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_MESH)) { + wpa_msg(wpa_s, MSG_INFO, "Driver does not support " + "mesh mode"); + return; + } + if (bss) + ssid->frequency = bss->freq; + if (wpa_supplicant_join_mesh(wpa_s, ssid) < 0) { + wpa_msg(wpa_s, MSG_ERROR, "couldn't join mesh"); + return; + } + wpa_s->current_bss = bss; + wpa_msg_ctrl(wpa_s, MSG_INFO, MESH_GROUP_STARTED + "ssid=\"%s\" id=%d", + wpa_ssid_txt(ssid->ssid, ssid->ssid_len), + ssid->id); +#else /* CONFIG_MESH */ + wpa_msg(wpa_s, MSG_ERROR, "mesh mode support not included in " + "the build"); +#endif /* CONFIG_MESH */ + return; + } + #ifdef CONFIG_TDLS if (bss) wpa_tdls_ap_ies(wpa_s->wpa, (const u8 *) (bss + 1), @@ -1764,9 +1790,10 @@ static void wpas_start_assoc_cb(struct wpa_radio_work *work, int deinit) params.fixed_bssid = 1; } - if (ssid->mode == WPAS_MODE_IBSS && ssid->frequency > 0 && - params.freq == 0) - params.freq = ssid->frequency; /* Initial channel for IBSS */ + /* Initial frequency for IBSS/mesh */ + if ((ssid->mode == WPAS_MODE_IBSS || ssid->mode == WPAS_MODE_MESH) && + ssid->frequency > 0 && params.freq == 0) + params.freq = ssid->frequency; if (ssid->mode == WPAS_MODE_IBSS) { if (ssid->beacon_int) @@ -1994,6 +2021,15 @@ void wpa_supplicant_deauthenticate(struct wpa_supplicant *wpa_s, wpa_tdls_teardown_peers(wpa_s->wpa); #endif /* CONFIG_TDLS */ +#ifdef CONFIG_MESH + if (wpa_s->ifmsh) { + + wpa_msg_ctrl(wpa_s, MSG_INFO, MESH_GROUP_REMOVED + "%s", wpa_s->ifname); + wpa_supplicant_leave_mesh(wpa_s); + } +#endif /* CONFIG_MESH */ + if (addr) { wpa_drv_deauthenticate(wpa_s, addr, reason_code); os_memset(&event, 0, sizeof(event)); @@ -2159,8 +2195,12 @@ void wpa_supplicant_select_network(struct wpa_supplicant *wpa_s, if (ssid) { wpa_s->current_ssid = ssid; eapol_sm_notify_config(wpa_s->eapol, NULL, NULL); + wpa_s->connect_without_scan = + (ssid->mode == WPAS_MODE_MESH) ? ssid : NULL; + } else { + wpa_s->connect_without_scan = NULL; } - wpa_s->connect_without_scan = NULL; + wpa_s->disconnected = 0; wpa_s->reassociate = 1; @@ -3812,6 +3852,13 @@ static void wpa_supplicant_deinit_iface(struct wpa_supplicant *wpa_s, wpa_s->ctrl_iface = NULL; } +#ifdef CONFIG_MESH + if (wpa_s->ifmsh) { + wpa_supplicant_mesh_iface_deinit(wpa_s, wpa_s->ifmsh); + wpa_s->ifmsh = NULL; + } +#endif /* CONFIG_MESH */ + if (wpa_s->conf != NULL) { wpa_config_free(wpa_s->conf); wpa_s->conf = NULL;