RadiotapPacket.hh
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 
17 #ifndef HH_SENF_Packets_80211Bundle_RadiotapPacket_
18 #define HH_SENF_Packets_80211Bundle_RadiotapPacket_ 1
19 
20 // Custom includes
21 #include <senf/Packets/Packets.hh>
22 #include <boost/unordered_map.hpp>
23 #include <boost/array.hpp>
24 #include <boost/functional/hash.hpp>
25 
26 //-/////////////////////////////////////////////////////////////////////////////////////////////////
27 namespace senf {
28 
34  {
35 # include SENF_FIXED_PARSER()
36 
37  SENF_PARSER_BITFIELD ( shortGI, 1, bool );
38  SENF_PARSER_BITFIELD ( badFCS, 1, bool );
39  SENF_PARSER_BITFIELD ( padding, 1, bool );
40  SENF_PARSER_BITFIELD_RO( fcsAtEnd, 1, bool ); // Cannot change this (change packet size)
42  SENF_PARSER_BITFIELD ( wep, 1, bool );
44  SENF_PARSER_BITFIELD ( cfp, 1, bool );
45 
47 
48  friend struct RadiotapPacketParser;
49  };
50 
56  {
57 # include SENF_FIXED_PARSER()
58 
60  SENF_PARSER_BITFIELD ( flag2ghz, 1, bool );
61  SENF_PARSER_BITFIELD ( ofdm, 1, bool );
62  SENF_PARSER_BITFIELD ( cck, 1, bool );
63  SENF_PARSER_BITFIELD ( turbo, 1, bool );
65  SENF_PARSER_BITFIELD ( quarterRateChannel, 1, bool );
66  SENF_PARSER_BITFIELD ( halfRateChannel, 1, bool );
67  SENF_PARSER_BITFIELD ( gsm, 1, bool );
68  SENF_PARSER_BITFIELD ( staticTurbo, 1, bool );
69  SENF_PARSER_BITFIELD ( gfsk, 1, bool );
70  SENF_PARSER_BITFIELD ( cckOfdm, 1, bool );
71  SENF_PARSER_BITFIELD ( passive, 1, bool );
72  SENF_PARSER_BITFIELD ( flag5ghz, 1, bool );
73 
75  };
76 
78  {
79 # include SENF_FIXED_PARSER()
80 
82  SENF_PARSER_BITFIELD ( badPlcp, 1, bool );
84 
86  };
87 
89  {
90 # include SENF_FIXED_PARSER()
91 
93  SENF_PARSER_BITFIELD ( noSeq, 1, bool );
94  SENF_PARSER_BITFIELD ( noAck, 1, bool );
95  SENF_PARSER_BITFIELD ( txRts, 1, bool );
96  SENF_PARSER_BITFIELD ( txCts, 1, bool );
97  SENF_PARSER_BITFIELD ( fail, 1, bool );
98 
100  };
101 
103  {
104 # include SENF_FIXED_PARSER()
105 
107  SENF_PARSER_BITFIELD ( fecTypeKnown, 1, bool );
108  SENF_PARSER_BITFIELD ( htFormatKnown, 1, bool );
109  SENF_PARSER_BITFIELD ( guardIntervalKnown, 1, bool );
110  SENF_PARSER_BITFIELD ( mcsIndexKnown, 1, bool );
111  SENF_PARSER_BITFIELD ( bandwidthKnown, 1, bool );
113  SENF_PARSER_BITFIELD ( fecType, 1, bool );
114  SENF_PARSER_BITFIELD ( htFormat, 1, bool );
115  SENF_PARSER_BITFIELD ( guardInterval, 1, bool );
116  SENF_PARSER_BITFIELD ( bandwidth, 2, unsigned );
117 
119 
121  };
122 
124  {
125 # include SENF_FIXED_PARSER()
126 
127  SENF_PARSER_BITFIELD ( groupIdKnown, 1, bool );
128  SENF_PARSER_BITFIELD ( bandwidthKnown, 1, bool );
129  SENF_PARSER_BITFIELD ( beamformedKnown, 1, bool );
130  SENF_PARSER_BITFIELD ( ldpcExtraOfdmSymbolKnown, 1, bool );
131  SENF_PARSER_BITFIELD ( shortGiNsymDisambiguationKnown, 1, bool );
132  SENF_PARSER_BITFIELD ( guardIntervalKnown, 1, bool );
133  SENF_PARSER_BITFIELD ( txOpPsNotAllowedKnown, 1, bool );
134  SENF_PARSER_BITFIELD ( stbcKnown, 1, bool );
136  SENF_PARSER_BITFIELD ( partialAidKnown, 1, bool );
137 
139  SENF_PARSER_BITFIELD ( beamformed, 1, bool );
140  SENF_PARSER_BITFIELD ( ldpcExtraOfdmSymbol, 1, bool );
141  SENF_PARSER_BITFIELD ( shortGiNsymDisambiguation, 1, bool );
142  SENF_PARSER_BITFIELD ( guardInterval, 1, bool );
143  SENF_PARSER_BITFIELD ( txOpPsNotAllowed, 1, bool );
144  SENF_PARSER_BITFIELD ( stbc, 1, bool );
145 
147 
148  SENF_PARSER_BITFIELD ( mcs_user0, 4, unsigned );
149  SENF_PARSER_BITFIELD ( nss_user0, 4, unsigned );
150  SENF_PARSER_BITFIELD ( mcs_user1, 4, unsigned );
151  SENF_PARSER_BITFIELD ( nss_user1, 4, unsigned );
152  SENF_PARSER_BITFIELD ( mcs_user2, 4, unsigned );
153  SENF_PARSER_BITFIELD ( nss_user2, 4, unsigned );
154  SENF_PARSER_BITFIELD ( mcs_user3, 4, unsigned );
155  SENF_PARSER_BITFIELD ( nss_user3, 4, unsigned );
156 
158  SENF_PARSER_BITFIELD ( coding_user3, 1, unsigned );
159  SENF_PARSER_BITFIELD ( coding_user2, 1, unsigned );
160  SENF_PARSER_BITFIELD ( coding_user1, 1, unsigned );
161  SENF_PARSER_BITFIELD ( coding_user0, 1, unsigned );
162 
165 
167  };
168 
170  {
171 # include SENF_FIXED_PARSER()
172 
173  SENF_PARSER_FIELD ( referenceNumber, UInt32Parser );
177 
179  };
180 
181 
200  {
201 # include SENF_FIXED_PARSER()
202 
203  /*
204  * mandatory fields
205  */
207  //padding bits, currently unused, it simply aligns the fields onto natural word boundaries.
208  SENF_PARSER_SKIP ( 1 );
210 
212 
214 
217 
219  // Could use the the entries from radiotap.h but I don't know,
220  // if I want to pollute the global and macro namespace even more ...
221  TSFT_INDEX = 0,
222  FLAGS_INDEX = 1,
223  RATE_INDEX = 2,
224  CHANNEL_INDEX = 3,
225  FHSS_INDEX = 4,
226  DBM_ANTSIGNAL_INDEX = 5,
227  DBM_ANTNOISE_INDEX = 6,
228  LOCK_QUALITY_INDEX = 7,
229  TX_ATTENUATION_INDEX = 8,
230  DB_TX_ATTENUATION_INDEX = 9,
231  DBM_TX_POWER_INDEX = 10,
232  ANTENNA_INDEX = 11,
233  DB_ANTSIGNAL_INDEX = 12,
234  DB_ANTNOISE_INDEX = 13,
235  RX_FLAGS_INDEX = 14,
236  TX_FLAGS_INDEX = 15,
237  RTS_RETRIES_INDEX = 16,
238  DATA_RETRIES_INDEX = 17,
239  MCS_INDEX = 19,
240  A_MPDU_STATUS_INDEX = 20,
241  VHT_INDEX = 21,
242 
243  MAX_INDEX = 21,
244 
245  RADIOTOP_NS_INDEX = 29,
246  VENDOR_NS_INDEX = 30,
247  EXTENDED_BITMASK_INDEX = 31
248  };
249 
250  enum PresentFlag {
251  TSFT_FLAG = (1<<TSFT_INDEX),
252  FLAGS_FLAG = (1<<FLAGS_INDEX),
253  RATE_FLAG = (1<<RATE_INDEX),
254  CHANNEL_FLAG = (1<<CHANNEL_INDEX),
255  FHSS_FLAG = (1<<FHSS_INDEX),
256  DBM_ANTSIGNAL_FLAG = (1<<DBM_ANTSIGNAL_INDEX),
257  DBM_ANTNOISE_FLAG = (1<<DBM_ANTNOISE_INDEX),
258  LOCK_QUALITY_FLAG = (1<<LOCK_QUALITY_INDEX),
259  TX_ATTENUATION_FLAG = (1<<TX_ATTENUATION_INDEX),
260  DB_TX_ATTENUATION_FLAG = (1<<DB_TX_ATTENUATION_INDEX),
261  DBM_TX_POWER_FLAG = (1<<DBM_TX_POWER_INDEX),
262  ANTENNA_FLAG = (1<<ANTENNA_INDEX),
263  DB_ANTSIGNAL_FLAG = (1<<DB_ANTSIGNAL_INDEX),
264  DB_ANTNOISE_FLAG = (1<<DB_ANTNOISE_INDEX),
265  RX_FLAGS_FLAG = (1<<RX_FLAGS_INDEX),
266  TX_FLAGS_FLAG = (1<<TX_FLAGS_INDEX),
267  RTS_RETRIES_FLAG = (1<<RTS_RETRIES_INDEX),
268  DATA_RETRIES_FLAG = (1<<DATA_RETRIES_INDEX),
269  MCS_FLAG = (1<<MCS_INDEX),
270  A_MPDU_STATUS_FLAG = (1<<A_MPDU_STATUS_INDEX),
271  VHT_FLAG = (1<<VHT_INDEX),
272 
273  RADIOTOP_NS_FLAG = (1<<RADIOTOP_NS_INDEX),
274  VENDOR_NS_FLAG = (1<<VENDOR_NS_INDEX),
275  EXTENDED_BITMASK_FLAG = (1<<EXTENDED_BITMASK_INDEX)
276  };
277 
278  static unsigned const FIELD_SIZE[MAX_INDEX+2];
279  };
280 
282  {
283 # include SENF_FIXED_PARSER()
284 
286  SENF_PARSER_BITFIELD_RO( frameType, 2, unsigned );
287  SENF_PARSER_SKIP_BITS ( 2 );
288 
290  };
291 
293  {
295 
296  static const size_type init_bytes = RadiotapPacket_HeaderParser::fixed_bytes;
297 
298  size_type bytes() const;
299 
300  //-////////////////////////////////////////////////////////////////////////
301 
302 # define FIELD(name,type,index) \
303  typedef type name ## _t; \
304  type name(unsigned extIndex = 0) { return parseField<type>(index, extIndex); } \
305  bool has_ ## name(unsigned extIndex = 0) { return currentTable()[(extIndex+1)*index]; } \
306  bool name ## Present(unsigned extIndex = 0) { return has_ ## name(extIndex); } \
307  type init_ ## name() { initField(index); return name(); } \
308  void disable_ ## name() { disableField(index); }
309 
310  FIELD( tsft, UInt64LSBParser, TSFT_INDEX );
311 
312  // flags is special: disabling 'flags' must also disable the 'fcs' field
314  flags_t flags(unsigned extIndex = 0) { return parseField<flags_t>(FLAGS_INDEX, extIndex); }
315  bool has_flags(unsigned extIndex = 0) { return currentTable()[(extIndex+1)*FLAGS_INDEX]; }
316  bool flagsPresent(unsigned extIndex = 0) { return has_flags(extIndex); }
317  flags_t init_flags() { initField(FLAGS_INDEX); return flags(); }
318  void disable_flags() { disable_fcs(); disableField(FLAGS_INDEX); }
319 
320  FIELD( rate, UInt8Parser, RATE_INDEX );
321  FIELD( channelOptions, RadiotapPacket_ChannelOptionsParser, CHANNEL_INDEX );
322  FIELD( fhss, UInt16LSBParser, FHSS_INDEX );
323  FIELD( dbmAntennaSignal, Int8Parser, DBM_ANTSIGNAL_INDEX );
324  FIELD( dbmAntennaNoise, Int8Parser, DBM_ANTNOISE_INDEX );
325  FIELD( lockQuality, UInt16LSBParser, LOCK_QUALITY_INDEX );
326  FIELD( txAttenuation, UInt16LSBParser, TX_ATTENUATION_INDEX );
327  FIELD( dbTxAttenuation, UInt16LSBParser, DB_TX_ATTENUATION_INDEX );
328  FIELD( dbmTxAttenuation, Int8Parser, DBM_TX_POWER_INDEX );
329  FIELD( antenna, UInt8Parser, ANTENNA_INDEX );
330  FIELD( dbAntennaSignal, UInt8Parser, DB_ANTSIGNAL_INDEX );
331  FIELD( dbAntennaNoise, UInt8Parser, DB_ANTNOISE_INDEX );
332  FIELD( rxFlags, RadiotapPacket_RxFlagsParser, RX_FLAGS_INDEX );
333  FIELD( txFlags, RadiotapPacket_TxFlagsParser, TX_FLAGS_INDEX );
334  FIELD( rtsRetries, UInt8Parser, RTS_RETRIES_INDEX );
335  FIELD( dataRetries, UInt8Parser, DATA_RETRIES_INDEX );
336  FIELD( mcs, RadiotapPacket_MCSParser, MCS_INDEX );
337  FIELD( vht, RadiotapPacket_VHTParser, VHT_INDEX );
338  FIELD( ampduStatus, RadiotapPacket_AMPDUStatusParser, A_MPDU_STATUS_INDEX );
339 
340 # undef FIELD
341 
343  UInt32Parser fcs();
344  bool has_fcs();
345  UInt32Parser init_fcs();
346  void disable_fcs();
347 
348  unsigned frameType();
349  unsigned rateInKbps();
350  unsigned bandwidth();
351 
352  private:
353  static const size_type fixed_bytes = 0; // hide this member, just in case
354 
355  typedef boost::array<size_type, MAX_INDEX * 3 + 2> OffsetTable;
356  typedef boost::unordered_map<std::size_t, OffsetTable> OffsetMap;
357 
358  //-////////////////////////////////////////////////////////////////////////
359  // Offset table handling
360 
361  // Fills the offset table based on a packet
362  static void parseOffsetTable(boost::uint8_t * data, int maxLength, OffsetTable & table);
363  // Generate an offset table just from the present flags
364  static void buildOffsetTable(boost::uint32_t presentFlags, OffsetTable & table);
365 
366  //-////////////////////////////////////////////////////////////////////////
367 
368  OffsetTable const & currentTable() const;
369  OffsetTable const & getTable(boost::uint32_t presentFlags) const;
370 
371  template <class Parser>
372  Parser parseField(unsigned index, unsigned extIndex);
373  void initField(unsigned index);
374  void disableField(unsigned index);
375 
376  size_type calculateSize() const;
377 
378  void updatePresentFlags(boost::uint32_t flags);
379  void insertRemoveBytes(unsigned from, unsigned to, int bytes);
380 
381  static OffsetMap offsetMap_;
382  OffsetTable const * currentTable_;
383 
384  friend struct RadiotapPacketType;
385  };
386 
401  : public PacketTypeBase,
402  public PacketTypeMixin<RadiotapPacketType>
403  {
407 
408  using mixin::initSize;
409 
410  static void init(packet p);
411  static void dump(packet p, std::ostream & os);
412  static factory_t nextPacketType(packet p);
413  static optional_range nextPacketRange(packet const & p);
414  };
415 
418 }
419 
420 //-/////////////////////////////////////////////////////////////////////////////////////////////////
421 #include "RadiotapPacket.cci"
422 //#include "RadiotapPacket.ct"
423 #include "RadiotapPacket.cti"
424 #endif
425 
426 
427 // Local Variables:
428 // mode: c++
429 // fill-column: 100
430 // comment-column: 40
431 // c-file-style: "senf"
432 // indent-tabs-mode: nil
433 // ispell-local-dictionary: "american"
434 // compile-command: "scons -u test"
435 // End:
RadiotapPacketParser parser
senf::FlagParser<?> cfp() const
senf::FlagParser<?> shortPreamble() const
#define SENF_PARSER_BITFIELD(name, bits, type)
Define bit-field.
PacketInterpreterBase::optional_range optional_range
Definition: PacketType.hh:111
senf::FlagParser<?>::value_type fcsAtEnd() const
Mixin to provide standard implementations for nextPacketRange and nextPacketType. ...
Definition: PacketType.hh:300
Parse 8bit unsigned byte aligned integer.
Definition: IntParser.hh:91
Parse in Radiotap Header channel frequency and flag field.
#define VHT_FLAG(name, desc, longDesc)
senf::FlagParser<?> fragmentation() const
Packets public header.
Return number of bytes to allocate to new object of given type.
PacketTypeMixin< RadiotapPacketType > mixin
PacketParserBase::size_type bytes(Parser const &p)
Return raw size parsed by the given parser object.
#define SENF_PARSER_FIELD(name, type)
Define normal parser field.
bool flagsPresent(unsigned extIndex=0)
#define SENF_PARSER_PRIVATE_FIELD(name, type)
Define parser field (private)
senf::FlagParser<?> padding() const
#define SENF_PARSER_FINALIZE(name)
Generate parser control members.
Parse an Radiotap header.
ConcretePacket< RadiotapPacketType > RadiotapPacket
Parse Flag field in Radiotap header.
#define MCS_FLAG(name, desc, longDesc)
void dump(std::ostream &os, DirectoryNode &dir=root())
Protocol specific packet handle.
Definition: Packet.hh:87
Helper base-class implementing the PacketType interface.
Definition: PacketType.hh:100
Packet data STL-sequence view.
Definition: PacketData.hh:61
#define SENF_PARSER_BITFIELD_RO(name, bits, type)
Define bit-field (read-only)
data_iterator i() const
Return beginning of data to parse.
senf::FlagParser<?> shortGI() const
flags_t flags(unsigned extIndex=0)
#define SENF_PARSER_SKIP(skip)
Skip bytes.
SENF_PACKET_PREVENT_TEMPLATE_INSTANTIATION(RadiotapPacket)
Parse 8bit signed byte aligned integer.
Definition: IntParser.hh:64
void init() const
Default implementation.
Parse 16bit unsigned byte aligned integer LSB.
Definition: IntParser.hh:201
detail::packet::size_type size_type
Unsigned integral type.
senf::FlagParser<?> wep() const
bool has_flags(unsigned extIndex=0)
#define FIELD(name, type, index)
ConcretePacket< RadiotapPacketType > packet
senf::FlagParser<?> badFCS() const
#define SENF_PARSER_SKIP_BITS(bits)
Skip bits within bitfield group.
Parser Base class.
PacketData & data() const
Access the packets raw data container.
struct ieee80211_mcs_info mcs
Parse 32bit unsigned byte aligned integer.
Definition: IntParser.hh:310
PacketInterpreterBase::factory_t factory_t
Definition: PacketType.hh:112
Parse 16bit unsigned byte aligned integer.
Definition: IntParser.hh:174
RadiotapPacket_FlagsParser flags_t
detail::packet::iterator data_iterator
Raw data iterator type.