由此可以考慮在linux下實現usb指令到串口指令轉換的驅動以驅動modem實現上網,各個平臺的linux內核中都有usbserial
模塊,該模塊是可以驅動modem上網的,因此可以考慮使用usbserial模塊驅動3G網卡上網。
Usb_modeswitch是對USB設備的工作模式進行轉換一種萬能工具,當然這種寶貝,只有在linux下才能體現其巨大的作用。
隨着移動通信,無線通信的發展,越來越多的設備被製作成USB接口,像一些無線網卡,3G數據卡等等。
這些設備的廠家一般都會提供windows 下驅動,這些設備在第一次插上機子的時候,它們處於CDROM+閃存模式,
可以從中提供驅動程序安裝驅動,在驅動程序安裝完成後,驅動會轉換成3G模式,此時就會出現usb modem設備,
目前的3G卡片全都是這樣,這就是所謂的“ZeroCD”。
而在linux下我們可沒有那麼好的待遇,廠家一般不會給我們提供linux下面的驅動,而目前的內核還不能自動識別並驅動。
所以我們需要用usb_modeswitch這個工具來進行模式轉換,設備模式依賴usb-storage和usbserial模式,
所以,在開發板上需要有這兩種模塊的支持,設備並能夠正常工作於這兩種模式下。
usb_modeswitch的正常工作依賴於Libusb所以我們還需要在內核中添加這個庫。
如果內核中不包括上述工具可以到一下地址下載:
libusb源碼下載: http://sourceforge.net/projects/libusb/files/libusb-1.0/
usb_modeswitcch下載: http://www.draisberghof.de/usb_modeswitch/
usb-modeswitch-data: http://www.draisberghof.de/usb_modeswitch/
以中興AC2726爲例進行移植過程如下:
-----------------------------------------------------------------------------------------------------------------------------------------------------
Device Drivers
Network device support --->
<*> PPP (point-to-point protocol) support
[*] PPP multilink support (EXPERIMENTAL)
[*] PPP filtering
<*> PPP support for async serial ports
<*> PPP support for sync tty ports
<*> PPP Deflate compression
<*> PPP BSD-Compress compression
< > PPP MPPE compression (encryption) (EXPERIMENTAL)
<*> PPP over Ethernet (EXPERIMENTAL)
< > PPP over L2TP (EXPERIMENTAL)
< > PPTP (Point-to-Point Tunneling Protocol) (EXPERIMENTAL)
(ppp用於撥號)
Device Drivers
USB support --->
[*] USB device filesystem
<*> USB Modem (CDC ACM) support
USB Serial Converter support --->
[*] USB Generic Serial Driver
<*> USB driver for GSM and CDMA modems
(用於支持usb轉串口)
Library Configuration --->
[*] Build libusb-0.1.12
(添加libusb庫)
Miscellaneous Applications --->
[*] usb_modeswitch
(添加usb_modeswitch模塊)
-----------------------------------------------------------------------------------------------------------------------------------------------------
內核配置到這裏就已經完成,然後需要修改option.c , Pl2303.c , Pl2303.h手動添加所要移植的3g設備信息;
(windows下使用usbviewer查看網卡的信息,主要是VENDOR_ID,PRODUCT_ID,MessageEndpoint)
Pl2303.h:
#define ZTE_VENDOR_ID 0x19d2
#define ZTE_PRODUCT_ID 0xfff5
這裏兩個數值可以通過在linux環境下用lsusb查詢到
Pl2303.c:
在static struct usb_device_id id_table []最後加入
{ USB_DEVICE(ZTE_VENDOR_ID, ZTE_PRODUCT_ID) },
option.c :
首先加入
#define ZTE_PRODUCT_CDMA_TECH6 0xfff1
其中0xfff1爲運行過usb_modeswitch之後設備被轉換成的編號,可以在pc機上試驗取得
然後在static struct usb_device_id option_ids[]最後加入
{ USB_DEVICE(ZTE_VENDOR_ID, ZTE_PRODUCT_CDMA_TECH6) },
-----------------------------------------------------------------------------------------------------------------------------------------------------
其內容爲:
DefaultVendor= 0x19d2
DefaultProduct= 0xfff5
TargetVendor= 0x19d2
TargetProduct= 0xfff1
MessageContent="5553424312345678c00000008000069f030000000000000000000000000000"
MessageEndpoint=0x0a
-----------------------------------------------------------------------------------------------------------------------------------------------------
到這裏上網卡移植就結束了,然後進行撥號:
pppd connect 'chat -v "" "AT" "OK" "ATZ" "OK" "ATDT#777 CONNECT"' user card password card /dev/ttyUSB0 115200 nodetach noauth nocrtscts modem noipdefault debug usepeerdns defaultroute ipcp-accept-local noccp