finish key distribution for initiator role

This commit is contained in:
matthias.ringwald 2014-06-13 15:50:55 +00:00
parent 641f306499
commit e14eb8abef

View File

@ -118,6 +118,7 @@ typedef enum {
// //
SM_STATE_DISTRIBUTE_KEYS, SM_STATE_DISTRIBUTE_KEYS,
SM_STATE_RECEIVE_KEYS,
// re establish previously distribued LTK // re establish previously distribued LTK
SM_STATE_PH4_Y_GET_ENC, SM_STATE_PH4_Y_GET_ENC,
@ -139,7 +140,7 @@ typedef enum {
SM_STATE_INITIATOR_PH2_W4_PAIRING_RANDOM, SM_STATE_INITIATOR_PH2_W4_PAIRING_RANDOM,
SM_STATE_INITIATOR_PH3_SEND_START_ENCRYPTION, SM_STATE_INITIATOR_PH3_SEND_START_ENCRYPTION,
SM_STATE_INITIATOR_XXX, SM_STATE_INITIATOR_PH3_XXXX,
} security_manager_state_t; } security_manager_state_t;
@ -805,8 +806,7 @@ static void sm_cmac_handle_encryption_result(sm_key_t data){
} }
} }
static int sm_key_distribution_done(){ static int sm_key_distribution_all_received(){
if (setup->sm_key_distribution_send_set) return 0;
int recv_flags = sm_key_distribution_flags_for_set(setup->sm_m_preq.initiator_key_distribution); int recv_flags = sm_key_distribution_flags_for_set(setup->sm_m_preq.initiator_key_distribution);
return recv_flags == setup->sm_key_distribution_received_set; return recv_flags == setup->sm_key_distribution_received_set;
} }
@ -1189,7 +1189,12 @@ static void sm_run(void){
return; return;
} }
if (sm_key_distribution_done()){ // keys are sent
if (connection->sm_role){
// slave -> receive master keys
connection->sm_state_responding = SM_STATE_IDLE;
} else {
// master -> all done
sm_2timeout_stop(); sm_2timeout_stop();
connection->sm_state_responding = SM_STATE_IDLE; connection->sm_state_responding = SM_STATE_IDLE;
} }
@ -1574,7 +1579,7 @@ static void sm_event_packet_handler (uint8_t packet_type, uint16_t channel, uint
if (connection->sm_role){ if (connection->sm_role){
connection->sm_state_responding = SM_STATE_PH3_GET_RANDOM; connection->sm_state_responding = SM_STATE_PH3_GET_RANDOM;
} else { } else {
connection->sm_state_responding = SM_STATE_INITIATOR_XXX; connection->sm_state_responding = SM_STATE_RECEIVE_KEYS;
} }
} }
break; break;
@ -1815,7 +1820,7 @@ static void sm_packet_handler(uint8_t packet_type, uint16_t handle, uint8_t *pac
connection->sm_state_responding = SM_STATE_PH2_C1_GET_ENC_C; connection->sm_state_responding = SM_STATE_PH2_C1_GET_ENC_C;
break; break;
case SM_STATE_DISTRIBUTE_KEYS: case SM_STATE_RECEIVE_KEYS:
switch(packet[0]){ switch(packet[0]){
case SM_CODE_ENCRYPTION_INFORMATION: case SM_CODE_ENCRYPTION_INFORMATION:
setup->sm_key_distribution_received_set |= SM_KEYDIST_FLAG_ENCRYPTION_INFORMATION; setup->sm_key_distribution_received_set |= SM_KEYDIST_FLAG_ENCRYPTION_INFORMATION;
@ -1853,13 +1858,17 @@ static void sm_packet_handler(uint8_t packet_type, uint16_t handle, uint8_t *pac
break; break;
default: default:
// Unexpected PDU // Unexpected PDU
printf("Unexpected PDU %u in SM_STATE_DISTRIBUTE_KEYS\n", packet[0]); printf("Unexpected PDU %u in SM_STATE_RECEIVE_KEYS\n", packet[0]);
break; break;
} }
// done with key distribution? // done with key distribution?
if (sm_key_distribution_done()){ if (sm_key_distribution_all_received()){
sm_2timeout_stop(); if (connection->sm_role){
connection->sm_state_responding = SM_STATE_IDLE; sm_2timeout_stop();
connection->sm_state_responding = SM_STATE_IDLE;
} else {
connection->sm_state_responding = SM_STATE_DISTRIBUTE_KEYS;
}
} }
break; break;
default: default: