[PATCH v2] tests: Add a unit test for RNR/basic ML element parsing

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Going through everything to test parsing of the basic ML element and the
RNR element is not really feasible for MBSSID mode. As such, add a unit
test to excercise parsing the available links from the RNR, basic ML
element and MBSSID-Index element if present.

Signed-off-by: Benjamin Berg <benjamin.berg@xxxxxxxxx>
Signed-off-by: Andrei Otcheretianski <andrei.otcheretianski@xxxxxxxxx>
---
 tests/Makefile   | 61 +++++++++++++++++++++++++++++-
 tests/test-bss.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 156 insertions(+), 1 deletion(-)
 create mode 100644 tests/test-bss.c

diff --git a/tests/Makefile b/tests/Makefile
index 2d2343b640..8ec154bb3e 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -2,7 +2,8 @@ ALL=test-base64 test-md4 test-milenage \
 	test-rsa-sig-ver \
 	test-sha1 \
 	test-https test-https_server \
-	test-sha256 test-aes test-x509v3 test-list test-rc4
+	test-sha256 test-aes test-x509v3 test-list test-rc4 \
+	test-bss
 
 include ../src/build.rules
 
@@ -82,6 +83,63 @@ test-x509v3: $(call BUILDOBJ,test-x509v3.o) $(LIBS)
 	$(LDO) $(LDFLAGS) -o $@ $< $(LLIBS)
 
 
+# We could cut this down more by enabling fewer options (above)
+ELIBS += $(SRC)/crypto/libcrypto.a
+ELIBS += $(SRC)/tls/libtls.a
+
+WPAS_SRC=../wpa_supplicant
+SRC=../src
+WPA_LIBS = $(SRC)/common/libcommon.a
+
+CFLAGS += -I$(SRC) -I$(SRC)/utils -I$(WPAS_SRC)
+
+CFLAGS += -DCONFIG_DRIVER_NONE
+CFLAGS += -DIEEE8021X_EAPOL
+
+WPA_OBJS = $(WPAS_SRC)/bssid_ignore.o
+WPA_OBJS += $(WPAS_SRC)/bss.o
+WPA_OBJS += $(WPAS_SRC)/config.o
+WPA_OBJS += $(WPAS_SRC)/config_file.o
+WPA_OBJS += $(WPAS_SRC)/eap_register.o
+WPA_OBJS += $(WPAS_SRC)/events.o
+WPA_OBJS += $(WPAS_SRC)/notify.o
+WPA_OBJS += $(WPAS_SRC)/offchannel.o
+WPA_OBJS += $(WPAS_SRC)/op_classes.o
+WPA_OBJS += $(WPAS_SRC)/robust_av.o
+WPA_OBJS += $(WPAS_SRC)/rrm.o
+WPA_OBJS += $(WPAS_SRC)/scan.o
+WPA_OBJS += $(WPAS_SRC)/wmm_ac.o
+WPA_OBJS += $(WPAS_SRC)/wpa_supplicant.o
+WPA_OBJS += $(WPAS_SRC)/wpas_glue.o
+WPA_OBJS += $(SRC)/rsn_supp/wpa.o
+WPA_OBJS += $(SRC)/rsn_supp/wpa_ft.o
+WPA_OBJS += $(SRC)/rsn_supp/wpa_ie.o
+WPA_OBJS += $(SRC)/rsn_supp/tdls.o
+WPA_OBJS += $(SRC)/rsn_supp/preauth.o
+WPA_OBJS += $(SRC)/rsn_supp/pmksa_cache.o
+WPA_OBJS += $(SRC)/eapol_supp/eapol_supp_sm.o
+WPA_OBJS += $(SRC)/eap_common/eap_common.o
+WPA_OBJS += $(SRC)/eap_peer/eap.o
+WPA_OBJS += $(SRC)/eap_peer/eap_methods.o
+WPA_OBJS += $(SRC)/drivers/driver_common.o
+WPA_OBJS += $(SRC)/drivers/driver_none.o
+WPA_OBJS += $(SRC)/drivers/drivers.o
+WPA_OBJS += $(SRC)/l2_packet/l2_packet_none.o
+
+_OBJS_VAR := WPA_OBJS
+include ../src/objs.mk
+
+_OBJS_VAR := WPA_LIBS
+include ../src/objs.mk
+
+_OBJS_VAR := ELIBS
+include ../src/objs.mk
+
+LIBS=$(SLIBS) $(DLIBS) $(WPA_LIBS) $(ELIBS)
+
+test-bss: $(call BUILDOBJ,test-bss.o) $(WPA_OBJS) $(LIBS)
+	$(LDO) $(LDFLAGS) -o $@ $< $(LLIBS) $(WPA_CFLAGS) $(WPA_OBJS) $(LIBS)
+
 run-tests: $(ALL)
 	./test-aes
 	./test-list
@@ -90,6 +148,7 @@ run-tests: $(ALL)
 	./test-rsa-sig-ver
 	./test-sha1
 	./test-sha256
+	./test-bss
 	@echo
 	@echo All tests completed successfully.
 
diff --git a/tests/test-bss.c b/tests/test-bss.c
new file mode 100644
index 0000000000..3e0900140c
--- /dev/null
+++ b/tests/test-bss.c
@@ -0,0 +1,96 @@
+/*
+ * WPA BSS parsing - test program
+ * Copyright (C) 2023 Intel Corporation
+ *
+ * This software may be distributed under the terms of the BSD license.
+ * See README for more details.
+ */
+
+#include <assert.h>
+
+#include "utils/includes.h"
+
+#include "utils/common.h"
+#include "wpa_supplicant_i.h"
+#include "bss.h"
+
+#define ASSERT_CMP_INT(a, cmp, b) { \
+	ssize_t __a = (a); ssize_t __b = (b);		\
+		if (!(__a cmp __b)) {			\
+			wpa_printf(MSG_ERROR, "Assertion failed: %ld %s %ld", \
+				   __a, #cmp, __b);	\
+			abort();			\
+		}					\
+	}
+
+void test_parse_basic_ml(struct wpa_supplicant *wpa_s, u8 mld_id)
+{
+	const u8 mld_ie[] = {
+		/* RNR */
+		WLAN_EID_REDUCED_NEIGHBOR_REPORT, 40,
+		0x00, 0x10, 0x51, 0x01, 0xff, 0x00, 0x11, 0x22,
+		0x33, 0x44, 0x01, 0x68, 0x05, 0x2d, 0xa6, 0x42,
+		0xfe, mld_id, 0x10, 0x00, 0x00, 0x10, 0x51, 0x06,
+		0xff, 0x00, 0x11, 0x22, 0x33, 0x44, 0x02, 0x68,
+		0x05, 0x2d, 0xa6, 0x42, 0xfe, mld_id, 0x11, 0x00,
+		/* basic ML */
+		WLAN_EID_EXTENSION, 1 + 15, WLAN_EID_EXT_MULTI_LINK,
+		0xb0, 0x01, 0x0d, 0x02, 0x00, 0x00, 0x00, 0x07,
+		0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
+	};
+	const u8 mbssid_idx_ie[] = {
+		WLAN_EID_MULTIPLE_BSSID_INDEX, 1, mld_id,
+	};
+	struct {
+		struct wpa_bss bss;
+		u8 ies[sizeof(mld_ie) + sizeof(mbssid_idx_ie)];
+	} bss;
+	u8 ap_mld_addr[ETH_ALEN];
+	u16 missing_links;
+	u8 ret;
+	u8 ap_mld_id;
+
+	memcpy(bss.bss.ies, mld_ie, sizeof(mld_ie));
+	bss.bss.ie_len = sizeof(mld_ie);
+
+	if (mld_id > 0) {
+		memcpy(bss.bss.ies + sizeof(mld_ie), mbssid_idx_ie,
+		       sizeof(mbssid_idx_ie));
+		bss.bss.ie_len += sizeof(mbssid_idx_ie);
+	}
+
+	ret = wpa_bss_parse_basic_ml_element(wpa_s, &bss.bss, ap_mld_addr,
+					     &missing_links, NULL, &ap_mld_id);
+
+	ASSERT_CMP_INT(ret, ==, 0);
+	ASSERT_CMP_INT(bss.bss.n_mld_links, ==, 1);
+	ASSERT_CMP_INT(missing_links, ==, 0x0002);
+	ASSERT_CMP_INT(ap_mld_id, ==, mld_id);
+}
+
+#define RUN_TEST(func, ...) do {			\
+		func(wpa_s, __VA_ARGS__);		\
+		printf("\nok " #func " " #__VA_ARGS__ "\n\n");		\
+	} while (false)
+
+int main(void)
+{
+	struct wpa_interface iface = {
+		.ifname = "dummy",
+	};
+	struct wpa_global *global;
+	struct wpa_params params = {
+		.wpa_debug_level = MSG_DEBUG,
+	};
+	struct wpa_supplicant *wpa_s;
+
+	global = wpa_supplicant_init(&params);
+
+	wpa_s = wpa_supplicant_add_iface(global, &iface, NULL);
+	assert(wpa_s);
+
+	RUN_TEST(test_parse_basic_ml, 0);
+	RUN_TEST(test_parse_basic_ml, 1);
+
+	return 0;
+}
-- 
2.43.0


_______________________________________________
Hostap mailing list
Hostap@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/hostap



[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux