Fix documentation build under maverick (doxygen 1.7.1)
[senf.git] / senf / Packets / 80211Bundle / WLANPacket.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 802.11 WLANPacket public header */
25
26 #ifndef HH_SENF_Packets_80211Bundle_WLANPacket_
27 #define HH_SENF_Packets_80211Bundle_WLANPacket_ 1
28
29 #include <senf/Packets/Packets.hh>
30 #include <senf/Packets/DefaultBundle/EthernetPacket.hh>
31 #include <senf/Packets/DefaultBundle/LlcSnapPacket.hh>
32
33 //-/////////////////////////////////////////////////////////////////////////////////////////////////
34
35 namespace senf
36 {
37
38     /** \brief 802.11 Frame parser
39         (see IEEE 802.11-2007 standard - Chapter 7 Frame formats)
40         <b>Re-ordering of bits due to host byte order</b>
41
42         Frame base class.
43      */
44     struct WLANPacketParser : public PacketParserBase
45     {
46     #   include SENF_PARSER()
47
48         /*
49          * Frame control field
50          * re-ordering of fields due to the byte order
51          */
52         SENF_PARSER_BITFIELD_RO ( subtype,        4,  unsigned );
53         SENF_PARSER_BITFIELD_RO ( type,           2,  unsigned );
54         SENF_PARSER_BITFIELD    ( version,        2,  unsigned );
55         SENF_PARSER_BITFIELD    ( order,          1,  bool     );
56         SENF_PARSER_BITFIELD    ( protectedFrame, 1,  bool     );
57         SENF_PARSER_BITFIELD    ( moreData,       1,  bool     );
58         SENF_PARSER_BITFIELD    ( pwrMgt,         1,  bool     );
59         SENF_PARSER_BITFIELD    ( retry,          1,  bool     );
60         SENF_PARSER_BITFIELD    ( moreFrag,       1,  bool     );
61         SENF_PARSER_BITFIELD    ( fromDS,         1,  bool     );
62         SENF_PARSER_BITFIELD    ( toDS,           1,  bool     );
63
64         SENF_PARSER_FIELD       ( duration,       UInt16LSBParser );
65
66         SENF_PARSER_FINALIZE(WLANPacketParser);
67     };
68
69     //-////////////////////////////////////////////////////////////////////////
70
71     /** \brief Management frame parser
72         <b>Re-ordering of bits due to LSB byte order</b>
73      */
74     struct WLANPacket_MgtFrameParser : public WLANPacketParser
75     {
76     #   include SENF_PARSER()
77
78         SENF_PARSER_INHERIT(WLANPacketParser);
79
80         SENF_PARSER_FIELD            ( destinationAddress, MACAddressParser );
81         SENF_PARSER_FIELD            ( sourceAddress,      MACAddressParser );
82         SENF_PARSER_FIELD            ( bssid,              MACAddressParser );
83
84         //workaround since bitfield LSB parsers are not available
85         SENF_PARSER_PRIVATE_BITFIELD ( seqNumber_1,    4, unsigned );
86         SENF_PARSER_BITFIELD         ( fragmentNumber, 4, unsigned );
87         SENF_PARSER_PRIVATE_FIELD    ( seqNumber_2,    UInt8Parser );
88
89         SENF_PARSER_INIT() { type_() = 0; }
90
91         SENF_PARSER_FINALIZE(WLANPacket_MgtFrameParser);
92
93         boost::uint16_t sequenceNumber() const {
94             return (uint16_t)(seqNumber_2()) << 4 | seqNumber_1();
95         };
96
97         void sequenceNumber(boost::uint16_t sn);
98     };
99
100     /** \brief WLAN Management frame packet
101
102         \par Packet type (typedef):
103             \ref WLANPacket_MgtFrame
104
105         \par Fields:
106             \ref WLANPacket_MgtFrameParser
107             \image html WLANPacket_MgtFrame.png
108
109         \ingroup protocolbundle_80211
110      */
111     struct WLANPacket_MgtFrameType
112         : public PacketTypeBase,
113           public PacketTypeMixin<WLANPacket_MgtFrameType>
114     {
115         typedef PacketTypeMixin<WLANPacket_MgtFrameType> mixin;
116         typedef ConcretePacket<WLANPacket_MgtFrameType> packet;
117         typedef WLANPacket_MgtFrameParser parser;
118
119         using mixin::init;
120         using mixin::initSize;
121         using PacketTypeBase::nextPacketRange;
122
123         static void dump(packet p, std::ostream &os);
124     };
125
126     /** \brief WLAN Management frame packet typedef
127         \ingroup protocolbundle_80211
128      */
129     typedef WLANPacket_MgtFrameType::packet WLANPacket_MgtFrame;
130
131     //-////////////////////////////////////////////////////////////////////////
132
133     /** \brief Control frame parser
134         <b>Re-ordering of bits due to LSB byte order</b>
135
136         currently only CTS, RTS and ACK control frames are supported
137      */
138     struct WLANPacket_CtrlFrameParser : public WLANPacketParser
139     {
140     #   include SENF_PARSER()
141
142         SENF_PARSER_INHERIT(WLANPacketParser);
143
144         SENF_PARSER_FIELD   ( receiverAddress, MACAddressParser );
145
146         //only RTS frame contains a source address field
147         //variant is also needed to set correct subtype value
148         SENF_PARSER_VARIANT ( subtype__, subtype,
149                 ( ids( na,            is_cts, set_cts, key(12, VoidPacketParser)) )
150                 ( ids( na,            is_ack, set_ack, key(13, VoidPacketParser)) )
151                 ( ids( sourceAddress, is_rts, set_rts, key(11, MACAddressParser)) ) );
152
153         SENF_PARSER_INIT() { type_() = 1; }
154
155         SENF_PARSER_FINALIZE(WLANPacket_CtrlFrameParser);
156     };
157
158     /** \brief WLAN Control frame packet
159
160         \par Packet type (typedef):
161             \ref WLANPacket_CtrlFrame
162
163         \par Fields:
164             \ref WLANPacket_CtrlFrameParser
165             \image html WLANPacket_CtrlFrame.png
166
167         \ingroup protocolbundle_80211
168      */
169     struct WLANPacket_CtrlFrameType
170         : public PacketTypeBase,
171           public PacketTypeMixin<WLANPacket_CtrlFrameType>
172     {
173         typedef PacketTypeMixin<WLANPacket_CtrlFrameType> mixin;
174         typedef ConcretePacket<WLANPacket_CtrlFrameType> packet;
175         typedef WLANPacket_CtrlFrameParser parser;
176
177         using mixin::init;
178         using mixin::initSize;
179         using PacketTypeBase::nextPacketRange;
180
181         static void dump(packet p, std::ostream &os);
182     };
183
184     /** \brief WLAN Control frame packet typedef
185         \ingroup protocolbundle_80211
186      */
187     typedef WLANPacket_CtrlFrameType::packet WLANPacket_CtrlFrame;
188
189     //-////////////////////////////////////////////////////////////////////////
190
191     /** \brief Data frame parser
192         <b>Re-ordering of bits due to LSB byte order</b>
193      */
194     struct WLANPacket_DataFrameParser : public WLANPacketParser
195     {
196     #   include SENF_PARSER()
197
198         SENF_PARSER_INHERIT(WLANPacketParser);
199
200     protected:
201         typedef UIntFieldParser<6, 6+2> dsBits_t;
202         dsBits_t::value_type dsBits() const { return parse<dsBits_t>( 1); }
203
204         MACAddressParser addr1() const { return parse<MACAddressParser>(  4); }
205         MACAddressParser addr2() const { return parse<MACAddressParser>( 10); }
206         MACAddressParser addr3() const { return parse<MACAddressParser>( 16); }
207
208         //sequence Number and fragment number
209         //shift bits manually due to LSB
210
211         typedef UIntFieldParser<0, 0+4> seqNumber_1_t;
212         seqNumber_1_t seqNumber_1() const { return parse<seqNumber_1_t>( 22); }
213
214     public:
215         typedef UIntFieldParser<4, 4+4> fragmentNumber_t;
216         fragmentNumber_t fragmentNumber() const { return parse<fragmentNumber_t>( 22); }
217
218     protected:
219         UInt8Parser seqNumber_2() const { return parse<UInt8Parser>( 23); }
220
221     public:
222         boost::uint16_t sequenceNumber() const {
223             return (uint16_t)(seqNumber_2()) << 4 | seqNumber_1();
224         };
225
226         void sequenceNumber(boost::uint16_t sn);
227
228         SENF_PARSER_GOTO_OFFSET( 24, 24);
229
230         // TODO fourth address field in case of WDS
231         // SENF_PARSER_PRIVATE_VARIANT (wds_, dsBits,
232         //     ( novalue ( disable_addr4,               VoidPacketParser ))
233         //     ( id      ( addr4,  key (3,              MACAddressParser ))) );
234
235         //QoS Field
236         SENF_PARSER_VARIANT ( qosField_, subtype,
237                 ( ids( na,       na,           set_data,        key(0, VoidPacketParser)) )
238                 ( ids( na,       na,           set_nullData,    key(4, VoidPacketParser)) )
239                 ( ids( qosField, has_qosField, set_qosData,     key(8, UInt16LSBParser )) )
240                 //we cannot parse qos Null (data) frames at the moment
241                 ( ids( na,       na,           set_qosNullData, key(12, UInt16LSBParser)) ) );
242
243         SENF_PARSER_INIT() { type_() = 2; }
244
245         SENF_PARSER_FINALIZE(WLANPacket_DataFrameParser);
246
247         MACAddressParser receiverAddress() const    { return addr1(); }; //ra is always addr1
248         MACAddressParser transmitterAddress() const { return addr2(); }; //ta is always addr2
249         MACAddressParser sourceAddress() const;
250         MACAddressParser destinationAddress() const;
251         MACAddressParser bssid() const;
252
253         friend class WLANPacket_DataFrameType;
254     };
255
256     /** \brief WLAN Data frame packet
257
258         \par Packet type (typedef):
259             \ref WLANPacket_DataFrame
260
261         \par Fields:
262             \ref WLANPacket_DataFrameParser
263             \image html WLANPacket_DataFrame.png
264
265         \ingroup protocolbundle_80211
266      */
267     struct WLANPacket_DataFrameType
268         : public PacketTypeBase,
269           public PacketTypeMixin<WLANPacket_DataFrameType>
270     {
271         typedef PacketTypeMixin<WLANPacket_DataFrameType> mixin;
272         typedef ConcretePacket<WLANPacket_DataFrameType> packet;
273         typedef WLANPacket_DataFrameParser parser;
274
275         using mixin::init;
276         using mixin::initSize;
277         using mixin::nextPacketRange;
278
279         static factory_t nextPacketType(packet p) {
280             return p->subtype() == 0 || p->subtype() == 8
281                 ? LlcSnapPacket::factory()
282                 : no_factory();
283         }
284
285         static void dump(packet p, std::ostream &os);
286     };
287
288     /** \brief WLAN Data frame packet typedef
289         \ingroup protocolbundle_80211
290      */
291     typedef WLANPacket_DataFrameType::packet WLANPacket_DataFrame;
292 }
293
294 //-/////////////////////////////////////////////////////////////////////////////////////////////////
295 //#include "WLANPacket.cci"
296 //#include "WLANPacket.ct"
297 //#include "WLANPacket.cti"
298 #endif
299
300 \f
301 // Local Variables:
302 // mode: c++
303 // fill-column: 100
304 // c-file-style: "senf"
305 // indent-tabs-mode: nil
306 // ispell-local-dictionary: "american"
307 // compile-command: "scons -u test"
308 // comment-column: 40
309 // End: