1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
|
// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
/*
* KUnit tests for channel helper functions
*
* Copyright (C) 2024 Intel Corporation
*/
#include <kunit/test.h>
#include "utils.h"
#include "iwl-trans.h"
#include "mld.h"
#include "sta.h"
static const struct is_dup_case {
const char *desc;
struct {
/* ieee80211_hdr fields */
__le16 fc;
__le16 seq;
u8 tid;
bool multicast;
/* iwl_rx_mpdu_desc fields */
bool is_amsdu;
u8 sub_frame_idx;
} rx_pkt;
struct {
__le16 last_seq;
u8 last_sub_frame_idx;
u8 tid;
} dup_data_state;
struct {
bool is_dup;
u32 rx_status_flag;
} result;
} is_dup_cases[] = {
{
.desc = "Control frame",
.rx_pkt = {
.fc = __cpu_to_le16(IEEE80211_FTYPE_CTL),
},
.result = {
.is_dup = false,
.rx_status_flag = 0,
}
},
{
.desc = "Null func frame",
.rx_pkt = {
.fc = __cpu_to_le16(IEEE80211_FTYPE_DATA |
IEEE80211_STYPE_NULLFUNC),
},
.result = {
.is_dup = false,
.rx_status_flag = 0,
}
},
{
.desc = "Multicast data",
.rx_pkt = {
.fc = __cpu_to_le16(IEEE80211_FTYPE_DATA),
.multicast = true,
},
.result = {
.is_dup = false,
.rx_status_flag = 0,
}
},
{
.desc = "QoS null func frame",
.rx_pkt = {
.fc = __cpu_to_le16(IEEE80211_FTYPE_DATA |
IEEE80211_STYPE_QOS_NULLFUNC),
},
.result = {
.is_dup = false,
.rx_status_flag = 0,
}
},
{
.desc = "QoS data new sequence",
.rx_pkt = {
.fc = __cpu_to_le16(IEEE80211_FTYPE_DATA |
IEEE80211_STYPE_QOS_DATA),
.seq = __cpu_to_le16(0x101),
},
.dup_data_state = {
.last_seq = __cpu_to_le16(0x100),
.last_sub_frame_idx = 0,
},
.result = {
.is_dup = false,
.rx_status_flag = RX_FLAG_DUP_VALIDATED,
},
},
{
.desc = "QoS data same sequence, no retry",
.rx_pkt = {
.fc = __cpu_to_le16(IEEE80211_FTYPE_DATA |
IEEE80211_STYPE_QOS_DATA),
.seq = __cpu_to_le16(0x100),
},
.dup_data_state = {
.last_seq = __cpu_to_le16(0x100),
.last_sub_frame_idx = 0,
},
.result = {
.is_dup = false,
.rx_status_flag = RX_FLAG_DUP_VALIDATED,
},
},
{
.desc = "QoS data same sequence, has retry",
.rx_pkt = {
.fc = __cpu_to_le16(IEEE80211_FTYPE_DATA |
IEEE80211_STYPE_QOS_DATA |
IEEE80211_FCTL_RETRY),
.seq = __cpu_to_le16(0x100),
},
.dup_data_state = {
.last_seq = __cpu_to_le16(0x100),
.last_sub_frame_idx = 0,
},
.result = {
.is_dup = true,
.rx_status_flag = 0,
},
},
{
.desc = "QoS data invalid tid",
.rx_pkt = {
.fc = __cpu_to_le16(IEEE80211_FTYPE_DATA |
IEEE80211_STYPE_QOS_DATA),
.seq = __cpu_to_le16(0x100),
.tid = IWL_MAX_TID_COUNT + 1,
},
.result = {
.is_dup = true,
.rx_status_flag = 0,
},
},
{
.desc = "non-QoS data, same sequence, same tid, no retry",
.rx_pkt = {
/* Driver will use tid = IWL_MAX_TID_COUNT */
.fc = __cpu_to_le16(IEEE80211_FTYPE_DATA),
.seq = __cpu_to_le16(0x100),
},
.dup_data_state = {
.tid = IWL_MAX_TID_COUNT,
.last_seq = __cpu_to_le16(0x100),
.last_sub_frame_idx = 0,
},
.result = {
.is_dup = false,
.rx_status_flag = RX_FLAG_DUP_VALIDATED,
},
},
{
.desc = "non-QoS data, same sequence, same tid, has retry",
.rx_pkt = {
/* Driver will use tid = IWL_MAX_TID_COUNT */
.fc = __cpu_to_le16(IEEE80211_FTYPE_DATA |
IEEE80211_FCTL_RETRY),
.seq = __cpu_to_le16(0x100),
},
.dup_data_state = {
.tid = IWL_MAX_TID_COUNT,
.last_seq = __cpu_to_le16(0x100),
.last_sub_frame_idx = 0,
},
.result = {
.is_dup = true,
.rx_status_flag = 0,
},
},
{
.desc = "non-QoS data, same sequence on different tid's",
.rx_pkt = {
/* Driver will use tid = IWL_MAX_TID_COUNT */
.fc = __cpu_to_le16(IEEE80211_FTYPE_DATA),
.seq = __cpu_to_le16(0x100),
},
.dup_data_state = {
.tid = 7,
.last_seq = __cpu_to_le16(0x100),
.last_sub_frame_idx = 0,
},
.result = {
.is_dup = false,
.rx_status_flag = RX_FLAG_DUP_VALIDATED,
},
},
{
.desc = "A-MSDU new subframe, allow same PN",
.rx_pkt = {
.fc = __cpu_to_le16(IEEE80211_FTYPE_DATA |
IEEE80211_STYPE_QOS_DATA),
.seq = __cpu_to_le16(0x100),
.is_amsdu = true,
.sub_frame_idx = 1,
},
.dup_data_state = {
.last_seq = __cpu_to_le16(0x100),
.last_sub_frame_idx = 0,
},
.result = {
.is_dup = false,
.rx_status_flag = RX_FLAG_ALLOW_SAME_PN |
RX_FLAG_DUP_VALIDATED,
},
},
{
.desc = "A-MSDU subframe with smaller idx, disallow same PN",
.rx_pkt = {
.fc = __cpu_to_le16(IEEE80211_FTYPE_DATA |
IEEE80211_STYPE_QOS_DATA),
.seq = __cpu_to_le16(0x100),
.is_amsdu = true,
.sub_frame_idx = 1,
},
.dup_data_state = {
.last_seq = __cpu_to_le16(0x100),
.last_sub_frame_idx = 2,
},
.result = {
.is_dup = false,
.rx_status_flag = RX_FLAG_DUP_VALIDATED,
},
},
{
.desc = "A-MSDU same subframe, no retry, disallow same PN",
.rx_pkt = {
.fc = __cpu_to_le16(IEEE80211_FTYPE_DATA |
IEEE80211_STYPE_QOS_DATA),
.seq = __cpu_to_le16(0x100),
.is_amsdu = true,
.sub_frame_idx = 0,
},
.dup_data_state = {
.last_seq = __cpu_to_le16(0x100),
.last_sub_frame_idx = 0,
},
.result = {
.is_dup = false,
.rx_status_flag = RX_FLAG_DUP_VALIDATED,
},
},
{
.desc = "A-MSDU same subframe, has retry",
.rx_pkt = {
.fc = __cpu_to_le16(IEEE80211_FTYPE_DATA |
IEEE80211_STYPE_QOS_DATA |
IEEE80211_FCTL_RETRY),
.seq = __cpu_to_le16(0x100),
.is_amsdu = true,
.sub_frame_idx = 0,
},
.dup_data_state = {
.last_seq = __cpu_to_le16(0x100),
.last_sub_frame_idx = 0,
},
.result = {
.is_dup = true,
.rx_status_flag = 0,
},
},
};
KUNIT_ARRAY_PARAM_DESC(test_is_dup, is_dup_cases, desc);
static void
setup_dup_data_state(struct ieee80211_sta *sta)
{
struct kunit *test = kunit_get_current_test();
const struct is_dup_case *param = (const void *)(test->param_value);
struct iwl_mld_sta *mld_sta = iwl_mld_sta_from_mac80211(sta);
u8 tid = param->dup_data_state.tid;
struct iwl_mld_rxq_dup_data *dup_data;
/* Allocate dup_data only for 1 queue */
KUNIT_ALLOC_AND_ASSERT(test, dup_data);
/* Initialize dup data, see iwl_mld_alloc_dup_data */
memset(dup_data->last_seq, 0xff, sizeof(dup_data->last_seq));
dup_data->last_seq[tid] = param->dup_data_state.last_seq;
dup_data->last_sub_frame_idx[tid] =
param->dup_data_state.last_sub_frame_idx;
mld_sta->dup_data = dup_data;
}
static void setup_rx_pkt(const struct is_dup_case *param,
struct ieee80211_hdr *hdr,
struct iwl_rx_mpdu_desc *mpdu_desc)
{
u8 tid = param->rx_pkt.tid;
/* Set "new rx packet" header */
hdr->frame_control = param->rx_pkt.fc;
hdr->seq_ctrl = param->rx_pkt.seq;
if (ieee80211_is_data_qos(hdr->frame_control)) {
u8 *qc = ieee80211_get_qos_ctl(hdr);
qc[0] = tid & IEEE80211_QOS_CTL_TID_MASK;
}
if (param->rx_pkt.multicast)
hdr->addr1[0] = 0x1;
/* Set mpdu_desc */
mpdu_desc->amsdu_info = param->rx_pkt.sub_frame_idx &
IWL_RX_MPDU_AMSDU_SUBFRAME_IDX_MASK;
if (param->rx_pkt.is_amsdu)
mpdu_desc->mac_flags2 |= IWL_RX_MPDU_MFLG2_AMSDU;
}
static void test_is_dup(struct kunit *test)
{
const struct is_dup_case *param = (const void *)(test->param_value);
struct iwl_mld *mld = test->priv;
struct iwl_rx_mpdu_desc mpdu_desc = { };
struct ieee80211_rx_status rx_status = { };
struct ieee80211_vif *vif;
struct ieee80211_sta *sta;
struct ieee80211_hdr hdr;
vif = iwlmld_kunit_add_vif(false, NL80211_IFTYPE_STATION);
sta = iwlmld_kunit_setup_sta(vif, IEEE80211_STA_AUTHORIZED, -1);
/* Prepare test case state */
setup_dup_data_state(sta);
setup_rx_pkt(param, &hdr, &mpdu_desc);
KUNIT_EXPECT_EQ(test,
iwl_mld_is_dup(mld, sta, &hdr, &mpdu_desc, &rx_status,
0), /* assuming only 1 queue */
param->result.is_dup);
KUNIT_EXPECT_EQ(test, rx_status.flag, param->result.rx_status_flag);
}
static struct kunit_case is_dup_test_cases[] = {
KUNIT_CASE_PARAM(test_is_dup, test_is_dup_gen_params),
{},
};
static struct kunit_suite is_dup = {
.name = "iwlmld-rx-is-dup",
.test_cases = is_dup_test_cases,
.init = iwlmld_kunit_test_init,
};
kunit_test_suite(is_dup);
|