From patchwork Fri Jun 12 06:15:27 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: 11601279 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 CC918138C for ; Fri, 12 Jun 2020 06:16:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B493E208A7 for ; Fri, 12 Jun 2020 06:16:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="exZ6gq4j" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726651AbgFLGQM (ORCPT ); Fri, 12 Jun 2020 02:16:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726561AbgFLGPn (ORCPT ); Fri, 12 Jun 2020 02:15:43 -0400 Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F1ABC03E96F for ; Thu, 11 Jun 2020 23:15:43 -0700 (PDT) Received: by mail-pl1-x644.google.com with SMTP id t7so3344690plr.0 for ; Thu, 11 Jun 2020 23:15:43 -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=B/AHWNUq2hQO+UxX262IRskqa77C3GfCCHKEkjol6ks=; b=exZ6gq4jica7r1Am4MijAZBEmoV17NqQcQgJBgDTB2O7D/eIFqcS+QBv09tg+lpoX4 4yo1vthRuvAuJoA+pjrPN3RhmCOry3XQAYhqxQqbsYkwnVGzXldC2S3UsDKayHHlOkkX zm716mYH2jX82WEfVBfoR6ixRw+Serj/6RX7w= 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=B/AHWNUq2hQO+UxX262IRskqa77C3GfCCHKEkjol6ks=; b=Aq4pIcgWptQ+pTOMNENjj/vf2lOoQFvv/aUqmz9CTNkxuiPBXvJwhg/jfrhP5P7sGM c75OulMKCXhOG4zHcmdZ/yL0W44v7MegDAaLa65hSlhLBJnGF5q3vf2+Imuc8muuPn9E tZOOfjQQJP43pEHycpkZn/ZaFRrqe3a0GoGGUF33eaiNhfogs6ghixOoBwG2JDMbMfQ9 fOy4Sm4XMt8847iQzE8+ArlWy3dBI6480/RPAQlHahG2T28CyBoAmwW5P3vw5sVKJfhN u+S9a7WSNvkmF/e5Llf26OZK7ViPwGPk0+fzjB9xJGbtUa37gMo+ZLDeF46uQVbgARHx OkZQ== X-Gm-Message-State: AOAM532J9vbZgDW7Y397eI5fGtU18sVV3XnUIxBCf4yHlRMfEbXM/zeR a79zgTFsPFJz9eF94c9wamBv5rdxxpU= X-Google-Smtp-Source: ABdhPJz8NU4IP8LCjEiHNcslLnkzsS225CV7pvoO8bQcuchT0N4rkCWqqcW8gUl2rbwYiD6sdOug/w== X-Received: by 2002:a17:902:7408:: with SMTP id g8mr9559400pll.143.1591942542347; Thu, 11 Jun 2020 23:15:42 -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.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Jun 2020 23:15:41 -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 5/7] Bluetooth: Notify adv monitor added event Date: Thu, 11 Jun 2020 23:15:27 -0700 Message-Id: <20200611231459.v3.5.Idb2c6bf4deb8728c363c3938b1d33057e07ca9c9@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_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 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 5dc47bba98a90..949964862c1b6 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);