mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-02-25 15:41:00 +00:00
mesh: add network key to provisioning data
This commit is contained in:
parent
6c38b88869
commit
2d97f8bb25
@ -276,10 +276,6 @@ static void mesh_provisioning_message_handler (uint8_t packet_type, uint16_t cha
|
||||
// get provisioning data
|
||||
provisioning_device_data_get(&provisioning_data);
|
||||
|
||||
// setup primary network with provisioned netkey
|
||||
primary_network_key = provisioning_device_data_get_network_key();
|
||||
mesh_network_key_add(primary_network_key);
|
||||
mesh_subnet_setup_for_netkey_index(primary_network_key->netkey_index);
|
||||
|
||||
// setup after provisioned
|
||||
mesh_access_setup_from_provisioning_data(&provisioning_data);
|
||||
@ -292,6 +288,7 @@ static void mesh_provisioning_message_handler (uint8_t packet_type, uint16_t cha
|
||||
mesh_store_iv_index_and_sequence_number();
|
||||
|
||||
// store primary network key
|
||||
primary_network_key = provisioning_device_data_get_network_key();
|
||||
mesh_store_network_key(primary_network_key);
|
||||
|
||||
|
||||
|
@ -1708,6 +1708,11 @@ void mesh_access_setup_from_provisioning_data(const mesh_provisioning_data_t * p
|
||||
// set device_key
|
||||
mesh_transport_set_device_key(provisioning_data->device_key);
|
||||
|
||||
// setup primary network with provisioned netkey
|
||||
mesh_network_key_add(provisioning_data->network_key);
|
||||
|
||||
// setup primary network
|
||||
mesh_subnet_setup_for_netkey_index(provisioning_data->network_key->netkey_index);
|
||||
|
||||
// Mesh Proxy
|
||||
#ifdef ENABLE_MESH_PROXY_SERVER
|
||||
|
@ -45,6 +45,7 @@
|
||||
#include <stdint.h>
|
||||
#include "btstack_defines.h"
|
||||
#include "btstack_crypto.h"
|
||||
#include "mesh_keys.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
@ -137,6 +138,9 @@ typedef struct {
|
||||
// IV Index
|
||||
uint32_t iv_index;
|
||||
|
||||
// Network Key (pass by reference)
|
||||
mesh_network_key_t * network_key;
|
||||
|
||||
} mesh_provisioning_data_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -119,7 +119,7 @@ static uint8_t enc_provisioning_data[25];
|
||||
static uint8_t provisioning_data[25];
|
||||
|
||||
// received network_key
|
||||
static mesh_network_key_t network_key;
|
||||
static mesh_network_key_t * network_key;
|
||||
|
||||
// DeviceKey
|
||||
static uint8_t device_key[16];
|
||||
@ -692,22 +692,25 @@ static void provisioning_handle_network_dervived(void * arg){
|
||||
|
||||
static void provisioning_handle_data_device_key(void * arg){
|
||||
// derive full network key
|
||||
mesh_network_key_derive(&prov_cmac_request, &network_key, &provisioning_handle_network_dervived, NULL);
|
||||
mesh_network_key_derive(&prov_cmac_request, network_key, &provisioning_handle_network_dervived, NULL);
|
||||
}
|
||||
|
||||
static void provisioning_handle_data_ccm(void * arg){
|
||||
|
||||
UNUSED(arg);
|
||||
|
||||
// validate MIC?
|
||||
// TODO: validate MIC?
|
||||
uint8_t mic[8];
|
||||
btstack_crypto_ccm_get_authentication_value(&prov_ccm_request, mic);
|
||||
printf("MIC: ");
|
||||
printf_hexdump(mic, 8);
|
||||
|
||||
// allocate network key
|
||||
network_key = btstack_memory_mesh_network_key_get();
|
||||
|
||||
// sort provisoning data
|
||||
memcpy(network_key.net_key, provisioning_data, 16);
|
||||
network_key.netkey_index = big_endian_read_16(provisioning_data, 16);
|
||||
memcpy(network_key->net_key, provisioning_data, 16);
|
||||
network_key->netkey_index = big_endian_read_16(provisioning_data, 16);
|
||||
flags = provisioning_data[18];
|
||||
iv_index = big_endian_read_32(provisioning_data, 19);
|
||||
unicast_address = big_endian_read_16(provisioning_data, 23);
|
||||
@ -898,7 +901,7 @@ uint32_t provisioning_device_data_get_iv_index(void){
|
||||
return iv_index;
|
||||
}
|
||||
mesh_network_key_t * provisioning_device_data_get_network_key(void){
|
||||
return &network_key;
|
||||
return network_key;
|
||||
}
|
||||
|
||||
void provisioning_device_data_get(mesh_provisioning_data_t * provisioning_data){
|
||||
@ -906,4 +909,5 @@ void provisioning_device_data_get(mesh_provisioning_data_t * provisioning_data){
|
||||
provisioning_data->iv_index = iv_index;
|
||||
provisioning_data->flags = flags;
|
||||
memcpy(provisioning_data->device_key, device_key, 16);
|
||||
provisioning_data->network_key = network_key;
|
||||
}
|
||||
|
@ -139,6 +139,11 @@ void pb_adv_send_pdu(uint16_t pb_transport_cid, const uint8_t * pdu, uint16_t si
|
||||
}
|
||||
void pb_gatt_send_pdu(uint16_t con_handle, const uint8_t * pdu, uint16_t pdu_size){}
|
||||
|
||||
static mesh_network_key_t network_key;
|
||||
mesh_network_key_t * btstack_memory_mesh_network_key_get(void){
|
||||
return &network_key;
|
||||
}
|
||||
|
||||
static void perform_crypto_operations(void){
|
||||
int more = 1;
|
||||
while (more){
|
||||
|
Loading…
x
Reference in New Issue
Block a user