您的位置:首页 > 运维架构

openwrt 3G驱动

2015-07-06 15:49 288 查看
在openwrt下面添加3G模块。目前,市场的3G模块大概有两种,一种是插上电脑,直接可以识别出来是USB-3G设备。

对于这种3G模块在openwrt上面的驱动,请参考这篇文章:

/article/10904755.html

本文讨论的是另外一种,插上电脑后,电脑识别出来的一个U盘。需要我们切换成usb-3G。

第一步,请参考这篇文章,编译 openwrt 固件:

/article/10904755.html

在这里。我们需要用到两个软件包:

libusb-1.0
usb-modeswith


openwrt 系统自带有,但是我测试不成功,不清楚为什么。于是我去网上找了其他版本的。

libusb-1.0.9.tar.bz2
usb-modeswitch-2.0.1.tar.bz2
usb-modeswitch-data-20131113.tar.bz2


交叉编译:

首先安装好对应的交叉编译工具链。我用的 mipsel-linux-gcc

libusb:

tar -xvf libusb-1.0.9.tar.bz2
cd libusb-1.0.9
CC=mipsel-linux-gcc ./configure --prefix=$PWD/tmp --host=mipsel-linux --build=i686-linux
make
make install


编译安装后的文件在 当前目录下的 tmp 里面。

进入该目录,把所有的头文件和库文件复制到交叉编译工具链里面

//头文件:
sudo  cp libusb.h /opt/buildroot-gcc342/include/
//lib:
sudo cp * -rfd /opt/buildroot-gcc342/lib/


同时,把库复制到根文件目录下的 lib 目录

sudo cp *so* -d /开发板的lib目录


usb_modeswitch:

修改 Makefile

CC          = mipsel-linux-gcc
CFLAGS      += -Wall
LIBS        = -lusb-1.0 -lpthread


然后执行如下操作:

make DESTDIR=$PWD/tmp
make DESTDIR=$PWD/tmp  install


编译安装后的文件在 当前目录下的 tmp 文件夹里面。

cd tmp
sudo cp * -rfd 开发板根目录


usb-modeswitch-data-20131113:

make DESTDIR=$PWD/tmp install
cd tmp sudo cp * -rfd 开发板根目录


最后一步:

根据VIP/PID在device_reference.txt里找到一段配置值,

device_reference.txt 参考网页:

http://www.draisberghof.de/usb_modeswitch/device_reference.txt

vi /etc/usb_modeswitch.conf

########################################################
# Prolink P2000 CDMA
#
# Test string: uMa=SSE

DefaultVendor= 0x05c6
DefaultProduct=0x1000

TargetVendor=  0x05c6
TargetProduct= 0x6000

MessageContent="5553424312345678000000000000061b000000020000000000000000000000"
NeedResponse=1


执行 usb_modeswitch -c /etc/usb_modeswitch.conf

如果执行后没有在 /dev 目录下生成 ttyUSB* 设备。请重启一次

输入ifconfig,查看是否有 3g-ppp0 。

root@DayDream:/# ifconfig
3g-ppp0   Link encap:Point-to-Point Protocol
inet addr:113.115.110.8  P-t-P:113.115.0.1  Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1500  Metric:1
RX packets:21 errors:0 dropped:0 overruns:0 frame:0
TX packets:23 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:3
RX bytes:1290 (1.2 KiB)  TX bytes:1316 (1.2 KiB)


但是,我尝试ping www.baidu.com

ping 114.114.114.114 都是ping不通,提示如下:

root@DayDream:/# ping www.baidu.com
ping: bad address 'www.baidu.com'

root@DayDream:/# ping 114.114.114.114
PING 114.114.114.114 (114.114.114.114): 56 data bytes
ping: sendto: Network is unreachable


输入 route 。发现没有设置网关:

root@DayDream:/# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
113.115.0.1     *               255.255.255.255 UH    0      0        0 3g-ppp0
192.168.20.0    *               255.255.255.0   U     0      0        0 br-lan


于是,设置上默认网关

route add default gw 113.115.0.1


在尝试一次。发现成功了:

root@DayDream:/# ping www.baidu.com
PING www.baidu.com (180.97.33.107): 56 data bytes
64 bytes from 180.97.33.107: seq=0 ttl=55 time=87.532 ms


下面的操作参考文章:

/article/10904755.html

内核的编译配置

make kernel_ menuconfig

USB串口驱动相关的配置项:

Device Drivers  ---> [*] USB support  --->
<*>   Support for Host-side USB
[*]     USB announce new devices
[*]     Enable USB persist by default
<*>     EHCI HCD (USB 2.0) support
[*]       Root Hub Transaction Translators
[*]       Improved Transaction Translator scheduling
<*>     OHCI HCD (USB 1.1) support
<*>     USB Modem (CDC ACM) support
<*>     USB Printer support
<*>     USB Wireless Device Management support
<*>   USB Serial Converter support  --->
<*>   USB driver for GSM and CDMA modems


PPP拨号的相关配置:

Device Drivers  ---> [*] Network device support  --->
<*>   PPP (point-to-point protocol) support
<*>     PPP BSD-Compress compression
<*>     PPP Deflate compression
[*]     PPP filtering
<*>     PPP MPPE compression (encryption)
[*]     PPP multilink support
<*>     PPP over Ethernet
<*>     PPP support for async serial ports
<*>     PPP support for sync tty ports


所需软件包:

ppp
chat
comgt
librt
libusb-1.0
usb-modeswith
zlib


保存 执行make V=99 后将编译好的镜像文件烧写到开发板。然后启动开发板

配置 网络

/etc/config/network
config interface 'ppp0'
option ifname 'ppp0'
option service 'evdo'
option username 'card'
option password 'card'
option device '/dev/ttyUSB0'
option proto '3g'
option dialnumber '#777'
option apn 'ctnet'
option auto 1


重启网络

/etc/init.d/netwrok restart
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: