feat(ble/bluedroid): Add more debug log for bluedroid

This commit is contained in:
chenjianhua
2025-11-21 13:29:44 +08:00
parent b50852df25
commit adb4cab44a
29 changed files with 276 additions and 109 deletions
@@ -786,7 +786,7 @@ void btm_acl_encrypt_change (UINT16 handle, UINT8 status, UINT8 encr_enable)
tBTM_SEC_DEV_REC *p_dev_rec;
tBTM_BL_ROLE_CHG_DATA evt;
BTM_TRACE_DEBUG ("btm_acl_encrypt_change handle=%d status=%d encr_enabl=%d\n",
BTM_TRACE_DEBUG ("btm_acl_encrypt_change handle=%d status=%d encr_enable=%d\n",
handle, status, encr_enable);
p = btm_handle_to_acl(handle);
if (p == NULL) {
@@ -77,18 +77,16 @@ BOOLEAN BTM_SecAddBleDevice (BD_ADDR bd_addr, BD_NAME bd_name, tBT_DEVICE_TYPE d
tBTM_SEC_DEV_REC *p_dev_rec;
tBTM_INQ_INFO *p_info = NULL;
BTM_TRACE_DEBUG ("BTM_SecAddBleDevice dev_type=0x%x", dev_type);
BTM_TRACE_DEBUG ("%s dev_type=0x%x bd_addr="MACSTR"", __func__, dev_type, MAC2STR(bd_addr));
p_dev_rec = btm_find_dev (bd_addr);
if (!p_dev_rec) {
BTM_TRACE_DEBUG("Add a new device");
/* There is no device record, allocate one.
* If we can not find an empty spot for this one, let it fail. */
if (list_length(btm_cb.p_sec_dev_rec_list) < BTM_SEC_MAX_DEVICE_RECORDS) {
p_dev_rec = (tBTM_SEC_DEV_REC *)osi_malloc(sizeof(tBTM_SEC_DEV_REC));
if(p_dev_rec) {
list_append(btm_cb.p_sec_dev_rec_list, p_dev_rec);
p_dev_rec = (tBTM_SEC_DEV_REC *)osi_malloc(sizeof(tBTM_SEC_DEV_REC));
if (p_dev_rec) {
list_append(btm_cb.p_sec_dev_rec_list, p_dev_rec);
BTM_TRACE_DEBUG ("allocate a new dev rec idx=0x%x\n", list_length(btm_cb.p_sec_dev_rec_list));
/* Mark this record as in use and initialize */
@@ -158,22 +156,20 @@ BOOLEAN BTM_SecAddBleDevice (BD_ADDR bd_addr, BD_NAME bd_name, tBT_DEVICE_TYPE d
BOOLEAN BTM_SecAddBleKey (BD_ADDR bd_addr, tBTM_LE_KEY_VALUE *p_le_key, tBTM_LE_KEY_TYPE key_type)
{
tBTM_SEC_DEV_REC *p_dev_rec;
BTM_TRACE_DEBUG ("BTM_SecAddBleKey");
p_dev_rec = btm_find_dev (bd_addr);
if (!p_dev_rec || !p_le_key ||
(key_type != BTM_LE_KEY_PENC && key_type != BTM_LE_KEY_PID &&
key_type != BTM_LE_KEY_PCSRK && key_type != BTM_LE_KEY_LENC &&
key_type != BTM_LE_KEY_LCSRK && key_type != BTM_LE_KEY_LID)) {
BTM_TRACE_WARNING ("BTM_SecAddBleKey() Wrong Type, or No Device record \
for bdaddr: %08x%04x, Type: %d",
(bd_addr[0] << 24) + (bd_addr[1] << 16) + (bd_addr[2] << 8) + bd_addr[3],
(bd_addr[4] << 8) + bd_addr[5], key_type);
BTM_TRACE_WARNING ("BTM_SecAddBleKey() Wrong Type, or No Device record \
for bdaddr: "MACSTR", key_type: %02x",
MAC2STR(bd_addr), key_type);
return (FALSE);
}
BTM_TRACE_DEBUG ("BTM_SecAddLeKey() BDA: %08x%04x, Type: 0x%02x",
(bd_addr[0] << 24) + (bd_addr[1] << 16) + (bd_addr[2] << 8) + bd_addr[3],
(bd_addr[4] << 8) + bd_addr[5], key_type);
BTM_TRACE_DEBUG ("BTM_SecAddLeKey() BDA: "MACSTR", key_type: 0x%02x",
MAC2STR(bd_addr), key_type);
btm_sec_save_le_key (bd_addr, key_type, p_le_key, FALSE);
@@ -1756,15 +1752,14 @@ void btm_ble_ltk_request_reply(BD_ADDR bda, BOOLEAN use_stk, BT_OCTET16 stk)
tBTM_CB *p_cb = &btm_cb;
if (p_rec == NULL) {
BTM_TRACE_ERROR("btm_ble_ltk_request_reply received for unknown device");
BTM_TRACE_ERROR("%s received for unknown device "MACSTR"", __func__, MAC2STR(bda));
return;
}
BTM_TRACE_DEBUG ("btm_ble_ltk_request_reply");
BTM_TRACE_DEBUG ("%s key_type=%x key_size=%d", __func__, p_rec->ble.key_type, p_rec->ble.keys.key_size);
p_cb->enc_handle = p_rec->ble_hci_handle;
p_cb->key_size = p_rec->ble.keys.key_size;
BTM_TRACE_DEBUG("key size = %d", p_rec->ble.keys.key_size);
if (use_stk) {
btsnd_hcic_ble_ltk_req_reply(btm_cb.enc_handle, stk);
} else { /* calculate LTK using peer device */
@@ -2044,7 +2039,8 @@ void btm_ble_conn_complete(UINT8 *p, UINT16 evt_len, BOOLEAN enhanced)
STREAM_TO_UINT8 (role, p);
STREAM_TO_UINT8 (bda_type, p);
STREAM_TO_BDADDR (bda, p);
BTM_TRACE_DEBUG("status = %d, handle = %d, role = %d, bda_type = %d",status,handle,role,bda_type);
BTM_TRACE_DEBUG("status=%d handle=%d role=%d bda_type=%d bda="MACSTR"",
status, handle, role, bda_type, MAC2STR(bda));
if (status == 0) {
if (enhanced) {
STREAM_TO_BDADDR (local_rpa, p);
@@ -821,6 +821,7 @@ tBTM_BLE_CONN_ST btm_ble_get_conn_st(void)
*******************************************************************************/
void btm_ble_set_conn_st(tBTM_BLE_CONN_ST new_st)
{
BTM_TRACE_DEBUG("%s old=%u new=%u", __func__, btm_cb.ble_ctr_cb.conn_state, new_st);
btm_cb.ble_ctr_cb.conn_state = new_st;
if (new_st == BLE_BG_CONN || new_st == BLE_DIR_CONN) {
@@ -2136,6 +2136,7 @@ void BTM_Recovery_Pre_State(void)
{
#if ((BLE_42_ADV_EN == TRUE) || (BLE_42_SCAN_EN == TRUE))
tBTM_BLE_INQ_CB *ble_inq_cb = &btm_cb.ble_ctr_cb.inq_var;
BTM_TRACE_DEBUG("%s state=0x%x", __func__, ble_inq_cb->state);
#endif // #if ((BLE_42_ADV_EN == TRUE) || (BLE_42_SCAN_EN == TRUE))
#if (BLE_42_ADV_EN == TRUE)
if (ble_inq_cb->state & BTM_BLE_ADVERTISING) {
@@ -73,9 +73,11 @@ BOOLEAN BTM_SecAddDevice (BD_ADDR bd_addr, DEV_CLASS dev_class, BD_NAME bd_name,
/* There is no device record, allocate one.
* If we can not find an empty spot for this one, let it fail. */
if (list_length(btm_cb.p_sec_dev_rec_list) < BTM_SEC_MAX_DEVICE_RECORDS) {
p_dev_rec = (tBTM_SEC_DEV_REC *)osi_malloc(sizeof(tBTM_SEC_DEV_REC));
if(p_dev_rec) {
list_append(btm_cb.p_sec_dev_rec_list, p_dev_rec);
p_dev_rec = (tBTM_SEC_DEV_REC *)osi_malloc(sizeof(tBTM_SEC_DEV_REC));
if(p_dev_rec) {
BTM_TRACE_DEBUG("%s alloc a new dev rec %p bd_addr="MACSTR"",
__func__, p_dev_rec, MAC2STR(bd_addr));
list_append(btm_cb.p_sec_dev_rec_list, p_dev_rec);
/* Mark this record as in use and initialize */
memset (p_dev_rec, 0, sizeof (tBTM_SEC_DEV_REC));
p_dev_rec->sec_flags = BTM_SEC_IN_USE;
@@ -360,6 +362,8 @@ tBTM_SEC_DEV_REC *btm_sec_alloc_dev (BD_ADDR bd_addr)
if (list_length(btm_cb.p_sec_dev_rec_list) < BTM_SEC_MAX_DEVICE_RECORDS){
p_dev_new_rec = (tBTM_SEC_DEV_REC *)osi_malloc(sizeof(tBTM_SEC_DEV_REC));
if (p_dev_new_rec) {
BTM_TRACE_DEBUG("%s alloc a new dev rec %p bd_addr="MACSTR"",
__func__, p_dev_new_rec, MAC2STR(bd_addr));
new_entry_found = TRUE;
malloc_new_entry = TRUE;
} else {
@@ -33,7 +33,7 @@
#define GATT_HDR_FIND_TYPE_VALUE_LEN 21
#define GATT_OP_CODE_SIZE 1
/**********************************************************************
** ATT protocl message building utility *
** ATT protocol message building utility *
***********************************************************************/
/*******************************************************************************
**
@@ -462,7 +462,7 @@ BT_HDR *attp_build_sr_msg(tGATT_TCB *p_tcb, UINT8 op_code, tGATT_SR_MSG *p_msg)
** Description This function sends the server response or indication message
** to client.
**
** Parameter p_tcb: pointer to the connecton control block.
** Parameter p_tcb: pointer to the connection control block.
** p_msg: pointer to message parameters structure.
**
** Returns GATT_SUCCESS if successfully sent; otherwise error code.
@@ -628,7 +628,7 @@ tGATT_STATUS attp_send_cl_msg (tGATT_TCB *p_tcb, UINT16 clcb_idx, UINT8 op_code,
if (p_cmd != NULL) {
status = attp_cl_send_cmd(p_tcb, clcb_idx, op_code, p_cmd);
}
GATT_TRACE_DEBUG("%s opcode=%x status=%x", __func__, op_code, status);
} else {
GATT_TRACE_ERROR("Peer device not connected");
}
@@ -995,6 +995,7 @@ void gatt_data_process (tGATT_TCB *p_tcb, BT_HDR *p_buf)
pseudo_op_code = op_code & (~GATT_WRITE_CMD_MASK);
if (pseudo_op_code < GATT_OP_CODE_MAX) {
GATT_TRACE_DEBUG("%s opcode=%x msg_len=%u", __func__, op_code, msg_len);
if (op_code == GATT_SIGN_CMD_WRITE) {
#if (SMP_INCLUDED == TRUE)
gatt_verify_signature(p_tcb, p_buf);
@@ -1220,7 +1221,6 @@ tGATT_CH_STATE gatt_get_ch_state(tGATT_TCB *p_tcb)
{
tGATT_CH_STATE ch_state = GATT_CH_CLOSE;
if (p_tcb) {
GATT_TRACE_DEBUG ("gatt_get_ch_state: ch_state=%d", p_tcb->ch_state);
ch_state = p_tcb->ch_state;
}
return ch_state;
@@ -1233,6 +1233,7 @@ uint16_t gatt_get_local_mtu(void)
void gatt_set_local_mtu(uint16_t mtu)
{
GATT_TRACE_DEBUG("%s mtu=%u", __func__, mtu);
gatt_default.local_mtu = mtu;
}
@@ -405,7 +405,7 @@ tGATT_STATUS gatt_sr_process_app_rsp (tGATT_TCB *p_tcb, tGATT_IF gatt_if,
tGATT_STATUS ret_code = GATT_SUCCESS;
UNUSED(trans_id);
GATT_TRACE_DEBUG("gatt_sr_process_app_rsp gatt_if=%d\n", gatt_if);
GATT_TRACE_DEBUG("gatt_sr_process_app_rsp gatt_if=%d opcode=%x\n", gatt_if, op_code);
gatt_sr_update_cback_cnt(p_tcb, gatt_if, FALSE, FALSE);
@@ -1827,6 +1827,7 @@ void gatt_server_handle_client_req (tGATT_TCB *p_tcb, UINT8 op_code,
{
/* there is pending command, discard this one */
if (!gatt_sr_cmd_empty(p_tcb) && op_code != GATT_HANDLE_VALUE_CONF) {
GATT_TRACE_WARNING("%s discard command opcode=%02x", __func__, op_code);
return;
}
@@ -1891,6 +1892,7 @@ void gatt_server_handle_client_req (tGATT_TCB *p_tcb, UINT8 op_code,
break;
default:
GATT_TRACE_ERROR("%s unknown command opcode=%02x", __func__, op_code);
break;
}
}
@@ -1364,7 +1364,8 @@ void gatt_rsp_timeout(TIMER_LIST_ENT *p_tle)
}
}
GATT_TRACE_WARNING("gatt_rsp_timeout disconnecting...");
GATT_TRACE_WARNING("gatt_rsp_timeout conn_id=%x op=%u op_sub=%u retry_count=%u disconnecting...",
p_clcb->conn_id, p_clcb->operation, p_clcb->op_subtype, p_clcb->retry_count);
gatt_disconnect (p_clcb->p_tcb);
}
@@ -1806,7 +1807,7 @@ void gatt_clcb_dealloc (tGATT_CLCB *p_clcb)
btu_free_timer(&p_clcb->rsp_timer_ent);
memset(p_clcb, 0, sizeof(tGATT_CLCB));
list_remove(gatt_cb.p_clcb_list, p_clcb);
p_clcb = NULL;
p_clcb = NULL;
}
}
@@ -618,6 +618,8 @@ BOOLEAN btsnd_hcic_ble_start_enc (UINT16 handle, UINT8 rand[HCIC_BLE_RAND_DI_SIZ
BT_HDR *p;
UINT8 *pp;
HCI_TRACE_DEBUG("%s handle=%u LTK=%s", __func__, handle, bt_hex2str(ltk, HCIC_BLE_ENCRYT_KEY_SIZE));
if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_BLE_START_ENC)) == NULL) {
return (FALSE);
}
@@ -644,6 +646,8 @@ BOOLEAN btsnd_hcic_ble_ltk_req_reply (UINT16 handle, UINT8 ltk[HCIC_BLE_ENCRYT_K
BT_HDR *p;
UINT8 *pp;
HCI_TRACE_DEBUG("%s handle=%u LTK=%s", __func__, handle, bt_hex2str(ltk, HCIC_BLE_ENCRYT_KEY_SIZE));
if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_LTK_REQ_REPLY)) == NULL) {
return (FALSE);
}
@@ -668,6 +672,8 @@ BOOLEAN btsnd_hcic_ble_ltk_req_neg_reply (UINT16 handle)
BT_HDR *p;
UINT8 *pp;
HCI_TRACE_WARNING("%s handle=%u", __func__, handle);
if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_LTK_REQ_NEG_REPLY)) == NULL) {
return (FALSE);
}
@@ -215,7 +215,7 @@ UINT16 L2CA_ConnectReq (UINT16 psm, BD_ADDR p_bd_addr)
**
** Parameters: PSM: L2CAP PSM for the connection
** BD address of the peer
** Enhaced retransmission mode configurations
** Enhanced retransmission mode configurations
** Returns the CID of the connection, or 0 if it failed to start
**
@@ -760,7 +760,7 @@ bool L2CA_GetIdentifiers(uint16_t lcid, uint16_t *rcid, uint16_t *handle)
**
** NOTE This timeout takes effect after at least 1 channel has been
** established and removed. L2CAP maintains its own timer from
** whan a connection is established till the first channel is
** when a connection is established till the first channel is
** set up.
*******************************************************************************/
BOOLEAN L2CA_SetIdleTimeout (UINT16 cid, UINT16 timeout, BOOLEAN is_global)
@@ -1901,6 +1901,8 @@ BOOLEAN L2CA_RemoveFixedChnl (UINT16 fixed_cid, BD_ADDR rem_bda)
tL2C_CCB *p_ccb;
tBT_TRANSPORT transport = BT_TRANSPORT_BR_EDR;
L2CAP_TRACE_DEBUG("%s cid=%04x bda="MACSTR"", __func__, fixed_cid, MAC2STR(rem_bda));
/* Check CID is valid and registered */
if ( (fixed_cid < L2CAP_FIRST_FIXED_CHNL) || (fixed_cid > L2CAP_LAST_FIXED_CHNL)
|| (l2cb.fixed_reg[fixed_cid - L2CAP_FIRST_FIXED_CHNL].pL2CA_FixedData_Cb == NULL) ) {
@@ -92,6 +92,8 @@ BOOLEAN L2CA_CancelBleConnectReq (BD_ADDR rem_bda)
{
tL2C_LCB *p_lcb;
L2CAP_TRACE_DEBUG("%s rem_bda="MACSTR"", __func__, MAC2STR(rem_bda));
/* There can be only one BLE connection request outstanding at a time */
if (btm_ble_get_conn_st() == BLE_CONN_IDLE) {
L2CAP_TRACE_WARNING ("L2CA_CancelBleConnectReq - no connection pending");
@@ -99,10 +101,8 @@ BOOLEAN L2CA_CancelBleConnectReq (BD_ADDR rem_bda)
}
if (memcmp (rem_bda, l2cb.ble_connecting_bda, BD_ADDR_LEN)) {
L2CAP_TRACE_WARNING ("L2CA_CancelBleConnectReq - different BDA Connecting: %08x%04x Cancel: %08x%04x",
(l2cb.ble_connecting_bda[0] << 24) + (l2cb.ble_connecting_bda[1] << 16) + (l2cb.ble_connecting_bda[2] << 8) + l2cb.ble_connecting_bda[3],
(l2cb.ble_connecting_bda[4] << 8) + l2cb.ble_connecting_bda[5],
(rem_bda[0] << 24) + (rem_bda[1] << 16) + (rem_bda[2] << 8) + rem_bda[3], (rem_bda[4] << 8) + rem_bda[5]);
L2CAP_TRACE_WARNING ("L2CA_CancelBleConnectReq - different BDA Connecting: "MACSTR" Cancel: "MACSTR"",
MAC2STR(l2cb.ble_connecting_bda), MAC2STR(rem_bda));
return (FALSE);
}
@@ -148,16 +148,12 @@ BOOLEAN L2CA_UpdateBleConnParams (BD_ADDR rem_bda, UINT16 min_int, UINT16 max_in
/* If we don't have one, create one and accept the connection. */
if (!p_lcb || !p_acl_cb) {
L2CAP_TRACE_WARNING ("L2CA_UpdateBleConnParams - unknown BD_ADDR %08x%04x",
(rem_bda[0] << 24) + (rem_bda[1] << 16) + (rem_bda[2] << 8) + rem_bda[3],
(rem_bda[4] << 8) + rem_bda[5]);
L2CAP_TRACE_WARNING ("L2CA_UpdateBleConnParams - unknown BD_ADDR "MACSTR"", MAC2STR(rem_bda));
return (FALSE);
}
if (p_lcb->transport != BT_TRANSPORT_LE) {
L2CAP_TRACE_WARNING ("L2CA_UpdateBleConnParams - BD_ADDR %08x%04x not LE",
(rem_bda[0] << 24) + (rem_bda[1] << 16) + (rem_bda[2] << 8) + rem_bda[3],
(rem_bda[4] << 8) + rem_bda[5]);
L2CAP_TRACE_WARNING ("L2CA_UpdateBleConnParams - BD_ADDR "MACSTR" not LE", MAC2STR(rem_bda));
return (FALSE);
}
@@ -172,7 +168,7 @@ BOOLEAN L2CA_UpdateBleConnParams (BD_ADDR rem_bda, UINT16 min_int, UINT16 max_in
if (p_lcb->conn_update_mask & L2C_BLE_UPDATE_PARAM_FULL){
status = HCI_ERR_ILLEGAL_COMMAND;
need_cb = true;
L2CAP_TRACE_ERROR("There are two connection parameter requests that are being updated, please try later ");
L2CAP_TRACE_ERROR("%s connection parameter update in progress, please try later", __func__);
}
if ((need_cb == TRUE) && (conn_callback_func.update_conn_param_cb != NULL)) {
@@ -221,20 +217,16 @@ BOOLEAN L2CA_EnableUpdateBleConnParams (BD_ADDR rem_bda, BOOLEAN enable)
p_lcb = l2cu_find_lcb_by_bd_addr (rem_bda, BT_TRANSPORT_LE);
if (!p_lcb) {
L2CAP_TRACE_WARNING ("L2CA_EnableUpdateBleConnParams - unknown BD_ADDR %08x%04x",
(rem_bda[0] << 24) + (rem_bda[1] << 16) + (rem_bda[2] << 8) + rem_bda[3],
(rem_bda[4] << 8) + rem_bda[5]);
L2CAP_TRACE_WARNING ("L2CA_EnableUpdateBleConnParams - unknown BD_ADDR "MACSTR"", MAC2STR(rem_bda));
return (FALSE);
}
L2CAP_TRACE_API ("%s - BD_ADDR %08x%04x enable %d current upd state 0x%02x", __FUNCTION__,
(rem_bda[0] << 24) + (rem_bda[1] << 16) + (rem_bda[2] << 8) + rem_bda[3],
(rem_bda[4] << 8) + rem_bda[5], enable, p_lcb->conn_update_mask);
L2CAP_TRACE_API ("%s - BD_ADDR "MACSTR" enable %d current upd state 0x%02x",
__func__, MAC2STR(rem_bda), enable, p_lcb->conn_update_mask);
if (p_lcb->transport != BT_TRANSPORT_LE) {
L2CAP_TRACE_WARNING ("%s - BD_ADDR %08x%04x not LE (link role %d)", __FUNCTION__,
(rem_bda[0] << 24) + (rem_bda[1] << 16) + (rem_bda[2] << 8) + rem_bda[3],
(rem_bda[4] << 8) + rem_bda[5], p_lcb->link_role);
L2CAP_TRACE_WARNING ("%s - BD_ADDR "MACSTR" not LE (link role %d)",
__func__, MAC2STR(rem_bda), p_lcb->link_role);
return (FALSE);
}
@@ -158,6 +158,9 @@ void l2cu_release_lcb (tL2C_LCB *p_lcb)
{
tL2C_CCB *p_ccb;
L2CAP_TRACE_DEBUG("%s handle=%u bda="MACSTR"",
__func__, p_lcb->handle, MAC2STR(p_lcb->remote_bd_addr));
p_lcb->in_use = FALSE;
p_lcb->is_bonding = FALSE;
#if (BLE_INCLUDED == TRUE)
@@ -79,7 +79,7 @@ static bool lmp_version_below(BD_ADDR bda, uint8_t version)
*******************************************************************************/
static void smp_update_key_mask (tSMP_CB *p_cb, UINT8 key_type, BOOLEAN recv)
{
SMP_TRACE_DEBUG("%s before update role=%d recv=%d local_i_key = %02x, local_r_key = %02x\n",
SMP_TRACE_DEBUG("%s before update role=%d recv=%d local_i_key = %02x, local_r_key = %02x",
__func__, p_cb->role, recv, p_cb->local_i_key, p_cb->local_r_key);
if (((p_cb->le_secure_connections_mode_is_used) ||
@@ -103,8 +103,8 @@ static void smp_update_key_mask (tSMP_CB *p_cb, UINT8 key_type, BOOLEAN recv)
}
}
SMP_TRACE_DEBUG("updated local_i_key = %02x, local_r_key = %02x\n", p_cb->local_i_key,
p_cb->local_r_key);
SMP_TRACE_DEBUG("updated local_i_key = %02x, local_r_key = %02x",
p_cb->local_i_key, p_cb->local_r_key);
}
/*******************************************************************************
@@ -115,7 +115,7 @@ void smp_send_app_cback(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
tSMP_EVT_DATA cb_data;
tSMP_STATUS callback_rc;
SMP_TRACE_DEBUG("%s p_cb->cb_evt=%d\n", __func__, p_cb->cb_evt);
SMP_TRACE_DEBUG("%s cb_evt=%d", __func__, p_cb->cb_evt);
if (p_cb->p_callback && p_cb->cb_evt != 0) {
switch (p_cb->cb_evt) {
case SMP_IO_CAP_REQ_EVT:
@@ -171,11 +171,11 @@ void smp_send_app_cback(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
p_cb->local_r_key = 0;
}
SMP_TRACE_DEBUG ("rcvd auth_req: 0x%02x, io_cap: %d \
loc_oob_flag: %d loc_enc_size: %d,"
"local_i_key: 0x%02x, local_r_key: 0x%02x\n",
p_cb->loc_auth_req, p_cb->local_io_capability, p_cb->loc_oob_flag,
p_cb->loc_enc_size, p_cb->local_i_key, p_cb->local_r_key);
SMP_TRACE_DEBUG ("rcvd auth_req: 0x%02x, io_cap: %d,"
"loc_oob_flag: %d loc_enc_size: %d,"
"local_i_key: 0x%02x, local_r_key: 0x%02x",
p_cb->loc_auth_req, p_cb->local_io_capability, p_cb->loc_oob_flag,
p_cb->loc_enc_size, p_cb->local_i_key, p_cb->local_r_key);
p_cb->secure_connections_only_mode_required =
(btm_cb.security_mode == BTM_SEC_MODE_SC) ? TRUE : FALSE;
@@ -222,8 +222,6 @@ void smp_send_app_cback(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
p_cb->discard_sec_req = FALSE;
smp_sm_event(p_cb, SMP_DISCARD_SEC_REQ_EVT, NULL);
}
SMP_TRACE_DEBUG("%s return\n", __func__);
}
/*******************************************************************************
@@ -249,7 +247,7 @@ void smp_send_pair_fail(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
*******************************************************************************/
void smp_send_pair_req(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
SMP_TRACE_DEBUG("%s\n", __func__);
SMP_TRACE_DEBUG("%s", __func__);
#if (BLE_INCLUDED == TRUE)
tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (p_cb->pairing_bda);
@@ -269,7 +267,7 @@ void smp_send_pair_req(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
*******************************************************************************/
void smp_send_pair_rsp(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
SMP_TRACE_DEBUG("%s\n", __func__);
SMP_TRACE_DEBUG("%s", __func__);
#if (BLE_INCLUDED == TRUE)
p_cb->local_i_key &= p_cb->peer_i_key;
@@ -291,7 +289,7 @@ void smp_send_pair_rsp(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
*******************************************************************************/
void smp_send_confirm(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
SMP_TRACE_DEBUG("%s\n", __func__);
SMP_TRACE_DEBUG("%s", __func__);
smp_send_cmd(SMP_OPCODE_CONFIRM, p_cb);
}
@@ -313,7 +311,7 @@ void smp_send_init(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
*******************************************************************************/
void smp_send_rand(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
SMP_TRACE_DEBUG("%s\n", __func__);
SMP_TRACE_DEBUG("%s", __func__);
smp_send_cmd(SMP_OPCODE_RAND, p_cb);
}
@@ -323,7 +321,7 @@ void smp_send_rand(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
*******************************************************************************/
void smp_send_pair_public_key(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
SMP_TRACE_DEBUG("%s\n", __func__);
SMP_TRACE_DEBUG("%s", __func__);
smp_send_cmd(SMP_OPCODE_PAIR_PUBLIC_KEY, p_cb);
}
@@ -365,7 +363,7 @@ void smp_send_enc_info(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
tBTM_LE_LENC_KEYS le_key;
SMP_TRACE_DEBUG("%s p_cb->loc_enc_size = %d\n", __func__, p_cb->loc_enc_size);
SMP_TRACE_DEBUG("%s loc_enc_size = %d", __func__, p_cb->loc_enc_size);
smp_update_key_mask (p_cb, SMP_SEC_KEY_TYPE_ENC, FALSE);
smp_send_cmd(SMP_OPCODE_ENCRYPT_INFO, p_cb);
@@ -383,8 +381,6 @@ void smp_send_enc_info(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
(tBTM_LE_KEY_VALUE *)&le_key, TRUE);
}
SMP_TRACE_DEBUG ("%s\n", __func__);
smp_key_distribution(p_cb, NULL);
#endif ///BLE_INCLUDED == TRUE
}
@@ -395,7 +391,7 @@ void smp_send_enc_info(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
*******************************************************************************/
void smp_send_id_info(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
SMP_TRACE_DEBUG("%s\n", __func__);
SMP_TRACE_DEBUG("%s", __func__);
smp_update_key_mask (p_cb, SMP_SEC_KEY_TYPE_ID, FALSE);
smp_send_cmd(SMP_OPCODE_IDENTITY_INFO, p_cb);
@@ -420,7 +416,7 @@ void smp_send_id_info(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
void smp_send_csrk_info(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
tBTM_LE_LCSRK_KEYS key;
SMP_TRACE_DEBUG("%s\n", __func__);
SMP_TRACE_DEBUG("%s", __func__);
smp_update_key_mask (p_cb, SMP_SEC_KEY_TYPE_CSRK, FALSE);
if (smp_send_cmd(SMP_OPCODE_SIGN_INFO, p_cb)) {
@@ -455,12 +451,10 @@ void smp_proc_sec_req(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
tBTM_BLE_SEC_REQ_ACT sec_req_act;
UINT8 reason;
SMP_TRACE_DEBUG("%s auth_req=0x%x", __func__, auth_req);
p_cb->cb_evt = 0;
btm_ble_link_sec_check(p_cb->pairing_bda, auth_req, &sec_req_act);
SMP_TRACE_DEBUG("%s sec_req_act=0x%x", __func__, sec_req_act);
SMP_TRACE_DEBUG("%s auth_req=0x%x sec_req_act=0x%x", __func__, auth_req, sec_req_act);
switch (sec_req_act) {
case BTM_BLE_SEC_REQ_ACT_ENCRYPT:
@@ -475,6 +469,8 @@ void smp_proc_sec_req(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
/* respond to non SC pairing request as failure in SC only mode */
if (p_cb->secure_connections_only_mode_required &&
(auth_req & SMP_SC_SUPPORT_BIT) == 0) {
SMP_TRACE_ERROR("%s SC mode not support, auth_req=0x%x",
__func__, auth_req);
reason = SMP_PAIR_AUTH_FAIL;
smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason);
} else {
@@ -503,7 +499,7 @@ void smp_proc_sec_req(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
void smp_proc_sec_grant(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
UINT8 res = *(UINT8 *)p_data;
SMP_TRACE_DEBUG("%s", __func__);
SMP_TRACE_DEBUG("%s res=0x%x", __func__, res);
if (res != SMP_SUCCESS) {
smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, p_data);
} else { /*otherwise, start pairing */
@@ -560,7 +556,7 @@ void smp_proc_pair_cmd(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
UINT8 reason = SMP_ENC_KEY_SIZE;
tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev (p_cb->pairing_bda);
SMP_TRACE_DEBUG("%s\n", __func__);
SMP_TRACE_DEBUG("%s", __func__);
/* erase all keys if it is slave proc pairing req*/
if (p_dev_rec && (p_cb->role == HCI_ROLE_SLAVE)) {
btm_sec_clear_ble_keys(p_dev_rec);
@@ -682,7 +678,7 @@ void smp_proc_confirm(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
UINT8 *p = (UINT8 *)p_data;
UINT8 reason = SMP_INVALID_PARAMETERS;
SMP_TRACE_DEBUG("%s\n", __func__);
SMP_TRACE_DEBUG("%s", __func__);
if (smp_command_has_invalid_parameters(p_cb)) {
smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason);
@@ -1170,6 +1166,7 @@ void smp_proc_compare(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
}
} else {
SMP_TRACE_ERROR("%s pairing failed - check confirm value error", __func__);
reason = p_cb->failure = SMP_CONFIRM_VALUE_ERR;
smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason);
}
@@ -1213,6 +1210,7 @@ void smp_start_enc(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
}
if (cmd != BTM_CMD_STARTED && cmd != BTM_BUSY) {
SMP_TRACE_ERROR("%s start encryption failed, cmd=0x%x", __func__, cmd);
smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason);
}
}
@@ -1239,7 +1237,7 @@ void smp_enc_cmpl(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
UINT8 enc_enable = *(UINT8 *)p_data;
UINT8 reason = enc_enable ? SMP_SUCCESS : SMP_ENC_FAIL;
SMP_TRACE_DEBUG("%s\n", __func__);
SMP_TRACE_DEBUG("%s %u", __func__, enc_enable);
smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason);
}
@@ -236,7 +236,7 @@ BOOLEAN SMP_PairCancel (BD_ADDR bd_addr)
if ( (p_cb->state != SMP_STATE_IDLE) &&
(!memcmp (p_cb->pairing_bda, bd_addr, BD_ADDR_LEN)) ) {
p_cb->is_pair_cancel = TRUE;
SMP_TRACE_DEBUG("Cancel Pairing: set fail reason Unknown");
SMP_TRACE_ERROR("%s Cancel Pairing: set fail reason Unknown", __func__);
smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &err_code);
status = TRUE;
}
@@ -434,6 +434,8 @@ void SMP_OobDataReply(BD_ADDR bd_addr, tSMP_STATUS res, UINT8 len, UINT8 *p_data
}
if (res != SMP_SUCCESS || len == 0 || !p_data) {
SMP_TRACE_ERROR("%s pairing failed, res=0x%x len=%u p_data=%p",
__func__, res, len, p_data);
smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &failure);
} else {
if (len > BT_OCTET16_LEN) {
@@ -524,10 +526,10 @@ void SMP_SecureConnectionOobDataReply(UINT8 *p_data)
** Description This function is called to encrypt the data with the specified
** key
**
** Parameters: key - Pointer to key key[0] conatins the MSB
** Parameters: key - Pointer to key key[0] contains the MSB
** key_len - key length
** plain_text - Pointer to data to be encrypted
** plain_text[0] conatins the MSB
** plain_text[0] contains the MSB
** pt_len - plain text length
** p_out - output of the encrypted texts
**
@@ -332,7 +332,7 @@ void smp_generate_stk(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
output.opcode = HCI_BLE_ENCRYPT;
memcpy(output.param_buf, p_cb->ltk, SMP_ENCRYT_DATA_SIZE);
} else if (!smp_calculate_legacy_short_term_key(p_cb, &output)) {
SMP_TRACE_ERROR("%s failed", __func__);
SMP_TRACE_ERROR("%s pairing failed", __func__);
smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &status);
return;
}
@@ -459,7 +459,7 @@ void smp_compute_csrk(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
UINT16_TO_STREAM(p, r);
if (!SMP_Encrypt(er, BT_OCTET16_LEN, buffer, 4, &output)) {
SMP_TRACE_ERROR("smp_generate_csrk failed\n");
SMP_TRACE_ERROR("%s pairing failed", __func__);
if (p_cb->smp_over_br) {
#if (CLASSIC_BT_INCLUDED == TRUE)
smp_br_state_machine_event(p_cb, SMP_BR_AUTH_CMPL_EVT, &status);
@@ -549,7 +549,7 @@ void smp_concatenate_peer( tSMP_CB *p_cb, UINT8 **p_data, UINT8 op_code)
** Function smp_gen_p1_4_confirm
**
** Description Generate Confirm/Compare Step1:
** p1 = pres || preq || rat' || iat'
** p1 = press || preq || rat' || iat'
**
** Returns void
**
@@ -574,22 +574,22 @@ void smp_gen_p1_4_confirm( tSMP_CB *p_cb, BT_OCTET16 p1)
UINT8_TO_STREAM(p, p_cb->addr_type);
/* LSB : iat': responder's address type */
UINT8_TO_STREAM(p, addr_type);
/* concatinate preq */
/* concatenate preq */
smp_concatenate_local(p_cb, &p, SMP_OPCODE_PAIRING_REQ);
/* concatinate pres */
/* concatenate press */
smp_concatenate_peer(p_cb, &p, SMP_OPCODE_PAIRING_RSP);
} else {
/* LSB : iat': initiator's address type */
UINT8_TO_STREAM(p, addr_type);
/* LSB : rat': responder's(local) address type */
UINT8_TO_STREAM(p, p_cb->addr_type);
/* concatinate preq */
/* concatenate preq */
smp_concatenate_peer(p_cb, &p, SMP_OPCODE_PAIRING_REQ);
/* concatinate pres */
/* concatenate press */
smp_concatenate_local(p_cb, &p, SMP_OPCODE_PAIRING_RSP);
}
#if SMP_DEBUG == TRUE
SMP_TRACE_DEBUG("p1 = pres || preq || rat' || iat'\n");
SMP_TRACE_DEBUG("p1 = press || preq || rat' || iat'\n");
smp_debug_print_nbyte_little_endian ((UINT8 *)p1, (const UINT8 *)"P1", 16);
#endif
}
@@ -654,7 +654,7 @@ void smp_calculate_comfirm (tSMP_CB *p_cb, BT_OCTET16 rand, BD_ADDR bda)
tSMP_STATUS status = SMP_PAIR_FAIL_UNKNOWN;
SMP_TRACE_DEBUG ("smp_calculate_comfirm \n");
/* generate p1 = pres || preq || rat' || iat' */
/* generate p1 = press || preq || rat' || iat' */
smp_gen_p1_4_confirm(p_cb, p1);
/* p1 = rand XOR p1 */
@@ -664,7 +664,7 @@ void smp_calculate_comfirm (tSMP_CB *p_cb, BT_OCTET16 rand, BD_ADDR bda)
/* calculate e(k, r XOR p1), where k = TK */
if (!SMP_Encrypt(p_cb->tk, BT_OCTET16_LEN, p1, BT_OCTET16_LEN, &output)) {
SMP_TRACE_ERROR("smp_generate_csrk failed");
SMP_TRACE_ERROR("%s calculate TK failed", __func__);
smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &status);
} else {
smp_calculate_comfirm_cont(p_cb, &output);
@@ -701,7 +701,7 @@ static void smp_calculate_comfirm_cont(tSMP_CB *p_cb, tSMP_ENC *p)
/* calculate: Confirm = E(k, p1' XOR p2) */
if (!SMP_Encrypt(p_cb->tk, BT_OCTET16_LEN, p2, BT_OCTET16_LEN, &output)) {
SMP_TRACE_ERROR("smp_calculate_comfirm_cont failed\n");
SMP_TRACE_ERROR("%s pairing failed", __func__);
smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &status);
} else {
SMP_TRACE_DEBUG("p_cb->rand_enc_proc_state=%d\n", p_cb->rand_enc_proc_state);
@@ -861,7 +861,7 @@ static void smp_generate_ltk_cont(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
/* LTK = d1(ER, DIV, 0)= e(ER, DIV)*/
if (!SMP_Encrypt(er, BT_OCTET16_LEN, (UINT8 *)&p_cb->div,
sizeof(UINT16), &output)) {
SMP_TRACE_ERROR("%s failed\n", __func__);
SMP_TRACE_ERROR("%s failed", __func__);
smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &status);
} else {
/* mask the LTK */
@@ -1373,6 +1373,8 @@ void smp_calculate_numeric_comparison_display_number(tSMP_CB *p_cb,
}
if (p_cb->number_to_display >= (BTM_MAX_PASSKEY_VAL + 1)) {
SMP_TRACE_ERROR("%s pairing failed - invalid number to display %u",
__func__, p_cb->number_to_display);
UINT8 reason;
reason = p_cb->failure = SMP_PAIR_FAIL_UNKNOWN;
smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason);
@@ -366,6 +366,7 @@ BOOLEAN smp_send_cmd(UINT8 cmd_code, tSMP_CB *p_cb)
}
if (!sent) {
SMP_TRACE_ERROR("%s failed, cmd_code=0x%02x", __func__, cmd_code);
if (p_cb->smp_over_br) {
#if (CLASSIC_BT_INCLUDED == TRUE)
smp_br_state_machine_event(p_cb, SMP_BR_AUTH_CMPL_EVT, &failure);
@@ -392,7 +393,7 @@ void smp_rsp_timeout(TIMER_LIST_ENT *p_tle)
UINT8 failure = SMP_RSP_TIMEOUT;
UNUSED(p_tle);
SMP_TRACE_EVENT("%s state:%d br_state:%d", __FUNCTION__, p_cb->state, p_cb->br_state);
SMP_TRACE_ERROR("%s state=%d br_state=%d", __func__, p_cb->state, p_cb->br_state);
if (p_cb->smp_over_br) {
#if (CLASSIC_BT_INCLUDED == TRUE)