1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-23 02:35:57 +01:00

Split dot11.h and dot11.cpp into several files.

This commit is contained in:
Matias Fontanini
2013-05-31 22:16:56 -03:00
parent eeb62add59
commit ec8374be60
54 changed files with 6971 additions and 5925 deletions

View File

@@ -21,7 +21,6 @@ libtins_la_SOURCES=src/arp.cpp \
src/dhcpv6.cpp \ src/dhcpv6.cpp \
src/dns.cpp \ src/dns.cpp \
src/dns_record.cpp \ src/dns_record.cpp \
src/dot11.cpp \
src/dot3.cpp \ src/dot3.cpp \
src/dot1q.cpp \ src/dot1q.cpp \
src/eapol.cpp \ src/eapol.cpp \
@@ -47,10 +46,19 @@ libtins_la_SOURCES=src/arp.cpp \
src/tcp.cpp \ src/tcp.cpp \
src/tcp_stream.cpp \ src/tcp_stream.cpp \
src/udp.cpp \ src/udp.cpp \
src/utils.cpp src/utils.cpp \
src/dot11/dot11_base.cpp \
src/dot11/dot11_data.cpp \
src/dot11/dot11_mgmt.cpp \
src/dot11/dot11_beacon.cpp \
src/dot11/dot11_assoc.cpp \
src/dot11/dot11_auth.cpp \
src/dot11/dot11_probe.cpp \
src/dot11/dot11_control.cpp
libtins_includedir = $(includedir)/tins libtinsdir = $(includedir)/tins
libtins_include_HEADERS = include/internals.h \
libtins_HEADERS = include/internals.h \
include/dhcpv6.h \ include/dhcpv6.h \
include/dot11.h \ include/dot11.h \
include/dot1q.h \ include/dot1q.h \
@@ -102,3 +110,14 @@ libtins_include_HEADERS = include/internals.h \
include/stp.h \ include/stp.h \
include/exceptions.h \ include/exceptions.h \
include/config.h include/config.h
libtins_dot11_HEADERS = include/dot11/dot11_base.h \
include/dot11/dot11_beacon.h \
include/dot11/dot11_data.h \
include/dot11/dot11_mgmt.h \
include/dot11/dot11_assoc.h \
include/dot11/dot11_auth.h \
include/dot11/dot11_probe.h \
include/dot11/dot11_control.h
libtins_dot11dir = $(includedir)/tins/dot11/

View File

@@ -55,11 +55,12 @@ build_triplet = @build@
host_triplet = @host@ host_triplet = @host@
target_triplet = @target@ target_triplet = @target@
subdir = . subdir = .
DIST_COMMON = README $(am__configure_deps) $(libtins_include_HEADERS) \ DIST_COMMON = README $(am__configure_deps) $(libtins_HEADERS) \
$(srcdir)/Makefile.am $(srcdir)/Makefile.in \ $(libtins_dot11_HEADERS) $(srcdir)/Makefile.am \
$(srcdir)/libtins.pc.in $(top_srcdir)/configure \ $(srcdir)/Makefile.in $(srcdir)/libtins.pc.in \
$(top_srcdir)/include/config.h.in AUTHORS INSTALL THANKS \ $(top_srcdir)/configure $(top_srcdir)/include/config.h.in \
config.guess config.sub depcomp install-sh ltmain.sh missing AUTHORS COPYING INSTALL THANKS TODO config.guess config.sub \
depcomp install-sh ltmain.sh missing
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/m4/ax_cxx_compile_stdcxx_11.m4 \ am__aclocal_m4_deps = $(top_srcdir)/m4/ax_cxx_compile_stdcxx_11.m4 \
$(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \ $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \
@@ -101,21 +102,25 @@ am__uninstall_files_from_dir = { \
$(am__cd) "$$dir" && rm -f $$files; }; \ $(am__cd) "$$dir" && rm -f $$files; }; \
} }
am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(pkgconfigdir)" \ am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(pkgconfigdir)" \
"$(DESTDIR)$(libtins_includedir)" "$(DESTDIR)$(libtinsdir)" "$(DESTDIR)$(libtins_dot11dir)"
LTLIBRARIES = $(lib_LTLIBRARIES) LTLIBRARIES = $(lib_LTLIBRARIES)
libtins_la_LIBADD = libtins_la_LIBADD =
am__dirstamp = $(am__leading_dot)dirstamp am__dirstamp = $(am__leading_dot)dirstamp
am_libtins_la_OBJECTS = src/arp.lo src/bootp.lo \ am_libtins_la_OBJECTS = src/arp.lo src/bootp.lo \
src/handshake_capturer.lo src/stp.lo src/pppoe.lo \ src/handshake_capturer.lo src/stp.lo src/pppoe.lo \
src/crypto.lo src/dhcp.lo src/dhcpv6.lo src/dns.lo \ src/crypto.lo src/dhcp.lo src/dhcpv6.lo src/dns.lo \
src/dns_record.lo src/dot11.lo src/dot3.lo src/dot1q.lo \ src/dns_record.lo src/dot3.lo src/dot1q.lo src/eapol.lo \
src/eapol.lo src/ethernetII.lo src/icmp.lo src/icmpv6.lo \ src/ethernetII.lo src/icmp.lo src/icmpv6.lo src/internals.lo \
src/internals.lo src/ip.lo src/ip_address.lo src/ipv6.lo \ src/ip.lo src/ip_address.lo src/ipv6.lo src/ipv6_address.lo \
src/ipv6_address.lo src/llc.lo src/loopback.lo \ src/llc.lo src/loopback.lo src/network_interface.lo \
src/network_interface.lo src/packet_sender.lo \ src/packet_sender.lo src/packet_writer.lo src/pdu.lo \
src/packet_writer.lo src/pdu.lo src/radiotap.lo src/rawpdu.lo \ src/radiotap.lo src/rawpdu.lo src/rsn_information.lo \
src/rsn_information.lo src/sll.lo src/snap.lo src/sniffer.lo \ src/sll.lo src/snap.lo src/sniffer.lo src/tcp.lo \
src/tcp.lo src/tcp_stream.lo src/udp.lo src/utils.lo src/tcp_stream.lo src/udp.lo src/utils.lo \
src/dot11/dot11_base.lo src/dot11/dot11_data.lo \
src/dot11/dot11_mgmt.lo src/dot11/dot11_beacon.lo \
src/dot11/dot11_assoc.lo src/dot11/dot11_auth.lo \
src/dot11/dot11_probe.lo src/dot11/dot11_control.lo
libtins_la_OBJECTS = $(am_libtins_la_OBJECTS) libtins_la_OBJECTS = $(am_libtins_la_OBJECTS)
libtins_la_LINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) \ libtins_la_LINK = $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CXXLD) $(AM_CXXFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CXXLD) $(AM_CXXFLAGS) \
@@ -141,7 +146,7 @@ am__can_run_installinfo = \
*) (install-info --version) >/dev/null 2>&1;; \ *) (install-info --version) >/dev/null 2>&1;; \
esac esac
DATA = $(pkgconfig_DATA) DATA = $(pkgconfig_DATA)
HEADERS = $(libtins_include_HEADERS) HEADERS = $(libtins_HEADERS) $(libtins_dot11_HEADERS)
ETAGS = etags ETAGS = etags
CTAGS = ctags CTAGS = ctags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
@@ -304,7 +309,6 @@ libtins_la_SOURCES = src/arp.cpp \
src/dhcpv6.cpp \ src/dhcpv6.cpp \
src/dns.cpp \ src/dns.cpp \
src/dns_record.cpp \ src/dns_record.cpp \
src/dot11.cpp \
src/dot3.cpp \ src/dot3.cpp \
src/dot1q.cpp \ src/dot1q.cpp \
src/eapol.cpp \ src/eapol.cpp \
@@ -330,10 +334,18 @@ libtins_la_SOURCES = src/arp.cpp \
src/tcp.cpp \ src/tcp.cpp \
src/tcp_stream.cpp \ src/tcp_stream.cpp \
src/udp.cpp \ src/udp.cpp \
src/utils.cpp src/utils.cpp \
src/dot11/dot11_base.cpp \
src/dot11/dot11_data.cpp \
src/dot11/dot11_mgmt.cpp \
src/dot11/dot11_beacon.cpp \
src/dot11/dot11_assoc.cpp \
src/dot11/dot11_auth.cpp \
src/dot11/dot11_probe.cpp \
src/dot11/dot11_control.cpp
libtins_includedir = $(includedir)/tins libtinsdir = $(includedir)/tins
libtins_include_HEADERS = include/internals.h \ libtins_HEADERS = include/internals.h \
include/dhcpv6.h \ include/dhcpv6.h \
include/dot11.h \ include/dot11.h \
include/dot1q.h \ include/dot1q.h \
@@ -386,6 +398,16 @@ libtins_include_HEADERS = include/internals.h \
include/exceptions.h \ include/exceptions.h \
include/config.h include/config.h
libtins_dot11_HEADERS = include/dot11/dot11_base.h \
include/dot11/dot11_beacon.h \
include/dot11/dot11_data.h \
include/dot11/dot11_mgmt.h \
include/dot11/dot11_assoc.h \
include/dot11/dot11_auth.h \
include/dot11/dot11_probe.h \
include/dot11/dot11_control.h
libtins_dot11dir = $(includedir)/tins/dot11/
all: all-am all: all-am
.SUFFIXES: .SUFFIXES:
@@ -490,7 +512,6 @@ src/dhcp.lo: src/$(am__dirstamp) src/$(DEPDIR)/$(am__dirstamp)
src/dhcpv6.lo: src/$(am__dirstamp) src/$(DEPDIR)/$(am__dirstamp) src/dhcpv6.lo: src/$(am__dirstamp) src/$(DEPDIR)/$(am__dirstamp)
src/dns.lo: src/$(am__dirstamp) src/$(DEPDIR)/$(am__dirstamp) src/dns.lo: src/$(am__dirstamp) src/$(DEPDIR)/$(am__dirstamp)
src/dns_record.lo: src/$(am__dirstamp) src/$(DEPDIR)/$(am__dirstamp) src/dns_record.lo: src/$(am__dirstamp) src/$(DEPDIR)/$(am__dirstamp)
src/dot11.lo: src/$(am__dirstamp) src/$(DEPDIR)/$(am__dirstamp)
src/dot3.lo: src/$(am__dirstamp) src/$(DEPDIR)/$(am__dirstamp) src/dot3.lo: src/$(am__dirstamp) src/$(DEPDIR)/$(am__dirstamp)
src/dot1q.lo: src/$(am__dirstamp) src/$(DEPDIR)/$(am__dirstamp) src/dot1q.lo: src/$(am__dirstamp) src/$(DEPDIR)/$(am__dirstamp)
src/eapol.lo: src/$(am__dirstamp) src/$(DEPDIR)/$(am__dirstamp) src/eapol.lo: src/$(am__dirstamp) src/$(DEPDIR)/$(am__dirstamp)
@@ -522,6 +543,28 @@ src/tcp.lo: src/$(am__dirstamp) src/$(DEPDIR)/$(am__dirstamp)
src/tcp_stream.lo: src/$(am__dirstamp) src/$(DEPDIR)/$(am__dirstamp) src/tcp_stream.lo: src/$(am__dirstamp) src/$(DEPDIR)/$(am__dirstamp)
src/udp.lo: src/$(am__dirstamp) src/$(DEPDIR)/$(am__dirstamp) src/udp.lo: src/$(am__dirstamp) src/$(DEPDIR)/$(am__dirstamp)
src/utils.lo: src/$(am__dirstamp) src/$(DEPDIR)/$(am__dirstamp) src/utils.lo: src/$(am__dirstamp) src/$(DEPDIR)/$(am__dirstamp)
src/dot11/$(am__dirstamp):
@$(MKDIR_P) src/dot11
@: > src/dot11/$(am__dirstamp)
src/dot11/$(DEPDIR)/$(am__dirstamp):
@$(MKDIR_P) src/dot11/$(DEPDIR)
@: > src/dot11/$(DEPDIR)/$(am__dirstamp)
src/dot11/dot11_base.lo: src/dot11/$(am__dirstamp) \
src/dot11/$(DEPDIR)/$(am__dirstamp)
src/dot11/dot11_data.lo: src/dot11/$(am__dirstamp) \
src/dot11/$(DEPDIR)/$(am__dirstamp)
src/dot11/dot11_mgmt.lo: src/dot11/$(am__dirstamp) \
src/dot11/$(DEPDIR)/$(am__dirstamp)
src/dot11/dot11_beacon.lo: src/dot11/$(am__dirstamp) \
src/dot11/$(DEPDIR)/$(am__dirstamp)
src/dot11/dot11_assoc.lo: src/dot11/$(am__dirstamp) \
src/dot11/$(DEPDIR)/$(am__dirstamp)
src/dot11/dot11_auth.lo: src/dot11/$(am__dirstamp) \
src/dot11/$(DEPDIR)/$(am__dirstamp)
src/dot11/dot11_probe.lo: src/dot11/$(am__dirstamp) \
src/dot11/$(DEPDIR)/$(am__dirstamp)
src/dot11/dot11_control.lo: src/dot11/$(am__dirstamp) \
src/dot11/$(DEPDIR)/$(am__dirstamp)
libtins.la: $(libtins_la_OBJECTS) $(libtins_la_DEPENDENCIES) $(EXTRA_libtins_la_DEPENDENCIES) libtins.la: $(libtins_la_OBJECTS) $(libtins_la_DEPENDENCIES) $(EXTRA_libtins_la_DEPENDENCIES)
$(libtins_la_LINK) -rpath $(libdir) $(libtins_la_OBJECTS) $(libtins_la_LIBADD) $(LIBS) $(libtins_la_LINK) -rpath $(libdir) $(libtins_la_OBJECTS) $(libtins_la_LIBADD) $(LIBS)
@@ -541,8 +584,22 @@ mostlyclean-compile:
-rm -f src/dns.lo -rm -f src/dns.lo
-rm -f src/dns_record.$(OBJEXT) -rm -f src/dns_record.$(OBJEXT)
-rm -f src/dns_record.lo -rm -f src/dns_record.lo
-rm -f src/dot11.$(OBJEXT) -rm -f src/dot11/dot11_assoc.$(OBJEXT)
-rm -f src/dot11.lo -rm -f src/dot11/dot11_assoc.lo
-rm -f src/dot11/dot11_auth.$(OBJEXT)
-rm -f src/dot11/dot11_auth.lo
-rm -f src/dot11/dot11_base.$(OBJEXT)
-rm -f src/dot11/dot11_base.lo
-rm -f src/dot11/dot11_beacon.$(OBJEXT)
-rm -f src/dot11/dot11_beacon.lo
-rm -f src/dot11/dot11_control.$(OBJEXT)
-rm -f src/dot11/dot11_control.lo
-rm -f src/dot11/dot11_data.$(OBJEXT)
-rm -f src/dot11/dot11_data.lo
-rm -f src/dot11/dot11_mgmt.$(OBJEXT)
-rm -f src/dot11/dot11_mgmt.lo
-rm -f src/dot11/dot11_probe.$(OBJEXT)
-rm -f src/dot11/dot11_probe.lo
-rm -f src/dot1q.$(OBJEXT) -rm -f src/dot1q.$(OBJEXT)
-rm -f src/dot1q.lo -rm -f src/dot1q.lo
-rm -f src/dot3.$(OBJEXT) -rm -f src/dot3.$(OBJEXT)
@@ -614,7 +671,6 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/dhcpv6.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/dhcpv6.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/dns.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/dns.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/dns_record.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/dns_record.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/dot11.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/dot1q.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/dot1q.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/dot3.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/dot3.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/eapol.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/eapol.Plo@am__quote@
@@ -645,6 +701,14 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/tcp_stream.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/tcp_stream.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/udp.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/udp.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/utils.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@src/$(DEPDIR)/utils.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@src/dot11/$(DEPDIR)/dot11_assoc.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@src/dot11/$(DEPDIR)/dot11_auth.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@src/dot11/$(DEPDIR)/dot11_base.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@src/dot11/$(DEPDIR)/dot11_beacon.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@src/dot11/$(DEPDIR)/dot11_control.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@src/dot11/$(DEPDIR)/dot11_data.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@src/dot11/$(DEPDIR)/dot11_mgmt.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@src/dot11/$(DEPDIR)/dot11_probe.Plo@am__quote@
.cpp.o: .cpp.o:
@am__fastdepCXX_TRUE@ depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\ @am__fastdepCXX_TRUE@ depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\
@@ -676,6 +740,7 @@ mostlyclean-libtool:
clean-libtool: clean-libtool:
-rm -rf .libs _libs -rm -rf .libs _libs
-rm -rf src/.libs src/_libs -rm -rf src/.libs src/_libs
-rm -rf src/dot11/.libs src/dot11/_libs
distclean-libtool: distclean-libtool:
-rm -f libtool config.lt -rm -f libtool config.lt
@@ -700,27 +765,48 @@ uninstall-pkgconfigDATA:
@list='$(pkgconfig_DATA)'; test -n "$(pkgconfigdir)" || list=; \ @list='$(pkgconfig_DATA)'; test -n "$(pkgconfigdir)" || list=; \
files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \ files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
dir='$(DESTDIR)$(pkgconfigdir)'; $(am__uninstall_files_from_dir) dir='$(DESTDIR)$(pkgconfigdir)'; $(am__uninstall_files_from_dir)
install-libtins_includeHEADERS: $(libtins_include_HEADERS) install-libtinsHEADERS: $(libtins_HEADERS)
@$(NORMAL_INSTALL) @$(NORMAL_INSTALL)
@list='$(libtins_include_HEADERS)'; test -n "$(libtins_includedir)" || list=; \ @list='$(libtins_HEADERS)'; test -n "$(libtinsdir)" || list=; \
if test -n "$$list"; then \ if test -n "$$list"; then \
echo " $(MKDIR_P) '$(DESTDIR)$(libtins_includedir)'"; \ echo " $(MKDIR_P) '$(DESTDIR)$(libtinsdir)'"; \
$(MKDIR_P) "$(DESTDIR)$(libtins_includedir)" || exit 1; \ $(MKDIR_P) "$(DESTDIR)$(libtinsdir)" || exit 1; \
fi; \ fi; \
for p in $$list; do \ for p in $$list; do \
if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
echo "$$d$$p"; \ echo "$$d$$p"; \
done | $(am__base_list) | \ done | $(am__base_list) | \
while read files; do \ while read files; do \
echo " $(INSTALL_HEADER) $$files '$(DESTDIR)$(libtins_includedir)'"; \ echo " $(INSTALL_HEADER) $$files '$(DESTDIR)$(libtinsdir)'"; \
$(INSTALL_HEADER) $$files "$(DESTDIR)$(libtins_includedir)" || exit $$?; \ $(INSTALL_HEADER) $$files "$(DESTDIR)$(libtinsdir)" || exit $$?; \
done done
uninstall-libtins_includeHEADERS: uninstall-libtinsHEADERS:
@$(NORMAL_UNINSTALL) @$(NORMAL_UNINSTALL)
@list='$(libtins_include_HEADERS)'; test -n "$(libtins_includedir)" || list=; \ @list='$(libtins_HEADERS)'; test -n "$(libtinsdir)" || list=; \
files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \ files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
dir='$(DESTDIR)$(libtins_includedir)'; $(am__uninstall_files_from_dir) dir='$(DESTDIR)$(libtinsdir)'; $(am__uninstall_files_from_dir)
install-libtins_dot11HEADERS: $(libtins_dot11_HEADERS)
@$(NORMAL_INSTALL)
@list='$(libtins_dot11_HEADERS)'; test -n "$(libtins_dot11dir)" || list=; \
if test -n "$$list"; then \
echo " $(MKDIR_P) '$(DESTDIR)$(libtins_dot11dir)'"; \
$(MKDIR_P) "$(DESTDIR)$(libtins_dot11dir)" || exit 1; \
fi; \
for p in $$list; do \
if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
echo "$$d$$p"; \
done | $(am__base_list) | \
while read files; do \
echo " $(INSTALL_HEADER) $$files '$(DESTDIR)$(libtins_dot11dir)'"; \
$(INSTALL_HEADER) $$files "$(DESTDIR)$(libtins_dot11dir)" || exit $$?; \
done
uninstall-libtins_dot11HEADERS:
@$(NORMAL_UNINSTALL)
@list='$(libtins_dot11_HEADERS)'; test -n "$(libtins_dot11dir)" || list=; \
files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
dir='$(DESTDIR)$(libtins_dot11dir)'; $(am__uninstall_files_from_dir)
ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
@@ -940,7 +1026,7 @@ check-am: all-am
check: check-am check: check-am
all-am: Makefile $(LTLIBRARIES) $(DATA) $(HEADERS) all-am: Makefile $(LTLIBRARIES) $(DATA) $(HEADERS)
installdirs: installdirs:
for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(pkgconfigdir)" "$(DESTDIR)$(libtins_includedir)"; do \ for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(pkgconfigdir)" "$(DESTDIR)$(libtinsdir)" "$(DESTDIR)$(libtins_dot11dir)"; do \
test -z "$$dir" || $(MKDIR_P) "$$dir"; \ test -z "$$dir" || $(MKDIR_P) "$$dir"; \
done done
install: install-am install: install-am
@@ -971,6 +1057,8 @@ distclean-generic:
-test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
-rm -f src/$(DEPDIR)/$(am__dirstamp) -rm -f src/$(DEPDIR)/$(am__dirstamp)
-rm -f src/$(am__dirstamp) -rm -f src/$(am__dirstamp)
-rm -f src/dot11/$(DEPDIR)/$(am__dirstamp)
-rm -f src/dot11/$(am__dirstamp)
maintainer-clean-generic: maintainer-clean-generic:
@echo "This command is intended for maintainers to use" @echo "This command is intended for maintainers to use"
@@ -982,7 +1070,7 @@ clean-am: clean-generic clean-libLTLIBRARIES clean-libtool \
distclean: distclean-am distclean: distclean-am
-rm -f $(am__CONFIG_DISTCLEAN_FILES) -rm -f $(am__CONFIG_DISTCLEAN_FILES)
-rm -rf src/$(DEPDIR) -rm -rf src/$(DEPDIR) src/dot11/$(DEPDIR)
-rm -f Makefile -rm -f Makefile
distclean-am: clean-am distclean-compile distclean-generic \ distclean-am: clean-am distclean-compile distclean-generic \
distclean-hdr distclean-libtool distclean-tags distclean-hdr distclean-libtool distclean-tags
@@ -999,7 +1087,8 @@ info: info-am
info-am: info-am:
install-data-am: install-libtins_includeHEADERS install-pkgconfigDATA install-data-am: install-libtinsHEADERS install-libtins_dot11HEADERS \
install-pkgconfigDATA
install-dvi: install-dvi-am install-dvi: install-dvi-am
@@ -1030,7 +1119,7 @@ installcheck-am:
maintainer-clean: maintainer-clean-am maintainer-clean: maintainer-clean-am
-rm -f $(am__CONFIG_DISTCLEAN_FILES) -rm -f $(am__CONFIG_DISTCLEAN_FILES)
-rm -rf $(top_srcdir)/autom4te.cache -rm -rf $(top_srcdir)/autom4te.cache
-rm -rf src/$(DEPDIR) -rm -rf src/$(DEPDIR) src/dot11/$(DEPDIR)
-rm -f Makefile -rm -f Makefile
maintainer-clean-am: distclean-am maintainer-clean-generic maintainer-clean-am: distclean-am maintainer-clean-generic
@@ -1047,8 +1136,8 @@ ps: ps-am
ps-am: ps-am:
uninstall-am: uninstall-libLTLIBRARIES \ uninstall-am: uninstall-libLTLIBRARIES uninstall-libtinsHEADERS \
uninstall-libtins_includeHEADERS uninstall-pkgconfigDATA uninstall-libtins_dot11HEADERS uninstall-pkgconfigDATA
.MAKE: install-am install-strip .MAKE: install-am install-strip
@@ -1062,14 +1151,15 @@ uninstall-am: uninstall-libLTLIBRARIES \
install install-am install-data install-data-am install-dvi \ install install-am install-data install-data-am install-dvi \
install-dvi-am install-exec install-exec-am install-html \ install-dvi-am install-exec install-exec-am install-html \
install-html-am install-info install-info-am \ install-html-am install-info install-info-am \
install-libLTLIBRARIES install-libtins_includeHEADERS \ install-libLTLIBRARIES install-libtinsHEADERS \
install-man install-pdf install-pdf-am install-pkgconfigDATA \ install-libtins_dot11HEADERS install-man install-pdf \
install-ps install-ps-am install-strip installcheck \ install-pdf-am install-pkgconfigDATA install-ps install-ps-am \
installcheck-am installdirs maintainer-clean \ install-strip installcheck installcheck-am installdirs \
maintainer-clean-generic mostlyclean mostlyclean-compile \ maintainer-clean maintainer-clean-generic mostlyclean \
mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ mostlyclean-compile mostlyclean-generic mostlyclean-libtool \
tags uninstall uninstall-am uninstall-libLTLIBRARIES \ pdf pdf-am ps ps-am tags uninstall uninstall-am \
uninstall-libtins_includeHEADERS uninstall-pkgconfigDATA uninstall-libLTLIBRARIES uninstall-libtinsHEADERS \
uninstall-libtins_dot11HEADERS uninstall-pkgconfigDATA
# Tell versions [3.59,3.63) of GNU make to not export all variables. # Tell versions [3.59,3.63) of GNU make to not export all variables.

File diff suppressed because it is too large Load Diff

620
include/dot11/dot11_assoc.h Normal file
View File

@@ -0,0 +1,620 @@
/*
* Copyright (c) 2012, Matias Fontanini
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef TINS_DOT11_DOT11_ASSOC_H
#define TINS_DOT11_DOT11_ASSOC_H
#include "../dot11/dot11_mgmt.h"
namespace Tins {
/**
* \brief Class representing a Disassociation frame in the IEEE 802.11 Protocol.
*
*/
class Dot11Disassoc : public Dot11ManagementFrame {
public:
/**
* \brief This PDU's flag.
*/
static const PDU::PDUType pdu_flag = PDU::DOT11_DIASSOC;
/**
* \brief Constructor for creating a 802.11 Disassociation.
*
* Constructs a 802.11 Disassociation taking the destination
* and source hardware address.
*
* \param dst_hw_addr The destination hardware address.
* \param src_hw_addr The source hardware address.
*/
Dot11Disassoc(const address_type &dst_hw_addr = address_type(),
const address_type &src_hw_addr = address_type());
/**
* \brief Constructs a Dot11Disassoc object from a buffer and
* adds all identifiable PDUs found in the buffer as children
* of this one.
*
* If the next PDU is not recognized, then a RawPDU is used.
*
* If there is not enough size for the header in the buffer
* or the input data is malformed, a malformed_packet exception
* is thrown.
*
* \param buffer The buffer from which this PDU will be constructed.
* \param total_sz The total size of the buffer.
*/
Dot11Disassoc(const uint8_t *buffer, uint32_t total_sz);
/**
* \brief Getter for the reason code field.
*
* \return The stored reason code.
*/
uint16_t reason_code() const { return Endian::le_to_host(_body.reason_code); }
/**
* \brief Setter for the reason code field.
*
* \param new_reason_code The reason code to be set.
*/
void reason_code(uint16_t new_reason_code);
/**
* \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;
/**
* \brief Getter for the PDU's type.
* \sa PDU::pdu_type
*/
PDUType pdu_type() const { return pdu_flag; }
/**
* \brief Check wether this PDU matches the specified flag.
* \param flag The flag to match
* \sa PDU::matches_flag
*/
bool matches_flag(PDUType flag) const {
return flag == pdu_flag || Dot11ManagementFrame::matches_flag(flag);
}
/**
* \brief Clones this PDU.
*
* \sa PDU::clone
*/
Dot11Disassoc *clone() const {
return new Dot11Disassoc(*this);
}
private:
struct DisassocBody {
uint16_t reason_code;
};
uint32_t write_fixed_parameters(uint8_t *buffer, uint32_t total_sz);
DisassocBody _body;
};
/**
* \brief Class representing an Association Request frame in the IEEE 802.11 Protocol.
*
*/
class Dot11AssocRequest : public Dot11ManagementFrame {
public:
/**
* \brief This PDU's flag.
*/
static const PDU::PDUType pdu_flag = PDU::DOT11_ASSOC_REQ;
/**
* \brief Constructor for creating a 802.11 Association Request.
*
* Constructs a 802.11 Association Request taking the
* destination and source hardware address.
*
* \param dst_hw_addr The destination hardware address.
* \param src_hw_addr The source hardware address.
*/
Dot11AssocRequest(const address_type &dst_hw_addr = address_type(),
const address_type &src_hw_addr = address_type());
/**
* \brief Constructs a Dot11AssocRequest object from a buffer
* and adds all identifiable PDUs found in the buffer as children
* of this one.
*
* If the next PDU is not recognized, then a RawPDU is used.
*
* If there is not enough size for the header in the buffer
* or the input data is malformed, a malformed_packet exception
* is thrown.
*
* \param buffer The buffer from which this PDU will be constructed.
* \param total_sz The total size of the buffer.
*/
Dot11AssocRequest(const uint8_t *buffer, uint32_t total_sz);
/**
* \brief Getter for the Capabilities Information.
*
* \return A constant refereence to the stored Capabilities
* Information field.
*/
const capability_information& capabilities() const { return _body.capability;}
/**
* \brief Getter for the Capabilities Information.
*
* \return A refereence to the stored Capabilities Information
* field.
*/
capability_information& capabilities() { return _body.capability;}
/**
* \brief Getter for the listen interval field.
*
* \return The stored listen interval field.
*/
uint16_t listen_interval() const { return Endian::le_to_host(_body.listen_interval); }
/**
* \brief Setter for the listen interval field.
*
* \param new_listen_interval The listen interval to be set.
*/
void listen_interval(uint16_t new_listen_interval);
/**
* \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;
/**
* \brief Getter for the PDU's type.
* \sa PDU::pdu_type
*/
PDUType pdu_type() const { return pdu_flag; }
/**
* \brief Check wether this PDU matches the specified flag.
* \param flag The flag to match
* \sa PDU::matches_flag
*/
bool matches_flag(PDUType flag) const {
return flag == pdu_flag || Dot11ManagementFrame::matches_flag(flag);
}
/**
* \brief Clones this PDU.
*
* \sa PDU::clone
*/
Dot11AssocRequest *clone() const {
return new Dot11AssocRequest(*this);
}
private:
struct AssocReqBody {
capability_information capability;
uint16_t listen_interval;
};
uint32_t write_fixed_parameters(uint8_t *buffer, uint32_t total_sz);
AssocReqBody _body;
};
/**
* \brief Class representing an Association Response frame in the IEEE 802.11 Protocol.
*
*/
class Dot11AssocResponse : public Dot11ManagementFrame {
public:
/**
* \brief This PDU's flag.
*/
static const PDU::PDUType pdu_flag = PDU::DOT11_ASSOC_RESP;
/**
* \brief Constructor for creating a 802.11 Association Response.
*
* Constructors a 802.11 Association Response taking destination
* and source hardware address.
*
* \param dst_hw_addr The destination hardware address.
* \param src_hw_addr The source hardware address.
*/
Dot11AssocResponse(const address_type &dst_hw_addr = address_type(),
const address_type &src_hw_addr = address_type());
/**
* \brief Constructor which creates a Dot11AssocResponse object
* from a buffer and adds all identifiable PDUs found in the
* buffer as children of this one.
*
* If the next PDU is not recognized, then a RawPDU is used.
*
* If there is not enough size for the header in the buffer
* or the input data is malformed, a malformed_packet exception
* is thrown.
*
* \param buffer The buffer from which this PDU will be constructed.
* \param total_sz The total size of the buffer.
*/
Dot11AssocResponse(const uint8_t *buffer, uint32_t total_sz);
/**
* \brief Getter for the Capabilities Information field.
*
* \return A constant reference to the stored Capabilities
* Information field.
*/
const capability_information& capabilities() const { return _body.capability;}
/**
* \brief Getter for the Capabilities Information field.
*
* \return A reference to the stored Capabilities
* Information field.
*/
capability_information& capabilities() { return _body.capability;}
/**
* \brief Getter for the status code field.
*
* \return The stored status code.
*/
uint16_t status_code() const { return Endian::le_to_host(_body.status_code); }
/**
* \brief Getter for the AID field.
*
* \return The stored AID field.
*/
uint16_t aid() const { return Endian::le_to_host(_body.aid); }
/**
* \brief Setter for the status code.
*
* \param new_status_code The status code to be set.
*/
void status_code(uint16_t new_status_code);
/**
* \brief Setter for the AID field.
*
* \param new_aid The AID value to be set.
*/
void aid(uint16_t new_aid);
/**
* \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;
/**
* \brief Getter for the PDU's type.
* \sa PDU::pdu_type
*/
PDUType pdu_type() const { return pdu_flag; }
/**
* \brief Check wether this PDU matches the specified flag.
* \param flag The flag to match
* \sa PDU::matches_flag
*/
bool matches_flag(PDUType flag) const {
return flag == pdu_flag || Dot11ManagementFrame::matches_flag(flag);
}
/**
* \brief Clones this PDU.
*
* \sa PDU::clone
*/
Dot11AssocResponse *clone() const {
return new Dot11AssocResponse(*this);
}
private:
struct AssocRespBody {
capability_information capability;
uint16_t status_code;
uint16_t aid;
};
uint32_t write_fixed_parameters(uint8_t *buffer, uint32_t total_sz);
AssocRespBody _body;
};
/**
* \brief Class representing an ReAssociation Request frame in the IEEE 802.11 Protocol.
*
*/
class Dot11ReAssocRequest : public Dot11ManagementFrame {
public:
/**
* \brief This PDU's flag.
*/
static const PDU::PDUType pdu_flag = PDU::DOT11_REASSOC_REQ;
/**
* \brief Constructor for creating a 802.11 ReAssociation Request.
*
* Constructors a 802.11 Association Request taking the destination
* and source hardware address.
*
* \param dst_hw_addr The destination hardware address.
* \param src_hw_addr The source hardware address.
*/
Dot11ReAssocRequest(const address_type &dst_hw_addr = address_type(),
const address_type &src_hw_addr = address_type());
/**
* \brief Constructs a Dot11AssocRequest object from a buffer
* and adds all identifiable PDUs found in the buffer as
* children of this one.
*
* If the next PDU is not recognized, then a RawPDU is used.
*
* If there is not enough size for the header in the buffer
* or the input data is malformed, a malformed_packet exception
* is thrown.
*
* \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 Getter for the Capabilities Information.
*
* \return A constant reference to the stored Capabilities
* Information field.
*/
const capability_information& capabilities() const { return _body.capability;}
/**
* \brief Getter for the Capabilities Information.
*
* \return A reference to the stored Capabilities Information
* field.
*/
capability_information& capabilities() { return _body.capability;}
/**
* \brief Getter for the listen interval field.
*
* \return The stored listen interval.
*/
uint16_t listen_interval() const { return Endian::le_to_host(_body.listen_interval); }
/**
* \brief Getter for the current ap field.
*
* \return The current ap.
*/
address_type current_ap() const { return _body.current_ap; }
/**
* \brief Setter for the listen interval field.
*
* \param new_listen_interval The listen interval to be set.
*/
void listen_interval(uint16_t new_listen_interval);
/**
* \brief Setter for the current ap.
*
* \param new_current_ap The address of the current ap.
*/
void current_ap(const address_type &new_current_ap);
/**
* \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;
/**
* \brief Getter for the PDU's type.
* \sa PDU::pdu_type
*/
PDUType pdu_type() const { return pdu_flag; }
/**
* \brief Check wether this PDU matches the specified flag.
* \param flag The flag to match
* \sa PDU::matches_flag
*/
bool matches_flag(PDUType flag) const {
return flag == pdu_flag || Dot11ManagementFrame::matches_flag(flag);
}
/**
* \brief Clones this PDU.
*
* \sa PDU::clone
*/
Dot11ReAssocRequest *clone() const {
return new Dot11ReAssocRequest(*this);
}
private:
struct ReAssocReqBody {
capability_information capability;
uint16_t listen_interval;
uint8_t current_ap[address_type::address_size];
};
uint32_t write_fixed_parameters(uint8_t *buffer, uint32_t total_sz);
ReAssocReqBody _body;
};
/**
* \brief IEEE 802.11 ReAssociation Response frame.
*
*/
class Dot11ReAssocResponse : public Dot11ManagementFrame {
public:
/**
* \brief This PDU's flag.
*/
static const PDU::PDUType pdu_flag = PDU::DOT11_REASSOC_RESP;
/**
* \brief Constructor for creating a 802.11 Association Response.
*
* Constructs a 802.11 ReAssociation Response taking the
* destination and source hardware address.
*
* \param dst_hw_addr The destination hardware address.
* \param src_hw_addr The source hardware address.
*/
Dot11ReAssocResponse(const address_type &dst_hw_addr = address_type(),
const address_type &src_hw_addr = address_type());
/**
* \brief Constructs a Dot11ReAssocResponse object from a buffer
* and adds all identifiable PDUs found in the buffer as children
* of this one.
*
* If the next PDU is not recognized, then a RawPDU is used.
*
* If there is not enough size for the header in the buffer
* or the input data is malformed, a malformed_packet exception
* is thrown.
*
* \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 Getter for the Capabilities Information.
*
* \return A constant reference to the stored Capabilities
* Information field.
*/
const capability_information& capabilities() const { return _body.capability;}
/**
* \brief Getter for the Capabilities Information.
*
* \return A reference to the stored Capabilities Information
* field.
*/
capability_information& capabilities() { return _body.capability;}
/**
* \brief Getter for the status code field.
*
* \return The stored status code.
*/
uint16_t status_code() const { return Endian::le_to_host(_body.status_code); }
/**
* \brief Getter for the AID field.
*
* \return The stored AID field value.
*/
uint16_t aid() const { return Endian::le_to_host(_body.aid); }
/**
* \brief Setter for the status code field.
*
* \param new_status_code The status code to be set.
*/
void status_code(uint16_t new_status_code);
/**
* \brief Setter for the AID field.
*
* \param new_aid The AID to be set.
*/
void aid(uint16_t new_aid);
/**
* \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;
/**
* \brief Getter for the PDU's type.
* \sa PDU::pdu_type
*/
PDUType pdu_type() const { return pdu_flag; }
/**
* \brief Check wether this PDU matches the specified flag.
* \param flag The flag to match
* \sa PDU::matches_flag
*/
bool matches_flag(PDUType flag) const {
return flag == pdu_flag || Dot11ManagementFrame::matches_flag(flag);
}
/**
* \brief Clones this PDU.
*
* \sa PDU::clone
*/
Dot11ReAssocResponse *clone() const {
return new Dot11ReAssocResponse(*this);
}
private:
struct ReAssocRespBody {
capability_information capability;
uint16_t status_code;
uint16_t aid;
};
uint32_t write_fixed_parameters(uint8_t *buffer, uint32_t total_sz);
ReAssocRespBody _body;
};
} // namespace Tins
#endif // TINS_DOT11_DOT11_ASSOC_H

258
include/dot11/dot11_auth.h Normal file
View File

@@ -0,0 +1,258 @@
/*
* Copyright (c) 2012, Matias Fontanini
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef TINS_DOT11_DOT11_AUTH_H
#define TINS_DOT11_DOT11_AUTH_H
#include "../dot11/dot11_mgmt.h"
namespace Tins {
/**
* \brief IEEE 802.11 Authentication Request frame.
*/
class Dot11Authentication : public Dot11ManagementFrame {
public:
/**
* \brief This PDU's flag.
*/
static const PDU::PDUType pdu_flag = PDU::DOT11_AUTH;
/**
* \brief Constructor for creating a 802.11 Authentication.
*
* Constructs a 802.11 Dot11Authentication taking the
* destination and source hardware address.
*
* \param dst_hw_addr The destination hardware address.
* \param src_hw_addr The source hardware address.
*/
Dot11Authentication(const address_type &dst_hw_addr = address_type(),
const address_type &src_hw_addr = address_type());
/**
* \brief Constructs a Dot11Authentication object from a buffer
* and adds all identifiable PDUs found in the buffer as children
* of this one.
*
* If the next PDU is not recognized, then a RawPDU is used.
*
* If there is not enough size for the header in the buffer
* or the input data is malformed, a malformed_packet exception
* is thrown.
*
* \param buffer The buffer from which this PDU will be constructed.
* \param total_sz The total size of the buffer.
*/
Dot11Authentication(const uint8_t *buffer, uint32_t total_sz);
/**
* \brief Getter for the Authetication Algorithm Number field.
*
* \return The stored authentication algorithm number.
*/
uint16_t auth_algorithm() const {return Endian::le_to_host(_body.auth_algorithm); }
/**
* \brief Getter for the Authetication Sequence Number field.
*
* \return The stored authentication sequence number.
*/
uint16_t auth_seq_number() const {return Endian::le_to_host(_body.auth_seq_number); }
/**
* \brief Getter for the status code field.
*
* \return The stored status code.
*/
uint16_t status_code() const { return Endian::le_to_host(_body.status_code); }
/**
* \brief Setter for the Authetication Algorithm Number field.
*
* \param new_auth_algorithm The Authetication Algorithm Number
* to be set.
*/
void auth_algorithm(uint16_t new_auth_algorithm);
/**
* \brief Setter for the Authetication Sequence Number field.
*
* \param new_auth_seq_number The Authetication Sequence Number
* to be set.
*/
void auth_seq_number(uint16_t new_auth_seq_number);
/**
* \brief Setter for the status code field.
*
* \param new_status_code The status code to be set.
*/
void status_code(uint16_t new_status_code);
/**
* \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;
/**
* \brief Getter for the PDU's type.
* \sa PDU::pdu_type
*/
PDUType pdu_type() const { return pdu_flag; }
/**
* \brief Check wether this PDU matches the specified flag.
* \param flag The flag to match
* \sa PDU::matches_flag
*/
bool matches_flag(PDUType flag) const {
return flag == pdu_flag || Dot11ManagementFrame::matches_flag(flag);
}
/**
* \brief Clones this PDU.
*
* \sa PDU::clone
*/
Dot11Authentication *clone() const {
return new Dot11Authentication(*this);
}
private:
struct AuthBody {
uint16_t auth_algorithm;
uint16_t auth_seq_number;
uint16_t status_code;
};
uint32_t write_fixed_parameters(uint8_t *buffer, uint32_t total_sz);
AuthBody _body;
};
/**
* \brief IEEE 802.11 Deauthentication frame.
*
*/
class Dot11Deauthentication : public Dot11ManagementFrame {
public:
/**
* \brief This PDU's flag.
*/
static const PDU::PDUType pdu_flag = PDU::DOT11_DEAUTH;
/**
* \brief Constructor for creating a 802.11 Deauthentication.
*
* Constructs a 802.11 Deauthentication taking the
* destination and source hardware address.
*
* \param dst_hw_addr The destination hardware address.
* \param src_hw_addr The source hardware address.
*/
Dot11Deauthentication(const address_type &dst_hw_addr = address_type(),
const address_type &src_hw_addr = address_type());
/**
* \brief Constructs a Dot11Deauthentication object from a buffer
* and adds all identifiable PDUs found in the buffer as children
* of this one.
*
* If the next PDU is not recognized, then a RawPDU is used.
*
* If there is not enough size for the header in the buffer
* or the input data is malformed, a malformed_packet exception
* is thrown.
*
* \param buffer The buffer from which this PDU will be constructed.
* \param total_sz The total size of the buffer.
*/
Dot11Deauthentication(const uint8_t *buffer, uint32_t total_sz);
/**
* \brief Getter for the reason code field.
*
* \return The reason code to be set.
*/
uint16_t reason_code() const { return Endian::le_to_host(_body.reason_code); }
/**
* \brief Setter for the reason code field.
*
* \param new_reason_code The reason code to be set.
*/
void reason_code(uint16_t new_reason_code);
/**
* \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;
/**
* \brief Getter for the PDU's type.
* \sa PDU::pdu_type
*/
PDUType pdu_type() const { return pdu_flag; }
/**
* \brief Check wether this PDU matches the specified flag.
* \param flag The flag to match
* \sa PDU::matches_flag
*/
bool matches_flag(PDUType flag) const {
return flag == pdu_flag || Dot11ManagementFrame::matches_flag(flag);
}
/**
* \brief Clones this PDU.
*
* \sa PDU::clone
*/
Dot11Deauthentication *clone() const {
return new Dot11Deauthentication(*this);
}
private:
struct DeauthBody {
uint16_t reason_code;
};
uint32_t write_fixed_parameters(uint8_t *buffer, uint32_t total_sz);
DeauthBody _body;
};
} // namespace Tins
#endif // TINS_DOT11_DOT11_AUTH_H

498
include/dot11/dot11_base.h Normal file
View File

@@ -0,0 +1,498 @@
/*
* Copyright (c) 2012, Matias Fontanini
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef TINS_DOT11_DOT11_H
#define TINS_DOT11_DOT11_H
#include <list>
#include "../pdu.h"
#include "../pdu_option.h"
#include "../small_uint.h"
#include "../hw_address.h"
#include "../endianness.h"
#include "../cxxstd.h"
#include "../macros.h"
namespace Tins {
class RSNInformation;
/**
* \brief Class representing an 802.11 frame.
*/
class Dot11 : public PDU {
public:
typedef HWAddress<6> address_type;
/**
* \brief This PDU's flag.
*/
static const PDU::PDUType pdu_flag = PDU::DOT11;
/**
* \brief Broadcast hardware address.
*/
static const address_type BROADCAST;
/**
* \brief Enum for the different types of 802.11 frames.
*
*/
enum Types {
MANAGEMENT = 0,
CONTROL = 1,
DATA = 2
};
/**
* \brief Enum for the different types of tagged options.
*/
enum OptionTypes {
SSID,
SUPPORTED_RATES,
FH_SET,
DS_SET,
CF_SET,
TIM,
IBSS_SET,
COUNTRY,
HOPPING_PATTERN_PARAMS,
HOPPING_PATTERN_TABLE,
REQUEST_INFORMATION,
BSS_LOAD,
EDCA,
TSPEC,
TCLAS,
SCHEDULE,
CHALLENGE_TEXT,
POWER_CONSTRAINT = 32,
POWER_CAPABILITY,
TPC_REQUEST,
TPC_REPORT,
SUPPORTED_CHANNELS,
CHANNEL_SWITCH,
MEASUREMENT_REQUEST,
MEASUREMENT_REPORT,
QUIET,
IBSS_DFS,
ERP_INFORMATION,
TS_DELAY,
TCLAS_PROCESSING,
QOS_CAPABILITY = 46,
RSN = 48,
EXT_SUPPORTED_RATES = 50
};
/**
* \brief Enum for the different subtypes of 802.11 management frames.
*
*/
enum ManagementSubtypes {
ASSOC_REQ = 0,
ASSOC_RESP = 1,
REASSOC_REQ = 2,
REASSOC_RESP = 3,
PROBE_REQ = 4,
PROBE_RESP = 5,
BEACON = 8,
ATIM = 9,
DISASSOC = 10,
AUTH = 11,
DEAUTH = 12
};
/**
* \brief Enum for the different subtypes of 802.11 control frames.
*
*/
enum ControlSubtypes {
BLOCK_ACK_REQ = 8,
BLOCK_ACK = 9,
PS = 10,
RTS = 11,
CTS = 12,
ACK = 13,
CF_END = 14,
CF_END_ACK = 15
};
/**
* \brief Enum fro the different subtypes of 802.11 data frames.
*
*/
enum DataSubtypes {
DATA_DATA = 0,
DATA_CF_ACK = 1,
DATA_CF_POLL = 2,
DATA_CF_ACK_POLL = 3,
DATA_NULL = 4,
CF_ACK = 5,
CF_POLL = 6,
CF_ACK_POLL = 7,
QOS_DATA_DATA = 8,
QOS_DATA_CF_ACK = 9,
QOS_DATA_CF_POLL = 10,
QOS_DATA_CF_ACK_POLL = 11,
QOS_DATA_NULL = 12
};
/**
* \brief IEEE 802.11 options struct.
*/
typedef PDUOption<uint8_t> option;
/**
* \brief Constructor for creating an 802.11 PDU
*
* Constructor that builds an 802.11 PDU taking the interface index,
* destination's and source's MAC.
*
* \param dst_hw_addr The destination hardware address.
*/
Dot11(const address_type &dst_hw_addr = address_type());
/**
* \brief Constructs 802.11 PDU from a buffer and adds all
* identifiable PDUs found in the buffer as children of this one.
*
* If the next PDU is not recognized, then a RawPDU is used.
*
* If there is not enough size for a 802.11 header in the
* buffer, a malformed_packet exception is thrown.
*
* \param buffer The buffer from which this PDU will be constructed.
* \param total_sz The total size of the buffer.
*/
Dot11(const uint8_t *buffer, uint32_t total_sz);
/**
* \brief Getter for the protocol version.
*
* \return uint8_t containing the protocol version.
*/
small_uint<2> protocol() const { return _header.control.protocol; }
/**
* \brief Getter for the 802.11 frame's type.
*
* \return uint8_t containing the type of this 802.11 frame.
*/
small_uint<2> type() const { return _header.control.type; }
/**
* \brief Getter for the 802.11 frame's subtype.
*
* \return uint8_t cotaining the subtype of this 802.11 frame.
*/
small_uint<4> subtype() const { return _header.control.subtype; }
/**
* \brief Getter for the 802.11 frame's To-DS field.
*
* \return small_uint<1> containing the To-DS field.
*/
small_uint<1> to_ds() const { return _header.control.to_ds; }
/**
* \brief Getter for the 802.11 frame's From-DS field.
*
* \return small_uint<1> containing the From-DS field.
*/
small_uint<1> from_ds() const { return _header.control.from_ds; }
/**
* \brief Getter for the 802.11 frame's More-Frag field.
*
* \return small_uint<1> containing the More-Frag field.
*/
small_uint<1> more_frag() const { return _header.control.more_frag; }
/**
* \brief Getter for the 802.11 frame's Retry field.
*
* \return small_uint<1> containing the Retry field.
*/
small_uint<1> retry() const { return _header.control.retry; }
/**
* \brief Getter for the 802.11 frame's Power-Management field.
*
* \return small_uint<1> containing the Power-Management field.
*/
small_uint<1> power_mgmt() const { return _header.control.power_mgmt; }
/**
* \brief Getter for the 802.11 frame's WEP field.
*
* \return small_uint<1> containing the WEP field.
*/
small_uint<1> wep() const { return _header.control.wep; }
/**
* \brief Getter for the 802.11 frame's Order field.
*
* \return small_uint<1> containing the Order field.
*/
small_uint<1> order() const { return _header.control.order; }
/**
* \brief Getter for the Duration-ID field.
*
* \return uint16_t containing the Duration-ID field.
*/
uint16_t duration_id() const { return Endian::le_to_host(_header.duration_id); }
/**
* \brief Getter for the first address.
*
* \return address_type containing the first address.
*/
address_type addr1() const { return _header.addr1; }
/**
* \brief Setter for the protocol version.
*
* \param new_proto The new protocol version.
*/
void protocol(small_uint<2> new_proto);
/**
* \brief Setter for the 802.11 frame's type.
*
* \param new_type The new type of this 802.11 frame.
*/
void type(small_uint<2> new_type);
/**
* \brief Setter for the 802.11 frame's subtype.
*
* \param new_subtype The new subtype of this 802.11 frame.
*/
void subtype(small_uint<4> new_subtype);
/**
* \brief Setter for the 802.11 frame's To-DS field.
*
* \param new_value The new value of the To-DS field.
*/
void to_ds(small_uint<1> new_value);
/**
* \brief Setter for the 802.11 frame's From-DS field.
*
* \param new_value The new value of the From-DS field.
*/
void from_ds(small_uint<1> new_value);
/**
* \brief Setter for the 802.11 frame's More-Frag field.
*
* \param new_value The new value of the More-Frag field.
*/
void more_frag(small_uint<1> new_value);
/**
* \brief Setter for the 802.11 frame's Retry field.
*
* \param new_value sThe new value of the Retry field.
*/
void retry(small_uint<1> new_value);
/**
* \brief Setter for the 802.11 frame's Power-Management field.
*
* \param new_value The new value of the Power-Management field.
*/
void power_mgmt(small_uint<1> new_value);
/**
* \brief Setter for the 802.11 frame's WEP field.
*
* \param new_value The new value of the WEP field.
*/
void wep(small_uint<1> new_value);
/**
* \brief Setter for the 802.11 frame's Order field.
*
* \param new_value The new value of the Order field.
*/
void order(small_uint<1> new_value);
/**
* \brief Setter for the Duration-ID field.
*
* \param new_duration_id The new value of the Duration-ID field.
*/
void duration_id(uint16_t new_duration_id);
/**
* \brief Setter for the first address.
*
* \param new_addr1 The new first address.
*/
void addr1(const address_type &new_addr1);
/* Virtual methods */
/**
* \brief Returns the 802.11 frame's header length.
*
* \return An uint32_t with the header's size.
* \sa PDU::header_size()
*/
uint32_t header_size() const;
#ifndef WIN32
/**
* \sa PDU::send()
*/
void send(PacketSender &sender, const NetworkInterface &iface);
#endif // WIN32
/**
* \brief Adds a new option to this Dot11 PDU.
* \param opt The option to be added.
*/
void add_option(const option &opt);
#if TINS_IS_CXX11
/**
* \brief Adds a new option to this Dot11 PDU.
*
* The option is move-constructed
*
* \param opt The option to be added.
*/
void add_option(option &&opt) {
internal_add_option(opt);
_options.push_back(std::move(opt));
}
#endif
/**
* \brief Looks up a tagged option in the option list.
*
* The returned pointer <b>must not</b> be free'd.
*
* \param opt The option identifier.
* \return The option found, or 0 if no such option has been set.
*/
const option *search_option(OptionTypes opt) const;
/**
* \brief Getter for the PDU's type.
* \sa PDU::pdu_type
*/
PDUType pdu_type() const { return pdu_flag; }
/**
* \sa PDU::clone
*/
Dot11 *clone() const {
return new Dot11(*this);
}
/**
* \brief Check wether this PDU matches the specified flag.
* \param flag The flag to match
* \sa PDU::matches_flag
*/
bool matches_flag(PDUType flag) const {
return flag == pdu_flag;
}
/**
* \brief Allocates an Dot11 PDU from a buffer.
*
* This can be used somehow as a "virtual constructor". This
* method instantiates a subclass of Dot11 from the given buffer.
* The allocated class' type will be figured out from the
* information provided in the buffer.
*
* \param buffer The buffer from which to take the PDU data.
* \param total_sz The total size of the buffer.
* \return The allocated Dot11 PDU.
*/
static Dot11 *from_bytes(const uint8_t *buffer, uint32_t total_sz);
protected:
virtual uint32_t write_ext_header(uint8_t *buffer, uint32_t total_sz) { return 0; }
virtual uint32_t write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) { return 0; }
void parse_tagged_parameters(const uint8_t *buffer, uint32_t total_sz);
void add_tagged_option(OptionTypes opt, uint8_t len, const uint8_t *val);
protected:
/**
* Struct that represents the 802.11 header
*/
TINS_BEGIN_PACK
struct ieee80211_header {
TINS_BEGIN_PACK
struct {
#if TINS_IS_LITTLE_ENDIAN
uint16_t protocol:2,
type:2,
subtype:4,
to_ds:1,
from_ds:1,
more_frag:1,
retry:1,
power_mgmt:1,
more_data:1,
wep:1,
order:1;
#elif TINS_IS_BIG_ENDIAN
uint16_t subtype:4,
type:2,
protocol:2,
order:1,
wep:1,
more_data:1,
power_mgmt:1,
retry:1,
more_frag:1,
from_ds:1,
to_ds:1;
#endif
} TINS_END_PACK control;
uint16_t duration_id;
uint8_t addr1[address_type::address_size];
} TINS_END_PACK;
private:
Dot11(const ieee80211_header *header_ptr);
void internal_add_option(const option &opt);
void write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent);
ieee80211_header _header;
uint32_t _options_size;
std::list<option> _options;
};
}
#endif // TINS_DOT11_DOT11_H

View File

@@ -0,0 +1,164 @@
/*
* Copyright (c) 2012, Matias Fontanini
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef TINS_DOT11_DOT11_BEACON_H
#define TINS_DOT11_DOT11_BEACON_H
#include "../dot11/dot11_mgmt.h"
namespace Tins {
/**
* \brief Class representing an 802.11 Beacon.
*
*/
class Dot11Beacon : public Dot11ManagementFrame {
public:
/**
* \brief This PDU's flag.
*/
static const PDU::PDUType pdu_flag = PDU::DOT11_BEACON;
/**
* \brief Constructor for creating a 802.11 Beacon.
*
* Constructs a 802.11 Beacon taking destination and source
* hardware address.
*
* \param dst_hw_addr The destination hardware address.
* \param src_hw_addr The source hardware address.
*/
Dot11Beacon(const address_type &dst_hw_addr = address_type(),
const address_type &src_hw_addr = address_type());
/**
* \brief Constructs a Dot11Beacon object from a buffer and adds
* all identifiable PDUs found in the buffer as children of this
* one.
*
* If the next PDU is not recognized, then a RawPDU is used.
*
* If there is not enough size for the header in the buffer
* or the input data is malformed, a malformed_packet exception
* is thrown.
*
* \param buffer The buffer from which this PDU will be constructed.
* \param total_sz The total size of the buffer.
*/
Dot11Beacon(const uint8_t *buffer, uint32_t total_sz);
/**
* \brief Getter for the timestamp field.
*
* \return The stored timestamp value.
*/
uint64_t timestamp() const { return Endian::le_to_host(_body.timestamp); }
/**
* \brief Getter for the interval field.
*
* \return The stored interval value.
*/
uint16_t interval() const { return Endian::le_to_host(_body.interval); }
/**
* \brief Getter for the Capabilities Information structure.
*
* \return A constant refereence to the stored Capabilities
* Information field.
*/
const capability_information& capabilities() const { return _body.capability; }
/**
* \brief Getter for the Capabilities Information.
*
* \return A refereence to the stored Capabilities Information
* field.
*/
capability_information& capabilities() { return _body.capability; }
/**
* \brief Setter for the timestamp field.
*
* \param new_timestamp The timestamp to be set.
*/
void timestamp(uint64_t new_timestamp);
/**
* \brief Setter for the interval field.
*
* \param new_interval The interval to be set.
*/
void interval(uint16_t new_interval);
/**
* \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;
/**
* \brief Check wether this PDU matches the specified flag.
* \param flag The flag to match
* \sa PDU::matches_flag
*/
bool matches_flag(PDUType flag) const {
return flag == pdu_flag || Dot11ManagementFrame::matches_flag(flag);
}
/**
* \brief Clones this PDU.
*
* \sa PDU::clone
*/
Dot11Beacon *clone() const {
return new Dot11Beacon(*this);
}
/**
* \brief Getter for the PDU's type.
* \sa PDU::pdu_type
*/
PDUType pdu_type() const { return pdu_flag; }
private:
TINS_BEGIN_PACK
struct BeaconBody {
uint64_t timestamp;
uint16_t interval;
capability_information capability;
} TINS_END_PACK;
uint32_t write_fixed_parameters(uint8_t *buffer, uint32_t total_sz);
BeaconBody _body;
};
} // namespace Tins
#endif // TINS_DOT11_DOT11_BEACON_H

View File

@@ -0,0 +1,743 @@
/*
* Copyright (c) 2012, Matias Fontanini
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef TINS_DOT11_DOT11_CONTROL_H
#define TINS_DOT11_DOT11_CONTROL_H
#include "../dot11/dot11_base.h"
namespace Tins {
/**
* \brief Class that represents an 802.11 control frame.
*/
class Dot11Control : public Dot11 {
public:
/**
* \brief This PDU's flag.
*/
static const PDU::PDUType pdu_flag = PDU::DOT11_CONTROL;
/**
* \brief Constructor for creating a 802.11 control frame PDU
*
* Constructs a 802.11 Control PDU taking the destination and
* source hardware addresses.
*
* \param dst_addr The destination hardware address.
*/
Dot11Control(const address_type &dst_addr = address_type());
/**
* \brief Constructs a Dot11Control object from a buffer and
* adds all identifiable PDUs found in the buffer as children
* of this one.
*
* If the next PDU is not recognized, then a RawPDU is used.
*
* If there is not enough size for the header in the buffer
* or the input data is malformed, a malformed_packet exception
* is thrown.
*
* \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
*/
PDUType pdu_type() const { return PDU::DOT11_CONTROL; }
/**
* \brief Check wether this PDU matches the specified flag.
* \param flag The flag to match
* \sa PDU::matches_flag
*/
bool matches_flag(PDUType flag) const {
return flag == PDU::DOT11_CONTROL || Dot11::matches_flag(flag);
}
};
/**
* \brief Class that represents an abstraction of the 802.11 control frames
* that contain a target address.
*/
class Dot11ControlTA : public Dot11Control {
public:
/**
* \brief Getter for the target address field.
*/
address_type target_addr() const { return _taddr; }
/**
* \brief Setter for the target address field.
* \param addr The new target address.
*/
void target_addr(const address_type &addr);
protected:
/**
* \brief Constructor for creating a 802.11 control frame TA PDU
*
* Constructs a 802.11 PDU taking the destination and source
* hardware addresses.
*
* \param dst_addr The destination hardware address.
* \param target_addr The source hardware address.
*/
Dot11ControlTA(const address_type &dst_addr = address_type(),
const address_type &target_addr = address_type());
/**
* \brief Constructs a Dot11ControlTA object from a buffer and
* adds all identifiable PDUs found in the buffer as children
* of this one.
*
* If the next PDU is not recognized, then a RawPDU is used.
*
* If there is not enough size for the header in the buffer
* or the input data is malformed, a malformed_packet exception
* is thrown.
*
* \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 Returns the 802.11 frame's header length.
*
* \return An uint32_t with the header's size.
* \sa PDU::header_size()
*/
uint32_t header_size() const;
protected:
/**
* \brief Getter for the control ta additional fields size.
*/
uint32_t controlta_size() const { return _taddr.size() + sizeof(ieee80211_header); }
uint32_t write_ext_header(uint8_t *buffer, uint32_t total_sz);
private:
address_type _taddr;
};
/**
* \brief IEEE 802.11 RTS frame.
*/
class Dot11RTS : public Dot11ControlTA {
public:
/**
* \brief This PDU's flag.
*/
static const PDU::PDUType pdu_flag = PDU::DOT11_RTS;
/**
* \brief Constructor for creating a 802.11 RTS frame PDU
*
* Constructs a 802.11 RTS PDU taking the destination and source
* hardware addresses.
*
* \param dst_addr The destination hardware address.
* \param target_addr The source hardware address.
*/
Dot11RTS(const address_type &dst_addr = address_type(),
const address_type &target_addr = address_type());
/**
* \brief Constructs a Dot11RTS object from a buffer and adds all
* identifiable PDUs found in the buffer as children of this one.
*
* If the next PDU is not recognized, then a RawPDU is used.
*
* If there is not enough size for the header in the buffer
* or the input data is malformed, a malformed_packet exception
* is thrown.
*
* \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 Clones this PDU.
*
* \sa PDU::clone
*/
Dot11RTS *clone() const {
return new Dot11RTS(*this);
}
/**
* \brief Getter for the PDU's type.
* \sa PDU::pdu_type
*/
PDUType pdu_type() const { return pdu_flag; }
/**
* \brief Check wether this PDU matches the specified flag.
* \param flag The flag to match
* \sa PDU::matches_flag
*/
bool matches_flag(PDUType flag) const {
return flag == pdu_flag || Dot11Control::matches_flag(flag);
}
};
class Dot11PSPoll : public Dot11ControlTA {
public:
/**
* \brief This PDU's flag.
*/
static const PDU::PDUType pdu_flag = PDU::DOT11_PS_POLL;
/**
* \brief Constructor for creating a 802.11 PS-Poll frame PDU
*
* Constructs a 802.11 PDU taking the destination and source
* hardware addresses.
*
* \param dst_addr The destination hardware address.
* \param target_addr The source hardware address.
*/
Dot11PSPoll(const address_type &dst_addr = address_type(),
const address_type &target_addr = address_type());
/**
* \brief Constructs a Dot11PSPoll object from a buffer and
* adds all identifiable PDUs found in the buffer as children of
* this one.
*
* If the next PDU is not recognized, then a RawPDU is used.
*
* If there is not enough size for the header in the buffer
* or the input data is malformed, a malformed_packet exception
* is thrown.
*
* \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);
/**
* \brief Clones this PDU.
*
* \sa PDU::clone
*/
Dot11PSPoll *clone() const {
return new Dot11PSPoll(*this);
}
/**
* \brief Getter for the PDU's type.
* \sa PDU::pdu_type
*/
PDUType pdu_type() const { return pdu_flag; }
/**
* \brief Check wether this PDU matches the specified flag.
* \param flag The flag to match
* \sa PDU::matches_flag
*/
bool matches_flag(PDUType flag) const {
return flag == pdu_flag || Dot11Control::matches_flag(flag);
}
};
class Dot11CFEnd : public Dot11ControlTA {
public:
/**
* \brief This PDU's flag.
*/
static const PDU::PDUType pdu_flag = PDU::DOT11_CF_END;
/**
* \brief Constructor for creating a 802.11 CF-End frame PDU
*
* Constructs a 802.11 PDU taking the destination and source
* hardware addresses.
*
* \param dst_addr The destination hardware address.
* \param target_addr The source hardware address.
*/
Dot11CFEnd(const address_type &dst_addr = address_type(),
const address_type &target_addr = address_type());
/**
* \brief Constructs a Dot11CFEnd object from a buffer and adds
* all identifiable PDUs found in the buffer as children of this
* one.
*
* If the next PDU is not recognized, then a RawPDU is used.
*
* If there is not enough size for the header in the buffer
* or the input data is malformed, a malformed_packet exception
* is thrown.
*
* \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);
/**
* \brief Clones this PDU.
*
* \sa PDU::clone
*/
Dot11CFEnd *clone() const {
return new Dot11CFEnd(*this);
}
/**
* \brief Getter for the PDU's type.
* \sa PDU::pdu_type
*/
PDUType pdu_type() const { return pdu_flag; }
/**
* \brief Check wether this PDU matches the specified flag.
* \param flag The flag to match
* \sa PDU::matches_flag
*/
bool matches_flag(PDUType flag) const {
return flag == pdu_flag || Dot11Control::matches_flag(flag);
}
};
class Dot11EndCFAck : public Dot11ControlTA {
public:
/**
* \brief This PDU's flag.
*/
static const PDU::PDUType pdu_flag = PDU::DOT11_END_CF_ACK;
/**
* \brief Constructor for creating a 802.11 End-CF-Ack frame PDU
*
* Constructs a 802.11 PDU taking the destination and source
* hardware addresses.
*
* \param dst_addr The destination hardware address.
* \param target_addr The source hardware address.
*/
Dot11EndCFAck(const address_type &dst_addr = address_type(),
const address_type &target_addr = address_type());
/**
* \brief Constructs a Dot11EndCFAck frame object from a buffer
* and adds all identifiable PDUs found in the buffer as children
* of this one.
*
* If the next PDU is not recognized, then a RawPDU is used.
*
* If there is not enough size for the header in the buffer
* or the input data is malformed, a malformed_packet exception
* is thrown.
*
* \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);
/**
* \brief Clones this PDU.
*
* \sa PDU::clone
*/
Dot11EndCFAck *clone() const {
return new Dot11EndCFAck(*this);
}
/**
* \brief Getter for the PDU's type.
* \sa PDU::pdu_type
*/
PDUType pdu_type() const { return pdu_flag; }
/**
* \brief Check wether this PDU matches the specified flag.
* \param flag The flag to match
* \sa PDU::matches_flag
*/
bool matches_flag(PDUType flag) const {
return flag == pdu_flag || Dot11Control::matches_flag(flag);
}
};
class Dot11Ack : public Dot11Control {
public:
/**
* \brief This PDU's flag.
*/
static const PDU::PDUType pdu_flag = PDU::DOT11_ACK;
/**
* \brief Constructor for creating a 802.11 Ack frame PDU
*
* Constructs a 802.11 PDU taking the destination and source
* hardware addresses.
*
* \param dst_addr The destination hardware address.
*/
Dot11Ack(const address_type &dst_addr = address_type());
/**
* \brief Constructs a Dot11Ack frame object from a buffer and
* adds all identifiable PDUs found in the buffer as children of
* this one.
*
* If the next PDU is not recognized, then a RawPDU is used.
*
* If there is not enough size for the header in the buffer
* or the input data is malformed, a malformed_packet exception
* is thrown.
*
* \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 Clones this PDU.
*
* \sa PDU::clone
*/
Dot11Ack *clone() const {
return new Dot11Ack(*this);
}
/**
* \brief Getter for the PDU's type.
* \sa PDU::pdu_type
*/
PDUType pdu_type() const { return pdu_flag; }
/**
* \brief Check wether this PDU matches the specified flag.
* \param flag The flag to match
* \sa PDU::matches_flag
*/
bool matches_flag(PDUType flag) const {
return flag == pdu_flag || Dot11Control::matches_flag(flag);
}
};
/**
* \brief Class that represents an 802.11 Block Ack Request PDU.
*/
class Dot11BlockAckRequest : public Dot11ControlTA {
public:
/**
* \brief This PDU's flag.
*/
static const PDU::PDUType pdu_flag = PDU::DOT11_BLOCK_ACK_REQ;
/**
* \brief Constructor for creating a 802.11 Block Ack request frame PDU
*
* Constructs a 802.11 PDU taking the destination and source
* hardware addresses.
*
* \param dst_addr The destination hardware address.
* \param target_addr The source hardware address.
*/
Dot11BlockAckRequest(const address_type &dst_addr = address_type(),
const address_type &target_addr = address_type());
/**
* \brief Constructs a Dot11BlockAckRequest object from a buffer
* and adds all identifiable PDUs found in the buffer as children
* of this one.
*
* If the next PDU is not recognized, then a RawPDU is used.
*
* If there is not enough size for the header in the buffer
* or the input data is malformed, a malformed_packet exception
* is thrown.
*
* \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 stored bar control field.
*/
small_uint<4> bar_control() const {
#if TINS_IS_LITTLE_ENDIAN
return _bar_control & 0xf;
#else
return (_bar_control >> 8) & 0xf;
#endif
}
/**
* \brief Getter for the start sequence field.
* \return The stored start sequence.
*/
small_uint<12> start_sequence() const {
#if TINS_IS_LITTLE_ENDIAN
return (_start_sequence >> 4) & 0xfff;
#else
return (Endian::le_to_host<uint16_t>(_start_sequence) >> 4) & 0xfff;
#endif
}
/**
* \brief Getter for the fragment number field.
* \return The stored fragment number field.
*/
small_uint<4> fragment_number() const {
#if TINS_IS_LITTLE_ENDIAN
return _start_sequence & 0xf;
#else
return (_start_sequence >> 8) & 0xf;
#endif
}
/**
* \brief Returns the 802.11 frame's header length.
*
* \return The header's size.
* \sa PDU::header_size()
*/
uint32_t header_size() const;
/* Setter */
/**
* \brief Setter for the bar control field.
* \param bar The bar control field to be set.
*/
void bar_control(small_uint<4> bar);
/**
* \brief Setter for the start sequence field.
* \param bar The start sequence field to be set.
*/
void start_sequence(small_uint<12> seq);
/**
* \brief Setter for the fragment number field.
* \param frag The fragment number field to be set.
*/
void fragment_number(small_uint<4> frag);
/**
* \brief Clones this PDU.
*
* \sa PDU::clone
*/
Dot11BlockAckRequest *clone() const {
return new Dot11BlockAckRequest(*this);
}
/**
* \brief Getter for the PDU's type.
* \sa PDU::pdu_type
*/
PDUType pdu_type() const { return pdu_flag; }
/**
* \brief Check wether this PDU matches the specified flag.
* \param flag The flag to match
* \sa PDU::matches_flag
*/
bool matches_flag(PDUType flag) const {
return flag == pdu_flag || Dot11Control::matches_flag(flag);
}
protected:
uint32_t write_ext_header(uint8_t *buffer, uint32_t total_sz);
private:
void init_block_ack();
uint16_t _bar_control;
uint16_t _start_sequence;
};
/**
* \brief Class that represents an 802.11 block ack frame.
*/
class Dot11BlockAck : public Dot11ControlTA {
public:
/**
* \brief This PDU's flag.
*/
static const PDU::PDUType pdu_flag = PDU::DOT11_BLOCK_ACK;
/**
* The size of the bitmap field.
*/
static const size_t bitmap_size = 8;
/**
* \brief Constructor for creating a 802.11 Block Ack frame PDU
*
* Constructs a 802.11 PDU taking the destination and source
* hardware addresses.
*
* \param dst_addr The destination hardware address.
* \param target_addr The source hardware address.
*/
Dot11BlockAck(const address_type &dst_addr = address_type(),
const address_type &target_addr = address_type());
/**
* \brief Constructs a Dot11BlockAck frame object from a buffer
* and adds all identifiable PDUs found in the buffer as children
* of this one.
*
* If the next PDU is not recognized, then a RawPDU is used.
*
* If there is not enough size for the header in the buffer
* or the input data is malformed, a malformed_packet exception
* is thrown.
*
* \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);
/* Getters */
/**
* \brief Getter for the bar control field.
* \return The stored bar control field.
*/
small_uint<4> bar_control() const {
#if TINS_IS_LITTLE_ENDIAN
return _bar_control & 0xf;
#else
return (_bar_control >> 8) & 0xf;
#endif
}
/**
* \brief Getter for the start sequence field.
* \return The stored start sequence.
*/
small_uint<12> start_sequence() const {
#if TINS_IS_LITTLE_ENDIAN
return (_start_sequence >> 4) & 0xfff;
#else
return (Endian::le_to_host<uint16_t>(_start_sequence) >> 4) & 0xfff;
#endif
}
/**
* \brief Getter for the fragment number field.
* \return The stored fragment number field.
*/
small_uint<4> fragment_number() const {
#if TINS_IS_LITTLE_ENDIAN
return _start_sequence & 0xf;
#else
return (_start_sequence >> 8) & 0xf;
#endif
}
/**
* \brief Returns the 802.11 frame's header length.
*
* \return An uint32_t with the header's size.
* \sa PDU::header_size()
*/
uint32_t header_size() const;
/* Setters */
/**
* \brief Setter for the bar control field.
* \param bar The bar control field to be set.
*/
void bar_control(small_uint<4> bar);
/**
* \brief Setter for the start sequence field.
* \param bar The start sequence field to be set.
*/
void start_sequence(small_uint<12> seq);
/**
* \brief Setter for the fragment number field.
* \param frag The fragment number field to be set.
*/
void fragment_number(small_uint<4> frag);
/**
* \brief Getter for the bitmap field.
*
* The returned pointer <b>must not</b> be free'd.
*
* \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
*/
PDUType pdu_type() const { return pdu_flag; }
/**
* \brief Check wether this PDU matches the specified flag.
* \param flag The flag to match
* \sa PDU::matches_flag
*/
bool matches_flag(PDUType flag) const {
return flag == pdu_flag || Dot11Control::matches_flag(flag);
}
/**
* \brief Clones this PDU.
*
* \sa PDU::clone
*/
Dot11BlockAck *clone() const {
return new Dot11BlockAck(*this);
}
private:
void init_block_ack();
uint32_t write_ext_header(uint8_t *buffer, uint32_t total_sz);
uint16_t _bar_control, _start_sequence;
uint8_t _bitmap[bitmap_size];
};
} // namespace Tins
#endif // TINS_DOT11_DOT11_CONTROL_H

294
include/dot11/dot11_data.h Normal file
View File

@@ -0,0 +1,294 @@
/*
* Copyright (c) 2012, Matias Fontanini
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef TINS_DOT11_DOT11_DATA_H
#define TINS_DOT11_DOT11_DATA_H
#include "../dot11/dot11_base.h"
namespace Tins {
class Dot11Data : public Dot11 {
public:
/**
* \brief This PDU's flag.
*/
static const PDU::PDUType pdu_flag = PDU::DOT11_DATA;
/**
* \brief Constructor for creating a 802.11 Data frame.
*
* Constructs a 802.11 Data frame taking the
* destination and source hardware addresses.
*
* \param dst_hw_addr The destination hardware address.
* \param src_hw_addr The source hardware address.
*/
Dot11Data(const address_type &dst_hw_addr = address_type(),
const address_type &src_hw_addr = address_type());
/**
* \brief Constructs a Dot11Data object from a buffer and adds
* all identifiable PDUs found in the buffer as children of
* this one.
*
* If the next PDU is not recognized, then a RawPDU is used.
*
* If there is not enough size for the header in the buffer
* or the input data is malformed, a malformed_packet exception
* is thrown.
*
* \param buffer The buffer from which this PDU will be constructed.
* \param total_sz The total size of the buffer.
*/
Dot11Data(const uint8_t *buffer, uint32_t total_sz);
/**
* \brief Getter for the second address.
*
* \return The stored second address.
*/
address_type addr2() const { return _ext_header.addr2; }
/**
* \brief Getter for the third address.
*
* \return The stored third address.
*/
address_type addr3() const { return _ext_header.addr3; }
/**
* \brief Getter for the fragment number field.
*
* \return The stored fragment number.
*/
small_uint<4> frag_num() const {
#if TINS_IS_LITTLE_ENDIAN
return _ext_header.frag_seq & 0xf;
#else
return (_ext_header.frag_seq >> 8) & 0xf;
#endif
}
/**
* \brief Getter for the sequence number field.
*
* \return The stored sequence number.
*/
small_uint<12> seq_num() const {
#if TINS_IS_LITTLE_ENDIAN
return (_ext_header.frag_seq >> 4) & 0xfff;
#else
return (Endian::le_to_host<uint16_t>(_ext_header.frag_seq) >> 4) & 0xfff;
#endif
}
/**
* \brief Getter for the fourth address.
*
* \return The fourth address.
*/
address_type addr4() const { return _addr4; }
/**
* \brief Setter for the second address.
*
* \param new_addr2 The second address to be set.
*/
void addr2(const address_type &new_addr2);
/**
* \brief Setter for the third address.
*
* \param new_addr3 The third address to be set.
*/
void addr3(const address_type &new_addr3);
/**
* \brief Setter for the fragment number field.
*
* \param new_frag_num The fragment number to be set.
*/
void frag_num(small_uint<4> new_frag_num);
/**
* \brief Setter for the sequence number field.
*
* \param new_seq_num The sequence number to be set.
*/
void seq_num(small_uint<12> new_seq_num);
/**
* \brief Setter for the fourth address field.
*
* \param new_addr4 The fourth address to be set.
*/
void addr4(const address_type &new_addr4);
/**
* \brief Returns the 802.11 frame's header length.
*
* \return An uint32_t with the header's size.
* \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_flag; }
/**
* \brief Check wether this PDU matches the specified flag.
* \param flag The flag to match
* \sa PDU::matches_flag
*/
bool matches_flag(PDUType flag) const {
return flag == pdu_flag || Dot11::matches_flag(flag);
}
/**
* \brief Clones this PDU.
*
* \sa PDU::clone
*/
Dot11Data *clone() const {
return new Dot11Data(*this);
}
protected:
TINS_BEGIN_PACK
struct ExtendedHeader {
uint8_t addr2[address_type::address_size];
uint8_t addr3[address_type::address_size];
uint16_t frag_seq;
} TINS_END_PACK;
struct no_inner_pdu { };
Dot11Data(const uint8_t *buffer, uint32_t total_sz, no_inner_pdu);
uint32_t init(const uint8_t *buffer, uint32_t total_sz);
uint32_t write_ext_header(uint8_t *buffer, uint32_t total_sz);
uint32_t data_frame_size() {
return sizeof(_ext_header) + ((from_ds() && to_ds()) ? sizeof(_addr4) : 0);
}
private:
ExtendedHeader _ext_header;
address_type _addr4;
};
class Dot11QoSData : public Dot11Data {
public:
/**
* \brief This PDU's flag.
*/
static const PDU::PDUType pdu_flag = PDU::DOT11_QOS_DATA;
/**
* \brief Constructor for creating a 802.11 QoS Data PDU
*
* Constructs a 802.11 QoS Data PDU taking the
* destination and source hardware addresses.
*
* \param dst_hw_addr The destination hardware address.
* \param src_hw_addr The source hardware address.
*/
Dot11QoSData(const address_type &dst_hw_addr = address_type(),
const address_type &src_hw_addr = address_type());
/**
* \brief Constructors Dot11QoSData object from a buffer and adds
* all identifiable PDUs found in the buffer as children of this
* one.
*
* If the next PDU is not recognized, then a RawPDU is used.
*
* If there is not enough size for the header in the buffer
* or the input data is malformed, a malformed_packet exception
* is thrown.
*
* \param buffer The buffer from which this PDU will be constructed.
* \param total_sz The total size of the buffer.
*/
Dot11QoSData(const uint8_t *buffer, uint32_t total_sz);
/**
* \brief Getter for the QOS Control field.
*
* \return The stored QOS Control field value.
*/
uint16_t qos_control() const { return Endian::le_to_host(_qos_control); }
/**
* \brief Setter for the QOS Control field.
*
* \param new_qos_control The QOS Control to be set.
*/
void qos_control(uint16_t new_qos_control);
/**
* \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;
/**
* \brief Clones this PDU.
*
* \sa PDU::clone
*/
Dot11QoSData *clone() const {
return new Dot11QoSData(*this);
}
/**
* \brief Getter for the PDU's type.
* \sa PDU::pdu_type
*/
PDUType pdu_type() const { return PDU::DOT11_QOS_DATA; }
/**
* \brief Check wether this PDU matches the specified flag.
* \param flag The flag to match
* \sa PDU::matches_flag
*/
bool matches_flag(PDUType flag) const {
return flag == PDU::DOT11_QOS_DATA || Dot11Data::matches_flag(flag);
}
private:
uint32_t write_fixed_parameters(uint8_t *buffer, uint32_t total_sz);
uint16_t _qos_control;
};
}
#endif // TINS_DOT11_DOT11_DATA_H

1053
include/dot11/dot11_mgmt.h Normal file

File diff suppressed because it is too large Load Diff

230
include/dot11/dot11_probe.h Normal file
View File

@@ -0,0 +1,230 @@
/*
* Copyright (c) 2012, Matias Fontanini
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#ifndef TINS_DOT11_DOT11_PROBE_H
#define TINS_DOT11_DOT11_PROBE_H
#include "../dot11/dot11_mgmt.h"
namespace Tins {
/**
* \brief Class representing an Probe Request frame in the IEEE 802.11 Protocol.
*
*/
class Dot11ProbeRequest : public Dot11ManagementFrame {
public:
/**
* \brief This PDU's flag.
*/
static const PDU::PDUType pdu_flag = PDU::DOT11_PROBE_REQ;
/**
* \brief Constructor for creating a 802.11 Probe Request.
*
* Constructs a 802.11 Probe Request taking the
* destination and source hardware address.
*
* \param dst_hw_addr The destination hardware address.
* \param src_hw_addr The source hardware address.
*/
Dot11ProbeRequest(const address_type &dst_hw_addr = address_type(),
const address_type &src_hw_addr = address_type());
/**
* \brief Constructs a Dot11ProbeRequest object from a buffer
* and adds all identifiable PDUs found in the buffer as children
* of this one.
*
* If the next PDU is not recognized, then a RawPDU is used.
*
* If there is not enough size for the header in the buffer
* or the input data is malformed, a malformed_packet exception
* is thrown.
*
* \param buffer The buffer from which this PDU will be constructed.
* \param total_sz The total size of the buffer.
*/
Dot11ProbeRequest(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_PROBE_REQ; }
/**
* \brief Check wether this PDU matches the specified flag.
* \param flag The flag to match
* \sa PDU::matches_flag
*/
bool matches_flag(PDUType flag) const {
return flag == pdu_flag || Dot11ManagementFrame::matches_flag(flag);
}
/**
* \brief Clones this PDU.
*
* \sa PDU::clone()
*/
Dot11ProbeRequest* clone() const {
return new Dot11ProbeRequest(*this);
}
};
/**
* \brief Class representing an Probe Response frame in the IEEE 802.11 Protocol.
*
*/
class Dot11ProbeResponse : public Dot11ManagementFrame {
public:
/**
* \brief This PDU's flag.
*/
static const PDU::PDUType pdu_flag = PDU::DOT11_PROBE_RESP;
/**
* \brief Constructor for creating a 802.11 Probe Response.
*
* Constructs a 802.11 Probe Response taking the
* destination and source hardware addresses.
*
* \param dst_hw_addr The destination hardware address.
* \param src_hw_addr The source hardware address.
*/
Dot11ProbeResponse(const address_type &dst_hw_addr = address_type(),
const address_type &src_hw_addr = address_type());
/**
* \brief Constructs a Dot11ProbeResponse object from a buffer
* and adds all identifiable PDUs found in the buffer as children
* of this one.
*
* If the next PDU is not recognized, then a RawPDU is used.
*
* If there is not enough size for the header in the buffer
* or the input data is malformed, a malformed_packet exception
* is thrown.
*
* \param buffer The buffer from which this PDU will be constructed.
* \param total_sz The total size of the buffer.
*/
Dot11ProbeResponse(const uint8_t *buffer, uint32_t total_sz);
/**
* \brief Getter for the timestamp field.
*
* \return The stored timestamp value.
*/
uint64_t timestamp() const { return Endian::le_to_host(_body.timestamp); }
/**
* \brief Getter for the interval field.
*
* \return The stored interval value.
*/
uint16_t interval() const { return Endian::le_to_host(_body.interval); }
/**
* \brief Getter for the Capabilities Information.
*
* \return A constant reference to the stored Capabilities
* Information field.
*/
const capability_information& capabilities() const { return _body.capability;}
/**
* \brief Getter for the Capabilities Information.
*
* \return A reference to the stored Capabilities Information
* field.
*/
capability_information& capabilities() { return _body.capability;}
/**
* \brief Setter for the timestamp field.
*
* \param new_timestamp The timestamp to be set.
*/
void timestamp(uint64_t new_timestamp);
/**
* \brief Setter for the interval field.
*
* \param new_interval The interval to be set.
*/
void interval(uint16_t new_interval);
/**
* \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;
/**
* \brief Clones this PDU.
*
* \sa PDU::clone()
*/
Dot11ProbeResponse* clone() const {
return new Dot11ProbeResponse(*this);
}
/**
* \brief Getter for the PDU's type.
* \sa PDU::pdu_type
*/
PDUType pdu_type() const { return pdu_flag; }
/**
* \brief Check wether this PDU matches the specified flag.
* \param flag The flag to match
* \sa PDU::matches_flag
*/
bool matches_flag(PDUType flag) const {
return flag == pdu_flag || Dot11ManagementFrame::matches_flag(flag);
}
protected:
private:
TINS_BEGIN_PACK
struct ProbeResp {
uint64_t timestamp;
uint16_t interval;
capability_information capability;
} TINS_END_PACK;
ProbeResp _body;
uint32_t write_fixed_parameters(uint8_t *buffer, uint32_t total_sz);
};
} // namespace Tins
#endif // TINS_DOT11_DOT11_PROBE_H

View File

@@ -41,7 +41,7 @@
#include "radiotap.h" #include "radiotap.h"
#include "packet.h" #include "packet.h"
#include "loopback.h" #include "loopback.h"
#include "dot11.h" #include "dot11/dot11_base.h"
#include "dot3.h" #include "dot3.h"
#include "sll.h" #include "sll.h"
#include "cxxstd.h" #include "cxxstd.h"

View File

@@ -32,7 +32,8 @@
#include <openssl/hmac.h> #include <openssl/hmac.h>
#include <openssl/aes.h> #include <openssl/aes.h>
#include "crypto.h" #include "crypto.h"
#include "dot11.h" #include "dot11/dot11_data.h"
#include "dot11/dot11_beacon.h"
namespace Tins { namespace Tins {
namespace Crypto { namespace Crypto {

File diff suppressed because it is too large Load Diff

249
src/dot11/dot11_assoc.cpp Normal file
View File

@@ -0,0 +1,249 @@
/*
* Copyright (c) 2012, Matias Fontanini
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <cassert>
#include <cstring>
#include "dot11/dot11_assoc.h"
namespace Tins {
/* Diassoc */
Dot11Disassoc::Dot11Disassoc(const address_type &dst_hw_addr,
const address_type &src_hw_addr)
: Dot11ManagementFrame(dst_hw_addr, src_hw_addr)
{
this->subtype(Dot11::DISASSOC);
memset(&_body, 0, sizeof(_body));
}
Dot11Disassoc::Dot11Disassoc(const uint8_t *buffer, uint32_t total_sz)
: Dot11ManagementFrame(buffer, total_sz) {
uint32_t sz = management_frame_size();
buffer += sz;
total_sz -= sz;
if(total_sz < sizeof(_body))
throw malformed_packet();
memcpy(&_body, buffer, sizeof(_body));
buffer += sizeof(_body);
total_sz -= sizeof(_body);
parse_tagged_parameters(buffer, total_sz);
}
void Dot11Disassoc::reason_code(uint16_t new_reason_code) {
this->_body.reason_code = Endian::host_to_le(new_reason_code);
}
uint32_t Dot11Disassoc::header_size() const {
return Dot11ManagementFrame::header_size() + sizeof(DisassocBody);
}
uint32_t Dot11Disassoc::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) {
uint32_t sz = sizeof(DisassocBody);
#ifdef TINS_DEBUG
assert(sz <= total_sz);
#endif
memcpy(buffer, &this->_body, sz);
return sz;
}
/* Assoc request. */
Dot11AssocRequest::Dot11AssocRequest(const address_type &dst_hw_addr,
const address_type &src_hw_addr)
: Dot11ManagementFrame(dst_hw_addr, src_hw_addr)
{
subtype(Dot11::ASSOC_REQ);
memset(&_body, 0, sizeof(_body));
}
Dot11AssocRequest::Dot11AssocRequest(const uint8_t *buffer, uint32_t total_sz)
: Dot11ManagementFrame(buffer, total_sz)
{
uint32_t sz = management_frame_size();
buffer += sz;
total_sz -= sz;
if(total_sz < sizeof(_body))
throw malformed_packet();
memcpy(&_body, buffer, sizeof(_body));
buffer += sizeof(_body);
total_sz -= sizeof(_body);
parse_tagged_parameters(buffer, total_sz);
}
void Dot11AssocRequest::listen_interval(uint16_t new_listen_interval) {
this->_body.listen_interval = Endian::host_to_le(new_listen_interval);
}
uint32_t Dot11AssocRequest::header_size() const {
return Dot11ManagementFrame::header_size() + sizeof(AssocReqBody);
}
uint32_t Dot11AssocRequest::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) {
uint32_t sz = sizeof(AssocReqBody);
#ifdef TINS_DEBUG
assert(sz <= total_sz);
#endif
memcpy(buffer, &this->_body, sz);
return sz;
}
/* Assoc response. */
Dot11AssocResponse::Dot11AssocResponse(const address_type &dst_hw_addr,
const address_type &src_hw_addr)
: Dot11ManagementFrame(dst_hw_addr, src_hw_addr)
{
subtype(Dot11::ASSOC_RESP);
memset(&_body, 0, sizeof(_body));
}
Dot11AssocResponse::Dot11AssocResponse(const uint8_t *buffer, uint32_t total_sz)
: Dot11ManagementFrame(buffer, total_sz)
{
uint32_t sz = management_frame_size();
buffer += sz;
total_sz -= sz;
if(total_sz < sizeof(_body))
throw malformed_packet();
memcpy(&_body, buffer, sizeof(_body));
buffer += sizeof(_body);
total_sz -= sizeof(_body);
parse_tagged_parameters(buffer, total_sz);
}
void Dot11AssocResponse::status_code(uint16_t new_status_code) {
this->_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);
}
uint32_t Dot11AssocResponse::header_size() const {
return Dot11ManagementFrame::header_size() + sizeof(AssocRespBody);
}
uint32_t Dot11AssocResponse::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) {
uint32_t sz = sizeof(AssocRespBody);
#ifdef TINS_DEBUG
assert(sz <= total_sz);
#endif
memcpy(buffer, &this->_body, sz);
return sz;
}
/* 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 uint8_t *buffer, uint32_t total_sz)
: Dot11ManagementFrame(buffer, total_sz)
{
uint32_t sz = management_frame_size();
buffer += sz;
total_sz -= sz;
if(total_sz < sizeof(_body))
throw malformed_packet();
memcpy(&_body, buffer, sizeof(_body));
buffer += sizeof(_body);
total_sz -= sizeof(_body);
parse_tagged_parameters(buffer, total_sz);
}
void Dot11ReAssocRequest::listen_interval(uint16_t new_listen_interval) {
this->_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);
}
uint32_t Dot11ReAssocRequest::header_size() const {
return Dot11ManagementFrame::header_size() + sizeof(this->_body);
}
uint32_t Dot11ReAssocRequest::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) {
uint32_t sz = sizeof(this->_body);
#ifdef TINS_DEBUG
assert(sz <= total_sz);
#endif
memcpy(buffer, &this->_body, sz);
return sz;
}
/* 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 uint8_t *buffer, uint32_t total_sz)
: Dot11ManagementFrame(buffer, total_sz) {
uint32_t sz = management_frame_size();
buffer += sz;
total_sz -= sz;
if(total_sz < sizeof(_body))
throw malformed_packet();
memcpy(&_body, buffer, sizeof(_body));
buffer += sizeof(_body);
total_sz -= sizeof(_body);
parse_tagged_parameters(buffer, total_sz);
}
void Dot11ReAssocResponse::status_code(uint16_t new_status_code) {
this->_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);
}
uint32_t Dot11ReAssocResponse::header_size() const {
return Dot11ManagementFrame::header_size() + sizeof(this->_body);
}
uint32_t Dot11ReAssocResponse::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) {
uint32_t sz = sizeof(this->_body);
#ifdef TINS_DEBUG
assert(sz <= total_sz);
#endif
memcpy(buffer, &this->_body, sz);
return sz;
}
} // namespace Tins

123
src/dot11/dot11_auth.cpp Normal file
View File

@@ -0,0 +1,123 @@
/*
* Copyright (c) 2012, Matias Fontanini
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <cassert>
#include <cstring>
#include "dot11/dot11_auth.h"
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));
}
Dot11Authentication::Dot11Authentication(const uint8_t *buffer, uint32_t total_sz)
: Dot11ManagementFrame(buffer, total_sz)
{
uint32_t sz = management_frame_size();
buffer += sz;
total_sz -= sz;
if(total_sz < sizeof(_body))
throw malformed_packet();
memcpy(&_body, buffer, sizeof(_body));
buffer += sizeof(_body);
total_sz -= sizeof(_body);
parse_tagged_parameters(buffer, total_sz);
}
void Dot11Authentication::auth_algorithm(uint16_t new_auth_algorithm) {
this->_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);
}
void Dot11Authentication::status_code(uint16_t new_status_code) {
this->_body.status_code = Endian::host_to_le(new_status_code);
}
uint32_t Dot11Authentication::header_size() const {
return Dot11ManagementFrame::header_size() + sizeof(_body);
}
uint32_t Dot11Authentication::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) {
uint32_t sz = sizeof(this->_body);
#ifdef TINS_DEBUG
assert(sz <= total_sz);
#endif
memcpy(buffer, &this->_body, sz);
return sz;
}
/* 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 uint8_t *buffer, uint32_t total_sz)
: Dot11ManagementFrame(buffer, total_sz) {
uint32_t sz = management_frame_size();
buffer += sz;
total_sz -= sz;
if(total_sz < sizeof(_body))
throw malformed_packet();
memcpy(&_body, buffer, sizeof(_body));
buffer += sizeof(_body);
total_sz -= sizeof(_body);
parse_tagged_parameters(buffer, total_sz);
}
void Dot11Deauthentication::reason_code(uint16_t new_reason_code) {
this->_body.reason_code = Endian::host_to_le(new_reason_code);
}
uint32_t Dot11Deauthentication::header_size() const {
return Dot11ManagementFrame::header_size() + sizeof(this->_body);
}
uint32_t Dot11Deauthentication::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) {
uint32_t sz = sizeof(this->_body);
#ifdef TINS_DEBUG
assert(sz <= total_sz);
#endif
memcpy(buffer, &this->_body, sz);
return sz;
}
} // namespace Tins

275
src/dot11/dot11_base.cpp Normal file
View File

@@ -0,0 +1,275 @@
/*
* Copyright (c) 2012, Matias Fontanini
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <cassert>
#include <cstring>
#include <stdexcept>
#include <algorithm>
#include <utility>
#include "macros.h"
#include "exceptions.h"
#include "dot11/dot11_base.h"
#ifndef WIN32
#if defined(__FreeBSD_kernel__) || defined(BSD) || defined(__APPLE__)
#include <sys/types.h>
#include <net/if_dl.h>
#else
#include <netpacket/packet.h>
#endif
#include <net/ethernet.h>
#include <netinet/in.h>
#endif
#include "dot11.h"
#include "rawpdu.h"
#include "rsn_information.h"
#include "packet_sender.h"
#include "snap.h"
namespace Tins {
const Dot11::address_type Dot11::BROADCAST = "ff:ff:ff:ff:ff:ff";
Dot11::Dot11(const address_type &dst_hw_addr)
: _options_size(0)
{
memset(&_header, 0, sizeof(ieee80211_header));
addr1(dst_hw_addr);
}
Dot11::Dot11(const ieee80211_header *header_ptr)
{
}
Dot11::Dot11(const uint8_t *buffer, uint32_t total_sz)
: _options_size(0)
{
if(total_sz < sizeof(_header))
throw malformed_packet();
std::memcpy(&_header, buffer, sizeof(_header));
}
void Dot11::parse_tagged_parameters(const uint8_t *buffer, uint32_t total_sz) {
if(total_sz > 0) {
uint8_t opcode, length;
while(total_sz >= 2) {
opcode = buffer[0];
length = buffer[1];
buffer += 2;
total_sz -= 2;
if(length > total_sz) {
throw malformed_packet();
}
add_tagged_option((OptionTypes)opcode, length, buffer);
buffer += length;
total_sz -= length;
}
}
}
void Dot11::add_tagged_option(OptionTypes opt, uint8_t len, const uint8_t *val) {
uint32_t opt_size = len + sizeof(uint8_t) * 2;
_options.push_back(option((uint8_t)opt, len, val));
_options_size += opt_size;
}
void Dot11::internal_add_option(const option &opt) {
_options_size += opt.data_size() + sizeof(uint8_t) * 2;
}
void Dot11::add_option(const option &opt) {
internal_add_option(opt);
_options.push_back(opt);
}
const Dot11::option *Dot11::search_option(OptionTypes opt) const {
for(std::list<option>::const_iterator it = _options.begin(); it != _options.end(); ++it)
if(it->option() == (uint8_t)opt)
return &(*it);
return 0;
}
void Dot11::protocol(small_uint<2> new_proto) {
this->_header.control.protocol = new_proto;
}
void Dot11::type(small_uint<2> new_type) {
this->_header.control.type = new_type;
}
void Dot11::subtype(small_uint<4> new_subtype) {
this->_header.control.subtype = new_subtype;
}
void Dot11::to_ds(small_uint<1> new_value) {
this->_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;
}
void Dot11::more_frag(small_uint<1> new_value) {
this->_header.control.more_frag = (new_value)? 1 : 0;
}
void Dot11::retry(small_uint<1> new_value) {
this->_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;
}
void Dot11::wep(small_uint<1> new_value) {
this->_header.control.wep = (new_value)? 1 : 0;
}
void Dot11::order(small_uint<1> new_value) {
this->_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);
}
void Dot11::addr1(const address_type &new_addr1) {
std::copy(new_addr1.begin(), new_addr1.end(), _header.addr1);
}
uint32_t Dot11::header_size() const {
uint32_t sz = sizeof(ieee80211_header) + _options_size;
return sz;
}
#ifndef WIN32
void Dot11::send(PacketSender &sender, const NetworkInterface &iface) {
if(!iface)
throw invalid_interface();
#if !defined(BSD) && !defined(__FreeBSD_kernel__)
sockaddr_ll addr;
memset(&addr, 0, sizeof(struct sockaddr_ll));
addr.sll_family = Endian::host_to_be<uint16_t>(PF_PACKET);
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);
sender.send_l2(*this, (struct sockaddr*)&addr, (uint32_t)sizeof(addr));
#else
sender.send_l2(*this, 0, 0, iface);
#endif
}
#endif // WIN32
void Dot11::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *parent) {
#ifdef TINS_DEBUG
assert(total_sz >= header_size());
#endif
memcpy(buffer, &_header, sizeof(_header));
buffer += sizeof(_header);
total_sz -= sizeof(_header);
uint32_t written = write_ext_header(buffer, total_sz);
buffer += written;
total_sz -= written;
uint32_t child_len = write_fixed_parameters(buffer, total_sz - _options_size);
buffer += child_len;
#ifdef TINS_DEBUG
assert(total_sz >= child_len + _options_size);
#endif
for(std::list<option>::const_iterator it = _options.begin(); it != _options.end(); ++it) {
*(buffer++) = it->option();
*(buffer++) = it->length_field();
std::copy(it->data_ptr(), it->data_ptr() + it->data_size(), buffer);
buffer += it->data_size();
}
}
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)
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);
}
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);
}
if(ret == 0)
ret = new Dot11(buffer, total_sz);
return ret;
}
} // namespace Tins

View File

@@ -0,0 +1,79 @@
/*
* Copyright (c) 2012, Matias Fontanini
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <cstring>
#include <cassert>
#include "dot11/dot11_beacon.h"
namespace Tins {
/* Dot11Beacon */
Dot11Beacon::Dot11Beacon(const address_type &dst_hw_addr,
const address_type &src_hw_addr)
: Dot11ManagementFrame(dst_hw_addr, src_hw_addr)
{
subtype(Dot11::BEACON);
std::memset(&_body, 0, sizeof(_body));
}
Dot11Beacon::Dot11Beacon(const uint8_t *buffer, uint32_t total_sz)
: Dot11ManagementFrame(buffer, total_sz)
{
uint32_t sz = management_frame_size();
buffer += sz;
total_sz -= sz;
if(total_sz < sizeof(_body))
throw malformed_packet();
std::memcpy(&_body, buffer, sizeof(_body));
buffer += sizeof(_body);
total_sz -= sizeof(_body);
parse_tagged_parameters(buffer, total_sz);
}
void Dot11Beacon::timestamp(uint64_t new_timestamp) {
this->_body.timestamp = Endian::host_to_le(new_timestamp);
}
void Dot11Beacon::interval(uint16_t new_interval) {
this->_body.interval = Endian::host_to_le(new_interval);
}
uint32_t Dot11Beacon::header_size() const {
return Dot11ManagementFrame::header_size() + sizeof(_body);
}
uint32_t Dot11Beacon::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) {
uint32_t sz = sizeof(_body);
#ifdef TINS_DEBUG
assert(sz <= total_sz);
#endif
std::memcpy(buffer, &this->_body, sz);
return sz;
}
} // namespace Tins

283
src/dot11/dot11_control.cpp Normal file
View File

@@ -0,0 +1,283 @@
/*
* Copyright (c) 2012, Matias Fontanini
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <cassert>
#include <cstring>
#include "dot11/dot11_control.h"
namespace Tins {
/* Dot11Control */
Dot11Control::Dot11Control(const address_type &dst_addr)
: Dot11(dst_addr)
{
type(CONTROL);
}
Dot11Control::Dot11Control(const uint8_t *buffer, uint32_t total_sz)
: Dot11(buffer, total_sz) {
}
/* Dot11ControlTA */
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) {
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));
_taddr = buffer;
}
uint32_t Dot11ControlTA::header_size() const {
return Dot11::header_size() + sizeof(_taddr);
}
uint32_t Dot11ControlTA::write_ext_header(uint8_t *buffer, uint32_t total_sz) {
#ifdef TINS_DEBUG
assert(total_sz >= sizeof(_taddr));
#endif
//std::memcpy(buffer, _taddr, sizeof(_taddr));
_taddr.copy(buffer);
return sizeof(_taddr);
}
void Dot11ControlTA::target_addr(const address_type &addr) {
_taddr = addr;
}
/* Dot11RTS */
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)
: Dot11ControlTA(buffer, total_sz) {
}
/* Dot11PSPoll */
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)
: Dot11ControlTA(buffer, total_sz) {
}
/* Dot11CFEnd */
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)
: Dot11ControlTA(buffer, total_sz) {
}
/* Dot11EndCFAck */
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)
: Dot11ControlTA(buffer, total_sz) {
}
/* Dot11Ack */
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)
{
}
/* Dot11BlockAck */
Dot11BlockAckRequest::Dot11BlockAckRequest(const address_type &dst_addr,
const address_type &target_addr)
: Dot11ControlTA(dst_addr, target_addr)
{
init_block_ack();
}
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 Dot11BlockAckRequest::init_block_ack() {
subtype(BLOCK_ACK_REQ);
std::memset(&_bar_control, 0, sizeof(_bar_control));
std::memset(&_start_sequence, 0, sizeof(_start_sequence));
}
uint32_t 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) + sizeof(_bar_control);
}
void Dot11BlockAckRequest::bar_control(small_uint<4> bar) {
#if TINS_IS_LITTLE_ENDIAN
_bar_control = bar | (_bar_control & 0xfff0);
#else
_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);
#else
_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);
#else
_start_sequence = (frag << 8) | (_start_sequence & 0xf0ff);
#endif
}
uint32_t Dot11BlockAckRequest::header_size() const {
return Dot11ControlTA::header_size() + sizeof(_start_sequence) + sizeof(_start_sequence);
}
/* Dot11BlockAck */
Dot11BlockAck::Dot11BlockAck(const address_type &dst_addr,
const address_type &target_addr)
: Dot11ControlTA(dst_addr, target_addr)
{
subtype(BLOCK_ACK);
std::memset(_bitmap, 0, sizeof(_bitmap));
}
Dot11BlockAck::Dot11BlockAck(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(_bitmap) + 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));
buffer += sizeof(_start_sequence);
std::memcpy(&_bitmap, buffer, sizeof(_bitmap));
}
void Dot11BlockAck::bar_control(small_uint<4> bar) {
#if TINS_IS_LITTLE_ENDIAN
_bar_control = bar | (_bar_control & 0xfff0);
#else
_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);
#else
_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);
#else
_start_sequence = (frag << 8) | (_start_sequence & 0xf0ff);
#endif
}
void Dot11BlockAck::bitmap(const uint8_t *bit) {
std::memcpy(_bitmap, bit, sizeof(_bitmap));
}
uint32_t Dot11BlockAck::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));
buffer += sizeof(_start_sequence);
std::memcpy(buffer, _bitmap, sizeof(_bitmap));
return parent_size + sizeof(_bitmap) + sizeof(_bar_control) + sizeof(_start_sequence);
}
uint32_t Dot11BlockAck::header_size() const {
return Dot11ControlTA::header_size() + sizeof(_start_sequence) + sizeof(_start_sequence) + sizeof(_bitmap);
}
} // namespace Tins

177
src/dot11/dot11_data.cpp Normal file
View File

@@ -0,0 +1,177 @@
/*
* Copyright (c) 2012, Matias Fontanini
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <cstring>
#include <cassert>
#include "dot11/dot11_data.h"
#include "rawpdu.h"
#include "snap.h"
namespace Tins {
/* Dot11Data */
Dot11Data::Dot11Data(const uint8_t *buffer, uint32_t total_sz)
: Dot11(buffer, total_sz)
{
const uint32_t offset = init(buffer, total_sz);
buffer += offset;
total_sz -= offset;
if(total_sz) {
// If the wep bit is on, then just use a RawPDU
if(wep())
inner_pdu(new Tins::RawPDU(buffer, total_sz));
else
inner_pdu(new Tins::SNAP(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) {
const uint8_t *start_ptr = buffer;
uint32_t sz = Dot11::header_size();
buffer += sz;
total_sz -= sz;
if(total_sz < sizeof(_ext_header))
throw malformed_packet();
std::memcpy(&_ext_header, buffer, sizeof(_ext_header));
buffer += sizeof(_ext_header);
total_sz -= sizeof(_ext_header);
if(from_ds() && to_ds()) {
if(total_sz < _addr4.size())
throw malformed_packet();
_addr4 = buffer;
buffer += _addr4.size();
total_sz -= _addr4.size();
}
return buffer - start_ptr;
}
Dot11Data::Dot11Data(const address_type &dst_hw_addr,
const address_type &src_hw_addr)
: Dot11(dst_hw_addr)
{
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())
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::addr3(const address_type &new_addr3) {
std::copy(new_addr3.begin(), new_addr3.end(), _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);
#else
_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);
#else
_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;
}
uint32_t Dot11Data::write_ext_header(uint8_t *buffer, uint32_t total_sz) {
uint32_t written = sizeof(_ext_header);
memcpy(buffer, &_ext_header, sizeof(_ext_header));
buffer += sizeof(_ext_header);
if (from_ds() && to_ds()) {
written += _addr4.size();
_addr4.copy(buffer);
}
return written;
}
/* QoS data. */
Dot11QoSData::Dot11QoSData(const address_type &dst_hw_addr,
const address_type &src_hw_addr)
: Dot11Data(dst_hw_addr, src_hw_addr)
{
subtype(Dot11::QOS_DATA_DATA);
_qos_control = 0;
}
Dot11QoSData::Dot11QoSData(const uint8_t *buffer, uint32_t total_sz)
// Am I breaking something? :S
: Dot11Data(buffer, total_sz, no_inner_pdu()) {
uint32_t sz = data_frame_size();
buffer += sz;
total_sz -= sz;
if(total_sz < sizeof(_qos_control))
throw malformed_packet();
_qos_control = *(uint16_t*)buffer;
total_sz -= sizeof(uint16_t);
buffer += sizeof(uint16_t);
if(total_sz)
inner_pdu(new Tins::SNAP(buffer, total_sz));
}
void Dot11QoSData::qos_control(uint16_t new_qos_control) {
this->_qos_control = Endian::host_to_le(new_qos_control);
}
uint32_t Dot11QoSData::header_size() const {
return Dot11Data::header_size() + sizeof(this->_qos_control);
}
uint32_t Dot11QoSData::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) {
uint32_t sz = sizeof(this->_qos_control);
#ifdef TINS_DEBUG
assert(sz <= total_sz);
#endif
*(uint16_t*)buffer = this->_qos_control;
return sz;
}
} // namespace Tins

601
src/dot11/dot11_mgmt.cpp Normal file
View File

@@ -0,0 +1,601 @@
/*
* Copyright (c) 2012, Matias Fontanini
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <cstring>
#include "dot11/dot11_mgmt.h"
#include "rsn_information.h"
namespace Tins {
/* Dot11ManagementFrame */
Dot11ManagementFrame::Dot11ManagementFrame(const uint8_t *buffer, uint32_t total_sz)
: Dot11(buffer, total_sz)
{
buffer += sizeof(ieee80211_header);
total_sz -= sizeof(ieee80211_header);
if(total_sz < sizeof(_ext_header))
throw malformed_packet();
std::memcpy(&_ext_header, buffer, sizeof(_ext_header));
total_sz -= sizeof(_ext_header);
if(from_ds() && to_ds()) {
if(total_sz >= _addr4.size())
_addr4 = buffer + sizeof(_ext_header);
else
throw malformed_packet();
}
}
Dot11ManagementFrame::Dot11ManagementFrame(const address_type &dst_hw_addr,
const address_type &src_hw_addr)
: Dot11(dst_hw_addr)
{
type(Dot11::MANAGEMENT);
memset(&_ext_header, 0, sizeof(_ext_header));
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())
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::addr3(const address_type &new_addr3) {
std::copy(new_addr3.begin(), new_addr3.end(), _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);
#else
_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);
#else
_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;
}
uint32_t Dot11ManagementFrame::write_ext_header(uint8_t *buffer, uint32_t total_sz) {
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;
std::copy(_addr4.begin(), _addr4.end(), buffer);
}
return written;
}
void Dot11ManagementFrame::ssid(const std::string &new_ssid) {
add_tagged_option(Dot11::SSID, new_ssid.size(), (const uint8_t*)new_ssid.c_str());
}
void Dot11ManagementFrame::rsn_information(const RSNInformation& info) {
RSNInformation::serialization_type buffer = info.serialize();
add_tagged_option(RSN, 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) {
uint8_t result = *it * 2;
if(result == 2 || result == 4 || result == 11 || result == 22)
result |= 0x80;
*(ptr++) = result;
}
return buffer;
}
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) {
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, new_rates.size(), buffer);
delete[] buffer;
}
void Dot11ManagementFrame::extended_supported_rates(const rates_type &new_rates) {
uint8_t *buffer = serialize_rates(new_rates);
add_tagged_option(EXT_SUPPORTED_RATES, new_rates.size(), buffer);
delete[] buffer;
}
void Dot11ManagementFrame::qos_capability(uint8_t new_qos_capability) {
add_tagged_option(QOS_CAPABILITY, 1, &new_qos_capability);
}
void Dot11ManagementFrame::power_capability(uint8_t min_power, uint8_t max_power) {
uint8_t buffer[2];
buffer[0] = min_power;
buffer[1] = max_power;
add_tagged_option(POWER_CAPABILITY, 2, buffer);
}
void Dot11ManagementFrame::supported_channels(const channels_type &new_channels) {
uint8_t* buffer = new uint8_t[new_channels.size() * 2];
uint8_t* ptr = buffer;
for(channels_type::const_iterator it = new_channels.begin(); it != new_channels.end(); ++it) {
*(ptr++) = it->first;
*(ptr++) = it->second;
}
add_tagged_option(SUPPORTED_CHANNELS, new_channels.size() * 2, buffer);
delete[] buffer;
}
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);
add_tagged_option(EDCA, sizeof(buffer), buffer);
}
void Dot11ManagementFrame::request_information(const request_info_type elements) {
uint8_t *buffer = new uint8_t[elements.size()], *ptr = buffer;
for (request_info_type::const_iterator it = elements.begin(); it != elements.end(); ++it)
*(ptr++) = *it;
add_tagged_option(REQUEST_INFORMATION, elements.size(), buffer);
delete[] buffer;
}
void Dot11ManagementFrame::fh_parameter_set(fh_params_set fh_params) {
fh_params.dwell_time = Endian::host_to_le(fh_params.dwell_time);
fh_params.hop_set = fh_params.hop_set;
fh_params.hop_pattern = fh_params.hop_pattern;
fh_params.hop_index = fh_params.hop_index;
add_tagged_option(FH_SET, sizeof(fh_params_set), (uint8_t*)&fh_params);
}
void Dot11ManagementFrame::ds_parameter_set(uint8_t current_channel) {
add_tagged_option(DS_SET, 1, &current_channel);
}
void Dot11ManagementFrame::cf_parameter_set(cf_params_set params) {
params.cfp_count = params.cfp_count;
params.cfp_period = params.cfp_period;
params.cfp_max_duration = Endian::host_to_le(params.cfp_max_duration);
params.cfp_dur_remaining = Endian::host_to_le(params.cfp_dur_remaining);
add_tagged_option(CF_SET, sizeof(params), (uint8_t*)&params);
}
void Dot11ManagementFrame::ibss_parameter_set(uint16_t atim_window) {
atim_window = Endian::host_to_le(atim_window);
add_tagged_option(IBSS_SET, 2, (uint8_t*)&atim_window);
}
void Dot11ManagementFrame::ibss_dfs(const ibss_dfs_params &params) {
uint8_t sz = address_type::address_size + sizeof(uint8_t) + sizeof(uint8_t) * 2 * params.channel_map.size();
uint8_t* buffer = new uint8_t[sz];
uint8_t* ptr_buffer = buffer;
ptr_buffer = params.dfs_owner.copy(ptr_buffer);
*(ptr_buffer++) = 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;
}
add_tagged_option(IBSS_DFS, sz, buffer);
delete[] buffer;
}
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");
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)
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) {
*(ptr++) = params.first_channel[i];
*(ptr++) = params.number_channels[i];
*(ptr++) = params.max_transmit_power[i];
}
add_tagged_option(COUNTRY, sz, &buffer[0]);
}
void Dot11ManagementFrame::fh_parameters(uint8_t prime_radix, uint8_t number_channels) {
uint8_t buffer[2];
buffer[0] = prime_radix;
buffer[1] = number_channels;
add_tagged_option(HOPPING_PATTERN_PARAMS, 2, buffer);
}
void Dot11ManagementFrame::fh_pattern_table(const fh_pattern_type &params) {
std::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;
fh_pattern_type::container_type::const_iterator it(params.random_table.begin());
for(; it != params.random_table.end(); ++it)
*(ptr++) = *it;
add_tagged_option(HOPPING_PATTERN_TABLE, data.size(), &data[0]);
}
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) {
uint8_t buffer[3];
buffer[0] = data.switch_mode;
buffer[1] = data.new_channel;
buffer[2] = data.switch_count;
add_tagged_option(CHANNEL_SWITCH, 3, buffer);
}
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);
add_tagged_option(QUIET, sizeof(buffer), buffer);
}
void Dot11ManagementFrame::tpc_report(uint8_t transmit_power, uint8_t link_margin) {
uint8_t buffer[2];
buffer[0] = transmit_power;
buffer[1] = link_margin;
add_tagged_option(TPC_REPORT, 2, buffer);
}
void Dot11ManagementFrame::erp_information(uint8_t value) {
add_tagged_option(ERP_INFORMATION, 1, &value);
}
void Dot11ManagementFrame::bss_load(const bss_load_type &data) {
uint8_t buffer[5];
uint16_t dummy = Endian::host_to_le(data.station_count);
//*(uint16_t*)buffer = Endian::host_to_le(data.station_count);
#if TINS_IS_LITTLE_ENDIAN
buffer[0] = dummy & 0xff;
buffer[1] = (dummy >> 8) & 0xff;
#else
buffer[0] = (dummy >> 8) & 0xff;
buffer[1] = dummy & 0xff;
#endif
buffer[2] = data.channel_utilization;
dummy = Endian::host_to_le(data.available_capacity);
#if TINS_IS_LITTLE_ENDIAN
buffer[3] = dummy & 0xff;
buffer[4] = (dummy >> 8) & 0xff;
#else
buffer[3] = (dummy >> 8) & 0xff;
buffer[4] = dummy & 0xff;
#endif
//*(uint16_t*)(buffer + 3) = Endian::host_to_le(data.available_capacity);
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(
data.partial_virtual_bitmap.begin(),
data.partial_virtual_bitmap.end(),
&buffer[3]
);
add_tagged_option(TIM, buffer.size(), &buffer[0]);
}
void Dot11ManagementFrame::challenge_text(const std::string &text) {
add_tagged_option(
CHALLENGE_TEXT,
text.size(),
(const uint8_t*)text.c_str()
);
}
// Getters
RSNInformation Dot11ManagementFrame::rsn_information() {
const Dot11::option *option = search_option(RSN);
if(!option || option->data_size() < (sizeof(uint16_t) << 1) + sizeof(uint32_t))
throw option_not_found();
return RSNInformation(option->data_ptr(), option->data_size());
}
std::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)
return "BROADCAST";
else
return std::string((const char*)option->data_ptr(), option->data_size());
}
Dot11ManagementFrame::rates_type Dot11ManagementFrame::supported_rates() const {
const Dot11::option *option = search_option(SUPPORTED_RATES);
if(!option || option->data_size() == 0)
throw option_not_found();
return deserialize_rates(option);
}
Dot11ManagementFrame::rates_type Dot11ManagementFrame::extended_supported_rates() const {
const Dot11::option *option = search_option(EXT_SUPPORTED_RATES);
if(!option || option->data_size() == 0)
throw option_not_found();
return deserialize_rates(option);
}
uint8_t Dot11ManagementFrame::qos_capability() const {
const Dot11::option *option = search_option(QOS_CAPABILITY);
if(!option || option->data_size() != 1)
throw option_not_found();
return *option->data_ptr();
}
std::pair<uint8_t, uint8_t> Dot11ManagementFrame::power_capability() const {
const Dot11::option *option = search_option(POWER_CAPABILITY);
if(!option || option->data_size() != 2)
throw option_not_found();
return std::make_pair(*option->data_ptr(), *(option->data_ptr() + 1));
}
Dot11ManagementFrame::channels_type Dot11ManagementFrame::supported_channels() const {
const Dot11::option *option = search_option(SUPPORTED_CHANNELS);
// We need a multiple of two
if(!option || ((option->data_size() & 0x1) == 1))
throw option_not_found();
channels_type output;
const uint8_t *ptr = option->data_ptr(), *end = ptr + option->data_size();
while(ptr != end) {
uint8_t first = *(ptr++);
output.push_back(std::make_pair(first, *(ptr++)));
}
return output;
}
Dot11ManagementFrame::request_info_type Dot11ManagementFrame::request_information() const {
const Dot11::option *option = search_option(REQUEST_INFORMATION);
if(!option || option->data_size() == 0)
throw option_not_found();
request_info_type output;
const uint8_t *ptr = option->data_ptr(), *end = ptr + option->data_size();
output.assign(ptr, end);
return output;
}
Dot11ManagementFrame::fh_params_set Dot11ManagementFrame::fh_parameter_set() const {
const Dot11::option *option = search_option(FH_SET);
if(!option || option->data_size() != sizeof(fh_params_set))
throw option_not_found();
fh_params_set output = *reinterpret_cast<const fh_params_set*>(option->data_ptr());
output.dwell_time = Endian::le_to_host(output.dwell_time);
output.hop_set = output.hop_set;
output.hop_pattern = output.hop_pattern;
output.hop_index = output.hop_index;
return output;
}
uint8_t Dot11ManagementFrame::ds_parameter_set() const {
const Dot11::option *option = search_option(DS_SET);
if(!option || option->data_size() != sizeof(uint8_t))
throw option_not_found();
return *option->data_ptr();
}
uint16_t Dot11ManagementFrame::ibss_parameter_set() const {
const Dot11::option *option = search_option(IBSS_SET);
if(!option || option->data_size() != sizeof(uint16_t))
throw option_not_found();
return Endian::le_to_host(*reinterpret_cast<const uint16_t*>(option->data_ptr()));
}
Dot11ManagementFrame::ibss_dfs_params Dot11ManagementFrame::ibss_dfs() const {
const Dot11::option *option = search_option(IBSS_DFS);
if(!option || option->data_size() < ibss_dfs_params::minimum_size)
throw option_not_found();
ibss_dfs_params output;
const uint8_t *ptr = option->data_ptr(), *end = ptr + option->data_size();
output.dfs_owner = ptr;
ptr += output.dfs_owner.size();
output.recovery_interval = *(ptr++);
while(ptr != end) {
uint8_t first = *(ptr++);
if(ptr == end)
throw option_not_found();
output.channel_map.push_back(std::make_pair(first, *(ptr++)));
}
return output;
}
Dot11ManagementFrame::country_params Dot11ManagementFrame::country() const {
const Dot11::option *option = search_option(COUNTRY);
if(!option || option->data_size() < country_params::minimum_size)
throw option_not_found();
country_params output;
const uint8_t *ptr = option->data_ptr(), *end = ptr + option->data_size();
std::copy(ptr, ptr + 3, std::back_inserter(output.country));
ptr += output.country.size();
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)
throw option_not_found();
return output;
}
std::pair<uint8_t, uint8_t> Dot11ManagementFrame::fh_parameters() const {
const Dot11::option *option = search_option(HOPPING_PATTERN_PARAMS);
if(!option || option->data_size() != sizeof(uint8_t) * 2)
throw option_not_found();
const uint8_t *ptr = option->data_ptr();
uint8_t first = *(ptr++);
return std::make_pair(first, *ptr);
}
Dot11ManagementFrame::fh_pattern_type Dot11ManagementFrame::fh_pattern_table() const {
const Dot11::option *option = search_option(HOPPING_PATTERN_TABLE);
if(!option || option->data_size() < fh_pattern_type::minimum_size)
throw option_not_found();
fh_pattern_type output;
const uint8_t *ptr = option->data_ptr(), *end = ptr + option->data_size();
output.flag = *(ptr++);
output.number_of_sets = *(ptr++);
output.modulus = *(ptr++);
output.offset = *(ptr++);
output.random_table.assign(ptr, end);
return output;
}
uint8_t Dot11ManagementFrame::power_constraint() const {
const Dot11::option *option = search_option(POWER_CONSTRAINT);
if(!option || option->data_size() != 1)
throw option_not_found();
return *option->data_ptr();
}
Dot11ManagementFrame::channel_switch_type Dot11ManagementFrame::channel_switch() const {
const Dot11::option *option = search_option(CHANNEL_SWITCH);
if(!option || option->data_size() != sizeof(uint8_t) * 3)
throw option_not_found();
const uint8_t *ptr = option->data_ptr();
channel_switch_type output;
output.switch_mode = *(ptr++);
output.new_channel = *(ptr++);
output.switch_count = *(ptr++);
return output;
}
Dot11ManagementFrame::quiet_type Dot11ManagementFrame::quiet() const {
const Dot11::option *option = search_option(QUIET);
if(!option || option->data_size() != (sizeof(uint8_t) * 2 + sizeof(uint16_t) * 2))
throw option_not_found();
const uint8_t *ptr = option->data_ptr();
quiet_type output;
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);
return output;
}
std::pair<uint8_t, uint8_t> Dot11ManagementFrame::tpc_report() const {
const Dot11::option *option = search_option(TPC_REPORT);
if(!option || option->data_size() != sizeof(uint8_t) * 2)
throw option_not_found();
const uint8_t *ptr = option->data_ptr();
uint8_t first = *(ptr++);
return std::make_pair(first, *ptr);
}
uint8_t Dot11ManagementFrame::erp_information() const {
const Dot11::option *option = search_option(ERP_INFORMATION);
if(!option || option->data_size() != sizeof(uint8_t))
throw option_not_found();
return *option->data_ptr();
}
Dot11ManagementFrame::bss_load_type Dot11ManagementFrame::bss_load() const {
const Dot11::option *option = search_option(BSS_LOAD);
if(!option || option->data_size() != sizeof(uint8_t) + 2 * sizeof(uint16_t))
throw option_not_found();
bss_load_type output;
const uint8_t *ptr = option->data_ptr();
output.station_count = Endian::le_to_host(*(uint16_t*)ptr);
output.channel_utilization = ptr[2];
output.available_capacity = Endian::le_to_host(*(uint16_t*)(ptr + 3));
return output;
}
Dot11ManagementFrame::tim_type Dot11ManagementFrame::tim() const {
const Dot11::option *option = search_option(TIM);
if(!option || option->data_size() < 4 * sizeof(uint8_t))
throw option_not_found();
const uint8_t *ptr = option->data_ptr(), *end = ptr + option->data_size();
tim_type output;
output.dtim_count = *(ptr++);
output.dtim_period = *(ptr++);
output.bitmap_control = *(ptr++);
output.partial_virtual_bitmap.assign(ptr, end);
return output;
}
std::string Dot11ManagementFrame::challenge_text() const {
const Dot11::option *option = search_option(CHALLENGE_TEXT);
if(!option || option->data_size() == 0)
throw option_not_found();
return std::string(option->data_ptr(), option->data_ptr() + option->data_size());
}
} // namespace Tins

97
src/dot11/dot11_probe.cpp Normal file
View File

@@ -0,0 +1,97 @@
/*
* Copyright (c) 2012, Matias Fontanini
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <cstring>
#include <cassert>
#include "dot11/dot11_probe.h"
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);
}
Dot11ProbeRequest::Dot11ProbeRequest(const uint8_t *buffer, uint32_t total_sz)
: Dot11ManagementFrame(buffer, total_sz)
{
uint32_t sz = management_frame_size();
buffer += sz;
total_sz -= sz;
parse_tagged_parameters(buffer, total_sz);
}
/* Probe Response */
Dot11ProbeResponse::Dot11ProbeResponse(const address_type &dst_hw_addr,
const address_type &src_hw_addr)
: Dot11ManagementFrame(dst_hw_addr, src_hw_addr)
{
this->subtype(Dot11::PROBE_RESP);
memset(&_body, 0, sizeof(_body));
}
Dot11ProbeResponse::Dot11ProbeResponse(const uint8_t *buffer, uint32_t total_sz)
: Dot11ManagementFrame(buffer, total_sz)
{
uint32_t sz = management_frame_size();
buffer += sz;
total_sz -= sz;
if(total_sz < sizeof(_body))
throw malformed_packet();
memcpy(&_body, buffer, sizeof(_body));
buffer += sizeof(_body);
total_sz -= sizeof(_body);
parse_tagged_parameters(buffer, total_sz);
}
void Dot11ProbeResponse::timestamp(uint64_t new_timestamp) {
this->_body.timestamp = Endian::host_to_le(new_timestamp);
}
void Dot11ProbeResponse::interval(uint16_t new_interval) {
this->_body.interval = Endian::host_to_le(new_interval);
}
uint32_t Dot11ProbeResponse::header_size() const {
return Dot11ManagementFrame::header_size() + sizeof(this->_body);
}
uint32_t Dot11ProbeResponse::write_fixed_parameters(uint8_t *buffer, uint32_t total_sz) {
uint32_t sz = sizeof(this->_body);
#ifdef TINS_DEBUG
assert(sz <= total_sz);
#endif
memcpy(buffer, &this->_body, sz);
return sz;
}
} // namespace Tins

View File

@@ -33,7 +33,6 @@
#endif #endif
#include <stdexcept> #include <stdexcept>
#include "eapol.h" #include "eapol.h"
#include "dot11.h"
#include "rsn_information.h" #include "rsn_information.h"
#include "exceptions.h" #include "exceptions.h"

View File

@@ -28,7 +28,7 @@
*/ */
#include "handshake_capturer.h" #include "handshake_capturer.h"
#include "dot11.h" #include "dot11/dot11_data.h"
namespace Tins { namespace Tins {
bool RSNHandshakeCapturer::process_packet(const PDU &pdu) { bool RSNHandshakeCapturer::process_packet(const PDU &pdu) {

View File

@@ -32,7 +32,7 @@
#include "ethernetII.h" #include "ethernetII.h"
#include "ieee802_3.h" #include "ieee802_3.h"
#include "radiotap.h" #include "radiotap.h"
#include "dot11.h" #include "dot11/dot11_base.h"
#include "ipv6.h" #include "ipv6.h"
#include "arp.h" #include "arp.h"
#include "eapol.h" #include "eapol.h"

View File

@@ -61,7 +61,7 @@
// PDUs required by PacketSender::send(PDU&, NetworkInterface) // PDUs required by PacketSender::send(PDU&, NetworkInterface)
#include "ethernetII.h" #include "ethernetII.h"
#include "radiotap.h" #include "radiotap.h"
#include "dot11.h" #include "dot11/dot11_base.h"
#include "radiotap.h" #include "radiotap.h"
#include "ieee802_3.h" #include "ieee802_3.h"
#include "internals.h" #include "internals.h"

View File

@@ -42,7 +42,7 @@
#include <net/ethernet.h> #include <net/ethernet.h>
#endif #endif
#include "radiotap.h" #include "radiotap.h"
#include "dot11.h" #include "dot11/dot11_base.h"
#include "utils.h" #include "utils.h"
#include "packet_sender.h" #include "packet_sender.h"
#include "exceptions.h" #include "exceptions.h"

2
tests/configure vendored
View File

@@ -2542,7 +2542,7 @@ if test "${enable_c__11+set}" = set; then :
fi fi
SOURCE_FILES=$(ls ../src/*cpp src/*cpp src/dot11/*cpp | tr '\n' ' ') SOURCE_FILES=$(ls ../src/*cpp ../src/dot11/*cpp src/*cpp src/dot11/*cpp | tr '\n' ' ')
ac_ext=cpp ac_ext=cpp

View File

@@ -11,7 +11,7 @@ AC_ARG_ENABLE(
[CFLAGS="$CFLAGS -std=c++0x"] [CFLAGS="$CFLAGS -std=c++0x"]
) )
SOURCE_FILES=$(ls ../src/*cpp src/*cpp src/dot11/*cpp | tr '\n' ' ') SOURCE_FILES=$(ls ../src/*cpp ../src/dot11/*cpp src/*cpp src/dot11/*cpp | tr '\n' ' ')
AC_CHECK_HEADERS([pcap.h gtest/gtest.h]) AC_CHECK_HEADERS([pcap.h gtest/gtest.h])
AC_CHECK_LIB(pcap, pcap_loop, [], [AC_MSG_ERROR([pcap library is needed!])]) AC_CHECK_LIB(pcap, pcap_loop, [], [AC_MSG_ERROR([pcap library is needed!])])

File diff suppressed because it is too large Load Diff

View File

@@ -1,15 +1,11 @@
#ifndef TINS_DOT11_TEST #ifndef TINS_DOT11_TEST
#define TINS_DOT11_TEST #define TINS_DOT11_TEST
#include "dot11.h" #include "dot11/dot11_base.h"
using Tins::Dot11; using Tins::Dot11;
using Tins::Dot11ManagementFrame;
using Tins::Dot11Data;
using Tins::Dot11ControlTA;
typedef Dot11::address_type address_type; typedef Dot11::address_type address_type;
typedef Dot11ManagementFrame::capability_information capability_information;
inline void test_equals(const Dot11 &dot1, const Dot11 &dot2) { inline void test_equals(const Dot11 &dot1, const Dot11 &dot2) {
EXPECT_EQ(dot1.protocol(), dot2.protocol()); EXPECT_EQ(dot1.protocol(), dot2.protocol());
@@ -26,80 +22,6 @@ inline void test_equals(const Dot11 &dot1, const Dot11 &dot2) {
EXPECT_EQ(dot1.addr1(), dot2.addr1()); EXPECT_EQ(dot1.addr1(), dot2.addr1());
} }
inline void test_equals(const Dot11ManagementFrame& b1, const Dot11ManagementFrame& b2) {
EXPECT_EQ(b1.addr2(), b2.addr2());
EXPECT_EQ(b1.addr3(), b2.addr3());
EXPECT_EQ(b1.addr4(), b2.addr4());
EXPECT_EQ(b1.frag_num(), b2.frag_num());
EXPECT_EQ(b1.seq_num(), b2.seq_num());
test_equals(static_cast<const Dot11&>(b1), static_cast<const Dot11&>(b2));
}
inline void test_equals(const Dot11Data& b1, const Dot11Data& b2) {
EXPECT_EQ(b1.addr2(), b2.addr2());
EXPECT_EQ(b1.addr3(), b2.addr3());
EXPECT_EQ(b1.addr4(), b2.addr4());
EXPECT_EQ(b1.frag_num(), b2.frag_num());
EXPECT_EQ(b1.seq_num(), b2.seq_num());
test_equals(static_cast<const Dot11&>(b1), static_cast<const Dot11&>(b2));
}
inline void test_equals(const Dot11ControlTA& b1, const Dot11ControlTA& b2) {
EXPECT_EQ(b1.target_addr(), b2.target_addr());
test_equals(static_cast<const Dot11&>(b1), static_cast<const Dot11&>(b2));
}
inline void test_equals(const capability_information &info1, const capability_information &info2) {
EXPECT_EQ(info1.ess(), info2.ess());
EXPECT_EQ(info1.ibss(), info2.ibss());
EXPECT_EQ(info1.cf_poll(), info2.cf_poll());
EXPECT_EQ(info1.cf_poll_req(), info2.cf_poll_req());
EXPECT_EQ(info1.privacy(), info2.privacy());
EXPECT_EQ(info1.short_preamble(), info2.short_preamble());
EXPECT_EQ(info1.pbcc(), info2.pbcc());
EXPECT_EQ(info1.channel_agility(), info2.channel_agility());
EXPECT_EQ(info1.spectrum_mgmt(), info2.spectrum_mgmt());
EXPECT_EQ(info1.qos(), info2.qos());
EXPECT_EQ(info1.sst(), info2.sst());
EXPECT_EQ(info1.apsd(), info2.apsd());
EXPECT_EQ(info1.reserved(), info2.reserved());
EXPECT_EQ(info1.dsss_ofdm(), info2.dsss_ofdm());
EXPECT_EQ(info1.delayed_block_ack(), info2.delayed_block_ack());
EXPECT_EQ(info1.immediate_block_ack(), info2.immediate_block_ack());
}
inline void test_equals_expected(const Dot11ManagementFrame &dot11) {
EXPECT_EQ(dot11.protocol(), 1);
EXPECT_EQ(dot11.type(), Dot11::MANAGEMENT);
EXPECT_EQ(dot11.to_ds(), 1);
EXPECT_EQ(dot11.from_ds(), 0);
EXPECT_EQ(dot11.more_frag(), 0);
EXPECT_EQ(dot11.retry(), 0);
EXPECT_EQ(dot11.power_mgmt(), 0);
EXPECT_EQ(dot11.wep(), 0);
EXPECT_EQ(dot11.order(), 0);
EXPECT_EQ(dot11.duration_id(), 0x234f);
EXPECT_EQ(dot11.addr1(), "00:01:02:03:04:05");
EXPECT_EQ(dot11.addr2(), "01:02:03:04:05:06");
EXPECT_EQ(dot11.addr3(), "02:03:04:05:06:07");
}
inline void test_equals_expected(const Dot11Data &dot11) {
EXPECT_EQ(dot11.type(), Dot11::DATA);
EXPECT_EQ(dot11.addr1(), "00:01:02:03:04:05");
EXPECT_EQ(dot11.addr2(), "01:02:03:04:05:06");
EXPECT_EQ(dot11.addr3(), "02:03:04:05:06:07");
EXPECT_EQ(dot11.frag_num(), 0xa);
EXPECT_EQ(dot11.seq_num(), 0xf1d);
}
inline void test_equals_expected(const Dot11ControlTA &dot11) {
EXPECT_EQ(dot11.target_addr(), "01:02:03:04:05:06");
EXPECT_EQ(dot11.addr1(), "00:01:02:03:04:05");
}
inline void test_equals_empty(const Dot11 &dot11) { inline void test_equals_empty(const Dot11 &dot11) {
Dot11::address_type empty_addr; Dot11::address_type empty_addr;
@@ -115,54 +37,5 @@ inline void test_equals_empty(const Dot11 &dot11) {
EXPECT_EQ(dot11.addr1(), empty_addr); EXPECT_EQ(dot11.addr1(), empty_addr);
} }
inline void test_equals_empty(const Dot11ManagementFrame &dot11) {
Dot11::address_type empty_addr;
EXPECT_EQ(dot11.type(), Dot11::MANAGEMENT);
EXPECT_EQ(dot11.addr2(), empty_addr);
EXPECT_EQ(dot11.addr3(), empty_addr);
EXPECT_EQ(dot11.addr4(), empty_addr);
EXPECT_EQ(dot11.frag_num(), 0);
EXPECT_EQ(dot11.seq_num(), 0);
test_equals_empty(static_cast<const Dot11 &>(dot11));
}
inline void test_equals_empty(const Dot11Data &dot11) {
Dot11::address_type empty_addr;
EXPECT_EQ(dot11.addr1(), empty_addr);
EXPECT_EQ(dot11.addr2(), empty_addr);
EXPECT_EQ(dot11.addr3(), empty_addr);
EXPECT_EQ(dot11.frag_num(), 0);
EXPECT_EQ(dot11.seq_num(), 0);
}
inline void test_equals_empty(const Dot11ControlTA &dot11) {
Dot11::address_type empty_addr;
EXPECT_EQ(dot11.target_addr(), empty_addr);
EXPECT_EQ(dot11.addr1(), empty_addr);
}
inline void test_equals_empty(const capability_information &info) {
EXPECT_EQ(info.ess(), 0);
EXPECT_EQ(info.ibss(), 0);
EXPECT_EQ(info.cf_poll(), 0);
EXPECT_EQ(info.cf_poll_req(), 0);
EXPECT_EQ(info.privacy(), 0);
EXPECT_EQ(info.short_preamble(), 0);
EXPECT_EQ(info.pbcc(), 0);
EXPECT_EQ(info.channel_agility(), 0);
EXPECT_EQ(info.spectrum_mgmt(), 0);
EXPECT_EQ(info.qos(), 0);
EXPECT_EQ(info.sst(), 0);
EXPECT_EQ(info.apsd(), 0);
EXPECT_EQ(info.reserved(), 0);
EXPECT_EQ(info.dsss_ofdm(), 0);
EXPECT_EQ(info.delayed_block_ack(), 0);
EXPECT_EQ(info.immediate_block_ack(), 0);
}
#endif // TINS_DOT11_TEST #endif // TINS_DOT11_TEST

View File

@@ -0,0 +1,27 @@
#ifndef TINS_TEST_DOT11_CONTROL_H
#define TINS_TEST_DOT11_CONTROL_H
#include "tests/dot11.h"
#include "dot11/dot11_control.h"
using Tins::Dot11ControlTA;
inline void test_equals(const Dot11ControlTA& b1, const Dot11ControlTA& b2) {
EXPECT_EQ(b1.target_addr(), b2.target_addr());
test_equals(static_cast<const Dot11&>(b1), static_cast<const Dot11&>(b2));
}
inline void test_equals_expected(const Dot11ControlTA &dot11) {
EXPECT_EQ(dot11.target_addr(), "01:02:03:04:05:06");
EXPECT_EQ(dot11.addr1(), "00:01:02:03:04:05");
}
inline void test_equals_empty(const Dot11ControlTA &dot11) {
Dot11::address_type empty_addr;
EXPECT_EQ(dot11.target_addr(), empty_addr);
EXPECT_EQ(dot11.addr1(), empty_addr);
}
#endif // TINS_TEST_DOT11_CONTROL_H

View File

@@ -0,0 +1,38 @@
#ifndef TINS_TEST_DOT11_DATA_H
#define TINS_TEST_DOT11_DATA_H
#include "tests/dot11.h"
#include "dot11/dot11_data.h"
using Tins::Dot11Data;
inline void test_equals(const Dot11Data& b1, const Dot11Data& b2) {
EXPECT_EQ(b1.addr2(), b2.addr2());
EXPECT_EQ(b1.addr3(), b2.addr3());
EXPECT_EQ(b1.addr4(), b2.addr4());
EXPECT_EQ(b1.frag_num(), b2.frag_num());
EXPECT_EQ(b1.seq_num(), b2.seq_num());
test_equals(static_cast<const Dot11&>(b1), static_cast<const Dot11&>(b2));
}
inline void test_equals_expected(const Dot11Data &dot11) {
EXPECT_EQ(dot11.type(), Dot11::DATA);
EXPECT_EQ(dot11.addr1(), "00:01:02:03:04:05");
EXPECT_EQ(dot11.addr2(), "01:02:03:04:05:06");
EXPECT_EQ(dot11.addr3(), "02:03:04:05:06:07");
EXPECT_EQ(dot11.frag_num(), 0xa);
EXPECT_EQ(dot11.seq_num(), 0xf1d);
}
inline void test_equals_empty(const Dot11Data &dot11) {
Dot11::address_type empty_addr;
EXPECT_EQ(dot11.addr1(), empty_addr);
EXPECT_EQ(dot11.addr2(), empty_addr);
EXPECT_EQ(dot11.addr3(), empty_addr);
EXPECT_EQ(dot11.frag_num(), 0);
EXPECT_EQ(dot11.seq_num(), 0);
}
#endif // TINS_TEST_DOT11_DATA_H

View File

@@ -0,0 +1,89 @@
#ifndef TINS_DOT11_MGMT_TEST_H
#define TINS_DOT11_MGMT_TEST_H
#include "tests/dot11.h"
#include "dot11/dot11_mgmt.h"
using Tins::Dot11ManagementFrame;
typedef Dot11ManagementFrame::capability_information capability_information;
inline void test_equals(const Dot11ManagementFrame& b1, const Dot11ManagementFrame& b2) {
EXPECT_EQ(b1.addr2(), b2.addr2());
EXPECT_EQ(b1.addr3(), b2.addr3());
EXPECT_EQ(b1.addr4(), b2.addr4());
EXPECT_EQ(b1.frag_num(), b2.frag_num());
EXPECT_EQ(b1.seq_num(), b2.seq_num());
test_equals(static_cast<const Dot11&>(b1), static_cast<const Dot11&>(b2));
}
inline void test_equals_expected(const Dot11ManagementFrame &dot11) {
EXPECT_EQ(dot11.protocol(), 1);
EXPECT_EQ(dot11.type(), Dot11::MANAGEMENT);
EXPECT_EQ(dot11.to_ds(), 1);
EXPECT_EQ(dot11.from_ds(), 0);
EXPECT_EQ(dot11.more_frag(), 0);
EXPECT_EQ(dot11.retry(), 0);
EXPECT_EQ(dot11.power_mgmt(), 0);
EXPECT_EQ(dot11.wep(), 0);
EXPECT_EQ(dot11.order(), 0);
EXPECT_EQ(dot11.duration_id(), 0x234f);
EXPECT_EQ(dot11.addr1(), "00:01:02:03:04:05");
EXPECT_EQ(dot11.addr2(), "01:02:03:04:05:06");
EXPECT_EQ(dot11.addr3(), "02:03:04:05:06:07");
}
inline void test_equals_empty(const Dot11ManagementFrame &dot11) {
Dot11::address_type empty_addr;
EXPECT_EQ(dot11.type(), Dot11::MANAGEMENT);
EXPECT_EQ(dot11.addr2(), empty_addr);
EXPECT_EQ(dot11.addr3(), empty_addr);
EXPECT_EQ(dot11.addr4(), empty_addr);
EXPECT_EQ(dot11.frag_num(), 0);
EXPECT_EQ(dot11.seq_num(), 0);
test_equals_empty(static_cast<const Dot11 &>(dot11));
}
inline void test_equals(const capability_information &info1, const capability_information &info2) {
EXPECT_EQ(info1.ess(), info2.ess());
EXPECT_EQ(info1.ibss(), info2.ibss());
EXPECT_EQ(info1.cf_poll(), info2.cf_poll());
EXPECT_EQ(info1.cf_poll_req(), info2.cf_poll_req());
EXPECT_EQ(info1.privacy(), info2.privacy());
EXPECT_EQ(info1.short_preamble(), info2.short_preamble());
EXPECT_EQ(info1.pbcc(), info2.pbcc());
EXPECT_EQ(info1.channel_agility(), info2.channel_agility());
EXPECT_EQ(info1.spectrum_mgmt(), info2.spectrum_mgmt());
EXPECT_EQ(info1.qos(), info2.qos());
EXPECT_EQ(info1.sst(), info2.sst());
EXPECT_EQ(info1.apsd(), info2.apsd());
EXPECT_EQ(info1.reserved(), info2.reserved());
EXPECT_EQ(info1.dsss_ofdm(), info2.dsss_ofdm());
EXPECT_EQ(info1.delayed_block_ack(), info2.delayed_block_ack());
EXPECT_EQ(info1.immediate_block_ack(), info2.immediate_block_ack());
}
inline void test_equals_empty(const capability_information &info) {
EXPECT_EQ(info.ess(), 0);
EXPECT_EQ(info.ibss(), 0);
EXPECT_EQ(info.cf_poll(), 0);
EXPECT_EQ(info.cf_poll_req(), 0);
EXPECT_EQ(info.privacy(), 0);
EXPECT_EQ(info.short_preamble(), 0);
EXPECT_EQ(info.pbcc(), 0);
EXPECT_EQ(info.channel_agility(), 0);
EXPECT_EQ(info.spectrum_mgmt(), 0);
EXPECT_EQ(info.qos(), 0);
EXPECT_EQ(info.sst(), 0);
EXPECT_EQ(info.apsd(), 0);
EXPECT_EQ(info.reserved(), 0);
EXPECT_EQ(info.dsss_ofdm(), 0);
EXPECT_EQ(info.delayed_block_ack(), 0);
EXPECT_EQ(info.immediate_block_ack(), 0);
}
#endif // TINS_DOT11_MGMT_TEST_H

View File

@@ -1,8 +1,5 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <algorithm> #include "dot11/dot11_control.h"
#include <memory>
#include <stdint.h>
#include "dot11.h"
#include "tests/dot11.h" #include "tests/dot11.h"
@@ -83,12 +80,12 @@ TEST_F(Dot11AckTest, CopyAssignmentOperator) {
TEST_F(Dot11AckTest, ClonePDU) { TEST_F(Dot11AckTest, ClonePDU) {
Dot11Ack dot1(expected_packet, sizeof(expected_packet)); Dot11Ack dot1(expected_packet, sizeof(expected_packet));
std::auto_ptr<Dot11Ack> dot2(dot1.clone()); Internals::smart_ptr<Dot11Ack>::type dot2(dot1.clone());
test_equals(dot1, *dot2); test_equals(dot1, *dot2);
} }
TEST_F(Dot11AckTest, FromBytes) { TEST_F(Dot11AckTest, FromBytes) {
std::auto_ptr<PDU> dot11(Dot11::from_bytes(expected_packet, sizeof(expected_packet))); Internals::smart_ptr<PDU>::type dot11(Dot11::from_bytes(expected_packet, sizeof(expected_packet)));
ASSERT_TRUE(dot11.get()); ASSERT_TRUE(dot11.get());
const Dot11Ack *inner = dot11->find_pdu<Dot11Ack>(); const Dot11Ack *inner = dot11->find_pdu<Dot11Ack>();
ASSERT_TRUE(inner); ASSERT_TRUE(inner);

View File

@@ -1,9 +1,6 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <algorithm> #include "dot11/dot11_assoc.h"
#include <memory> #include "tests/dot11_mgmt.h"
#include <stdint.h>
#include "dot11.h"
#include "tests/dot11.h"
using namespace std; using namespace std;
@@ -71,12 +68,12 @@ TEST_F(Dot11AssocRequestTest, ListenInterval) {
TEST_F(Dot11AssocRequestTest, ClonePDU) { TEST_F(Dot11AssocRequestTest, ClonePDU) {
Dot11AssocRequest dot1(expected_packet, sizeof(expected_packet)); Dot11AssocRequest dot1(expected_packet, sizeof(expected_packet));
std::auto_ptr<Dot11AssocRequest> dot2(dot1.clone()); Internals::smart_ptr<Dot11AssocRequest>::type dot2(dot1.clone());
test_equals(dot1, *dot2); test_equals(dot1, *dot2);
} }
TEST_F(Dot11AssocRequestTest, FromBytes) { TEST_F(Dot11AssocRequestTest, FromBytes) {
std::auto_ptr<PDU> dot11(Dot11::from_bytes(expected_packet, sizeof(expected_packet))); Internals::smart_ptr<PDU>::type dot11(Dot11::from_bytes(expected_packet, sizeof(expected_packet)));
ASSERT_TRUE(dot11.get()); ASSERT_TRUE(dot11.get());
const Dot11AssocRequest *inner = dot11->find_pdu<Dot11AssocRequest>(); const Dot11AssocRequest *inner = dot11->find_pdu<Dot11AssocRequest>();
ASSERT_TRUE(inner); ASSERT_TRUE(inner);

View File

@@ -1,9 +1,6 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <algorithm> #include "dot11/dot11_assoc.h"
#include <memory> #include "tests/dot11_mgmt.h"
#include <stdint.h>
#include "dot11.h"
#include "tests/dot11.h"
using namespace std; using namespace std;
@@ -79,12 +76,12 @@ TEST_F(Dot11AssocResponseTest, AID) {
TEST_F(Dot11AssocResponseTest, ClonePDU) { TEST_F(Dot11AssocResponseTest, ClonePDU) {
Dot11AssocResponse dot1(expected_packet, sizeof(expected_packet)); Dot11AssocResponse dot1(expected_packet, sizeof(expected_packet));
std::auto_ptr<Dot11AssocResponse> dot2(dot1.clone()); Internals::smart_ptr<Dot11AssocResponse>::type dot2(dot1.clone());
test_equals(dot1, *dot2); test_equals(dot1, *dot2);
} }
TEST_F(Dot11AssocResponseTest, FromBytes) { TEST_F(Dot11AssocResponseTest, FromBytes) {
std::auto_ptr<PDU> dot11(Dot11::from_bytes(expected_packet, sizeof(expected_packet))); Internals::smart_ptr<PDU>::type dot11(Dot11::from_bytes(expected_packet, sizeof(expected_packet)));
ASSERT_TRUE(dot11.get()); ASSERT_TRUE(dot11.get());
const Dot11AssocResponse *inner = dot11->find_pdu<Dot11AssocResponse>(); const Dot11AssocResponse *inner = dot11->find_pdu<Dot11AssocResponse>();
ASSERT_TRUE(inner); ASSERT_TRUE(inner);

View File

@@ -1,9 +1,6 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <algorithm> #include "dot11/dot11_auth.h"
#include <memory> #include "tests/dot11_mgmt.h"
#include <stdint.h>
#include "dot11.h"
#include "tests/dot11.h"
using namespace std; using namespace std;
@@ -87,12 +84,12 @@ TEST_F(Dot11AuthenticationTest, AuthAlgorithm) {
TEST_F(Dot11AuthenticationTest, ClonePDU) { TEST_F(Dot11AuthenticationTest, ClonePDU) {
Dot11Authentication dot1(expected_packet, sizeof(expected_packet)); Dot11Authentication dot1(expected_packet, sizeof(expected_packet));
std::auto_ptr<Dot11Authentication> dot2(dot1.clone()); Internals::smart_ptr<Dot11Authentication>::type dot2(dot1.clone());
test_equals(dot1, *dot2); test_equals(dot1, *dot2);
} }
TEST_F(Dot11AuthenticationTest, FromBytes) { TEST_F(Dot11AuthenticationTest, FromBytes) {
std::auto_ptr<PDU> dot11(Dot11::from_bytes(expected_packet, sizeof(expected_packet))); Internals::smart_ptr<PDU>::type dot11(Dot11::from_bytes(expected_packet, sizeof(expected_packet)));
ASSERT_TRUE(dot11.get()); ASSERT_TRUE(dot11.get());
const Dot11Authentication *inner = dot11->find_pdu<Dot11Authentication>(); const Dot11Authentication *inner = dot11->find_pdu<Dot11Authentication>();
ASSERT_TRUE(inner); ASSERT_TRUE(inner);

View File

@@ -1,10 +1,7 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <algorithm> #include "dot11/dot11_beacon.h"
#include <memory>
#include <stdint.h>
#include "dot11.h"
#include "rsn_information.h" #include "rsn_information.h"
#include "tests/dot11.h" #include "tests/dot11_mgmt.h"
using namespace std; using namespace std;
@@ -109,7 +106,7 @@ TEST_F(Dot11BeaconTest, SeqNum) {
} }
TEST_F(Dot11BeaconTest, FromBytes) { TEST_F(Dot11BeaconTest, FromBytes) {
std::auto_ptr<PDU> dot11(Dot11::from_bytes(expected_packet, sizeof(expected_packet))); Internals::smart_ptr<PDU>::type dot11(Dot11::from_bytes(expected_packet, sizeof(expected_packet)));
ASSERT_TRUE(dot11.get()); ASSERT_TRUE(dot11.get());
const Dot11Beacon *beacon = dot11->find_pdu<Dot11Beacon>(); const Dot11Beacon *beacon = dot11->find_pdu<Dot11Beacon>();
ASSERT_TRUE(beacon); ASSERT_TRUE(beacon);

View File

@@ -1,8 +1,5 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <algorithm> #include "dot11/dot11_control.h"
#include <memory>
#include <stdint.h>
#include "dot11.h"
#include "tests/dot11.h" #include "tests/dot11.h"
@@ -75,12 +72,12 @@ TEST_F(Dot11BlockAckRequestTest, ClonePDU) {
dot1.fragment_number(6); dot1.fragment_number(6);
dot1.start_sequence(0x294); dot1.start_sequence(0x294);
dot1.bar_control(0x9); dot1.bar_control(0x9);
std::auto_ptr<Dot11BlockAckRequest> dot2(dot1.clone()); Internals::smart_ptr<Dot11BlockAckRequest>::type dot2(dot1.clone());
test_equals(dot1, *dot2); test_equals(dot1, *dot2);
} }
TEST_F(Dot11BlockAckRequestTest, FromBytes) { TEST_F(Dot11BlockAckRequestTest, FromBytes) {
std::auto_ptr<PDU> dot11(Dot11::from_bytes(expected_packet, sizeof(expected_packet))); Internals::smart_ptr<PDU>::type dot11(Dot11::from_bytes(expected_packet, sizeof(expected_packet)));
ASSERT_TRUE(dot11.get()); ASSERT_TRUE(dot11.get());
const Dot11BlockAckRequest *inner = dot11->find_pdu<Dot11BlockAckRequest>(); const Dot11BlockAckRequest *inner = dot11->find_pdu<Dot11BlockAckRequest>();
ASSERT_TRUE(inner); ASSERT_TRUE(inner);

View File

@@ -1,9 +1,5 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <algorithm> #include "tests/dot11_control.h"
#include <memory>
#include <stdint.h>
#include "dot11.h"
#include "tests/dot11.h"
using namespace std; using namespace std;
@@ -59,12 +55,12 @@ TEST_F(Dot11CFEndTest, CopyAssignmentOperator) {
TEST_F(Dot11CFEndTest, ClonePDU) { TEST_F(Dot11CFEndTest, ClonePDU) {
Dot11CFEnd dot1(expected_packet, sizeof(expected_packet)); Dot11CFEnd dot1(expected_packet, sizeof(expected_packet));
std::auto_ptr<Dot11CFEnd> dot2(dot1.clone()); Internals::smart_ptr<Dot11CFEnd>::type dot2(dot1.clone());
test_equals(dot1, *dot2); test_equals(dot1, *dot2);
} }
TEST_F(Dot11CFEndTest, FromBytes) { TEST_F(Dot11CFEndTest, FromBytes) {
std::auto_ptr<PDU> dot11(Dot11::from_bytes(expected_packet, sizeof(expected_packet))); Internals::smart_ptr<PDU>::type dot11(Dot11::from_bytes(expected_packet, sizeof(expected_packet)));
ASSERT_TRUE(dot11.get()); ASSERT_TRUE(dot11.get());
const Dot11CFEnd *inner = dot11->find_pdu<Dot11CFEnd>(); const Dot11CFEnd *inner = dot11->find_pdu<Dot11CFEnd>();
ASSERT_TRUE(inner); ASSERT_TRUE(inner);

View File

@@ -1,9 +1,5 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <algorithm> #include "tests/dot11_control.h"
#include <memory>
#include <stdint.h>
#include "dot11.h"
#include "tests/dot11.h"
using namespace std; using namespace std;
@@ -59,12 +55,12 @@ TEST_F(Dot11EndCFAckTest, CopyAssignmentOperator) {
TEST_F(Dot11EndCFAckTest, ClonePDU) { TEST_F(Dot11EndCFAckTest, ClonePDU) {
Dot11EndCFAck dot1(expected_packet, sizeof(expected_packet)); Dot11EndCFAck dot1(expected_packet, sizeof(expected_packet));
std::auto_ptr<Dot11EndCFAck> dot2(dot1.clone()); Internals::smart_ptr<Dot11EndCFAck>::type dot2(dot1.clone());
test_equals(dot1, *dot2); test_equals(dot1, *dot2);
} }
TEST_F(Dot11EndCFAckTest, FromBytes) { TEST_F(Dot11EndCFAckTest, FromBytes) {
std::auto_ptr<PDU> dot11(Dot11::from_bytes(expected_packet, sizeof(expected_packet))); Internals::smart_ptr<PDU>::type dot11(Dot11::from_bytes(expected_packet, sizeof(expected_packet)));
ASSERT_TRUE(dot11.get()); ASSERT_TRUE(dot11.get());
const Dot11EndCFAck *inner = dot11->find_pdu<Dot11EndCFAck>(); const Dot11EndCFAck *inner = dot11->find_pdu<Dot11EndCFAck>();
ASSERT_TRUE(inner); ASSERT_TRUE(inner);

View File

@@ -1,10 +1,5 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <algorithm> #include "tests/dot11_data.h"
#include <memory>
#include <stdint.h>
#include "dot11.h"
#include "cxxstd.h"
#include "tests/dot11.h"
using namespace std; using namespace std;

View File

@@ -1,9 +1,6 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <algorithm> #include "dot11/dot11_auth.h"
#include <memory> #include "tests/dot11_mgmt.h"
#include <stdint.h>
#include "dot11.h"
#include "tests/dot11.h"
using namespace std; using namespace std;
@@ -69,12 +66,12 @@ TEST_F(Dot11DeauthenticationTest, ReasonCode) {
TEST_F(Dot11DeauthenticationTest, ClonePDU) { TEST_F(Dot11DeauthenticationTest, ClonePDU) {
Dot11Deauthentication dot1(expected_packet, sizeof(expected_packet)); Dot11Deauthentication dot1(expected_packet, sizeof(expected_packet));
std::auto_ptr<Dot11Deauthentication> dot2(dot1.clone()); Internals::smart_ptr<Dot11Deauthentication>::type dot2(dot1.clone());
test_equals(dot1, *dot2); test_equals(dot1, *dot2);
} }
TEST_F(Dot11DeauthenticationTest, FromBytes) { TEST_F(Dot11DeauthenticationTest, FromBytes) {
std::auto_ptr<PDU> dot11(Dot11::from_bytes(expected_packet, sizeof(expected_packet))); Internals::smart_ptr<PDU>::type dot11(Dot11::from_bytes(expected_packet, sizeof(expected_packet)));
ASSERT_TRUE(dot11.get()); ASSERT_TRUE(dot11.get());
const Dot11Deauthentication *inner = dot11->find_pdu<Dot11Deauthentication>(); const Dot11Deauthentication *inner = dot11->find_pdu<Dot11Deauthentication>();
ASSERT_TRUE(inner); ASSERT_TRUE(inner);

View File

@@ -1,9 +1,6 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <algorithm> #include "dot11/dot11_assoc.h"
#include <memory> #include "tests/dot11_mgmt.h"
#include <stdint.h>
#include "dot11.h"
#include "tests/dot11.h"
using namespace std; using namespace std;
@@ -70,12 +67,12 @@ TEST_F(Dot11DisassocTest, ReasonCode) {
TEST_F(Dot11DisassocTest, ClonePDU) { TEST_F(Dot11DisassocTest, ClonePDU) {
Dot11Disassoc dot1(expected_packet, sizeof(expected_packet)); Dot11Disassoc dot1(expected_packet, sizeof(expected_packet));
std::auto_ptr<Dot11Disassoc> dot2(dot1.clone()); Internals::smart_ptr<Dot11Disassoc>::type dot2(dot1.clone());
test_equals(dot1, *dot2); test_equals(dot1, *dot2);
} }
TEST_F(Dot11DisassocTest, FromBytes) { TEST_F(Dot11DisassocTest, FromBytes) {
std::auto_ptr<PDU> dot11(Dot11::from_bytes(expected_packet, sizeof(expected_packet))); Internals::smart_ptr<PDU>::type dot11(Dot11::from_bytes(expected_packet, sizeof(expected_packet)));
ASSERT_TRUE(dot11.get()); ASSERT_TRUE(dot11.get());
const Dot11Disassoc *inner = dot11->find_pdu<Dot11Disassoc>(); const Dot11Disassoc *inner = dot11->find_pdu<Dot11Disassoc>();
ASSERT_TRUE(inner); ASSERT_TRUE(inner);

View File

@@ -1,9 +1,4 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <cstring>
#include <string>
#include <algorithm>
#include <stdint.h>
#include "dot11.h"
#include "tests/dot11.h" #include "tests/dot11.h"
#include "utils.h" #include "utils.h"

View File

@@ -1,9 +1,6 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <algorithm> #include "dot11/dot11_probe.h"
#include <memory> #include "tests/dot11_mgmt.h"
#include <stdint.h>
#include "dot11.h"
#include "tests/dot11.h"
using namespace std; using namespace std;
@@ -60,12 +57,12 @@ TEST_F(Dot11ProbeRequestTest, CopyAssignmentOperator) {
TEST_F(Dot11ProbeRequestTest, ClonePDU) { TEST_F(Dot11ProbeRequestTest, ClonePDU) {
Dot11ProbeRequest dot1(expected_packet, sizeof(expected_packet)); Dot11ProbeRequest dot1(expected_packet, sizeof(expected_packet));
std::auto_ptr<Dot11ProbeRequest> dot2(dot1.clone()); Internals::smart_ptr<Dot11ProbeRequest>::type dot2(dot1.clone());
test_equals(dot1, *dot2); test_equals(dot1, *dot2);
} }
TEST_F(Dot11ProbeRequestTest, FromBytes) { TEST_F(Dot11ProbeRequestTest, FromBytes) {
std::auto_ptr<PDU> dot11(Dot11::from_bytes(expected_packet, sizeof(expected_packet))); Internals::smart_ptr<PDU>::type dot11(Dot11::from_bytes(expected_packet, sizeof(expected_packet)));
ASSERT_TRUE(dot11.get()); ASSERT_TRUE(dot11.get());
const Dot11ProbeRequest *inner = dot11->find_pdu<Dot11ProbeRequest>(); const Dot11ProbeRequest *inner = dot11->find_pdu<Dot11ProbeRequest>();
ASSERT_TRUE(inner); ASSERT_TRUE(inner);

View File

@@ -1,9 +1,6 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <algorithm> #include "dot11/dot11_probe.h"
#include <memory> #include "tests/dot11_mgmt.h"
#include <stdint.h>
#include "dot11.h"
#include "tests/dot11.h"
using namespace std; using namespace std;
@@ -78,12 +75,12 @@ TEST_F(Dot11ProbeResponseTest, Timestamp) {
TEST_F(Dot11ProbeResponseTest, ClonePDU) { TEST_F(Dot11ProbeResponseTest, ClonePDU) {
Dot11ProbeResponse dot1(expected_packet, sizeof(expected_packet)); Dot11ProbeResponse dot1(expected_packet, sizeof(expected_packet));
std::auto_ptr<Dot11ProbeResponse> dot2(dot1.clone()); Internals::smart_ptr<Dot11ProbeResponse>::type dot2(dot1.clone());
test_equals(dot1, *dot2); test_equals(dot1, *dot2);
} }
TEST_F(Dot11ProbeResponseTest, FromBytes) { TEST_F(Dot11ProbeResponseTest, FromBytes) {
std::auto_ptr<PDU> dot11(Dot11::from_bytes(expected_packet, sizeof(expected_packet))); Internals::smart_ptr<PDU>::type dot11(Dot11::from_bytes(expected_packet, sizeof(expected_packet)));
ASSERT_TRUE(dot11.get()); ASSERT_TRUE(dot11.get());
const Dot11ProbeResponse *inner = dot11->find_pdu<Dot11ProbeResponse>(); const Dot11ProbeResponse *inner = dot11->find_pdu<Dot11ProbeResponse>();
ASSERT_TRUE(inner); ASSERT_TRUE(inner);

View File

@@ -1,9 +1,5 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <algorithm> #include "tests/dot11_control.h"
#include <memory>
#include <stdint.h>
#include "dot11.h"
#include "tests/dot11.h"
using namespace std; using namespace std;
@@ -59,12 +55,12 @@ TEST_F(Dot11PSPollTest, CopyAssignmentOperator) {
TEST_F(Dot11PSPollTest, ClonePDU) { TEST_F(Dot11PSPollTest, ClonePDU) {
Dot11PSPoll dot1(expected_packet, sizeof(expected_packet)); Dot11PSPoll dot1(expected_packet, sizeof(expected_packet));
std::auto_ptr<Dot11PSPoll> dot2(dot1.clone()); Internals::smart_ptr<Dot11PSPoll>::type dot2(dot1.clone());
test_equals(dot1, *dot2); test_equals(dot1, *dot2);
} }
TEST_F(Dot11PSPollTest, FromBytes) { TEST_F(Dot11PSPollTest, FromBytes) {
std::auto_ptr<PDU> dot11(Dot11::from_bytes(expected_packet, sizeof(expected_packet))); Internals::smart_ptr<PDU>::type dot11(Dot11::from_bytes(expected_packet, sizeof(expected_packet)));
ASSERT_TRUE(dot11.get()); ASSERT_TRUE(dot11.get());
const Dot11PSPoll *inner = dot11->find_pdu<Dot11PSPoll>(); const Dot11PSPoll *inner = dot11->find_pdu<Dot11PSPoll>();
ASSERT_TRUE(inner); ASSERT_TRUE(inner);

View File

@@ -1,9 +1,6 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <algorithm> #include "dot11/dot11_assoc.h"
#include <memory> #include "tests/dot11_mgmt.h"
#include <stdint.h>
#include "dot11.h"
#include "tests/dot11.h"
using namespace std; using namespace std;
@@ -78,12 +75,12 @@ TEST_F(Dot11ReAssocRequestTest, CurrentAP) {
TEST_F(Dot11ReAssocRequestTest, ClonePDU) { TEST_F(Dot11ReAssocRequestTest, ClonePDU) {
Dot11ReAssocRequest dot1(expected_packet, sizeof(expected_packet)); Dot11ReAssocRequest dot1(expected_packet, sizeof(expected_packet));
std::auto_ptr<Dot11ReAssocRequest> dot2(dot1.clone()); Internals::smart_ptr<Dot11ReAssocRequest>::type dot2(dot1.clone());
test_equals(dot1, *dot2); test_equals(dot1, *dot2);
} }
TEST_F(Dot11ReAssocRequestTest, FromBytes) { TEST_F(Dot11ReAssocRequestTest, FromBytes) {
std::auto_ptr<PDU> dot11(Dot11::from_bytes(expected_packet, sizeof(expected_packet))); Internals::smart_ptr<PDU>::type dot11(Dot11::from_bytes(expected_packet, sizeof(expected_packet)));
ASSERT_TRUE(dot11.get()); ASSERT_TRUE(dot11.get());
const Dot11ReAssocRequest *inner = dot11->find_pdu<Dot11ReAssocRequest>(); const Dot11ReAssocRequest *inner = dot11->find_pdu<Dot11ReAssocRequest>();
ASSERT_TRUE(inner); ASSERT_TRUE(inner);

View File

@@ -1,9 +1,6 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <algorithm> #include "dot11/dot11_assoc.h"
#include <memory> #include "tests/dot11_mgmt.h"
#include <stdint.h>
#include "dot11.h"
#include "tests/dot11.h"
using namespace std; using namespace std;
@@ -67,12 +64,12 @@ TEST_F(Dot11ReAssocResponseTest, CopyAssignmentOperator) {
TEST_F(Dot11ReAssocResponseTest, ClonePDU) { TEST_F(Dot11ReAssocResponseTest, ClonePDU) {
Dot11ReAssocResponse dot1(expected_packet, sizeof(expected_packet)); Dot11ReAssocResponse dot1(expected_packet, sizeof(expected_packet));
std::auto_ptr<Dot11ReAssocResponse> dot2(dot1.clone()); Internals::smart_ptr<Dot11ReAssocResponse>::type dot2(dot1.clone());
test_equals(dot1, *dot2); test_equals(dot1, *dot2);
} }
TEST_F(Dot11ReAssocResponseTest, FromBytes) { TEST_F(Dot11ReAssocResponseTest, FromBytes) {
std::auto_ptr<PDU> dot11(Dot11::from_bytes(expected_packet, sizeof(expected_packet))); Internals::smart_ptr<PDU>::type dot11(Dot11::from_bytes(expected_packet, sizeof(expected_packet)));
ASSERT_TRUE(dot11.get()); ASSERT_TRUE(dot11.get());
const Dot11ReAssocResponse *inner = dot11->find_pdu<Dot11ReAssocResponse>(); const Dot11ReAssocResponse *inner = dot11->find_pdu<Dot11ReAssocResponse>();
ASSERT_TRUE(inner); ASSERT_TRUE(inner);

View File

@@ -1,9 +1,5 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <algorithm> #include "tests/dot11_control.h"
#include <memory>
#include <stdint.h>
#include "dot11.h"
#include "tests/dot11.h"
using namespace std; using namespace std;
@@ -59,12 +55,12 @@ TEST_F(Dot11RTSTest, CopyAssignmentOperator) {
TEST_F(Dot11RTSTest, ClonePDU) { TEST_F(Dot11RTSTest, ClonePDU) {
Dot11RTS dot1(expected_packet, sizeof(expected_packet)); Dot11RTS dot1(expected_packet, sizeof(expected_packet));
std::auto_ptr<Dot11RTS> dot2(dot1.clone()); Internals::smart_ptr<Dot11RTS>::type dot2(dot1.clone());
test_equals(dot1, *dot2); test_equals(dot1, *dot2);
} }
TEST_F(Dot11RTSTest, FromBytes) { TEST_F(Dot11RTSTest, FromBytes) {
std::auto_ptr<PDU> dot11(Dot11::from_bytes(expected_packet, sizeof(expected_packet))); Internals::smart_ptr<PDU>::type dot11(Dot11::from_bytes(expected_packet, sizeof(expected_packet)));
ASSERT_TRUE(dot11.get()); ASSERT_TRUE(dot11.get());
const Dot11RTS *inner = dot11->find_pdu<Dot11RTS>(); const Dot11RTS *inner = dot11->find_pdu<Dot11RTS>();
ASSERT_TRUE(inner); ASSERT_TRUE(inner);

View File

@@ -3,7 +3,8 @@
#include <string> #include <string>
#include <stdint.h> #include <stdint.h>
#include "radiotap.h" #include "radiotap.h"
#include "dot11.h" #include "dot11/dot11_data.h"
#include "dot11/dot11_beacon.h"
#include "utils.h" #include "utils.h"
using namespace std; using namespace std;

View File

@@ -4,7 +4,7 @@
#include <stdint.h> #include <stdint.h>
#include "crypto.h" #include "crypto.h"
#include "arp.h" #include "arp.h"
#include "dot11.h" #include "dot11/dot11_data.h"
using namespace Tins; using namespace Tins;