From patchwork Mon Apr 21 11:12:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ludovico de Nittis X-Patchwork-Id: 883241 Received: from bali.collaboradmins.com (bali.collaboradmins.com [148.251.105.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 50CC429D0E for ; Mon, 21 Apr 2025 11:13:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.251.105.195 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745234023; cv=none; b=LpW1ZJc6Y7DrcVVDueS4x1Xaqwfb9Xeaeu7QjTmBlbAP1alM4NZ3NDTZya28dLxmHHbDgRsaKrqrt7awiMIgeqZ3ABcTmPcNS/LBpeGNtsnyQaDeLAEzV+V0GTz1fzfraw9yK+4rG64w4q/KnUSUj3ZKSHwu/HfYGnWDvuQGGVk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745234023; c=relaxed/simple; bh=Fi0MPczyk21pAUbypOskIDPslLKmxMIDpsqDKorEJpk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CYp9TWseek/T/UyU16kazOCBTN5aQmE7v5cxhNAuyfei6CM8nY6M4R46eexMz0OJwIzhsAHNu7wqm/w+jMpPcI+/A43a6noFC92XY9fTUPHEUUHl8CGN4J2R45gx4Wt42xFI5ZmORj5ZDhilteh8FVJ3vgdmR/FxXPN9Y48ax+k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=qW+tNbUl; arc=none smtp.client-ip=148.251.105.195 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="qW+tNbUl" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1745234019; bh=Fi0MPczyk21pAUbypOskIDPslLKmxMIDpsqDKorEJpk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qW+tNbUlmqGExULSxcZt9YcBzIigsKzkKIQN1g5MSdd0qzxDbX8V/wXSE40iggCBS usxz7cXu19SwrF8gadow+VU09mcKJPQioL7Spaqi2XzLOodqVOXV0Qt1QzGR1BzXxN K7E79X8PFQ2Nfqwbyu76sLBJYSli/sCe4YINU4jAPxOHG2txHrY2GmHKgZuxrgyPLS QERaTYqy67lS6VuDwPOd53QBgAw0dyANhTr3EiVtrIqYq94CIsiHMxv0V8jrsoa2An rFvmQT28WueZIP2Gqlna+hetMTH/OSihM/Ij4hi0iYtOZjBOZ9MquVN38cmAbE4DtG VcpN7/Zmc4tlQ== Received: from localhost.localdomain (unknown [81.56.51.115]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: denittis) by bali.collaboradmins.com (Postfix) with ESMTPSA id 54EE417E00FC; Mon, 21 Apr 2025 13:13:39 +0200 (CEST) From: Ludovico de Nittis To: linux-bluetooth@vger.kernel.org Cc: Ludovico de Nittis Subject: [PATCH BlueZ 1/5] src: Add new SixaxisCablePairing property Date: Mon, 21 Apr 2025 13:12:47 +0200 Message-ID: <20250421111251.108943-2-ludovico.denittis@collabora.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250421111251.108943-1-ludovico.denittis@collabora.com> References: <20250421111251.108943-1-ludovico.denittis@collabora.com> Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This adds initial support for a new SixaxisCablePairing property. The property can be used to set a device as being a "real" Sixaxis gamepad and then handle it differently when needed. --- doc/org.bluez.Device.rst | 6 ++++++ src/device.c | 44 ++++++++++++++++++++++++++++++++++++++++ src/device.h | 3 +++ 3 files changed, 53 insertions(+) diff --git a/doc/org.bluez.Device.rst b/doc/org.bluez.Device.rst index 13328249b..2d85d0dc2 100644 --- a/doc/org.bluez.Device.rst +++ b/doc/org.bluez.Device.rst @@ -279,6 +279,12 @@ boolean LegacyPairing [readonly] Bluetooth 2.1 (or newer) devices that have disabled Extended Inquiry Response support. +boolean SixaxisCablePairing [readonly] +`````````````````````````````````````` + + Set to true if the device was paired using the Sixaxis USB custom protocol. + If true, the device connection will happen without enforcing encryption. + string Modalias [readonly, optional] ```````````````````````````````````` diff --git a/src/device.c b/src/device.c index b82a905f9..b11b5c8e4 100644 --- a/src/device.c +++ b/src/device.c @@ -239,6 +239,7 @@ struct btd_device { GSList *watches; /* List of disconnect_data */ bool temporary; bool connectable; + bool sixaxis_cable_pairing; unsigned int disconn_timer; unsigned int discov_timer; unsigned int temporary_timer; /* Temporary/disappear timer */ @@ -507,6 +508,9 @@ static gboolean store_device_info_cb(gpointer user_data) g_key_file_set_boolean(key_file, "General", "Blocked", device->blocked); + g_key_file_set_boolean(key_file, "General", "SixaxisCablePairing", + device->sixaxis_cable_pairing); + if (device->wake_override != WAKE_FLAG_DEFAULT) { g_key_file_set_boolean(key_file, "General", "WakeAllowed", device->wake_override == @@ -908,6 +912,11 @@ bool btd_device_is_trusted(struct btd_device *device) return device->trusted; } +bool device_is_sixaxis_cable_pairing(struct btd_device *device) +{ + return device->sixaxis_cable_pairing; +} + static gboolean dev_property_get_address(const GDBusPropertyTable *property, DBusMessageIter *iter, void *data) { @@ -1153,6 +1162,17 @@ static gboolean dev_property_get_legacy(const GDBusPropertyTable *property, return TRUE; } +static gboolean dev_property_get_sixaxis_cable_pairing(const GDBusPropertyTable *property, + DBusMessageIter *iter, void *data) +{ + struct btd_device *device = data; + dbus_bool_t val = device->sixaxis_cable_pairing; + + dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &val); + + return TRUE; +} + static gboolean dev_property_get_rssi(const GDBusPropertyTable *property, DBusMessageIter *iter, void *data) { @@ -3483,6 +3503,7 @@ static const GDBusPropertyTable device_properties[] = { { "Trusted", "b", dev_property_get_trusted, dev_property_set_trusted }, { "Blocked", "b", dev_property_get_blocked, dev_property_set_blocked }, { "LegacyPairing", "b", dev_property_get_legacy }, + { "SixaxisCablePairing", "b", dev_property_get_sixaxis_cable_pairing }, { "RSSI", "n", dev_property_get_rssi, NULL, dev_property_exists_rssi }, { "Connected", "b", dev_property_get_connected }, { "UUIDs", "as", dev_property_get_uuids }, @@ -4062,6 +4083,9 @@ next: if (blocked) device_block(device, FALSE); + device->sixaxis_cable_pairing = g_key_file_get_boolean(key_file, "General", + "SixaxisCablePairing", NULL); + /* Load device profile list */ uuids = g_key_file_get_string_list(key_file, "General", "Services", NULL, NULL); @@ -4857,6 +4881,9 @@ void device_merge_duplicate(struct btd_device *dev, struct btd_device *dup) dev->trusted = dup->trusted; dev->blocked = dup->blocked; + /* Skip sixaxis_cable_pairing property because it doesn't support LE, so we + * never expect to have a duplicate device in that case */ + for (l = dup->uuids; l; l = g_slist_next(l)) dev->uuids = g_slist_append(dev->uuids, g_strdup(l->data)); @@ -6416,6 +6443,23 @@ void device_set_legacy(struct btd_device *device, bool legacy) DEVICE_INTERFACE, "LegacyPairing"); } +void device_set_sixaxis_cable_pairing(struct btd_device *device, + gboolean sixaxis_cable_pairing) +{ + if (!device) + return; + + if (device->sixaxis_cable_pairing == sixaxis_cable_pairing) + return; + + DBG("setting sixaxis cable pairing %d", sixaxis_cable_pairing); + + device->sixaxis_cable_pairing = sixaxis_cable_pairing; + + g_dbus_emit_property_changed(dbus_conn, device->path, + DEVICE_INTERFACE, "SixaxisCablePairing"); +} + void device_store_svc_chng_ccc(struct btd_device *device, uint8_t bdaddr_type, uint16_t value) { diff --git a/src/device.h b/src/device.h index 2e4a9771d..c0fa6ec3a 100644 --- a/src/device.h +++ b/src/device.h @@ -94,6 +94,7 @@ bool device_is_connectable(struct btd_device *device); bool device_is_paired(struct btd_device *device, uint8_t bdaddr_type); bool device_is_bonded(struct btd_device *device, uint8_t bdaddr_type); bool btd_device_is_trusted(struct btd_device *device); +bool device_is_sixaxis_cable_pairing(struct btd_device *device); void device_set_paired(struct btd_device *dev, uint8_t bdaddr_type); void device_set_unpaired(struct btd_device *dev, uint8_t bdaddr_type); void btd_device_set_temporary(struct btd_device *device, bool temporary); @@ -101,6 +102,8 @@ void btd_device_set_trusted(struct btd_device *device, gboolean trusted); void btd_device_set_connectable(struct btd_device *device, bool connectable); void device_set_bonded(struct btd_device *device, uint8_t bdaddr_type); void device_set_legacy(struct btd_device *device, bool legacy); +void device_set_sixaxis_cable_pairing(struct btd_device *device, + gboolean sixaxis_cable_pairing); void device_set_rssi_with_delta(struct btd_device *device, int8_t rssi, int8_t delta_threshold); void device_set_rssi(struct btd_device *device, int8_t rssi); From patchwork Mon Apr 21 11:12:48 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ludovico de Nittis X-Patchwork-Id: 882889 Received: from bali.collaboradmins.com (bali.collaboradmins.com [148.251.105.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1735D263899 for ; Mon, 21 Apr 2025 11:13:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.251.105.195 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745234027; cv=none; b=lRKjU7WaMkhbSxEvSYqldr6kqnAuEfTheJXkSBWG9PnK3AlqmefACkNl/nlz3A4QqXAiIw2+IEKpF+veTVQzQfo9i9gYHBEcH0lalnWg1AxTn/pw7h2ZcfFKuh82QtK4K2YN3a7QV6tt8E7LYVp1PIVvhZvw46Hf2zI9yMv0ljk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745234027; c=relaxed/simple; bh=rEkISNblRcWOJgNCgm1vnNuXQKQ0gFUjSn8dHoaP1MI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=O0Hwx5+K0WEd58hx0ztayzN8YWxvdgCRGXBtav9m76JGFNNTFfezAWhHtN+kSq71HQg7+SsvRBjdmwF2B80/9UdhncEbXs1egQJfSfSVQMMRXBoh9oT+yOonHhUqoGgUFmJIHRgKoqokJI7mtbxkXO5mdt5ld1JMTZtf6nh0QYk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=Y2kaZ9hZ; arc=none smtp.client-ip=148.251.105.195 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="Y2kaZ9hZ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1745234023; bh=rEkISNblRcWOJgNCgm1vnNuXQKQ0gFUjSn8dHoaP1MI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y2kaZ9hZ3lPXBc8wU0q5rbGqftlmhI+/xNgao7WQj9XqIxeEIZK9gWykS0hldBnj5 u0GXBh+uDwkGqwoeW1qXIAI4YhXdI1XTqqQPBkDwe2+6ItUyFobMVRunBehtgZ24LT mTuzkkpACQv/KOg0mny9U4hcuoUTTMCVLOLXN9OMY/VEPYk01VdyBultnj5yPvBlYY iOZLUINwWVk0veaQQmXPL+UDGwhPGRBVDn800dOUeyNPjOhkEpbkoePiIB1zL6YUz0 cyhd9S7rx27MvZg0u4mA6GzkgURxYkUhsRtTD1E51787BOa2vef08yJ3Y4qP03Szsp 0z84D0D7iJpNQ== Received: from localhost.localdomain (unknown [81.56.51.115]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: denittis) by bali.collaboradmins.com (Postfix) with ESMTPSA id DE68217E0649; Mon, 21 Apr 2025 13:13:42 +0200 (CEST) From: Ludovico de Nittis To: linux-bluetooth@vger.kernel.org Cc: Ludovico de Nittis Subject: [PATCH BlueZ 2/5] client: Print SixaxisCablePairing value if BlueZ was compiled with sixaxis Date: Mon, 21 Apr 2025 13:12:48 +0200 Message-ID: <20250421111251.108943-3-ludovico.denittis@collabora.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250421111251.108943-1-ludovico.denittis@collabora.com> References: <20250421111251.108943-1-ludovico.denittis@collabora.com> Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 If BlueZ was compiled with sixaxis support enabled, print in output the property value of SixaxisCablePairing when using `bluetoothctl info`. --- client/main.c | 3 +++ configure.ac | 3 +++ 2 files changed, 6 insertions(+) diff --git a/client/main.c b/client/main.c index 6039aa50c..bda8983e4 100644 --- a/client/main.c +++ b/client/main.c @@ -1705,6 +1705,9 @@ static void cmd_info(int argc, char *argv[]) print_property(proxy, "Connected"); print_property(proxy, "WakeAllowed"); print_property(proxy, "LegacyPairing"); +#ifdef HAVE_SIXAXIS + print_property(proxy, "SixaxisCablePairing"); +#endif print_uuids(proxy); print_property(proxy, "Modalias"); print_property(proxy, "ManufacturerData"); diff --git a/configure.ac b/configure.ac index 1e089aaa7..ec509c97e 100644 --- a/configure.ac +++ b/configure.ac @@ -420,6 +420,9 @@ AC_ARG_ENABLE(sixaxis, AS_HELP_STRING([--enable-sixaxis], [enable sixaxis plugin]), [enable_sixaxis=${enableval}]) AM_CONDITIONAL(SIXAXIS, test "${enable_sixaxis}" = "yes" && test "${enable_udev}" != "no") +if (test "${enable_sixaxis}" = "yes" && test "${enable_udev}" != "no"); then + AC_DEFINE(HAVE_SIXAXIS, 1, [Define to 1 if sixaxis plugin is enabled]) +fi AC_ARG_ENABLE(hid2hci, AS_HELP_STRING([--enable-hid2hci], [enable hid2hci tool]), [enable_hid2hci=${enableval}]) From patchwork Mon Apr 21 11:12:49 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ludovico de Nittis X-Patchwork-Id: 883240 Received: from bali.collaboradmins.com (bali.collaboradmins.com [148.251.105.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1B790261370 for ; Mon, 21 Apr 2025 11:13:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.251.105.195 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745234029; cv=none; b=Z9ciySUhTWSWM3RHsojag1ODefMtaCp1mF+fhFBzWVZtCOBh71r84co9RnnA95lyQZ5Gv7FTFFjb7DTMh7b7k0VJ4kSEmGIQO86aTrsTFruYmq2zBm6BiAv2t5WCzH9U3oMojlJzBdWc8jSxXA/5j6y5DOTqoqCkW/WoAw5gB1o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745234029; c=relaxed/simple; bh=2pe6XjjC0mhZG7nI/GV4gZgYITk5arIObQn1QvX8Yng=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=i5t1v5be6UhE0YQuJoVRflVLoJOvgMYGFWTUfdmzeyVRTJgmSGZ0U493PHREFtzhEMuBFUvYTEvg9zTxbCaTgG5KZLn/aDsV6zt51Efip/YKySsMVy3ubtZddwu+JJINzJWY3kNKMWsD+sJ9bbBTWBnfjxJZA3OCixYCX5A1lU4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=mKG9X8lx; arc=none smtp.client-ip=148.251.105.195 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="mKG9X8lx" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1745234025; bh=2pe6XjjC0mhZG7nI/GV4gZgYITk5arIObQn1QvX8Yng=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mKG9X8lxYCqArB6r9u3xoL8HFMC59B1Rq7N/T+POU6XDaLIh0BNFC0MIBLMe5H3PD SvJaZWbqB5T4DDi6cfy9fT1fYUJq536/VJF6GDJe4RfdF8aefsNAqW6GSvV1h+nI8w OEfTxcmt+obFKxHda8gL8Ad/bopBlsdqN9C9aJlN7illWCE7QVu2A10fENr4OP38zr +fLpOBnpwazWVIbmmt44ksChoWUYP7E6vmyNiDsIwk/BHOn9ux4fTmKqoJrKwx1LPP 0di7usL6fb+WN84/34kTuRjJWYTlNX+w7PJNxy75T1nl6u+6dhC2VO1CX5fBTGHSLL sV4yA4s5LJNaw== Received: from localhost.localdomain (unknown [81.56.51.115]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: denittis) by bali.collaboradmins.com (Postfix) with ESMTPSA id E6E0D17E00FC; Mon, 21 Apr 2025 13:13:44 +0200 (CEST) From: Ludovico de Nittis To: linux-bluetooth@vger.kernel.org Cc: Ludovico de Nittis Subject: [PATCH BlueZ 3/5] plugins: Set SixaxisCablePairing property when pairing a sixaxis with USB Date: Mon, 21 Apr 2025 13:12:49 +0200 Message-ID: <20250421111251.108943-4-ludovico.denittis@collabora.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250421111251.108943-1-ludovico.denittis@collabora.com> References: <20250421111251.108943-1-ludovico.denittis@collabora.com> Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 If we are pairing a Sixaxis device using a USB cable, we set the SixaxisCablePairing property to flag that event. --- plugins/sixaxis.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/sixaxis.c b/plugins/sixaxis.c index 3e69f1dd2..84dd3891b 100644 --- a/plugins/sixaxis.c +++ b/plugins/sixaxis.c @@ -296,10 +296,13 @@ static void agent_auth_cb(DBusError *derr, void *user_data) remove_device = false; btd_device_set_temporary(closure->device, false); - if (closure->type == CABLE_PAIRING_SIXAXIS) + if (closure->type == CABLE_PAIRING_SIXAXIS) { btd_device_set_record(closure->device, HID_UUID, SIXAXIS_HID_SDP_RECORD); + device_set_sixaxis_cable_pairing(closure->device, true); + } + ba2str(&closure->bdaddr, device_addr); ba2str(¢ral_bdaddr, central_addr); ba2str(adapter_bdaddr, adapter_addr); From patchwork Mon Apr 21 11:12:50 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ludovico de Nittis X-Patchwork-Id: 882888 Received: from bali.collaboradmins.com (bali.collaboradmins.com [148.251.105.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 423BF2627E2 for ; Mon, 21 Apr 2025 11:13:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.251.105.195 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745234031; cv=none; b=ZUxU8n9Lc/FhitCzZQYG9V3BN433QgcmR/9nnOUadCAJMQAGwbs43kvd86VDPX26RlPVun6/S6E1V/Er7bzY9TVhwGA96uWUjFMWdK04To32UQXIwaI84L/wJdUQN49hFC/Fc0foHYeseYYDpNQ5Vh2wJNEaoLrL4qeudsJnlgQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745234031; c=relaxed/simple; bh=uyiaTkqyRA79UvhhJaU5tQNx2Ty//3tdGJyAtJFejAc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dsJnUs28CZpjTOfBj4RvB8/KNUnLgiVMaTpD6RBMAzcaj7+fawOpkWYd9VD3QvynqqSuyl0yTuBGGjwFFAX9NRyQh8YZ2rHLe9YxcaDYncKapUKYgxFHZlg+YQwLM15uEISxh3fb3zMkPl7Kv0zsTvoLpcOBNIrkSmwIs3Dhpzs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=U2X30y4V; arc=none smtp.client-ip=148.251.105.195 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="U2X30y4V" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1745234027; bh=uyiaTkqyRA79UvhhJaU5tQNx2Ty//3tdGJyAtJFejAc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U2X30y4Vr7a1DQWVEbcsNWvADcNEwKe9K6rDrTeoxM6u+9H/LUCMF6oAeQfBzSCDZ g7wox0gZ6/lBOhFugOhTiXqL5Lr2BtuUXVwUYWLcKnH/RY8DW7m2nlyne2c9AWzMUG g/JaF66tt2yTbblYqDbI/Jof5AYvm96dN4kFUuXWcv7YVZeeTYPjsu9mR2rYxeJkAy PPR+F6eLNwWvp8PZS7oOpGHqlmO828CeGDs9d+Np/Y4Gqr82eXbdFeLkZF2l4BGbpP +PdRbwB+pgBmPf7TSc3MOqKiELib1w1LvNIRsgwMpmdp9kvc8WrZdSyrO093F5lHQ/ NsJc9T+RevNxQ== Received: from localhost.localdomain (unknown [81.56.51.115]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: denittis) by bali.collaboradmins.com (Postfix) with ESMTPSA id 3EDB817E09B5; Mon, 21 Apr 2025 13:13:47 +0200 (CEST) From: Ludovico de Nittis To: linux-bluetooth@vger.kernel.org Cc: Ludovico de Nittis Subject: [PATCH BlueZ 4/5] input: Start the server with sec low and bump it when making the connection Date: Mon, 21 Apr 2025 13:12:50 +0200 Message-ID: <20250421111251.108943-5-ludovico.denittis@collabora.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250421111251.108943-1-ludovico.denittis@collabora.com> References: <20250421111251.108943-1-ludovico.denittis@collabora.com> Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 BT_IO_SEC_LOW is the only way to allow Sixaxis devices to establish a connection. When BlueZ has been compiled with Sixaxis support enabled, we start the listening input server with BT_IO_SEC_LOW to avoid breaking the Sixaxis support. Then, in `hidp_add_connection()`, we check if either `classic_bonded_only` was disabled or if this device is a Sixaxis. If neither are true, we bump the security back to BT_IO_SEC_MEDIUM, i.e. enforcing encryption. This allows supporting the Sixaxis gamepad without having to change the classic bonded only option. --- profiles/input/device.c | 6 ++++-- profiles/input/server.c | 7 +++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/profiles/input/device.c b/profiles/input/device.c index 3627573e7..eb2fb5c8e 100644 --- a/profiles/input/device.c +++ b/profiles/input/device.c @@ -1088,8 +1088,10 @@ static int hidp_add_connection(struct input_device *idev) if (device_name_known(idev->device)) device_get_name(idev->device, req->name, sizeof(req->name)); + sixaxis_cable_pairing = device_is_sixaxis_cable_pairing(idev->device); + /* Make sure the device is bonded if required */ - if (classic_bonded_only && !input_device_bonded(idev)) { + if (classic_bonded_only && !sixaxis_cable_pairing && !input_device_bonded(idev)) { error("Rejected connection from !bonded device %s", idev->path); goto cleanup; } @@ -1098,7 +1100,7 @@ static int hidp_add_connection(struct input_device *idev) /* Some platforms may choose to require encryption for all devices */ /* Note that this only matters for pre 2.1 devices as otherwise the */ /* device is encrypted by default by the lower layers */ - if (classic_bonded_only || idev->type == BT_UHID_KEYBOARD) { + if (!sixaxis_cable_pairing && (classic_bonded_only || idev->type == BT_UHID_KEYBOARD)) { if (!bt_io_set(idev->intr_io, &gerr, BT_IO_OPT_SEC_LEVEL, BT_IO_SEC_MEDIUM, BT_IO_OPT_INVALID)) { diff --git a/profiles/input/server.c b/profiles/input/server.c index 79cf08a66..73caeb076 100644 --- a/profiles/input/server.c +++ b/profiles/input/server.c @@ -273,6 +273,13 @@ int server_start(const bdaddr_t *src) BtIOSecLevel sec_level = input_get_classic_bonded_only() ? BT_IO_SEC_MEDIUM : BT_IO_SEC_LOW; +#ifdef HAVE_SIXAXIS + /* Lower security to allow the Sixaxis gamepad to connect. */ + /* Unless classic bonded only mode is disabled, the security level */ + /* will be bumped again for non sixaxis devices in hidp_add_connection() */ + sec_level = BT_IO_SEC_LOW; +#endif + server = g_new0(struct input_server, 1); bacpy(&server->src, src); From patchwork Mon Apr 21 11:12:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ludovico de Nittis X-Patchwork-Id: 883239 Received: from bali.collaboradmins.com (bali.collaboradmins.com [148.251.105.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8251B2627E2 for ; Mon, 21 Apr 2025 11:13:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.251.105.195 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745234034; cv=none; b=mfxi5kPTyUd/mVWbSrtfqo9G5m1648FgqgrqIJP72LeC+IJMvDAXyB1RIlTscFOZdPOjhxZxGSiS8hwhTPfmchjMmDVMs2JsHxFy4LFA24b6MtHcxlxMuGY9xgfT2Zvp2EqMghtTjG5jyZ01aNInzQTm9LFJKJDYQrZZDwPXawU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745234034; c=relaxed/simple; bh=s/fBpRKRwdp0GU83TvjtnYPZz7NKUhBHuYwO995Vffo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=G652xG2Z8v8+w4FIDPC2w7RMUKGjvahZXi39WXrKNQ/IChp1RsqM1FkwXrtC84wFsXDq2RZAhU5lEsR332gS++inpd4PJn+PhG37IWqIHWkSOwkNXsYgDhQYBTCypeb8EhUrEPz7ycbvZapQDh7U66S0sc3otnXKgEWxz7ljYwk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=SuAHx38n; arc=none smtp.client-ip=148.251.105.195 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="SuAHx38n" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1745234030; bh=s/fBpRKRwdp0GU83TvjtnYPZz7NKUhBHuYwO995Vffo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SuAHx38nuYzm9idj8yBB3VX9+fVjwpPEUa4bfzBwQVTTPVJlCJ2AsvPI8QckkE6WR TO9Hu/IKeG+AEYJTEGABu+U/+oxlFZQG7vxeseb2B/jPItDXMo6OmOLp1/hdfZzEhM Wl2kwVntSBBEuL2wNQcR8krKYKIaMpqVlT+5MZefrWqivFCZ6Z0vHl7SwNjRfgNmvi TS8NsJ94atHEahKFe9vZxzIrILLz4eZAxhx2xSlqvVqSdYPDP1F9O+uNHONU5Y3BjE 9RGwS9ukgE6gUtNx03EE3yPszTtFP9yTGPpoVhgUgvWakNpw3Ad/3qIe8yfoFF+QR9 sWwNuVFy5plkw== Received: from localhost.localdomain (unknown [81.56.51.115]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: denittis) by bali.collaboradmins.com (Postfix) with ESMTPSA id 61F3717E00FC; Mon, 21 Apr 2025 13:13:50 +0200 (CEST) From: Ludovico de Nittis To: linux-bluetooth@vger.kernel.org Cc: Ludovico de Nittis Subject: [PATCH BlueZ 5/5] input: Validate the Sixaxis HID report descriptor Date: Mon, 21 Apr 2025 13:12:51 +0200 Message-ID: <20250421111251.108943-6-ludovico.denittis@collabora.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250421111251.108943-1-ludovico.denittis@collabora.com> References: <20250421111251.108943-1-ludovico.denittis@collabora.com> Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Given that the Sixaxis devices can't work with encryption, i.e. they only work with BT_IO_SEC_LOW, this makes it harder to notice if the device we are talking to is the expected Sixaxis gamepad or an impostor. To reduce the possible attack surface, we ensure that the report descriptor that the device provided resembles what a real Sixaxis gamepad should have. E.g. it should only have Usages for `Joystick`, `Pointer` etc... and nothing unexpected like `Keyboard`. --- profiles/input/device.c | 71 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/profiles/input/device.c b/profiles/input/device.c index eb2fb5c8e..2297eb4ff 100644 --- a/profiles/input/device.c +++ b/profiles/input/device.c @@ -1062,9 +1062,72 @@ static gboolean encrypt_notify(GIOChannel *io, GIOCondition condition, return FALSE; } +static bool validate_sixaxis_rd_data(const uint8_t *rd_data, uint16_t rd_size) +{ + uint16_t i; + size_t data_size = 0; + + for (i = 0; i < rd_size; i += 1 + data_size) { + uint8_t b = rd_data[i]; + + /* Long items are reserved for future use, HID 1.11 Section 6.2.2.3 */ + if (b == 0xFE) { + DBG("The sixaxis HID report descriptor has an unexpected long item"); + return false; + } + + /* Extract data following the HID 1.11 Section 6.2.2.2 */ + uint8_t bSize = b & 0x03; + uint8_t bType = (b >> 2) & 0x03; + uint8_t bTag = (b >> 4) & 0x0F; + data_size = bSize == 3 ? 4 : bSize; + + if ((i + 1 + data_size) > rd_size) + break; + + const uint8_t *data = &rd_data[i + 1]; + + if (bType == 1 && bTag == 0x0 && data_size >= 1) { + /* Usage Page (Generic Desktop) */ + if (data_size == 1 && data[0] == 0x01) + continue; + + /* Usage Page (Button) */ + if (data_size == 1 && data[0] == 0x09) + continue; + + /* Usage Page (Vendor Defined Page 1) */ + if (data_size == 2 && data[0] == 0x00 && data[1] == 0xFF) + continue; + + DBG("The sixaxis HID report descriptor has an unexpected Usage Page: 0x%02X", data[0]); + return false; + } + + if (bType == 2 && bTag == 0x0 && data_size >= 1) { + /* Usage (Joystick) */ + if (data_size == 1 && data[0] == 0x04) + continue; + + /* Usage (Pointer) */ + if (data_size == 1 && data[0] == 0x01) + continue; + + /* Axis usages, e.g. Usage (X) */ + if (data_size == 1 && data[0] >= 0x30 && data[0] <= 0x35) + continue; + + DBG("The sixaxis HID report descriptor has an unexpected Usage: 0x%02X", data[0]); + return false; + } + } + return true; +} + static int hidp_add_connection(struct input_device *idev) { struct hidp_connadd_req *req; + bool sixaxis_cable_pairing; GError *gerr = NULL; int err; @@ -1090,6 +1153,14 @@ static int hidp_add_connection(struct input_device *idev) sixaxis_cable_pairing = device_is_sixaxis_cable_pairing(idev->device); + /* The Sixaxis devices must use the security level BT_IO_SEC_LOW to work. */ + /* We reduce the attach surface by ensuring that the report descriptor only */ + /* contains the expected Usages that a real Sixaxis gamepad has */ + if (sixaxis_cable_pairing && !validate_sixaxis_rd_data(req->rd_data, req->rd_size)) { + error("The sixaxis HID SDP record has unexpected entries, rejecting the connection to %s", idev->path); + goto cleanup; + } + /* Make sure the device is bonded if required */ if (classic_bonded_only && !sixaxis_cable_pairing && !input_device_bonded(idev)) { error("Rejected connection from !bonded device %s", idev->path);