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

简介:

内核:需要有以下模块: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仍然停留在后台等待下次数据传送


本文转自 Linux_woniu 51CTO博客,原文链接:http://blog.51cto.com/linuxcgi/1965298

相关文章
|
1月前
|
JSON 机器人 Linux
推荐一款嵌入式Linux开源框架与封装-cpp-tbox
推荐一款嵌入式Linux开源框架与封装-cpp-tbox
59 3
|
1月前
|
Linux Shell
嵌入式Linux系统脚本小技巧之启动脚本
嵌入式Linux系统脚本小技巧之启动脚本
19 2
|
5天前
|
Linux
linux驱动层输出dev_dbg打印信息
linux驱动层输出dev_dbg打印信息
11 0
|
12天前
|
Ubuntu 算法 Linux
嵌入式Linux的学习误区
该文指出了学习嵌入式Linux开发的两个常见误区。一是过分专注于学习桌面或服务器版Linux,而非关注嵌入式开发本身,实际上只需熟悉基本操作即可。二是试图在没有基础的情况下直接阅读Linux内核源代码,这是不切实际的,应先建立基础知识再进行源码学习。文章还提到了在嵌入式系统中获取和处理屏幕数据的示例,包括使用gsnap工具将framebuffer数据转为图像,以及涉及的交叉编译过程。
11 0
|
14天前
|
存储 监控 Linux
【专栏】在 Linux 中,了解已安装驱动器是系统管理的关键
【4月更文挑战第28天】在 Linux 中,了解已安装驱动器是系统管理的关键。本文介绍了三种方法:1) 使用 `lsblk` 命令显示设备名、大小和类型;2) `fdisk -l` 命令提供详细分区信息;3) `gnome-disks` 等系统管理工具展示驱动器信息。此外,还讨论了驱动器类型识别、挂载点概念及其应用。通过这些方法,用户能有效地监控和管理 Linux 系统中的驱动器。
|
27天前
|
Linux 编译器 测试技术
嵌入式 Linux 下的 LVGL 移植
嵌入式 Linux 下的 LVGL 移植
|
27天前
|
Linux Go
Linux命令Top 100驱动人生! 面试必备
探索Linux命令不再迷茫!本文分10部分详解20个基础命令,带你由浅入深掌握文件、目录管理和文本处理。 [1]: <https://cloud.tencent.com/developer/article/2396114> [2]: <https://pan.quark.cn/s/865a0bbd5720> [3]: <https://yv4kfv1n3j.feishu.cn/docx/MRyxdaqz8ow5RjxyL1ucrvOYnnH>
79 0
|
27天前
|
Linux 开发工具
【ZYNQ】配置嵌入式 Linux 静态 IP 地址
【ZYNQ】配置嵌入式 Linux 静态 IP 地址
|
1月前
|
Linux API C语言
lua 如何在嵌入式Linux中与c语言结合
lua 如何在嵌入式Linux中与c语言结合
12 1
|
1月前
|
小程序 Linux
嵌入式Linux系统-升级包中的脚本
嵌入式Linux系统-升级包中的脚本
21 1