公司最近有個國外有個項目須要用到WCDMA貓,網上簡單選型了一下決定使用ZTE的型號MF667S的貓,本覺得在Linux下撥號是比較簡單的(以前有兩款3G貓的調試經驗),估計半天能搞定,結果折騰了一週才調通,記錄一下調試過程當中遇到的坑.網絡
因爲如今的貓都有多種模式,目的是爲了Windows下的小白用戶第一次插入的時候以cdrom或者u盤的模式使用,安裝裏面自帶的驅動後,再由驅動切換到貓的模式.這種方法在Windows下是很方便的,可是到了Linux下就很蛋疼了,須要藉助usb_modeswitch來進行模式切換.主頁ide
下載最新的usb_modeswitch,編譯,編輯一下配置文件usb_modeswitch.conf:測試
DefaultVendor=0x19d2 DefaultProduct=0x1588 TargetVendor=0x19d2 TargetProduct=0x1589 MessageContent="5553424312345678000000000000061e000000000000000000000000000000" MessageContent2="5553424312345679000000000000061b000000020000000000000000000000"
其中DefaultVendor和TargetVendor都是0x19d2,這也是ZTE公司的廠商ID,DefaultProduct爲0x1588,是插入貓後作爲USB模式系統認到的產品ID,可經過lsusb或者cat /proc/bus/usb/devices查看.TargetProduct0x1589是切換爲貓後的產品ID,切換後可用lsusb查看.(不過感受這裏能夠隨便填一個,沒什麼用).MessageContent從usb_modeswitch主頁抄的,試過只用一個MessageContent沒法激活,須要MessageContent2一塊兒使用.就這配置文件還踩了一個坑,之前的貓有加個MessageEndPoint=0xa,移植的時候也一同移植過來了,結果發消息怎麼都是出錯,後來移除後用默認的0x1發現能夠切換了-.-.spa
配置文件寫好了,執行命令:./usb_modeswitch -W -c /etc/usb_modeswitch.conf,獲得如下信息調試
* usb_modeswitch: handle USB devices with multiple modes * Version 2.2.5 (C) Josua Dietze 2015 * Based on libusb1/libusbx ! PLEASE REPORT NEW CONFIGURATIONS ! DefaultVendor= 0x19d2 DefaultProduct= 0x1588 TargetVendor= 0x19d2 TargetProduct= 0x1589 MessageContent="5553424312345678000000000000061e000000000000000000000000000000" MessageContent2="5553424312345679000000000000061b000000020000000000000000000000" NeedResponse=0 Look for target devices ... found USB ID 1d6b:0002 found USB ID 1d6b:0002 found USB ID 1d6b:0001 found USB ID 1d6b:0001 found USB ID 1d6b:0001 found USB ID 1d6b:0001 found USB ID 1d6b:0001 found USB ID 0403:6015 found USB ID 0dfc:0001 found USB ID 19d2:1588 vendor ID matched No devices in target mode or class found Look for default devices ... found USB ID 1d6b:0002 found USB ID 1d6b:0002 found USB ID 1d6b:0001 found USB ID 1d6b:0001 found USB ID 1d6b:0001 found USB ID 1d6b:0001 found USB ID 1d6b:0001 found USB ID 0403:6015 found USB ID 0dfc:0001 found USB ID 19d2:1588 vendor ID matched product ID matched Found devices in default mode (1) Access device 003 on bus 001 Current configuration number is 1 Use interface number 0 Use endpoints 0x01 (out) and 0x81 (in) USB description data (for identification) ------------------------- Manufacturer: ZTE,Incorporated Product: ZTE Mobile Broadband Station Serial No.: 1234567890ABCDEF ------------------------- Looking for active driver ... OK, driver detached Set up interface 0 Use endpoint 0x01 for message sending ... Trying to send message 1 to endpoint 0x01 ... OK, message successfully sent Trying to send message 2 to endpoint 0x01 ... OK, message successfully sent Reset response endpoint 0x81 Reset message endpoint 0x01 -> Run lsusb to note any changes. Bye!
說明已經切換成功了,再cat /proc/bus/usb/devices查看設備信息以下:code
T: Bus=01 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#= 6 Spd=480 MxCh= 0 D: Ver= 2.00 Cls=02(comm.) Sub=00 Prot=00 MxPS=64 #Cfgs= 1 P: Vendor=19d2 ProdID=1589 Rev= 0.00 S: Manufacturer=ZTE,Incorporated S: Product=ZTE Mobile Broadband Station S: SerialNumber=1234567890ABCDEF C:* #Ifs= 7 Cfg#= 1 Atr=a0 MxPwr=500mA A: FirstIf#= 0 IfCount= 2 Cls=02(comm.) Sub=06 Prot=00 I:* If#= 0 Alt= 0 #EPs= 1 Cls=02(comm.) Sub=06 Prot=00 Driver=cdc_ether E: Ad=88(I) Atr=03(Int.) MxPS= 64 Ivl=125us I: If#= 1 Alt= 0 #EPs= 0 Cls=0a(data ) Sub=00 Prot=00 Driver=cdc_ether I:* If#= 1 Alt= 1 #EPs= 2 Cls=0a(data ) Sub=00 Prot=00 Driver=cdc_ether E: Ad=81(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=01(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms I:* If#= 2 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=ff Prot=ff Driver=(none) E: Ad=87(I) Atr=03(Int.) MxPS= 64 Ivl=500us E: Ad=82(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=02(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms I:* If#= 3 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=ff Prot=ff Driver=(none) E: Ad=83(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=03(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms I:* If#= 4 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=ff Prot=ff Driver=(none) E: Ad=84(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=04(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms I:* If#= 5 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=ff Prot=ff Driver=(none) E: Ad=85(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=05(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms I:* If#= 6 Alt= 0 #EPs= 2 Cls=08(stor.) Sub=06 Prot=50 Driver=usb-storage E: Ad=86(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=06(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms
ProdID已經切換成1589,自動加載了個cdc_ether驅動,還有4個設備未驅動和一個usb存儲.cdc_ether驅動生成了一個usb0的網口設備.至此,說明WCDMA貓已經切換模式成功.blog
模式切換成功後,因爲自動加載了網卡驅動生成了usb0的網口設備,讓我又踩了一個坑,覺得這是一個純網卡的模塊,論壇上搜索了一番,也沒有這個型號貓的明確說明,相近的型號也描述的不清不楚的,試過dhclinet usb0,無效.還有說要訪問個gateway受權再分配IP的(純屬扯談).後來才發現這個usb0的網卡設備徹底沒用,這個貓是一個傳統的usb轉串口的貓.dns
在系統啓動的時候rc.local里加上下面的命令:modeprobe usbserial.ko vendor=0x19d2 product=0x1589,再從新執行第一步,OK,串口出來了.ip
ls /dev/ttyUSB* -l,有時候會生成0-3共4個USB口,有時候會生成0-4共5個USB控制口,不解爲何.rem
ttyUSB設備生成後就能夠對設備進行AT指令撥號了,因爲生成了4-5個USB節點,只好一個個試驗哪一個節點是貓口,經測試發現,USB0 USB1接收AT指令能返回OK,USB2 USB3直接返回TIMEOUT,說明2,3不是,貓口在0,1之間.繼續測試鎖定貓口爲第一個設備/dev/ttyUSB0.
接下來就是寫腳本了.SCRIPT:
ABORT BUSY ABORT 'NO CARRIER' ABORT 'NO DIALTONE' '' AT+CGDCONT=1,"IP","3GNET" OK ATDT*99# CONNECT
pppd 115200 connect "/usr/sbin/chat -f dial.script -v" /dev/ttyUSB0 modem defaultroute
經過上面的命令和腳本,發送AT+CGDCONT=1,"IP","3GNET"能夠獲得OK,再發送ATDT*99#卻返回ERROR-.-;因而又在論壇摸索了半天,發現有我的遇到了相同的狀況,提示在最前面加一條AT+CFUN=1,0(註冊網絡)果真就不返回ERROR返回CONNECT了.本覺得大功告成,誰知道pppd在下一步的時候又提示檢測不到本地IP,並且看log,CONNECT以後確實沒有返回本地和遠程的IP信息.
在這一步又卡殼了幾天,最後想着換一批pppd參數,折騰了幾下終於撥上去了-.-;最終的腳本和命令以下:
ABORT BUSY ABORT 'NO CARRIER' ABORT 'NO DIALTONE' '' AT+CFUN=1,0 OK AT+CGDCONT=1,"IP","3GNET" OK ATDT*99# CONNECT
pppd 115200 connect "/usr/sbin/chat -f dial.script -v" /dev/ttyUSB0 ipcp-accept-local ipcp-accept-remote defaultroute usepeerdns
PS:這款貓還有個BUG,每次撥號,必需要撥兩次才能成功,第一次撥號ATDT最後仍是會返回ERROR,第二次撥號就能夠正確的撥上去了-.-,ZTE的東西就是不太靠譜,最後沒辦法只有在上層應用加個判斷,撥號撥兩次再檢查狀態...