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

Commit f9eee5ef authored by Jakub Pawlowski's avatar Jakub Pawlowski Committed by Andre Eisenbach
Browse files

Use handles to identify GATT attributes (1/4)

Bug: 27778668
Change-Id: Id7454450c1ce2164001a1f9ca0b91f18d84e3fd6
parent 2ffd0555
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -5540,7 +5540,7 @@ static void bta_dm_gattc_callback(tBTA_GATTC_EVT event, tBTA_GATTC *p_data)
            break;

        case BTA_GATTC_SEARCH_RES_EVT:
            bta_dm_gatt_disc_result(p_data->srvc_res.service_uuid.id);
            bta_dm_gatt_disc_result(p_data->srvc_res.service_uuid);
            break;

        case BTA_GATTC_SEARCH_CMPL_EVT:
+44 −131
Original line number Diff line number Diff line
@@ -1086,21 +1086,12 @@ void bta_gattc_read(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
    if (!bta_gattc_enqueue(p_clcb, p_data))
        return;

    UINT16 handle = 0;
    tGATT_READ_PARAM    read_param;
    tBTA_GATT_STATUS    status;

    memset (&read_param, 0 ,sizeof(tGATT_READ_PARAM));

    if (p_data->api_write.p_descr_type == NULL)
        handle = p_data->api_write.char_id.inst_id;
    else
        handle = p_data->api_write.p_descr_type->inst_id;

    read_param.by_handle.handle = handle;
    read_param.by_handle.handle = p_data->api_read.handle;
    read_param.by_handle.auth_req = p_data->api_read.auth_req;

    status = GATTC_Read(p_clcb->bta_conn_id, GATT_READ_BY_HANDLE, &read_param);
    tBTA_GATT_STATUS status = GATTC_Read(p_clcb->bta_conn_id, GATT_READ_BY_HANDLE, &read_param);

    /* read fail */
    if (status != BTA_GATT_OK)
@@ -1122,39 +1113,19 @@ void bta_gattc_read(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
*********************************************************************************/
void bta_gattc_read_multi(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
{
    UINT16              i, handle;
    tBTA_GATT_STATUS    status = BTA_GATT_OK;
    tGATT_READ_PARAM    read_param;
    tBTA_GATTC_ATTR_ID  *p_id;

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

        p_id = p_data->api_read_multi.p_id_list;

        for (i = 0; i < p_data->api_read_multi.num_attr && p_id; i ++, p_id ++)
        {
            handle = 0;

            if (p_id->id_type == BTA_GATT_TYPE_CHAR) {
                handle = p_id->id_value.char_id.char_id.inst_id;
            } else if (p_id->id_type == BTA_GATT_TYPE_CHAR_DESCR) {
                handle = p_id->id_value.char_descr_id.descr_id.inst_id;
            } else {
                APPL_TRACE_ERROR("invalud ID type: %d", p_id->id_type);
            }

            if (handle == 0)
            {
                status = BTA_GATT_ERROR;
                break;
            }
        }
        if (status == BTA_GATT_OK)
        {
            read_param.read_multiple.num_handles = p_data->api_read_multi.num_attr;
            read_param.read_multiple.auth_req = p_data->api_read_multi.auth_req;
            memcpy(&read_param.read_multiple.handles, p_data->api_read_multi.handles,
                                        sizeof(UINT16) * p_data->api_read_multi.num_attr);

            status = GATTC_Read(p_clcb->bta_conn_id, GATT_READ_MULTIPLE, &read_param);
        }
@@ -1184,18 +1155,11 @@ void bta_gattc_write(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
    if (!bta_gattc_enqueue(p_clcb, p_data))
        return;

    UINT16              handle = 0;
    tBTA_GATT_STATUS    status = BTA_GATT_OK;

    if (p_data->api_write.p_descr_type == NULL)
        handle = p_data->api_write.char_id.inst_id;
    else
        handle = p_data->api_write.p_descr_type->inst_id;

    tGATT_VALUE attr;

    attr.conn_id = p_clcb->bta_conn_id;
    attr.handle = handle;
    attr.handle = p_data->api_write.handle;
    attr.offset = p_data->api_write.offset;
    attr.len    = p_data->api_write.len;
    attr.auth_req = p_data->api_write.auth_req;
@@ -1252,7 +1216,7 @@ 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 = p_data->api_confirm.char_id.inst_id;
    UINT16 handle = p_data->api_confirm.handle;

    if (GATTC_SendHandleValueConfirm(p_data->api_confirm.hdr.layer_specific, handle)
        != GATT_SUCCESS) {
@@ -1278,45 +1242,25 @@ void bta_gattc_read_cmpl(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_OP_CMPL *p_data)
{
    UINT8               event;
    tBTA_GATTC          cb_data;
    tBTA_GATT_READ_VAL  read_value;
    tBTA_GATT_UNFMT     read_value;

    memset(&cb_data, 0, sizeof(tBTA_GATTC));
    memset(&read_value, 0, sizeof(tBTA_GATT_READ_VAL));
    memset(&read_value, 0, sizeof(tBTA_GATT_UNFMT));

    cb_data.read.status     = p_data->status;

    if (p_data->p_cmpl != NULL && p_data->status == BTA_GATT_OK)
    {
        if (bta_gattc_handle2id(p_clcb->p_srcb,
                                p_data->p_cmpl->att_value.handle,
                                &cb_data.read.srvc_id,
                                &cb_data.read.char_id,
                                &cb_data.read.descr_type) == FALSE)
        {
            cb_data.read.status = BTA_GATT_INTERNAL_ERROR;
            APPL_TRACE_ERROR("can not map to GATT ID. handle = 0x%04x",
                                p_data->p_cmpl->att_value.handle);
        }
        else
        {
            cb_data.read.status = bta_gattc_pack_read_cb_data(p_clcb->p_srcb,
                                                              &cb_data.read.descr_type.uuid,
                                                              &p_data->p_cmpl->att_value,
                                                              &read_value);
        cb_data.read.handle = p_data->p_cmpl->att_value.handle;

        read_value.len = p_data->p_cmpl->att_value.len;
        read_value.p_value = p_data->p_cmpl->att_value.value;
        cb_data.read.p_value = &read_value;
        }
    }
    else
    {
        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;
        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));
    } else {
        cb_data.read.handle = p_clcb->p_q_cmd->api_read.handle;
    }

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

    osi_free_and_reset((void **)&p_clcb->p_q_cmd);
@@ -1341,35 +1285,15 @@ void bta_gattc_write_cmpl(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_OP_CMPL *p_data)
    memset(&cb_data, 0, sizeof(tBTA_GATTC));

    cb_data.write.status     = p_data->status;

    if (p_data->p_cmpl != NULL)
    {
        bta_gattc_handle2id(p_clcb->p_srcb, p_data->p_cmpl->att_value.handle,
                            &cb_data.write.srvc_id, &cb_data.write.char_id,
                            &cb_data.write.descr_type);
    }
    else
    {
        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));
    }
    cb_data.write.handle = p_data->p_cmpl->att_value.handle;

    if (p_clcb->p_q_cmd->api_write.hdr.event == BTA_GATTC_API_WRITE_EVT &&
        p_clcb->p_q_cmd->api_write.write_type == BTA_GATTC_WRITE_PREPARE)

        event = BTA_GATTC_PREP_WRITE_EVT;

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

        event = BTA_GATTC_WRITE_CHAR_EVT;

    else
        event = BTA_GATTC_WRITE_DESCR_EVT;
        event = p_clcb->p_q_cmd->api_write.cmpl_evt;

    osi_free_and_reset((void **)&p_clcb->p_q_cmd);
    cb_data.write.conn_id = p_clcb->bta_conn_id;
@@ -1760,8 +1684,9 @@ 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))
    const tBTA_GATTC_CHARACTERISTIC *p_char = bta_gattc_get_characteristic_srcb(p_srcb, p_notify->handle);
    if (p_char && bta_gattc_uuid_compare(&p_char->service->uuid, &gattp_uuid, TRUE) &&
        bta_gattc_uuid_compare(&p_char->uuid, &srvc_chg_uuid, TRUE))
    {
        if (att_value->len != BTA_GATTC_SERVICE_CHANGED_LEN) {
            APPL_TRACE_ERROR("%s: received malformed service changed indication, skipping", __func__);
@@ -1890,11 +1815,7 @@ void bta_gattc_process_indicate(UINT16 conn_id, tGATTC_OPTYPE op, tGATT_CL_COMPL

    p_clcb = bta_gattc_find_clcb_by_conn_id(conn_id);

    if (bta_gattc_handle2id(p_srcb, handle,
                            &notify.char_id.srvc_id,
                            &notify.char_id.char_id,
                            &notify.descr_type))
    {
    notify.handle = handle;
    /* if non-service change indication/notification, forward to application */
    if (!bta_gattc_process_srvc_chg_ind(conn_id, p_clrcb, p_srcb, p_clcb, &notify, &p_data->att_value))
    {
@@ -1904,18 +1825,18 @@ void bta_gattc_process_indicate(UINT16 conn_id, tGATTC_OPTYPE op, tGATT_CL_COMPL
            /* connection not open yet */
            if (p_clcb == NULL)
            {
                    if ((p_clcb = bta_gattc_clcb_alloc(gatt_if, remote_bda, transport)) != NULL)
                    {
                p_clcb = bta_gattc_clcb_alloc(gatt_if, remote_bda, transport);

                if (p_clcb == NULL) {
                    APPL_TRACE_ERROR("No resources");
                    return;
                }

                p_clcb->bta_conn_id = conn_id;
                p_clcb->transport   = transport;

                bta_gattc_sm_execute(p_clcb, BTA_GATTC_INT_CONN_EVT, NULL);
            }
                    else
                    {
                        APPL_TRACE_ERROR("No resources");
                    }
                }

            if (p_clcb != NULL)
                bta_gattc_proc_other_indication(p_clcb, op, p_data, &notify);
@@ -1928,14 +1849,6 @@ void bta_gattc_process_indicate(UINT16 conn_id, tGATTC_OPTYPE op, tGATT_CL_COMPL
        }
    }
}
    else
    {
        APPL_TRACE_ERROR("%s Indi/Notif for Unknown handle[0x%04x], can not find in local cache.",
                         __func__, handle);
        if (op == GATTC_OPTYPE_INDICATION)
            GATTC_SendHandleValueConfirm(conn_id, handle);
    }
}
/*******************************************************************************
**
** Function         bta_gattc_cmpl_cback
+67 −115
Original line number Diff line number Diff line
@@ -278,8 +278,8 @@ const list_t* BTA_GATTC_GetServices(UINT16 conn_id) {
**
** Description      This function is called to find the characteristic on the given server.
**
** Parameters       conn_id: connection ID which identify the server.
**                  handle: characteristic handle
** Parameters       conn_id - connection ID which identify the server.
**                  handle - characteristic handle
**
** Returns          returns pointer to tBTA_GATTC_CHARACTERISTIC or NULL.
**
@@ -290,12 +290,12 @@ const tBTA_GATTC_CHARACTERISTIC* BTA_GATTC_GetCharacteristic(UINT16 conn_id, UIN

/*******************************************************************************
**
** Function         BTA_GATTC_GetCharacteristic
** Function         BTA_GATTC_GetDescriptor
**
** Description      This function is called to find the characteristic on the given server.
**
** Parameters       conn_id: connection ID which identify the server.
**                  handle: descriptor handle
** Parameters       conn_id - connection ID which identify the server.
**                  handle - descriptor handle
**
** Returns          returns pointer to tBTA_GATTC_DESCRIPTOR or NULL.
**
@@ -326,17 +326,15 @@ void BTA_GATTC_GetGattDb(UINT16 conn_id, UINT16 start_handle, UINT16 end_handle
**
** Function         BTA_GATTC_ReadCharacteristic
**
** Description      This function is called to read a service's characteristics of
**                    the given characteritisc ID.
** Description      This function is called to read a characteristics value
**
** Parameters       conn_id - connectino ID.
**                    p_char_id - characteritic ID to read.
** Parameters       conn_id - connection ID.
**                  handle - characteritic handle to read.
**
** Returns          None
**
*******************************************************************************/
void BTA_GATTC_ReadCharacteristic(UINT16 conn_id, tBTA_GATTC_CHAR_ID *p_char_id,
                                  tBTA_GATT_AUTH_REQ auth_req)
void BTA_GATTC_ReadCharacteristic(UINT16 conn_id, UINT16 handle, tBTA_GATT_AUTH_REQ auth_req)
{
    tBTA_GATTC_API_READ *p_buf =
        (tBTA_GATTC_API_READ *)osi_calloc(sizeof(tBTA_GATTC_API_READ));
@@ -344,10 +342,8 @@ void BTA_GATTC_ReadCharacteristic(UINT16 conn_id, tBTA_GATTC_CHAR_ID *p_char_id,
    p_buf->hdr.event = BTA_GATTC_API_READ_EVT;
    p_buf->hdr.layer_specific = conn_id;
    p_buf->auth_req = auth_req;

    memcpy(&p_buf->srvc_id, &p_char_id->srvc_id, sizeof(tBTA_GATT_SRVC_ID));
    memcpy(&p_buf->char_id, &p_char_id->char_id, sizeof(tBTA_GATT_ID));
    p_buf->p_descr_type = NULL;
    p_buf->handle = handle;
    p_buf->cmpl_evt = BTA_GATTC_READ_CHAR_EVT;

    bta_sys_sendmsg(p_buf);
}
@@ -356,30 +352,24 @@ void BTA_GATTC_ReadCharacteristic(UINT16 conn_id, tBTA_GATTC_CHAR_ID *p_char_id,
**
** Function         BTA_GATTC_ReadCharDescr
**
** Description      This function is called to read a characteristics descriptor.
** Description      This function is called to read a descriptor value.
**
** Parameters       conn_id - connection ID.
**                    p_char_descr_id - characteritic descriptor ID to read.
**                  handle - descriptor handle to read.
**
** Returns          None
**
*******************************************************************************/
void BTA_GATTC_ReadCharDescr (UINT16 conn_id,
                              tBTA_GATTC_CHAR_DESCR_ID  *p_descr_id,
                              tBTA_GATT_AUTH_REQ auth_req)
void BTA_GATTC_ReadCharDescr (UINT16 conn_id, UINT16 handle, tBTA_GATT_AUTH_REQ auth_req)
{
    const size_t len = sizeof(tBTA_GATT_ID) + sizeof(tBTA_GATTC_API_READ);
    tBTA_GATTC_API_READ *p_buf = (tBTA_GATTC_API_READ *)osi_calloc(len);
    tBTA_GATTC_API_READ *p_buf =
        (tBTA_GATTC_API_READ *)osi_calloc(sizeof(tBTA_GATTC_API_READ));

    p_buf->hdr.event = BTA_GATTC_API_READ_EVT;
    p_buf->hdr.layer_specific = conn_id;
    p_buf->auth_req = auth_req;

    memcpy(&p_buf->srvc_id, &p_descr_id->char_id.srvc_id, sizeof(tBTA_GATT_SRVC_ID));
    memcpy(&p_buf->char_id, &p_descr_id->char_id.char_id, sizeof(tBTA_GATT_ID));
    p_buf->p_descr_type  = (tBTA_GATT_ID *)(p_buf + 1);

    memcpy(p_buf->p_descr_type, &p_descr_id->descr_id, sizeof(tBTA_GATT_ID));
    p_buf->handle = handle;
    p_buf->cmpl_evt = BTA_GATTC_READ_DESCR_EVT;

    bta_sys_sendmsg(p_buf);
}
@@ -400,23 +390,16 @@ void BTA_GATTC_ReadCharDescr (UINT16 conn_id,
void BTA_GATTC_ReadMultiple(UINT16 conn_id, tBTA_GATTC_MULTI *p_read_multi,
                            tBTA_GATT_AUTH_REQ auth_req)
{
    const size_t len = sizeof(tBTA_GATTC_API_READ_MULTI) +
                        p_read_multi->num_attr * sizeof(tBTA_GATTC_ATTR_ID);
    tBTA_GATTC_API_READ_MULTI *p_buf =
        (tBTA_GATTC_API_READ_MULTI *)osi_calloc(len);
        (tBTA_GATTC_API_READ_MULTI *)osi_calloc(sizeof(tBTA_GATTC_API_READ_MULTI));

    p_buf->hdr.event = BTA_GATTC_API_READ_MULTI_EVT;
    p_buf->hdr.layer_specific = conn_id;
    p_buf->auth_req = auth_req;
    p_buf->num_attr = p_read_multi->num_attr;

    if (p_buf->num_attr > 0) {
        tBTA_GATTC_ATTR_ID *p_value;
        p_buf->p_id_list = p_value = (tBTA_GATTC_ATTR_ID *)(p_buf + 1);
        for (int i = 0; i < p_buf->num_attr; i++, p_value++) {
            memcpy(p_value, &p_read_multi->id_list[i], sizeof(tBTA_GATTC_ATTR_ID));
        }
    }
    if (p_buf->num_attr > 0)
        memcpy(p_buf->handles, p_read_multi->handles, sizeof(UINT16) * p_read_multi->num_attr);

    bta_sys_sendmsg(p_buf);
}
@@ -428,7 +411,7 @@ void BTA_GATTC_ReadMultiple(UINT16 conn_id, tBTA_GATTC_MULTI *p_read_multi,
** Description      This function is called to write characteristic value.
**
** Parameters       conn_id - connection ID.
**                    p_char_id - characteristic ID to write.
**                  handle - characteristic handle to write.
**                  write_type - type of write.
**                  len: length of the data to be written.
**                  p_value - the value to be written.
@@ -437,7 +420,7 @@ void BTA_GATTC_ReadMultiple(UINT16 conn_id, tBTA_GATTC_MULTI *p_read_multi,
**
*******************************************************************************/
void BTA_GATTC_WriteCharValue ( UINT16 conn_id,
                                tBTA_GATTC_CHAR_ID *p_char_id,
                                UINT16 handle,
                                tBTA_GATTC_WRITE_TYPE  write_type,
                                UINT16 len,
                                UINT8 *p_value,
@@ -449,11 +432,8 @@ void BTA_GATTC_WriteCharValue ( UINT16 conn_id,
    p_buf->hdr.event = BTA_GATTC_API_WRITE_EVT;
    p_buf->hdr.layer_specific = conn_id;
    p_buf->auth_req = auth_req;

    memcpy(&p_buf->srvc_id, &p_char_id->srvc_id, sizeof(tBTA_GATT_SRVC_ID));
    memcpy(&p_buf->char_id, &p_char_id->char_id, sizeof(tBTA_GATT_ID));
    p_buf->p_descr_type = NULL;

    p_buf->handle = handle;
    p_buf->cmpl_evt = BTA_GATTC_WRITE_CHAR_EVT;
    p_buf->write_type = write_type;
    p_buf->len = len;

@@ -469,10 +449,10 @@ void BTA_GATTC_WriteCharValue ( UINT16 conn_id,
**
** Function         BTA_GATTC_WriteCharDescr
**
** Description      This function is called to write characteristic descriptor value.
** Description      This function is called to write descriptor value.
**
** Parameters       conn_id - connection ID
**                    p_char_descr_id - characteristic descriptor ID to write.
**                  handle - descriptor hadle to write.
**                  write_type - write type.
**                  p_value - the value to be written.
**
@@ -480,12 +460,12 @@ void BTA_GATTC_WriteCharValue ( UINT16 conn_id,
**
*******************************************************************************/
void BTA_GATTC_WriteCharDescr (UINT16 conn_id,
                               tBTA_GATTC_CHAR_DESCR_ID *p_char_descr_id,
                               UINT16 handle,
                               tBTA_GATTC_WRITE_TYPE  write_type,
                               tBTA_GATT_UNFMT      *p_data,
                               tBTA_GATT_AUTH_REQ auth_req)
{
    size_t len = sizeof(tBTA_GATTC_API_WRITE) + sizeof(tBTA_GATT_ID);
    size_t len = sizeof(tBTA_GATTC_API_WRITE);

    if (p_data != NULL)
        len += p_data->len;
@@ -494,15 +474,12 @@ void BTA_GATTC_WriteCharDescr (UINT16 conn_id,
    p_buf->hdr.event = BTA_GATTC_API_WRITE_EVT;
    p_buf->hdr.layer_specific = conn_id;
    p_buf->auth_req = auth_req;

    memcpy(&p_buf->srvc_id, &p_char_descr_id->char_id.srvc_id, sizeof(tBTA_GATT_SRVC_ID));
    memcpy(&p_buf->char_id, &p_char_descr_id->char_id.char_id, sizeof(tBTA_GATT_ID));
    p_buf->p_descr_type = (tBTA_GATT_ID *)(p_buf + 1);
    memcpy(p_buf->p_descr_type, &p_char_descr_id->descr_id, sizeof(tBTA_GATT_ID));
    p_buf->handle = handle;
    p_buf->cmpl_evt = BTA_GATTC_WRITE_DESCR_EVT;
    p_buf->write_type = write_type;

    if (p_data && p_data->len != 0) {
        p_buf->p_value  = (UINT8 *)(p_buf->p_descr_type + 1);
        p_buf->p_value  = (UINT8 *)(p_buf + 1);
        p_buf->len      = p_data->len;
        /* pack the descr data */
        memcpy(p_buf->p_value, p_data->p_value, p_data->len);
@@ -526,7 +503,7 @@ void BTA_GATTC_WriteCharDescr (UINT16 conn_id,
** Returns          None
**
*******************************************************************************/
void BTA_GATTC_PrepareWrite  (UINT16 conn_id, tBTA_GATTC_CHAR_ID *p_char_id,
void BTA_GATTC_PrepareWrite  (UINT16 conn_id, UINT16 handle,
                              UINT16 offset, UINT16 len, UINT8 *p_value,
                              tBTA_GATT_AUTH_REQ auth_req)
{
@@ -536,10 +513,7 @@ void BTA_GATTC_PrepareWrite (UINT16 conn_id, tBTA_GATTC_CHAR_ID *p_char_id,
    p_buf->hdr.event = BTA_GATTC_API_WRITE_EVT;
    p_buf->hdr.layer_specific = conn_id;
    p_buf->auth_req = auth_req;

    memcpy(&p_buf->srvc_id, &p_char_id->srvc_id, sizeof(tBTA_GATT_SRVC_ID));
    memcpy(&p_buf->char_id, &p_char_id->char_id, sizeof(tBTA_GATT_ID));
    p_buf->p_descr_type = NULL;
    p_buf->handle = handle;

    p_buf->write_type = BTA_GATTC_WRITE_PREPARE;
    p_buf->offset   = offset;
@@ -589,20 +563,16 @@ void BTA_GATTC_ExecuteWrite (UINT16 conn_id, BOOLEAN is_execute)
** Returns          None
**
*******************************************************************************/
void BTA_GATTC_SendIndConfirm (UINT16 conn_id, tBTA_GATTC_CHAR_ID *p_char_id)
void BTA_GATTC_SendIndConfirm (UINT16 conn_id, UINT16 handle)
{
    tBTA_GATTC_API_CONFIRM *p_buf =
        (tBTA_GATTC_API_CONFIRM *)osi_calloc(sizeof(tBTA_GATTC_API_CONFIRM));

    APPL_TRACE_API("%s conn_id=%d service uuid1=0x%x char uuid=0x%x",
                   __func__, conn_id, p_char_id->srvc_id.id.uuid.uu.uuid16,
                   p_char_id->char_id.uuid.uu.uuid16);
    APPL_TRACE_API("%s conn_id=%d handle=0x%04x", __func__, conn_id, handle);

    p_buf->hdr.event = BTA_GATTC_API_CONFIRM_EVT;
    p_buf->hdr.layer_specific = conn_id;

    memcpy(&p_buf->srvc_id, &p_char_id->srvc_id, sizeof(tBTA_GATT_SRVC_ID));
    memcpy(&p_buf->char_id, &p_char_id->char_id, sizeof(tBTA_GATT_ID));
    p_buf->handle = handle;

    bta_sys_sendmsg(p_buf);
}
@@ -615,22 +585,21 @@ void BTA_GATTC_SendIndConfirm (UINT16 conn_id, tBTA_GATTC_CHAR_ID *p_char_id)
**
** Parameters       client_if - client interface.
**                  bda - target GATT server.
**                  p_char_id - pointer to GATT characteristic ID.
**                  handle - GATT characteristic handle.
**
** Returns          OK if registration succeed, otherwise failed.
**
*******************************************************************************/
tBTA_GATT_STATUS BTA_GATTC_RegisterForNotifications (tBTA_GATTC_IF client_if,
                                                     BD_ADDR bda,
                                                     tBTA_GATTC_CHAR_ID *p_char_id)
                                                     BD_ADDR bda, UINT16 handle)
{
    tBTA_GATTC_RCB      *p_clreg;
    tBTA_GATT_STATUS    status = BTA_GATT_ILLEGAL_PARAMETER;
    UINT8               i;

    if (!p_char_id)
    if (!handle)
    {
        APPL_TRACE_ERROR("deregistration failed, unknow char id");
        APPL_TRACE_ERROR("deregistration failed, handle is 0");
        return status;
    }

@@ -640,7 +609,7 @@ tBTA_GATT_STATUS BTA_GATTC_RegisterForNotifications (tBTA_GATTC_IF client_if,
        {
            if ( p_clreg->notif_reg[i].in_use &&
                 !memcmp(p_clreg->notif_reg[i].remote_bda, bda, BD_ADDR_LEN) &&
                  bta_gattc_charid_compare(&p_clreg->notif_reg[i].char_id, p_char_id))
                  p_clreg->notif_reg[i].handle == handle)
            {
                APPL_TRACE_WARNING("notification already registered");
                status = BTA_GATT_OK;
@@ -658,10 +627,7 @@ tBTA_GATT_STATUS BTA_GATTC_RegisterForNotifications (tBTA_GATTC_IF client_if,
                    p_clreg->notif_reg[i].in_use = TRUE;
                    memcpy(p_clreg->notif_reg[i].remote_bda, bda, BD_ADDR_LEN);

                    p_clreg->notif_reg[i].char_id.srvc_id.is_primary = p_char_id->srvc_id.is_primary;
                    bta_gattc_cpygattid(&p_clreg->notif_reg[i].char_id.srvc_id.id, &p_char_id->srvc_id.id);
                    bta_gattc_cpygattid(&p_clreg->notif_reg[i].char_id.char_id, &p_char_id->char_id);

                    p_clreg->notif_reg[i].handle = handle;
                    status = BTA_GATT_OK;
                    break;
                }
@@ -685,58 +651,44 @@ tBTA_GATT_STATUS BTA_GATTC_RegisterForNotifications (tBTA_GATTC_IF client_if,
**
** Function         BTA_GATTC_DeregisterForNotifications
**
** Description      This function is called to de-register for notification of a service.
** Description      This function is called to de-register for notification of a servbice.
**
** Parameters       client_if - client interface.
**                  bda - target GATT server.
**                  p_char_id - pointer to GATT characteristic ID.
**                  remote_bda - target GATT server.
**                  handle - GATT characteristic handle.
**
** Returns          OK if deregistration succeed, otherwise failed.
**
*******************************************************************************/
tBTA_GATT_STATUS BTA_GATTC_DeregisterForNotifications (tBTA_GATTC_IF client_if,
                                                       BD_ADDR bda,
                                                       tBTA_GATTC_CHAR_ID *p_char_id)
                                                       BD_ADDR bda, UINT16 handle)
{
    tBTA_GATTC_RCB      *p_clreg;
    tBTA_GATT_STATUS    status = BTA_GATT_ILLEGAL_PARAMETER;
    UINT8               i;
    if (!handle) {
        APPL_TRACE_ERROR("%s: deregistration failed, handle is 0", __func__);
        return BTA_GATT_ILLEGAL_PARAMETER;
    }

    if (!p_char_id)
    {
        APPL_TRACE_ERROR("%s deregistration failed, unknown char id", __func__);
        return status;
    tBTA_GATTC_RCB *p_clreg = bta_gattc_cl_get_regcb(client_if);
    if (p_clreg == NULL) {
        APPL_TRACE_ERROR("%s client_if: %d not registered bd_addr:%02x:%02x:%02x:%02x:%02x:%02x",
            __func__, client_if, bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]);
        return BTA_GATT_ILLEGAL_PARAMETER;
    }

    if ((p_clreg = bta_gattc_cl_get_regcb(client_if)) != NULL)
    {
        for (i = 0; i < BTA_GATTC_NOTIF_REG_MAX; i ++)
        {
    for (int i = 0; i < BTA_GATTC_NOTIF_REG_MAX; i ++) {
        if (p_clreg->notif_reg[i].in_use &&
            !memcmp(p_clreg->notif_reg[i].remote_bda, bda, BD_ADDR_LEN) &&
                bta_gattc_charid_compare(&p_clreg->notif_reg[i].char_id, p_char_id))
            {
            p_clreg->notif_reg[i].handle == handle) {
            APPL_TRACE_DEBUG("%s deregistered bd_addr:%02x:%02x:%02x:%02x:%02x:%02x",
                __func__, bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]);
            memset(&p_clreg->notif_reg[i], 0, sizeof(tBTA_GATTC_NOTIF_REG));
                status = BTA_GATT_OK;
                break;
            return BTA_GATT_OK;
        }
    }
        if (i == BTA_GATTC_NOTIF_REG_MAX)
        {
            status = BTA_GATT_ERROR;

    APPL_TRACE_ERROR("%s registration not found bd_addr:%02x:%02x:%02x:%02x:%02x:%02x",
        __func__, bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]);
        }
    }
    else
    {
        APPL_TRACE_ERROR("%s client_if: %d not registered bd_addr:%02x:%02x:%02x:%02x:%02x:%02x",
            __func__, client_if, bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]);
    }

    return status;
    return BTA_GATT_ERROR;
}

/*******************************************************************************
+16 −57

File changed.

Preview size limit exceeded, changes collapsed.

+9 −16

File changed.

Preview size limit exceeded, changes collapsed.

Loading