mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-01-26 21:35:16 +00:00
mesh: move virtual address utility functions to mesh from configuration server
This commit is contained in:
parent
0d42a0592d
commit
380f8b85c8
@ -47,6 +47,7 @@
|
||||
#include "btstack_event.h"
|
||||
#include "btstack_tlv.h"
|
||||
#include "btstack_memory.h"
|
||||
#include "btstack_debug.h"
|
||||
|
||||
#include "mesh/adv_bearer.h"
|
||||
#include "mesh/beacon.h"
|
||||
@ -69,6 +70,11 @@
|
||||
|
||||
// Persistent storage structures
|
||||
|
||||
typedef struct {
|
||||
uint16_t hash;
|
||||
uint8_t label_uuid[16];
|
||||
} mesh_persistent_virtual_address_t;
|
||||
|
||||
typedef struct {
|
||||
uint16_t netkey_index;
|
||||
|
||||
@ -299,6 +305,76 @@ void mesh_foundation_state_store(void){
|
||||
btstack_tlv_singleton_impl->store_tag(btstack_tlv_singleton_context, mesh_foundation_state_tag, (uint8_t *) &data, sizeof(data));
|
||||
}
|
||||
|
||||
// Mesh Virtual Address Management
|
||||
static uint32_t mesh_virtual_address_tag_for_pseudo_dst(uint16_t pseudo_dst){
|
||||
return ((uint32_t) 'M' << 24) | ((uint32_t) 'V' << 16) | ((uint32_t) pseudo_dst);
|
||||
}
|
||||
|
||||
static void mesh_store_virtual_address(uint16_t pseudo_dest, uint16_t hash, const uint8_t * label_uuid){
|
||||
mesh_persistent_virtual_address_t data;
|
||||
uint32_t tag = mesh_virtual_address_tag_for_pseudo_dst(pseudo_dest);
|
||||
data.hash = hash;
|
||||
memcpy(data.label_uuid, label_uuid, 16);
|
||||
btstack_tlv_singleton_impl->store_tag(btstack_tlv_singleton_context, tag, (uint8_t *) &data, sizeof(data));
|
||||
}
|
||||
|
||||
static void mesh_delete_virtual_address(uint16_t pseudo_dest){
|
||||
uint32_t tag = mesh_virtual_address_tag_for_pseudo_dst(pseudo_dest);
|
||||
btstack_tlv_singleton_impl->delete_tag(btstack_tlv_singleton_context, tag);
|
||||
}
|
||||
|
||||
void mesh_load_virtual_addresses(void){
|
||||
uint16_t pseudo_dst;
|
||||
for (pseudo_dst = 0x8000; pseudo_dst < (0x8000 + MAX_NR_MESH_VIRTUAL_ADDRESSES); pseudo_dst++){
|
||||
mesh_virtual_address_tag_for_pseudo_dst(pseudo_dst);
|
||||
mesh_persistent_virtual_address_t data;
|
||||
uint32_t tag = mesh_virtual_address_tag_for_pseudo_dst(pseudo_dst);
|
||||
int virtual_address_len = btstack_tlv_singleton_impl->get_tag(btstack_tlv_singleton_context, tag, (uint8_t *) &data, sizeof(data));
|
||||
if (virtual_address_len == 0) return;
|
||||
|
||||
mesh_virtual_address_t * virtual_address = btstack_memory_mesh_virtual_address_get();
|
||||
if (virtual_address == NULL) return;
|
||||
|
||||
virtual_address->pseudo_dst = pseudo_dst;
|
||||
virtual_address->hash = data.hash;
|
||||
memcpy(virtual_address->label_uuid, data.label_uuid, 16);
|
||||
mesh_virtual_address_add(virtual_address);
|
||||
}
|
||||
}
|
||||
|
||||
void mesh_delete_virtual_addresses(void){
|
||||
uint16_t pseudo_dest;
|
||||
for (pseudo_dest = 0x8000; pseudo_dest < (0x8000 + MAX_NR_MESH_VIRTUAL_ADDRESSES); pseudo_dest++){
|
||||
mesh_delete_virtual_address(pseudo_dest);
|
||||
}
|
||||
}
|
||||
|
||||
void mesh_virtual_address_decrease_refcount(mesh_virtual_address_t * virtual_address){
|
||||
if (virtual_address == NULL){
|
||||
log_error("virtual_address == NULL");
|
||||
}
|
||||
// decrease refcount
|
||||
virtual_address->ref_count--;
|
||||
// Free virtual address if ref count reaches zero
|
||||
if (virtual_address->ref_count > 0) return;
|
||||
// delete from TLV
|
||||
mesh_delete_virtual_address(virtual_address->pseudo_dst);
|
||||
// remove from list
|
||||
mesh_virtual_address_remove(virtual_address);
|
||||
// free memory
|
||||
btstack_memory_mesh_virtual_address_free(virtual_address);
|
||||
}
|
||||
|
||||
void mesh_virtual_address_increase_refcount(mesh_virtual_address_t * virtual_address){
|
||||
if (virtual_address == NULL){
|
||||
log_error("virtual_address == NULL");
|
||||
}
|
||||
virtual_address->ref_count++;
|
||||
if (virtual_address->ref_count > 1) return;
|
||||
// store in TLV
|
||||
mesh_store_virtual_address(virtual_address->pseudo_dst, virtual_address->hash, virtual_address->label_uuid);
|
||||
}
|
||||
|
||||
// Mesh Network Keys
|
||||
static uint32_t mesh_network_key_tag_for_internal_index(uint16_t internal_index){
|
||||
return ((uint32_t) 'M' << 24) | ((uint32_t) 'N' << 16) | ((uint32_t) internal_index);
|
||||
|
@ -42,6 +42,7 @@
|
||||
#include "mesh/provisioning.h"
|
||||
#include "mesh/mesh_keys.h"
|
||||
#include "mesh/mesh_access.h"
|
||||
#include "mesh/mesh_virtual_addresses.h"
|
||||
|
||||
#if defined __cplusplus
|
||||
extern "C" {
|
||||
@ -58,6 +59,12 @@ void mesh_init(void);
|
||||
*/
|
||||
void mesh_register_provisioning_device_packet_handler(btstack_packet_handler_t packet_handler);
|
||||
|
||||
// Mesh Virtual Address Management
|
||||
void mesh_load_virtual_addresses(void);
|
||||
void mesh_delete_virtual_addresses(void);
|
||||
void mesh_virtual_address_decrease_refcount(mesh_virtual_address_t * virtual_address);
|
||||
void mesh_virtual_address_increase_refcount(mesh_virtual_address_t * virtual_address);
|
||||
|
||||
// Foundation state
|
||||
void mesh_foundation_state_load(void);
|
||||
void mesh_foundation_state_store(void);
|
||||
|
@ -64,12 +64,6 @@
|
||||
|
||||
#define MESH_HEARTBEAT_FEATURES_SUPPORTED_MASK 0x000f
|
||||
|
||||
typedef struct {
|
||||
uint16_t hash;
|
||||
uint8_t label_uuid[16];
|
||||
} mesh_persistent_virtual_address_t;
|
||||
|
||||
|
||||
// current access pdu
|
||||
static mesh_pdu_t * access_pdu_in_process;
|
||||
|
||||
@ -113,84 +107,12 @@ static uint8_t heartbeat_count_log(uint16_t value){
|
||||
static const btstack_tlv_t * btstack_tlv_singleton_impl;
|
||||
static void * btstack_tlv_singleton_context;
|
||||
|
||||
static uint32_t mesh_virtual_address_tag_for_pseudo_dst(uint16_t pseudo_dst){
|
||||
return ((uint32_t) 'M' << 24) | ((uint32_t) 'V' << 16) | ((uint32_t) pseudo_dst);
|
||||
}
|
||||
|
||||
static void mesh_configuration_server_setup_tlv(void){
|
||||
if (btstack_tlv_singleton_impl) return;
|
||||
btstack_tlv_get_instance(&btstack_tlv_singleton_impl, &btstack_tlv_singleton_context);
|
||||
}
|
||||
|
||||
static void mesh_store_virtual_address(uint16_t pseudo_dest, uint16_t hash, const uint8_t * label_uuid){
|
||||
mesh_configuration_server_setup_tlv();
|
||||
|
||||
mesh_persistent_virtual_address_t data;
|
||||
uint32_t tag = mesh_virtual_address_tag_for_pseudo_dst(pseudo_dest);
|
||||
data.hash = hash;
|
||||
memcpy(data.label_uuid, label_uuid, 16);
|
||||
btstack_tlv_singleton_impl->store_tag(btstack_tlv_singleton_context, tag, (uint8_t *) &data, sizeof(data));
|
||||
}
|
||||
|
||||
static void mesh_delete_virtual_address(uint16_t pseudo_dest){
|
||||
mesh_configuration_server_setup_tlv();
|
||||
|
||||
uint32_t tag = mesh_virtual_address_tag_for_pseudo_dst(pseudo_dest);
|
||||
btstack_tlv_singleton_impl->delete_tag(btstack_tlv_singleton_context, tag);
|
||||
}
|
||||
|
||||
void mesh_load_virtual_addresses(void){
|
||||
mesh_configuration_server_setup_tlv();
|
||||
uint16_t pseudo_dst;
|
||||
for (pseudo_dst = 0x8000; pseudo_dst < (0x8000 + MAX_NR_MESH_VIRTUAL_ADDRESSES); pseudo_dst++){
|
||||
mesh_virtual_address_tag_for_pseudo_dst(pseudo_dst);
|
||||
mesh_persistent_virtual_address_t data;
|
||||
uint32_t tag = mesh_virtual_address_tag_for_pseudo_dst(pseudo_dst);
|
||||
int virtual_address_len = btstack_tlv_singleton_impl->get_tag(btstack_tlv_singleton_context, tag, (uint8_t *) &data, sizeof(data));
|
||||
if (virtual_address_len == 0) return;
|
||||
|
||||
mesh_virtual_address_t * virtual_address = btstack_memory_mesh_virtual_address_get();
|
||||
if (virtual_address == NULL) return;
|
||||
|
||||
virtual_address->pseudo_dst = pseudo_dst;
|
||||
virtual_address->hash = data.hash;
|
||||
memcpy(virtual_address->label_uuid, data.label_uuid, 16);
|
||||
mesh_virtual_address_add(virtual_address);
|
||||
}
|
||||
}
|
||||
|
||||
void mesh_delete_virtual_addresses(void){
|
||||
uint16_t pseudo_dest;
|
||||
for (pseudo_dest = 0x8000; pseudo_dest < (0x8000 + MAX_NR_MESH_VIRTUAL_ADDRESSES); pseudo_dest++){
|
||||
mesh_delete_virtual_address(pseudo_dest);
|
||||
}
|
||||
}
|
||||
|
||||
static void mesh_virtual_address_decrease_refcount(mesh_virtual_address_t * virtual_address){
|
||||
if (virtual_address == NULL){
|
||||
log_error("virtual_address == NULL");
|
||||
}
|
||||
// decrease refcount
|
||||
virtual_address->ref_count--;
|
||||
// Free virtual address if ref count reaches zero
|
||||
if (virtual_address->ref_count > 0) return;
|
||||
// delete from TLV
|
||||
mesh_delete_virtual_address(virtual_address->pseudo_dst);
|
||||
// remove from list
|
||||
mesh_virtual_address_remove(virtual_address);
|
||||
// free memory
|
||||
btstack_memory_mesh_virtual_address_free(virtual_address);
|
||||
}
|
||||
|
||||
static void mesh_virtual_address_increase_refcount(mesh_virtual_address_t * virtual_address){
|
||||
if (virtual_address == NULL){
|
||||
log_error("virtual_address == NULL");
|
||||
}
|
||||
virtual_address->ref_count++;
|
||||
if (virtual_address->ref_count > 1) return;
|
||||
// store in TLV
|
||||
mesh_store_virtual_address(virtual_address->pseudo_dst, virtual_address->hash, virtual_address->label_uuid);
|
||||
}
|
||||
|
||||
static int mesh_model_is_configuration_server(uint32_t model_identifier){
|
||||
return mesh_model_is_bluetooth_sig(model_identifier) && (mesh_model_get_model_id(model_identifier) == MESH_SIG_MODEL_ID_CONFIGURATION_SERVER);
|
||||
|
@ -84,10 +84,6 @@ const mesh_operation_t * mesh_configuration_server_get_operations(void);
|
||||
|
||||
void mesh_configuration_server_feature_changed(void);
|
||||
|
||||
void mesh_load_virtual_addresses(void);
|
||||
|
||||
void mesh_delete_virtual_addresses(void);
|
||||
|
||||
void mesh_load_subscriptions(void);
|
||||
|
||||
void mesh_delete_subscriptions(void);
|
||||
|
Loading…
x
Reference in New Issue
Block a user