fff-hoods/fff-wireless: Reconfigure instead of delete and create

Previously, when configurehood switched status, all WiFi devices
were completely rewritten and all interfaces were deleted and
recreated. This is both unnecessary and ugly.

This patch redesigns WiFi setup to create all interfaces (in
parallel) initially, and then only to enable/disable them as
necessary. Where reconfiguration is necessary, only the variable
parts are changed.

Since most of the wifi-device config is already created by
OpenWrt, this builds based on the existing wifi-devices and
only removes the default wifi-ifaces.

This patch will not change the logic (codeflow) of configurehood,
but only affects how action on the WiFi devices/interfaces is
taken.

Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
Reviewed-by: Fabian Bläse <fabian@blaese.de>
This commit is contained in:
Adrian Schmutzler 2019-06-16 16:23:24 +02:00
parent 8a1eb6d4c8
commit 3d9eb1db2e
8 changed files with 163 additions and 299 deletions

View File

@ -1,7 +1,7 @@
include $(TOPDIR)/rules.mk include $(TOPDIR)/rules.mk
PKG_NAME:=fff-hoods PKG_NAME:=fff-hoods
PKG_RELEASE:=5 PKG_RELEASE:=6
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME) PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)

View File

@ -0,0 +1,27 @@
#!/bin/sh
. /lib/functions/fff/wireless
# Set up wXsta
for radio in $(wifiListRadio); do
# wXsta: We can use $freq here, as the initial radios are not set up with auto
freq="$(wifiGetFreq $radio)"
uci batch <<-__EOF__
set network.configsta${freq}=interface
set network.configsta${freq}.proto='static'
set wireless.w${freq}sta='wifi-iface'
set wireless.w${freq}sta.device='${radio}'
set wireless.w${freq}sta.network='configsta${freq}'
set wireless.w${freq}sta.ifname='w${freq}sta'
set wireless.w${freq}sta.mode='sta'
set wireless.w${freq}sta.ssid='config.franken.freifunk.net'
set wireless.w${freq}sta.disabled='1'
__EOF__
done
uci commit network
uci commit wireless
# vim: set noexpandtab:tabstop=4

View File

@ -13,33 +13,20 @@ getWirelessHoodfile() {
# only change temporarily # only change temporarily
if ! wifiDelIface; then # Set channel to auto, enable wXsta, disable other interfaces
echo "Can't delete current wifi setup" for radio in $(wifiListRadio); do
exit 1 uci set "wireless.${radio}.channel=auto"
fi
#now we look for phy and add this
for phy in $(iw phy | awk '/^Wiphy/{ print $2 }'); do
radio="$(wifiAddPhyCond "$phy" "2" "auto")"
radio5="$(wifiAddPhyCond "$phy" "5" "auto5")"
if [ -n "$radio5" ] ; then
radio="$radio5"
staiface="w5sta"
else
staiface="w2sta"
fi
#and here we add the station freq="$(wifiGetFreq $radio)"
if ! wifiAddSta "$radio" "config.franken.freifunk.net" "configSta" "$staiface" ; then uci set wireless.w${freq}ap.disabled='1'
echo "Can't add Sta interface on $radio." uci set wireless.w${freq}mesh.disabled='1'
exit 1 uci set wireless.w${freq}configap.disabled='1'
else uci set wireless.w${freq}sta.disabled='0'
uci -q set network.configSta=interface
uci -q set network.configSta.proto='static'
uci -q commit network
reload_config
fi
done done
uci commit wireless
reload_config
wifi wifi
# wait a moment to start the interface # wait a moment to start the interface
sleep 10; sleep 10;

View File

@ -46,27 +46,17 @@ hasInternet() {
if [ -s "$hoodfilewww" ] && isGatewayAvailable ; then if [ -s "$hoodfilewww" ] && isGatewayAvailable ; then
needwifi="0" needwifi="0"
for radio in $(uci show wireless | sed -n 's,.*\.\([a-z0-9]*\)=wifi-device,\1,p'); do for radio in $(wifiListRadio); do
freq="2" freq="$(wifiGetFreq $radio)"
if [ "$(uci get "wireless.${radio}.channel")" -gt "14" ]; then
freq="5"
fi
# Break: wXconfig is up # Break: wXconfig is up
uci -q get "wireless.w${freq}configap" > /dev/null && continue [ "$(uci get "wireless.w${freq}configap.disabled")" = "0" ] && continue
# Break: No mesh interface # Break: No mesh interface
uci -q get "wireless.w${freq}mesh" > /dev/null || continue [ "$(uci get "wireless.w${freq}mesh.disabled")" = "0" ] || continue
# Create configap # Enable configap
iface="configap$freq" uci set wireless.w${freq}configap.disabled='0'
uci set network.${iface}=interface uci commit wireless
uci set network.${iface}.proto='static'
uci set network.${iface}.ip6addr='fe80::1/64'
uci commit network
reload_config
if ! wifiAddAP "$radio" "config.franken.freifunk.net" "$iface" "configap" "1"; then
echo "Can't add Config interface on $radio."
exit 1
fi
needwifi="1" needwifi="1"
done done
@ -157,38 +147,50 @@ if [ -s "$hoodfiletmp" ]; then
uci -q commit system uci -q commit system
reload_config reload_config
if ! wifiDelIface; then for radio in $(wifiListRadio); do
echo "Can't delete current wifi setup" freq="$(wifiGetFreq $radio)"
exit 1
fi
for phy in $(iw phy | awk '/^Wiphy/{ print $2 }'); do if [ "$freq" = "5" ]; then
radio="$(wifiAddPhyCond "$phy" "2" "$chan2ghz")" uci set wireless.${radio}.channel="$chan5ghz"
radio5="$(wifiAddPhyCond "$phy" "5" "$chan5ghz")" mesh_type="$mesh_type5"
[ -n "$radio5" ] && radio="$radio5" elif [ "$freq" = "2" ]; then
uci set wireless.${radio}.channel="$chan2ghz"
if ! wifiAddAP "$radio" "$essid" "mesh" "ap" "0"; then mesh_type="$mesh_type2"
echo "Can't add AP interface on $radio."
exit 1
fi fi
# add 802.11s mesh if type = "802.11s" # Disable wXsta, wXconfigap
if ( [ -n "$radio5" ] && [ "$mesh_type5" = "802.11s" ] ) || [ "$mesh_type2" = "802.11s" ]; then uci set wireless.w${freq}sta.disabled='1'
if ! wifiAddMesh "$radio" "$mesh_id"; then uci set wireless.w${freq}configap.disabled='1'
echo "Can't add Mesh interface on $radio."
exit 1
fi
fi
# add IBSS mesh if type = "ibss" # Configure wXap
if ( [ -n "$radio5" ] && [ "$mesh_type5" = "ibss" ] ) || [ "$mesh_type2" = "ibss" ]; then uci set wireless.w${freq}ap.ssid="$essid"
if ! wifiAddAdHocMesh "$radio" "$mesh_essid" "$mesh_bssid"; then uci set wireless.w${freq}ap.disabled='0'
echo "Can't add AdHocMesh interface on $radio."
exit 1 # Configure 802.11s mesh if type = "802.11s"
fi if [ "$mesh_type" = "802.11s" ]; then
uci set wireless.w${freq}mesh.mode='mesh'
uci -q del wireless.w${freq}mesh.bssid
uci -q del wireless.w${freq}mesh.ssid
uci -q del wireless.w${freq}mesh.mcast_rate
uci set wireless.w${freq}mesh.mesh_id="$mesh_id"
uci set wireless.w${freq}mesh.mesh_fwding='0'
uci set wireless.w${freq}mesh.disabled='0'
# Configure IBSS mesh if type = "ibss"
elif [ "$mesh_type" = "ibss" ]; then
uci set wireless.w${freq}mesh.mode='adhoc'
uci -q del wireless.w${freq}mesh.mesh_id
uci -q del wireless.w${freq}mesh.mesh_fwding
uci set wireless.w${freq}mesh.bssid="$mesh_bssid"
uci set wireless.w${freq}mesh.ssid="$mesh_essid"
uci set wireless.w${freq}mesh.mcast_rate='6000'
uci set wireless.w${freq}mesh.disabled='0'
# Disable mesh by setting no mesh_type
else
uci set wireless.w${freq}mesh.disabled='1'
fi fi
done done
uci commit wireless
echo "Loading wifi" echo "Loading wifi"
wifi wifi

View File

@ -1,7 +1,7 @@
include $(TOPDIR)/rules.mk include $(TOPDIR)/rules.mk
PKG_NAME:=fff-wireless PKG_NAME:=fff-wireless
PKG_RELEASE:=7 PKG_RELEASE:=8
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME) PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)

View File

@ -1,32 +1,80 @@
#!/bin/sh #!/bin/sh
# Copyright 2016 Tim Niemeyer # Copyright 2016 Tim Niemeyer
# Copyright 2019 Adrian Schmutzler
# License GPLv3 # License GPLv3
. /lib/functions.sh
. /lib/functions/fff/wireless . /lib/functions/fff/wireless
if ! wifiDelAll; then removeWifiIface() {
echo "Can't delete current wifi setup" local name="$1"
exit 1 uci del "wireless.$name"
fi }
for phy in $(iw phy | awk '/^Wiphy/{ print $2 }'); do configWifiDevice() {
radio="$(wifiAddPhyCond "$phy" "2" "1")" local radio="$1"
radio5="$(wifiAddPhyCond "$phy" "5" "36")" local freq="$(wifiGetFreq $radio)"
[ -n "$radio5" ] && radio="$radio5"
if [ -z "$radio" ] ; then
echo "Can't create radio for $phy"
exit 1
fi
if ! wifiAddAP "$radio" "do.not.use" "mesh" "ap" "0" ; then [ "$freq" = "2" ] && uci set "wireless.${radio}.legacy_rates=0"
echo "Can't add AP interface on $radio."
exit 1
fi
if ! wifiAddMesh "$radio" "mesh.do.not.use" ; then # Comments
echo "Can't add Mesh interface on $radio." # wXmesh: use 802.11s mesh as "default"
exit 1
fi uci batch <<-__EOF__
done set wireless.${radio}.htmode='HT20'
set wireless.${radio}.country='DE'
set wireless.${radio}.disabled='0'
set wireless.w${freq}ap='wifi-iface'
set wireless.w${freq}ap.device='${radio}'
set wireless.w${freq}ap.network='mesh'
set wireless.w${freq}ap.ifname='w${freq}ap'
set wireless.w${freq}ap.mode='ap'
set wireless.w${freq}ap.ssid='noservice.freifunk'
set wireless.w${freq}ap.encryption='none'
set wireless.w${freq}ap.hidden='0'
set wireless.w${freq}ap.disabled='0'
set network.w${freq}mesh='interface'
set network.w${freq}mesh.mtu='1560'
set network.w${freq}mesh.proto='batadv'
set network.w${freq}mesh.mesh='bat0'
set wireless.w${freq}mesh='wifi-iface'
set wireless.w${freq}mesh.device='${radio}'
set wireless.w${freq}mesh.network='w${freq}mesh'
set wireless.w${freq}mesh.ifname='w${freq}mesh'
set wireless.w${freq}mesh.mode='mesh'
set wireless.w${freq}mesh.mesh_id='nomesh.freifunk'
set wireless.w${freq}mesh.encryption='none'
set wireless.w${freq}mesh.mesh_fwding=0
set wireless.w${freq}mesh.disabled='0'
set network.configap${freq}=interface
set network.configap${freq}.proto='static'
set network.configap${freq}.ip6addr='fe80::1/64'
set wireless.w${freq}configap='wifi-iface'
set wireless.w${freq}configap.device='${radio}'
set wireless.w${freq}configap.network='configap${freq}'
set wireless.w${freq}configap.ifname='w${freq}configap'
set wireless.w${freq}configap.mode='ap'
set wireless.w${freq}configap.ssid='config.franken.freifunk.net'
set wireless.w${freq}configap.encryption='none'
set wireless.w${freq}configap.hidden='1'
set wireless.w${freq}configap.disabled='1'
__EOF__
}
# Remove WiFi config
config_load wireless
config_foreach removeWifiIface wifi-iface
# Set up WiFi devices and interfaces, but leave the latter disabled
config_load wireless
config_foreach configWifiDevice wifi-device
uci commit network
uci commit wireless
# vim: set noexpandtab:tabstop=4 # vim: set noexpandtab:tabstop=4

View File

@ -1,229 +1,29 @@
# Copyright 2016 Tim Niemeyer # Copyright 2016 Tim Niemeyer
# License GPLv3 # License GPLv3
wifiDelAll() { wifiListRadio() {
if [ $# -ne "0" ] if [ $# -ne "0" ]
then then
echo "Usage: wifiDelAll" echo "Usage: wifiListRadio"
return 1 return 1
fi fi
> /etc/config/wireless uci show wireless | sed -n 's,.*\.\([a-z0-9]*\)=wifi-device,\1,p'
return 0 return 0
} }
wifiDelIface() { wifiGetFreq() {
if [ $# -ne "0" ] if [ $# -ne "1" ]
then then
echo "Usage: wifiDelIface" echo "Usage: wifiGetFreq <radio>"
return 1
fi
grep 'config wifi-iface' /etc/config/wireless | sed -n -e "s/.*'\([^']*\)'.*/\1/p" | while read -r line ; do
uci -q delete "wireless.$line"
done
uci -q commit wireless
return 0
}
wifiAddPhy() {
if [ $# -ne "2" ]
then
echo "Usage: wifiAddPhy <phy> <channel>"
return 1
fi
local phy=$1
local channel=$2
local radio="radio$(echo "$phy" | tr -d -C "0-9")"
local hwmode="11g"
if [ "$channel" = "auto5" ] ; then
hwmode="11a"
channel="auto"
elif ( ! [ "$channel" = "auto" ] ) && [ "$channel" -gt "14" ]; then
hwmode="11a"
fi
uci batch <<-__EOF__
set wireless.${radio}='wifi-device'
set wireless.${radio}.type='mac80211'
set wireless.${radio}.channel='${channel}'
set wireless.${radio}.phy='${phy}'
set wireless.${radio}.hwmode='${hwmode}'
set wireless.${radio}.htmode='HT20'
set wireless.${radio}.country='DE'
__EOF__
if [ "$hwmode" = "11g" ]; then
uci batch <<-__EOF__
set wireless.${radio}.legacy_rates='0'
__EOF__
fi
uci commit wireless
echo "${radio}"
return 0
}
wifiAddPhyCond() {
if [ $# -ne "3" ]
then
return 1
fi
local phy=$1
local freq=$2
local channel=$3
local radio=""
if iw phy "$phy" info | grep -q -m1 "${freq}... MHz"; then
radio="$(wifiAddPhy "$phy" "$channel")"
if [ -z "$radio" ]; then
return 1
fi
fi
echo "$radio"
return 0 # also returns success if outermost if is false
}
wifiAddAdHocMesh() {
if [ $# -ne "3" ]
then
echo "Usage: wifiAddAdHocMesh <radio> <essid> <bssid>"
return 1 return 1
fi fi
local radio=$1 local radio=$1
local essid=$2
local bssid=$3
local channel=$(uci get "wireless.${radio}.channel") # Use hwmode for switching, since this is always set by firmware (effectively hard-coded)
local iface="w2mesh" # Do not use channel, as this might be "auto" for both
if [ "$channel" -gt "14" ]; then [ "$(uci get "wireless.${radio}.hwmode")" = "11a" ] && echo "5" || echo "2"
iface="w5mesh"
fi
uci batch <<-__EOF__
set wireless.${iface}='wifi-iface'
set wireless.${iface}.device='${radio}'
set wireless.${iface}.network='${iface}'
set wireless.${iface}.ifname='${iface}'
set wireless.${iface}.mode='adhoc'
set wireless.${iface}.bssid='${bssid}'
set wireless.${iface}.ssid='${essid}'
set wireless.${iface}.mcast_rate='6000'
set wireless.${iface}.encryption='none'
commit wireless
set network.${iface}='interface'
set network.${iface}.mtu='1528'
set network.${iface}.proto='batadv'
set network.${iface}.mesh='bat0'
commit network
__EOF__
echo "${iface}"
return 0
}
wifiAddAP() {
if [ $# -ne "5" ]
then
echo "Usage: wifiAddAP <radio> <essid> <network> <iface> <hidden>"
return 1
fi
local radio=$1
local essid=$2
local network=$3
local inface=$4
local hidden=$5
local channel=$(uci get "wireless.${radio}.channel")
local iface="w2${inface}"
if [ "$channel" -gt "14" ]; then
iface="w5${inface}"
fi
uci batch <<-__EOF__
set wireless.${iface}='wifi-iface'
set wireless.${iface}.device='${radio}'
set wireless.${iface}.network='${network}'
set wireless.${iface}.ifname='${iface}'
set wireless.${iface}.mode='ap'
set wireless.${iface}.ssid='${essid}'
set wireless.${iface}.encryption='none'
set wireless.${iface}.hidden='${hidden}'
commit wireless
__EOF__
echo "${iface}"
return 0
}
wifiAddSta() {
if [ $# -ne "4" ]
then
echo "Usage: wifiAddSta <radio> <essid> <network> <iface>"
return 1
fi
local radio=$1
local essid=$2
local network=$3
local iface=$4
uci batch <<-__EOF__
set wireless.${iface}='wifi-iface'
set wireless.${iface}.device='${radio}'
set wireless.${iface}.network='${network}'
set wireless.${iface}.ifname='${iface}'
set wireless.${iface}.mode='sta'
set wireless.${iface}.ssid='${essid}'
commit wireless
__EOF__
echo "${iface}"
return 0
}
wifiAddMesh() {
if [ $# -ne "2" ]
then
echo "Usage: wifiAddMesh <radio> <mesh-id>"
return 1
fi
local radio=$1
local mesh_id=$2
local channel=$(uci get "wireless.${radio}.channel")
local iface="w2mesh"
if [ "$channel" -gt "14" ]; then
iface="w5mesh"
fi
uci batch <<-__EOF__
set wireless.${iface}='wifi-iface'
set wireless.${iface}.device='${radio}'
set wireless.${iface}.network='${iface}'
set wireless.${iface}.ifname='${iface}'
set wireless.${iface}.mode='mesh'
set wireless.${iface}.mesh_id='${mesh_id}'
set wireless.${iface}.encryption='none'
set wireless.${iface}.mesh_fwding=0
commit wireless
set network.${iface}='interface'
set network.${iface}.mtu='1560'
set network.${iface}.proto='batadv'
set network.${iface}.mesh='bat0'
commit network
__EOF__
echo "${iface}"
return 0 return 0
} }
# vim: set noexpandtab:tabstop=4 # vim: set noexpandtab:tabstop=4