]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
tests: Add a unit test for RNR/basic ML element parsing
authorAndrei Otcheretianski <andrei.otcheretianski@intel.com>
Tue, 28 Nov 2023 01:50:07 +0000 (03:50 +0200)
committerJouni Malinen <j@w1.fi>
Sat, 2 Dec 2023 17:02:02 +0000 (19:02 +0200)
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@intel.com>
Signed-off-by: Andrei Otcheretianski <andrei.otcheretianski@intel.com>
tests/Makefile
tests/test-bss.c [new file with mode: 0644]

index 2d2343b640a52d16735ca1524c16b9570e48d042..8ec154bb3e9e0e0fadc7e9a81d3365ec7290fad9 100644 (file)
@@ -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 (file)
index 0000000..3e09001
--- /dev/null
@@ -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;
+}