From patchwork Mon May 25 14:46:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Crispin X-Patchwork-Id: 1297371 X-Patchwork-Delegate: blogic@openwrt.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=phrozen.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20170209 header.b=kmO+zzbb; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49W0Kt6LSJz9sT0 for ; Tue, 26 May 2020 00:46:57 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Subject:MIME-Version:Message-Id:Date:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=iYmXyFu60zbasxnuceJOsX18IHhM1U/IHt/3/JmwVCE=; b=kmO+zzbbwF7QGg cKDu60E9apL6MYDcEy9BjTQ4AmO+Tco18aTHwauj9wqxnWSgfFKLBAGiJHjc8d4KN7C7iwONyOgz6 JyN2lQldMyYTixsr4XytGhtD2TO97+O+GX6tDFwaoSu/Ca+9KF0Wl53dEh+rdvQiU1Uj7R51x136Y Xk+LSZCwxXydjCq+OgmcEdkbjFaTlhKKKPIcG6u7lNI6RDRFa/Hhqzj2VnMphd5vTkhQJ4h+JCyIj hd0EJI+NZvlFdTg2ldfuwOUcA3nQYsII3/EqOvQsBVF7OH7Uz5QY4G9vSjmbvZfI93aZue1XcBm/n QaYJYxt5kHPW86L+WU2Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jdENR-0006Ir-UP; Mon, 25 May 2020 14:46:53 +0000 Received: from nbd.name ([2a01:4f8:221:3d45::2]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jdENO-0006Hs-8W for openwrt-devel@lists.openwrt.org; Mon, 25 May 2020 14:46:51 +0000 Received: from [46.59.216.37] (helo=bertha8.datto.lan) by ds12 with esmtpa (Exim 4.89) (envelope-from ) id 1jdENL-0007TV-4n; Mon, 25 May 2020 16:46:47 +0200 From: John Crispin To: openwrt-devel@lists.openwrt.org Date: Mon, 25 May 2020 16:46:39 +0200 Message-Id: <20200525144639.10421-1-john@phrozen.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200525_074650_459064_84B50DCA X-CRM114-Status: GOOD ( 13.04 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record Subject: [OpenWrt-Devel] [PATCH] hostapd: add support for wifi-station and wifi-vlan sections X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: John Crispin Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org This patch adds support for 2 new uci sections. config wifi-vlan # iface is optional. if it is not defined the vlan will apply # to all interfaces option iface default_radio0 option name guest option vid 100 option network guest config wifi-station # iface is optional. if it is not defined the station will apply # to all interfaces option iface default_radio0 # mac is optional. if it is not defined it will be a catch all # for any sta using this key option mac '00:11:22:33:44:55' # vid is optional. if it is not defined, the sta will be part of # the primary iface. option vid 100 option key testtest With this patch applied it is possible to use multiple PSKs and VIDs on a single BSS. Signed-off-by: John Crispin --- .../files/lib/netifd/wireless/mac80211.sh | 8 +++- .../network/services/hostapd/files/hostapd.sh | 37 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/package/kernel/mac80211/files/lib/netifd/wireless/mac80211.sh b/package/kernel/mac80211/files/lib/netifd/wireless/mac80211.sh index 7ca138c68c..19d05cb6dc 100644 --- a/package/kernel/mac80211/files/lib/netifd/wireless/mac80211.sh +++ b/package/kernel/mac80211/files/lib/netifd/wireless/mac80211.sh @@ -506,7 +506,7 @@ mac80211_iw_interface_add() { mac80211_prepare_vif() { json_select config - json_get_vars ifname mode ssid wds powersave macaddr enable + json_get_vars ifname mode ssid wds powersave macaddr enable wpa_psk_file vlan_file [ -n "$ifname" ] || ifname="wlan${phy#phy}${if_idx:+-$if_idx}" if_idx=$((${if_idx:-0} + 1)) @@ -524,6 +524,12 @@ mac80211_prepare_vif() { json_add_object data json_add_string ifname "$ifname" json_close_object + + [ "$mode" == "ap" ] && { + [ -z "$wpa_psk_file" ] && hostapd_set_psk "$ifname" + [ -z "$vlan_file" ] && hostapd_set_vlan "$ifname" + } + json_select config # It is far easier to delete and create the desired interface diff --git a/package/network/services/hostapd/files/hostapd.sh b/package/network/services/hostapd/files/hostapd.sh index 637f298ad9..a3554b6451 100644 --- a/package/network/services/hostapd/files/hostapd.sh +++ b/package/network/services/hostapd/files/hostapd.sh @@ -262,6 +262,39 @@ hostapd_common_add_bss_config() { config_add_string 'owe_transition_bssid:macaddr' 'owe_transition_ssid:string' } +hostapd_set_vlan_file() { + local ifname="$1" + local vlan="$2" + json_get_vars name vid + echo "${vid} ${ifname}-${name}" >> /var/run/hostapd-${ifname}.vlan + wireless_add_vlan "${vlan}" "${ifname}-${name}" +} + +hostapd_set_vlan() { + local ifname="$1" + + rm /var/run/hostapd-${ifname}.vlan + for_each_vlan hostapd_set_vlan_file ${ifname} +} + +hostapd_set_psk_file() { + local ifname="$1" + local vlan="$2" + local vlan_id="" + + json_get_vars mac vid key + set_default isolate "00:00:00:00:00:00" + [ -n "$vid" ] && vlan_id="vlanid=$vid " + echo "${vlan_id} ${mac} ${key}" >> /var/run/hostapd-${ifname}.psk +} + +hostapd_set_psk() { + local ifname="$1" + + rm /var/run/hostapd-${ifname}.psk + for_each_station hostapd_set_psk_file ${ifname} +} + hostapd_set_bss_options() { local var="$1" local phy="$2" @@ -377,12 +410,15 @@ hostapd_set_bss_options() { else append bss_conf "wpa_passphrase=$key" "$N" fi + [ -z "$wpa_psk_file" ] && set_default wpa_psk_file /var/run/hostapd-$ifname.psk [ -n "$wpa_psk_file" ] && { [ -e "$wpa_psk_file" ] || touch "$wpa_psk_file" append bss_conf "wpa_psk_file=$wpa_psk_file" "$N" } [ "$eapol_version" -ge "1" -a "$eapol_version" -le "2" ] && append bss_conf "eapol_version=$eapol_version" "$N" + set_default dynamic_vlan 0 + vlan_possible=1 wps_possible=1 ;; eap|eap192|eap-eap192) @@ -639,6 +675,7 @@ hostapd_set_bss_options() { [ -n "$vlan_possible" -a -n "$dynamic_vlan" ] && { json_get_vars vlan_naming vlan_tagged_interface vlan_bridge vlan_file set_default vlan_naming 1 + [ -z "$vlan_file" ] && set_default vlan_file /var/run/hostapd-$ifname.vlan append bss_conf "dynamic_vlan=$dynamic_vlan" "$N" append bss_conf "vlan_naming=$vlan_naming" "$N" [ -n "$vlan_bridge" ] && \