Bluetooth: Fix mgmt response when HCI_Write_Scan_Enable fails
authorJohan Hedberg <johan.hedberg@intel.com>
Mon, 7 Nov 2011 20:16:03 +0000 (22:16 +0200)
committerGustavo F. Padovan <padovan@profusion.mobi>
Tue, 8 Nov 2011 14:54:10 +0000 (12:54 -0200)
A proper mgmt_command_status should be returned to user-space if either
discoverable or connectable enabling fails.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
include/net/bluetooth/hci_core.h
net/bluetooth/hci_event.c
net/bluetooth/mgmt.c

index 5803c1ebcefa7ae95be1cbc38b2441255f6a62b0..c233bceb3cccc8fc59ace45c4c44579e3a7446e4 100644 (file)
@@ -911,6 +911,7 @@ int mgmt_index_removed(u16 index);
 int mgmt_powered(u16 index, u8 powered);
 int mgmt_discoverable(u16 index, u8 discoverable);
 int mgmt_connectable(u16 index, u8 connectable);
+int mgmt_write_scan_failed(u16 index, u8 scan, u8 status);
 int mgmt_new_key(u16 index, struct link_key *key, u8 persistent);
 int mgmt_connected(u16 index, bdaddr_t *bdaddr, u8 link_type);
 int mgmt_disconnected(u16 index, bdaddr_t *bdaddr);
index cf992656593742a43788f47a7742a06ff529055e..176cecae4b42c899b74fc44381a584360bd0d267 100644 (file)
@@ -280,11 +280,14 @@ static void hci_cc_write_scan_enable(struct hci_dev *hdev, struct sk_buff *skb)
        if (!sent)
                return;
 
-       if (status != 0)
-               goto done;
-
        param = *((__u8 *) sent);
 
+       if (status != 0) {
+               mgmt_write_scan_failed(hdev->id, param, status);
+               hdev->discov_timeout = 0;
+               goto done;
+       }
+
        old_pscan = test_and_clear_bit(HCI_PSCAN, &hdev->flags);
        old_iscan = test_and_clear_bit(HCI_ISCAN, &hdev->flags);
 
index 724d4fee2bd7960ef49e52e3fb1e1537848a2b7a..0cb023e0edb402fcff4a438b7e0f275bf488db7c 100644 (file)
@@ -2056,6 +2056,19 @@ int mgmt_connectable(u16 index, u8 connectable)
        return ret;
 }
 
+int mgmt_write_scan_failed(u16 index, u8 scan, u8 status)
+{
+       if (scan & SCAN_PAGE)
+               mgmt_pending_foreach(MGMT_OP_SET_CONNECTABLE, index,
+                                               cmd_status_rsp, &status);
+
+       if (scan & SCAN_INQUIRY)
+               mgmt_pending_foreach(MGMT_OP_SET_DISCOVERABLE, index,
+                                               cmd_status_rsp, &status);
+
+       return 0;
+}
+
 int mgmt_new_key(u16 index, struct link_key *key, u8 persistent)
 {
        struct mgmt_ev_new_key ev;