1 /*
2 * WPA BSS parsing - test program
3 * Copyright (C) 2023 Intel Corporation
4 *
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
7 */
8
9 #include <assert.h>
10
11 #include "utils/includes.h"
12
13 #include "utils/common.h"
14 #include "wpa_supplicant_i.h"
15 #include "bss.h"
16
17 #define ASSERT_CMP_INT(a, cmp, b) { \
18 ssize_t __a = (a); ssize_t __b = (b); \
19 if (!(__a cmp __b)) { \
20 wpa_printf(MSG_ERROR, "Assertion failed: %ld %s %ld", \
21 __a, #cmp, __b); \
22 abort(); \
23 } \
24 }
25
test_parse_basic_ml(struct wpa_supplicant * wpa_s,u8 mld_id)26 void test_parse_basic_ml(struct wpa_supplicant *wpa_s, u8 mld_id)
27 {
28 const u8 mld_ie[] = {
29 /* RNR */
30 WLAN_EID_REDUCED_NEIGHBOR_REPORT, 40,
31 0x00, 0x10, 0x51, 0x01, 0xff, 0x00, 0x11, 0x22,
32 0x33, 0x44, 0x01, 0x68, 0x05, 0x2d, 0xa6, 0x42,
33 0xfe, mld_id, 0x10, 0x00, 0x00, 0x10, 0x51, 0x06,
34 0xff, 0x00, 0x11, 0x22, 0x33, 0x44, 0x02, 0x68,
35 0x05, 0x2d, 0xa6, 0x42, 0xfe, mld_id, 0x11, 0x00,
36 /* basic ML */
37 WLAN_EID_EXTENSION, 1 + 15, WLAN_EID_EXT_MULTI_LINK,
38 0xb0, 0x01, 0x0d, 0x02, 0x00, 0x00, 0x00, 0x07,
39 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
40 };
41 const u8 mbssid_idx_ie[] = {
42 WLAN_EID_MULTIPLE_BSSID_INDEX, 1, mld_id,
43 };
44 struct {
45 struct wpa_bss bss;
46 u8 ies[sizeof(mld_ie) + sizeof(mbssid_idx_ie)];
47 } bss;
48 u8 ap_mld_addr[ETH_ALEN];
49 u16 missing_links;
50 u8 ret;
51 u8 ap_mld_id;
52
53 memcpy(bss.bss.ies, mld_ie, sizeof(mld_ie));
54 bss.bss.ie_len = sizeof(mld_ie);
55
56 if (mld_id > 0) {
57 memcpy(bss.bss.ies + sizeof(mld_ie), mbssid_idx_ie,
58 sizeof(mbssid_idx_ie));
59 bss.bss.ie_len += sizeof(mbssid_idx_ie);
60 }
61
62 ret = wpa_bss_parse_basic_ml_element(wpa_s, &bss.bss, ap_mld_addr,
63 &missing_links, NULL, &ap_mld_id);
64
65 ASSERT_CMP_INT(ret, ==, 0);
66 ASSERT_CMP_INT(bss.bss.valid_links, ==, 1);
67 ASSERT_CMP_INT(missing_links, ==, 0x0002);
68 ASSERT_CMP_INT(ap_mld_id, ==, mld_id);
69 }
70
71 #define RUN_TEST(func, ...) do { \
72 func(wpa_s, __VA_ARGS__); \
73 printf("\nok " #func " " #__VA_ARGS__ "\n\n"); \
74 } while (false)
75
main(void)76 int main(void)
77 {
78 struct wpa_interface iface = {
79 .ifname = "dummy",
80 };
81 struct wpa_global *global;
82 struct wpa_params params = {
83 .wpa_debug_level = MSG_DEBUG,
84 };
85 struct wpa_supplicant *wpa_s;
86
87 global = wpa_supplicant_init(¶ms);
88
89 wpa_s = wpa_supplicant_add_iface(global, &iface, NULL);
90 assert(wpa_s);
91
92 RUN_TEST(test_parse_basic_ml, 0);
93 RUN_TEST(test_parse_basic_ml, 1);
94
95 return 0;
96 }
97