简体   繁体   English

Linux内核模块,防止usbcore在探测后注册另一个接口

[英]Linux Kernel Module , prevent usbcore to registered another interface after probe

I am looking for a way to prevent usbcore to register a new interface usbhid or other after a "request" probe . 我正在寻找一种方法来防止usbcore在“请求”探测之后注册usbhid或其他新接口。

C function Linux Kernel Module (mUSBdriver.c) C函数Linux内核模块(mUSBdriver.c)

...
static int mUSBdriver_probe(struct usb_interface *interface, const struct usb_device_id *id){
       printk(KERN_INFO "mUSBdriver: new USB device PLUGGED!");
       return 0; // indicate we will manage this device
       //return -ENODEV;  indicate we will NOT manage this device
    }
...

here are my steps compilation and insertion 这是我的步骤编译和插入

rmmod usbhid 
rmmod mUSBdriver 
make 
insmod mUSBdriver.ko

When i Hot-Plug my device 当我热插拔设备时

~# tail -n 50 /var/log/syslog
...
...kernel: usbcore: registered new interface driver mUSBdriver
...kernel: usb 2-1: Product HID Keyboard
...
...kernel: mUSBdriver:new USB device PLUGGED!
...

My device is an HID keyboard class, then 我的设备是HID键盘类,然后

~# tail -n 50 /var/log/syslog
...
...kernel: usbcore: registered new interface driver mUSBdriver
...kernel: usb 2-1: Product HID Keyboard
...
...kernel: mUSBdriver:new USB device PLUGGED!
...kernel: usbcore: registered new interface driver usbhid
...kernel: usbhid: USB HID core driver
...

Then nothing appears since I decided to manage (return 0) this device. 自从我决定管理(返回0)该设备以来,什么都没出现。 I am looking for a solution to prevent usbcore registered another interface after my driver receive a probe. 我正在寻找一种解决方案,以防止驱动程序收到探针后usbcore注册另一个接口。 I want to consider this device as "BAD USB" and cancel all other operations. 我想将此设备视为“ BAD USB”并取消所有其他操作。 I search in usb.h but nothing . 我在usb.h中搜索,但是什么也没有。

Any idea how do I take ? 知道我该怎么办吗?

my idea: 
- send a notification to usbcore ?
- hook on usbcore  ?

(but I do not know how to do it)

usbcore never allows two drivers to attach to the same interface at the same time. usbcore绝对不允许两个驱动程序同时连接到同一接口。

What usbcore actually did was to register a new interface driver . usbcore实际上所做的是注册一个新的接口驱动程序 This has nothing to do with whether an interface for that driver exists, or is actually available; 这与该驱动程序的接口是否存在或实际可用无关。 it happens when that driver (module) is being loaded. 加载该驱动程序(模块)时发生。


However, there might be a problem: the first driver that gets probed, wins. 但是,可能存在问题:被探测的第一个驱动程序获胜。 If the usbhid driver is already loaded, it's possible that it attaches before your own driver. 如果已经加载了usbhid驱动程序,则它可能会在您自己的驱动程序之前附加。

To prevent usbhid from attaching to your device, you have to tell it to ignore that device with a module option: 为了防止usbhid连接到您的设备,您必须通过模块选项告诉它忽略该设备:

options usbhid quirks=0x1234:0x5678:4

or add a HID_QUIRK_IGNORE entry to drivers/hid/usbhid/hid-quirks.c . 或将HID_QUIRK_IGNORE条目添加到drivers/hid/usbhid/hid-quirks.c

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM