Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1127721pxp; Sat, 12 Mar 2022 02:28:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJy1FiTPerwSNM8Qix7TnbBpL7RhvC9BGW5ii8tN/lJ6lG5A5FAVOJ0MtDNPvXQGByVIMjkT X-Received: by 2002:a50:aa8c:0:b0:410:801c:4e2f with SMTP id q12-20020a50aa8c000000b00410801c4e2fmr12226932edc.179.1647080921421; Sat, 12 Mar 2022 02:28:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1647080921; cv=none; d=google.com; s=arc-20160816; b=TyFv3aOJHGA495n3OSV6/PLbKfiBqOBWoHPa7fDNvt9j4gqqJ2D5sq9zz30r73uLDh ssWQcS8a1OwI4Oa/trAatzhV6sScPIdcMKjqJ9bBEC4nzoKtBWZ3Ybs2U2wHkNsdoDdC GTALYp2se+ARn/Md9FcWafvNKaTfEytpEWfle0g+XNAc1he17AWv7eKm8EVqiICegWbe DeMpjL0b+5Q0D8hseYD07FnZREL+nuaCxisjZksQEMbY+pr2o7hrfhFp5fl+oyESi+T/ Woi5ZjpPgDexlT7gLVqVvpUrbF++aAGKvzGZrhQp9uz/u+FLvmZuU92j8HVyXhwCFC+U rv7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=KYvhJwEqPqMacll2Nmd0cKWfMMmSrt6TYTGYVr6fAKo=; b=W+8rtmqzGkcnp1QYcpxfe6I/srgeyRcDpt92/+MSxmeUqHYdh6GVShHqw08QJXyWYO av8emOdLHtuFbnwHEtUqqVn9k/CUdWlXv4OyvDGDZA7s4fsAXmArgusSlcxPebpV7ANS j27yhU7njEV3xY8t6KYO3Q3pgX1Nueqp3aws+xPVpyaWL+Ihp0GWlGajvAobJuuCjRVM 1ArG8Kqm+g2YBFqVhEDDVjJYiAKx5M3FgSpoTuAprOm6k6FNw5y1vOBrH6Ct6cvKU8WU Epsk+5PsZO0/I5vWgndPgbXDNg2pUDkMI+2L7yQg13n/OxnAdxoI8ViQYqby0gJeX6Rg FDJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=J7927ySs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l19-20020a17090612d300b006db7533943esi5354777ejb.403.2022.03.12.02.28.16; Sat, 12 Mar 2022 02:28:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=J7927ySs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231600AbiCLKKb (ORCPT + 99 others); Sat, 12 Mar 2022 05:10:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231698AbiCLKKV (ORCPT ); Sat, 12 Mar 2022 05:10:21 -0500 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E9BC92272F0 for ; Sat, 12 Mar 2022 02:09:15 -0800 (PST) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-2d11b6259adso90235007b3.19 for ; Sat, 12 Mar 2022 02:09:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=KYvhJwEqPqMacll2Nmd0cKWfMMmSrt6TYTGYVr6fAKo=; b=J7927ySszHyeEQ7P3AfY7detl3yHPIjk9WdOIkUB8+zI2dkgItouavznSbYeg3NM+P SXANcpzXzr3G/7UmiTDBUm88mHvQp2aL2VATbxYYqV7D1DdBv5ZoxAQTX3Vs+qiW7I5B 4zV1G9DGOv7Mt5OkPAoI6c13wbFEgyatJJ7jtAUNK1V8jHkroNF6kmgknUSn+dt3gDTs F0+ynuPrf1nqKM8RahsoEZHKcR7VchM17ovI8tyUc3uTtPsGp+QbOc4cbu6frU1Qi06R EF0rKjFbynmwND6YkEz6lAcGwdMSRWh1R4fsqzk8M6SYRs/5P751Zaii0RPBZ3cSYrfO Y1Rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=KYvhJwEqPqMacll2Nmd0cKWfMMmSrt6TYTGYVr6fAKo=; b=MNfLkn66lm0TzyDm49jqPhL+Vi6FBnEVQ+/VbuXhQs3q4IlOFuM8TvauYst58sQSgV zqiHvsDRq1boN5z6oF/qmpyCY9QfI6hsVd+aXdNW5+SlsPKJxvPCjzisX4pDHY9m4yPb Ve0jlk5Rj4RvxUgBW/4n/1z5QiR1HwFz4TqQxGCfd6QkfsBTVkDVL/+xZkcTmivUUdU5 C1hp6pyrYFtkaJLxaDHUJ6yF4C4FckOvGb6/Lyysf3LcKWFP0AI4xF3vvdrmJcB/1Obh av+mmDSA8zY0gBbSy78294j4TBTfjzl7e+R7+wTJ/U2SK3bHEPiajPvl2hHfMX/kyLLH JViA== X-Gm-Message-State: AOAM5336P1kPPdTdHv1r+NNJVxAmTfVatPGJQMA/FeISfQ7nds/wujL0 r3xEtV/SgXXIS5oiwT0T6ElERHZvI2DfOA== X-Received: from mmandlik.mtv.corp.google.com ([2620:15c:202:201:1cf8:bbfc:56cd:c500]) (user=mmandlik job=sendgmr) by 2002:a81:493:0:b0:2dc:a1c3:5e13 with SMTP id 141-20020a810493000000b002dca1c35e13mr11655097ywe.381.1647079755192; Sat, 12 Mar 2022 02:09:15 -0800 (PST) Date: Sat, 12 Mar 2022 02:08:59 -0800 In-Reply-To: <20220312020707.1.I2b7f789329979102339d7e0717522ba417b63109@changeid> Message-Id: <20220312020707.2.Ie20f132ad5cb6bcd435d6c6e0fca8a9d858e83d4@changeid> Mime-Version: 1.0 References: <20220312020707.1.I2b7f789329979102339d7e0717522ba417b63109@changeid> X-Mailer: git-send-email 2.35.1.723.g4982287a31-goog Subject: [PATCH 2/2] Bluetooth: Send AdvMonitor Dev Found for all matched devices From: Manish Mandlik To: marcel@holtmann.org, luiz.dentz@gmail.com Cc: chromeos-bluetooth-upstreaming@chromium.org, linux-bluetooth@vger.kernel.org, Manish Mandlik , Miao-chen Chou , "David S. Miller" , Jakub Kicinski , Johan Hedberg , linux-kernel@vger.kernel.org, netdev@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When an Advertisement Monitor is configured with SamplingPeriod 0xFF, the controller reports only one adv report along with the MSFT Monitor Device event. When an advertiser matches multiple monitors, some controllers send one adv report for each matched monitor; whereas, some controllers send just one adv report for all matched monitors. In such a case, report Adv Monitor Device Found event for each matched monitor. Signed-off-by: Manish Mandlik Reviewed-by: Miao-chen Chou --- net/bluetooth/mgmt.c | 70 +++++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 33 deletions(-) diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c index d59c70e9166f..e4da2318a2f6 100644 --- a/net/bluetooth/mgmt.c +++ b/net/bluetooth/mgmt.c @@ -9628,17 +9628,44 @@ void mgmt_adv_monitor_device_lost(struct hci_dev *hdev, u16 handle, NULL); } +static void mgmt_send_adv_monitor_device_found(struct hci_dev *hdev, + struct sk_buff *skb, + struct sock *skip_sk, + u16 handle) +{ + struct sk_buff *advmon_skb; + size_t advmon_skb_len; + __le16 *monitor_handle; + + if (!skb) + return; + + advmon_skb_len = (sizeof(struct mgmt_ev_adv_monitor_device_found) - + sizeof(struct mgmt_ev_device_found)) + skb->len; + advmon_skb = mgmt_alloc_skb(hdev, MGMT_EV_ADV_MONITOR_DEVICE_FOUND, + advmon_skb_len); + if (!advmon_skb) + return; + + /* ADV_MONITOR_DEVICE_FOUND is similar to DEVICE_FOUND event except + * that it also has 'monitor_handle'. Make a copy of DEVICE_FOUND and + * store monitor_handle of the matched monitor. + */ + monitor_handle = skb_put(advmon_skb, sizeof(*monitor_handle)); + *monitor_handle = cpu_to_le16(handle); + skb_put_data(advmon_skb, skb->data, skb->len); + + mgmt_event_skb(advmon_skb, skip_sk); +} + static void mgmt_adv_monitor_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, bool report_device, struct sk_buff *skb, struct sock *skip_sk) { - struct sk_buff *advmon_skb; - size_t advmon_skb_len; - __le16 *monitor_handle; struct monitored_device *dev, *tmp; bool matched = false; - bool notify = false; + bool notified = false; /* We have received the Advertisement Report because: * 1. the kernel has initiated active discovery @@ -9660,25 +9687,6 @@ static void mgmt_adv_monitor_device_found(struct hci_dev *hdev, return; } - advmon_skb_len = (sizeof(struct mgmt_ev_adv_monitor_device_found) - - sizeof(struct mgmt_ev_device_found)) + skb->len; - advmon_skb = mgmt_alloc_skb(hdev, MGMT_EV_ADV_MONITOR_DEVICE_FOUND, - advmon_skb_len); - if (!advmon_skb) { - if (report_device) - mgmt_event_skb(skb, skip_sk); - else - kfree_skb(skb); - return; - } - - /* ADV_MONITOR_DEVICE_FOUND is similar to DEVICE_FOUND event except - * that it also has 'monitor_handle'. Make a copy of DEVICE_FOUND and - * store monitor_handle of the matched monitor. - */ - monitor_handle = skb_put(advmon_skb, sizeof(*monitor_handle)); - skb_put_data(advmon_skb, skb->data, skb->len); - hdev->advmon_pend_notify = false; list_for_each_entry_safe(dev, tmp, &hdev->monitored_devices, list) { @@ -9686,8 +9694,10 @@ static void mgmt_adv_monitor_device_found(struct hci_dev *hdev, matched = true; if (!dev->notified) { - *monitor_handle = cpu_to_le16(dev->handle); - notify = true; + mgmt_send_adv_monitor_device_found(hdev, skb, + skip_sk, + dev->handle); + notified = true; dev->notified = true; } } @@ -9697,25 +9707,19 @@ static void mgmt_adv_monitor_device_found(struct hci_dev *hdev, } if (!report_device && - ((matched && !notify) || !msft_monitor_supported(hdev))) { + ((matched && !notified) || !msft_monitor_supported(hdev))) { /* Handle 0 indicates that we are not active scanning and this * is a subsequent advertisement report for an already matched * Advertisement Monitor or the controller offloading support * is not available. */ - *monitor_handle = 0; - notify = true; + mgmt_send_adv_monitor_device_found(hdev, skb, skip_sk, 0); } if (report_device) mgmt_event_skb(skb, skip_sk); else kfree_skb(skb); - - if (notify) - mgmt_event_skb(advmon_skb, skip_sk); - else - kfree_skb(advmon_skb); } void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, -- 2.35.1.723.g4982287a31-goog