diff --git a/include/dot11.h b/include/dot11.h index f3a11db..50310cd 100644 --- a/include/dot11.h +++ b/include/dot11.h @@ -1551,11 +1551,11 @@ namespace Tins { uint8_t addr3[address_type::address_size]; struct { #if __BYTE_ORDER == __LITTLE_ENDIAN - unsigned int frag_number:4; - unsigned int seq_number:12; + uint16_t frag_number:4, + seq_number:12; #elif __BYTE_ORDER == __BIG_ENDIAN - unsigned int seq_number:12; - unsigned int frag_number:4; + uint16_t seq_number:12, + frag_number:4; #endif } __attribute__((__packed__)) seq_control; } __attribute__((__packed__)); @@ -2642,7 +2642,7 @@ namespace Tins { uint64_t timestamp; uint16_t interval; CapabilityInformation capability; - }; + } __attribute__((__packed__)); ProbeResp _body; @@ -2772,21 +2772,20 @@ namespace Tins { } protected: struct ExtendedHeader { - uint8_t addr2[6]; - uint8_t addr3[6]; + uint8_t addr2[address_type::address_size]; + uint8_t addr3[address_type::address_size]; 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; + #if TINS_IS_LITTLE_ENDIAN + uint16_t frag_number:4, + seq_number:12; + #elif TINS_IS_BIG_ENDIAN + uint16_t frag_number:4, + seq_number:12; #endif } __attribute__((__packed__)) seq_control; } __attribute__((__packed__)); uint32_t write_ext_header(uint8_t *buffer, uint32_t total_sz); - void copy_ext_header(const Dot11Data *other); uint32_t data_frame_size() { return sizeof(_ext_header) + (from_ds() && to_ds()) ? sizeof(_addr4) : 0; } private: @@ -2824,23 +2823,13 @@ namespace Tins { * \param total_sz The total size of the buffer. */ Dot11QoSData(const uint8_t *buffer, uint32_t total_sz); - - /** - * \brief Copy constructor. - */ - Dot11QoSData(const Dot11QoSData &other); - - /** - * \brief Copy assignment operator. - */ - Dot11QoSData &operator= (const Dot11QoSData &other); - + /** * \brief Getter for the qos_control field. * * \return The value of the qos_control field in an uint16_t. */ - uint16_t qos_control() const { return _qos_control; } + uint16_t qos_control() const { return Utils::le_to_host(_qos_control); } /** * \brief Setter for the qos_control field. @@ -2881,7 +2870,6 @@ namespace Tins { return flag == PDU::DOT11_QOS_DATA || Dot11Data::matches_flag(flag); } private: - void copy_fields(const Dot11QoSData *other); uint32_t write_fixed_parameters(uint8_t *buffer, uint32_t total_sz); @@ -2941,6 +2929,17 @@ namespace Tins { * that contain a target address. */ class Dot11ControlTA : public Dot11Control { + public: + /** + * \brief Getter for the target address field. + */ + address_type target_addr() const { return _taddr; } + + /** + * \brief Setter for the target address field. + * \param addr The new target address. + */ + void target_addr(const address_type &addr); protected: /** * \brief Constructor for creating a 802.11 control frame TA PDU @@ -2966,17 +2965,6 @@ namespace Tins { */ Dot11ControlTA(const uint8_t *buffer, uint32_t total_sz); - /** - * \brief Getter for the target address field. - */ - address_type target_addr() const { return _taddr; } - - /** - * \brief Setter for the target address field. - * \param addr The new target address. - */ - void target_addr(const address_type &addr); - /** * \brief Returns the 802.11 frame's header length. * @@ -2993,7 +2981,7 @@ namespace Tins { uint32_t write_ext_header(uint8_t *buffer, uint32_t total_sz); private: - uint8_t _taddr[6]; + address_type _taddr; }; class Dot11RTS : public Dot11ControlTA { @@ -3032,13 +3020,15 @@ namespace Tins { * * \sa PDU::clone_pdu */ - PDU *clone_pdu() const; + Dot11RTS *clone_pdu() const { + return new Dot11RTS(*this); + } /** * \brief Getter for the PDU's type. * \sa PDU::pdu_type */ - PDUType pdu_type() const { return PDU::DOT11_RTS; } + PDUType pdu_type() const { return pdu_flag; } /** * \brief Check wether this PDU matches the specified flag. @@ -3046,7 +3036,7 @@ namespace Tins { * \sa PDU::matches_flag */ bool matches_flag(PDUType flag) { - return flag == PDU::DOT11_RTS || Dot11Control::matches_flag(flag); + return flag == pdu_flag || Dot11Control::matches_flag(flag); } }; @@ -3086,13 +3076,15 @@ namespace Tins { * * \sa PDU::clone_pdu */ - PDU *clone_pdu() const; + Dot11PSPoll *clone_pdu() const { + return new Dot11PSPoll(*this); + } /** * \brief Getter for the PDU's type. * \sa PDU::pdu_type */ - PDUType pdu_type() const { return PDU::DOT11_PS_POLL; } + PDUType pdu_type() const { return pdu_flag; } /** * \brief Check wether this PDU matches the specified flag. @@ -3100,7 +3092,7 @@ namespace Tins { * \sa PDU::matches_flag */ bool matches_flag(PDUType flag) { - return flag == PDU::DOT11_PS_POLL || Dot11Control::matches_flag(flag); + return flag == pdu_flag || Dot11Control::matches_flag(flag); } }; @@ -3140,13 +3132,15 @@ namespace Tins { * * \sa PDU::clone_pdu */ - PDU *clone_pdu() const; + Dot11CFEnd *clone_pdu() const { + return new Dot11CFEnd(*this); + } /** * \brief Getter for the PDU's type. * \sa PDU::pdu_type */ - PDUType pdu_type() const { return PDU::DOT11_CF_END; } + PDUType pdu_type() const { return pdu_flag; } /** * \brief Check wether this PDU matches the specified flag. @@ -3154,7 +3148,7 @@ namespace Tins { * \sa PDU::matches_flag */ bool matches_flag(PDUType flag) { - return flag == PDU::DOT11_CF_END || Dot11Control::matches_flag(flag); + return flag == pdu_flag || Dot11Control::matches_flag(flag); } }; @@ -3193,13 +3187,15 @@ namespace Tins { * * \sa PDU::clone_pdu */ - PDU *clone_pdu() const; + Dot11EndCFAck *clone_pdu() const { + return new Dot11EndCFAck(*this); + } /** * \brief Getter for the PDU's type. * \sa PDU::pdu_type */ - PDUType pdu_type() const { return PDU::DOT11_END_CF_ACK; } + PDUType pdu_type() const { return pdu_flag; } /** * \brief Check wether this PDU matches the specified flag. @@ -3207,7 +3203,7 @@ namespace Tins { * \sa PDU::matches_flag */ bool matches_flag(PDUType flag) { - return flag == PDU::DOT11_END_CF_ACK || Dot11Control::matches_flag(flag); + return flag == pdu_flag || Dot11Control::matches_flag(flag); } }; @@ -3245,13 +3241,15 @@ namespace Tins { * * \sa PDU::clone_pdu */ - PDU *clone_pdu() const; + Dot11Ack *clone_pdu() const { + return new Dot11Ack(*this); + } /** * \brief Getter for the PDU's type. * \sa PDU::pdu_type */ - PDUType pdu_type() const { return PDU::DOT11_ACK; } + PDUType pdu_type() const { return pdu_flag; } /** * \brief Check wether this PDU matches the specified flag. @@ -3259,7 +3257,7 @@ namespace Tins { * \sa PDU::matches_flag */ bool matches_flag(PDUType flag) { - return flag == PDU::DOT11_ACK || Dot11Control::matches_flag(flag); + return flag == pdu_flag || Dot11Control::matches_flag(flag); } }; @@ -3302,17 +3300,24 @@ namespace Tins { * \brief Getter for the bar control field. * \return The bar control field. */ - uint16_t bar_control() const { return _bar_control.tid; } + uint16_t bar_control() const { return Utils::le_to_host(_bar_control.tid); } /** * \brief Getter for the start sequence field. * \return The bar start sequence. */ - uint16_t start_sequence() const { return (_start_sequence.frag << 12) | (_start_sequence.seq); } + uint16_t start_sequence() const { return Utils::le_to_host(_start_sequence.seq); } + + /** + * \brief Getter for the fragment number field. + * \return The fragment number field. + */ + uint8_t fragment_number() const { return _start_sequence.frag; } + /** * \brief Returns the 802.11 frame's header length. * - * \return An uint32_t with the header's size. + * \return The header's size. * \sa PDU::header_size() */ uint32_t header_size() const; @@ -3330,19 +3335,27 @@ namespace Tins { * \param bar The new start sequence field. */ void start_sequence(uint16_t seq); + + /** + * \brief Setter for the fragment number field. + * \param frag The new fragment number field. + */ + void fragment_number(uint8_t frag); /** * \brief Clones this PDU. * * \sa PDU::clone_pdu */ - PDU *clone_pdu() const; + Dot11BlockAckRequest *clone_pdu() const { + return new Dot11BlockAckRequest(*this); + } /** * \brief Getter for the PDU's type. * \sa PDU::pdu_type */ - PDUType pdu_type() const { return PDU::DOT11_BLOCK_ACK_REQ; } + PDUType pdu_type() const { return pdu_flag; } /** * \brief Check wether this PDU matches the specified flag. @@ -3350,7 +3363,7 @@ namespace Tins { * \sa PDU::matches_flag */ bool matches_flag(PDUType flag) { - return flag == PDU::DOT11_BLOCK_ACK_REQ || Dot11Control::matches_flag(flag); + return flag == pdu_flag || Dot11Control::matches_flag(flag); } protected: uint32_t write_ext_header(uint8_t *buffer, uint32_t total_sz); @@ -3455,7 +3468,7 @@ namespace Tins { * \brief Getter for the PDU's type. * \sa PDU::pdu_type */ - PDUType pdu_type() const { return PDU::DOT11_BLOCK_ACK; } + PDUType pdu_type() const { return pdu_flag; } /** * \brief Check wether this PDU matches the specified flag. @@ -3463,7 +3476,7 @@ namespace Tins { * \sa PDU::matches_flag */ bool matches_flag(PDUType flag) { - return flag == PDU::DOT11_BLOCK_ACK || Dot11Control::matches_flag(flag); + return flag == pdu_flag || Dot11Control::matches_flag(flag); } /** @@ -3471,7 +3484,9 @@ namespace Tins { * * \sa PDU::clone_pdu */ - PDU *clone_pdu() const; + Dot11BlockAck *clone_pdu() const { + return new Dot11BlockAck(*this); + } private: struct BarControl { uint16_t reserved:12, diff --git a/src/dot11.cpp b/src/dot11.cpp index 95d9566..bdb7427 100644 --- a/src/dot11.cpp +++ b/src/dot11.cpp @@ -63,12 +63,6 @@ Dot11::Dot11(const ieee80211_header *header_ptr) Dot11::Dot11(const uint8_t *buffer, uint32_t total_sz) : PDU(ETHERTYPE_IP), _options_size(0) { - /*if(total_sz < sizeof(_header.control)) - throw runtime_error("Not enough size for an IEEE 802.11 header in the buffer."); - uint32_t sz = std::min((uint32_t)sizeof(_header), total_sz); - std::memcpy(&_header, buffer, sz); - buffer += sz; - total_sz -= sz;*/ if(total_sz < sizeof(_header)) throw runtime_error("Not enough size for an Dot11 header in the buffer."); std::memcpy(&_header, buffer, sizeof(_header)); @@ -81,17 +75,20 @@ Dot11 &Dot11::operator= (const Dot11 &other) { } void Dot11::parse_tagged_parameters(const uint8_t *buffer, uint32_t total_sz) { - uint8_t opcode, length; - while(total_sz >= 2) { - opcode = buffer[0]; - length = buffer[1]; - buffer += 2; - total_sz -= 2; - if(length > total_sz) - return; //malformed - add_tagged_option((TaggedOption)opcode, length, buffer); - buffer += length; - total_sz -= length; + if(total_sz > 0) { + uint8_t opcode, length; + while(total_sz >= 2) { + opcode = buffer[0]; + length = buffer[1]; + buffer += 2; + total_sz -= 2; + if(length > total_sz) { + throw std::runtime_error("Malformed option encountered"); + } + add_tagged_option((TaggedOption)opcode, length, buffer); + buffer += length; + total_sz -= length; + } } } @@ -1197,6 +1194,9 @@ Dot11ProbeRequest::Dot11ProbeRequest(const NetworkInterface& iface, Dot11ProbeRequest::Dot11ProbeRequest(const uint8_t *buffer, uint32_t total_sz) : Dot11ManagementFrame(buffer, total_sz) { + uint32_t sz = management_frame_size(); + buffer += sz; + total_sz -= sz; parse_tagged_parameters(buffer, total_sz); } @@ -1256,11 +1256,11 @@ Dot11Data::Dot11Data(const uint8_t *buffer, uint32_t total_sz) buffer += sizeof(_ext_header); total_sz -= sizeof(_ext_header); if(from_ds() && to_ds()) { - if(total_sz < sizeof(_addr4)) + if(total_sz < _addr4.size()) throw runtime_error("Not enough size for an IEEE 802.11 data header in the buffer."); - std::memcpy(&_addr4, buffer, sizeof(_addr4)); - buffer += sizeof(_addr4); - total_sz -= sizeof(_addr4); + _addr4 = buffer; + buffer += _addr4.size(); + total_sz -= _addr4.size(); } if(total_sz) inner_pdu(new Tins::SNAP(buffer, total_sz)); @@ -1277,12 +1277,6 @@ Dot11Data::Dot11Data(const NetworkInterface &iface, addr2(src_hw_addr); } -void Dot11Data::copy_ext_header(const Dot11Data* other) { - /*Dot11::copy_80211_fields(other); - std::memcpy(&this->_ext_header, &other->_ext_header, sizeof(this->_ext_header)); - _addr4, other->_addr4, 6);*/ -} - uint32_t Dot11Data::header_size() const { uint32_t sz = Dot11::header_size() + sizeof(_ext_header); if (this->from_ds() && this->to_ds()) @@ -1303,7 +1297,7 @@ void Dot11Data::frag_num(uint8_t new_frag_num) { } void Dot11Data::seq_num(uint16_t new_seq_num) { - _ext_header.seq_control.seq_number = new_seq_num; + _ext_header.seq_control.seq_number = Utils::host_to_le(new_seq_num); } void Dot11Data::addr4(const address_type &new_addr4) { @@ -1349,23 +1343,8 @@ Dot11QoSData::Dot11QoSData(const uint8_t *buffer, uint32_t total_sz) inner_pdu(new Tins::SNAP(buffer, total_sz)); } -Dot11QoSData::Dot11QoSData(const Dot11QoSData &other) : Dot11Data(other) { - copy_fields(&other); -} - -Dot11QoSData &Dot11QoSData::operator= (const Dot11QoSData &other) { - copy_inner_pdu(other); - copy_fields(&other); - return *this; -} - -void Dot11QoSData::copy_fields(const Dot11QoSData *other) { - Dot11Data::copy_ext_header(other); - _qos_control = other->_qos_control; -} - void Dot11QoSData::qos_control(uint16_t new_qos_control) { - this->_qos_control = new_qos_control; + this->_qos_control = Utils::host_to_le(new_qos_control); } uint32_t Dot11QoSData::header_size() const { @@ -1407,7 +1386,8 @@ Dot11ControlTA::Dot11ControlTA(const uint8_t *buffer, uint32_t total_sz) : Dot11 total_sz -= sizeof(ieee80211_header); if(total_sz < sizeof(_taddr)) throw runtime_error("Not enough size for an IEEE 802.11 RTS frame in the buffer."); - std::memcpy(_taddr, buffer, sizeof(_taddr)); + //std::memcpy(_taddr, buffer, sizeof(_taddr)); + _taddr = buffer; } uint32_t Dot11ControlTA::header_size() const { @@ -1416,12 +1396,13 @@ uint32_t Dot11ControlTA::header_size() const { uint32_t Dot11ControlTA::write_ext_header(uint8_t *buffer, uint32_t total_sz) { assert(total_sz >= sizeof(_taddr)); - std::memcpy(buffer, _taddr, sizeof(_taddr)); + //std::memcpy(buffer, _taddr, sizeof(_taddr)); + _taddr.copy(buffer); return sizeof(_taddr); } void Dot11ControlTA::target_addr(const address_type &addr) { - std::copy(addr.begin(), addr.end(), _taddr); + _taddr = addr; } /* Dot11RTS */ @@ -1438,12 +1419,6 @@ Dot11RTS::Dot11RTS(const uint8_t *buffer, uint32_t total_sz) } -PDU *Dot11RTS::clone_pdu() const { - Dot11RTS *new_pdu = new Dot11RTS(); - new_pdu->copy_80211_fields(this); - return new_pdu; -} - /* Dot11PSPoll */ Dot11PSPoll::Dot11PSPoll(const NetworkInterface &iface, @@ -1458,12 +1433,6 @@ Dot11PSPoll::Dot11PSPoll(const uint8_t *buffer, uint32_t total_sz) } -PDU *Dot11PSPoll::clone_pdu() const { - Dot11PSPoll *new_pdu = new Dot11PSPoll(); - new_pdu->copy_80211_fields(this); - return new_pdu; -} - /* Dot11CFEnd */ Dot11CFEnd::Dot11CFEnd(const NetworkInterface &iface, @@ -1478,12 +1447,6 @@ Dot11CFEnd::Dot11CFEnd(const uint8_t *buffer, uint32_t total_sz) } -PDU *Dot11CFEnd::clone_pdu() const { - Dot11CFEnd *new_pdu = new Dot11CFEnd(); - new_pdu->copy_80211_fields(this); - return new_pdu; -} - /* Dot11EndCFAck */ Dot11EndCFAck::Dot11EndCFAck(const NetworkInterface &iface, @@ -1498,12 +1461,6 @@ Dot11EndCFAck::Dot11EndCFAck(const uint8_t *buffer, uint32_t total_sz) } -PDU *Dot11EndCFAck::clone_pdu() const { - Dot11EndCFAck *new_pdu = new Dot11EndCFAck(); - new_pdu->copy_80211_fields(this); - return new_pdu; -} - /* Dot11Ack */ Dot11Ack::Dot11Ack(const NetworkInterface &iface, @@ -1517,12 +1474,6 @@ Dot11Ack::Dot11Ack(const uint8_t *buffer, uint32_t total_sz) : Dot11Control(buff } -PDU *Dot11Ack::clone_pdu() const { - Dot11Ack *ack = new Dot11Ack(); - ack->copy_80211_fields(this); - return ack; -} - /* Dot11BlockAck */ Dot11BlockAckRequest::Dot11BlockAckRequest(const NetworkInterface &iface, @@ -1559,23 +1510,23 @@ uint32_t Dot11BlockAckRequest::write_ext_header(uint8_t *buffer, uint32_t total_ } void Dot11BlockAckRequest::bar_control(uint16_t bar) { - std::memcpy(&_bar_control, &bar, sizeof(bar)); + //std::memcpy(&_bar_control, &bar, sizeof(bar)); + _bar_control.tid = Utils::host_to_le(bar); } void Dot11BlockAckRequest::start_sequence(uint16_t seq) { - std::memcpy(&_start_sequence, &seq, sizeof(seq)); + //std::memcpy(&_start_sequence, &seq, sizeof(seq)); + _start_sequence.seq = Utils::host_to_le(seq); +} + +void Dot11BlockAckRequest::fragment_number(uint8_t frag) { + _start_sequence.frag = frag; } uint32_t Dot11BlockAckRequest::header_size() const { return Dot11ControlTA::header_size() + sizeof(_start_sequence) + sizeof(_start_sequence); } -PDU *Dot11BlockAckRequest::clone_pdu() const { - Dot11BlockAckRequest *new_pdu = new Dot11BlockAckRequest(); - new_pdu->copy_80211_fields(this); - return new_pdu; -} - /* Dot11BlockAck */ Dot11BlockAck::Dot11BlockAck(const NetworkInterface &iface, @@ -1626,12 +1577,6 @@ uint32_t Dot11BlockAck::header_size() const { return Dot11ControlTA::header_size() + sizeof(_start_sequence) + sizeof(_start_sequence) + sizeof(_bitmap); } -PDU *Dot11BlockAck::clone_pdu() const { - Dot11BlockAck *new_pdu = new Dot11BlockAck(); - new_pdu->copy_80211_fields(this); - return new_pdu; -} - /* RSNInformation */ RSNInformation::RSNInformation() : _version(1), _capabilities(0) { diff --git a/tests/include/tests/dot11.h b/tests/include/tests/dot11.h index c470d5f..118972d 100644 --- a/tests/include/tests/dot11.h +++ b/tests/include/tests/dot11.h @@ -6,7 +6,9 @@ using Tins::Dot11; using Tins::Dot11ManagementFrame; using Tins::Dot11Data; +using Tins::Dot11ControlTA; +typedef Dot11::address_type address_type; typedef Dot11ManagementFrame::CapabilityInformation CapabilityInformation; inline void test_equals(const Dot11 &dot1, const Dot11 &dot2) { @@ -44,6 +46,11 @@ inline void test_equals(const Dot11Data& b1, const Dot11Data& b2) { test_equals(static_cast(b1), static_cast(b2)); } +inline void test_equals(const Dot11ControlTA& b1, const Dot11ControlTA& b2) { + EXPECT_EQ(b1.target_addr(), b2.target_addr()); + 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()); @@ -88,6 +95,11 @@ inline void test_equals_expected(const Dot11Data &dot11) { EXPECT_EQ(dot11.seq_num(), 0xf1d); } +inline void test_equals_expected(const Dot11ControlTA &dot11) { + EXPECT_EQ(dot11.target_addr(), "01:02:03:04:05:06"); + EXPECT_EQ(dot11.addr1(), "00:01:02:03:04:05"); +} + inline void test_equals_empty(const Dot11 &dot11) { Dot11::address_type empty_addr; @@ -126,6 +138,13 @@ inline void test_equals_empty(const Dot11Data &dot11) { EXPECT_EQ(dot11.seq_num(), 0); } +inline void test_equals_empty(const Dot11ControlTA &dot11) { + Dot11::address_type empty_addr; + + EXPECT_EQ(dot11.target_addr(), empty_addr); + EXPECT_EQ(dot11.addr1(), empty_addr); +} + inline void test_equals_empty(const CapabilityInformation &info) { EXPECT_EQ(info.ess(), 0); EXPECT_EQ(info.ibss(), 0); diff --git a/tests/src/dot11/ack.cpp b/tests/src/dot11/ack.cpp new file mode 100644 index 0000000..6a121af --- /dev/null +++ b/tests/src/dot11/ack.cpp @@ -0,0 +1,103 @@ +#include +#include +#include +#include +#include "dot11.h" +#include "tests/dot11.h" + + +using namespace std; +using namespace Tins; + +typedef Dot11::address_type address_type; + +class Dot11AckTest : public testing::Test { +public: + static const address_type empty_addr, hwaddr; + static const uint8_t expected_packet[]; +}; + +const address_type Dot11AckTest::empty_addr; + +const uint8_t Dot11AckTest::expected_packet[] = { + '\xd5', '\x01', 'O', '#', '\x00', '\x01', '\x02', '\x03', '\x04', '\x05' +}; + +void test_equals(const Dot11Ack &dot1, const Dot11Ack &dot2) { + test_equals( + static_cast(dot1), + static_cast(dot2) + ); +} + +void test_equals_expected(const Dot11Ack &dot11) { + EXPECT_EQ(dot11.protocol(), 1); + EXPECT_EQ(dot11.type(), Dot11::CONTROL); + EXPECT_EQ(dot11.subtype(), Dot11::ACK); + EXPECT_EQ(dot11.to_ds(), 1); + EXPECT_EQ(dot11.from_ds(), 0); + EXPECT_EQ(dot11.more_frag(), 0); + EXPECT_EQ(dot11.retry(), 0); + EXPECT_EQ(dot11.power_mgmt(), 0); + EXPECT_EQ(dot11.wep(), 0); + EXPECT_EQ(dot11.order(), 0); + EXPECT_EQ(dot11.duration_id(), 0x234f); + EXPECT_EQ(dot11.subtype(), Dot11::ACK); + EXPECT_EQ(dot11.addr1(), "00:01:02:03:04:05"); +} + +TEST_F(Dot11AckTest, Constructor) { + Dot11Ack dot11; + test_equals_empty(static_cast(dot11)); + EXPECT_EQ(dot11.protocol(), 0); + EXPECT_EQ(dot11.type(), Dot11::CONTROL); + EXPECT_EQ(dot11.subtype(), Dot11::ACK); + EXPECT_EQ(dot11.to_ds(), 0); + EXPECT_EQ(dot11.from_ds(), 0); + EXPECT_EQ(dot11.more_frag(), 0); + EXPECT_EQ(dot11.retry(), 0); + EXPECT_EQ(dot11.power_mgmt(), 0); + EXPECT_EQ(dot11.wep(), 0); + EXPECT_EQ(dot11.order(), 0); + EXPECT_EQ(dot11.duration_id(), 0); + EXPECT_EQ(dot11.addr1(), empty_addr); +} + +TEST_F(Dot11AckTest, ConstructorFromBuffer) { + Dot11Ack dot11(expected_packet, sizeof(expected_packet)); + test_equals_expected(dot11); +} + +TEST_F(Dot11AckTest, CopyConstructor) { + Dot11Ack dot1(expected_packet, sizeof(expected_packet)); + Dot11Ack dot2(dot1); + test_equals(dot1, dot2); +} + +TEST_F(Dot11AckTest, CopyAssignmentOperator) { + Dot11Ack dot1(expected_packet, sizeof(expected_packet)); + Dot11Ack dot2; + dot2 = dot1; + test_equals(dot1, dot2); +} + +TEST_F(Dot11AckTest, ClonePDU) { + Dot11Ack dot1(expected_packet, sizeof(expected_packet)); + std::auto_ptr dot2(dot1.clone_pdu()); + test_equals(dot1, *dot2); +} + +TEST_F(Dot11AckTest, FromBytes) { + std::auto_ptr dot11(Dot11::from_bytes(expected_packet, sizeof(expected_packet))); + ASSERT_TRUE(dot11.get()); + const Dot11Ack *inner = dot11->find_inner_pdu(); + ASSERT_TRUE(inner); + test_equals_expected(*inner); +} + +TEST_F(Dot11AckTest, Serialize) { + Dot11Ack pdu(expected_packet, sizeof(expected_packet)); + PDU::serialization_type buffer = pdu.serialize(); + ASSERT_EQ(sizeof(expected_packet), buffer.size()); + EXPECT_TRUE(std::equal(buffer.begin(), buffer.end(), expected_packet)); +} diff --git a/tests/src/dot11/assoc_request.cpp b/tests/src/dot11/assoc_request.cpp index fab9327..4f06b6e 100644 --- a/tests/src/dot11/assoc_request.cpp +++ b/tests/src/dot11/assoc_request.cpp @@ -65,6 +65,12 @@ TEST_F(Dot11AssocRequestTest, CopyAssignmentOperator) { test_equals(dot1, dot2); } +TEST_F(Dot11AssocRequestTest, ListenInterval) { + Dot11AssocRequest dot11; + dot11.listen_interval(0x92fd); + EXPECT_EQ(dot11.listen_interval(), 0x92fd); +} + TEST_F(Dot11AssocRequestTest, ClonePDU) { Dot11AssocRequest dot1(expected_packet, sizeof(expected_packet)); std::auto_ptr dot2(dot1.clone_pdu()); @@ -79,3 +85,10 @@ TEST_F(Dot11AssocRequestTest, FromBytes) { test_equals_expected(*inner); } +TEST_F(Dot11AssocRequestTest, Serialize) { + Dot11AssocRequest pdu(expected_packet, sizeof(expected_packet)); + PDU::serialization_type buffer = pdu.serialize(); + ASSERT_EQ(sizeof(expected_packet), buffer.size()); + EXPECT_TRUE(std::equal(buffer.begin(), buffer.end(), expected_packet)); +} + diff --git a/tests/src/dot11/assoc_response.cpp b/tests/src/dot11/assoc_response.cpp index 8b35f9b..fde6694 100644 --- a/tests/src/dot11/assoc_response.cpp +++ b/tests/src/dot11/assoc_response.cpp @@ -67,6 +67,18 @@ TEST_F(Dot11AssocResponseTest, CopyAssignmentOperator) { test_equals(dot1, dot2); } +TEST_F(Dot11AssocResponseTest, StatusCode) { + Dot11AssocResponse dot11; + dot11.status_code(0x92f3); + EXPECT_EQ(dot11.status_code(), 0x92f3); +} + +TEST_F(Dot11AssocResponseTest, AID) { + Dot11AssocResponse dot11; + dot11.aid(0x92f3); + EXPECT_EQ(dot11.aid(), 0x92f3); +} + TEST_F(Dot11AssocResponseTest, ClonePDU) { Dot11AssocResponse dot1(expected_packet, sizeof(expected_packet)); std::auto_ptr dot2(dot1.clone_pdu()); @@ -82,3 +94,10 @@ TEST_F(Dot11AssocResponseTest, FromBytes) { test_equals_expected(*inner); } +TEST_F(Dot11AssocResponseTest, Serialize) { + Dot11AssocResponse pdu(expected_packet, sizeof(expected_packet)); + PDU::serialization_type buffer = pdu.serialize(); + ASSERT_EQ(sizeof(expected_packet), buffer.size()); + EXPECT_TRUE(std::equal(buffer.begin(), buffer.end(), expected_packet)); +} + diff --git a/tests/src/dot11/authentication.cpp b/tests/src/dot11/authentication.cpp index 2e2d3d4..cdf4fb9 100644 --- a/tests/src/dot11/authentication.cpp +++ b/tests/src/dot11/authentication.cpp @@ -69,6 +69,24 @@ TEST_F(Dot11AuthenticationTest, CopyAssignmentOperator) { test_equals(dot1, dot2); } +TEST_F(Dot11AuthenticationTest, StatusCode) { + Dot11Authentication dot11; + dot11.status_code(0x92f3); + EXPECT_EQ(dot11.status_code(), 0x92f3); +} + +TEST_F(Dot11AuthenticationTest, AuthSequenceNumber) { + Dot11Authentication dot11; + dot11.auth_seq_number(0x92f3); + EXPECT_EQ(dot11.auth_seq_number(), 0x92f3); +} + +TEST_F(Dot11AuthenticationTest, AuthAlgorithm) { + Dot11Authentication dot11; + dot11.auth_algorithm(0x92f3); + EXPECT_EQ(dot11.auth_algorithm(), 0x92f3); +} + TEST_F(Dot11AuthenticationTest, ClonePDU) { Dot11Authentication dot1(expected_packet, sizeof(expected_packet)); std::auto_ptr dot2(dot1.clone_pdu()); @@ -83,3 +101,10 @@ TEST_F(Dot11AuthenticationTest, FromBytes) { test_equals_expected(*inner); } +TEST_F(Dot11AuthenticationTest, Serialize) { + Dot11Authentication pdu(expected_packet, sizeof(expected_packet)); + PDU::serialization_type buffer = pdu.serialize(); + ASSERT_EQ(sizeof(expected_packet), buffer.size()); + EXPECT_TRUE(std::equal(buffer.begin(), buffer.end(), expected_packet)); +} + diff --git a/tests/src/dot11/beacon.cpp b/tests/src/dot11/beacon.cpp index d10aaac..6b15d2f 100644 --- a/tests/src/dot11/beacon.cpp +++ b/tests/src/dot11/beacon.cpp @@ -249,30 +249,30 @@ TEST_F(Dot11BeaconTest, Country) { TEST_F(Dot11BeaconTest, FHParameters) { Dot11Beacon dot11; - std::pair data(0x42, 0x1f); - dot11.fh_parameters(data.first, data.second); - EXPECT_EQ(data, dot11.fh_parameters()); + std::pair tim(0x42, 0x1f); + dot11.fh_parameters(tim.first, tim.second); + EXPECT_EQ(tim, dot11.fh_parameters()); } TEST_F(Dot11BeaconTest, FHPattern) { Dot11Beacon dot11; - Dot11Beacon::fh_pattern_type data, output; - data.flag = 0x67; - data.number_of_sets = 0x42; - data.modulus = 0x1f; - data.offset = 0x3a; - data.random_table.push_back(23); - data.random_table.push_back(15); - data.random_table.push_back(129); + Dot11Beacon::fh_pattern_type tim, output; + tim.flag = 0x67; + tim.number_of_sets = 0x42; + tim.modulus = 0x1f; + tim.offset = 0x3a; + tim.random_table.push_back(23); + tim.random_table.push_back(15); + tim.random_table.push_back(129); - dot11.fh_pattern_table(data); + dot11.fh_pattern_table(tim); output = dot11.fh_pattern_table(); - EXPECT_EQ(data.flag, data.flag); - EXPECT_EQ(data.number_of_sets, data.number_of_sets); - EXPECT_EQ(data.modulus, data.modulus); - EXPECT_EQ(data.offset, data.offset); - EXPECT_EQ(data.random_table, data.random_table); + EXPECT_EQ(tim.flag, tim.flag); + EXPECT_EQ(tim.number_of_sets, tim.number_of_sets); + EXPECT_EQ(tim.modulus, tim.modulus); + EXPECT_EQ(tim.offset, tim.offset); + EXPECT_EQ(tim.random_table, tim.random_table); } TEST_F(Dot11BeaconTest, PowerConstraint) { @@ -283,33 +283,33 @@ TEST_F(Dot11BeaconTest, PowerConstraint) { TEST_F(Dot11BeaconTest, ChannelSwitch) { Dot11Beacon dot11; - Dot11Beacon::channel_switch_type data(13, 42, 98), output; - dot11.channel_switch(data); + Dot11Beacon::channel_switch_type tim(13, 42, 98), output; + dot11.channel_switch(tim); output = dot11.channel_switch(); - EXPECT_EQ(output.switch_mode, data.switch_mode); - EXPECT_EQ(output.new_channel, data.new_channel); - EXPECT_EQ(output.switch_count, data.switch_count); + EXPECT_EQ(output.switch_mode, tim.switch_mode); + EXPECT_EQ(output.new_channel, tim.new_channel); + EXPECT_EQ(output.switch_count, tim.switch_count); } TEST_F(Dot11BeaconTest, Quiet) { Dot11Beacon dot11; - Dot11Beacon::quiet_type data(13, 42, 0x928f, 0xf1ad), output; - dot11.quiet(data); + Dot11Beacon::quiet_type tim(13, 42, 0x928f, 0xf1ad), output; + dot11.quiet(tim); output = dot11.quiet(); - EXPECT_EQ(output.quiet_count, data.quiet_count); - EXPECT_EQ(output.quiet_period, data.quiet_period); - EXPECT_EQ(output.quiet_duration, data.quiet_duration); - EXPECT_EQ(output.quiet_offset, data.quiet_offset); + EXPECT_EQ(output.quiet_count, tim.quiet_count); + EXPECT_EQ(output.quiet_period, tim.quiet_period); + EXPECT_EQ(output.quiet_duration, tim.quiet_duration); + EXPECT_EQ(output.quiet_offset, tim.quiet_offset); } TEST_F(Dot11BeaconTest, TPCReport) { Dot11Beacon dot11; - std::pair data(42, 193); - dot11.tpc_report(data.first, data.second); - EXPECT_EQ(dot11.tpc_report(), data); + std::pair tim(42, 193); + dot11.tpc_report(tim.first, tim.second); + EXPECT_EQ(dot11.tpc_report(), tim); } TEST_F(Dot11BeaconTest, ERPInformation) { @@ -320,33 +320,33 @@ TEST_F(Dot11BeaconTest, ERPInformation) { TEST_F(Dot11BeaconTest, BSSLoad) { Dot11Beacon dot11; - Dot11Beacon::bss_load_type data(0x129f, 42, 0xf5a2), output; - dot11.bss_load(data); + Dot11Beacon::bss_load_type tim(0x129f, 42, 0xf5a2), output; + dot11.bss_load(tim); output = dot11.bss_load(); - EXPECT_EQ(data.station_count, output.station_count); - EXPECT_EQ(data.channel_utilization, output.channel_utilization); - EXPECT_EQ(data.available_capacity, output.available_capacity); + EXPECT_EQ(tim.station_count, output.station_count); + EXPECT_EQ(tim.channel_utilization, output.channel_utilization); + EXPECT_EQ(tim.available_capacity, output.available_capacity); } TEST_F(Dot11BeaconTest, TIM) { Dot11Beacon dot11; - Dot11Beacon::tim_type data, output; - data.dtim_count = 42; - data.dtim_period = 59; - data.bitmap_control = 191; + Dot11Beacon::tim_type tim, output; + tim.dtim_count = 42; + tim.dtim_period = 59; + tim.bitmap_control = 191; - data.partial_virtual_bitmap.push_back(92); - data.partial_virtual_bitmap.push_back(182); - data.partial_virtual_bitmap.push_back(212); + tim.partial_virtual_bitmap.push_back(92); + tim.partial_virtual_bitmap.push_back(182); + tim.partial_virtual_bitmap.push_back(212); - dot11.tim(data); + dot11.tim(tim); output = dot11.tim(); - EXPECT_EQ(data.dtim_count, output.dtim_count); - EXPECT_EQ(data.dtim_period, output.dtim_period); - EXPECT_EQ(data.bitmap_control, output.bitmap_control); - EXPECT_EQ(data.partial_virtual_bitmap, output.partial_virtual_bitmap); + EXPECT_EQ(tim.dtim_count, output.dtim_count); + EXPECT_EQ(tim.dtim_period, output.dtim_period); + EXPECT_EQ(tim.bitmap_control, output.bitmap_control); + EXPECT_EQ(tim.partial_virtual_bitmap, output.partial_virtual_bitmap); } TEST_F(Dot11BeaconTest, ChallengeText) { @@ -355,3 +355,63 @@ TEST_F(Dot11BeaconTest, ChallengeText) { EXPECT_EQ(dot11.challenge_text(), "libtins ftw"); } + +TEST_F(Dot11BeaconTest, PCAPLoad1) { + const uint8_t buffer[] = { + '\x80', '\x00', '\x00', '\x00', '\xff', '\xff', '\xff', '\xff', + '\xff', '\xff', '\xf4', '\xec', '8', '\xfe', 'M', '\x92', '\xf4', + '\xec', '8', '\xfe', 'M', '\x92', '\xe0', '\xea', '\x80', '\xd1', + '\xd4', '\xce', ',', '\x00', '\x00', '\x00', 'd', '\x00', '1', + '\x04', '\x00', '\x07', 'S', 'e', 'g', 'u', 'n', 'd', 'o', '\x01', + '\x08', '\x82', '\x84', '\x8b', '\x96', '\x0c', '\x12', '\x18', '$', + '\x03', '\x01', '\x01', '\x05', '\x04', '\x00', '\x01', '\x00', + '\x00', '\x07', '\x06', 'U', 'S', ' ', '\x01', '\r', '\x14', '*', + '\x01', '\x00', '0', '\x14', '\x01', '\x00', '\x00', '\x0f', '\xac', + '\x04', '\x01', '\x00', '\x00', '\x0f', '\xac', '\x04', '\x01', + '\x00', '\x00', '\x0f', '\xac', '\x02', '\x00', '\x00', '2', '\x04', + '0', 'H', '`', 'l', '\xdd', '\x18', '\x00', 'P', '\xf2', '\x02', + '\x01', '\x01', '\x03', '\x00', '\x03', '\xa4', '\x00', '\x00', + '\'', '\xa4', '\x00', '\x00', 'B', 'C', '^', '\x00', 'b', '2', + '/', '\x00', '\xdd', '\t', '\x00', '\x03', '\x7f', '\x01', '\x01', + '\x00', '\x00', '\xff', '\x7f' + }; + typedef Dot11Beacon::country_params::container_type country_container; + Dot11Beacon dot11(buffer, sizeof(buffer)); + float rates[] = { 1.0f, 2.0f, 5.5f, 11.0f, 6.0f, 9.0f, 12.0f, 18.0f}, + ext_rates[] = { 24.0f, 36.0f, 48.0f, 54.0f }; + Dot11Beacon::rates_type rates_parsed = dot11.supported_rates(); + Dot11Beacon::rates_type ext_rates_parsed = dot11.extended_supported_rates(); + Dot11Beacon::tim_type tim(0, 1, 0, Dot11Beacon::tim_type::container_type(1)), + tim_parsed = dot11.tim(); + Dot11Beacon::country_params country("US ", + country_container(1, 1), + country_container(1, 13), + country_container(1, 20)), + country_parsed = dot11.country(); + EXPECT_EQ(dot11.ssid(), "Segundo"); + ASSERT_EQ(rates_parsed.size(), sizeof(rates) / sizeof(float)); + EXPECT_TRUE(std::equal(rates_parsed.begin(), rates_parsed.end(), rates)); + ASSERT_EQ(ext_rates_parsed.size(), sizeof(ext_rates) / sizeof(float)); + EXPECT_TRUE(std::equal(ext_rates_parsed.begin(), ext_rates_parsed.end(), ext_rates)); + EXPECT_EQ(1, dot11.ds_parameter_set()); + EXPECT_EQ(tim.dtim_count, tim_parsed.dtim_count); + EXPECT_EQ(tim.dtim_period, tim_parsed.dtim_period); + EXPECT_EQ(tim.bitmap_control, tim_parsed.bitmap_control); + EXPECT_EQ(tim.partial_virtual_bitmap, tim_parsed.partial_virtual_bitmap); + EXPECT_EQ(country.country, country_parsed.country); + EXPECT_EQ(country.first_channel, country_parsed.first_channel); + EXPECT_EQ(country.number_channels, country_parsed.number_channels); + EXPECT_EQ(country.max_transmit_power, country_parsed.max_transmit_power); + EXPECT_EQ(dot11.erp_information(), 0); + + PDU::serialization_type serialized = dot11.serialize(); + ASSERT_EQ(sizeof(buffer), serialized.size()); + EXPECT_TRUE(std::equal(serialized.begin(), serialized.end(), buffer)); +} + +TEST_F(Dot11BeaconTest, Serialize) { + Dot11Beacon pdu(expected_packet, sizeof(expected_packet)); + PDU::serialization_type buffer = pdu.serialize(); + ASSERT_EQ(sizeof(expected_packet), buffer.size()); + EXPECT_TRUE(std::equal(buffer.begin(), buffer.end(), expected_packet)); +} diff --git a/tests/src/dot11/block_ack_request.cpp b/tests/src/dot11/block_ack_request.cpp new file mode 100644 index 0000000..7fed3de --- /dev/null +++ b/tests/src/dot11/block_ack_request.cpp @@ -0,0 +1,98 @@ +#include +#include +#include +#include +#include "dot11.h" +#include "tests/dot11.h" + +/* PLZ PLZ I need some BLOCK ACK REQUEST packet dump, + * in order to check the constructor from buffer. + */ + + +using namespace std; +using namespace Tins; + +typedef Dot11::address_type address_type; + +class Dot11BlockAckRequestTest : public testing::Test { +public: + static const address_type empty_addr, hwaddr; + static const uint8_t expected_packet[]; +}; +/*const uint8_t Dot11BlockAckRequestTest::expected_packet[] = { + '\x00', '\x00', ' ', '\x00', 'o', 'H', '\x00', '\x00', 's', 'H', '\xbf', '4', '\x00', '\x00', '\x00', '\x00', '\x10', '\x02', 'l', '\t', '\xdf', '\x00', '\xdc', '\xe0', '\x01', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\xfb', '\x00', '\xcf', '\x01', '\x00', '!', 'k', '\x02', '\xe5', '\x99', '\x00', '\x1c', '\xa0', '\xa8', '\r', 'U', '\x04', '\x00', '\xcf', '!', '\xc7', '\xf3', '\x00', ';' +};*/ + +void test_equals(const Dot11BlockAckRequest &dot1, const Dot11BlockAckRequest &dot2) { + EXPECT_EQ(dot1.fragment_number(), dot2.fragment_number()); + EXPECT_EQ(dot1.start_sequence(), dot2.start_sequence()); + EXPECT_EQ(dot1.bar_control(), dot2.bar_control()); + +} + +void test_equals_expected(const Dot11BlockAckRequest &dot11) { + EXPECT_EQ(dot11.type(), Dot11::CONTROL); + EXPECT_EQ(dot11.subtype(), Dot11::BLOCK_ACK_REQ); + EXPECT_EQ(dot11.fragment_number(), 6); + EXPECT_EQ(dot11.start_sequence(), 0x294); + EXPECT_EQ(dot11.bar_control(), 0x92f); +} + +TEST_F(Dot11BlockAckRequestTest, Constructor) { + Dot11BlockAckRequest dot11; + test_equals_empty(static_cast(dot11)); + EXPECT_EQ(dot11.subtype(), Dot11::BLOCK_ACK_REQ); + EXPECT_EQ(dot11.fragment_number(), 0); + EXPECT_EQ(dot11.start_sequence(), 0); + EXPECT_EQ(dot11.bar_control(), 0); +} + +/*TEST_F(Dot11BlockAckRequestTest, ConstructorFromBuffer) { + Dot11BlockAckRequest dot11(expected_packet, sizeof(expected_packet)); + test_equals_expected(dot11); +}*/ + + +TEST_F(Dot11BlockAckRequestTest, CopyConstructor) { + Dot11BlockAckRequest dot1; + dot1.fragment_number(6); + dot1.start_sequence(0x294); + dot1.bar_control(0x92f); + Dot11BlockAckRequest dot2(dot1); + test_equals(dot1, dot2); +} + +TEST_F(Dot11BlockAckRequestTest, CopyAssignmentOperator) { + Dot11BlockAckRequest dot1; + dot1.fragment_number(6); + dot1.start_sequence(0x294); + dot1.bar_control(0x92f); + Dot11BlockAckRequest dot2; + dot2 = dot1; + test_equals(dot1, dot2); +} + +TEST_F(Dot11BlockAckRequestTest, ClonePDU) { + Dot11BlockAckRequest dot1; + dot1.fragment_number(6); + dot1.start_sequence(0x294); + dot1.bar_control(0x92f); + std::auto_ptr dot2(dot1.clone_pdu()); + test_equals(dot1, *dot2); +} + +/*TEST_F(Dot11BlockAckRequestTest, FromBytes) { + std::auto_ptr dot11(Dot11::from_bytes(expected_packet, sizeof(expected_packet))); + ASSERT_TRUE(dot11.get()); + const Dot11BlockAckRequest *inner = dot11->find_inner_pdu(); + ASSERT_TRUE(inner); + test_equals_expected(*inner); +}*/ + +/*TEST_F(Dot11BlockAckRequestTest, Serialize) { + Dot11BlockAckRequest pdu(expected_packet, sizeof(expected_packet)); + PDU::serialization_type buffer = pdu.serialize(); + ASSERT_EQ(sizeof(expected_packet), buffer.size()); + EXPECT_TRUE(std::equal(buffer.begin(), buffer.end(), expected_packet)); +}*/ diff --git a/tests/src/dot11/cfend.cpp b/tests/src/dot11/cfend.cpp new file mode 100644 index 0000000..e026e76 --- /dev/null +++ b/tests/src/dot11/cfend.cpp @@ -0,0 +1,80 @@ +#include +#include +#include +#include +#include "dot11.h" +#include "tests/dot11.h" + + +using namespace std; +using namespace Tins; + +typedef Dot11::address_type address_type; + +class Dot11CFEndTest : public testing::Test { +public: + static const address_type empty_addr, hwaddr; + static const uint8_t expected_packet[]; +}; + +const uint8_t Dot11CFEndTest::expected_packet[] = { + '\xe5', '\x01', 'O', '#', '\x00', '\x01', '\x02', '\x03', '\x04', + '\x05', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06' +}; + +void test_equals(const Dot11CFEnd &dot1, const Dot11CFEnd &dot2) { + test_equals( + static_cast(dot1), + static_cast(dot2) + ); +} + +void test_equals_expected(const Dot11CFEnd &dot11) { + test_equals_expected(static_cast(dot11)); + EXPECT_EQ(dot11.subtype(), Dot11::CF_END); +} + +TEST_F(Dot11CFEndTest, Constructor) { + Dot11CFEnd dot11; + test_equals_empty(static_cast(dot11)); + EXPECT_EQ(dot11.subtype(), Dot11::CF_END); +} + +TEST_F(Dot11CFEndTest, ConstructorFromBuffer) { + Dot11CFEnd dot11(expected_packet, sizeof(expected_packet)); + test_equals_expected(dot11); +} + +TEST_F(Dot11CFEndTest, CopyConstructor) { + Dot11CFEnd dot1(expected_packet, sizeof(expected_packet)); + Dot11CFEnd dot2(dot1); + test_equals(dot1, dot2); +} + +TEST_F(Dot11CFEndTest, CopyAssignmentOperator) { + Dot11CFEnd dot1(expected_packet, sizeof(expected_packet)); + Dot11CFEnd dot2; + dot2 = dot1; + test_equals(dot1, dot2); +} + +TEST_F(Dot11CFEndTest, ClonePDU) { + Dot11CFEnd dot1(expected_packet, sizeof(expected_packet)); + std::auto_ptr dot2(dot1.clone_pdu()); + test_equals(dot1, *dot2); +} + +TEST_F(Dot11CFEndTest, FromBytes) { + std::auto_ptr dot11(Dot11::from_bytes(expected_packet, sizeof(expected_packet))); + ASSERT_TRUE(dot11.get()); + const Dot11CFEnd *inner = dot11->find_inner_pdu(); + ASSERT_TRUE(inner); + test_equals_expected(*inner); +} + +TEST_F(Dot11CFEndTest, Serialize) { + Dot11CFEnd pdu(expected_packet, sizeof(expected_packet)); + PDU::serialization_type buffer = pdu.serialize(); + ASSERT_EQ(sizeof(expected_packet), buffer.size()); + EXPECT_TRUE(std::equal(buffer.begin(), buffer.end(), expected_packet)); +} diff --git a/tests/src/dot11/cfendack.cpp b/tests/src/dot11/cfendack.cpp new file mode 100644 index 0000000..f6d6fc9 --- /dev/null +++ b/tests/src/dot11/cfendack.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 Dot11EndCFAckTest : public testing::Test { +public: + static const address_type empty_addr, hwaddr; + static const uint8_t expected_packet[]; +}; + +const uint8_t Dot11EndCFAckTest::expected_packet[] = { + '\xf5', '\x01', 'O', '#', '\x00', '\x01', '\x02', '\x03', '\x04', + '\x05', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06' +}; + +void test_equals(const Dot11EndCFAck &dot1, const Dot11EndCFAck &dot2) { + test_equals( + static_cast(dot1), + static_cast(dot2) + ); +} + +void test_equals_expected(const Dot11EndCFAck &dot11) { + test_equals_expected(static_cast(dot11)); + EXPECT_EQ(dot11.subtype(), Dot11::CF_END_ACK); +} + +TEST_F(Dot11EndCFAckTest, Constructor) { + Dot11EndCFAck dot11; + test_equals_empty(static_cast(dot11)); + EXPECT_EQ(dot11.subtype(), Dot11::CF_END_ACK); +} + +TEST_F(Dot11EndCFAckTest, ConstructorFromBuffer) { + Dot11EndCFAck dot11(expected_packet, sizeof(expected_packet)); + test_equals_expected(dot11); +} + +TEST_F(Dot11EndCFAckTest, CopyConstructor) { + Dot11EndCFAck dot1(expected_packet, sizeof(expected_packet)); + Dot11EndCFAck dot2(dot1); + test_equals(dot1, dot2); +} + +TEST_F(Dot11EndCFAckTest, CopyAssignmentOperator) { + Dot11EndCFAck dot1(expected_packet, sizeof(expected_packet)); + Dot11EndCFAck dot2; + dot2 = dot1; + test_equals(dot1, dot2); +} + +TEST_F(Dot11EndCFAckTest, ClonePDU) { + Dot11EndCFAck dot1(expected_packet, sizeof(expected_packet)); + std::auto_ptr dot2(dot1.clone_pdu()); + test_equals(dot1, *dot2); +} + +TEST_F(Dot11EndCFAckTest, FromBytes) { + std::auto_ptr dot11(Dot11::from_bytes(expected_packet, sizeof(expected_packet))); + ASSERT_TRUE(dot11.get()); + const Dot11EndCFAck *inner = dot11->find_inner_pdu(); + ASSERT_TRUE(inner); + test_equals_expected(*inner); +} + +TEST_F(Dot11EndCFAckTest, Serialize) { + Dot11EndCFAck pdu(expected_packet, sizeof(expected_packet)); + PDU::serialization_type buffer = pdu.serialize(); + ASSERT_EQ(sizeof(expected_packet), buffer.size()); + EXPECT_TRUE(std::equal(buffer.begin(), buffer.end(), expected_packet)); +} + diff --git a/tests/src/dot11/data.cpp b/tests/src/dot11/data.cpp index 64768ac..3e576c5 100644 --- a/tests/src/dot11/data.cpp +++ b/tests/src/dot11/data.cpp @@ -20,7 +20,7 @@ public: 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' + '\x03', '\x04', '\x05', '\x06', '\x07', '\xda', '\xf1' }; TEST_F(Dot11DataTest, Constructor) { @@ -61,3 +61,41 @@ TEST_F(Dot11DataTest, FromBytes) { test_equals_expected(*inner); } + +TEST_F(Dot11DataTest, PCAPLoad1) { + const uint8_t buffer[] = { + '\x08', 'B', '\xd4', '\x00', '\x00', '$', '!', '\x92', '\xa7', + 'S', '\x00', '\x1b', '\x11', '\xd2', '\x1b', '\xeb', '\x00', + '\x1b', '\x11', '\xd2', '\x1b', '\xeb', '\x90', 'y', '\xa3', + '_', '\x00', ' ', '\x00', '\x00', '\x00', '\x00', '\xf0', '\xef', + '\xb5', '\xf9', '4', '\xcb', '\x00', ',', 'D', '\xe4', '\xba', + '"', '\xa7', '/', '/', 'G', '\x04', '\xd5', 'o', 'N', '\xeb', + '6', '[', '\xc3', 'D', 't', 'y', '\xec', '\x84', '\xf2', '`', + ' ', 'X', '\x1e', 'p', '\xa2', 'z', '\x02', '\x1a', '7', '\xd2', + '\xf2', '\n', '\x1c', '\xc7', 'z', 'D', '\xc4', '\xc4', '\xbc', + 'G', '_', '\x9f', '\xcf', '\xbc', '\xa2', '\xb7', '\xaf', '\xed', + '\xe0', '\xcc', '\xb9', '\x9e', '\x94', ' ', '\xee', 'F', '\x89', + '1', '\xab', '\xe7', '\xb8', 'I', '\xaf', '\xc3', '\xf4', '\xc5', + '\x95', '\x1c', '\x8d', '\x1a', '\xf8', ':', '\xbd', '\x95', + '\xbf', 'y', '\xce', '\xda', 'x', 's', '@', '\xe0', '>', '\xa1', + 'B', '\x94', '\xd9', '\xb1', '\xa6', '\x17', '\xee', '\xb4', + '\x95', 'E' + }; + Dot11Data dot1(buffer, sizeof(buffer)); + EXPECT_EQ(dot1.addr1(), "00:24:21:92:a7:53"); + EXPECT_EQ(dot1.addr2(), "00:1b:11:d2:1b:eb"); + EXPECT_EQ(dot1.addr3(), "00:1b:11:d2:1b:eb"); + EXPECT_EQ(dot1.wep(), 1); + EXPECT_EQ(dot1.from_ds(), 1); + EXPECT_EQ(dot1.frag_num(), 0); + EXPECT_EQ(dot1.seq_num(), 1945); + std::auto_ptr dot2(dot1.clone_pdu()); + test_equals(dot1, *dot2); +} + +TEST_F(Dot11DataTest, Serialize) { + Dot11Data pdu(expected_packet, sizeof(expected_packet)); + PDU::serialization_type buffer = pdu.serialize(); + ASSERT_EQ(sizeof(expected_packet), buffer.size()); + EXPECT_TRUE(std::equal(buffer.begin(), buffer.end(), expected_packet)); +} diff --git a/tests/src/dot11/deauthentication.cpp b/tests/src/dot11/deauthentication.cpp index 97e92f8..6c58a75 100644 --- a/tests/src/dot11/deauthentication.cpp +++ b/tests/src/dot11/deauthentication.cpp @@ -63,6 +63,12 @@ TEST_F(Dot11DeauthenticationTest, CopyAssignmentOperator) { test_equals(dot1, dot2); } +TEST_F(Dot11DeauthenticationTest, ReasonCode) { + Dot11Deauthentication dot11; + dot11.reason_code(0x92f3); + EXPECT_EQ(dot11.reason_code(), 0x92f3); +} + TEST_F(Dot11DeauthenticationTest, ClonePDU) { Dot11Deauthentication dot1(expected_packet, sizeof(expected_packet)); std::auto_ptr dot2(dot1.clone_pdu()); @@ -77,3 +83,10 @@ TEST_F(Dot11DeauthenticationTest, FromBytes) { test_equals_expected(*inner); } +TEST_F(Dot11DeauthenticationTest, Serialize) { + Dot11Deauthentication pdu(expected_packet, sizeof(expected_packet)); + PDU::serialization_type buffer = pdu.serialize(); + ASSERT_EQ(sizeof(expected_packet), buffer.size()); + EXPECT_TRUE(std::equal(buffer.begin(), buffer.end(), expected_packet)); +} + diff --git a/tests/src/dot11/disassoc.cpp b/tests/src/dot11/disassoc.cpp index 8e026f1..309f1b5 100644 --- a/tests/src/dot11/disassoc.cpp +++ b/tests/src/dot11/disassoc.cpp @@ -63,6 +63,12 @@ TEST_F(Dot11DisassocTest, CopyAssignmentOperator) { test_equals(dot1, dot2); } +TEST_F(Dot11DisassocTest, ReasonCode) { + Dot11Disassoc dot11; + dot11.reason_code(0x92f3); + EXPECT_EQ(dot11.reason_code(), 0x92f3); +} + TEST_F(Dot11DisassocTest, ClonePDU) { Dot11Disassoc dot1(expected_packet, sizeof(expected_packet)); std::auto_ptr dot2(dot1.clone_pdu()); @@ -76,3 +82,10 @@ TEST_F(Dot11DisassocTest, FromBytes) { ASSERT_TRUE(inner); test_equals_expected(*inner); } + +TEST_F(Dot11DisassocTest, Serialize) { + Dot11Disassoc pdu(expected_packet, sizeof(expected_packet)); + PDU::serialization_type buffer = pdu.serialize(); + ASSERT_EQ(sizeof(expected_packet), buffer.size()); + EXPECT_TRUE(std::equal(buffer.begin(), buffer.end(), expected_packet)); +} diff --git a/tests/src/dot11/dot11.cpp b/tests/src/dot11/dot11.cpp index 5b5a617..7cf8c25 100644 --- a/tests/src/dot11/dot11.cpp +++ b/tests/src/dot11/dot11.cpp @@ -159,5 +159,11 @@ TEST_F(Dot11Test, AddTaggedOption) { EXPECT_TRUE(std::equal(hwaddr.begin(), hwaddr.end(), option->data_ptr())); } +TEST_F(Dot11Test, Serialize) { + Dot11 pdu(expected_packet, sizeof(expected_packet)); + PDU::serialization_type buffer = pdu.serialize(); + ASSERT_EQ(sizeof(expected_packet), buffer.size()); + EXPECT_TRUE(std::equal(buffer.begin(), buffer.end(), expected_packet)); +} diff --git a/tests/src/dot11/probe_response.cpp b/tests/src/dot11/probe_response.cpp index 79954dd..759c412 100644 --- a/tests/src/dot11/probe_response.cpp +++ b/tests/src/dot11/probe_response.cpp @@ -67,6 +67,18 @@ TEST_F(Dot11ProbeResponseTest, CopyAssignmentOperator) { test_equals(dot1, dot2); } +TEST_F(Dot11ProbeResponseTest, Interval) { + Dot11ProbeResponse dot11; + dot11.interval(0x92af); + EXPECT_EQ(dot11.interval(), 0x92af); +} + +TEST_F(Dot11ProbeResponseTest, Timestamp) { + Dot11ProbeResponse dot11; + dot11.timestamp(0x92af8a72df928a7c); + EXPECT_EQ(dot11.timestamp(), 0x92af8a72df928a7c); +} + TEST_F(Dot11ProbeResponseTest, ClonePDU) { Dot11ProbeResponse dot1(expected_packet, sizeof(expected_packet)); std::auto_ptr dot2(dot1.clone_pdu()); @@ -81,3 +93,9 @@ TEST_F(Dot11ProbeResponseTest, FromBytes) { test_equals_expected(*inner); } +TEST_F(Dot11ProbeResponseTest, Serialize) { + Dot11ProbeResponse pdu(expected_packet, sizeof(expected_packet)); + PDU::serialization_type buffer = pdu.serialize(); + ASSERT_EQ(sizeof(expected_packet), buffer.size()); + EXPECT_TRUE(std::equal(buffer.begin(), buffer.end(), expected_packet)); +} diff --git a/tests/src/dot11/pspoll.cpp b/tests/src/dot11/pspoll.cpp new file mode 100644 index 0000000..adc534b --- /dev/null +++ b/tests/src/dot11/pspoll.cpp @@ -0,0 +1,80 @@ +#include +#include +#include +#include +#include "dot11.h" +#include "tests/dot11.h" + + +using namespace std; +using namespace Tins; + +typedef Dot11::address_type address_type; + +class Dot11PSPollTest : public testing::Test { +public: + static const address_type empty_addr, hwaddr; + static const uint8_t expected_packet[]; +}; + +const uint8_t Dot11PSPollTest::expected_packet[] = { + '\xa5', '\x01', 'O', '#', '\x00', '\x01', '\x02', '\x03', '\x04', + '\x05', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06' +}; + +void test_equals(const Dot11PSPoll &dot1, const Dot11PSPoll &dot2) { + test_equals( + static_cast(dot1), + static_cast(dot2) + ); +} + +void test_equals_expected(const Dot11PSPoll &dot11) { + test_equals_expected(static_cast(dot11)); + EXPECT_EQ(dot11.subtype(), Dot11::PS); +} + +TEST_F(Dot11PSPollTest, Constructor) { + Dot11PSPoll dot11; + test_equals_empty(static_cast(dot11)); + EXPECT_EQ(dot11.subtype(), Dot11::PS); +} + +TEST_F(Dot11PSPollTest, ConstructorFromBuffer) { + Dot11PSPoll dot11(expected_packet, sizeof(expected_packet)); + test_equals_expected(dot11); +} + +TEST_F(Dot11PSPollTest, CopyConstructor) { + Dot11PSPoll dot1(expected_packet, sizeof(expected_packet)); + Dot11PSPoll dot2(dot1); + test_equals(dot1, dot2); +} + +TEST_F(Dot11PSPollTest, CopyAssignmentOperator) { + Dot11PSPoll dot1(expected_packet, sizeof(expected_packet)); + Dot11PSPoll dot2; + dot2 = dot1; + test_equals(dot1, dot2); +} + +TEST_F(Dot11PSPollTest, ClonePDU) { + Dot11PSPoll dot1(expected_packet, sizeof(expected_packet)); + std::auto_ptr dot2(dot1.clone_pdu()); + test_equals(dot1, *dot2); +} + +TEST_F(Dot11PSPollTest, FromBytes) { + std::auto_ptr dot11(Dot11::from_bytes(expected_packet, sizeof(expected_packet))); + ASSERT_TRUE(dot11.get()); + const Dot11PSPoll *inner = dot11->find_inner_pdu(); + ASSERT_TRUE(inner); + test_equals_expected(*inner); +} + +TEST_F(Dot11PSPollTest, Serialize) { + Dot11PSPoll pdu(expected_packet, sizeof(expected_packet)); + PDU::serialization_type buffer = pdu.serialize(); + ASSERT_EQ(sizeof(expected_packet), buffer.size()); + EXPECT_TRUE(std::equal(buffer.begin(), buffer.end(), expected_packet)); +} diff --git a/tests/src/dot11/reassoc_request.cpp b/tests/src/dot11/reassoc_request.cpp index 0b2f24f..f8e693f 100644 --- a/tests/src/dot11/reassoc_request.cpp +++ b/tests/src/dot11/reassoc_request.cpp @@ -66,6 +66,18 @@ TEST_F(Dot11ReAssocRequestTest, CopyAssignmentOperator) { test_equals(dot1, dot2); } +TEST_F(Dot11ReAssocRequestTest, ListenInterval) { + Dot11ReAssocRequest dot11; + dot11.listen_interval(0x92fd); + EXPECT_EQ(dot11.listen_interval(), 0x92fd); +} + +TEST_F(Dot11ReAssocRequestTest, CurrentAP) { + Dot11ReAssocRequest dot11; + dot11.current_ap("00:01:02:03:04:05"); + EXPECT_EQ(dot11.current_ap(), "00:01:02:03:04:05"); +} + TEST_F(Dot11ReAssocRequestTest, ClonePDU) { Dot11ReAssocRequest dot1(expected_packet, sizeof(expected_packet)); std::auto_ptr dot2(dot1.clone_pdu()); @@ -80,3 +92,9 @@ TEST_F(Dot11ReAssocRequestTest, FromBytes) { test_equals_expected(*inner); } +TEST_F(Dot11ReAssocRequestTest, Serialize) { + Dot11ReAssocRequest pdu(expected_packet, sizeof(expected_packet)); + PDU::serialization_type buffer = pdu.serialize(); + ASSERT_EQ(sizeof(expected_packet), buffer.size()); + EXPECT_TRUE(std::equal(buffer.begin(), buffer.end(), expected_packet)); +} diff --git a/tests/src/dot11/reassoc_response.cpp b/tests/src/dot11/reassoc_response.cpp index 1ab4b6f..2ea73b9 100644 --- a/tests/src/dot11/reassoc_response.cpp +++ b/tests/src/dot11/reassoc_response.cpp @@ -81,3 +81,10 @@ TEST_F(Dot11ReAssocResponseTest, FromBytes) { test_equals_expected(*inner); } +TEST_F(Dot11ReAssocResponseTest, Serialize) { + Dot11ReAssocResponse pdu(expected_packet, sizeof(expected_packet)); + PDU::serialization_type buffer = pdu.serialize(); + ASSERT_EQ(sizeof(expected_packet), buffer.size()); + EXPECT_TRUE(std::equal(buffer.begin(), buffer.end(), expected_packet)); +} + diff --git a/tests/src/dot11/rts.cpp b/tests/src/dot11/rts.cpp new file mode 100644 index 0000000..91f6994 --- /dev/null +++ b/tests/src/dot11/rts.cpp @@ -0,0 +1,80 @@ +#include +#include +#include +#include +#include "dot11.h" +#include "tests/dot11.h" + + +using namespace std; +using namespace Tins; + +typedef Dot11::address_type address_type; + +class Dot11RTSTest : public testing::Test { +public: + static const address_type empty_addr, hwaddr; + static const uint8_t expected_packet[]; +}; + +const uint8_t Dot11RTSTest::expected_packet[] = { + '\xb5', '\x01', 'O', '#', '\x00', '\x01', '\x02', '\x03', '\x04', + '\x05', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06' +}; + +void test_equals(const Dot11RTS &dot1, const Dot11RTS &dot2) { + test_equals( + static_cast(dot1), + static_cast(dot2) + ); +} + +void test_equals_expected(const Dot11RTS &dot11) { + test_equals_expected(static_cast(dot11)); + EXPECT_EQ(dot11.subtype(), Dot11::RTS); +} + +TEST_F(Dot11RTSTest, Constructor) { + Dot11RTS dot11; + test_equals_empty(static_cast(dot11)); + EXPECT_EQ(dot11.subtype(), Dot11::RTS); +} + +TEST_F(Dot11RTSTest, ConstructorFromBuffer) { + Dot11RTS dot11(expected_packet, sizeof(expected_packet)); + test_equals_expected(dot11); +} + +TEST_F(Dot11RTSTest, CopyConstructor) { + Dot11RTS dot1(expected_packet, sizeof(expected_packet)); + Dot11RTS dot2(dot1); + test_equals(dot1, dot2); +} + +TEST_F(Dot11RTSTest, CopyAssignmentOperator) { + Dot11RTS dot1(expected_packet, sizeof(expected_packet)); + Dot11RTS dot2; + dot2 = dot1; + test_equals(dot1, dot2); +} + +TEST_F(Dot11RTSTest, ClonePDU) { + Dot11RTS dot1(expected_packet, sizeof(expected_packet)); + std::auto_ptr dot2(dot1.clone_pdu()); + test_equals(dot1, *dot2); +} + +TEST_F(Dot11RTSTest, FromBytes) { + std::auto_ptr dot11(Dot11::from_bytes(expected_packet, sizeof(expected_packet))); + ASSERT_TRUE(dot11.get()); + const Dot11RTS *inner = dot11->find_inner_pdu(); + ASSERT_TRUE(inner); + test_equals_expected(*inner); +} + +TEST_F(Dot11RTSTest, Serialize) { + Dot11RTS pdu(expected_packet, sizeof(expected_packet)); + PDU::serialization_type buffer = pdu.serialize(); + ASSERT_EQ(sizeof(expected_packet), buffer.size()); + EXPECT_TRUE(std::equal(buffer.begin(), buffer.end(), expected_packet)); +}