mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2025-02-01 14:14:23 +01:00
scan: Implement scan_oper_class_to_band
This function takes an Operating Channel and a Country String to convert it into a band. Using scan_oper_class_to_band and scan_channel_to_freq, an Operating Channel, a Country String and a Channel Number together can be converted into an actual frequency. EU and US country codes based on wpa_supplicant's tables.
This commit is contained in:
parent
859dcf0d59
commit
92bc1d6896
104
src/scan.c
104
src/scan.c
@ -1113,6 +1113,110 @@ uint32_t scan_channel_to_freq(uint8_t channel, enum scan_band band)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char *const oper_class_us_codes[] = {
|
||||||
|
"US", "CA"
|
||||||
|
};
|
||||||
|
|
||||||
|
static const char *const oper_class_eu_codes[] = {
|
||||||
|
"AL", "AM", "AT", "AZ", "BA", "BE", "BG", "BY", "CH", "CY", "CZ", "DE",
|
||||||
|
"DK", "EE", "EL", "ES", "FI", "FR", "GE", "HR", "HU", "IE", "IS", "IT",
|
||||||
|
"LI", "LT", "LU", "LV", "MD", "ME", "MK", "MT", "NL", "NO", "PL", "PT",
|
||||||
|
"RO", "RS", "RU", "SE", "SI", "SK", "TR", "UA", "UK"
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Annex E, table E-1 */
|
||||||
|
static const uint8_t oper_class_us_to_global[] = {
|
||||||
|
[1] = 115, [2] = 118, [3] = 124, [4] = 121,
|
||||||
|
[5] = 125, [6] = 103, [7] = 103, [8] = 102,
|
||||||
|
[9] = 102, [10] = 101, [11] = 101, [12] = 81,
|
||||||
|
[13] = 94, [14] = 95, [15] = 96, [22] = 116,
|
||||||
|
[23] = 119, [24] = 122, [25] = 126, [26] = 126,
|
||||||
|
[27] = 117, [28] = 120, [29] = 123, [30] = 127,
|
||||||
|
[31] = 127, [32] = 83, [33] = 84
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Annex E, table E-2 */
|
||||||
|
static const uint8_t oper_class_eu_to_global[] = {
|
||||||
|
[1] = 115, [2] = 118, [3] = 121, [4] = 81,
|
||||||
|
[5] = 116, [6] = 119, [7] = 122, [8] = 117,
|
||||||
|
[9] = 120, [10] = 123, [11] = 83, [12] = 84,
|
||||||
|
[17] = 125
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Annex E, table E-3 */
|
||||||
|
static const uint8_t oper_class_jp_to_global[] = {
|
||||||
|
[1] = 115, [2] = 112, [3] = 112, [4] = 112,
|
||||||
|
[5] = 112, [6] = 112, [7] = 109, [8] = 109,
|
||||||
|
[9] = 109, [10] = 109, [11] = 109, [12] = 113,
|
||||||
|
[13] = 113, [14] = 113, [15] = 113, [16] = 110,
|
||||||
|
[17] = 110, [18] = 110, [19] = 110, [20] = 110,
|
||||||
|
[21] = 114, [22] = 114, [23] = 114, [24] = 114,
|
||||||
|
[25] = 111, [26] = 111, [27] = 111, [28] = 111,
|
||||||
|
[29] = 111, [30] = 81, [31] = 82, [32] = 118,
|
||||||
|
[33] = 118, [34] = 121, [35] = 121, [36] = 116,
|
||||||
|
[37] = 119, [38] = 119, [39] = 122, [40] = 122,
|
||||||
|
[41] = 117, [42] = 120, [43] = 120, [44] = 123,
|
||||||
|
[45] = 123, [46] = 104, [47] = 104, [48] = 104,
|
||||||
|
[49] = 104, [50] = 104, [51] = 105, [52] = 105,
|
||||||
|
[53] = 105, [54] = 105, [55] = 105, [56] = 83,
|
||||||
|
[57] = 84, [58] = 121
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Annex E, table E-4 (only 2.4GHz and 4.9 / 5GHz bands) */
|
||||||
|
static const enum scan_band oper_class_to_band_global[] = {
|
||||||
|
[81 ... 84] = SCAN_BAND_2_4_GHZ,
|
||||||
|
[104 ... 127] = SCAN_BAND_5_GHZ,
|
||||||
|
};
|
||||||
|
|
||||||
|
enum scan_band scan_oper_class_to_band(const uint8_t *country,
|
||||||
|
uint8_t oper_class)
|
||||||
|
{
|
||||||
|
unsigned int i;
|
||||||
|
int table = 0;
|
||||||
|
|
||||||
|
if (country && country[2] >= 1 && country[2] <= 4)
|
||||||
|
table = country[2];
|
||||||
|
else if (country) {
|
||||||
|
for (i = 0; i < L_ARRAY_SIZE(oper_class_us_codes); i++)
|
||||||
|
if (!memcmp(oper_class_us_codes[i], country, 2)) {
|
||||||
|
/* Use table E-1 */
|
||||||
|
table = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < L_ARRAY_SIZE(oper_class_eu_codes); i++)
|
||||||
|
if (!memcmp(oper_class_eu_codes[i], country, 2)) {
|
||||||
|
/* Use table E-2 */
|
||||||
|
table = 2;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!memcmp("JP", country, 2))
|
||||||
|
/* Use table E-3 */
|
||||||
|
table = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (table) {
|
||||||
|
case 1:
|
||||||
|
if (oper_class < L_ARRAY_SIZE(oper_class_us_to_global))
|
||||||
|
oper_class = oper_class_us_to_global[oper_class];
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
if (oper_class < L_ARRAY_SIZE(oper_class_eu_to_global))
|
||||||
|
oper_class = oper_class_eu_to_global[oper_class];
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
if (oper_class < L_ARRAY_SIZE(oper_class_jp_to_global))
|
||||||
|
oper_class = oper_class_jp_to_global[oper_class];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (oper_class < L_ARRAY_SIZE(oper_class_to_band_global))
|
||||||
|
return oper_class_to_band_global[oper_class];
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
struct scan_freq_set {
|
struct scan_freq_set {
|
||||||
uint16_t channels_2ghz;
|
uint16_t channels_2ghz;
|
||||||
struct l_uintset *channels_5ghz;
|
struct l_uintset *channels_5ghz;
|
||||||
|
@ -88,6 +88,8 @@ void bss_get_supported_ciphers(struct scan_bss *bss,
|
|||||||
|
|
||||||
uint8_t scan_freq_to_channel(uint32_t freq, enum scan_band *out_band);
|
uint8_t scan_freq_to_channel(uint32_t freq, enum scan_band *out_band);
|
||||||
uint32_t scan_channel_to_freq(uint8_t channel, enum scan_band band);
|
uint32_t scan_channel_to_freq(uint8_t channel, enum scan_band band);
|
||||||
|
enum scan_band scan_oper_class_to_band(const uint8_t *country,
|
||||||
|
uint8_t oper_class);
|
||||||
|
|
||||||
struct scan_freq_set *scan_freq_set_new(void);
|
struct scan_freq_set *scan_freq_set_new(void);
|
||||||
void scan_freq_set_free(struct scan_freq_set *freqs);
|
void scan_freq_set_free(struct scan_freq_set *freqs);
|
||||||
|
Loading…
Reference in New Issue
Block a user