1 // SPDX-License-Identifier: GPL-2.0-only
3 * KUnit tests for element parsing
5 * Copyright (C) 2023-2024 Intel Corporation
7 #include <kunit/test.h>
8 #include "../ieee80211_i.h"
10 MODULE_IMPORT_NS("EXPORTED_FOR_KUNIT_TESTING");
12 static void mle_defrag(struct kunit
*test
)
14 struct ieee80211_elems_parse_params parse_params
= {
17 .mode
= IEEE80211_CONN_MODE_EHT
,
19 struct ieee802_11_elems
*parsed
;
21 u8
*len_mle
, *len_prof
;
24 skb
= alloc_skb(1024, GFP_KERNEL
);
25 KUNIT_ASSERT_NOT_NULL(test
, skb
);
27 if (skb_pad(skb
, skb_tailroom(skb
))) {
28 KUNIT_FAIL(test
, "failed to pad skb");
32 /* build a multi-link element */
33 skb_put_u8(skb
, WLAN_EID_EXTENSION
);
34 len_mle
= skb_put(skb
, 1);
35 skb_put_u8(skb
, WLAN_EID_EXT_EHT_MULTI_LINK
);
37 put_unaligned_le16(IEEE80211_ML_CONTROL_TYPE_BASIC
,
39 /* struct ieee80211_mle_basic_common_info */
40 skb_put_u8(skb
, 7); /* includes len field */
41 skb_put_data(skb
, "\x00\x00\x00\x00\x00\x00", ETH_ALEN
); /* MLD addr */
43 /* with a STA profile inside */
44 skb_put_u8(skb
, IEEE80211_MLE_SUBELEM_PER_STA_PROFILE
);
45 len_prof
= skb_put(skb
, 1);
46 put_unaligned_le16(IEEE80211_MLE_STA_CONTROL_COMPLETE_PROFILE
|
49 skb_put_u8(skb
, 1); /* fake sta_info_len - includes itself */
50 /* put a bunch of useless elements into it */
51 for (i
= 0; i
< 20; i
++) {
52 skb_put_u8(skb
, WLAN_EID_SSID
);
57 /* fragment STA profile */
58 ieee80211_fragment_element(skb
, len_prof
,
59 IEEE80211_MLE_SUBELEM_FRAGMENT
);
61 ieee80211_fragment_element(skb
, len_mle
, WLAN_EID_FRAGMENT
);
63 parse_params
.start
= skb
->data
;
64 parse_params
.len
= skb
->len
;
65 parsed
= ieee802_11_parse_elems_full(&parse_params
);
66 /* should return ERR_PTR or valid, not NULL */
67 KUNIT_EXPECT_NOT_NULL(test
, parsed
);
69 if (IS_ERR_OR_NULL(parsed
))
72 KUNIT_EXPECT_NOT_NULL(test
, parsed
->ml_basic
);
77 2 /* sta profile element header */ +
78 3 /* sta profile header */ +
79 20 * 22 /* sta profile data */ +
80 2 /* sta profile fragment element */);
81 KUNIT_EXPECT_NOT_NULL(test
, parsed
->prof
);
84 3 /* sta profile header */ +
85 20 * 22 /* sta profile data */);
92 static struct kunit_case element_parsing_test_cases
[] = {
93 KUNIT_CASE(mle_defrag
),
97 static struct kunit_suite element_parsing
= {
98 .name
= "mac80211-element-parsing",
99 .test_cases
= element_parsing_test_cases
,
102 kunit_test_suite(element_parsing
);