Commit 86a8cfc6 authored by Johan Hedberg's avatar Johan Hedberg

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: default avatarJohan Hedberg <johan.hedberg@intel.com>
Acked-by: default avatarMarcel Holtmann <marcel@holtmann.org>
parent 5f97c1df
...@@ -1561,7 +1561,6 @@ static int unpair_device(struct sock *sk, u16 index, void *data, u16 len) ...@@ -1561,7 +1561,6 @@ static int unpair_device(struct sock *sk, u16 index, void *data, u16 len)
struct hci_cp_disconnect dc; struct hci_cp_disconnect dc;
struct pending_cmd *cmd; struct pending_cmd *cmd;
struct hci_conn *conn; struct hci_conn *conn;
u8 status = 0;
int err; int err;
if (len != sizeof(*cp)) if (len != sizeof(*cp))
...@@ -1579,32 +1578,38 @@ static int unpair_device(struct sock *sk, u16 index, void *data, u16 len) ...@@ -1579,32 +1578,38 @@ static int unpair_device(struct sock *sk, u16 index, void *data, u16 len)
bacpy(&rp.addr.bdaddr, &cp->addr.bdaddr); bacpy(&rp.addr.bdaddr, &cp->addr.bdaddr);
rp.addr.type = cp->addr.type; 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) if (cp->addr.type == MGMT_ADDR_BREDR)
err = hci_remove_link_key(hdev, &cp->addr.bdaddr); err = hci_remove_link_key(hdev, &cp->addr.bdaddr);
else else
err = hci_remove_ltk(hdev, &cp->addr.bdaddr); err = hci_remove_ltk(hdev, &cp->addr.bdaddr);
if (err < 0) { if (err < 0) {
status = MGMT_STATUS_NOT_PAIRED; err = cmd_complete(sk, index, MGMT_OP_UNPAIR_DEVICE,
goto unlock; MGMT_STATUS_NOT_PAIRED,
}
if (!test_bit(HCI_UP, &hdev->flags) || !cp->disconnect) {
err = cmd_complete(sk, index, MGMT_OP_UNPAIR_DEVICE, status,
&rp, sizeof(rp)); &rp, sizeof(rp));
device_unpaired(hdev, &cp->addr.bdaddr, cp->addr.type, sk);
goto unlock; goto unlock;
} }
if (cp->disconnect) {
if (cp->addr.type == MGMT_ADDR_BREDR) if (cp->addr.type == MGMT_ADDR_BREDR)
conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK,
&cp->addr.bdaddr); &cp->addr.bdaddr);
else else
conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, conn = hci_conn_hash_lookup_ba(hdev, LE_LINK,
&cp->addr.bdaddr); &cp->addr.bdaddr);
} else {
conn = NULL;
}
if (!conn) { 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)); &rp, sizeof(rp));
device_unpaired(hdev, &cp->addr.bdaddr, cp->addr.type, sk); device_unpaired(hdev, &cp->addr.bdaddr, cp->addr.type, sk);
goto unlock; goto unlock;
...@@ -1624,9 +1629,6 @@ static int unpair_device(struct sock *sk, u16 index, void *data, u16 len) ...@@ -1624,9 +1629,6 @@ static int unpair_device(struct sock *sk, u16 index, void *data, u16 len)
mgmt_pending_remove(cmd); mgmt_pending_remove(cmd);
unlock: unlock:
if (err < 0)
err = cmd_complete(sk, index, MGMT_OP_UNPAIR_DEVICE, status,
&rp, sizeof(rp));
hci_dev_unlock(hdev); hci_dev_unlock(hdev);
hci_dev_put(hdev); hci_dev_put(hdev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment