1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-23 02:35:57 +01:00

Fix invalid FCS serialization offset on RadioTap

This commit is contained in:
Matias Fontanini
2016-02-02 22:43:28 -08:00
parent 8ab48106d6
commit 4b0976571e
2 changed files with 24 additions and 3 deletions

View File

@@ -522,7 +522,7 @@ void RadioTap::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU
stream.write(rate_);
}
if (radio_.flags.channel) {
if (((buffer - buffer_start) & 1) == 1) {
if (((stream.pointer() - buffer_start) & 1) == 1) {
stream.write<uint8_t>(0);
}
stream.write(channel_freq_);
@@ -535,7 +535,7 @@ void RadioTap::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU
stream.write(dbm_noise_);
}
if (radio_.flags.lock_quality) {
if (((buffer - buffer_start) & 1) == 1) {
if (((stream.pointer() - buffer_start) & 1) == 1) {
stream.write<uint8_t>(0);
}
stream.write(signal_quality_);
@@ -547,7 +547,7 @@ void RadioTap::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU
stream.write(db_signal_);
}
if (radio_.flags.rx_flags) {
if (((buffer - buffer_start) & 1) == 1) {
if (((stream.pointer() - buffer_start) & 1) == 1) {
stream.write<uint8_t>(0);
}
stream.write(rx_flags_);

View File

@@ -9,6 +9,8 @@
#include "dot11/dot11_data.h"
#include "dot11/dot11_beacon.h"
#include "arp.h"
#include "snap.h"
#include "eapol.h"
#include "utils.h"
using namespace std;
@@ -379,4 +381,23 @@ TEST_F(RadioTapTest, TSFT) {
EXPECT_EQ(radio.tsft(), 0x7afb9a8dU);
}
TEST_F(RadioTapTest, SerializationWorksFine) {
const uint8_t expected[] = {
0, 0, 26, 0, 43, 72, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 108,
9, 160, 0, 206, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 170, 170, 3, 0, 0, 0, 136, 142,
1, 3, 0, 95, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 55, 43, 4, 210
};
RadioTap radio = RadioTap() / Dot11Data() / SNAP() / RSNEAPOL();
RadioTap::serialization_type buffer = radio.serialize();
EXPECT_EQ(
RadioTap::serialization_type(expected, expected + sizeof(expected)),
buffer
);
}
#endif // HAVE_DOT11