From patchwork Thu May 28 23:54:53 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: 196968 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=-9.9 required=3.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=unavailable 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 A5516C433E0 for ; Thu, 28 May 2020 23:55:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7E16C206DF for ; Thu, 28 May 2020 23:55:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="UrA0iTOg" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2437897AbgE1Xz2 (ORCPT ); Thu, 28 May 2020 19:55:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2437692AbgE1XzY (ORCPT ); Thu, 28 May 2020 19:55:24 -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 3F0CBC0A88B4 for ; Thu, 28 May 2020 16:55:23 -0700 (PDT) Received: by mail-pf1-x441.google.com with SMTP id y198so263827pfb.4 for ; Thu, 28 May 2020 16:55:23 -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=LSWv1a2AYReRskzQvhkBjb0iSRTTIV4DxJjMfd48OhE=; b=UrA0iTOg50gC1alITZzEJ6olAVG678EysBccbqjAu151WV3kA2E3Ic4n3xREiYuk7Q nX4GVIdLj0wIn8TQgeDfk7HxT+1NtiLAI3znKquhbXuQHdnKLBpjXN9GXm+Ts9xpEwxh APYzmKkvevneVIammCUCUjT9n+jC20Q1RR8W0= 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=LSWv1a2AYReRskzQvhkBjb0iSRTTIV4DxJjMfd48OhE=; b=dZQf90gFVYR2EE/j3j2C5LUC+bgmZIf2biPDGnXApsTdyT58PwlfL+Us/0Pg2qkJ4R AhCMHfp3NmhrpSVpP3m+hvA9w8zv4PblADCa/dlbD9K+g6LPsfz8FElRZNZQo0BgyUHv yxZ/LA1dGW7Apu+DhbWK45DuLDfXHQqJ8q4BWkPsjP4n4BL+/2A2bPPCE42wHwNObouo 3rB39cz5qWtTj9qdxR2Wznyk+ZUEwAEOJYo4Hm58d8igHLRD4+t/aKDRWCU8Blh1BgUF +Q4TIMk4ze8+GC28Xr9Gfluolab3N9H0PEUysRwfIHsMLZ7GBVnh9zF/9MBf+dFhj6LL IoHQ== X-Gm-Message-State: AOAM531edm/ku02yM1r3cZuhjMT8MaSWCHZ5Q8OhOvuMQi1oc/t7m0UE +ngbf8gWP00nLEY41j/cLWSRrS5/mus= X-Google-Smtp-Source: ABdhPJwNtcpluriLpQr31e/YaMZi6+OJknFPwXzYeZEKpF/RvnoW5r+gNLrc1p9tmAMewkkq26eetw== X-Received: by 2002:a62:640b:: with SMTP id y11mr6032255pfb.318.1590710122085; Thu, 28 May 2020 16:55:22 -0700 (PDT) Received: from mcchou0.mtv.corp.google.com ([2620:15c:202:201:b46:ac84:1014:9555]) by smtp.gmail.com with ESMTPSA id f18sm5022591pga.75.2020.05.28.16.55.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 May 2020 16:55:21 -0700 (PDT) From: Miao-chen Chou To: Bluetooth Kernel Mailing List Cc: Alain Michaud , Marcel Holtmann , Manish Mandlik , Luiz Augusto von Dentz , Yoni Shavit , Michael Sun , Miao-chen Chou , "David S. Miller" , Jakub Kicinski , Johan Hedberg , linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v1 5/7] Bluetooth: Notify adv monitor added event Date: Thu, 28 May 2020 16:54:53 -0700 Message-Id: <20200528165324.v1.5.Idb2c6bf4deb8728c363c3938b1d33057e07ca9c9@changeid> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200528165324.v1.1.I636f906bf8122855dfd2ba636352bbdcb50c35ed@changeid> References: <20200528165324.v1.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_ADDED event. The following test was performed. - Start two btmgmt consoles, issue a btmgmt advmon-add command on one console and observe a MGMT_EV_ADV_MONITOR_ADDED event on the other Signed-off-by: Miao-chen Chou --- net/bluetooth/mgmt.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c index 710ec00219a0b..da65b6ab2e3a0 100644 --- a/net/bluetooth/mgmt.c +++ b/net/bluetooth/mgmt.c @@ -155,6 +155,7 @@ static const u16 mgmt_events[] = { MGMT_EV_EXT_INFO_CHANGED, MGMT_EV_PHY_CONFIGURATION_CHANGED, MGMT_EV_EXP_FEATURE_CHANGED, + MGMT_EV_ADV_MONITOR_ADDED, }; static const u16 mgmt_untrusted_commands[] = { @@ -3853,6 +3854,16 @@ static int set_exp_feature(struct sock *sk, struct hci_dev *hdev, MGMT_STATUS_NOT_SUPPORTED); } +static void mgmt_adv_monitor_added(struct sock *sk, struct hci_dev *hdev, + u16 handle) +{ + struct mgmt_ev_adv_monitor_added ev; + + ev.monitor_handle = handle; + + mgmt_event(MGMT_EV_ADV_MONITOR_ADDED, hdev, &ev, sizeof(ev), sk); +} + static int read_adv_monitor_features(struct sock *sk, struct hci_dev *hdev, void *data, u16 len) { @@ -3903,8 +3914,8 @@ static int add_adv_patterns_monitor(struct sock *sk, struct hci_dev *hdev, struct mgmt_rp_add_adv_patterns_monitor rp; struct adv_monitor *m = NULL; struct adv_pattern *p = NULL; + unsigned int mp_cnt = 0, prev_adv_monitors_cnt; __u8 cp_ofst = 0, cp_len = 0; - unsigned int mp_cnt = 0; int err, i; BT_DBG("request for %s", hdev->name); @@ -3968,6 +3979,8 @@ static int add_adv_patterns_monitor(struct sock *sk, struct hci_dev *hdev, hci_dev_lock(hdev); + prev_adv_monitors_cnt = hdev->adv_monitors_cnt; + err = hci_add_adv_monitor(hdev, m); if (err) { if (err == -ENOSPC) { @@ -3978,6 +3991,9 @@ static int add_adv_patterns_monitor(struct sock *sk, struct hci_dev *hdev, goto unlock; } + if (hdev->adv_monitors_cnt > prev_adv_monitors_cnt) + mgmt_adv_monitor_added(sk, hdev, m->handle); + hci_dev_unlock(hdev); rp.monitor_handle = m->handle;