NOTICE: The Processors Wiki will End-of-Life on January 15, 2021. It is recommended to download any files or other content you may need that are hosted on processors.wiki.ti.com. The site is now set to read only.

Android-USB-3G-Modem-Integration

From Texas Instruments Wiki
Jump to: navigation, search

Content is no longer maintained and is being kept for reference only!

Construction Icon small.png This page is currently under construction. The content of this page is due to change quite frequently and thus the quality and accuracy are not guaranteed until this message has been removed. Please feel free to contribute to this page while construction is in progress.

This page is currently under construction

Introduction[edit]

Content is no longer maintained and is being kept for reference only!

Majority of mobile telephone networks around the world offer mobile internet connections over 3G GSM using a portable USB modem device. A 3G modem allows you to access the internet anywhere, anytime, as long as you are within a 3G coverage area.

This document acts as guide to add 3G USB modem device spport in Android to access the data connectivity. It describes components involved for adding 3G modem support to Android and provides necessary configuration procedure.

AM335x EVM(REV 1.1A) and TI-Android-JB-4.1.2-DevKit-4.0.1 release is used as a base code for 3G modem integration. Airtel USB 3G (Huawei E173 based) modem is used for testing the functionality.Other Huawei based modems might work as well.

Android Telephony Architecture[edit]

The diagram illustrates the Android's Telephony system architecture.

AndroidTelephony.gif

Application: All the telephony related applications like Dialer, Call tracker, SMS, MMS, GPRS, Antenna signal indicator and etc, will be tied up with the Android telephony framework services. The telephony framework provides APIs to access the Phone.

Framework services: Telephony framework will be initialized and started during the system start up. All the queries from the application through API will directed to the Radio interface Layer of Android by these services. The service will keep tracking of all the unsolicited commands from the modem. Unsolicited commands are the commands initiated from the modem.

Radio Interface Layer (RIL): It is the bridge between Android phone framework services and the hardware.The RIL consist of two primary components.

  • RIL Daemon
  • Vendor RIL

RIL Daemon: RILD will be initialized during the Android system start up. It will read the system property or use command line arguments to find which library has to be used for Vendor RIL.It provide the appropriate input for vendor RIL and finally calls RIL_Init function of Vendor RIL to map all the Vendor RIL functions to the upper layer.

Vendor RIL: It is a library specific to each modem that processes all communication with radio hardware and dispatches calls to the RIL Daemon.

USB 3G Modem Demo[edit]

USB 3G modem support is available for AM335x EVM with Android 4.1.1 sources. Below sections provide procedure to download and build sourcesand provides necessary steps to configure 3G modem.

Getting Sources[edit]

3G USB modem configuration support has been added in settings app for AM335x EVM. Please follow below commands to download AM335x Android 4.1.1 sources with 3G modem support.

 $ mkdir ~/roboat-jb
 $ cd ~/rowboat-jb
 $ repo init -u git://gitorious.org/rowboat/manifest.git -m rowboat-jb-4.1.2-am335x.xml
 $ repo sync

Create a Bootable SD/MMC Card[edit]

Build source code for AM335x EVM and create a bootable SD card. Please follow instructions mentioned in below developer guide. http://processors.wiki.ti.com/index.php/TI-Android-JB-4.1.2-DevKit-4.0.1_DeveloperGuide#Build_Procedure

Download USB mode switch pre-complied binary from http://www.draisberghof.de/usb_modeswitch/#download

Copy usb_modeswitch binary to Android Filesystem (system/bin location)

   $ sudo cp usb_modeswitch-1.1.9-arm-static /media/rootfs/system/bin/usb_modeswitch

Test 3G Functionality[edit]

  • Bootup the board.
  • Connect USB 3G modem to board.
  • Wait for around 8-10 secs to get 3G modem detected and configured.
  • Go Settings Application <More...> and you will see the following


AndroidSettings.png

  • Select <Mobile networks> and you will get this screen:


AndroidSettingsMore.png

  • Select <Access Point Names>. when you come to the access point page you should see the list of APNs that are supported for your modem. Select appropriate APN.

If you don't see any APN list, click in the top right corner and select <New APN>. This is the tricky part where you fill in the GSM operators settings.Find your GSM operator settings and fill in following fields.


SettingsAPN.png


Mark "Data Enabled" check box.

  • Check whether browser works

Android USB 3G modem Integration[edit]

This section takes you through necessary steps involved in integrating USB 3G modem with Android. Procedure mentioned below is applicable for Android 4.1.1 version and may or may not work as ease with other Android versions.

Enable Android Telephony[edit]

Add APN List[edit]

An Access Point Name (APN) is the name of a gateway between a 3G(or GPRS, etc) mobile network and another computer network, frequently the public Internet.A mobile device making a data connection must be configured with an APN to present to the carrier. The carrier will then examine this identifier to determine what type of network connection should be created, for example: what IP addresses should be assigned to the wireless device, what security methods should be used, and how or if, it should be connected to some private customer network.

apns-conf.xml file contains the list of carriers. Android Telephony provider will read this file (/etc/apns-conf.xml location) and maintain the database of all APN carriers mentioned.

Add apns-conf.xml file to /system/etc/ (symlink /etc) of your file system.

 diff --git a/device.mk b/device.mk
 --- a/device.mk
 +++ b/device.mk
 @@ -46,6 +46,9 @@ PRODUCT_COPY_FILES += \
  PRODUCT_COPY_FILES += \
         packages/wallpapers/LivePicker/android.software.live_wallpaper.xml:system/etc/permissions/android.software.live_wallpaper.xml
  
 +PRODUCT_COPY_FILES += \
 +       device/ti/am335xevm/apns-full-conf.xml:system/etc/apns-conf.xml
 +
 # KeyPads
  PRODUCT_COPY_FILES += \
      $(LOCAL_PATH)/gpio-keys.kl:system/usr/keylayout/gpio-keys.kl \

Enable Mobile Network Support[edit]

Add mobile network attribute to the overlay config.xml file so that connectivity manager will understand that mobile connectivity is available. This will also enable "Settings->More->Mobile networks" option.

 diff --git a/overlay/frameworks/base/core/res/res/values/config.xml b/overlay/frameworks/base/core/res/res/values/config.xml
 index 82229a2..a2e55de 100644
 --- a/overlay/frameworks/base/core/res/res/values/config.xml
 +++ b/overlay/frameworks/base/core/res/res/values/config.xml
 @@ -128,6 +128,7 @@
      <string-array translatable="false" name="networkAttributes">
          <item>"ethernet,9,9,2,-1,true"</item>
 +        <item>"mobile,0,0,0,-1,true"</item>
         <item>"wifi,1,1,1,-1,true"</item>
          <item>"wifi_p2p,13,1,0,-1,true"</item>
      </string-array>

Add GSM telephony permissions

 diff --git a/device.mk b/device.mk
 index 7f0bc2d..64f9ec8 100644
 --- a/device.mk
 +++ b/device.mk
 @@ -41,7 +41,8 @@ PRODUCT_COPY_FILES += \
         frameworks/native/data/etc/android.hardware.usb.accessory.xml:system/etc/permissions/android.hardware.usb.accessory.xml \
         frameworks/native/data/etc/android.hardware.usb.host.xml:system/etc/permissions/android.hardware.usb.host.xml \
         frameworks/native/data/etc/android.hardware.sensor.light.xml:system/etc/permissions/android.hardware.sensor.light.xml \
 -       device/ti/am335xevm/android.hardware.screen.xml:system/etc/permissions/android.hardware.screen.xml
 +       device/ti/am335xevm/android.hardware.screen.xml:system/etc/permissions/android.hardware.screen.xml \
 +       frameworks/native/data/etc/android.hardware.telephony.gsm.xml:system/etc/permissions/android.hardware.telephony.gsm.xml
  
  PRODUCT_COPY_FILES += \
         packages/wallpapers/LivePicker/android.software.live_wallpaper.xml:system/etc/permissions/android.software.live_wallpaper.xml


Enable Radio Intferace Layer(RIL) deamon build[edit]

By default RIL daemon is not included in build. Enable RIL daemon build.

 diff --git a/device.mk b/device.mk
 index 64f9ec8..399e54e 100644
 --- a/device.mk
 +++ b/device.mk
 @@ -142,6 +142,9 @@ PRODUCT_PACKAGES += \
  PRODUCT_PACKAGES += \
         TemperatureWidget
  
 +PRODUCT_PACKAGES += \
 +       rild
 +
  $(call inherit-product, frameworks/native/build/tablet-dalvik-heap.mk)
  $(call inherit-product-if-exists, hardware/ti/wpan/wl12xx-bluetooth/wl12xx_bt_products.mk)
  $(call inherit-product-if-exists, hardware/ti/wlan/mac80211/firmware/wl12xx_wlan_fw_products.mk)

USB Modem Mode Switching[edit]

USB 3G modem devices will have two modes

  • USB flash memory storage
  • USB Modem.

The first mode, sometimes known as ZeroCD, is often used to provide driver for desktop operating system and is generally of no interest for Android.

By default modem will be in flash memory storage mode. usb_modeswitch utility can be used for switching USB 3G modem into modem mode.

USB Mode Switch Configuration[edit]

The ARM compiled usb_modeswitch binary and its sources can be obtained from HERE Copy the usb_modeswitch (ARM Compiled binary) and usb_modeswitch.conf to the /system/bin folder.

Below is example usb_modeswitch.conf file for the Huawei E1731 Modem (Airtel in India).

  Huawei E1731

  EnableLogging=1

  DefaultVendor= 0x12d1
  DefaultProduct=0x1446

  TargetVendor=  0x12d1
  TargetProductList="1001,1406,140b,140c,1412,141b,1436,14ac,1506"

  CheckSuccess=20

  MessageEndpoint= 0x01
  MessageContent="55534243123456780000000000000011062000000100000000000000000000"

The vendor IDs and product IDs mentioned in this configurations are specific to modem. If you are using some other modem then, you can find vendor IDs and product IDs using lsusb command and modify usb_modeswitch.conf file accordingly.

Add USB Mode switch as a Service[edit]

Add USB mode switch as a service in init.<platform>.rc file.

 :Ex device/ti/am335xevm/init.am335xevm.rc file
 
 #Download usb_modeswitch ARM complied binrary from
 #    http://www.draisberghof.de/usb_modeswitch/#download
 #    and place it in "/system/bin" folder of your filesystem with "usb_modeswitch" name.
 service usb_modeswitch /system/bin/usb_modeswitch -I -W -c /etc/usbmodeswitch.conf
     class main
     disabled
     oneshot

Start usb_modeswitch Service[edit]

start usb_modeswitch service if "usb" is connected. If 3G modem is connected, it will switch it in modem mode.

 diff --git a/VolumeManager.cpp b/VolumeManager.cpp
 --- a/VolumeManager.cpp
 +++ b/VolumeManager.cpp
 @@ -37,6 +35,7 @@
  #include <sysutils/NetlinkEvent.h>
  
  #include <private/android_filesystem_config.h>
 +#include <cutils/properties.h>
  
  #include "VolumeManager.h"
  #include "DirectVolume.h"
 @@ -144,6 +143,11 @@ void VolumeManager::handleBlockEvent(NetlinkEvent *evt) {
  #ifdef NETLINK_DEBUG
              SLOGD("Device '%s' event handled by volume %s\n", devpath, (*it)->getLabel());
  #endif
 +       if (strcmp((*it)->getLabel(),"usb")  == 0)
 +       {
 +            SLOGD("start usb modswitch service");
 +           property_set("ctl.start","usb_modeswitch");
 +       }
              hit = true;
              break;
          }

3G Modem Node Permissions[edit]

Once 3G modem is switched into modem mode. It will provide 3 serial nodes. /dev/ttyUSB0: used for your ppp data connections. /dev/ttyUSB2: used for GSM related tasks such as SMS and network checks. /dev/ttyUSB1: not used at all.

Note: The actual device assignments (e.g. /dev/ttyUSB0) may be different if you have other USB serial devices installed..

Provide appropriate permissions to these nodes.

 diff --git a/ueventd.am335xevm.rc b/ueventd.am335xevm.rc
 index d7cc538..2ba0518 100644
 --- a/ueventd.am335xevm.rc
 +++ b/ueventd.am335xevm.rc
 @@ -1 +1,4 @@
 -/dev/video0         0666  root       root
 +/dev/video0    0666    root    root
 +/dev/ttyUSB0   0660    radio   radio
 +/dev/ttyUSB1   0660    radio   radio
 +/dev/ttyUSB2   0660    radio   radio

Get RIL library[edit]

Download the ril repository and replace your existing RIL library with new one. This RIL library will start ppp (point to point) daemon to establish a internet link when setup data call is requested.

 $ cd ~
 $ git clone git://gitorious.org/rowboat/hardware-ril.git -b rowboat-jb-4.1
 $ cd ~/hardware-ril
 $ rm -rf <android sources>/hardware/ril/reference-ril
 $ cp -r ~/hardware-ril/reference-ril  <android sources>/hardware/ril/reference-ril

PPP Configuration[edit]

PPP is the protocol used for establishing internet links over dial-up modems, DSL connections, and many other types of point-to-point links. The pppd daemon works together with the kernel PPP driver to establish and maintain a PPP link with another system (called the peer) and to negotiate Internet Protocol (IP) addresses for each end of the link.

PPP daemon will run user defined scripts when link is established and disconnected.

ip-up-datakey: This script is run by the pppd after the link is established. ip-down-datakey: This script is run by the pppd after the link is disconnected.

  • ip-up-datakey script
 #!/system/bin/sh
 case $1 in
     ppp1)
         /android/bin/iptables --flush;
         /android/bin/iptables --table nat --flush;
         /android/bin/iptables --delete-chain;
         /android/bin/iptables --table nat --append POSTROUTING --out-interface ppp0 -j MASQUERADE;
         /android/bin/iptables --append FORWARD --in-interface ppp1 -j ACCEPT;
         echo 0 > /proc/sys/net/ipv4/ip_forward;
         echo 1 > /proc/sys/net/ipv4/ip_forward;
         ;;
     ppp0)
     /system/bin/setprop "net.interfaces.defaultroute" "ppp1";
     ;;
 esac
 
 /system/bin/setprop "net.ppp1.dns1" "$DNS1"
 /system/bin/setprop "net.ppp1.dns2" "$DNS2"
 /system/bin/setprop "net.ppp1.local-ip" "$IPLOCAL"
 /system/bin/setprop "net.ppp1.remote-ip" "$IPREMOTE"
 /system/bin/setprop "net.ppp1.gw" "$IPREMOTE"
 /system/bin/setprop "net.ppp1.if" "$IFNAME"
 
  • ip-down-datakey
 #!/system/bin/sh
 case $1 in
     ppp1)
         echo 0 > /proc/sys/net/ipv4/ip_forward;
         ;;
 esac
 
 /system/bin/setprop "net.ppp1.dns1" ""
 /system/bin/setprop "net.ppp1.dns2" ""
 /system/bin/setprop "net.ppp1.local-ip" ""
 /system/bin/setprop "net.ppp1.remote-ip" ""
 /system/bin/setprop "net.ppp1.gw" ""
 /system/bin/setprop "net.ppp1.if" ""

Place these scripts in <Android source>/device/ti/<target product>/ppp folder.

Add following lines to device.mk file to copy these files to Android filesystem.

 PRODUCT_COPY_FILES += \
        device/ti/am335xevm/ppp/ip-up-datakey:system/etc/ppp/ip-up-datakey \
        device/ti/am335xevm/ppp/ip-down-datakey:system/etc/ppp/ip-down-datakey

Kernel Configuration for USB Modem[edit]

Make sure following configuration options are enabled in kernel.

Device Drivers  --->
 [*] Network device support  --->
   <*>   PPP (point-to-point protocol) support
     <*>     PPP BSD-Compress compression
     <*>     PPP Deflate compression
     <*>     PPP support for async serial ports
     <*>     PPP support for sync tty ports
 [*] USB support  --->
   <*>   USB Modem (CDC ACM) support
   <*>   USB Serial Converter support  --->
     [*]   USB Generic Serial Driver
     <*>   USB driver for GSM and CDMA modems
E2e.jpg {{
  1. switchcategory:MultiCore=
  • For technical support on MultiCore devices, please post your questions in the C6000 MultiCore Forum
  • For questions related to the BIOS MultiCore SDK (MCSDK), please use the BIOS Forum

Please post only comments related to the article Android-USB-3G-Modem-Integration here.

Keystone=
  • For technical support on MultiCore devices, please post your questions in the C6000 MultiCore Forum
  • For questions related to the BIOS MultiCore SDK (MCSDK), please use the BIOS Forum

Please post only comments related to the article Android-USB-3G-Modem-Integration here.

C2000=For technical support on the C2000 please post your questions on The C2000 Forum. Please post only comments about the article Android-USB-3G-Modem-Integration here. DaVinci=For technical support on DaVincoplease post your questions on The DaVinci Forum. Please post only comments about the article Android-USB-3G-Modem-Integration here. MSP430=For technical support on MSP430 please post your questions on The MSP430 Forum. Please post only comments about the article Android-USB-3G-Modem-Integration here. OMAP35x=For technical support on OMAP please post your questions on The OMAP Forum. Please post only comments about the article Android-USB-3G-Modem-Integration here. OMAPL1=For technical support on OMAP please post your questions on The OMAP Forum. Please post only comments about the article Android-USB-3G-Modem-Integration here. MAVRK=For technical support on MAVRK please post your questions on The MAVRK Toolbox Forum. Please post only comments about the article Android-USB-3G-Modem-Integration here. For technical support please post your questions at http://e2e.ti.com. Please post only comments about the article Android-USB-3G-Modem-Integration here.

}}

Hyperlink blue.png Links

Amplifiers & Linear
Audio
Broadband RF/IF & Digital Radio
Clocks & Timers
Data Converters

DLP & MEMS
High-Reliability
Interface
Logic
Power Management

Processors

Switches & Multiplexers
Temperature Sensors & Control ICs
Wireless Connectivity