Skip to content

Commit eac7784

Browse files
ArunmaniAlagarsamy2710kartben
authored andcommitted
soc: silabs: siwg917: Relocate country code mapping function
Moved the `siwx91x_map_country_code_to_region()` function from the Wi-Fi driver source file to nwp.c. This change prepares the codebase for upcoming enhancements related to the regulatory domain GET operation. Signed-off-by: Arunmani Alagarsamy <[email protected]>
1 parent 72a3f7e commit eac7784

File tree

3 files changed

+66
-53
lines changed

3 files changed

+66
-53
lines changed

drivers/wifi/siwx91x/siwx91x_wifi.c

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -24,44 +24,6 @@ LOG_MODULE_REGISTER(siwx91x_wifi);
2424

2525
NET_BUF_POOL_FIXED_DEFINE(siwx91x_tx_pool, 1, _NET_ETH_MAX_FRAME_SIZE, 0, NULL);
2626

27-
typedef struct {
28-
const char *const *codes;
29-
size_t num_codes;
30-
sl_wifi_region_code_t region_code;
31-
} region_map_t;
32-
33-
static const char *const us_codes[] = {
34-
"AE", "AR", "AS", "BB", "BM", "BR", "BS", "CA", "CO", "CR", "CU", "CX",
35-
"DM", "DO", "EC", "FM", "GD", "GY", "GU", "HN", "HT", "JM", "KY", "LB",
36-
"LK", "MH", "MN", "MP", "MO", "MY", "NI", "PA", "PE", "PG", "PH", "PK",
37-
"PR", "PW", "PY", "SG", "MX", "SV", "TC", "TH", "TT", "US", "UY", "VE",
38-
"VI", "VN", "VU", "00"
39-
/* Map "00" (world domain) to US region,
40-
* as using the world domain is not recommended
41-
*/
42-
};
43-
static const char *const eu_codes[] = {
44-
"AD", "AF", "AI", "AL", "AM", "AN", "AT", "AW", "AU", "AZ", "BA", "BE",
45-
"BG", "BH", "BL", "BT", "BY", "CH", "CY", "CZ", "DE", "DK", "EE", "ES",
46-
"FR", "GB", "GE", "GF", "GL", "GP", "GR", "GT", "HK", "HR", "HU", "ID",
47-
"IE", "IL", "IN", "IR", "IS", "IT", "JO", "KH", "FI", "KN", "KW", "KZ",
48-
"LC", "LI", "LT", "LU", "LV", "MD", "ME", "MK", "MF", "MT", "MV", "MQ",
49-
"NL", "NO", "NZ", "OM", "PF", "PL", "PM", "PT", "QA", "RO", "RS", "RU",
50-
"SA", "SE", "SI", "SK", "SR", "SY", "TR", "TW", "UA", "UZ", "VC", "WF",
51-
"WS", "YE", "RE", "YT"
52-
};
53-
static const char *const jp_codes[] = {"BD", "BN", "BO", "CL", "BZ", "JP", "NP"};
54-
static const char *const kr_codes[] = {"KR", "KP"};
55-
static const char *const cn_codes[] = {"CN"};
56-
57-
static const region_map_t region_maps[] = {
58-
{us_codes, ARRAY_SIZE(us_codes), SL_WIFI_REGION_US},
59-
{eu_codes, ARRAY_SIZE(eu_codes), SL_WIFI_REGION_EU},
60-
{jp_codes, ARRAY_SIZE(jp_codes), SL_WIFI_REGION_JP},
61-
{kr_codes, ARRAY_SIZE(kr_codes), SL_WIFI_REGION_KR},
62-
{cn_codes, ARRAY_SIZE(cn_codes), SL_WIFI_REGION_CN},
63-
};
64-
6527
static int siwx91x_sl_to_z_mode(sl_wifi_interface_t interface)
6628
{
6729
switch (interface) {
@@ -407,21 +369,6 @@ static int siwx91x_get_version(const struct device *dev, struct wifi_version *pa
407369
return 0;
408370
}
409371

410-
sl_wifi_region_code_t siwx91x_map_country_code_to_region(const char *country_code)
411-
{
412-
__ASSERT(country_code, "country_code cannot be NULL");
413-
414-
ARRAY_FOR_EACH(region_maps, i) {
415-
for (size_t j = 0; j < region_maps[i].num_codes; j++) {
416-
if (memcmp(country_code, region_maps[i].codes[j],
417-
WIFI_COUNTRY_CODE_LEN) == 0) {
418-
return region_maps[i].region_code;
419-
}
420-
}
421-
}
422-
return SL_WIFI_DEFAULT_REGION;
423-
}
424-
425372
static int siwx91x_wifi_reg_domain(const struct device *dev, struct wifi_reg_domain *reg_domain)
426373
{
427374
sl_wifi_operation_mode_t oper_mode = sli_get_opermode();

soc/silabs/silabs_siwx91x/siwg917/nwp.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,59 @@ BUILD_ASSERT(DT_REG_SIZE(DT_CHOSEN(zephyr_sram)) == KB(195) ||
3232
DT_REG_SIZE(DT_CHOSEN(zephyr_sram)) == KB(255) ||
3333
DT_REG_SIZE(DT_CHOSEN(zephyr_sram)) == KB(319));
3434

35+
typedef struct {
36+
const char *const *codes;
37+
size_t num_codes;
38+
sl_wifi_region_code_t region_code;
39+
} region_map_t;
40+
41+
static const char *const us_codes[] = {
42+
"AE", "AR", "AS", "BB", "BM", "BR", "BS", "CA", "CO", "CR", "CU", "CX",
43+
"DM", "DO", "EC", "FM", "GD", "GY", "GU", "HN", "HT", "JM", "KY", "LB",
44+
"LK", "MH", "MN", "MP", "MO", "MY", "NI", "PA", "PE", "PG", "PH", "PK",
45+
"PR", "PW", "PY", "SG", "MX", "SV", "TC", "TH", "TT", "US", "UY", "VE",
46+
"VI", "VN", "VU", "00"
47+
/* Map "00" (world domain) to US region,
48+
* as using the world domain is not recommended
49+
*/
50+
};
51+
static const char *const eu_codes[] = {
52+
"AD", "AF", "AI", "AL", "AM", "AN", "AT", "AW", "AU", "AZ", "BA", "BE",
53+
"BG", "BH", "BL", "BT", "BY", "CH", "CY", "CZ", "DE", "DK", "EE", "ES",
54+
"FR", "GB", "GE", "GF", "GL", "GP", "GR", "GT", "HK", "HR", "HU", "ID",
55+
"IE", "IL", "IN", "IR", "IS", "IT", "JO", "KH", "FI", "KN", "KW", "KZ",
56+
"LC", "LI", "LT", "LU", "LV", "MD", "ME", "MK", "MF", "MT", "MV", "MQ",
57+
"NL", "NO", "NZ", "OM", "PF", "PL", "PM", "PT", "QA", "RO", "RS", "RU",
58+
"SA", "SE", "SI", "SK", "SR", "SY", "TR", "TW", "UA", "UZ", "VC", "WF",
59+
"WS", "YE", "RE", "YT"
60+
};
61+
static const char *const jp_codes[] = {"BD", "BN", "BO", "CL", "BZ", "JP", "NP"};
62+
static const char *const kr_codes[] = {"KR", "KP"};
63+
static const char *const cn_codes[] = {"CN"};
64+
65+
static const region_map_t region_maps[] = {
66+
{us_codes, ARRAY_SIZE(us_codes), SL_WIFI_REGION_US},
67+
{eu_codes, ARRAY_SIZE(eu_codes), SL_WIFI_REGION_EU},
68+
{jp_codes, ARRAY_SIZE(jp_codes), SL_WIFI_REGION_JP},
69+
{kr_codes, ARRAY_SIZE(kr_codes), SL_WIFI_REGION_KR},
70+
{cn_codes, ARRAY_SIZE(cn_codes), SL_WIFI_REGION_CN},
71+
};
72+
73+
sl_wifi_region_code_t siwx91x_map_country_code_to_region(const char *country_code)
74+
{
75+
__ASSERT(country_code, "country_code cannot be NULL");
76+
77+
ARRAY_FOR_EACH(region_maps, i) {
78+
for (size_t j = 0; j < region_maps[i].num_codes; j++) {
79+
if (memcmp(country_code, region_maps[i].codes[j],
80+
WIFI_COUNTRY_CODE_LEN) == 0) {
81+
return region_maps[i].region_code;
82+
}
83+
}
84+
}
85+
return SL_WIFI_DEFAULT_REGION;
86+
}
87+
3588
static void siwx91x_apply_sram_config(sl_si91x_boot_configuration_t *boot_config)
3689
{
3790
/* The size does not match exactly because 1 KB is reserved at the start of the RAM */

soc/silabs/silabs_siwx91x/siwg917/nwp.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,17 @@
2424
*/
2525
int siwx91x_nwp_mode_switch(uint8_t oper_mode, bool hidden_ssid, uint8_t max_num_sta);
2626

27+
/**
28+
* @brief Map an ISO/IEC 3166-1 alpha-2 country code to a Wi-Fi region code.
29+
*
30+
* This function maps a 2-character country code (e.g., "US", "FR", "JP")
31+
* to the corresponding region code defined in the SDK (sl_wifi_region_code_t).
32+
* If the country is not explicitly listed, it defaults to the US region.
33+
*
34+
* @param[in] country_code Pointer to a 2-character ISO country code.
35+
*
36+
* @return Corresponding sl_wifi_region_code_t value.
37+
*/
38+
sl_wifi_region_code_t siwx91x_map_country_code_to_region(const char *country_code);
39+
2740
#endif

0 commit comments

Comments
 (0)