From 5222a1edd20bf71cd05e304c94a32038ce37c219 Mon Sep 17 00:00:00 2001 From: Santiago Alessandri Date: Tue, 6 Sep 2011 10:58:51 -0300 Subject: [PATCH 1/2] Added Dot11ProbeRequest --- include/dot11.h | 68 ++++++++++++++++++++++++++++++++++++++++++++++++- src/dot11.cpp | 44 ++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+), 1 deletion(-) diff --git a/include/dot11.h b/include/dot11.h index db3c687..0e2305d 100644 --- a/include/dot11.h +++ b/include/dot11.h @@ -1025,6 +1025,7 @@ namespace Tins { void power_capabilities(uint8_t min_power, uint8_t max_power); void supported_channels(const std::list > &new_channels); void edca_parameter_set(uint32_t ac_be, uint32_t ac_bk, uint32_t ac_vi, uint32_t ac_vo); + void request_information(const std::list elements); uint32_t write_ext_header(uint8_t *buffer, uint32_t total_sz); void copy_ext_header(const Dot11ManagementFrame *other); @@ -1944,6 +1945,71 @@ namespace Tins { }; + /** + * \brief Class representing an Probe Request frame in the IEEE 802.11 Protocol. + * + */ + class Dot11ProbeRequest : public Dot11ManagementFrame { + + public: + + /** + * \brief Default constructor for the Probe Request frame. + * + */ + Dot11ProbeRequest(); + + /** + * \brief Constructor for creating a 802.11 Probe Request. + * + * Constructor that builds a 802.11 Probe Request taking the interface name, + * destination's and source's MAC. + * + * \param iface string containing the interface's name from where to send the packet. + * \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 std::string& iface, const uint8_t* dst_hw_addr = 0, const uint8_t* src_hw_addr = 0) throw (std::runtime_error); + + /** + * \brief Constructor which creates a Dot11ProbeRequest 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. + */ + 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); + + }; + class Dot11QoSData : public Dot11DataFrame { public: @@ -2474,7 +2540,7 @@ namespace Tins { * \return The bar control field. */ uint16_t bar_control() const { return _bar_control.tid; } - + /** * \brief Getter for the start sequence field. * \return The bar start sequence. diff --git a/src/dot11.cpp b/src/dot11.cpp index a1ef762..1af615e 100644 --- a/src/dot11.cpp +++ b/src/dot11.cpp @@ -432,6 +432,18 @@ void Tins::Dot11ManagementFrame::edca_parameter_set(uint32_t ac_be, uint32_t ac_ delete[] buffer; } +void Tins::Dot11ManagementFrame::request_information(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); + delete[] buffer; +} + /* * Dot11DataFrame */ @@ -1048,6 +1060,38 @@ uint32_t Tins::Dot11ReAssocResponse::write_fixed_parameters(uint8_t *buffer, uin return sz; } +/* Probe Request */ + +Tins::Dot11ProbeRequest::Dot11ProbeRequest() : Dot11ManagementFrame() { + this->subtype(Dot11::PROBE_REQ); +} + +Tins::Dot11ProbeRequest::Dot11ProbeRequest(const std::string& iface, + const uint8_t* dst_hw_addr, + const uint8_t* src_hw_addr) throw (std::runtime_error) : Dot11ManagementFrame(iface, dst_hw_addr, src_hw_addr) { + this->subtype(Dot11::PROBE_REQ); +} + +Tins::Dot11ProbeRequest::Dot11ProbeRequest(const uint8_t *buffer, uint32_t total_sz) : Dot11ManagementFrame(buffer, total_sz) { + parse_tagged_parameters(buffer, total_sz); +} + +void Tins::Dot11ProbeRequest::ssid(const std::string &new_ssid) { + Dot11ManagementFrame::ssid(new_ssid); +} + +void Tins::Dot11ProbeRequest::supported_rates(const std::list &new_rates) { + Dot11ManagementFrame::supported_rates(new_rates); +} + +void Tins::Dot11ProbeRequest::request_information(const std::list elements) { + Dot11ManagementFrame::request_information(elements); +} + +void Tins::Dot11ProbeRequest::extended_supported_rates(const std::list &new_rates) { + Dot11ManagementFrame::extended_supported_rates(new_rates); +} + /* QoS data. */ Tins::Dot11QoSData::Dot11QoSData(const std::string& iface, const uint8_t* dst_hw_addr, const uint8_t* src_hw_addr, PDU* child) throw (std::runtime_error) : Dot11DataFrame(iface, dst_hw_addr, src_hw_addr, child) { From 26d791ee055202690e82683514d0c00be299c324 Mon Sep 17 00:00:00 2001 From: Santiago Alessandri Date: Wed, 7 Sep 2011 10:04:50 -0300 Subject: [PATCH 2/2] Added helper methods and Dot11ProbeResponse (still unfinished) --- include/dot11.h | 85 +++++++++++++++++++++++++- src/dot11.cpp | 155 +++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 237 insertions(+), 3 deletions(-) diff --git a/include/dot11.h b/include/dot11.h index 0e2305d..ee40657 100644 --- a/include/dot11.h +++ b/include/dot11.h @@ -62,7 +62,7 @@ namespace Tins { DS_SET, CF_SET, TIM, - BSS, + IBSS_SET, COUNTRY, HOPPING_PATTERN_PARAMS, HOPPING_PATTERN_TABLE, @@ -1026,6 +1026,19 @@ namespace Tins { void supported_channels(const std::list > &new_channels); void edca_parameter_set(uint32_t ac_be, uint32_t ac_bk, uint32_t ac_vi, uint32_t ac_vo); void request_information(const std::list elements); + void fh_parameter_set(uint16_t dwell_time, uint8_t hop_set, uint8_t hop_pattern, uint8_t hop_index); + void ds_parameter_set(uint8_t current_channel); + void cf_parameter_set(uint8_t cfp_count, uint8_t cfp_period, uint16_t cfp_max_duration, uint16_t cfp_dur_remaining); + void ibss_parameter_set(uint16_t atim_window); + void ibss_dfs(const uint8_t* dfs_owner, uint8_t recovery_interval, const std::vector >& channel_map); + void country(const std::vector& countries, const std::vector& first_channels, const std::vector& number_channels, const std::vector& max_power); + void fh_parameters(uint8_t prime_radix, uint8_t number_channels); + void fh_pattern_table(uint8_t flag, uint8_t number_of_sets, uint8_t modulus, uint8_t offset, const std::vector& random_table); + void power_constraint(uint8_t local_power_constraint); + void channel_switch(uint8_t switch_mode, uint8_t new_channel, uint8_t switch_count); + void quiet(uint8_t quiet_count, uint8_t quiet_period, uint16_t quiet_duration, uint16_t quiet_offset); + void tpc_report(uint8_t transmit_power, uint8_t link_margin); + uint32_t write_ext_header(uint8_t *buffer, uint32_t total_sz); void copy_ext_header(const Dot11ManagementFrame *other); @@ -2008,6 +2021,76 @@ namespace Tins { */ void request_information(const std::list elements); + /** + * \brief Clones this PDU. + * + * \sa PDU::clone_pdu() + */ + PDU* clone_pdu() const; + + }; + + /** + * \brief Class representing an Probe Response frame in the IEEE 802.11 Protocol. + * + */ + class Dot11ProbeResponse : public Dot11ManagementFrame { + + public: + + /** + * \brief Getter for the timestamp field. + * + * \return Timestamp value in an uint64_t. + */ + inline uint64_t timestamp() const { return this->_body.timestamp; } + + /** + * \brief Getter for the interval field. + * + * \return Timestamp value in an uint16_t. + */ + inline uint16_t interval() const { return Utils::net_to_host_s(this->_body.interval); } + + /** + * \brief Getter for the Capabilities Information. + * + * \return CapabilityInformation Structure in a CapabilityInformation&. + */ + inline const CapabilityInformation& capabilities() const { return this->_body.capability;} + + /** + * \brief Getter for the Capabilities Information. + * + * \return CapabilityInformation Structure in a CapabilityInformation&. + */ + inline CapabilityInformation& capabilities() { return this->_body.capability;} + + /** + * \brief Setter for the timestamp field. + * + * \param new_timestamp uint64_t with the timestamp to set. + */ + void timestamp(uint64_t new_timestamp); + + /** + * \brief Setter for the interval field. + * + * \param new_interval uint16_t with the interval to set. + */ + void interval(uint16_t new_interval); + + protected: + + private: + struct ProbeResp { + uint64_t timestamp; + uint16_t interval; + CapabilityInformation capability; + }; + + ProbeResp _body; + }; class Dot11QoSData : public Dot11DataFrame { diff --git a/src/dot11.cpp b/src/dot11.cpp index 1af615e..893a0f0 100644 --- a/src/dot11.cpp +++ b/src/dot11.cpp @@ -421,7 +421,7 @@ void Tins::Dot11ManagementFrame::supported_channels(const std::list elements) { @@ -444,6 +443,152 @@ void Tins::Dot11ManagementFrame::request_information(const std::list el delete[] buffer; } +void Tins::Dot11ManagementFrame::fh_parameter_set(uint16_t dwell_time, uint8_t hop_set, uint8_t hop_pattern, uint8_t hop_index) { + uint8_t buffer[5]; + uint16_t* ptr_buffer = (uint16_t*)buffer; + ptr_buffer[0] = dwell_time; + buffer[2] = hop_set; + buffer[3] = hop_pattern; + buffer[4] = hop_index; + add_tagged_option(FH_SET, 5, buffer); + +} + +void Tins::Dot11ManagementFrame::ds_parameter_set(uint8_t current_channel) { + add_tagged_option(DS_SET, 1, ¤t_channel); +} + +void Tins::Dot11ManagementFrame::cf_parameter_set(uint8_t cfp_count, + uint8_t cfp_period, + uint16_t cfp_max_duration, + uint16_t cfp_dur_remaining) { + uint8_t buffer[6]; + uint16_t* ptr_buffer = (uint16_t*)buffer; + buffer[0] = cfp_count; + buffer[1] = cfp_period; + ptr_buffer[1] = cfp_max_duration; + ptr_buffer[2] = cfp_dur_remaining; + add_tagged_option(CF_SET, 6, buffer); + +} + +void Tins::Dot11ManagementFrame::ibss_parameter_set(uint16_t atim_window) { + add_tagged_option(IBSS_SET, 2, (uint8_t*)&atim_window); +} + +void Tins::Dot11ManagementFrame::country(const std::vector& countries, + const std::vector& first_channels, + const std::vector& number_channels, + const std::vector& max_power) { + + /* Check that the lists have the same number of elements */ + if ((countries.size() != first_channels.size()) || + (countries.size() != number_channels.size()) || + (countries.size() != max_power.size())) + throw runtime_error("Lists should be of equal length!"); + + uint8_t sz = 6 * countries.size(); + if (sz & 1) // If size is odd, pad it + sz++; + uint8_t* buffer = new uint8_t[sz]; + uint8_t* ptr_buffer = buffer; + for (uint8_t i = 0; i < countries.size(); i++) { + memcpy(ptr_buffer, countries[i], 3); + ptr_buffer += 3; + *ptr_buffer = first_channels[i]; + ptr_buffer++; + *ptr_buffer = number_channels[i]; + ptr_buffer++; + *ptr_buffer = max_power[i]; + ptr_buffer++; + } + add_tagged_option(COUNTRY, sz, buffer); + delete[] buffer; + +} + +void Tins::Dot11ManagementFrame::fh_parameters(uint8_t prime_radix, uint8_t number_channels) { + uint8_t buffer[2]; + buffer[0] = prime_radix; + buffer[1] = number_channels; + add_tagged_option(HOPPING_PATTERN_PARAMS, 2, buffer); +} + +void Tins::Dot11ManagementFrame::fh_pattern_table(uint8_t flag, + uint8_t number_of_sets, + uint8_t modulus, + uint8_t offset, + const vector& random_table) { + + uint8_t sz = 4 + random_table.size(); + uint8_t* buffer = new uint8_t[sz]; + buffer[0] = flag; + buffer[1] = number_of_sets; + buffer[2] = modulus; + buffer[3] = offset; + uint8_t* ptr_buffer = &buffer[4]; + for (vector::const_iterator it = random_table.begin(); it != random_table.end(); it++) + *(ptr_buffer++) = *it; + add_tagged_option(HOPPING_PATTERN_TABLE, sz, buffer); + delete[] buffer; +} + +void Tins::Dot11ManagementFrame::power_constraint(uint8_t local_power_constraint) { + add_tagged_option(POWER_CONSTRAINT, 1, &local_power_constraint); +} + +void Tins::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; + buffer[2] = switch_count; + add_tagged_option(CHANNEL_SWITCH, 3, buffer); + +} + +void Tins::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; + + buffer[0] = quiet_count; + buffer[1] = quiet_period; + ptr_buffer[1] = quiet_duration; + ptr_buffer[2] = quiet_offset; + add_tagged_option(QUIET, 6, buffer); + +} + +void Tins::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; + + memcpy(ptr_buffer, dfs_owner, 6); + ptr_buffer += 6; + *(ptr_buffer++) = recovery_interval; + for (vector >::const_iterator it = channel_map.begin(); it != channel_map.end(); it++) { + *(ptr_buffer++) = it->first; + *(ptr_buffer++) = it->second; + } + + add_tagged_option(IBSS_DFS, sz, buffer); + + delete[] buffer; + +} + +void Tins::Dot11ManagementFrame::tpc_report(uint8_t transmit_power, uint8_t link_margin) { + + uint8_t buffer[2]; + buffer[0] = transmit_power; + buffer[1] = link_margin; + add_tagged_option(TPC_REPORT, 2, buffer); + +} + /* * Dot11DataFrame */ @@ -1092,6 +1237,12 @@ void Tins::Dot11ProbeRequest::extended_supported_rates(const std::list &n Dot11ManagementFrame::extended_supported_rates(new_rates); } +Tins::PDU* Tins::Dot11ProbeRequest::clone_pdu() const { + Dot11ProbeRequest* new_pdu = new Dot11ProbeRequest(); + new_pdu->copy_80211_fields(this); + return new_pdu; +} + /* QoS data. */ Tins::Dot11QoSData::Dot11QoSData(const std::string& iface, const uint8_t* dst_hw_addr, const uint8_t* src_hw_addr, PDU* child) throw (std::runtime_error) : Dot11DataFrame(iface, dst_hw_addr, src_hw_addr, child) {