--- mdap-server.pl 2007/04/24 17:02:41 32 +++ mdap-server.pl 2007/11/16 14:59:30 47 @@ -1,10 +1,14 @@ #!/usr/bin/perl +use warnings; use strict; use IO::Socket::Multicast; use Data::Dump qw/dump/; use Getopt::Long; +use lib './lib'; +use MDAP::ChangeIP; + my $GROUP = '224.0.0.103'; my $PORT = '3235'; @@ -16,6 +20,8 @@ my $resend_search_delay = 3; my $tftp_path = '/srv/tftp/'; +my $flashed_cmd = 'system config led=flash'; + GetOptions( "port=i" => \$PORT, "group=s" => \$GROUP, @@ -25,6 +31,7 @@ "search=i" => \$resend_search_delay, "tftp=s" => \$tftp_path, "credentials" => \$credentials, + "exec=s" => \$flashed_cmd, ); $quiet = 0 if $verbose; @@ -41,16 +48,17 @@ while(<$fh>) { chomp; next if /^#/ || /^$/ || /^\s+$/; - if (/^\S+\s\S+$/) { + if (/^\S+\s+\S+$/) { push @try_accounts, $_; } else { warn "invalid $passwd_path entry: $_\n"; } } - print "found ", $#try_accounts + 1, " accounts to try on password protected ants\n"; + print "found ", $#try_accounts + 1, " accounts to try on password protected ants", + $credentials ? " and display credentials" : "", "\n"; } -warn "search for ants every ${resend_search_delay}s\ntftp server path: $tftp_path\n"; +warn "search for ants every ${resend_search_delay}s\ntftp server path: $tftp_path\nflashed to current version: $flashed_cmd\n"; sub fw { my ($board, $offset,$len) = @_; @@ -200,7 +208,7 @@ next if ( $type =~ m#^(INFO|ANT-SEARCH|EXEC-CLI)# ); my $ant = $h->{'ANT-ID'} || die "no ANT-ID in ", dump( $h ); - my $seq_nr = $h->{'SEQ-NR'}; + my $seq_nr = $1 if (defined $h->{'SEQ-NR'} && $h->{'SEQ-NR'} =~ m/^-*(\d)+/); #warn "SEQ-NR: $seq_nr ok: ",$ant_ok_password->{$ant},"\n" if ($seq_nr); my ($user_id,$user_pwd) = ant_credentials( $ant ); @@ -230,16 +238,17 @@ if ( $build ne $new_build ) { print "+ $ant version $build -> $new_build\n"; mdap_send("EXEC-CLI MDAP/$mdap_ver\r\nCLI-CMD:software upgrade\r\nSEQ-NR:1\r\nTO-ANT:$ant\r\nUSER-ID:$user_id\r\nUSER-PWD:$user_pwd\r\n"); + $ant_flashing->{$ant}++; } else { once "$ant OK version $build", $ant_unknown_password->{$ant} ? ' with unknown password' : - $ant_ok_password->{$ant} ? ' password protected' : + $ant_passwd->{$ant} ? ' password protected' : '', "\n"; $ant_flashing->{$ant} = 0; # green|red|orange|flash|off - mdap_send("EXEC-CLI MDAP/$mdap_ver\r\nCLI-CMD:system config led=flash\r\nSEQ-NR:1\r\nTO-ANT:$ant\r\nUSER-ID:$user_id\r\nUSER-PWD:$user_pwd\r\n"); + mdap_send("EXEC-CLI MDAP/$mdap_ver\r\nCLI-CMD:$flashed_cmd\r\nSEQ-NR:1\r\nTO-ANT:$ant\r\nUSER-ID:$user_id\r\nUSER-PWD:$user_pwd\r\n"); my $waiting = 0; my $count = 0; map { @@ -256,15 +265,21 @@ } else { once "!! NO FIRMWARE for $board in $tftp_path for ant $ant, skipping update\n"; } + + if ( my $command = CWMP::ChangeIP::check( $h ) ) { + warn "## sending $command to $ant\n"; + mdap_send("EXEC-CLI MDAP/$mdap_ver\r\nCLI-CMD:$command\r\nSEQ-NR:1\r\nTO-ANT:$ant\r\nUSER-ID:$user_id\r\nUSER-PWD:$user_pwd\r\n"); + } + } elsif ( $type eq 'REPLY-EXEC-CLI' ) { + print "+ $type\n$data\n" if ($verbose); if ( $seq_nr == 1 ) { - 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"); - forget_ant( $ant ); - $ant_flashing->{$ant}++; - } elsif ( $seq_nr == 2 ) { - print "+ $ant led\n" if ($verbose); + forget_ant( $ant ) if ( $ant_flashing->{$ant} ); + } elsif ( $seq_nr < 0 ) { + warn "EXEC-CLI failed\n"; } + } else { print "!! reply $type ignored ", dump( $h ), $/; }