12

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.

Alessandro Minoccheri
  • 35,521
  • 22
  • 122
  • 171
Sani Yusuf
  • 982
  • 1
  • 10
  • 20

5 Answers5

9

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.

Nippey
  • 4,708
  • 36
  • 44
  • I have tried this and it does not work. BDW my device is a galaxy ace rooted – Sani Yusuf Oct 12 '12 at 09:47
  • 1
    i HAVE GOTTEN a working solution. I needed to find my device modem which in my case is SMD0 instead of TTYUSB0. I have had a couple commands work and some return OK . Still investigating. Thanks guys. – Sani Yusuf Oct 15 '12 at 09:05
  • Aaah, that's why I told you to check out the guide. :o) I'll complete my answer in order to match that problem. Thank you for sharing with us! – Nippey Oct 15 '12 at 09:15
  • If I connect my phone with USB and use /dev/smd0 with adb shell, it works but using same method on Android Terminal Emulator doesn't. What could be wrong? – Umair A. Dec 23 '13 at 19:20
  • So @Nippey, there is no way to do it on the Galaxy S4? I desperately need to know the TMSI (which changes all the time, "T" stands for Temporary). – tiktak Jul 07 '14 at 20:30
2

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.

Nikolay Elenkov
  • 52,576
  • 10
  • 84
  • 84
  • It is actually possible. i Have been able to get a couple working and most have returned OK request. – Sani Yusuf Oct 15 '12 at 09:03
  • Again, echo them where? What command did you issue? ADB is just a means to execute shell command on the phone. You could be able to talk to some serial(-like) device directly, or you may not be able to. This largely depends on the particular phone. – Nikolay Elenkov Oct 15 '12 at 09:07
1

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.

psiphi75
  • 1,985
  • 1
  • 24
  • 36
MRodrigues
  • 1,927
  • 1
  • 17
  • 22
1

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

dcoles
  • 3,785
  • 2
  • 28
  • 26
Balwinder SIngh
  • 1,831
  • 2
  • 24
  • 28
  • " to check which port is being used by RIl use `getprop rild.libargs`" but in my case it returns nothing. No text is shown. I am using a Samsung GT-S5301 – mkhan Sep 09 '15 at 10:04
1

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.
Dustin
  • 2,064
  • 1
  • 16
  • 12