Inter-revision diff: patch 7

Comparing v1 (message) to v5 (message)

--- v1
+++ v5
@@ -8,23 +8,50 @@
 
 Signed-off-by: Roderick Colenbrander <roderick.colenbrander@sony.com>
 ---
- drivers/hid/hid-playstation.c | 36 +++++++++++++++++++++++++++++++++++
- drivers/hid/hid-quirks.c      |  1 +
- 2 files changed, 37 insertions(+)
+ drivers/hid/Kconfig           |  1 +
+ drivers/hid/hid-playstation.c | 41 +++++++++++++++++++++++++++++++++++
+ 2 files changed, 42 insertions(+)
 
+diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig
+index 0c141f2312f7..b3ec01c7a0b7 100644
+--- a/drivers/hid/Kconfig
++++ b/drivers/hid/Kconfig
+@@ -856,6 +856,7 @@ config HID_PLANTRONICS
+ config HID_PLAYSTATION
+ 	tristate "PlayStation HID Driver"
+ 	depends on HID
++	select CRC32
+ 	select POWER_SUPPLY
+ 	help
+ 	  Provides support for Sony PS5 controllers including support for
 diff --git a/drivers/hid/hid-playstation.c b/drivers/hid/hid-playstation.c
-index b0c0286cfd2b..042fa8d2627d 100644
+index 0c3956756bf0..2da362d3dbda 100644
 --- a/drivers/hid/hid-playstation.c
 +++ b/drivers/hid/hid-playstation.c
-@@ -43,6 +43,7 @@ struct ps_calibration_data {
+@@ -6,6 +6,7 @@
+  */
+ 
+ #include <linux/bits.h>
++#include <linux/crc32.h>
+ #include <linux/device.h>
+ #include <linux/hid.h>
+ #include <linux/input/mt.h>
+@@ -45,8 +46,14 @@ struct ps_calibration_data {
+ 	int sens_denom;
  };
  
++/* Seed values for DualShock4 / DualSense CRC32 for different report types. */
++#define PS_INPUT_CRC32_SEED	0xA1
++#define PS_FEATURE_CRC32_SEED	0xA3
++
  #define DS_INPUT_REPORT_USB			0x01
+ #define DS_INPUT_REPORT_USB_SIZE		64
 +#define DS_INPUT_REPORT_BT			0x31
++#define DS_INPUT_REPORT_BT_SIZE			78
  
- #define DS_FEATURE_REPORT_CALIBRATION		5
+ #define DS_FEATURE_REPORT_CALIBRATION		0x05
  #define DS_FEATURE_REPORT_CALIBRATION_SIZE	41
-@@ -274,6 +275,17 @@ static int ps_device_register_battery(struct ps_device *dev)
+@@ -292,6 +299,17 @@ static int ps_device_register_battery(struct ps_device *dev)
  	return 0;
  }
  
@@ -42,35 +69,35 @@
  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;
+@@ -342,6 +360,17 @@ static int ps_get_report(struct hid_device *hdev, uint8_t report_id, uint8_t *bu
+ 		return -EINVAL;
+ 	}
  
-+	if (ds->base.hdev->bus == BUS_BLUETOOTH) {
-+		/* Last 4 bytes contains crc32 */
-+		uint8_t crc_offset = DS_FEATURE_REPORT_CALIBRATION_SIZE - 4;
++	if (hdev->bus == BUS_BLUETOOTH) {
++		/* Last 4 bytes contains crc32. */
++		uint8_t crc_offset = 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;
++		if (!ps_check_crc32(PS_FEATURE_CRC32_SEED, buf, crc_offset, report_crc)) {
++			hid_err(hdev, "CRC check failed for reportID=%d\n", report_id);
++			return -EILSEQ;
 +		}
 +	}
 +
- 	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) {
+ 	return 0;
+ }
+ 
+@@ -543,6 +572,17 @@ static int dualsense_parse_report(struct ps_device *ps_dev, struct hid_report *r
+ 	if (hdev->bus == BUS_USB && report->id == DS_INPUT_REPORT_USB &&
+ 			size == DS_INPUT_REPORT_USB_SIZE) {
  		ds_report = (struct dualsense_input_report *)&data[1];
-+	} else if (report->id == DS_INPUT_REPORT_BT && hdev->bus == BUS_BLUETOOTH) {
++	} else if (hdev->bus == BUS_BLUETOOTH && report->id == DS_INPUT_REPORT_BT &&
++			size == DS_INPUT_REPORT_BT_SIZE) {
 +		/* 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);
++		if (!ps_check_crc32(PS_INPUT_CRC32_SEED, data, size - 4, report_crc)) {
++			hid_err(hdev, "DualSense input CRC's check failed\n");
 +			return -EILSEQ;
 +		}
 +
@@ -78,27 +105,14 @@
  	} else {
  		hid_err(hdev, "Unhandled reportID=%d\n", report->id);
  		return -1;
-@@ -756,6 +790,8 @@ static void ps_remove(struct hid_device *hdev)
+@@ -806,6 +846,7 @@ 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 },
++	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS5_CONTROLLER) },
+ 	{ HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS5_CONTROLLER) },
+ 	{ }
  };
-diff --git a/drivers/hid/hid-quirks.c b/drivers/hid/hid-quirks.c
-index 1ca46cb445be..541c8837debd 100644
---- a/drivers/hid/hid-quirks.c
-+++ b/drivers/hid/hid-quirks.c
-@@ -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) },
 -- 
 2.26.2
 
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help