diff --git a/include/dot11.h b/include/dot11.h index d052dba..7e79a83 100644 --- a/include/dot11.h +++ b/include/dot11.h @@ -435,7 +435,7 @@ namespace Tins { * \brief Getter for the PDU's type. * \sa PDU::pdu_type */ - PDUType pdu_type() const { return PDU::DOT11; } + PDUType pdu_type() const { return pdu_flag; } /** * \brief Check wether this PDU matches the specified flag. @@ -443,7 +443,7 @@ namespace Tins { * \sa PDU::matches_flag */ bool matches_flag(PDUType flag) { - return flag == PDU::DOT11; + return flag == pdu_flag; } /** @@ -1535,7 +1535,7 @@ namespace Tins { * * \sa PDU::pdu_type */ - PDUType pdu_type() const { return PDU::DOT11_MANAGEMENT; } + PDUType pdu_type() const { return pdu_flag; } /** * \brief Check wether this PDU matches the specified flag. @@ -1543,7 +1543,7 @@ namespace Tins { * \sa PDU::matches_flag */ bool matches_flag(PDUType flag) { - return flag == PDU::DOT11_MANAGEMENT || Dot11::matches_flag(flag); + return flag == pdu_flag || Dot11::matches_flag(flag); } protected: struct ExtendedHeader { @@ -1680,7 +1680,7 @@ namespace Tins { * \sa PDU::matches_flag */ bool matches_flag(PDUType flag) { - return flag == PDU::DOT11_BEACON || Dot11ManagementFrame::matches_flag(flag); + return flag == pdu_flag || Dot11ManagementFrame::matches_flag(flag); } /** @@ -1689,14 +1689,14 @@ namespace Tins { * \sa PDU::clone_pdu */ Dot11Beacon *clone_pdu() const { - return PDU::do_clone_pdu(); + return new Dot11Beacon(*this); } /** * \brief Getter for the PDU's type. * \sa PDU::pdu_type */ - PDUType pdu_type() const { return PDU::DOT11_BEACON; } + PDUType pdu_type() const { return pdu_flag; } private: struct BeaconBody { uint64_t timestamp; @@ -1769,7 +1769,7 @@ namespace Tins { * \brief Getter for the PDU's type. * \sa PDU::pdu_type */ - PDUType pdu_type() const { return PDU::DOT11_DIASSOC; } + PDUType pdu_type() const { return pdu_flag; } /** * \brief Check wether this PDU matches the specified flag. @@ -1786,7 +1786,7 @@ namespace Tins { * \sa PDU::clone_pdu */ Dot11Disassoc *clone_pdu() const { - return PDU::do_clone_pdu(); + return new Dot11Disassoc(*this); } private: struct DisassocBody { @@ -1851,7 +1851,7 @@ namespace Tins { * * \return The listen interval in an uint16_t. */ - uint16_t listen_interval() const { return _body.listen_interval; } + uint16_t listen_interval() const { return Utils::le_to_host(_body.listen_interval); } /** * \brief Setter for the listen interval. @@ -1872,7 +1872,7 @@ namespace Tins { * \brief Getter for the PDU's type. * \sa PDU::pdu_type */ - PDUType pdu_type() const { return PDU::DOT11_ASSOC_REQ; } + PDUType pdu_type() const { return pdu_flag; } /** * \brief Check wether this PDU matches the specified flag. @@ -1888,7 +1888,9 @@ namespace Tins { * * \sa PDU::clone_pdu */ - PDU *clone_pdu() const; + Dot11AssocRequest *clone_pdu() const { + return new Dot11AssocRequest(*this); + } private: struct AssocReqBody { CapabilityInformation capability; @@ -1953,14 +1955,14 @@ namespace Tins { * * \return The status code in an uint16_t. */ - uint16_t status_code() const { return _body.status_code; } + uint16_t status_code() const { return Utils::le_to_host(_body.status_code); } /** * \brief Getter for the AID field. * * \return The AID field value in an uint16_t. */ - uint16_t aid() const { return _body.aid; } + uint16_t aid() const { return Utils::le_to_host(_body.aid); } /** * \brief Setter for the status code. @@ -1988,7 +1990,7 @@ namespace Tins { * \brief Getter for the PDU's type. * \sa PDU::pdu_type */ - PDUType pdu_type() const { return PDU::DOT11_ASSOC_RESP; } + PDUType pdu_type() const { return pdu_flag; } /** * \brief Check wether this PDU matches the specified flag. @@ -1996,7 +1998,7 @@ namespace Tins { * \sa PDU::matches_flag */ bool matches_flag(PDUType flag) { - return flag == PDU::DOT11_ASSOC_RESP || Dot11ManagementFrame::matches_flag(flag); + return flag == pdu_flag || Dot11ManagementFrame::matches_flag(flag); } /** @@ -2004,7 +2006,9 @@ namespace Tins { * * \sa PDU::clone_pdu */ - PDU *clone_pdu() const; + Dot11AssocResponse *clone_pdu() const { + return new Dot11AssocResponse(*this); + } private: struct AssocRespBody { CapabilityInformation capability; @@ -2070,14 +2074,14 @@ namespace Tins { * * \return The listen interval in an uint16_t. */ - uint16_t listen_interval() const { return _body.listen_interval; } + uint16_t listen_interval() const { return Utils::le_to_host(_body.listen_interval); } /** * \brief Getter for the current ap field. * * \return The current ap in an array of 6 uint8_t. */ - const uint8_t* current_ap() const { return _body.current_ap; } + address_type current_ap() const { return _body.current_ap; } /** * \brief Setter for the listen interval. @@ -2091,7 +2095,7 @@ namespace Tins { * * \param new_current_ap uint8_t array of 6 bytes with the new current ap. */ - void current_ap(uint8_t* new_current_ap); + void current_ap(const address_type &new_current_ap); /** * \brief Returns the frame's header length. @@ -2105,7 +2109,7 @@ namespace Tins { * \brief Getter for the PDU's type. * \sa PDU::pdu_type */ - PDUType pdu_type() const { return PDU::DOT11_REASSOC_REQ; } + PDUType pdu_type() const { return pdu_flag; } /** * \brief Check wether this PDU matches the specified flag. @@ -2113,7 +2117,7 @@ namespace Tins { * \sa PDU::matches_flag */ bool matches_flag(PDUType flag) { - return flag == PDU::DOT11_REASSOC_REQ || Dot11ManagementFrame::matches_flag(flag); + return flag == pdu_flag || Dot11ManagementFrame::matches_flag(flag); } /** @@ -2121,12 +2125,14 @@ namespace Tins { * * \sa PDU::clone_pdu */ - PDU *clone_pdu() const; + Dot11ReAssocRequest *clone_pdu() const { + return new Dot11ReAssocRequest(*this); + } private: struct ReAssocReqBody { CapabilityInformation capability; uint16_t listen_interval; - uint8_t current_ap[6]; + uint8_t current_ap[address_type::address_size]; }; uint32_t write_fixed_parameters(uint8_t *buffer, uint32_t total_sz); @@ -2187,14 +2193,14 @@ namespace Tins { * * \return The status code in an uint16_t. */ - uint16_t status_code() const { return _body.status_code; } + uint16_t status_code() const { return Utils::le_to_host(_body.status_code); } /** * \brief Getter for the AID field. * * \return The AID field value in an uint16_t. */ - uint16_t aid() const { return _body.aid; } + uint16_t aid() const { return Utils::le_to_host(_body.aid); } /** * \brief Setter for the status code. @@ -2222,7 +2228,7 @@ namespace Tins { * \brief Getter for the PDU's type. * \sa PDU::pdu_type */ - PDUType pdu_type() const { return PDU::DOT11_ASSOC_RESP; } + PDUType pdu_type() const { return pdu_flag; } /** * \brief Check wether this PDU matches the specified flag. @@ -2230,7 +2236,7 @@ namespace Tins { * \sa PDU::matches_flag */ bool matches_flag(PDUType flag) { - return flag == PDU::DOT11_ASSOC_RESP || Dot11ManagementFrame::matches_flag(flag); + return flag == pdu_flag || Dot11ManagementFrame::matches_flag(flag); } /** @@ -2238,7 +2244,9 @@ namespace Tins { * * \sa PDU::clone_pdu */ - PDU *clone_pdu() const; + Dot11ReAssocResponse *clone_pdu() const { + return new Dot11ReAssocResponse(*this); + } private: struct ReAssocRespBody { CapabilityInformation capability; @@ -2290,21 +2298,21 @@ namespace Tins { * * \return The authentication algorithm number in an uint16_t. */ - uint16_t auth_algorithm() const {return _body.auth_algorithm; } + uint16_t auth_algorithm() const {return Utils::le_to_host(_body.auth_algorithm); } /** * \brief Getter for the Authetication Sequence Number. * * \return The authentication sequence number in an uint16_t. */ - uint16_t auth_seq_number() const {return _body.auth_seq_number; } + uint16_t auth_seq_number() const {return Utils::le_to_host(_body.auth_seq_number); } /** * \brief Getter for the status code. * * \return The status code in an uint16_t. */ - uint16_t status_code() const { return _body.status_code; } + uint16_t status_code() const { return Utils::le_to_host(_body.status_code); } /** * \brief Setter for the Authetication Algorithm Number. @@ -2339,7 +2347,7 @@ namespace Tins { * \brief Getter for the PDU's type. * \sa PDU::pdu_type */ - PDUType pdu_type() const { return PDU::DOT11_AUTH; } + PDUType pdu_type() const { return pdu_flag; } /** * \brief Check wether this PDU matches the specified flag. @@ -2347,7 +2355,7 @@ namespace Tins { * \sa PDU::matches_flag */ bool matches_flag(PDUType flag) { - return flag == PDU::DOT11_AUTH || Dot11ManagementFrame::matches_flag(flag); + return flag == pdu_flag || Dot11ManagementFrame::matches_flag(flag); } /** @@ -2355,7 +2363,9 @@ namespace Tins { * * \sa PDU::clone_pdu */ - PDU *clone_pdu() const; + Dot11Authentication *clone_pdu() const { + return new Dot11Authentication(*this); + } private: struct AuthBody { uint16_t auth_algorithm; @@ -2408,7 +2418,7 @@ namespace Tins { * * \return uint16_t with the reason code. */ - uint16_t reason_code() const { return _body.reason_code; } + uint16_t reason_code() const { return Utils::le_to_host(_body.reason_code); } /** * \brief Setter for the reason code. @@ -2429,7 +2439,7 @@ namespace Tins { * \brief Getter for the PDU's type. * \sa PDU::pdu_type */ - PDUType pdu_type() const { return PDU::DOT11_DEAUTH; } + PDUType pdu_type() const { return pdu_flag; } /** * \brief Check wether this PDU matches the specified flag. @@ -2437,7 +2447,7 @@ namespace Tins { * \sa PDU::matches_flag */ bool matches_flag(PDUType flag) { - return flag == PDU::DOT11_DEAUTH || Dot11ManagementFrame::matches_flag(flag); + return flag == pdu_flag || Dot11ManagementFrame::matches_flag(flag); } /** @@ -2445,7 +2455,9 @@ namespace Tins { * * \sa PDU::clone_pdu */ - PDU *clone_pdu() const; + Dot11Deauthentication *clone_pdu() const { + return new Dot11Deauthentication(*this); + } private: struct DeauthBody { uint16_t reason_code; diff --git a/include/pdu.h b/include/pdu.h index 4cb0e3d..a93d88b 100644 --- a/include/pdu.h +++ b/include/pdu.h @@ -307,7 +307,7 @@ namespace Tins { template T *do_clone_pdu() const { T *new_pdu = new T(*static_cast(this)); - new_pdu->copy_inner_pdu(*this); + //new_pdu->copy_inner_pdu(*this); return new_pdu; } private: diff --git a/src/dot11.cpp b/src/dot11.cpp index 317283e..77a60dc 100644 --- a/src/dot11.cpp +++ b/src/dot11.cpp @@ -215,9 +215,21 @@ PDU *Dot11::from_bytes(const uint8_t *buffer, uint32_t total_sz) { if(hdr->control.type == MANAGEMENT) { if(hdr->control.subtype == BEACON) ret = new Dot11Beacon(buffer, total_sz); - //else if(hdr->control.subtype == DISASSOC) - else + else if(hdr->control.subtype == DISASSOC) ret = new Dot11Disassoc(buffer, total_sz); + else if(hdr->control.subtype == ASSOC_REQ) + ret = new Dot11AssocRequest(buffer, total_sz); + else if(hdr->control.subtype == ASSOC_RESP) + ret = new Dot11AssocResponse(buffer, total_sz); + else if(hdr->control.subtype == REASSOC_REQ) + ret = new Dot11ReAssocRequest(buffer, total_sz); + else if(hdr->control.subtype == REASSOC_RESP) + ret = new Dot11ReAssocResponse(buffer, total_sz); + else if(hdr->control.subtype == AUTH) + ret = new Dot11Authentication(buffer, total_sz); + //else if(hdr->control.subtype == DEAUTH) + else + ret = new Dot11Deauthentication(buffer, total_sz); } else if(hdr->control.type == DATA){ if(hdr->control.subtype <= 4) @@ -939,7 +951,7 @@ Dot11AssocRequest::Dot11AssocRequest(const uint8_t *buffer, uint32_t total_sz) : } void Dot11AssocRequest::listen_interval(uint16_t new_listen_interval) { - this->_body.listen_interval = new_listen_interval; + this->_body.listen_interval = Utils::host_to_le(new_listen_interval); } uint32_t Dot11AssocRequest::header_size() const { @@ -953,14 +965,6 @@ uint32_t Dot11AssocRequest::write_fixed_parameters(uint8_t *buffer, uint32_t tot return sz; } -PDU *Dot11AssocRequest::clone_pdu() const { - Dot11AssocRequest *new_pdu = new Dot11AssocRequest(); - new_pdu->copy_80211_fields(this); - new_pdu->copy_ext_header(this); - std::memcpy(&new_pdu->_body, &_body, sizeof(_body)); - return new_pdu; -} - /* Assoc response. */ Dot11AssocResponse::Dot11AssocResponse(const NetworkInterface& iface, @@ -986,11 +990,11 @@ Dot11AssocResponse::Dot11AssocResponse(const uint8_t *buffer, uint32_t total_sz) } void Dot11AssocResponse::status_code(uint16_t new_status_code) { - this->_body.status_code = new_status_code; + this->_body.status_code = Utils::host_to_le(new_status_code); } void Dot11AssocResponse::aid(uint16_t new_aid) { - this->_body.aid = new_aid; + this->_body.aid = Utils::host_to_le(new_aid); } uint32_t Dot11AssocResponse::header_size() const { @@ -1004,14 +1008,6 @@ uint32_t Dot11AssocResponse::write_fixed_parameters(uint8_t *buffer, uint32_t to return sz; } -PDU *Dot11AssocResponse::clone_pdu() const { - Dot11AssocResponse *new_pdu = new Dot11AssocResponse(); - new_pdu->copy_80211_fields(this); - new_pdu->copy_ext_header(this); - std::memcpy(&new_pdu->_body, &_body, sizeof(_body)); - return new_pdu; -} - /* ReAssoc request. */ Dot11ReAssocRequest::Dot11ReAssocRequest(const NetworkInterface& iface, @@ -1037,11 +1033,11 @@ Dot11ReAssocRequest::Dot11ReAssocRequest(const uint8_t *buffer, uint32_t total_s } void Dot11ReAssocRequest::listen_interval(uint16_t new_listen_interval) { - this->_body.listen_interval = new_listen_interval; + this->_body.listen_interval = Utils::host_to_le(new_listen_interval); } -void Dot11ReAssocRequest::current_ap(uint8_t* new_current_ap) { - memcpy(this->_body.current_ap, new_current_ap, 6); +void Dot11ReAssocRequest::current_ap(const address_type &new_current_ap) { + new_current_ap.copy(_body.current_ap); } uint32_t Dot11ReAssocRequest::header_size() const { @@ -1055,14 +1051,6 @@ uint32_t Dot11ReAssocRequest::write_fixed_parameters(uint8_t *buffer, uint32_t t return sz; } -PDU *Dot11ReAssocRequest::clone_pdu() const { - Dot11ReAssocRequest *new_pdu = new Dot11ReAssocRequest(); - new_pdu->copy_80211_fields(this); - new_pdu->copy_ext_header(this); - std::memcpy(&new_pdu->_body, &_body, sizeof(_body)); - return new_pdu; -} - /* ReAssoc response. */ Dot11ReAssocResponse::Dot11ReAssocResponse(const NetworkInterface& iface, @@ -1087,11 +1075,11 @@ Dot11ReAssocResponse::Dot11ReAssocResponse(const uint8_t *buffer, uint32_t total } void Dot11ReAssocResponse::status_code(uint16_t new_status_code) { - this->_body.status_code = new_status_code; + this->_body.status_code = Utils::host_to_le(new_status_code); } void Dot11ReAssocResponse::aid(uint16_t new_aid) { - this->_body.aid = new_aid; + this->_body.aid = Utils::host_to_le(new_aid); } uint32_t Dot11ReAssocResponse::header_size() const { @@ -1105,12 +1093,90 @@ uint32_t Dot11ReAssocResponse::write_fixed_parameters(uint8_t *buffer, uint32_t return sz; } -PDU *Dot11ReAssocResponse::clone_pdu() const { - Dot11ReAssocResponse *new_pdu = new Dot11ReAssocResponse(); - new_pdu->copy_80211_fields(this); - new_pdu->copy_ext_header(this); - std::memcpy(&new_pdu->_body, &_body, sizeof(_body)); - return new_pdu; + +/* Auth */ + +Dot11Authentication::Dot11Authentication(const NetworkInterface& iface, + const address_type &dst_hw_addr, const address_type &src_hw_addr) +: Dot11ManagementFrame(iface, dst_hw_addr, src_hw_addr) +{ + this->subtype(Dot11::AUTH); + memset(&_body, 0, sizeof(_body)); +} + +Dot11Authentication::Dot11Authentication(const uint8_t *buffer, uint32_t total_sz) +: Dot11ManagementFrame(buffer, total_sz) +{ + uint32_t sz = management_frame_size(); + buffer += sz; + total_sz -= sz; + if(total_sz < sizeof(_body)) + throw runtime_error("Not enough size for an IEEE 802.11 authentication header in the buffer."); + memcpy(&_body, buffer, sizeof(_body)); + buffer += sizeof(_body); + total_sz -= sizeof(_body); + parse_tagged_parameters(buffer, total_sz); +} + +void Dot11Authentication::auth_algorithm(uint16_t new_auth_algorithm) { + this->_body.auth_algorithm = Utils::host_to_le(new_auth_algorithm); +} + +void Dot11Authentication::auth_seq_number(uint16_t new_auth_seq_number) { + this->_body.auth_seq_number = Utils::host_to_le(new_auth_seq_number); +} + +void Dot11Authentication::status_code(uint16_t new_status_code) { + this->_body.status_code = Utils::host_to_le(new_status_code); +} + +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); + assert(sz <= total_sz); + memcpy(buffer, &this->_body, sz); + return sz; +} + +/* Deauth */ + +Dot11Deauthentication::Dot11Deauthentication(const NetworkInterface& iface, + const address_type &dst_hw_addr, const address_type &src_hw_addr) +: Dot11ManagementFrame(iface, dst_hw_addr, src_hw_addr) +{ + this->subtype(Dot11::DEAUTH); + memset(&_body, 0, sizeof(_body)); +} + +Dot11Deauthentication::Dot11Deauthentication(const uint8_t *buffer, uint32_t total_sz) +: Dot11ManagementFrame(buffer, total_sz) { + uint32_t sz = management_frame_size(); + buffer += sz; + total_sz -= sz; + if(total_sz < sizeof(_body)) + throw runtime_error("Not enough size for a IEEE 802.11 deauthentication header in the buffer."); + memcpy(&_body, buffer, sizeof(_body)); + buffer += sizeof(_body); + total_sz -= sizeof(_body); + parse_tagged_parameters(buffer, total_sz); +} + +void Dot11Deauthentication::reason_code(uint16_t new_reason_code) { + this->_body.reason_code = Utils::host_to_le(new_reason_code); +} + +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); + assert(sz <= total_sz); + memcpy(buffer, &this->_body, sz); + return sz; } /* Probe Request */ @@ -1186,107 +1252,6 @@ uint32_t Dot11ProbeResponse::write_fixed_parameters(uint8_t *buffer, uint32_t to return sz; } -/* Auth */ - -Dot11Authentication::Dot11Authentication(const NetworkInterface& iface, - const address_type &dst_hw_addr, const address_type &src_hw_addr) -: Dot11ManagementFrame(iface, dst_hw_addr, src_hw_addr) -{ - this->subtype(Dot11::AUTH); - memset(&_body, 0, sizeof(_body)); -} - -Dot11Authentication::Dot11Authentication(const uint8_t *buffer, uint32_t total_sz) -: Dot11ManagementFrame(buffer, total_sz) -{ - uint32_t sz = management_frame_size(); - buffer += sz; - total_sz -= sz; - if(total_sz < sizeof(_body)) - throw runtime_error("Not enough size for an IEEE 802.11 authentication header in the buffer."); - memcpy(&_body, buffer, sizeof(_body)); - buffer += sizeof(_body); - total_sz -= sizeof(_body); - parse_tagged_parameters(buffer, total_sz); -} - -void Dot11Authentication::auth_algorithm(uint16_t new_auth_algorithm) { - this->_body.auth_algorithm = new_auth_algorithm; -} - -void Dot11Authentication::auth_seq_number(uint16_t new_auth_seq_number) { - this->_body.auth_seq_number = new_auth_seq_number; -} - -void Dot11Authentication::status_code(uint16_t new_status_code) { - this->_body.status_code = new_status_code; -} - -uint32_t Dot11Authentication::header_size() const { - return Dot11ManagementFrame::header_size() + sizeof(this->_body); -} - -PDU* Dot11Authentication::clone_pdu() const { - Dot11Authentication *new_pdu = new Dot11Authentication(); - new_pdu->copy_80211_fields(this); - new_pdu->copy_ext_header(this); - std::memcpy(&new_pdu->_body, &_body, sizeof(_body)); - return new_pdu; -} - -uint32_t Dot11Authentication::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) { - uint32_t sz = sizeof(this->_body); - assert(sz <= total_sz); - memcpy(buffer, &this->_body, sz); - return sz; -} - -/* Deauth */ - -Dot11Deauthentication::Dot11Deauthentication(const NetworkInterface& iface, - const address_type &dst_hw_addr, const address_type &src_hw_addr) -: Dot11ManagementFrame(iface, dst_hw_addr, src_hw_addr) -{ - this->subtype(Dot11::DEAUTH); - memset(&_body, 0, sizeof(_body)); -} - -Dot11Deauthentication::Dot11Deauthentication(const uint8_t *buffer, uint32_t total_sz) -: Dot11ManagementFrame(buffer, total_sz) { - uint32_t sz = management_frame_size(); - buffer += sz; - total_sz -= sz; - if(total_sz < sizeof(_body)) - throw runtime_error("Not enough size for a IEEE 802.11 deauthentication header in the buffer."); - memcpy(&_body, buffer, sizeof(_body)); - buffer += sizeof(_body); - total_sz -= sizeof(_body); - parse_tagged_parameters(buffer, total_sz); -} - -void Dot11Deauthentication::reason_code(uint16_t new_reason_code) { - this->_body.reason_code = new_reason_code; -} - -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); - assert(sz <= total_sz); - memcpy(buffer, &this->_body, sz); - return sz; -} - -PDU *Dot11Deauthentication::clone_pdu() const { - Dot11Deauthentication *new_pdu = new Dot11Deauthentication(); - new_pdu->copy_80211_fields(this); - new_pdu->copy_ext_header(this); - memcpy(&new_pdu->_body, &this->_body, sizeof(this->_body)); - return new_pdu; -} - /* Dot11Data */ Dot11Data::Dot11Data(const uint8_t *buffer, uint32_t total_sz) diff --git a/tests/include/tests/dot11.h b/tests/include/tests/dot11.h index 3cb63ed..b8d427f 100644 --- a/tests/include/tests/dot11.h +++ b/tests/include/tests/dot11.h @@ -6,6 +6,8 @@ using Tins::Dot11; using Tins::Dot11ManagementFrame; +typedef Dot11ManagementFrame::CapabilityInformation CapabilityInformation; + inline void test_equals(const Dot11 &dot1, const Dot11 &dot2) { EXPECT_EQ(dot1.protocol(), dot2.protocol()); EXPECT_EQ(dot1.type(), dot2.type()); @@ -31,6 +33,25 @@ inline void test_equals(const Dot11ManagementFrame& b1, const Dot11ManagementFra test_equals(static_cast(b1), static_cast(b2)); } +inline void test_equals(const CapabilityInformation &info1, const CapabilityInformation &info2) { + EXPECT_EQ(info1.ess(), info2.ess()); + EXPECT_EQ(info1.ibss(), info2.ibss()); + EXPECT_EQ(info1.cf_poll(), info2.cf_poll()); + EXPECT_EQ(info1.cf_poll_req(), info2.cf_poll_req()); + EXPECT_EQ(info1.privacy(), info2.privacy()); + EXPECT_EQ(info1.short_preamble(), info2.short_preamble()); + EXPECT_EQ(info1.pbcc(), info2.pbcc()); + EXPECT_EQ(info1.channel_agility(), info2.channel_agility()); + EXPECT_EQ(info1.spectrum_mgmt(), info2.spectrum_mgmt()); + EXPECT_EQ(info1.qos(), info2.qos()); + EXPECT_EQ(info1.sst(), info2.sst()); + EXPECT_EQ(info1.apsd(), info2.apsd()); + EXPECT_EQ(info1.reserved(), info2.reserved()); + EXPECT_EQ(info1.dsss_ofdm(), info2.dsss_ofdm()); + EXPECT_EQ(info1.delayed_block_ack(), info2.delayed_block_ack()); + EXPECT_EQ(info1.immediate_block_ack(), info2.immediate_block_ack()); +} + inline void test_equals_expected(const Dot11ManagementFrame &dot11) { EXPECT_EQ(dot11.protocol(), 1); EXPECT_EQ(dot11.type(), Dot11::MANAGEMENT); @@ -75,4 +96,24 @@ inline void test_equals_empty(const Dot11ManagementFrame &dot11) { test_equals_empty(static_cast(dot11)); } +inline void test_equals_empty(const CapabilityInformation &info) { + EXPECT_EQ(info.ess(), 0); + EXPECT_EQ(info.ibss(), 0); + EXPECT_EQ(info.cf_poll(), 0); + EXPECT_EQ(info.cf_poll_req(), 0); + EXPECT_EQ(info.privacy(), 0); + EXPECT_EQ(info.short_preamble(), 0); + EXPECT_EQ(info.pbcc(), 0); + EXPECT_EQ(info.channel_agility(), 0); + EXPECT_EQ(info.spectrum_mgmt(), 0); + EXPECT_EQ(info.qos(), 0); + EXPECT_EQ(info.sst(), 0); + EXPECT_EQ(info.apsd(), 0); + EXPECT_EQ(info.reserved(), 0); + EXPECT_EQ(info.dsss_ofdm(), 0); + EXPECT_EQ(info.delayed_block_ack(), 0); + EXPECT_EQ(info.immediate_block_ack(), 0); +} + + #endif // TINS_DOT11_TEST diff --git a/tests/src/dot11/assoc_request.cpp b/tests/src/dot11/assoc_request.cpp new file mode 100644 index 0000000..fab9327 --- /dev/null +++ b/tests/src/dot11/assoc_request.cpp @@ -0,0 +1,81 @@ +#include +#include +#include +#include +#include "dot11.h" +#include "tests/dot11.h" + + +using namespace std; +using namespace Tins; + +typedef Dot11::address_type address_type; + +class Dot11AssocRequestTest : public testing::Test { +public: + static const address_type empty_addr, hwaddr; + static const uint8_t expected_packet[]; + //static void test_equals_expected(const Dot11Beacon&dot11); +}; + +const uint8_t Dot11AssocRequestTest::expected_packet[] = { + '\x01', '\x01', 'O', '#', '\x00', '\x01', '\x02', '\x03', '\x04', + '\x05', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x02', + '\x03', '\x04', '\x05', '\x06', '\x07', '\x00', '\x00', '\x15', + ' ', '\xf3', '\x92' +}; + +void test_equals(const Dot11AssocRequest &dot1, const Dot11AssocRequest &dot2) { + test_equals(dot1.capabilities(), dot2.capabilities()); + EXPECT_EQ(dot1.listen_interval(), dot2.listen_interval()); + test_equals( + static_cast(dot1), + static_cast(dot2) + ); +} + +void test_equals_expected(const Dot11AssocRequest &dot11) { + test_equals_expected(static_cast(dot11)); + EXPECT_EQ(dot11.listen_interval(), 0x92f3); + EXPECT_EQ(dot11.subtype(), Dot11::ASSOC_REQ); +} + +TEST_F(Dot11AssocRequestTest, Constructor) { + Dot11AssocRequest dot11; + test_equals_empty(static_cast(dot11)); + EXPECT_EQ(dot11.listen_interval(), 0); + EXPECT_EQ(dot11.subtype(), Dot11::ASSOC_REQ); +} + +TEST_F(Dot11AssocRequestTest, ConstructorFromBuffer) { + Dot11AssocRequest dot11(expected_packet, sizeof(expected_packet)); + test_equals_expected(dot11); +} + +TEST_F(Dot11AssocRequestTest, CopyConstructor) { + Dot11AssocRequest dot1(expected_packet, sizeof(expected_packet)); + Dot11AssocRequest dot2(dot1); + test_equals(dot1, dot2); +} + +TEST_F(Dot11AssocRequestTest, CopyAssignmentOperator) { + Dot11AssocRequest dot1(expected_packet, sizeof(expected_packet)); + Dot11AssocRequest dot2; + dot2 = dot1; + test_equals(dot1, dot2); +} + +TEST_F(Dot11AssocRequestTest, ClonePDU) { + Dot11AssocRequest dot1(expected_packet, sizeof(expected_packet)); + std::auto_ptr dot2(dot1.clone_pdu()); + test_equals(dot1, *dot2); +} + +TEST_F(Dot11AssocRequestTest, FromBytes) { + std::auto_ptr dot11(Dot11::from_bytes(expected_packet, sizeof(expected_packet))); + ASSERT_TRUE(dot11.get()); + const Dot11AssocRequest *inner = dot11->find_inner_pdu(); + ASSERT_TRUE(inner); + test_equals_expected(*inner); +} + diff --git a/tests/src/dot11/assoc_response.cpp b/tests/src/dot11/assoc_response.cpp new file mode 100644 index 0000000..8b35f9b --- /dev/null +++ b/tests/src/dot11/assoc_response.cpp @@ -0,0 +1,84 @@ +#include +#include +#include +#include +#include "dot11.h" +#include "tests/dot11.h" + + +using namespace std; +using namespace Tins; + +typedef Dot11::address_type address_type; + +class Dot11AssocResponseTest : public testing::Test { +public: + static const address_type empty_addr, hwaddr; + static const uint8_t expected_packet[]; +}; + +const uint8_t Dot11AssocResponseTest::expected_packet[] = { + '\x11', '\x01', 'O', '#', '\x00', '\x01', '\x02', '\x03', '\x04', + '\x05', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x02', + '\x03', '\x04', '\x05', '\x06', '\x07', '\x00', '\x00', + '\x15', ' ', '\xf3', '\x92', ':', '\xf2' +}; + +void test_equals(const Dot11AssocResponse &dot1, const Dot11AssocResponse &dot2) { + test_equals(dot1.capabilities(), dot2.capabilities()); + EXPECT_EQ(dot1.status_code(), dot2.status_code()); + EXPECT_EQ(dot1.aid(), dot2.aid()); + test_equals( + static_cast(dot1), + static_cast(dot2) + ); +} + +void test_equals_expected(const Dot11AssocResponse &dot11) { + test_equals_expected(static_cast(dot11)); + EXPECT_EQ(dot11.status_code(), 0x92f3); + EXPECT_EQ(dot11.aid(), 0xf23a); + EXPECT_EQ(dot11.subtype(), Dot11::ASSOC_RESP); +} + +TEST_F(Dot11AssocResponseTest, Constructor) { + Dot11AssocResponse dot11; + test_equals_empty(static_cast(dot11)); + EXPECT_EQ(dot11.status_code(), 0); + EXPECT_EQ(dot11.aid(), 0); + EXPECT_EQ(dot11.subtype(), Dot11::ASSOC_RESP); +} + +TEST_F(Dot11AssocResponseTest, ConstructorFromBuffer) { + Dot11AssocResponse dot11(expected_packet, sizeof(expected_packet)); + test_equals_expected(dot11); +} + +TEST_F(Dot11AssocResponseTest, CopyConstructor) { + Dot11AssocResponse dot1(expected_packet, sizeof(expected_packet)); + Dot11AssocResponse dot2(dot1); + test_equals(dot1, dot2); +} + +TEST_F(Dot11AssocResponseTest, CopyAssignmentOperator) { + Dot11AssocResponse dot1(expected_packet, sizeof(expected_packet)); + Dot11AssocResponse dot2; + dot2 = dot1; + test_equals(dot1, dot2); +} + +TEST_F(Dot11AssocResponseTest, ClonePDU) { + Dot11AssocResponse dot1(expected_packet, sizeof(expected_packet)); + std::auto_ptr dot2(dot1.clone_pdu()); + test_equals(dot1, *dot2); +} + +TEST_F(Dot11AssocResponseTest, FromBytes) { + std::auto_ptr dot11(Dot11::from_bytes(expected_packet, sizeof(expected_packet))); + ASSERT_TRUE(dot11.get()); + std::cout << (int)dot11->pdu_type() << std::endl; + const Dot11AssocResponse *inner = dot11->find_inner_pdu(); + ASSERT_TRUE(inner); + test_equals_expected(*inner); +} + diff --git a/tests/src/dot11/authentication.cpp b/tests/src/dot11/authentication.cpp new file mode 100644 index 0000000..2e2d3d4 --- /dev/null +++ b/tests/src/dot11/authentication.cpp @@ -0,0 +1,85 @@ +#include +#include +#include +#include +#include "dot11.h" +#include "tests/dot11.h" + + +using namespace std; +using namespace Tins; + +typedef Dot11::address_type address_type; + +class Dot11AuthenticationTest : public testing::Test { +public: + static const address_type empty_addr, hwaddr; + static const uint8_t expected_packet[]; +}; + +const uint8_t Dot11AuthenticationTest::expected_packet[] = { + '\xb1', '\x01', 'O', '#', '\x00', '\x01', '\x02', '\x03', '\x04', + '\x05', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x02', + '\x03', '\x04', '\x05', '\x06', '\x07', '\x00', '\x00', '\xa2', + '(', ':', '\xf2', '\xf3', '\x92' +}; + +void test_equals(const Dot11Authentication &dot1, const Dot11Authentication &dot2) { + EXPECT_EQ(dot1.status_code(), dot2.status_code()); + EXPECT_EQ(dot1.auth_seq_number(), dot2.auth_seq_number()); + EXPECT_EQ(dot1.auth_algorithm(), dot2.auth_algorithm()); + test_equals( + static_cast(dot1), + static_cast(dot2) + ); +} + +void test_equals_expected(const Dot11Authentication &dot11) { + test_equals_expected(static_cast(dot11)); + EXPECT_EQ(dot11.status_code(), 0x92f3); + EXPECT_EQ(dot11.auth_seq_number(), 0xf23a); + EXPECT_EQ(dot11.auth_algorithm(), 0x28a2); + EXPECT_EQ(dot11.subtype(), Dot11::AUTH); +} + +TEST_F(Dot11AuthenticationTest, Constructor) { + Dot11Authentication dot11; + test_equals_empty(static_cast(dot11)); + EXPECT_EQ(dot11.status_code(), 0); + EXPECT_EQ(dot11.auth_seq_number(), 0); + EXPECT_EQ(dot11.auth_algorithm(), 0); + EXPECT_EQ(dot11.subtype(), Dot11::AUTH); +} + +TEST_F(Dot11AuthenticationTest, ConstructorFromBuffer) { + Dot11Authentication dot11(expected_packet, sizeof(expected_packet)); + test_equals_expected(dot11); +} + +TEST_F(Dot11AuthenticationTest, CopyConstructor) { + Dot11Authentication dot1(expected_packet, sizeof(expected_packet)); + Dot11Authentication dot2(dot1); + test_equals(dot1, dot2); +} + +TEST_F(Dot11AuthenticationTest, CopyAssignmentOperator) { + Dot11Authentication dot1(expected_packet, sizeof(expected_packet)); + Dot11Authentication dot2; + dot2 = dot1; + test_equals(dot1, dot2); +} + +TEST_F(Dot11AuthenticationTest, ClonePDU) { + Dot11Authentication dot1(expected_packet, sizeof(expected_packet)); + std::auto_ptr dot2(dot1.clone_pdu()); + test_equals(dot1, *dot2); +} + +TEST_F(Dot11AuthenticationTest, FromBytes) { + std::auto_ptr dot11(Dot11::from_bytes(expected_packet, sizeof(expected_packet))); + ASSERT_TRUE(dot11.get()); + const Dot11Authentication *inner = dot11->find_inner_pdu(); + ASSERT_TRUE(inner); + test_equals_expected(*inner); +} + diff --git a/tests/src/dot11/beacon.cpp b/tests/src/dot11/beacon.cpp index 7e0ef87..d10aaac 100644 --- a/tests/src/dot11/beacon.cpp +++ b/tests/src/dot11/beacon.cpp @@ -59,25 +59,8 @@ void test_equals(const Dot11Beacon& b1, const Dot11Beacon& b2) { EXPECT_EQ(b1.interval(), b2.interval()); EXPECT_EQ(b1.timestamp(), b2.timestamp()); - const Dot11Beacon::CapabilityInformation &info1 = b1.capabilities(), - &info2 = b2.capabilities(); - EXPECT_EQ(info1.ess(), info2.ess()); - EXPECT_EQ(info1.ibss(), info2.ibss()); - EXPECT_EQ(info1.cf_poll(), info2.cf_poll()); - EXPECT_EQ(info1.cf_poll_req(), info2.cf_poll_req()); - EXPECT_EQ(info1.privacy(), info2.privacy()); - EXPECT_EQ(info1.short_preamble(), info2.short_preamble()); - EXPECT_EQ(info1.pbcc(), info2.pbcc()); - EXPECT_EQ(info1.channel_agility(), info2.channel_agility()); - EXPECT_EQ(info1.spectrum_mgmt(), info2.spectrum_mgmt()); - EXPECT_EQ(info1.qos(), info2.qos()); - EXPECT_EQ(info1.sst(), info2.sst()); - EXPECT_EQ(info1.apsd(), info2.apsd()); - EXPECT_EQ(info1.reserved(), info2.reserved()); - EXPECT_EQ(info1.dsss_ofdm(), info2.dsss_ofdm()); - EXPECT_EQ(info1.delayed_block_ack(), info2.delayed_block_ack()); - EXPECT_EQ(info1.immediate_block_ack(), info2.immediate_block_ack()); - + test_equals(b1.capabilities(), b2.capabilities()); + test_equals( static_cast(b1), static_cast(b2) @@ -87,24 +70,7 @@ void test_equals(const Dot11Beacon& b1, const Dot11Beacon& b2) { TEST_F(Dot11BeaconTest, DefaultConstructor) { Dot11Beacon dot11; test_equals_empty(static_cast(dot11)); - - const Dot11Beacon::CapabilityInformation& info = dot11.capabilities(); - EXPECT_EQ(info.ess(), 0); - EXPECT_EQ(info.ibss(), 0); - EXPECT_EQ(info.cf_poll(), 0); - EXPECT_EQ(info.cf_poll_req(), 0); - EXPECT_EQ(info.privacy(), 0); - EXPECT_EQ(info.short_preamble(), 0); - EXPECT_EQ(info.pbcc(), 0); - EXPECT_EQ(info.channel_agility(), 0); - EXPECT_EQ(info.spectrum_mgmt(), 0); - EXPECT_EQ(info.qos(), 0); - EXPECT_EQ(info.sst(), 0); - EXPECT_EQ(info.apsd(), 0); - EXPECT_EQ(info.reserved(), 0); - EXPECT_EQ(info.dsss_ofdm(), 0); - EXPECT_EQ(info.delayed_block_ack(), 0); - EXPECT_EQ(info.immediate_block_ack(), 0); + test_equals_empty(dot11.capabilities()); EXPECT_EQ(dot11.interval(), 0); EXPECT_EQ(dot11.timestamp(), 0); diff --git a/tests/src/dot11/deauthentication.cpp b/tests/src/dot11/deauthentication.cpp new file mode 100644 index 0000000..97e92f8 --- /dev/null +++ b/tests/src/dot11/deauthentication.cpp @@ -0,0 +1,79 @@ +#include +#include +#include +#include +#include "dot11.h" +#include "tests/dot11.h" + + +using namespace std; +using namespace Tins; + +typedef Dot11::address_type address_type; + +class Dot11DeauthenticationTest : public testing::Test { +public: + static const address_type empty_addr, hwaddr; + static const uint8_t expected_packet[]; +}; + +const uint8_t Dot11DeauthenticationTest::expected_packet[] = { + '\xc1', '\x01', 'O', '#', '\x00', '\x01', '\x02', '\x03', '\x04', + '\x05', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x02', + '\x03', '\x04', '\x05', '\x06', '\x07', '\x00', '\x00', '\xf3', + '\x92' +}; + +void test_equals(const Dot11Deauthentication &dot1, const Dot11Deauthentication &dot2) { + EXPECT_EQ(dot1.reason_code(), dot2.reason_code()); + test_equals( + static_cast(dot1), + static_cast(dot2) + ); +} + +void test_equals_expected(const Dot11Deauthentication &dot11) { + test_equals_expected(static_cast(dot11)); + EXPECT_EQ(dot11.reason_code(), 0x92f3); + EXPECT_EQ(dot11.subtype(), Dot11::DEAUTH); +} + +TEST_F(Dot11DeauthenticationTest, Constructor) { + Dot11Deauthentication dot11; + test_equals_empty(static_cast(dot11)); + EXPECT_EQ(dot11.reason_code(), 0); + EXPECT_EQ(dot11.subtype(), Dot11::DEAUTH); +} + +TEST_F(Dot11DeauthenticationTest, ConstructorFromBuffer) { + Dot11Deauthentication dot11(expected_packet, sizeof(expected_packet)); + test_equals_expected(dot11); +} + +TEST_F(Dot11DeauthenticationTest, CopyConstructor) { + Dot11Deauthentication dot1(expected_packet, sizeof(expected_packet)); + Dot11Deauthentication dot2(dot1); + test_equals(dot1, dot2); +} + +TEST_F(Dot11DeauthenticationTest, CopyAssignmentOperator) { + Dot11Deauthentication dot1(expected_packet, sizeof(expected_packet)); + Dot11Deauthentication dot2; + dot2 = dot1; + test_equals(dot1, dot2); +} + +TEST_F(Dot11DeauthenticationTest, ClonePDU) { + Dot11Deauthentication dot1(expected_packet, sizeof(expected_packet)); + std::auto_ptr dot2(dot1.clone_pdu()); + test_equals(dot1, *dot2); +} + +TEST_F(Dot11DeauthenticationTest, FromBytes) { + std::auto_ptr dot11(Dot11::from_bytes(expected_packet, sizeof(expected_packet))); + ASSERT_TRUE(dot11.get()); + const Dot11Deauthentication *inner = dot11->find_inner_pdu(); + ASSERT_TRUE(inner); + test_equals_expected(*inner); +} + diff --git a/tests/src/dot11/disassoc.cpp b/tests/src/dot11/disassoc.cpp index 4b7789e..8e026f1 100644 --- a/tests/src/dot11/disassoc.cpp +++ b/tests/src/dot11/disassoc.cpp @@ -42,6 +42,7 @@ TEST_F(Dot11DisassocTest, Constructor) { Dot11Disassoc dot11; test_equals_empty(static_cast(dot11)); EXPECT_EQ(dot11.reason_code(), 0); + EXPECT_EQ(dot11.subtype(), Dot11::DISASSOC); } TEST_F(Dot11DisassocTest, ConstructorFromBuffer) { @@ -71,8 +72,7 @@ TEST_F(Dot11DisassocTest, ClonePDU) { TEST_F(Dot11DisassocTest, FromBytes) { std::auto_ptr dot11(Dot11::from_bytes(expected_packet, sizeof(expected_packet))); ASSERT_TRUE(dot11.get()); - std::cout << (int)dot11->pdu_type() << std::endl; - const Dot11Disassoc *disassoc = dot11->find_inner_pdu(); - ASSERT_TRUE(disassoc); - test_equals_expected(*disassoc); + const Dot11Disassoc *inner = dot11->find_inner_pdu(); + ASSERT_TRUE(inner); + test_equals_expected(*inner); } diff --git a/tests/src/dot11/reassoc_request.cpp b/tests/src/dot11/reassoc_request.cpp new file mode 100644 index 0000000..0b2f24f --- /dev/null +++ b/tests/src/dot11/reassoc_request.cpp @@ -0,0 +1,82 @@ +#include +#include +#include +#include +#include "dot11.h" +#include "tests/dot11.h" + + +using namespace std; +using namespace Tins; + +typedef Dot11::address_type address_type; + +class Dot11ReAssocRequestTest : public testing::Test { +public: + static const address_type empty_addr, hwaddr; + static const uint8_t expected_packet[]; +}; + +const uint8_t Dot11ReAssocRequestTest::expected_packet[] = { + '!', '\x01', 'O', '#', '\x00', '\x01', '\x02', '\x03', '\x04', + '\x05', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x02', + '\x03', '\x04', '\x05', '\x06', '\x07', '\x00', '\x00', '\x15', + ' ', '\xf3', '\x92', '\x03', '\x04', '\x05', '\x06', '\x07', '\x08' +}; + +void test_equals(const Dot11ReAssocRequest &dot1, const Dot11ReAssocRequest &dot2) { + test_equals(dot1.capabilities(), dot2.capabilities()); + EXPECT_EQ(dot1.listen_interval(), dot2.listen_interval()); + EXPECT_EQ(dot1.current_ap(), dot2.current_ap()); + test_equals( + static_cast(dot1), + static_cast(dot2) + ); +} + +void test_equals_expected(const Dot11ReAssocRequest &dot11) { + test_equals_expected(static_cast(dot11)); + EXPECT_EQ(dot11.listen_interval(), 0x92f3); + EXPECT_EQ(dot11.subtype(), Dot11::REASSOC_REQ); +} + +TEST_F(Dot11ReAssocRequestTest, Constructor) { + Dot11ReAssocRequest dot11; + test_equals_empty(static_cast(dot11)); + EXPECT_EQ(dot11.listen_interval(), 0); + EXPECT_EQ(dot11.current_ap(), address_type()); + EXPECT_EQ(dot11.subtype(), Dot11::REASSOC_REQ); +} + +TEST_F(Dot11ReAssocRequestTest, ConstructorFromBuffer) { + Dot11ReAssocRequest dot11(expected_packet, sizeof(expected_packet)); + test_equals_expected(dot11); +} + +TEST_F(Dot11ReAssocRequestTest, CopyConstructor) { + Dot11ReAssocRequest dot1(expected_packet, sizeof(expected_packet)); + Dot11ReAssocRequest dot2(dot1); + test_equals(dot1, dot2); +} + +TEST_F(Dot11ReAssocRequestTest, CopyAssignmentOperator) { + Dot11ReAssocRequest dot1(expected_packet, sizeof(expected_packet)); + Dot11ReAssocRequest dot2; + dot2 = dot1; + test_equals(dot1, dot2); +} + +TEST_F(Dot11ReAssocRequestTest, ClonePDU) { + Dot11ReAssocRequest dot1(expected_packet, sizeof(expected_packet)); + std::auto_ptr dot2(dot1.clone_pdu()); + test_equals(dot1, *dot2); +} + +TEST_F(Dot11ReAssocRequestTest, FromBytes) { + std::auto_ptr dot11(Dot11::from_bytes(expected_packet, sizeof(expected_packet))); + ASSERT_TRUE(dot11.get()); + const Dot11ReAssocRequest *inner = dot11->find_inner_pdu(); + ASSERT_TRUE(inner); + test_equals_expected(*inner); +} + diff --git a/tests/src/dot11/reassoc_response.cpp b/tests/src/dot11/reassoc_response.cpp new file mode 100644 index 0000000..1ab4b6f --- /dev/null +++ b/tests/src/dot11/reassoc_response.cpp @@ -0,0 +1,83 @@ +#include +#include +#include +#include +#include "dot11.h" +#include "tests/dot11.h" + + +using namespace std; +using namespace Tins; + +typedef Dot11::address_type address_type; + +class Dot11ReAssocResponseTest : public testing::Test { +public: + static const address_type empty_addr, hwaddr; + static const uint8_t expected_packet[]; +}; + +const uint8_t Dot11ReAssocResponseTest::expected_packet[] = { + '1', '\x01', 'O', '#', '\x00', '\x01', '\x02', '\x03', '\x04', + '\x05', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x02', + '\x03', '\x04', '\x05', '\x06', '\x07', '\x00', '\x00', '\x15', + ' ', '\xf3', '\x92', ':', '\xf2' +}; + +void test_equals(const Dot11ReAssocResponse &dot1, const Dot11ReAssocResponse &dot2) { + test_equals(dot1.capabilities(), dot2.capabilities()); + EXPECT_EQ(dot1.status_code(), dot2.status_code()); + EXPECT_EQ(dot1.aid(), dot2.aid()); + test_equals( + static_cast(dot1), + static_cast(dot2) + ); +} + +void test_equals_expected(const Dot11ReAssocResponse &dot11) { + test_equals_expected(static_cast(dot11)); + EXPECT_EQ(dot11.status_code(), 0x92f3); + EXPECT_EQ(dot11.aid(), 0xf23a); + EXPECT_EQ(dot11.subtype(), Dot11::REASSOC_RESP); +} + +TEST_F(Dot11ReAssocResponseTest, Constructor) { + Dot11ReAssocResponse dot11; + test_equals_empty(static_cast(dot11)); + EXPECT_EQ(dot11.status_code(), 0); + EXPECT_EQ(dot11.aid(), 0); + EXPECT_EQ(dot11.subtype(), Dot11::REASSOC_RESP); +} + +TEST_F(Dot11ReAssocResponseTest, ConstructorFromBuffer) { + Dot11ReAssocResponse dot11(expected_packet, sizeof(expected_packet)); + test_equals_expected(dot11); +} + +TEST_F(Dot11ReAssocResponseTest, CopyConstructor) { + Dot11ReAssocResponse dot1(expected_packet, sizeof(expected_packet)); + Dot11ReAssocResponse dot2(dot1); + test_equals(dot1, dot2); +} + +TEST_F(Dot11ReAssocResponseTest, CopyAssignmentOperator) { + Dot11ReAssocResponse dot1(expected_packet, sizeof(expected_packet)); + Dot11ReAssocResponse dot2; + dot2 = dot1; + test_equals(dot1, dot2); +} + +TEST_F(Dot11ReAssocResponseTest, ClonePDU) { + Dot11ReAssocResponse dot1(expected_packet, sizeof(expected_packet)); + std::auto_ptr dot2(dot1.clone_pdu()); + test_equals(dot1, *dot2); +} + +TEST_F(Dot11ReAssocResponseTest, FromBytes) { + std::auto_ptr dot11(Dot11::from_bytes(expected_packet, sizeof(expected_packet))); + ASSERT_TRUE(dot11.get()); + const Dot11ReAssocResponse *inner = dot11->find_inner_pdu(); + ASSERT_TRUE(inner); + test_equals_expected(*inner); +} +