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

Commit b5619fbc authored by Hui Peng's avatar Hui Peng
Browse files

[Invisalign2] cleanup logging statements in smp

Bug: 301661850
Test: mma packages/modules/Bluetooth
Change-Id: I9aded612db7ce31b9868da7c2cbf3544a5f361d4
parent 4b5f1bce
Loading
Loading
Loading
Loading
+122 −138

File changed.

Preview size limit exceeded, changes collapsed.

+32 −36
Original line number Original line Diff line number Diff line
@@ -54,7 +54,7 @@ void SMP_Init(uint8_t init_security_mode) {
  smp_cb.smp_rsp_timer_ent = alarm_new("smp.smp_rsp_timer_ent");
  smp_cb.smp_rsp_timer_ent = alarm_new("smp.smp_rsp_timer_ent");
  smp_cb.delayed_auth_timer_ent = alarm_new("smp.delayed_auth_timer_ent");
  smp_cb.delayed_auth_timer_ent = alarm_new("smp.delayed_auth_timer_ent");


  LOG_VERBOSE("%s", __func__);
  LOG_VERBOSE("init_security_mode:%d", init_security_mode);


  smp_l2cap_if_init();
  smp_l2cap_if_init();
  /* initialization of P-256 parameters */
  /* initialization of P-256 parameters */
@@ -64,8 +64,7 @@ void SMP_Init(uint8_t init_security_mode) {
  smp_cb.cert_failure = static_cast<tSMP_STATUS>(
  smp_cb.cert_failure = static_cast<tSMP_STATUS>(
      stack_config_get_interface()->get_pts_smp_failure_case());
      stack_config_get_interface()->get_pts_smp_failure_case());
  if (smp_cb.cert_failure)
  if (smp_cb.cert_failure)
    LOG_ERROR("%s PTS FAILURE MODE IN EFFECT (CASE %d)", __func__,
    LOG_ERROR("PTS FAILURE MODE IN EFFECT (CASE %d)", smp_cb.cert_failure);
              smp_cb.cert_failure);
}
}


/*******************************************************************************
/*******************************************************************************
@@ -78,10 +77,10 @@ void SMP_Init(uint8_t init_security_mode) {
 *
 *
 ******************************************************************************/
 ******************************************************************************/
bool SMP_Register(tSMP_CALLBACK* p_cback) {
bool SMP_Register(tSMP_CALLBACK* p_cback) {
  LOG_VERBOSE("SMP_Register state=%d", smp_cb.state);
  LOG_VERBOSE("state=%d", smp_cb.state);


  if (smp_cb.p_callback != NULL) {
  if (smp_cb.p_callback != NULL) {
    LOG_ERROR("SMP_Register: duplicate registration, overwrite it");
    LOG_ERROR("duplicate registration, overwrite it");
  }
  }
  smp_cb.p_callback = p_cback;
  smp_cb.p_callback = p_cback;


@@ -103,9 +102,8 @@ bool SMP_Register(tSMP_CALLBACK* p_cback) {
tSMP_STATUS SMP_Pair(const RawAddress& bd_addr, tBLE_ADDR_TYPE addr_type) {
tSMP_STATUS SMP_Pair(const RawAddress& bd_addr, tBLE_ADDR_TYPE addr_type) {
  tSMP_CB* p_cb = &smp_cb;
  tSMP_CB* p_cb = &smp_cb;


  LOG_VERBOSE("%s: state=%d br_state=%d flag=0x%x, bd_addr=%s", __func__,
  LOG_VERBOSE("state=%d br_state=%d flag=0x%x, bd_addr=%s", p_cb->state,
              p_cb->state, p_cb->br_state, p_cb->flags,
              p_cb->br_state, p_cb->flags, ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
              ADDRESS_TO_LOGGABLE_CSTR(bd_addr));


  if (p_cb->state != SMP_STATE_IDLE ||
  if (p_cb->state != SMP_STATE_IDLE ||
      p_cb->flags & SMP_PAIR_FLAGS_WE_STARTED_DD || p_cb->smp_over_br) {
      p_cb->flags & SMP_PAIR_FLAGS_WE_STARTED_DD || p_cb->smp_over_br) {
@@ -123,7 +121,7 @@ tSMP_STATUS SMP_Pair(const RawAddress& bd_addr, tBLE_ADDR_TYPE addr_type) {
      tSMP_INT_DATA smp_int_data;
      tSMP_INT_DATA smp_int_data;
      smp_int_data.status = SMP_PAIR_INTERNAL_ERR;
      smp_int_data.status = SMP_PAIR_INTERNAL_ERR;
      p_cb->status = SMP_PAIR_INTERNAL_ERR;
      p_cb->status = SMP_PAIR_INTERNAL_ERR;
      LOG_ERROR("%s: L2C connect fixed channel failed.", __func__);
      LOG_ERROR("L2C connect fixed channel failed.");
      smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &smp_int_data);
      smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &smp_int_data);
      return SMP_PAIR_INTERNAL_ERR;
      return SMP_PAIR_INTERNAL_ERR;
    }
    }
@@ -152,9 +150,8 @@ tSMP_STATUS SMP_Pair(const RawAddress& bd_addr) {
tSMP_STATUS SMP_BR_PairWith(const RawAddress& bd_addr) {
tSMP_STATUS SMP_BR_PairWith(const RawAddress& bd_addr) {
  tSMP_CB* p_cb = &smp_cb;
  tSMP_CB* p_cb = &smp_cb;


  LOG_VERBOSE("%s: state=%d br_state=%d flag=0x%x, bd_addr=%s", __func__,
  LOG_VERBOSE("state=%d br_state=%d flag=0x%x, bd_addr=%s", p_cb->state,
              p_cb->state, p_cb->br_state, p_cb->flags,
              p_cb->br_state, p_cb->flags, ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
              ADDRESS_TO_LOGGABLE_CSTR(bd_addr));


  if (p_cb->state != SMP_STATE_IDLE || p_cb->smp_over_br ||
  if (p_cb->state != SMP_STATE_IDLE || p_cb->smp_over_br ||
      p_cb->flags & SMP_PAIR_FLAGS_WE_STARTED_DD) {
      p_cb->flags & SMP_PAIR_FLAGS_WE_STARTED_DD) {
@@ -168,7 +165,7 @@ tSMP_STATUS SMP_BR_PairWith(const RawAddress& bd_addr) {
  p_cb->pairing_bda = bd_addr;
  p_cb->pairing_bda = bd_addr;


  if (!L2CA_ConnectFixedChnl(L2CAP_SMP_BR_CID, bd_addr)) {
  if (!L2CA_ConnectFixedChnl(L2CAP_SMP_BR_CID, bd_addr)) {
    LOG_ERROR("%s: L2C connect fixed channel failed.", __func__);
    LOG_ERROR("L2C connect fixed channel failed.");
    tSMP_INT_DATA smp_int_data;
    tSMP_INT_DATA smp_int_data;
    smp_int_data.status = SMP_PAIR_INTERNAL_ERR;
    smp_int_data.status = SMP_PAIR_INTERNAL_ERR;
    p_cb->status = SMP_PAIR_INTERNAL_ERR;
    p_cb->status = SMP_PAIR_INTERNAL_ERR;
@@ -193,10 +190,10 @@ tSMP_STATUS SMP_BR_PairWith(const RawAddress& bd_addr) {
bool SMP_PairCancel(const RawAddress& bd_addr) {
bool SMP_PairCancel(const RawAddress& bd_addr) {
  tSMP_CB* p_cb = &smp_cb;
  tSMP_CB* p_cb = &smp_cb;


  LOG_VERBOSE("SMP_CancelPair state=%d flag=0x%x ", p_cb->state, p_cb->flags);
  LOG_VERBOSE("state=%d flag=0x%x ", p_cb->state, p_cb->flags);
  if (p_cb->state != SMP_STATE_IDLE && p_cb->pairing_bda == bd_addr) {
  if (p_cb->state != SMP_STATE_IDLE && p_cb->pairing_bda == bd_addr) {
    p_cb->is_pair_cancel = true;
    p_cb->is_pair_cancel = true;
    LOG_VERBOSE("Cancel Pairing: set fail reason Unknown");
    LOG_VERBOSE("set fail reason Unknown");
    tSMP_INT_DATA smp_int_data;
    tSMP_INT_DATA smp_int_data;
    smp_int_data.status = SMP_PAIR_FAIL_UNKNOWN;
    smp_int_data.status = SMP_PAIR_FAIL_UNKNOWN;
    smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &smp_int_data);
    smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &smp_int_data);
@@ -220,7 +217,7 @@ bool SMP_PairCancel(const RawAddress& bd_addr) {
 *
 *
 ******************************************************************************/
 ******************************************************************************/
void SMP_SecurityGrant(const RawAddress& bd_addr, tSMP_STATUS res) {
void SMP_SecurityGrant(const RawAddress& bd_addr, tSMP_STATUS res) {
  LOG_VERBOSE("SMP_SecurityGrant ");
  LOG_VERBOSE("addr:%s", ADDRESS_TO_LOGGABLE_CSTR(bd_addr));


  // If just showing consent dialog, send response
  // If just showing consent dialog, send response
  if (smp_cb.cb_evt == SMP_CONSENT_REQ_EVT) {
  if (smp_cb.cb_evt == SMP_CONSENT_REQ_EVT) {
@@ -229,7 +226,7 @@ void SMP_SecurityGrant(const RawAddress& bd_addr, tSMP_STATUS res) {
      if (res == SMP_SUCCESS) {
      if (res == SMP_SUCCESS) {
        smp_sm_event(&smp_cb, SMP_SC_NC_OK_EVT, NULL);
        smp_sm_event(&smp_cb, SMP_SC_NC_OK_EVT, NULL);
      } else {
      } else {
        LOG_WARN("%s() - Consent dialog fails for JUSTWORKS", __func__);
        LOG_WARN("Consent dialog fails for JUSTWORKS");
        /* send pairing failure */
        /* send pairing failure */
        tSMP_INT_DATA smp_int_data;
        tSMP_INT_DATA smp_int_data;
        smp_int_data.status = SMP_NUMERIC_COMPAR_FAIL;
        smp_int_data.status = SMP_NUMERIC_COMPAR_FAIL;
@@ -248,7 +245,7 @@ void SMP_SecurityGrant(const RawAddress& bd_addr, tSMP_STATUS res) {
        smp_cb.tk = {0};
        smp_cb.tk = {0};
        smp_sm_event(&smp_cb, SMP_KEY_READY_EVT, &smp_int_data);
        smp_sm_event(&smp_cb, SMP_KEY_READY_EVT, &smp_int_data);
      } else {
      } else {
        LOG_WARN("%s() - Consent dialog fails for ENCRYPTION_ONLY", __func__);
        LOG_WARN("Consent dialog fails for ENCRYPTION_ONLY");
        /* send pairing failure */
        /* send pairing failure */
        tSMP_INT_DATA smp_int_data;
        tSMP_INT_DATA smp_int_data;
        smp_int_data.status = SMP_NUMERIC_COMPAR_FAIL;
        smp_int_data.status = SMP_NUMERIC_COMPAR_FAIL;
@@ -304,27 +301,26 @@ void SMP_PasskeyReply(const RawAddress& bd_addr, uint8_t res,
                      uint32_t passkey) {
                      uint32_t passkey) {
  tSMP_CB* p_cb = &smp_cb;
  tSMP_CB* p_cb = &smp_cb;


  LOG_VERBOSE("SMP_PasskeyReply: Key: %d  Result:%d", passkey, res);
  LOG_VERBOSE("Key:%d  Result:%d", passkey, res);


  /* If timeout already expired or has been canceled, ignore the reply */
  /* If timeout already expired or has been canceled, ignore the reply */
  if (p_cb->cb_evt != SMP_PASSKEY_REQ_EVT) {
  if (p_cb->cb_evt != SMP_PASSKEY_REQ_EVT) {
    LOG_WARN("SMP_PasskeyReply() - Wrong State: %d", p_cb->state);
    LOG_WARN("Wrong State:%d", p_cb->state);
    return;
    return;
  }
  }


  if (bd_addr != p_cb->pairing_bda) {
  if (bd_addr != p_cb->pairing_bda) {
    LOG_ERROR("SMP_PasskeyReply() - Wrong BD Addr");
    LOG_ERROR("Wrong BD Addr");
    return;
    return;
  }
  }


  if (btm_find_dev(bd_addr) == NULL) {
  if (btm_find_dev(bd_addr) == NULL) {
    LOG_ERROR("SMP_PasskeyReply() - no dev CB");
    LOG_ERROR("no dev CB");
    return;
    return;
  }
  }


  if (passkey > BTM_MAX_PASSKEY_VAL || res != SMP_SUCCESS) {
  if (passkey > BTM_MAX_PASSKEY_VAL || res != SMP_SUCCESS) {
    LOG_WARN("SMP_PasskeyReply() - Wrong key len: %d or passkey entry fail",
    LOG_WARN("Wrong key len:%d or passkey entry fail", passkey);
             passkey);
    /* send pairing failure */
    /* send pairing failure */
    tSMP_INT_DATA smp_int_data;
    tSMP_INT_DATA smp_int_data;
    smp_int_data.status = SMP_PASSKEY_ENTRY_FAIL;
    smp_int_data.status = SMP_PASSKEY_ENTRY_FAIL;
@@ -357,26 +353,26 @@ void SMP_PasskeyReply(const RawAddress& bd_addr, uint8_t res,
void SMP_ConfirmReply(const RawAddress& bd_addr, uint8_t res) {
void SMP_ConfirmReply(const RawAddress& bd_addr, uint8_t res) {
  tSMP_CB* p_cb = &smp_cb;
  tSMP_CB* p_cb = &smp_cb;


  LOG_VERBOSE("%s: Result:%d", __func__, res);
  LOG_VERBOSE("addr:%s, Result:%d", ADDRESS_TO_LOGGABLE_CSTR(bd_addr), res);


  /* If timeout already expired or has been canceled, ignore the reply */
  /* If timeout already expired or has been canceled, ignore the reply */
  if (p_cb->cb_evt != SMP_NC_REQ_EVT) {
  if (p_cb->cb_evt != SMP_NC_REQ_EVT) {
    LOG_WARN("%s() - Wrong State: %d", __func__, p_cb->state);
    LOG_WARN("Wrong State:%d", p_cb->state);
    return;
    return;
  }
  }


  if (bd_addr != p_cb->pairing_bda) {
  if (bd_addr != p_cb->pairing_bda) {
    LOG_ERROR("%s() - Wrong BD Addr", __func__);
    LOG_ERROR("Wrong BD Addr");
    return;
    return;
  }
  }


  if (btm_find_dev(bd_addr) == NULL) {
  if (btm_find_dev(bd_addr) == NULL) {
    LOG_ERROR("%s() - no dev CB", __func__);
    LOG_ERROR("no dev CB");
    return;
    return;
  }
  }


  if (res != SMP_SUCCESS) {
  if (res != SMP_SUCCESS) {
    LOG_WARN("%s() - Numeric Comparison fails", __func__);
    LOG_WARN("Numeric Comparison fails");
    /* send pairing failure */
    /* send pairing failure */
    tSMP_INT_DATA smp_int_data;
    tSMP_INT_DATA smp_int_data;
    smp_int_data.status = SMP_NUMERIC_COMPAR_FAIL;
    smp_int_data.status = SMP_NUMERIC_COMPAR_FAIL;
@@ -403,7 +399,7 @@ void SMP_OobDataReply(const RawAddress& bd_addr, tSMP_STATUS res, uint8_t len,
  tSMP_CB* p_cb = &smp_cb;
  tSMP_CB* p_cb = &smp_cb;
  tSMP_KEY key;
  tSMP_KEY key;


  LOG_VERBOSE("%s State: %d  res:%d", __func__, smp_cb.state, res);
  LOG_VERBOSE("State:%d  res:%d", smp_cb.state, res);


  /* If timeout already expired or has been canceled, ignore the reply */
  /* If timeout already expired or has been canceled, ignore the reply */
  if (p_cb->state != SMP_STATE_WAIT_APP_RSP || p_cb->cb_evt != SMP_OOB_REQ_EVT)
  if (p_cb->state != SMP_STATE_WAIT_APP_RSP || p_cb->cb_evt != SMP_OOB_REQ_EVT)
@@ -442,7 +438,7 @@ void SMP_SecureConnectionOobDataReply(uint8_t* p_data) {


  tSMP_SC_OOB_DATA* p_oob = (tSMP_SC_OOB_DATA*)p_data;
  tSMP_SC_OOB_DATA* p_oob = (tSMP_SC_OOB_DATA*)p_data;
  if (!p_oob) {
  if (!p_oob) {
    LOG_ERROR("%s received no data", __func__);
    LOG_ERROR("received no data");
    tSMP_INT_DATA smp_int_data;
    tSMP_INT_DATA smp_int_data;
    smp_int_data.status = SMP_OOB_FAIL;
    smp_int_data.status = SMP_OOB_FAIL;
    smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &smp_int_data);
    smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &smp_int_data);
@@ -450,9 +446,9 @@ void SMP_SecureConnectionOobDataReply(uint8_t* p_data) {
  }
  }


  LOG_VERBOSE(
  LOG_VERBOSE(
      "%s req_oob_type: %d, loc_oob_data.present: %d, "
      "req_oob_type:%d, loc_oob_data.present:%d, "
      "peer_oob_data.present:%d",
      "peer_oob_data.present:%d",
      __func__, p_cb->req_oob_type, p_oob->loc_oob_data.present,
      p_cb->req_oob_type, p_oob->loc_oob_data.present,
      p_oob->peer_oob_data.present);
      p_oob->peer_oob_data.present);


  if (p_cb->state != SMP_STATE_WAIT_APP_RSP ||
  if (p_cb->state != SMP_STATE_WAIT_APP_RSP ||
+7 −7
Original line number Original line Diff line number Diff line
@@ -251,7 +251,7 @@ void smp_set_br_state(tSMP_BR_STATE br_state) {
                smp_get_br_state_name(br_state), br_state);
                smp_get_br_state_name(br_state), br_state);
    smp_cb.br_state = br_state;
    smp_cb.br_state = br_state;
  } else {
  } else {
    LOG_VERBOSE("%s invalid br_state =%d", __func__, br_state);
    LOG_VERBOSE("invalid br_state=%d", br_state);
  }
  }
}
}


@@ -305,14 +305,14 @@ void smp_br_state_machine_event(tSMP_CB* p_cb, tSMP_BR_EVENT event,
  tSMP_BR_SM_TBL state_table;
  tSMP_BR_SM_TBL state_table;
  uint8_t action, entry;
  uint8_t action, entry;


  LOG_VERBOSE("main %s", __func__);
  LOG_VERBOSE("addr:%s", ADDRESS_TO_LOGGABLE_CSTR(p_cb->pairing_bda));
  if (curr_state >= SMP_BR_STATE_MAX) {
  if (curr_state >= SMP_BR_STATE_MAX) {
    LOG_VERBOSE("Invalid br_state: %d", curr_state);
    LOG_VERBOSE("Invalid br_state: %d", curr_state);
    return;
    return;
  }
  }


  if (p_cb->role > HCI_ROLE_PERIPHERAL) {
  if (p_cb->role > HCI_ROLE_PERIPHERAL) {
    LOG_ERROR("%s: invalid role %d", __func__, p_cb->role);
    LOG_ERROR("invalid role %d", p_cb->role);
    return;
    return;
  }
  }


+46 −57
Original line number Original line Diff line number Diff line
@@ -92,7 +92,7 @@ void smp_proc_passkey(tSMP_CB* p_cb, BT_OCTET8 rand) {
  uint32_t passkey; /* 19655 test number; */
  uint32_t passkey; /* 19655 test number; */
  uint8_t* pp = rand;
  uint8_t* pp = rand;


  LOG_VERBOSE("%s", __func__);
  LOG_VERBOSE("addr:%s", ADDRESS_TO_LOGGABLE_CSTR(p_cb->pairing_bda));
  STREAM_TO_UINT32(passkey, pp);
  STREAM_TO_UINT32(passkey, pp);
  passkey &= ~SMP_PASSKEY_MASK;
  passkey &= ~SMP_PASSKEY_MASK;


@@ -135,7 +135,7 @@ void smp_proc_passkey(tSMP_CB* p_cb, BT_OCTET8 rand) {
 *
 *
 ******************************************************************************/
 ******************************************************************************/
void smp_generate_passkey(tSMP_CB* p_cb, UNUSED_ATTR tSMP_INT_DATA* p_data) {
void smp_generate_passkey(tSMP_CB* p_cb, UNUSED_ATTR tSMP_INT_DATA* p_data) {
  LOG_VERBOSE("%s", __func__);
  LOG_VERBOSE("addr:%s", ADDRESS_TO_LOGGABLE_CSTR(p_cb->pairing_bda));
  /* generate MRand or SRand */
  /* generate MRand or SRand */
  btsnd_hcic_ble_rand(Bind(&smp_proc_passkey, p_cb));
  btsnd_hcic_ble_rand(Bind(&smp_proc_passkey, p_cb));
}
}
@@ -154,7 +154,7 @@ void smp_generate_passkey(tSMP_CB* p_cb, UNUSED_ATTR tSMP_INT_DATA* p_data) {
void smp_generate_stk(tSMP_CB* p_cb, UNUSED_ATTR tSMP_INT_DATA* p_data) {
void smp_generate_stk(tSMP_CB* p_cb, UNUSED_ATTR tSMP_INT_DATA* p_data) {
  Octet16 output;
  Octet16 output;


  LOG_VERBOSE("%s", __func__);
  LOG_VERBOSE("addr:%s", ADDRESS_TO_LOGGABLE_CSTR(p_cb->pairing_bda));


  if (p_cb->le_secure_connections_mode_is_used) {
  if (p_cb->le_secure_connections_mode_is_used) {
    LOG_VERBOSE("FOR LE SC LTK IS USED INSTEAD OF STK");
    LOG_VERBOSE("FOR LE SC LTK IS USED INSTEAD OF STK");
@@ -176,7 +176,7 @@ void smp_compute_csrk(uint16_t div, tSMP_CB* p_cb) {


  p_cb->div = div;
  p_cb->div = div;


  LOG_VERBOSE("%s: div=%x", __func__, p_cb->div);
  LOG_VERBOSE("div=0x%x", p_cb->div);
  const Octet16& er = BTM_GetDeviceEncRoot();
  const Octet16& er = BTM_GetDeviceEncRoot();
  /* CSRK = d1(ER, DIV, 1) */
  /* CSRK = d1(ER, DIV, 1) */
  UINT16_TO_STREAM(p, p_cb->div);
  UINT16_TO_STREAM(p, p_cb->div);
@@ -192,7 +192,7 @@ void smp_compute_csrk(uint16_t div, tSMP_CB* p_cb) {
void smp_generate_csrk(tSMP_CB* p_cb, UNUSED_ATTR tSMP_INT_DATA* p_data) {
void smp_generate_csrk(tSMP_CB* p_cb, UNUSED_ATTR tSMP_INT_DATA* p_data) {
  bool div_status;
  bool div_status;


  LOG_VERBOSE("smp_generate_csrk");
  LOG_VERBOSE("addr:%s", ADDRESS_TO_LOGGABLE_CSTR(p_cb->pairing_bda));


  div_status = btm_get_local_div(p_cb->pairing_bda, &p_cb->div);
  div_status = btm_get_local_div(p_cb->pairing_bda, &p_cb->div);
  if (div_status) {
  if (div_status) {
@@ -216,7 +216,7 @@ void smp_generate_csrk(tSMP_CB* p_cb, UNUSED_ATTR tSMP_INT_DATA* p_data) {
void smp_concatenate_local(tSMP_CB* p_cb, uint8_t** p_data, uint8_t op_code) {
void smp_concatenate_local(tSMP_CB* p_cb, uint8_t** p_data, uint8_t op_code) {
  uint8_t* p = *p_data;
  uint8_t* p = *p_data;


  LOG_VERBOSE("%s", __func__);
  LOG_VERBOSE("addr:%s", ADDRESS_TO_LOGGABLE_CSTR(p_cb->pairing_bda));
  UINT8_TO_STREAM(p, op_code);
  UINT8_TO_STREAM(p, op_code);
  UINT8_TO_STREAM(p, p_cb->local_io_capability);
  UINT8_TO_STREAM(p, p_cb->local_io_capability);
  UINT8_TO_STREAM(p, p_cb->loc_oob_flag);
  UINT8_TO_STREAM(p, p_cb->loc_oob_flag);
@@ -235,7 +235,7 @@ void smp_concatenate_local(tSMP_CB* p_cb, uint8_t** p_data, uint8_t op_code) {
void smp_concatenate_peer(tSMP_CB* p_cb, uint8_t** p_data, uint8_t op_code) {
void smp_concatenate_peer(tSMP_CB* p_cb, uint8_t** p_data, uint8_t op_code) {
  uint8_t* p = *p_data;
  uint8_t* p = *p_data;


  LOG_VERBOSE("smp_concatenate_peer ");
  LOG_VERBOSE("addr:%s", ADDRESS_TO_LOGGABLE_CSTR(p_cb->pairing_bda));
  UINT8_TO_STREAM(p, op_code);
  UINT8_TO_STREAM(p, op_code);
  UINT8_TO_STREAM(p, p_cb->peer_io_caps);
  UINT8_TO_STREAM(p, p_cb->peer_io_caps);
  UINT8_TO_STREAM(p, p_cb->peer_oob_flag);
  UINT8_TO_STREAM(p, p_cb->peer_oob_flag);
@@ -254,7 +254,9 @@ void smp_concatenate_peer(tSMP_CB* p_cb, uint8_t** p_data, uint8_t op_code) {
 */
 */
Octet16 smp_gen_p1_4_confirm(tSMP_CB* p_cb,
Octet16 smp_gen_p1_4_confirm(tSMP_CB* p_cb,
                             tBLE_ADDR_TYPE remote_bd_addr_type) {
                             tBLE_ADDR_TYPE remote_bd_addr_type) {
  LOG_VERBOSE("%s", __func__);
  LOG_VERBOSE("pairing_addr:%s, rmt_addr_type:%s",
              ADDRESS_TO_LOGGABLE_CSTR(p_cb->pairing_bda),
              AddressTypeText(remote_bd_addr_type).c_str());
  Octet16 p1;
  Octet16 p1;
  uint8_t* p = p1.data();
  uint8_t* p = p1.data();
  if (p_cb->role == HCI_ROLE_CENTRAL) {
  if (p_cb->role == HCI_ROLE_CENTRAL) {
@@ -288,7 +290,7 @@ Octet16 smp_gen_p1_4_confirm(tSMP_CB* p_cb,
 *                  p2 = ra || ia || padding
 *                  p2 = ra || ia || padding
 */
 */
Octet16 smp_gen_p2_4_confirm(tSMP_CB* p_cb, const RawAddress& remote_bda) {
Octet16 smp_gen_p2_4_confirm(tSMP_CB* p_cb, const RawAddress& remote_bda) {
  LOG_VERBOSE("%s", __func__);
  LOG_VERBOSE("addr:%s", ADDRESS_TO_LOGGABLE_CSTR(p_cb->pairing_bda));
  Octet16 p2{0};
  Octet16 p2{0};
  uint8_t* p = p2.data();
  uint8_t* p = p2.data();
  /* 32-bit Padding */
  /* 32-bit Padding */
@@ -319,13 +321,13 @@ Octet16 smp_gen_p2_4_confirm(tSMP_CB* p_cb, const RawAddress& remote_bda) {
 ******************************************************************************/
 ******************************************************************************/
tSMP_STATUS smp_calculate_comfirm(tSMP_CB* p_cb, const Octet16& rand,
tSMP_STATUS smp_calculate_comfirm(tSMP_CB* p_cb, const Octet16& rand,
                                  Octet16* output) {
                                  Octet16* output) {
  LOG_VERBOSE("%s", __func__);
  LOG_VERBOSE("addr:%s", ADDRESS_TO_LOGGABLE_CSTR(p_cb->pairing_bda));
  RawAddress remote_bda;
  RawAddress remote_bda;
  tBLE_ADDR_TYPE remote_bd_addr_type = BLE_ADDR_PUBLIC;
  tBLE_ADDR_TYPE remote_bd_addr_type = BLE_ADDR_PUBLIC;
  /* get remote connection specific bluetooth address */
  /* get remote connection specific bluetooth address */
  if (!BTM_ReadRemoteConnectionAddr(p_cb->pairing_bda, remote_bda,
  if (!BTM_ReadRemoteConnectionAddr(p_cb->pairing_bda, remote_bda,
                                    &remote_bd_addr_type, true)) {
                                    &remote_bd_addr_type, true)) {
    LOG_ERROR("%s: cannot obtain remote device address", __func__);
    LOG_ERROR("cannot obtain remote device address");
    return SMP_PAIR_FAIL_UNKNOWN;
    return SMP_PAIR_FAIL_UNKNOWN;
  }
  }
  /* get local connection specific bluetooth address */
  /* get local connection specific bluetooth address */
@@ -362,7 +364,7 @@ tSMP_STATUS smp_calculate_comfirm(tSMP_CB* p_cb, const Octet16& rand,
 *
 *
 ******************************************************************************/
 ******************************************************************************/
static void smp_generate_confirm(tSMP_CB* p_cb) {
static void smp_generate_confirm(tSMP_CB* p_cb) {
  LOG_VERBOSE("%s", __func__);
  LOG_VERBOSE("addr:%s", ADDRESS_TO_LOGGABLE_CSTR(p_cb->pairing_bda));
  smp_debug_print_nbyte_little_endian(p_cb->rand.data(), "local_rand", 16);
  smp_debug_print_nbyte_little_endian(p_cb->rand.data(), "local_rand", 16);
  Octet16 output;
  Octet16 output;
  tSMP_STATUS status = smp_calculate_comfirm(p_cb, p_cb->rand, &output);
  tSMP_STATUS status = smp_calculate_comfirm(p_cb, p_cb->rand, &output);
@@ -396,7 +398,7 @@ static void smp_generate_confirm(tSMP_CB* p_cb) {
 ******************************************************************************/
 ******************************************************************************/
void smp_generate_srand_mrand_confirm(tSMP_CB* p_cb,
void smp_generate_srand_mrand_confirm(tSMP_CB* p_cb,
                                      UNUSED_ATTR tSMP_INT_DATA* p_data) {
                                      UNUSED_ATTR tSMP_INT_DATA* p_data) {
  LOG_VERBOSE("%s", __func__);
  LOG_VERBOSE("addr:%s", ADDRESS_TO_LOGGABLE_CSTR(p_cb->pairing_bda));
  /* generate MRand or SRand */
  /* generate MRand or SRand */
  btsnd_hcic_ble_rand(Bind(
  btsnd_hcic_ble_rand(Bind(
      [](tSMP_CB* p_cb, BT_OCTET8 rand) {
      [](tSMP_CB* p_cb, BT_OCTET8 rand) {
@@ -426,7 +428,7 @@ void smp_generate_srand_mrand_confirm(tSMP_CB* p_cb,
 *
 *
 ******************************************************************************/
 ******************************************************************************/
void smp_generate_compare(tSMP_CB* p_cb, UNUSED_ATTR tSMP_INT_DATA* p_data) {
void smp_generate_compare(tSMP_CB* p_cb, UNUSED_ATTR tSMP_INT_DATA* p_data) {
  LOG_VERBOSE("smp_generate_compare ");
  LOG_VERBOSE("addr:%s", ADDRESS_TO_LOGGABLE_CSTR(p_cb->pairing_bda));
  smp_debug_print_nbyte_little_endian(p_cb->rrand, "peer rand", 16);
  smp_debug_print_nbyte_little_endian(p_cb->rrand, "peer rand", 16);
  Octet16 output;
  Octet16 output;
  tSMP_STATUS status = smp_calculate_comfirm(p_cb, p_cb->rrand, &output);
  tSMP_STATUS status = smp_calculate_comfirm(p_cb, p_cb->rrand, &output);
@@ -451,7 +453,7 @@ void smp_generate_compare(tSMP_CB* p_cb, UNUSED_ATTR tSMP_INT_DATA* p_data) {
static void smp_process_stk(tSMP_CB* p_cb, Octet16* p) {
static void smp_process_stk(tSMP_CB* p_cb, Octet16* p) {
  tSMP_KEY key;
  tSMP_KEY key;


  LOG_VERBOSE("smp_process_stk ");
  LOG_VERBOSE("addr:%s", ADDRESS_TO_LOGGABLE_CSTR(p_cb->pairing_bda));
  smp_mask_enc_key(p_cb->loc_enc_size, p);
  smp_mask_enc_key(p_cb->loc_enc_size, p);


  key.key_type = SMP_KEY_TYPE_STK;
  key.key_type = SMP_KEY_TYPE_STK;
@@ -468,13 +470,12 @@ static void smp_process_ediv(tSMP_CB* p_cb, Octet16& p) {
  uint8_t* pp = p.data();
  uint8_t* pp = p.data();
  uint16_t y;
  uint16_t y;


  LOG_VERBOSE("smp_process_ediv ");
  LOG_VERBOSE("addr:%s", ADDRESS_TO_LOGGABLE_CSTR(p_cb->pairing_bda));
  STREAM_TO_UINT16(y, pp);
  STREAM_TO_UINT16(y, pp);


  /* EDIV = Y xor DIV */
  /* EDIV = Y xor DIV */
  p_cb->ediv = p_cb->div ^ y;
  p_cb->ediv = p_cb->div ^ y;
  /* send LTK ready */
  /* send LTK ready */
  LOG_ERROR("LTK ready");
  key.key_type = SMP_KEY_TYPE_LTK;
  key.key_type = SMP_KEY_TYPE_LTK;
  key.p_data = p.data();
  key.p_data = p.data();


@@ -487,7 +488,7 @@ static void smp_process_ediv(tSMP_CB* p_cb, Octet16& p) {
 * This function is to proceed generate Y = E(DHK, Rand)
 * This function is to proceed generate Y = E(DHK, Rand)
 */
 */
static void smp_generate_y(tSMP_CB* p_cb, BT_OCTET8 rand) {
static void smp_generate_y(tSMP_CB* p_cb, BT_OCTET8 rand) {
  LOG_VERBOSE("%s ", __func__);
  LOG_VERBOSE("addr:%s", ADDRESS_TO_LOGGABLE_CSTR(p_cb->pairing_bda));


  const Octet16& dhk = BTM_GetDeviceDHK();
  const Octet16& dhk = BTM_GetDeviceDHK();


@@ -504,7 +505,7 @@ static void smp_generate_y(tSMP_CB* p_cb, BT_OCTET8 rand) {
static void smp_generate_ltk_cont(uint16_t div, tSMP_CB* p_cb) {
static void smp_generate_ltk_cont(uint16_t div, tSMP_CB* p_cb) {
  p_cb->div = div;
  p_cb->div = div;


  LOG_VERBOSE("%s", __func__);
  LOG_VERBOSE("addr:%s", ADDRESS_TO_LOGGABLE_CSTR(p_cb->pairing_bda));
  const Octet16& er = BTM_GetDeviceEncRoot();
  const Octet16& er = BTM_GetDeviceEncRoot();


  /* LTK = d1(ER, DIV, 0)= e(ER, DIV)*/
  /* LTK = d1(ER, DIV, 0)= e(ER, DIV)*/
@@ -536,7 +537,7 @@ static void smp_generate_ltk_cont(uint16_t div, tSMP_CB* p_cb) {
 *
 *
 ******************************************************************************/
 ******************************************************************************/
void smp_generate_ltk(tSMP_CB* p_cb, UNUSED_ATTR tSMP_INT_DATA* p_data) {
void smp_generate_ltk(tSMP_CB* p_cb, UNUSED_ATTR tSMP_INT_DATA* p_data) {
  LOG_VERBOSE("%s", __func__);
  LOG_VERBOSE("addr:%s", ADDRESS_TO_LOGGABLE_CSTR(p_cb->pairing_bda));


  if (smp_get_br_state() == SMP_BR_STATE_BOND_PENDING) {
  if (smp_get_br_state() == SMP_BR_STATE_BOND_PENDING) {
    smp_br_process_link_key(p_cb, NULL);
    smp_br_process_link_key(p_cb, NULL);
@@ -551,7 +552,7 @@ void smp_generate_ltk(tSMP_CB* p_cb, UNUSED_ATTR tSMP_INT_DATA* p_data) {
  if (div_status) {
  if (div_status) {
    smp_generate_ltk_cont(p_cb->div, p_cb);
    smp_generate_ltk_cont(p_cb->div, p_cb);
  } else {
  } else {
    LOG_VERBOSE("%s: Generate DIV for LTK", __func__);
    LOG_VERBOSE("Generate DIV for LTK");


    /* generate MRand or SRand */
    /* generate MRand or SRand */
    btsnd_hcic_ble_rand(Bind(
    btsnd_hcic_ble_rand(Bind(
@@ -566,7 +567,7 @@ void smp_generate_ltk(tSMP_CB* p_cb, UNUSED_ATTR tSMP_INT_DATA* p_data) {


/* The function calculates legacy STK */
/* The function calculates legacy STK */
Octet16 smp_calculate_legacy_short_term_key(tSMP_CB* p_cb) {
Octet16 smp_calculate_legacy_short_term_key(tSMP_CB* p_cb) {
  LOG_VERBOSE("%s", __func__);
  LOG_VERBOSE("addr:%s", ADDRESS_TO_LOGGABLE_CSTR(p_cb->pairing_bda));


  Octet16 text{};
  Octet16 text{};
  if (p_cb->role == HCI_ROLE_CENTRAL) {
  if (p_cb->role == HCI_ROLE_CENTRAL) {
@@ -594,7 +595,7 @@ Octet16 smp_calculate_legacy_short_term_key(tSMP_CB* p_cb) {
 *
 *
 ******************************************************************************/
 ******************************************************************************/
void smp_create_private_key(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) {
void smp_create_private_key(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) {
  LOG_VERBOSE("%s", __func__);
  LOG_VERBOSE("addr:%s", ADDRESS_TO_LOGGABLE_CSTR(p_cb->pairing_bda));


  // Only use the stored OOB data if we are in an oob association model
  // Only use the stored OOB data if we are in an oob association model
  if (p_cb->selected_association_model == SMP_MODEL_SEC_CONN_OOB) {
  if (p_cb->selected_association_model == SMP_MODEL_SEC_CONN_OOB) {
@@ -715,7 +716,7 @@ void smp_process_private_key(tSMP_CB* p_cb) {
  Point public_key;
  Point public_key;
  BT_OCTET32 private_key;
  BT_OCTET32 private_key;


  LOG_VERBOSE("%s", __func__);
  LOG_VERBOSE("addr:%s", ADDRESS_TO_LOGGABLE_CSTR(p_cb->pairing_bda));


  memcpy(private_key, p_cb->private_key, BT_OCTET32_LEN);
  memcpy(private_key, p_cb->private_key, BT_OCTET32_LEN);
  ECC_PointMult(&public_key, &(curve_p256.G), (uint32_t*)private_key);
  ECC_PointMult(&public_key, &(curve_p256.G), (uint32_t*)private_key);
@@ -748,7 +749,7 @@ void smp_compute_dhkey(tSMP_CB* p_cb) {
  Point peer_publ_key, new_publ_key;
  Point peer_publ_key, new_publ_key;
  BT_OCTET32 private_key;
  BT_OCTET32 private_key;


  LOG_VERBOSE("%s", __func__);
  LOG_VERBOSE("addr:%s", ADDRESS_TO_LOGGABLE_CSTR(p_cb->pairing_bda));


  memcpy(private_key, p_cb->private_key, BT_OCTET32_LEN);
  memcpy(private_key, p_cb->private_key, BT_OCTET32_LEN);
  memcpy(peer_publ_key.x, p_cb->peer_publ_key.x, BT_OCTET32_LEN);
  memcpy(peer_publ_key.x, p_cb->peer_publ_key.x, BT_OCTET32_LEN);
@@ -774,7 +775,7 @@ void smp_compute_dhkey(tSMP_CB* p_cb) {
void smp_calculate_local_commitment(tSMP_CB* p_cb) {
void smp_calculate_local_commitment(tSMP_CB* p_cb) {
  uint8_t random_input;
  uint8_t random_input;


  LOG_VERBOSE("%s", __func__);
  LOG_VERBOSE("addr:%s", ADDRESS_TO_LOGGABLE_CSTR(p_cb->pairing_bda));


  switch (p_cb->selected_association_model) {
  switch (p_cb->selected_association_model) {
    case SMP_MODEL_SEC_CONN_JUSTWORKS:
    case SMP_MODEL_SEC_CONN_JUSTWORKS:
@@ -805,15 +806,13 @@ void smp_calculate_local_commitment(tSMP_CB* p_cb) {
                p_cb->selected_association_model);
                p_cb->selected_association_model);
      return;
      return;
  }
  }

  LOG_VERBOSE("local commitment calculation is completed");
}
}


/** The function calculates peer commmitment */
/** The function calculates peer commmitment */
Octet16 smp_calculate_peer_commitment(tSMP_CB* p_cb) {
Octet16 smp_calculate_peer_commitment(tSMP_CB* p_cb) {
  uint8_t ri;
  uint8_t ri;


  LOG_VERBOSE("%s", __func__);
  LOG_VERBOSE("addr:%s", ADDRESS_TO_LOGGABLE_CSTR(p_cb->pairing_bda));
  Octet16 output{0};
  Octet16 output{0};
  switch (p_cb->selected_association_model) {
  switch (p_cb->selected_association_model) {
    case SMP_MODEL_SEC_CONN_JUSTWORKS:
    case SMP_MODEL_SEC_CONN_JUSTWORKS:
@@ -841,7 +840,6 @@ Octet16 smp_calculate_peer_commitment(tSMP_CB* p_cb) {
      return output;
      return output;
  }
  }


  LOG_VERBOSE("peer commitment calculation is completed");
  return output;
  return output;
}
}


@@ -857,7 +855,7 @@ Octet16 smp_calculate_peer_commitment(tSMP_CB* p_cb) {
 ******************************************************************************/
 ******************************************************************************/
void smp_calculate_numeric_comparison_display_number(tSMP_CB* p_cb,
void smp_calculate_numeric_comparison_display_number(tSMP_CB* p_cb,
                                                     tSMP_INT_DATA* p_data) {
                                                     tSMP_INT_DATA* p_data) {
  LOG_VERBOSE("%s", __func__);
  LOG_VERBOSE("addr:%s", ADDRESS_TO_LOGGABLE_CSTR(p_cb->pairing_bda));


  if (p_cb->role == HCI_ROLE_CENTRAL) {
  if (p_cb->role == HCI_ROLE_CENTRAL) {
    p_cb->number_to_display = crypto_toolbox::g2(
    p_cb->number_to_display = crypto_toolbox::g2(
@@ -871,17 +869,16 @@ void smp_calculate_numeric_comparison_display_number(tSMP_CB* p_cb,
    tSMP_INT_DATA smp_int_data;
    tSMP_INT_DATA smp_int_data;
    smp_int_data.status = SMP_PAIR_FAIL_UNKNOWN;
    smp_int_data.status = SMP_PAIR_FAIL_UNKNOWN;
    p_cb->failure = SMP_PAIR_FAIL_UNKNOWN;
    p_cb->failure = SMP_PAIR_FAIL_UNKNOWN;
    LOG_VERBOSE("Number to display in numeric comparison=%d too large",
                p_cb->number_to_display);
    smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &smp_int_data);
    smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &smp_int_data);
    return;
    return;
  }
  }


  LOG_VERBOSE("Number to display in numeric comparison = %d",
              p_cb->number_to_display);
  p_cb->cb_evt = SMP_NC_REQ_EVT;
  p_cb->cb_evt = SMP_NC_REQ_EVT;
  tSMP_INT_DATA smp_int_data;
  tSMP_INT_DATA smp_int_data;
  smp_int_data.passkey = p_cb->number_to_display;
  smp_int_data.passkey = p_cb->number_to_display;
  smp_sm_event(p_cb, SMP_SC_DSPL_NC_EVT, &smp_int_data);
  smp_sm_event(p_cb, SMP_SC_DSPL_NC_EVT, &smp_int_data);
  return;
}
}


/*******************************************************************************
/*******************************************************************************
@@ -901,7 +898,7 @@ void smp_calculate_numeric_comparison_display_number(tSMP_CB* p_cb,
void smp_calculate_local_dhkey_check(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) {
void smp_calculate_local_dhkey_check(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) {
  uint8_t iocap[3], a[7], b[7];
  uint8_t iocap[3], a[7], b[7];


  LOG_VERBOSE("%s", __func__);
  LOG_VERBOSE("addr:%s", ADDRESS_TO_LOGGABLE_CSTR(p_cb->pairing_bda));


  smp_calculate_f5_mackey_and_long_term_key(p_cb);
  smp_calculate_f5_mackey_and_long_term_key(p_cb);


@@ -911,8 +908,6 @@ void smp_calculate_local_dhkey_check(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) {
  smp_collect_peer_ble_address(b, p_cb);
  smp_collect_peer_ble_address(b, p_cb);
  p_cb->dhkey_check = crypto_toolbox::f6(p_cb->mac_key, p_cb->rand, p_cb->rrand,
  p_cb->dhkey_check = crypto_toolbox::f6(p_cb->mac_key, p_cb->rand, p_cb->rrand,
                                         p_cb->peer_random, iocap, a, b);
                                         p_cb->peer_random, iocap, a, b);

  LOG_VERBOSE("local DHKey check calculation is completed");
}
}


/*******************************************************************************
/*******************************************************************************
@@ -928,7 +923,7 @@ void smp_calculate_peer_dhkey_check(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) {
  uint8_t iocap[3], a[7], b[7];
  uint8_t iocap[3], a[7], b[7];
  tSMP_KEY key;
  tSMP_KEY key;


  LOG_VERBOSE("%s", __func__);
  LOG_VERBOSE("addr:%s", ADDRESS_TO_LOGGABLE_CSTR(p_cb->pairing_bda));


  smp_collect_peer_io_capabilities(iocap, p_cb);
  smp_collect_peer_io_capabilities(iocap, p_cb);


@@ -936,8 +931,6 @@ void smp_calculate_peer_dhkey_check(tSMP_CB* p_cb, tSMP_INT_DATA* p_data) {
  smp_collect_peer_ble_address(b, p_cb);
  smp_collect_peer_ble_address(b, p_cb);
  Octet16 param_buf = crypto_toolbox::f6(p_cb->mac_key, p_cb->rrand, p_cb->rand,
  Octet16 param_buf = crypto_toolbox::f6(p_cb->mac_key, p_cb->rrand, p_cb->rand,
                                         p_cb->local_random, iocap, b, a);
                                         p_cb->local_random, iocap, b, a);

  LOG_VERBOSE("peer DHKey check calculation is completed");
  key.key_type = SMP_KEY_TYPE_PEER_DHK_CHCK;
  key.key_type = SMP_KEY_TYPE_PEER_DHK_CHCK;
  key.p_data = param_buf.data();
  key.p_data = param_buf.data();
  tSMP_INT_DATA smp_int_data;
  tSMP_INT_DATA smp_int_data;
@@ -960,7 +953,7 @@ bool smp_calculate_link_key_from_long_term_key(tSMP_CB* p_cb) {
  RawAddress bda_for_lk;
  RawAddress bda_for_lk;
  tBLE_ADDR_TYPE conn_addr_type;
  tBLE_ADDR_TYPE conn_addr_type;


  LOG_VERBOSE("%s", __func__);
  LOG_VERBOSE("addr:%s", ADDRESS_TO_LOGGABLE_CSTR(p_cb->pairing_bda));


  if (p_cb->id_addr_rcvd && p_cb->id_addr_type == BLE_ADDR_PUBLIC) {
  if (p_cb->id_addr_rcvd && p_cb->id_addr_type == BLE_ADDR_PUBLIC) {
    LOG_VERBOSE(
    LOG_VERBOSE(
@@ -977,7 +970,7 @@ bool smp_calculate_link_key_from_long_term_key(tSMP_CB* p_cb) {


  p_dev_rec = btm_find_dev(p_cb->pairing_bda);
  p_dev_rec = btm_find_dev(p_cb->pairing_bda);
  if (p_dev_rec == NULL) {
  if (p_dev_rec == NULL) {
    LOG_ERROR("%s failed to find Security Record", __func__);
    LOG_ERROR("failed to find Security Record");
    return false;
    return false;
  }
  }


@@ -1001,8 +994,8 @@ bool smp_calculate_link_key_from_long_term_key(tSMP_CB* p_cb) {
    else
    else
      link_key_type = BTM_LKEY_TYPE_UNAUTH_COMB;
      link_key_type = BTM_LKEY_TYPE_UNAUTH_COMB;
  } else {
  } else {
    LOG_ERROR("%s failed to update link_key. Sec Mode = %d, sm4 = 0x%02x",
    LOG_ERROR("failed to update link_key. Sec Mode=%d, sm4=0x%02x",
              __func__, p_cb->init_security_mode, p_dev_rec->sm4);
              p_cb->init_security_mode, p_dev_rec->sm4);
    return false;
    return false;
  }
  }


@@ -1012,8 +1005,6 @@ bool smp_calculate_link_key_from_long_term_key(tSMP_CB* p_cb) {
  std::reverse_copy(link_key.begin(), link_key.end(), notif_link_key.begin());
  std::reverse_copy(link_key.begin(), link_key.end(), notif_link_key.begin());
  btm_sec_link_key_notification(bda_for_lk, notif_link_key, link_key_type);
  btm_sec_link_key_notification(bda_for_lk, notif_link_key, link_key_type);


  LOG_VERBOSE("%s is completed", __func__);

  return true;
  return true;
}
}


@@ -1021,25 +1012,24 @@ bool smp_calculate_link_key_from_long_term_key(tSMP_CB* p_cb) {
bool smp_calculate_long_term_key_from_link_key(tSMP_CB* p_cb) {
bool smp_calculate_long_term_key_from_link_key(tSMP_CB* p_cb) {
  tBTM_SEC_DEV_REC* p_dev_rec;
  tBTM_SEC_DEV_REC* p_dev_rec;


  LOG_VERBOSE("%s", __func__);
  LOG_VERBOSE("addr:%s", ADDRESS_TO_LOGGABLE_CSTR(p_cb->pairing_bda));


  p_dev_rec = btm_find_dev(p_cb->pairing_bda);
  p_dev_rec = btm_find_dev(p_cb->pairing_bda);
  if (p_dev_rec == NULL) {
  if (p_dev_rec == NULL) {
    LOG_ERROR("%s failed to find Security Record", __func__);
    LOG_ERROR("ailed to find Security Record");
    return false;
    return false;
  }
  }


  uint8_t br_link_key_type;
  uint8_t br_link_key_type;
  br_link_key_type = BTM_SecGetDeviceLinkKeyType(p_cb->pairing_bda);
  br_link_key_type = BTM_SecGetDeviceLinkKeyType(p_cb->pairing_bda);
  if (br_link_key_type == BTM_LKEY_TYPE_IGNORE) {
  if (br_link_key_type == BTM_LKEY_TYPE_IGNORE) {
    LOG_ERROR("%s failed to retrieve BR link type", __func__);
    LOG_ERROR("failed to retrieve BR link type");
    return false;
    return false;
  }
  }


  if ((br_link_key_type != BTM_LKEY_TYPE_AUTH_COMB_P_256) &&
  if ((br_link_key_type != BTM_LKEY_TYPE_AUTH_COMB_P_256) &&
      (br_link_key_type != BTM_LKEY_TYPE_UNAUTH_COMB_P_256)) {
      (br_link_key_type != BTM_LKEY_TYPE_UNAUTH_COMB_P_256)) {
    LOG_ERROR("%s LE SC LTK can't be derived from LK %d", __func__,
    LOG_ERROR("LE SC LTK can't be derived from LK %d", br_link_key_type);
              br_link_key_type);
    return false;
    return false;
  }
  }


@@ -1052,7 +1042,6 @@ bool smp_calculate_long_term_key_from_link_key(tSMP_CB* p_cb) {
  p_cb->sec_level = (br_link_key_type == BTM_LKEY_TYPE_AUTH_COMB_P_256)
  p_cb->sec_level = (br_link_key_type == BTM_LKEY_TYPE_AUTH_COMB_P_256)
                        ? SMP_SEC_AUTHENTICATED
                        ? SMP_SEC_AUTHENTICATED
                        : SMP_SEC_UNAUTHENTICATE;
                        : SMP_SEC_UNAUTHENTICATE;
  LOG_VERBOSE("%s is completed", __func__);
  return true;
  return true;
}
}


@@ -1060,14 +1049,14 @@ bool smp_calculate_long_term_key_from_link_key(tSMP_CB* p_cb) {
 * This function generates nonce.
 * This function generates nonce.
 */
 */
void smp_start_nonce_generation(tSMP_CB* p_cb) {
void smp_start_nonce_generation(tSMP_CB* p_cb) {
  LOG_VERBOSE("%s", __func__);
  LOG_VERBOSE("start generating nonce");
  btsnd_hcic_ble_rand(Bind(
  btsnd_hcic_ble_rand(Bind(
      [](tSMP_CB* p_cb, BT_OCTET8 rand) {
      [](tSMP_CB* p_cb, BT_OCTET8 rand) {
        memcpy(p_cb->rand.data(), rand, BT_OCTET8_LEN);
        memcpy(p_cb->rand.data(), rand, BT_OCTET8_LEN);
        btsnd_hcic_ble_rand(Bind(
        btsnd_hcic_ble_rand(Bind(
            [](tSMP_CB* p_cb, BT_OCTET8 rand) {
            [](tSMP_CB* p_cb, BT_OCTET8 rand) {
              memcpy(p_cb->rand.data() + 8, rand, BT_OCTET8_LEN);
              memcpy(p_cb->rand.data() + 8, rand, BT_OCTET8_LEN);
              LOG_VERBOSE("%s round %d", __func__, p_cb->round);
              LOG_VERBOSE("round %d, done", p_cb->round);
              /* notifies SM that it has new nonce. */
              /* notifies SM that it has new nonce. */
              smp_sm_event(p_cb, SMP_HAVE_LOC_NONCE_EVT, NULL);
              smp_sm_event(p_cb, SMP_HAVE_LOC_NONCE_EVT, NULL);
            },
            },
+23 −34
Original line number Original line Diff line number Diff line
@@ -55,7 +55,7 @@ static void smp_br_data_received(uint16_t channel, const RawAddress& bd_addr,
 ******************************************************************************/
 ******************************************************************************/
void smp_l2cap_if_init(void) {
void smp_l2cap_if_init(void) {
  tL2CAP_FIXED_CHNL_REG fixed_reg;
  tL2CAP_FIXED_CHNL_REG fixed_reg;
  LOG_VERBOSE("SMDBG l2c %s", __func__);
  LOG_VERBOSE("SMDBG l2c");


  fixed_reg.pL2CA_FixedConn_Cb = smp_connect_callback;
  fixed_reg.pL2CA_FixedConn_Cb = smp_connect_callback;
  fixed_reg.pL2CA_FixedData_Cb = smp_data_received;
  fixed_reg.pL2CA_FixedData_Cb = smp_data_received;
@@ -89,29 +89,22 @@ static void smp_connect_callback(UNUSED_ATTR uint16_t channel,
  tSMP_CB* p_cb = &smp_cb;
  tSMP_CB* p_cb = &smp_cb;
  tSMP_INT_DATA int_data;
  tSMP_INT_DATA int_data;


  LOG_DEBUG("bd_addr:%s transport:%s, connected:%d",
            ADDRESS_TO_LOGGABLE_CSTR(bd_addr),
            bt_transport_text(transport).c_str(), connected);

  if (bd_addr.IsEmpty()) {
  if (bd_addr.IsEmpty()) {
    LOG_WARN("Received unexpected callback for empty address");
    LOG_WARN("empty address");
    return;
    return;
  }
  }


  if (transport == BT_TRANSPORT_BR_EDR) {
  if (transport == BT_TRANSPORT_BR_EDR) {
    LOG_WARN("Received unexpected callback on classic channel peer:%s",
    LOG_WARN("unexpected transport");
             ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
    return;
    return;
  }
  }


  if (connected) {
    LOG_DEBUG("SMP Received connect callback bd_addr:%s transport:%s",
              ADDRESS_TO_LOGGABLE_CSTR(bd_addr), bt_transport_text(transport).c_str());
  } else {
    LOG_DEBUG("SMP Received disconnect callback bd_addr:%s transport:%s",
              ADDRESS_TO_LOGGABLE_CSTR(bd_addr), bt_transport_text(transport).c_str());
  }

  if (bd_addr == p_cb->pairing_bda) {
  if (bd_addr == p_cb->pairing_bda) {
    LOG_DEBUG("Received callback for device in pairing process:%s state:%s",
    LOG_DEBUG("in pairing process");
              ADDRESS_TO_LOGGABLE_CSTR(bd_addr),
              (connected) ? "connected" : "disconnected");


    if (connected) {
    if (connected) {
      if (!p_cb->connect_initialized) {
      if (!p_cb->connect_initialized) {
@@ -150,19 +143,19 @@ static void smp_data_received(uint16_t channel, const RawAddress& bd_addr,
  uint8_t cmd;
  uint8_t cmd;


  if (p_buf->len < 1) {
  if (p_buf->len < 1) {
    LOG_WARN("%s: smp packet length %d too short: must be at least 1", __func__,
    LOG_WARN("packet too short");
             p_buf->len);
    osi_free(p_buf);
    osi_free(p_buf);
    return;
    return;
  }
  }


  STREAM_TO_UINT8(cmd, p);
  STREAM_TO_UINT8(cmd, p);


  LOG_VERBOSE("%s: SMDBG l2c, cmd=0x%x", __func__, cmd);
  LOG_VERBOSE("cmd=%s[0x%02x]",
              smp_opcode_text(static_cast<tSMP_OPCODE>(cmd)).c_str(), cmd);


  /* sanity check */
  /* sanity check */
  if ((SMP_OPCODE_MAX < cmd) || (SMP_OPCODE_MIN > cmd)) {
  if ((SMP_OPCODE_MAX < cmd) || (SMP_OPCODE_MIN > cmd)) {
    LOG_WARN("Ignore received command with RESERVED code 0x%02x", cmd);
    LOG_WARN("invalid command");
    osi_free(p_buf);
    osi_free(p_buf);
    return;
    return;
  }
  }
@@ -192,10 +185,8 @@ static void smp_data_received(uint16_t channel, const RawAddress& bd_addr,
                    false /* is_over_br */);
                    false /* is_over_br */);


    if (cmd == SMP_OPCODE_CONFIRM) {
    if (cmd == SMP_OPCODE_CONFIRM) {
      LOG_VERBOSE(
      LOG_VERBOSE("peer_auth_req=0x%02x, loc_auth_req=0x%02x",
          "in %s cmd = 0x%02x, peer_auth_req = 0x%02x,"
                  p_cb->peer_auth_req, p_cb->loc_auth_req);
          "loc_auth_req = 0x%02x",
          __func__, cmd, p_cb->peer_auth_req, p_cb->loc_auth_req);


      if ((p_cb->peer_auth_req & SMP_SC_SUPPORT_BIT) &&
      if ((p_cb->peer_auth_req & SMP_SC_SUPPORT_BIT) &&
          (p_cb->loc_auth_req & SMP_SC_SUPPORT_BIT)) {
          (p_cb->loc_auth_req & SMP_SC_SUPPORT_BIT)) {
@@ -230,17 +221,14 @@ static void smp_br_connect_callback(uint16_t channel, const RawAddress& bd_addr,
  tSMP_CB* p_cb = &smp_cb;
  tSMP_CB* p_cb = &smp_cb;
  tSMP_INT_DATA int_data;
  tSMP_INT_DATA int_data;


  LOG_VERBOSE("%s", __func__);

  if (transport != BT_TRANSPORT_BR_EDR) {
  if (transport != BT_TRANSPORT_BR_EDR) {
    LOG_WARN("%s is called on unexpected transport %d", __func__, transport);
    LOG_WARN("unexpected transport %s", bt_transport_text(transport).c_str());
    return;
    return;
  }
  }


  VLOG(1) << __func__ << " for pairing BDA: "
  LOG_INFO("BDA:%s pairing_bda:%s, connected:%d",
          << ADDRESS_TO_LOGGABLE_STR(bd_addr)
           ADDRESS_TO_LOGGABLE_CSTR(bd_addr),
          << ", pairing_bda:" << ADDRESS_TO_LOGGABLE_STR(p_cb->pairing_bda)
           ADDRESS_TO_LOGGABLE_CSTR(p_cb->pairing_bda), connected);
          << " Event: " << ((connected) ? "connected" : "disconnected");


  if (bd_addr != p_cb->pairing_bda) return;
  if (bd_addr != p_cb->pairing_bda) return;


@@ -298,20 +286,21 @@ static void smp_br_data_received(uint16_t channel, const RawAddress& bd_addr,
  tSMP_CB* p_cb = &smp_cb;
  tSMP_CB* p_cb = &smp_cb;
  uint8_t* p = (uint8_t*)(p_buf + 1) + p_buf->offset;
  uint8_t* p = (uint8_t*)(p_buf + 1) + p_buf->offset;
  uint8_t cmd;
  uint8_t cmd;
  LOG_VERBOSE("SMDBG l2c %s", __func__);
  LOG_VERBOSE("SMDBG l2c");


  if (p_buf->len < 1) {
  if (p_buf->len < 1) {
    LOG_WARN("%s: smp packet length %d too short: must be at least 1", __func__,
    LOG_WARN("packet too short");
             p_buf->len);
    osi_free(p_buf);
    osi_free(p_buf);
    return;
    return;
  }
  }


  STREAM_TO_UINT8(cmd, p);
  STREAM_TO_UINT8(cmd, p);
  LOG_VERBOSE("cmd=%s[0x%02x]",
              smp_opcode_text(static_cast<tSMP_OPCODE>(cmd)).c_str(), cmd);


  /* sanity check */
  /* sanity check */
  if ((SMP_OPCODE_MAX < cmd) || (SMP_OPCODE_MIN > cmd)) {
  if ((SMP_OPCODE_MAX < cmd) || (SMP_OPCODE_MIN > cmd)) {
    LOG_WARN("Ignore received command with RESERVED code 0x%02x", cmd);
    LOG_WARN("invalid command 0x%02x", cmd);
    osi_free(p_buf);
    osi_free(p_buf);
    return;
    return;
  }
  }
Loading