mirror of
https://github.com/mfontanini/libtins
synced 2026-01-30 05:24:26 +01:00
Code cleanup and use same syntax on the entire project
Initial code cleanup More code cleanup Cleanup more code Cleanup Dot11 code Fix OSX build issue Cleanup examples Fix ref and pointer declaration syntax Fix braces
This commit is contained in:
@@ -37,168 +37,159 @@ using Tins::Memory::InputMemoryStream;
|
||||
using Tins::Memory::OutputMemoryStream;
|
||||
|
||||
namespace Tins {
|
||||
/* Diassoc */
|
||||
|
||||
Dot11Disassoc::Dot11Disassoc(const address_type &dst_hw_addr,
|
||||
const address_type &src_hw_addr)
|
||||
: Dot11ManagementFrame(dst_hw_addr, src_hw_addr), _body()
|
||||
{
|
||||
this->subtype(Dot11::DISASSOC);
|
||||
// Disassoc
|
||||
|
||||
Dot11Disassoc::Dot11Disassoc(const address_type& dst_hw_addr,
|
||||
const address_type& src_hw_addr)
|
||||
: Dot11ManagementFrame(dst_hw_addr, src_hw_addr), body_() {
|
||||
this->subtype(Dot11::DISASSOC);
|
||||
}
|
||||
|
||||
Dot11Disassoc::Dot11Disassoc(const uint8_t *buffer, uint32_t total_sz)
|
||||
Dot11Disassoc::Dot11Disassoc(const uint8_t* buffer, uint32_t total_sz)
|
||||
: Dot11ManagementFrame(buffer, total_sz) {
|
||||
InputMemoryStream stream(buffer, total_sz);
|
||||
stream.skip(management_frame_size());
|
||||
stream.read(_body);
|
||||
stream.read(body_);
|
||||
parse_tagged_parameters(stream);
|
||||
}
|
||||
|
||||
void Dot11Disassoc::reason_code(uint16_t new_reason_code) {
|
||||
this->_body.reason_code = Endian::host_to_le(new_reason_code);
|
||||
body_.reason_code = Endian::host_to_le(new_reason_code);
|
||||
}
|
||||
|
||||
uint32_t Dot11Disassoc::header_size() const {
|
||||
return Dot11ManagementFrame::header_size() + sizeof(DisassocBody);
|
||||
return Dot11ManagementFrame::header_size() + sizeof(body_);
|
||||
}
|
||||
|
||||
void Dot11Disassoc::write_fixed_parameters(OutputMemoryStream& stream) {
|
||||
stream.write(_body);
|
||||
stream.write(body_);
|
||||
}
|
||||
|
||||
/* Assoc request. */
|
||||
// Assoc request
|
||||
|
||||
Dot11AssocRequest::Dot11AssocRequest(const address_type &dst_hw_addr,
|
||||
const address_type &src_hw_addr)
|
||||
: Dot11ManagementFrame(dst_hw_addr, src_hw_addr), _body()
|
||||
{
|
||||
Dot11AssocRequest::Dot11AssocRequest(const address_type& dst_hw_addr,
|
||||
const address_type& src_hw_addr)
|
||||
: Dot11ManagementFrame(dst_hw_addr, src_hw_addr), body_() {
|
||||
subtype(Dot11::ASSOC_REQ);
|
||||
}
|
||||
|
||||
Dot11AssocRequest::Dot11AssocRequest(const uint8_t *buffer, uint32_t total_sz)
|
||||
: Dot11ManagementFrame(buffer, total_sz)
|
||||
{
|
||||
Dot11AssocRequest::Dot11AssocRequest(const uint8_t* buffer, uint32_t total_sz)
|
||||
: Dot11ManagementFrame(buffer, total_sz) {
|
||||
InputMemoryStream stream(buffer, total_sz);
|
||||
stream.skip(management_frame_size());
|
||||
stream.read(_body);
|
||||
stream.read(body_);
|
||||
parse_tagged_parameters(stream);
|
||||
}
|
||||
|
||||
void Dot11AssocRequest::listen_interval(uint16_t new_listen_interval) {
|
||||
this->_body.listen_interval = Endian::host_to_le(new_listen_interval);
|
||||
body_.listen_interval = Endian::host_to_le(new_listen_interval);
|
||||
}
|
||||
|
||||
uint32_t Dot11AssocRequest::header_size() const {
|
||||
return Dot11ManagementFrame::header_size() + sizeof(AssocReqBody);
|
||||
return Dot11ManagementFrame::header_size() + sizeof(body_);
|
||||
}
|
||||
|
||||
void Dot11AssocRequest::write_fixed_parameters(OutputMemoryStream& stream) {
|
||||
stream.write(_body);
|
||||
stream.write(body_);
|
||||
}
|
||||
|
||||
/* Assoc response. */
|
||||
// Assoc response
|
||||
|
||||
Dot11AssocResponse::Dot11AssocResponse(const address_type &dst_hw_addr,
|
||||
const address_type &src_hw_addr)
|
||||
: Dot11ManagementFrame(dst_hw_addr, src_hw_addr)
|
||||
{
|
||||
Dot11AssocResponse::Dot11AssocResponse(const address_type& dst_hw_addr,
|
||||
const address_type& src_hw_addr)
|
||||
: Dot11ManagementFrame(dst_hw_addr, src_hw_addr), body_() {
|
||||
subtype(Dot11::ASSOC_RESP);
|
||||
memset(&_body, 0, sizeof(_body));
|
||||
}
|
||||
|
||||
Dot11AssocResponse::Dot11AssocResponse(const uint8_t *buffer, uint32_t total_sz)
|
||||
: Dot11ManagementFrame(buffer, total_sz)
|
||||
{
|
||||
Dot11AssocResponse::Dot11AssocResponse(const uint8_t* buffer, uint32_t total_sz)
|
||||
: Dot11ManagementFrame(buffer, total_sz) {
|
||||
InputMemoryStream stream(buffer, total_sz);
|
||||
stream.skip(management_frame_size());
|
||||
stream.read(_body);
|
||||
stream.read(body_);
|
||||
parse_tagged_parameters(stream);
|
||||
}
|
||||
|
||||
void Dot11AssocResponse::status_code(uint16_t new_status_code) {
|
||||
this->_body.status_code = Endian::host_to_le(new_status_code);
|
||||
body_.status_code = Endian::host_to_le(new_status_code);
|
||||
}
|
||||
|
||||
void Dot11AssocResponse::aid(uint16_t new_aid) {
|
||||
this->_body.aid = Endian::host_to_le(new_aid);
|
||||
body_.aid = Endian::host_to_le(new_aid);
|
||||
}
|
||||
|
||||
uint32_t Dot11AssocResponse::header_size() const {
|
||||
return Dot11ManagementFrame::header_size() + sizeof(AssocRespBody);
|
||||
return Dot11ManagementFrame::header_size() + sizeof(body_);
|
||||
}
|
||||
|
||||
void Dot11AssocResponse::write_fixed_parameters(OutputMemoryStream& stream) {
|
||||
stream.write(_body);
|
||||
stream.write(body_);
|
||||
}
|
||||
|
||||
/* ReAssoc request. */
|
||||
// ReAssoc request
|
||||
|
||||
Dot11ReAssocRequest::Dot11ReAssocRequest(const address_type &dst_hw_addr,
|
||||
const address_type &src_hw_addr)
|
||||
: Dot11ManagementFrame(dst_hw_addr, src_hw_addr)
|
||||
{
|
||||
this->subtype(Dot11::REASSOC_REQ);
|
||||
memset(&_body, 0, sizeof(_body));
|
||||
Dot11ReAssocRequest::Dot11ReAssocRequest(const address_type& dst_hw_addr,
|
||||
const address_type& src_hw_addr)
|
||||
: Dot11ManagementFrame(dst_hw_addr, src_hw_addr), body_() {
|
||||
subtype(Dot11::REASSOC_REQ);
|
||||
}
|
||||
|
||||
Dot11ReAssocRequest::Dot11ReAssocRequest(const uint8_t *buffer, uint32_t total_sz)
|
||||
: Dot11ManagementFrame(buffer, total_sz)
|
||||
{
|
||||
Dot11ReAssocRequest::Dot11ReAssocRequest(const uint8_t* buffer, uint32_t total_sz)
|
||||
: Dot11ManagementFrame(buffer, total_sz) {
|
||||
InputMemoryStream stream(buffer, total_sz);
|
||||
stream.skip(management_frame_size());
|
||||
stream.read(_body);
|
||||
stream.read(body_);
|
||||
parse_tagged_parameters(stream);
|
||||
}
|
||||
|
||||
void Dot11ReAssocRequest::listen_interval(uint16_t new_listen_interval) {
|
||||
this->_body.listen_interval = Endian::host_to_le(new_listen_interval);
|
||||
body_.listen_interval = Endian::host_to_le(new_listen_interval);
|
||||
}
|
||||
|
||||
void Dot11ReAssocRequest::current_ap(const address_type &new_current_ap) {
|
||||
new_current_ap.copy(_body.current_ap);
|
||||
void Dot11ReAssocRequest::current_ap(const address_type& new_current_ap) {
|
||||
new_current_ap.copy(body_.current_ap);
|
||||
}
|
||||
|
||||
uint32_t Dot11ReAssocRequest::header_size() const {
|
||||
return Dot11ManagementFrame::header_size() + sizeof(this->_body);
|
||||
return Dot11ManagementFrame::header_size() + sizeof(body_);
|
||||
}
|
||||
|
||||
void Dot11ReAssocRequest::write_fixed_parameters(OutputMemoryStream& stream) {
|
||||
stream.write(_body);
|
||||
stream.write(body_);
|
||||
}
|
||||
|
||||
/* ReAssoc response. */
|
||||
// ReAssoc response
|
||||
|
||||
Dot11ReAssocResponse::Dot11ReAssocResponse(const address_type &dst_hw_addr,
|
||||
const address_type &src_hw_addr)
|
||||
: Dot11ManagementFrame(dst_hw_addr, src_hw_addr)
|
||||
{
|
||||
this->subtype(Dot11::REASSOC_RESP);
|
||||
memset(&_body, 0, sizeof(_body));
|
||||
Dot11ReAssocResponse::Dot11ReAssocResponse(const address_type& dst_hw_addr,
|
||||
const address_type& src_hw_addr)
|
||||
: Dot11ManagementFrame(dst_hw_addr, src_hw_addr), body_() {
|
||||
subtype(Dot11::REASSOC_RESP);
|
||||
}
|
||||
|
||||
Dot11ReAssocResponse::Dot11ReAssocResponse(const uint8_t *buffer, uint32_t total_sz)
|
||||
Dot11ReAssocResponse::Dot11ReAssocResponse(const uint8_t* buffer, uint32_t total_sz)
|
||||
: Dot11ManagementFrame(buffer, total_sz) {
|
||||
InputMemoryStream stream(buffer, total_sz);
|
||||
stream.skip(management_frame_size());
|
||||
stream.read(_body);
|
||||
stream.read(body_);
|
||||
parse_tagged_parameters(stream);
|
||||
}
|
||||
|
||||
void Dot11ReAssocResponse::status_code(uint16_t new_status_code) {
|
||||
this->_body.status_code = Endian::host_to_le(new_status_code);
|
||||
body_.status_code = Endian::host_to_le(new_status_code);
|
||||
}
|
||||
|
||||
void Dot11ReAssocResponse::aid(uint16_t new_aid) {
|
||||
this->_body.aid = Endian::host_to_le(new_aid);
|
||||
body_.aid = Endian::host_to_le(new_aid);
|
||||
}
|
||||
|
||||
uint32_t Dot11ReAssocResponse::header_size() const {
|
||||
return Dot11ManagementFrame::header_size() + sizeof(this->_body);
|
||||
return Dot11ManagementFrame::header_size() + sizeof(body_);
|
||||
}
|
||||
|
||||
void Dot11ReAssocResponse::write_fixed_parameters(OutputMemoryStream& stream) {
|
||||
stream.write(_body);
|
||||
stream.write(body_);
|
||||
}
|
||||
} // namespace Tins
|
||||
|
||||
} // Tins
|
||||
|
||||
#endif // HAVE_DOT11
|
||||
|
||||
@@ -37,74 +37,71 @@ using Tins::Memory::InputMemoryStream;
|
||||
using Tins::Memory::OutputMemoryStream;
|
||||
|
||||
namespace Tins {
|
||||
/* Auth */
|
||||
|
||||
Dot11Authentication::Dot11Authentication(const address_type &dst_hw_addr,
|
||||
const address_type &src_hw_addr)
|
||||
: Dot11ManagementFrame(dst_hw_addr, src_hw_addr)
|
||||
{
|
||||
this->subtype(Dot11::AUTH);
|
||||
memset(&_body, 0, sizeof(_body));
|
||||
// Auth
|
||||
|
||||
Dot11Authentication::Dot11Authentication(const address_type& dst_hw_addr,
|
||||
const address_type& src_hw_addr)
|
||||
: Dot11ManagementFrame(dst_hw_addr, src_hw_addr), body_() {
|
||||
subtype(Dot11::AUTH);
|
||||
}
|
||||
|
||||
Dot11Authentication::Dot11Authentication(const uint8_t *buffer, uint32_t total_sz)
|
||||
: Dot11ManagementFrame(buffer, total_sz)
|
||||
{
|
||||
Dot11Authentication::Dot11Authentication(const uint8_t* buffer, uint32_t total_sz)
|
||||
: Dot11ManagementFrame(buffer, total_sz) {
|
||||
InputMemoryStream stream(buffer, total_sz);
|
||||
stream.skip(management_frame_size());
|
||||
stream.read(_body);
|
||||
stream.read(body_);
|
||||
parse_tagged_parameters(stream);
|
||||
}
|
||||
|
||||
void Dot11Authentication::auth_algorithm(uint16_t new_auth_algorithm) {
|
||||
this->_body.auth_algorithm = Endian::host_to_le(new_auth_algorithm);
|
||||
body_.auth_algorithm = Endian::host_to_le(new_auth_algorithm);
|
||||
}
|
||||
|
||||
void Dot11Authentication::auth_seq_number(uint16_t new_auth_seq_number) {
|
||||
this->_body.auth_seq_number = Endian::host_to_le(new_auth_seq_number);
|
||||
body_.auth_seq_number = Endian::host_to_le(new_auth_seq_number);
|
||||
}
|
||||
|
||||
void Dot11Authentication::status_code(uint16_t new_status_code) {
|
||||
this->_body.status_code = Endian::host_to_le(new_status_code);
|
||||
body_.status_code = Endian::host_to_le(new_status_code);
|
||||
}
|
||||
|
||||
uint32_t Dot11Authentication::header_size() const {
|
||||
return Dot11ManagementFrame::header_size() + sizeof(_body);
|
||||
return Dot11ManagementFrame::header_size() + sizeof(body_);
|
||||
}
|
||||
|
||||
void Dot11Authentication::write_fixed_parameters(OutputMemoryStream& stream) {
|
||||
stream.write(_body);
|
||||
stream.write(body_);
|
||||
}
|
||||
|
||||
/* Deauth */
|
||||
// Deauth
|
||||
|
||||
Dot11Deauthentication::Dot11Deauthentication(const address_type &dst_hw_addr,
|
||||
const address_type &src_hw_addr)
|
||||
: Dot11ManagementFrame(dst_hw_addr, src_hw_addr)
|
||||
{
|
||||
this->subtype(Dot11::DEAUTH);
|
||||
memset(&_body, 0, sizeof(_body));
|
||||
Dot11Deauthentication::Dot11Deauthentication(const address_type& dst_hw_addr,
|
||||
const address_type& src_hw_addr)
|
||||
: Dot11ManagementFrame(dst_hw_addr, src_hw_addr), body_() {
|
||||
subtype(Dot11::DEAUTH);
|
||||
}
|
||||
|
||||
Dot11Deauthentication::Dot11Deauthentication(const uint8_t *buffer, uint32_t total_sz)
|
||||
Dot11Deauthentication::Dot11Deauthentication(const uint8_t* buffer, uint32_t total_sz)
|
||||
: Dot11ManagementFrame(buffer, total_sz) {
|
||||
InputMemoryStream stream(buffer, total_sz);
|
||||
stream.skip(management_frame_size());
|
||||
stream.read(_body);
|
||||
stream.read(body_);
|
||||
parse_tagged_parameters(stream);
|
||||
}
|
||||
|
||||
void Dot11Deauthentication::reason_code(uint16_t new_reason_code) {
|
||||
this->_body.reason_code = Endian::host_to_le(new_reason_code);
|
||||
body_.reason_code = Endian::host_to_le(new_reason_code);
|
||||
}
|
||||
|
||||
uint32_t Dot11Deauthentication::header_size() const {
|
||||
return Dot11ManagementFrame::header_size() + sizeof(this->_body);
|
||||
return Dot11ManagementFrame::header_size() + sizeof(body_);
|
||||
}
|
||||
|
||||
void Dot11Deauthentication::write_fixed_parameters(OutputMemoryStream& stream) {
|
||||
stream.write(_body);
|
||||
stream.write(body_);
|
||||
}
|
||||
} // namespace Tins
|
||||
|
||||
} // Tins
|
||||
|
||||
#endif // HAVE_DOT11
|
||||
|
||||
@@ -59,24 +59,23 @@ using Tins::Memory::InputMemoryStream;
|
||||
using Tins::Memory::OutputMemoryStream;
|
||||
|
||||
namespace Tins {
|
||||
|
||||
const Dot11::address_type Dot11::BROADCAST = "ff:ff:ff:ff:ff:ff";
|
||||
|
||||
Dot11::Dot11(const address_type &dst_hw_addr)
|
||||
: _header(), _options_size(0)
|
||||
{
|
||||
Dot11::Dot11(const address_type& dst_hw_addr)
|
||||
: header_(), options_size_(0) {
|
||||
addr1(dst_hw_addr);
|
||||
}
|
||||
|
||||
Dot11::Dot11(const ieee80211_header *header_ptr)
|
||||
{
|
||||
Dot11::Dot11(const dot11_header* header_ptr)
|
||||
: header_(), options_size_(0) {
|
||||
|
||||
}
|
||||
|
||||
Dot11::Dot11(const uint8_t *buffer, uint32_t total_sz)
|
||||
: _options_size(0)
|
||||
{
|
||||
Dot11::Dot11(const uint8_t* buffer, uint32_t total_sz)
|
||||
: options_size_(0) {
|
||||
InputMemoryStream stream(buffer, total_sz);
|
||||
stream.read(_header);
|
||||
stream.read(header_);
|
||||
}
|
||||
|
||||
void Dot11::parse_tagged_parameters(InputMemoryStream& stream) {
|
||||
@@ -93,104 +92,104 @@ void Dot11::parse_tagged_parameters(InputMemoryStream& stream) {
|
||||
}
|
||||
}
|
||||
|
||||
void Dot11::add_tagged_option(OptionTypes 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(option((uint8_t)opt, val, val + len));
|
||||
_options_size += opt_size;
|
||||
options_.push_back(option((uint8_t)opt, val, val + len));
|
||||
options_size_ += opt_size;
|
||||
}
|
||||
|
||||
void Dot11::internal_add_option(const option &opt) {
|
||||
_options_size += static_cast<uint32_t>(opt.data_size() + sizeof(uint8_t) * 2);
|
||||
void Dot11::internal_add_option(const option& opt) {
|
||||
options_size_ += static_cast<uint32_t>(opt.data_size() + sizeof(uint8_t) * 2);
|
||||
}
|
||||
|
||||
bool Dot11::remove_option(OptionTypes type) {
|
||||
options_type::iterator iter = search_option_iterator(type);
|
||||
if (iter == _options.end()) {
|
||||
if (iter == options_.end()) {
|
||||
return false;
|
||||
}
|
||||
_options_size -= static_cast<uint32_t>(iter->data_size() + sizeof(uint8_t) * 2);
|
||||
_options.erase(iter);
|
||||
options_size_ -= static_cast<uint32_t>(iter->data_size() + sizeof(uint8_t) * 2);
|
||||
options_.erase(iter);
|
||||
return true;
|
||||
}
|
||||
|
||||
void Dot11::add_option(const option &opt) {
|
||||
void Dot11::add_option(const option& opt) {
|
||||
internal_add_option(opt);
|
||||
_options.push_back(opt);
|
||||
options_.push_back(opt);
|
||||
}
|
||||
|
||||
const Dot11::option *Dot11::search_option(OptionTypes type) const {
|
||||
const Dot11::option* Dot11::search_option(OptionTypes type) const {
|
||||
// Search for the iterator. If we found something, return it, otherwise return nullptr.
|
||||
options_type::const_iterator iter = search_option_iterator(type);
|
||||
return (iter != _options.end()) ? &*iter : 0;
|
||||
return (iter != options_.end()) ? &*iter : 0;
|
||||
}
|
||||
|
||||
Dot11::options_type::const_iterator Dot11::search_option_iterator(OptionTypes type) const {
|
||||
Internals::option_type_equality_comparator<option> comparator(static_cast<uint8_t>(type));
|
||||
return find_if(_options.begin(), _options.end(), comparator);
|
||||
return find_if(options_.begin(), options_.end(), comparator);
|
||||
}
|
||||
|
||||
Dot11::options_type::iterator Dot11::search_option_iterator(OptionTypes type) {
|
||||
Internals::option_type_equality_comparator<option> comparator(static_cast<uint8_t>(type));
|
||||
return find_if(_options.begin(), _options.end(), comparator);
|
||||
return find_if(options_.begin(), options_.end(), comparator);
|
||||
}
|
||||
|
||||
void Dot11::protocol(small_uint<2> new_proto) {
|
||||
this->_header.control.protocol = new_proto;
|
||||
header_.control.protocol = new_proto;
|
||||
}
|
||||
|
||||
void Dot11::type(small_uint<2> new_type) {
|
||||
this->_header.control.type = new_type;
|
||||
header_.control.type = new_type;
|
||||
}
|
||||
|
||||
void Dot11::subtype(small_uint<4> new_subtype) {
|
||||
this->_header.control.subtype = new_subtype;
|
||||
header_.control.subtype = new_subtype;
|
||||
}
|
||||
|
||||
void Dot11::to_ds(small_uint<1> new_value) {
|
||||
this->_header.control.to_ds = (new_value)? 1 : 0;
|
||||
header_.control.to_ds = (new_value)? 1 : 0;
|
||||
}
|
||||
|
||||
void Dot11::from_ds(small_uint<1> new_value) {
|
||||
this->_header.control.from_ds = (new_value)? 1 : 0;
|
||||
header_.control.from_ds = (new_value)? 1 : 0;
|
||||
}
|
||||
|
||||
void Dot11::more_frag(small_uint<1> new_value) {
|
||||
this->_header.control.more_frag = (new_value)? 1 : 0;
|
||||
header_.control.more_frag = (new_value)? 1 : 0;
|
||||
}
|
||||
|
||||
void Dot11::retry(small_uint<1> new_value) {
|
||||
this->_header.control.retry = (new_value)? 1 : 0;
|
||||
header_.control.retry = (new_value)? 1 : 0;
|
||||
}
|
||||
|
||||
void Dot11::power_mgmt(small_uint<1> new_value) {
|
||||
this->_header.control.power_mgmt = (new_value)? 1 : 0;
|
||||
header_.control.power_mgmt = (new_value)? 1 : 0;
|
||||
}
|
||||
|
||||
void Dot11::wep(small_uint<1> new_value) {
|
||||
this->_header.control.wep = (new_value)? 1 : 0;
|
||||
header_.control.wep = (new_value)? 1 : 0;
|
||||
}
|
||||
|
||||
void Dot11::order(small_uint<1> new_value) {
|
||||
this->_header.control.order = (new_value)? 1 : 0;
|
||||
header_.control.order = (new_value)? 1 : 0;
|
||||
}
|
||||
|
||||
void Dot11::duration_id(uint16_t new_duration_id) {
|
||||
this->_header.duration_id = Endian::host_to_le(new_duration_id);
|
||||
header_.duration_id = Endian::host_to_le(new_duration_id);
|
||||
}
|
||||
|
||||
void Dot11::addr1(const address_type &new_addr1) {
|
||||
std::copy(new_addr1.begin(), new_addr1.end(), _header.addr1);
|
||||
void Dot11::addr1(const address_type& new_addr1) {
|
||||
new_addr1.copy(header_.addr1);
|
||||
}
|
||||
|
||||
uint32_t Dot11::header_size() const {
|
||||
uint32_t sz = sizeof(ieee80211_header) + _options_size;
|
||||
return sz;
|
||||
return sizeof(header_) + options_size_;
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
void Dot11::send(PacketSender &sender, const NetworkInterface &iface) {
|
||||
if(!iface)
|
||||
void Dot11::send(PacketSender& sender, const NetworkInterface& iface) {
|
||||
if (!iface) {
|
||||
throw invalid_interface();
|
||||
}
|
||||
|
||||
#if !defined(BSD) && !defined(__FreeBSD_kernel__)
|
||||
sockaddr_ll addr;
|
||||
@@ -201,7 +200,7 @@ void Dot11::send(PacketSender &sender, const NetworkInterface &iface) {
|
||||
addr.sll_protocol = Endian::host_to_be<uint16_t>(ETH_P_ALL);
|
||||
addr.sll_halen = 6;
|
||||
addr.sll_ifindex = iface.id();
|
||||
memcpy(&(addr.sll_addr), _header.addr1, 6);
|
||||
memcpy(&(addr.sll_addr), header_.addr1, 6);
|
||||
sender.send_l2(*this, (struct sockaddr*)&addr, (uint32_t)sizeof(addr));
|
||||
#else
|
||||
sender.send_l2(*this, 0, 0, iface);
|
||||
@@ -209,74 +208,84 @@ void Dot11::send(PacketSender &sender, const NetworkInterface &iface) {
|
||||
}
|
||||
#endif // _WIN32
|
||||
|
||||
void Dot11::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent) {
|
||||
void Dot11::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU* parent) {
|
||||
OutputMemoryStream stream(buffer, total_sz);
|
||||
stream.write(_header);
|
||||
stream.write(header_);
|
||||
write_ext_header(stream);
|
||||
write_fixed_parameters(stream);
|
||||
for (std::list<option>::const_iterator it = _options.begin(); it != _options.end(); ++it) {
|
||||
for (std::list<option>::const_iterator it = options_.begin(); it != options_.end(); ++it) {
|
||||
stream.write<uint8_t>(it->option());
|
||||
stream.write<uint8_t>(it->length_field());
|
||||
stream.write(it->data_ptr(), it->data_size());
|
||||
}
|
||||
}
|
||||
|
||||
Dot11 *Dot11::from_bytes(const uint8_t *buffer, uint32_t total_sz) {
|
||||
Dot11* Dot11::from_bytes(const uint8_t* buffer, uint32_t total_sz) {
|
||||
// We only need the control field, the length of the PDU will depend on the flags set.
|
||||
|
||||
// This should be sizeof(ieee80211_header::control), but gcc 4.2 complains
|
||||
if(total_sz < 2)
|
||||
// This should be sizeof(dot11_header::control), but gcc 4.2 complains
|
||||
if (total_sz < 2) {
|
||||
throw malformed_packet();
|
||||
const ieee80211_header *hdr = (const ieee80211_header*)buffer;
|
||||
Dot11 *ret = 0;
|
||||
if(hdr->control.type == MANAGEMENT) {
|
||||
if(hdr->control.subtype == BEACON)
|
||||
ret = new Dot11Beacon(buffer, total_sz);
|
||||
else if(hdr->control.subtype == DISASSOC)
|
||||
ret = new Dot11Disassoc(buffer, total_sz);
|
||||
else if(hdr->control.subtype == ASSOC_REQ)
|
||||
ret = new Dot11AssocRequest(buffer, total_sz);
|
||||
else if(hdr->control.subtype == ASSOC_RESP)
|
||||
ret = new Dot11AssocResponse(buffer, total_sz);
|
||||
else if(hdr->control.subtype == REASSOC_REQ)
|
||||
ret = new Dot11ReAssocRequest(buffer, total_sz);
|
||||
else if(hdr->control.subtype == REASSOC_RESP)
|
||||
ret = new Dot11ReAssocResponse(buffer, total_sz);
|
||||
else if(hdr->control.subtype == AUTH)
|
||||
ret = new Dot11Authentication(buffer, total_sz);
|
||||
else if(hdr->control.subtype == DEAUTH)
|
||||
ret = new Dot11Deauthentication(buffer, total_sz);
|
||||
else if(hdr->control.subtype == PROBE_REQ)
|
||||
ret = new Dot11ProbeRequest(buffer, total_sz);
|
||||
else if(hdr->control.subtype == PROBE_RESP)
|
||||
ret = new Dot11ProbeResponse(buffer, total_sz);
|
||||
}
|
||||
else if(hdr->control.type == DATA){
|
||||
if(hdr->control.subtype <= 4)
|
||||
ret = new Dot11Data(buffer, total_sz);
|
||||
else
|
||||
ret = new Dot11QoSData(buffer, total_sz);
|
||||
const dot11_header* hdr = (const dot11_header*)buffer;
|
||||
if (hdr->control.type == MANAGEMENT) {
|
||||
switch (hdr->control.subtype) {
|
||||
case BEACON:
|
||||
return new Dot11Beacon(buffer, total_sz);
|
||||
case DISASSOC:
|
||||
return new Dot11Disassoc(buffer, total_sz);
|
||||
case ASSOC_REQ:
|
||||
return new Dot11AssocRequest(buffer, total_sz);
|
||||
case ASSOC_RESP:
|
||||
return new Dot11AssocResponse(buffer, total_sz);
|
||||
case REASSOC_REQ:
|
||||
return new Dot11ReAssocRequest(buffer, total_sz);
|
||||
case REASSOC_RESP:
|
||||
return new Dot11ReAssocResponse(buffer, total_sz);
|
||||
case AUTH:
|
||||
return new Dot11Authentication(buffer, total_sz);
|
||||
case DEAUTH:
|
||||
return new Dot11Deauthentication(buffer, total_sz);
|
||||
case PROBE_REQ:
|
||||
return new Dot11ProbeRequest(buffer, total_sz);
|
||||
case PROBE_RESP:
|
||||
return new Dot11ProbeResponse(buffer, total_sz);
|
||||
default:
|
||||
break;
|
||||
};
|
||||
}
|
||||
else if(hdr->control.type == CONTROL){
|
||||
if(hdr->control.subtype == ACK)
|
||||
ret = new Dot11Ack(buffer, total_sz);
|
||||
else if(hdr->control.subtype == CF_END)
|
||||
ret = new Dot11CFEnd(buffer, total_sz);
|
||||
else if(hdr->control.subtype == CF_END_ACK)
|
||||
ret = new Dot11EndCFAck(buffer, total_sz);
|
||||
else if(hdr->control.subtype == PS)
|
||||
ret = new Dot11PSPoll(buffer, total_sz);
|
||||
else if(hdr->control.subtype == RTS)
|
||||
ret = new Dot11RTS(buffer, total_sz);
|
||||
else if(hdr->control.subtype == BLOCK_ACK)
|
||||
ret = new Dot11BlockAck(buffer, total_sz);
|
||||
else if(hdr->control.subtype == BLOCK_ACK_REQ)
|
||||
ret = new Dot11BlockAckRequest(buffer, total_sz);
|
||||
else if (hdr->control.type == DATA) {
|
||||
if (hdr->control.subtype <= 4) {
|
||||
return new Dot11Data(buffer, total_sz);
|
||||
}
|
||||
else {
|
||||
return new Dot11QoSData(buffer, total_sz);
|
||||
}
|
||||
}
|
||||
if(ret == 0)
|
||||
ret = new Dot11(buffer, total_sz);
|
||||
return ret;
|
||||
else if (hdr->control.type == CONTROL) {
|
||||
switch (hdr->control.subtype) {
|
||||
case ACK:
|
||||
return new Dot11Ack(buffer, total_sz);
|
||||
case CF_END:
|
||||
return new Dot11CFEnd(buffer, total_sz);
|
||||
case CF_END_ACK:
|
||||
return new Dot11EndCFAck(buffer, total_sz);
|
||||
case PS:
|
||||
return new Dot11PSPoll(buffer, total_sz);
|
||||
case RTS:
|
||||
return new Dot11RTS(buffer, total_sz);
|
||||
case BLOCK_ACK:
|
||||
return new Dot11BlockAck(buffer, total_sz);
|
||||
case BLOCK_ACK_REQ:
|
||||
return new Dot11BlockAckRequest(buffer, total_sz);
|
||||
default:
|
||||
break;
|
||||
};
|
||||
}
|
||||
// Fallback to just building a dot11
|
||||
return new Dot11(buffer, total_sz);
|
||||
}
|
||||
} // namespace Tins
|
||||
|
||||
} // Tins
|
||||
|
||||
#endif // HAVE_DOT11
|
||||
|
||||
@@ -37,40 +37,39 @@ using Tins::Memory::InputMemoryStream;
|
||||
using Tins::Memory::OutputMemoryStream;
|
||||
|
||||
namespace Tins {
|
||||
/* Dot11Beacon */
|
||||
|
||||
Dot11Beacon::Dot11Beacon(const address_type &dst_hw_addr,
|
||||
const address_type &src_hw_addr)
|
||||
: Dot11ManagementFrame(dst_hw_addr, src_hw_addr)
|
||||
{
|
||||
// Dot11Beacon
|
||||
|
||||
Dot11Beacon::Dot11Beacon(const address_type& dst_hw_addr,
|
||||
const address_type& src_hw_addr)
|
||||
: Dot11ManagementFrame(dst_hw_addr, src_hw_addr), body_() {
|
||||
subtype(Dot11::BEACON);
|
||||
std::memset(&_body, 0, sizeof(_body));
|
||||
}
|
||||
|
||||
Dot11Beacon::Dot11Beacon(const uint8_t *buffer, uint32_t total_sz)
|
||||
: Dot11ManagementFrame(buffer, total_sz)
|
||||
{
|
||||
Dot11Beacon::Dot11Beacon(const uint8_t* buffer, uint32_t total_sz)
|
||||
: Dot11ManagementFrame(buffer, total_sz) {
|
||||
InputMemoryStream stream(buffer, total_sz);
|
||||
stream.skip(management_frame_size());
|
||||
stream.read(_body);
|
||||
stream.read(body_);
|
||||
parse_tagged_parameters(stream);
|
||||
}
|
||||
|
||||
void Dot11Beacon::timestamp(uint64_t new_timestamp) {
|
||||
this->_body.timestamp = Endian::host_to_le(new_timestamp);
|
||||
body_.timestamp = Endian::host_to_le(new_timestamp);
|
||||
}
|
||||
|
||||
void Dot11Beacon::interval(uint16_t new_interval) {
|
||||
this->_body.interval = Endian::host_to_le(new_interval);
|
||||
body_.interval = Endian::host_to_le(new_interval);
|
||||
}
|
||||
|
||||
uint32_t Dot11Beacon::header_size() const {
|
||||
return Dot11ManagementFrame::header_size() + sizeof(_body);
|
||||
return Dot11ManagementFrame::header_size() + sizeof(body_);
|
||||
}
|
||||
|
||||
void Dot11Beacon::write_fixed_parameters(OutputMemoryStream& stream) {
|
||||
stream.write(_body);
|
||||
stream.write(body_);
|
||||
}
|
||||
} // namespace Tins
|
||||
|
||||
} // Tins
|
||||
|
||||
#endif // HAVE_DOT11
|
||||
|
||||
@@ -30,237 +30,225 @@
|
||||
#include "dot11/dot11_control.h"
|
||||
#ifdef HAVE_DOT11
|
||||
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
#include "memory_helpers.h"
|
||||
|
||||
using std::copy;
|
||||
|
||||
using Tins::Memory::InputMemoryStream;
|
||||
using Tins::Memory::OutputMemoryStream;
|
||||
|
||||
namespace Tins {
|
||||
/* Dot11Control */
|
||||
|
||||
Dot11Control::Dot11Control(const address_type &dst_addr)
|
||||
: Dot11(dst_addr)
|
||||
{
|
||||
// Dot11Control
|
||||
|
||||
Dot11Control::Dot11Control(const address_type& dst_addr)
|
||||
: Dot11(dst_addr) {
|
||||
type(CONTROL);
|
||||
}
|
||||
|
||||
Dot11Control::Dot11Control(const uint8_t *buffer, uint32_t total_sz)
|
||||
Dot11Control::Dot11Control(const uint8_t* buffer, uint32_t total_sz)
|
||||
: Dot11(buffer, total_sz) {
|
||||
|
||||
}
|
||||
|
||||
/* Dot11ControlTA */
|
||||
// Dot11ControlTA
|
||||
|
||||
Dot11ControlTA::Dot11ControlTA(const address_type &dst_addr,
|
||||
const address_type &target_address)
|
||||
: Dot11Control(dst_addr)
|
||||
{
|
||||
Dot11ControlTA::Dot11ControlTA(const address_type& dst_addr,
|
||||
const address_type& target_address)
|
||||
: Dot11Control(dst_addr) {
|
||||
target_addr(target_address);
|
||||
}
|
||||
|
||||
Dot11ControlTA::Dot11ControlTA(const uint8_t *buffer, uint32_t total_sz) : Dot11Control(buffer, total_sz) {
|
||||
Dot11ControlTA::Dot11ControlTA(const uint8_t* buffer, uint32_t total_sz) : Dot11Control(buffer, total_sz) {
|
||||
InputMemoryStream stream(buffer, total_sz);
|
||||
stream.skip(sizeof(ieee80211_header));
|
||||
stream.read(_taddr);
|
||||
stream.skip(sizeof(dot11_header));
|
||||
stream.read(taddr_);
|
||||
}
|
||||
|
||||
uint32_t Dot11ControlTA::header_size() const {
|
||||
return Dot11::header_size() + sizeof(_taddr);
|
||||
return Dot11::header_size() + taddr_.size();
|
||||
}
|
||||
|
||||
void Dot11ControlTA::write_ext_header(OutputMemoryStream& stream) {
|
||||
stream.write(_taddr);
|
||||
stream.write(taddr_);
|
||||
}
|
||||
|
||||
void Dot11ControlTA::target_addr(const address_type &addr) {
|
||||
_taddr = addr;
|
||||
void Dot11ControlTA::target_addr(const address_type& addr) {
|
||||
taddr_ = addr;
|
||||
}
|
||||
|
||||
/* Dot11RTS */
|
||||
// Dot11RTS
|
||||
|
||||
Dot11RTS::Dot11RTS(const address_type &dst_addr,
|
||||
const address_type &target_addr)
|
||||
: Dot11ControlTA(dst_addr, target_addr)
|
||||
{
|
||||
Dot11RTS::Dot11RTS(const address_type& dst_addr,
|
||||
const address_type& target_addr)
|
||||
: Dot11ControlTA(dst_addr, target_addr) {
|
||||
subtype(RTS);
|
||||
}
|
||||
|
||||
Dot11RTS::Dot11RTS(const uint8_t *buffer, uint32_t total_sz)
|
||||
Dot11RTS::Dot11RTS(const uint8_t* buffer, uint32_t total_sz)
|
||||
: Dot11ControlTA(buffer, total_sz) {
|
||||
|
||||
}
|
||||
|
||||
/* Dot11PSPoll */
|
||||
// Dot11PSPoll
|
||||
|
||||
Dot11PSPoll::Dot11PSPoll(const address_type &dst_addr,
|
||||
const address_type &target_addr)
|
||||
: Dot11ControlTA(dst_addr, target_addr)
|
||||
{
|
||||
Dot11PSPoll::Dot11PSPoll(const address_type& dst_addr,
|
||||
const address_type& target_addr)
|
||||
: Dot11ControlTA(dst_addr, target_addr) {
|
||||
subtype(PS);
|
||||
}
|
||||
|
||||
Dot11PSPoll::Dot11PSPoll(const uint8_t *buffer, uint32_t total_sz)
|
||||
Dot11PSPoll::Dot11PSPoll(const uint8_t* buffer, uint32_t total_sz)
|
||||
: Dot11ControlTA(buffer, total_sz) {
|
||||
|
||||
}
|
||||
|
||||
/* Dot11CFEnd */
|
||||
// Dot11CFEnd
|
||||
|
||||
Dot11CFEnd::Dot11CFEnd(const address_type &dst_addr,
|
||||
const address_type &target_addr)
|
||||
: Dot11ControlTA(dst_addr, target_addr)
|
||||
{
|
||||
Dot11CFEnd::Dot11CFEnd(const address_type& dst_addr,
|
||||
const address_type& target_addr)
|
||||
: Dot11ControlTA(dst_addr, target_addr) {
|
||||
subtype(CF_END);
|
||||
}
|
||||
|
||||
Dot11CFEnd::Dot11CFEnd(const uint8_t *buffer, uint32_t total_sz)
|
||||
Dot11CFEnd::Dot11CFEnd(const uint8_t* buffer, uint32_t total_sz)
|
||||
: Dot11ControlTA(buffer, total_sz) {
|
||||
|
||||
}
|
||||
|
||||
/* Dot11EndCFAck */
|
||||
// Dot11EndCFAck
|
||||
|
||||
Dot11EndCFAck::Dot11EndCFAck(const address_type &dst_addr,
|
||||
const address_type &target_addr)
|
||||
: Dot11ControlTA(dst_addr, target_addr)
|
||||
{
|
||||
Dot11EndCFAck::Dot11EndCFAck(const address_type& dst_addr,
|
||||
const address_type& target_addr)
|
||||
: Dot11ControlTA(dst_addr, target_addr) {
|
||||
subtype(CF_END_ACK);
|
||||
}
|
||||
|
||||
Dot11EndCFAck::Dot11EndCFAck(const uint8_t *buffer, uint32_t total_sz)
|
||||
Dot11EndCFAck::Dot11EndCFAck(const uint8_t* buffer, uint32_t total_sz)
|
||||
: Dot11ControlTA(buffer, total_sz) {
|
||||
|
||||
}
|
||||
|
||||
/* Dot11Ack */
|
||||
// Dot11Ack
|
||||
|
||||
Dot11Ack::Dot11Ack(const address_type &dst_addr)
|
||||
: Dot11Control(dst_addr)
|
||||
{
|
||||
Dot11Ack::Dot11Ack(const address_type& dst_addr)
|
||||
: Dot11Control(dst_addr) {
|
||||
subtype(ACK);
|
||||
}
|
||||
|
||||
Dot11Ack::Dot11Ack(const uint8_t *buffer, uint32_t total_sz)
|
||||
: Dot11Control(buffer, total_sz)
|
||||
{
|
||||
Dot11Ack::Dot11Ack(const uint8_t* buffer, uint32_t total_sz)
|
||||
: Dot11Control(buffer, total_sz) {
|
||||
|
||||
}
|
||||
|
||||
/* Dot11BlockAck */
|
||||
// Dot11BlockAck
|
||||
|
||||
Dot11BlockAckRequest::Dot11BlockAckRequest(const address_type &dst_addr,
|
||||
const address_type &target_addr)
|
||||
: Dot11ControlTA(dst_addr, target_addr)
|
||||
{
|
||||
init_block_ack();
|
||||
Dot11BlockAckRequest::Dot11BlockAckRequest(const address_type& dst_addr,
|
||||
const address_type& target_addr)
|
||||
: Dot11ControlTA(dst_addr, target_addr), bar_control_(0), start_sequence_(0) {
|
||||
subtype(BLOCK_ACK_REQ);
|
||||
}
|
||||
|
||||
Dot11BlockAckRequest::Dot11BlockAckRequest(const uint8_t *buffer, uint32_t total_sz)
|
||||
: Dot11ControlTA(buffer, total_sz)
|
||||
{
|
||||
Dot11BlockAckRequest::Dot11BlockAckRequest(const uint8_t* buffer, uint32_t total_sz)
|
||||
: Dot11ControlTA(buffer, total_sz) {
|
||||
InputMemoryStream stream(buffer, total_sz);
|
||||
stream.skip(controlta_size());
|
||||
stream.read(_bar_control);
|
||||
stream.read(_start_sequence);
|
||||
}
|
||||
|
||||
void Dot11BlockAckRequest::init_block_ack() {
|
||||
subtype(BLOCK_ACK_REQ);
|
||||
std::memset(&_bar_control, 0, sizeof(_bar_control));
|
||||
std::memset(&_start_sequence, 0, sizeof(_start_sequence));
|
||||
stream.read(bar_control_);
|
||||
stream.read(start_sequence_);
|
||||
}
|
||||
|
||||
void Dot11BlockAckRequest::write_ext_header(OutputMemoryStream& stream) {
|
||||
Dot11ControlTA::write_ext_header(stream);
|
||||
stream.write(_bar_control);
|
||||
stream.write(_start_sequence);
|
||||
stream.write(bar_control_);
|
||||
stream.write(start_sequence_);
|
||||
}
|
||||
|
||||
void Dot11BlockAckRequest::bar_control(small_uint<4> bar) {
|
||||
#if TINS_IS_LITTLE_ENDIAN
|
||||
_bar_control = bar | (_bar_control & 0xfff0);
|
||||
bar_control_ = bar | (bar_control_ & 0xfff0);
|
||||
#else
|
||||
_bar_control = (bar << 8) | (_bar_control & 0xf0ff);
|
||||
bar_control_ = (bar << 8) | (bar_control_ & 0xf0ff);
|
||||
#endif
|
||||
}
|
||||
|
||||
void Dot11BlockAckRequest::start_sequence(small_uint<12> seq) {
|
||||
#if TINS_IS_LITTLE_ENDIAN
|
||||
_start_sequence = (seq << 4) | (_start_sequence & 0xf);
|
||||
start_sequence_ = (seq << 4) | (start_sequence_ & 0xf);
|
||||
#else
|
||||
_start_sequence = Endian::host_to_le<uint16_t>(seq << 4) | (_start_sequence & 0xf00);
|
||||
start_sequence_ = Endian::host_to_le<uint16_t>(seq << 4) | (start_sequence_ & 0xf00);
|
||||
#endif
|
||||
}
|
||||
|
||||
void Dot11BlockAckRequest::fragment_number(small_uint<4> frag) {
|
||||
#if TINS_IS_LITTLE_ENDIAN
|
||||
_start_sequence = frag | (_start_sequence & 0xfff0);
|
||||
start_sequence_ = frag | (start_sequence_ & 0xfff0);
|
||||
#else
|
||||
_start_sequence = (frag << 8) | (_start_sequence & 0xf0ff);
|
||||
start_sequence_ = (frag << 8) | (start_sequence_ & 0xf0ff);
|
||||
#endif
|
||||
}
|
||||
|
||||
uint32_t Dot11BlockAckRequest::header_size() const {
|
||||
return Dot11ControlTA::header_size() + sizeof(_start_sequence) + sizeof(_start_sequence);
|
||||
return Dot11ControlTA::header_size() + sizeof(start_sequence_) + sizeof(start_sequence_);
|
||||
}
|
||||
|
||||
/* Dot11BlockAck */
|
||||
// Dot11BlockAck
|
||||
|
||||
Dot11BlockAck::Dot11BlockAck(const address_type &dst_addr,
|
||||
const address_type &target_addr)
|
||||
: Dot11ControlTA(dst_addr, target_addr)
|
||||
{
|
||||
Dot11BlockAck::Dot11BlockAck(const address_type& dst_addr,
|
||||
const address_type& target_addr)
|
||||
: Dot11ControlTA(dst_addr, target_addr), bitmap_() {
|
||||
subtype(BLOCK_ACK);
|
||||
std::memset(_bitmap, 0, sizeof(_bitmap));
|
||||
}
|
||||
|
||||
Dot11BlockAck::Dot11BlockAck(const uint8_t *buffer, uint32_t total_sz) : Dot11ControlTA(buffer, total_sz) {
|
||||
Dot11BlockAck::Dot11BlockAck(const uint8_t* buffer, uint32_t total_sz)
|
||||
: Dot11ControlTA(buffer, total_sz) {
|
||||
InputMemoryStream stream(buffer, total_sz);
|
||||
stream.skip(controlta_size());
|
||||
stream.read(_bar_control);
|
||||
stream.read(_start_sequence);
|
||||
stream.read(_bitmap);
|
||||
stream.read(bar_control_);
|
||||
stream.read(start_sequence_);
|
||||
stream.read(bitmap_);
|
||||
}
|
||||
|
||||
void Dot11BlockAck::bar_control(small_uint<4> bar) {
|
||||
#if TINS_IS_LITTLE_ENDIAN
|
||||
_bar_control = bar | (_bar_control & 0xfff0);
|
||||
bar_control_ = bar | (bar_control_ & 0xfff0);
|
||||
#else
|
||||
_bar_control = (bar << 8) | (_bar_control & 0xf0ff);
|
||||
bar_control_ = (bar << 8) | (bar_control_ & 0xf0ff);
|
||||
#endif
|
||||
}
|
||||
|
||||
void Dot11BlockAck::start_sequence(small_uint<12> seq) {
|
||||
#if TINS_IS_LITTLE_ENDIAN
|
||||
_start_sequence = (seq << 4) | (_start_sequence & 0xf);
|
||||
start_sequence_ = (seq << 4) | (start_sequence_ & 0xf);
|
||||
#else
|
||||
_start_sequence = Endian::host_to_le<uint16_t>(seq << 4) | (_start_sequence & 0xf00);
|
||||
start_sequence_ = Endian::host_to_le<uint16_t>(seq << 4) | (start_sequence_ & 0xf00);
|
||||
#endif
|
||||
}
|
||||
|
||||
void Dot11BlockAck::fragment_number(small_uint<4> frag) {
|
||||
#if TINS_IS_LITTLE_ENDIAN
|
||||
_start_sequence = frag | (_start_sequence & 0xfff0);
|
||||
start_sequence_ = frag | (start_sequence_ & 0xfff0);
|
||||
#else
|
||||
_start_sequence = (frag << 8) | (_start_sequence & 0xf0ff);
|
||||
start_sequence_ = (frag << 8) | (start_sequence_ & 0xf0ff);
|
||||
#endif
|
||||
}
|
||||
|
||||
void Dot11BlockAck::bitmap(const uint8_t *bit) {
|
||||
std::memcpy(_bitmap, bit, sizeof(_bitmap));
|
||||
void Dot11BlockAck::bitmap(const uint8_t* bit) {
|
||||
copy(bit, bit + bitmap_size, bitmap_);
|
||||
}
|
||||
|
||||
void Dot11BlockAck::write_ext_header(OutputMemoryStream& stream) {
|
||||
Dot11ControlTA::write_ext_header(stream);
|
||||
stream.write(_bar_control);
|
||||
stream.write(_start_sequence);
|
||||
stream.write(_bitmap);
|
||||
stream.write(bar_control_);
|
||||
stream.write(start_sequence_);
|
||||
stream.write(bitmap_);
|
||||
}
|
||||
|
||||
uint32_t Dot11BlockAck::header_size() const {
|
||||
return Dot11ControlTA::header_size() + sizeof(_start_sequence) + sizeof(_start_sequence) + sizeof(_bitmap);
|
||||
return Dot11ControlTA::header_size() + sizeof(start_sequence_) +
|
||||
sizeof(start_sequence_) + sizeof(bitmap_);
|
||||
}
|
||||
} // namespace Tins
|
||||
|
||||
} // Tins
|
||||
|
||||
#endif // HAVE_DOT11
|
||||
|
||||
@@ -39,17 +39,17 @@ using Tins::Memory::InputMemoryStream;
|
||||
using Tins::Memory::OutputMemoryStream;
|
||||
|
||||
namespace Tins {
|
||||
/* Dot11Data */
|
||||
|
||||
Dot11Data::Dot11Data(const uint8_t *buffer, uint32_t total_sz)
|
||||
: Dot11(buffer, total_sz)
|
||||
{
|
||||
// Dot11Data
|
||||
|
||||
Dot11Data::Dot11Data(const uint8_t* buffer, uint32_t total_sz)
|
||||
: Dot11(buffer, total_sz) {
|
||||
const uint32_t offset = init(buffer, total_sz);
|
||||
InputMemoryStream stream(buffer, total_sz);
|
||||
stream.skip(offset);
|
||||
if (stream) {
|
||||
// If the wep bit is on, then just use a RawPDU
|
||||
if(wep()) {
|
||||
if (wep()) {
|
||||
inner_pdu(new Tins::RawPDU(stream.pointer(), stream.size()));
|
||||
}
|
||||
else {
|
||||
@@ -58,89 +58,84 @@ Dot11Data::Dot11Data(const uint8_t *buffer, uint32_t total_sz)
|
||||
}
|
||||
}
|
||||
|
||||
Dot11Data::Dot11Data(const uint8_t *buffer, uint32_t total_sz, no_inner_pdu)
|
||||
: Dot11(buffer, total_sz)
|
||||
{
|
||||
Dot11Data::Dot11Data(const uint8_t* buffer, uint32_t total_sz, no_inner_pdu)
|
||||
: Dot11(buffer, total_sz) {
|
||||
init(buffer, total_sz);
|
||||
}
|
||||
|
||||
uint32_t Dot11Data::init(const uint8_t *buffer, uint32_t total_sz) {
|
||||
uint32_t Dot11Data::init(const uint8_t* buffer, uint32_t total_sz) {
|
||||
InputMemoryStream stream(buffer, total_sz);
|
||||
stream.skip(Dot11::header_size());
|
||||
stream.read(_ext_header);
|
||||
stream.read(ext_header_);
|
||||
if (from_ds() && to_ds()) {
|
||||
stream.read(_addr4);
|
||||
stream.read(addr4_);
|
||||
}
|
||||
return total_sz - stream.size();
|
||||
}
|
||||
|
||||
Dot11Data::Dot11Data(const address_type &dst_hw_addr,
|
||||
const address_type &src_hw_addr)
|
||||
: Dot11(dst_hw_addr)
|
||||
{
|
||||
Dot11Data::Dot11Data(const address_type& dst_hw_addr,
|
||||
const address_type& src_hw_addr)
|
||||
: Dot11(dst_hw_addr), ext_header_() {
|
||||
type(Dot11::DATA);
|
||||
memset(&_ext_header, 0, sizeof(_ext_header));
|
||||
addr2(src_hw_addr);
|
||||
}
|
||||
|
||||
uint32_t Dot11Data::header_size() const {
|
||||
uint32_t sz = Dot11::header_size() + sizeof(_ext_header);
|
||||
if (this->from_ds() && this->to_ds())
|
||||
uint32_t sz = Dot11::header_size() + sizeof(ext_header_);
|
||||
if (this->from_ds() && this->to_ds()) {
|
||||
sz += 6;
|
||||
}
|
||||
return sz;
|
||||
}
|
||||
|
||||
void Dot11Data::addr2(const address_type &new_addr2) {
|
||||
std::copy(new_addr2.begin(), new_addr2.end(), _ext_header.addr2);
|
||||
void Dot11Data::addr2(const address_type& new_addr2) {
|
||||
new_addr2.copy(ext_header_.addr2);
|
||||
}
|
||||
|
||||
void Dot11Data::addr3(const address_type &new_addr3) {
|
||||
std::copy(new_addr3.begin(), new_addr3.end(), _ext_header.addr3);
|
||||
void Dot11Data::addr3(const address_type& new_addr3) {
|
||||
new_addr3.copy(ext_header_.addr3);
|
||||
}
|
||||
|
||||
void Dot11Data::frag_num(small_uint<4> new_frag_num) {
|
||||
#if TINS_IS_LITTLE_ENDIAN
|
||||
_ext_header.frag_seq = new_frag_num | (_ext_header.frag_seq & 0xfff0);
|
||||
ext_header_.frag_seq = new_frag_num | (ext_header_.frag_seq & 0xfff0);
|
||||
#else
|
||||
_ext_header.frag_seq = (new_frag_num << 8) | (_ext_header.frag_seq & 0xf0ff);
|
||||
ext_header_.frag_seq = (new_frag_num << 8) | (ext_header_.frag_seq & 0xf0ff);
|
||||
#endif
|
||||
}
|
||||
|
||||
void Dot11Data::seq_num(small_uint<12> new_seq_num) {
|
||||
#if TINS_IS_LITTLE_ENDIAN
|
||||
_ext_header.frag_seq = (new_seq_num << 4) | (_ext_header.frag_seq & 0xf);
|
||||
ext_header_.frag_seq = (new_seq_num << 4) | (ext_header_.frag_seq & 0xf);
|
||||
#else
|
||||
_ext_header.frag_seq = Endian::host_to_le<uint16_t>(new_seq_num << 4) | (_ext_header.frag_seq & 0xf00);
|
||||
ext_header_.frag_seq = Endian::host_to_le<uint16_t>(new_seq_num << 4) | (ext_header_.frag_seq & 0xf00);
|
||||
#endif
|
||||
}
|
||||
|
||||
void Dot11Data::addr4(const address_type &new_addr4) {
|
||||
_addr4 = new_addr4;
|
||||
void Dot11Data::addr4(const address_type& new_addr4) {
|
||||
addr4_ = new_addr4;
|
||||
}
|
||||
|
||||
void Dot11Data::write_ext_header(OutputMemoryStream& stream) {
|
||||
stream.write(_ext_header);
|
||||
stream.write(ext_header_);
|
||||
if (from_ds() && to_ds()) {
|
||||
stream.write(_addr4);
|
||||
stream.write(addr4_);
|
||||
}
|
||||
}
|
||||
|
||||
/* QoS data. */
|
||||
// QoS data
|
||||
|
||||
Dot11QoSData::Dot11QoSData(const address_type &dst_hw_addr,
|
||||
const address_type &src_hw_addr)
|
||||
: Dot11Data(dst_hw_addr, src_hw_addr)
|
||||
{
|
||||
Dot11QoSData::Dot11QoSData(const address_type& dst_hw_addr,
|
||||
const address_type& src_hw_addr)
|
||||
: Dot11Data(dst_hw_addr, src_hw_addr), qos_control_() {
|
||||
subtype(Dot11::QOS_DATA_DATA);
|
||||
_qos_control = 0;
|
||||
}
|
||||
|
||||
Dot11QoSData::Dot11QoSData(const uint8_t *buffer, uint32_t total_sz)
|
||||
// Am I breaking something? :S
|
||||
Dot11QoSData::Dot11QoSData(const uint8_t* buffer, uint32_t total_sz)
|
||||
: Dot11Data(buffer, total_sz, no_inner_pdu()) {
|
||||
InputMemoryStream stream(buffer, total_sz);
|
||||
stream.skip(data_frame_size());
|
||||
stream.read(_qos_control);
|
||||
stream.skip(Dot11Data::header_size());
|
||||
stream.read(qos_control_);
|
||||
if (total_sz) {
|
||||
// If the wep bit is on, then just use a RawPDU
|
||||
if (wep()) {
|
||||
@@ -153,16 +148,17 @@ Dot11QoSData::Dot11QoSData(const uint8_t *buffer, uint32_t total_sz)
|
||||
}
|
||||
|
||||
void Dot11QoSData::qos_control(uint16_t new_qos_control) {
|
||||
this->_qos_control = Endian::host_to_le(new_qos_control);
|
||||
qos_control_ = Endian::host_to_le(new_qos_control);
|
||||
}
|
||||
|
||||
uint32_t Dot11QoSData::header_size() const {
|
||||
return Dot11Data::header_size() + sizeof(this->_qos_control);
|
||||
return Dot11Data::header_size() + sizeof(qos_control_);
|
||||
}
|
||||
|
||||
void Dot11QoSData::write_fixed_parameters(OutputMemoryStream& stream) {
|
||||
stream.write(_qos_control);
|
||||
stream.write(qos_control_);
|
||||
}
|
||||
} // namespace Tins
|
||||
|
||||
} // Tins
|
||||
|
||||
#endif // HAVE_DOT11
|
||||
|
||||
@@ -34,76 +34,88 @@
|
||||
#include "rsn_information.h"
|
||||
#include "memory_helpers.h"
|
||||
|
||||
using std::string;
|
||||
using std::copy;
|
||||
using std::vector;
|
||||
using std::back_inserter;
|
||||
using std::runtime_error;
|
||||
using std::pair;
|
||||
using std::make_pair;
|
||||
|
||||
using Tins::Memory::InputMemoryStream;
|
||||
using Tins::Memory::OutputMemoryStream;
|
||||
|
||||
namespace Tins {
|
||||
/* Dot11ManagementFrame */
|
||||
|
||||
Dot11ManagementFrame::Dot11ManagementFrame(const uint8_t *buffer, uint32_t total_sz)
|
||||
: Dot11(buffer, total_sz)
|
||||
{
|
||||
// Dot11ManagementFrame
|
||||
|
||||
Dot11ManagementFrame::Dot11ManagementFrame(const uint8_t* buffer, uint32_t total_sz)
|
||||
: Dot11(buffer, total_sz) {
|
||||
InputMemoryStream stream(buffer, total_sz);
|
||||
stream.skip(sizeof(ieee80211_header));
|
||||
stream.read(_ext_header);
|
||||
stream.skip(sizeof(dot11_header));
|
||||
stream.read(ext_header_);
|
||||
if (from_ds() && to_ds()) {
|
||||
stream.read(_addr4);
|
||||
stream.read(addr4_);
|
||||
}
|
||||
}
|
||||
|
||||
Dot11ManagementFrame::Dot11ManagementFrame(const address_type &dst_hw_addr,
|
||||
const address_type &src_hw_addr)
|
||||
: Dot11(dst_hw_addr), _ext_header()
|
||||
{
|
||||
Dot11ManagementFrame::Dot11ManagementFrame(const address_type& dst_hw_addr,
|
||||
const address_type& src_hw_addr)
|
||||
: Dot11(dst_hw_addr), ext_header_() {
|
||||
type(Dot11::MANAGEMENT);
|
||||
addr2(src_hw_addr);
|
||||
}
|
||||
|
||||
uint32_t Dot11ManagementFrame::header_size() const {
|
||||
uint32_t sz = Dot11::header_size() + sizeof(_ext_header);
|
||||
if (this->from_ds() && this->to_ds()) {
|
||||
uint32_t sz = Dot11::header_size() + sizeof(ext_header_);
|
||||
if (from_ds() && to_ds()) {
|
||||
sz += 6;
|
||||
}
|
||||
return sz;
|
||||
}
|
||||
|
||||
void Dot11ManagementFrame::addr2(const address_type &new_addr2) {
|
||||
std::copy(new_addr2.begin(), new_addr2.end(), _ext_header.addr2);
|
||||
void Dot11ManagementFrame::addr2(const address_type& new_addr2) {
|
||||
new_addr2.copy(ext_header_.addr2);
|
||||
}
|
||||
|
||||
void Dot11ManagementFrame::addr3(const address_type &new_addr3) {
|
||||
std::copy(new_addr3.begin(), new_addr3.end(), _ext_header.addr3);
|
||||
void Dot11ManagementFrame::addr3(const address_type& new_addr3) {
|
||||
new_addr3.copy(ext_header_.addr3);
|
||||
}
|
||||
|
||||
void Dot11ManagementFrame::frag_num(small_uint<4> new_frag_num) {
|
||||
#if TINS_IS_LITTLE_ENDIAN
|
||||
_ext_header.frag_seq = new_frag_num | (_ext_header.frag_seq & 0xfff0);
|
||||
ext_header_.frag_seq = new_frag_num | (ext_header_.frag_seq & 0xfff0);
|
||||
#else
|
||||
_ext_header.frag_seq = (new_frag_num << 8) | (_ext_header.frag_seq & 0xf0ff);
|
||||
ext_header_.frag_seq = (new_frag_num << 8) | (ext_header_.frag_seq & 0xf0ff);
|
||||
#endif
|
||||
}
|
||||
|
||||
void Dot11ManagementFrame::seq_num(small_uint<12> new_seq_num) {
|
||||
#if TINS_IS_LITTLE_ENDIAN
|
||||
_ext_header.frag_seq = (new_seq_num << 4) | (_ext_header.frag_seq & 0xf);
|
||||
ext_header_.frag_seq = (new_seq_num << 4) | (ext_header_.frag_seq & 0xf);
|
||||
#else
|
||||
_ext_header.frag_seq = Endian::host_to_le<uint16_t>(new_seq_num << 4) | (_ext_header.frag_seq & 0xf00);
|
||||
ext_header_.frag_seq = Endian::host_to_le<uint16_t>(new_seq_num << 4) |
|
||||
(ext_header_.frag_seq & 0xf00);
|
||||
#endif
|
||||
}
|
||||
|
||||
void Dot11ManagementFrame::addr4(const address_type &new_addr4) {
|
||||
_addr4 = new_addr4;
|
||||
void Dot11ManagementFrame::addr4(const address_type& new_addr4) {
|
||||
addr4_ = new_addr4;
|
||||
}
|
||||
|
||||
void Dot11ManagementFrame::write_ext_header(OutputMemoryStream& stream) {
|
||||
stream.write(_ext_header);
|
||||
stream.write(ext_header_);
|
||||
if (from_ds() && to_ds()) {
|
||||
stream.write(_addr4);
|
||||
stream.write(addr4_);
|
||||
}
|
||||
}
|
||||
|
||||
void Dot11ManagementFrame::ssid(const std::string &new_ssid) {
|
||||
add_tagged_option(Dot11::SSID, static_cast<uint8_t>(new_ssid.size()), (const uint8_t*)new_ssid.c_str());
|
||||
void Dot11ManagementFrame::ssid(const string& new_ssid) {
|
||||
add_tagged_option(
|
||||
Dot11::SSID,
|
||||
static_cast<uint8_t>(new_ssid.size()),
|
||||
(const uint8_t*)new_ssid.c_str()
|
||||
);
|
||||
}
|
||||
|
||||
void Dot11ManagementFrame::rsn_information(const RSNInformation& info) {
|
||||
@@ -111,36 +123,36 @@ void Dot11ManagementFrame::rsn_information(const RSNInformation& info) {
|
||||
add_tagged_option(RSN, static_cast<uint8_t>(buffer.size()), &buffer[0]);
|
||||
}
|
||||
|
||||
uint8_t *Dot11ManagementFrame::serialize_rates(const rates_type &rates) {
|
||||
uint8_t *buffer = new uint8_t[rates.size()], *ptr = buffer;
|
||||
for(rates_type::const_iterator it = rates.begin(); it != rates.end(); ++it) {
|
||||
vector<uint8_t> Dot11ManagementFrame::serialize_rates(const rates_type& rates) {
|
||||
vector<uint8_t> buffer(rates.size());
|
||||
uint8_t* ptr = &buffer[0];
|
||||
for (rates_type::const_iterator it = rates.begin(); it != rates.end(); ++it) {
|
||||
uint8_t result = static_cast<uint8_t>(*it * 2);
|
||||
if(result == 2 || result == 4 || result == 11 || result == 22)
|
||||
if (result == 2 || result == 4 || result == 11 || result == 22) {
|
||||
result |= 0x80;
|
||||
}
|
||||
*(ptr++) = result;
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
Dot11ManagementFrame::rates_type Dot11ManagementFrame::deserialize_rates(const option *opt) {
|
||||
Dot11ManagementFrame::rates_type Dot11ManagementFrame::deserialize_rates(const option* opt) {
|
||||
rates_type output;
|
||||
const uint8_t *ptr = opt->data_ptr(), *end = ptr + opt->data_size();
|
||||
while(ptr != end) {
|
||||
const uint8_t* ptr = opt->data_ptr(), *end = ptr + opt->data_size();
|
||||
while (ptr != end) {
|
||||
output.push_back(float(*(ptr++) & 0x7f) / 2);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
void Dot11ManagementFrame::supported_rates(const rates_type &new_rates) {
|
||||
uint8_t *buffer = serialize_rates(new_rates);
|
||||
add_tagged_option(SUPPORTED_RATES, static_cast<uint8_t>(new_rates.size()), buffer);
|
||||
delete[] buffer;
|
||||
void Dot11ManagementFrame::supported_rates(const rates_type& new_rates) {
|
||||
vector<uint8_t> buffer = serialize_rates(new_rates);
|
||||
add_tagged_option(SUPPORTED_RATES, static_cast<uint8_t>(buffer.size()), &buffer[0]);
|
||||
}
|
||||
|
||||
void Dot11ManagementFrame::extended_supported_rates(const rates_type &new_rates) {
|
||||
uint8_t *buffer = serialize_rates(new_rates);
|
||||
add_tagged_option(EXT_SUPPORTED_RATES, static_cast<uint8_t>(new_rates.size()), buffer);
|
||||
delete[] buffer;
|
||||
void Dot11ManagementFrame::extended_supported_rates(const rates_type& new_rates) {
|
||||
vector<uint8_t> buffer = serialize_rates(new_rates);
|
||||
add_tagged_option(EXT_SUPPORTED_RATES, static_cast<uint8_t>(buffer.size()), &buffer[0]);
|
||||
}
|
||||
|
||||
void Dot11ManagementFrame::qos_capability(qos_capability_type new_qos_capability) {
|
||||
@@ -154,10 +166,10 @@ void Dot11ManagementFrame::power_capability(uint8_t min_power, uint8_t max_power
|
||||
add_tagged_option(POWER_CAPABILITY, 2, buffer);
|
||||
}
|
||||
|
||||
void Dot11ManagementFrame::supported_channels(const channels_type &new_channels) {
|
||||
std::vector<uint8_t> buffer(new_channels.size() * 2);
|
||||
void Dot11ManagementFrame::supported_channels(const channels_type& new_channels) {
|
||||
vector<uint8_t> buffer(new_channels.size() * 2);
|
||||
uint8_t* ptr = &buffer[0];
|
||||
for(channels_type::const_iterator it = new_channels.begin(); it != new_channels.end(); ++it) {
|
||||
for (channels_type::const_iterator it = new_channels.begin(); it != new_channels.end(); ++it) {
|
||||
*(ptr++) = it->first;
|
||||
*(ptr++) = it->second;
|
||||
}
|
||||
@@ -166,13 +178,13 @@ void Dot11ManagementFrame::supported_channels(const channels_type &new_channels)
|
||||
|
||||
void Dot11ManagementFrame::edca_parameter_set(uint32_t ac_be, uint32_t ac_bk, uint32_t ac_vi, uint32_t ac_vo) {
|
||||
uint8_t buffer[18];
|
||||
buffer[0] = 0;
|
||||
buffer[1] = 0;
|
||||
uint32_t* ptr = (uint32_t*)(buffer + 2);
|
||||
*(ptr++) = Endian::host_to_le(ac_be);
|
||||
*(ptr++) = Endian::host_to_le(ac_bk);
|
||||
*(ptr++) = Endian::host_to_le(ac_vi);
|
||||
*(ptr++) = Endian::host_to_le(ac_vo);
|
||||
OutputMemoryStream stream(buffer, sizeof(buffer));
|
||||
stream.write<uint8_t>(0);
|
||||
stream.write<uint8_t>(0);
|
||||
stream.write_le(ac_be);
|
||||
stream.write_le(ac_bk);
|
||||
stream.write_le(ac_vi);
|
||||
stream.write_le(ac_vo);
|
||||
add_tagged_option(EDCA, sizeof(buffer), buffer);
|
||||
}
|
||||
|
||||
@@ -180,30 +192,28 @@ void Dot11ManagementFrame::request_information(const request_info_type elements)
|
||||
add_tagged_option(REQUEST_INFORMATION, static_cast<uint8_t>(elements.size()), &elements[0]);
|
||||
}
|
||||
|
||||
void Dot11ManagementFrame::fh_parameter_set(const fh_params_set &fh_params) {
|
||||
uint8_t data[5];
|
||||
uint16_t dwell = Endian::host_to_le(fh_params.dwell_time);
|
||||
std::memcpy(data, &dwell, sizeof(dwell));
|
||||
data[2] = fh_params.hop_set;
|
||||
data[3] = fh_params.hop_pattern;
|
||||
data[4] = fh_params.hop_index;
|
||||
add_tagged_option(FH_SET, sizeof(data), data);
|
||||
|
||||
void Dot11ManagementFrame::fh_parameter_set(const fh_params_set& fh_params) {
|
||||
uint8_t buffer[5];
|
||||
OutputMemoryStream stream(buffer, sizeof(buffer));
|
||||
stream.write_le(fh_params.dwell_time);
|
||||
stream.write(fh_params.hop_set);
|
||||
stream.write(fh_params.hop_pattern);
|
||||
stream.write(fh_params.hop_index);
|
||||
add_tagged_option(FH_SET, sizeof(buffer), buffer);
|
||||
}
|
||||
|
||||
void Dot11ManagementFrame::ds_parameter_set(uint8_t current_channel) {
|
||||
add_tagged_option(DS_SET, 1, ¤t_channel);
|
||||
}
|
||||
|
||||
void Dot11ManagementFrame::cf_parameter_set(const cf_params_set ¶ms) {
|
||||
uint8_t data[6];
|
||||
data[0] = params.cfp_count;
|
||||
data[1] = params.cfp_period;
|
||||
uint16_t dummy = Endian::host_to_le(params.cfp_max_duration);
|
||||
std::memcpy(data + 2, &dummy, sizeof(uint16_t));
|
||||
dummy = Endian::host_to_le(params.cfp_dur_remaining);
|
||||
std::memcpy(data + 4, &dummy, sizeof(uint16_t));
|
||||
add_tagged_option(CF_SET, sizeof(data), data);
|
||||
void Dot11ManagementFrame::cf_parameter_set(const cf_params_set& params) {
|
||||
uint8_t buffer[6];
|
||||
OutputMemoryStream stream(buffer, sizeof(buffer));
|
||||
stream.write(params.cfp_count);
|
||||
stream.write(params.cfp_period);
|
||||
stream.write_le(params.cfp_max_duration);
|
||||
stream.write_le(params.cfp_dur_remaining);
|
||||
add_tagged_option(CF_SET, sizeof(buffer), buffer);
|
||||
}
|
||||
|
||||
void Dot11ManagementFrame::ibss_parameter_set(uint16_t atim_window) {
|
||||
@@ -211,35 +221,37 @@ void Dot11ManagementFrame::ibss_parameter_set(uint16_t atim_window) {
|
||||
add_tagged_option(IBSS_SET, 2, (uint8_t*)&atim_window);
|
||||
}
|
||||
|
||||
void Dot11ManagementFrame::ibss_dfs(const ibss_dfs_params ¶ms) {
|
||||
void Dot11ManagementFrame::ibss_dfs(const ibss_dfs_params& params) {
|
||||
const size_t sz = address_type::address_size + sizeof(uint8_t) +
|
||||
sizeof(uint8_t) * 2 * params.channel_map.size();
|
||||
std::vector<uint8_t> buffer(sz);
|
||||
uint8_t* ptr_buffer = &buffer[0];
|
||||
|
||||
ptr_buffer = params.dfs_owner.copy(ptr_buffer);
|
||||
*(ptr_buffer++) = params.recovery_interval;
|
||||
sizeof(uint8_t) * 2 * params.channel_map.size();
|
||||
vector<uint8_t> buffer(sz);
|
||||
OutputMemoryStream stream(buffer);
|
||||
stream.write(params.dfs_owner);
|
||||
stream.write(params.recovery_interval);
|
||||
for (channels_type::const_iterator it = params.channel_map.begin(); it != params.channel_map.end(); ++it) {
|
||||
*(ptr_buffer++) = it->first;
|
||||
*(ptr_buffer++) = it->second;
|
||||
stream.write(it->first);
|
||||
stream.write(it->second);
|
||||
}
|
||||
|
||||
add_tagged_option(IBSS_DFS, static_cast<uint8_t>(buffer.size()), &buffer[0]);
|
||||
}
|
||||
|
||||
void Dot11ManagementFrame::country(const country_params ¶ms) {
|
||||
void Dot11ManagementFrame::country(const country_params& params) {
|
||||
if ((params.first_channel.size() != params.number_channels.size()) ||
|
||||
(params.number_channels.size() != params.max_transmit_power.size()))
|
||||
throw std::runtime_error("The length of the lists are distinct");
|
||||
if(params.country.size() != 3)
|
||||
throw std::runtime_error("Invalid country identifier length");
|
||||
(params.number_channels.size() != params.max_transmit_power.size())) {
|
||||
throw runtime_error("The length of the lists are distinct");
|
||||
}
|
||||
if (params.country.size() != 3) {
|
||||
throw runtime_error("Invalid country identifier length");
|
||||
}
|
||||
size_t sz = sizeof(uint8_t) * 3 * params.first_channel.size() + params.country.size();
|
||||
// Use 1 byte padding at the end if the length is odd.
|
||||
if((sz & 1) == 1)
|
||||
if ((sz & 1) == 1) {
|
||||
sz++;
|
||||
std::vector<uint8_t> buffer(sz);
|
||||
uint8_t *ptr = std::copy(params.country.begin(), params.country.end(), &buffer[0]);
|
||||
for(size_t i(0); i < params.first_channel.size(); ++i) {
|
||||
}
|
||||
vector<uint8_t> buffer(sz);
|
||||
uint8_t* ptr = copy(params.country.begin(), params.country.end(), &buffer[0]);
|
||||
for (size_t i(0); i < params.first_channel.size(); ++i) {
|
||||
*(ptr++) = params.first_channel[i];
|
||||
*(ptr++) = params.number_channels[i];
|
||||
*(ptr++) = params.max_transmit_power[i];
|
||||
@@ -254,16 +266,17 @@ void Dot11ManagementFrame::fh_parameters(uint8_t prime_radix, uint8_t number_cha
|
||||
add_tagged_option(HOPPING_PATTERN_PARAMS, 2, buffer);
|
||||
}
|
||||
|
||||
void Dot11ManagementFrame::fh_pattern_table(const fh_pattern_type ¶ms) {
|
||||
std::vector<uint8_t> data(sizeof(uint8_t) * 4 + params.random_table.size());
|
||||
uint8_t *ptr = &data[0];
|
||||
void Dot11ManagementFrame::fh_pattern_table(const fh_pattern_type& params) {
|
||||
vector<uint8_t> data(sizeof(uint8_t) * 4 + params.random_table.size());
|
||||
uint8_t* ptr = &data[0];
|
||||
*(ptr++) = params.flag;
|
||||
*(ptr++) = params.number_of_sets;
|
||||
*(ptr++) = params.modulus;
|
||||
*(ptr++) = params.offset;
|
||||
byte_array::const_iterator it(params.random_table.begin());
|
||||
for(; it != params.random_table.end(); ++it)
|
||||
for (; it != params.random_table.end(); ++it) {
|
||||
*(ptr++) = *it;
|
||||
}
|
||||
add_tagged_option(HOPPING_PATTERN_TABLE, static_cast<uint8_t>(data.size()), &data[0]);
|
||||
}
|
||||
|
||||
@@ -271,7 +284,7 @@ void Dot11ManagementFrame::power_constraint(uint8_t local_power_constraint) {
|
||||
add_tagged_option(POWER_CONSTRAINT, 1, &local_power_constraint);
|
||||
}
|
||||
|
||||
void Dot11ManagementFrame::channel_switch(const channel_switch_type &data) {
|
||||
void Dot11ManagementFrame::channel_switch(const channel_switch_type& data) {
|
||||
uint8_t buffer[3];
|
||||
buffer[0] = data.switch_mode;
|
||||
buffer[1] = data.new_channel;
|
||||
@@ -280,14 +293,13 @@ void Dot11ManagementFrame::channel_switch(const channel_switch_type &data) {
|
||||
|
||||
}
|
||||
|
||||
void Dot11ManagementFrame::quiet(const quiet_type &data) {
|
||||
void Dot11ManagementFrame::quiet(const quiet_type& data) {
|
||||
uint8_t buffer[6];
|
||||
uint16_t* ptr_buffer = (uint16_t*)(buffer + 2);
|
||||
|
||||
buffer[0] = data.quiet_count;
|
||||
buffer[1] = data.quiet_period;
|
||||
ptr_buffer[0] = Endian::host_to_le(data.quiet_duration);
|
||||
ptr_buffer[1] = Endian::host_to_le(data.quiet_offset);
|
||||
OutputMemoryStream stream(buffer, sizeof(buffer));
|
||||
stream.write(data.quiet_count);
|
||||
stream.write(data.quiet_period);
|
||||
stream.write_le(data.quiet_duration);
|
||||
stream.write_le(data.quiet_offset);
|
||||
add_tagged_option(QUIET, sizeof(buffer), buffer);
|
||||
}
|
||||
|
||||
@@ -303,7 +315,7 @@ void Dot11ManagementFrame::erp_information(uint8_t value) {
|
||||
add_tagged_option(ERP_INFORMATION, 1, &value);
|
||||
}
|
||||
|
||||
void Dot11ManagementFrame::bss_load(const bss_load_type &data) {
|
||||
void Dot11ManagementFrame::bss_load(const bss_load_type& data) {
|
||||
uint8_t buffer[5];
|
||||
uint16_t dummy = Endian::host_to_le(data.station_count);
|
||||
|
||||
@@ -328,20 +340,21 @@ void Dot11ManagementFrame::bss_load(const bss_load_type &data) {
|
||||
add_tagged_option(BSS_LOAD, sizeof(buffer), buffer);
|
||||
}
|
||||
|
||||
void Dot11ManagementFrame::tim(const tim_type &data) {
|
||||
std::vector<uint8_t> buffer(sizeof(uint8_t) * 3 + data.partial_virtual_bitmap.size());
|
||||
buffer[0] = data.dtim_count;
|
||||
buffer[1] = data.dtim_period;
|
||||
buffer[2] = data.bitmap_control;
|
||||
std::copy(
|
||||
void Dot11ManagementFrame::tim(const tim_type& data) {
|
||||
vector<uint8_t> buffer(sizeof(uint8_t) * 3 + data.partial_virtual_bitmap.size());
|
||||
OutputMemoryStream stream(buffer);
|
||||
|
||||
stream.write(data.dtim_count);
|
||||
stream.write(data.dtim_period);
|
||||
stream.write(data.bitmap_control);
|
||||
stream.write(
|
||||
data.partial_virtual_bitmap.begin(),
|
||||
data.partial_virtual_bitmap.end(),
|
||||
&buffer[3]
|
||||
data.partial_virtual_bitmap.end()
|
||||
);
|
||||
add_tagged_option(TIM, static_cast<uint8_t>(buffer.size()), &buffer[0]);
|
||||
}
|
||||
|
||||
void Dot11ManagementFrame::challenge_text(const std::string &text) {
|
||||
void Dot11ManagementFrame::challenge_text(const string& text) {
|
||||
add_tagged_option(
|
||||
CHALLENGE_TEXT,
|
||||
static_cast<uint8_t>(text.size()),
|
||||
@@ -349,9 +362,9 @@ void Dot11ManagementFrame::challenge_text(const std::string &text) {
|
||||
);
|
||||
}
|
||||
|
||||
void Dot11ManagementFrame::vendor_specific(const vendor_specific_type &data) {
|
||||
void Dot11ManagementFrame::vendor_specific(const vendor_specific_type& data) {
|
||||
byte_array buffer(3 + data.data.size());
|
||||
std::copy(
|
||||
copy(
|
||||
data.data.begin(),
|
||||
data.data.end(),
|
||||
data.oui.copy(buffer.begin())
|
||||
@@ -365,14 +378,17 @@ RSNInformation Dot11ManagementFrame::rsn_information() const {
|
||||
return search_and_convert<RSNInformation>(RSN);
|
||||
}
|
||||
|
||||
std::string Dot11ManagementFrame::ssid() const {
|
||||
const Dot11::option *option = search_option(SSID);
|
||||
if(!option)
|
||||
string Dot11ManagementFrame::ssid() const {
|
||||
const Dot11::option* option = search_option(SSID);
|
||||
if (!option) {
|
||||
throw option_not_found();
|
||||
if(option->data_size() == 0 && this->subtype() == Dot11::PROBE_REQ)
|
||||
}
|
||||
if (option->data_size() == 0 && subtype() == Dot11::PROBE_REQ){
|
||||
return "BROADCAST";
|
||||
else
|
||||
return std::string((const char*)option->data_ptr(), option->data_size());
|
||||
}
|
||||
else {
|
||||
return string((const char*)option->data_ptr(), option->data_size());
|
||||
}
|
||||
}
|
||||
|
||||
Dot11ManagementFrame::rates_type Dot11ManagementFrame::supported_rates() const {
|
||||
@@ -387,8 +403,8 @@ Dot11ManagementFrame::qos_capability_type Dot11ManagementFrame::qos_capability()
|
||||
return search_and_convert<uint8_t>(QOS_CAPABILITY);
|
||||
}
|
||||
|
||||
std::pair<uint8_t, uint8_t> Dot11ManagementFrame::power_capability() const {
|
||||
return search_and_convert<std::pair<uint8_t, uint8_t> >(POWER_CAPABILITY);
|
||||
pair<uint8_t, uint8_t> Dot11ManagementFrame::power_capability() const {
|
||||
return search_and_convert<pair<uint8_t, uint8_t> >(POWER_CAPABILITY);
|
||||
}
|
||||
|
||||
Dot11ManagementFrame::channels_type Dot11ManagementFrame::supported_channels() const {
|
||||
@@ -423,8 +439,8 @@ Dot11ManagementFrame::country_params Dot11ManagementFrame::country() const {
|
||||
return search_and_convert<country_params>(COUNTRY);
|
||||
}
|
||||
|
||||
std::pair<uint8_t, uint8_t> Dot11ManagementFrame::fh_parameters() const {
|
||||
return search_and_convert<std::pair<uint8_t, uint8_t> >(HOPPING_PATTERN_PARAMS);
|
||||
pair<uint8_t, uint8_t> Dot11ManagementFrame::fh_parameters() const {
|
||||
return search_and_convert<pair<uint8_t, uint8_t> >(HOPPING_PATTERN_PARAMS);
|
||||
}
|
||||
|
||||
Dot11ManagementFrame::fh_pattern_type Dot11ManagementFrame::fh_pattern_table() const {
|
||||
@@ -443,8 +459,8 @@ Dot11ManagementFrame::quiet_type Dot11ManagementFrame::quiet() const {
|
||||
return search_and_convert<quiet_type>(QUIET);
|
||||
}
|
||||
|
||||
std::pair<uint8_t, uint8_t> Dot11ManagementFrame::tpc_report() const {
|
||||
return search_and_convert<std::pair<uint8_t, uint8_t> >(TPC_REPORT);
|
||||
pair<uint8_t, uint8_t> Dot11ManagementFrame::tpc_report() const {
|
||||
return search_and_convert<pair<uint8_t, uint8_t> >(TPC_REPORT);
|
||||
}
|
||||
|
||||
uint8_t Dot11ManagementFrame::erp_information() const {
|
||||
@@ -459,23 +475,26 @@ Dot11ManagementFrame::tim_type Dot11ManagementFrame::tim() const {
|
||||
return search_and_convert<tim_type>(TIM);
|
||||
}
|
||||
|
||||
std::string Dot11ManagementFrame::challenge_text() const {
|
||||
return search_and_convert<std::string>(CHALLENGE_TEXT);
|
||||
string Dot11ManagementFrame::challenge_text() const {
|
||||
return search_and_convert<string>(CHALLENGE_TEXT);
|
||||
}
|
||||
|
||||
Dot11ManagementFrame::vendor_specific_type Dot11ManagementFrame::vendor_specific() const {
|
||||
const Dot11::option *option = search_option(VENDOR_SPECIFIC);
|
||||
if(!option || option->data_size() < 3)
|
||||
const Dot11::option* option = search_option(VENDOR_SPECIFIC);
|
||||
if (!option || option->data_size() < 3) {
|
||||
throw option_not_found();
|
||||
return vendor_specific_type::from_bytes(option->data_ptr(),
|
||||
static_cast<uint32_t>(option->data_size()));
|
||||
}
|
||||
return vendor_specific_type::from_bytes(
|
||||
option->data_ptr(),
|
||||
static_cast<uint32_t>(option->data_size())
|
||||
);
|
||||
}
|
||||
|
||||
Dot11ManagementFrame::vendor_specific_type
|
||||
Dot11ManagementFrame::vendor_specific_type::from_bytes(const uint8_t *buffer, uint32_t sz)
|
||||
{
|
||||
if(sz < 3)
|
||||
Dot11ManagementFrame::vendor_specific_type::from_bytes(const uint8_t* buffer, uint32_t sz) {
|
||||
if (sz < 3) {
|
||||
throw malformed_option();
|
||||
}
|
||||
return vendor_specific_type(
|
||||
buffer,
|
||||
byte_array(buffer + 3, buffer + sz)
|
||||
@@ -484,75 +503,81 @@ Dot11ManagementFrame::vendor_specific_type
|
||||
|
||||
// Options
|
||||
|
||||
Dot11ManagementFrame::fh_params_set Dot11ManagementFrame::fh_params_set::from_option(const option &opt)
|
||||
{
|
||||
if(opt.data_size() != 5)
|
||||
Dot11ManagementFrame::fh_params_set
|
||||
Dot11ManagementFrame::fh_params_set::from_option(const option& opt) {
|
||||
if (opt.data_size() != 5) {
|
||||
throw malformed_option();
|
||||
}
|
||||
fh_params_set output;
|
||||
std::memcpy(&output.dwell_time, opt.data_ptr(), sizeof(uint16_t));
|
||||
output.dwell_time = Endian::le_to_host(output.dwell_time);
|
||||
output.hop_set = opt.data_ptr()[2];
|
||||
output.hop_pattern = opt.data_ptr()[3];
|
||||
output.hop_index = opt.data_ptr()[4];
|
||||
InputMemoryStream stream(opt.data_ptr(), opt.data_size());
|
||||
output.dwell_time = stream.read_le<uint16_t>();
|
||||
output.hop_set = stream.read<uint8_t>();
|
||||
output.hop_pattern = stream.read<uint8_t>();
|
||||
output.hop_index = stream.read<uint8_t>();
|
||||
return output;
|
||||
}
|
||||
|
||||
Dot11ManagementFrame::cf_params_set Dot11ManagementFrame::cf_params_set::from_option(const option &opt)
|
||||
{
|
||||
if(opt.data_size() != 6)
|
||||
Dot11ManagementFrame::cf_params_set
|
||||
Dot11ManagementFrame::cf_params_set::from_option(const option& opt) {
|
||||
if (opt.data_size() != 6) {
|
||||
throw malformed_option();
|
||||
}
|
||||
cf_params_set output;
|
||||
output.cfp_count = *opt.data_ptr();
|
||||
output.cfp_period = opt.data_ptr()[1];
|
||||
std::memcpy(&output.cfp_max_duration, &opt.data_ptr()[2], sizeof(uint16_t));
|
||||
std::memcpy(&output.cfp_dur_remaining, &opt.data_ptr()[4], sizeof(uint16_t));
|
||||
output.cfp_max_duration = Endian::le_to_host(output.cfp_max_duration);
|
||||
output.cfp_dur_remaining = Endian::le_to_host(output.cfp_dur_remaining);
|
||||
InputMemoryStream stream(opt.data_ptr(), opt.data_size());
|
||||
output.cfp_count = stream.read<uint8_t>();
|
||||
output.cfp_period = stream.read<uint8_t>();
|
||||
output.cfp_max_duration = stream.read_le<uint16_t>();
|
||||
output.cfp_dur_remaining = stream.read_le<uint16_t>();
|
||||
return output;
|
||||
}
|
||||
|
||||
Dot11ManagementFrame::ibss_dfs_params Dot11ManagementFrame::ibss_dfs_params::from_option(const option &opt)
|
||||
{
|
||||
if(opt.data_size() < ibss_dfs_params::minimum_size)
|
||||
Dot11ManagementFrame::ibss_dfs_params
|
||||
Dot11ManagementFrame::ibss_dfs_params::from_option(const option& opt) {
|
||||
if (opt.data_size() < ibss_dfs_params::minimum_size) {
|
||||
throw malformed_option();
|
||||
}
|
||||
ibss_dfs_params output;
|
||||
const uint8_t *ptr = opt.data_ptr(), *end = ptr + opt.data_size();
|
||||
const uint8_t* ptr = opt.data_ptr(), *end = ptr + opt.data_size();
|
||||
output.dfs_owner = ptr;
|
||||
ptr += output.dfs_owner.size();
|
||||
output.recovery_interval = *(ptr++);
|
||||
while(ptr != end) {
|
||||
while (ptr != end) {
|
||||
uint8_t first = *(ptr++);
|
||||
if(ptr == end)
|
||||
throw option_not_found();
|
||||
output.channel_map.push_back(std::make_pair(first, *(ptr++)));
|
||||
if (ptr == end) {
|
||||
throw malformed_option();
|
||||
}
|
||||
output.channel_map.push_back(make_pair(first, *(ptr++)));
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
Dot11ManagementFrame::country_params Dot11ManagementFrame::country_params::from_option(const option &opt)
|
||||
{
|
||||
if(opt.data_size() < country_params::minimum_size)
|
||||
Dot11ManagementFrame::country_params
|
||||
Dot11ManagementFrame::country_params::from_option(const option& opt) {
|
||||
if (opt.data_size() < country_params::minimum_size) {
|
||||
throw malformed_option();
|
||||
}
|
||||
country_params output;
|
||||
const uint8_t *ptr = opt.data_ptr(), *end = ptr + opt.data_size();
|
||||
std::copy(ptr, ptr + 3, std::back_inserter(output.country));
|
||||
const uint8_t* ptr = opt.data_ptr(), *end = ptr + opt.data_size();
|
||||
copy(ptr, ptr + 3, back_inserter(output.country));
|
||||
ptr += output.country.size();
|
||||
while(end - ptr >= 3) {
|
||||
while (end - ptr >= 3) {
|
||||
output.first_channel.push_back(*(ptr++));
|
||||
output.number_channels.push_back(*(ptr++));
|
||||
output.max_transmit_power.push_back(*(ptr++));
|
||||
}
|
||||
if(ptr != end)
|
||||
if (ptr != end) {
|
||||
throw malformed_option();
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
Dot11ManagementFrame::fh_pattern_type Dot11ManagementFrame::fh_pattern_type::from_option(const option &opt)
|
||||
{
|
||||
if(opt.data_size() < fh_pattern_type::minimum_size)
|
||||
Dot11ManagementFrame::fh_pattern_type
|
||||
Dot11ManagementFrame::fh_pattern_type::from_option(const option& opt) {
|
||||
if (opt.data_size() < fh_pattern_type::minimum_size) {
|
||||
throw malformed_option();
|
||||
}
|
||||
fh_pattern_type output;
|
||||
const uint8_t *ptr = opt.data_ptr(), *end = ptr + opt.data_size();
|
||||
const uint8_t* ptr = opt.data_ptr(), *end = ptr + opt.data_size();
|
||||
|
||||
output.flag = *(ptr++);
|
||||
output.number_of_sets = *(ptr++);
|
||||
@@ -563,11 +588,12 @@ Dot11ManagementFrame::fh_pattern_type Dot11ManagementFrame::fh_pattern_type::fro
|
||||
return output;
|
||||
}
|
||||
|
||||
Dot11ManagementFrame::channel_switch_type Dot11ManagementFrame::channel_switch_type::from_option(const option &opt)
|
||||
{
|
||||
if(opt.data_size() != sizeof(uint8_t) * 3)
|
||||
Dot11ManagementFrame::channel_switch_type
|
||||
Dot11ManagementFrame::channel_switch_type::from_option(const option& opt) {
|
||||
if (opt.data_size() != sizeof(uint8_t) * 3) {
|
||||
throw malformed_option();
|
||||
const uint8_t *ptr = opt.data_ptr();
|
||||
}
|
||||
const uint8_t* ptr = opt.data_ptr();
|
||||
channel_switch_type output;
|
||||
output.switch_mode = *(ptr++);
|
||||
output.new_channel = *(ptr++);
|
||||
@@ -575,41 +601,39 @@ Dot11ManagementFrame::channel_switch_type Dot11ManagementFrame::channel_switch_t
|
||||
return output;
|
||||
}
|
||||
|
||||
Dot11ManagementFrame::quiet_type Dot11ManagementFrame::quiet_type::from_option(const option &opt)
|
||||
{
|
||||
if(opt.data_size() != (sizeof(uint8_t) * 2 + sizeof(uint16_t) * 2))
|
||||
Dot11ManagementFrame::quiet_type
|
||||
Dot11ManagementFrame::quiet_type::from_option(const option& opt) {
|
||||
if (opt.data_size() != (sizeof(uint8_t) * 2 + sizeof(uint16_t) * 2)) {
|
||||
throw malformed_option();
|
||||
const uint8_t *ptr = opt.data_ptr();
|
||||
}
|
||||
quiet_type output;
|
||||
InputMemoryStream stream(opt.data_ptr(), opt.data_size());
|
||||
|
||||
output.quiet_count = *(ptr++);
|
||||
output.quiet_period = *(ptr++);
|
||||
const uint16_t *ptr_16 = (const uint16_t*)ptr;
|
||||
output.quiet_duration = Endian::le_to_host(*(ptr_16++));
|
||||
output.quiet_offset = Endian::le_to_host(*ptr_16);
|
||||
output.quiet_count = stream.read<uint8_t>();
|
||||
output.quiet_period = stream.read<uint8_t>();
|
||||
output.quiet_duration = stream.read_le<uint16_t>();
|
||||
output.quiet_offset = stream.read_le<uint16_t>();
|
||||
return output;
|
||||
}
|
||||
|
||||
Dot11ManagementFrame::bss_load_type Dot11ManagementFrame::bss_load_type::from_option(const option &opt)
|
||||
{
|
||||
if(opt.data_size() != sizeof(uint8_t) + 2 * sizeof(uint16_t))
|
||||
Dot11ManagementFrame::bss_load_type
|
||||
Dot11ManagementFrame::bss_load_type::from_option(const option& opt) {
|
||||
if (opt.data_size() != sizeof(uint8_t) + 2 * sizeof(uint16_t)) {
|
||||
throw malformed_option();
|
||||
}
|
||||
bss_load_type output;
|
||||
|
||||
const uint8_t *ptr = opt.data_ptr();
|
||||
std::memcpy(&output.station_count, ptr, sizeof(uint16_t));
|
||||
std::memcpy(&output.available_capacity, ptr + 3, sizeof(uint16_t));
|
||||
output.channel_utilization = ptr[2];
|
||||
output.station_count = Endian::le_to_host(output.station_count);
|
||||
output.available_capacity = Endian::le_to_host(output.available_capacity);
|
||||
InputMemoryStream stream(opt.data_ptr(), opt.data_size());
|
||||
output.station_count = stream.read_le<uint16_t>();
|
||||
output.channel_utilization = stream.read<uint8_t>();
|
||||
output.available_capacity = stream.read_le<uint16_t>();
|
||||
return output;
|
||||
}
|
||||
|
||||
Dot11ManagementFrame::tim_type Dot11ManagementFrame::tim_type::from_option(const option &opt)
|
||||
{
|
||||
if(opt.data_size() < 4 * sizeof(uint8_t))
|
||||
Dot11ManagementFrame::tim_type Dot11ManagementFrame::tim_type::from_option(const option& opt) {
|
||||
if (opt.data_size() < 4 * sizeof(uint8_t)) {
|
||||
throw malformed_option();
|
||||
const uint8_t *ptr = opt.data_ptr(), *end = ptr + opt.data_size();
|
||||
}
|
||||
const uint8_t* ptr = opt.data_ptr(), *end = ptr + opt.data_size();
|
||||
tim_type output;
|
||||
|
||||
output.dtim_count = *(ptr++);
|
||||
@@ -619,6 +643,7 @@ Dot11ManagementFrame::tim_type Dot11ManagementFrame::tim_type::from_option(const
|
||||
output.partial_virtual_bitmap.assign(ptr, end);
|
||||
return output;
|
||||
}
|
||||
} // namespace Tins
|
||||
|
||||
} // Tins
|
||||
|
||||
#endif // HAVE_DOT11
|
||||
|
||||
@@ -38,56 +38,54 @@ using Tins::Memory::InputMemoryStream;
|
||||
using Tins::Memory::OutputMemoryStream;
|
||||
|
||||
namespace Tins {
|
||||
/* Probe Request */
|
||||
|
||||
Dot11ProbeRequest::Dot11ProbeRequest(const address_type &dst_hw_addr,
|
||||
const address_type &src_hw_addr)
|
||||
: Dot11ManagementFrame(dst_hw_addr, src_hw_addr)
|
||||
{
|
||||
this->subtype(Dot11::PROBE_REQ);
|
||||
// Probe Request
|
||||
|
||||
Dot11ProbeRequest::Dot11ProbeRequest(const address_type& dst_hw_addr,
|
||||
const address_type& src_hw_addr)
|
||||
: Dot11ManagementFrame(dst_hw_addr, src_hw_addr) {
|
||||
subtype(Dot11::PROBE_REQ);
|
||||
}
|
||||
|
||||
Dot11ProbeRequest::Dot11ProbeRequest(const uint8_t *buffer, uint32_t total_sz)
|
||||
: Dot11ManagementFrame(buffer, total_sz)
|
||||
{
|
||||
Dot11ProbeRequest::Dot11ProbeRequest(const uint8_t* buffer, uint32_t total_sz)
|
||||
: Dot11ManagementFrame(buffer, total_sz) {
|
||||
InputMemoryStream stream(buffer, total_sz);
|
||||
stream.skip(management_frame_size());
|
||||
parse_tagged_parameters(stream);
|
||||
}
|
||||
|
||||
/* Probe Response */
|
||||
// Probe Response
|
||||
|
||||
Dot11ProbeResponse::Dot11ProbeResponse(const address_type &dst_hw_addr,
|
||||
const address_type &src_hw_addr)
|
||||
: Dot11ManagementFrame(dst_hw_addr, src_hw_addr), _body()
|
||||
{
|
||||
this->subtype(Dot11::PROBE_RESP);
|
||||
Dot11ProbeResponse::Dot11ProbeResponse(const address_type& dst_hw_addr,
|
||||
const address_type& src_hw_addr)
|
||||
: Dot11ManagementFrame(dst_hw_addr, src_hw_addr), body_() {
|
||||
subtype(Dot11::PROBE_RESP);
|
||||
}
|
||||
|
||||
Dot11ProbeResponse::Dot11ProbeResponse(const uint8_t *buffer, uint32_t total_sz)
|
||||
: Dot11ManagementFrame(buffer, total_sz)
|
||||
{
|
||||
Dot11ProbeResponse::Dot11ProbeResponse(const uint8_t* buffer, uint32_t total_sz)
|
||||
: Dot11ManagementFrame(buffer, total_sz) {
|
||||
InputMemoryStream stream(buffer, total_sz);
|
||||
stream.skip(management_frame_size());
|
||||
stream.read(_body);
|
||||
stream.read(body_);
|
||||
parse_tagged_parameters(stream);
|
||||
}
|
||||
|
||||
void Dot11ProbeResponse::timestamp(uint64_t new_timestamp) {
|
||||
this->_body.timestamp = Endian::host_to_le(new_timestamp);
|
||||
body_.timestamp = Endian::host_to_le(new_timestamp);
|
||||
}
|
||||
|
||||
void Dot11ProbeResponse::interval(uint16_t new_interval) {
|
||||
this->_body.interval = Endian::host_to_le(new_interval);
|
||||
body_.interval = Endian::host_to_le(new_interval);
|
||||
}
|
||||
|
||||
uint32_t Dot11ProbeResponse::header_size() const {
|
||||
return Dot11ManagementFrame::header_size() + sizeof(this->_body);
|
||||
return Dot11ManagementFrame::header_size() + sizeof(body_);
|
||||
}
|
||||
|
||||
void Dot11ProbeResponse::write_fixed_parameters(OutputMemoryStream& stream) {
|
||||
stream.write(_body);
|
||||
stream.write(body_);
|
||||
}
|
||||
|
||||
} // namespace Tins
|
||||
|
||||
#endif // HAVE_DOT11
|
||||
|
||||
Reference in New Issue
Block a user