]> Pileus Git - ~andy/linux/blobdiff - net/bluetooth/mgmt.c
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/padovan/blueto...
[~andy/linux] / net / bluetooth / mgmt.c
index cc4ea392ac6a305faa7f084bdba73b858554ef34..fbcbef6ecceb633dc8fa8123e1b5b03f210f3549 100644 (file)
@@ -24,6 +24,7 @@
 
 #include <linux/kernel.h>
 #include <linux/uaccess.h>
+#include <linux/module.h>
 #include <asm/unaligned.h>
 
 #include <net/bluetooth/bluetooth.h>
@@ -35,6 +36,8 @@
 
 #define INQUIRY_LEN_BREDR 0x08 /* TGAP(100) */
 
+#define SERVICE_CACHE_TIMEOUT (5 * 1000)
+
 struct pending_cmd {
        struct list_head list;
        u16 opcode;
@@ -472,6 +475,32 @@ static int update_class(struct hci_dev *hdev)
        return hci_send_cmd(hdev, HCI_OP_WRITE_CLASS_OF_DEV, sizeof(cod), cod);
 }
 
+static void service_cache_off(struct work_struct *work)
+{
+       struct hci_dev *hdev = container_of(work, struct hci_dev,
+                                                       service_cache.work);
+
+       if (!test_and_clear_bit(HCI_SERVICE_CACHE, &hdev->flags))
+               return;
+
+       hci_dev_lock(hdev);
+
+       update_eir(hdev);
+       update_class(hdev);
+
+       hci_dev_unlock(hdev);
+}
+
+static void mgmt_init_hdev(struct hci_dev *hdev)
+{
+       if (!test_and_set_bit(HCI_MGMT, &hdev->flags))
+               INIT_DELAYED_WORK(&hdev->service_cache, service_cache_off);
+
+       if (!test_and_set_bit(HCI_SERVICE_CACHE, &hdev->flags))
+               schedule_delayed_work(&hdev->service_cache,
+                               msecs_to_jiffies(SERVICE_CACHE_TIMEOUT));
+}
+
 static int read_controller_info(struct sock *sk, u16 index)
 {
        struct mgmt_rp_read_info rp;
@@ -489,10 +518,8 @@ static int read_controller_info(struct sock *sk, u16 index)
 
        hci_dev_lock(hdev);
 
-       if (test_and_clear_bit(HCI_PI_MGMT_INIT, &hci_pi(sk)->flags)) {
-               set_bit(HCI_MGMT, &hdev->flags);
-               set_bit(HCI_SERVICE_CACHE, &hdev->flags);
-       }
+       if (test_and_clear_bit(HCI_PI_MGMT_INIT, &hci_pi(sk)->flags))
+               mgmt_init_hdev(hdev);
 
        memset(&rp, 0, sizeof(rp));
 
@@ -992,8 +1019,12 @@ static int set_dev_class(struct sock *sk, u16 index, unsigned char *data,
        hdev->major_class = cp->major;
        hdev->minor_class = cp->minor;
 
-       if (test_and_clear_bit(HCI_SERVICE_CACHE, &hdev->flags))
+       if (test_and_clear_bit(HCI_SERVICE_CACHE, &hdev->flags)) {
+               hci_dev_unlock(hdev);
+               cancel_delayed_work_sync(&hdev->service_cache);
+               hci_dev_lock(hdev);
                update_eir(hdev);
+       }
 
        err = update_class(hdev);
 
@@ -1660,7 +1691,7 @@ static int user_confirm_reply(struct sock *sk, u16 index, void *data, u16 len)
 static int user_confirm_neg_reply(struct sock *sk, u16 index, void *data,
                                                                        u16 len)
 {
-       struct mgmt_cp_user_confirm_reply *cp = (void *) data;
+       struct mgmt_cp_user_confirm_neg_reply *cp = data;
 
        BT_DBG("");