Packets/80221Bundle: more GenericTLVBase integration; removed GenericTLVPacket; some...
[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, MIHFId_TLVParser );
82         // Destination MIHF Id
83         SENF_PARSER_FIELD ( dst_mihfId, MIHFId_TLVParser );
84
85         SENF_PARSER_FINALIZE ( MIHPacketParser );
86
87         SENF_PARSER_INIT() {
88             version_() = 1;
89             src_mihfId().type() = 1;
90             dst_mihfId().type() = 2;
91         }
92
93         friend class MIHPacketType;
94     };
95
96     /** \brief MIH packet
97
98         \par Packet type (typedef):
99             \ref MIHPacket
100
101         \par Fields:
102             \ref MIHPacketParser
103
104         \ingroup protocolbundle_80221
105      */
106     struct MIHPacketType
107         : public PacketTypeBase,
108           public PacketTypeMixin<MIHPacketType, MIHMessageRegistry>
109     {
110 #ifndef DOXYGEN
111         typedef PacketTypeMixin<MIHPacketType, MIHMessageRegistry> mixin;
112 #endif
113         typedef ConcretePacket<MIHPacketType> packet; ///< MIH packet typedef
114         typedef MIHPacketParser parser;               ///< typedef to the parser of MIH packet
115
116         using mixin::nextPacketRange;
117         using mixin::init;
118         using mixin::initSize;
119
120         /** \brief Dump given MIH packet in readable form to given output stream */
121         static void dump(packet p, std::ostream &os);
122         static void finalize(packet p);
123         static factory_t nextPacketType(packet p);
124     };
125
126     /** \brief MIH packet typedef
127         \ingroup protocolbundle_80221
128      */
129     typedef ConcretePacket<MIHPacketType> MIHPacket;
130
131
132     struct MIHGenericPayloadPacketParser : public PacketParserBase
133     {
134     #   include SENF_PARSER()
135         SENF_PARSER_LIST ( tlv_list, packetSize(), MIHGenericTLVParser );
136         SENF_PARSER_FINALIZE ( MIHGenericPayloadPacketParser );
137     };
138
139     struct MIHGenericPayloadPacketType
140         : public PacketTypeBase,
141           public PacketTypeMixin<MIHGenericPayloadPacketType>
142     {
143 #ifndef DOXYGEN
144         typedef PacketTypeMixin<MIHGenericPayloadPacketType> mixin;
145 #endif
146         typedef ConcretePacket<MIHGenericPayloadPacketType> packet; ///< MIH Payload packet typedef
147         typedef MIHGenericPayloadPacketParser parser; ///< typedef to the parser of MIH Payload packet
148
149         using mixin::nextPacketRange;
150         using mixin::init;
151         using mixin::initSize;
152
153         /** \brief Dump given MIHGenericPayload in readable form to given output stream */
154         static void dump(packet p, std::ostream &os);
155         static void finalize(packet p);
156     };
157
158      /** \brief MIH Payload packet typedef
159          \ingroup protocolbundle_80221
160       */
161     typedef ConcretePacket<MIHGenericPayloadPacketType> MIHGenericPayloadPacket;
162 }
163
164
165 ///////////////////////////////hh.e////////////////////////////////////////
166 //#include "MIHPacket.cci"
167 //#include "MIHPacket.ct"
168 //#include "MIHPacket.cti"
169 #endif
170
171
172 \f
173 // Local Variables:
174 // mode: c++
175 // fill-column: 100
176 // c-file-style: "senf"
177 // indent-tabs-mode: nil
178 // ispell-local-dictionary: "american"
179 // compile-command: "scons -u test"
180 // comment-column: 40
181 // End: