forked from kismetwireless/kismet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
datasource_linux_bluetooth.cc
147 lines (111 loc) · 4.86 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*
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 "datasource_linux_bluetooth.h"
#include "json_adapter.h"
#include "phy_bluetooth.h"
#include "messagebus.h"
#include "protobuf_cpp/linuxbluetooth.pb.h"
#ifdef HAVE_LINUX_BLUETOOTH_DATASOURCE
kis_datasource_linux_bluetooth::kis_datasource_linux_bluetooth(shared_datasource_builder in_builder) :
kis_datasource(in_builder) {
// Set the capture binary
set_int_source_ipc_binary("kismet_cap_linux_bluetooth");
pack_comp_btdevice = packetchain->register_packet_component("BTDEVICE");
pack_comp_meta = packetchain->register_packet_component("METABLOB");
}
bool kis_datasource_linux_bluetooth::dispatch_rx_packet(const nonstd::string_view& command,
uint32_t seqno, const nonstd::string_view& content) {
if (kis_datasource::dispatch_rx_packet(command, seqno, content))
return true;
if (command.compare("LBTDATAREPORT") == 0) {
handle_packet_linuxbtdevice(seqno, content);
return true;
}
return false;
}
void kis_datasource_linux_bluetooth::handle_packet_linuxbtdevice(uint32_t in_seqno,
const nonstd::string_view& in_content) {
// If we're paused, throw away this packet
{
kis_lock_guard<kis_mutex> lk(ext_mutex,
"kis_datasource_linux_bluetooth handle_packet_linuxbtdevice");
if (get_source_paused())
return;
}
KismetLinuxBluetooth::LinuxBluetoothDataReport report;
if (!report.ParseFromArray(in_content.data(), in_content.length())) {
_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());
auto packet = packetchain->generate_packet();
auto bpi = packetchain->new_packet_component<bluetooth_packinfo>();
packet->insert(pack_comp_btdevice, bpi);
if (report.has_signal()) {
auto siginfo = handle_sub_signal(report.signal());
packet->insert(pack_comp_l1info, siginfo);
}
if (report.has_gps()) {
auto 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 = munge_to_printable(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));
// Forge a metablob until we transition the capture protocols
std::stringstream fake_json;
fake_json << "{";
fake_json << "\"bt_address\":\"" << bpi->address << "\",";
fake_json << "\"bt_name\":\"" << json_adapter::sanitize_string(bpi->name) << "\",";
fake_json << "\"txpower\":" << bpi->txpower << ",";
fake_json << "\"type\":" << bpi->type << ",";
fake_json << "\"uuid_list\": [";
bool need_comma = false;
for (auto u : bpi->service_uuid_vec) {
fake_json << "\"" << u << "\"";
if (need_comma)
fake_json << ",";
need_comma = true;
}
fake_json << "]";
fake_json << "}";
auto metablob = packetchain->new_packet_component<packet_metablob>();
metablob->set_data("LINUXBLUETOOTH", fake_json.str());
packet->insert(pack_comp_meta, metablob);
auto datasrcinfo = packetchain->new_packet_component<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->process_packet(packet);
}
#endif