diff mbox series

[4/6] wifi: mac80211: kunit: generalize public action test

Message ID 20231220151952.415232-5-benjamin@sipsolutions.net
State New
Headers show
Series Add some more cfg80211 and mac80211 kunit tests | expand

Commit Message

Benjamin Berg Dec. 20, 2023, 3:19 p.m. UTC
From: Johannes Berg <johannes.berg@intel.com>

Generalize the test to be able to handle arbitrary
action categories and non-action frames, for further
test expansion.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Reviewed-by: Gregory Greenman <gregory.greenman@intel.com>
---
 net/mac80211/tests/mfp.c | 78 +++++++++++++++++++++++++++++-----------
 1 file changed, 57 insertions(+), 21 deletions(-)
diff mbox series

Patch

diff --git a/net/mac80211/tests/mfp.c b/net/mac80211/tests/mfp.c
index 629a5801c08f..6ec31386c0df 100644
--- a/net/mac80211/tests/mfp.c
+++ b/net/mac80211/tests/mfp.c
@@ -13,34 +13,52 @@  MODULE_IMPORT_NS(EXPORTED_FOR_KUNIT_TESTING);
 
 static const struct mfp_test_case {
 	const char *desc;
-	bool sta, mfp, decrypted, unicast, protected_dual;
+	bool sta, mfp, decrypted, unicast;
+	u8 category;
+	u8 stype;
+	u8 action;
 	ieee80211_rx_result result;
-} accept_public_action_cases[] = {
+} accept_mfp_cases[] = {
 	/* regular public action */
 	{
 		.desc = "public action: accept unicast from unknown peer",
+		.stype = IEEE80211_STYPE_ACTION,
+		.category = WLAN_CATEGORY_PUBLIC,
+		.action = WLAN_PUB_ACTION_DSE_ENABLEMENT,
 		.unicast = true,
 		.result = RX_CONTINUE,
 	},
 	{
 		.desc = "public action: accept multicast from unknown peer",
+		.stype = IEEE80211_STYPE_ACTION,
+		.category = WLAN_CATEGORY_PUBLIC,
+		.action = WLAN_PUB_ACTION_DSE_ENABLEMENT,
 		.unicast = false,
 		.result = RX_CONTINUE,
 	},
 	{
 		.desc = "public action: accept unicast without MFP",
+		.stype = IEEE80211_STYPE_ACTION,
+		.category = WLAN_CATEGORY_PUBLIC,
+		.action = WLAN_PUB_ACTION_DSE_ENABLEMENT,
 		.unicast = true,
 		.sta = true,
 		.result = RX_CONTINUE,
 	},
 	{
 		.desc = "public action: accept multicast without MFP",
+		.stype = IEEE80211_STYPE_ACTION,
+		.category = WLAN_CATEGORY_PUBLIC,
+		.action = WLAN_PUB_ACTION_DSE_ENABLEMENT,
 		.unicast = false,
 		.sta = true,
 		.result = RX_CONTINUE,
 	},
 	{
 		.desc = "public action: drop unicast with MFP",
+		.stype = IEEE80211_STYPE_ACTION,
+		.category = WLAN_CATEGORY_PUBLIC,
+		.action = WLAN_PUB_ACTION_DSE_ENABLEMENT,
 		.unicast = true,
 		.sta = true,
 		.mfp = true,
@@ -48,6 +66,9 @@  static const struct mfp_test_case {
 	},
 	{
 		.desc = "public action: accept multicast with MFP",
+		.stype = IEEE80211_STYPE_ACTION,
+		.category = WLAN_CATEGORY_PUBLIC,
+		.action = WLAN_PUB_ACTION_DSE_ENABLEMENT,
 		.unicast = false,
 		.sta = true,
 		.mfp = true,
@@ -56,33 +77,43 @@  static const struct mfp_test_case {
 	/* protected dual of public action */
 	{
 		.desc = "protected dual: drop unicast from unknown peer",
-		.protected_dual = true,
+		.stype = IEEE80211_STYPE_ACTION,
+		.category = WLAN_CATEGORY_PROTECTED_DUAL_OF_ACTION,
+		.action = WLAN_PUB_ACTION_DSE_ENABLEMENT,
 		.unicast = true,
 		.result = RX_DROP_U_UNPROT_DUAL,
 	},
 	{
 		.desc = "protected dual: drop multicast from unknown peer",
-		.protected_dual = true,
+		.stype = IEEE80211_STYPE_ACTION,
+		.category = WLAN_CATEGORY_PROTECTED_DUAL_OF_ACTION,
+		.action = WLAN_PUB_ACTION_DSE_ENABLEMENT,
 		.unicast = false,
 		.result = RX_DROP_U_UNPROT_DUAL,
 	},
 	{
 		.desc = "protected dual: drop unicast without MFP",
-		.protected_dual = true,
+		.stype = IEEE80211_STYPE_ACTION,
+		.category = WLAN_CATEGORY_PROTECTED_DUAL_OF_ACTION,
+		.action = WLAN_PUB_ACTION_DSE_ENABLEMENT,
 		.unicast = true,
 		.sta = true,
 		.result = RX_DROP_U_UNPROT_DUAL,
 	},
 	{
 		.desc = "protected dual: drop multicast without MFP",
-		.protected_dual = true,
+		.stype = IEEE80211_STYPE_ACTION,
+		.category = WLAN_CATEGORY_PROTECTED_DUAL_OF_ACTION,
+		.action = WLAN_PUB_ACTION_DSE_ENABLEMENT,
 		.unicast = false,
 		.sta = true,
 		.result = RX_DROP_U_UNPROT_DUAL,
 	},
 	{
 		.desc = "protected dual: drop undecrypted unicast with MFP",
-		.protected_dual = true,
+		.stype = IEEE80211_STYPE_ACTION,
+		.category = WLAN_CATEGORY_PROTECTED_DUAL_OF_ACTION,
+		.action = WLAN_PUB_ACTION_DSE_ENABLEMENT,
 		.unicast = true,
 		.sta = true,
 		.mfp = true,
@@ -90,7 +121,9 @@  static const struct mfp_test_case {
 	},
 	{
 		.desc = "protected dual: drop undecrypted multicast with MFP",
-		.protected_dual = true,
+		.stype = IEEE80211_STYPE_ACTION,
+		.category = WLAN_CATEGORY_PROTECTED_DUAL_OF_ACTION,
+		.action = WLAN_PUB_ACTION_DSE_ENABLEMENT,
 		.unicast = false,
 		.sta = true,
 		.mfp = true,
@@ -98,7 +131,9 @@  static const struct mfp_test_case {
 	},
 	{
 		.desc = "protected dual: accept unicast with MFP",
-		.protected_dual = true,
+		.stype = IEEE80211_STYPE_ACTION,
+		.category = WLAN_CATEGORY_PROTECTED_DUAL_OF_ACTION,
+		.action = WLAN_PUB_ACTION_DSE_ENABLEMENT,
 		.decrypted = true,
 		.unicast = true,
 		.sta = true,
@@ -107,7 +142,9 @@  static const struct mfp_test_case {
 	},
 	{
 		.desc = "protected dual: accept multicast with MFP",
-		.protected_dual = true,
+		.stype = IEEE80211_STYPE_ACTION,
+		.category = WLAN_CATEGORY_PROTECTED_DUAL_OF_ACTION,
+		.action = WLAN_PUB_ACTION_DSE_ENABLEMENT,
 		.decrypted = true,
 		.unicast = false,
 		.sta = true,
@@ -116,11 +153,9 @@  static const struct mfp_test_case {
 	},
 };
 
-KUNIT_ARRAY_PARAM_DESC(accept_public_action,
-		       accept_public_action_cases,
-		       desc);
+KUNIT_ARRAY_PARAM_DESC(accept_mfp, accept_mfp_cases, desc);
 
-static void accept_public_action(struct kunit *test)
+static void accept_mfp(struct kunit *test)
 {
 	static struct sta_info sta = {};
 	const struct mfp_test_case *params = test->param_value;
@@ -130,7 +165,7 @@  static void accept_public_action(struct kunit *test)
 	struct ieee80211_rx_status *status;
 	struct ieee80211_hdr_3addr hdr = {
 		.frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
-					     IEEE80211_STYPE_ACTION),
+					     params->stype),
 		.addr1 = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
 		.addr2 = { 0x12, 0x22, 0x33, 0x44, 0x55, 0x66 },
 		/* A3/BSSID doesn't matter here */
@@ -160,11 +195,12 @@  static void accept_public_action(struct kunit *test)
 
 	skb_put_data(rx.skb, &hdr, sizeof(hdr));
 
-	if (params->protected_dual)
-		skb_put_u8(rx.skb, WLAN_CATEGORY_PROTECTED_DUAL_OF_ACTION);
-	else
-		skb_put_u8(rx.skb, WLAN_CATEGORY_PUBLIC);
-	skb_put_u8(rx.skb, WLAN_PUB_ACTION_DSE_ENABLEMENT);
+	switch (params->stype) {
+	case IEEE80211_STYPE_ACTION:
+		skb_put_u8(rx.skb, params->category);
+		skb_put_u8(rx.skb, params->action);
+		break;
+	}
 
 	KUNIT_EXPECT_EQ(test,
 			ieee80211_drop_unencrypted_mgmt(&rx),
@@ -172,7 +208,7 @@  static void accept_public_action(struct kunit *test)
 }
 
 static struct kunit_case mfp_test_cases[] = {
-	KUNIT_CASE_PARAM(accept_public_action, accept_public_action_gen_params),
+	KUNIT_CASE_PARAM(accept_mfp, accept_mfp_gen_params),
 	{}
 };