per-agent configuration of batch processors, #71837
[freeside.git] / torrus / perllib / Torrus / DevDiscover / ATMEL.pm
1 #  Copyright (C) 2004  Scott Brooks
2 #
3 #  This program is free software; you can redistribute it and/or modify
4 #  it under the terms of the GNU General Public License as published by
5 #  the Free Software Foundation; either version 2 of the License, or
6 #  (at your option) any later version.
7 #
8 #  This program is distributed in the hope that it will be useful,
9 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 #  GNU General Public License for more details.
12 #
13 #  You should have received a copy of the GNU General Public License
14 #  along with this program; if not, write to the Free Software
15 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
16
17 # Scott Brooks <sbrooks@binary-solutions.net>
18
19 # ATMEL based access points/bridges
20
21 package Torrus::DevDiscover::ATMEL;
22
23 use strict;
24 use Torrus::Log;
25
26
27 $Torrus::DevDiscover::registry{'ATMEL'} = {
28     'sequence'     => 500,
29     'checkdevtype' => \&checkdevtype,
30     'discover'     => \&discover,
31     'buildConfig'  => \&buildConfig
32     };
33
34
35 our %oiddef =
36     (
37      # Check to see if we can get the list of running WSS ports
38      'sysDeviceInfo'           => '1.3.6.1.4.1.410.1.1.1.5.0',
39      'bridgeOperationalMode'   => '1.3.6.1.4.1.410.1.1.4.1.0',
40      'operAccessPointName'     => '1.3.6.1.4.1.410.1.2.1.10.0',
41      'bridgeRemoteBridgeBSSID' => '1.3.6.1.4.1.410.1.1.4.2.0'
42      );
43
44
45 sub checkdevtype
46 {
47     my $dd = shift;
48     my $devdetails = shift;
49
50     if( not $dd->checkSnmpOID('sysDeviceInfo') )
51     {
52         return 0;
53     }
54        
55     return 1;
56 }
57
58 sub discover
59 {
60     my $dd = shift;
61     my $devdetails = shift;
62
63     my $data = $devdetails->data();
64
65     my $info = $dd->retrieveSnmpOIDs('sysDeviceInfo',
66                                      'operAccessPointName',
67                                      'bridgeOperationalMode',
68                                      'bridgeRemoteBridgeBSSID',
69                                      );
70
71     my $deviceInfo = substr($info->{'sysDeviceInfo'},2);    
72     my $bridgeName = $info->{'operAccessPointName'};
73     
74     #Get rid of all the nulls returned.
75     $bridgeName =~ s/\000//g;
76     
77     $data->{'param'}{'comment'} = $bridgeName;
78
79     my $bridgeMode = $info->{'bridgeOperationalMode'};
80
81     my $remoteMac = substr($info->{'bridgeRemoteBridgeBSSID'},2);
82     
83     $remoteMac =~ s/(\w\w)/$1-/g;
84     $remoteMac = substr($remoteMac,0,-1);
85
86     my $bridge=0;
87
88     my ($version,$macaddr,$reserved,$regdomain,$producttype,$oemname,$oemid,
89         $productname,$hardwarerev) = unpack("LH12SLLA32LA32L",
90                                             pack("H*", $deviceInfo));
91     
92     $macaddr =~ s/(\w\w)/$1-/g;
93     $macaddr = substr($macaddr,0,-1);
94     
95     $data->{'param'}{'comment'} = $bridgeName;
96     
97     if ($productname =~ m/airPoint/)
98     {
99         #we have an access point
100         if ($bridgeMode == 3)
101         {
102             #we have an access point in client bridge mode.
103             $bridge=1;
104         }
105     }
106     else
107     {
108         #we have a bridge
109         $bridge=1;
110     }
111     if (!$bridge)
112     {
113         $devdetails->setCap('ATMEL::accessPoint');
114         my $legend =
115             "AP: " . $bridgeName .";" .
116             "Mac: " . $macaddr.";";
117         $data->{'param'}{'legend'} .= $legend;
118
119     }
120     else
121     {
122         my $legend =
123             "Bridge: " . $bridgeName .";" .
124             "Mac: " . $macaddr.";";
125         $data->{'param'}{'legend'} .= $legend;
126
127         $data->{'param'}{'legend'} .= "AP Mac: " . $remoteMac . ";";
128     }
129     #disable SNMP uptime check
130     $data->{'param'}{'snmp-check-sysuptime'} = 'no';
131     
132     return 1;
133 }
134
135
136 sub buildConfig
137 {
138     my $devdetails = shift;
139     my $cb = shift;
140     my $devNode = shift;
141
142     my @templates = ('ATMEL::atmel-device-subtree');
143
144     if( $devdetails->hasCap('ATMEL::accessPoint') )
145     {
146         push (@templates, 'ATMEL::atmel-accesspoint-stats');
147     }
148     else
149     {
150         push (@templates, 'ATMEL::atmel-client-stats');
151     }
152
153     foreach my $tmpl ( @templates )
154     {
155         $cb->addTemplateApplication( $devNode, $tmpl );
156     }
157 }
158
159
160 1;
161
162
163 # Local Variables:
164 # mode: perl
165 # indent-tabs-mode: nil
166 # perl-indent-level: 4
167 # End: