From 9dc998503590163068845827d951fc2f05a17bda Mon Sep 17 00:00:00 2001 From: Jakub Pawlowski Date: Thu, 17 Mar 2016 12:05:54 -0700 Subject: [PATCH] Use handles to identify GATT attributes (1/4) Bug: 27778668 Change-Id: Id7454450c1ce2164001a1f9ca0b91f18d84e3fd6 --- bta/dm/bta_dm_act.c | 2 +- bta/gatt/bta_gattc_act.c | 175 +++++------------- bta/gatt/bta_gattc_api.c | 182 +++++++------------ bta/gatt/bta_gattc_cache.c | 73 ++------ bta/gatt/bta_gattc_int.h | 25 +-- bta/gatt/bta_gattc_utils.c | 136 +------------- bta/hh/bta_hh_le.c | 299 +++++++++++-------------------- bta/include/bta_gatt_api.h | 240 +++++-------------------- btif/include/btif_gatt_util.h | 4 - btif/src/btif_gatt_client.c | 145 +++++---------- btif/src/btif_gatt_server.c | 12 +- btif/src/btif_gatt_util.c | 69 ++----- service/hal/bluetooth_gatt_interface.cpp | 29 ++- service/hal/bluetooth_gatt_interface.h | 12 +- 14 files changed, 368 insertions(+), 1035 deletions(-) diff --git a/bta/dm/bta_dm_act.c b/bta/dm/bta_dm_act.c index 73d7afbd7..811a7cd31 100644 --- a/bta/dm/bta_dm_act.c +++ b/bta/dm/bta_dm_act.c @@ -5601,7 +5601,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: diff --git a/bta/gatt/bta_gattc_act.c b/bta/gatt/bta_gattc_act.c index 26fc5bcce..388d9a429 100644 --- a/bta/gatt/bta_gattc_act.c +++ b/bta/gatt/bta_gattc_act.c @@ -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.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)); + 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.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,50 +1815,38 @@ 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, - ¬ify.char_id.srvc_id, - ¬ify.char_id.char_id, - ¬ify.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, ¬ify, &p_data->att_value)) { - /* if non-service change indication/notification, forward to application */ - if (!bta_gattc_process_srvc_chg_ind(conn_id, p_clrcb, p_srcb, p_clcb, ¬ify, &p_data->att_value)) + /* if app registered for the notification */ + if (bta_gattc_check_notif_registry(p_clrcb, p_srcb, ¬ify)) { - /* if app registered for the notification */ - if (bta_gattc_check_notif_registry(p_clrcb, p_srcb, ¬ify)) + /* connection not open yet */ + if (p_clcb == NULL) { - /* connection not open yet */ - if (p_clcb == NULL) - { - if ((p_clcb = bta_gattc_clcb_alloc(gatt_if, remote_bda, transport)) != NULL) - { - p_clcb->bta_conn_id = conn_id; - p_clcb->transport = transport; + p_clcb = bta_gattc_clcb_alloc(gatt_if, remote_bda, transport); - bta_gattc_sm_execute(p_clcb, BTA_GATTC_INT_CONN_EVT, NULL); - } - else - { - APPL_TRACE_ERROR("No resources"); - } + if (p_clcb == NULL) { + APPL_TRACE_ERROR("No resources"); + return; } - if (p_clcb != NULL) - bta_gattc_proc_other_indication(p_clcb, op, p_data, ¬ify); - } - /* no one intersted and need ack? */ - else if (op == GATTC_OPTYPE_INDICATION) - { - APPL_TRACE_DEBUG("%s no one interested, ack now", __func__); - GATTC_SendHandleValueConfirm(conn_id, handle); + p_clcb->bta_conn_id = conn_id; + p_clcb->transport = transport; + + bta_gattc_sm_execute(p_clcb, BTA_GATTC_INT_CONN_EVT, NULL); } + + if (p_clcb != NULL) + bta_gattc_proc_other_indication(p_clcb, op, p_data, ¬ify); } - } - 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) + /* no one intersted and need ack? */ + else if (op == GATTC_OPTYPE_INDICATION) + { + APPL_TRACE_DEBUG("%s no one interested, ack now", __func__); GATTC_SendHandleValueConfirm(conn_id, handle); + } } } /******************************************************************************* diff --git a/bta/gatt/bta_gattc_api.c b/bta/gatt/bta_gattc_api.c index 923eb2016..0ea579642 100644 --- a/bta/gatt/bta_gattc_api.c +++ b/bta/gatt/bta_gattc_api.c @@ -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,8 +411,8 @@ 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. -** write_type - type of 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 ++) - { - 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)) - { - 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; - } - } - 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", + 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) && + 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)); + return BTA_GATT_OK; } } - 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; + 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]); + return BTA_GATT_ERROR; } /******************************************************************************* diff --git a/bta/gatt/bta_gattc_cache.c b/bta/gatt/bta_gattc_cache.c index 8dcd21e24..aaff813cf 100644 --- a/bta/gatt/bta_gattc_cache.c +++ b/bta/gatt/bta_gattc_cache.c @@ -94,9 +94,9 @@ bool display_cache_service(void *data, void *context) { tBTA_GATTC_SERVICE *p_cur_srvc = data; APPL_TRACE_ERROR("Service: handle[%d ~ %d] %s[0x%04x] inst[%d]", p_cur_srvc->s_handle, p_cur_srvc->e_handle, - ((p_cur_srvc->service_uuid.id.uuid.len == 2) ? "uuid16" : "uuid128"), - p_cur_srvc->service_uuid.id.uuid.uu.uuid16, - p_cur_srvc->service_uuid.id.inst_id); + ((p_cur_srvc->uuid.len == 2) ? "uuid16" : "uuid128"), + p_cur_srvc->uuid.uu.uuid16, + p_cur_srvc->handle); if (p_cur_srvc->characteristics != NULL) { list_foreach(p_cur_srvc->characteristics, display_cache_attribute, NULL); @@ -211,9 +211,9 @@ static tBTA_GATT_STATUS bta_gattc_add_srvc_to_cache(tBTA_GATTC_SERV *p_srvc_cb, /* update service information */ p_new_srvc->s_handle = s_handle; p_new_srvc->e_handle = e_handle; - p_new_srvc->service_uuid.is_primary = is_primary; - memcpy(&p_new_srvc->service_uuid.id.uuid, p_uuid, sizeof(tBT_UUID)); - p_new_srvc->service_uuid.id.inst_id = s_handle; + p_new_srvc->is_primary = is_primary; + memcpy(&p_new_srvc->uuid, p_uuid, sizeof(tBT_UUID)); + p_new_srvc->handle = s_handle; p_new_srvc->characteristics = list_new(characteristic_free); p_new_srvc->included_svc = list_new(osi_free); @@ -946,47 +946,6 @@ void bta_gattc_disc_cmpl_cback (UINT16 conn_id, tGATT_DISC_TYPE disc_type, tGATT /******************************************************************************* ** -** Function bta_gattc_handle2id -** -** Description map a handle to GATT ID in a given cache. -** -** Returns FALSE if map can not be found. -** -*******************************************************************************/ - -BOOLEAN bta_gattc_handle2id(tBTA_GATTC_SERV *p_srcb, UINT16 handle, tBTA_GATT_SRVC_ID *p_service_id, - tBTA_GATT_ID *p_char_id, tBTA_GATT_ID *p_descr_type) -{ - memset(p_service_id, 0, sizeof(tBTA_GATT_SRVC_ID)); - memset(p_char_id, 0, sizeof(tBTA_GATT_ID)); - memset(p_descr_type, 0, sizeof(tBTA_GATT_ID)); - - if (!p_srcb->p_srvc_cache || list_is_empty(p_srcb->p_srvc_cache)) - return FALSE; - - tBTA_GATTC_DESCRIPTOR* p_desc = bta_gattc_get_descriptor_srcb(p_srcb, handle); - tBTA_GATTC_CHARACTERISTIC* p_char = NULL; - if (p_desc) { - memcpy(&p_descr_type->uuid, &p_desc->uuid, sizeof(tBT_UUID)); - p_descr_type->inst_id = p_desc->handle; - - p_char = p_desc->characteristic; - } else { - p_char = bta_gattc_get_characteristic_srcb(p_srcb, handle); - } - - if (p_char) { - memcpy(&p_char_id->uuid, &p_char->uuid, sizeof(tBT_UUID)); - p_char_id->inst_id = p_char->handle; - - memcpy(p_service_id, &p_char->service->service_uuid, sizeof(tBTA_GATT_SRVC_ID)); - return TRUE; - } - return FALSE; -} - -/******************************************************************************* -** ** Function bta_gattc_search_service ** ** Description search local cache for matching service record. @@ -1005,14 +964,14 @@ void bta_gattc_search_service(tBTA_GATTC_CLCB *p_clcb, tBT_UUID *p_uuid) sn != list_end(p_clcb->p_srcb->p_srvc_cache); sn = list_next(sn)) { tBTA_GATTC_SERVICE *p_cache = list_node(sn); - if (!bta_gattc_uuid_compare(p_uuid, &p_cache->service_uuid.id.uuid, FALSE)) + if (!bta_gattc_uuid_compare(p_uuid, &p_cache->uuid, FALSE)) continue; #if (defined BTA_GATT_DEBUG && BTA_GATT_DEBUG == TRUE) APPL_TRACE_DEBUG("found service [0x%04x], inst[%d] handle [%d]", - p_cache->service_uuid.id.uuid.uu.uuid16, - p_cache->service_uuid.id.inst_id, - p_cache->s_handle); + p_cache->uuid.uu.uuid16, + p_cache->handle, + p_cache->s_handle); #endif if (!p_clcb->p_rcb->p_cback) continue; @@ -1020,8 +979,8 @@ void bta_gattc_search_service(tBTA_GATTC_CLCB *p_clcb, tBT_UUID *p_uuid) memset(&cb_data, 0, sizeof(tBTA_GATTC)); cb_data.srvc_res.conn_id = p_clcb->bta_conn_id; - memcpy(&cb_data.srvc_res.service_uuid, &p_cache->service_uuid, - sizeof(tBTA_GATT_SRVC_ID)); + cb_data.srvc_res.service_uuid.inst_id = p_cache->handle; + memcpy(&cb_data.srvc_res.service_uuid.uuid, &p_cache->uuid, sizeof(tBTA_GATT_ID)); (* p_clcb->p_rcb->p_cback)(BTA_GATTC_SEARCH_RES_EVT, &cb_data); } @@ -1239,14 +1198,14 @@ static void bta_gattc_get_gatt_db_impl(tBTA_GATTC_SERV *p_srvc_cb, break; bta_gattc_fill_gatt_db_el(curr_db_attr, - p_cur_srvc->service_uuid.is_primary ? + p_cur_srvc->is_primary ? BTGATT_DB_PRIMARY_SERVICE : BTGATT_DB_SECONDARY_SERVICE, 0 /* att_handle */, p_cur_srvc->s_handle, p_cur_srvc->e_handle, p_cur_srvc->s_handle, - p_cur_srvc->service_uuid.id.uuid, + p_cur_srvc->uuid, 0 /* prop */); curr_db_attr++; @@ -1445,10 +1404,10 @@ void bta_gattc_cache_save(tBTA_GATTC_SERV *p_srvc_cb, UINT16 conn_id) BTA_GATTC_ATTR_TYPE_SRVC, p_cur_srvc->s_handle, p_cur_srvc->e_handle, - p_cur_srvc->service_uuid.id.uuid, + p_cur_srvc->uuid, 0 /* properties */, 0 /* incl_srvc_handle */, - p_cur_srvc->service_uuid.is_primary); + p_cur_srvc->is_primary); } for (list_node_t *sn = list_begin(p_srvc_cb->p_srvc_cache); diff --git a/bta/gatt/bta_gattc_int.h b/bta/gatt/bta_gattc_int.h index b40408b21..c74f7d2a7 100644 --- a/bta/gatt/bta_gattc_int.h +++ b/bta/gatt/bta_gattc_int.h @@ -123,18 +123,16 @@ typedef struct { BT_HDR hdr; tBTA_GATT_AUTH_REQ auth_req; - tBTA_GATT_SRVC_ID srvc_id; - tBTA_GATT_ID char_id; - tBTA_GATT_ID *p_descr_type; + UINT16 handle; + tBTA_GATTC_EVT cmpl_evt; } tBTA_GATTC_API_READ; typedef struct { BT_HDR hdr; tBTA_GATT_AUTH_REQ auth_req; - tBTA_GATT_SRVC_ID srvc_id; - tBTA_GATT_ID char_id; - tBTA_GATT_ID *p_descr_type; + UINT16 handle; + tBTA_GATTC_EVT cmpl_evt; tBTA_GATTC_WRITE_TYPE write_type; UINT16 offset; UINT16 len; @@ -150,8 +148,7 @@ typedef struct typedef struct { BT_HDR hdr; - tBTA_GATT_SRVC_ID srvc_id; - tBTA_GATT_ID char_id; + UINT16 handle; } tBTA_GATTC_API_CONFIRM; typedef tGATT_CL_COMPLETE tBTA_GATTC_CMPL; @@ -175,7 +172,7 @@ typedef struct BT_HDR hdr; tBTA_GATT_AUTH_REQ auth_req; UINT8 num_attr; - tBTA_GATTC_ATTR_ID *p_id_list; + UINT16 handles[GATT_MAX_READ_MULTI_HANDLES]; }tBTA_GATTC_API_READ_MULTI; typedef struct @@ -304,7 +301,7 @@ typedef struct { BOOLEAN in_use; BD_ADDR remote_bda; - tBTA_GATTC_CHAR_ID char_id; + UINT16 handle; }tBTA_GATTC_NOTIF_REG; typedef struct @@ -466,18 +463,13 @@ extern tBTA_GATTC_CLCB * bta_gattc_find_int_disconn_clcb(tBTA_GATTC_DATA *p_msg) extern BOOLEAN bta_gattc_enqueue(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data); -extern BOOLEAN bta_gattc_handle2id(tBTA_GATTC_SERV *p_srcb, UINT16 handle, tBTA_GATT_SRVC_ID *service_id, tBTA_GATT_ID *char_id, tBTA_GATT_ID *p_type); -extern BOOLEAN bta_gattc_uuid_compare (tBT_UUID *p_src, tBT_UUID *p_tar, BOOLEAN is_precise); +extern BOOLEAN bta_gattc_uuid_compare (const tBT_UUID *p_src, const tBT_UUID *p_tar, BOOLEAN is_precise); extern BOOLEAN bta_gattc_check_notif_registry(tBTA_GATTC_RCB *p_clreg, tBTA_GATTC_SERV *p_srcb, tBTA_GATTC_NOTIFY *p_notify); -extern tBTA_GATT_STATUS bta_gattc_pack_read_cb_data(tBTA_GATTC_SERV *p_srcb, tBT_UUID *p_descr_uuid, tGATT_VALUE *p_attr, tBTA_GATT_READ_VAL *p_value); extern BOOLEAN bta_gattc_mark_bg_conn (tBTA_GATTC_IF client_if, BD_ADDR_PTR remote_bda, BOOLEAN add, BOOLEAN is_listen); extern BOOLEAN bta_gattc_check_bg_conn (tBTA_GATTC_IF client_if, BD_ADDR remote_bda, UINT8 role); extern UINT8 bta_gattc_num_reg_app(void); extern void bta_gattc_clear_notif_registration(tBTA_GATTC_SERV *p_srcb, UINT16 conn_id, UINT16 start_handle, UINT16 end_handle); extern tBTA_GATTC_SERV * bta_gattc_find_srvr_cache(BD_ADDR bda); -extern BOOLEAN bta_gattc_charid_compare(tBTA_GATTC_CHAR_ID *p_src, tBTA_GATTC_CHAR_ID *p_tar); -extern BOOLEAN bta_gattc_srvcid_compare(tBTA_GATT_SRVC_ID *p_src, tBTA_GATT_SRVC_ID *p_tar); -extern void bta_gattc_cpygattid(tBTA_GATT_ID *p_des, tBTA_GATT_ID *p_src); /* discovery functions */ extern void bta_gattc_disc_res_cback (UINT16 conn_id, tGATT_DISC_TYPE disc_type, tGATT_DISC_RES *p_data); @@ -487,6 +479,7 @@ extern tBTA_GATT_STATUS bta_gattc_discover_pri_service(UINT16 conn_id, tBTA_GATT extern void bta_gattc_search_service(tBTA_GATTC_CLCB *p_clcb, tBT_UUID *p_uuid); extern const list_t* bta_gattc_get_services(UINT16 conn_id); extern const tBTA_GATTC_SERVICE* bta_gattc_get_service_for_handle(UINT16 conn_id, UINT16 handle); +tBTA_GATTC_CHARACTERISTIC* bta_gattc_get_characteristic_srcb(tBTA_GATTC_SERV *p_srcb, UINT16 handle); extern tBTA_GATTC_CHARACTERISTIC* bta_gattc_get_characteristic(UINT16 conn_id, UINT16 handle); extern tBTA_GATTC_DESCRIPTOR* bta_gattc_get_descriptor(UINT16 conn_id, UINT16 handle); extern void bta_gattc_get_gatt_db(UINT16 conn_id, UINT16 start_handle, UINT16 end_handle, btgatt_db_element_t **db, int *count); diff --git a/bta/gatt/bta_gattc_utils.c b/bta/gatt/bta_gattc_utils.c index 3fb5cde2d..3aa55f84b 100644 --- a/bta/gatt/bta_gattc_utils.c +++ b/bta/gatt/bta_gattc_utils.c @@ -73,10 +73,10 @@ void bta_gatt_convert_uuid16_to_uuid128(UINT8 uuid_128[LEN_UUID_128], UINT16 uui ** Returns TRUE if two uuid match; FALSE otherwise. ** *******************************************************************************/ -BOOLEAN bta_gattc_uuid_compare (tBT_UUID *p_src, tBT_UUID *p_tar, BOOLEAN is_precise) +BOOLEAN bta_gattc_uuid_compare (const tBT_UUID *p_src, const tBT_UUID *p_tar, BOOLEAN is_precise) { UINT8 su[LEN_UUID_128], tu[LEN_UUID_128]; - UINT8 *ps, *pt; + const UINT8 *ps, *pt; /* any of the UUID is unspecified */ if (p_src == 0 || p_tar == 0) @@ -446,85 +446,6 @@ BOOLEAN bta_gattc_enqueue(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data) /******************************************************************************* ** -** Function bta_gattc_cpygattid -** -** Description copy two tBTA_GATT_ID value -** -** Returns -** -*******************************************************************************/ -void bta_gattc_cpygattid(tBTA_GATT_ID *p_des, tBTA_GATT_ID *p_src) -{ - memset ((void *)p_des, 0, sizeof(tBTA_GATT_ID)); - - p_des->inst_id = p_src->inst_id; - - p_des->uuid.len = p_src->uuid.len; - - if (p_des->uuid.len == LEN_UUID_16) - { - p_des->uuid.uu.uuid16 = p_src->uuid.uu.uuid16; - } - else if (p_des->uuid.len == LEN_UUID_128) - { - memcpy(p_des->uuid.uu.uuid128, p_src->uuid.uu.uuid128, LEN_UUID_128); - } -} -/******************************************************************************* -** -** Function bta_gattc_gattid_compare -** -** Description compare two tBTA_GATT_ID type of pointer -** -** Returns -** -*******************************************************************************/ -BOOLEAN bta_gattc_gattid_compare(tBTA_GATT_ID *p_src, tBTA_GATT_ID *p_tar) -{ - if (p_src->inst_id == p_tar->inst_id && - bta_gattc_uuid_compare (&p_src->uuid, &p_tar->uuid, TRUE )) - return TRUE; - else - return FALSE; - -} -/******************************************************************************* -** -** Function bta_gattc_srvcid_compare -** -** Description compare two tBTA_GATT_SRVC_ID type of pointer -** -** Returns -** -*******************************************************************************/ -BOOLEAN bta_gattc_srvcid_compare(tBTA_GATT_SRVC_ID *p_src, tBTA_GATT_SRVC_ID *p_tar) -{ - if (p_src->is_primary == p_tar->is_primary && - bta_gattc_gattid_compare (&p_src->id, &p_tar->id)) - return TRUE; - else - return FALSE; -} -/******************************************************************************* -** -** Function bta_gattc_charid_compare -** -** Description compare two tBTA_GATTC_CHAR_ID type of pointer -** -** Returns -** -*******************************************************************************/ -BOOLEAN bta_gattc_charid_compare(tBTA_GATTC_CHAR_ID *p_src, tBTA_GATTC_CHAR_ID *p_tar) -{ - if (bta_gattc_gattid_compare (&p_src->char_id, &p_tar->char_id) && - bta_gattc_srvcid_compare (&p_src->srvc_id, &p_tar->srvc_id)) - return TRUE; - else - return FALSE; -} - -/******************************************************************************* -** ** Function bta_gattc_check_notif_registry ** ** Description check if the service notificaition has been registered. @@ -541,7 +462,7 @@ BOOLEAN bta_gattc_check_notif_registry(tBTA_GATTC_RCB *p_clreg, tBTA_GATTC_SERV { if (p_clreg->notif_reg[i].in_use && bdcmp(p_clreg->notif_reg[i].remote_bda, p_srcb->server_bda) == 0 && - bta_gattc_charid_compare (&p_clreg->notif_reg[i].char_id, &p_notify->char_id)) + p_clreg->notif_reg[i].handle == p_notify->handle) { APPL_TRACE_DEBUG("Notification registered!"); return TRUE; @@ -581,7 +502,7 @@ void bta_gattc_clear_notif_registration(tBTA_GATTC_SERV *p_srcb, UINT16 conn_id, /* It's enough to get service or characteristic handle, as * clear boundaries are always around service. */ - handle = p_clrcb->notif_reg[i].char_id.char_id.inst_id; + handle = p_clrcb->notif_reg[i].handle; if (handle >= start_handle && handle <= end_handle) memset(&p_clrcb->notif_reg[i], 0, sizeof(tBTA_GATTC_NOTIF_REG)); } @@ -594,55 +515,6 @@ void bta_gattc_clear_notif_registration(tBTA_GATTC_SERV *p_srcb, UINT16 conn_id, /******************************************************************************* ** -** Function bta_gattc_pack_cb_data -** -** Description pack the data from read response into callback data structure. -** -** Returns -** -*******************************************************************************/ -tBTA_GATT_STATUS bta_gattc_pack_read_cb_data(tBTA_GATTC_SERV *p_srcb, - tBT_UUID *p_descr_uuid, - tGATT_VALUE *p_attr, - tBTA_GATT_READ_VAL *p_value) -{ - UINT8 i = 0, *pp = p_attr->value; - tBT_UUID uuid = {LEN_UUID_16, {GATT_UUID_CHAR_AGG_FORMAT}}; - UINT16 handle; - tBTA_GATT_STATUS status = BTA_GATT_OK; - - /* GATT_UUID_CHAR_AGG_FORMAT */ - if (bta_gattc_uuid_compare (&uuid, p_descr_uuid, TRUE)) - { - while (p_attr->len >= 2 && i < BTA_GATTC_MULTI_MAX) - { - STREAM_TO_UINT16(handle, pp); - - if (bta_gattc_handle2id(p_srcb, - handle, - &p_value->aggre_value.pre_format[i].char_id.srvc_id, - &p_value->aggre_value.pre_format[i].char_id.char_id, - &p_value->aggre_value.pre_format[i].descr_id) == FALSE) - { - status = BTA_GATT_INTERNAL_ERROR; - APPL_TRACE_ERROR("can not map to GATT ID. handle = 0x%04x", handle); - break; - } - i ++; - p_attr->len -= 2; - } - p_value->aggre_value.num_pres_fmt = i; - } - else - { - /* all others, take as raw format */ - p_value->unformat.len = p_attr->len; - p_value->unformat.p_value = p_attr->value; - } - return status; -} -/******************************************************************************* -** ** Function bta_gattc_mark_bg_conn ** ** Description mark background connection status when a bg connection is initiated diff --git a/bta/hh/bta_hh_le.c b/bta/hh/bta_hh_le.c index 5e3486e67..88d1508fd 100644 --- a/bta/hh/bta_hh_le.c +++ b/bta/hh/bta_hh_le.c @@ -162,58 +162,33 @@ static void gatt_execute_next_op(UINT16 conn_id) { if (op->type == GATT_READ_CHAR) { const tBTA_GATTC_CHARACTERISTIC *p_char = BTA_GATTC_GetCharacteristic(op->conn_id, op->handle); - tBTA_GATTC_CHAR_ID char_id; - char_id.char_id.uuid = p_char->uuid; - char_id.char_id.inst_id = p_char->handle; - char_id.srvc_id = p_char->service->service_uuid; mark_as_executing(conn_id); - BTA_GATTC_ReadCharacteristic(op->conn_id, &char_id, - BTA_GATT_AUTH_REQ_NONE); + BTA_GATTC_ReadCharacteristic(op->conn_id, p_char->handle, BTA_GATT_AUTH_REQ_NONE); list_remove(gatt_op_queue, op); } else if (op->type == GATT_READ_DESC) { const tBTA_GATTC_DESCRIPTOR *p_desc = BTA_GATTC_GetDescriptor(op->conn_id, op->handle); - const tBTA_GATTC_CHARACTERISTIC *p_char = p_desc->characteristic; - tBTA_GATTC_CHAR_DESCR_ID descr_id; - descr_id.descr_id.inst_id = p_desc->handle; - descr_id.descr_id.uuid = p_desc->uuid; - descr_id.char_id.char_id.uuid = p_char->uuid; - descr_id.char_id.char_id.inst_id = p_char->handle; - descr_id.char_id.srvc_id = p_char->service->service_uuid; mark_as_executing(conn_id); - BTA_GATTC_ReadCharDescr(op->conn_id, &descr_id, - BTA_GATT_AUTH_REQ_NONE); + BTA_GATTC_ReadCharDescr(op->conn_id, p_desc->handle, BTA_GATT_AUTH_REQ_NONE); list_remove(gatt_op_queue, op); } else if (op->type == GATT_WRITE_CHAR) { const tBTA_GATTC_CHARACTERISTIC *p_char = BTA_GATTC_GetCharacteristic(op->conn_id, op->handle); - tBTA_GATTC_CHAR_ID char_id; - char_id.char_id.uuid = p_char->uuid; - char_id.char_id.inst_id = p_char->handle; - char_id.srvc_id = p_char->service->service_uuid; - mark_as_executing(conn_id); - BTA_GATTC_WriteCharValue(op->conn_id, &char_id, op->write_type, op->len, + BTA_GATTC_WriteCharValue(op->conn_id, p_char->handle, op->write_type, op->len, op->p_value, BTA_GATT_AUTH_REQ_NONE); list_remove(gatt_op_queue, op); } else if (op->type == GATT_WRITE_DESC) { const tBTA_GATTC_DESCRIPTOR *p_desc = BTA_GATTC_GetDescriptor(op->conn_id, op->handle); - const tBTA_GATTC_CHARACTERISTIC *p_char = p_desc->characteristic; - tBTA_GATTC_CHAR_DESCR_ID descr_id; - descr_id.descr_id.inst_id = p_desc->handle; - descr_id.descr_id.uuid = p_desc->uuid; - descr_id.char_id.char_id.uuid = p_char->uuid; - descr_id.char_id.char_id.inst_id = p_char->handle; - descr_id.char_id.srvc_id = p_char->service->service_uuid; tBTA_GATT_UNFMT value; value.len = op->len; value.p_value = op->p_value; mark_as_executing(conn_id); - BTA_GATTC_WriteCharDescr(op->conn_id, &descr_id, BTA_GATTC_TYPE_WRITE, + BTA_GATTC_WriteCharDescr(op->conn_id, p_desc->handle, BTA_GATTC_TYPE_WRITE, &value, BTA_GATT_AUTH_REQ_NONE); list_remove(gatt_op_queue, op); } @@ -471,52 +446,6 @@ void bta_hh_le_open_conn(tBTA_HH_DEV_CB *p_cb, BD_ADDR remote_bda) /******************************************************************************* ** -** Function bta_hh_le_fill_16bits_gatt_id -** -** Description Utility function to fill a GATT ID strucure -** -*******************************************************************************/ -void bta_hh_le_fill_16bits_gatt_id(UINT8 inst_id, UINT16 uuid, tBTA_GATT_ID *p_output) -{ - p_output->inst_id = inst_id; - p_output->uuid.len = LEN_UUID_16; - p_output->uuid.uu.uuid16 = uuid; -} - -/******************************************************************************* -** -** Function bta_hh_le_fill_16bits_srvc_id -** -** Description Utility function to fill a service ID strucure with a 16 bits -** service UUID. -** -*******************************************************************************/ -void bta_hh_le_fill_16bits_srvc_id(BOOLEAN is_pri, UINT8 inst_id, UINT16 srvc_uuid, - tBTA_GATT_SRVC_ID *p_output) -{ - memset((void *)p_output, 0, sizeof(tBTA_GATT_SRVC_ID)); - p_output->is_primary = is_pri; - bta_hh_le_fill_16bits_gatt_id(inst_id, srvc_uuid, &p_output->id); - -} - -/******************************************************************************* -** -** Function bta_hh_le_fill_16bits_char_id -** -** Description Utility function to fill a char ID strucure with a 16 bits -** char UUID. -** -*******************************************************************************/ -void bta_hh_le_fill_16bits_char_id(UINT8 inst_id, UINT16 char_uuid, - tBTA_GATT_ID *p_output) -{ - memset((void *)p_output, 0, sizeof(tBTA_GATT_ID)); - bta_hh_le_fill_16bits_gatt_id(inst_id, char_uuid, p_output); -} - -/******************************************************************************* -** ** Function bta_hh_le_find_dev_cb_by_conn_id ** ** Description Utility function find a device control block by connection ID. @@ -769,14 +698,11 @@ static tBTA_HH_STATUS bta_hh_le_read_char_dscrpt(tBTA_HH_DEV_CB *p_cb, UINT16 ch void bta_hh_le_save_rpt_ref(tBTA_HH_DEV_CB *p_dev_cb, tBTA_HH_LE_RPT *p_rpt, tBTA_GATTC_READ *p_data) { - UINT8 *pp; - tBTA_HH_RPT_CACHE_ENTRY rpt_entry; - /* if the length of the descriptor value is right, parse it */ if (p_data->status == BTA_GATT_OK && - p_data->p_value && p_data->p_value->unformat.len == 2) + p_data->p_value && p_data->p_value->len == 2) { - pp = p_data->p_value->unformat.p_value; + UINT8 *pp = p_data->p_value->p_value; STREAM_TO_UINT8(p_rpt->rpt_id, pp); STREAM_TO_UINT8(p_rpt->rpt_type, pp); @@ -785,8 +711,9 @@ void bta_hh_le_save_rpt_ref(tBTA_HH_DEV_CB *p_dev_cb, tBTA_HH_LE_RPT *p_rpt, p_rpt->rpt_type = BTA_HH_RPTT_RESRV; #if BTA_HH_DEBUG == TRUE - APPL_TRACE_DEBUG("report ID: %d", p_rpt->rpt_id); + APPL_TRACE_DEBUG("%s: report ID: %d", __func__, p_rpt->rpt_id); #endif + tBTA_HH_RPT_CACHE_ENTRY rpt_entry; rpt_entry.rpt_id = p_rpt->rpt_id; rpt_entry.rpt_type = p_rpt->rpt_type; rpt_entry.rpt_uuid = p_rpt->uuid; @@ -824,18 +751,15 @@ void bta_hh_le_save_rpt_ref(tBTA_HH_DEV_CB *p_dev_cb, tBTA_HH_LE_RPT *p_rpt, void bta_hh_le_save_ext_rpt_ref(tBTA_HH_DEV_CB *p_dev_cb, tBTA_GATTC_READ *p_data) { - UINT8 *pp; - /* if the length of the descriptor value is right, parse it assume it's a 16 bits UUID */ if (p_data->status == BTA_GATT_OK && - p_data->p_value && p_data->p_value->unformat.len == 2) - { - pp = p_data->p_value->unformat.p_value; + p_data->p_value && p_data->p_value->len == 2) { + UINT8 *pp = p_data->p_value->p_value; STREAM_TO_UINT16(p_dev_cb->hid_srvc.ext_rpt_ref, pp); #if BTA_HH_DEBUG == TRUE - APPL_TRACE_DEBUG("External Report Reference UUID 0x%04x", + APPL_TRACE_DEBUG("%s: External Report Reference UUID 0x%04x", __func__, p_dev_cb->hid_srvc.ext_rpt_ref); #endif } @@ -851,35 +775,23 @@ void bta_hh_le_save_ext_rpt_ref(tBTA_HH_DEV_CB *p_dev_cb, ** Parameters: ** *******************************************************************************/ -void bta_hh_le_register_input_notif(tBTA_HH_DEV_CB *p_dev_cb, UINT8 srvc_inst, - UINT8 proto_mode, BOOLEAN register_ba) +void bta_hh_le_register_input_notif(tBTA_HH_DEV_CB *p_dev_cb, UINT8 proto_mode, BOOLEAN register_ba) { tBTA_HH_LE_RPT *p_rpt = &p_dev_cb->hid_srvc.report[0]; - tBTA_GATTC_CHAR_ID char_id; - UINT8 i; - UINT16 srvc_uuid; #if BTA_HH_DEBUG == TRUE - APPL_TRACE_DEBUG("bta_hh_le_register_input_notif mode: %d", proto_mode); + APPL_TRACE_DEBUG("%s: bta_hh_le_register_input_notif mode: %d", __func__, proto_mode); #endif - for (i = 0; i < BTA_HH_LE_RPT_MAX; i ++, p_rpt ++) + for (int i = 0; i < BTA_HH_LE_RPT_MAX; i ++, p_rpt ++) { if (p_rpt->rpt_type == BTA_HH_RPTT_INPUT) { - if (p_rpt->uuid == GATT_UUID_BATTERY_LEVEL) - srvc_uuid = UUID_SERVCLASS_BATTERY; - else - srvc_uuid = UUID_SERVCLASS_LE_HID; - - bta_hh_le_fill_16bits_srvc_id(TRUE, p_rpt->srvc_inst_id, srvc_uuid, &char_id.srvc_id); - bta_hh_le_fill_16bits_char_id(p_rpt->char_inst_id, p_rpt->uuid, &char_id.char_id); if (register_ba && p_rpt->uuid == GATT_UUID_BATTERY_LEVEL) { - BTA_GATTC_RegisterForNotifications(bta_hh_cb.gatt_if, - p_dev_cb->addr, - &char_id); + BTA_GATTC_RegisterForNotifications(bta_hh_cb.gatt_if, p_dev_cb->addr, + p_rpt->char_inst_id); } /* boot mode, deregister report input notification */ else if (proto_mode == BTA_HH_PROTO_BOOT_MODE) @@ -888,18 +800,16 @@ void bta_hh_le_register_input_notif(tBTA_HH_DEV_CB *p_dev_cb, UINT8 srvc_inst, p_rpt->client_cfg_value == BTA_GATT_CLT_CONFIG_NOTIFICATION) { APPL_TRACE_DEBUG("---> Deregister Report ID: %d", p_rpt->rpt_id); - BTA_GATTC_DeregisterForNotifications(bta_hh_cb.gatt_if, - p_dev_cb->addr, - &char_id); + BTA_GATTC_DeregisterForNotifications(bta_hh_cb.gatt_if, p_dev_cb->addr, + p_rpt->char_inst_id); } /* register boot reports notification */ else if (p_rpt->uuid == GATT_UUID_HID_BT_KB_INPUT || p_rpt->uuid == GATT_UUID_HID_BT_MOUSE_INPUT) { APPL_TRACE_DEBUG("<--- Register Boot Report ID: %d", p_rpt->rpt_id); - BTA_GATTC_RegisterForNotifications(bta_hh_cb.gatt_if, - p_dev_cb->addr, - &char_id); + BTA_GATTC_RegisterForNotifications(bta_hh_cb.gatt_if, p_dev_cb->addr, + p_rpt->char_inst_id); } } else if (proto_mode == BTA_HH_PROTO_RPT_MODE) @@ -910,17 +820,15 @@ void bta_hh_le_register_input_notif(tBTA_HH_DEV_CB *p_dev_cb, UINT8 srvc_inst, { APPL_TRACE_DEBUG("---> Deregister Boot Report ID: %d", p_rpt->rpt_id); - BTA_GATTC_DeregisterForNotifications(bta_hh_cb.gatt_if, - p_dev_cb->addr, - &char_id); + BTA_GATTC_DeregisterForNotifications(bta_hh_cb.gatt_if, p_dev_cb->addr, + p_rpt->char_inst_id); } else if (p_rpt->uuid == GATT_UUID_HID_REPORT && p_rpt->client_cfg_value == BTA_GATT_CLT_CONFIG_NOTIFICATION) { APPL_TRACE_DEBUG("<--- Register Report ID: %d", p_rpt->rpt_id); - BTA_GATTC_RegisterForNotifications(bta_hh_cb.gatt_if, - p_dev_cb->addr, - &char_id); + BTA_GATTC_RegisterForNotifications(bta_hh_cb.gatt_if, p_dev_cb->addr, + p_rpt->char_inst_id); } } /* @@ -943,7 +851,7 @@ void bta_hh_le_open_cmpl(tBTA_HH_DEV_CB *p_cb) #if BTA_HH_DEBUG bta_hh_le_hid_report_dbg(p_cb); #endif - bta_hh_le_register_input_notif(p_cb, 0, p_cb->mode, TRUE); + bta_hh_le_register_input_notif(p_cb, p_cb->mode, TRUE); bta_hh_sm_execute(p_cb, BTA_HH_OPEN_CMPL_EVT, NULL); #if (BTA_HH_LE_RECONN == TRUE) @@ -1048,7 +956,7 @@ BOOLEAN bta_hh_le_set_protocol_mode(tBTA_HH_DEV_CB *p_cb, tBTA_HH_PROTO_MODE mod else { /* if set to report mode, need to de-register all input report notification */ - bta_hh_le_register_input_notif(p_cb, 0, p_cb->mode, FALSE); + bta_hh_le_register_input_notif(p_cb, p_cb->mode, FALSE); cback_data.status = BTA_HH_OK; } if (p_cb->state == BTA_HH_W4_CONN_ST) @@ -1469,11 +1377,11 @@ void process_included(tBTA_HH_DEV_CB *p_dev_cb, tBTA_GATTC_SERVICE *service) { isn != list_end(service->included_svc); isn = list_next(isn)) { tBTA_GATTC_INCLUDED_SVC *p_isvc = list_node(isn); tBTA_GATTC_SERVICE *incl_svc = p_isvc->included_service; - if (incl_svc->service_uuid.id.uuid.uu.uuid16 == UUID_SERVCLASS_BATTERY && - incl_svc->service_uuid.id.uuid.len == LEN_UUID_16) { + if (incl_svc->uuid.uu.uuid16 == UUID_SERVCLASS_BATTERY && + incl_svc->uuid.len == LEN_UUID_16) { /* read include service UUID */ - p_dev_cb->hid_srvc.incl_srvc_inst = incl_svc->service_uuid.id.inst_id; + p_dev_cb->hid_srvc.incl_srvc_inst = incl_svc->handle; for (list_node_t *cn = list_begin(incl_svc->characteristics); cn != list_end(incl_svc->characteristics); cn = list_next(cn)) { @@ -1556,7 +1464,7 @@ static void bta_hh_le_search_hid_chars(tBTA_HH_DEV_CB *p_dev_cb, tBTA_GATTC_SERV case GATT_UUID_HID_BT_MOUSE_INPUT: case GATT_UUID_HID_BT_KB_INPUT: if (bta_hh_le_find_alloc_report_entry(p_dev_cb, - service->service_uuid.id.inst_id, + service->handle, p_char->uuid.uu.uuid16, p_char->handle) == NULL) APPL_TRACE_ERROR("%s: Add report entry failed !!!", __func__); @@ -1616,13 +1524,13 @@ void bta_hh_le_srvc_search_cmpl(tBTA_GATTC_SEARCH_CMPL *p_data) sn != list_end(services); sn = list_next(sn)) { tBTA_GATTC_SERVICE *service = list_node(sn); - if (service->service_uuid.id.uuid.uu.uuid16 == UUID_SERVCLASS_LE_HID && - service->service_uuid.is_primary && !have_hid) { + if (service->uuid.uu.uuid16 == UUID_SERVCLASS_LE_HID && + service->is_primary && !have_hid) { have_hid = true; /* found HID primamry service */ p_dev_cb->hid_srvc.in_use = TRUE; - p_dev_cb->hid_srvc.srvc_inst_id = service->service_uuid.id.inst_id; + p_dev_cb->hid_srvc.srvc_inst_id = service->handle; p_dev_cb->hid_srvc.proto_mode_handle = 0; p_dev_cb->hid_srvc.control_point_handle = 0; @@ -1630,7 +1538,7 @@ void bta_hh_le_srvc_search_cmpl(tBTA_GATTC_SEARCH_CMPL *p_data) bta_hh_le_search_hid_chars(p_dev_cb, service); APPL_TRACE_DEBUG("%s: have HID service inst_id= %d", __func__, p_dev_cb->hid_srvc.srvc_inst_id); - } else if (service->service_uuid.id.uuid.uu.uuid16 == UUID_SERVCLASS_SCAN_PARAM) { + } else if (service->uuid.uu.uuid16 == UUID_SERVCLASS_SCAN_PARAM) { p_dev_cb->scan_refresh_char_handle = 0; for (list_node_t *cn = list_begin(service->characteristics); @@ -1683,20 +1591,18 @@ void bta_hh_read_battery_level_cmpl(UINT8 status, tBTA_HH_DEV_CB *p_dev_cb, tBTA *******************************************************************************/ void bta_hh_le_save_rpt_map(tBTA_HH_DEV_CB *p_dev_cb, tBTA_GATTC_READ *p_data) { - UINT8 *pp ; tBTA_HH_LE_HID_SRVC *p_srvc = &p_dev_cb->hid_srvc; - pp = p_data->p_value->unformat.p_value; - osi_free_and_reset((void **)&p_srvc->rpt_map); - if (p_data->p_value->unformat.len > 0) - p_srvc->rpt_map = (UINT8 *)osi_malloc(p_data->p_value->unformat.len); + if (p_data->p_value->len > 0) + p_srvc->rpt_map = (UINT8 *)osi_malloc(p_data->p_value->len); if (p_srvc->rpt_map != NULL) { - STREAM_TO_ARRAY(p_srvc->rpt_map, pp, p_data->p_value->unformat.len); - p_srvc->descriptor.dl_len = p_data->p_value->unformat.len; + UINT8 *pp = p_data->p_value->p_value; + STREAM_TO_ARRAY(p_srvc->rpt_map, pp, p_data->p_value->len); + p_srvc->descriptor.dl_len = p_data->p_value->len; p_srvc->descriptor.dsc_list = p_dev_cb->hid_srvc.rpt_map; } } @@ -1724,6 +1630,9 @@ void bta_hh_le_proc_get_rpt_cmpl(tBTA_HH_DEV_CB *p_dev_cb, tBTA_GATTC_READ *p_da return; } + const tBTA_GATTC_CHARACTERISTIC *p_char = BTA_GATTC_GetCharacteristic(p_dev_cb->conn_id, + p_data->handle); + memset(&hs_data, 0, sizeof(hs_data)); hs_data.status = BTA_HH_ERR; hs_data.handle = p_dev_cb->hid_handle; @@ -1731,22 +1640,22 @@ void bta_hh_le_proc_get_rpt_cmpl(tBTA_HH_DEV_CB *p_dev_cb, tBTA_GATTC_READ *p_da if (p_data->status == BTA_GATT_OK) { p_rpt = bta_hh_le_find_report_entry(p_dev_cb, - p_data->srvc_id.id.inst_id, - p_data->char_id.uuid.uu.uuid16, - p_data->char_id.inst_id); + p_char->service->handle, + p_char->uuid.uu.uuid16, + p_char->handle); if (p_rpt != NULL && p_data->p_value != NULL) { - p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR) + p_data->p_value->unformat.len + 1); + p_buf = (BT_HDR *)osi_malloc(sizeof(BT_HDR) + p_data->p_value->len + 1); /* pack data send to app */ hs_data.status = BTA_HH_OK; - p_buf->len = p_data->p_value->unformat.len + 1; + p_buf->len = p_data->p_value->len + 1; p_buf->layer_specific = 0; p_buf->offset = 0; /* attach report ID as the first byte of the report before sending it to USB HID driver */ pp = (UINT8*)(p_buf + 1); UINT8_TO_STREAM(pp, p_rpt->rpt_id); - memcpy(pp, p_data->p_value->unformat.p_value, p_data->p_value->unformat.len); + memcpy(pp, p_data->p_value->p_value, p_data->p_value->len); hs_data.rsp_data.p_rpt_data =p_buf; } @@ -1778,7 +1687,7 @@ void bta_hh_le_proc_read_proto_mode(tBTA_HH_DEV_CB *p_dev_cb, tBTA_GATTC_READ *p { hs_data.status = BTA_HH_OK; /* match up BTE/BTA report/boot mode def*/ - hs_data.rsp_data.proto_mode = *(p_data->p_value->unformat.p_value); + hs_data.rsp_data.proto_mode = *(p_data->p_value->p_value); /* LE repot mode is the opposite value of BR/EDR report mode, flip it here */ if (hs_data.rsp_data.proto_mode == 0) hs_data.rsp_data.proto_mode = BTA_HH_PROTO_BOOT_MODE; @@ -1811,7 +1720,11 @@ void bta_hh_w4_le_read_char_cmpl(tBTA_HH_DEV_CB *p_dev_cb, tBTA_HH_DATA *p_buf) tBTA_GATTC_READ * p_data = (tBTA_GATTC_READ *)p_buf; UINT8 *pp ; - if (p_data->char_id.uuid.uu.uuid16 == GATT_UUID_BATTERY_LEVEL) + const tBTA_GATTC_CHARACTERISTIC *p_char = BTA_GATTC_GetCharacteristic(p_dev_cb->conn_id, + p_data->handle); + UINT16 char_uuid = p_char->uuid.uu.uuid16; + + if (char_uuid == GATT_UUID_BATTERY_LEVEL) { bta_hh_read_battery_level_cmpl(p_data->status, p_dev_cb, p_data); } @@ -1819,9 +1732,9 @@ void bta_hh_w4_le_read_char_cmpl(tBTA_HH_DEV_CB *p_dev_cb, tBTA_HH_DATA *p_buf) { if (p_data->status == BTA_GATT_OK && p_data->p_value) { - pp = p_data->p_value->unformat.p_value; + pp = p_data->p_value->p_value; - switch (p_data->char_id.uuid.uu.uuid16) + switch (char_uuid) { /* save device information */ case GATT_UUID_HID_INFORMATION: @@ -1837,8 +1750,7 @@ void bta_hh_w4_le_read_char_cmpl(tBTA_HH_DEV_CB *p_dev_cb, tBTA_HH_DATA *p_buf) default: #if BTA_HH_DEBUG == TRUE APPL_TRACE_ERROR("Unexpected read %s(0x%04x)", - bta_hh_uuid_to_str(p_data->char_id.uuid.uu.uuid16), - p_data->char_id.uuid.uu.uuid16); + bta_hh_uuid_to_str(char_uuid), char_uuid); #endif break; } @@ -1846,12 +1758,10 @@ void bta_hh_w4_le_read_char_cmpl(tBTA_HH_DEV_CB *p_dev_cb, tBTA_HH_DATA *p_buf) else { #if BTA_HH_DEBUG == TRUE - APPL_TRACE_ERROR("read uuid %s[0x%04x] error: %d", - bta_hh_uuid_to_str(p_data->char_id.uuid.uu.uuid16), - p_data->char_id.uuid.uu.uuid16, - p_data->status); + APPL_TRACE_ERROR("read uuid %s[0x%04x] error: %d", bta_hh_uuid_to_str(char_uuid), + char_uuid, p_data->status); #else - APPL_TRACE_ERROR("read uuid [0x%04x] error: %d", p_data->char_id.uuid.uu.uuid16, p_data->status); + APPL_TRACE_ERROR("read uuid [0x%04x] error: %d", char_uuid, p_data->status); #endif } } @@ -1871,7 +1781,11 @@ void bta_hh_le_read_char_cmpl (tBTA_HH_DEV_CB *p_dev_cb, tBTA_HH_DATA *p_buf) { tBTA_GATTC_READ * p_data = (tBTA_GATTC_READ *)p_buf; - switch (p_data->char_id.uuid.uu.uuid16) + const tBTA_GATTC_CHARACTERISTIC *p_char = BTA_GATTC_GetCharacteristic(p_dev_cb->conn_id, + p_data->handle); + UINT16 char_uuid = p_char->uuid.uu.uuid16; + + switch (char_uuid) { /* GET_REPORT */ case GATT_UUID_HID_REPORT: @@ -1887,7 +1801,7 @@ void bta_hh_le_read_char_cmpl (tBTA_HH_DEV_CB *p_dev_cb, tBTA_HH_DATA *p_buf) break; default: - APPL_TRACE_ERROR("Unexpected Read UUID: 0x%04x", p_data->char_id.uuid.uu.uuid16); + APPL_TRACE_ERROR("Unexpected Read UUID: 0x%04x", char_uuid); break; } @@ -1908,15 +1822,17 @@ void bta_hh_le_read_descr_cmpl(tBTA_HH_DEV_CB *p_dev_cb, tBTA_HH_DATA *p_buf) tBTA_GATTC_READ * p_data = (tBTA_GATTC_READ *)p_buf; UINT8 *pp; + const tBTA_GATTC_DESCRIPTOR *p_desc = BTA_GATTC_GetDescriptor(p_data->conn_id, p_data->handle); + /* if a report client configuration */ - if (p_data->descr_type.uuid.uu.uuid16 == GATT_UUID_CHAR_CLIENT_CONFIG) + if (p_desc->uuid.uu.uuid16 == GATT_UUID_CHAR_CLIENT_CONFIG) { if ((p_rpt = bta_hh_le_find_report_entry(p_dev_cb, - p_data->srvc_id.id.inst_id, - p_data->char_id.uuid.uu.uuid16, - p_data->char_id.inst_id)) != NULL) + p_desc->characteristic->service->handle, + p_desc->characteristic->uuid.uu.uuid16, + p_desc->characteristic->handle)) != NULL) { - pp = p_data->p_value->unformat.p_value; + pp = p_data->p_value->p_value; STREAM_TO_UINT16(p_rpt->client_cfg_value, pp); APPL_TRACE_DEBUG("Read Client Configuration: 0x%04x", p_rpt->client_cfg_value); @@ -1942,10 +1858,10 @@ void bta_hh_w4_le_read_descr_cmpl(tBTA_HH_DEV_CB *p_dev_cb, tBTA_HH_DATA *p_buf) if (p_data == NULL) return; - const tBTA_GATTC_DESCRIPTOR *p_desc = BTA_GATTC_GetDescriptor(p_data->conn_id, p_data->descr_type.inst_id); + const tBTA_GATTC_DESCRIPTOR *p_desc = BTA_GATTC_GetDescriptor(p_data->conn_id, p_data->handle); if (p_desc == NULL) { - APPL_TRACE_ERROR("%s: p_descr is NULL %d", __func__, p_data->descr_type.inst_id); + APPL_TRACE_ERROR("%s: p_descr is NULL %d", __func__, p_data->handle); return; } @@ -1960,7 +1876,7 @@ void bta_hh_w4_le_read_descr_cmpl(tBTA_HH_DEV_CB *p_dev_cb, tBTA_HH_DATA *p_buf) { case GATT_UUID_HID_REPORT: if ((p_rpt = bta_hh_le_find_report_entry(p_dev_cb, - p_desc->characteristic->service->service_uuid.id.inst_id, + p_desc->characteristic->service->handle, GATT_UUID_HID_REPORT, p_desc->characteristic->handle))) bta_hh_le_save_rpt_ref(p_dev_cb, p_rpt, p_data); @@ -1972,9 +1888,9 @@ void bta_hh_w4_le_read_descr_cmpl(tBTA_HH_DEV_CB *p_dev_cb, tBTA_HH_DATA *p_buf) case GATT_UUID_BATTERY_LEVEL: if ((p_rpt = bta_hh_le_find_report_entry(p_dev_cb, - p_data->srvc_id.id.inst_id, + p_desc->characteristic->service->handle, GATT_UUID_BATTERY_LEVEL, - p_data->char_id.inst_id))) + p_desc->characteristic->handle))) bta_hh_le_save_rpt_ref(p_dev_cb, p_rpt, p_data); break; @@ -2001,7 +1917,10 @@ void bta_hh_w4_le_write_cmpl(tBTA_HH_DEV_CB *p_dev_cb, tBTA_HH_DATA *p_buf) if (p_data == NULL) return; - if (p_data->char_id.uuid.uu.uuid16 == GATT_UUID_HID_PROTO_MODE) + const tBTA_GATTC_CHARACTERISTIC *p_char = BTA_GATTC_GetCharacteristic(p_dev_cb->conn_id, + p_data->handle); + + if (p_char->uuid.uu.uuid16 == GATT_UUID_HID_PROTO_MODE) { p_dev_cb->status = (p_data->status == BTA_GATT_OK) ? BTA_HH_OK : BTA_HH_ERR_PROTO; @@ -2028,17 +1947,20 @@ void bta_hh_le_write_cmpl(tBTA_HH_DEV_CB *p_dev_cb, tBTA_HH_DATA *p_buf) if (p_data == NULL || cb_evt == 0) return; + const tBTA_GATTC_CHARACTERISTIC *p_char = BTA_GATTC_GetCharacteristic(p_dev_cb->conn_id, + p_data->handle); + #if BTA_HH_DEBUG APPL_TRACE_DEBUG("bta_hh_le_write_cmpl w4_evt: %d", p_dev_cb->w4_evt); #endif - switch (p_data->char_id.uuid.uu.uuid16) + switch (p_char->uuid.uu.uuid16) { /* Set protocol finished */ case GATT_UUID_HID_PROTO_MODE: cback_data.handle = p_dev_cb->hid_handle; if (p_data->status == BTA_GATT_OK) { - bta_hh_le_register_input_notif(p_dev_cb, p_data->srvc_id.id.inst_id, p_dev_cb->mode, FALSE); + bta_hh_le_register_input_notif(p_dev_cb, p_dev_cb->mode, FALSE); cback_data.status = BTA_HH_OK; } else @@ -2082,12 +2004,17 @@ void bta_hh_le_write_char_descr_cmpl(tBTA_HH_DEV_CB *p_dev_cb, tBTA_HH_DATA *p_b tBTA_GATTC_WRITE *p_data = (tBTA_GATTC_WRITE *)p_buf; UINT8 srvc_inst_id, hid_inst_id; + const tBTA_GATTC_DESCRIPTOR *p_desc = BTA_GATTC_GetDescriptor(p_dev_cb->conn_id, + p_data->handle); + + UINT16 desc_uuid = p_desc->uuid.uu.uuid16; + UINT16 char_uuid = p_desc->characteristic->uuid.uu.uuid16; /* only write client configuration possible */ - if (p_data->descr_type.uuid.uu.uuid16 == GATT_UUID_CHAR_CLIENT_CONFIG) + if (desc_uuid == GATT_UUID_CHAR_CLIENT_CONFIG) { - srvc_inst_id = p_data->srvc_id.id.inst_id; + srvc_inst_id = p_desc->characteristic->service->handle; hid_inst_id = srvc_inst_id; - switch (p_data->char_id.uuid.uu.uuid16) + switch (char_uuid) { case GATT_UUID_BATTERY_LEVEL: /* battery level clt cfg registered */ hid_inst_id = bta_hh_le_find_service_inst_by_battery_inst_id(p_dev_cb, srvc_inst_id); @@ -2108,18 +2035,16 @@ void bta_hh_le_write_char_descr_cmpl(tBTA_HH_DEV_CB *p_dev_cb, tBTA_HH_DATA *p_b break; default: - APPL_TRACE_ERROR("Unknown char ID clt cfg: 0x%04x", p_data->char_id.uuid.uu.uuid16); + APPL_TRACE_ERROR("Unknown char ID clt cfg: 0x%04x", char_uuid); } } else { #if BTA_HH_DEBUG == TRUE - APPL_TRACE_ERROR("Unexpected write to %s(0x%04x)", - bta_hh_uuid_to_str(p_data->descr_type.uuid.uu.uuid16), - p_data->descr_type.uuid.uu.uuid16); + APPL_TRACE_ERROR("Unexpected write to %s(0x%04x)", + bta_hh_uuid_to_str(desc_uuid), desc_uuid); #else - APPL_TRACE_ERROR("Unexpected write to (0x%04x)", - p_data->descr_type.uuid.uu.uuid16); + APPL_TRACE_ERROR("Unexpected write to (0x%04x)", desc_uuid); #endif } @@ -2146,21 +2071,25 @@ void bta_hh_le_input_rpt_notify(tBTA_GATTC_NOTIFY *p_data) APPL_TRACE_ERROR("notification received from Unknown device"); return; } + + const tBTA_GATTC_CHARACTERISTIC *p_char = BTA_GATTC_GetCharacteristic(p_dev_cb->conn_id, + p_data->handle); + app_id= p_dev_cb->app_id; p_rpt = bta_hh_le_find_report_entry(p_dev_cb, p_dev_cb->hid_srvc.srvc_inst_id, - p_data->char_id.char_id.uuid.uu.uuid16, - p_data->char_id.char_id.inst_id); + p_char->uuid.uu.uuid16, + p_char->handle); if (p_rpt == NULL) { APPL_TRACE_ERROR("notification received for Unknown Report"); return; } - if (p_data->char_id.char_id.uuid.uu.uuid16 == GATT_UUID_HID_BT_MOUSE_INPUT) + if (p_char->uuid.uu.uuid16 == GATT_UUID_HID_BT_MOUSE_INPUT) app_id = BTA_HH_APP_ID_MI; - else if (p_data->char_id.char_id.uuid.uu.uuid16 == GATT_UUID_HID_BT_KB_INPUT) + else if (p_char->uuid.uu.uuid16 == GATT_UUID_HID_BT_KB_INPUT) app_id = BTA_HH_APP_ID_KB; APPL_TRACE_DEBUG("Notification received on report ID: %d", p_rpt->rpt_id); @@ -2728,18 +2657,8 @@ static void bta_hh_le_register_scpp_notif(tBTA_HH_DEV_CB *p_dev_cb, tBTA_GATT_ST if (bta_hh_le_write_char_clt_cfg (p_dev_cb, p_dev_cb->scan_refresh_char_handle, BTA_GATT_CLT_CONFIG_NOTIFICATION)) { - const tBTA_GATTC_CHARACTERISTIC *p_char = - BTA_GATTC_GetCharacteristic(p_dev_cb->conn_id, - p_dev_cb->scan_refresh_char_handle); - - tBTA_GATTC_CHAR_ID char_id; - UINT16 srvc_handle = p_char->service->service_uuid.id.inst_id; - bta_hh_le_fill_16bits_srvc_id(TRUE, srvc_handle, UUID_SERVCLASS_SCAN_PARAM, &char_id.srvc_id); - bta_hh_le_fill_16bits_char_id(p_char->handle, GATT_UUID_SCAN_REFRESH, &char_id.char_id); - - BTA_GATTC_RegisterForNotifications(bta_hh_cb.gatt_if, - p_dev_cb->addr, - &char_id); + BTA_GATTC_RegisterForNotifications(bta_hh_cb.gatt_if, p_dev_cb->addr, + p_dev_cb->scan_refresh_char_handle); return; } } diff --git a/bta/include/bta_gatt_api.h b/bta/include/bta_gatt_api.h index ba05c1d76..4c9f76c1e 100644 --- a/bta/include/bta_gatt_api.h +++ b/bta/include/bta_gatt_api.h @@ -204,52 +204,12 @@ typedef UINT8 tBTA_GATTC_WRITE_TYPE; #define BTA_GATT_CONN_NONE 0x0101 /* 0x0101 no connection to cancel */ typedef UINT16 tBTA_GATT_REASON; -typedef struct -{ - tBTA_GATT_ID id; - BOOLEAN is_primary; -}tBTA_GATT_SRVC_ID; - -typedef struct -{ - tBTA_GATT_SRVC_ID srvc_id; - tBTA_GATT_ID char_id; -}tBTA_GATTC_CHAR_ID; - -typedef struct -{ - tBTA_GATTC_CHAR_ID char_id; - tBTA_GATT_ID descr_id; -}tBTA_GATTC_CHAR_DESCR_ID; - -typedef struct -{ - tBTA_GATT_SRVC_ID srvc_id; - tBTA_GATT_SRVC_ID incl_svc_id; -}tBTA_GATTC_INCL_SVC_ID; - -#define BTA_GATT_TYPE_CHAR 0 -#define BTA_GATT_TYPE_CHAR_DESCR 1 -typedef UINT8 tBTA_GATT_ID_TYPE; - -typedef struct -{ - tBTA_GATT_ID_TYPE id_type; - union - { - tBTA_GATTC_CHAR_ID char_id; - tBTA_GATTC_CHAR_DESCR_ID char_descr_id; - - } id_value; -}tBTA_GATTC_ATTR_ID; - #define BTA_GATTC_MULTI_MAX GATT_MAX_READ_MULTI_HANDLES typedef struct { UINT8 num_attr; - tBTA_GATTC_ATTR_ID id_list[BTA_GATTC_MULTI_MAX]; - + UINT16 handles[BTA_GATTC_MULTI_MAX]; }tBTA_GATTC_MULTI; #define BTA_GATT_AUTH_REQ_NONE GATT_AUTH_REQ_NONE @@ -292,34 +252,17 @@ typedef struct typedef struct { - UINT8 num_pres_fmt; /* number of presentation format aggregated*/ - tBTA_GATTC_CHAR_DESCR_ID pre_format[BTA_GATTC_MULTI_MAX]; -}tBTA_GATT_CHAR_AGGRE_VALUE; - -typedef union -{ - tBTA_GATT_CHAR_AGGRE_VALUE aggre_value; - tBTA_GATT_UNFMT unformat; - -}tBTA_GATT_READ_VAL; - -typedef struct -{ UINT16 conn_id; tBTA_GATT_STATUS status; - tBTA_GATT_SRVC_ID srvc_id; - tBTA_GATT_ID char_id; - tBTA_GATT_ID descr_type; - tBTA_GATT_READ_VAL *p_value; + UINT16 handle; + tBTA_GATT_UNFMT *p_value; }tBTA_GATTC_READ; typedef struct { UINT16 conn_id; tBTA_GATT_STATUS status; - tBTA_GATT_SRVC_ID srvc_id; - tBTA_GATT_ID char_id; - tBTA_GATT_ID descr_type; + UINT16 handle; }tBTA_GATTC_WRITE; typedef struct @@ -337,7 +280,7 @@ typedef struct typedef struct { UINT16 conn_id; - tBTA_GATT_SRVC_ID service_uuid; + tBTA_GATT_ID service_uuid; }tBTA_GATTC_SRVC_RES; typedef struct @@ -370,8 +313,7 @@ typedef struct { UINT16 conn_id; BD_ADDR bda; - tBTA_GATTC_CHAR_ID char_id; - tBTA_GATT_ID descr_type; + UINT16 handle; UINT16 len; UINT8 value[BTA_GATT_MAX_ATTR_LEN]; BOOLEAN is_notify; @@ -618,7 +560,9 @@ typedef void (tBTA_GATTS_CBACK)(tBTA_GATTS_EVT event, tBTA_GATTS *p_data); typedef struct { - tBTA_GATT_SRVC_ID service_uuid; + tBT_UUID uuid; + BOOLEAN is_primary; + UINT16 handle; UINT16 s_handle; UINT16 e_handle; list_t *characteristics; /* list of tBTA_GATTC_CHARACTERISTIC */ @@ -797,7 +741,7 @@ extern const tBTA_GATTC_CHARACTERISTIC* BTA_GATTC_GetCharacteristic(UINT16 conn_ /******************************************************************************* ** -** Function BTA_GATTC_GetCharacteristic +** Function BTA_GATTC_GetDescriptor ** ** Description This function is called to find the characteristic on the given server. ** @@ -811,98 +755,6 @@ extern const tBTA_GATTC_DESCRIPTOR* BTA_GATTC_GetDescriptor(UINT16 conn_id, UINT /******************************************************************************* ** -** Function BTA_GATTC_GetFirstChar -** -** Description This function is called to find the first charatceristic of the -** service on the given server. -** -** Parameters conn_id: connection ID which identify the server. -** p_srvc_id: the service ID of which the characteristic is belonged to. -** p_char_uuid_cond: Characteristic UUID, if NULL find the first available -** characteristic. -** p_char_result: output parameter which will store the GATT -** characteristic ID. -** p_property: output parameter to carry the characteristic property. -** -** Returns returns status. -** -*******************************************************************************/ -extern tBTA_GATT_STATUS BTA_GATTC_GetFirstChar (UINT16 conn_id, - tBTA_GATT_SRVC_ID *p_srvc_id, - tBT_UUID *p_char_uuid_cond, - tBTA_GATTC_CHAR_ID *p_char_result, - tBTA_GATT_CHAR_PROP *p_property); - -/******************************************************************************* -** -** Function BTA_GATTC_GetNextChar -** -** Description This function is called to find the next charatceristic of the -** service on the given server. -** -** Parameters conn_id: connection ID which identify the server. -** p_start_char_id: start the characteristic search from the next record -** after the one identified by char_id. -** p_char_uuid_cond: Characteristic UUID, if NULL find the first available -** characteristic. -** p_char_result: output parameter which will store the GATT -** characteristic ID. -** p_property: output parameter, characteristic property. -** -** Returns returns status. -** -*******************************************************************************/ -extern tBTA_GATT_STATUS BTA_GATTC_GetNextChar (UINT16 conn_id, - tBTA_GATTC_CHAR_ID *p_start_char_id, - tBT_UUID *p_char_uuid_cond, - tBTA_GATTC_CHAR_ID *p_char_result, - tBTA_GATT_CHAR_PROP *p_property); - -/******************************************************************************* -** -** Function BTA_GATTC_GetFirstCharDescr -** -** Description This function is called to find the first charatceristic descriptor of the -** charatceristic on the given server. -** -** Parameters conn_id: connection ID which identify the server. -** p_char_id: the characteristic ID of which the descriptor is belonged to. -** p_descr_uuid_cond: Characteristic Descr UUID, if NULL find the first available -** characteristic. -** p_descr_result: output parameter which will store the GATT -** characteristic descriptor ID. -** -** Returns returns status. -** -*******************************************************************************/ -extern tBTA_GATT_STATUS BTA_GATTC_GetFirstCharDescr (UINT16 conn_id, tBTA_GATTC_CHAR_ID *p_char_id, - tBT_UUID *p_descr_uuid_cond, - tBTA_GATTC_CHAR_DESCR_ID *p_descr_result); - -/******************************************************************************* -** -** Function BTA_GATTC_GetFirstIncludedService -** -** Description This function is called to find the first included service of the -** service on the given server. -** -** Parameters conn_id: connection ID which identify the server. -** p_srvc_id: the service ID of which the included service is belonged to. -** p_uuid_cond: include service UUID, if NULL find the first available -** included service. -** p_result: output parameter which will store the GATT ID -** of the included service found. -** -** Returns returns status. -** -*******************************************************************************/ -extern tBTA_GATT_STATUS BTA_GATTC_GetFirstIncludedService(UINT16 conn_id, - tBTA_GATT_SRVC_ID *p_srvc_id, - tBT_UUID *p_uuid_cond, - tBTA_GATTC_INCL_SVC_ID *p_result); - -/******************************************************************************* -** ** Function BTA_GATTC_GetGattDb ** ** Description This function is called to get gatt db. @@ -920,34 +772,29 @@ extern void BTA_GATTC_GetGattDb(UINT16 conn_id, UINT16 start_handle, UINT16 end_ ** ** 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. +** handle - characteritic handle to read. ** ** Returns None ** *******************************************************************************/ -extern 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); /******************************************************************************* ** ** 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 ** *******************************************************************************/ -extern void BTA_GATTC_ReadCharDescr (UINT16 conn_id, - tBTA_GATTC_CHAR_DESCR_ID *p_char_descr_id, - tBTA_GATT_AUTH_REQ auth_req); +void BTA_GATTC_ReadCharDescr (UINT16 conn_id, UINT16 handle, tBTA_GATT_AUTH_REQ auth_req); /******************************************************************************* ** @@ -956,40 +803,40 @@ extern void BTA_GATTC_ReadCharDescr (UINT16 conn_id, ** Description This function is called to write characteristic value. ** ** Parameters conn_id - connection ID. -** p_char_id - characteristic ID to write. -** write_type - type of 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. ** ** Returns None ** *******************************************************************************/ -extern void BTA_GATTC_WriteCharValue (UINT16 conn_id, - tBTA_GATTC_CHAR_ID *p_char_id, - tBTA_GATTC_WRITE_TYPE write_type, - UINT16 len, - UINT8 *p_value, - tBTA_GATT_AUTH_REQ auth_req); +void BTA_GATTC_WriteCharValue ( UINT16 conn_id, + UINT16 handle, + tBTA_GATTC_WRITE_TYPE write_type, + UINT16 len, + UINT8 *p_value, + tBTA_GATT_AUTH_REQ auth_req); /******************************************************************************* ** ** 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. -** write_type - type of write. +** handle - descriptor handle to write. +** write_type - type of write. ** p_value - the value to be written. ** ** Returns None ** *******************************************************************************/ -extern void BTA_GATTC_WriteCharDescr (UINT16 conn_id, - tBTA_GATTC_CHAR_DESCR_ID *p_char_descr_id, - tBTA_GATTC_WRITE_TYPE write_type, - tBTA_GATT_UNFMT *p_data, - tBTA_GATT_AUTH_REQ auth_req); +void BTA_GATTC_WriteCharDescr (UINT16 conn_id, + UINT16 handle, + tBTA_GATTC_WRITE_TYPE write_type, + tBTA_GATT_UNFMT *p_data, + tBTA_GATT_AUTH_REQ auth_req); /******************************************************************************* ** @@ -998,12 +845,12 @@ extern void BTA_GATTC_WriteCharDescr (UINT16 conn_id, ** Description This function is called to send handle value confirmation. ** ** Parameters conn_id - connection ID. -** p_char_id - characteristic ID to confrim. +** handle - characteristic handle to confirm. ** ** Returns None ** *******************************************************************************/ -extern void BTA_GATTC_SendIndConfirm (UINT16 conn_id, tBTA_GATTC_CHAR_ID *p_char_id); +extern void BTA_GATTC_SendIndConfirm (UINT16 conn_id, UINT16 handle); /******************************************************************************* ** @@ -1011,17 +858,16 @@ extern void BTA_GATTC_SendIndConfirm (UINT16 conn_id, tBTA_GATTC_CHAR_ID *p_char ** ** Description This function is called to register for notification of a service. ** -** Parameters client_if - client interface. -** remote_bda - target GATT server. -** p_char_id - pointer to GATT characteristic ID. +** Parameters client_if - client interface. +** remote_bda - target GATT server. +** handle - GATT characteristic handle. ** ** Returns OK if registration succeed, otherwise failed. ** *******************************************************************************/ extern tBTA_GATT_STATUS BTA_GATTC_RegisterForNotifications (tBTA_GATTC_IF client_if, BD_ADDR remote_bda, - tBTA_GATTC_CHAR_ID *p_char_id); - + UINT16 handle); /******************************************************************************* ** @@ -1031,14 +877,14 @@ extern tBTA_GATT_STATUS BTA_GATTC_RegisterForNotifications (tBTA_GATTC_IF c ** ** Parameters client_if - client interface. ** remote_bda - target GATT server. -** p_char_id - pointer to a GATT characteristic ID. +** handle - GATT characteristic handle. ** ** Returns OK if deregistration succeed, otherwise failed. ** *******************************************************************************/ extern tBTA_GATT_STATUS BTA_GATTC_DeregisterForNotifications (tBTA_GATTC_IF client_if, BD_ADDR remote_bda, - tBTA_GATTC_CHAR_ID *p_char_id); + UINT16 handle); /******************************************************************************* ** @@ -1047,16 +893,16 @@ extern tBTA_GATT_STATUS BTA_GATTC_DeregisterForNotifications (tBTA_GATTC_IF ** Description This function is called to prepare write a characteristic value. ** ** Parameters conn_id - connection ID. -** p_char_id - GATT characteritic ID of the service. +** handle - GATT characteritic handle. ** offset - offset of the write value. -** len: length of the data to be written. +** len - length of the data to be written. ** p_value - the value to be written. ** ** Returns None ** *******************************************************************************/ extern void BTA_GATTC_PrepareWrite (UINT16 conn_id, - tBTA_GATTC_CHAR_ID *p_char_id, + UINT16 handle, UINT16 offset, UINT16 len, UINT8 *p_value, diff --git a/btif/include/btif_gatt_util.h b/btif/include/btif_gatt_util.h index af217c2d9..715e0c518 100644 --- a/btif/include/btif_gatt_util.h +++ b/btif/include/btif_gatt_util.h @@ -25,14 +25,10 @@ #include "bta/include/bta_gatt_api.h" void btif_to_bta_uuid(tBT_UUID *p_dest, bt_uuid_t *p_src); -void btif_to_bta_gatt_id(tBTA_GATT_ID *p_dest, btgatt_gatt_id_t *p_src); -void btif_to_bta_srvc_id(tBTA_GATT_SRVC_ID *p_dest, btgatt_srvc_id_t *p_src); void btif_to_bta_response(tBTA_GATTS_RSP *p_dest, btgatt_response_t* p_src); void btif_to_bta_uuid_mask(tBTA_DM_BLE_PF_COND_MASK *p_mask, bt_uuid_t *p_src); void bta_to_btif_uuid(bt_uuid_t *p_dest, tBT_UUID *p_src); -void bta_to_btif_srvc_id(btgatt_srvc_id_t *p_dest, tBTA_GATT_SRVC_ID *p_src); -void bta_to_btif_gatt_id(btgatt_gatt_id_t *p_dest, tBTA_GATT_ID *p_src); uint16_t set_read_value(btgatt_read_params_t *p_dest, tBTA_GATTC_READ *p_src); uint16_t get_uuid16(tBT_UUID *p_uuid); diff --git a/btif/src/btif_gatt_client.c b/btif/src/btif_gatt_client.c index 31bc4804c..8205ba56e 100644 --- a/btif/src/btif_gatt_client.c +++ b/btif/src/btif_gatt_client.c @@ -180,6 +180,7 @@ typedef struct btgatt_srvc_id_t incl_srvc_id; btgatt_gatt_id_t char_id; btgatt_gatt_id_t descr_id; + uint16_t handle; bt_uuid_t uuid; bt_uuid_t uuid_mask; uint16_t conn_id; @@ -320,20 +321,19 @@ static void btapp_gattc_req_data(UINT16 event, char *p_dest, char *p_src) if (p_src_data->read.p_value != NULL) { - p_dest_data->read.p_value = osi_malloc(sizeof(tBTA_GATT_READ_VAL)); + p_dest_data->read.p_value = osi_malloc(sizeof(tBTA_GATT_UNFMT)); memcpy(p_dest_data->read.p_value, p_src_data->read.p_value, - sizeof(tBTA_GATT_READ_VAL)); + sizeof(tBTA_GATT_UNFMT)); // Allocate buffer for att value if necessary - if (get_uuid16(&p_src_data->read.descr_type.uuid) != GATT_UUID_CHAR_AGG_FORMAT && - p_src_data->read.p_value->unformat.len > 0 && - p_src_data->read.p_value->unformat.p_value != NULL) { - p_dest_data->read.p_value->unformat.p_value = - osi_malloc(p_src_data->read.p_value->unformat.len); - memcpy(p_dest_data->read.p_value->unformat.p_value, - p_src_data->read.p_value->unformat.p_value, - p_src_data->read.p_value->unformat.len); + if (p_src_data->read.p_value->len > 0 && + p_src_data->read.p_value->p_value != NULL) { + p_dest_data->read.p_value->p_value = + osi_malloc(p_src_data->read.p_value->len); + memcpy(p_dest_data->read.p_value->p_value, + p_src_data->read.p_value->p_value, + p_src_data->read.p_value->len); } } else { BTIF_TRACE_WARNING("%s :Src read.p_value ptr is NULL for event 0x%x", @@ -356,11 +356,9 @@ static void btapp_gattc_free_req_data(UINT16 event, tBTA_GATTC *p_data) case BTA_GATTC_READ_DESCR_EVT: if (p_data != NULL && p_data->read.p_value != NULL) { - if ((get_uuid16(&p_data->read.descr_type.uuid) != - GATT_UUID_CHAR_AGG_FORMAT) && - (p_data->read.p_value->unformat.len > 0)) { - osi_free_and_reset((void **)&p_data->read.p_value->unformat.p_value); - } + if (p_data->read.p_value->len > 0) + osi_free_and_reset((void **)&p_data->read.p_value->p_value); + osi_free_and_reset((void **)&p_data->read.p_value); } break; @@ -479,13 +477,8 @@ static void btif_gattc_upstreams_evt(uint16_t event, char* p_param) case BTA_GATTC_WRITE_CHAR_EVT: case BTA_GATTC_PREP_WRITE_EVT: { - btgatt_write_params_t data; - bta_to_btif_srvc_id(&data.srvc_id, &p_data->write.srvc_id); - bta_to_btif_gatt_id(&data.char_id, &p_data->write.char_id); - - HAL_CBACK(bt_gatt_callbacks, client->write_characteristic_cb - , p_data->write.conn_id, p_data->write.status, &data - ); + HAL_CBACK(bt_gatt_callbacks, client->write_characteristic_cb, + p_data->write.conn_id, p_data->write.status, p_data->write.handle); break; } @@ -516,13 +509,8 @@ static void btif_gattc_upstreams_evt(uint16_t event, char* p_param) case BTA_GATTC_WRITE_DESCR_EVT: { - btgatt_write_params_t data; - bta_to_btif_srvc_id(&data.srvc_id, &p_data->write.srvc_id); - bta_to_btif_gatt_id(&data.char_id, &p_data->write.char_id); - bta_to_btif_gatt_id(&data.descr_id, &p_data->write.descr_type); - - HAL_CBACK(bt_gatt_callbacks, client->write_descriptor_cb - , p_data->write.conn_id, p_data->write.status, &data); + HAL_CBACK(bt_gatt_callbacks, client->write_descriptor_cb, + p_data->write.conn_id, p_data->write.status, p_data->write.handle); break; } @@ -531,22 +519,17 @@ static void btif_gattc_upstreams_evt(uint16_t event, char* p_param) btgatt_notify_params_t data; bdcpy(data.bda.address, p_data->notify.bda); - - bta_to_btif_srvc_id(&data.srvc_id, &p_data->notify.char_id.srvc_id); - bta_to_btif_gatt_id(&data.char_id, &p_data->notify.char_id.char_id); memcpy(data.value, p_data->notify.value, p_data->notify.len); + data.handle = p_data->notify.handle; data.is_notify = p_data->notify.is_notify; data.len = p_data->notify.len; - HAL_CBACK(bt_gatt_callbacks, client->notify_cb - , p_data->notify.conn_id, &data); + HAL_CBACK(bt_gatt_callbacks, client->notify_cb, p_data->notify.conn_id, &data); if (p_data->notify.is_notify == FALSE) - { - BTA_GATTC_SendIndConfirm(p_data->notify.conn_id, - &p_data->notify.char_id); - } + BTA_GATTC_SendIndConfirm(p_data->notify.conn_id, p_data->notify.handle); + break; } @@ -1121,8 +1104,6 @@ static void btgattc_handle_event(uint16_t event, char* p_param) { tBTA_GATT_STATUS status; tBT_UUID uuid; - tBTA_GATTC_CHAR_ID in_char_id; - tBTA_GATTC_CHAR_DESCR_ID in_char_descr_id; tBTA_GATT_UNFMT descr_val; btif_gattc_cb_t* p_cb = (btif_gattc_cb_t*) p_param; @@ -1256,40 +1237,23 @@ static void btgattc_handle_event(uint16_t event, char* p_param) } case BTIF_GATTC_READ_CHAR: - btif_to_bta_srvc_id(&in_char_id.srvc_id, &p_cb->srvc_id); - btif_to_bta_gatt_id(&in_char_id.char_id, &p_cb->char_id); - - BTA_GATTC_ReadCharacteristic(p_cb->conn_id, &in_char_id, p_cb->auth_req); + BTA_GATTC_ReadCharacteristic(p_cb->conn_id, p_cb->handle, p_cb->auth_req); break; case BTIF_GATTC_READ_CHAR_DESCR: - btif_to_bta_srvc_id(&in_char_descr_id.char_id.srvc_id, &p_cb->srvc_id); - btif_to_bta_gatt_id(&in_char_descr_id.char_id.char_id, &p_cb->char_id); - btif_to_bta_gatt_id(&in_char_descr_id.descr_id, &p_cb->descr_id); - - BTA_GATTC_ReadCharDescr(p_cb->conn_id, &in_char_descr_id, p_cb->auth_req); + BTA_GATTC_ReadCharDescr(p_cb->conn_id, p_cb->handle, p_cb->auth_req); break; case BTIF_GATTC_WRITE_CHAR: - btif_to_bta_srvc_id(&in_char_id.srvc_id, &p_cb->srvc_id); - btif_to_bta_gatt_id(&in_char_id.char_id, &p_cb->char_id); - - BTA_GATTC_WriteCharValue(p_cb->conn_id, &in_char_id, - p_cb->write_type, - p_cb->len, - p_cb->value, - p_cb->auth_req); + BTA_GATTC_WriteCharValue(p_cb->conn_id, p_cb->handle, p_cb->write_type, + p_cb->len, p_cb->value, p_cb->auth_req); break; case BTIF_GATTC_WRITE_CHAR_DESCR: - btif_to_bta_srvc_id(&in_char_descr_id.char_id.srvc_id, &p_cb->srvc_id); - btif_to_bta_gatt_id(&in_char_descr_id.char_id.char_id, &p_cb->char_id); - btif_to_bta_gatt_id(&in_char_descr_id.descr_id, &p_cb->descr_id); - descr_val.len = p_cb->len; descr_val.p_value = p_cb->value; - BTA_GATTC_WriteCharDescr(p_cb->conn_id, &in_char_descr_id, + BTA_GATTC_WriteCharDescr(p_cb->conn_id, p_cb->handle, p_cb->write_type, &descr_val, p_cb->auth_req); break; @@ -1299,27 +1263,19 @@ static void btgattc_handle_event(uint16_t event, char* p_param) break; case BTIF_GATTC_REG_FOR_NOTIFICATION: - btif_to_bta_srvc_id(&in_char_id.srvc_id, &p_cb->srvc_id); - btif_to_bta_gatt_id(&in_char_id.char_id, &p_cb->char_id); - status = BTA_GATTC_RegisterForNotifications(p_cb->client_if, - p_cb->bd_addr.address, &in_char_id); + p_cb->bd_addr.address, p_cb->handle); HAL_CBACK(bt_gatt_callbacks, client->register_for_notification_cb, - p_cb->conn_id, 1, status, &p_cb->srvc_id, - &p_cb->char_id); + p_cb->conn_id, 1, status, p_cb->handle); break; case BTIF_GATTC_DEREG_FOR_NOTIFICATION: - btif_to_bta_srvc_id(&in_char_id.srvc_id, &p_cb->srvc_id); - btif_to_bta_gatt_id(&in_char_id.char_id, &p_cb->char_id); - status = BTA_GATTC_DeregisterForNotifications(p_cb->client_if, - p_cb->bd_addr.address, &in_char_id); + p_cb->bd_addr.address, p_cb->handle); HAL_CBACK(bt_gatt_callbacks, client->register_for_notification_cb, - p_cb->conn_id, 0, status, &p_cb->srvc_id, - &p_cb->char_id); + p_cb->conn_id, 0, status, p_cb->handle); break; case BTIF_GATTC_REFRESH: @@ -1801,67 +1757,54 @@ static bt_status_t btif_gattc_get_gatt_db(int conn_id) } -static bt_status_t btif_gattc_read_char(int conn_id, btgatt_srvc_id_t* srvc_id, - btgatt_gatt_id_t* char_id, int auth_req ) +static bt_status_t btif_gattc_read_char(int conn_id, uint16_t handle, int auth_req) { CHECK_BTGATT_INIT(); btif_gattc_cb_t btif_cb; btif_cb.conn_id = (uint16_t) conn_id; + btif_cb.handle = (uint16_t) handle; btif_cb.auth_req = (uint8_t) auth_req; - memcpy(&btif_cb.srvc_id, srvc_id, sizeof(btgatt_srvc_id_t)); - memcpy(&btif_cb.char_id, char_id, sizeof(btgatt_gatt_id_t)); return btif_transfer_context(btgattc_handle_event, BTIF_GATTC_READ_CHAR, (char*) &btif_cb, sizeof(btif_gattc_cb_t), NULL); } -static bt_status_t btif_gattc_read_char_descr(int conn_id, btgatt_srvc_id_t* srvc_id, - btgatt_gatt_id_t* char_id, - btgatt_gatt_id_t* descr_id, - int auth_req ) +static bt_status_t btif_gattc_read_char_descr(int conn_id, uint16_t handle, int auth_req) { CHECK_BTGATT_INIT(); btif_gattc_cb_t btif_cb; btif_cb.conn_id = (uint16_t) conn_id; + btif_cb.handle = (uint16_t) handle; btif_cb.auth_req = (uint8_t) auth_req; - memcpy(&btif_cb.srvc_id, srvc_id, sizeof(btgatt_srvc_id_t)); - memcpy(&btif_cb.char_id, char_id, sizeof(btgatt_gatt_id_t)); - memcpy(&btif_cb.descr_id, descr_id, sizeof(btgatt_gatt_id_t)); return btif_transfer_context(btgattc_handle_event, BTIF_GATTC_READ_CHAR_DESCR, (char*) &btif_cb, sizeof(btif_gattc_cb_t), NULL); } -static bt_status_t btif_gattc_write_char(int conn_id, btgatt_srvc_id_t* srvc_id, - btgatt_gatt_id_t* char_id, int write_type, +static bt_status_t btif_gattc_write_char(int conn_id, uint16_t handle, int write_type, int len, int auth_req, char* p_value) { CHECK_BTGATT_INIT(); btif_gattc_cb_t btif_cb; btif_cb.conn_id = (uint16_t) conn_id; + btif_cb.handle = (uint16_t) handle; btif_cb.auth_req = (uint8_t) auth_req; btif_cb.write_type = (uint8_t) write_type; btif_cb.len = len > BTGATT_MAX_ATTR_LEN ? BTGATT_MAX_ATTR_LEN : len; - memcpy(&btif_cb.srvc_id, srvc_id, sizeof(btgatt_srvc_id_t)); - memcpy(&btif_cb.char_id, char_id, sizeof(btgatt_gatt_id_t)); memcpy(btif_cb.value, p_value, btif_cb.len); return btif_transfer_context(btgattc_handle_event, BTIF_GATTC_WRITE_CHAR, (char*) &btif_cb, sizeof(btif_gattc_cb_t), NULL); } -static bt_status_t btif_gattc_write_char_descr(int conn_id, btgatt_srvc_id_t* srvc_id, - btgatt_gatt_id_t* char_id, - btgatt_gatt_id_t* descr_id, +static bt_status_t btif_gattc_write_char_descr(int conn_id, uint16_t handle, int write_type, int len, int auth_req, char* p_value) { CHECK_BTGATT_INIT(); btif_gattc_cb_t btif_cb; btif_cb.conn_id = (uint16_t) conn_id; + btif_cb.handle = (uint16_t) handle; btif_cb.auth_req = (uint8_t) auth_req; btif_cb.write_type = (uint8_t) write_type; btif_cb.len = len > BTGATT_MAX_ATTR_LEN ? BTGATT_MAX_ATTR_LEN : len; - memcpy(&btif_cb.srvc_id, srvc_id, sizeof(btgatt_srvc_id_t)); - memcpy(&btif_cb.char_id, char_id, sizeof(btgatt_gatt_id_t)); - memcpy(&btif_cb.descr_id, descr_id, sizeof(btgatt_gatt_id_t)); memcpy(btif_cb.value, p_value, btif_cb.len); return btif_transfer_context(btgattc_handle_event, BTIF_GATTC_WRITE_CHAR_DESCR, (char*) &btif_cb, sizeof(btif_gattc_cb_t), NULL); @@ -1878,29 +1821,25 @@ static bt_status_t btif_gattc_execute_write(int conn_id, int execute) } static bt_status_t btif_gattc_reg_for_notification(int client_if, const bt_bdaddr_t *bd_addr, - btgatt_srvc_id_t* srvc_id, - btgatt_gatt_id_t* char_id) + uint16_t handle) { CHECK_BTGATT_INIT(); btif_gattc_cb_t btif_cb; btif_cb.client_if = (uint8_t) client_if; bdcpy(btif_cb.bd_addr.address, bd_addr->address); - memcpy(&btif_cb.srvc_id, srvc_id, sizeof(btgatt_srvc_id_t)); - memcpy(&btif_cb.char_id, char_id, sizeof(btgatt_gatt_id_t)); + btif_cb.handle = handle; return btif_transfer_context(btgattc_handle_event, BTIF_GATTC_REG_FOR_NOTIFICATION, (char*) &btif_cb, sizeof(btif_gattc_cb_t), NULL); } static bt_status_t btif_gattc_dereg_for_notification(int client_if, const bt_bdaddr_t *bd_addr, - btgatt_srvc_id_t* srvc_id, - btgatt_gatt_id_t* char_id) + uint16_t handle) { CHECK_BTGATT_INIT(); btif_gattc_cb_t btif_cb; btif_cb.client_if = (uint8_t) client_if; bdcpy(btif_cb.bd_addr.address, bd_addr->address); - memcpy(&btif_cb.srvc_id, srvc_id, sizeof(btgatt_srvc_id_t)); - memcpy(&btif_cb.char_id, char_id, sizeof(btgatt_gatt_id_t)); + btif_cb.handle = handle; return btif_transfer_context(btgattc_handle_event, BTIF_GATTC_DEREG_FOR_NOTIFICATION, (char*) &btif_cb, sizeof(btif_gattc_cb_t), NULL); } diff --git a/btif/src/btif_gatt_server.c b/btif/src/btif_gatt_server.c index 5dc31fb31..4a4cc5b4b 100644 --- a/btif/src/btif_gatt_server.c +++ b/btif/src/btif_gatt_server.c @@ -441,11 +441,13 @@ static void btgatts_handle_event(uint16_t event, char* p_param) case BTIF_GATTS_CREATE_SERVICE: { - tBTA_GATT_SRVC_ID srvc_id; - btif_to_bta_srvc_id(&srvc_id, &p_cb->srvc_id); - BTA_GATTS_CreateService(p_cb->server_if, &srvc_id.id.uuid, - srvc_id.id.inst_id, p_cb->num_handles, - srvc_id.is_primary); + tBT_UUID uuid; + btif_to_bta_uuid(&uuid, &p_cb->srvc_id.id.uuid); + + BTA_GATTS_CreateService(p_cb->server_if, &uuid, + p_cb->srvc_id.id.inst_id, p_cb->num_handles, + p_cb->srvc_id.is_primary); + break; } diff --git a/btif/src/btif_gatt_util.c b/btif/src/btif_gatt_util.c index ded1093a6..c93d866b4 100644 --- a/btif/src/btif_gatt_util.c +++ b/btif/src/btif_gatt_util.c @@ -109,19 +109,6 @@ void btif_to_bta_uuid(tBT_UUID *p_dest, bt_uuid_t *p_src) } } -void btif_to_bta_gatt_id(tBTA_GATT_ID *p_dest, btgatt_gatt_id_t *p_src) -{ - p_dest->inst_id = p_src->inst_id; - btif_to_bta_uuid(&p_dest->uuid, &p_src->uuid); -} - -void btif_to_bta_srvc_id(tBTA_GATT_SRVC_ID *p_dest, btgatt_srvc_id_t *p_src) -{ - p_dest->id.inst_id = p_src->id.inst_id; - btif_to_bta_uuid(&p_dest->id.uuid, &p_src->id.uuid); - p_dest->is_primary = p_src->is_primary; -} - void btif_to_bta_response(tBTA_GATTS_RSP *p_dest, btgatt_response_t* p_src) { p_dest->attr_value.auth_req = p_src->attr_value.auth_req; @@ -199,19 +186,6 @@ void bta_to_btif_uuid(bt_uuid_t *p_dest, tBT_UUID *p_src) } } -void bta_to_btif_gatt_id(btgatt_gatt_id_t *p_dest, tBTA_GATT_ID *p_src) -{ - p_dest->inst_id = p_src->inst_id; - bta_to_btif_uuid(&p_dest->uuid, &p_src->uuid); -} - -void bta_to_btif_srvc_id(btgatt_srvc_id_t *p_dest, tBTA_GATT_SRVC_ID *p_src) -{ - p_dest->id.inst_id = p_src->id.inst_id; - bta_to_btif_uuid(&p_dest->id.uuid, &p_src->id.uuid); - p_dest->is_primary = p_src->is_primary; -} - /******************************************************************************* * Utility functions *******************************************************************************/ @@ -237,44 +211,25 @@ uint16_t get_uuid16(tBT_UUID *p_uuid) uint16_t set_read_value(btgatt_read_params_t *p_dest, tBTA_GATTC_READ *p_src) { - uint16_t descr_type = 0; uint16_t len = 0; p_dest->status = p_src->status; - bta_to_btif_srvc_id(&p_dest->srvc_id, &p_src->srvc_id); - bta_to_btif_gatt_id(&p_dest->char_id, &p_src->char_id); - bta_to_btif_gatt_id(&p_dest->descr_id, &p_src->descr_type); - - descr_type = get_uuid16(&p_src->descr_type.uuid); + p_dest->handle = p_src->handle; - switch (descr_type) + if (( p_src->status == BTA_GATT_OK ) &&(p_src->p_value != NULL)) { - case GATT_UUID_CHAR_AGG_FORMAT: - /* not supported */ - p_dest->value_type = GATTC_READ_VALUE_TYPE_AGG_FORMAT; - break; - - default: - if (( p_src->status == BTA_GATT_OK ) &&(p_src->p_value != NULL)) - { - LOG_INFO(LOG_TAG, "%s unformat.len = %d ", __FUNCTION__, p_src->p_value->unformat.len); - p_dest->value.len = p_src->p_value->unformat.len; - if ( p_src->p_value->unformat.len > 0 && p_src->p_value->unformat.p_value != NULL ) - { - memcpy(p_dest->value.value, p_src->p_value->unformat.p_value, - p_src->p_value->unformat.len); - } - len += p_src->p_value->unformat.len; - } - else - { - p_dest->value.len = 0; - } - - p_dest->value_type = GATTC_READ_VALUE_TYPE_VALUE; - break; + LOG_INFO(LOG_TAG, "%s len = %d ", __FUNCTION__, p_src->p_value->len); + p_dest->value.len = p_src->p_value->len; + if ( p_src->p_value->len > 0 && p_src->p_value->p_value != NULL ) + memcpy(p_dest->value.value, p_src->p_value->p_value, + p_src->p_value->len); + + len += p_src->p_value->len; + } else { + p_dest->value.len = 0; } + p_dest->value_type = GATTC_READ_VALUE_TYPE_VALUE; return len; } diff --git a/service/hal/bluetooth_gatt_interface.cpp b/service/hal/bluetooth_gatt_interface.cpp index 107395c7b..2f7cf538a 100644 --- a/service/hal/bluetooth_gatt_interface.cpp +++ b/service/hal/bluetooth_gatt_interface.cpp @@ -130,20 +130,16 @@ void SearchCompleteCallback(int conn_id, int status) { SearchCompleteCallback(g_interface, conn_id, status)); } -void RegisterForNotificationCallback(int conn_id, int registered, int status, - btgatt_srvc_id_t *srvc_id, - btgatt_gatt_id_t *char_id) { +void RegisterForNotificationCallback(int conn_id, int registered, int status, uint16_t handle) { shared_lock lock(g_instance_lock); VERIFY_INTERFACE_OR_RETURN(); LOG(INFO) << __func__ << " - conn_id: " << conn_id << " - status: " << status << " - registered: " << registered - << " - srvc_id: " << (srvc_id ? srvc_id->id.inst_id : 0) - << " - char_id: " << (char_id ? char_id->inst_id : 0); + << " - handle: " << handle; FOR_EACH_CLIENT_OBSERVER( - RegisterForNotificationCallback(g_interface, conn_id, status, registered, - srvc_id, char_id)); + RegisterForNotificationCallback(g_interface, conn_id, status, registered, handle)); } void NotifyCallback(int conn_id, btgatt_notify_params_t *p_data) { @@ -152,8 +148,7 @@ void NotifyCallback(int conn_id, btgatt_notify_params_t *p_data) { VLOG(2) << __func__ << " - conn_id: " << conn_id << " - address: " << BtAddrString(&p_data->bda) - << " - srvc_id: " << (p_data ? p_data->srvc_id.id.inst_id : 0) - << " - char_id: " << (p_data ? p_data->char_id.inst_id : 0) + << " - handle: " << p_data->handle << " - len: " << p_data->len << " - is_notify: " << p_data->is_notify; @@ -161,8 +156,7 @@ void NotifyCallback(int conn_id, btgatt_notify_params_t *p_data) { NotifyCallback(g_interface, conn_id, p_data)); } -void WriteCharacteristicCallback(int conn_id, int status, - btgatt_write_params_t *p_data) { +void WriteCharacteristicCallback(int conn_id, int status, uint16_t handle) { shared_lock lock(g_instance_lock); VERIFY_INTERFACE_OR_RETURN(); @@ -170,11 +164,11 @@ void WriteCharacteristicCallback(int conn_id, int status, << " - status: " << status; FOR_EACH_CLIENT_OBSERVER( - WriteCharacteristicCallback(g_interface, conn_id, status, p_data)); + WriteCharacteristicCallback(g_interface, conn_id, status, handle)); } void WriteDescriptorCallback(int conn_id, int status, - btgatt_write_params_t *p_data) { + uint16_t handle) { shared_lock lock(g_instance_lock); VERIFY_INTERFACE_OR_RETURN(); @@ -182,7 +176,7 @@ void WriteDescriptorCallback(int conn_id, int status, << " - status: " << status; FOR_EACH_CLIENT_OBSERVER( - WriteDescriptorCallback(g_interface, conn_id, status, p_data)); + WriteDescriptorCallback(g_interface, conn_id, status, handle)); } void ListenCallback(int status, int client_if) { @@ -648,8 +642,7 @@ void BluetoothGattInterface::ClientObserver::RegisterForNotificationCallback( int /* conn_id */, int /* status */, int /* registered */, - btgatt_srvc_id_t* /* srvc_id */, - btgatt_gatt_id_t* /* char_id */) { + uint16_t /* handle */) { // Do nothing } @@ -664,7 +657,7 @@ void BluetoothGattInterface::ClientObserver::WriteCharacteristicCallback( BluetoothGattInterface* /* gatt_iface */, int /* conn_id */, int /* status */, - btgatt_write_params_t* /* p_data */) { + uint16_t /* handle */) { // Do nothing } @@ -672,7 +665,7 @@ void BluetoothGattInterface::ClientObserver::WriteDescriptorCallback( BluetoothGattInterface* /* gatt_iface */, int /* conn_id */, int /* status */, - btgatt_write_params_t* /* p_data */) { + uint16_t /* handle */) { // Do nothing } diff --git a/service/hal/bluetooth_gatt_interface.h b/service/hal/bluetooth_gatt_interface.h index fea6eb529..462220cba 100644 --- a/service/hal/bluetooth_gatt_interface.h +++ b/service/hal/bluetooth_gatt_interface.h @@ -82,9 +82,7 @@ class BluetoothGattInterface { virtual void RegisterForNotificationCallback( BluetoothGattInterface* gatt_iface, - int conn_id, int status, int registered, - btgatt_srvc_id_t* srvc_id, - btgatt_gatt_id_t* char_id); + int conn_id, int status, int registered, uint16_t handle); virtual void NotifyCallback( BluetoothGattInterface* gatt_iface, @@ -92,15 +90,11 @@ class BluetoothGattInterface { virtual void WriteCharacteristicCallback( BluetoothGattInterface* gatt_iface, - int conn_id, - int status, - btgatt_write_params_t* p_data); + int conn_id, int status, uint16_t handle); virtual void WriteDescriptorCallback( BluetoothGattInterface* gatt_iface, - int conn_id, - int status, - btgatt_write_params_t* p_data); + int conn_id, int status, uint16_t handle); virtual void ListenCallback( BluetoothGattInterface* gatt_iface, -- 2.11.0