Skip to content

Commit

Permalink
Merge "OOB: generateLocalOobdata()"
Browse files Browse the repository at this point in the history
  • Loading branch information
goptedoblivion authored and Gerrit Code Review committed Apr 29, 2021
2 parents d348c92 + 643da61 commit 89d078c
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 23 deletions.
3 changes: 2 additions & 1 deletion bta/dm/bta_dm_act.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2220,7 +2220,8 @@ static tBTM_STATUS bta_dm_sp_cback(tBTM_SP_EVT event,

case BTM_SP_LOC_OOB_EVT:
#ifdef BTIF_DM_OOB_TEST
btif_dm_proc_loc_oob((bool)(p_data->loc_oob.status == BTM_SUCCESS),
btif_dm_proc_loc_oob(BT_TRANSPORT_BR_EDR,
(bool)(p_data->loc_oob.status == BTM_SUCCESS),
p_data->loc_oob.c, p_data->loc_oob.r);
#endif
break;
Expand Down
4 changes: 3 additions & 1 deletion bta/test/common/mock_btif_dm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ extern std::map<std::string, int> mock_function_count_map;
#include "bta/include/bta_api.h"
#include "include/hardware/bluetooth.h"
#include "internal_include/bte_appl.h"
#include "types/bt_transport.h"
#include "types/raw_address.h"

struct uid_set_t;
Expand Down Expand Up @@ -168,6 +169,7 @@ bool btif_dm_proc_rmt_oob(const RawAddress& bd_addr, Octet16* p_c,
return false;
}

void btif_dm_proc_loc_oob(bool valid, const Octet16& c, const Octet16& r) {
void btif_dm_proc_loc_oob(tBT_TRANSPORT transport, bool is_valid,
const Octet16& c, const Octet16& r) {
mock_function_count_map[__func__]++;
}
3 changes: 2 additions & 1 deletion btif/include/btif_dm.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ void btif_dm_set_oob_for_le_io_req(const RawAddress& bd_addr,
tBTM_LE_AUTH_REQ* p_auth_req);
#ifdef BTIF_DM_OOB_TEST
void btif_dm_load_local_oob(void);
void btif_dm_proc_loc_oob(bool valid, const Octet16& c, const Octet16& r);
void btif_dm_proc_loc_oob(tBT_TRANSPORT transport, bool is_valid,
const Octet16& c, const Octet16& r);
bool btif_dm_proc_rmt_oob(const RawAddress& bd_addr, Octet16* p_c,
Octet16* p_r);
void btif_dm_generate_local_oob_data(tBT_TRANSPORT transport);
Expand Down
10 changes: 5 additions & 5 deletions btif/src/btif_dm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2273,17 +2273,17 @@ void btif_dm_load_local_oob(void) {
*
******************************************************************************/
void btif_dm_generate_local_oob_data(tBT_TRANSPORT transport) {
LOG_DEBUG("Transport %s", bt_transport_text(transport).c_str());
if (transport == BT_TRANSPORT_BR_EDR) {
BTM_ReadLocalOobData();
} else if (transport == BT_TRANSPORT_LE) {
// TODO(184377951): Call LE Implementation (not yet implemented?)
} else {
BTIF_TRACE_ERROR("Bad transport type! %d", transport);
SMP_CrLocScOobData(base::BindOnce(&btif_dm_proc_loc_oob));
}
}

void btif_dm_proc_loc_oob(bool valid, const Octet16& c, const Octet16& r) {
invoke_oob_data_request_cb(BT_TRANSPORT_BR_EDR, valid, c, r);
void btif_dm_proc_loc_oob(tBT_TRANSPORT transport, bool is_valid,
const Octet16& c, const Octet16& r) {
invoke_oob_data_request_cb(transport, is_valid, c, r);
}

/*******************************************************************************
Expand Down
7 changes: 0 additions & 7 deletions include/hardware/bluetooth.h
Original file line number Diff line number Diff line change
Expand Up @@ -355,13 +355,6 @@ typedef struct {
uint8_t le_appearance[2]; /* For the appearance of the device */
} bt_oob_data_t;

/** Bundle that can contain 1 or both of P192 and P256 */
// typedef struct {
// uint8_t address[7]; /* Bluetooth Device Address (6) plus Address Type
// (1) */ bt_oob_data_t p192_data; /* P192 Data or NULL */ bt_oob_data_t
// p256_data; /* P256 Data or NULL */
//} bt_oob_data_bundle_t;

/** Bluetooth Device Type */
typedef enum {
BT_DEVICE_DEVTYPE_BREDR = 0x1,
Expand Down
17 changes: 17 additions & 0 deletions stack/include/smp_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include "bt_target.h"
#include "smp_api_types.h"
#include "types/bt_transport.h"

/*****************************************************************************
* External Function Declarations
Expand Down Expand Up @@ -174,6 +175,22 @@ extern void SMP_OobDataReply(const RawAddress& bd_addr, tSMP_STATUS res,
******************************************************************************/
extern void SMP_SecureConnectionOobDataReply(uint8_t* p_data);

/*******************************************************************************
*
* Function SMP_CrLocScOobData
*
* Description This function is called to generate a public key to be
* passed to a remote device via an Out of Band transport
*
* Parameters: callback - receive the data
*
******************************************************************************/
extern void SMP_CrLocScOobData(
base::OnceCallback<void(tBT_TRANSPORT, bool,
const std::array<unsigned char, 16>&,
const std::array<unsigned char, 16>&)>
callback);

// Called when LTK request is received from controller.
extern bool smp_proc_ltk_request(const RawAddress& bda);

Expand Down
24 changes: 21 additions & 3 deletions stack/smp/smp_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -498,9 +498,6 @@ void SMP_OobDataReply(const RawAddress& bd_addr, tSMP_STATUS res, uint8_t len,
*
******************************************************************************/
void SMP_SecureConnectionOobDataReply(uint8_t* p_data) {
LOG_ASSERT(!bluetooth::shim::is_gd_shim_enabled())
<< "Legacy SMP API should not be invoked when GD Security is used";

tSMP_CB* p_cb = &smp_cb;

tSMP_SC_OOB_DATA* p_oob = (tSMP_SC_OOB_DATA*)p_data;
Expand Down Expand Up @@ -552,3 +549,24 @@ void SMP_SecureConnectionOobDataReply(uint8_t* p_data) {
smp_int_data.p_data = p_data;
smp_sm_event(&smp_cb, SMP_SC_OOB_DATA_EVT, &smp_int_data);
}

/*******************************************************************************
*
* Function SMP_CrLocScOobData
*
* Description This function is called to generate a public key to be
* passed to a remote device via Out of Band transport
*
* Parameters: callback - receive the data
*
******************************************************************************/
void SMP_CrLocScOobData(
base::OnceCallback<void(tBT_TRANSPORT, bool,
const std::array<unsigned char, 16>&,
const std::array<unsigned char, 16>&)>
callback) {
smp_cb.selected_association_model = SMP_MODEL_SEC_CONN_OOB;
smp_calculate_local_commitment(&smp_cb);
std::move(callback).Run(BT_TRANSPORT_LE, true, smp_cb.commitment,
smp_cb.local_random);
}
7 changes: 3 additions & 4 deletions stack/smp/smp_keys.cc
Original file line number Diff line number Diff line change
Expand Up @@ -614,19 +614,18 @@ void smp_create_private_key(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) {
*
******************************************************************************/
void smp_use_oob_private_key(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) {
SMP_TRACE_DEBUG("%s req_oob_type: %d, role: %d", __func__, p_cb->req_oob_type,
p_cb->role);
LOG_INFO("req_oob_type: %d, role: %d", p_cb->req_oob_type, p_cb->role);

switch (p_cb->req_oob_type) {
case SMP_OOB_BOTH:
case SMP_OOB_LOCAL:
SMP_TRACE_DEBUG("%s restore secret key", __func__)
LOG_INFO("restore secret key");
memcpy(p_cb->private_key, p_cb->sc_oob_data.loc_oob_data.private_key_used,
BT_OCTET32_LEN);
smp_process_private_key(p_cb);
break;
default:
SMP_TRACE_DEBUG("%s create secret key anew", __func__);
LOG_INFO("create secret key anew");
smp_set_state(SMP_STATE_PAIR_REQ_RSP);
smp_decide_association_model(p_cb, NULL);
break;
Expand Down
6 changes: 6 additions & 0 deletions stack/test/common/mock_btif_dm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ extern std::map<std::string, int> mock_function_count_map;
#include <cstdint>
#include "bta/include/bta_api.h"
#include "include/hardware/bluetooth.h"
#include "types/bt_transport.h"
#include "types/raw_address.h"

struct uid_set_t;
Expand Down Expand Up @@ -155,3 +156,8 @@ void btif_dm_update_ble_remote_properties(const RawAddress& bd_addr,
tBT_DEVICE_TYPE dev_type) {
mock_function_count_map[__func__]++;
}

void btif_dm_proc_loc_oob(tBT_TRANSPORT transport, bool is_valid,
const Octet16& c, const Octet16& r) {
mock_function_count_map[__func__]++;
}
8 changes: 8 additions & 0 deletions stack/test/common/mock_smp_smp_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,11 @@ void SMP_SecureConnectionOobDataReply(uint8_t* p_data) {
void SMP_SecurityGrant(const RawAddress& bd_addr, tSMP_STATUS res) {
mock_function_count_map[__func__]++;
}

void SMP_CrLocScOobData(
base::OnceCallback<void(tBT_TRANSPORT, bool,
const std::array<unsigned char, 16>&,
const std::array<unsigned char, 16>&)>
callback) {
mock_function_count_map[__func__]++;
}
4 changes: 3 additions & 1 deletion test/mock/mock_btif_dm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ extern std::map<std::string, int> mock_function_count_map;
#include "bta/include/bta_api.h"
#include "include/hardware/bluetooth.h"
#include "internal_include/bte_appl.h"
#include "types/bt_transport.h"
#include "types/raw_address.h"

struct uid_set_t;
Expand Down Expand Up @@ -168,6 +169,7 @@ bool btif_dm_proc_rmt_oob(const RawAddress& bd_addr, Octet16* p_c,
return false;
}

void btif_dm_proc_loc_oob(const Octet16& c, const Octet16& r) {
void btif_dm_proc_loc_oob(tBT_TRANSPORT transport, bool is_valid,
const Octet16& c, const Octet16& r) {
mock_function_count_map[__func__]++;
}
8 changes: 8 additions & 0 deletions test/mock/mock_stack_smp_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,11 @@ void SMP_SecureConnectionOobDataReply(uint8_t* p_data) {
void SMP_SecurityGrant(const RawAddress& bd_addr, tSMP_STATUS res) {
mock_function_count_map[__func__]++;
}

void SMP_CrLocScOobData(
base::OnceCallback<void(tBT_TRANSPORT, bool,
const std::array<unsigned char, 16>&,
const std::array<unsigned char, 16>&)>
callback) {
mock_function_count_map[__func__]++;
}

0 comments on commit 89d078c

Please sign in to comment.