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 non-inline non-template implementation */
26 #include "MIHPacket.hh"
27 //#include "MIHPacket.ih"
30 #include "../../Packets/Packets.hh"
31 #include "../../Utils/hexdump.hh"
32 #include <boost/io/ios_state.hpp>
35 ///////////////////////////////cc.p////////////////////////////////////////
39 ///////////////////////////////////////////////////////////////////////////
42 prefix_ void senf::MIHFId_TLVParser::setString(std::string const &id)
44 size_type str_size (id.size());
45 // the maximum length of a MIHF_ID is 253 octets (see F.3.11 in 802.21)
47 throw std::length_error("maximum length of a MIHF_ID is 253 octets");
48 safe_data_iterator si = resizeValueField( str_size);
49 std::copy( id.begin(), id.end(), si);
52 prefix_ void senf::MIHFId_TLVParser::setMACAddress(senf::MACAddress const &mac)
54 safe_data_iterator si = resizeValueField(12);
55 std::copy( mac.begin(), mac.end(), getNAIEncodedOutputIterator(si));
58 prefix_ void senf::MIHFId_TLVParser::setINet4Address(senf::INet4Address const &addr)
60 safe_data_iterator si = resizeValueField(8);
61 std::copy( addr.begin(), addr.end(), getNAIEncodedOutputIterator(si));
64 prefix_ void senf::MIHFId_TLVParser::setINet6Address(senf::INet6Address const &addr)
66 safe_data_iterator si = resizeValueField(32);
67 std::copy( addr.begin(), addr.end(), getNAIEncodedOutputIterator(si));
70 prefix_ void senf::MIHFId_TLVParser::setEUI64(senf::EUI64 const &addr)
72 safe_data_iterator si = resizeValueField(16);
73 std::copy( addr.begin(), addr.end(), getNAIEncodedOutputIterator(si));
76 prefix_ senf::MIHFId senf::MIHFId_TLVParser::valueAs(MIHFId::Type type)
79 if (length() == 0) return MIHFId();
83 case MIHFId::MACAddress:
84 return MIHFId( asMACAddress());
85 case MIHFId::INet4Address:
86 return MIHFId( asINet4Address());
87 case MIHFId::INet6Address:
88 return MIHFId( asINet6Address());
90 return MIHFId( asINet6Address());
92 return MIHFId( asINet6Address());
98 ///////////////////////////////////////////////////////////////////////////
101 prefix_ void senf::MIHPacketType::dump(packet p, std::ostream &os)
103 boost::io::ios_all_saver ias(os);
104 os << "MIH Packet:\n"
105 << " protocol header:\n"
106 << " version : " << unsigned( p->version()) << "\n"
107 << " ack request : " << p->ackRequest() << "\n"
108 << " ack response : " << p->ackResponse() << "\n"
109 << " UIR : " << p->uir() << "\n"
110 << " more fragments : " << p->moreFragment() << "\n"
111 << " fragment number : " << p->fragmentNr() << "\n"
112 << " message ID (MID) : " << unsigned( p->messageId()) << "\n"
113 << " sid : " << unsigned( p->sid()) << "\n"
114 << " opcode : " << unsigned( p->opcode()) << "\n"
115 << " aid : " << unsigned( p->aid()) << "\n"
116 << " transaction id : " << unsigned( p->transactionId()) << "\n"
117 << " payload length : " << unsigned( p->payloadLength()) << "\n"
118 << " source MIHF_Id TLV :\n"
119 << " type : " << unsigned (p->src_mihfId().type()) << "\n"
120 << " length : " << unsigned (p->src_mihfId().length()) << "\n"
122 std::string src_mihfId (p->src_mihfId().asString());
123 hexdump(src_mihfId.begin(), src_mihfId.end(), os);
124 os << " destination MIHF_Id TLV:\n"
125 << " type : " << unsigned (p->dst_mihfId().type()) << "\n"
126 << " length : " << unsigned (p->dst_mihfId().length()) << "\n"
128 std::string dst_mihfId (p->dst_mihfId().asString());
129 hexdump(dst_mihfId.begin(), dst_mihfId.end(), os);
132 prefix_ void senf::MIHPacketType::finalize(packet p)
134 p->src_mihfId().finalizeLength();
135 p->dst_mihfId().finalizeLength();
136 p->payloadLength_() << p.size() - 8;
137 p->messageId() << key(p.next(nothrow));
140 prefix_ senf::PacketInterpreterBase::factory_t senf::MIHPacketType::nextPacketType(packet p)
142 if (p.data().size() < initSize())
144 PkReg_Entry const * e (PacketRegistry<MIHMessageRegistry>::lookup( p->messageId(), nothrow ));
145 return e ? e->factory() : MIHPayloadPacket::factory();
148 prefix_ void senf::MIHPayloadPacketType::dump(packet p, std::ostream &os)
150 boost::io::ios_all_saver ias(os);
151 os << "MIH Payload (service specific TLVs):\n"
155 ///////////////////////////////cc.e////////////////////////////////////////
162 // c-file-style: "senf"
163 // indent-tabs-mode: nil
164 // ispell-local-dictionary: "american"
165 // compile-command: "scons -u test"
166 // comment-column: 40