From: tho Date: Fri, 9 Oct 2009 09:21:58 +0000 (+0000) Subject: Packets/StringParser: added template arg for length field X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=a3f9296f648c4991a1576d4200abfdc72788bc16;hp=d1284f9a03b4e3a8624842ecd39304403f53a960;p=senf.git Packets/StringParser: added template arg for length field git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1484 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/senf/Packets/80211Bundle/InformationElements.hh b/senf/Packets/80211Bundle/InformationElements.hh new file mode 100644 index 0000000..0b550f4 --- /dev/null +++ b/senf/Packets/80211Bundle/InformationElements.hh @@ -0,0 +1,65 @@ +// $Id$ +// +// Copyright (C) 2009 +// Fraunhofer Institute for Open Communication Systems (FOKUS) +// Competence Center NETwork research (NET), St. Augustin, GERMANY +// Thorsten Horstmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the +// Free Software Foundation, Inc., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +/** \file + \brief WLAN Information Elements public header */ + +#ifndef HH_SENF_Packets_80211Bundle_InformationElements_ +#define HH_SENF_Packets_80211Bundle_InformationElements_ 1 + +// Custom includes +#include + +//#include "InformationElements.mpp" +///////////////////////////////hh.p//////////////////////////////////////// + +namespace senf { + + class WLANInfoElementParser : public PacketParserBase + { + public: +# include SENF_PARSER() + SENF_PARSER_FIELD ( type, UInt8Parser ); + SENF_PARSER_FIELD ( length, UInt8Parser ); + SENF_PARSER_FINALIZE ( WLANInfoElementParser ); + }; + + typedef GenericTLVParserBase WLANGenericInfoElementParser; + +} + +///////////////////////////////hh.e//////////////////////////////////////// +//#include "InformationElements.cci" +//#include "InformationElements.ct" +//#include "InformationElements.cti" +#endif + + +// Local Variables: +// mode: c++ +// fill-column: 100 +// comment-column: 40 +// c-file-style: "senf" +// indent-tabs-mode: nil +// ispell-local-dictionary: "american" +// compile-command: "scons -u test" +// End: diff --git a/senf/Packets/80211Bundle/WLANBeaconPacket.cc b/senf/Packets/80211Bundle/WLANBeaconPacket.cc index d91f059..327a838 100644 --- a/senf/Packets/80211Bundle/WLANBeaconPacket.cc +++ b/senf/Packets/80211Bundle/WLANBeaconPacket.cc @@ -1,9 +1,10 @@ -// $Id: WLANPacket.cc 1449 2009-09-25 23:03:48Z g0dil $ +// $Id$ // -// Copyright (C) 2008 +// Copyright (C) 2009 // Fraunhofer Institute for Open Communication Systems (FOKUS) // Competence Center NETwork research (NET), St. Augustin, GERMANY // Christian Niephaus +// Thorsten Horstmann // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -20,7 +21,7 @@ // Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// Definition of non-inline non-template functions +// Definition of 802.11 WLAN Beacon Packet non-inline non-template functions // Custom includes #include "WLANBeaconPacket.hh" @@ -29,9 +30,7 @@ #include #define prefix_ - -namespace { -} +///////////////////////////////cc.p//////////////////////////////////////// prefix_ void senf::WLANBeaconPacketType::dump(packet p, std::ostream &os) { @@ -40,6 +39,7 @@ prefix_ void senf::WLANBeaconPacketType::dump(packet p, std::ostream &os) << senf::fieldName("timestamp") << unsigned( p->timestamp()) << "\n"; } +///////////////////////////////cc.e//////////////////////////////////////// #undef prefix_ diff --git a/senf/Packets/80211Bundle/WLANBeaconPacket.hh b/senf/Packets/80211Bundle/WLANBeaconPacket.hh index 1e762e1..fcfe80d 100644 --- a/senf/Packets/80211Bundle/WLANBeaconPacket.hh +++ b/senf/Packets/80211Bundle/WLANBeaconPacket.hh @@ -1,9 +1,10 @@ // $Id$ // -// Copyright (C) 2008 +// Copyright (C) 2009 // Fraunhofer Institute for Open Communication Systems (FOKUS) // Competence Center NETwork research (NET), St. Augustin, GERMANY // Christian Niephaus +// Thorsten Horstmann // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -21,45 +22,30 @@ // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. /** \file - \brief 802.11 WLANPacket public header */ + \brief 802.11 WLAN Beacon Packet public header */ #ifndef HH_SENF_Packets_80211Bundle_WLANBeaconPacket_ #define HH_SENF_Packets_80211Bundle_WLANBeaconPacket_ 1 +// Custom includes #include +#include "InformationElements.hh" +///////////////////////////////hh.p//////////////////////////////////////// +namespace senf { -namespace senf -{ - - /** \brief 802.11 Beacon Frame parser - (see IEEE 802.11-2007 standard - Chapter 7.2.3.1 Frame formats) - Re-ordering of bits due to host byte order - - Frame base class. - */ - -// struct WLANBeaconPacketParser : public senf::PacketParserBase -// { -// #include SENF_PARSER(); -// SENF_PARSER_FIELD( elementId, UInt8Parser); -// SENF_PARSER_FIELD( length, UInt8Parser); -// -// } - - - struct WLANBeaconPacketParser : public senf::PacketParserBase + struct WLANBeaconPacketParser : public PacketParserBase { # include SENF_PARSER() - SENF_PARSER_FIELD(timestamp, UInt64LSBParser); - SENF_PARSER_FIELD(beaconInterval, UInt16LSBParser); + SENF_PARSER_FIELD( timestamp, UInt64LSBParser ); + SENF_PARSER_FIELD( beaconInterval, UInt16LSBParser ); SENF_PARSER_SKIP(2,2); //capability flags //SSID element // SENF_PARSER_FIELD() - SENF_PARSER_FINALIZE(WLANBeaconPacketParser); + SENF_PARSER_FINALIZE( WLANBeaconPacketParser ); }; @@ -70,8 +56,6 @@ namespace senf \refWLANBeaconPacket \par Fields: - \ref WLANBeaconPacket_MgtFrameParser - \image html WLANBeaconPacket.png \ingroup protocolbundle_80211 */ @@ -92,10 +76,13 @@ namespace senf typedef ConcretePacket WLANBeaconPacket; - } -#endif /* HH_SENF_Packets_80211Bundle_WLANBeaconPacket_ */ +///////////////////////////////hh.e//////////////////////////////////////// +//#include "WLANBeaconPacket.cci" +//#include "WLANBeaconPacket.ct" +//#include "WLANBeaconPacket.cti" +#endif // Local Variables: diff --git a/senf/Packets/80211Bundle/WLANBeaconPacket.test.cc b/senf/Packets/80211Bundle/WLANBeaconPacket.test.cc index f5585a6..a05ed9b 100644 --- a/senf/Packets/80211Bundle/WLANBeaconPacket.test.cc +++ b/senf/Packets/80211Bundle/WLANBeaconPacket.test.cc @@ -1,9 +1,10 @@ -// $Id: WLANPacket.test.cc 1317 2009-08-21 14:07:47Z g0dil $ +// $Id$ // -// Copyright (C) 2008 +// Copyright (C) 2009 // Fraunhofer Institute for Open Communication Systems (FOKUS) // Competence Center NETwork research (NET), St. Augustin, GERMANY // Christian Niephaus +// Thorsten Horstmann // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -21,17 +22,16 @@ // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. /** \file - \brief WLANPacket unit tests */ + \brief 802.11 WLAN Beacon Packet unit tests */ // Custom includes #include "WLANBeaconPacket.hh" -#include #include #include ///////////////////////////////cc.p//////////////////////////////////////// -/* test parser with a data frame */ + BOOST_AUTO_UNIT_TEST(WLANBeaconPacket_packet) { unsigned char data[] = { @@ -46,7 +46,7 @@ BOOST_AUTO_UNIT_TEST(WLANBeaconPacket_packet) 0x2c, 0x01, 0x11, 0x30, 0x01, 0x11, 0x34, 0x01, 0x17, 0x38, 0x01, 0x17, 0x3c, 0x01, 0x17, 0x40, 0x01, 0x17, 0x95, 0x01, 0x1e, 0x99, 0x01, 0x1e, 0x9d, 0x01, 0x1e, 0xa1, 0x01, 0x1e, 0xa5, 0x01, 0x1e, //Country information - 0x20, 0x01, 0x00, //power contraint + 0x20, 0x01, 0x00, //power constraint 0xdd, 0x18, 0x00, 0x50, 0xf2, 0x02, 0x01, 0x01, 0x88, 0x00, 0x02, 0xa3, 0x00, 0x00, 0x27, 0xa4, 0x00, 0x00, 0x42, 0x43, 0x5e, 0x00, 0x62, 0x32, 0x2f, 0x00, //vendor specific @@ -56,9 +56,11 @@ BOOST_AUTO_UNIT_TEST(WLANBeaconPacket_packet) BOOST_CHECK_EQUAL( p->timestamp(), 0x0000009C4CAA303AuLL); BOOST_CHECK_EQUAL( p->beaconInterval(), 100u); - } +///////////////////////////////cc.e//////////////////////////////////////// +#undef prefix_ + // Local Variables: // mode: c++ diff --git a/senf/Packets/80211Bundle/WLANPacket.hh b/senf/Packets/80211Bundle/WLANPacket.hh index b0539d6..794007b 100644 --- a/senf/Packets/80211Bundle/WLANPacket.hh +++ b/senf/Packets/80211Bundle/WLANPacket.hh @@ -41,7 +41,7 @@ namespace senf Frame base class. */ - struct WLANPacketParser : public senf::PacketParserBase + struct WLANPacketParser : public PacketParserBase { # include SENF_PARSER() @@ -107,16 +107,16 @@ namespace senf \ingroup protocolbundle_80211 */ struct WLANPacket_MgtFrameType - : public senf::PacketTypeBase, - public senf::PacketTypeMixin + : public PacketTypeBase, + public PacketTypeMixin { - typedef senf::PacketTypeMixin mixin; - typedef senf::ConcretePacket packet; + typedef PacketTypeMixin mixin; + typedef ConcretePacket packet; typedef WLANPacket_MgtFrameParser parser; using mixin::init; using mixin::initSize; - using senf::PacketTypeBase::nextPacketRange; + using PacketTypeBase::nextPacketRange; static void dump(packet p, std::ostream &os); }; @@ -162,16 +162,16 @@ namespace senf \ingroup protocolbundle_80211 */ struct WLANPacket_CtrlFrameType - : public senf::PacketTypeBase, - public senf::PacketTypeMixin + : public PacketTypeBase, + public PacketTypeMixin { - typedef senf::PacketTypeMixin mixin; - typedef senf::ConcretePacket packet; + typedef PacketTypeMixin mixin; + typedef ConcretePacket packet; typedef WLANPacket_CtrlFrameParser parser; using mixin::init; using mixin::initSize; - using senf::PacketTypeBase::nextPacketRange; + using PacketTypeBase::nextPacketRange; static void dump(packet p, std::ostream &os); }; @@ -246,11 +246,11 @@ namespace senf \ingroup protocolbundle_80211 */ struct WLANPacket_DataFrameType - : public senf::PacketTypeBase, - public senf::PacketTypeMixin + : public PacketTypeBase, + public PacketTypeMixin { - typedef senf::PacketTypeMixin mixin; - typedef senf::ConcretePacket packet; + typedef PacketTypeMixin mixin; + typedef ConcretePacket packet; typedef WLANPacket_DataFrameParser parser; using mixin::init; diff --git a/senf/Packets/DefaultBundle/EthernetPacket.hh b/senf/Packets/DefaultBundle/EthernetPacket.hh index bade575..8eed2ec 100644 --- a/senf/Packets/DefaultBundle/EthernetPacket.hh +++ b/senf/Packets/DefaultBundle/EthernetPacket.hh @@ -125,9 +125,12 @@ namespace senf { static void finalize(packet p); }; - /** \brief Ethernet packet typedef */ + /** \brief Ethernet packet typedef + \ingroup protocolbundle_default + */ typedef ConcretePacket EthernetPacket; + /** \brief Parse an ethernet VLAN tag Parser interpreting the ethernet VLAN tag. Fields are diff --git a/senf/Packets/DefaultBundle/IPv6Extensions.hh b/senf/Packets/DefaultBundle/IPv6Extensions.hh index b506914..226ab24 100644 --- a/senf/Packets/DefaultBundle/IPv6Extensions.hh +++ b/senf/Packets/DefaultBundle/IPv6Extensions.hh @@ -175,7 +175,7 @@ namespace senf { \ref IPv6RoutingPacket \par Fields: - \ref IPv6PRoutingPacketParser + \ref IPv6RoutingPacketParser \par Associated registries: \ref IpTypes diff --git a/senf/Packets/StringParser.cci b/senf/Packets/StringParser.cti similarity index 61% rename from senf/Packets/StringParser.cci rename to senf/Packets/StringParser.cti index 53966af..36b3075 100644 --- a/senf/Packets/StringParser.cci +++ b/senf/Packets/StringParser.cti @@ -21,7 +21,7 @@ // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. /** \file - \brief StringParser inline non-template implementation */ + \brief StringParser inline template implementation */ //#include "StringParser.ih" @@ -30,43 +30,50 @@ #define prefix_ inline ///////////////////////////////cci.p/////////////////////////////////////// -prefix_ senf::StringParser::StringParser(data_iterator i, state_type s) +template +prefix_ senf::StringParser::StringParser(data_iterator i, state_type s) : PacketParserBase(i, s, init_bytes) {} -prefix_ senf::StringParser::size_type senf::StringParser::bytes() +template +prefix_ typename senf::StringParser::size_type senf::StringParser::bytes() const { - return parse(0)+2; + return length().value() + senf::bytes(length()); } -prefix_ senf::StringParser::value_type senf::StringParser::value() +template +prefix_ typename senf::StringParser::value_type senf::StringParser::value() const { validate(bytes()); - return std::string(i()+2, i()+bytes()); + return std::string(i()+senf::bytes(length()), i()+bytes()); } -prefix_ void senf::StringParser::value(value_type v) +template +prefix_ void senf::StringParser::value(value_type v) { validate(bytes()); - resize(bytes(), v.size()+2); + resize(bytes(), v.size()+senf::bytes(length())); parse(0) = v.size(); - std::copy(v.begin(), v.end(), i()+2); + std::copy(v.begin(), v.end(), i()+senf::bytes(length())); } -prefix_ senf::StringParser::operator value_type() +template +prefix_ senf::StringParser::operator value_type() const { return value(); } -prefix_ senf::StringParser const & senf::StringParser::operator=(value_type other) +template +prefix_ typename senf::StringParser const & senf::StringParser::operator=(value_type other) { value(other); return *this; } -prefix_ std::ostream & senf::operator<<(std::ostream & os, StringParser const & value) +template +prefix_ std::ostream & senf::operator<<(std::ostream & os, StringParser const & value) { os << value.value(); return os; diff --git a/senf/Packets/StringParser.hh b/senf/Packets/StringParser.hh index bc0ffb2..dda7e2f 100644 --- a/senf/Packets/StringParser.hh +++ b/senf/Packets/StringParser.hh @@ -37,16 +37,20 @@ namespace senf { - struct StringParser + template + class StringParser : public PacketParserBase { - + public: StringParser(data_iterator i, state_type s); /////////////////////////////////////////////////////////////////////////// +# include SENF_PARSER() + SENF_PARSER_PRIVATE_FIELD ( length, LengthParser ); + typedef std::string value_type; - static const size_type init_bytes = 2; + static const size_type init_bytes = senf::init_bytes::value; size_type bytes() const; value_type value() const; @@ -55,7 +59,8 @@ namespace senf { StringParser const & operator=(value_type other); }; - std::ostream & operator<<(std::ostream & os, StringParser const & value); + template + std::ostream & operator<<(std::ostream & os, StringParser const & value); } @@ -63,9 +68,9 @@ namespace senf { #endif #if !defined(HH_SENF_Packets_Packets__decls_) && !defined(HH_SENF_Packets_StringParser_i_) #define HH_SENF_Packets_StringParser_i_ -#include "StringParser.cci" +//#include "StringParser.cci" //#include "StringParser.ct" -//#include "StringParser.cti" +#include "StringParser.cti" #endif diff --git a/senf/Packets/StringParser.test.cc b/senf/Packets/StringParser.test.cc index c9590fc..da9fcb4 100644 --- a/senf/Packets/StringParser.test.cc +++ b/senf/Packets/StringParser.test.cc @@ -38,6 +38,8 @@ namespace { struct VoidPacket : public senf::PacketTypeBase {}; + + typedef senf::StringParser MyStringParser; } BOOST_AUTO_UNIT_TEST(stringParser) @@ -46,13 +48,13 @@ BOOST_AUTO_UNIT_TEST(stringParser) senf::PacketInterpreterBase::ptr p (senf::PacketInterpreter::create(data)); BOOST_CHECK_EQUAL( p->data().size(), 6u ); - BOOST_CHECK_EQUAL( senf::StringParser(p->data().begin(), &p->data()).value(), "TEST" ); + BOOST_CHECK_EQUAL( MyStringParser(p->data().begin(), &p->data()).value(), "TEST" ); - senf::StringParser(p->data().begin(), &p->data()).value("Another Test"); + MyStringParser(p->data().begin(), &p->data()).value("Another Test"); BOOST_CHECK_EQUAL( p->data().size(), 14u ); BOOST_CHECK_EQUAL( p->data()[0], 0u ); BOOST_CHECK_EQUAL( p->data()[1], 12u ); - BOOST_CHECK_EQUAL( senf::StringParser(p->data().begin(), &p->data()).value(), "Another Test" ); + BOOST_CHECK_EQUAL( MyStringParser(p->data().begin(), &p->data()).value(), "Another Test" ); } ///////////////////////////////cc.e////////////////////////////////////////