Bluetooth: mgmt: Fix set_local_name and set_dev_class powered checks
authorJohan Hedberg <johan.hedberg@intel.com>
Tue, 21 Feb 2012 12:32:24 +0000 (14:32 +0200)
committerJohan Hedberg <johan.hedberg@intel.com>
Tue, 21 Feb 2012 16:47:46 +0000 (18:47 +0200)
Both the Set Local Name and the Set Device Class commands should fail if
the adapter is not powered on.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Acked-by: Marcel Holtmann <marcel@holtmann.org>
net/bluetooth/mgmt.c

index c27481c3c95dae72d96fdd45210edbf5551aef91..03a13843cd1624a2e6b89e506f18dd9037ba95bc 100644 (file)
@@ -1272,6 +1272,12 @@ static int set_dev_class(struct sock *sk, u16 index, void *data, u16 len)
 
        hci_dev_lock(hdev);
 
+       if (!hdev_is_powered(hdev)) {
+               err = cmd_status(sk, index, MGMT_OP_SET_DEV_CLASS,
+                                               MGMT_STATUS_NOT_POWERED);
+               goto unlock;
+       }
+
        hdev->major_class = cp->major;
        hdev->minor_class = cp->minor;
 
@@ -1288,6 +1294,7 @@ static int set_dev_class(struct sock *sk, u16 index, void *data, u16 len)
                err = cmd_complete(sk, index, MGMT_OP_SET_DEV_CLASS, 0,
                                                                NULL, 0);
 
+unlock:
        hci_dev_unlock(hdev);
        hci_dev_put(hdev);
 
@@ -2076,6 +2083,12 @@ static int set_local_name(struct sock *sk, u16 index, void *data,
 
        hci_dev_lock(hdev);
 
+       if (!hdev_is_powered(hdev)) {
+               err = cmd_status(sk, index, MGMT_OP_SET_LOCAL_NAME,
+                                               MGMT_STATUS_NOT_POWERED);
+               goto failed;
+       }
+
        cmd = mgmt_pending_add(sk, MGMT_OP_SET_LOCAL_NAME, hdev, data,
                                                                        len);
        if (!cmd) {