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

Add scan response data to DFU bootloader

Hello together,

I try to add some bytes for scan response data in DFU bootloader. So I changed the file components/libraries/bootloader/ble_dfu/nrf_dfu_ble.c to add 6 bytes:

static uint32_t advertising_init(uint8_t adv_flags, ble_gap_adv_params_t const * const p_adv_params)
{
    uint32_t err_code;
    uint16_t actual_device_name_length = BLE_GAP_ADV_SET_DATA_SIZE_MAX - APP_ADV_DATA_HEADER_SIZE;

    /* This needs to be static because of SoftDevice API requirements. */
    static uint8_t m_enc_advdata[BLE_GAP_ADV_SET_DATA_SIZE_MAX];
    static uint8_t m_enc_resp_data[6];

    ble_gap_adv_data_t m_adv_data =
    {
        .adv_data =
        {
            .p_data = m_enc_advdata,
            .len    = APP_ADV_DATA_HEADER_SIZE,
        },
        //================This is added by me
        .scan_rsp_data =
        {
            .p_data = m_enc_resp_data,
            .len    = 6,
        }
        //======================================
    };

    /* Encode flags. */
    m_enc_advdata[0] = 0x2;
    m_enc_advdata[1] = BLE_GAP_AD_TYPE_FLAGS;
    m_enc_advdata[2] = adv_flags;

    /* Encode 'more available' UUID list. */
    m_enc_advdata[3] = 0x3;
    m_enc_advdata[4] = BLE_GAP_AD_TYPE_16BIT_SERVICE_UUID_MORE_AVAILABLE;
    m_enc_advdata[5] = LSB_16(BLE_DFU_SERVICE_UUID);
    m_enc_advdata[6] = MSB_16(BLE_DFU_SERVICE_UUID);

    /* Get GAP device name and length. */
    err_code = sd_ble_gap_device_name_get(&m_enc_advdata[9], &actual_device_name_length);
    if (err_code != NRF_SUCCESS)
    {
        return err_code;
    }

    // Set GAP device in advertising data.
    m_enc_advdata[7] = actual_device_name_length + 1; // (actual_length + ADV_AD_TYPE_FIELD_SIZE(1))
    m_enc_advdata[8] = BLE_GAP_AD_TYPE_COMPLETE_LOCAL_NAME;

    m_adv_data.adv_data.len += actual_device_name_length;
    
    //============This is added by me
    //Add scan response data
    m_enc_resp_data[0]=0x0A;
    m_enc_resp_data[1]=0x0B;
    m_enc_resp_data[2]=0x0C;
    m_enc_resp_data[3]=0x0D;
    m_enc_resp_data[4]=0x0E;
    m_enc_resp_data[5]=0x0F;
    //=================================

    return sd_ble_gap_adv_set_configure(&m_adv_handle, &m_adv_data, p_adv_params);
}

But then, the bootloader does not advertize. If I remove the 6 lines which set the m_enc_resp_data single bytes, the bootloader advertizes (but I see no scan response data in nrfConnect).

I use SDK 15.3 with SD112 on nrf52810.

Parents
  • Hi,

    You can't just add arbitrary bytes to a advertising/scan-response packet like this. It follows a certain format. See this post. Based on the flags and data you provide, the device that scans these packets decodes and displays the data in different ways. In the nRF5 SDK, we have the function ble_advdata_encode() that helps you encode the data in the correct format.

    You have m_enc_resp_data[0]=0x0A , so you are indicating that you have 0x0A length of data, but at the same time you are setting scan_rsp_data.len to 6. Try setting m_enc_resp_data[0] to 0x05 instead.

Reply
  • Hi,

    You can't just add arbitrary bytes to a advertising/scan-response packet like this. It follows a certain format. See this post. Based on the flags and data you provide, the device that scans these packets decodes and displays the data in different ways. In the nRF5 SDK, we have the function ble_advdata_encode() that helps you encode the data in the correct format.

    You have m_enc_resp_data[0]=0x0A , so you are indicating that you have 0x0A length of data, but at the same time you are setting scan_rsp_data.len to 6. Try setting m_enc_resp_data[0] to 0x05 instead.

Children
No Data
Related