Usb Hid Com Driver Service

The Bluetooth driver stack comprises the core portion of the support provided by Microsoft Windows will discover that the mouse supports the Bluetooth HID service.

文件名称: USB-HID-Specification下载  收藏

详细说明 USB hid中文协议说明 讲得很好 很适合于初学者 我找了很久才找到的 希望初学者有帮助-USB hid Chinese protocol description, put it very well, it is suitable for beginners. I found a long time to find. Want to help beginners

文件列表 点击判断是否您需要的文件 如果是垃圾请在下面评价投诉 :

HID是Human Interface Devices的缩写.翻译成中文即为人机交互设备.这里的人机交互设备是一个宏观上面的概念,任何设备,只要符合HID spec,都可以称之为HID设备

在make menuconfig中 选中USB Human Interface Device full HID support 则所有USB HID都会被驱动 其中包括USB Mouse

在drivers/hid/usbhid/Kconfig看到这项对应的为 CONFIG_USB_HID

又在drivers/hid/usbhid/Makefile中看到 obj- CONFIG_USB_HID usbhid.o

换句话说 如果选中built-in.则 obj-y中加入usbhid.o

如果将这一项选中为M module, 则obj-m中加入usbhid.o

也就是说 如果选中USB Human Interface Device full HID support为built-in.则usbhid.o会被built-in

再在drivers/hid/usbhid/.usbhid.o.cmd中看到usbhid.o其实是由 hid-core.o,hid-quirks.o,hiddev.o组成的

也就是说 当在Menuconfig中选中那一项后 这三个.o都会被built-in.

在drivers/hid/usbhid/hid-core.c中 有如下语句

表明当hid-usb.o hid-core.o等三个组成 添加入kernel core时 会调用hid_init.

hid_init首先调用usbhid_quirks_init

其实就是查找insmod 时给的pid,vid参数在quirks列表中是否有 如果有 就替换 没有就创建

此function只有在选中CONFIG_USB_HIDDEV才会真正做事

bool /dev/hiddev raw HID device support

它只是简单的注册一个USB设备 但这个设备在USB 硬件插入时什么都不作

.match_flags USB_DEVICE_ID_MATCH_INT_CLASS

.bInterfaceClass USB_INTERFACE_CLASS_HID

第一个参数为USB Core传过来的USB设备Interface 第二个参数为本driver的id_table.

首先查看quirks.使用usbhid_lookup_quirk 从静态和动态quirks list中查是否此device包含在其中

interface- desc.bInterfaceSubClass USB_CLASS_HID

interface- desc.bInterfaceSubClass USB_INTERFACE_SUBCLASS_BOOT

interface- desc.bInterfaceProtocol USB_INTERFACE_PROTOCOL_MOUSE

当使用insmod或modprobe安装模块时 可以通过模块参数给模块传递一些数值 这增加了模块的灵活性 但在使用模块参数之前 必须要让这些参数对insmod可见 则可以使用如下方式 让insmod知道参数名

module_param_named name, value, type, perm

perm是参数的权限 其实就是/sys/module/ module_name /parameters的权限

module_param_named size, disk_size, int, S_IRUGO ;

那么在模块代码中disk_size的值就是100 相反 如果加载模块时没有指定参数 那么模块代码中disk_size的值仍是默认的1024

MODULE_LICENSE module license.如果没有 insmod时会警告

static int hid_probe struct usb_interface intf, const struct usb_device_id id

dbg_hid HID probe called for ifnum d n,

intf- altsetting- desc.bInterfaceNumber ;

if . hid usb_hid_configure intf

if hid- quirks HID_QUIRK_RESET_LEDS

hid- claimed HID_CLAIMED_INPUT;

hid- claimed HID_CLAIMED_HIDDEV;

printk HID device not claimed by input or hiddev n ;

if hid- claimed HID_CLAIMED_INPUT

if hid- quirks HID_QUIRK_SONY_PS3_CONTROLLER

hid_fixup_sony_ps3_controller interface_to_usbdev intf,

intf- cur_altsetting- desc.bInterfaceNumber ;

if hid- claimed HID_CLAIMED_INPUT HID_CLAIMED_HIDDEV

if hid- claimed HID_CLAIMED_HIDDEV

if hid- collection i. type HID_COLLECTION_APPLICATION

hid- collection i. usage HID_USAGE_PAGE HID_UP_GENDESK

hid- collection i. usage 0xffff ARRAY_SIZE hid_types

c hid_types hid- collection i. usage 0xffff ;

usb_make_path interface_to_usbdev intf, path, 63 ;

printk : USB HID v x. 02x s s on s n,

hid- version 8, hid- version 0xff, c, hid- name, path ;

1.1: usb_hid_configure intf 解读

static struct hid_device usb_hid_configure struct usb_interface intf

struct usb_host_interface interface intf- cur_altsetting;

struct usb_device dev interface_to_usbdev intf ;

//得到对应vid,pid的quriks.如果没有 则返回0

quirks usbhid_lookup_quirk le16_to_cpu dev- descriptor.idVendor,

le16_to_cpu dev- descriptor.idProduct ;

//如果为boot设备且为keyboard或mouse.则quirks HID_QUIRK_NOGET

if interface- desc.bInterfaceSubClass USB_INTERFACE_SUBCLASS_BOOT

if interface- desc.bInterfaceProtocol USB_INTERFACE_PROTOCOL_KEYBOARD

//HID_QUIRK_IGNORE_MOUSE表示如果为mouse,则忽略

if quirks HID_QUIRK_IGNORE_MOUSE

//如果interface扩展描述符中没有类型为HID_DT_HID条目 或者interface包含的endpoint数目为0 又或者interface endpoint中扩展描述符中没有类型为HID_DT_HID的条目 则退出

if usb_get_extra_descriptor interface, HID_DT_HID, hdesc

. interface- desc.bNumEndpoints

usb_get_extra_descriptor interface- endpoint 0, HID_DT_HID, hdesc

dbg_hid class descriptor not present n ;

if hdesc- desc n. bDescriptorType HID_DT_REPORT

rsize le16_to_cpu hdesc- desc n. wDescriptorLength ;

if . rsize rsize HID_MAX_DESCRIPTOR_SIZE

dbg_hid weird size of report descriptor u n, rsize ;

if . rdesc kmalloc rsize, GFP_KERNEL

dbg_hid couldn t allocate rdesc memory n ;

//向dev的endpoint发送HID_REQ_SET_IDLE request.

hid_set_idle dev, interface- desc.bInterfaceNumber, 0, 0 ;

//取得report description的详细信息,放到rdesc中

if n hid_get_class_descriptor dev, interface- desc.bInterfaceNumber, HID_DT_REPORT, rdesc, rsize 0

dbg_hid reading report descriptor failed n ;

usbhid_fixup_report_descriptor le16_to_cpu dev- descriptor.idVendor,

le16_to_cpu dev- descriptor.idProduct, rdesc,

dbg_hid report descriptor size u, read d , rsize, n ;

dbg_hid_line 02x, unsigned char rdesc n ;

//解析report 并建立hid_device.返回给hid.

if . hid hid_parse_report rdesc, n

dbg_hid parsing report descriptor failed n ;

if . usbhid kzalloc sizeof struct usbhid_device, GFP_KERNEL

usbhid- bufsize HID_MIN_BUFFER_SIZE;

hid_find_max_report hid, HID_INPUT_REPORT, usbhid- bufsize ;

hid_find_max_report hid, HID_OUTPUT_REPORT, usbhid- bufsize ;

hid_find_max_report hid, HID_FEATURE_REPORT, usbhid- bufsize ;

if usbhid- bufsize HID_MAX_BUFFER_SIZE

usbhid- bufsize HID_MAX_BUFFER_SIZE;

hid_find_max_report hid, HID_INPUT_REPORT, insize ;

for n 0; n desc.bNumEndpoints; n

struct usb_endpoint_descriptor endpoint;

endpoint interface- endpoint n. desc;

if endpoint- bmAttributes 3 . 3

if hid- collection- usage HID_GD_MOUSE hid_mousepoll_interval 0

interval hid_mousepoll_interval;

if usb_endpoint_dir_in endpoint

if . usbhid- urbin usb_alloc_urb 0, GFP_KERNEL

pipe usb_rcvintpipe dev, endpoint- bEndpointAddress ;

usb_fill_int_urb usbhid- urbin, dev, pipe, usbhid- inbuf, insize,

usbhid- urbin- transfer_dma usbhid- inbuf_dma;

usbhid- urbin- transfer_flags URB_NO_TRANSFER_DMA_MAP;

if . usbhid- urbout usb_alloc_urb 0, GFP_KERNEL

pipe usb_sndintpipe dev, endpoint- bEndpointAddress ;

usb_fill_int_urb usbhid- urbout, dev, pipe, usbhid- outbuf, 0,

usbhid- urbout- transfer_dma usbhid- outbuf_dma;

usbhid- urbout- transfer_flags URB_NO_TRANSFER_DMA_MAP;

err_hid couldn t find an input interrupt endpoint ;

init_waitqueue_head hid- wait ;

INIT_WORK usbhid- reset_work, hid_reset ;

setup_timer usbhid- io_retry, hid_retry_timeout, unsigned long hid ;

spin_lock_init usbhid- inlock ;

spin_lock_init usbhid- outlock ;

spin_lock_init usbhid- ctrllock ;

hid- version le16_to_cpu hdesc- bcdHID ;

hid- country hdesc- bCountryCode;

usbhid- ifnum interface- desc.bInterfaceNumber;

strlcpy hid- name, dev- manufacturer, sizeof hid- name ;

strlcat hid- name, , sizeof hid- name ;

strlcat hid- name, dev- product, sizeof hid- name ;

snprintf hid- name, sizeof hid- name, HID 04x: 04x,

le16_to_cpu dev- descriptor.idVendor,

hid- vendor le16_to_cpu dev- descriptor.idVendor ;

hid- product le16_to_cpu dev- descriptor.idProduct ;

usb_make_path dev, hid- phys, sizeof hid- phys ;

strlcat hid- phys, /input, sizeof hid- phys ;

snprintf hid- phys len, sizeof hid- phys - len,

d, intf- altsetting 0. desc.bInterfaceNumber ;

if usb_string dev, dev- descriptor.iSerialNumber, hid- uniq, 64 0

usbhid- urbctrl usb_alloc_urb 0, GFP_KERNEL ;

usb_fill_control_urb usbhid- urbctrl, dev, 0, void usbhid- cr,

usbhid- ctrlbuf, 1, hid_ctrl, hid ;

usbhid- urbctrl- setup_dma usbhid- cr_dma;

usbhid- urbctrl- transfer_dma usbhid- ctrlbuf_dma;

usbhid- urbctrl- transfer_flags URB_NO_TRANSFER_DMA_MAP URB_NO_SETUP_DMA_MAP ;

hid- hidinput_input_event usb_hidinput_input_event;

hid- hiddev_hid_event hiddev_hid_event;

hid- hiddev_report_event hiddev_report_event;

usb_free_urb usbhid- urbctrl ;

1.1.1: usbhid_lookup_quirk pid,vid 解析

分别使用usbhid_exists_dquirk pid,vid, usbhid_exists_squirk pid,vid 来查看动态和静态的quirks-list.如果有 则返回此quirks.没有 则返回0

1.1.2 usb_get_extra_descriptor descriptor, type, hdesc 解析

它调用__usb_get_extra_descriptor 来解析参数一 interface或endpoint 描述符 中的扩展描述符区--extra 看是否有类型为参数二 type 的条目 然后把地址交给参数三

Sam未经证明的猜测 HID设备中 interface描述符中包含的这个扩展描述符 其中存放的都是HID信息 以hid_descriptor结构存放

对于HID设备来说,在interface description之后会附加一个hid description, hid description中的最后部份包含有Report description或者Physical Descriptors的长度.

hid_descriptor- usb_descriptor_header- bDescriptorType为HID_DT_HID

后面描述符 包括它自己 hid_descriptor- hid_class_descriptor- bDescriptorType 为HID_DT_REPORT

1.1.3 hid_set_idle struct usb_device dev, int ifnum, int report, int idle

它简单的调用usb_control_msg 发送或接收一个usb 控制消息

usb_control_msg dev, usb_sndctrlpipe dev, 0,

HID_REQ_SET_IDLE, USB_TYPE_CLASS USB_RECIP_INTERFACE, idle 8 report,

ifnum, NULL, 0, USB_CTRL_SET_TIMEOUT ;

usb_sndctrlpipe dev, 0 指出将dev中endpoint 0 设为发送control管道

HID_REQ_SET_IDLE 此控制消息的Request

USB_TYPE_CLASS USB_RECIP_INTERFACE 请求类型.

1.1.4: hid_get_class_descriptor dev, interface- desc.bInterfaceNumber, HID_DT_REPORT, rdesc, rsize

也是通过调用usb_control_msg 发送或接收一个usb 控制消息

发送USB_REQ_GET_DESCRIPTOR 将得到的 report descriptor放到rdesc中

1.1.5: hid_parse_report __u8 start, unsigned size

参数一 通过usb_control_msg发送request USB_REQ_GET_DESCRIPTOR 从设备得到的report descriptor.

2. 将参数一中数据保存在hid_device- rdesc中 长度保存在hid_device- rsize中

3. 使用fetch_item __u8 start, __u8 end, struct hid_item item 得到report description的下一项数据 放到item中

读USB HID driver时 看到quirks这部分内容 因为之前在看USB部分代码时 常看到类似的内容 但对它的语义理解并不清楚 只是笼统地认为是一个需要修正的东西 现在稍微研究一下

quirks: 怪癖的意思,也就是说它某种特性与通常的USB设备不相同

在 /drivers/usb/core/quirks.c中 有个usb_quirk_list列表 它其实就是一个黑名单 描述了某个设备有何种问题 例如

USB_DEVICE 0x03f0, 0x4002, . driver_info USB_QUIRK_NO_AUTOSUSPEND ,

表明 vid 0x03f0,pid 0x4002的设备 Hewlett-Packard PhotoSmart 720 不能自动suspend.

则判断一个设备是不是在这张黑名单上,然后如果是的,就判断它具体是属于哪种问题,

Sam在看USB HID driver时 在modules insmod时 会调用hid_init 它又会调用usbhid_quirks_init

如果在insmod modules时 使用modules参数添加了quirks 格式为 quirks pid:vid:quirks

则将此项内容添加或替换在动态建立的dquirks_list中 换句话说 也就是当modules的提供商知道自己的设备会有什么异常时 可以这样使用

注意 此处仅仅是将某种PID VID的quirks添加进动态列表而已

有动态黑名单 就有静态黑名单 静态黑名单在 /drivers/hid/usbhid/hid-quirks.c中--hid_blacklist 它描绘了已知所有的quirks.

在hid 设备probe时 会调用usbhid_lookup_quirk 它则分别调用usbhid_exists_dquirk 动态 和usbhid_exists_squirk 静态 在静态黑名单和动态黑名单中寻找有没有对应的vid和pid设备 如果有 则将quirks纪录在hid- quirks中.

Describe: ST STM32 USB HID Driver DEMO Software File list time 2008061314 Click to check if it s the file you need, and recomment it at the bottom : HIDDemo_V1.0.

I have a USB barcode scanner device HID that sends keycodes correctly to the host Win08R2. But in the guest OS WinXP, Win7, Win03 some of the keycodes are.

VC-USB-HID.rar - 常用的Windows API调用 怎样编写一个在USB接口读写数据的程序 HID设备的访问 STM32_USB.rar - stm32 USB 开发 上位机 驱动 下位.

For windows xp, Windows 7 drivers: USB HID Device - drivers for windows xp. USB HID Device Driver for Windows 7 Service Pack USB HID Device Driver driver.

USB-HID-Specification USB hid中文协议说明,讲得很好,很适合于初学者。我找了很久才找到的。希望 有 USB develop 242万源代码下载- www.pudn.com

Linux下USB HID device driver研究