associate_ap: fixes various regexes related to determining station association

This commit is contained in:
Jed Reynolds
2020-04-27 23:53:47 -07:00
parent 99631ec92d
commit 7ea9fd6933

View File

@@ -45,7 +45,7 @@ use Scalar::Util; #::looks_like_number;
use Getopt::Long; use Getopt::Long;
no warnings 'portable'; # Support for 64-bit ints required no warnings 'portable'; # Support for 64-bit ints required
use Socket; use Socket;
#use Data::Dumper;
our $binsleep = 0; our $binsleep = 0;
if ( -x "/bin/sleep" || -x "/usr/bin/sleep") { if ( -x "/bin/sleep" || -x "/usr/bin/sleep") {
$::binsleep = 1; $::binsleep = 1;
@@ -810,7 +810,7 @@ sub delete_port {
sub get_sta_state { sub get_sta_state {
my($rs_status) = @_; my($rs_status) = @_;
die("is_assoc_state: wants ref to status string") unless($rs_status); die("is_assoc_state: wants ref to status string") unless($rs_status);
my @lines = split(/\n/, $$rs_status); my @lines = split(/\r?\n/, $$rs_status);
my $careful = 0; my $careful = 0;
my $name = "unknown"; my $name = "unknown";
my $ip = "0.0.0.0"; my $ip = "0.0.0.0";
@@ -823,38 +823,44 @@ sub get_sta_state {
my $mask; my $mask;
my $channel; my $channel;
my $mode; my $mode;
my $probed_seen = 0;
for my $line (@lines) { for my $line (@lines) {
$first = "_"; $first = "_";
$line =~ m/^\s+(\S+?:)\s+/; my($key) = $line =~ m/^\s*([^:]+:)\s+/;
#print "}}}} $line\n"; #print "{{{$key}}} $line\n";
if ($1 && $1 eq "MAC:" ) { next if ($line =~ /^\s*$/);
next if ($line =~ /RSLT:/);
last if ($line =~ /default@/);
$probed_seen++ if ($line =~ /Probed/);
if ($key && $key eq "MAC:" ) {
@hunks = split(/: /, $line); @hunks = split(/: /, $line);
$mac = (split(/ /, $hunks[1]))[0]; $mac = (split(/ /, $hunks[1]))[0];
$name = (split(/ /, $hunks[2]))[0]; $name = (split(/ /, $hunks[2]))[0];
next; next;
} }
if ($1 && $1 eq "IP:") { if ($key && $key eq "IP:") {
@hunks = split(/: /, $line); @hunks = split(/: /, $line);
$ip = (split(/ /, $hunks[1]))[0]; $ip = (split(/ /, $hunks[1]))[0];
$mask = (split(/ /, $hunks[2]))[0]; $mask = (split(/ /, $hunks[2]))[0];
$gw = (split(/ /, $hunks[3]))[0]; $gw = (split(/ /, $hunks[3]))[0];
next; next;
} }
if ($1 && $1 eq "Probed:") { if ($probed_seen && ($line =~ /Mode:/)) {
@hunks = split(/: /, $line); @hunks = split(/: /, $line);
$careful = 1; $careful = 1;
$mode = (split(/ /, $hunks[2]))[0]; $mode = (split(/ /, $hunks[2]))[0];
next; next;
} }
if( $careful && $1 eq "Channel:" ) { if( $probed_seen && $careful && ($key eq "Channel:")) {
@hunks = split(/: /, $line); @hunks = split(/: /, $line);
#print Dumper(\@hunks);
$channel = (split(/ /, $hunks[1]))[0]; $channel = (split(/ /, $hunks[1]))[0];
$freq = (split(/ /, $hunks[3]))[0]; $freq = (split(/ /, $hunks[3]))[0];
if ((@hunks > 3) && (defined $hunks[4])) { if ((@hunks > 3) && (defined $hunks[4])) {
$assoc = (split(/ /, $hunks[4]))[0]; $assoc = (split(/ /, $hunks[4]))[0];
} }
#print " assoc:".$assoc;
last;
} }
} }
my %rv = ( my %rv = (
@@ -866,6 +872,7 @@ sub get_sta_state {
"mac" => $mac, "mac" => $mac,
"mode" => $mode, "mode" => $mode,
"name" => $name ); "name" => $name );
#print Dumper(\%rv);
return %rv; return %rv;
} }
@@ -931,9 +938,10 @@ sub awaitNewStations {
my @not_assoc = (); my @not_assoc = ();
for my $sta_name (sort(keys(%::sta_names))) { for my $sta_name (sort(keys(%::sta_names))) {
my $status = $::utils->doAsyncCmd($::utils->fmt_cmd("show_port", 1, $::resource, $sta_name)); my $status = $::utils->doAsyncCmd($::utils->fmt_cmd("show_port", 1, $::resource, $sta_name));
#print "STATUS: $status\n\n";
my %sta_status = get_sta_state(\$status); my %sta_status = get_sta_state(\$status);
#print " $sta_name ".$sta_status{"assoc"}; #print " $sta_name ".$sta_status{"assoc"};
if( $sta_status{"assoc"} ne "Not-Associated") { if( $sta_status{"assoc"} !~ /NA|Not-Associated|unknown/) {
push(@are_assoc, $sta_name); push(@are_assoc, $sta_name);
} }
else { else {
@@ -946,6 +954,7 @@ sub awaitNewStations {
print " Associated:".join(", ", @are_assoc)."\n"; print " Associated:".join(", ", @are_assoc)."\n";
print " Pending :".join(", ", @not_assoc)."\n"; print " Pending :".join(", ", @not_assoc)."\n";
} }
sleep 1;
} # ~while } # ~while
} }
@@ -1345,7 +1354,7 @@ sub doStep_2 {
my $status = $::utils->doAsyncCmd($::utils->fmt_cmd("show_port", 1, $::resource, $sta_name)); my $status = $::utils->doAsyncCmd($::utils->fmt_cmd("show_port", 1, $::resource, $sta_name));
my %state = get_sta_state(\$status); my %state = get_sta_state(\$status);
#print $state{"name"}.": ".$state{"assoc"}." "; #print $state{"name"}.": ".$state{"assoc"}." ";
$num_assoc++ if($state{"assoc"} ne "Not-Associated"); $num_assoc++ if( $state{"assoc"} !~ /NA|Not-Associated|unknown/);
#print $state{"ip"}."/".$state{"mask"}." gw:".$state{"gw"}."\n"; #print $state{"ip"}."/".$state{"mask"}." gw:".$state{"gw"}."\n";
$num_ip++ if($state{"ip"} ne "0.0.0.0" ); $num_ip++ if($state{"ip"} ne "0.0.0.0" );
} }