Skip to contentSkip to conversation

sixaxis: Fix Bluetooth PS3 clone joypad being named like the original

PATCH Applied Szymon Janc 1 participant 2 messages Feb 18, 2021 – Feb 22, 2021 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sixaxis: Fix Bluetooth PS3 clone joypad being named like the original

When cable pairing a PS3 clone device, we should try and keep the USB device name to create a new btd_device so that the joypad is named after its USB name when connecting through Bluetooth.

If that isn't done, "Shanwan" clone joypads are named like the genuine joypads, and kernel Bluetooth quirks aren't applied.

gh-issue: https://github.com/bluez/bluez/issues/46

---
 plugins/sixaxis.c        |  5 ++++-
 profiles/input/server.c  |  2 +-
 profiles/input/sixaxis.h | 13 ++++++++++++-
 3 files changed, 17 insertions(+), 3 deletions(-)
plugins/sixaxis.c +4 -1
index d693a86c0..517cecc47 100644
@@ -387,6 +387,7 @@ get_pairing_type_for_device(struct udev_device *udevice, uint16_t *bus,
 						char **sysfs_path)
 {
 	struct udev_device *hid_parent;
+	const char *hid_name;
 	const char *hid_id;
 	const struct cable_pairing *cp;
 	uint16_t vid, pid;
@@ -401,7 +402,9 @@ get_pairing_type_for_device(struct udev_device *udevice, uint16_t *bus,
 	if (!hid_id || sscanf(hid_id, "%hx:%hx:%hx", bus, &vid, &pid) != 3)
 		return NULL;
 
-	cp = get_pairing(vid, pid);
+	hid_name = udev_device_get_property_value(hid_parent, "HID_NAME");
+
+	cp = get_pairing(vid, pid, hid_name);
 	*sysfs_path = g_strdup(udev_device_get_syspath(udevice));
 
 	return cp;
profiles/input/server.c +1 -1
index d8b413744..79cf08a66 100644
@@ -120,7 +120,7 @@ static bool dev_is_sixaxis(const bdaddr_t *src, const bdaddr_t *dst)
 	vid = btd_device_get_vendor(device);
 	pid = btd_device_get_product(device);
 
-	cp = get_pairing(vid, pid);
+	cp = get_pairing(vid, pid, NULL);
 	if (cp && (cp->type == CABLE_PAIRING_SIXAXIS ||
 					cp->type == CABLE_PAIRING_DS4))
 		return true;
profiles/input/sixaxis.h +12 -1
index a3cda70e4..ab8831995 100644
@@ -29,7 +29,7 @@ struct cable_pairing {
 };
 
 static inline const struct cable_pairing *
-get_pairing(uint16_t vid, uint16_t pid)
+get_pairing(uint16_t vid, uint16_t pid, const char *name)
 {
 	static const struct cable_pairing devices[] = {
 		{
@@ -40,6 +40,14 @@ get_pairing(uint16_t vid, uint16_t pid)
 			.version = 0x0000,
 			.type = CABLE_PAIRING_SIXAXIS,
 		},
+		{
+			.name = "SHANWAN PS3 GamePad",
+			.source = 0x0002,
+			.vid = 0x054c,
+			.pid = 0x0268,
+			.version = 0x0000,
+			.type = CABLE_PAIRING_SIXAXIS,
+		},
 		{
 			.name = "Navigation Controller",
 			.source = 0x0002,
@@ -73,6 +81,9 @@ get_pairing(uint16_t vid, uint16_t pid)
 		if (devices[i].pid != pid)
 			continue;
 
+		if (name && strcmp(name, devices[i].name))
+			continue;
+
 		return &devices[i];
 	}
 
Signature · 1 line
2.29.2
author Applied
#1 lore raw
Quoted 42 lines · On Thursday, 18 February 2021 20:05:45 CET Szymon Janc wrote:

When cable pairing a PS3 clone device, we should try and keep the USB device name to create a new btd_device so that the joypad is named after its USB name when connecting through Bluetooth.

If that isn't done, "Shanwan" clone joypads are named like the genuine joypads, and kernel Bluetooth quirks aren't applied.

gh-issue: https://github.com/bluez/bluez/issues/46

---
 plugins/sixaxis.c        |  5 ++++-
 profiles/input/server.c  |  2 +-
 profiles/input/sixaxis.h | 13 ++++++++++++-
 3 files changed, 17 insertions(+), 3 deletions(-)
plugins/sixaxis.c +4 -1
index d693a86c0..517cecc47 100644
@@ -387,6 +387,7 @@ get_pairing_type_for_device(struct udev_device *udevice,
 uint16_t *bus, char **sysfs_path)
 {
 	struct udev_device *hid_parent;
+	const char *hid_name;
 	const char *hid_id;
 	const struct cable_pairing *cp;
 	uint16_t vid, pid;
@@ -401,7 +402,9 @@ get_pairing_type_for_device(struct udev_device *udevice,
 uint16_t *bus, if (!hid_id || sscanf(hid_id, "%hx:%hx:%hx", bus, &vid,
 &pid) != 3) return NULL;
 
-	cp = get_pairing(vid, pid);
+	hid_name = udev_device_get_property_value(hid_parent, "HID_NAME");
+
+	cp = get_pairing(vid, pid, hid_name);
 	*sysfs_path = g_strdup(udev_device_get_syspath(udevice));
 
 	return cp;
profiles/input/server.c +0 -0
index d8b413744..79cf08a66 100644

profiles/input/server.c static bool dev_is_sixaxis(const bdaddr_t *src, const · line 125

Quoted 7 lines
profiles/input/server.c +1 -1
@@ -120,7 +120,7 @@ static bool dev_is_sixaxis(const bdaddr_t *src, const
 bdaddr_t *dst) vid = btd_device_get_vendor(device);
 	pid = btd_device_get_product(device);
 
-	cp = get_pairing(vid, pid);
+	cp = get_pairing(vid, pid, NULL);
 	if (cp && (cp->type == CABLE_PAIRING_SIXAXIS ||
 					cp->type == 

CABLE_PAIRING_DS4))

Quoted 30 lines
profiles/input/server.c +0 -0
 		return true;
profiles/input/sixaxis.h +9 -1
index a3cda70e4..ab8831995 100644
@@ -29,7 +29,7 @@ struct cable_pairing {
 };
 
 static inline const struct cable_pairing *
-get_pairing(uint16_t vid, uint16_t pid)
+get_pairing(uint16_t vid, uint16_t pid, const char *name)
 {
 	static const struct cable_pairing devices[] = {
 		{
@@ -40,6 +40,14 @@ get_pairing(uint16_t vid, uint16_t pid)
 			.version = 0x0000,
 			.type = CABLE_PAIRING_SIXAXIS,
 		},
+		{
+			.name = "SHANWAN PS3 GamePad",
+			.source = 0x0002,
+			.vid = 0x054c,
+			.pid = 0x0268,
+			.version = 0x0000,
+			.type = CABLE_PAIRING_SIXAXIS,
+		},
 		{
 			.name = "Navigation Controller",
 			.source = 0x0002,

profiles/input/sixaxis.h get_pairing(uint16_t vid, uint16_t pid) · line 88

Quoted 8 lines
profiles/input/sixaxis.h +3 -0
@@ -73,6 +81,9 @@ get_pairing(uint16_t vid, uint16_t pid)
 		if (devices[i].pid != pid)
 			continue;
 
+		if (name && strcmp(name, devices[i].name))
+			continue;
+
 		return &devices[i];
 	}

Applied.

Signature · 2 lines
pozdrawiam
Szymon Janc