[MOD] WIFI country code fix ( root required )

Search This thread

churchmice

Senior Member
Nov 20, 2010
213
86
[Disclaim]
Mod at your own risk and I don't hold any responsibility for any consequence that may have been caused by this mod.
Remember to make a backup first though I have tested on my pixel.

[Background]

My company uses channel 132,136,140,144 to broadcast 5G wifi, however, the wifi region code on my phone is set to 'CN', so my phone could not even detect the wifi. For a complete list of available wifi channel in each region, please refer to this wiki.

I tried to set wifi_country_code via 'settings put global wifi_country code US' or add 'country=US' in /etc/wifi/wpa_supplicant.conf, but without vain. Then I came across this post https://forum.xda-developers.com/showthread.php?t=2368501, and I decide to hack the setCountryCode function in the wifiservice to force the country to be 'US'. According to the wiki, region 'US' has the most available number of channels.

This post will tell you how you could bypass this restriction on your phone. Your phone shall be rooted, of course.

[Step to step guide]
1) Setup tools, which includes
a) adb
b) jdk
c)baksmali https://bitbucket.org/JesusFreke/smali/downloads

2) Connect your phone and pull all the related files ( actually only wifi-service.odex and boot.oat is needed )
adb pull /system/framework framework
3) Decompile the odex file by using the following command
java -Xms1g -jar baksmali-2.2b4.jar x -d framework/arm64 framework/oat/arm64/wifi-service.odex -o wifi-service
The output goes to wifi-service folder
4) Mod wifi-service/com/android/server/wifi/WifiServiceImpl.smali
Search for 'method public setCountryCode', which is around line 5605, basically we just want to force the country code to "US".
a) Change .register 8 to '.register 9'
This is because we are going to use one more register to hold the static content 'US', aka, your desired country code
The original code uses 8 registers, aka, v0 - v4 for local varialbe, v5-v7 for parameter, they are also alised to p0-p2.
After this change, we can use the register named v5, v6-v8 will be aliased to p0-p2.
b) Add a line under const-string/jumbo v2, "WifiService"
const-string/jumbo v5, "US"
Therefore, v5 hold the content 'US', which is the desired country code.
c) Replace all p1 with v5 inside this method
Originally the country code is passed from outside the call, we just force it to 'US', which is stored in variable v5

5) Repack by the following command
java -Xms1g -jar smali-2.2b4.jar a -o classes.dex wifi-service
jar -cvf wifi-service.jar classes.dex

6) Install on the phone
adb push wifi-service.jar /sdcard/
The following commands shall be executed on the phone and with root prividelege
mount -o rw,remount /system
#Make a backup first
cd system
cp -p framework/oat/arm64/wifi-service.odex framework/oat/arm64/wifi-service.odex.bak
cp -p framework/wifi-service.jar framework/wifi-service.jar.bak
#Install the new file
cp /sdcard/wifi-service.jar /system/framework/
chown root.root framework/wifi-service.jar
chmod 644 framework/wifi-service.jar
rm framework/oat/arm64/wifi-service.ode
reboot


A modified wifi-service.jar is also uploaded and I have tested on my pixel. Everything seems fine.
 

Attachments

  • wifi-service.jar
    433.5 KB · Views: 1,257

Thomasvt

Member
Dec 10, 2014
41
17
Hi,

Thanks your your tutorial. I just have one question.

5) Repack by the following command
java -Xms1g -jar smali-2.2b4.jar a -o classes.dex wifi-service
jar -cvf wifi-service.jar classes.dex

How do I execute this command(s)?
When I try them as 2 commands;
> 'jar' is not recognized as an internal or external command


Just found it, just be sure to set java/bin as Path in system settings. Even if "java -version" just works.

Thanks!
 
Last edited:

oatspunk

Member
Feb 26, 2017
5
0
Hi,

Please Help
After I do step 2 (pull framework )
Why i did not get folder framework/arm64 or framework/oat/arm64 ?



In my country, using 2.4Ghz wifi
And I have a problem with the channel. I hope to be able to switch to channel 14. (JP)

Thanks +
 

markus.marus

New member
Oct 22, 2017
2
0
Channel 149

Thanks for your description.
Is it also possible to reach channel 149 ?
I tryed it but without success.

I need this channel to connect my android phone with my copter.
Regards
Markus
 
Last edited:

nick_fc

Senior Member
Jan 4, 2013
86
10

HelpWiFi repair

New member
Jun 4, 2021
1
0

Attachments

  • 20210524_104237.jpg
    20210524_104237.jpg
    4.5 MB · Views: 57

Top Liked Posts

  • There are no posts matching your filters.
  • 6
    [Disclaim]
    Mod at your own risk and I don't hold any responsibility for any consequence that may have been caused by this mod.
    Remember to make a backup first though I have tested on my pixel.

    [Background]

    My company uses channel 132,136,140,144 to broadcast 5G wifi, however, the wifi region code on my phone is set to 'CN', so my phone could not even detect the wifi. For a complete list of available wifi channel in each region, please refer to this wiki.

    I tried to set wifi_country_code via 'settings put global wifi_country code US' or add 'country=US' in /etc/wifi/wpa_supplicant.conf, but without vain. Then I came across this post https://forum.xda-developers.com/showthread.php?t=2368501, and I decide to hack the setCountryCode function in the wifiservice to force the country to be 'US'. According to the wiki, region 'US' has the most available number of channels.

    This post will tell you how you could bypass this restriction on your phone. Your phone shall be rooted, of course.

    [Step to step guide]
    1) Setup tools, which includes
    a) adb
    b) jdk
    c)baksmali https://bitbucket.org/JesusFreke/smali/downloads

    2) Connect your phone and pull all the related files ( actually only wifi-service.odex and boot.oat is needed )
    adb pull /system/framework framework
    3) Decompile the odex file by using the following command
    java -Xms1g -jar baksmali-2.2b4.jar x -d framework/arm64 framework/oat/arm64/wifi-service.odex -o wifi-service
    The output goes to wifi-service folder
    4) Mod wifi-service/com/android/server/wifi/WifiServiceImpl.smali
    Search for 'method public setCountryCode', which is around line 5605, basically we just want to force the country code to "US".
    a) Change .register 8 to '.register 9'
    This is because we are going to use one more register to hold the static content 'US', aka, your desired country code
    The original code uses 8 registers, aka, v0 - v4 for local varialbe, v5-v7 for parameter, they are also alised to p0-p2.
    After this change, we can use the register named v5, v6-v8 will be aliased to p0-p2.
    b) Add a line under const-string/jumbo v2, "WifiService"
    const-string/jumbo v5, "US"
    Therefore, v5 hold the content 'US', which is the desired country code.
    c) Replace all p1 with v5 inside this method
    Originally the country code is passed from outside the call, we just force it to 'US', which is stored in variable v5

    5) Repack by the following command
    java -Xms1g -jar smali-2.2b4.jar a -o classes.dex wifi-service
    jar -cvf wifi-service.jar classes.dex

    6) Install on the phone
    adb push wifi-service.jar /sdcard/
    The following commands shall be executed on the phone and with root prividelege
    mount -o rw,remount /system
    #Make a backup first
    cd system
    cp -p framework/oat/arm64/wifi-service.odex framework/oat/arm64/wifi-service.odex.bak
    cp -p framework/wifi-service.jar framework/wifi-service.jar.bak
    #Install the new file
    cp /sdcard/wifi-service.jar /system/framework/
    chown root.root framework/wifi-service.jar
    chmod 644 framework/wifi-service.jar
    rm framework/oat/arm64/wifi-service.ode
    reboot


    A modified wifi-service.jar is also uploaded and I have tested on my pixel. Everything seems fine.
    2
    I just released an Xposed module that does the same thing. Thanks @op for the tip.

    https://forum.xda-developers.com/xposed/modules/mod-change-wifi-region-to-enable-5ghz-t3396936/
    1
    Thanks for your description.
    Is it also possible to reach channel 149 ?
    I tryed it but without success.

    I need this channel to connect my android phone with my copter.
    Regards
    Markus

    Set region as "EU", and it should work :)