<?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>What is the difference between &amp;quot;data length&amp;quot; and MTU?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/41629/what-is-the-difference-between-data-length-and-mtu</link><description>I want to use BLE 4.2 Data length extension to stuff more data into one packet. I am looking at the &amp;quot;ble_app_att_mtu_throughput&amp;quot; example and am getting confused because there is both a NRF_BLE_GATT_EVT_ATT_MTU_UPDATED event and a NRF_BLE_GATT_EVT_DATA_LENGTH_UPDATED</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 21 Dec 2018 10:00:31 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/41629/what-is-the-difference-between-data-length-and-mtu" /><item><title>RE: What is the difference between "data length" and MTU?</title><link>https://devzone.nordicsemi.com/thread/162811?ContentTypeID=1</link><pubDate>Fri, 21 Dec 2018 10:00:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:48406355-263a-4091-845a-465e84d9539c</guid><dc:creator>bjorn-spockeli</dc:creator><description>&lt;p&gt;I think the data length is set to 27 before the ATT MTU update to 140 and then this update leads to the datalength being increased to&amp;nbsp; 140. Let me know if you see 140byte on the air or not.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: What is the difference between "data length" and MTU?</title><link>https://devzone.nordicsemi.com/thread/162781?ContentTypeID=1</link><pubDate>Fri, 21 Dec 2018 07:42:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b45d37db-6554-4f47-9fcd-b11dd44e2312</guid><dc:creator>Andrew Ong</dc:creator><description>&lt;p&gt;Actually, I just did a manual check and&amp;nbsp;it reports that my data length is 140!&amp;nbsp;I never get the&amp;nbsp;NRF_BLE_GATT_EVT_DATA_LENGTH_UPDATED event, but it looks like the data length changed anyway!&amp;nbsp; I&amp;#39;m going to test it now.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void data_len_set(uint8_t value)
{
    ret_code_t err_code;
    err_code = nrf_ble_gatt_data_length_set(&amp;amp;m_gatt, BLE_CONN_HANDLE_INVALID, value);
    APP_ERROR_CHECK(err_code);

    uint8_t future_data_length = 0;
    nrf_ble_gatt_data_length_get(&amp;amp;m_gatt, BLE_CONN_HANDLE_INVALID, &amp;amp;future_data_length);
    NRF_LOG_INFO(&amp;quot;Next data length set to %u bytes.&amp;quot;, future_data_length);
}

/**@brief Function for handling events from the GATT library. */
static void gatt_evt_handler(nrf_ble_gatt_t * p_gatt, nrf_ble_gatt_evt_t const * p_evt)
{
    (void) p_gatt; //UNUSED 

    switch (p_evt-&amp;gt;evt_id)
    {
        case NRF_BLE_GATT_EVT_ATT_MTU_UPDATED:
        {

            NRF_LOG_INFO(&amp;quot;ATT MTU exchange completed. MTU set to %u bytes.&amp;quot;,
                         p_evt-&amp;gt;params.att_mtu_effective);

            NRF_LOG_INFO(&amp;quot;Data length is %u bytes.&amp;quot;, p_evt-&amp;gt;params.data_length);
        } break;

        case NRF_BLE_GATT_EVT_DATA_LENGTH_UPDATED:
        {
            NRF_LOG_INFO(&amp;quot;Data length updated to %u bytes.&amp;quot;, p_evt-&amp;gt;params.data_length);
        } break;
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;&amp;lt;info&amp;gt; app: Next data length set to 144 bytes.
&amp;lt;info&amp;gt; app: Slow advertising.
&amp;lt;info&amp;gt; app: Connected to a previously bonded device.
&amp;lt;debug&amp;gt; ble_gatt: Requesting to update ATT MTU to 140 bytes on connection 0x0.
&amp;lt;debug&amp;gt; ble_gatt: Requesting to update data length to 144 on connection 0x0.
&amp;lt;info&amp;gt; app: Reset challenge status on conn_handle 0x0
&amp;lt;info&amp;gt; app: Connected
&amp;lt;info&amp;gt; app: connection interval: min 24, max: 24
&amp;lt;debug&amp;gt; ble_gatt: Data length updated to 27 on connection 0x0.
&amp;lt;debug&amp;gt; ble_gatt: max_rx_octets: 27
&amp;lt;debug&amp;gt; ble_gatt: max_tx_octets: 27
&amp;lt;debug&amp;gt; ble_gatt: max_rx_time: 328
&amp;lt;debug&amp;gt; ble_gatt: max_tx_time: 328
&amp;lt;info&amp;gt; app: Data length updated to 27 bytes.
&amp;lt;info&amp;gt; app: Bonding...
&amp;lt;info&amp;gt; app: Connection secured: role: 1, conn_handle: 0x0, procedure: 0.
&amp;lt;debug&amp;gt; ble_gatt: ATT MTU updated to 140 bytes on connection 0x0 (response).
&amp;lt;info&amp;gt; app: ATT MTU exchange completed. MTU set to 140 bytes.
&amp;lt;info&amp;gt; app: Data length is 140 bytes.
&amp;lt;info&amp;gt; app: Peer data updated.
&amp;lt;info&amp;gt; app: Peer data updated.&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;These results confuse me. It says &amp;quot;Requesting to update data length to 144&amp;quot;, then it says &amp;quot;data length updated to 27 bytes&amp;quot;. The number 27 is nowhere in my code. THEN it says &amp;quot;Data length IS 140&amp;quot;. I&amp;#39;m just going to assume&amp;nbsp;the data length is 140 now. Time to test.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: What is the difference between "data length" and MTU?</title><link>https://devzone.nordicsemi.com/thread/162780?ContentTypeID=1</link><pubDate>Fri, 21 Dec 2018 07:37:26 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f6c6383a-ad9c-4e1a-8ac0-cef1ee7a4d35</guid><dc:creator>Andrew Ong</dc:creator><description>&lt;p&gt;No, the data length does not increase when I set&amp;nbsp;&lt;span&gt;DATA_LEN_MAX to 130. Data length stays at 27.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I am using microBits as sniffers but they do not pick up&amp;nbsp;my connection, so I don&amp;#39;t have a sniffer trace to show.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: What is the difference between "data length" and MTU?</title><link>https://devzone.nordicsemi.com/thread/162704?ContentTypeID=1</link><pubDate>Thu, 20 Dec 2018 15:18:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0f779763-b4c7-42b9-968c-aebf715fb746</guid><dc:creator>bjorn-spockeli</dc:creator><description>&lt;p&gt;Hmm, that is weird. Do you see the data length increasing if you set to a value below&amp;nbsp;&lt;span&gt;NRF_SDH_BLE_GATT_MAX_MTU_SIZE, i.e. 140? If not could you capture a sniffer trace with a BLE protocol analyzer or the nRF Sniffer? It would help to see if a request to increase the data length is sent or not.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: What is the difference between "data length" and MTU?</title><link>https://devzone.nordicsemi.com/thread/162562?ContentTypeID=1</link><pubDate>Wed, 19 Dec 2018 19:40:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:73ee53c6-c507-4342-9d44-9a8e4b9ec29f</guid><dc:creator>Andrew Ong</dc:creator><description>&lt;p&gt;&lt;span&gt;#define DATA_LEN_MAX 251&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;i run APP_ERROR_CHECK on&amp;nbsp;nrf_ble_gatt_data_length_set and it never complains. I&amp;#39;m assuming this means no errors.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: What is the difference between "data length" and MTU?</title><link>https://devzone.nordicsemi.com/thread/162543?ContentTypeID=1</link><pubDate>Wed, 19 Dec 2018 16:22:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:eca7d7d4-62f4-4911-ba09-e921f01159e1</guid><dc:creator>bjorn-spockeli</dc:creator><description>&lt;p&gt;What is&amp;nbsp;&lt;span&gt;DATA_LEN_MAX set to? Does nrf_ble_gatt_data_length_set return a non-zero error code?&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: What is the difference between "data length" and MTU?</title><link>https://devzone.nordicsemi.com/thread/162403?ContentTypeID=1</link><pubDate>Wed, 19 Dec 2018 06:17:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2ec50533-7709-42cc-8706-9ed3a3830fca</guid><dc:creator>Andrew Ong</dc:creator><description>&lt;p&gt;I am using SDK 14.0.0 with Softdevice S132 5.0.0.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I tried using the function&amp;nbsp;data_len_set(DATA_LEN_MAX) right before advertising_start()&amp;nbsp;as demonstrated in the SDK 15.0.0 example, but the call seems to be&amp;nbsp;ignored. My data length remains at 27 no matter where I place data_len_set(DATA_LEN_MAX).&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: What is the difference between "data length" and MTU?</title><link>https://devzone.nordicsemi.com/thread/162346?ContentTypeID=1</link><pubDate>Tue, 18 Dec 2018 16:00:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:038d4de2-9836-4451-9bac-83230f16b936</guid><dc:creator>bjorn-spockeli</dc:creator><description>&lt;p&gt;This is defined in the BLE v4.2 specification,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Which SDK version are you using, SDK v14.2 ? It looks like&amp;nbsp;&lt;span&gt;NRF_SDH_BLE_GAP_DATA_LENGTH&amp;nbsp;was added in SDK v15.0.0.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Looking at the ble_app_througput example in SDK v14.2.0&amp;nbsp; it seems that the data length is set to&amp;nbsp;247 + L2CAP_HDR_LEN if&amp;nbsp;data_len_ext_enabled is true&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;// function seting the data length to be used in connections. 
void data_len_ext_set(bool status)
{
    m_test_params.data_len_ext_enabled = status;

    uint8_t data_length = status ? (247 + L2CAP_HDR_LEN) : (23 + L2CAP_HDR_LEN);
    (void) nrf_ble_gatt_data_length_set(&amp;amp;m_gatt, BLE_CONN_HANDLE_INVALID, data_length);
}

// data_len_ext_set is called from main()
data_len_ext_set(m_test_params.data_len_ext_enabled);

// m_test_params is defined in main.c
static test_params_t m_test_params =
{
    .att_mtu                  = NRF_SDH_BLE_GATT_MAX_MTU_SIZE,
    .conn_interval            = CONN_INTERVAL_DEFAULT,
    .data_len_ext_enabled     = true,
    .conn_evt_len_ext_enabled = true,
    // Only symmetric PHYs are supported.
#if defined(S140)
    .phys.tx_phys             = BLE_GAP_PHY_2MBPS | BLE_GAP_PHY_1MBPS | BLE_GAP_PHY_CODED,
    .phys.rx_phys             = BLE_GAP_PHY_2MBPS | BLE_GAP_PHY_1MBPS | BLE_GAP_PHY_CODED,
#else
    .phys.tx_phys             = BLE_GAP_PHY_2MBPS | BLE_GAP_PHY_1MBPS,
    .phys.rx_phys             = BLE_GAP_PHY_2MBPS | BLE_GAP_PHY_1MBPS,
#endif
};&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I think its a artifact as its been fixed in SDK v15.x.x&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void data_len_set(uint8_t value)
{
    ret_code_t err_code;
    err_code = nrf_ble_gatt_data_length_set(&amp;amp;m_gatt, BLE_CONN_HANDLE_INVALID, value);
    APP_ERROR_CHECK(err_code);

    m_test_params.data_len = value;
}&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: What is the difference between "data length" and MTU?</title><link>https://devzone.nordicsemi.com/thread/162194?ContentTypeID=1</link><pubDate>Tue, 18 Dec 2018 03:50:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:40d43cb0-2026-4525-ac26-8c27d7a388ba</guid><dc:creator>Andrew Ong</dc:creator><description>&lt;p&gt;So the &amp;quot;data length&amp;quot; is the lower level number. Wow. What&amp;#39;s the point of&amp;nbsp;having an ATT MTU AND a data length? Why not just have a &amp;quot;data length&amp;quot;?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;This must be&amp;nbsp;why BLE 4.2 has the feature called &amp;quot;Data length extension&amp;quot;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;My defines are set like this:&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;#define&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;NRF_SDH_BLE_GATT_MAX_MTU_SIZE&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;140&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;NRF_SDH_BLE_GAP_DATA_LENGTH is nowhere in my project. Was that introduced in SDK 15.0.0?&amp;nbsp;Since that is not defined, do I change the data length with&amp;nbsp;nrf_ble_gatt_data_length_set()? For some reason, that function has a (void) prepended to it in the example. Why?&amp;nbsp;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: What is the difference between "data length" and MTU?</title><link>https://devzone.nordicsemi.com/thread/162140?ContentTypeID=1</link><pubDate>Mon, 17 Dec 2018 16:06:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e7d116ad-e418-45dd-9479-6bed763543f1</guid><dc:creator>bjorn-spockeli</dc:creator><description>&lt;p&gt;Hi Andrew,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;the ATT MTU is the maximum transmission unit for the the ATT protocol which encapsulated inside the Data Channel PDU and the data length is the the size of the Data Channel PDU, see &lt;a href="https://m.eet.com/media/1117455/bluefig2.gif"&gt;this &lt;/a&gt;illustration.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;So if the ATT MTU is increased to 140, but the Data length is 27, then the ATT data will be segmented into 27byte chunks. Hence, if you want to fit the entire ATT MTU within the Data Channel PDU(i.e. one BLE data packet), then the Data length must be set&amp;nbsp;higher than the ATT MTU size.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;From the log output it still appers that the Data length is 27 bytes.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;What have you set the following macros to in sdk_config?&lt;/p&gt;
&lt;p&gt;NRF_SDH_BLE_GAP_DATA_LENGTH&lt;/p&gt;
&lt;p&gt;NRF_SDH_BLE_GATT_MAX_MTU_SIZE&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>