Skip to content

Instantly share code, notes, and snippets.

@ryancdotorg
Created March 23, 2023 15:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryancdotorg/7fd09c561e5cdccb09185fdcd4e7e562 to your computer and use it in GitHub Desktop.
Save ryancdotorg/7fd09c561e5cdccb09185fdcd4e7e562 to your computer and use it in GitHub Desktop.
--- a/drivers/net/wireless/ath/regd.c
+++ b/drivers/net/wireless/ath/regd.c
@@ -23,6 +23,10 @@
#include "regd.h"
#include "regd_common.h"
+static char *default_country_alpha2 = NULL;
+module_param_named(default_country, default_country_alpha2, charp, S_IRUGO);
+MODULE_PARM_DESC(default_country, "Default Country Code (ISO 3166-1 Alpha-2)");
+
static int __ath_regd_init(struct ath_regulatory *reg);
static struct reg_dmn_pair_mapping *ath_get_regpair(int regdmn);
@@ -710,6 +714,61 @@
reg->current_rd = 0x64;
}
+static u16 __ath_country_code(u16 regdmn) {
+ unsigned int uint;
+ u16 ctry_code;
+
+ /* if ATH_USER_REGD is enabled, override the EEPROM setting */
+ if (IS_ENABLED(CPTCFG_ATH_USER_REGD) &&
+ default_country_alpha2 != NULL) {
+ if (default_country_alpha2[0] >= '0' &&
+ default_country_alpha2[0] <= '9') {
+ if (kstrouint(default_country_alpha2, 0, &uint) == 0) {
+ if (uint <= 0xffff)
+ return (u16)uint;
+ }
+ }
+ ctry_code = ath_regd_find_country_by_name(default_country_alpha2);
+ if (ctry_code != (u16) -1) {
+ printk(KERN_DEBUG
+ "ath: EEPROM regdomain overridden by "
+ "default country parameter: %s\n",
+ default_country_alpha2);
+ return ctry_code;
+ } else {
+ printk(KERN_DEBUG
+ "ath: Invalid default country parameter "
+ "%s, falling back to EEPROM settings\n",
+ default_country_alpha2);
+ }
+ }
+
+ if (regdmn == CTRY_DEFAULT) {
+ printk(KERN_DEBUG "ath: EEPROM indicates default "
+ "country code should be used\n");
+ /* if a default country was passed as a module parameter,
+ * try to use that instead of the hardcoded default */
+ if (!IS_ENABLED(CPTCFG_ATH_USER_REGD) &&
+ default_country_alpha2 != NULL) {
+ ctry_code = ath_regd_find_country_by_name(default_country_alpha2);
+ if (ctry_code != (u16) -1) {
+ printk(KERN_DEBUG "ath: Using default country "
+ "parameter: %s\n", default_country_alpha2);
+ return ctry_code;
+ } else {
+ printk(KERN_DEBUG "ath: Invalid default country "
+ "parameter: %s\n", default_country_alpha2);
+ }
+ }
+ printk(KERN_DEBUG "ath: Default country parameter "
+ "not set, using hardcoded value\n");
+ return CTRY_UNITED_STATES;
+ }
+
+ /* map the EEPROM setting to a country code */
+ return ath_regd_get_default_country(regdmn);
+}
+
static int __ath_regd_init(struct ath_regulatory *reg)
{
struct country_code_to_enum_rd *country = NULL;
@@ -728,14 +787,7 @@
}
regdmn = ath_regd_get_eepromRD(reg);
- reg->country_code = ath_regd_get_default_country(regdmn);
-
- if (reg->country_code == CTRY_DEFAULT &&
- regdmn == CTRY_DEFAULT) {
- printk(KERN_DEBUG "ath: EEPROM indicates default "
- "country code should be used\n");
- reg->country_code = CTRY_UNITED_STATES;
- }
+ reg->country_code = __ath_country_code(regdmn);
if (reg->country_code == CTRY_DEFAULT) {
country = NULL;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment