handle encryption key refresh event

This commit is contained in:
Matthias Ringwald 2015-08-13 13:04:27 +02:00
parent 003a27eb00
commit 5f62024dd4
2 changed files with 30 additions and 0 deletions

View File

@ -156,6 +156,7 @@ static void att_event_packet_handler (uint8_t packet_type, uint16_t channel, uin
break;
case HCI_EVENT_ENCRYPTION_CHANGE:
case HCI_EVENT_ENCRYPTION_KEY_REFRESH_COMPLETE:
// check handle
if (att_connection.con_handle != READ_BT_16(packet, 3)) break;
att_connection.encryption_key_size = sm_encryption_key_size(att_client_addr_type, att_client_address);

View File

@ -1823,6 +1823,35 @@ static void sm_event_packet_handler (uint8_t packet_type, uint16_t channel, uint
}
break;
case HCI_EVENT_ENCRYPTION_KEY_REFRESH_COMPLETE:
handle = READ_BT_16(packet, 3);
sm_conn = sm_get_connection_for_handle(handle);
if (!sm_conn) break;
log_info("Encryption key refresh complete, key size %u", sm_conn->sm_connection_encrypted,
sm_conn->sm_actual_encryption_key_size);
log_info("event handler, state %u", sm_conn->sm_engine_state);
// continue if part of initial pairing
switch (sm_conn->sm_engine_state){
case SM_INITIATOR_PH0_W4_CONNECTION_ENCRYPTED:
sm_conn->sm_engine_state = SM_INITIATOR_CONNECTED;
sm_done_for_handle(sm_conn->sm_handle);
break;
case SM_PH2_W4_CONNECTION_ENCRYPTED:
if (sm_conn->sm_role){
// slave
sm_conn->sm_engine_state = SM_PH3_GET_RANDOM;
} else {
// master
sm_conn->sm_engine_state = SM_PH3_RECEIVE_KEYS;
}
break;
default:
break;
}
break;
case HCI_EVENT_DISCONNECTION_COMPLETE:
handle = READ_BT_16(packet, 3);
sm_done_for_handle(handle);