microbit: Persistance of BLE Service Chnaged metadata

BLE maintains metadata on its characterisitics, some of which record whether
or not a central device (phone/tablet) wishes to receive notifications when a
given BLE characteristic changes value. One such characterisitic is used as
part of a core BLE service to indicate of the BLE profile of a device has
changed.

IOS is heavily reliant on this feature, and expects the state of this metadata
to be persistent across device reboots. This patch ensures that this metadata
is always set to allow Service Changed indications to be propagated to central
devices.
This commit is contained in:
Joe Finney 2016-01-25 17:12:17 +00:00
parent 6a7436e5c7
commit 99d7231945

View file

@ -52,7 +52,6 @@ static void bleDisconnectionCallback(const Gap::DisconnectionCallbackParams_t *r
if (manager)
manager->advertise();
}
/**
@ -60,7 +59,16 @@ static void bleDisconnectionCallback(const Gap::DisconnectionCallbackParams_t *r
*/
static void bleConnectionCallback(const Gap::ConnectionCallbackParams_t *reason)
{
// Ensure that there's no stale, cached information in the client... invalidate all characteristics.
uint16_t len = 8;
// Configure the ServiceChanged characteristic to receive service changed indications
// TODO: This is really a workaround as we can't maintain persistent state on the micro:bit across USB
// reprogramming flashes.... yet.
uint8_t data[] = {0x0B,0x00,0x02,0x00,0x02,0x00,0xB8,0x46};
sd_ble_gatts_sys_attr_set(reason->handle, data, len, BLE_GATTS_SYS_ATTR_FLAG_SYS_SRVCS);
sd_ble_gatts_service_changed(reason->handle, 0x000c, 0xffff);
}