mirror of
https://github.com/mfontanini/libtins
synced 2026-01-27 12:14:26 +01:00
Code cleanup and use same syntax on the entire project
Initial code cleanup More code cleanup Cleanup more code Cleanup Dot11 code Fix OSX build issue Cleanup examples Fix ref and pointer declaration syntax Fix braces
This commit is contained in:
429
src/radiotap.cpp
429
src/radiotap.cpp
@@ -49,33 +49,34 @@
|
||||
#include "exceptions.h"
|
||||
#include "memory_helpers.h"
|
||||
|
||||
using std::memcpy;
|
||||
|
||||
using Tins::Memory::OutputMemoryStream;
|
||||
|
||||
namespace Tins {
|
||||
|
||||
void check_size(uint32_t total_sz, size_t field_size) {
|
||||
if(total_sz < field_size)
|
||||
if (total_sz < field_size) {
|
||||
throw malformed_packet();
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void read_field(const uint8_t* &buffer, uint32_t &total_sz, T& field) {
|
||||
void read_field(const uint8_t* &buffer, uint32_t& total_sz, T& field) {
|
||||
check_size(total_sz, sizeof(field));
|
||||
memcpy(&field, buffer, sizeof(field));
|
||||
buffer += sizeof(field);
|
||||
total_sz -= sizeof(field);
|
||||
}
|
||||
|
||||
RadioTap::RadioTap() : _radio()
|
||||
{
|
||||
RadioTap::RadioTap() : radio_() {
|
||||
init();
|
||||
}
|
||||
|
||||
RadioTap::RadioTap(const uint8_t *buffer, uint32_t total_sz)
|
||||
{
|
||||
check_size(total_sz, sizeof(_radio));
|
||||
const uint8_t *buffer_start = buffer;
|
||||
std::memcpy(&_radio, buffer, sizeof(_radio));
|
||||
RadioTap::RadioTap(const uint8_t* buffer, uint32_t total_sz) {
|
||||
check_size(total_sz, sizeof(radio_));
|
||||
const uint8_t* buffer_start = buffer;
|
||||
memcpy(&radio_, buffer, sizeof(radio_));
|
||||
uint32_t radiotap_hdr_size = length();
|
||||
check_size(total_sz, radiotap_hdr_size);
|
||||
// We start on the first flags field, skipping version, pad and length.
|
||||
@@ -86,74 +87,81 @@ RadioTap::RadioTap(const uint8_t *buffer, uint32_t total_sz)
|
||||
buffer += extra_flags_size;
|
||||
radiotap_hdr_size -= extra_flags_size;
|
||||
// Also skip the header
|
||||
buffer += sizeof(_radio);
|
||||
radiotap_hdr_size -= sizeof(_radio);
|
||||
buffer += sizeof(radio_);
|
||||
radiotap_hdr_size -= sizeof(radio_);
|
||||
|
||||
while(true) {
|
||||
_radio.flags_32 |= *(const uint32_t*)current_flags;
|
||||
if(current_flags->tsft) {
|
||||
while (true) {
|
||||
radio_.flags_32 |= *(const uint32_t*)current_flags;
|
||||
if (current_flags->tsft) {
|
||||
align_buffer<8>(buffer_start, buffer, radiotap_hdr_size);
|
||||
read_field(buffer, radiotap_hdr_size, _tsft);
|
||||
read_field(buffer, radiotap_hdr_size, tsft_);
|
||||
}
|
||||
|
||||
if(current_flags->flags)
|
||||
read_field(buffer, radiotap_hdr_size, _flags);
|
||||
if (current_flags->flags) {
|
||||
read_field(buffer, radiotap_hdr_size, flags_);
|
||||
}
|
||||
|
||||
if(current_flags->rate)
|
||||
read_field(buffer, radiotap_hdr_size, _rate);
|
||||
if (current_flags->rate) {
|
||||
read_field(buffer, radiotap_hdr_size, rate_);
|
||||
}
|
||||
|
||||
if(current_flags->channel) {
|
||||
if (current_flags->channel) {
|
||||
align_buffer<2>(buffer_start, buffer, radiotap_hdr_size);
|
||||
read_field(buffer, radiotap_hdr_size, _channel_freq);
|
||||
read_field(buffer, radiotap_hdr_size, _channel_type);
|
||||
read_field(buffer, radiotap_hdr_size, channel_freq_);
|
||||
read_field(buffer, radiotap_hdr_size, channel_type_);
|
||||
}
|
||||
|
||||
if(current_flags->dbm_signal)
|
||||
read_field(buffer, radiotap_hdr_size, _dbm_signal);
|
||||
if (current_flags->dbm_signal) {
|
||||
read_field(buffer, radiotap_hdr_size, dbm_signal_);
|
||||
}
|
||||
|
||||
if(current_flags->dbm_noise)
|
||||
read_field(buffer, radiotap_hdr_size, _dbm_noise);
|
||||
if (current_flags->dbm_noise) {
|
||||
read_field(buffer, radiotap_hdr_size, dbm_noise_);
|
||||
}
|
||||
|
||||
if(current_flags->lock_quality)
|
||||
read_field(buffer, radiotap_hdr_size, _signal_quality);
|
||||
if (current_flags->lock_quality) {
|
||||
read_field(buffer, radiotap_hdr_size, signal_quality_);
|
||||
}
|
||||
|
||||
if(current_flags->antenna)
|
||||
read_field(buffer, radiotap_hdr_size, _antenna);
|
||||
if (current_flags->antenna) {
|
||||
read_field(buffer, radiotap_hdr_size, antenna_);
|
||||
}
|
||||
|
||||
if(current_flags->db_signal)
|
||||
read_field(buffer, radiotap_hdr_size, _db_signal);
|
||||
if (current_flags->db_signal) {
|
||||
read_field(buffer, radiotap_hdr_size, db_signal_);
|
||||
}
|
||||
|
||||
if(current_flags->rx_flags) {
|
||||
if (current_flags->rx_flags) {
|
||||
align_buffer<2>(buffer_start, buffer, radiotap_hdr_size);
|
||||
read_field(buffer, radiotap_hdr_size, _rx_flags);
|
||||
read_field(buffer, radiotap_hdr_size, rx_flags_);
|
||||
}
|
||||
|
||||
if(current_flags->tx_flags) {
|
||||
if (current_flags->tx_flags) {
|
||||
align_buffer<2>(buffer_start, buffer, radiotap_hdr_size);
|
||||
read_field(buffer, radiotap_hdr_size, _tx_flags);
|
||||
read_field(buffer, radiotap_hdr_size, tx_flags_);
|
||||
}
|
||||
|
||||
if(current_flags->data_retries) {
|
||||
read_field(buffer, radiotap_hdr_size, _data_retries);
|
||||
if (current_flags->data_retries) {
|
||||
read_field(buffer, radiotap_hdr_size, data_retries_);
|
||||
}
|
||||
|
||||
if(current_flags->channel_plus) {
|
||||
if (current_flags->channel_plus) {
|
||||
align_buffer<4>(buffer_start, buffer, radiotap_hdr_size);
|
||||
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);
|
||||
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_);
|
||||
}
|
||||
if(current_flags->mcs) {
|
||||
read_field(buffer, radiotap_hdr_size, _mcs.known);
|
||||
read_field(buffer, radiotap_hdr_size, _mcs.flags);
|
||||
read_field(buffer, radiotap_hdr_size, _mcs.mcs);
|
||||
if (current_flags->mcs) {
|
||||
read_field(buffer, radiotap_hdr_size, mcs_.known);
|
||||
read_field(buffer, radiotap_hdr_size, mcs_.flags);
|
||||
read_field(buffer, radiotap_hdr_size, mcs_.mcs);
|
||||
}
|
||||
// We can do this safely because we checked the size on find_extra_flags...
|
||||
if(current_flags->ext == 1) {
|
||||
if (current_flags->ext == 1) {
|
||||
current_flags++;
|
||||
}
|
||||
else {
|
||||
@@ -164,15 +172,17 @@ RadioTap::RadioTap(const uint8_t *buffer, uint32_t total_sz)
|
||||
total_sz -= length();
|
||||
buffer += radiotap_hdr_size;
|
||||
|
||||
if(_radio.flags.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)
|
||||
if ((flags() & FAILED_FCS) !=0) {
|
||||
throw malformed_packet();
|
||||
}
|
||||
}
|
||||
|
||||
if(total_sz)
|
||||
if (total_sz) {
|
||||
inner_pdu(Dot11::from_bytes(buffer, total_sz));
|
||||
}
|
||||
}
|
||||
|
||||
void RadioTap::init() {
|
||||
@@ -200,241 +210,266 @@ uint32_t RadioTap::find_extra_flag_fields_size(const uint8_t* buffer, uint32_t t
|
||||
|
||||
// Setter for RadioTap fields
|
||||
void RadioTap::version(uint8_t new_version) {
|
||||
_radio.it_version = new_version;
|
||||
radio_.it_version = new_version;
|
||||
}
|
||||
|
||||
void RadioTap::padding(uint8_t new_padding) {
|
||||
_radio.it_pad = new_padding;
|
||||
radio_.it_pad = new_padding;
|
||||
}
|
||||
|
||||
void RadioTap::length(uint16_t new_length) {
|
||||
_radio.it_len = Endian::host_to_le(new_length);
|
||||
radio_.it_len = Endian::host_to_le(new_length);
|
||||
}
|
||||
|
||||
void RadioTap::tsft(uint64_t new_tsft) {
|
||||
_tsft = Endian::host_to_le(new_tsft);
|
||||
_radio.flags.tsft = 1;
|
||||
tsft_ = Endian::host_to_le(new_tsft);
|
||||
radio_.flags.tsft = 1;
|
||||
}
|
||||
|
||||
void RadioTap::flags(FrameFlags new_flags) {
|
||||
_flags = (uint8_t)new_flags;
|
||||
_radio.flags.flags = 1;
|
||||
flags_ = (uint8_t)new_flags;
|
||||
radio_.flags.flags = 1;
|
||||
}
|
||||
|
||||
void RadioTap::rate(uint8_t new_rate) {
|
||||
_rate = new_rate;
|
||||
_radio.flags.rate = 1;
|
||||
rate_ = new_rate;
|
||||
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(new_type);
|
||||
_radio.flags.channel = 1;
|
||||
channel_freq_ = Endian::host_to_le(new_freq);
|
||||
channel_type_ = Endian::host_to_le(new_type);
|
||||
radio_.flags.channel = 1;
|
||||
}
|
||||
void RadioTap::dbm_signal(int8_t new_dbm_signal) {
|
||||
_dbm_signal = new_dbm_signal;
|
||||
_radio.flags.dbm_signal = 1;
|
||||
dbm_signal_ = new_dbm_signal;
|
||||
radio_.flags.dbm_signal = 1;
|
||||
}
|
||||
|
||||
void RadioTap::dbm_noise(int8_t new_dbm_noise) {
|
||||
_dbm_noise = new_dbm_noise;
|
||||
_radio.flags.dbm_noise = 1;
|
||||
dbm_noise_ = new_dbm_noise;
|
||||
radio_.flags.dbm_noise = 1;
|
||||
}
|
||||
|
||||
void RadioTap::signal_quality(uint8_t new_signal_quality) {
|
||||
_signal_quality = new_signal_quality;
|
||||
_radio.flags.lock_quality = 1;
|
||||
signal_quality_ = new_signal_quality;
|
||||
radio_.flags.lock_quality = 1;
|
||||
}
|
||||
|
||||
void RadioTap::data_retries(uint8_t new_data_retries) {
|
||||
_data_retries = new_data_retries;
|
||||
_radio.flags.data_retries = 1;
|
||||
data_retries_ = new_data_retries;
|
||||
radio_.flags.data_retries = 1;
|
||||
}
|
||||
|
||||
void RadioTap::antenna(uint8_t new_antenna) {
|
||||
_antenna = new_antenna;
|
||||
_radio.flags.antenna = 1;
|
||||
antenna_ = new_antenna;
|
||||
radio_.flags.antenna = 1;
|
||||
}
|
||||
|
||||
void RadioTap::db_signal(uint8_t new_db_signal) {
|
||||
_db_signal = new_db_signal;
|
||||
_radio.flags.db_signal = 1;
|
||||
db_signal_ = new_db_signal;
|
||||
radio_.flags.db_signal = 1;
|
||||
}
|
||||
|
||||
void RadioTap::rx_flags(uint16_t new_rx_flag) {
|
||||
_rx_flags = Endian::host_to_le(new_rx_flag);
|
||||
_radio.flags.rx_flags = 1;
|
||||
rx_flags_ = Endian::host_to_le(new_rx_flag);
|
||||
radio_.flags.rx_flags = 1;
|
||||
}
|
||||
|
||||
void RadioTap::tx_flags(uint16_t new_tx_flag) {
|
||||
_tx_flags = Endian::host_to_le(new_tx_flag);
|
||||
_radio.flags.tx_flags = 1;
|
||||
tx_flags_ = Endian::host_to_le(new_tx_flag);
|
||||
radio_.flags.tx_flags = 1;
|
||||
}
|
||||
|
||||
void RadioTap::mcs(const mcs_type& new_mcs) {
|
||||
_mcs = new_mcs;
|
||||
_radio.flags.mcs = 1;
|
||||
mcs_ = new_mcs;
|
||||
radio_.flags.mcs = 1;
|
||||
}
|
||||
|
||||
uint32_t RadioTap::header_size() const {
|
||||
uint32_t total_bytes = 0;
|
||||
if(_radio.flags.tsft)
|
||||
total_bytes += sizeof(_tsft);
|
||||
if(_radio.flags.flags)
|
||||
total_bytes += sizeof(_flags);
|
||||
if(_radio.flags.rate)
|
||||
total_bytes += sizeof(_rate);
|
||||
if(_radio.flags.channel) {
|
||||
if (radio_.flags.tsft) {
|
||||
total_bytes += sizeof(tsft_);
|
||||
}
|
||||
if (radio_.flags.flags) {
|
||||
total_bytes += sizeof(flags_);
|
||||
}
|
||||
if (radio_.flags.rate) {
|
||||
total_bytes += sizeof(rate_);
|
||||
}
|
||||
if (radio_.flags.channel) {
|
||||
total_bytes += (total_bytes & 1);
|
||||
total_bytes += sizeof(uint16_t) * 2;
|
||||
}
|
||||
if(_radio.flags.dbm_signal)
|
||||
total_bytes += sizeof(_dbm_signal);
|
||||
if(_radio.flags.dbm_noise)
|
||||
total_bytes += sizeof(_dbm_noise);
|
||||
if(_radio.flags.lock_quality) {
|
||||
total_bytes += (total_bytes & 1);
|
||||
total_bytes += sizeof(_signal_quality);
|
||||
if (radio_.flags.dbm_signal) {
|
||||
total_bytes += sizeof(dbm_signal_);
|
||||
}
|
||||
if(_radio.flags.antenna)
|
||||
total_bytes += sizeof(_antenna);
|
||||
if(_radio.flags.db_signal)
|
||||
total_bytes += sizeof(_db_signal);
|
||||
if(_radio.flags.rx_flags) {
|
||||
total_bytes += (total_bytes & 1);
|
||||
total_bytes += sizeof(_rx_flags);
|
||||
if (radio_.flags.dbm_noise) {
|
||||
total_bytes += sizeof(dbm_noise_);
|
||||
}
|
||||
if(_radio.flags.tx_flags) {
|
||||
if (radio_.flags.lock_quality) {
|
||||
total_bytes += (total_bytes & 1);
|
||||
total_bytes += sizeof(_tx_flags);
|
||||
total_bytes += sizeof(signal_quality_);
|
||||
}
|
||||
if(_radio.flags.data_retries)
|
||||
total_bytes += sizeof(_data_retries);
|
||||
if(_radio.flags.channel_plus) {
|
||||
if (radio_.flags.antenna) {
|
||||
total_bytes += sizeof(antenna_);
|
||||
}
|
||||
if (radio_.flags.db_signal) {
|
||||
total_bytes += sizeof(db_signal_);
|
||||
}
|
||||
if (radio_.flags.rx_flags) {
|
||||
total_bytes += (total_bytes & 1);
|
||||
total_bytes += sizeof(rx_flags_);
|
||||
}
|
||||
if (radio_.flags.tx_flags) {
|
||||
total_bytes += (total_bytes & 1);
|
||||
total_bytes += sizeof(tx_flags_);
|
||||
}
|
||||
if (radio_.flags.data_retries) {
|
||||
total_bytes += sizeof(data_retries_);
|
||||
}
|
||||
if (radio_.flags.channel_plus) {
|
||||
uint32_t offset = total_bytes % 4;
|
||||
if(offset)
|
||||
if (offset) {
|
||||
total_bytes += 4 - offset;
|
||||
}
|
||||
total_bytes += 8;
|
||||
}
|
||||
if(_radio.flags.mcs) {
|
||||
total_bytes += sizeof(_mcs);
|
||||
if (radio_.flags.mcs) {
|
||||
total_bytes += sizeof(mcs_);
|
||||
}
|
||||
|
||||
return sizeof(_radio) + total_bytes;
|
||||
return sizeof(radio_) + total_bytes;
|
||||
}
|
||||
|
||||
uint32_t RadioTap::trailer_size() const {
|
||||
// will be sizeof(uint32_t) if the FCS-at-the-end bit is on.
|
||||
return ((_flags & 0x10) != 0) ? sizeof(uint32_t) : 0;
|
||||
return ((flags_ & 0x10) != 0) ? sizeof(uint32_t) : 0;
|
||||
}
|
||||
|
||||
// Getter for RadioTap fields
|
||||
uint8_t RadioTap::version() const {
|
||||
return _radio.it_version;
|
||||
return radio_.it_version;
|
||||
}
|
||||
|
||||
uint8_t RadioTap::padding() const {
|
||||
return _radio.it_pad;
|
||||
return radio_.it_pad;
|
||||
}
|
||||
|
||||
uint16_t RadioTap::length() const {
|
||||
return Endian::le_to_host(_radio.it_len);
|
||||
return Endian::le_to_host(radio_.it_len);
|
||||
}
|
||||
|
||||
uint64_t RadioTap::tsft() const {
|
||||
if(!_radio.flags.tsft)
|
||||
if (!radio_.flags.tsft) {
|
||||
throw field_not_present();
|
||||
return Endian::le_to_host(_tsft);
|
||||
}
|
||||
return Endian::le_to_host(tsft_);
|
||||
}
|
||||
|
||||
RadioTap::FrameFlags RadioTap::flags() const {
|
||||
if(!_radio.flags.flags)
|
||||
if (!radio_.flags.flags) {
|
||||
throw field_not_present();
|
||||
return (FrameFlags)_flags;
|
||||
}
|
||||
return (FrameFlags)flags_;
|
||||
}
|
||||
|
||||
uint8_t RadioTap::rate() const {
|
||||
if(!_radio.flags.rate)
|
||||
if (!radio_.flags.rate) {
|
||||
throw field_not_present();
|
||||
return _rate;
|
||||
}
|
||||
return rate_;
|
||||
}
|
||||
|
||||
uint16_t RadioTap::channel_freq() const {
|
||||
if(!_radio.flags.channel)
|
||||
throw field_not_present();
|
||||
return Endian::le_to_host(_channel_freq);
|
||||
if (!radio_.flags.channel) {
|
||||
throw field_not_present();
|
||||
}
|
||||
return Endian::le_to_host(channel_freq_);
|
||||
}
|
||||
|
||||
uint16_t RadioTap::channel_type() const {
|
||||
if(!_radio.flags.channel)
|
||||
if (!radio_.flags.channel) {
|
||||
throw field_not_present();
|
||||
return Endian::le_to_host(_channel_type);
|
||||
}
|
||||
return Endian::le_to_host(channel_type_);
|
||||
}
|
||||
|
||||
int8_t RadioTap::dbm_signal() const {
|
||||
if(!_radio.flags.dbm_signal)
|
||||
if (!radio_.flags.dbm_signal) {
|
||||
throw field_not_present();
|
||||
return _dbm_signal;
|
||||
}
|
||||
return dbm_signal_;
|
||||
}
|
||||
|
||||
int8_t RadioTap::dbm_noise() const {
|
||||
if(!_radio.flags.dbm_noise)
|
||||
if (!radio_.flags.dbm_noise) {
|
||||
throw field_not_present();
|
||||
return _dbm_noise;
|
||||
}
|
||||
return dbm_noise_;
|
||||
}
|
||||
|
||||
uint16_t RadioTap::signal_quality() const {
|
||||
if(!_radio.flags.lock_quality)
|
||||
throw field_not_present();
|
||||
return _signal_quality;
|
||||
if (!radio_.flags.lock_quality) {
|
||||
throw field_not_present();
|
||||
}
|
||||
return signal_quality_;
|
||||
}
|
||||
|
||||
uint8_t RadioTap::antenna() const {
|
||||
if(!_radio.flags.antenna)
|
||||
throw field_not_present();
|
||||
return _antenna;
|
||||
if (!radio_.flags.antenna) {
|
||||
throw field_not_present();
|
||||
}
|
||||
return antenna_;
|
||||
}
|
||||
|
||||
RadioTap::mcs_type RadioTap::mcs() const {
|
||||
if(!_radio.flags.mcs)
|
||||
throw field_not_present();
|
||||
return _mcs;
|
||||
if (!radio_.flags.mcs) {
|
||||
throw field_not_present();
|
||||
}
|
||||
return mcs_;
|
||||
}
|
||||
|
||||
uint8_t RadioTap::db_signal() const {
|
||||
if(!_radio.flags.db_signal)
|
||||
throw field_not_present();
|
||||
return _db_signal;
|
||||
if (!radio_.flags.db_signal) {
|
||||
throw field_not_present();
|
||||
}
|
||||
return db_signal_;
|
||||
}
|
||||
|
||||
uint32_t RadioTap::channel_plus() const {
|
||||
if(!_radio.flags.channel_plus)
|
||||
if (!radio_.flags.channel_plus) {
|
||||
throw field_not_present();
|
||||
return Endian::le_to_host<uint32_t>(_channel_type);
|
||||
}
|
||||
return Endian::le_to_host<uint32_t>(channel_type_);
|
||||
}
|
||||
|
||||
uint16_t RadioTap::rx_flags() const {
|
||||
if(!_radio.flags.rx_flags)
|
||||
throw field_not_present();
|
||||
return Endian::le_to_host(_rx_flags);
|
||||
if (!radio_.flags.rx_flags) {
|
||||
throw field_not_present();
|
||||
}
|
||||
return Endian::le_to_host(rx_flags_);
|
||||
}
|
||||
|
||||
uint16_t RadioTap::tx_flags() const {
|
||||
if(!_radio.flags.tx_flags)
|
||||
throw field_not_present();
|
||||
return Endian::le_to_host(_tx_flags);
|
||||
if (!radio_.flags.tx_flags) {
|
||||
throw field_not_present();
|
||||
}
|
||||
return Endian::le_to_host(tx_flags_);
|
||||
}
|
||||
|
||||
uint8_t RadioTap::data_retries() const {
|
||||
if(!_radio.flags.data_retries)
|
||||
throw field_not_present();
|
||||
return _data_retries;
|
||||
if (!radio_.flags.data_retries) {
|
||||
throw field_not_present();
|
||||
}
|
||||
return data_retries_;
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
void RadioTap::send(PacketSender &sender, const NetworkInterface &iface) {
|
||||
if(!iface)
|
||||
void RadioTap::send(PacketSender& sender, const NetworkInterface& iface) {
|
||||
if (!iface) {
|
||||
throw invalid_interface();
|
||||
}
|
||||
|
||||
#if !defined(BSD) && !defined(__FreeBSD_kernel__)
|
||||
struct sockaddr_ll addr;
|
||||
@@ -446,8 +481,8 @@ void RadioTap::send(PacketSender &sender, const NetworkInterface &iface) {
|
||||
addr.sll_halen = 6;
|
||||
addr.sll_ifindex = iface.id();
|
||||
|
||||
const Tins::Dot11 *wlan = tins_cast<Tins::Dot11*>(inner_pdu());
|
||||
if(wlan) {
|
||||
const Tins::Dot11* wlan = tins_cast<Tins::Dot11*>(inner_pdu());
|
||||
if (wlan) {
|
||||
Tins::Dot11::address_type dot11_addr(wlan->addr1());
|
||||
std::copy(dot11_addr.begin(), dot11_addr.end(), addr.sll_addr);
|
||||
}
|
||||
@@ -459,11 +494,12 @@ void RadioTap::send(PacketSender &sender, const NetworkInterface &iface) {
|
||||
}
|
||||
#endif
|
||||
|
||||
bool RadioTap::matches_response(const uint8_t *ptr, uint32_t total_sz) const {
|
||||
if(sizeof(_radio) < total_sz)
|
||||
bool RadioTap::matches_response(const uint8_t* ptr, uint32_t total_sz) const {
|
||||
if (sizeof(radio_) < total_sz) {
|
||||
return false;
|
||||
const radiotap_hdr *radio_ptr = (const radiotap_hdr*)ptr;
|
||||
if(radio_ptr->it_len <= total_sz) {
|
||||
}
|
||||
const radiotap_hdr* radio_ptr = (const radiotap_hdr*)ptr;
|
||||
if (radio_ptr->it_len <= total_sz) {
|
||||
ptr += radio_ptr->it_len;
|
||||
total_sz -= radio_ptr->it_len;
|
||||
return inner_pdu() ? inner_pdu()->matches_response(ptr, total_sz) : true;
|
||||
@@ -471,65 +507,65 @@ bool RadioTap::matches_response(const uint8_t *ptr, uint32_t total_sz) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
void RadioTap::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent) {
|
||||
void RadioTap::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent) {
|
||||
OutputMemoryStream stream(buffer, total_sz);
|
||||
uint8_t *buffer_start = buffer;
|
||||
_radio.it_len = Endian::host_to_le<uint16_t>(header_size());
|
||||
stream.write(_radio);
|
||||
if(_radio.flags.tsft) {
|
||||
stream.write(_tsft);
|
||||
uint8_t* buffer_start = buffer;
|
||||
radio_.it_len = Endian::host_to_le<uint16_t>(header_size());
|
||||
stream.write(radio_);
|
||||
if (radio_.flags.tsft) {
|
||||
stream.write(tsft_);
|
||||
}
|
||||
if(_radio.flags.flags) {
|
||||
stream.write(_flags);
|
||||
if (radio_.flags.flags) {
|
||||
stream.write(flags_);
|
||||
}
|
||||
if(_radio.flags.rate) {
|
||||
stream.write(_rate);
|
||||
if (radio_.flags.rate) {
|
||||
stream.write(rate_);
|
||||
}
|
||||
if(_radio.flags.channel) {
|
||||
if(((buffer - buffer_start) & 1) == 1) {
|
||||
if (radio_.flags.channel) {
|
||||
if (((buffer - buffer_start) & 1) == 1) {
|
||||
stream.write<uint8_t>(0);
|
||||
}
|
||||
stream.write(_channel_freq);
|
||||
stream.write(_channel_type);
|
||||
stream.write(channel_freq_);
|
||||
stream.write(channel_type_);
|
||||
}
|
||||
if(_radio.flags.dbm_signal) {
|
||||
stream.write(_dbm_signal);
|
||||
if (radio_.flags.dbm_signal) {
|
||||
stream.write(dbm_signal_);
|
||||
}
|
||||
if(_radio.flags.dbm_noise) {
|
||||
stream.write(_dbm_noise);
|
||||
if (radio_.flags.dbm_noise) {
|
||||
stream.write(dbm_noise_);
|
||||
}
|
||||
if(_radio.flags.lock_quality) {
|
||||
if(((buffer - buffer_start) & 1) == 1) {
|
||||
if (radio_.flags.lock_quality) {
|
||||
if (((buffer - buffer_start) & 1) == 1) {
|
||||
stream.write<uint8_t>(0);
|
||||
}
|
||||
stream.write(_signal_quality);
|
||||
stream.write(signal_quality_);
|
||||
}
|
||||
if(_radio.flags.antenna) {
|
||||
stream.write(_antenna);
|
||||
if (radio_.flags.antenna) {
|
||||
stream.write(antenna_);
|
||||
}
|
||||
if(_radio.flags.db_signal) {
|
||||
stream.write(_db_signal);
|
||||
if (radio_.flags.db_signal) {
|
||||
stream.write(db_signal_);
|
||||
}
|
||||
if(_radio.flags.rx_flags) {
|
||||
if(((buffer - buffer_start) & 1) == 1) {
|
||||
if (radio_.flags.rx_flags) {
|
||||
if (((buffer - buffer_start) & 1) == 1) {
|
||||
stream.write<uint8_t>(0);
|
||||
}
|
||||
stream.write(_rx_flags);
|
||||
stream.write(rx_flags_);
|
||||
}
|
||||
if(_radio.flags.channel_plus) {
|
||||
if (radio_.flags.channel_plus) {
|
||||
const uint32_t padding = ((stream.pointer() - buffer_start) % 4);
|
||||
if (padding != 0) {
|
||||
stream.fill(4 - padding, 0);
|
||||
}
|
||||
uint32_t dummy = _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));
|
||||
stream.write(dummy);
|
||||
stream.write(_channel_freq);
|
||||
stream.write(_channel);
|
||||
stream.write(_max_power);
|
||||
stream.write(channel_freq_);
|
||||
stream.write(channel_);
|
||||
stream.write(max_power_);
|
||||
}
|
||||
if ((_flags & 0x10) != 0 && inner_pdu()) {
|
||||
if ((flags_ & 0x10) != 0 && inner_pdu()) {
|
||||
uint32_t crc32 = Endian::host_to_le(
|
||||
Utils::crc32(stream.pointer(), inner_pdu()->size())
|
||||
);
|
||||
@@ -537,6 +573,7 @@ void RadioTap::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU
|
||||
stream.write(crc32);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // Tins
|
||||
|
||||
#endif // HAVE_DOT11
|
||||
|
||||
Reference in New Issue
Block a user