2016-09-26 13:37:39 +00:00
|
|
|
/******************************************************************************
|
|
|
|
*
|
|
|
|
* Copyright (C) 2003-2012 Broadcom Corporation
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at:
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
*
|
|
|
|
* This file contains the GATT client discovery procedures and cache
|
|
|
|
* related functions.
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
#include "bt_target.h"
|
|
|
|
|
2017-04-19 09:16:24 +00:00
|
|
|
#if defined(GATTC_INCLUDED) && (GATTC_INCLUDED == TRUE)
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include "utl.h"
|
|
|
|
#include "bta_sys.h"
|
|
|
|
#include "sdp_api.h"
|
|
|
|
#include "sdpdefs.h"
|
|
|
|
#include "bta_gattc_int.h"
|
|
|
|
#include "btm_api.h"
|
|
|
|
#include "btm_ble_api.h"
|
2017-08-17 13:13:45 +00:00
|
|
|
#include "allocator.h"
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
#define LOG_TAG "bt_bta_gattc"
|
|
|
|
// #include "osi/include/log.h"
|
|
|
|
|
|
|
|
static void bta_gattc_char_dscpt_disc_cmpl(UINT16 conn_id, tBTA_GATTC_SERV *p_srvc_cb);
|
2017-04-23 09:52:18 +00:00
|
|
|
#if (SDP_INCLUDED == TRUE)
|
2016-09-26 13:37:39 +00:00
|
|
|
static tBTA_GATT_STATUS bta_gattc_sdp_service_disc(UINT16 conn_id, tBTA_GATTC_SERV *p_server_cb);
|
|
|
|
#define BTA_GATT_SDP_DB_SIZE 4096
|
2017-04-23 09:52:18 +00:00
|
|
|
#endif ///SDP_INCLUDED == TRUE
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
** Constants
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#if (defined BTA_GATT_DEBUG && BTA_GATT_DEBUG == TRUE)
|
2016-11-24 18:10:15 +00:00
|
|
|
static char *bta_gattc_attr_type[] = {
|
2016-09-26 13:37:39 +00:00
|
|
|
"I", /* Included Service */
|
|
|
|
"C", /* Characteristic */
|
|
|
|
"D" /* Characteristic Descriptor */
|
|
|
|
};
|
|
|
|
/* utility functions */
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_gattc_display_cache_server
|
|
|
|
**
|
|
|
|
** Description debug function to display the server cache.
|
|
|
|
**
|
|
|
|
** Returns none.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
static void bta_gattc_display_cache_server(tBTA_GATTC_CACHE *p_cache)
|
|
|
|
{
|
|
|
|
UINT8 i = 0, j;
|
|
|
|
tBTA_GATTC_CACHE *p_cur_srvc = p_cache;
|
|
|
|
tBTA_GATTC_CACHE_ATTR *p_attr;
|
|
|
|
|
|
|
|
APPL_TRACE_ERROR("<================Start Server Cache =============>");
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
while (p_cur_srvc) {
|
2016-09-26 13:37:39 +00:00
|
|
|
APPL_TRACE_ERROR("Service[%d]: handle[%d ~ %d] %s[0x%04x] inst[%d]",
|
2016-11-24 18:10:15 +00:00
|
|
|
i, 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);
|
2016-09-26 13:37:39 +00:00
|
|
|
i ++;
|
|
|
|
|
|
|
|
p_attr = p_cur_srvc->p_attr;
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
for (j = 0; p_attr; j ++ ) {
|
2016-09-26 13:37:39 +00:00
|
|
|
APPL_TRACE_ERROR("\t Attr[0x%04x] handle[%d] uuid[0x%04x] inst[%d] type[%s] prop[0x%1x]",
|
2016-11-24 18:10:15 +00:00
|
|
|
j + 1, p_attr->attr_handle, p_attr->p_uuid->uuid16, p_attr->inst_id,
|
|
|
|
bta_gattc_attr_type[p_attr->attr_type], p_attr->property);
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
p_attr = p_attr->p_next;
|
|
|
|
}
|
|
|
|
p_cur_srvc = p_cur_srvc->p_next;
|
|
|
|
}
|
|
|
|
|
|
|
|
APPL_TRACE_ERROR("<================End Server Cache =============>");
|
|
|
|
APPL_TRACE_ERROR(" ");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_gattc_display_explore_record
|
|
|
|
**
|
|
|
|
** Description debug function to display the exploration list
|
|
|
|
**
|
|
|
|
** Returns none.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
static void bta_gattc_display_explore_record(tBTA_GATTC_ATTR_REC *p_rec, UINT8 num_rec)
|
|
|
|
{
|
|
|
|
UINT8 i;
|
|
|
|
tBTA_GATTC_ATTR_REC *pp = p_rec;
|
|
|
|
|
|
|
|
APPL_TRACE_ERROR("<================Start Explore Queue =============>");
|
2016-11-24 18:10:15 +00:00
|
|
|
for (i = 0; i < num_rec; i ++, pp ++) {
|
2016-09-26 13:37:39 +00:00
|
|
|
APPL_TRACE_ERROR("\t rec[%d] uuid[0x%04x] s_handle[%d] e_handle[%d] is_primary[%d]",
|
2016-11-24 18:10:15 +00:00
|
|
|
i + 1, pp->uuid.uu.uuid16, pp->s_handle, pp->e_handle, pp->is_primary);
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
APPL_TRACE_ERROR("<================ End Explore Queue =============>");
|
|
|
|
APPL_TRACE_ERROR(" ");
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif /* BTA_GATT_DEBUG == TRUE */
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_gattc_alloc_cache_buf
|
|
|
|
**
|
2017-08-17 13:13:45 +00:00
|
|
|
** Description Allocate a buffer for database cache.
|
2016-09-26 13:37:39 +00:00
|
|
|
**
|
|
|
|
** Returns status
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
BT_HDR *bta_gattc_alloc_cache_buf(tBTA_GATTC_SERV *p_srvc_cb)
|
|
|
|
{
|
|
|
|
BT_HDR *p_buf;
|
|
|
|
|
2017-08-17 13:13:45 +00:00
|
|
|
if ((p_buf = (BT_HDR *)osi_calloc(GATT_DB_BUF_SIZE)) == NULL) {
|
|
|
|
APPL_TRACE_DEBUG("No resources: buffer allocation failed.");
|
2016-09-26 13:37:39 +00:00
|
|
|
utl_freebuf((void **)&p_srvc_cb->p_srvc_list);
|
|
|
|
p_srvc_cb->free_byte = 0;
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
p_srvc_cb->p_free = (UINT8 *) p_buf;
|
2017-08-17 13:13:45 +00:00
|
|
|
p_srvc_cb->free_byte = GATT_DB_BUF_SIZE;
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
/* link into buffer queue */
|
2017-08-17 13:13:45 +00:00
|
|
|
fixed_queue_enqueue(p_srvc_cb->cache_buffer, p_buf);
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
#if BTA_GATT_DEBUG== TRUE
|
|
|
|
APPL_TRACE_DEBUG("allocating new buffer: free byte = %d", p_srvc_cb->free_byte);
|
|
|
|
#endif
|
|
|
|
return p_buf;
|
|
|
|
}
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_gattc_init_cache
|
|
|
|
**
|
|
|
|
** Description Initialize the database cache and discovery related resources.
|
|
|
|
**
|
|
|
|
** Returns status
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
tBTA_GATT_STATUS bta_gattc_init_cache(tBTA_GATTC_SERV *p_srvc_cb)
|
|
|
|
{
|
|
|
|
tBTA_GATT_STATUS status = BTA_GATT_OK;
|
|
|
|
|
2017-08-17 13:13:45 +00:00
|
|
|
while (!fixed_queue_is_empty(p_srvc_cb->cache_buffer)) {
|
|
|
|
osi_free (fixed_queue_dequeue(p_srvc_cb->cache_buffer));
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
utl_freebuf((void **)&p_srvc_cb->p_srvc_list);
|
|
|
|
|
2017-08-17 13:13:45 +00:00
|
|
|
if ((p_srvc_cb->p_srvc_list = (tBTA_GATTC_ATTR_REC *)osi_malloc(BTA_GATTC_ATTR_LIST_SIZE)) == NULL) {
|
|
|
|
APPL_TRACE_DEBUG("No resources: buffer allocation failed.");
|
2016-09-26 13:37:39 +00:00
|
|
|
status = GATT_NO_RESOURCES;
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
p_srvc_cb->total_srvc = 0;
|
|
|
|
p_srvc_cb->cur_srvc_idx =
|
2016-11-24 18:10:15 +00:00
|
|
|
p_srvc_cb->cur_char_idx =
|
|
|
|
p_srvc_cb->next_avail_idx = 0;
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (bta_gattc_alloc_cache_buf(p_srvc_cb) == NULL) {
|
2016-09-26 13:37:39 +00:00
|
|
|
status = GATT_NO_RESOURCES;
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
p_srvc_cb->p_cur_srvc = p_srvc_cb->p_srvc_cache = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_gattc_get_srvc_inst_id
|
|
|
|
**
|
|
|
|
** Description get service instance number
|
|
|
|
**
|
|
|
|
** Returns instance ID of the service.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
static UINT8 bta_gattc_get_srvc_inst_id(tBTA_GATTC_SERV *p_srvc_cb, tBT_UUID uuid)
|
|
|
|
{
|
|
|
|
UINT8 i = 0, inst = 0;
|
|
|
|
tBTA_GATTC_ATTR_REC *p_srvc_rec;
|
|
|
|
|
|
|
|
for (i = 0; i < p_srvc_cb->total_srvc; i ++)
|
2016-11-24 18:10:15 +00:00
|
|
|
/*
|
|
|
|
for (; i < p_srvc_cb->cur_srvc_idx; i ++)*/
|
2016-09-26 13:37:39 +00:00
|
|
|
{
|
|
|
|
p_srvc_rec = p_srvc_cb->p_srvc_list + i;
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (bta_gattc_uuid_compare(&p_srvc_rec->uuid, &uuid, TRUE)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
inst ++;
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
return inst ;
|
|
|
|
}
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_gattc_get_char_inst_id
|
|
|
|
**
|
|
|
|
** Description get characteristic instance number
|
|
|
|
**
|
|
|
|
** Returns characteristic instance ID.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
static UINT8 bta_gattc_get_char_inst_id(tBTA_GATTC_CACHE *p_service_cache, tBT_UUID *p_uuid)
|
|
|
|
{
|
|
|
|
UINT8 inst = 0;
|
|
|
|
tBTA_GATTC_CACHE_ATTR *p_attr;
|
|
|
|
tBT_UUID attr_uuid;
|
|
|
|
|
|
|
|
p_attr = p_service_cache->p_attr;
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
while (p_attr) {
|
2016-09-26 13:37:39 +00:00
|
|
|
bta_gattc_pack_attr_uuid(p_attr, &attr_uuid);
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (bta_gattc_uuid_compare(&attr_uuid, p_uuid, TRUE)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
inst ++;
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
p_attr = p_attr->p_next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return inst ;
|
|
|
|
}
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_gattc_get_char_descr_inst_id
|
|
|
|
**
|
|
|
|
** Description get characteristic descriptor instance number
|
|
|
|
**
|
|
|
|
** Returns characteristic instance ID.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
static UINT8 bta_gattc_get_char_descr_inst_id(tBTA_GATTC_CACHE_ATTR *p_char_attr, tBT_UUID *p_uuid)
|
|
|
|
{
|
|
|
|
UINT8 inst = 0;
|
|
|
|
tBT_UUID attr_uuid;
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_char_attr != NULL) {
|
2016-09-26 13:37:39 +00:00
|
|
|
p_char_attr = p_char_attr->p_next;
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
while (p_char_attr) {
|
2016-09-26 13:37:39 +00:00
|
|
|
bta_gattc_pack_attr_uuid(p_char_attr, &attr_uuid);
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (bta_gattc_uuid_compare(&attr_uuid, p_uuid, TRUE)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
inst ++;
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
p_char_attr = p_char_attr->p_next;
|
|
|
|
}
|
|
|
|
return inst ;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_gattc_add_srvc_to_cache
|
|
|
|
**
|
|
|
|
** Description Add a service into database cache.
|
|
|
|
**
|
|
|
|
** Returns status
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
static tBTA_GATT_STATUS bta_gattc_add_srvc_to_cache(tBTA_GATTC_SERV *p_srvc_cb,
|
2016-11-24 18:10:15 +00:00
|
|
|
UINT16 s_handle, UINT16 e_handle,
|
|
|
|
tBT_UUID *p_uuid,
|
|
|
|
BOOLEAN is_primary, UINT8 srvc_inst)
|
2016-09-26 13:37:39 +00:00
|
|
|
{
|
|
|
|
tBTA_GATTC_CACHE *p_new_srvc = NULL;
|
|
|
|
tBTA_GATT_STATUS status = BTA_GATT_OK;
|
|
|
|
|
|
|
|
#if (defined BTA_GATT_DEBUG && BTA_GATT_DEBUG == TRUE)
|
|
|
|
APPL_TRACE_DEBUG("Add a service into Service");
|
|
|
|
APPL_TRACE_DEBUG("free byte = %d, req %d bytes.", p_srvc_cb->free_byte, sizeof(tBTA_GATTC_CACHE))
|
|
|
|
#endif
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_srvc_cb->free_byte < sizeof(tBTA_GATTC_CACHE)) {
|
|
|
|
if (bta_gattc_alloc_cache_buf(p_srvc_cb) == NULL) {
|
2016-09-26 13:37:39 +00:00
|
|
|
return GATT_NO_RESOURCES;
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
p_new_srvc = (tBTA_GATTC_CACHE *)p_srvc_cb->p_free;
|
|
|
|
/* 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 = srvc_inst;
|
|
|
|
p_new_srvc->p_next = NULL;
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_srvc_cb->p_cur_srvc != NULL) {
|
2016-09-26 13:37:39 +00:00
|
|
|
p_srvc_cb->p_cur_srvc->p_next = p_new_srvc;
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
p_srvc_cb->p_cur_srvc = p_new_srvc;
|
|
|
|
p_srvc_cb->p_cur_srvc->p_cur_char = NULL;
|
|
|
|
|
|
|
|
/* first service */
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_srvc_cb->p_srvc_cache == NULL) {
|
2016-09-26 13:37:39 +00:00
|
|
|
p_srvc_cb->p_srvc_cache = p_new_srvc;
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
/* update buffer managament info */
|
|
|
|
p_srvc_cb->p_free += sizeof(tBTA_GATTC_CACHE);
|
|
|
|
p_srvc_cb->free_byte -= sizeof(tBTA_GATTC_CACHE);
|
|
|
|
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_gattc_add_attr_to_cache
|
|
|
|
**
|
|
|
|
** Description Add an attribute into database cache buffer.
|
|
|
|
**
|
|
|
|
** Returns status
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
static tBTA_GATT_STATUS bta_gattc_add_attr_to_cache(tBTA_GATTC_SERV *p_srvc_cb,
|
2016-11-24 18:10:15 +00:00
|
|
|
UINT16 handle,
|
|
|
|
tBT_UUID *p_uuid,
|
|
|
|
UINT8 property,
|
|
|
|
tBTA_GATTC_ATTR_TYPE type)
|
2016-09-26 13:37:39 +00:00
|
|
|
{
|
|
|
|
tBTA_GATTC_CACHE_ATTR *p_attr;
|
|
|
|
tBTA_GATT_STATUS status = BTA_GATT_OK;
|
|
|
|
UINT16 len = sizeof(tBTA_GATTC_CACHE_ATTR) + p_uuid->len;
|
|
|
|
UINT8 *pp;
|
|
|
|
|
|
|
|
#if (defined BTA_GATT_DEBUG && BTA_GATT_DEBUG == TRUE)
|
|
|
|
APPL_TRACE_DEBUG("bta_gattc_add_attr_to_cache: Add a [%s] into Service", bta_gattc_attr_type[type]);
|
|
|
|
APPL_TRACE_DEBUG("handle=%d uuid16=0x%x property=0x%x type=%d", handle, p_uuid->uu.uuid16, property, type);
|
|
|
|
APPL_TRACE_DEBUG("free byte = %d, req %d bytes.", p_srvc_cb->free_byte, len);
|
|
|
|
#endif
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_srvc_cb->p_cur_srvc == NULL) {
|
2016-09-26 13:37:39 +00:00
|
|
|
APPL_TRACE_ERROR("Illegal action to add char/descr/incl srvc before adding a service!");
|
|
|
|
return GATT_WRONG_STATE;
|
|
|
|
}
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_srvc_cb->free_byte < len) {
|
|
|
|
if (bta_gattc_alloc_cache_buf(p_srvc_cb) == NULL) {
|
2016-09-26 13:37:39 +00:00
|
|
|
return GATT_NO_RESOURCES;
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
p_attr = (tBTA_GATTC_CACHE_ATTR *)p_srvc_cb->p_free;
|
|
|
|
|
|
|
|
p_attr->attr_handle = handle;
|
|
|
|
p_attr->attr_type = type;
|
|
|
|
p_attr->property = property;
|
|
|
|
p_attr->uuid_len = p_uuid->len;
|
|
|
|
p_attr->p_uuid = (tBTA_GATTC_UUID *)(p_attr + 1);
|
|
|
|
p_attr->p_next = NULL;
|
|
|
|
|
|
|
|
pp = (UINT8 *)p_attr->p_uuid;
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_uuid->len == LEN_UUID_16) {
|
2016-09-26 13:37:39 +00:00
|
|
|
UINT16_TO_STREAM(pp, p_uuid->uu.uuid16);
|
2016-11-24 18:10:15 +00:00
|
|
|
} else if (p_uuid->len == LEN_UUID_128) {
|
2016-09-26 13:37:39 +00:00
|
|
|
memcpy(pp, p_uuid->uu.uuid128, LEN_UUID_128);
|
|
|
|
}
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (type == BTA_GATTC_ATTR_TYPE_CHAR) {
|
2016-09-26 13:37:39 +00:00
|
|
|
p_attr->inst_id = bta_gattc_get_char_inst_id(p_srvc_cb->p_cur_srvc, p_uuid);
|
|
|
|
p_srvc_cb->p_cur_srvc->p_cur_char = p_attr;
|
2016-11-24 18:10:15 +00:00
|
|
|
} else if (type == BTA_GATTC_ATTR_TYPE_CHAR_DESCR) {
|
2016-09-26 13:37:39 +00:00
|
|
|
p_attr->inst_id = bta_gattc_get_char_descr_inst_id(p_srvc_cb->p_cur_srvc->p_cur_char, p_uuid);
|
2016-11-24 18:10:15 +00:00
|
|
|
} else { /* TODO: --->> temp treat included service as single instance */
|
2016-09-26 13:37:39 +00:00
|
|
|
p_attr->inst_id = 0;
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
/* update service information */
|
|
|
|
p_srvc_cb->p_free += len;
|
|
|
|
p_srvc_cb->free_byte -= len;
|
|
|
|
|
|
|
|
/* first attribute within the service, update the attribute pointer */
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_srvc_cb->p_cur_srvc->p_attr == NULL) {
|
2016-09-26 13:37:39 +00:00
|
|
|
p_srvc_cb->p_cur_srvc->p_attr = p_attr;
|
|
|
|
}
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_srvc_cb->p_cur_srvc->p_last_attr != NULL) {
|
2016-09-26 13:37:39 +00:00
|
|
|
p_srvc_cb->p_cur_srvc->p_last_attr->p_next = p_attr;
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
p_srvc_cb->p_cur_srvc->p_last_attr = p_attr;
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_gattc_get_disc_range
|
|
|
|
**
|
|
|
|
** Description get discovery stating and ending handle range.
|
|
|
|
**
|
|
|
|
** Returns None.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void bta_gattc_get_disc_range(tBTA_GATTC_SERV *p_srvc_cb, UINT16 *p_s_hdl, UINT16 *p_e_hdl, BOOLEAN is_srvc)
|
|
|
|
{
|
|
|
|
tBTA_GATTC_ATTR_REC *p_rec = NULL;
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (is_srvc) {
|
2016-09-26 13:37:39 +00:00
|
|
|
p_rec = p_srvc_cb->p_srvc_list + p_srvc_cb->cur_srvc_idx;
|
|
|
|
*p_s_hdl = p_rec->s_handle;
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
p_rec = p_srvc_cb->p_srvc_list + p_srvc_cb->cur_char_idx;
|
|
|
|
*p_s_hdl = p_rec->s_handle + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
*p_e_hdl = p_rec->e_handle;
|
|
|
|
#if (defined BTA_GATT_DEBUG && BTA_GATT_DEBUG == TRUE)
|
2016-11-24 18:10:15 +00:00
|
|
|
APPL_TRACE_DEBUG("discover range [%d ~ %d]", p_rec->s_handle, p_rec->e_handle);
|
2016-09-26 13:37:39 +00:00
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_gattc_discover_pri_service
|
|
|
|
**
|
|
|
|
** Description Start primary service discovery
|
|
|
|
**
|
|
|
|
** Returns status of the operation.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
tBTA_GATT_STATUS bta_gattc_discover_pri_service(UINT16 conn_id, tBTA_GATTC_SERV *p_server_cb,
|
2016-11-24 18:10:15 +00:00
|
|
|
UINT8 disc_type)
|
2016-09-26 13:37:39 +00:00
|
|
|
{
|
|
|
|
tBTA_GATTC_CLCB *p_clcb = bta_gattc_find_clcb_by_conn_id(conn_id);
|
|
|
|
tBTA_GATT_STATUS status = BTA_GATT_ERROR;
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_clcb) {
|
|
|
|
if (p_clcb->transport == BTA_TRANSPORT_LE) {
|
2016-09-26 13:37:39 +00:00
|
|
|
status = bta_gattc_discover_procedure(conn_id, p_server_cb, disc_type);
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
2017-04-23 09:52:18 +00:00
|
|
|
#if (SDP_INCLUDED == TRUE)
|
2016-09-26 13:37:39 +00:00
|
|
|
status = bta_gattc_sdp_service_disc(conn_id, p_server_cb);
|
2017-04-23 09:52:18 +00:00
|
|
|
#endif ///SDP_INCLUDED == TRUE
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_gattc_discover_procedure
|
|
|
|
**
|
|
|
|
** Description Start a particular type of discovery procedure on server.
|
|
|
|
**
|
|
|
|
** Returns status of the operation.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
tBTA_GATT_STATUS bta_gattc_discover_procedure(UINT16 conn_id, tBTA_GATTC_SERV *p_server_cb,
|
2016-11-24 18:10:15 +00:00
|
|
|
UINT8 disc_type)
|
2016-09-26 13:37:39 +00:00
|
|
|
{
|
|
|
|
tGATT_DISC_PARAM param;
|
|
|
|
BOOLEAN is_service = TRUE;
|
|
|
|
|
|
|
|
memset(¶m, 0, sizeof(tGATT_DISC_PARAM));
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (disc_type == GATT_DISC_SRVC_ALL || disc_type == GATT_DISC_SRVC_BY_UUID) {
|
2016-09-26 13:37:39 +00:00
|
|
|
param.s_handle = 1;
|
|
|
|
param.e_handle = 0xFFFF;
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
|
|
|
if (disc_type == GATT_DISC_CHAR_DSCPT) {
|
2016-09-26 13:37:39 +00:00
|
|
|
is_service = FALSE;
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
bta_gattc_get_disc_range(p_server_cb, ¶m.s_handle, ¶m.e_handle, is_service);
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (param.s_handle > param.e_handle) {
|
2016-09-26 13:37:39 +00:00
|
|
|
return GATT_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return GATTC_Discover (conn_id, disc_type, ¶m);
|
|
|
|
|
|
|
|
}
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_gattc_start_disc_include_srvc
|
|
|
|
**
|
|
|
|
** Description Start discovery for included service
|
|
|
|
**
|
|
|
|
** Returns status of the operation.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
tBTA_GATT_STATUS bta_gattc_start_disc_include_srvc(UINT16 conn_id, tBTA_GATTC_SERV *p_srvc_cb)
|
|
|
|
{
|
|
|
|
return bta_gattc_discover_procedure(conn_id, p_srvc_cb, GATT_DISC_INC_SRVC);
|
|
|
|
}
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_gattc_start_disc_char
|
|
|
|
**
|
|
|
|
** Description Start discovery for characteristic
|
|
|
|
**
|
|
|
|
** Returns status of the operation.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
tBTA_GATT_STATUS bta_gattc_start_disc_char(UINT16 conn_id, tBTA_GATTC_SERV *p_srvc_cb)
|
|
|
|
{
|
|
|
|
p_srvc_cb->total_char = 0;
|
|
|
|
|
|
|
|
return bta_gattc_discover_procedure(conn_id, p_srvc_cb, GATT_DISC_CHAR);
|
|
|
|
}
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_gattc_start_disc_char_dscp
|
|
|
|
**
|
|
|
|
** Description Start discovery for characteristic descriptor
|
|
|
|
**
|
|
|
|
** Returns none.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void bta_gattc_start_disc_char_dscp(UINT16 conn_id, tBTA_GATTC_SERV *p_srvc_cb)
|
|
|
|
{
|
|
|
|
APPL_TRACE_DEBUG("starting discover characteristics descriptor");
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (bta_gattc_discover_procedure(conn_id, p_srvc_cb, GATT_DISC_CHAR_DSCPT) != 0) {
|
2016-09-26 13:37:39 +00:00
|
|
|
bta_gattc_char_dscpt_disc_cmpl(conn_id, p_srvc_cb);
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_gattc_explore_srvc
|
|
|
|
**
|
|
|
|
** Description process the service discovery complete event
|
|
|
|
**
|
|
|
|
** Returns status
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
static void bta_gattc_explore_srvc(UINT16 conn_id, tBTA_GATTC_SERV *p_srvc_cb)
|
|
|
|
{
|
|
|
|
tBTA_GATTC_ATTR_REC *p_rec = p_srvc_cb->p_srvc_list + p_srvc_cb->cur_srvc_idx;
|
|
|
|
tBTA_GATTC_CLCB *p_clcb = bta_gattc_find_clcb_by_conn_id(conn_id);
|
|
|
|
|
|
|
|
APPL_TRACE_DEBUG("Start service discovery: srvc_idx = %d", p_srvc_cb->cur_srvc_idx);
|
|
|
|
|
|
|
|
p_srvc_cb->cur_char_idx = p_srvc_cb->next_avail_idx = p_srvc_cb->total_srvc;
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_clcb == NULL) {
|
2016-09-26 13:37:39 +00:00
|
|
|
APPL_TRACE_ERROR("unknown connection ID");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* start expore a service if there is service not been explored */
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_srvc_cb->cur_srvc_idx < p_srvc_cb->total_srvc) {
|
2016-09-26 13:37:39 +00:00
|
|
|
/* add the first service into cache */
|
|
|
|
if (bta_gattc_add_srvc_to_cache (p_srvc_cb,
|
|
|
|
p_rec->s_handle,
|
|
|
|
p_rec->e_handle,
|
|
|
|
&p_rec->uuid,
|
|
|
|
p_rec->is_primary,
|
2016-11-24 18:10:15 +00:00
|
|
|
p_rec->srvc_inst_id) == 0) {
|
2016-09-26 13:37:39 +00:00
|
|
|
/* start discovering included services */
|
|
|
|
bta_gattc_start_disc_include_srvc(conn_id, p_srvc_cb);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* no service found at all, the end of server discovery*/
|
2016-11-22 12:32:45 +00:00
|
|
|
LOG_DEBUG("%s no more services found", __func__);
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
#if (defined BTA_GATT_DEBUG && BTA_GATT_DEBUG == TRUE)
|
|
|
|
bta_gattc_display_cache_server(p_srvc_cb->p_srvc_cache);
|
|
|
|
#endif
|
|
|
|
/* save cache to NV */
|
|
|
|
p_clcb->p_srcb->state = BTA_GATTC_SERV_SAVE;
|
|
|
|
bta_gattc_co_cache_open(p_srvc_cb->server_bda, BTA_GATTC_CI_CACHE_OPEN_EVT,
|
|
|
|
conn_id, TRUE);
|
|
|
|
}
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_gattc_incl_srvc_disc_cmpl
|
|
|
|
**
|
|
|
|
** Description process the relationship discovery complete event
|
|
|
|
**
|
|
|
|
** Returns status
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
static void bta_gattc_incl_srvc_disc_cmpl(UINT16 conn_id, tBTA_GATTC_SERV *p_srvc_cb)
|
|
|
|
{
|
|
|
|
p_srvc_cb->cur_char_idx = p_srvc_cb->total_srvc;
|
|
|
|
|
|
|
|
/* start discoverying characteristic */
|
|
|
|
bta_gattc_start_disc_char(conn_id, p_srvc_cb);
|
|
|
|
}
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_gattc_char_disc_cmpl
|
|
|
|
**
|
|
|
|
** Description process the characteristic discovery complete event
|
|
|
|
**
|
|
|
|
** Returns status
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
static void bta_gattc_char_disc_cmpl(UINT16 conn_id, tBTA_GATTC_SERV *p_srvc_cb)
|
|
|
|
{
|
|
|
|
tBTA_GATTC_ATTR_REC *p_rec = p_srvc_cb->p_srvc_list + p_srvc_cb->cur_char_idx;
|
|
|
|
|
|
|
|
/* if there are characteristic needs to be explored */
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_srvc_cb->total_char > 0) {
|
2016-09-26 13:37:39 +00:00
|
|
|
/* add the first characteristic into cache */
|
|
|
|
bta_gattc_add_attr_to_cache (p_srvc_cb,
|
|
|
|
p_rec->s_handle,
|
|
|
|
&p_rec->uuid,
|
|
|
|
p_rec->property,
|
|
|
|
BTA_GATTC_ATTR_TYPE_CHAR);
|
|
|
|
|
|
|
|
/* start discoverying characteristic descriptor , if failed, disc for next char*/
|
|
|
|
bta_gattc_start_disc_char_dscp(conn_id, p_srvc_cb);
|
2016-11-24 18:10:15 +00:00
|
|
|
} else { /* otherwise start with next service */
|
2016-09-26 13:37:39 +00:00
|
|
|
p_srvc_cb->cur_srvc_idx ++;
|
|
|
|
|
|
|
|
bta_gattc_explore_srvc (conn_id, p_srvc_cb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_gattc_char_dscpt_disc_cmpl
|
|
|
|
**
|
|
|
|
** Description process the char descriptor discovery complete event
|
|
|
|
**
|
|
|
|
** Returns status
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
static void bta_gattc_char_dscpt_disc_cmpl(UINT16 conn_id, tBTA_GATTC_SERV *p_srvc_cb)
|
|
|
|
{
|
|
|
|
tBTA_GATTC_ATTR_REC *p_rec = NULL;
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (-- p_srvc_cb->total_char > 0) {
|
2016-09-26 13:37:39 +00:00
|
|
|
p_rec = p_srvc_cb->p_srvc_list + (++ p_srvc_cb->cur_char_idx);
|
|
|
|
/* add the next characteristic into cache */
|
|
|
|
bta_gattc_add_attr_to_cache (p_srvc_cb,
|
|
|
|
p_rec->s_handle,
|
|
|
|
&p_rec->uuid,
|
|
|
|
p_rec->property,
|
|
|
|
BTA_GATTC_ATTR_TYPE_CHAR);
|
|
|
|
|
|
|
|
/* start discoverying next characteristic for char descriptor */
|
|
|
|
bta_gattc_start_disc_char_dscp(conn_id, p_srvc_cb);
|
2016-11-24 18:10:15 +00:00
|
|
|
} else
|
|
|
|
/* all characteristic has been explored, start with next service if any */
|
2016-09-26 13:37:39 +00:00
|
|
|
{
|
|
|
|
#if (defined BTA_GATT_DEBUG && BTA_GATT_DEBUG == TRUE)
|
|
|
|
APPL_TRACE_ERROR("all char has been explored");
|
|
|
|
#endif
|
|
|
|
p_srvc_cb->cur_srvc_idx ++;
|
|
|
|
bta_gattc_explore_srvc (conn_id, p_srvc_cb);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
static BOOLEAN bta_gattc_srvc_in_list(tBTA_GATTC_SERV *p_srvc_cb, UINT16 s_handle,
|
|
|
|
UINT16 e_handle, tBT_UUID uuid)
|
|
|
|
{
|
|
|
|
tBTA_GATTC_ATTR_REC *p_rec = NULL;
|
|
|
|
UINT8 i;
|
|
|
|
BOOLEAN exist_srvc = FALSE;
|
|
|
|
UNUSED(uuid);
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (!GATT_HANDLE_IS_VALID(s_handle) || !GATT_HANDLE_IS_VALID(e_handle)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
APPL_TRACE_ERROR("invalid included service handle: [0x%04x ~ 0x%04x]", s_handle, e_handle);
|
|
|
|
exist_srvc = TRUE;
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
|
|
|
for (i = 0; i < p_srvc_cb->next_avail_idx; i ++) {
|
2016-09-26 13:37:39 +00:00
|
|
|
p_rec = p_srvc_cb->p_srvc_list + i;
|
|
|
|
|
|
|
|
/* a new service should not have any overlap with other service handle range */
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_rec->s_handle == s_handle || p_rec->e_handle == e_handle) {
|
2016-09-26 13:37:39 +00:00
|
|
|
exist_srvc = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return exist_srvc;
|
|
|
|
}
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_gattc_add_srvc_to_list
|
|
|
|
**
|
|
|
|
** Description Add a service into explore pending list
|
|
|
|
**
|
|
|
|
** Returns status
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
static tBTA_GATT_STATUS bta_gattc_add_srvc_to_list(tBTA_GATTC_SERV *p_srvc_cb,
|
2016-11-24 18:10:15 +00:00
|
|
|
UINT16 s_handle, UINT16 e_handle,
|
|
|
|
tBT_UUID uuid, BOOLEAN is_primary)
|
2016-09-26 13:37:39 +00:00
|
|
|
{
|
|
|
|
tBTA_GATTC_ATTR_REC *p_rec = NULL;
|
|
|
|
tBTA_GATT_STATUS status = BTA_GATT_OK;
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_srvc_cb->p_srvc_list && p_srvc_cb->next_avail_idx < BTA_GATTC_MAX_CACHE_CHAR) {
|
2016-09-26 13:37:39 +00:00
|
|
|
p_rec = p_srvc_cb->p_srvc_list + p_srvc_cb->next_avail_idx;
|
|
|
|
|
|
|
|
APPL_TRACE_DEBUG("%s handle=%d, service type=0x%04x",
|
2016-11-24 18:10:15 +00:00
|
|
|
__func__, s_handle, uuid.uu.uuid16);
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
p_rec->s_handle = s_handle;
|
|
|
|
p_rec->e_handle = e_handle;
|
|
|
|
p_rec->is_primary = is_primary;
|
|
|
|
p_rec->srvc_inst_id = bta_gattc_get_srvc_inst_id(p_srvc_cb, uuid);
|
|
|
|
memcpy(&p_rec->uuid, &uuid, sizeof(tBT_UUID));
|
|
|
|
|
|
|
|
p_srvc_cb->total_srvc ++;
|
|
|
|
p_srvc_cb->next_avail_idx ++;
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
|
|
|
/* allocate bigger buffer ?? */
|
2016-09-26 13:37:39 +00:00
|
|
|
status = GATT_DB_FULL;
|
|
|
|
|
|
|
|
APPL_TRACE_ERROR("service not added, no resources or wrong state");
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_gattc_add_char_to_list
|
|
|
|
**
|
|
|
|
** Description Add a characteristic into explore pending list
|
|
|
|
**
|
|
|
|
** Returns status
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
static tBTA_GATT_STATUS bta_gattc_add_char_to_list(tBTA_GATTC_SERV *p_srvc_cb,
|
2016-11-24 18:10:15 +00:00
|
|
|
UINT16 decl_handle, UINT16 value_handle,
|
|
|
|
tBT_UUID uuid, UINT8 property)
|
2016-09-26 13:37:39 +00:00
|
|
|
{
|
|
|
|
tBTA_GATTC_ATTR_REC *p_rec = NULL;
|
|
|
|
tBTA_GATT_STATUS status = BTA_GATT_OK;
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_srvc_cb->p_srvc_list == NULL) {
|
2016-09-26 13:37:39 +00:00
|
|
|
APPL_TRACE_ERROR("No service available, unexpected char discovery result");
|
|
|
|
status = BTA_GATT_INTERNAL_ERROR;
|
2016-11-24 18:10:15 +00:00
|
|
|
} else if (p_srvc_cb->next_avail_idx < BTA_GATTC_MAX_CACHE_CHAR) {
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
p_rec = p_srvc_cb->p_srvc_list + p_srvc_cb->next_avail_idx;
|
|
|
|
|
|
|
|
p_srvc_cb->total_char ++;
|
|
|
|
|
|
|
|
p_rec->s_handle = value_handle;
|
|
|
|
p_rec->property = property;
|
|
|
|
p_rec->e_handle = (p_srvc_cb->p_srvc_list + p_srvc_cb->cur_srvc_idx)->e_handle;
|
|
|
|
memcpy(&p_rec->uuid, &uuid, sizeof(tBT_UUID));
|
|
|
|
|
|
|
|
/* update the endind handle of pervious characteristic if available */
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_srvc_cb->total_char > 1) {
|
2016-09-26 13:37:39 +00:00
|
|
|
p_rec -= 1;
|
|
|
|
p_rec->e_handle = decl_handle - 1;
|
|
|
|
}
|
|
|
|
p_srvc_cb->next_avail_idx ++;
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
APPL_TRACE_ERROR("char not added, no resources");
|
|
|
|
/* allocate bigger buffer ?? */
|
|
|
|
status = BTA_GATT_DB_FULL;
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
|
|
|
|
}
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_gattc_sdp_callback
|
|
|
|
**
|
|
|
|
** Description Process the discovery result from sdp
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
2017-04-23 09:52:18 +00:00
|
|
|
#if (SDP_INCLUDED == TRUE)
|
2016-09-26 13:37:39 +00:00
|
|
|
void bta_gattc_sdp_callback (UINT16 sdp_status)
|
|
|
|
{
|
|
|
|
tSDP_DISC_REC *p_sdp_rec = NULL;
|
|
|
|
tBT_UUID service_uuid;
|
|
|
|
tSDP_PROTOCOL_ELEM pe;
|
|
|
|
UINT16 start_handle = 0, end_handle = 0;
|
|
|
|
tBTA_GATTC_SERV *p_srvc_cb = bta_gattc_find_scb_by_cid(bta_gattc_cb.sdp_conn_id);
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (((sdp_status == SDP_SUCCESS) || (sdp_status == SDP_DB_FULL)) && p_srvc_cb != NULL) {
|
|
|
|
do {
|
2016-09-26 13:37:39 +00:00
|
|
|
/* find a service record, report it */
|
|
|
|
p_sdp_rec = SDP_FindServiceInDb(bta_gattc_cb.p_sdp_db,
|
|
|
|
0, p_sdp_rec);
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_sdp_rec) {
|
|
|
|
if (SDP_FindServiceUUIDInRec(p_sdp_rec, &service_uuid)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (SDP_FindProtocolListElemInRec(p_sdp_rec, UUID_PROTOCOL_ATT, &pe)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
start_handle = (UINT16) pe.params[0];
|
|
|
|
end_handle = (UINT16) pe.params[1];
|
|
|
|
|
|
|
|
#if (defined BTA_GATT_DEBUG && BTA_GATT_DEBUG == TRUE)
|
|
|
|
APPL_TRACE_EVENT("Found ATT service [0x%04x] handle[0x%04x ~ 0x%04x]",
|
2016-11-24 18:10:15 +00:00
|
|
|
service_uuid.uu.uuid16, start_handle, end_handle);
|
2016-09-26 13:37:39 +00:00
|
|
|
#endif
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (GATT_HANDLE_IS_VALID(start_handle) && GATT_HANDLE_IS_VALID(end_handle) &&
|
|
|
|
p_srvc_cb != NULL) {
|
2016-09-26 13:37:39 +00:00
|
|
|
/* discover services result, add services into a service list */
|
|
|
|
bta_gattc_add_srvc_to_list(p_srvc_cb,
|
|
|
|
start_handle,
|
|
|
|
end_handle,
|
|
|
|
service_uuid,
|
|
|
|
TRUE);
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
APPL_TRACE_ERROR("invalid start_handle = %d end_handle = %d",
|
2016-11-24 18:10:15 +00:00
|
|
|
start_handle, end_handle);
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (p_sdp_rec);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( p_srvc_cb != NULL)
|
|
|
|
/* start discover primary service */
|
|
|
|
{
|
2016-11-24 18:10:15 +00:00
|
|
|
bta_gattc_explore_srvc(bta_gattc_cb.sdp_conn_id, p_srvc_cb);
|
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
APPL_TRACE_ERROR("GATT service discovery is done on unknown connection");
|
|
|
|
}
|
|
|
|
|
2017-08-17 13:13:45 +00:00
|
|
|
osi_free(bta_gattc_cb.p_sdp_db);
|
2016-09-26 13:37:39 +00:00
|
|
|
bta_gattc_cb.p_sdp_db = NULL;
|
|
|
|
bta_gattc_cb.sdp_conn_id = 0;
|
|
|
|
}
|
2017-04-23 09:52:18 +00:00
|
|
|
#endif ///SDP_INCLUDED == TRUE
|
|
|
|
|
2016-09-26 13:37:39 +00:00
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_gattc_sdp_service_disc
|
|
|
|
**
|
|
|
|
** Description Start DSP Service Discovert
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
2017-04-23 09:52:18 +00:00
|
|
|
#if (SDP_INCLUDED == TRUE)
|
2016-09-26 13:37:39 +00:00
|
|
|
static tBTA_GATT_STATUS bta_gattc_sdp_service_disc(UINT16 conn_id, tBTA_GATTC_SERV *p_server_cb)
|
|
|
|
{
|
|
|
|
tSDP_UUID uuid;
|
|
|
|
UINT16 num_attrs = 2;
|
|
|
|
UINT16 attr_list[2];
|
|
|
|
tBTA_GATT_STATUS status = BTA_GATT_ERROR;
|
|
|
|
|
|
|
|
memset (&uuid, 0, sizeof(tSDP_UUID));
|
|
|
|
|
|
|
|
uuid.len = LEN_UUID_16;
|
|
|
|
uuid.uu.uuid16 = UUID_PROTOCOL_ATT;
|
|
|
|
|
2017-08-17 13:13:45 +00:00
|
|
|
if ((bta_gattc_cb.p_sdp_db = (tSDP_DISCOVERY_DB *)osi_malloc(BTA_GATT_SDP_DB_SIZE)) != NULL) {
|
2016-09-26 13:37:39 +00:00
|
|
|
attr_list[0] = ATTR_ID_SERVICE_CLASS_ID_LIST;
|
|
|
|
attr_list[1] = ATTR_ID_PROTOCOL_DESC_LIST;
|
|
|
|
|
|
|
|
SDP_InitDiscoveryDb (bta_gattc_cb.p_sdp_db, BTA_GATT_SDP_DB_SIZE, 1,
|
|
|
|
&uuid, num_attrs, attr_list);
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (!SDP_ServiceSearchAttributeRequest (p_server_cb->server_bda,
|
|
|
|
bta_gattc_cb.p_sdp_db, &bta_gattc_sdp_callback)) {
|
2017-08-17 13:13:45 +00:00
|
|
|
osi_free(bta_gattc_cb.p_sdp_db);
|
2016-09-26 13:37:39 +00:00
|
|
|
bta_gattc_cb.p_sdp_db = NULL;
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
bta_gattc_cb.sdp_conn_id = conn_id;
|
|
|
|
status = BTA_GATT_OK;
|
|
|
|
}
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
|
|
|
return status;
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
2017-04-23 09:52:18 +00:00
|
|
|
#endif ///SDP_INCLUDED == TRUE
|
|
|
|
|
2016-09-26 13:37:39 +00:00
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_gattc_disc_res_cback
|
|
|
|
** bta_gattc_disc_cmpl_cback
|
|
|
|
**
|
|
|
|
** Description callback functions to GATT client stack.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void bta_gattc_disc_res_cback (UINT16 conn_id, tGATT_DISC_TYPE disc_type, tGATT_DISC_RES *p_data)
|
|
|
|
{
|
2016-11-24 18:10:15 +00:00
|
|
|
tBTA_GATTC_SERV *p_srvc_cb = NULL;
|
2016-09-26 13:37:39 +00:00
|
|
|
BOOLEAN pri_srvc;
|
|
|
|
tBTA_GATTC_CLCB *p_clcb = bta_gattc_find_clcb_by_conn_id(conn_id);
|
|
|
|
|
|
|
|
p_srvc_cb = bta_gattc_find_scb_by_cid(conn_id);
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_srvc_cb != NULL && p_clcb != NULL && p_clcb->state == BTA_GATTC_DISCOVER_ST) {
|
|
|
|
switch (disc_type) {
|
|
|
|
case GATT_DISC_SRVC_ALL:
|
|
|
|
/* discover services result, add services into a service list */
|
|
|
|
bta_gattc_add_srvc_to_list(p_srvc_cb,
|
|
|
|
p_data->handle,
|
|
|
|
p_data->value.group_value.e_handle,
|
|
|
|
p_data->value.group_value.service_type,
|
|
|
|
TRUE);
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
break;
|
|
|
|
case GATT_DISC_SRVC_BY_UUID:
|
|
|
|
bta_gattc_add_srvc_to_list(p_srvc_cb,
|
|
|
|
p_data->handle,
|
|
|
|
p_data->value.group_value.e_handle,
|
|
|
|
p_data->value.group_value.service_type,
|
|
|
|
TRUE);
|
|
|
|
break;
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
case GATT_DISC_INC_SRVC:
|
|
|
|
/* add included service into service list if it's secondary or it never showed up
|
|
|
|
in the primary service search */
|
|
|
|
pri_srvc = bta_gattc_srvc_in_list(p_srvc_cb,
|
|
|
|
p_data->value.incl_service.s_handle,
|
|
|
|
p_data->value.incl_service.e_handle,
|
|
|
|
p_data->value.incl_service.service_type);
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (!pri_srvc)
|
|
|
|
bta_gattc_add_srvc_to_list(p_srvc_cb,
|
|
|
|
p_data->value.incl_service.s_handle,
|
|
|
|
p_data->value.incl_service.e_handle,
|
|
|
|
p_data->value.incl_service.service_type,
|
|
|
|
FALSE);
|
|
|
|
/* add into database */
|
|
|
|
bta_gattc_add_attr_to_cache(p_srvc_cb,
|
|
|
|
p_data->handle,
|
|
|
|
&p_data->value.incl_service.service_type,
|
|
|
|
pri_srvc,
|
|
|
|
BTA_GATTC_ATTR_TYPE_INCL_SRVC);
|
|
|
|
break;
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
case GATT_DISC_CHAR:
|
|
|
|
/* add char value into database */
|
|
|
|
bta_gattc_add_char_to_list(p_srvc_cb,
|
|
|
|
p_data->handle,
|
|
|
|
p_data->value.dclr_value.val_handle,
|
|
|
|
p_data->value.dclr_value.char_uuid,
|
|
|
|
p_data->value.dclr_value.char_prop);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GATT_DISC_CHAR_DSCPT:
|
|
|
|
bta_gattc_add_attr_to_cache(p_srvc_cb, p_data->handle, &p_data->type, 0,
|
|
|
|
BTA_GATTC_ATTR_TYPE_CHAR_DESCR);
|
|
|
|
break;
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void bta_gattc_disc_cmpl_cback (UINT16 conn_id, tGATT_DISC_TYPE disc_type, tGATT_STATUS status)
|
|
|
|
{
|
2016-11-24 18:10:15 +00:00
|
|
|
tBTA_GATTC_SERV *p_srvc_cb;
|
2016-09-26 13:37:39 +00:00
|
|
|
tBTA_GATTC_CLCB *p_clcb = bta_gattc_find_clcb_by_conn_id(conn_id);
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if ( p_clcb && (status != GATT_SUCCESS || p_clcb->status != GATT_SUCCESS) ) {
|
|
|
|
if (p_clcb->status == GATT_SUCCESS) {
|
2016-09-26 13:37:39 +00:00
|
|
|
p_clcb->status = status;
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
bta_gattc_sm_execute(p_clcb, BTA_GATTC_DISCOVER_CMPL_EVT, NULL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
p_srvc_cb = bta_gattc_find_scb_by_cid(conn_id);
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_srvc_cb != NULL) {
|
|
|
|
switch (disc_type) {
|
|
|
|
case GATT_DISC_SRVC_ALL:
|
|
|
|
case GATT_DISC_SRVC_BY_UUID:
|
2016-09-26 13:37:39 +00:00
|
|
|
#if (defined BTA_GATT_DEBUG && BTA_GATT_DEBUG == TRUE)
|
2016-11-24 18:10:15 +00:00
|
|
|
bta_gattc_display_explore_record(p_srvc_cb->p_srvc_list, p_srvc_cb->next_avail_idx);
|
2016-09-26 13:37:39 +00:00
|
|
|
#endif
|
2016-11-24 18:10:15 +00:00
|
|
|
bta_gattc_explore_srvc(conn_id, p_srvc_cb);
|
|
|
|
break;
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
case GATT_DISC_INC_SRVC:
|
|
|
|
bta_gattc_incl_srvc_disc_cmpl(conn_id, p_srvc_cb);
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
break;
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
case GATT_DISC_CHAR:
|
2016-09-26 13:37:39 +00:00
|
|
|
#if (defined BTA_GATT_DEBUG && BTA_GATT_DEBUG == TRUE)
|
2016-11-24 18:10:15 +00:00
|
|
|
bta_gattc_display_explore_record(p_srvc_cb->p_srvc_list, p_srvc_cb->next_avail_idx);
|
2016-09-26 13:37:39 +00:00
|
|
|
#endif
|
2016-11-24 18:10:15 +00:00
|
|
|
bta_gattc_char_disc_cmpl(conn_id, p_srvc_cb);
|
|
|
|
break;
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
case GATT_DISC_CHAR_DSCPT:
|
|
|
|
bta_gattc_char_dscpt_disc_cmpl(conn_id, p_srvc_cb);
|
|
|
|
break;
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_gattc_id2handle
|
|
|
|
**
|
|
|
|
** Description map GATT ID to handle in a given cache.
|
|
|
|
**
|
|
|
|
** Returns the handle mapped. 0 if not found.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
UINT16 bta_gattc_id2handle(tBTA_GATTC_SERV *p_srcb, tBTA_GATT_SRVC_ID *p_service_id,
|
|
|
|
tBTA_GATT_ID *p_char_id, tBTA_GATT_ID *p_descr_uuid)
|
|
|
|
{
|
|
|
|
tBTA_GATTC_CACHE *p_cache = p_srcb->p_srvc_cache;
|
|
|
|
tBTA_GATTC_CACHE_ATTR *p_attr;
|
|
|
|
UINT8 j;
|
|
|
|
UINT16 handle = 0;
|
|
|
|
tBT_UUID attr_uuid;
|
|
|
|
BOOLEAN char_map = FALSE, done = FALSE;
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
while (p_service_id && p_cache && !done) {
|
2016-09-26 13:37:39 +00:00
|
|
|
#if (defined BTA_GATT_DEBUG && BTA_GATT_DEBUG == TRUE)
|
|
|
|
APPL_TRACE_DEBUG("Service: handle[%d] uuid[0x%04x] inst[%d]",
|
2016-11-24 18:10:15 +00:00
|
|
|
p_cache->s_handle, p_cache->service_uuid.id.uuid.uu.uuid16,
|
|
|
|
p_cache->service_uuid.id.inst_id);
|
2016-09-26 13:37:39 +00:00
|
|
|
#endif
|
|
|
|
p_attr = p_cache->p_attr;
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (bta_gattc_srvcid_compare(p_service_id, &p_cache->service_uuid)) {
|
|
|
|
for (j = 0; p_attr; j ++) {
|
2016-09-26 13:37:39 +00:00
|
|
|
#if (defined BTA_GATT_DEBUG && BTA_GATT_DEBUG == TRUE)
|
|
|
|
APPL_TRACE_DEBUG("\t Attr[0x%04x] handle[0x%04x] uuid[0x%04x] inst[%d] type[%d]",
|
2016-11-24 18:10:15 +00:00
|
|
|
j + 1, p_attr->attr_handle, p_attr->p_uuid->uuid16,
|
|
|
|
p_attr->inst_id, p_attr->attr_type);
|
2016-09-26 13:37:39 +00:00
|
|
|
#endif
|
|
|
|
bta_gattc_pack_attr_uuid(p_attr, &attr_uuid);
|
|
|
|
|
|
|
|
if (bta_gattc_uuid_compare(&p_char_id->uuid, &attr_uuid, TRUE) &&
|
2016-11-24 18:10:15 +00:00
|
|
|
p_char_id->inst_id == p_attr->inst_id) {
|
|
|
|
if (p_descr_uuid == NULL) {
|
2016-09-26 13:37:39 +00:00
|
|
|
handle = p_attr->attr_handle;
|
|
|
|
done = TRUE;
|
|
|
|
break;
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
#if (defined BTA_GATT_DEBUG && BTA_GATT_DEBUG == TRUE)
|
|
|
|
APPL_TRACE_DEBUG("found matching characteristic for the descriptor");
|
|
|
|
#endif
|
|
|
|
char_map = TRUE;
|
|
|
|
}
|
2016-11-24 18:10:15 +00:00
|
|
|
} else if (char_map == TRUE) {
|
|
|
|
if (p_attr->attr_type == BTA_GATTC_ATTR_TYPE_CHAR_DESCR) {
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
if (p_descr_uuid != NULL &&
|
2016-11-24 18:10:15 +00:00
|
|
|
bta_gattc_uuid_compare(&p_descr_uuid->uuid, &attr_uuid, TRUE) &&
|
|
|
|
p_descr_uuid->inst_id == p_attr->inst_id) {
|
2016-09-26 13:37:39 +00:00
|
|
|
#if (defined BTA_GATT_DEBUG && BTA_GATT_DEBUG == TRUE)
|
|
|
|
APPL_TRACE_DEBUG("found descriptor!!");
|
|
|
|
#endif
|
|
|
|
handle = p_attr->attr_handle;
|
|
|
|
done = TRUE;
|
|
|
|
break;
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
#if (defined BTA_GATT_DEBUG && BTA_GATT_DEBUG == TRUE)
|
|
|
|
APPL_TRACE_DEBUG("descriptor UUID not matching");
|
|
|
|
#endif
|
|
|
|
}
|
2016-11-24 18:10:15 +00:00
|
|
|
} else { /* another char */
|
2016-09-26 13:37:39 +00:00
|
|
|
#if (defined BTA_GATT_DEBUG && BTA_GATT_DEBUG == TRUE)
|
2016-11-24 18:10:15 +00:00
|
|
|
APPL_TRACE_DEBUG("no matching descptr found!!start of next characteristic");
|
2016-09-26 13:37:39 +00:00
|
|
|
#endif
|
|
|
|
char_map = FALSE;
|
|
|
|
done = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
p_attr = p_attr->p_next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
p_cache = p_cache->p_next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** 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)
|
|
|
|
{
|
|
|
|
tBTA_GATTC_CACHE *p_cache = p_srcb->p_srvc_cache;
|
|
|
|
tBTA_GATTC_CACHE_ATTR *p_attr, *p_char = NULL;
|
|
|
|
UINT8 j;
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
while (p_cache) {
|
2016-09-26 13:37:39 +00:00
|
|
|
#if (defined BTA_GATT_DEBUG && BTA_GATT_DEBUG == TRUE)
|
|
|
|
APPL_TRACE_DEBUG("Service: handle[%d] uuid[0x%04x] inst[%d]",
|
2016-11-24 18:10:15 +00:00
|
|
|
p_cache->s_handle, p_cache->service_uuid.id.uuid.uu.uuid16,
|
|
|
|
p_cache->service_uuid.id.inst_id);
|
2016-09-26 13:37:39 +00:00
|
|
|
#endif
|
|
|
|
/* a service found */
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_cache->s_handle == handle) {
|
2016-09-26 13:37:39 +00:00
|
|
|
memcpy(p_service_id, &p_cache->service_uuid, sizeof(tBTA_GATT_SRVC_ID));
|
|
|
|
|
|
|
|
return TRUE;
|
2016-11-24 18:10:15 +00:00
|
|
|
} else { /* start looking for attributes within the service */
|
2016-09-26 13:37:39 +00:00
|
|
|
p_attr = p_cache->p_attr;
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
for (j = 0; p_attr; j ++) {
|
2016-09-26 13:37:39 +00:00
|
|
|
#if (defined BTA_GATT_DEBUG && BTA_GATT_DEBUG == TRUE)
|
|
|
|
APPL_TRACE_DEBUG("\t Attr[0x%04x] handle[0x%04x] uuid[0x%04x] inst[%d] type[%d]",
|
2016-11-24 18:10:15 +00:00
|
|
|
j + 1, p_attr->attr_handle, p_attr->p_uuid->uuid16,
|
|
|
|
p_attr->inst_id, p_attr->attr_type);
|
2016-09-26 13:37:39 +00:00
|
|
|
#endif
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_attr->attr_type == BTA_GATTC_ATTR_TYPE_CHAR) {
|
2016-09-26 13:37:39 +00:00
|
|
|
p_char = p_attr;
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (handle == p_attr->attr_handle) {
|
2016-09-26 13:37:39 +00:00
|
|
|
memcpy(p_service_id, &p_cache->service_uuid, sizeof(tBTA_GATT_SRVC_ID));
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_attr->attr_type == BTA_GATTC_ATTR_TYPE_CHAR_DESCR) {
|
2016-09-26 13:37:39 +00:00
|
|
|
bta_gattc_pack_attr_uuid(p_attr, &p_descr_type->uuid);
|
|
|
|
p_descr_type->inst_id = p_attr->inst_id;
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_char != NULL) {
|
2016-09-26 13:37:39 +00:00
|
|
|
bta_gattc_pack_attr_uuid(p_char, &p_char_id->uuid);
|
|
|
|
p_char_id->inst_id = p_char->inst_id;
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
APPL_TRACE_ERROR("descptr does not belong to any chracteristic");
|
|
|
|
}
|
2016-11-24 18:10:15 +00:00
|
|
|
} else
|
|
|
|
/* is a characterisitc value or included service */
|
2016-09-26 13:37:39 +00:00
|
|
|
{
|
|
|
|
bta_gattc_pack_attr_uuid(p_attr, &p_char_id->uuid);
|
2016-11-24 18:10:15 +00:00
|
|
|
p_char_id->inst_id = p_attr->inst_id;
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
p_attr = p_attr->p_next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
p_cache = p_cache->p_next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_gattc_search_service
|
|
|
|
**
|
|
|
|
** Description search local cache for matching service record.
|
|
|
|
**
|
|
|
|
** Returns FALSE if map can not be found.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void bta_gattc_search_service(tBTA_GATTC_CLCB *p_clcb, tBT_UUID *p_uuid)
|
|
|
|
{
|
|
|
|
tBTA_GATTC_SERV *p_srcb = p_clcb->p_srcb;
|
|
|
|
tBTA_GATTC_CACHE *p_cache = p_srcb->p_srvc_cache;
|
|
|
|
tBTA_GATTC cb_data;
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
while (p_cache) {
|
|
|
|
if (bta_gattc_uuid_compare(p_uuid, &p_cache->service_uuid.id.uuid, FALSE)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
#if (defined BTA_GATT_DEBUG && BTA_GATT_DEBUG == TRUE)
|
|
|
|
APPL_TRACE_DEBUG("found service [0x%04x], inst[%d] handle [%d]",
|
2016-11-24 18:10:15 +00:00
|
|
|
p_cache->service_uuid.id.uuid.uu.uuid16,
|
|
|
|
p_cache->service_uuid.id.inst_id,
|
|
|
|
p_cache->s_handle);
|
2016-09-26 13:37:39 +00:00
|
|
|
#endif
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_clcb->p_rcb->p_cback) {
|
2016-09-26 13:37:39 +00:00
|
|
|
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,
|
2016-11-24 18:10:15 +00:00
|
|
|
sizeof(tBTA_GATT_SRVC_ID));
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
(* p_clcb->p_rcb->p_cback)(BTA_GATTC_SEARCH_RES_EVT, &cb_data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
p_cache = p_cache->p_next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_gattc_find_record
|
|
|
|
**
|
|
|
|
** Description search local cache for matching attribute record.
|
|
|
|
**
|
|
|
|
** Parameter p_result: output parameter to store the characteristic/
|
|
|
|
** included service GATT ID.
|
|
|
|
**
|
|
|
|
** Returns GATT_ERROR is no recording found. BTA_GATT_OK if record found.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
static tBTA_GATT_STATUS bta_gattc_find_record(tBTA_GATTC_SERV *p_srcb,
|
2016-11-24 18:10:15 +00:00
|
|
|
tBTA_GATTC_ATTR_TYPE attr_type,
|
|
|
|
tBTA_GATT_SRVC_ID *p_service_id,
|
|
|
|
tBTA_GATT_ID *p_start_rec,
|
|
|
|
tBT_UUID *p_uuid_cond,
|
|
|
|
tBTA_GATT_ID *p_result,
|
|
|
|
void *p_param)
|
2016-09-26 13:37:39 +00:00
|
|
|
{
|
|
|
|
tBTA_GATTC_CACHE *p_cache = p_srcb->p_srvc_cache;
|
|
|
|
tBTA_GATT_STATUS status = BTA_GATT_ERROR;
|
|
|
|
UINT8 i, j;
|
|
|
|
tBTA_GATTC_CACHE_ATTR *p_attr;
|
|
|
|
BOOLEAN char_found = FALSE, descr_found = FALSE;
|
|
|
|
tBTA_GATT_ID *p_descr_id = (tBTA_GATT_ID *)p_param;;
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
for (i = 0; p_cache && status != BTA_GATT_OK; i ++) {
|
|
|
|
if (bta_gattc_srvcid_compare(p_service_id, &p_cache->service_uuid)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
#if (defined BTA_GATT_DEBUG && BTA_GATT_DEBUG == TRUE)
|
|
|
|
APPL_TRACE_DEBUG("found matching service [0x%04x], inst[%d]",
|
2016-11-24 18:10:15 +00:00
|
|
|
p_cache->service_uuid.id.uuid.uu.uuid16,
|
|
|
|
p_cache->service_uuid.id.inst_id);
|
2016-09-26 13:37:39 +00:00
|
|
|
#endif
|
|
|
|
p_attr = p_cache->p_attr;
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
for (j = 0; p_attr; j ++) {
|
2016-09-26 13:37:39 +00:00
|
|
|
#if (defined BTA_GATT_DEBUG && BTA_GATT_DEBUG == TRUE)
|
|
|
|
APPL_TRACE_DEBUG("\t Attr[%d] handle[0x%04x] uuid[0x%04x] inst[%d] type[%d]",
|
2016-11-24 18:10:15 +00:00
|
|
|
j + 1, p_attr->attr_handle,
|
|
|
|
p_attr->p_uuid->uuid16,
|
|
|
|
p_attr->inst_id,
|
|
|
|
p_attr->attr_type);
|
2016-09-26 13:37:39 +00:00
|
|
|
#endif
|
|
|
|
bta_gattc_pack_attr_uuid(p_attr, &p_result->uuid);
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_start_rec != NULL && char_found == FALSE) {
|
2016-09-26 13:37:39 +00:00
|
|
|
/* find the starting record first */
|
|
|
|
if (bta_gattc_uuid_compare(&p_start_rec->uuid, &p_result->uuid, FALSE) &&
|
2016-11-24 18:10:15 +00:00
|
|
|
p_start_rec->inst_id == p_attr->inst_id &&
|
|
|
|
(attr_type == p_attr->attr_type ||
|
|
|
|
/* find descriptor would look for characteristic first */
|
|
|
|
(attr_type == BTA_GATTC_ATTR_TYPE_CHAR_DESCR &&
|
|
|
|
p_attr->attr_type == BTA_GATTC_ATTR_TYPE_CHAR))) {
|
2016-09-26 13:37:39 +00:00
|
|
|
char_found = TRUE;
|
|
|
|
}
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
/* if looking for descriptor, here is the where the descrptor to be found */
|
2016-11-24 18:10:15 +00:00
|
|
|
if (attr_type == BTA_GATTC_ATTR_TYPE_CHAR_DESCR) {
|
2016-09-26 13:37:39 +00:00
|
|
|
/* next characeteristic already, return error */
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_attr->attr_type != BTA_GATTC_ATTR_TYPE_CHAR_DESCR) {
|
2016-09-26 13:37:39 +00:00
|
|
|
break;
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
/* find starting descriptor */
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_descr_id != NULL && !descr_found) {
|
2016-09-26 13:37:39 +00:00
|
|
|
if (bta_gattc_uuid_compare(&p_descr_id->uuid, &p_result->uuid, TRUE)
|
2016-11-24 18:10:15 +00:00
|
|
|
&& p_descr_id->inst_id == p_attr->inst_id) {
|
2016-09-26 13:37:39 +00:00
|
|
|
descr_found = TRUE;
|
|
|
|
}
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
/* with matching descriptor */
|
2016-11-24 18:10:15 +00:00
|
|
|
if (bta_gattc_uuid_compare(p_uuid_cond, &p_result->uuid, FALSE)) {
|
2016-09-26 13:37:39 +00:00
|
|
|
p_result->inst_id = p_attr->inst_id;
|
|
|
|
status = BTA_GATT_OK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
if (bta_gattc_uuid_compare(p_uuid_cond, &p_result->uuid, FALSE) &&
|
2016-11-24 18:10:15 +00:00
|
|
|
attr_type == p_attr->attr_type) {
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
#if (defined BTA_GATT_DEBUG && BTA_GATT_DEBUG == TRUE)
|
|
|
|
APPL_TRACE_DEBUG("found char handle mapping characteristic");
|
|
|
|
#endif
|
|
|
|
p_result->inst_id = p_attr->inst_id;
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_param != NULL) {
|
2016-09-26 13:37:39 +00:00
|
|
|
if (attr_type == BTA_GATTC_ATTR_TYPE_CHAR ||
|
2016-11-24 18:10:15 +00:00
|
|
|
attr_type == BTA_GATTC_ATTR_TYPE_INCL_SRVC) {
|
2016-09-26 13:37:39 +00:00
|
|
|
*(tBTA_GATT_CHAR_PROP *)p_param = p_attr->property;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
status = BTA_GATT_OK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
p_attr = p_attr->p_next;
|
|
|
|
}
|
|
|
|
#if (defined BTA_GATT_DEBUG && BTA_GATT_DEBUG == TRUE)
|
2016-11-24 18:10:15 +00:00
|
|
|
if (status) {
|
2016-09-26 13:37:39 +00:00
|
|
|
APPL_TRACE_ERROR("In the given service, can not find matching record");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
p_cache = p_cache->p_next;
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_gattc_query_cache
|
|
|
|
**
|
|
|
|
** Description search local cache for matching attribute record.
|
|
|
|
**
|
|
|
|
** Parameters conn_id: connection ID which identify the server.
|
|
|
|
** p_srvc_id: the service ID of which the characteristic is belonged to.
|
|
|
|
** *p_start_rec: start the search from the next record
|
|
|
|
** after the one identified by *p_start_rec.
|
|
|
|
** p_uuid_cond: UUID, if NULL find the first available
|
|
|
|
** characteristic/included service.
|
|
|
|
** p_output: output parameter which will store the GATT ID
|
|
|
|
** of the characteristic /included service found.
|
|
|
|
**
|
|
|
|
** Returns BTA_GATT_ERROR is no recording found. BTA_GATT_OK if record found.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
tBTA_GATT_STATUS bta_gattc_query_cache(UINT16 conn_id,
|
|
|
|
tBTA_GATTC_ATTR_TYPE query_type,
|
|
|
|
tBTA_GATT_SRVC_ID *p_srvc_id,
|
|
|
|
tBTA_GATT_ID *p_start_rec,
|
|
|
|
tBT_UUID *p_uuid_cond,
|
|
|
|
tBTA_GATT_ID *p_output,
|
|
|
|
void *p_param)
|
|
|
|
{
|
|
|
|
tBTA_GATTC_CLCB *p_clcb = bta_gattc_find_clcb_by_conn_id(conn_id);
|
|
|
|
tBTA_GATT_STATUS status = BTA_GATT_ILLEGAL_PARAMETER;
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_clcb != NULL ) {
|
|
|
|
if (p_clcb->state == BTA_GATTC_CONN_ST) {
|
2016-09-26 13:37:39 +00:00
|
|
|
if (p_clcb->p_srcb &&
|
2016-11-24 18:10:15 +00:00
|
|
|
!p_clcb->p_srcb->p_srvc_list && /* no active discovery */
|
|
|
|
p_clcb->p_srcb->p_srvc_cache) {
|
2016-09-26 13:37:39 +00:00
|
|
|
status = bta_gattc_find_record(p_clcb->p_srcb,
|
|
|
|
query_type,
|
|
|
|
p_srvc_id,
|
|
|
|
p_start_rec,
|
|
|
|
p_uuid_cond,
|
|
|
|
p_output,
|
|
|
|
p_param);
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
status = BTA_GATT_ERROR;
|
|
|
|
APPL_TRACE_ERROR("No server cache available");
|
|
|
|
}
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
APPL_TRACE_ERROR("server cache not available, CLCB state = %d", p_clcb->state);
|
|
|
|
|
|
|
|
status = (p_clcb->state == BTA_GATTC_DISCOVER_ST) ? BTA_GATT_BUSY : BTA_GATT_ERROR;
|
|
|
|
}
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
APPL_TRACE_ERROR("Unknown conn ID: %d", conn_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_gattc_rebuild_cache
|
|
|
|
**
|
|
|
|
** Description rebuild server cache from NV cache.
|
|
|
|
**
|
|
|
|
** Parameters
|
|
|
|
**
|
|
|
|
** Returns None.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void bta_gattc_rebuild_cache(tBTA_GATTC_SERV *p_srvc_cb, UINT16 num_attr,
|
|
|
|
tBTA_GATTC_NV_ATTR *p_attr, UINT16 attr_index)
|
|
|
|
{
|
|
|
|
/* first attribute loading, initialize buffer */
|
|
|
|
APPL_TRACE_ERROR("bta_gattc_rebuild_cache");
|
2016-11-24 18:10:15 +00:00
|
|
|
if (attr_index == 0) {
|
2017-08-17 13:13:45 +00:00
|
|
|
while (!fixed_queue_is_empty(p_srvc_cb->cache_buffer)) {
|
|
|
|
osi_free(fixed_queue_dequeue(p_srvc_cb->cache_buffer));
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (bta_gattc_alloc_cache_buf(p_srvc_cb) == NULL) {
|
2016-09-26 13:37:39 +00:00
|
|
|
APPL_TRACE_ERROR("allocate cache buffer failed, no resources");
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
p_srvc_cb->p_cur_srvc = p_srvc_cb->p_srvc_cache = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
while (num_attr > 0 && p_attr != NULL) {
|
|
|
|
switch (p_attr->attr_type) {
|
|
|
|
case BTA_GATTC_ATTR_TYPE_SRVC:
|
|
|
|
bta_gattc_add_srvc_to_cache(p_srvc_cb,
|
|
|
|
p_attr->s_handle,
|
|
|
|
p_attr->e_handle,
|
|
|
|
&p_attr->uuid,
|
|
|
|
p_attr->is_primary,
|
|
|
|
p_attr->id);
|
|
|
|
break;
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
case BTA_GATTC_ATTR_TYPE_CHAR:
|
|
|
|
case BTA_GATTC_ATTR_TYPE_CHAR_DESCR:
|
|
|
|
case BTA_GATTC_ATTR_TYPE_INCL_SRVC:
|
|
|
|
bta_gattc_add_attr_to_cache(p_srvc_cb,
|
|
|
|
p_attr->s_handle,
|
|
|
|
&p_attr->uuid,
|
|
|
|
p_attr->prop,
|
|
|
|
p_attr->attr_type);
|
|
|
|
break;
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
p_attr ++;
|
|
|
|
num_attr --;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_gattc_fill_nv_attr
|
|
|
|
**
|
|
|
|
** Description fill a NV attribute entry value
|
|
|
|
**
|
|
|
|
** Returns None.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void bta_gattc_fill_nv_attr(tBTA_GATTC_NV_ATTR *p_attr, UINT8 type, UINT16 s_handle,
|
|
|
|
UINT16 e_handle, UINT8 id, tBT_UUID uuid, UINT8 prop,
|
|
|
|
BOOLEAN is_primary)
|
|
|
|
{
|
|
|
|
p_attr->s_handle = s_handle;
|
|
|
|
p_attr->e_handle = e_handle;
|
|
|
|
p_attr->attr_type = type;
|
|
|
|
p_attr->is_primary = is_primary;
|
|
|
|
p_attr->id = id;
|
|
|
|
p_attr->prop = prop;
|
|
|
|
|
|
|
|
memcpy(&p_attr->uuid, &uuid, sizeof(tBT_UUID));
|
|
|
|
}
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_gattc_cache_save
|
|
|
|
**
|
|
|
|
** Description save the server cache into NV
|
|
|
|
**
|
|
|
|
** Returns None.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
BOOLEAN bta_gattc_cache_save(tBTA_GATTC_SERV *p_srvc_cb, UINT16 conn_id)
|
|
|
|
{
|
|
|
|
tBTA_GATTC_CACHE *p_cur_srvc = p_srvc_cb->p_srvc_cache;
|
|
|
|
UINT8 i = 0;
|
|
|
|
UINT16 offset = 0;
|
|
|
|
tBTA_GATTC_NV_ATTR nv_attr[BTA_GATTC_NV_LOAD_MAX];
|
|
|
|
tBTA_GATTC_CACHE_ATTR *p_attr;
|
|
|
|
tBT_UUID uuid;
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
while (p_cur_srvc && i < BTA_GATTC_NV_LOAD_MAX) {
|
|
|
|
if (offset ++ >= p_srvc_cb->attr_index) {
|
2016-09-26 13:37:39 +00:00
|
|
|
bta_gattc_fill_nv_attr(&nv_attr[i++],
|
|
|
|
BTA_GATTC_ATTR_TYPE_SRVC,
|
|
|
|
p_cur_srvc->s_handle,
|
|
|
|
p_cur_srvc->e_handle,
|
|
|
|
p_cur_srvc->service_uuid.id.inst_id,
|
|
|
|
p_cur_srvc->service_uuid.id.uuid,
|
|
|
|
0,
|
|
|
|
p_cur_srvc->service_uuid.is_primary);
|
|
|
|
}
|
|
|
|
|
|
|
|
p_attr = p_cur_srvc->p_attr;
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
for (; p_attr && i < BTA_GATTC_NV_LOAD_MAX ; offset ++, p_attr = p_attr->p_next) {
|
|
|
|
if (offset >= p_srvc_cb->attr_index) {
|
|
|
|
if ((uuid.len = p_attr->uuid_len) == LEN_UUID_16) {
|
2016-09-26 13:37:39 +00:00
|
|
|
uuid.uu.uuid16 = p_attr->p_uuid->uuid16;
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
memcpy(uuid.uu.uuid128, p_attr->p_uuid->uuid128, LEN_UUID_128);
|
|
|
|
}
|
|
|
|
|
|
|
|
bta_gattc_fill_nv_attr(&nv_attr[i++],
|
|
|
|
p_attr->attr_type,
|
|
|
|
p_attr->attr_handle,
|
|
|
|
0,
|
|
|
|
p_attr->inst_id,
|
|
|
|
uuid,
|
|
|
|
p_attr->property,
|
|
|
|
FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
p_cur_srvc = p_cur_srvc->p_next;
|
|
|
|
}
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (i > 0) {
|
2016-09-26 13:37:39 +00:00
|
|
|
bta_gattc_co_cache_save(p_srvc_cb->server_bda, BTA_GATTC_CI_CACHE_SAVE_EVT, i,
|
|
|
|
nv_attr, p_srvc_cb->attr_index, conn_id);
|
|
|
|
|
|
|
|
p_srvc_cb->attr_index += i;
|
|
|
|
|
|
|
|
return TRUE;
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2017-04-19 09:16:24 +00:00
|
|
|
#endif /* GATTC_INCLUDED */
|
2016-09-26 13:37:39 +00:00
|
|
|
|