Packets/80211Bundle: added SSID-IE to BeaconPacket
tho [Fri, 9 Oct 2009 11:39:04 +0000 (11:39 +0000)]
git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1487 270642c3-0616-0410-b53a-bc976706d245

senf/Packets/80211Bundle/InformationElements.hh
senf/Packets/80211Bundle/WLANBeaconPacket.hh
senf/Packets/80211Bundle/WLANBeaconPacket.test.cc
senf/Packets/StringParser.cti

index 0b550f4..21911d5 100644 (file)
@@ -45,6 +45,21 @@ namespace senf {
 
     typedef GenericTLVParserBase<WLANInfoElementParser> WLANGenericInfoElementParser;
     
+    struct WLANSSIDInfoElementParser
+        : public WLANInfoElementParser
+    {
+    #   include SENF_PARSER()
+        SENF_PARSER_INHERIT  ( WLANInfoElementParser            );
+        // the StringParser includes the length field so we have to go back
+        SENF_PARSER_GOTO     ( length                           );
+        SENF_PARSER_FIELD    ( value, StringParser<UInt8Parser> );
+        SENF_PARSER_FINALIZE ( WLANSSIDInfoElementParser        );
+     
+        SENF_PARSER_INIT() {
+            type() = TYPEID;
+        }        
+        static const type_t::value_type TYPEID = 0x00u;
+    };
 }
 
 ///////////////////////////////hh.e////////////////////////////////////////
index fcfe80d..3451770 100644 (file)
@@ -38,12 +38,12 @@ namespace senf {
     {
     #   include SENF_PARSER()
 
-        SENF_PARSER_FIELD( timestamp,      UInt64LSBParser );
-        SENF_PARSER_FIELD( beaconInterval, UInt16LSBParser );
-        SENF_PARSER_SKIP(2,2); //capability flags
+        SENF_PARSER_FIELD( timestamp,      UInt64LSBParser   );
+        SENF_PARSER_FIELD( beaconInterval, UInt16LSBParser   );
+        SENF_PARSER_SKIP ( 2,2); //capability flags
 
-        //SSID element
-//        SENF_PARSER_FIELD()
+        SENF_PARSER_FIELD( ssidIE, WLANSSIDInfoElementParser );
+        WLANSSIDInfoElementParser::value_t ssid() const { return ssidIE().value(); }
         
         SENF_PARSER_FINALIZE( WLANBeaconPacketParser );
         
@@ -60,16 +60,16 @@ namespace senf {
         \ingroup protocolbundle_80211
      */
     struct WLANBeaconPacketType
-        : public senf::PacketTypeBase,
-          public senf::PacketTypeMixin<WLANBeaconPacketType>
+        : public PacketTypeBase,
+          public PacketTypeMixin<WLANBeaconPacketType>
     {
-        typedef senf::PacketTypeMixin<WLANBeaconPacketType> mixin;
-        typedef senf::ConcretePacket<WLANBeaconPacketType> packet;
+        typedef PacketTypeMixin<WLANBeaconPacketType> mixin;
+        typedef ConcretePacket<WLANBeaconPacketType> packet;
         typedef WLANBeaconPacketParser parser;
 
         using mixin::init;
         using mixin::initSize;
-        using senf::PacketTypeBase::nextPacketRange;
+        using PacketTypeBase::nextPacketRange;
 
         static void dump(packet p, std::ostream &os);
     };
index a05ed9b..41eb81d 100644 (file)
@@ -32,7 +32,7 @@
 
 ///////////////////////////////cc.p////////////////////////////////////////
 
-BOOST_AUTO_UNIT_TEST(WLANBeaconPacket_packet)
+BOOST_AUTO_UNIT_TEST(WLANBeaconPacket_parse)
 {
     unsigned char data[] = {
         0x3a, 0x30, 0xaa, 0x4c, 0x9c, 0x00, 0x00, 0x00, //timestamp
@@ -55,7 +55,27 @@ BOOST_AUTO_UNIT_TEST(WLANBeaconPacket_packet)
 
     BOOST_CHECK_EQUAL( p->timestamp(), 0x0000009C4CAA303AuLL);
     BOOST_CHECK_EQUAL( p->beaconInterval(), 100u);
+    BOOST_CHECK_EQUAL( p->ssidIE().length(), 5);
+    BOOST_CHECK_EQUAL( p->ssidIE().value().value(), "boxC1");
+    BOOST_CHECK_EQUAL( p->ssid().value(), "boxC1");
+}
 
+BOOST_AUTO_UNIT_TEST(WLANBeaconPacket_create)
+{
+    senf::WLANBeaconPacket p (senf::WLANBeaconPacket::create());
+    p->timestamp() << 0x0000009C4CAA303AuLL;
+    p->beaconInterval() << 100u;
+    p->ssidIE().value() << "boxC1";
+    p.finalizeThis();
+    
+    unsigned char data[] = {
+        0x3a, 0x30, 0xaa, 0x4c, 0x9c, 0x00, 0x00, 0x00, //timestamp
+        0x64, 0x00, //beacon interval
+        0x00, 0x00, //capability information
+        0x00, 0x05, 0x62, 0x6f, 0x78, 0x43, 0x31 //SSID
+    };
+    SENF_CHECK_EQUAL_COLLECTIONS( p.data().begin(), p.data().end(),
+            data, data+sizeof(data) );
 }
 
 ///////////////////////////////cc.e////////////////////////////////////////
index 36b3075..11c50ee 100644 (file)
@@ -55,7 +55,7 @@ prefix_ void senf::StringParser<LengthParser>::value(value_type v)
 { 
     validate(bytes());
     resize(bytes(), v.size()+senf::bytes(length())); 
-    parse<UInt16Parser>(0) = v.size(); 
+    length() << v.size(); 
     std::copy(v.begin(), v.end(), i()+senf::bytes(length()));
 }