1. 前言
因為需要适配4G子產品,這裡總結下整個調試過程;
2. linux部分
linux 部分主要是硬體識别,當拿到子產品後,插入闆子上,列印如下:
[ 185.120132] usb 3-1: new high-speed USB device number 2 using xhci-hcd
[ 185.141610] usb 3-1: New USB device found, idVendor=12d1, idProduct=15c1
[ 185.149447] usb 3-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 185.157830] usb 3-1: Product: HUAWEI Mobile V7R11
[ 185.164667] usb 3-1: Manufacturer: Huawei Technologies Co., Ltd.
[ 185.171450] usb 3-1: SerialNumber: 0123456789ABCDEF
[ 185.251621] cdc_ether 3-1:2.0 usb0: register 'cdc_ether' at usb-xhci-hcd.0.auto-1, CDC Ethernet Device, 02:1e:10:1f:00:00
[ 185.271723] option 3-1:2.2: GSM modem (1-port) converter detected
[ 185.286827] usb 3-1: GSM modem (1-port) converter now attached to ttyUSB0
[ 185.295963] option 3-1:2.3: GSM modem (1-port) converter detected
[ 185.304478] usb 3-1: GSM modem (1-port) converter now attached to ttyUSB1
[ 185.313672] option 3-1:2.4: GSM modem (1-port) converter detected
[ 185.320886] CPU1: Booted secondary processor
[ 185.320886] CPU1: update cpu_power 1024
[ 185.332151] usb 3-1: GSM modem (1-port) converter now attached to ttyUSB2
[ 185.341133] option 3-1:2.5: GSM modem (1-port) converter detected
[ 185.350048] usb 3-1: GSM modem (1-port) converter now attached to ttyUSB3
[ 185.358760] option 3-1:2.6: GSM modem (1-port) converter detected
[ 185.367116] usb 3-1: GSM modem (1-port) converter now attached to ttyUSB4
從列印可以看出如下資訊: (1)USB序列槽驅動正常工作,裝置加載正常。 (2)CDC ECM驅動正常工作。 (3)一共生成了5個虛拟的序列槽。
3. android部分
3.1 RIL庫的移植
在init.rc中添加服務如下:service ril-daemon /system/bin/rild -l libhuawei-ril.so
其中rild源碼在/hardware/ril/rild/目錄下, 然後将libhuawei-ril.so放到system/lib/目錄中,在device/softwinner/common/目錄下,建立檔案夾LTE/,在該目錄中添加檔案firmware-LTE.mk, 然後将libhuawei-ril.so檔案放入該目錄,在firmware-LTE.mk中添加内容如下:
修改device/softwinner/petrel-p1,添加内容如下:
3.2 修改使用的USB或者PCM端口的權限
device/softwinner/petrel-p1目錄中,添加如下内容:
3.3 手動測試模組撥号過程
(1)這時候可以借用SDK中PPP源碼(對應目錄為external/ppp)編譯出來的pppoe可執行程式。 首先将部分linux-ppp-script中的相關檔案拷貝到SDK中的對應目錄,如下:
(2)同時,需要修改huawei-ppp-on腳本,内容如下:
#!/bin/sh
#
# Script to initiate a ppp connection. This is the first part of the
# pair of scripts. This is not a secure pair of scripts as the codes
# are visible with the 'ps' command. However, it is simple.
# Modify: fangxiaozhi <[email protected]>
programName=${0##*/}
# These are the parameters. Change as needed.
#DEVICE=/dev/usb/tts/0
#DEVICE=/dev/ttyACM0 #The modem file name of the data card
DEVICE=/dev/ttyUSB0 #The modem file name of the data card
TELEPHONE=*99# # The telephone number for the connection, by default, it will be *99#
ACCOUNT="" # The account name for logon, by default, it will be null
PASSWORD="" # The password for this account, by default, it will be null
AUTH="" # Authentic protocol,byi default, it will be null
APN=1234
STR_USER="user \"card\""
STR_PASSWD="password \"card\""
show_usage(){
echo "usage:"
echo " $programName [--usr=username] [--pwd=password] [--pn=phonenumber][--apn=apn][--auth=authentic protocol]"
echo " [--local_ip=local_ip] [--remote_ip=remote_ip] [--usepeernds=usepeernds]"
echo "username: The account name get from your ISP, by default, it will be null"
echo "password: The password for your account, by default, it will be null"
echo "phonenumber: The phone number for dialing up, by default, it will be *99#"
echo "apn: access point name"
echo "auth: chap/pap. for example: --auth=chap"
exit 0
}
PID=`ps -ef | grep -v grep | grep "huawei-dial" | grep "pppd" | busybox awk '{ print $2; exit }'`
if test $PID; then
echo "PPP link is active"
exit 1
fi
if [ $# -eq 1 -a "$1" = "--help" ]
then
show_usage
fi
for i in "$@"
do
case $i in
--device=*)
echo "--device*=$i"
DEVICE=${i#--device=}
;;
--usr=*)
echo "--usr*=$i"
ACCOUNT=${i#--usr=}
;;
--pwd=*)
echo "--pwd*=$i"
PASSWORD=${i#--pwd=}
;;
--pn=*)
echo "--pn*$i"
TELEPHONE=${i#--pn=}
;;
--apn=*)
echo "--apn*=$i"
APN=${i#--apn=}
;;
--auth=*)
echo "--auth*=$i"
AUTH=${i#--auth=}
if [ "$AUTH" = "chap" ]; then
AUTH=-pap
fi
if [ "$AUTH" = "pap" ]; then
AUTH=-chap
fi
;;
--local_ip=*)
echo "--local_ip*=$i"
PAR_LOCAL=${i#--local_ip=}
;;
--remote_ip=*)
echo "--remote_ip*=$i"
PAR_REMOTE=${i#--remote_ip=}
;;
--usepeernds=*)
echo "--usepeernds*=$i"
PAR_USEERDNS=${i#--usepeernds=}
;;
*)
echo "*=$i"
esac
done
if [ "$PAR_LOCAL" = "" ]; then
LOCAL_IP=0.0.0.0
else
LOCAL_IP=$PAR_LOCAL
fi
if [ "$PAR_REMOTE" = "" ]; then
REMOTE_IP=0.0.0.0
else
REMOTE_IP=$PAR_REMOTE
fi
if [ ! "$PAR_USEERDNS" = "" ]; then
USEPEERDNS=''
for NAMESERVER in `echo $PAR_USEERDNS | awk -F: '{for (i=1;i<=NF;i++) print $i}'`
do
echo "nameserver $NAMESERVER" >> /etc/ppp/resolv.conf
done
else
USEPEERDNS='usepeerdns'
fi
NETMASK=255.255.255.0 # The proper netmask if needed
#
# Export them so that they will be available at 'ppp-on-dialer' time.
export TELEPHONE APN ACCOUNT PASSWORD
#
# This is the location of the script which dials the phone and logs
# in. Please use the absolute file name as the $PATH variable is not
# used on the connect option. (To do so on a 'root' account would be
# a security hole so don't ask.)
#
# Initiate the connection
#
# I put most of the common options on this command. Please, don't
# forget the 'lock' option or some programs such as mgetty will not
# work. The asyncmap and escape will permit the PPP link to work with
# a telnet or rlogin connection. You are welcome to make any changes
# as desired. Don't use the 'defaultroute' option if you currently
# have a default route to an ethernet gateway.
#
if [ ! -d "/data/ppp" ]
then
mkdir /data/ppp
fi
if [ -f "/data/ppp/options" ]
then
echo "" > /data/ppp/options
fi
if [ -f "/data/ppp/pap-secrets" ]
then
chmod 700 /data/ppp/pap-secrets
fi
if [ -f "/data/ppp/chap-secrets" ]
then
chmod 700 /data/ppp/chap-secrets
fi
if [ ! "$ACCOUNT" = "" ]
then
echo "$ACCOUNT * $PASSWORD *" > /data/ppp/pap-secrets
echo "$ACCOUNT * $PASSWORD *" > /data/ppp/chap-secrets
STR_USER="user \"$ACCOUNT\""
STR_PASSWD="password \"$PASSWORD\""
else
echo "* * * *" > /data/ppp/pap-secrets
echo "* * * *" > /data/ppp/chap-secrets
fi
chmod 400 /data/ppp/pap-secrets
chmod 400 /data/ppp/chap-secrets
if [ "$TELEPHONE" = "*99#" ]; then
echo " ABORT \"NO CARRIER\"
ABORT \"NO DIALTONE\"
ABORT \"ERROR\"
ABORT \"NO ANSWER\"
ABORT \"BUSY\"
ABORT \"Username/Password Incorrect\"
\"\" AT
\"OK-+++\c-OK\" ATH0
OK AT+CGDCONT=1,\"IP\",\"$APN\"
OK ATDT$TELEPHONE
CONNECT \"\"
" > /data/ppp/huawei-chat
fi
if [ "$TELEPHONE" = "#777" ]; then
echo -e "at^pppcfg=\"$ACCOUNT\",\"$PASSWORD\"\r\n" > $DEVICE
echo " ABORT \"NO CARRIER\"
ABORT \"NO DIALTONE\"
ABORT \"ERROR\"
ABORT \"NO ANSWER\"
ABORT \"BUSY\"
TIMEOUT 120
ABORT \"Username/Password Incorrect\"
\"\" AT
OK ATDT#777
CONNECT \"\"
" > /data/ppp/huawei-chat
fi
if [ ! -d "/data/ppp/peers" ]
then
mkdir /data/ppp/peers
fi
echo "$DEVICE
115200
crtscts
modem
debug
nodetach
usepeerdns
noipdefault
defaultroute
$LOCAL_IP:$REMOTE_IP
$STR_USER
$STR_PASSWD
noauth
$AUTH
-mschap
-mschap-v2
ipcp-accept-local
ipcp-accept-remote
connect '/system/bin/chat -s -v -f /data/ppp/huawei-chat'
" > /data/ppp/peers/huawei-dial
#/bin/cp ./ip-up /etc/ppp/ip-up
#/bin/cp ./ip-down /etc/ppp/ip-down
exec /system/bin/pppoe call huawei-dial&
exit 0
(3)需要修改external/pppd/pathname.h檔案
#define _PATH_PEERFILES _ROOT_PATH "/etc/ppp/peers/"
改成
#define _PATH_PEERFILES _ROOT_PATH "/data/ppp/peers/"
4. 修改ip-up腳本
#!/system/bin/sh
PPPD_PID_FILE=/data/system/${PHYINTERFACE}_pppd.pid
case $1 in
ppp[1-9])
/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 $1 -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" "gprs";
;;
esac
#just for debug [email protected]
#/system/bin/log -t aw-pppoe "0: $0"
#/system/bin/log -t aw-pppoe "1: $1"
#/system/bin/log -t aw-pppoe "2: $2"
#/system/bin/log -t aw-pppoe "3: $3"
#/system/bin/log -t aw-pppoe "4: $4"
#/system/bin/log -t aw-pppoe "5: $5"
#/system/bin/log -t aw-pppoe "6: $6"
#
#/system/bin/log -t aw-pppoe "LINKNAME: $LINKNAME"
#/system/bin/log -t aw-pppoe "IFNAME: $IFNAME"
#/system/bin/log -t aw-pppoe "DEVICE: $DEVICE"
#/system/bin/log -t aw-pppoe "PPPLOGNAME: $PPPLOGNAME"
#/system/bin/log -t aw-pppoe "PPPD_PID: $PPPD_PID"
#/system/bin/log -t aw-pppoe "PEERNAME: $PEERNAME"
#/system/bin/log -t aw-pppoe "SPEED: $SPEED"
#/system/bin/log -t aw-pppoe "USEPEERDNS: $USEPEERDNS"
#/system/bin/log -t aw-pppoe "LINKINTERFACE: $LINKINTERFACE"
# Use interface name if linkname is not available
NAME="$PHYINTERFACE-"$1""
/system/bin/setprop "net.$NAME.dns1" "$DNS1"
/system/bin/setprop "net.$NAME.dns2" "$DNS2"
/system/bin/setprop "net.$NAME.local-ip" "$IPLOCAL"
/system/bin/setprop "net.$NAME.remote-ip" "$IPREMOTE"
/system/bin/setprop "net.${PHYINTERFACE}-pppoe.phyif" "$1"
/system/bin/setprop "net.${PHYINTERFACE}-pppoe.status" "started"
5. 運作huawei-ppp-on腳本
sh ./huawei-ppp-on --user=card --pwd=card --pn=*99# --auth=chap --apn=1234 正常情況下列印為:
er=card --pwd=card --pn=*99# --auth=chap --apn=1234 <
*=--user=card
--pwd*=--pwd=card
--pn*--pn=*99#
--auth*=--auth=chap
--apn*=--apn=1234
[email protected]:/system/etc/ppp # abort on (NO CARRIER)
abort on (NO DIALTONE)
abort on (ERROR)
abort on (NO ANSWER)
abort on (BUSY)
abort on (Username/Password Incorrect)
send (AT^M)
expect (OK)
AT^M^M
OK
-- got it
send (ATH0^M)
expect (OK)
^M
ATH0^M^M
OK
-- got it
send (AT+CGDCONT=1,"IP","1234"^M)
expect (OK)
^M
AT+CGDCONT=1,"IP","1234"
OK
-- got it
send (ATDT*99#^M)
expect (CONNECT)
ATDT*99#^M^M
CONNECT
-- got it
send
6. 檢視虛拟網卡
執行指令busybox ifconfig,可以看到生成了ppp0網口,如下:
但是此時是無法連接配接網際網路的,因為沒有配置dns
7. 檢視dns
首先看下通過pppoe封包互動獲得dns是什麼,利用指令擷取如下:getprop | grep dns
[net.-ppp0.dns1]: [211.136.20.203]
[net.-ppp0.dns2]: [211.136.17.107]
8. 配置dsn
[email protected]:/system/etc/ppp # setprop net.dns1 211.136.20.203
[email protected]:/system/etc/ppp # setprop net.dns2 211.136.17.107
[email protected]:/system/etc/ppp # ndc resolver setifdns ppp0 "" 211.136.20.203
200 0 Resolver command succeeded
[email protected]:/system/etc/ppp # ndc resolver setdefaultif ppp0
9. ping百度
ping www.baidu.com
PING www.a.shifen.com (183.232.231.173) 56(84) bytes of data.
64 bytes from 183.232.231.173: icmp_seq=1 ttl=55 time=49.2 ms
64 bytes from 183.232.231.173: icmp_seq=2 ttl=55 time=31.4 ms
64 bytes from 183.232.231.173: icmp_seq=3 ttl=55 time=30.6 ms
64 bytes from 183.232.231.173: icmp_seq=4 ttl=55 time=29.7 ms
64 bytes from 183.232.231.173: icmp_seq=5 ttl=55 time=25.6 ms
64 bytes from 183.232.231.173: icmp_seq=6 ttl=55 time=32.8 ms
64 bytes from 183.232.231.173: icmp_seq=7 ttl=55 time=32.6 ms
64 bytes from 183.232.231.173: icmp_seq=8 ttl=55 time=28.5 ms
64 bytes from 183.232.231.173: icmp_seq=9 ttl=55 time=27.5 ms
64 bytes from 183.232.231.173: icmp_seq=10 ttl=55 time=33.8 ms
64 bytes from 183.232.231.173: icmp_seq=11 ttl=55 time=32.2 ms
64 bytes from 183.232.231.173: icmp_seq=12 ttl=55 time=31.3 ms
64 bytes from 183.232.231.173: icmp_seq=13 ttl=55 time=27.2 ms
64 bytes from 183.232.231.173: icmp_seq=14 ttl=55 time=33.6 ms
64 bytes from 183.232.231.173: icmp_seq=15 ttl=55 time=29.4 ms
64 bytes from 183.232.231.173: icmp_seq=16 ttl=55 time=31.2 ms
64 bytes from 183.232.231.173: icmp_seq=17 ttl=55 time=28.7 ms
64 bytes from 183.232.231.173: icmp_seq=18 ttl=55 time=33.5 ms
64 bytes from 183.232.231.173: icmp_seq=19 ttl=55 time=32.4 ms
64 bytes from 183.232.231.173: icmp_seq=20 ttl=55 time=30.1 ms
64 bytes from 183.232.231.173: icmp_seq=21 ttl=55 time=26.7 ms
64 bytes from 183.232.231.173: icmp_seq=22 ttl=55 time=33.5 ms
64 bytes from 183.232.231.173: icmp_seq=23 ttl=55 time=33.5 ms
64 bytes from 183.232.231.173: icmp_seq=24 ttl=55 time=28.5 ms
64 bytes from 183.232.231.173: icmp_seq=25 ttl=55 time=30.8 ms
64 bytes from 183.232.231.173: icmp_seq=26 ttl=55 time=33.6 ms
64 bytes from 183.232.231.173: icmp_seq=27 ttl=55 time=31.8 ms
64 bytes from 183.232.231.173: icmp_seq=28 ttl=55 time=29.5 ms
64 bytes from 183.232.231.173: icmp_seq=29 ttl=55 time=33.6 ms
表明手動測試,可以連接配接網絡了。
10. 通過init.rc進行撥号
device/softwinner/petrel-p1/init.rc中可以修改如下
序列槽中輸入setprop persist.has_LTE 1,即可進行撥号。