From 808a8d5019fce4a7ca2c027ea7838d43c6d8cad0 Mon Sep 17 00:00:00 2001 From: Conrad Lara - KG6JEI Date: Thu, 1 May 2014 20:32:40 -0700 Subject: [PATCH 1/6] Initial changes to work with OpenWRT 12.09 Mostly relates to iwinfo being the new command to obtain info about devices. iwlist does not exist in 12.09 --- files/usr/local/bin/wscan | 25 +++++++++++------------ files/www/cgi-bin/channelmaps.pm | 12 ++++++----- files/www/cgi-bin/perlfunc.pm | 34 +++++++++++--------------------- files/www/cgi-bin/setup | 5 ++--- files/www/cgi-bin/status | 9 ++++----- 5 files changed, 37 insertions(+), 48 deletions(-) diff --git a/files/usr/local/bin/wscan b/files/usr/local/bin/wscan index 81a4e9a0..596e8abd 100755 --- a/files/usr/local/bin/wscan +++ b/files/usr/local/bin/wscan @@ -186,8 +186,8 @@ sub pushAP if($ssid eq "") { $ssid = "(hidden)" } - if($key eq "off") { $key = " " } - else { $key = "*" } + if($key eq "none") { $key = " " } + else { $key = "*" } $mac =~ /^(\w\w):(\w\w):(\w\w):(\w\w):(\w\w):(\w\w)/; $mac1 = $1 . $2 . $3; @@ -248,36 +248,35 @@ die "bad interface" if not defined $iface; if($raw) { - system("/usr/sbin/iwlist $iface scan"); + system("/usr/bin/iwinfo $iface scan"); exit; } while(1) { - open(FILE, "/usr/sbin/iwlist $iface scan 2>&1 |") or die "iwlist failed"; + open(FILE, "/usr/bin/iwinfo $iface scan 2>&1 |") or die "iwinfo failed"; $mode = ""; @list = (); ++$iters; while($line = ) { - if($line =~ /\s+Cell \d+ - Address: (\S+)/) + if($line =~ /Cell \d+ - Address: (\S+)/) { - if ( $lastseen < 10000 ) { pushAP($signal, $chan, $key, $ssid, $mac, $mode) } + pushAP($signal, $chan, $key, $ssid, $mac, $mode); $mac = $1; $mode = ""; } - if($line =~ /\bESSID:"(.*)"/) { $ssid = $1 } - if($line =~ /\bMode:(\S+)/) { $mode = $1 } - if($line =~ /\bChannel:(\d+)/) { $chan = $1 } - if($line =~ /\bSignal level=([\d-]+)/) { $signal = $1 } - if($line =~ /\bEncryption key:(\w+)/) { $key = $1 } - if($line =~ /\bExtra: Last beacon: (\d+)ms/) { $lastseen = $1 } + if($line =~ /\bESSID: "(.*)"/) { $ssid = $1 } + if($line =~ /\bMode: (\S+)/) { $mode = $1 } + if($line =~ /\bChannel: (\d+)/) { $chan = $1 } + if($line =~ /\bSignal: ([\d-]+)/) { $signal = $1 } + if($line =~ /\bEncryption: (\w+)/) { $key = $1 } } close(FILE); - if ( $lastseen < 10000 ) { pushAP($signal, $chan, $key, $ssid, $mac, $mode) } + pushAP($signal, $chan, $key, $ssid, $mac, $mode); sleep 1 if not scalar @list and $loops != 1; if(not $batch) diff --git a/files/www/cgi-bin/channelmaps.pm b/files/www/cgi-bin/channelmaps.pm index ae55646b..247edc50 100644 --- a/files/www/cgi-bin/channelmaps.pm +++ b/files/www/cgi-bin/channelmaps.pm @@ -99,9 +99,10 @@ sub is_channel_valid # We don't have the device band in the data file so lets fall back to checking manually else { my $channelok=0; - foreach (`iwlist wlan0 channel`) + foreach (`iwinfo wlan0 channels`) { next unless /Channel $channel/; + next if /\[restricted\]/; $channelok=1; } return $channelok; @@ -125,11 +126,12 @@ sub rf_channels_list else { my %channels = (); - foreach (`iwlist wlan0 channel` ) + foreach (`iwinfo wlan0 freqlist` ) { - next unless /([0-9]+) : ([0-9]+.[0-9]+)/; - my $channelnum = $1; - my $channelfreq = $2; + next unless /([0-9]+.[0-9]+) Ghz \(Channel ([0-9]+)\)/; + next if /\[restricted\]/; + my $channelnum = $2; + my $channelfreq = $1; $channelnum =~s/^0+//g; $channels->{$channelnum} = "$channelfreq GHZ" ; } diff --git a/files/www/cgi-bin/perlfunc.pm b/files/www/cgi-bin/perlfunc.pm index 4f91ee02..50d0654c 100644 --- a/files/www/cgi-bin/perlfunc.pm +++ b/files/www/cgi-bin/perlfunc.pm @@ -1,4 +1,4 @@ -############################# +########################## # html functions # emit the http server response @@ -83,13 +83,13 @@ sub read_query_string # c-style fgets for read_postdata + $stdinbuffer = ""; sub fgets { my($size) = @_; my $line = ""; - while(1) { unless(length $stdinbuffer) @@ -118,14 +118,14 @@ sub fgets # (from STDIN in method=post form) sub read_postdata { + if ( $ENV{REQUEST_METHOD} != "POST" || !$ENV{CONTENT_LENGTH}){ return; }; my ($line, $parm, $file, $handle, $tmp); my $state = "boundary"; my ($boundary) = $ENV{CONTENT_TYPE} =~ /boundary=(\S+)/ if $ENV{CONTENT_TYPE}; my $parsedebug = 0; push(@parse_errors, "[$boundary]") if $parsedebug; - while(length ($line = fgets(1000))) - { + { $line =~ s/[\r\n]+$//; # chomp doesn't strip \r! #print "[$state] $line
\n"; @@ -546,25 +546,15 @@ sub save_setup sub get_wifi_signal { - # CMLARA: - # this would be easy if /proc/net/wireless updated automatically, but it doesn't. - # the hack is to re-scan - # also iwlist doesnt correctly limit to single ssid - # and we have to call from 2 programs now instead of 1 - my ($ssid) = (`uci -q get wireless.\@wifi-iface[0].ssid`); - chomp $ssid; + my $wifiintf = `uci -q get network.wifi.ifname`; + chomp $wifiintf; my ($SignalLevel) = "N/A"; my ($NoiseFloor) = "N/A"; - foreach(`iwlist $_[0] scanning essid "$ssid" |tr '\n' ' '|sed 's/Cell \\([0-9]\\{2,\\}\\) - Address:/\\nCell \\1 - Address:/g'|grep -i "$ssid"`) + foreach(`iwinfo $wifiintf info`) { - next unless /.*Signal level=([\d\-]+) dBm.* Extra: Last beacon: ([\d]+)ms/; - if ( $2 < 10000 ) {$SignalLevel=$1;} - } - - foreach(`iw dev $_[0] survey dump|grep -A 1 \"\\[in use\\]\"`) - { - next unless /([\d\-]+) dBm/; - $NoiseFloor=$1; + next unless /.*Signal: ([\d\-]+) dBm.*Noise: ([\d\-]+) dBm/; + $SignalLevel=$1; + $NoiseFloor=$2; } if ( $SignalLevel == "N/A" || $NoiseFloor == "N/A" ) @@ -592,9 +582,9 @@ sub get_free_mem { foreach(`free`) { - next unless /^\s+Mem[:]/; + next unless /^Mem[:]/; my @tmp = split /\s+/, $_; - return $tmp[4] + $tmp[6]; + return $tmp[3] + $tmp[5]; } return "N/A"; } diff --git a/files/www/cgi-bin/setup b/files/www/cgi-bin/setup index b67d1efd..720995d0 100755 --- a/files/www/cgi-bin/setup +++ b/files/www/cgi-bin/setup @@ -5,7 +5,6 @@ $debug = 0; BEGIN {push @INC, '/www/cgi-bin'}; use perlfunc; use channelmaps; - # # load the config parms # @@ -95,7 +94,7 @@ $parms{dmz_dhcp_limit} = $dmz_dhcp_limit = $dmz_dhcp_end - $dmz_dhcp_start; unless($parms{reload}) { - ($wifi_txpower) = `iwconfig wlan0 2>/dev/null` =~ /Tx-Power=(\d+)/; + ($wifi_txpower) = `iwinfo wlan0 info 2>/dev/null` =~ /Tx-Power: (\d+)/; if (wifi_useschains()){ $wifi_txant = `cat /sys/kernel/debug/ieee80211/phy0/ath9k/tx_chainmask`; $wifi_rxant = `cat /sys/kernel/debug/ieee80211/phy0/ath9k/rx_chainmask`; @@ -146,7 +145,7 @@ if($parms{button_apply} or $parms{button_save}) $cmd .= "ifup wifi_mon >/dev/null 2>&1;"; } $cmd .= "iw phy phy0 set distance $wifi_distance >/dev/null 2>&1;"; - $cmd .= "iwconfig wlan0 txpower $wifi_txpower >/dev/null 2>&1;"; + $cmd .= "iw dev wlan0 set txpower fixed ${wifi_txpower}00 >/dev/null 2>&1;"; system $cmd; } diff --git a/files/www/cgi-bin/status b/files/www/cgi-bin/status index 35eef4cd..17055c95 100755 --- a/files/www/cgi-bin/status +++ b/files/www/cgi-bin/status @@ -1,10 +1,9 @@ -#!/usr/bin/perl - -$debug = 0; +#!/usr/bin/perl +$| = 1; +$debug = 1; BEGIN {push @INC, '/www/cgi-bin'}; use perlfunc; - # collect some variables $node = nvram_get("node"); $node = "NOCALL" if $node eq ""; @@ -212,7 +211,7 @@ push @col2, "system time" . `date +'%a %b %e %Y
%T % $uptime = `uptime`; $uptime =~ s/^ ..:..:.. up //; -($uptime, $load) = $uptime =~ /(.*), load average: (.*)/; +($uptime, $load) = $uptime =~ /(.*), load average: (.*)/; push @col2, "uptime
load average$uptime
$load"; $str = "free spaceflash = "; From 207c0f738f449b91e31ed702caad1f7e0bed3be8 Mon Sep 17 00:00:00 2001 From: Conrad Lara - KG6JEI Date: Fri, 2 May 2014 12:07:19 -0700 Subject: [PATCH 2/6] Adjust usage of wifi_txpoweroffset() to handle the fact that offset may be set already in iwinfo so we need to read that value first. Made adjustmetns to code that calls wifi_txpoweroffset() to ensure we minimize the number of calls that spawn a shell. Also adjust the setting of $wifi_txpower to handle the fact that iwinfo returns the known offset. --- files/www/cgi-bin/perlfunc.pm | 15 ++++++++++----- files/www/cgi-bin/setup | 4 +++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/files/www/cgi-bin/perlfunc.pm b/files/www/cgi-bin/perlfunc.pm index 50d0654c..6de86443 100644 --- a/files/www/cgi-bin/perlfunc.pm +++ b/files/www/cgi-bin/perlfunc.pm @@ -1189,13 +1189,18 @@ sub wifi_useschains #has increased it to a higher level. sub wifi_txpoweroffset { - - $boardinfo = hardware_info(); - if ( exists $boardinfo->{'pwroffset'} ) { - return $boardinfo->{'pwroffset'}; + my $myiwoffset=`iwinfo wlan0 info 2>/dev/null` =~ /TX power offset: (\d+)/; + if ( $myiwoffset ) { + return $myiwoffset; } else { - return 0; + $boardinfo = hardware_info(); + if ( exists $boardinfo->{'pwroffset'} ) { + return $boardinfo->{'pwroffset'}; + } else + { + return 0; + } } } diff --git a/files/www/cgi-bin/setup b/files/www/cgi-bin/setup index 720995d0..b220c607 100755 --- a/files/www/cgi-bin/setup +++ b/files/www/cgi-bin/setup @@ -95,6 +95,7 @@ $parms{dmz_dhcp_limit} = $dmz_dhcp_limit = $dmz_dhcp_end - $dmz_dhcp_start; unless($parms{reload}) { ($wifi_txpower) = `iwinfo wlan0 info 2>/dev/null` =~ /Tx-Power: (\d+)/; + $wifi_txpower -= wifi_txpoweroffset(); if (wifi_useschains()){ $wifi_txant = `cat /sys/kernel/debug/ieee80211/phy0/ath9k/tx_chainmask`; $wifi_rxant = `cat /sys/kernel/debug/ieee80211/phy0/ath9k/rx_chainmask`; @@ -552,7 +553,8 @@ if($wifi_proto ne "disabled") print "Tx Power\n"; print "\n"; print "Distance\n"; From e549afa190be1815b3de940305b39660315bdfa7 Mon Sep 17 00:00:00 2001 From: Conrad Lara - KG6JEI Date: Sun, 4 May 2014 14:28:03 -0700 Subject: [PATCH 3/6] Only subtract poweroffset when the value given by iwinfo has an offset applied --- files/www/cgi-bin/setup | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/files/www/cgi-bin/setup b/files/www/cgi-bin/setup index b220c607..6138c3c6 100755 --- a/files/www/cgi-bin/setup +++ b/files/www/cgi-bin/setup @@ -95,7 +95,10 @@ $parms{dmz_dhcp_limit} = $dmz_dhcp_limit = $dmz_dhcp_end - $dmz_dhcp_start; unless($parms{reload}) { ($wifi_txpower) = `iwinfo wlan0 info 2>/dev/null` =~ /Tx-Power: (\d+)/; - $wifi_txpower -= wifi_txpoweroffset(); + (my $iwoffset) = `iwinfo wlan0 info 2>/dev/null` =~ /TX power offset: (\d+)/; + if ( $iwoffset ) { + $wifi_txpower -= $iwoffset; + } if (wifi_useschains()){ $wifi_txant = `cat /sys/kernel/debug/ieee80211/phy0/ath9k/tx_chainmask`; $wifi_rxant = `cat /sys/kernel/debug/ieee80211/phy0/ath9k/rx_chainmask`; From 570901df2527ee485b09dbf9d5d5828a0a2b0fd3 Mon Sep 17 00:00:00 2001 From: Conrad Lara - KG6JEI Date: Sun, 4 May 2014 14:37:28 -0700 Subject: [PATCH 4/6] Disable debugging in status cgi script --- files/www/cgi-bin/status | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/files/www/cgi-bin/status b/files/www/cgi-bin/status index 17055c95..27853b23 100755 --- a/files/www/cgi-bin/status +++ b/files/www/cgi-bin/status @@ -1,7 +1,6 @@ #!/usr/bin/perl -$| = 1; -$debug = 1; +$debug = 0; BEGIN {push @INC, '/www/cgi-bin'}; use perlfunc; # collect some variables From d6bb48154a4b8b67332c68f339237acc07e25abf Mon Sep 17 00:00:00 2001 From: Conrad Lara - KG6JEI Date: Tue, 6 May 2014 14:29:19 -0700 Subject: [PATCH 5/6] Resolve issue related to returning the offset used by iwinfo --- files/www/cgi-bin/perlfunc.pm | 6 +++--- files/www/cgi-bin/setup | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/files/www/cgi-bin/perlfunc.pm b/files/www/cgi-bin/perlfunc.pm index 6de86443..30b7c7b6 100644 --- a/files/www/cgi-bin/perlfunc.pm +++ b/files/www/cgi-bin/perlfunc.pm @@ -1189,9 +1189,9 @@ sub wifi_useschains #has increased it to a higher level. sub wifi_txpoweroffset { - my $myiwoffset=`iwinfo wlan0 info 2>/dev/null` =~ /TX power offset: (\d+)/; - if ( $myiwoffset ) { - return $myiwoffset; + my $doesiwoffset=`iwinfo wlan0 info 2>/dev/null` =~ /TX power offset: (\d+)/; + if ( $doesiwoffset ) { + return $1; } else { $boardinfo = hardware_info(); diff --git a/files/www/cgi-bin/setup b/files/www/cgi-bin/setup index 6138c3c6..c4799ad4 100755 --- a/files/www/cgi-bin/setup +++ b/files/www/cgi-bin/setup @@ -95,9 +95,9 @@ $parms{dmz_dhcp_limit} = $dmz_dhcp_limit = $dmz_dhcp_end - $dmz_dhcp_start; unless($parms{reload}) { ($wifi_txpower) = `iwinfo wlan0 info 2>/dev/null` =~ /Tx-Power: (\d+)/; - (my $iwoffset) = `iwinfo wlan0 info 2>/dev/null` =~ /TX power offset: (\d+)/; - if ( $iwoffset ) { - $wifi_txpower -= $iwoffset; + (my $doesiwoffset) = `iwinfo wlan0 info 2>/dev/null` =~ /TX power offset: (\d+)/; + if ( $doesiwoffset ) { + $wifi_txpower -= $1; } if (wifi_useschains()){ $wifi_txant = `cat /sys/kernel/debug/ieee80211/phy0/ath9k/tx_chainmask`; From 064fc820789db3915a5d59f931296c52f12e0815 Mon Sep 17 00:00:00 2001 From: Conrad Lara - KG6JEI Date: Tue, 6 May 2014 14:58:42 -0700 Subject: [PATCH 6/6] permpackage and repo address setup. --- files/etc/opkg.conf | 2 +- files/etc/permpkg | 35 ++++++++++++++++++++++++----------- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/files/etc/opkg.conf b/files/etc/opkg.conf index c3b12abb..2a5c45e3 100644 --- a/files/etc/opkg.conf +++ b/files/etc/opkg.conf @@ -1,4 +1,4 @@ -src/gz packages http://www.broadband-hamnet.org/download/backfire/10.03.1/ar71xx/packages +src/gz packages http://www.broadband-hamnet.org/download/attitude_adjustment/12.09/ar71xx/generic/packages dest root / dest ram /tmp lists_dir ext /var/opkg-lists diff --git a/files/etc/permpkg b/files/etc/permpkg index bcbb2732..95c542e4 100644 --- a/files/etc/permpkg +++ b/files/etc/permpkg @@ -1,56 +1,66 @@ base-files bridge busybox -crda dnsmasq dropbear firewall hotplug2 +ip ip6tables iptables -iptables-mod-conntrack -iptables-mod-nat +iptables-mod-ipopt iw +iwinfo +jshn kernel kmod-ath kmod-ath9k kmod-ath9k-common -kmod-button-hotplug kmod-cfg80211 -kmod-crc-ccitt kmod-crypto-aes kmod-crypto-arc4 kmod-crypto-core -kmod-input-core -kmod-input-gpio-buttons -kmod-input-polldev +kmod-gpio-button-hotplug kmod-ip6tables kmod-ipt-conntrack kmod-ipt-core +kmod-ipt-ipopt kmod-ipt-nat kmod-ipt-nathelper kmod-ipv6 kmod-leds-gpio +kmod-ledtrig-default-on +kmod-ledtrig-netdev +kmod-ledtrig-timer +kmod-ledtrig-usbdev +kmod-lib-crc-ccitt kmod-mac80211 kmod-nls-base kmod-ppp kmod-pppoe +kmod-pppox kmod-usb-core kmod-usb-ohci kmod-usb-uhci kmod-usb2 +kmod-wdt-ath79 +libblobmsg-json libc libgcc libip4tc libip6tc +libiwinfo +libjson libnl-tiny libpcap libpthread librt +libubox +libubus libuci libxtables -microperl mtd +netifd ntpclient olsrd olsrd-mod-arprefresh @@ -58,6 +68,7 @@ olsrd-mod-dot-draw olsrd-mod-dyn-gw olsrd-mod-httpinfo olsrd-mod-nameservice +olsrd-mod-secure olsrd-mod-txtinfo olsrd-mod-watchdog opkg @@ -68,11 +79,13 @@ perlbase-perlio perlbase-xsloader ppp ppp-mod-pppoe +ssidident swconfig tcpdump-mini +uboot-envtools +ubus +ubusd uci -udevtrigger uhttpd -wireless-tools wpad-mini xinetd