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();
97 void sequenceNumber(boost::uint16_t sn);
100 /** \brief WLAN Management frame packet
102 \par Packet type (typedef):
103 \ref WLANPacket_MgtFrame
106 \ref WLANPacket_MgtFrameParser
107 \image html WLANPacket_MgtFrame.png
109 \ingroup protocolbundle_80211
111 struct WLANPacket_MgtFrameType
112 : public PacketTypeBase,
113 public PacketTypeMixin<WLANPacket_MgtFrameType>
115 typedef PacketTypeMixin<WLANPacket_MgtFrameType> mixin;
116 typedef ConcretePacket<WLANPacket_MgtFrameType> packet;
117 typedef WLANPacket_MgtFrameParser parser;
120 using mixin::initSize;
121 using PacketTypeBase::nextPacketRange;
123 static void dump(packet p, std::ostream &os);
126 /** \brief WLAN Management frame packet typedef
127 \ingroup protocolbundle_80211
129 typedef WLANPacket_MgtFrameType::packet WLANPacket_MgtFrame;
131 ///////////////////////////////////////////////////////////////////////////
133 /** \brief Control frame parser
134 <b>Re-ordering of bits due to LSB byte order</b>
136 currently only CTS, RTS and ACK control frames are supported
138 struct WLANPacket_CtrlFrameParser : public WLANPacketParser
140 # include SENF_PARSER()
142 SENF_PARSER_INHERIT(WLANPacketParser);
144 SENF_PARSER_FIELD ( receiverAddress, MACAddressParser );
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)) ) );
153 SENF_PARSER_INIT() { type_() = 1; }
155 SENF_PARSER_FINALIZE(WLANPacket_CtrlFrameParser);
158 /** \brief WLAN Control frame packet
160 \par Packet type (typedef):
161 \ref WLANPacket_CtrlFrame
164 \ref WLANPacket_CtrlFrameParser
165 \image html WLANPacket_CtrlFrame.png
167 \ingroup protocolbundle_80211
169 struct WLANPacket_CtrlFrameType
170 : public PacketTypeBase,
171 public PacketTypeMixin<WLANPacket_CtrlFrameType>
173 typedef PacketTypeMixin<WLANPacket_CtrlFrameType> mixin;
174 typedef ConcretePacket<WLANPacket_CtrlFrameType> packet;
175 typedef WLANPacket_CtrlFrameParser parser;
178 using mixin::initSize;
179 using PacketTypeBase::nextPacketRange;
181 static void dump(packet p, std::ostream &os);
184 /** \brief WLAN Control frame packet typedef
185 \ingroup protocolbundle_80211
187 typedef WLANPacket_CtrlFrameType::packet WLANPacket_CtrlFrame;
189 ///////////////////////////////////////////////////////////////////////////
191 /** \brief Data frame parser
192 <b>Re-ordering of bits due to LSB byte order</b>
194 struct WLANPacket_DataFrameParser : public WLANPacketParser
196 # include SENF_PARSER()
198 SENF_PARSER_INHERIT(WLANPacketParser);
200 SENF_PARSER_GOTO(subtype);
201 SENF_PARSER_SKIP_BITS(14); //<pkgdraw: hide
202 SENF_PARSER_PRIVATE_BITFIELD ( dsBits, 2, unsigned ); //<pkgdraw: hide
203 SENF_PARSER_SKIP ( 2, 2 ); //<pkgdraw: hide
205 SENF_PARSER_PRIVATE_FIELD ( addr1, MACAddressParser );
206 SENF_PARSER_PRIVATE_FIELD ( addr2, MACAddressParser );
207 SENF_PARSER_PRIVATE_FIELD ( addr3, MACAddressParser );
209 //sequence Number and fragment number
210 //shift bits manually due to LSB
211 SENF_PARSER_PRIVATE_BITFIELD ( seqNumber_1, 4, unsigned );
212 SENF_PARSER_BITFIELD ( fragmentNumber, 4, unsigned );
213 SENF_PARSER_PRIVATE_FIELD ( seqNumber_2, UInt8Parser );
215 boost::uint16_t sequenceNumber() const {
216 return (uint16_t)(seqNumber_2()) << 4 | seqNumber_1();
219 void sequenceNumber(boost::uint16_t sn);
221 // TODO fourth address field in case of WDS
222 // SENF_PARSER_PRIVATE_VARIANT (wds_, dsBits,
223 // ( novalue ( disable_addr4, VoidPacketParser ))
224 // ( id ( addr4, key (3, MACAddressParser ))) );
227 SENF_PARSER_VARIANT ( qosField_, subtype,
228 ( ids( na, na, set_data, key(0, VoidPacketParser)) )
229 ( ids( na, na, set_nullData, key(4, VoidPacketParser)) )
230 ( ids( qosField, has_qosField, set_qosData, key(8, UInt16LSBParser )) )
231 //we cannot parse qos Null (data) frames at the moment
232 ( ids( na, na, set_qosNullData, key(12, UInt16LSBParser)) ) );
234 SENF_PARSER_INIT() { type_() = 2; }
236 SENF_PARSER_FINALIZE(WLANPacket_DataFrameParser);
238 MACAddressParser receiverAddress() const { return addr1(); }; //ra is always addr1
239 MACAddressParser transmitterAddress() const { return addr2(); }; //ta is always addr2
240 MACAddressParser sourceAddress() const;
241 MACAddressParser destinationAddress() const;
242 MACAddressParser bssid() const;
244 friend class WLANPacket_DataFrameType;
247 /** \brief WLAN Data frame packet
249 \par Packet type (typedef):
250 \ref WLANPacket_DataFrame
253 \ref WLANPacket_DataFrameParser
254 \image html WLANPacket_DataFrame.png
256 \ingroup protocolbundle_80211
258 struct WLANPacket_DataFrameType
259 : public PacketTypeBase,
260 public PacketTypeMixin<WLANPacket_DataFrameType>
262 typedef PacketTypeMixin<WLANPacket_DataFrameType> mixin;
263 typedef ConcretePacket<WLANPacket_DataFrameType> packet;
264 typedef WLANPacket_DataFrameParser parser;
267 using mixin::initSize;
268 using mixin::nextPacketRange;
270 static factory_t nextPacketType(packet p) {
271 return p->subtype() == 0 || p->subtype() == 8
272 ? LlcSnapPacket::factory()
276 static void dump(packet p, std::ostream &os);
279 /** \brief WLAN Data frame packet typedef
280 \ingroup protocolbundle_80211
282 typedef WLANPacket_DataFrameType::packet WLANPacket_DataFrame;
285 ///////////////////////////////hh.e////////////////////////////////////////
286 //#include "WLANPacket.cci"
287 //#include "WLANPacket.ct"
288 //#include "WLANPacket.cti"
295 // c-file-style: "senf"
296 // indent-tabs-mode: nil
297 // ispell-local-dictionary: "american"
298 // compile-command: "scons -u test"
299 // comment-column: 40