Commit eac77845 authored by Arunmani Alagarsamy's avatar Arunmani Alagarsamy Committed by Benjamin Cabé
Browse files

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: default avatarArunmani Alagarsamy <arunmani.a@silabs.com>
parent 72a3f7e4
Loading
Loading
Loading
Loading
+0 −53
Original line number Diff line number Diff line
@@ -24,44 +24,6 @@ LOG_MODULE_REGISTER(siwx91x_wifi);

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

typedef struct {
	const char *const *codes;
	size_t num_codes;
	sl_wifi_region_code_t region_code;
} region_map_t;

static const char *const us_codes[] = {
	"AE", "AR", "AS", "BB", "BM", "BR", "BS", "CA", "CO", "CR", "CU", "CX",
	"DM", "DO", "EC", "FM", "GD", "GY", "GU", "HN", "HT", "JM", "KY", "LB",
	"LK", "MH", "MN", "MP", "MO", "MY", "NI", "PA", "PE", "PG", "PH", "PK",
	"PR", "PW", "PY", "SG", "MX", "SV", "TC", "TH", "TT", "US", "UY", "VE",
	"VI", "VN", "VU", "00"
	/* Map "00" (world domain) to US region,
	 * as using the world domain is not recommended
	 */
};
static const char *const eu_codes[] = {
	"AD", "AF", "AI", "AL", "AM", "AN", "AT", "AW", "AU", "AZ", "BA", "BE",
	"BG", "BH", "BL", "BT", "BY", "CH", "CY", "CZ", "DE", "DK", "EE", "ES",
	"FR", "GB", "GE", "GF", "GL", "GP", "GR", "GT", "HK", "HR", "HU", "ID",
	"IE", "IL", "IN", "IR", "IS", "IT", "JO", "KH", "FI", "KN", "KW", "KZ",
	"LC", "LI", "LT", "LU", "LV", "MD", "ME", "MK", "MF", "MT", "MV", "MQ",
	"NL", "NO", "NZ", "OM", "PF", "PL", "PM", "PT", "QA", "RO", "RS", "RU",
	"SA", "SE", "SI", "SK", "SR", "SY", "TR", "TW", "UA", "UZ", "VC", "WF",
	"WS", "YE", "RE", "YT"
};
static const char *const jp_codes[] = {"BD", "BN", "BO", "CL", "BZ", "JP", "NP"};
static const char *const kr_codes[] = {"KR", "KP"};
static const char *const cn_codes[] = {"CN"};

static const region_map_t region_maps[] = {
	{us_codes, ARRAY_SIZE(us_codes), SL_WIFI_REGION_US},
	{eu_codes, ARRAY_SIZE(eu_codes), SL_WIFI_REGION_EU},
	{jp_codes, ARRAY_SIZE(jp_codes), SL_WIFI_REGION_JP},
	{kr_codes, ARRAY_SIZE(kr_codes), SL_WIFI_REGION_KR},
	{cn_codes, ARRAY_SIZE(cn_codes), SL_WIFI_REGION_CN},
};

static int siwx91x_sl_to_z_mode(sl_wifi_interface_t interface)
{
	switch (interface) {
@@ -407,21 +369,6 @@ static int siwx91x_get_version(const struct device *dev, struct wifi_version *pa
	return 0;
}

sl_wifi_region_code_t siwx91x_map_country_code_to_region(const char *country_code)
{
	__ASSERT(country_code, "country_code cannot be NULL");

	ARRAY_FOR_EACH(region_maps, i) {
		for (size_t j = 0; j < region_maps[i].num_codes; j++) {
			if (memcmp(country_code, region_maps[i].codes[j],
			    WIFI_COUNTRY_CODE_LEN) == 0) {
				return region_maps[i].region_code;
			}
		}
	}
	return SL_WIFI_DEFAULT_REGION;
}

static int siwx91x_wifi_reg_domain(const struct device *dev, struct wifi_reg_domain *reg_domain)
{
	sl_wifi_operation_mode_t oper_mode = sli_get_opermode();
+53 −0
Original line number Diff line number Diff line
@@ -32,6 +32,59 @@ BUILD_ASSERT(DT_REG_SIZE(DT_CHOSEN(zephyr_sram)) == KB(195) ||
	     DT_REG_SIZE(DT_CHOSEN(zephyr_sram)) == KB(255) ||
	     DT_REG_SIZE(DT_CHOSEN(zephyr_sram)) == KB(319));

typedef struct {
	const char *const *codes;
	size_t num_codes;
	sl_wifi_region_code_t region_code;
} region_map_t;

static const char *const us_codes[] = {
	"AE", "AR", "AS", "BB", "BM", "BR", "BS", "CA", "CO", "CR", "CU", "CX",
	"DM", "DO", "EC", "FM", "GD", "GY", "GU", "HN", "HT", "JM", "KY", "LB",
	"LK", "MH", "MN", "MP", "MO", "MY", "NI", "PA", "PE", "PG", "PH", "PK",
	"PR", "PW", "PY", "SG", "MX", "SV", "TC", "TH", "TT", "US", "UY", "VE",
	"VI", "VN", "VU", "00"
	/* Map "00" (world domain) to US region,
	 * as using the world domain is not recommended
	 */
};
static const char *const eu_codes[] = {
	"AD", "AF", "AI", "AL", "AM", "AN", "AT", "AW", "AU", "AZ", "BA", "BE",
	"BG", "BH", "BL", "BT", "BY", "CH", "CY", "CZ", "DE", "DK", "EE", "ES",
	"FR", "GB", "GE", "GF", "GL", "GP", "GR", "GT", "HK", "HR", "HU", "ID",
	"IE", "IL", "IN", "IR", "IS", "IT", "JO", "KH", "FI", "KN", "KW", "KZ",
	"LC", "LI", "LT", "LU", "LV", "MD", "ME", "MK", "MF", "MT", "MV", "MQ",
	"NL", "NO", "NZ", "OM", "PF", "PL", "PM", "PT", "QA", "RO", "RS", "RU",
	"SA", "SE", "SI", "SK", "SR", "SY", "TR", "TW", "UA", "UZ", "VC", "WF",
	"WS", "YE", "RE", "YT"
};
static const char *const jp_codes[] = {"BD", "BN", "BO", "CL", "BZ", "JP", "NP"};
static const char *const kr_codes[] = {"KR", "KP"};
static const char *const cn_codes[] = {"CN"};

static const region_map_t region_maps[] = {
	{us_codes, ARRAY_SIZE(us_codes), SL_WIFI_REGION_US},
	{eu_codes, ARRAY_SIZE(eu_codes), SL_WIFI_REGION_EU},
	{jp_codes, ARRAY_SIZE(jp_codes), SL_WIFI_REGION_JP},
	{kr_codes, ARRAY_SIZE(kr_codes), SL_WIFI_REGION_KR},
	{cn_codes, ARRAY_SIZE(cn_codes), SL_WIFI_REGION_CN},
};

sl_wifi_region_code_t siwx91x_map_country_code_to_region(const char *country_code)
{
	__ASSERT(country_code, "country_code cannot be NULL");

	ARRAY_FOR_EACH(region_maps, i) {
		for (size_t j = 0; j < region_maps[i].num_codes; j++) {
			if (memcmp(country_code, region_maps[i].codes[j],
				   WIFI_COUNTRY_CODE_LEN) == 0) {
				return region_maps[i].region_code;
			}
		}
	}
	return SL_WIFI_DEFAULT_REGION;
}

static void siwx91x_apply_sram_config(sl_si91x_boot_configuration_t *boot_config)
{
	/* The size does not match exactly because 1 KB is reserved at the start of the RAM */
+13 −0
Original line number Diff line number Diff line
@@ -24,4 +24,17 @@
 */
int siwx91x_nwp_mode_switch(uint8_t oper_mode, bool hidden_ssid, uint8_t max_num_sta);

/**
 * @brief Map an ISO/IEC 3166-1 alpha-2 country code to a Wi-Fi region code.
 *
 * This function maps a 2-character country code (e.g., "US", "FR", "JP")
 * to the corresponding region code defined in the SDK (sl_wifi_region_code_t).
 * If the country is not explicitly listed, it defaults to the US region.
 *
 * @param[in] country_code  Pointer to a 2-character ISO country code.
 *
 * @return Corresponding sl_wifi_region_code_t value.
 */
sl_wifi_region_code_t siwx91x_map_country_code_to_region(const char *country_code);

#endif