[Bluetooth] Integrate services into the driver model
[pandora-kernel.git] / net / bluetooth / hidp / core.c
index de8af5f..03b5dad 100644 (file)
@@ -20,7 +20,6 @@
    SOFTWARE IS DISCLAIMED.
 */
 
-#include <linux/config.h>
 #include <linux/module.h>
 
 #include <linux/types.h>
@@ -41,6 +40,7 @@
 #include <linux/input.h>
 
 #include <net/bluetooth/bluetooth.h>
+#include <net/bluetooth/hci_core.h>
 #include <net/bluetooth/l2cap.h>
 
 #include "hidp.h"
@@ -520,7 +520,7 @@ static int hidp_session(void *arg)
 
        if (session->input) {
                input_unregister_device(session->input);
-               kfree(session->input);
+               session->input = NULL;
        }
 
        up_write(&hidp_session_sem);
@@ -529,6 +529,26 @@ static int hidp_session(void *arg)
        return 0;
 }
 
+static struct device *hidp_get_device(struct hidp_session *session)
+{
+       bdaddr_t *src = &bt_sk(session->ctrl_sock->sk)->src;
+       bdaddr_t *dst = &bt_sk(session->ctrl_sock->sk)->dst;
+       struct hci_dev *hdev;
+       struct hci_conn *conn;
+
+       hdev = hci_get_route(dst, src);
+       if (!hdev)
+               return NULL;
+
+       conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, dst);
+       if (!conn)
+               return NULL;
+
+       hci_dev_put(hdev);
+
+       return &conn->dev;
+}
+
 static inline void hidp_setup_input(struct hidp_session *session, struct hidp_connadd_req *req)
 {
        struct input_dev *input = session->input;
@@ -536,6 +556,8 @@ static inline void hidp_setup_input(struct hidp_session *session, struct hidp_co
 
        input->private = session;
 
+       input->name = "Bluetooth HID Boot Protocol Device";
+
        input->id.bustype = BUS_BLUETOOTH;
        input->id.vendor  = req->vendor;
        input->id.product = req->product;
@@ -565,6 +587,8 @@ static inline void hidp_setup_input(struct hidp_session *session, struct hidp_co
                input->relbit[0] |= BIT(REL_WHEEL);
        }
 
+       input->cdev.dev = hidp_get_device(session);
+
        input->event = hidp_input_event;
 
        input_register_device(input);
@@ -581,17 +605,15 @@ int hidp_add_connection(struct hidp_connadd_req *req, struct socket *ctrl_sock,
                        bacmp(&bt_sk(ctrl_sock->sk)->dst, &bt_sk(intr_sock->sk)->dst))
                return -ENOTUNIQ;
 
-       session = kmalloc(sizeof(struct hidp_session), GFP_KERNEL);
-       if (!session) 
+       session = kzalloc(sizeof(struct hidp_session), GFP_KERNEL);
+       if (!session)
                return -ENOMEM;
-       memset(session, 0, sizeof(struct hidp_session));
 
-       session->input = kmalloc(sizeof(struct input_dev), GFP_KERNEL);
+       session->input = input_allocate_device();
        if (!session->input) {
                kfree(session);
                return -ENOMEM;
        }
-       memset(session->input, 0, sizeof(struct input_dev));
 
        down_write(&hidp_session_sem);
 
@@ -651,15 +673,15 @@ unlink:
 
        __hidp_unlink_session(session);
 
-       if (session->input)
+       if (session->input) {
                input_unregister_device(session->input);
+               session->input = NULL; /* don't try to free it here */
+       }
 
 failed:
        up_write(&hidp_session_sem);
 
-       if (session->input)
-               kfree(session->input);
-
+       kfree(session->input);
        kfree(session);
        return err;
 }