forked from kismetwireless/kismet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
datasource_linux_bluetooth.cc
121 lines (89 loc) · 3.83 KB
/
datasource_linux_bluetooth.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
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 "kis_datasource.h"
#include "datasource_linux_bluetooth.h"
#include "phy_bluetooth.h"
#include "protobuf_cpp/linuxbluetooth.pb.h"
#ifdef HAVE_LINUX_BLUETOOTH_DATASOURCE
KisDatasourceLinuxBluetooth::KisDatasourceLinuxBluetooth(GlobalRegistry *in_globalreg,
SharedDatasourceBuilder in_builder) : KisDatasource(in_globalreg, in_builder) {
// Set the capture binary
set_int_source_ipc_binary("kismet_cap_linux_bluetooth");
pack_comp_btdevice = packetchain->RegisterPacketComponent("BTDEVICE");
}
bool KisDatasourceLinuxBluetooth::dispatch_rx_packet(std::shared_ptr<KismetExternal::Command> c) {
if (KisDatasource::dispatch_rx_packet(c))
return true;
if (c->command() == "LBTDATAREPORT") {
handle_packet_linuxbtdevice(c->seqno(), c->content());
return true;
}
return false;
}
void KisDatasourceLinuxBluetooth::handle_packet_linuxbtdevice(uint32_t in_seqno,
std::string in_content) {
// If we're paused, throw away this packet
{
local_locker lock(&ext_mutex);
if (get_source_paused())
return;
}
KismetLinuxBluetooth::LinuxBluetoothDataReport report;
if (!report.ParseFromString(in_content)) {
_MSG(std::string("Kismet datasource driver ") + get_source_builder()->get_source_type() +
std::string(" could not parse the data report, something is wrong with "
"the remote capture tool"), MSGFLAG_ERROR);
trigger_error("Invalid LBTDATAREPORT");
return;
}
if (report.has_message())
_MSG(report.message().msgtext(), report.message().msgtype());
if (report.has_warning())
set_int_source_warning(report.warning());
kis_packet *packet = packetchain->GeneratePacket();
bluetooth_packinfo *bpi = new bluetooth_packinfo();
packet->insert(pack_comp_btdevice, bpi);
kis_layer1_packinfo *siginfo = NULL;
kis_gps_packinfo *gpsinfo = NULL;
if (report.has_signal()) {
siginfo = handle_sub_signal(report.signal());
packet->insert(pack_comp_l1info, siginfo);
}
if (report.has_gps()) {
gpsinfo = handle_sub_gps(report.gps());
packet->insert(pack_comp_gps, gpsinfo);
}
if (clobber_timestamp && get_source_remote()) {
gettimeofday(&(packet->ts), NULL);
} else {
packet->ts.tv_sec = report.btdevice().time_sec();
packet->ts.tv_usec = report.btdevice().time_usec();
}
bpi->address = mac_addr(report.btdevice().address());
bpi->name = MungeToPrintable(report.btdevice().name());
bpi->txpower = report.btdevice().txpower();
bpi->type = report.btdevice().type();
for (auto u : report.btdevice().uuid_list())
bpi->service_uuid_vec.push_back(uuid(u));
packetchain_comp_datasource *datasrcinfo = new packetchain_comp_datasource();
datasrcinfo->ref_source = this;
packet->insert(pack_comp_datasrc, datasrcinfo);
inc_source_num_packets(1);
get_source_packet_rrd()->add_sample(1, time(0));
// Inject the packet into the packetchain if we have one
packetchain->ProcessPacket(packet);
}
#endif