sm.c (48f33f37ebd420cb7aae248a79774e16e0dcb03b) sm.c (3b7fd749adde4e153c569c0a0ae252fd9a49b180)
1/*
2 * Copyright (C) 2014 BlueKitchen GmbH
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright

--- 3404 unchanged lines hidden (view full) ---

3413 break;
3414
3415 default:
3416 break;
3417 }
3418 break;
3419
3420 case HCI_EVENT_ENCRYPTION_CHANGE:
1/*
2 * Copyright (C) 2014 BlueKitchen GmbH
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright

--- 3404 unchanged lines hidden (view full) ---

3413 break;
3414
3415 default:
3416 break;
3417 }
3418 break;
3419
3420 case HCI_EVENT_ENCRYPTION_CHANGE:
3421 con_handle = little_endian_read_16(packet, 3);
3421 con_handle = hci_event_encryption_change_get_connection_handle(packet);
3422 sm_conn = sm_get_connection_for_handle(con_handle);
3423 if (!sm_conn) break;
3424
3422 sm_conn = sm_get_connection_for_handle(con_handle);
3423 if (!sm_conn) break;
3424
3425 sm_conn->sm_connection_encrypted = packet[5];
3425 sm_conn->sm_connection_encrypted = hci_event_encryption_change_get_encryption_enabled(packet);
3426 log_info("Encryption state change: %u, key size %u", sm_conn->sm_connection_encrypted,
3427 sm_conn->sm_actual_encryption_key_size);
3428 log_info("event handler, state %u", sm_conn->sm_engine_state);
3429
3430 // encryption change event concludes re-encryption for bonded devices (even if it fails)
3431 if (sm_conn->sm_engine_state == SM_INITIATOR_PH0_W4_CONNECTION_ENCRYPTED){
3432 sm_conn->sm_engine_state = SM_INITIATOR_CONNECTED;
3426 log_info("Encryption state change: %u, key size %u", sm_conn->sm_connection_encrypted,
3427 sm_conn->sm_actual_encryption_key_size);
3428 log_info("event handler, state %u", sm_conn->sm_engine_state);
3429
3430 // encryption change event concludes re-encryption for bonded devices (even if it fails)
3431 if (sm_conn->sm_engine_state == SM_INITIATOR_PH0_W4_CONNECTION_ENCRYPTED){
3432 sm_conn->sm_engine_state = SM_INITIATOR_CONNECTED;
3433 // block connection if encryption fails
3434 if (sm_conn->sm_connection_encrypted == 0){
3435 // set state to 'TIMEOUT' to prevent further interaction with this
3436 // also, gap_reconnect_security_setup_active will return true
3437 sm_conn->sm_engine_state = SM_GENERAL_TIMEOUT;
3438 }
3433 // notify client, if pairing was requested before
3434 if (sm_conn->sm_pairing_requested){
3435 sm_conn->sm_pairing_requested = 0;
3436 if (sm_conn->sm_connection_encrypted){
3437 sm_notify_client_status_reason(sm_conn, ERROR_CODE_SUCCESS, 0);
3438 } else {
3439 sm_notify_client_status_reason(sm_conn, ERROR_CODE_AUTHENTICATION_FAILURE, 0);
3440 }

--- 1174 unchanged lines hidden ---
3439 // notify client, if pairing was requested before
3440 if (sm_conn->sm_pairing_requested){
3441 sm_conn->sm_pairing_requested = 0;
3442 if (sm_conn->sm_connection_encrypted){
3443 sm_notify_client_status_reason(sm_conn, ERROR_CODE_SUCCESS, 0);
3444 } else {
3445 sm_notify_client_status_reason(sm_conn, ERROR_CODE_AUTHENTICATION_FAILURE, 0);
3446 }

--- 1174 unchanged lines hidden ---