4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Christian Niephaus <cni@berlios.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 // Definition of RadiotapPacket non-inline non-template functions
25 #include "RadiotapPacket.hh"
26 //#include "RadiotapPacket.ih"
29 #include "WLANPacket.hh"
30 #include <boost/io/ios_state.hpp>
33 # include "radiotap/radiotap_iter.h"
37 ///////////////////////////////cc.p//////////////////////////////////////
39 prefix_ void senf::RadiotapPacketParser::fillOffsetTable(boost::uint8_t * data, int maxLength,
42 struct ieee80211_radiotap_iterator iter;
43 ieee80211_radiotap_iterator_init(&iter,
44 (struct ieee80211_radiotap_header *)data,
47 while (ieee80211_radiotap_iterator_next(&iter)==0) {
48 if (iter.is_radiotap_ns &&
49 iter.this_arg_index <= int(senf::RadiotapPacketParser::MAX_INDEX)) {
50 table[iter.this_arg_index] = iter.this_arg - data;
51 std::cerr << ">> " << iter.this_arg_index << " " << table[iter.this_arg_index] << "\n";
54 table[MAX_INDEX+1] = iter.this_arg - data + iter.this_arg_size;
55 std::cerr << ">> size " << table[MAX_INDEX+1] << "\n";
58 prefix_ senf::RadiotapPacketParser::OffsetTable const &
59 senf::RadiotapPacketParser::offsetTable(boost::uint32_t presentFlags)
61 typedef std::map<boost::uint32_t, OffsetTable> OffsetMap;
62 static OffsetMap offsetMap;
64 OffsetMap::iterator i (offsetMap.find(presentFlags));
65 if (i == offsetMap.end()) {
67 fillOffsetTable(&(*data().begin()), data().size(), table);
68 i = offsetMap.insert(std::make_pair(presentFlags, table)).first;
74 #define DUMP_OPTIONAL_FIELD(name, sign, desc) \
75 if (p->name ## Present()) \
76 os << senf::fieldName(desc) << sign(p->name()) \
79 prefix_ void senf::RadiotapPacketType::dump(packet p, std::ostream &os)
81 boost::io::ios_all_saver ias(os);
83 << senf::fieldName("version") << unsigned(p->version()) << "\n"
84 << senf::fieldName("length") << unsigned(p->length()) << "\n";
85 // TODO: flags, channelOptions
86 DUMP_OPTIONAL_FIELD( tsft, unsigned, "MAC timestamp" );
87 DUMP_OPTIONAL_FIELD( rate, unsigned, "rate" );
88 DUMP_OPTIONAL_FIELD( fhss, unsigned, "FHSS" );
89 DUMP_OPTIONAL_FIELD( dbmAntennaSignal, signed, "antenna signal (dBm)" );
90 DUMP_OPTIONAL_FIELD( dbmAntennaNoise, signed, "antenna noise (dBm)" );
91 DUMP_OPTIONAL_FIELD( lockQuality, unsigned, "lock quality" );
92 DUMP_OPTIONAL_FIELD( txAttenuation, unsigned, "tx attenuation" );
93 DUMP_OPTIONAL_FIELD( dbTxAttenuation, unsigned, "tx attenuation (dB)" );
94 DUMP_OPTIONAL_FIELD( dbmTxAttenuation, signed, "tx attenuation (dBm)" );
95 DUMP_OPTIONAL_FIELD( antenna, unsigned, "antenna" );
96 DUMP_OPTIONAL_FIELD( dbAntennaSignal, unsigned, "antenna signal (dB)" );
97 DUMP_OPTIONAL_FIELD( dbAntennaNoise, unsigned, "antenna noise (dB)" );
98 DUMP_OPTIONAL_FIELD( headerFcs, unsigned, "FCS (in header)" );
99 if (p->flagsPresent() && p->flags().fcsAtEnd())
100 os << senf::fieldName("FCS (at end)") << unsigned(p->fcs()) << "\n";
103 #undef DUMP_OPTIONAL_FIELD
105 prefix_ void senf::RadiotapPacketType::finalize(packet p)
107 p->length() << p->calculateSize();
110 prefix_ senf::PacketInterpreterBase::factory_t senf::RadiotapPacketType::nextPacketType(packet p)
112 static factory_t frameTypeFactory[] = { WLANPacket_MgtFrame::factory(),
113 WLANPacket_CtrlFrame::factory(),
114 WLANPacket_DataFrame::factory(),
116 return frameTypeFactory[p->frameType()];
119 prefix_ senf::RadiotapPacketType::optional_range
120 senf::RadiotapPacketType::nextPacketRange(packet p)
122 size_type h (senf::bytes(p.parser()));
123 size_type t (p->flagsPresent() && p->flags().fcsAtEnd() ? 4 : 0);
124 return p.size() < h+t
126 : optional_range( range(p.data().begin() + h, p.data().end() - t) );
129 ///////////////////////////////cc.e////////////////////////////////////////
136 // c-file-style: "senf"
137 // indent-tabs-mode: nil
138 // ispell-local-dictionary: "american"
139 // compile-command: "scons -u test"
140 // comment-column: 40