WLANPacket.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 "WLANPacket.hh"
15 //#include "WLANPacket.ih"
16 
17 // Custom includes
18 #include <boost/io/ios_state.hpp>
19 
20 #define prefix_
21 //-/////////////////////////////////////////////////////////////////////////////////////////////////
22 
23 namespace {
24  void dumpBase(senf::WLANPacketParser const & p, std::ostream & os)
25  {
26  os << " version : " << p.version() << std::endl
27  << " type : " << p.type() << std::endl
28  << " subtype : " << p.subtype() << std::endl
29  << " flags :";
30  if ( p.toDS() ) os << " toDS";
31  if ( p.fromDS() ) os << " fromDS";
32  if ( p.moreFrag() ) os << " moreFrag";
33  if ( p.retry() ) os << " retry";
34  if ( p.pwrMgt() ) os << " pwrMgt";
35  if ( p.moreData() ) os << " moreData";
36  if ( p.protectedFrame() ) os << " protected";
37  if ( p.order() ) os << " order";
38 
39  if ( !(p.toDS() || p.fromDS() || p.moreFrag() || p.retry() || p.pwrMgt() ||
40  p.moreData() || p.protectedFrame() || p.order()) )
41  os << " none";
42  os << std::endl
43  << " duration : " << p.duration() << std::endl;
44  }
45 }
46 
47 //-/////////////////////////////////////////////////////////////////////////////////////////////////
48 // senf::WLANPacket_MgtFrameParser
49 
51 {
52  seqNumber_2() = 0u | (sn >> 4 ) ;
53  seqNumber_1() = 0u | sn;
54 }
55 
57 {
58  boost::io::ios_all_saver ias(os);
59  os << "802.11 MAC Management Frame:\n";
60  dumpBase(p.parser(), os);
61  os << senf::fieldName("destination") << p->destinationAddress() << std::endl
62  << senf::fieldName("source") << p->sourceAddress() << std::endl
63  << senf::fieldName("bss id") << p->bssid() << std::endl
64  << senf::fieldName("sequence number") << p->sequenceNumber() << std::endl
65  << senf::fieldName("fragment number") << p->fragmentNumber() << std::endl;
66 }
67 
68 //-/////////////////////////////////////////////////////////////////////////////////////////////////
69 // senf::WLANPacket_CtrlFrameType
70 
72 {
73  boost::io::ios_all_saver ias(os);
74  os << "802.11 MAC Control Frame:\n";
75  dumpBase(p.parser(), os);
76  os << senf::fieldName("receiver") << p->receiverAddress() << std::endl;
77  if (p->is_rts())
78  os << senf::fieldName("source") << p->sourceAddress() << std::endl;
79 }
80 
81 //-/////////////////////////////////////////////////////////////////////////////////////////////////
82 // senf::WLANPacket_DataFrameParser
83 
85 {
86  seqNumber_2() = 0u | (sn >> 4 ) ;
87  seqNumber_1() = 0u | sn;
88 }
89 
91  const
92 {
93  switch (dsBits()) {
94  case 0 :
95  case 2 :
96  return addr1();
97  default:
98  return addr3();
99  }
100 }
101 
103  const
104 {
105  switch (dsBits()) {
106  case 0:
107  case 1:
108  return addr2();
109  case 3:
110  return addr4();
111  default:
112  return addr3();
113  }
114 }
115 
117  const
118 {
119  switch (dsBits()) {
120  case 0 :
121  return addr3();
122  case 1 :
123  return addr1();
124  default:
125  return addr2();
126  }
127 }
128 
130 {
131  boost::io::ios_all_saver ias(os);
132  os << "802.11 MAC Data Frame:\n";
133  dumpBase(p.parser(), os);
134  os << senf::fieldName("destination") << p->destinationAddress();
135  if (p->dsBits()==0 || p->dsBits()==2) os << " (receiver)";
136  os << std::endl
137  << senf::fieldName("source") << p->sourceAddress();
138  if (p->dsBits()==0 || p->dsBits()==1) os << " (transmitter)";
139  os << std::endl
140  << senf::fieldName("bss id") << p->bssid();
141  if (p->dsBits()==1) os << " (receiver)";
142  else if (p->dsBits()!=0) os << " (transmitter)";
143  os << std::endl
144  << senf::fieldName("sequence number") << p->sequenceNumber() << std::endl
145  << senf::fieldName("fragment number") << p->fragmentNumber() << std::endl;
146  if (p->has_qosField())
147  os << senf::fieldName("QOS data") << p->qosField() << std::endl;
148 }
149 
150 //-/////////////////////////////////////////////////////////////////////////////////////////////////
151 #undef prefix_
152 
153 
154 // Local Variables:
155 // mode: c++
156 // fill-column: 100
157 // c-file-style: "senf"
158 // indent-tabs-mode: nil
159 // ispell-local-dictionary: "american"
160 // compile-command: "scons -u test"
161 // comment-column: 40
162 // End:
senf::UIntFieldParser<?,?+2 >::value_type type() const
static void dump(packet p, std::ostream &os)
Definition: WLANPacket.cc:56
#define prefix_
Definition: WLANPacket.cc:20
boost::uint16_t sequenceNumber() const
Definition: WLANPacket.hh:88
senf::UIntFieldParser<?,?+4 > seqNumber_1() const
std::string fieldName(std::string const &s)
Definition: DumpFormat.cc:28
senf::FlagParser<?> retry() const
senf::UIntFieldParser<?,?+2 > version() const
MACAddressParser destinationAddress() const
Definition: WLANPacket.cc:90
senf::FlagParser<?> toDS() const
senf::FlagParser<?> pwrMgt() const
Parse an Ethernet MAC address.
MACAddressParser bssid() const
Definition: WLANPacket.cc:116
senf::UIntFieldParser<?,?+4 >::value_type subtype() const
senf::FlagParser<?> moreData() const
Protocol specific packet handle.
Definition: Packet.hh:87
static void dump(packet p, std::ostream &os)
Definition: WLANPacket.cc:71
802.11 Frame parser (see IEEE 802.11-2007 standard - Chapter 7 Frame formats) Re-ordering of bits due...
Definition: WLANPacket.hh:35
senf::UIntFieldParser<?,?+2 > dsBits() const
UInt8Parser seqNumber_2() const
boost::uint16_t sequenceNumber() const
Definition: WLANPacket.hh:232
senf::FlagParser<?> fromDS() const
senf::FlagParser<?> protectedFrame() const
MACAddressParser sourceAddress() const
Definition: WLANPacket.cc:102
UInt16LSBParser duration() const
802.11 WLANPacket public header
senf::FlagParser<?> moreFrag() const
static void dump(packet p, std::ostream &os)
Definition: WLANPacket.cc:129
senf::FlagParser<?> order() const
Parser parser() const
Access packet field parser directly.