sm.c (b2072c76babc2e047a5363932f9c1e04226c180f) sm.c (afbd946d92409b562f5d55c5ee8b9f95bf5fa15e)
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

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

4334 sm_done_for_handle(con_handle);
4335 sm_conn->sm_engine_state = sm_conn->sm_role ? SM_RESPONDER_IDLE : SM_INITIATOR_CONNECTED;
4336 return;
4337 }
4338
4339 log_debug("sm_pdu_handler: state %u, pdu 0x%02x", sm_conn->sm_engine_state, sm_pdu_code);
4340
4341 int err;
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

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

4334 sm_done_for_handle(con_handle);
4335 sm_conn->sm_engine_state = sm_conn->sm_role ? SM_RESPONDER_IDLE : SM_INITIATOR_CONNECTED;
4336 return;
4337 }
4338
4339 log_debug("sm_pdu_handler: state %u, pdu 0x%02x", sm_conn->sm_engine_state, sm_pdu_code);
4340
4341 int err;
4342 uint8_t max_encryption_key_size;
4342 UNUSED(err);
4343
4344 if (sm_pdu_code == SM_CODE_KEYPRESS_NOTIFICATION){
4345 uint8_t buffer[5];
4346 buffer[0] = SM_EVENT_KEYPRESS_NOTIFICATION;
4347 buffer[1] = 3;
4348 little_endian_store_16(buffer, 2, con_handle);
4349 buffer[4] = packet[1];

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

4381 if (sm_pdu_code != SM_CODE_PAIRING_RESPONSE){
4382 sm_pdu_received_in_wrong_state(sm_conn);
4383 break;
4384 }
4385
4386 // store pairing request
4387 (void)memcpy(&setup->sm_s_pres, packet,
4388 sizeof(sm_pairing_packet_t));
4343 UNUSED(err);
4344
4345 if (sm_pdu_code == SM_CODE_KEYPRESS_NOTIFICATION){
4346 uint8_t buffer[5];
4347 buffer[0] = SM_EVENT_KEYPRESS_NOTIFICATION;
4348 buffer[1] = 3;
4349 little_endian_store_16(buffer, 2, con_handle);
4350 buffer[4] = packet[1];

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

4382 if (sm_pdu_code != SM_CODE_PAIRING_RESPONSE){
4383 sm_pdu_received_in_wrong_state(sm_conn);
4384 break;
4385 }
4386
4387 // store pairing request
4388 (void)memcpy(&setup->sm_s_pres, packet,
4389 sizeof(sm_pairing_packet_t));
4390
4391 // validate encryption key size
4392 max_encryption_key_size = sm_pairing_packet_get_max_encryption_key_size(setup->sm_s_pres);
4393 if ((max_encryption_key_size < 7) || (max_encryption_key_size > 16)){
4394 sm_pairing_error(sm_conn, SM_REASON_INVALID_PARAMETERS);
4395 break;
4396 }
4397
4389 err = sm_stk_generation_init(sm_conn);
4390
4391#ifdef ENABLE_TESTING_SUPPORT
4392 if (0 < test_pairing_failure && test_pairing_failure < SM_REASON_DHKEY_CHECK_FAILED){
4393 log_info("testing_support: abort with pairing failure %u", test_pairing_failure);
4394 err = test_pairing_failure;
4395 }
4396#endif

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

4480 if (sm_pdu_code != SM_CODE_PAIRING_REQUEST){
4481 sm_pdu_received_in_wrong_state(sm_conn);
4482 break;;
4483 }
4484
4485 // store pairing request
4486 (void)memcpy(&sm_conn->sm_m_preq, packet, sizeof(sm_pairing_packet_t));
4487
4398 err = sm_stk_generation_init(sm_conn);
4399
4400#ifdef ENABLE_TESTING_SUPPORT
4401 if (0 < test_pairing_failure && test_pairing_failure < SM_REASON_DHKEY_CHECK_FAILED){
4402 log_info("testing_support: abort with pairing failure %u", test_pairing_failure);
4403 err = test_pairing_failure;
4404 }
4405#endif

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

4489 if (sm_pdu_code != SM_CODE_PAIRING_REQUEST){
4490 sm_pdu_received_in_wrong_state(sm_conn);
4491 break;;
4492 }
4493
4494 // store pairing request
4495 (void)memcpy(&sm_conn->sm_m_preq, packet, sizeof(sm_pairing_packet_t));
4496
4497 // validation encryption key size
4498 max_encryption_key_size = sm_pairing_packet_get_max_encryption_key_size(sm_conn->sm_m_preq);
4499 if ((max_encryption_key_size < 7) || (max_encryption_key_size > 16)){
4500 sm_pairing_error(sm_conn, SM_REASON_INVALID_PARAMETERS);
4501 break;
4502 }
4503
4488 // check if IRK completed
4489 switch (sm_conn->sm_irk_lookup_state){
4490 case IRK_LOOKUP_SUCCEEDED:
4491 case IRK_LOOKUP_FAILED:
4492 sm_conn->sm_engine_state = SM_RESPONDER_PH1_PAIRING_REQUEST_RECEIVED;
4493 break;
4494 default:
4495 sm_conn->sm_engine_state = SM_RESPONDER_PH1_PAIRING_REQUEST_RECEIVED_W4_IRK;

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

4799 if (sm_pdu_code != SM_CODE_PAIRING_RESPONSE){
4800 sm_pdu_received_in_wrong_state(sm_conn);
4801 break;
4802 }
4803 // store pairing response
4804 (void)memcpy(&setup->sm_s_pres, packet, sizeof(sm_pairing_packet_t));
4805
4806 // validate encryption key size
4504 // check if IRK completed
4505 switch (sm_conn->sm_irk_lookup_state){
4506 case IRK_LOOKUP_SUCCEEDED:
4507 case IRK_LOOKUP_FAILED:
4508 sm_conn->sm_engine_state = SM_RESPONDER_PH1_PAIRING_REQUEST_RECEIVED;
4509 break;
4510 default:
4511 sm_conn->sm_engine_state = SM_RESPONDER_PH1_PAIRING_REQUEST_RECEIVED_W4_IRK;

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

4815 if (sm_pdu_code != SM_CODE_PAIRING_RESPONSE){
4816 sm_pdu_received_in_wrong_state(sm_conn);
4817 break;
4818 }
4819 // store pairing response
4820 (void)memcpy(&setup->sm_s_pres, packet, sizeof(sm_pairing_packet_t));
4821
4822 // validate encryption key size
4807 sm_conn->sm_actual_encryption_key_size = sm_calc_actual_encryption_key_size(sm_pairing_packet_get_max_encryption_key_size(setup->sm_s_pres));
4823 max_encryption_key_size = sm_pairing_packet_get_max_encryption_key_size(setup->sm_s_pres);
4824 if ((max_encryption_key_size < 7) || (max_encryption_key_size > 16)){
4825 sm_pairing_error(sm_conn, SM_REASON_INVALID_PARAMETERS);
4826 break;
4827 }
4828 sm_conn->sm_actual_encryption_key_size = sm_calc_actual_encryption_key_size(max_encryption_key_size);
4808 // SC Only mandates 128 bit key size
4809 if (sm_sc_only_mode && (sm_conn->sm_actual_encryption_key_size < 16)) {
4810 sm_conn->sm_actual_encryption_key_size = 0;
4811 }
4812 if (sm_conn->sm_actual_encryption_key_size == 0){
4813 sm_pairing_error(sm_conn, SM_REASON_ENCRYPTION_KEY_SIZE);
4814 break;
4815 }

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

4827 }
4828 break;
4829
4830 case SM_BR_EDR_RESPONDER_W4_PAIRING_REQUEST:
4831 if (sm_pdu_code != SM_CODE_PAIRING_REQUEST){
4832 sm_pdu_received_in_wrong_state(sm_conn);
4833 break;
4834 }
4829 // SC Only mandates 128 bit key size
4830 if (sm_sc_only_mode && (sm_conn->sm_actual_encryption_key_size < 16)) {
4831 sm_conn->sm_actual_encryption_key_size = 0;
4832 }
4833 if (sm_conn->sm_actual_encryption_key_size == 0){
4834 sm_pairing_error(sm_conn, SM_REASON_ENCRYPTION_KEY_SIZE);
4835 break;
4836 }

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

4848 }
4849 break;
4850
4851 case SM_BR_EDR_RESPONDER_W4_PAIRING_REQUEST:
4852 if (sm_pdu_code != SM_CODE_PAIRING_REQUEST){
4853 sm_pdu_received_in_wrong_state(sm_conn);
4854 break;
4855 }
4856
4835 // store pairing request
4836 (void)memcpy(&sm_conn->sm_m_preq, packet, sizeof(sm_pairing_packet_t));
4857 // store pairing request
4858 (void)memcpy(&sm_conn->sm_m_preq, packet, sizeof(sm_pairing_packet_t));
4859
4837 // validate encryption key size
4860 // validate encryption key size
4838 sm_conn->sm_actual_encryption_key_size = sm_calc_actual_encryption_key_size(sm_pairing_packet_get_max_encryption_key_size(sm_conn->sm_m_preq));
4861 max_encryption_key_size = sm_pairing_packet_get_max_encryption_key_size(setup->sm_m_preq);
4862 if ((max_encryption_key_size < 7) || (max_encryption_key_size > 16)){
4863 sm_pairing_error(sm_conn, SM_REASON_INVALID_PARAMETERS);
4864 break;
4865 }
4866 sm_conn->sm_actual_encryption_key_size = sm_calc_actual_encryption_key_size(max_encryption_key_size);
4839 // SC Only mandates 128 bit key size
4840 if (sm_sc_only_mode && (sm_conn->sm_actual_encryption_key_size < 16)) {
4841 sm_conn->sm_actual_encryption_key_size = 0;
4842 }
4843 if (sm_conn->sm_actual_encryption_key_size == 0){
4844 sm_pairing_error(sm_conn, SM_REASON_ENCRYPTION_KEY_SIZE);
4845 break;
4846 }

--- 681 unchanged lines hidden ---
4867 // SC Only mandates 128 bit key size
4868 if (sm_sc_only_mode && (sm_conn->sm_actual_encryption_key_size < 16)) {
4869 sm_conn->sm_actual_encryption_key_size = 0;
4870 }
4871 if (sm_conn->sm_actual_encryption_key_size == 0){
4872 sm_pairing_error(sm_conn, SM_REASON_ENCRYPTION_KEY_SIZE);
4873 break;
4874 }

--- 681 unchanged lines hidden ---