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

Commit 18b46ca5 authored by Martin Brabham's avatar Martin Brabham
Browse files

Security: Flatten callouts intp sp_cback

Bug: 162984360
Tag: #refactor
Test: compiles and devices pair and work
Change-Id: I1954b560fada4d38c719b747d5a3ca08f1712f59
parent 772d999c
Loading
Loading
Loading
Loading
+23 −9
Original line number Diff line number Diff line
@@ -35,9 +35,11 @@
#include "bt_types.h"
#include "bta_api.h"
#include "bta_dm_api.h"
#include "bta_dm_ci.h"
#include "bta_dm_co.h"
#include "bta_dm_int.h"
#include "bta_sys.h"
#include "btif_dm.h"
#include "btif_storage.h"
#include "btm_api.h"
#include "btm_int.h"
@@ -2380,12 +2382,14 @@ static uint8_t bta_dm_sp_cback(tBTM_SP_EVT event, tBTM_SP_EVT_DATA* p_data) {
  APPL_TRACE_EVENT("bta_dm_sp_cback: %d", event);
  if (!bta_dm_cb.p_sec_cback) return BTM_NOT_AUTHORIZED;

  bool sp_rmt_result = false;
  /* TODO_SP */
  switch (event) {
    case BTM_SP_IO_REQ_EVT:
      if (btm_local_io_caps != BTM_IO_CAP_NONE) {
        /* translate auth_req */
        bta_dm_co_io_req(p_data->io_req.bd_addr, &p_data->io_req.io_cap,
        btif_dm_set_oob_for_io_req(&p_data->io_req.oob_data);
        btif_dm_proc_io_req(p_data->io_req.bd_addr, &p_data->io_req.io_cap,
                            &p_data->io_req.oob_data, &p_data->io_req.auth_req,
                            p_data->io_req.is_orig);
      }
@@ -2394,7 +2398,7 @@ static uint8_t bta_dm_sp_cback(tBTM_SP_EVT event, tBTM_SP_EVT_DATA* p_data) {
      break;
    case BTM_SP_IO_RSP_EVT:
      if (btm_local_io_caps != BTM_IO_CAP_NONE) {
        bta_dm_co_io_rsp(p_data->io_rsp.bd_addr, p_data->io_rsp.io_cap,
        btif_dm_proc_io_rsp(p_data->io_rsp.bd_addr, p_data->io_rsp.io_cap,
                            p_data->io_rsp.oob_data, p_data->io_rsp.auth_req);
      }
      break;
@@ -2482,13 +2486,23 @@ static uint8_t bta_dm_sp_cback(tBTM_SP_EVT event, tBTM_SP_EVT_DATA* p_data) {
      break;

    case BTM_SP_LOC_OOB_EVT:
      bta_dm_co_loc_oob((bool)(p_data->loc_oob.status == BTM_SUCCESS),
#ifdef BTIF_DM_OOB_TEST
      btif_dm_proc_loc_oob((bool)(p_data->loc_oob.status == BTM_SUCCESS),
                           p_data->loc_oob.c, p_data->loc_oob.r);
#endif
      break;

    case BTM_SP_RMT_OOB_EVT:
      bta_dm_co_rmt_oob(p_data->rmt_oob.bd_addr);
    case BTM_SP_RMT_OOB_EVT: {
      Octet16 c;
      Octet16 r;
      sp_rmt_result = false;
#ifdef BTIF_DM_OOB_TEST
      sp_rmt_result = btif_dm_proc_rmt_oob(p_data->rmt_oob.bd_addr, &c, &r);
#endif
      BTIF_TRACE_DEBUG("bta_dm_co_rmt_oob: result=%d", sp_rmt_result);
      bta_dm_ci_rmt_oob(sp_rmt_result, p_data->rmt_oob.bd_addr, c, r);
      break;
    }

    default:
      status = BTM_NOT_AUTHORIZED;
+0 −97
Original line number Diff line number Diff line
@@ -57,103 +57,6 @@ bool bta_dm_co_get_compress_memory(UNUSED_ATTR tBTA_SYS_ID id,
  return true;
}

/*******************************************************************************
 *
 * Function         bta_dm_co_io_req
 *
 * Description      This callout function is executed by DM to get IO
 *                  capabilities of the local device for the Simple Pairing
 *                  process.
 *
 * Parameters       bd_addr  - The peer device
 *                  *p_io_cap - The local Input/Output capabilities
 *                  *p_oob_data - true, if OOB data is available for the peer
 *                                device.
 *                  *p_auth_req - true, if MITM protection is required.
 *
 * Returns          void.
 *
 ******************************************************************************/
void bta_dm_co_io_req(UNUSED_ATTR const RawAddress& bd_addr,
                      tBTM_IO_CAP* p_io_cap, tBTM_OOB_DATA* p_oob_data,
                      tBTM_AUTH_REQ* p_auth_req, bool is_orig) {
  btif_dm_set_oob_for_io_req(p_oob_data);
  btif_dm_proc_io_req(bd_addr, p_io_cap, p_oob_data, p_auth_req, is_orig);
  BTIF_TRACE_DEBUG("bta_dm_co_io_req *p_oob_data = %d", *p_oob_data);
  BTIF_TRACE_DEBUG("bta_dm_co_io_req *p_io_cap = %d", *p_io_cap);
  BTIF_TRACE_DEBUG("bta_dm_co_io_req *p_auth_req = %d", *p_auth_req);
  BTIF_TRACE_DEBUG("bta_dm_co_io_req is_orig = %d", is_orig);
}

/*******************************************************************************
 *
 * Function         bta_dm_co_io_rsp
 *
 * Description      This callout function is executed by DM to report IO
 *                  capabilities of the peer device for the Simple Pairing
 *                  process.
 *
 * Parameters       bd_addr  - The peer device
 *                  io_cap - The remote Input/Output capabilities
 *                  oob_data - true, if OOB data is available for the peer
 *                             device.
 *                  auth_req - true, if MITM protection is required.
 *
 * Returns          void.
 *
 ******************************************************************************/
void bta_dm_co_io_rsp(const RawAddress& bd_addr, tBTM_IO_CAP io_cap,
                      tBTM_OOB_DATA oob_data, tBTM_AUTH_REQ auth_req) {
  btif_dm_proc_io_rsp(bd_addr, io_cap, oob_data, auth_req);
}

/*******************************************************************************
 *
 * Function         bta_dm_co_loc_oob
 *
 * Description      This callout function is executed by DM to report the OOB
 *                  data of the local device for the Simple Pairing process
 *
 * Parameters       valid - true, if the local OOB data is retrieved from LM
 *                  c     - Simple Pairing Hash C
 *                  r     - Simple Pairing Randomnizer R
 *
 * Returns          void.
 *
 ******************************************************************************/
void bta_dm_co_loc_oob(bool valid, const Octet16& c, const Octet16& r) {
  BTIF_TRACE_DEBUG("bta_dm_co_loc_oob, valid = %d", valid);
#ifdef BTIF_DM_OOB_TEST
  btif_dm_proc_loc_oob(valid, c, r);
#endif
}

/*******************************************************************************
 *
 * Function         bta_dm_co_rmt_oob
 *
 * Description      This callout function is executed by DM to request the OOB
 *                  data for the remote device for the Simple Pairing process
 *                  Need to call bta_dm_ci_rmt_oob() in response
 *
 * Parameters       bd_addr  - The peer device
 *
 * Returns          void.
 *
 ******************************************************************************/
void bta_dm_co_rmt_oob(const RawAddress& bd_addr) {
  Octet16 c;
  Octet16 r;
  bool result = false;

#ifdef BTIF_DM_OOB_TEST
  result = btif_dm_proc_rmt_oob(bd_addr, &c, &r);
#endif

  BTIF_TRACE_DEBUG("bta_dm_co_rmt_oob: result=%d", result);
  bta_dm_ci_rmt_oob(result, bd_addr, c, r);
}

/*******************************************************************************
 *
 * Function         bta_dm_co_le_io_key_req