FORUMS
Remove All Ads from XDA

[MOD] WIFI country code fix ( root required )

196 posts
Thanks Meter: 75
 
By churchmice, Senior Member on 17th February 2017, 08:07 AM
Post Reply Email Thread
[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/sho....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.
Attached Files
File Type: jar wifi-service.jar - [Click for QR Code] (433.5 KB, 786 views)
The Following 5 Users Say Thank You to churchmice For This Useful Post: [ View ] Gift churchmice Ad-Free
 
 
13th August 2017, 07:35 PM |#2  
Member
Thanks Meter: 14
 
More
Hi,

Thanks your your tutorial. I just have one question.

Quote:

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!
15th August 2017, 12:10 AM |#3  
Junior Member
Thanks Meter: 0
 
More
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 +
16th August 2017, 10:21 AM |#4  
Senior Member
Flag Trento
Thanks Meter: 392
 
Donate to Me
More
Quote:
Originally Posted by oatspunk

Hi,

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

[...]

I think it's "dex", not "odex".
5th November 2017, 03:24 PM |#5  
Junior Member
Thanks Meter: 0
 
More
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
12th November 2017, 11:39 AM |#6  
Member
Thanks Meter: 14
 
More
Quote:
Originally Posted by markus.marus

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
The Following User Says Thank You to Thomasvt For This Useful Post: [ View ] Gift Thomasvt Ad-Free
19th January 2018, 09:20 AM |#7  
Member
Thanks Meter: 10
 
More
Quote:
Originally Posted by Thomasvt

Hi,

Thanks your your tutorial. I just have one question.



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!

Can anybody help in this thread https://forum.xda-developers.com/zen...5#post75254641
13th March 2018, 06:51 PM |#8  
Junior Member
Thanks Meter: 0
 
More
...
4th April 2018, 06:17 AM |#9  
madmack's Avatar
Senior Member
Flag Boston, MA
Thanks Meter: 4,802
 
Donate to Me
More
I just released an Xposed module that does the same thing. Thanks @op for the tip.

https://forum.xda-developers.com/xpo...5ghz-t3396936/
The Following User Says Thank You to madmack For This Useful Post: [ View ] Gift madmack Ad-Free
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes