@@ -43,6 +43,7 @@ struct ps_calibration_data {
};
#define DS_INPUT_REPORT_USB 0x01
+#define DS_INPUT_REPORT_BT 0x31
#define DS_FEATURE_REPORT_CALIBRATION 5
#define DS_FEATURE_REPORT_CALIBRATION_SIZE 41
@@ -274,6 +275,17 @@ static int ps_device_register_battery(struct ps_device *dev)
return 0;
}
+/* Compute crc32 of HID data and compare against expected CRC. */
+static bool ps_check_crc32(uint8_t seed, uint8_t *data, size_t len, uint32_t report_crc)
+{
+ uint32_t crc;
+
+ crc = crc32_le(0xFFFFFFFF, &seed, 1);
+ crc = ~crc32_le(crc, data, len);
+
+ return crc == report_crc;
+}
+
static struct input_dev *ps_gamepad_create(struct hid_device *hdev)
{
struct input_dev *gamepad;
@@ -390,6 +402,18 @@ static int dualsense_get_calibration_data(struct dualsense *ds)
if (ret < 0)
goto err_free;
+ if (ds->base.hdev->bus == BUS_BLUETOOTH) {
+ /* Last 4 bytes contains crc32 */
+ uint8_t crc_offset = DS_FEATURE_REPORT_CALIBRATION_SIZE - 4;
+ uint32_t report_crc = get_unaligned_le32(&buf[crc_offset]);
+
+ if (!ps_check_crc32(0xa3, buf, crc_offset, report_crc)) {
+ hid_err(ds->base.hdev, "DualSense calibration report CRC's check failed\n");
+ ret = -EILSEQ;
+ goto err_free;
+ }
+ }
+
gyro_pitch_bias = get_unaligned_le16(&buf[1]);
gyro_yaw_bias = get_unaligned_le16(&buf[3]);
gyro_roll_bias = get_unaligned_le16(&buf[5]);
@@ -494,6 +518,16 @@ static int dualsense_parse_report(struct ps_device *ps_dev, struct hid_report *r
*/
if (report->id == DS_INPUT_REPORT_USB && hdev->bus == BUS_USB) {
ds_report = (struct dualsense_input_report *)&data[1];
+ } else if (report->id == DS_INPUT_REPORT_BT && hdev->bus == BUS_BLUETOOTH) {
+ /* Last 4 bytes of input report contain crc32 */
+ uint32_t report_crc = get_unaligned_le32(&data[size - 4]);
+
+ if (!ps_check_crc32(0xa1, data, size - 4, report_crc)) {
+ hid_err(hdev, "DualSense input CRC's check failed, size=%d\n", size);
+ return -EILSEQ;
+ }
+
+ ds_report = (struct dualsense_input_report *)&data[2];
} else {
hid_err(hdev, "Unhandled reportID=%d\n", report->id);
return -1;
@@ -756,6 +790,8 @@ static void ps_remove(struct hid_device *hdev)
}
static const struct hid_device_id ps_devices[] = {
+ { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS5_CONTROLLER),
+ .driver_data = 0 },
{ HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS5_CONTROLLER),
.driver_data = 0 },
};
@@ -567,6 +567,7 @@ static const struct hid_device_id hid_have_special_driver[] = {
#endif
#if IS_ENABLED(CONFIG_HID_PLAYSTATION)
{ HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS5_CONTROLLER) },
++ { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS5_CONTROLLER) },
#endif
#if IS_ENABLED(CONFIG_HID_PRIMAX)
{ HID_USB_DEVICE(USB_VENDOR_ID_PRIMAX, USB_DEVICE_ID_PRIMAX_KEYBOARD) },