我是靠谱客的博主 孝顺香水,最近开发中收集的这篇文章主要介绍全志平台华为4G模块开发调试记录1. 前言2. linux部分3. android部分4. 修改ip-up脚本5. 运行huawei-ppp-on脚本6. 查看虚拟网卡7. 查看dns8. 配置dsn9. ping百度10. 通过init.rc进行拨号,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

以下技术在盈鹏飞嵌入式的A40I/T3核心板(CoM-X40I)和主控板(SBC-X40I)上经过验证,欢迎 交流! CoM-X40I核心板和SBC-X40I主板见下图:
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

1. 前言

因为需要适配4G模块,这里总结下整个调试过程;

2. linux部分

linux 部分主要是硬件识别,当拿到模块后,插入板子上,打印如下:


   
   
  1. [ 185.120132] usb 3- 1: new high-speed USB device number 2 using xhci-hcd
  2. [ 185.141610] usb 3- 1: New USB device found, idVendor= 12d1, idProduct= 15c1
  3. [ 185.149447] usb 3- 1: New USB device strings: Mfr= 1, Product= 2, SerialNumber= 3
  4. [ 185.157830] usb 3- 1: Product: HUAWEI Mobile V7R11
  5. [ 185.164667] usb 3- 1: Manufacturer: Huawei Technologies Co., Ltd.
  6. [ 185.171450] usb 3- 1: SerialNumber: 0123456789ABCDEF
  7. [ 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
  8. [ 185.271723] option 3- 1: 2.2: GSM modem ( 1-port) converter detected
  9. [ 185.286827] usb 3- 1: GSM modem ( 1-port) converter now attached to ttyUSB0
  10. [ 185.295963] option 3- 1: 2.3: GSM modem ( 1-port) converter detected
  11. [ 185.304478] usb 3- 1: GSM modem ( 1-port) converter now attached to ttyUSB1
  12. [ 185.313672] option 3- 1: 2.4: GSM modem ( 1-port) converter detected
  13. [ 185.320886] CPU1: Booted secondary processor
  14. [ 185.320886] CPU1: update cpu_power 1024
  15. [ 185.332151] usb 3- 1: GSM modem ( 1-port) converter now attached to ttyUSB2
  16. [ 185.341133] option 3- 1: 2.5: GSM modem ( 1-port) converter detected
  17. [ 185.350048] usb 3- 1: GSM modem ( 1-port) converter now attached to ttyUSB3
  18. [ 185.358760] option 3- 1: 2.6: GSM modem ( 1-port) converter detected
  19. [ 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脚本,内容如下:


   
   
  1. #!/bin/sh
  2. #
  3. # Script to initiate a ppp connection. This is the first part of the
  4. # pair of scripts. This is not a secure pair of scripts as the codes
  5. # are visible with the 'ps' command. However, it is simple.
  6. # Modify: fangxiaozhi <huananhu@huawei.com>
  7. programName= ${0##*/}
  8. # These are the parameters. Change as needed.
  9. #DEVICE=/dev/usb/tts/0
  10. #DEVICE=/dev/ttyACM0 #The modem file name of the data card
  11. DEVICE=/dev/ttyUSB0 #The modem file name of the data card
  12. TELEPHONE=*99 # # The telephone number for the connection, by default, it will be *99#
  13. ACCOUNT= "" # The account name for logon, by default, it will be null
  14. PASSWORD= "" # The password for this account, by default, it will be null
  15. AUTH= "" # Authentic protocol,byi default, it will be null
  16. APN=1234
  17. STR_USER= "user "card""
  18. STR_PASSWD= "password "card""
  19. show_usage(){
  20. echo "usage:"
  21. echo " $programName [--usr=username] [--pwd=password] [--pn=phonenumber][--apn=apn][--auth=authentic protocol]"
  22. echo " [--local_ip=local_ip] [--remote_ip=remote_ip] [--usepeernds=usepeernds]"
  23. echo "username: The account name get from your ISP, by default, it will be null"
  24. echo "password: The password for your account, by default, it will be null"
  25. echo "phonenumber: The phone number for dialing up, by default, it will be *99#"
  26. echo "apn: access point name"
  27. echo "auth: chap/pap. for example: --auth=chap"
  28. exit 0
  29. }
  30. PID=`ps -ef | grep -v grep | grep "huawei-dial" | grep "pppd" | busybox awk '{ print $2; exit }'`
  31. if test $PID; then
  32. echo "PPP link is active"
  33. exit 1
  34. fi
  35. if [ $# -eq 1 -a "$1" = "--help" ]
  36. then
  37. show_usage
  38. fi
  39. for i in "$@"
  40. do
  41. case $i in
  42. --device=*)
  43. echo "--device*=$i"
  44. DEVICE= ${i#--device=}
  45. ;;
  46. --usr=*)
  47. echo "--usr*=$i"
  48. ACCOUNT= ${i#--usr=}
  49. ;;
  50. -- pwd=*)
  51. echo "--pwd*=$i"
  52. PASSWORD= ${i#--pwd=}
  53. ;;
  54. --pn=*)
  55. echo "--pn*$i"
  56. TELEPHONE= ${i#--pn=}
  57. ;;
  58. --apn=*)
  59. echo "--apn*=$i"
  60. APN= ${i#--apn=}
  61. ;;
  62. --auth=*)
  63. echo "--auth*=$i"
  64. AUTH= ${i#--auth=}
  65. if [ "$AUTH" = "chap" ]; then
  66. AUTH=-pap
  67. fi
  68. if [ "$AUTH" = "pap" ]; then
  69. AUTH=-chap
  70. fi
  71. ;;
  72. --local_ip=*)
  73. echo "--local_ip*=$i"
  74. PAR_LOCAL= ${i#--local_ip=}
  75. ;;
  76. --remote_ip=*)
  77. echo "--remote_ip*=$i"
  78. PAR_REMOTE= ${i#--remote_ip=}
  79. ;;
  80. --usepeernds=*)
  81. echo "--usepeernds*=$i"
  82. PAR_USEERDNS= ${i#--usepeernds=}
  83. ;;
  84. *)
  85. echo "*=$i"
  86. esac
  87. done
  88. if [ "$PAR_LOCAL" = "" ]; then
  89. LOCAL_IP=0.0.0.0
  90. else
  91. LOCAL_IP= $PAR_LOCAL
  92. fi
  93. if [ "$PAR_REMOTE" = "" ]; then
  94. REMOTE_IP=0.0.0.0
  95. else
  96. REMOTE_IP= $PAR_REMOTE
  97. fi
  98. if [ ! "$PAR_USEERDNS" = "" ]; then
  99. USEPEERDNS= ''
  100. for NAMESERVER in ` echo $PAR_USEERDNS | awk -F: '{for (i=1;i<=NF;i++) print $i}'`
  101. do
  102. echo "nameserver $NAMESERVER" >> /etc/ppp/resolv.conf
  103. done
  104. else
  105. USEPEERDNS= 'usepeerdns'
  106. fi
  107. NETMASK=255.255.255.0 # The proper netmask if needed
  108. #
  109. # Export them so that they will be available at 'ppp-on-dialer' time.
  110. export TELEPHONE APN ACCOUNT PASSWORD
  111. #
  112. # This is the location of the script which dials the phone and logs
  113. # in. Please use the absolute file name as the $PATH variable is not
  114. # used on the connect option. (To do so on a 'root' account would be
  115. # a security hole so don't ask.)
  116. #
  117. # Initiate the connection
  118. #
  119. # I put most of the common options on this command. Please, don't
  120. # forget the 'lock' option or some programs such as mgetty will not
  121. # work. The asyncmap and escape will permit the PPP link to work with
  122. # a telnet or rlogin connection. You are welcome to make any changes
  123. # as desired. Don't use the 'defaultroute' option if you currently
  124. # have a default route to an ethernet gateway.
  125. #
  126. if [ ! -d "/data/ppp" ]
  127. then
  128. mkdir /data/ppp
  129. fi
  130. if [ -f "/data/ppp/options" ]
  131. then
  132. echo "" > /data/ppp/options
  133. fi
  134. if [ -f "/data/ppp/pap-secrets" ]
  135. then
  136. chmod 700 /data/ppp/pap-secrets
  137. fi
  138. if [ -f "/data/ppp/chap-secrets" ]
  139. then
  140. chmod 700 /data/ppp/chap-secrets
  141. fi
  142. if [ ! "$ACCOUNT" = "" ]
  143. then
  144. echo "$ACCOUNT * $PASSWORD *" > /data/ppp/pap-secrets
  145. echo "$ACCOUNT * $PASSWORD *" > /data/ppp/chap-secrets
  146. STR_USER= "user "$ACCOUNT""
  147. STR_PASSWD= "password "$PASSWORD""
  148. else
  149. echo "* * * *" > /data/ppp/pap-secrets
  150. echo "* * * *" > /data/ppp/chap-secrets
  151. fi
  152. chmod 400 /data/ppp/pap-secrets
  153. chmod 400 /data/ppp/chap-secrets
  154. if [ "$TELEPHONE" = "*99#" ]; then
  155. echo " ABORT "NO CARRIER"
  156. ABORT "NO DIALTONE"
  157. ABORT "ERROR"
  158. ABORT "NO ANSWER"
  159. ABORT "BUSY"
  160. ABORT "Username/Password Incorrect"
  161. "" AT
  162. "OK-+++c-OK" ATH0
  163. OK AT+CGDCONT=1,"IP","$APN"
  164. OK ATDT$TELEPHONE
  165. CONNECT ""
  166. " > /data/ppp/huawei-chat
  167. fi
  168. if [ "$TELEPHONE" = "#777" ]; then
  169. echo -e "at^pppcfg="$ACCOUNT","$PASSWORD"rn" > $DEVICE
  170. echo " ABORT "NO CARRIER"
  171. ABORT "NO DIALTONE"
  172. ABORT "ERROR"
  173. ABORT "NO ANSWER"
  174. ABORT "BUSY"
  175. TIMEOUT 120
  176. ABORT "Username/Password Incorrect"
  177. "" AT
  178. OK ATDT#777
  179. CONNECT ""
  180. " > /data/ppp/huawei-chat
  181. fi
  182. if [ ! -d "/data/ppp/peers" ]
  183. then
  184. mkdir /data/ppp/peers
  185. fi
  186. echo "$DEVICE
  187. 115200
  188. crtscts
  189. modem
  190. debug
  191. nodetach
  192. usepeerdns
  193. noipdefault
  194. defaultroute
  195. $LOCAL_IP:$REMOTE_IP
  196. $STR_USER
  197. $STR_PASSWD
  198. noauth
  199. $AUTH
  200. -mschap
  201. -mschap-v2
  202. ipcp-accept-local
  203. ipcp-accept-remote
  204. connect '/system/bin/chat -s -v -f /data/ppp/huawei-chat'
  205. " > /data/ppp/peers/huawei-dial
  206. #/bin/cp ./ip-up /etc/ppp/ip-up
  207. #/bin/cp ./ip-down /etc/ppp/ip-down
  208. exec /system/bin/pppoe call huawei-dial&
  209. exit 0

(3)需要修改external/pppd/pathname.h文件


   
   
  1. #define _PATH_PEERFILES _ROOT_PATH "/etc/ppp/peers/"
  2. 改成
  3. #define _PATH_PEERFILES _ROOT_PATH "/data/ppp/peers/"

4. 修改ip-up脚本


   
   
  1. #!/system/bin/sh
  2. PPPD_PID_FILE=/data/system/ ${PHYINTERFACE}_pppd.pid
  3. case $1 in
  4. ppp[1-9])
  5. /android/bin/iptables --flush;
  6. /android/bin/iptables --table nat --flush;
  7. /android/bin/iptables --delete-chain;
  8. /android/bin/iptables --table nat --append POSTROUTING --out-interface ppp0 -j MASQUERADE;
  9. /android/bin/iptables --append FORWARD --in-interface $1 -j ACCEPT;
  10. echo 0 > /proc/sys/net/ipv4/ip_forward;
  11. echo 1 > /proc/sys/net/ipv4/ip_forward;
  12. ;;
  13. ppp0)
  14. /system/bin/setprop "net.interfaces.defaultroute" "gprs";
  15. ;;
  16. esac
  17. #just for debug ...............shuge@allwinnertech.com
  18. #/system/bin/log -t aw-pppoe "0: $0"
  19. #/system/bin/log -t aw-pppoe "1: $1"
  20. #/system/bin/log -t aw-pppoe "2: $2"
  21. #/system/bin/log -t aw-pppoe "3: $3"
  22. #/system/bin/log -t aw-pppoe "4: $4"
  23. #/system/bin/log -t aw-pppoe "5: $5"
  24. #/system/bin/log -t aw-pppoe "6: $6"
  25. #
  26. #/system/bin/log -t aw-pppoe "LINKNAME: $LINKNAME"
  27. #/system/bin/log -t aw-pppoe "IFNAME: $IFNAME"
  28. #/system/bin/log -t aw-pppoe "DEVICE: $DEVICE"
  29. #/system/bin/log -t aw-pppoe "PPPLOGNAME: $PPPLOGNAME"
  30. #/system/bin/log -t aw-pppoe "PPPD_PID: $PPPD_PID"
  31. #/system/bin/log -t aw-pppoe "PEERNAME: $PEERNAME"
  32. #/system/bin/log -t aw-pppoe "SPEED: $SPEED"
  33. #/system/bin/log -t aw-pppoe "USEPEERDNS: $USEPEERDNS"
  34. #/system/bin/log -t aw-pppoe "LINKINTERFACE: $LINKINTERFACE"
  35. # Use interface name if linkname is not available
  36. NAME= "$PHYINTERFACE-" $1 ""
  37. /system/bin/setprop "net.$NAME.dns1" "$DNS1"
  38. /system/bin/setprop "net.$NAME.dns2" "$DNS2"
  39. /system/bin/setprop "net.$NAME.local-ip" "$IPLOCAL"
  40. /system/bin/setprop "net.$NAME.remote-ip" "$IPREMOTE"
  41. /system/bin/setprop "net.${PHYINTERFACE}-pppoe.phyif" "$1"
  42. /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 正常情况下打印为:


   
   
  1. er =card --pwd=card --pn=*99# --auth=chap --apn=1234 <
  2. * = --user=card
  3. --pwd*=--pwd=card
  4. --pn*--pn=*99#
  5. --auth*=--auth=chap
  6. --apn*=--apn=1234
  7. root @petrel -p1: / system /etc /ppp # abort on ( NO CARRIER)
  8. abort on ( NO DIALTONE)
  9. abort on (ERROR)
  10. abort on ( NO ANSWER)
  11. abort on (BUSY)
  12. abort on (Username /Password Incorrect)
  13. send ( AT ^M)
  14. expect (OK)
  15. AT ^M ^M
  16. OK
  17. -- got it
  18. send (ATH0 ^M)
  19. expect (OK)
  20. ^M
  21. ATH0 ^M ^M
  22. OK
  23. -- got it
  24. send ( AT +CGDCONT = 1,"IP","1234" ^M)
  25. expect (OK)
  26. ^M
  27. AT +CGDCONT = 1,"IP","1234"
  28. OK
  29. -- got it
  30. send (ATDT * 99# ^M)
  31. expect ( CONNECT)
  32. ATDT * 99# ^M ^M
  33. CONNECT
  34. -- got it
  35. send

6. 查看虚拟网卡

执行命令busybox ifconfig,可以看到生成了ppp0网口,如下:

但是此时是无法连接互联网的,因为没有配置dns

7. 查看dns

首先看下通过pppoe报文交互获得dns是什么,利用命令获取如下:getprop | grep dns


   
   
  1. [ net.-ppp0.dns1]: [ 211.136 .20 .203]
  2. [ net.-ppp0.dns2]: [ 211.136 .17 .107]

8. 配置dsn


   
   
  1. root@petrel-p1: /system/etc/ppp # setprop net.dns1 211.136.20.203
  2. root@petrel-p1: /system/etc/ppp # setprop net.dns2 211.136.17.107
  3. root@petrel-p1: /system/etc/ppp # ndc resolver setifdns ppp0 "" 211.136.20.203
  4. 200 0 Resolver command succeeded
  5. root@petrel-p1: /system/etc/ppp # ndc resolver setdefaultif ppp0

9. ping百度

ping www.baidu.com


   
   
  1. PING www.a.shifen.com ( 183.232 .231 .173) 56( 84) bytes of data.
  2. 64 bytes from 183.232 .231 .173: icmp_seq= 1 ttl= 55 time= 49.2 ms
  3. 64 bytes from 183.232 .231 .173: icmp_seq= 2 ttl= 55 time= 31.4 ms
  4. 64 bytes from 183.232 .231 .173: icmp_seq= 3 ttl= 55 time= 30.6 ms
  5. 64 bytes from 183.232 .231 .173: icmp_seq= 4 ttl= 55 time= 29.7 ms
  6. 64 bytes from 183.232 .231 .173: icmp_seq= 5 ttl= 55 time= 25.6 ms
  7. 64 bytes from 183.232 .231 .173: icmp_seq= 6 ttl= 55 time= 32.8 ms
  8. 64 bytes from 183.232 .231 .173: icmp_seq= 7 ttl= 55 time= 32.6 ms
  9. 64 bytes from 183.232 .231 .173: icmp_seq= 8 ttl= 55 time= 28.5 ms
  10. 64 bytes from 183.232 .231 .173: icmp_seq= 9 ttl= 55 time= 27.5 ms
  11. 64 bytes from 183.232 .231 .173: icmp_seq= 10 ttl= 55 time= 33.8 ms
  12. 64 bytes from 183.232 .231 .173: icmp_seq= 11 ttl= 55 time= 32.2 ms
  13. 64 bytes from 183.232 .231 .173: icmp_seq= 12 ttl= 55 time= 31.3 ms
  14. 64 bytes from 183.232 .231 .173: icmp_seq= 13 ttl= 55 time= 27.2 ms
  15. 64 bytes from 183.232 .231 .173: icmp_seq= 14 ttl= 55 time= 33.6 ms
  16. 64 bytes from 183.232 .231 .173: icmp_seq= 15 ttl= 55 time= 29.4 ms
  17. 64 bytes from 183.232 .231 .173: icmp_seq= 16 ttl= 55 time= 31.2 ms
  18. 64 bytes from 183.232 .231 .173: icmp_seq= 17 ttl= 55 time= 28.7 ms
  19. 64 bytes from 183.232 .231 .173: icmp_seq= 18 ttl= 55 time= 33.5 ms
  20. 64 bytes from 183.232 .231 .173: icmp_seq= 19 ttl= 55 time= 32.4 ms
  21. 64 bytes from 183.232 .231 .173: icmp_seq= 20 ttl= 55 time= 30.1 ms
  22. 64 bytes from 183.232 .231 .173: icmp_seq= 21 ttl= 55 time= 26.7 ms
  23. 64 bytes from 183.232 .231 .173: icmp_seq= 22 ttl= 55 time= 33.5 ms
  24. 64 bytes from 183.232 .231 .173: icmp_seq= 23 ttl= 55 time= 33.5 ms
  25. 64 bytes from 183.232 .231 .173: icmp_seq= 24 ttl= 55 time= 28.5 ms
  26. 64 bytes from 183.232 .231 .173: icmp_seq= 25 ttl= 55 time= 30.8 ms
  27. 64 bytes from 183.232 .231 .173: icmp_seq= 26 ttl= 55 time= 33.6 ms
  28. 64 bytes from 183.232 .231 .173: icmp_seq= 27 ttl= 55 time= 31.8 ms
  29. 64 bytes from 183.232 .231 .173: icmp_seq= 28 ttl= 55 time= 29.5 ms
  30. 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,即可进行拨号。

最后

以上就是孝顺香水为你收集整理的全志平台华为4G模块开发调试记录1. 前言2. linux部分3. android部分4. 修改ip-up脚本5. 运行huawei-ppp-on脚本6. 查看虚拟网卡7. 查看dns8. 配置dsn9. ping百度10. 通过init.rc进行拨号的全部内容,希望文章能够帮你解决全志平台华为4G模块开发调试记录1. 前言2. linux部分3. android部分4. 修改ip-up脚本5. 运行huawei-ppp-on脚本6. 查看虚拟网卡7. 查看dns8. 配置dsn9. ping百度10. 通过init.rc进行拨号所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(42)

评论列表共有 0 条评论

立即
投稿
返回
顶部