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