4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Thorsten Horstmann <tho@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 MIH protocol public header */
26 #ifndef HH_SENF_Packets_80221Bundle_MIHPacket_
27 #define HH_SENF_Packets_80221Bundle_MIHPacket_ 1
30 #include "../../Packets/Packets.hh"
31 #include "../../Socket/Protocols/Raw/MACAddress.hh"
32 #include "../../Socket/Protocols/INet/INet4Address.hh"
33 #include "../../Socket/Protocols/INet/INet6Address.hh"
34 #include "TLVPacket.hh"
35 #include <boost/function_output_iterator.hpp>
36 #include <boost/iterator/filter_iterator.hpp>
39 //#include "MIHPacket.mpp"
40 ///////////////////////////////hh.p////////////////////////////////////////
44 /** \brief Parse a MIHF_ID
46 the maximum length of a MIHF_ID is 253 octets (see F.3.11 in 802.21)
47 we could set maxLengthValue in init(), but for the most MIHF_IDs the default
48 maximum length of 127 should be enough.
50 \note you must call mihfIdPacket.maxLengthValue( 253) *before*
51 setting longer MIHF_IDs values.
53 class MIHFId_TLVParser : public BaseTLVPacketParser
55 # include SENF_PARSER()
56 SENF_PARSER_INHERIT ( BaseTLVPacketParser );
57 SENF_PARSER_SKIP ( length(), 0 );
58 SENF_PARSER_FINALIZE ( MIHFId_TLVParser );
60 std::string asString() const;
61 void setString(std::string const &id);
63 senf::MACAddress asMACAddress() const;
64 void setMACAddress(senf::MACAddress const &mac);
66 senf::INet4Address asINet4Address() const;
67 void setINet4Address(senf::INet4Address const &addr);
69 senf::INet6Address asINet6Address() const;
70 void setINet6Address(senf::INet6Address const &addr);
73 template <class OutputIterator>
74 struct binaryNAIEncoder {
75 binaryNAIEncoder(OutputIterator &i) : i_(i) {}
76 void operator()(const boost::uint8_t &v) const {
82 template <class OutputIterator>
83 static boost::function_output_iterator<binaryNAIEncoder<OutputIterator> > getNAIEncodedOutputIterator(OutputIterator i) {
84 return boost::make_function_output_iterator(binaryNAIEncoder<OutputIterator>(i));
87 struct binaryNAIDecoder {
88 binaryNAIDecoder() : readNextByte_(true) {}
89 bool operator()(const boost::uint8_t &v) {
90 readNextByte_ = readNextByte_ ? false : true;
95 template <class Iterator>
96 static boost::filter_iterator<binaryNAIDecoder, Iterator> getNAIDecodedIterator(Iterator begin, Iterator end) {
97 return boost::make_filter_iterator<binaryNAIDecoder>(begin, end);
101 /** \brief Parse a MIH packet
103 Parser implementing the MIH header. The fields implemented are:
104 \image html MIHPacket.png
108 struct MIHPacketParser : public PacketParserBase
110 # include SENF_PARSER()
112 SENF_PARSER_BITFIELD_RO ( version, 4, unsigned );
113 SENF_PARSER_BITFIELD ( ackRequest, 1, bool );
114 SENF_PARSER_BITFIELD ( ackResponse, 1, bool );
115 SENF_PARSER_BITFIELD ( uir, 1, bool );
116 SENF_PARSER_BITFIELD ( moreFragment, 1, bool );
117 SENF_PARSER_BITFIELD ( fragmentNr, 7, unsigned );
118 SENF_PARSER_SKIP_BITS ( 1 );
120 // MIH message ID (MID)
121 SENF_PARSER_BITFIELD ( sid, 4, unsigned );
122 SENF_PARSER_BITFIELD ( opcode, 2, unsigned );
123 SENF_PARSER_BITFIELD ( aid, 10, unsigned );
125 SENF_PARSER_SKIP_BITS ( 4 );
126 SENF_PARSER_BITFIELD ( transactionId, 12, unsigned );
127 SENF_PARSER_FIELD_RO ( payloadLength, UInt16Parser );
130 SENF_PARSER_FIELD ( src_mihfId, MIHFId_TLVParser );
131 // Destination MIHF Id
132 SENF_PARSER_FIELD ( dst_mihfId, MIHFId_TLVParser );
134 SENF_PARSER_FINALIZE ( MIHPacketParser );
138 src_mihfId().type() = 1;
139 dst_mihfId().type() = 2;
142 friend class MIHPacketType;
145 /** \brief MIH packet
147 \par Packet type (typedef):
153 \ingroup protocolbundle_80221
156 : public PacketTypeBase,
157 public PacketTypeMixin<MIHPacketType>
160 typedef PacketTypeMixin<MIHPacketType> mixin;
162 typedef ConcretePacket<MIHPacketType> packet; ///< MIH packet typedef
163 typedef MIHPacketParser parser; ///< typedef to the parser of MIH packet
165 using mixin::nextPacketRange;
167 using mixin::initSize;
169 /** \brief Dump given MIH packet in readable form to given output stream */
170 static void dump(packet p, std::ostream &os);
171 static void finalize(packet p);
172 static factory_t nextPacketType(packet p);
175 /** \brief MIH packet typedef */
176 typedef ConcretePacket<MIHPacketType> MIHPacket;
179 struct MIHPayloadPacketParser : public PacketParserBase
181 # include SENF_PARSER()
182 SENF_PARSER_LIST ( tlv_list, packetSize(), GenericTLVPacketParser );
184 SENF_PARSER_FINALIZE ( MIHPayloadPacketParser );
187 struct MIHPayloadPacketType
188 : public PacketTypeBase,
189 public PacketTypeMixin<MIHPayloadPacketType>
192 typedef PacketTypeMixin<MIHPayloadPacketType> mixin;
194 typedef ConcretePacket<MIHPayloadPacketType> packet; ///< MIH Payload packet typedef
195 typedef MIHPayloadPacketParser parser; ///< typedef to the parser of MIH Payload packet
197 using mixin::nextPacketRange;
199 using mixin::initSize;
201 /** \brief Dump given MIHPayload in readable form to given output stream */
202 static void dump(packet p, std::ostream &os);
205 /** \brief MIH Payload packet typedef */
206 typedef ConcretePacket<MIHPayloadPacketType> MIHPayloadPacket;
210 ///////////////////////////////hh.e////////////////////////////////////////
212 #ifndef SENF_PACKETS_DECL_ONLY
213 //#include "MIHPacket.cci"
214 //#include "MIHPacket.ct"
215 //#include "MIHPacket.cti"
222 // c-file-style: "senf"
223 // indent-tabs-mode: nil
224 // ispell-local-dictionary: "american"
225 // compile-command: "scons -u test"
226 // comment-column: 40