DeviceIoControl in HIDAPI fail with "(0x00000057) The parameter is incorrect" #712
Labels
No labels
3rdparty
Android
API
Author does not respond
bsd
bug
build system/CI
ci-virtual-device
CMake
Contributions Welcome
Core
dependencies
device-specific
documentation
don't_merge
duplicate
enhancement
Example
Haiku
hidraw
hotplug
info required
invalid
libusb
macOS
Misc
Not an issue
question
Release
Test
Test GUI
Windows
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-libusb/hidapi#712
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
I’ve made this project using C++ and HIDAPI to interact with a dualsense controller.
hid_get_feature_reportfails becauseDeviceIoControlreturns an error.When the
DeviceIoControlcall is made, it fails with the error:Error Code: 0x00000057 (The parameter is incorrect)The device is accessible, and I can use
hid_openwithout issues. Other HID operations (like sending reports) work fine.Reference: deviceiocontrol
Do you know the communication protocol of the device and if you are sure the feature report exists?
@mcuee
Yes, I’ve seen similar web-based projects that work. Here is one: core.js line 418. You can also find it running at DualShock Tools.
I’ve looked into how WebHID interacts with the device compared to HIDAPI, reviewed the documentation for both, and still can’t figure out why it isn’t working.
This is something likely device-specific. Need to debug further to know for sure.
@Youw
Any suggestions on what or how to debug to be sure?
I'd start with getting the HID Device descriptor of that device and verifying it supports that output feature report.
There is also a chance that that report is on a different usage page, which is a different logical hid_device on Windows. This one is easy to try if you try your code sample on Linux.
Do you've the WebHID solution running on the same Windows computer with the same HID device?
@JoergAtGithub Yes
@Youw I ran it on a fresh Ubuntu install with this code, and you were right—it worked. I'm just not sure how to replicate this on Windows now.
This is the output from that code.
This only supports my assumption that your output feature report is on a different usage/usage_page. On Windows different usage/usage_page combinations are different logical devices (e.g. listed as different devices under hid_enumerate with identical VID/PID/SerialNumber). You may need to open different
hid_devices for different reports.And that is not a HIDAPI quirk - that's WinAPI behavior, and HIDAPI is only trying to be as thin implementation layer as possible.
Thank you for the clarification, sorry it took me a minute to get it. I’ve taken your advice and enumerated all possible
hid_devices usinghid_enumerateto identify the different usage pages and usages associated with the device. However, based on my findings, the device exposes only one logical interface with a single usage page and usage combination (Usage Page:0x1, Usage:0x5).Here is the code used
Console Output
Just to double confirm, please run hidapi's hidtest application and not your application under Windows to check the output under Windows.
https://github.com/libusb/hidapi/tree/master/hidtest
Sure @mcuee, here’s the output. Sorry for the delay.
There were other reports, but they were related to my Logitech mouse and keyboard. I’m not sure about this unknown one, so I’ve included it just in case. If you would like the entire report page feel free to let me know.
Interesting. You didn't have to use WinAPI to get usage/usage_page -
hid_device_infoalready has these fileds.And to double-check - what version of HIDAPI are you using? Latest release?
So far I don't see any obvious reason whay the sample you have shouldn't work. Report descriptor does have the 0x80 feature report. The only thing that comes to my mind, is that as per HID Report Descriptor, your report size is 8 (+ report ID), and you only provide a buffer of 4 bytes.
Yes, I'm using latest release.
I changed it to 8 (+ report ID).
Output:
I'm really not sure what it could be at this point.
Neither do I.
For historical reasons I'll leave the WebHID implementation if GetFeatureReport on Windows in Chrome:
https://chromium.googlesource.com/chromium/src/+/32352ad08ee673a4d43e8593ce988b224f6482d3/device/hid/hid_connection_win.cc#167
It doesn't differ much from what we do in HIDAPI (at least up to the point of
DeviceIoControlcall. The only difference I see is that we provide both inout and output buffers, but Chrome implementation only passes the output buffer toDeviceIoControl.@92half99 if you're up to it, you could try to remove the input buffer from
DeviceIoControlhere, just to try it locally and check if it makes any difference. And as per Chrome implementation, the buffer has to beFeatureReportByteLength+ 1 bytes, so your latest attempt should have better chance to succeed.I'll give it a shot and let you know how it goes. I’m still just curious why it works on Linux but not on Windows.
@Youw I tried it.
Here's the altered code.
Same output:
At this point, I no longer have suggestions. From what it looks - all should work.
If you discover anything else - feel free to share.
BTW: there is also an experimental windows backend:
winrt. I suspect it should have the same behavior as win32 backend. If you're up to it - go try it as well.It worked! To be perfectly honest, I'm still relatively new to programming. I'm an undergraduate CS student, and I don't fully understand why the
winrtbuild worked while themainbuild didn’t. If you could share your thoughts on this, I would greatly appreciate it.Those are different backends. Something about the implementayion must be different. I'm not sure what, as it is propriatary MS implementation.
I am now encountering a different error regardless of the backend I use. I think I might have to accept that this device is too difficult to work with.
code:
Output:
winrt
hidapi