mesh: move model to appkey laod/store to mesh from access

This commit is contained in:
Matthias Ringwald 2019-07-15 13:06:19 +02:00
parent 68d9ac2397
commit 726dac53ea
4 changed files with 103 additions and 106 deletions

View File

@ -381,6 +381,100 @@ void mesh_delete_app_keys(void){
}
}
// Model to Appkey List
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->get_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->store_tag(btstack_tlv_singleton_context, tag, (uint8_t *) &model->appkey_indices, sizeof(model->appkey_indices));
}
static void mesh_delete_appkey_list(mesh_model_t * model){
uint32_t tag = mesh_model_tag_for_index(model->mid);
btstack_tlv_singleton_impl->delete_tag(btstack_tlv_singleton_context, tag);
}
void mesh_load_appkey_lists(void){
printf("Load Appkey Lists\n");
// iterate over elements and models
mesh_element_iterator_t element_it;
mesh_element_iterator_init(&element_it);
while (mesh_element_iterator_has_next(&element_it)){
mesh_element_t * element = mesh_element_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_next(&model_it);
mesh_load_appkey_list(model);
}
}
}
void mesh_delete_appkey_lists(void){
printf("Delete Appkey Lists\n");
// iterate over elements and models
mesh_element_iterator_t element_it;
mesh_element_iterator_init(&element_it);
while (mesh_element_iterator_has_next(&element_it)){
mesh_element_t * element = mesh_element_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_next(&model_it);
mesh_delete_appkey_list(model);
}
}
}
void mesh_model_reset_appkeys(mesh_model_t * mesh_model){
uint16_t i;
for (i=0;i<MAX_NR_MESH_APPKEYS_PER_MODEL;i++){
mesh_model->appkey_indices[i] = MESH_APPKEY_INVALID;
}
}
uint8_t mesh_model_bind_appkey(mesh_model_t * mesh_model, uint16_t appkey_index){
uint16_t 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;
}
void mesh_model_unbind_appkey(mesh_model_t * mesh_model, uint16_t appkey_index){
uint16_t 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);
}
}
}
int mesh_model_contains_appkey(mesh_model_t * mesh_model, uint16_t appkey_index){
uint16_t i;
for (i=0;i<MAX_NR_MESH_APPKEYS_PER_MODEL;i++){
if (mesh_model->appkey_indices[i] == appkey_index) return 1;
}
return 0;
}
static void mesh_node_setup_default_models(void){
// configure Config Server
mesh_configuration_server_model.model_identifier = mesh_model_get_model_identifier_bluetooth_sig(MESH_SIG_MODEL_ID_CONFIGURATION_SERVER);

View File

@ -41,6 +41,7 @@
#include "btstack_defines.h"
#include "mesh/provisioning.h"
#include "mesh/mesh_keys.h"
#include "mesh/mesh_access.h"
#if defined __cplusplus
extern "C" {
@ -69,6 +70,14 @@ void mesh_delete_app_key(uint16_t internal_index);
void mesh_delete_app_keys(void);
void mesh_load_app_keys(void);
// Mesh Model to Appkey List
void mesh_load_appkey_lists(void);
void mesh_delete_appkey_lists(void);
void mesh_model_reset_appkeys(mesh_model_t * mesh_model);
uint8_t mesh_model_bind_appkey(mesh_model_t * mesh_model, uint16_t appkey_index);
void mesh_model_unbind_appkey(mesh_model_t * mesh_model, uint16_t appkey_index);
int mesh_model_contains_appkey(mesh_model_t * mesh_model, uint16_t appkey_index);
// temp
void mesh_access_setup_from_provisioning_data(const mesh_provisioning_data_t * provisioning_data);
void mesh_access_setup_without_provisiong_data(void);

View File

@ -1040,104 +1040,6 @@ void mesh_foundation_state_store(void){
}
// Model to Appkey List
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){
mesh_access_setup_tlv();
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));
}
static void mesh_store_appkey_list(mesh_model_t * model){
mesh_access_setup_tlv();
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_delete_appkey_list(mesh_model_t * model){
mesh_access_setup_tlv();
uint32_t tag = mesh_model_tag_for_index(model->mid);
btstack_tlv_singleton_impl->delete_tag(btstack_tlv_singleton_context, tag);
}
void mesh_load_appkey_lists(void){
printf("Load Appkey Lists\n");
// iterate over elements and models
mesh_element_iterator_t element_it;
mesh_element_iterator_init(&element_it);
while (mesh_element_iterator_has_next(&element_it)){
mesh_element_t * element = mesh_element_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_next(&model_it);
mesh_load_appkey_list(model);
}
}
}
void mesh_delete_appkey_lists(void){
printf("Delete Appkey Lists\n");
mesh_access_setup_tlv();
// iterate over elements and models
mesh_element_iterator_t element_it;
mesh_element_iterator_init(&element_it);
while (mesh_element_iterator_has_next(&element_it)){
mesh_element_t * element = mesh_element_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_next(&model_it);
mesh_delete_appkey_list(model);
}
}
}
void mesh_model_reset_appkeys(mesh_model_t * mesh_model){
uint16_t i;
for (i=0;i<MAX_NR_MESH_APPKEYS_PER_MODEL;i++){
mesh_model->appkey_indices[i] = MESH_APPKEY_INVALID;
}
}
uint8_t mesh_model_bind_appkey(mesh_model_t * mesh_model, uint16_t appkey_index){
uint16_t 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;
}
void mesh_model_unbind_appkey(mesh_model_t * mesh_model, uint16_t appkey_index){
uint16_t 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);
}
}
}
int mesh_model_contains_appkey(mesh_model_t * mesh_model, uint16_t appkey_index){
uint16_t i;
for (i=0;i<MAX_NR_MESH_APPKEYS_PER_MODEL;i++){
if (mesh_model->appkey_indices[i] == appkey_index) return 1;
}
return 0;
}
// Mesh IV Index
static uint32_t mesh_tag_for_iv_index_and_seq_number(void){
return ((uint32_t) 'M' << 24) | ((uint32_t) 'F' << 16) | ((uint32_t) 'I' << 9) | ((uint32_t) 'S');

View File

@ -356,14 +356,6 @@ void mesh_access_appkey_finalize(mesh_transport_key_t * transport_key);
// Mesh Model Subscriptions
int mesh_model_contains_subscription(mesh_model_t * mesh_model, uint16_t address);
// Mesh Model to Appkey List
void mesh_load_appkey_lists(void);
void mesh_delete_appkey_lists(void);
void mesh_model_reset_appkeys(mesh_model_t * mesh_model);
uint8_t mesh_model_bind_appkey(mesh_model_t * mesh_model, uint16_t appkey_index);
void mesh_model_unbind_appkey(mesh_model_t * mesh_model, uint16_t appkey_index);
int mesh_model_contains_appkey(mesh_model_t * mesh_model, uint16_t appkey_index);
// Mesh IV Index and sequence number
void mesh_store_iv_index_after_provisioning(uint32_t iv_index);
void mesh_store_iv_index_and_sequence_number(void);