mirror of
https://github.com/mfontanini/libtins
synced 2026-01-26 12:01:34 +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:
73
src/llc.cpp
73
src/llc.cpp
@@ -44,28 +44,26 @@ const uint8_t LLC::GLOBAL_DSAP_ADDR = 0xFF;
|
||||
const uint8_t LLC::NULL_ADDR = 0x00;
|
||||
|
||||
LLC::LLC()
|
||||
: _header(), control_field(), _type(LLC::INFORMATION)
|
||||
{
|
||||
control_field_length = 2;
|
||||
information_field_length = 0;
|
||||
: header_(), control_field(), type_(LLC::INFORMATION) {
|
||||
control_field_length_ = 2;
|
||||
information_field_length_ = 0;
|
||||
}
|
||||
|
||||
LLC::LLC(uint8_t dsap, uint8_t ssap)
|
||||
: control_field(), _type(LLC::INFORMATION)
|
||||
{
|
||||
_header.dsap = dsap;
|
||||
_header.ssap = ssap;
|
||||
control_field_length = 2;
|
||||
information_field_length = 0;
|
||||
: control_field(), type_(LLC::INFORMATION) {
|
||||
header_.dsap = dsap;
|
||||
header_.ssap = ssap;
|
||||
control_field_length_ = 2;
|
||||
information_field_length_ = 0;
|
||||
}
|
||||
|
||||
LLC::LLC(const uint8_t *buffer, uint32_t total_sz) {
|
||||
LLC::LLC(const uint8_t* buffer, uint32_t total_sz) {
|
||||
InputMemoryStream stream(buffer, total_sz);
|
||||
stream.read(_header);
|
||||
stream.read(header_);
|
||||
if (!stream) {
|
||||
throw malformed_packet();
|
||||
}
|
||||
information_field_length = 0;
|
||||
information_field_length_ = 0;
|
||||
if ((*stream.pointer() & 0x03) == LLC::UNNUMBERED) {
|
||||
type(LLC::UNNUMBERED);
|
||||
stream.read(control_field.unnumbered);
|
||||
@@ -73,7 +71,7 @@ LLC::LLC(const uint8_t *buffer, uint32_t total_sz) {
|
||||
}
|
||||
else {
|
||||
type((Format)(*stream.pointer() & 0x03));
|
||||
control_field_length = 2;
|
||||
control_field_length_ = 2;
|
||||
stream.read(control_field.info);
|
||||
}
|
||||
if (stream) {
|
||||
@@ -88,51 +86,52 @@ LLC::LLC(const uint8_t *buffer, uint32_t total_sz) {
|
||||
|
||||
void LLC::group(bool value) {
|
||||
if (value) {
|
||||
_header.dsap |= 0x01;
|
||||
header_.dsap |= 0x01;
|
||||
}
|
||||
else {
|
||||
_header.dsap &= 0xFE;
|
||||
header_.dsap &= 0xFE;
|
||||
}
|
||||
}
|
||||
|
||||
void LLC::dsap(uint8_t new_dsap) {
|
||||
_header.dsap = new_dsap;
|
||||
header_.dsap = new_dsap;
|
||||
}
|
||||
|
||||
void LLC::response(bool value) {
|
||||
if (value) {
|
||||
_header.ssap |= 0x01;
|
||||
header_.ssap |= 0x01;
|
||||
}
|
||||
else {
|
||||
_header.ssap &= 0xFE;
|
||||
header_.ssap &= 0xFE;
|
||||
}
|
||||
}
|
||||
|
||||
void LLC::ssap(uint8_t new_ssap) {
|
||||
_header.ssap = new_ssap;
|
||||
header_.ssap = new_ssap;
|
||||
}
|
||||
|
||||
void LLC::type(LLC::Format type) {
|
||||
_type = type;
|
||||
type_ = type;
|
||||
switch (type) {
|
||||
case LLC::INFORMATION:
|
||||
control_field_length = 2;
|
||||
control_field_length_ = 2;
|
||||
control_field.info.type_bit = 0;
|
||||
break;
|
||||
case LLC::SUPERVISORY:
|
||||
control_field_length = 2;
|
||||
control_field_length_ = 2;
|
||||
control_field.super.type_bit = 1;
|
||||
break;
|
||||
case LLC::UNNUMBERED:
|
||||
control_field_length = 1;
|
||||
control_field_length_ = 1;
|
||||
control_field.unnumbered.type_bits = 3;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void LLC::send_seq_number(uint8_t seq_number) {
|
||||
if (type() != LLC::INFORMATION)
|
||||
if (type() != LLC::INFORMATION) {
|
||||
return;
|
||||
}
|
||||
control_field.info.send_seq_num = seq_number;
|
||||
}
|
||||
|
||||
@@ -165,14 +164,16 @@ void LLC::poll_final(bool value) {
|
||||
}
|
||||
|
||||
void LLC::supervisory_function(LLC::SupervisoryFunctions new_func) {
|
||||
if (type() != LLC::SUPERVISORY)
|
||||
if (type() != LLC::SUPERVISORY) {
|
||||
return;
|
||||
}
|
||||
control_field.super.supervisory_func = new_func;
|
||||
}
|
||||
|
||||
void LLC::modifier_function(LLC::ModifierFunctions mod_func) {
|
||||
if (type() != LLC::UNNUMBERED)
|
||||
if (type() != LLC::UNNUMBERED) {
|
||||
return;
|
||||
}
|
||||
control_field.unnumbered.mod_func1 = mod_func >> 3;
|
||||
control_field.unnumbered.mod_func2 = mod_func & 0x07;
|
||||
}
|
||||
@@ -182,26 +183,26 @@ void LLC::add_xid_information(uint8_t xid_id, uint8_t llc_type_class, uint8_t re
|
||||
xid[0] = xid_id;
|
||||
xid[1] = llc_type_class;
|
||||
xid[2] = receive_window;
|
||||
information_field_length += static_cast<uint8_t>(xid.size());
|
||||
information_fields.push_back(xid);
|
||||
information_field_length_ += static_cast<uint8_t>(xid.size());
|
||||
information_fields_.push_back(xid);
|
||||
}
|
||||
|
||||
uint32_t LLC::header_size() const {
|
||||
return sizeof(_header) + control_field_length + information_field_length;
|
||||
return sizeof(header_) + control_field_length_ + information_field_length_;
|
||||
}
|
||||
|
||||
void LLC::clear_information_fields() {
|
||||
information_field_length = 0;
|
||||
information_fields.clear();
|
||||
information_field_length_ = 0;
|
||||
information_fields_.clear();
|
||||
}
|
||||
|
||||
void LLC::write_serialization(uint8_t *buffer, uint32_t total_sz, const Tins::PDU *parent) {
|
||||
void LLC::write_serialization(uint8_t* buffer, uint32_t total_sz, const Tins::PDU* parent) {
|
||||
OutputMemoryStream stream(buffer, total_sz);
|
||||
if (inner_pdu() && inner_pdu()->pdu_type() == PDU::STP) {
|
||||
dsap(0x42);
|
||||
ssap(0x42);
|
||||
}
|
||||
stream.write(_header);
|
||||
stream.write(header_);
|
||||
switch (type()) {
|
||||
case LLC::UNNUMBERED:
|
||||
stream.write(control_field.unnumbered);
|
||||
@@ -214,9 +215,9 @@ void LLC::write_serialization(uint8_t *buffer, uint32_t total_sz, const Tins::PD
|
||||
break;
|
||||
}
|
||||
|
||||
for (field_list::const_iterator it = information_fields.begin(); it != information_fields.end(); it++) {
|
||||
for (field_list::const_iterator it = information_fields_.begin(); it != information_fields_.end(); it++) {
|
||||
stream.write(it->begin(), it->end());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} // Tins
|
||||
|
||||
Reference in New Issue
Block a user