Bluetooth: Track number of added devices with HCI_AUTO_CONN_REPORT
Subsystems (2)
PATCH 1/3 Bluetooth: Track number of added devices with HCI_AUTO_CONN_REPORT
From: Johan Hedberg <[email protected]>
To be able to make the right choice of whether to start passive scanning or to send out a mgmt_device_found event we need to know if there are any devices in the le_conn_params list with the auto_connect value set to HCI_AUTO_CONN_REPORT. This patch adds a counter for this kind of devices.
--- include/net/bluetooth/hci_core.h | 1 + net/bluetooth/hci_core.c | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-)
include/net/bluetooth/hci_core.h +1 -0
@@ -312,6 +312,7 @@ struct hci_dev {struct list_head le_white_list;struct list_head le_conn_params;struct list_head pend_le_conns; +unsigned int pend_le_reports;struct hci_dev_stats stat;
net/bluetooth/hci_core.c +15 -2
@@ -3545,20 +3545,28 @@ int hci_conn_params_set(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type,if (!params)return -EIO ; - params->auto_connect = auto_connect; +if (params->auto_connect ==HCI_AUTO_CONN_REPORT && + auto_connect !=HCI_AUTO_CONN_REPORT ) + hdev->pend_le_reports--;switch (auto_connect) {case HCI_AUTO_CONN_DISABLED : -case HCI_AUTO_CONN_REPORT :case HCI_AUTO_CONN_LINK_LOSS :hci_pend_le_conn_del (hdev, addr, addr_type);break ; +case HCI_AUTO_CONN_REPORT : +if (params->auto_connect !=HCI_AUTO_CONN_REPORT ) + hdev->pend_le_reports++; +hci_pend_le_conn_del (hdev, addr, addr_type); +break ;case HCI_AUTO_CONN_ALWAYS :if (!is_connected (hdev, addr, addr_type))hci_pend_le_conn_add (hdev, addr, addr_type);break ; } + params->auto_connect = auto_connect; +BT_DBG ("addr %pMR (type %u) auto_connect %u" , addr, addr_type, auto_connect);
@@ -3574,6 +3582,9 @@ void hci_conn_params_del(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type)if (!params)return ; +if (params->auto_connect ==HCI_AUTO_CONN_REPORT ) + hdev->pend_le_reports--; +hci_pend_le_conn_del (hdev, addr, addr_type);list_del (¶ms->list);
@@ -3605,6 +3616,8 @@ void hci_conn_params_clear_enabled(struct hci_dev *hdev)list_for_each_entry_safe (params, tmp, &hdev->le_conn_params, list) {if (params->auto_connect ==HCI_AUTO_CONN_DISABLED )continue ; +if (params->auto_connect ==HCI_AUTO_CONN_REPORT ) + hdev->pend_le_reports--;list_del (¶ms->list);kfree (params); }
Signature · 1 line
1.9.3
PATCH 2/3 Bluetooth: Allow mgmt_device_found events for kernel-side scanning
From: Johan Hedberg <[email protected]>
When the kernel is doing LE scanning because of one or more devices added with action 0x00 through the Add Device command we do want to let mgmt_device_found() to proceed with sending an event. This kind of devices are tracked with hdev->pend_le_reports, so check this value before bailing out from the function.
--- net/bluetooth/mgmt.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
net/bluetooth/mgmt.c +10 -2
@@ -6401,8 +6401,16 @@ void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,struct smp_irk *irk;size_t ev_size; -if (!hci_discovery_active (hdev)) -return ; +/* Don't send events for a non-kernel initiated discovery. With +* LE one exception is if we have pend_le_reports > 0 in which +* case we're doing passive scanning and want these events. +*/ +if (!hci_discovery_active (hdev)) { +if (link_type ==ACL_LINK ) +return ; +if (link_type ==LE_LINK && !hdev->pend_le_reports) +return ; + }/* Make sure that the buffer is big enough. The 5 extra bytes * are for the potential CoD field.
Signature · 1 line
1.9.3
PATCH 3/3 Bluetooth: Add support for background LE scanning
In reply to [email protected]From: Johan Hedberg <[email protected]>
If we have one or more devices with HCI_AUTO_CONN_REPORT we should do background scanning and emit mgmt_device_found events. This patch modifies the hci_update_background_scan() function to extend the conditions needed to trigger scanning, and adds the necessary code to process_adv_report() to emit mgmt_device_found events.
--- net/bluetooth/hci_core.c | 7 ++++--- net/bluetooth/hci_event.c | 25 +++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 5 deletions(-)
net/bluetooth/hci_core.c +4 -3
@@ -5380,9 +5380,10 @@ void hci_update_background_scan(struct hci_dev *hdev)hci_req_init (&req, hdev); -if (list_empty (&hdev->pend_le_conns)) { -/* If there is no pending LE connections, we should stop -* the background scanning. +if (list_empty (&hdev->pend_le_conns) && !hdev->pend_le_reports) { +/* If there is no pending LE connections or devices +* to be scanned for, we should stop the background +* scanning. */ /* If controller is not scanning we are done. */
net/bluetooth/hci_event.c +23 -2
@@ -4225,11 +4225,32 @@ static void process_adv_report(struct hci_dev *hdev, u8 type, bdaddr_t *bdaddr,bool match;u32 flags; -/* Passive scanning shouldn't trigger any device found events */ +/* Passive scanning shouldn't trigger any device found events, +* except for devices marked as CONN_REPORT for which we do send +* device found events. +*/ if (hdev->le_scan_type ==LE_SCAN_PASSIVE ) { +struct hci_conn_params *param; +if (type ==LE_ADV_IND || type ==LE_ADV_DIRECT_IND )check_pending_le_conn (hdev, bdaddr, bdaddr_type); -return ; + +if (!hdev->pend_le_reports) +return ; + +if (type ==LE_ADV_DIRECT_IND ) +return ; + + param =hci_conn_params_lookup (hdev, bdaddr, bdaddr_type); +if (!param || param->auto_connect !=HCI_AUTO_CONN_REPORT ) +return ; + +if (type ==LE_ADV_NONCONN_IND || type ==LE_ADV_SCAN_IND ) + flags =MGMT_DEV_FOUND_NOT_CONNECTABLE ; +else + flags =0 ; +mgmt_device_found (hdev, bdaddr,LE_LINK , bdaddr_type,NULL , + rssi, flags, data, len,NULL ,0 ); }/* When receiving non-connectable or scannable undirected
Signature · 1 line
1.9.3
Marcel Holtmann
maintainerRe: [PATCH 2/3] Bluetooth: Allow mgmt_device_found events for kernel-side scanning
In reply to [email protected]Hi Johan,
Quoted 10 lines
When the kernel is doing LE scanning because of one or more devices added with action
0x00through the Add Device command we do want to letmgmt_device_found()to proceed with sending an event. This kind of devices are tracked withhdev->pend_le_reports, so check this value before bailing out from the function.Signed-off-by Johan Hedberg <[email protected]>---
net/bluetooth/mgmt.c| 12 ++++++++++--1 file changed, 10 insertions(+), 2 deletions(-)
patch has been applied to bluetooth-next tree.
Regards
Marcel
Marcel Holtmann
maintainerRe: [PATCH 3/3] Bluetooth: Add support for background LE scanning
In reply to [email protected]Hi Johan,
Quoted 11 lines
If we have one or more devices with
HCI_AUTO_CONN_REPORTwe should do background scanning and emitmgmt_device_foundevents. This patch modifies thehci_update_background_scan()function to extend the conditions needed to trigger scanning, and adds the necessary code toprocess_adv_report()to emitmgmt_device_foundevents.Signed-off-by Johan Hedberg <[email protected]>---
net/bluetooth/hci_core.c| 7 ++++---net/bluetooth/hci_event.c| 25 +++++++++++++++++++++++--2 files changed, 27 insertions(+), 5 deletions(-)
patch has been applied to bluetooth-next tree.
Regards
Marcel
Marcel Holtmann
maintainerHi Johan,
Quoted 11 lines
To be able to make the right choice of whether to start passive scanning or to send out a
mgmt_device_foundevent we need to know if there are any devices in thele_conn_paramslist with theauto_connectvalue set toHCI_AUTO_CONN_REPORT. This patch adds a counter for this kind of devices.Signed-off-by Johan Hedberg <[email protected]>---
include/net/bluetooth/hci_core.h| 1 +net/bluetooth/hci_core.c| 17 +++++++++++++++--2 files changed, 16 insertions(+), 2 deletions(-)
patch has been applied to bluetooth-next tree.
Regards
Marcel