mesh: add mesh_access_pdu_t and provide memory pool

This commit is contained in:
Matthias Ringwald 2018-11-09 11:33:32 +01:00
parent 1cbafa7ff4
commit 898500f031
4 changed files with 67 additions and 4 deletions

View File

@ -45,13 +45,36 @@
extern "C" {
#endif
#define MESH_DEVICE_KEY_INDEX 0xffff
#define MESH_NETWORK_PAYLOAD_MAX 29
#define MESH_ACCESS_PAYLOAD_MAX 384
// both mesh_network_du and mesh_access_pdu_t the same basic struct
typedef struct {
// allow for linked lists
btstack_linked_item_t item;
// meta data network layer
uint16_t netkey_index;
uint8_t len;
uint8_t data[29];
// meta data transport layer
uint16_t appkey_index;
// pdu
uint16_t len;
uint8_t data[MESH_NETWORK_PAYLOAD_MAX];
} mesh_network_pdu_t;
typedef struct {
// allow for linked lists
btstack_linked_item_t item;
// meta data network layer
uint16_t netkey_index;
// meta data transport layer
uint16_t appkey_index;
// pdu
uint16_t len;
uint8_t data[MESH_ACCESS_PAYLOAD_MAX];
} mesh_access_pdu_t;
//
typedef struct {
btstack_linked_item_t item;

View File

@ -938,6 +938,44 @@ void btstack_memory_mesh_network_pdu_free(mesh_network_pdu_t *mesh_network_pdu){
#endif
// MARK: mesh_access_pdu_t
#if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_ACCESS_PDUS)
#if defined(MAX_NO_MESH_ACCESS_PDUS)
#error "Deprecated MAX_NO_MESH_ACCESS_PDUS defined instead of MAX_NR_MESH_ACCESS_PDUS. Please update your btstack_config.h to use MAX_NR_MESH_ACCESS_PDUS."
#else
#define MAX_NR_MESH_ACCESS_PDUS 0
#endif
#endif
#ifdef MAX_NR_MESH_ACCESS_PDUS
#if MAX_NR_MESH_ACCESS_PDUS > 0
static mesh_access_pdu_t mesh_access_pdu_storage[MAX_NR_MESH_ACCESS_PDUS];
static btstack_memory_pool_t mesh_access_pdu_pool;
mesh_access_pdu_t * btstack_memory_mesh_access_pdu_get(void){
return (mesh_access_pdu_t *) btstack_memory_pool_get(&mesh_access_pdu_pool);
}
void btstack_memory_mesh_access_pdu_free(mesh_access_pdu_t *mesh_access_pdu){
btstack_memory_pool_free(&mesh_access_pdu_pool, mesh_access_pdu);
}
#else
mesh_access_pdu_t * btstack_memory_mesh_access_pdu_get(void){
return NULL;
}
void btstack_memory_mesh_access_pdu_free(mesh_access_pdu_t *mesh_access_pdu){
// silence compiler warning about unused parameter in a portable way
(void) mesh_access_pdu;
};
#endif
#elif defined(HAVE_MALLOC)
mesh_access_pdu_t * btstack_memory_mesh_access_pdu_get(void){
return (mesh_access_pdu_t*) malloc(sizeof(mesh_access_pdu_t));
}
void btstack_memory_mesh_access_pdu_free(mesh_access_pdu_t *mesh_access_pdu){
free(mesh_access_pdu);
}
#endif
// MARK: mesh_network_key_t
#if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_NETWORK_KEYS)
#if defined(MAX_NO_MESH_NETWORK_KEYS)

View File

@ -151,9 +151,11 @@ 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_network_key
// mesh_network_pdu, mesh_access_pdu, mesh_network_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_access_pdu_t * btstack_memory_mesh_access_pdu_get(void);
void btstack_memory_mesh_access_pdu_free(mesh_access_pdu_t *mesh_access_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);
#endif

View File

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