2018-11-27 22:37:59 -07:00
|
|
|
#!/bin/sh
|
|
|
|
<<'LICENSE'
|
|
|
|
Part of AREDN -- Used for creating Amateur Radio Emergency Data Networks
|
|
|
|
Copyright (C) 2018 Joe Ayers ae6xe@arrl.net
|
|
|
|
See Contributors file for additional contributors
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation version 3 of the License.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
Additional Terms:
|
|
|
|
|
|
|
|
Additional use restrictions exist on the AREDN(TM) trademark and logo.
|
|
|
|
See AREDNLicense.txt for more info.
|
|
|
|
|
|
|
|
Attributions to the AREDN Project must be retained in the source code.
|
|
|
|
If importing this code into a new or existing project attribution
|
|
|
|
to the AREDN project must be added to the source code.
|
|
|
|
|
|
|
|
You must not misrepresent the origin of the material contained within.
|
|
|
|
|
|
|
|
Modified versions must be modified to attribute to the original source
|
|
|
|
and be marked in reasonable ways as differentiate it from the original
|
|
|
|
version.
|
|
|
|
|
|
|
|
LICENSE
|
|
|
|
|
|
|
|
# This script reads the AREDN related wireless config options and generates
|
|
|
|
# a wireless UCI config file
|
|
|
|
|
|
|
|
# $1 is directory to create the wireless config
|
|
|
|
|
|
|
|
dropdir=${1-/etc/config}
|
|
|
|
|
|
|
|
# get aredn wifi related parameters
|
|
|
|
configfile=/etc/config.mesh/_setup
|
|
|
|
while read -r line; do
|
|
|
|
if [ -n "$line" -a -z "${line##wifi*}" ]; then
|
2019-06-20 00:30:29 -06:00
|
|
|
value="${line##*= }"
|
|
|
|
value="${value##*=}"
|
|
|
|
eval ${line%% =*}="\"$value"\"
|
2018-11-27 22:37:59 -07:00
|
|
|
fi
|
|
|
|
done < $configfile
|
|
|
|
|
|
|
|
# get mesh RF dev master setting in /etc/config/network
|
|
|
|
|
|
|
|
meshif="$(uci -q get network.wifi.ifname)"
|
|
|
|
meshphy="phy${meshif#wlan}"
|
|
|
|
|
|
|
|
rm -f "${dropdir}/wireless"
|
|
|
|
touch "${dropdir}/wireless"
|
|
|
|
|
2018-12-17 21:13:37 -07:00
|
|
|
ifacecount=$(ls -d /sys/class/ieee80211/* | wc -l)
|
2018-11-27 22:37:59 -07:00
|
|
|
ifacenum=0
|
|
|
|
|
2019-04-06 22:03:16 -06:00
|
|
|
# find each phy and configure in wireless config
|
2018-11-27 22:37:59 -07:00
|
|
|
for _dev in /sys/class/ieee80211/*; do
|
|
|
|
[ -e "$_dev" ] || continue
|
|
|
|
|
|
|
|
dev="${_dev##*/}"
|
|
|
|
radio="radio${dev#phy}"
|
2019-04-06 22:03:16 -06:00
|
|
|
wlan="wlan${dev#phy}"
|
2018-11-27 22:37:59 -07:00
|
|
|
|
|
|
|
if [ -x /usr/bin/readlink -a -h "/sys/class/ieee80211/${dev}" ]; then
|
|
|
|
devpath="$(readlink -n -f /sys/class/ieee80211/${dev})"
|
|
|
|
else
|
|
|
|
devpath=""
|
|
|
|
fi
|
|
|
|
if [ -n "${devpath}" ]; then
|
|
|
|
devpath="${devpath##/sys/devices/}"
|
|
|
|
devpath="${devpath%%/ieee802*}"
|
|
|
|
case "${devpath}" in
|
|
|
|
platform*/pci*) devpath="${devpath##platform/}";;
|
|
|
|
esac
|
|
|
|
dev_id="set wireless.${radio}.path=${devpath}"
|
|
|
|
else
|
|
|
|
dev_id="set wireless.${radio}.macaddr=$(cat /sys/class/ieee80211/${dev}/macaddress)"
|
|
|
|
fi
|
|
|
|
|
|
|
|
is_mesh_rf=0
|
|
|
|
hwmode="11g"
|
|
|
|
htmode="HT20"
|
2019-04-06 22:03:16 -06:00
|
|
|
disabled="0"
|
|
|
|
chanbw=""
|
|
|
|
country=""
|
|
|
|
channel=""
|
|
|
|
distance=""
|
2018-11-27 22:37:59 -07:00
|
|
|
|
|
|
|
iw phy "${dev}" info | grep -q '5180 MHz' && {
|
|
|
|
hwmode="11a"
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ "${dev}" = "${meshphy}" ]; then
|
|
|
|
# mesh RF adhoc configuration
|
|
|
|
is_mesh_rf=1
|
|
|
|
channel="${wifi_channel}"
|
|
|
|
chanbw="${wifi_chanbw}"
|
|
|
|
country="HX"
|
|
|
|
distance="${wifi_distance}"
|
|
|
|
ssid="${wifi_ssid}-${chanbw}-v3"
|
|
|
|
mode="adhoc"
|
|
|
|
encryption="none"
|
|
|
|
key=""
|
|
|
|
network="wifi"
|
2019-04-06 22:03:16 -06:00
|
|
|
elif [[ $wifi2_enable -eq 1 -a \( $ifacecount -eq 1 -o \( \( $ifacecount -gt 1 \) -a \( "$hwmode" = "$wifi2_hwmode" \) \) \) ]]; then
|
|
|
|
# LAN AP interface
|
2018-11-27 22:37:59 -07:00
|
|
|
channel="${wifi2_channel}"
|
2018-11-30 09:32:38 -07:00
|
|
|
ssid=$(echo "${wifi2_ssid}" | sed -e 's/\(..\)/\\x\1/g')
|
|
|
|
ssid=$(echo -e "${ssid}")
|
|
|
|
ssid=${ssid//\"/\\\"}
|
2018-11-27 22:37:59 -07:00
|
|
|
mode="ap"
|
|
|
|
encryption="${wifi2_encryption}"
|
2018-11-30 09:32:38 -07:00
|
|
|
key=$(echo "${wifi2_key}" | sed -e 's/\(..\)/\\x\1/g')
|
|
|
|
key=$(echo -e "${key}")
|
|
|
|
key=${key//\"/\\\"}
|
2018-11-27 22:37:59 -07:00
|
|
|
network="lan"
|
2019-04-06 22:03:16 -06:00
|
|
|
elif [[ $wifi3_enable -eq 1 -a \( $ifacecount -eq 1 -o \( \( $ifacecount -gt 1 \) -a \( "$hwmode" = "$wifi3_hwmode" \) \) \) ]]; then
|
|
|
|
# WAN Client
|
|
|
|
disabled="0"
|
|
|
|
channel=""
|
|
|
|
ssid=$(echo "${wifi3_ssid}" | sed -e 's/\(..\)/\\x\1/g')
|
|
|
|
ssid=$(echo -e "${ssid}")
|
|
|
|
ssid=${ssid//\"/\\\"}
|
|
|
|
mode="sta"
|
2019-06-20 00:30:29 -06:00
|
|
|
if [ -z "$wifi3_key" ]; then
|
|
|
|
encryption="none"
|
|
|
|
key=""
|
|
|
|
else
|
|
|
|
encryption="psk2"
|
|
|
|
key=$(echo "${wifi3_key}" | sed -e 's/\(..\)/\\x\1/g')
|
|
|
|
key=$(echo -e "${key}")
|
|
|
|
key=${key//\"/\\\"}
|
|
|
|
fi
|
2019-04-06 22:03:16 -06:00
|
|
|
network="wan"
|
|
|
|
htmode=""
|
|
|
|
uci -c ${dropdir} -q batch > /dev/null <<-EOF
|
|
|
|
set network.wan.ifname=$wlan
|
|
|
|
EOF
|
|
|
|
uci -c ${dropdir} -q commit network
|
|
|
|
else
|
|
|
|
# interface is disabled
|
|
|
|
disabled="1"
|
2018-11-27 22:37:59 -07:00
|
|
|
fi
|
|
|
|
|
2018-12-17 21:13:37 -07:00
|
|
|
uci -c ${dropdir} -q batch > /dev/null <<-EOF
|
|
|
|
set wireless.${radio}=wifi-device
|
|
|
|
set wireless.${radio}.type=mac80211
|
|
|
|
set wireless.${radio}.disabled=${disabled}
|
|
|
|
set wireless.${radio}.channel=${channel}
|
|
|
|
set wireless.${radio}.chanbw=${chanbw}
|
|
|
|
set wireless.${radio}.country=${country}
|
|
|
|
set wireless.${radio}.distance=${distance}
|
|
|
|
set wireless.${radio}.hwmode=${hwmode}
|
|
|
|
set wireless.${radio}.htmode=${htmode}
|
|
|
|
${dev_id}
|
|
|
|
add wireless wifi-iface
|
|
|
|
set wireless.@wifi-iface[${ifacenum}].device=${radio}
|
|
|
|
set wireless.@wifi-iface[${ifacenum}].network=${network}
|
|
|
|
set wireless.@wifi-iface[${ifacenum}].mode=${mode}
|
|
|
|
set wireless.@wifi-iface[${ifacenum}].ssid="${ssid}"
|
|
|
|
set wireless.@wifi-iface[${ifacenum}].encryption=${encryption}
|
|
|
|
set wireless.@wifi-iface[${ifacenum}].key="${key}"
|
|
|
|
EOF
|
|
|
|
uci -c ${dropdir} -q commit wireless
|
|
|
|
|
|
|
|
if [ ${is_mesh_rf} -eq 1 ]; then
|
|
|
|
# add monitor interface on mesh rf
|
|
|
|
ifacenum=$((ifacenum + 1))
|
2018-11-27 22:37:59 -07:00
|
|
|
uci -c ${dropdir} -q batch > /dev/null <<-EOF
|
|
|
|
add wireless wifi-iface
|
2018-12-17 21:13:37 -07:00
|
|
|
set wireless.@wifi-iface[${ifacenum}].device=${radio}
|
|
|
|
set wireless.@wifi-iface[${ifacenum}].network=wifi_mon
|
|
|
|
set wireless.@wifi-iface[${ifacenum}].mode=monitor
|
2018-12-12 14:16:07 -07:00
|
|
|
EOF
|
2018-12-17 21:13:37 -07:00
|
|
|
uci -q -c ${dropdir} commit wireless
|
2018-11-27 22:37:59 -07:00
|
|
|
fi
|
2018-12-12 14:16:07 -07:00
|
|
|
|
2018-11-27 22:37:59 -07:00
|
|
|
ifacenum=$((ifacenum + 1))
|
|
|
|
|
|
|
|
done
|