A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
radiotap-header.cc
Go to the documentation of this file.
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 <cmath>
23
#include "ns3/log.h"
24
#include "
radiotap-header.h
"
25
26
NS_LOG_COMPONENT_DEFINE
(
"RadiotapHeader"
);
27
28
namespace
ns3 {
29
30
NS_OBJECT_ENSURE_REGISTERED
(RadiotapHeader);
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
{
48
static
TypeId
tid =
TypeId
(
"ns3::RadiotapHeader"
)
49
.
SetParent
<
Header
> ()
50
.AddConstructor<RadiotapHeader> ()
51
;
52
return
tid;
53
}
54
55
TypeId
56
RadiotapHeader::GetInstanceTypeId
(
void
)
const
57
{
58
return
GetTypeId
();
59
}
60
61
uint32_t
62
RadiotapHeader::GetSerializedSize
(
void
)
const
63
{
64
NS_LOG_FUNCTION
(
this
);
65
return
m_length
;
66
}
67
68
void
69
RadiotapHeader::Serialize
(
Buffer::Iterator
start
)
const
70
{
71
NS_LOG_FUNCTION
(
this
<< &start);
72
73
start.
WriteU8
(0);
// major version of radiotap header
74
start.
WriteU8
(0);
// pad field
75
start.
WriteU16
(
m_length
);
// entire length of radiotap data + header
76
start.
WriteU32
(
m_present
);
// bits describing which fields follow header
77
78
//
79
// Time Synchronization Function Timer (when the first bit of the MPDU
80
// arrived at the MAC)
81
//
82
if
(
m_present
&
RADIOTAP_TSFT
)
// bit 0
83
{
84
start.
WriteU64
(
m_tsft
);
85
}
86
87
//
88
// Properties of transmitted and received frames.
89
//
90
if
(
m_present
&
RADIOTAP_FLAGS
)
// bit 1
91
{
92
start.
WriteU8
(
m_flags
);
93
}
94
95
//
96
// TX/RX data rate in units of 500 kbps
97
//
98
if
(
m_present
&
RADIOTAP_RATE
)
// bit 2
99
{
100
start.
WriteU8
(
m_rate
);
101
}
102
103
//
104
// Tx/Rx frequency in MHz, followed by flags.
105
//
106
if
(
m_present
&
RADIOTAP_CHANNEL
)
// bit 3
107
{
108
start.
WriteU16
(
m_channelFreq
);
109
start.
WriteU16
(
m_channelFlags
);
110
}
111
112
//
113
// RF signal power at the antenna, decibel difference from an arbitrary, fixed
114
// reference.
115
//
116
if
(
m_present
&
RADIOTAP_DBM_ANTSIGNAL
)
// bit 5
117
{
118
start.
WriteU8
(
m_antennaSignal
);
119
}
120
121
//
122
// RF noise power at the antenna, decibel difference from an arbitrary, fixed
123
// reference.
124
//
125
if
(
m_present
&
RADIOTAP_DBM_ANTNOISE
)
// bit 6
126
{
127
start.
WriteU8
(
m_antennaNoise
);
128
}
129
}
130
131
uint32_t
132
RadiotapHeader::Deserialize
(
Buffer::Iterator
start
)
133
{
134
NS_LOG_FUNCTION
(
this
<< &start);
135
136
uint8_t tmp = start.
ReadU8
();
// major version of radiotap header
137
NS_ASSERT_MSG
(tmp == 0x00,
"RadiotapHeader::Deserialize(): Unexpected major version"
);
138
start.
ReadU8
();
// pad field
139
140
m_length
= start.
ReadU16
();
// entire length of radiotap data + header
141
m_present
= start.
ReadU32
();
// bits describing which fields follow header
142
143
uint32_t bytesRead = 8;
144
145
//
146
// Time Synchronization Function Timer (when the first bit of the MPDU arrived at the MAC)
147
//
148
if
(
m_present
&
RADIOTAP_TSFT
)
// bit 0
149
{
150
m_tsft
= start.
ReadU64
();
151
bytesRead += 8;
152
}
153
154
//
155
// Properties of transmitted and received frames.
156
//
157
if
(
m_present
&
RADIOTAP_FLAGS
)
// bit 1
158
{
159
m_flags
= start.
ReadU8
();
160
++bytesRead;
161
}
162
163
//
164
// TX/RX data rate in units of 500 kbps
165
//
166
if
(
m_present
&
RADIOTAP_RATE
)
// bit 2
167
{
168
m_rate
= start.
ReadU8
();
169
++bytesRead;
170
}
171
172
//
173
// Tx/Rx frequency in MHz, followed by flags.
174
//
175
if
(
m_present
&
RADIOTAP_CHANNEL
)
// bit 3
176
{
177
m_channelFreq
= start.
ReadU16
();
178
m_channelFlags
= start.
ReadU16
();
179
bytesRead += 4;
180
}
181
182
//
183
// The hop set and pattern for frequency-hopping radios. We don't need it but
184
// still need to account for it.
185
//
186
if
(
m_present
&
RADIOTAP_FHSS
)
// bit 4
187
{
188
start.
ReadU8
();
189
++bytesRead;
190
}
191
192
//
193
// RF signal power at the antenna, decibel difference from an arbitrary, fixed
194
// reference.
195
//
196
if
(
m_present
&
RADIOTAP_DBM_ANTSIGNAL
)
// bit 5
197
{
198
m_antennaSignal
= start.
ReadU8
();
199
++bytesRead;
200
}
201
202
//
203
// RF noise power at the antenna, decibel difference from an arbitrary, fixed
204
// reference.
205
//
206
if
(
m_present
&
RADIOTAP_DBM_ANTNOISE
)
// bit 6
207
{
208
m_antennaNoise
= start.
ReadU8
();
209
++bytesRead;
210
}
211
212
NS_ASSERT_MSG
(
m_length
== bytesRead,
"RadiotapHeader::Deserialize(): expected and actual lengths inconsistent"
);
213
return
bytesRead;
214
}
215
216
void
217
RadiotapHeader::Print
(std::ostream &os)
const
218
{
219
NS_LOG_FUNCTION
(
this
<< &os);
220
os <<
" tsft="
<<
m_tsft
221
<<
" flags="
<< std::hex <<
m_flags
<< std::dec
222
<<
" rate="
<< (uint16_t)
m_rate
223
<<
" freq="
<<
m_channelFreq
224
<<
" chflags="
<< std::hex << (uint32_t)
m_channelFlags
<< std::dec
225
<<
" signal="
<< (int16_t)
m_antennaSignal
226
<<
" noise="
<< (int16_t)
m_antennaNoise
;
227
}
228
229
void
230
RadiotapHeader::SetTsft
(uint64_t value)
231
{
232
NS_LOG_FUNCTION
(
this
<< value);
233
m_tsft
= value;
234
235
if
(!(
m_present
&
RADIOTAP_TSFT
))
236
{
237
m_present
|=
RADIOTAP_TSFT
;
238
m_length
+= 8;
239
}
240
241
NS_LOG_LOGIC
(
this
<<
" m_length="
<<
m_length
<<
" m_present=0x"
<< std::hex <<
m_present
<< std::dec);
242
}
243
244
uint64_t
245
RadiotapHeader::GetTsft
()
const
246
{
247
NS_LOG_FUNCTION
(
this
);
248
return
m_tsft
;
249
}
250
251
void
252
RadiotapHeader::SetFrameFlags
(uint8_t flags)
253
{
254
NS_LOG_FUNCTION
(
this
<< static_cast<uint32_t> (flags));
255
m_flags
= flags;
256
257
if
(!(
m_present
&
RADIOTAP_FLAGS
))
258
{
259
m_present
|=
RADIOTAP_FLAGS
;
260
m_length
+= 1;
261
}
262
263
NS_LOG_LOGIC
(
this
<<
" m_length="
<<
m_length
<<
" m_present=0x"
<< std::hex <<
m_present
<< std::dec);
264
}
265
266
uint8_t
267
RadiotapHeader::GetFrameFlags
(
void
)
const
268
{
269
NS_LOG_FUNCTION
(
this
);
270
return
m_flags
;
271
}
272
273
void
274
RadiotapHeader::SetRate
(uint8_t rate)
275
{
276
NS_LOG_FUNCTION
(
this
<< static_cast<uint32_t> (rate));
277
m_rate
= rate;
278
279
if
(!(
m_present
&
RADIOTAP_RATE
))
280
{
281
m_present
|=
RADIOTAP_RATE
;
282
m_length
+= 1;
283
}
284
285
NS_LOG_LOGIC
(
this
<<
" m_length="
<<
m_length
<<
" m_present=0x"
<< std::hex <<
m_present
<< std::dec);
286
}
287
288
uint8_t
289
RadiotapHeader::GetRate
(
void
)
const
290
{
291
NS_LOG_FUNCTION
(
this
);
292
return
m_rate
;
293
}
294
295
void
296
RadiotapHeader::SetChannelFrequencyAndFlags
(uint16_t frequency, uint16_t flags)
297
{
298
NS_LOG_FUNCTION
(
this
<< frequency << flags);
299
m_channelFreq
= frequency;
300
m_channelFlags
= flags;
301
302
if
(!(
m_present
&
RADIOTAP_CHANNEL
))
303
{
304
m_present
|=
RADIOTAP_CHANNEL
;
305
m_length
+= 4;
306
}
307
308
NS_LOG_LOGIC
(
this
<<
" m_length="
<<
m_length
<<
" m_present=0x"
<< std::hex <<
m_present
<< std::dec);
309
}
310
311
uint16_t
312
RadiotapHeader::GetChannelFrequency
(
void
)
const
313
{
314
NS_LOG_FUNCTION
(
this
);
315
return
m_channelFreq
;
316
}
317
318
uint16_t
319
RadiotapHeader::GetChannelFlags
(
void
)
const
320
{
321
NS_LOG_FUNCTION
(
this
);
322
return
m_channelFlags
;
323
}
324
325
void
326
RadiotapHeader::SetAntennaSignalPower
(
double
signal)
327
{
328
NS_LOG_FUNCTION
(
this
<< signal);
329
330
if
(!(
m_present
&
RADIOTAP_DBM_ANTSIGNAL
))
331
{
332
m_present
|=
RADIOTAP_DBM_ANTSIGNAL
;
333
m_length
+= 1;
334
}
335
if
(signal > 127)
336
{
337
m_antennaSignal
= 127;
338
}
339
else
if
(signal < -128)
340
{
341
m_antennaSignal
= -128;
342
}
343
else
344
{
345
m_antennaSignal
=
static_cast<
int8_t
>
(floor (signal + 0.5));
346
}
347
348
NS_LOG_LOGIC
(
this
<<
" m_length="
<<
m_length
<<
" m_present=0x"
<< std::hex <<
m_present
<< std::dec);
349
}
350
351
uint8_t
352
RadiotapHeader::GetAntennaSignalPower
(
void
)
const
353
{
354
NS_LOG_FUNCTION
(
this
);
355
return
m_antennaSignal
;
356
}
357
358
void
359
RadiotapHeader::SetAntennaNoisePower
(
double
noise)
360
{
361
NS_LOG_FUNCTION
(
this
<< noise);
362
363
if
(!(
m_present
&
RADIOTAP_DBM_ANTNOISE
))
364
{
365
m_present
|=
RADIOTAP_DBM_ANTNOISE
;
366
m_length
+= 1;
367
}
368
if
(noise > 127.0)
369
{
370
m_antennaNoise
= 127;
371
}
372
else
if
(noise < -128.0)
373
{
374
m_antennaNoise
= -128;
375
}
376
else
377
{
378
m_antennaNoise
=
static_cast<
int8_t
>
(floor (noise + 0.5));
379
}
380
381
NS_LOG_LOGIC
(
this
<<
" m_length="
<<
m_length
<<
" m_present=0x"
<< std::hex <<
m_present
<< std::dec);
382
}
383
384
uint8_t
385
RadiotapHeader::GetAntennaNoisePower
(
void
)
const
386
{
387
NS_LOG_FUNCTION
(
this
);
388
return
m_antennaNoise
;
389
}
390
391
}
// namespace ns3
src
network
utils
radiotap-header.cc
Generated on Tue May 14 2013 11:08:31 for ns-3 by
1.8.1.2