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

Issues with dynamically adding/removing manufacturer specific data

Hey all,

I have a custom board running nRF52832 with Softdevice S132 v6.1.0 and SDK15.2. My application requires me to start advertising without any manufacturer data, then add manufacturer data in reaction to an event. To do this, when the event occurs, I stop the advertising, create a ble_advdata_manuf_data_t variable (in a function) and add my data, then pass it to the original advdata variable.

ble_advdata_manuf_data_t adv_manuf_data;

err_code = sd_ble_gap_adv_stop(m_adv_handle); //Stop advertising
APP_ERROR_CHECK(err_code);

memset(&adv_manuf_data, 0, sizeof(adv_manuf_data));

adv_manuf_data.data.p_data        = adv_manuf_data_data;
adv_manuf_data.data.size          = length;        
adv_manuf_data.company_identifier = 0x0059; //Nordic's company ID

advdata.p_manuf_specific_data = &adv_manuf_data;

err_code = ble_advdata_encode(&advdata, m_adv_data.adv_data.p_data, &m_adv_data.adv_data.len);
APP_ERROR_CHECK(err_code);

err_code = sd_ble_gap_adv_set_configure(&m_adv_handle, &m_adv_data, &adv_params);
APP_ERROR_CHECK(err_code);

err_code = sd_ble_gap_adv_start(m_adv_handle, APP_BLE_CONN_CFG_TAG); //Restart advertising
APP_ERROR_CHECK(err_code);

I should also point out that I have adv_manuf_data_data declared globally and have 16 btyes of space reserved for it. I also have advdata declared globaly, which I reuse (no double buffering since I stop advertising). However I am finding that I can only utilize about 6 bytes of adv_manuf_data_data before my application crashes, due to most likely some sort of a buffer overflow. I don't have a proper Segger debugger, so I can't see exactly what error I am getting. What I am seeing is that depending on how many of bytes of adv_manuf_data_data I actually put data in (even though 16 bytes should be reserved), I notice that the advertised device name gets truncated - this is why I think there is an overflow.
My understanding is, it is OK to modify advertising data as long as advertising is stopped when the modification happens. So I am not using double buffers like other people have suggested. Any idea why I am seeing this issue?
Thanks
Parents
  • I want to add one more thing I tried, to no avail:

    I have also tried globally declaring ble_advdata_manuf_data_t variable, instead of locally declaring within a function, but it made no difference - I see the exact same behavior. Since we pass the pointer of ble_advdata_manuf_data_t variable to the ble_advdata_t variable (advdata.p_manuf_specific_data), I figured it should be ok to dynamically change the contents of ble_advdata_manuf_data_t as long as advertising is stopped. And when I want to remove the manufacturer data again, I just point to a null pointer like so:

    advdata.p_manuf_specific_data = NULL;    

    But like I said, I see the issue as I described above. Thanks in advance.

Reply
  • I want to add one more thing I tried, to no avail:

    I have also tried globally declaring ble_advdata_manuf_data_t variable, instead of locally declaring within a function, but it made no difference - I see the exact same behavior. Since we pass the pointer of ble_advdata_manuf_data_t variable to the ble_advdata_t variable (advdata.p_manuf_specific_data), I figured it should be ok to dynamically change the contents of ble_advdata_manuf_data_t as long as advertising is stopped. And when I want to remove the manufacturer data again, I just point to a null pointer like so:

    advdata.p_manuf_specific_data = NULL;    

    But like I said, I see the issue as I described above. Thanks in advance.

Children
No Data
Related