aredn: Mesh RF enable/disable (#307)

add feature to turn off Mesh RF if not in use.  When off,
section to re-purpose wireless card to LAN bridged Access
Point becomes visable.
Closes #155
This commit is contained in:
Joe AE6XE 2018-12-12 13:16:07 -08:00 committed by dman776
parent ce5a757ca0
commit f777e914f9
10 changed files with 207 additions and 120 deletions

View File

@ -8,11 +8,12 @@ wifi_channel = 1
wifi_chanbw = 20
wifi_distance = 0
wifi_country = 00
wifi_enable = 1
wifi2_enable = 0
wifi2_ssid = NoCall-AREDN
wifi2_channel = 36
wifi2_encryption = none
wifi2_encryption =
wifi2_key =
dmz_mode = 3

View File

@ -8,6 +8,7 @@ wifi_channel = 1
wifi_chanbw = 20
wifi_distance = 0
wifi_country = 00
wifi_enable = 1
wifi2_enable = 0
wifi2_ssid = NoCAll-AREDN

View File

@ -36,6 +36,12 @@ LICENSE
# Look for hung 'iw' zombie processes prone to hang
# when available memory is low.
# if Mesh RF is disabled, then nothing to do
iface=$(uci -q get 'network.wifi.ifname')
if [ "$iface" = "${iface##wlan*}" ]; then
exit
fi
zombiepid="/tmp/clean_zombie.pid"
[ -e $zombiepid ] && [ -d "/proc/$(cat $zombiepid)" ] && exit

View File

@ -124,15 +124,23 @@ foreach $line (`cat /etc/config.mesh/_setup`)
}
chomp ($lanintf=`jsonfilter -e '@.network.lan.ifname' < /etc/board.json`);
$cfg{"lan_intf"} = "$lanintf";
if ( ! $cfg{"wifi_intf"} )
{
$cfg{"wifi_intf"} = get_interface("wifi");
}
$cfg{"wan_intf"} = get_bridge_interfaces("wan");
$cfg{"dtdlink_intf"} = get_bridge_interfaces("dtdlink");
$cfg{lan_intf} = "$lanintf";
$cfg{"wifi_intf"} =~ /wlan(\d+)/;
$cfg{wan_intf} = get_bridge_interfaces("wan");
$cfg{dtdlink_intf} = get_bridge_interfaces("dtdlink");
if ( $cfg{wifi_enable} == 1 )
{
$cfg{wifi_intf} = `jsonfilter -e '@.network.wifi.ifname' < /etc/board.json | cut -f1`;
$cfg{wifi_intf} =~ /wlan(\d+)/;
chomp $cfg{wifi_intf};
}
else
{
$wifi_sudo_intf = "$lanintf";
$wifi_sudo_intf =~ s/^([^\. \t]+).*$/$1/;
$cfg{wifi_intf} = $wifi_sudo_intf . ".3975";
}
die "configuration load failed\n" unless keys %cfg;
@ -417,7 +425,10 @@ unless($cfg{wifi_proto} eq "disabled")
{
$cfg{wifi_txpower} = wifi_maxpower($cfg{wifi_channel}) if not defined $cfg{wifi_txpower} or $cfg{wifi_txpower} > wifi_maxpower($cfg{wifi_channel});
$cfg{wifi_txpower} = 1 if $cfg{wifi_txpower} < 1;
print FILE "/usr/sbin/iw dev $cfg{wifi_intf} set txpower fixed $cfg{wifi_txpower}00\n";
if ( $cfg{wifi_enable} == 1 )
{
print FILE "/usr/sbin/iw dev $cfg{wifi_intf} set txpower fixed $cfg{wifi_txpower}00\n";
}
if(defined $cfg{aprs_lat} and defined $cfg{aprs_lon})
{
printf FILE "echo %s,%s > /tmp/latlon.txt\n", $cfg{aprs_lat}, $cfg{aprs_lon};
@ -467,8 +478,6 @@ if(-f "/etc/config.mesh/olsrd")
print OUT "config LoadPlugin\n";
print OUT " option library 'olsrd_dyn_gw.so.0.5'\n";
print OUT " option Interval '60'\n";
print OUT " list Ping '71.42.236.91'\n"; # hsmm-mesh.org\n";
print OUT " list Ping '71.42.236.90'\n"; # hsmm-mesh.org\n";
print OUT " list Ping '8.8.8.8'\n"; # google dns\n";
print OUT " list Ping '8.8.4.4'\n"; # google dns\n";
print OUT "\n\n";

View File

@ -39,6 +39,11 @@
# The wireless driver poorly tunes and treats these neighbors as noise in error.
# This is a workaround until root cause driver updates occur.
chomp ($iface=`uci -q get 'network.wifi.ifname'`); # wireless interface
$wifi_disable = ( $iface =~ /eth.*$/ )? 1 : 0;
exit 0 if $wifi_disable;
$now=`cat /proc/uptime | cut -f1 -d" "`;
chomp $now;
exit 0 unless $now > 119;
@ -75,7 +80,6 @@ if ( -f "$snrlogpid" )
sleep 7;
chomp ($iface=`uci -q get 'network.wifi.ifname'`); # wireless interface
foreach(`iwinfo $iface info`)
{
next unless /^.*PHY name:\s*([a-z0-4]+)/;

View File

@ -256,6 +256,14 @@ end
-- Neighbor Class END
-- MAIN() -------------------------------------------------------------------------------------
-- get wifi interface name
wifiiface=get_ifname("wifi")
-- if Mesh RF is turned off do nothing
if ( wifiiface == string.match(wifiiface,'eth.*')) then
return
end
-- check to make sure a prior instance is not still running
local f = io.open(pidfile,"r")
if (f) then
@ -285,9 +293,6 @@ if (f) then
end
end
-- get wifi interface name
wifiiface=get_ifname("wifi")
-- load the lasttime table
if file_exists(lastdat) then
local f,err=io.open(lastdat,"r")

View File

@ -52,6 +52,7 @@ done < $configfile
meshif="$(uci -q get network.wifi.ifname)"
meshphy="phy${meshif#wlan}"
hwtype="$(/usr/local/bin/get_hardwaretype)"
rm -f "${dropdir}/wireless"
touch "${dropdir}/wireless"
@ -109,7 +110,6 @@ for _dev in /sys/class/ieee80211/*; do
key=""
network="wifi"
else
# mesh AP bridged with lan
disabled="${wifi2_disabled}"
channel="${wifi2_channel}"
chanbw=""
@ -126,39 +126,42 @@ for _dev in /sys/class/ieee80211/*; do
network="lan"
fi
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))
# test for devices with 2 wireless cards -- don't setup 2 APs
if [ "$hwtype" != "rb-952ui-5ac2nd" -o "$hwmode" != "11g" -o ${is_mesh_rf} -eq 1 ]; then
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=wifi_mon
set wireless.@wifi-iface[${ifacenum}].mode=monitor
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 -q -c ${dropdir} commit wireless
fi
uci -c ${dropdir} -q commit wireless
if [ ${is_mesh_rf} -eq 1 ]; then
# add monitor interface on mesh rf
ifacenum=$((ifacenum + 1))
uci -c ${dropdir} -q batch > /dev/null <<-EOF
add wireless wifi-iface
set wireless.@wifi-iface[${ifacenum}].device=${radio}
set wireless.@wifi-iface[${ifacenum}].network=wifi_mon
set wireless.@wifi-iface[${ifacenum}].mode=monitor
EOF
uci -q -c ${dropdir} commit wireless
fi
fi
ifacenum=$((ifacenum + 1))
done

View File

@ -128,7 +128,7 @@ else
}
# make sure unchecked checkboxes are accounted for
foreach(qw(lan_dhcp olsrd_bridge olsrd_gw wifi2_enable lan_dhcp_noroute))
foreach(qw(lan_dhcp olsrd_bridge olsrd_gw wifi2_enable lan_dhcp_noroute wifi_enable))
{
$parms{$_} = 0 unless $parms{$_};
}
@ -187,7 +187,7 @@ $parms{wifi_txpower} = $wifi_txpower;
# apply the wifi settings
#
if($parms{button_apply} or $parms{button_save})
if(($parms{button_apply} or $parms{button_save}) and $wifi_enable )
{
if($wifi_distance < 1 or $wifi_distance =~ /\D/)
{
@ -682,6 +682,14 @@ print "<table width=100% style='border-collapse: collapse;'>
push @hidden, "<input type=hidden name=wifi_proto value='static'>";
# add enable/disable
#
print "\n<tr><td>Enable</td>";
print "<td><input type=checkbox name=wifi_enable value=1";
print " checked" if $wifi_enable;
print "></td></tr>\n";
print "<tr><td><nobr>IP Address</nobr></td>\n";
print "<td><input type=text size=15 name=wifi_ip value='$wifi_ip'></td></tr>\n";
print "<tr><td>Netmask</td>\n";
@ -694,53 +702,67 @@ if ( -f "/etc/config/unconfigured" || $parms{button_reset} ) {
$wifi_chanbw = $defaultwifi->{'chanbw'};
}
print "<tr><td>SSID</td>\n";
print "<td><input type=text size=15 name=wifi_ssid value='$wifi_ssid'>";
print "-$wifi_chanbw-v3</td></tr>\n";
push @hidden, "<input type=hidden name=wifi_mode value='$wifi_mode'>";
print "<tr><td>Channel</td>\n";
print "<td><select name=wifi_channel>\n";
my $rfchannels=rf_channels_list();
foreach $channelnumber (sort {$a <=> $b} keys %{$rfchannels} )
if ( ${wifi_enable} )
{
selopt($rfchannels->{$channelnumber}, $channelnumber, $wifi_channel);
print "<tr><td>SSID</td>\n";
print "<td><input type=text size=15 name=wifi_ssid value='$wifi_ssid'>";
print "-$wifi_chanbw-v3</td></tr>\n";
push @hidden, "<input type=hidden name=wifi_mode value='$wifi_mode'>";
print "<tr><td>Channel</td>\n";
print "<td><select name=wifi_channel>\n";
my $rfchannels=rf_channels_list();
foreach $channelnumber (sort {$a <=> $b} keys %{$rfchannels} )
{
selopt($rfchannels->{$channelnumber}, $channelnumber, $wifi_channel);
}
print "</select></td></tr>\n";
print "<tr><td>Channel Width</td>\n";
print "<td><select name=wifi_chanbw>\n";
selopt("20 MHz","20",$wifi_chanbw);
selopt("10 MHz","10",$wifi_chanbw);
selopt("5 MHz","5",$wifi_chanbw);
print "</select></td></tr>\n";
push (@hidden, "<input type=hidden name=wifi_country value='HX'>");
print "<tr><td colspan=2 align=center><hr><small>Active Settings</small></td></tr>\n";
print "<tr><td><nobr>Tx Power</nobr></td>\n";
print "<td><select name=wifi_txpower>\n";
my $txpoweroffset = wifi_txpoweroffset();
for($i = wifi_maxpower($wifi_channel); $i >= 1; --$i) { selopt($i+$txpoweroffset ." dBm", $i, $wifi_txpower) }
print "</select>&nbsp;&nbsp;<a href=\"/help.html\#power\" target=\"_blank\"><img src=\"/qmark.png\"></a></td></tr>\n";
print "<tr id='dist' class='dist-norm'><td>Distance to<br />FARTHEST Neighbor</td>\n";
$wifi_distance=int($wifi_distance); # in meters
$wifi_distance_disp_km=int($wifi_distance/1000);
$wifi_distance_disp_miles=sprintf("%.2f",$wifi_distance_disp_km*.621371192);
print "<td><input disabled size=6 type=text name='wifi_distance_disp_miles' value='$wifi_distance_disp_miles' title='Distance to the farthest neighbor'>&nbsp;miles<br />";
print "<input disabled size=6 type=text size=4 name='wifi_distance_disp_km' value='$wifi_distance_disp_km' title='Distance to the farthest neighbor'>&nbsp;kilometers<br />";
print "<input disabled size=6 type=text size=4 name='wifi_distance_disp_meters' value='$wifi_distance' title='Distance to the farthest neighbor'>&nbsp;meters<br />";
print "<input id='distance_slider' type='range' min='0' max='150' step='1' value='$wifi_distance_disp_km' oninput='updDist(this.value)' onchange='updDist(this.value)' /><br />";
print "<input type='hidden' size='6' name='wifi_distance' value='$wifi_distance' />";
print "</td></tr>\n";
print "<tr><td></td><td><input type=submit name=button_apply value=Apply title='Immediately use these active settings'></td></tr>\n";
}
print "</select></td></tr>\n";
print "<tr><td>Channel Width</td>\n";
print "<td><select name=wifi_chanbw>\n";
selopt("20 MHz","20",$wifi_chanbw);
selopt("10 MHz","10",$wifi_chanbw);
selopt("5 MHz","5",$wifi_chanbw);
print "</select></td></tr>\n";
push (@hidden, "<input type=hidden name=wifi_country value='HX'>");
print "<tr><td colspan=2 align=center><hr><small>Active Settings</small></td></tr>\n";
print "<tr><td><nobr>Tx Power</nobr></td>\n";
print "<td><select name=wifi_txpower>\n";
my $txpoweroffset = wifi_txpoweroffset();
for($i = wifi_maxpower($wifi_channel); $i >= 1; --$i) { selopt($i+$txpoweroffset ." dBm", $i, $wifi_txpower) }
print "</select>&nbsp;&nbsp;<a href=\"/help.html\#power\" target=\"_blank\"><img src=\"/qmark.png\"></a></td></tr>\n";
print "<tr id='dist' class='dist-norm'><td>Distance to<br />FARTHEST Neighbor</td>\n";
$wifi_distance=int($wifi_distance); # in meters
$wifi_distance_disp_km=int($wifi_distance/1000);
$wifi_distance_disp_miles=sprintf("%.2f",$wifi_distance_disp_km*.621371192);
print "<td><input disabled size=6 type=text name='wifi_distance_disp_miles' value='$wifi_distance_disp_miles' title='Distance to the farthest neighbor'>&nbsp;miles<br />";
print "<input disabled size=6 type=text size=4 name='wifi_distance_disp_km' value='$wifi_distance_disp_km' title='Distance to the farthest neighbor'>&nbsp;kilometers<br />";
print "<input disabled size=6 type=text size=4 name='wifi_distance_disp_meters' value='$wifi_distance' title='Distance to the farthest neighbor'>&nbsp;meters<br />";
print "<input id='distance_slider' type='range' min='0' max='150' step='1' value='$wifi_distance_disp_km' oninput='updDist(this.value)' onchange='updDist(this.value)' /><br />";
print "<input type='hidden' size='6' name='wifi_distance' value='$wifi_distance' />";
print "</td></tr>\n";
print "<tr><td></td><td><input type=submit name=button_apply value=Apply title='Immediately use these active settings'></td></tr>\n";
else
{
push @hidden, "<input type=hidden name=wifi_ssid value='$wifi_ssid'>";
push @hidden, "<input type=hidden name=wifi_mode value='$wifi_mode'>";
push @hidden, "<input type=hidden name=wifi_txpower value='$wifi_txpower'>";
push @hidden, "<input type=hidden name=wifi_channel value='$wifi_channel'>";
push @hidden, "<input type=hidden name=wifi_chanbw value='$wifi_chanbw'>";
push @hidden, "<input type=hidden name=wifi_distance value='$wifi_distance'>";
push (@hidden, "<input type=hidden name=wifi_country value='HX'>");
}
print "</table></td>\n";
@ -833,18 +855,18 @@ else
print "<tr><td colspan=2><hr></hr></td></tr>";
if ( $phycount > 1 ) {
if ( $phycount > 1 or ! $wifi_enable ) {
# determine AP's band
if ( "$phy" eq "phy0" ) { $APphy="phy1"; }
else { $APphy="phy0"; }
$rc3 = system("iw phy ${APphy} info | grep -q '5180 MHz > /dev/null");
$rc3 = system("iw phy ${APphy} info | grep -q '5180 MHz' > /dev/null");
undef @chan;
if ( $rc3 ) {
@chan=@cfive;
@chan=@ctwo;
}
else {
@chan=@ctwo;
@chan=@cfive;
}
print "<tr><th colspan=2>LAN Access Point</th></tr>";
@ -874,6 +896,14 @@ if ( $phycount > 1 ) {
print "<td><input type=password size=15 name=wifi2_key value='$wifi2_key'>";
print "</td></tr>\n";
}
else
{
push @hidden, "<input type=hidden name=wifi2_enable value='$wifi2_enable'>";
push @hidden, "<input type=hidden name=wifi2_ssid value='$wifi2_ssid'>";
push @hidden, "<input type=hidden name=wifi2_key value='$wifi2_key'>";
push @hidden, "<input type=hidden name=wifi2_channel value='$wifi2_channel'>";
push @hidden, "<input type=hidden name=wifi2_encryption value='$wifi2_encryption'>";
}
if(0) # disable for now
{

View File

@ -50,21 +50,27 @@ $config = "not set" if $config eq "" or not -d "/etc/config.mesh";
$wifi_iface = get_interface("wifi");
$wifi_iface =~ /wlan(\d+)/;
$radio = ( defined $1 )? "radio$1" : "radio0";
$wifi_disable = ( $wifi_iface =~ /eth.*$/ )? 1 : 0;
($junk, $wifi_channel) = &uci_get_named_option("wireless", "$radio", "channel");
if ($wifi_channel >= 76 and $wifi_channel <= 99)
if ( ! $wifi_disable )
{
$wifi_channel = ($wifi_channel*5+3000);
}
($junk, $wifi_chanbw) = &uci_get_named_option("wireless", "$radio", "chanbw");
$node_desc = `/sbin/uci -q get system.\@system[0].description`; #pull the node description from uci
$wifi_ssid = "N/A";
@wisections = &uci_get_all_indexed_by_sectiontype("wireless", "wifi-iface");
foreach(@wisections) {
if ($_->{network} eq "wifi") {
$wifi_ssid = $_->{ssid};
($junk, $wifi_channel) = &uci_get_named_option("wireless", "$radio", "channel");
if ($wifi_channel >= 76 and $wifi_channel <= 99)
{
$wifi_channel = ($wifi_channel*5+3000);
}
($junk, $wifi_chanbw) = &uci_get_named_option("wireless", "$radio", "chanbw");
$wifi_ssid = "N/A";
@wisections = &uci_get_all_indexed_by_sectiontype("wireless", "wifi-iface");
foreach(@wisections) {
if ($_->{network} eq "wifi") {
$wifi_ssid = $_->{ssid};
}
}
}
$node_desc = `/sbin/uci -q get system.\@system[0].description`; #pull the node description from uci
#get location info if available
$lat_lon = "<strong>Location Not Available</strong>";
if(-f "/etc/latlon") {
@ -117,8 +123,11 @@ if($config eq "mesh")
{
print "&nbsp;&nbsp;&nbsp;";
print "<button type=button onClick='window.location=\"mesh\"' title='See what is on the mesh'>Mesh Status</button>\n";
print "&nbsp;&nbsp;&nbsp;";
print "<button type=button onClick='window.location=\"scan\"' title='See what wireless networks are nearby'>WiFi Scan</button>\n";
if ( ! $wifi_disable )
{
print "&nbsp;&nbsp;&nbsp;";
print "<button type=button onClick='window.location=\"scan\"' title='See what wireless networks are nearby'>WiFi Scan</button>\n";
}
}
print "&nbsp;&nbsp;&nbsp;";
@ -164,10 +173,18 @@ $browser_ip = "";
# left column - network interface info
# show the wifi address
# show the Primary/Wifi address
($ip, $mask, $bcast, $net, $cidr) = get_ip4_network($wifi_iface);
$cidr = "/ $cidr" if $cidr;
$str = "<th align=right><nobr>WiFi address</nobr></th><td>$ip <small>$cidr</small><br>";
if (! $wifi_disable )
{
$str = "<th align=right><nobr>Wifi address</nobr></th><td>$ip <small>$cidr</small><br>";
}
else
{
$str = "<th align=right><nobr>Primary address</nobr></th><td>$ip <small>$cidr</small><br>";
}
# $str .= "<small><nobr>" . get_ip6_addr($wifi_iface) . "</nobr></small></td>";
push @col1, $str;
@ -217,19 +234,21 @@ if($browser_ip)
push @col1, $str . "</td>";
}
$str = "<th align=right><nobr>SSID</nobr></th><td>$wifi_ssid";
push @col1, $str . "</td>";
if ( ! $wifi_disable )
{
$str = "<th align=right><nobr>SSID</nobr></th><td>$wifi_ssid";
push @col1, $str . "</td>";
$str = "<th align=right><nobr>Channel</nobr></th><td>$wifi_channel";
push @col1, $str . "</td>";
$str = "<th align=right><nobr>Bandwidth</nobr></th><td>$wifi_chanbw Mhz";
push @col1, $str . "</td>";
$str = "<th align=right><nobr>Channel</nobr></th><td>$wifi_channel";
push @col1, $str . "</td>";
$str = "<th align=right><nobr>Bandwidth</nobr></th><td>$wifi_chanbw Mhz";
push @col1, $str . "</td>";
}
# right column - system info
if($config eq "mesh")
if($config eq "mesh" and ! $wifi_disable )
{
$str = "<th align=right valign=middle><nobr>Signal/Noise/Ratio</nobr></th><td valign=middle><nobr>";
($s, $n) = get_wifi_signal($wifi_iface);

View File

@ -111,6 +111,8 @@ system ("rm", "-r", "-f", "/tmp/sd");
foreach $path (@files) {
next if (! -e $path and ! -d $path);
if ( $path =~ /^\/(.*\/).*\/$/ ) {
my $rpath = $1;
system("mkdir", "-p", "/tmp/sd/$rpath");
@ -132,6 +134,13 @@ foreach $path (@sensitive) {
}
}
#Remove passwords from config files
system ("cat /tmp/sd/etc/config/wireless | sed -e 's/ key.*\$/ key \*\*\*\*\*\*/' > /tmp/sd/etc/config/wireless.sav");
unlink "rm /tmp/sd/etc/config/wireless";
rename "/tmp/sd/etc/config/wireless.sav", "/tmp/sd/etc/config/wireless";
system ("cat /tmp/sd/etc/config.mesh/_setup | sed -e 's/_key =.*\$/_key =/' > /tmp/sd/etc/config.mesh/_setup.sav");
unlink "/tmp/sd/etc/config.mesh/_setup";
rename "/tmp/sd/etc/config.mesh/_setup.sav", "/tmp/sd/etc/config.mesh/_setup";
system("touch","/tmp/sd/data.txt");