4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at
9 // http://senf.berlios.de/license.html
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on,
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
15 // Software distributed under the License is distributed on an "AS IS" basis,
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
17 // for the specific language governing rights and limitations under the License.
19 // The Original Code is Fraunhofer FOKUS code.
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V.
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
26 // Thorsten Horstmann <tho@berlios.de>
29 \brief MIH protocol non-inline non-template implementation */
31 #include "MIHPacket.hh"
32 //#include "MIHPacket.ih"
35 #include <boost/io/ios_state.hpp>
36 #include <senf/Utils/String.hh>
37 #include <senf/Packets/DefaultBundle/EthernetPacket.hh>
40 //-/////////////////////////////////////////////////////////////////////////////////////////////////
42 SENF_PACKET_REGISTRY_REGISTER( senf::EtherTypes, senf::MIHPacketType::etherType, senf::MIHPacket);
45 //-/////////////////////////////////////////////////////////////////////////////////////////////////
48 prefix_ void senf::MIHPacketType::dump(packet p, std::ostream & os)
50 boost::io::ios_all_saver ias(os);
52 << " protocol header:\n"
53 << senf::fieldName(" version") << unsigned( p->version()) << "\n"
54 << senf::fieldName(" ack request") << p->ackRequest() << "\n"
55 << senf::fieldName(" ack response") << p->ackResponse() << "\n"
56 << senf::fieldName(" UIR") << p->uir() << "\n"
57 << senf::fieldName(" more fragments") << p->moreFragment() << "\n"
58 << senf::fieldName(" fragment number") << p->fragmentNr() << "\n"
59 << senf::fieldName(" message ID (MID)") << unsigned( p->messageId()) << "\n"
60 << senf::fieldName(" sid") << unsigned( p->sid()) << "\n"
61 << senf::fieldName(" opcode") << unsigned( p->opcode()) << "\n"
62 << senf::fieldName(" aid") << unsigned( p->aid()) << "\n"
63 << senf::fieldName(" transaction id") << unsigned( p->transactionId()) << "\n"
64 << senf::fieldName(" payload length") << unsigned( p->payloadLength()) << "\n";
65 p->src_mihfId().dump( os);
66 p->dst_mihfId().dump( os);
69 prefix_ void senf::MIHPacketType::finalize(packet p)
71 p->src_mihfId().finalize();
72 p->dst_mihfId().finalize();
73 p->payloadLength_() << p.size() - 8;
74 p->messageId() << key(p.next(nothrow));
77 prefix_ senf::PacketInterpreterBase::factory_t senf::MIHPacketType::nextPacketType(packet p)
79 if (p.data().size() < initSize())
81 PacketRegistry<MIHMessageRegistry>::Entry const * e (
82 PacketRegistry<MIHMessageRegistry>::lookup( p->messageId(), nothrow ));
83 return e ? e->factory() : MIHGenericPayloadPacket::factory();
86 prefix_ void senf::MIHPacketType::validate(packet p)
89 if (p.data().size() < initSize())
90 throw InvalidMIHPacketException("truncated MIH message");
91 if (p->version() != 1)
92 throw InvalidMIHPacketException("invalid MIH version: ") << senf::str(p->version());
93 if (p->payloadLength() != p.size()-8)
94 throw InvalidMIHPacketException("wrong MIH length: ") << senf::str(p->payloadLength());
95 if (p.next(senf::nothrow))
96 MIHMessageRegistry::instance().validate( p->messageId(), p.next());
97 } catch (TruncatedPacketException & e) {
98 throw InvalidMIHPacketException("truncated MIH message");
102 //-/////////////////////////////////////////////////////////////////////////////////////////////////
103 // MIHGenericPayloadPacketType
105 prefix_ void senf::MIHGenericPayloadPacketType::dump(packet p, std::ostream & os)
107 boost::io::ios_all_saver ias(os);
108 os << "MIH Payload (service specific TLVs):\n";
109 typedef parser::tlvList_t::container tlvListContainer_t;
110 tlvListContainer_t tlvListContainer (p->tlvList());
111 for (tlvListContainer_t::const_iterator i = tlvListContainer.begin(); i != tlvListContainer.end(); ++i)
115 prefix_ void senf::MIHGenericPayloadPacketType::finalize(packet p)
117 typedef parser::tlvList_t::container tlvContainer_t;
118 tlvContainer_t tlvs (p->tlvList() );
119 for (tlvContainer_t::iterator i (tlvs.begin()); i != tlvs.end(); ++i) {
120 MIHGenericTLVParser p (*i);
126 //-/////////////////////////////////////////////////////////////////////////////////////////////////
133 // c-file-style: "senf"
134 // indent-tabs-mode: nil
135 // ispell-local-dictionary: "american"
136 // compile-command: "scons -u test"
137 // comment-column: 40