summaryrefslogtreecommitdiffstats
path: root/net/bluetooth/mgmt.c
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@intel.com>2012-02-22 22:53:34 +0200
committerJohan Hedberg <johan.hedberg@intel.com>2012-02-23 13:07:01 +0200
commit86a8cfc6d0428f32d702ec59c1b3ef38541a6821 (patch)
tree32e643285bb2d3f96776077f1c00ef5840aec112 /net/bluetooth/mgmt.c
parent5f97c1df5563349795f26ed249e2a8840237c569 (diff)
downloadlinux-86a8cfc6d0428f32d702ec59c1b3ef38541a6821.tar.bz2
Bluetooth: mgmt: Fix unpair_device responses
This patch adds an error return when not powered and cleans up/simpifies the function logic in the same go. Signed-off-by: Johan Hedberg <johan.hedberg@intel.com> Acked-by: Marcel Holtmann <marcel@holtmann.org>
Diffstat (limited to 'net/bluetooth/mgmt.c')
-rw-r--r--net/bluetooth/mgmt.c36
1 files changed, 19 insertions, 17 deletions
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 7c7bc2a21393..36bebfb2d840 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -1561,7 +1561,6 @@ static int unpair_device(struct sock *sk, u16 index, void *data, u16 len)
struct hci_cp_disconnect dc;
struct pending_cmd *cmd;
struct hci_conn *conn;
- u8 status = 0;
int err;
if (len != sizeof(*cp))
@@ -1579,32 +1578,38 @@ static int unpair_device(struct sock *sk, u16 index, void *data, u16 len)
bacpy(&rp.addr.bdaddr, &cp->addr.bdaddr);
rp.addr.type = cp->addr.type;
+ if (!hdev_is_powered(hdev)) {
+ err = cmd_complete(sk, index, MGMT_OP_UNPAIR_DEVICE,
+ MGMT_STATUS_NOT_POWERED,
+ &rp, sizeof(rp));
+ goto unlock;
+ }
+
if (cp->addr.type == MGMT_ADDR_BREDR)
err = hci_remove_link_key(hdev, &cp->addr.bdaddr);
else
err = hci_remove_ltk(hdev, &cp->addr.bdaddr);
if (err < 0) {
- status = MGMT_STATUS_NOT_PAIRED;
- goto unlock;
- }
-
- if (!test_bit(HCI_UP, &hdev->flags) || !cp->disconnect) {
- err = cmd_complete(sk, index, MGMT_OP_UNPAIR_DEVICE, status,
- &rp, sizeof(rp));
- device_unpaired(hdev, &cp->addr.bdaddr, cp->addr.type, sk);
+ err = cmd_complete(sk, index, MGMT_OP_UNPAIR_DEVICE,
+ MGMT_STATUS_NOT_PAIRED,
+ &rp, sizeof(rp));
goto unlock;
}
- if (cp->addr.type == MGMT_ADDR_BREDR)
- conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK,
+ if (cp->disconnect) {
+ if (cp->addr.type == MGMT_ADDR_BREDR)
+ conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK,
&cp->addr.bdaddr);
- else
- conn = hci_conn_hash_lookup_ba(hdev, LE_LINK,
+ else
+ conn = hci_conn_hash_lookup_ba(hdev, LE_LINK,
&cp->addr.bdaddr);
+ } else {
+ conn = NULL;
+ }
if (!conn) {
- err = cmd_complete(sk, index, MGMT_OP_UNPAIR_DEVICE, status,
+ err = cmd_complete(sk, index, MGMT_OP_UNPAIR_DEVICE, 0,
&rp, sizeof(rp));
device_unpaired(hdev, &cp->addr.bdaddr, cp->addr.type, sk);
goto unlock;
@@ -1624,9 +1629,6 @@ static int unpair_device(struct sock *sk, u16 index, void *data, u16 len)
mgmt_pending_remove(cmd);
unlock:
- if (err < 0)
- err = cmd_complete(sk, index, MGMT_OP_UNPAIR_DEVICE, status,
- &rp, sizeof(rp));
hci_dev_unlock(hdev);
hci_dev_put(hdev);