--- mdap-server.pl 2007/04/23 23:11:30 24 +++ mdap-server.pl 2007/04/24 10:11:24 29 @@ -104,6 +104,9 @@ } my $ant_passwd; +my $ant_unknown_password; +my $ant_ok_password; +my $ant_flashing; sub ant_credentials { my $ant = shift || die "no ant?"; @@ -113,24 +116,38 @@ return ($user_id,$user_pwd); } -my $ant_unknown_password; -my $ant_ok_password; +sub ant_unknown_password { + my $ant = shift || die "no ant?"; + if ( $ant_unknown_password->{$ant} ) { + $ant_unknown_password->{$ant}--; + } + return $ant_unknown_password->{$ant}; +} sub ant_another_passwd { my $ant = shift || die "no ant?"; - return 0 if ( $ant_unknown_password->{$ant} ); + + return 0 if ant_unknown_password( $ant ); + return 0 if $ant_ok_password->{$ant}; $ant_passwd->{$ant}++; if ( $ant_passwd->{$ant} > $#try_accounts ) { print "$ant ant with unknown password\n"; - $ant_unknown_password->{$ant}++; + $ant_unknown_password->{$ant} = 10; $ant_passwd->{$ant} = 0; return 0; } return 1; } +sub forget_ant { + my $ant = shift || die "no ant?"; + delete $ant_unknown_password->{$ant}; + delete $ant_passwd->{$ant}; + delete $ant_ok_password->{$ant}; +} + my $once; sub once { @@ -176,13 +193,14 @@ my ($user_id,$user_pwd) = ant_credentials( $ant ); if ($type eq 'REPLY-ANT-SEARCH') { - mdap_send("INFO MDAP/$mdap_ver\r\nSEQ-NR:1\r\nTO-ANT:$ant\r\nUSER-ID:$user_id\r\nUSER-PWD:$user_pwd\r\n") unless ( $ant_unknown_password->{$ant} ); + mdap_send("INFO MDAP/$mdap_ver\r\nSEQ-NR:1\r\nTO-ANT:$ant\r\nUSER-ID:$user_id\r\nUSER-PWD:$user_pwd\r\n") unless ant_unknown_password( $ant ); } elsif ($type eq 'REPLY-INFO') { if ( $seq_nr < 0 ) { - if ( $ant_ok_password ) { - $ant_ok_password->{$ant} = 0; - } elsif ( ant_another_passwd( $ant ) ) { +# if ( $ant_ok_password ) { +# $ant_ok_password->{$ant} = 0; +# } elsif ( ant_another_passwd( $ant ) ) { + if ( ant_another_passwd( $ant ) ) { ($user_id,$user_pwd) = ant_credentials( $ant ); mdap_send("INFO MDAP/$mdap_ver\r\nSEQ-NR:1\r\nTO-ANT:$ant\r\nUSER-ID:$user_id\r\nUSER-PWD:$user_pwd\r\n"); } @@ -204,16 +222,26 @@ $ant_ok_password->{$ant} ? ' password protected' : '', "\n"; + $ant_flashing->{$ant} = 0; + my $waiting = 0; + my $count = 0; + map { + $waiting++ if ($ant_flashing->{$_}); + $count++; + } keys %$ant_flashing; + if ($ant_flashing && $waiting == 0) { + print "**** ALL $count ANTS FLASHED ****\n"; + $ant_flashing = {}; + } } } else { once "!! NO FIRMWARE for $board in $tftp_path for ant $ant, skipping update\n"; } } elsif ( $type eq 'REPLY-EXEC-CLI' && $h->{'SEQ-NR'} == 1 ) { - print "+ $ant bootp mode re-flash started\n"; + print "+ $ant bootp mode re-flash started\n" if ($verbose); mdap_send("EXEC-CLI MDAP/$mdap_ver\r\nSEQ-NR:2\r\nTO-ANT:$ant\r\nUSER-ID:$user_id\r\nUSER-PWD:$user_pwd\r\n"); - $ant_unknown_password->{$ant} = 0; - $ant_passwd->{$ant} = 0; - $ant_ok_password->{$ant} = 0; + forget_ant( $ant ); + $ant_flashing->{$ant}++; } else { print "!! reply ignored ", dump( $h ), $/; }