From patchwork Fri Jun 12 23:45:54 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: 11602411 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 9B75490 for ; Fri, 12 Jun 2020 23:46:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7FA272078E for ; Fri, 12 Jun 2020 23:46:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="NGNurGt0" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726565AbgFLXqu (ORCPT ); Fri, 12 Jun 2020 19:46:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726479AbgFLXqW (ORCPT ); Fri, 12 Jun 2020 19:46:22 -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 CF1C4C08C5C4 for ; Fri, 12 Jun 2020 16:46:21 -0700 (PDT) Received: by mail-pf1-x441.google.com with SMTP id h185so5042220pfg.2 for ; Fri, 12 Jun 2020 16:46:21 -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=zMQlEqjqoacqpXZTlZ3YLpGiZUvYpLoVd15y+E+dpdQ=; b=NGNurGt0mvjvRu3TVbYjBlLXx7kZRBbxZcX1dx8qYHXbNnrnYAhK1jpSyzvbayiE51 jUT5N2RscL+lrZSHZJk+i16ZueP/MW9JbREooTiSQ3ucp7UJzAm3biN8+KjSQnGh4Eef Z6N/mWieGMRZ8vWqGv599Y1jTI2X0VQopk31Y= 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=zMQlEqjqoacqpXZTlZ3YLpGiZUvYpLoVd15y+E+dpdQ=; b=EoI9vvpzhW8Gf1N5vwlfq2nd3LY+u/8/Gk8bo7wdLMGCztHcM4rfRyzkGil0rYY5Pq PihDMRowE1aKVvLuywa7rBWi+5dw67SaDUh2BPNoADMqssE98xC+3CmBN4CoLB4QFRRr S9KNgY8QJH6bHHlODIcsXNWr3yZOZ/5CH/RsQfb/67swRvf/ZNwPvBn/obb4hZZcTBHL tjXrmSOh3QnXYjtkXQ4VjKRgVAwQSJUyN88wRxWBckiQjxjs3hRcN7spDn6kGSA68J8D obAn42U0YHqu9rb2K1ghBOGGxoVHUxqNLD6ZUrdVG84h1rI85ZSc4ev3teUcqW7TJK1Y FYig== X-Gm-Message-State: AOAM532zw6JodD0dHkY6HzfOynx/t7oCgquqzkWR5QAt061UYcgS4ptI s0P/Tt99uNjbC5IVHaRsuRFJd+JY4Eg= X-Google-Smtp-Source: ABdhPJwwI88y3KPf/uEawfB3t+HEZAdNVNlNRKE2cxEnE3yOADaWvv+z634q4m7eqFPim4FeU+hnzw== X-Received: by 2002:a63:c204:: with SMTP id b4mr12500068pgd.67.1592005580978; Fri, 12 Jun 2020 16:46:20 -0700 (PDT) Received: from mcchou0.mtv.corp.google.com ([2620:15c:202:201:b46:ac84:1014:9555]) by smtp.gmail.com with ESMTPSA id b19sm6198639pjo.57.2020.06.12.16.46.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Jun 2020 16:46:20 -0700 (PDT) From: Miao-chen Chou To: Bluetooth Kernel Mailing List Cc: Alain Michaud , Michael Sun , Marcel Holtmann , Yoni Shavit , Luiz Augusto von Dentz , Miao-chen Chou , "David S. Miller" , Jakub Kicinski , Johan Hedberg , linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH v4 5/7] Bluetooth: Notify adv monitor added event Date: Fri, 12 Jun 2020 16:45:54 -0700 Message-Id: <20200612164243.v4.5.Idb2c6bf4deb8728c363c3938b1d33057e07ca9c9@changeid> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200612164243.v4.1.I636f906bf8122855dfd2ba636352bbdcb50c35ed@changeid> References: <20200612164243.v4.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 --- Changes in v4: None Changes in v3: - Convert the endianness of the returned handle. Changes in v2: None 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 887e193ce0038..0a1e89ce75eae 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 = cpu_to_le16(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) { @@ -3905,8 +3916,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); @@ -3970,6 +3981,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) { @@ -3980,6 +3993,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 = cpu_to_le16(m->handle);