#!/usr/pkg/bin/perl -w

# parse_kismet_ap
#     Parses kismet's (http://www.kismetwireless.net) ap_manuf list for use in
#   Netdisco

# $Id: parse_kismet_ap,v 1.3 2004/03/09 22:16:52 maxbaker Exp $

my $ap = 'ap_manuf';

open (AP, "<$ap") or die "Can't open $ap. $!\n";

while (my $line = <AP>){
    chomp($line);
    $line =~ s/#.*//;
    next if $line =~ /^\s*$/;

    my @entries = split("\t",$line);

    unless (scalar @entries >= 3) {
        print "Bad Line $. : $line\n";
        next;
    }

    my ($oui,$mask) = split('/',$entries[0]);

    # cheap and dirty
    my @splitmask=split(/:/,$mask);
    my $lastchunk = 6;
    for (my $i=1;$i <= 6;$i++){
        if ($splitmask[$i] eq '00') {
            $lastchunk = $i;
            last;
        }
    }

    #                         hex digits      colons
    my $ap = uc(substr($oui,0,($lastchunk*2 + ($lastchunk-1)) ));

    my $vendor       = $entries[1];
    my $model        = $entries[2];
    my $ssid_default = $entries[3] || '';
    my $channel      = $entries[4] || '';
    my $ip           = $entries[5] || '';

    if ($model =~ /unknown/i){
        $model = '';
    } else {
        $model = ' '.$model;
    }

    print "                '$ap' => '$vendor$model',\n";
}
