Skip to content

Commit

Permalink
aredn: add wan wifi client capability
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe Ayers authored and ae6xe committed Jun 18, 2019
1 parent d8f9320 commit 74ca6f5
Show file tree
Hide file tree
Showing 7 changed files with 275 additions and 78 deletions.
5 changes: 5 additions & 0 deletions files/etc/config.mesh/_setup
Expand Up @@ -17,6 +17,11 @@ wifi2_encryption =
wifi2_key =
wifi2_hwmode = 11a

wifi3_enable = 0
wifi3_ssid =
wifi3_key =
wifi3_hwmode = 11a

dmz_mode = 3
lan_proto = static
lan_ip = 172.27.0.1
Expand Down
5 changes: 5 additions & 0 deletions files/etc/config.mesh/_setup.default
Expand Up @@ -17,6 +17,11 @@ wifi2_encryption = none
wifi2_key =
wifi2_hwmode = 11a

wifi3_enable = 0
wifi3_ssid =
wifi3_key =
wifi3_hwmode = 11a

dmz_mode = 3
lan_proto = static
lan_ip = 172.27.0.1
Expand Down
5 changes: 3 additions & 2 deletions files/usr/local/bin/node-setup
Expand Up @@ -126,7 +126,9 @@ foreach $line (`cat /etc/config.mesh/_setup`)
chomp ($lanintf=`jsonfilter -e '@.network.lan.ifname' < /etc/board.json`);
$cfg{lan_intf} = "$lanintf";

$cfg{wan_intf} = get_bridge_interfaces("wan");
$cfg{wan_intf} = "dummy";
# wan_intf is set by wifi-setup directly to network config file

$cfg{dtdlink_intf} = get_bridge_interfaces("dtdlink");

if ( $cfg{wifi_enable} == 1 )
Expand Down Expand Up @@ -511,7 +513,6 @@ system $cmd;
#
system('/usr/local/bin/wifi-setup');


unless($auto)
{
print "configuration complete.\n";
Expand Down
51 changes: 38 additions & 13 deletions files/usr/local/bin/wifi-setup
Expand Up @@ -53,18 +53,27 @@ done < $configfile
meshif="$(uci -q get network.wifi.ifname)"
meshphy="phy${meshif#wlan}"

# set physical wan interface in network

wan_intf=`cat /etc/board.json|jsonfilter -e '@.network.wan.ifname'`
uci -c ${dropdir} -q batch > /dev/null <<-EOF
set network.wan.ifname=$wan_intf
EOF
uci -c ${dropdir} -q commit network

rm -f "${dropdir}/wireless"
touch "${dropdir}/wireless"

ifacecount=$(ls -d /sys/class/ieee80211/* | wc -l)
ifacenum=0

# find each phy and configure in wirelss config
# find each phy and configure in wireless config
for _dev in /sys/class/ieee80211/*; do
[ -e "$_dev" ] || continue

dev="${_dev##*/}"
radio="radio${dev#phy}"
wlan="wlan${dev#phy}"

if [ -x /usr/bin/readlink -a -h "/sys/class/ieee80211/${dev}" ]; then
devpath="$(readlink -n -f /sys/class/ieee80211/${dev})"
Expand All @@ -85,21 +94,19 @@ for _dev in /sys/class/ieee80211/*; do
is_mesh_rf=0
hwmode="11g"
htmode="HT20"
disabled="0"
chanbw=""
country=""
channel=""
distance=""

iw phy "${dev}" info | grep -q '5180 MHz' && {
hwmode="11a"
}

if [[ $wifi2_enable -eq 1 -a \( $ifacecount -eq 1 -o \( \( $ifacecount -gt 1 \) -a \( "$hwmode" = "$wifi2_hwmode" \) \) \) ]] ; then
wifi2_disabled="0"
else
wifi2_disabled="1"
fi

if [ "${dev}" = "${meshphy}" ]; then
# mesh RF adhoc configuration
is_mesh_rf=1
disabled="0"
channel="${wifi_channel}"
chanbw="${wifi_chanbw}"
country="HX"
Expand All @@ -109,12 +116,9 @@ for _dev in /sys/class/ieee80211/*; do
encryption="none"
key=""
network="wifi"
else
disabled="${wifi2_disabled}"
elif [[ $wifi2_enable -eq 1 -a \( $ifacecount -eq 1 -o \( \( $ifacecount -gt 1 \) -a \( "$hwmode" = "$wifi2_hwmode" \) \) \) ]]; then
# LAN AP interface
channel="${wifi2_channel}"
chanbw=""
country=""
distance=""
ssid=$(echo "${wifi2_ssid}" | sed -e 's/\(..\)/\\x\1/g')
ssid=$(echo -e "${ssid}")
ssid=${ssid//\"/\\\"}
Expand All @@ -124,6 +128,27 @@ for _dev in /sys/class/ieee80211/*; do
key=$(echo -e "${key}")
key=${key//\"/\\\"}
network="lan"
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"
encryption="psk2"
key=$(echo "${wifi3_key}" | sed -e 's/\(..\)/\\x\1/g')
key=$(echo -e "${key}")
key=${key//\"/\\\"}
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"
fi

uci -c ${dropdir} -q batch > /dev/null <<-EOF
Expand Down
2 changes: 1 addition & 1 deletion files/www/cgi-bin/perlfunc.pm
Expand Up @@ -594,7 +594,7 @@ sub save_setup
open(FILE, ">$_[0]") or return 0;
foreach(sort keys %parms)
{
next unless /^(aprs|dhcp|dmz|lan|olsrd|wan|wifi|wifi2|dtdlink|ntp|time|description)_/;
next unless /^(aprs|dhcp|dmz|lan|olsrd|wan|wifi|wifi2|wifi3|dtdlink|ntp|time|description)_/;
print FILE "$_ = $parms{$_}\n";
}
close(FILE);
Expand Down

0 comments on commit 74ca6f5

Please sign in to comment.