From 9d990f671926483acbc4a7b86bd4854448533356 Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Mon, 5 Sep 2011 14:41:30 -0300 Subject: [PATCH 1/6] Fixed several Dot11 bugs. --- include/dot11.h | 67 +++++++++++++++++++++++++++++----------- include/pdu.h | 6 ++++ src/dot11.cpp | 81 +++++++++++++++++++++++++++++++++---------------- 3 files changed, 110 insertions(+), 44 deletions(-) diff --git a/include/dot11.h b/include/dot11.h index b6e18cd..b1eeef8 100644 --- a/include/dot11.h +++ b/include/dot11.h @@ -114,6 +114,7 @@ namespace Tins { * */ enum ControlSubtypes { + BLOCK_ACK_REQ = 8, BLOCK_ACK = 9, PS = 10, RTS = 11, @@ -988,7 +989,6 @@ namespace Tins { * \sa PDU::header_size() */ uint32_t header_size() const; - protected: struct ExtendedHeader { uint8_t addr2[6]; @@ -1028,7 +1028,6 @@ namespace Tins { uint32_t write_ext_header(uint8_t *buffer, uint32_t total_sz); void copy_ext_header(const Dot11ManagementFrame *other); - private: ExtendedHeader _ext_header; uint8_t _addr4[6]; @@ -1036,8 +1035,18 @@ namespace Tins { }; class Dot11DataFrame : public Dot11 { - public: + /** + * \brief Constructor which creates a Dot11DataFrame object from a buffer and adds all identifiable + * PDUs found in the buffer as children of this one. + * \param buffer The buffer from which this PDU will be constructed. + * \param total_sz The total size of the buffer. + */ + Dot11DataFrame(uint32_t iface_index, const uint8_t *dst_hw_addr = 0, const uint8_t *src_hw_addr = 0, PDU* child = 0); + Dot11DataFrame(const uint8_t *dst_hw_addr = 0, const uint8_t *src_hw_addr = 0, PDU* child = 0); + Dot11DataFrame(const std::string &iface, const uint8_t *dst_hw_addr, const uint8_t *src_hw_addr, PDU* child = 0) throw (std::runtime_error); + Dot11DataFrame(const uint8_t *buffer, uint32_t total_sz); + Dot11DataFrame(const Dot11DataFrame &other); /** * \brief Getter for the second address. * @@ -1116,6 +1125,11 @@ namespace Tins { */ uint32_t header_size() const; + /** + * \brief Getter for the PDU's type. + * \sa PDU::pdu_type + */ + PDUType pdu_type() const { return PDU::DOT11_DATA; } protected: struct ExtendedHeader { uint8_t addr2[6]; @@ -1131,18 +1145,6 @@ namespace Tins { } __attribute__((__packed__)) seq_control; } __attribute__((__packed__)); - /** - * \brief Constructor which creates a Dot11DataFrame object from a buffer and adds all identifiable - * PDUs found in the buffer as children of this one. - * \param buffer The buffer from which this PDU will be constructed. - * \param total_sz The total size of the buffer. - */ - Dot11DataFrame(uint32_t iface_index, const uint8_t *dst_hw_addr = 0, const uint8_t *src_hw_addr = 0, PDU* child = 0); - Dot11DataFrame(const uint8_t *dst_hw_addr = 0, const uint8_t *src_hw_addr = 0, PDU* child = 0); - Dot11DataFrame(const std::string &iface, const uint8_t *dst_hw_addr, const uint8_t *src_hw_addr, PDU* child = 0) throw (std::runtime_error); - Dot11DataFrame(const uint8_t *buffer, uint32_t total_sz); - Dot11DataFrame(const Dot11DataFrame &other); - uint32_t write_ext_header(uint8_t *buffer, uint32_t total_sz); void copy_ext_header(const Dot11DataFrame *other); @@ -1298,7 +1300,6 @@ namespace Tins { void copy_fields(const Dot11Beacon *other); uint32_t write_fixed_parameters(uint8_t *buffer, uint32_t total_sz); - BeaconBody _body; }; @@ -1724,6 +1725,12 @@ namespace Tins { * \sa PDU::header_size() */ uint32_t header_size() const; + + /** + * \brief Getter for the PDU's type. + * \sa PDU::pdu_type + */ + PDUType pdu_type() const { return PDU::DOT11_QOS_DATA; } private: void copy_fields(const Dot11QoSData *other); uint32_t write_fixed_parameters(uint8_t *buffer, uint32_t total_sz); @@ -1778,6 +1785,12 @@ namespace Tins { * \param total_sz The total size of the buffer. */ Dot11Control(const uint8_t *buffer, uint32_t total_sz); + + /** + * \brief Getter for the PDU's type. + * \sa PDU::pdu_type + */ + PDUType pdu_type() const { return PDU::DOT11_CONTROL; } }; /** @@ -1853,7 +1866,7 @@ namespace Tins { /** * \brief Getter for the control ta additional fields size. */ - uint32_t controlta_size() const { return sizeof(_taddr); } + uint32_t controlta_size() const { return sizeof(_taddr) + sizeof(ieee80211_header); } uint32_t write_ext_header(uint8_t *buffer, uint32_t total_sz); private: @@ -1907,6 +1920,12 @@ namespace Tins { * \param total_sz The total size of the buffer. */ Dot11RTS(const uint8_t *buffer, uint32_t total_sz); + + /** + * \brief Getter for the PDU's type. + * \sa PDU::pdu_type + */ + PDUType pdu_type() const { return PDU::DOT11_RTS; } }; class Dot11PSPoll : public Dot11ControlTA { @@ -2094,6 +2113,12 @@ namespace Tins { * \param total_sz The total size of the buffer. */ Dot11Ack(const uint8_t *buffer, uint32_t total_sz); + + /** + * \brief Getter for the PDU's type. + * \sa PDU::pdu_type + */ + PDUType pdu_type() const { return PDU::DOT11_ACK; } }; /** @@ -2268,10 +2293,16 @@ namespace Tins { * \param bit The new bitmap field to be set. */ void bitmap(const uint8_t *bit); + + /** + * \brief Getter for the PDU's type. + * \sa PDU::pdu_type + */ + PDUType pdu_type() const { return PDU::DOT11_BLOCK_ACK; } private: uint32_t write_ext_header(uint8_t *buffer, uint32_t total_sz); - uint8_t _bitmap[128]; + uint8_t _bitmap[8]; }; }; diff --git a/include/pdu.h b/include/pdu.h index c6cc06a..7f5ca29 100644 --- a/include/pdu.h +++ b/include/pdu.h @@ -53,6 +53,12 @@ namespace Tins { RAW, ETHERNET_II, DOT11, + DOT11_DATA, + DOT11_QOS_DATA, + DOT11_CONTROL, + DOT11_ACK, + DOT11_BLOCK_ACK, + DOT11_RTS, SNAP, RADIOTAP, IP, diff --git a/src/dot11.cpp b/src/dot11.cpp index 71176e8..ff57668 100644 --- a/src/dot11.cpp +++ b/src/dot11.cpp @@ -208,17 +208,17 @@ bool Tins::Dot11::send(PacketSender* sender) { void Tins::Dot11::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent) { uint32_t my_sz = header_size(); assert(total_sz >= my_sz); - memcpy(buffer, &this->_header, sizeof(ieee80211_header)); - buffer += sizeof(ieee80211_header); - total_sz -= sizeof(ieee80211_header); + memcpy(buffer, &_header, sizeof(_header)); + buffer += sizeof(_header); + total_sz -= sizeof(_header); uint32_t written = this->write_ext_header(buffer, total_sz); buffer += written; total_sz -= written; - uint32_t child_len = write_fixed_parameters(buffer, total_sz - sizeof(ieee80211_header) - _options_size); + uint32_t child_len = write_fixed_parameters(buffer, total_sz - _options_size); buffer += child_len; - assert(total_sz > child_len + _options_size); + assert(total_sz >= child_len + _options_size); for(std::list::const_iterator it = _options.begin(); it != _options.end(); ++it) { *(buffer++) = it->option; *(buffer++) = it->length; @@ -233,11 +233,33 @@ Tins::PDU *Tins::Dot11::from_bytes(const uint8_t *buffer, uint32_t total_sz) { throw std::runtime_error("Not enough size for a IEEE 802.11 header in the buffer."); const ieee80211_header *hdr = (const ieee80211_header*)buffer; PDU *ret = 0; - if(hdr->control.type == 0 && hdr->control.subtype == 8) { + if(hdr->control.type == MANAGEMENT && hdr->control.subtype == 8) { if(total_sz < sizeof(_header)) throw std::runtime_error("Not enough size for an IEEE 802.11 header in the buffer."); ret = new Dot11Beacon(buffer, total_sz); } + else if(hdr->control.type == DATA){ + if(hdr->control.subtype <= 4) + ret = new Dot11DataFrame(buffer, total_sz); + else + ret = new Dot11QoSData(buffer, total_sz); + } + 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 ret = new Dot11(buffer, total_sz); return ret; @@ -261,24 +283,30 @@ Tins::Dot11ManagementFrame::Dot11ManagementFrame(const uint8_t *buffer, uint32_t Tins::Dot11ManagementFrame::Dot11ManagementFrame(const uint8_t *dst_hw_addr, const uint8_t *src_hw_addr) : Dot11(dst_hw_addr) { this->type(Dot11::MANAGEMENT); - this->addr2(src_hw_addr); + if(src_hw_addr) + addr2(src_hw_addr); + else + std::memset(_ext_header.addr2, 0, sizeof(_ext_header.addr2)); } Tins::Dot11ManagementFrame::Dot11ManagementFrame(const std::string &iface, const uint8_t *dst_hw_addr, const uint8_t *src_hw_addr) throw (std::runtime_error) : Dot11(iface, dst_hw_addr) { this->type(Dot11::MANAGEMENT); - this->addr2(src_hw_addr); + if(src_hw_addr) + addr2(src_hw_addr); + else + std::memset(_ext_header.addr2, 0, sizeof(_ext_header.addr2)); } Tins::Dot11ManagementFrame::Dot11ManagementFrame(const Dot11ManagementFrame &other) : Dot11(other) { - + copy_ext_header(&other); } void Tins::Dot11ManagementFrame::copy_ext_header(const Dot11ManagementFrame* other) { Dot11::copy_80211_fields(other); - std::memcpy(&this->_ext_header, &other->_ext_header, sizeof(this->_ext_header)); - std::memcpy(this->_addr4, other->_addr4, 6); + std::memcpy(&_ext_header, &other->_ext_header, sizeof(_ext_header)); + std::memcpy(_addr4, other->_addr4, 6); } uint32_t Tins::Dot11ManagementFrame::header_size() const { @@ -309,15 +337,14 @@ void Tins::Dot11ManagementFrame::addr4(const uint8_t* new_addr4) { } uint32_t Tins::Dot11ManagementFrame::write_ext_header(uint8_t *buffer, uint32_t total_sz) { - uint32_t written = sizeof(this->_ext_header); - memcpy(buffer, &this->_ext_header, sizeof(this->_ext_header)); - buffer += sizeof(this->_ext_header); - if (this->from_ds() && this->to_ds()) { + uint32_t written = sizeof(_ext_header); + memcpy(buffer, &_ext_header, sizeof(this->_ext_header)); + buffer += sizeof(_ext_header); + if (from_ds() && to_ds()) { written += 6; - memcpy(buffer, this->_addr4, 6); + memcpy(buffer, _addr4, 6); } return written; - } void Tins::Dot11ManagementFrame::ssid(const std::string &new_ssid) { @@ -481,9 +508,7 @@ uint32_t Tins::Dot11DataFrame::write_ext_header(uint8_t *buffer, uint32_t total_ } -/* - * Beacon - */ +/* Dot11Beacon */ Tins::Dot11Beacon::Dot11Beacon(const uint8_t* dst_hw_addr, const uint8_t* src_hw_addr) : Dot11ManagementFrame() { this->subtype(Dot11::BEACON); @@ -509,7 +534,7 @@ Tins::Dot11Beacon::Dot11Beacon(const uint8_t *buffer, uint32_t total_sz) : Dot11 } Tins::Dot11Beacon::Dot11Beacon(const Dot11Beacon &other) : Dot11ManagementFrame(other) { - + copy_fields(&other); } Tins::Dot11Beacon &Tins::Dot11Beacon::operator= (const Dot11Beacon &other) { @@ -594,11 +619,11 @@ bool Tins::Dot11Beacon::rsn_information(RSNInformation *rsn) { } uint32_t Tins::Dot11Beacon::header_size() const { - return Dot11ManagementFrame::header_size() + sizeof(BeaconBody); + return Dot11ManagementFrame::header_size() + sizeof(_body); } uint32_t Tins::Dot11Beacon::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) { - uint32_t sz = sizeof(BeaconBody); + uint32_t sz = sizeof(_body); assert(sz <= total_sz); memcpy(buffer, &this->_body, sz); return sz; @@ -876,8 +901,9 @@ Tins::Dot11QoSData::Dot11QoSData(uint32_t iface_index, const uint8_t* dst_hw_add } Tins::Dot11QoSData::Dot11QoSData(const uint8_t *buffer, uint32_t total_sz) : Dot11DataFrame(buffer, total_sz) { - buffer += sizeof(ieee80211_header); - total_sz -= sizeof(ieee80211_header); + uint32_t sz = Dot11DataFrame::header_size(); + buffer += sz; + total_sz -= sz; assert(total_sz >= sizeof(this->_qos_control)); this->_qos_control = *(uint16_t*)buffer; total_sz -= sizeof(uint16_t); @@ -1092,7 +1118,7 @@ Tins::Dot11BlockAckRequest::Dot11BlockAckRequest(const uint8_t *buffer, uint32_t } void Tins::Dot11BlockAckRequest::init_block_ack() { - subtype(BLOCK_ACK); + subtype(BLOCK_ACK_REQ); std::memset(&_bar_control, 0, sizeof(_bar_control)); std::memset(&_start_sequence, 0, sizeof(_start_sequence)); } @@ -1120,14 +1146,17 @@ uint32_t Tins::Dot11BlockAckRequest::header_size() const { /* Dot11BlockAck */ Tins::Dot11BlockAck::Dot11BlockAck(const uint8_t* dst_addr , const uint8_t* target_addr, PDU* child) : Dot11BlockAckRequest(dst_addr, target_addr, child) { + subtype(BLOCK_ACK); 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) { + subtype(BLOCK_ACK); std::memset(_bitmap, 0, sizeof(_bitmap)); } Tins::Dot11BlockAck::Dot11BlockAck(uint32_t iface_index, const uint8_t* dst_addr, const uint8_t *target_addr, PDU* child) : Dot11BlockAckRequest(iface_index, dst_addr, target_addr, child) { + subtype(BLOCK_ACK); std::memset(_bitmap, 0, sizeof(_bitmap)); } From fc480550b024daa706112fca45f6b42be92e9284 Mon Sep 17 00:00:00 2001 From: Santiago Alessandri Date: Mon, 5 Sep 2011 14:42:55 -0300 Subject: [PATCH 2/6] Autoconf and Automake files for compiling and installing the library --- Makefile.in | 14 +++++-- configure | 102 ++++++++++++++++++++++++++++++++++++++++++++++++--- configure.ac | 5 ++- 3 files changed, 110 insertions(+), 11 deletions(-) diff --git a/Makefile.in b/Makefile.in index 08ee260..ff89f4f 100644 --- a/Makefile.in +++ b/Makefile.in @@ -1,11 +1,11 @@ CXX=@CXX@ -CFLAGS=-c -Wall @CFLAGS@ -DTINS_VERSION=@PACKAGE_VERSION@ -LDFLAGS=-lpcap +CFLAGS=-c -Wall -fPIC @CFLAGS@ -DTINS_VERSION=@PACKAGE_VERSION@ +LDFLAGS=-lpcap -shared -Wl,-soname,libtins.so SOURCES=$(wildcard src/*.cpp) OBJECTS=$(SOURCES:.cpp=.o) -INCLUDE = -Iinclude/ -EXECUTABLE=client +INCLUDE=-Iinclude/ +EXECUTABLE=libtins.so all: $(SOURCES) $(EXECUTABLE) @@ -21,3 +21,9 @@ $(EXECUTABLE): $(OBJECTS) clean: rm $(OBJECTS) $(EXECUTABLE) + +install: + rm -r /usr/include/tins + mkdir /usr/include/tins + cp include/*.h /usr/include/tins/ + cp $(EXECUTABLE) /usr/lib/ diff --git a/configure b/configure index 0bafc8d..9d12c98 100755 --- a/configure +++ b/configure @@ -1586,6 +1586,52 @@ $as_echo "$ac_res" >&6; } eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;} } # ac_fn_cxx_check_header_compile + +# ac_fn_cxx_try_link LINENO +# ------------------------- +# Try to link conftest.$ac_ext, and return whether this succeeded. +ac_fn_cxx_try_link () +{ + as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + rm -f conftest.$ac_objext conftest$ac_exeext + if { { ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_link") 2>conftest.err + ac_status=$? + if test -s conftest.err; then + grep -v '^ *+' conftest.err >conftest.er1 + cat conftest.er1 >&5 + mv -f conftest.er1 conftest.err + fi + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } && { + test -z "$ac_cxx_werror_flag" || + test ! -s conftest.err + } && test -s conftest$ac_exeext && { + test "$cross_compiling" = yes || + $as_test_x conftest$ac_exeext + }; then : + ac_retval=0 +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + ac_retval=1 +fi + # Delete the IPA/IPO (Inter Procedural Analysis/Optimization) information + # created by the PGI compiler (conftest_ipa8_conftest.oo), as it would + # interfere with the next link command; also delete a directory that is + # left behind by Apple's compiler. We do this before executing the actions. + rm -rf conftest.dSYM conftest_ipa8_conftest.oo + eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;} + as_fn_set_status $ac_retval + +} # ac_fn_cxx_try_link cat >config.log <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. @@ -2854,19 +2900,65 @@ fi done -for ac_header +for ac_header in pcap.h do : - as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh` -ac_fn_cxx_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default" -if eval test \"x\$"$as_ac_Header"\" = x"yes"; then : + ac_fn_cxx_check_header_mongrel "$LINENO" "pcap.h" "ac_cv_header_pcap_h" "$ac_includes_default" +if test "x$ac_cv_header_pcap_h" = x""yes; then : cat >>confdefs.h <<_ACEOF -#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1 +#define HAVE_PCAP_H 1 _ACEOF fi done +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for pcap_loop in -lpcap" >&5 +$as_echo_n "checking for pcap_loop in -lpcap... " >&6; } +if test "${ac_cv_lib_pcap_pcap_loop+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + ac_check_lib_save_LIBS=$LIBS +LIBS="-lpcap $LIBS" +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +/* Override any GCC internal prototype to avoid an error. + Use char because int might match the return type of a GCC + builtin and then its argument prototype would still apply. */ +#ifdef __cplusplus +extern "C" +#endif +char pcap_loop (); +int +main () +{ +return pcap_loop (); + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_link "$LINENO"; then : + ac_cv_lib_pcap_pcap_loop=yes +else + ac_cv_lib_pcap_pcap_loop=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +LIBS=$ac_check_lib_save_LIBS +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_pcap_pcap_loop" >&5 +$as_echo "$ac_cv_lib_pcap_pcap_loop" >&6; } +if test "x$ac_cv_lib_pcap_pcap_loop" = x""yes; then : + cat >>confdefs.h <<_ACEOF +#define HAVE_LIBPCAP 1 +_ACEOF + + LIBS="-lpcap $LIBS" + +else + as_fn_error $? "pcap library is needed!" "$LINENO" 5 +fi + ac_config_files="$ac_config_files Makefile" diff --git a/configure.ac b/configure.ac index 2597c81..bf89377 100644 --- a/configure.ac +++ b/configure.ac @@ -3,13 +3,14 @@ AC_INIT(myconfig, 0.1) AC_PROG_CXX() AC_LANG(C++) -if test -n "$debug" +if test -n "$debug" then CFLAGS="-DDEBUG -g" else CFLAGS="-O3" fi -AC_CHECK_HEADERS([]) +AC_CHECK_HEADERS([pcap.h]) +AC_CHECK_LIB(pcap, pcap_loop, [], [AC_MSG_ERROR([pcap library is needed!])]) AC_SUBST(CFLAGS) AC_OUTPUT(Makefile) From 8c661e57aa8121ec34dfae194c8f99de9a66a08c Mon Sep 17 00:00:00 2001 From: Santiago Alessandri Date: Tue, 6 Sep 2011 09:08:10 -0300 Subject: [PATCH 3/6] Fixed the Makefile.in --- Makefile.in | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Makefile.in b/Makefile.in index ff89f4f..2931180 100644 --- a/Makefile.in +++ b/Makefile.in @@ -23,7 +23,9 @@ clean: rm $(OBJECTS) $(EXECUTABLE) install: - rm -r /usr/include/tins - mkdir /usr/include/tins - cp include/*.h /usr/include/tins/ - cp $(EXECUTABLE) /usr/lib/ + install include/* /usr/include/tins/ + install $(EXECUTABLE) /usr/lib/ + +uninstall: + rm -r /usr/include/tins/ + rm /usr/lib/$(EXECUTABLE) From aaad48c25cb1a172cabf30c353147097fdd31f6a Mon Sep 17 00:00:00 2001 From: Santiago Alessandri Date: Tue, 6 Sep 2011 09:55:35 -0300 Subject: [PATCH 4/6] Added Dot11ReAssocRequest. --- include/dot11.h | 241 ++++++++++++++++++++++++++++++++++++++++-------- src/dot11.cpp | 145 +++++++++++++++++++++++------ 2 files changed, 317 insertions(+), 69 deletions(-) diff --git a/include/dot11.h b/include/dot11.h index b1eeef8..2c1ee06 100644 --- a/include/dot11.h +++ b/include/dot11.h @@ -1645,6 +1645,165 @@ namespace Tins { AssocRespBody _body; }; + class Dot11ReAssocRequest : public Dot11ManagementFrame { + + public: + /** + * \brief Default constructor for the ReAssociation Request frame. + * + */ + Dot11ReAssocRequest(); + + /** + * \brief Constructor for creating a 802.11 ReAssociation Request. + * + * Constructor that builds a 802.11 ReAssociation Request taking the interface name, + * destination's and source's MAC. + * + * \param iface string containing the interface's name from where to send the packet. + * \param dst_hw_addr uint8_t array of 6 bytes containing the destination's MAC(optional). + * \param src_hw_addr uint8_t array of 6 bytes containing the source's MAC(optional). + */ + Dot11ReAssocRequest(const std::string& iface, const uint8_t* dst_hw_addr = 0, const uint8_t* src_hw_addr = 0) throw (std::runtime_error); + + /** + * \brief Constructor which creates a Dot11ReAssocRequest object from a + * buffer and adds all identifiable PDUs found in the buffer as children of this one. + * + * \param buffer The buffer from which this PDU will be constructed. + * \param total_sz The total size of the buffer. + */ + Dot11ReAssocRequest(const uint8_t *buffer, uint32_t total_sz); + + /** + * \brief Copy constructor. + */ + Dot11ReAssocRequest(const Dot11ReAssocRequest &other); + + /** + * \brief Copy assignment operator. + */ + Dot11ReAssocRequest &operator= (const Dot11ReAssocRequest &other); + + /** + * \brief Getter for the Capabilities Information. + * + * \return CapabilityInformation Structure in a CapabilityInformation&. + */ + inline const CapabilityInformation& capabilities() const { return this->_body.capability;} + + /** + * \brief Getter for the Capabilities Information. + * + * \return CapabilityInformation Structure in a CapabilityInformation&. + */ + inline CapabilityInformation& capabilities() { return this->_body.capability;} + + /** + * \brief Getter for the listen interval. + * + * \return The listen interval in an uint16_t. + */ + inline uint16_t listen_interval() const { return this->_body.listen_interval; } + + /** + * \brief Getter for the current AP field. + * + * \return The current AP value in an uint8_t*. + */ + inline const uint8_t* current_ap() const {return this->_body.current_ap; } + + /** + * \brief Setter for the listen interval. + * + * \param new_listen_interval uint16_t with the new listen interval. + */ + void listen_interval(uint16_t new_listen_interval); + + /** + * \brief Setter for the current AP field. + * + * \param new_current_ap uint8_t array of 6 bytes with the new current_ap + */ + void current_ap(const uint8_t* new_current_ap); + + /** + * \brief Helper method to set the essid. + * + * \param new_ssid The ssid to be set. + */ + void ssid(const std::string &new_ssid); + + /** + * \brief Helper method to set the supported rates. + * + * \param new_rates A list of rates to be set. + */ + void supported_rates(const std::list &new_rates); + + /** + * \brief Helper method to set the extended supported rates. + * + * \param new_rates A list of rates to be set. + */ + void extended_supported_rates(const std::list &new_rates); + + /** + * \brief Helper method to set the power capabilities. + * + * \param min_power uint8_t indicating the minimum transmiting power capability. + * \param max_power uint8_t indicating the maximum transmiting power capability. + */ + void power_capabilities(uint8_t min_power, uint8_t max_power); + + /** + * \brief Helper method to set the supported channels. + * + * \param new_channels A list of channels to be set. + */ + void supported_channels(const std::list > &new_channels); + + /** + * \brief Helper method to set the RSN information option. + * + * \param info The RSNInformation structure to be set. + */ + void rsn_information(const RSNInformation& info); + + /** + * \brief Helper method to set the QoS capabilities. + * + * \param new_qos_capabilities uint8_t with the capabilities. + */ + void qos_capabilities(uint8_t new_qos_capabilities); + + /** + * \brief Returns the frame's header length. + * + * \return An uint32_t with the header's size. + * \sa PDU::header_size() + */ + uint32_t header_size() const; + + + protected: + + + + private: + struct ReAssocReqBody { + CapabilityInformation capability; + uint16_t listen_interval; + uint8_t current_ap[6]; + }; + + void copy_fields(const Dot11ReAssocRequest* other); + uint32_t write_fixed_parameters(uint8_t* buffer, uint32_t total_sz); + + ReAssocReqBody _body; + + }; + class Dot11QoSData : public Dot11DataFrame { public: @@ -1725,7 +1884,7 @@ namespace Tins { * \sa PDU::header_size() */ uint32_t header_size() const; - + /** * \brief Getter for the PDU's type. * \sa PDU::pdu_type @@ -1779,13 +1938,13 @@ namespace Tins { Dot11Control(uint32_t iface_index, const uint8_t* dst_addr = 0, PDU* child = 0); /** - * \brief Constructor which creates an 802.11 control frame object from a buffer and + * \brief Constructor which creates an 802.11 control frame object from a buffer and * adds all identifiable PDUs found in the buffer as children of this one. * \param buffer The buffer from which this PDU will be constructed. * \param total_sz The total size of the buffer. */ Dot11Control(const uint8_t *buffer, uint32_t total_sz); - + /** * \brief Getter for the PDU's type. * \sa PDU::pdu_type @@ -1837,24 +1996,24 @@ namespace Tins { Dot11ControlTA(uint32_t iface_index, const uint8_t* dst_addr = 0, const uint8_t *target_addr = 0, PDU* child = 0); /** - * \brief Constructor which creates an 802.11 control frame object from a buffer and + * \brief Constructor which creates an 802.11 control frame object from a buffer and * adds all identifiable PDUs found in the buffer as children of this one. * \param buffer The buffer from which this PDU will be constructed. * \param total_sz The total size of the buffer. */ Dot11ControlTA(const uint8_t *buffer, uint32_t total_sz); - + /** * \brief Getter for the target address field. */ inline const uint8_t* target_addr() const { return _taddr; } - + /** * \brief Setter for the target address field. * \param addr The new target address. */ void target_addr(const uint8_t *addr); - + /** * \brief Returns the 802.11 frame's header length. * @@ -1867,13 +2026,13 @@ namespace Tins { * \brief Getter for the control ta additional fields size. */ uint32_t controlta_size() const { return sizeof(_taddr) + sizeof(ieee80211_header); } - + uint32_t write_ext_header(uint8_t *buffer, uint32_t total_sz); private: - + uint8_t _taddr[6]; }; - + class Dot11RTS : public Dot11ControlTA { public: /** @@ -1914,20 +2073,20 @@ namespace Tins { Dot11RTS(uint32_t iface_index, const uint8_t* dst_hw_addr = 0, const uint8_t *target_addr = 0, PDU* child = 0); /** - * \brief Constructor which creates an 802.11 RTS frame object from a buffer and + * \brief Constructor which creates an 802.11 RTS frame object from a buffer and * adds all identifiable PDUs found in the buffer as children of this one. * \param buffer The buffer from which this PDU will be constructed. * \param total_sz The total size of the buffer. */ Dot11RTS(const uint8_t *buffer, uint32_t total_sz); - + /** * \brief Getter for the PDU's type. * \sa PDU::pdu_type */ PDUType pdu_type() const { return PDU::DOT11_RTS; } }; - + class Dot11PSPoll : public Dot11ControlTA { public: /** @@ -1968,14 +2127,14 @@ namespace Tins { Dot11PSPoll(uint32_t iface_index, const uint8_t* dst_addr, const uint8_t *target_addr, PDU* child); /** - * \brief Constructor which creates an 802.11 PS-Poll frame object from a buffer and + * \brief Constructor which creates an 802.11 PS-Poll frame object from a buffer and * adds all identifiable PDUs found in the buffer as children of this one. * \param buffer The buffer from which this PDU will be constructed. * \param total_sz The total size of the buffer. */ Dot11PSPoll(const uint8_t *buffer, uint32_t total_sz); }; - + class Dot11CFEnd : public Dot11ControlTA { public: /** @@ -2016,14 +2175,14 @@ namespace Tins { Dot11CFEnd(uint32_t iface_index, const uint8_t* dst_addr, const uint8_t *target_addr, PDU* child); /** - * \brief Constructor which creates an 802.11 CF-End frame object from a buffer and + * \brief Constructor which creates an 802.11 CF-End frame object from a buffer and * adds all identifiable PDUs found in the buffer as children of this one. * \param buffer The buffer from which this PDU will be constructed. * \param total_sz The total size of the buffer. */ Dot11CFEnd(const uint8_t *buffer, uint32_t total_sz); }; - + class Dot11EndCFAck : public Dot11ControlTA { public: /** @@ -2061,14 +2220,14 @@ namespace Tins { Dot11EndCFAck(uint32_t iface_index, const uint8_t* dst_addr, const uint8_t *target_addr, PDU* child); /** - * \brief Constructor which creates an 802.11 End-CF-Ack frame object from a buffer and + * \brief Constructor which creates an 802.11 End-CF-Ack frame object from a buffer and * adds all identifiable PDUs found in the buffer as children of this one. * \param buffer The buffer from which this PDU will be constructed. * \param total_sz The total size of the buffer. */ Dot11EndCFAck(const uint8_t *buffer, uint32_t total_sz); }; - + class Dot11Ack : public Dot11Control { public: /** @@ -2107,20 +2266,20 @@ namespace Tins { Dot11Ack(uint32_t iface_index, const uint8_t* dst_addr, PDU* child); /** - * \brief Constructor which creates an 802.11 Ack frame object from a buffer and + * \brief Constructor which creates an 802.11 Ack frame object from a buffer and * adds all identifiable PDUs found in the buffer as children of this one. * \param buffer The buffer from which this PDU will be constructed. * \param total_sz The total size of the buffer. */ Dot11Ack(const uint8_t *buffer, uint32_t total_sz); - + /** * \brief Getter for the PDU's type. * \sa PDU::pdu_type */ PDUType pdu_type() const { return PDU::DOT11_ACK; } }; - + /** * \brief Class that represents an 802.11 Block Ack Request PDU. */ @@ -2161,27 +2320,27 @@ namespace Tins { Dot11BlockAckRequest(uint32_t iface_index, const uint8_t* dst_addr, const uint8_t *target_addr, PDU* child); /** - * \brief Constructor which creates an 802.11 Block Ack request frame object from a buffer and + * \brief Constructor which creates an 802.11 Block Ack request frame object from a buffer and * adds all identifiable PDUs found in the buffer as children of this one. * \param buffer The buffer from which this PDU will be constructed. * \param total_sz The total size of the buffer. */ Dot11BlockAckRequest(const uint8_t *buffer, uint32_t total_sz); - + /* Getter */ - + /** * \brief Getter for the bar control field. * \return The bar control field. */ uint16_t bar_control() const { return *(const uint16_t*)&_bar_control; } - + /** * \brief Getter for the start sequence field. * \return The bar start sequence. */ uint16_t start_sequence() const { return *(const uint16_t*)&_start_sequence; } - + /** * \brief Returns the 802.11 frame's header length. * @@ -2189,15 +2348,15 @@ namespace Tins { * \sa PDU::header_size() */ uint32_t header_size() const; - + /* Setter */ - + /** * \brief Setter for the bar control field. * \param bar The new bar control field. */ void bar_control(uint16_t bar); - + /** * \brief Setter for the start sequence field. * \param bar The new start sequence field. @@ -2208,25 +2367,25 @@ namespace Tins { * \brief Getter for the control ta additional fields size. */ uint32_t blockack_request_size() const { return controlta_size() + sizeof(_bar_control) + sizeof(_start_sequence); } - + uint32_t write_ext_header(uint8_t *buffer, uint32_t total_sz); private: struct BarControl { uint16_t reserved:12, tid:4; } __attribute__((__packed__)); - + struct StartSequence { uint16_t frag:4, seq:12; } __attribute__((__packed__)); - + void init_block_ack(); - + BarControl _bar_control; StartSequence _start_sequence; }; - + /** * \brief Class that represents an 802.11 block ack frame. */ @@ -2267,13 +2426,13 @@ namespace Tins { Dot11BlockAck(uint32_t iface_index, const uint8_t* dst_addr, const uint8_t *target_addr, PDU* child); /** - * \brief Constructor which creates an 802.11 Block Ack request frame object from a buffer and + * \brief Constructor which creates an 802.11 Block Ack request frame object from a buffer and * adds all identifiable PDUs found in the buffer as children of this one. * \param buffer The buffer from which this PDU will be constructed. * \param total_sz The total size of the buffer. */ Dot11BlockAck(const uint8_t *buffer, uint32_t total_sz); - + /** * \brief Returns the 802.11 frame's header length. * @@ -2281,19 +2440,19 @@ namespace Tins { * \sa PDU::header_size() */ uint32_t header_size() const; - + /** * \brief Getter for the bitmap field. * \return The bitmap field. */ const uint8_t *bitmap() const { return _bitmap; } - + /** * \brief Setter for the bitmap field. * \param bit The new bitmap field to be set. */ void bitmap(const uint8_t *bit); - + /** * \brief Getter for the PDU's type. * \sa PDU::pdu_type @@ -2301,7 +2460,7 @@ namespace Tins { PDUType pdu_type() const { return PDU::DOT11_BLOCK_ACK; } private: uint32_t write_ext_header(uint8_t *buffer, uint32_t total_sz); - + uint8_t _bitmap[8]; }; }; diff --git a/src/dot11.cpp b/src/dot11.cpp index ff57668..fa84f08 100644 --- a/src/dot11.cpp +++ b/src/dot11.cpp @@ -241,7 +241,7 @@ Tins::PDU *Tins::Dot11::from_bytes(const uint8_t *buffer, uint32_t total_sz) { else if(hdr->control.type == DATA){ if(hdr->control.subtype <= 4) ret = new Dot11DataFrame(buffer, total_sz); - else + else ret = new Dot11QoSData(buffer, total_sz); } else if(hdr->control.type == CONTROL){ @@ -888,6 +888,95 @@ uint32_t Tins::Dot11AssocResponse::write_fixed_parameters(uint8_t *buffer, uint3 return sz; } +/* ReAssoc Request */ + +Tins::Dot11ReAssocRequest::Dot11ReAssocRequest() : Dot11ManagementFrame() { + this->subtype(Dot11::REASSOC_REQ); + memset(&_body, 0, sizeof(_body)); +} + +Tins::Dot11ReAssocRequest::Dot11ReAssocRequest(const std::string& iface, + const uint8_t* dst_hw_addr, + const uint8_t* src_hw_addr) throw (std::runtime_error) : Dot11ManagementFrame(iface, dst_hw_addr, src_hw_addr) { + this->subtype(Dot11::REASSOC_REQ); + memset(&_body, 0, sizeof(_body)); +} + +Tins::Dot11ReAssocRequest::Dot11ReAssocRequest(const uint8_t *buffer, uint32_t total_sz) : Dot11ManagementFrame(buffer, total_sz) { + uint32_t sz = Dot11ManagementFrame::header_size(); + buffer += sz; + total_sz -= sz; + if(total_sz < sizeof(_body)) + throw std::runtime_error("Not enough size for an IEEE 802.11 association header in the buffer."); + memcpy(&_body, buffer, sizeof(_body)); + buffer += sizeof(_body); + total_sz -= sizeof(_body); + parse_tagged_parameters(buffer, total_sz); +} + +Tins::Dot11ReAssocRequest::Dot11ReAssocRequest(const Dot11ReAssocRequest &other) : Dot11ManagementFrame(other) { + copy_fields(&other); +} + +Tins::Dot11ReAssocRequest &Tins::Dot11ReAssocRequest::operator= (const Dot11ReAssocRequest &other) { + copy_inner_pdu(other); + copy_fields(&other); + return *this; +} + +void Tins::Dot11ReAssocRequest::copy_fields(const Dot11ReAssocRequest *other) { + Dot11ManagementFrame::copy_ext_header(other); + std::memcpy(&_body, &other->_body, sizeof(_body)); +} + +void Tins::Dot11ReAssocRequest::listen_interval(uint16_t new_listen_interval) { + this->_body.listen_interval = new_listen_interval; +} + +void Tins::Dot11ReAssocRequest::current_ap(const uint8_t* new_current_ap) { + memcpy(this->_body.current_ap, new_current_ap, 6); +} + +void Tins::Dot11ReAssocRequest::ssid(const std::string &new_ssid) { + Dot11ManagementFrame::ssid(new_ssid); +} + +void Tins::Dot11ReAssocRequest::supported_rates(const std::list &new_rates) { + Dot11ManagementFrame::supported_rates(new_rates); +} + +void Tins::Dot11ReAssocRequest::extended_supported_rates(const std::list &new_rates) { + Dot11ManagementFrame::extended_supported_rates(new_rates); +} + +void Tins::Dot11ReAssocRequest::power_capabilities(uint8_t min_power, uint8_t max_power) { + Dot11ManagementFrame::power_capabilities(min_power, max_power); +} + +void Tins::Dot11ReAssocRequest::supported_channels(const std::list > &new_channels) { + Dot11ManagementFrame::supported_channels(new_channels); +} + +void Tins::Dot11ReAssocRequest::rsn_information(const RSNInformation& info) { + Dot11ManagementFrame::rsn_information(info); +} + +void Tins::Dot11ReAssocRequest::qos_capabilities(uint8_t new_qos_capabilities) { + Dot11ManagementFrame::qos_capabilities(new_qos_capabilities); +} + +uint32_t Tins::Dot11ReAssocRequest::header_size() const { + return Dot11ManagementFrame::header_size() + sizeof(this->_body); +} + +uint32_t Tins::Dot11ReAssocRequest::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) { + uint32_t sz = sizeof(this->_body); + assert(sz <= total_sz); + memcpy(buffer, &this->_body, sz); + return sz; +} + + /* QoS data. */ Tins::Dot11QoSData::Dot11QoSData(const std::string& iface, const uint8_t* dst_hw_addr, const uint8_t* src_hw_addr, PDU* child) throw (std::runtime_error) : Dot11DataFrame(iface, dst_hw_addr, src_hw_addr, child) { @@ -1008,16 +1097,16 @@ Tins::Dot11RTS::Dot11RTS(const uint8_t* dst_addr , const uint8_t* target_addr, P 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) { +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_addr, const uint8_t *target_addr, PDU* child) : Dot11ControlTA(iface_index, dst_addr, target_addr, child) { +Tins::Dot11RTS::Dot11RTS(uint32_t iface_index, const uint8_t* dst_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) { - +Tins::Dot11RTS::Dot11RTS(const uint8_t *buffer, uint32_t total_sz) : Dot11ControlTA(buffer, total_sz) { + } /* Dot11PSPoll */ @@ -1026,16 +1115,16 @@ Tins::Dot11PSPoll::Dot11PSPoll(const uint8_t* dst_addr , const uint8_t* target_a 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) { +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_addr, const uint8_t *target_addr, PDU* child) : Dot11ControlTA(iface_index, dst_addr, target_addr, child) { +Tins::Dot11PSPoll::Dot11PSPoll(uint32_t iface_index, const uint8_t* dst_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) { - +Tins::Dot11PSPoll::Dot11PSPoll(const uint8_t *buffer, uint32_t total_sz) : Dot11ControlTA(buffer, total_sz) { + } /* Dot11CFEnd */ @@ -1044,16 +1133,16 @@ Tins::Dot11CFEnd::Dot11CFEnd(const uint8_t* dst_addr , const uint8_t* target_add 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) { +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_addr, const uint8_t *target_addr, PDU* child) : Dot11ControlTA(iface_index, dst_addr, target_addr, child) { +Tins::Dot11CFEnd::Dot11CFEnd(uint32_t iface_index, const uint8_t* dst_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) { - +Tins::Dot11CFEnd::Dot11CFEnd(const uint8_t *buffer, uint32_t total_sz) : Dot11ControlTA(buffer, total_sz) { + } /* Dot11EndCFAck */ @@ -1062,16 +1151,16 @@ Tins::Dot11EndCFAck::Dot11EndCFAck(const uint8_t* dst_addr , const uint8_t* targ 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) { +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_addr, const uint8_t *target_addr, PDU* child) : Dot11ControlTA(iface_index, dst_addr, target_addr, child) { +Tins::Dot11EndCFAck::Dot11EndCFAck(uint32_t iface_index, const uint8_t* dst_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) { - +Tins::Dot11EndCFAck::Dot11EndCFAck(const uint8_t *buffer, uint32_t total_sz) : Dot11ControlTA(buffer, total_sz) { + } /* Dot11Ack */ @@ -1080,16 +1169,16 @@ Tins::Dot11Ack::Dot11Ack(const uint8_t* dst_addr, PDU* child) : Dot11Control(ds subtype(ACK); } -Tins::Dot11Ack::Dot11Ack(const std::string& iface, const uint8_t* dst_addr, PDU* child) throw (std::runtime_error) : Dot11Control(iface, dst_addr, child) { +Tins::Dot11Ack::Dot11Ack(const std::string& iface, const uint8_t* dst_addr, PDU* child) throw (std::runtime_error) : Dot11Control(iface, dst_addr, child) { subtype(ACK); } -Tins::Dot11Ack::Dot11Ack(uint32_t iface_index, const uint8_t* dst_addr, PDU* child) : Dot11Control(iface_index, dst_addr, child) { +Tins::Dot11Ack::Dot11Ack(uint32_t iface_index, const uint8_t* dst_addr, PDU* child) : Dot11Control(iface_index, dst_addr, child) { subtype(ACK); } -Tins::Dot11Ack::Dot11Ack(const uint8_t *buffer, uint32_t total_sz) : Dot11Control(buffer, total_sz) { - +Tins::Dot11Ack::Dot11Ack(const uint8_t *buffer, uint32_t total_sz) : Dot11Control(buffer, total_sz) { + } /* Dot11BlockAck */ @@ -1098,15 +1187,15 @@ Tins::Dot11BlockAckRequest::Dot11BlockAckRequest(const uint8_t* dst_addr , const 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) { +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_addr, const uint8_t *target_addr, PDU* child) : Dot11ControlTA(iface_index, dst_addr, target_addr, child) { +Tins::Dot11BlockAckRequest::Dot11BlockAckRequest(uint32_t iface_index, const uint8_t* dst_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) { +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; @@ -1135,7 +1224,7 @@ uint32_t Tins::Dot11BlockAckRequest::write_ext_header(uint8_t *buffer, uint32_t 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)); } @@ -1150,17 +1239,17 @@ Tins::Dot11BlockAck::Dot11BlockAck(const uint8_t* dst_addr , const uint8_t* targ 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) { +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) { subtype(BLOCK_ACK); std::memset(_bitmap, 0, sizeof(_bitmap)); } -Tins::Dot11BlockAck::Dot11BlockAck(uint32_t iface_index, const uint8_t* dst_addr, const uint8_t *target_addr, PDU* child) : Dot11BlockAckRequest(iface_index, dst_addr, target_addr, child) { +Tins::Dot11BlockAck::Dot11BlockAck(uint32_t iface_index, const uint8_t* dst_addr, const uint8_t *target_addr, PDU* child) : Dot11BlockAckRequest(iface_index, dst_addr, target_addr, child) { subtype(BLOCK_ACK); std::memset(_bitmap, 0, sizeof(_bitmap)); } -Tins::Dot11BlockAck::Dot11BlockAck(const uint8_t *buffer, uint32_t total_sz) : Dot11BlockAckRequest(buffer, total_sz) { +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; From 990f408e53d10543d40e31bfb9980c10a17ee038 Mon Sep 17 00:00:00 2001 From: Santiago Alessandri Date: Tue, 6 Sep 2011 10:17:19 -0300 Subject: [PATCH 5/6] Added Dot11ReAssocResponse. --- include/dot11.h | 140 ++++++++++++++++++++++++++++++++++++++++++++++++ src/dot11.cpp | 71 ++++++++++++++++++++++++ 2 files changed, 211 insertions(+) diff --git a/include/dot11.h b/include/dot11.h index 2c1ee06..a3ad5b9 100644 --- a/include/dot11.h +++ b/include/dot11.h @@ -1645,6 +1645,10 @@ namespace Tins { AssocRespBody _body; }; + /** + * \brief Class representing an ReAssociation Request frame in the IEEE 802.11 Protocol. + * + */ class Dot11ReAssocRequest : public Dot11ManagementFrame { public: @@ -1804,6 +1808,142 @@ namespace Tins { }; + /** + * \brief Class representing an ReAssociation Response frame in the IEEE 802.11 Protocol. + * + */ + class Dot11ReAssocResponse : public Dot11ManagementFrame { + + public: + /** + * \brief Default constructor for the Association Response frame. + * + */ + Dot11ReAssocResponse(); + + /** + * \brief Constructor for creating a 802.11 ReAssociation Response. + * + * Constructor that builds a 802.11 ReAssociation Response taking the interface name, + * destination's and source's MAC. + * + * \param iface string containing the interface's name from where to send the packet. + * \param dst_hw_addr uint8_t array of 6 bytes containing the destination's MAC(optional). + * \param src_hw_addr uint8_t array of 6 bytes containing the source's MAC(optional). + */ + Dot11ReAssocResponse(const std::string& iface, const uint8_t* dst_hw_addr = 0, const uint8_t* src_hw_addr = 0) throw (std::runtime_error); + + /** + * \brief Constructor which creates a Dot11ReAssocResponse object from a + * buffer and adds all identifiable PDUs found in the buffer as children of this one. + * + * \param buffer The buffer from which this PDU will be constructed. + * \param total_sz The total size of the buffer. + */ + Dot11ReAssocResponse(const uint8_t *buffer, uint32_t total_sz); + + /** + * \brief Copy constructor. + */ + Dot11ReAssocResponse(const Dot11ReAssocResponse &other); + + /** + * \brief Copy assignment operator + */ + Dot11ReAssocResponse &operator= (const Dot11ReAssocResponse &other); + + /** + * \brief Getter for the Capabilities Information. + * + * \return CapabilityInformation Structure in a CapabilityInformation&. + */ + inline const CapabilityInformation& capabilities() const { return this->_body.capability;} + + /** + * \brief Getter for the Capabilities Information. + * + * \return CapabilityInformation Structure in a CapabilityInformation&. + */ + inline CapabilityInformation& capabilities() { return this->_body.capability;} + + /** + * \brief Getter for the status code. + * + * \return The status code in an uint16_t. + */ + inline uint16_t status_code() const { return this->_body.status_code; } + + /** + * \brief Getter for the AID field. + * + * \return The AID field value in an uint16_t. + */ + inline uint16_t aid() const { return this->_body.aid; } + + /** + * \brief Setter for the status code. + * + * \param new_status_code uint16_t with the new status code. + */ + void status_code(uint16_t new_status_code); + + /** + * \brief Setter for the AID field. + * + * \param new_aid uint16_t with the new AID value. + */ + void aid(uint16_t new_aid); + + /** + * \brief Helper method to set the supported rates. + * + * \param new_rates A list of rates to be set. + */ + void supported_rates(const std::list &new_rates); + + /** + * \brief Helper method to set the extended supported rates. + * + * \param new_rates A list of rates to be set. + */ + void extended_supported_rates(const std::list &new_rates); + + /** + * \brief Helper method to set the EDCA Parameter Set. + * + * \param ac_be uint32_t with the value of the ac_be field. + * \param ac_bk uint32_t with the value of the ac_bk field. + * \param ac_vi uint32_t with the value of the ac_vi field. + * \param ac_vo uint32_t with the value of the ac_vo field. + */ + void edca_parameter_set(uint32_t ac_be, uint32_t ac_bk, uint32_t ac_vi, uint32_t ac_vo); + + /** + * \brief Returns the frame's header length. + * + * \return An uint32_t with the header's size. + * \sa PDU::header_size() + */ + uint32_t header_size() const; + + + protected: + + private: + + struct ReAssocRespBody { + CapabilityInformation capability; + uint16_t status_code; + uint16_t aid; + }; + + void copy_fields(const Dot11ReAssocResponse *other); + uint32_t write_fixed_parameters(uint8_t *buffer, uint32_t total_sz); + + ReAssocRespBody _body; + + }; + class Dot11QoSData : public Dot11DataFrame { public: diff --git a/src/dot11.cpp b/src/dot11.cpp index fa84f08..a1ef762 100644 --- a/src/dot11.cpp +++ b/src/dot11.cpp @@ -976,6 +976,77 @@ uint32_t Tins::Dot11ReAssocRequest::write_fixed_parameters(uint8_t *buffer, uint return sz; } +/* ReAssociation Response */ + +Tins::Dot11ReAssocResponse::Dot11ReAssocResponse() : Dot11ManagementFrame() { + this->subtype(Dot11::REASSOC_RESP); + memset(&_body, 0, sizeof(_body)); +} + +Tins::Dot11ReAssocResponse::Dot11ReAssocResponse(const std::string& iface, + const uint8_t* dst_hw_addr, + const uint8_t* src_hw_addr) throw (std::runtime_error) : Dot11ManagementFrame(iface, dst_hw_addr, src_hw_addr) { + this->subtype(Dot11::REASSOC_RESP); + memset(&_body, 0, sizeof(_body)); +} + +Tins::Dot11ReAssocResponse::Dot11ReAssocResponse(const uint8_t *buffer, uint32_t total_sz) : Dot11ManagementFrame(buffer, total_sz) { + uint32_t sz = Dot11ManagementFrame::header_size(); + buffer += sz; + total_sz -= sz; + if(total_sz < sizeof(_body)) + throw std::runtime_error("Not enough size for an IEEE 802.11 reassociation response header in the buffer."); + memcpy(&_body, buffer, sizeof(_body)); + buffer += sizeof(_body); + total_sz -= sizeof(_body); + parse_tagged_parameters(buffer, total_sz); +} + +Tins::Dot11ReAssocResponse::Dot11ReAssocResponse(const Dot11ReAssocResponse &other) : Dot11ManagementFrame(other) { + copy_fields(&other); +} + +Tins::Dot11ReAssocResponse &Tins::Dot11ReAssocResponse::operator= (const Dot11ReAssocResponse &other) { + copy_inner_pdu(other); + copy_fields(&other); + return *this; +} + +void Tins::Dot11ReAssocResponse::copy_fields(const Dot11ReAssocResponse *other) { + Dot11ManagementFrame::copy_ext_header(other); + std::memcpy(&_body, &other->_body, sizeof(_body)); +} + +void Tins::Dot11ReAssocResponse::status_code(uint16_t new_status_code) { + this->_body.status_code = new_status_code; +} + +void Tins::Dot11ReAssocResponse::aid(uint16_t new_aid) { + this->_body.aid = new_aid; +} + +void Tins::Dot11ReAssocResponse::supported_rates(const std::list &new_rates) { + Dot11ManagementFrame::supported_rates(new_rates); +} + +void Tins::Dot11ReAssocResponse::extended_supported_rates(const std::list &new_rates) { + Dot11ManagementFrame::extended_supported_rates(new_rates); +} + +void Tins::Dot11ReAssocResponse::edca_parameter_set(uint32_t ac_be, uint32_t ac_bk, uint32_t ac_vi, uint32_t ac_vo) { + Dot11ManagementFrame::edca_parameter_set(ac_be, ac_bk, ac_vi, ac_vo); +} + +uint32_t Tins::Dot11ReAssocResponse::header_size() const { + return Dot11ManagementFrame::header_size() + sizeof(this->_body); +} + +uint32_t Tins::Dot11ReAssocResponse::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) { + uint32_t sz = sizeof(this->_body); + assert(sz <= total_sz); + memcpy(buffer, &this->_body, sz); + return sz; +} /* QoS data. */ From 232e5b6cccb79469549bd16f0c5c157cf5f84cad Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Tue, 6 Sep 2011 10:17:57 -0300 Subject: [PATCH 6/6] Fixed antialising strict rules. --- include/dot11.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/dot11.h b/include/dot11.h index b1eeef8..4a26cbc 100644 --- a/include/dot11.h +++ b/include/dot11.h @@ -2174,13 +2174,13 @@ namespace Tins { * \brief Getter for the bar control field. * \return The bar control field. */ - uint16_t bar_control() const { return *(const uint16_t*)&_bar_control; } + uint16_t bar_control() const { return _bar_control.tid; } /** * \brief Getter for the start sequence field. * \return The bar start sequence. */ - uint16_t start_sequence() const { return *(const uint16_t*)&_start_sequence; } + uint16_t start_sequence() const { return (_start_sequence.frag << 12) | (_start_sequence.seq); } /** * \brief Returns the 802.11 frame's header length.