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 memset(&table, 0, sizeof(table));
43 struct ieee80211_radiotap_iterator iter;
44 ieee80211_radiotap_iterator_init(&iter,
45 (struct ieee80211_radiotap_header *)data,
48 while (ieee80211_radiotap_iterator_next(&iter)==0) {
49 if (iter.is_radiotap_ns &&
50 iter.this_arg_index <= int(senf::RadiotapPacketParser::MAX_INDEX))
51 table[iter.this_arg_index] = iter.this_arg - data;
53 table[MAX_INDEX+1] = iter.this_arg - data + iter.this_arg_size;
56 prefix_ senf::RadiotapPacketParser::OffsetTable const &
57 senf::RadiotapPacketParser::offsetTable(boost::uint32_t presentFlags)
59 typedef std::map<boost::uint32_t, OffsetTable> OffsetMap;
60 static OffsetMap offsetMap;
62 OffsetMap::iterator i (offsetMap.find(presentFlags));
63 if (i == offsetMap.end()) {
65 fillOffsetTable(&(*data().begin()), data().size(), table);
66 i = offsetMap.insert(std::make_pair(presentFlags, table)).first;
72 prefix_ void senf::RadiotapPacketType::dump(packet p, std::ostream &os)
74 boost::io::ios_all_saver ias(os);
76 << senf::fieldName("version") << unsigned(p->version()) << '\n'
77 << senf::fieldName("length") << unsigned(p->length()) << '\n';
79 # define DUMP_OPTIONAL_FIELD(name, sign, desc) \
80 if (p->name ## Present()) \
81 os << senf::fieldName(desc) << sign(p->name()) << '\n';
83 DUMP_OPTIONAL_FIELD( tsft, boost::uint64_t, "MAC timestamp" );
85 if (p->flagsPresent()) {
86 os << senf::fieldName("flags");
88 # define DUMP_FLAG(name,desc) if (p->flags().name()) os << desc " "
89 DUMP_FLAG(shortGI, "ShortGI");
90 DUMP_FLAG(badFCS, "BadFCS");
91 DUMP_FLAG(fcsAtEnd, "FCSatEnd");
92 DUMP_FLAG(fragmentation, "Frag");
93 DUMP_FLAG(wep, "WEP");
94 DUMP_FLAG(shortPreamble, "ShortPreamble");
95 DUMP_FLAG(cfp, "CFP");
101 DUMP_OPTIONAL_FIELD( rate, unsigned, "rate" );
103 if (p->channelOptionsPresent()) {
104 os << senf::fieldName("channel frequency")
105 << unsigned(p->channelOptions().freq()) << '\n'
106 << senf::fieldName("channel flags");
108 # define DUMP_FLAG(name,desc) if (p->channelOptions().name()) os << desc " "
109 DUMP_FLAG(flag2ghz, "2GHz");
110 DUMP_FLAG(ofdm, "OFDM");
111 DUMP_FLAG(cck, "CCK");
112 DUMP_FLAG(turbo, "Turbo");
113 DUMP_FLAG(quarterRateChannel, "Rate/4");
114 DUMP_FLAG(halfRateChannel, "Rate/2");
115 DUMP_FLAG(gsm, "GSM");
116 DUMP_FLAG(staticTurbo, "StaticTurbo");
117 DUMP_FLAG(gfsk, "GFSK");
118 DUMP_FLAG(cckOfdm, "CCKOFDM");
119 DUMP_FLAG(passive, "Passive");
120 DUMP_FLAG(flag5ghz, "5GHz");
126 DUMP_OPTIONAL_FIELD( fhss, unsigned, "FHSS" );
127 DUMP_OPTIONAL_FIELD( dbmAntennaSignal, signed, "antenna signal (dBm)" );
128 DUMP_OPTIONAL_FIELD( dbmAntennaNoise, signed, "antenna noise (dBm)" );
129 DUMP_OPTIONAL_FIELD( lockQuality, unsigned, "lock quality" );
130 DUMP_OPTIONAL_FIELD( txAttenuation, unsigned, "tx attenuation" );
131 DUMP_OPTIONAL_FIELD( dbTxAttenuation, unsigned, "tx attenuation (dB)" );
132 DUMP_OPTIONAL_FIELD( dbmTxAttenuation, signed, "tx attenuation (dBm)" );
133 DUMP_OPTIONAL_FIELD( antenna, unsigned, "antenna" );
134 DUMP_OPTIONAL_FIELD( dbAntennaSignal, unsigned, "antenna signal (dB)" );
135 DUMP_OPTIONAL_FIELD( dbAntennaNoise, unsigned, "antenna noise (dB)" );
136 DUMP_OPTIONAL_FIELD( headerFcs, unsigned, "FCS (in header)" );
138 if (p->flagsPresent() && p->flags().fcsAtEnd())
139 os << senf::fieldName("FCS (at end)") << unsigned(p->fcs()) << '\n';
141 # undef DUMP_OPTIONAL_FIELD
145 prefix_ void senf::RadiotapPacketType::finalize(packet p)
147 ///\fixme Is this really correct ? shouldn't I use nextPacket.begin() - begin() here ?
148 p->length() << p->calculateSize();
151 prefix_ senf::PacketInterpreterBase::factory_t senf::RadiotapPacketType::nextPacketType(packet p)
153 static factory_t frameTypeFactory[] = { WLANPacket_MgtFrame::factory(),
154 WLANPacket_CtrlFrame::factory(),
155 WLANPacket_DataFrame::factory(),
157 return frameTypeFactory[p->frameType()];
160 prefix_ senf::RadiotapPacketType::optional_range
161 senf::RadiotapPacketType::nextPacketRange(packet p)
163 size_type h (senf::bytes(p.parser()));
164 size_type t (p->flagsPresent() && p->flags().fcsAtEnd() ? 4 : 0);
165 return p.size() < h+t
167 : optional_range( range(p.data().begin() + h, p.data().end() - t) );
170 ///////////////////////////////cc.e////////////////////////////////////////
177 // c-file-style: "senf"
178 // indent-tabs-mode: nil
179 // ispell-local-dictionary: "american"
180 // compile-command: "scons -u test"
181 // comment-column: 40