diff --git a/include/dot11.h b/include/dot11.h index 7e79a83..f3a11db 100644 --- a/include/dot11.h +++ b/include/dot11.h @@ -2514,7 +2514,7 @@ namespace Tins { * \sa PDU::matches_flag */ bool matches_flag(PDUType flag) { - return flag == PDU::DOT11_PROBE_REQ || Dot11ManagementFrame::matches_flag(flag); + return flag == pdu_flag || Dot11ManagementFrame::matches_flag(flag); } /** @@ -2522,7 +2522,9 @@ namespace Tins { * * \sa PDU::clone_pdu() */ - PDU* clone_pdu() const; + Dot11ProbeRequest* clone_pdu() const { + return new Dot11ProbeRequest(*this); + } }; @@ -2565,14 +2567,14 @@ namespace Tins { * * \return Timestamp value in an uint64_t. */ - uint64_t timestamp() const { return _body.timestamp; } + uint64_t timestamp() const { return Utils::le_to_host(_body.timestamp); } /** * \brief Getter for the interval field. * * \return Timestamp value in an uint16_t. */ - uint16_t interval() const { return _body.interval; } + uint16_t interval() const { return Utils::le_to_host(_body.interval); } /** * \brief Getter for the Capabilities Information. @@ -2615,13 +2617,15 @@ namespace Tins { * * \sa PDU::clone_pdu() */ - PDU* clone_pdu() const; + Dot11ProbeResponse* clone_pdu() const { + return new Dot11ProbeResponse(*this); + } /** * \brief Getter for the PDU's type. * \sa PDU::pdu_type */ - PDUType pdu_type() const { return PDU::DOT11_PROBE_RESP; } + PDUType pdu_type() const { return pdu_flag; } /** * \brief Check wether this PDU matches the specified flag. @@ -2629,7 +2633,7 @@ namespace Tins { * \sa PDU::matches_flag */ bool matches_flag(PDUType flag) { - return flag == PDU::DOT11_PROBE_RESP || Dot11ManagementFrame::matches_flag(flag); + return flag == pdu_flag || Dot11ManagementFrame::matches_flag(flag); } protected: @@ -2691,14 +2695,14 @@ namespace Tins { * * \return The sequence number as an uint16_t. */ - uint16_t seq_num() const { return _ext_header.seq_control.seq_number; } + uint16_t seq_num() const { return Utils::le_to_host(_ext_header.seq_control.seq_number); } /** * \brief Getter for the fourth address. * * \return The fourth address as a constant uint8_t pointer. */ - const uint8_t* addr4() const { return _addr4; } + address_type addr4() const { return _addr4; } /** * \brief Setter for the second address. @@ -2733,7 +2737,7 @@ namespace Tins { * * \param new_addr4 const uint8_t array of 6 bytes containing the new fourth address. */ - void addr4(const uint8_t* new_addr4); + void addr4(const address_type &new_addr4); /** * \brief Returns the 802.11 frame's header length. @@ -2747,7 +2751,7 @@ namespace Tins { * \brief Getter for the PDU's type. * \sa PDU::pdu_type */ - PDUType pdu_type() const { return PDU::DOT11_DATA; } + PDUType pdu_type() const { return pdu_flag; } /** * \brief Check wether this PDU matches the specified flag. @@ -2755,7 +2759,7 @@ namespace Tins { * \sa PDU::matches_flag */ bool matches_flag(PDUType flag) { - return flag == PDU::DOT11_DATA || Dot11::matches_flag(flag); + return flag == pdu_flag || Dot11::matches_flag(flag); } /** @@ -2763,7 +2767,9 @@ namespace Tins { * * \sa PDU::clone_pdu */ - PDU *clone_pdu() const; + Dot11Data *clone_pdu() const { + return new Dot11Data(*this); + } protected: struct ExtendedHeader { uint8_t addr2[6]; @@ -2785,7 +2791,7 @@ namespace Tins { uint32_t data_frame_size() { return sizeof(_ext_header) + (from_ds() && to_ds()) ? sizeof(_addr4) : 0; } private: ExtendedHeader _ext_header; - uint8_t _addr4[6]; + address_type _addr4; }; class Dot11QoSData : public Dot11Data { @@ -2856,7 +2862,9 @@ namespace Tins { * * \sa PDU::clone_pdu */ - PDU *clone_pdu() const; + Dot11QoSData *clone_pdu() const { + return new Dot11QoSData(*this); + } /** * \brief Getter for the PDU's type. diff --git a/src/dot11.cpp b/src/dot11.cpp index 77a60dc..95d9566 100644 --- a/src/dot11.cpp +++ b/src/dot11.cpp @@ -227,9 +227,15 @@ PDU *Dot11::from_bytes(const uint8_t *buffer, uint32_t total_sz) { 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 + else if(hdr->control.subtype == DEAUTH) ret = new Dot11Deauthentication(buffer, total_sz); + else if(hdr->control.subtype == PROBE_REQ) + ret = new Dot11ProbeRequest(buffer, total_sz); + //else if(hdr->control.subtype == PROBE_RESP) + else + ret = new Dot11ProbeResponse(buffer, total_sz); + + } else if(hdr->control.type == DATA){ if(hdr->control.subtype <= 4) @@ -1194,13 +1200,6 @@ Dot11ProbeRequest::Dot11ProbeRequest(const uint8_t *buffer, uint32_t total_sz) parse_tagged_parameters(buffer, total_sz); } -PDU* Dot11ProbeRequest::clone_pdu() const { - Dot11ProbeRequest* new_pdu = new Dot11ProbeRequest(); - new_pdu->copy_80211_fields(this); - new_pdu->copy_ext_header(this); - return new_pdu; -} - /* Probe Response */ Dot11ProbeResponse::Dot11ProbeResponse(const NetworkInterface& iface, @@ -1208,7 +1207,7 @@ Dot11ProbeResponse::Dot11ProbeResponse(const NetworkInterface& iface, : Dot11ManagementFrame(iface, dst_hw_addr, src_hw_addr) { this->subtype(Dot11::PROBE_RESP); - memset(&this->_body, 0, sizeof(this->_body)); + memset(&_body, 0, sizeof(_body)); } Dot11ProbeResponse::Dot11ProbeResponse(const uint8_t *buffer, uint32_t total_sz) @@ -1226,25 +1225,17 @@ Dot11ProbeResponse::Dot11ProbeResponse(const uint8_t *buffer, uint32_t total_sz) } void Dot11ProbeResponse::timestamp(uint64_t new_timestamp) { - this->_body.timestamp = new_timestamp; + this->_body.timestamp = Utils::host_to_le(new_timestamp); } void Dot11ProbeResponse::interval(uint16_t new_interval) { - this->_body.interval = new_interval; + this->_body.interval = Utils::host_to_le(new_interval); } uint32_t Dot11ProbeResponse::header_size() const { return Dot11ManagementFrame::header_size() + sizeof(this->_body); } -PDU* Dot11ProbeResponse::clone_pdu() const { - Dot11ProbeResponse* new_pdu = new Dot11ProbeResponse(); - new_pdu->copy_80211_fields(this); - new_pdu->copy_ext_header(this); - memcpy(&new_pdu->_body, &this->_body, sizeof(this->_body)); - return new_pdu; -} - uint32_t Dot11ProbeResponse::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) { uint32_t sz = sizeof(this->_body); assert(sz <= total_sz); @@ -1282,13 +1273,14 @@ Dot11Data::Dot11Data(const NetworkInterface &iface, : Dot11(iface, dst_hw_addr, child) { type(Dot11::DATA); + memset(&_ext_header, 0, sizeof(_ext_header)); addr2(src_hw_addr); } void Dot11Data::copy_ext_header(const Dot11Data* other) { - Dot11::copy_80211_fields(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); + _addr4, other->_addr4, 6);*/ } uint32_t Dot11Data::header_size() const { @@ -1307,35 +1299,29 @@ void Dot11Data::addr3(const address_type &new_addr3) { } void Dot11Data::frag_num(uint8_t new_frag_num) { - this->_ext_header.seq_control.frag_number = new_frag_num; + _ext_header.seq_control.frag_number = new_frag_num; } void Dot11Data::seq_num(uint16_t new_seq_num) { - this->_ext_header.seq_control.seq_number = new_seq_num; + _ext_header.seq_control.seq_number = new_seq_num; } -void Dot11Data::addr4(const uint8_t* new_addr4) { - memcpy(this->_addr4, new_addr4, 6); +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(this->_ext_header); - memcpy(buffer, &this->_ext_header, sizeof(this->_ext_header)); - buffer += sizeof(this->_ext_header); - if (this->from_ds() && this->to_ds()) { + uint32_t written = sizeof(_ext_header); + memcpy(buffer, &_ext_header, sizeof(_ext_header)); + buffer += sizeof(_ext_header); + if (from_ds() && to_ds()) { written += 6; - memcpy(buffer, this->_addr4, 6); + _addr4.copy(buffer); } return written; } -PDU *Dot11Data::clone_pdu() const { - Dot11Data *new_pdu = new Dot11Data(); - new_pdu->copy_80211_fields(this); - return new_pdu; -} - /* QoS data. */ Dot11QoSData::Dot11QoSData(const NetworkInterface &iface, @@ -1343,8 +1329,8 @@ Dot11QoSData::Dot11QoSData(const NetworkInterface &iface, PDU* child) : Dot11Data(iface, dst_hw_addr, src_hw_addr, child) { - this->subtype(Dot11::QOS_DATA_DATA); - this->_qos_control = 0; + subtype(Dot11::QOS_DATA_DATA); + _qos_control = 0; } Dot11QoSData::Dot11QoSData(const uint8_t *buffer, uint32_t total_sz) @@ -1356,7 +1342,7 @@ Dot11QoSData::Dot11QoSData(const uint8_t *buffer, uint32_t total_sz) total_sz -= sz; if(total_sz < sizeof(this->_qos_control)) throw runtime_error("Not enough size for an IEEE 802.11 data header in the buffer."); - this->_qos_control = *(uint16_t*)buffer; + _qos_control = *(uint16_t*)buffer; total_sz -= sizeof(uint16_t); buffer += sizeof(uint16_t); if(total_sz) @@ -1393,12 +1379,6 @@ uint32_t Dot11QoSData::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz return sz; } -PDU *Dot11QoSData::clone_pdu() const { - Dot11QoSData *new_pdu = new Dot11QoSData(); - new_pdu->copy_80211_fields(this); - return new_pdu; -} - /* Dot11Control */ Dot11Control::Dot11Control(const NetworkInterface &iface, diff --git a/tests/depends.d b/tests/depends.d index f497cc2..71146e8 100644 --- a/tests/depends.d +++ b/tests/depends.d @@ -264,6 +264,75 @@ src/utils_test.o: src/utils_test.cpp ../include/utils.h \ ../include/network_interface.h: ../include/ipaddress.h: +src/dot11/assoc_request.o: src/dot11/assoc_request.cpp ../include/dot11.h \ + ../include/pdu.h ../include/packetsender.h ../include/utils.h \ + ../include/ipaddress.h ../include/hwaddress.h \ + ../include/network_interface.h include/tests/dot11.h \ + include/tests/dot11.h + +../include/dot11.h: + +../include/pdu.h: + +../include/packetsender.h: + +../include/utils.h: + +../include/ipaddress.h: + +../include/hwaddress.h: + +../include/network_interface.h: + +include/tests/dot11.h: + +include/tests/dot11.h: +src/dot11/assoc_response.o: src/dot11/assoc_response.cpp \ + ../include/dot11.h ../include/pdu.h ../include/packetsender.h \ + ../include/utils.h ../include/ipaddress.h ../include/hwaddress.h \ + ../include/network_interface.h include/tests/dot11.h \ + include/tests/dot11.h + +../include/dot11.h: + +../include/pdu.h: + +../include/packetsender.h: + +../include/utils.h: + +../include/ipaddress.h: + +../include/hwaddress.h: + +../include/network_interface.h: + +include/tests/dot11.h: + +include/tests/dot11.h: +src/dot11/authentication.o: src/dot11/authentication.cpp \ + ../include/dot11.h ../include/pdu.h ../include/packetsender.h \ + ../include/utils.h ../include/ipaddress.h ../include/hwaddress.h \ + ../include/network_interface.h include/tests/dot11.h \ + include/tests/dot11.h + +../include/dot11.h: + +../include/pdu.h: + +../include/packetsender.h: + +../include/utils.h: + +../include/ipaddress.h: + +../include/hwaddress.h: + +../include/network_interface.h: + +include/tests/dot11.h: + +include/tests/dot11.h: src/dot11/beacon.o: src/dot11/beacon.cpp ../include/dot11.h \ ../include/pdu.h ../include/packetsender.h ../include/utils.h \ ../include/ipaddress.h ../include/hwaddress.h \ @@ -286,6 +355,52 @@ src/dot11/beacon.o: src/dot11/beacon.cpp ../include/dot11.h \ include/tests/dot11.h: +include/tests/dot11.h: +src/dot11/deauthentication.o: src/dot11/deauthentication.cpp \ + ../include/dot11.h ../include/pdu.h ../include/packetsender.h \ + ../include/utils.h ../include/ipaddress.h ../include/hwaddress.h \ + ../include/network_interface.h include/tests/dot11.h \ + include/tests/dot11.h + +../include/dot11.h: + +../include/pdu.h: + +../include/packetsender.h: + +../include/utils.h: + +../include/ipaddress.h: + +../include/hwaddress.h: + +../include/network_interface.h: + +include/tests/dot11.h: + +include/tests/dot11.h: +src/dot11/disassoc.o: src/dot11/disassoc.cpp ../include/dot11.h \ + ../include/pdu.h ../include/packetsender.h ../include/utils.h \ + ../include/ipaddress.h ../include/hwaddress.h \ + ../include/network_interface.h include/tests/dot11.h \ + include/tests/dot11.h + +../include/dot11.h: + +../include/pdu.h: + +../include/packetsender.h: + +../include/utils.h: + +../include/ipaddress.h: + +../include/hwaddress.h: + +../include/network_interface.h: + +include/tests/dot11.h: + include/tests/dot11.h: src/dot11/dot11.o: src/dot11/dot11.cpp ../include/dot11.h \ ../include/pdu.h ../include/packetsender.h ../include/utils.h \ @@ -312,6 +427,75 @@ include/tests/dot11.h: include/tests/dot11.h: ../include/utils.h: +src/dot11/probe_request.o: src/dot11/probe_request.cpp ../include/dot11.h \ + ../include/pdu.h ../include/packetsender.h ../include/utils.h \ + ../include/ipaddress.h ../include/hwaddress.h \ + ../include/network_interface.h include/tests/dot11.h \ + include/tests/dot11.h + +../include/dot11.h: + +../include/pdu.h: + +../include/packetsender.h: + +../include/utils.h: + +../include/ipaddress.h: + +../include/hwaddress.h: + +../include/network_interface.h: + +include/tests/dot11.h: + +include/tests/dot11.h: +src/dot11/reassoc_request.o: src/dot11/reassoc_request.cpp \ + ../include/dot11.h ../include/pdu.h ../include/packetsender.h \ + ../include/utils.h ../include/ipaddress.h ../include/hwaddress.h \ + ../include/network_interface.h include/tests/dot11.h \ + include/tests/dot11.h + +../include/dot11.h: + +../include/pdu.h: + +../include/packetsender.h: + +../include/utils.h: + +../include/ipaddress.h: + +../include/hwaddress.h: + +../include/network_interface.h: + +include/tests/dot11.h: + +include/tests/dot11.h: +src/dot11/reassoc_response.o: src/dot11/reassoc_response.cpp \ + ../include/dot11.h ../include/pdu.h ../include/packetsender.h \ + ../include/utils.h ../include/ipaddress.h ../include/hwaddress.h \ + ../include/network_interface.h include/tests/dot11.h \ + include/tests/dot11.h + +../include/dot11.h: + +../include/pdu.h: + +../include/packetsender.h: + +../include/utils.h: + +../include/ipaddress.h: + +../include/hwaddress.h: + +../include/network_interface.h: + +include/tests/dot11.h: + +include/tests/dot11.h: ../src/arp.o: ../src/arp.cpp ../include/arp.h ../include/pdu.h \ ../include/packetsender.h ../include/ipaddress.h ../include/utils.h \ ../include/hwaddress.h ../include/network_interface.h ../include/ip.h \ diff --git a/tests/include/tests/dot11.h b/tests/include/tests/dot11.h index b8d427f..c470d5f 100644 --- a/tests/include/tests/dot11.h +++ b/tests/include/tests/dot11.h @@ -5,6 +5,7 @@ using Tins::Dot11; using Tins::Dot11ManagementFrame; +using Tins::Dot11Data; typedef Dot11ManagementFrame::CapabilityInformation CapabilityInformation; @@ -33,6 +34,16 @@ inline void test_equals(const Dot11ManagementFrame& b1, const Dot11ManagementFra test_equals(static_cast(b1), static_cast(b2)); } +inline void test_equals(const Dot11Data& b1, const Dot11Data& b2) { + EXPECT_EQ(b1.addr2(), b2.addr2()); + EXPECT_EQ(b1.addr3(), b2.addr3()); + EXPECT_EQ(b1.addr4(), b2.addr4()); + EXPECT_EQ(b1.frag_num(), b2.frag_num()); + EXPECT_EQ(b1.seq_num(), b2.seq_num()); + + 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()); @@ -68,6 +79,15 @@ inline void test_equals_expected(const Dot11ManagementFrame &dot11) { EXPECT_EQ(dot11.addr3(), "02:03:04:05:06:07"); } +inline void test_equals_expected(const Dot11Data &dot11) { + EXPECT_EQ(dot11.type(), Dot11::DATA); + EXPECT_EQ(dot11.addr1(), "00:01:02:03:04:05"); + EXPECT_EQ(dot11.addr2(), "01:02:03:04:05:06"); + EXPECT_EQ(dot11.addr3(), "02:03:04:05:06:07"); + EXPECT_EQ(dot11.frag_num(), 0xa); + EXPECT_EQ(dot11.seq_num(), 0xf1d); +} + inline void test_equals_empty(const Dot11 &dot11) { Dot11::address_type empty_addr; @@ -96,6 +116,16 @@ inline void test_equals_empty(const Dot11ManagementFrame &dot11) { test_equals_empty(static_cast(dot11)); } +inline void test_equals_empty(const Dot11Data &dot11) { + Dot11::address_type empty_addr; + + EXPECT_EQ(dot11.addr1(), empty_addr); + EXPECT_EQ(dot11.addr2(), empty_addr); + EXPECT_EQ(dot11.addr3(), empty_addr); + EXPECT_EQ(dot11.frag_num(), 0); + EXPECT_EQ(dot11.seq_num(), 0); +} + inline void test_equals_empty(const CapabilityInformation &info) { EXPECT_EQ(info.ess(), 0); EXPECT_EQ(info.ibss(), 0); diff --git a/tests/src/dot11/data.cpp b/tests/src/dot11/data.cpp new file mode 100644 index 0000000..64768ac --- /dev/null +++ b/tests/src/dot11/data.cpp @@ -0,0 +1,63 @@ +#include +#include +#include +#include +#include "dot11.h" +#include "tests/dot11.h" + + +using namespace std; +using namespace Tins; + +typedef Dot11::address_type address_type; + +class Dot11DataTest : public testing::Test { +public: + static const address_type empty_addr, hwaddr; + static const uint8_t expected_packet[]; +}; + +const uint8_t Dot11DataTest::expected_packet[] = { + '\t', '\x00', 'O', '#', '\x00', '\x01', '\x02', '\x03', '\x04', + '\x05', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x02', + '\x03', '\x04', '\x05', '\x06', '\x07', '\x00', '\x00' +}; + +TEST_F(Dot11DataTest, Constructor) { + Dot11Data dot11; + test_equals_empty(dot11); + +} + +TEST_F(Dot11DataTest, ConstructorFromBuffer) { + Dot11Data dot11(expected_packet, sizeof(expected_packet)); + test_equals_expected(dot11); +} + +TEST_F(Dot11DataTest, CopyConstructor) { + Dot11Data dot1(expected_packet, sizeof(expected_packet)); + Dot11Data dot2(dot1); + test_equals(dot1, dot2); +} + +TEST_F(Dot11DataTest, CopyAssignmentOperator) { + Dot11Data dot1(expected_packet, sizeof(expected_packet)); + Dot11Data dot2; + dot2 = dot1; + test_equals(dot1, dot2); +} + +TEST_F(Dot11DataTest, ClonePDU) { + Dot11Data dot1(expected_packet, sizeof(expected_packet)); + std::auto_ptr dot2(dot1.clone_pdu()); + test_equals(dot1, *dot2); +} + +TEST_F(Dot11DataTest, FromBytes) { + std::auto_ptr dot11(Dot11::from_bytes(expected_packet, sizeof(expected_packet))); + ASSERT_TRUE(dot11.get()); + const Dot11Data *inner = dot11->find_inner_pdu(); + ASSERT_TRUE(inner); + test_equals_expected(*inner); +} + diff --git a/tests/src/dot11/probe_request.cpp b/tests/src/dot11/probe_request.cpp new file mode 100644 index 0000000..7763ece --- /dev/null +++ b/tests/src/dot11/probe_request.cpp @@ -0,0 +1,75 @@ +#include +#include +#include +#include +#include "dot11.h" +#include "tests/dot11.h" + + +using namespace std; +using namespace Tins; + +typedef Dot11::address_type address_type; + +class Dot11ProbeRequestTest : public testing::Test { +public: + static const address_type empty_addr, hwaddr; + static const uint8_t expected_packet[]; +}; + +const uint8_t Dot11ProbeRequestTest::expected_packet[] = { + 'A', '\x01', 'O', '#', '\x00', '\x01', '\x02', '\x03', '\x04', + '\x05', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x02', + '\x03', '\x04', '\x05', '\x06', '\x07', '\x00', '\x00' +}; + +void test_equals(const Dot11ProbeRequest &dot1, const Dot11ProbeRequest &dot2) { + test_equals( + static_cast(dot1), + static_cast(dot2) + ); +} + +void test_equals_expected(const Dot11ProbeRequest &dot11) { + test_equals_expected(static_cast(dot11)); + EXPECT_EQ(dot11.subtype(), Dot11::PROBE_REQ); +} + +TEST_F(Dot11ProbeRequestTest, Constructor) { + Dot11ProbeRequest dot11; + test_equals_empty(static_cast(dot11)); + EXPECT_EQ(dot11.subtype(), Dot11::PROBE_REQ); +} + +TEST_F(Dot11ProbeRequestTest, ConstructorFromBuffer) { + Dot11ProbeRequest dot11(expected_packet, sizeof(expected_packet)); + test_equals_expected(dot11); +} + +TEST_F(Dot11ProbeRequestTest, CopyConstructor) { + Dot11ProbeRequest dot1(expected_packet, sizeof(expected_packet)); + Dot11ProbeRequest dot2(dot1); + test_equals(dot1, dot2); +} + +TEST_F(Dot11ProbeRequestTest, CopyAssignmentOperator) { + Dot11ProbeRequest dot1(expected_packet, sizeof(expected_packet)); + Dot11ProbeRequest dot2; + dot2 = dot1; + test_equals(dot1, dot2); +} + +TEST_F(Dot11ProbeRequestTest, ClonePDU) { + Dot11ProbeRequest dot1(expected_packet, sizeof(expected_packet)); + std::auto_ptr dot2(dot1.clone_pdu()); + test_equals(dot1, *dot2); +} + +TEST_F(Dot11ProbeRequestTest, FromBytes) { + std::auto_ptr dot11(Dot11::from_bytes(expected_packet, sizeof(expected_packet))); + ASSERT_TRUE(dot11.get()); + const Dot11ProbeRequest *inner = dot11->find_inner_pdu(); + ASSERT_TRUE(inner); + test_equals_expected(*inner); +} + diff --git a/tests/src/dot11/probe_response.cpp b/tests/src/dot11/probe_response.cpp new file mode 100644 index 0000000..79954dd --- /dev/null +++ b/tests/src/dot11/probe_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 Dot11ProbeResponseTest : public testing::Test { +public: + static const address_type empty_addr, hwaddr; + static const uint8_t expected_packet[]; +}; + +const uint8_t Dot11ProbeResponseTest::expected_packet[] = { + 'Q', '\x01', 'O', '#', '\x00', '\x01', '\x02', '\x03', '\x04', + '\x05', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x02', + '\x03', '\x04', '\x05', '\x06', '\x07', '\x00', '\x00', '\x91', + '\x8a', '\x83', '\'', '\xdf', '\x98', '\xa6', '\x17', '\x8d', + '\x92', '\x00', '\x00' +}; + +void test_equals(const Dot11ProbeResponse &dot1, const Dot11ProbeResponse &dot2) { + EXPECT_EQ(dot1.interval(), dot2.interval()); + EXPECT_EQ(dot1.timestamp(), dot2.timestamp()); + test_equals( + static_cast(dot1), + static_cast(dot2) + ); +} + +void test_equals_expected(const Dot11ProbeResponse &dot11) { + test_equals_expected(static_cast(dot11)); + EXPECT_EQ(dot11.timestamp(), 0x17a698df27838a91); + EXPECT_EQ(dot11.interval(), 0x928d); + EXPECT_EQ(dot11.subtype(), Dot11::PROBE_RESP); +} + +TEST_F(Dot11ProbeResponseTest, Constructor) { + Dot11ProbeResponse dot11; + test_equals_empty(static_cast(dot11)); + EXPECT_EQ(dot11.timestamp(), 0); + EXPECT_EQ(dot11.interval(), 0); + EXPECT_EQ(dot11.subtype(), Dot11::PROBE_RESP); +} + +TEST_F(Dot11ProbeResponseTest, ConstructorFromBuffer) { + Dot11ProbeResponse dot11(expected_packet, sizeof(expected_packet)); + test_equals_expected(dot11); +} + +TEST_F(Dot11ProbeResponseTest, CopyConstructor) { + Dot11ProbeResponse dot1(expected_packet, sizeof(expected_packet)); + Dot11ProbeResponse dot2(dot1); + test_equals(dot1, dot2); +} + +TEST_F(Dot11ProbeResponseTest, CopyAssignmentOperator) { + Dot11ProbeResponse dot1(expected_packet, sizeof(expected_packet)); + Dot11ProbeResponse dot2; + dot2 = dot1; + test_equals(dot1, dot2); +} + +TEST_F(Dot11ProbeResponseTest, ClonePDU) { + Dot11ProbeResponse dot1(expected_packet, sizeof(expected_packet)); + std::auto_ptr dot2(dot1.clone_pdu()); + test_equals(dot1, *dot2); +} + +TEST_F(Dot11ProbeResponseTest, FromBytes) { + std::auto_ptr dot11(Dot11::from_bytes(expected_packet, sizeof(expected_packet))); + ASSERT_TRUE(dot11.get()); + const Dot11ProbeResponse *inner = dot11->find_inner_pdu(); + ASSERT_TRUE(inner); + test_equals_expected(*inner); +} +