You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
Currently, in gatts, services can only be added at the time of stack init.
int
ble_gatts_count_cfg(const struct ble_gatt_svc_def *defs)
{
struct ble_gatt_resources res = { 0 };
int rc;
rc = ble_gatts_count_resources(defs, &res);
if (rc != 0) {
return rc;
}
ble_hs_max_services += res.svcs;
ble_hs_max_attrs += res.attrs;
/* Reserve an extra CCCD for the cache. */
ble_hs_max_client_configs +=
res.cccds * (MYNEWT_VAL(BLE_MAX_CONNECTIONS) + 1);
return 0;
}
All the memory needed for services and attributes is pre-decided and cannot be changed later.
I found the approach to implement dynamic addition/deletion of the services below.
In the above diagram, the current scheme(old scheme) :
ble_gatts_clt_cfg_pool allocates the entire ble_gatts_clt_cfg array in one go. This restricts the further addition of any clt_cfg if needed in case if the service containing subscribable characteristics is added.
The ble_gatts_clt_cfgs static global array present in ble_gatts.c file cannot be extended further if needed due to its fix size.
This same data structure also reflects in the ble_gatts_conn present in ble_gatt_priv.h file. This structure is stored for each connection.
Beyond the memory allocated in mempool no memory can be allocated at the runtime from mempool.
In the new scheme, the following changes solve the problems with the current scheme :
ble_gatts_clt_cfg_pool allocates only one clt_cfg block at a time. This allows the further addition of clt_cfg blocks in case of new service containing a subscribable characteristic is added.
ble_gatts_clt_cfgs will be converted to a list instead of an array. This solves the problem of adding the clt_cfg at runtime.
ble_gatts_conn will also be converted to list.
Whenever the dynamic service is added, the memory will be allocated directly using malloc. At the time of deinit, the mempool memory can be freed using the check os_memblock_from(). If the check fails the memory is freed using normal free().
The text was updated successfully, but these errors were encountered:
Hi,
Currently, in gatts, services can only be added at the time of stack init.
All the memory needed for services and attributes is pre-decided and cannot be changed later.
I found the approach to implement dynamic addition/deletion of the services below.
In the above diagram, the current scheme(old scheme) :
In the new scheme, the following changes solve the problems with the current scheme :
os_memblock_from()
. If the check fails the memory is freed using normal free().The text was updated successfully, but these errors were encountered: