1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-27 04:11:35 +01:00

Modified some protocols' internal type names.

This commit is contained in:
Matias Fontanini
2013-04-09 15:40:58 -03:00
parent 20054e6c73
commit ae1e1c2ce2
22 changed files with 356 additions and 319 deletions

View File

@@ -90,37 +90,42 @@ void Dot11::parse_tagged_parameters(const uint8_t *buffer, uint32_t total_sz) {
if(length > total_sz) {
throw std::runtime_error("Malformed option encountered");
}
add_tagged_option((TaggedOption)opcode, length, buffer);
add_tagged_option((OptionTypes)opcode, length, buffer);
buffer += length;
total_sz -= length;
}
}
}
void Dot11::add_tagged_option(TaggedOption opt, uint8_t len, const uint8_t *val) {
void Dot11::add_tagged_option(OptionTypes opt, uint8_t len, const uint8_t *val) {
uint32_t opt_size = len + sizeof(uint8_t) * 2;
_options.push_back(dot11_option((uint8_t)opt, len, val));
_options.push_back(option((uint8_t)opt, len, val));
_options_size += opt_size;
}
#if TINS_IS_CXX11
void Dot11::add_tagged_option(dot11_option &&opt) {
void Dot11::add_option(option &&opt) {
internal_add_option(opt);
_options.push_back(std::move(opt));
}
#endif
void Dot11::internal_add_option(const dot11_option &opt) {
void Dot11::internal_add_option(const option &opt) {
_options_size += opt.data_size() + sizeof(uint8_t) * 2;
}
void Dot11::add_tagged_option(const dot11_option &opt) {
void Dot11::add_option(const option &opt) {
internal_add_option(opt);
_options.push_back(opt);
}
const Dot11::dot11_option *Dot11::search_option(TaggedOption opt) const {
for(std::list<dot11_option>::const_iterator it = _options.begin(); it != _options.end(); ++it)
void Dot11::add_tagged_option(const option &opt) {
internal_add_option(opt);
_options.push_back(opt);
}
const Dot11::option *Dot11::search_option(OptionTypes opt) const {
for(std::list<option>::const_iterator it = _options.begin(); it != _options.end(); ++it)
if(it->option() == (uint8_t)opt)
return &(*it);
return 0;
@@ -219,7 +224,7 @@ void Dot11::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *p
uint32_t child_len = write_fixed_parameters(buffer, total_sz - _options_size);
buffer += child_len;
assert(total_sz >= child_len + _options_size);
for(std::list<dot11_option>::const_iterator it = _options.begin(); it != _options.end(); ++it) {
for(std::list<option>::const_iterator it = _options.begin(); it != _options.end(); ++it) {
*(buffer++) = it->option();
*(buffer++) = it->length_field();
std::copy(it->data_ptr(), it->data_ptr() + it->data_size(), buffer);
@@ -377,9 +382,9 @@ uint8_t *Dot11ManagementFrame::serialize_rates(const rates_type &rates) {
return buffer;
}
Dot11ManagementFrame::rates_type Dot11ManagementFrame::deserialize_rates(const dot11_option *option) {
Dot11ManagementFrame::rates_type Dot11ManagementFrame::deserialize_rates(const option *opt) {
rates_type output;
const uint8_t *ptr = option->data_ptr(), *end = ptr + option->data_size();
const uint8_t *ptr = opt->data_ptr(), *end = ptr + opt->data_size();
while(ptr != end) {
output.push_back(float(*(ptr++) & 0x7f) / 2);
}
@@ -609,49 +614,49 @@ void Dot11ManagementFrame::challenge_text(const std::string &text) {
// Getters
RSNInformation Dot11ManagementFrame::rsn_information() {
const Dot11::dot11_option *option = search_option(RSN);
const Dot11::option *option = search_option(RSN);
if(!option || option->data_size() < (sizeof(uint16_t) << 1) + sizeof(uint32_t))
throw std::runtime_error("RSN information not set");
return RSNInformation(option->data_ptr(), option->data_size());
}
string Dot11ManagementFrame::ssid() const {
const Dot11::dot11_option *option = search_option(SSID);
const Dot11::option *option = search_option(SSID);
if(!option || option->data_size() == 0)
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::dot11_option *option = search_option(SUPPORTED_RATES);
const Dot11::option *option = search_option(SUPPORTED_RATES);
if(!option || option->data_size() == 0)
throw std::runtime_error("Supported rates not set");
return deserialize_rates(option);
}
Dot11ManagementFrame::rates_type Dot11ManagementFrame::extended_supported_rates() const {
const Dot11::dot11_option *option = search_option(EXT_SUPPORTED_RATES);
const Dot11::option *option = search_option(EXT_SUPPORTED_RATES);
if(!option || option->data_size() == 0)
throw std::runtime_error("Extended supported rates not set");
return deserialize_rates(option);
}
uint8_t Dot11ManagementFrame::qos_capability() const {
const Dot11::dot11_option *option = search_option(QOS_CAPABILITY);
const Dot11::option *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<uint8_t, uint8_t> Dot11ManagementFrame::power_capability() const {
const Dot11::dot11_option *option = search_option(POWER_CAPABILITY);
const Dot11::option *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::dot11_option *option = search_option(SUPPORTED_CHANNELS);
const Dot11::option *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");
@@ -665,7 +670,7 @@ Dot11ManagementFrame::channels_type Dot11ManagementFrame::supported_channels() c
}
Dot11ManagementFrame::request_info_type Dot11ManagementFrame::request_information() const {
const Dot11::dot11_option *option = search_option(REQUEST_INFORMATION);
const Dot11::option *option = search_option(REQUEST_INFORMATION);
if(!option || option->data_size() == 0)
throw std::runtime_error("Request information not set");
request_info_type output;
@@ -675,7 +680,7 @@ Dot11ManagementFrame::request_info_type Dot11ManagementFrame::request_informatio
}
Dot11ManagementFrame::fh_params_set Dot11ManagementFrame::fh_parameter_set() const {
const Dot11::dot11_option *option = search_option(FH_SET);
const Dot11::option *option = search_option(FH_SET);
if(!option || option->data_size() != sizeof(fh_params_set))
throw std::runtime_error("FH parameters set not set");
fh_params_set output = *reinterpret_cast<const fh_params_set*>(option->data_ptr());
@@ -687,21 +692,21 @@ Dot11ManagementFrame::fh_params_set Dot11ManagementFrame::fh_parameter_set() con
}
uint8_t Dot11ManagementFrame::ds_parameter_set() const {
const Dot11::dot11_option *option = search_option(DS_SET);
const Dot11::option *option = search_option(DS_SET);
if(!option || option->data_size() != sizeof(uint8_t))
throw std::runtime_error("DS parameters set not set");
return *option->data_ptr();
}
uint16_t Dot11ManagementFrame::ibss_parameter_set() const {
const Dot11::dot11_option *option = search_option(IBSS_SET);
const Dot11::option *option = search_option(IBSS_SET);
if(!option || option->data_size() != sizeof(uint16_t))
throw std::runtime_error("IBSS parameters set not set");
return Endian::le_to_host(*reinterpret_cast<const uint16_t*>(option->data_ptr()));
}
Dot11ManagementFrame::ibss_dfs_params Dot11ManagementFrame::ibss_dfs() const {
const Dot11::dot11_option *option = search_option(IBSS_DFS);
const Dot11::option *option = search_option(IBSS_DFS);
if(!option || option->data_size() < ibss_dfs_params::minimum_size)
throw std::runtime_error("IBSS DFS set not set");
ibss_dfs_params output;
@@ -719,7 +724,7 @@ Dot11ManagementFrame::ibss_dfs_params Dot11ManagementFrame::ibss_dfs() const {
}
Dot11ManagementFrame::country_params Dot11ManagementFrame::country() const {
const Dot11::dot11_option *option = search_option(COUNTRY);
const Dot11::option *option = search_option(COUNTRY);
if(!option || option->data_size() < country_params::minimum_size)
throw std::runtime_error("Country option not set");
country_params output;
@@ -737,7 +742,7 @@ Dot11ManagementFrame::country_params Dot11ManagementFrame::country() const {
}
std::pair<uint8_t, uint8_t> Dot11ManagementFrame::fh_parameters() const {
const Dot11::dot11_option *option = search_option(HOPPING_PATTERN_PARAMS);
const Dot11::option *option = search_option(HOPPING_PATTERN_PARAMS);
if(!option || option->data_size() != sizeof(uint8_t) * 2)
throw std::runtime_error("FH parameters option not set");
const uint8_t *ptr = option->data_ptr();
@@ -746,7 +751,7 @@ std::pair<uint8_t, uint8_t> Dot11ManagementFrame::fh_parameters() const {
}
Dot11ManagementFrame::fh_pattern_type Dot11ManagementFrame::fh_pattern_table() const {
const Dot11::dot11_option *option = search_option(HOPPING_PATTERN_TABLE);
const Dot11::option *option = search_option(HOPPING_PATTERN_TABLE);
if(!option || option->data_size() < fh_pattern_type::minimum_size)
throw std::runtime_error("FH pattern option not set");
fh_pattern_type output;
@@ -762,14 +767,14 @@ Dot11ManagementFrame::fh_pattern_type Dot11ManagementFrame::fh_pattern_table() c
}
uint8_t Dot11ManagementFrame::power_constraint() const {
const Dot11::dot11_option *option = search_option(POWER_CONSTRAINT);
const Dot11::option *option = search_option(POWER_CONSTRAINT);
if(!option || option->data_size() != 1)
throw std::runtime_error("Power constraint option not set");
return *option->data_ptr();
}
Dot11ManagementFrame::channel_switch_type Dot11ManagementFrame::channel_switch() const {
const Dot11::dot11_option *option = search_option(CHANNEL_SWITCH);
const Dot11::option *option = search_option(CHANNEL_SWITCH);
if(!option || option->data_size() != sizeof(uint8_t) * 3)
throw std::runtime_error("Channel switch option not set");
const uint8_t *ptr = option->data_ptr();
@@ -781,7 +786,7 @@ Dot11ManagementFrame::channel_switch_type Dot11ManagementFrame::channel_switch()
}
Dot11ManagementFrame::quiet_type Dot11ManagementFrame::quiet() const {
const Dot11::dot11_option *option = search_option(QUIET);
const Dot11::option *option = search_option(QUIET);
if(!option || option->data_size() != (sizeof(uint8_t) * 2 + sizeof(uint16_t) * 2))
throw std::runtime_error("Quiet option not set");
const uint8_t *ptr = option->data_ptr();
@@ -796,7 +801,7 @@ Dot11ManagementFrame::quiet_type Dot11ManagementFrame::quiet() const {
}
std::pair<uint8_t, uint8_t> Dot11ManagementFrame::tpc_report() const {
const Dot11::dot11_option *option = search_option(TPC_REPORT);
const Dot11::option *option = search_option(TPC_REPORT);
if(!option || option->data_size() != sizeof(uint8_t) * 2)
throw std::runtime_error("TPC Report option not set");
const uint8_t *ptr = option->data_ptr();
@@ -805,14 +810,14 @@ std::pair<uint8_t, uint8_t> Dot11ManagementFrame::tpc_report() const {
}
uint8_t Dot11ManagementFrame::erp_information() const {
const Dot11::dot11_option *option = search_option(ERP_INFORMATION);
const Dot11::option *option = search_option(ERP_INFORMATION);
if(!option || option->data_size() != sizeof(uint8_t))
throw std::runtime_error("ERP Information option not set");
return *option->data_ptr();
}
Dot11ManagementFrame::bss_load_type Dot11ManagementFrame::bss_load() const {
const Dot11::dot11_option *option = search_option(BSS_LOAD);
const Dot11::option *option = search_option(BSS_LOAD);
if(!option || option->data_size() != sizeof(uint8_t) + 2 * sizeof(uint16_t))
throw std::runtime_error("BSS Load option not set");
bss_load_type output;
@@ -825,7 +830,7 @@ Dot11ManagementFrame::bss_load_type Dot11ManagementFrame::bss_load() const {
}
Dot11ManagementFrame::tim_type Dot11ManagementFrame::tim() const {
const Dot11::dot11_option *option = search_option(TIM);
const Dot11::option *option = search_option(TIM);
if(!option || option->data_size() < 4 * sizeof(uint8_t))
throw std::runtime_error("TIM option not set");
const uint8_t *ptr = option->data_ptr(), *end = ptr + option->data_size();
@@ -840,7 +845,7 @@ Dot11ManagementFrame::tim_type Dot11ManagementFrame::tim() const {
}
std::string Dot11ManagementFrame::challenge_text() const {
const Dot11::dot11_option *option = search_option(CHALLENGE_TEXT);
const Dot11::option *option = search_option(CHALLENGE_TEXT);
if(!option || option->data_size() == 0)
throw std::runtime_error("Challenge text option not set");
return std::string(option->data_ptr(), option->data_ptr() + option->data_size());