This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Adding scan response gives invalid flags

I see this quote in response to a question asking for examples on how to code a scan response

possibly not - but it'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 and srdlen of the sd_ble_gap_adv_data_set(). Or if you're using the Advertising and Scan Response encoder library, one layer higher, the unencoded data into the last argument of ble_adv_data_set()p_srdata, if if you're using the entire advertising module, ble_advertising_init() with a non-NULL p_srdata second paramter.

Trivial it aint!!! Well at least regardless of what I place in the scan response I get invalid flags unless the scan response is empty.

Its a scannable advertsiement!

adv_properties.type = BLE_GAP_ADV_TYPE_CONNECTABLE_SCANNABLE_UNDIRECTED;

Then there is this very confusing statement in the documentation:

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.

I assumed what this means is that I duplicate the flags setting done in the advertisement and the friendly name setting in the advertisement. This is all I do and the advertisement alone works but when I add the scan response INVALID FLAGS!  Go figure. It doesn't seem to matter what I pit in there I get the same result

SO PLEASE

Provide an example that WORKS for a connectable peripheral.

Using the advertisement alone I have several Androids whose LeScanner (Lollipop +) do NOT report certain advertisements generated by the Nordic nRF52... dongle. Changing the NAME in the advertisement makes it detectable. I have only seen this behavior with ads generated by the Nordic chip (no market device I have worked with has that problem. I am beginning to think it has something to do with the messed up scan response from the Nordic. Sniffers DO detect the ads. I know Android needs to have a response to a scan request so I am trying desperately to generate one.

Here is the contents of the advertisement and scan response data

Advertisement 02, 01, 06, 0A, 09, 42, 70, 54, 69, 6D, 65, 4F, 6E, 65, 07, 03, 10, 18, 0A, 18, 05, 18
Scan Response 02, 01, 06, 0A, 09, 42, 70, 54, 69, 6D, 65, 4F, 6E, 65
Failed to set advertisement data. Error code: invalid flags

Parents
  • Thank you for specifying!

    I see that you have set the advertising flags in your scan response as well. Adding advertising flags in the scan response isn't allowed, and will return the INVALID FLAGS error that you're seeing. I'm struggling to see why you have written "Required Nordic duplicate" regarding these? We don't use advertising flags in scan responses in any of our examples. Please try removing these flags from your scan response data.

    Best regards,

    Simon

  • That's what I thought, but the documentation specifically says that I have to do it! That is what confused the life out of me.

    Here I quote the documentation:

    /**@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));
    

    As I stated in the initial post the @Note was very confusing and did not make any sense but I did as it says

     * @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.

    and duplicated the flags and name in the scan response.

    If that is not what the @Note is saying, what is it telling me to do?

Reply
  • That's what I thought, but the documentation specifically says that I have to do it! That is what confused the life out of me.

    Here I quote the documentation:

    /**@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));
    

    As I stated in the initial post the @Note was very confusing and did not make any sense but I did as it says

     * @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.

    and duplicated the flags and name in the scan response.

    If that is not what the @Note is saying, what is it telling me to do?

Children
No Data
Related