From 64f864173393f6e750a94b895f39119ca80b93df Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Thu, 12 Mar 2015 16:18:45 +0200 Subject: 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. --- attrib/gattrib.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'attrib') 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; } -- cgit v1.2.1