From 3500187e39a030839a787f111db411ffc8429972 Mon Sep 17 00:00:00 2001 From: Santiago Alessandri Date: Thu, 8 Sep 2011 11:25:55 -0300 Subject: [PATCH] Finished adding helpers. Finished beacon helpers --- include/dot11.h | 127 ++++++++++++++++++++++++++++++++++++++++++++++++ src/dot11.cpp | 94 +++++++++++++++++++++++++++++++++-- 2 files changed, 217 insertions(+), 4 deletions(-) diff --git a/include/dot11.h b/include/dot11.h index be6888f..518c165 100644 --- a/include/dot11.h +++ b/include/dot11.h @@ -1204,6 +1204,17 @@ namespace Tins { */ void bss_load(uint16_t station_count, uint8_t channel_utilization, uint16_t avaliable_capacity); + /** + * \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); + uint32_t write_ext_header(uint8_t *buffer, uint32_t total_sz); void copy_ext_header(const Dot11ManagementFrame *other); @@ -1338,6 +1349,103 @@ namespace Tins { */ 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. * @@ -1345,6 +1453,25 @@ namespace Tins { */ 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 search for the ESSID of this beacon. * diff --git a/src/dot11.cpp b/src/dot11.cpp index 3b0ad8f..2925779 100644 --- a/src/dot11.cpp +++ b/src/dot11.cpp @@ -591,6 +591,21 @@ void Tins::Dot11ManagementFrame::bss_load(uint16_t station_count, uint8_t channe add_tagged_option(BSS_LOAD, 5, buffer); } +void Tins::Dot11ManagementFrame::tim(uint8_t dtim_count, + uint8_t dtim_period, + uint8_t bitmap_control, + uint8_t* partial_virtual_bitmap, + uint8_t partial_virtual_bitmap_sz) { + + uint8_t sz = 3 + partial_virtual_bitmap_sz; + uint8_t* buffer = new uint8_t[sz]; + buffer[0] = dtim_count; + buffer[1] = dtim_period; + buffer[2] = bitmap_control; + memcpy(buffer + 3, partial_virtual_bitmap, partial_virtual_bitmap_sz); + add_tagged_option(TIM, sz, buffer); +} + /* Dot11Beacon */ Tins::Dot11Beacon::Dot11Beacon(const uint8_t* dst_hw_addr, const uint8_t* src_hw_addr) : Dot11ManagementFrame() { @@ -637,10 +652,6 @@ void Tins::Dot11Beacon::ds_parameter_set(uint8_t current_channel) { Dot11ManagementFrame::ds_parameter_set(current_channel); } -void Tins::Dot11Beacon::rsn_information(const RSNInformation& info) { - Dot11ManagementFrame::rsn_information(info); -} - void Tins::Dot11Beacon::fh_parameter_set(uint16_t dwell_time, uint8_t hop_set, uint8_t hop_pattern, @@ -659,6 +670,81 @@ void Tins::Dot11Beacon::ibss_parameter_set(uint16_t atim_window) { Dot11ManagementFrame::ibss_parameter_set(atim_window); } +void Tins::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 Tins::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 Tins::Dot11Beacon::fh_parameters(uint8_t prime_radix, uint8_t number_channels) { + Dot11ManagementFrame::fh_parameters(prime_radix, number_channels); +} + +void Tins::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 Tins::Dot11Beacon::power_constraint(uint8_t local_power_constraint) { + Dot11ManagementFrame::power_constraint(local_power_constraint); +} + +void Tins::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 Tins::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 Tins::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 Tins::Dot11Beacon::tpc_report(uint8_t transmit_power, uint8_t link_margin) { + Dot11ManagementFrame::tpc_report(transmit_power, link_margin); +} + +void Tins::Dot11Beacon::erp_information(uint8_t value) { + Dot11ManagementFrame::erp_information(value); +} + +void Tins::Dot11Beacon::extended_supported_rates(const std::list &new_rates) { + Dot11ManagementFrame::extended_supported_rates(new_rates); +} + +void Tins::Dot11Beacon::rsn_information(const RSNInformation& info) { + Dot11ManagementFrame::rsn_information(info); +} + +void Tins::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 Tins::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); +} + + string Tins::Dot11Beacon::essid() const { const Dot11::Dot11_Option *option = lookup_option(SSID); return (option) ? string((const char*)option->value, option->length) : 0;