From 75c5dfdc68998e98bad319bde7964759c88d44e2 Mon Sep 17 00:00:00 2001 From: Santiago Alessandri Date: Mon, 22 Aug 2011 13:17:11 -0300 Subject: [PATCH] Added Management and Beacon subclasses --- include/ieee802-11.h | 76 +++++++++++++++++++++++++++++++++++++++++++- src/ieee802-11.cpp | 20 ++++++++++++ 2 files changed, 95 insertions(+), 1 deletion(-) diff --git a/include/ieee802-11.h b/include/ieee802-11.h index e7b3988..b263766 100644 --- a/include/ieee802-11.h +++ b/include/ieee802-11.h @@ -103,7 +103,7 @@ namespace Tins { * \param child PDU* with the PDU contained by the 802.11 PDU (optional). */ IEEE802_11(const uint8_t* dst_hw_addr = 0, const uint8_t* src_hw_addr = 0, PDU* child = 0); - + /** * \brief Constructor for creating a 802.11 PDU * @@ -472,6 +472,80 @@ namespace Tins { uint32_t _iface_index; }; + + /** + * \brief Abstract class that englobes all Management frames in the 802.11 protocol. + */ + class ManagementFrame : public IEEE802_11 { + + public: + + protected: + + ManagementFrame(); + + struct CapabilityInformation { + unsigned int ess:1; + unsigned int ibss:1; + unsigned int cf_poll:1; + unsigned int cf_poll_req:1; + unsigned int privacy:1; + unsigned int short_preamble:1; + unsigned int pbcc:1; + unsigned int chanel_agility:1; + unsigned int spectrum_mgmt:1; + unsigned int qos:1; + unsigned int sst:1; + unsigned int apsd:1; + unsigned int reserved:1; + unsigned int dsss_ofdm:1; + unsigned int delayed_block_ack:1; + unsigned int immediate_block_ack:1; + } __attribute__((__packed__)); + + private: + + + }; + + /** + * \brief Class representing a Beacon in the IEEE 802.11 Protocol. + * + */ + class IEEE802_11_Beacon : public ManagementFrame { + + public: + + /** + * \brief Default constructor for the beacon frame. + * + */ + IEEE802_11_Beacon(); + + /** + * \brief Returns the frame's header length. + * + * \return An uint32_t with the header's size. + * \sa PDU::header_size() + */ + uint32_t header_size() const; + + private: + + struct BeaconBody { + uint64_t timestamp; + uint16_t interval; + CapabilityInformation capability; + } __attribute__((__packed__)); + + BeaconBody _body; + + uint32_t write_fixed_parameters(uint8_t *buffer, uint32_t total_sz); + + }; + + + } #endif diff --git a/src/ieee802-11.cpp b/src/ieee802-11.cpp index 204cecc..31355b8 100644 --- a/src/ieee802-11.cpp +++ b/src/ieee802-11.cpp @@ -178,3 +178,23 @@ void Tins::IEEE802_11::write_serialization(uint8_t *buffer, uint32_t total_sz, c Tins::IEEE802_11::IEEE802_11(const ieee80211_header *header_ptr) : PDU(ETHERTYPE_IP) { } + +Tins::ManagementFrame::ManagementFrame() : IEEE802_11() { + this->type(IEEE802_11::MANAGEMENT); +} + +Tins::IEEE802_11_Beacon::IEEE802_11_Beacon() : ManagementFrame() { + this->subtype(IEEE802_11::BEACON); +} + +uint32_t Tins::IEEE802_11_Beacon::header_size() const { + return IEEE802_11::header_size() + sizeof(BeaconBody); +} + +uint32_t Tins::IEEE802_11_Beacon::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) { + uint32_t sz = sizeof(BeaconBody); + assert(sz <= total_sz); + memcpy(buffer, &this->_body, sz); + return sz; +} +