From patchwork Tue Sep 15 17:41:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abhishek Pandit-Subedi X-Patchwork-Id: 252731 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F3559C43461 for ; Tue, 15 Sep 2020 17:45:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9B7882193E for ; Tue, 15 Sep 2020 17:45:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="K4iPadvg" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727916AbgIORoR (ORCPT ); Tue, 15 Sep 2020 13:44:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727803AbgIORl6 (ORCPT ); Tue, 15 Sep 2020 13:41:58 -0400 Received: from mail-pj1-x1044.google.com (mail-pj1-x1044.google.com [IPv6:2607:f8b0:4864:20::1044]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB9B0C061788 for ; Tue, 15 Sep 2020 10:41:57 -0700 (PDT) Received: by mail-pj1-x1044.google.com with SMTP id jw11so166250pjb.0 for ; Tue, 15 Sep 2020 10:41:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=K68OMwlpExv+H2CPFTDq3E7u55gF4Q0V8948rZscVcY=; b=K4iPadvg0nNgSbx6It9gMhlMf8f3iAUys9Jl6j7LYXIlIvdjbXFt2Gsla5ytYqS0Z2 KwWR1KmWId7wMR44ZW0EghB1L8nFOskYcaUFgkkv/RUmCCzC/4zICqtFgbvVx2q/7zDE TTTdmrVU5Umn6U1ix4G3Azv+gJ/05M9AmZBnU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=K68OMwlpExv+H2CPFTDq3E7u55gF4Q0V8948rZscVcY=; b=AgwuxRsFP5RfDUt+cFkc0+NyZqqweAw+mdBR9ldFuGewpwiHcm2OWTeAi/H1ZpVoum 1ZBwjYujR1u5X2qp8dLHdxgoKWPHIxK4dpicogBbptPmqgrTgPowUBX3T4U8CVB3sq+z gxnJapGxodhrhKABa+OOpI58nQOls+nVOrhwhEKDh0p1mEBiOuKuFwV0Syn3aVkPdYwl W5UEKbh9bTLaPQXWIZKQymMRICjdWuHtALAnZqrwv0SBK4otIrYVmI8d0WdHZ/CjfYIR Sjcsv4q9npZ41Hi7MVnt9/WmZD3jToCAEtti2uO7bNDK0q6OvcUcanRXYm0k8p2a6sOx J3gA== X-Gm-Message-State: AOAM5337vKhGBtB6So2Cl54G20Lgdlh3MuScOKpUomUne4UORxmCAGgW vXvssg8e3lGlg6Is9wNz+PFUkQ== X-Google-Smtp-Source: ABdhPJwc68XJZ8R6iQvfVf8UExhHudfNU97Pet9GhVy5uDvY3ltTqkxf80GZUXznPoCphv5OvrSTBA== X-Received: by 2002:a17:90a:1548:: with SMTP id y8mr423325pja.113.1600191717370; Tue, 15 Sep 2020 10:41:57 -0700 (PDT) Received: from apsdesk.mtv.corp.google.com ([2620:15c:202:1:7220:84ff:fe09:2b94]) by smtp.gmail.com with ESMTPSA id y29sm15490232pfq.207.2020.09.15.10.41.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Sep 2020 10:41:56 -0700 (PDT) From: Abhishek Pandit-Subedi To: luiz.dentz@gmail.com, marcel@holtmann.org Cc: chromeos-bluetooth-upstreaming@chromium.org, linux-bluetooth@vger.kernel.org, Abhishek Pandit-Subedi Subject: [Bluez PATCH v5 1/4] adapter: Refactor kernel feature globals Date: Tue, 15 Sep 2020 10:41:43 -0700 Message-Id: <20200915104127.Bluez.v5.1.Ib9712d2bf5d4b3f90c5bc835742aea8c7cd239e4@changeid> X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog In-Reply-To: <20200915174146.1693687-1-abhishekpandit@chromium.org> References: <20200915174146.1693687-1-abhishekpandit@chromium.org> MIME-Version: 1.0 Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Move all the kernel specific feature globals into a single kernel_features bitfield and replace all uses with the bitfield instead. --- Changes in v5: - Remove use of !! in has_kernel_features Changes in v4: None Changes in v3: None Changes in v2: None src/adapter.c | 59 ++++++++++++++++++++++++++------------------------- src/adapter.h | 9 ++++++++ 2 files changed, 39 insertions(+), 29 deletions(-) diff --git a/src/adapter.c b/src/adapter.c index 1435e2bd7..88b5202d9 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -116,13 +116,7 @@ static const struct mgmt_blocked_key_info blocked_keys[] = { static DBusConnection *dbus_conn = NULL; -static bool kernel_conn_control = false; - -static bool kernel_blocked_keys_supported = false; - -static bool kernel_set_system_config = false; - -static bool kernel_exp_features = false; +static uint32_t kernel_features = 0; static GList *adapter_list = NULL; static unsigned int adapter_remaining = 0; @@ -678,7 +672,7 @@ static bool set_discoverable(struct btd_adapter *adapter, uint8_t mode, DBG("sending set mode command for index %u", adapter->dev_id); - if (kernel_conn_control) { + if (has_kernel_features(KERNEL_CONN_CONTROL)) { if (mode) set_mode(adapter, MGMT_OP_SET_CONNECTABLE, mode); else @@ -1334,7 +1328,7 @@ static void trigger_passive_scanning(struct btd_adapter *adapter) * no need to start any discovery. The kernel will keep scanning * as long as devices are in its auto-connection list. */ - if (kernel_conn_control) + if (has_kernel_features(KERNEL_CONN_CONTROL)) return; /* @@ -1385,7 +1379,7 @@ static void stop_passive_scanning_complete(uint8_t status, uint16_t length, * no need to stop any discovery. The kernel will handle the * auto-connection by itself. */ - if (kernel_conn_control) + if (has_kernel_features(KERNEL_CONN_CONTROL)) return; /* @@ -2816,7 +2810,7 @@ static void property_set_mode_complete(uint8_t status, uint16_t length, static void clear_discoverable(struct btd_adapter *adapter) { - if (!kernel_conn_control) + if (!has_kernel_features(KERNEL_CONN_CONTROL)) return; if (!(adapter->current_settings & MGMT_SETTING_DISCOVERABLE)) @@ -2876,7 +2870,7 @@ static void property_set_mode(struct btd_adapter *adapter, uint32_t setting, break; case MGMT_SETTING_DISCOVERABLE: - if (kernel_conn_control) { + if (has_kernel_features(KERNEL_CONN_CONTROL)) { if (mode) { set_mode(adapter, MGMT_OP_SET_CONNECTABLE, mode); @@ -4193,7 +4187,8 @@ static void load_default_system_params(struct btd_adapter *adapter) size_t len = 0; unsigned int err; - if (!main_opts.default_params.num_entries || !kernel_set_system_config) + if (!main_opts.default_params.num_entries || + !has_kernel_features(KERNEL_SET_SYSTEM_CONFIG)) return; params = malloc0(sizeof(*params) * @@ -4878,7 +4873,7 @@ int adapter_connect_list_add(struct btd_adapter *adapter, * adapter_auto_connect_add() function is used to maintain what to * connect. */ - if (kernel_conn_control) + if (has_kernel_features(KERNEL_CONN_CONTROL)) return 0; if (g_slist_find(adapter->connect_list, device)) { @@ -4918,7 +4913,7 @@ void adapter_connect_list_remove(struct btd_adapter *adapter, if (device == adapter->connect_le) adapter->connect_le = NULL; - if (kernel_conn_control) + if (has_kernel_features(KERNEL_CONN_CONTROL)) return; if (!g_slist_find(adapter->connect_list, device)) { @@ -4980,7 +4975,7 @@ void adapter_whitelist_add(struct btd_adapter *adapter, struct btd_device *dev) { struct mgmt_cp_add_device cp; - if (!kernel_conn_control) + if (!has_kernel_features(KERNEL_CONN_CONTROL)) return; memset(&cp, 0, sizeof(cp)); @@ -5019,7 +5014,7 @@ void adapter_whitelist_remove(struct btd_adapter *adapter, struct btd_device *de { struct mgmt_cp_remove_device cp; - if (!kernel_conn_control) + if (!has_kernel_features(KERNEL_CONN_CONTROL)) return; memset(&cp, 0, sizeof(cp)); @@ -5075,7 +5070,7 @@ void adapter_auto_connect_add(struct btd_adapter *adapter, uint8_t bdaddr_type; unsigned int id; - if (!kernel_conn_control) + if (!has_kernel_features(KERNEL_CONN_CONTROL)) return; if (g_slist_find(adapter->connect_list, device)) { @@ -5147,7 +5142,7 @@ void adapter_set_device_wakeable(struct btd_adapter *adapter, const bdaddr_t *bdaddr; uint8_t bdaddr_type; - if (!kernel_conn_control) + if (!has_kernel_features(KERNEL_CONN_CONTROL)) return; bdaddr = device_get_address(device); @@ -5224,7 +5219,7 @@ void adapter_auto_connect_remove(struct btd_adapter *adapter, uint8_t bdaddr_type; unsigned int id; - if (!kernel_conn_control) + if (!has_kernel_features(KERNEL_CONN_CONTROL)) return; if (!g_slist_find(adapter->connect_list, device)) { @@ -6764,7 +6759,7 @@ connect_le: * If kernel background scan is used then the kernel is * responsible for connecting. */ - if (kernel_conn_control) + if (has_kernel_features(KERNEL_CONN_CONTROL)) return; /* @@ -8964,7 +8959,7 @@ static int clear_devices(struct btd_adapter *adapter) { struct mgmt_cp_remove_device cp; - if (!kernel_conn_control) + if (!has_kernel_features(KERNEL_CONN_CONTROL)) return 0; memset(&cp, 0, sizeof(cp)); @@ -9282,7 +9277,7 @@ static void read_info_complete(uint8_t status, uint16_t length, (missing_settings & MGMT_SETTING_FAST_CONNECTABLE)) set_mode(adapter, MGMT_OP_SET_FAST_CONNECTABLE, 0x01); - if (kernel_exp_features) + if (has_kernel_features(KERNEL_EXP_FEATURES)) read_exp_features(adapter); err = adapter_register(adapter); @@ -9403,7 +9398,8 @@ static void read_info_complete(uint8_t status, uint16_t length, set_name(adapter, btd_adapter_get_name(adapter)); - if (kernel_blocked_keys_supported && !set_blocked_keys(adapter)) { + if (has_kernel_features(KERNEL_BLOCKED_KEYS_SUPPORTED) && + !set_blocked_keys(adapter)) { btd_error(adapter->dev_id, "Failed to set blocked keys for index %u", adapter->dev_id); @@ -9414,7 +9410,7 @@ static void read_info_complete(uint8_t status, uint16_t length, !(adapter->current_settings & MGMT_SETTING_BONDABLE)) set_mode(adapter, MGMT_OP_SET_BONDABLE, 0x01); - if (!kernel_conn_control) + if (!has_kernel_features(KERNEL_CONN_CONTROL)) set_mode(adapter, MGMT_OP_SET_CONNECTABLE, 0x01); else if (adapter->current_settings & MGMT_SETTING_CONNECTABLE) set_mode(adapter, MGMT_OP_SET_CONNECTABLE, 0x00); @@ -9590,19 +9586,19 @@ static void read_commands_complete(uint8_t status, uint16_t length, switch (op) { case MGMT_OP_ADD_DEVICE: DBG("enabling kernel-side connection control"); - kernel_conn_control = true; + kernel_features |= KERNEL_CONN_CONTROL; break; case MGMT_OP_SET_BLOCKED_KEYS: DBG("kernel supports the set_blocked_keys op"); - kernel_blocked_keys_supported = true; + kernel_features |= KERNEL_BLOCKED_KEYS_SUPPORTED; break; case MGMT_OP_SET_DEF_SYSTEM_CONFIG: DBG("kernel supports set system confic"); - kernel_set_system_config = true; + kernel_features |= KERNEL_SET_SYSTEM_CONFIG; break; case MGMT_OP_READ_EXP_FEATURES_INFO: DBG("kernel supports exp features"); - kernel_exp_features = true; + kernel_features |= KERNEL_EXP_FEATURES; break; default: break; @@ -9768,3 +9764,8 @@ bool btd_le_connect_before_pairing(void) return false; } + +bool has_kernel_features(uint32_t features) +{ + return (kernel_features & features); +} diff --git a/src/adapter.h b/src/adapter.h index f8ac20261..b0ed4915f 100644 --- a/src/adapter.h +++ b/src/adapter.h @@ -233,3 +233,12 @@ void btd_adapter_for_each_device(struct btd_adapter *adapter, void *data); bool btd_le_connect_before_pairing(void); + +enum kernel_features { + KERNEL_CONN_CONTROL = 1 << 0, + KERNEL_BLOCKED_KEYS_SUPPORTED = 1 << 1, + KERNEL_SET_SYSTEM_CONFIG = 1 << 2, + KERNEL_EXP_FEATURES = 1 << 3, +}; + +bool has_kernel_features(uint32_t feature); From patchwork Tue Sep 15 17:41:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abhishek Pandit-Subedi X-Patchwork-Id: 252732 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F3B2DC43461 for ; Tue, 15 Sep 2020 17:43:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 943B321974 for ; Tue, 15 Sep 2020 17:43:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="OLQmmhyk" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727881AbgIORnY (ORCPT ); Tue, 15 Sep 2020 13:43:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727962AbgIORmA (ORCPT ); Tue, 15 Sep 2020 13:42:00 -0400 Received: from mail-pj1-x1043.google.com (mail-pj1-x1043.google.com [IPv6:2607:f8b0:4864:20::1043]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB10AC06178B for ; Tue, 15 Sep 2020 10:41:59 -0700 (PDT) Received: by mail-pj1-x1043.google.com with SMTP id a9so169573pjg.1 for ; Tue, 15 Sep 2020 10:41:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=etTtXFZ+lu630ZAqLK4CGu9TZoeAs1sQTeV8Ne2d0us=; b=OLQmmhykEbiDObMY6ZoX0TLRp1ikCpRQyFIyK1sjIC0ENWMNyGSUAxdt+OD97awO3+ 6YKkwfzsOP2C5Q18SyYf0T8YUUOAxj+g4zbJ5rStZUVB8g/TCbbSRHTR1MNG4Lw9h3eG Q9XkScCXCbLPD0sRs7YQEysLZLNHya8dG2vdg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=etTtXFZ+lu630ZAqLK4CGu9TZoeAs1sQTeV8Ne2d0us=; b=Wtot8YXLdN29U1UvlsTtXAJwaKoW4NJEeQStue0bkhFXjEnLDq00dpsasPMQHCx3wJ nuB+U76hB7kos1t23Q+H1cACHsjJpVTFufO9R2z2p/2ryOuzRFDJrjqm1XWpcnmDt6YC jdo7xgicp2KSWNbh1TUnQJhKoh5TLDYZgQQme3MEqPhydTTfwLIZcSrMxcgEHRT7juhN KdQCPFlyz/taxOL1K7qUvCq7qjSvuWMXG+IvJDGad0FtTbjgiQ9u/LC/3EnLVi3AwPBJ ukRIujWIZs6hZEXUzQXDMCDcCfVKkHTtsk+pB4MG5WOsurVvIBGtYyRU1GCHltIaJRxA 7JnA== X-Gm-Message-State: AOAM531IlYzcvUkum+GEw35AGV7lwd1sop1kAxQEdD7tMykdGYiQPKBw EHXmwSU/T4mwjsNmJqCdF3wKOQ== X-Google-Smtp-Source: ABdhPJy67haYqzSnqDJzk9iacHskFZpn5BMblVFqIjsigk+6rRYwzns2rmgFVA5iCQcPxWU4wrtgAA== X-Received: by 2002:a17:90a:dd46:: with SMTP id u6mr456402pjv.67.1600191719475; Tue, 15 Sep 2020 10:41:59 -0700 (PDT) Received: from apsdesk.mtv.corp.google.com ([2620:15c:202:1:7220:84ff:fe09:2b94]) by smtp.gmail.com with ESMTPSA id y29sm15490232pfq.207.2020.09.15.10.41.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Sep 2020 10:41:58 -0700 (PDT) From: Abhishek Pandit-Subedi To: luiz.dentz@gmail.com, marcel@holtmann.org Cc: chromeos-bluetooth-upstreaming@chromium.org, linux-bluetooth@vger.kernel.org, Abhishek Pandit-Subedi Subject: [Bluez PATCH v5 3/4] policy: Enable reconnect for a2dp-sink in defaults Date: Tue, 15 Sep 2020 10:41:45 -0700 Message-Id: <20200915104127.Bluez.v5.3.Ic87c0fbb00fe76356cee8f78a82b29a47fc6d438@changeid> X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog In-Reply-To: <20200915174146.1693687-1-abhishekpandit@chromium.org> References: <20200915174146.1693687-1-abhishekpandit@chromium.org> MIME-Version: 1.0 Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Add a2dp-sink to default reconnects list. --- Changes in v5: None Changes in v4: None Changes in v3: None Changes in v2: None plugins/policy.c | 3 ++- src/main.conf | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/policy.c b/plugins/policy.c index de51e58b9..c18ca8d1f 100644 --- a/plugins/policy.c +++ b/plugins/policy.c @@ -65,7 +65,8 @@ struct reconnect_data { }; static const char *default_reconnect[] = { - HSP_AG_UUID, HFP_AG_UUID, A2DP_SOURCE_UUID, NULL }; + HSP_AG_UUID, HFP_AG_UUID, A2DP_SOURCE_UUID, + A2DP_SINK_UUID, NULL }; static char **reconnect_uuids = NULL; static const size_t default_attempts = 7; diff --git a/src/main.conf b/src/main.conf index 42f7e41c5..e1d77cc47 100644 --- a/src/main.conf +++ b/src/main.conf @@ -186,7 +186,7 @@ # timeout). The policy plugin should contain a sane set of values by # default, but this list can be overridden here. By setting the list to # empty the reconnection feature gets disabled. -#ReconnectUUIDs=00001112-0000-1000-8000-00805f9b34fb,0000111f-0000-1000-8000-00805f9b34fb,0000110a-0000-1000-8000-00805f9b34fb +#ReconnectUUIDs=00001112-0000-1000-8000-00805f9b34fb,0000111f-0000-1000-8000-00805f9b34fb,0000110a-0000-1000-8000-00805f9b34fb,0000110b-0000-1000-8000-00805f9b34fb # ReconnectAttempts define the number of attempts to reconnect after a link # lost. Setting the value to 0 disables reconnecting feature. From patchwork Tue Sep 15 17:41:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Abhishek Pandit-Subedi X-Patchwork-Id: 252733 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3CD6EC433E2 for ; Tue, 15 Sep 2020 17:42:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DD77D208E4 for ; Tue, 15 Sep 2020 17:42:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="Nysth9fd" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727937AbgIORmX (ORCPT ); Tue, 15 Sep 2020 13:42:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727966AbgIORmB (ORCPT ); Tue, 15 Sep 2020 13:42:01 -0400 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18DDBC06178C for ; Tue, 15 Sep 2020 10:42:01 -0700 (PDT) Received: by mail-pf1-x444.google.com with SMTP id o20so2345398pfp.11 for ; Tue, 15 Sep 2020 10:42:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1Lb3TTPN31sY7TtlFDspcb6ha7dyHPbWFWNXvetWXH4=; b=Nysth9fd/ZV6IC4NHMhMej61IFXdbe2fQXQBsN40g28Lf2dOBUSoGAYX1ci0mia8Xv Ogg5au63B8NiuDT889dycIMGI+5KI/H6tSDNhhtDkeBcEF4Ti0kbdJVkbYvbyakcNJ3k vvJpJtkQQDeSKU4nFqG2PYe+JoYQ11EsQwETk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1Lb3TTPN31sY7TtlFDspcb6ha7dyHPbWFWNXvetWXH4=; b=hGtPyXb7+yMEYnx1EDQX9ztYd9zkvouqfm6x48X9cz27LHWubeA9eEcNYkyD3JhBzU jDDuleNATZZVrsB7OPWAxC4SH+3FHZvBmspIbddztz3qs6mEew+ZzMYbOZTj/b4xLtgW Q7nw9qiJtwogvWB1we5pVRIm8CWBJh18r3liZWgJStGtN1kYoLO5/k3/nuTBJWxCe2aO PuZ5JVkptxaLsGeY6HWp5ZTRK/5yaYzgl66mSnNwg43EWrUIoFMvpsvj8boe7quRRjQA yZRU+ScSq0iF4+yvRqObJHYaQkuNQ1m9kZdsHx5ltku5eH8q38RrIVLsxrQ2bt7huRLl KXZw== X-Gm-Message-State: AOAM532Rg1quqjbDKEFajNoM7IWZdxnWD3lC48emM91rOaYdV+SkyJic ku6uFRBcT8IikgxXftSZ9ioiJg== X-Google-Smtp-Source: ABdhPJySXv6MhYQq8gmSLar8/L0BArCo0bDPe8Fe04nb+Z5EY51eLuDgXS//A4YMvD3gcaGzKD+h+w== X-Received: by 2002:a63:2bd1:: with SMTP id r200mr15353887pgr.20.1600191720565; Tue, 15 Sep 2020 10:42:00 -0700 (PDT) Received: from apsdesk.mtv.corp.google.com ([2620:15c:202:1:7220:84ff:fe09:2b94]) by smtp.gmail.com with ESMTPSA id y29sm15490232pfq.207.2020.09.15.10.41.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Sep 2020 10:42:00 -0700 (PDT) From: Abhishek Pandit-Subedi To: luiz.dentz@gmail.com, marcel@holtmann.org Cc: chromeos-bluetooth-upstreaming@chromium.org, linux-bluetooth@vger.kernel.org, Abhishek Pandit-Subedi Subject: [Bluez PATCH v5 4/4] policy: Reconnect audio on controller resume Date: Tue, 15 Sep 2020 10:41:46 -0700 Message-Id: <20200915104127.Bluez.v5.4.I26efd89de3a70af1cd9775d457d0c10f4aafd4cb@changeid> X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog In-Reply-To: <20200915174146.1693687-1-abhishekpandit@chromium.org> References: <20200915174146.1693687-1-abhishekpandit@chromium.org> MIME-Version: 1.0 Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org During system suspend, all peer devices are disconnected. On resume, HID devices will reconnect but audio devices stay disconnected. As a quality of life improvement, mark audio devices that were disconnected due to suspend and attempt to reconnect them when the controller resumes (after a delay for better co-existence with Wi-Fi). --- Changes in v5: None Changes in v4: - Set reconnect timer in disconnect if resume events aren't supported - Only set reconnect timer if adapter matches current notification - Refactor changes in src/adapter to its own commit - Refactor enabling A2DP_SINK_UUID into its own commit Changes in v3: - Refactored resume notification to use btd_adapter_driver - Renamed ReconnectAudioDelay to ResumeDelay and set default to 2 - Added A2DP_SINK_UUID to default reconnect list Changes in v2: - Refactored to use policy instead of connecting directly in adapter plugins/policy.c | 84 ++++++++++++++++++++++++++++++++++++++++-------- src/main.c | 1 + src/main.conf | 9 ++++++ 3 files changed, 81 insertions(+), 13 deletions(-) diff --git a/plugins/policy.c b/plugins/policy.c index c18ca8d1f..6bd389518 100644 --- a/plugins/policy.c +++ b/plugins/policy.c @@ -62,6 +62,7 @@ struct reconnect_data { guint timer; bool active; unsigned int attempt; + bool on_resume; }; static const char *default_reconnect[] = { @@ -76,6 +77,9 @@ static const int default_intervals[] = { 1, 2, 4, 8, 16, 32, 64 }; static int *reconnect_intervals = NULL; static size_t reconnect_intervals_len = 0; +static const int default_resume_delay = 2; +static int resume_delay; + static GSList *reconnects = NULL; static unsigned int service_id = 0; @@ -712,6 +716,9 @@ static gboolean reconnect_timeout(gpointer data) /* Mark the GSource as invalid */ reconnect->timer = 0; + /* Mark any reconnect on resume as handled */ + reconnect->on_resume = false; + err = btd_device_connect_services(reconnect->dev, reconnect->services); if (err < 0) { error("Reconnecting services failed: %s (%d)", @@ -725,14 +732,17 @@ static gboolean reconnect_timeout(gpointer data) return FALSE; } -static void reconnect_set_timer(struct reconnect_data *reconnect) +static void reconnect_set_timer(struct reconnect_data *reconnect, int timeout) { - static int timeout = 0; + static int interval_timeout = 0; reconnect->active = true; if (reconnect->attempt < reconnect_intervals_len) - timeout = reconnect_intervals[reconnect->attempt]; + interval_timeout = reconnect_intervals[reconnect->attempt]; + + if (timeout < 0) + timeout = interval_timeout; DBG("attempt %u/%zu %d seconds", reconnect->attempt + 1, reconnect_attempts, timeout); @@ -744,10 +754,14 @@ static void reconnect_set_timer(struct reconnect_data *reconnect) static void disconnect_cb(struct btd_device *dev, uint8_t reason) { struct reconnect_data *reconnect; + struct btd_service *service; + struct policy_data *data; DBG("reason %u", reason); - if (reason != MGMT_DEV_DISCONN_TIMEOUT) + /* Only attempt reconnect for the following reasons */ + if (reason != MGMT_DEV_DISCONN_TIMEOUT && + reason != MGMT_DEV_DISCONN_LOCAL_HOST_SUSPEND) return; reconnect = reconnect_find(dev); @@ -756,10 +770,47 @@ static void disconnect_cb(struct btd_device *dev, uint8_t reason) reconnect_reset(reconnect); - DBG("Device %s identified for auto-reconnection", - device_get_path(dev)); + DBG("Device %s identified for auto-reconnection", device_get_path(dev)); + + switch(reason) + { + case MGMT_DEV_DISCONN_LOCAL_HOST_SUSPEND: + if (btd_device_get_service(dev, A2DP_SINK_UUID)) { + DBG("%s configured to reconnect on resume", + device_get_path(dev)); - reconnect_set_timer(reconnect); + reconnect->on_resume = true; + + /* If the kernel supports resume events, it is + * preferable to set the reconnect timer there as it is + * a more predictable delay. + */ + if (!has_kernel_features(KERNEL_HAS_RESUME_EVT)) + reconnect_set_timer(reconnect, resume_delay); + } + break; + case MGMT_DEV_DISCONN_TIMEOUT: + reconnect_set_timer(reconnect, -1); + break; + default: + DBG("Developer error. Reason = %d", reason); + break; + } +} + +static void policy_adapter_resume(struct btd_adapter *adapter) +{ + GSList *l; + + /* Check if devices on this adapter need to be reconnected on resume */ + for (l = reconnects; l; l = g_slist_next(l)) { + struct reconnect_data *reconnect = l->data; + + if (reconnect->on_resume && + device_get_adapter(reconnect->dev) == adapter) { + reconnect_set_timer(reconnect, resume_delay); + } + } } static void conn_fail_cb(struct btd_device *dev, uint8_t status) @@ -787,14 +838,15 @@ static void conn_fail_cb(struct btd_device *dev, uint8_t status) return; } - reconnect_set_timer(reconnect); + reconnect_set_timer(reconnect, -1); } static int policy_adapter_probe(struct btd_adapter *adapter) { DBG(""); - btd_adapter_restore_powered(adapter); + if (auto_enable) + btd_adapter_restore_powered(adapter); return 0; } @@ -802,6 +854,7 @@ static int policy_adapter_probe(struct btd_adapter *adapter) static struct btd_adapter_driver policy_driver = { .name = "policy", .probe = policy_adapter_probe, + .resume = policy_adapter_resume, }; static int policy_init(void) @@ -855,14 +908,20 @@ static int policy_init(void) auto_enable = g_key_file_get_boolean(conf, "Policy", "AutoEnable", NULL); + resume_delay = g_key_file_get_integer( + conf, "Policy", "ResumeDelay", &gerr); + + if (gerr) { + g_clear_error(&gerr); + resume_delay = default_resume_delay; + } done: if (reconnect_uuids && reconnect_uuids[0] && reconnect_attempts) { btd_add_disconnect_cb(disconnect_cb); btd_add_conn_fail_cb(conn_fail_cb); } - if (auto_enable) - btd_register_adapter_driver(&policy_driver); + btd_register_adapter_driver(&policy_driver); return 0; } @@ -883,8 +942,7 @@ static void policy_exit(void) btd_service_remove_state_cb(service_id); - if (auto_enable) - btd_unregister_adapter_driver(&policy_driver); + btd_unregister_adapter_driver(&policy_driver); } BLUETOOTH_PLUGIN_DEFINE(policy, VERSION, BLUETOOTH_PLUGIN_PRIORITY_DEFAULT, diff --git a/src/main.c b/src/main.c index b37c32948..038f867b5 100644 --- a/src/main.c +++ b/src/main.c @@ -131,6 +131,7 @@ static const char *policy_options[] = { "ReconnectAttempts", "ReconnectIntervals", "AutoEnable", + "ResumeDelay", NULL }; diff --git a/src/main.conf b/src/main.conf index e1d77cc47..9f882e65a 100644 --- a/src/main.conf +++ b/src/main.conf @@ -202,3 +202,12 @@ # This includes adapters present on start as well as adapters that are plugged # in later on. Defaults to 'false'. #AutoEnable=false + +# Audio devices that were disconnected due to suspend will be reconnected on +# resume. ResumeDelay determines the delay between when the controller +# resumes from suspend and a connection attempt is made. A longer delay is +# better for better co-existence with Wi-Fi. +# The value is in seconds. +# Default: 2 +#ResumeDelay = 2 +