http://blog.csdn.net/zanget/article/details/6203282
本人最近做一个usb modem的Linux应用,设备本身能被windows识别成磁盘,由于自身带驱动、应用程序(中国移动的,M$ windoz上 L!!!),也能发送接收GPRS信息,而应用却在Linux上没有任何信息和资料。。。
没办法,既然能在M$ windoz上使用,那么也只有试试看了●0●
A. 测试
插上设备后:
root@zanget:sbin# lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 014: ID 0471:1202 Philips
Bus 002 Device 003: ID 0e0f:0002
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
root@zanget:dev# dmesg
[575642.984739] usb 2-1: new full speed USB device using uhci_hcd and address 14
[575643.219301] usb 2-1: configuration #1 chosen from 1 choice
[575643.264255] scsi4 : SCSI emulation for USB Mass Storage devices
[575643.280808] usb-storage: device found at 14
[575643.280811] usb-storage: waiting for device to settle before scanning
[575649.988144] usb-storage: device scan complete
[575651.010892] scsi 4:0:0:0: Direct-Access Philips Dev. 0 LUN 0 1.0 PQ: 0 ANSI: 0
[575651.041831] sd 4:0:0:0: [sdc] 6144 512-byte hardware sectors: (3.14 MB/3.00 MiB)
[575651.056810] sd 4:0:0:0: [sdc] Test WP failed, assume Write Enabled
[575651.056813] sd 4:0:0:0: [sdc] Assuming drive cache: write through
[575651.072312] sd 4:0:0:0: [sdc] 6144 512-byte hardware sectors: (3.14 MB/3.00 MiB)
[575651.094904] sd 4:0:0:0: [sdc] Test WP failed, assume Write Enabled
[575651.094907] sd 4:0:0:0: [sdc] Assuming drive cache: write through
[575651.094915] sdc:
[575651.107885] sd 4:0:0:0: [sdc] Attached SCSI removable disk
[575651.108059] sd 4:0:0:0: Attached scsi generic sg3 type 0
root@zanget:dev# cat /var/log/messages
Feb 23 09:46:05 zanget kernel: [575642.984739] usb 2-1: new full speed USB device using uhci_hcd and address 14
Feb 23 09:46:05 zanget kernel: [575643.219301] usb 2-1: configuration #1 chosen from 1 choice
Feb 23 09:46:05 zanget kernel: [575643.264255] scsi4 : SCSI emulation for USB Mass Storage devices
Feb 23 09:46:13 zanget kernel: [575651.010892] scsi 4:0:0:0: Direct-Access Philips Dev. 0 LUN 0 1.0 PQ: 0 ANSI: 0
Feb 23 09:46:13 zanget kernel: [575651.041831] sd 4:0:0:0: [sdc] 6144 512-byte hardware sectors: (3.14 MB/3.00 MiB)
Feb 23 09:46:13 zanget kernel: [575651.056810] sd 4:0:0:0: [sdc] Test WP failed, assume Write Enabled
Feb 23 09:46:13 zanget kernel: [575651.072312] sd 4:0:0:0: [sdc] 6144 512-byte hardware sectors: (3.14 MB/3.00 MiB)
Feb 23 09:46:13 zanget kernel: [575651.094904] sd 4:0:0:0: [sdc] Test WP failed, assume Write Enabled
Feb 23 09:46:13 zanget kernel: [575651.094915] sdc:
Feb 23 09:46:13 zanget kernel: [575651.107885] sd 4:0:0:0: [sdc] Attached SCSI removable disk
Feb 23 09:46:13 zanget kernel: [575651.108059] sd 4:0:0:0: Attached scsi generic sg3 type 0
还好Linux能识别此设备,当然被识别成磁盘了,心想,浮云也不过如此。
B. 信息
既然设备在M$ windoz上能正常使用,那么可从M$ windoz上找到些许信息,以帮助Linux开发。
通过M$ windoz找到 Philips Dev. 0 LUN USB
通过Google 关键字Philips Dev. 0 LUN USB Device linux driver找到下面文章:
http://www.epokh.org/blog/?p=357
C. 配置
找到usb_modemswitch,安装后,拷贝配置文件usb_modeswitch.conf,并修改设置如下:
DisableSwitching=0
# Enable logging (results in a extensive report file in /var/log, named
# "usb_modeswitch_<interface-name>" (and probably others)
EnableLogging=0
#0471:1202 Philips
DefaultVendor = 0x0471
DefaultProduct = 0x1202
TargetVendor = 0x0471
CheckSuccess=20
InquireDevice=1
MessageContent="5553424312345678000000000000061b000000020000000000000000000000"
使用
usb_modeswitch -I -n -c /win/modem/usb-modeswitch/usb-modeswitch-1.1.6/release/etc/usb_modeswitch.conf
Looking for target devices ...
No devices in target mode or class found
Looking for default devices ...
Found devices in default mode, class or configuration (1)
Accessing device 014 on bus 002 ...
Getting the current device configuration ...
OK, got current device configuration (1)
Ambiguous Class/InterfaceClass: 0x02/0x08
Using endpoints 0x03 (out) and 0x83 (in)
Using endpoints 0x03 (out) and 0x83 (in)
Inquiring device details; driver will be detached ...
Looking for active driver ...
No driver found. Either detached before or never attached
SCSI inquiry data (for identification)
-------------------------
Vendor String: Philips
Model String: Dev. 0 LUN 0
Revision String: 1.0
-------------------------
USB description data (for identification)
-------------------------
Manufacturer: Royal Philips Electronics
Product: Reference Design Philips Semiconductors only Mass Storage
Serial No.: 000000-00-000000
-------------------------
Setting up communication with interface 0 ...
Using endpoint 0x03 for message sending ...
Trying to send message 1 to endpoint 0x03 ...
OK, message successfully sent
Reading the response to the message (CSW) ...
OK, response successfully read (13 bytes).
Resetting response endpoint 0x83
Resetting message endpoint 0x03
Checking for mode switch (max. 20 times, once per second) ...
Waiting for original device to vanish ...
Waiting for original device to vanish ...
Waiting for original device to vanish ...
Waiting for original device to vanish ...
Waiting for original device to vanish ...
Waiting for original device to vanish ...
Waiting for original device to vanish ...
Waiting for original device to vanish ...
Waiting for original device to vanish ...
Waiting for original device to vanish ...
Waiting for original device to vanish ...
Waiting for original device to vanish ...
Waiting for original device to vanish ...
Waiting for original device to vanish ...
Waiting for original device to vanish ...
Waiting for original device to vanish ...
Waiting for original device to vanish ...
Waiting for original device to vanish ...
Waiting for original device to vanish ...
Waiting for original device to vanish ...
Original device still present after the timeout
Mode switch most likely failed. Bye.
不管怎么改,楞是不成功!
到官方论坛上淘了好久:
http://www.draisberghof.de/usb_modeswitch/bb/viewforum.php?f=4
几乎都差发帖了(最终还是忍不住,发帖了帖子链接在
http://www.draisberghof.de/usb_modeswitch/bb/viewtopic.php?p=4214#4214)!
后来从Josh哪里得知
Seems like you don't have to switch anything, the serial ports are there. You just have to bind a driver to them.
In comes the magic of the Linux kernel; issue the following commands (as root or with sudo):
因为
iManufacturer 1 Royal Philips Electronics
iProduct 2 Reference Design Philips Semiconductors only Mass Storage
iSerial 3 000000-00-000000
来自
root@zanget:sbin# lsusb -v -d 0471:1202
Bus 002 Device 014: ID 0471:1202 Philips
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 2.00
bDeviceClass 2 Communications
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 8
idVendor 0x0471 Philips
idProduct 0x1202
bcdDevice 1.00
iManufacturer 1 Royal Philips Electronics
iProduct 2 Reference Design Philips Semiconductors only Mass Storage
iSerial 3 000000-00-000000
bNumConfigurations 1
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 32
bNumInterfaces 1
bConfigurationValue 1
iConfiguration 0
bmAttributes 0xc0
Self Powered
MaxPower 500mA
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 2
bInterfaceClass 8 Mass Storage
bInterfaceSubClass 6 SCSI
bInterfaceProtocol 80 Bulk (Zip)
iInterface 4 Mass Storage Device
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x03 EP 3 OUT
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 0
Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x83 EP 3 IN
bmAttributes 2
Transfer Type Bulk
Synch Type None
Usage Type Data
wMaxPacketSize 0x0040 1x 64 bytes
bInterval 0
Device Status: 0x0000
(Bus Powered)
下面就好办了!
D. 识别
root@zanget:/# modprobe -v option
WARNING: All config files need .conf: /etc/modprobe.d/vmware-tools, it will be ignored in a future release.
insmod /lib/modules/2.6.28-19-generic/kernel/drivers/usb/serial/usbserial.ko
insmod /lib/modules/2.6.28-19-generic/kernel/drivers/usb/serial/option.ko
root@zanget:/#echo "0471 1202" > /sys/bus/usb-serial/drivers/option1/new_id
root@zanget:sbin# dmesg
[575642.984739] usb 2-1: new full speed USB device using uhci_hcd and address 14
[575643.219301] usb 2-1: configuration #1 chosen from 1 choice
[575643.264255] scsi4 : SCSI emulation for USB Mass Storage devices
[575643.280808] usb-storage: device found at 14
[575643.280811] usb-storage: waiting for device to settle before scanning
[575649.988144] usb-storage: device scan complete
[575651.010892] scsi 4:0:0:0: Direct-Access Philips Dev. 0 LUN 0 1.0 PQ: 0 ANSI: 0
[575651.041831] sd 4:0:0:0: [sdc] 6144 512-byte hardware sectors: (3.14 MB/3.00 MiB)
[575651.056810] sd 4:0:0:0: [sdc] Test WP failed, assume Write Enabled
[575651.056813] sd 4:0:0:0: [sdc] Assuming drive cache: write through
[575651.072312] sd 4:0:0:0: [sdc] 6144 512-byte hardware sectors: (3.14 MB/3.00 MiB)
[575651.094904] sd 4:0:0:0: [sdc] Test WP failed, assume Write Enabled
[575651.094907] sd 4:0:0:0: [sdc] Assuming drive cache: write through
[575651.094915] sdc:
[575651.107885] sd 4:0:0:0: [sdc] Attached SCSI removable disk
[575651.108059] sd 4:0:0:0: Attached scsi generic sg3 type 0
[578032.229818] UDF-fs: No VRS found
[578032.233357] ISO 9660 Extensions: Microsoft Joliet Level 3
[578032.242905] ISO 9660 Extensions: RRIP_1991A
[578744.750658] scsi 4:0:0:0: rejecting I/O to dead device
[581375.334829] usb 2-1: usbfs: process 26789 (usb_modeswitch) did not claim interface 0 before use
[581696.737020] usb 2-1: usbfs: process 26815 (usb_modeswitch) did not claim interface 0 before use
[582968.446436] usb 2-1: usbfs: process 26923 (usb_modeswitch) did not claim interface 0 before use
[582994.135335] usb 2-1: usbfs: process 26926 (usb_modeswitch) did not claim interface 0 before use
[583009.793851] usb 2-1: usbfs: process 26929 (usb_modeswitch) did not claim interface 0 before use
[583025.178155] usb 2-1: usbfs: process 26930 (usb_modeswitch) did not claim interface 0 before use
[586567.806011] usb 2-1: usbfs: process 27198 (usb_modeswitch) did not claim interface 0 before use
[587580.241077] usbcore: deregistering interface driver usb-storage
[587614.306469] usb 2-1: usbfs: process 27282 (usb_modeswitch) did not claim interface 0 before use
[587640.871790] usb 2-1: usbfs: process 27285 (usb_modeswitch) did not claim interface 0 before use
[588024.420627] usb 2-1: usbfs: process 27331 (usb_modeswitch) did not claim interface 0 before use
[589119.835562] USB Serial support registered for GSM modem (1-port)
[589119.835591] usbcore: registered new interface driver option
[589119.835597] option: v0.7.2:USB Driver for GSM modems
[589272.591332] option 2-1:1.0: GSM modem (1-port) converter detected
[589272.591534] usb 2-1: GSM modem (1-port) converter now attached to ttyUSB0
注意:当插拔后,发现端口变化了:
cdc_acm 2-1:1.0: ttyACM0: USB ACM device
usbcore: registered new interface driver cdc_acm
新的接口:ttyACM0
E. 使用:
好,开启minicom,设置为ttyUSB0,波特率(通过manual,或者使用串口调试助手(M$ windoz上的( -___- )b)找到当前模块的波特率),测试基本AT 命令。。。
AT+IPR=? 查询支持的DTE-DCE 波特率
AT+IPR? 读取当前的DTE-DCE 波特率
AT+IPR= 设置DTE-DCE 波特率
默认default : 57600
AT+IPR=57600
改为AT+IPR=115200
F. PPPD配置
配置文件如下
#/etc/ppp/chap-secrets
#
# Secrets for authentication using CHAP
# client server secret IP addresses
"cmwap" * "cmwap" *
#!/bin/sh
#
# File: /etc/ppp/gprs-connect-chat
TIMEOUT 5
ECHO ON
ABORT ' BUSY '
ABORT ' ERROR '
ABORT ' NO ANSWER '
ABORT ' NO CARRIER '
ABORT ' NO DIALTONE '
ABORT ' RINGING RINGING '
'' AT
OK 'AT+CFUN=1'
TIMEOUT 12
OK AT+CGATT?
OK AT+CGATT=1
OK AT+CGATT?
OK 'AT+CGDCONT=1,"IP" "cmwap"'
SAY 'Dialing.../n'
OK ATDT*99***1#
#OK ATDT*99#
TIMEOUT 60
CONNECT ""
SAY "Connected. now logging in... "
# /etc/ppp/options
novj
noccp
# Give some debug info
debug
kdebug 7
# Add default route
defaultroute
# Print out all the option values which have been set.
dump
noauth
connect "/usr/sbin/chat -v -f /etc/ppp/gprs-connect-chat"
#disconnect "/usr/sbin/chat -v -f /etc/ppp/gprs-disconnect-chat"
# Give some debug info
debug
#logfile /var/log/ppplog
/dev/ttyUSB0
115200
defaultroute
user "cmwap"
0.0.0.0:0.0.0.0
nodetach
#usepeerdns
lcp-echo-failure 0
lcp-echo-interval 0
G. 开始使用PPPD拨号拨号
root@zanget:~# pppd call options
pppd options in effect:
debug debug # (from /etc/ppp/peers/options)
kdebug 7 # (from /etc/ppp/peers/options)
nodetach # (from /etc/ppp/peers/options)
dump # (from /etc/ppp/peers/options)
noauth # (from /etc/ppp/peers/options)
user cmwap # (from /etc/ppp/peers/options)
/dev/ttyUSB0 # (from /etc/ppp/peers/options)
115200 # (from /etc/ppp/peers/options)
lock # (from /etc/ppp/options)
connect /usr/sbin/chat -v -f /etc/ppp/gprs-connect-chat # (from /etc/ppp/peers/options)
crtscts # (from /etc/ppp/options)
modem # (from /etc/ppp/options)
asyncmap 0 # (from /etc/ppp/options)
lcp-echo-failure 0 # (from /etc/ppp/peers/options)
lcp-echo-interval 0 # (from /etc/ppp/peers/options)
hide-password # (from /etc/ppp/options)
novj # (from /etc/ppp/peers/options)
defaultroute # (from /etc/ppp/peers/options)
proxyarp # (from /etc/ppp/options)
: # (from /etc/ppp/peers/options)
noccp # (from /etc/ppp/peers/options)
noipx # (from /etc/ppp/options)
VAL
NO CARRIER
OK
OK
+CGATT: 1
OK
OK
+CGATT: 1
OKDialing...
OK
CONNECTConnected. now logging in...
Script /usr/sbin/chat -v -f /etc/ppp/gprs-connect-chat finished (pid 28801), status = 0x0
Serial connection established.
using channel 20
Using interface ppp0
Connect: ppp0 <--> /dev/ttyUSB0
rcvd [LCP ConfReq id=0x6 <mru 1600> <auth pap> <magic 0x5fb8dec7> <asyncmap 0x0> <pcomp> <accomp>]
sent [LCP ConfReq id=0x1 <asyncmap 0x0> <magic 0x4bcc2a1c> <pcomp> <accomp>]
sent [LCP ConfAck id=0x6 <mru 1600> <auth pap> <magic 0x5fb8dec7> <asyncmap 0x0> <pcomp> <accomp>]
rcvd [LCP ConfAck id=0x1 <asyncmap 0x0> <magic 0x4bcc2a1c> <pcomp> <accomp>]
sent [PAP AuthReq id=0x1 user="cmwap" password=<hidden>]
rcvd [PAP AuthAck id=0x1 "TTP Com PPP - Password Verified OK"]
Remote message: TTP Com PPP - Password Verified OK
PAP authentication succeeded
sent [IPCP ConfReq id=0x1 <addr 0.0.0.0>]
rcvd [IPCP ConfNak id=0x1 <addr 10.183.122.34>]
sent [IPCP ConfReq id=0x2 <addr 10.183.122.34>]
rcvd [IPCP ConfReq id=0x6 <addr 10.0.0.1>]
sent [IPCP ConfAck id=0x6 <addr 10.0.0.1>]
rcvd [IPCP ConfAck id=0x2 <addr 10.183.122.34>]
Cannot determine ethernet address for proxy ARP
local IP address 10.183.122.34
remote IP address 10.0.0.1
Script /etc/ppp/ip-up started (pid 28807)
Script /etc/ppp/ip-up finished (pid 28807), status = 0x0
好,拨号成功!!!现在通过cmwap访问移动内网以发送彩信的时候,会出现
connect: No route to host:
解决办法:
route add default ppp0
查看
netstat -rn
好,现在终于能访问了!!!