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>
37 prefix_ std::string senf::MIHFId_TLVParser::asString()
40 return std::string( i(1+length_bytes()), i(1+length_bytes()+length()) );
43 prefix_ void senf::MIHFId_TLVParser::setString(std::string const &id)
45 size_type str_size (id.size());
46 // the maximum length of a MIHF_ID is 253 octets (see F.3.11 in 802.21)
48 throw std::length_error("maximum length of a MIHF_ID is 253 octets");
49 safe_data_iterator si = resizeValue( str_size);
50 std::copy( id.begin(), id.end(), si);
53 prefix_ senf::MACAddress senf::MIHFId_TLVParser::asMACAddress()
56 return MACAddress::from_data(
57 getNAIDecodedIterator( i(1+length_bytes()), i(1+length_bytes()+12) ));
60 prefix_ void senf::MIHFId_TLVParser::setMACAddress(senf::MACAddress const &mac)
62 safe_data_iterator si = resizeValue(12);
63 std::copy( mac.begin(), mac.end(), getNAIEncodedOutputIterator(si));
67 prefix_ senf::INet4Address senf::MIHFId_TLVParser::asINet4Address()
70 return INet4Address::from_data(
71 getNAIDecodedIterator( i(1+length_bytes()), i(1+length_bytes()+8) ));
74 prefix_ void senf::MIHFId_TLVParser::setINet4Address(senf::INet4Address const &addr)
76 safe_data_iterator si = resizeValue(8);
77 std::copy( addr.begin(), addr.end(), getNAIEncodedOutputIterator(si));
80 prefix_ senf::INet6Address senf::MIHFId_TLVParser::asINet6Address()
83 return INet6Address::from_data(
84 getNAIDecodedIterator( i(1+length_bytes()), i(1+length_bytes()+32) ));
87 prefix_ void senf::MIHFId_TLVParser::setINet6Address(senf::INet6Address const &addr)
89 safe_data_iterator si = resizeValue(32);
90 std::copy( addr.begin(), addr.end(), getNAIEncodedOutputIterator(si));
93 prefix_ void senf::MIHPacketType::dump(packet p, std::ostream &os)
95 boost::io::ios_all_saver ias(os);
97 << " protocol header:\n"
98 << " Version: " << unsigned( p->version()) << "\n"
99 << " Ack-Request: " << p->ackRequest() << "\n"
100 << " Ack-Response: " << p->ackResponse() << "\n"
101 << " UIR: " << p->uir() << "\n"
102 << " more fragment: " << p->moreFragment() << "\n"
103 << " fragment number: " << p->fragmentNr() << "\n"
104 << " message ID (MID): " << unsigned( p->messageId()) << "\n"
105 << " SID: " << unsigned( p->sid()) << "\n"
106 << " Opcode: " << unsigned( p->opcode()) << "\n"
107 << " AID: " << unsigned( p->aid()) << "\n"
108 << " Transaction ID: " << unsigned( p->transactionId()) << "\n"
109 << " payload length: " << unsigned( p->payloadLength()) << "\n"
110 << " source MIHF_Id TLV:\n"
111 << " type: " << unsigned (p->src_mihfId().type()) << "\n"
112 << " length: " << unsigned (p->src_mihfId().length()) << "\n"
114 std::string src_mihfId (p->src_mihfId().asString());
115 hexdump(src_mihfId.begin(), src_mihfId.end(), os);
116 os << " destination MIHF_Id TLV:\n"
117 << " type: " << unsigned (p->dst_mihfId().type()) << "\n"
118 << " length: " << unsigned (p->dst_mihfId().length()) << "\n"
120 std::string dst_mihfId (p->dst_mihfId().asString());
121 hexdump(dst_mihfId.begin(), dst_mihfId.end(), os);
124 prefix_ void senf::MIHPacketType::finalize(packet p)
126 p->src_mihfId().shrinkLength();
127 p->dst_mihfId().shrinkLength();
128 p->payloadLength_() << p.size() - 8;
129 p->messageId() << key(p.next(nothrow));
132 prefix_ senf::PacketInterpreterBase::factory_t senf::MIHPacketType::nextPacketType(packet p)
134 if (p.data().size() < initSize())
136 PkReg_Entry const * e (PacketRegistry<MIHMessageRegistry>::lookup( p->messageId(), nothrow ));
137 return e ? e->factory() : MIHPayloadPacket::factory();
140 prefix_ void senf::MIHPayloadPacketType::dump(packet p, std::ostream &os)
142 boost::io::ios_all_saver ias(os);
143 os << "MIH Payload (service specific TLVs):\n"
153 // c-file-style: "senf"
154 // indent-tabs-mode: nil
155 // ispell-local-dictionary: "american"
156 // compile-command: "scons -u test"
157 // comment-column: 40