12 |
my $GROUP = '224.0.0.103'; |
my $GROUP = '224.0.0.103'; |
13 |
my $PORT = '3235'; |
my $PORT = '3235'; |
14 |
|
|
15 |
my $debug = 0; |
#my $debug = 0; # from MDAP |
16 |
my $quiet = 1; |
my $quiet = 1; |
17 |
my $verbose = 0; |
my $verbose = 0; |
18 |
my $credentials = 0; |
my $credentials = 0; |
101 |
return $hash; |
return $hash; |
102 |
} |
} |
103 |
|
|
104 |
|
sub _dump_data { |
105 |
|
my $data = shift; |
106 |
|
$data =~ s/\s+/ /gs; |
107 |
|
return substr($data,0,150); |
108 |
|
} |
109 |
|
|
110 |
sub mdap_send { |
sub mdap_send { |
111 |
my $data = shift; |
my $data = shift; |
112 |
|
|
118 |
if ($debug) { |
if ($debug) { |
119 |
warn ">> ${GROUP}:${PORT} >> ", dump( $data ), $/; |
warn ">> ${GROUP}:${PORT} >> ", dump( $data ), $/; |
120 |
} elsif( ! $quiet ) { |
} elsif( ! $quiet ) { |
121 |
$data =~ s/\s+/ /gi; |
warn ">> ",_dump_data($data),$/; |
|
warn ">> ", substr($data,0,70), $/; |
|
122 |
} |
} |
123 |
} |
} |
124 |
|
|
199 |
my $client_version = $h->{'MDAP-VERSION'}; |
my $client_version = $h->{'MDAP-VERSION'}; |
200 |
$mdap_ver = $client_version if ($client_version); |
$mdap_ver = $client_version if ($client_version); |
201 |
|
|
|
print "<< $type $proto/$mdap_ver << ", length($data), " bytes\n" unless $quiet; |
|
|
|
|
|
warn dump( $data, $h ),$/ if ($debug); |
|
|
|
|
202 |
# we are getting our own messages (since our source port |
# we are getting our own messages (since our source port |
203 |
# is same as destination) |
# is same as destination) |
204 |
next if ( $type =~ m#^(INFO|ANT-SEARCH|EXEC-CLI)# ); |
next if ( $type =~ m#^(INFO|ANT-SEARCH|EXEC-CLI)# ); |
205 |
|
|
206 |
|
print "<< $type $proto/$mdap_ver << ", length($data), " bytes: ",_dump_data($data),$/ unless $quiet; |
207 |
|
|
208 |
|
warn dump( $data, $h ),$/ if ($debug); |
209 |
|
|
210 |
my $ant = $h->{'ANT-ID'} || die "no ANT-ID in ", dump( $h ); |
my $ant = $h->{'ANT-ID'} || die "no ANT-ID in ", dump( $h ); |
211 |
my $seq_nr = $1 if (defined $h->{'SEQ-NR'} && $h->{'SEQ-NR'} =~ m/^-*(\d)+/); |
my $seq_nr = $1 if (defined $h->{'SEQ-NR'} && $h->{'SEQ-NR'} =~ m/^(-*\d)+/); |
212 |
#warn "SEQ-NR: $seq_nr ok: ",$ant_ok_password->{$ant},"\n" if ($seq_nr); |
#warn "SEQ-NR: $seq_nr ok: ",$ant_ok_password->{$ant},"\n" if ($seq_nr); |
213 |
|
|
214 |
my ($user_id,$user_pwd) = ant_credentials( $ant ); |
my ($user_id,$user_pwd) = ant_credentials( $ant ); |
234 |
my $board = $h->{'_BOARD_NAME'} || die "no _BOARD_NAME?"; |
my $board = $h->{'_BOARD_NAME'} || die "no _BOARD_NAME?"; |
235 |
if ( fw_exists( $board ) ) { |
if ( fw_exists( $board ) ) { |
236 |
my $build = $h->{'_BUILD'} || die "no _BUILD?"; |
my $build = $h->{'_BUILD'} || die "no _BUILD?"; |
237 |
|
$build =~ s/^(\d+)\.(\d+)\.(\d+)\.(\d+).*$/$1.$2.$3.$4/; |
238 |
my $new_build = fw_build( $board ); |
my $new_build = fw_build( $board ); |
239 |
if ( $build ne $new_build ) { |
if ( $build ne $new_build ) { |
240 |
print "+ $ant version $build -> $new_build\n"; |
print "+ $ant $board version $build -> $new_build\n"; |
241 |
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"); |
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"); |
242 |
$ant_flashing->{$ant}++; |
$ant_flashing->{$ant}++; |
243 |
|
next; |
244 |
} else { |
} else { |
245 |
once "$ant OK version $build", |
once "$ant $board OK version $build", |
246 |
$ant_unknown_password->{$ant} ? ' with unknown password' : |
$ant_unknown_password->{$ant} ? ' with unknown password' : |
247 |
$ant_passwd->{$ant} ? ' password protected' : |
$ant_passwd->{$ant} ? ' password protected' : |
248 |
''; |
''; |
257 |
$count++; |
$count++; |
258 |
} keys %$ant_flashing; |
} keys %$ant_flashing; |
259 |
if ($waiting == 0) { |
if ($waiting == 0) { |
260 |
status "ALL $count ANTS FLASHED to $build\n"; |
status "ALL $count ANTS FLASHED\n"; |
261 |
$ant_flashing = undef; |
$ant_flashing = undef; |
262 |
} else { |
} else { |
263 |
status "$waiting of $count ants still flasing upto $build\n"; |
status "$waiting of $count ants still flasing\n"; |
264 |
} |
} |
265 |
} |
} |
|
} else { |
|
|
once "!! NO FIRMWARE for $board in $tftp_path for ant $ant, skipping update"; |
|
|
} |
|
266 |
|
|
267 |
if ( $plugins ) { |
if ( $plugins ) { |
268 |
foreach my $plugin ( MDAP->plugins ) { |
foreach my $plugin ( MDAP->plugins ) { |
269 |
warn "## calling $plugin\n" if $debug; |
warn "## calling $plugin\n" if $debug; |
270 |
if ( my $command = $plugin->check( $h ) ) { |
if ( my $command = $plugin->check( $h ) ) { |
271 |
|
|
272 |
warn ">> $ant ", |
warn ">> $plugin $ant $board ", |
273 |
$h->{'ANT-NAME'}, " ", |
$h->{'ANT-NAME'}, " ", |
274 |
$h->{'_BUILD'}, " ", |
$h->{'_BUILD'}, " ", |
275 |
"\t:$command\n"; |
"\t:$command\n"; |
276 |
|
|
277 |
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"); } |
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"); |
278 |
|
last; |
279 |
|
} |
280 |
|
} |
281 |
} |
} |
282 |
|
|
283 |
|
} else { |
284 |
|
once "!! NO FIRMWARE for $board in $tftp_path for ant $ant, skipping update"; |
285 |
} |
} |
286 |
|
|
287 |
} elsif ( $type eq 'REPLY-EXEC-CLI' ) { |
} elsif ( $type eq 'REPLY-EXEC-CLI' ) { |
288 |
print "##<< $type\n$data\n" if $debug; |
print "##<< $type $seq_nr\n$data\n" if $debug; |
289 |
if ( $seq_nr == 1 ) { |
if ( $seq_nr == 1 ) { |
290 |
# 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"); |
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"); |
291 |
forget_ant( $ant ) if ( $ant_flashing->{$ant} ); |
forget_ant( $ant ) if ( $ant_flashing->{$ant} ); |
292 |
} elsif ( $seq_nr < 0 ) { |
} elsif ( $seq_nr < 0 ) { |
293 |
warn "EXEC-CLI failed: $data\n"; |
warn "EXEC-CLI failed: $data\n"; |