Skip to content

Commit

Permalink
Start adding external antenna mapper
Browse files Browse the repository at this point in the history
  • Loading branch information
dragorn committed Sep 7, 2018
1 parent 4c32592 commit 80b5731
Show file tree
Hide file tree
Showing 4 changed files with 249 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile.in
Expand Up @@ -128,7 +128,7 @@ PSO = util.cc.o globalregistry.cc.o \
psutils.cc.o battery.cc.o \
tcpserver2.cc.o tcpclient2.cc.o serialclient2.cc.o pipeclient.cc.o ipc_remote2.cc.o \
$(PROTOBUF_CPP_O_TARGET) kis_external.cc.o \
dlttracker.cc.o datasourcetracker.cc.o kis_datasource.cc.o \
dlttracker.cc.o antennatracker.cc.o datasourcetracker.cc.o kis_datasource.cc.o \
datasource_linux_bluetooth.cc.o datasource_rtl433.cc.o \
kis_net_microhttpd.cc.o system_monitor.cc.o base64.cc.o \
kis_httpd_websession.cc.o kis_httpd_registry.cc.o \
Expand Down
110 changes: 110 additions & 0 deletions antennatracker.cc
@@ -0,0 +1,110 @@
/*
This file is part of Kismet
Kismet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Kismet is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Kismet; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

#include "config.h"
#include "antennatracker.h"

Antennatracker::Antennatracker() {
antenna_id_map =
std::make_shared<TrackerElementIntMap>();
antenna_enp =
std::make_shared<Kis_Net_Httpd_Simple_Tracked_Endpoint>("/antenna/antennas", antenna_id_map);
next_ant_id = 0;
}

Antennatracker::~Antennatracker() {
Globalreg::globalreg->RemoveGlobal("ANTENNATRACKER");
}

int Antennatracker::add_antenna(uuid in_src, int in_srcnum, int in_adjustment) {
local_locker l(mutex);

for (auto ai : *antenna_id_map) {
auto a = std::static_pointer_cast<tracked_antenna>(ai.second);

if (a->get_source_uuid() == in_src && a->get_source_antnum() == in_srcnum) {
return a->get_id();
}
}

auto ant = std::make_shared<tracked_antenna>();

uuid u;
u.GenerateRandomTimeUUID();

ant->set_id(next_ant_id++);
ant->set_source_uuid(in_src);
ant->set_source_antnum(in_srcnum);
ant->set_power_adjust(in_adjustment);

ant->set_antenna_uuid(u);

antenna_id_map->insert(ant->get_id(), ant);

return ant->get_id();
}

int Antennatracker::add_antenna(uuid in_src, int in_srcnum, int in_adjustment, uuid in_ant_uuid) {
local_locker l(mutex);

for (auto ai : *antenna_id_map) {
auto a = std::static_pointer_cast<tracked_antenna>(ai.second);

if (a->get_source_uuid() == in_src && a->get_source_antnum() == in_srcnum) {
return a->get_id();
}
}

auto ant = std::make_shared<tracked_antenna>();

ant->set_id(next_ant_id++);
ant->set_source_uuid(in_src);
ant->set_source_antnum(in_srcnum);
ant->set_power_adjust(in_adjustment);
ant->set_antenna_uuid(in_ant_uuid);

antenna_id_map->insert(ant->get_id(), ant);

return ant->get_id();
}

int Antennatracker::set_antenna_adjustment(int in_antnum, int in_adjustment) {
local_locker l(mutex);

auto ai = antenna_id_map->find(in_antnum);

if (ai == antenna_id_map->end())
return -1;

auto a = std::static_pointer_cast<tracked_antenna>(ai->second);
a->set_power_adjust(in_adjustment);

return 1;
}

std::shared_ptr<tracked_antenna> Antennatracker::get_antenna(int in_antnum) {
local_locker l(mutex);

auto ai = antenna_id_map->find(in_antnum);

if (ai == antenna_id_map->end())
return nullptr;

return std::static_pointer_cast<tracked_antenna>(ai->second);
}

134 changes: 134 additions & 0 deletions antennatracker.h
@@ -0,0 +1,134 @@
/*
This file is part of Kismet
Kismet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Kismet is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Kismet; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

#ifndef __ANTENNATRACKER_H__
#define __ANTENNATRACKER_H__

#include "config.h"
#include "kis_net_microhttpd.h"
#include "globalregistry.h"
#include "trackedcomponent.h"
#include "kis_mutex.h"

/* Antenna tracker
*
* Map per-source antennas to a common antenna ID number for fast grouping across sources.
*
* Sources should register antennas with the antenna mapping system and use those simple
* IDs for mapping to per-antenna signals.
*
* Other mechanisms, such as SDOA, can use these groupings for fast analysis
*/

class tracked_antenna : public tracker_component {
public:
tracked_antenna() :
tracker_component(0) {
register_fields();
reserve_fields(NULL);
}

tracked_antenna(int in_id) :
tracker_component(in_id) {
register_fields();
reserve_fields(NULL);
}

tracked_antenna(int in_id, std::shared_ptr<TrackerElementMap> e) :
tracker_component(in_id) {
register_fields();
reserve_fields(e);
}

virtual uint32_t get_signature() const override {
return Adler32Checksum("tracked_antenna");
}

virtual std::unique_ptr<TrackerElement> clone_type() override {
using this_t = std::remove_pointer<decltype(this)>::type;
auto dup = std::unique_ptr<this_t>(new this_t());
return std::move(dup);
}

virtual std::unique_ptr<TrackerElement> clone_type(int in_id) override {
using this_t = std::remove_pointer<decltype(this)>::type;
auto dup = std::unique_ptr<this_t>(new this_t(in_id));
return std::move(dup);
}

__Proxy(antenna_id, uint32_t, unsigned int, unsigned int, antenna_id);
__Proxy(antenna_uuid, uuid, uuid, uuid, antenna_uuid);
__Proxy(source_uuid, uuid, uuid, uuid, source_uuid);
__Proxy(source_antnum, int32_t, int32_t, int32_t, source_antnum);
__Proxy(power_adjust, int32_t, int32_t, int32_t, power_adjust);

protected:
virtual void register_fields() override {
tracker_component::register_fields();

RegisterField("kismet.antenna.id", "Antenna ID for fast lookup", &antenna_id);
RegisterField("kismet.antenna.uuid", "Antenna UUID", &antenna_uuid);
RegisterField("kismet.antenna.source_uuid", "UUID of antenna source", &source_uuid);
RegisterField("kismet.antenna.source_antnum", "Antenna number on source", &source_antnum);
RegisterField("kismet.antenna.power_adjust", "Optional power adjustment", &power_adjust);
}

std::shared_ptr<TrackerElementInt32> antenna_id;
std::shared_ptr<TrackerElementUUID> antenna_uuid;
std::shared_ptr<TrackerElementUUID> source_uuid;
std::shared_ptr<TrackerElementInt32> power_adjust;
std::shared_ptr<TrackerElementInt32> source_antnum;

};

class Antennatracker : public LifetimeGlobal {
public:
static std::shared_ptr<Antennatracker> create_at() {
auto mon = std::make_shared<Antennatracker>();
Globalreg::globalreg->RegisterLifetimeGlobal(mon);
Globalreg::globalreg->InsertGlobal("ANTENNATRACKER", mon);

return mon;
}

Antennatracker();
virtual ~Antennatracker();

// Add a new antenna
int add_antenna(uuid in_src, int in_srcnum, int adjustment);
int add_antenna(uuid in_src, int in_srcnum, int adjustment, uuid in_ant_uuid);

// Adjust an existing antenna
int set_antenna_adjustment(int in_antnum, int adjustment);

// Retreive antenna
std::shared_ptr<tracked_antenna> get_antenna(int in_antnum);

protected:
kis_recursive_timed_mutex mutex;

int next_ant_id;

std::shared_ptr<TrackerElementIntMap> antenna_id_map;

std::shared_ptr<Kis_Net_Httpd_Simple_Tracked_Endpoint> antenna_enp;

};

#endif

4 changes: 4 additions & 0 deletions kismet_server.cc
Expand Up @@ -62,6 +62,7 @@
#include "kis_dissector_ipdata.h"

#include "dlttracker.h"
#include "antennatracker.h"
#include "kis_datasource.h"
#include "datasourcetracker.h"
#include "datasource_pcapfile.h"
Expand Down Expand Up @@ -937,6 +938,9 @@ int main(int argc, char *argv[], char *envp[]) {
// Create the DLT tracker
auto dlttracker = DltTracker::create_dltt();

// Create antenna mapper
auto anttracker = Antennatracker::create_at();

// Add the datasource tracker
std::shared_ptr<Datasourcetracker> datasourcetracker;
datasourcetracker = Datasourcetracker::create_dst();
Expand Down

0 comments on commit 80b5731

Please sign in to comment.