Loading system/stack/btm/btm_ble_sec.cc +15 −19 Original line number Diff line number Diff line Loading @@ -51,9 +51,9 @@ #include "stack/include/btm_ble_privacy.h" #include "stack/include/btm_ble_sec_api.h" #include "stack/include/btm_log_history.h" #include "stack/include/btm_status.h" #include "stack/include/gatt_api.h" #include "stack/include/l2cap_security_interface.h" #include "stack/include/l2cdefs.h" #include "stack/include/smp_api.h" #include "stack/include/smp_api_types.h" #include "types/raw_address.h" Loading Loading @@ -709,11 +709,11 @@ static tBTM_SEC_ACTION btm_ble_determine_security_act( * p_callback : Pointer to the callback function. * p_ref_data : Pointer to be returned along with the callback. * * Returns Returns - L2CAP LE Connection Response Result Code. * Returns Returns - tBTM_STATUS * ******************************************************************************/ tL2CAP_LE_RESULT_CODE btm_ble_start_sec_check(const RawAddress& bd_addr, uint16_t psm, bool is_originator, tBTM_STATUS btm_ble_start_sec_check(const RawAddress& bd_addr, uint16_t psm, bool is_originator, tBTM_SEC_CALLBACK* p_callback, void* p_ref_data) { /* Find the service record for the PSM */ Loading @@ -724,7 +724,7 @@ tL2CAP_LE_RESULT_CODE btm_ble_start_sec_check(const RawAddress& bd_addr, if (!p_serv_rec) { LOG_WARN("PSM: %d no application registered", psm); (*p_callback)(&bd_addr, BT_TRANSPORT_LE, p_ref_data, BTM_MODE_UNSUPPORTED); return L2CAP_LE_RESULT_NO_PSM; return BTM_ILLEGAL_VALUE; } bool is_encrypted = BTM_IsEncrypted(bd_addr, BT_TRANSPORT_LE); Loading @@ -733,18 +733,14 @@ tL2CAP_LE_RESULT_CODE btm_ble_start_sec_check(const RawAddress& bd_addr, if (!is_originator) { if ((p_serv_rec->security_flags & BTM_SEC_IN_ENCRYPT) && !is_encrypted) { LOG_ERROR( "L2CAP_LE_RESULT_INSUFFICIENT_ENCRYP. service " "security_flags=0x%x, ", LOG_ERROR("BTM_NOT_ENCRYPTED. service security_flags=0x%x", p_serv_rec->security_flags); return L2CAP_LE_RESULT_INSUFFICIENT_ENCRYP; return BTM_NOT_ENCRYPTED; } else if ((p_serv_rec->security_flags & BTM_SEC_IN_AUTHENTICATE) && !(is_link_key_authed || is_authenticated)) { LOG_ERROR( "L2CAP_LE_RESULT_INSUFFICIENT_AUTHENTICATION. service " "security_flags=0x%x, ", LOG_ERROR("BTM_NOT_AUTHENTICATED. service security_flags=0x%x", p_serv_rec->security_flags); return L2CAP_LE_RESULT_INSUFFICIENT_AUTHENTICATION; return BTM_NOT_AUTHENTICATED; } /* TODO: When security is required, then must check that the key size of our service is equal or smaller than the incoming connection key size. */ Loading Loading @@ -782,7 +778,7 @@ tL2CAP_LE_RESULT_CODE btm_ble_start_sec_check(const RawAddress& bd_addr, } if (ble_sec_act == BTM_BLE_SEC_NONE && sec_act != BTM_SEC_ENC_PENDING) { return L2CAP_LE_RESULT_CONN_OK; return BTM_SUCCESS; } l2cble_update_sec_act(bd_addr, sec_act); Loading @@ -790,7 +786,7 @@ tL2CAP_LE_RESULT_CODE btm_ble_start_sec_check(const RawAddress& bd_addr, BTM_SetEncryption(bd_addr, BT_TRANSPORT_LE, p_callback, p_ref_data, ble_sec_act); return L2CAP_LE_RESULT_CONN_OK; return BTM_SUCCESS; } /******************************************************************************* Loading system/stack/btm/btm_ble_sec.h +6 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ #include "macros.h" #include "stack/include/btm_ble_sec_api_types.h" #include "stack/include/btm_sec_api_types.h" #include "stack/include/btm_status.h" #include "types/raw_address.h" typedef enum : uint8_t { Loading Loading @@ -66,3 +67,8 @@ void btm_sec_save_le_key(const RawAddress& bd_addr, tBTM_LE_KEY_TYPE key_type, void btm_ble_update_sec_key_size(const RawAddress& bd_addr, uint8_t enc_key_size); uint8_t btm_ble_read_sec_key_size(const RawAddress& bd_addr); tBTM_STATUS btm_ble_start_sec_check(const RawAddress& bd_addr, uint16_t psm, bool is_originator, tBTM_SEC_CALLBACK* p_callback, void* p_ref_data); system/stack/l2cap/l2c_ble.cc +21 −10 Original line number Diff line number Diff line Loading @@ -41,6 +41,7 @@ #include "os/log.h" #include "osi/include/allocator.h" #include "osi/include/properties.h" #include "stack/btm/btm_ble_sec.h" #include "stack/btm/btm_dev.h" #include "stack/btm/btm_int_types.h" #include "stack/btm/btm_sec.h" Loading @@ -59,11 +60,6 @@ constexpr char kBtmLogTag[] = "L2CAP"; } tL2CAP_LE_RESULT_CODE btm_ble_start_sec_check(const RawAddress& bd_addr, uint16_t psm, bool is_originator, tBTM_SEC_CALLBACK* p_callback, void* p_ref_data); extern tBTM_CB btm_cb; using base::StringPrintf; Loading Loading @@ -1614,7 +1610,6 @@ tL2CAP_LE_RESULT_CODE l2ble_sec_access_req(const RawAddress& bd_addr, uint16_t psm, bool is_originator, tBTM_SEC_CALLBACK* p_callback, void* p_ref_data) { tL2CAP_LE_RESULT_CODE result; tL2C_LCB* p_lcb = NULL; if (!p_callback) { Loading Loading @@ -1643,10 +1638,26 @@ tL2CAP_LE_RESULT_CODE l2ble_sec_access_req(const RawAddress& bd_addr, p_buf->p_callback = p_callback; p_buf->p_ref_data = p_ref_data; fixed_queue_enqueue(p_lcb->le_sec_pending_q, p_buf); result = btm_ble_start_sec_check(bd_addr, psm, is_originator, tBTM_STATUS result = btm_ble_start_sec_check(bd_addr, psm, is_originator, &l2cble_sec_comp, p_ref_data); return result; switch (result) { case BTM_SUCCESS: return L2CAP_LE_RESULT_CONN_OK; case BTM_ILLEGAL_VALUE: return L2CAP_LE_RESULT_NO_PSM; case BTM_NOT_AUTHENTICATED: return L2CAP_LE_RESULT_INSUFFICIENT_AUTHENTICATION; case BTM_NOT_ENCRYPTED: return L2CAP_LE_RESULT_INSUFFICIENT_ENCRYP; case BTM_NOT_AUTHORIZED: return L2CAP_LE_RESULT_INSUFFICIENT_AUTHORIZATION; case BTM_INSUFFICIENT_ENCRYPT_KEY_SIZE: return L2CAP_LE_RESULT_INSUFFICIENT_ENCRYP_KEY_SIZE; default: LOG_ERROR("unexpected return value: %s", btm_status_text(result).c_str()); return L2CAP_LE_RESULT_INVALID_PARAMETERS; } } /* This function is called to adjust the connection intervals based on various Loading system/test/mock/mock_stack_btm_ble.cc +6 −6 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ #include <optional> #include "stack/include/btm_api_types.h" #include "stack/include/btm_status.h" #include "test/common/mock_functions.h" // Original usings Loading Loading @@ -115,8 +116,7 @@ bool btm_ble_get_enc_key_type::return_value = false; uint8_t btm_ble_read_sec_key_size::return_value = 0; tBTM_STATUS btm_ble_set_encryption::return_value = 0; tBTM_STATUS btm_ble_start_encrypt::return_value = 0; tL2CAP_LE_RESULT_CODE btm_ble_start_sec_check::return_value = L2CAP_LE_RESULT_CONN_OK; tBTM_STATUS btm_ble_start_sec_check::return_value = BTM_SUCCESS; bool btm_get_local_div::return_value = false; tBTM_STATUS btm_proc_smp_cback::return_value = 0; Loading Loading @@ -327,8 +327,8 @@ tBTM_STATUS btm_ble_start_encrypt(const RawAddress& bda, bool use_stk, inc_func_call_count(__func__); return test::mock::stack_btm_ble::btm_ble_start_encrypt(bda, use_stk, p_stk); } tL2CAP_LE_RESULT_CODE btm_ble_start_sec_check(const RawAddress& bd_addr, uint16_t psm, bool is_originator, tBTM_STATUS btm_ble_start_sec_check(const RawAddress& bd_addr, uint16_t psm, bool is_originator, tBTM_SEC_CALLBACK* p_callback, void* p_ref_data) { inc_func_call_count(__func__); Loading system/test/mock/mock_stack_btm_ble.h +8 −8 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ #include "stack/include/btm_ble_api_types.h" #include "stack/include/btm_ble_sec_api_types.h" #include "stack/include/btm_sec_api_types.h" #include "stack/include/btm_status.h" #include "stack/include/l2cdefs.h" #include "types/ble_address_with_type.h" #include "types/raw_address.h" Loading Loading @@ -596,16 +597,15 @@ extern struct btm_ble_start_encrypt btm_ble_start_encrypt; // Params: const RawAddress& bd_addr, uint16_t psm, bool is_originator, // tBTM_SEC_CALLBACK* p_callback, void* p_ref_data Return: tL2CAP_LE_RESULT_CODE struct btm_ble_start_sec_check { static tL2CAP_LE_RESULT_CODE return_value; std::function<tL2CAP_LE_RESULT_CODE( const RawAddress& bd_addr, uint16_t psm, bool is_originator, tBTM_SEC_CALLBACK* p_callback, void* p_ref_data)> static tBTM_STATUS return_value; std::function<tBTM_STATUS(const RawAddress& bd_addr, uint16_t psm, bool is_originator, tBTM_SEC_CALLBACK* p_callback, void* p_ref_data)> body{[](const RawAddress& /* bd_addr */, uint16_t /* psm */, bool /* is_originator */, tBTM_SEC_CALLBACK* /* p_callback */, void* /* p_ref_data */) { return return_value; }}; tL2CAP_LE_RESULT_CODE operator()(const RawAddress& bd_addr, uint16_t psm, bool is_originator, tBTM_SEC_CALLBACK* p_callback, tBTM_STATUS operator()(const RawAddress& bd_addr, uint16_t psm, bool is_originator, tBTM_SEC_CALLBACK* p_callback, void* p_ref_data) { return body(bd_addr, psm, is_originator, p_callback, p_ref_data); }; Loading Loading
system/stack/btm/btm_ble_sec.cc +15 −19 Original line number Diff line number Diff line Loading @@ -51,9 +51,9 @@ #include "stack/include/btm_ble_privacy.h" #include "stack/include/btm_ble_sec_api.h" #include "stack/include/btm_log_history.h" #include "stack/include/btm_status.h" #include "stack/include/gatt_api.h" #include "stack/include/l2cap_security_interface.h" #include "stack/include/l2cdefs.h" #include "stack/include/smp_api.h" #include "stack/include/smp_api_types.h" #include "types/raw_address.h" Loading Loading @@ -709,11 +709,11 @@ static tBTM_SEC_ACTION btm_ble_determine_security_act( * p_callback : Pointer to the callback function. * p_ref_data : Pointer to be returned along with the callback. * * Returns Returns - L2CAP LE Connection Response Result Code. * Returns Returns - tBTM_STATUS * ******************************************************************************/ tL2CAP_LE_RESULT_CODE btm_ble_start_sec_check(const RawAddress& bd_addr, uint16_t psm, bool is_originator, tBTM_STATUS btm_ble_start_sec_check(const RawAddress& bd_addr, uint16_t psm, bool is_originator, tBTM_SEC_CALLBACK* p_callback, void* p_ref_data) { /* Find the service record for the PSM */ Loading @@ -724,7 +724,7 @@ tL2CAP_LE_RESULT_CODE btm_ble_start_sec_check(const RawAddress& bd_addr, if (!p_serv_rec) { LOG_WARN("PSM: %d no application registered", psm); (*p_callback)(&bd_addr, BT_TRANSPORT_LE, p_ref_data, BTM_MODE_UNSUPPORTED); return L2CAP_LE_RESULT_NO_PSM; return BTM_ILLEGAL_VALUE; } bool is_encrypted = BTM_IsEncrypted(bd_addr, BT_TRANSPORT_LE); Loading @@ -733,18 +733,14 @@ tL2CAP_LE_RESULT_CODE btm_ble_start_sec_check(const RawAddress& bd_addr, if (!is_originator) { if ((p_serv_rec->security_flags & BTM_SEC_IN_ENCRYPT) && !is_encrypted) { LOG_ERROR( "L2CAP_LE_RESULT_INSUFFICIENT_ENCRYP. service " "security_flags=0x%x, ", LOG_ERROR("BTM_NOT_ENCRYPTED. service security_flags=0x%x", p_serv_rec->security_flags); return L2CAP_LE_RESULT_INSUFFICIENT_ENCRYP; return BTM_NOT_ENCRYPTED; } else if ((p_serv_rec->security_flags & BTM_SEC_IN_AUTHENTICATE) && !(is_link_key_authed || is_authenticated)) { LOG_ERROR( "L2CAP_LE_RESULT_INSUFFICIENT_AUTHENTICATION. service " "security_flags=0x%x, ", LOG_ERROR("BTM_NOT_AUTHENTICATED. service security_flags=0x%x", p_serv_rec->security_flags); return L2CAP_LE_RESULT_INSUFFICIENT_AUTHENTICATION; return BTM_NOT_AUTHENTICATED; } /* TODO: When security is required, then must check that the key size of our service is equal or smaller than the incoming connection key size. */ Loading Loading @@ -782,7 +778,7 @@ tL2CAP_LE_RESULT_CODE btm_ble_start_sec_check(const RawAddress& bd_addr, } if (ble_sec_act == BTM_BLE_SEC_NONE && sec_act != BTM_SEC_ENC_PENDING) { return L2CAP_LE_RESULT_CONN_OK; return BTM_SUCCESS; } l2cble_update_sec_act(bd_addr, sec_act); Loading @@ -790,7 +786,7 @@ tL2CAP_LE_RESULT_CODE btm_ble_start_sec_check(const RawAddress& bd_addr, BTM_SetEncryption(bd_addr, BT_TRANSPORT_LE, p_callback, p_ref_data, ble_sec_act); return L2CAP_LE_RESULT_CONN_OK; return BTM_SUCCESS; } /******************************************************************************* Loading
system/stack/btm/btm_ble_sec.h +6 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ #include "macros.h" #include "stack/include/btm_ble_sec_api_types.h" #include "stack/include/btm_sec_api_types.h" #include "stack/include/btm_status.h" #include "types/raw_address.h" typedef enum : uint8_t { Loading Loading @@ -66,3 +67,8 @@ void btm_sec_save_le_key(const RawAddress& bd_addr, tBTM_LE_KEY_TYPE key_type, void btm_ble_update_sec_key_size(const RawAddress& bd_addr, uint8_t enc_key_size); uint8_t btm_ble_read_sec_key_size(const RawAddress& bd_addr); tBTM_STATUS btm_ble_start_sec_check(const RawAddress& bd_addr, uint16_t psm, bool is_originator, tBTM_SEC_CALLBACK* p_callback, void* p_ref_data);
system/stack/l2cap/l2c_ble.cc +21 −10 Original line number Diff line number Diff line Loading @@ -41,6 +41,7 @@ #include "os/log.h" #include "osi/include/allocator.h" #include "osi/include/properties.h" #include "stack/btm/btm_ble_sec.h" #include "stack/btm/btm_dev.h" #include "stack/btm/btm_int_types.h" #include "stack/btm/btm_sec.h" Loading @@ -59,11 +60,6 @@ constexpr char kBtmLogTag[] = "L2CAP"; } tL2CAP_LE_RESULT_CODE btm_ble_start_sec_check(const RawAddress& bd_addr, uint16_t psm, bool is_originator, tBTM_SEC_CALLBACK* p_callback, void* p_ref_data); extern tBTM_CB btm_cb; using base::StringPrintf; Loading Loading @@ -1614,7 +1610,6 @@ tL2CAP_LE_RESULT_CODE l2ble_sec_access_req(const RawAddress& bd_addr, uint16_t psm, bool is_originator, tBTM_SEC_CALLBACK* p_callback, void* p_ref_data) { tL2CAP_LE_RESULT_CODE result; tL2C_LCB* p_lcb = NULL; if (!p_callback) { Loading Loading @@ -1643,10 +1638,26 @@ tL2CAP_LE_RESULT_CODE l2ble_sec_access_req(const RawAddress& bd_addr, p_buf->p_callback = p_callback; p_buf->p_ref_data = p_ref_data; fixed_queue_enqueue(p_lcb->le_sec_pending_q, p_buf); result = btm_ble_start_sec_check(bd_addr, psm, is_originator, tBTM_STATUS result = btm_ble_start_sec_check(bd_addr, psm, is_originator, &l2cble_sec_comp, p_ref_data); return result; switch (result) { case BTM_SUCCESS: return L2CAP_LE_RESULT_CONN_OK; case BTM_ILLEGAL_VALUE: return L2CAP_LE_RESULT_NO_PSM; case BTM_NOT_AUTHENTICATED: return L2CAP_LE_RESULT_INSUFFICIENT_AUTHENTICATION; case BTM_NOT_ENCRYPTED: return L2CAP_LE_RESULT_INSUFFICIENT_ENCRYP; case BTM_NOT_AUTHORIZED: return L2CAP_LE_RESULT_INSUFFICIENT_AUTHORIZATION; case BTM_INSUFFICIENT_ENCRYPT_KEY_SIZE: return L2CAP_LE_RESULT_INSUFFICIENT_ENCRYP_KEY_SIZE; default: LOG_ERROR("unexpected return value: %s", btm_status_text(result).c_str()); return L2CAP_LE_RESULT_INVALID_PARAMETERS; } } /* This function is called to adjust the connection intervals based on various Loading
system/test/mock/mock_stack_btm_ble.cc +6 −6 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ #include <optional> #include "stack/include/btm_api_types.h" #include "stack/include/btm_status.h" #include "test/common/mock_functions.h" // Original usings Loading Loading @@ -115,8 +116,7 @@ bool btm_ble_get_enc_key_type::return_value = false; uint8_t btm_ble_read_sec_key_size::return_value = 0; tBTM_STATUS btm_ble_set_encryption::return_value = 0; tBTM_STATUS btm_ble_start_encrypt::return_value = 0; tL2CAP_LE_RESULT_CODE btm_ble_start_sec_check::return_value = L2CAP_LE_RESULT_CONN_OK; tBTM_STATUS btm_ble_start_sec_check::return_value = BTM_SUCCESS; bool btm_get_local_div::return_value = false; tBTM_STATUS btm_proc_smp_cback::return_value = 0; Loading Loading @@ -327,8 +327,8 @@ tBTM_STATUS btm_ble_start_encrypt(const RawAddress& bda, bool use_stk, inc_func_call_count(__func__); return test::mock::stack_btm_ble::btm_ble_start_encrypt(bda, use_stk, p_stk); } tL2CAP_LE_RESULT_CODE btm_ble_start_sec_check(const RawAddress& bd_addr, uint16_t psm, bool is_originator, tBTM_STATUS btm_ble_start_sec_check(const RawAddress& bd_addr, uint16_t psm, bool is_originator, tBTM_SEC_CALLBACK* p_callback, void* p_ref_data) { inc_func_call_count(__func__); Loading
system/test/mock/mock_stack_btm_ble.h +8 −8 Original line number Diff line number Diff line Loading @@ -34,6 +34,7 @@ #include "stack/include/btm_ble_api_types.h" #include "stack/include/btm_ble_sec_api_types.h" #include "stack/include/btm_sec_api_types.h" #include "stack/include/btm_status.h" #include "stack/include/l2cdefs.h" #include "types/ble_address_with_type.h" #include "types/raw_address.h" Loading Loading @@ -596,16 +597,15 @@ extern struct btm_ble_start_encrypt btm_ble_start_encrypt; // Params: const RawAddress& bd_addr, uint16_t psm, bool is_originator, // tBTM_SEC_CALLBACK* p_callback, void* p_ref_data Return: tL2CAP_LE_RESULT_CODE struct btm_ble_start_sec_check { static tL2CAP_LE_RESULT_CODE return_value; std::function<tL2CAP_LE_RESULT_CODE( const RawAddress& bd_addr, uint16_t psm, bool is_originator, tBTM_SEC_CALLBACK* p_callback, void* p_ref_data)> static tBTM_STATUS return_value; std::function<tBTM_STATUS(const RawAddress& bd_addr, uint16_t psm, bool is_originator, tBTM_SEC_CALLBACK* p_callback, void* p_ref_data)> body{[](const RawAddress& /* bd_addr */, uint16_t /* psm */, bool /* is_originator */, tBTM_SEC_CALLBACK* /* p_callback */, void* /* p_ref_data */) { return return_value; }}; tL2CAP_LE_RESULT_CODE operator()(const RawAddress& bd_addr, uint16_t psm, bool is_originator, tBTM_SEC_CALLBACK* p_callback, tBTM_STATUS operator()(const RawAddress& bd_addr, uint16_t psm, bool is_originator, tBTM_SEC_CALLBACK* p_callback, void* p_ref_data) { return body(bd_addr, psm, is_originator, p_callback, p_ref_data); }; Loading