什么是 HID_MAX_USAGES

什么是 HID_MAX_USAGES

问题:HID_MAX_USAGES 是什么?它有什么用?为什么这个值这么小?

(代码行:

#define HID_MAX_USAGES                        12288

/usr/src/linux/include/linux/hid.h 

背景信息:我需要将值设置为 32k 并重新编译内核。否则我的游戏鼠标不会被 ubuntu 识别。所以在更改系统之前,我想知道这个值有什么用处。

答案1

我认为HID_MAX_USAGES如此“小”会导致 HID 设备报告描述符,在 hid 设备报告正确大小的情况下,尺寸要小得多,在这种情况下它的描述符不会超过硬编码限制HID_MAX_USAGES

当您遇到键盘或鼠标无法工作的问题,并且在重新编译内核并增加设备后,HID_MAX_USES您的设备开始工作。这很可能是因为下限会拒绝解析报告的描述符。

在阅读和谷歌搜索了一些内容后,我检查了一些 Linux 驱动程序,它们似乎可以覆盖设备本身报告的内容。例如,如果设备报告它有 2^15,则驱动程序可以将其覆盖为允许的最大值HID_MAX_USAGES,或者使用设备使用量的实际大小。

简而言之,基本上发生的事情是,hid-device 报告描述符指定了过多的消费者使用次数(例如 2^15 ),超过了HID_MAX_USAGES。这会阻止正确解析报告的描述符,并且很可能设备或其部分将无法工作。

我一直HID_MAX_USAGES在生产环境中使用这种肮脏的增量式黑客技术。我问过它有多肮脏,但没有好的答案。但据我所知,我可以看到这种黑客技术会占用更大的内存空间,我还没有研究过它是否会稍微损害性能。我看不出这种黑客技术会带来任何安全风险。(如果我错了,请纠正我。)

我认为在错误报告中增加HID_MAX_USAGES是任何主线内核都无法解决的问题,这不是最佳解决方案。评级者我建议您提交一份有关您的 hid- keyboard\mice 无法正常工作的详细错误报告。您还可以联系产品制造商,以在驱动程序中添加适当的支持。


扩展 (来源):

On Tue, 21 May 2013, Christian Ohm wrote:

> Is there any reason why HID_MAX_USAGES shouldn't be more than 12288?  

Well, the reasoning is a mixture of current implementation, and 
reasonability.

- we currently have statically allocated arrays on a per-parser basis, for 
  parsing usages and collection indices. If the number of max usages is 
  going to grow in an uncontrolled manner, we'll have to change the way 
  our parser works (which is not impossible, of course).

- most of the ocurences of huge max usages being presented by the devices 
  have actually turned out to be bogus and could have been fixed by 
  patching the report descriptor in order to reflect the real behavior of 
  the device

Thanks,

-- 
Jiri Kosina
SUSE Labs

上述代码片段来自 hid 子系统内核维护器。

相关内容