#!/usr/bin/perl 


use Getopt::Std;
	       
# Port? This is the standard port#
my $port = 161;
my $ReverseTXRX;

my %opts; 
getopt("-ic", \%opts);
my $host = $opts{'i'} || Usage();
my $community = $opts{'c'} || Usage();
my $Percentage = 1;
my $MAX_RSSI = 40.0;

#################################################################
#---------------------- 4/22/2003 Earl -------------------------#
#################################################################

use Net::SNMP;
# use strict;

# Setup OIDs (OID's must end in .0)

my $sysDescr = '1.3.6.1.4.1.410.1.1.1.1.0'; 
my $sysDevInfo = '1.3.6.1.4.1.410.1.1.1.5.0';
my $TestMode = '1.3.6.1.4.1.410.1.1.8.2.0'; 
my $Mode = '1.3.6.1.4.1.410.1.1.4.1.0'; 
my $Wireless = '1.3.6.1.4.1.410.1.2.7.1.0'; 
my $Ch = '1.3.6.1.4.1.410.1.2.1.1.0'; 
my $ClientsNum = '1.3.6.1.4.1.410.1.2.1.3.0'; 
my $CR31 = '1.3.6.1.4.1.410.1.1.8.8.0'; 
my $WLstatisticsGRP = "1.3.6.1.4.1.410.1.2.3.1.0";
# Start the SNMP session
my ($session, $error) = Net::SNMP->session(
	    -hostname  => shift || $host,
             -community => shift || $community,
             -port      => shift || $port
          );


   $Data = snmpQuery($session,$Wireless);
   $Data_sysDevInfo = snmpQuery($session,$sysDevInfo);
   $Data_sysDescr = snmpQuery($session,$sysDescr);
   $Data3 = snmpQuery($session,$ClientsNum);
   $Data4 = snmpQuery($session,$TestMode);
   $Data5 = snmpQuery($session,$Mode);
   $Data6 = snmpQuery($session,$Ch);
   $Data7 = snmpQuery($session,$CR31);
   $OEMname = substr($Data_sysDevInfo,42,42);
   
   $d0hb = hex(substr($OEMname, 0, 1));
   $d0lb = hex(substr($OEMname, 1, 1));
   $d1hb = hex(substr($OEMname, 2, 1));
   $d1lb = hex(substr($OEMname, 3, 1));
   $d2hb = hex(substr($OEMname, 4, 1));
   $d2lb = hex(substr($OEMname, 5, 1));
   $d3hb = hex(substr($OEMname, 6, 1));
   $d3lb = hex(substr($OEMname, 7, 1));
   $d4hb = hex(substr($OEMname, 8, 1));
   $d4lb = hex(substr($OEMname, 9, 1));
   $d5hb = hex(substr($OEMname, 10, 1));
   $d5lb = hex(substr($OEMname, 11, 1));
   $d6hb = hex(substr($OEMname, 12, 1));
   $d6lb = hex(substr($OEMname, 13, 1));
   $d7hb = hex(substr($OEMname, 14, 1));
   $d7lb = hex(substr($OEMname, 15, 1));
   
   $d8hb = hex(substr($OEMname, 16, 1));
   $d8lb = hex(substr($OEMname, 17, 1));
   $d9hb = hex(substr($OEMname, 18, 1));
   $d9lb = hex(substr($OEMname, 19, 1));
   $d10hb = hex(substr($OEMname, 20, 1));
   $d10lb = hex(substr($OEMname, 21, 1));
   $d11hb = hex(substr($OEMname, 22, 1));
   $d11lb = hex(substr($OEMname, 23, 1));
   $d12hb = hex(substr($OEMname, 24, 1));
   $d12lb = hex(substr($OEMname, 25, 1));
   $d13hb = hex(substr($OEMname, 26, 1));
   $d13lb = hex(substr($OEMname, 27, 1));
   $d14hb = hex(substr($OEMname, 28, 1));
   $d14lb = hex(substr($OEMname, 29, 1));
   $d15hb = hex(substr($OEMname, 30, 1));
   $d15lb = hex(substr($OEMname, 31, 1));
   $d16hb = hex(substr($OEMname, 32, 1));
   $d16lb = hex(substr($OEMname, 33, 1));
   $d17hb = hex(substr($OEMname, 34, 1));
   $d17lb = hex(substr($OEMname, 35, 1));
   $d18hb = hex(substr($OEMname, 36, 1));
   $d18lb = hex(substr($OEMname, 37, 1));
   
   $nam1c1 = $d0lb + $d0hb * 16;
   $nam1c2 = $d1lb + $d1hb * 16;
   $nam1c1 = chr($nam1c1);
   $nam1c2 = chr($nam1c2);
   $nam1c3 = $d2lb + $d2hb * 16;
   $nam1c4 = $d3lb + $d3hb * 16;
   $nam1c3 = chr($nam1c3);
   $nam1c4 = chr($nam1c4);
   $nam1c5 = $d4lb + $d4hb * 16;
   $nam1c6 = $d5lb + $d5hb * 16;
   $nam1c5 = chr($nam1c5);
   $nam1c6 = chr($nam1c6);
   $nam1c7 = $d6lb + $d6hb * 16;
   $nam1c8 = $d7lb + $d7hb * 16;
   $nam1c7 = chr($nam1c7);
   $nam1c8 = chr($nam1c8);
  $nam1c9 = $d8lb + $d8hb * 16;
  $nam1c10 = $d9lb + $d9hb * 16;
  $nam1c9 = chr($nam1c9);
  $nam1c10 = chr($nam1c10);
   $nam1c11 = $d10lb + $d10hb * 16;
   $nam1c12 = $d11lb + $d11hb * 16;
   $nam1c11 = chr($nam1c11);
   $nam1c12 = chr($nam1c12);
  $nam1c13 = $d12lb + $d12hb * 16;
  $nam1c14 = $d13lb + $d13hb * 16;
  $nam1c13 = chr($nam1c13);
  $nam1c14 = chr($nam1c14);
   $nam1c15 = $d14lb + $d14hb * 16;
   $nam1c16 = $d15lb + $d15hb * 16;
   $nam1c15 = chr($nam1c15);
   $nam1c16 = chr($nam1c16);
  
   $nam1c17 = $d16lb + $d16hb * 16;
   $nam1c18 = $d17lb + $d17hb * 16;
   $nam1c17 = chr($nam1c17);
   $nam1c18 = chr($nam1c18);
  $nam1c19 = $d18lb + $d18hb * 16;
  $nam1c20 = $d19lb + $d19hb * 16;
  $nam1c19 = chr($nam1c19);
  $nam1c20 = chr($nam1c20);
  
  $OEM1 = "$nam1c1$nam1c2$nam1c3$nam1c4$nam1c5$nam1c6$nam1c7$nam1c8$nam1c9$nam1c10$nam1c11$nam1c12$nam1c13$nam1c14$nam1c15$nam1c16$nam1c17$nam1c18$nam1c19$nam1c20";


$nam1 = substr($Data, 34, 32);
$d0hb = hex(substr($Data, 34, 1));
$d0lb = hex(substr($Data, 35, 1));
$d1hb = hex(substr($Data, 36, 1));
$d1lb = hex(substr($Data, 37, 1));
$d2hb = hex(substr($Data, 38, 1));
$d2lb = hex(substr($Data, 39, 1));
$d3hb = hex(substr($Data, 40, 1));
$d3lb = hex(substr($Data, 41, 1));
$d4hb = hex(substr($Data, 42, 1));
$d4lb = hex(substr($Data, 43, 1));
$d5hb = hex(substr($Data, 44, 1));
$d5lb = hex(substr($Data, 45, 1));
$d6hb = hex(substr($Data, 46, 1));
$d6lb = hex(substr($Data, 47, 1));
$d7hb = hex(substr($Data, 48, 1));
$d7lb = hex(substr($Data, 49, 1));
$nam1c1 = $d0lb + $d0hb * 16;
$nam1c2 = $d1lb + $d1hb * 16;
$nam1c1 = chr($nam1c1);
$nam1c2 = chr($nam1c2);
$nam1c3 = $d2lb + $d2hb * 16;
$nam1c4 = $d3lb + $d3hb * 16;
$nam1c3 = chr($nam1c3);
$nam1c4 = chr($nam1c4);
$nam1c5 = $d4lb + $d4hb * 16;
$nam1c6 = $d5lb + $d5hb * 16;
$nam1c5 = chr($nam1c5);
$nam1c6 = chr($nam1c6);
$nam1c7 = $d6lb + $d6hb * 16;
$nam1c8 = $d7lb + $d7hb * 16;
$nam1c7 = chr($nam1c7);
$nam1c8 = chr($nam1c8);
$nam1 = "$nam1c1$nam1c2$nam1c3$nam1c4$nam1c5$nam1c6$nam1c7$nam1c8";
$nam1c1 = 0;
$nam1c2 = 0;
$nam1c3 = 0;
$nam1c4 = 0;
$nam1c5 = 0;
$nam1c6 = 0;
$nam1c7 = 0;
$nam1c8 = 0;

$nam2 = substr($Data, 34+96, 32);
$d0hb = hex(substr($Data, 34+96, 1));
$d0lb = hex(substr($Data, 35+96, 1));
$d1hb = hex(substr($Data, 36+96, 1));
$d1lb = hex(substr($Data, 37+96, 1));
$d2hb = hex(substr($Data, 38+96, 1));
$d2lb = hex(substr($Data, 39+96, 1));
$d3hb = hex(substr($Data, 40+96, 1));
$d3lb = hex(substr($Data, 41+96, 1));
$d4hb = hex(substr($Data, 42+96, 1));
$d4lb = hex(substr($Data, 43+96, 1));
$d5hb = hex(substr($Data, 44+96, 1));
$d5lb = hex(substr($Data, 45+96, 1));
$d6hb = hex(substr($Data, 46+96, 1));
$d6lb = hex(substr($Data, 47+96, 1));
$d7hb = hex(substr($Data, 48+96, 1));
$d7lb = hex(substr($Data, 49+96, 1));
$nam1c1 = $d0lb + $d0hb * 16;
$nam1c2 = $d1lb + $d1hb * 16;
$nam1c1 = chr($nam1c1);
$nam1c2 = chr($nam1c2);
$nam1c3 = $d2lb + $d2hb * 16;
$nam1c4 = $d3lb + $d3hb * 16;
$nam1c3 = chr($nam1c3);
$nam1c4 = chr($nam1c4);
$nam1c5 = $d4lb + $d4hb * 16;
$nam1c6 = $d5lb + $d5hb * 16;
$nam1c5 = chr($nam1c5);
$nam1c6 = chr($nam1c6);
$nam1c7 = $d6lb + $d6hb * 16;
$nam1c8 = $d7lb + $d7hb * 16;
$nam1c7 = chr($nam1c7);
$nam1c8 = chr($nam1c8);
$nam2 = "$nam1c1$nam1c2$nam1c3$nam1c4$nam1c5$nam1c6$nam1c7$nam1c8";
$nam1c1 = 0;
$nam1c2 = 0;
$nam1c3 = 0;
$nam1c4 = 0;
$nam1c5 = 0;
$nam1c6 = 0;
$nam1c7 = 0;
$nam1c8 = 0;


$nam3 = substr($Data, 34+96+96, 32);
$d0hb = hex(substr($Data, 34+96+96, 1));
$d0lb = hex(substr($Data, 35+96+96, 1));
$d1hb = hex(substr($Data, 36+96+96, 1));
$d1lb = hex(substr($Data, 37+96+96, 1));
$d2hb = hex(substr($Data, 38+96+96, 1));
$d2lb = hex(substr($Data, 39+96+96, 1));
$d3hb = hex(substr($Data, 40+96+96, 1));
$d3lb = hex(substr($Data, 41+96+96, 1));
$d4hb = hex(substr($Data, 42+96+96, 1));
$d4lb = hex(substr($Data, 43+96+96, 1));
$d5hb = hex(substr($Data, 44+96+96, 1));
$d5lb = hex(substr($Data, 45+96+96, 1));
$d6hb = hex(substr($Data, 46+96+96, 1));
$d6lb = hex(substr($Data, 47+96+96, 1));
$d7hb = hex(substr($Data, 48+96+96, 1));
$d7lb = hex(substr($Data, 49+96+96, 1));
$nam1c1 = $d0lb + $d0hb * 16;
$nam1c2 = $d1lb + $d1hb * 16;
$nam1c1 = chr($nam1c1);
$nam1c2 = chr($nam1c2);
$nam1c3 = $d2lb + $d2hb * 16;
$nam1c4 = $d3lb + $d3hb * 16;
$nam1c3 = chr($nam1c3);
$nam1c4 = chr($nam1c4);
$nam1c5 = $d4lb + $d4hb * 16;
$nam1c6 = $d5lb + $d5hb * 16;
$nam1c5 = chr($nam1c5);
$nam1c6 = chr($nam1c6);
$nam1c7 = $d6lb + $d6hb * 16;
$nam1c8 = $d7lb + $d7hb * 16;
$nam1c7 = chr($nam1c7);
$nam1c8 = chr($nam1c8);
$nam3 = "$nam1c1$nam1c2$nam1c3$nam1c4$nam1c5$nam1c6$nam1c7$nam1c8";
$nam1c1 = 0;
$nam1c2 = 0;
$nam1c3 = 0;
$nam1c4 = 0;
$nam1c5 = 0;
$nam1c6 = 0;
$nam1c7 = 0;
$nam1c8 = 0;

$nam4 = substr($Data, 34+96+96+96, 32);
$d0hb = hex(substr($Data, 34+96+96+96, 1));
$d0lb = hex(substr($Data, 35+96+96+96, 1));
$d1hb = hex(substr($Data, 36+96+96+96, 1));
$d1lb = hex(substr($Data, 37+96+96+96, 1));
$d2hb = hex(substr($Data, 38+96+96+96, 1));
$d2lb = hex(substr($Data, 39+96+96+96, 1));
$d3hb = hex(substr($Data, 40+96+96+96, 1));
$d3lb = hex(substr($Data, 41+96+96+96, 1));
$d4hb = hex(substr($Data, 42+96+96+96, 1));
$d4lb = hex(substr($Data, 43+96+96+96, 1));
$d5hb = hex(substr($Data, 44+96+96+96, 1));
$d5lb = hex(substr($Data, 45+96+96+96, 1));
$d6hb = hex(substr($Data, 46+96+96+96, 1));
$d6lb = hex(substr($Data, 47+96+96+96, 1));
$d7hb = hex(substr($Data, 48+96+96+96, 1));
$d7lb = hex(substr($Data, 49+96+96+96, 1));
$nam1c1 = $d0lb + $d0hb * 16;
$nam1c2 = $d1lb + $d1hb * 16;
$nam1c1 = chr($nam1c1);
$nam1c2 = chr($nam1c2);
$nam1c3 = $d2lb + $d2hb * 16;
$nam1c4 = $d3lb + $d3hb * 16;
$nam1c3 = chr($nam1c3);
$nam1c4 = chr($nam1c4);
$nam1c5 = $d4lb + $d4hb * 16;
$nam1c6 = $d5lb + $d5hb * 16;
$nam1c5 = chr($nam1c5);
$nam1c6 = chr($nam1c6);
$nam1c7 = $d6lb + $d6hb * 16;
$nam1c8 = $d7lb + $d7hb * 16;
$nam1c7 = chr($nam1c7);
$nam1c8 = chr($nam1c8);
$nam4 = "$nam1c1$nam1c2$nam1c3$nam1c4$nam1c5$nam1c6$nam1c7$nam1c8";
$nam1c1 = 0;
$nam1c2 = 0;
$nam1c3 = 0;
$nam1c4 = 0;
$nam1c5 = 0;
$nam1c6 = 0;
$nam1c7 = 0;
$nam1c8 = 0;


$nam5 = substr($Data, 34+96+96+96+96, 32);
$d0hb = hex(substr($Data, 34+96+96+96+96, 1));
$d0lb = hex(substr($Data, 35+96+96+96+96, 1));
$d1hb = hex(substr($Data, 36+96+96+96+96, 1));
$d1lb = hex(substr($Data, 37+96+96+96+96, 1));
$d2hb = hex(substr($Data, 38+96+96+96+96, 1));
$d2lb = hex(substr($Data, 39+96+96+96+96, 1));
$d3hb = hex(substr($Data, 40+96+96+96+96, 1));
$d3lb = hex(substr($Data, 41+96+96+96+96, 1));
$d4hb = hex(substr($Data, 42+96+96+96+96, 1));
$d4lb = hex(substr($Data, 43+96+96+96+96, 1));
$d5hb = hex(substr($Data, 44+96+96+96+96, 1));
$d5lb = hex(substr($Data, 45+96+96+96+96, 1));
$d6hb = hex(substr($Data, 46+96+96+96+96, 1));
$d6lb = hex(substr($Data, 47+96+96+96+96, 1));
$d7hb = hex(substr($Data, 48+96+96+96+96, 1));
$d7lb = hex(substr($Data, 49+96+96+96+96, 1));
$nam1c1 = $d0lb + $d0hb * 16;
$nam1c2 = $d1lb + $d1hb * 16;
$nam1c1 = chr($nam1c1);
$nam1c2 = chr($nam1c2);
$nam1c3 = $d2lb + $d2hb * 16;
$nam1c4 = $d3lb + $d3hb * 16;
$nam1c3 = chr($nam1c3);
$nam1c4 = chr($nam1c4);
$nam1c5 = $d4lb + $d4hb * 16;
$nam1c6 = $d5lb + $d5hb * 16;
$nam1c5 = chr($nam1c5);
$nam1c6 = chr($nam1c6);
$nam1c7 = $d6lb + $d6hb * 16;
$nam1c8 = $d7lb + $d7hb * 16;
$nam1c7 = chr($nam1c7);
$nam1c8 = chr($nam1c8);
$nam5 = "$nam1c1$nam1c2$nam1c3$nam1c4$nam1c5$nam1c6$nam1c7$nam1c8";
$nam1c1 = 0;
$nam1c2 = 0;
$nam1c3 = 0;
$nam1c4 = 0;
$nam1c5 = 0;
$nam1c6 = 0;
$nam1c7 = 0;
$nam1c8 = 0;

$nam6 = substr($Data, 34+96+96+96+96+96, 32);
$d0hb = hex(substr($Data, 34+96+96+96+96+96, 1));
$d0lb = hex(substr($Data, 35+96+96+96+96+96, 1));
$d1hb = hex(substr($Data, 36+96+96+96+96+96, 1));
$d1lb = hex(substr($Data, 37+96+96+96+96+96, 1));
$d2hb = hex(substr($Data, 38+96+96+96+96+96, 1));
$d2lb = hex(substr($Data, 39+96+96+96+96+96, 1));
$d3hb = hex(substr($Data, 40+96+96+96+96+96, 1));
$d3lb = hex(substr($Data, 41+96+96+96+96+96, 1));
$d4hb = hex(substr($Data, 42+96+96+96+96+96, 1));
$d4lb = hex(substr($Data, 43+96+96+96+96+96, 1));
$d5hb = hex(substr($Data, 44+96+96+96+96+96, 1));
$d5lb = hex(substr($Data, 45+96+96+96+96+96, 1));
$d6hb = hex(substr($Data, 46+96+96+96+96+96, 1));
$d6lb = hex(substr($Data, 47+96+96+96+96+96, 1));
$d7hb = hex(substr($Data, 48+96+96+96+96+96, 1));
$d7lb = hex(substr($Data, 49+96+96+96+96+96, 1));
$nam1c1 = $d0lb + $d0hb * 16;
$nam1c2 = $d1lb + $d1hb * 16;
$nam1c1 = chr($nam1c1);
$nam1c2 = chr($nam1c2);
$nam1c3 = $d2lb + $d2hb * 16;
$nam1c4 = $d3lb + $d3hb * 16;
$nam1c3 = chr($nam1c3);
$nam1c4 = chr($nam1c4);
$nam1c5 = $d4lb + $d4hb * 16;
$nam1c6 = $d5lb + $d5hb * 16;
$nam1c5 = chr($nam1c5);
$nam1c6 = chr($nam1c6);
$nam1c7 = $d6lb + $d6hb * 16;
$nam1c8 = $d7lb + $d7hb * 16;
$nam1c7 = chr($nam1c7);
$nam1c8 = chr($nam1c8);
$nam6 = "$nam1c1$nam1c2$nam1c3$nam1c4$nam1c5$nam1c6$nam1c7$nam1c8";
$nam1c1 = 0;
$nam1c2 = 0;
$nam1c3 = 0;
$nam1c4 = 0;
$nam1c5 = 0;
$nam1c6 = 0;
$nam1c7 = 0;
$nam1c8 = 0;


# new way ############################################EARL#

$IP1 = substr($Data,2,12);
$connectedtoo1 = ($Data3);
$ch = $Data6;
$mo = oct($Data5);

 
 if ($mo == 1) {$Data5 = "Point to Multi-Point";
  }
 if ($mo == 2) {$Data5 = "AP";
  }
 if ($mo == 3) {$Data5 = "AP Client";
  }
 if ($mo == 4) {$Data5 = "Point to Point";
  }
 if ($mo == 5) {$Data5 = "Repeater";
  }
 

$d0hb = hex(substr($Data, 14, 1));
$d0lb = hex(substr($Data, 15, 1));
$d1hb = hex(substr($Data, 16, 1));
$d1lb = hex(substr($Data, 17, 1));
$rssi1total = $d0lb + $d0hb * 16;
$lq1total = $d1lb + $d1hb * 16;

  {
 if ( $Percentage == 1 ) {
    $rssi = $rssi1total;
    $link = $lq1total;
    if ($rssi > $MAX_RSSI) {
      $rssi = 40;
    }
    if ($link > $MAX_RSSI) {
      $link = 40;
    }
    $linkvalue = ($MAX_RSSI - $link);
    $rssi1total = ( $rssi / $MAX_RSSI ) * 100;
    $lq1total = ( $linkvalue / $MAX_RSSI ) * 100;
  }

}
$rssi1total = int($rssi1total);
$lq1total = int($lq1total);

$d0hb = hex(substr($Data, 14+96, 1));
$d0lb = hex(substr($Data, 15+96, 1));
$d1hb = hex(substr($Data, 16+96, 1));
$d1lb = hex(substr($Data, 17+96, 1));
$rssi2total = $d0lb + $d0hb * 16;
$lq2total = $d1lb + $d1hb * 16;

  {
 if ( $Percentage == 1 ) {
    $rssi = $rssi2total;
    $link = $lq2total;
    if ($rssi > $MAX_RSSI) {
      $rssi = 40;
    }
    if ($link > $MAX_RSSI) {
      $link = 40;
    }
    $linkvalue = ($MAX_RSSI - $link);
    $rssi2total = ( $rssi / $MAX_RSSI ) * 100;
    $lq2total = ( $linkvalue / $MAX_RSSI ) * 100;
  }

}

$rssi2total = int($rssi2total);
$lq2total = int($lq2total);

$IP2 = substr($Data,2+96,12);

$d0hb = hex(substr($Data, 14+96+96, 1));
$d0lb = hex(substr($Data, 15+96+96, 1));
$d1hb = hex(substr($Data, 16+96+96, 1));
$d1lb = hex(substr($Data, 17+96+96, 1));
$rssi3total = $d0lb + $d0hb * 16;
$lq3total = $d1lb + $d1hb * 16;

   {
  if ( $Percentage == 1 ) {
     $rssi = $rssi3total;
     $link = $lq3total;
     if ($rssi > $MAX_RSSI) {
       $rssi = 40;
     }
     if ($link > $MAX_RSSI) {
       $link = 40;
     }
     $linkvalue = ($MAX_RSSI - $link);
     $rssi3total = ( $rssi / $MAX_RSSI ) * 100;
     $lq3total = ( $linkvalue / $MAX_RSSI ) * 100;
   }
 
 }
$rssi3total = int($rssi3total);
$lq3total = int($lq3total);

$IP3 = substr($Data,2+96+96,12);

$d0hb = hex(substr($Data, 14+96+96+96, 1));
$d0lb = hex(substr($Data, 15+96+96+96, 1));
$d1hb = hex(substr($Data, 16+96+96+96, 1));
$d1lb = hex(substr($Data, 17+96+96+96, 1));
$rssi4total = $d0lb + $d0hb * 16;
$lq4total = $d1lb + $d1hb * 16;

  {
 if ( $Percentage == 1 ) {
    $rssi = $rssi4total;
    $link = $lq4total;
    if ($rssi > $MAX_RSSI) {
      $rssi = 40;
    }
    if ($link > $MAX_RSSI) {
      $link = 40;
    }
    $linkvalue = ($MAX_RSSI - $link);
    $rssi4total = ( $rssi / $MAX_RSSI ) * 100;
    $lq4total = ( $linkvalue / $MAX_RSSI ) * 100;
  }

}
$rssi4total = int($rssi4total);
$lq4total = int($lq4total);

$IP4 = substr($Data,2+96+96+96,12);

$d0hb = hex(substr($Data, 14+96+96+96+96, 1));
$d0lb = hex(substr($Data, 15+96+96+96+96, 1));
$d1hb = hex(substr($Data, 16+96+96+96+96, 1));
$d1lb = hex(substr($Data, 17+96+96+96+96, 1));
$rssi5total = $d0lb + $d0hb * 16;
$lq5total = $d1lb + $d1hb * 16;

  {
 if ( $Percentage == 1 ) {
    $rssi = $rssi5total;
    $link = $lq5total;
    if ($rssi > $MAX_RSSI) {
      $rssi = 40;
    }
    if ($link > $MAX_RSSI) {
      $link = 40;
    }
    $linkvalue = ($MAX_RSSI - $link);
    $rssi5total = ( $rssi / $MAX_RSSI ) * 100;
    $lq5total = ( $linkvalue / $MAX_RSSI ) * 100;
  }

}

$rssi5total = int($rssi5total);
$lq5total = int($lq5total);

$IP5 = substr($Data,2+96+96+96+96,12);

$d0hb = hex(substr($Data, 14+96+96+96+96+96, 1));
$d0lb = hex(substr($Data, 15+96+96+96+96+96, 1));
$d1hb = hex(substr($Data, 16+96+96+96+96+96, 1));
$d1lb = hex(substr($Data, 17+96+96+96+96+96, 1));
$rssi6total = $d0lb + $d0hb * 16;
$lq6total = $d1lb + $d1hb * 16;

  {
 if ( $Percentage == 1 ) {
    $rssi = $rssi6total;
    $link = $lq6total;
    if ($rssi > $MAX_RSSI) {
      $rssi = 40;
    }
    if ($link > $MAX_RSSI) {
      $link = 40;
    }
    $linkvalue = ($MAX_RSSI - $link);
    $rssi6total = ( $rssi / $MAX_RSSI ) * 100;
    $lq6total = ( $linkvalue / $MAX_RSSI ) * 100;
  }

}

$rssi6total = int($rssi6total);
$lq6total = int($lq6total);

$IP6 = substr($Data,2+96+96+96+96+96,12);

$Data7 = substr($Data7,2,32);
$ch1pwr = substr($Data7,0,2);
$ch2pwr = substr($Data7,2,2);
$ch3pwr = substr($Data7,4,2);
$ch4pwr = substr($Data7,6,2);
$ch5pwr = substr($Data7,8,2);
$ch6pwr = substr($Data7,10,2);
$ch7pwr = substr($Data7,12,2);
$ch8pwr = substr($Data7,14,2);
$ch9pwr = substr($Data7,16,2);
$ch10pwr = substr($Data7,18,2);
$ch11pwr = substr($Data7,20,2);
$ch12pwr = substr($Data7,22,2);
$ch13pwr = substr($Data7,24,2);
$ch14pwr = substr($Data7,26,2);

# Return lines of data


 
 
    print " \n";
    print "Atmel Chipset Radio Information";
    print " \n";
    print "(SmartBridges APPO - API - D-Link DWL-900AP - Other Atmel Based Chipsets)";
    print " \n";
    print "by Earl Campbell - UpHi.net 08/17/2003";
    print " \n";
    print " \n";
    print "Name of Radio     ",$Data_sysDescr;
    print " \n";
    print "Associated to     ",$Data3;
    print " \n";
    print "On Channel        ",$ch;
    print " \n";
    print "In Mode           ",$Data5;
    print " \n";
    print " \n";
    print "CR31 Power Control Regs Min 0----(Max)80----FF Min  ";
    print " \n";
    print " \n";
print "  Ch 1                             ",$ch1pwr;
    print " \n";
print "  Ch 2                             ",$ch2pwr;
    print " \n";
print "  Ch 3                             ",$ch3pwr;
    print " \n";
print "  Ch 4                             ",$ch4pwr;
    print " \n";
print "  Ch 5                             ",$ch5pwr;
    print " \n";
print "  Ch 6                             ",$ch6pwr;
    print " \n";
print "  Ch 7                             ",$ch7pwr;
    print " \n";
print "  Ch 8                             ",$ch8pwr;
    print " \n";
print "  Ch 9                             ",$ch9pwr;
    print " \n";
print "  Ch 10                            ",$ch10pwr;
    print " \n";
print "  Ch 11                            ",$ch11pwr;
    print " \n";
print "  Ch 12                            ",$ch12pwr;
    print " \n";
print "  Ch 13                            ",$ch13pwr;
    print " \n";
print "  Ch 14                            ",$ch14pwr;
    print " \n";
    print " \n";

    print "Site 1            ",$IP1," ",$nam1;
    print " \n";
    print "RSSI %            ",$rssi1total;
    print " \n";
    print "Link %            ",$lq1total;
    print " \n";
    print " \n";
 
    print "Site 2            ",$IP2," ",$nam2;
    print " \n";
    print "RSSI %            ",$rssi2total;
    print " \n";
    print "Link %            ",$lq2total;
    print " \n";
    print " \n";
 
    print "Site 3            ",$IP3," ",$nam3;
    print " \n";
    print "RSSI %            ",$rssi3total;
    print " \n";
    print "Link %            ",$lq3total;
    print " \n";
    print " \n";
 
    print "Site 4            ",$IP4," ",$nam4;
    print " \n";
    print "RSSI %            ",$rssi4total;
    print " \n";
    print "Link %            ",$lq4total;
    print " \n";
    print " \n";

    print "Site 5            ",$IP5," ",$nam5;
    print " \n";
    print "RSSI %            ",$rssi5total;
    print " \n";
    print "Link %            ",$lq5total;
    print " \n";
    print " \n";
 
    print "Site 6            ",$IP6," ",$nam6;
    print " \n";
    print "RSSI %            ",$rssi6total;
    print " \n";
    print "Link %            ",$lq6total;
    print " \n";
    print " \n";
 
    print "OEMname           ",$OEM1;
    print " \n";
    print " \n";
    print "Data for IP       ",$host;
    print " \n";
    print " \n";
    
$Data = snmpQuery($session,$WLstatisticsGRP);

    
$UnicastTransmittedPackets = substr($Data,2,8);
$Total = "0";
$conv = $UnicastTransmittedPackets;
$d0hb = hex(substr($conv, 0, 1));
$d0lb = hex(substr($conv, 1, 1));
$d1hb = hex(substr($conv, 2, 1));
$d1lb = hex(substr($conv, 3, 1));
$d2hb = hex(substr($conv, 4, 1));
$d2lb = hex(substr($conv, 5, 1));
$d3hb = hex(substr($conv, 6, 1));
$d3lb = hex(substr($conv, 7, 1));
$H1 = $d0lb + $d0hb * 16;
$L1 = $d1lb * 256 + ($d1hb * 4096);
$H2 = ($d2lb * 65536) + ($d2hb * (65536 * 16));
$L2 = ($d3lb * (65536 * 256)) + ($d3hb * (65536 * 4096));
$Total = ($L1) + ($H1) + ($L2) + ($H2);

    print "UnicastTransmittedPackets   ",$Total;
    print " \n";
    
$BroadcastTransmittedPackets = substr($Data,10,8);
$Total = "0";
$conv = $BroadcastTransmittedPackets;
$d0hb = hex(substr($conv, 0, 1));
$d0lb = hex(substr($conv, 1, 1));
$d1hb = hex(substr($conv, 2, 1));
$d1lb = hex(substr($conv, 3, 1));
$d2hb = hex(substr($conv, 4, 1));
$d2lb = hex(substr($conv, 5, 1));
$d3hb = hex(substr($conv, 6, 1));
$d3lb = hex(substr($conv, 7, 1));
$H1 = $d0lb + $d0hb * 16;
$L1 = $d1lb * 256 + ($d1hb * 4096);
$H2 = ($d2lb * 65536) + ($d2hb * (65536 * 16));
$L2 = ($d3lb * (65536 * 256)) + ($d3hb * (65536 * 4096));
$Total = ($L1) + ($H1) + ($L2) + ($H2);

    print "BroadcastTransmittedPackets ",$Total;
    print " \n";

$MulticastTransmittedPackets = substr($Data,18,8);
$Total = "0";
$conv = $MulticastTransmittedPackets;
$d0hb = hex(substr($conv, 0, 1));
$d0lb = hex(substr($conv, 1, 1));
$d1hb = hex(substr($conv, 2, 1));
$d1lb = hex(substr($conv, 3, 1));
$d2hb = hex(substr($conv, 4, 1));
$d2lb = hex(substr($conv, 5, 1));
$d3hb = hex(substr($conv, 6, 1));
$d3lb = hex(substr($conv, 7, 1));
$H1 = $d0lb + $d0hb * 16;
$L1 = $d1lb * 256 + ($d1hb * 4096);
$H2 = ($d2lb * 65536) + ($d2hb * (65536 * 16));
$L2 = ($d3lb * (65536 * 256)) + ($d3hb * (65536 * 4096));
$Total = ($L1) + ($H1) + ($L2) + ($H2);
    print "MulticastTransmittedPackets ",$Total;
    print " \n";
    
$TransmittedBeacon = substr($Data,26,8);
$Total = "0";
$conv = $TransmittedBeacon;
$d0hb = hex(substr($conv, 0, 1));
$d0lb = hex(substr($conv, 1, 1));
$d1hb = hex(substr($conv, 2, 1));
$d1lb = hex(substr($conv, 3, 1));
$d2hb = hex(substr($conv, 4, 1));
$d2lb = hex(substr($conv, 5, 1));
$d3hb = hex(substr($conv, 6, 1));
$d3lb = hex(substr($conv, 7, 1));
$H1 = $d0lb + $d0hb * 16;
$L1 = $d1lb * 256 + ($d1hb * 4096);
$H2 = ($d2lb * 65536) + ($d2hb * (65536 * 16));
$L2 = ($d3lb * (65536 * 256)) + ($d3hb * (65536 * 4096));
$Total = ($L1) + ($H1) + ($L2) + ($H2);
    print "TransmittedBeacon           ",$Total;
    print " \n";
    
$TransmittedACK = substr($Data,34,8);
$Total = "0";
$conv = $TransmittedACK;
$d0hb = hex(substr($conv, 0, 1));
$d0lb = hex(substr($conv, 1, 1));
$d1hb = hex(substr($conv, 2, 1));
$d1lb = hex(substr($conv, 3, 1));
$d2hb = hex(substr($conv, 4, 1));
$d2lb = hex(substr($conv, 5, 1));
$d3hb = hex(substr($conv, 6, 1));
$d3lb = hex(substr($conv, 7, 1));
$H1 = $d0lb + $d0hb * 16;
$L1 = $d1lb * 256 + ($d1hb * 4096);
$H2 = ($d2lb * 65536) + ($d2hb * (65536 * 16));
$L2 = ($d3lb * (65536 * 256)) + ($d3hb * (65536 * 4096));
$Total = ($L1) + ($H1) + ($L2) + ($H2);
    print "TransmittedACK              ",$Total;
    print " \n";
    
$TransmittedRTS = substr($Data,42,8);
$Total = "0";
$conv = $TransmittedRTS;
$d0hb = hex(substr($conv, 0, 1));
$d0lb = hex(substr($conv, 1, 1));
$d1hb = hex(substr($conv, 2, 1));
$d1lb = hex(substr($conv, 3, 1));
$d2hb = hex(substr($conv, 4, 1));
$d2lb = hex(substr($conv, 5, 1));
$d3hb = hex(substr($conv, 6, 1));
$d3lb = hex(substr($conv, 7, 1));
$H1 = $d0lb + $d0hb * 16;
$L1 = $d1lb * 256 + ($d1hb * 4096);
$H2 = ($d2lb * 65536) + ($d2hb * (65536 * 16));
$L2 = ($d3lb * (65536 * 256)) + ($d3hb * (65536 * 4096));
$Total = ($L1) + ($H1) + ($L2) + ($H2);
    print "TransmittedRTS              ",$Total;
    print " \n";
    
$TransmittedCTS = substr($Data,50,8);
$Total = "0";
$conv = $TransmittedCTS;
$d0hb = hex(substr($conv, 0, 1));
$d0lb = hex(substr($conv, 1, 1));
$d1hb = hex(substr($conv, 2, 1));
$d1lb = hex(substr($conv, 3, 1));
$d2hb = hex(substr($conv, 4, 1));
$d2lb = hex(substr($conv, 5, 1));
$d3hb = hex(substr($conv, 6, 1));
$d3lb = hex(substr($conv, 7, 1));
$H1 = $d0lb + $d0hb * 16;
$L1 = $d1lb * 256 + ($d1hb * 4096);
$H2 = ($d2lb * 65536) + ($d2hb * (65536 * 16));
$L2 = ($d3lb * (65536 * 256)) + ($d3hb * (65536 * 4096));
$Total = ($L1) + ($H1) + ($L2) + ($H2);
   print "TransmittedCTS              ",$Total;
    print " \n";
    
$UnicastReceivedPackets = substr($Data,58,8);
$Total = "0";
$conv = $UnicastReceivedPackets;
$d0hb = hex(substr($conv, 0, 1));
$d0lb = hex(substr($conv, 1, 1));
$d1hb = hex(substr($conv, 2, 1));
$d1lb = hex(substr($conv, 3, 1));
$d2hb = hex(substr($conv, 4, 1));
$d2lb = hex(substr($conv, 5, 1));
$d3hb = hex(substr($conv, 6, 1));
$d3lb = hex(substr($conv, 7, 1));
$H1 = $d0lb + $d0hb * 16;
$L1 = $d1lb * 256 + ($d1hb * 4096);
$H2 = ($d2lb * 65536) + ($d2hb * (65536 * 16));
$L2 = ($d3lb * (65536 * 256)) + ($d3hb * (65536 * 4096));
$Total = ($L1) + ($H1) + ($L2) + ($H2);
    print "UnicastReceivedPackets      ",$Total;
    print " \n";
    
$BroadcastReceivedPackets = substr($Data,66,8);
$Total = "0";
$conv = $BroadcastReceivedPackets;
$d0hb = hex(substr($conv, 0, 1));
$d0lb = hex(substr($conv, 1, 1));
$d1hb = hex(substr($conv, 2, 1));
$d1lb = hex(substr($conv, 3, 1));
$d2hb = hex(substr($conv, 4, 1));
$d2lb = hex(substr($conv, 5, 1));
$d3hb = hex(substr($conv, 6, 1));
$d3lb = hex(substr($conv, 7, 1));
$H1 = $d0lb + $d0hb * 16;
$L1 = $d1lb * 256 + ($d1hb * 4096);
$H2 = ($d2lb * 65536) + ($d2hb * (65536 * 16));
$L2 = ($d3lb * (65536 * 256)) + ($d3hb * (65536 * 4096));
$Total = ($L1) + ($H1) + ($L2) + ($H2);
    print "BroadcastReceivedPackets    ",$Total;
    print " \n";
    
$MulticastReceivedPackets = substr($Data,74,8);
$Total = "0";
$conv = $MulticastReceivedPackets;
$d0hb = hex(substr($conv, 0, 1));
$d0lb = hex(substr($conv, 1, 1));
$d1hb = hex(substr($conv, 2, 1));
$d1lb = hex(substr($conv, 3, 1));
$d2hb = hex(substr($conv, 4, 1));
$d2lb = hex(substr($conv, 5, 1));
$d3hb = hex(substr($conv, 6, 1));
$d3lb = hex(substr($conv, 7, 1));
$H1 = $d0lb + $d0hb * 16;
$L1 = $d1lb * 256 + ($d1hb * 4096);
$H2 = ($d2lb * 65536) + ($d2hb * (65536 * 16));
$L2 = ($d3lb * (65536 * 256)) + ($d3hb * (65536 * 4096));
$Total = ($L1) + ($H1) + ($L2) + ($H2);
    print "MulticastReceivedPackets    ",$Total;
    print " \n";
    
$ReceivedBeacon = substr($Data,82,8);
$Total = "0";
$conv = $ReceivedBeacon;
$d0hb = hex(substr($conv, 0, 1));
$d0lb = hex(substr($conv, 1, 1));
$d1hb = hex(substr($conv, 2, 1));
$d1lb = hex(substr($conv, 3, 1));
$d2hb = hex(substr($conv, 4, 1));
$d2lb = hex(substr($conv, 5, 1));
$d3hb = hex(substr($conv, 6, 1));
$d3lb = hex(substr($conv, 7, 1));
$H1 = $d0lb + $d0hb * 16;
$L1 = $d1lb * 256 + ($d1hb * 4096);
$H2 = ($d2lb * 65536) + ($d2hb * (65536 * 16));
$L2 = ($d3lb * (65536 * 256)) + ($d3hb * (65536 * 4096));
$Total = ($L1) + ($H1) + ($L2) + ($H2);
    print "ReceivedBeacon              ",$Total;
    print " \n";
    
$ReceivedACK = substr($Data,90,8);
$Total = "0";
$conv = $ReceivedACK;
$d0hb = hex(substr($conv, 0, 1));
$d0lb = hex(substr($conv, 1, 1));
$d1hb = hex(substr($conv, 2, 1));
$d1lb = hex(substr($conv, 3, 1));
$d2hb = hex(substr($conv, 4, 1));
$d2lb = hex(substr($conv, 5, 1));
$d3hb = hex(substr($conv, 6, 1));
$d3lb = hex(substr($conv, 7, 1));
$H1 = $d0lb + $d0hb * 16;
$L1 = $d1lb * 256 + ($d1hb * 4096);
$H2 = ($d2lb * 65536) + ($d2hb * (65536 * 16));
$L2 = ($d3lb * (65536 * 256)) + ($d3hb * (65536 * 4096));
$Total = ($L1) + ($H1) + ($L2) + ($H2);
    print "ReceivedACK                 ",$Total;
    print " \n";
    
$ReceivedRTS = substr($Data,98,8);
$Total = "0";
$conv = $ReceivedRTS;
$d0hb = hex(substr($conv, 0, 1));
$d0lb = hex(substr($conv, 1, 1));
$d1hb = hex(substr($conv, 2, 1));
$d1lb = hex(substr($conv, 3, 1));
$d2hb = hex(substr($conv, 4, 1));
$d2lb = hex(substr($conv, 5, 1));
$d3hb = hex(substr($conv, 6, 1));
$d3lb = hex(substr($conv, 7, 1));
$H1 = $d0lb + $d0hb * 16;
$L1 = $d1lb * 256 + ($d1hb * 4096);
$H2 = ($d2lb * 65536) + ($d2hb * (65536 * 16));
$L2 = ($d3lb * (65536 * 256)) + ($d3hb * (65536 * 4096));
$Total = ($L1) + ($H1) + ($L2) + ($H2);
    print "ReceivedRTS                 ",$Total;
   print " \n";
    
$ReceivedCTS = substr($Data,106,8);
$Total = "0";
$conv = $ReceivedACK;
$d0hb = hex(substr($conv, 0, 1));
$d0lb = hex(substr($conv, 1, 1));
$d1hb = hex(substr($conv, 2, 1));
$d1lb = hex(substr($conv, 3, 1));
$d2hb = hex(substr($conv, 4, 1));
$d2lb = hex(substr($conv, 5, 1));
$d3hb = hex(substr($conv, 6, 1));
$d3lb = hex(substr($conv, 7, 1));
$H1 = $d0lb + $d0hb * 16;
$L1 = $d1lb * 256 + ($d1hb * 4096);
$H2 = ($d2lb * 65536) + ($d2hb * (65536 * 16));
$L2 = ($d3lb * (65536 * 256)) + ($d3hb * (65536 * 4096));
$Total = ($L1) + ($H1) + ($L2) + ($H2);
    print "ReceivedCTS                 ",$Total;
    print " \n";
    
$ACKFailure = substr($Data,114,8);
$Total = "0";
$conv = $ACKFailure;
$d0hb = hex(substr($conv, 0, 1));
$d0lb = hex(substr($conv, 1, 1));
$d1hb = hex(substr($conv, 2, 1));
$d1lb = hex(substr($conv, 3, 1));
$d2hb = hex(substr($conv, 4, 1));
$d2lb = hex(substr($conv, 5, 1));
$d3hb = hex(substr($conv, 6, 1));
$d3lb = hex(substr($conv, 7, 1));
$H1 = $d0lb + $d0hb * 16;
$L1 = $d1lb * 256 + ($d1hb * 4096);
$H2 = ($d2lb * 65536) + ($d2hb * (65536 * 16));
$L2 = ($d3lb * (65536 * 256)) + ($d3hb * (65536 * 4096));
$Total = ($L1) + ($H1) + ($L2) + ($H2);
    print "ACKFailure                  ",$Total;
    print " \n";

$CTSFailure = substr($Data,122,8);
$Total = "0";
$conv = $CTSFailure;
$d0hb = hex(substr($conv, 0, 1));
$d0lb = hex(substr($conv, 1, 1));
$d1hb = hex(substr($conv, 2, 1));
$d1lb = hex(substr($conv, 3, 1));
$d2hb = hex(substr($conv, 4, 1));
$d2lb = hex(substr($conv, 5, 1));
$d3hb = hex(substr($conv, 6, 1));
$d3lb = hex(substr($conv, 7, 1));
$H1 = $d0lb + $d0hb * 16;
$L1 = $d1lb * 256 + ($d1hb * 4096);
$H2 = ($d2lb * 65536) + ($d2hb * (65536 * 16));
$L2 = ($d3lb * (65536 * 256)) + ($d3hb * (65536 * 4096));
$Total = ($L1) + ($H1) + ($L2) + ($H2);
    print "CTSFailure                  ",$Total;
    print " \n";
    
$RetryPackets = substr($Data,130,8);
$Total = "0";
$conv = $RetryPackets;
$d0hb = hex(substr($conv, 0, 1));
$d0lb = hex(substr($conv, 1, 1));
$d1hb = hex(substr($conv, 2, 1));
$d1lb = hex(substr($conv, 3, 1));
$d2hb = hex(substr($conv, 4, 1));
$d2lb = hex(substr($conv, 5, 1));
$d3hb = hex(substr($conv, 6, 1));
$d3lb = hex(substr($conv, 7, 1));
$H1 = $d0lb + $d0hb * 16;
$L1 = $d1lb * 256 + ($d1hb * 4096);
$H2 = ($d2lb * 65536) + ($d2hb * (65536 * 16));
$L2 = ($d3lb * (65536 * 256)) + ($d3hb * (65536 * 4096));
$Total = ($L1) + ($H1) + ($L2) + ($H2);
    print "RetryPackets                ",$Total;
    print " \n";
    
$ReceivedDuplicate = substr($Data,138,8);
$Total = "0";
$conv = $RetryDuplicate;
$d0hb = hex(substr($conv, 0, 1));
$d0lb = hex(substr($conv, 1, 1));
$d1hb = hex(substr($conv, 2, 1));
$d1lb = hex(substr($conv, 3, 1));
$d2hb = hex(substr($conv, 4, 1));
$d2lb = hex(substr($conv, 5, 1));
$d3hb = hex(substr($conv, 6, 1));
$d3lb = hex(substr($conv, 7, 1));
$H1 = $d0lb + $d0hb * 16;
$L1 = $d1lb * 256 + ($d1hb * 4096);
$H2 = ($d2lb * 65536) + ($d2hb * (65536 * 16));
$L2 = ($d3lb * (65536 * 256)) + ($d3hb * (65536 * 4096));
$Total = ($L1) + ($H1) + ($L2) + ($H2);
    print "RetryDuplicate              ",$Total;
    print " \n";
    
$FailedPackets = substr($Data,146,8);
$Total = "0";
$conv = $FailedPackets;
$d0hb = hex(substr($conv, 0, 1));
$d0lb = hex(substr($conv, 1, 1));
$d1hb = hex(substr($conv, 2, 1));
$d1lb = hex(substr($conv, 3, 1));
$d2hb = hex(substr($conv, 4, 1));
$d2lb = hex(substr($conv, 5, 1));
$d3hb = hex(substr($conv, 6, 1));
$d3lb = hex(substr($conv, 7, 1));
$H1 = $d0lb + $d0hb * 16;
$L1 = $d1lb * 256 + ($d1hb * 4096);
$H2 = ($d2lb * 65536) + ($d2hb * (65536 * 16));
$L2 = ($d3lb * (65536 * 256)) + ($d3hb * (65536 * 4096));
$Total = ($L1) + ($H1) + ($L2) + ($H2);
    print "FailedPackets               ",$Total;
    print " \n";
    
$AgedPackets = substr($Data,154,8);
$Total = "0";
$conv = $AgedPackets;
$d0hb = hex(substr($conv, 0, 1));
$d0lb = hex(substr($conv, 1, 1));
$d1hb = hex(substr($conv, 2, 1));
$d1lb = hex(substr($conv, 3, 1));
$d2hb = hex(substr($conv, 4, 1));
$d2lb = hex(substr($conv, 5, 1));
$d3hb = hex(substr($conv, 6, 1));
$d3lb = hex(substr($conv, 7, 1));
$H1 = $d0lb + $d0hb * 16;
$L1 = $d1lb * 256 + ($d1hb * 4096);
$H2 = ($d2lb * 65536) + ($d2hb * (65536 * 16));
$L2 = ($d3lb * (65536 * 256)) + ($d3hb * (65536 * 4096));
$Total = ($L1) + ($H1) + ($L2) + ($H2);
    print "AgedPackets                 ",$Total;
    print " \n";
    
$FCSError = substr($Data,162,8);
$Total = "0";
$conv = $FCSError;
$d0hb = hex(substr($conv, 0, 1));
$d0lb = hex(substr($conv, 1, 1));
$d1hb = hex(substr($conv, 2, 1));
$d1lb = hex(substr($conv, 3, 1));
$d2hb = hex(substr($conv, 4, 1));
$d2lb = hex(substr($conv, 5, 1));
$d3hb = hex(substr($conv, 6, 1));
$d3lb = hex(substr($conv, 7, 1));
$H1 = $d0lb + $d0hb * 16;
$L1 = $d1lb * 256 + ($d1hb * 4096);
$H2 = ($d2lb * 65536) + ($d2hb * (65536 * 16));
$L2 = ($d3lb * (65536 * 256)) + ($d3hb * (65536 * 4096));
$Total = ($L1) + ($H1) + ($L2) + ($H2);
    print "FCSError                    ",$Total;
    print " \n";
    
$InvalidPLCP = substr($Data,170,8);
$Total = "0";
$conv = $InvalidPLCP;
$d0hb = hex(substr($conv, 0, 1));
$d0lb = hex(substr($conv, 1, 1));
$d1hb = hex(substr($conv, 2, 1));
$d1lb = hex(substr($conv, 3, 1));
$d2hb = hex(substr($conv, 4, 1));
$d2lb = hex(substr($conv, 5, 1));
$d3hb = hex(substr($conv, 6, 1));
$d3lb = hex(substr($conv, 7, 1));
$H1 = $d0lb + $d0hb * 16;
$L1 = $d1lb * 256 + ($d1hb * 4096);
$H2 = ($d2lb * 65536) + ($d2hb * (65536 * 16));
$L2 = ($d3lb * (65536 * 256)) + ($d3hb * (65536 * 4096));
$Total = ($L1) + ($H1) + ($L2) + ($H2);
    print "InvalidPLCP                 ",$Total;
    print " \n";
    print " \n";
  
    print "Wireless Raw Data     ";
    print " \n";
    print " \n",$Data;
    print " \n";
    print " \n";

# All Done. Close.  
$session->close;
exit 0;


#The actual query control, depending on the type. 
sub snmpQuery() {
    my ($session, $result,$resultval,@values,$retval,@Rest,$query,$type);
    ($session,$query,$type) = @_;
    $result = $session->get_request(
				    -varbindlist => [$query]
				    );
#
# The error check is important, more so, if the values 
# returned is not correct. This messes up the logs!
#
    if (!defined($result)) {
#
# Ideally this should be handled by the MRTG properly. 
#	printf("ERROR: %s.\n", $session->error);
	$session->close;
# Though its wrong to return '0' as exit code for an error, we'd 
# do this so that MRTG behaves.
	return;
	exit 0;
    }

    $resultval = $result->{$query};
    if ( $type == 0 ) { 
	(@Rest) = split(" ",$resultval);
	($retval,@Rest) = reverse(@Rest);
    }
    if ( $type == 1 ) {
	@values = hexString($resultval);
	($retval,@Rest) = @values;
    } 
    if ( $type == 2 ) {
	@values = hexString($resultval);
	my ( $UTPax, $BTPax, $MTPax, $TBecon, $TACK, $TRTS, $TCTS, $URPax, $BRPax, $MRPax, @Rest) = @values;
	$retval = $UTPax + $BTPax + $MTPax;	
    }
    if ( $type == 3 ) {
	@values = hexString($resultval);
	my ( $UTPax, $BTPax, $MTPax, $TBecon, $TACK, $TRTS, $TCTS, $URPax, $BRPax, $MRPax, @Rest) = @values;
	$retval = $URPax + $BRPax + $MRPax;	
    }
    if ($type == 4 ){
	$retval = $resultval;
    }
    return $retval;
}



# For the case of the Hex-String, the string needs to be broken into
# the octets, and they are read in reverse. 
sub hexString() {
    my (@vals,$dList,@Rest,$length,$i);
    ($dList,@Rest) = @_;
    $length = length($dList);

# Sanitizing by removing the 0x character first. 
    $dList = substr($dList,2,$length);
    $length = $length - 2;
# Quick and dirty extraction of values.
    $i=0;
    while ($i<$length) {
	my $val = "";
	my $k = 6;
	do {
	    my $Temp = substr($dList,$i+$k,2);
	    $val = $val.$Temp;
	    $k = $k - 2;
	} while ($k >-1);
	$i = $i+8;
	push @vals, hex($val);
    }
    return @vals;
}

