diff --git a/include/ieee802-11.h b/include/ieee802-11.h index bfed646..8a2482b 100644 --- a/include/ieee802-11.h +++ b/include/ieee802-11.h @@ -753,6 +753,44 @@ namespace Tins { */ void group_suite(CypherSuites group); + /** + * \brief Sets the version. + * \param ver The version to be set. + */ + void version(uint16_t ver); + + /** + * \brief Sets the capabilities field. + * \param cap The capabilities to be set. + */ + void capabilities(uint16_t cap); + + /* Getters */ + + /** + * \brief Getter for the group suite field. + * \return The group suite field. + */ + inline CypherSuites group_suite() const { return _group_suite; } + + /** + * \brief Getter for the version field. + * \return The version field. + */ + inline uint16_t version() const { return _version; } + + /** + * \brief Getter for the pairwise cypher suite list. + * \return A list of pairwise cypher suites. + */ + inline const std::list &pairwise_cyphers() const { return _pairwise_cyphers; } + + /** + * \brief Getter for the akm suite list. + * \return A list of akm suites. + */ + inline const std::list &akm_cyphers() const { return _akm_cyphers; } + /** * \brief Serializes this object. * \param size Output parameter which will contain the size of @@ -1087,7 +1125,16 @@ namespace Tins { * 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. * diff --git a/src/ieee802-11.cpp b/src/ieee802-11.cpp index 2b3ba1a..e4c5ba2 100644 --- a/src/ieee802-11.cpp +++ b/src/ieee802-11.cpp @@ -22,6 +22,7 @@ #include #include #include +#include //borrame #ifndef WIN32 #include #include @@ -29,6 +30,8 @@ #endif #include "ieee802-11.h" #include "rawpdu.h" +#include "radiotap.h" +#include "sniffer.h" #include "utils.h" using namespace std; @@ -244,6 +247,8 @@ Tins::PDU *Tins::IEEE802_11::from_bytes(const uint8_t *buffer, uint32_t total_sz PDU *ret = 0; if(hdr->control.type == 0 && hdr->control.subtype == 8) ret = new IEEE802_11_Beacon(buffer, total_sz); + else + ret = new IEEE802_11(buffer, total_sz); return ret; } @@ -329,11 +334,52 @@ void Tins::IEEE802_11_Beacon::rsn_information(const RSNInformation& info) { delete[] buffer; } -std::string Tins::IEEE802_11_Beacon::essid() const { +string Tins::IEEE802_11_Beacon::essid() const { const IEEE802_11::IEEE802_11_Option *option = lookup_option(SSID); return (option) ? string((const char*)option->value, option->length) : 0; } +bool Tins::IEEE802_11_Beacon::rsn_information(RSNInformation *rsn) { + const IEEE802_11::IEEE802_11_Option *option = lookup_option(RSN); + if(!option || option->length < (sizeof(uint16_t) << 1) + sizeof(uint32_t)) + return false; + const uint8_t *buffer = option->value; + uint32_t bytes_left = option->length; + rsn->version(*(uint16_t*)buffer); + buffer += sizeof(uint16_t); + rsn->group_suite((RSNInformation::CypherSuites)*(uint32_t*)buffer); + buffer += sizeof(uint32_t); + + bytes_left -= (sizeof(uint16_t) << 1) + sizeof(uint32_t); + if(bytes_left < sizeof(uint16_t)) + return false; + uint16_t count = *(uint16_t*)buffer; + buffer += sizeof(uint16_t); + if(count * sizeof(uint32_t) > bytes_left) + return false; + bytes_left -= count * sizeof(uint32_t); + while(count--) { + rsn->add_pairwise_cypher((RSNInformation::CypherSuites)*(uint32_t*)buffer); + buffer += sizeof(uint32_t); + } + if(bytes_left < sizeof(uint16_t)) + return false; + count = *(uint16_t*)buffer; + buffer += sizeof(uint16_t); + bytes_left -= sizeof(uint16_t); + if(count * sizeof(uint32_t) > bytes_left) + return false; + bytes_left -= count * sizeof(uint32_t); + while(count--) { + rsn->add_akm_cypher((RSNInformation::AKMSuites)*(uint32_t*)buffer); + buffer += sizeof(uint32_t); + } + if(bytes_left < sizeof(uint16_t)) + return false; + rsn->capabilities(*(uint16_t*)buffer); + return true; +} + uint32_t Tins::IEEE802_11_Beacon::header_size() const { return IEEE802_11::header_size() + sizeof(BeaconBody); } @@ -391,6 +437,14 @@ void Tins::RSNInformation::group_suite(CypherSuites group) { _group_suite = group; } +void Tins::RSNInformation::version(uint16_t ver) { + _version = ver; +} + +void Tins::RSNInformation::capabilities(uint16_t cap) { + _capabilities = cap; +} + uint8_t *Tins::RSNInformation::serialize(uint32_t &size) const { size = sizeof(_version) + sizeof(_capabilities) + sizeof(uint32_t); size += (sizeof(uint16_t) << 1); // 2 lists count.