summaryrefslogtreecommitdiff
path: root/attrib
diff options
context:
space:
mode:
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2015-03-12 16:18:45 +0200
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>2015-03-15 09:01:36 +0200
commit64f864173393f6e750a94b895f39119ca80b93df (patch)
tree2260a12ec2c9137c6a90ca56f290719d64247c60 /attrib
parent1f6bd25b1ad1c055cf3eac8e0c5b987a357a33fb (diff)
downloadbluez-64f864173393f6e750a94b895f39119ca80b93df.tar.gz
attrib: Fix not honoring MTU
If MTU has changed, by bt_gatt_client for example, the code should be able to figure it out without waiting g_attrib_set_mtu to be called.
Diffstat (limited to 'attrib')
-rw-r--r--attrib/gattrib.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/attrib/gattrib.c b/attrib/gattrib.c
index 514fc8f5f..201135961 100644
--- a/attrib/gattrib.c
+++ b/attrib/gattrib.c
@@ -429,9 +429,24 @@ guint g_attrib_register(GAttrib *attrib, guint8 opcode, guint16 handle,
uint8_t *g_attrib_get_buffer(GAttrib *attrib, size_t *len)
{
+ uint16_t mtu;
+
if (!attrib || !len)
return NULL;
+ mtu = bt_att_get_mtu(attrib->att);
+
+ /*
+ * Clients of this expect a buffer to use.
+ *
+ * Pdu encoding in shared/att verifies if whole buffer fits the mtu,
+ * thus we should set the buflen also when mtu is reduced. But we
+ * need to reallocate the buffer only if mtu is larger.
+ */
+ if (mtu > attrib->buflen)
+ attrib->buf = g_realloc(attrib->buf, mtu);
+
+ attrib->buflen = mtu;
*len = attrib->buflen;
return attrib->buf;
}