树莓派 android 3g,树莓派--USB 3G网卡的移植(华为E353、ZTE AD3812)

要给pi装一个usb 3G的网卡。

1:准备工作

网上对3G网卡的移植讲解的帖子很多,也看了不少,基本原理概括下来就是:

A:usb 3G网卡比较新的内核基本都是有驱动支持的,pi的内核是3.1XX了,所以不需要再去编译内核了。

B:在linux上,3G网卡上电会被检测为storge设备,而要用它拨号上网,就需要把网卡从storge设备转为modem设备,怎么转化呢?linux下有个软件叫usb_modeswitch,这是需要安装的第1个软件。

C:usb 3G网卡使用的是pppd拨号上网,内核好像有,具体我也没测试过,反正是安装了一个,这个是安装的第2个软件。

D:为了简化pppd的拨号流程(传统方式要编写好几个脚本,调用几次pppd的命令),需要一个wvdial的软件,它将pppd的拨号流程简化为一个配置脚本,写好脚本,运行wvdial,它会先完成和modem的AT命令交互,待交互完成后,再调用pppd,完成拨号上网。这是需要安装的第3个软件。

2:步骤

A:安装usb_modeswitch

1.apt-get install usb-modeswitch usb-modeswitch-data

安装两个东西,一个是软件,一个是众多usb设备的设备号和转换代码的列表,这个待会儿用的到

B:安装pppd

1.apt-get install pppd

C:安装wvdial

1.apt-get install wvdial

D:查看当前设备的设备号

1.lsusb

a4c26d1e5885305701be709a3d33442f.png

这里在存储设备下的设备号是12d1(华为的东西都是这个号)和14fe,转换成功后会变成1506,当然也有的是不变的。

E:根据刚才的设备号,查找转化文件,生成配置文件

1.tar -xzvf /usr/share/usb_modeswitch/configPack.tar.gz12d1\:14fe

打开文件,就看到了它的转换码

a4c26d1e5885305701be709a3d33442f.png

这时,直接用把这个文件的路径作为下一个步骤中的转换文件的路径,也可以像很多帖子里说的一样,把它添加到/etc/usb_modeswitch.conf文件中。也有的说可以直接在usb_modeswitch.d文件夹下添加命令就能设备默认路径,反正我是设置了没有成功= =!索性就在命令上价格路径吧,反正以后都是写成开机运行的...

在usb_modeswitch.conf文件的最末尾输入下面的内容。

a4c26d1e5885305701be709a3d33442f.png

上面的Default的两行就是刚才lsusb看到的,下面就是刚才看到的文件里的内容了!

F:输入usb_modeswitch命令完成转换

这一步之前一直不成功,ZTE的AD3812上电之后就能自动转换,可是华为的这个352死活就是不行。要完成转换,一般输入以下命令:

1.usb_modeswitch -W -c /etc/usb_modeswitch.conf

但是悲剧事情就发生了!

a4c26d1e5885305701be709a3d33442f.png

原因是usb_modeswitch的转换方式所致,原因见(http://www.draisberghof.de/usb_modeswitch/#hardware)

Very important note:

Personally, I could not test the vast majority of supported devices; the list here - as well as the necessary data - relies on reports from third parties (people, that is). So it may happen that you hit sudden obstacles even with your device listed here.That said, the user base of this little tool has grown considerably, so that any data related problems are generally surfacing quite soon.

There are hitherto three known methods for initiating the switching process:

1.sending a rarely used or seemingly weird standard storage command (equivalent to those of SCSI) to the storage device ("eject" for example)

2.sending one or more vendor-specific control messages to the device

3.actively removing (detaching) the storage driver from the device (only some early devices)

Again,if you don't find the name of your device in the list, it may still be supported.The important thing is that you find your device's USB ID in the config file folder. Have a look into the latest data package (SeeDownload).

Here is the list of devices, together with the respective contributors:

就是这个第一个动作导致了转换不成功!因此命令要改为(增加-I选项)

1.usb_modeswitch -W -c /etc/usb_modeswitch.conf -I

成功之后lsusb,可以看到模式已经转变:ls /dev/可以看到多了ttyUSB0~ttyUSB2

a4c26d1e5885305701be709a3d33442f.png

a4c26d1e5885305701be709a3d33442f.png

G:运行wvdialconf命令,看看这3个哪个是可以接收AT命令的

a4c26d1e5885305701be709a3d33442f.png

H:编写wvdial的配置文件,这里需要注意几点!首先,tty设备一定要选对,最简单的方式就是两个都试一下!之前就是选错了,老是提示modem hung up!还有就是拨号的几个参数要写对,联通的号码是#99*,接入点是3gnet,这几个不写对也是不行的!最后就是Auto DNS,没有这个也不好上网的!具体的配置文件如下:(可以用Dialer编写多个硬件的配置)

[Dialer HW]

Init1 = ATZ

Init2 = ATQ0 V1 E1 S0=0 &C1 &D2

Init3 = AT+CGDCONT=1,"IP","3gnet"

Password = ppp

Phone = *99#

Modem Type = Analog Modem

Stupid Mode = 1

Baud = 9600

Auto DNS = on

Modem = /dev/ttyUSB0

ISDN = 0

Username = ppp

;Carrier Check = off

;New PPPD = yes

[Dialer ZTE]

Init1 = ATZ

Init2 = ATQ0 V1 E1 S0=0 &C1 &D2

Init3 = AT+CGDCONT=1,"IP","3gnet"

Password = ppp

Phone = *99#

Modem Type = Analog Modem

Stupid Mode = 1

Baud = 9600

Auto DNS = on

Modem = /dev/ttyUSB3

ISDN = 0

Username = ppp

;Carrier Check = off

;New PPPD = yes

H:运行脚本,wvdial HW,拨号上网!

I:修改路由表

因为我把eth0的ip设置成了静态ip,设置方法如下:

nano /etc/network/interfaces /etc/network/interfacesbak #备份原有配置文件 nano /etc/network/interfaces #编辑网网卡配置文件 auto lo auto eth0 #开机自动连接网络 iface lo inet loopback allow-hotplug eth0 //有线网卡 iface eth0 inet static #static表示使用固定ip,dhcp表述使用动态ip address 192.168.21.166 #设置ip地址 netmask 255.255.255.0 #设置子网掩码 gateway192.168.21.2 #设置网关 ctrl+o #保存配置 因此,我的路由表默认路由的出口是eth0,显然是不能上网的,要上网需要删除该路由,并重新添加ppp0的路由,命令如下:

route del -net 0.0.0.0

route add default dev ppp0

最后路由表变成这样了:

a4c26d1e5885305701be709a3d33442f.png

最后,ping一下百度,证明成功了!

a4c26d1e5885305701be709a3d33442f.png

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值