aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@intel.com>2012-02-21 07:13:02 -0500
committerJohan Hedberg <johan.hedberg@intel.com>2012-02-21 11:47:44 -0500
commit4b34ee782164fbaf29b2e7c0e8cb3a898c0986ca (patch)
tree482ccb3ab4181544e48e5abd4491c5a4afbecc15
parent8ee5654034c85b3915d078147a9d1064cac1852e (diff)
Bluetooth: mgmt: Fix powered checks for commands
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> Acked-by: Marcel Holtmann <marcel@holtmann.org>
-rw-r--r--net/bluetooth/mgmt.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index c25cb648059e..c27481c3c95d 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -118,6 +118,9 @@ static const u16 mgmt_events[] = {
118 118
119#define SERVICE_CACHE_TIMEOUT (5 * 1000) 119#define SERVICE_CACHE_TIMEOUT (5 * 1000)
120 120
121#define hdev_is_powered(hdev) (test_bit(HCI_UP, &hdev->flags) && \
122 !test_bit(HCI_AUTO_OFF, &hdev->dev_flags))
123
121struct pending_cmd { 124struct pending_cmd {
122 struct list_head list; 125 struct list_head list;
123 u16 opcode; 126 u16 opcode;
@@ -733,7 +736,7 @@ static int set_powered(struct sock *sk, u16 index, void *data, u16 len)
733 struct mgmt_mode *cp = data; 736 struct mgmt_mode *cp = data;
734 struct hci_dev *hdev; 737 struct hci_dev *hdev;
735 struct pending_cmd *cmd; 738 struct pending_cmd *cmd;
736 int err, up; 739 int err;
737 740
738 BT_DBG("request for hci%u", index); 741 BT_DBG("request for hci%u", index);
739 742
@@ -758,8 +761,7 @@ static int set_powered(struct sock *sk, u16 index, void *data, u16 len)
758 } 761 }
759 } 762 }
760 763
761 up = test_bit(HCI_UP, &hdev->flags); 764 if (!!cp->val == hdev_is_powered(hdev)) {
762 if ((cp->val && up) || (!cp->val && !up)) {
763 err = send_settings_rsp(sk, MGMT_OP_SET_POWERED, hdev); 765 err = send_settings_rsp(sk, MGMT_OP_SET_POWERED, hdev);
764 goto failed; 766 goto failed;
765 } 767 }
@@ -810,7 +812,7 @@ static int set_discoverable(struct sock *sk, u16 index, void *data, u16 len)
810 812
811 hci_dev_lock(hdev); 813 hci_dev_lock(hdev);
812 814
813 if (!test_bit(HCI_UP, &hdev->flags)) { 815 if (!hdev_is_powered(hdev)) {
814 err = cmd_status(sk, index, MGMT_OP_SET_DISCOVERABLE, 816 err = cmd_status(sk, index, MGMT_OP_SET_DISCOVERABLE,
815 MGMT_STATUS_NOT_POWERED); 817 MGMT_STATUS_NOT_POWERED);
816 goto failed; 818 goto failed;
@@ -877,7 +879,7 @@ static int set_connectable(struct sock *sk, u16 index, void *data, u16 len)
877 879
878 hci_dev_lock(hdev); 880 hci_dev_lock(hdev);
879 881
880 if (!test_bit(HCI_UP, &hdev->flags)) { 882 if (!hdev_is_powered(hdev)) {
881 err = cmd_status(sk, index, MGMT_OP_SET_CONNECTABLE, 883 err = cmd_status(sk, index, MGMT_OP_SET_CONNECTABLE,
882 MGMT_STATUS_NOT_POWERED); 884 MGMT_STATUS_NOT_POWERED);
883 goto failed; 885 goto failed;
@@ -1005,7 +1007,7 @@ static int set_link_security(struct sock *sk, u16 index, void *data, u16 len)
1005 1007
1006 hci_dev_lock(hdev); 1008 hci_dev_lock(hdev);
1007 1009
1008 if (!test_bit(HCI_UP, &hdev->flags)) { 1010 if (!hdev_is_powered(hdev)) {
1009 err = cmd_status(sk, index, MGMT_OP_SET_LINK_SECURITY, 1011 err = cmd_status(sk, index, MGMT_OP_SET_LINK_SECURITY,
1010 MGMT_STATUS_NOT_POWERED); 1012 MGMT_STATUS_NOT_POWERED);
1011 goto failed; 1013 goto failed;
@@ -1064,7 +1066,7 @@ static int set_ssp(struct sock *sk, u16 index, void *data, u16 len)
1064 1066
1065 hci_dev_lock(hdev); 1067 hci_dev_lock(hdev);
1066 1068
1067 if (!test_bit(HCI_UP, &hdev->flags)) { 1069 if (!hdev_is_powered(hdev)) {
1068 err = cmd_status(sk, index, MGMT_OP_SET_SSP, 1070 err = cmd_status(sk, index, MGMT_OP_SET_SSP,
1069 MGMT_STATUS_NOT_POWERED); 1071 MGMT_STATUS_NOT_POWERED);
1070 goto failed; 1072 goto failed;
@@ -1621,7 +1623,7 @@ static int pin_code_reply(struct sock *sk, u16 index, void *data, u16 len)
1621 1623
1622 hci_dev_lock(hdev); 1624 hci_dev_lock(hdev);
1623 1625
1624 if (!test_bit(HCI_UP, &hdev->flags)) { 1626 if (!hdev_is_powered(hdev)) {
1625 err = cmd_status(sk, index, MGMT_OP_PIN_CODE_REPLY, 1627 err = cmd_status(sk, index, MGMT_OP_PIN_CODE_REPLY,
1626 MGMT_STATUS_NOT_POWERED); 1628 MGMT_STATUS_NOT_POWERED);
1627 goto failed; 1629 goto failed;
@@ -1690,7 +1692,7 @@ static int pin_code_neg_reply(struct sock *sk, u16 index, void *data, u16 len)
1690 1692
1691 hci_dev_lock(hdev); 1693 hci_dev_lock(hdev);
1692 1694
1693 if (!test_bit(HCI_UP, &hdev->flags)) { 1695 if (!hdev_is_powered(hdev)) {
1694 err = cmd_status(sk, index, MGMT_OP_PIN_CODE_NEG_REPLY, 1696 err = cmd_status(sk, index, MGMT_OP_PIN_CODE_NEG_REPLY,
1695 MGMT_STATUS_NOT_POWERED); 1697 MGMT_STATUS_NOT_POWERED);
1696 goto failed; 1698 goto failed;
@@ -1933,7 +1935,7 @@ static int user_pairing_resp(struct sock *sk, u16 index, bdaddr_t *bdaddr,
1933 1935
1934 hci_dev_lock(hdev); 1936 hci_dev_lock(hdev);
1935 1937
1936 if (!test_bit(HCI_UP, &hdev->flags)) { 1938 if (!hdev_is_powered(hdev)) {
1937 err = cmd_status(sk, index, mgmt_op, MGMT_STATUS_NOT_POWERED); 1939 err = cmd_status(sk, index, mgmt_op, MGMT_STATUS_NOT_POWERED);
1938 goto done; 1940 goto done;
1939 } 1941 }
@@ -2109,7 +2111,7 @@ static int read_local_oob_data(struct sock *sk, u16 index)
2109 2111
2110 hci_dev_lock(hdev); 2112 hci_dev_lock(hdev);
2111 2113
2112 if (!test_bit(HCI_UP, &hdev->flags)) { 2114 if (!hdev_is_powered(hdev)) {
2113 err = cmd_status(sk, index, MGMT_OP_READ_LOCAL_OOB_DATA, 2115 err = cmd_status(sk, index, MGMT_OP_READ_LOCAL_OOB_DATA,
2114 MGMT_STATUS_NOT_POWERED); 2116 MGMT_STATUS_NOT_POWERED);
2115 goto unlock; 2117 goto unlock;
@@ -2280,7 +2282,7 @@ static int start_discovery(struct sock *sk, u16 index,
2280 2282
2281 hci_dev_lock(hdev); 2283 hci_dev_lock(hdev);
2282 2284
2283 if (!test_bit(HCI_UP, &hdev->flags)) { 2285 if (!hdev_is_powered(hdev)) {
2284 err = cmd_status(sk, index, MGMT_OP_START_DISCOVERY, 2286 err = cmd_status(sk, index, MGMT_OP_START_DISCOVERY,
2285 MGMT_STATUS_NOT_POWERED); 2287 MGMT_STATUS_NOT_POWERED);
2286 goto failed; 2288 goto failed;