diff --git a/include/tins/dot11/dot11_assoc.h b/include/tins/dot11/dot11_assoc.h index 1aeceec..edc30c3 100644 --- a/include/tins/dot11/dot11_assoc.h +++ b/include/tins/dot11/dot11_assoc.h @@ -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; }; diff --git a/include/tins/dot11/dot11_auth.h b/include/tins/dot11/dot11_auth.h index ff206f5..5f6dcb3 100644 --- a/include/tins/dot11/dot11_auth.h +++ b/include/tins/dot11/dot11_auth.h @@ -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; }; diff --git a/include/tins/dot11/dot11_base.h b/include/tins/dot11/dot11_base.h index a17fc36..af6c050 100644 --- a/include/tins/dot11/dot11_base.h +++ b/include/tins/dot11/dot11_base.h @@ -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: diff --git a/include/tins/dot11/dot11_beacon.h b/include/tins/dot11/dot11_beacon.h index 0d0529e..bd44400 100644 --- a/include/tins/dot11/dot11_beacon.h +++ b/include/tins/dot11/dot11_beacon.h @@ -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; }; diff --git a/include/tins/dot11/dot11_control.h b/include/tins/dot11/dot11_control.h index 5e11068..7528de6 100644 --- a/include/tins/dot11/dot11_control.h +++ b/include/tins/dot11/dot11_control.h @@ -148,7 +148,7 @@ protected: return static_cast(_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]; diff --git a/include/tins/dot11/dot11_data.h b/include/tins/dot11/dot11_data.h index 68ad45c..7482a1a 100644 --- a/include/tins/dot11/dot11_data.h +++ b/include/tins/dot11/dot11_data.h @@ -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( @@ -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; }; diff --git a/include/tins/dot11/dot11_mgmt.h b/include/tins/dot11/dot11_mgmt.h index 8d10777..ae0bcd6 100644 --- a/include/tins/dot11/dot11_mgmt.h +++ b/include/tins/dot11/dot11_mgmt.h @@ -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) + diff --git a/include/tins/dot11/dot11_probe.h b/include/tins/dot11/dot11_probe.h index 34a9896..2cd0044 100644 --- a/include/tins/dot11/dot11_probe.h +++ b/include/tins/dot11/dot11_probe.h @@ -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 diff --git a/src/dot11/dot11_assoc.cpp b/src/dot11/dot11_assoc.cpp index 80260a3..da923d2 100644 --- a/src/dot11/dot11_assoc.cpp +++ b/src/dot11/dot11_assoc.cpp @@ -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 diff --git a/src/dot11/dot11_auth.cpp b/src/dot11/dot11_auth.cpp index e9f9321..892fcd0 100644 --- a/src/dot11/dot11_auth.cpp +++ b/src/dot11/dot11_auth.cpp @@ -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 diff --git a/src/dot11/dot11_base.cpp b/src/dot11/dot11_base.cpp index aa6e958..98defe8 100644 --- a/src/dot11/dot11_base.cpp +++ b/src/dot11/dot11_base.cpp @@ -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