From 4eba89add8db804c33e8692edf5b27c2d3a2e365 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Fri, 7 Apr 2017 21:49:36 +0200 Subject: o Cleaning up code, fixing many small bugs. o Making a better envelope format. o Reading out the interface's channel. --- src/capture.cpp | 45 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 10 deletions(-) (limited to 'src/capture.cpp') 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 +#include #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(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(data.dst)); - probe->set_rssi(data.rssi); + if (data.rssi) { + probe->set_rssi(data.rssi); + } } - envelope.SerializeToString(&str); - cout << static_cast(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; -- cgit v1.2.3