1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-30 05:24:26 +01:00

Started refactoring 802.11 control frames.

This commit is contained in:
Matias Fontanini
2011-09-05 12:03:44 -03:00
parent 477a757f5a
commit 65f689027d
2 changed files with 783 additions and 4 deletions

View File

@@ -829,3 +829,241 @@ uint32_t Tins::Dot11QoSData::write_fixed_parameters(uint8_t *buffer, uint32_t to
*(uint16_t*)buffer = this->_qos_control;
return sz;
}
/* Dot11Control */
Tins::Dot11Control::Dot11Control(const uint8_t* dst_addr, PDU* child) : Dot11(dst_addr, child) {
type(CONTROL);
}
Tins::Dot11ControlTA::Dot11ControlTA(const std::string& iface, const uint8_t* dst_addr, PDU* child) throw (std::runtime_error) : Dot11(iface, dst_addr, child) {
type(CONTROL);
}
Tins::Dot11ControlTA::Dot11ControlTA(uint32_t iface_index, const uint8_t* dst_addr, PDU* child) : Dot11(iface_index, dst_addr, child) {
type(CONTROL);
}
Tins::Dot11ControlTA::Dot11ControlTA(const uint8_t *buffer, uint32_t total_sz) : Dot11(buffer, total_sz) {
}
/* Dot11ControlTA */
Tins::Dot11ControlTA::Dot11ControlTA(const uint8_t* dst_addr, const uint8_t *target_addres, PDU* child) : Dot11Control(dst_addr, child) {
if(target_addr)
target_addr(target_address);
else
std::memset(_taddr, 0, sizeof(_taddr));
}
Tins::Dot11ControlTA::Dot11ControlTA(const std::string& iface, const uint8_t* dst_addr, const uint8_t *target_addr, PDU* child) throw (std::runtime_error) : Dot11Control(iface, dst_addr, child){
if(target_addr)
target_addr(target_address);
else
std::memset(_taddr, 0, sizeof(_taddr));
}
Tins::Dot11ControlTA::Dot11ControlTA(uint32_t iface_index, const uint8_t* dst_addr, const uint8_t *target_addr, PDU* child) : Dot11Control(iface_index, dst_addr, child) {
if(target_addr)
target_addr(target_address);
else
std::memset(_taddr, 0, sizeof(_taddr));
}
Tins::Dot11ControlTA::Dot11ControlTA(const uint8_t *buffer, uint32_t total_sz) : Dot11Control(buffer, total_sz) {
buffer += sizeof(ieee80211_header);
total_sz -= sizeof(ieee80211_header);
if(total_sz < sizeof(_taddr))
throw std::runtime_error("Not enough size for an IEEE 802.11 RTS frame in the buffer.");
std::memcpy(_taddr, buffer, sizeof(_taddr));
}
uint32_t Tins::Dot11ControlTA::header_size() const {
return Dot11::header_size() + sizeof(_taddr);
}
uint32_t Tins::Dot11ControlTA::write_ext_header(uint8_t *buffer, uint32_t total_sz) {
assert(total_sz >= sizeof(_taddr));
std::memcpy(buffer, _taddr, sizeof(_taddr));
return sizeof(_taddr);
}
void Tins::Dot11ControlTA::target_addr(const uint8_t *addr) {
std::memcpy(_taddr, addr, sizeof(_taddr));
}
/* Dot11RTS */
Tins::Dot11RTS::Dot11RTS(const uint8_t* dst_addr , const uint8_t* target_addr, PDU* child) : Dot11ControlTA(dst_addr, target_addr, child) {
subtype(RTS);
}
Tins::Dot11RTS::Dot11RTS(const std::string& iface, const uint8_t* dst_addr, const uint8_t *target_addr, PDU* child) throw (std::runtime_error) : Dot11ControlTA(iface, dst_addr, target_addr, child) {
subtype(RTS);
}
Tins::Dot11RTS::Dot11RTS(uint32_t iface_index, const uint8_t* dst_hw_addr, const uint8_t *target_addr, PDU* child) : Dot11ControlTA(iface_index, dst_addr, target_addr, child) {
subtype(RTS);
}
Tins::Dot11RTS::Dot11RTS(const uint8_t *buffer, uint32_t total_sz) : Dot11ControlTA(buffer, total_sz) {
}
/* Dot11PSPoll */
Tins::Dot11PSPoll::Dot11PSPoll(const uint8_t* dst_addr , const uint8_t* target_addr, PDU* child) : Dot11ControlTA(dst_addr, target_addr, child) {
subtype(PS);
}
Tins::Dot11PSPoll::Dot11PSPoll(const std::string& iface, const uint8_t* dst_addr, const uint8_t *target_addr, PDU* child) throw (std::runtime_error) : Dot11ControlTA(iface, dst_addr, target_addr, child) {
subtype(PS);
}
Tins::Dot11PSPoll::Dot11PSPoll(uint32_t iface_index, const uint8_t* dst_hw_addr, const uint8_t *target_addr, PDU* child) : Dot11ControlTA(iface_index, dst_addr, target_addr, child) {
subtype(PS);
}
Tins::Dot11PSPoll::Dot11PSPoll(const uint8_t *buffer, uint32_t total_sz) : Dot11ControlTA(buffer, total_sz) {
}
/* Dot11CFEnd */
Tins::Dot11CFEnd::Dot11CFEnd(const uint8_t* dst_addr , const uint8_t* target_addr, PDU* child) : Dot11ControlTA(dst_addr, target_addr, child) {
subtype(CF_END);
}
Tins::Dot11CFEnd::Dot11CFEnd(const std::string& iface, const uint8_t* dst_addr, const uint8_t *target_addr, PDU* child) throw (std::runtime_error) : Dot11ControlTA(iface, dst_addr, target_addr, child) {
subtype(CF_END);
}
Tins::Dot11CFEnd::Dot11CFEnd(uint32_t iface_index, const uint8_t* dst_hw_addr, const uint8_t *target_addr, PDU* child) : Dot11ControlTA(iface_index, dst_addr, target_addr, child) {
subtype(CF_END);
}
Tins::Dot11CFEnd::Dot11CFEnd(const uint8_t *buffer, uint32_t total_sz) : Dot11ControlTA(buffer, total_sz) {
}
/* Dot11EndCFAck */
Tins::Dot11EndCFAck::Dot11EndCFAck(const uint8_t* dst_addr , const uint8_t* target_addr, PDU* child) : Dot11ControlTA(dst_addr, target_addr, child) {
subtype(CF_END_ACK);
}
Tins::Dot11EndCFAck::Dot11EndCFAck(const std::string& iface, const uint8_t* dst_addr, const uint8_t *target_addr, PDU* child) throw (std::runtime_error) : Dot11ControlTA(iface, dst_addr, target_addr, child) {
subtype(CF_END_ACK);
}
Tins::Dot11EndCFAck::Dot11EndCFAck(uint32_t iface_index, const uint8_t* dst_hw_addr, const uint8_t *target_addr, PDU* child) : Dot11ControlTA(iface_index, dst_addr, target_addr, child) {
subtype(CF_END_ACK);
}
Tins::Dot11EndCFAck::Dot11EndCFAck(const uint8_t *buffer, uint32_t total_sz) : Dot11ControlTA(buffer, total_sz) {
}
/* Dot11Ack */
Tins::Dot11Ack::Dot11Ack(const uint8_t* dst_addr , PDU* child) : Dot11(dst_addr, target_addr, child) {
subtype(ACK);
}
Tins::Dot11Ack::Dot11Ack(const std::string& iface, onst uint8_t *target_addr, PDU* child) throw (std::runtime_error) : Dot11(iface, dst_addr, child) {
subtype(ACK);
}
Tins::Dot11Ack::Dot11Ack(uint32_t iface_index, const uint8_t* dst_hw_addr, PDU* child) : Dot11(iface_index, dst_addr, child) {
subtype(ACK);
}
Tins::Dot11Ack::Dot11Ack(const uint8_t *buffer, uint32_t total_sz) : Dot11(buffer, total_sz) {
}
/* Dot11BlockAck */
Tins::Dot11BlockAckRequest::Dot11BlockAckRequest(const uint8_t* dst_addr , const uint8_t* target_addr, PDU* child) : Dot11ControlTA(dst_addr, target_addr, child) {
init_block_ack();
}
Tins::Dot11BlockAckRequest::Dot11BlockAckRequest(const std::string& iface, const uint8_t* dst_addr, const uint8_t *target_addr, PDU* child) throw (std::runtime_error) : Dot11ControlTA(iface, dst_addr, target_addr, child) {
init_block_ack();
}
Tins::Dot11BlockAckRequest::Dot11BlockAckRequest(uint32_t iface_index, const uint8_t* dst_hw_addr, const uint8_t *target_addr, PDU* child) : Dot11ControlTA(iface_index, dst_addr, target_addr, child) {
init_block_ack();
}
Tins::Dot11BlockAckRequest::Dot11BlockAckRequest(const uint8_t *buffer, uint32_t total_sz) : Dot11ControlTA(buffer, total_sz) {
uint32_t padding = controlta_size();
buffer += padding;
total_sz -= padding;
if(total_sz < sizeof(_bar_control) + sizeof(_start_sequence))
throw std::runtime_error("Not enough size for an IEEE 802.11 Block Ack frame in the buffer.");
std::memcpy(&_bar_control, buffer, sizeof(_bar_control));
buffer += sizeof(_bar_control);
std::memcpy(&_start_sequence, buffer, sizeof(_start_sequence));
}
void Tins::Dot11BlockAckRequest::init_block_ack() {
subtype(BLOCK_ACK);
std::memset(&_bar_control, 0, sizeof(_bar_control));
std::memset(&_start_sequence, 0, sizeof(_start_sequence));
}
uint32_t Tins::Dot11BlockAckRequest::write_ext_header(uint8_t *buffer, uint32_t total_sz) {
uint32_t parent_size = Dot11ControlTA::write_ext_header(buffer, total_sz);
buffer += parent_size;
std::memcpy(buffer, _bar_control, sizeof(_bar_control));
buffer += sizeof(_bar_control);
std::memcpy(buffer, _start_sequence, sizeof(_start_sequence));
return parent_size + sizeof(_start_sequence);
}
void Tins::Dot11BlockAckRequest::bar_control(uint16_t bar) {
std::memcpy(&_bar_control, &bar, sizeof(bar));
}
void Tins::Dot11BlockAckRequest::start_sequence(uint16_t seq) {
std::memcpy(&_start_sequence, &seq, sizeof(seq));
}
uint32_t Tins::Dot11BlockAckRequest::header_size() const {
return Dot11ControlTA::header_size() + sizeof(_start_sequence) + sizeof(_start_sequence);
}
/* Dot11BlockAck */
Tins::Dot11BlockAck::Dot11BlockAck(const uint8_t* dst_addr , const uint8_t* target_addr, PDU* child) : Dot11BlockAckRequest(dst_addr, target_addr, child) {
std::memset(_bitmap, 0, sizeof(_bitmap));
}
Tins::Dot11BlockAck::Dot11BlockAck(const std::string& iface, const uint8_t* dst_addr, const uint8_t *target_addr, PDU* child) throw (std::runtime_error) : Dot11BlockAckRequest(iface, dst_addr, target_addr, child) {
std::memset(_bitmap, 0, sizeof(_bitmap));
}
Tins::Dot11BlockAck::Dot11BlockAck(uint32_t iface_index, const uint8_t* dst_hw_addr, const uint8_t *target_addr, PDU* child) : Dot11BlockAckRequest(iface_index, dst_addr, target_addr, child) {
std::memset(_bitmap, 0, sizeof(_bitmap));
}
Tins::Dot11BlockAck::Dot11BlockAck(const uint8_t *buffer, uint32_t total_sz) : Dot11BlockAckRequest(buffer, total_sz) {
uint32_t padding = blockack_request_size();
buffer += padding;
total_sz -= padding;
if(total_sz < sizeof(_bitmap))
throw std::runtime_error("Not enough size for an IEEE 802.11 Block Ack frame in the buffer.");
std::memcpy(&_bitmap, buffer, sizeof(_bitmap));
}
void Tins::Dot11BlockAck::bitmap(const uint8_t bit) {
std::memcpy(_bitmap, bit, sizeof(_bitmap));
}
uint32_t Tins::Dot11BlockAck::write_ext_header(uint8_t *buffer, uint32_t total_sz) {
uint32_t parent_size = Dot11BlockAckRequest::write_ext_header(buffer, total_sz);
buffer += parent_size;
std::memcpy(buffer, _bitmap, sizeof(_bitmap));
return parent_size + sizeof(_bitmap);
}
uint32_t Tins::Dot11BlockAck::header_size() const {
return Dot11BlockAckRequest::header_size() + sizeof(_bitmap));
}