80211Bundle: some clean-up
[senf.git] / Packets / 80211Bundle / RadiotapPacket.hh
1 // $Id$
2 //
3 // Copyright (C) 2008
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Christian Niephaus <cni@berlios.de>
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
23 /** \file
24     \brief Radiotap header \n
25         <b>Radiotap uses least significant bit byte order</b>
26     */
27
28 #ifndef HH_SENF_Packets_80211Bundle_RadiotapPacket_
29 #define HH_SENF_Packets_80211Bundle_RadiotapPacket_ 1
30
31 #include "../../Packets/Packets.hh"
32
33 namespace senf
34 {
35
36     /** \brief Parse Flag field in Radiotap header
37      * <b>Re-ordering of bits due to LSB byte order</b>
38
39      */
40     struct RadiotapPacketParser_Flags : public senf::PacketParserBase
41     {
42     #   include SENF_FIXED_PARSER()
43
44         SENF_PARSER_BITFIELD ( shortGI,        1, bool );
45         SENF_PARSER_BITFIELD ( badFCS,         1, bool );
46         SENF_PARSER_BITFIELD ( padding,        1, bool );
47         SENF_PARSER_BITFIELD ( fcsPresent,     1, bool );
48         SENF_PARSER_BITFIELD ( fragmentation,  1, bool );
49         SENF_PARSER_BITFIELD ( wep,            1, bool );
50         SENF_PARSER_BITFIELD ( shortPreamble,  1, bool );
51         SENF_PARSER_BITFIELD ( cfp,            1, bool );
52
53         SENF_PARSER_FINALIZE ( RadiotapPacketParser_Flags );
54     };
55
56     /** \brief Parse in Radiotap Header channel frequency and flag field
57
58         <b>Re-ordering of bits due to LSB byte order</b>
59      */
60     struct RadiotapPacketParser_ChannelOptions : public senf::PacketParserBase
61     {
62     #   include SENF_FIXED_PARSER()
63
64         SENF_PARSER_FIELD     ( freq,          UInt16LSBParser );
65
66         SENF_PARSER_BITFIELD  ( flag2ghz,             1, bool  );
67         SENF_PARSER_BITFIELD  ( ofdm,                 1, bool  );
68         SENF_PARSER_BITFIELD  ( cck,                  1, bool  );
69         SENF_PARSER_BITFIELD  ( turbo,                1, bool  );
70         SENF_PARSER_SKIP_BITS ( 4                              ); //currently unused in radiotap
71         SENF_PARSER_BITFIELD  ( quarterRateChannel,   1, bool  );
72         SENF_PARSER_BITFIELD  ( halfRateChannel,      1, bool  );
73         SENF_PARSER_BITFIELD  ( gsm,                  1, bool  );
74         SENF_PARSER_BITFIELD  ( staticTurbo,          1, bool  );
75         SENF_PARSER_BITFIELD  ( gfsk,                 1, bool  );
76         SENF_PARSER_BITFIELD  ( cckOfdm,              1, bool  );
77         SENF_PARSER_BITFIELD  ( passive,              1, bool  );
78         SENF_PARSER_BITFIELD  ( flag5ghz,             1, bool  );
79
80         SENF_PARSER_FINALIZE ( RadiotapPacketParser_ChannelOptions );
81     };
82
83     /** \brief Parse an Radiotap header
84
85         Parser implementing the Radiotap header
86
87         \see <a href="http://www.radiotap.org">Radiotap.org</a>
88
89         \todo extended present field (bit 31 of present field is set)
90     */
91     struct RadiotapPacketParser : public senf::PacketParserBase
92     {
93     #   include SENF_PARSER()
94
95         /*
96          * mandatory fields
97          */
98         SENF_PARSER_FIELD ( version, UInt8Parser     );
99         //padding bits, currently unused, it simply aligns the fields onto natural word boundaries.
100         SENF_PARSER_SKIP  ( 1,1                      );
101         SENF_PARSER_FIELD ( length,  UInt16LSBParser );
102
103         /*
104          * present flags
105          * indicate which data field are contained in the packet
106          */
107         SENF_PARSER_BITFIELD_RO ( lockQualityPresent,      1, bool );
108         SENF_PARSER_BITFIELD_RO ( dbmAntennaNoisePresent,  1, bool );
109         SENF_PARSER_BITFIELD_RO ( dbmAntennaSignalPresent, 1, bool );
110         SENF_PARSER_BITFIELD_RO ( fhssPresent,             1, bool );
111         SENF_PARSER_BITFIELD_RO ( channelOptionsPresent,   1, bool );
112         SENF_PARSER_BITFIELD_RO ( ratePresent,             1, bool );
113         SENF_PARSER_BITFIELD_RO ( flagsPresent,            1, bool );
114         SENF_PARSER_BITFIELD_RO ( tsftPresent,             1, bool );
115         SENF_PARSER_SKIP_BITS   ( 2                                ); //currently unused bits
116         SENF_PARSER_BITFIELD_RO ( dbAntennaNoisePresent,   1, bool );
117         SENF_PARSER_BITFIELD_RO ( dbAntennaSignalPresent,  1, bool );
118         SENF_PARSER_BITFIELD_RO ( antennaPresent,          1, bool );
119         SENF_PARSER_BITFIELD_RO ( dbmTxAttenuationPresent, 1, bool );
120         SENF_PARSER_BITFIELD_RO ( dbTxAttenuationPresent,  1, bool );
121         SENF_PARSER_BITFIELD_RO ( txAttenuationPresent,    1, bool );
122         SENF_PARSER_SKIP_BITS   ( 8                                ); //currently unused bits
123         //if bit is set,another 32 bit present flag is attached (not implemented yet)
124         SENF_PARSER_BITFIELD    ( extendedBitmaskPresent,  1, bool );
125         SENF_PARSER_SKIP_BITS   ( 7                                ); //currently unused bits
126
127         /*
128          * Radiotap data
129          * parsing data according to present flags
130          */
131         #define OPTIONAL_FIELD(name, parser) SENF_PARSER_VARIANT \
132             ( name##_, name##Present, \
133               ( novalue( disable_##name, VoidPacketParser )) \
134               (      id( name,           parser           )) );
135
136         OPTIONAL_FIELD ( tsft,             UInt64LSBParser                     );
137         OPTIONAL_FIELD ( flags,            RadiotapPacketParser_Flags          );
138         OPTIONAL_FIELD ( rate,             UInt8Parser                         );
139         OPTIONAL_FIELD ( channelOptions,   RadiotapPacketParser_ChannelOptions );
140         OPTIONAL_FIELD ( fhss,             UInt16LSBParser                     );
141         OPTIONAL_FIELD ( dbmAntennaSignal, Int8Parser                          );
142         OPTIONAL_FIELD ( dbmAntennaNoise,  Int8Parser                          );
143         OPTIONAL_FIELD ( txAttenuation,    UInt16LSBParser                     );
144         OPTIONAL_FIELD ( dbTxAttenuation,  UInt16LSBParser                     );
145         OPTIONAL_FIELD ( antenna,          UInt8Parser                         );
146         OPTIONAL_FIELD ( dbAntennaSignal,  UInt8Parser                         );
147         OPTIONAL_FIELD ( dbAntennaNoise,   UInt8Parser                         );
148
149         SENF_PARSER_INIT() {
150             version() = 0;
151         }
152
153         SENF_PARSER_FINALIZE(RadiotapPacketParser);
154     };
155
156     /** \brief Radiotap packet
157
158         \par Packet type (typedef):
159             \ref RadiotapPacket
160
161         \par Fields:
162             \ref RadiotapPacketParser
163
164         \ingroup protocolbundle_80211
165      */
166     struct RadiotapPacketType
167         : public senf::PacketTypeBase,
168           public senf::PacketTypeMixin<RadiotapPacketType>
169     {
170         typedef senf::PacketTypeMixin<RadiotapPacketType> mixin;
171         typedef senf::ConcretePacket<RadiotapPacketType> packet;
172         typedef senf::RadiotapPacketParser parser;
173
174         using mixin::nextPacketRange;
175         using mixin::init;
176         using mixin::initSize;
177
178         static void dump(packet p, std::ostream &os);
179         static void finalize(packet p);
180     };
181
182     typedef senf::ConcretePacket<RadiotapPacketType> RadiotapPacket;
183 }
184
185 #endif