温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

嵌入式Linux下3G无线上网卡的驱动

发布时间:2020-03-03 06:16:07 来源:网络 阅读:962 作者:Linux_woniu 栏目:系统运维

内核:需要有以下模块:option usbserial usbstorage

主要是要在编译内核的时候选中

[*] 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

[*] USB support  --->

       <*>     USB Modem (CDC ACM) support

[*] USB support  --->

    <*>   USB Serial Converter support  --->

              <*>   USB driver for GSM and CDMA modems

修改linux-2.6.21.x/drivers/usb/serial/option.c

#define HUAWEI_WENDIR_ID 0x12d1

#define HUAWEI_PRODUCT_ECxx 0x14ef

{USB_DEVICE(HUAWEI_WENDIR_ID,HUAWEI_PRODUCT_ECxx)} /*HUAWEI  xxx*/

#make modules                       //编译外挂模块

#make modules_install            //安装模块

#usbserial.ko,option.ko

模块编译完后应将其复制到开发板上,并执行以下命令,否则会报找不到modules.dep

#depmod –a                    //创建模块的链接

#modprobe usbserial.ko

# modprobe option.ko

软件4个:libusb、usb_modeswitch、pppd、usb-modeswitch-data(交叉编译)

#lsusb、usb_modeswitch、(lib文件夹)、chat、pppd等移植到开发板。

这个数据包包含了usb_modeswitch所有支持的3G上网卡的配置文件。

1.在开发板上USB口插入3G上网卡。

2.在开发板上输入lsusb会出现以下结果,说明开发板与3G上网卡硬件物理上连接成功,记下12d1:14ef这个数字,后边用。

# lsusb

Bus 004 Device 002: ID 12d1:14ef HUAWEI XXXX(省略若干)

这里若无lsusb命令,可以查看/proc/bus/usb/devices下的响应设备信息。其中:

#cat /proc/bus/usb/devices

Vendor=12d1 ProdID=14ef

3.编辑usb_modeswitch目录下的usb_modeswitch.conf文件

# T-Mobile NL (Huawei xxx)

#

# Contributor: Alex Hermann

DefaultVendor= 0x12d1

DefaultProduct=0x14ef

TargetVendor= 0x12d1

TargetProduct= 0x1506

MessageContent="55534243123456780000000000000011062000000100000000000000000000"

CheckSuccess=5

4.执行usb_modeswitch将3G上网卡U盘模式转换为modem模式

#./usb_modeswitch -c /etc/usb_modeswitch/usb_modeswitch.conf

Looking for target devices ...

 No devices in target mode or class found

Looking for default devices ...

   found matching product ID

   adding device

 Found device in default mode, class or configuration (1)

Accessing device 003 on bus 001 ...

Getting the current device configuration ...

 OK, got current device configuration (1)

Using first interface: 0x00

Using endpoints 0x08 (out) and 0x87 (in)

Inquiring device details; driver will be detached ...

Looking for active driver ...

 OK, driver found ("usb-storage")

 OK, driver "usb-storage" detached

SCSI inquiry data (for identification)

-------------------------

  Vendor String: HUAWEI  

  Model String: Mass Storage    

  Revision String: 2.31

-------------------------

USB description data (for identification)

-------------------------

  Manufacturer: HUAEI TECHNOLOGIES

  Product: HUAWEI Mobile

  Serial No.: not provided

-------------------------

Setting up communication with interface 0

Using endpoint 0x08 for message sending ...

Trying to send message 1 to endpoint 0x08 ...

 OK, message successfully sent

Resetting response endpoint 0x87

 Could not reset endpoint (probably harmless): -145

Resetting message endpoint 0x08

 Could not reset endpoint (probably harmless): -19

 Device is gone, skipping any further commands

Checking for mode switch (max. 20 times, once per second) ...

 Searching for target devices ...

Found target device, now opening

 Found correct target device

Mode switch succeeded. Bye.


屏幕会显示一堆模式转换信息,之后会显示成功

检查是否转换成功,执行lsusb,发现14ef变为1506,表示转换成功。

5.查看/dev下是否有一下设备节点

#ls /dev/ttyUSB*

#/dev/ttyUSB0 /dev/ttyUSB1 /dev/ttyUSB2 /dev/ttyUSB3 /dev/ttyUSB4

这里根据切换后的提醒,建立相应的设备节点。

6.硬件问题都解决了,开始拨号吧:(电信的拨号脚本,联通、移动的应该会变化,请google)

第一个文件:wcdma (路径/etc/ppp/peer/)

/dev/ttyUSB0  

115200  

nodetach  

user "card"  

password "card"  

crtscts  

show-password  

usepeerdns  

noauth  

noipdefault  

novj  

novjccomp  

noccp  

defaultroute  

ipcp-accept-local  

ipcp-accept-remote  

connect 'chat -s -v -f /etc_ro/ppp/chat/wcdma-connect-chat'

disconnect 'chat -s -v -f /etc_ro/ppp/chat/disconnect-chat'

第二个文件:wcdma-connect-chat (路径/etc/ppp/chat/)

ABORT 'NO CARRIER'

ABORT 'ERROR'

ABORT 'NO DIALTONE'

ABORT 'BUSY'

ABORT 'NO ANSWER'

'' \rAT

OK \rATZ

OK \rAT+CGDCONT=1,"IP","cmnet",,0,0

OK-AT-OK ATDT*99***1#

CONNECT \d\c

电信脚本

TIMEOUT 5
ABORT "DELAYED"
ABORT "BUSY"
ABORT "ERROR"
ABORT "NO DIALTONE"
ABORT "NO CARRIER"
""   AT
"OK-+++\c-OK" ATH0
TIMEOUT 40
""   AT
OK  ATDT#777
CONNECT ""

第三个文件:disconnect-chat

ABORT "BUSY"  

ABORT "ERROR"  

ABORT "NO DIALTONE"  

SAY "/nSending break to the modem/n"  

'' "/K"  

'' "+++ATH"  

SAY "/nGoodbye/n"

执行脚本拨号测试

#pppd call   gprs

abort on (NO CARRIER)

abort on (ERROR)

abort on (NO DIALTONE)

abort on (BUSY)

abort on (NO ANSWER)

send (^MAT^M)

expect (OK)

^MT^M^M

OK

 -- got it


send (^MATZ^M)

expect (OK)

^M

^MATZ^M^M

OK

 -- got it


send (^MAT+CGDCONT=1,"IP","cmnet",,0,0^M)

expect (OK)

^M

^MAT+CGDCONT=1,"IP","cmnet",,0,0^M^M

OK

 -- got it


send (ATDT*99***1#^M)

expect (CONNECT)

^M

ATDT*99***1#^M^M

CONNECT

 -- got it


send (\d)

Serial connection established.

Using interface ppp0

Connect: ppp0 <--> /dev/ttyUSB0

CHAP authentication succeeded: Welcome!!

CHAP authentication succeeded

Could not determine remote IP address: defaulting to 10.64.64.64

local  IP address 10.109.28.39

remote IP address 10.64.64.64

primary   DNS address 211.137.130.18

secondary DNS address 211.137.130.20

这时代表已经拨号成功,通过ifconfig命令可以看到有个ppp0,说明大功告成了

尝试ping www.baidu.com,应该就通了。

7.PPPD脚本分享

1. CHAT脚本
一个简单的chat脚本有下面的结构:
"" AT
OK ATDT dialnumber
CONNECT ""
一个chat脚本都是由字符串对来组成的。前面的字符串都是期望获取的串,紧跟的是发送的字符串。这个脚本每一项的具体含义是这样的:
1)   MODEM期望空字符串。这句话的意思直接理解就是MODEM不管收到什么字符串,先发出字符串AT;
2)   期望收到“OK”字符串,然后发送字符串“ATDT dialnumber”
3)   如果收到“CONNECT”,就不再发送,认为数据链路已建立连接。
这样的chat脚本是最简单的,如果需要进行超时控制,就可以加入如下字段:
TIMEOUT 10
如果要增加对特殊情况的处理,就加入下面字段:
ABORT BUSY   
ABORT NO ANSWER
ABORT RINGING
这三行语句的意思是:如果收到字符串“BUSY”、“NO ANSWER”、“RINGING”就退出执行。
所以在考虑到各种特殊情况下,配置一个PPP连接的CHAT脚本就可以像下面这样:
TIMEOUT 30
ABORT BUSY   
ABORT NO ANSWER
ABORT RINGING
"" AT
OK ATDT dialnumber
CONNECT ""


2.OPTIONS脚本
OPTIONS脚本的内容,为PPP连接指定了连接使用的设备、使用的控制字符传输速率、指定了硬件加速、溢出控制等。
例如下面的options脚本:
ttyS0 ---- 指定连接使用的设备,例如:ttyS0、ttyS1等
57600 ---- 设置连接使用的控制字符传输速率,可以设置为57600、115200等
debug ---- 如果需要加入调试信息,就加入参数debug
logfile /var/ ppplog ---- 将连接过程中的信息输入到某个文件中
mtu 1500
-detach
noipdefault ---- 不使用默认IP就可以加入参数noipdefault
defaultroute
usepeerdns ---- 使用服务器端协商的DNS就可以设置参数usepeerdns
lcp-echo-failure 4 ---- 当连续4次没有收到发出的LCP回声请求时,就认为服务器端已不再响应,就退出执行。这里的失败次数可以灵活来决定。
-ccp ---- 不使用压缩控制协议
-vj ---- 关掉式IP头压缩
-chap ---- 不使用chap鉴权
-mschap-v2 ---- 不使用mschap鉴权
user
hide-password
connect "/usr/bin/chat -v -t6 -f /var/ chat" ---- 制定了要使用的chat脚本的位置。加上参数-v 告诉 chat命令将其所有的输出/入拷贝到系统记录里(通常是 /var/log/messages)。-t 6 指定了执行chat该命令的时间为6s。chat脚本的位置可以位于/etc/目录下,也可以位于/var下,这个可以更加需要灵活设置。

persist --- 永久链接(自动重拨)

crtscts --- 告诉ppp使用modem的硬件流量控制

modem --- 使ppp使用DCD信号来判断连接是否正常,有无掉线现象

deflate --- 使pppd使用defalte压缩方式

idle --- 设置了一个时间限制,当在300秒的时间内没有数据传送,就断开连接

lock --- 则创建一个锁定文件,其他程序在发现存在这个文件后,就能得知相应的串口已经被使用。

demond --- 参数告诉pppd停留在后台,监视网络数据,一旦有要求就立即进行连网,超时后就断开连接,但pppd仍然停留在后台等待下次数据传送

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI