author | Tom Henderson <tomh@tomh.org> |
Mon, 21 Feb 2011 09:11:37 -0800 | |
changeset 6823 | a27f86fb4e55 |
parent 6393 | src/node/radiotap-header.cc@f7e1f9dfa08d |
child 7027 | 169e09e9428d |
permissions | -rw-r--r-- |
6009 | 1 |
/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ |
2 |
/* |
|
3 |
* Copyright (c) 2009 CTTC |
|
4 |
* |
|
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; |
|
8 |
* |
|
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. |
|
13 |
* |
|
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 |
|
17 |
* |
|
18 |
* Author: Nicola Baldo <nbaldo@cttc.es> |
|
19 |
*/ |
|
20 |
||
21 |
#include <iomanip> |
|
22 |
#include <math.h> |
|
23 |
#include "ns3/log.h" |
|
24 |
#include "radiotap-header.h" |
|
25 |
||
26 |
NS_LOG_COMPONENT_DEFINE ("RadiotapHeader"); |
|
27 |
||
28 |
namespace ns3 { |
|
6393
f7e1f9dfa08d
ensure objects are regsitered
Josh Pelkey <jpelkey@gatech.edu>
parents:
6036
diff
changeset
|
29 |
|
f7e1f9dfa08d
ensure objects are regsitered
Josh Pelkey <jpelkey@gatech.edu>
parents:
6036
diff
changeset
|
30 |
NS_OBJECT_ENSURE_REGISTERED (RadiotapHeader); |
6009 | 31 |
|
32 |
RadiotapHeader::RadiotapHeader() |
|
33 |
: m_length(8), |
|
34 |
m_present(0), |
|
35 |
m_tsft(0), |
|
36 |
m_flags(FRAME_FLAG_NONE), |
|
37 |
m_rate(0), |
|
38 |
m_channelFreq(0), |
|
39 |
m_channelFlags(CHANNEL_FLAG_NONE), |
|
40 |
m_antennaSignal(0), |
|
41 |
m_antennaNoise(0) |
|
42 |
{ |
|
43 |
NS_LOG_FUNCTION (this); |
|
44 |
} |
|
45 |
||
46 |
TypeId RadiotapHeader::GetTypeId (void) |
|
47 |
{ |
|
6393
f7e1f9dfa08d
ensure objects are regsitered
Josh Pelkey <jpelkey@gatech.edu>
parents:
6036
diff
changeset
|
48 |
static TypeId tid = TypeId ("ns3::RadiotapHeader") |
6009 | 49 |
.SetParent<Header> () |
50 |
.AddConstructor<RadiotapHeader> () |
|
51 |
; |
|
52 |
return tid; |
|
53 |
} |
|
54 |
||
55 |
TypeId |
|
56 |
RadiotapHeader::GetInstanceTypeId (void) const |
|
57 |
{ |
|
58 |
NS_LOG_FUNCTION (this); |
|
59 |
return GetTypeId (); |
|
60 |
} |
|
61 |
||
62 |
uint32_t |
|
63 |
RadiotapHeader::GetSerializedSize (void) const |
|
64 |
{ |
|
65 |
NS_LOG_FUNCTION (this); |
|
66 |
return m_length; |
|
67 |
} |
|
68 |
||
69 |
void |
|
70 |
RadiotapHeader::Serialize (Buffer::Iterator start) const |
|
71 |
{ |
|
72 |
NS_LOG_FUNCTION (this); |
|
73 |
||
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 |
|
78 |
||
79 |
// |
|
80 |
// Time Synchronization Function Timer (when the first bit of the MPDU |
|
81 |
// arrived at the MAC) |
|
82 |
// |
|
83 |
if (m_present & RADIOTAP_TSFT) // bit 0 |
|
84 |
{ |
|
85 |
start.WriteU64 (m_tsft); |
|
86 |
} |
|
87 |
||
88 |
// |
|
89 |
// Properties of transmitted and received frames. |
|
90 |
// |
|
91 |
if (m_present & RADIOTAP_FLAGS) // bit 1 |
|
92 |
{ |
|
93 |
start.WriteU8 (m_flags); |
|
94 |
} |
|
95 |
||
96 |
// |
|
97 |
// TX/RX data rate in units of 500 kbps |
|
98 |
// |
|
99 |
if (m_present & RADIOTAP_RATE) // bit 2 |
|
100 |
{ |
|
101 |
start.WriteU8 (m_rate); |
|
102 |
} |
|
103 |
||
104 |
// |
|
105 |
// Tx/Rx frequency in MHz, followed by flags. |
|
106 |
// |
|
107 |
if (m_present & RADIOTAP_CHANNEL) // bit 3 |
|
108 |
{ |
|
109 |
start.WriteU16 (m_channelFreq); |
|
110 |
start.WriteU16 (m_channelFlags); |
|
111 |
} |
|
112 |
||
113 |
// |
|
114 |
// RF signal power at the antenna, decibel difference from an arbitrary, fixed |
|
115 |
// reference. |
|
116 |
// |
|
117 |
if (m_present & RADIOTAP_DBM_ANTSIGNAL) // bit 5 |
|
118 |
{ |
|
119 |
start.WriteU8 (m_antennaSignal); |
|
120 |
} |
|
121 |
||
122 |
// |
|
123 |
// RF noise power at the antenna, decibel difference from an arbitrary, fixed |
|
124 |
// reference. |
|
125 |
// |
|
126 |
if (m_present & RADIOTAP_DBM_ANTNOISE) // bit 6 |
|
127 |
{ |
|
128 |
start.WriteU8 (m_antennaNoise); |
|
129 |
} |
|
130 |
} |
|
131 |
||
132 |
uint32_t |
|
133 |
RadiotapHeader::Deserialize (Buffer::Iterator start) |
|
134 |
{ |
|
135 |
NS_LOG_FUNCTION (this); |
|
136 |
||
6036 | 137 |
uint8_t __attribute__ ((unused)) tmp = start.ReadU8 (); // major version of radiotap header |
6009 | 138 |
NS_ASSERT_MSG (tmp == 0x00, "RadiotapHeader::Deserialize(): Unexpected major version"); |
139 |
start.ReadU8 (); // pad field |
|
140 |
||
141 |
m_length = start.ReadU16 (); // entire length of radiotap data + header |
|
142 |
m_present = start.ReadU32 (); // bits describing which fields follow header |
|
143 |
||
144 |
uint32_t bytesRead = 8; |
|
145 |
||
146 |
// |
|
147 |
// Time Synchronization Function Timer (when the first bit of the MPDU arrived at the MAC) |
|
148 |
// |
|
149 |
if (m_present & RADIOTAP_TSFT) // bit 0 |
|
150 |
{ |
|
151 |
m_tsft = start.ReadU64(); |
|
152 |
bytesRead += 8; |
|
153 |
} |
|
154 |
||
155 |
// |
|
156 |
// Properties of transmitted and received frames. |
|
157 |
// |
|
158 |
if (m_present & RADIOTAP_FLAGS) // bit 1 |
|
159 |
{ |
|
160 |
m_flags = start.ReadU8(); |
|
161 |
++bytesRead; |
|
162 |
} |
|
163 |
||
164 |
// |
|
165 |
// TX/RX data rate in units of 500 kbps |
|
166 |
// |
|
167 |
if (m_present & RADIOTAP_RATE) // bit 2 |
|
168 |
{ |
|
169 |
m_rate = start.ReadU8(); |
|
170 |
++bytesRead; |
|
171 |
} |
|
172 |
||
173 |
// |
|
174 |
// Tx/Rx frequency in MHz, followed by flags. |
|
175 |
// |
|
176 |
if (m_present & RADIOTAP_CHANNEL) // bit 3 |
|
177 |
{ |
|
178 |
m_channelFreq = start.ReadU16(); |
|
179 |
m_channelFlags = start.ReadU16(); |
|
180 |
bytesRead += 4; |
|
181 |
} |
|
182 |
||
183 |
// |
|
184 |
// The hop set and pattern for frequency-hopping radios. We don't need it but |
|
185 |
// still need to account for it. |
|
186 |
// |
|
187 |
if (m_present & RADIOTAP_FHSS) // bit 4 |
|
188 |
{ |
|
189 |
start.ReadU8(); |
|
190 |
++bytesRead; |
|
191 |
} |
|
192 |
||
193 |
// |
|
194 |
// RF signal power at the antenna, decibel difference from an arbitrary, fixed |
|
195 |
// reference. |
|
196 |
// |
|
197 |
if (m_present & RADIOTAP_DBM_ANTSIGNAL) // bit 5 |
|
198 |
{ |
|
199 |
m_antennaSignal = start.ReadU8(); |
|
200 |
++bytesRead; |
|
201 |
} |
|
202 |
||
203 |
// |
|
204 |
// RF noise power at the antenna, decibel difference from an arbitrary, fixed |
|
205 |
// reference. |
|
206 |
// |
|
207 |
if (m_present & RADIOTAP_DBM_ANTNOISE) // bit 6 |
|
208 |
{ |
|
209 |
m_antennaNoise = start.ReadU8(); |
|
210 |
++bytesRead; |
|
211 |
} |
|
212 |
||
213 |
NS_ASSERT_MSG(m_length == bytesRead, "RadiotapHeader::Deserialize(): expected and actual lengths inconsistent"); |
|
214 |
return bytesRead; |
|
215 |
} |
|
216 |
||
217 |
void |
|
218 |
RadiotapHeader::Print (std::ostream &os) const |
|
219 |
{ |
|
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; |
|
228 |
} |
|
229 |
||
230 |
void |
|
231 |
RadiotapHeader::SetTsft (uint64_t value) |
|
232 |
{ |
|
233 |
NS_LOG_FUNCTION (this << value); |
|
234 |
m_tsft = value; |
|
235 |
||
236 |
if (!(m_present & RADIOTAP_TSFT)) |
|
237 |
{ |
|
238 |
m_present |= RADIOTAP_TSFT; |
|
239 |
m_length += 8; |
|
240 |
} |
|
241 |
||
242 |
NS_LOG_LOGIC (this << " m_length=" << m_length << " m_present=0x" << std::hex << m_present << std::dec); |
|
243 |
} |
|
244 |
||
245 |
uint64_t |
|
246 |
RadiotapHeader::GetTsft () const |
|
247 |
{ |
|
248 |
NS_LOG_FUNCTION (this); |
|
249 |
return m_tsft; |
|
250 |
} |
|
251 |
||
252 |
void |
|
253 |
RadiotapHeader::SetFrameFlags (uint8_t flags) |
|
254 |
{ |
|
255 |
NS_LOG_FUNCTION (this << flags); |
|
256 |
m_flags = flags; |
|
257 |
||
258 |
if (!(m_present & RADIOTAP_FLAGS)) |
|
259 |
{ |
|
260 |
m_present |= RADIOTAP_FLAGS; |
|
261 |
m_length += 1; |
|
262 |
} |
|
263 |
||
264 |
NS_LOG_LOGIC (this << " m_length=" << m_length << " m_present=0x" << std::hex << m_present << std::dec); |
|
265 |
} |
|
266 |
||
267 |
uint8_t |
|
268 |
RadiotapHeader::GetFrameFlags (void) const |
|
269 |
{ |
|
270 |
NS_LOG_FUNCTION (this); |
|
271 |
return m_flags; |
|
272 |
} |
|
273 |
||
274 |
void |
|
275 |
RadiotapHeader::SetRate (uint8_t rate) |
|
276 |
{ |
|
277 |
NS_LOG_FUNCTION (this << rate); |
|
278 |
m_rate = rate; |
|
279 |
||
280 |
if (!(m_present & RADIOTAP_RATE)) |
|
281 |
{ |
|
282 |
m_present |= RADIOTAP_RATE; |
|
283 |
m_length += 1; |
|
284 |
} |
|
285 |
||
286 |
NS_LOG_LOGIC (this << " m_length=" << m_length << " m_present=0x" << std::hex << m_present << std::dec); |
|
287 |
} |
|
288 |
||
289 |
uint8_t |
|
290 |
RadiotapHeader::GetRate (void) const |
|
291 |
{ |
|
292 |
NS_LOG_FUNCTION (this); |
|
293 |
return m_rate; |
|
294 |
} |
|
295 |
||
296 |
void |
|
297 |
RadiotapHeader::SetChannelFrequencyAndFlags (uint16_t frequency, uint16_t flags) |
|
298 |
{ |
|
299 |
NS_LOG_FUNCTION (this << frequency << flags); |
|
300 |
m_channelFreq = frequency; |
|
301 |
m_channelFlags = flags; |
|
302 |
||
303 |
if (!(m_present & RADIOTAP_CHANNEL)) |
|
304 |
{ |
|
305 |
m_present |= RADIOTAP_CHANNEL; |
|
306 |
m_length += 4; |
|
307 |
} |
|
308 |
||
309 |
NS_LOG_LOGIC (this << " m_length=" << m_length << " m_present=0x" << std::hex << m_present << std::dec); |
|
310 |
} |
|
311 |
||
312 |
uint16_t |
|
313 |
RadiotapHeader::GetChannelFrequency (void) const |
|
314 |
{ |
|
315 |
NS_LOG_FUNCTION (this); |
|
316 |
return m_channelFreq; |
|
317 |
} |
|
318 |
||
319 |
uint16_t |
|
320 |
RadiotapHeader::GetChannelFlags (void) const |
|
321 |
{ |
|
322 |
NS_LOG_FUNCTION (this); |
|
323 |
return m_channelFlags; |
|
324 |
} |
|
325 |
||
326 |
void |
|
327 |
RadiotapHeader::SetAntennaSignalPower (int8_t signal) |
|
328 |
{ |
|
329 |
NS_LOG_FUNCTION (this << signal); |
|
330 |
m_antennaSignal = signal; |
|
331 |
||
332 |
if (!(m_present & RADIOTAP_DBM_ANTSIGNAL)) |
|
333 |
{ |
|
334 |
m_present |= RADIOTAP_DBM_ANTSIGNAL; |
|
335 |
m_length += 1; |
|
336 |
} |
|
337 |
||
338 |
NS_LOG_LOGIC (this << " m_length=" << m_length << " m_present=0x" << std::hex << m_present << std::dec); |
|
339 |
} |
|
340 |
||
341 |
void |
|
342 |
RadiotapHeader::SetAntennaSignalPower (double signal) |
|
343 |
{ |
|
344 |
NS_LOG_FUNCTION (this << signal); |
|
345 |
||
346 |
if (signal < -128) |
|
347 |
{ |
|
348 |
return SetAntennaSignalPower (static_cast<int8_t> (-128)); |
|
349 |
} |
|
350 |
||
351 |
if (signal > 127) |
|
352 |
{ |
|
353 |
return SetAntennaSignalPower (static_cast<int8_t> (127)); |
|
354 |
} |
|
355 |
||
356 |
SetAntennaSignalPower (static_cast<int8_t> (floor(signal + 0.5))); |
|
357 |
} |
|
358 |
||
359 |
uint8_t |
|
360 |
RadiotapHeader::GetAntennaSignalPower (void) const |
|
361 |
{ |
|
362 |
NS_LOG_FUNCTION (this); |
|
363 |
return m_antennaSignal; |
|
364 |
} |
|
365 |
||
366 |
void |
|
367 |
RadiotapHeader::SetAntennaNoisePower (int8_t noise) |
|
368 |
{ |
|
369 |
NS_LOG_FUNCTION (this << noise); |
|
370 |
m_antennaNoise = noise; |
|
371 |
||
372 |
if (!(m_present & RADIOTAP_DBM_ANTNOISE)) |
|
373 |
{ |
|
374 |
m_present |= RADIOTAP_DBM_ANTNOISE; |
|
375 |
m_length += 1; |
|
376 |
} |
|
377 |
||
378 |
NS_LOG_LOGIC (this << " m_length=" << m_length << " m_present=0x" << std::hex << m_present << std::dec); |
|
379 |
} |
|
380 |
||
381 |
void |
|
382 |
RadiotapHeader::SetAntennaNoisePower (double noise) |
|
383 |
{ |
|
384 |
NS_LOG_FUNCTION (this << noise); |
|
385 |
||
386 |
if (noise < -128) |
|
387 |
{ |
|
388 |
return SetAntennaNoisePower (static_cast<int8_t> (-128)); |
|
389 |
} |
|
390 |
||
391 |
if (noise > 127) |
|
392 |
{ |
|
393 |
return SetAntennaNoisePower (static_cast<int8_t> (127)); |
|
394 |
} |
|
395 |
||
396 |
SetAntennaNoisePower (static_cast<int8_t> (floor(noise + 0.5))); |
|
397 |
} |
|
398 |
||
399 |
uint8_t |
|
400 |
RadiotapHeader::GetAntennaNoisePower (void) const |
|
401 |
{ |
|
402 |
NS_LOG_FUNCTION (this); |
|
403 |
return m_antennaNoise; |
|
404 |
} |
|
405 |
||
406 |
} // namespace ns3 |