sm.c (178e8c1b8fecea135a633e71da11e3c04ce36787) sm.c (f32b7a88e66a25540de795d65b9d1eaea41cbfab)
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

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

2201 break;
2202 }
2203 break;
2204#endif /* ENABLE_LE_SECURE_CONNECTIONS */
2205#endif /* ENABLE_LE_PERIPHERAL */
2206
2207#ifdef ENABLE_LE_CENTRAL
2208 case SM_INITIATOR_PH0_HAS_LTK:
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

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

2201 break;
2202 }
2203 break;
2204#endif /* ENABLE_LE_SECURE_CONNECTIONS */
2205#endif /* ENABLE_LE_PERIPHERAL */
2206
2207#ifdef ENABLE_LE_CENTRAL
2208 case SM_INITIATOR_PH0_HAS_LTK:
2209 sm_reset_setup();
2210 sm_load_security_info(sm_connection);
2211 sm_connection->sm_engine_state = SM_INITIATOR_PH0_SEND_START_ENCRYPTION;
2209 // just lock context
2212 break;
2213 case SM_INITIATOR_PH1_W2_SEND_PAIRING_REQUEST:
2214 sm_reset_setup();
2215 sm_init_setup(sm_connection);
2216 sm_timeout_start(sm_connection);
2217 sm_connection->sm_engine_state = SM_INITIATOR_PH1_SEND_PAIRING_REQUEST;
2218 break;
2219#endif

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

2349 buffer[1] = setup->sm_pairing_failed_reason;
2350 connection->sm_engine_state = connection->sm_role ? SM_RESPONDER_IDLE : SM_INITIATOR_CONNECTED;
2351 l2cap_send_connectionless(connection->sm_handle, L2CAP_CID_SECURITY_MANAGER_PROTOCOL, (uint8_t*) buffer, sizeof(buffer));
2352 sm_notify_client_status_reason(connection, ERROR_CODE_AUTHENTICATION_FAILURE, setup->sm_pairing_failed_reason);
2353 sm_done_for_handle(connection->sm_handle);
2354 break;
2355 }
2356
2210 break;
2211 case SM_INITIATOR_PH1_W2_SEND_PAIRING_REQUEST:
2212 sm_reset_setup();
2213 sm_init_setup(sm_connection);
2214 sm_timeout_start(sm_connection);
2215 sm_connection->sm_engine_state = SM_INITIATOR_PH1_SEND_PAIRING_REQUEST;
2216 break;
2217#endif

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

2347 buffer[1] = setup->sm_pairing_failed_reason;
2348 connection->sm_engine_state = connection->sm_role ? SM_RESPONDER_IDLE : SM_INITIATOR_CONNECTED;
2349 l2cap_send_connectionless(connection->sm_handle, L2CAP_CID_SECURITY_MANAGER_PROTOCOL, (uint8_t*) buffer, sizeof(buffer));
2350 sm_notify_client_status_reason(connection, ERROR_CODE_AUTHENTICATION_FAILURE, setup->sm_pairing_failed_reason);
2351 sm_done_for_handle(connection->sm_handle);
2352 break;
2353 }
2354
2357 // responding state
2355 // secure connections, initiator + responding states
2358#ifdef ENABLE_LE_SECURE_CONNECTIONS
2359 case SM_SC_W2_CMAC_FOR_CONFIRMATION:
2360 if (!sm_cmac_ready()) break;
2361 connection->sm_engine_state = SM_SC_W4_CMAC_FOR_CONFIRMATION;
2362 sm_sc_calculate_local_confirm(connection);
2363 break;
2364 case SM_SC_W2_CMAC_FOR_CHECK_CONFIRMATION:
2365 if (!sm_cmac_ready()) break;

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

2412 connection->sm_engine_state = SM_SC_W4_CALCULATE_ILK;
2413 h7_calculate_ilk(connection);
2414 break;
2415#endif
2416#endif
2417
2418#ifdef ENABLE_LE_CENTRAL
2419 // initiator side
2356#ifdef ENABLE_LE_SECURE_CONNECTIONS
2357 case SM_SC_W2_CMAC_FOR_CONFIRMATION:
2358 if (!sm_cmac_ready()) break;
2359 connection->sm_engine_state = SM_SC_W4_CMAC_FOR_CONFIRMATION;
2360 sm_sc_calculate_local_confirm(connection);
2361 break;
2362 case SM_SC_W2_CMAC_FOR_CHECK_CONFIRMATION:
2363 if (!sm_cmac_ready()) break;

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

2410 connection->sm_engine_state = SM_SC_W4_CALCULATE_ILK;
2411 h7_calculate_ilk(connection);
2412 break;
2413#endif
2414#endif
2415
2416#ifdef ENABLE_LE_CENTRAL
2417 // initiator side
2420 case SM_INITIATOR_PH0_SEND_START_ENCRYPTION: {
2418
2419 case SM_INITIATOR_PH0_HAS_LTK: {
2420 sm_reset_setup();
2421 sm_load_security_info(connection);
2422
2421 sm_key_t peer_ltk_flipped;
2422 reverse_128(setup->sm_peer_ltk, peer_ltk_flipped);
2423 connection->sm_engine_state = SM_INITIATOR_PH0_W4_CONNECTION_ENCRYPTED;
2424 log_info("sm: hci_le_start_encryption ediv 0x%04x", setup->sm_peer_ediv);
2425 uint32_t rand_high = big_endian_read_32(setup->sm_peer_rand, 0);
2426 uint32_t rand_low = big_endian_read_32(setup->sm_peer_rand, 4);
2427 hci_send_cmd(&hci_le_start_encryption, connection->sm_handle,rand_low, rand_high, setup->sm_peer_ediv, peer_ltk_flipped);
2428 return;

--- 2184 unchanged lines hidden ---
2423 sm_key_t peer_ltk_flipped;
2424 reverse_128(setup->sm_peer_ltk, peer_ltk_flipped);
2425 connection->sm_engine_state = SM_INITIATOR_PH0_W4_CONNECTION_ENCRYPTED;
2426 log_info("sm: hci_le_start_encryption ediv 0x%04x", setup->sm_peer_ediv);
2427 uint32_t rand_high = big_endian_read_32(setup->sm_peer_rand, 0);
2428 uint32_t rand_low = big_endian_read_32(setup->sm_peer_rand, 4);
2429 hci_send_cmd(&hci_le_start_encryption, connection->sm_handle,rand_low, rand_high, setup->sm_peer_ediv, peer_ltk_flipped);
2430 return;

--- 2184 unchanged lines hidden ---