linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC 1/8] gattrib: Fix GAttrib buffer allocation
@ 2012-06-07  0:40 Andre Guedes
  2012-06-07  0:40 ` [RFC 2/8] gattrib: Fix g_attrib_set_mtu Andre Guedes
                   ` (7 more replies)
  0 siblings, 8 replies; 12+ messages in thread
From: Andre Guedes @ 2012-06-07  0:40 UTC (permalink / raw)
  To: linux-bluetooth

GAttrib buffer should be allocated according to ATT_MTU value. Over
BR/EDR, ATT_MTU should be set to the L2CAP imtu negotiated during
L2CAP configuration phase. Over LE, ATT_MTU should be 23 octets.
---
 attrib/gattrib.c |   32 ++++++++++++++++++++------------
 1 file changed, 20 insertions(+), 12 deletions(-)

diff --git a/attrib/gattrib.c b/attrib/gattrib.c
index 29c3585..137e0ab 100644
--- a/attrib/gattrib.c
+++ b/attrib/gattrib.c
@@ -433,15 +433,34 @@ done:
 GAttrib *g_attrib_new(GIOChannel *io)
 {
 	struct _GAttrib *attrib;
-	uint16_t omtu;
+	uint16_t imtu;
+	uint16_t att_mtu;
+	uint16_t cid;
+	GError *gerr = NULL;
 
 	g_io_channel_set_encoding(io, NULL, NULL);
 	g_io_channel_set_buffered(io, FALSE);
 
+	bt_io_get(io, BT_IO_L2CAP, &gerr,
+			BT_IO_OPT_IMTU, &imtu,
+			BT_IO_OPT_CID, &cid,
+			BT_IO_OPT_INVALID);
+
+	if (gerr) {
+		error("%s", gerr->message);
+		g_error_free(gerr);
+		return NULL;
+	}
+
 	attrib = g_try_new0(struct _GAttrib, 1);
 	if (attrib == NULL)
 		return NULL;
 
+	att_mtu = (cid == ATT_CID) ? ATT_DEFAULT_LE_MTU : imtu;
+
+	attrib->buf = g_malloc0(att_mtu);
+	attrib->buflen = att_mtu;
+
 	attrib->io = g_io_channel_ref(io);
 	attrib->requests = g_queue_new();
 	attrib->responses = g_queue_new();
@@ -450,17 +469,6 @@ GAttrib *g_attrib_new(GIOChannel *io)
 			G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
 			received_data, attrib);
 
-	if (bt_io_get(attrib->io, BT_IO_L2CAP, NULL,
-			BT_IO_OPT_OMTU, &omtu,
-			BT_IO_OPT_INVALID)) {
-		if (omtu == 0 || omtu > ATT_MAX_MTU)
-			omtu = ATT_MAX_MTU;
-	} else
-		omtu = ATT_DEFAULT_LE_MTU;
-
-	attrib->buf = g_malloc0(omtu);
-	attrib->buflen = omtu;
-
 	return g_attrib_ref(attrib);
 }
 
-- 
1.7.10.3


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

end of thread, other threads:[~2012-06-07 20:13 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-07  0:40 [RFC 1/8] gattrib: Fix GAttrib buffer allocation Andre Guedes
2012-06-07  0:40 ` [RFC 2/8] gattrib: Fix g_attrib_set_mtu Andre Guedes
2012-06-07  1:26   ` Anderson Lizardo
2012-06-07 20:13     ` Andre Guedes
2012-06-07  0:40 ` [RFC 3/8] attrib-server: Fix gatt_channel MTU value Andre Guedes
2012-06-07  0:40 ` [RFC 4/8] attrib-server: Fix mtu_exchange Andre Guedes
2012-06-07  0:41 ` [RFC 5/8] attrib-server: Update GAttrib buffer after Exchange MTU Andre Guedes
2012-06-07  0:41 ` [RFC 6/8] Remove omtu parameter from LE bt_io_connect calls Andre Guedes
2012-06-07  0:41 ` [RFC 7/8] Fix gatt_connect for BR/EDR Andre Guedes
2012-06-07  0:41 ` [RFC 8/8] Remove workaround in gatt_connect Andre Guedes
2012-06-07  7:03 ` [RFC 1/8] gattrib: Fix GAttrib buffer allocation Johan Hedberg
2012-06-07 13:13   ` 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).