<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>GATT Write Event data restricted to only 1 byte</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/10937/gatt-write-event-data-restricted-to-only-1-byte</link><description>The following seems to suggest each write event can only contain 1 byte of data at a time. 
 /**@brief Event structure for @ref BLE_GATTS_EVT_WRITE. */

typedef struct
{
 uint16_t handle; /**&amp;lt; Attribute Handle. */
 uint8_t op; /**&amp;lt; Type of write</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 23 Dec 2015 16:19:40 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/10937/gatt-write-event-data-restricted-to-only-1-byte" /><item><title>RE: GATT Write Event data restricted to only 1 byte</title><link>https://devzone.nordicsemi.com/thread/40885?ContentTypeID=1</link><pubDate>Wed, 23 Dec 2015 16:19:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8073d890-ec25-4895-845f-9f7fb6ed2510</guid><dc:creator>Maz Shar</dc:creator><description>&lt;p&gt;I have discovered this is only &amp;quot;safe&amp;quot; because an extra 23 bytes is allocated for the event buffer when initialising the soft device.&lt;/p&gt;
&lt;p&gt;See &lt;strong&gt;BLE_STACK_EVT_MSG_BUF_SIZE&lt;/strong&gt; in &lt;strong&gt;ble_stack_handler_types.h&lt;/strong&gt; which is allocated the size of a ble event + &lt;strong&gt;GATT_MTU_SIZE_DEFAULT&lt;/strong&gt; (23 bytes).&lt;/p&gt;
&lt;p&gt;So, the &lt;strong&gt;&lt;em&gt;data&lt;/em&gt;&lt;/strong&gt; property serves merely as a starting address. The write event secretly has an extra 23 bytes allocated to &amp;quot;account for&amp;quot; 20 bytes of data (removing headers).&lt;/p&gt;
&lt;p&gt;This is hacky and not what your answer informed me about at all.&lt;/p&gt;
&lt;p&gt;Would it not work to assign that &lt;strong&gt;GATT_MTU_SIZE_DEFAULT&lt;/strong&gt; to &lt;strong&gt;&lt;em&gt;data&lt;/em&gt;&lt;/strong&gt; property itself i.e. &lt;strong&gt;&lt;em&gt;data[GATT_MTU_SIZE_DEFAULT - GATT_HEADERS]&lt;/em&gt;&lt;/strong&gt;? where GATT_HEADERS = 3&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: GATT Write Event data restricted to only 1 byte</title><link>https://devzone.nordicsemi.com/thread/40887?ContentTypeID=1</link><pubDate>Mon, 21 Dec 2015 09:21:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a5000bcb-5afd-45be-834a-c7291b95a606</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;The debugger just shows you what it thinks it knows which is one byte, the actual data pointed to is safely allocated to be the correct length and can be read.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: GATT Write Event data restricted to only 1 byte</title><link>https://devzone.nordicsemi.com/thread/40886?ContentTypeID=1</link><pubDate>Mon, 21 Dec 2015 09:17:42 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cf1b8f1f-bffb-4c41-8ff5-b47d37090122</guid><dc:creator>Maz Shar</dc:creator><description>&lt;p&gt;I&amp;#39;m still interested in a response to my above comment. Thanks!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: GATT Write Event data restricted to only 1 byte</title><link>https://devzone.nordicsemi.com/thread/40884?ContentTypeID=1</link><pubDate>Fri, 18 Dec 2015 13:24:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:d17116b5-bca9-47d8-946a-5501d47a6d1e</guid><dc:creator>Maz Shar</dc:creator><description>&lt;blockquote&gt;
&lt;p&gt;&amp;quot;You can see there&amp;#39;s a length in there so you know there is more than one byte of data.&amp;quot;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The fact there is a length doesn&amp;#39;t mean we know there is more than one byte of data. That just tells us how far to read which can still be the wrong place, right?&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&amp;quot;It just means data is a &lt;em&gt;pointer&lt;/em&gt; to uint8_t with at least one byte in it.&amp;quot;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This does not seem to be the case with regards to safe memory allocation. I&amp;#39;ve looked at the memory through the debugger and saw that there is 1 byte allocated in the memory directly for &lt;em&gt;data&lt;/em&gt; in the ble_gatts_evt_write_t structure and not a 4-byte pointer which points to a value...&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: GATT Write Event data restricted to only 1 byte</title><link>https://devzone.nordicsemi.com/thread/40883?ContentTypeID=1</link><pubDate>Fri, 18 Dec 2015 12:11:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:16d51207-99ee-4f34-8df6-2e3c23c1a8ea</guid><dc:creator>P&amp;#229;l H&amp;#229;land</dc:creator><description>&lt;p&gt;Also explained in this answer: &lt;a href="https://devzone.nordicsemi.com/question/199/sending-more-than-8bits-of-data-over-bluetooth/"&gt;devzone.nordicsemi.com/.../&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: GATT Write Event data restricted to only 1 byte</title><link>https://devzone.nordicsemi.com/thread/40882?ContentTypeID=1</link><pubDate>Fri, 18 Dec 2015 11:50:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8871d38b-95fb-4deb-8e4d-f0100b2691db</guid><dc:creator>RK</dc:creator><description>&lt;p&gt;It&amp;#39;s a pretty standard C idiom. You can see there&amp;#39;s a length in there so you know there is more than one byte of data, it just means data is a pointer to uint8_t with at least one byte in it, you can just use it as a pointer to uint8_t with the cast, as you did, and read up to length bytes, the actual data pointed to will contain all the &amp;#39;len&amp;#39; bytes.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>