/* * Copyright (c) 2012, Nasel * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following disclaimer * in the documentation and/or other materials provided with the * distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ #include #include #include #include #include #include "macros.h" #ifndef WIN32 #if defined(BSD) || defined(__APPLE__) #include #include #else #include #endif #include #include #endif #include "dot11.h" #include "rawpdu.h" #include "rsn_information.h" #include "packet_sender.h" #include "snap.h" using std::pair; using std::vector; using std::string; using std::list; 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(child), _options_size(0) { memset(&_header, 0, sizeof(ieee80211_header)); addr1(dst_hw_addr); } Dot11::Dot11(const ieee80211_header *header_ptr) { } Dot11::Dot11(const uint8_t *buffer, uint32_t total_sz) : _options_size(0) { if(total_sz < sizeof(_header)) throw runtime_error("Not enough size for an Dot11 header in the buffer."); std::memcpy(&_header, buffer, sizeof(_header)); } void Dot11::parse_tagged_parameters(const uint8_t *buffer, uint32_t total_sz) { if(total_sz > 0) { uint8_t opcode, length; while(total_sz >= 2) { opcode = buffer[0]; length = buffer[1]; buffer += 2; total_sz -= 2; if(length > total_sz) { throw std::runtime_error("Malformed option encountered"); } add_tagged_option((OptionTypes)opcode, length, buffer); buffer += length; total_sz -= length; } } } 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(option((uint8_t)opt, len, val)); _options_size += opt_size; } #if TINS_IS_CXX11 void Dot11::add_option(option &&opt) { internal_add_option(opt); _options.push_back(std::move(opt)); } #endif void Dot11::internal_add_option(const option &opt) { _options_size += opt.data_size() + sizeof(uint8_t) * 2; } void Dot11::add_option(const option &opt) { internal_add_option(opt); _options.push_back(opt); } 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