diff --git a/include/dot11.h b/include/dot11.h index 0cd404c..a7df46c 100644 --- a/include/dot11.h +++ b/include/dot11.h @@ -177,10 +177,9 @@ namespace Tins { * Constructor that builds a 802.11 PDU taking the destination's and source's MAC. * * \param dst_hw_addr uint8_t array of 6 bytes containing the destination's MAC(optional). - * \param src_hw_addr uint8_t array of 6 bytes containing the source's MAC(optional). * \param child PDU* with the PDU contained by the 802.11 PDU (optional). */ - Dot11(const uint8_t* dst_hw_addr = 0, const uint8_t* src_hw_addr = 0, PDU* child = 0); + Dot11(const uint8_t* dst_hw_addr = 0, PDU* child = 0); /** * \brief Constructor for creating a 802.11 PDU @@ -190,10 +189,9 @@ namespace Tins { * * \param iface string containing the interface's name from where to send the packet. * \param dst_hw_addr uint8_t array of 6 bytes containing the destination's MAC(optional). - * \param src_hw_addr uint8_t array of 6 bytes containing the source's MAC(optional). * \param child PDU* with the PDU contained by the 802.11 PDU (optional). */ - Dot11(const std::string& iface, const uint8_t* dst_hw_addr = 0, const uint8_t* src_hw_addr = 0, PDU* child = 0) throw (std::runtime_error); + Dot11(const std::string& iface, const uint8_t* dst_hw_addr = 0, PDU* child = 0) throw (std::runtime_error); /** * \brief Constructor for creating an 802.11 PDU @@ -203,10 +201,9 @@ namespace Tins { * * \param iface_index const uint32_t with the interface's index from where to send the packet. * \param dst_hw_addr uint8_t array of 6 bytes containing the destination's MAC(optional). - * \param src_hw_addr uint8_t array of 6 bytes containing the source's MAC(optional). * \param child PDU* with the PDU contained by the 802.11 PDU (optional). */ - Dot11(uint32_t iface_index, const uint8_t* dst_hw_addr = 0, const uint8_t* src_hw_addr = 0, PDU* child = 0); + Dot11(uint32_t iface_index, const uint8_t* dst_hw_addr = 0, PDU* child = 0); /** * \brief Constructor which creates an 802.11 object from a buffer and adds all identifiable @@ -215,7 +212,7 @@ namespace Tins { * \param total_sz The total size of the buffer. */ Dot11(const uint8_t *buffer, uint32_t total_sz); - + /** * \brief Copy constructor. */ @@ -232,7 +229,7 @@ namespace Tins { * \brief Copy assignment operator. */ Dot11 &operator= (const Dot11 &other); - + /** * \brief Getter for the protocol version. * @@ -317,41 +314,6 @@ namespace Tins { */ inline const uint8_t* addr1() const { return this->_header.addr1; } - /** - * \brief Getter for the second address. - * - * \return The second address as a constant uint8_t pointer. - */ - inline const uint8_t* addr2() const { return this->_header.addr2; } - - /** - * \brief Getter for the third address. - * - * \return The third address as a constant uint8_t pointer. - */ - inline const uint8_t* addr3() const { return this->_header.addr3; } - - /** - * \brief Getter for the fragment number. - * - * \return The fragment number as an uint8_t. - */ - inline uint8_t frag_num() const { return this->_header.seq_control.frag_number; } - - /** - * \brief Getter for the sequence number. - * - * \return The sequence number as an uint16_t. - */ - inline uint16_t seq_num() const { return Utils::net_to_host_s(this->_header.seq_control.seq_number); } - - /** - * \brief Getter for the fourth address. - * - * \return The fourth address as a constant uint8_t pointer. - */ - inline const uint8_t* addr4() const { return this->_addr4; } - /** * \brief Getter for the interface. * @@ -443,41 +405,6 @@ namespace Tins { */ void addr1(const uint8_t* new_addr1); - /** - * \brief Setter for the second address. - * - * \param new_addr2 const uint8_t array of 6 bytes containing the new second's address. - */ - void addr2(const uint8_t* new_addr2); - - /** - * \brief Setter for the third address. - * - * \param new_addr3 const uint8_t array of 6 bytes containing the new third address. - */ - void addr3(const uint8_t* new_addr3); - - /** - * \brief Setter for the fragment number. - * - * \param new_frag_num uint8_t with the new fragment number. - */ - void frag_num(uint8_t new_frag_num); - - /** - * \brief Setter for the sequence number. - * - * \param new_seq_num uint16_t with the new sequence number. - */ - void seq_num(uint16_t new_seq_num); - - /** - * \brief Setter for the fourth address. - * - * \param new_addr4 const uint8_t array of 6 bytes containing the new fourth address. - */ - void addr4(const uint8_t* new_addr4); - /** * \brief Setter for the interface. * @@ -537,6 +464,7 @@ namespace Tins { */ static PDU *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; } void parse_tagged_parameters(const uint8_t *buffer, uint32_t total_sz); void copy_80211_fields(const Dot11 *other); @@ -574,17 +502,6 @@ namespace Tins { } __attribute__((__packed__)) control; uint16_t duration_id; uint8_t addr1[6]; - uint8_t addr2[6]; - uint8_t addr3[6]; - struct { - #if __BYTE_ORDER == __LITTLE_ENDIAN - unsigned int seq_number:12; - unsigned int frag_number:4; - #elif __BYTE_ORDER == __BIG_ENDIAN - unsigned int frag_number:4; - unsigned int seq_number:12; - #endif - } __attribute__((__packed__)) seq_control; } __attribute__((__packed__)); private: @@ -595,7 +512,6 @@ namespace Tins { ieee80211_header _header; - uint8_t _addr4[6]; uint32_t _iface_index, _options_size; std::list _options; }; @@ -994,7 +910,99 @@ namespace Tins { } __attribute__((__packed__)); + /** + * \brief Getter for the second address. + * + * \return The second address as a constant uint8_t pointer. + */ + inline const uint8_t* addr2() const { return this->_ext_header.addr2; } + + /** + * \brief Getter for the third address. + * + * \return The third address as a constant uint8_t pointer. + */ + inline const uint8_t* addr3() const { return this->_ext_header.addr3; } + + /** + * \brief Getter for the fragment number. + * + * \return The fragment number as an uint8_t. + */ + inline uint8_t frag_num() const { return this->_ext_header.seq_control.frag_number; } + + /** + * \brief Getter for the sequence number. + * + * \return The sequence number as an uint16_t. + */ + inline uint16_t seq_num() const { return Utils::net_to_host_s(this->_ext_header.seq_control.seq_number); } + + /** + * \brief Getter for the fourth address. + * + * \return The fourth address as a constant uint8_t pointer. + */ + inline const uint8_t* addr4() const { return this->_addr4; } + + /** + * \brief Setter for the second address. + * + * \param new_addr2 const uint8_t array of 6 bytes containing the new second's address. + */ + void addr2(const uint8_t* new_addr2); + + /** + * \brief Setter for the third address. + * + * \param new_addr3 const uint8_t array of 6 bytes containing the new third address. + */ + void addr3(const uint8_t* new_addr3); + + /** + * \brief Setter for the fragment number. + * + * \param new_frag_num uint8_t with the new fragment number. + */ + void frag_num(uint8_t new_frag_num); + + /** + * \brief Setter for the sequence number. + * + * \param new_seq_num uint16_t with the new sequence number. + */ + void seq_num(uint16_t new_seq_num); + + /** + * \brief Setter for the fourth address. + * + * \param new_addr4 const uint8_t array of 6 bytes containing the new fourth address. + */ + void addr4(const uint8_t* new_addr4); + + /** + * \brief Returns the 802.11 frame's header length. + * + * \return An uint32_t with the header's size. + * \sa PDU::header_size() + */ + uint32_t header_size() const; + protected: + struct ExtendedHeader { + uint8_t addr2[6]; + uint8_t addr3[6]; + struct { + #if __BYTE_ORDER == __LITTLE_ENDIAN + unsigned int seq_number:12; + unsigned int frag_number:4; + #elif __BYTE_ORDER == __BIG_ENDIAN + unsigned int frag_number:4; + unsigned int seq_number:12; + #endif + } __attribute__((__packed__)) seq_control; + } __attribute__((__packed__)); + /** * \brief Constructor which creates a Dot11ManagementFrame object from a buffer and adds all identifiable * PDUs found in the buffer as children of this one. @@ -1017,12 +1025,131 @@ namespace Tins { void supported_channels(const std::list > &new_channels); void edca_parameter_set(uint32_t ac_be, uint32_t ac_bk, uint32_t ac_vi, uint32_t ac_vo); + uint32_t write_ext_header(uint8_t *buffer, uint32_t total_sz); + void copy_ext_header(const Dot11ManagementFrame *other); private: - + ExtendedHeader _ext_header; + uint8_t _addr4[6]; }; + class Dot11DataFrame : public Dot11 { + + public: + /** + * \brief Getter for the second address. + * + * \return The second address as a constant uint8_t pointer. + */ + inline const uint8_t* addr2() const { return this->_ext_header.addr2; } + + /** + * \brief Getter for the third address. + * + * \return The third address as a constant uint8_t pointer. + */ + inline const uint8_t* addr3() const { return this->_ext_header.addr3; } + + /** + * \brief Getter for the fragment number. + * + * \return The fragment number as an uint8_t. + */ + inline uint8_t frag_num() const { return this->_ext_header.seq_control.frag_number; } + + /** + * \brief Getter for the sequence number. + * + * \return The sequence number as an uint16_t. + */ + inline uint16_t seq_num() const { return Utils::net_to_host_s(this->_ext_header.seq_control.seq_number); } + + /** + * \brief Getter for the fourth address. + * + * \return The fourth address as a constant uint8_t pointer. + */ + inline const uint8_t* addr4() const { return this->_addr4; } + + /** + * \brief Setter for the second address. + * + * \param new_addr2 const uint8_t array of 6 bytes containing the new second's address. + */ + void addr2(const uint8_t* new_addr2); + + /** + * \brief Setter for the third address. + * + * \param new_addr3 const uint8_t array of 6 bytes containing the new third address. + */ + void addr3(const uint8_t* new_addr3); + + /** + * \brief Setter for the fragment number. + * + * \param new_frag_num uint8_t with the new fragment number. + */ + void frag_num(uint8_t new_frag_num); + + /** + * \brief Setter for the sequence number. + * + * \param new_seq_num uint16_t with the new sequence number. + */ + void seq_num(uint16_t new_seq_num); + + /** + * \brief Setter for the fourth address. + * + * \param new_addr4 const uint8_t array of 6 bytes containing the new fourth address. + */ + void addr4(const uint8_t* new_addr4); + + /** + * \brief Returns the 802.11 frame's header length. + * + * \return An uint32_t with the header's size. + * \sa PDU::header_size() + */ + uint32_t header_size() const; + + protected: + struct ExtendedHeader { + uint8_t addr2[6]; + uint8_t addr3[6]; + struct { + #if __BYTE_ORDER == __LITTLE_ENDIAN + unsigned int seq_number:12; + unsigned int frag_number:4; + #elif __BYTE_ORDER == __BIG_ENDIAN + unsigned int frag_number:4; + unsigned int seq_number:12; + #endif + } __attribute__((__packed__)) seq_control; + } __attribute__((__packed__)); + + /** + * \brief Constructor which creates a Dot11DataFrame object from a buffer and adds all identifiable + * PDUs found in the buffer as children of this one. + * \param buffer The buffer from which this PDU will be constructed. + * \param total_sz The total size of the buffer. + */ + Dot11DataFrame(uint32_t iface_index, const uint8_t *dst_hw_addr = 0, const uint8_t *src_hw_addr = 0, PDU* child = 0); + Dot11DataFrame(const uint8_t *dst_hw_addr = 0, const uint8_t *src_hw_addr = 0, PDU* child = 0); + Dot11DataFrame(const std::string &iface, const uint8_t *dst_hw_addr, const uint8_t *src_hw_addr, PDU* child = 0) throw (std::runtime_error); + Dot11DataFrame(const uint8_t *buffer, uint32_t total_sz); + Dot11DataFrame(const Dot11DataFrame &other); + + uint32_t write_ext_header(uint8_t *buffer, uint32_t total_sz); + void copy_ext_header(const Dot11DataFrame *other); + + private: + ExtendedHeader _ext_header; + uint8_t _addr4[6]; + + }; /** * \brief Class representing a Beacon in the IEEE 802.11 Protocol. @@ -1064,12 +1191,12 @@ namespace Tins { * \brief Copy constructor. */ Dot11Beacon(const Dot11Beacon &other); - + /** * \brief Copy assignment operator. */ Dot11Beacon &operator= (const Dot11Beacon &other); - + /** * \brief Getter for the timestamp field. * @@ -1170,8 +1297,8 @@ namespace Tins { void copy_fields(const Dot11Beacon *other); uint32_t write_fixed_parameters(uint8_t *buffer, uint32_t total_sz); - - + + BeaconBody _body; }; @@ -1205,12 +1332,12 @@ namespace Tins { * \brief Copy constructor. */ Dot11Disassoc(const Dot11Disassoc &other); - + /** * \brief Copy assignment operator. */ Dot11Disassoc &operator= (const Dot11Disassoc &other); - + /** * \brief Getter for the reason code. * @@ -1517,7 +1644,7 @@ namespace Tins { AssocRespBody _body; }; - class Dot11QoSData : public Dot11 { + class Dot11QoSData : public Dot11DataFrame { public: @@ -1570,7 +1697,7 @@ namespace Tins { * \brief Copy constructor. */ Dot11QoSData(const Dot11QoSData &other); - + /** * \brief Copy assignment operator. */ @@ -1601,7 +1728,7 @@ namespace Tins { void copy_fields(const Dot11QoSData *other); uint32_t write_fixed_parameters(uint8_t *buffer, uint32_t total_sz); - + uint16_t _qos_control; }; diff --git a/src/dot11.cpp b/src/dot11.cpp index 45e17a5..53f625e 100644 --- a/src/dot11.cpp +++ b/src/dot11.cpp @@ -40,30 +40,24 @@ using namespace std; const uint8_t *Tins::Dot11::BROADCAST = (const uint8_t*)"\xff\xff\xff\xff\xff\xff"; -Tins::Dot11::Dot11(const uint8_t* dst_hw_addr, const uint8_t* src_hw_addr, PDU* child) : PDU(ETHERTYPE_IP, child), _options_size(0) { +Tins::Dot11::Dot11(const uint8_t* dst_hw_addr, PDU* child) : PDU(ETHERTYPE_IP, child), _options_size(0) { memset(&this->_header, 0, sizeof(ieee80211_header)); if(dst_hw_addr) this->addr1(dst_hw_addr); - if(src_hw_addr) - this->addr2(src_hw_addr); } -Tins::Dot11::Dot11(const std::string& iface, const uint8_t* dst_hw_addr, const uint8_t* src_hw_addr, PDU* child) throw (std::runtime_error) : PDU(ETHERTYPE_IP, child), _options_size(0) { +Tins::Dot11::Dot11(const std::string& iface, const uint8_t* dst_hw_addr, PDU* child) throw (std::runtime_error) : PDU(ETHERTYPE_IP, child), _options_size(0) { memset(&this->_header, 0, sizeof(ieee80211_header)); if(dst_hw_addr) this->addr1(dst_hw_addr); - if(src_hw_addr) - this->addr2(src_hw_addr); this->iface(iface); } -Tins::Dot11::Dot11(uint32_t iface_index, const uint8_t* dst_hw_addr, const uint8_t* src_hw_addr, PDU* child) : PDU(ETHERTYPE_IP, child), _options_size(0) { +Tins::Dot11::Dot11(uint32_t iface_index, const uint8_t* dst_hw_addr, PDU* child) : PDU(ETHERTYPE_IP, child), _options_size(0) { memset(&this->_header, 0, sizeof(ieee80211_header)); if(dst_hw_addr) this->addr1(dst_hw_addr); - if(src_hw_addr) - this->addr2(src_hw_addr); this->iface(iface_index); } @@ -182,26 +176,6 @@ void Tins::Dot11::addr1(const uint8_t* new_addr1) { memcpy(this->_header.addr1, new_addr1, 6); } -void Tins::Dot11::addr2(const uint8_t* new_addr2) { - memcpy(this->_header.addr2, new_addr2, 6); -} - -void Tins::Dot11::addr3(const uint8_t* new_addr3) { - memcpy(this->_header.addr3, new_addr3, 6); -} - -void Tins::Dot11::frag_num(uint8_t new_frag_num) { - this->_header.seq_control.frag_number = new_frag_num; -} - -void Tins::Dot11::seq_num(uint16_t new_seq_num) { - this->_header.seq_control.seq_number = Utils::net_to_host_s(new_seq_num); -} - -void Tins::Dot11::addr4(const uint8_t* new_addr4) { - memcpy(this->_addr4, new_addr4, 6); -} - void Tins::Dot11::iface(uint32_t new_iface_index) { this->_iface_index = new_iface_index; } @@ -214,8 +188,6 @@ void Tins::Dot11::iface(const std::string& new_iface) throw (std::runtime_error) uint32_t Tins::Dot11::header_size() const { uint32_t sz = sizeof(ieee80211_header) + _options_size; - if (this->to_ds() && this->from_ds()) - sz += 6; return sz; } @@ -238,11 +210,11 @@ void Tins::Dot11::write_serialization(uint8_t *buffer, uint32_t total_sz, const assert(total_sz >= my_sz); memcpy(buffer, &this->_header, sizeof(ieee80211_header)); buffer += sizeof(ieee80211_header); - if (this->to_ds() && this->from_ds()) { - memcpy(buffer, this->_addr4, 6); - buffer += 6; - total_sz -= 6; - } + total_sz -= sizeof(ieee80211_header); + + uint32_t written = this->write_ext_header(buffer, total_sz); + buffer += written; + total_sz -= written; uint32_t child_len = write_fixed_parameters(buffer, total_sz - sizeof(ieee80211_header) - _options_size); buffer += child_len; @@ -273,7 +245,6 @@ Tins::PDU *Tins::Dot11::from_bytes(const uint8_t *buffer, uint32_t total_sz) { void Tins::Dot11::copy_80211_fields(const Dot11 *other) { std::memcpy(&_header, &other->_header, sizeof(_header)); - std::memcpy(_addr4, other->_addr4, sizeof(_header)); _iface_index = other->_iface_index; _options_size = other->_options_size; for(std::list::const_iterator it = other->_options.begin(); it != other->_options.end(); ++it) @@ -288,18 +259,65 @@ Tins::Dot11ManagementFrame::Dot11ManagementFrame(const uint8_t *buffer, uint32_t } -Tins::Dot11ManagementFrame::Dot11ManagementFrame(const uint8_t *dst_hw_addr, const uint8_t *src_hw_addr) : Dot11(dst_hw_addr, src_hw_addr) { +Tins::Dot11ManagementFrame::Dot11ManagementFrame(const uint8_t *dst_hw_addr, const uint8_t *src_hw_addr) : Dot11(dst_hw_addr) { this->type(Dot11::MANAGEMENT); + this->addr2(src_hw_addr); } Tins::Dot11ManagementFrame::Dot11ManagementFrame(const std::string &iface, const uint8_t *dst_hw_addr, - const uint8_t *src_hw_addr) throw (std::runtime_error) : Dot11(iface, dst_hw_addr, src_hw_addr) { + const uint8_t *src_hw_addr) throw (std::runtime_error) : Dot11(iface, dst_hw_addr) { this->type(Dot11::MANAGEMENT); + this->addr2(src_hw_addr); } Tins::Dot11ManagementFrame::Dot11ManagementFrame(const Dot11ManagementFrame &other) : Dot11(other) { - + +} + +void Tins::Dot11ManagementFrame::copy_ext_header(const Dot11ManagementFrame* other) { + Dot11::copy_80211_fields(other); + std::memcpy(&this->_ext_header, &other->_ext_header, sizeof(this->_ext_header)); + std::memcpy(this->_addr4, other->_addr4, 6); +} + +uint32_t Tins::Dot11ManagementFrame::header_size() const { + uint32_t sz = Dot11::header_size() + sizeof(_ext_header); + if (this->from_ds() && this->to_ds()) + sz += 6; + return sz; +} + +void Tins::Dot11ManagementFrame::addr2(const uint8_t* new_addr2) { + memcpy(this->_ext_header.addr2, new_addr2, 6); +} + +void Tins::Dot11ManagementFrame::addr3(const uint8_t* new_addr3) { + memcpy(this->_ext_header.addr3, new_addr3, 6); +} + +void Tins::Dot11ManagementFrame::frag_num(uint8_t new_frag_num) { + this->_ext_header.seq_control.frag_number = new_frag_num; +} + +void Tins::Dot11ManagementFrame::seq_num(uint16_t new_seq_num) { + this->_ext_header.seq_control.seq_number = Utils::net_to_host_s(new_seq_num); +} + +void Tins::Dot11ManagementFrame::addr4(const uint8_t* new_addr4) { + memcpy(this->_addr4, new_addr4, 6); +} + +uint32_t Tins::Dot11ManagementFrame::write_ext_header(uint8_t *buffer, uint32_t total_sz) { + uint32_t written = sizeof(this->_ext_header); + memcpy(buffer, &this->_ext_header, sizeof(this->_ext_header)); + buffer += sizeof(this->_ext_header); + if (this->from_ds() && this->to_ds()) { + written += 6; + memcpy(buffer, this->_addr4, 6); + } + return written; + } void Tins::Dot11ManagementFrame::ssid(const std::string &new_ssid) { @@ -387,6 +405,82 @@ void Tins::Dot11ManagementFrame::edca_parameter_set(uint32_t ac_be, uint32_t ac_ delete[] buffer; } +/* + * Dot11DataFrame + */ + +Tins::Dot11DataFrame::Dot11DataFrame(const uint8_t *buffer, uint32_t total_sz) : Dot11(buffer, total_sz) { + +} + +Tins::Dot11DataFrame::Dot11DataFrame(uint32_t iface_index, const uint8_t *dst_hw_addr, const uint8_t *src_hw_addr, PDU* child) : Dot11(iface_index, dst_hw_addr, child) { + this->type(Dot11::DATA); + this->addr2(src_hw_addr); +} + +Tins::Dot11DataFrame::Dot11DataFrame(const uint8_t *dst_hw_addr, const uint8_t *src_hw_addr, PDU* child) : Dot11(dst_hw_addr, child) { + this->type(Dot11::DATA); + this->addr2(src_hw_addr); +} + + +Tins::Dot11DataFrame::Dot11DataFrame(const std::string &iface, + const uint8_t *dst_hw_addr, + const uint8_t *src_hw_addr, + PDU* child) throw (std::runtime_error) : Dot11(iface, dst_hw_addr, child) { + this->type(Dot11::DATA); + this->addr2(src_hw_addr); +} + +Tins::Dot11DataFrame::Dot11DataFrame(const Dot11DataFrame &other) : Dot11(other) { + +} + +void Tins::Dot11DataFrame::copy_ext_header(const Dot11DataFrame* other) { + Dot11::copy_80211_fields(other); + std::memcpy(&this->_ext_header, &other->_ext_header, sizeof(this->_ext_header)); + std::memcpy(this->_addr4, other->_addr4, 6); +} + +uint32_t Tins::Dot11DataFrame::header_size() const { + uint32_t sz = Dot11::header_size() + sizeof(_ext_header); + if (this->from_ds() && this->to_ds()) + sz += 6; + return sz; +} + +void Tins::Dot11DataFrame::addr2(const uint8_t* new_addr2) { + memcpy(this->_ext_header.addr2, new_addr2, 6); +} + +void Tins::Dot11DataFrame::addr3(const uint8_t* new_addr3) { + memcpy(this->_ext_header.addr3, new_addr3, 6); +} + +void Tins::Dot11DataFrame::frag_num(uint8_t new_frag_num) { + this->_ext_header.seq_control.frag_number = new_frag_num; +} + +void Tins::Dot11DataFrame::seq_num(uint16_t new_seq_num) { + this->_ext_header.seq_control.seq_number = Utils::net_to_host_s(new_seq_num); +} + +void Tins::Dot11DataFrame::addr4(const uint8_t* new_addr4) { + memcpy(this->_addr4, new_addr4, 6); +} + +uint32_t Tins::Dot11DataFrame::write_ext_header(uint8_t *buffer, uint32_t total_sz) { + uint32_t written = sizeof(this->_ext_header); + memcpy(buffer, &this->_ext_header, sizeof(this->_ext_header)); + buffer += sizeof(this->_ext_header); + if (this->from_ds() && this->to_ds()) { + written += 6; + memcpy(buffer, this->_addr4, 6); + } + return written; + +} + /* * Beacon */ @@ -415,7 +509,7 @@ Tins::Dot11Beacon::Dot11Beacon(const uint8_t *buffer, uint32_t total_sz) : Dot11 } Tins::Dot11Beacon::Dot11Beacon(const Dot11Beacon &other) : Dot11ManagementFrame(other) { - + } Tins::Dot11Beacon &Tins::Dot11Beacon::operator= (const Dot11Beacon &other) { @@ -425,7 +519,7 @@ Tins::Dot11Beacon &Tins::Dot11Beacon::operator= (const Dot11Beacon &other) { } void Tins::Dot11Beacon::copy_fields(const Dot11Beacon *other) { - copy_80211_fields(other); + Dot11ManagementFrame::copy_ext_header(other); std::memcpy(&_body, &other->_body, sizeof(_body)); } @@ -500,7 +594,7 @@ bool Tins::Dot11Beacon::rsn_information(RSNInformation *rsn) { } uint32_t Tins::Dot11Beacon::header_size() const { - return Dot11::header_size() + sizeof(BeaconBody); + return Dot11ManagementFrame::header_size() + sizeof(BeaconBody); } uint32_t Tins::Dot11Beacon::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) { @@ -535,7 +629,7 @@ Tins::Dot11Disassoc &Tins::Dot11Disassoc::operator= (const Dot11Disassoc &other) } void Tins::Dot11Disassoc::copy_fields(const Dot11Disassoc *other) { - copy_80211_fields(other); + Dot11ManagementFrame::copy_ext_header(other); std::memcpy(&_body, &other->_body, sizeof(_body)); } @@ -544,7 +638,7 @@ void Tins::Dot11Disassoc::reason_code(uint16_t new_reason_code) { } uint32_t Tins::Dot11Disassoc::header_size() const { - return Dot11::header_size() + sizeof(DisassocBody); + return Dot11ManagementFrame::header_size() + sizeof(DisassocBody); } uint32_t Tins::Dot11Disassoc::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) { @@ -651,7 +745,7 @@ Tins::Dot11AssocRequest &Tins::Dot11AssocRequest::operator= (const Dot11AssocReq } void Tins::Dot11AssocRequest::copy_fields(const Dot11AssocRequest *other) { - copy_80211_fields(other); + Dot11ManagementFrame::copy_ext_header(other); std::memcpy(&_body, &other->_body, sizeof(_body)); } @@ -688,7 +782,7 @@ void Tins::Dot11AssocRequest::qos_capabilities(uint8_t new_qos_capabilities) { } uint32_t Tins::Dot11AssocRequest::header_size() const { - return Dot11::header_size() + sizeof(AssocReqBody); + return Dot11ManagementFrame::header_size() + sizeof(AssocReqBody); } uint32_t Tins::Dot11AssocRequest::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) { @@ -734,7 +828,7 @@ Tins::Dot11AssocResponse &Tins::Dot11AssocResponse::operator= (const Dot11AssocR } void Tins::Dot11AssocResponse::copy_fields(const Dot11AssocResponse *other) { - copy_80211_fields(other); + Dot11ManagementFrame::copy_ext_header(other); std::memcpy(&_body, &other->_body, sizeof(_body)); } @@ -759,7 +853,7 @@ void Tins::Dot11AssocResponse::edca_parameter_set(uint32_t ac_be, uint32_t ac_bk } uint32_t Tins::Dot11AssocResponse::header_size() const { - return Dot11::header_size() + sizeof(AssocRespBody); + return Dot11ManagementFrame::header_size() + sizeof(AssocRespBody); } uint32_t Tins::Dot11AssocResponse::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) { @@ -771,25 +865,17 @@ uint32_t Tins::Dot11AssocResponse::write_fixed_parameters(uint8_t *buffer, uint3 /* QoS data. */ -Tins::Dot11QoSData::Dot11QoSData(const uint8_t* dst_hw_addr, const uint8_t* src_hw_addr, PDU* child) : Dot11(dst_hw_addr, src_hw_addr, child) { - this->type(Dot11::DATA); +Tins::Dot11QoSData::Dot11QoSData(const std::string& iface, const uint8_t* dst_hw_addr, const uint8_t* src_hw_addr, PDU* child) throw (std::runtime_error) : Dot11DataFrame(iface, dst_hw_addr, src_hw_addr, child) { this->subtype(Dot11::QOS_DATA_DATA); this->_qos_control = 0; } -Tins::Dot11QoSData::Dot11QoSData(const std::string& iface, const uint8_t* dst_hw_addr, const uint8_t* src_hw_addr, PDU* child) throw (std::runtime_error) : Dot11(iface, dst_hw_addr, src_hw_addr, child) { - this->type(Dot11::DATA); +Tins::Dot11QoSData::Dot11QoSData(uint32_t iface_index, const uint8_t* dst_hw_addr, const uint8_t* src_hw_addr, PDU* child) : Dot11DataFrame(iface_index, dst_hw_addr, src_hw_addr, child) { this->subtype(Dot11::QOS_DATA_DATA); this->_qos_control = 0; } -Tins::Dot11QoSData::Dot11QoSData(uint32_t iface_index, const uint8_t* dst_hw_addr, const uint8_t* src_hw_addr, PDU* child) : Dot11(iface_index, dst_hw_addr, src_hw_addr, child) { - this->type(Dot11::DATA); - this->subtype(Dot11::QOS_DATA_DATA); - this->_qos_control = 0; -} - -Tins::Dot11QoSData::Dot11QoSData(const uint8_t *buffer, uint32_t total_sz) : Dot11(buffer, total_sz) { +Tins::Dot11QoSData::Dot11QoSData(const uint8_t *buffer, uint32_t total_sz) : Dot11DataFrame(buffer, total_sz) { buffer += sizeof(ieee80211_header); total_sz -= sizeof(ieee80211_header); assert(total_sz >= sizeof(this->_qos_control)); @@ -800,7 +886,7 @@ Tins::Dot11QoSData::Dot11QoSData(const uint8_t *buffer, uint32_t total_sz) : Dot inner_pdu(new Tins::SNAP(buffer, total_sz)); } -Tins::Dot11QoSData::Dot11QoSData(const Dot11QoSData &other) : Dot11(other) { +Tins::Dot11QoSData::Dot11QoSData(const Dot11QoSData &other) : Dot11DataFrame(other) { copy_fields(&other); } @@ -811,7 +897,7 @@ Tins::Dot11QoSData &Tins::Dot11QoSData::operator= (const Dot11QoSData &other) { } void Tins::Dot11QoSData::copy_fields(const Dot11QoSData *other) { - copy_80211_fields(other); + Dot11DataFrame::copy_ext_header(other); _qos_control = other->_qos_control; }