summaryrefslogtreecommitdiffstats
path: root/net/bluetooth/mgmt.c
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@intel.com>2012-02-22 15:53:34 -0500
committerJohan Hedberg <johan.hedberg@intel.com>2012-02-23 06:07:01 -0500
commit86a8cfc6d0428f32d702ec59c1b3ef38541a6821 (patch)
tree32e643285bb2d3f96776077f1c00ef5840aec112 /net/bluetooth/mgmt.c
parent5f97c1df5563349795f26ed249e2a8840237c569 (diff)
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)
1561 struct hci_cp_disconnect dc; 1561 struct hci_cp_disconnect dc;
1562 struct pending_cmd *cmd; 1562 struct pending_cmd *cmd;
1563 struct hci_conn *conn; 1563 struct hci_conn *conn;
1564 u8 status = 0;
1565 int err; 1564 int err;
1566 1565
1567 if (len != sizeof(*cp)) 1566 if (len != sizeof(*cp))
@@ -1579,32 +1578,38 @@ static int unpair_device(struct sock *sk, u16 index, void *data, u16 len)
1579 bacpy(&rp.addr.bdaddr, &cp->addr.bdaddr); 1578 bacpy(&rp.addr.bdaddr, &cp->addr.bdaddr);
1580 rp.addr.type = cp->addr.type; 1579 rp.addr.type = cp->addr.type;
1581 1580
1581 if (!hdev_is_powered(hdev)) {
1582 err = cmd_complete(sk, index, MGMT_OP_UNPAIR_DEVICE,
1583 MGMT_STATUS_NOT_POWERED,
1584 &rp, sizeof(rp));
1585 goto unlock;
1586 }
1587
1582 if (cp->addr.type == MGMT_ADDR_BREDR) 1588 if (cp->addr.type == MGMT_ADDR_BREDR)
1583 err = hci_remove_link_key(hdev, &cp->addr.bdaddr); 1589 err = hci_remove_link_key(hdev, &cp->addr.bdaddr);
1584 else 1590 else
1585 err = hci_remove_ltk(hdev, &cp->addr.bdaddr); 1591 err = hci_remove_ltk(hdev, &cp->addr.bdaddr);
1586 1592
1587 if (err < 0) { 1593 if (err < 0) {
1588 status = MGMT_STATUS_NOT_PAIRED; 1594 err = cmd_complete(sk, index, MGMT_OP_UNPAIR_DEVICE,
1589 goto unlock; 1595 MGMT_STATUS_NOT_PAIRED,
1590 } 1596 &rp, sizeof(rp));
1591
1592 if (!test_bit(HCI_UP, &hdev->flags) || !cp->disconnect) {
1593 err = cmd_complete(sk, index, MGMT_OP_UNPAIR_DEVICE, status,
1594 &rp, sizeof(rp));
1595 device_unpaired(hdev, &cp->addr.bdaddr, cp->addr.type, sk);
1596 goto unlock; 1597 goto unlock;
1597 } 1598 }
1598 1599
1599 if (cp->addr.type == MGMT_ADDR_BREDR) 1600 if (cp->disconnect) {
1600 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, 1601 if (cp->addr.type == MGMT_ADDR_BREDR)
1602 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK,
1601 &cp->addr.bdaddr); 1603 &cp->addr.bdaddr);
1602 else 1604 else
1603 conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, 1605 conn = hci_conn_hash_lookup_ba(hdev, LE_LINK,
1604 &cp->addr.bdaddr); 1606 &cp->addr.bdaddr);
1607 } else {
1608 conn = NULL;
1609 }
1605 1610
1606 if (!conn) { 1611 if (!conn) {
1607 err = cmd_complete(sk, index, MGMT_OP_UNPAIR_DEVICE, status, 1612 err = cmd_complete(sk, index, MGMT_OP_UNPAIR_DEVICE, 0,
1608 &rp, sizeof(rp)); 1613 &rp, sizeof(rp));
1609 device_unpaired(hdev, &cp->addr.bdaddr, cp->addr.type, sk); 1614 device_unpaired(hdev, &cp->addr.bdaddr, cp->addr.type, sk);
1610 goto unlock; 1615 goto unlock;
@@ -1624,9 +1629,6 @@ static int unpair_device(struct sock *sk, u16 index, void *data, u16 len)
1624 mgmt_pending_remove(cmd); 1629 mgmt_pending_remove(cmd);
1625 1630
1626unlock: 1631unlock:
1627 if (err < 0)
1628 err = cmd_complete(sk, index, MGMT_OP_UNPAIR_DEVICE, status,
1629 &rp, sizeof(rp));
1630 hci_dev_unlock(hdev); 1632 hci_dev_unlock(hdev);
1631 hci_dev_put(hdev); 1633 hci_dev_put(hdev);
1632 1634