In my previous blog I had shown how Alioth established a data connection and was able to browse the internet. I am going a bit into the details on how we achieved this in this blog.

When I wanted to enable data on the Android Porting that we made to Alioth, I started off with getting it work on Linux first and then moved onto Android .There are some differences in enabling the 2G GPRS for Linux and the steps you need to take for Android

Have a look at the block diagram below

How to integrate GSM/2G Modem in Android - block Diagram

Bottom layers, Layer 1 through 3 is almost same in the Linux. I have enabled the data connection in Linux. Here is a snapshot of bringing up GPRS in Linux (the good old console way !!).

Snapshot of bringing up GPRS in Linux

The Top 2 layers are Android Service and Application Layers which has the Telephony manager and the Telephone application as well respectively. These layers do NOT require any change to integrate our modem to Android.

So the changes for Android are concentrated on the following

    • 1. Vendor RIL
    2. PPPD Changes for Android.

1.1 Vendor RIL

The Android Open Source Project provides a Radio Interface Layer (RIL) between Android telephony services (android.telephony) and the radio hardware.It consists of a stack of two components: a RIL Daemon and a Vendor RIL. The RIL Daemon talks to the telephony services and dispatches “solicited commands” to the Vendor RIL. The Vendor RIL is specific to a particular radio implementation, and dispatches “unsolicited commands” up to the RIL Daemon

To enable GPRS in Android, we should enable the GSM first. If the SIM_STATE is not ready, the android will not allow the user to enable GPRS from the Application layer. Most of the AT commands used in the sample vendor RIL given by Android will work fine for most of the Modems. But still few commands are specific to the modem which has to be addressed and changed for each modem.

Enabling GPRS and GSM simultaneously requires MUX mode support in the modem and MUX driver to provide multiple virtual channels to RIL.

The reference Vendor RIL uses single physical port for GSM and GPRS. Practically we cannot use that. So we should enable MUX before Vendor RIL starts. The vendor will open two virtual ports for GSM and GPRS respectively.

Solicited commands are the commands from the telephony applications/services to the modem and unsolicited commands are the commands from the modem to upper layers. When the vendor RIL receives a solicited command for DATA connection, it should be routed to the GPRS port and if the command is for GSM, it should be routed to the GSM port. Likewise the unsolicited command read loop should read both the ports (GSM/GPRS) for any new unsolicited command from the modem.

When an enable request received for GPRS with the APN configurations, after sending all the AT commands to enable the GPRS, the vendor RIL has to write all the PPPD configurations to the /etc/ppp/options file and start the PPPD process.

AT Commands to be sent from the Vendor RIL to enable GPRS connection

    • AT+CGDCONT=1,”IP”,”” // APN name will be one of the parameter for this call
    • AT+CGQREQ=1 // Set required QoSparams to default
    • AT+CGQMIN=1 // Set minimum QoSparams to default
    • AT+CGEREP=1,0 // packet-domain event reporting
    • AT+CGACT=1,0 // Hangup anything that’s happening there now
    ATD*99***1# // Start data on PDP context 1

Here is the sample PPPD options file for Android

    • /*Sample options file */
    • <Device name with Path>
    • user 0
    • password
    • unit 0
    • noauth
    • nodetach
    • defaultroute
    • nocrtscts
    • ipcp-no-addresses
    • noipdefault
    • lcp-echo-failure 4
    lcp-echo-interval 60

The final part in the Vendor RIL is monitoring the DATA connection. The vendor RIL should monitor the DATA connection and intimate the upper layer if there is any change in the DATA connection. Set the command AT+CGEREP=2,1 in the modem to enable GPRS notification. Then the modem will generate an unsolicited response “+CGEV” when there is a change in the GPRS connection. If the vendor RIL receives this unsolicited command from the modem, it has to identify the change and intimate it with the unsolicited response RIL_UNSOL_DATA_CALL_LIST_CHANGED. So the Telephony manager service will get to know if there is lose is DATA connection and it will re-establish connection.

1.2 Changes in PPPD

Even though the PPPD layer is almost same as Linux, there are some key changes in the Android PPPD.

  1. The PPPD source which is coming with Android will not read its configurations from File. Instead of reading it from file, it will expect it as arguments. All the file operations will be commented out with a macro called ANDROID_CHANGES. We should alter the PPPD to read the PPP options from the file. Because the PPPD options will change whenever there is a change in APN configuration.
  2. In Linux, we use chat application and scripts to establish the PPPD connection over GPRS. But CHAT application will not be part of Android based PPPD.
  3. In Android, PPPD will be running as a service. So when PPPD lose its connection, it will be restarted automatically.
  4. When the device loses the GPRS connection, the PPPD will call the script called /etc/ppp/pppd_down in Linux. But Android PPPD will call /etc/ppp/pppd_down_ppp0. The interface name will be added to the end. Likewise when the PPPD is up, it will call pppd_up_ppp0.

So these changes made my GPRS modem work with Android properly.

I think you are all are interested to know how the telephony would look like. I am working on that blog.. Would come back shortly.

One thought on “How to integrate GSM/2G Modem in Android – To establish data Connection”
  1. Hi GomathiShankar,
    Its a wonder tutorial about the RIL and how to fix the issue on the GPRS part. I am using a embedded board with external GSM/GPRS module based SIM300 on Android 4.0. I am also facing the same issue. I could not able to establish the data connection and access the internet by GPRS. Please share details about what are the changes we need to be done to work with GPRS.

    Thanks in Adv.

Comments are closed.