diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2017-04-07 21:49:36 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2017-04-07 21:49:36 +0200 |
commit | 4eba89add8db804c33e8692edf5b27c2d3a2e365 (patch) | |
tree | 5fba0a0fa4d6010d13f99215508212086a116063 /src/capture.cpp | |
parent | 36e59a1991f075e36e117a08321d5e4c4dc00eac (diff) | |
download | wifi-triangulator-master.tar.gz wifi-triangulator-master.tar.bz2 wifi-triangulator-master.tar.xz wifi-triangulator-master.zip |
o Making a better envelope format.
o Reading out the interface's channel.
Diffstat (limited to 'src/capture.cpp')
-rw-r--r-- | src/capture.cpp | 45 |
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; |