mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-02-28 16:11:24 +00:00
mesh: mesh_virtual_address_register returns mesh_virtual_address_t, only call add subscription if virtual address not already contained
This commit is contained in:
parent
1f45d60344
commit
c216d5d320
@ -1127,7 +1127,8 @@ int btstack_main(void)
|
||||
|
||||
// PTS Virtual Address Label UUID - without Config Model, PTS uses our device uuid
|
||||
btstack_parse_hex("001BDC0810210B0E0A0C000B0E0A0C00", 16, label_uuid);
|
||||
pts_proxy_dst = mesh_virtual_address_register(label_uuid, 0x9779);
|
||||
mesh_virtual_address_t * virtual_addresss = mesh_virtual_address_register(label_uuid, 0x9779);
|
||||
pts_proxy_dst = virtual_addresss->pseudo_dst;
|
||||
|
||||
// PTS Device UUID
|
||||
btstack_parse_hex(pts_device_uuid_string, 16, pts_device_uuid);
|
||||
|
@ -883,18 +883,26 @@ static void config_model_subscription_virtual_address_add_hash(void *arg){
|
||||
mesh_model_t * mesh_model = mesh_model_get_configuration_server();
|
||||
|
||||
// add if not exists
|
||||
uint16_t pseudo_dst = MESH_ADDRESS_UNSASSIGNED;
|
||||
mesh_virtual_address_t * virtual_address = mesh_virtual_address_for_label_uuid(model_subscription_label_uuid);
|
||||
if (virtual_address == NULL){
|
||||
// add virtual address
|
||||
pseudo_dst = mesh_virtual_address_register(model_subscription_label_uuid, model_subscription_hash);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t status;
|
||||
if (pseudo_dst == MESH_ADDRESS_UNSASSIGNED){
|
||||
uint8_t status = MESH_FOUNDATION_STATUS_SUCCESS;
|
||||
uint16_t pseudo_dst = MESH_ADDRESS_UNSASSIGNED;
|
||||
if (virtual_address == NULL){
|
||||
status = MESH_FOUNDATION_STATUS_INSUFFICIENT_RESOURCES;
|
||||
} else {
|
||||
status = mesh_model_add_subscription(target_model, pseudo_dst);
|
||||
pseudo_dst = virtual_address->pseudo_dst;
|
||||
if (!mesh_model_contains_subscription(target_model, pseudo_dst)){
|
||||
status = mesh_model_add_subscription(target_model, pseudo_dst);
|
||||
}
|
||||
}
|
||||
|
||||
config_model_subscription_status(mesh_model, mesh_pdu_netkey_index(access_pdu_in_process), mesh_pdu_src(access_pdu_in_process), status, model_subscription_element_address, pseudo_dst, target_model->model_identifier);
|
||||
@ -933,18 +941,28 @@ static void config_model_subscription_virtual_address_overwrite_hash(void *arg){
|
||||
mesh_model_t * mesh_model = mesh_model_get_configuration_server();
|
||||
|
||||
// add if not exists
|
||||
uint16_t pseudo_dst = MESH_ADDRESS_UNSASSIGNED;
|
||||
mesh_virtual_address_t * virtual_address = mesh_virtual_address_for_label_uuid(model_subscription_label_uuid);
|
||||
if (virtual_address == NULL){
|
||||
// add virtual address
|
||||
pseudo_dst = mesh_virtual_address_register(model_subscription_label_uuid, model_subscription_hash);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t status;
|
||||
if (pseudo_dst == MESH_ADDRESS_UNSASSIGNED){
|
||||
uint8_t status = MESH_FOUNDATION_STATUS_SUCCESS;
|
||||
uint16_t pseudo_dst = MESH_ADDRESS_UNSASSIGNED;
|
||||
if (virtual_address == NULL){
|
||||
status = MESH_FOUNDATION_STATUS_INSUFFICIENT_RESOURCES;
|
||||
} else {
|
||||
status = mesh_model_overwrite_subscription(target_model, pseudo_dst);
|
||||
// clear subscriptions
|
||||
mesh_model_delete_all_subscriptions(target_model);
|
||||
|
||||
// add new subscription
|
||||
pseudo_dst = virtual_address->pseudo_dst;
|
||||
status = mesh_model_add_subscription(target_model, pseudo_dst);
|
||||
}
|
||||
|
||||
config_model_subscription_status(mesh_model, mesh_pdu_netkey_index(access_pdu_in_process), mesh_pdu_src(access_pdu_in_process), status, model_subscription_element_address, pseudo_dst, target_model->model_identifier);
|
||||
|
@ -909,8 +909,9 @@ TEST(MessageTest, Message22Send){
|
||||
mesh_lower_transport_set_seq(seq);
|
||||
uint8_t label_uuid[16];
|
||||
btstack_parse_hex(message22_label_string, 16, label_uuid);
|
||||
uint16_t proxy_dst = mesh_virtual_address_register(label_uuid, 0xb529);
|
||||
test_send_access_message(netkey_index, appkey_index, ttl, src, proxy_dst, szmic, message22_upper_transport_pdu, 1, message22_lower_transport_pdus, message22_network_pdus);
|
||||
mesh_virtual_address_t * virtual_address = mesh_virtual_address_register(label_uuid, 0xb529);
|
||||
uint16_t pseudo_dst = virtual_address->pseudo_dst;
|
||||
test_send_access_message(netkey_index, appkey_index, ttl, src, pseudo_dst, szmic, message22_upper_transport_pdu, 1, message22_lower_transport_pdus, message22_network_pdus);
|
||||
}
|
||||
|
||||
// Message 23
|
||||
@ -944,8 +945,9 @@ TEST(MessageTest, Message23Send){
|
||||
mesh_lower_transport_set_seq(seq);
|
||||
uint8_t label_uuid[16];
|
||||
btstack_parse_hex(message23_label_string, 16, label_uuid);
|
||||
uint16_t proxy_dst = mesh_virtual_address_register(label_uuid, 0x9736);
|
||||
test_send_access_message(netkey_index, appkey_index, ttl, src, proxy_dst, szmic, message23_upper_transport_pdu, 1, message23_lower_transport_pdus, message23_network_pdus);
|
||||
mesh_virtual_address_t * virtual_address = mesh_virtual_address_register(label_uuid, 0x9736);
|
||||
uint16_t pseudo_dst = virtual_address->pseudo_dst;
|
||||
test_send_access_message(netkey_index, appkey_index, ttl, src, pseudo_dst, szmic, message23_upper_transport_pdu, 1, message23_lower_transport_pdus, message23_network_pdus);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -981,8 +983,9 @@ TEST(MessageTest, Message24Send){
|
||||
mesh_lower_transport_set_seq(seq);
|
||||
uint8_t label_uuid[16];
|
||||
btstack_parse_hex(message24_label_string, 16, label_uuid);
|
||||
uint16_t proxy_dst = mesh_virtual_address_register(label_uuid, 0x9736);
|
||||
test_send_access_message(netkey_index, appkey_index, ttl, src, proxy_dst, szmic, message24_upper_transport_pdu, 2, message24_lower_transport_pdus, message24_network_pdus);
|
||||
mesh_virtual_address_t * virtual_address = mesh_virtual_address_register(label_uuid, 0x9736);
|
||||
uint16_t pseudo_dst = virtual_address->pseudo_dst;
|
||||
test_send_access_message(netkey_index, appkey_index, ttl, src, pseudo_dst, szmic, message24_upper_transport_pdu, 2, message24_lower_transport_pdus, message24_network_pdus);
|
||||
}
|
||||
|
||||
// Proxy Configuration Test
|
||||
|
@ -82,19 +82,6 @@ void mesh_upper_transport_send_access_pdu(mesh_pdu_t * pdu);
|
||||
// Virtual Address Management
|
||||
//
|
||||
|
||||
/**
|
||||
* @brief Register Virtual Address
|
||||
* @param LabelUUID (16 bytes)
|
||||
* @returns pseudo_dst that can be used as dst with all mesh_uppert_transport calls
|
||||
*/
|
||||
uint16_t mesh_virtual_address_register(uint8_t * label_uuid, uint16_t hash);
|
||||
|
||||
/**
|
||||
* @brief Unregister Virtual Address
|
||||
* @param pseudo_dst to unregister
|
||||
*/
|
||||
void mesh_virtual_address_unregister(uint16_t pseudo_dst);
|
||||
|
||||
// test
|
||||
void mesh_lower_transport_received_message(mesh_network_callback_type_t callback_type, mesh_network_pdu_t *network_pdu);
|
||||
void mesh_lower_transport_dump(void);
|
||||
|
@ -56,20 +56,26 @@ static void mesh_print_hex(const char * name, const uint8_t * data, uint16_t len
|
||||
|
||||
static mesh_virtual_address_t test_virtual_address;
|
||||
|
||||
static void mesh_virtual_address_run(void){
|
||||
void mesh_virtual_address_add(mesh_virtual_address_t * virtual_address){
|
||||
// printf("TODO: implement mesh_virtual_address_add\n");
|
||||
virtual_address->pseudo_dst = 0x8000;
|
||||
memcpy(&test_virtual_address, virtual_address, sizeof(mesh_virtual_address_t));
|
||||
}
|
||||
|
||||
uint16_t mesh_virtual_address_register(uint8_t * label_uuid, uint16_t hash){
|
||||
// TODO:: check if already exists
|
||||
// TODO: calc hash
|
||||
test_virtual_address.hash = hash;
|
||||
memcpy(test_virtual_address.label_uuid, label_uuid, 16);
|
||||
test_virtual_address.pseudo_dst = 0x8000;
|
||||
mesh_virtual_address_run();
|
||||
return test_virtual_address.pseudo_dst;
|
||||
void mesh_virtual_address_remove(mesh_virtual_address_t * virtual_address){
|
||||
printf("TODO: implement mesh_virtual_address_remove\n");
|
||||
}
|
||||
|
||||
void mesh_virtual_address_unregister(uint16_t pseudo_dst){
|
||||
// helper
|
||||
mesh_virtual_address_t * mesh_virtual_address_register(uint8_t * label_uuid, uint16_t hash){
|
||||
mesh_virtual_address_t * virtual_address = btstack_memory_mesh_virtual_address_get();
|
||||
if (virtual_address == NULL) return NULL;
|
||||
|
||||
virtual_address->hash = hash;
|
||||
memcpy(virtual_address->label_uuid, label_uuid, 16);
|
||||
mesh_virtual_address_add(virtual_address);
|
||||
|
||||
return virtual_address;
|
||||
}
|
||||
|
||||
mesh_virtual_address_t * mesh_virtual_address_for_pseudo_dst(uint16_t pseudo_dst){
|
||||
|
@ -60,7 +60,11 @@ typedef struct {
|
||||
|
||||
// virtual address management
|
||||
|
||||
uint16_t mesh_virtual_address_register(uint8_t * label_uuid, uint16_t hash);
|
||||
void mesh_virtual_address_add(mesh_virtual_address_t * virtual_address);
|
||||
|
||||
void mesh_virtual_address_remove(mesh_virtual_address_t * virtual_address);
|
||||
|
||||
mesh_virtual_address_t * mesh_virtual_address_register(uint8_t * label_uuid, uint16_t hash);
|
||||
|
||||
mesh_virtual_address_t * mesh_virtual_address_for_pseudo_dst(uint16_t pseudo_dst);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user