Linux bluetooth development
 help / color / mirror / Atom feed
From: Johan Hedberg <johan.hedberg@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH v5 11/26] Bluetooth: Handle AD updating through an async request
Date: Fri, 15 Mar 2013 17:07:01 -0500	[thread overview]
Message-ID: <1363385236-25704-12-git-send-email-johan.hedberg@gmail.com> (raw)
In-Reply-To: <1363385236-25704-1-git-send-email-johan.hedberg@gmail.com>

From: Johan Hedberg <johan.hedberg@intel.com>

For proper control of the AD update and the related HCI commands it's
best to run the AD update through an async request instead of a
standalone HCI command. This patch changes the hci_update_ad() function
to take a request pointer and updates its users appropriately. E.g. the
function is no longer called after the init sequence but during stage 3
of the init sequence.

The TX power is read during the init sequence, so we don't need an
explicit update whenever it is read and the AD update based on the local
name should be done through the local name mgmt handler. The only other
user is the update based on enabling advertising. This part is still
kept as there is no mgmt API to enable it.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Acked-by: Marcel Holtmann <marcel@holtmann.org>
---
 include/net/bluetooth/hci_core.h |    4 ++--
 net/bluetooth/hci_core.c         |   29 ++++++++++-------------------
 net/bluetooth/hci_event.c        |   19 +++++++++----------
 3 files changed, 21 insertions(+), 31 deletions(-)

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index d6c3256..cb99193 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -740,8 +740,6 @@ int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 *hash,
 								u8 *randomizer);
 int hci_remove_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr);
 
-int hci_update_ad(struct hci_dev *hdev);
-
 void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb);
 
 int hci_recv_frame(struct sk_buff *skb);
@@ -1167,6 +1165,8 @@ struct hci_sec_filter {
 #define hci_req_lock(d)		mutex_lock(&d->req_lock)
 #define hci_req_unlock(d)	mutex_unlock(&d->req_lock)
 
+void hci_update_ad(struct hci_request *req);
+
 void hci_le_conn_update(struct hci_conn *conn, u16 min, u16 max,
 					u16 latency, u16 to_multiplier);
 void hci_le_start_enc(struct hci_conn *conn, __le16 ediv, __u8 rand[8],
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 9e87a91..0ffd358 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -492,8 +492,10 @@ static void hci_init3_req(struct hci_request *req, unsigned long opt)
 	if (hdev->commands[5] & 0x10)
 		hci_setup_link_policy(req);
 
-	if (lmp_le_capable(hdev))
+	if (lmp_le_capable(hdev)) {
 		hci_set_le_support(req);
+		hci_update_ad(req);
+	}
 }
 
 static int __hci_init(struct hci_dev *hdev)
@@ -936,39 +938,29 @@ static u8 create_ad(struct hci_dev *hdev, u8 *ptr)
 	return ad_len;
 }
 
-int hci_update_ad(struct hci_dev *hdev)
+void hci_update_ad(struct hci_request *req)
 {
+	struct hci_dev *hdev = req->hdev;
 	struct hci_cp_le_set_adv_data cp;
 	u8 len;
-	int err;
-
-	hci_dev_lock(hdev);
 
-	if (!lmp_le_capable(hdev)) {
-		err = -EINVAL;
-		goto unlock;
-	}
+	if (!lmp_le_capable(hdev))
+		return;
 
 	memset(&cp, 0, sizeof(cp));
 
 	len = create_ad(hdev, cp.data);
 
 	if (hdev->adv_data_len == len &&
-	    memcmp(cp.data, hdev->adv_data, len) == 0) {
-		err = 0;
-		goto unlock;
-	}
+	    memcmp(cp.data, hdev->adv_data, len) == 0)
+		return;
 
 	memcpy(hdev->adv_data, cp.data, sizeof(cp.data));
 	hdev->adv_data_len = len;
 
 	cp.length = len;
-	err = hci_send_cmd(hdev, HCI_OP_LE_SET_ADV_DATA, sizeof(cp), &cp);
 
-unlock:
-	hci_dev_unlock(hdev);
-
-	return err;
+	hci_req_add(req, HCI_OP_LE_SET_ADV_DATA, sizeof(cp), &cp);
 }
 
 /* ---- HCI ioctl helpers ---- */
@@ -1025,7 +1017,6 @@ int hci_dev_open(__u16 dev)
 		hci_dev_hold(hdev);
 		set_bit(HCI_UP, &hdev->flags);
 		hci_notify(hdev, HCI_DEV_UP);
-		hci_update_ad(hdev);
 		if (!test_bit(HCI_SETUP, &hdev->dev_flags) &&
 		    mgmt_valid_hdev(hdev)) {
 			hci_dev_lock(hdev);
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index ed4ecd9..84edacb 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -223,9 +223,6 @@ static void hci_cc_write_local_name(struct hci_dev *hdev, struct sk_buff *skb)
 		memcpy(hdev->dev_name, sent, HCI_MAX_NAME_LENGTH);
 
 	hci_dev_unlock(hdev);
-
-	if (!status && !test_bit(HCI_INIT, &hdev->flags))
-		hci_update_ad(hdev);
 }
 
 static void hci_cc_read_local_name(struct hci_dev *hdev, struct sk_buff *skb)
@@ -776,11 +773,8 @@ static void hci_cc_le_read_adv_tx_power(struct hci_dev *hdev,
 
 	BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
 
-	if (!rp->status) {
+	if (!rp->status)
 		hdev->adv_tx_power = rp->tx_power;
-		if (!test_bit(HCI_INIT, &hdev->flags))
-			hci_update_ad(hdev);
-	}
 }
 
 static void hci_cc_user_confirm_reply(struct hci_dev *hdev, struct sk_buff *skb)
@@ -877,10 +871,15 @@ static void hci_cc_le_set_adv_enable(struct hci_dev *hdev, struct sk_buff *skb)
 			clear_bit(HCI_LE_PERIPHERAL, &hdev->dev_flags);
 	}
 
-	hci_dev_unlock(hdev);
+	if (!test_bit(HCI_INIT, &hdev->flags)) {
+		struct hci_request req;
 
-	if (!test_bit(HCI_INIT, &hdev->flags))
-		hci_update_ad(hdev);
+		hci_req_init(&req, hdev);
+		hci_update_ad(&req);
+		hci_req_run(&req, NULL);
+	}
+
+	hci_dev_unlock(hdev);
 }
 
 static void hci_cc_le_set_scan_param(struct hci_dev *hdev, struct sk_buff *skb)
-- 
1.7.10.4


  parent reply	other threads:[~2013-03-15 22:07 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-15 22:06 [PATCH v5 00/26] Bluetooth: Management interface fixes Johan Hedberg
2013-03-15 22:06 ` [PATCH v5 01/26] Bluetooth: Move power on HCI command updates to their own function Johan Hedberg
2013-03-15 22:06 ` [PATCH v5 02/26] Bluetooth: Update mgmt powered HCI commands to use async requests Johan Hedberg
2013-03-15 22:06 ` [PATCH v5 03/26] Bluetooth: Wait for HCI command completion with mgmt_set_powered Johan Hedberg
2013-03-15 22:06 ` [PATCH v5 04/26] Bluetooth: Fix busy condition testing for EIR and class updates Johan Hedberg
2013-03-15 22:06 ` [PATCH v5 05/26] Bluetooth: Fix UUID/class mgmt command response synchronization Johan Hedberg
2013-03-15 22:06 ` [PATCH v5 06/26] Bluetooth: Remove useless HCI_PENDING_CLASS flag Johan Hedberg
2013-03-15 22:06 ` [PATCH v5 07/26] Bluetooth: Add a define for the HCI persistent flags mask Johan Hedberg
2013-03-15 22:06 ` [PATCH v5 08/26] Bluetooth: Clear non-persistent flags when closing HCI device Johan Hedberg
2013-03-15 22:06 ` [PATCH v5 09/26] Bluetooth: Fix clearing flags on power off before notifying mgmt Johan Hedberg
2013-03-15 22:07 ` [PATCH v5 10/26] Bluetooth: Fix waiting for EIR update when setting local name Johan Hedberg
2013-03-15 22:07 ` Johan Hedberg [this message]
2013-03-15 22:07 ` [PATCH v5 12/26] Bluetooth: Fix local name setting for LE-only controllers Johan Hedberg
2013-03-15 22:07 ` [PATCH v5 13/26] Bluetooth: Fix setting local name to the existing value Johan Hedberg
2013-03-15 22:07 ` [PATCH v5 14/26] Bluetooth: Use an async request for mgmt_set_connectable Johan Hedberg
2013-03-15 22:07 ` [PATCH v5 15/26] Bluetooth: Fix fast connectable response sending Johan Hedberg
2013-03-15 22:07 ` [PATCH v5 16/26] Bluetooth: Limit fast connectable support to >= 1.2 controllers Johan Hedberg
2013-03-15 22:07 ` [PATCH v5 17/26] Bluetooth: Fix error response for simultaneous fast connectable commands Johan Hedberg
2013-03-15 22:07 ` [PATCH v5 18/26] Bluetooth: Add proper flag for fast connectable mode Johan Hedberg
2013-03-15 22:07 ` [PATCH v5 19/26] Bluetooth: Refactor fast connectable HCI commands Johan Hedberg
2013-03-15 22:07 ` [PATCH v5 20/26] Bluetooth: Disable fast connectable when disabling connectable Johan Hedberg
2013-03-15 22:07 ` [PATCH v5 21/26] Bluetooth: Add reading of page scan parameters Johan Hedberg
2013-03-15 22:07 ` [PATCH v5 22/26] Bluetooth: Update page scan parameters after successful write commands Johan Hedberg
2013-03-15 22:07 ` [PATCH v5 23/26] Bluetooth: Fix updating page scan parameters when not necessary Johan Hedberg
2013-03-15 22:07 ` [PATCH v5 24/26] Bluetooth: Fix fast connectable state when enabling page scan Johan Hedberg
2013-03-15 22:07 ` [PATCH v5 25/26] Bluetooth: Simplify address parameters of user_pairing_resp() Johan Hedberg
2013-03-15 22:07 ` [PATCH v5 26/26] Bluetooth: Fix PIN/Confirm/Passkey response parameters Johan Hedberg
2013-03-18 17:08   ` Gustavo Padovan

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=1363385236-25704-12-git-send-email-johan.hedberg@gmail.com \
    --to=johan.hedberg@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox