1
0
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:
Matias Fontanini
2016-01-02 08:17:59 -08:00
parent f5a82b1a17
commit d84f10cf08
177 changed files with 13203 additions and 12272 deletions

View File

@@ -30,237 +30,225 @@
#include "dot11/dot11_control.h"
#ifdef HAVE_DOT11
#include <cstring>
#include <algorithm>
#include "memory_helpers.h"
using std::copy;
using Tins::Memory::InputMemoryStream;
using Tins::Memory::OutputMemoryStream;
namespace Tins {
/* Dot11Control */
Dot11Control::Dot11Control(const address_type &dst_addr)
: Dot11(dst_addr)
{
// Dot11Control
Dot11Control::Dot11Control(const address_type& dst_addr)
: Dot11(dst_addr) {
type(CONTROL);
}
Dot11Control::Dot11Control(const uint8_t *buffer, uint32_t total_sz)
Dot11Control::Dot11Control(const uint8_t* buffer, uint32_t total_sz)
: Dot11(buffer, total_sz) {
}
/* Dot11ControlTA */
// Dot11ControlTA
Dot11ControlTA::Dot11ControlTA(const address_type &dst_addr,
const address_type &target_address)
: Dot11Control(dst_addr)
{
Dot11ControlTA::Dot11ControlTA(const address_type& dst_addr,
const address_type& target_address)
: Dot11Control(dst_addr) {
target_addr(target_address);
}
Dot11ControlTA::Dot11ControlTA(const uint8_t *buffer, uint32_t total_sz) : Dot11Control(buffer, total_sz) {
Dot11ControlTA::Dot11ControlTA(const uint8_t* buffer, uint32_t total_sz) : Dot11Control(buffer, total_sz) {
InputMemoryStream stream(buffer, total_sz);
stream.skip(sizeof(ieee80211_header));
stream.read(_taddr);
stream.skip(sizeof(dot11_header));
stream.read(taddr_);
}
uint32_t Dot11ControlTA::header_size() const {
return Dot11::header_size() + sizeof(_taddr);
return Dot11::header_size() + taddr_.size();
}
void Dot11ControlTA::write_ext_header(OutputMemoryStream& stream) {
stream.write(_taddr);
stream.write(taddr_);
}
void Dot11ControlTA::target_addr(const address_type &addr) {
_taddr = addr;
void Dot11ControlTA::target_addr(const address_type& addr) {
taddr_ = addr;
}
/* Dot11RTS */
// Dot11RTS
Dot11RTS::Dot11RTS(const address_type &dst_addr,
const address_type &target_addr)
: Dot11ControlTA(dst_addr, target_addr)
{
Dot11RTS::Dot11RTS(const address_type& dst_addr,
const address_type& target_addr)
: Dot11ControlTA(dst_addr, target_addr) {
subtype(RTS);
}
Dot11RTS::Dot11RTS(const uint8_t *buffer, uint32_t total_sz)
Dot11RTS::Dot11RTS(const uint8_t* buffer, uint32_t total_sz)
: Dot11ControlTA(buffer, total_sz) {
}
/* Dot11PSPoll */
// Dot11PSPoll
Dot11PSPoll::Dot11PSPoll(const address_type &dst_addr,
const address_type &target_addr)
: Dot11ControlTA(dst_addr, target_addr)
{
Dot11PSPoll::Dot11PSPoll(const address_type& dst_addr,
const address_type& target_addr)
: Dot11ControlTA(dst_addr, target_addr) {
subtype(PS);
}
Dot11PSPoll::Dot11PSPoll(const uint8_t *buffer, uint32_t total_sz)
Dot11PSPoll::Dot11PSPoll(const uint8_t* buffer, uint32_t total_sz)
: Dot11ControlTA(buffer, total_sz) {
}
/* Dot11CFEnd */
// Dot11CFEnd
Dot11CFEnd::Dot11CFEnd(const address_type &dst_addr,
const address_type &target_addr)
: Dot11ControlTA(dst_addr, target_addr)
{
Dot11CFEnd::Dot11CFEnd(const address_type& dst_addr,
const address_type& target_addr)
: Dot11ControlTA(dst_addr, target_addr) {
subtype(CF_END);
}
Dot11CFEnd::Dot11CFEnd(const uint8_t *buffer, uint32_t total_sz)
Dot11CFEnd::Dot11CFEnd(const uint8_t* buffer, uint32_t total_sz)
: Dot11ControlTA(buffer, total_sz) {
}
/* Dot11EndCFAck */
// Dot11EndCFAck
Dot11EndCFAck::Dot11EndCFAck(const address_type &dst_addr,
const address_type &target_addr)
: Dot11ControlTA(dst_addr, target_addr)
{
Dot11EndCFAck::Dot11EndCFAck(const address_type& dst_addr,
const address_type& target_addr)
: Dot11ControlTA(dst_addr, target_addr) {
subtype(CF_END_ACK);
}
Dot11EndCFAck::Dot11EndCFAck(const uint8_t *buffer, uint32_t total_sz)
Dot11EndCFAck::Dot11EndCFAck(const uint8_t* buffer, uint32_t total_sz)
: Dot11ControlTA(buffer, total_sz) {
}
/* Dot11Ack */
// Dot11Ack
Dot11Ack::Dot11Ack(const address_type &dst_addr)
: Dot11Control(dst_addr)
{
Dot11Ack::Dot11Ack(const address_type& dst_addr)
: Dot11Control(dst_addr) {
subtype(ACK);
}
Dot11Ack::Dot11Ack(const uint8_t *buffer, uint32_t total_sz)
: Dot11Control(buffer, total_sz)
{
Dot11Ack::Dot11Ack(const uint8_t* buffer, uint32_t total_sz)
: Dot11Control(buffer, total_sz) {
}
/* Dot11BlockAck */
// Dot11BlockAck
Dot11BlockAckRequest::Dot11BlockAckRequest(const address_type &dst_addr,
const address_type &target_addr)
: Dot11ControlTA(dst_addr, target_addr)
{
init_block_ack();
Dot11BlockAckRequest::Dot11BlockAckRequest(const address_type& dst_addr,
const address_type& target_addr)
: Dot11ControlTA(dst_addr, target_addr), bar_control_(0), start_sequence_(0) {
subtype(BLOCK_ACK_REQ);
}
Dot11BlockAckRequest::Dot11BlockAckRequest(const uint8_t *buffer, uint32_t total_sz)
: Dot11ControlTA(buffer, total_sz)
{
Dot11BlockAckRequest::Dot11BlockAckRequest(const uint8_t* buffer, uint32_t total_sz)
: Dot11ControlTA(buffer, total_sz) {
InputMemoryStream stream(buffer, total_sz);
stream.skip(controlta_size());
stream.read(_bar_control);
stream.read(_start_sequence);
}
void Dot11BlockAckRequest::init_block_ack() {
subtype(BLOCK_ACK_REQ);
std::memset(&_bar_control, 0, sizeof(_bar_control));
std::memset(&_start_sequence, 0, sizeof(_start_sequence));
stream.read(bar_control_);
stream.read(start_sequence_);
}
void Dot11BlockAckRequest::write_ext_header(OutputMemoryStream& stream) {
Dot11ControlTA::write_ext_header(stream);
stream.write(_bar_control);
stream.write(_start_sequence);
stream.write(bar_control_);
stream.write(start_sequence_);
}
void Dot11BlockAckRequest::bar_control(small_uint<4> bar) {
#if TINS_IS_LITTLE_ENDIAN
_bar_control = bar | (_bar_control & 0xfff0);
bar_control_ = bar | (bar_control_ & 0xfff0);
#else
_bar_control = (bar << 8) | (_bar_control & 0xf0ff);
bar_control_ = (bar << 8) | (bar_control_ & 0xf0ff);
#endif
}
void Dot11BlockAckRequest::start_sequence(small_uint<12> seq) {
#if TINS_IS_LITTLE_ENDIAN
_start_sequence = (seq << 4) | (_start_sequence & 0xf);
start_sequence_ = (seq << 4) | (start_sequence_ & 0xf);
#else
_start_sequence = Endian::host_to_le<uint16_t>(seq << 4) | (_start_sequence & 0xf00);
start_sequence_ = Endian::host_to_le<uint16_t>(seq << 4) | (start_sequence_ & 0xf00);
#endif
}
void Dot11BlockAckRequest::fragment_number(small_uint<4> frag) {
#if TINS_IS_LITTLE_ENDIAN
_start_sequence = frag | (_start_sequence & 0xfff0);
start_sequence_ = frag | (start_sequence_ & 0xfff0);
#else
_start_sequence = (frag << 8) | (_start_sequence & 0xf0ff);
start_sequence_ = (frag << 8) | (start_sequence_ & 0xf0ff);
#endif
}
uint32_t Dot11BlockAckRequest::header_size() const {
return Dot11ControlTA::header_size() + sizeof(_start_sequence) + sizeof(_start_sequence);
return Dot11ControlTA::header_size() + sizeof(start_sequence_) + sizeof(start_sequence_);
}
/* Dot11BlockAck */
// Dot11BlockAck
Dot11BlockAck::Dot11BlockAck(const address_type &dst_addr,
const address_type &target_addr)
: Dot11ControlTA(dst_addr, target_addr)
{
Dot11BlockAck::Dot11BlockAck(const address_type& dst_addr,
const address_type& target_addr)
: Dot11ControlTA(dst_addr, target_addr), bitmap_() {
subtype(BLOCK_ACK);
std::memset(_bitmap, 0, sizeof(_bitmap));
}
Dot11BlockAck::Dot11BlockAck(const uint8_t *buffer, uint32_t total_sz) : Dot11ControlTA(buffer, total_sz) {
Dot11BlockAck::Dot11BlockAck(const uint8_t* buffer, uint32_t total_sz)
: Dot11ControlTA(buffer, total_sz) {
InputMemoryStream stream(buffer, total_sz);
stream.skip(controlta_size());
stream.read(_bar_control);
stream.read(_start_sequence);
stream.read(_bitmap);
stream.read(bar_control_);
stream.read(start_sequence_);
stream.read(bitmap_);
}
void Dot11BlockAck::bar_control(small_uint<4> bar) {
#if TINS_IS_LITTLE_ENDIAN
_bar_control = bar | (_bar_control & 0xfff0);
bar_control_ = bar | (bar_control_ & 0xfff0);
#else
_bar_control = (bar << 8) | (_bar_control & 0xf0ff);
bar_control_ = (bar << 8) | (bar_control_ & 0xf0ff);
#endif
}
void Dot11BlockAck::start_sequence(small_uint<12> seq) {
#if TINS_IS_LITTLE_ENDIAN
_start_sequence = (seq << 4) | (_start_sequence & 0xf);
start_sequence_ = (seq << 4) | (start_sequence_ & 0xf);
#else
_start_sequence = Endian::host_to_le<uint16_t>(seq << 4) | (_start_sequence & 0xf00);
start_sequence_ = Endian::host_to_le<uint16_t>(seq << 4) | (start_sequence_ & 0xf00);
#endif
}
void Dot11BlockAck::fragment_number(small_uint<4> frag) {
#if TINS_IS_LITTLE_ENDIAN
_start_sequence = frag | (_start_sequence & 0xfff0);
start_sequence_ = frag | (start_sequence_ & 0xfff0);
#else
_start_sequence = (frag << 8) | (_start_sequence & 0xf0ff);
start_sequence_ = (frag << 8) | (start_sequence_ & 0xf0ff);
#endif
}
void Dot11BlockAck::bitmap(const uint8_t *bit) {
std::memcpy(_bitmap, bit, sizeof(_bitmap));
void Dot11BlockAck::bitmap(const uint8_t* bit) {
copy(bit, bit + bitmap_size, bitmap_);
}
void Dot11BlockAck::write_ext_header(OutputMemoryStream& stream) {
Dot11ControlTA::write_ext_header(stream);
stream.write(_bar_control);
stream.write(_start_sequence);
stream.write(_bitmap);
stream.write(bar_control_);
stream.write(start_sequence_);
stream.write(bitmap_);
}
uint32_t Dot11BlockAck::header_size() const {
return Dot11ControlTA::header_size() + sizeof(_start_sequence) + sizeof(_start_sequence) + sizeof(_bitmap);
return Dot11ControlTA::header_size() + sizeof(start_sequence_) +
sizeof(start_sequence_) + sizeof(bitmap_);
}
} // namespace Tins
} // Tins
#endif // HAVE_DOT11