rename sm_central_device* into sm_address_resolution*

This commit is contained in:
Matthias Ringwald 2015-07-31 16:19:02 +02:00
parent 07a9209480
commit 69d313c5b0

View File

@ -142,12 +142,13 @@ static uint8_t sm_cmac_block_current;
static uint8_t sm_cmac_block_count;
static void (*sm_cmac_done_handler)(uint8_t hash[8]);
// resolvable private address lookup
static int sm_central_device_test;
static int sm_central_device_matched;
static int sm_central_ah_calculation_active;
static uint8_t sm_central_device_addr_type;
static bd_addr_t sm_central_device_address;
// resolvable private address lookup / CSRK calculation
static int sm_address_resolution_device_test;
static int sm_address_resolution_device_matched;
static int sm_address_resolution_ah_calculation_active;
static uint8_t sm_address_resolution_device_addr_type;
static bd_addr_t sm_address_resolution_device_address;
static void * sm_address_resolution_device_context;
// aes128 crypto engine. store current sm_connection_t in sm_aes128_context
static sm_aes128_state_t sm_aes128_state;
@ -156,9 +157,6 @@ static void * sm_aes128_context;
// random engine. store context (ususally sm_connection_t)
static void * sm_random_context;
// CSRK calculation
static void * sm_csrk_context;
//
// Volume 3, Part H, Chapter 24
// "Security shall be initiated by the Security Manager in the device in the master role.
@ -540,16 +538,16 @@ static void sm_setup_key_distribution(uint8_t key_set){
// CSRK Key Lookup
/* static */ int sm_central_device_lookup_active(void){
return sm_central_device_test >= 0;
/* static */ int sm_address_resolution_device_lookup_active(void){
return sm_address_resolution_device_test >= 0;
}
static void sm_central_device_start_lookup(sm_connection_t * sm_conn, uint8_t addr_type, bd_addr_t addr){
memcpy(sm_central_device_address, addr, 6);
sm_central_device_addr_type = addr_type;
sm_central_device_test = 0;
sm_central_device_matched = -1;
sm_csrk_context = sm_conn;
static void sm_address_resolution_device_start_lookup(sm_connection_t * sm_conn, uint8_t addr_type, bd_addr_t addr){
memcpy(sm_address_resolution_device_address, addr, 6);
sm_address_resolution_device_addr_type = addr_type;
sm_address_resolution_device_test = 0;
sm_address_resolution_device_matched = -1;
sm_address_resolution_device_context = sm_conn;
sm_notify_client(SM_IDENTITY_RESOLVING_STARTED, addr_type, addr, 0, 0);
}
@ -928,14 +926,14 @@ static void sm_run(void){
// CSRK Lookup
// -- if csrk lookup ready, find connection that require csrk lookup
if (!sm_central_device_lookup_active()){
if (!sm_address_resolution_device_lookup_active()){
hci_connections_get_iterator(&it);
while(linked_list_iterator_has_next(&it)){
hci_connection_t * hci_connection = (hci_connection_t *) linked_list_iterator_next(&it);
sm_connection_t * sm_connection = &hci_connection->sm_connection;
if (sm_connection->sm_csrk_lookup_state == CSRK_LOOKUP_W4_READY){
// and start lookup
sm_central_device_start_lookup(sm_connection, sm_connection->sm_peer_addr_type, sm_connection->sm_peer_address);
sm_address_resolution_device_start_lookup(sm_connection, sm_connection->sm_peer_addr_type, sm_connection->sm_peer_address);
sm_connection->sm_csrk_lookup_state = CSRK_LOOKUP_STARTED;
break;
}
@ -943,21 +941,21 @@ static void sm_run(void){
}
// -- Continue with CSRK device lookup by public or resolvable private address
if (sm_central_device_test >= 0){
log_info("LE Device Lookup: device %u/%u", sm_central_device_test, le_device_db_count());
sm_connection_t * sm_csrk_connection = (sm_connection_t *) sm_csrk_context;
while (sm_central_device_test < le_device_db_count()){
if (sm_address_resolution_device_test >= 0){
log_info("LE Device Lookup: device %u/%u", sm_address_resolution_device_test, le_device_db_count());
sm_connection_t * sm_csrk_connection = (sm_connection_t *) sm_address_resolution_device_context;
while (sm_address_resolution_device_test < le_device_db_count()){
int addr_type;
bd_addr_t addr;
sm_key_t irk;
le_device_db_info(sm_central_device_test, &addr_type, addr, irk);
le_device_db_info(sm_address_resolution_device_test, &addr_type, addr, irk);
log_info("device type %u, addr: %s", addr_type, bd_addr_to_str(addr));
if (sm_central_device_addr_type == addr_type && memcmp(addr, sm_central_device_address, 6) == 0){
if (sm_address_resolution_device_addr_type == addr_type && memcmp(addr, sm_address_resolution_device_address, 6) == 0){
log_info("LE Device Lookup: found CSRK by { addr_type, address} ");
sm_central_device_matched = sm_central_device_test;
sm_central_device_test = -1;
sm_notify_client(SM_IDENTITY_RESOLVING_SUCCEEDED, sm_central_device_addr_type, sm_central_device_address, 0, sm_central_device_matched);
sm_address_resolution_device_matched = sm_address_resolution_device_test;
sm_address_resolution_device_test = -1;
sm_notify_client(SM_IDENTITY_RESOLVING_SUCCEEDED, sm_address_resolution_device_addr_type, sm_address_resolution_device_address, 0, sm_address_resolution_device_matched);
// re-use stored LTK/EDIV/RAND if requested & we're master
// TODO: replace global with flag in sm_connection_t
@ -972,8 +970,8 @@ static void sm_run(void){
break;
}
if (sm_central_device_addr_type == 0){
sm_central_device_test++;
if (sm_address_resolution_device_addr_type == 0){
sm_address_resolution_device_test++;
continue;
}
@ -983,18 +981,18 @@ static void sm_run(void){
log_key("IRK", irk);
sm_key_t r_prime;
sm_ah_r_prime(sm_central_device_address, r_prime);
sm_central_ah_calculation_active = 1;
sm_ah_r_prime(sm_address_resolution_device_address, r_prime);
sm_address_resolution_ah_calculation_active = 1;
sm_aes128_start(irk, r_prime, sm_csrk_connection);
return;
}
if (sm_central_device_test >= le_device_db_count()){
if (sm_address_resolution_device_test >= le_device_db_count()){
log_info("LE Device Lookup: not found");
sm_central_device_test = -1;
sm_address_resolution_device_test = -1;
sm_csrk_connection->sm_csrk_lookup_state = CSRK_LOOKUP_IDLE;
sm_csrk_connection = NULL;
sm_notify_client(SM_IDENTITY_RESOLVING_FAILED, sm_central_device_addr_type, sm_central_device_address, 0, 0);
sm_notify_client(SM_IDENTITY_RESOLVING_FAILED, sm_address_resolution_device_addr_type, sm_address_resolution_device_address, 0, 0);
}
}
@ -1349,24 +1347,24 @@ static void sm_handle_encryption_result(uint8_t * data){
sm_aes128_state = SM_AES128_IDLE;
if (sm_central_ah_calculation_active){
sm_central_ah_calculation_active = 0;
if (sm_address_resolution_ah_calculation_active){
sm_address_resolution_ah_calculation_active = 0;
// compare calulated address against connecting device
uint8_t hash[3];
swap24(data, hash);
if (memcmp(&sm_central_device_address[3], hash, 3) == 0){
if (memcmp(&sm_address_resolution_device_address[3], hash, 3) == 0){
// found
sm_central_device_matched = sm_central_device_test;
sm_central_device_test = -1;
sm_connection_t * sm_csrk_connection = (sm_connection_t *) sm_csrk_context;
sm_csrk_context = NULL;
sm_address_resolution_device_matched = sm_address_resolution_device_test;
sm_address_resolution_device_test = -1;
sm_connection_t * sm_csrk_connection = (sm_connection_t *) sm_address_resolution_device_context;
sm_address_resolution_device_context = NULL;
sm_csrk_connection->sm_csrk_lookup_state = CSRK_LOOKUP_IDLE;
sm_notify_client(SM_IDENTITY_RESOLVING_SUCCEEDED, sm_central_device_addr_type, sm_central_device_address, 0, sm_central_device_matched);
sm_notify_client(SM_IDENTITY_RESOLVING_SUCCEEDED, sm_address_resolution_device_addr_type, sm_address_resolution_device_address, 0, sm_address_resolution_device_matched);
log_info("LE Device Lookup: matched resolvable private address");
return;
}
// no match
sm_central_device_test++;
sm_address_resolution_device_test++;
return;
}
switch (dkg_state){
@ -2066,8 +2064,8 @@ void sm_init(void){
dkg_state = DKG_W4_WORKING;
rau_state = RAU_W4_WORKING;
sm_aes128_state = SM_AES128_IDLE;
sm_central_device_test = -1; // no private address to resolve yet
sm_central_ah_calculation_active = 0;
sm_address_resolution_device_test = -1; // no private address to resolve yet
sm_address_resolution_ah_calculation_active = 0;
gap_random_adress_update_period = 15 * 60 * 1000L;