Diff between 1f6bd25b1ad1c055cf3eac8e0c5b987a357a33fb and 64f864173393f6e750a94b895f39119ca80b93df

Changed Files

File Additions Deletions Status
attrib/gattrib.c +15 -0 modified

Full Patch

diff --git a/attrib/gattrib.c b/attrib/gattrib.c
index 514fc8f..2011359 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;
 }