summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Halbert <halbert@halwitz.org>2019-06-05 20:08:53 -0400
committerDan Halbert <halbert@halwitz.org>2019-06-05 20:08:53 -0400
commit1905d90eaa65b6b306c84038cc1ad32e4e601f65 (patch)
tree057d67d2d4e532e4ec791d10439993d30ec57f8d
parent613e12f99fd101a2c6b4b738da398a270aede538 (diff)
Make advertising data buffers long-lived
-rw-r--r--ports/nrf/common-hal/bleio/Peripheral.c5
-rw-r--r--ports/nrf/common-hal/bleio/Peripheral.h4
2 files changed, 6 insertions, 3 deletions
diff --git a/ports/nrf/common-hal/bleio/Peripheral.c b/ports/nrf/common-hal/bleio/Peripheral.c
index 2cd52841a..e522b50d2 100644
--- a/ports/nrf/common-hal/bleio/Peripheral.c
+++ b/ports/nrf/common-hal/bleio/Peripheral.c
@@ -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;
diff --git a/ports/nrf/common-hal/bleio/Peripheral.h b/ports/nrf/common-hal/bleio/Peripheral.h
index 58526fc48..eb0b0417a 100644
--- a/ports/nrf/common-hal/bleio/Peripheral.h
+++ b/ports/nrf/common-hal/bleio/Peripheral.h
@@ -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;