Skip to contentSkip to conversation

Bluetooth: hci_sync: Convert MGMT_OP_SET_DISCOVERABLE to use cmd_sync

PATCH In review Luiz Augusto von Dentz 2 participants 6 messages Nov 12, 2021 – Nov 16, 2021

Subsystems (2)
lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH 1/3 Bluetooth: hci_sync: Convert MGMT_OP_SET_DISCOVERABLE to use cmd_sync

From: Luiz Augusto von Dentz <[email protected]>

This makes MGMT_OP_SET_DISCOVERABLE use hci_cmd_sync_queue instead of use a dedicated discoverable_update work.

---
 include/net/bluetooth/hci_core.h |  2 -
 include/net/bluetooth/hci_sync.h |  3 ++
 net/bluetooth/hci_request.c      | 12 -----
 net/bluetooth/hci_sync.c         | 90 +++++++++++++++++++++++++++++++-
 net/bluetooth/mgmt.c             | 43 +++++++--------
 5 files changed, 112 insertions(+), 38 deletions(-)
include/net/bluetooth/hci_core.h +0 -2
index cb5684da3ed4..9a56957c5967 100644
@@ -497,7 +497,6 @@ struct hci_dev {
 	struct work_struct	bg_scan_update;
 	struct work_struct	scan_update;
 	struct work_struct	connectable_update;
-	struct work_struct	discoverable_update;
 	struct delayed_work	le_scan_disable;
 	struct delayed_work	le_scan_restart;
 
@@ -1833,7 +1832,6 @@ void mgmt_new_conn_param(struct hci_dev *hdev, bdaddr_t *bdaddr,
 void mgmt_smp_complete(struct hci_conn *conn, bool complete);
 bool mgmt_get_connectable(struct hci_dev *hdev);
 void mgmt_set_connectable_complete(struct hci_dev *hdev, u8 status);
-void mgmt_set_discoverable_complete(struct hci_dev *hdev, u8 status);
 u8 mgmt_get_adv_discov_flags(struct hci_dev *hdev);
 void mgmt_advertising_added(struct sock *sk, struct hci_dev *hdev,
 			    u8 instance);
include/net/bluetooth/hci_sync.h +3 -0
index 00b13e8ca800..d335c0ce8c5d 100644
@@ -90,6 +90,9 @@ int hci_dev_close_sync(struct hci_dev *hdev);
 int hci_powered_update_sync(struct hci_dev *hdev);
 int hci_set_powered_sync(struct hci_dev *hdev, u8 val);
 
+int hci_update_discoverable_sync(struct hci_dev *hdev);
+int hci_update_discoverable(struct hci_dev *hdev);
+
 int hci_start_discovery_sync(struct hci_dev *hdev);
 int hci_stop_discovery_sync(struct hci_dev *hdev);
 
net/bluetooth/hci_request.c +0 -12
index 8aa6e1840c9a..9f355d8c34f2 100644
@@ -2131,16 +2131,6 @@ static int discoverable_update(struct hci_request *req, unsigned long opt)
 	return 0;
 }
 
-static void discoverable_update_work(struct work_struct *work)
-{
-	struct hci_dev *hdev = container_of(work, struct hci_dev,
-					    discoverable_update);
-	u8 status;
-
-	hci_req_sync(hdev, discoverable_update, 0, HCI_CMD_TIMEOUT, &status);
-	mgmt_set_discoverable_complete(hdev, status);
-}
-
 void __hci_abort_conn(struct hci_request *req, struct hci_conn *conn,
 		      u8 reason)
 {
@@ -2852,7 +2842,6 @@ void hci_request_setup(struct hci_dev *hdev)
 	INIT_WORK(&hdev->bg_scan_update, bg_scan_update);
 	INIT_WORK(&hdev->scan_update, scan_update_work);
 	INIT_WORK(&hdev->connectable_update, connectable_update_work);
-	INIT_WORK(&hdev->discoverable_update, discoverable_update_work);
 	INIT_DELAYED_WORK(&hdev->discov_off, discov_off);
 	INIT_DELAYED_WORK(&hdev->le_scan_disable, le_scan_disable_work);
 	INIT_DELAYED_WORK(&hdev->le_scan_restart, le_scan_restart_work);
@@ -2868,7 +2857,6 @@ void hci_request_cancel_all(struct hci_dev *hdev)
 	cancel_work_sync(&hdev->bg_scan_update);
 	cancel_work_sync(&hdev->scan_update);
 	cancel_work_sync(&hdev->connectable_update);
-	cancel_work_sync(&hdev->discoverable_update);
 	cancel_delayed_work_sync(&hdev->discov_off);
 	cancel_delayed_work_sync(&hdev->le_scan_disable);
 	cancel_delayed_work_sync(&hdev->le_scan_restart);
net/bluetooth/hci_sync.c +89 -1

102 lines not on this page · raw message

net/bluetooth/mgmt.c +20 -23

83 lines not on this page · raw message

Signature · 1 line
2.33.1
author maintainer
#1 lore raw

PATCH 2/3 Bluetooth: hci_sync: Convert MGMT_OP_SET_CONNECTABLE to use cmd_sync

From: Luiz Augusto von Dentz <[email protected]>

This makes MGMT_OP_SET_CONNEABLE use hci_cmd_sync_queue instead of use a dedicated connetable_update work.

---
 include/net/bluetooth/hci_core.h |  2 --
 include/net/bluetooth/hci_sync.h |  2 ++
 net/bluetooth/hci_request.c      | 43 --------------------------------
 net/bluetooth/hci_sync.c         | 31 +++++++++++++++++++++++
 net/bluetooth/mgmt.c             | 36 +++++++++++++-------------
 5 files changed, 52 insertions(+), 62 deletions(-)
include/net/bluetooth/hci_core.h +0 -2
index 9a56957c5967..70f2e16de18b 100644
@@ -496,7 +496,6 @@ struct hci_dev {
 	struct work_struct	discov_update;
 	struct work_struct	bg_scan_update;
 	struct work_struct	scan_update;
-	struct work_struct	connectable_update;
 	struct delayed_work	le_scan_disable;
 	struct delayed_work	le_scan_restart;
 
@@ -1831,7 +1830,6 @@ void mgmt_new_conn_param(struct hci_dev *hdev, bdaddr_t *bdaddr,
 			 u16 max_interval, u16 latency, u16 timeout);
 void mgmt_smp_complete(struct hci_conn *conn, bool complete);
 bool mgmt_get_connectable(struct hci_dev *hdev);
-void mgmt_set_connectable_complete(struct hci_dev *hdev, u8 status);
 u8 mgmt_get_adv_discov_flags(struct hci_dev *hdev);
 void mgmt_advertising_added(struct sock *sk, struct hci_dev *hdev,
 			    u8 instance);
include/net/bluetooth/hci_sync.h +2 -0
index d335c0ce8c5d..0336c1bc5d25 100644
@@ -93,6 +93,8 @@ int hci_set_powered_sync(struct hci_dev *hdev, u8 val);
 int hci_update_discoverable_sync(struct hci_dev *hdev);
 int hci_update_discoverable(struct hci_dev *hdev);
 
+int hci_update_connectable_sync(struct hci_dev *hdev);
+
 int hci_start_discovery_sync(struct hci_dev *hdev);
 int hci_stop_discovery_sync(struct hci_dev *hdev);
 
net/bluetooth/hci_request.c +0 -43

61 lines not on this page · raw message

net/bluetooth/hci_sync.c +31 -0
index 205823f21fff..517c5bb92004 100644
@@ -4517,6 +4517,37 @@ int hci_update_discoverable(struct hci_dev *hdev)
 	return 0;
 }
 
+int hci_update_connectable_sync(struct hci_dev *hdev)
+{
+	int err;
+
+	err = hci_update_scan_sync(hdev);
+	if (err)
+		return err;
+
+	/* If BR/EDR is not enabled and we disable advertising as a
+	 * by-product of disabling connectable, we need to update the
+	 * advertising flags.
+	 */
+	if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED))
+		err = hci_update_adv_data_sync(hdev, hdev->cur_adv_instance);
+
+	/* Update the advertising parameters if necessary */
+	if (hci_dev_test_flag(hdev, HCI_ADVERTISING) ||
+	    !list_empty(&hdev->adv_instances)) {
+		if (ext_adv_capable(hdev))
+			err = hci_start_ext_adv_sync(hdev,
+						     hdev->cur_adv_instance);
+		else
+			err = hci_enable_advertising_sync(hdev);
+
+		if (err)
+			return err;
+	}
+
+	return hci_update_passive_scan_sync(hdev);
+}
+
 static int hci_inquiry_sync(struct hci_dev *hdev, u8 length)
 {
 	const u8 giac[3] = { 0x33, 0x8b, 0x9e };
net/bluetooth/mgmt.c +19 -17
index 1cb5d9113863..fe52b7eefb56 100644
@@ -1537,31 +1537,26 @@ static int set_discoverable(struct sock *sk, struct hci_dev *hdev, void *data,
 	return err;
 }
 
-void mgmt_set_connectable_complete(struct hci_dev *hdev, u8 status)
+static void mgmt_set_connectable_complete(struct hci_dev *hdev, void *data,
+					  int err)
 {
-	struct mgmt_pending_cmd *cmd;
+	struct mgmt_pending_cmd *cmd = data;
 
-	bt_dev_dbg(hdev, "status 0x%02x", status);
+	bt_dev_dbg(hdev, "err %d", err);
 
 	hci_dev_lock(hdev);
 
-	cmd = pending_find(MGMT_OP_SET_CONNECTABLE, hdev);
-	if (!cmd)
-		goto unlock;
-
-	if (status) {
-		u8 mgmt_err = mgmt_status(status);
+	if (err) {
+		u8 mgmt_err = mgmt_status(err);
 		mgmt_cmd_status(cmd->sk, cmd->index, cmd->opcode, mgmt_err);
-		goto remove_cmd;
+		goto done;
 	}
 
 	send_settings_rsp(cmd->sk, MGMT_OP_SET_CONNECTABLE, hdev);
 	new_settings(hdev, cmd->sk);
 
-remove_cmd:
-	mgmt_pending_remove(cmd);
-
-unlock:
+done:
+	mgmt_pending_free(cmd);
 	hci_dev_unlock(hdev);
 }
 
@@ -1594,6 +1589,13 @@ static int set_connectable_update_settings(struct hci_dev *hdev,
 	return 0;
 }
 
+static int set_connectable_sync(struct hci_dev *hdev, void *data)
+{
+	BT_DBG("%s", hdev->name);
+
+	return hci_update_connectable_sync(hdev);
+}
+
 static int set_connectable(struct sock *sk, struct hci_dev *hdev, void *data,
 			   u16 len)
 {
@@ -1626,7 +1628,7 @@ static int set_connectable(struct sock *sk, struct hci_dev *hdev, void *data,
 		goto failed;
 	}
 
-	cmd = mgmt_pending_add(sk, MGMT_OP_SET_CONNECTABLE, hdev, data, len);
+	cmd = mgmt_pending_new(sk, MGMT_OP_SET_CONNECTABLE, hdev, data, len);
 	if (!cmd) {
 		err = -ENOMEM;
 		goto failed;
@@ -1643,8 +1645,8 @@ static int set_connectable(struct sock *sk, struct hci_dev *hdev, void *data,
 		hci_dev_clear_flag(hdev, HCI_CONNECTABLE);
 	}
 
-	queue_work(hdev->req_workqueue, &hdev->connectable_update);
-	err = 0;
+	err = hci_cmd_sync_queue(hdev, set_connectable_sync, cmd,
+				 mgmt_set_connectable_complete);
 
 failed:
 	hci_dev_unlock(hdev);
Signature · 1 line
2.33.1
maintainer
#2 lore raw

Re: [PATCH 2/3] Bluetooth: hci_sync: Convert MGMT_OP_SET_CONNECTABLE to use cmd_sync

Hi Luiz,

Quoted 11 lines

This makes MGMT_OP_SET_CONNEABLE use hci_cmd_sync_queue instead of use a dedicated connetable_update work.

---

include/net/bluetooth/hci_core.h |  2 --
include/net/bluetooth/hci_sync.h |  2 ++
net/bluetooth/hci_request.c      | 43 --------------------------------
net/bluetooth/hci_sync.c         | 31 +++++++++++++++++++++++
net/bluetooth/mgmt.c             | 36 +++++++++++++-------------
5 files changed, 52 insertions(+), 62 deletions(-)

Patch has been applied to bluetooth-next tree.

Regards

Marcel

author maintainer
#3 lore raw

PATCH 3/3 Bluetooth: hci_request: Remove bg_scan_update work

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

This work is no longer necessary since all the code using it has been converted to use hci_passive_scan/hci_passive_scan_sync.

---
 include/net/bluetooth/hci_core.h |   1 -
 net/bluetooth/hci_request.c      | 107 -------------------------------
 net/bluetooth/hci_request.h      |   5 --
 3 files changed, 113 deletions(-)
include/net/bluetooth/hci_core.h +0 -1
index 70f2e16de18b..71dc02f1c4a1 100644
@@ -494,7 +494,6 @@ struct hci_dev {
 	struct work_struct	tx_work;
 
 	struct work_struct	discov_update;
-	struct work_struct	bg_scan_update;
 	struct work_struct	scan_update;
 	struct delayed_work	le_scan_disable;
 	struct delayed_work	le_scan_restart;
net/bluetooth/hci_request.c +0 -107

131 lines not on this page · raw message

net/bluetooth/hci_request.h +0 -5
index ba75c2da70f4..5f8e8846ec74 100644
@@ -127,10 +127,5 @@ int hci_abort_conn(struct hci_conn *conn, u8 reason);
 void __hci_abort_conn(struct hci_request *req, struct hci_conn *conn,
 		      u8 reason);
 
-static inline void hci_update_background_scan(struct hci_dev *hdev)
-{
-	queue_work(hdev->req_workqueue, &hdev->bg_scan_update);
-}
-
 void hci_request_setup(struct hci_dev *hdev);
 void hci_request_cancel_all(struct hci_dev *hdev);
Signature · 1 line
2.33.1
maintainer
#4 lore raw

Re: [PATCH 3/3] Bluetooth: hci_request: Remove bg_scan_update work

Hi Luiz,

Quoted 9 lines

This work is no longer necessary since all the code using it has been converted to use hci_passive_scan/hci_passive_scan_sync.

---

include/net/bluetooth/hci_core.h |   1 -
net/bluetooth/hci_request.c      | 107 -------------------------------
net/bluetooth/hci_request.h      |   5 --
3 files changed, 113 deletions(-)

patch has been applied to bluetooth-next tree.

Regards

Marcel

maintainer
#5 lore raw
In reply to Luiz Augusto von Dentz

Hi Luiz,

Quoted 11 lines

This makes MGMT_OP_SET_DISCOVERABLE use hci_cmd_sync_queue instead of use a dedicated discoverable_update work.

---

include/net/bluetooth/hci_core.h |  2 -
include/net/bluetooth/hci_sync.h |  3 ++
net/bluetooth/hci_request.c      | 12 -----
net/bluetooth/hci_sync.c         | 90 +++++++++++++++++++++++++++++++-
net/bluetooth/mgmt.c             | 43 +++++++--------
5 files changed, 112 insertions(+), 38 deletions(-)

patch has been applied to bluetooth-next tree.

Regards

Marcel