linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 2/2] drivers: hid: warn feature report 0x81
@ 2022-10-02 22:01 Henry Castro
  2022-10-06  4:02 ` Roderick Colenbrander
  0 siblings, 1 reply; 6+ messages in thread
From: Henry Castro @ 2022-10-02 22:01 UTC (permalink / raw)
  To: thunderbird2k
  Cc: Henry Castro, Jiri Kosina, Benjamin Tissoires, linux-input, linux-kernel

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 :)

Signed-off-by: Henry Castro <hcvcastro@gmail.com>
---
 drivers/hid/hid-sony.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c
index 656caa07b25f..e3e9c58887cf 100644
--- a/drivers/hid/hid-sony.c
+++ b/drivers/hid/hid-sony.c
@@ -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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] drivers: hid: warn feature report 0x81
  2022-10-02 22:01 [PATCH 2/2] drivers: hid: warn feature report 0x81 Henry Castro
@ 2022-10-06  4:02 ` Roderick Colenbrander
  2022-10-06 13:22   ` Henry Castro
  0 siblings, 1 reply; 6+ messages in thread
From: Roderick Colenbrander @ 2022-10-06  4:02 UTC (permalink / raw)
  To: Henry Castro; +Cc: Jiri Kosina, Benjamin Tissoires, linux-input, linux-kernel

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

On Sun, Oct 2, 2022 at 3:01 PM Henry Castro <hcvcastro@gmail.com> wrote:
>
> 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 :)
>
> Signed-off-by: Henry Castro <hcvcastro@gmail.com>
> ---
>  drivers/hid/hid-sony.c | 11 ++++++-----
>  1 file changed, 6 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c
> index 656caa07b25f..e3e9c58887cf 100644
> --- a/drivers/hid/hid-sony.c
> +++ b/drivers/hid/hid-sony.c
> @@ -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
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 2/2] drivers: hid: warn feature report 0x81
  2022-10-06  4:02 ` Roderick Colenbrander
@ 2022-10-06 13:22   ` Henry Castro
  2022-10-06 14:01     ` Roderick Colenbrander
  0 siblings, 1 reply; 6+ messages in thread
From: Henry Castro @ 2022-10-06 13:22 UTC (permalink / raw)
  To: thunderbird2k
  Cc: Henry Castro, Jiri Kosina, Benjamin Tissoires, linux-input, linux-kernel

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 :)

Signed-off-by: Henry Castro <hcvcastro@gmail.com>
---

>> 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(-)

diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c
index 656caa07b25f..e3e9c58887cf 100644
--- a/drivers/hid/hid-sony.c
+++ b/drivers/hid/hid-sony.c
@@ -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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] drivers: hid: warn feature report 0x81
  2022-10-06 13:22   ` Henry Castro
@ 2022-10-06 14:01     ` Roderick Colenbrander
  2022-10-06 14:53       ` Henry Castro
  0 siblings, 1 reply; 6+ messages in thread
From: Roderick Colenbrander @ 2022-10-06 14:01 UTC (permalink / raw)
  To: Henry Castro; +Cc: Jiri Kosina, Benjamin Tissoires, linux-input, linux-kernel

On Thu, Oct 6, 2022 at 6:22 AM Henry Castro <hcvcastro@gmail.com> wrote:
>
> 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 :)
>
> Signed-off-by: Henry Castro <hcvcastro@gmail.com>
> ---
>
> >> 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 :)
>

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 {

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 2/2] drivers: hid: warn feature report 0x81
  2022-10-06 14:01     ` Roderick Colenbrander
@ 2022-10-06 14:53       ` Henry Castro
  2022-10-30 15:40         ` [PATCH v2] " Henry Castro
  0 siblings, 1 reply; 6+ messages in thread
From: Henry Castro @ 2022-10-06 14:53 UTC (permalink / raw)
  To: thunderbird2k
  Cc: Henry Castro, Jiri Kosina, Benjamin Tissoires, linux-input, linux-kernel

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 :)

Signed-off-by: Henry Castro <hcvcastro@gmail.com>
---

> 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(-)

diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c
index 656caa07b25f..e3e9c58887cf 100644
--- a/drivers/hid/hid-sony.c
+++ b/drivers/hid/hid-sony.c
@@ -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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2] drivers: hid: warn feature report 0x81
  2022-10-06 14:53       ` Henry Castro
@ 2022-10-30 15:40         ` Henry Castro
  0 siblings, 0 replies; 6+ messages in thread
From: Henry Castro @ 2022-10-30 15:40 UTC (permalink / raw)
  To: thunderbird2k
  Cc: Henry Castro, Jiri Kosina, Benjamin Tissoires, Henrik Rydberg,
	linux-input, linux-kernel

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 :)

Signed-off-by: Henry Castro <hcvcastro@gmail.com>
---

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(-)

diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c
index c10513efe677..ee364bef81a7 100644
--- a/drivers/hid/hid-sony.c
+++ b/drivers/hid/hid-sony.c
@@ -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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-10-30 15:41 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-02 22:01 [PATCH 2/2] drivers: hid: warn feature report 0x81 Henry Castro
2022-10-06  4:02 ` Roderick Colenbrander
2022-10-06 13:22   ` Henry Castro
2022-10-06 14:01     ` Roderick Colenbrander
2022-10-06 14:53       ` Henry Castro
2022-10-30 15:40         ` [PATCH v2] " Henry Castro

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).