public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] *** SUBJECT HERE ***
@ 2009-04-30  1:42 ngh
  2009-04-30  1:42 ` [PATCH] Add support for negotiating new L2CAP options after a failed configuration ngh
  2009-04-30  2:01 ` [PATCH] *** SUBJECT HERE *** Marcel Holtmann
  0 siblings, 2 replies; 4+ messages in thread
From: ngh @ 2009-04-30  1:42 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Nathan Holstein

From: Nathan Holstein <nathan@lampreynetworks.com>

This is a revamping of the previous patches that I submited.  I started from
scratch, rebase all the changes onto the latest bluetooth-testing (2.6.30-rc3).
While applying the changes, I attempted to clean up the code and apply the
input from Marcel and Gustavo.

Unfortunately, I did not get a chance to test this for regressions vs. the
previous version of the code.  I did remove the code which segmented outgoing
PDUs: it wouldn't have worked with the current tx window=1, and would have
produced memory leaks.

The code is available from git://staticfree.info/git/el2cap on branch "ertm".

Nathan Holstein (9):
  Add #defines and data structures for enhanced L2CAP
  Add support for sending enhanced L2CAP data
  Add support for sending L2CAP S-frames.
  Append RFC option when configuring an L2CAP socket.
  Add support for parsing enhanced L2CAP configuration options.
  Add support for receiving data over an enhanced L2CAP channel
  Check the FCS of a received L2CAP packet.
  Reassemble segmented L2CAP PDUs upon reception
  Add support for negotiating new L2CAP options after a failed
    configuration

 include/net/bluetooth/bluetooth.h |    3 +-
 include/net/bluetooth/l2cap.h     |  124 +++++++-
 net/bluetooth/l2cap.c             |  607 ++++++++++++++++++++++++++++++++++---
 3 files changed, 673 insertions(+), 61 deletions(-)


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

* [PATCH] Add support for negotiating new L2CAP options after a failed configuration
  2009-04-30  1:42 [PATCH] *** SUBJECT HERE *** ngh
@ 2009-04-30  1:42 ` ngh
  2009-04-30  2:01 ` [PATCH] *** SUBJECT HERE *** Marcel Holtmann
  1 sibling, 0 replies; 4+ messages in thread
From: ngh @ 2009-04-30  1:42 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Nathan Holstein

From: Nathan Holstein <nathan@lampreynetworks.com>

When negotiating the configuration of an L2CAP socket, the remote may reject
the initial configuration that was sent.  This patch adds allows selecting
differing configuration values.
---
 net/bluetooth/l2cap.c |  106 ++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 97 insertions(+), 9 deletions(-)

diff --git a/net/bluetooth/l2cap.c b/net/bluetooth/l2cap.c
index 7505137..528c72d 100644
--- a/net/bluetooth/l2cap.c
+++ b/net/bluetooth/l2cap.c
@@ -2016,6 +2016,70 @@ static int l2cap_parse_conf_req(struct sock *sk, void *data)
 	return ptr - data;
 }
 
+static inline int l2cap_parse_conf_rsp(struct sock *sk, void *rsp, int len, void *_req, u16 *result)
+{
+	struct l2cap_pinfo *pi = l2cap_pi(sk);
+	struct l2cap_conf_req *req = _req;
+	void *ptr = req->data;
+	int type, hint, olen;
+	unsigned long val;
+	struct l2cap_conf_rfc rfc;
+
+	BT_DBG("sk %p, rsp %p, len %d, req %p", sk, rsp, len, _req);
+
+	while (len >= L2CAP_CONF_OPT_SIZE) {
+		len -= l2cap_get_conf_opt(&rsp, &type, &olen, &val);
+
+		hint  = type & L2CAP_CONF_HINT;
+		type &= 0x7f;
+
+		switch (type) {
+		case L2CAP_CONF_MTU:
+			if (val < L2CAP_CONF_MIN_MTU)
+			{
+				*result = L2CAP_CONF_UNACCEPT;
+				pi->omtu = L2CAP_CONF_MIN_MTU;
+			}
+			else
+				pi->omtu = val;
+			l2cap_add_conf_opt(&ptr, L2CAP_CONF_MTU, 2, pi->omtu);
+			break;
+
+		case L2CAP_CONF_FLUSH_TO:
+			pi->flush_to = val;
+			l2cap_add_conf_opt(&ptr, L2CAP_CONF_FLUSH_TO, 2,
+						pi->flush_to);
+			break;
+
+		case L2CAP_CONF_QOS:
+			break;
+
+		case L2CAP_CONF_RFC:
+			/* Currently, the code does not support negotiating to
+			 * use a different mode than was initially created. This
+			 * can be used for switching between ERTM/Streaming, and
+			 * will be useful for implementing MCAP/HDP on top of
+			 * eL2CAP. */
+			*result = L2CAP_CONF_UNACCEPT;
+			if (pi->mode == L2CAP_MODE_BASIC)
+				pi->fcs = 0;
+			l2cap_add_conf_opt(&ptr, L2CAP_CONF_RFC,
+						sizeof(rfc), (unsigned long) &rfc);
+			break;
+
+		case L2CAP_CONF_FCS:
+			pi->fcs = val;
+			l2cap_add_conf_opt(&ptr, L2CAP_CONF_FCS, 1, pi->fcs);
+		}
+	}
+
+	req->dcid   = cpu_to_le16(pi->dcid);
+	req->flags  = cpu_to_le16(0x0000);
+
+	BT_DBG("ptr %p, req->data %p", ptr, req->data);
+	return ptr - _req;
+}
+
 static int l2cap_build_conf_rsp(struct sock *sk, void *data, u16 result, u16 flags)
 {
 	struct l2cap_conf_rsp *rsp = data;
@@ -2237,6 +2301,15 @@ static inline int l2cap_config_req(struct l2cap_conn *conn, struct l2cap_cmd_hdr
 	if (sk->sk_state == BT_DISCONN)
 		goto unlock;
 
+	/* Reject if connected and in eL2CAP mode. */
+	if (sk->sk_state == BT_CONNECTED && l2cap_pi(sk)->mode != L2CAP_MODE_BASIC)
+	{
+		l2cap_send_cmd(conn, cmd->ident, L2CAP_CONF_RSP,
+				l2cap_build_conf_rsp(sk, rsp,
+					L2CAP_CONF_REJECT, flags), rsp);
+		goto unlock;
+	}
+
 	/* Reject if config buffer is too small. */
 	len = cmd_len - sizeof(*req);
 	if (l2cap_pi(sk)->conf_len + len > sizeof(l2cap_pi(sk)->conf_req)) {
@@ -2305,21 +2378,36 @@ static inline int l2cap_config_rsp(struct l2cap_conn *conn, struct l2cap_cmd_hdr
 	if (!sk)
 		return 0;
 
+	/* Reject if connected and in eL2CAP mode. */
+	if (sk->sk_state == BT_CONNECTED && l2cap_pi(sk)->mode != L2CAP_MODE_BASIC)
+	{
+		l2cap_send_cmd(conn, cmd->ident, L2CAP_CONF_RSP,
+				l2cap_build_conf_rsp(sk, rsp,
+					L2CAP_CONF_REJECT, flags), rsp);
+		goto done;
+	}
+
 	switch (result) {
 	case L2CAP_CONF_SUCCESS:
 		break;
 
 	case L2CAP_CONF_UNACCEPT:
 		if (++l2cap_pi(sk)->conf_retry < L2CAP_CONF_MAX_RETRIES) {
-			char req[128];
-			/* It does not make sense to adjust L2CAP parameters
-			 * that are currently defined in the spec. We simply
-			 * resend config request that we sent earlier. It is
-			 * stupid, but it helps qualification testing which
-			 * expects at least some response from us. */
-			l2cap_send_cmd(conn, l2cap_get_ident(conn), L2CAP_CONF_REQ,
-						l2cap_build_conf_req(sk, req), req);
-			goto done;
+			int len = cmd->len - sizeof(*rsp);
+			char req[64];
+
+			/* throw out any old conf requests we stored */
+			result = L2CAP_CONF_SUCCESS;
+			len = l2cap_parse_conf_rsp(sk, rsp->data, len, req,
+					&result);
+
+			BT_DBG("len %d", len);
+			l2cap_send_cmd(conn, l2cap_get_ident(conn),
+						L2CAP_CONF_REQ, len, req);
+			if (result == L2CAP_CONF_SUCCESS)
+				break;
+			else
+				goto done;
 		}
 
 	default:
-- 
1.6.0.6


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

* Re: [PATCH] *** SUBJECT HERE ***
  2009-04-30  1:42 [PATCH] *** SUBJECT HERE *** ngh
  2009-04-30  1:42 ` [PATCH] Add support for negotiating new L2CAP options after a failed configuration ngh
@ 2009-04-30  2:01 ` Marcel Holtmann
  2009-04-30 16:12   ` Gustavo F. Padovan
  1 sibling, 1 reply; 4+ messages in thread
From: Marcel Holtmann @ 2009-04-30  2:01 UTC (permalink / raw)
  To: ngh; +Cc: linux-bluetooth, Nathan Holstein

Hi Nathan,

> This is a revamping of the previous patches that I submited.  I started from
> scratch, rebase all the changes onto the latest bluetooth-testing (2.6.30-rc3).
> While applying the changes, I attempted to clean up the code and apply the
> input from Marcel and Gustavo.
> 
> Unfortunately, I did not get a chance to test this for regressions vs. the
> previous version of the code.  I did remove the code which segmented outgoing
> PDUs: it wouldn't have worked with the current tx window=1, and would have
> produced memory leaks.
> 
> The code is available from git://staticfree.info/git/el2cap on branch "ertm".

no idea why are using a branch for this. Just a remote repository should
be enough. Anyhow you have to add Signed-off-by statements to your
patches. Otherwise I can't apply them.

Regards

Marcel



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

* Re: [PATCH] *** SUBJECT HERE ***
  2009-04-30  2:01 ` [PATCH] *** SUBJECT HERE *** Marcel Holtmann
@ 2009-04-30 16:12   ` Gustavo F. Padovan
  0 siblings, 0 replies; 4+ messages in thread
From: Gustavo F. Padovan @ 2009-04-30 16:12 UTC (permalink / raw)
  To: Nathan Holstein; +Cc: ngh, linux-bluetooth, Marcel Holtmann

Hi Nathan,

On Wed, Apr 29, 2009 at 11:01 PM, Marcel Holtmann <marcel@holtmann.org> wro=
te:
> Hi Nathan,
>
>> This is a revamping of the previous patches that I submited. =A0I starte=
d from
>> scratch, rebase all the changes onto the latest bluetooth-testing (2.6.3=
0-rc3).
>> While applying the changes, I attempted to clean up the code and apply t=
he
>> input from Marcel and Gustavo.
>>
>> Unfortunately, I did not get a chance to test this for regressions vs. t=
he
>> previous version of the code. =A0I did remove the code which segmented o=
utgoing
>> PDUs: it wouldn't have worked with the current tx window=3D1, and would =
have
>> produced memory leaks.
>>
>> The code is available from git://staticfree.info/git/el2cap on branch "e=
rtm".
>
> no idea why are using a branch for this. Just a remote repository should
> be enough. Anyhow you have to add Signed-off-by statements to your
> patches. Otherwise I can't apply them.

Also add -n to your git format-patch options to number the
patches(e.g. [PATCH 01/07]...)

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



--=20
Gustavo F. Padovan
http://padovan.org

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

end of thread, other threads:[~2009-04-30 16:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-04-30  1:42 [PATCH] *** SUBJECT HERE *** ngh
2009-04-30  1:42 ` [PATCH] Add support for negotiating new L2CAP options after a failed configuration ngh
2009-04-30  2:01 ` [PATCH] *** SUBJECT HERE *** Marcel Holtmann
2009-04-30 16:12   ` Gustavo F. Padovan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox