Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How can i advertise my mac id of nrf52840 in DFU mode(secure_bootloader_ble_s140_pca10056)

Hi Nordic team,

                        I was working on nRF DFU (secure_bootloader_ble_s140_pca10056) .I just want to advertise my device mac id to Phones app while in OTA mode to specify devices while updating in same place.Im using nrf52840 custom board.I can get the mac id using function sd_ble_gap_addr_get(&ble_addr); .

1. How can advertise the mac id in while in OTA bootloader mode.

2. As i was new to nrF can you specify which file or which fuction should be edited for that.

pls help 

Thanks & Regards

Akshay

Parents
  • Hi,

    Do you have your own assigned public mac address, or do you want to use a random static type address like all the SDK examples do by default? In case of the latter I would not recommend you change the address because the DFU client libraries expect the address to stay the same as in the application +1:

    When the Buttonless Secure DFU Service enters the bootloader, the device enters DFU mode and starts advertising on BLE address + 1. This is done to prevent the client from using cached BLE services and characteristics data for the device. Buttonless Secure DFU Service without bonds

    Best regards,

    Vidar

  • Ok thanks for your reply vidar

    i got the mac id from of nrf52840 chip using function sd_ble_gap_addr_get(&ble_addr); .

    1.my question was how can i advertise my chips mac id(6 bytes long) to nrf connect app(or any phones app)while in dfu mode

    2. where should i add the mac id to get it advertise

Reply
  • Ok thanks for your reply vidar

    i got the mac id from of nrf52840 chip using function sd_ble_gap_addr_get(&ble_addr); .

    1.my question was how can i advertise my chips mac id(6 bytes long) to nrf connect app(or any phones app)while in dfu mode

    2. where should i add the mac id to get it advertise

Children
  • The default chip address is already included in the advertisment packet so you don't have to change anything. Are you testing with an iPhone by any chance? If so, please note that Core Bluetooth framework does not expose discovered BT addresses to apps such as nRF connect.This is also why our iOS DFU library need to set a new DFU device name prior to entering DFU mode:

    When the Buttonless Secure DFU Service enters the bootloader, the device enters DFU mode and starts advertising on BLE address + 1. This is done to prevent the client from using cached BLE services and characteristics data for the device.

    Setting an alternative advertisement name was added to help locate peer devices in DFU mode when the API for the client application does not provide direct access to the Bluetooth address. [this applies to iOS]

    Setting a new advertisement name is optional, but it must be done prior to requesting to enter DFU mode. It is not possible to set it more than once before entering DFU mode. The advertisement name will be reset upon a successful Device Firmware Update, or when the DFU mode times out due to inactivity.

  • 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];

    ble_gap_adv_data_t m_adv_data =
    {
    .adv_data =
    {
    .p_data = m_enc_advdata,
    .len = APP_ADV_DATA_HEADER_SIZE,
    }
    };

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

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

    in this function i can see they are adding the data to the advertisement buffer m_enc_advdata[0]

    can we add our custom data to specify the device from other(data some thing related to us)

    1. Is that possible

    2 .where should i add

  • Hi,

    does the identification need to be unique for each device, or unique for your product? In the latter case you may consider generating a random 128 bit UUID and add it to the scan response packet.

    e.g.

    /*216484f7-ace1-4de7-8164-bf4f61203793*/
    #define RANDOM_UUID  {{0x93, 0x37, 0x20, 0x61, 0x4f, 0xbf, 0x64, 0x81, 0xe7, 0x4d, 0xe1, 0xac, 0xf7, 0x84, 0x64, 0x21}}  
    
    
    /**@brief     Function for the Advertising functionality initialization.
     *
     * @details   Encodes the required advertising data and passes it to the stack.
     *            The advertising data encoded here is specific for DFU.
     */
    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;
        ble_uuid128_t random_uuid = RANDOM_UUID;
    
        /* 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_scan_rsp[BLE_GAP_ADV_SET_DATA_SIZE_MAX];
    
        ble_gap_adv_data_t m_adv_data =
        {
            .adv_data =
            {
                .p_data = m_enc_advdata,
                .len    = APP_ADV_DATA_HEADER_SIZE,
            },
    
            .scan_rsp_data =
            {
                .p_data = m_enc_scan_rsp,
                .len    = BLE_GAP_ADV_SET_DATA_SIZE_MAX,
            }
        };
    
        /* Add 128-bit UUID to scan response packet */
        m_enc_scan_rsp[0] = sizeof(ble_uuid128_t) + 1;  /* Length field in bytes. 128-bit UUID + Type field   */
        m_enc_scan_rsp[1] = BLE_GAP_AD_TYPE_128BIT_SERVICE_UUID_COMPLETE;
        
        memcpy(&m_enc_scan_rsp[2], &random_uuid, sizeof(random_uuid));
    
        m_adv_data.scan_rsp_data.len = sizeof(ble_uuid128_t) + 2; // Length field + type field + 128 bit uuid
    
        /* 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;
    
        return sd_ble_gap_adv_set_configure(&m_adv_handle, &m_adv_data, p_adv_params);
    }

Related