Make advertising data buffers long-lived

This commit is contained in:
Dan Halbert 2019-06-05 20:08:53 -04:00
parent 613e12f99f
commit 1905d90eaa
2 changed files with 6 additions and 3 deletions

View File

@ -177,9 +177,13 @@ void common_hal_bleio_peripheral_start_advertising(bleio_peripheral_obj_t *self,
}
check_data_fit(advertising_data_bufinfo->len);
// The advertising data buffers must not move, because the SoftDevice depends on them.
// So make them long-lived.
self->advertising_data = (uint8_t *) gc_alloc(BLE_GAP_ADV_SET_DATA_SIZE_MAX * sizeof(uint8_t), false, true);
memcpy(self->advertising_data, advertising_data_bufinfo->buf, advertising_data_bufinfo->len);
check_data_fit(scan_response_data_bufinfo->len);
self->scan_response_data = (uint8_t *) gc_alloc(BLE_GAP_ADV_SET_DATA_SIZE_MAX * sizeof(uint8_t), false, true);
memcpy(self->scan_response_data, scan_response_data_bufinfo->buf, scan_response_data_bufinfo->len);
@ -214,7 +218,6 @@ void common_hal_bleio_peripheral_start_advertising(bleio_peripheral_obj_t *self,
}
void common_hal_bleio_peripheral_stop_advertising(bleio_peripheral_obj_t *self) {
if (self->adv_handle == BLE_GAP_ADV_SET_HANDLE_NOT_SET)
return;

View File

@ -46,8 +46,8 @@ typedef struct {
// The advertising data and scan response buffers are held by us, not by the SD, so we must
// maintain them and not change it. If we need to change the contents during advertising,
// there are tricks to get the SD to notice (see DevZone - TBS).
uint8_t advertising_data[BLE_GAP_ADV_SET_DATA_SIZE_MAX];
uint8_t scan_response_data[BLE_GAP_ADV_SET_DATA_SIZE_MAX];
uint8_t* advertising_data;
uint8_t* scan_response_data;
uint8_t adv_handle;
} bleio_peripheral_obj_t;