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);
54 prefix_ senf::MACAddress senf::MIHFId_TLVParser::asMACAddress()
57 return MACAddress::from_data(
58 getNAIDecodedIterator( i(1+length_bytes()), i(1+length_bytes()+12) ));
61 prefix_ void senf::MIHFId_TLVParser::setMACAddress(senf::MACAddress const &mac)
63 safe_data_iterator si = resizeValue(12);
64 std::copy( mac.begin(), mac.end(), getNAIEncodedOutputIterator(si));
68 prefix_ senf::INet4Address senf::MIHFId_TLVParser::asINet4Address()
71 return INet4Address::from_data(
72 getNAIDecodedIterator( i(1+length_bytes()), i(1+length_bytes()+8) ));
75 prefix_ void senf::MIHFId_TLVParser::setINet4Address(senf::INet4Address const &addr)
77 safe_data_iterator si = resizeValue(8);
78 std::copy( addr.begin(), addr.end(), getNAIEncodedOutputIterator(si));
81 prefix_ senf::INet6Address senf::MIHFId_TLVParser::asINet6Address()
84 return INet6Address::from_data(
85 getNAIDecodedIterator( i(1+length_bytes()), i(1+length_bytes()+32) ));
88 prefix_ void senf::MIHFId_TLVParser::setINet6Address(senf::INet6Address const &addr)
90 safe_data_iterator si = resizeValue(32);
91 std::copy( addr.begin(), addr.end(), getNAIEncodedOutputIterator(si));
95 prefix_ void senf::MIHPacketType::dump(packet p, std::ostream &os)
97 boost::io::ios_all_saver ias(os);
99 << " protocol header:\n"
100 << " Version: " << unsigned( p->version()) << "\n"
101 << " Ack-Request: " << p->ackRequest() << "\n"
102 << " Ack-Response: " << p->ackResponse() << "\n"
103 << " UIR: " << p->uir() << "\n"
104 << " more fragment: " << p->moreFragment() << "\n"
105 << " fragment number: " << p->fragmentNr() << "\n"
106 << " message ID (MID):\n"
107 << " SID: " << unsigned( p->sid()) << "\n"
108 << " Opcode: " << unsigned( p->opcode()) << "\n"
109 << " AID: " << unsigned( p->aid()) << "\n"
110 << " Transaction ID: " << unsigned( p->transactionId()) << "\n"
111 << " payload length: " << unsigned( p->payloadLength()) << "\n"
112 << " source MIHF_Id TLV:\n"
113 << " type: " << unsigned (p->src_mihfId().type()) << "\n"
114 << " length: " << unsigned (p->src_mihfId().length()) << "\n"
116 std::string src_mihfId (p->src_mihfId().asString());
117 hexdump(src_mihfId.begin(), src_mihfId.end(), os);
118 os << " destination MIHF_Id TLV:\n"
119 << " type: " << unsigned (p->dst_mihfId().type()) << "\n"
120 << " length: " << unsigned (p->dst_mihfId().length()) << "\n"
122 std::string dst_mihfId (p->dst_mihfId().asString());
123 hexdump(dst_mihfId.begin(), dst_mihfId.end(), os);
127 prefix_ void senf::MIHPacketType::finalize(packet p)
129 p->src_mihfId().shrinkLength();
130 p->dst_mihfId().shrinkLength();
131 p->payloadLength_() << p.size() - 8;
141 // c-file-style: "senf"
142 // indent-tabs-mode: nil
143 // ispell-local-dictionary: "american"
144 // compile-command: "scons -u test"
145 // comment-column: 40