eiwd

no dbus iwd with iwctl functionality
git clone https://git.daat.foo/repos/eiwd.git
Log | Files | Refs | Submodules | README | LICENSE

test-band.c (23451B)


      1 /*
      2  *
      3  *  Wireless daemon for Linux
      4  *
      5  *  Copyright (C) 2021  Intel Corporation. All rights reserved.
      6  *
      7  *  This library is free software; you can redistribute it and/or
      8  *  modify it under the terms of the GNU Lesser General Public
      9  *  License as published by the Free Software Foundation; either
     10  *  version 2.1 of the License, or (at your option) any later version.
     11  *
     12  *  This library is distributed in the hope that it will be useful,
     13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
     14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     15  *  Lesser General Public License for more details.
     16  *
     17  *  You should have received a copy of the GNU Lesser General Public
     18  *  License along with this library; if not, write to the Free Software
     19  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
     20  *
     21  */
     22 
     23 #ifdef HAVE_CONFIG_H
     24 #include <config.h>
     25 #endif
     26 
     27 #include <stdio.h>
     28 #include <string.h>
     29 #include <assert.h>
     30 #include <stdlib.h>
     31 #include <errno.h>
     32 #include <ell/ell.h>
     33 
     34 #include "src/band.h"
     35 #include "src/netdev.h"
     36 #include "src/ie.h"
     37 
     38 static struct band *new_band()
     39 {
     40 	/* Band with VHT/80, short GI, NSS:2 and VHT MCS 0-9 */
     41 	static const uint8_t vht_mcs_set[] = {
     42 		0xfa, 0xff, 0x00, 0x00, 0xfa, 0xff, 0x00, 0x20,
     43 	};
     44 	static const uint8_t vht_capabilities[] = {
     45 		0xa0, 0x71, 0x80, 0x03,
     46 	};
     47 	static const uint8_t ht_mcs_set[] = {
     48 		0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     49 		0x00, 0x00, 0x2c, 0x01, 0x01, 0x00, 0x00, 0x00,
     50 	};
     51 	static const uint8_t ht_capabilities[] = {
     52 		0xee, 0x11,
     53 	};
     54 	/* band + 8 basic rates */
     55 	struct band *band = l_malloc(sizeof(struct band) + 8);
     56 
     57 	memset(band, 0, sizeof(struct band) + 8);
     58 
     59 	band->supported_rates_len = 8;
     60 	band->supported_rates[0] = 12;
     61 	band->supported_rates[1] = 18;
     62 	band->supported_rates[2] = 24;
     63 	band->supported_rates[3] = 36;
     64 	band->supported_rates[4] = 48;
     65 	band->supported_rates[5] = 72;
     66 	band->supported_rates[6] = 96;
     67 	band->supported_rates[7] = 108;
     68 
     69 	band->ht_supported = true;
     70 	band->vht_supported = true;
     71 
     72 	memcpy(band->vht_mcs_set, vht_mcs_set, sizeof(band->vht_mcs_set));
     73 	memcpy(band->vht_capabilities, vht_capabilities,
     74 					sizeof(band->vht_capabilities));
     75 	memcpy(band->ht_mcs_set, ht_mcs_set, sizeof(band->ht_mcs_set));
     76 	memcpy(band->ht_capabilities, ht_capabilities,
     77 					sizeof(band->ht_capabilities));
     78 
     79 	return band;
     80 }
     81 
     82 static void band_test_nonht_1(const void *data)
     83 {
     84 	uint8_t supported_rates[] = { 1, 8,
     85 			0x8c, 0x12, 0x98, 0x24, 0xb0, 0x48, 0x60, 0x6c };
     86 	struct band *band = new_band();
     87 	uint64_t data_rate;
     88 	int ret;
     89 
     90 	ret = band_estimate_nonht_rate(band, supported_rates, NULL,
     91 							-50, &data_rate);
     92 	assert(ret == 0);
     93 	assert(data_rate == 54000000);
     94 
     95 	ret = band_estimate_nonht_rate(band, supported_rates, NULL,
     96 							-66, &data_rate);
     97 	assert(ret == 0);
     98 	assert(data_rate == 48000000);
     99 
    100 	ret = band_estimate_nonht_rate(band, supported_rates, NULL,
    101 							-70, &data_rate);
    102 	assert(ret == 0);
    103 	assert(data_rate == 36000000);
    104 
    105 	ret = band_estimate_nonht_rate(band, supported_rates, NULL,
    106 							-74, &data_rate);
    107 	assert(ret == 0);
    108 	assert(data_rate == 24000000);
    109 
    110 	ret = band_estimate_nonht_rate(band, supported_rates, NULL,
    111 							-77, &data_rate);
    112 	assert(ret == 0);
    113 	assert(data_rate == 18000000);
    114 
    115 	ret = band_estimate_nonht_rate(band, supported_rates, NULL,
    116 							-79, &data_rate);
    117 	assert(ret == 0);
    118 	assert(data_rate == 12000000);
    119 
    120 	ret = band_estimate_nonht_rate(band, supported_rates, NULL,
    121 							-81, &data_rate);
    122 	assert(ret == 0);
    123 	assert(data_rate == 9000000);
    124 
    125 	ret = band_estimate_nonht_rate(band, supported_rates, NULL,
    126 							-82, &data_rate);
    127 	assert(ret == 0);
    128 	assert(data_rate == 6000000);
    129 
    130 	ret = band_estimate_nonht_rate(band, supported_rates, NULL,
    131 							-83, &data_rate);
    132 	assert(ret < 0);
    133 
    134 	band_free(band);
    135 }
    136 
    137 static void band_test_ht_1(const void *data)
    138 {
    139 	/* HT40 */
    140 	uint8_t hto[] = { 61, 22,
    141 				0x95, 0x0d, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00,
    142 				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    143 				0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
    144 	/* HT40, MCS 0-23, 40/20Mhz SGI */
    145 	uint8_t htc[] = { 45, 26,
    146 				0xef, 0x09, 0x17, 0xff, 0xff, 0xff, 0x00, 0x00,
    147 				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
    148 				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    149 				0x00, 0x00 };
    150 	struct band *band = new_band();
    151 	uint64_t data_rate;
    152 	int ret;
    153 
    154 	ret = band_estimate_ht_rx_rate(band, htc, hto, -51, &data_rate);
    155 	assert(ret == 0);
    156 	assert(data_rate == 300000000);
    157 
    158 	ret = band_estimate_ht_rx_rate(band, htc, hto, -62, &data_rate);
    159 	assert(ret == 0);
    160 	assert(data_rate == 270000000);
    161 
    162 	ret = band_estimate_ht_rx_rate(band, htc, hto, -63, &data_rate);
    163 	assert(ret == 0);
    164 	assert(data_rate == 240000000);
    165 
    166 	ret = band_estimate_ht_rx_rate(band, htc, hto, -66, &data_rate);
    167 	assert(ret == 0);
    168 	assert(data_rate == 180000000);
    169 
    170 	ret = band_estimate_ht_rx_rate(band, htc, hto, -71, &data_rate);
    171 	assert(ret == 0);
    172 	assert(data_rate == 120000000);
    173 
    174 	ret = band_estimate_ht_rx_rate(band, htc, hto, -74, &data_rate);
    175 	assert(ret == 0);
    176 	assert(data_rate == 90000000);
    177 
    178 	ret = band_estimate_ht_rx_rate(band, htc, hto, -76, &data_rate);
    179 	assert(ret == 0);
    180 	assert(data_rate == 60000000);
    181 
    182 	ret = band_estimate_ht_rx_rate(band, htc, hto, -79, &data_rate);
    183 	assert(ret == 0);
    184 	assert(data_rate == 30000000);
    185 
    186 	/* We should now fall back to HT20 */
    187 	ret = band_estimate_ht_rx_rate(band, htc, hto, -82, &data_rate);
    188 	assert(ret == 0);
    189 	assert(data_rate == 14444440);
    190 
    191 	ret = band_estimate_ht_rx_rate(band, htc, hto, -83, &data_rate);
    192 	assert(ret < 0);
    193 
    194 	band_free(band);
    195 }
    196 
    197 static void band_test_vht_1(const void *data)
    198 {
    199 	/* VHT operating on 80 Mhz */
    200 	uint8_t vhto[] = { 192, 5, 0x01, 0x9b, 0x00, 0x00, 0x00 };
    201 	/* VHT80, NSS:3, MCS 0-9, 80Mhz SGI */
    202 	uint8_t vhtc[] = { 191, 12,
    203 				0xb2, 0x59, 0x82, 0x0f, 0xea, 0xff, 0x00, 0x00,
    204 				0xea, 0xff, 0x00, 0x00 };
    205 	/* HT40 */
    206 	uint8_t hto[] = { 61, 22,
    207 				0x95, 0x0d, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00,
    208 				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    209 				0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
    210 	/* HT40, MCS 0-23, 40/20Mhz SGI */
    211 	uint8_t htc[] = { 45, 26,
    212 				0xef, 0x09, 0x17, 0xff, 0xff, 0xff, 0x00, 0x00,
    213 				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    214 				0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    215 				0x00, 0x00 };
    216 	struct band *band = new_band();
    217 	uint64_t data_rate;
    218 	int ret;
    219 
    220 	ret = band_estimate_vht_rx_rate(band, vhtc, vhto, htc, hto,
    221 					-51, &data_rate);
    222 	assert(ret == 0);
    223 	assert(data_rate == 866666660);
    224 
    225 	ret = band_estimate_vht_rx_rate(band, vhtc, vhto, htc, hto,
    226 					-53, &data_rate);
    227 	assert(ret == 0);
    228 	assert(data_rate == 780000000);
    229 
    230 	ret = band_estimate_vht_rx_rate(band, vhtc, vhto, htc, hto,
    231 					-56, &data_rate);
    232 	assert(ret == 0);
    233 	assert(data_rate == 650000000);
    234 
    235 	ret = band_estimate_vht_rx_rate(band, vhtc, vhto, htc, hto,
    236 					-59, &data_rate);
    237 	assert(ret == 0);
    238 	assert(data_rate == 585000000);
    239 
    240 	ret = band_estimate_vht_rx_rate(band, vhtc, vhto, htc, hto,
    241 					-60, &data_rate);
    242 	assert(ret == 0);
    243 	assert(data_rate == 520000000);
    244 
    245 	ret = band_estimate_vht_rx_rate(band, vhtc, vhto, htc, hto,
    246 					-63, &data_rate);
    247 	assert(ret == 0);
    248 	assert(data_rate == 390000000);
    249 
    250 	ret = band_estimate_vht_rx_rate(band, vhtc, vhto, htc, hto,
    251 					-67, &data_rate);
    252 	assert(ret == 0);
    253 	assert(data_rate == 260000000);
    254 
    255 	ret = band_estimate_vht_rx_rate(band, vhtc, vhto, htc, hto,
    256 					-70, &data_rate);
    257 	assert(ret == 0);
    258 	assert(data_rate == 195000000);
    259 
    260 	ret = band_estimate_vht_rx_rate(band, vhtc, vhto, htc, hto,
    261 					-73, &data_rate);
    262 	assert(ret == 0);
    263 	assert(data_rate == 130000000);
    264 
    265 	ret = band_estimate_vht_rx_rate(band, vhtc, vhto, htc, hto,
    266 					-76, &data_rate);
    267 	assert(ret == 0);
    268 	assert(data_rate == 65000000);
    269 
    270 	/* We should now fall back to HT40 */
    271 	ret = band_estimate_vht_rx_rate(band, vhtc, vhto, htc, hto,
    272 					-79, &data_rate);
    273 	assert(ret == 0);
    274 	assert(data_rate == 30000000);
    275 
    276 	/* And only enough for HT20 */
    277 	ret = band_estimate_vht_rx_rate(band, vhtc, vhto, htc, hto,
    278 					-82, &data_rate);
    279 	assert(ret == 0);
    280 	assert(data_rate == 14444440);
    281 
    282 	ret = band_estimate_vht_rx_rate(band, vhtc, vhto, htc, hto,
    283 					-83, &data_rate);
    284 	assert(ret < 0);
    285 
    286 	band_free(band);
    287 }
    288 
    289 struct he_test_data {
    290 	enum band_freq freq;
    291 	int32_t rssi;
    292 	uint64_t expected_rate;
    293 	int expected_return;
    294 	/* Own capabilities */
    295 	struct band_he_capabilities capabilities;
    296 	/* Peer HE Capabilities IE */
    297 	uint8_t he_capabilities[31];
    298 
    299 };
    300 
    301 /* IWD doesn't look at this */
    302 #define HE_MAC_CAPA 0, 0, 0, 0, 0, 0
    303 /* IWD only cares about the width set byte */
    304 #define HE_PHY_CAPA(wset) wset, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
    305 
    306 #define MCS7		0
    307 #define MCS9		1
    308 #define MCS11		2
    309 #define MCS_UNSUP	0xff, 0xff
    310 /* A readable macro for defining MCS sets */
    311 #define HE_MCS_SET(mcs, nss) \
    312 	(nss >= 1 ? mcs << 0 : 3 << 0) | \
    313 	(nss >= 2 ? mcs << 2 : 3 << 2) | \
    314 	(nss >= 3 ? mcs << 4 : 3 << 4) | \
    315 	(nss >= 4 ? mcs << 6 : 3 << 6),  \
    316 	(nss >= 5 ? mcs << 0 : 3 << 0) | \
    317 	(nss >= 6 ? mcs << 2 : 3 << 2) | \
    318 	(nss >= 7 ? mcs << 4 : 3 << 4) | \
    319 	(nss >= 8 ? mcs << 6 : 3 << 6)
    320 
    321 /* 2.4GHz, 20MHz, MCS 7, NSS 1 */
    322 const struct he_test_data he_test_2_4_20mhz_mcs_7_nss_1 = {
    323 	.freq = BAND_FREQ_2_4_GHZ,
    324 	.rssi = -20,
    325 	.expected_rate = 86000000ULL,
    326 	.capabilities = {
    327 		.he_mcs_set = { HE_MCS_SET(MCS7, 1), MCS_UNSUP },
    328 		.he_phy_capa = { HE_PHY_CAPA(0x00) },
    329 		.iftypes = 1 << NETDEV_IFTYPE_STATION,
    330 	},
    331 	.he_capabilities = {
    332 		22, IE_TYPE_HE_CAPABILITIES - 256, HE_MAC_CAPA,
    333 		HE_PHY_CAPA(0x00), MCS_UNSUP, HE_MCS_SET(MCS7, 1),
    334 	},
    335 };
    336 
    337 /* 2.4GHz, 40MHz, MCS 7, NSS 1 */
    338 const struct he_test_data he_test_2_4_40mhz_mcs_7_nss_1 = {
    339 	.freq = BAND_FREQ_2_4_GHZ,
    340 	.rssi = -20,
    341 	.expected_rate = 172000000ULL,
    342 	.capabilities = {
    343 		.he_mcs_set = { HE_MCS_SET(MCS7, 1), MCS_UNSUP },
    344 		.he_phy_capa = { HE_PHY_CAPA(0x02) },
    345 		.iftypes = 1 << NETDEV_IFTYPE_STATION,
    346 	},
    347 	.he_capabilities = {
    348 		22, IE_TYPE_HE_CAPABILITIES - 256, HE_MAC_CAPA,
    349 		HE_PHY_CAPA(0x02), MCS_UNSUP, HE_MCS_SET(MCS7, 1),
    350 	},
    351 };
    352 
    353 /* 5GHz, 20MHz, MCS 7, NSS 1 */
    354 const struct he_test_data he_test_5_20mhz_mcs_7_nss_1 = {
    355 	.freq = BAND_FREQ_5_GHZ,
    356 	.rssi = -20,
    357 	.expected_rate = 86000000ULL,
    358 	.capabilities = {
    359 		.he_mcs_set = { HE_MCS_SET(MCS7, 1), MCS_UNSUP },
    360 		.he_phy_capa = { HE_PHY_CAPA(0x00) },
    361 		.iftypes = 1 << NETDEV_IFTYPE_STATION,
    362 	},
    363 	.he_capabilities = {
    364 		22, IE_TYPE_HE_CAPABILITIES - 256, HE_MAC_CAPA,
    365 		HE_PHY_CAPA(0x00), MCS_UNSUP, HE_MCS_SET(MCS7, 1)
    366 	},
    367 };
    368 
    369 /* 5GHz, 80MHz, MCS 7, NSS 1 */
    370 const struct he_test_data he_test_5_80mhz_mcs_7_nss_1 = {
    371 	.freq = BAND_FREQ_5_GHZ,
    372 	.rssi = -20,
    373 	.expected_rate = 360300000ULL,
    374 	.capabilities = {
    375 		.he_mcs_set = { HE_MCS_SET(MCS7, 1), MCS_UNSUP },
    376 		.he_phy_capa = { HE_PHY_CAPA(0x04) },
    377 		.iftypes = 1 << NETDEV_IFTYPE_STATION,
    378 	},
    379 	.he_capabilities = {
    380 		22, IE_TYPE_HE_CAPABILITIES - 256, HE_MAC_CAPA,
    381 		HE_PHY_CAPA(0x04), MCS_UNSUP, HE_MCS_SET(MCS7, 1)
    382 	},
    383 };
    384 
    385 /* 5GHz, 160MHz, MCS 7, NSS 1 */
    386 const struct he_test_data he_test_5_160mhz_mcs_7_nss_1 = {
    387 	.freq = BAND_FREQ_5_GHZ,
    388 	.rssi = -20,
    389 	.expected_rate = 720600000ULL,
    390 	.capabilities = {
    391 		.he_mcs_set = { HE_MCS_SET(MCS7, 1), MCS_UNSUP,
    392 				HE_MCS_SET(MCS7, 1), MCS_UNSUP },
    393 		.he_phy_capa = { HE_PHY_CAPA(0x0c) },
    394 		.iftypes = 1 << NETDEV_IFTYPE_STATION,
    395 	},
    396 	.he_capabilities = {
    397 		26, IE_TYPE_HE_CAPABILITIES - 256, HE_MAC_CAPA,
    398 		HE_PHY_CAPA(0x0c), MCS_UNSUP, HE_MCS_SET(MCS7, 1),
    399 				MCS_UNSUP, HE_MCS_SET(MCS7, 1)
    400 	},
    401 };
    402 
    403 /* 5GHz, 160/80+80MHz, MCS 7, NSS 1 */
    404 const struct he_test_data he_test_5_160_80_P_80_mhz_mcs_7_nss_1 = {
    405 	.freq = BAND_FREQ_5_GHZ,
    406 	.rssi = -20,
    407 	.expected_rate = 720600000ULL,
    408 	.capabilities = {
    409 		.he_mcs_set = { HE_MCS_SET(MCS7, 1), MCS_UNSUP,
    410 				HE_MCS_SET(MCS7, 1), MCS_UNSUP,
    411 				HE_MCS_SET(MCS7, 1), MCS_UNSUP },
    412 		.he_phy_capa = { HE_PHY_CAPA(0x1c) },
    413 		.iftypes = 1 << NETDEV_IFTYPE_STATION,
    414 	},
    415 	.he_capabilities = {
    416 		30, IE_TYPE_HE_CAPABILITIES - 256, HE_MAC_CAPA,
    417 		HE_PHY_CAPA(0x1c), MCS_UNSUP, HE_MCS_SET(MCS7, 1),
    418 				MCS_UNSUP, HE_MCS_SET(MCS7, 1),
    419 				MCS_UNSUP, HE_MCS_SET(MCS7, 1)
    420 	},
    421 };
    422 
    423 /* 5GHz, max data rate */
    424 const struct he_test_data he_test_5_max_data_rate = {
    425 	.freq = BAND_FREQ_5_GHZ,
    426 	.rssi = -20,
    427 	.expected_rate = 1201000000ULL * 8ULL,
    428 	.capabilities = {
    429 		.he_mcs_set = { HE_MCS_SET(MCS11, 8), MCS_UNSUP,
    430 				HE_MCS_SET(MCS11, 8), MCS_UNSUP,
    431 				HE_MCS_SET(MCS11, 8), MCS_UNSUP },
    432 		.he_phy_capa = { HE_PHY_CAPA(0x1c) },
    433 		.iftypes = 1 << NETDEV_IFTYPE_STATION,
    434 	},
    435 	.he_capabilities = {
    436 		30, IE_TYPE_HE_CAPABILITIES - 256, HE_MAC_CAPA,
    437 		HE_PHY_CAPA(0x1c), MCS_UNSUP, HE_MCS_SET(MCS11, 8),
    438 				MCS_UNSUP, HE_MCS_SET(MCS11, 8),
    439 				MCS_UNSUP, HE_MCS_SET(MCS11, 8)
    440 	},
    441 };
    442 
    443 const struct he_test_data he_all_mcs_unsupported = {
    444 	.freq = BAND_FREQ_5_GHZ,
    445 	.rssi = -20,
    446 	.expected_rate = 1201000000ULL * 8ULL,
    447 	.expected_return = -ENETUNREACH,
    448 	.capabilities = {
    449 		.he_mcs_set = { MCS_UNSUP, MCS_UNSUP,
    450 				MCS_UNSUP, MCS_UNSUP,
    451 				MCS_UNSUP, MCS_UNSUP },
    452 		.he_phy_capa = { HE_PHY_CAPA(0x1c) },
    453 		.iftypes = 1 << NETDEV_IFTYPE_STATION,
    454 	},
    455 	.he_capabilities = {
    456 		30, IE_TYPE_HE_CAPABILITIES - 256, HE_MAC_CAPA,
    457 		HE_PHY_CAPA(0x1c), MCS_UNSUP, MCS_UNSUP,
    458 				MCS_UNSUP, MCS_UNSUP,
    459 				MCS_UNSUP, MCS_UNSUP
    460 	},
    461 };
    462 
    463 /* 5GHz, max data rate, low-rssi */
    464 const struct he_test_data he_test_5_low_rssi = {
    465 	.freq = BAND_FREQ_5_GHZ,
    466 	.rssi = -80, /* Should force 20MHz/MCS0 width to be used */
    467 	.expected_rate = 8600000ULL * 8ULL,
    468 	.capabilities = {
    469 		.he_mcs_set = { HE_MCS_SET(MCS11, 8), MCS_UNSUP,
    470 				HE_MCS_SET(MCS11, 8), MCS_UNSUP,
    471 				HE_MCS_SET(MCS11, 8), MCS_UNSUP },
    472 		.he_phy_capa = { HE_PHY_CAPA(0x1c) },
    473 		.iftypes = 1 << NETDEV_IFTYPE_STATION,
    474 	},
    475 	.he_capabilities = {
    476 		30, IE_TYPE_HE_CAPABILITIES - 256, HE_MAC_CAPA,
    477 		HE_PHY_CAPA(0x1c), MCS_UNSUP, HE_MCS_SET(MCS11, 8),
    478 				MCS_UNSUP, HE_MCS_SET(MCS11, 8),
    479 				MCS_UNSUP, HE_MCS_SET(MCS11, 8)
    480 	},
    481 };
    482 
    483 static void band_test_he(const void *data)
    484 {
    485 	const struct he_test_data *he_data = data;
    486 	struct band *band;
    487 	uint64_t rate = 0;
    488 	int ret;
    489 
    490 	band = new_band();
    491 	band->freq = he_data->freq;
    492 	band->he_capabilities = l_queue_new();
    493 
    494 	l_queue_push_tail(band->he_capabilities,
    495 				(void*)&(he_data->capabilities));
    496 
    497 	assert(ie_validate_he_capabilities(he_data->he_capabilities + 2,
    498 					he_data->he_capabilities[0]));
    499 
    500 	ret = band_estimate_he_rx_rate(band, he_data->he_capabilities + 2,
    501 					he_data->rssi, &rate);
    502 	assert(ret == he_data->expected_return);
    503 
    504 	if (ret == 0)
    505 		assert(rate == he_data->expected_rate);
    506 
    507 	l_queue_destroy(band->he_capabilities, NULL);
    508 	l_free(band);
    509 }
    510 
    511 struct oci2freq_data {
    512 	unsigned int op;
    513 	unsigned int chan;
    514 	int expected_freq;
    515 };
    516 
    517 static const struct oci2freq_data oci2freq_data_1 = { 129, 100, 5500 };
    518 static const struct oci2freq_data oci2freq_data_2 = { 129, 108, 5540 };
    519 static const struct oci2freq_data oci2freq_data_3 = { 129, 106, -EINVAL };
    520 static const struct oci2freq_data oci2freq_data_4 = { 81, 1, 2412 };
    521 static const struct oci2freq_data oci2freq_data_5 = { 82, 1, -EINVAL };
    522 static const struct oci2freq_data oci2freq_data_6 = { 82, 14, 2484 };
    523 static const struct oci2freq_data oci2freq_data_7 = { 88, 0, -ENOENT };
    524 static const struct oci2freq_data oci2freq_data_8 = { 128, 161, 5805 };
    525 
    526 static void test_oci2freq(const void *data)
    527 {
    528 	const struct oci2freq_data *test = data;
    529 	int r;
    530 
    531 	r = oci_to_frequency(test->op, test->chan);
    532 	assert(r == test->expected_freq);
    533 }
    534 
    535 static const struct band_chandef cd_1 = {
    536 	.frequency = 5540,
    537 	.channel_width = BAND_CHANDEF_WIDTH_160,
    538 	.center1_frequency = 5570,
    539 };
    540 
    541 static const struct band_chandef cd_2 = {
    542 	.frequency = 5180,
    543 	.channel_width = BAND_CHANDEF_WIDTH_80P80,
    544 	.center1_frequency = 5210,
    545 	.center2_frequency = 5775,
    546 };
    547 
    548 static const struct band_chandef cd_3 = {
    549 	.frequency = 2437,
    550 	.channel_width = BAND_CHANDEF_WIDTH_20NOHT,
    551 	.center1_frequency = 2437,
    552 };
    553 
    554 static const struct band_chandef cd_4 = {
    555 	.frequency = 2437,
    556 	.channel_width = BAND_CHANDEF_WIDTH_40,
    557 	.center1_frequency = 2427,
    558 };
    559 
    560 static const struct band_chandef cd_5 = {
    561 	.frequency = 6235,
    562 	.channel_width = BAND_CHANDEF_WIDTH_20,
    563 };
    564 
    565 static const struct band_chandef cd_6 = {
    566 	.frequency = 6235,
    567 	.channel_width =  BAND_CHANDEF_WIDTH_40,
    568 };
    569 
    570 static const struct band_chandef cd_7 = {
    571 	.frequency = 6235,
    572 	.channel_width =  BAND_CHANDEF_WIDTH_80,
    573 };
    574 
    575 static const struct band_chandef cd_8 = {
    576 	.frequency = 6235,
    577 	.channel_width =  BAND_CHANDEF_WIDTH_160,
    578 };
    579 
    580 static const struct band_chandef cd_9 = {
    581 	.frequency = 6235,
    582 	.channel_width =  BAND_CHANDEF_WIDTH_80P80,
    583 	.center1_frequency = 6145,
    584 	.center2_frequency = 6225,
    585 };
    586 
    587 struct oci_data {
    588 	const struct band_chandef *cd;
    589 	uint8_t oci[3];
    590 	int expected_verify_error;
    591 };
    592 
    593 static const struct oci_data oci_data_1 = { &cd_1, { 129, 108, 0 } };
    594 static const struct oci_data oci_data_2 = { &cd_2, { 130, 36, 155 } };
    595 static const struct oci_data oci_data_3 = { &cd_3, { 81, 6, 0 } };
    596 static const struct oci_data oci_data_4 = { &cd_4, { 84, 6, 0 } };
    597 static const struct oci_data oci_data_5 = { &cd_5, { 131, 57, 0 } };
    598 static const struct oci_data oci_data_6 = { &cd_6, { 132, 57, 0 } };
    599 static const struct oci_data oci_data_7 = { &cd_7, { 133, 57, 0 } };
    600 static const struct oci_data oci_data_8 = { &cd_8, { 134, 57, 0 } };
    601 static const struct oci_data oci_data_9 = { &cd_9, { 135, 57, 55 } };
    602 
    603 static const struct oci_data oci_err_1 = { &cd_1, { 129, 36, 0 }, -EPERM };
    604 static const struct oci_data oci_err_2 = { &cd_1, { 121, 108, 0 }, -EPERM };
    605 static const struct oci_data oci_err_3 = { &cd_1, { 130, 36, 155 }, -EPERM };
    606 static const struct oci_data oci_err_4 = { &cd_3, { 81, 5 }, -EPERM };
    607 static const struct oci_data oci_err_5 = { &cd_3, { 80, 1 }, -ENOENT };
    608 static const struct oci_data oci_err_6 = { &cd_3, { 81, 15 }, -EINVAL };
    609 static const struct oci_data oci_err_7 = { &cd_4, { 84, 5 }, -EPERM };
    610 static const struct oci_data oci_err_8 = { &cd_4, { 83, 6 }, -EPERM };
    611 
    612 static void test_oci_verify(const void *data)
    613 {
    614 	const struct oci_data *test = data;
    615 	int r;
    616 
    617 	r = oci_verify(test->oci, test->cd);
    618 	assert(r == test->expected_verify_error);
    619 }
    620 
    621 static void test_oci_from_chandef(const void *data)
    622 {
    623 	const struct oci_data *test = data;
    624 	uint8_t oci[3];
    625 	int r;
    626 
    627 	r = oci_from_chandef(test->cd, oci);
    628 	assert(!r);
    629 
    630 	assert(!memcmp(oci, test->oci, sizeof(oci)));
    631 }
    632 
    633 static void test_6ghz_channels(const void *data)
    634 {
    635 	unsigned int i;
    636 
    637 	/* Test all channels for 6GHz */
    638 	for (i = 1; i <= 233; i += 4)
    639 		assert(band_channel_to_freq(i, BAND_FREQ_6_GHZ) != 0);
    640 }
    641 
    642 static void test_6ghz_freqs(const void *data)
    643 {
    644 	uint32_t i;
    645 	enum band_freq band;
    646 
    647 	for (i = 5955; i <= 7115; i += 20) {
    648 		assert(band_freq_to_channel(i, &band) != 0);
    649 		assert(band == BAND_FREQ_6_GHZ);
    650 	}
    651 }
    652 
    653 static void test_conversions(const void *data)
    654 {
    655 	/*
    656 	 * Test a few invalid channels/frequencies that appear valid but are
    657 	 * not in the E-4 table. The checks in band.c seem to cover 2.4GHz and
    658 	 * 6GHz very well since there are no gaps, but the 5GHz band has some
    659 	 * segmentation.
    660 	 */
    661 
    662 	/* Gap in 5GHz channels between 68 and 96 */
    663 	assert(!band_channel_to_freq(72, BAND_FREQ_5_GHZ));
    664 	assert(!band_freq_to_channel(5360, NULL));
    665 
    666 	/* Invalid channel using 4000mhz starting frequency */
    667 	assert(!band_channel_to_freq(183, BAND_FREQ_5_GHZ));
    668 	assert(!band_freq_to_channel(4915, NULL));
    669 
    670 	assert(!band_channel_to_freq(192, BAND_FREQ_5_GHZ));
    671 }
    672 
    673 static void test_conversion_fallback(const void *data)
    674 {
    675 	enum band_freq band;
    676 	const uint8_t cc[] = {'E', 'S', 0x04};
    677 
    678 	/*
    679 	 * Without a fallback, this would fail. There is no operclass 3 in the
    680 	 * global operating table (E-4)
    681 	 */
    682 	band = band_oper_class_to_band(cc, 3);
    683 	assert(band == BAND_FREQ_5_GHZ);
    684 }
    685 
    686 static void test_unsupported_freqs(const void *data)
    687 {
    688 	/*
    689 	 * These are frequencies that were seen advertised by some drivers
    690 	 * but that don't match any global operating classes IWD has. They may
    691 	 * be valid, but IWD should not parse them correctly without added
    692 	 * support in band.c.
    693 	 */
    694 	uint32_t unsupported[] = {
    695 		5920, 5940, 5960, 5980, 6000, 6020, 6040, 6060, 6080,
    696 	};
    697 	unsigned int i;
    698 
    699 	for (i = 0; i < L_ARRAY_SIZE(unsupported); i++) {
    700 		uint8_t channel = band_freq_to_channel(unsupported[i], NULL);
    701 
    702 		assert(!channel);
    703 	}
    704 }
    705 
    706 int main(int argc, char *argv[])
    707 {
    708 	l_test_init(&argc, &argv);
    709 
    710 	l_test_add("/band/non-HT/test1", band_test_nonht_1, NULL);
    711 
    712 	l_test_add("/band/HT/test1", band_test_ht_1, NULL);
    713 
    714 	l_test_add("/band/VHT/test1", band_test_vht_1, NULL);
    715 
    716 	l_test_add("/band/HE/test/2.4GHz/20MHz/MCS7/NSS1", band_test_he,
    717 					&he_test_2_4_20mhz_mcs_7_nss_1);
    718 	l_test_add("/band/HE/test/2.4GHz/40MHz/MCS7/NSS1", band_test_he,
    719 					&he_test_2_4_40mhz_mcs_7_nss_1);
    720 	l_test_add("/band/HE/test/5GHz/20MHz/MCS7/NSS1", band_test_he,
    721 					&he_test_5_20mhz_mcs_7_nss_1);
    722 	l_test_add("/band/HE/test/5GHz/80MHz/MCS7/NSS1", band_test_he,
    723 					&he_test_5_80mhz_mcs_7_nss_1);
    724 	l_test_add("/band/HE/test/5GHz/160MHz/MCS7/NSS1", band_test_he,
    725 					&he_test_5_160mhz_mcs_7_nss_1);
    726 	l_test_add("/band/HE/test/5GHz/160/80+80MHz/MCS7/NSS1", band_test_he,
    727 					&he_test_5_160_80_P_80_mhz_mcs_7_nss_1);
    728 	l_test_add("/band/HE/test/5GHz/max data rate", band_test_he,
    729 					&he_test_5_max_data_rate);
    730 	l_test_add("/band/HE/test/all MCS unsupported", band_test_he,
    731 					&he_all_mcs_unsupported);
    732 	l_test_add("/band/HE/test/low RSSI", band_test_he,
    733 					&he_test_5_low_rssi);
    734 
    735 	l_test_add("/band/oci2freq 1", test_oci2freq, &oci2freq_data_1);
    736 	l_test_add("/band/oci2freq 2", test_oci2freq, &oci2freq_data_2);
    737 	l_test_add("/band/oci2freq 3", test_oci2freq, &oci2freq_data_3);
    738 	l_test_add("/band/oci2freq 4", test_oci2freq, &oci2freq_data_4);
    739 	l_test_add("/band/oci2freq 5", test_oci2freq, &oci2freq_data_5);
    740 	l_test_add("/band/oci2freq 6", test_oci2freq, &oci2freq_data_6);
    741 	l_test_add("/band/oci2freq 7", test_oci2freq, &oci2freq_data_7);
    742 	l_test_add("/band/oci2freq 8", test_oci2freq, &oci2freq_data_8);
    743 
    744 	l_test_add("/band/oci/verify 1", test_oci_verify, &oci_data_1);
    745 	l_test_add("/band/oci/verify 2", test_oci_verify, &oci_data_2);
    746 	l_test_add("/band/oci/verify 3", test_oci_verify, &oci_data_3);
    747 	l_test_add("/band/oci/verify 4", test_oci_verify, &oci_data_4);
    748 	l_test_add("/band/oci/verify 5", test_oci_verify, &oci_data_5);
    749 	l_test_add("/band/oci/verify 6", test_oci_verify, &oci_data_6);
    750 	l_test_add("/band/oci/verify 7", test_oci_verify, &oci_data_7);
    751 	l_test_add("/band/oci/verify 8", test_oci_verify, &oci_data_8);
    752 	l_test_add("/band/oci/verify 9", test_oci_verify, &oci_data_9);
    753 
    754 	l_test_add("/band/oci/noverify 1", test_oci_verify, &oci_err_1);
    755 	l_test_add("/band/oci/noverify 2", test_oci_verify, &oci_err_2);
    756 	l_test_add("/band/oci/noverify 3", test_oci_verify, &oci_err_3);
    757 	l_test_add("/band/oci/noverify 4", test_oci_verify, &oci_err_4);
    758 	l_test_add("/band/oci/noverify 5", test_oci_verify, &oci_err_5);
    759 	l_test_add("/band/oci/noverify 6", test_oci_verify, &oci_err_6);
    760 	l_test_add("/band/oci/noverify 7", test_oci_verify, &oci_err_7);
    761 	l_test_add("/band/oci/noverify 8", test_oci_verify, &oci_err_8);
    762 
    763 	l_test_add("/band/oci/chandef 1", test_oci_from_chandef, &oci_data_1);
    764 	l_test_add("/band/oci/chandef 2", test_oci_from_chandef, &oci_data_2);
    765 	l_test_add("/band/oci/chandef 3", test_oci_from_chandef, &oci_data_3);
    766 	l_test_add("/band/oci/chandef 4", test_oci_from_chandef, &oci_data_4);
    767 
    768 	l_test_add("/band/6ghz/channels", test_6ghz_channels, NULL);
    769 	l_test_add("/band/6ghz/freq", test_6ghz_freqs, NULL);
    770 
    771 	l_test_add("/band/conversions", test_conversions, NULL);
    772 	l_test_add("/band/conversion fallback", test_conversion_fallback, NULL);
    773 	l_test_add("/band/unsupported freqs", test_unsupported_freqs, NULL);
    774 
    775 	return l_test_run();
    776 }