Sani Yusuf
Sani Yusuf

Reputation: 982

Sending AT Commands Via ADB Android

I have a task at work to investigate if it is possible to send AT commands to an android device via ADB shell. So far,I have tried to echo out the AT commands but it passes them as normal strings. Any help please anyone.

Upvotes: 12

Views: 57853

Answers (6)

Drew L
Drew L

Reputation: 1

Device does not necessarily have to be rooted. I just got a successful return on a test command on a SM-146U (T-Mobile) by running

echo -e "AT+CFUN=?\r\n" > /dev/tty

through basic ADB

Upvotes: 0

Balwinder SIngh
Balwinder SIngh

Reputation: 1961

Yes you can run AT commands from adb shell too.

Prerequisites:

  1. rooted android phone
  2. you are aware of the port that RIL use for i/o operation.
  3. to check which port is being used by Android's Radio Interface Layer (RIL) use getprop rild.libargs

To run AT command from ADB use:

echo -c "AT\r\n" > /dev/smd11

p.s. /dev/smd11 is port used by RIL. This varies from device to device.

Also to run AT commands from Android application check this tutorial: Executing AT commands from Android Application

Upvotes: 1

Dustin
Dustin

Reputation: 2154

Kind of a combination of the above. We got it working with 2 terminals on a Pixel 4 XL.
On one we did:

cat /dev/smd7

in the other:

echo "AT\r" > /dev/smd7

The output shows up in the first terminal

Notes:

  1. Have to be root!
  2. None of the discovery mechanisms worked for us, so we blindly called into smdX until we got a response from "AT\r".
  3. echo automatically adds a \n, so adding it is redundant.

Upvotes: 1

MRodrigues
MRodrigues

Reputation: 2025

In order to find out which port to use : You can check

# cat /proc/tty/drivers

Use logcat -b radio | grep dev to see wich tty the radio is using.

Upvotes: 2

Nippey
Nippey

Reputation: 4739

Please try this:

echo -e "AT+CFUN=?\r\n" > /dev/ttyUSB0

On your phone, the serial line must not necessarily be called ttyUSB0. If this is not working or not available, check out the other entries of the /dev/ directory.
So it could also be /dev/ttyGS0 or /dev/SMD0 (as found out by @Sani).

For further information, please check out this Guide


NOTE:

There might also be phones, that do not respond to AT commands on any of their serial (tty) devices.
I just tried my own procedure on a Samsung Galaxy S4 and did not have any success.

Upvotes: 9

Nikolay Elenkov
Nikolay Elenkov

Reputation: 52936

Echo them where? In Android you talk to the rild (Radio Interface Layer) daemon, which in turns talks to a proprietary library, which sends commands to the actual hardware. Check rild source code for details. You could probably write a command line program that talks to the rild and execute it via adb shell, if that fits your needs.

Upvotes: 2

Related Questions