13 * |
13 * |
14 * You should have received a copy of the GNU General Public License |
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 |
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 |
16 * Foundation, Include., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
17 * |
17 * |
18 * Author: Nicola Baldo <nbaldo@cttc.es> |
18 * Authors: Nicola Baldo <nbaldo@cttc.es> |
|
19 * Sébastien Deronne <sebastien.deronne@gmail.com> |
19 */ |
20 */ |
20 |
21 |
21 #ifndef RADIOTAP_HEADER_H |
22 #ifndef RADIOTAP_HEADER_H |
22 #define RADIOTAP_HEADER_H |
23 #define RADIOTAP_HEADER_H |
23 |
24 |
24 |
25 |
25 #include <ns3/header.h> |
26 #include <ns3/header.h> |
26 |
27 |
27 namespace ns3 { |
28 namespace ns3 { |
28 |
29 |
29 /** |
30 /** |
30 * @brief Radiotap header implementation |
31 * @brief Radiotap header implementation |
31 * |
32 * |
32 * Radiotap is a de facto standard for 802.11 frame injection and reception. |
33 * Radiotap is a de facto standard for 802.11 frame injection and reception. |
33 * The radiotap header format is a mechanism to supply additional information |
34 * The radiotap header format is a mechanism to supply additional information |
34 * about frames, from the driver to userspace applications such as libpcap, and |
35 * about frames, from the driver to userspace applications such as libpcap, and |
35 * from a userspace application to the driver for transmission. |
36 * from a userspace application to the driver for transmission. |
36 * |
|
37 * @warning the radiotap header specification says that the fields included in |
|
38 * the header should be aligned to their natural size (e.g., 16-bit fields |
|
39 * aligned to 16-bit boundaries, 32-bit fields aligned to 32-bit boundaries, |
|
40 * and so on. This implementation does not enforce this. However, the radiotap |
|
41 * specification enforces an order in which fields have to appear (if they |
|
42 * appear), and this ordering is such that, provided you don't leave gaps, all |
|
43 * fields will end up aligned without the need of inserting padding space. By |
|
44 * the term "gap" I mean not using a field which would appear between two used |
|
45 * fields. Moral: don't leave gaps, or if you do be careful about how you |
|
46 * do it. |
|
47 */ |
37 */ |
48 class RadiotapHeader : public Header |
38 class RadiotapHeader : public Header |
49 { |
39 { |
50 public: |
40 public: |
51 RadiotapHeader(); |
41 RadiotapHeader (); |
52 /** |
42 /** |
53 * \brief Get the type ID. |
43 * \brief Get the type ID. |
54 * \return the object TypeId |
44 * \return the object TypeId |
55 */ |
45 */ |
56 static TypeId GetTypeId (void); |
46 static TypeId GetTypeId (void); |
57 virtual TypeId GetInstanceTypeId (void) const; |
47 virtual TypeId GetInstanceTypeId (void) const; |
58 |
48 |
59 /** |
49 /** |
60 * This method is used by Packet::AddHeader to store the header into the byte |
50 * This method is used by Packet::AddHeader to store the header into the byte |
61 * buffer of a packet. This method returns the number of bytes which are |
51 * buffer of a packet. This method returns the number of bytes which are |
62 * needed to store the header data during a Serialize. |
52 * needed to store the header data during a Serialize. |
63 * |
53 * |
64 * @returns The expected size of the header. |
54 * @returns The expected size of the header. |
65 */ |
55 */ |
66 virtual uint32_t GetSerializedSize (void) const; |
56 virtual uint32_t GetSerializedSize (void) const; |
67 |
57 |
68 /** |
58 /** |
69 * This method is used by Packet::AddHeader to store the header into the byte |
59 * This method is used by Packet::AddHeader to store the header into the byte |
70 * buffer of a packet. The data written is expected to match bit-for-bit the |
60 * buffer of a packet. The data written is expected to match bit-for-bit the |
71 * representation of this header in a real network. |
61 * representation of this header in a real network. |
72 * |
62 * |
73 * @param start An iterator which points to where the header should |
63 * @param start An iterator which points to where the header should |
74 * be written. |
64 * be written. |
75 */ |
65 */ |
76 virtual void Serialize (Buffer::Iterator start) const; |
66 virtual void Serialize (Buffer::Iterator start) const; |
77 |
67 |
78 /** |
68 /** |
79 * This method is used by Packet::RemoveHeader to re-create a header from the |
69 * This method is used by Packet::RemoveHeader to re-create a header from the |
80 * byte buffer of a packet. The data read is expected to match bit-for-bit |
70 * byte buffer of a packet. The data read is expected to match bit-for-bit |
81 * the representation of this header in real networks. |
71 * the representation of this header in real networks. |
82 * |
72 * |
83 * @param start An iterator which points to where the header should |
73 * @param start An iterator which points to where the header should |
84 * written. |
74 * written. |
85 * @returns The number of bytes read. |
75 * @returns The number of bytes read. |
86 */ |
76 */ |
87 virtual uint32_t Deserialize (Buffer::Iterator start); |
77 virtual uint32_t Deserialize (Buffer::Iterator start); |
88 |
78 |
89 /** |
79 /** |
90 * This method is used by Packet::Print to print the content of the header as |
80 * This method is used by Packet::Print to print the content of the header as |
91 * ascii data to a C++ output stream. Although the header is free to format |
81 * ascii data to a C++ output stream. Although the header is free to format |
92 * its output as it wishes, it is recommended to follow a few rules to integrate |
82 * its output as it wishes, it is recommended to follow a few rules to integrate |
93 * with the packet pretty printer: start with flags, small field |
83 * with the packet pretty printer: start with flags, small field |
94 * values located between a pair of parens. Values should be separated |
84 * values located between a pair of parens. Values should be separated |
95 * by whitespace. Follow the parens with the important fields, |
85 * by whitespace. Follow the parens with the important fields, |
96 * separated by whitespace. |
86 * separated by whitespace. |
97 * |
87 * |
98 * eg: (field1 val1 field2 val2 field3 val3) field4 val4 field5 val5 |
88 * eg: (field1 val1 field2 val2 field3 val3) field4 val4 field5 val5 |
99 * |
89 * |
100 * @param os The output stream |
90 * @param os The output stream |
101 */ |
91 */ |
102 virtual void Print (std::ostream &os) const; |
92 virtual void Print (std::ostream &os) const; |
103 |
93 |
104 /** |
94 /** |
105 * @brief Set the Time Synchronization Function Timer (TSFT) value. Valid for |
95 * @brief Set the Time Synchronization Function Timer (TSFT) value. Valid for |
106 * received frames only. |
96 * received frames only. |
107 * |
97 * |
108 * @param tsft Value in microseconds of the MAC's 64-bit 802.11 Time |
98 * @param tsft Value in microseconds of the MAC's 64-bit 802.11 Time |
109 * Synchronization Function timer when the first bit of the MPDU |
99 * Synchronization Function timer when the first bit of the MPDU |
110 * arrived at the MAC. |
100 * arrived at the MAC. |
111 */ |
101 */ |
112 void SetTsft (uint64_t tsft); |
102 void SetTsft (uint64_t tsft); |
113 |
103 |
114 /** |
104 /** |
115 * @brief Get the Time Synchronization Function Timer (TSFT) value. Valid for |
105 * @brief Get the Time Synchronization Function Timer (TSFT) value. Valid for |
116 * received frames only. |
106 * received frames only. |
117 * |
107 * |
118 * @returns The value in microseconds of the MAC's 64-bit 802.11 Time |
108 * @returns The value in microseconds of the MAC's 64-bit 802.11 Time |
119 * Synchronization Function timer when the first bit of the MPDU |
109 * Synchronization Function timer when the first bit of the MPDU |
120 * arrived at the MAC. |
110 * arrived at the MAC. |
121 */ |
111 */ |
122 uint64_t GetTsft (void) const; |
112 uint64_t GetTsft (void) const; |
123 |
113 |
124 enum { |
114 enum |
|
115 { |
125 FRAME_FLAG_NONE = 0x00, /**< No flags set */ |
116 FRAME_FLAG_NONE = 0x00, /**< No flags set */ |
126 FRAME_FLAG_CFP = 0x01, /**< Frame sent/received during CFP */ |
117 FRAME_FLAG_CFP = 0x01, /**< Frame sent/received during CFP */ |
127 FRAME_FLAG_SHORT_PREAMBLE = 0x02, /**< Frame sent/received with short preamble */ |
118 FRAME_FLAG_SHORT_PREAMBLE = 0x02, /**< Frame sent/received with short preamble */ |
128 FRAME_FLAG_WEP = 0x04, /**< Frame sent/received with WEP encryption */ |
119 FRAME_FLAG_WEP = 0x04, /**< Frame sent/received with WEP encryption */ |
129 FRAME_FLAG_FRAGMENTED = 0x08, /**< Frame sent/received with fragmentation */ |
120 FRAME_FLAG_FRAGMENTED = 0x08, /**< Frame sent/received with fragmentation */ |
191 */ |
183 */ |
192 uint16_t GetChannelFlags (void) const; |
184 uint16_t GetChannelFlags (void) const; |
193 |
185 |
194 /** |
186 /** |
195 * @brief Set the RF signal power at the antenna as a decibel difference |
187 * @brief Set the RF signal power at the antenna as a decibel difference |
196 * from an arbitrary, fixed reference. |
188 * from an arbitrary, fixed reference. |
197 * |
189 * |
198 * @param signal The RF signal power at the antenna as a decibel difference |
190 * @param signal The RF signal power at the antenna as a decibel difference |
199 * from an arbitrary, fixed reference; |
191 * from an arbitrary, fixed reference; |
200 */ |
192 */ |
201 void SetAntennaSignalPower (double signal); |
193 void SetAntennaSignalPower (double signal); |
202 |
194 |
203 /** |
195 /** |
204 * @brief Get the RF signal power at the antenna as a decibel difference |
196 * @brief Get the RF signal power at the antenna as a decibel difference |
205 * from an arbitrary, fixed reference. |
197 * from an arbitrary, fixed reference. |
206 * |
198 * |
207 * @returns The RF signal power at the antenna as a decibel difference |
199 * @returns The RF signal power at the antenna as a decibel difference |
208 * from an arbitrary, fixed reference. |
200 * from an arbitrary, fixed reference. |
209 */ |
201 */ |
210 uint8_t GetAntennaSignalPower (void) const; |
202 uint8_t GetAntennaSignalPower (void) const; |
211 |
203 |
212 /** |
204 /** |
213 * @brief Set the RF noise power at the antenna as a decibel difference |
205 * @brief Set the RF noise power at the antenna as a decibel difference |
214 * from an arbitrary, fixed reference. |
206 * from an arbitrary, fixed reference. |
215 * |
207 * |
216 * @param noise The RF noise power at the antenna as a decibel difference |
208 * @param noise The RF noise power at the antenna as a decibel difference |
217 * from an arbitrary, fixed reference. |
209 * from an arbitrary, fixed reference. |
218 */ |
210 */ |
219 void SetAntennaNoisePower (double noise); |
211 void SetAntennaNoisePower (double noise); |
220 |
212 |
221 /** |
213 /** |
222 * @brief Get the RF noise power at the antenna as a decibel difference |
214 * @brief Get the RF noise power at the antenna as a decibel difference |
223 * from an arbitrary, fixed reference. |
215 * from an arbitrary, fixed reference. |
224 * |
216 * |
225 * @returns The RF noise power at the antenna as a decibel difference |
217 * @returns The RF noise power at the antenna as a decibel difference |
226 * from an arbitrary, fixed reference. |
218 * from an arbitrary, fixed reference. |
227 */ |
219 */ |
228 uint8_t GetAntennaNoisePower (void) const; |
220 uint8_t GetAntennaNoisePower (void) const; |
229 |
221 |
|
222 enum |
|
223 { |
|
224 MCS_KNOWN_NONE = 0x00, /**< No flags set */ |
|
225 MCS_KNOWN_BANDWIDTH = 0x01, /**< Bandwidth */ |
|
226 MCS_KNOWN_INDEX = 0x02, /**< MCS index known */ |
|
227 MCS_KNOWN_GUARD_INTERVAL = 0x04, /**< Guard interval */ |
|
228 MCS_KNOWN_HT_FORMAT = 0x08, /**< HT format */ |
|
229 MCS_KNOWN_FEC_TYPE = 0x10, /**< FEC type */ |
|
230 MCS_KNOWN_STBC = 0x20, /**< STBC known */ |
|
231 MCS_KNOWN_NESS = 0x40, /**< Ness known (Number of extension spatial streams) */ |
|
232 MCS_KNOWN_NESS_BIT_1 = 0x80, /**< Ness data - bit 1 (MSB) of Number of extension spatial streams */ |
|
233 }; |
|
234 |
|
235 enum |
|
236 { |
|
237 MCS_FLAGS_NONE = 0x00, /**< Default: 20 MHz, long guard interval, mixed HT format and BCC FEC type */ |
|
238 MCS_FLAGS_BANDWIDTH_40 = 0x01, /**< 40 MHz */ |
|
239 MCS_FLAGS_BANDWIDTH_20L = 0x02, /**< 20L (20 MHz in lower half of 40 MHz channel) */ |
|
240 MCS_FLAGS_BANDWIDTH_20U = 0x03, /**< 20U (20 MHz in upper half of 40 MHz channel) */ |
|
241 MCS_FLAGS_GUARD_INTERVAL = 0x04, /**< Short guard interval */ |
|
242 MCS_FLAGS_HT_GREENFIELD = 0x08, /**< Greenfield HT format */ |
|
243 MCS_FLAGS_FEC_TYPE = 0x10, /**< LDPC FEC type */ |
|
244 MCS_FLAGS_STBC_STREAMS = 0x60, /**< STBC enabled */ |
|
245 MCS_FLAGS_NESS_BIT_0 = 0x80, /**< Ness - bit 0 (LSB) of Number of extension spatial streams */ |
|
246 }; |
|
247 |
|
248 /** |
|
249 * @brief Set the MCS fields |
|
250 * |
|
251 * @param known The kwown flags. |
|
252 * @param flags The flags to set. |
|
253 * @param mcs The MCS index value. |
|
254 */ |
|
255 void SetMcsFields (uint8_t known, uint8_t flags, uint8_t mcs); |
|
256 |
|
257 /** |
|
258 * @brief Get the MCS known bitmap. |
|
259 * |
|
260 * @returns The MCS known bitmap. |
|
261 */ |
|
262 uint8_t GetMcsKnown (void) const; |
|
263 /** |
|
264 * @brief Get the MCS flags. |
|
265 * |
|
266 * @returns The MCS flags. |
|
267 */ |
|
268 uint8_t GetMcsFlags (void) const; |
|
269 /** |
|
270 * @brief Get the MCS index value. |
|
271 * |
|
272 * @returns The MCS index value. |
|
273 */ |
|
274 uint8_t GetMcsRate (void) const; |
|
275 |
|
276 enum |
|
277 { |
|
278 A_MPDU_STATUS_NONE = 0x00, /**< No flags set */ |
|
279 A_MPDU_STATUS_REPORT_ZERO_LENGTH = 0x01, /**< Driver reports 0-length subframes */ |
|
280 A_MPDU_STATUS_IS_ZERO_LENGTH = 0x02, /**< Frame is 0-length subframe (valid only if 0x0001 is set) */ |
|
281 A_MPDU_STATUS_LAST_KNOWN = 0x04, /**< Last subframe is known (should be set for all subframes in an A-MPDU) */ |
|
282 A_MPDU_STATUS_LAST = 0x08, /**< This frame is the last subframe */ |
|
283 A_MPDU_STATUS_DELIMITER_CRC_ERROR = 0x10, /**< Delimiter CRC error */ |
|
284 A_MPDU_STATUS_DELIMITER_CRC_KNOWN = 0x20 /**< Delimiter CRC value known: the delimiter CRC value field is valid */ |
|
285 }; |
|
286 |
|
287 /** |
|
288 * @brief Set the A-MPDU status fields |
|
289 * |
|
290 * @param referenceNumber The A-MPDU reference number to identify all subframes belonging to the same A-MPDU. |
|
291 * @param flags The flags to set. |
|
292 * @param crc The CRC value value. |
|
293 */ |
|
294 void SetAmpduStatus (uint32_t referenceNumber, uint16_t flags, uint8_t crc); |
|
295 |
|
296 /** |
|
297 * @brief Get the A-MPDU reference number. |
|
298 * |
|
299 * @returns The A-MPDU reference number. |
|
300 */ |
|
301 uint32_t GetAmpduStatusRef (void) const; |
|
302 /** |
|
303 * @brief Get the A-MPDU status flags. |
|
304 * |
|
305 * @returns The A-MPDU status flags. |
|
306 */ |
|
307 uint16_t GetAmpduStatusFlags (void) const; |
|
308 |
|
309 |
230 private: |
310 private: |
231 enum { |
311 enum |
|
312 { |
232 RADIOTAP_TSFT = 0x00000001, |
313 RADIOTAP_TSFT = 0x00000001, |
233 RADIOTAP_FLAGS = 0x00000002, |
314 RADIOTAP_FLAGS = 0x00000002, |
234 RADIOTAP_RATE = 0x00000004, |
315 RADIOTAP_RATE = 0x00000004, |
235 RADIOTAP_CHANNEL = 0x00000008, |
316 RADIOTAP_CHANNEL = 0x00000008, |
236 RADIOTAP_FHSS = 0x00000010, |
317 RADIOTAP_FHSS = 0x00000010, |
237 RADIOTAP_DBM_ANTSIGNAL = 0x00000020, |
318 RADIOTAP_DBM_ANTSIGNAL = 0x00000020, |
238 RADIOTAP_DBM_ANTNOISE = 0x00000040, |
319 RADIOTAP_DBM_ANTNOISE = 0x00000040, |
239 RADIOTAP_LOCK_QUALITY = 0x00000080, |
320 RADIOTAP_LOCK_QUALITY = 0x00000080, |
240 RADIOTAP_TX_ATTENUATION = 0x00000100, |
321 RADIOTAP_TX_ATTENUATION = 0x00000100, |
241 RADIOTAP_DB_TX_ATTENUATION = 0x00000200, |
322 RADIOTAP_DB_TX_ATTENUATION = 0x00000200, |
242 RADIOTAP_DBM_TX_POWER = 0x00000200, |
323 RADIOTAP_DBM_TX_POWER = 0x00000400, |
243 RADIOTAP_ANTENNA = 0x00000400, |
324 RADIOTAP_ANTENNA = 0x00000800, |
244 RADIOTAP_DB_ANTSIGNAL = 0x00000800, |
325 RADIOTAP_DB_ANTSIGNAL = 0x00001000, |
245 RADIOTAP_DB_ANTNOISE = 0x00001000, |
326 RADIOTAP_DB_ANTNOISE = 0x00002000, |
|
327 RADIOTAP_RX_FLAGS = 0x00004000, |
|
328 RADIOTAP_MCS = 0x00080000, |
|
329 RADIOTAP_AMPDU_STATUS = 0x00100000, |
|
330 RADIOTAP_VHT = 0x00200000, |
246 RADIOTAP_EXT = 0x10000000 |
331 RADIOTAP_EXT = 0x10000000 |
247 }; |
332 }; |
248 |
333 |
249 uint16_t m_length; //!< entire length of radiotap data + header |
334 uint16_t m_length; //!< entire length of radiotap data + header |
250 uint32_t m_present; //!< bits describing which fields follow header |
335 uint32_t m_present; //!< bits describing which fields follow header |
251 |
336 |
252 uint64_t m_tsft; //!< Time Synchronization Function Timer (when the first bit of the MPDU arrived at the MAC) |
337 uint64_t m_tsft; //!< Time Synchronization Function Timer (when the first bit of the MPDU arrived at the MAC) |
253 uint8_t m_flags; //!< Properties of transmitted and received frames. |
338 uint8_t m_flags; //!< Properties of transmitted and received frames. |
254 uint8_t m_rate; //!< TX/RX data rate in units of 500 kbps |
339 uint8_t m_rate; //!< TX/RX data rate in units of 500 kbps |
|
340 uint8_t m_channelPad; //!< Tx/Rx channel padding. |
255 uint16_t m_channelFreq; //!< Tx/Rx frequency in MHz. |
341 uint16_t m_channelFreq; //!< Tx/Rx frequency in MHz. |
256 uint16_t m_channelFlags; //!< Tx/Rx channel flags. |
342 uint16_t m_channelFlags; //!< Tx/Rx channel flags. |
257 int8_t m_antennaSignal; //!< RF signal power at the antenna, dB difference from an arbitrary, fixed reference. |
343 int8_t m_antennaSignal; //!< RF signal power at the antenna, dB difference from an arbitrary, fixed reference. |
258 int8_t m_antennaNoise; //!< RF noise power at the antenna, dB difference from an arbitrary, fixed reference. |
344 int8_t m_antennaNoise; //!< RF noise power at the antenna, dB difference from an arbitrary, fixed reference. |
|
345 |
|
346 uint8_t m_mcsKnown; //!< MCS Flags, known information field. |
|
347 uint8_t m_mcsFlags; //!< MCS Flags, flags field. |
|
348 uint8_t m_mcsRate; //!< MCS Flags, mcs rate index. |
|
349 |
|
350 uint8_t m_ampduStatusPad; //!< A-MPDU Status Flags, padding before A-MPDU Status Field. |
|
351 uint32_t m_ampduStatusRef; //!< A-MPDU Status Flags, reference number. |
|
352 uint16_t m_ampduStatusFlags; //!< A-MPDU Status Flags, information about the received A-MPDU. |
|
353 uint8_t m_ampduStatusCRC; //!< A-MPDU Status Flags, delimiter CRC value. |
259 }; |
354 }; |
260 |
355 |
261 } // namespace ns3 |
356 } // namespace ns3 |
262 |
357 |
263 #endif /* RADIOTAP_HEADER_H */ |
358 #endif /* RADIOTAP_HEADER_H */ |