3G USB modem 驱动移植总结

http://wenku.baidu.com/view/ecac6309bb68a98271fefa51.html

1. 背景知识

现在一些新的USB 设备(特别是一些高速 WAN 设备,很贵的那种)都有MS Windows的驱动程序,当第一次插入机子的时候,它们处于闪存模式,并从中提取和安装驱动。在驱动安装完毕之后,驱动马上转换模式,储存设备消失(基本上都是这样的),然后一个新的设备(比如一个USB modem)出现。有些人把这个特性叫做"ZeroCD"。然而在linux中因为版本太多没有办法在闪存中存储modem的驱动,所以在linux下要写驱动。因为在linux中会先把这种3G modem识别成光盘,也就是说3G USB modemusb-storage首先驱动了,这样真正的modem的驱动没有机会去驱动此设备。所以写驱动的难点就在于怎样避开被识别成光盘,让真正的modem的驱动有机会驱动设备。事实上如果能避开识别成光盘,linux的通用驱动usbserial本身就可以驱动3G USB modem,当然为了提高速度还是要给usbserial打补丁,否则最高速度就只能是63Kbps了。

 

The new USB Option WWAN modem device support a CDROM device, which holds the needed Windows driver to use the WWAN modem.Therefore the firmware of the WWAN modem announce during the USB enumeration process to work as a virtual CDROM device withits vendor name "ZOPTION". This device is now called ZERO-CD.

 

The Linux OS does currently not use this ZERO-CD, because the image can not hold all the needed binary kernel drivers, whichmay exists in the world. Also it is often strange to identify the exact matching drivers to your system, because the 2.6.xx kernel has today a lot of Distro specific patches. So we will currently not use this ZERO-CD device for Linux and have to switchit off. Once you send this switch off command to the WWAN modem, another new USB enumeration will be requested by the WWAN modemfirmware. Afterwards the real WWAN modem interface is available on the USB bus.

 

Looking on the Linux USB core system, it has another restriction. If there are more than one possible drivers, which can worksuccessfully with that USB WWAN modem, the USB core system will allow probing the WWAN modem by these drivers in a special order.First the already loaded driver will be allowed to do the probe. If then this driver do a successful probe, another potential driver will never become a chance to do also a probing with that hardware. Therefore it is (currently) impossible to use the final WWAN modem driver to send the ZERO-CD switch off command, because often the USB mass storge driver will be already loaded andis working in your Linux system.

 

If the probing of an already loaded module is not successful or no module is loaded, the udev system will trigger a modeprobe to load the needed driver(s). But the loading order of the drivers is not clear specified, although is may depends on the order of the appearance in the modules dependency files created by depmod.

 

2. 驱动方法

 

目前注意有以下几种方法,

 

2.1 使用USB_ModeSwitch 工具加usbserial驱动

利用USB_ModeSwitchUSB 3G modem切换到modem的状态。然后用usbserial来驱动。然而USB_ModeSwitch依赖于udevudevkernel 2.6下才有,对于kernel 2.4不支持。

 

2.2 使用ozerocdoff工具加usbserial驱动

原理和USB_ModeSwitch的方法差不多,事实上ozerocdoff的代码参考了USB_ModeSwitch。都是先把USB 3G modem切换到modem的状态。然后用usbserial来驱动。然而USB_ModeSwitch依赖于udevudevkernel 2.6下才有,对于kernel 2.4不支持。

 

2.3 使用eject

使用eject命令把3G USB modem虚拟的光盘弹出。进而usbserial就可以识别3G USB modem。此方法通用在kernel 2.4下可以用。但在v9机器上不行。

例如电脑把3G USB识别成三人sr0

 

下面是使用ejectusbserial驱动3G USB modemlog

附件因为格式的原因请用ultraedit打开(即用记事本打开后copyultraedit)。

 

 2.4 给内核发送命令

 

usb-storage模块中加入一些发给内核的命令,告诉系统此3G USB modem有多个port,不要简单的当成mass-storage对待。

 

华为和OPTION公司在Linux的内核的usb-storage中加入了代码,告诉系统要特别对待华为的3G USB modem

 

下面是采用这种方式在V9下的log

 

 

 

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. actively removing (rather detaching) the storage driver from the device

3. sending a certain control message to the device

 

 

3. 移植到LT-E02

 

在上面提到的四种方法中,eject和初始化命令方法,在intel 845主板加redhat 9下都可以成功,但不知为什么在LT-E02上却不行。所以得想其它办法。

 

华为的EC1260在高版本的Linux内核中的unusual_devs.h中加入了下面的代码对华为的3G USB modem特别对待。即在被识别成Mass Storage的过程中给系统发送命令告诉系统此设备里有modem

/usr/src/linux-2.4/drivers/usb/unusual_dev.h

UNUSUAL_DEV(  0x12d1, 0x1001, 0x0000, 0x0000,

              "HUAWEI MOBILE",

              "Mass Storage",

              US_SC_DEVICE, US_PR_DEVICE, usb_stor_huawei_e220_init,

              0),

 

kernel 2.4中我们参考华为的做法在unusual_dev.h中加入了类似的代码,在设备插入的瞬间切到modem的状态。

 

下面是修改后的源代码。

下面是编译好的可以用于V9的模块,因为usb-storage.o依赖于scsi_mod所以要先加载scsi_mod.o然后加载usb-storage.o usbserial_new.o是自己修改后的3G上网卡驱动。附件里还包含了拨号脚本参考。

 

操作方法。

3.0 修改LT-E02BIOS设置,Chipset Features/USB Legacy Support 设置值为disable

       如果是enable的话,插入3G上网卡然后开机的话USB controller会起不了,即所有的USB设备都不能用。

下面是Chipset Features/USB Legacy Support 设置值为enablelog

3.1 修改usb-storage代码,并编译成usb-storage并复制到/lib/modules/2.4.20-8custom/kernel/drivers/usb/storage 替换原来的usb-storage

3.2 修改usbserial,加入产品ID,并加入一些代码使其支持高速率传输。编译成usbserial_new.o模块,然后修改/etc/rc.local,加入加载usbserial_new.o模块的命令。

3.3 插入3G USB modem然后开机,USBhotplug机制会自动调用usb-storage模块。usbserial_new.o模块会自动识别HUAWEI3G上网卡,接下来它会识别出ttyUSB0, ttyUSB1等。

3.4 利用pppd拨号上网

   下面是拨号脚本

Echo “nameserver 202.96.134.133” > /etc/resolv.conf

pppd connect 'chat -v "" "AT" "" "ATDT#777 CONNECT"' user CARD password CARD /dev/ttyUSB0 460800 nodetach crtscts debug usepeerdns defaultroute

由于并不是每次都可以拨号成功,所以要是不成功可以先用killall -9 pppd杀死pppd进程然后再用pppd拨号。

3.5 修改/etc/resolve.config

加入DNS,比如加入深圳电信的dns

nameserver 202.96.128.86

 

 

4. 参考文档

usb_modeswith的说明文档

http://www.draisberghof.de/usb_modeswitch/#trouble

2. option 公司开发的ozerocdoffreadme文档

 

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值