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

Legend:
Removed from v.3  
changed lines
  Added in v.7

  ViewVC Help
Powered by ViewVC 1.1.26