|
From: Ivan D. <idr...@us...> - 2006-06-15 00:41:06
|
Update of /cvsroot/terk/embed/src/scripts In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv13687/src/scripts Modified Files: autoconnect.pl robot.init config.wlan0.default wifiConnect.pl Log Message: Redesigned network connection procedure. Includes reading config files, WEP, and more reliable pinging. Removed calls to getIP. Index: config.wlan0.default =================================================================== RCS file: /cvsroot/terk/embed/src/scripts/config.wlan0.default,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** config.wlan0.default 24 Apr 2006 19:00:55 -0000 1.1 --- config.wlan0.default 15 Jun 2006 00:40:58 -0000 1.2 *************** *** 1,4 **** ! auto=true ! dataEncryption=false ! ssid=CMU ! networkKey= --- 1,4 ---- ! auto=true ! dataEncryption=false ! ssid=CMU ! networkKey= Index: robot.init =================================================================== RCS file: /cvsroot/terk/embed/src/scripts/robot.init,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** robot.init 13 Jun 2006 20:44:06 -0000 1.21 --- robot.init 15 Jun 2006 00:40:58 -0000 1.22 *************** *** 10,13 **** --- 10,14 ---- mv /opt/connectlog0.txt /opt/connectlog1.txt + echo `date +%R:%S` Robot.init started. >> /opt/connectlog0.txt echo `date +%R:%S` Copied logs. >> /opt/connectlog0.txt *************** *** 19,22 **** --- 20,25 ---- insmod /opt/drivers/qemotor.ko >> /opt/connectlog0.txt + mount -t nfs -o nolock 192.168.1.103:/edbnfs /mnt >> /opt/connect.log #Mount edbnfs folder + #################### Stage 0.1: Generate Unique mubers, checking for CFG ########################### *************** *** 60,77 **** ln -s /opt/connectlog4.txt /home/www/connectlog4.txt ! #################### Stage 1 & 2: Network Connect##################################################### /opt/bin/setLEDs ! /opt/scripts/wifiConnect.pl wlan0 >> /opt/connect.log ! /opt/scripts/wiredConnect.pl eth0 >> /opt/connect.log ! udhcpc -i wlan0 -b -p /var/run/udhcpc.wlan0 >/dev/null 2>&1 >> /opt/connect.log ! mount -t nfs -o nolock 192.168.1.103:/edbnfs /mnt >> /opt/connect.log ! sleep 5; ! /opt/scripts/waitForPing.pl 128.2.211.159 >> /opt/connect.log cd /opt/ice --- 63,80 ---- ln -s /opt/connectlog4.txt /home/www/connectlog4.txt ! #################### Stage 1 & 2: Network Connect #################################################### /opt/bin/setLEDs ! echo `date +%R:%S` Connecting to the network... >> /opt/connectlog0.txt ! /opt/scripts/wiredConnect.pl eth0 ! /opt/scripts/wifiConnect.pl wlan0 ! udhcpc -i wlan0 -b -p /var/run/udhcpc.wlan0 >/dev/null 2>&1 ! /opt/scripts/tryGateways.pl ! ################### Stage X: Start Terk Server ####################################################### cd /opt/ice Index: wifiConnect.pl =================================================================== RCS file: /cvsroot/terk/embed/src/scripts/wifiConnect.pl,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** wifiConnect.pl 13 Jun 2006 20:44:06 -0000 1.7 --- wifiConnect.pl 15 Jun 2006 00:40:58 -0000 1.8 *************** *** 34,45 **** } ! $ssid = $Config{"ssid"}; ! $networkKey = $Config{"networkKey"}; open(WLANCTL, "/sbin/wlanctl-ng ${INTERFACE} lnxreq_ifstate ifstate=enable |"); open(WLANCTL, "/sbin/wlanctl-ng ${INTERFACE} dot11req_mibset mibattribute=p2CnfShortPreamble=long |"); - if ($Config{"auto"} =~ m/true/){ print LOG "\tUsing autoconnect\n"; open(SCAN, "/opt/scripts/scan.pl |") or die "Cannot run scan.pl $!\n"; --- 34,66 ---- } ! ###################### print config settings ########################### ! ! print LOG "\tLoading config settings...\n"; ! print LOG "\t--------------------------\n"; ! ! $auto = $Config{"auto"}; ! $ssid = $Config{"ssid"}; ! $dataEncryption = $Config{"dataEncryption"}; ! $networkKey = $Config{"networkKey"}; ! ! if($auto eq 'true'){ ! print LOG "\tauto=true\n"; ! } else { ! print LOG "\tauto=false\n"; ! } ! ! print LOG "\tssid = $ssid\n"; ! print LOG "\tdataEncryption = $dataEncryption\n"; ! print LOG "\tnetworkKey = $networkKey\n"; ! ! ################### start connecting #################################### open(WLANCTL, "/sbin/wlanctl-ng ${INTERFACE} lnxreq_ifstate ifstate=enable |"); open(WLANCTL, "/sbin/wlanctl-ng ${INTERFACE} dot11req_mibset mibattribute=p2CnfShortPreamble=long |"); + if ($auto =~ m/true/) + { + ##################### autoconnect ########################### print LOG "\tUsing autoconnect\n"; open(SCAN, "/opt/scripts/scan.pl |") or die "Cannot run scan.pl $!\n"; *************** *** 50,72 **** print LOG "\t$_ \n"; } ! } else { ! if($Config{"dataEncryption"} =~ m/wep/){ ! print LOG "\tConnecting using encryption to $ssid\n"; ! open(WLANCTL, "/sbin/wlanctl-ng ${INTERFACE} dot11req_mibset mibattribute=dot11WEPDefaultKey=$networkKey |"); ! open(WLANCTL, "/sbin/wlanctl-ng ${INTERFACE} dot11req_mibset mibattribute=dot11WEPDefaultKeyID=0 |"); ! open(WLANCTL, "/sbin/wlanctl-ng ${INTERFACE} dot11req_mibset mibattribute=dot11ExcludeUnencrypted=true |"); ! open(WLANCTL, "/sbin/wlanctl-ng ${INTERFACE} lnxreq_autojoin ssid=$ssid authtype=opensystem |"); ! ! } else { ! print LOG "\tConnecting unencrypted to $ssid\n"; ! open(WLANCTL, "/sbin/wlanctl-ng ${INTERFACE} lnxreq_autojoin ssid=$ssid authtype=opensystem |"); } ! # open(SETLEDS, "/opt/bin/setLEDs 0 1 2 3 4 5|"); ! # sleep 1; ! # open(SETLEDS, "/opt/bin/setLEDs 0|"); ! # sleep 1; ! # open(SETLEDS, "/opt/bin/setLEDs 0 1 2 3 4 5|"); } --- 71,143 ---- print LOG "\t$_ \n"; } + } + else + { + if ($dataEncryption eq "Disabled") + { + ############### connect to a specific SSID, no WEP ########## ! print LOG "\tConnecting unencrypted to $ssid\n"; ! open(WLANCTL, "/sbin/wlanctl-ng ${INTERFACE} lnxreq_autojoin ssid=$ssid authtype=opensystem |"); } + else + { + ############## connect to a specific SSID, using WEP ####### ! print LOG "\tConnecting using $networkKey to $ssid\n"; ! ! open(WLANCTL, "/sbin/wlanctl-ng ${INTERFACE} lnxreq_autojoin ssid=$ssid authtype=opensystem |"); ! open(WLANCTL, "/sbin/wlanctl-ng ${INTERFACE} lnxreq_hostwep encrypt=true decrypt=true |"); ! open(WLANCTL, "/sbin/wlanctl-ng ${INTERFACE} dot11req_mibset mibattribute=dot11PrivacyInvoked=true |"); ! open(WLANCTL, "/sbin/wlanctl-ng ${INTERFACE} dot11req_mibset mibattribute=dot11WEPDefaultKeyID=0 |"); ! open(WLANCTL, "/sbin/wlanctl-ng ${INTERFACE} dot11req_mibset mibattribute=dot11WEPDefaultKey0=$networkKey |"); ! } ! ! ################## ping to verify ############################## ! ! $pkts_sent = 0; ! $pkts_rcvd = 0; ! $max = 0; ! ! open (PING, "/bin/ping -c 4 128.2.211.159 |"); ! ! while (<PING>) { ! if (/^(\d+) packets transmitted, (\d+) /) { ! $pkts_sent = $1; ! $pkts_rcvd = $2; ! } ! elsif (/(\d+\.?\d*)\/(\d+\.?\d*)\/(\d+\.?\d*)/) { #look for num/num/num ! $min = $1; ! $avg = $2; ! $max = $3; ! } ! elsif (/^(\d+).*seq=(\d+).*ttl=(\d+).*time=(\d+\.?\d*) ms/) { ! # look for packet size seq=NN and time=NN ! $pkt_size[$pingI]=$1; ! $seq[$pingI]=$2; ! $ttl[$pingI]=$3; ! $rtt[$pingI]=$4; ! $pingI++; ! } ! elsif (/^(\d+).*seq=(\d+).*ttl=(\d+).*time=(\d+\.?\d*) usec/) { ! # look for packet size seq=NN and time=NN ! $pkt_size[$pingI]=$1; ! $seq[$pingI]=$2; ! $ttl[$pingI]=$3; ! $rtt[$pingI]=$4/1000; ! $pingI++; ! } ! elsif( /^interval: (\d+\.?\d*)/ ) { ! $interval = $1; ! } ! } ! ! close (PING); ! ! if($pkts_rcvd == 0){ ! print LOG "\tSuccessfully connected!\n"; ! } else { ! print LOG "\tPing test failed. Not connected\n"; ! } } Index: autoconnect.pl =================================================================== RCS file: /cvsroot/terk/embed/src/scripts/autoconnect.pl,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** autoconnect.pl 13 Jun 2006 20:44:06 -0000 1.12 --- autoconnect.pl 15 Jun 2006 00:40:58 -0000 1.13 *************** *** 19,37 **** if($_ =~ m/\berror\b/) { print LOG "\tNo wlan0!\n"; ! print LOG "\t$_\n"; ! #open(LED, "/opt/bin/setLEDs 0 1 2 3 4 5 6 7 |") or die "Cannot set LED $!\n"; ! #sleep 1; ! #open(LED, "/opt/bin/setLEDs |") or die "Cannot set LED $!\n"; ! #sleep 1; ! #open(LED, "/opt/bin/setLEDs 0 1 2 3 4 5 6 7 |") or die "Cannot set LED $!\n"; ! #sleep 1; ! #open(LED, "/opt/bin/setLEDs |") or die "Cannot set LED $!\n"; close(LOG); exit; } } - - #open(LED, "/opt/bin/setLEDs 0 |") or die "Cannot set LED $!\n"; print LOG "\tTrying the various access points:\n"; --- 19,30 ---- if($_ =~ m/\berror\b/) { print LOG "\tNo wlan0!\n"; ! print LOG "\t$_\n"; close(LOG); exit; } } + ############################# load results ################################# + print LOG "\tTrying the various access points:\n"; *************** *** 57,69 **** $connect_success = 0; ! ! print LOG "\tbssid: $bssid ssid: $ssid\n"; ! ! if($ssid eq "no_value"){ ! } else { ! #open(LED, "/opt/bin/setLEDs|") or die "Cannot set LED $!\n"; ! #sleep .2; ! #open(LED, "/opt/bin/setLEDs 0|") or die "Cannot set LED $!\n"; open (CONNECT, "/sbin/wlanctl-ng wlan0 lnxreq_autojoin ssid=$ssid authtype=opensystem |") or die "Cannot open connect $!\n"; --- 50,66 ---- $connect_success = 0; ! ! if($ssid eq "no_value" || $ssid eq ""){ ! $Results[$index]{ping_success} = "bad"; ! } ! else { + ############################ connect ################################## + + ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time); + + printf LOG "\t%02d:%02d:%02d ", $hour, $min, $sec; + print LOG "trying network: $ssid\n"; + open (CONNECT, "/sbin/wlanctl-ng wlan0 lnxreq_autojoin ssid=$ssid authtype=opensystem |") or die "Cannot open connect $!\n"; *************** *** 76,122 **** my ($var, $value) = split(/\s*=\s*/, $_, 2); $value =~ tr/'//d; ! $CONNECT_Result{$var} = $value; ! # print LOG "\tvar $var is $value\n"; } close CONNECT; ! open(PSAUX, "/bin/ps |") or die "Cannot run /bin/ps $!\n"; ! while(<PSAUX>) { ! if($_ =~ /wlan0/ && $_ =~ /udhcpc/){ ! chomp; ! @entry = split(' '); ! $pid = $entry[0]; ! print LOG "\tkilling udhcpc pid $pid\n"; ! open (KILLUDHCPC, "/bin/kill $pid |") or die "Cannot kill udhcpc $!\n"; ! } ! } ! ! sleep 1; open (RENEW, "/sbin/udhcpc -nq -i wlan0|") or die "Cannot send renew signal to udhcpc $!\n"; ! # open (RENEW, "/bin/kill -SIGUSR1 $pid |") or die "Cannot send renew signal to udhcpc $!\n"; ! sleep 1; ! open(IPGRAB, "/opt/scripts/getIP.pl wlan0 |"); ! while(<IPGRAB>){ ! chomp; ! $ip = $_; ! } ! $pkts_sent = 0; ! $pkts_rcvd = 0; ! $max = 0; ! if($ip){ ! print LOG "\tGot: $ip \n"; ! open (PING, "/bin/ping -c 4 128.2.211.159 |"); while (<PING>) { - # print "$_"; if (/^(\d+) packets transmitted, (\d+) /) { ! $pkts_sent = $1; ! $pkts_rcvd = $2; } elsif (/(\d+\.?\d*)\/(\d+\.?\d*)\/(\d+\.?\d*)/) { #look for num/num/num --- 73,115 ---- my ($var, $value) = split(/\s*=\s*/, $_, 2); $value =~ tr/'//d; ! $CONNECT_Result{$var} = $value; ! # print LOG "\t\tvar $var is $value\n"; } close CONNECT; ! #open(PSAUX, "/bin/ps |") or die "Cannot run /bin/ps $!\n"; ! #while(<PSAUX>) { ! # if($_ =~ /wlan0/ && $_ =~ /udhcpc/){ ! # chomp; ! # @entry = split(' '); ! # $pid = $entry[0]; ! # print LOG "\t\tkilling udhcpc pid $pid\n"; ! # open (KILLUDHCPC, "/bin/kill $pid |") or die "Cannot kill udhcpc $!\n"; ! # } ! #} ! #sleep 1; open (RENEW, "/sbin/udhcpc -nq -i wlan0|") or die "Cannot send renew signal to udhcpc $!\n"; ! #sleep 1; ! #open(IPGRAB, "/opt/scripts/getIP.pl wlan0 |"); ! #while(<IPGRAB>){ ! # chomp; ! # $ip = $_; ! #} ! ############################### ping ############################################## ! $pkts_sent = 0; ! $pkts_rcvd = 0; ! $max = 0; ! open (PING, "/bin/ping -c 3 128.2.211.159 |"); while (<PING>) { if (/^(\d+) packets transmitted, (\d+) /) { ! $pkts_sent = $1; ! $pkts_rcvd = $2; } elsif (/(\d+\.?\d*)\/(\d+\.?\d*)\/(\d+\.?\d*)/) { #look for num/num/num *************** *** 132,136 **** $rtt[$pingI]=$4; $pingI++; ! } elsif (/^(\d+).*seq=(\d+).*ttl=(\d+).*time=(\d+\.?\d*) usec/) { # look for packet size seq=NN and time=NN $pkt_size[$pingI]=$1; --- 125,130 ---- $rtt[$pingI]=$4; $pingI++; ! } ! elsif (/^(\d+).*seq=(\d+).*ttl=(\d+).*time=(\d+\.?\d*) usec/) { # look for packet size seq=NN and time=NN $pkt_size[$pingI]=$1; *************** *** 144,152 **** } } close (PING); ! print LOG "\tpackets sent: $pkts_sent packets received: $pkts_rcvd\n"; ! print LOG "\tmax response time was: $max\n"; ! } if($pkts_rcvd == 0){ --- 138,146 ---- } } + close (PING); ! # print LOG "\tpackets sent: $pkts_sent packets received: $pkts_rcvd\n"; ! # print LOG "\tmax response time was: $max\n"; if($pkts_rcvd == 0){ *************** *** 160,163 **** --- 154,159 ---- } + ################################ order by ping results ##################################### + @ordered = sort { $b->{pkts_rcvd} <=> $a->{pkts_rcvd} || $b->{signal} <=> $a->{signal} } @Results; *************** *** 166,170 **** printf LOG "\n\t%02d:%02d:%02d ", $hour, $min, $sec; print LOG "Results in order of preference: \n\n"; ! for $ref (@ordered){ $ossid = $ref->{ssid}; --- 162,168 ---- printf LOG "\n\t%02d:%02d:%02d ", $hour, $min, $sec; print LOG "Results in order of preference: \n\n"; ! print LOG "\tstatus\tpackets\tsignal\tnoise\tSSID\n"; ! print LOG "\t-------------------------------------\n"; ! for $ref (@ordered){ $ossid = $ref->{ssid}; *************** *** 173,185 **** $osignal = $ref->{signal} - 65400; $onoise = $ref->{noise} - 65400; ! print LOG "\t$obssid $opkts_rcvd $osignal $onoise $ossid\n"; } $best_ssid = $ordered[0]{ssid}; if($ordered[0]{ping_success} eq "good"){ - #open(LED, "/opt/bin/setLEDs 0 1 |") or die "Cannot set LED $!\n"; ! print LOG "\tConnecting to ssid: $best_ssid\n"; open (FINAL_CONNECT, "/sbin/wlanctl-ng wlan0 lnxreq_autojoin ssid=$best_ssid authtype=opensystem |") or die "Cannot open connect $!\n"; --- 171,185 ---- $osignal = $ref->{signal} - 65400; $onoise = $ref->{noise} - 65400; ! $oping_success = $ref->{ping_success}; ! print LOG "\t$oping_success\t$opkts_rcvd\t$osignal\t$onoise\t$ossid\n"; } $best_ssid = $ordered[0]{ssid}; + ############################# connect to best ################################################# + if($ordered[0]{ping_success} eq "good"){ ! print LOG "\n\tFound available network! Connecting to ssid: $best_ssid\n"; open (FINAL_CONNECT, "/sbin/wlanctl-ng wlan0 lnxreq_autojoin ssid=$best_ssid authtype=opensystem |") or die "Cannot open connect $!\n"; *************** *** 194,198 **** $value =~ tr/'//d; $FINAL_CONNECT_Result{$var} = $value; ! # print "var $var is $value\n"; } --- 194,198 ---- $value =~ tr/'//d; $FINAL_CONNECT_Result{$var} = $value; ! # print "var $var is $value\n"; } *************** *** 210,239 **** if($FINAL_CONNECT_Result{resultcode} eq "success"){ print LOG "\tSuccessfully connected\n"; - - #open(LED, "/opt/bin/setLEDs 0|") or die "Cannot set LED $!\n"; - #sleep .2; - #open(LED, "/opt/bin/setLEDs 0 1|") or die "Cannot set LED $!\n"; - #sleep .2; - #open(LED, "/opt/bin/setLEDs 0 1 2|") or die "Cannot set LED $!\n"; - #sleep .2; - #open(LED, "/opt/bin/setLEDs 0 1 2 3|") or die "Cannot set LED $!\n"; - #sleep .2; - #open(LED, "/opt/bin/setLEDs 0 1 2 3 4|") or die "Cannot set LED $!\n"; - #sleep .2; - #open(LED, "/opt/bin/setLEDs 0 1 2 3 4 5|") or die "Cannot set LED $!\n"; - #sleep .2; close(LOG); exit 0; } } ! ! print LOG "\tNo valid networks\n"; ! #open(LED, "/opt/bin/setLEDs 0 1 2 3 4 5 6 7 |") or die "Cannot set LED $!\n"; ! #sleep 1; ! #open(LED, "/opt/bin/setLEDs |") or die "Cannot set LED $!\n"; ! #sleep 1; ! #open(LED, "/opt/bin/setLEDs 0 1 2 3 4 5 6 7 |") or die "Cannot set LED $!\n"; ! #sleep 1; ! #open(LED, "/opt/bin/setLEDs |") or die "Cannot set LED $!\n"; close(LOG); --- 210,222 ---- if($FINAL_CONNECT_Result{resultcode} eq "success"){ print LOG "\tSuccessfully connected\n"; close(LOG); exit 0; + }else{ + print LOG "\tNot successfully connected\n"; } } ! else{ ! print LOG "\n\tNo valid networks found.\n"; ! } close(LOG); |