]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
Bluetooth: Create hci_cancel_inquiry()
authorAndre Guedes <andre.guedes@openbossa.org>
Fri, 4 Nov 2011 17:16:52 +0000 (14:16 -0300)
committerGustavo F. Padovan <padovan@profusion.mobi>
Tue, 8 Nov 2011 14:54:08 +0000 (12:54 -0200)
This patch adds a function to hci_core to cancel an ongoing inquiry.

According to the Bluetooth spec, the inquiry cancel command should
only be issued after the inquiry command has been issued, a command
status event has been received for the inquiry command, and before
the inquiry complete event occurs.

As HCI_INQUIRY flag is only set just after an inquiry command status
event occurs and it is cleared just after an inquiry complete event
occurs, the inquiry cancel command should be issued only if HCI_INQUIRY
flag is set.

Additionally, cancel inquiry related code from stop_discovery() were
replaced by a hci_cancel_inquiry() call.

Signed-off-by: Andre Guedes <andre.guedes@openbossa.org>
Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
include/net/bluetooth/hci_core.h
net/bluetooth/hci_core.c
net/bluetooth/mgmt.c

index 32f30533fd5dda5bc76dcdf8908371e9d8afa08a..20db034390b71ec8030bd7f28efd12d60536a13a 100644 (file)
@@ -971,5 +971,6 @@ void hci_le_ltk_reply(struct hci_conn *conn, u8 ltk[16]);
 void hci_le_ltk_neg_reply(struct hci_conn *conn);
 
 int hci_do_inquiry(struct hci_dev *hdev, u8 length);
+int hci_cancel_inquiry(struct hci_dev *hdev);
 
 #endif /* __HCI_CORE_H */
index e6e991331ef82f63119c41a75834fb11460b7e1a..6a4bd2d8da997ff6b6a113b120f8cf21e1d0127f 100644 (file)
@@ -2578,3 +2578,13 @@ int hci_do_inquiry(struct hci_dev *hdev, u8 length)
 
        return hci_send_cmd(hdev, HCI_OP_INQUIRY, sizeof(cp), &cp);
 }
+
+int hci_cancel_inquiry(struct hci_dev *hdev)
+{
+       BT_DBG("%s", hdev->name);
+
+       if (!test_bit(HCI_INQUIRY, &hdev->flags))
+               return -EPERM;
+
+       return hci_send_cmd(hdev, HCI_OP_INQUIRY_CANCEL, 0, NULL);
+}
index 17c7fbbc12105494a533b8285f6807f5eefd167a..0f9ef94324623f4743818333f56ba56b43b04630 100644 (file)
@@ -1649,7 +1649,7 @@ static int stop_discovery(struct sock *sk, u16 index)
                goto failed;
        }
 
-       err = hci_send_cmd(hdev, HCI_OP_INQUIRY_CANCEL, 0, NULL);
+       err = hci_cancel_inquiry(hdev);
        if (err < 0)
                mgmt_pending_remove(cmd);