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 <senf/Packets/Packets.hh>
31 #include <senf/Utils/hexdump.hh>
32 #include <boost/io/ios_state.hpp>
33 #include <senf/Packets/DefaultBundle/EthernetPacket.hh>
36 ///////////////////////////////cc.p////////////////////////////////////////
39 SENF_PACKET_REGISTRY_REGISTER( senf::EtherTypes, 0x8917, senf::MIHPacket);
42 ///////////////////////////////////////////////////////////////////////////
45 prefix_ void senf::MIHFId_TLVParser::setString(std::string const &id)
47 size_type str_size (id.size());
48 // the maximum length of a MIHF_ID is 253 octets (see F.3.11 in 802.21)
50 throw std::length_error("maximum length of a MIHF_ID is 253 octets");
51 safe_data_iterator si = resizeValueField( str_size);
52 std::copy( id.begin(), id.end(), si);
55 prefix_ void senf::MIHFId_TLVParser::setMACAddress(senf::MACAddress const &mac)
57 safe_data_iterator si = resizeValueField(12);
58 std::copy( mac.begin(), mac.end(), getNAIEncodedOutputIterator(si));
61 prefix_ void senf::MIHFId_TLVParser::setINet4Address(senf::INet4Address const &addr)
63 safe_data_iterator si = resizeValueField(8);
64 std::copy( addr.begin(), addr.end(), getNAIEncodedOutputIterator(si));
67 prefix_ void senf::MIHFId_TLVParser::setINet6Address(senf::INet6Address const &addr)
69 safe_data_iterator si = resizeValueField(32);
70 std::copy( addr.begin(), addr.end(), getNAIEncodedOutputIterator(si));
73 prefix_ void senf::MIHFId_TLVParser::setEUI64(senf::EUI64 const &addr)
75 safe_data_iterator si = resizeValueField(16);
76 std::copy( addr.begin(), addr.end(), getNAIEncodedOutputIterator(si));
79 prefix_ senf::MIHFId senf::MIHFId_TLVParser::valueAs(MIHFId::Type type)
82 if (length() == 0) return MIHFId();
86 case MIHFId::MACAddress:
87 return MIHFId( asMACAddress());
88 case MIHFId::INet4Address:
89 return MIHFId( asINet4Address());
90 case MIHFId::INet6Address:
91 return MIHFId( asINet6Address());
93 return MIHFId( asINet6Address());
95 return MIHFId( asINet6Address());
101 ///////////////////////////////////////////////////////////////////////////
104 prefix_ void senf::MIHPacketType::dump(packet p, std::ostream &os)
106 boost::io::ios_all_saver ias(os);
107 os << "MIH Packet:\n"
108 << " protocol header:\n"
109 << senf::fieldName(" version") << unsigned( p->version()) << "\n"
110 << senf::fieldName(" ack request") << p->ackRequest() << "\n"
111 << senf::fieldName(" ack response") << p->ackResponse() << "\n"
112 << senf::fieldName(" UIR") << p->uir() << "\n"
113 << senf::fieldName(" more fragments") << p->moreFragment() << "\n"
114 << senf::fieldName(" fragment number") << p->fragmentNr() << "\n"
115 << senf::fieldName(" message ID (MID)") << unsigned( p->messageId()) << "\n"
116 << senf::fieldName(" sid") << unsigned( p->sid()) << "\n"
117 << senf::fieldName(" opcode") << unsigned( p->opcode()) << "\n"
118 << senf::fieldName(" aid") << unsigned( p->aid()) << "\n"
119 << senf::fieldName(" transaction id") << unsigned( p->transactionId()) << "\n"
120 << senf::fieldName(" payload length") << unsigned( p->payloadLength()) << "\n"
121 << " source MIHF_Id TLV:\n"
122 << senf::fieldName(" type") << unsigned (p->src_mihfId().type()) << "\n"
123 << senf::fieldName(" length") << unsigned (p->src_mihfId().length()) << "\n"
125 std::string src_mihfId (p->src_mihfId().asString());
126 hexdump(src_mihfId.begin(), src_mihfId.end(), os);
127 os << " destination MIHF_Id TLV:\n"
128 << senf::fieldName(" type") << unsigned (p->dst_mihfId().type()) << "\n"
129 << senf::fieldName(" length") << unsigned (p->dst_mihfId().length()) << "\n"
131 std::string dst_mihfId (p->dst_mihfId().asString());
132 hexdump(dst_mihfId.begin(), dst_mihfId.end(), os);
135 prefix_ void senf::MIHPacketType::finalize(packet p)
137 p->src_mihfId().finalizeLength();
138 p->dst_mihfId().finalizeLength();
139 p->payloadLength_() << p.size() - 8;
140 p->messageId() << key(p.next(nothrow));
143 prefix_ senf::PacketInterpreterBase::factory_t senf::MIHPacketType::nextPacketType(packet p)
145 if (p.data().size() < initSize())
147 PkReg_Entry const * e (PacketRegistry<MIHMessageRegistry>::lookup( p->messageId(), nothrow ));
148 return e ? e->factory() : MIHPayloadPacket::factory();
151 prefix_ void senf::MIHPayloadPacketType::dump(packet p, std::ostream &os)
153 boost::io::ios_all_saver ias(os);
154 os << "MIH Payload (service specific TLVs):\n"
158 ///////////////////////////////cc.e////////////////////////////////////////
165 // c-file-style: "senf"
166 // indent-tabs-mode: nil
167 // ispell-local-dictionary: "american"
168 // compile-command: "scons -u test"
169 // comment-column: 40