80221Bundle: added static const etherType member to MIHPacketType
[senf.git] / senf / Packets / 80221Bundle / MIHPacket.hh
1 // $Id$
2 //
3 // Copyright (C) 2009
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Thorsten Horstmann <tho@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 MIH protocol public header */
25
26 #ifndef HH_SENF_Packets_80221Bundle_MIHPacket_
27 #define HH_SENF_Packets_80221Bundle_MIHPacket_ 1
28
29 // Custom includes
30 #include <senf/Packets/Packets.hh>
31 #include "TLVParser.hh"
32 #include "MIHMessageRegistry.hh"
33
34 //#include "MIHPacket.mpp"
35 //-/////////////////////////////////////////////////////////////////////////////////////////////////
36
37 namespace senf {
38
39     /** \brief Parse a MIH packet
40
41         Parser implementing the MIH header. The fields implemented are:
42         \image html MIHPacket.png
43
44         \see MIHPacketType
45      */
46     struct MIHPacketParser : public PacketParserBase
47     {
48     #   include SENF_PARSER()
49
50         SENF_PARSER_BITFIELD_RO ( version,       4,  unsigned );
51         SENF_PARSER_BITFIELD    ( ackRequest,    1,  bool     );
52         SENF_PARSER_BITFIELD    ( ackResponse,   1,  bool     );
53         SENF_PARSER_BITFIELD    ( uir,           1,  bool     );
54         SENF_PARSER_BITFIELD    ( moreFragment,  1,  bool     );
55         SENF_PARSER_BITFIELD    ( fragmentNr,    7,  unsigned );
56         SENF_PARSER_SKIP_BITS   ( 1                           );
57
58         // MIH message ID (MID)
59         SENF_PARSER_FIELD    ( messageId, UInt16Parser ); //<pkgdraw:hide
60         SENF_PARSER_GOTO     ( messageId               );
61         SENF_PARSER_BITFIELD ( sid,     4,  unsigned   );
62         SENF_PARSER_BITFIELD ( opcode,  2,  unsigned   );
63         SENF_PARSER_BITFIELD ( aid,    10,  unsigned   );
64
65         SENF_PARSER_SKIP_BITS ( 4                           );
66         SENF_PARSER_BITFIELD  ( transactionId, 12, unsigned );
67         SENF_PARSER_FIELD_RO  ( payloadLength, UInt16Parser );
68
69         SENF_PARSER_GOTO_OFFSET( 8, 8); // just to limit the offset calculation
70
71         // Source MIHF Id
72         SENF_PARSER_FIELD ( src_mihfId, MIHFSrcIdTLVParser );
73         // Destination MIHF Id
74         SENF_PARSER_FIELD ( dst_mihfId, MIHFDstIdTLVParser );
75
76         SENF_PARSER_FINALIZE ( MIHPacketParser );
77
78         SENF_PARSER_INIT() {
79             defaultInit();
80             version_() = 1;
81         }
82
83         friend class MIHPacketType;
84     };
85
86     /** \brief MIH packet
87
88         \par Packet type (typedef):
89             \ref MIHPacket
90
91         \par Fields:
92             \ref MIHPacketParser
93
94         \ingroup protocolbundle_80221
95      */
96     struct MIHPacketType
97         : public PacketTypeBase,
98           public PacketTypeMixin<MIHPacketType, MIHMessageRegistry>
99     {
100         typedef PacketTypeMixin<MIHPacketType, MIHMessageRegistry> mixin;
101         typedef ConcretePacket<MIHPacketType> packet; ///< MIH packet typedef
102         typedef MIHPacketParser parser;               ///< typedef to the parser of MIH packet
103
104         using mixin::nextPacketRange;
105         using mixin::init;
106         using mixin::initSize;
107
108         /** \brief Dump given MIH packet in readable form to given output stream */
109         static void dump(packet p, std::ostream & os);
110         static void finalize(packet p);
111         static factory_t nextPacketType(packet p);
112         static void validate(packet p);
113
114         static const boost::uint16_t etherType = 0x8917;
115     };
116
117     /** \brief MIH packet typedef
118         \ingroup protocolbundle_80221
119      */
120     typedef ConcretePacket<MIHPacketType> MIHPacket;
121
122
123     struct MIHGenericPayloadPacketParser : public PacketParserBase
124     {
125     #   include SENF_PARSER()
126         SENF_PARSER_LIST ( tlvList, packetSize(), MIHGenericTLVParser );
127         SENF_PARSER_FINALIZE ( MIHGenericPayloadPacketParser );
128     };
129
130     struct MIHGenericPayloadPacketType
131         : public PacketTypeBase,
132           public PacketTypeMixin<MIHGenericPayloadPacketType>
133     {
134         typedef PacketTypeMixin<MIHGenericPayloadPacketType> mixin;
135         typedef ConcretePacket<MIHGenericPayloadPacketType> packet; ///< MIH Payload packet typedef
136         typedef MIHGenericPayloadPacketParser parser; ///< typedef to the parser of MIH Payload packet
137
138         using mixin::nextPacketRange;
139         using mixin::init;
140         using mixin::initSize;
141
142         /** \brief Dump given MIHGenericPayload in readable form to given output stream */
143         static void dump(packet p, std::ostream & os);
144         static void finalize(packet p);
145     };
146
147      /** \brief MIH Payload packet typedef
148          \ingroup protocolbundle_80221
149       */
150     typedef ConcretePacket<MIHGenericPayloadPacketType> MIHGenericPayloadPacket;
151 }
152
153
154 //-/////////////////////////////////////////////////////////////////////////////////////////////////
155 //#include "MIHPacket.cci"
156 //#include "MIHPacket.ct"
157 //#include "MIHPacket.cti"
158 #endif
159
160
161 \f
162 // Local Variables:
163 // mode: c++
164 // fill-column: 100
165 // c-file-style: "senf"
166 // indent-tabs-mode: nil
167 // ispell-local-dictionary: "american"
168 // compile-command: "scons -u test"
169 // comment-column: 40
170 // End: