}
prefix_ void senf::ppi::IPv4SourceForcingDgramWriter::operator()(Handle handle,
- Packet const & packet){
+ Packet const & packet)
+{
sendtoandfrom(
handle.fd(),
reinterpret_cast<void*> (&*packet.data().begin()),
}
prefix_ void senf::ppi::IPv6SourceForcingDgramWriter::operator()(Handle handle,
- Packet const & packet){
+ Packet const & packet){
sendtoandfrom(
handle.fd(),
reinterpret_cast<void*> (&*packet.data().begin()),
{
boost::io::ios_all_saver ias(os);
os << "Radiotap:\n"
- << " Version : " << unsigned( p->version()) << "\n"
- << " Length : " << unsigned( p->length()) << "\n";
+ << " version : " << unsigned( p->version()) << "\n"
+ << " length : " << unsigned( p->length()) << "\n";
if (p->has_tsft())
- os << " MAC timestamp : " << unsigned( p->tsft()) << "\n";
+ os << " MAC timestamp : " << unsigned( p->tsft()) << "\n";
// TODO: flags
if (p->has_rate())
- os << " Rate : " << unsigned( p->rate()) << "\n";
+ os << " rate : " << unsigned( p->rate()) << "\n";
// TODO: channelOptions
if (p->has_fhss())
- os << " FHSS : " << unsigned( p->fhss()) << "\n";
+ os << " FHSS : " << unsigned( p->fhss()) << "\n";
if (p->has_dbmAntennaSignal())
- os << " Antenna Signal (dBm): " << signed( p->dbmAntennaSignal()) << "\n";
+ os << " antenna signal (dBm) : " << signed( p->dbmAntennaSignal()) << "\n";
if (p->has_dbmAntennaNoise())
- os << " Antenna Noise (dBm) : " << signed( p->dbmAntennaNoise()) << "\n";
+ os << " antenna noise (dBm) : " << signed( p->dbmAntennaNoise()) << "\n";
if (p->has_lockQuality())
- os << " Lock Quality : " << unsigned( p->lockQuality()) << "\n";
+ os << " lock quality : " << unsigned( p->lockQuality()) << "\n";
if (p->has_txAttenuation())
- os << " txAttenuation : " << unsigned( p->txAttenuation()) << "\n";
+ os << " tx attenuation : " << unsigned( p->txAttenuation()) << "\n";
if (p->has_dbTxAttenuation())
- os << " dbTxAttenuation : " << unsigned( p->dbTxAttenuation()) << "\n";
+ os << " tx attenuation (dB) : " << unsigned( p->dbTxAttenuation()) << "\n";
if (p->has_dbmTxAttenuation())
- os << " dbmTxAttenuation : " << signed( p->dbmTxAttenuation()) << "\n";
+ os << " tx attenuation (dBm) : " << signed( p->dbmTxAttenuation()) << "\n";
if (p->has_antenna())
- os << " Antenna : " << unsigned( p->antenna()) << "\n";
+ os << " antenna : " << unsigned( p->antenna()) << "\n";
if (p->has_dbAntennaSignal())
- os << " Antenna Signal (dB) : " << unsigned( p->dbAntennaSignal()) << "\n";
+ os << " antenna signal (dB) : " << unsigned( p->dbAntennaSignal()) << "\n";
if (p->has_dbAntennaNoise())
- os << " Antenna Noise (dB) : " << unsigned( p->dbAntennaNoise()) << "\n";
- if (p->has_fcs())
- os << " FCS : " << unsigned( p->fcs()) << "\n";
+ os << " antenna noise (dB) : " << unsigned( p->dbAntennaNoise()) << "\n";
+ if (p->has_headerFcs())
+ os << " FCS : " << unsigned( p->fcs()) << "\n";
}
prefix_ void senf::RadiotapPacketType::finalize(packet p)
{
- p->length() << senf::bytes( p.parser());
+ p->length() << p->calculateSize();
}
prefix_ senf::PacketInterpreterBase::factory_t senf::RadiotapPacketType::nextPacketType(packet p)
{
- return WLANPacket::factory();
+ static factory_t frameTypeFactory[] = { WLANPacket_MgtFrame::factory(),
+ WLANPacket_CtrlFrame::factory(),
+ WLANPacket_DataFrame::factory(),
+ no_factory() };
+ return frameTypeFactory[p->frameType()];
}
+prefix_ senf::RadiotapPacketType::optional_range
+senf::RadiotapPacketType::nextPacketRange(packet p)
+{
+ size_type h (senf::bytes(p.parser()));
+ size_type t (p->flagsPresent() && p->flags().fcsAtEnd() ? 4 : 0);
+ return p.size() < h+t
+ ? no_range()
+ : optional_range( range(p.data().begin() + h, p.data().end() - t) );
+}
#undef prefix_
SENF_PARSER_BITFIELD ( shortGI, 1, bool );
SENF_PARSER_BITFIELD ( badFCS, 1, bool );
SENF_PARSER_BITFIELD ( padding, 1, bool );
- SENF_PARSER_BITFIELD ( fcsPresent, 1, bool );
+ SENF_PARSER_BITFIELD_RO ( fcsAtEnd, 1, bool ); // Cannot change this (change packet size)
SENF_PARSER_BITFIELD ( fragmentation, 1, bool );
SENF_PARSER_BITFIELD ( wep, 1, bool );
SENF_PARSER_BITFIELD ( shortPreamble, 1, bool );
SENF_PARSER_BITFIELD_RO ( flagsPresent, 1, bool );
SENF_PARSER_BITFIELD_RO ( tsftPresent, 1, bool );
SENF_PARSER_SKIP_BITS ( 1 ); //currently unused bits
- SENF_PARSER_BITFIELD_RO ( fcsPresent, 1, bool );
+ SENF_PARSER_BITFIELD_RO ( headerFcsPresent, 1, bool );
SENF_PARSER_BITFIELD_RO ( dbAntennaNoisePresent, 1, bool );
SENF_PARSER_BITFIELD_RO ( dbAntennaSignalPresent, 1, bool );
SENF_PARSER_BITFIELD_RO ( antennaPresent, 1, bool );
SENF_PARSER_BITFIELD ( extendedBitmaskPresent, 1, bool );
SENF_PARSER_SKIP_BITS ( 7 ); //currently unused bits
+ SENF_PARSER_LABEL( headerEnd_ );
+
/*
* Radiotap data
* parsing data according to present flags
OPTIONAL_FIELD ( antenna, UInt8Parser );
OPTIONAL_FIELD ( dbAntennaSignal, UInt8Parser );
OPTIONAL_FIELD ( dbAntennaNoise, UInt8Parser );
- SKIP_OPTIONAL_PADDING ( fcsPresent(), dbAntennaNoise, 4 );
- OPTIONAL_FIELD ( fcs, UInt32Parser );
+ SKIP_OPTIONAL_PADDING ( headerFcsPresent(), dbAntennaNoise, 4 );
+ OPTIONAL_FIELD ( headerFcs, UInt32Parser );
+
+ SENF_PARSER_LABEL( packetEnd_ );
+
+ size_type calculateSize() { return packetEnd__offset(); }
+
+ // Ouch ... changing the flags().fcsAtEnd() field needs to resize the packet ... !!!
+ // Need to think, if I can do this with a variant parser ...
+ SENF_PARSER_CUSTOM_FIELD( fcs, senf::UInt32Parser, 0, 0 ) {
+ return parse<senf::UInt32Parser>(data().end()-4);
+ }
SENF_PARSER_INIT() {
version() = 0;
}
+ // The headers length is to be taken from the 'length' value
+ SENF_PARSER_GOTO_OFFSET( length(), headerEnd__init_bytes );
+
SENF_PARSER_FINALIZE( RadiotapPacketParser );
+
+ SENF_PARSER_SKIP_BITS( 4 );
+ SENF_PARSER_BITFIELD_RO ( frameType, 2, unsigned );
+ SENF_PARSER_SKIP_BITS( 2 );
+
};
/** \brief Radiotap packet
typedef ConcretePacket<RadiotapPacketType> packet;
typedef RadiotapPacketParser parser;
- using mixin::nextPacketRange;
using mixin::init;
using mixin::initSize;
static void dump(packet p, std::ostream &os);
static void finalize(packet p);
static factory_t nextPacketType(packet p);
+ static optional_range nextPacketRange(packet p);
};
typedef ConcretePacket<RadiotapPacketType> RadiotapPacket;
}
#endif
+
+\f
+// 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:
0x00 ,0x00 ,0x1a ,0x00, 0x6f, 0x18, 0x00, 0x00,
0x02, 0xe6, 0x8a, 0xdf, 0x12, 0x00, 0x00, 0x00,
0x12, 0x0c, 0xc8, 0x14, 0x40, 0x01, 0xc3, 0xa0,
- 0x02, 0x23
+ 0x02, 0x23,
+ 0x00, 0x00, 0x00, 0x00,
};
senf::RadiotapPacket p (senf::RadiotapPacket::create(data));
BOOST_CHECK_EQUAL( p->flags().shortPreamble(), true);
BOOST_CHECK_EQUAL( p->flags().wep(), false);
BOOST_CHECK_EQUAL( p->flags().fragmentation(), false);
- BOOST_CHECK_EQUAL( p->flags().fcsPresent(), true);
+ BOOST_CHECK_EQUAL( p->flags().fcsAtEnd(), true);
BOOST_CHECK_EQUAL( p->flags().padding(), false);
BOOST_CHECK_EQUAL( p->flags().badFCS(), false);
BOOST_CHECK_EQUAL( p->flags().shortGI(), false);
unsigned char data[] = {
0x00 ,0x00 ,0x1a ,0x00, 0x6f, 0x18, 0x00, 0x00,
0x02, 0xe6, 0x8a, 0xdf, 0x12, 0x00, 0x00, 0x00,
- 0x12, 0x0c, 0xc8, 0x14, 0x40, 0x01, 0xc3, 0xa0,
+ 0x02, 0x0c, 0xc8, 0x14, 0x40, 0x01, 0xc3, 0xa0,
0x02, 0x23
};
SENF_CHECK_NO_THROW( p->flags().shortPreamble() = true);
SENF_CHECK_NO_THROW( p->flags().wep() = false);
SENF_CHECK_NO_THROW( p->flags().fragmentation() = false);
- SENF_CHECK_NO_THROW( p->flags().fcsPresent() = true);
+ // SENF_CHECK_NO_THROW( p->flags().fcsAtEnd() = true);
SENF_CHECK_NO_THROW( p->flags().padding() = false);
SENF_CHECK_NO_THROW( p->flags().badFCS() = false);
SENF_CHECK_NO_THROW( p->flags().shortGI() = false);
p.finalizeAll();
BOOST_CHECK_EQUAL( p->length(), 26u );
- BOOST_CHECK( equal( p.data().begin(), p.data().end(), data ));
+ BOOST_CHECK_EQUAL_COLLECTIONS( p.data().begin(), p.data().end(),
+ data, data+sizeof(data)/sizeof(data[0]) );
}
BOOST_AUTO_UNIT_TEST(RadiotapPacket_packet_ath9k)
{
/* radiotap packet from ath9k with atheros card*/
unsigned char data[] = {
- 0x00, 0x00, 0x20, 0x00, 0x6f, 0x48, 0x00, 0x00, 0x87, 0xbb, 0x91, 0x7c, 0x3b, 0x00, 0x00, 0x00,
- 0x00, 0x04, 0x85, 0x09, 0x80, 0x04, 0xb2, 0xa1, 0x00, 0x00, 0x00, 0x00, 0xd5, 0x1a, 0xf7, 0x94
+ 0x00, 0x00, 0x20, 0x00, 0x6f, 0x48, 0x00, 0x00,
+ 0x87, 0xbb, 0x91, 0x7c, 0x3b, 0x00, 0x00, 0x00,
+ 0x00, 0x04, 0x85, 0x09, 0x80, 0x04, 0xb2, 0xa1,
+ 0x00, 0x00, 0x00, 0x00, 0xd5, 0x1a, 0xf7, 0x94,
+ 0x00, 0x00, 0x00, 0x00,
};
senf::RadiotapPacket p (senf::RadiotapPacket::create(data));
BOOST_CHECK_EQUAL( p->dbmAntennaSignal(), -78);
BOOST_CHECK_EQUAL( p->dbmAntennaNoise(), -95);
- BOOST_CHECK_EQUAL( p->fcs(), 0xd51af794);
+ BOOST_CHECK_EQUAL( p->headerFcs(), 0xd51af794);
BOOST_CHECK_EQUAL( p->antenna(), 0u);
-
-
}
+
+\f
+// Local Variables:
+// mode: c++
+// fill-column: 100
+// c-file-style: "senf"
+// indent-tabs-mode: nil
+// ispell-local-dictionary: "american"
+// compile-command: "scons -u test"
+// comment-column: 40
+// End:
// Custom includes
#include "WLANPacket.hh"
#include "../../Packets/Packets.hh"
-#include "../DefaultBundle/LlcSnapPacket.hh"
#include <boost/io/ios_state.hpp>
#define prefix_
+namespace {
+
+ void dumpBase(senf::WLANPacketParser const & p, std::ostream & os)
+ {
+ os << " version : " << unsigned(p.version()) <<"\n"
+ << " type : " << unsigned(p.type()) << "\n"
+ << " subtype : " << unsigned(p.subtype()) << "\n"
+ << " flags :";
+ if ( p.toDS() ) os << " toDS";
+ if ( p.fromDS() ) os << " fromDS";
+ if ( p.moreFrag() ) os << " moreFrag";
+ if ( p.retry() ) os << " retry";
+ if ( p.pwrMgt() ) os << " pwrMgt";
+ if ( p.moreData() ) os << " moreData";
+ if ( p.protectedFrame() ) os << " protected";
+ if ( p.order() ) os << " order";
+
+ if ( !(p.toDS() || p.fromDS() || p.moreFrag() || p.retry() || p.pwrMgt() ||
+ p.moreData() || p.protectedFrame() || p.order()) )
+ os << " none";
+ os << "\n"
+ << " duration : " << unsigned(p.duration()) << "\n";
+ }
+}
+
+prefix_ void senf::WLANPacket_MgtFrameType::dump(packet p, std::ostream &os)
+{
+ boost::io::ios_all_saver ias(os);
+ os << "802.11 MAC Mangement Frame:\n";
+ dumpBase(p.parser(), os);
+ os << " destination : " << p->destinationAddress() << "\n"
+ << " source : " << p->sourceAddress() << "\n"
+ << " bss id : " << p->bssid() << "\n"
+ << " sequence number : " << p->sequenceNumber() << "\n"
+ << " fragment number : " << p->fragmentNumber() << "\n";
+}
+
+prefix_ void senf::WLANPacket_CtrlFrameType::dump(packet p, std::ostream &os)
+{
+ boost::io::ios_all_saver ias(os);
+ os << "802.11 MAC Control Frame:\n";
+ dumpBase(p.parser(), os);
+ os << " receiver : " << p->receiverAddress() << "\n";
+ if (p->is_rts())
+ os << " source : " << p->sourceAddress() << "\n";
+}
+
prefix_ senf::MACAddressParser senf::WLANPacket_DataFrameParser::destinationAddress()
const
{
switch (dsBits()) {
case 0 :
- case 2 :
- return addr1();
+ case 2 : return addr1();
+ default: return addr3();
}
- return addr3();
}
prefix_ senf::MACAddressParser senf::WLANPacket_DataFrameParser::sourceAddress()
switch (dsBits())
{
case 0 :
- case 1 :
- return addr2();
- break;
- case 2 :
- return addr3();
- break;
-//TODO wds frames
-// case 3:
-// return addr4();
+ case 1 : return addr2();
+ // TODO wds frames
+ // case 3 : return addr4();
+ default: return addr3();
}
- //just to avoid compiler warning
- //TODO
- return addr1();
}
prefix_ senf::MACAddressParser senf::WLANPacket_DataFrameParser::bssid()
{
switch (dsBits())
{
- case 0 :
- return addr3();
- break;
- case 1 :
- return addr1();
- break;
- case 2:
- return addr2();
+ case 0 : return addr3();
+ case 1 : return addr1();
+ default: return addr2();
}
- //just to avoid compiler warning
- //TODO
- return addr1();
}
-prefix_ senf::PacketInterpreterBase::factory_t senf::WLANPacketType::nextPacketType(packet p)
-{
- if (p->is_dataFrame() && (p->subtype()==0 || p->subtype()==8)) //data frame and subtype is Data or QoS Data
- return LlcSnapPacket::factory();
- return no_factory();
-}
-
-prefix_ senf::PacketInterpreterBase::optional_range senf::WLANPacketType::nextPacketRange(packet p)
-{
- if (p->is_dataFrame()) {
- size_type sz = 24; //header length of wlan data frame (WDS is not considered)
- if (p->subtype()==8) //subtype QoSData
- sz+=2; //2 bytes for QoS field
- return range(
- boost::next(p.data().begin(),sz),
- boost::prior(p.data().end(),4) ); //-4 bytes FCS
- }
- //TODO beacon frame payload
- return no_range();
-}
-
-prefix_ void senf::WLANPacketType::dump(packet p, std::ostream &os)
+prefix_ void senf::WLANPacket_DataFrameType::dump(packet p, std::ostream &os)
{
boost::io::ios_all_saver ias(os);
- os << "802.11 MAC Frame:\n"
- << " Type : " << unsigned( p->type()) << "\n"
- << " Subtype : " << unsigned( p->subtype()) << "\n"
- << " Retransmission : " << unsigned( p->retry()) << "\n"
- << " Duration : " << unsigned( p->duration()) << "\n";
- if (p->is_mgtFrame()) {
- os << " Management-Frame:\n"
- << " BSSID : " << p->mgtFrame().bssid() << "\n"
- << " Destination Address : " << p->mgtFrame().destinationAddress() << "\n"
- << " Source Address : " << p->mgtFrame().sourceAddress() << "\n"
- << " Sequence Number : " << unsigned( p->mgtFrame().sequenceNumber()) << "\n"
- << " Fragment Number : " << unsigned( p->mgtFrame().fragmentNumber()) << "\n";
- }
- if (p->is_ctrlFrame()) {
- os << " Control-Frame ";
- if (p->ctrlFrame().is_cts()) os << "(CTS):\n";
- if (p->ctrlFrame().is_ack()) os << "(ACK):\n";
- if (p->ctrlFrame().is_rts()) os << "(RTS):\n";
- os << " Receiver Address : " << p->ctrlFrame().receiverAddress() << "\n";
- if (p->ctrlFrame().is_rts())
- os << " Source Address : " << p->ctrlFrame().sourceAddress() << "\n";
- }
- if (p->is_dataFrame()) {
- os << " Data-Frame:\n"
- << " Sequence Number : " << unsigned( p->dataFrame().sequenceNumber()) << "\n"
- << " Fragment Number : " << unsigned( p->dataFrame().fragmentNumber()) << "\n";
- }
-};
-
-
-
+ os << "802.11 MAC Data Frame:\n";
+ dumpBase(p.parser(), os);
+ os << " destination : " << p->destinationAddress();
+ if (p->dsBits()==0 || p->dsBits()==2) os << " (receiver)";
+ os << "\n"
+ << " source : " << p->sourceAddress();
+ if (p->dsBits()==0 || p->dsBits()==1) os << " (transmitter)";
+ os << "\n"
+ << " bss id : " << p->bssid();
+ if (p->dsBits()==1) os << " (receiver)";
+ else if (p->dsBits()!=0) os << " (transmitter)";
+ os << "\n"
+ << " sequence number : " << p->sequenceNumber() << "\n"
+ << " fragment number : " << p->fragmentNumber() << "\n";
+ if (p->has_qosField())
+ os << " QOS data : " << p->qosField() << "\n";
+}
#undef prefix_
+
+\f
+// Local Variables:
+// mode: c++
+// fill-column: 100
+// c-file-style: "senf"
+// indent-tabs-mode: nil
+// ispell-local-dictionary: "american"
+// compile-command: "scons -u test"
+// comment-column: 40
+// End:
#include "../../Packets/Packets.hh"
#include "../DefaultBundle/EthernetPacket.hh"
+#include "../DefaultBundle/LlcSnapPacket.hh"
namespace senf
{
- /** \brief Management frame parser
- * <b>Re-ordering of bits due to LSB byte order</b>
+ /** \brief 802.11 Frame parser
+ (see IEEE 802.11-2007 standard - Chapter 7 Frame formats)
+ <b>Re-ordering of bits due to host byte order</b>
+ Frame base class.
*/
- struct WLANPacket_MgtFrameParser : public senf::PacketParserBase
+ struct WLANPacketParser : public senf::PacketParserBase
{
- # include SENF_FIXED_PARSER()
+ # include SENF_PARSER()
+
+ /*
+ * Frame control field
+ * re-ordering of fields due to the byte order
+ */
+ SENF_PARSER_BITFIELD_RO ( subtype, 4, unsigned );
+ SENF_PARSER_BITFIELD_RO ( type, 2, unsigned );
+ SENF_PARSER_BITFIELD ( version, 2, unsigned );
+ SENF_PARSER_BITFIELD ( order, 1, bool );
+ SENF_PARSER_BITFIELD ( protectedFrame, 1, bool );
+ SENF_PARSER_BITFIELD ( moreData, 1, bool );
+ SENF_PARSER_BITFIELD ( pwrMgt, 1, bool );
+ SENF_PARSER_BITFIELD ( retry, 1, bool );
+ SENF_PARSER_BITFIELD ( moreFrag, 1, bool );
+ SENF_PARSER_BITFIELD ( fromDS, 1, bool );
+ SENF_PARSER_BITFIELD ( toDS, 1, bool );
+
+ SENF_PARSER_FIELD ( duration, UInt16LSBParser );
+
+ SENF_PARSER_FINALIZE(WLANPacketParser);
+ };
+
+ ///////////////////////////////////////////////////////////////////////////
+
+ /** \brief Management frame parser
+ <b>Re-ordering of bits due to LSB byte order</b>
+ */
+ struct WLANPacket_MgtFrameParser : public WLANPacketParser
+ {
+ # include SENF_PARSER()
+
+ SENF_PARSER_INHERIT(WLANPacketParser);
- SENF_PARSER_PRIVATE_BITFIELD ( subtype, 4, unsigned ); //<pkgdraw: hide
- //skip type and version
- SENF_PARSER_SKIP_BITS ( 4 ); //<pkgdraw: hide
- //jump to fist address field
- SENF_PARSER_SKIP ( 3 ); //<pkgdraw: hide
SENF_PARSER_FIELD ( destinationAddress, MACAddressParser );
SENF_PARSER_FIELD ( sourceAddress, MACAddressParser );
SENF_PARSER_FIELD ( bssid, MACAddressParser );
SENF_PARSER_BITFIELD ( fragmentNumber, 4, unsigned );
SENF_PARSER_PRIVATE_FIELD ( seqNumber_2, UInt8Parser );
- SENF_PARSER_FINALIZE(WLANPacket_MgtFrameParser);
+ SENF_PARSER_INIT() { type_() = 0; }
- //this is needed due to the goto in the WLANPacketParser. Don't know exactly why yet.
- SENF_PARSER_INIT() {}
+ SENF_PARSER_FINALIZE(WLANPacket_MgtFrameParser);
boost::uint16_t sequenceNumber() const {
return (uint16_t)(seqNumber_2()) << 4 | seqNumber_1();
};
};
+ /** \brief WLAN Management frame packet
+
+ \par Packet type (typedef):
+ \refWLANPacket_MgtFrame
+
+ \par Fields:
+ \ref WLANPacket_MgtFrameParser
+ \image html WLANPacket_MgtFrame.png
+
+ \ingroup protocolbundle_80211
+ */
+ struct WLANPacket_MgtFrameType
+ : public senf::PacketTypeBase,
+ public senf::PacketTypeMixin<WLANPacket_MgtFrameType>
+ {
+ typedef senf::PacketTypeMixin<WLANPacket_MgtFrameType> mixin;
+ typedef senf::ConcretePacket<WLANPacket_MgtFrameType> packet;
+ typedef WLANPacket_MgtFrameParser parser;
+
+ using mixin::init;
+ using mixin::initSize;
+ using senf::PacketTypeBase::nextPacketRange;
+
+ static void dump(packet p, std::ostream &os);
+ };
+
+ typedef WLANPacket_MgtFrameType::packet WLANPacket_MgtFrame;
+
+ ///////////////////////////////////////////////////////////////////////////
+
/** \brief Control frame parser
- * <b>Re-ordering of bits due to LSB byte order</b>
- *
- * currently only CTS, RTS and ACK control frames are supported
+ <b>Re-ordering of bits due to LSB byte order</b>
+ currently only CTS, RTS and ACK control frames are supported
*/
- struct WLANPacket_CtrlFrameParser : public senf::PacketParserBase
+ struct WLANPacket_CtrlFrameParser : public WLANPacketParser
{
# include SENF_PARSER()
- SENF_PARSER_PRIVATE_BITFIELD ( subtype, 4, unsigned ); //<pkgdraw: hide
- //skip type and version
- SENF_PARSER_SKIP_BITS ( 4 ); //<pkgdraw: hide
- //jump to fist address field
- SENF_PARSER_SKIP ( 3, 3 ); //<pkgdraw: hide
+ SENF_PARSER_INHERIT(WLANPacketParser);
+
SENF_PARSER_FIELD ( receiverAddress, MACAddressParser );
//only RTS frame contains a source address field
( ids( na, is_ack, set_ack, key(13, VoidPacketParser)) )
( ids( sourceAddress, is_rts, set_rts, key(11, MACAddressParser)) ) );
+ SENF_PARSER_INIT() { type_() = 1; }
+
SENF_PARSER_FINALIZE(WLANPacket_CtrlFrameParser);
+ };
- //this is needed to due to the goto in the WLANPacketParser. Don't know exactly why yet.
- SENF_PARSER_INIT() {}
+ /** \brief WLAN Control frame packet
+
+ \par Packet type (typedef):
+ \ref WLANPacket_CtrlFrame
+
+ \par Fields:
+ \ref WLANPacket_CtrlFrameParser
+ \image html WLANPacket_CtrlFrame.png
+
+ \ingroup protocolbundle_80211
+ */
+ struct WLANPacket_CtrlFrameType
+ : public senf::PacketTypeBase,
+ public senf::PacketTypeMixin<WLANPacket_CtrlFrameType>
+ {
+ typedef senf::PacketTypeMixin<WLANPacket_CtrlFrameType> mixin;
+ typedef senf::ConcretePacket<WLANPacket_CtrlFrameType> packet;
+ typedef WLANPacket_CtrlFrameParser parser;
+
+ using mixin::init;
+ using mixin::initSize;
+ using senf::PacketTypeBase::nextPacketRange;
+
+ static void dump(packet p, std::ostream &os);
};
- /** \brief Data frame parser
- * <b>Re-ordering of bits due to LSB byte order</b>
+ typedef WLANPacket_CtrlFrameType::packet WLANPacket_CtrlFrame;
+ ///////////////////////////////////////////////////////////////////////////
+
+ /** \brief Data frame parser
+ <b>Re-ordering of bits due to LSB byte order</b>
*/
- struct WLANPacket_DataFrameParser : public senf::PacketParserBase
+ struct WLANPacket_DataFrameParser : public WLANPacketParser
{
# include SENF_PARSER()
- SENF_PARSER_PRIVATE_BITFIELD ( subtype, 4, unsigned ); //<pkgdraw: hide
- //jump to 'toDS' and 'fromDS' bits
- //skip type and version
- SENF_PARSER_SKIP_BITS ( 4 ); //<pkgdraw: hide
- //skip other flags
- SENF_PARSER_SKIP_BITS ( 6 ); //<pkgdraw: hide
- //needed in data frames due to the variable address fields
+
+ SENF_PARSER_INHERIT(WLANPacketParser);
+
+ SENF_PARSER_GOTO(subtype);
+ SENF_PARSER_SKIP_BITS(14); //<pkgdraw: hide
SENF_PARSER_PRIVATE_BITFIELD ( dsBits, 2, unsigned ); //<pkgdraw: hide
- //skip duration field
SENF_PARSER_SKIP ( 2, 2 ); //<pkgdraw: hide
SENF_PARSER_PRIVATE_FIELD ( addr1, MACAddressParser );
SENF_PARSER_BITFIELD ( fragmentNumber, 4, unsigned );
SENF_PARSER_PRIVATE_FIELD ( seqNumber_2, UInt8Parser );
- //TODO fourth address field in case of WDS
-// SENF_PARSER_PRIVATE_VARIANT (wds_, dsBits,
-// ( novalue ( disable_addr4, VoidPacketParser ))
-// ( id ( addr4, key (3, MACAddressParser ))) );
+ boost::uint16_t sequenceNumber() const {
+ return (uint16_t)(seqNumber_2()) << 4 | seqNumber_1();
+ };
+
+ // TODO fourth address field in case of WDS
+ // SENF_PARSER_PRIVATE_VARIANT (wds_, dsBits,
+ // ( novalue ( disable_addr4, VoidPacketParser ))
+ // ( id ( addr4, key (3, MACAddressParser ))) );
- //QoS Filed
+ //QoS Field
SENF_PARSER_VARIANT ( qosField_, subtype,
( ids( na, na, set_data, key(0, VoidPacketParser)) )
( ids( na, na, set_nullData, key(4, VoidPacketParser)) )
//we cannot parse qos Null (data) frames at the moment
( ids( na, na, set_qosNullData, key(12, UInt16LSBParser)) ) );
- SENF_PARSER_FINALIZE(WLANPacket_DataFrameParser);
-
- //this is needed to due to the goto in the WLANPacketParser. Don't know exactly why yet.
- SENF_PARSER_INIT() {}
+ SENF_PARSER_INIT() { type_() = 2; }
- boost::uint16_t sequenceNumber() const {
- return (uint16_t)(seqNumber_2()) << 4 | seqNumber_1();
- };
+ SENF_PARSER_FINALIZE(WLANPacket_DataFrameParser);
MACAddressParser receiverAddress() const { return addr1(); }; //ra is always addr1
MACAddressParser transmitterAddress() const { return addr2(); }; //ta is always addr2
MACAddressParser sourceAddress() const;
MACAddressParser destinationAddress() const;
MACAddressParser bssid() const;
- };
-
-
- /** \brief 802.11 Frame parser
- * (see IEEE 802.11-2007 standard - Chapter 7 Frame formats)
- * <b>Re-ordering of bits due to LSB byte order</b>
-
- */
- struct WLANPacketParser : public senf::PacketParserBase
- {
- # include SENF_PARSER()
-
- /*
- * Frame control field
- * re-ordering of fields due to the byte order
- */
- SENF_PARSER_BITFIELD_RO ( subtype, 4, unsigned );
- SENF_PARSER_BITFIELD_RO ( type, 2, unsigned );
- SENF_PARSER_BITFIELD ( version, 2, unsigned );
- SENF_PARSER_BITFIELD ( order, 1, bool );
- SENF_PARSER_BITFIELD ( protectedFrame, 1, bool );
- SENF_PARSER_BITFIELD ( moreData, 1, bool );
- SENF_PARSER_BITFIELD ( pwrMgt, 1, bool );
- SENF_PARSER_BITFIELD ( retry, 1, bool );
- SENF_PARSER_BITFIELD ( moreFrag, 1, bool );
- SENF_PARSER_BITFIELD ( fromDS, 1, bool );
- SENF_PARSER_BITFIELD ( toDS, 1, bool );
-
- SENF_PARSER_FIELD ( duration, UInt16LSBParser );
-
- SENF_PARSER_GOTO( subtype ); // subparsers need to know the subtype
- SENF_PARSER_VARIANT ( frameType_, type,
- ( ids( mgtFrame, is_mgtFrame, init_mgtFrame, WLANPacket_MgtFrameParser ))
- ( ids( ctrlFrame, is_ctrlFrame, init_ctrlFrame, WLANPacket_CtrlFrameParser ))
- ( ids( dataFrame, is_dataFrame, init_dataFrame, WLANPacket_DataFrameParser ))
- ( novalue( reserved, WLANPacket_CtrlFrameParser )) );
-
- SENF_PARSER_CUSTOM_FIELD( fcs, senf::UInt32Parser, fcs_t::fixed_bytes, fcs_t::fixed_bytes) {
- return parse<UInt32Parser>( data().size()-4 ); }
-
- SENF_PARSER_FINALIZE(WLANPacketParser);
-
- SENF_PARSER_INIT() {
- version() = 0;
- }
-
- //Problems can occur with old madwifi and ath5k. Some frames only
- //contains two byte FCS instead of four.
-// UInt32Parser fcs() const { return parse<UInt32Parser>( data().size()-4 ); }
+ friend class WLANPacket_DataFrameType;
};
- /** \brief WLAN packet
+ /** \brief WLAN Data frame packet
\par Packet type (typedef):
- \ref WLANPacket
+ \ref WLANPacket_DataFrame
\par Fields:
- \ref WLANPacketParser
- \image html WLANPacket.png
+ \ref WLANPacket_DataFrameParser
+ \image html WLANPacket_DataFrame.png
\ingroup protocolbundle_80211
*/
- struct WLANPacketType
+ struct WLANPacket_DataFrameType
: public senf::PacketTypeBase,
- public senf::PacketTypeMixin<WLANPacketType>
+ public senf::PacketTypeMixin<WLANPacket_DataFrameType>
{
- typedef senf::PacketTypeMixin<WLANPacketType> mixin;
- typedef senf::ConcretePacket<WLANPacketType> packet;
- typedef WLANPacketParser parser;
-
+ typedef senf::PacketTypeMixin<WLANPacket_DataFrameType> mixin;
+ typedef senf::ConcretePacket<WLANPacket_DataFrameType> packet;
+ typedef WLANPacket_DataFrameParser parser;
using mixin::init;
using mixin::initSize;
-// using senf::PacketTypeBase::nextPacketRange;
- static optional_range nextPacketRange(packet p);
- static factory_t nextPacketType(packet p);
+ using mixin::nextPacketRange;
+
+ static factory_t nextPacketType(packet p) {
+ return p->subtype() == 0 || p->subtype() == 8
+ ? LlcSnapPacket::factory()
+ : no_factory();
+ }
static void dump(packet p, std::ostream &os);
-// static PacketParserBase::size_type initSize();
};
- typedef senf::ConcretePacket<WLANPacketType> WLANPacket;
+ typedef WLANPacket_DataFrameType::packet WLANPacket_DataFrame;
}
-
#endif /* HH_SENF_Packets_80211Bundle_WLANPacket_ */
+
+\f
+// Local Variables:
+// mode: c++
+// fill-column: 100
+// c-file-style: "senf"
+// indent-tabs-mode: nil
+// ispell-local-dictionary: "american"
+// compile-command: "scons -u test"
+// comment-column: 40
+// End:
0x06, 0xb0, 0x00, 0x18, 0x4d, 0x6e, 0x78, 0x48,
0x30, 0x00, 0x01, 0x00,
0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00, 0x08, 0x00, //llc header
- 0x38, 0x39, 0x30, 0x31 //trailer
};
-
- senf::WLANPacket p (senf::WLANPacket::create(data));
+ senf::WLANPacket_DataFrame p (senf::WLANPacket_DataFrame::create(data));
BOOST_CHECK_EQUAL( p->version(), 0u );
BOOST_CHECK_EQUAL( p->type(), 2u );
BOOST_CHECK_EQUAL( p->duration(), 0u );
- BOOST_CHECK_EQUAL(
- p->dataFrame().destinationAddress().value(),
+ BOOST_CHECK_EQUAL( p->destinationAddress().value(),
senf::MACAddress::from_string("00:18:4d:6e:78:48") );
- BOOST_CHECK_EQUAL(
- p->dataFrame().sourceAddress().value(),
- senf::MACAddress::from_string("00:0b:6b:57:06:b0") );
- BOOST_CHECK_EQUAL(
- p->dataFrame().bssid().value(),
- senf::MACAddress::from_string("00:1a:4d:3e:c7:5c") );
-
- BOOST_CHECK_EQUAL(
- p->dataFrame().bssid().value(),
- p->dataFrame().receiverAddress().value() );
- BOOST_CHECK_EQUAL(
- p->dataFrame().transmitterAddress().value(),
- p->dataFrame().sourceAddress().value() );
-
- BOOST_CHECK_EQUAL( p->dataFrame().sequenceNumber(), 3u );
- BOOST_CHECK_EQUAL( p->dataFrame().fragmentNumber(), 0u );
+ BOOST_CHECK_EQUAL( p->sourceAddress().value(),
+ senf::MACAddress::from_string("00:0b:6b:57:06:b0") );
+ BOOST_CHECK_EQUAL (p->bssid().value(),
+ senf::MACAddress::from_string("00:1a:4d:3e:c7:5c") );
+
+ BOOST_CHECK_EQUAL( p->bssid().value(),
+ p->receiverAddress().value() );
+ BOOST_CHECK_EQUAL( p->transmitterAddress().value(),
+ p->sourceAddress().value() );
+
+ BOOST_CHECK_EQUAL( p->sequenceNumber(), 3u );
+ BOOST_CHECK_EQUAL( p->fragmentNumber(), 0u );
std::ostringstream oss (std::ostringstream::out);
- SENF_CHECK_NO_THROW( p.dump( oss));
+ SENF_CHECK_NO_THROW( p.dump(oss) );
- BOOST_CHECK( p.next());
+ BOOST_REQUIRE( p.next(senf::nothrow) );
BOOST_CHECK( p.next().is<senf::LlcSnapPacket>() );
}
/* test parser with creating a data frame*/
BOOST_AUTO_UNIT_TEST(WLANPacket_dataFrame_create)
{
- senf::WLANPacket p (senf::WLANPacket::create());
+ senf::WLANPacket_DataFrame p (senf::WLANPacket_DataFrame::create());
- SENF_CHECK_NO_THROW( p->init_dataFrame() );
- SENF_CHECK_NO_THROW( p->dataFrame().bssid() = senf::MACAddress::from_string("00:1a:4d:3e:c7:5c") );
+ SENF_CHECK_NO_THROW( p->bssid() = senf::MACAddress::from_string("00:1a:4d:3e:c7:5c") );
BOOST_CHECK_EQUAL( p->type(), 2u );
}
0xa3, 0x40, 0x00, 0x27, 0xa4, 0x00, 0x00, 0x42,
0x43, 0x5e, 0x00, 0x62, 0x32, 0x2f, 0x00, 0xa0,
0x00, 0xdd, 0x09, 0x00, 0x03, 0x7f, 0x01, 0x01,
- 0x00, 0x24, 0xff, 0x7f, 0x87, 0x07, 0x1f, 0xf5,
+ 0x00, 0x24, 0xff, 0x7f,
};
- senf::WLANPacket p (senf::WLANPacket::create(data));
+ senf::WLANPacket_MgtFrame p (senf::WLANPacket_MgtFrame::create(data));
BOOST_CHECK_EQUAL( p->version(), 0u );
BOOST_CHECK_EQUAL( p->type(), 0u );
BOOST_CHECK_EQUAL( p->order(), false );
BOOST_CHECK_EQUAL( p->duration(), 0u );
- BOOST_CHECK_EQUAL( p->is_mgtFrame(), true );
+ BOOST_CHECK_EQUAL( p->destinationAddress().value(),
+ senf::MACAddress::from_string("ff:ff:ff:ff:ff:ff") );
+ BOOST_CHECK_EQUAL( p->sourceAddress().value(),
+ senf::MACAddress::from_string("00:1a:4d:3e:c7:5c") );
+ BOOST_CHECK_EQUAL( p->bssid().value(),
+ senf::MACAddress::from_string("00:1a:4d:3e:c7:5c") );
- BOOST_CHECK_EQUAL(
- p->mgtFrame().destinationAddress().value(),
- senf::MACAddress::from_string("ff:ff:ff:ff:ff:ff") );
- BOOST_CHECK_EQUAL(
- p->mgtFrame().sourceAddress().value(),
- senf::MACAddress::from_string("00:1a:4d:3e:c7:5c") );
- BOOST_CHECK_EQUAL(
- p->mgtFrame().bssid().value(),
- senf::MACAddress::from_string("00:1a:4d:3e:c7:5c") );
-
- BOOST_CHECK_EQUAL( p->mgtFrame().sequenceNumber(), 302u );
- BOOST_CHECK_EQUAL( p->mgtFrame().fragmentNumber(), 0u );
-
- BOOST_CHECK_EQUAL( p->fcs(), 0x87071ff5 );
+ BOOST_CHECK_EQUAL( p->sequenceNumber(), 302u );
+ BOOST_CHECK_EQUAL( p->fragmentNumber(), 0u );
}
/* test parser with creating a beacon frame*/
BOOST_AUTO_UNIT_TEST(WLANPacket_mgtFrame_create)
{
- senf::WLANPacket p (senf::WLANPacket::create());
+ senf::WLANPacket_MgtFrame p (senf::WLANPacket_MgtFrame::create());
- SENF_CHECK_NO_THROW( p->init_mgtFrame() );
SENF_CHECK_NO_THROW(
- p->mgtFrame().destinationAddress() = senf::MACAddress::from_string("ff:ff:ff:ff:ff:ff")
+ p->destinationAddress() = senf::MACAddress::from_string("ff:ff:ff:ff:ff:ff")
);
SENF_CHECK_NO_THROW(
- p->mgtFrame().sourceAddress() = senf::MACAddress::from_string("00:1a:4d:3e:c7:5c")
+ p->sourceAddress() = senf::MACAddress::from_string("00:1a:4d:3e:c7:5c")
);
SENF_CHECK_NO_THROW(
- p->mgtFrame().bssid() = senf::MACAddress::from_string("00:1a:4d:3e:c7:5c")
+ p->bssid() = senf::MACAddress::from_string("00:1a:4d:3e:c7:5c")
);
BOOST_CHECK_EQUAL( p->type(), 0u );
BOOST_AUTO_UNIT_TEST(WLANPacket_ctrlFrame_packet)
{
unsigned char data[] = {
- 0xd4, 0x00, 0x00, 0x00, 0x00, 0x0b, 0x6b, 0x57,
- 0x06, 0xb0, 0x4f, 0xda
+ 0xd4, 0x00, 0x00, 0x00,
+ 0x00, 0x0b, 0x6b, 0x57, 0x06, 0xb0,
+ 0x4f, 0xda, // What is this ?
};
- senf::WLANPacket p (senf::WLANPacket::create(data));
+ senf::WLANPacket_CtrlFrame p (senf::WLANPacket_CtrlFrame::create(data));
BOOST_CHECK_EQUAL( p->version(), 0u );
BOOST_CHECK_EQUAL( p->type(), 1u );
BOOST_CHECK_EQUAL( p->duration(), 0u );
- BOOST_CHECK_EQUAL(
- p->ctrlFrame().receiverAddress().value(),
- senf::MACAddress::from_string("00:0b:6b:57:06:b0") );
+ BOOST_CHECK_EQUAL( p->receiverAddress().value(),
+ senf::MACAddress::from_string("00:0b:6b:57:06:b0") );
}
-
/* test parser with creating an ACK frame*/
BOOST_AUTO_UNIT_TEST(WLANPacket_ctrlFrame_create)
{
- senf::WLANPacket p (senf::WLANPacket::create()) ;
-// std::cout << unsigned( senf::init_bytes<senf::WLANPacketParser_CtrlFrameParser>::value ) << "\n";
- SENF_CHECK_NO_THROW(p->init_ctrlFrame());
-// std::cout << unsigned( senf::init_bytes<senf::WLANPacketParser_CtrlFrameParser>::value ) << "\n";
- p->ctrlFrame().receiverAddress() = senf::MACAddress::from_string("00:1a:4d:3e:c7:5c");
- p->ctrlFrame().set_ack();
+ senf::WLANPacket_CtrlFrame p (senf::WLANPacket_CtrlFrame::create()) ;
+ p->receiverAddress() = senf::MACAddress::from_string("00:1a:4d:3e:c7:5c");
+ p->set_ack();
BOOST_CHECK_EQUAL( p->type(), 1u);
BOOST_CHECK_EQUAL( p->subtype(), 13u);
}
+\f
+// Local Variables:
+// mode: c++
+// fill-column: 100
+// c-file-style: "senf"
+// indent-tabs-mode: nil
+// ispell-local-dictionary: "american"
+// compile-command: "scons -u test"
+// comment-column: 40
+// End:
{
boost::io::ios_all_saver ias(os);
os << "MIH Packet:\n"
- << " protocol header:\n"
- << " Version: " << unsigned( p->version()) << "\n"
- << " Ack-Request: " << p->ackRequest() << "\n"
- << " Ack-Response: " << p->ackResponse() << "\n"
- << " UIR: " << p->uir() << "\n"
- << " more fragment: " << p->moreFragment() << "\n"
- << " fragment number: " << p->fragmentNr() << "\n"
- << " message ID (MID): " << unsigned( p->messageId()) << "\n"
- << " SID: " << unsigned( p->sid()) << "\n"
- << " Opcode: " << unsigned( p->opcode()) << "\n"
- << " AID: " << unsigned( p->aid()) << "\n"
- << " Transaction ID: " << unsigned( p->transactionId()) << "\n"
- << " payload length: " << unsigned( p->payloadLength()) << "\n"
- << " source MIHF_Id TLV:\n"
- << " type: " << unsigned (p->src_mihfId().type()) << "\n"
- << " length: " << unsigned (p->src_mihfId().length()) << "\n"
- << " value:\n";
+ << " protocol header:\n"
+ << " version : " << unsigned( p->version()) << "\n"
+ << " ack request : " << p->ackRequest() << "\n"
+ << " ack response : " << p->ackResponse() << "\n"
+ << " UIR : " << p->uir() << "\n"
+ << " more fragments : " << p->moreFragment() << "\n"
+ << " fragment number : " << p->fragmentNr() << "\n"
+ << " message ID (MID) : " << unsigned( p->messageId()) << "\n"
+ << " sid : " << unsigned( p->sid()) << "\n"
+ << " opcode : " << unsigned( p->opcode()) << "\n"
+ << " aid : " << unsigned( p->aid()) << "\n"
+ << " transaction id : " << unsigned( p->transactionId()) << "\n"
+ << " payload length : " << unsigned( p->payloadLength()) << "\n"
+ << " source MIHF_Id TLV :\n"
+ << " type : " << unsigned (p->src_mihfId().type()) << "\n"
+ << " length : " << unsigned (p->src_mihfId().length()) << "\n"
+ << " value :\n";
std::string src_mihfId (p->src_mihfId().asString());
hexdump(src_mihfId.begin(), src_mihfId.end(), os);
- os << " destination MIHF_Id TLV:\n"
- << " type: " << unsigned (p->dst_mihfId().type()) << "\n"
- << " length: " << unsigned (p->dst_mihfId().length()) << "\n"
- << " value:\n";
+ os << " destination MIHF_Id TLV:\n"
+ << " type : " << unsigned (p->dst_mihfId().type()) << "\n"
+ << " length : " << unsigned (p->dst_mihfId().length()) << "\n"
+ << " value :\n";
std::string dst_mihfId (p->dst_mihfId().asString());
hexdump(dst_mihfId.begin(), dst_mihfId.end(), os);
}
boost::io::ios_all_saver ias(os);
os << "GenericTLVPacket:\n"
<< std::dec
- << " type: " << unsigned( p->type()) << "\n"
- << " length: " << unsigned( p->length()) << "\n"
- << " value\n:";
+ << " type : " << unsigned( p->type()) << "\n"
+ << " length : " << unsigned( p->length()) << "\n"
+ << " value\n : ";
senf::hexdump( p->value().begin(), p->value().end(), os);
}
os << "Ethernet II (DIX)";
else
os << "Ethernet 802.3 (bad ethertype >1500 and <1536)";
- os << ": \n"
- << " destination : " << p->destination() << "\n"
- << " source : " << p->source() << "\n"
- << " type/length : 0x"
- << std::hex << std::setw(4) << std::setfill('0') << p->type_length() << "\n";
+ os << ": \n"
+ << " destination : " << p->destination() << "\n"
+ << " source : " << p->source() << "\n"
+ << " type/length : 0x"
+ << std::hex << std::setw(4) << std::setfill('0') << p->type_length() << "\n";
}
prefix_ senf::PacketInterpreterBase::factory_t senf::EthernetPacketType::nextPacketType(packet p)
prefix_ void senf::EthVLanPacketType::dump(packet p, std::ostream & os)
{
boost::io::ios_all_saver ias(os);
- os << "Ethernet 802.1q (VLAN):\n"
- << " priority : " << p->priority() << "\n"
- << " cfi : " << p->cfi() << "\n"
- << " vlan-ID : " << p->vlanId() << "\n"
- << " ethertype : 0x"
- << std::hex << std::setw(4) << std::setfill('0') << p->type() << "\n";
+ os << "Ethernet 802.1q (VLAN):\n"
+ << " priority : " << p->priority() << "\n"
+ << " cfi : " << p->cfi() << "\n"
+ << " vlan-ID : " << p->vlanId() << "\n"
+ << " ethertype : 0x"
+ << std::hex << std::setw(4) << std::setfill('0') << p->type() << "\n";
}
prefix_ void senf::EthVLanPacketType::finalize(packet p)
{
boost::io::ios_all_saver ias(os);
os << "ICMPv6 protocol:\n"
- << "Type : " << p->type() <<"\n"
- << "Code : " << p->code() <<"\n"
- << "Checksum : " << p->checksum() << "\n";
+ << " type : " << p->type() <<"\n"
+ << " code : " << p->code() <<"\n"
+ << " checksum : " << p->checksum() << "\n";
}
///////////////////////////////cc.e////////////////////////////////////////
prefix_ void senf::IPv4PacketType::dump(packet p, std::ostream & os)
{
boost::io::ios_all_saver ias(os);
- os << "Internet protocol Version 4:\n"
- << " version : " << p->version() << "\n"
- << " IHL : " << p->ihl() << "\n"
- << " TOS : " << unsigned(p->tos()) << "\n"
- << " length : " << p->length() << "\n"
- << " identifier : " << p->identifier() << "\n"
- << " DF : " << p->df() << "\n"
- << " MF : " << p->mf() << "\n"
- << " fragment : " << p->frag() << "\n"
- << " TTL : " << unsigned(p->ttl()) << "\n"
- << " protocol : " << unsigned(p->protocol()) << "\n"
- << " checksum : 0x"
+ os << "Internet protocol Version 4:\n"
+ << " version : " << p->version() << "\n"
+ << " ip header length : " << p->ihl() << "\n"
+ << " tos : " << unsigned(p->tos()) << "\n"
+ << " length : " << p->length() << "\n"
+ << " identifier : " << p->identifier() << "\n"
+ << " dont fragment : " << p->df() << "\n"
+ << " more fragments : " << p->mf() << "\n"
+ << " fragment : " << p->frag() << "\n"
+ << " ttl : " << unsigned(p->ttl()) << "\n"
+ << " protocol : " << unsigned(p->protocol()) << "\n"
+ << " checksum : 0x"
<< std::hex << std::setw(4) << std::setfill('0') << p->checksum() << std::dec << "\n"
- << " source : " << p->source() << "\n"
- << " destination : " << p->destination() << "\n";
+ << " source : " << p->source() << "\n"
+ << " destination : " << p->destination() << "\n";
}
prefix_ void senf::IPv4PacketType::finalize(packet p)
prefix_ void senf::IPv6ExtensionType_Fragment::dump(packet p, std::ostream & os)
{
os << "Internet protocol Version 6 fragment extension:\n"
- << " next header : " << unsigned(p->nextHeader()) << "\n"
- << " fragment offset: " << std::hex << unsigned(p->fragmentOffset()) << "\n"
- << " more fragments : " << (p->moreFragments()?"yes":"no") << "\n"
- << " id : " << std::hex << unsigned(p->id()) << "\n";
+ << " next header : " << unsigned(p->nextHeader()) << "\n"
+ << " fragment offset : " << std::hex << unsigned(p->fragmentOffset()) << "\n"
+ << " more fragments : " << (p->moreFragments()?"yes":"no") << "\n"
+ << " id : " << std::hex << unsigned(p->id()) << "\n";
}
prefix_ void senf::IPv6ExtensionType_Routing::dump(packet p, std::ostream & os)
{
os << "Internet protocol Version 6 routing extension:\n"
- << " next header : " << unsigned (p->nextHeader()) << "\n"
- << " header length : " << unsigned (p->headerLength()) << "\n"
- << " routing type : " << unsigned (p->routingType()) << "\n"
- << " segments left : " << unsigned (p->segmentsLeft()) << "\n";
- IPv6Extension_Routing::Parser::hopAddresses_t::container hopAddresses (p->hopAddresses());
- os << " further Hop Addresses : \n";
+ << " next header : " << unsigned (p->nextHeader()) << "\n"
+ << " header length : " << unsigned (p->headerLength()) << "\n"
+ << " routing type : " << unsigned (p->routingType()) << "\n"
+ << " segments left : " << unsigned (p->segmentsLeft()) << "\n";
+ IPv6Extension_Routing::Parser::hopAddresses_t::container hopAddresses (p->hopAddresses());
+ os << " further Hop Addresses : \n";
if ( p->segmentsLeft() != 0 ){
for (IPv6Extension_Routing::Parser::hopAddresses_t::container::iterator i (hopAddresses.begin()); i != hopAddresses.end(); ++i)
os << *i << "\n";
prefix_ void senf::IPv6ExtensionType_HopByHop::dump(packet p, std::ostream & os)
{
os << "Internet protocol Version 6 Hop-By-Hop extension:\n"
- << " next header : " << unsigned (p->nextHeader()) << "\n"
- << " header length : " << unsigned (p->headerLength()) << "\n";
+ << " next header : " << unsigned (p->nextHeader()) << "\n"
+ << " header length : " << unsigned (p->headerLength()) << "\n";
}
prefix_ void senf::IPv6ExtensionType_Destination::dump(packet p, std::ostream & os)
{
os << "Internet protocol Version 6 Destination Options extension:\n"
- << " next header : " << unsigned (p->nextHeader()) << "\n"
- << " header length : " << unsigned (p->headerLength()) << "\n";
+ << " next header : " << unsigned (p->nextHeader()) << "\n"
+ << " header length : " << unsigned (p->headerLength()) << "\n";
}
///////////////////////////////cc.e////////////////////////////////////////
prefix_ void senf::IPv6PacketType::dump(packet p, std::ostream & os)
{
boost::io::ios_all_saver ias(os);
- os << "Internet protocol Version 6:\n"
- << " version : " << unsigned(p->version()) << "\n"
- << " traffic class : 0x"
+ os << "Internet protocol Version 6:\n"
+ << " version : " << unsigned(p->version()) << "\n"
+ << " traffic class : 0x"
<< std::hex << std::setw(2) << std::setfill('0') << unsigned(p->trafficClass()) << "\n"
- << " flow label : 0x"
+ << " flow label : 0x"
<< std::hex << std::setw(5) << std::setfill('0') << unsigned(p->flowLabel()) << "\n"
- << " payload length : " << std::dec << unsigned(p->length()) << "\n"
- << " next header : " << unsigned(p->nextHeader()) << "\n"
- << " hop limit : " << unsigned(p->hopLimit()) << "\n"
- << " source : " << p->source() << "\n"
- << " destination : " << p->destination() << "\n";
+ << " payload length : " << std::dec << unsigned(p->length()) << "\n"
+ << " next header : " << unsigned(p->nextHeader()) << "\n"
+ << " hop limit : " << unsigned(p->hopLimit()) << "\n"
+ << " source : " << p->source() << "\n"
+ << " destination : " << p->destination() << "\n";
}
prefix_ void senf::IPv6PacketType::finalize(packet p)
prefix_ void senf::LlcSnapPacketType::dump(packet p, std::ostream & os)
{
boost::io::ios_all_saver ias(os);
- os << "LLC/SNAP\n"
+ os << "LLC/SNAP:\n"
<< std::hex << std::setfill('0')
- << " LLC\n"
- << " DSAP: 0x" << unsigned(p->dsap()) << "\n"
- << " SSAP: 0x" << unsigned(p->ssap()) << "\n"
- << " controlId: 0x" << unsigned(p->ctrl()) << "\n"
- << " SNAP\n"
- << " ProtocolId: 0x" << std::setw(6) << unsigned(p->protocolId()) << "\n"
- << " type_length: 0x" << std::setw(4) << unsigned(p->type_length()) << "\n";
+ << " LLC\n"
+ << " dsap : 0x" << unsigned(p->dsap()) << "\n"
+ << " ssap : 0x" << unsigned(p->ssap()) << "\n"
+ << " control id : 0x" << unsigned(p->ctrl()) << "\n"
+ << " SNAP\n"
+ << " protocol id : 0x" << std::setw(6) << unsigned(p->protocolId()) << "\n"
+ << " type/length : 0x" << std::setw(4) << unsigned(p->type_length()) << "\n";
}
prefix_ senf::PacketInterpreterBase::factory_t senf::LlcSnapPacketType::nextPacketType(packet p)
{
boost::io::ios_all_saver ias(os);
os << "Real Time Protocol:\n"
- << " Version : " << p->version() << "\n"
- << " Padding : " << p->padding() << "\n"
- << " Extension : " << p->extension() << "\n"
- << " Contributing Source Count(CC) : " << p->csrcCount() << "\n"
- << " Marker : " << p->marker() << "\n"
- << " Payload Type : " << p->payloadType() << " "<< ptName(p->payloadType() ) <<"\n"
- << " Sequence number : " << p->seqNumber() << "\n"
- << " Timestamp : " << p->timeStamp() << "\n"
- << " Synchronisation Source Identifier : " << p->synSourceId() << "\n";
-
+ << " version : " << p->version() << "\n"
+ << " padding : " << p->padding() << "\n"
+ << " extension : " << p->extension() << "\n"
+ << " contributing source cnt : " << p->csrcCount() << "\n"
+ << " marker : " << p->marker() << "\n"
+ << " payload type : " << p->payloadType() << " "<< ptName(p->payloadType() ) <<"\n"
+ << " sequence number : " << p->seqNumber() << "\n"
+ << " timestamp : " << p->timeStamp() << "\n"
+ << " sync source id : " << p->synSourceId() << "\n";
}
#undef prefix_
{
boost::io::ios_all_saver ias(os);
os << "UDP:\n"
- << " source port : " << p->source() << "\n"
- << " dest port : " << p->destination() << "\n"
- << " length : " << p->length() << "\n"
- << " checksum : "
+ << " source port : " << p->source() << "\n"
+ << " dest port : " << p->destination() << "\n"
+ << " length : " << p->length() << "\n"
+ << " checksum : "
<< std::hex << std::setw(4) << std::setfill('0') << p->checksum() << "\n";
}
"8", "9", "10", "11", "12", "13", "14", "15" };
boost::io::ios_all_saver ias(os);
os << "DTCP HELLO Packet:" << std::endl
- << " version : " << p->versionNumber() << std::endl
- << " command : " << COMMANDS[p->command()] << std::endl
- << " interval : " << unsigned(p->interval()) << std::endl
- << " sequence number : " << p->sequenceNumber() << std::endl
- << " receive capable feed : " << (p->receiveCapableFeed() ? "yes" : "no") << std::endl
- << " ip version : " << p->ipVersion() << std::endl
- << " tunnel protocol : " << unsigned(p->tunnelProtocol()) << std::endl
- << " number of BDL ips : " << unsigned(p->fbipCount()) << std::endl
- << " feed BDL ips : ";
+ << " version : " << p->versionNumber() << std::endl
+ << " command : " << COMMANDS[p->command()] << std::endl
+ << " interval : " << unsigned(p->interval()) << std::endl
+ << " sequence number : " << p->sequenceNumber() << std::endl
+ << " receive capable feed : " << (p->receiveCapableFeed() ? "yes" : "no") << std::endl
+ << " ip version : " << p->ipVersion() << std::endl
+ << " tunnel protocol : " << unsigned(p->tunnelProtocol()) << std::endl
+ << " number of BDL ips : " << unsigned(p->fbipCount()) << std::endl
+ << " feed BDL ips : ";
switch (p->ipVersion()) {
case 4 : {
hello.dump(ss);
BOOST_CHECK_EQUAL( ss.str(),
"DTCP HELLO Packet:\n"
- " version : 1\n"
- " command : JOIN\n"
- " interval : 5\n"
- " sequence number : 2571\n"
- " receive capable feed : yes\n"
- " ip version : 4\n"
- " tunnel protocol : 23\n"
- " number of BDL ips : 2\n"
- " feed BDL ips : \n"
+ " version : 1\n"
+ " command : JOIN\n"
+ " interval : 5\n"
+ " sequence number : 2571\n"
+ " receive capable feed : yes\n"
+ " ip version : 4\n"
+ " tunnel protocol : 23\n"
+ " number of BDL ips : 2\n"
+ " feed BDL ips : \n"
" 101.102.103.104\n"
" 201.202.203.204\n" );
{
boost::io::ios_all_saver ias(os);
os << "GRE Encapsulation:\n"
- << " checksum_present : " << p->checksum_present() << "\n"
- << " protocol_type : 0x" << std::hex << p->protocol_type() << "\n"
+ << " checksum_present : " << p->checksum_present() << "\n"
+ << " protocol_type : 0x" << std::hex << p->protocol_type() << "\n"
;
}
boost::io::ios_all_saver ias(os);
os << "MPE Section:\n"
<< std::hex
- << " table_id: 0x" << unsigned(p->table_id()) << "\n"
- << " section_syntax_indicator: " << p->section_syntax_indicator() << "\n"
- << " private_indicator: " << p->private_indicator() << "\n"
+ << " table_id : 0x" << unsigned(p->table_id()) << "\n"
+ << " section syntax indicator: " << p->section_syntax_indicator() << "\n"
+ << " private indicator : " << p->private_indicator() << "\n"
<< std::dec
- << " section_length: " << p->section_length() << "\n"
+ << " section length : " << p->section_length() << "\n"
<< std::hex
- << " MAC_address_6: 0x" << unsigned(p->mac_addr_6()) << "\n"
- << " MAC_address_5: 0x" << unsigned(p->mac_addr_5()) << "\n"
- << " payload_scrambling_control: 0x" << p->payload_scrmbl_ctrl() << "\n"
- << " address_scrambling_control: 0x" << p-> addr_scrmbl_ctrl() << "\n"
- << " LLC_SNAP_flag: 0x" << p->llc_snap_flag() << "\n"
- << " current_next_indicator: 0x" << p->curr_next_indicator() << "\n"
- << " section_number: 0x" << unsigned(p->section_num()) << "\n"
- << " last_section_number: 0x" << unsigned(p->last_section_num()) << "\n"
- << " real_time_parameters: \n"
- << " delta_t: 0x" << unsigned(p->real_time_parameters().delta_t()) << "\n"
- << " table_boundary: 0x" << unsigned(p->real_time_parameters().table_boundary()) << "\n"
- << " frame_boundary: 0x" << unsigned(p->real_time_parameters().frame_boundary()) << "\n"
- << " address: 0x" << unsigned(p->real_time_parameters().address()) << "\n"
+ << " MAC address 6 : 0x" << unsigned(p->mac_addr_6()) << "\n"
+ << " MAC address 5 : 0x" << unsigned(p->mac_addr_5()) << "\n"
+ << " payload scrambling ctrl : 0x" << p->payload_scrmbl_ctrl() << "\n"
+ << " address scrambling ctrl : 0x" << p-> addr_scrmbl_ctrl() << "\n"
+ << " LLC/SNAP flag : 0x" << p->llc_snap_flag() << "\n"
+ << " current next indicator : 0x" << p->curr_next_indicator() << "\n"
+ << " section number : 0x" << unsigned(p->section_num()) << "\n"
+ << " last section number : 0x" << unsigned(p->last_section_num()) << "\n"
+ << " real time parameters : \n"
+ << " delta_t : 0x" << unsigned(p->real_time_parameters().delta_t()) << "\n"
+ << " table boundary : 0x" << unsigned(p->real_time_parameters().table_boundary()) << "\n"
+ << " frame boundary : 0x" << unsigned(p->real_time_parameters().frame_boundary()) << "\n"
+ << " address : 0x" << unsigned(p->real_time_parameters().address()) << "\n"
<< std::dec
- << " CRC: " << unsigned(p->crc()) << "\n";
+ << " crc : " << unsigned(p->crc()) << "\n";
}
prefix_ senf::PacketParserBase::size_type senf::MPESectionType::initSize()
{
os << "SNDUPacket:\n"
<< std::dec
- << " d_bit: " << p->d_bit() << "\n"
- << " length: " << unsigned(p->length()) << "\n"
+ << " d_bit : " << p->d_bit() << "\n"
+ << " length : " << unsigned(p->length()) << "\n"
<< std::hex
- << " type: 0x" << unsigned(p->type()) << "\n"
+ << " type : 0x" << unsigned(p->type()) << "\n"
<< std::dec
- << " crc: " << unsigned(p->crc()) << "\n";
+ << " crc : " << unsigned(p->crc()) << "\n";
}
prefix_ senf::PacketParserBase::size_type senf::SNDUPacketType::initSize()
boost::io::ios_all_saver ias(os);
os << "TransportPacket:\n"
<< std::hex
- << " syncByte: 0x" << unsigned(p->sync_byte()) << "\n"
- << " transport_error_indicator: 0x" << unsigned(p->transport_error_indicator()) << "\n"
- << " payload_unit_start_indicator (pusi): 0x" << unsigned(p->pusi()) << "\n"
- << " transport_priority: 0x" << unsigned(p->transport_priority()) << "\n"
+ << " syncByte : 0x" << unsigned(p->sync_byte()) << "\n"
+ << " transport error ind. : 0x" << unsigned(p->transport_error_indicator()) << "\n"
+ << " payload unit start ind. : 0x" << unsigned(p->pusi()) << "\n"
+ << " transport priority : 0x" << unsigned(p->transport_priority()) << "\n"
<< std::dec
- << " pid: " << unsigned(p->pid()) << "\n"
+ << " pid : " << unsigned(p->pid()) << "\n"
<< std::hex
- << " transport_scrambling_control: 0x" << unsigned(p->transport_scrmbl_ctrl()) << "\n"
- << " adaptation_field_control: 0x" << unsigned(p->adaptation_field_ctrl()) << "\n"
- << " continuity_counter: 0x" << unsigned(p->continuity_counter()) << "\n";
+ << " transport scrambling c. : 0x" << unsigned(p->transport_scrmbl_ctrl()) << "\n"
+ << " adaptation field ctrl : 0x" << unsigned(p->adaptation_field_ctrl()) << "\n"
+ << " continuity counter : 0x" << unsigned(p->continuity_counter()) << "\n";
if (p->pusi())
- os << " pointer_field: 0x" << unsigned(p->pointer_field()) << "\n";
+ os << " pointer field : 0x" << unsigned(p->pointer_field()) << "\n";
}
///////////////////////////////cc.e////////////////////////////////////////
prefix_ senf::ClockService::abstime_type senf::ClockService::abstime_m(clock_type clock)
{
+ if (clock == 0)
+ return abstime_type();
if (now() - baseClock_ > 1000000000ll)
restart_m();
#ifdef BOOST_DATE_TIME_POSIX_TIME_STD_CONFIG
{
if ( fd < 0)
SENF_THROW_SYSTEM_EXCEPTION("Could not open socket for NetdeviceController.");
- std::cerr << ">>Made SockFd: " << fd << std::endl;
}
prefix_ senf::NetdeviceController::SockFd::~SockFd()
{
- std::cerr << ">>Dispose SockFd: " << fd << std::endl;
::close(fd);
}
}
// Ensure, the destructor is called and calls the correct close() implementation
- BOOST_CHECK_EQUAL( senf::test::SomeSocketProtocol::closeCount(), 1u );
+ BOOST_CHECK( senf::test::SomeSocketProtocol::closeCount() > 1u );
}
///////////////////////////////cc.e////////////////////////////////////////
ls( output, command.commandPath() );
break;
+ case ParseCommandInfo::BuiltinLL :
+ if (skipping())
+ break;
+ // The parser ensures, we have either one or no argument
+ ll( output, command.commandPath() );
+ break;
+
case ParseCommandInfo::BuiltinLR :
if (skipping())
break;
prefix_ void senf::console::Executor::ls(std::ostream & output,
ParseCommandInfo::TokensRange path)
{
+ Path dir (cwd_);
+ traverseDirectory(path, dir);
+ DirectoryNode & node (*dir.back().lock());
+ DirectoryNode::child_iterator i (node.children().begin());
+ DirectoryNode::child_iterator const i_end (node.children().end());
+ for (; i != i_end; ++i)
+ output << i->first << "\n";
+}
+
+prefix_ void senf::console::Executor::ll(std::ostream & output,
+ ParseCommandInfo::TokensRange path)
+{
# define HELP_COLUMN 28
unsigned width (senf::console::Client::getWidth(output, 80u, 60u)-(HELP_COLUMN+1));
void cd(ParseCommandInfo::TokensRange dir);
void ls(std::ostream & output, ParseCommandInfo::TokensRange dir);
+ void ll(std::ostream & output, ParseCommandInfo::TokensRange dir);
void lr(std::ostream & output, ParseCommandInfo::TokensRange dir);
void pushd(ParseCommandInfo::TokensRange dir);
void popd();
{
std::stringstream os;
- parser.parse("ls", &setCommand);
+ parser.parse("ll", &setCommand);
executor(os, commands.back());
- BOOST_CHECK_EQUAL( commands.back().builtin(), senf::console::ParseCommandInfo::BuiltinLS );
+ BOOST_CHECK_EQUAL( commands.back().builtin(), senf::console::ParseCommandInfo::BuiltinLL );
BOOST_CHECK_EQUAL( os.str(),
"dir1/ \n"
"dir2/ Helptext\n"
{
std::stringstream os;
- parser.parse("ls dir1", &setCommand);
+ parser.parse("ll dir1", &setCommand);
executor(os, commands.back());
- BOOST_CHECK_EQUAL( commands.back().builtin(), senf::console::ParseCommandInfo::BuiltinLS );
+ BOOST_CHECK_EQUAL( commands.back().builtin(), senf::console::ParseCommandInfo::BuiltinLL );
BOOST_CHECK_EQUAL( os.str(), "dir3/ \n" );
}
{
std::stringstream os;
- parser.parse("ls dir1", &setCommand);
+ parser.parse("ll dir1", &setCommand);
executor(os, commands.back());
- BOOST_CHECK_EQUAL( commands.back().builtin(), senf::console::ParseCommandInfo::BuiltinLS );
+ BOOST_CHECK_EQUAL( commands.back().builtin(), senf::console::ParseCommandInfo::BuiltinLL );
BOOST_CHECK_EQUAL( os.str(), "dir3/ \n" );
}
info_->builtin(ParseCommandInfo::BuiltinLS);
setBuiltinPathArg(path); }
+ void builtin_ll(std::vector<Token> & path)
+ { info_->clear();
+ info_->builtin(ParseCommandInfo::BuiltinLL);
+ setBuiltinPathArg(path); }
+
void builtin_lr(std::vector<Token> & path)
{ info_->clear();
info_->builtin(ParseCommandInfo::BuiltinLR);
enum BuiltinCommand { NoBuiltin,
BuiltinCD,
BuiltinLS,
+ BuiltinLL,
BuiltinLR,
BuiltinPUSHD,
BuiltinPOPD,
| self.keyword_p("ls")
>> ! path
>> eps_p [ bind(&PD::builtin_ls)(d_, path_) ]
+ | self.keyword_p("ll")
+ >> ! path
+ >> eps_p [ bind(&PD::builtin_ll)(d_, path_) ]
| self.keyword_p("lr")
>> ! path
>> eps_p [ bind(&PD::builtin_lr)(d_, path_) ]
{ os_ << "builtin_cd( " << senf::stringJoin(path, "/") << " )\n"; }
void builtin_ls(std::vector<senf::console::Token> const & path)
{ os_ << "builtin_ls( " << senf::stringJoin(path, "/") << " )\n"; }
+ void builtin_ll(std::vector<senf::console::Token> const & path)
+ { os_ << "builtin_ll( " << senf::stringJoin(path, "/") << " )\n"; }
void builtin_lr(std::vector<senf::console::Token> const & path)
{ os_ << "builtin_lr( " << senf::stringJoin(path, "/") << " )\n"; }
void builtin_exit()
{
std::stringstream ss;
SENF_CHECK_NO_THROW(
- parser.parse("test/test { ls; }",
+ parser.parse("test/test { ll; }",
boost::bind<void>( boost::ref(executor), boost::ref(ss), _1 )) );
BOOST_CHECK_EQUAL( ss.str(),
"<Directory at '/test/dircb'>\n"
nread = 0;
flags = 0;
data = "";
- socket.write("ls");
+ socket.write("ll");
timer.timeout(delay(300));
senf::scheduler::process();
BOOST_CHECK_EQUAL( nread, 1 );
nread = 0;
flags = 0;
data = "";
- socket.write("ls");
+ socket.write("ll");
timer.timeout(delay(300));
senf::scheduler::process();
BOOST_CHECK_EQUAL( nread, 1 );