Linux + GSM : How to access your cell phone innards with Linux

This article explores your options to access your GSM cell phone from a linux system, and manipulate SMS and phonebook entries.

Doesn’t provide hints about how to unlock a GSM cell phone though 😉

Existing tools

As usual it started with what seemed to be a simple need : I wanted to backup the contacts SIM card’s memory. I installed and tried various pieces of software with various but consistently disappointing results :

  • kmobiletools : neat GUI, able to load the phonebook, but no option to export it to a file or restore it (but it works great if you want to send SMS from your computer with your mobile attached)
  • kandy : nice interface, and is supposed to be able to sync your KDE AddressBook … but as far as my test went, it was not able to connect to my cell phone (maybe it will work with yours)
  • xgsm / gsmlib : this one’s GUI is ugly, but at least it was possible to connect to the cell phone and save the phonebook to a file… but unfortunately it failed to restore it !!!
  • KitchenSync was supposed to be a kind of universal sync tool, but as far as I’m concerned I didn’t manage to get anything out of it

You might first give a try to those tools and the others, they didn’t work for me but it doesn’t mean it won’t work for you !

DIY approach

Connecting the data cable

First let’s plug that data cable you bought for your cell phone from any mobile phone shop or from ebay.
Here’s what shows up with a dmesg :
spaghetti:~/$ dmesg
[492737.436000] usb 2-2: new full speed USB device using uhci_hcd and address 5
[492737.604000] usb 2-2: configuration #1 chosen from 1 choice
[492737.604000] cp2101 2-2:1.0: cp2101 converter detected
[492737.720000] usb 2-2: reset full speed USB device using uhci_hcd and address 5
[492737.868000] usb 2-2: cp2101 converter now attached to ttyUSB0

Looking up in google to know what is a CP2101 … This “USB data cable” is just a USB attached Serial Adapter (RS232 interface), which you can use like any other serial port under linux and which is now attached to /dev/ttyUSB0.

Connecting to the cell phone over this serial port

What then came to my mind is to use a terminal emulator capable of talking over a serial line. There are many such tool (minicom, kermit, hyperterminal … pick your favorite one). I tend to use cu for this purpose.
spaghetti% cu -h -s 38400 -l /dev/ttyUSB0

Hmm that was easy … For the parameters, here is the explanation :

  • -h : turns on local echo (for you to see what you type in)
  • -s : chooses the speed
  • -l : chooses the tty matching the serial port you want to use

Trying a few commands

Some more googling and it turns out that one talks to his GSM cell phone as one would talk to those old RTC modems, using “AT-commands”. Those AT-commands are fairly standardized in the GSM specifications.
For example, here is how to seek an entry from the phonebook (“PB“) on the SIM card (the “SM” storage). Note that the ^M are the enter I type in :
spaghetti% cu -h -s 38400 -l /dev/ttyUSB0
+CPBR: 13,"33123456789",145,"Some Dude"

We first selected the phonebook storage “SM” (the SIM card) and then fetched the 13th record out of it. The 145 which came along means the phone number is in international form (you have to add a “+” ahead of it when dialing).
Let’s write an entry :
AT+CPBW=61,"1234",129,"Name Dude"^M
+CPBR: 61,"1234",129,"Name Dude"

First we wrote the entry with the AT+CPBW command then read it back with AT+CPBR. The 129 means the phone number is not in its international form.

Now we could send an SMS :
> Did you get that ?^Z
+CMGS: 0

First we specify that the SMS will be in “text format” with the AT+CMGF command. Then we send the SMS with the AT+CMGS command. First the number, then the text which is terminated with a ^Z.

Scripting, anyone ?

Of course, you might want to automate this all. You might want to backup / restore your SIM card, send an SMS from a script and so on …
For such purposes, there is a Perl module Device::Modem which will let you send AT-commands and get results very simply. And I am currently writing the Device::Modem::GSM module which will make it easy to interact with a GSM mobile phone.


This post barely scratches the surface of what you can do by using AT-commands with your mobile. You can read about all the other commands in the GSM reference on AT-commands, which you’ll find on the internet with a wisely built search query.

Developers’ home runs a nice technical tutorial about SMSes too.

Question to the readers

As I said, I am currently writing a Perl module to simplify GSM automation. I had in mind phonebook operations and SMS sending … What other features would you like to see implemented ?

Your ideas in the comments !

3 thoughts on “Linux + GSM : How to access your cell phone innards with Linux”

  1. Repairing your iPhone is within reach of all by having a little patience, knowing that the replacement of batteries iphone 6 is a relatively simple operation that takes only fifteen minutes. And in addition to saving money, you make a gesture for the planet by not throwing a device still functional…

Leave a Reply

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