All of lore.kernel.org
 help / color / mirror / Atom feed
From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH v8 19/23] Bluetooth: hci_sync: Convert MGMT_OP_SET_ADVERTISING
Date: Wed, 27 Oct 2021 16:58:56 -0700	[thread overview]
Message-ID: <20211027235900.1882863-20-luiz.dentz@gmail.com> (raw)
In-Reply-To: <20211027235900.1882863-1-luiz.dentz@gmail.com>

From: Brian Gix <brian.gix@intel.com>

mgmt-test paths:
Set powered on - Privacy and Advertising
Set Advertising on - Success 2
Set Advertising on - Appearance 1
Set Advertising on - Local name 1
Set Advertising on - Name + Appear 1
Add Advertising - Success 4
Add Advertising - Success 5
Add Ext Advertising - Success 4
Add Ext Advertising - Success 5

Signed-off-by: Brian Gix <brian.gix@intel.com>
---
 net/bluetooth/mgmt.c | 103 ++++++++++++++++++++-----------------------
 1 file changed, 48 insertions(+), 55 deletions(-)

diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index b8b3176e05b6..48a901c93141 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -5608,29 +5608,25 @@ static int set_device_id(struct sock *sk, struct hci_dev *hdev, void *data,
 	return err;
 }
 
-static void enable_advertising_instance(struct hci_dev *hdev, u8 status,
-					u16 opcode)
+static void enable_advertising_instance(struct hci_dev *hdev, int err)
 {
-	bt_dev_dbg(hdev, "status %u", status);
+	if (err)
+		bt_dev_err(hdev, "failed to re-configure advertising %d", err);
+	else
+		bt_dev_dbg(hdev, "status %d", err);
 }
 
-static void set_advertising_complete(struct hci_dev *hdev, u8 status,
-				     u16 opcode)
+static void set_advertising_complete(struct hci_dev *hdev, void *data, int err)
 {
 	struct cmd_lookup match = { NULL, hdev };
-	struct hci_request req;
 	u8 instance;
 	struct adv_info *adv_instance;
-	int err;
-
-	hci_dev_lock(hdev);
+	u8 status = mgmt_status(err);
 
 	if (status) {
-		u8 mgmt_err = mgmt_status(status);
-
 		mgmt_pending_foreach(MGMT_OP_SET_ADVERTISING, hdev,
-				     cmd_status_rsp, &mgmt_err);
-		goto unlock;
+				     cmd_status_rsp, &status);
+		return;
 	}
 
 	if (hci_dev_test_flag(hdev, HCI_LE_ADV))
@@ -5662,30 +5658,55 @@ static void set_advertising_complete(struct hci_dev *hdev, u8 status,
 	 */
 	if (hci_dev_test_flag(hdev, HCI_ADVERTISING) ||
 	    list_empty(&hdev->adv_instances))
-		goto unlock;
+		return;
 
 	instance = hdev->cur_adv_instance;
 	if (!instance) {
 		adv_instance = list_first_entry_or_null(&hdev->adv_instances,
 							struct adv_info, list);
 		if (!adv_instance)
-			goto unlock;
+			return;
 
 		instance = adv_instance->instance;
 	}
 
-	hci_req_init(&req, hdev);
+	err = hci_schedule_adv_instance_sync(hdev, instance, true);
+
+	enable_advertising_instance(hdev, err);
+}
 
-	err = __hci_req_schedule_adv_instance(&req, instance, true);
+static int set_adv_sync(struct hci_dev *hdev, void *data)
+{
+	struct mgmt_pending_cmd *cmd = data;
+	struct mgmt_mode *cp = cmd->param;
+	u8 val = !!cp->val;
 
-	if (!err)
-		err = hci_req_run(&req, enable_advertising_instance);
+	if (cp->val == 0x02)
+		hci_dev_set_flag(hdev, HCI_ADVERTISING_CONNECTABLE);
+	else
+		hci_dev_clear_flag(hdev, HCI_ADVERTISING_CONNECTABLE);
 
-	if (err)
-		bt_dev_err(hdev, "failed to re-configure advertising");
+	cancel_adv_timeout(hdev);
 
-unlock:
-	hci_dev_unlock(hdev);
+	if (val) {
+		/* Switch to instance "0" for the Set Advertising setting.
+		 * We cannot use update_[adv|scan_rsp]_data() here as the
+		 * HCI_ADVERTISING flag is not yet set.
+		 */
+		hdev->cur_adv_instance = 0x00;
+
+		if (ext_adv_capable(hdev)) {
+			hci_start_ext_adv_sync(hdev, 0x00);
+		} else {
+			hci_update_adv_data_sync(hdev, 0x00);
+			hci_update_scan_rsp_data_sync(hdev, 0x00);
+			hci_enable_advertising_sync(hdev);
+		}
+	} else {
+		hci_disable_advertising_sync(hdev);
+	}
+
+	return 0;
 }
 
 static int set_advertising(struct sock *sk, struct hci_dev *hdev, void *data,
@@ -5693,7 +5714,6 @@ static int set_advertising(struct sock *sk, struct hci_dev *hdev, void *data,
 {
 	struct mgmt_mode *cp = data;
 	struct mgmt_pending_cmd *cmd;
-	struct hci_request req;
 	u8 val, status;
 	int err;
 
@@ -5759,40 +5779,13 @@ static int set_advertising(struct sock *sk, struct hci_dev *hdev, void *data,
 	}
 
 	cmd = mgmt_pending_add(sk, MGMT_OP_SET_ADVERTISING, hdev, data, len);
-	if (!cmd) {
+	if (!cmd)
 		err = -ENOMEM;
-		goto unlock;
-	}
-
-	hci_req_init(&req, hdev);
-
-	if (cp->val == 0x02)
-		hci_dev_set_flag(hdev, HCI_ADVERTISING_CONNECTABLE);
 	else
-		hci_dev_clear_flag(hdev, HCI_ADVERTISING_CONNECTABLE);
-
-	cancel_adv_timeout(hdev);
+		err = hci_cmd_sync_queue(hdev, set_adv_sync, cmd,
+					 set_advertising_complete);
 
-	if (val) {
-		/* Switch to instance "0" for the Set Advertising setting.
-		 * We cannot use update_[adv|scan_rsp]_data() here as the
-		 * HCI_ADVERTISING flag is not yet set.
-		 */
-		hdev->cur_adv_instance = 0x00;
-
-		if (ext_adv_capable(hdev)) {
-			__hci_req_start_ext_adv(&req, 0x00);
-		} else {
-			__hci_req_update_adv_data(&req, 0x00);
-			__hci_req_update_scan_rsp_data(&req, 0x00);
-			__hci_req_enable_advertising(&req);
-		}
-	} else {
-		__hci_req_disable_advertising(&req);
-	}
-
-	err = hci_req_run(&req, set_advertising_complete);
-	if (err < 0)
+	if (err < 0 && cmd)
 		mgmt_pending_remove(cmd);
 
 unlock:
-- 
2.31.1


  parent reply	other threads:[~2021-10-27 23:59 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-27 23:58 [PATCH v8 00/23] Bluetooth: HCI command synchronization Luiz Augusto von Dentz
2021-10-27 23:58 ` [PATCH v8 01/23] Bluetooth: Add helper for serialized HCI command execution Luiz Augusto von Dentz
2021-10-27 23:58 ` [PATCH v8 02/23] Bluetooth: hci_sync: Make use of hci_cmd_sync_queue set 1 Luiz Augusto von Dentz
2021-10-27 23:58 ` [PATCH v8 03/23] Bluetooth: hci_sync: Make use of hci_cmd_sync_queue set 2 Luiz Augusto von Dentz
2021-10-27 23:58 ` [PATCH v8 04/23] Bluetooth: hci_sync: Make use of hci_cmd_sync_queue set 3 Luiz Augusto von Dentz
2021-10-27 23:58 ` [PATCH v8 05/23] Bluetooth: hci_sync: Enable advertising when LL privacy is enabled Luiz Augusto von Dentz
2021-10-27 23:58 ` [PATCH v8 06/23] Bluetooth: hci_sync: Rework background scan Luiz Augusto von Dentz
2021-10-27 23:58 ` [PATCH v8 07/23] Bluetooth: hci_sync: Convert MGMT_SET_POWERED Luiz Augusto von Dentz
2021-10-27 23:58 ` [PATCH v8 08/23] Bluetooth: hci_sync: Convert MGMT_OP_START_DISCOVERY Luiz Augusto von Dentz
2021-10-27 23:58 ` [PATCH v8 09/23] Bluetooth: hci_sync: Convert MGMT_OP_SET_FAST_CONNECTABLE Luiz Augusto von Dentz
2021-10-27 23:58 ` [PATCH v8 10/23] Bluetooth: hci_sync: Enable synch'd set_bredr Luiz Augusto von Dentz
2021-10-27 23:58 ` [PATCH v8 11/23] Bluetooth: hci_sync: Convert MGMT_OP_GET_CONN_INFO Luiz Augusto von Dentz
2021-10-27 23:58 ` [PATCH v8 12/23] Bluetooth: hci_sync: Convert MGMT_OP_SET_SECURE_CONN Luiz Augusto von Dentz
2021-10-27 23:58 ` [PATCH v8 13/23] Bluetooth: hci_sync: Convert MGMT_OP_GET_CLOCK_INFO Luiz Augusto von Dentz
2021-10-27 23:58 ` [PATCH v8 14/23] Bluetooth: hci_sync: Convert MGMT_OP_SET_LE Luiz Augusto von Dentz
2021-10-27 23:58 ` [PATCH v8 15/23] Bluetooth: hci_sync: Convert MGMT_OP_READ_LOCAL_OOB_DATA Luiz Augusto von Dentz
2021-10-27 23:58 ` [PATCH v8 16/23] Bluetooth: hci_sync: Convert MGMT_OP_READ_LOCAL_OOB_EXT_DATA Luiz Augusto von Dentz
2021-10-27 23:58 ` [PATCH v8 17/23] Bluetooth: hci_sync: Convert MGMT_OP_SET_LOCAL_NAME Luiz Augusto von Dentz
2021-10-27 23:58 ` [PATCH v8 18/23] Bluetooth: hci_sync: Convert MGMT_OP_SET_PHY_CONFIGURATION Luiz Augusto von Dentz
2021-10-27 23:58 ` Luiz Augusto von Dentz [this message]
2021-10-27 23:58 ` [PATCH v8 20/23] Bluetooth: hci_sync: Convert adv_expire Luiz Augusto von Dentz
2021-10-27 23:58 ` [PATCH v8 21/23] Bluetooth: hci_sync: Convert MGMT_OP_SSP Luiz Augusto von Dentz
2021-10-27 23:58 ` [PATCH v8 22/23] Bluetooth: hci_sync: Rework init stages Luiz Augusto von Dentz
2021-10-27 23:59 ` [PATCH v8 23/23] Bluetooth: hci_sync: Rework hci_suspend_notifier Luiz Augusto von Dentz
2021-10-29 14:54 ` [PATCH v8 00/23] Bluetooth: HCI command synchronization Marcel Holtmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211027235900.1882863-20-luiz.dentz@gmail.com \
    --to=luiz.dentz@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.