linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: johan.hedberg@gmail.com
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH 1/9] Bluetooth: mgmt: Fix powered checks for commands
Date: Tue, 21 Feb 2012 17:59:57 +0200	[thread overview]
Message-ID: <1329840005-4977-1-git-send-email-johan.hedberg@gmail.com> (raw)

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

Having the HCI_AUTO_OFF flag set means that from a mgmt interface
perspective we're still not powered, so all tests for HCI_UP should also
include a test for HCI_AUTO_OFF. This patch adds a convenience macro for
it.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 net/bluetooth/mgmt.c |   26 ++++++++++++++------------
 1 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index c25cb64..c27481c 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -118,6 +118,9 @@ static const u16 mgmt_events[] = {
 
 #define SERVICE_CACHE_TIMEOUT (5 * 1000)
 
+#define hdev_is_powered(hdev) (test_bit(HCI_UP, &hdev->flags) && \
+				!test_bit(HCI_AUTO_OFF, &hdev->dev_flags))
+
 struct pending_cmd {
 	struct list_head list;
 	u16 opcode;
@@ -733,7 +736,7 @@ static int set_powered(struct sock *sk, u16 index, void *data, u16 len)
 	struct mgmt_mode *cp = data;
 	struct hci_dev *hdev;
 	struct pending_cmd *cmd;
-	int err, up;
+	int err;
 
 	BT_DBG("request for hci%u", index);
 
@@ -758,8 +761,7 @@ static int set_powered(struct sock *sk, u16 index, void *data, u16 len)
 		}
 	}
 
-	up = test_bit(HCI_UP, &hdev->flags);
-	if ((cp->val && up) || (!cp->val && !up)) {
+	if (!!cp->val == hdev_is_powered(hdev)) {
 		err = send_settings_rsp(sk, MGMT_OP_SET_POWERED, hdev);
 		goto failed;
 	}
@@ -810,7 +812,7 @@ static int set_discoverable(struct sock *sk, u16 index, void *data, u16 len)
 
 	hci_dev_lock(hdev);
 
-	if (!test_bit(HCI_UP, &hdev->flags)) {
+	if (!hdev_is_powered(hdev)) {
 		err = cmd_status(sk, index, MGMT_OP_SET_DISCOVERABLE,
 						MGMT_STATUS_NOT_POWERED);
 		goto failed;
@@ -877,7 +879,7 @@ static int set_connectable(struct sock *sk, u16 index, void *data, u16 len)
 
 	hci_dev_lock(hdev);
 
-	if (!test_bit(HCI_UP, &hdev->flags)) {
+	if (!hdev_is_powered(hdev)) {
 		err = cmd_status(sk, index, MGMT_OP_SET_CONNECTABLE,
 						MGMT_STATUS_NOT_POWERED);
 		goto failed;
@@ -1005,7 +1007,7 @@ static int set_link_security(struct sock *sk, u16 index, void *data, u16 len)
 
 	hci_dev_lock(hdev);
 
-	if (!test_bit(HCI_UP, &hdev->flags)) {
+	if (!hdev_is_powered(hdev)) {
 		err = cmd_status(sk, index, MGMT_OP_SET_LINK_SECURITY,
 						MGMT_STATUS_NOT_POWERED);
 		goto failed;
@@ -1064,7 +1066,7 @@ static int set_ssp(struct sock *sk, u16 index, void *data, u16 len)
 
 	hci_dev_lock(hdev);
 
-	if (!test_bit(HCI_UP, &hdev->flags)) {
+	if (!hdev_is_powered(hdev)) {
 		err = cmd_status(sk, index, MGMT_OP_SET_SSP,
 						MGMT_STATUS_NOT_POWERED);
 		goto failed;
@@ -1621,7 +1623,7 @@ static int pin_code_reply(struct sock *sk, u16 index, void *data, u16 len)
 
 	hci_dev_lock(hdev);
 
-	if (!test_bit(HCI_UP, &hdev->flags)) {
+	if (!hdev_is_powered(hdev)) {
 		err = cmd_status(sk, index, MGMT_OP_PIN_CODE_REPLY,
 						MGMT_STATUS_NOT_POWERED);
 		goto failed;
@@ -1690,7 +1692,7 @@ static int pin_code_neg_reply(struct sock *sk, u16 index, void *data, u16 len)
 
 	hci_dev_lock(hdev);
 
-	if (!test_bit(HCI_UP, &hdev->flags)) {
+	if (!hdev_is_powered(hdev)) {
 		err = cmd_status(sk, index, MGMT_OP_PIN_CODE_NEG_REPLY,
 						MGMT_STATUS_NOT_POWERED);
 		goto failed;
@@ -1933,7 +1935,7 @@ static int user_pairing_resp(struct sock *sk, u16 index, bdaddr_t *bdaddr,
 
 	hci_dev_lock(hdev);
 
-	if (!test_bit(HCI_UP, &hdev->flags)) {
+	if (!hdev_is_powered(hdev)) {
 		err = cmd_status(sk, index, mgmt_op, MGMT_STATUS_NOT_POWERED);
 		goto done;
 	}
@@ -2109,7 +2111,7 @@ static int read_local_oob_data(struct sock *sk, u16 index)
 
 	hci_dev_lock(hdev);
 
-	if (!test_bit(HCI_UP, &hdev->flags)) {
+	if (!hdev_is_powered(hdev)) {
 		err = cmd_status(sk, index, MGMT_OP_READ_LOCAL_OOB_DATA,
 						MGMT_STATUS_NOT_POWERED);
 		goto unlock;
@@ -2280,7 +2282,7 @@ static int start_discovery(struct sock *sk, u16 index,
 
 	hci_dev_lock(hdev);
 
-	if (!test_bit(HCI_UP, &hdev->flags)) {
+	if (!hdev_is_powered(hdev)) {
 		err = cmd_status(sk, index, MGMT_OP_START_DISCOVERY,
 						MGMT_STATUS_NOT_POWERED);
 		goto failed;
-- 
1.7.9


             reply	other threads:[~2012-02-21 15:59 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-21 15:59 johan.hedberg [this message]
2012-02-21 15:59 ` [PATCH 2/9] Bluetooth: mgmt: Fix set_local_name and set_dev_class powered checks johan.hedberg
2012-02-21 16:09   ` Marcel Holtmann
2012-02-21 15:59 ` [PATCH 3/9] Bluetooth: mgmt: Allow connectable/discoverable changes in off state johan.hedberg
2012-02-21 16:14   ` Marcel Holtmann
2012-02-21 16:00 ` [PATCH 4/9] Bluetooth: mgmt: Fix current settings values when powered off johan.hedberg
2012-02-21 16:15   ` Marcel Holtmann
2012-02-21 16:00 ` [PATCH 5/9] Bluetooth: mgmt: Add convenience function for sending New Settings johan.hedberg
2012-02-21 16:15   ` Marcel Holtmann
2012-02-21 16:00 ` [PATCH 6/9] Bluetooth: mgmt: Fix New Settings event for connectable/discoverable johan.hedberg
2012-02-21 16:21   ` Marcel Holtmann
2012-02-21 17:46     ` Johan Hedberg
2012-02-21 16:00 ` [PATCH 7/9] Bluetooth: mgmt: Fix set_fast_connectable error return johan.hedberg
2012-02-21 16:16   ` Marcel Holtmann
2012-02-21 16:00 ` [PATCH 8/9] Bluetooth: mgmt: Fix pairable setting upon initialization johan.hedberg
2012-02-21 16:17   ` Marcel Holtmann
2012-02-21 16:00 ` [PATCH 9/9] Bluetooth: Fix clearing of persistent dev_flags johan.hedberg
2012-02-21 16:18   ` Marcel Holtmann
2012-02-21 16:09 ` [PATCH 1/9] Bluetooth: mgmt: Fix powered checks for commands 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=1329840005-4977-1-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;
as well as URLs for NNTP newsgroup(s).