aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2006-07-06 07:09:02 -0400
committerDavid S. Miller <davem@sunset.davemloft.net>2006-09-28 21:01:26 -0400
commit0a85b964e141a4b8db6eaf500ceace12f8f52f93 (patch)
tree8479bdc23230d7c1fa581af15199d7bef7268231
parentb219e3ac66183fc9771b94af931fb5fd41d586ec (diff)
[Bluetooth] Integrate services into the driver model
This patch integrates the services of the Bluetooth protocols RFCOMM, BNEP and HIDP into the driver model. This makes it possible to assign the virtual TTY, network and input devices to a specific Bluetooth connection. Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
-rw-r--r--net/bluetooth/bnep/core.c26
-rw-r--r--net/bluetooth/hidp/core.c23
-rw-r--r--net/bluetooth/rfcomm/tty.c21
3 files changed, 67 insertions, 3 deletions
diff --git a/net/bluetooth/bnep/core.c b/net/bluetooth/bnep/core.c
index e620061fb50f..2312d050eeed 100644
--- a/net/bluetooth/bnep/core.c
+++ b/net/bluetooth/bnep/core.c
@@ -51,6 +51,7 @@
51#include <asm/unaligned.h> 51#include <asm/unaligned.h>
52 52
53#include <net/bluetooth/bluetooth.h> 53#include <net/bluetooth/bluetooth.h>
54#include <net/bluetooth/hci_core.h>
54#include <net/bluetooth/l2cap.h> 55#include <net/bluetooth/l2cap.h>
55 56
56#include "bnep.h" 57#include "bnep.h"
@@ -515,6 +516,26 @@ static int bnep_session(void *arg)
515 return 0; 516 return 0;
516} 517}
517 518
519static struct device *bnep_get_device(struct bnep_session *session)
520{
521 bdaddr_t *src = &bt_sk(session->sock->sk)->src;
522 bdaddr_t *dst = &bt_sk(session->sock->sk)->dst;
523 struct hci_dev *hdev;
524 struct hci_conn *conn;
525
526 hdev = hci_get_route(dst, src);
527 if (!hdev)
528 return NULL;
529
530 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, dst);
531 if (!conn)
532 return NULL;
533
534 hci_dev_put(hdev);
535
536 return &conn->dev;
537}
538
518int bnep_add_connection(struct bnep_connadd_req *req, struct socket *sock) 539int bnep_add_connection(struct bnep_connadd_req *req, struct socket *sock)
519{ 540{
520 struct net_device *dev; 541 struct net_device *dev;
@@ -534,7 +555,6 @@ int bnep_add_connection(struct bnep_connadd_req *req, struct socket *sock)
534 if (!dev) 555 if (!dev)
535 return -ENOMEM; 556 return -ENOMEM;
536 557
537
538 down_write(&bnep_session_sem); 558 down_write(&bnep_session_sem);
539 559
540 ss = __bnep_get_session(dst); 560 ss = __bnep_get_session(dst);
@@ -551,7 +571,7 @@ int bnep_add_connection(struct bnep_connadd_req *req, struct socket *sock)
551 memcpy(s->eh.h_source, &dst, ETH_ALEN); 571 memcpy(s->eh.h_source, &dst, ETH_ALEN);
552 memcpy(dev->dev_addr, s->eh.h_dest, ETH_ALEN); 572 memcpy(dev->dev_addr, s->eh.h_dest, ETH_ALEN);
553 573
554 s->dev = dev; 574 s->dev = dev;
555 s->sock = sock; 575 s->sock = sock;
556 s->role = req->role; 576 s->role = req->role;
557 s->state = BT_CONNECTED; 577 s->state = BT_CONNECTED;
@@ -568,6 +588,8 @@ int bnep_add_connection(struct bnep_connadd_req *req, struct socket *sock)
568 bnep_set_default_proto_filter(s); 588 bnep_set_default_proto_filter(s);
569#endif 589#endif
570 590
591 SET_NETDEV_DEV(dev, bnep_get_device(s));
592
571 err = register_netdev(dev); 593 err = register_netdev(dev);
572 if (err) { 594 if (err) {
573 goto failed; 595 goto failed;
diff --git a/net/bluetooth/hidp/core.c b/net/bluetooth/hidp/core.c
index c6e3a2c27c6e..03b5dadb4951 100644
--- a/net/bluetooth/hidp/core.c
+++ b/net/bluetooth/hidp/core.c
@@ -40,6 +40,7 @@
40#include <linux/input.h> 40#include <linux/input.h>
41 41
42#include <net/bluetooth/bluetooth.h> 42#include <net/bluetooth/bluetooth.h>
43#include <net/bluetooth/hci_core.h>
43#include <net/bluetooth/l2cap.h> 44#include <net/bluetooth/l2cap.h>
44 45
45#include "hidp.h" 46#include "hidp.h"
@@ -528,6 +529,26 @@ static int hidp_session(void *arg)
528 return 0; 529 return 0;
529} 530}
530 531
532static struct device *hidp_get_device(struct hidp_session *session)
533{
534 bdaddr_t *src = &bt_sk(session->ctrl_sock->sk)->src;
535 bdaddr_t *dst = &bt_sk(session->ctrl_sock->sk)->dst;
536 struct hci_dev *hdev;
537 struct hci_conn *conn;
538
539 hdev = hci_get_route(dst, src);
540 if (!hdev)
541 return NULL;
542
543 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, dst);
544 if (!conn)
545 return NULL;
546
547 hci_dev_put(hdev);
548
549 return &conn->dev;
550}
551
531static inline void hidp_setup_input(struct hidp_session *session, struct hidp_connadd_req *req) 552static inline void hidp_setup_input(struct hidp_session *session, struct hidp_connadd_req *req)
532{ 553{
533 struct input_dev *input = session->input; 554 struct input_dev *input = session->input;
@@ -566,6 +587,8 @@ static inline void hidp_setup_input(struct hidp_session *session, struct hidp_co
566 input->relbit[0] |= BIT(REL_WHEEL); 587 input->relbit[0] |= BIT(REL_WHEEL);
567 } 588 }
568 589
590 input->cdev.dev = hidp_get_device(session);
591
569 input->event = hidp_input_event; 592 input->event = hidp_input_event;
570 593
571 input_register_device(input); 594 input_register_device(input);
diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
index bd8d671a0ba6..26f322737db0 100644
--- a/net/bluetooth/rfcomm/tty.c
+++ b/net/bluetooth/rfcomm/tty.c
@@ -38,6 +38,7 @@
38#include <linux/skbuff.h> 38#include <linux/skbuff.h>
39 39
40#include <net/bluetooth/bluetooth.h> 40#include <net/bluetooth/bluetooth.h>
41#include <net/bluetooth/hci_core.h>
41#include <net/bluetooth/rfcomm.h> 42#include <net/bluetooth/rfcomm.h>
42 43
43#ifndef CONFIG_BT_RFCOMM_DEBUG 44#ifndef CONFIG_BT_RFCOMM_DEBUG
@@ -161,6 +162,24 @@ static inline struct rfcomm_dev *rfcomm_dev_get(int id)
161 return dev; 162 return dev;
162} 163}
163 164
165static struct device *rfcomm_get_device(struct rfcomm_dev *dev)
166{
167 struct hci_dev *hdev;
168 struct hci_conn *conn;
169
170 hdev = hci_get_route(&dev->dst, &dev->src);
171 if (!hdev)
172 return NULL;
173
174 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &dev->dst);
175 if (!conn)
176 return NULL;
177
178 hci_dev_put(hdev);
179
180 return &conn->dev;
181}
182
164static int rfcomm_dev_add(struct rfcomm_dev_req *req, struct rfcomm_dlc *dlc) 183static int rfcomm_dev_add(struct rfcomm_dev_req *req, struct rfcomm_dlc *dlc)
165{ 184{
166 struct rfcomm_dev *dev; 185 struct rfcomm_dev *dev;
@@ -244,7 +263,7 @@ out:
244 return err; 263 return err;
245 } 264 }
246 265
247 tty_register_device(rfcomm_tty_driver, dev->id, NULL); 266 tty_register_device(rfcomm_tty_driver, dev->id, rfcomm_get_device(dev));
248 267
249 return dev->id; 268 return dev->id;
250} 269}