Skip to contentSkip to conversation

sixaxis: Improved support for DualShock 3 clones

RFC New Szymon Janc 1 participant 4 messages Apr 8, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover sixaxis: Improved support for DualShock 3 clones

Hi,

Some DualShock3 clones (eg ShanWan) were reported to not provide valid SDP record required by HID profile. Due to this those failed to work with current BlueZ sixaxis code (ie no input device were created).

This small serie is an attempt to extend DS3 support also with those misbehaving clones. Idea is that we can provide fixed SDP recrod for devices that use valid PID/VID and skip SDP search.

In this version SDP is kept in sixaxis plugin and provided via btd_device_set_record instead of SDP search. Nice addition is that sixaxis specific code is no longer needed in input server.

This makes code similar to how original Fedora sixaxis plugin worked as suggested in previous review round.

I tested this with genuine DS3 and it seems to work OK. Testing with clones is stil required though.

@Alex
Testing with Navigation Controller is also needed ie if SDP record is same as with DS3 or if we need dedicated one.

BR
Szymon Janc

Szymon Janc (3):
core/device: Add support for setting SDP record
sixaxis: Provide DualShock 3 SDP record while adding new device profiles/input: Remove sixaxis specific code

 Makefile.plugins        |   1 +
 plugins/sixaxis.c       | 166 ++++++++++++++++++++++++++++++++++++++++++++++++
 profiles/input/server.c |  89 +-------------------------
 src/device.c            |  31 +++++++++
 src/device.h            |   3 +
 5 files changed, 203 insertions(+), 87 deletions(-)
Signature · 1 line
2.1.4
#1 lore raw

RFC v2 1/3 core/device: Add support for setting SDP record

This allows to set SDP record for device without resolving services over SDP. After SDP is provided profiles are probed.

---
 src/device.c | 31 +++++++++++++++++++++++++++++++
 src/device.h |  3 +++
 2 files changed, 34 insertions(+)
src/device.c +31 -0
index 91dea27..e5cf362 100644
@@ -5293,6 +5293,37 @@ static sdp_list_t *read_device_records(struct btd_device *device)
 	return recs;
 }
 
+void btd_device_set_record(struct btd_device *device, const char *uuid,
+							sdp_record_t *rec)
+{
+	/* This API is only used for BR/EDR */
+	struct bearer_state *state = &device->bredr_state;
+	struct browse_req *req;
+	sdp_list_t *recs = NULL;
+
+	if (!rec)
+		return;
+
+	req = browse_request_new(device, NULL);
+	if (!req)
+		return;
+
+	recs = sdp_list_append(recs, rec);
+	update_bredr_services(req, recs);
+	sdp_list_free(recs, NULL);
+
+	device->svc_refreshed = true;
+	state->svc_resolved = true;
+
+	device_probe_profiles(device, req->profiles_added);
+
+	/* Propagate services changes */
+	g_dbus_emit_property_changed(dbus_conn, req->device->path,
+						DEVICE_INTERFACE, "UUIDs");
+
+	device_svc_resolved(device, device->bdaddr_type, 0);
+}
+
 const sdp_record_t *btd_device_get_record(struct btd_device *device,
 							const char *uuid)
 {
src/device.h +3 -0
index 9e86469..7e9a369 100644
@@ -62,6 +62,9 @@ struct device_addr_type {
 int device_addr_type_cmp(gconstpointer a, gconstpointer b);
 GSList *btd_device_get_uuids(struct btd_device *device);
 void device_probe_profiles(struct btd_device *device, GSList *profiles);
+
+void btd_device_set_record(struct btd_device *device, const char *uuid,
+							sdp_record_t *rec);
 const sdp_record_t *btd_device_get_record(struct btd_device *device,
 						const char *uuid);
 struct gatt_primary *btd_device_get_primary(struct btd_device *device,
Signature · 1 line
2.1.4
#2 lore raw

RFC v2 2/3 sixaxis: Provide DualShock 3 SDP record while adding new device

In reply to Szymon Janc

This allows to skip SDP search for DualShock 3 devices. Since some DS3 clones were reported to not provide any SDP record this should allow to operate them.

---
 Makefile.plugins  |   1 +
 plugins/sixaxis.c | 166 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 167 insertions(+)
Makefile.plugins +1 -0
index 52b51c5..9425c0a 100644
@@ -116,4 +116,5 @@ plugins_sixaxis_la_SOURCES = plugins/sixaxis.c
 plugins_sixaxis_la_LDFLAGS = $(AM_LDFLAGS) -module -avoid-version \
 						-no-undefined @UDEV_LIBS@
 plugins_sixaxis_la_CFLAGS = $(AM_CFLAGS) -fvisibility=hidden @UDEV_CFLAGS@
+plugins_sixaxis_la_LIBADD = lib/libbluetooth-internal.la
 endif
plugins/sixaxis.c +166 -0

184 lines not on this page · raw message

Signature · 1 line
2.1.4
#3 lore raw

RFC v2 3/3 profiles/input: Remove sixaxis specific code

In reply to Szymon Janc

Sixaxis devices now have provides SDP record while being created. There is no need to punch sixaxis holes in input code anymore.

---
 profiles/input/server.c | 89 ++-----------------------------------------------
 1 file changed, 2 insertions(+), 87 deletions(-)
profiles/input/server.c +2 -87
index eb3fcf8..43733ea 100644
@@ -67,85 +67,6 @@ static int server_cmp(gconstpointer s, gconstpointer user_data)
 	return bacmp(&server->src, src);
 }
 
-struct sixaxis_data {
-	GIOChannel *chan;
-	uint16_t psm;
-};
-
-static void sixaxis_sdp_cb(struct btd_device *dev, int err, void *user_data)
-{
-	struct sixaxis_data *data = user_data;
-	const bdaddr_t *src;
-
-	DBG("err %d (%s)", err, strerror(-err));
-
-	if (err < 0)
-		goto fail;
-
-	src = btd_adapter_get_address(device_get_adapter(dev));
-
-	if (input_device_set_channel(src, device_get_address(dev), data->psm,
-								data->chan) < 0)
-		goto fail;
-
-	g_io_channel_unref(data->chan);
-	g_free(data);
-
-	return;
-
-fail:
-	g_io_channel_shutdown(data->chan, TRUE, NULL);
-	g_io_channel_unref(data->chan);
-	g_free(data);
-}
-
-static void sixaxis_browse_sdp(const bdaddr_t *src, const bdaddr_t *dst,
-						GIOChannel *chan, uint16_t psm)
-{
-	struct btd_device *device;
-	struct sixaxis_data *data;
-
-	device = btd_adapter_find_device(adapter_find(src), dst, BDADDR_BREDR);
-	if (!device)
-		return;
-
-	data = g_new0(struct sixaxis_data, 1);
-	data->chan = g_io_channel_ref(chan);
-	data->psm = psm;
-
-	if (psm == L2CAP_PSM_HIDP_CTRL)
-		device_discover_services(device);
-
-	device_wait_for_svc_complete(device, sixaxis_sdp_cb, data);
-}
-
-static bool dev_is_sixaxis(const bdaddr_t *src, const bdaddr_t *dst)
-{
-	struct btd_device *device;
-	uint16_t vid, pid;
-
-	device = btd_adapter_find_device(adapter_find(src), dst, BDADDR_BREDR);
-	if (!device)
-		return false;
-
-	vid = btd_device_get_vendor(device);
-	pid = btd_device_get_product(device);
-
-	/* DualShock 3 */
-	if (vid == 0x054c && pid == 0x0268)
-		return true;
-
-	/* DualShock 4 */
-	if (vid == 0x054c && pid == 0x05c4)
-		return true;
-
-	/* Navigation Controller */
-	if (vid == 0x054c && pid == 0x042f)
-		return true;
-
-	return false;
-}
-
 static void connect_event_cb(GIOChannel *chan, GError *err, gpointer data)
 {
 	uint16_t psm;
@@ -178,11 +99,6 @@ static void connect_event_cb(GIOChannel *chan, GError *err, gpointer data)
 	if (ret == 0)
 		return;
 
-	if (ret == -ENOENT && dev_is_sixaxis(&src, &dst)) {
-		sixaxis_browse_sdp(&src, &dst, chan, psm);
-		return;
-	}
-
 	error("Refusing input device connect: %s (%d)", strerror(-ret), -ret);
 
 	/* Send unplug virtual cable to unknown devices */
@@ -207,8 +123,7 @@ static void auth_callback(DBusError *derr, void *user_data)
 		goto reject;
 	}
 
-	if (!input_device_exists(&server->src, &confirm->dst) &&
-				!dev_is_sixaxis(&server->src, &confirm->dst))
+	if (!input_device_exists(&server->src, &confirm->dst))
 		return;
 
 	if (!bt_io_accept(confirm->io, connect_event_cb, server, NULL, &err)) {
@@ -259,7 +174,7 @@ static void confirm_event_cb(GIOChannel *chan, gpointer user_data)
 		goto drop;
 	}
 
-	if (!input_device_exists(&src, &dst) && !dev_is_sixaxis(&src, &dst)) {
+	if (!input_device_exists(&src, &dst)) {
 		error("Refusing connection from %s: unknown device", addr);
 		goto drop;
 	}
Signature · 1 line
2.1.4