4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at
9 // http://senf.berlios.de/license.html
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on,
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
15 // Software distributed under the License is distributed on an "AS IS" basis,
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
17 // for the specific language governing rights and limitations under the License.
19 // The Original Code is Fraunhofer FOKUS code.
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V.
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
26 // Christian Niephaus <cni@berlios.de>
29 \brief 802.11 WLANPacket public header */
31 #ifndef HH_SENF_Packets_80211Bundle_WLANPacket_
32 #define HH_SENF_Packets_80211Bundle_WLANPacket_ 1
34 #include <senf/Packets/Packets.hh>
35 #include <senf/Packets/DefaultBundle/EthernetPacket.hh>
36 #include <senf/Packets/DefaultBundle/LlcSnapPacket.hh>
38 //-/////////////////////////////////////////////////////////////////////////////////////////////////
43 /** \brief 802.11 Frame parser
44 (see IEEE 802.11-2007 standard - Chapter 7 Frame formats)
45 <b>Re-ordering of bits due to host byte order</b>
49 struct WLANPacketParser : public PacketParserBase
51 # include SENF_PARSER()
55 * re-ordering of fields due to the byte order
57 SENF_PARSER_BITFIELD_RO ( subtype, 4, unsigned );
58 SENF_PARSER_BITFIELD_RO ( type, 2, unsigned );
59 SENF_PARSER_BITFIELD ( version, 2, unsigned );
60 SENF_PARSER_BITFIELD ( order, 1, bool );
61 SENF_PARSER_BITFIELD ( protectedFrame, 1, bool );
62 SENF_PARSER_BITFIELD ( moreData, 1, bool );
63 SENF_PARSER_BITFIELD ( pwrMgt, 1, bool );
64 SENF_PARSER_BITFIELD ( retry, 1, bool );
65 SENF_PARSER_BITFIELD ( moreFrag, 1, bool );
66 SENF_PARSER_BITFIELD ( fromDS, 1, bool );
67 SENF_PARSER_BITFIELD ( toDS, 1, bool );
69 SENF_PARSER_FIELD ( duration, UInt16LSBParser );
71 SENF_PARSER_FINALIZE(WLANPacketParser);
74 //-////////////////////////////////////////////////////////////////////////
76 /** \brief Management frame parser
77 <b>Re-ordering of bits due to LSB byte order</b>
79 struct WLANPacket_MgtFrameParser : public WLANPacketParser
81 # include SENF_PARSER()
83 SENF_PARSER_INHERIT(WLANPacketParser);
85 SENF_PARSER_FIELD ( destinationAddress, MACAddressParser );
86 SENF_PARSER_FIELD ( sourceAddress, MACAddressParser );
87 SENF_PARSER_FIELD ( bssid, MACAddressParser );
89 //workaround since bitfield LSB parsers are not available
90 SENF_PARSER_PRIVATE_BITFIELD ( seqNumber_1, 4, unsigned );
91 SENF_PARSER_BITFIELD ( fragmentNumber, 4, unsigned );
92 SENF_PARSER_PRIVATE_FIELD ( seqNumber_2, UInt8Parser );
94 SENF_PARSER_INIT() { type_() = 0; }
96 SENF_PARSER_FINALIZE(WLANPacket_MgtFrameParser);
98 boost::uint16_t sequenceNumber() const {
99 return (uint16_t)(seqNumber_2()) << 4 | seqNumber_1();
102 void sequenceNumber(boost::uint16_t sn);
105 /** \brief WLAN Management frame packet
107 \par Packet type (typedef):
108 \ref WLANPacket_MgtFrame
111 \ref WLANPacket_MgtFrameParser
112 \image html WLANPacket_MgtFrame.png
114 \ingroup protocolbundle_80211
116 struct WLANPacket_MgtFrameType
117 : public PacketTypeBase,
118 public PacketTypeMixin<WLANPacket_MgtFrameType>
120 typedef PacketTypeMixin<WLANPacket_MgtFrameType> mixin;
121 typedef ConcretePacket<WLANPacket_MgtFrameType> packet;
122 typedef WLANPacket_MgtFrameParser parser;
125 using mixin::initSize;
126 using PacketTypeBase::nextPacketRange;
128 static void dump(packet p, std::ostream & os);
131 /** \brief WLAN Management frame packet typedef
132 \ingroup protocolbundle_80211
134 typedef WLANPacket_MgtFrameType::packet WLANPacket_MgtFrame;
136 //-////////////////////////////////////////////////////////////////////////
138 /** \brief Control frame parser
139 <b>Re-ordering of bits due to LSB byte order</b>
141 currently only CTS, RTS and ACK control frames are supported
143 struct WLANPacket_CtrlFrameParser : public WLANPacketParser
145 # include SENF_PARSER()
147 SENF_PARSER_INHERIT(WLANPacketParser);
149 SENF_PARSER_FIELD ( receiverAddress, MACAddressParser );
151 //only RTS frame contains a source address field
152 //variant is also needed to set correct subtype value
153 SENF_PARSER_VARIANT ( subtype__, subtype,
154 ( ids( na, is_cts, set_cts, key(12, VoidPacketParser)) )
155 ( ids( na, is_ack, set_ack, key(13, VoidPacketParser)) )
156 ( ids( sourceAddress, is_rts, set_rts, key(11, MACAddressParser)) ) );
158 SENF_PARSER_INIT() { type_() = 1; }
160 SENF_PARSER_FINALIZE(WLANPacket_CtrlFrameParser);
163 /** \brief WLAN Control frame packet
165 \par Packet type (typedef):
166 \ref WLANPacket_CtrlFrame
169 \ref WLANPacket_CtrlFrameParser
170 \image html WLANPacket_CtrlFrame.png
172 \ingroup protocolbundle_80211
174 struct WLANPacket_CtrlFrameType
175 : public PacketTypeBase,
176 public PacketTypeMixin<WLANPacket_CtrlFrameType>
178 typedef PacketTypeMixin<WLANPacket_CtrlFrameType> mixin;
179 typedef ConcretePacket<WLANPacket_CtrlFrameType> packet;
180 typedef WLANPacket_CtrlFrameParser parser;
183 using mixin::initSize;
184 using PacketTypeBase::nextPacketRange;
186 static void dump(packet p, std::ostream & os);
189 /** \brief WLAN Control frame packet typedef
190 \ingroup protocolbundle_80211
192 typedef WLANPacket_CtrlFrameType::packet WLANPacket_CtrlFrame;
194 //-////////////////////////////////////////////////////////////////////////
196 /** \brief Data frame parser
197 <b>Re-ordering of bits due to LSB byte order</b>
199 struct WLANPacket_DataFrameParser : public WLANPacketParser
201 # include SENF_PARSER()
203 SENF_PARSER_INHERIT(WLANPacketParser);
206 typedef UIntFieldParser<6, 6+2> dsBits_t;
207 dsBits_t::value_type dsBits() const { return parse<dsBits_t>( 1); }
209 MACAddressParser addr1() const { return parse<MACAddressParser>( 4); }
210 MACAddressParser addr2() const { return parse<MACAddressParser>( 10); }
211 MACAddressParser addr3() const { return parse<MACAddressParser>( 16); }
213 //sequence Number and fragment number
214 //shift bits manually due to LSB
216 typedef UIntFieldParser<0, 0+4> seqNumber_1_t;
217 seqNumber_1_t seqNumber_1() const { return parse<seqNumber_1_t>( 22); }
220 typedef UIntFieldParser<4, 4+4> fragmentNumber_t;
221 fragmentNumber_t fragmentNumber() const { return parse<fragmentNumber_t>( 22); }
224 UInt8Parser seqNumber_2() const { return parse<UInt8Parser>( 23); }
227 boost::uint16_t sequenceNumber() const {
228 return (uint16_t)(seqNumber_2()) << 4 | seqNumber_1();
231 void sequenceNumber(boost::uint16_t sn);
233 SENF_PARSER_GOTO_OFFSET( 24, 24);
235 // TODO fourth address field in case of WDS
236 // SENF_PARSER_PRIVATE_VARIANT (wds_, dsBits,
237 // ( novalue ( disable_addr4, VoidPacketParser ))
238 // ( id ( addr4, key (3, MACAddressParser ))) );
241 SENF_PARSER_VARIANT ( qosField_, subtype,
242 ( ids( na, na, set_data, key(0, VoidPacketParser)) )
243 ( ids( na, na, set_nullData, key(4, VoidPacketParser)) )
244 ( ids( qosField, has_qosField, set_qosData, key(8, UInt16LSBParser )) )
245 //we cannot parse qos Null (data) frames at the moment
246 ( ids( na, na, set_qosNullData, key(12, UInt16LSBParser)) ) );
248 SENF_PARSER_INIT() { type_() = 2; }
250 SENF_PARSER_FINALIZE(WLANPacket_DataFrameParser);
252 MACAddressParser receiverAddress() const { return addr1(); }; //ra is always addr1
253 MACAddressParser transmitterAddress() const { return addr2(); }; //ta is always addr2
254 MACAddressParser sourceAddress() const;
255 MACAddressParser destinationAddress() const;
256 MACAddressParser bssid() const;
258 friend struct WLANPacket_DataFrameType;
261 /** \brief WLAN Data frame packet
263 \par Packet type (typedef):
264 \ref WLANPacket_DataFrame
267 \ref WLANPacket_DataFrameParser
268 \image html WLANPacket_DataFrame.png
270 \ingroup protocolbundle_80211
272 struct WLANPacket_DataFrameType
273 : public PacketTypeBase,
274 public PacketTypeMixin<WLANPacket_DataFrameType>
276 typedef PacketTypeMixin<WLANPacket_DataFrameType> mixin;
277 typedef ConcretePacket<WLANPacket_DataFrameType> packet;
278 typedef WLANPacket_DataFrameParser parser;
281 using mixin::initSize;
282 using mixin::nextPacketRange;
284 static factory_t nextPacketType(packet p) {
285 return p->subtype() == 0 || p->subtype() == 8
286 ? LlcSnapPacket::factory()
290 static void dump(packet p, std::ostream & os);
293 /** \brief WLAN Data frame packet typedef
294 \ingroup protocolbundle_80211
296 typedef WLANPacket_DataFrameType::packet WLANPacket_DataFrame;
299 //-/////////////////////////////////////////////////////////////////////////////////////////////////
300 //#include "WLANPacket.cci"
301 //#include "WLANPacket.ct"
302 //#include "WLANPacket.cti"
309 // c-file-style: "senf"
310 // indent-tabs-mode: nil
311 // ispell-local-dictionary: "american"
312 // compile-command: "scons -u test"
313 // comment-column: 40