mesh: assign unique pseudo_dst to virtual addresses

This commit is contained in:
Matthias Ringwald 2019-06-11 18:29:23 +02:00
parent 1e0992b52f
commit c5b2420dc1
3 changed files with 38 additions and 13 deletions

View File

@ -886,12 +886,16 @@ static void config_model_subscription_virtual_address_add_hash(void *arg){
mesh_virtual_address_t * virtual_address = mesh_virtual_address_for_label_uuid(model_subscription_label_uuid); mesh_virtual_address_t * virtual_address = mesh_virtual_address_for_label_uuid(model_subscription_label_uuid);
if (virtual_address == NULL){ if (virtual_address == NULL){
// add virtual address // add virtual address
virtual_address = btstack_memory_mesh_virtual_address_get(); uint16_t pseudo_dst = mesh_virtual_addresses_get_free_pseudo_dst();
if (virtual_address != NULL){ if (pseudo_dst != MESH_ADDRESS_UNSASSIGNED){
virtual_address->hash = model_subscription_hash; virtual_address = btstack_memory_mesh_virtual_address_get();
memcpy(virtual_address->label_uuid, model_subscription_label_uuid, 16); if (virtual_address != NULL){
mesh_virtual_address_add(virtual_address); virtual_address->hash = model_subscription_hash;
} virtual_address->pseudo_dst = pseudo_dst;
memcpy(virtual_address->label_uuid, model_subscription_label_uuid, 16);
mesh_virtual_address_add(virtual_address);
}
}
} }
uint8_t status = MESH_FOUNDATION_STATUS_SUCCESS; uint8_t status = MESH_FOUNDATION_STATUS_SUCCESS;
@ -944,12 +948,16 @@ static void config_model_subscription_virtual_address_overwrite_hash(void *arg){
mesh_virtual_address_t * virtual_address = mesh_virtual_address_for_label_uuid(model_subscription_label_uuid); mesh_virtual_address_t * virtual_address = mesh_virtual_address_for_label_uuid(model_subscription_label_uuid);
if (virtual_address == NULL){ if (virtual_address == NULL){
// add virtual address // add virtual address
virtual_address = btstack_memory_mesh_virtual_address_get(); uint16_t pseudo_dst = mesh_virtual_addresses_get_free_pseudo_dst();
if (virtual_address != NULL){ if (pseudo_dst != MESH_ADDRESS_UNSASSIGNED){
virtual_address->hash = model_subscription_hash; virtual_address = btstack_memory_mesh_virtual_address_get();
memcpy(virtual_address->label_uuid, model_subscription_label_uuid, 16); if (virtual_address != NULL){
mesh_virtual_address_add(virtual_address); virtual_address->hash = model_subscription_hash;
} virtual_address->pseudo_dst = pseudo_dst;
memcpy(virtual_address->label_uuid, model_subscription_label_uuid, 16);
mesh_virtual_address_add(virtual_address);
}
}
} }
uint8_t status = MESH_FOUNDATION_STATUS_SUCCESS; uint8_t status = MESH_FOUNDATION_STATUS_SUCCESS;

View File

@ -47,22 +47,37 @@
// virtual address management // virtual address management
static btstack_linked_list_t mesh_virtual_addresses; static btstack_linked_list_t mesh_virtual_addresses;
static uint8_t mesh_virtual_addresses_used[MAX_NR_MESH_VIRTUAL_ADDRESSES];
uint16_t mesh_virtual_addresses_get_free_pseudo_dst(void){
uint16_t i;
for (i=0;i < MAX_NR_MESH_VIRTUAL_ADDRESSES ; i++){
if (mesh_virtual_addresses_used[i] == 0){
return 0x8000+i;
}
}
return MESH_ADDRESS_UNSASSIGNED;
}
void mesh_virtual_address_add(mesh_virtual_address_t * virtual_address){ void mesh_virtual_address_add(mesh_virtual_address_t * virtual_address){
virtual_address->pseudo_dst = 0x8000; mesh_virtual_addresses_used[virtual_address->pseudo_dst-0x8000] = 1;
btstack_linked_list_add(&mesh_virtual_addresses, (void *) virtual_address); btstack_linked_list_add(&mesh_virtual_addresses, (void *) virtual_address);
} }
void mesh_virtual_address_remove(mesh_virtual_address_t * virtual_address){ void mesh_virtual_address_remove(mesh_virtual_address_t * virtual_address){
btstack_linked_list_remove(&mesh_virtual_addresses, (void *) virtual_address); btstack_linked_list_remove(&mesh_virtual_addresses, (void *) virtual_address);
mesh_virtual_addresses_used[virtual_address->pseudo_dst-0x8000] = 0;
} }
// helper // helper
mesh_virtual_address_t * mesh_virtual_address_register(uint8_t * label_uuid, uint16_t hash){ mesh_virtual_address_t * mesh_virtual_address_register(uint8_t * label_uuid, uint16_t hash){
uint16_t pseudo_dst = mesh_virtual_addresses_get_free_pseudo_dst();
if (pseudo_dst == 0) return NULL;
mesh_virtual_address_t * virtual_address = btstack_memory_mesh_virtual_address_get(); mesh_virtual_address_t * virtual_address = btstack_memory_mesh_virtual_address_get();
if (virtual_address == NULL) return NULL; if (virtual_address == NULL) return NULL;
virtual_address->hash = hash; virtual_address->hash = hash;
virtual_address->pseudo_dst = pseudo_dst;
memcpy(virtual_address->label_uuid, label_uuid, 16); memcpy(virtual_address->label_uuid, label_uuid, 16);
mesh_virtual_address_add(virtual_address); mesh_virtual_address_add(virtual_address);

View File

@ -61,6 +61,8 @@ typedef struct {
// virtual address management // virtual address management
uint16_t mesh_virtual_addresses_get_free_pseudo_dst(void);
void mesh_virtual_address_add(mesh_virtual_address_t * virtual_address); void mesh_virtual_address_add(mesh_virtual_address_t * virtual_address);
void mesh_virtual_address_remove(mesh_virtual_address_t * virtual_address); void mesh_virtual_address_remove(mesh_virtual_address_t * virtual_address);