[Bluetooth] Integrate services into the driver model
[pandora-kernel.git] / net / bluetooth / bnep / core.c
index 682bf20..2312d05 100644 (file)
@@ -29,7 +29,6 @@
  * $Id: core.c,v 1.20 2002/08/04 21:23:58 maxk Exp $
  */ 
 
-#include <linux/config.h>
 #include <linux/module.h>
 
 #include <linux/kernel.h>
@@ -52,6 +51,7 @@
 #include <asm/unaligned.h>
 
 #include <net/bluetooth/bluetooth.h>
+#include <net/bluetooth/hci_core.h>
 #include <net/bluetooth/l2cap.h>
 
 #include "bnep.h"
@@ -75,7 +75,7 @@ static struct bnep_session *__bnep_get_session(u8 *dst)
 
        list_for_each(p, &bnep_session_list) {
                s = list_entry(p, struct bnep_session, list);   
-               if (!memcmp(dst, s->eh.h_source, ETH_ALEN))
+               if (!compare_ether_addr(dst, s->eh.h_source))
                        return s;
        }
        return NULL;
@@ -420,10 +420,10 @@ static inline int bnep_tx_frame(struct bnep_session *s, struct sk_buff *skb)
        iv[il++] = (struct kvec) { &type, 1 };
        len++;
 
-       if (!memcmp(eh->h_dest, s->eh.h_source, ETH_ALEN))
+       if (!compare_ether_addr(eh->h_dest, s->eh.h_source))
                type |= 0x01;
 
-       if (!memcmp(eh->h_source, s->eh.h_dest, ETH_ALEN))
+       if (!compare_ether_addr(eh->h_source, s->eh.h_dest))
                type |= 0x02;
 
        if (type)
@@ -516,6 +516,26 @@ static int bnep_session(void *arg)
        return 0;
 }
 
+static struct device *bnep_get_device(struct bnep_session *session)
+{
+       bdaddr_t *src = &bt_sk(session->sock->sk)->src;
+       bdaddr_t *dst = &bt_sk(session->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;
+}
+
 int bnep_add_connection(struct bnep_connadd_req *req, struct socket *sock)
 {
        struct net_device *dev;
@@ -532,9 +552,8 @@ int bnep_add_connection(struct bnep_connadd_req *req, struct socket *sock)
        dev = alloc_netdev(sizeof(struct bnep_session),
                           (*req->device) ? req->device : "bnep%d",
                           bnep_net_setup);
-       if (!dev) 
-               return ENOMEM;
-
+       if (!dev)
+               return -ENOMEM;
 
        down_write(&bnep_session_sem);
 
@@ -552,7 +571,7 @@ int bnep_add_connection(struct bnep_connadd_req *req, struct socket *sock)
        memcpy(s->eh.h_source, &dst, ETH_ALEN);
        memcpy(dev->dev_addr, s->eh.h_dest, ETH_ALEN);
 
-       s->dev = dev;
+       s->dev   = dev;
        s->sock  = sock;
        s->role  = req->role;
        s->state = BT_CONNECTED;
@@ -569,6 +588,8 @@ int bnep_add_connection(struct bnep_connadd_req *req, struct socket *sock)
        bnep_set_default_proto_filter(s);
 #endif
 
+       SET_NETDEV_DEV(dev, bnep_get_device(s));
+
        err = register_netdev(dev);
        if (err) {
                goto failed;