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