mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-02-28 16:11:24 +00:00
mesh: persist model to appkey binding
This commit is contained in:
parent
23278b5ce9
commit
f53a82f230
191
test/mesh/mesh.c
191
test/mesh/mesh.c
@ -94,6 +94,8 @@ static void mesh_access_set_primary_element_address(uint16_t unicast_address);
|
||||
|
||||
static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size);
|
||||
|
||||
static void mesh_delete_appkey_lists(void);
|
||||
|
||||
static uint8_t mesh_flags;
|
||||
|
||||
static uint16_t pb_transport_cid = MESH_PB_TRANSPORT_INVALID_CID;
|
||||
@ -537,6 +539,9 @@ static void mesh_provisioning_message_handler (uint8_t packet_type, uint16_t cha
|
||||
// delete old app keys
|
||||
mesh_delete_app_keys();
|
||||
|
||||
// delete old model to appkey bindings
|
||||
mesh_delete_appkey_lists();
|
||||
|
||||
// store in TLV
|
||||
btstack_tlv_singleton_impl->store_tag(btstack_tlv_singleton_context, 'PROV', (uint8_t *) &provisioning_data, sizeof(mesh_provisioning_data_t));
|
||||
|
||||
@ -1415,7 +1420,6 @@ typedef enum {
|
||||
MESH_NODE_IDENTITY_STATE_ADVERTISING_NOT_SUPPORTED
|
||||
} mesh_node_identity_state_t;
|
||||
|
||||
|
||||
static btstack_crypto_aes128_cmac_t configuration_server_cmac_request;
|
||||
|
||||
static mesh_pdu_t * access_pdu_in_process;
|
||||
@ -1492,78 +1496,10 @@ typedef struct {
|
||||
static uint16_t mid_counter;
|
||||
static btstack_linked_list_t elements;
|
||||
|
||||
static mesh_heartbeat_publication_t mesh_heartbeat_publication;
|
||||
|
||||
static void mesh_model_reset_appkeys(mesh_model_t * mesh_model){
|
||||
int i;
|
||||
for (i=0;i<MAX_NR_MESH_APPKEYS_PER_MODEL;i++){
|
||||
mesh_model->appkey_indices[i] = MESH_APPKEY_INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
static uint8_t mesh_model_bind_appkey(mesh_model_t * mesh_model, uint16_t appkey_index){
|
||||
int i;
|
||||
for (i=0;i<MAX_NR_MESH_APPKEYS_PER_MODEL;i++){
|
||||
if (mesh_model->appkey_indices[i] == appkey_index) return MESH_FOUNDATION_STATUS_SUCCESS;
|
||||
}
|
||||
for (i=0;i<MAX_NR_MESH_APPKEYS_PER_MODEL;i++){
|
||||
if (mesh_model->appkey_indices[i] == MESH_APPKEY_INVALID) {
|
||||
mesh_model->appkey_indices[i] = appkey_index;
|
||||
return MESH_FOUNDATION_STATUS_SUCCESS;
|
||||
}
|
||||
}
|
||||
return MESH_FOUNDATION_STATUS_INSUFFICIENT_RESOURCES;
|
||||
}
|
||||
|
||||
static void mesh_model_unbind_appkey(mesh_model_t * mesh_model, uint16_t appkey_index){
|
||||
int i;
|
||||
for (i=0;i<MAX_NR_MESH_APPKEYS_PER_MODEL;i++){
|
||||
if (mesh_model->appkey_indices[i] == appkey_index) {
|
||||
mesh_model->appkey_indices[i] = MESH_APPKEY_INVALID;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void mesh_model_reset_subscriptions(mesh_model_t * mesh_model){
|
||||
int i;
|
||||
for (i=0;i<MAX_NR_MESH_SUBSCRIPTION_PER_MODEL;i++){
|
||||
mesh_model->subscriptions[i] = MESH_ADDRESS_UNSASSIGNED;
|
||||
}
|
||||
}
|
||||
|
||||
static uint8_t mesh_model_add_subscription(mesh_model_t * mesh_model, uint16_t address){
|
||||
int i;
|
||||
for (i=0;i<MAX_NR_MESH_SUBSCRIPTION_PER_MODEL;i++){
|
||||
if (mesh_model->subscriptions[i] == address) return MESH_FOUNDATION_STATUS_SUCCESS;
|
||||
}
|
||||
for (i=0;i<MAX_NR_MESH_SUBSCRIPTION_PER_MODEL;i++){
|
||||
if (mesh_model->subscriptions[i] == MESH_ADDRESS_UNSASSIGNED) {
|
||||
mesh_model->subscriptions[i] = address;
|
||||
return MESH_FOUNDATION_STATUS_SUCCESS;
|
||||
}
|
||||
}
|
||||
return MESH_FOUNDATION_STATUS_INSUFFICIENT_RESOURCES;
|
||||
}
|
||||
|
||||
static void mesh_model_delete_subscription(mesh_model_t * mesh_model, uint16_t address){
|
||||
int i;
|
||||
for (i=0;i<MAX_NR_MESH_SUBSCRIPTION_PER_MODEL;i++){
|
||||
if (mesh_model->subscriptions[i] == address) {
|
||||
mesh_model->subscriptions[i] = MESH_ADDRESS_UNSASSIGNED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
static mesh_element_t primary_element;
|
||||
static btstack_linked_list_t mesh_elements;
|
||||
|
||||
static mesh_element_t * mesh_primary_element(void){
|
||||
return &primary_element;
|
||||
}
|
||||
static mesh_heartbeat_publication_t mesh_heartbeat_publication;
|
||||
|
||||
static void mesh_access_set_primary_element_address(uint16_t unicast_address){
|
||||
primary_element.unicast_address = unicast_address;
|
||||
@ -1617,6 +1553,121 @@ static mesh_model_t * mesh_model_get_by_identifier(mesh_element_t * element, uin
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
// model to appkey list/binding
|
||||
|
||||
static uint32_t mesh_model_tag_for_index(uint16_t internal_model_id){
|
||||
return ((uint32_t) 'M' << 24) | ((uint32_t) 'B' << 16) | ((uint32_t) internal_model_id);
|
||||
}
|
||||
|
||||
static void mesh_load_appkey_list(mesh_model_t * model){
|
||||
uint32_t tag = mesh_model_tag_for_index(model->mid);
|
||||
btstack_tlv_singleton_impl->store_tag(btstack_tlv_singleton_context, tag, (uint8_t *) &model->appkey_indices, sizeof(model->appkey_indices));
|
||||
}
|
||||
|
||||
static void mesh_store_appkey_list(mesh_model_t * model){
|
||||
uint32_t tag = mesh_model_tag_for_index(model->mid);
|
||||
btstack_tlv_singleton_impl->get_tag(btstack_tlv_singleton_context, tag, (uint8_t *) &model->appkey_indices, sizeof(model->appkey_indices));
|
||||
}
|
||||
|
||||
#define MESH_MODEL_INDEX_MAX (16)
|
||||
|
||||
static void mesh_load_appkey_lists(void){
|
||||
printf("Load Appkey Lists\n");
|
||||
// iterate over elements and models
|
||||
btstack_linked_list_iterator_t element_it;
|
||||
btstack_linked_list_iterator_init(&element_it, &mesh_elements);
|
||||
while (btstack_linked_list_iterator_has_next(&element_it)){
|
||||
mesh_element_t * element = (mesh_element_t *) btstack_linked_list_iterator_next(&element_it);
|
||||
mesh_model_iterator_t model_it;
|
||||
mesh_model_iterator_init(&model_it, element);
|
||||
while (mesh_model_iterator_has_next(&model_it)){
|
||||
mesh_model_t * model = mesh_model_iterator_get_next(&model_it);
|
||||
mesh_load_appkey_list(model);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void mesh_delete_appkey_lists(void){
|
||||
printf("Delete App Keys\n");
|
||||
// iterate over elements and models
|
||||
uint16_t internal_model_id;
|
||||
for (internal_model_id = 0; internal_model_id < MESH_MODEL_INDEX_MAX; internal_model_id++){
|
||||
uint32_t tag = mesh_model_tag_for_index(internal_model_id);
|
||||
btstack_tlv_singleton_impl->delete_tag(btstack_tlv_singleton_context, tag);
|
||||
}
|
||||
}
|
||||
|
||||
static void mesh_model_reset_appkeys(mesh_model_t * mesh_model){
|
||||
int i;
|
||||
for (i=0;i<MAX_NR_MESH_APPKEYS_PER_MODEL;i++){
|
||||
mesh_model->appkey_indices[i] = MESH_APPKEY_INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
static uint8_t mesh_model_bind_appkey(mesh_model_t * mesh_model, uint16_t appkey_index){
|
||||
int i;
|
||||
for (i=0;i<MAX_NR_MESH_APPKEYS_PER_MODEL;i++){
|
||||
if (mesh_model->appkey_indices[i] == appkey_index) return MESH_FOUNDATION_STATUS_SUCCESS;
|
||||
}
|
||||
for (i=0;i<MAX_NR_MESH_APPKEYS_PER_MODEL;i++){
|
||||
if (mesh_model->appkey_indices[i] == MESH_APPKEY_INVALID) {
|
||||
mesh_model->appkey_indices[i] = appkey_index;
|
||||
mesh_store_appkey_list(mesh_model);
|
||||
return MESH_FOUNDATION_STATUS_SUCCESS;
|
||||
}
|
||||
}
|
||||
return MESH_FOUNDATION_STATUS_INSUFFICIENT_RESOURCES;
|
||||
}
|
||||
|
||||
static void mesh_model_unbind_appkey(mesh_model_t * mesh_model, uint16_t appkey_index){
|
||||
int i;
|
||||
for (i=0;i<MAX_NR_MESH_APPKEYS_PER_MODEL;i++){
|
||||
if (mesh_model->appkey_indices[i] == appkey_index) {
|
||||
mesh_model->appkey_indices[i] = MESH_APPKEY_INVALID;
|
||||
mesh_store_appkey_list(mesh_model);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void mesh_model_reset_subscriptions(mesh_model_t * mesh_model){
|
||||
int i;
|
||||
for (i=0;i<MAX_NR_MESH_SUBSCRIPTION_PER_MODEL;i++){
|
||||
mesh_model->subscriptions[i] = MESH_ADDRESS_UNSASSIGNED;
|
||||
}
|
||||
}
|
||||
|
||||
static uint8_t mesh_model_add_subscription(mesh_model_t * mesh_model, uint16_t address){
|
||||
int i;
|
||||
for (i=0;i<MAX_NR_MESH_SUBSCRIPTION_PER_MODEL;i++){
|
||||
if (mesh_model->subscriptions[i] == address) return MESH_FOUNDATION_STATUS_SUCCESS;
|
||||
}
|
||||
for (i=0;i<MAX_NR_MESH_SUBSCRIPTION_PER_MODEL;i++){
|
||||
if (mesh_model->subscriptions[i] == MESH_ADDRESS_UNSASSIGNED) {
|
||||
mesh_model->subscriptions[i] = address;
|
||||
return MESH_FOUNDATION_STATUS_SUCCESS;
|
||||
}
|
||||
}
|
||||
return MESH_FOUNDATION_STATUS_INSUFFICIENT_RESOURCES;
|
||||
}
|
||||
|
||||
static void mesh_model_delete_subscription(mesh_model_t * mesh_model, uint16_t address){
|
||||
int i;
|
||||
for (i=0;i<MAX_NR_MESH_SUBSCRIPTION_PER_MODEL;i++){
|
||||
if (mesh_model->subscriptions[i] == address) {
|
||||
mesh_model->subscriptions[i] = MESH_ADDRESS_UNSASSIGNED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
static mesh_element_t * mesh_primary_element(void){
|
||||
return &primary_element;
|
||||
}
|
||||
|
||||
static void mesh_access_message_processed(mesh_pdu_t * pdu){
|
||||
mesh_upper_transport_message_processed_by_higher_layer(pdu);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user