4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Christian Niephaus <cni@berlios.de>
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.
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.
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.
24 \brief 802.11 WLANPacket public header */
26 #ifndef HH_SENF_Packets_80211Bundle_WLANPacket_
27 #define HH_SENF_Packets_80211Bundle_WLANPacket_ 1
29 #include <senf/Packets/Packets.hh>
30 #include <senf/Packets/DefaultBundle/EthernetPacket.hh>
31 #include <senf/Packets/DefaultBundle/LlcSnapPacket.hh>
33 ///////////////////////////////hh.p////////////////////////////////////////
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>
44 struct WLANPacketParser : public PacketParserBase
46 # include SENF_PARSER()
50 * re-ordering of fields due to the byte order
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 );
64 SENF_PARSER_FIELD ( duration, UInt16LSBParser );
66 SENF_PARSER_FINALIZE(WLANPacketParser);
69 ///////////////////////////////////////////////////////////////////////////
71 /** \brief Management frame parser
72 <b>Re-ordering of bits due to LSB byte order</b>
74 struct WLANPacket_MgtFrameParser : public WLANPacketParser
76 # include SENF_PARSER()
78 SENF_PARSER_INHERIT(WLANPacketParser);
80 SENF_PARSER_FIELD ( destinationAddress, MACAddressParser );
81 SENF_PARSER_FIELD ( sourceAddress, MACAddressParser );
82 SENF_PARSER_FIELD ( bssid, MACAddressParser );
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 );
89 SENF_PARSER_INIT() { type_() = 0; }
91 SENF_PARSER_FINALIZE(WLANPacket_MgtFrameParser);
93 boost::uint16_t sequenceNumber() const {
94 return (uint16_t)(seqNumber_2()) << 4 | seqNumber_1();
98 /** \brief WLAN Management frame packet
100 \par Packet type (typedef):
101 \refWLANPacket_MgtFrame
104 \ref WLANPacket_MgtFrameParser
105 \image html WLANPacket_MgtFrame.png
107 \ingroup protocolbundle_80211
109 struct WLANPacket_MgtFrameType
110 : public PacketTypeBase,
111 public PacketTypeMixin<WLANPacket_MgtFrameType>
113 typedef PacketTypeMixin<WLANPacket_MgtFrameType> mixin;
114 typedef ConcretePacket<WLANPacket_MgtFrameType> packet;
115 typedef WLANPacket_MgtFrameParser parser;
118 using mixin::initSize;
119 using PacketTypeBase::nextPacketRange;
121 static void dump(packet p, std::ostream &os);
124 typedef WLANPacket_MgtFrameType::packet WLANPacket_MgtFrame;
126 ///////////////////////////////////////////////////////////////////////////
128 /** \brief Control frame parser
129 <b>Re-ordering of bits due to LSB byte order</b>
131 currently only CTS, RTS and ACK control frames are supported
133 struct WLANPacket_CtrlFrameParser : public WLANPacketParser
135 # include SENF_PARSER()
137 SENF_PARSER_INHERIT(WLANPacketParser);
139 SENF_PARSER_FIELD ( receiverAddress, MACAddressParser );
141 //only RTS frame contains a source address field
142 //variant is also needed to set correct subtype value
143 SENF_PARSER_VARIANT ( subtype__, subtype,
144 ( ids( na, is_cts, set_cts, key(12, VoidPacketParser)) )
145 ( ids( na, is_ack, set_ack, key(13, VoidPacketParser)) )
146 ( ids( sourceAddress, is_rts, set_rts, key(11, MACAddressParser)) ) );
148 SENF_PARSER_INIT() { type_() = 1; }
150 SENF_PARSER_FINALIZE(WLANPacket_CtrlFrameParser);
153 /** \brief WLAN Control frame packet
155 \par Packet type (typedef):
156 \ref WLANPacket_CtrlFrame
159 \ref WLANPacket_CtrlFrameParser
160 \image html WLANPacket_CtrlFrame.png
162 \ingroup protocolbundle_80211
164 struct WLANPacket_CtrlFrameType
165 : public PacketTypeBase,
166 public PacketTypeMixin<WLANPacket_CtrlFrameType>
168 typedef PacketTypeMixin<WLANPacket_CtrlFrameType> mixin;
169 typedef ConcretePacket<WLANPacket_CtrlFrameType> packet;
170 typedef WLANPacket_CtrlFrameParser parser;
173 using mixin::initSize;
174 using PacketTypeBase::nextPacketRange;
176 static void dump(packet p, std::ostream &os);
179 typedef WLANPacket_CtrlFrameType::packet WLANPacket_CtrlFrame;
181 ///////////////////////////////////////////////////////////////////////////
183 /** \brief Data frame parser
184 <b>Re-ordering of bits due to LSB byte order</b>
186 struct WLANPacket_DataFrameParser : public WLANPacketParser
188 # include SENF_PARSER()
190 SENF_PARSER_INHERIT(WLANPacketParser);
192 SENF_PARSER_GOTO(subtype);
193 SENF_PARSER_SKIP_BITS(14); //<pkgdraw: hide
194 SENF_PARSER_PRIVATE_BITFIELD ( dsBits, 2, unsigned ); //<pkgdraw: hide
195 SENF_PARSER_SKIP ( 2, 2 ); //<pkgdraw: hide
197 SENF_PARSER_PRIVATE_FIELD ( addr1, MACAddressParser );
198 SENF_PARSER_PRIVATE_FIELD ( addr2, MACAddressParser );
199 SENF_PARSER_PRIVATE_FIELD ( addr3, MACAddressParser );
201 //sequence Number and fragment number
202 //shift bits manually due to LSB
203 SENF_PARSER_PRIVATE_BITFIELD ( seqNumber_1, 4, unsigned );
204 SENF_PARSER_BITFIELD ( fragmentNumber, 4, unsigned );
205 SENF_PARSER_PRIVATE_FIELD ( seqNumber_2, UInt8Parser );
207 boost::uint16_t sequenceNumber() const {
208 return (uint16_t)(seqNumber_2()) << 4 | seqNumber_1();
211 // TODO fourth address field in case of WDS
212 // SENF_PARSER_PRIVATE_VARIANT (wds_, dsBits,
213 // ( novalue ( disable_addr4, VoidPacketParser ))
214 // ( id ( addr4, key (3, MACAddressParser ))) );
217 SENF_PARSER_VARIANT ( qosField_, subtype,
218 ( ids( na, na, set_data, key(0, VoidPacketParser)) )
219 ( ids( na, na, set_nullData, key(4, VoidPacketParser)) )
220 ( ids( qosField, has_qosField, set_qosData, key(8, UInt16LSBParser )) )
221 //we cannot parse qos Null (data) frames at the moment
222 ( ids( na, na, set_qosNullData, key(12, UInt16LSBParser)) ) );
224 SENF_PARSER_INIT() { type_() = 2; }
226 SENF_PARSER_FINALIZE(WLANPacket_DataFrameParser);
228 MACAddressParser receiverAddress() const { return addr1(); }; //ra is always addr1
229 MACAddressParser transmitterAddress() const { return addr2(); }; //ta is always addr2
230 MACAddressParser sourceAddress() const;
231 MACAddressParser destinationAddress() const;
232 MACAddressParser bssid() const;
234 friend class WLANPacket_DataFrameType;
237 /** \brief WLAN Data frame packet
239 \par Packet type (typedef):
240 \ref WLANPacket_DataFrame
243 \ref WLANPacket_DataFrameParser
244 \image html WLANPacket_DataFrame.png
246 \ingroup protocolbundle_80211
248 struct WLANPacket_DataFrameType
249 : public PacketTypeBase,
250 public PacketTypeMixin<WLANPacket_DataFrameType>
252 typedef PacketTypeMixin<WLANPacket_DataFrameType> mixin;
253 typedef ConcretePacket<WLANPacket_DataFrameType> packet;
254 typedef WLANPacket_DataFrameParser parser;
257 using mixin::initSize;
258 using mixin::nextPacketRange;
260 static factory_t nextPacketType(packet p) {
261 return p->subtype() == 0 || p->subtype() == 8
262 ? LlcSnapPacket::factory()
266 static void dump(packet p, std::ostream &os);
269 typedef WLANPacket_DataFrameType::packet WLANPacket_DataFrame;
272 ///////////////////////////////hh.e////////////////////////////////////////
273 //#include "WLANPacket.cci"
274 //#include "WLANPacket.ct"
275 //#include "WLANPacket.cti"
282 // c-file-style: "senf"
283 // indent-tabs-mode: nil
284 // ispell-local-dictionary: "american"
285 // compile-command: "scons -u test"
286 // comment-column: 40