[RFCv2 bluetooth-next 07/19] bluetooth: introduce l2cap_hdev_chan_connect

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



A BTLE 6LoWPAN should be binded to one hci device and is not changeable
afterwards. This patch adds l2cap_hdev_chan_connect function without calling
hci_get_route which decides on bluetooth side which may be the best hci
device which should be use. The hci dev will be available by parameter.

Signed-off-by: Alexander Aring <aar@xxxxxxxxxxxxxx>
---
 include/net/bluetooth/l2cap.h |  3 +++
 net/bluetooth/l2cap_core.c    | 28 +++++++++++++++++++++-------
 2 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
index 5ee3c68..8a4d26e 100644
--- a/include/net/bluetooth/l2cap.h
+++ b/include/net/bluetooth/l2cap.h
@@ -928,6 +928,9 @@ struct l2cap_chan *l2cap_chan_create(void);
 void l2cap_chan_close(struct l2cap_chan *chan, int reason);
 int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid,
 		       bdaddr_t *dst, u8 dst_type);
+int l2cap_hdev_chan_connect(struct hci_dev *hdev,
+			    struct l2cap_chan *chan, __le16 psm, u16 cid,
+			    bdaddr_t *dst, u8 dst_type);
 int l2cap_chan_send(struct l2cap_chan *chan, struct msghdr *msg, size_t len);
 void l2cap_chan_busy(struct l2cap_chan *chan, int busy);
 int l2cap_chan_check_security(struct l2cap_chan *chan, bool initiator);
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 54ceb1f..2ab8814 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -7041,21 +7041,17 @@ static bool is_valid_psm(u16 psm, u8 dst_type) {
 	return ((psm & 0x0101) == 0x0001);
 }
 
-int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid,
-		       bdaddr_t *dst, u8 dst_type)
+int l2cap_hdev_chan_connect(struct hci_dev *hdev,
+			    struct l2cap_chan *chan, __le16 psm, u16 cid,
+			    bdaddr_t *dst, u8 dst_type)
 {
 	struct l2cap_conn *conn;
 	struct hci_conn *hcon;
-	struct hci_dev *hdev;
 	int err;
 
 	BT_DBG("%pMR -> %pMR (type %u) psm 0x%2.2x", &chan->src, dst,
 	       dst_type, __le16_to_cpu(psm));
 
-	hdev = hci_get_route(dst, &chan->src);
-	if (!hdev)
-		return -EHOSTUNREACH;
-
 	hci_dev_lock(hdev);
 
 	if (!is_valid_psm(__le16_to_cpu(psm), dst_type) && !cid &&
@@ -7199,7 +7195,25 @@ chan_unlock:
 	mutex_unlock(&conn->chan_lock);
 done:
 	hci_dev_unlock(hdev);
+	return err;
+}
+EXPORT_SYMBOL_GPL(l2cap_hdev_chan_connect);
+
+int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid,
+		       bdaddr_t *dst, u8 dst_type)
+{
+	struct hci_dev *hdev;
+	int err = -EHOSTUNREACH;
+
+	hdev = hci_get_route(dst, &chan->src);
+	if (!hdev)
+		goto done;
+
+	err = l2cap_hdev_chan_connect(hdev, chan, psm, cid, dst, dst_type);
+
 	hci_dev_put(hdev);
+
+done:
 	return err;
 }
 EXPORT_SYMBOL_GPL(l2cap_chan_connect);
-- 
2.9.2

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux