From: Vinicius Costa Gomes <vinicius.gomes@openbossa.org>
To: linux-bluetooth@vger.kernel.org
Cc: Ville Tervo <ville.tervo@nokia.com>
Subject: [bluetooth-next -v2 04/24] Bluetooth: Add LE connection support to L2CAP
Date: Thu, 10 Feb 2011 22:38:49 -0300 [thread overview]
Message-ID: <1297388349-14878-5-git-send-email-vinicius.gomes@openbossa.org> (raw)
In-Reply-To: <1297388349-14878-4-git-send-email-vinicius.gomes@openbossa.org>
From: Ville Tervo <ville.tervo@nokia.com>
Add basic LE connection support to L2CAP. LE
connection can be created by specifying cid
in struct sockaddr_l2
Signed-off-by: Ville Tervo <ville.tervo@nokia.com>
---
include/net/bluetooth/l2cap.h | 3 +++
net/bluetooth/l2cap_core.c | 23 +++++++++++++++++++----
net/bluetooth/l2cap_sock.c | 7 ++++---
3 files changed, 26 insertions(+), 7 deletions(-)
diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
index 75ef0b2..78552a0 100644
--- a/include/net/bluetooth/l2cap.h
+++ b/include/net/bluetooth/l2cap.h
@@ -160,6 +160,9 @@ struct l2cap_conn_rsp {
/* channel indentifier */
#define L2CAP_CID_SIGNALING 0x0001
#define L2CAP_CID_CONN_LESS 0x0002
+#define L2CAP_CID_LE_DATA 0x0004
+#define L2CAP_CID_LE_SIGNALING 0x0005
+#define L2CAP_CID_SMP 0x0006
#define L2CAP_CID_DYN_START 0x0040
#define L2CAP_CID_DYN_END 0xffff
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index ba7f9da..b322cf5 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -595,6 +595,12 @@ static void l2cap_conn_ready(struct l2cap_conn *conn)
for (sk = l->head; sk; sk = l2cap_pi(sk)->next_c) {
bh_lock_sock(sk);
+ if (conn->hcon->type == LE_LINK) {
+ l2cap_sock_clear_timer(sk);
+ sk->sk_state = BT_CONNECTED;
+ sk->sk_state_change(sk);
+ }
+
if (sk->sk_type != SOCK_SEQPACKET &&
sk->sk_type != SOCK_STREAM) {
l2cap_sock_clear_timer(sk);
@@ -653,7 +659,11 @@ static struct l2cap_conn *l2cap_conn_add(struct hci_conn *hcon, u8 status)
BT_DBG("hcon %p conn %p", hcon, conn);
- conn->mtu = hcon->hdev->acl_mtu;
+ if (hcon->hdev->le_mtu && hcon->type == LE_LINK)
+ conn->mtu = hcon->hdev->le_mtu;
+ else
+ conn->mtu = hcon->hdev->acl_mtu;
+
conn->src = &hcon->hdev->bdaddr;
conn->dst = &hcon->dst;
@@ -760,8 +770,13 @@ int l2cap_do_connect(struct sock *sk)
auth_type = l2cap_get_auth_type(sk);
- hcon = hci_connect(hdev, ACL_LINK, dst,
+ if (l2cap_pi(sk)->dcid == L2CAP_CID_LE_DATA)
+ hcon = hci_connect(hdev, LE_LINK, dst,
l2cap_pi(sk)->sec_level, auth_type);
+ else
+ hcon = hci_connect(hdev, ACL_LINK, dst,
+ l2cap_pi(sk)->sec_level, auth_type);
+
if (!hcon)
goto done;
@@ -3522,7 +3537,7 @@ static int l2cap_connect_cfm(struct hci_conn *hcon, u8 status)
BT_DBG("hcon %p bdaddr %s status %d", hcon, batostr(&hcon->dst), status);
- if (hcon->type != ACL_LINK)
+ if (!(hcon->type == ACL_LINK || hcon->type == LE_LINK))
return -EINVAL;
if (!status) {
@@ -3551,7 +3566,7 @@ static int l2cap_disconn_cfm(struct hci_conn *hcon, u8 reason)
{
BT_DBG("hcon %p reason %d", hcon, reason);
- if (hcon->type != ACL_LINK)
+ if (!(hcon->type == ACL_LINK || hcon->type == LE_LINK))
return -EINVAL;
l2cap_conn_del(hcon, bt_err(reason));
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index adf4169..b435e5f 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -168,13 +168,13 @@ static int l2cap_sock_connect(struct socket *sock, struct sockaddr *addr, int al
len = min_t(unsigned int, sizeof(la), alen);
memcpy(&la, addr, len);
- if (la.l2_cid)
+ if (la.l2_cid && la.l2_psm)
return -EINVAL;
lock_sock(sk);
if ((sk->sk_type == SOCK_SEQPACKET || sk->sk_type == SOCK_STREAM)
- && !la.l2_psm) {
+ && !(la.l2_psm || la.l2_cid)) {
err = -EINVAL;
goto done;
}
@@ -216,7 +216,7 @@ static int l2cap_sock_connect(struct socket *sock, struct sockaddr *addr, int al
/* PSM must be odd and lsb of upper byte must be 0 */
if ((__le16_to_cpu(la.l2_psm) & 0x0101) != 0x0001 &&
- sk->sk_type != SOCK_RAW) {
+ sk->sk_type != SOCK_RAW && !la.l2_cid) {
err = -EINVAL;
goto done;
}
@@ -224,6 +224,7 @@ static int l2cap_sock_connect(struct socket *sock, struct sockaddr *addr, int al
/* Set destination address and psm */
bacpy(&bt_sk(sk)->dst, &la.l2_bdaddr);
l2cap_pi(sk)->psm = la.l2_psm;
+ l2cap_pi(sk)->dcid = la.l2_cid;
err = l2cap_do_connect(sk);
if (err)
--
1.7.4
next prev parent reply other threads:[~2011-02-11 1:38 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-11 1:38 [bluetooth-next -v2 00/24] Just Works SMP implementation Vinicius Costa Gomes
2011-02-11 1:38 ` [bluetooth-next -v2 01/24] Bluetooth: Add low energy commands and events Vinicius Costa Gomes
2011-02-11 1:38 ` [bluetooth-next -v2 02/24] Bluetooth: Add LE connect support Vinicius Costa Gomes
2011-02-11 1:38 ` [bluetooth-next -v2 03/24] Bluetooth: Use LE buffers for LE traffic Vinicius Costa Gomes
2011-02-11 1:38 ` Vinicius Costa Gomes [this message]
2011-02-11 1:38 ` [bluetooth-next -v2 05/24] Bluetooth: Add server socket support for LE connection Vinicius Costa Gomes
2011-02-11 1:38 ` [bluetooth-next -v2 06/24] Bluetooth: Do not send disconn comand over LE links Vinicius Costa Gomes
2011-02-11 1:38 ` [bluetooth-next -v2 07/24] Bluetooth: Fix initiated LE connections Vinicius Costa Gomes
2011-02-11 1:38 ` [bluetooth-next -v2 08/24] Bluetooth: Treat LE and ACL links separately on timeout Vinicius Costa Gomes
2011-02-11 1:38 ` [bluetooth-next -v2 09/24] Bluetooth: Add SMP command structures Vinicius Costa Gomes
2011-02-11 1:38 ` [bluetooth-next -v2 10/24] Bluetooth: Implement the first SMP commands Vinicius Costa Gomes
2011-02-11 1:38 ` [bluetooth-next -v2 11/24] Bluetooth: Start SMP procedure Vinicius Costa Gomes
2011-02-11 1:38 ` [bluetooth-next -v2 12/24] Bluetooth: simple SMP pairing negotiation Vinicius Costa Gomes
2011-02-11 1:38 ` [bluetooth-next -v2 13/24] Bluetooth: LE SMP Cryptoolbox functions Vinicius Costa Gomes
2011-02-11 1:38 ` [bluetooth-next -v2 14/24] Bluetooth: Add support for using the crypto subsystem Vinicius Costa Gomes
2011-02-11 1:39 ` [bluetooth-next -v2 15/24] Bluetooth: Add SMP confirmation structs Vinicius Costa Gomes
2011-02-11 1:39 ` [bluetooth-next -v2 16/24] Bluetooth: Add SMP confirmation checks methods Vinicius Costa Gomes
2011-02-11 1:39 ` [bluetooth-next -v2 17/24] Bluetooth: Minor fix in SMP methods Vinicius Costa Gomes
2011-02-11 1:39 ` [bluetooth-next -v2 18/24] Bluetooth: Add support for LE Start Encryption Vinicius Costa Gomes
2011-02-11 1:39 ` [bluetooth-next -v2 19/24] Bluetooth: Add support for resuming socket when SMP is finished Vinicius Costa Gomes
2011-02-11 1:39 ` [bluetooth-next -v2 20/24] Bluetooth: Fix initial security level of LE links Vinicius Costa Gomes
2011-02-11 1:46 ` [bluetooth-next -v2 21/24] Bluetooth: Update the security level when link is encrypted Vinicius Costa Gomes
2011-02-11 1:46 ` [bluetooth-next -v2 22/24] Bluetooth: Add support for Pairing features exchange Vinicius Costa Gomes
2011-02-11 1:46 ` [bluetooth-next -v2 23/24] Bluetooth: Add support for SMP timeout Vinicius Costa Gomes
2011-02-11 1:46 ` [bluetooth-next -v2 24/24] Bluetooth: Add key size checks for SMP Vinicius Costa Gomes
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1297388349-14878-5-git-send-email-vinicius.gomes@openbossa.org \
--to=vinicius.gomes@openbossa.org \
--cc=linux-bluetooth@vger.kernel.org \
--cc=ville.tervo@nokia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox