Skip to content

Instantly share code, notes, and snippets.

@BigNerd95
Last active March 1, 2023 09:05
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save BigNerd95/0be0a5b52a16524a78fc768f0d208a74 to your computer and use it in GitHub Desktop.
Save BigNerd95/0be0a5b52a16524a78fc768f0d208a74 to your computer and use it in GitHub Desktop.
Atheros Country Code ART bypass passing a custom Country Name when loading the driver (e.g.: insmod ath cn=AU)
char *user_country_name = ""; // [MOD]
module_param_named(cn, user_country_name, charp, S_IRUGO); // [MOD]
MODULE_PARM_DESC(cn, "Country Name"); // [MOD]
static int __ath_regd_init(struct ath_regulatory *reg)
{
struct country_code_to_enum_rd *country = NULL;
u16 regdmn;
if (!reg)
return -EINVAL;
ath_regd_sanitize(reg);
printk(KERN_DEBUG "ath: EEPROM regdomain: 0x%0x\n", reg->current_rd);
if (!ath_regd_is_eeprom_valid(reg)) {
pr_err("Invalid EEPROM contents\n");
return -EINVAL;
}
regdmn = ath_regd_get_eepromRD(reg);
reg->country_code = ath_regd_find_country_by_name(user_country_name); // [MOD]
if (reg->country_code != (u16) -1) // [MOD]
printk(KERN_DEBUG "ath: User Override Country Code\n"); // [MOD]
else // [MOD]
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;
}
// [...]
@BigNerd95
Copy link
Author

BigNerd95 commented Oct 9, 2017

LEDE instruction:

  1. Clone LEDE project
    git clone https://github.com/lede-project/source.git
    cd source

  2. Build for your target
    make menuconfig (select your target)
    make package/kernel/mac80211/compile

  3. Patch the driver with my diff
    You have to edit __ath_regd_init function in this file:
    build_dir/target-[ARCH]/linux-ar71xx_generic/backports-[VER]/drivers/net/wireless/ath/regd.c
    (Add lines with // [MOD] comment)

  4. Build and flash the firmware
    Build the firmware
    make -j9
    (Where 9 is your cpu's threads number + 1)
    Then flash the router
    On PC: nc -l -p 1234 -q 0 < bin/targets/ar71xx/generic/lede-ar71xx-generic-[MODEL]-squashfs-sysupgrade.bin
    On router: nc 192.168.1.X 1234 > /tmp/fw.bin && sysupgrade /tmp/fw.bin

  5. Add driver parameter
    After the router reboot, create the file /etc/modules.d/ath
    echo "ath cn=AU" > /etc/modules.d/ath
    So when LEDE starts up, the ath module will be loaded with cn (Country Name) parameter.

  6. Check the Mod
    reboot the router and check log messages:
    dmesg | grep ath
    You should see

ath: EEPROM regdomain: 0x0
ath: User Override Country Code
ath: doing EEPROM country->regdmn map search
ath: country maps to regdmn code: 0x21
ath: Country alpha2 being used: AU
ath: Regpair used: 0x21
  1. Check Reg Domain
    You can check the reg domain
    iw reg get
    and you should see
global
country AU: DFS-ETSI

phy#0
country AU: DFS-ETSI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment