aboutsummaryrefslogtreecommitdiff
path: root/src/capture.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/capture.cpp')
-rw-r--r--src/capture.cpp45
1 files changed, 35 insertions, 10 deletions
diff --git a/src/capture.cpp b/src/capture.cpp
index 5844b25..a6cc713 100644
--- a/src/capture.cpp
+++ b/src/capture.cpp
@@ -1,10 +1,20 @@
#include <iostream>
+#include <iwlib.h>
#include "wifi-triangulator/core.h"
using namespace std;
using namespace wifi_triangulator;
+void send_info(uint64_t freq) {
+ pb::envelope envelope;
+ pb::listener_station_info *i = envelope.mutable_listener_station_info();
+ i->set_freq(freq);
+ write_envelope(pb::letter_type::listener_station_info_lt, envelope);
+}
+
int main(int argc, char *argv[]) {
+ app_name = argv[0];
+
if (argc != 2) {
fprintf(stderr, "usage: %s [interface]\n", argv[0]);
return EXIT_FAILURE;
@@ -14,24 +24,39 @@ int main(int argc, char *argv[]) {
GOOGLE_PROTOBUF_VERIFY_VERSION;
- string str;
- str.reserve(1 << 16);
+ int iw;
+ if ((iw = iw_sockets_open()) < 0) {
+ perror("Could not open iw sockets");
+ return EXIT_FAILURE;
+ }
+
+ wireless_config wc;
+ if (iw_get_basic_config(iw, dev.c_str(), &wc) < 0) {
+ perror("iw_get_basic_config");
+ return EXIT_FAILURE;
+ }
+
+ auto freq = static_cast<uint64_t>(wc.freq);
+
+ send_info(freq);
int ret = launch_capture(dev, [&](const data &data) {
pb::envelope envelope;
envelope.set_time_s(data.sec);
envelope.set_time_us(data.usec);
- envelope.set_type(data.type);
- if (data.type == pb::packet_type::probe_request) {
- pb::probe *probe = envelope.mutable_probe();
+ pb::frame *frame = envelope.mutable_frame();
+ frame->set_type(data.type);
+
+ if (data.type == pb::frame_type ::probe_request) {
+ pb::probe *probe = frame->mutable_probe();
probe->set_src(data.src);
- probe->set_dst(static_cast<uint64_t>(data.dst));
- probe->set_rssi(data.rssi);
+ if (data.rssi) {
+ probe->set_rssi(data.rssi);
+ }
}
- envelope.SerializeToString(&str);
- cout << static_cast<uint16_t>(str.length()) << str << flush;
+ write_envelope(pb::letter_type::frame_lt, envelope);
// static int count = 0;
// cerr << "count=" << count << "!\r" << flush;
@@ -40,7 +65,7 @@ int main(int argc, char *argv[]) {
google::protobuf::ShutdownProtobufLibrary();
- cerr << "Capture exiting" << endl;
+ cerr << app_name << " exiting" << endl;
cout.flush();
return ret;