| 1 | # SNMP::Info::Layer2::Airespace | ||
| 2 | # | ||
| 3 | # Copyright (c) 2008 Eric Miller | ||
| 4 | # | ||
| 5 | # Redistribution and use in source and binary forms, with or without | ||
| 6 | # modification, are permitted provided that the following conditions are met: | ||
| 7 | # | ||
| 8 | # * Redistributions of source code must retain the above copyright notice, | ||
| 9 | # this list of conditions and the following disclaimer. | ||
| 10 | # * Redistributions in binary form must reproduce the above copyright | ||
| 11 | # notice, this list of conditions and the following disclaimer in the | ||
| 12 | # documentation and/or other materials provided with the distribution. | ||
| 13 | # * Neither the name of the University of California, Santa Cruz nor the | ||
| 14 | # names of its contributors may be used to endorse or promote products | ||
| 15 | # derived from this software without specific prior written permission. | ||
| 16 | # | ||
| 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
| 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 20 | # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
| 21 | # LIABLE FOR # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
| 22 | # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
| 23 | # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
| 24 | # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
| 25 | # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 26 | # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| 27 | # POSSIBILITY OF SUCH DAMAGE. | ||
| 28 | |||
| 29 | package SNMP::Info::Layer2::Airespace; | ||
| 30 | |||
| 31 | use strict; | ||
| 32 | use warnings; | ||
| 33 | use Exporter; | ||
| 34 | use SNMP::Info::Bridge; | ||
| 35 | use SNMP::Info::CDP; | ||
| 36 | use SNMP::Info::Airespace; | ||
| 37 | |||
| 38 | @SNMP::Info::Layer2::Airespace::ISA | ||
| 39 | = qw/SNMP::Info::Airespace SNMP::Info::CDP SNMP::Info::Bridge Exporter/; | ||
| 40 | @SNMP::Info::Layer2::Airespace::EXPORT_OK = qw//; | ||
| 41 | |||
| 42 | our ($VERSION, %FUNCS, %GLOBALS, %MIBS, %MUNGE); | ||
| 43 | |||
| 44 | $VERSION = '3.985003'; | ||
| 45 | |||
| 46 | %MIBS = ( | ||
| 47 | %SNMP::Info::MIBS, %SNMP::Info::Bridge::MIBS, | ||
| 48 | %SNMP::Info::CDP::MIBS, %SNMP::Info::Airespace::MIBS, | ||
| 49 | 'CISCO-LWAPP-DOT11-CLIENT-MIB' => 'cldcClientCurrentTxRateSet', | ||
| 50 | 'CISCO-LWAPP-DOT11-MIB' => 'cldHtDot11nChannelBandwidth', | ||
| 51 | 'CISCO-LWAPP-AP-MIB' => 'cLApIfMacAddress', | ||
| 52 | ); | ||
| 53 | |||
| 54 | %GLOBALS = ( | ||
| 55 | %SNMP::Info::GLOBALS, %SNMP::Info::Bridge::GLOBALS, | ||
| 56 | %SNMP::Info::CDP::GLOBALS, %SNMP::Info::Airespace::GLOBALS, | ||
| 57 | ); | ||
| 58 | |||
| 59 | %FUNCS = ( | ||
| 60 | %SNMP::Info::FUNCS, %SNMP::Info::Bridge::FUNCS, | ||
| 61 | %SNMP::Info::CDP::FUNCS, %SNMP::Info::Airespace::FUNCS, | ||
| 62 | # CISCO-LWAPP-AP-MIB::cLApTable | ||
| 63 | 'ap_if_mac' => 'cLApIfMacAddress', | ||
| 64 | # CISCO-LWAPP-DOT11-CLIENT-MIB::cldcClientTable | ||
| 65 | 'client_txrate' => 'cldcClientCurrentTxRateSet', | ||
| 66 | 'cd11_proto' => 'cldcClientProtocol', | ||
| 67 | 'cd11_rateset' => 'cldcClientDataRateSet', | ||
| 68 | # CISCO-LWAPP-DOT11-MIB::cldHtMacOperationsTable | ||
| 69 | 'cd11n_ch_bw' => 'cldHtDot11nChannelBandwidth', | ||
| 70 | |||
| 71 | ); | ||
| 72 | |||
| 73 | %MUNGE = ( | ||
| 74 | %SNMP::Info::MUNGE, %SNMP::Info::Bridge::MUNGE, | ||
| 75 | %SNMP::Info::CDP::MUNGE, %SNMP::Info::Airespace::MUNGE, | ||
| 76 | 'ap_if_mac' => \&SNMP::Info::munge_mac, | ||
| 77 | 'cd11n_ch_bw' => \&munge_cd11n_ch_bw, | ||
| 78 | 'cd11_rateset' => \&munge_cd11_rateset, | ||
| 79 | 'cd11_proto' => \&munge_cd11_proto, | ||
| 80 | ); | ||
| 81 | |||
| 82 | # 802.11n Modulation and Coding Scheme (MCS) | ||
| 83 | my $mcs_index = { | ||
| 84 | 20 => { | ||
| 85 | m0 => '6.5', | ||
| 86 | m1 => '13', | ||
| 87 | m2 => '19.5', | ||
| 88 | m3 => '26', | ||
| 89 | m4 => '39', | ||
| 90 | m5 => '52', | ||
| 91 | m6 => '58.5', | ||
| 92 | m7 => '65', | ||
| 93 | m8 => '13', | ||
| 94 | m9 => '26', | ||
| 95 | m10 => '39', | ||
| 96 | m11 => '52', | ||
| 97 | m12 => '78', | ||
| 98 | m13 => '104', | ||
| 99 | m14 => '117', | ||
| 100 | m15 => '130', | ||
| 101 | m16 => '19.5', | ||
| 102 | m17 => '39', | ||
| 103 | m18 => '58.5', | ||
| 104 | m19 => '78', | ||
| 105 | m20 => '117', | ||
| 106 | m21 => '156', | ||
| 107 | m22 => '175.5', | ||
| 108 | m23 => '195', | ||
| 109 | # This is a cheat for 802.11a bonded | ||
| 110 | m108 => '108', | ||
| 111 | }, | ||
| 112 | 40 => { | ||
| 113 | m0 => '15', | ||
| 114 | m1 => '30', | ||
| 115 | m2 => '45', | ||
| 116 | m3 => '60', | ||
| 117 | m4 => '90', | ||
| 118 | m5 => '120', | ||
| 119 | m6 => '135', | ||
| 120 | m7 => '157.5', | ||
| 121 | m8 => '30', | ||
| 122 | m9 => '60', | ||
| 123 | m10 => '90', | ||
| 124 | m11 => '120', | ||
| 125 | m12 => '180', | ||
| 126 | m13 => '240', | ||
| 127 | m14 => '270', | ||
| 128 | m15 => '300', | ||
| 129 | m16 => '45', | ||
| 130 | m17 => '90', | ||
| 131 | m18 => '135', | ||
| 132 | m19 => '180', | ||
| 133 | m20 => '270', | ||
| 134 | m21 => '360', | ||
| 135 | m22 => '405', | ||
| 136 | m23 => '450', | ||
| 137 | } | ||
| 138 | }; | ||
| 139 | |||
| 140 | sub os { | ||
| 141 | return 'cisco'; | ||
| 142 | } | ||
| 143 | |||
| 144 | sub vendor { | ||
| 145 | return 'cisco'; | ||
| 146 | } | ||
| 147 | |||
| 148 | sub model { | ||
| 149 | my $airespace = shift; | ||
| 150 | my $model = $airespace->airespace_model(); | ||
| 151 | return unless defined $model; | ||
| 152 | |||
| 153 | return $model; | ||
| 154 | } | ||
| 155 | |||
| 156 | sub cd11_mac { | ||
| 157 | my $airespace = shift; | ||
| 158 | my $cd11_sigstrength = $airespace->cd11_sigstrength(); | ||
| 159 | |||
| 160 | my $ret = {}; | ||
| 161 | foreach my $idx ( keys %$cd11_sigstrength ) { | ||
| 162 | my $mac = join( ":", map { sprintf "%02x", $_ } split /\./, $idx ); | ||
| 163 | $ret->{$idx} = $mac | ||
| 164 | } | ||
| 165 | return $ret; | ||
| 166 | } | ||
| 167 | |||
| 168 | sub cd11_txrate { | ||
| 169 | my $airespace = shift; | ||
| 170 | |||
| 171 | my $rates = $airespace->client_txrate() || {}; | ||
| 172 | my $protos = $airespace->cd11_proto() || {}; | ||
| 173 | my $bws = $airespace->cd11n_ch_bw() || {}; | ||
| 174 | |||
| 175 | my $cd11_txrate = {}; | ||
| 176 | foreach my $idx ( keys %$rates ) { | ||
| 177 | my $rate = $rates->{$idx} || '0.0'; | ||
| 178 | |||
| 179 | if ( $rate =~ /^\d+/ ) { | ||
| 180 | $cd11_txrate->{$idx} = [ $rate * 1.0 ]; | ||
| 181 | } | ||
| 182 | elsif ( $rate =~ /^m/ ) { | ||
| 183 | my $band = $protos->{$idx}; | ||
| 184 | my $bw = $bws->{$band}; | ||
| 185 | # FIXME throw some kind of error if we get an index/rate that we haven't implemented yet? Now we simply return "0.0"... | ||
| 186 | $cd11_txrate->{$idx} = [ $mcs_index->{$bw}->{$rate} || '0.0' ]; | ||
| 187 | } | ||
| 188 | else { | ||
| 189 | $cd11_txrate->{$idx} = [ $rate ]; | ||
| 190 | } | ||
| 191 | } | ||
| 192 | return $cd11_txrate; | ||
| 193 | } | ||
| 194 | |||
| 195 | sub munge_cd11n_ch_bw { | ||
| 196 | my $bw = shift; | ||
| 197 | |||
| 198 | if ( $bw =~ /forty/ ) { | ||
| 199 | return 40; | ||
| 200 | } | ||
| 201 | return 20; | ||
| 202 | } | ||
| 203 | |||
| 204 | sub munge_cd11_proto { | ||
| 205 | my $bw = shift; | ||
| 206 | |||
| 207 | return 2 if ( $bw eq 'dot11n5' ); | ||
| 208 | |||
| 209 | return 1; | ||
| 210 | } | ||
| 211 | |||
| 212 | sub munge_cd11_rateset { | ||
| 213 | my $rates = shift; | ||
| 214 | return [ map { $_ * 1.0 } split /,/, $rates ]; | ||
| 215 | } | ||
| 216 | |||
| 217 | # Cisco provides the AP's Ethernet MAC via | ||
| 218 | # CISCO-LWAPP-AP-MIB::cLApIfMacAddress this was not available pre-Cisco | ||
| 219 | sub i_mac { | ||
| 220 | my $airespace = shift; | ||
| 221 | my $partial = shift; | ||
| 222 | |||
| 223 | my $i_index = $airespace->i_index($partial) || {}; | ||
| 224 | my $ap_mac = $airespace->ap_if_mac() || {}; | ||
| 225 | |||
| 226 | my $i_mac = $airespace->SUPER::i_mac() || {}; | ||
| 227 | foreach my $iid ( keys %$i_index ) { | ||
| 228 | my $index = $i_index->{$iid}; | ||
| 229 | next unless defined $index; | ||
| 230 | |||
| 231 | if ( $index =~ /(?:[0-9A-Fa-f]{2}:){5}[0-9A-Fa-f]{2}/ ) { | ||
| 232 | $index =~ s/\.\d+$//; | ||
| 233 | next unless defined $index; | ||
| 234 | my $sys_mac = join( '.', map { hex($_) } split( ':', $index ) ); | ||
| 235 | my $mac = $ap_mac->{$sys_mac}; | ||
| 236 | $i_mac->{$iid} = $mac; | ||
| 237 | } | ||
| 238 | } | ||
| 239 | return $i_mac; | ||
| 240 | } | ||
| 241 | |||
| 242 | 1; | ||
| 243 | __END__ |