WICG / webhid

Web API for accessing Human Interface Devices (HID)
Other
140 stars 35 forks source link

Failed to open the device in ChromeOS #110

Open sd016808 opened 1 year ago

sd016808 commented 1 year ago

The device log: [19:15:28] HID device detected: vendorId=2362, productId=628, name='hid-over-i2c 093A:0274', serial='', deviceIds=[/sys/devices/pci0000:00/0000:00:17.2/i2c_designware.3/i2c-9/9-002c/0018:093A:0274.0002/hidraw/hidraw1']

[19:15:30] Permission broker failed to open '/dev/hidraw1': org.freedesktop.DBus.Error.Failed: permission_broker/permission_denied:Permission to open '/dev/hidraw1' denied

The same code can work in Windows, but failed in ChromeOS.

I find some documents said I must set the udev-rules, I have tried to create a file(50-webhid.rules) as below:
SUBSYSTEM=="hidraw", ATTRS{idVendor}=="2362", MODE="0666" SUBSYSTEM=="hidraw1", ATTRS{idVendor}=="2362", MODE="0666" SUBSYSTEM=="hidraw", ATTRS{idVendor}=="093A", MODE="0666" SUBSYSTEM=="hidraw1", ATTRS{idVendor}=="093A", MODE="0666" KERNEL=="hidraw", ATTRS{idVendor}=="093A", MODE="0666" KERNEL=="hidraw", ATTRS{idVendor}=="2362", MODE="0666" KERNEL=="hidraw", SUBSYSTEM=="hidraw", ATTRS{idVendor}=="093A", MODE="0666" KERNEL=="hidraw", SUBSYSTEN=="hidraw", ATTRS{idVendor}=="2362", MODE="0666"

After creating this file, I am still unable to open the device and receive the same error message. Do you have any suggestions? Thank you for your help.

nondebug commented 1 year ago

Try this one:

KERNEL=="hidraw*", SUBSYSTEM=="hidraw", ATTRS{idVendor}=="093a", MODE="0666"

Note 093a instead of 093A. Attributes are strings and the comparison is case-sensitive. Use lowercase hex digits when matching ATTRS{idVendor}.

Confusingly, Bluetooth udev rules match against KERNELS which uses uppercase hex digits.

sd016808 commented 1 year ago

I have done your suggestion, but I got the same result. The log in chrome://system shows the following information: 2023-05-11T02:26:35.342090Z INFO permission_broker[1374]: ProcessPath(/dev/hidraw2) 2023-05-11T02:26:35.436572Z INFO permission_broker[1374]: AllowUsbDeviceRule: IGNORE 2023-05-11T02:26:35.437162Z INFO permission_broker[1374]: AllowTtyDeviceRule: IGNORE 2023-05-11T02:26:35.437202Z INFO permission_broker[1374]: DenyClaimedUsbDeviceRule: IGNORE 2023-05-11T02:26:35.437257Z INFO permission_broker[1374]: DenyUninitializedDeviceRule: IGNORE 2023-05-11T02:26:35.437286Z INFO permission_broker[1374]: DenyUsbDeviceClassRule: IGNORE 2023-05-11T02:26:35.437316Z INFO permission_broker[1374]: DenyUsbVendorIdRule: IGNORE 2023-05-11T02:26:35.437345Z INFO permission_broker[1374]: AllowHidrawDeviceRule: ALLOW 2023-05-11T02:26:35.437376Z INFO permission_broker[1374]: AllowGroupTtyDeviceRule: IGNORE 2023-05-11T02:26:35.437403Z INFO permission_broker[1374]: DenyGroupTtyDeviceRule: IGNORE 2023-05-11T02:26:35.437479Z INFO permission_broker[1374]: message repeated 2 times: [ DenyGroupTtyDeviceRule: IGNORE] 2023-05-11T02:26:35.583029Z INFO permission_broker[1374]: DenyClaimedHidrawDeviceRule: DENY 2023-05-11T02:26:35.583110Z INFO permission_broker[1374]: Verdict for /dev/hidraw2: DENY 2023-05-11T02:26:35.583167Z ERR permission_broker[1374]: OpenPathImpl(...): Domain=permission_broker, Code=permission_denied, Message=Permission to open '/dev/hidraw2' denied

I suspect that the issue might be related to the DenyClaimedHidrawDeviceRule being set to DENY, but I'm not sure why it's set to that.

P.S. My Hid Device is a touch pad.

sd016808 commented 1 year ago

I have tried another Ubuntu system, and everything works fine after the rules are set. However, ChromeOS still does not work.

My ChromeOS uses the 64-bit version of Chromium 97.0.4666.0 and Chrome 113.0.5650.0.

Actually, I have tried several devices on ChromeOS. Not only our device cannot open, but also any device on it cannot be opened.

nondebug commented 1 year ago

Ah right, on ChromeOS the file permissions are irrelevant so udev rules won't help. The permission broker manages device access. If the device is blocked by DenyClaimedHidrawDeviceRule then that means there's another subsystem that claimed one of the device's interfaces. Can you share the device's HID report descriptor?

sd016808 commented 1 year ago

I show the information from HID Explorer. If you need more, please let me know.

productName: PIXA2342:00 093A:200D
vendorId:    0x093A (2362)
productId:   0x200D (8205)
opened:      false
collections[0]
  Usage 000D:0005
  Input reports: 0x01
  Feature reports: 0x09, 0x04, 0x08, 0x03
collections[1]
  Usage 000D:000E
  Feature reports: 0x07, 0x06
collections[2]
  Usage FF00:0001
  Feature reports: 0x41, 0x43, 0x42
Input report 0x01
  2 values * 1 bits (bits 0 to 1)
    Data,Var,Abs
    Usages: 000D:0047 (Digitizers > Touch Valid), 000D:0042 (Digitizers > Tip Switch)
    Logical bounds: 0 to 1
  2 values * 1 bits (bits 2 to 3)
    Cnst,Var,Abs
    Logical bounds: 0 to 1
  4 bits (bits 4 to 7)
    Data,Var,Abs
    Usage: 000D:0051 (Digitizers > Contact Identifier)
    Logical bounds: 0 to 15
  16 bits (bits 8 to 23)
    Data,Var,Abs
    Usage: 0001:0030 (Generic Desktop > X)
    Logical bounds: 0 to 3996
    Physical bounds: 0 to 1269
    Units: 10^-2*cm
  16 bits (bits 24 to 39)
    Data,Var,Abs
    Usage: 0001:0031 (Generic Desktop > Y)
    Logical bounds: 0 to 2242
    Physical bounds: 0 to 712
    Units: 10^-2*cm
  16 bits (bits 40 to 55)
    Data,Var,Abs
    Usage: 000D:0030 (Digitizers > Tip Pressure)
    Logical bounds: 0 to 2242
    Physical bounds: 0 to 712
    Units: 10^-2*cm
  16 bits (bits 56 to 71)
    Data,Var,Abs
    Usage: 000D:0056 (Digitizers > Scan Time)
    Logical bounds: 0 to 65535
    Physical bounds: 0 to 65535
    Units: 10^-4*s
  8 bits (bits 72 to 79)
    Data,Var,Abs
    Usage: 000D:0054 (Digitizers > Contact Count)
    Logical bounds: 0 to 5
    Physical bounds: 0 to 65535
    Units: 10^-4*s
  1 bit (bit 80)
    Data,Var,Abs
    Usage: 0009:0001 (Button Button 1)
    Logical bounds: 0 to 1
    Physical bounds: 0 to 65535
    Units: 10^-4*s
  7 bits (bits 81 to 87)
    Data,Var,Abs
    Usage: FF00:0024 (Vendor-defined page 0xFF00 usage 0x0024)
    Logical bounds: 0 to 127
    Physical bounds: 0 to 65535
    Units: 10^-4*s
  32 bits (bits 88 to 119)
    Data,Var,Abs
    Usage: FF00:0025 (Vendor-defined page 0xFF00 usage 0x0025)
    Logical bounds: 0 to 2147483647
    Physical bounds: 0 to 65535
    Units: 10^-4*s
  16 bits (bits 120 to 135)
    Data,Var,Abs
    Usage: FF00:0026 (Vendor-defined page 0xFF00 usage 0x0026)
    Logical bounds: 0 to 32767
    Physical bounds: 0 to 65535
    Units: 10^-4*s
Feature report 0x09
  256 values * 8 bits (bits 0 to 2047)
    Data,Var,Abs
    Usage: FF00:00C5 (Vendor-defined page 0xFF00 usage 0x00C5)
    Logical bounds: 0 to 255
    Physical bounds: 0 to 65535
    Units: 10^-4*s
Feature report 0x04
  8 bits (bits 0 to 7)
    Data,Var,Abs
    Usage: 000D:0059 (Digitizers > Pad Type)
    Logical bounds: 0 to 2
    Physical bounds: 0 to 65535
    Units: 10^-4*s
Feature report 0x08
  1 bit (bit 0)
    Data,Var,Abs
    Usage: 000D:0060 (Digitizers > Latency Mode)
    Logical bounds: 0 to 1
    Physical bounds: 0 to 65535
    Units: 10^-4*s
  7 values * 1 bits (bits 1 to 7)
    Cnst,Var,Abs
    Logical bounds: 0 to 1
    Physical bounds: 0 to 65535
    Units: 10^-4*s
Feature report 0x03
  8 bits (bits 0 to 7)
    Data,Var,Abs
    Usage: 000D:0055 (Digitizers > Contact Count Maximum)
    Logical bounds: 0 to 5
    Physical bounds: 0 to 65535
    Units: 10^-4*s
Feature report 0x07
  2 values * 1 bits (bits 0 to 1)
    Data,Var,Abs
    Usages: 000D:0057 (Digitizers > Surface Switch), 000D:0058 (Digitizers > Button Switch)
    Logical bounds: 0 to 1
    Physical bounds: 0 to 65535
    Units: 10^-4*s
  6 values * 1 bits (bits 2 to 7)
    Cnst,Var,Abs
    Logical bounds: 0 to 1
    Physical bounds: 0 to 65535
    Units: 10^-4*s
Feature report 0x06
  8 bits (bits 0 to 7)
    Data,Var,Abs
    Usage: 000D:0052 (Digitizers > Device Mode)
    Logical bounds: 0 to 10
    Physical bounds: 0 to 65535
    Units: 10^-4*s
Feature report 0x41
  256 values * 8 bits (bits 0 to 2047)
    Data,Var,Abs
    Usage: FF00:0005 (Vendor-defined page 0xFF00 usage 0x0005)
    Logical bounds: 0 to 255
    Physical bounds: 0 to 65535
    Units: 10^-4*s
Feature report 0x43
  3 values * 8 bits (bits 0 to 23)
    Data,Var,Abs
    Usage: FF00:00C4 (Vendor-defined page 0xFF00 usage 0x00C4)
    Logical bounds: 0 to 255
    Physical bounds: 0 to 65535
    Units: 10^-4*s
Feature report 0x42
  3 values * 8 bits (bits 0 to 23)
    Data,Var,Abs
    Usage: FF00:00C4 (Vendor-defined page 0xFF00 usage 0x00C4)
    Logical bounds: 0 to 255
    Physical bounds: 0 to 65535
    Units: 10^-4*s
sd016808 commented 1 year ago

Hi, any updates on this case?

nondebug commented 1 year ago

This is the permission broker working as intended. Permission broker's DenyClaimedHidrawDeviceRule looks at sibling devices to see if there are any children with capabilities that should be blocked. If so, it blocks HID access to the whole device.

In this case the device is a touchpad, so a device is created in the input subsystem. DenyClaimedHidrawDeviceRule::ShouldSiblingSubsystemExcludeHidAccess has special logic for input devices to check for specific key or axis input capabilities found on pointing devices and keyboards. Touchpads have pointing capabilities (ABS_X, ABS_Y, BTN_LEFT) which cause their HID interfaces to be blocked by the permission broker.

The same code can work in Windows, but failed in ChromeOS.

If this allows you to capture touchpad inputs on Windows then that's not intended and we should update the blocklist to include the Digitizers usage page.

sd016808 commented 1 year ago

Could we have a configuration setting to skip the permission inspection process?

I require the capability to read/write the feature report for Vendor Defined usage pages. collections[2] Usage FF00:0001 Feature reports: 0x41, 0x43, 0x42

This is crucial for updating our touchpad firmware across different operating systems and conducting thorough functionality checks before delivering the touchpad to customers. It would be highly inconvenient if we were unable to utilize WebHID for these purposes.

nondebug commented 1 year ago

The blocking happens at the platform level and isn't part of WebHID. Can you file a ChromeOS issue describing your use case?