linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] Bluetooth: Add Fixed Channels support to bind syscall.
@ 2010-07-12 21:19 Gustavo F. Padovan
  2010-07-12 21:19 ` [PATCH 2/2] Bluetooth: Add Fixed Channels support to connect() Gustavo F. Padovan
  2010-07-13 17:26 ` [PATCH 1/2] Bluetooth: Add Fixed Channels support to bind syscall Anderson Lizardo
  0 siblings, 2 replies; 5+ messages in thread
From: Gustavo F. Padovan @ 2010-07-12 21:19 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: marcel, Gustavo F. Padovan

From: Gustavo F. Padovan <padovan@profusion.mobi>

L2CAP nows support bind to a fixed channel, this is needed for Low Energy
and AMP.
bind returns error if you pass both PSM and CID values.

Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
---
 net/bluetooth/l2cap.c |   48 +++++++++++++++++++++++++++++++++++-------------
 1 files changed, 35 insertions(+), 13 deletions(-)

diff --git a/net/bluetooth/l2cap.c b/net/bluetooth/l2cap.c
index 449cbdd..39f047b 100644
--- a/net/bluetooth/l2cap.c
+++ b/net/bluetooth/l2cap.c
@@ -726,7 +726,7 @@ static inline void l2cap_chan_add(struct l2cap_conn *conn, struct sock *sk, stru
 }
 
 /* ---- Socket interface ---- */
-static struct sock *__l2cap_get_sock_by_addr(__le16 psm, bdaddr_t *src)
+static struct sock *__l2cap_sock_by_psm_addr(__le16 psm, bdaddr_t *src)
 {
 	struct sock *sk;
 	struct hlist_node *node;
@@ -738,6 +738,16 @@ found:
 	return sk;
 }
 
+static struct sock *__l2cap_sock_by_cid_addr(__le16 cid, bdaddr_t *src)
+{
+	struct sock *sk;
+	struct hlist_node *node;
+	sk_for_each(sk, node, &l2cap_sk_list.head)
+		if (l2cap_pi(sk)->scid == cid && !bacmp(&bt_sk(sk)->src, src))
+			return sk;
+	return NULL;
+}
+
 /* Find socket with psm and source bdaddr.
  * Returns closest match.
  */
@@ -996,7 +1006,7 @@ static int l2cap_sock_bind(struct socket *sock, struct sockaddr *addr, int alen)
 	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);
@@ -1014,18 +1024,30 @@ static int l2cap_sock_bind(struct socket *sock, struct sockaddr *addr, int alen)
 
 	write_lock_bh(&l2cap_sk_list.lock);
 
-	if (la.l2_psm && __l2cap_get_sock_by_addr(la.l2_psm, &la.l2_bdaddr)) {
-		err = -EADDRINUSE;
-	} else {
-		/* Save source address */
-		bacpy(&bt_sk(sk)->src, &la.l2_bdaddr);
-		l2cap_pi(sk)->psm   = la.l2_psm;
-		l2cap_pi(sk)->sport = la.l2_psm;
-		sk->sk_state = BT_BOUND;
+	if (la.l2_psm) {
+		if (__l2cap_sock_by_psm_addr(la.l2_psm, &la.l2_bdaddr)) {
+			err = -EADDRINUSE;
+		} else {
+			/* Save source address */
+			bacpy(&bt_sk(sk)->src, &la.l2_bdaddr);
+			l2cap_pi(sk)->psm   = la.l2_psm;
+			l2cap_pi(sk)->sport = la.l2_psm;
+			sk->sk_state = BT_BOUND;
 
-		if (__le16_to_cpu(la.l2_psm) == 0x0001 ||
+			if (__le16_to_cpu(la.l2_psm) == 0x0001 ||
 					__le16_to_cpu(la.l2_psm) == 0x0003)
-			l2cap_pi(sk)->sec_level = BT_SECURITY_SDP;
+				l2cap_pi(sk)->sec_level = BT_SECURITY_SDP;
+		}
+	} else if (la.l2_cid) {
+		/* Save source address */
+		if (__l2cap_sock_by_cid_addr(la.l2_cid, &la.l2_bdaddr)) {
+			err = -EADDRINUSE;
+		} else {
+			bacpy(&bt_sk(sk)->src, &la.l2_bdaddr);
+			l2cap_pi(sk)->scid  = la.l2_cid;
+			l2cap_pi(sk)->sport = la.l2_cid;
+			sk->sk_state = BT_BOUND;
+		}
 	}
 
 	write_unlock_bh(&l2cap_sk_list.lock);
@@ -1241,7 +1263,7 @@ static int l2cap_sock_listen(struct socket *sock, int backlog)
 		write_lock_bh(&l2cap_sk_list.lock);
 
 		for (psm = 0x1001; psm < 0x1100; psm += 2)
-			if (!__l2cap_get_sock_by_addr(cpu_to_le16(psm), src)) {
+			if (!__l2cap_sock_by_psm_addr(cpu_to_le16(psm), src)) {
 				l2cap_pi(sk)->psm   = cpu_to_le16(psm);
 				l2cap_pi(sk)->sport = cpu_to_le16(psm);
 				err = 0;
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] Bluetooth: Add Fixed Channels support to connect()
  2010-07-12 21:19 [PATCH 1/2] Bluetooth: Add Fixed Channels support to bind syscall Gustavo F. Padovan
@ 2010-07-12 21:19 ` Gustavo F. Padovan
  2010-07-12 21:46   ` Marcel Holtmann
  2010-07-13 17:26 ` [PATCH 1/2] Bluetooth: Add Fixed Channels support to bind syscall Anderson Lizardo
  1 sibling, 1 reply; 5+ messages in thread
From: Gustavo F. Padovan @ 2010-07-12 21:19 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: marcel, Gustavo F. Padovan

From: Gustavo F. Padovan <padovan@profusion.mobi>

All the Fixed Channel shall be set up with SOCK_DGRAM passing the channel
id too. If you don't inform the channel id, L2CAP will use the
Connectionless channel (0x0002), which was already the default channel for
SOCK_DGRAM.

Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
---
 net/bluetooth/l2cap.c |   14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/net/bluetooth/l2cap.c b/net/bluetooth/l2cap.c
index 39f047b..132197e 100644
--- a/net/bluetooth/l2cap.c
+++ b/net/bluetooth/l2cap.c
@@ -229,9 +229,14 @@ static void __l2cap_chan_add(struct l2cap_conn *conn, struct sock *sk, struct so
 		/* Alloc CID for connection-oriented socket */
 		l2cap_pi(sk)->scid = l2cap_alloc_cid(l);
 	} else if (sk->sk_type == SOCK_DGRAM) {
-		/* Connectionless socket */
-		l2cap_pi(sk)->scid = L2CAP_CID_CONN_LESS;
-		l2cap_pi(sk)->dcid = L2CAP_CID_CONN_LESS;
+		if (l2cap_pi(sk)->scid) {
+			/* Fixed channels */
+			l2cap_pi(sk)->dcid = l2cap_pi(sk)->scid;
+		} else {
+			/* Connectionless socket */
+			l2cap_pi(sk)->scid = L2CAP_CID_CONN_LESS;
+			l2cap_pi(sk)->dcid = L2CAP_CID_CONN_LESS;
+		}
 		l2cap_pi(sk)->omtu = L2CAP_DEFAULT_MTU;
 	} else {
 		/* Raw socket can send/recv signalling messages only */
@@ -1164,7 +1169,7 @@ 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_psm && la.l2_cid)
 		return -EINVAL;
 
 	lock_sock(sk);
@@ -1213,6 +1218,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)->scid = la.l2_cid;
 
 	err = l2cap_do_connect(sk);
 	if (err)
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] Bluetooth: Add Fixed Channels support to connect()
  2010-07-12 21:19 ` [PATCH 2/2] Bluetooth: Add Fixed Channels support to connect() Gustavo F. Padovan
@ 2010-07-12 21:46   ` Marcel Holtmann
  0 siblings, 0 replies; 5+ messages in thread
From: Marcel Holtmann @ 2010-07-12 21:46 UTC (permalink / raw)
  To: Gustavo F. Padovan; +Cc: linux-bluetooth, marcel, Gustavo F. Padovan

Hi Gustavo,

> All the Fixed Channel shall be set up with SOCK_DGRAM passing the channel
> id too. If you don't inform the channel id, L2CAP will use the
> Connectionless channel (0x0002), which was already the default channel for
> SOCK_DGRAM.

we actually can't do that. So the fixed channel have specific types
assigned with it. For example LE configures the ATT channel in basic
mode and HS uses ERTM on the AMP manager protocol.

However the only channel that we currently wanna access from user space
with SOCK_SEQPACKET is the ATT channel on LE. So we should disallow any
other access to fixed channels and use SOCK_DGRAM for raw access to the
signal channel as before. And SOCK_SEQPACKET for the ATT channel. All
other attempts to bind or connect a fixed channel should be rejected for
now.

Regards

Marcel



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] Bluetooth: Add Fixed Channels support to bind syscall.
  2010-07-12 21:19 [PATCH 1/2] Bluetooth: Add Fixed Channels support to bind syscall Gustavo F. Padovan
  2010-07-12 21:19 ` [PATCH 2/2] Bluetooth: Add Fixed Channels support to connect() Gustavo F. Padovan
@ 2010-07-13 17:26 ` Anderson Lizardo
  2010-07-13 17:30   ` Anderson Lizardo
  1 sibling, 1 reply; 5+ messages in thread
From: Anderson Lizardo @ 2010-07-13 17:26 UTC (permalink / raw)
  To: Gustavo F. Padovan; +Cc: linux-bluetooth, marcel, Gustavo F. Padovan

On Mon, Jul 12, 2010 at 6:19 PM, Gustavo F. Padovan <gustavo@padovan.org> wrote:
> diff --git a/net/bluetooth/l2cap.c b/net/bluetooth/l2cap.c
> index 449cbdd..39f047b 100644
> --- a/net/bluetooth/l2cap.c
> +++ b/net/bluetooth/l2cap.c
> @@ -726,7 +726,7 @@ static inline void l2cap_chan_add(struct l2cap_conn *conn, struct sock *sk, stru
>  }
>
>  /* ---- Socket interface ---- */
> -static struct sock *__l2cap_get_sock_by_addr(__le16 psm, bdaddr_t *src)
> +static struct sock *__l2cap_sock_by_psm_addr(__le16 psm, bdaddr_t *src)
>  {
>        struct sock *sk;
>        struct hlist_node *node;
> @@ -738,6 +738,16 @@ found:
>        return sk;
>  }
>
> +static struct sock *__l2cap_sock_by_cid_addr(__le16 cid, bdaddr_t *src)
> +{
> +       struct sock *sk;
> +       struct hlist_node *node;
> +       sk_for_each(sk, node, &l2cap_sk_list.head)
> +               if (l2cap_pi(sk)->scid == cid && !bacmp(&bt_sk(sk)->src, src))
> +                       return sk;
> +       return NULL;
> +}
> +

If sk->sport is always filled with either cid or psm , why not have
just a single "__l2cap_sock_addr"  function ?

Regads,
-- 
Anderson Lizardo
OpenBossa Labs - INdT
Manaus - Brazil

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] Bluetooth: Add Fixed Channels support to bind syscall.
  2010-07-13 17:26 ` [PATCH 1/2] Bluetooth: Add Fixed Channels support to bind syscall Anderson Lizardo
@ 2010-07-13 17:30   ` Anderson Lizardo
  0 siblings, 0 replies; 5+ messages in thread
From: Anderson Lizardo @ 2010-07-13 17:30 UTC (permalink / raw)
  To: Gustavo F. Padovan; +Cc: linux-bluetooth, marcel, Gustavo F. Padovan

On Tue, Jul 13, 2010 at 2:26 PM, Anderson Lizardo
<anderson.lizardo@openbossa.org> wrote:
> If sk->sport is always filled with either cid or psm , why not have
> just a single "__l2cap_sock_addr"  function ?

In other words, my suggestion is to keep __l2cap_get_sock_by_addr() as
is (as it already checks for sport) and use it both for PSM and CID.
This could potentially allow a bit of refactoring on the
l2cap_sock_bind() changes as well.

Regards,
-- 
Anderson Lizardo
OpenBossa Labs - INdT
Manaus - Brazil

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-07-13 17:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-12 21:19 [PATCH 1/2] Bluetooth: Add Fixed Channels support to bind syscall Gustavo F. Padovan
2010-07-12 21:19 ` [PATCH 2/2] Bluetooth: Add Fixed Channels support to connect() Gustavo F. Padovan
2010-07-12 21:46   ` Marcel Holtmann
2010-07-13 17:26 ` [PATCH 1/2] Bluetooth: Add Fixed Channels support to bind syscall Anderson Lizardo
2010-07-13 17:30   ` Anderson Lizardo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).