Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8c491c77 authored by Grzegorz Kołodziejczyk's avatar Grzegorz Kołodziejczyk
Browse files

smp: Add SIRK verification callback

Don't bond with not valid CSIS devices if device was presented as member
of group by using matching RSI.

This part extends SMP module and related with callback to SIRK for
verification of potential members.

Tag: #feature
Bug: 278514112
Test: atest bluetooth_csis_test
Change-Id: If67b829b8dd1e5e4d2a9de08df92cff45b5c27f9
parent 90d88342
Loading
Loading
Loading
Loading
+42 −1
Original line number Diff line number Diff line
@@ -138,6 +138,7 @@ static uint8_t bta_dm_ble_smp_cback(tBTM_LE_EVT event, const RawAddress& bda,
                                    tBTM_LE_EVT_DATA* p_data);
static void bta_dm_ble_id_key_cback(uint8_t key_type,
                                    tBTM_BLE_LOCAL_KEYS* p_key);
static uint8_t bta_dm_sirk_verifiction_cback(const RawAddress& bd_addr);
static void bta_dm_gattc_register(void);
static void btm_dm_start_gatt_discovery(const RawAddress& bd_addr);
static void bta_dm_gattc_callback(tBTA_GATTC_EVT event, tBTA_GATTC* p_data);
@@ -349,7 +350,8 @@ const tBTM_APPL_INFO bta_security = {
    .p_bond_cancel_cmpl_callback = &bta_dm_bond_cancel_complete_cback,
    .p_sp_callback = &bta_dm_sp_cback,
    .p_le_callback = &bta_dm_ble_smp_cback,
    .p_le_key_callback = &bta_dm_ble_id_key_cback};
    .p_le_key_callback = &bta_dm_ble_id_key_cback,
    .p_sirk_verification_callback = &bta_dm_sirk_verifiction_cback};

#define MAX_DISC_RAW_DATA_BUF (4096)
uint8_t g_disc_raw_data_buf[MAX_DISC_RAW_DATA_BUF];
@@ -367,6 +369,20 @@ void bta_dm_enable(tBTA_DM_SEC_CBACK* p_sec_cback) {
  btm_local_io_caps = btif_storage_get_local_io_caps();
}

void bta_dm_ble_sirk_sec_cb_register(tBTA_DM_SEC_CBACK* p_cback) {
  /* Save the callback to be called when a request of member validation will be
   * needed. */
  LOG_DEBUG("");
  bta_dm_cb.p_sec_sirk_cback = p_cback;
}

void bta_dm_ble_sirk_confirm_device_reply(const RawAddress& bd_addr,
                                          bool accept) {
  LOG_DEBUG("");
  get_btm_client_interface().security.BTM_BleSirkConfirmDeviceReply(
      bd_addr, accept ? BTM_SUCCESS : BTM_NOT_AUTHORIZED);
}

void bta_dm_search_set_state(tBTA_DM_STATE state) {
  bta_dm_search_cb.state = state;
}
@@ -4021,6 +4037,31 @@ static void bta_dm_ble_id_key_cback(uint8_t key_type,
  return;
}

/*******************************************************************************
 *
 * Function         bta_dm_sirk_verifiction_cback
 *
 * Description      SIRK verification when pairing CSIP set member.
 *
 * Returns          void
 *
 ******************************************************************************/
static uint8_t bta_dm_sirk_verifiction_cback(const RawAddress& bd_addr) {
  tBTA_DM_SEC sec_event = {.ble_req = {
                               .bd_addr = bd_addr,
                           }};

  if (bta_dm_cb.p_sec_sirk_cback) {
    LOG_DEBUG("callback called");
    bta_dm_cb.p_sec_sirk_cback(BTA_DM_SIRK_VERIFICATION_REQ_EVT, &sec_event);
    return BTM_CMD_STARTED;
  }

  LOG_DEBUG("no callback registered");

  return BTM_SUCCESS_NO_SECURITY;
}

/*******************************************************************************
 *
 * Function         bta_dm_add_blekey
+37 −0
Original line number Diff line number Diff line
@@ -798,6 +798,43 @@ void BTA_DmBleSubrateRequest(const RawAddress& bd_addr, uint16_t subrate_min,
                               subrate_max, max_latency, cont_num, timeout));
}

/*******************************************************************************
 *
 * Function         BTA_DmSirkSecCbRegister
 *
 * Description      This procedure registeres in requested a callback for
 *                  verification by CSIP potential set member.
 *
 * Parameters       p_cback     - callback to member verificator
 *
 * Returns          void
 *
 ******************************************************************************/
void BTA_DmSirkSecCbRegister(tBTA_DM_SEC_CBACK* p_cback) {
  LOG_DEBUG("");
  do_in_main_thread(FROM_HERE,
                    base::Bind(bta_dm_ble_sirk_sec_cb_register, p_cback));
}

/*******************************************************************************
 *
 * Function         BTA_DmSirkConfirmDeviceReply
 *
 * Description      This procedure confirms requested to validate set device.
 *
 * Parameters       bd_addr     - BD address of the peer
 *                  accept      - True if device is authorized by CSIP, false
 *                                otherwise.
 *
 * Returns          void
 *
 ******************************************************************************/
void BTA_DmSirkConfirmDeviceReply(const RawAddress& bd_addr, bool accept) {
  LOG_DEBUG("");
  do_in_main_thread(FROM_HERE, base::Bind(bta_dm_ble_sirk_confirm_device_reply,
                                          bd_addr, accept));
}

bool BTA_DmCheckLeAudioCapable(const RawAddress& address) {
  for (tBTM_INQ_INFO* inq_ent = BTM_InqDbFirst(); inq_ent != nullptr;
       inq_ent = BTM_InqDbNext(inq_ent)) {
+4 −0
Original line number Diff line number Diff line
@@ -332,6 +332,7 @@ extern tBTA_DM_CONNECTED_SRVCS bta_dm_conn_srvcs;
typedef struct {
  tBTA_DM_ACTIVE_LINK device_list;
  tBTA_DM_SEC_CBACK* p_sec_cback;
  tBTA_DM_SEC_CBACK* p_sec_sirk_cback;
  tBTA_BLE_ENERGY_INFO_CBACK* p_energy_info_cback;
  bool disabling;
  alarm_t* disable_timer;
@@ -510,6 +511,9 @@ void bta_dm_enable(tBTA_DM_SEC_CBACK*);
void bta_dm_disable();
void bta_dm_init_cb(void);
void bta_dm_deinit_cb(void);
void bta_dm_ble_sirk_sec_cb_register(tBTA_DM_SEC_CBACK*);
void bta_dm_ble_sirk_confirm_device_reply(const RawAddress& bd_addr,
                                          bool accept);
void bta_dm_set_dev_name(const std::vector<uint8_t>&);
void bta_dm_set_visibility(tBTA_DM_DISC, tBTA_DM_CONN);
void bta_dm_set_scan_config(tBTA_DM_MSG* p_data);
+30 −0
Original line number Diff line number Diff line
@@ -249,6 +249,7 @@ typedef enum : uint8_t {
  BTA_DM_REPORT_BONDING_EVT = 32,    /*handle for pin or key missing*/
  BTA_DM_LE_ADDR_ASSOC_EVT = 33,     /* identity address association event */
  BTA_DM_LINK_UP_FAILED_EVT = 34,    /* Create connection failed event */
  BTA_DM_SIRK_VERIFICATION_REQ_EVT = 35,
} tBTA_DM_SEC_EVT;

/* Structure associated with BTA_DM_PIN_REQ_EVT */
@@ -1181,6 +1182,35 @@ void BTA_DmBleScan(bool start, uint8_t duration, bool low_latency_scan = false);
 ******************************************************************************/
void BTA_DmBleCsisObserve(bool observe, tBTA_DM_SEARCH_CBACK* p_results_cb);

/*******************************************************************************
 *
 * Function         BTA_DmSirkSecCbRegister
 *
 * Description      This procedure registeres in requested a callback for
 *                  verification by CSIS potential set member.
 *
 * Parameters       p_cback     - callback to member verificator
 *
 * Returns          void
 *
 ******************************************************************************/
void BTA_DmSirkSecCbRegister(tBTA_DM_SEC_CBACK* p_cback);

/*******************************************************************************
 *
 * Function         BTA_DmSirkConfirmDeviceReply
 *
 * Description      This procedure confirms requested to validate set device.
 *
 * Parameters       bd_addr     - BD address of the peer
 *                  accept      - True if device is authorized by CSIS, false
 *                                otherwise.
 *
 * Returns          void
 *
 ******************************************************************************/
void BTA_DmSirkConfirmDeviceReply(const RawAddress& bd_addr, bool accept);

/*******************************************************************************
 *
 * Function         BTA_DmBleConfigLocalPrivacy
+10 −0
Original line number Diff line number Diff line
@@ -32,3 +32,13 @@ void BTA_DmBleCsisObserve(bool observe, tBTA_DM_SEARCH_CBACK* p_results_cb) {
  LOG_ASSERT(dm_interface) << "Mock BTA DM interface not set!";
  return dm_interface->BTA_DmBleCsisObserve(observe, p_results_cb);
}

void BTA_DmSirkSecCbRegister(tBTA_DM_SEC_CBACK* p_cback) {
  LOG_ASSERT(dm_interface) << "Mock BTA DM interface not set!";
  return dm_interface->BTA_DmSirkSecCbRegister(p_cback);
}

void BTA_DmSirkConfirmDeviceReply(const RawAddress& bd_addr, bool accept) {
  LOG_ASSERT(dm_interface) << "Mock BTA DM interface not set!";
  return dm_interface->BTA_DmSirkConfirmDeviceReply(bd_addr, accept);
}
Loading