Info/IEEE802dot11.pm untested

filter: Statementstmt 0.0% 0 / 72 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 122 CC 12 SCAR 28.8
CC
12
Cov
0%
i_80211channel
42.0
vendor
12.0
os_ver
12.0
CRAP 17.8
1 # SNMP::Info::IEEE802dot11
2 #
3 # Copyright (c) 2008 Eric Miller
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions are met:
8 #
9 # * Redistributions of source code must retain the above copyright notice,
10 # this list of conditions and the following disclaimer.
11 # * Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
14 # * Neither the name of the University of California, Santa Cruz nor the
15 # names of its contributors may be used to endorse or promote products
16 # derived from this software without specific prior written permission.
17 #
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22 # LIABLE FOR # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 # POSSIBILITY OF SUCH DAMAGE.
29  
30 package SNMP::Info::IEEE802dot11;
31  
32 use strict;
33 use warnings;
34 use Exporter;
35 use SNMP::Info;
36  
37 @SNMP::Info::IEEE802dot11::ISA = qw/SNMP::Info Exporter/;
38 @SNMP::Info::IEEE802dot11::EXPORT_OK = qw//;
39  
40 our ($VERSION, %FUNCS, %GLOBALS, %MIBS, %MUNGE);
41  
42 $VERSION = '3.985003';
43  
44 %MIBS = ( 'IEEE802dot11-MIB' => 'dot11DesiredSSID', );
45  
46 %GLOBALS = ();
47  
48 %FUNCS = (
49  
50 # dot11PhyOFDMTable
51 'dot11_cur_freq' => 'dot11CurrentFrequency',
52  
53 # dot11PhyDSSSTable
54 'dot11_cur_ch' => 'dot11CurrentChannel',
55  
56 # dot11PhyOperationTable
57 'dot11_phy_type' => 'dot11PHYType',
58 'dot11_reg_dom' => 'dot11CurrentRegDomain',
59  
60 # dot11ResourceInfoTable
61 'dot11_prod_ver' => 'dot11manufacturerProductVersion',
62 'dot11_prod_name' => 'dot11manufacturerProductName',
63 'dot11_man_name' => 'dot11manufacturerName',
64  
65 # dot11OperationTable
66 'dot11_mac' => 'dot11MACAddress',
67  
68 # dot11StationConfigTable
69 'dot11_bss_type' => 'dot11DesiredBSSType',
70 'i_ssidlist' => 'dot11DesiredSSID',
71 'dot11_pwr_mode' => 'dot11PowerManagementMode',
72 'dot11_sta_id' => 'dot11StationID',
73  
74 # dot11PhyTxPowerTable
75 'dot11_cur_tx_pwr' => 'dot11CurrentTxPowerLevel',
76 'dot11_tx_pwr_level_1' => 'dot11TxPowerLevel1',
77 'dot11_tx_pwr_level_2' => 'dot11TxPowerLevel2',
78 'dot11_tx_pwr_level_3' => 'dot11TxPowerLevel3',
79 'dot11_tx_pwr_level_4' => 'dot11TxPowerLevel4',
80 'dot11_tx_pwr_level_5' => 'dot11TxPowerLevel5',
81 'dot11_tx_pwr_level_6' => 'dot11TxPowerLevel6',
82 'dot11_tx_pwr_level_7' => 'dot11TxPowerLevel7',
83 'dot11_tx_pwr_level_8' => 'dot11TxPowerLevel8',
84 );
85  
86 %MUNGE = (
87 'dot11_mac' => \&SNMP::Info::munge_mac,
88 'dot11_sta_id' => \&SNMP::Info::munge_mac,
89 );
90  
91 sub vendor {
92 my $dot11 = shift;
93  
94 my $names = $dot11->dot11_man_name();
95  
96 foreach my $iid ( keys %$names ) {
97 my $vendor = $names->{$iid};
98 next unless defined $vendor;
99 if ( $vendor =~ /^(\S+)/ ) {
100 return lc($1);
101 }
102 }
103  
104 return;
105 }
106  
107 sub model {
108 my $dot11 = shift;
109  
110 my $names = $dot11->dot11_prod_name();
111  
112 foreach my $iid ( keys %$names ) {
113 my $prod = $names->{$iid};
114 next unless defined $prod;
115 return lc($prod);
116 }
117 return;
118 }
119  
120 sub os_ver {
121 my $dot11 = shift;
122  
123 my $versions = $dot11->dot11_prod_ver();
124  
125 foreach my $iid ( keys %$versions ) {
126 my $ver = $versions->{$iid};
127 next unless defined $ver;
128 if ( $ver =~ /([\d\.]+)/ ) {
129 return $1;
130 }
131 }
132  
133 return;
134 }
135  
136 sub i_80211channel {
137 my $dot11 = shift;
138  
139 my $phy_type = $dot11->dot11_phy_type() || {};
140 my $cur_freq = $dot11->dot11_cur_freq() || {};
141 my $cur_ch = $dot11->dot11_cur_ch() || {};
142  
143 my %i_80211channel;
144 foreach my $iid ( keys %$phy_type ) {
145 my $type = $phy_type->{$iid};
146 next unless defined $type;
147 if ( $type =~ /dsss/ ) {
148 my $ch = $cur_ch->{$iid};
149 next unless defined $ch;
150 $i_80211channel{$iid} = $ch;
151 }
152 elsif ( $type =~ /ofdm/ ) {
153 my $ch = $cur_freq->{$iid};
154 next unless defined $ch;
155 $i_80211channel{$iid} = $ch;
156 }
157 else {
158 next;
159 }
160 }
161  
162 return \%i_80211channel;
163 }
164  
165 sub dot11_cur_tx_pwr_mw {
166 my $dot11 = shift;
167 my $partial = shift;
168 my $cur = $dot11->dot11_cur_tx_pwr($partial);
169 my $dot11_cur_tx_pwr_mw = {};
170 foreach my $idx ( keys %$cur ) {
171 my $pwr = $cur->{$idx};
172 if ( $pwr >= 1 && $pwr <= 8 ) {
173  
174 # ToDo - Look at string eval
175 my $mw
176 = eval "\$dot11->dot11_tx_pwr_level_$pwr(\$idx)"; ## no critic
177 $dot11_cur_tx_pwr_mw->{$idx} = $mw->{$idx};
178 }
179 else {
180 next;
181 }
182 }
183 return $dot11_cur_tx_pwr_mw;
184 }
185  
186 1;
187  
188 __END__