From patchwork Mon Oct 2 23:13:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 731139 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 58781E776CB for ; Mon, 2 Oct 2023 23:13:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229675AbjJBXNS (ORCPT ); Mon, 2 Oct 2023 19:13:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229954AbjJBXNR (ORCPT ); Mon, 2 Oct 2023 19:13:17 -0400 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75841BD for ; Mon, 2 Oct 2023 16:13:14 -0700 (PDT) Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1c3cbfa40d6so2502215ad.1 for ; Mon, 02 Oct 2023 16:13:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696288393; x=1696893193; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=JpYutWjFqZxEpDs2kxc762rU/OhATu8xckFRLTT1LHU=; b=d1PTaSIA2LWLFKcIEUcFDkyx+0FFN/HruxD9UVVO18rSl8atD5OoOpYI3XU6Ectog2 wWeaqbzNtwsdPZNivEgf67yBGFn1KxtZ1TFQN3euFMwSfA4q3LKFeNK2Df52vCqrroR4 u5c/4KhPyux/Jo2f1ZOP+BHChNBo94f2QghHY9julxIFo71w7ZE7Cip9QrRxRt7ujuJC GKVAG9dD99f0FKFhjZg1i+a+jz2dDL7HzZoqGmICTHLPcRqGXeoB6kyWtj6wuxSU+JmK MM+WAflsv1PtPFpq4na7M7QEQ2Yme1yWjTvKFSzSzKxtlTER5SJex1lIRdIZRJkR6usv w2hA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696288393; x=1696893193; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=JpYutWjFqZxEpDs2kxc762rU/OhATu8xckFRLTT1LHU=; b=GtBdUz9x3tka+Vy9MynBC2iJlfg8PcZbwm4ykPJ5D4tnpz4a3SVwh5fZkRhbu4yodh LZzKzIARij+dzUOuusxJLJAi0cRVZYPrfRR2c4VWF3/QWeGDHHUR1leeq3acbYWdGrFk NGWOoF5djuMa7eC6t4cmDsYxY1TRdU5YQ+Tsx1C8sD1lJuGNLDnN/BCLSt1PpLylo1py pxjC8JC42bD0Ku31cvOJ8Bqc9SgPULf1LRLY99BBE1Acq/YcfNVnafWEjgIHLNPuO692 6oZPODE3PxkQGv/qo65y67J7hTGKWnxfdZN1PjD98A7bDcQf3+/Iir8VbJSlbBmiglFS u79w== X-Gm-Message-State: AOJu0YyamdJDFx1Q++pDcMQz1pySPUu23qcAHtkb9FjcLpKN0Ua6DW2y iA9PSWBgDS+DO0ntZcewpyHwip5T2O9c8V3P X-Google-Smtp-Source: AGHT+IHKlxnJNi4SSWiFSM88Bj2yslU9i314qDIe101tUiMlsmZrUvdSlRbZdUjbF1jRpFaWPrt8mw== X-Received: by 2002:a17:902:c948:b0:1c4:4c73:94e6 with SMTP id i8-20020a170902c94800b001c44c7394e6mr15291306pla.51.1696288392950; Mon, 02 Oct 2023 16:13:12 -0700 (PDT) Received: from lvondent-mobl4.. (c-98-232-221-87.hsd1.or.comcast.net. [98.232.221.87]) by smtp.gmail.com with ESMTPSA id l11-20020a170902d34b00b001c75627545csm5181817plk.135.2023.10.02.16.13.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 16:13:12 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 1/6] shared/csip: Fix returning invalid data to attribute Size reads Date: Mon, 2 Oct 2023 16:13:05 -0700 Message-ID: <20231002231311.3104749-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz The attribute Size value is stored in the size_val not on size member which represents the attribute object. --- src/shared/csip.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/shared/csip.c b/src/shared/csip.c index 04a8d542b390..24d5d6a323bd 100644 --- a/src/shared/csip.c +++ b/src/shared/csip.c @@ -291,8 +291,8 @@ static void csis_size_read(struct gatt_db_attribute *attrib, struct bt_csis *csis = user_data; struct iovec iov; - iov.iov_base = &csis->size; - iov.iov_len = sizeof(csis->size); + iov.iov_base = &csis->size_val; + iov.iov_len = sizeof(csis->size_val); gatt_db_attribute_read_result(attrib, id, 0, iov.iov_base, iov.iov_len); From patchwork Mon Oct 2 23:13:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 728599 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D0BA9E776CB for ; Mon, 2 Oct 2023 23:13:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237160AbjJBXNU (ORCPT ); Mon, 2 Oct 2023 19:13:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237224AbjJBXNT (ORCPT ); Mon, 2 Oct 2023 19:13:19 -0400 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2691DB7 for ; Mon, 2 Oct 2023 16:13:16 -0700 (PDT) Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1c60cec8041so2312115ad.3 for ; Mon, 02 Oct 2023 16:13:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696288395; x=1696893195; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=9aaaqJ139poo/qtsU22+bWZZ765/12Sgyv2nlisoT+0=; b=Fr/BsEVBpa3lRzYIBb7fDr/IcFzDfFG5BzOFj+29X5G7LQe5KLf7O/id4vhl3L2rmo EZmA+Tg53CYdXBVFc99jCi22q8rQnipcbncoopbQBpRbhv8tFygiOulEu/RcELXviBSF KOdnjY/t0Z5XfhRuiyCM34ommUcCM19qnZt8y4xjM8xbXas4GejnVdN5qVL0MQvtyl/t WzTdElcp1sOWiZhRndYsUdzRioHGI+14Lta+h6UJr/Jmlnn/wFF/BdEztQ0l+ZV6ij60 jQTRC3TJnXyGpFldoVpEDNpl9a8ItCO/9Fd2cbVJJ7SR5baPZ+6JHIpl1AZCv3dcWSAt yngw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696288395; x=1696893195; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9aaaqJ139poo/qtsU22+bWZZ765/12Sgyv2nlisoT+0=; b=D5Y6rd74Od/lcCC4iApQR6yoah6JCadwFVoRjbfLrXFdhH+7tToZNMCWlvlEUaDod9 L+NhFbD1uakt0+o0mBwDx5zBIRkIfLGtNsFcUODOj3rVdSRkbjFIdzOkzPT8imzK6yGF XAadi3Vxn/2CqqQaLQz7FFWdyluB3IO6iTKQsbK6ZWZD6J6PM+obc/S15mDk9ZfBGzTi 0JfT/R/LvkVCK3cu7O6F+/6kIMWcOU1Q8yWG0zLeLoelbB61nBnw0EAU9bKnM1XKhX2O Ih0toF6Vx9sAd4E1vJwzLHD6fgSxVxjsQZy6Z8iBhoLajXulrcZfyR0N1hzMMrUPBw1D nszA== X-Gm-Message-State: AOJu0YxGoXGUdLfBaJvQyb086iULLbuNwKzw+p6IenxcQDPWSQiTwoO1 v87SEWl5R5X+jtny1m7gfMAdSYPZzWHlgwKs X-Google-Smtp-Source: AGHT+IH2FdEdNVnbQ02u54alY3YTG+/p+ZNK6Zz5BQlSBflyAQP5DO7W0OVAKLyBO4VpKqasdoQeqw== X-Received: by 2002:a17:903:41c1:b0:1c7:37e2:13fe with SMTP id u1-20020a17090341c100b001c737e213femr13314758ple.2.1696288394802; Mon, 02 Oct 2023 16:13:14 -0700 (PDT) Received: from lvondent-mobl4.. (c-98-232-221-87.hsd1.or.comcast.net. [98.232.221.87]) by smtp.gmail.com with ESMTPSA id l11-20020a170902d34b00b001c75627545csm5181817plk.135.2023.10.02.16.13.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 16:13:13 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 2/6] shared/csip: Fix not requiring encryption Date: Mon, 2 Oct 2023 16:13:06 -0700 Message-ID: <20231002231311.3104749-2-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231002231311.3104749-1-luiz.dentz@gmail.com> References: <20231002231311.3104749-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz According to CSIS spec all attributes shall require encryption: 'Table 5.1: Coordinated Set Identification Service characteristics' --- src/shared/csip.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/shared/csip.c b/src/shared/csip.c index 24d5d6a323bd..eb80bbc3b26c 100644 --- a/src/shared/csip.c +++ b/src/shared/csip.c @@ -721,7 +721,8 @@ static struct csis_sirk *sirk_new(struct bt_csis *csis, struct gatt_db *db, bt_uuid16_create(&uuid, CS_SIRK); csis->sirk = gatt_db_service_add_characteristic(csis->service, &uuid, - BT_ATT_PERM_READ, + BT_ATT_PERM_READ | + BT_ATT_PERM_READ_ENCRYPT, BT_GATT_CHRC_PROP_READ, csis_sirk_read, NULL, csis); @@ -729,7 +730,8 @@ static struct csis_sirk *sirk_new(struct bt_csis *csis, struct gatt_db *db, bt_uuid16_create(&uuid, CS_SIZE); csis->size = gatt_db_service_add_characteristic(csis->service, &uuid, - BT_ATT_PERM_READ, + BT_ATT_PERM_READ | + BT_ATT_PERM_READ_ENCRYPT, BT_GATT_CHRC_PROP_READ, csis_size_read, NULL, csis); @@ -737,7 +739,10 @@ static struct csis_sirk *sirk_new(struct bt_csis *csis, struct gatt_db *db, /* Lock */ bt_uuid16_create(&uuid, CS_LOCK); csis->lock = gatt_db_service_add_characteristic(csis->service, &uuid, - BT_ATT_PERM_READ, + BT_ATT_PERM_READ | + BT_ATT_PERM_READ_ENCRYPT | + BT_ATT_PERM_WRITE | + BT_ATT_PERM_WRITE_ENCRYPT, BT_GATT_CHRC_PROP_READ | BT_GATT_CHRC_PROP_WRITE | BT_GATT_CHRC_PROP_NOTIFY, @@ -751,7 +756,8 @@ static struct csis_sirk *sirk_new(struct bt_csis *csis, struct gatt_db *db, /* Rank */ bt_uuid16_create(&uuid, CS_RANK); csis->rank = gatt_db_service_add_characteristic(csis->service, &uuid, - BT_ATT_PERM_READ, + BT_ATT_PERM_READ | + BT_ATT_PERM_READ_ENCRYPT, BT_GATT_CHRC_PROP_READ, csis_rank_read_cb, NULL, csis); From patchwork Mon Oct 2 23:13:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 731138 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E2A23E776D4 for ; Mon, 2 Oct 2023 23:13:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236552AbjJBXNV (ORCPT ); Mon, 2 Oct 2023 19:13:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237155AbjJBXNU (ORCPT ); Mon, 2 Oct 2023 19:13:20 -0400 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B646AC for ; Mon, 2 Oct 2023 16:13:18 -0700 (PDT) Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1c5db4925f9so1955415ad.1 for ; Mon, 02 Oct 2023 16:13:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696288397; x=1696893197; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=kXfx1LMcF2ZoyM6EdfEh52gSmxJjZ/+b1hClxDBVCaM=; b=QhYiUB+xyQ0Szk6Aw0mnaf10msNzj2RMNGNmEtNi4bWBTRiVlr9bG9/nZd50mjclx8 B1QH3IGSCKXlL9xtPVA8n8RCw8j6NfjT6P5xzgpxt8VqwPniFZLFCFPyLN7Q/DbDH9Ie yGQN5H6Jrh/vSjS6frRHEax9YYeGpf2sFkCPH3eFDYdvi7ChXmdCOntSwtfB1Z7iv4Wp 6gA/T+b0yy03NrX/KO6amo+b/ZiVPMIitpaRzH3xbiDnlIKvf4CMyRUPhMUop4gva5PL yddcQdnTnffCa3arJZOuTsxw8QUdaw2UbhNqvmAHk/K0IdgvyJMA+M1L6j3uxndfZfy+ gwmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696288397; x=1696893197; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kXfx1LMcF2ZoyM6EdfEh52gSmxJjZ/+b1hClxDBVCaM=; b=Lkbw/nBcLvvPhwGZG6lOnALWZ2MgIuSSf8Aob6ewJxt0qCLzwCtVQHbiogqcFOAJ0I VSrVWTXrOSyXksHKI0TMorNBpaw5kKBAnDY4dkvJ/7uF4wwCl4ilKSmHHYCRUYdpqmWr FjZljMzo52aHJ7oNHq0dvgzAG4nqXvZSfMUoD8TeyRw1zwpDoMb2dT+xQpH1vGiOlQRd sy0hmWInB8N+1skNST9wkxQgkEj4etquQ9oEbsxwsHf/u9j8JLEL4BdFOhwsYyc31DPB 270b0jM9m5xEXzmNZUmEP8Ss0v+DrbU4mxrmatMevzgPwdXbhzjtcEWPxSPIEQDrD5f8 XZiA== X-Gm-Message-State: AOJu0Yzrly9RUm45ohv7Qh97FoAwCQBnYsBC/8vuRfCtdQUHIFFJpPRo /qs4qjxL+ri9BtgfzJgsRuI4Md1di4N43b+J X-Google-Smtp-Source: AGHT+IGf0jikbCpGXJFNofhKsj0CWsja8DZeb53t2YwB6r5Yns7ayiX5x9AJWCijKUnRaypOZ+CflQ== X-Received: by 2002:a17:903:18e:b0:1c6:de7:add9 with SMTP id z14-20020a170903018e00b001c60de7add9mr1424616plg.19.1696288396642; Mon, 02 Oct 2023 16:13:16 -0700 (PDT) Received: from lvondent-mobl4.. (c-98-232-221-87.hsd1.or.comcast.net. [98.232.221.87]) by smtp.gmail.com with ESMTPSA id l11-20020a170902d34b00b001c75627545csm5181817plk.135.2023.10.02.16.13.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 16:13:15 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 3/6] shared/csip: Fix not always reading SIRK value Date: Mon, 2 Oct 2023 16:13:07 -0700 Message-ID: <20231002231311.3104749-3-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231002231311.3104749-1-luiz.dentz@gmail.com> References: <20231002231311.3104749-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This makes sure the SIRK value is always read otherwise its value can be outdated or not even read if the connection was interrupted before read procedure was completed. --- src/shared/csip.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shared/csip.c b/src/shared/csip.c index eb80bbc3b26c..85de63ea626b 100644 --- a/src/shared/csip.c +++ b/src/shared/csip.c @@ -597,7 +597,7 @@ static void foreach_csis_char(struct gatt_db_attribute *attr, void *user_data) DBG(csip, "SIRK found: handle 0x%04x", value_handle); csis = csip_get_csis(csip); - if (!csis || csis->sirk) + if (!csis) return; csis->sirk = attr; From patchwork Mon Oct 2 23:13:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 728598 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CACBDE776D1 for ; Mon, 2 Oct 2023 23:13:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237155AbjJBXNX (ORCPT ); Mon, 2 Oct 2023 19:13:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229954AbjJBXNW (ORCPT ); Mon, 2 Oct 2023 19:13:22 -0400 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E823AC for ; Mon, 2 Oct 2023 16:13:19 -0700 (PDT) Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1c328b53aeaso2455535ad.2 for ; Mon, 02 Oct 2023 16:13:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696288398; x=1696893198; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=f0DzF5mqOD1kMWTkgMUl5iJBtPUnq8TgdRfUEKxTAb0=; b=Tow5NGx2qoS1i+5rRupn14fM9Oqfq4Fz/G9ULh1TVOsWtnTa31/oGWQBNlQi9gBmjA OWt3lRpbhFxSy0AbOVe+dyz1djiv92d4GScZp+1BEgyfbdbM8Ga4qKW7BKHteZvkgMsS XhQc2WwErckUJePWuteIOZbYt4OO12oJzbYLt+FSvpF0KiopiROP+axHe4snLXVBpR/f yukQ2oPTSxqwhC9jfAG2JFsASDns0276sNru3tPLGdzE5sKGaPhRmaRr/EJsTKK6ynTo NLPP+UFetzoo5pKL2GdUIiCwNP2m2YF+bmcX3/7f9h7qZ4lyTFlE5OjFYkplqAQ0XpOr zr8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696288398; x=1696893198; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=f0DzF5mqOD1kMWTkgMUl5iJBtPUnq8TgdRfUEKxTAb0=; b=pidGTDr3SAUbLE4zYYXSSTfOt+K+holhkevMTaOmG/JFC6LGQdKHdjy4Lpg0ss8Ywu lD8MzQaYFQFgyDalDD1d6pk1PLkLr5aE5ZXlwc9CXj9lbxQhENO16IDlhOQuclwxvHZX sH3zToF+iQgMVlQnRoU8f338YE+1R9kcGBCjFHCVjRfAeO6H7vuFUndnqnHtUs/Gb/k8 Egwbu25HTdbIICux1GuvMxbMe92BE8j6Kh0fFIKwOcEcnU0CyEzFy3RCJdMoXw4J6Jcy bS2Q/ejLmuBvZ7feNQPKQsU2rR2e7CKHJuMqkGm7fcPzb6xRcvo8tEiCkr3QuOqw0nR2 5XCw== X-Gm-Message-State: AOJu0Yw8/Pc5ZRQbe5JZu1BPLqE1JG7MQJnjpr//hzH+IAoeA1whGsLj nGMSYny5xnB2RlsNUpvnjKyWRoseoujHDxTp X-Google-Smtp-Source: AGHT+IHtcqRVROIlUg6dmW8xcP3/xfL7roi+GlT64K7LwOoO2NnsmaWDR5MhC82mHOe5AgdjgiF1YQ== X-Received: by 2002:a17:902:9b8e:b0:1c0:cbaf:6930 with SMTP id y14-20020a1709029b8e00b001c0cbaf6930mr11958854plp.54.1696288398399; Mon, 02 Oct 2023 16:13:18 -0700 (PDT) Received: from lvondent-mobl4.. (c-98-232-221-87.hsd1.or.comcast.net. [98.232.221.87]) by smtp.gmail.com with ESMTPSA id l11-20020a170902d34b00b001c75627545csm5181817plk.135.2023.10.02.16.13.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 16:13:17 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 4/6] device: Add btd_device_get_ltk Date: Mon, 2 Oct 2023 16:13:08 -0700 Message-ID: <20231002231311.3104749-4-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231002231311.3104749-1-luiz.dentz@gmail.com> References: <20231002231311.3104749-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This adds btd_device_get_ltk function which can be used by plugins to access the LTK key. --- src/device.c | 17 +++++++++++++++++ src/device.h | 2 ++ 2 files changed, 19 insertions(+) diff --git a/src/device.c b/src/device.c index 35ce1df0fe74..a734fff0dc73 100644 --- a/src/device.c +++ b/src/device.c @@ -1938,6 +1938,23 @@ void device_set_ltk(struct btd_device *device, const uint8_t val[16], queue_foreach(device->sirks, add_set, device); } +bool btd_device_get_ltk(struct btd_device *device, uint8_t key[16], + bool *central, uint8_t *enc_size) +{ + if (!device || !device->ltk || !key) + return false; + + memcpy(key, device->ltk->key, sizeof(device->ltk->key)); + + if (central) + *central = device->ltk->central; + + if (enc_size) + *enc_size = device->ltk->enc_size; + + return true; +} + static bool match_sirk(const void *data, const void *match_data) { const struct sirk_info *sirk = data; diff --git a/src/device.h b/src/device.h index 0a9e51533ca5..8bb38669d457 100644 --- a/src/device.h +++ b/src/device.h @@ -132,6 +132,8 @@ void device_request_disconnect(struct btd_device *device, DBusMessage *msg); bool device_is_disconnecting(struct btd_device *device); void device_set_ltk(struct btd_device *device, const uint8_t val[16], bool central, uint8_t enc_size); +bool btd_device_get_ltk(struct btd_device *device, uint8_t val[16], + bool *central, uint8_t *enc_size); bool btd_device_add_set(struct btd_device *device, bool encrypted, uint8_t sirk[16], uint8_t size, uint8_t rank); void device_store_svc_chng_ccc(struct btd_device *device, uint8_t bdaddr_type, From patchwork Mon Oct 2 23:13:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 731137 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3147BE776CB for ; Mon, 2 Oct 2023 23:13:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237218AbjJBXN0 (ORCPT ); Mon, 2 Oct 2023 19:13:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237222AbjJBXNZ (ORCPT ); Mon, 2 Oct 2023 19:13:25 -0400 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98140D7 for ; Mon, 2 Oct 2023 16:13:21 -0700 (PDT) Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1c723f1c80fso2579945ad.1 for ; Mon, 02 Oct 2023 16:13:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696288400; x=1696893200; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=jTfkD4LB0wR3NJmaf5Zf1JnCjxtvsB7d6ETy73XgILw=; b=Eo5qjrkdYurH+JaU9Fh+52dpH6uZJD6BUlnU+o1UDVMY6AHM2hQ7Inl3YbSjd3JfIw iCCxC/PdZBOzvjJv0wOGQ6lBo8VR91qWpXQ+SxDoANerKHbwEB2PBmWPjDWWaOAe8MGE Epv7p/NVZtH0v5TXSvkBZupTV02ggUdqiaZjgamtM7qG9GJo3VMtlDxhLX//BdN1B1dY irNHVEVOrZGKfj8RR+lfbkc7J3+WcBGm0dsf+BVWdfK6ZoB4T0b+eye1FYgGuBwbSe+Q /M1KgQqlduwH2wMul8z0tDaq5MjOtrGw1UKTEq12ggResSSVyURF8v6s+LGdeDB1g9+G NorQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696288400; x=1696893200; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jTfkD4LB0wR3NJmaf5Zf1JnCjxtvsB7d6ETy73XgILw=; b=kYbEP5E1zLVqB09jFYJas5/b6oE42C+Wsl4nSleLxhe4ntZd3uBgMDqcq7tlbMbq/a 1Qwbqla59pjL6L0AfzzSVsRgdbbQgqgAE6siFYpdfgxpWHoQjhro2UvtGH17kn0YGQ5p dQMzkoTP2Z1EdD2AY04mOKvTqXM/U18UVj5Vum2+jCXND4GWzbAmWXMDBXnPDe6jZX/P OfEDMR4IDMGVbSFVcH2hrmUFJ/RtrxEr7bmdbPEJyjZyVD7Ov89MkqXVAaQgs3qtk8VQ VThd+Ss/yDWyRc+k6cOt0w8VQqnX5aQvx1UxsvHRvogBez17X3lqzii+k7py9LEZifNc 5dGw== X-Gm-Message-State: AOJu0YwMm2C6yqp2gJBT8bsXMURhUZ9TCN6F2gioibsymLKCrJ1s1WAv cboN0j6yQxXXZyPonlF+LB5mpSmRMnnDQDH0 X-Google-Smtp-Source: AGHT+IHWbavW4s0LKB4zGTtVMv+IMcrWnXJtoPXE3u30Uud5xHLT1f+F5vRdWWlzV3PdSL+6/iL9Cg== X-Received: by 2002:a17:902:c409:b0:1c5:ea60:85c1 with SMTP id k9-20020a170902c40900b001c5ea6085c1mr13693506plk.12.1696288400148; Mon, 02 Oct 2023 16:13:20 -0700 (PDT) Received: from lvondent-mobl4.. (c-98-232-221-87.hsd1.or.comcast.net. [98.232.221.87]) by smtp.gmail.com with ESMTPSA id l11-20020a170902d34b00b001c75627545csm5181817plk.135.2023.10.02.16.13.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 16:13:19 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 5/6] csip: Add support for SIRK encryption Date: Mon, 2 Oct 2023 16:13:09 -0700 Message-ID: <20231002231311.3104749-5-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231002231311.3104749-1-luiz.dentz@gmail.com> References: <20231002231311.3104749-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This implements SIRK value encryption using the LTK which is accessed using btd_device_get_ltk. --- profiles/audio/csip.c | 36 ++++++++++++++++++++++++++---- src/shared/csip.c | 51 ++++--------------------------------------- src/shared/csip.h | 5 ++--- 3 files changed, 38 insertions(+), 54 deletions(-) diff --git a/profiles/audio/csip.c b/profiles/audio/csip.c index 05bf588d8d6f..a697ebdfbda0 100644 --- a/profiles/audio/csip.c +++ b/profiles/audio/csip.c @@ -40,6 +40,7 @@ #include "src/shared/gatt-client.h" #include "src/shared/gatt-server.h" #include "src/shared/csip.h" +#include "src/shared/crypto.h" #include "btio/btio.h" #include "src/plugin.h" @@ -313,10 +314,37 @@ static struct btd_profile csip_profile = { .experimental = true, }; -static bool csis_ltk_read(struct bt_csip *csip, uint8_t k[16], void *user_data) +static bool csis_encrypt(struct bt_att *att, uint8_t val[16]) { - /* TODO: Retrieve LTK using device object */ - return false; + struct btd_device *device; + struct bt_crypto *crypto; + uint8_t ltk[16]; + bool ret; + + device = btd_adapter_find_device_by_fd(bt_att_get_fd(att)); + if (!device) { + error("Unable to find device"); + return false; + } + + if (!btd_device_get_ltk(device, ltk, NULL, NULL)) { + error("Unable to get device LTK"); + return false; + } + + crypto = bt_crypto_new(); + if (!crypto) { + error("Failed to open crypto"); + return false; + } + + ret = bt_crypto_sef(crypto, ltk, val, val); + if (!ret) + error("Failed to encrypt SIRK using LTK"); + + bt_crypto_unref(crypto); + + return ret; } static void csis_data_add(struct csis_data *data) @@ -332,7 +360,7 @@ static void csis_data_add(struct csis_data *data) bt_csip_set_sirk(data->csip, btd_opts.csis.encrypt, btd_opts.csis.sirk, btd_opts.csis.size, btd_opts.csis.rank, - csis_ltk_read, data); + csis_encrypt); if (!servers) servers = queue_new(); diff --git a/src/shared/csip.c b/src/shared/csip.c index 85de63ea626b..53ce155416c7 100644 --- a/src/shared/csip.c +++ b/src/shared/csip.c @@ -66,6 +66,7 @@ struct bt_csis { struct gatt_db_attribute *lock; struct gatt_db_attribute *lock_ccc; struct gatt_db_attribute *rank; + bt_csip_encrypt_func_t encrypt; }; struct bt_csip_cb { @@ -96,9 +97,6 @@ struct bt_csip { bt_csip_destroy_func_t debug_destroy; void *debug_data; - bt_csip_ltk_func_t ltk_func; - void *ltk_data; - bt_csip_sirk_func_t sirk_func; void *sirk_data; @@ -218,46 +216,6 @@ static void csip_debug(struct bt_csip *csip, const char *format, ...) va_end(ap); } -static bool csip_match_att(const void *data, const void *match_data) -{ - const struct bt_csip *csip = data; - const struct bt_att *att = match_data; - - return bt_csip_get_att((void *)csip) == att; -} - -static bool csis_sirk_enc(struct bt_csis *csis, struct bt_att *att, - struct csis_sirk *sirk) -{ - struct bt_csip *csip; - uint8_t k[16]; - struct bt_crypto *crypto; - bool ret; - - csip = queue_find(sessions, csip_match_att, att); - if (!csip) - return false; - - if (!csip->ltk_func(csip, k, csip->ltk_data)) { - DBG(csip, "Unable to read sef key"); - return false; - } - - crypto = bt_crypto_new(); - if (!crypto) { - DBG(csip, "Failed to open crypto"); - return false; - } - - ret = bt_crypto_sef(crypto, k, sirk->val, sirk->val); - if (!ret) - DBG(csip, "Failed to encrypt SIRK using sef"); - - bt_crypto_unref(crypto); - - return ret; -} - static void csis_sirk_read(struct gatt_db_attribute *attrib, unsigned int id, uint16_t offset, uint8_t opcode, struct bt_att *att, @@ -270,7 +228,7 @@ static void csis_sirk_read(struct gatt_db_attribute *attrib, memcpy(&sirk, csis->sirk_val, sizeof(sirk)); if (sirk.type == BT_CSIP_SIRK_ENCRYPT && - !csis_sirk_enc(csis, att, &sirk)) { + !csis->encrypt(att, sirk.val)) { gatt_db_attribute_read_result(attrib, id, BT_ATT_ERROR_UNLIKELY, NULL, 0); return; @@ -776,7 +734,7 @@ static struct csis_sirk *sirk_new(struct bt_csis *csis, struct gatt_db *db, bool bt_csip_set_sirk(struct bt_csip *csip, bool encrypt, uint8_t k[16], uint8_t size, uint8_t rank, - bt_csip_ltk_func_t func, void *user_data) + bt_csip_encrypt_func_t func) { uint8_t zero[16] = {}; uint8_t type; @@ -793,8 +751,7 @@ bool bt_csip_set_sirk(struct bt_csip *csip, bool encrypt, if (!sirk_new(csip->ldb->csis, csip->ldb->db, type, k, size, rank)) return false; - csip->ltk_func = func; - csip->ltk_data = user_data; + csip->ldb->csis->encrypt = func; return true; } diff --git a/src/shared/csip.h b/src/shared/csip.h index bc5519cfbc49..81c8954aba8d 100644 --- a/src/shared/csip.h +++ b/src/shared/csip.h @@ -27,8 +27,7 @@ typedef void (*bt_csip_ready_func_t)(struct bt_csip *csip, void *user_data); typedef void (*bt_csip_destroy_func_t)(void *user_data); typedef void (*bt_csip_debug_func_t)(const char *str, void *user_data); typedef void (*bt_csip_func_t)(struct bt_csip *csip, void *user_data); -typedef bool (*bt_csip_ltk_func_t)(struct bt_csip *csip, uint8_t k[16], - void *user_data); +typedef bool (*bt_csip_encrypt_func_t)(struct bt_att *att, uint8_t k[16]); typedef bool (*bt_csip_sirk_func_t)(struct bt_csip *csip, uint8_t type, uint8_t k[16], uint8_t size, uint8_t rank, void *user_data); @@ -54,7 +53,7 @@ struct bt_csip *bt_csip_new(struct gatt_db *ldb, struct gatt_db *rdb); bool bt_csip_set_sirk(struct bt_csip *csip, bool encrypt, uint8_t k[16], uint8_t size, uint8_t rank, - bt_csip_ltk_func_t func, void *user_data); + bt_csip_encrypt_func_t func); bool bt_csip_get_sirk(struct bt_csip *csip, uint8_t *type, uint8_t k[16], uint8_t *size, uint8_t *rank); From patchwork Mon Oct 2 23:13:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 728597 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 31D06E776D4 for ; Mon, 2 Oct 2023 23:13:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237222AbjJBXN1 (ORCPT ); Mon, 2 Oct 2023 19:13:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237244AbjJBXN0 (ORCPT ); Mon, 2 Oct 2023 19:13:26 -0400 Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A835DD for ; Mon, 2 Oct 2023 16:13:23 -0700 (PDT) Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-690d2e13074so239508b3a.1 for ; Mon, 02 Oct 2023 16:13:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696288402; x=1696893202; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=9bOC1VWOkzWPvLAfHiyqGBjBEjQKxpPMPr3QmumM+hI=; b=gEuvx4kwefP7Q0Pn5wMil5iyl4ZDcWOjNq1tGputuspprYE1axPR3E3YUsa+pHkuCd 1O9EW4rnAGFnT/RJ/VR4Lahr15aBQE8N93lmm6NujVJ4vdTNxOfhxH2UMhBhIlQSwjBk 9rEi3ui03UytE552b9icQfPGhE+C+kCVz4pbqXx4l1HM5BAl1pOwCAemBBGl32Zv70TD RzxsM9QaJ2y3y2timLDwmgJiVcdKuGNT4VbRlSsPsqsn31kL3qyES9noSNKjhpI4mX4d TYCgWeyzjxbhWZdJJ6T/rv3b8XnaJLtf2HT9pWdmpELIHMvy58k4f9sEikJM3CwGNmqS xFDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696288402; x=1696893202; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9bOC1VWOkzWPvLAfHiyqGBjBEjQKxpPMPr3QmumM+hI=; b=uBRvgwm2cTvJFoHpsU++YMW2AcpVOU6aH63IoTEy7wOVs4jGGRis+f7i4aphc4MyFv Rm7NtrFUYCxisyCEjPCIrek0e9PnOg7crzorbXwwxtDgoQEA4uOYK/jR+X4IcMD1z9FT mGdcEY7tV9wJvCtLmUuYRnjQqUwQnNYr6053BhNJzJrJmuOhkOwPM5gQ2s30wX09uIBa 2QEkM24sNIoYGwQVtq4rbpcGM1nNw7UItu5nBZFtPnhG2Vpox7aaR5K8JBvi+hLXT6Oo YXg9jiKl53Qgi3+mP3wHqCi9x+N0T36h43keBp78fH6U5DwhWlEtpdb843LDTPP7aZ9I pqKQ== X-Gm-Message-State: AOJu0YxgeQdfeHMz3Ddzr+3NT5MoTO8fyWrib5J87d1VuJAC9QpxbF3n TXCRJovk02Q+D9Mrz26RSHeYX/cpVt1jAZOv X-Google-Smtp-Source: AGHT+IGtye+3+8UyljIW0DCUmMZilPydAwhorVqjGSypd/sULvlUnpocYvlmwe/DCS4zI6ZjG8j8eQ== X-Received: by 2002:a05:6a21:a590:b0:160:8984:6cc6 with SMTP id gd16-20020a056a21a59000b0016089846cc6mr14298969pzc.58.1696288401985; Mon, 02 Oct 2023 16:13:21 -0700 (PDT) Received: from lvondent-mobl4.. (c-98-232-221-87.hsd1.or.comcast.net. [98.232.221.87]) by smtp.gmail.com with ESMTPSA id l11-20020a170902d34b00b001c75627545csm5181817plk.135.2023.10.02.16.13.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 16:13:20 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 6/6] main.conf: Fix default of CSIS.encrypt Date: Mon, 2 Oct 2023 16:13:10 -0700 Message-ID: <20231002231311.3104749-6-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231002231311.3104749-1-luiz.dentz@gmail.com> References: <20231002231311.3104749-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz CSIS.encrypt setting shall default to true, not false. --- src/main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main.c b/src/main.c index cddf1396197b..ddb73431df94 100644 --- a/src/main.c +++ b/src/main.c @@ -1195,6 +1195,7 @@ static void init_defaults(void) btd_opts.avdtp.stream_mode = BT_IO_MODE_BASIC; btd_opts.advmon.rssi_sampling_period = 0xFF; + btd_opts.csis.encrypt = true; } static void log_handler(const gchar *log_domain, GLogLevelFlags log_level,