Skip to contentSkip to conversation

drivers: hid: warn feature report 0x81

PATCH Superseded Henry Castro 2 participants 6 messages Oct 2, 2022 – Oct 30, 2022 HID

lore
Share & tools
lore
#0 lore raw

PATCH 2/2 drivers: hid: warn feature report 0x81

Unfortunately, my PS DualShock 4, does not support the feature 0x81 to get the MAC address. Instead, use a unique hash to fake a MAC address, so I can use DS4 to play Retroarch :)

---
 drivers/hid/hid-sony.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/hid/hid-sony.c +6 -5
index 656caa07b25f..e3e9c58887cf 100644
@@ -2641,13 +2641,14 @@ static int sony_check_add(struct sony_sc *sc)
 				HID_REQ_GET_REPORT);
 
 		if (ret != DS4_FEATURE_REPORT_0x81_SIZE) {
-			hid_err(sc->hdev, "failed to retrieve feature report 0x81 with the DualShock 4 MAC address\n");
-			ret = ret < 0 ? ret : -EINVAL;
-			goto out_free;
+			uint32_t hash = full_name_hash(NULL, dev_name(&sc->hdev->dev),
+						       strlen(dev_name(&sc->hdev->dev)));
+			hid_warn(sc->hdev, "failed to retrieve feature report 0x81 with the DualShock 4 MAC address\n");
+			memcpy(sc->mac_address, &hash, sizeof(hash));
+		} else {
+			memcpy(sc->mac_address, &buf[1], sizeof(sc->mac_address));
 		}
 
-		memcpy(sc->mac_address, &buf[1], sizeof(sc->mac_address));
-
 		snprintf(sc->hdev->uniq, sizeof(sc->hdev->uniq),
 			 "%pMR", sc->mac_address);
 	} else if ((sc->quirks & SIXAXIS_CONTROLLER_USB) ||
Signature · 1 line
2.20.1
#1 lore raw

I see in the other email. If it doesn't support this request, it is likely a clone device. We are about to submit a brand new DS4 driver (for hid-playstation). It will use a different report (0x12) if I recall which does the same thing. That's the more mainstream one we use.

Thanks,
Roderick

Quoted 38 lines · Henry Castro

Unfortunately, my PS DualShock 4, does not support the feature 0x81 to get the MAC address. Instead, use a unique hash to fake a MAC address, so I can use DS4 to play Retroarch :)

---
 drivers/hid/hid-sony.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/hid/hid-sony.c +6 -6
index 656caa07b25f..e3e9c58887cf 100644
@@ -2641,13 +2641,14 @@ static int sony_check_add(struct sony_sc *sc)
                                HID_REQ_GET_REPORT);
 
                if (ret != DS4_FEATURE_REPORT_0x81_SIZE) {
-                       hid_err(sc->hdev, "failed to retrieve feature report 0x81 with the DualShock 4 MAC address\n");
-                       ret = ret < 0 ? ret : -EINVAL;
-                       goto out_free;
+                       uint32_t hash = full_name_hash(NULL, dev_name(&sc->hdev->dev),
+                                                      strlen(dev_name(&sc->hdev->dev)));
+                       hid_warn(sc->hdev, "failed to retrieve feature report 0x81 with the DualShock 4 MAC address\n");
+                       memcpy(sc->mac_address, &hash, sizeof(hash));
+               } else {
+                       memcpy(sc->mac_address, &buf[1], sizeof(sc->mac_address));
                }
 
-               memcpy(sc->mac_address, &buf[1], sizeof(sc->mac_address));
-
                snprintf(sc->hdev->uniq, sizeof(sc->hdev->uniq),
                         "%pMR", sc->mac_address);
        } else if ((sc->quirks & SIXAXIS_CONTROLLER_USB) ||
--

2.20.1

#2 lore raw

PATCH 2/2 drivers: hid: warn feature report 0x81

Unfortunately, my PS DualShock 4, does not support the feature 0x81 to get the MAC address. Instead, use a unique hash to fake a MAC address, so I can use DS4 to play Retroarch :)

---

Quoted 5 lines
Quoted 5 lines

I see in the other email. If it doesn't support this request, it is likely a clone device. We are about to submit a brand new DS4 driver (for hid-playstation). It will use a different report (0x12) if I recall which does the same thing. That's the more mainstream one we use.

I have 2 DualShock 4, I did not notice but I have one DS4 compatible (clone, I guess).

The DS4 Sony -> returns -ETIMEDOUT
The DS4 clone -> returns -EPIPE

Look great the new DS4 driver :)

 drivers/hid/hid-sony.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/hid/hid-sony.c +6 -5
index 656caa07b25f..e3e9c58887cf 100644
@@ -2641,13 +2641,14 @@ static int sony_check_add(struct sony_sc *sc)
 				HID_REQ_GET_REPORT);
 
 		if (ret != DS4_FEATURE_REPORT_0x81_SIZE) {
-			hid_err(sc->hdev, "failed to retrieve feature report 0x81 with the DualShock 4 MAC address\n");
-			ret = ret < 0 ? ret : -EINVAL;
-			goto out_free;
+			uint32_t hash = full_name_hash(NULL, dev_name(&sc->hdev->dev),
+						       strlen(dev_name(&sc->hdev->dev)));
+			hid_warn(sc->hdev, "failed to retrieve feature report 0x81 with the DualShock 4 MAC address\n");
+			memcpy(sc->mac_address, &hash, sizeof(hash));
+		} else {
+			memcpy(sc->mac_address, &buf[1], sizeof(sc->mac_address));
 		}
 
-		memcpy(sc->mac_address, &buf[1], sizeof(sc->mac_address));
-
 		snprintf(sc->hdev->uniq, sizeof(sc->hdev->uniq),
 			 "%pMR", sc->mac_address);
 	} else if ((sc->quirks & SIXAXIS_CONTROLLER_USB) ||

--
2.20.1

#3 lore raw
Quoted 15 lines · Henry Castro

Unfortunately, my PS DualShock 4, does not support the feature 0x81 to get the MAC address. Instead, use a unique hash to fake a MAC address, so I can use DS4 to play Retroarch :)

---

Quoted 5 lines
Quoted 5 lines

I see in the other email. If it doesn't support this request, it is likely a clone device. We are about to submit a brand new DS4 driver (for hid-playstation). It will use a different report (0x12) if I recall which does the same thing. That's the more mainstream one we use.

Quoted 8 lines

I have 2 DualShock 4, I did not notice but I have one DS4 compatible (clone, I guess).

The DS4 Sony -> returns -ETIMEDOUT
The DS4 clone -> returns -EPIPE

Look great the new DS4 driver :)

Just for reference if you want to try out if 0x12 works, you can try this code. This is from the new driver (ps_get_report is from hid-playstation, but you can just use one of the existing hid calls) if you wanted to try.

#define DS4_FEATURE_REPORT_PAIRING_INFO 0x12
#define DS4_FEATURE_REPORT_PAIRING_INFO_SIZE 16

    if (hdev->bus == BUS_USB) {
        buf = kzalloc(DS4_FEATURE_REPORT_PAIRING_INFO_SIZE, GFP_KERNEL);
        if (!buf)
            return -ENOMEM;

        ret = ps_get_report(hdev, DS4_FEATURE_REPORT_PAIRING_INFO, buf,
                DS4_FEATURE_REPORT_PAIRING_INFO_SIZE, false);
        if (ret) {
            hid_err(hdev, "Failed to retrieve DualShock4 pairing info:
%d\n", ret);
            goto err_free;
        }

        memcpy(ds4->base.mac_address, &buf[1], sizeof(ds4->base.mac_address));
    } else {
#4 lore raw

PATCH 2/2 drivers: hid: warn feature report 0x81

Unfortunately, my PS DualShock 4, does not support the feature 0x81 to get the MAC address. Instead, use a unique hash to fake a MAC address, so I can use DS4 to play Retroarch :)

---

Quoted 4 lines

Just for reference if you want to try out if 0x12 works, you can try this code. This is from the new driver (ps_get_report is from hid-playstation, but you can just use one of the existing hid calls) if you wanted to try.

It works with my 2 DS4 =)

		if (sc->hdev->bus == BUS_USB) {
			buf = kzalloc(DS4_FEATURE_REPORT_PAIRING_INFO_SIZE, GFP_KERNEL);
			if (!buf)
				return -ENOMEM;

			ret = hid_hw_raw_request(sc->hdev, DS4_FEATURE_REPORT_PAIRING_INFO, buf,
						 DS4_FEATURE_REPORT_PAIRING_INFO_SIZE, HID_FEATURE_REPORT,
						 HID_REQ_GET_REPORT);
			if (ret != DS4_FEATURE_REPORT_PAIRING_INFO_SIZE) {
				hid_err(sc->hdev, "Failed to retrieve DualShock4 pairing info:%pe\n", ERR_PTR(ret));
				goto out_free;
			}

			memcpy(sc->mac_address, &buf[1], sizeof(sc->mac_address));
 drivers/hid/hid-sony.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/hid/hid-sony.c +6 -5
index 656caa07b25f..e3e9c58887cf 100644
@@ -2641,13 +2641,14 @@ static int sony_check_add(struct sony_sc *sc)
 				HID_REQ_GET_REPORT);
 
 		if (ret != DS4_FEATURE_REPORT_0x81_SIZE) {
-			hid_err(sc->hdev, "failed to retrieve feature report 0x81 with the DualShock 4 MAC address\n");
-			ret = ret < 0 ? ret : -EINVAL;
-			goto out_free;
+			uint32_t hash = full_name_hash(NULL, dev_name(&sc->hdev->dev),
+						       strlen(dev_name(&sc->hdev->dev)));
+			hid_warn(sc->hdev, "failed to retrieve feature report 0x81 with the DualShock 4 MAC address\n");
+			memcpy(sc->mac_address, &hash, sizeof(hash));
+		} else {
+			memcpy(sc->mac_address, &buf[1], sizeof(sc->mac_address));
 		}
 
-		memcpy(sc->mac_address, &buf[1], sizeof(sc->mac_address));
-
 		snprintf(sc->hdev->uniq, sizeof(sc->hdev->uniq),
 			 "%pMR", sc->mac_address);
 	} else if ((sc->quirks & SIXAXIS_CONTROLLER_USB) ||

--
2.20.1

#5 lore raw

PATCH v2 1/1 drivers: hid: warn feature report 0x81

Unfortunately, my PS DualShock 4, does not support the feature 0x81 to get the MAC address. Instead, fallback feature report 0x12, so I can
use DS4 to play Retroarch :)

---

What do you think about patching the existing driver to fix with the feature 0x12 to obtain the MAC address, meanwhile the new driver is released?

 drivers/hid/hid-sony.c | 27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 deletions(-)
drivers/hid/hid-sony.c +19 -8
index c10513efe677..ee364bef81a7 100644
@@ -506,6 +506,8 @@ struct motion_output_report_02 {
 #define DS4_FEATURE_REPORT_0x05_SIZE 41
 #define DS4_FEATURE_REPORT_0x81_SIZE 7
 #define DS4_FEATURE_REPORT_0xA3_SIZE 49
+#define DS4_FEATURE_REPORT_PAIRING_INFO 0x12
+#define DS4_FEATURE_REPORT_PAIRING_INFO_SIZE 16
 #define DS4_INPUT_REPORT_0x11_SIZE 78
 #define DS4_OUTPUT_REPORT_0x05_SIZE 32
 #define DS4_OUTPUT_REPORT_0x11_SIZE 78
@@ -1259,7 +1261,7 @@ static void nsg_mrxu_parse_report(struct sony_sc *sc, u8 *rd, int size)
 	 *   the touch-related data starts at offset 2.
 	 * For the first byte, bit 0 is set when touchpad button is pressed.
 	 * Bit 2 is set when a touch is active and the drag (Fn) key is pressed.
-	 * This drag key is mapped to BTN_LEFT.  It is operational only when a
+	 * This drag key is mapped to BTN_LEFT.  It is operational only when a
 	 *   touch point is active.
 	 * Bit 4 is set when only the first touch point is active.
 	 * Bit 6 is set when only the second touch point is active.
@@ -1532,13 +1534,13 @@ static int sony_register_touchpad(struct sony_sc *sc, int touch_count,
 	input_set_abs_params(sc->touchpad, ABS_MT_POSITION_Y, 0, h, 0, 0);
 
 	if (touch_major > 0) {
-		input_set_abs_params(sc->touchpad, ABS_MT_TOUCH_MAJOR,
+		input_set_abs_params(sc->touchpad, ABS_MT_TOUCH_MAJOR,
 			0, touch_major, 0, 0);
 		if (touch_minor > 0)
-			input_set_abs_params(sc->touchpad, ABS_MT_TOUCH_MINOR,
+			input_set_abs_params(sc->touchpad, ABS_MT_TOUCH_MINOR,
 				0, touch_minor, 0, 0);
 		if (orientation > 0)
-			input_set_abs_params(sc->touchpad, ABS_MT_ORIENTATION,
+			input_set_abs_params(sc->touchpad, ABS_MT_ORIENTATION,
 				0, orientation, 0, 0);
 	}
 
@@ -2627,7 +2629,8 @@ static int sony_check_add(struct sony_sc *sc)
 			return 0;
 		}
 	} else if (sc->quirks & (DUALSHOCK4_CONTROLLER_USB | DUALSHOCK4_DONGLE)) {
-		buf = kmalloc(DS4_FEATURE_REPORT_0x81_SIZE, GFP_KERNEL);
+		buf = kzalloc(DS4_FEATURE_REPORT_PAIRING_INFO_SIZE, GFP_KERNEL);
+
 		if (!buf)
 			return -ENOMEM;
 
@@ -2641,9 +2644,17 @@ static int sony_check_add(struct sony_sc *sc)
 				HID_REQ_GET_REPORT);
 
 		if (ret != DS4_FEATURE_REPORT_0x81_SIZE) {
-			hid_err(sc->hdev, "failed to retrieve feature report 0x81 with the DualShock 4 MAC address\n");
-			ret = ret < 0 ? ret : -EINVAL;
-			goto out_free;
+			hid_warn(sc->hdev, "failed to retrieve feature report 0x81 with the DualShock 4 MAC address\n");
+
+			ret = hid_hw_raw_request(sc->hdev, DS4_FEATURE_REPORT_PAIRING_INFO,
+						 buf, DS4_FEATURE_REPORT_PAIRING_INFO_SIZE,
+						 HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
+
+			if (ret != DS4_FEATURE_REPORT_PAIRING_INFO_SIZE) {
+				hid_err(sc->hdev, "Failed to retrieve DualShock4 pairing info:%d\n",
+					ret);
+				goto out_free;
+			}
 		}
 
 		memcpy(sc->mac_address, &buf[1], sizeof(sc->mac_address));

--
2.20.1