嵌入式linux2.6.30用usb_modeswitch驱动3G无线上网卡貌似成功但无ttyUSBx出来求教高手
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了嵌入式linux2.6.30用usb_modeswitch驱动3G无线上网卡貌似成功但无ttyUSBx出来求教高手相关的知识,希望对你有一定的参考价值。
! PLEASE REPORT ---
DefaultVendor= 0x1c9e
DefaultProduct= 0xf000
TargetVendor= 0x1c9e
TargetProduct= 0x9603
TargetClass= not set
TargetProductList=""
DetachStorageOnly=0
HuaweiMode=0
SierraMode=0
SonyMode=0
GCTMode=0
KobilMode=0
MessageEndpoint= not set
MessageContent="55534243123456788000000080000606f50402527000000000000000000000"
NeedResponse=0
ResponseEndpoint= not set
Interface=0x00
InquireDevice enabled (default)
Success check enabled, max. wait time 20 seconds
System integration mode disabled
usb_set_debug: Setting debugging level to 15 (on)
usb_os_find_busses: Found 001usb 1-2: usbfs: process 471 (usb_modeswitch) did not claim interface 0 before use
usb_os_find_busses: Skipping non bus directory devices
usb_os_find_devices: Found 002 on 001
usb_os_find_devices: Found 001 on 001
error obtaining child information: Inappropriate ioctl for device
Looking for target devices ...
searching devices, found USB ID 1c9e:f000
found matching vendor ID
searching devices, found USB ID 1d6b:0001
No devices in target mode or class found
Looking for default devices ...
searching devices, found USB ID 1c9e:f000
found matching vendor ID
found matching product ID
adding device
searching devices, found USB ID 1d6b:0001
Found devices in default mode, class or configuration (1)
Accessing device 002 on bus 001 ...
Getting the current device configuration ...
OK, got current device configuration (1)
Using endpoints 0x01 (out) and 0x81 (in)
Using endpoints 0x01 (out) and 0x81 (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: USBModem
Model String: Disk
Revision String: 2.31
-------------------------
USB description data (for identification)
-------------------------
Manufacturer: USB Modem
Product: USB Modem
Serial No.: 000000000000
-------------------------
Setting up communication with interface 0 ...
Using endpoint 0x01 for message sending ...
Trying to send message 1 to endpoint 0x01 ...
OK, message successfully sent
Resetting response endpoint 0x81
Resetting message endpoint 0x01
Checking for mode switch (max. 20 times, once per second) ...
Waiting for original device to vanish ...
usb 1-2: USB disconnect, address 2
usb 1-2: new full speed USB device using at91_ohci and address 3
usb 1-2: configuration #1 chosen from 1 choice
scsi1 : SCSI emulation for USB Mass Storage devices
Waiting for original device to vanish ...
USB error: could not claim interface 0: No such device
USB error: could not release intf 0: No such device
Original device can't be accessed anymore. Good.
Searching for target devices ...
usb_os_find_busses: Found 001
usb_os_find_busses: Skipping non bus directory devices
usb_os_find_devices: Found 003 on 001
usb_os_find_devices: Found 001 on 001
error obtaining child information: Inappropriate ioctl for device
searching devices, found USB ID 1c9e:9603
found matching vendor ID
found matching product ID
adding device
searching devices, found USB ID 1d6b:0001
Found target device, now opening
Found target device 003 on bus 001
Target device description data
-------------------------
Manufacturer: USB Modem
Product: Modem Configuration
Serial No.: 000000000000
-------------------------
Found correct target device
Mode switch succeeded. Bye.
[root@EM9X60 /mnt/nfs]#
[root@EM9X60 /mnt/nfs]#scsi 1:0:0:0: Direct-Access USBModem Disk 2.31 PQ: 0 ANSI: 2
sd 1:0:0:0: [sda] Attached SCSI removable disk
如何在嵌入式linux开发板上使用USB键盘
鼠标驱动可分为几个部分:驱动加载部分、probe部分、open部分、urb回调函数处理部分。下文阴影部分为注解。
一、驱动加载部分
static int __init usb_mouse_init(void)
int retval = usb_register(&usb_mouse_driver);//注册鼠标驱动
if (retval == 0)
info(DRIVER_VERSION ":" DRIVER_DESC);
return retval;
其中usb_mouse_driver的定义为:
static struct usb_driver usb_mouse_driver =
.owner = THIS_MODULE,
.name = "usbmouse",
.probe = usb_mouse_probe,
.disconnect = usb_mouse_disconnect,
.id_table = usb_mouse_id_table,
;
如果注册成功的话,将会调用usb_mouse_probe。那么什么时候才算注册成功呢?
和其它驱动注册过程一样,只有在其对应的“总线”上发现匹配的“设备”才会调用probe。总线匹配的方法和具体总线相关,如:platform_bus_type中是判断驱动名称和平台设备名称是否相同;那如何确认usb总线的匹配方法呢?
Usb设备是注册在usb_bus_type总线下的。查看usb_bus_type的匹配方法。
struct bus_type usb_bus_type =
.name = "usb",
.match = usb_device_match,
.hotplug = usb_hotplug,
.suspend = usb_generic_suspend,
.resume = usb_generic_resume,
;
其中usb_device_match定义了匹配方法
static int usb_device_match (struct device *dev, struct device_driver *drv)
struct usb_interface *intf;
struct usb_driver *usb_drv;
const struct usb_device_id *id;
/* check for generic driver, which we don\'t match any device with */
if (drv == &usb_generic_driver)
return 0;
intf = to_usb_interface(dev);
usb_drv = to_usb_driver(drv);
id = usb_match_id (intf, usb_drv->id_table);
if (id)
return 1;
return 0;
可以看出usb的匹配方法是usb_match_id (intf, usb_drv->id_table),也就是说通过比对“dev中intf信息”和“usb_drv->id_table信息”,如果匹配则说明驱动所对应的设备已经添加到总线上了,所以接下了就会调用drv中的probe方法注册usb设备驱动。
usb_mouse_id_table的定义为:
static struct usb_device_id usb_mouse_id_table[] =
USB_INTERFACE_INFO(3, 1, 2) ,
/* Terminating entry */
;
#define USB_INTERFACE_INFO(cl,sc,pr) /
.match_flags = USB_DEVICE_ID_MATCH_INT_INFO, /
.bInterfaceClass = (cl), /
.bInterfaceSubClass = (sc), /
.bInterfaceProtocol = (pr)
鼠标设备遵循USB人机接口设备(HID),在HID规范中规定鼠标接口类码为:
接口类:0x03
接口子类:0x01
接口协议:0x02
这样分类的好处是设备厂商可以直接利用标准的驱动程序。除了HID类以外还有Mass storage、printer、audio等
#define USB_DEVICE_ID_MATCH_INT_INFO /
(USB_DEVICE_ID_MATCH_INT_CLASS | USB_DEVICE_ID_MATCH_INT_SUBCLASS | USB_DEVICE_ID_MATCH_INT_PROTOCOL)
匹配的过程为:
usb_match_id(struct usb_interface *interface, const struct usb_device_id *id)
struct usb_host_interface *intf;
struct usb_device *dev;
/* proc_connectinfo in devio.c may call us with id == NULL. */
if (id == NULL)
return NULL;
intf = interface->cur_altsetting;
dev = interface_to_usbdev(interface);
/* It is important to check that id->driver_info is nonzero,
since an entry that is all zeroes except for a nonzero
id->driver_info is the way to create an entry that
indicates that the driver want to examine every
device and interface. */
for (; id->idVendor || id->bDeviceClass || id->bInterfaceClass ||
id->driver_info; id++)
if ((id->match_flags & USB_DEVICE_ID_MATCH_VENDOR) &&
id->idVendor != le16_to_cpu(dev->descriptor.idVendor))
continue;
if ((id->match_flags & USB_DEVICE_ID_MATCH_PRODUCT) &&
id->idProduct != le16_to_cpu(dev->descriptor.idProduct))
continue;
/* No need to test id->bcdDevice_lo != 0, since 0 is never greater than any unsigned number. */
if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_LO) &&
(id->bcdDevice_lo > le16_to_cpu(dev->descriptor.bcdDevice)))
continue;
if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_HI) &&
(id->bcdDevice_hi < le16_to_cpu(dev->descriptor.bcdDevice)))
continue;
if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_CLASS) &&
(id->bDeviceClass != dev->descriptor.bDeviceClass))
continue;
if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_SUBCLASS) &&
(id->bDeviceSubClass!= dev->descriptor.bDeviceSubClass))
continue;
if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_PROTOCOL) &&
(id->bDeviceProtocol != dev->descriptor.bDeviceProtocol))
continue;
//接口类
if ((id->match_flags & USB_DEVICE_ID_MATCH_INT_CLASS) &&
(id->bInterfaceClass != intf->desc.bInterfaceClass))
continue;
//接口子类
if ((id->match_flags & USB_DEVICE_ID_MATCH_INT_SUBCLASS) &&
(id->bInterfaceSubClass != intf->desc.bInterfaceSubClass))
continue;
//遵循的协议
if ((id->match_flags & USB_DEVICE_ID_MATCH_INT_PROTOCOL) &&
(id->bInterfaceProtocol != intf->desc.bInterfaceProtocol))
continue;
return id;
return NULL;
从中可以看出,只有当设备的接口类、接口子类、接口协议匹配鼠标驱动时鼠标驱动才会调用probe方法。 参考技术A 首先usb键盘驱动的源代码位于一下目录:
drivers/usb/input/usbkbd.c
将usb键盘驱动编译进内核:
#make menuconfig
Device Drivers--->USB support---->USB HIDBP Keyboard (simple Boot) support
(注意:有可能默认设置USB键盘驱动是不可见的,需修改当前目录下的Kconfig文件,在此不做详细介绍,Kconfig语法有待进一步熟悉:))
保存设置后,重新编译内核:
#source setenv
#make uImage
uImage生成后位于目录:arch/arm/boot/uImage;
(或者直接将usb键盘驱动编译为驱动模块,进行加载也可);
启动系统后,确定usb键盘加载到了那个设备文件,一般为/dev/input/event0设备,可通过cat命令进行确认:
#cat /dev/input/event0
操作usb键盘,会有乱码出现;
然后应用层用这个程序来获取usb键盘的输入:
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <linux/input.h>
struct input_event buff;
int fd;
int read_nu;
int main(int argc, char *argv[])
fd = open("/dev/input/event0", O_RDONLY);
if (fd < 0)
perror("can not open device usbkeyboard!");
exit(1);
int i = 0;
printf("--fd:%d--\n",fd);
while(1)
while(read(fd,&buff,sizeof(struct input_event))==0)
;
//if(buff.code > 40)
printf("type:%d code:%d value:%d\n",buff.type,buff.code,buff.value);
//#if 0
//i++;
//if(i > 12)
//
//break;
//
//#endif
close(fd);
return 1;
运行程序后,按下A键,可见如下输出:
--fd:3--
type:1 code:30 value:1
type:0 code:0 value:0本回答被提问者采纳
以上是关于嵌入式linux2.6.30用usb_modeswitch驱动3G无线上网卡貌似成功但无ttyUSBx出来求教高手的主要内容,如果未能解决你的问题,请参考以下文章
LED_9261在linux2.6.30中tick_led的实现