<?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>Adding scan response gives invalid flags</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/61829/adding-scan-response-gives-invalid-flags</link><description>I see this quote in response to a question asking for examples on how to code a scan response 
 
 possibly not - but it&amp;#39;s trivial - just encode the scan response in the same way you encode the advertising data and then add the encoded data to the p_sr_data</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 02 Jun 2020 07:17:20 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/61829/adding-scan-response-gives-invalid-flags" /><item><title>RE: Adding scan response gives invalid flags</title><link>https://devzone.nordicsemi.com/thread/252626?ContentTypeID=1</link><pubDate>Tue, 02 Jun 2020 07:17:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ea7a5781-a086-4536-8d0e-1ee424372d2e</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;You&amp;#39;re right, it&amp;#39;s not very easy to understand, and it seems like the part about the local name isn&amp;#39;t relevant. I will report this internally and hopefully, we&amp;#39;ll clarify this note in a future release. Thank you for your suggestion!&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Adding scan response gives invalid flags</title><link>https://devzone.nordicsemi.com/thread/252428?ContentTypeID=1</link><pubDate>Fri, 29 May 2020 13:20:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8792814f-d071-4f36-ac6e-fc1fd66a3eb0</guid><dc:creator>brianreinhold</dc:creator><description>&lt;p&gt;I guess it is best to ignore the note. I have checked on the air and the advertisement and scan response are what I expect given how I have populated it. And I DO duplicate the name in both. So that is clearly not an issue. Might I suggest that the Note say the both the adv and scan response are limited to 31 bytes? The rest of the text makes no sense and is not even true as I can duplicate the name.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Adding scan response gives invalid flags</title><link>https://devzone.nordicsemi.com/thread/252350?ContentTypeID=1</link><pubDate>Fri, 29 May 2020 09:44:46 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:365c9627-94ed-4c01-9164-bd248aec579a</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Yes, that is correct, both advertisement and scan response are 31 bytes each.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Adding scan response gives invalid flags</title><link>https://devzone.nordicsemi.com/thread/252318?ContentTypeID=1</link><pubDate>Fri, 29 May 2020 08:40:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b2d47a49-93e0-42ae-9510-befc221b24b3</guid><dc:creator>brianreinhold</dc:creator><description>&lt;p&gt;Still sounds weird but I took the flags out of the scan response but not the duplicate name. I no longer get the error and it looks like it worked ... BUT I did not check it on the air.&lt;/p&gt;
&lt;p&gt;IN any case, I am still not sure of the limitation. I have plenty of room byte-wise...(I am assuming 31 bytes in the adv and 31 bytes in the scan response. Is that not true?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Adding scan response gives invalid flags</title><link>https://devzone.nordicsemi.com/thread/252313?ContentTypeID=1</link><pubDate>Fri, 29 May 2020 07:57:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fcb76913-5df0-4256-ab5a-43e09239b712</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;&amp;quot;Limitations imposed by this API call to the data provided include having a flags data type in the scan response data and&amp;nbsp;duplicating the local name in the advertising data and scan response data.&amp;quot; means that the scan response data is &lt;strong&gt;limited to, and therefore can not&amp;nbsp;&lt;/strong&gt;include flags or duplicates of the local name. I can see how this can be misunderstood and I&amp;#39;m sorry you did.&amp;nbsp; Hopefully, this clarifies things for you.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Adding scan response gives invalid flags</title><link>https://devzone.nordicsemi.com/thread/252184?ContentTypeID=1</link><pubDate>Thu, 28 May 2020 12:46:38 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ec4a9ab8-7f08-491b-b915-9261bbed6f1f</guid><dc:creator>brianreinhold</dc:creator><description>&lt;p&gt;That&amp;#39;s what I thought, but the documentation specifically says that I have to do it! That is what confused the life out of me.&lt;/p&gt;
&lt;p&gt;Here I quote the documentation:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/**@brief Configure an advertising set. Set, clear or update advertising and scan response data.
 *
 * @note  The format of the advertising data will be checked by this call to ensure interoperability.
 *        Limitations imposed by this API call to the data provided include having a flags data type in the scan response data and
 *        duplicating the local name in the advertising data and scan response data.
 *
 * @note In order to update advertising data while advertising, new advertising buffers must be provided.
 *
 * @mscs
 * @mmsc{@ref BLE_GAP_ADV_MSC}
 * @mmsc{@ref BLE_GAP_WL_SHARE_MSC}
 * @endmscs
 *
 * @param[in,out] p_adv_handle                         Provide a pointer to a handle containing @ref BLE_GAP_ADV_SET_HANDLE_NOT_SET to configure
 *                                                     a new advertising set. On success, a new handle is then returned through the pointer.
 *                                                     Provide a pointer to an existing advertising handle to configure an existing advertising set.
 * @param[in]     p_adv_data                           Advertising data. If set to NULL, no advertising data will be used. See @ref ble_gap_adv_data_t.
 * @param[in]     p_adv_params                         Advertising parameters. When this function is used to update advertising data while advertising,
 *                                                     this parameter must be NULL. See @ref ble_gap_adv_params_t.
 *
 * @retval ::NRF_SUCCESS                               Advertising set successfully configured.
 * @retval ::NRF_ERROR_INVALID_PARAM                   Invalid parameter(s) supplied:
 *                                                      - Invalid advertising data configuration specified. See @ref ble_gap_adv_data_t.
 *                                                      - Invalid configuration of p_adv_params. See @ref ble_gap_adv_params_t.
 *                                                      - Use of whitelist requested but whitelist has not been set,
 *                                                        see @ref sd_ble_gap_whitelist_set.
 * @retval ::BLE_ERROR_GAP_INVALID_BLE_ADDR            ble_gap_adv_params_t::p_peer_addr is invalid.
 * @retval ::NRF_ERROR_INVALID_STATE                   Invalid state to perform operation. Either:
 *                                                     - It is invalid to provide non-NULL advertising set parameters while advertising.
 *                                                     - It is invalid to provide the same data buffers while advertising. To update
 *                                                       advertising data, provide new advertising buffers.
 * @retval ::BLE_ERROR_GAP_DISCOVERABLE_WITH_WHITELIST Discoverable mode and whitelist incompatible.
 * @retval ::BLE_ERROR_INVALID_ADV_HANDLE              The provided advertising handle was not found. Use @ref BLE_GAP_ADV_SET_HANDLE_NOT_SET to
 *                                                     configure a new advertising handle.
 * @retval ::NRF_ERROR_INVALID_ADDR                    Invalid pointer supplied.
 * @retval ::NRF_ERROR_INVALID_FLAGS                   Invalid combination of advertising flags supplied.
 * @retval ::NRF_ERROR_INVALID_DATA                    Invalid data type(s) supplied. Check the advertising data format specification
 *                                                     given in Bluetooth Specification Version 5.0, Volume 3, Part C, Chapter 11.
 * @retval ::NRF_ERROR_INVALID_LENGTH                  Invalid data length(s) supplied.
 * @retval ::NRF_ERROR_NOT_SUPPORTED                   Unsupported data length or advertising parameter configuration.
 * @retval ::NRF_ERROR_NO_MEM                          Not enough memory to configure a new advertising handle. Update an
 *                                                     existing advertising handle instead.
 * @retval ::BLE_ERROR_GAP_UUID_LIST_MISMATCH Invalid UUID list supplied.
 */
SVCALL(SD_BLE_GAP_ADV_SET_CONFIGURE, uint32_t, sd_ble_gap_adv_set_configure(adapter_t *adapter, uint8_t *p_adv_handle, ble_gap_adv_data_t const *p_adv_data, ble_gap_adv_params_t const *p_adv_params));
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;As I stated in the initial post the @Note was very confusing and did not make any sense but I did as it says&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt; * @note  The format of the advertising data will be checked by this call to ensure interoperability.
 *        Limitations imposed by this API call to the data provided include having a flags data type in the scan response data and
 *        duplicating the local name in the advertising data and scan response data.&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;and duplicated the flags and name in the scan response.&lt;/p&gt;
&lt;p&gt;If that is not what the @Note is saying, what is it telling me to do?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Adding scan response gives invalid flags</title><link>https://devzone.nordicsemi.com/thread/252166?ContentTypeID=1</link><pubDate>Thu, 28 May 2020 12:10:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c9bbb29b-3d33-4acc-83b3-3d9e948bbae5</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Thank you for specifying!&lt;/p&gt;
&lt;p&gt;I see that you have set the advertising flags in your scan response as well. Adding advertising flags in the scan response isn&amp;#39;t allowed, and will return the INVALID FLAGS error that you&amp;#39;re seeing.&amp;nbsp;I&amp;#39;m struggling to see why&amp;nbsp;you have written &amp;quot;Required Nordic duplicate&amp;quot; regarding these? We don&amp;#39;t use advertising flags in scan responses in any of our examples. Please try removing these flags from your scan response data.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Adding scan response gives invalid flags</title><link>https://devzone.nordicsemi.com/thread/251990?ContentTypeID=1</link><pubDate>Wed, 27 May 2020 14:04:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cbf14756-f127-4bb4-938f-db26896a5969</guid><dc:creator>brianreinhold</dc:creator><description>&lt;p&gt;The advertisement alone does NOT give the invalid flags. Only when I try to add the scan response. Here is the code. All the flag settings are defined by Nordic. They should be valid. Note that this is the pc-ble-driver and the code is on a PC. I am making direct calls to the sd_* methods via the pc-ble-driver serial interface.&lt;/p&gt;
&lt;p&gt;Note further that the code to populate the scan response is commented out because its addition causes the INVALID FLAGS error. Without it, the code works.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;static ble_gap_adv_params_t     m_adv_params;
static ble_gap_adv_data_t m_adv_data;
static uint8_t  data_buffer[BUFFER_SIZE];
static uint8_t  scan_rsp_buffer[BUFFER_SIZE];

uint32_t advertisement_data_set(adapter_t* adapter, uint8_t* advHandle, short int* serviceUuids,
    int length, uint8_t* service128Uuids, const char* friendlyName)
{
    uint32_t error_code;
    uint8_t  index = 0;
    uint8_t  scan_index = 0;
    uint8_t  i = 0;
    char printBuf[256];
    memset(printBuf, 0, 256);
    memset(data_buffer, 0, sizeof(data_buffer));
    memset(scan_rsp_buffer, 0, sizeof(scan_rsp_buffer));

    const uint8_t name_length = (uint8_t)strlen(friendlyName);

    // Set the flags - important to indicate no EDR/BR support for some Androids
    // Actually by spec one is SUPPOSED to set one of the discoverable flags to be discoverable.
    data_buffer[index++] = 2;        // length of flags data type
    data_buffer[index++] = BLE_GAP_AD_TYPE_FLAGS;
    data_buffer[index++] = BLE_GAP_ADV_FLAG_LE_GENERAL_DISC_MODE | BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED;    // No EDR/BR support and general discoverable

    // Required Nordic duplicate for the scan response
    scan_rsp_buffer[scan_index++] = 2;        // length of flags data type
    scan_rsp_buffer[scan_index++] = BLE_GAP_AD_TYPE_FLAGS;
    scan_rsp_buffer[scan_index++] = BLE_GAP_ADV_FLAG_LE_GENERAL_DISC_MODE | BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED;

    // Set the device name.
    if (friendlyName != NULL)
    {
        data_buffer[index++] = name_length + 1; // Device name + data type
        data_buffer[index++] = BLE_GAP_AD_TYPE_COMPLETE_LOCAL_NAME;
        memcpy((char*)&amp;amp;data_buffer[index], friendlyName, name_length);
        index += name_length;
    }

    // Set the device full name as a copy in the scan response.
    if (friendlyName != NULL)
    {
        scan_rsp_buffer[scan_index++] = name_length + 1; // Device name + data type
        scan_rsp_buffer[scan_index++] = BLE_GAP_AD_TYPE_COMPLETE_LOCAL_NAME;
        memcpy((char*)&amp;amp;scan_rsp_buffer[scan_index], friendlyName, name_length);
        scan_index += name_length;
    }

    if (serviceUuids != NULL)
    {
        // Set the device&amp;#39;s available services.
        data_buffer[index++] = 1 + 2 * length;
        data_buffer[index++] = BLE_GAP_AD_TYPE_16BIT_SERVICE_UUID_COMPLETE;
        for (i = 0; i &amp;lt; length; i++)
        {
            // Store in little-endian format.
            data_buffer[index++] = serviceUuids[i] &amp;amp; 0xFF;
            data_buffer[index++] = (serviceUuids[i] &amp;amp; 0xFF00) &amp;gt;&amp;gt; 8;
        }
    }

    // Scan response:
    if (service128Uuids != NULL)
    {
        scan_rsp_buffer[scan_index++] = 1 + 16; //(only room for one)
        scan_rsp_buffer[scan_index++] = BLE_GAP_AD_TYPE_128BIT_SERVICE_UUID_MORE_AVAILABLE;
        // Store in little-endian format.
        memcpy(&amp;amp;scan_rsp_buffer[scan_index], service128Uuids, 16);
        scan_index = scan_index + 16;
    }


    ble_gap_adv_properties_t adv_properties;
    adv_properties.type = BLE_GAP_ADV_TYPE_CONNECTABLE_SCANNABLE_UNDIRECTED;
    adv_properties.anonymous = 0;
    adv_properties.include_tx_power = 0;

    m_adv_params.properties = adv_properties;
    m_adv_params.filter_policy = BLE_GAP_ADV_FP_ANY;
    m_adv_params.duration = BLE_GAP_ADV_TIMEOUT_GENERAL_UNLIMITED;
    m_adv_params.p_peer_addr = NULL;
    m_adv_params.interval = ADVERTISING_INTERVAL_40_MS;
    m_adv_params.max_adv_evts = 0;
    m_adv_params.primary_phy = BLE_GAP_PHY_AUTO;
    m_adv_params.secondary_phy = BLE_GAP_PHY_AUTO;
    m_adv_params.channel_mask[0] = 0;
    m_adv_params.channel_mask[1] = 0;
    m_adv_params.channel_mask[2] = 0;
    m_adv_params.channel_mask[3] = 0;
    m_adv_params.channel_mask[4] = 0;

    memset (&amp;amp;m_adv_data, 0, sizeof(m_adv_data));

    m_adv_data.adv_data.p_data = data_buffer;
    m_adv_data.adv_data.len = index;
 //   m_adv_data.scan_rsp_data.p_data = scan_rsp_buffer;
 //   m_adv_data.scan_rsp_data.len = scan_index;

    printf(&amp;quot;Advertising data set\n&amp;quot;);
    printf(&amp;quot;Advertisement %s\n&amp;quot;, byteToHex(m_adv_data.adv_data.p_data, &amp;amp;printBuf[0], &amp;quot;, &amp;quot;, m_adv_data.adv_data.len));
  //  if (scan_index &amp;gt; 0)
  //  {
  //      memset(printBuf, 0, 256);
  //      printf(&amp;quot;Scan Response %s\n&amp;quot;, byteToHex(m_adv_data.scan_rsp_data.p_data, &amp;amp;printBuf[0], &amp;quot;, &amp;quot;, m_adv_data.scan_rsp_data.len));
  //  }

    error_code = sd_ble_gap_adv_set_configure(adapter, advHandle, &amp;amp;m_adv_data, &amp;amp;m_adv_params);

    if (error_code != NRF_SUCCESS)
    {
        if (error_code == 10)
        {
            printf(&amp;quot;Failed to set advertisement data. Error code: invalid flags\n&amp;quot;);
        }
        else
        {
            printf(&amp;quot;Failed to set advertisement data. Error code: 0x%02X\n&amp;quot;, error_code);
        }
        fflush(stdout);
        return error_code;
    }
    fflush(stdout);
    return NRF_SUCCESS;
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Adding scan response gives invalid flags</title><link>https://devzone.nordicsemi.com/thread/251945?ContentTypeID=1</link><pubDate>Wed, 27 May 2020 12:25:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a0ecc9b8-8cdf-4d03-9729-7d007b4073e5</guid><dc:creator>Simonr</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;The&lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v16.0.0/ble_sdk_app_nus_eval.html"&gt; ble_app_uart example&lt;/a&gt;, for one, in the SDK uses scan response data for adding UUID (see the srdata calls in the advertising_init() function). What advertising flag(s) are you setting in order to receive the INVALID FLAGS return error?&lt;/p&gt;
&lt;p&gt;You can also check out our &lt;a href="https://devzone.nordicsemi.com/nordic/short-range-guides/b/bluetooth-low-energy/posts/ble-services-a-beginners-tutorial"&gt;Bluetooth Low Energy Services tutorial&lt;/a&gt;, which explains in detail how to add scan responses to your advertising data.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>