AnalyzerBase.cc
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
6 //
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
11 //
12 
13 
14 #include "AnalyzerBase.hh"
15 
16 // Custom includes
17 #include <sys/types.h>
18 #include <sys/stat.h>
19 #include <fcntl.h>
23 
24 #define prefix_
25 //-/////////////////////////////////////////////////////////////////////////////////////////////////
26 
28  : configuration_(configuration),
29  timer_("intervalTimer", senf::membind( &AnalyzerBase::timerEvent, this)),
30  startTime_(senf::ClockService::now()),
31  nextTimeout_(senf::ClockService::clock_type(0)),
32  athSpectralScan_(configuration.phyName),
33  spectralUnknownType_(0),
34  pktData_(0),
35  pktManagement_(0),
36  pktControl_(0),
37  pktOther_(0),
38  pktTx_(0),
39  pktExceptions_(0),
40  pktFrequencyMismatch_(0)
41 {
42  noroute(input);
43  input.onRequest( &AnalyzerBase::request);
45 
46  // start the interval timer
47  nextTimeout_ = startTime_ + configuration_.reportingInterval;
48  timer_.timeout( nextTimeout_);
49 }
50 
52 {
53  return athSpectralScan_;
54 }
55 
56 prefix_ void AnalyzerBase::timerEvent()
57 {
58  // get current time
60  // call report with current time and the actual interval duration
61  v_timerInterval( current - startTime_, configuration_.reportingInterval + (current - nextTimeout_));
62  // restart timer fixing any potential scheduling issues
63  nextTimeout_ += configuration_.reportingInterval;
64  timer_.timeout( nextTimeout_);
65 
66  if (configuration_.duration and ((current - startTime_) >= configuration_.duration)) {
67  v_terminate(current - startTime_);
69  }
70 }
71 
73 {
74  if ( !athSpectralScan_.spectralPeriod(configuration_.spectralPeriod) or
77  !athSpectralScan_.spectralBins(configuration_.spectralBins) or
78  !athSpectralScan_.spectralCount(configuration_.spectralCount))
79  return false;
80 
81  bool rtn = athSpectralScan_.callback(
82  std::bind(&AnalyzerBase::processSpectralEvent, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4));
83  athSpectralScan_.frequency(configuration_.frequency, 0, 0);
84  return rtn;
85 }
86 
87 prefix_ void AnalyzerBase::request()
88 {
89  senf::RadiotapPacket rtPacket (input());
90  senf::RadiotapPacket::Parser rtParser (rtPacket.parser());
91 
92  if (!rtParser.tsftPresent()) {
93  // ignore Tx Frames
94  pktTx_++;
95  return;
96  }
97 
98  unsigned freq (0);
99  unsigned rate(0);
100  signed rssi(0);
101  unsigned length(0);
102 
103  try {
105  if (dpkt) {
106  pktData_++;
107  }
108  else {
110  if (mpkt) {
111  pktManagement_++;
112  }
113  else {
115  if (cpkt) {
116  pktControl_++;
117  }
118  else {
119  pktOther_++;
120  }
121  }
122  }
123 
124  // determine frequency
125  if (rtParser.channelOptionsPresent()) {
126  freq = rtParser.channelOptions().freq();
127  }
128 
129  // determine data rate
130  if (rtParser.mcsPresent()) {
131  unsigned id (senf::emu::WLANModulationParameterRegistry::instance().parameterIdByMCS_HT(
132  rtParser.mcs().mcsIndex(),
133  rtParser.mcs().bandwidth(),
134  rtParser.mcs().guardInterval() ));
136  }
137  else if (rtParser.vhtPresent()) {
138  // we need to extend the Modulation registry to support VHT...
139  unsigned id (senf::emu::WLANModulationParameterRegistry::instance().parameterIdByMCS_VHT(
140  rtParser.vht().mcs_user0(),
141  rtParser.vht().nss_user0(),
142  rtParser.bandwidth(),
143  rtParser.vht().guardInterval() ));
144 
146  }
147  else if (rtParser.ratePresent()) {
148  rate = rtParser.rate() * 500;
149  }
150 
151  rssi = short(rtParser.dbmAntennaSignal());
152  length = rtPacket.size() - rtParser.length();
153  }
154  catch(...) {
155  pktExceptions_++;
156  };
157 
158  if (freq == configuration_.frequency)
159  v_80211FrameReceived(rtParser.tsft(), freq, rssi, rate, length, rtPacket);
160  else
161  pktFrequencyMismatch_++;
162 }
163 
164 prefix_ void AnalyzerBase::processSpectralEvent(std::uint64_t tsft, std::uint16_t frequency, unsigned numBins, void * sample)
165 {
166  switch (((fft_sample_tlv*) sample)->type) {
167  case ATH_FFT_SAMPLE_HT20:
168  v_SpectralDataReceived(tsft, frequency, numBins, *((fft_sample_ht20 *) sample));
169  break;
171  v_SpectralDataReceived(tsft, frequency, numBins, *((fft_sample_ht20_40 *) sample));
172  break;
174  v_SpectralDataReceived(tsft, frequency, numBins, *((fft_sample_ath10k *) sample));
175  break;
176  default:
177  spectralUnknownType_++;
178  break;
179  }
180 }
181 
183 {
184  std::stringstream ss;
185  athSpectralScan_.stats(ss);
186 
187  return "pktData " + senf::str(pktData_) +
188  ", pktManagement " + senf::str(pktManagement_) +
189  ", pktControl " + senf::str(pktControl_) +
190  ", pktOther " + senf::str(pktOther_) +
191  ", pktTx " + senf::str(pktTx_) +
192  ", pktExceptions " + senf::str(pktExceptions_) +
193  ", pktFrequencyMismatch " + senf::str(pktFrequencyMismatch_) +
194 
195  " --- " + senf::str(ss) + ", spectralUnknown " + senf::str(spectralUnknownType_);
196 }
197 
198 //-/////////////////////////////////////////////////////////////////////////////////////////////////
199 #undef prefix_
senf::ClockService::clock_type duration
config::time_type clock_type
virtual void v_80211FrameReceived(std::uint64_t tsft, unsigned frequency, signed rssi, unsigned rate, unsigned length, senf::RadiotapPacket &rt)=0
unsigned spectralShortRepeat() const
virtual void v_terminate(senf::ClockService::clock_type const &sessionDuration)=0
unsigned spectralCount() const
u8 type
virtual void terminate() const
unsigned spectralCount
unsigned spectralFFTPeriod() const
#define prefix_
Definition: AnalyzerBase.cc:24
boost::function< R(Args)> membind(R(T::*fn)(Args), T *ob)
Annotations public header.
bool callback(AthSpectralScanCallback const &cb)
void noroute(connector::Connector &connector)
ClockService::clock_type const & now()
WLANPacket_DataFrameType::packet WLANPacket_DataFrame
WLANPacket_MgtFrameType::packet WLANPacket_MgtFrame
void processSpectralEvent(std::uint64_t tsft, std::uint16_t frequency, unsigned numBins, void *spectralSample)
unsigned frequency
std::string stats()
unsigned rate
Bitrate in kbit/s.
void timeout(ClockService::clock_type const &timeout, bool initiallyEnabled=true)
senf::ClockService::clock_type reportingInterval
WLANPacket_CtrlFrameType::packet WLANPacket_CtrlFrame
virtual void v_timerInterval(senf::ClockService::clock_type const &timestamp, senf::ClockService::clock_type const &actualDuration)=0
nothrow
AnalyzerBase(Configuration const &configuration)
Definition: AnalyzerBase.cc:27
unsigned spectralBins
senf::emu::AthSpectralScan & athSpectralScan()
Definition: AnalyzerBase.cc:51
s8 rssi
Configuration const & configuration_
Definition: AnalyzerBase.hh:43
WLANInterface public header.
WLANModulationParameter const & findModulationById(ModulationParameter::id_t id) const
unsigned spectralPeriod
static WLANModulationParameterRegistry & instance()
void frequency(std::uint32_t freq, std::uint32_t bandwidth, std::int32_t offset=0)
unsigned spectralFFTPeriod
senf::ppi::connector::PassiveInput< senf::RadiotapPacket > input
Definition: AnalyzerBase.hh:30
bool spectralShortRepeat
static clock_type now()
bool startSpectralScan()
Definition: AnalyzerBase.cc:72
virtual void v_SpectralDataReceived(std::uint64_t tsft, unsigned frequency, unsigned bins, fft_sample_ht20 const &)=0
void stats(std::ostream &os)
__be16 freq
__be16 length
void throttlingDisc(ThrottlingDisc const &disc)
unsigned spectralPeriod() const