From patchwork Wed Mar 8 00:51:57 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: 660704 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 B802BC6FA99 for ; Wed, 8 Mar 2023 00:52:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229706AbjCHAwF (ORCPT ); Tue, 7 Mar 2023 19:52:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229629AbjCHAwD (ORCPT ); Tue, 7 Mar 2023 19:52:03 -0500 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A5CDA9094 for ; Tue, 7 Mar 2023 16:52:02 -0800 (PST) Received: by mail-pj1-x1036.google.com with SMTP id cp7-20020a17090afb8700b0023756229427so638971pjb.1 for ; Tue, 07 Mar 2023 16:52:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678236721; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=4R6L+GTqN8b3HGMFjKfIcEc3M6NiP/F3Cu0JK9UAazE=; b=XaylUqxZyDxA28SVDmw24q0HP6BEynbXE0xpAOyfLSPXa5uV6XMoz5FbDM7TVaP1f0 GQa6qNpJgNEDLLgHyPCgnrTAfrwVlfk9rPn/ZFpTsyiU8JX4vdW3JsMmZGfkQ4A0asqa Vo8OOyeSEWtDNmphqyJYaRLwfimGzbYHb6lnUvZIjM3uGouZnbY+cIb7Zrvx8JIKmekN 9G6Fsr/rIldOysMEO+zjZziv3hfPypBohlx8gerRt0J6r/qdxGrydixpYvRPXiygn9fd TQ/+ExOvGa60d9K6Y7zHTKQ2CHlbEhe7cWbuJZqdXdgssMri5nQTpZ0E/Kq0KrtzWMUW NcqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678236721; 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=4R6L+GTqN8b3HGMFjKfIcEc3M6NiP/F3Cu0JK9UAazE=; b=Vbmn8ymyoADyucGvoZb8FHytAW1zw0YzGn7ZBTJIBPD+0RIu2AyHGFpXeTSFkWVxNK hU/gM8r8q+bp8kGNf/3D4Uzju0Z+iI2RoLw81NKczpjru3KwiCnNVQevS0gyAUsBTuEi kyxG9MKXoLFHoMpL6Grpta1P6nVs4O/7yBYvoyVHO4W9G1ohuck28C+csKySJKHn81LZ QywljxMQrHFf39N2VSsxCdEDZYJTXDppadfqPwlYxgd8jlkX69Pq1N0XG2mY7h0nmvZi liVKGDFxy+uHtgu9fjtIunY18eQU3nMqEQ3D5bEPHz8HsAOUave5f6dCaU0zvzY2qAUN pmCA== X-Gm-Message-State: AO0yUKUyjiNqJMqgOBBjl5Evfs+NrZwUIInkbl8XLfONG2bST1CjqXtl XqAtnZSo//qoPsf7JmJdfWZTiQXRp+0= X-Google-Smtp-Source: AK7set+nNGHkE5A4fCwnM7MuGvP64tL3NiqSWdDikD1ZJxix0suV2ECN8nMCTP6ZygtUSMw3zwH53Q== X-Received: by 2002:a05:6a20:7d86:b0:cd:6f68:98d6 with SMTP id v6-20020a056a207d8600b000cd6f6898d6mr20483872pzj.0.1678236721221; Tue, 07 Mar 2023 16:52:01 -0800 (PST) Received: from lvondent-mobl4.. (c-71-59-129-171.hsd1.or.comcast.net. [71.59.129.171]) by smtp.gmail.com with ESMTPSA id j18-20020aa78dd2000000b005d61829db4fsm8379610pfr.168.2023.03.07.16.51.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Mar 2023 16:52:00 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 1/2] device: Fix not always storing device info Date: Tue, 7 Mar 2023 16:51:57 -0800 Message-Id: <20230308005158.2661414-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz When updating the device address check if the device is marked as temporary before attempting to call store_device_info otherwise it will have no effect and instead btd_device_set_temporary must be called. --- src/device.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/device.c b/src/device.c index df50ce7b4f6c..652c03606b9e 100644 --- a/src/device.c +++ b/src/device.c @@ -4412,7 +4412,10 @@ void device_update_addr(struct btd_device *device, const bdaddr_t *bdaddr, bacpy(&device->bdaddr, bdaddr); device->bdaddr_type = bdaddr_type; - store_device_info(device); + if (device->temporary) + btd_device_set_temporary(device, false); + else + store_device_info(device); g_dbus_emit_property_changed(dbus_conn, device->path, DEVICE_INTERFACE, "Address"); From patchwork Wed Mar 8 00:51:58 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: 662187 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 8323DC6FD1F for ; Wed, 8 Mar 2023 00:52:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229707AbjCHAwF (ORCPT ); Tue, 7 Mar 2023 19:52:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229484AbjCHAwE (ORCPT ); Tue, 7 Mar 2023 19:52:04 -0500 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B20DDA8C48 for ; Tue, 7 Mar 2023 16:52:03 -0800 (PST) Received: by mail-pf1-x434.google.com with SMTP id a7so9241676pfx.10 for ; Tue, 07 Mar 2023 16:52:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678236723; 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=UqSEsPP2Qc9avva4EXCBw4/r2HhRoTMabXS46bng8UI=; b=Re/OXOEHoLbmNvvXnEj43TGfPpJ+l3UICme+4TF+TFb5z46t6TnuDHatPk6lhcJ9Br TkLQhOYroTuwhipcTMo0Wwo4Vly/p4XYeg95QK+x7UkbLW/CiAOdIoAiqSc52p1qa9QG O6TaKE9Bj7c/r21UXQszSJNahf6bMjQtldp6+06zDVBOv4XDTVPC7WZJZJcdZDnRFWqI +FnmLe39QdPZTenefqwwbrFNrzuODq8PJkVF5v5kPWLHdDeOfQJ/TQdZbsGc7tXfHyTg 7JbcMfAFB/7k7QEm/RrCwAqHPOUQZ6imv/IWk1fBPvij7hjfeOh5uJ99beD9kHDSW4mC ET3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678236723; 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=UqSEsPP2Qc9avva4EXCBw4/r2HhRoTMabXS46bng8UI=; b=b2lu9xtnidc99aRtRZrezPSvwwTLuxIk4AeOpr9dzngH77vCmBHHgqTq3Yte78dI84 1Cbt6a0LKg1r0jpcNIbBHPzUbFW6gRgiSVLLh1yNOFettha1rNVFIbFNzno/O5fX3c2C nXJZoFF/qBWeXZXchuZ+orwrVABJCbd6+g0ZPVwWT+0Nh9kEVyLyGCd7zQh7iwh9IN9M cVZ21Phc8JE7YW7caYNqHS5eJMFI8R7UXqvOHOVNxziUO9LUhCy+Mtq7beqZ8Q2ENi3J 27Xk+OmdDTwk5FXMwEZ1bkloXwrIepfsTju+bjt2Z8saI2PVZM6y24o580lJ0xiC+OsQ TMHw== X-Gm-Message-State: AO0yUKUMxkSzZ0PsHzjFc8aajs71uIVfqlm//3tqLYM4UidXBwigk0uh /AxNaiJKPT+b0OQ71Wtu6p95bbAiDWI= X-Google-Smtp-Source: AK7set9xLly7MjiXLdiW7zpQzKTMEd5Zo1LQTfKftHYJOPWzF2NY+FpcxhJy6YFjb5/vdRK5s4Z1MA== X-Received: by 2002:aa7:973c:0:b0:618:920c:8cb2 with SMTP id k28-20020aa7973c000000b00618920c8cb2mr12980760pfg.21.1678236722688; Tue, 07 Mar 2023 16:52:02 -0800 (PST) Received: from lvondent-mobl4.. (c-71-59-129-171.hsd1.or.comcast.net. [71.59.129.171]) by smtp.gmail.com with ESMTPSA id j18-20020aa78dd2000000b005d61829db4fsm8379610pfr.168.2023.03.07.16.52.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Mar 2023 16:52:02 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 2/2] gatt: Fix creating duplicated objects Date: Tue, 7 Mar 2023 16:51:58 -0800 Message-Id: <20230308005158.2661414-2-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230308005158.2661414-1-luiz.dentz@gmail.com> References: <20230308005158.2661414-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 checks cid before attempting to create device, if the device is using an RPA it could be that the MGMT event has not been processed yet which would lead to create a second copy of the same device using its identity address. --- src/gatt-database.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/gatt-database.c b/src/gatt-database.c index ea282d4bc193..3b53bf2a3c84 100644 --- a/src/gatt-database.c +++ b/src/gatt-database.c @@ -632,6 +632,7 @@ static void connect_cb(GIOChannel *io, GError *gerr, gpointer user_data) struct btd_device *device; uint8_t dst_type; bdaddr_t src, dst; + uint16_t cid; if (gerr) { error("%s", gerr->message); @@ -641,6 +642,7 @@ static void connect_cb(GIOChannel *io, GError *gerr, gpointer user_data) bt_io_get(io, &gerr, BT_IO_OPT_SOURCE_BDADDR, &src, BT_IO_OPT_DEST_BDADDR, &dst, BT_IO_OPT_DEST_TYPE, &dst_type, + BT_IO_OPT_CID, &cid, BT_IO_OPT_INVALID); if (gerr) { error("bt_io_get: %s", gerr->message); @@ -655,9 +657,21 @@ static void connect_cb(GIOChannel *io, GError *gerr, gpointer user_data) if (!adapter) return; - device = btd_adapter_get_device(adapter, &dst, dst_type); - if (!device) + /* Check cid before attempting to create device, if the device is using + * an RPA it could be that the MGMT event has not been processed yet + * which would lead to create a second copy of the same device using its + * identity address. + */ + if (cid == BT_ATT_CID) + device = btd_adapter_get_device(adapter, &dst, dst_type); + else + device = btd_adapter_find_device(adapter, &dst, dst_type); + + if (!device) { + error("Unable to find device, dropping connection attempt"); + g_io_channel_shutdown(io, FALSE, NULL); return; + } device_attach_att(device, io); }