Chinaunix首页 | 论坛 | 博客
  • 博客访问: 15483682
  • 博文数量: 2005
  • 博客积分: 11986
  • 博客等级: 上将
  • 技术积分: 22535
  • 用 户 组: 普通用户
  • 注册时间: 2007-05-17 13:56
文章分类

全部博文(2005)

文章存档

2014年(2)

2013年(2)

2012年(16)

2011年(66)

2010年(368)

2009年(743)

2008年(491)

2007年(317)

分类: 嵌入式

2009-07-20 15:09:08

《捕获linux内核枚举usb鼠标键盘设备完整log信息》
1.修改Makefile和hid-debug.c
在linux-2.6.27.7/drivers/hid/hid-debug.c中定义如下一行.
static int hid_debug = 1;
同时将文件内的所有EXPORT_SYMBOL_GPL行注释掉
// EXPORT_SYMBOL_GPL
修改linux-2.6.27.7/drivers/hid/Makefile
hid-y        += hid-debug.o

在linux-2.6.27.7/drivers/hid/usbhid/Makefile加入添加../hid-debug.o
usbhid-objs    := hid-core.o hid-quirks.o ../hid-debug.o
或者将hid-debug.c拷贝到usbhid目录,在Makefile中添加
usbhid-objs    := hid-core.o hid-quirks.o hid-debug.o

2.配置设置头文件
/lib/modules/2.6.27-7-generic/build/include/linux/hid-debug.h
添加如下一行
#define CONFIG_HID_DEBUG    1

/lib/modules/2.6.27-7-generic/build/include/linux/hid.h
原来
#ifdef CONFIG_HID_DEBUG
 extern int hid_debug;
#endif

#define dbg_hid(format, arg...) if (hid_debug) \
                printk(KERN_EMERG "%s: " format ,\
                __FILE__ , ## arg)
#define dbg_hid_line(format, arg...) if (hid_debug) \
                printk(format, ## arg)

改为
#define CONFIG_HID_DEBUG    1
#ifdef CONFIG_HID_DEBUG
// extern int hid_debug;
#endif

#define dbg_hid(format, arg...) if (1) \
                printk(KERN_DEBUG "[%04d %s]%s: " format ,\
                __LINE__, __func__, __FILE__ , ## arg)
#define dbg_hid_line(format, arg...) if (1) \
                printk(format, ## arg)

3.可以编译了

luther@gliethttp:~/usbhid$ make -C /lib/modules/`uname -r`/build M=`pwd` modules
make: Entering directory `/usr/src/linux-headers-2.6.27-7-generic'
  CC [M]  /home/luther/usbhid/hid-core.o
  CC [M]  /home/luther/usbhid/hid-quirks.o
  CC [M]  /home/luther/usbhid/hid-debug.o
  CC [M]  /home/luther/usbhid/hiddev.o
  LD [M]  /home/luther/usbhid/usbhid.o
  CC [M]  /home/luther/usbhid/usbkbd.o
  CC [M]  /home/luther/usbhid/usbmouse.o
  Building modules, stage 2.
  MODPOST 3 modules
  CC      /home/luther/usbhid/usbhid.mod.o
  LD [M]  /home/luther/usbhid/usbhid.ko
  CC      /home/luther/usbhid/usbkbd.mod.o
  LD [M]  /home/luther/usbhid/usbkbd.ko
  CC      /home/luther/usbhid/usbmouse.mod.o
  LD [M]  /home/luther/usbhid/usbmouse.ko
make: Leaving directory `/usr/src/linux-headers-2.6.27-7-generic'
luther@gliethttp:~/usbhid$

luther@gliethttp:~/usbhid$ cat mak.sh
make -C /lib/modules/`uname -r`/build M=`pwd` modules
luther@gliethttp:~/usbhid$ cat ins.sh
sudo rmmod usbhid
sudo insmod ./usbhid.ko
luther@gliethttp:~/usbhid$ cat unins.sh
sudo rmmod usbhid
sudo insmod /lib/modules/`uname -r`/kernel/drivers/hid/usbhid/usbhid.ko
luther@gliethttp:~/usbhid$



========================================
附上一个参考鼠标报告描述符
unsigned char mouse_report[] = {
    0x05, 0x01, // USAGE_PAGE (Generic Desktop) // parser->global.usage_page = 0x01;进入Generic Desktop
    0x09, 0x02, // USAGE (Mouse)
    0xa1, 0x01, // COLLECTION (Application)     // 对基于Generic Desktop的Mouse信息进行收集
    0x09, 0x01, //   USAGE (Pointer)
    0xa1, 0x00, //   COLLECTION (Physical)      // 对基于Generic Desktop的Porinter信息进行收集[luther.gliethttp]
    0x05, 0x09, //     USAGE_PAGE (Button)      // parser->global.usage_page = 0x09;进入Button
    0x19, 0x01, //     USAGE_MINIMUM (Button 1)
    0x29, 0x03, //     USAGE_MAXIMUM (Button 3)
    0x15, 0x00, //     LOGICAL_MINIMUM (0)
    0x25, 0x01, //     LOGICAL_MAXIMUM (1)
    0x95, 0x03, //     REPORT_COUNT (3)
    0x75, 0x01, //     REPORT_SIZE (1)
    0x81, 0x02, //     INPUT (Data,Var,Abs)     // 生成具有上面4个local属性和2个global属性的Button的Input报告report数据格式,同时复位 local[luther.gliethttp]
    0x95, 0x01, //     REPORT_COUNT (1)
    0x75, 0x05, //     REPORT_SIZE (5)
    0x81, 0x03, //     INPUT (Cnst,Var,Abs)     // 生成只有上面2个local.usage[0-1]属性的Button的Input报告report数据格式[luther.gliethttp]
    0x05, 0x01, //     USAGE_PAGE (Generic Desktop)// parser->global.usage_page = 0x01;进入Generic Desktop
    0x09, 0x30, //     USAGE (X)
    0x09, 0x31, //     USAGE (Y)
    0x09, 0x38, //     USAGE (Wheel)
    0x15, 0x81, //     LOGICAL_MINIMUM (-127)
    0x25, 0x7f, //     LOGICAL_MAXIMUM (127)
    0x75, 0x08, //     REPORT_SIZE (8)
    0x95, 0x03, //     REPORT_COUNT (3)
    0x81, 0x06, //     INPUT (Data,Var,Rel)     // 生成hid设备report上报数据格式[luther.gliethttp]
    0xc0,       //   END_COLLECTION
    0xc0        // END_COLLECTION
};
report->field[0]->usage[0].hid = 0x9001
Mapping: Button.0001 ---> Key.Lefttn
report->field[0]->usage[1].hid = 0x9002
Mapping: Button.0002 ---> Key.RightBt
report->field[0]->usage[2].hid = 0x9003
Mapping: Button.0003 ---> Key.Middletn
report->field[1]->usage[0].hid = 0x1030
Mapping: GenericDesktop.X ---> Relatve.X
report->field[1]->usage[1].hid =0x10031
Mapping: GenericDeskop.Y ---> Relative.Y
report->field[1]->sage[2].hid = 0x10038
Mapping: GenericDeskop.Wheel ---> Relative.Wheel

             for (i = 0; i < report->maxfield; i++)
                for (j = 0; j < report->field[i]->maxusage; j++) {
                    printk("\n\nreport->field[%d]->usage[%d].hid = 0x%04x\n",
                            i, j, report->field[i]->usage[j].hid);
                    hidinput_configure_usage(hidinput, report->field[i],
                                 report->field[i]->usage + j);
                }



luther@gliethttp:~$ sudo cat /proc/kmsg
6>[25440.752066] usb 2-1: USB disconnect, address 4
6>[25443.632283] usb 2-2: new low speed USB device using uhci_hcd and address 5
6>[25443.804876] usb 2-2: configuration #1 chosen from 1 choice
7>[25443.807620] /home/luther/usbhid/hid-core.c: HID probe called for ifnum 0
<7>[25443.827017] /home/luther/usbhid/hid-core.c: report descriptor (size 52, read 52) =  05 01 09 02 a1 01 09 01 a1 00 05 09 19 01 29 03 15 00 25 01 75 01 95 03 81 02 75 05 95 01 81 01 05 01 09 30 09 31 09 38 15 81 25 7f 75 08 95 03 81 06 c0 c0
<7>[25443.827293]   INPUT[INPUT]
<7>[25443.827301]     Field(0)
<7>[25443.827304]       Physical(GenericDesktop.Pointer)
<7>[25443.827311]       Usage(3)
<7>[25443.827314]         Button.0001
<7>[25443.827320]         Button.0002
<7>[25443.827326]         Button.0003
<7>[25443.827331]       Logical Minimum(0)
<7>[25443.827335]       Logical Maximum(1)
<7>[25443.827338]       Report Size(1)
<7>[25443.827341]       Report Count(3)
<7>[25443.827344]       Report Offset(0)
<7>[25443.827347]       Flags( Variable Absolute )
<7>[25443.827357]     Field(1)
<7>[25443.827360]       Physical(GenericDesktop.Pointer)
<7>[25443.827366]       Usage(3)
<7>[25443.827369]         GenericDesktop.X
<7>[25443.827375]         GenericDesktop.Y
<7>[25443.827380]         GenericDesktop.Wheel
<7>[25443.827386]       Logical Minimum(-127)
<7>[25443.827389]       Logical Maximum(127)
<7>[25443.827392]       Report Size(8)
<7>[25443.827395]       Report Count(3)
<7>[25443.827398]       Report Offset(8)
<7>[25443.827401]       Flags( VarRelative )
<6>[5443.827480] input: US Optical Mouse as /devces/pci0000:00/0000:001a.1/usb2/2-2/2-2:1.0/nput/input28
<6>[25443.864401] input,hidraw0: USB HID v1.11 Mous [USB Optical Mouse] on usb-0000:00:1a.1-2
<6>[2449.929272] usb 2-2: USB disconnect, address 5


hid.ko打印出来的log[luther.gliethttp]

<6>[31403.007715] usbcore: registered new interface driver usbhid
<6>[31403.007759] usbhid: v2.6:USB HID core driver
3973]ub22 ofgrto 1coe rm1coc
<7>[31413.973622] [0374 hidinput_configure_usage]/hid/hid-input.c: Mapping: Button.0001 ---> Key.LeftBtn
<7>[31413.973644] [0374 hidinput_configure_usage]/hid/hid-input.c: Mapping: Button.0002 ---> Key.RightBtn
<7>[31413.973653] [0374 hidinput_configure_usage]/hid/hid-input.c: Mapping: Button.0003 ---> Key.MiddleBtn
<7>[31413.93663][34hdnu_ofgr_sg]hdhdiptc apn:Gnrceko. ->Rltv.
7[11.37][34hdnu_oniueuae/i/i-nu.:Mpig eeiDstpY-- eaieY<>343938][34hdnu_ofgr_sg]hdhdiptc apn:Gnrceko.he ->Rltv.he
<6>[31414.009063] input,hidraw0: USB HID 1.11 os UBOtclMue nub00::a12<7>[31417.588760] [0963 hid_input_report]/hid/hid-core.c: report (size 4) (unnumbered)
<7>[31417.588774] [0972 hid_input_report]/hid/hid-core.c: report 0 (size 4) =  00 ff 01 00
<7>[31417.596763] [0963 hid_input_report]/hid/hid-core.c: report (size 4) (unnumbered)
<7>[31417.596776] [0972 hid_input_report]/hid/hid-core.c: report 0 (size 4) =  00 00 01 00
<7>[31417.604760] [0963 hid_input_report]/hid/hid-core.c: report (size 4) (unnumbered)
<7>[31417.604771] [0972 hid_input_report]/hid/hid-core.c: report 0 (size 4) =  00 ff 01 00
<7>[31418.428766] [0963 hid_input_report]/hid/hid-core.c: report (size 4) (unnumbered)
<7>[31418.428780] [0972 hid_input_report]/hid/hid-core.c: report 0 (size 4) =  00 01 00 00
<7>[31418.452762] [0963 hid_input_report]/hid/hid-core.c: report (size 4) (unnumbered)
<7>[31418.452771] [0972 hid_input_report]/hid/hid-core.c: report 0 (size 4) =  00 01 00 00
<7>[31426.740808] [0963 hid_input_report]/hid/hid-core.c: report (size 4) (unnumbered)
<7>[31426.740818] [0972 hid_input_report]/hid/hid-core.c: report 0 (size 4) =  01 00 00 00
<7>[31426.972812] [0963 hid_input_report]/hid/hid-core.c: report (size 4) (unnumbered)
<7>[31426.972825] [0972 hid_input_report]/hid/hid-core.c: report 0 (size 4) =  00 00 00 00
<7>[31427.668816] [0963 hid_input_report]/hid/hid-core.c: report (size 4) (unnumbered)

文件:修改后的源码 hid.tar.bz2
大小:59KB
下载:下载

阅读(4153) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~