104 |
} |
} |
105 |
|
|
106 |
my $ant_passwd; |
my $ant_passwd; |
107 |
|
my $ant_unknown_password; |
108 |
|
my $ant_ok_password; |
109 |
|
my $ant_flashing; |
110 |
|
|
111 |
sub ant_credentials { |
sub ant_credentials { |
112 |
my $ant = shift || die "no ant?"; |
my $ant = shift || die "no ant?"; |
116 |
return ($user_id,$user_pwd); |
return ($user_id,$user_pwd); |
117 |
} |
} |
118 |
|
|
119 |
my $ant_password_protected; |
sub ant_unknown_password { |
120 |
|
my $ant = shift || die "no ant?"; |
121 |
|
if ( $ant_unknown_password->{$ant} ) { |
122 |
|
$ant_unknown_password->{$ant}--; |
123 |
|
} |
124 |
|
return $ant_unknown_password->{$ant}; |
125 |
|
} |
126 |
|
|
127 |
sub ant_another_passwd { |
sub ant_another_passwd { |
128 |
my $ant = shift || die "no ant?"; |
my $ant = shift || die "no ant?"; |
129 |
return if ( $ant_password_protected->{$ant} ); |
|
130 |
|
return 0 if ant_unknown_password( $ant ); |
131 |
|
return 0 if $ant_ok_password->{$ant}; |
132 |
|
|
133 |
$ant_passwd->{$ant}++; |
$ant_passwd->{$ant}++; |
134 |
|
|
135 |
if ( $ant_passwd->{$ant} > $#try_accounts ) { |
if ( $ant_passwd->{$ant} > $#try_accounts ) { |
136 |
print "!! ant $ant password protected\n"; |
print "$ant ant with unknown password\n"; |
137 |
$ant_password_protected->{$ant}++; |
$ant_unknown_password->{$ant} = 10; |
138 |
|
$ant_passwd->{$ant} = 0; |
139 |
return 0; |
return 0; |
140 |
} |
} |
141 |
return 1; |
return 1; |
142 |
} |
} |
143 |
|
|
144 |
|
sub forget_ant { |
145 |
|
my $ant = shift || die "no ant?"; |
146 |
|
delete $ant_unknown_password->{$ant}; |
147 |
|
delete $ant_passwd->{$ant}; |
148 |
|
delete $ant_ok_password->{$ant}; |
149 |
|
} |
150 |
|
|
151 |
my $once; |
my $once; |
152 |
|
|
153 |
sub once { |
sub once { |
154 |
my $m = join(" ", @_); |
my $m = join('', @_); |
155 |
$once->{$m}++; |
$once->{$m}++; |
156 |
print $m if ($once->{$m} == 1); |
print $m if ($once->{$m} == 1); |
157 |
} |
} |
158 |
|
|
159 |
|
my $status = ''; |
160 |
|
|
161 |
|
sub status { |
162 |
|
my $m = join('', @_); |
163 |
|
if ($m ne $status) { |
164 |
|
print $m; |
165 |
|
$status = $m; |
166 |
|
} |
167 |
|
} |
168 |
|
|
169 |
local $SIG{ALRM} = sub { |
local $SIG{ALRM} = sub { |
170 |
mdap_send("ANT-SEARCH MDAP/1.1\r\n"); |
mdap_send("ANT-SEARCH MDAP/1.1\r\n"); |
171 |
alarm( $resend_search_delay ); |
alarm( $resend_search_delay ); |
197 |
next if ( $type =~ m#^(INFO|ANT-SEARCH|EXEC-CLI)# ); |
next if ( $type =~ m#^(INFO|ANT-SEARCH|EXEC-CLI)# ); |
198 |
|
|
199 |
my $ant = $h->{'ANT-ID'} || die "no ANT-ID in ", dump( $h ); |
my $ant = $h->{'ANT-ID'} || die "no ANT-ID in ", dump( $h ); |
200 |
|
my $seq_nr = $h->{'SEQ-NR'}; |
201 |
|
#warn "SEQ-NR: $seq_nr ok: ",$ant_ok_password->{$ant},"\n" if ($seq_nr); |
202 |
|
|
203 |
my ($user_id,$user_pwd) = ant_credentials( $ant ); |
my ($user_id,$user_pwd) = ant_credentials( $ant ); |
204 |
|
|
205 |
if ($type eq 'REPLY-ANT-SEARCH') { |
if ($type eq 'REPLY-ANT-SEARCH') { |
206 |
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_password_protected->{$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 ); |
207 |
} elsif ($type eq 'REPLY-INFO') { |
} elsif ($type eq 'REPLY-INFO') { |
208 |
|
|
209 |
if ($h->{'SEQ-NR'} < 0) { |
if ( $seq_nr < 0 ) { |
210 |
|
# if ( $ant_ok_password ) { |
211 |
|
# $ant_ok_password->{$ant} = 0; |
212 |
|
# } elsif ( ant_another_passwd( $ant ) ) { |
213 |
if ( ant_another_passwd( $ant ) ) { |
if ( ant_another_passwd( $ant ) ) { |
214 |
my ($user_id,$user_pwd) = ant_credentials( $ant ); |
($user_id,$user_pwd) = ant_credentials( $ant ); |
215 |
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"); |
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"); |
216 |
} |
} |
217 |
next; |
next; |
218 |
|
} else { |
219 |
|
$ant_ok_password->{$ant}++; |
220 |
} |
} |
221 |
|
|
222 |
my $board = $h->{'_BOARD_NAME'} || die "no _BOARD_NAME?"; |
my $board = $h->{'_BOARD_NAME'} || die "no _BOARD_NAME?"; |
224 |
my $build = $h->{'_BUILD'} || die "no _BUILD?"; |
my $build = $h->{'_BUILD'} || die "no _BUILD?"; |
225 |
my $new_build = fw_build( $board ); |
my $new_build = fw_build( $board ); |
226 |
if ( $build ne $new_build ) { |
if ( $build ne $new_build ) { |
227 |
print "UPDATE STEP 1 on ant $ant version $build -> $new_build\n"; |
print "+ $ant version $build -> $new_build\n"; |
228 |
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"); |
229 |
} else { |
} else { |
230 |
once "OK ant $ant has $build\n"; |
once "$ant OK version $build", |
231 |
|
$ant_unknown_password->{$ant} ? ' with unknown password' : |
232 |
|
$ant_ok_password->{$ant} ? ' password protected' : |
233 |
|
'', |
234 |
|
"\n"; |
235 |
|
$ant_flashing->{$ant} = 0; |
236 |
|
my $waiting = 0; |
237 |
|
my $count = 0; |
238 |
|
map { |
239 |
|
$waiting++ if ($ant_flashing->{$_}); |
240 |
|
$count++; |
241 |
|
} keys %$ant_flashing; |
242 |
|
if ($waiting == 0) { |
243 |
|
status "ALL $count ANTS FLASHED to $build\n"; |
244 |
|
$ant_flashing = undef; |
245 |
|
} else { |
246 |
|
status "$waiting of $count ants still flasing upto $build\n"; |
247 |
|
} |
248 |
} |
} |
249 |
} else { |
} else { |
250 |
once "!! NO FIRMWARE for $board in $tftp_path for ant $ant, skipping update\n"; |
once "!! NO FIRMWARE for $board in $tftp_path for ant $ant, skipping update\n"; |
251 |
} |
} |
252 |
} elsif ( $type eq 'REPLY-EXEC-CLI' && $h->{'SEQ-NR'} == 1 ) { |
} elsif ( $type eq 'REPLY-EXEC-CLI' && $h->{'SEQ-NR'} == 1 ) { |
253 |
print "UPDATE STEP 2 on ant $ant\n"; |
print "+ $ant bootp mode re-flash started\n" if ($verbose); |
254 |
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"); |
255 |
|
forget_ant( $ant ); |
256 |
|
$ant_flashing->{$ant}++; |
257 |
} else { |
} else { |
258 |
print "!! reply ignored ", dump( $h ), $/; |
print "!! reply ignored ", dump( $h ), $/; |
259 |
} |
} |