mesh: provide memory pool for mesh_transport_keys

This commit is contained in:
Matthias Ringwald 2019-04-25 18:58:21 +02:00
parent fe49119220
commit 01e2bf9489
3 changed files with 53 additions and 2 deletions

View File

@ -1038,6 +1038,52 @@ void btstack_memory_mesh_network_key_free(mesh_network_key_t *mesh_network_key){
#endif
// MARK: mesh_transport_key_t
#if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_TRANSPORT_KEYS)
#if defined(MAX_NO_MESH_TRANSPORT_KEYS)
#error "Deprecated MAX_NO_MESH_TRANSPORT_KEYS defined instead of MAX_NR_MESH_TRANSPORT_KEYS. Please update your btstack_config.h to use MAX_NR_MESH_TRANSPORT_KEYS."
#else
#define MAX_NR_MESH_TRANSPORT_KEYS 0
#endif
#endif
#ifdef MAX_NR_MESH_TRANSPORT_KEYS
#if MAX_NR_MESH_TRANSPORT_KEYS > 0
static mesh_transport_key_t mesh_transport_key_storage[MAX_NR_MESH_TRANSPORT_KEYS];
static btstack_memory_pool_t mesh_transport_key_pool;
mesh_transport_key_t * btstack_memory_mesh_transport_key_get(void){
void * buffer = btstack_memory_pool_get(&mesh_transport_key_pool);
if (buffer){
memset(buffer, 0, sizeof(mesh_transport_key_t));
}
return (mesh_transport_key_t *) buffer;
}
void btstack_memory_mesh_transport_key_free(mesh_transport_key_t *mesh_transport_key){
btstack_memory_pool_free(&mesh_transport_key_pool, mesh_transport_key);
}
#else
mesh_transport_key_t * btstack_memory_mesh_transport_key_get(void){
return NULL;
}
void btstack_memory_mesh_transport_key_free(mesh_transport_key_t *mesh_transport_key){
// silence compiler warning about unused parameter in a portable way
(void) mesh_transport_key;
};
#endif
#elif defined(HAVE_MALLOC)
mesh_transport_key_t * btstack_memory_mesh_transport_key_get(void){
void * buffer = malloc(sizeof(mesh_transport_key_t));
if (buffer){
memset(buffer, 0, sizeof(mesh_transport_key_t));
}
return (mesh_transport_key_t *) buffer;
}
void btstack_memory_mesh_transport_key_free(mesh_transport_key_t *mesh_transport_key){
free(mesh_transport_key);
}
#endif
#endif
// init
void btstack_memory_init(void){
@ -1109,5 +1155,8 @@ void btstack_memory_init(void){
#if MAX_NR_MESH_NETWORK_KEYS > 0
btstack_memory_pool_create(&mesh_network_key_pool, mesh_network_key_storage, MAX_NR_MESH_NETWORK_KEYS, sizeof(mesh_network_key_t));
#endif
#if MAX_NR_MESH_TRANSPORT_KEYS > 0
btstack_memory_pool_create(&mesh_transport_key_pool, mesh_transport_key_storage, MAX_NR_MESH_TRANSPORT_KEYS, sizeof(mesh_transport_key_t));
#endif
#endif
}

View File

@ -152,13 +152,15 @@ sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void);
void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry);
#endif
#ifdef ENABLE_MESH
// mesh_network_pdu, mesh_transport_pdu, mesh_network_key
// mesh_network_pdu, mesh_transport_pdu, mesh_network_key, mesh_transport_key
mesh_network_pdu_t * btstack_memory_mesh_network_pdu_get(void);
void btstack_memory_mesh_network_pdu_free(mesh_network_pdu_t *mesh_network_pdu);
mesh_transport_pdu_t * btstack_memory_mesh_transport_pdu_get(void);
void btstack_memory_mesh_transport_pdu_free(mesh_transport_pdu_t *mesh_transport_pdu);
mesh_network_key_t * btstack_memory_mesh_network_key_get(void);
void btstack_memory_mesh_network_key_free(mesh_network_key_t *mesh_network_key);
mesh_transport_key_t * btstack_memory_mesh_transport_key_get(void);
void btstack_memory_mesh_transport_key_free(mesh_transport_key_t *mesh_transport_key);
#endif
#if defined __cplusplus

View File

@ -209,7 +209,7 @@ list_of_le_structs = [
["gatt_client", "whitelist_entry", "sm_lookup_entry"],
]
list_of_mesh_structs = [
['mesh_network_pdu', 'mesh_transport_pdu', 'mesh_network_key']
['mesh_network_pdu', 'mesh_transport_pdu', 'mesh_network_key', 'mesh_transport_key']
]
btstack_root = os.path.abspath(os.path.dirname(sys.argv[0]) + '/..')