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

Port Dot11 classes to use OutputMemoryStream

This commit is contained in:
Matias Fontanini
2015-12-26 16:54:35 -08:00
parent 02e2b278de
commit 31ca9a6cc8
16 changed files with 71 additions and 146 deletions

View File

@@ -124,7 +124,7 @@ private:
uint16_t reason_code;
};
uint32_t write_fixed_parameters(uint8_t *buffer, uint32_t total_sz);
void write_fixed_parameters(Memory::OutputMemoryStream& stream);
DisassocBody _body;
};
@@ -235,7 +235,7 @@ private:
uint16_t listen_interval;
};
uint32_t write_fixed_parameters(uint8_t *buffer, uint32_t total_sz);
void write_fixed_parameters(Memory::OutputMemoryStream& stream);
AssocReqBody _body;
};
@@ -361,7 +361,7 @@ private:
uint16_t aid;
};
uint32_t write_fixed_parameters(uint8_t *buffer, uint32_t total_sz);
void write_fixed_parameters(Memory::OutputMemoryStream& stream);
AssocRespBody _body;
};
@@ -487,7 +487,7 @@ private:
uint8_t current_ap[address_type::address_size];
};
uint32_t write_fixed_parameters(uint8_t *buffer, uint32_t total_sz);
void write_fixed_parameters(Memory::OutputMemoryStream& stream);
ReAssocReqBody _body;
};
@@ -613,7 +613,7 @@ private:
uint16_t aid;
};
uint32_t write_fixed_parameters(uint8_t *buffer, uint32_t total_sz);
void write_fixed_parameters(Memory::OutputMemoryStream& stream);
ReAssocRespBody _body;
};

View File

@@ -155,7 +155,7 @@ private:
uint16_t status_code;
};
uint32_t write_fixed_parameters(uint8_t *buffer, uint32_t total_sz);
void write_fixed_parameters(Memory::OutputMemoryStream& stream);
AuthBody _body;
@@ -250,7 +250,7 @@ private:
uint16_t reason_code;
};
uint32_t write_fixed_parameters(uint8_t *buffer, uint32_t total_sz);
void write_fixed_parameters(Memory::OutputMemoryStream& stream);
DeauthBody _body;
};

View File

@@ -44,6 +44,7 @@
namespace Tins {
namespace Memory {
class InputMemoryStream;
class OutputMemoryStream;
} // Memory
class RSNInformation;
@@ -479,8 +480,8 @@ public:
*/
static Dot11 *from_bytes(const uint8_t *buffer, uint32_t total_sz);
protected:
virtual uint32_t write_ext_header(uint8_t *buffer, uint32_t total_sz) { return 0; }
virtual uint32_t write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) { return 0; }
virtual void write_ext_header(Memory::OutputMemoryStream& stream) { }
virtual void write_fixed_parameters(Memory::OutputMemoryStream& stream) { }
void parse_tagged_parameters(Memory::InputMemoryStream& stream);
void add_tagged_option(OptionTypes opt, uint8_t len, const uint8_t *val);
protected:

View File

@@ -157,7 +157,7 @@ namespace Tins {
capability_information capability;
} TINS_END_PACK;
uint32_t write_fixed_parameters(uint8_t *buffer, uint32_t total_sz);
void write_fixed_parameters(Memory::OutputMemoryStream& stream);
BeaconBody _body;
};

View File

@@ -148,7 +148,7 @@ protected:
return static_cast<uint32_t>(_taddr.size() + sizeof(ieee80211_header));
}
uint32_t write_ext_header(uint8_t *buffer, uint32_t total_sz);
void write_ext_header(Memory::OutputMemoryStream& stream);
private:
address_type _taddr;
@@ -582,7 +582,7 @@ public:
return flag == pdu_flag || Dot11Control::matches_flag(flag);
}
protected:
uint32_t write_ext_header(uint8_t *buffer, uint32_t total_sz);
void write_ext_header(Memory::OutputMemoryStream& stream);
private:
void init_block_ack();
@@ -739,7 +739,7 @@ public:
}
private:
void init_block_ack();
uint32_t write_ext_header(uint8_t *buffer, uint32_t total_sz);
void write_ext_header(Memory::OutputMemoryStream& stream);
uint16_t _bar_control, _start_sequence;
uint8_t _bitmap[bitmap_size];

View File

@@ -243,7 +243,7 @@ protected:
Dot11Data(const uint8_t *buffer, uint32_t total_sz, no_inner_pdu);
uint32_t init(const uint8_t *buffer, uint32_t total_sz);
uint32_t write_ext_header(uint8_t *buffer, uint32_t total_sz);
void write_ext_header(Memory::OutputMemoryStream& stream);
uint32_t data_frame_size() {
return static_cast<uint32_t>(
@@ -337,8 +337,7 @@ public:
return flag == PDU::DOT11_QOS_DATA || Dot11Data::matches_flag(flag);
}
private:
uint32_t write_fixed_parameters(uint8_t *buffer, uint32_t total_sz);
void write_fixed_parameters(Memory::OutputMemoryStream& stream);
uint16_t _qos_control;
};

View File

@@ -1160,7 +1160,7 @@ protected:
*/
Dot11ManagementFrame(const uint8_t *buffer, uint32_t total_sz);
uint32_t write_ext_header(uint8_t *buffer, uint32_t total_sz);
void write_ext_header(Memory::OutputMemoryStream& stream);
uint32_t management_frame_size() {
return sizeof(ieee80211_header) + sizeof(_ext_header) +

View File

@@ -227,7 +227,7 @@ private:
ProbeResp _body;
uint32_t write_fixed_parameters(uint8_t *buffer, uint32_t total_sz);
void write_fixed_parameters(Memory::OutputMemoryStream& stream);
};
} // namespace Tins
#endif // TINS_DOT11_DOT11_PROBE_H

View File

@@ -35,6 +35,7 @@
#include "memory_helpers.h"
using Tins::Memory::InputMemoryStream;
using Tins::Memory::OutputMemoryStream;
namespace Tins {
/* Diassoc */
@@ -62,13 +63,8 @@ uint32_t Dot11Disassoc::header_size() const {
return Dot11ManagementFrame::header_size() + sizeof(DisassocBody);
}
uint32_t Dot11Disassoc::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) {
uint32_t sz = sizeof(DisassocBody);
#ifdef TINS_DEBUG
assert(sz <= total_sz);
#endif
memcpy(buffer, &this->_body, sz);
return sz;
void Dot11Disassoc::write_fixed_parameters(OutputMemoryStream& stream) {
stream.write(_body);
}
/* Assoc request. */
@@ -97,13 +93,8 @@ uint32_t Dot11AssocRequest::header_size() const {
return Dot11ManagementFrame::header_size() + sizeof(AssocReqBody);
}
uint32_t Dot11AssocRequest::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) {
uint32_t sz = sizeof(AssocReqBody);
#ifdef TINS_DEBUG
assert(sz <= total_sz);
#endif
memcpy(buffer, &this->_body, sz);
return sz;
void Dot11AssocRequest::write_fixed_parameters(OutputMemoryStream& stream) {
stream.write(_body);
}
/* Assoc response. */
@@ -137,13 +128,8 @@ uint32_t Dot11AssocResponse::header_size() const {
return Dot11ManagementFrame::header_size() + sizeof(AssocRespBody);
}
uint32_t Dot11AssocResponse::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) {
uint32_t sz = sizeof(AssocRespBody);
#ifdef TINS_DEBUG
assert(sz <= total_sz);
#endif
memcpy(buffer, &this->_body, sz);
return sz;
void Dot11AssocResponse::write_fixed_parameters(OutputMemoryStream& stream) {
stream.write(_body);
}
/* ReAssoc request. */
@@ -177,13 +163,8 @@ uint32_t Dot11ReAssocRequest::header_size() const {
return Dot11ManagementFrame::header_size() + sizeof(this->_body);
}
uint32_t Dot11ReAssocRequest::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) {
uint32_t sz = sizeof(this->_body);
#ifdef TINS_DEBUG
assert(sz <= total_sz);
#endif
memcpy(buffer, &this->_body, sz);
return sz;
void Dot11ReAssocRequest::write_fixed_parameters(OutputMemoryStream& stream) {
stream.write(_body);
}
/* ReAssoc response. */
@@ -216,13 +197,8 @@ uint32_t Dot11ReAssocResponse::header_size() const {
return Dot11ManagementFrame::header_size() + sizeof(this->_body);
}
uint32_t Dot11ReAssocResponse::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) {
uint32_t sz = sizeof(this->_body);
#ifdef TINS_DEBUG
assert(sz <= total_sz);
#endif
memcpy(buffer, &this->_body, sz);
return sz;
void Dot11ReAssocResponse::write_fixed_parameters(OutputMemoryStream& stream) {
stream.write(_body);
}
} // namespace Tins

View File

@@ -35,6 +35,7 @@
#include "memory_helpers.h"
using Tins::Memory::InputMemoryStream;
using Tins::Memory::OutputMemoryStream;
namespace Tins {
/* Auth */
@@ -72,13 +73,8 @@ uint32_t Dot11Authentication::header_size() const {
return Dot11ManagementFrame::header_size() + sizeof(_body);
}
uint32_t Dot11Authentication::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) {
uint32_t sz = sizeof(this->_body);
#ifdef TINS_DEBUG
assert(sz <= total_sz);
#endif
memcpy(buffer, &this->_body, sz);
return sz;
void Dot11Authentication::write_fixed_parameters(OutputMemoryStream& stream) {
stream.write(_body);
}
/* Deauth */
@@ -107,13 +103,8 @@ uint32_t Dot11Deauthentication::header_size() const {
return Dot11ManagementFrame::header_size() + sizeof(this->_body);
}
uint32_t Dot11Deauthentication::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) {
uint32_t sz = sizeof(this->_body);
#ifdef TINS_DEBUG
assert(sz <= total_sz);
#endif
memcpy(buffer, &this->_body, sz);
return sz;
void Dot11Deauthentication::write_fixed_parameters(OutputMemoryStream& stream) {
stream.write(_body);
}
} // namespace Tins

View File

@@ -57,6 +57,7 @@
#include "memory_helpers.h"
using Tins::Memory::InputMemoryStream;
using Tins::Memory::OutputMemoryStream;
namespace Tins {
const Dot11::address_type Dot11::BROADCAST = "ff:ff:ff:ff:ff:ff";
@@ -210,27 +211,14 @@ void Dot11::send(PacketSender &sender, const NetworkInterface &iface) {
#endif // _WIN32
void Dot11::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent) {
#ifdef TINS_DEBUG
assert(total_sz >= header_size());
#endif
memcpy(buffer, &_header, sizeof(_header));
buffer += sizeof(_header);
total_sz -= sizeof(_header);
uint32_t written = write_ext_header(buffer, total_sz);
buffer += written;
total_sz -= written;
uint32_t child_len = write_fixed_parameters(buffer, total_sz - _options_size);
buffer += child_len;
#ifdef TINS_DEBUG
assert(total_sz >= child_len + _options_size);
#endif
for(std::list<option>::const_iterator it = _options.begin(); it != _options.end(); ++it) {
*(buffer++) = it->option();
*(buffer++) = static_cast<uint8_t>(it->length_field());
std::copy(it->data_ptr(), it->data_ptr() + it->data_size(), buffer);
buffer += it->data_size();
OutputMemoryStream stream(buffer, total_sz);
stream.write(_header);
write_ext_header(stream);
write_fixed_parameters(stream);
for (std::list<option>::const_iterator it = _options.begin(); it != _options.end(); ++it) {
stream.write<uint8_t>(it->option());
stream.write<uint8_t>(it->length_field());
stream.write(it->data_ptr(), it->data_size());
}
}

View File

@@ -35,6 +35,7 @@
#include "memory_helpers.h"
using Tins::Memory::InputMemoryStream;
using Tins::Memory::OutputMemoryStream;
namespace Tins {
/* Dot11Beacon */
@@ -68,13 +69,8 @@ uint32_t Dot11Beacon::header_size() const {
return Dot11ManagementFrame::header_size() + sizeof(_body);
}
uint32_t Dot11Beacon::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) {
uint32_t sz = sizeof(_body);
#ifdef TINS_DEBUG
assert(sz <= total_sz);
#endif
std::memcpy(buffer, &this->_body, sz);
return sz;
void Dot11Beacon::write_fixed_parameters(OutputMemoryStream& stream) {
stream.write(_body);
}
} // namespace Tins

View File

@@ -35,6 +35,7 @@
#include "memory_helpers.h"
using Tins::Memory::InputMemoryStream;
using Tins::Memory::OutputMemoryStream;
namespace Tins {
/* Dot11Control */
@@ -69,13 +70,8 @@ uint32_t Dot11ControlTA::header_size() const {
return Dot11::header_size() + sizeof(_taddr);
}
uint32_t Dot11ControlTA::write_ext_header(uint8_t *buffer, uint32_t total_sz) {
#ifdef TINS_DEBUG
assert(total_sz >= sizeof(_taddr));
#endif
//std::memcpy(buffer, _taddr, sizeof(_taddr));
_taddr.copy(buffer);
return sizeof(_taddr);
void Dot11ControlTA::write_ext_header(OutputMemoryStream& stream) {
stream.write(_taddr);
}
void Dot11ControlTA::target_addr(const address_type &addr) {
@@ -176,13 +172,10 @@ void Dot11BlockAckRequest::init_block_ack() {
std::memset(&_start_sequence, 0, sizeof(_start_sequence));
}
uint32_t Dot11BlockAckRequest::write_ext_header(uint8_t *buffer, uint32_t total_sz) {
uint32_t parent_size = Dot11ControlTA::write_ext_header(buffer, total_sz);
buffer += parent_size;
std::memcpy(buffer, &_bar_control, sizeof(_bar_control));
buffer += sizeof(_bar_control);
std::memcpy(buffer, &_start_sequence, sizeof(_start_sequence));
return parent_size + sizeof(_start_sequence) + sizeof(_bar_control);
void Dot11BlockAckRequest::write_ext_header(OutputMemoryStream& stream) {
Dot11ControlTA::write_ext_header(stream);
stream.write(_bar_control);
stream.write(_start_sequence);
}
void Dot11BlockAckRequest::bar_control(small_uint<4> bar) {
@@ -259,14 +252,11 @@ void Dot11BlockAck::bitmap(const uint8_t *bit) {
std::memcpy(_bitmap, bit, sizeof(_bitmap));
}
uint32_t Dot11BlockAck::write_ext_header(uint8_t *buffer, uint32_t total_sz) {
uint32_t parent_size = Dot11ControlTA::write_ext_header(buffer, total_sz);
InputMemoryStream stream(buffer, total_sz);
stream.skip(parent_size);
stream.read(_bar_control);
stream.read(_start_sequence);
stream.read(_bitmap);
return total_sz - stream.size();
void Dot11BlockAck::write_ext_header(OutputMemoryStream& stream) {
Dot11ControlTA::write_ext_header(stream);
stream.write(_bar_control);
stream.write(_start_sequence);
stream.write(_bitmap);
}
uint32_t Dot11BlockAck::header_size() const {

View File

@@ -37,6 +37,7 @@
#include "memory_helpers.h"
using Tins::Memory::InputMemoryStream;
using Tins::Memory::OutputMemoryStream;
namespace Tins {
/* Dot11Data */
@@ -118,16 +119,11 @@ void Dot11Data::addr4(const address_type &new_addr4) {
_addr4 = new_addr4;
}
uint32_t Dot11Data::write_ext_header(uint8_t *buffer, uint32_t total_sz) {
uint32_t written = sizeof(_ext_header);
memcpy(buffer, &_ext_header, sizeof(_ext_header));
buffer += sizeof(_ext_header);
void Dot11Data::write_ext_header(OutputMemoryStream& stream) {
stream.write(_ext_header);
if (from_ds() && to_ds()) {
written += static_cast<uint32_t>(_addr4.size());
_addr4.copy(buffer);
stream.write(_addr4);
}
return written;
}
/* QoS data. */
@@ -165,13 +161,8 @@ uint32_t Dot11QoSData::header_size() const {
return Dot11Data::header_size() + sizeof(this->_qos_control);
}
uint32_t Dot11QoSData::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) {
uint32_t sz = sizeof(this->_qos_control);
#ifdef TINS_DEBUG
assert(sz <= total_sz);
#endif
std::memcpy(buffer, &this->_qos_control, sizeof(uint16_t));
return sz;
void Dot11QoSData::write_fixed_parameters(OutputMemoryStream& stream) {
stream.write(_qos_control);
}
} // namespace Tins

View File

@@ -35,6 +35,7 @@
#include "memory_helpers.h"
using Tins::Memory::InputMemoryStream;
using Tins::Memory::OutputMemoryStream;
namespace Tins {
/* Dot11ManagementFrame */
@@ -94,15 +95,11 @@ void Dot11ManagementFrame::addr4(const address_type &new_addr4) {
_addr4 = new_addr4;
}
uint32_t Dot11ManagementFrame::write_ext_header(uint8_t *buffer, uint32_t total_sz) {
uint32_t written = sizeof(_ext_header);
memcpy(buffer, &_ext_header, sizeof(this->_ext_header));
buffer += sizeof(_ext_header);
void Dot11ManagementFrame::write_ext_header(OutputMemoryStream& stream) {
stream.write(_ext_header);
if (from_ds() && to_ds()) {
written += 6;
std::copy(_addr4.begin(), _addr4.end(), buffer);
stream.write(_addr4);
}
return written;
}
void Dot11ManagementFrame::ssid(const std::string &new_ssid) {

View File

@@ -36,6 +36,7 @@
#include "memory_helpers.h"
using Tins::Memory::InputMemoryStream;
using Tins::Memory::OutputMemoryStream;
namespace Tins {
/* Probe Request */
@@ -85,13 +86,8 @@ uint32_t Dot11ProbeResponse::header_size() const {
return Dot11ManagementFrame::header_size() + sizeof(this->_body);
}
uint32_t Dot11ProbeResponse::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) {
uint32_t sz = sizeof(this->_body);
#ifdef TINS_DEBUG
assert(sz <= total_sz);
#endif
memcpy(buffer, &this->_body, sz);
return sz;
void Dot11ProbeResponse::write_fixed_parameters(OutputMemoryStream& stream) {
stream.write(_body);
}
} // namespace Tins