Skip to content

Commit

Permalink
Start enablng first view
Browse files Browse the repository at this point in the history
  • Loading branch information
dragorn committed Nov 14, 2018
1 parent 1c87f65 commit 80bba1c
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 7 deletions.
14 changes: 14 additions & 0 deletions devicetracker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,8 @@ std::shared_ptr<kis_tracked_device_base>

auto mm_pair = std::make_pair(in_mac, device);
tracked_mac_multimap.insert(mm_pair);

new_view_device(device);
}

return device;
Expand Down Expand Up @@ -920,6 +922,9 @@ int Devicetracker::timetracker_event(int eventid) {
}
}

// Forget it from any views
remove_view_device(d);

// Forget it from the immutable vec, but keep its
// position; we need to have vecpos = devid
auto iti = immutable_tracked_vec->begin() + d->get_kis_internal_id();
Expand Down Expand Up @@ -1161,6 +1166,15 @@ void Devicetracker::update_view_device(std::shared_ptr<kis_tracked_device_base>
}
}

void Devicetracker::remove_view_device(std::shared_ptr<kis_tracked_device_base> in_device) {
local_locker l(view_mutex);

for (auto i : *view_vec) {
auto vi = std::static_pointer_cast<DevicetrackerView>(i);
vi->removeDevice(in_device);
}
}

int Devicetracker::store_devices() {
auto devs = std::make_shared<TrackerElementVector>();
auto immutable_copy = std::make_shared<TrackerElementVector>(immutable_tracked_vec);
Expand Down
1 change: 1 addition & 0 deletions devicetracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ friend class DevicetrackerStateStore;

virtual void new_view_device(std::shared_ptr<kis_tracked_device_base> in_device);
virtual void update_view_device(std::shared_ptr<kis_tracked_device_base> in_device);
virtual void remove_view_device(std::shared_ptr<kis_tracked_device_base> in_device);

protected:
GlobalRegistry *globalreg;
Expand Down
10 changes: 6 additions & 4 deletions devicetracker_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
#include "kis_mutex.h"
#include "kismet_algorithm.h"

DevicetrackerView::DevicetrackerView(const std::string& in_id, new_device_cb in_new_cb,
updated_device_cb in_update_cb) :
DevicetrackerView::DevicetrackerView(const std::string& in_id, const std::string& in_description,
new_device_cb in_new_cb, updated_device_cb in_update_cb) :
tracker_component{},
new_cb {in_new_cb},
update_cb {in_update_cb} {
Expand All @@ -36,10 +36,12 @@ DevicetrackerView::DevicetrackerView(const std::string& in_id, new_device_cb in_
register_fields();
reserve_fields(nullptr);

set_view_id(in_id);
view_id->set(in_id);
view_description->set(in_description);

auto uri = fmt::format("/devices/view/{}/devices", in_id);
device_list = std::make_shared<TrackerElementVector>();

auto uri = fmt::format("/devices/view/{}/devices", in_id);
device_endp =
std::make_shared<Kis_Net_Httpd_Simple_Post_Endpoint>(uri, false,
std::bind(&DevicetrackerView::device_endpoint_handler, this, _1, _2, _3, _4), &mutex);
Expand Down
8 changes: 5 additions & 3 deletions devicetracker_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,20 @@ class DevicetrackerView : public tracker_component {
using new_device_cb = std::function<bool (std::shared_ptr<kis_tracked_device_base>)>;
using updated_device_cb = std::function<bool (std::shared_ptr<kis_tracked_device_base>)>;

DevicetrackerView(const std::string& in_id, new_device_cb in_new_cb, updated_device_cb in_upd_cb);
DevicetrackerView(const std::string& in_id, const std::string& in_description,
new_device_cb in_new_cb, updated_device_cb in_upd_cb);

virtual ~DevicetrackerView() {
local_locker l(mutex);
}

// Protect proxies w/ mutex
__ProxyM(view_id, std::string, std::string, std::string, view_id, mutex);
__ProxyM(view_description, std::string, std::string, std::string, view_description, mutex);
__ProxyGet(view_id, std::string, std::string, view_id);
__ProxyGet(view_description, std::string, std::string, view_description);

virtual void pre_serialize() override {
local_eol_shared_locker lock(mutex);
list_sz->set(device_list->size());
}

virtual void post_serialize() override {
Expand Down
36 changes: 36 additions & 0 deletions phy_80211.cc
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,36 @@ Kis_80211_Phy::Kis_80211_Phy(GlobalRegistry *in_globalreg, int in_phyid) :
}
}

// Create a view
auto ap_view =
std::make_shared<DevicetrackerView>("phydot11_accesspoints",
"IEEE802.11 Access Points",
[this](std::shared_ptr<kis_tracked_device_base> dev) -> bool {
auto dot11 =
dev->get_sub_as<dot11_tracked_device>(dot11_device_entry_id);

if (dot11 == nullptr)
return false;

if (dot11->get_type_set() & DOT11_DEVICE_TYPE_BEACON_AP)
return true;

return false;
},
[this](std::shared_ptr<kis_tracked_device_base> dev) -> bool {
auto dot11 =
dev->get_sub_as<dot11_tracked_device>(dot11_device_entry_id);

if (dot11 == nullptr)
return false;

if (dot11->get_type_set() & DOT11_DEVICE_TYPE_BEACON_AP)
return true;

return false;
});
devicetracker->add_view(ap_view);

// Register js module for UI
std::shared_ptr<Kis_Httpd_Registry> httpregistry =
Globalreg::FetchGlobalAs<Kis_Httpd_Registry>(globalreg, "WEBREGISTRY");
Expand Down Expand Up @@ -966,6 +996,8 @@ int Kis_80211_Phy::CommonClassifierDot11(CHAINCALL_PARMS) {
dot11info->subtype == packet_sub_probe_resp) {
d11phy->HandleSSID(bssid_dev, bssid_dot11, in_pack, dot11info, pack_gpsinfo);
}

d11phy->devicetracker->update_view_device(bssid_dev);
}

if (source_dev != NULL) {
Expand Down Expand Up @@ -1021,6 +1053,8 @@ int Kis_80211_Phy::CommonClassifierDot11(CHAINCALL_PARMS) {
dot11info->subtype == packet_sub_reassociation_req) {
d11phy->HandleProbedSSID(source_dev, source_dot11, in_pack, dot11info, pack_gpsinfo);
}

d11phy->devicetracker->update_view_device(source_dev);
}

if (dest_dev != NULL) {
Expand Down Expand Up @@ -1056,6 +1090,8 @@ int Kis_80211_Phy::CommonClassifierDot11(CHAINCALL_PARMS) {
;
}
}

d11phy->devicetracker->update_view_device(dest_dev);
}

// Safety check that our BSSID device exists
Expand Down

0 comments on commit 80bba1c

Please sign in to comment.