如何防止 linux 初始化 USB HID 设备 [英] How can I prevent linux from initializing a USB HID device

查看:17
本文介绍了如何防止 linux 初始化 USB HID 设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可以在两种不同模式下工作的 USB HID 设备.模式的选择基于发送给它的 USB 枚举/初始化数据包的顺序.

I have a USB HID device that can work in two different modes. The selection of modes is based on the sequence of USB enumeration/initialization packets sent to it.

我使用的是运行 Raspbian 的 Raspberry Pi 3,但是如果我为桌面 Ubuntu 发行版编译代码,我也会看到同样的问题.

I am using a Raspberry Pi 3 running Raspbian, however I also see the same issue if I compile my code for my desktop Ubuntu distro.

我遇到的问题是 linux 将 USB 设备识别为 HID 设备,然后发送它认为启动设备所必需的命令序列,这可以正常工作并以模式 1"启动设备.

The issue I have is that linux is recognizing the USB device as a HID device and then sending the sequence of commands that it deems necessary to start the device, and this works correctly and starts the device in "Mode 1".

但是,我需要以模式 2"启动设备,为此我需要发送一组略有不同的枚举/初始化命令.

However I need to start the device in "Mode 2" and to do this I need to send a slightly different set of enumeration/initialization commands.

我是 linux 新手,但对 windows 下的 LibUSB 和 LibUSBDotNet 非常有经验,可以在 windows 下获得我想要的行为.

I am new to linux but very experienced with LibUSB and LibUSBDotNet under windows and can get the behavior I desire under windows.

Windows 具有与 linux 相似的行为,因为它会枚举、将设备识别为 USB HID 设备,然后根据它认为合适的方式对其进行初始化,从而导致设备进入模式 1".为了防止 Windows 这样做,我可以为设备创建一个 LibUSB 过滤器驱动程序,然后替换默认驱动程序,因此 Windows 现在将进行初始枚举,实现设备的 VID 和 PID 由 LibUSB 过滤器驱动程序管理(而不是比 Windows HID 驱动程序)然后停止枚举/初始化 - 这允许我的代码接管并完成初始化到模式 2".

Windows has similar behaviour to linux in that it will enumerate, recognise the device as a USB HID device and then initialise it as it deems fit resulting in the device going into "Mode 1". To prevent windows doing this I can create a LibUSB filter driver for the device, which then replaces the default driver, so windows will now do the initial enumeration, realise that the VID and PID of the device are managed by the LibUSB filter driver (rather than the windows HID driver) and then stop enumeration/initialization - this allows my code to take over and complete the initialization into "Mode 2".

如何阻止 Linux 完全枚举/初始化此设备(就像我对 Windows 所做的那样).也许我需要对 udev 规则做些什么,但我不知道是什么,因为我是 linux 新手.

How can I stop Linux from fully enumerating/initializing this device (as I do with windows). Perhaps I need to do something with udev rules or something, but I would have no idea what as I am new to linux.

非常感谢任何帮助

推荐答案

你说得对,你必须玩弄 udev 规则.

you have right, you have to play with the udev rules.

首先,您必须识别您的设备.找到您设备的 idProduct 和 idVendor.您可以使用:

First of all you have to identify your device. Find the idProduct and the idVendor of your device. You can use:

lsusb

然后在 rules.d 文件夹 (/etc/udev/rules.d) 中创建一个名为:

Then in the rules.d folder (/etc/udev/rules.d) create a new file with the name:

10-my-usb.rules

在这个文件中添加这一行

In this file add this line

SUBSYSTEM=="usb",ATTRS{idVendor}=="XXXX", ATTRS{idProduct}=="XXXX", MODE="666", GROUP+="plugdev"

用之前得到的值替换XXXX

Replace the XXXX with the value you get before

然后重新启动您的 udev 规则:

Then restart your udev rules:

sudo udevadm trigger

然后拔掉再插就可以正常使用了

Then unplug and replug normally you can use it

这篇关于如何防止 linux 初始化 USB HID 设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆