From patchwork Fri Jun 19 22:56:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Sun X-Patchwork-Id: 11615303 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 18F38913 for ; Fri, 19 Jun 2020 22:56:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0158122400 for ; Fri, 19 Jun 2020 22:56:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="hMfnMWNM" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729887AbgFSW4l (ORCPT ); Fri, 19 Jun 2020 18:56:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729852AbgFSW4k (ORCPT ); Fri, 19 Jun 2020 18:56:40 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C789DC06174E for ; Fri, 19 Jun 2020 15:56:40 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id c17so11721197ybf.7 for ; Fri, 19 Jun 2020 15:56:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc:content-transfer-encoding; bh=A1e11u7HNsaVCh/raWH9GxHfgJx+PWPc1jfYmJ1V0lU=; b=hMfnMWNMn27o2KaghyB1Z3B5n6jw2ENw+Typiktn6Ixmu//Ez7uOwtzHX1z0GISlmD DLlS/BDIY4FUxftFHmY+Cbu4L7Aae+E0ZPr574JkhZJAtJGR4H5v8zX0tYnQLApbWr3o OeezGvsIqaHgF5pmMsB8HrWPRNRaEUBg2jlRuzjfXRRCtmRxqyGf6KSfgoV0TIZGghGd eEqTkhpqRJ5Ls31Qho1DtS0tgrL0fwcg1oKqUCZsOKMljQs712bD2iHmVHM7dUYX4v1Y FzVh699kkGBpHQhyuLod2CXgX1q+oQ2K9YGeGzXL9ZlL7weoBs70qT/C87dlz9l67h5l d3FQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc:content-transfer-encoding; bh=A1e11u7HNsaVCh/raWH9GxHfgJx+PWPc1jfYmJ1V0lU=; b=OrJiuN2W1M9G+6Bt7umZTnNt1YqwEsRg5mjV16iXdFL0IklZP5cLcqLp2XFZLrBHHV Eywyde7ZhlvE7OhzZp9bdWkWjjRvO7iS3tniqQZ7S16geqvhUt4hDWZx7WN0MM3RLyCy iRYFoD4hFk/bPlvE2Axd5HhINjPUksR3/NsGCL5+Yus27uWo4tyq9uwPIVQPmEz1mZwb shldMDI8mdK+igaQzJ4ZxrA4pbvTLFDjUtqZwcLcRz+ndJ9nn6Bn5aNbQeMVdSGw8P74 RdVghawjjFT1PqmaBCT6rnFSAyQEsK8H9SfMNakxEvAjPBeZX4ZDOu7OILe/hHf6bFO4 eC9w== X-Gm-Message-State: AOAM532eeenpZcCwE7imWxrJpqCmem/xKFMIFMhjhaLfE09gK0Whou43 PkJthno9edPOoA7EKsmzCyJkDwta4c5OfX5V4733trsnYmybltNcsdlQ7Ju0cKvOEqx7q7JWdd0 O1h4Dmg00FBXxCISITbUxQOX5pExv7+Q10GXki9HLFqmlG1b5LeF9rFO1THgqCySwIgmoxqWLx+ pBx+eIiVaoVRI= X-Google-Smtp-Source: ABdhPJwTmInh8CdMqD6XeoH2v/heJNj9oPacoqlSfUuDbSBCDk4j+9WD4IsBIoLaL5yhvSFZIhN4FO+SVDqLtG9I7w== X-Received: by 2002:a25:32d1:: with SMTP id y200mr10090665yby.507.1592607400013; Fri, 19 Jun 2020 15:56:40 -0700 (PDT) Date: Fri, 19 Jun 2020 15:56:22 -0700 In-Reply-To: <20200619225623.10200-1-michaelfsun@google.com> Message-Id: <20200619155612.bluez.v4.2.Ib8ae2d78936aa9f16a318aca14cf8c7198449bac@changeid> Mime-Version: 1.0 References: <20200619225623.10200-1-michaelfsun@google.com> X-Mailer: git-send-email 2.27.0.111.gc72c7da667-goog Subject: [bluez PATCH v4 2/3] btmgmt: Add command "remove" into "monitor" btmgmt submenu From: Michael Sun To: linux-bluetooth@vger.kernel.org Cc: luiz.von.dentz@intel.com, mcchou@chromium.org, chromeos-bluetooth-upstreaming@chromium.org, alainm@chromium.org, Michael Sun Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This patch introduces a new btmgmt command ‘remove’ wihtin "monitor" submenu to allow users to remove previously added filters along with a event handler to handle kernel issued MGMT_EV_ADV_MONITOR_REMOVED event. The command will work with the new MGMT opcode MGMT_OP_REMOVE_ADV_MONITOR. Tested on Atlas Chromebook with a sample stdout below: [mgmt]# remove 1 Advertisement monitor with handle: 0x0001 removed [mgmt]# remove 1234 Could not remove advertisement monitor with status 0x11 (Invalid Index) Reviewed-by: Miao-chen Chou Signed-off-by: Michael Sun --- Changes in v4: - Fix endianness Changes in v3: None Changes in v2: - Move remove command into submenu and fix build warnings tools/btmgmt.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/tools/btmgmt.c b/tools/btmgmt.c index f50d29651346..1c46041ccb18 100644 --- a/tools/btmgmt.c +++ b/tools/btmgmt.c @@ -1013,6 +1013,20 @@ static void advertising_removed(uint16_t index, uint16_t len, print("hci%u advertising_removed: instance %u", index, ev->instance); } +static void advmon_removed(uint16_t index, uint16_t len, const void *param, + void *user_data) +{ + const struct mgmt_ev_adv_monitor_removed *ev = param; + + if (len < sizeof(*ev)) { + error("Too small (%u bytes) %s event", len, __func__); + return; + } + + print("hci%u %s: handle %u", index, __func__, + le16_to_cpu(ev->monitor_handle)); +} + static void version_rsp(uint8_t status, uint16_t len, const void *param, void *user_data) { @@ -4644,6 +4658,44 @@ static void cmd_advmon_features(int argc, char **argv) } } +static void advmon_remove_rsp(uint8_t status, uint16_t len, const void *param, + void *user_data) +{ + const struct mgmt_rp_remove_adv_monitor *rp = param; + + if (status != MGMT_STATUS_SUCCESS) { + error("Could not remove advertisement monitor with status " + "0x%02x (%s)", status, mgmt_errstr(status)); + return bt_shell_noninteractive_quit(EXIT_FAILURE); + } + + print("Advertisement monitor with handle: 0x%04x removed", + le16_to_cpu(rp->monitor_handle)); + return bt_shell_noninteractive_quit(EXIT_SUCCESS); +} + +static void cmd_advmon_remove(int argc, char **argv) +{ + struct mgmt_cp_remove_adv_monitor cp; + uint16_t index, monitor_handle; + + index = mgmt_index; + if (index == MGMT_INDEX_NONE) + index = 0; + + if (sscanf(argv[1], "%hx", &monitor_handle) != 1) { + error("Wrong formatted handle argument"); + return bt_shell_noninteractive_quit(EXIT_FAILURE); + } + + cp.monitor_handle = cpu_to_le16(monitor_handle); + if (mgmt_send(mgmt, MGMT_OP_REMOVE_ADV_MONITOR, index, sizeof(cp), &cp, + advmon_remove_rsp, NULL, NULL) == 0) { + error("Unable to send appearance cmd"); + return bt_shell_noninteractive_quit(EXIT_FAILURE); + } +} + static void register_mgmt_callbacks(struct mgmt *mgmt, uint16_t index) { mgmt_register(mgmt, MGMT_EV_CONTROLLER_ERROR, index, controller_error, @@ -4696,6 +4748,8 @@ static void register_mgmt_callbacks(struct mgmt *mgmt, uint16_t index) advertising_added, NULL, NULL); mgmt_register(mgmt, MGMT_EV_ADVERTISING_REMOVED, index, advertising_removed, NULL, NULL); + mgmt_register(mgmt, MGMT_EV_ADV_MONITOR_REMOVED, index, advmon_removed, + NULL, NULL); } static void cmd_select(int argc, char **argv) @@ -4719,6 +4773,8 @@ static const struct bt_shell_menu monitor_menu = { { "features", NULL, cmd_advmon_features, "Show advertisement monitor " "features" }, + { "remove", "", + cmd_advmon_remove, "Remove advertisement monitor " }, { } }, };