mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-01-30 15:32:41 +00:00
mesh: assign unique pseudo_dst to virtual addresses
This commit is contained in:
parent
1e0992b52f
commit
c5b2420dc1
@ -886,11 +886,15 @@ 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);
|
||||
if (virtual_address == NULL){
|
||||
// add virtual address
|
||||
virtual_address = btstack_memory_mesh_virtual_address_get();
|
||||
if (virtual_address != NULL){
|
||||
virtual_address->hash = model_subscription_hash;
|
||||
memcpy(virtual_address->label_uuid, model_subscription_label_uuid, 16);
|
||||
mesh_virtual_address_add(virtual_address);
|
||||
uint16_t pseudo_dst = mesh_virtual_addresses_get_free_pseudo_dst();
|
||||
if (pseudo_dst != MESH_ADDRESS_UNSASSIGNED){
|
||||
virtual_address = btstack_memory_mesh_virtual_address_get();
|
||||
if (virtual_address != NULL){
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -944,11 +948,15 @@ 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);
|
||||
if (virtual_address == NULL){
|
||||
// add virtual address
|
||||
virtual_address = btstack_memory_mesh_virtual_address_get();
|
||||
if (virtual_address != NULL){
|
||||
virtual_address->hash = model_subscription_hash;
|
||||
memcpy(virtual_address->label_uuid, model_subscription_label_uuid, 16);
|
||||
mesh_virtual_address_add(virtual_address);
|
||||
uint16_t pseudo_dst = mesh_virtual_addresses_get_free_pseudo_dst();
|
||||
if (pseudo_dst != MESH_ADDRESS_UNSASSIGNED){
|
||||
virtual_address = btstack_memory_mesh_virtual_address_get();
|
||||
if (virtual_address != NULL){
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,22 +47,37 @@
|
||||
// virtual address management
|
||||
|
||||
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){
|
||||
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);
|
||||
}
|
||||
|
||||
void mesh_virtual_address_remove(mesh_virtual_address_t * virtual_address){
|
||||
btstack_linked_list_remove(&mesh_virtual_addresses, (void *) virtual_address);
|
||||
mesh_virtual_addresses_used[virtual_address->pseudo_dst-0x8000] = 0;
|
||||
}
|
||||
|
||||
// helper
|
||||
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();
|
||||
if (virtual_address == NULL) return NULL;
|
||||
|
||||
virtual_address->hash = hash;
|
||||
virtual_address->pseudo_dst = pseudo_dst;
|
||||
memcpy(virtual_address->label_uuid, label_uuid, 16);
|
||||
mesh_virtual_address_add(virtual_address);
|
||||
|
||||
|
@ -61,6 +61,8 @@ typedef struct {
|
||||
|
||||
// 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_remove(mesh_virtual_address_t * virtual_address);
|
||||
|
Loading…
x
Reference in New Issue
Block a user