Tuesday, April 27, 2010

Use 3G modem data card in Android

We found Android-x86 had a new feature about telephony. It's about to use a 3G modem data card in EeePC and it can use 3G network to browse Internet. Therefore, I followed up this issue and verified it in Devkit8000 device. Now, it's one of our new released features and it comes with 0xdroid 0x4 release pre-built image too. In the beginning, I was trying to use a Quanta Q101 data card in Android emulator. How to run this experiment in my Ubuntu 9.10 manchine?

Set up Quanta Q101

Check this long discussion, I added a new rule file as below. When I plug-in q101 card, it can auto-mount to GSM modem mode with 4 ports.

erin@midnight:~$ cat /etc/udev/rules.d/30-q101.rules
# first, q101 will be detected as usb_storage of 0408:1000
# you have to force it suspend to change running mode from
# storage to 3.5g card

SUBSYSTEM=="block", ENV{DEVTYPE}=="disk", ACTION=="add", ATTRS{idVendor}=="0408", ATTRS{idProduct}=="1000", RUN+="/bin/sh -c 'cd /sys$env{DEVPATH};until test -f power/level;do cd ..;done;if [ -f power/level ];then echo suspend > power/level;fi'"

Wait about 10 seconds, then you can check these devices. RIL is /dev/ttyUSB3, PPP is /dev/ttyUSB1. When you use in Android emulator, it would become /dev/ttyS2 and /dev/ttyS3.

erin@midnight:~$ ls -l /dev/ttyUSB*
crw-rw---- 1 root dialout 188, 1 2010-04-27 16:34 /dev/ttyUSB1
crw-rw---- 1 root dialout 188, 2 2010-04-27 15:55 /dev/ttyUSB2
crw-rw---- 1 root dialout 188, 3 2010-04-27 17:16 /dev/ttyUSB3
crw-rw---- 1 root dialout 188, 4 2010-04-27 15:50 /dev/ttyUSB4

Need Kernel support PPP
I read this discussion and download Android kernel source code to rebuild kernel.

# git clone git://android.git.kernel.org/kernel/common.git
# cd kernel
# git checkout -b android-goldfish korg/android-goldfish-2.6.29
# cd $MYDROID/out
# ./host/linux-x86/bin/emulator -system ./target/product/generic/system.img -sysdir ./target/product/generic/system -data ./target/product/generic/userdata.img -kernel ../prebuilt/android-arm/kernel/kernel-qemu -ramdisk ./target/product/generic/ramdisk.img
# adb pull /proc/config.gz $MYDROID/kernel/
# cd $MYDROID/kernel/
# gunzip config.gz
# mv config .config
# make ARCH=arm menuconfig
(Add PPP in)
# make ARCH=arm CROSS_COMPILE=../prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi- zImage

Start the emulator again with new kernel image and then check /dev/ppp device!

# cd $MYDROID/out
# ./host/linux-x86/bin/emulator -system ./target/product/generic/system.img -sysdir ./target/product/generic/system -data ./target/product/generic/userdata.img -kernel ../kernel/arch/arm/boot/zImage -ramdisk ./target/product/generic/ramdisk.img
# adb shell ls -l /dev/ppp
crw-rw---- radio vpn 108, 0 2010-04-27 15:36 ppp

Modify Android source code
I applied the patches from Android-x86 and re-modified some code for Quanta q101 card. Also modify gprs script, since I am using Taiwan GSM netowork.

external ppp

hardware ril

system core

Since I am using Android emulator, the device names are different from Devkit8000.

Change the device permissions:

diff --git a/init/devices.c b/init/devices.c
index 4d93b44..0023cc3 100644
--- a/init/devices.c
+++ b/init/devices.c
@@ -108,6 +108,8 @@ static struct perms_ devperms[] = {
{ "/dev/android_adb_enable", 0660, AID_ADB, AID_ADB, 0 },
{ "/dev/ttyMSM0", 0600, AID_BLUETOOTH, AID_BLUETOOTH, 0 },
{ "/dev/ttyHS0", 0600, AID_BLUETOOTH, AID_BLUETOOTH, 0 },
+ { "/dev/ttyS2", 0660, AID_RADIO, AID_RADIO, 0 },
+ { "/dev/ttyS3", 0660, AID_RADIO, AID_RADIO, 0 },
{ "/dev/uinput", 0660, AID_SYSTEM, AID_BLUETOOTH, 0 },
{ "/dev/alarm", 0664, AID_SYSTEM, AID_RADIO, 0 },
{ "/dev/tty0", 0660, AID_ROOT, AID_SYSTEM, 0 },

Modify RIL argument and add ppp service from init:

erin@midnight:~/eclair/mydroid/build/target/board/generic$ cat system.prop
# system.prop for generic sdk

rild.libargs=-d /dev/ttyS2

# add these lines in system/core/rootdir/init.rc
service ppp /system/bin/pppd call gprs
user root
group system radio

Run Android Emulator
After changing these code, rebuilt Android again. Then we can run Android emulator from below command:

erin@midnight:~/eclair/mydroid/out$ ./host/linux-x86/bin/emulator -system ./target/product/generic/system.img -sysdir ./target/product/generic/system -data ./target/product/generic/userdata.img -kernel ../kernel/arch/arm/boot/zImage -ramdisk ./target/product/generic/ramdisk.img -sdcard ./target/product/generic/sdcard.img -qemu -serial /dev/ttyUSB3 -serial /dev/ttyUSB1

Run ppp manually
After starting ppp service, it would appear one network connection called 'ppp'.

# adb shell
# start ppp
# netcfg
lo UP 0x00000049
eth0 UP 0x00001043
tunl0 DOWN 0x00000080
gre0 DOWN 0x00000080
ppp0 UP 0x000010d1

Add APN for Taiwan GSM network

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.