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

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

问题描述

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

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

我遇到的问题是linux将USB设备识别为HID设备,然后发送它认为启动该设备所需的命令序列,该命令序列正常运行并以模式1"启动该设备. /p>

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

我是Linux新手,但是在Windows下对LibUSB和LibUSBDotNet很有经验,并且可以在Windows下获得我想要的行为.

Windows与linux具有相似的行为,它将枚举,将该设备识别为USB HID设备,然后在认为合适的时候对其进行初始化,从而使该设备进入模式1".为了防止Windows执行此操作,我可以为设备创建一个LibUSB筛选器驱动程序,然后替换默认驱动程序,因此Windows现在将执行初始枚举,要意识到该设备的VID和PID由LibUSB筛选器驱动程序管理(而是而不是Windows HID驱动程序),然后停止枚举/初始化-这使我的代码可以接管并完成对模式2"的初始化.

如何阻止Linux完全枚举/初始化此设备(就像使用Windows一样).也许我需要对udev规则或某些东西做些什么,但是我不知道我是什么Linux新手.

任何帮助表示赞赏

解决方案

您有权利,必须使用udev规则.

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

lsusb

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

10-my-usb.rules

在此文件中添加以下行

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

将XXXX替换为之前获得的值

然后重新启动udev规则:

sudo udevadm trigger

然后正常拔出并重新插上电源即可

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.

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.

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".

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.

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

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".

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.

Any help greatly appreciated

解决方案

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

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

lsusb

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"

Replace the XXXX with the value you get before

Then restart your udev rules:

sudo udevadm trigger

Then unplug and replug normally you can use it

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

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