From: "Gustavo F. Padovan" <gustavo@padovan.org>
To: linux-bluetooth@vger.kernel.org
Cc: marcel@holtman.org, "Gustavo F. Padovan" <padovan@profusion.mobi>
Subject: [PATCH 1/2] Bluetooth: Add Fixed Channels support to bind syscall.
Date: Mon, 12 Jul 2010 18:19:04 -0300 [thread overview]
Message-ID: <1278969545-26864-1-git-send-email-gustavo@padovan.org> (raw)
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
next reply other threads:[~2010-07-12 21:19 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-12 21:19 Gustavo F. Padovan [this message]
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
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=1278969545-26864-1-git-send-email-gustavo@padovan.org \
--to=gustavo@padovan.org \
--cc=linux-bluetooth@vger.kernel.org \
--cc=marcel@holtman.org \
--cc=padovan@profusion.mobi \
/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;
as well as URLs for NNTP newsgroup(s).