Posted on

Change Android preferred network mode using AT commands

I needed a solution on how to change the preferred network mode on KitKat and Lollipop devices and, I had the “luck” of only having to target two rooted Samsung devices from the Galaxy Grand series.

My initial search lead me to a lot of stack overflow posts that mainly described solutions using code reflection of methods belonging to com.android.internal.telephony.PhoneFactory class. None of these seemed to work on more recent android versions, even if installing the app on the android folder reserved for system apps: /system/priv-app/.

One of the first clues on stack overflow was this post: http://stackoverflow.com/questions/5436251/how-to-access-setpreferrednetworktype-in-android-source

Nothing worked either: not the reflection code on the post, the app from TheMasterBaron/Toggle-2G, nothing!

A more useful clue came from this xda post: http://forum.xda-developers.com/galaxy-s2/help/how-to-talk-to-modem-commands-t1471241

The post talked among many things, of a way to execute AT commands from windows to android. I used PuTTY, made a serial COM4 connection to the device and in a few seconds, I was executing all sorts of AT commands and getting all sorts of responses. This was great but, I still had no clue on how to execute these commands on the android device itself.

Capture

I started to search about AT commands and one of the first things you learn is that they are different from device to device because different devices use different modems, etc.

A quick query of both devices using the command AT+CLAC showed a different list of supported commands and, event more surprising, in devices from the same company and series. The devices are more or less one year apart from each other in terms of release dates.

Capture2

I found a lot of documents regarding AT commands but, this one has many practical examples on how to use them: https://www.sierrawireless.com/resources/documents/support/2130617_supported_at_command_reference-v2.4.pdf

The first thing I had to know, was how to change the preferred network mode on both devices and, all the documentation found online was really helpful. Using PuTTY, I managed to change the network mode from 4G to GSM by using the following commands:

KitKat:

Lollipop:

All the network modes were easy to find by using the query version of the above commands, after changing between different network modes:
KitKat:

Lollipop:

One of the first things you got to search about, is what serial port does the modem uses: it’s on this serial port that all AT commands will be executed and all responses will be there also.

The initial search lead me to the ports ttyGS0 and smd0. The port smd0 seemed to work on KitKat and, by using this shell command I received my first OK response from android:

But, the happiness didn’t last long, I still had no clue on what port Lollipop was using so, I decided to use brute force, and executed ls /dev/ which returned a bunch of folders representing block/character devices. More info on this subject, here. I counted more or less 750 folders and, one of these folders, contained my serial port! All I had to do was find it! How? well, simple, just test them all in a simple way by trying to change the network mode, like this:

etc…

I did a search by blocks of 40 sequential commands from the 750 and almost at the end, eureka! The network mode changed! I found two serial ports that responded to the AT commands! These were the ones that did it:

The final version of the commands on both android versions, which changed the network mode from the default 4G to GSM:

KitKat:

Lollipop:

So, that’s it, I hope this helps someone.

Capture

 

 

 

Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

2 thoughts on “Change Android preferred network mode using AT commands

  1. Hi, Can you please suggest same commands for Marshmello

    1. The commands maybe different not because of the android version but because of the device’s hardware. I suggest you try to find the port your device is using to accept AT commands.

Leave a Reply

Your email address will not be published. Required fields are marked *