diff --git a/include/dot11.h b/include/dot11.h index dd98471..755d94a 100644 --- a/include/dot11.h +++ b/include/dot11.h @@ -23,6 +23,7 @@ #define TINS_DOT_11 #include +#include #include #include #include @@ -75,7 +76,7 @@ namespace Tins { COUNTRY, HOPPING_PATTERN_PARAMS, HOPPING_PATTERN_TABLE, - REQUEST, + REQUEST_INFORMATION, BSS_LOAD, EDCA, TSPEC, @@ -174,39 +175,22 @@ namespace Tins { /** * \brief Getter for Dot11 options' data pointer. */ - const uint8_t* data_ptr() const { return value; } + const uint8_t* data_ptr() const { return &value[0]; } /** * \brief Getter for the data size field */ - uint8_t data_size() const { return length; } + uint8_t data_size() const { return value.size(); } /** - * \brief The option number. + * \brief Getter for the data size field */ - uint8_t option; - private: - /** - * \brief The value's length in bytes. - */ - uint8_t length; - /** - * \brief The option's value. - */ - uint8_t *value; + uint8_t option() const { return option_id; } + private: + uint8_t option_id; + std::vector value; }; - - /** - * \brief Constructor for creating a 802.11 PDU - * - * Constructor that builds a 802.11 PDU taking the destination's and source's MAC. - * - * \param dst_hw_addr uint8_t array of 6 bytes containing the destination's MAC(optional). - * \param child PDU* with the PDU contained by the 802.11 PDU (optional). - */ - Dot11(const address_type &dst_hw_addr = address_type(), - PDU* child = 0); - + /** * \brief Constructor for creating an 802.11 PDU * @@ -217,7 +201,7 @@ namespace Tins { * \param dst_hw_addr uint8_t array of 6 bytes containing the destination's MAC(optional). * \param child PDU* with the PDU contained by the 802.11 PDU (optional). */ - Dot11(const NetworkInterface &iface, + Dot11(const NetworkInterface &iface = NetworkInterface(), const address_type &dst_hw_addr = address_type(), PDU* child = 0); @@ -229,18 +213,6 @@ namespace Tins { */ Dot11(const uint8_t *buffer, uint32_t total_sz); - /** - * \brief Copy constructor. - */ - Dot11(const Dot11 &other); - - /** - * \brief Dot11 destructor. - * - * Releases the memory allocated for tagged options. - */ - ~Dot11(); - /** * \brief Copy assignment operator. */ @@ -321,7 +293,7 @@ namespace Tins { * * \return The value of the duration/id field in an uint16_t. */ - uint16_t duration_id() const { return this->_header.duration_id; } + uint16_t duration_id() const { return Utils::le_to_host(this->_header.duration_id); } /** * \brief Getter for the first address. @@ -492,7 +464,7 @@ namespace Tins { */ struct ieee80211_header { struct { - #if __BYTE_ORDER == __LITTLE_ENDIAN + #if TINS_IS_LITTLE_ENDIAN unsigned int protocol:2; unsigned int type:2; unsigned int subtype:4; @@ -504,18 +476,18 @@ namespace Tins { unsigned int more_data:1; unsigned int wep:1; unsigned int order:1; - #elif __BYTE_ORDER == __BIG_ENDIAN - unsigned int protocol:2; - unsigned int type:2; + #elif TINS_IS_BIG_ENDIAN unsigned int subtype:4; - unsigned int to_ds:1; - unsigned int from_ds:1; - unsigned int more_frag:1; - unsigned int retry:1; - unsigned int power_mgmt:1; - unsigned int more_data:1; - unsigned int wep:1; + unsigned int type:2; + unsigned int protocol:2; unsigned int order:1; + unsigned int wep:1; + unsigned int more_data:1; + unsigned int power_mgmt:1; + unsigned int retry:1; + unsigned int more_frag:1; + unsigned int from_ds:1; + unsigned int to_ds:1; #endif } __attribute__((__packed__)) control; uint16_t duration_id; @@ -649,7 +621,22 @@ namespace Tins { class Dot11ManagementFrame : public Dot11 { public: /** - * \brief This PDU's flag. + * The supported rates container type. + */ + typedef std::vector rates_type; + + /** + * The supported channels container type. + */ + typedef std::vector > channels_type; + + /** + * The requested information container type. + */ + typedef std::vector request_info_type; + + /** + * This PDU's flag. */ static const PDU::PDUType pdu_flag = PDU::DOT11_MANAGEMENT; @@ -688,24 +675,44 @@ namespace Tins { PEER_STA_NOT_SUPPORT_CIPHER = 45 }; - 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 _channel_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; - + class CapabilityInformation { + private: + #if TINS_IS_LITTLE_ENDIAN + uint16_t _ess:1, + _ibss:1, + _cf_poll:1, + _cf_poll_req:1, + _privacy:1, + _short_preamble:1, + _pbcc:1, + _channel_agility:1, + _spectrum_mgmt:1, + _qos:1, + _sst:1, + _apsd:1, + _reserved:1, + _dsss_ofdm:1, + _delayed_block_ack:1, + _immediate_block_ack:1; + #elif TINS_IS_BIG_ENDIAN + uint16_t _channel_agility:1, + _pbcc:1, + _short_preamble:1, + _privacy:1, + _cf_poll_req:1, + _cf_poll:1, + _ibss:1, + _ess:1, + _immediate_block_ack:1, + _delayed_block_ack:1, + _dsss_ofdm:1, + _reserved:1, + _apsd:1, + _sst:1, + _qos:1, + _spectrum_mgmt:1; + #endif + public: /** * \brief Getter for the ess flag. * @@ -1002,58 +1009,8 @@ namespace Tins { */ void addr4(const address_type &new_addr4); - /** - * \brief Returns the 802.11 frame's header length. - * - * \return An uint32_t with the header's size. - * \sa PDU::header_size() - */ - uint32_t header_size() const; - - /** - * \brief Getter for the PDU's type. - * - * \sa PDU::pdu_type - */ - PDUType pdu_type() const { return PDU::DOT11_MANAGEMENT; } - - /** - * \brief Check wether this PDU matches the specified flag. - * \param flag The flag to match - * \sa PDU::matches_flag - */ - bool matches_flag(PDUType flag) { - return flag == PDU::DOT11_MANAGEMENT || Dot11::matches_flag(flag); - } - protected: - struct ExtendedHeader { - uint8_t addr2[6]; - uint8_t addr3[6]; - struct { - #if __BYTE_ORDER == __LITTLE_ENDIAN - unsigned int frag_number:4; - unsigned int seq_number:12; - #elif __BYTE_ORDER == __BIG_ENDIAN - unsigned int seq_number:12; - unsigned int frag_number:4; - #endif - } __attribute__((__packed__)) seq_control; - } __attribute__((__packed__)); - - /** - * \brief Constructor which creates a Dot11ManagementFrame object from a buffer and adds all identifiable - * PDUs found in the buffer as children of this one. - * \param buffer The buffer from which this PDU will be constructed. - * \param total_sz The total size of the buffer. - */ - Dot11ManagementFrame(const address_type &dst_hw_addr = address_type(), - const address_type &src_hw_addr = address_type()); - Dot11ManagementFrame(const NetworkInterface &iface, - const address_type &dst_hw_addr = address_type(), - const address_type &src_hw_addr = address_type()); - Dot11ManagementFrame(const uint8_t *buffer, uint32_t total_sz); - Dot11ManagementFrame(const Dot11ManagementFrame& other); - + // Option setter helpers + /** * \brief Helper method to set the ssid. * @@ -1071,23 +1028,23 @@ namespace Tins { /** * \brief Helper method to set the supported rates. * - * \param new_rates A list of rates to be set. + * \param new_rates The new rates to be set. */ - void supported_rates(const std::list &new_rates); + void supported_rates(const rates_type &new_rates); /** * \brief Helper method to set the extended supported rates. * - * \param new_rates A list of rates to be set. + * \param new_rates The new rates to be set. */ - void extended_supported_rates(const std::list &new_rates); + void extended_supported_rates(const rates_type &new_rates); /** * \brief Helper method to set the QoS capabilities. * * \param new_qos_capabilities uint8_t with the capabilities. */ - void qos_capabilities(uint8_t new_qos_capabilities); + void qos_capability(uint8_t new_qos_capability); /** * \brief Helper method to set the power capabilities. @@ -1095,14 +1052,14 @@ namespace Tins { * \param min_power uint8_t indicating the minimum transmiting power capability. * \param max_power uint8_t indicating the maximum transmiting power capability. */ - void power_capabilities(uint8_t min_power, uint8_t max_power); + void power_capability(uint8_t min_power, uint8_t max_power); /** * \brief Helper method to set the supported channels. * * \param new_channels A list of channels to be set. */ - void supported_channels(const std::list > &new_channels); + void supported_channels(const channels_type &new_channels); /** * \brief Helper method to set the EDCA Parameter Set. @@ -1119,7 +1076,7 @@ namespace Tins { * * \param elements A list of elements. */ - void request_information(const std::list elements); + void request_information(const request_info_type elements); /** * \brief Helper method to set the FH parameter. @@ -1261,15 +1218,147 @@ namespace Tins { * \brief ch_text_sz uint8_t with the ch_text's length. */ void challenge_text(uint8_t* ch_text, uint8_t ch_text_sz); + + // Option searching helpers + + /** + * \brief Helper method to search for the RSN information of this PDU. + * + * This method fills the RSN information structure of this PDU. + * \param rsn A pointer in which the RSN information will be stored. + * \return True if the RSNInformation option has been set. + */ + bool rsn_information(RSNInformation *rsn); + + /** + * \brief Helper method to search for this PDU's ssid. + * + * Throws a std::runtime_error if the option has not been set. + * + * \return std::string containing the ssid. + */ + std::string ssid() const; + + /** + * \brief Helper method to get the supported rates. + * + * Throws a std::runtime_error if the option has not been set. + * + * \return rates_type containing the supported rates. + */ + rates_type supported_rates() const; + + /** + * \brief Helper method to get the extended supported rates. + * + * Throws a std::runtime_error if the option has not been set. + * + * \return rates_type containing the extended supported rates. + */ + rates_type extended_supported_rates() const; + + /** + * \brief Helper method to get the QOS capability. + * + * Throws a std::runtime_error if the option has not been set. + * + * \return uint8_t containing the QOS capability. + */ + uint8_t qos_capability() const; + + /** + * \brief Helper method to get the power capability. + * + * Throws a std::runtime_error if the option has not been set. + * + * \return std::pair containing the power capability. + */ + std::pair power_capability() const; + + /** + * \brief Helper method to get the supported channels. + * + * Throws a std::runtime_error if the option has not been set. + * + * \return channels_type containing the power capability. + */ + channels_type supported_channels() const; + + /** + * \brief Helper method to get the request information. + * + * Throws a std::runtime_error if the option has not been set. + * + * \return request_info_type containing the request information. + */ + request_info_type request_information() const; + + // ************************ + + /** + * \brief Returns the 802.11 frame's header length. + * + * \return An uint32_t with the header's size. + * \sa PDU::header_size() + */ + uint32_t header_size() const; + + /** + * \brief Getter for the PDU's type. + * + * \sa PDU::pdu_type + */ + PDUType pdu_type() const { return PDU::DOT11_MANAGEMENT; } + + /** + * \brief Check wether this PDU matches the specified flag. + * \param flag The flag to match + * \sa PDU::matches_flag + */ + bool matches_flag(PDUType flag) { + return flag == PDU::DOT11_MANAGEMENT || Dot11::matches_flag(flag); + } + protected: + struct ExtendedHeader { + uint8_t addr2[address_type::address_size]; + uint8_t addr3[address_type::address_size]; + struct { + #if __BYTE_ORDER == __LITTLE_ENDIAN + unsigned int frag_number:4; + unsigned int seq_number:12; + #elif __BYTE_ORDER == __BIG_ENDIAN + unsigned int seq_number:12; + unsigned int frag_number:4; + #endif + } __attribute__((__packed__)) seq_control; + } __attribute__((__packed__)); + + + Dot11ManagementFrame(const NetworkInterface &iface = NetworkInterface(), + const address_type &dst_hw_addr = address_type(), + const address_type &src_hw_addr = address_type()); + + /** + * \brief Constructor which creates a Dot11ManagementFrame object from a buffer and adds all identifiable + * PDUs found in the buffer as children of this one. + * + * \param buffer The buffer from which this PDU will be constructed. + * \param total_sz The total size of the buffer. + */ + Dot11ManagementFrame(const uint8_t *buffer, uint32_t total_sz); uint32_t write_ext_header(uint8_t *buffer, uint32_t total_sz); void copy_ext_header(const Dot11ManagementFrame *other); uint32_t management_frame_size() { - return sizeof(_ext_header) + (from_ds() && to_ds()) ? address_type::address_size : 0; + return sizeof(ieee80211_header) + sizeof(_ext_header) + + ((from_ds() && to_ds()) ? address_type::address_size : 0); } private: + static uint8_t *serialize_rates(const rates_type &rates); + static rates_type deserialize_rates(const Dot11Option *option); + ExtendedHeader _ext_header; address_type _addr4; }; @@ -1285,14 +1374,6 @@ namespace Tins { */ static const PDU::PDUType pdu_flag = PDU::DOT11_BEACON; - /** - * \brief Default constructor for the beacon frame. - * \param dst_hw_addr uint8_t array of 6 bytes containing the destination's MAC(optional). - * \param src_hw_addr uint8_t array of 6 bytes containing the source's MAC(optional). - */ - Dot11Beacon(const address_type &dst_hw_addr = address_type(), - const address_type &src_hw_addr = address_type()); - /** * \brief Constructor for creating a 802.11 Beacon. * @@ -1303,7 +1384,7 @@ namespace Tins { * \param dst_hw_addr uint8_t array of 6 bytes containing the destination's MAC(optional). * \param src_hw_addr uint8_t array of 6 bytes containing the source's MAC(optional). */ - Dot11Beacon(const NetworkInterface& iface, + Dot11Beacon(const NetworkInterface& iface = NetworkInterface(), const address_type &dst_hw_addr = address_type(), const address_type &src_hw_addr = address_type()); @@ -1321,28 +1402,28 @@ namespace Tins { * * \return Timestamp value in an uint64_t. */ - uint64_t timestamp() const { return this->_body.timestamp; } + uint64_t timestamp() const { return Utils::le_to_host(this->_body.timestamp); } /** * \brief Getter for the interval field. * * \return Timestamp value in an uint16_t. */ - uint16_t interval() const { return this->_body.interval; } + uint16_t interval() const { return Utils::le_to_host(this->_body.interval); } + + /** + * \brief Getter for the Capabilities Information structure. + * + * \return const CapabilityInformation&. + */ + const CapabilityInformation& capabilities() const { return this->_body.capability; } /** * \brief Getter for the Capabilities Information. * - * \return CapabilityInformation Structure in a CapabilityInformation&. + * \return CapabilityInformation&. */ - const CapabilityInformation& capabilities() const { return this->_body.capability;} - - /** - * \brief Getter for the Capabilities Information. - * - * \return CapabilityInformation Structure in a CapabilityInformation&. - */ - CapabilityInformation& capabilities() { return this->_body.capability;} + CapabilityInformation& capabilities() { return this->_body.capability; } /** * \brief Setter for the timestamp field. @@ -1358,199 +1439,6 @@ namespace Tins { */ void interval(uint16_t new_interval); - /** - * \brief Helper method to set the essid. - * \param new_essid The essid to be set. - */ - void essid(const std::string &new_essid); - - /** - * \brief Helper method to set the supported rates. - * \param new_rates A list of rates to be set. - */ - void supported_rates(const std::list &new_rates); - - /** - * \brief Helper method to set the FH parameter. - * - * \param dwell_time uint16_t with the dwell_time value. - * \param hop_set uint8_t with the value of the set_hop. - * \param hop_pattern uint8_t with the value of the hop_pattern field. - * \param hop_index uint8_t with the value of the hop_index field. - */ - void fh_parameter_set(uint16_t dwell_time, uint8_t hop_set, uint8_t hop_pattern, uint8_t hop_index); - - /** - * \brief Helper method to set the DS parameter. - * - * \param current_channel uint8_t with the value of the current_channel field. - */ - void ds_parameter_set(uint8_t current_channel); - - /** - * \brief Helper method to set the CF parameter. - * - * \param cfp_count uint8_t with the value of the cfp count field. - * \param cfp_period uint8_t with the value of the cfp period field. - * \param cfp_max_duration uint16_t with the value of the cfp max duration field. - * \param cfp_dur_remaining uint16_t with the value of the DurRemaining field. - */ - void cf_parameter_set(uint8_t cfp_count, uint8_t cfp_period, uint16_t cfp_max_duration, uint16_t cfp_dur_remaining); - - /** - * \brief Helper method to set the IBSS parameter. - * - * \param atim_window uint16_t with the value of the ATIM window field. - */ - void ibss_parameter_set(uint16_t atim_window); - - /** - * \brief Helper method to set the TIM tagged option. - * - * \brief dtim_count uint8_t with the value of the DTIM count field. - * \brief dtim_period uint8_t with the value of the DTIM period field. - * \brief bitmap_control uint8_t with the value of the Bitmap Control field. - * \brief partial_virtual_bitmap uint8_t array with the value fo the Partial Virtual Bitmap field. - * \brief partial_virtual_bitmap_sz uint8_t with the size of the partial_virtual_bitmap array. - */ - void tim(uint8_t dtim_count, uint8_t dtim_period, uint8_t bitmap_control, uint8_t* partial_virtual_bitmap, uint8_t partial_virtual_bitmap_sz); - - /** - * \brief Helper method to set the country tagged option. - * - * \param countries Reference to a vector of uint8_t arrays of 3 bytes. Containing the list of countries. - * \param first_channels Reference to a vector of uint8_t. Containing the first channels for each country. - * \param num_channels Reference to a vector of uint8_t. Containing the number of channels for each country. - * \param max_power Reference to a vector of uint8_t. Containing the max power for each country. - */ - void country(const std::vector& countries, const std::vector& first_channels, const std::vector& number_channels, const std::vector& max_power); - - /** - * \brief Helper method to set the FH parameters. - * - * \param prime_radix uint8_t with the value of the prime radix field. - * \param number_channels uint8_t with the value of the number channels field. - */ - void fh_parameters(uint8_t prime_radix, uint8_t number_channels); - - /** - * \brief Helper method to set the FH pattern table. - * - * \param flag uint8_t with the value of the flag field. - * \param number_of_sets uint8_t with the value of the number of sets field. - * \param modulus uint8_t with the value of the modulus field. - * \param offset uint8_t with the value of the offset field. - * \param random_table reference to vector of uint8_t witht the elements of the table. - */ - void fh_pattern_table(uint8_t flag, uint8_t number_of_sets, uint8_t modulus, uint8_t offset, const std::vector& random_table); - - /** - * \brief Helper method to set the Power Constraint tagged option. - * - * \param local_power_constraint uint8_t with the value of the local power constraint field. - */ - void power_constraint(uint8_t local_power_constraint); - - /** - * \brief Helper method to set the Channel Switch tagged option. - * - * \param switch_mode uint8_t with the value of the switch mode field. - * \param new_channel uint8_t with the value of the new channel field. - * \param switch_count uint8_t with the value of the switch count field. - */ - void channel_switch(uint8_t switch_mode, uint8_t new_channel, uint8_t switch_count); - - /** - * \brief Helper method to set the Quiet tagged option. - * - * \param quiet_count uint8_t with the value of the quiet count field. - * \param quiet_period uint8_t with the value of the quiet period field. - * \param quiet_duration uint16_t with the value of the quiet duration field. - * \param quiet_offset uint16_t with the value of the quiet offset field. - */ - void quiet(uint8_t quiet_count, uint8_t quiet_period, uint16_t quiet_duration, uint16_t quiet_offset); - - /** - * \brief Helper method to set the IBSS DFS tagged option. - * - * \param dfs_owner uint8_t array of 6 bytes with the dfs owner. - * \param recovery_interval uint8_t with the value of the recovery interval field. - * \param channel_map Reference to a constant vector of pair of uint8_t with the map of channels. - */ - void ibss_dfs(const uint8_t* dfs_owner, uint8_t recovery_interval, const std::vector >& channel_map); - - /** - * \brief Helper method to set the TPC Report tagged option. - * - * \param transmit_power uint8_t with the value of the transmit power field. - * \param link_margin uint8_t with the value of the link margin field. - */ - void tpc_report(uint8_t transmit_power, uint8_t link_margin); - - /** - * \brief Helper method to set the ERP Information tagged option. - * - * \param value with the value to set as argument of the tagged option. - */ - void erp_information(uint8_t value); - - /** - * \brief Helper method to set the extended supported rates. - * - * \param new_rates A list of rates to be set. - */ - void extended_supported_rates(const std::list &new_rates); - - /** - * \brief Helper method to set the RSN information option. - * - * \param info The RSNInformation structure to be set. - */ - void rsn_information(const RSNInformation& info); - - /** - * \brief Helper method to set the BSS Load tagged option. - * - * \param station_count uint16_t with the value of the station count field. - * \param channel_utilization uint8_t with the value of the channel utilization field. - * \param available_capacity uint16_t with the value of the available capacity field. - */ - void bss_load(uint16_t station_count, uint8_t channel_utilization, uint16_t avaliable_capacity); - - /** - * \brief Helper method to set the EDCA Parameter Set. - * - * \param ac_be uint32_t with the value of the ac_be field. - * \param ac_bk uint32_t with the value of the ac_bk field. - * \param ac_vi uint32_t with the value of the ac_vi field. - * \param ac_vo uint32_t with the value of the ac_vo field. - */ - void edca_parameter_set(uint32_t ac_be, uint32_t ac_bk, uint32_t ac_vi, uint32_t ac_vo); - - /** - * \brief Helper method to set the QoS capability tagged option. - * - * \brief qos_info uint8_t with the QoS info byte. - */ - void qos_capabilities(uint8_t qos_info); - - /** - * \brief Helper method to search for the ESSID of this beacon. - * - * This method returns the essid of this beacon, or an empty - * string if no essid has been set. - */ - std::string essid() const; - - /** - * \brief Helper method to search for the RSN information of this beacon. - * - * This method fills the RSN information structure of this beacon. - * \param rsn A pointer in which the RSN information will be stored. - * \return True if the RSNInformation option has been set. - */ - bool rsn_information(RSNInformation *rsn); - /** * \brief Returns the frame's header length. * @@ -1573,7 +1461,9 @@ namespace Tins { * * \sa PDU::clone_pdu */ - PDU *clone_pdu() const; + PDU *clone_pdu() const { + return PDU::do_clone_pdu(); + } /** * \brief Getter for the PDU's type. @@ -1597,18 +1487,12 @@ namespace Tins { * */ class Dot11Disassoc : public Dot11ManagementFrame { - public: - - /** - * \brief Default constructor for the Disassociation frame. - * - * \param dst_hw_addr uint8_t array of 6 bytes containing the destination's MAC(optional). - * \param src_hw_addr uint8_t array of 6 bytes containing the source's MAC(optional). + /** + * \brief This PDU's flag. */ - Dot11Disassoc(const address_type &dst_hw_addr = address_type(), - const address_type &src_hw_addr = address_type()); - + static const PDU::PDUType pdu_flag = PDU::DOT11_DIASSOC; + /** * \brief Constructor for creating a 802.11 Disassociation. * @@ -1619,7 +1503,7 @@ namespace Tins { * \param dst_hw_addr uint8_t array of 6 bytes containing the destination's MAC(optional). * \param src_hw_addr uint8_t array of 6 bytes containing the source's MAC(optional). */ - Dot11Disassoc(const NetworkInterface& iface, + Dot11Disassoc(const NetworkInterface& iface = NetworkInterface(), const address_type &dst_hw_addr = address_type(), const address_type &src_hw_addr = address_type()); @@ -1696,15 +1580,6 @@ namespace Tins { */ static const PDU::PDUType pdu_flag = PDU::DOT11_ASSOC_REQ; - /** - * \brief Default constructor for the Association Request frame. - * - * \param dst_hw_addr uint8_t array of 6 bytes containing the destination's MAC(optional). - * \param src_hw_addr uint8_t array of 6 bytes containing the source's MAC(optional). - */ - Dot11AssocRequest(const address_type &dst_hw_addr = address_type(), - const address_type &src_hw_addr = address_type()); - /** * \brief Constructor for creating a 802.11 Association Request. * @@ -1715,7 +1590,7 @@ namespace Tins { * \param dst_hw_addr uint8_t array of 6 bytes containing the destination's MAC(optional). * \param src_hw_addr uint8_t array of 6 bytes containing the source's MAC(optional). */ - Dot11AssocRequest(const NetworkInterface& iface, + Dot11AssocRequest(const NetworkInterface& iface = NetworkInterface(), const address_type &dst_hw_addr = address_type(), const address_type &src_hw_addr = address_type()); @@ -1756,56 +1631,6 @@ namespace Tins { */ void listen_interval(uint16_t new_listen_interval); - /** - * \brief Helper method to set the essid. - * - * \param new_ssid The ssid to be set. - */ - void ssid(const std::string &new_ssid); - - /** - * \brief Helper method to set the supported rates. - * - * \param new_rates A list of rates to be set. - */ - void supported_rates(const std::list &new_rates); - - /** - * \brief Helper method to set the extended supported rates. - * - * \param new_rates A list of rates to be set. - */ - void extended_supported_rates(const std::list &new_rates); - - /** - * \brief Helper method to set the power capabilities. - * - * \param min_power uint8_t indicating the minimum transmiting power capability. - * \param max_power uint8_t indicating the maximum transmiting power capability. - */ - void power_capabilities(uint8_t min_power, uint8_t max_power); - - /** - * \brief Helper method to set the supported channels. - * - * \param new_channels A list of channels to be set. - */ - void supported_channels(const std::list > &new_channels); - - /** - * \brief Helper method to set the RSN information option. - * - * \param info The RSNInformation structure to be set. - */ - void rsn_information(const RSNInformation& info); - - /** - * \brief Helper method to set the QoS capabilities. - * - * \param new_qos_capabilities uint8_t with the capabilities. - */ - void qos_capabilities(uint8_t new_qos_capabilities); - /** * \brief Returns the frame's header length. * @@ -1857,15 +1682,6 @@ namespace Tins { */ static const PDU::PDUType pdu_flag = PDU::DOT11_ASSOC_RESP; - /** - * \brief Default constructor for the Association Response frame. - * - * \param dst_hw_addr uint8_t array of 6 bytes containing the destination's MAC(optional). - * \param src_hw_addr uint8_t array of 6 bytes containing the source's MAC(optional). - */ - Dot11AssocResponse(const address_type &dst_hw_addr = address_type(), - const address_type &src_hw_addr = address_type()); - /** * \brief Constructor for creating a 802.11 Association Response. * @@ -1876,7 +1692,7 @@ namespace Tins { * \param dst_hw_addr uint8_t array of 6 bytes containing the destination's MAC(optional). * \param src_hw_addr uint8_t array of 6 bytes containing the source's MAC(optional). */ - Dot11AssocResponse(const NetworkInterface& iface, + Dot11AssocResponse(const NetworkInterface& iface = NetworkInterface(), const address_type &dst_hw_addr = address_type(), const address_type &src_hw_addr = address_type()); @@ -1931,30 +1747,6 @@ namespace Tins { */ void aid(uint16_t new_aid); - /** - * \brief Helper method to set the supported rates. - * - * \param new_rates A list of rates to be set. - */ - void supported_rates(const std::list &new_rates); - - /** - * \brief Helper method to set the extended supported rates. - * - * \param new_rates A list of rates to be set. - */ - void extended_supported_rates(const std::list &new_rates); - - /** - * \brief Helper method to set the EDCA Parameter Set. - * - * \param ac_be uint32_t with the value of the ac_be field. - * \param ac_bk uint32_t with the value of the ac_bk field. - * \param ac_vi uint32_t with the value of the ac_vi field. - * \param ac_vo uint32_t with the value of the ac_vo field. - */ - void edca_parameter_set(uint32_t ac_be, uint32_t ac_bk, uint32_t ac_vi, uint32_t ac_vo); - /** * \brief Returns the frame's header length. * @@ -2007,15 +1799,6 @@ namespace Tins { */ static const PDU::PDUType pdu_flag = PDU::DOT11_REASSOC_REQ; - /** - * \brief Default constructor for the ReAssociation Request frame. - * - * \param dst_hw_addr uint8_t array of 6 bytes containing the destination's MAC(optional). - * \param src_hw_addr uint8_t array of 6 bytes containing the source's MAC(optional). - */ - Dot11ReAssocRequest(const address_type &dst_hw_addr = address_type(), - const address_type &src_hw_addr = address_type()); - /** * \brief Constructor for creating a 802.11 ReAssociation Request. * @@ -2026,7 +1809,7 @@ namespace Tins { * \param dst_hw_addr uint8_t array of 6 bytes containing the destination's MAC(optional). * \param src_hw_addr uint8_t array of 6 bytes containing the source's MAC(optional). */ - Dot11ReAssocRequest(const NetworkInterface& iface, + Dot11ReAssocRequest(const NetworkInterface& iface = NetworkInterface(), const address_type &dst_hw_addr = address_type(), const address_type &src_hw_addr = address_type()); @@ -2081,56 +1864,6 @@ namespace Tins { */ void current_ap(uint8_t* new_current_ap); - /** - * \brief Helper method to set the essid. - * - * \param new_ssid The ssid to be set. - */ - void ssid(const std::string &new_ssid); - - /** - * \brief Helper method to set the supported rates. - * - * \param new_rates A list of rates to be set. - */ - void supported_rates(const std::list &new_rates); - - /** - * \brief Helper method to set the extended supported rates. - * - * \param new_rates A list of rates to be set. - */ - void extended_supported_rates(const std::list &new_rates); - - /** - * \brief Helper method to set the power capabilities. - * - * \param min_power uint8_t indicating the minimum transmiting power capability. - * \param max_power uint8_t indicating the maximum transmiting power capability. - */ - void power_capabilities(uint8_t min_power, uint8_t max_power); - - /** - * \brief Helper method to set the supported channels. - * - * \param new_channels A list of channels to be set. - */ - void supported_channels(const std::list > &new_channels); - - /** - * \brief Helper method to set the RSN information option. - * - * \param info The RSNInformation structure to be set. - */ - void rsn_information(const RSNInformation& info); - - /** - * \brief Helper method to set the QoS capabilities. - * - * \param new_qos_capabilities uint8_t with the capabilities. - */ - void qos_capabilities(uint8_t new_qos_capabilities); - /** * \brief Returns the frame's header length. * @@ -2183,15 +1916,6 @@ namespace Tins { */ static const PDU::PDUType pdu_flag = PDU::DOT11_REASSOC_RESP; - /** - * \brief Default constructor for the ReAssociation Response frame. - * - * \param dst_hw_addr uint8_t array of 6 bytes containing the destination's MAC(optional). - * \param src_hw_addr uint8_t array of 6 bytes containing the source's MAC(optional). - */ - Dot11ReAssocResponse(const address_type &dst_hw_addr = address_type(), - const address_type &src_hw_addr = address_type()); - /** * \brief Constructor for creating a 802.11 Association Response. * @@ -2202,7 +1926,7 @@ namespace Tins { * \param dst_hw_addr uint8_t array of 6 bytes containing the destination's MAC(optional). * \param src_hw_addr uint8_t array of 6 bytes containing the source's MAC(optional). */ - Dot11ReAssocResponse(const NetworkInterface& iface, + Dot11ReAssocResponse(const NetworkInterface& iface = NetworkInterface(), const address_type &dst_hw_addr = address_type(), const address_type &src_hw_addr = address_type()); @@ -2257,30 +1981,6 @@ namespace Tins { */ void aid(uint16_t new_aid); - /** - * \brief Helper method to set the supported rates. - * - * \param new_rates A list of rates to be set. - */ - void supported_rates(const std::list &new_rates); - - /** - * \brief Helper method to set the extended supported rates. - * - * \param new_rates A list of rates to be set. - */ - void extended_supported_rates(const std::list &new_rates); - - /** - * \brief Helper method to set the EDCA Parameter Set. - * - * \param ac_be uint32_t with the value of the ac_be field. - * \param ac_bk uint32_t with the value of the ac_bk field. - * \param ac_vi uint32_t with the value of the ac_vi field. - * \param ac_vo uint32_t with the value of the ac_vo field. - */ - void edca_parameter_set(uint32_t ac_be, uint32_t ac_bk, uint32_t ac_vi, uint32_t ac_vo); - /** * \brief Returns the frame's header length. * @@ -2333,15 +2033,6 @@ namespace Tins { */ static const PDU::PDUType pdu_flag = PDU::DOT11_AUTH; - /** - * \brief Default constructor for the Authentication frame. - * - * \param dst_hw_addr uint8_t array of 6 bytes containing the destination's MAC(optional). - * \param src_hw_addr uint8_t array of 6 bytes containing the source's MAC(optional). - */ - Dot11Authentication(const address_type &dst_hw_addr = address_type(), - const address_type &src_hw_addr = address_type()); - /** * \brief Constructor for creating a 802.11 Authentication. * @@ -2352,7 +2043,7 @@ namespace Tins { * \param dst_hw_addr uint8_t array of 6 bytes containing the destination's MAC(optional). * \param src_hw_addr uint8_t array of 6 bytes containing the source's MAC(optional). */ - Dot11Authentication(const NetworkInterface& iface, + Dot11Authentication(const NetworkInterface& iface = NetworkInterface(), const address_type &dst_hw_addr = address_type(), const address_type &src_hw_addr = address_type()); @@ -2407,14 +2098,6 @@ namespace Tins { */ void status_code(uint16_t new_status_code); - /** - * \brief Helper method to set the Challenge Text tagged option. - * - * \brief ch_text uint8_t array with the challenge_text. - * \brief ch_text_sz uint8_t with the ch_text's length. - */ - void challenge_text(uint8_t* ch_text, uint8_t ch_text_sz); - /** * \brief Returns the frame's header length. * @@ -2468,15 +2151,6 @@ namespace Tins { */ static const PDU::PDUType pdu_flag = PDU::DOT11_DEAUTH; - /** - * \brief Default constructor for the Deauthentication frame. - * - * \param dst_hw_addr uint8_t array of 6 bytes containing the destination's MAC(optional). - * \param src_hw_addr uint8_t array of 6 bytes containing the source's MAC(optional). - */ - Dot11Deauthentication(const address_type &dst_hw_addr = address_type(), - const address_type &src_hw_addr = address_type()); - /** * \brief Constructor for creating a 802.11 Deauthentication. * @@ -2487,9 +2161,9 @@ namespace Tins { * \param dst_hw_addr uint8_t array of 6 bytes containing the destination's MAC(optional). * \param src_hw_addr uint8_t array of 6 bytes containing the source's MAC(optional). */ - Dot11Deauthentication(const NetworkInterface& iface, + Dot11Deauthentication(const NetworkInterface& iface = NetworkInterface(), const address_type &dst_hw_addr = address_type(), - const address_type &src_hw_addr = 0); + const address_type &src_hw_addr = address_type()); /** * \brief Constructor which creates a Dot11Deauthentication object from a buffer and adds @@ -2564,15 +2238,6 @@ namespace Tins { */ static const PDU::PDUType pdu_flag = PDU::DOT11_PROBE_REQ; - /** - * \brief Default constructor for the Probe Request frame. - * - * \param dst_hw_addr uint8_t array of 6 bytes containing the destination's MAC(optional). - * \param src_hw_addr uint8_t array of 6 bytes containing the source's MAC(optional). - */ - Dot11ProbeRequest(const address_type &dst_hw_addr = address_type(), - const address_type &src_hw_addr = address_type()); - /** * \brief Constructor for creating a 802.11 Probe Request. * @@ -2583,7 +2248,7 @@ namespace Tins { * \param dst_hw_addr uint8_t array of 6 bytes containing the destination's MAC(optional). * \param src_hw_addr uint8_t array of 6 bytes containing the source's MAC(optional). */ - Dot11ProbeRequest(const NetworkInterface& iface, + Dot11ProbeRequest(const NetworkInterface& iface = NetworkInterface(), const address_type &dst_hw_addr = address_type(), const address_type &src_hw_addr = address_type()); @@ -2596,34 +2261,6 @@ namespace Tins { */ Dot11ProbeRequest(const uint8_t *buffer, uint32_t total_sz); - /** - * \brief Helper method to set the essid. - * - * \param new_ssid The ssid to be set. - */ - void ssid(const std::string &new_ssid); - - /** - * \brief Helper method to set the supported rates. - * - * \param new_rates A list of rates to be set. - */ - void supported_rates(const std::list &new_rates); - - /** - * \brief Helper method to set the extended supported rates. - * - * \param new_rates A list of rates to be set. - */ - void extended_supported_rates(const std::list &new_rates); - - /** - * \brief Helper method to set the Request Information element. - * - * \param elements A list of elements. - */ - void request_information(const std::list elements); - /** * \brief Getter for the PDU's type. * \sa PDU::pdu_type @@ -2659,15 +2296,6 @@ namespace Tins { */ static const PDU::PDUType pdu_flag = PDU::DOT11_PROBE_RESP; - /** - * \brief Default constructor for the Probe Response frame. - * - * \param dst_hw_addr uint8_t array of 6 bytes containing the destination's MAC(optional). - * \param src_hw_addr uint8_t array of 6 bytes containing the source's MAC(optional). - */ - Dot11ProbeResponse(const address_type &dst_hw_addr = address_type(), - const address_type &src_hw_addr = address_type()); - /** * \brief Constructor for creating a 802.11 Probe Response. * @@ -2678,7 +2306,7 @@ namespace Tins { * \param dst_hw_addr uint8_t array of 6 bytes containing the destination's MAC(optional). * \param src_hw_addr uint8_t array of 6 bytes containing the source's MAC(optional). */ - Dot11ProbeResponse(const NetworkInterface& iface, + Dot11ProbeResponse(const NetworkInterface& iface = NetworkInterface(), const address_type &dst_hw_addr = address_type(), const address_type &src_hw_addr = address_type()); @@ -2733,166 +2361,6 @@ namespace Tins { */ void interval(uint16_t new_interval); - /** - * \brief Helper method to set the ssid. - * - * \param new_ssid The ssid to be set. - */ - void ssid(const std::string &new_ssid); - - /** - * \brief Helper method to set the supported rates. - * - * \param new_rates A list of rates to be set. - */ - void supported_rates(const std::list &new_rates); - - /** - * \brief Helper method to set the FH parameter. - * - * \param dwell_time uint16_t with the dwell_time value. - * \param hop_set uint8_t with the value of the set_hop. - * \param hop_pattern uint8_t with the value of the hop_pattern field. - * \param hop_index uint8_t with the value of the hop_index field. - */ - void fh_parameter_set(uint16_t dwell_time, uint8_t hop_set, uint8_t hop_pattern, uint8_t hop_index); - - /** - * \brief Helper method to set the DS parameter. - * - * \param current_channel uint8_t with the value of the current_channel field. - */ - void ds_parameter_set(uint8_t current_channel); - - /** - * \brief Helper method to set the CF parameter. - * - * \param cfp_count uint8_t with the value of the cfp count field. - * \param cfp_period uint8_t with the value of the cfp period field. - * \param cfp_max_duration uint16_t with the value of the cfp max duration field. - * \param cfp_dur_remaining uint16_t with the value of the DurRemaining field. - */ - void cf_parameter_set(uint8_t cfp_count, uint8_t cfp_period, uint16_t cfp_max_duration, uint16_t cfp_dur_remaining); - - /** - * \brief Helper method to set the IBSS parameter. - * - * \param atim_window uint16_t with the value of the ATIM window field. - */ - void ibss_parameter_set(uint16_t atim_window); - - /** - * \brief Helper method to set the country tagged option. - * - * \param countries Reference to a vector of uint8_t arrays of 3 bytes. Containing the list of countries. - * \param first_channels Reference to a vector of uint8_t. Containing the first channels for each country. - * \param num_channels Reference to a vector of uint8_t. Containing the number of channels for each country. - * \param max_power Reference to a vector of uint8_t. Containing the max power for each country. - */ - void country(const std::vector& countries, const std::vector& first_channels, const std::vector& number_channels, const std::vector& max_power); - - /** - * \brief Helper method to set the FH parameters. - * - * \param prime_radix uint8_t with the value of the prime radix field. - * \param number_channels uint8_t with the value of the number channels field. - */ - void fh_parameters(uint8_t prime_radix, uint8_t number_channels); - - /** - * \brief Helper method to set the FH pattern table. - * - * \param flag uint8_t with the value of the flag field. - * \param number_of_sets uint8_t with the value of the number of sets field. - * \param modulus uint8_t with the value of the modulus field. - * \param offset uint8_t with the value of the offset field. - * \param random_table reference to vector of uint8_t witht the elements of the table. - */ - void fh_pattern_table(uint8_t flag, uint8_t number_of_sets, uint8_t modulus, uint8_t offset, const std::vector& random_table); - - /** - * \brief Helper method to set the Power Constraint tagged option. - * - * \param local_power_constraint uint8_t with the value of the local power constraint field. - */ - void power_constraint(uint8_t local_power_constraint); - - /** - * \brief Helper method to set the Channel Switch tagged option. - * - * \param switch_mode uint8_t with the value of the switch mode field. - * \param new_channel uint8_t with the value of the new channel field. - * \param switch_count uint8_t with the value of the switch count field. - */ - void channel_switch(uint8_t switch_mode, uint8_t new_channel, uint8_t switch_count); - - /** - * \brief Helper method to set the Quiet tagged option. - * - * \param quiet_count uint8_t with the value of the quiet count field. - * \param quiet_period uint8_t with the value of the quiet period field. - * \param quiet_duration uint16_t with the value of the quiet duration field. - * \param quiet_offset uint16_t with the value of the quiet offset field. - */ - void quiet(uint8_t quiet_count, uint8_t quiet_period, uint16_t quiet_duration, uint16_t quiet_offset); - - /** - * \brief Helper method to set the IBSS DFS tagged option. - * - * \param dfs_owner uint8_t array of 6 bytes with the dfs owner. - * \param recovery_interval uint8_t with the value of the recovery interval field. - * \param channel_map Reference to a constant vector of pair of uint8_t with the map of channels. - */ - void ibss_dfs(const uint8_t* dfs_owner, uint8_t recovery_interval, const std::vector >& channel_map); - - /** - * \brief Helper method to set the TPC Report tagged option. - * - * \param transmit_power uint8_t with the value of the transmit power field. - * \param link_margin uint8_t with the value of the link margin field. - */ - void tpc_report(uint8_t transmit_power, uint8_t link_margin); - - /** - * \brief Helper method to set the ERP Information tagged option. - * - * \param value with the value to set as argument of the tagged option. - */ - void erp_information(uint8_t value); - - /** - * \brief Helper method to set the extended supported rates. - * - * \param new_rates A list of rates to be set. - */ - void extended_supported_rates(const std::list &new_rates); - - /** - * \brief Helper method to set the RSN information option. - * - * \param info The RSNInformation structure to be set. - */ - void rsn_information(const RSNInformation& info); - - /** - * \brief Helper method to set the BSS Load tagged option. - * - * \param station_count uint16_t with the value of the station count field. - * \param channel_utilization uint8_t with the value of the channel utilization field. - * \param available_capacity uint16_t with the value of the available capacity field. - */ - void bss_load(uint16_t station_count, uint8_t channel_utilization, uint16_t avaliable_capacity); - - /** - * \brief Helper method to set the EDCA Parameter Set. - * - * \param ac_be uint32_t with the value of the ac_be field. - * \param ac_bk uint32_t with the value of the ac_bk field. - * \param ac_vi uint32_t with the value of the ac_vi field. - * \param ac_vo uint32_t with the value of the ac_vo field. - */ - void edca_parameter_set(uint32_t ac_be, uint32_t ac_bk, uint32_t ac_vi, uint32_t ac_vo); - /** * \brief Returns the frame's header length. * @@ -2944,13 +2412,11 @@ namespace Tins { */ static const PDU::PDUType pdu_flag = PDU::DOT11_DATA; - Dot11Data(const address_type &dst_hw_addr = address_type(), + Dot11Data(const NetworkInterface &iface = NetworkInterface(), + const address_type &dst_hw_addr = address_type(), const address_type &src_hw_addr = address_type(), PDU* child = 0); - Dot11Data(const NetworkInterface &iface, const address_type &dst_hw_addr, - const address_type &src_hw_addr, PDU* child = 0); - /** * \brief Constructor which creates a Dot11Data object from a buffer and adds all identifiable * PDUs found in the buffer as children of this one. @@ -3088,19 +2554,6 @@ namespace Tins { */ static const PDU::PDUType pdu_flag = PDU::DOT11_QOS_DATA; - /** - * \brief Constructor for creating a 802.11 QoS Data PDU - * - * Constructor that builds a 802.11 QoS Data PDU taking the destination's and source's MAC. - * - * \param dst_hw_addr uint8_t array of 6 bytes containing the destination's MAC(optional). - * \param src_hw_addr uint8_t array of 6 bytes containing the source's MAC(optional). - * \param child PDU* with the PDU contained by the 802.11 PDU (optional). - */ - Dot11QoSData(const address_type &dst_hw_addr = address_type(), - const address_type &src_hw_addr = address_type(), - PDU* child = 0); - /** * \brief Constructor for creating a 802.11 QoS Data PDU * @@ -3112,7 +2565,7 @@ namespace Tins { * \param src_hw_addr uint8_t array of 6 bytes containing the source's MAC(optional). * \param child PDU* with the PDU contained by the 802.11 PDU (optional). */ - Dot11QoSData(const NetworkInterface& iface, + Dot11QoSData(const NetworkInterface& iface = NetworkInterface(), const address_type &dst_hw_addr = address_type(), const address_type &src_hw_addr = address_type(), PDU* child = 0); @@ -3195,18 +2648,7 @@ namespace Tins { * \brief This PDU's flag. */ static const PDU::PDUType pdu_flag = PDU::DOT11_CONTROL; - - /** - * \brief Constructor for creating a 802.11 control frame PDU - * - * Constructor that builds a 802.11 PDU taking the destination's and source's MAC. - * - * \param dst_addr uint8_t array of 6 bytes containing the destination's MAC(optional). - * \param child PDU* with the PDU contained by the 802.11 PDU (optional). - */ - Dot11Control(const address_type &dst_addr = address_type(), - PDU* child = 0); - + /** * \brief Constructor for creating a 802.11 control frame PDU * @@ -3217,7 +2659,7 @@ namespace Tins { * \param dst_addr uint8_t array of 6 bytes containing the destination's MAC(optional). * \param child PDU* with the PDU contained by the 802.11 PDU (optional). */ - Dot11Control(const NetworkInterface& iface, + Dot11Control(const NetworkInterface& iface = NetworkInterface(), const address_type &dst_addr = address_type(), PDU* child = 0); @@ -3251,19 +2693,6 @@ namespace Tins { */ class Dot11ControlTA : public Dot11Control { protected: - /** - * \brief Constructor for creating a 802.11 control frame TA PDU - * - * Constructor that builds a 802.11 PDU taking the destination's and source's MAC. - * - * \param dst_addr uint8_t array of 6 bytes containing the destination's MAC(optional). - * \param target_addr uint8_t array of 6 bytes containing the source's MAC(optional). - * \param child PDU* with the PDU contained by the 802.11 PDU (optional). - */ - Dot11ControlTA(const address_type &dst_addr = address_type(), - const address_type &target_addr = address_type(), - PDU* child = 0); - /** * \brief Constructor for creating a 802.11 control frame TA PDU * @@ -3275,7 +2704,7 @@ namespace Tins { * \param target_addr uint8_t array of 6 bytes containing the source's MAC(optional). * \param child PDU* with the PDU contained by the 802.11 PDU (optional). */ - Dot11ControlTA(const NetworkInterface& iface, + Dot11ControlTA(const NetworkInterface& iface = NetworkInterface(), const address_type &dst_addr = address_type(), const address_type &target_addr = address_type(), PDU* child = 0); @@ -3324,19 +2753,6 @@ namespace Tins { * \brief This PDU's flag. */ static const PDU::PDUType pdu_flag = PDU::DOT11_RTS; - - /** - * \brief Constructor for creating a 802.11 RTS frame PDU - * - * Constructor that builds a 802.11 PDU taking the destination's and source's MAC. - * - * \param dst_addr uint8_t array of 6 bytes containing the destination's MAC(optional). - * \param target_addr uint8_t array of 6 bytes containing the source's MAC(optional). - * \param child PDU* with the PDU contained by the 802.11 PDU (optional). - */ - Dot11RTS(const address_type &dst_addr = address_type(), - const address_type &target_addr = address_type(), - PDU* child = 0); /** * \brief Constructor for creating a 802.11 RTS frame PDU @@ -3349,7 +2765,7 @@ namespace Tins { * \param target_addr uint8_t array of 6 bytes containing the source's MAC(optional). * \param child PDU* with the PDU contained by the 802.11 PDU (optional). */ - Dot11RTS(const NetworkInterface& iface, + Dot11RTS(const NetworkInterface& iface = NetworkInterface(), const address_type &dst_addr = address_type(), const address_type &target_addr = address_type(), PDU* child = 0); @@ -3391,19 +2807,6 @@ namespace Tins { * \brief This PDU's flag. */ static const PDU::PDUType pdu_flag = PDU::DOT11_PS_POLL; - - /** - * \brief Constructor for creating a 802.11 PS-Poll frame PDU - * - * Constructor that builds a 802.11 PDU taking the destination's and source's MAC. - * - * \param dst_addr uint8_t array of 6 bytes containing the destination's MAC(optional). - * \param target_addr uint8_t array of 6 bytes containing the source's MAC(optional). - * \param child PDU* with the PDU contained by the 802.11 PDU (optional). - */ - Dot11PSPoll(const address_type &dst_addr = address_type(), - const address_type &target_addr = address_type(), - PDU* child = 0); /** * \brief Constructor for creating a 802.11 PS-Poll frame PDU @@ -3416,7 +2819,7 @@ namespace Tins { * \param target_addr uint8_t array of 6 bytes containing the source's MAC(optional). * \param child PDU* with the PDU contained by the 802.11 PDU (optional). */ - Dot11PSPoll(const NetworkInterface& iface, + Dot11PSPoll(const NetworkInterface& iface = NetworkInterface(), const address_type &dst_addr = address_type(), const address_type &target_addr = address_type(), PDU* child = 0); @@ -3458,19 +2861,6 @@ namespace Tins { * \brief This PDU's flag. */ static const PDU::PDUType pdu_flag = PDU::DOT11_CF_END; - - /** - * \brief Constructor for creating a 802.11 CF-End frame PDU - * - * Constructor that builds a 802.11 PDU taking the destination's and source's MAC. - * - * \param dst_addr uint8_t array of 6 bytes containing the destination's MAC(optional). - * \param target_addr uint8_t array of 6 bytes containing the source's MAC(optional). - * \param child PDU* with the PDU contained by the 802.11 PDU (optional). - */ - Dot11CFEnd(const address_type &dst_addr = address_type(), - const address_type &target_addr = address_type(), - PDU* child = 0); /** * \brief Constructor for creating a 802.11 CF-End frame PDU @@ -3483,7 +2873,7 @@ namespace Tins { * \param target_addr uint8_t array of 6 bytes containing the source's MAC(optional). * \param child PDU* with the PDU contained by the 802.11 PDU (optional). */ - Dot11CFEnd(const NetworkInterface& iface, + Dot11CFEnd(const NetworkInterface& iface = NetworkInterface(), const address_type &dst_addr = address_type(), const address_type &target_addr = address_type(), PDU* child = 0); @@ -3525,18 +2915,6 @@ namespace Tins { * \brief This PDU's flag. */ static const PDU::PDUType pdu_flag = PDU::DOT11_END_CF_ACK; - - /** - * \brief Constructor for creating a 802.11 End-CF-Ack frame PDU - * - * Constructor that builds a 802.11 PDU taking the destination's and source's MAC. - * \param dst_addr uint8_t array of 6 bytes containing the destination's MAC(optional). - * \param target_addr uint8_t array of 6 bytes containing the source's MAC(optional). - * \param child PDU* with the PDU contained by the 802.11 PDU (optional). - */ - Dot11EndCFAck(const address_type &dst_addr = address_type(), - const address_type &target_addr = address_type(), - PDU* child = 0); /** * \brief Constructor for creating a 802.11 End-CF-Ack frame PDU @@ -3548,7 +2926,7 @@ namespace Tins { * \param target_addr uint8_t array of 6 bytes containing the source's MAC(optional). * \param child PDU* with the PDU contained by the 802.11 PDU (optional). */ - Dot11EndCFAck(const NetworkInterface& iface, + Dot11EndCFAck(const NetworkInterface& iface = NetworkInterface(), const address_type &dst_addr = address_type(), const address_type &target_addr = address_type(), PDU* child = 0); @@ -3590,16 +2968,6 @@ namespace Tins { * \brief This PDU's flag. */ static const PDU::PDUType pdu_flag = PDU::DOT11_ACK; - - /** - * \brief Constructor for creating a 802.11 Ack frame PDU - * - * Constructor that builds a 802.11 PDU taking the destination's and source's MAC. - * - * \param dst_addr uint8_t array of 6 bytes containing the destination's MAC(optional). - * \param child PDU* with the PDU contained by the 802.11 PDU (optional). - */ - Dot11Ack(const address_type &dst_addr = address_type(), PDU* child = 0); /** * \brief Constructor for creating a 802.11 Ack frame PDU @@ -3611,7 +2979,7 @@ namespace Tins { * \param dst_addr uint8_t array of 6 bytes containing the destination's MAC(optional). * \param child PDU* with the PDU contained by the 802.11 PDU (optional). */ - Dot11Ack(const NetworkInterface& iface, + Dot11Ack(const NetworkInterface& iface = NetworkInterface(), const address_type &dst_addr = address_type(), PDU* child = 0); @@ -3655,18 +3023,6 @@ namespace Tins { * \brief This PDU's flag. */ static const PDU::PDUType pdu_flag = PDU::DOT11_BLOCK_ACK_REQ; - - /** - * \brief Constructor for creating a 802.11 Block Ack request frame PDU - * - * Constructor that builds a 802.11 PDU taking the destination's and source's MAC. - * \param dst_addr uint8_t array of 6 bytes containing the destination's MAC(optional). - * \param target_addr uint8_t array of 6 bytes containing the source's MAC(optional). - * \param child PDU* with the PDU contained by the 802.11 PDU (optional). - */ - Dot11BlockAckRequest(const address_type &dst_addr = address_type(), - const address_type &target_addr = address_type(), - PDU* child = 0); /** * \brief Constructor for creating a 802.11 Block Ack request frame PDU @@ -3678,7 +3034,7 @@ namespace Tins { * \param target_addr uint8_t array of 6 bytes containing the source's MAC(optional). * \param child PDU* with the PDU contained by the 802.11 PDU (optional). */ - Dot11BlockAckRequest(const NetworkInterface& iface, + Dot11BlockAckRequest(const NetworkInterface& iface = NetworkInterface(), const address_type &dst_addr = address_type(), const address_type &target_addr = address_type(), PDU* child = 0); @@ -3775,18 +3131,6 @@ namespace Tins { * \brief This PDU's flag. */ static const PDU::PDUType pdu_flag = PDU::DOT11_BLOCK_ACK; - - /** - * \brief Constructor for creating a 802.11 Block Ack frame PDU. - * - * Constructor that builds a 802.11 PDU taking the destination's and source's MAC. - * \param dst_addr uint8_t array of 6 bytes containing the destination's MAC(optional). - * \param target_addr uint8_t array of 6 bytes containing the source's MAC(optional). - * \param child PDU* with the PDU contained by the 802.11 PDU (optional). - */ - Dot11BlockAck(const address_type &dst_addr = address_type(), - const address_type &target_addr = address_type(), - PDU* child = 0); /** * \brief Constructor for creating a 802.11 Block Ack frame PDU @@ -3798,7 +3142,7 @@ namespace Tins { * \param target_addr uint8_t array of 6 bytes containing the source's MAC(optional). * \param child PDU* with the PDU contained by the 802.11 PDU (optional). */ - Dot11BlockAck(const NetworkInterface& iface, + Dot11BlockAck(const NetworkInterface& iface = NetworkInterface(), const address_type &dst_addr = address_type(), const address_type &target_addr = address_type(), PDU* child = 0); diff --git a/src/dot11.cpp b/src/dot11.cpp index 7cefd63..5eca823 100644 --- a/src/dot11.cpp +++ b/src/dot11.cpp @@ -46,20 +46,12 @@ using std::runtime_error; namespace Tins { const Dot11::address_type Dot11::BROADCAST = "ff:ff:ff:ff:ff:ff"; -Dot11::Dot11(const address_type &dst_hw_addr, PDU* child) -: PDU(ETHERTYPE_IP, child), _options_size(0) -{ - memset(&this->_header, 0, sizeof(ieee80211_header)); - addr1(dst_hw_addr); -} - Dot11::Dot11(const NetworkInterface &iface, const address_type &dst_hw_addr, PDU* child) -: PDU(ETHERTYPE_IP, child), _options_size(0) +: PDU(ETHERTYPE_IP, child), _iface(iface), _options_size(0) { memset(&_header, 0, sizeof(ieee80211_header)); addr1(dst_hw_addr); - this->iface(iface); } Dot11::Dot11(const ieee80211_header *header_ptr) @@ -78,21 +70,10 @@ Dot11::Dot11(const uint8_t *buffer, uint32_t total_sz) buffer += sz; total_sz -= sz;*/ if(total_sz < sizeof(_header)) - throw runtime_error("Not enough size for an IEEE 802.11 header in the buffer."); + throw runtime_error("Not enough size for an Dot11 header in the buffer."); std::memcpy(&_header, buffer, sizeof(_header)); } -Dot11::Dot11(const Dot11 &other) : PDU(other) { - copy_80211_fields(&other); -} - -Dot11::~Dot11() { - while(_options.size()) { - delete[] _options.front().value; - _options.pop_front(); - } -} - Dot11 &Dot11::operator= (const Dot11 &other) { copy_80211_fields(&other); copy_inner_pdu(other); @@ -114,9 +95,9 @@ void Dot11::parse_tagged_parameters(const uint8_t *buffer, uint32_t total_sz) { } } -Dot11::Dot11Option::Dot11Option(uint8_t opt, uint8_t len, const uint8_t *val) : option(opt), length(len) { - value = new uint8_t[len]; - std::memcpy(value, val, len); +Dot11::Dot11Option::Dot11Option(uint8_t opt, uint8_t len, const uint8_t *val) +: option_id(opt), value(val, val + len) { + } void Dot11::add_tagged_option(TaggedOption opt, uint8_t len, const uint8_t *val) { @@ -127,7 +108,7 @@ void Dot11::add_tagged_option(TaggedOption opt, uint8_t len, const uint8_t *val) const Dot11::Dot11Option *Dot11::search_option(TaggedOption opt) const { for(std::list::const_iterator it = _options.begin(); it != _options.end(); ++it) - if(it->option == (uint8_t)opt) + if(it->option() == (uint8_t)opt) return &(*it); return 0; } @@ -173,7 +154,7 @@ void Dot11::order(bool new_value) { } void Dot11::duration_id(uint16_t new_duration_id) { - this->_header.duration_id = new_duration_id; + this->_header.duration_id = Utils::host_to_le(new_duration_id); } void Dot11::addr1(const address_type &new_addr1) { @@ -218,10 +199,11 @@ void Dot11::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *p buffer += child_len; assert(total_sz >= child_len + _options_size); for(std::list::const_iterator it = _options.begin(); it != _options.end(); ++it) { - *(buffer++) = it->option; - *(buffer++) = it->length; - std::memcpy(buffer, it->value, it->length); - buffer += it->length; + *(buffer++) = it->option(); + *(buffer++) = it->data_size(); + //std::memcpy(buffer, it->value, it->length); + std::copy(it->data_ptr(), it->data_ptr() + it->data_size(), buffer); + buffer += it->data_size(); } } @@ -268,7 +250,7 @@ void Dot11::copy_80211_fields(const Dot11 *other) { _iface = other->_iface; _options_size = other->_options_size; for(std::list::const_iterator it = other->_options.begin(); it != other->_options.end(); ++it) - _options.push_back(Dot11Option(it->option, it->length, it->value)); + _options.push_back(Dot11Option(it->option(), it->data_size(), it->data_ptr())); } /* Dot11ManagementFrame */ @@ -279,22 +261,15 @@ Dot11ManagementFrame::Dot11ManagementFrame(const uint8_t *buffer, uint32_t total buffer += sizeof(ieee80211_header); total_sz -= sizeof(ieee80211_header); if(total_sz < sizeof(_ext_header)) - throw runtime_error("Not enough size for an IEEE 802.11 header in the buffer."); + throw runtime_error("Not enough size for an Dot11ManagementFrame header in the buffer."); std::memcpy(&_ext_header, buffer, sizeof(_ext_header)); total_sz -= sizeof(_ext_header); - if(from_ds() && to_ds() && total_sz >= _addr4.size()) - //std::memcpy(_addr4, buffer + sizeof(_ext_header), sizeof(_addr4)); - _addr4 = buffer + sizeof(_ext_header); - else - throw runtime_error("Not enough size for an IEEE 802.11 header in the buffer."); -} - -Dot11ManagementFrame::Dot11ManagementFrame( - const address_type &dst_hw_addr, const address_type &src_hw_addr) -: Dot11(dst_hw_addr) -{ - type(Dot11::MANAGEMENT); - addr2(src_hw_addr); + if(from_ds() && to_ds()) { + if(total_sz >= _addr4.size()) + _addr4 = buffer + sizeof(_ext_header); + else + throw runtime_error("Not enough size for an Dot11ManagementFrame header in the buffer."); + } } Dot11ManagementFrame::Dot11ManagementFrame(const NetworkInterface &iface, @@ -302,13 +277,10 @@ Dot11ManagementFrame::Dot11ManagementFrame(const NetworkInterface &iface, : Dot11(iface, dst_hw_addr) { type(Dot11::MANAGEMENT); + memset(&_ext_header, 0, sizeof(_ext_header)); addr2(src_hw_addr); } -Dot11ManagementFrame::Dot11ManagementFrame(const Dot11ManagementFrame &other) : Dot11(other) { - copy_ext_header(&other); -} - void Dot11ManagementFrame::copy_ext_header(const Dot11ManagementFrame* other) { Dot11::copy_80211_fields(other); std::memcpy(&_ext_header, &other->_ext_header, sizeof(_ext_header)); @@ -365,45 +337,53 @@ void Dot11ManagementFrame::rsn_information(const RSNInformation& info) { delete[] buffer; } -void Dot11ManagementFrame::supported_rates(const std::list &new_rates) { - uint8_t *buffer = new uint8_t[new_rates.size()], *ptr = buffer; - for(std::list::const_iterator it = new_rates.begin(); it != new_rates.end(); ++it) { - uint8_t result = 0x80, left = *it / 0.5; - if(*it - left > 0) - left++; - *(ptr++) = (result | left); +uint8_t *Dot11ManagementFrame::serialize_rates(const rates_type &rates) { + uint8_t *buffer = new uint8_t[rates.size()], *ptr = buffer; + for(rates_type::const_iterator it = rates.begin(); it != rates.end(); ++it) { + uint8_t result = *it * 2; + if(result == 2 || result == 4 || result == 11 || result == 22) + result |= 0x80; + *(ptr++) = result; } + return buffer; +} + +Dot11ManagementFrame::rates_type Dot11ManagementFrame::deserialize_rates(const Dot11Option *option) { + rates_type output; + const uint8_t *ptr = option->data_ptr(), *end = ptr + option->data_size(); + while(ptr != end) { + output.push_back(float(*(ptr++) & 0x7f) / 2); + } + return output; +} + +void Dot11ManagementFrame::supported_rates(const rates_type &new_rates) { + uint8_t *buffer = serialize_rates(new_rates); add_tagged_option(SUPPORTED_RATES, new_rates.size(), buffer); delete[] buffer; } -void Dot11ManagementFrame::extended_supported_rates(const std::list &new_rates) { - uint8_t *buffer = new uint8_t[new_rates.size()], *ptr = buffer; - for(std::list::const_iterator it = new_rates.begin(); it != new_rates.end(); ++it) { - uint8_t result = 0x80, left = *it / 0.5; - if(*it - left > 0) - left++; - *(ptr++) = (result | left); - } +void Dot11ManagementFrame::extended_supported_rates(const rates_type &new_rates) { + uint8_t *buffer = serialize_rates(new_rates); add_tagged_option(EXT_SUPPORTED_RATES, new_rates.size(), buffer); delete[] buffer; } -void Dot11ManagementFrame::qos_capabilities(uint8_t new_qos_capabilities) { - add_tagged_option(QOS_CAPABILITY, 1, &new_qos_capabilities); +void Dot11ManagementFrame::qos_capability(uint8_t new_qos_capability) { + add_tagged_option(QOS_CAPABILITY, 1, &new_qos_capability); } -void Dot11ManagementFrame::power_capabilities(uint8_t min_power, uint8_t max_power) { +void Dot11ManagementFrame::power_capability(uint8_t min_power, uint8_t max_power) { uint8_t buffer[2]; buffer[0] = min_power; buffer[1] = max_power; add_tagged_option(POWER_CAPABILITY, 2, buffer); } -void Dot11ManagementFrame::supported_channels(const std::list > &new_channels) { +void Dot11ManagementFrame::supported_channels(const channels_type &new_channels) { uint8_t* buffer = new uint8_t[new_channels.size() * 2]; uint8_t* ptr = buffer; - for(std::list >::const_iterator it = new_channels.begin(); it != new_channels.end(); ++it) { + for(channels_type::const_iterator it = new_channels.begin(); it != new_channels.end(); ++it) { *(ptr++) = it->first; *(ptr++) = it->second; } @@ -414,23 +394,20 @@ void Dot11ManagementFrame::supported_channels(const std::list elements) { - uint16_t sz = elements.size(); - list::const_iterator it = elements.begin(); - uint8_t* buffer = new uint8_t[sz]; - for (uint16_t i = 0; i < sz; i++) { - buffer[i] = *it; - it++; - } - add_tagged_option(REQUEST, sz, buffer); +void Dot11ManagementFrame::request_information(const request_info_type elements) { + uint8_t *buffer = new uint8_t[elements.size()], *ptr = buffer; + for (request_info_type::const_iterator it = elements.begin(); it != elements.end(); ++it) + *(ptr++) = *it; + add_tagged_option(REQUEST_INFORMATION, elements.size(), buffer); delete[] buffer; } @@ -529,7 +506,6 @@ void Dot11ManagementFrame::power_constraint(uint8_t local_power_constraint) { } void Dot11ManagementFrame::channel_switch(uint8_t switch_mode, uint8_t new_channel, uint8_t switch_count) { - uint8_t buffer[3]; buffer[0] = switch_mode; buffer[1] = new_channel; @@ -539,7 +515,6 @@ void Dot11ManagementFrame::channel_switch(uint8_t switch_mode, uint8_t new_chann } void Dot11ManagementFrame::quiet(uint8_t quiet_count, uint8_t quiet_period, uint16_t quiet_duration, uint16_t quiet_offset) { - uint8_t buffer[6]; uint16_t* ptr_buffer = (uint16_t*)buffer; @@ -552,7 +527,6 @@ void Dot11ManagementFrame::quiet(uint8_t quiet_count, uint8_t quiet_period, uint } void Dot11ManagementFrame::ibss_dfs(const uint8_t* dfs_owner, uint8_t recovery_interval, const vector >& channel_map) { - uint8_t sz = 7 + 2 * channel_map.size(); uint8_t* buffer = new uint8_t[sz]; uint8_t* ptr_buffer = buffer; @@ -572,7 +546,6 @@ void Dot11ManagementFrame::ibss_dfs(const uint8_t* dfs_owner, uint8_t recovery_i } void Dot11ManagementFrame::tpc_report(uint8_t transmit_power, uint8_t link_margin) { - uint8_t buffer[2]; buffer[0] = transmit_power; buffer[1] = link_margin; @@ -614,164 +587,12 @@ void Dot11ManagementFrame::challenge_text(uint8_t* ch_text, uint8_t ch_text_sz) add_tagged_option(CHALLENGE_TEXT, ch_text_sz, ch_text); } -/* Dot11Beacon */ - -Dot11Beacon::Dot11Beacon(const address_type &dst_hw_addr, - const address_type &src_hw_addr) -: Dot11ManagementFrame(dst_hw_addr, src_hw_addr) { - subtype(Dot11::BEACON); - memset(&_body, 0, sizeof(_body)); -} - -Dot11Beacon::Dot11Beacon(const NetworkInterface& iface, - const address_type &dst_hw_addr, const address_type &src_hw_addr) -: Dot11ManagementFrame(iface, dst_hw_addr, src_hw_addr) -{ - subtype(Dot11::BEACON); - memset(&_body, 0, sizeof(_body)); -} - -Dot11Beacon::Dot11Beacon(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 beacon header in the buffer."); - memcpy(&_body, buffer, sizeof(_body)); - buffer += sizeof(_body); - total_sz -= sizeof(_body); - parse_tagged_parameters(buffer, total_sz); -} - -void Dot11Beacon::timestamp(uint64_t new_timestamp) { - this->_body.timestamp = new_timestamp; -} - -void Dot11Beacon::interval(uint16_t new_interval) { - this->_body.interval = new_interval; -} - -void Dot11Beacon::essid(const std::string &new_essid) { - Dot11ManagementFrame::ssid(new_essid); -} - -void Dot11Beacon::supported_rates(const std::list &new_rates) { - Dot11ManagementFrame::supported_rates(new_rates); -} - -void Dot11Beacon::ds_parameter_set(uint8_t current_channel) { - Dot11ManagementFrame::ds_parameter_set(current_channel); -} - -void Dot11Beacon::fh_parameter_set(uint16_t dwell_time, - uint8_t hop_set, - uint8_t hop_pattern, - uint8_t hop_index) { - Dot11ManagementFrame::fh_parameter_set(dwell_time, hop_set, hop_pattern, hop_index); -} - -void Dot11Beacon::cf_parameter_set(uint8_t cfp_count, - uint8_t cfp_period, - uint16_t cfp_max_duration, - uint16_t cfp_dur_remaining) { - Dot11ManagementFrame::cf_parameter_set(cfp_count, cfp_period, cfp_max_duration, cfp_dur_remaining); -} - -void Dot11Beacon::ibss_parameter_set(uint16_t atim_window) { - Dot11ManagementFrame::ibss_parameter_set(atim_window); -} - -void Dot11Beacon::tim(uint8_t dtim_count, - uint8_t dtim_period, - uint8_t bitmap_control, - uint8_t* partial_virtual_bitmap, - uint8_t partial_virtual_bitmap_sz) { - Dot11ManagementFrame::tim(dtim_count, dtim_period, bitmap_control, partial_virtual_bitmap, partial_virtual_bitmap_sz); -} - -void Dot11Beacon::country(const std::vector& countries, - const std::vector& first_channels, - const std::vector& number_channels, - const std::vector& max_power) { - Dot11ManagementFrame::country(countries, first_channels, number_channels, max_power); -} - -void Dot11Beacon::fh_parameters(uint8_t prime_radix, uint8_t number_channels) { - Dot11ManagementFrame::fh_parameters(prime_radix, number_channels); -} - -void Dot11Beacon::fh_pattern_table(uint8_t flag, - uint8_t number_of_sets, - uint8_t modulus, - uint8_t offset, - const std::vector& random_table) { - Dot11ManagementFrame::fh_pattern_table(flag, number_of_sets, modulus, offset, random_table); -} - -void Dot11Beacon::power_constraint(uint8_t local_power_constraint) { - Dot11ManagementFrame::power_constraint(local_power_constraint); -} - -void Dot11Beacon::channel_switch(uint8_t switch_mode, uint8_t new_channel, uint8_t switch_count) { - Dot11ManagementFrame::channel_switch(switch_mode, new_channel, switch_count); -} - -void Dot11Beacon::quiet(uint8_t quiet_count, uint8_t quiet_period, uint16_t quiet_duration, uint16_t quiet_offset) { - Dot11ManagementFrame::quiet(quiet_count, quiet_period, quiet_duration, quiet_offset); -} - -void Dot11Beacon::ibss_dfs(const uint8_t* dfs_owner, - uint8_t recovery_interval, - const std::vector >& channel_map) { - Dot11ManagementFrame::ibss_dfs(dfs_owner, recovery_interval, channel_map); -} - -void Dot11Beacon::tpc_report(uint8_t transmit_power, uint8_t link_margin) { - Dot11ManagementFrame::tpc_report(transmit_power, link_margin); -} - -void Dot11Beacon::erp_information(uint8_t value) { - Dot11ManagementFrame::erp_information(value); -} - -void Dot11Beacon::extended_supported_rates(const std::list &new_rates) { - Dot11ManagementFrame::extended_supported_rates(new_rates); -} - -void Dot11Beacon::rsn_information(const RSNInformation& info) { - Dot11ManagementFrame::rsn_information(info); -} - -void Dot11Beacon::bss_load(uint16_t station_count, - uint8_t channel_utilization, - uint16_t available_capacity) { - Dot11ManagementFrame::bss_load(station_count, channel_utilization, available_capacity); -} - -void Dot11Beacon::edca_parameter_set(uint32_t ac_be, - uint32_t ac_bk, - uint32_t ac_vi, - uint32_t ac_vo) { - Dot11ManagementFrame::edca_parameter_set(ac_be, ac_bk, ac_vi, ac_vo); -} - -void Dot11Beacon::qos_capabilities(uint8_t qos_info) { - Dot11ManagementFrame::qos_capabilities(qos_info); -} - -string Dot11Beacon::essid() const { - const Dot11::Dot11Option *option = search_option(SSID); - return (option) ? string((const char*)option->value, option->length) : 0; -} - -bool Dot11Beacon::rsn_information(RSNInformation *rsn) { +bool Dot11ManagementFrame::rsn_information(RSNInformation *rsn) { const Dot11::Dot11Option *option = search_option(RSN); - if(!option || option->length < (sizeof(uint16_t) << 1) + sizeof(uint32_t)) + if(!option || option->data_size() < (sizeof(uint16_t) << 1) + sizeof(uint32_t)) return false; - const uint8_t *buffer = option->value; - uint32_t bytes_left = option->length; + const uint8_t *buffer = option->data_ptr(); + uint32_t bytes_left = option->data_size(); rsn->version(*(uint16_t*)buffer); buffer += sizeof(uint16_t); rsn->group_suite((RSNInformation::CypherSuites)*(uint32_t*)buffer); @@ -807,6 +628,98 @@ bool Dot11Beacon::rsn_information(RSNInformation *rsn) { return true; } +string Dot11ManagementFrame::ssid() const { + const Dot11::Dot11Option *option = search_option(SSID); + if(!option) + throw std::runtime_error("SSID not set"); + return string((const char*)option->data_ptr(), option->data_size()); +} + +Dot11ManagementFrame::rates_type Dot11ManagementFrame::supported_rates() const { + const Dot11::Dot11Option *option = search_option(SUPPORTED_RATES); + if(!option) + throw std::runtime_error("Supported rates not set"); + return deserialize_rates(option); +} + +Dot11ManagementFrame::rates_type Dot11ManagementFrame::extended_supported_rates() const { + const Dot11::Dot11Option *option = search_option(EXT_SUPPORTED_RATES); + if(!option) + throw std::runtime_error("Extended supported rates not set"); + return deserialize_rates(option); +} + +uint8_t Dot11ManagementFrame::qos_capability() const { + const Dot11::Dot11Option *option = search_option(QOS_CAPABILITY); + if(!option || option->data_size() != 1) + throw std::runtime_error("QOS capability not set"); + return *option->data_ptr(); +} + +std::pair Dot11ManagementFrame::power_capability() const { + const Dot11::Dot11Option *option = search_option(POWER_CAPABILITY); + if(!option || option->data_size() != 2) + throw std::runtime_error("Power capability not set"); + return std::make_pair(*option->data_ptr(), *(option->data_ptr() + 1)); +} + +Dot11ManagementFrame::channels_type Dot11ManagementFrame::supported_channels() const { + const Dot11::Dot11Option *option = search_option(SUPPORTED_CHANNELS); + // We need a multiple of two + if(!option || ((option->data_size() & 0x1) == 1)) + throw std::runtime_error("Supported channels not set"); + channels_type output; + const uint8_t *ptr = option->data_ptr(), *end = ptr + option->data_size(); + while(ptr != end) { + uint8_t first = *(ptr++); + output.push_back(std::make_pair(first, *(ptr++))); + } + return output; +} + +Dot11ManagementFrame::request_info_type Dot11ManagementFrame::request_information() const { + const Dot11::Dot11Option *option = search_option(REQUEST_INFORMATION); + if(!option) + throw std::runtime_error("Supported channels not set"); + request_info_type output; + const uint8_t *ptr = option->data_ptr(), *end = ptr + option->data_size(); + while(ptr != end) + output.push_back(*(ptr++)); + return output; +} + +/* Dot11Beacon */ + +Dot11Beacon::Dot11Beacon(const NetworkInterface& iface, + const address_type &dst_hw_addr, const address_type &src_hw_addr) +: Dot11ManagementFrame(iface, dst_hw_addr, src_hw_addr) +{ + subtype(Dot11::BEACON); + memset(&_body, 0, sizeof(_body)); +} + +Dot11Beacon::Dot11Beacon(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 beacon header in the buffer."); + memcpy(&_body, buffer, sizeof(_body)); + buffer += sizeof(_body); + total_sz -= sizeof(_body); + parse_tagged_parameters(buffer, total_sz); +} + +void Dot11Beacon::timestamp(uint64_t new_timestamp) { + this->_body.timestamp = Utils::host_to_le(new_timestamp); +} + +void Dot11Beacon::interval(uint16_t new_interval) { + this->_body.interval = Utils::host_to_le(new_interval); +} + uint32_t Dot11Beacon::header_size() const { return Dot11ManagementFrame::header_size() + sizeof(_body); } @@ -818,23 +731,8 @@ uint32_t Dot11Beacon::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) return sz; } -PDU *Dot11Beacon::clone_pdu() const { - Dot11Beacon *new_pdu = new Dot11Beacon(); - new_pdu->copy_80211_fields(this); - new_pdu->copy_ext_header(this); - std::memcpy(&new_pdu->_body, &_body, sizeof(_body)); - return new_pdu; -} - /* Diassoc */ -Dot11Disassoc::Dot11Disassoc(const address_type &dst_hw_addr, - const address_type &src_hw_addr) -: Dot11ManagementFrame(dst_hw_addr, src_hw_addr) { - subtype(Dot11::DISASSOC); - memset(&_body, 0, sizeof(_body)); -} - Dot11Disassoc::Dot11Disassoc(const NetworkInterface& iface, const address_type &dst_hw_addr, const address_type &src_hw_addr) : Dot11ManagementFrame(iface, dst_hw_addr, src_hw_addr){ @@ -880,14 +778,6 @@ PDU *Dot11Disassoc::clone_pdu() const { /* Assoc request. */ -Dot11AssocRequest::Dot11AssocRequest(const address_type &dst_hw_addr, - const address_type &src_hw_addr) -: Dot11ManagementFrame(dst_hw_addr, src_hw_addr) -{ - subtype(Dot11::ASSOC_REQ); - memset(&_body, 0, sizeof(_body)); -} - Dot11AssocRequest::Dot11AssocRequest(const NetworkInterface& iface, const address_type &dst_hw_addr, const address_type &src_hw_addr) : Dot11ManagementFrame(iface, dst_hw_addr, src_hw_addr) @@ -912,34 +802,6 @@ void Dot11AssocRequest::listen_interval(uint16_t new_listen_interval) { this->_body.listen_interval = new_listen_interval; } -void Dot11AssocRequest::ssid(const std::string &new_ssid) { - Dot11ManagementFrame::ssid(new_ssid); -} - -void Dot11AssocRequest::supported_rates(const std::list &new_rates) { - Dot11ManagementFrame::supported_rates(new_rates); -} - -void Dot11AssocRequest::extended_supported_rates(const std::list &new_rates) { - Dot11ManagementFrame::extended_supported_rates(new_rates); -} - -void Dot11AssocRequest::power_capabilities(uint8_t min_power, uint8_t max_power) { - Dot11ManagementFrame::power_capabilities(min_power, max_power); -} - -void Dot11AssocRequest::supported_channels(const std::list > &new_channels) { - Dot11ManagementFrame::supported_channels(new_channels); -} - -void Dot11AssocRequest::rsn_information(const RSNInformation& info) { - Dot11ManagementFrame::rsn_information(info); -} - -void Dot11AssocRequest::qos_capabilities(uint8_t new_qos_capabilities) { - Dot11ManagementFrame::qos_capabilities(new_qos_capabilities); -} - uint32_t Dot11AssocRequest::header_size() const { return Dot11ManagementFrame::header_size() + sizeof(AssocReqBody); } @@ -961,14 +823,6 @@ PDU *Dot11AssocRequest::clone_pdu() const { /* Assoc response. */ -Dot11AssocResponse::Dot11AssocResponse(const address_type &dst_hw_addr, - const address_type &src_hw_addr) -: Dot11ManagementFrame(dst_hw_addr, src_hw_addr) -{ - subtype(Dot11::ASSOC_RESP); - memset(&_body, 0, sizeof(_body)); -} - Dot11AssocResponse::Dot11AssocResponse(const NetworkInterface& iface, const address_type &dst_hw_addr, const address_type &src_hw_addr) : Dot11ManagementFrame(iface, dst_hw_addr, src_hw_addr) @@ -999,18 +853,6 @@ void Dot11AssocResponse::aid(uint16_t new_aid) { this->_body.aid = new_aid; } -void Dot11AssocResponse::supported_rates(const std::list &new_rates) { - Dot11ManagementFrame::supported_rates(new_rates); -} - -void Dot11AssocResponse::extended_supported_rates(const std::list &new_rates) { - Dot11ManagementFrame::extended_supported_rates(new_rates); -} - -void Dot11AssocResponse::edca_parameter_set(uint32_t ac_be, uint32_t ac_bk, uint32_t ac_vi, uint32_t ac_vo) { - Dot11ManagementFrame::edca_parameter_set(ac_be, ac_bk, ac_vi, ac_vo); -} - uint32_t Dot11AssocResponse::header_size() const { return Dot11ManagementFrame::header_size() + sizeof(AssocRespBody); } @@ -1032,14 +874,6 @@ PDU *Dot11AssocResponse::clone_pdu() const { /* ReAssoc request. */ -Dot11ReAssocRequest::Dot11ReAssocRequest(const address_type &dst_hw_addr, - const address_type &src_hw_addr) -: Dot11ManagementFrame(dst_hw_addr, src_hw_addr) -{ - this->subtype(Dot11::REASSOC_REQ); - memset(&_body, 0, sizeof(_body)); -} - Dot11ReAssocRequest::Dot11ReAssocRequest(const NetworkInterface& iface, const address_type &dst_hw_addr, const address_type &src_hw_addr) : Dot11ManagementFrame(iface, dst_hw_addr, src_hw_addr) @@ -1070,34 +904,6 @@ void Dot11ReAssocRequest::current_ap(uint8_t* new_current_ap) { memcpy(this->_body.current_ap, new_current_ap, 6); } -void Dot11ReAssocRequest::ssid(const std::string &new_ssid) { - Dot11ManagementFrame::ssid(new_ssid); -} - -void Dot11ReAssocRequest::supported_rates(const std::list &new_rates) { - Dot11ManagementFrame::supported_rates(new_rates); -} - -void Dot11ReAssocRequest::extended_supported_rates(const std::list &new_rates) { - Dot11ManagementFrame::extended_supported_rates(new_rates); -} - -void Dot11ReAssocRequest::power_capabilities(uint8_t min_power, uint8_t max_power) { - Dot11ManagementFrame::power_capabilities(min_power, max_power); -} - -void Dot11ReAssocRequest::supported_channels(const std::list > &new_channels) { - Dot11ManagementFrame::supported_channels(new_channels); -} - -void Dot11ReAssocRequest::rsn_information(const RSNInformation& info) { - Dot11ManagementFrame::rsn_information(info); -} - -void Dot11ReAssocRequest::qos_capabilities(uint8_t new_qos_capabilities) { - Dot11ManagementFrame::qos_capabilities(new_qos_capabilities); -} - uint32_t Dot11ReAssocRequest::header_size() const { return Dot11ManagementFrame::header_size() + sizeof(this->_body); } @@ -1119,14 +925,6 @@ PDU *Dot11ReAssocRequest::clone_pdu() const { /* ReAssoc response. */ -Dot11ReAssocResponse::Dot11ReAssocResponse(const address_type &dst_hw_addr, - const address_type &src_hw_addr) -: Dot11ManagementFrame(dst_hw_addr, src_hw_addr) -{ - this->subtype(Dot11::REASSOC_RESP); - memset(&_body, 0, sizeof(_body)); -} - Dot11ReAssocResponse::Dot11ReAssocResponse(const NetworkInterface& iface, const address_type &dst_hw_addr, const address_type &src_hw_addr) : Dot11ManagementFrame(iface, dst_hw_addr, src_hw_addr) @@ -1156,18 +954,6 @@ void Dot11ReAssocResponse::aid(uint16_t new_aid) { this->_body.aid = new_aid; } -void Dot11ReAssocResponse::supported_rates(const std::list &new_rates) { - Dot11ManagementFrame::supported_rates(new_rates); -} - -void Dot11ReAssocResponse::extended_supported_rates(const std::list &new_rates) { - Dot11ManagementFrame::extended_supported_rates(new_rates); -} - -void Dot11ReAssocResponse::edca_parameter_set(uint32_t ac_be, uint32_t ac_bk, uint32_t ac_vi, uint32_t ac_vo) { - Dot11ManagementFrame::edca_parameter_set(ac_be, ac_bk, ac_vi, ac_vo); -} - uint32_t Dot11ReAssocResponse::header_size() const { return Dot11ManagementFrame::header_size() + sizeof(this->_body); } @@ -1189,13 +975,6 @@ PDU *Dot11ReAssocResponse::clone_pdu() const { /* Probe Request */ -Dot11ProbeRequest::Dot11ProbeRequest(const address_type &dst_hw_addr, - const address_type &src_hw_addr) -: Dot11ManagementFrame(dst_hw_addr, src_hw_addr) -{ - this->subtype(Dot11::PROBE_REQ); -} - Dot11ProbeRequest::Dot11ProbeRequest(const NetworkInterface& iface, const address_type &dst_hw_addr, const address_type &src_hw_addr) : Dot11ManagementFrame(iface, dst_hw_addr, src_hw_addr) @@ -1209,22 +988,6 @@ Dot11ProbeRequest::Dot11ProbeRequest(const uint8_t *buffer, uint32_t total_sz) parse_tagged_parameters(buffer, total_sz); } -void Dot11ProbeRequest::ssid(const std::string &new_ssid) { - Dot11ManagementFrame::ssid(new_ssid); -} - -void Dot11ProbeRequest::supported_rates(const std::list &new_rates) { - Dot11ManagementFrame::supported_rates(new_rates); -} - -void Dot11ProbeRequest::request_information(const std::list elements) { - Dot11ManagementFrame::request_information(elements); -} - -void Dot11ProbeRequest::extended_supported_rates(const std::list &new_rates) { - Dot11ManagementFrame::extended_supported_rates(new_rates); -} - PDU* Dot11ProbeRequest::clone_pdu() const { Dot11ProbeRequest* new_pdu = new Dot11ProbeRequest(); new_pdu->copy_80211_fields(this); @@ -1234,14 +997,6 @@ PDU* Dot11ProbeRequest::clone_pdu() const { /* Probe Response */ -Dot11ProbeResponse::Dot11ProbeResponse(const address_type &dst_hw_addr, - const address_type &src_hw_addr) -: Dot11ManagementFrame(dst_hw_addr, src_hw_addr) -{ - this->subtype(Dot11::PROBE_RESP); - memset(&this->_body, 0, sizeof(this->_body)); -} - Dot11ProbeResponse::Dot11ProbeResponse(const NetworkInterface& iface, const address_type &dst_hw_addr, const address_type &src_hw_addr) : Dot11ManagementFrame(iface, dst_hw_addr, src_hw_addr) @@ -1272,96 +1027,6 @@ void Dot11ProbeResponse::interval(uint16_t new_interval) { this->_body.interval = new_interval; } -void Dot11ProbeResponse::ssid(const std::string &new_ssid) { - Dot11ManagementFrame::ssid(new_ssid); -} - -void Dot11ProbeResponse::supported_rates(const std::list &new_rates) { - Dot11ManagementFrame::supported_rates(new_rates); -} - -void Dot11ProbeResponse::fh_parameter_set(uint16_t dwell_time, uint8_t hop_set, uint8_t hop_pattern, uint8_t hop_index) { - Dot11ManagementFrame::fh_parameter_set(dwell_time, hop_set, hop_pattern, hop_index); -} - -void Dot11ProbeResponse::ds_parameter_set(uint8_t current_channel) { - Dot11ManagementFrame::ds_parameter_set(current_channel); -} - -void Dot11ProbeResponse::cf_parameter_set(uint8_t cfp_count, uint8_t cfp_period, uint16_t cfp_max_duration, uint16_t cfp_dur_remaining) { - Dot11ManagementFrame::cf_parameter_set(cfp_count, cfp_period, cfp_max_duration, cfp_dur_remaining); -} - -void Dot11ProbeResponse::ibss_parameter_set(uint16_t atim_window) { - Dot11ManagementFrame::ibss_parameter_set(atim_window); -} - -void Dot11ProbeResponse::country(const std::vector& countries, - const std::vector& first_channels, - const std::vector& number_channels, - const std::vector& max_power) { - Dot11ManagementFrame::country(countries, first_channels, number_channels, max_power); -} - -void Dot11ProbeResponse::fh_parameters(uint8_t prime_radix, uint8_t number_channels) { - Dot11ManagementFrame::fh_parameters(prime_radix, number_channels); -} - -void Dot11ProbeResponse::fh_pattern_table(uint8_t flag, - uint8_t number_of_sets, - uint8_t modulus, - uint8_t offset, - const std::vector& random_table) { - Dot11ManagementFrame::fh_pattern_table(flag, number_of_sets, modulus, offset, random_table); -} - -void Dot11ProbeResponse::power_constraint(uint8_t local_power_constraint) { - Dot11ManagementFrame::power_constraint(local_power_constraint); -} - -void Dot11ProbeResponse::channel_switch(uint8_t switch_mode, uint8_t new_channel, uint8_t switch_count) { - Dot11ManagementFrame::channel_switch(switch_mode, new_channel, switch_count); -} - -void Dot11ProbeResponse::quiet(uint8_t quiet_count, uint8_t quiet_period, uint16_t quiet_duration, uint16_t quiet_offset) { - Dot11ManagementFrame::quiet(quiet_count, quiet_period, quiet_duration, quiet_offset); -} - -void Dot11ProbeResponse::ibss_dfs(const uint8_t* dfs_owner, - uint8_t recovery_interval, - const std::vector >& channel_map) { - Dot11ManagementFrame::ibss_dfs(dfs_owner, recovery_interval, channel_map); -} - -void Dot11ProbeResponse::tpc_report(uint8_t transmit_power, uint8_t link_margin) { - Dot11ManagementFrame::tpc_report(transmit_power, link_margin); -} - -void Dot11ProbeResponse::erp_information(uint8_t value) { - Dot11ManagementFrame::erp_information(value); -} - -void Dot11ProbeResponse::extended_supported_rates(const std::list &new_rates) { - Dot11ManagementFrame::extended_supported_rates(new_rates); -} - -void Dot11ProbeResponse::rsn_information(const RSNInformation& info) { - Dot11ManagementFrame::rsn_information(info); -} - -void Dot11ProbeResponse::bss_load(uint16_t station_count, - uint8_t channel_utilization, - uint16_t available_capacity) { - Dot11ManagementFrame::bss_load(station_count, channel_utilization, available_capacity); -} - -void Dot11ProbeResponse::edca_parameter_set(uint32_t ac_be, - uint32_t ac_bk, - uint32_t ac_vi, - uint32_t ac_vo) { - Dot11ManagementFrame::edca_parameter_set(ac_be, ac_bk, ac_vi, ac_vo); -} - uint32_t Dot11ProbeResponse::header_size() const { return Dot11ManagementFrame::header_size() + sizeof(this->_body); } @@ -1383,14 +1048,6 @@ uint32_t Dot11ProbeResponse::write_fixed_parameters(uint8_t *buffer, uint32_t to /* Auth */ -Dot11Authentication::Dot11Authentication(const address_type &dst_hw_addr, - const address_type &src_hw_addr) -: Dot11ManagementFrame(dst_hw_addr, src_hw_addr) -{ - this->subtype(Dot11::AUTH); - memset(&_body, 0, sizeof(_body)); -} - 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) @@ -1425,10 +1082,6 @@ void Dot11Authentication::status_code(uint16_t new_status_code) { this->_body.status_code = new_status_code; } -void Dot11Authentication::challenge_text(uint8_t* ch_text, uint8_t ch_text_sz) { - Dot11ManagementFrame::challenge_text(ch_text, ch_text_sz); -} - uint32_t Dot11Authentication::header_size() const { return Dot11ManagementFrame::header_size() + sizeof(this->_body); } @@ -1450,14 +1103,6 @@ uint32_t Dot11Authentication::write_fixed_parameters(uint8_t *buffer, uint32_t t /* Deauth */ -Dot11Deauthentication::Dot11Deauthentication(const address_type &dst_hw_addr, - const address_type &src_hw_addr) -: Dot11ManagementFrame(dst_hw_addr, src_hw_addr) -{ - this->subtype(Dot11::DEAUTH); - memset(&_body, 0, sizeof(_body)); -} - 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) @@ -1525,14 +1170,6 @@ Dot11Data::Dot11Data(const uint8_t *buffer, uint32_t total_sz) inner_pdu(new Tins::SNAP(buffer, total_sz)); } -Dot11Data::Dot11Data(const address_type &dst_hw_addr, - const address_type &src_hw_addr, PDU* child) -: Dot11(dst_hw_addr, child) -{ - type(Dot11::DATA); - addr2(src_hw_addr); -} - Dot11Data::Dot11Data(const NetworkInterface &iface, const address_type &dst_hw_addr, const address_type &src_hw_addr, @@ -1596,13 +1233,6 @@ PDU *Dot11Data::clone_pdu() const { /* QoS data. */ -Dot11QoSData::Dot11QoSData(const address_type &dst_hw_addr, - const address_type &src_hw_addr, PDU* child) -: Dot11Data(dst_hw_addr, src_hw_addr, child) -{ - -} - Dot11QoSData::Dot11QoSData(const NetworkInterface &iface, const address_type &dst_hw_addr, const address_type &src_hw_addr, PDU* child) @@ -1666,12 +1296,6 @@ PDU *Dot11QoSData::clone_pdu() const { /* Dot11Control */ -Dot11Control::Dot11Control(const address_type &dst_addr, PDU* child) -: Dot11(dst_addr, child) -{ - type(CONTROL); -} - Dot11Control::Dot11Control(const NetworkInterface &iface, const address_type &dst_addr, PDU* child) : Dot11(iface, dst_addr, child) @@ -1685,12 +1309,6 @@ Dot11Control::Dot11Control(const uint8_t *buffer, uint32_t total_sz) } /* Dot11ControlTA */ -Dot11ControlTA::Dot11ControlTA(const address_type &dst_addr, - const address_type &target_address, PDU* child) -: Dot11Control(dst_addr, child) -{ - target_addr(target_address); -} Dot11ControlTA::Dot11ControlTA(const NetworkInterface &iface, const address_type &dst_addr, const address_type &target_address, PDU* child) @@ -1722,12 +1340,6 @@ void Dot11ControlTA::target_addr(const address_type &addr) { } /* Dot11RTS */ -Dot11RTS::Dot11RTS(const address_type &dst_addr , - const address_type &target_addr, PDU* child) -: Dot11ControlTA(dst_addr, target_addr, child) -{ - subtype(RTS); -} Dot11RTS::Dot11RTS(const NetworkInterface &iface, const address_type &dst_addr, const address_type &target_addr, PDU* child) @@ -1749,13 +1361,6 @@ PDU *Dot11RTS::clone_pdu() const { /* Dot11PSPoll */ -Dot11PSPoll::Dot11PSPoll(const address_type &dst_addr, - const address_type &target_addr, PDU* child) -: Dot11ControlTA(dst_addr, target_addr, child) -{ - subtype(PS); -} - Dot11PSPoll::Dot11PSPoll(const NetworkInterface &iface, const address_type &dst_addr, const address_type &target_addr, PDU* child) : Dot11ControlTA(iface, dst_addr, target_addr, child) @@ -1776,13 +1381,6 @@ PDU *Dot11PSPoll::clone_pdu() const { /* Dot11CFEnd */ -Dot11CFEnd::Dot11CFEnd(const address_type &dst_addr, - const address_type &target_addr, PDU* child) -: Dot11ControlTA(dst_addr, target_addr, child) -{ - subtype(CF_END); -} - Dot11CFEnd::Dot11CFEnd(const NetworkInterface &iface, const address_type &dst_addr, const address_type &target_addr, PDU* child) : Dot11ControlTA(iface, dst_addr, target_addr, child) @@ -1803,13 +1401,6 @@ PDU *Dot11CFEnd::clone_pdu() const { /* Dot11EndCFAck */ -Dot11EndCFAck::Dot11EndCFAck(const address_type &dst_addr, - const address_type &target_addr, PDU* child) -: Dot11ControlTA(dst_addr, target_addr, child) -{ - subtype(CF_END_ACK); -} - Dot11EndCFAck::Dot11EndCFAck(const NetworkInterface &iface, const address_type &dst_addr, const address_type &target_addr, PDU* child) : Dot11ControlTA(iface, dst_addr, target_addr, child) @@ -1830,12 +1421,6 @@ PDU *Dot11EndCFAck::clone_pdu() const { /* Dot11Ack */ -Dot11Ack::Dot11Ack(const address_type &dst_addr, PDU* child) -: Dot11Control(dst_addr, child) -{ - subtype(ACK); -} - Dot11Ack::Dot11Ack(const NetworkInterface &iface, const address_type &dst_addr, PDU* child) : Dot11Control(iface, dst_addr, child) @@ -1855,13 +1440,6 @@ PDU *Dot11Ack::clone_pdu() const { /* Dot11BlockAck */ -Dot11BlockAckRequest::Dot11BlockAckRequest( - const address_type &dst_addr , const address_type &target_addr, PDU* child) -: Dot11ControlTA(dst_addr, target_addr, child) -{ - init_block_ack(); -} - Dot11BlockAckRequest::Dot11BlockAckRequest(const NetworkInterface &iface, const address_type &dst_addr, const address_type &target_addr, PDU* child) : Dot11ControlTA(iface, dst_addr, target_addr, child) @@ -1914,13 +1492,6 @@ PDU *Dot11BlockAckRequest::clone_pdu() const { } /* Dot11BlockAck */ -Dot11BlockAck::Dot11BlockAck(const address_type &dst_addr, - const address_type &target_addr, PDU* child) -: Dot11ControlTA(dst_addr, target_addr, child) -{ - subtype(BLOCK_ACK); - std::memset(_bitmap, 0, sizeof(_bitmap)); -} Dot11BlockAck::Dot11BlockAck(const NetworkInterface &iface, const address_type &dst_addr, const address_type &target_addr, PDU* child) diff --git a/tests/include/tests/dot11.h b/tests/include/tests/dot11.h new file mode 100644 index 0000000..4e400ef --- /dev/null +++ b/tests/include/tests/dot11.h @@ -0,0 +1,21 @@ +#ifndef TINS_DOT11_TEST +#define TINS_DOT11_TEST + +#include "dot11.h" + +inline void test_equals(const Tins::Dot11 &dot1, const Tins::Dot11 &dot2) { + EXPECT_EQ(dot1.protocol(), dot2.protocol()); + EXPECT_EQ(dot1.type(), dot2.type()); + EXPECT_EQ(dot1.subtype(), dot2.subtype()); + EXPECT_EQ(dot1.to_ds(), dot2.to_ds()); + EXPECT_EQ(dot1.from_ds(), dot2.from_ds()); + EXPECT_EQ(dot1.more_frag(), dot2.more_frag()); + EXPECT_EQ(dot1.retry(), dot2.retry()); + EXPECT_EQ(dot1.power_mgmt(), dot2.power_mgmt()); + EXPECT_EQ(dot1.wep(), dot2.wep()); + EXPECT_EQ(dot1.order(), dot2.order()); + EXPECT_EQ(dot1.duration_id(), dot2.duration_id()); + EXPECT_EQ(dot1.addr1(), dot2.addr1()); +} + +#endif // TINS_DOT11_TEST diff --git a/tests/src/dot11/beacon.cpp b/tests/src/dot11/beacon.cpp new file mode 100644 index 0000000..b73021c --- /dev/null +++ b/tests/src/dot11/beacon.cpp @@ -0,0 +1,241 @@ +#include +#include +#include +#include +#include "dot11.h" +#include "tests/dot11.h" + + +using namespace std; +using namespace Tins; + +typedef Dot11::address_type address_type; +typedef Dot11Beacon::channels_type channels_type; + +class Dot11BeaconTest : 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 address_type Dot11BeaconTest::empty_addr, + Dot11BeaconTest::hwaddr("72:91:34:fa:de:ad"); + +const uint8_t Dot11BeaconTest::expected_packet[] = { + '\x81', '\x01', 'O', '#', '\x00', '\x01', '\x02', '\x03', '\x04', + '\x05', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x02', + '\x03', '\x04', '\x05', '\x06', '\x07', '\x00', '\x00', '\xfa', + '\x01', '\x93', '(', 'A', '#', '\xad', '\x1f', '\xfa', '\x14', + '\x95', ' ' +}; + +void Dot11BeaconTest::test_equals_expected(const Dot11Beacon &dot11) { + EXPECT_EQ(dot11.protocol(), 1); + EXPECT_EQ(dot11.type(), Dot11::MANAGEMENT); + EXPECT_EQ(dot11.subtype(), 8); + 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.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.timestamp(), 0x1fad2341289301faLL); + EXPECT_EQ(dot11.interval(), 0x14fa); + + const Dot11Beacon::CapabilityInformation &info = dot11.capabilities(); + EXPECT_EQ(info.ess(), 1); + EXPECT_EQ(info.ibss(), 0); + EXPECT_EQ(info.cf_poll(), 1); + EXPECT_EQ(info.cf_poll_req(), 0); + EXPECT_EQ(info.privacy(), 1); + EXPECT_EQ(info.short_preamble(), 0); + EXPECT_EQ(info.pbcc(), 0); + EXPECT_EQ(info.channel_agility(), 1); + 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(), 1); + EXPECT_EQ(info.delayed_block_ack(), 0); + EXPECT_EQ(info.immediate_block_ack(), 0); +} + +void test_equals(const Dot11Beacon& b1, const Dot11Beacon& 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()); + 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(static_cast(b1), static_cast(b2)); +} + +TEST_F(Dot11BeaconTest, DefaultConstructor) { + Dot11Beacon dot11; + EXPECT_EQ(dot11.addr2(), empty_addr); + EXPECT_EQ(dot11.addr3(), empty_addr); + EXPECT_EQ(dot11.addr4(), empty_addr); + EXPECT_EQ(dot11.frag_num(), 0); + EXPECT_EQ(dot11.seq_num(), 0); + + 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); + + EXPECT_EQ(dot11.interval(), 0); + EXPECT_EQ(dot11.timestamp(), 0); +} + +// beacon_interval=0x14fa, timestamp=0x1fad2341289301fa, cap="ESS+CFP+privacy+DSSS-OFDM" +TEST_F(Dot11BeaconTest, ConstructorFromBuffer) { + Dot11Beacon dot11(expected_packet, sizeof(expected_packet)); + test_equals_expected(dot11); +} + +TEST_F(Dot11BeaconTest, CopyConstructor) { + Dot11Beacon dot1(expected_packet, sizeof(expected_packet)); + Dot11Beacon dot2(dot1); + test_equals(dot1, dot2); +} + +TEST_F(Dot11BeaconTest, CopyAssignmentOperator) { + Dot11Beacon dot1(expected_packet, sizeof(expected_packet)); + Dot11Beacon dot2; + dot2 = dot1; + test_equals(dot1, dot2); +} + +TEST_F(Dot11BeaconTest, FromBytes) { + std::auto_ptr dot11(Dot11::from_bytes(expected_packet, sizeof(expected_packet))); + ASSERT_TRUE(dot11.get()); + const Dot11Beacon *beacon = dot11->find_inner_pdu(); + ASSERT_TRUE(beacon); + test_equals_expected(*beacon); +} + +TEST_F(Dot11BeaconTest, Timestamp) { + Dot11Beacon dot11; + dot11.timestamp(0x1fad2341289301faLL); + EXPECT_EQ(dot11.timestamp(), 0x1fad2341289301faLL); +} + +TEST_F(Dot11BeaconTest, Interval) { + Dot11Beacon dot11; + dot11.interval(0x14fa); + EXPECT_EQ(dot11.interval(), 0x14fa); +} + +TEST_F(Dot11BeaconTest, SSID) { + Dot11Beacon dot11; + dot11.ssid("libtins"); + EXPECT_EQ(dot11.ssid(), "libtins"); +} + +TEST_F(Dot11BeaconTest, SupportedRates) { + Dot11Beacon dot11; + Dot11Beacon::rates_type rates, found_rates; + rates.push_back(0.5f); + rates.push_back(1.0f); + rates.push_back(5.5f); + rates.push_back(7.5f); + dot11.supported_rates(rates); + found_rates = dot11.supported_rates(); + ASSERT_EQ(rates.size(), found_rates.size()); + EXPECT_TRUE(std::equal(rates.begin(), rates.end(), found_rates.begin())); +} + +TEST_F(Dot11BeaconTest, ExtendedSupportedRates) { + Dot11Beacon dot11; + Dot11Beacon::rates_type rates, found_rates; + rates.push_back(0.5f); + rates.push_back(1.0f); + rates.push_back(5.5f); + rates.push_back(7.5f); + dot11.extended_supported_rates(rates); + found_rates = dot11.extended_supported_rates(); + ASSERT_EQ(rates.size(), found_rates.size()); + EXPECT_TRUE(std::equal(rates.begin(), rates.end(), found_rates.begin())); +} + +TEST_F(Dot11BeaconTest, QOSCapability) { + Dot11Beacon dot11; + dot11.qos_capability(0xfa); + EXPECT_EQ(dot11.qos_capability(), 0xfa); +} + +TEST_F(Dot11BeaconTest, PowerCapability) { + typedef std::pair power_pair; + + Dot11Beacon dot11; + dot11.power_capability(0xfa, 0xa2); + power_pair power = dot11.power_capability(); + EXPECT_EQ(power.first, 0xfa); + EXPECT_EQ(power.second, 0xa2); +} + +TEST_F(Dot11BeaconTest, SupportedChannels) { + Dot11Beacon dot11; + channels_type channels, output; + channels.push_back(std::make_pair(13, 19)); + channels.push_back(std::make_pair(67, 159)); + dot11.supported_channels(channels); + output = dot11.supported_channels(); + ASSERT_EQ(output.size(), channels.size()); + EXPECT_TRUE(std::equal(channels.begin(), channels.end(), output.begin())); +} + +TEST_F(Dot11BeaconTest, RequestInformation) { + Dot11Beacon dot11; + Dot11Beacon::request_info_type info, found_info; + info.push_back(10); + info.push_back(15); + info.push_back(51); + info.push_back(42); + dot11.request_information(info); + found_info = dot11.request_information(); + ASSERT_EQ(info.size(), found_info.size()); + EXPECT_TRUE(std::equal(info.begin(), info.end(), found_info.begin())); +} diff --git a/tests/src/dot11/dot11.cpp b/tests/src/dot11/dot11.cpp new file mode 100644 index 0000000..e856ed4 --- /dev/null +++ b/tests/src/dot11/dot11.cpp @@ -0,0 +1,163 @@ +#include +#include +#include +#include +#include +#include "dot11.h" +#include "tests/dot11.h" +#include "utils.h" + +using namespace std; +using namespace Tins; + +typedef Dot11::address_type address_type; + +class Dot11Test : public testing::Test { +public: + static const address_type empty_addr, hwaddr; + static const uint8_t expected_packet[]; +}; + +const address_type Dot11Test::empty_addr, + Dot11Test::hwaddr("72:91:34:fa:de:ad"); + + +const uint8_t Dot11Test::expected_packet[] = { + '5', '\x01', 'O', '#', '\x00', '\x01', '\x02', '\x03', '\x04', '\x05' +}; + +TEST_F(Dot11Test, DefaultConstructor) { + Dot11 dot11; + EXPECT_EQ(dot11.protocol(), 0); + EXPECT_EQ(dot11.type(), 0); + EXPECT_EQ(dot11.subtype(), 0); + 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(Dot11Test, CopyConstructor) { + Dot11 dot1(expected_packet, sizeof(expected_packet)); + Dot11 dot2(dot1); + test_equals(dot1, dot2); +} + +TEST_F(Dot11Test, CopyAssignmentOperator) { + Dot11 dot1(expected_packet, sizeof(expected_packet)); + Dot11 dot2; + dot2 = dot1; + test_equals(dot1, dot2); +} + +//type="Control", subtype=3, proto=1, FCfield="to-DS", ID=0x234f, addr1="00:01:02:03:04:05") +TEST_F(Dot11Test, ConstructorFromBuffer) { + Dot11 dot11(expected_packet, sizeof(expected_packet)); + EXPECT_EQ(dot11.protocol(), 1); + EXPECT_EQ(dot11.type(), Dot11::CONTROL); + EXPECT_EQ(dot11.subtype(), 3); + 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.addr1(), "00:01:02:03:04:05"); +} + +TEST_F(Dot11Test, SrcAddrConstructor) { + Dot11 dot11("lo", hwaddr); + EXPECT_EQ(dot11.addr1(), hwaddr); +} + +TEST_F(Dot11Test, Protocol) { + Dot11 dot11; + dot11.protocol(1); + EXPECT_EQ(dot11.protocol(), 1); +} + +TEST_F(Dot11Test, Type) { + Dot11 dot11; + dot11.type(Dot11::CONTROL); + EXPECT_EQ(dot11.type(), Dot11::CONTROL); +} + +TEST_F(Dot11Test, Subtype) { + Dot11 dot11; + dot11.subtype(Dot11::QOS_DATA_DATA); + EXPECT_EQ(dot11.subtype(), Dot11::QOS_DATA_DATA); +} + +TEST_F(Dot11Test, ToDS) { + Dot11 dot11; + dot11.to_ds(true); + EXPECT_EQ(dot11.to_ds(), true); +} + +TEST_F(Dot11Test, FromDS) { + Dot11 dot11; + dot11.from_ds(true); + EXPECT_EQ(dot11.from_ds(), true); +} + +TEST_F(Dot11Test, MoreFrag) { + Dot11 dot11; + dot11.more_frag(1); + EXPECT_EQ(dot11.more_frag(), 1); +} + +TEST_F(Dot11Test, Retry) { + Dot11 dot11; + dot11.retry(1); + EXPECT_EQ(dot11.retry(), 1); +} + +TEST_F(Dot11Test, PowerMGMT) { + Dot11 dot11; + dot11.power_mgmt(1); + EXPECT_EQ(dot11.power_mgmt(), 1); +} + +TEST_F(Dot11Test, WEP) { + Dot11 dot11; + dot11.wep(1); + EXPECT_EQ(dot11.wep(), 1); +} + +TEST_F(Dot11Test, Order) { + Dot11 dot11; + dot11.order(1); + EXPECT_EQ(dot11.order(), 1); +} + +TEST_F(Dot11Test, DurationID) { + Dot11 dot11; + dot11.duration_id(0x7163); + EXPECT_EQ(dot11.duration_id(), 0x7163); +} + +TEST_F(Dot11Test, Addr1) { + Dot11 dot11; + dot11.addr1(hwaddr); + EXPECT_EQ(dot11.addr1(), hwaddr); +} + +TEST_F(Dot11Test, AddTaggedOption) { + Dot11 dot11; + dot11.add_tagged_option(Dot11::SSID, hwaddr.size(), hwaddr.begin()); + const Dot11::Dot11Option *option; + ASSERT_TRUE((option = dot11.search_option(Dot11::SSID))); + EXPECT_EQ(option->data_size(), hwaddr.size()); + EXPECT_EQ(option->option(), Dot11::SSID); + EXPECT_TRUE(std::equal(hwaddr.begin(), hwaddr.end(), option->data_ptr())); +} + + +