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

这里主要记录一下应用层如何配置自动上网,前提是内核已经配置好驱动,在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:1506

SUBSYSTEM=="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 script

SUBSYSTEM=="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 created

sleep 1

if [ ! -c "/dev/ttyUSB0" ];then

exit

fi

my_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 ppp0

while 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

fi

done

echo "$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/ttyUSB2

115200

crtscts

connect '/usr/sbin/chat -v -f /etc/ppp/chat/unicom-chat'

debug

nodetach

ipcp-accept-local

ipcp-accept-remote

# Use this connection as the default route

defaultroute

# 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

"" AT

OK "AT+CGDCONT=1,"IP","3GNET""

OK ATD*99#

CONNECT

# end of unicom-chat

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值