/[mdap]/mdap-server.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /mdap-server.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2 by dpavlin, Sun Apr 22 12:52:15 2007 UTC revision 8 by dpavlin, Sun Apr 22 16:06:03 2007 UTC
# Line 7  use Data::Dump qw/dump/; Line 7  use Data::Dump qw/dump/;
7  use constant GROUP => '224.0.0.103';  use constant GROUP => '224.0.0.103';
8  use constant PORT  => '3235';  use constant PORT  => '3235';
9    
10    my $debug = shift @ARGV;
11    
12  my $local_port = 1000;  my $local_port = 1000;
13    
14  my $resend_search_delay = 3;  my $resend_search_delay = 3;
15    my $tftp_path = '/srv/tftp/';
16    
17    sub fw {
18            my ($board, $offset,$len) = @_;
19            open(my $fh, "$tftp_path/$board") || die "Can't open image $tftp_path/$board: $!";
20            my $b;
21            seek($fh, $offset, 0) || die "can't seek to $offset: $!";
22            read($fh, $b, $len) || die "can't read $len bytes from $offset: $!";
23            close($fh);
24            return $b;
25    }
26    
27    sub fw_build {
28            my $board_name = shift || return 0;
29            my $v = join('.', unpack('CCCC',fw($board_name,0x20,4)) );
30            print "# fw_build $board_name $v\n";
31            return $v;
32    }
33    
34    sub fw_exists {
35            my $board = shift;
36            return -e "$tftp_path/$board";
37    }
38    
39  my $sock = IO::Socket::Multicast->new(LocalPort=>PORT,ReuseAddr=>1);  my $sock = IO::Socket::Multicast->new(LocalPort=>PORT,ReuseAddr=>1);
40  $sock->mcast_add(GROUP) || die "Couldn't set group: $!\n";  $sock->mcast_add(GROUP) || die "Couldn't set group: $!\n";
# Line 29  sub ant2hash { Line 54  sub ant2hash {
54    
55  sub mdap_send {  sub mdap_send {
56          my $data = shift;          my $data = shift;
57          warn ">> $data\n>>----------\n";          warn ">> $data\n>>----------\n" if ($debug);
         my $null = chr(0);  
58          $sock->mcast_send( "${data}", GROUP . ':' . PORT );          $sock->mcast_send( "${data}", GROUP . ':' . PORT );
59  }  }
60    
# Line 41  local $SIG{ALRM} = sub { Line 65  local $SIG{ALRM} = sub {
65    
66  alarm( $resend_search_delay );  alarm( $resend_search_delay );
67    
68    mdap_send("ANT-SEARCH MDAP/1.1\r\n46");
69    
70  while (1) {  while (1) {
71          my $data;          my $data;
72          next unless $sock->recv($data,1024);          next unless $sock->recv($data,1024);
# Line 51  while (1) { Line 77  while (1) {
77    
78                  my $h = ant2hash($data);                  my $h = ant2hash($data);
79    
80                  print "# $type $proto ", dump( $h ), $/;                  my $ant = $h->{'ANT-ID'} || die "no ANT-ID in ", dump( $h );
81    
82                    print "<< $type $proto ", length($data), " bytes\n";
83    
84                    warn dump($h),$/ if ($debug);
85    
86                  if ($type eq 'REPLY-ANT-SEARCH') {                  if ($type eq 'REPLY-ANT-SEARCH') {
87                          mdap_send("INFO MDAP/1.2                          mdap_send("INFO MDAP/1.2\r\nSEQ-NR:1\r\nTO-ANT:$ant\r\nUSER-ID:Administrator\r\nUSER-PWD:\r\n22");
 SEQ-NR:1  
 TO-ANT:0644JTHJ4  
 USER-ID:Administrator  
 USER-PWD:\r\n22");  
88                  } elsif ($type eq 'REPLY-INFO') {                  } elsif ($type eq 'REPLY-INFO') {
89                          if (                          my $board = $h->{'_BOARD_NAME'} || die "no _BOARD_NAME?";
90                                  $h->{'_BUILD'} eq '6.1.7.2' &&                          if ( fw_exists( $board ) ) {
91                                  $h->{'_BUILDNAME'} eq 'ZZO9AA6.172' &&                                  if ( $h->{'_BUILD'} ne fw_build( $board ) ) {
92                                  $h->{'_BUILDVARIANT'} eq 'AA' &&                                          print "UPDATE STEP 1 on ant $ant\n";
93                                  1                                          mdap_send("EXEC-CLI MDAP/1.2\r\nCLI-CMD:software upgrade\r\nSEQ-NR:1\r\nTO-ANT:$ant\r\nUSER-ID:Administrator\r\nUSER-PWD:\r\n1F");
94                          ) {                                  } else {
95                                  mdap_send("EXEC-CLI MDAP/1.2                                          print "OK ant $ant allready updated...\n";
96  CLI-CMD:software upgrade                                  }
 SEQ-NR:1  
 TO-ANT:0644JTHJ4  
 USER-ID:Administrator  
 USER-PWD:\r\n1F");  
97                          } else {                          } else {
98                                    print "!! NO FIRMWARE for $board in $tftp_path for ant $ant, skipping update\n";
99                          }                          }
100                    } elsif ( $type eq 'REPLY-EXEC-CLI' && $h->{'SEQ-NR'} == 1 ) {
101                                                            print "UPDATE STEP 2 on ant $ant\n";
102                                    mdap_send("EXEC-CLI MDAP/1.2\r\nSEQ-NR:2\r\nTO-ANT:$ant\r\nUSER-ID:Administrator\r\nUSER-PWD:\r\n5F");
103                  } else {                  } else {
104                          print "!! reply ignored\n";                          print "!! reply ignored ", dump( $h ), $/;
105                  }                  }
106    
107          } else {          } else {
108                  print $data, "\n", "-" x 30, "\n";                  warn "<=" x 15, "\n", $data, "\n", "<=" x 15, "\n";
109          }          }
110  }  }

Legend:
Removed from v.2  
changed lines
  Added in v.8

  ViewVC Help
Powered by ViewVC 1.1.26