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