1 // SPDX-License-Identifier: GPL-2.0-only 1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 2 /* 3 * KUnit tests for element parsing 3 * KUnit tests for element parsing 4 * 4 * 5 * Copyright (C) 2023-2024 Intel Corporation 5 * Copyright (C) 2023-2024 Intel Corporation 6 */ 6 */ 7 #include <kunit/test.h> 7 #include <kunit/test.h> 8 #include "../ieee80211_i.h" 8 #include "../ieee80211_i.h" 9 9 10 MODULE_IMPORT_NS(EXPORTED_FOR_KUNIT_TESTING); 10 MODULE_IMPORT_NS(EXPORTED_FOR_KUNIT_TESTING); 11 11 12 static void mle_defrag(struct kunit *test) 12 static void mle_defrag(struct kunit *test) 13 { 13 { 14 struct ieee80211_elems_parse_params pa 14 struct ieee80211_elems_parse_params parse_params = { 15 .link_id = 12, 15 .link_id = 12, 16 .from_ap = true, 16 .from_ap = true, 17 .mode = IEEE80211_CONN_MODE_EH 17 .mode = IEEE80211_CONN_MODE_EHT, 18 }; 18 }; 19 struct ieee802_11_elems *parsed; 19 struct ieee802_11_elems *parsed; 20 struct sk_buff *skb; 20 struct sk_buff *skb; 21 u8 *len_mle, *len_prof; 21 u8 *len_mle, *len_prof; 22 int i; 22 int i; 23 23 24 skb = alloc_skb(1024, GFP_KERNEL); 24 skb = alloc_skb(1024, GFP_KERNEL); 25 KUNIT_ASSERT_NOT_NULL(test, skb); 25 KUNIT_ASSERT_NOT_NULL(test, skb); 26 26 27 if (skb_pad(skb, skb_tailroom(skb))) { 27 if (skb_pad(skb, skb_tailroom(skb))) { 28 KUNIT_FAIL(test, "failed to pa 28 KUNIT_FAIL(test, "failed to pad skb"); 29 return; 29 return; 30 } 30 } 31 31 32 /* build a multi-link element */ 32 /* build a multi-link element */ 33 skb_put_u8(skb, WLAN_EID_EXTENSION); 33 skb_put_u8(skb, WLAN_EID_EXTENSION); 34 len_mle = skb_put(skb, 1); 34 len_mle = skb_put(skb, 1); 35 skb_put_u8(skb, WLAN_EID_EXT_EHT_MULTI 35 skb_put_u8(skb, WLAN_EID_EXT_EHT_MULTI_LINK); 36 36 37 put_unaligned_le16(IEEE80211_ML_CONTRO 37 put_unaligned_le16(IEEE80211_ML_CONTROL_TYPE_BASIC, 38 skb_put(skb, 2)); 38 skb_put(skb, 2)); 39 /* struct ieee80211_mle_basic_common_i 39 /* struct ieee80211_mle_basic_common_info */ 40 skb_put_u8(skb, 7); /* includes len fi 40 skb_put_u8(skb, 7); /* includes len field */ 41 skb_put_data(skb, "\x00\x00\x00\x00\x0 41 skb_put_data(skb, "\x00\x00\x00\x00\x00\x00", ETH_ALEN); /* MLD addr */ 42 42 43 /* with a STA profile inside */ 43 /* with a STA profile inside */ 44 skb_put_u8(skb, IEEE80211_MLE_SUBELEM_ 44 skb_put_u8(skb, IEEE80211_MLE_SUBELEM_PER_STA_PROFILE); 45 len_prof = skb_put(skb, 1); 45 len_prof = skb_put(skb, 1); 46 put_unaligned_le16(IEEE80211_MLE_STA_C 46 put_unaligned_le16(IEEE80211_MLE_STA_CONTROL_COMPLETE_PROFILE | 47 parse_params.link_i 47 parse_params.link_id, 48 skb_put(skb, 2)); 48 skb_put(skb, 2)); 49 skb_put_u8(skb, 1); /* fake sta_info_l 49 skb_put_u8(skb, 1); /* fake sta_info_len - includes itself */ 50 /* put a bunch of useless elements int 50 /* put a bunch of useless elements into it */ 51 for (i = 0; i < 20; i++) { 51 for (i = 0; i < 20; i++) { 52 skb_put_u8(skb, WLAN_EID_SSID) 52 skb_put_u8(skb, WLAN_EID_SSID); 53 skb_put_u8(skb, 20); 53 skb_put_u8(skb, 20); 54 skb_put(skb, 20); 54 skb_put(skb, 20); 55 } 55 } 56 56 57 /* fragment STA profile */ 57 /* fragment STA profile */ 58 ieee80211_fragment_element(skb, len_pr 58 ieee80211_fragment_element(skb, len_prof, 59 IEEE80211_M 59 IEEE80211_MLE_SUBELEM_FRAGMENT); 60 /* fragment MLE */ 60 /* fragment MLE */ 61 ieee80211_fragment_element(skb, len_ml 61 ieee80211_fragment_element(skb, len_mle, WLAN_EID_FRAGMENT); 62 62 63 parse_params.start = skb->data; 63 parse_params.start = skb->data; 64 parse_params.len = skb->len; 64 parse_params.len = skb->len; 65 parsed = ieee802_11_parse_elems_full(& 65 parsed = ieee802_11_parse_elems_full(&parse_params); 66 /* should return ERR_PTR or valid, not 66 /* should return ERR_PTR or valid, not NULL */ 67 KUNIT_EXPECT_NOT_NULL(test, parsed); 67 KUNIT_EXPECT_NOT_NULL(test, parsed); 68 68 69 if (IS_ERR_OR_NULL(parsed)) 69 if (IS_ERR_OR_NULL(parsed)) 70 goto free_skb; 70 goto free_skb; 71 71 72 KUNIT_EXPECT_NOT_NULL(test, parsed->ml 72 KUNIT_EXPECT_NOT_NULL(test, parsed->ml_basic); 73 KUNIT_EXPECT_EQ(test, 73 KUNIT_EXPECT_EQ(test, 74 parsed->ml_basic_len, 74 parsed->ml_basic_len, 75 2 /* control */ + 75 2 /* control */ + 76 7 /* common info */ + 76 7 /* common info */ + 77 2 /* sta profile eleme 77 2 /* sta profile element header */ + 78 3 /* sta profile heade 78 3 /* sta profile header */ + 79 20 * 22 /* sta profile 79 20 * 22 /* sta profile data */ + 80 2 /* sta profile fragm 80 2 /* sta profile fragment element */); 81 KUNIT_EXPECT_NOT_NULL(test, parsed->pr 81 KUNIT_EXPECT_NOT_NULL(test, parsed->prof); 82 KUNIT_EXPECT_EQ(test, 82 KUNIT_EXPECT_EQ(test, 83 parsed->sta_prof_len, 83 parsed->sta_prof_len, 84 3 /* sta profile heade 84 3 /* sta profile header */ + 85 20 * 22 /* sta profile 85 20 * 22 /* sta profile data */); 86 86 87 kfree(parsed); 87 kfree(parsed); 88 free_skb: 88 free_skb: 89 kfree_skb(skb); 89 kfree_skb(skb); 90 } 90 } 91 91 92 static struct kunit_case element_parsing_test_ 92 static struct kunit_case element_parsing_test_cases[] = { 93 KUNIT_CASE(mle_defrag), 93 KUNIT_CASE(mle_defrag), 94 {} 94 {} 95 }; 95 }; 96 96 97 static struct kunit_suite element_parsing = { 97 static struct kunit_suite element_parsing = { 98 .name = "mac80211-element-parsing", 98 .name = "mac80211-element-parsing", 99 .test_cases = element_parsing_test_cas 99 .test_cases = element_parsing_test_cases, 100 }; 100 }; 101 101 102 kunit_test_suite(element_parsing); 102 kunit_test_suite(element_parsing); 103 103
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.