mirror of
https://github.com/mfontanini/libtins
synced 2026-01-28 20:44:26 +01:00
Fixed some compilation errors/warnings and bugs when using Big Endian architectures.
This commit is contained in:
111
src/radiotap.cpp
111
src/radiotap.cpp
@@ -77,56 +77,57 @@ RadioTap::RadioTap(const uint8_t *buffer, uint32_t total_sz)
|
||||
buffer += sizeof(_radio);
|
||||
radiotap_hdr_size -= sizeof(_radio);
|
||||
|
||||
if(_radio.tsft)
|
||||
if(_radio.flags.tsft)
|
||||
read_field(buffer, radiotap_hdr_size, _tsft);
|
||||
|
||||
if(_radio.flags)
|
||||
if(_radio.flags.flags)
|
||||
read_field(buffer, radiotap_hdr_size, _flags);
|
||||
|
||||
if(_radio.rate)
|
||||
if(_radio.flags.rate)
|
||||
read_field(buffer, radiotap_hdr_size, _rate);
|
||||
|
||||
if(_radio.channel) {
|
||||
if(_radio.flags.channel) {
|
||||
if(((buffer - buffer_start) & 1) == 1) {
|
||||
buffer++;
|
||||
radiotap_hdr_size--;
|
||||
}
|
||||
read_field(buffer, radiotap_hdr_size, _channel_freq);
|
||||
uint16_t dummy;
|
||||
read_field(buffer, radiotap_hdr_size, dummy);
|
||||
_channel_type = dummy;
|
||||
read_field(buffer, radiotap_hdr_size, _channel_type);
|
||||
}
|
||||
|
||||
if(_radio.dbm_signal)
|
||||
if(_radio.flags.dbm_signal)
|
||||
read_field(buffer, radiotap_hdr_size, _dbm_signal);
|
||||
|
||||
if(_radio.dbm_noise)
|
||||
if(_radio.flags.dbm_noise)
|
||||
read_field(buffer, radiotap_hdr_size, _dbm_noise);
|
||||
|
||||
if(_radio.lock_quality)
|
||||
if(_radio.flags.lock_quality)
|
||||
read_field(buffer, radiotap_hdr_size, _signal_quality);
|
||||
|
||||
if(_radio.antenna)
|
||||
if(_radio.flags.antenna)
|
||||
read_field(buffer, radiotap_hdr_size, _antenna);
|
||||
|
||||
if(_radio.db_signal)
|
||||
if(_radio.flags.db_signal)
|
||||
read_field(buffer, radiotap_hdr_size, _db_signal);
|
||||
|
||||
if(_radio.rx_flags) {
|
||||
if(_radio.flags.rx_flags) {
|
||||
if(((buffer - buffer_start) & 1) == 1) {
|
||||
buffer++;
|
||||
radiotap_hdr_size--;
|
||||
}
|
||||
read_field(buffer, radiotap_hdr_size, _rx_flags);
|
||||
}
|
||||
if(_radio.channel_plus) {
|
||||
if(_radio.flags.channel_plus) {
|
||||
uint32_t offset = ((buffer - buffer_start) % 4);
|
||||
if(offset) {
|
||||
offset = 4 - offset;
|
||||
buffer += offset;
|
||||
radiotap_hdr_size -= offset;
|
||||
}
|
||||
read_field(buffer, radiotap_hdr_size, _channel_type);
|
||||
uint32_t dummy;
|
||||
read_field(buffer, radiotap_hdr_size, dummy);
|
||||
// nasty Big Endian fix
|
||||
_channel_type = Endian::le_to_host<uint16_t>(Endian::host_to_le<uint32_t>(dummy));
|
||||
read_field(buffer, radiotap_hdr_size, _channel_freq);
|
||||
read_field(buffer, radiotap_hdr_size, _channel);
|
||||
read_field(buffer, radiotap_hdr_size, _max_power);
|
||||
@@ -135,7 +136,7 @@ RadioTap::RadioTap(const uint8_t *buffer, uint32_t total_sz)
|
||||
total_sz -= length();
|
||||
buffer += radiotap_hdr_size;
|
||||
|
||||
if(_radio.flags && (flags() & FCS) != 0) {
|
||||
if(_radio.flags.flags && (flags() & FCS) != 0) {
|
||||
check_size(total_sz, sizeof(uint32_t));
|
||||
total_sz -= sizeof(uint32_t);
|
||||
if((flags() & FAILED_FCS) !=0)
|
||||
@@ -169,83 +170,83 @@ void RadioTap::length(uint16_t new_length) {
|
||||
|
||||
void RadioTap::tsft(uint64_t new_tsft) {
|
||||
_tsft = Endian::host_to_le(new_tsft);
|
||||
_radio.tsft = 1;
|
||||
_radio.flags.tsft = 1;
|
||||
}
|
||||
|
||||
void RadioTap::flags(FrameFlags new_flags) {
|
||||
_flags = (uint8_t)new_flags;
|
||||
_radio.flags = 1;
|
||||
_radio.flags.flags = 1;
|
||||
}
|
||||
|
||||
void RadioTap::rate(uint8_t new_rate) {
|
||||
_rate = new_rate;
|
||||
_radio.rate = 1;
|
||||
_radio.flags.rate = 1;
|
||||
}
|
||||
|
||||
void RadioTap::channel(uint16_t new_freq, uint16_t new_type) {
|
||||
_channel_freq = Endian::host_to_le(new_freq);
|
||||
_channel_type = Endian::host_to_le<uint32_t>(new_type);
|
||||
_radio.channel = 1;
|
||||
_channel_type = Endian::host_to_le(new_type);
|
||||
_radio.flags.channel = 1;
|
||||
}
|
||||
void RadioTap::dbm_signal(uint8_t new_dbm_signal) {
|
||||
_dbm_signal = new_dbm_signal;
|
||||
_radio.dbm_signal = 1;
|
||||
_radio.flags.dbm_signal = 1;
|
||||
}
|
||||
|
||||
void RadioTap::dbm_noise(uint8_t new_dbm_noise) {
|
||||
_dbm_noise = new_dbm_noise;
|
||||
_radio.dbm_noise = 1;
|
||||
_radio.flags.dbm_noise = 1;
|
||||
}
|
||||
|
||||
void RadioTap::signal_quality(uint8_t new_signal_quality) {
|
||||
_signal_quality = new_signal_quality;
|
||||
_radio.lock_quality = 1;
|
||||
_radio.flags.lock_quality = 1;
|
||||
}
|
||||
|
||||
void RadioTap::antenna(uint8_t new_antenna) {
|
||||
_antenna = new_antenna;
|
||||
_radio.antenna = 1;
|
||||
_radio.flags.antenna = 1;
|
||||
}
|
||||
|
||||
void RadioTap::db_signal(uint8_t new_db_signal) {
|
||||
_db_signal = new_db_signal;
|
||||
_radio.db_signal = 1;
|
||||
_radio.flags.db_signal = 1;
|
||||
}
|
||||
|
||||
void RadioTap::rx_flags(uint16_t new_rx_flag) {
|
||||
_rx_flags = Endian::host_to_le(new_rx_flag);
|
||||
_radio.rx_flags = 1;
|
||||
_radio.flags.rx_flags = 1;
|
||||
}
|
||||
|
||||
uint32_t RadioTap::header_size() const {
|
||||
uint32_t total_bytes = 0;
|
||||
if(_radio.tsft)
|
||||
if(_radio.flags.tsft)
|
||||
total_bytes += sizeof(_tsft);
|
||||
if(_radio.flags)
|
||||
if(_radio.flags.flags)
|
||||
total_bytes += sizeof(_flags);
|
||||
if(_radio.rate)
|
||||
if(_radio.flags.rate)
|
||||
total_bytes += sizeof(_rate);
|
||||
if(_radio.channel) {
|
||||
if(_radio.flags.channel) {
|
||||
total_bytes += (total_bytes & 1);
|
||||
total_bytes += sizeof(uint16_t) * 2;
|
||||
}
|
||||
if(_radio.dbm_signal)
|
||||
if(_radio.flags.dbm_signal)
|
||||
total_bytes += sizeof(_dbm_signal);
|
||||
if(_radio.dbm_noise)
|
||||
if(_radio.flags.dbm_noise)
|
||||
total_bytes += sizeof(_dbm_noise);
|
||||
if(_radio.lock_quality) {
|
||||
if(_radio.flags.lock_quality) {
|
||||
total_bytes += (total_bytes & 1);
|
||||
total_bytes += sizeof(_signal_quality);
|
||||
}
|
||||
if(_radio.antenna)
|
||||
if(_radio.flags.antenna)
|
||||
total_bytes += sizeof(_antenna);
|
||||
if(_radio.db_signal)
|
||||
if(_radio.flags.db_signal)
|
||||
total_bytes += sizeof(_db_signal);
|
||||
if(_radio.rx_flags) {
|
||||
if(_radio.flags.rx_flags) {
|
||||
total_bytes += (total_bytes & 1);
|
||||
total_bytes += sizeof(_rx_flags);
|
||||
}
|
||||
if(_radio.channel_plus) {
|
||||
if(_radio.flags.channel_plus) {
|
||||
uint32_t offset = total_bytes % 4;
|
||||
if(offset)
|
||||
total_bytes += 4 - offset;
|
||||
@@ -309,56 +310,55 @@ void RadioTap::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU
|
||||
_radio.it_len = Endian::host_to_le<uint16_t>(sz);
|
||||
memcpy(buffer, &_radio, sizeof(_radio));
|
||||
buffer += sizeof(_radio);
|
||||
if(_radio.tsft) {
|
||||
if(_radio.flags.tsft) {
|
||||
memcpy(buffer, &_tsft, sizeof(_tsft));
|
||||
buffer += sizeof(_tsft);
|
||||
}
|
||||
if(_radio.flags) {
|
||||
if(_radio.flags.flags) {
|
||||
memcpy(buffer, &_flags, sizeof(_flags));
|
||||
buffer += sizeof(_flags);
|
||||
}
|
||||
if(_radio.rate) {
|
||||
if(_radio.flags.rate) {
|
||||
memcpy(buffer, &_rate, sizeof(_rate));
|
||||
buffer += sizeof(_rate);
|
||||
}
|
||||
if(_radio.channel) {
|
||||
if(_radio.flags.channel) {
|
||||
if(((buffer - buffer_start) & 1) == 1)
|
||||
*(buffer++) = 0;
|
||||
uint16_t dummy = _channel_type;
|
||||
memcpy(buffer, &_channel_freq, sizeof(_channel_freq));
|
||||
buffer += sizeof(_channel_freq);
|
||||
memcpy(buffer, &dummy, sizeof(dummy));
|
||||
buffer += sizeof(dummy);
|
||||
memcpy(buffer, &_channel_type, sizeof(_channel_type));
|
||||
buffer += sizeof(_channel_type);
|
||||
}
|
||||
if(_radio.dbm_signal) {
|
||||
if(_radio.flags.dbm_signal) {
|
||||
memcpy(buffer, &_dbm_signal, sizeof(_dbm_signal));
|
||||
buffer += sizeof(_dbm_signal);
|
||||
}
|
||||
if(_radio.dbm_noise) {
|
||||
if(_radio.flags.dbm_noise) {
|
||||
memcpy(buffer, &_dbm_noise, sizeof(_dbm_noise));
|
||||
buffer += sizeof(_dbm_noise);
|
||||
}
|
||||
if(_radio.lock_quality) {
|
||||
if(_radio.flags.lock_quality) {
|
||||
if(((buffer - buffer_start) & 1) == 1)
|
||||
*(buffer++) = 0;
|
||||
memcpy(buffer, &_signal_quality, sizeof(_signal_quality));
|
||||
buffer += sizeof(_signal_quality);
|
||||
}
|
||||
if(_radio.antenna) {
|
||||
if(_radio.flags.antenna) {
|
||||
memcpy(buffer, &_antenna, sizeof(_antenna));
|
||||
buffer += sizeof(_antenna);
|
||||
}
|
||||
if(_radio.db_signal) {
|
||||
if(_radio.flags.db_signal) {
|
||||
memcpy(buffer, &_db_signal, sizeof(_db_signal));
|
||||
buffer += sizeof(_db_signal);
|
||||
}
|
||||
if(_radio.rx_flags) {
|
||||
if(_radio.flags.rx_flags) {
|
||||
if(((buffer - buffer_start) & 1) == 1)
|
||||
*(buffer++) = 0;
|
||||
memcpy(buffer, &_rx_flags, sizeof(_rx_flags));
|
||||
buffer += sizeof(_rx_flags);
|
||||
}
|
||||
if(_radio.channel_plus) {
|
||||
if(_radio.flags.channel_plus) {
|
||||
uint32_t offset = ((buffer - buffer_start) % 4);
|
||||
if(offset) {
|
||||
offset = 4 - offset;
|
||||
@@ -366,8 +366,11 @@ void RadioTap::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU
|
||||
*buffer++ = 0;
|
||||
}
|
||||
}
|
||||
memcpy(buffer, &_channel_type, sizeof(_channel_type));
|
||||
buffer += sizeof(_channel_type);
|
||||
uint32_t dummy = _channel_type;
|
||||
// nasty Big Endian fix
|
||||
dummy = Endian::le_to_host<uint32_t>(Endian::host_to_le<uint16_t>(dummy));
|
||||
memcpy(buffer, &dummy, sizeof(dummy));
|
||||
buffer += sizeof(dummy);
|
||||
memcpy(buffer, &_channel_freq, sizeof(_channel_freq));
|
||||
buffer += sizeof(_channel_freq);
|
||||
memcpy(buffer, &_channel, sizeof(_channel));
|
||||
|
||||
Reference in New Issue
Block a user