Linux bluetooth development
 help / color / mirror / Atom feed
From: johan.hedberg@gmail.com
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH 4/9] Bluetooth: Refactor set_connectable settings update to separate function
Date: Sat, 19 Oct 2013 23:38:18 +0300	[thread overview]
Message-ID: <1382215103-6968-5-git-send-email-johan.hedberg@gmail.com> (raw)
In-Reply-To: <1382215103-6968-1-git-send-email-johan.hedberg@gmail.com>

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

We will need to directly update the device flags and notify user space
of the new settings not just when we're powered off but also if it turns
out that there are no HCI commands to send (which can happen in
particular when BR/EDR is disabled). Since this is a considerable amount
of code, refactor it to a separate function so it can be reused for the
"no HCI commands to send" case.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 net/bluetooth/mgmt.c | 46 +++++++++++++++++++++++++++-------------------
 1 file changed, 27 insertions(+), 19 deletions(-)

diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index c363285..b74a157 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -1381,6 +1381,32 @@ unlock:
 	hci_dev_unlock(hdev);
 }
 
+static int set_connectable_update_settings(struct hci_dev *hdev,
+					   struct sock *sk, u8 val)
+{
+	bool changed = false;
+	int err;
+
+	if (!!val != test_bit(HCI_CONNECTABLE, &hdev->dev_flags))
+		changed = true;
+
+	if (val) {
+		set_bit(HCI_CONNECTABLE, &hdev->dev_flags);
+	} else {
+		clear_bit(HCI_CONNECTABLE, &hdev->dev_flags);
+		clear_bit(HCI_DISCOVERABLE, &hdev->dev_flags);
+	}
+
+	err = send_settings_rsp(sk, MGMT_OP_SET_CONNECTABLE, hdev);
+	if (err < 0)
+		return err;
+
+	if (changed)
+		return new_settings(hdev, sk);
+
+	return 0;
+}
+
 static int set_connectable(struct sock *sk, struct hci_dev *hdev, void *data,
 			   u16 len)
 {
@@ -1404,25 +1430,7 @@ static int set_connectable(struct sock *sk, struct hci_dev *hdev, void *data,
 	hci_dev_lock(hdev);
 
 	if (!hdev_is_powered(hdev)) {
-		bool changed = false;
-
-		if (!!cp->val != test_bit(HCI_CONNECTABLE, &hdev->dev_flags))
-			changed = true;
-
-		if (cp->val) {
-			set_bit(HCI_CONNECTABLE, &hdev->dev_flags);
-		} else {
-			clear_bit(HCI_CONNECTABLE, &hdev->dev_flags);
-			clear_bit(HCI_DISCOVERABLE, &hdev->dev_flags);
-		}
-
-		err = send_settings_rsp(sk, MGMT_OP_SET_CONNECTABLE, hdev);
-		if (err < 0)
-			goto failed;
-
-		if (changed)
-			err = new_settings(hdev, sk);
-
+		err = set_connectable_update_settings(hdev, sk, cp->val);
 		goto failed;
 	}
 
-- 
1.8.3.1


  parent reply	other threads:[~2013-10-19 20:38 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-19 20:38 [PATCH 0/9] Bluetooth: Add LE support for mgmt_set_discoverable johan.hedberg
2013-10-19 20:38 ` [PATCH 1/9] Bluetooth: Check for flag instead of features in update_scan_rsp_data() johan.hedberg
2013-10-19 20:38 ` [PATCH 2/9] Bluetooth: Check for flag instead of features in update_adv_data() johan.hedberg
2013-10-19 20:38 ` [PATCH 3/9] Bluetooth: Add missing check for BREDR_ENABLED flag in update_class() johan.hedberg
2013-10-19 20:38 ` johan.hedberg [this message]
2013-10-19 20:38 ` [PATCH 5/9] Bluetooth: Fix updating settings when there are no HCI commands to send johan.hedberg
2013-10-19 20:38 ` [PATCH 6/9] Bluetooth: Move mgmt_pending_find to avoid forward declarations johan.hedberg
2013-10-19 20:38 ` [PATCH 7/9] Bluetooth: Fix sending write_scan_enable when BR/EDR is disabled johan.hedberg
2013-10-19 20:38 ` [PATCH 8/9] Bluetooth: Move HCI_LIMITED_DISCOVERABLE changes to a general place johan.hedberg
2013-10-19 20:38 ` [PATCH 9/9] Bluetooth: Update Set Discoverable to support LE johan.hedberg
2013-10-19 22:11   ` Marcel Holtmann
2013-10-20  8:55   ` [PATCH v2] " johan.hedberg
2013-10-20 16:00     ` [PATCH v3] " johan.hedberg
2013-10-20 16:07       ` 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=1382215103-6968-5-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