嵌入式linux下 华为E353模块3G自动上网配置

来源:互联网 发布:ios java jit 编辑:程序博客网 时间:2024/06/06 03:45

这里主要记录一下应用层如何配置自动上网,前提是内核已经配置好驱动,在option.c中添加了相应的ID。

内核中如何配置,请自行搜索。


相关应用层软件:

 usb_modeswitch

 udev

 pppd 

 chat

 以上软件除udev外,其他的都需要移植,如何移植请自行搜索。

 

硬件:HUAWEI E353s 3G dongle 带中国联通3G上网SIM卡


1. usb_modeswitch 配置

插入上网卡到主机USB接口,lsusb 一下,发现上网卡识别为 12d1:14fe,如下

Bus 002 Device 043: ID 12d1:14fe Huawei Technologies Co., Ltd.


sudo vi /etc/usb_modeswitch.d/huawei.conf,添加如下内容后保存

########################################################
# Huawei, newer modems


DefaultVendor=0x12d1
DefaultProduct=0x14fe


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


CheckSuccess=20


MessageContent="55534243123456780000000000000011062000000100000000000000000000"

其中0x14fe要与lsusb后显示的对应


2. udev配置

cd  /etc/udev/rules.d

sudo vi 70-huawei-3G-dongle.rules,添加如下内容后保存

# add for HUAWEI E353 3G dongle# usb_modeswitch from 12d1:14fe ==> 12d1:1506SUBSYSTEM=="usb", ATTR{idVendor}=="12d1", ATTR{idProduct}=="14fe", MODE="0666", RUN+="/usr/sbin/usb_modeswitch -c /etc/usb_modeswitch.d/huawei.conf"# if switch success, run our scriptSUBSYSTEM=="usb", ATTR{idVendor}=="12d1", ATTR{idProduct}=="1506",MODE="0666", RUN+="/sbin/3g-dongle-cfg.sh"

说明:当系统检测到pid:vid 为12d1:14fe的usb设备时,运行

/usr/sbin/usb_modeswitch -c /etc/usb_modeswitch.d/huawei.conf 会把设备转化为12d1:1506的上网卡设备

而当转化完成后系统会检测到12d1:1506,然后自动运行我们的脚本/sbin/3g-dongle-cfg.sh


3. 脚本/sbin/3g-dongle-cfg.sh 内容如下:

#!/bin/sh# wait for /dev/ttyUSB* be createdsleep 1 if [ ! -c "/dev/ttyUSB0" ];then        exitfimy_name=${0##*/}max_tty=`ls -r /dev/ttyUSB*|sed -n 1p $list`max=${max_tty##*B}a="/dev/ttyUSB$((max-2))"b="/dev/ttyUSB$((max-1))"c="/dev/ttyUSB$max"#sudo ip rou delete default#sudo ip rou add default via 117.207.216.1 dev ppp0while true;do        if [ -c "$a" ] && [ -c "$b" ] && [ -c "$c" ] ;then                echo "$my_name: start config 3G dongle $a $b $c..." > /dev/kmsg                echo "$c" > /tmp/3g_$max-peers                cat /tmp/3g_$max-peers /etc/ppp/peers/unicom-peers > /etc/ppp/peers/3g_$max-peers                pppd call 3g_$max-peers > /dev/kmsg # it should be blocked                sleep 2        else                if [ -f "/tmp/3g_$max-peers" ];then rm /tmp/3g_$max-peers;fi                if [ -f "/etc/ppp/peers/3g_$max-peers" ];then rm /etc/ppp/peers/3g_$max-peers;fi                break        fidoneecho "$my_name:3G dongle $c removed,bye ..." > /dev/kmsg

当转化为12d1:1506的设备后,驱动自动添加3个设备 ttyUSBx、ttyUSBy、ttyUSBz,这里xyz为连续的3个数字,如0、1、2

这个网卡使用ttyUSBz(也就是最大数字的那个口)作为AT命令口。


4. pppd和chat脚本

 pppd脚本:cat /etc/ppp/peers/unicom-peers

##******************************************************************## /etc/ppp/peers/unicom-peers ## this is ppp script for use chinaunicom's WCDMA data service ##******************************************************************## note: If the kernel creat ttyUSB0 ttyUSB1 ttyUSB2 for our 3G dongle# We should use ttyUSB2 for AT command #/dev/ttyUSB2115200crtsctsconnect '/usr/sbin/chat -v -f /etc/ppp/chat/unicom-chat'debugnodetachipcp-accept-localipcp-accept-remote# Use this connection as the default routedefaultroute# Makes pppd "dial again" when the connection is lost.persist# Try to get the name server addresses from the ISP.usepeerdns# end of unicom

chat 脚本:

cat /etc/ppp/chat/unicom-chat:

#******************************************************************## /etc/ppp/chat/unicom-chat ## this is the chat script for unicom ## *****************************************************************#ABORT "NO CARRIER"ABORT "NO DIALTONE"ABORT "ERROR"ABORT "NO ANSWER"ABORT "BUSY"TIMEOUT 120"" ATOK "AT+CGDCONT=1,\"IP\",\"3GNET\""OK ATD*99#CONNECT# end of unicom-chat


0 0
原创粉丝点击