Search:

SENF Extensible Network Framework

  • Home
  • Download
  • Wiki
  • BerliOS
  • ChangeLog
  • Browse SVN
  • Bug Tracker
  • Overview
  • Examples
  • HowTos
  • Glossary
  • PPI
  • Packets
  • Scheduler
  • Socket
  • Utils
  • Console
  • Daemon
  • Logger
  • Termlib
  • Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

80211Bundle/RadiotapPacket.hh

Go to the documentation of this file.
00001 // $Id: RadiotapPacket.hh 1772 2011-03-10 12:45:21Z tho $
00002 //
00003 // Copyright (C) 2008
00004 // Fraunhofer (FOKUS)
00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY
00006 //     Christian Niephaus <cni@berlios.de>
00007 //     Stefan Bund <g0dil@berlios.de>
00008 //
00009 // This program is free software; you can redistribute it and/or modify
00010 // it under the terms of the GNU General Public License as published by
00011 // the Free Software Foundation; either version 2 of the License, or
00012 // (at your option) any later version.
00013 //
00014 // This program is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 // GNU General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU General Public License
00020 // along with this program; if not, write to the
00021 // Free Software Foundation, Inc.,
00022 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00023 
00027 #ifndef HH_SENF_Packets_80211Bundle_RadiotapPacket_
00028 #define HH_SENF_Packets_80211Bundle_RadiotapPacket_ 1
00029 
00030 // Custom includes
00031 #include <senf/Packets/Packets.hh>
00032 #include <boost/array.hpp>
00033 
00034 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00035 namespace senf {
00036 
00041     struct RadiotapPacketParser_Flags : public PacketParserBase
00042     {
00043 #       include SENF_FIXED_PARSER()
00044 
00045         SENF_PARSER_BITFIELD ( shortGI,        1, bool );
00046         SENF_PARSER_BITFIELD ( badFCS,         1, bool );
00047         SENF_PARSER_BITFIELD ( padding,        1, bool );
00048         SENF_PARSER_BITFIELD_RO ( fcsAtEnd,    1, bool ); // Cannot change this (change packet size)
00049         SENF_PARSER_BITFIELD ( fragmentation,  1, bool );
00050         SENF_PARSER_BITFIELD ( wep,            1, bool );
00051         SENF_PARSER_BITFIELD ( shortPreamble,  1, bool );
00052         SENF_PARSER_BITFIELD ( cfp,            1, bool );
00053 
00054         SENF_PARSER_FINALIZE ( RadiotapPacketParser_Flags );
00055 
00056         friend class RadiotapPacketParser;
00057     };
00058 
00063     struct RadiotapPacketParser_ChannelOptions : public PacketParserBase
00064     {
00065 #       include SENF_FIXED_PARSER()
00066 
00067         SENF_PARSER_FIELD     ( freq,          UInt16LSBParser );
00068 
00069         SENF_PARSER_BITFIELD  ( flag2ghz,             1, bool  );
00070         SENF_PARSER_BITFIELD  ( ofdm,                 1, bool  );
00071         SENF_PARSER_BITFIELD  ( cck,                  1, bool  );
00072         SENF_PARSER_BITFIELD  ( turbo,                1, bool  );
00073         SENF_PARSER_SKIP_BITS ( 4                              );
00074         SENF_PARSER_BITFIELD  ( quarterRateChannel,   1, bool  );
00075         SENF_PARSER_BITFIELD  ( halfRateChannel,      1, bool  );
00076         SENF_PARSER_BITFIELD  ( gsm,                  1, bool  );
00077         SENF_PARSER_BITFIELD  ( staticTurbo,          1, bool  );
00078         SENF_PARSER_BITFIELD  ( gfsk,                 1, bool  );
00079         SENF_PARSER_BITFIELD  ( cckOfdm,              1, bool  );
00080         SENF_PARSER_BITFIELD  ( passive,              1, bool  );
00081         SENF_PARSER_BITFIELD  ( flag5ghz,             1, bool  );
00082 
00083         SENF_PARSER_FINALIZE ( RadiotapPacketParser_ChannelOptions );
00084     };
00085 
00086     struct RadiotapPacketParser_RxFlags : public PacketParserBase
00087     {
00088 #       include SENF_FIXED_PARSER()
00089 
00090         SENF_PARSER_SKIP_BITS ( 6                              );
00091         SENF_PARSER_BITFIELD  ( badPlcp,              1, bool  );
00092         SENF_PARSER_SKIP_BITS ( 1                              );
00093 
00094         SENF_PARSER_FINALIZE( RadiotapPacketParser_RxFlags );
00095     };
00096 
00097     struct RadiotapPacketParser_TxFlags : public PacketParserBase
00098     {
00099 #       include SENF_FIXED_PARSER()
00100 
00101         SENF_PARSER_SKIP_BITS ( 5                              );
00102         SENF_PARSER_BITFIELD  ( txRts,                1, bool  );
00103         SENF_PARSER_BITFIELD  ( txCts,                1, bool  );
00104         SENF_PARSER_BITFIELD  ( fail,                 1, bool  );
00105 
00106         SENF_PARSER_FINALIZE( RadiotapPacketParser_TxFlags );
00107     };
00108 
00126     struct RadiotapPacketParser_Header : public PacketParserBase
00127     {
00128 #       include SENF_FIXED_PARSER()
00129 
00130         /*
00131          * mandatory fields
00132          */
00133         SENF_PARSER_FIELD ( version, UInt8Parser     );
00134         //padding bits, currently unused, it simply aligns the fields onto natural word boundaries.
00135         SENF_PARSER_SKIP  ( 1                        );
00136         SENF_PARSER_FIELD ( length,  UInt16LSBParser );
00137 
00138         SENF_PARSER_PRIVATE_FIELD ( presentFlags, UInt32LSBParser );
00139 
00140         SENF_PARSER_FINALIZE ( RadiotapPacketParser_Header );
00141 
00142         enum PresentIndex {
00143             // Could use the the entries from radiotap.h but I don't know,
00144             // if I want to pollute the global and macro namespace even more ...
00145             TSFT_INDEX              =  0,
00146             FLAGS_INDEX             =  1,
00147             RATE_INDEX              =  2,
00148             CHANNEL_INDEX           =  3,
00149             FHSS_INDEX              =  4,
00150             DBM_ANTSIGNAL_INDEX     =  5,
00151             DBM_ANTNOISE_INDEX      =  6,
00152             LOCK_QUALITY_INDEX      =  7,
00153             TX_ATTENUATION_INDEX    =  8,
00154             DB_TX_ATTENUATION_INDEX =  9,
00155             DBM_TX_POWER_INDEX      = 10,
00156             ANTENNA_INDEX           = 11,
00157             DB_ANTSIGNAL_INDEX      = 12,
00158             DB_ANTNOISE_INDEX       = 13,
00159             RX_FLAGS_INDEX          = 14,
00160             TX_FLAGS_INDEX          = 15,
00161             RTS_RETRIES_INDEX       = 16,
00162             DATA_RETRIES_INDEX      = 17,
00163 
00164             MAX_INDEX               = 17,
00165 
00166             RADIOTOP_NS_INDEX       = 29,
00167             VENDOR_NS_INDEX         = 30,
00168             EXTENDED_BITMASK_INDEX  = 31
00169         };
00170 
00171         enum PresentFlag {
00172             TSFT_FLAG               = (1<<TSFT_INDEX),
00173             FLAGS_FLAG              = (1<<FLAGS_INDEX),
00174             RATE_FLAG               = (1<<RATE_INDEX),
00175             CHANNEL_FLAG            = (1<<CHANNEL_INDEX),
00176             FHSS_FLAG               = (1<<FHSS_INDEX),
00177             DBM_ANTSIGNAL_FLAG      = (1<<DBM_ANTSIGNAL_INDEX),
00178             DBM_ANTNOISE_FLAG       = (1<<DBM_ANTNOISE_INDEX),
00179             LOCK_QUALITY_FLAG       = (1<<LOCK_QUALITY_INDEX),
00180             TX_ATTENUATION_FLAG     = (1<<TX_ATTENUATION_INDEX),
00181             DB_TX_ATTENUATION_FLAG  = (1<<DB_TX_ATTENUATION_INDEX),
00182             DBM_TX_POWER_FLAG       = (1<<DBM_TX_POWER_INDEX),
00183             ANTENNA_FLAG            = (1<<ANTENNA_INDEX),
00184             DB_ANTSIGNAL_FLAG       = (1<<DB_ANTSIGNAL_INDEX),
00185             DB_ANTNOISE_FLAG        = (1<<DB_ANTNOISE_INDEX),
00186             RX_FLAGS_FLAG           = (1<<RX_FLAGS_INDEX),
00187             TX_FLAGS_FLAG           = (1<<TX_FLAGS_INDEX),
00188             RTS_RETRIES_FLAG        = (1<<RTS_RETRIES_INDEX),
00189             DATA_RETRIES_FLAG       = (1<<DATA_RETRIES_INDEX),
00190 
00191             RADIOTOP_NS_FLAG        = (1<<RADIOTOP_NS_INDEX),
00192             VENDOR_NS_FLAG          = (1<<VENDOR_NS_INDEX),
00193             EXTENDED_BITMASK_FLAG   = (1<<EXTENDED_BITMASK_INDEX)
00194         };
00195 
00196         static unsigned const FIELD_SIZE[MAX_INDEX+2];
00197     };
00198 
00199     struct RadiotapPacketParser_FrameType : public PacketParserBase
00200     {
00201 #       include SENF_FIXED_PARSER()
00202 
00203         SENF_PARSER_SKIP_BITS(4);
00204         SENF_PARSER_BITFIELD_RO( frameType, 2, unsigned );
00205         SENF_PARSER_SKIP_BITS(2);
00206 
00207         SENF_PARSER_FINALIZE(RadiotapPacketParser_FrameType);
00208     };
00209 
00210     struct RadiotapPacketParser : public RadiotapPacketParser_Header
00211     {
00212         RadiotapPacketParser(data_iterator i, state_type s);
00213 
00214         static const size_type init_bytes = RadiotapPacketParser_Header::fixed_bytes;
00215 
00216         size_type bytes() const;
00217 
00218         //-////////////////////////////////////////////////////////////////////////
00219 
00220 #       define FIELD(name,type,index)                                   \
00221             typedef type name ## _t;                                    \
00222             type name() { return parseField<type>(index); }             \
00223             bool has_ ## name() { return currentTable()[index]; }       \
00224             bool name ## Present() { return has_ ## name(); }           \
00225             type init_ ## name() { initField(index); return name(); }   \
00226             void disable_ ## name() { disableField(index); }
00227 
00228         FIELD( tsft,              UInt64LSBParser,                      TSFT_INDEX              );
00229 
00230         // flags is special: disabling 'flags' must also disable the 'fcs' field
00231         typedef RadiotapPacketParser_Flags flags_t;
00232         flags_t flags() { return parseField<flags_t>(FLAGS_INDEX); }
00233         bool has_flags() { return currentTable()[FLAGS_INDEX]; }
00234         bool flagsPresent() { return has_flags(); }
00235         flags_t init_flags() { initField(FLAGS_INDEX); return flags(); }
00236         void disable_flags() { disable_fcs(); disableField(FLAGS_INDEX); }
00237 
00238         FIELD( rate,              UInt8Parser,                          RATE_INDEX              );
00239         FIELD( channelOptions,    RadiotapPacketParser_ChannelOptions,  CHANNEL_INDEX           );
00240         FIELD( fhss,              UInt16LSBParser,                      FHSS_INDEX              );
00241         FIELD( dbmAntennaSignal,  Int8Parser,                           DBM_ANTSIGNAL_INDEX     );
00242         FIELD( dbmAntennaNoise,   Int8Parser,                           DBM_ANTNOISE_INDEX      );
00243         FIELD( lockQuality,       UInt16LSBParser,                      LOCK_QUALITY_INDEX      );
00244         FIELD( txAttenuation,     UInt16LSBParser,                      TX_ATTENUATION_INDEX    );
00245         FIELD( dbTxAttenuation,   UInt16LSBParser,                      DB_TX_ATTENUATION_INDEX );
00246         FIELD( dbmTxAttenuation,  Int8Parser,                           DBM_TX_POWER_INDEX      );
00247         FIELD( antenna,           UInt8Parser,                          ANTENNA_INDEX           );
00248         FIELD( dbAntennaSignal,   UInt8Parser,                          DB_ANTSIGNAL_INDEX      );
00249         FIELD( dbAntennaNoise,    UInt8Parser,                          DB_ANTNOISE_INDEX       );
00250         FIELD( rxFlags,           RadiotapPacketParser_RxFlags,         RX_FLAGS_INDEX          );
00251         FIELD( txFlags,           RadiotapPacketParser_TxFlags,         TX_FLAGS_INDEX          );
00252         FIELD( rtsRetries,        UInt8Parser,                          RTS_RETRIES_INDEX       );
00253         FIELD( dataRetries,       UInt8Parser,                          DATA_RETRIES_INDEX      );
00254 
00255 #       undef FIELD
00256 
00257         typedef UInt32Parser fcs_t;
00258         UInt32Parser fcs();
00259         bool has_fcs();
00260         UInt32Parser init_fcs();
00261         void disable_fcs();
00262 
00263         unsigned frameType();
00264 
00265     private:
00266         static const size_type fixed_bytes = 0; // hide this member, just in case
00267 
00268         typedef boost::array<size_type,MAX_INDEX+2> OffsetTable;
00269 
00270         //-////////////////////////////////////////////////////////////////////////
00271         // Offset table handling
00272 
00273         static OffsetTable & offsetTable(boost::uint32_t presentFlags);
00274         // Fills the offset table based on a packet
00275         static void parseOffsetTable(boost::uint8_t * data, int maxLength, OffsetTable & table);
00276         // Generate an offset table just from the present flags
00277         static void buildOffsetTable(boost::uint32_t presentFlags, OffsetTable & table);
00278 
00279         //-////////////////////////////////////////////////////////////////////////
00280 
00281         OffsetTable const & currentTable() const;
00282         OffsetTable const & getTable(boost::uint32_t presentFlags) const;
00283 
00284         template <class Parser>
00285         Parser parseField(unsigned index);
00286         void initField(unsigned index);
00287         void disableField(unsigned index);
00288 
00289         size_type calculateSize() const;
00290 
00291         void updatePresentFlags(boost::uint32_t flags);
00292         void insertRemoveBytes(unsigned from, unsigned to, int bytes);
00293 
00294         OffsetTable const * currentTable_;
00295 
00296         friend class RadiotapPacketType;
00297     };
00298 
00312     struct RadiotapPacketType
00313         : public PacketTypeBase,
00314           public PacketTypeMixin<RadiotapPacketType>
00315     {
00316         typedef PacketTypeMixin<RadiotapPacketType> mixin;
00317         typedef ConcretePacket<RadiotapPacketType> packet;
00318         typedef RadiotapPacketParser parser;
00319 
00320         using mixin::initSize;
00321 
00322         static void init(packet p);
00323         static void dump(packet p, std::ostream & os);
00324         static factory_t nextPacketType(packet p);
00325         static optional_range nextPacketRange(packet p);
00326     };
00327 
00328     typedef ConcretePacket<RadiotapPacketType> RadiotapPacket;
00329 }
00330 
00331 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00332 #include "RadiotapPacket.cci"
00333 //#include "RadiotapPacket.ct"
00334 #include "RadiotapPacket.cti"
00335 #endif
00336 
00337 
00338 // Local Variables:
00339 // mode: c++
00340 // fill-column: 100
00341 // comment-column: 40
00342 // c-file-style: "senf"
00343 // indent-tabs-mode: nil
00344 // ispell-local-dictionary: "american"
00345 // compile-command: "scons -u test"
00346 // End:

Contact: senf-dev@lists.berlios.de | © 2006-2010 Fraunhofer Institute for Open Communication Systems, Network Research