Info/Layer2/FortiAP.pm untested

filter: Statementstmt 0.0% 0 / 183 Branchbran 0.0% 0 / 36 Conditioncond 0.0% 0 / 83 MC/DCmcdc 0.0% 0 / 44 Subroutinesub 0.0% 0 / 28 Podpod 0.0% 0 / 24 totaltotal 0.0% 0 / 398 CC 19 SCAR 21.3
CC
19
Cov
0%
_fap_vap_ports
30.0
os_ver
12.0
i_ssidmac
12.0
CRAP 8.4
1 # SNMP::Info::Layer2::FortiAP
2 #
3 # Copyright (c) 2026 SNMP::Info Developers
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::Layer2::FortiAP;
31  
32 use strict;
33 use warnings;
34 use Exporter;
35 use SNMP::Info::Layer2;
36  
37 @SNMP::Info::Layer2::FortiAP::ISA = qw/
38 SNMP::Info::Layer2
39 Exporter
40 /;
41 @SNMP::Info::Layer2::FortiAP::EXPORT_OK = qw//;
42  
43 our ( $VERSION, %GLOBALS, %MIBS, %FUNCS, %MUNGE );
44  
45 $VERSION = '3.985003';
46  
47 %MIBS = ( %SNMP::Info::Layer2::MIBS, );
48  
49 %GLOBALS = (
50 %SNMP::Info::Layer2::GLOBALS,
51  
52 # FORTINET-FORTIAP-MIB objects are read by OID until the MIB is in a
53 # netdisco-mibs release, netdisco/netdisco-mibs#312
54 # fapVersion, fapSerialNum
55 'fap_version' => '.1.3.6.1.4.1.12356.120.1.1.0',
56 'fap_serial' => '.1.3.6.1.4.1.12356.120.1.2.0',
57 );
58  
59 %FUNCS = (
60 %SNMP::Info::Layer2::FUNCS,
61  
62 # fapRadioTxPowerOper (dBm), fapRadioChannelOper; indexed by radio
63 'fap_radio_tx_pwr' => '.1.3.6.1.4.1.12356.120.4.1.1.10',
64 'fap_radio_channel' => '.1.3.6.1.4.1.12356.120.4.1.1.14',
65  
66 # fapVapSSID; indexed by radio.wlan
67 'fap_vap_ssid' => '.1.3.6.1.4.1.12356.120.7.1.1.4',
68  
69 # fapStaVlanId, fapStaSSID; indexed by radio.wlan.<station MAC>
70 'fap_sta_vlan' => '.1.3.6.1.4.1.12356.120.8.1.1.5',
71 'fap_sta_ssid' => '.1.3.6.1.4.1.12356.120.8.1.1.7',
72 );
73  
74 %MUNGE = ( %SNMP::Info::Layer2::MUNGE, );
75  
76 # FortiAPs serve no sysServices
77 sub layers {
78 my $fap = shift;
79  
80 return $fap->SUPER::layers() || '00000010';
81 }
82  
83 sub vendor {
84 return 'fortinet';
85 }
86  
87 sub os {
88 return 'fortiap';
89 }
90  
91 # fapVersion is "<image>-v<version>", e.g. "FP221E-v7.0-build0033"
92 sub os_ver {
93 my $fap = shift;
94 my $version = $fap->fap_version();
95  
96 return unless defined $version;
97 return $1 if $version =~ /^\S+?-v(\S+)$/;
98 return $version;
99 }
100  
101 # The image name before "-v" names the model: FP231G, PU231F
102 sub model {
103 my $fap = shift;
104 my $version = $fap->fap_version() // '';
105  
106 return $1 if $version =~ /^(\S+?)-v/;
107 return $fap->SUPER::model();
108 }
109  
110 sub serial {
111 my $fap = shift;
112  
113 return $fap->fap_serial();
114 }
115  
116 # fapRadioTable row R is the interface named wifi<R>; no column links
117 # the two
118 sub _fap_radios {
119 my $fap = shift;
120  
121 my $channels = $fap->fap_radio_channel() || {};
122 my $i_descr = $fap->i_description() || {};
123 my %ifindex_by_name = reverse %$i_descr;
124  
125 my %radios;
126 foreach my $radio ( keys %$channels ) {
127 my $ifindex = $ifindex_by_name{"wifi$radio"};
128 $radios{$radio} = $ifindex if defined $ifindex;
129 }
130 return \%radios;
131 }
132  
133 # Per-VAP interfaces of a mapped radio: wlan<R><W>, w<R><W>.<vlan>,
134 # tv<R><W>, wlbgs<R>; and per-SSID interfaces br.ssid.<W>, tc<W> of a WLAN
135 # served on a mapped radio
136 sub _fap_vap_ports {
137 my $fap = shift;
138  
139 my $radios = $fap->_fap_radios();
140 my $i_descr = $fap->i_description() || {};
141 my %wlans = map { ( split /\./ )[1] => 1 }
142 grep { exists $radios->{ ( split /\./ )[0] } }
143 keys %{ $fap->fap_vap_ssid() || {} };
144  
145 my %vap_ports;
146 foreach my $iid ( keys %$i_descr ) {
147 my $name = $i_descr->{$iid};
148 if ( $name =~ /^(?:wlan(\d)\d+|w(\d)\d+\.\d+|tv(\d)\d+|wlbgs(\d))$/ )
149 {
150 my $radio = $1 // $2 // $3 // $4;
151 $vap_ports{$iid} = 1 if exists $radios->{$radio};
152 }
153 elsif ( $name =~ /^(?:br\.ssid\.|tc)(\d+)$/ ) {
154 $vap_ports{$iid} = 1 if $wlans{$1};
155 }
156 }
157 return \%vap_ports;
158 }
159  
160 sub interfaces {
161 my $fap = shift;
162 my $partial = shift;
163  
164 my $interfaces = $fap->SUPER::interfaces($partial) || {};
165 my $vap_ports = $fap->_fap_vap_ports();
166  
167 delete @{$interfaces}{ keys %$vap_ports };
168 return $interfaces;
169 }
170  
171 sub i_80211channel {
172 my $fap = shift;
173  
174 my $radios = $fap->_fap_radios();
175 my $channels = $fap->fap_radio_channel() || {};
176  
177 my %i_80211channel;
178 foreach my $radio ( keys %$radios ) {
179 my $channel = $channels->{$radio};
180 next unless $channel;
181 $i_80211channel{ $radios->{$radio} } = $channel;
182 }
183 return \%i_80211channel;
184 }
185  
186 sub dot11_cur_tx_pwr_mw {
187 my $fap = shift;
188  
189 my $radios = $fap->_fap_radios();
190 my $channels = $fap->fap_radio_channel() || {};
191 my $power = $fap->fap_radio_tx_pwr() || {};
192  
193 my %tx_pwr_mw;
194 foreach my $radio ( keys %$radios ) {
195 my $dbm = $power->{$radio};
196 next
197 unless $channels->{$radio}
198 and defined $dbm
199 and $dbm =~ /^-?\d+$/;
200 $tx_pwr_mw{ $radios->{$radio} } = int( 10**( $dbm / 10 ) + 0.5 );
201 }
202 return \%tx_pwr_mw;
203 }
204  
205 sub i_ssidlist {
206 my $fap = shift;
207  
208 my $radios = $fap->_fap_radios();
209 my $ssids = $fap->fap_vap_ssid() || {};
210  
211 my %i_ssidlist;
212 foreach my $vap ( keys %$ssids ) {
213 my ( $radio, $wlan ) = split /\./, $vap;
214 next unless defined $wlan and exists $radios->{$radio};
215 $i_ssidlist{"$radios->{$radio}.$wlan"} = $ssids->{$vap};
216 }
217 return \%i_ssidlist;
218 }
219  
220 # The BSSID is the MAC of the VAP's wlan<R><W> interface
221 sub i_ssidmac {
222 my $fap = shift;
223  
224 my $radios = $fap->_fap_radios();
225 my $ssids = $fap->fap_vap_ssid() || {};
226 my $i_descr = $fap->i_description() || {};
227 my $i_mac = $fap->i_mac() || {};
228 my %ifindex_by_name = reverse %$i_descr;
229  
230 my %i_ssidmac;
231 foreach my $vap ( keys %$ssids ) {
232 my ( $radio, $wlan ) = split /\./, $vap;
233 next unless defined $wlan and exists $radios->{$radio};
234 my $vap_port = $ifindex_by_name{"wlan$radio$wlan"};
235 next unless defined $vap_port and $i_mac->{$vap_port};
236 $i_ssidmac{"$radios->{$radio}.$wlan"} = $i_mac->{$vap_port};
237 }
238 return \%i_ssidmac;
239 }
240  
241 # fapStaMacAddr is a PhysAddress index, so normally length prefixed;
242 # accept the bare six octets too
243 sub _fap_sta_index {
244 my $iid = shift;
245  
246 my ( $radio, $wlan, @octets ) = split /\./, $iid;
247 shift @octets if @octets == 7 and $octets[0] == 6;
248 return unless defined $wlan and @octets == 6;
249 return ( $radio, $wlan, join ':', map { sprintf '%02x', $_ } @octets );
250 }
251  
252 # Stations on a radio with a port: { iid => [ radio ifIndex, mac ] }
253 sub _fap_stations {
254 my $fap = shift;
255 my $partial = shift;
256  
257 my $radios = $fap->_fap_radios();
258 my $ssids = $fap->fap_sta_ssid($partial) || {};
259  
260 my %stations;
261 foreach my $iid ( keys %$ssids ) {
262 my ( $radio, $wlan, $mac ) = _fap_sta_index($iid);
263 next unless defined $mac and exists $radios->{$radio};
264 $stations{$iid} = [ $radios->{$radio}, $mac ];
265 }
266 return \%stations;
267 }
268  
269 sub qb_fw_mac {
270 my $fap = shift;
271 my $stations = $fap->_fap_stations(shift);
272  
273 return { map { $_ => $stations->{$_}[1] } keys %$stations };
274 }
275  
276 sub qb_fw_port {
277 my $fap = shift;
278 my $stations = $fap->_fap_stations(shift);
279  
280 return { map { $_ => $stations->{$_}[0] } keys %$stations };
281 }
282  
283 sub qb_fw_vlan {
284 my $fap = shift;
285 my $partial = shift;
286 my $stations = $fap->_fap_stations($partial);
287 my $vlans = $fap->fap_sta_vlan($partial) || {};
288  
289 return {
290 map { $_ => $vlans->{$_} }
291 grep { defined $vlans->{$_} } keys %$stations
292 };
293 }
294  
295 # Stations are reported on radio ifIndexes, which serve no bridge port
296 sub bp_index {
297 my $fap = shift;
298 my $partial = shift;
299  
300 # Copied: SUPER returns the cached table by reference
301 my %bp_index = %{ $fap->SUPER::bp_index($partial) || {} };
302 my $radios = $fap->_fap_radios();
303  
304 foreach my $ifindex ( values %$radios ) {
305 $bp_index{$ifindex} = $ifindex unless exists $bp_index{$ifindex};
306 }
307 return \%bp_index;
308 }
309  
310 # fapStationTable has no rate column; an empty rate keeps the client
311 sub cd11_txrate {
312 my $fap = shift;
313 my $stations = $fap->_fap_stations(shift);
314  
315 return { map { $_ => [] } keys %$stations };
316 }
317  
318 sub cd11_mac {
319 my $fap = shift;
320  
321 return $fap->qb_fw_mac(shift);
322 }
323  
324 sub cd11_ssid {
325 my $fap = shift;
326 my $partial = shift;
327 my $stations = $fap->_fap_stations($partial);
328 my $ssids = $fap->fap_sta_ssid($partial) || {};
329  
330 return { map { $_ => $ssids->{$_} } keys %$stations };
331 }
332  
333 sub cd11_port {
334 my $fap = shift;
335 my $stations = $fap->_fap_stations(shift);
336 my $interfaces = $fap->interfaces();
337  
338 return {
339 map { $_ => $interfaces->{ $stations->{$_}[0] } }
340 keys %$stations
341 };
342 }
343  
344 # Loopback and Linux pseudo devices that carry no traffic
345 sub i_ignore {
346 my $fap = shift;
347 my $partial = shift;
348  
349 my $ignore = $fap->SUPER::i_ignore($partial) || {};
350 my $i_descr = $fap->i_description($partial) || {};
351 my $i_type = $fap->i_type($partial) || {};
352  
353 foreach my $iid ( keys %$i_descr ) {
354 my $name = $i_descr->{$iid};
355 my $type = $i_type->{$iid} // '';
356 $ignore->{$iid}++
357 if $type eq 'softwareLoopback'
358 or $name =~ /^(?:gre|gretap|ip6tnl|sit|ip6gre|ifb|teql|soc)\d*$/
359 or $name =~ /^(?:ipsecdummy|miireg)$/;
360 }
361 return $ignore;
362 }
363  
364 1;
365 __END__