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

Commit 0bf66a0b authored by Andre Eisenbach's avatar Andre Eisenbach Committed by Matthew Xie
Browse files

LE: UPF 45 bug fixes

This change fixes the following issues:
- Second GATT-over-BR/EDR channel cannot be established when there
  already is an existing GATT-over-BR/EDR channel
- If encryption fails for an LE connection due to a missing key,
  the security state is not being cleared and blocks all further
  security processing
- When DM discovery of an LE Peripheral device fails with a
  connection timeout, no further discovery requests can be made
- GATT service discovery can get into endless loop when duplicate descriptor
  definitions are found on the remote device
- When GATT over BR/EDR fails, BTA does not give a connection
  callback to the application initiating the connection
- BR/EDR connection to remote platform does not generate API callbacks
- Stack crash discovered during UPF after remote disconnects
- The host is sending HCI disconnect to invalid HCI handle when
  SMP fails because of a connection timeout
- Possible race condition:
  If a disconnect is immediately followed by a connection complete,
  the connection complete cannot be processed in the BTA GATT state
  machine
- Write Complete event is not triggered for Prepare Write requests

Change-Id: I539cdedd68007818ff4f0d0213cee1c913f72d0f

Conflicts:
	bta/gatt/bta_gatts_act.c
parent e9235ff6
Loading
Loading
Loading
Loading
+50 −23
Original line number Diff line number Diff line
@@ -92,9 +92,6 @@ static void bta_dm_sys_hw_cback( tBTA_SYS_HW_EVT status );
static BOOLEAN bta_dm_dev_blacklisted_for_switch (BD_ADDR remote_bd_addr);
static void bta_dm_delay_role_switch_cback (TIMER_LIST_ENT *p_tle);

static void bta_dm_remove_sec_dev_entry(BD_ADDR remote_bd_addr);


static void bta_dm_disable_search_and_disc(void);
#if ((defined BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
    #if ((defined SMP_INCLUDED) && (SMP_INCLUDED == TRUE))
@@ -110,6 +107,8 @@ static void bta_dm_gattc_callback(tBTA_GATTC_EVT event, tBTA_GATTC *p_data);
static void bta_dm_observe_results_cb (tBTM_INQ_RESULTS *p_inq, UINT8 *p_eir);
static void bta_dm_observe_cmpl_cb (void * p_result);

static void bta_dm_remove_sec_dev_entry(BD_ADDR remote_bd_addr);

#ifndef BTA_DM_BLE_ADV_CHNL_MAP
#define BTA_DM_BLE_ADV_CHNL_MAP (BTM_BLE_ADV_CHNL_37|BTM_BLE_ADV_CHNL_38|BTM_BLE_ADV_CHNL_39)
#endif
@@ -193,6 +192,7 @@ const UINT32 bta_service_id_to_btm_srv_id_lkup_tbl [BTA_MAX_SERVICE_ID] =
#if BLE_INCLUDED && BTA_GATT_INCLUDED
    ,BTM_SEC_SERVICE_ATT                    /* BTA_GATT_SERVICE_ID */
#endif

};

/* bta security callback */
@@ -267,7 +267,6 @@ void bta_dm_enable(tBTA_DM_MSG *p_data)
    tBTA_SYS_HW_MSG *sys_enable_event;
    tBTA_DM_SEC sec_event;


    /* if already in use, return an error */
    if( bta_dm_cb.is_bta_dm_active == TRUE  )
    {
@@ -279,7 +278,6 @@ void bta_dm_enable(tBTA_DM_MSG *p_data)
        return;
    }


    /* first, register our callback to SYS HW manager */
    bta_sys_hw_register( BTA_SYS_HW_BLUETOOTH, bta_dm_sys_hw_cback );

@@ -382,6 +380,7 @@ static void bta_dm_sys_hw_cback( tBTA_SYS_HW_EVT status )
        {
            BTM_BleLoadLocalKeys(BTA_BLE_LOCAL_KEY_TYPE_ID, (tBTM_BLE_LOCAL_KEYS *)&id_key);
        }
        bta_dm_search_cb.conn_id = BTA_GATT_INVALID_CONN_ID;
#endif

        BTM_SecRegister((tBTM_APPL_INFO*)&bta_security);
@@ -2353,11 +2352,6 @@ static void bta_dm_discover_device(BD_ADDR remote_bd_addr)
{
    tBTA_DM_MSG * p_msg;

#if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE
    tBT_DEVICE_TYPE dev_type;
    tBLE_ADDR_TYPE  addr_type;
#endif

    APPL_TRACE_DEBUG6("bta_dm_discover_device, BDA:0x%02X%02X%02X%02X%02X%02X",
                        remote_bd_addr[0],remote_bd_addr[1],
                        remote_bd_addr[2],remote_bd_addr[3],
@@ -2434,9 +2428,7 @@ static void bta_dm_discover_device(BD_ADDR remote_bd_addr)
                                    bta_dm_search_cb.services_to_search
                                    );
            }
            BTM_ReadDevInfo(remote_bd_addr, &dev_type, &addr_type);

            if (dev_type == BT_DEVICE_TYPE_BLE)
            if (BTM_UseLeLink(bta_dm_search_cb.peer_bdaddr))
            /*
            if ( bta_dm_search_cb.p_btm_inq_info != NULL &&
                 bta_dm_search_cb.p_btm_inq_info->results.device_type == BT_DEVICE_TYPE_BLE &&
@@ -2656,10 +2648,6 @@ static void bta_dm_service_search_remname_cback (BD_ADDR bd_addr, DEV_CLASS dc,
static void bta_dm_remname_cback (tBTM_REMOTE_DEV_NAME *p_remote_name)
{
    tBTA_DM_REM_NAME * p_msg;
#if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE
    tBT_DEVICE_TYPE dev_type;
    tBLE_ADDR_TYPE  addr_type;
#endif

    APPL_TRACE_DEBUG2("bta_dm_remname_cback len = %d name=<%s>", p_remote_name->length,
                      p_remote_name->remote_bd_name);
@@ -2671,8 +2659,7 @@ static void bta_dm_remname_cback (tBTM_REMOTE_DEV_NAME *p_remote_name)

    BTM_SecDeleteRmtNameNotifyCallback(&bta_dm_service_search_remname_cback);
#if BLE_INCLUDED == TRUE
    BTM_ReadDevInfo(p_remote_name->remote_bd_name, &dev_type, &addr_type);
    if (dev_type == BT_DEVICE_TYPE_BLE)
    if (BTM_UseLeLink(bta_dm_search_cb.peer_bdaddr))
        GAP_BleReadPeerPrefConnParams (bta_dm_search_cb.peer_bdaddr);
#endif
    if ((p_msg = (tBTA_DM_REM_NAME *) GKI_getbuf(sizeof(tBTA_DM_REM_NAME))) != NULL)
@@ -2958,6 +2945,7 @@ static UINT8 bta_dm_authentication_complete_cback(BD_ADDR bd_addr, DEV_CLASS dev
        }
        /* delete this device entry from Sec Dev DB */
        bta_dm_remove_sec_dev_entry(bd_addr);

    }

    return BTM_SUCCESS;
@@ -3188,7 +3176,6 @@ static void bta_dm_signal_strength_timer_cback (TIMER_LIST_ENT *p_tle)
*******************************************************************************/
static void bta_dm_bl_change_cback (tBTM_BL_EVENT_DATA *p_data)
{

    tBTA_DM_ACL_CHANGE * p_msg;

    if ((p_msg = (tBTA_DM_ACL_CHANGE *) GKI_getbuf(sizeof(tBTA_DM_ACL_CHANGE))) != NULL)
@@ -3763,6 +3750,7 @@ static void bta_dm_remove_sec_dev_entry(BD_ADDR remote_bd_addr)
    }
}


/*******************************************************************************
**
** Function         bta_dm_adjust_roles
@@ -4974,6 +4962,9 @@ void bta_dm_ble_observe (tBTA_DM_MSG *p_data)
}

#if ((defined BTA_GATT_INCLUDED) &&  (BTA_GATT_INCLUDED == TRUE))
#ifndef BTA_DM_GATT_CLOSE_DELAY_TOUT
#define BTA_DM_GATT_CLOSE_DELAY_TOUT    1000
#endif

/*******************************************************************************
**
@@ -5133,13 +5124,39 @@ static void bta_dm_gatt_disc_complete(UINT16 conn_id, tBTA_GATT_STATUS status)
        }
        if (conn_id != BTA_GATT_INVALID_CONN_ID)
        {
            BTA_GATTC_Close(conn_id);
            if (BTA_DM_GATT_CLOSE_DELAY_TOUT != 0)
            {
                bta_sys_start_timer(&bta_dm_search_cb.gatt_close_timer, BTA_DM_DISC_CLOSE_TOUT_EVT,
                                     BTA_DM_GATT_CLOSE_DELAY_TOUT);
            }
            else
            {
                BTA_GATTC_Close(conn_id);
                bta_dm_search_cb.conn_id = BTA_GATT_INVALID_CONN_ID;
            }
        }

        bta_dm_search_cb.gatt_disc_active = FALSE;
    }
}

/*******************************************************************************
**
** Function         bta_dm_close_gatt_conn
**
** Description      This function close the GATT connection after delay timeout.
**
** Parameters:
**
*******************************************************************************/
void bta_dm_close_gatt_conn(tBTA_DM_MSG *p_data)
{
    if (bta_dm_search_cb.conn_id != BTA_GATT_INVALID_CONN_ID)
        BTA_GATTC_Close(bta_dm_search_cb.conn_id);

    bta_dm_search_cb.conn_id = BTA_GATT_INVALID_CONN_ID;
}

/*******************************************************************************
**
** Function         btm_dm_start_gatt_discovery
@@ -5153,6 +5170,16 @@ static void bta_dm_gatt_disc_complete(UINT16 conn_id, tBTA_GATT_STATUS status)
void btm_dm_start_gatt_discovery (BD_ADDR bd_addr)
{
    bta_dm_search_cb.gatt_disc_active = TRUE;

    /* connection is already open */
    if (bdcmp(bta_dm_search_cb.pending_close_bda, bd_addr) == 0 &&
        bta_dm_search_cb.conn_id != BTA_GATT_INVALID_CONN_ID)
    {
        memset(bta_dm_search_cb.pending_close_bda, 0, BD_ADDR_LEN);
        bta_sys_stop_timer(&bta_dm_search_cb.gatt_close_timer);
        btm_dm_start_disc_gatt_services(bta_dm_search_cb.conn_id);
    }
    else
        BTA_GATTC_Open(bta_dm_search_cb.client_if, bd_addr, TRUE);
}

+5 −2
Original line number Diff line number Diff line
@@ -128,8 +128,8 @@ enum
    BTA_DM_SDP_RESULT_EVT,
    BTA_DM_SEARCH_CMPL_EVT,
    BTA_DM_DISCOVERY_RESULT_EVT,
    BTA_DM_API_DI_DISCOVER_EVT

    BTA_DM_API_DI_DISCOVER_EVT,
    BTA_DM_DISC_CLOSE_TOUT_EVT
};

/* data type for BTA_DM_API_ENABLE_EVT */
@@ -818,6 +818,8 @@ typedef struct
    UINT8 *                 p_ble_rawdata;
    UINT32                 ble_raw_size;
    UINT32                 ble_raw_used;
    TIMER_LIST_ENT         gatt_close_timer;
    BD_ADDR                pending_close_bda;
#endif
#endif

@@ -991,6 +993,7 @@ extern void bta_dm_security_grant (tBTA_DM_MSG *p_data);
extern void bta_dm_ble_set_bg_conn_type (tBTA_DM_MSG *p_data);
extern void bta_dm_ble_set_conn_params (tBTA_DM_MSG *p_data);
extern void bta_dm_ble_set_scan_params (tBTA_DM_MSG *p_data);
extern void bta_dm_close_gatt_conn(tBTA_DM_MSG *p_data);
extern void bta_dm_ble_observe (tBTA_DM_MSG *p_data);
#endif
extern void bta_dm_set_encryption(tBTA_DM_MSG *p_data);
+28 −9
Original line number Diff line number Diff line
@@ -61,18 +61,18 @@ const tBTA_DM_ACTION bta_dm_action[] =
    bta_dm_close_acl,         /* 10 BTA_DM_API_ADD_DEVICE_EVT */

    /* security API events */
    bta_dm_bond,              /* 10  BTA_DM_API_BOND_EVT */
    bta_dm_bond_cancel,       /* 11  BTA_DM_API_BOND_CANCEL_EVT */
    bta_dm_pin_reply,         /* 12 BTA_DM_API_PIN_REPLY_EVT */
    bta_dm_link_policy,       /* 13 BTA_DM_API_LINK_POLICY_EVT */
    bta_dm_auth_reply,        /* 14 BTA_DM_API_AUTH_REPLY_EVT */
    bta_dm_bond,              /* 11  BTA_DM_API_BOND_EVT */
    bta_dm_bond_cancel,       /* 12  BTA_DM_API_BOND_CANCEL_EVT */
    bta_dm_pin_reply,         /* 13 BTA_DM_API_PIN_REPLY_EVT */
    bta_dm_link_policy,       /* 14 BTA_DM_API_LINK_POLICY_EVT */
    bta_dm_auth_reply,        /* 15 BTA_DM_API_AUTH_REPLY_EVT */

    /* power manger events */
    bta_dm_pm_btm_status,     /* 15 BTA_DM_PM_BTM_STATUS_EVT */
    bta_dm_pm_timer,          /* 16 BTA_DM_PM_TIMER_EVT*/
    bta_dm_pm_btm_status,     /* 16 BTA_DM_PM_BTM_STATUS_EVT */
    bta_dm_pm_timer,          /* 17 BTA_DM_PM_TIMER_EVT*/

    /* simple pairing events */
    bta_dm_confirm,           /* 17 BTA_DM_API_CONFIRM_EVT */
    bta_dm_confirm,           /* 18 BTA_DM_API_CONFIRM_EVT */

    bta_dm_set_encryption,    /* BTA_DM_API_SET_ENCRYPTION_EVT */

@@ -134,7 +134,10 @@ enum
    BTA_DM_SEARCH_CANCEL_TRANSAC_CMPL,  /* 15 bta_dm_search_cancel_transac_cmpl */
    BTA_DM_DISC_RMT_NAME,               /* 16 bta_dm_disc_rmt_name */
    BTA_DM_API_DI_DISCOVER,             /* 17 bta_dm_di_disc */
    BTA_DM_SEARCH_NUM_ACTIONS           /* 18 */
#if BLE_INCLUDED == TRUE
    BTA_DM_CLOSE_GATT_CONN,             /* 18 bta_dm_close_gatt_conn */
#endif
    BTA_DM_SEARCH_NUM_ACTIONS           /* 19 */
};


@@ -160,6 +163,9 @@ const tBTA_DM_ACTION bta_dm_search_action[] =
  bta_dm_search_cancel_transac_cmpl, /* 15 BTA_DM_SEARCH_CANCEL_TRANSAC_CMPL */
  bta_dm_disc_rmt_name,             /* 16 BTA_DM_DISC_RMT_NAME */
  bta_dm_di_disc                    /* 17 BTA_DM_API_DI_DISCOVER */
#if BLE_INCLUDED == TRUE
  ,bta_dm_close_gatt_conn
#endif
};

#define BTA_DM_SEARCH_IGNORE       BTA_DM_SEARCH_NUM_ACTIONS
@@ -184,6 +190,9 @@ const UINT8 bta_dm_search_idle_st_table[][BTA_DM_SEARCH_NUM_COLS] =
/* SEARCH_CMPL_EVT */       {BTA_DM_SEARCH_IGNORE,             BTA_DM_SEARCH_IGNORE,          BTA_DM_SEARCH_IDLE},
/* DISCV_RES_EVT */         {BTA_DM_SEARCH_IGNORE,             BTA_DM_SEARCH_IGNORE,          BTA_DM_SEARCH_IDLE},
/* API_DI_DISCOVER_EVT */   {BTA_DM_API_DI_DISCOVER,           BTA_DM_SEARCH_IGNORE,          BTA_DM_SEARCH_ACTIVE}
#if BLE_INCLUDED == TRUE
/* DISC_CLOSE_TOUT_EVT */   ,{BTA_DM_CLOSE_GATT_CONN,           BTA_DM_SEARCH_IGNORE,          BTA_DM_SEARCH_IDLE}
#endif

};
const UINT8 bta_dm_search_search_active_st_table[][BTA_DM_SEARCH_NUM_COLS] =
@@ -200,6 +209,9 @@ const UINT8 bta_dm_search_search_active_st_table[][BTA_DM_SEARCH_NUM_COLS] =
/* DISCV_RES_EVT */         {BTA_DM_SEARCH_RESULT,             BTA_DM_SEARCH_IGNORE,          BTA_DM_SEARCH_ACTIVE},
/* API_DI_DISCOVER_EVT */   {BTA_DM_SEARCH_IGNORE,             BTA_DM_SEARCH_IGNORE,          BTA_DM_SEARCH_ACTIVE}

#if BLE_INCLUDED == TRUE
/* DISC_CLOSE_TOUT_EVT */   ,{BTA_DM_SEARCH_IGNORE,             BTA_DM_SEARCH_IGNORE,          BTA_DM_SEARCH_ACTIVE}
#endif

};

@@ -217,6 +229,9 @@ const UINT8 bta_dm_search_search_cancelling_st_table[][BTA_DM_SEARCH_NUM_COLS] =
/* DISCV_RES_EVT */         {BTA_DM_SEARCH_CANCEL_TRANSAC_CMPL, BTA_DM_SEARCH_CANCEL_CMPL,     BTA_DM_SEARCH_IDLE},
/* API_DI_DISCOVER_EVT */   {BTA_DM_SEARCH_IGNORE,              BTA_DM_SEARCH_IGNORE,          BTA_DM_SEARCH_CANCELLING}

#if BLE_INCLUDED == TRUE
/* DISC_CLOSE_TOUT_EVT */   ,{BTA_DM_SEARCH_IGNORE,              BTA_DM_SEARCH_IGNORE,          BTA_DM_SEARCH_CANCELLING}
#endif

};

@@ -234,6 +249,10 @@ const UINT8 bta_dm_search_disc_active_st_table[][BTA_DM_SEARCH_NUM_COLS] =
/* DISCV_RES_EVT */         {BTA_DM_DISC_RESULT,               BTA_DM_SEARCH_IGNORE,          BTA_DM_DISCOVER_ACTIVE},
/* API_DI_DISCOVER_EVT */   {BTA_DM_SEARCH_IGNORE,             BTA_DM_SEARCH_IGNORE,          BTA_DM_DISCOVER_ACTIVE}

#if BLE_INCLUDED == TRUE
/* DISC_CLOSE_TOUT_EVT */   ,{BTA_DM_SEARCH_IGNORE,             BTA_DM_SEARCH_IGNORE,          BTA_DM_DISCOVER_ACTIVE}
#endif

};

typedef const UINT8 (*tBTA_DM_ST_TBL)[BTA_DM_SEARCH_NUM_COLS];
+38 −95
Original line number Diff line number Diff line
@@ -471,7 +471,7 @@ void bta_gattc_open(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
                                      p_data->api_conn.remote_bda,
                                      &p_clcb->bta_conn_id))
        {
            gattc_data.hdr.layer_specific = p_clcb->bta_conn_id;
            gattc_data.int_conn.hdr.layer_specific = p_clcb->bta_conn_id;

            bta_gattc_sm_execute(p_clcb, BTA_GATTC_INT_CONN_EVT, &gattc_data);
        }
@@ -511,7 +511,7 @@ void bta_gattc_init_bk_conn(tBTA_GATTC_API_OPEN *p_data, tBTA_GATTC_RCB *p_clreg
                                          p_data->remote_bda,
                                          &conn_id))
            {
                if ((p_clcb = bta_gattc_clcb_alloc(p_data->client_if, p_data->remote_bda)) != NULL)
                if ((p_clcb = bta_gattc_find_alloc_clcb(p_data->client_if, p_data->remote_bda)) != NULL)
                {
                    gattc_data.hdr.layer_specific = p_clcb->bta_conn_id = conn_id;

@@ -628,11 +628,11 @@ void bta_gattc_conn(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
    if (p_data != NULL)
    {
        APPL_TRACE_DEBUG1("bta_gattc_conn conn_id=%d",p_data->hdr.layer_specific);
        p_clcb->bta_conn_id  = p_data->int_conn.hdr.layer_specific;
        GATT_GetConnectionInfor(p_data->int_conn.hdr.layer_specific, &gatt_if, p_clcb->bda);
    }

        p_clcb->p_srcb->connected = TRUE;
        p_clcb->bta_conn_id  = p_data->hdr.layer_specific;
        GATT_GetConnectionInfor(p_data->hdr.layer_specific, &gatt_if, p_clcb->bda);

        /* start database cache if needed */
        if (p_clcb->p_srcb->p_srvc_cache == NULL ||
            p_clcb->p_srcb->state != BTA_GATTC_SERV_IDLE)
@@ -640,7 +640,7 @@ void bta_gattc_conn(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
            if (p_clcb->p_srcb->state == BTA_GATTC_SERV_IDLE)
            {
                p_clcb->p_srcb->state = BTA_GATTC_SERV_LOAD;
                bta_gattc_sm_execute(p_clcb, BTA_GATTC_START_CACHE_EVT, p_data);
                bta_gattc_sm_execute(p_clcb, BTA_GATTC_START_CACHE_EVT, NULL);
            }
            else /* cache is building */
                p_clcb->state = BTA_GATTC_DISCOVER_ST;
@@ -668,7 +668,6 @@ void bta_gattc_conn(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
                                      p_clcb->bta_conn_id);
        }
    }
}
/*******************************************************************************
**
** Function         bta_gattc_close_fail
@@ -721,19 +720,13 @@ void bta_gattc_close(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
    if (!BTM_IsBleLink(p_clcb->bda))
        bta_sys_conn_close( BTA_ID_GATTC ,BTA_ALL_APP_ID, p_clcb->bda);

    if (p_clcb->status == BTA_GATT_OK)
    {
    bta_gattc_clcb_dealloc(p_clcb);
    }

    if (p_data->hdr.event == BTA_GATTC_API_CLOSE_EVT)
        cb_data.close.status = GATT_Disconnect(p_data->hdr.layer_specific);

    if ((p_cback != NULL) && (*p_cback != NULL))
    {
    if(p_cback)
        (* p_cback)(BTA_GATTC_CLOSE_EVT,   (tBTA_GATTC *)&cb_data);
    }


    if (p_clreg->num_clcb == 0 && p_clreg->dereg_pending)
    {
@@ -955,7 +948,7 @@ void bta_gattc_read(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
        if ((handle = bta_gattc_id2handle(p_clcb->p_srcb,
                                          &p_data->api_read.srvc_id,
                                          &p_data->api_read.char_id,
                                          p_data->api_read.descr_type)) == 0)
                                          p_data->api_read.p_descr_type)) == 0)
        {
            op_cmpl.status = BTA_GATT_ERROR;
        }
@@ -992,11 +985,9 @@ void bta_gattc_read_multi(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
    tGATT_READ_PARAM    read_param;
    tBTA_GATTC_OP_CMPL  op_cmpl;
    tBTA_GATTC_ATTR_ID  *p_id;
    tBT_UUID            dummy_uuid;

    if (bta_gattc_enqueue(p_clcb, p_data))
    {
        memset(&dummy_uuid, 0, sizeof(tBT_UUID));
        memset(&read_param, 0, sizeof(tGATT_READ_PARAM));

        p_id = p_data->api_read_multi.p_id_list;
@@ -1010,14 +1001,14 @@ void bta_gattc_read_multi(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
                handle = bta_gattc_id2handle(p_clcb->p_srcb,
                                     &p_id->id_value.char_id.srvc_id,
                                     &p_id->id_value.char_id.char_id,
                                     dummy_uuid);
                                     NULL);
            }
            else if (p_id->id_type == BTA_GATT_TYPE_CHAR_DESCR)
            {
                handle = bta_gattc_id2handle(p_clcb->p_srcb,
                                     &p_id->id_value.char_descr_id.char_id.srvc_id,
                                     &p_id->id_value.char_descr_id.char_id.char_id,
                                     p_id->id_value.char_descr_id.descr_type);
                                     &p_id->id_value.char_descr_id.descr_id);
            }
            else
            {
@@ -1072,7 +1063,7 @@ void bta_gattc_write(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
        if ((handle = bta_gattc_id2handle(p_clcb->p_srcb,
                                          &p_data->api_write.srvc_id,
                                          &p_data->api_write.char_id,
                                          p_data->api_write.descr_type)) == 0)
                                          p_data->api_write.p_descr_type)) == 0)
        {
            status = BTA_GATT_ERROR;
        }
@@ -1143,12 +1134,11 @@ void bta_gattc_execute(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
void bta_gattc_confirm(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
{
    UINT16 handle;
    tBT_UUID    null_uuid = {0};

    if ((handle = bta_gattc_id2handle(p_clcb->p_srcb,
                                      &p_data->api_confirm.srvc_id,
                                      &p_data->api_confirm.char_id,
                                      null_uuid)) == 0)
                                      NULL)) == 0)
    {
        APPL_TRACE_ERROR0("Can not map service/char ID into valid handle");
    }
@@ -1165,7 +1155,6 @@ void bta_gattc_confirm(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
            bta_sys_busy(BTA_ID_GATTC, BTA_ALL_APP_ID, p_clcb->bda);
            bta_sys_idle(BTA_ID_GATTC, BTA_ALL_APP_ID, p_clcb->bda);
        }

    }
}
/*******************************************************************************
@@ -1202,7 +1191,7 @@ void bta_gattc_read_cmpl(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_OP_CMPL *p_data)
        else
        {
            cb_data.read.status = bta_gattc_pack_read_cb_data(p_clcb->p_srcb,
                                                              cb_data.read.descr_type,
                                                              &cb_data.read.descr_type.uuid,
                                                              &p_data->p_cmpl->att_value,
                                                              &read_value);
            cb_data.read.p_value = &read_value;
@@ -1212,10 +1201,11 @@ void bta_gattc_read_cmpl(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_OP_CMPL *p_data)
    {
        cb_data.read.srvc_id = p_clcb->p_q_cmd->api_read.srvc_id;
        cb_data.read.char_id = p_clcb->p_q_cmd->api_read.char_id;
        cb_data.read.descr_type = p_clcb->p_q_cmd->api_read.descr_type;
        if (p_clcb->p_q_cmd->api_read.p_descr_type)
            memcpy(&cb_data.read.descr_type, p_clcb->p_q_cmd->api_read.p_descr_type, sizeof(tBTA_GATT_ID));
    }

    event = (p_clcb->p_q_cmd->api_read.descr_type.len == 0) ? BTA_GATTC_READ_CHAR_EVT: BTA_GATTC_READ_DESCR_EVT;
    event = (p_clcb->p_q_cmd->api_read.p_descr_type == NULL) ? BTA_GATTC_READ_CHAR_EVT: BTA_GATTC_READ_DESCR_EVT;
    cb_data.read.conn_id = p_clcb->bta_conn_id;

    utl_freebuf((void **)&p_clcb->p_q_cmd);
@@ -1237,6 +1227,8 @@ void bta_gattc_write_cmpl(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_OP_CMPL *p_data)
    tBTA_GATTC      cb_data = {0};
    UINT8          event;

    memset(&cb_data, 0, sizeof(tBTA_GATTC));

    cb_data.write.status     = p_data->status;

    if (p_data->p_cmpl != NULL)
@@ -1247,9 +1239,10 @@ void bta_gattc_write_cmpl(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_OP_CMPL *p_data)
    }
    else
    {
        cb_data.write.srvc_id = p_clcb->p_q_cmd->api_write.srvc_id;
        cb_data.write.char_id = p_clcb->p_q_cmd->api_write.char_id;
        cb_data.write.descr_type = p_clcb->p_q_cmd->api_write.descr_type;
        memcpy(&cb_data.write.srvc_id, &p_clcb->p_q_cmd->api_write.srvc_id, sizeof(tBTA_GATT_SRVC_ID));
        memcpy(&cb_data.write.char_id, &p_clcb->p_q_cmd->api_write.char_id, sizeof(tBTA_GATT_ID));
        if (p_clcb->p_q_cmd->api_write.p_descr_type)
            memcpy(&cb_data.write.descr_type, p_clcb->p_q_cmd->api_write.p_descr_type, sizeof(tBTA_GATT_ID));
    }

    if (p_clcb->p_q_cmd->api_write.hdr.event == BTA_GATTC_API_WRITE_EVT &&
@@ -1257,7 +1250,7 @@ void bta_gattc_write_cmpl(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_OP_CMPL *p_data)

        event = BTA_GATTC_PREP_WRITE_EVT;

    else if (p_clcb->p_q_cmd->api_write.descr_type.len == 0)
    else if (p_clcb->p_q_cmd->api_write.p_descr_type == NULL)

        event = BTA_GATTC_WRITE_CHAR_EVT;

@@ -1392,7 +1385,7 @@ void bta_gattc_search(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
    {
        status = BTA_GATT_OK;
        /* search the local cache of a server device */
        bta_gattc_search_service(p_clcb, p_data->api_search.srvc_uuid);
        bta_gattc_search_service(p_clcb, p_data->api_search.p_srvc_uuid);
    }
    cb_data.search_cmpl.status  = status;
    cb_data.search_cmpl.conn_id = p_clcb->bta_conn_id;
@@ -1609,72 +1602,26 @@ static void bta_gattc_deregister_cmpl(tBTA_GATTC_RCB *p_clreg)
static void bta_gattc_conn_cback(tGATT_IF gattc_if, BD_ADDR bda, UINT16 conn_id,
                                 BOOLEAN connected, tGATT_DISCONN_REASON reason)
{
    BT_HDR          *p_buf;
    tBTA_GATTC_CLCB *p_clcb = NULL;
    UINT8           role ;
    tBTA_GATTC_DATA *p_buf;

    APPL_TRACE_DEBUG4("bta_gattc_conn_cback: cif = %d connected = %d conn_id = %d reaosn = 0x%04x",
                      gattc_if, connected, conn_id, reason);

    if (connected)
    if ((p_buf = (tBTA_GATTC_DATA *) GKI_getbuf(sizeof(tBTA_GATTC_DATA))) != NULL)
    {
        role = L2CA_GetBleConnRole(bda);
        memset(p_buf, 0, sizeof(tBTA_GATTC_DATA));

        if (role == HCI_ROLE_SLAVE)
            bta_gattc_conn_find_alloc(bda);

        /* outgoing connection : locate a logic channel */
        if ((p_clcb = bta_gattc_find_clcb_by_cif(gattc_if, bda)) == NULL)
        {
            /* for a background connection or listening connection */
            if (/* L2CA_GetBleConnRole(bda)== HCI_ROLE_MASTER && */
                bta_gattc_check_bg_conn(gattc_if, bda, role))
            {
                /* allocate a new channel */
                p_clcb = bta_gattc_clcb_alloc(gattc_if, bda);
            }
        }
        if (p_clcb != NULL)
        {
            p_clcb->bta_conn_id = conn_id;

            if ((p_buf = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL)
            {
                p_buf->event = BTA_GATTC_INT_CONN_EVT;
                p_buf->layer_specific = conn_id;
        p_buf->int_conn.hdr.event            = connected ? BTA_GATTC_INT_CONN_EVT: BTA_GATTC_INT_DISCONN_EVT;
        p_buf->int_conn.hdr.layer_specific   = conn_id;
        p_buf->int_conn.client_if            = gattc_if;
        p_buf->int_conn.role                 = L2CA_GetBleConnRole(bda);
        p_buf->int_conn.reason               = reason;
        bdcpy(p_buf->int_conn.remote_bda, bda);

                bta_sys_sendmsg(p_buf);
            }
        }
    }
    else
    {
#if BLE_INCLUDED == TRUE
        bta_gattc_conn_dealloc(bda);
#endif
        /* connection attempt timeout, send connection callback event */
        if (reason == GATT_CONN_CANCEL )
        {
            p_clcb = bta_gattc_find_alloc_clcb(gattc_if, bda);
            p_clcb->bta_conn_id = conn_id;
        }
        if ((p_clcb = bta_gattc_find_clcb_by_conn_id(conn_id)) != NULL)
        {
            if ((p_buf = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL)
            {
                p_buf->event = BTA_GATTC_INT_DISCONN_EVT;
                p_buf->layer_specific = conn_id;
                p_clcb->reason        = reason;

                bta_sys_sendmsg(p_buf);
            }
        }
        else
        {
            APPL_TRACE_DEBUG1(" connection ID: [%d] not used by BTA", conn_id);
        }
    }
}
/*******************************************************************************
**
** Function         bta_gattc_process_api_refresh
@@ -1750,8 +1697,8 @@ BOOLEAN bta_gattc_process_srvc_chg_ind(UINT16 conn_id,
    srvc_chg_uuid.len = 2;
    srvc_chg_uuid.uu.uuid16 = GATT_UUID_GATT_SRV_CHGD;

    if (bta_gattc_uuid_compare(p_notify->char_id.srvc_id.id.uuid, gattp_uuid, TRUE) &&
        bta_gattc_uuid_compare(p_notify->char_id.char_id.uuid, srvc_chg_uuid, TRUE))
    if (bta_gattc_uuid_compare(&p_notify->char_id.srvc_id.id.uuid, &gattp_uuid, TRUE) &&
        bta_gattc_uuid_compare(&p_notify->char_id.char_id.uuid, &srvc_chg_uuid, TRUE))
    {
        processed = TRUE;
        /* mark service handle change pending */
@@ -1879,11 +1826,7 @@ void bta_gattc_process_indicate(UINT16 conn_id, tGATTC_OPTYPE op, tGATT_CL_COMPL
                    {
                        p_clcb->bta_conn_id = conn_id;

                        /* send connection event */
                        bta_gattc_send_open_cback(p_clrcb,
                                                  BTA_GATT_OK,
                                                  remote_bda,
                                                  conn_id);
                        bta_gattc_sm_execute(p_clcb, BTA_GATTC_INT_CONN_EVT, NULL);
                    }
                    else
                    {
+22 −13

File changed.

Preview size limit exceeded, changes collapsed.

Loading