From patchwork Thu Sep 17 06:19:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miao-chen Chou X-Patchwork-Id: 252710 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, URIBL_BLOCKED, 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 67938C43461 for ; Thu, 17 Sep 2020 06:21:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 30CA121974 for ; Thu, 17 Sep 2020 06:21:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="JzMmoTcW" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726180AbgIQGVF (ORCPT ); Thu, 17 Sep 2020 02:21:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725267AbgIQGVA (ORCPT ); Thu, 17 Sep 2020 02:21:00 -0400 Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98B68C06174A for ; Wed, 16 Sep 2020 23:20:59 -0700 (PDT) Received: by mail-pj1-x1041.google.com with SMTP id gf14so687217pjb.5 for ; Wed, 16 Sep 2020 23:20: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=u+E1bUX0uVxPcQEsE71u1Ro0+1uBNDa00K7AzDVg6ww=; b=JzMmoTcWN8r9fSmiCYVyLPGHh/4yWvxDpYqk069/aA0JUhS+nsf6IGucPO3ltdzFJf jASugceVLWrXVfiKMemt1bQEDNMTQMYzcqxO9sljNItL71/ackDP1tql0loY1YvzdZ64 /6lCuBdKbw81qjgDCBt1Ma4YGQDcBXd8gt8RI= 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=u+E1bUX0uVxPcQEsE71u1Ro0+1uBNDa00K7AzDVg6ww=; b=GBKqUpsIqgmMz6hE7xKd1a1SUflt95085FsNLZKMd3LWIw41iEcu0O/o8+5EYUTBnb ne10RvCNadO/6k6WRYUb3L6safW6ISa9r/Do3BFPlqB4XtoguLehhsFnRueTVOztvEmr mw7vDvXQvoHD9Dzle48hODoGaeiEuBBdFnqJlvYtg58rRcfKsCMALJybQyrNw7DBmmGa akhDhVA5FjKTNw+QaxrssaYfn0D5BovkkO2xCTLElw6DRpmU33oeaoNGP1VqcY9N+t7q zd1wcKM8rai8OJxY7bPMqZiWNs5YV+9nQMiErJfdibYD9mjwTixplO9yPI19jKSj6uH5 pnlg== X-Gm-Message-State: AOAM532r4YpaUBrZVBW/Yz6IbZLBP3g7Wh2fOK569oQcJAXwvT7zdkV6 NXM3JaJp3yG6KMkH4mNRaBb7UVwULJyCbA== X-Google-Smtp-Source: ABdhPJxDipMIHXKpm3c6DmFyUw4IIzmnEx8rFamxqZGXE0sjF0YXtQziINFn+lAgKiCQcbITt0UhEg== X-Received: by 2002:a17:90a:297:: with SMTP id w23mr6897687pja.44.1600323658882; Wed, 16 Sep 2020 23:20:58 -0700 (PDT) Received: from mcchou0.mtv.corp.google.com ([2620:15c:202:201:de4a:3eff:fe75:1314]) by smtp.gmail.com with ESMTPSA id g23sm19264943pfh.133.2020.09.16.23.20.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 16 Sep 2020 23:20:58 -0700 (PDT) From: Miao-chen Chou To: Bluetooth Kernel Mailing List Cc: Marcel Holtmann , Howard Chung , Manish Mandlik , Alain Michaud , chromeos-bluetooth-upstreaming@chromium.org, Luiz Augusto von Dentz , Miao-chen Chou Subject: [BlueZ PATCH v2 5/8] adapter: Clear all Adv monitors upon bring-up Date: Wed, 16 Sep 2020 23:19:48 -0700 Message-Id: <20200916231935.BlueZ.v2.5.Id6bfe7838831ae01fddc8605689dd77b51673960@changeid> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200916231935.BlueZ.v2.1.I2830b9c1212a64b062201ed9f2b71294f50ad22d@changeid> References: <20200916231935.BlueZ.v2.1.I2830b9c1212a64b062201ed9f2b71294f50ad22d@changeid> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This clears all Adv monitors upon daemon bring-up by issuing MGMT_OP_REMOVE_ADV_MONITOR command with monitor_handle 0. The following test was performed: - Add an Adv Monitor using btmgmt, restart bluetoothd and observe the monitor got removed. Reviewed-by: Alain Michaud Reviewed-by: Manish Mandlik Reviewed-by: Howard Chung --- (no changes since v1) src/adapter.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/adapter.c b/src/adapter.c index d33ce7124..191467048 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -9513,6 +9513,43 @@ failed: btd_adapter_unref(adapter); } +static void reset_adv_monitors_complete(uint8_t status, uint16_t length, + const void *param, void *user_data) +{ + struct mgmt_rp_remove_adv_monitor *rp = param; + + if (status != MGMT_STATUS_SUCCESS) { + error("Failed to reset Adv Monitors: %s (0x%02x)", + mgmt_errstr(status), status); + return; + } + + if (length < sizeof(*rp)) { + error("Wrong size of remove Adv Monitor response for reset " + "all Adv Monitors"); + return; + } + + DBG("Removed all Adv Monitors"); +} + +static void reset_adv_monitors(uint16_t index) +{ + struct mgmt_cp_remove_adv_monitor cp; + + DBG("sending remove Adv Monitor command with handle 0"); + + /* Handle 0 indicates to remove all */ + cp.monitor_handle = 0; + if (mgmt_send(mgmt_master, MGMT_OP_REMOVE_ADV_MONITOR, index, + sizeof(cp), &cp, reset_adv_monitors_complete, NULL, + NULL) > 0) { + return; + } + + error("Failed to reset Adv Monitors"); +} + static void index_added(uint16_t index, uint16_t length, const void *param, void *user_data) { @@ -9527,6 +9564,8 @@ static void index_added(uint16_t index, uint16_t length, const void *param, return; } + reset_adv_monitors(index); + adapter = btd_adapter_new(index); if (!adapter) { btd_error(index,