We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 5358

Summary: [Patch] Read of feature report of DualSohck4 off by one
Product: SDL Reporter: Mathieu Eyraud <meyraud705>
Component: joystickAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2    
Version: 2.0.13   
Hardware: x86_64   
OS: Linux   
Attachments: read of feature report off by one
fix linux hidapi

Description Mathieu Eyraud 2020-11-19 09:22:17 UTC
Created attachment 4526 [details]
read of feature report off by one

The report id is repeated at the beginning of the answer of ReadFeatureReport(). Actual data start at offset 2.

Here the calibration data as reported by HIDAPI_DumpPacket():
PS4 calibration packet: size = 42
00:       0x05 0x05 0x01 0x00 0x01 0x00 0xf1 0xff
08:       0xa4 0x22 0xdb 0x22 0xd0 0x22 0xef 0xdd
16:       0x28 0xdd 0x87 0xdc 0x1c 0x02 0x1c 0x02
24:       0xd2 0x1f 0x09 0xe0 0x04 0x21 0xff 0xe0
32:       0x67 0x1f 0x38 0xdf 0x0c 0x00 0x90 0x0d
40:       0x99 0xfc

I do not own a DualSense controller to test, but it may also need this patch.
Comment 1 Mathieu Eyraud 2020-11-19 15:54:24 UTC
Bug is actually is Linux hidapi implementation.

A BLE hack is always executed in hid_get_feature_report because is_BLE() always return true. is_BLE return the value of parse_uevent_info which is 1 in case of success.

There is still an issue with the size:

windows usb:
PS4 calibration packet: size = 38
00:       0x02 0x01 0x00 0x01 0x00 0xf1 0xff 0xa4
08:       0x22 0xef 0xdd 0xdb 0x22 0x28 0xdd 0xd0
16:       0x22 0x87 0xdc 0x1c 0x02 0x1c 0x02 0xd2
24:       0x1f 0x09 0xe0 0x04 0x21 0xff 0xe0 0x67
32:       0x1f 0x38 0xdf 0x0c 0x00 0x00

linux usb:
PS4 calibration packet: size = 38
00:       0x02 0x02 0x01 0x00 0x01 0x00 0xf1 0xff
08:       0xa4 0x22 0xef 0xdd 0xdb 0x22 0x28 0xdd
16:       0xd0 0x22 0x87 0xdc 0x1c 0x02 0x1c 0x02
24:       0xd2 0x1f 0x09 0xe0 0x04 0x21 0xff 0xe0
32:       0x67 0x1f 0x38 0xdf 0x0c 0x00

linux usb ble hack disabled:
SDL: PS4 calibration packet: size = 37
00:       0x02 0x01 0x00 0x01 0x00 0xf1 0xff 0xa4
08:       0x22 0xef 0xdd 0xdb 0x22 0x28 0xdd 0xd0
16:       0x22 0x87 0xdc 0x1c 0x02 0x1c 0x02 0xd2
24:       0x1f 0x09 0xe0 0x04 0x21 0xff 0xe0 0x67
32:       0x1f 0x38 0xdf 0x0c 0x00
Comment 2 Mathieu Eyraud 2020-11-19 17:26:16 UTC
Created attachment 4528 [details]
fix linux hidapi

Patch that fixes BLE hack, size, and include upstream patch "File descriptor 0 is perfectly valid, and shouldn't be considered as an error" ( https://github.com/libusb/hidapi/issues/199 ).
Comment 3 Sam Lantinga 2020-11-21 18:21:40 UTC
Fixed, thanks!
http://hg.libsdl.org/SDL/rev/d4587072b314
http://hg.libsdl.org/SDL/rev/ddd319229757
http://hg.libsdl.org/SDL/rev/60dcd2afd107

The actual value should be 37 bytes. The windows code had a bug where it was adding an extra zero byte.