Skip to contentSkip to conversation

Bluetooth: Further LE scanning fixes & cleanups

PATCH In review [email protected] 2 participants 14 messages Jul 4, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover Bluetooth: Further LE scanning fixes & cleanups

Hi,

Here's another set of patches to fix and clean up various things with LE scanning. The core part of these changes are related to unifuing the list usage for the various types of connection parameter entries.

Johan

----------------------------------------------------------------
Johan Hedberg (12):
Bluetooth: Fix missing return statement in process_adv_report
Bluetooth: Convert pend_le_conn list to a generic action list
Bluetooth: Convert pend_le_reports into a list
Bluetooth: Simplify use of hci_pend_le_conns_clear()
Bluetooth: Don't bother doing anything if auto_connect doesn't change
Bluetooth: Simplify hci_conn_params->action list usage
Bluetooth: Remove unused hci_pend_le_conn_del() function
Bluetooth: Fix clearing and restarting all LE actions on power cycle
Bluetooth: Remove unnecessary usage of hci_pend_le_conn_add
Bluetooth: Remove unused hci_pend_le_conn_add function
Bluetooth: Make hci_pend_le_conn_lookup more general purposed
Bluetooth: Use hci_pend_le_action_lookup to look up report entries

 include/net/bluetooth/hci_core.h | 12 ++---
 net/bluetooth/hci_core.c         | 93 ++++++++++++++----------------------
 net/bluetooth/hci_event.c        | 21 ++++----
 net/bluetooth/mgmt.c             | 41 ++++++++--------
 4 files changed, 73 insertions(+), 94 deletions(-)
#1 lore raw

PATCH 1/12 Bluetooth: Fix missing return statement in process_adv_report

From: Johan Hedberg <[email protected]>

If we're doing passive scanning we shouldn't proceed with any of the code that deals with active scanning (pending reports, etc.). This patch fixes a missing return statement for the passive scanning section in the process_adv_report() function.

---
 net/bluetooth/hci_event.c | 1 +
 1 file changed, 1 insertion(+)
net/bluetooth/hci_event.c +1 -0
index 20317e516e74..e0407e674061 100644
@@ -4256,6 +4256,7 @@ static void process_adv_report(struct hci_dev *hdev, u8 type, bdaddr_t *bdaddr,
 			flags = 0;
 		mgmt_device_found(hdev, bdaddr, LE_LINK, bdaddr_type, NULL,
 				  rssi, flags, data, len, NULL, 0);
+		return;
 	}
 
 	/* When receiving non-connectable or scannable undirected
Signature · 1 line
1.9.3
#2 lore raw

PATCH 2/12 Bluetooth: Convert pend_le_conn list to a generic action list

In reply to [email protected]

From: Johan Hedberg <[email protected]>

In preparation to store also HCI_AUTO_CONN_REPORT entries in a list it makes sense to convert the existing pend_le_conn list head of hci_conn_params into a more generically named "action". This makes sense because a parameter entry will never participate in more than one action list.

---
 include/net/bluetooth/hci_core.h |  2 +-
 net/bluetooth/hci_core.c         | 10 +++++-----
 2 files changed, 6 insertions(+), 6 deletions(-)
include/net/bluetooth/hci_core.h +1 -1
index 09f9fb85d8fd..3b1143caa380 100644
@@ -439,7 +439,7 @@ struct hci_chan {
 
 struct hci_conn_params {
 	struct list_head list;
-	struct list_head pend_le_conn;
+	struct list_head action;
 
 	bdaddr_t addr;
 	u8 addr_type;
net/bluetooth/hci_core.c +5 -5
index 750f969df8db..fed2a0648d3d 100644
@@ -3440,7 +3440,7 @@ struct hci_conn_params *hci_pend_le_conn_lookup(struct hci_dev *hdev,
 	if (!hci_is_identity_address(addr, addr_type))
 		return NULL;
 
-	list_for_each_entry(param, &hdev->pend_le_conns, pend_le_conn) {
+	list_for_each_entry(param, &hdev->pend_le_conns, action) {
 		if (bacmp(&param->addr, addr) == 0 &&
 		    param->addr_type == addr_type)
 			return param;
@@ -3452,8 +3452,8 @@ struct hci_conn_params *hci_pend_le_conn_lookup(struct hci_dev *hdev,
 /* This function requires the caller holds hdev->lock */
 void hci_pend_le_conn_add(struct hci_dev *hdev, struct hci_conn_params *params)
 {
-	list_del_init(&params->pend_le_conn);
-	list_add(&params->pend_le_conn, &hdev->pend_le_conns);
+	list_del_init(&params->action);
+	list_add(&params->action, &hdev->pend_le_conns);
 
 	BT_DBG("addr %pMR (type %u)", &params->addr, params->addr_type);
 
@@ -3463,7 +3463,7 @@ void hci_pend_le_conn_add(struct hci_dev *hdev, struct hci_conn_params *params)
 /* This function requires the caller holds hdev->lock */
 void hci_pend_le_conn_del(struct hci_dev *hdev, struct hci_conn_params *params)
 {
-	list_del_init(&params->pend_le_conn);
+	list_del_init(&params->action);
 
 	BT_DBG("addr %pMR (type %u)", &params->addr, params->addr_type);
 
@@ -3504,7 +3504,7 @@ struct hci_conn_params *hci_conn_params_add(struct hci_dev *hdev,
 	params->addr_type = addr_type;
 
 	list_add(&params->list, &hdev->le_conn_params);
-	INIT_LIST_HEAD(&params->pend_le_conn);
+	INIT_LIST_HEAD(&params->action);
 
 	params->conn_min_interval = hdev->le_conn_min_interval;
 	params->conn_max_interval = hdev->le_conn_max_interval;
Signature · 1 line
1.9.3
#3 lore raw

PATCH 3/12 Bluetooth: Convert pend_le_reports into a list

In reply to [email protected]

From: Johan Hedberg <[email protected]>

To simplify manipulation and lookup of hci_conn_params entries of the type HCI_AUTO_CONN_REPORT it makes sense to store them in their own list. The new action list_head in hci_conn_params is used for this purpose.

---
 include/net/bluetooth/hci_core.h |  2 +-
 net/bluetooth/hci_core.c         | 17 +++++++++++------
 net/bluetooth/hci_event.c        |  2 +-
 net/bluetooth/mgmt.c             |  4 ++--
 4 files changed, 15 insertions(+), 10 deletions(-)
include/net/bluetooth/hci_core.h +1 -1
index 3b1143caa380..9670f4c66ee3 100644
@@ -312,7 +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 list_head	pend_le_reports;
 
 	struct hci_dev_stats	stat;
 
net/bluetooth/hci_core.c +11 -6
index fed2a0648d3d..296f44748636 100644
@@ -3529,7 +3529,7 @@ int hci_conn_params_set(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type,
 
 	if (params->auto_connect == HCI_AUTO_CONN_REPORT &&
 	    auto_connect != HCI_AUTO_CONN_REPORT)
-		hdev->pend_le_reports--;
+		list_del_init(&params->action);
 
 	switch (auto_connect) {
 	case HCI_AUTO_CONN_DISABLED:
@@ -3537,8 +3537,11 @@ int hci_conn_params_set(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type,
 		hci_pend_le_conn_del(hdev, params);
 		break;
 	case HCI_AUTO_CONN_REPORT:
-		if (params->auto_connect != HCI_AUTO_CONN_REPORT)
-			hdev->pend_le_reports++;
+		if (params->auto_connect != HCI_AUTO_CONN_REPORT) {
+			list_del_init(&params->action);
+			list_add(&params->action,
+				 &hdev->pend_le_reports);
+		}
 		hci_pend_le_conn_del(hdev, params);
 		break;
 	case HCI_AUTO_CONN_ALWAYS:
@@ -3565,7 +3568,7 @@ void hci_conn_params_del(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type)
 		return;
 
 	if (params->auto_connect == HCI_AUTO_CONN_REPORT)
-		hdev->pend_le_reports--;
+		list_del_init(&params->action);
 
 	hci_pend_le_conn_del(hdev, params);
 
@@ -3599,7 +3602,7 @@ void hci_conn_params_clear_enabled(struct hci_dev *hdev)
 		if (params->auto_connect == HCI_AUTO_CONN_DISABLED)
 			continue;
 		if (params->auto_connect == HCI_AUTO_CONN_REPORT)
-			hdev->pend_le_reports--;
+			list_del_init(&params->action);
 		list_del(&params->list);
 		kfree(params);
 	}
@@ -3859,6 +3862,7 @@ struct hci_dev *hci_alloc_dev(void)
 	INIT_LIST_HEAD(&hdev->le_white_list);
 	INIT_LIST_HEAD(&hdev->le_conn_params);
 	INIT_LIST_HEAD(&hdev->pend_le_conns);
+	INIT_LIST_HEAD(&hdev->pend_le_reports);
 	INIT_LIST_HEAD(&hdev->conn_hash.list);
 
 	INIT_WORK(&hdev->rx_work, hci_rx_work);
@@ -5362,7 +5366,8 @@ void hci_update_background_scan(struct hci_dev *hdev)
 
 	hci_req_init(&req, hdev);
 
-	if (list_empty(&hdev->pend_le_conns) && !hdev->pend_le_reports) {
+	if (list_empty(&hdev->pend_le_conns) &&
+	    list_empty(&hdev->pend_le_reports)) {
 		/* If there is no pending LE connections or devices
 		 * to be scanned for, we should stop the background
 		 * scanning.
net/bluetooth/hci_event.c +1 -1
index e0407e674061..2a2ef698e851 100644
@@ -4240,7 +4240,7 @@ static void process_adv_report(struct hci_dev *hdev, u8 type, bdaddr_t *bdaddr,
 				return;
 		}
 
-		if (!hdev->pend_le_reports)
+		if (list_empty(&hdev->pend_le_reports))
 			return;
 
 		if (type == LE_ADV_DIRECT_IND)
net/bluetooth/mgmt.c +2 -2
index 474b6dcdf665..a823cccf81f1 100644
@@ -5226,7 +5226,7 @@ static int remove_device(struct sock *sk, struct hci_dev *hdev,
 		}
 
 		if (params->auto_connect == HCI_AUTO_CONN_REPORT)
-			hdev->pend_le_reports--;
+			list_del_init(&params->action);
 
 		hci_pend_le_conn_del(hdev, params);
 		list_del(&params->list);
@@ -6540,7 +6540,7 @@ void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
 	if (!hci_discovery_active(hdev)) {
 		if (link_type == ACL_LINK)
 			return;
-		if (link_type == LE_LINK && !hdev->pend_le_reports)
+		if (link_type == LE_LINK && list_empty(&hdev->pend_le_reports))
 			return;
 	}
 
Signature · 1 line
1.9.3
#4 lore raw

PATCH 4/12 Bluetooth: Simplify use of hci_pend_le_conns_clear()

In reply to [email protected]

From: Johan Hedberg <[email protected]>

Now that pend_le_connections is a list of hci_conn_params entries we can simply remove items from that list as we iterate through the global list of le_conn_params. This also moves the responsibility of calling hci_update_background_scan() to the functions that were previously calling hci_pend_le_conns_clear(). The only user that's left for hci_pend_le_conns_clear() is hci_dev_do_close() which anyway does not need to call hci_update_background_scan().

---
 net/bluetooth/hci_core.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
net/bluetooth/hci_core.c +4 -6
index 296f44748636..dd8aa5f86810 100644
@@ -3477,8 +3477,6 @@ void hci_pend_le_conns_clear(struct hci_dev *hdev)
 		list_del_init(hdev->pend_le_conns.next);
 
 	BT_DBG("All LE pending connections cleared");
-
-	hci_update_background_scan(hdev);
 }
 
 /* This function requires the caller holds hdev->lock */
@@ -3601,13 +3599,12 @@ 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)
-			list_del_init(&params->action);
+		list_del(&params->action);
 		list_del(&params->list);
 		kfree(params);
 	}
 
-	hci_pend_le_conns_clear(hdev);
+	hci_update_background_scan(hdev);
 
 	BT_DBG("All enabled LE connection parameters were removed");
 }
@@ -3618,11 +3615,12 @@ void hci_conn_params_clear_all(struct hci_dev *hdev)
 	struct hci_conn_params *params, *tmp;
 
 	list_for_each_entry_safe(params, tmp, &hdev->le_conn_params, list) {
+		list_del(&params->action);
 		list_del(&params->list);
 		kfree(params);
 	}
 
-	hci_pend_le_conns_clear(hdev);
+	hci_update_background_scan(hdev);
 
 	BT_DBG("All LE connection parameters were removed");
 }
Signature · 1 line
1.9.3
#5 lore raw

PATCH 5/12 Bluetooth: Don't bother doing anything if auto_connect doesn't change

In reply to [email protected]

From: Johan Hedberg <[email protected]>

When hci_conn_params_set() is called if the new auto_connect value is the same as the old one we don't need to take any action. Simply return success from the function in this case.

---
 net/bluetooth/hci_core.c | 3 +++
 1 file changed, 3 insertions(+)
net/bluetooth/hci_core.c +3 -0
index dd8aa5f86810..0601fcbd21eb 100644
@@ -3525,6 +3525,9 @@ int hci_conn_params_set(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type,
 	if (!params)
 		return -EIO;
 
+	if (params->auto_connect == auto_connect)
+		return 0;
+
 	if (params->auto_connect == HCI_AUTO_CONN_REPORT &&
 	    auto_connect != HCI_AUTO_CONN_REPORT)
 		list_del_init(&params->action);
Signature · 1 line
1.9.3
#6 lore raw

PATCH 6/12 Bluetooth: Simplify hci_conn_params->action list usage

In reply to [email protected]

From: Johan Hedberg <[email protected]>

Since params->action is used for both the pend_le_conns and pend_le_reports lists we can simplify the adding and deleting of the lists considerably. For example, when deleting entries in most situations we no-longer need to check the auto_connect value but can directly proceed with calling list_del_init on param->action (which is safe even if the entry is not part of any list).

---
 net/bluetooth/hci_core.c  | 28 +++++++++++-----------------
 net/bluetooth/hci_event.c |  6 ++++--
 net/bluetooth/mgmt.c      |  6 ++----
 3 files changed, 17 insertions(+), 23 deletions(-)
net/bluetooth/hci_core.c +11 -17
index 0601fcbd21eb..3b0da6eeb449 100644
@@ -3528,26 +3528,22 @@ int hci_conn_params_set(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type,
 	if (params->auto_connect == auto_connect)
 		return 0;
 
-	if (params->auto_connect == HCI_AUTO_CONN_REPORT &&
-	    auto_connect != HCI_AUTO_CONN_REPORT)
-		list_del_init(&params->action);
+	list_del_init(&params->action);
 
 	switch (auto_connect) {
 	case HCI_AUTO_CONN_DISABLED:
 	case HCI_AUTO_CONN_LINK_LOSS:
-		hci_pend_le_conn_del(hdev, params);
+		hci_update_background_scan(hdev);
 		break;
 	case HCI_AUTO_CONN_REPORT:
-		if (params->auto_connect != HCI_AUTO_CONN_REPORT) {
-			list_del_init(&params->action);
-			list_add(&params->action,
-				 &hdev->pend_le_reports);
-		}
-		hci_pend_le_conn_del(hdev, params);
+		list_add(&params->action, &hdev->pend_le_reports);
+		hci_update_background_scan(hdev);
 		break;
 	case HCI_AUTO_CONN_ALWAYS:
-		if (!is_connected(hdev, addr, addr_type))
-			hci_pend_le_conn_add(hdev, params);
+		if (!is_connected(hdev, addr, addr_type)) {
+			list_add(&params->action, &hdev->pend_le_conns);
+			hci_update_background_scan(hdev);
+		}
 		break;
 	}
 
@@ -3568,14 +3564,12 @@ 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)
-		list_del_init(&params->action);
-
-	hci_pend_le_conn_del(hdev, params);
-
+	list_del(&params->action);
 	list_del(&params->list);
 	kfree(params);
 
+	hci_update_background_scan(hdev);
+
 	BT_DBG("addr %pMR (type %u)", addr, addr_type);
 }
 
net/bluetooth/hci_event.c +4 -2
index 2a2ef698e851..0ccdf9df2188 100644
@@ -4154,8 +4154,10 @@ static void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
 	hci_proto_connect_cfm(conn, ev->status);
 
 	params = hci_conn_params_lookup(hdev, &conn->dst, conn->dst_type);
-	if (params)
-		hci_pend_le_conn_del(hdev, params);
+	if (params) {
+		list_del_init(&params->action);
+		hci_update_background_scan(hdev);
+	}
 
 unlock:
 	hci_dev_unlock(hdev);
net/bluetooth/mgmt.c +2 -4
index a823cccf81f1..77c64b8cb7e2 100644
@@ -5225,12 +5225,10 @@ static int remove_device(struct sock *sk, struct hci_dev *hdev,
 			goto unlock;
 		}
 
-		if (params->auto_connect == HCI_AUTO_CONN_REPORT)
-			list_del_init(&params->action);
-
-		hci_pend_le_conn_del(hdev, params);
+		list_del_init(&params->action);
 		list_del(&params->list);
 		kfree(params);
+		hci_update_background_scan(hdev);
 
 		device_removed(sk, hdev, &cp->addr.bdaddr, cp->addr.type);
 	} else {
Signature · 1 line
1.9.3
#7 lore raw

PATCH 7/12 Bluetooth: Remove unused hci_pend_le_conn_del() function

In reply to [email protected]

From: Johan Hedberg <[email protected]>

Now that there are no-longer any users of the hci_pend_le_conn_del() function we can simply go ahead and remove it.

---
 include/net/bluetooth/hci_core.h |  1 -
 net/bluetooth/hci_core.c         | 10 ----------
 2 files changed, 11 deletions(-)
include/net/bluetooth/hci_core.h +0 -1
index 9670f4c66ee3..758146c513d3 100644
@@ -871,7 +871,6 @@ void hci_conn_params_clear_enabled(struct hci_dev *hdev);
 struct hci_conn_params *hci_pend_le_conn_lookup(struct hci_dev *hdev,
 						bdaddr_t *addr, u8 addr_type);
 void hci_pend_le_conn_add(struct hci_dev *hdev, struct hci_conn_params *params);
-void hci_pend_le_conn_del(struct hci_dev *hdev, struct hci_conn_params *params);
 void hci_pend_le_conns_clear(struct hci_dev *hdev);
 
 void hci_update_background_scan(struct hci_dev *hdev);
net/bluetooth/hci_core.c +0 -10
index 3b0da6eeb449..6eadde820333 100644
@@ -3461,16 +3461,6 @@ void hci_pend_le_conn_add(struct hci_dev *hdev, struct hci_conn_params *params)
 }
 
 /* This function requires the caller holds hdev->lock */
-void hci_pend_le_conn_del(struct hci_dev *hdev, struct hci_conn_params *params)
-{
-	list_del_init(&params->action);
-
-	BT_DBG("addr %pMR (type %u)", &params->addr, params->addr_type);
-
-	hci_update_background_scan(hdev);
-}
-
-/* This function requires the caller holds hdev->lock */
 void hci_pend_le_conns_clear(struct hci_dev *hdev)
 {
 	while (!list_empty(&hdev->pend_le_conns))
Signature · 1 line
1.9.3
#8 lore raw

PATCH 8/12 Bluetooth: Fix clearing and restarting all LE actions on power cycle

In reply to [email protected]

From: Johan Hedberg <[email protected]>

When powering off (hci_dev_do_close) we should clear both the pend_le_reports and pend_le_conns types of entries. When powering on respectively we should populate both lists. This patch converts the hci_pend_le_conns_clear() function into hci_pend_le_actions_clear() (which can now be static) and converts the restart_le_auto_conns() function into restart_le_actions().

---
 include/net/bluetooth/hci_core.h |  1 -
 net/bluetooth/hci_core.c         | 23 ++++++++++++-----------
 net/bluetooth/mgmt.c             | 33 ++++++++++++++++-----------------
 3 files changed, 28 insertions(+), 29 deletions(-)
include/net/bluetooth/hci_core.h +0 -1
index 758146c513d3..9208b18cb1e9 100644
@@ -871,7 +871,6 @@ void hci_conn_params_clear_enabled(struct hci_dev *hdev);
 struct hci_conn_params *hci_pend_le_conn_lookup(struct hci_dev *hdev,
 						bdaddr_t *addr, u8 addr_type);
 void hci_pend_le_conn_add(struct hci_dev *hdev, struct hci_conn_params *params);
-void hci_pend_le_conns_clear(struct hci_dev *hdev);
 
 void hci_update_background_scan(struct hci_dev *hdev);
 
net/bluetooth/hci_core.c +12 -11
index 6eadde820333..3a1a25dcb2bc 100644
@@ -2354,6 +2354,17 @@ done:
 	return err;
 }
 
+/* This function requires the caller holds hdev->lock */
+static void hci_pend_le_actions_clear(struct hci_dev *hdev)
+{
+	struct hci_conn_params *p;
+
+	list_for_each_entry(p, &hdev->le_conn_params, list)
+		list_del_init(&p->action);
+
+	BT_DBG("All LE pending actions cleared");
+}
+
 static int hci_dev_do_close(struct hci_dev *hdev)
 {
 	BT_DBG("%s %p", hdev->name, hdev);
@@ -2391,7 +2402,7 @@ static int hci_dev_do_close(struct hci_dev *hdev)
 	hci_dev_lock(hdev);
 	hci_inquiry_cache_flush(hdev);
 	hci_conn_hash_flush(hdev);
-	hci_pend_le_conns_clear(hdev);
+	hci_pend_le_actions_clear(hdev);
 	hci_dev_unlock(hdev);
 
 	hci_notify(hdev, HCI_DEV_DOWN);
@@ -3460,16 +3471,6 @@ void hci_pend_le_conn_add(struct hci_dev *hdev, struct hci_conn_params *params)
 	hci_update_background_scan(hdev);
 }
 
-/* This function requires the caller holds hdev->lock */
-void hci_pend_le_conns_clear(struct hci_dev *hdev)
-{
-	while (!list_empty(&hdev->pend_le_conns))
-		list_del_init(hdev->pend_le_conns.next);
-
-	BT_DBG("All LE pending connections cleared");
-}
-
-/* This function requires the caller holds hdev->lock */
 struct hci_conn_params *hci_conn_params_add(struct hci_dev *hdev,
 					    bdaddr_t *addr, u8 addr_type)
 {
net/bluetooth/mgmt.c +16 -17
index 77c64b8cb7e2..f1672b15c0f3 100644
@@ -5533,29 +5533,28 @@ void mgmt_index_removed(struct hci_dev *hdev)
 }
 
 /* This function requires the caller holds hdev->lock */
-static void restart_le_auto_conns(struct hci_dev *hdev)
+static void restart_le_actions(struct hci_dev *hdev)
 {
 	struct hci_conn_params *p;
-	bool added = false;
 
 	list_for_each_entry(p, &hdev->le_conn_params, list) {
-		if (p->auto_connect == HCI_AUTO_CONN_ALWAYS) {
-			hci_pend_le_conn_add(hdev, p);
-			added = true;
+		/* Needed for AUTO_OFF case where might not "really"
+		 * have been powered off.
+		 */
+		list_del_init(&p->action);
+
+		switch (p->auto_connect) {
+		case HCI_AUTO_CONN_ALWAYS:
+			list_add(&p->action, &hdev->pend_le_conns);
+			break;
+		case HCI_AUTO_CONN_REPORT:
+			list_add(&p->action, &hdev->pend_le_reports);
+			break;
+		default:
+			break;
 		}
 	}
 
-	/* Calling hci_pend_le_conn_add will actually already trigger
-	 * background scanning when needed. So no need to trigger it
-	 * just another time.
-	 *
-	 * This check is here to avoid an unneeded restart of the
-	 * passive scanning. Since this is during the controller
-	 * power up phase the duplicate filtering is not an issue.
-	 */
-	if (added)
-		return;
-
 	hci_update_background_scan(hdev);
 }
 
@@ -5567,7 +5566,7 @@ static void powered_complete(struct hci_dev *hdev, u8 status)
 
 	hci_dev_lock(hdev);
 
-	restart_le_auto_conns(hdev);
+	restart_le_actions(hdev);
 
 	mgmt_pending_foreach(MGMT_OP_SET_POWERED, hdev, settings_rsp, &match);
 
Signature · 1 line
1.9.3
#9 lore raw

PATCH 9/12 Bluetooth: Remove unnecessary usage of hci_pend_le_conn_add

In reply to [email protected]

From: Johan Hedberg <[email protected]>

This is the last place using hci_pend_le_conn_add() and we can more just as simply manipulate the list directly here.

---
 net/bluetooth/hci_event.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net/bluetooth/hci_event.c +3 -1
index 0ccdf9df2188..9e0b2e888bba 100644
@@ -2209,7 +2209,9 @@ static void hci_disconn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
 			/* Fall through */
 
 		case HCI_AUTO_CONN_ALWAYS:
-			hci_pend_le_conn_add(hdev, params);
+			list_del_init(&params->action);
+			list_add(&params->action, &hdev->pend_le_conns);
+			hci_update_background_scan(hdev);
 			break;
 
 		default:
Signature · 1 line
1.9.3
#10 lore raw

PATCH 10/12 Bluetooth: Remove unused hci_pend_le_conn_add function

In reply to [email protected]

From: Johan Hedberg <[email protected]>

Since there are no more users of this function we can simply go ahead and remove it.

---
 include/net/bluetooth/hci_core.h |  1 -
 net/bluetooth/hci_core.c         | 10 ----------
 2 files changed, 11 deletions(-)
include/net/bluetooth/hci_core.h +0 -1
index 9208b18cb1e9..c2bc9180cb79 100644
@@ -870,7 +870,6 @@ void hci_conn_params_clear_enabled(struct hci_dev *hdev);
 
 struct hci_conn_params *hci_pend_le_conn_lookup(struct hci_dev *hdev,
 						bdaddr_t *addr, u8 addr_type);
-void hci_pend_le_conn_add(struct hci_dev *hdev, struct hci_conn_params *params);
 
 void hci_update_background_scan(struct hci_dev *hdev);
 
net/bluetooth/hci_core.c +0 -10
index 3a1a25dcb2bc..38a0c5cd0ee4 100644
@@ -3461,16 +3461,6 @@ struct hci_conn_params *hci_pend_le_conn_lookup(struct hci_dev *hdev,
 }
 
 /* This function requires the caller holds hdev->lock */
-void hci_pend_le_conn_add(struct hci_dev *hdev, struct hci_conn_params *params)
-{
-	list_del_init(&params->action);
-	list_add(&params->action, &hdev->pend_le_conns);
-
-	BT_DBG("addr %pMR (type %u)", &params->addr, params->addr_type);
-
-	hci_update_background_scan(hdev);
-}
-
 struct hci_conn_params *hci_conn_params_add(struct hci_dev *hdev,
 					    bdaddr_t *addr, u8 addr_type)
 {
Signature · 1 line
1.9.3
#11 lore raw

PATCH 11/12 Bluetooth: Make hci_pend_le_conn_lookup more general purposed

In reply to [email protected]

From: Johan Hedberg <[email protected]>

In some circumstances we need to look up entries in pend_le_conns and in other in pend_le_reports. This patch converts the existing lookup function for pend_le_conns to something that can be used for both lists.

---
 include/net/bluetooth/hci_core.h | 5 +++--
 net/bluetooth/hci_core.c         | 6 +++---
 net/bluetooth/hci_event.c        | 2 +-
 3 files changed, 7 insertions(+), 6 deletions(-)
include/net/bluetooth/hci_core.h +3 -2
index c2bc9180cb79..1cae4d3a629d 100644
@@ -868,8 +868,9 @@ void hci_conn_params_clear_all(struct hci_dev *hdev);
 void hci_conn_params_clear_disabled(struct hci_dev *hdev);
 void hci_conn_params_clear_enabled(struct hci_dev *hdev);
 
-struct hci_conn_params *hci_pend_le_conn_lookup(struct hci_dev *hdev,
-						bdaddr_t *addr, u8 addr_type);
+struct hci_conn_params *hci_pend_le_action_lookup(struct list_head *list,
+						  bdaddr_t *addr,
+						  u8 addr_type);
 
 void hci_update_background_scan(struct hci_dev *hdev);
 
net/bluetooth/hci_core.c +3 -3
index 38a0c5cd0ee4..038b4748375b 100644
@@ -3442,8 +3442,8 @@ static bool is_connected(struct hci_dev *hdev, bdaddr_t *addr, u8 type)
 }
 
 /* This function requires the caller holds hdev->lock */
-struct hci_conn_params *hci_pend_le_conn_lookup(struct hci_dev *hdev,
-						bdaddr_t *addr, u8 addr_type)
+struct hci_conn_params *hci_pend_le_action_lookup(struct list_head *list,
+						  bdaddr_t *addr, u8 addr_type)
 {
 	struct hci_conn_params *param;
 
@@ -3451,7 +3451,7 @@ struct hci_conn_params *hci_pend_le_conn_lookup(struct hci_dev *hdev,
 	if (!hci_is_identity_address(addr, addr_type))
 		return NULL;
 
-	list_for_each_entry(param, &hdev->pend_le_conns, action) {
+	list_for_each_entry(param, list, action) {
 		if (bacmp(&param->addr, addr) == 0 &&
 		    param->addr_type == addr_type)
 			return param;
net/bluetooth/hci_event.c +1 -1
index 9e0b2e888bba..9274cd228995 100644
@@ -4194,7 +4194,7 @@ static bool check_pending_le_conn(struct hci_dev *hdev, bdaddr_t *addr,
 {
 	struct hci_conn *conn;
 
-	if (!hci_pend_le_conn_lookup(hdev, addr, addr_type))
+	if (!hci_pend_le_action_lookup(&hdev->pend_le_conns, addr, addr_type))
 		return false;
 
 	conn = hci_connect_le(hdev, addr, addr_type, BT_SECURITY_LOW,
Signature · 1 line
1.9.3
#12 lore raw

PATCH 12/12 Bluetooth: Use hci_pend_le_action_lookup to look up report entries

In reply to [email protected]

From: Johan Hedberg <[email protected]>

Instead of looking through the entire list of entries we can more efficiently use the new hci_pend_le_action_lookup() function to look up entries specifically in the pend_le_reports list. Since the search is now limited to the right list we can also remove an unnecessary check for list_empty() before the lookup.

---
 net/bluetooth/hci_event.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
net/bluetooth/hci_event.c +3 -5
index 9274cd228995..c380545f1e92 100644
@@ -4244,14 +4244,12 @@ static void process_adv_report(struct hci_dev *hdev, u8 type, bdaddr_t *bdaddr,
 				return;
 		}
 
-		if (list_empty(&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)
+		param = hci_pend_le_action_lookup(&hdev->pend_le_reports,
+						  bdaddr, bdaddr_type);
+		if (!param)
 			return;
 
 		if (type == LE_ADV_NONCONN_IND || type == LE_ADV_SCAN_IND)
Signature · 1 line
1.9.3
maintainer
#13 lore raw
In reply to [email protected]

Hi Johan,

Quoted 21 lines

Here's another set of patches to fix and clean up various things with LE scanning. The core part of these changes are related to unifuing the list usage for the various types of connection parameter entries.

Johan

----------------------------------------------------------------
Johan Hedberg (12):
Bluetooth: Fix missing return statement in process_adv_report
Bluetooth: Convert pend_le_conn list to a generic action list
Bluetooth: Convert pend_le_reports into a list
Bluetooth: Simplify use of hci_pend_le_conns_clear()
Bluetooth: Don't bother doing anything if auto_connect doesn't change
Bluetooth: Simplify hci_conn_params->action list usage
Bluetooth: Remove unused hci_pend_le_conn_del() function
Bluetooth: Fix clearing and restarting all LE actions on power cycle
Bluetooth: Remove unnecessary usage of hci_pend_le_conn_add
Bluetooth: Remove unused hci_pend_le_conn_add function
Bluetooth: Make hci_pend_le_conn_lookup more general purposed
Bluetooth: Use hci_pend_le_action_lookup to look up report entries

Quoted 5 lines
include/net/bluetooth/hci_core.h | 12 ++---
net/bluetooth/hci_core.c         | 93 ++++++++++++++----------------------
net/bluetooth/hci_event.c        | 21 ++++----
net/bluetooth/mgmt.c             | 41 ++++++++--------
4 files changed, 73 insertions(+), 94 deletions(-)

all 12 patches have been applied to bluetooth-next tree.

Regards

Marcel