From f777e914f94af7796fbe126e48365c19e14e37c5 Mon Sep 17 00:00:00 2001 From: Joe AE6XE Date: Wed, 12 Dec 2018 13:16:07 -0800 Subject: [PATCH] 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 --- files/etc/config.mesh/_setup | 3 +- files/etc/config.mesh/_setup.default | 1 + files/usr/local/bin/clean_zombie.sh | 6 ++ files/usr/local/bin/node-setup | 31 ++++--- files/usr/local/bin/rssi_monitor | 6 +- files/usr/local/bin/snrlog | 11 ++- files/usr/local/bin/wifi-setup | 63 +++++++------ files/www/cgi-bin/setup | 132 ++++++++++++++++----------- files/www/cgi-bin/status | 65 ++++++++----- files/www/cgi-bin/supporttool | 9 ++ 10 files changed, 207 insertions(+), 120 deletions(-) diff --git a/files/etc/config.mesh/_setup b/files/etc/config.mesh/_setup index 1315c765..b83b193a 100644 --- a/files/etc/config.mesh/_setup +++ b/files/etc/config.mesh/_setup @@ -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 diff --git a/files/etc/config.mesh/_setup.default b/files/etc/config.mesh/_setup.default index bfb76658..eea9c4f4 100644 --- a/files/etc/config.mesh/_setup.default +++ b/files/etc/config.mesh/_setup.default @@ -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 diff --git a/files/usr/local/bin/clean_zombie.sh b/files/usr/local/bin/clean_zombie.sh index 58b7692e..261ad280 100755 --- a/files/usr/local/bin/clean_zombie.sh +++ b/files/usr/local/bin/clean_zombie.sh @@ -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 diff --git a/files/usr/local/bin/node-setup b/files/usr/local/bin/node-setup index 64aee771..c2c48d93 100755 --- a/files/usr/local/bin/node-setup +++ b/files/usr/local/bin/node-setup @@ -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"; diff --git a/files/usr/local/bin/rssi_monitor b/files/usr/local/bin/rssi_monitor index e97bfe1a..6e94699a 100755 --- a/files/usr/local/bin/rssi_monitor +++ b/files/usr/local/bin/rssi_monitor @@ -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]+)/; diff --git a/files/usr/local/bin/snrlog b/files/usr/local/bin/snrlog index 4b643a17..2809e7ff 100755 --- a/files/usr/local/bin/snrlog +++ b/files/usr/local/bin/snrlog @@ -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") diff --git a/files/usr/local/bin/wifi-setup b/files/usr/local/bin/wifi-setup index 15c7717c..c38f5635 100755 --- a/files/usr/local/bin/wifi-setup +++ b/files/usr/local/bin/wifi-setup @@ -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 diff --git a/files/www/cgi-bin/setup b/files/www/cgi-bin/setup index 487991fe..90e45c2f 100755 --- a/files/www/cgi-bin/setup +++ b/files/www/cgi-bin/setup @@ -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 " push @hidden, ""; +# add enable/disable +# + +print "\n"; +print "\n"; + print "\n"; print "\n"; print "\n"; @@ -694,53 +702,67 @@ if ( -f "/etc/config/unconfigured" || $parms{button_reset} ) { $wifi_chanbw = $defaultwifi->{'chanbw'}; } -print "\n"; -print "\n"; - -push @hidden, ""; - -print "\n"; -print "\n"; + print "\n"; + + push @hidden, ""; + + print "\n"; + print "\n"; + + print "\n"; + print "\n"; + + push (@hidden, ""); + + print "\n"; + + print "\n"; + print "\n"; + + print "\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 "\n"; + + print "\n"; + } -print "\n"; - -print "\n"; -print "\n"; - -push (@hidden, ""); - -print "\n"; - -print "\n"; -print "\n"; - -print "\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 "\n"; - -print "\n"; +else +{ + push @hidden, ""; + push @hidden, ""; + push @hidden, ""; + push @hidden, ""; + push @hidden, ""; + push @hidden, ""; + push (@hidden, ""); +} print "
Enable
IP Address
Netmask
SSID"; -print "-$wifi_chanbw-v3
Channel
SSID"; + print "-$wifi_chanbw-v3
Channel
Channel Width

Active Settings
Tx Power  
Distance to
FARTHEST Neighbor
 miles
"; + print " kilometers
"; + print " meters
"; + + print "
"; + print ""; + print "
Channel Width

Active Settings
Tx Power  
Distance to
FARTHEST Neighbor
 miles
"; -print " kilometers
"; -print " meters
"; - -print "
"; -print ""; -print "
\n"; @@ -833,18 +855,18 @@ else print "
"; -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 "LAN Access Point"; @@ -874,6 +896,14 @@ if ( $phycount > 1 ) { print ""; print "\n"; } +else +{ + push @hidden, ""; + push @hidden, ""; + push @hidden, ""; + push @hidden, ""; + push @hidden, ""; +} if(0) # disable for now { diff --git a/files/www/cgi-bin/status b/files/www/cgi-bin/status index aedb8e35..006237bd 100755 --- a/files/www/cgi-bin/status +++ b/files/www/cgi-bin/status @@ -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 = "Location Not Available"; if(-f "/etc/latlon") { @@ -117,8 +123,11 @@ if($config eq "mesh") { print "   "; print "\n"; - print "   "; - print "\n"; + if ( ! $wifi_disable ) + { + print "   "; + print "\n"; + } } print "   "; @@ -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 = "WiFi address$ip $cidr
"; +if (! $wifi_disable ) +{ + $str = "Wifi address$ip $cidr
"; +} +else +{ + $str = "Primary address$ip $cidr
"; +} + # $str .= "" . get_ip6_addr($wifi_iface) . ""; push @col1, $str; @@ -217,19 +234,21 @@ if($browser_ip) push @col1, $str . ""; } -$str = "SSID$wifi_ssid"; -push @col1, $str . ""; +if ( ! $wifi_disable ) +{ + $str = "SSID$wifi_ssid"; + push @col1, $str . ""; -$str = "Channel$wifi_channel"; -push @col1, $str . ""; - -$str = "Bandwidth$wifi_chanbw Mhz"; -push @col1, $str . ""; + $str = "Channel$wifi_channel"; + push @col1, $str . ""; + $str = "Bandwidth$wifi_chanbw Mhz"; + push @col1, $str . ""; +} # right column - system info -if($config eq "mesh") +if($config eq "mesh" and ! $wifi_disable ) { $str = "Signal/Noise/Ratio"; ($s, $n) = get_wifi_signal($wifi_iface); diff --git a/files/www/cgi-bin/supporttool b/files/www/cgi-bin/supporttool index 704160c3..cb491d10 100755 --- a/files/www/cgi-bin/supporttool +++ b/files/www/cgi-bin/supporttool @@ -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");