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 // the maximum length of a MIHF_ID is 253 octets (see F.3.11 in 802.21)
45 // we could set maxLengthValue in INIT, but for the most MIHF_IDs the default
46 // maximum length of 127 should be enough.
47 // The user must call mihPacket->src_mihfId().maxLengthValue( 127) before
48 // setting longer MIHF_IDs
49 class MIHFId_TLVParser : public BaseTLVPacketParser
51 # include SENF_PARSER()
52 SENF_PARSER_INHERIT ( BaseTLVPacketParser );
53 SENF_PARSER_SKIP ( length(), 0 );
54 SENF_PARSER_FINALIZE ( MIHFId_TLVParser );
56 std::string asString() const;
57 void setString(std::string const &id);
59 senf::MACAddress asMACAddress() const;
60 void setMACAddress(senf::MACAddress const &mac);
62 senf::INet4Address asINet4Address() const;
63 void setINet4Address(senf::INet4Address const &addr);
65 senf::INet6Address asINet6Address() const;
66 void setINet6Address(senf::INet6Address const &addr);
69 template <class OutputIterator>
70 struct binaryNAIEncoder {
71 binaryNAIEncoder(OutputIterator &i) : i_(i) {}
72 void operator()(const boost::uint8_t &v) const {
78 template <class OutputIterator>
79 static boost::function_output_iterator<binaryNAIEncoder<OutputIterator> > getNAIEncodedOutputIterator(OutputIterator i) {
80 return boost::make_function_output_iterator(binaryNAIEncoder<OutputIterator>(i));
83 struct binaryNAIDecoder {
84 binaryNAIDecoder() : readNextByte_(true) {}
85 bool operator()(const boost::uint8_t &v) {
86 readNextByte_ = readNextByte_ ? false : true;
91 template <class Iterator>
92 static boost::filter_iterator<binaryNAIDecoder, Iterator> getNAIDecodedIterator(Iterator begin, Iterator end) {
93 return boost::make_filter_iterator<binaryNAIDecoder>(begin, end);
97 struct MIHPacketParser : public PacketParserBase
99 # include SENF_PARSER()
101 SENF_PARSER_BITFIELD_RO ( version, 4, unsigned );
102 SENF_PARSER_BITFIELD ( ackRequest, 1, bool );
103 SENF_PARSER_BITFIELD ( ackResponse, 1, bool );
104 SENF_PARSER_BITFIELD ( uir, 1, bool );
105 SENF_PARSER_BITFIELD ( moreFragment, 1, bool );
106 SENF_PARSER_BITFIELD ( fragmentNr, 7, unsigned );
107 SENF_PARSER_SKIP_BITS ( 1 );
109 // MIH message ID (MID)
110 SENF_PARSER_BITFIELD ( sid, 4, unsigned );
111 SENF_PARSER_BITFIELD ( opcode, 2, unsigned );
112 SENF_PARSER_BITFIELD ( aid, 10, unsigned );
114 SENF_PARSER_SKIP_BITS ( 4 );
115 SENF_PARSER_BITFIELD ( transactionId, 12, unsigned );
116 SENF_PARSER_FIELD_RO ( payloadLength, UInt16Parser );
119 SENF_PARSER_FIELD ( src_mihfId, MIHFId_TLVParser );
120 // Destination MIHF Id
121 SENF_PARSER_FIELD ( dst_mihfId, MIHFId_TLVParser );
123 SENF_PARSER_FINALIZE ( MIHPacketParser );
127 src_mihfId().type() = 1;
128 dst_mihfId().type() = 2;
131 friend class MIHPacketType;
134 /** \brief MIH packet
136 \par Packet type (typedef):
141 \image html MIHPacket.png
143 \ingroup protocolbundle_80221
146 : public PacketTypeBase,
147 public PacketTypeMixin<MIHPacketType>
149 typedef PacketTypeMixin<MIHPacketType> mixin;
150 typedef ConcretePacket<MIHPacketType> packet;
151 typedef MIHPacketParser parser;
153 using mixin::nextPacketRange;
155 using mixin::initSize;
157 static void dump(packet p, std::ostream &os);
158 static void finalize(packet p);
159 static factory_t nextPacketType(packet p);
162 typedef ConcretePacket<MIHPacketType> MIHPacket;
165 struct MIHPayloadPacketParser : public PacketParserBase
167 # include SENF_PARSER()
168 SENF_PARSER_LIST ( tlv_list, packetSize(), GenericTLVPacketParser );
170 SENF_PARSER_FINALIZE ( MIHPayloadPacketParser );
173 struct MIHPayloadPacketType
174 : public PacketTypeBase,
175 public PacketTypeMixin<MIHPayloadPacketType>
177 typedef PacketTypeMixin<MIHPayloadPacketType> mixin;
178 typedef ConcretePacket<MIHPayloadPacketType> packet;
179 typedef MIHPayloadPacketParser parser;
181 using mixin::nextPacketRange;
183 using mixin::initSize;
185 static void dump(packet p, std::ostream &os);
188 typedef ConcretePacket<MIHPayloadPacketType> MIHPayloadPacket;
194 ///////////////////////////////hh.e////////////////////////////////////////
196 #ifndef SENF_PACKETS_DECL_ONLY
197 //#include "MIHPacket.cci"
198 //#include "MIHPacket.ct"
199 //#include "MIHPacket.cti"
206 // c-file-style: "senf"
207 // indent-tabs-mode: nil
208 // ispell-local-dictionary: "american"
209 // compile-command: "scons -u test"
210 // comment-column: 40