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 <math.h>
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
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
137
uint8_t tmp = start.
ReadU8
();
// major version of radiotap header
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
(
double
signal)
328
{
329
NS_LOG_FUNCTION
(
this
<< signal);
330
331
if
(!(
m_present
&
RADIOTAP_DBM_ANTSIGNAL
))
332
{
333
m_present
|=
RADIOTAP_DBM_ANTSIGNAL
;
334
m_length
+= 1;
335
}
336
if
(signal > 127)
337
{
338
m_antennaSignal
= 127;
339
}
340
else
if
(signal < -128)
341
{
342
m_antennaSignal
= -128;
343
}
344
else
345
{
346
m_antennaSignal
=
static_cast<
int8_t
>
(floor (signal + 0.5));
347
}
348
349
NS_LOG_LOGIC
(
this
<<
" m_length="
<<
m_length
<<
" m_present=0x"
<< std::hex <<
m_present
<< std::dec);
350
}
351
352
uint8_t
353
RadiotapHeader::GetAntennaSignalPower
(
void
)
const
354
{
355
NS_LOG_FUNCTION
(
this
);
356
return
m_antennaSignal
;
357
}
358
359
void
360
RadiotapHeader::SetAntennaNoisePower
(
double
noise)
361
{
362
NS_LOG_FUNCTION
(
this
<< noise);
363
364
if
(!(
m_present
&
RADIOTAP_DBM_ANTNOISE
))
365
{
366
m_present
|=
RADIOTAP_DBM_ANTNOISE
;
367
m_length
+= 1;
368
}
369
if
(noise > 127.0)
370
{
371
m_antennaNoise
= 127;
372
}
373
else
if
(noise < -128.0)
374
{
375
m_antennaNoise
= -128;
376
}
377
else
378
{
379
m_antennaNoise
=
static_cast<
int8_t
>
(floor (noise + 0.5));
380
}
381
382
NS_LOG_LOGIC
(
this
<<
" m_length="
<<
m_length
<<
" m_present=0x"
<< std::hex <<
m_present
<< std::dec);
383
}
384
385
uint8_t
386
RadiotapHeader::GetAntennaNoisePower
(
void
)
const
387
{
388
NS_LOG_FUNCTION
(
this
);
389
return
m_antennaNoise
;
390
}
391
392
}
// namespace ns3
src
network
utils
radiotap-header.cc
Generated on Tue Oct 9 2012 16:45:45 for ns-3 by
1.8.1.2