From patchwork Tue Nov 28 01:50:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrei Otcheretianski X-Patchwork-Id: 1868675 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=HIFQAYA6; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=Ei0peSoJ; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=hostap-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SdyWY0FPJz1yRy for ; Mon, 27 Nov 2023 18:53:29 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=nvgwN351XSOQMvu4KRPrz9zfwGcJKzS7C8SswlAvdgg=; b=HIFQAYA6hptFY1 SxnwlEOQKKkDvHJF0cMHcnb+Qjs+fWMjmXB4PaVJ39rmla7ZCsMzX8i5UptEFv+TaH7/8r7OuQZJ9 3Pq5lOWGc0/+CKeQax0dU/X/Ouuzp+ChDnNroIq1DqKJaDLo2x2GWdz4J2iOASOp/L+muRVxTt2La 3ECSnR5zA5M6ujyONnZyu7W0m0qjeJwiii2ArVDVUJsQCbtuwWLUMLgqc0YSlm5InstxUj68lTSkR mmfUDJ1NGQZlkWgPZ2yXkqbPaFS2hX/JGfryRnHUTj0Pzw8KS7GPv6ssNo+HVbwnXk4G7iJpgJcFj SGcCJmQeGE6oKGWs5g/g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r7WPp-001lPL-0q; Mon, 27 Nov 2023 07:52:25 +0000 Received: from mgamail.intel.com ([134.134.136.31]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r7WPl-001lOs-21 for hostap@lists.infradead.org; Mon, 27 Nov 2023 07:52:23 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701071541; x=1732607541; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hOVWL8pBsygr5wmej/2nxUZlTu3dC/cj90UHHFj4G8k=; b=Ei0peSoJ7fvcv430xV+so9sxg1M/8+hM4Vs/MhHVektfBVGasPEMXMCP FV4Yt5uPBzuTaOriF1fsrf00j3nxSkC+x5mFQSaknxHrGK2RxM2jSrxxT UC1qZUywdhW9C0gb214bU4/IKucXnIju+ui/Mzk7nUgRuonyo391oRgqr eWTo6hozkvEmelAdZfaVS/adDrf5LZ4YOwJqMiDHs8lDSuvDvGKYmNpch RrN6YcAK3xbbXo41JAEFv+Z+/UbqVol4uub3kdU4FwYqlapDIrnC89btI 7btUQsy7Jlvjyq2pZQlVN+i7CBK75UnZ0JH5wy9d+2Z95NBNUBHLPOPgv A==; X-IronPort-AV: E=McAfee;i="6600,9927,10906"; a="456983606" X-IronPort-AV: E=Sophos;i="6.04,230,1695711600"; d="scan'208";a="456983606" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Nov 2023 23:52:19 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10906"; a="744483830" X-IronPort-AV: E=Sophos;i="6.04,230,1695711600"; d="scan'208";a="744483830" Received: from unknown (HELO WEIS0042.iil.intel.com) ([10.12.217.211]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Nov 2023 23:52:03 -0800 From: Andrei Otcheretianski To: hostap@lists.infradead.org Cc: Andrei Otcheretianski , Benjamin Berg Subject: [PATCH v2] tests: Add a unit test for RNR/basic ML element parsing Date: Tue, 28 Nov 2023 03:50:07 +0200 Message-ID: <20231128015007.3399996-1-andrei.otcheretianski@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231126_235221_738191_5A8E533D X-CRM114-Status: GOOD ( 17.40 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: 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 [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [134.134.136.31 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 SPF_NONE SPF: sender does not publish an SPF Record 2.5 DATE_IN_FUTURE_12_24 Date: is 12 to 24 hours after Received: date -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.2 DKIMWL_WL_HIGH DKIMwl.org - High trust sender X-BeenThere: hostap@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Hostap" Errors-To: hostap-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org 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 Signed-off-by: Andrei Otcheretianski --- 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 + +#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(¶ms); + + 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; +}