public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
From: Marcel Holtmann <marcel@holtmann.org>
To: BlueZ development <bluez-devel@lists.sourceforge.net>
Subject: Re: [Bluez-devel] It's rfcomm connect problem
Date: Mon, 24 Jul 2006 23:12:21 +0200	[thread overview]
Message-ID: <1153775541.25058.6.camel@localhost> (raw)
In-Reply-To: <7359D844-F738-4AD1-A1FD-F59BEFD149EC@infitsrl.com>

[-- Attachment #1: Type: text/plain, Size: 312 bytes --]

Hi Fabrizio,

> Last solutions it's to see at l2cap layer and try to understand ho wo  
> write the patch, if
> I will succeed to find  the past Marcel's thread about it I'll try to  
> write this patch.

it must look something like the attached one. However that one might
crash your machine.

Regards

Marcel


[-- Attachment #2: patch --]
[-- Type: text/x-patch, Size: 3011 bytes --]

diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
index 8242a0e..cb19e66 100644
--- a/include/net/bluetooth/l2cap.h
+++ b/include/net/bluetooth/l2cap.h
@@ -183,6 +183,8 @@ struct l2cap_chan_list {
 };
 
 struct l2cap_conn {
+	struct list_head list;
+
 	struct hci_conn	*hcon;
 
 	bdaddr_t	*dst;
diff --git a/net/bluetooth/l2cap.c b/net/bluetooth/l2cap.c
index eaaad65..1d1c423 100644
--- a/net/bluetooth/l2cap.c
+++ b/net/bluetooth/l2cap.c
@@ -63,6 +63,9 @@ static struct bt_sock_list l2cap_sk_list
 	.lock = RW_LOCK_UNLOCKED
 };
 
+static LIST_HEAD(l2cap_conn_list);
+static DEFINE_SPINLOCK(l2cap_conn_lock);
+
 static void __l2cap_sock_close(struct sock *sk, int reason);
 static void l2cap_sock_close(struct sock *sk);
 static void l2cap_sock_kill(struct sock *sk);
@@ -295,6 +298,10 @@ static void l2cap_conn_del(struct hci_co
 
 	BT_DBG("hcon %p conn %p, err %d", hcon, conn, err);
 
+	spin_lock_bh(&l2cap_conn_lock);
+	list_del(&conn->list);
+	spin_unlock_bh(&l2cap_conn_lock);
+
 	if (conn->rx_skb)
 		kfree_skb(conn->rx_skb);
 
@@ -642,18 +649,23 @@ static int l2cap_do_connect(struct sock 
 	sk->sk_state = BT_CONNECT;
 	l2cap_sock_set_timer(sk, sk->sk_sndtimeo);
 
-	if (hcon->state == BT_CONNECTED) {
-		if (sk->sk_type == SOCK_SEQPACKET) {
-			struct l2cap_conn_req req;
-			l2cap_pi(sk)->ident = l2cap_get_ident(conn);
-			req.scid = __cpu_to_le16(l2cap_pi(sk)->scid);
-			req.psm  = l2cap_pi(sk)->psm;
-			l2cap_send_cmd(conn, l2cap_pi(sk)->ident,
-					L2CAP_CONN_REQ, sizeof(req), &req);
-		} else {
-			l2cap_sock_clear_timer(sk);
-			sk->sk_state = BT_CONNECTED;
-		}
+	if (hcon->state != BT_CONNECTED) {
+		spin_lock_bh(&l2cap_conn_lock);
+		list_add_tail(&conn->list, &l2cap_conn_list);
+		spin_unlock_bh(&l2cap_conn_lock);
+		goto done;
+	}
+
+	if (sk->sk_type == SOCK_SEQPACKET) {
+		struct l2cap_conn_req req;
+		l2cap_pi(sk)->ident = l2cap_get_ident(conn);
+		req.scid = __cpu_to_le16(l2cap_pi(sk)->scid);
+		req.psm  = l2cap_pi(sk)->psm;
+		l2cap_send_cmd(conn, l2cap_pi(sk)->ident,
+				L2CAP_CONN_REQ, sizeof(req), &req);
+	} else {
+		l2cap_sock_clear_timer(sk);
+		sk->sk_state = BT_CONNECTED;
 	}
 
 done:
@@ -1926,12 +1938,35 @@ static int l2cap_connect_cfm(struct hci_
 	if (hcon->type != ACL_LINK)
 		return 0;
 
-	if (!status) {
+	switch (status) {
+	case 0x00:
 		conn = l2cap_conn_add(hcon, status);
-		if (conn)
-			l2cap_conn_ready(conn);
-	} else
+		if (!conn)
+			break;
+
+		spin_lock_bh(&l2cap_conn_lock);
+		list_del(&conn->list);
+		spin_unlock_bh(&l2cap_conn_lock);
+
+		l2cap_conn_ready(conn);
+
+		spin_lock_bh(&l2cap_conn_lock);
+		if (!list_empty(&l2cap_conn_list)) {
+			conn = list_entry(l2cap_conn_list.next, struct l2cap_conn, list);
+			list_move_tail(&conn->list, &l2cap_conn_list);
+			hci_conn_put(conn->hcon);
+			hci_connect(conn->hcon->hdev, ACL_LINK, conn->dst);
+		}
+		spin_unlock_bh(&l2cap_conn_lock);
+		break;
+
+	case 0x0c:
+		break;
+
+	default:
 		l2cap_conn_del(hcon, bt_err(status));
+		break;
+	}
 
 	return 0;
 }

[-- Attachment #3: Type: text/plain, Size: 348 bytes --]

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

[-- Attachment #4: Type: text/plain, Size: 164 bytes --]

_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

  reply	other threads:[~2006-07-24 21:12 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-07-19 16:28 [Bluez-devel] Error: sdptool browse --> Connection reset by peer JP Freeley
2006-07-20  0:48 ` Marcel Holtmann
2006-07-20 21:27   ` JP Freeley
2006-07-25  4:26     ` JP Freeley
2006-07-22 14:08   ` [Bluez-devel] It's rfcomm connect problem Fabrizio Guglielmino
2006-07-24  8:38     ` Andreas Gaufer
2006-07-24 13:33       ` Fabrizio Guglielmino
2006-07-24 13:56         ` Andreas Gaufer
2006-07-24 16:35           ` Marcel Holtmann
2006-07-24 18:34             ` Andreas Gaufer
2006-07-24 20:30               ` Fabrizio Guglielmino
2006-07-24 21:12                 ` Marcel Holtmann [this message]
2006-07-27  9:04                   ` Fabrizio Guglielmino
2006-07-27  9:25                     ` [Bluez-devel] It's rfcomm connect problem [ERRATA] Fabrizio Guglielmino
2006-07-28 11:14                     ` [Bluez-devel] It's rfcomm connect problem Marcel Holtmann
2006-07-31 10:02                       ` [Bluez-devel] About l2cap patch to handle multiple connections Fabrizio Guglielmino
2006-07-31 14:14                         ` Marcel Holtmann
2006-08-02 11:24                           ` Fabrizio Guglielmino
2006-08-02 13:43                             ` Marcel Holtmann

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=1153775541.25058.6.camel@localhost \
    --to=marcel@holtmann.org \
    --cc=bluez-devel@lists.sourceforge.net \
    /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