Sending AT Commands Via ADB Android - 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.

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.

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.

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.

Yes you can run AT commands from adb shell too...
prerequsite :-
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 RIl use `getprop rild.libargs`
To run AT command from ADB use:
echo -c "AT\r\n" > /dev/smd11
PS: smd11 is port used by RIL.This varies from device to device.
ALso to run AT commands from android application check this tutorial
http://tech-papers.org/executing-at-commands-android-application/

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:
Have to be root!
None of the discovery mechanisms worked for us, so we blindly called into smdX until we got a response from "AT\r".
echo automatically adds a \n, so adding it is redundant.

Related

How to execute gsm0710muxd during boot time of android

I am using mux drivers for GSM modem with android 4.0.4 and I executes using command on console:
./gsm0710muxd -s /dev/ttyUSB0 -b 115200 -n 3
but I want to automate this, so I want to execute it during boot-up time so that my virtual ports may work with my gsm modem for calling functionalities but I am unable to automate this command, I have no idea how to do this because the command is complicated, I don't know how to use this as a whole to tell system serial port, baudrate, number of ports.
You can do this by giving this command in init.rc. Here is an example from init.rc. You can add this in the boot section of init.rc where other services are also initialized.
service gsmmuxd /system/bin/logwrapper /system/bin/gsm0710muxd –s /dev/<serial_port> –n3 -v7 –mbasic
class main
user radio
group radio cache inet misc
oneshot
Plus you will also need to change the device which is used in ril-daemon service. For instance, my RIL library is librapid-ril-core.so and I am using mux, the configuration would be the following:
service ril-daemon /system/bin/rild -l /system/lib/librapid-ril-core.so -- -a /dev/pts/0 -n /dev/pts/1
Here, if we were using USB, you would see /dev/ttyUSB0 and /dev/ttyUSB1 in your init.rc configurations.
I hope this helps. Please feel free to ask further questions.

adb: device not found

I'm trying to build a Kivy app on my Android phone using Buildozer. But adb is not finding my device. This is the error I am getting:
dan#dan-asus:~/kivy$ adb usb
error: device not found
dan#dan-asus:~/kivy$ adb devices
List of devices attached
I've added my vendor and product id that I got from lsusb in my /lib/udev/rules.d/70-android-tools-adb.rules file as so:
# Lenovo A789
SUBSYSTEM=="usb", ATTR{idVendor}=="17ef", ATTR{idProduct}=="7497", MODE="0666", OWNER="dan", TAG+="uaccess"
Have two 1.1 and two 2.0 USB outlets. Tried all four of them. Made sure I restarted adb every time I made a change and even tried to reboot my phone a few time.
What am I missing?
adb version is 1.0.31
I know this should be a comment, but I don't have enough reputation for that... so here is my "answer".
I can think of a couple of things that you don't mention specifically in your question:
Do you have a file ~/.android/adb_usb.ini? If yes, is the vendor ID written there? (in your case should be 0x17EF in a single line). Try with that and restart your ADB server.
Is ADB enabled in your device? You can check that with lsusb -v -d 17ef:7497 | grep -B 3 -i iInterface and look for some interface with class 255, subclass 66, protocol 1. That's your ADB USB interface in the device, if you don't find it, check the device's settings/configuration.
Hope it helps.

Talking to modem with AT commands on android

I'm trying to talk to samsung galaxy s2 plus and huawei p1 xl (u9200) modem sending AT commands, but can't get any result. I'm sending commands using adb shell and view logs with logcat.
In samsung when i execute cat /proc/tty/drivers i get the following:
/dev/tty /dev/tty 5 0 system:/dev/tty
/dev/console /dev/console 5 1 system:console
/dev/ptmx /dev/ptmx 5 2 system
/dev/vc/0 /dev/vc/0 4 0 system:vtmaster
rfcomm /dev/rfcomm 216 0-255 serial
g_serial /dev/ttyGS 237 0-3 serial
serial /dev/ttyS 4 64-67 serial
pty_slave /dev/pts 136 0-1048575 pty:slave
pty_master /dev/ptm 128 0-1048575 pty:master
unknown /dev/tty 4 1-63 console
Looks like i should send commands to /dev/ttyGS0, but it doesn't reply. I've tried the following commands:
echo "AT\r" > /dev/ttyGS0
echo "ATD12345678900;\r" > /dev/ttyGS0
but nothing happens. Actually, i'm not sure that i have to send commands to this file, but others don't reply too.
I've read article on XDA-developers, but it didn't help.
With Huawei i know which file i should use, but i can't make data call. I can make regular voice call, but i can't execute AT+CSNS=4. Just doesn't work. Also i have LG P765, which is based on a similar chipset and on LG i can make data call. Can anyone tell me what should i do?
All devices are rooted.
I suggest that you try to send AT command using the atinout program, e.g. instead of redirecting output to the modem device run
echo "ATD12345678900;" | atinout - /dev/ttyGS0 -
I am guessing, but it could be that the echo command in the adb shell does not interpret \r as anything special (that would at least explain no response whatsoever). By using atinout you are guarantied that AT command lines are properly terminated with \r and capturing should be simpler and work much more reliably.
please try different ports available to check the results.
in my android its working under /dev/pts/7 port number.
also use different terminal to read and write
Terminal 1 :
echo -e "AT\r" > /dev/pts/7
Terminal 2 :
cat /dev/pts/7
also try using executing as a root user.

How to run AT commands in Android terminal as root user?

I have root my Android mobile (Spice MI 270). I want to run AT commands. But whenever I try to run any AT command form shell, it is giving messages as 'AT not found'. My whole purpose of routing is to give AT commands to modem.
How should I proceed?
Thanks.
You can use the program atinout which will allow you to easily send AT commands from the commands line. Example to hang up a call:
$ echo ATH | atinout - /dev/ttyACM0 -
ATH
OK
$
You need to find the name of the serial device for android (on desktop linux it is typically /dev/ttyACM0 but Android use something different as far as I remember).

How to control a serial device on Android?

I want to develop an application whitch control the serial device over usb, on Linux Android.
An Android OS is 3.1 that supports USB host.
Q1: Please let me know how to get which port the serial device is mounted .
I got likely USB device information when I got "Dump Device State" on Dalvik Debug Monitor.
And, I checked /dev/tty* on android device by using adb.
I don't know which one(/dev/tty??) the serial device is.
adb shell
$ ls /dev/tty*
/dev/tty
/dev/ttyFIQ0
/dev/ttyHS0
/dev/ttyHS2
/dev/ttyHS3
/dev/ttyHS4
/dev/ttyS0
/dev/ttyS1
/dev/ttyS2
/dev/ttyS3
Q2: Please let me know how to control the serial device on Android without root permission.
I have a application(exe) that can control the serial device on linux.
I tried to do on android , but I couldn't do for permission denied.
And, I tried redirect to the serial port(maybe)
$ ls > /dev/ttyS0
But I couldn't.
cannot create /dev/ttyS0: permission denied.
Please let me know anything how to control and access to the serial device.
There is a great review of this in the XDA forum thread:
How to talk to the Modem with AT commands.
That thread show you how to send AT commands (ATC) with a remote terminal (USB connected to you PC), but it has not yet solved the problem of how to use a local (phone) terminal to talk to the phone Modem.
BTW. You need a terminal application/program to do any talking to the modem (remember, its a 2-way communication). So that's why you need a rooted device, since the root kit usually come with Busybox (that includes a microcom terminal program). Otherwise you have to write your own program.
in next step, you can test tty* port by couple of command:
$ cat /dev/tty* /for receive the characters from tty
and
$ echo 'text string' > /dev/tty* /for send characters to tty
good luck!
Try on a rooted device?? In researching the same thing I've read that only a few 3.1 / 2.3.4 devices allow non-root access to the usb port.
This is what I get on my HTC Desire unrooted, 2.2:
$ ls /dev/tty*
ls /dev/tty*
/dev/tty
/dev/ttyHS0
/dev/ttyHSUSB0
/dev/ttyHSUSB1
/dev/ttyHSUSB2
/dev/ttyMSM0
My Asus Transformer, unrooted, 3.2:
$ ls /dev/tty*
ls /dev/tty*
/dev/tty
/dev/ttyHS1
/dev/ttyHS2
/dev/ttyS0
/dev/ttyS1
/dev/ttyS2
/dev/ttyS3
I get exactly the same list when docked with the Keyboard Dock installed (It as 2 x USB ports).
Hope it helps, please let me know I'd love to be able to do the same.

Categories

Resources