mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-03-29 22:20:37 +00:00
mesh: introduce application key list
This commit is contained in:
parent
44c5d856a0
commit
aacf960d48
@ -263,8 +263,55 @@ static btstack_crypto_aes128_cmac_t mesh_cmac_request;
|
||||
static uint8_t mesh_secure_network_beacon[22];
|
||||
static uint8_t mesh_secure_network_beacon_auth_value[16];
|
||||
|
||||
// application key list
|
||||
|
||||
typedef struct {
|
||||
uint8_t aid;
|
||||
uint8_t first;
|
||||
} mesh_application_key_iterator_t;
|
||||
|
||||
typedef struct {
|
||||
btstack_linked_item_t item;
|
||||
|
||||
// index into shared global key list
|
||||
uint16_t appkey_index;
|
||||
|
||||
// random net_key
|
||||
uint8_t application_key[16];
|
||||
|
||||
uint8_t aid;
|
||||
} mesh_application_key_t;
|
||||
|
||||
static uint8_t test_application_key[16];
|
||||
static uint16_t test_application_key_index;
|
||||
|
||||
static const uint8_t * mesh_application_key_list_get(uint16_t appkey_index){
|
||||
if (appkey_index != test_application_key_index) return NULL;
|
||||
return test_application_key;
|
||||
}
|
||||
|
||||
void mesh_application_key_set(uint16_t appkey_index, const uint8_t * application_key){
|
||||
test_application_key_index = appkey_index;
|
||||
memcpy(test_application_key, application_key, 16);
|
||||
}
|
||||
|
||||
// mesh network key iterator
|
||||
static void mesh_application_key_iterator_init(mesh_application_key_iterator_t * it, uint8_t aid){
|
||||
it->aid = aid;
|
||||
it->first = 1;
|
||||
}
|
||||
|
||||
static int mesh_application_key_iterator_has_more(mesh_application_key_iterator_t * it){
|
||||
return it->first && it->aid == test_application_key_index;
|
||||
}
|
||||
|
||||
static const uint8_t * mesh_application_key_iterator_get_next(mesh_application_key_iterator_t * it){
|
||||
it->first = 0;
|
||||
return test_application_key;
|
||||
}
|
||||
|
||||
|
||||
// stub lower transport
|
||||
static uint8_t application_key[16];
|
||||
static uint8_t application_nonce[13];
|
||||
static btstack_crypto_ccm_t ccm;
|
||||
|
||||
@ -327,7 +374,7 @@ static void transport_received_message(mesh_network_pdu_t * network_pdu){
|
||||
// Control Message
|
||||
|
||||
} else {
|
||||
// uint8_t aid = (lower_transport_pdu[0]&0x3f);
|
||||
uint8_t aid = (lower_transport_pdu[0]&0x3f);
|
||||
int seg = lower_transport_pdu[0] >> 7;
|
||||
printf("SEG: %u\n", seg);
|
||||
|
||||
@ -346,6 +393,9 @@ static void transport_received_message(mesh_network_pdu_t * network_pdu){
|
||||
// TODO: copy message before overwriting it
|
||||
|
||||
// TODO: lookup device or applicaton key
|
||||
|
||||
const uint8_t * application_key = mesh_application_key_list_get(aid);
|
||||
|
||||
transport_setup_application_nonce(application_nonce, network_pdu);
|
||||
btstack_crypo_ccm_init(&ccm, application_key, application_nonce, upper_transport_pdu_len, 4);
|
||||
btstack_crypto_ccm_decrypt_block(&ccm, upper_transport_pdu_len, upper_transport_pdu, upper_transport_pdu, &transport_received_message_b, network_pdu);
|
||||
@ -371,7 +421,10 @@ static void load_provisioning_data_test_message(void){
|
||||
btstack_parse_hex("0953fa93e7caac9638f58820220a398e", 16, provisioning_data.encryption_key);
|
||||
btstack_parse_hex("8b84eedec100067d670971dd2aa700cf", 16, provisioning_data.privacy_key);
|
||||
mesh_network_key_list_add_from_provisioning_data(&provisioning_data);
|
||||
|
||||
uint8_t application_key[16];
|
||||
btstack_parse_hex("63964771734fbd76e3b40519d1d94a48", 16, application_key);
|
||||
mesh_application_key_set( 0x26, application_key);
|
||||
}
|
||||
|
||||
static void receive_test_message(void){
|
||||
@ -623,8 +676,11 @@ int btstack_main(void)
|
||||
mesh_network_set_higher_layer_handler(&transport_received_message);
|
||||
|
||||
// PTS app key
|
||||
uint8_t application_key[16];
|
||||
const char * application_key_string = "3216D1509884B533248541792B877F98";
|
||||
btstack_parse_hex(application_key_string, 16, application_key);
|
||||
mesh_application_key_set(0x26, application_key); // TODO: figure out correct AID
|
||||
|
||||
printf("Application Key: ");
|
||||
printf_hexdump(application_key, 16);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user