WLANPacket.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_WLANPacket_
18 #define HH_SENF_Packets_80211Bundle_WLANPacket_ 1
19 
22 #include "Registries.hh"
23 
24 //-/////////////////////////////////////////////////////////////////////////////////////////////////
25 
26 namespace senf
27 {
28 
36  {
37  # include SENF_PARSER()
38 
39  /*
40  * Frame control field
41  * re-ordering of fields due to the byte order
42  */
43  SENF_PARSER_BITFIELD_RO( subtype, 4, unsigned );
44  SENF_PARSER_BITFIELD_RO( type, 2, unsigned );
45  SENF_PARSER_BITFIELD ( version, 2, unsigned );
46  SENF_PARSER_BITFIELD ( order, 1, bool );
48  SENF_PARSER_BITFIELD ( moreData, 1, bool );
49  SENF_PARSER_BITFIELD ( pwrMgt, 1, bool );
50  SENF_PARSER_BITFIELD ( retry, 1, bool );
51  SENF_PARSER_BITFIELD ( moreFrag, 1, bool );
52  SENF_PARSER_BITFIELD ( fromDS, 1, bool );
53  SENF_PARSER_BITFIELD ( toDS, 1, bool );
54 
56 
58 
61  SENF_PARSER_BITFIELD ( dsBits, 2, unsigned );
62  };
63 
64  //-////////////////////////////////////////////////////////////////////////
65 
70  {
71  # include SENF_PARSER()
72 
74 
75  SENF_PARSER_FIELD( destinationAddress, MACAddressParser );
78 
79  //workaround since bitfield LSB parsers are not available
80  SENF_PARSER_PRIVATE_BITFIELD( seqNumber_1, 4, unsigned );
81  SENF_PARSER_BITFIELD ( fragmentNumber, 4, unsigned );
83 
85 
86  SENF_PARSER_INIT() { type_() = 0; }
87 
88  boost::uint16_t sequenceNumber() const {
89  return (uint16_t)(seqNumber_2()) << 4 | seqNumber_1();
90  };
91 
92  void sequenceNumber(boost::uint16_t sn);
93 
94  friend struct WLANPacket_MgtFrameType;
95  };
96 
109  : public PacketTypeBase,
110  public PacketTypeMixin<WLANPacket_MgtFrameType, WLANManagementSubtypes>
111  {
115 
116  using mixin::init;
117  using mixin::initSize;
118  using mixin::nextPacketType;
119  using mixin::nextPacketRange;
120 
121  static key_t nextPacketKey(packet p)
122  { return p->subtype(); }
123  static void finalize(packet p)
124  { p->subtype_() << key(p.next(nothrow)); }
125  static void dump(packet p, std::ostream & os);
126  };
127 
132 
133  //-////////////////////////////////////////////////////////////////////////
134 
141  {
142  # include SENF_PARSER()
143 
145 
146  SENF_PARSER_FIELD( receiverAddress, MACAddressParser );
147 
148  //only RTS frame contains a source address field
149  //variant is also needed to set correct subtype value
150  SENF_PARSER_VARIANT( subtype__, subtype,
151  ( ids( na, is_cts, set_cts, key(12, VoidPacketParser)) )
152  ( ids( na, is_ack, set_ack, key(13, VoidPacketParser)) )
153  ( ids( sourceAddress, is_rts, set_rts, key(11, MACAddressParser)) ) );
154 
156 
157  SENF_PARSER_INIT() { type_() = 1; }
158  };
159 
172  : public PacketTypeBase,
173  public PacketTypeMixin<WLANPacket_CtrlFrameType>
174  {
178 
179  using mixin::init;
180  using mixin::initSize;
182 
183  static void dump(packet p, std::ostream & os);
184  };
185 
190 
191  //-////////////////////////////////////////////////////////////////////////
192 
194  {
195  # include SENF_PARSER()
196 
199  SENF_PARSER_FIELD( sequenceNumber, UInt32LSBParser );
200 
201  // ToDo (2016-12-07 tho) add variant parser for addr5 & addr6
202  // depending on the AE field in flags
203 
205  };
206 
211  {
212  # include SENF_PARSER()
213 
215 
216  protected:
217  MACAddressParser addr1() const { return parse<MACAddressParser>( 4); }
218  MACAddressParser addr2() const { return parse<MACAddressParser>( 10); }
219  MACAddressParser addr3() const { return parse<MACAddressParser>( 16); }
220 
221  // sequence Number and fragment number
222  // shift bits manually due to LSB
223 
225  seqNumber_1_t seqNumber_1() const { return parse<seqNumber_1_t>( 22); }
226  UInt8Parser seqNumber_2() const { return parse<UInt8Parser>( 23); }
227 
228  public:
230  fragmentNumber_t fragmentNumber() const { return parse<fragmentNumber_t>( 22); }
231 
232  boost::uint16_t sequenceNumber() const {
233  return (uint16_t)(seqNumber_2()) << 4 | seqNumber_1();
234  };
235 
236  void sequenceNumber(boost::uint16_t sn);
237 
238  SENF_PARSER_GOTO_OFFSET( 24, 24);
239 
240  // 4th address
242  ( novalue( disable_addr4, VoidPacketParser ))
243  ( id ( addr4, key(3, MACAddressParser ))) );
244 
245  // QoS Field
246  SENF_PARSER_VARIANT( qosField_, subtype,
247  ( ids( na, na, set_data, key(0, VoidPacketParser)) )
248  ( ids( na, na, set_nullData, key(4, VoidPacketParser)) )
249  ( ids( qosField, has_qosField, set_qosData, key(8, UInt16LSBParser )) )
250  //we cannot parse qos Null (data) frames at the moment
251  ( ids( na, na, set_qosNullData, key(12, UInt16LSBParser)) ) );
252 
253  // Mesh Control field
255  ( novalue( disable_mcf, VoidPacketParser ))
256  ( id ( meshControlField, key(3, WLANPacket_MeshControlFieldParser ))) );
257 
259 
260  SENF_PARSER_INIT() { type_() = 2; }
261 
262  MACAddressParser receiverAddress() const { return addr1(); }; //ra is always addr1
263  MACAddressParser transmitterAddress() const { return addr2(); }; //ta is always addr2
264  MACAddressParser sourceAddress() const;
265  MACAddressParser destinationAddress() const;
266  MACAddressParser bssid() const;
267 
269  };
270 
283  : public PacketTypeBase,
284  public PacketTypeMixin<WLANPacket_DataFrameType>
285  {
289 
290  using mixin::init;
291  using mixin::initSize;
292  using mixin::nextPacketRange;
293 
294  static factory_t nextPacketType(packet p) {
295  return p->subtype() == 0 || p->subtype() == 8
297  : no_factory();
298  }
299 
300  static void dump(packet p, std::ostream & os);
301  };
302 
307 }
308 
309 //-/////////////////////////////////////////////////////////////////////////////////////////////////
310 //#include "WLANPacket.cci"
311 //#include "WLANPacket.ct"
312 //#include "WLANPacket.cti"
313 #endif
314 
315 
316 // Local Variables:
317 // mode: c++
318 // fill-column: 100
319 // c-file-style: "senf"
320 // indent-tabs-mode: nil
321 // ispell-local-dictionary: "american"
322 // compile-command: "scons -u test"
323 // comment-column: 40
324 // End:
#define SENF_PARSER_INHERIT(base)
Define parser inheritance.
WLANPacket_DataFrameParser parser
Definition: WLANPacket.hh:288
EthernetPacket public header.
ConcretePacket< WLANPacket_CtrlFrameType > packet
Definition: WLANPacket.hh:176
MACAddressParser receiverAddress() const
Definition: WLANPacket.hh:262
Parse unsigned bitfield with up to 32bit&#39;s.
Definition: IntParser.hh:515
senf::UIntFieldParser<?,?+2 >::value_type type() const
#define SENF_PARSER_BITFIELD(name, bits, type)
Define bit-field.
ConcretePacket< WLANPacket_MgtFrameType > packet
Definition: WLANPacket.hh:113
UIntFieldParser< 0, 0+4 > seqNumber_1_t
Definition: WLANPacket.hh:224
Mixin to provide standard implementations for nextPacketRange and nextPacketType. ...
Definition: PacketType.hh:300
boost::uint16_t sequenceNumber() const
Definition: WLANPacket.hh:88
Parse 8bit unsigned byte aligned integer.
Definition: IntParser.hh:91
WLAN Data frame packet.
Definition: WLANPacket.hh:282
Control frame parser Re-ordering of bits due to LSB byte order
Definition: WLANPacket.hh:140
senf::FlagParser<?> retry() const
senf::UIntFieldParser<?,?+2 > version() const
MACAddressParser addr2() const
Definition: WLANPacket.hh:218
senf::FlagParser<?> toDS() const
senf::FlagParser<?> pwrMgt() const
#define SENF_PARSER_FIELD(name, type)
Define normal parser field.
#define SENF_PARSER_VARIANT(name, chooser, types)
Define VariantParser field.
#define SENF_PARSER_PRIVATE_VARIANT(name, chooser, types)
Define private VariantParser field.
WLANPacket_DataFrameType::packet WLANPacket_DataFrame
WLAN Data frame packet typedef.
Definition: WLANPacket.hh:306
#define SENF_PARSER_PRIVATE_FIELD(name, type)
Define parser field (private)
Parse an Ethernet MAC address.
WLANPacket_MgtFrameType::packet WLANPacket_MgtFrame
WLAN Management frame packet typedef.
Definition: WLANPacket.hh:131
#define SENF_PARSER_FINALIZE(name)
Generate parser control members.
senf::UIntFieldParser<?,?+4 >::value_type subtype() const
senf::FlagParser<?> moreData() const
MACAddressParser addr3() const
Definition: WLANPacket.hh:219
UIntFieldParser< 4, 4+4 > fragmentNumber_t
Definition: WLANPacket.hh:229
Management frame parser Re-ordering of bits due to LSB byte order
Definition: WLANPacket.hh:69
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
#define SENF_PARSER_BITFIELD_RO(name, bits, type)
Define bit-field (read-only)
WLAN Management frame packet.
Definition: WLANPacket.hh:108
#define SENF_PARSER_INIT()
Define parser initialization routine.
static optional_range nextPacketRange(packet p)
Get next packet placement.
Packet next() const
Get next packet in chain.
std::uint8_t bssid[6]
Default parser parsing nothing.
UInt8Parser seqNumber_2() const
Definition: WLANPacket.hh:226
802.11 Frame parser (see IEEE 802.11-2007 standard - Chapter 7 Frame formats) Re-ordering of bits due...
Definition: WLANPacket.hh:35
PacketTypeMixin< WLANPacket_CtrlFrameType > mixin
Definition: WLANPacket.hh:175
WLANPacket_CtrlFrameParser parser
Definition: WLANPacket.hh:177
senf::UIntFieldParser<?,?+2 > dsBits() const
seqNumber_1_t seqNumber_1() const
Definition: WLANPacket.hh:225
WLANPacket_CtrlFrameType::packet WLANPacket_CtrlFrame
WLAN Control frame packet typedef.
Definition: WLANPacket.hh:189
ConcretePacket< WLANPacket_DataFrameType > packet
Definition: WLANPacket.hh:287
Parse 16bit unsigned byte aligned integer LSB.
Definition: IntParser.hh:201
nothrow
fragmentNumber_t fragmentNumber() const
Definition: WLANPacket.hh:230
static key_t nextPacketKey(packet p)
Definition: WLANPacket.hh:121
boost::uint16_t sequenceNumber() const
Definition: WLANPacket.hh:232
senf::FlagParser<?> fromDS() const
senf::FlagParser<?> protectedFrame() const
PacketTypeMixin< WLANPacket_DataFrameType > mixin
Definition: WLANPacket.hh:286
Data frame parser Re-ordering of bits due to LSB byte order
Definition: WLANPacket.hh:210
UInt16LSBParser duration() const
#define SENF_PARSER_SKIP_BITS(bits)
Skip bits within bitfield group.
Parser Base class.
static factory_t nextPacketType(packet p)
Definition: WLANPacket.hh:294
PacketInterpreterBase::factory_t factory_t
Definition: PacketType.hh:112
#define SENF_PARSER_GOTO_OFFSET(offset)
Change current offset to explicit value.
static factory_t factory()
Return factory for packets of specific type.
MACAddressParser transmitterAddress() const
Definition: WLANPacket.hh:263
#define SENF_PARSER_PRIVATE_BITFIELD(name, bits, type)
Define bit-field (private)
WLANPacket_MgtFrameParser parser
Definition: WLANPacket.hh:114
LLC/SNAP public header.
WLAN Control frame packet.
Definition: WLANPacket.hh:171
senf::FlagParser<?> moreFrag() const
PacketTypeMixin< WLANPacket_MgtFrameType, WLANManagementSubtypes > mixin
Definition: WLANPacket.hh:112
senf::FlagParser<?> order() const
MACAddressParser addr1() const
Definition: WLANPacket.hh:217
80211Bundle packet registries public header
static void finalize(packet p)
Definition: WLANPacket.hh:123