Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp5542380iog; Wed, 22 Jun 2022 23:37:47 -0700 (PDT) X-Google-Smtp-Source: AGRyM1stv1w15q45xh+jTu4+EA9EXKRTBWBnH5JVc+7wlLrK5oCDgA5sD0exeFZamDZPPYi6Bx59 X-Received: by 2002:a05:6a00:1344:b0:51b:e3b5:54e2 with SMTP id k4-20020a056a00134400b0051be3b554e2mr39360580pfu.6.1655966267375; Wed, 22 Jun 2022 23:37:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655966267; cv=none; d=google.com; s=arc-20160816; b=nr5vB0wB3W9S7Zw8g65H2MiLkxkNHYD02IhizphAdhZU4WjM8UZSFEPyg5PMpPM1pY tnfHNSrLMCQBEBFTswj6ELit98eTCrJirqz7VnBeq/IzyqfA7WyT3Wu8TWA8abMBxYTF SBfB2KQEZH1GNzkPY5o4oMQfBcQDp+4JYYNg2fSbPW0CfNYOLN6eCK150UjDe87L3qSP hsbXvX3LgNAe71MK+ws7UUN1z/0MIHZyzJDTXyM5hxCqpjVpJPBxwGA7wIsMQbTSbKtU SAX7d78wejVShy9Wit2eAN4OeODJtUZLMkdYKkUY/mCpb7Z+7wXf5AOKieqihzJH+WFZ 3YnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:feedback-id:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from; bh=+stSi10GfXgsYEHK0Grm2hTwXQJPyAOdXjQoQXEJeKA=; b=wthcJf6WsjC1Vk/08yCOBrQ/TDlgu3ZXU34+EWxtl4fT0qm0ZDQgjrPdqelX2q3Upt ONH9LK3vtwYl1lmwnFjFNh43qeNwFcgxQl/00wiefmiMXTt95NXbS405bKm/DeNeZSNI JzVwWGPtTbIH2WaPJe5ktxEy0nHtJTNcsAgetdH5P/ctXCnMW9Sdw1QQjATstY2zh57k dUyNYOncQTkGVPcVnxYaxNkSdEcGq1M8Z+tGLYF9hzl+m2sBTqxhBQO/gbWvmuOKFiwj X93/RsY/6t8S9fpL+oIu8jWJGSKIY1UkOP+GFVBCOuxeAy2/iYdIXA5YlibioK0TYxfU 6X3w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j64-20020a638043000000b0040cc5d2b9d5si13449200pgd.836.2022.06.22.23.37.26; Wed, 22 Jun 2022 23:37:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229469AbiFWGaL (ORCPT + 99 others); Thu, 23 Jun 2022 02:30:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229461AbiFWGaK (ORCPT ); Thu, 23 Jun 2022 02:30:10 -0400 X-Greylist: delayed 17148 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Wed, 22 Jun 2022 23:30:06 PDT Received: from smtpbgjp3.qq.com (smtpbgjp3.qq.com [54.92.39.34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6DFD5387B2 for ; Wed, 22 Jun 2022 23:30:06 -0700 (PDT) X-QQ-mid: bizesmtp73t1655965800ta4dykda Received: from localhost.localdomain ( [113.57.152.160]) by bizesmtp.qq.com (ESMTP) with id ; Thu, 23 Jun 2022 14:29:55 +0800 (CST) X-QQ-SSF: 01400000002000C0E000000A0000000 X-QQ-FEAT: dpyQmELDBxGupUERX8pQO6ILwxDVXkQdBhxsenN2dZKfCetxOC3moznZ8C+zK LZ/6ngLUusGAdNTyfPD5bAJDB/EcFcCfmdJHH/Deo/keZ9XMHfYcn76ydLKmw9kr6BbapWq cVikTKI7ptGjEizu784vPbb3S4fqe9h/YrIEryXAogoRprY0gPgtrTgB+o7XpqJjwJZdumc xvkeuYw9BPhgJbhN815FwD7HNQM5g4YtiPzQiMQluebLFzl5k2o2qheiT8f3nyIrsXilWIB Uf1dLXzurUJLCohWy5BcF59qRnRehsesXEvekzh7QLx5jGk8DRmxYPqV8R/QNa9jXkYrNv6 aSQ+r40wDdQEy/1dwm0/5aEpxbSlg== X-QQ-GoodBg: 1 From: Youwan Wang To: linux-bluetooth@vger.kernel.org Cc: Youwan Wang Subject: [PATCH] device: Fix not removing connected device Date: Thu, 23 Jun 2022 14:29:53 +0800 Message-Id: <20220623062953.13419-1-wangyouwan@uniontech.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:uniontech.com:qybgforeign:qybgforeign8 X-QQ-Bgrelay: 1 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org [bluetooth]# connect 40:EF:4C:0C:11:F0 Attempting to connect to 40:EF:4C:0C:11:F0 [CHG] Device 40:EF:4C:0C:11:F0 Connected: yes Connection successful [CHG] Device 40:EF:4C:0C:11:F0 ServicesResolved: yes [UFO]# remove 40:EF:4C:0C:11:F0 [CHG] Device 40:EF:4C:0C:11:F0 ServicesResolved: no Device has been removed [CHG] Device 40:EF:4C:0C:11:F0 Connected: no [bluetooth]# info 40:EF:4C:0C:11:F0 Device 40:EF:4C:0C:11:F0 (public) Name: UFO Alias: UFO Class: 0x00240418 Icon: audio-headphones Paired: yes Trusted: no Blocked: no Connected: no LegacyPairing: no UUID: Headset UUID: Audio Sink UUID: A/V Remote Control Target UUID: A/V Remote Control UUID: Handsfree UUID: Phonebook Access Server --- src/adapter.c | 11 ++++++++++- src/device.c | 5 +++-- src/device.h | 3 ++- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/adapter.c b/src/adapter.c index afefa1d5d..16da20034 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -7171,6 +7171,8 @@ static void adapter_remove_connection(struct btd_adapter *adapter, struct btd_device *device, uint8_t bdaddr_type) { + bool remove_device = false; + DBG(""); if (!g_slist_find(adapter->connections, device)) { @@ -7178,7 +7180,7 @@ static void adapter_remove_connection(struct btd_adapter *adapter, return; } - device_remove_connection(device, bdaddr_type); + device_remove_connection(device, bdaddr_type, &remove_device); if (device_is_authenticating(device)) device_cancel_authentication(device, TRUE); @@ -7188,6 +7190,13 @@ static void adapter_remove_connection(struct btd_adapter *adapter, return; adapter->connections = g_slist_remove(adapter->connections, device); + + if (remove_device) { + const char *path = device_get_path(device); + + DBG("Removing temporary device %s", path); + btd_adapter_remove_device(adapter, device); + } } static void adapter_stop(struct btd_adapter *adapter) diff --git a/src/device.c b/src/device.c index 7b451e458..c5484ca7b 100644 --- a/src/device.c +++ b/src/device.c @@ -3073,7 +3073,8 @@ static void set_temporary_timer(struct btd_device *dev, unsigned int timeout) dev, NULL); } -void device_remove_connection(struct btd_device *device, uint8_t bdaddr_type) +void device_remove_connection(struct btd_device *device, uint8_t bdaddr_type, + bool *remove) { struct bearer_state *state = get_state(device, bdaddr_type); DBusMessage *reply; @@ -3159,7 +3160,7 @@ void device_remove_connection(struct btd_device *device, uint8_t bdaddr_type) DEVICE_INTERFACE, "Connected"); if (remove_device) - set_temporary_timer(device, 0); + *remove = remove_device; } guint device_add_disconnect_watch(struct btd_device *device, diff --git a/src/device.h b/src/device.h index 960255d2b..d7f886224 100644 --- a/src/device.h +++ b/src/device.h @@ -123,7 +123,8 @@ int device_notify_pincode(struct btd_device *device, gboolean secure, void device_cancel_authentication(struct btd_device *device, gboolean aborted); gboolean device_is_authenticating(struct btd_device *device); void device_add_connection(struct btd_device *dev, uint8_t bdaddr_type); -void device_remove_connection(struct btd_device *device, uint8_t bdaddr_type); +void device_remove_connection(struct btd_device *device, uint8_t bdaddr_type, + bool *remove); void device_request_disconnect(struct btd_device *device, DBusMessage *msg); bool device_is_disconnecting(struct btd_device *device); void device_set_ltk_enc_size(struct btd_device *device, uint8_t enc_size); -- 2.20.1