1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
3
* Copyright (c) 2009 CTTC
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 2 as
7
* published by the Free Software Foundation;
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Include., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
* Author: Nicola Baldo <nbaldo@cttc.es>
24
#include "radiotap-header.h"
26
NS_LOG_COMPONENT_DEFINE ("RadiotapHeader");
30
NS_OBJECT_ENSURE_REGISTERED (RadiotapHeader);
32
RadiotapHeader::RadiotapHeader()
36
m_flags (FRAME_FLAG_NONE),
39
m_channelFlags (CHANNEL_FLAG_NONE),
43
NS_LOG_FUNCTION (this);
46
TypeId RadiotapHeader::GetTypeId (void)
48
static TypeId tid = TypeId ("ns3::RadiotapHeader")
50
.AddConstructor<RadiotapHeader> ()
56
RadiotapHeader::GetInstanceTypeId (void) const
58
NS_LOG_FUNCTION (this);
63
RadiotapHeader::GetSerializedSize (void) const
65
NS_LOG_FUNCTION (this);
70
RadiotapHeader::Serialize (Buffer::Iterator start) const
72
NS_LOG_FUNCTION (this);
74
start.WriteU8 (0); // major version of radiotap header
75
start.WriteU8 (0); // pad field
76
start.WriteU16 (m_length); // entire length of radiotap data + header
77
start.WriteU32 (m_present); // bits describing which fields follow header
80
// Time Synchronization Function Timer (when the first bit of the MPDU
81
// arrived at the MAC)
83
if (m_present & RADIOTAP_TSFT) // bit 0
85
start.WriteU64 (m_tsft);
89
// Properties of transmitted and received frames.
91
if (m_present & RADIOTAP_FLAGS) // bit 1
93
start.WriteU8 (m_flags);
97
// TX/RX data rate in units of 500 kbps
99
if (m_present & RADIOTAP_RATE) // bit 2
101
start.WriteU8 (m_rate);
105
// Tx/Rx frequency in MHz, followed by flags.
107
if (m_present & RADIOTAP_CHANNEL) // bit 3
109
start.WriteU16 (m_channelFreq);
110
start.WriteU16 (m_channelFlags);
114
// RF signal power at the antenna, decibel difference from an arbitrary, fixed
117
if (m_present & RADIOTAP_DBM_ANTSIGNAL) // bit 5
119
start.WriteU8 (m_antennaSignal);
123
// RF noise power at the antenna, decibel difference from an arbitrary, fixed
126
if (m_present & RADIOTAP_DBM_ANTNOISE) // bit 6
128
start.WriteU8 (m_antennaNoise);
133
RadiotapHeader::Deserialize (Buffer::Iterator start)
135
NS_LOG_FUNCTION (this);
137
uint8_t __attribute__ ((unused)) tmp = start.ReadU8 (); // major version of radiotap header
138
NS_ASSERT_MSG (tmp == 0x00, "RadiotapHeader::Deserialize(): Unexpected major version");
139
start.ReadU8 (); // pad field
141
m_length = start.ReadU16 (); // entire length of radiotap data + header
142
m_present = start.ReadU32 (); // bits describing which fields follow header
144
uint32_t bytesRead = 8;
147
// Time Synchronization Function Timer (when the first bit of the MPDU arrived at the MAC)
149
if (m_present & RADIOTAP_TSFT) // bit 0
151
m_tsft = start.ReadU64 ();
156
// Properties of transmitted and received frames.
158
if (m_present & RADIOTAP_FLAGS) // bit 1
160
m_flags = start.ReadU8 ();
165
// TX/RX data rate in units of 500 kbps
167
if (m_present & RADIOTAP_RATE) // bit 2
169
m_rate = start.ReadU8 ();
174
// Tx/Rx frequency in MHz, followed by flags.
176
if (m_present & RADIOTAP_CHANNEL) // bit 3
178
m_channelFreq = start.ReadU16 ();
179
m_channelFlags = start.ReadU16 ();
184
// The hop set and pattern for frequency-hopping radios. We don't need it but
185
// still need to account for it.
187
if (m_present & RADIOTAP_FHSS) // bit 4
194
// RF signal power at the antenna, decibel difference from an arbitrary, fixed
197
if (m_present & RADIOTAP_DBM_ANTSIGNAL) // bit 5
199
m_antennaSignal = start.ReadU8 ();
204
// RF noise power at the antenna, decibel difference from an arbitrary, fixed
207
if (m_present & RADIOTAP_DBM_ANTNOISE) // bit 6
209
m_antennaNoise = start.ReadU8 ();
213
NS_ASSERT_MSG (m_length == bytesRead, "RadiotapHeader::Deserialize(): expected and actual lengths inconsistent");
218
RadiotapHeader::Print (std::ostream &os) const
220
NS_LOG_FUNCTION (this);
221
os << " tsft=" << m_tsft
222
<< " flags=" << std::hex << m_flags << std::dec
223
<< " rate=" << (uint16_t) m_rate
224
<< " freq=" << m_channelFreq
225
<< " chflags=" << std::hex << (uint32_t)m_channelFlags << std::dec
226
<< " signal=" << (int16_t) m_antennaSignal
227
<< " noise=" << (int16_t) m_antennaNoise;
231
RadiotapHeader::SetTsft (uint64_t value)
233
NS_LOG_FUNCTION (this << value);
236
if (!(m_present & RADIOTAP_TSFT))
238
m_present |= RADIOTAP_TSFT;
242
NS_LOG_LOGIC (this << " m_length=" << m_length << " m_present=0x" << std::hex << m_present << std::dec);
246
RadiotapHeader::GetTsft () const
248
NS_LOG_FUNCTION (this);
253
RadiotapHeader::SetFrameFlags (uint8_t flags)
255
NS_LOG_FUNCTION (this << flags);
258
if (!(m_present & RADIOTAP_FLAGS))
260
m_present |= RADIOTAP_FLAGS;
264
NS_LOG_LOGIC (this << " m_length=" << m_length << " m_present=0x" << std::hex << m_present << std::dec);
268
RadiotapHeader::GetFrameFlags (void) const
270
NS_LOG_FUNCTION (this);
275
RadiotapHeader::SetRate (uint8_t rate)
277
NS_LOG_FUNCTION (this << rate);
280
if (!(m_present & RADIOTAP_RATE))
282
m_present |= RADIOTAP_RATE;
286
NS_LOG_LOGIC (this << " m_length=" << m_length << " m_present=0x" << std::hex << m_present << std::dec);
290
RadiotapHeader::GetRate (void) const
292
NS_LOG_FUNCTION (this);
297
RadiotapHeader::SetChannelFrequencyAndFlags (uint16_t frequency, uint16_t flags)
299
NS_LOG_FUNCTION (this << frequency << flags);
300
m_channelFreq = frequency;
301
m_channelFlags = flags;
303
if (!(m_present & RADIOTAP_CHANNEL))
305
m_present |= RADIOTAP_CHANNEL;
309
NS_LOG_LOGIC (this << " m_length=" << m_length << " m_present=0x" << std::hex << m_present << std::dec);
313
RadiotapHeader::GetChannelFrequency (void) const
315
NS_LOG_FUNCTION (this);
316
return m_channelFreq;
320
RadiotapHeader::GetChannelFlags (void) const
322
NS_LOG_FUNCTION (this);
323
return m_channelFlags;
327
RadiotapHeader::SetAntennaSignalPower (double signal)
329
NS_LOG_FUNCTION (this << signal);
331
if (!(m_present & RADIOTAP_DBM_ANTSIGNAL))
333
m_present |= RADIOTAP_DBM_ANTSIGNAL;
338
m_antennaSignal = 127;
340
else if (signal < -128)
342
m_antennaSignal = -128;
346
m_antennaSignal = static_cast<int8_t> (floor (signal + 0.5));
349
NS_LOG_LOGIC (this << " m_length=" << m_length << " m_present=0x" << std::hex << m_present << std::dec);
353
RadiotapHeader::GetAntennaSignalPower (void) const
355
NS_LOG_FUNCTION (this);
356
return m_antennaSignal;
360
RadiotapHeader::SetAntennaNoisePower (double noise)
362
NS_LOG_FUNCTION (this << noise);
364
if (!(m_present & RADIOTAP_DBM_ANTNOISE))
366
m_present |= RADIOTAP_DBM_ANTNOISE;
371
m_antennaNoise = 127;
373
else if (noise < -128.0)
375
m_antennaNoise = -128;
379
m_antennaNoise = static_cast<int8_t> (floor (noise + 0.5));
382
NS_LOG_LOGIC (this << " m_length=" << m_length << " m_present=0x" << std::hex << m_present << std::dec);
386
RadiotapHeader::GetAntennaNoisePower (void) const
388
NS_LOG_FUNCTION (this);
389
return m_antennaNoise;