From 1905d90eaa65b6b306c84038cc1ad32e4e601f65 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Wed, 5 Jun 2019 20:08:53 -0400 Subject: [PATCH] Make advertising data buffers long-lived --- ports/nrf/common-hal/bleio/Peripheral.c | 5 ++++- ports/nrf/common-hal/bleio/Peripheral.h | 4 ++-- 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 2cd52841a3..e522b50d28 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 58526fc484..eb0b0417a1 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;