mesh: move appkey laod/store to mesh from access

This commit is contained in:
Matthias Ringwald 2019-07-15 12:58:17 +02:00
parent 663808079b
commit 68d9ac2397
4 changed files with 71 additions and 78 deletions

View File

@ -92,6 +92,13 @@ typedef struct {
uint8_t privacy_key[16];
} mesh_persistent_net_key_t;
typedef struct {
uint16_t netkey_index;
uint16_t appkey_index;
uint8_t aid;
uint8_t version;
uint8_t key[16];
} mesh_persistent_app_key_t;
static btstack_packet_handler_t provisioning_device_packet_handler;
static btstack_packet_callback_registration_t hci_event_callback_registration;
@ -316,6 +323,64 @@ void mesh_delete_network_keys(void){
}
}
// Mesh App Keys
static uint32_t mesh_transport_key_tag_for_internal_index(uint16_t internal_index){
return ((uint32_t) 'M' << 24) | ((uint32_t) 'A' << 16) | ((uint32_t) internal_index);
}
void mesh_store_app_key(mesh_transport_key_t * app_key){
mesh_persistent_app_key_t data;
printf("Store AppKey: internal index 0x%x, AppKey Index 0x%06x, AID %02x: ", app_key->internal_index, app_key->appkey_index, app_key->aid);
printf_hexdump(app_key->key, 16);
uint32_t tag = mesh_transport_key_tag_for_internal_index(app_key->internal_index);
data.netkey_index = app_key->netkey_index;
data.appkey_index = app_key->appkey_index;
data.aid = app_key->aid;
data.version = app_key->version;
memcpy(data.key, app_key->key, 16);
btstack_tlv_singleton_impl->store_tag(btstack_tlv_singleton_context, tag, (uint8_t *) &data, sizeof(data));
}
void mesh_delete_app_key(uint16_t internal_index){
uint32_t tag = mesh_transport_key_tag_for_internal_index(internal_index);
btstack_tlv_singleton_impl->delete_tag(btstack_tlv_singleton_context, tag);
}
void mesh_load_app_keys(void){
printf("Load App Keys\n");
uint16_t internal_index;
for (internal_index = 0; internal_index < MAX_NR_MESH_TRANSPORT_KEYS; internal_index++){
mesh_persistent_app_key_t data;
uint32_t tag = mesh_transport_key_tag_for_internal_index(internal_index);
int app_key_len = btstack_tlv_singleton_impl->get_tag(btstack_tlv_singleton_context, tag, (uint8_t *) &data, sizeof(data));
if (app_key_len == 0) continue;
mesh_transport_key_t * key = btstack_memory_mesh_transport_key_get();
if (key == NULL) return;
key->internal_index = internal_index;
key->appkey_index = data.appkey_index;
key->netkey_index = data.netkey_index;
key->aid = data.aid;
key->akf = 1;
key->version = data.version;
memcpy(key->key, data.key, 16);
mesh_transport_key_add(key);
printf("- internal index 0x%x, AppKey Index 0x%06x, AID %02x: ", key->internal_index, key->appkey_index, key->aid);
printf_hexdump(key->key, 16);
}
}
void mesh_delete_app_keys(void){
printf("Delete App Keys\n");
uint16_t internal_index;
for (internal_index = 0; internal_index < MAX_NR_MESH_TRANSPORT_KEYS; internal_index++){
mesh_delete_app_key(internal_index);
}
}
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

@ -63,6 +63,12 @@ void mesh_delete_network_key(uint16_t internal_index);
void mesh_delete_network_keys(void);
void mesh_load_network_keys(void);
// Mesh Appkeys
void mesh_store_app_key(mesh_transport_key_t * app_key);
void mesh_delete_app_key(uint16_t internal_index);
void mesh_delete_app_keys(void);
void mesh_load_app_keys(void);
// 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

@ -1039,77 +1039,6 @@ 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 App Keys
typedef struct {
uint16_t netkey_index;
uint16_t appkey_index;
uint8_t aid;
uint8_t version;
uint8_t key[16];
} mesh_persistent_app_key_t;
static uint32_t mesh_transport_key_tag_for_internal_index(uint16_t internal_index){
return ((uint32_t) 'M' << 24) | ((uint32_t) 'A' << 16) | ((uint32_t) internal_index);
}
void mesh_store_app_key(mesh_transport_key_t * app_key){
mesh_access_setup_tlv();
mesh_persistent_app_key_t data;
printf("Store AppKey: internal index 0x%x, AppKey Index 0x%06x, AID %02x: ", app_key->internal_index, app_key->appkey_index, app_key->aid);
printf_hexdump(app_key->key, 16);
uint32_t tag = mesh_transport_key_tag_for_internal_index(app_key->internal_index);
data.netkey_index = app_key->netkey_index;
data.appkey_index = app_key->appkey_index;
data.aid = app_key->aid;
data.version = app_key->version;
memcpy(data.key, app_key->key, 16);
btstack_tlv_singleton_impl->store_tag(btstack_tlv_singleton_context, tag, (uint8_t *) &data, sizeof(data));
}
void mesh_delete_app_key(uint16_t internal_index){
mesh_access_setup_tlv();
uint32_t tag = mesh_transport_key_tag_for_internal_index(internal_index);
btstack_tlv_singleton_impl->delete_tag(btstack_tlv_singleton_context, tag);
}
void mesh_load_app_keys(void){
mesh_access_setup_tlv();
printf("Load App Keys\n");
uint16_t internal_index;
for (internal_index = 0; internal_index < MAX_NR_MESH_TRANSPORT_KEYS; internal_index++){
mesh_persistent_app_key_t data;
uint32_t tag = mesh_transport_key_tag_for_internal_index(internal_index);
int app_key_len = btstack_tlv_singleton_impl->get_tag(btstack_tlv_singleton_context, tag, (uint8_t *) &data, sizeof(data));
if (app_key_len == 0) continue;
mesh_transport_key_t * key = btstack_memory_mesh_transport_key_get();
if (key == NULL) return;
key->internal_index = internal_index;
key->appkey_index = data.appkey_index;
key->netkey_index = data.netkey_index;
key->aid = data.aid;
key->akf = 1;
key->version = data.version;
memcpy(key->key, data.key, 16);
mesh_transport_key_add(key);
printf("- internal index 0x%x, AppKey Index 0x%06x, AID %02x: ", key->internal_index, key->appkey_index, key->aid);
printf_hexdump(key->key, 16);
}
}
void mesh_delete_app_keys(void){
printf("Delete App Keys\n");
uint16_t internal_index;
for (internal_index = 0; internal_index < MAX_NR_MESH_TRANSPORT_KEYS; internal_index++){
mesh_delete_app_key(internal_index);
}
}
// Model to Appkey List

View File

@ -351,13 +351,6 @@ uint16_t mesh_pdu_len(mesh_pdu_t * pdu);
uint8_t * mesh_pdu_data(mesh_pdu_t * pdu);
void mesh_access_netkey_finalize(mesh_network_key_t * network_key);
// Mesh Appkeys
void mesh_store_app_key(mesh_transport_key_t * app_key);
void mesh_delete_app_key(uint16_t internal_index);
void mesh_delete_app_keys(void);
void mesh_load_app_keys(void);
void mesh_access_appkey_finalize(mesh_transport_key_t * transport_key);
// Mesh Model Subscriptions