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

Does the advertising uuids passed to ble_advdata_set need to persist?

I'm using a snippet from the ble_app_uart example and see in the examples:

//static ble_uuid_t adv_uuids[1];

static void advertising_init(void)
{
    uint32_t      err_code;
    ble_advdata_t advdata;
    ble_advdata_t scanrsp;
    uint8_t       flags = BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE;
    
    ble_uuid_t adv_uuids[] = {{BLE_UUID_NUS_SERVICE, m_nus.uuid_type}};
    //adv_uuids[0].uuid = BLE_UUID_NUS_SERVICE;
    //adv_uuids[0].type = m_nus.uuid_type;

    memset(&advdata, 0, sizeof(advdata));
    advdata.name_type               = BLE_ADVDATA_FULL_NAME;
    advdata.include_appearance      = false;
    advdata.flags                   = flags;

    memset(&scanrsp, 0, sizeof(scanrsp));
    scanrsp.uuids_complete.uuid_cnt = sizeof(adv_uuids) / sizeof(adv_uuids[0]);
    scanrsp.uuids_complete.p_uuids  = adv_uuids;        

    err_code = ble_advdata_set(&advdata, &scanrsp);
    APP_ERROR_CHECK(err_code);
}

scanrsp.uuids_complete.p_uuids = adv_uuids;

We pass a pointer and it's unclear whether the actual data needs to persist longer than the call to the function. Basically, is it OK that adv_uuids is a local variable? Does ble_advdata_set make a copy of the contents of the pointer?

Related