Commit ff39fc1b authored by Manish Mandlik's avatar Manish Mandlik Committed by Marcel Holtmann

Bluetooth: Send AdvMonitor Dev Found for all matched devices

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: default avatarManish Mandlik <mmandlik@google.com>
Reviewed-by: default avatarMiao-chen Chou <mcchou@chromium.org>
Signed-off-by: default avatarMarcel Holtmann <marcel@holtmann.org>
parent 37b63c68
...@@ -9628,17 +9628,44 @@ void mgmt_adv_monitor_device_lost(struct hci_dev *hdev, u16 handle, ...@@ -9628,17 +9628,44 @@ void mgmt_adv_monitor_device_lost(struct hci_dev *hdev, u16 handle,
NULL); 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, static void mgmt_adv_monitor_device_found(struct hci_dev *hdev,
bdaddr_t *bdaddr, bool report_device, bdaddr_t *bdaddr, bool report_device,
struct sk_buff *skb, struct sk_buff *skb,
struct sock *skip_sk) struct sock *skip_sk)
{ {
struct sk_buff *advmon_skb;
size_t advmon_skb_len;
__le16 *monitor_handle;
struct monitored_device *dev, *tmp; struct monitored_device *dev, *tmp;
bool matched = false; bool matched = false;
bool notify = false; bool notified = false;
/* We have received the Advertisement Report because: /* We have received the Advertisement Report because:
* 1. the kernel has initiated active discovery * 1. the kernel has initiated active discovery
...@@ -9660,25 +9687,6 @@ static void mgmt_adv_monitor_device_found(struct hci_dev *hdev, ...@@ -9660,25 +9687,6 @@ static void mgmt_adv_monitor_device_found(struct hci_dev *hdev,
return; 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; hdev->advmon_pend_notify = false;
list_for_each_entry_safe(dev, tmp, &hdev->monitored_devices, list) { 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, ...@@ -9686,8 +9694,10 @@ static void mgmt_adv_monitor_device_found(struct hci_dev *hdev,
matched = true; matched = true;
if (!dev->notified) { if (!dev->notified) {
*monitor_handle = cpu_to_le16(dev->handle); mgmt_send_adv_monitor_device_found(hdev, skb,
notify = true; skip_sk,
dev->handle);
notified = true;
dev->notified = true; dev->notified = true;
} }
} }
...@@ -9697,25 +9707,19 @@ static void mgmt_adv_monitor_device_found(struct hci_dev *hdev, ...@@ -9697,25 +9707,19 @@ static void mgmt_adv_monitor_device_found(struct hci_dev *hdev,
} }
if (!report_device && 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 /* Handle 0 indicates that we are not active scanning and this
* is a subsequent advertisement report for an already matched * is a subsequent advertisement report for an already matched
* Advertisement Monitor or the controller offloading support * Advertisement Monitor or the controller offloading support
* is not available. * is not available.
*/ */
*monitor_handle = 0; mgmt_send_adv_monitor_device_found(hdev, skb, skip_sk, 0);
notify = true;
} }
if (report_device) if (report_device)
mgmt_event_skb(skb, skip_sk); mgmt_event_skb(skb, skip_sk);
else else
kfree_skb(skb); 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, void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment