mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-02-27 03:39:56 +00:00
mesh: add internal index to network keys
This commit is contained in:
parent
859d0ce23e
commit
4517f741ac
@ -246,6 +246,9 @@ static void mesh_network_key_add_from_provisioning_data(const mesh_provisioning_
|
||||
// get key
|
||||
mesh_network_key_t * network_key = btstack_memory_mesh_network_key_get();
|
||||
|
||||
// internal index 0 for primary network key
|
||||
network_key->internal_index = 0;
|
||||
|
||||
// get single instance
|
||||
memset(network_key, 0, sizeof(mesh_network_key_t));
|
||||
|
||||
|
@ -51,16 +51,30 @@ static void mesh_print_hex(const char * name, const uint8_t * data, uint16_t len
|
||||
|
||||
// network key list
|
||||
static btstack_linked_list_t network_keys;
|
||||
static uint8_t mesh_network_key_used[MAX_NR_MESH_NETWORK_KEYS];
|
||||
|
||||
void mesh_network_key_init(void){
|
||||
network_keys = NULL;
|
||||
}
|
||||
|
||||
uint16_t mesh_network_key_get_free_index(void){
|
||||
// find empty slot, skip slot #0 reserved for primary network key
|
||||
uint16_t i;
|
||||
for (i=1;i < MAX_NR_MESH_NETWORK_KEYS ; i++){
|
||||
if (mesh_network_key_used[i] == 0){
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mesh_network_key_add(mesh_network_key_t * network_key){
|
||||
mesh_network_key_used[network_key->internal_index] = 1;
|
||||
btstack_linked_list_add_tail(&network_keys, (btstack_linked_item_t *) network_key);
|
||||
}
|
||||
|
||||
int mesh_network_key_remove(mesh_network_key_t * network_key){
|
||||
mesh_network_key_used[network_key->internal_index] = 1;
|
||||
return btstack_linked_list_remove(&network_keys, (btstack_linked_item_t *) network_key);
|
||||
}
|
||||
|
||||
|
@ -60,6 +60,9 @@ typedef enum {
|
||||
typedef struct {
|
||||
btstack_linked_item_t item;
|
||||
|
||||
// internal index [0..MAX_NR_MESH_NETWORK_KEYS-1]
|
||||
uint16_t internal_index;
|
||||
|
||||
// index into shared global key list
|
||||
uint16_t netkey_index;
|
||||
|
||||
@ -136,6 +139,13 @@ typedef struct {
|
||||
*/
|
||||
void mesh_network_key_init(void);
|
||||
|
||||
/**
|
||||
* @brief Get internal index of free network key storage entry
|
||||
* @note index 0 is reserved for primary network key
|
||||
* @returns index or 0u if none found
|
||||
*/
|
||||
uint16_t mesh_network_key_get_free_index(void);
|
||||
|
||||
/**
|
||||
* @brief Add network key to list
|
||||
* @param network_key
|
||||
|
Loading…
x
Reference in New Issue
Block a user