From patchwork Fri Jun 12 06:15:28 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: 11601275 X-Patchwork-Delegate: marcel@holtmann.org 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 AFD1A138C for ; Fri, 12 Jun 2020 06:16:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 92FFB208A7 for ; Fri, 12 Jun 2020 06:16:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="jonoUL05" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726610AbgFLGPv (ORCPT ); Fri, 12 Jun 2020 02:15:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726588AbgFLGPp (ORCPT ); Fri, 12 Jun 2020 02:15:45 -0400 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21EC7C08C5CA for ; Thu, 11 Jun 2020 23:15:44 -0700 (PDT) Received: by mail-pf1-x441.google.com with SMTP id s23so3824339pfh.7 for ; Thu, 11 Jun 2020 23:15:44 -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=bjVNlTYI+xsZXGbrReh494MpQ4GuctCPzPE7Z8G4kGo=; b=jonoUL05OOWkRW2SdfbUtpdSqOiXCoy97A+2NGpnmP6+KSMLgXuGuZ2/9YIfnvdfkr 8geTmvPuqLpSqNGvH3l2Aju2DtWynxz8WFcuOnhtepJsHqMkOc3Dncg7YYtnWmYkGln2 598lZiK9psitQuODC/o4+meHb4BJWv4vK9ahY= 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=bjVNlTYI+xsZXGbrReh494MpQ4GuctCPzPE7Z8G4kGo=; b=K9YETQ4wsCY/lFtZLfEJ1fSf7a4R9nwCoHn8vaVBx42jgSSeBIgCHZ3vJUm4xkVgN5 YdVdES3/ISbfnHrXx3B1go3D9kXe/QdaI8jAVtTByQfuUXORui9yB51WUe0lwBlWWoU2 eA9DAIiOSggv7nkFMmpgdhInZZ5bAu7DSXNur/rcS6OHaR/yl6fwwzRNRPyjXf5XsinS CozAppf8qz5dFq1J7uROTYJW0dgyvW+bt+hTYWd5fTbZFUe1wc7slKMUh6Si3ieN0QTr 6K5hJ38Iz6JOFw+7HBwAHkFGJriC2vxGhSNBILfB+8z854er1r/bcu3F8zzvbeWvkJe5 cTNg== X-Gm-Message-State: AOAM533wUjaGHSB3hZrgBMahRQRSGmB6ym9fZYL+GjX79hreZ/3IwtmA GQ9wNl+hUyV9lj6Eeupsk4d2dh5bYt0= X-Google-Smtp-Source: ABdhPJywuUy0Y8FI65nYI4VhXJozaQgFCors93AJxQUsFcAbuyyu8L7YDQdq63RFawWhuL4UAaXyMw== X-Received: by 2002:a63:a50:: with SMTP id z16mr9387214pgk.162.1591942543479; Thu, 11 Jun 2020 23:15:43 -0700 (PDT) Received: from mcchou0.mtv.corp.google.com ([2620:15c:202:201:b46:ac84:1014:9555]) by smtp.gmail.com with ESMTPSA id g6sm4933923pfb.164.2020.06.11.23.15.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Jun 2020 23:15:43 -0700 (PDT) From: Miao-chen Chou To: Bluetooth Kernel Mailing List Cc: Marcel Holtmann , Luiz Augusto von Dentz , Alain Michaud , Michael Sun , Yoni Shavit , Miao-chen Chou , "David S. Miller" , Jakub Kicinski , Johan Hedberg , linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v3 6/7] Bluetooth: Notify adv monitor removed event Date: Thu, 11 Jun 2020 23:15:28 -0700 Message-Id: <20200611231459.v3.6.If1a82f71eb63f969de3d5a5da03c2908b58a721a@changeid> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200611231459.v3.1.I636f906bf8122855dfd2ba636352bbdcb50c35ed@changeid> References: <20200611231459.v3.1.I636f906bf8122855dfd2ba636352bbdcb50c35ed@changeid> MIME-Version: 1.0 Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This notifies management sockets on MGMT_EV_ADV_MONITOR_REMOVED event. The following test was performed. - Start two btmgmt consoles, issue a btmgmt advmon-remove command on one console and observe a MGMT_EV_ADV_MONITOR_REMOVED event on the other. Signed-off-by: Miao-chen Chou --- Changes in v3: - Convert the endianness of the returned handle. Changes in v2: None net/bluetooth/mgmt.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c index 949964862c1b6..03cd0efd987ae 100644 --- a/net/bluetooth/mgmt.c +++ b/net/bluetooth/mgmt.c @@ -156,6 +156,7 @@ static const u16 mgmt_events[] = { MGMT_EV_PHY_CONFIGURATION_CHANGED, MGMT_EV_EXP_FEATURE_CHANGED, MGMT_EV_ADV_MONITOR_ADDED, + MGMT_EV_ADV_MONITOR_REMOVED, }; static const u16 mgmt_untrusted_commands[] = { @@ -3864,6 +3865,16 @@ static void mgmt_adv_monitor_added(struct sock *sk, struct hci_dev *hdev, mgmt_event(MGMT_EV_ADV_MONITOR_ADDED, hdev, &ev, sizeof(ev), sk); } +static void mgmt_adv_monitor_removed(struct sock *sk, struct hci_dev *hdev, + u16 handle) +{ + struct mgmt_ev_adv_monitor_added ev; + + ev.monitor_handle = cpu_to_le16(handle); + + mgmt_event(MGMT_EV_ADV_MONITOR_REMOVED, hdev, &ev, sizeof(ev), sk); +} + static int read_adv_monitor_features(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) { @@ -4016,12 +4027,15 @@ static int remove_adv_monitor(struct sock *sk, struct hci_dev *hdev, { struct mgmt_cp_remove_adv_monitor *cp = data; struct mgmt_rp_remove_adv_monitor rp; + unsigned int prev_adv_monitors_cnt; int err; BT_DBG("request for %s", hdev->name); hci_dev_lock(hdev); + prev_adv_monitors_cnt = hdev->adv_monitors_cnt; + err = hci_remove_adv_monitor(hdev, cp->monitor_handle); if (err == -ENOENT) { err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_REMOVE_ADV_MONITOR, @@ -4029,6 +4043,9 @@ static int remove_adv_monitor(struct sock *sk, struct hci_dev *hdev, goto unlock; } + if (hdev->adv_monitors_cnt < prev_adv_monitors_cnt) + mgmt_adv_monitor_removed(sk, hdev, cp->monitor_handle); + hci_dev_unlock(hdev); rp.monitor_handle = cpu_to_le16(cp->monitor_handle);