From 12339a801146d45f8aab010b38c099082bfc80e5 Mon Sep 17 00:00:00 2001 From: Jakub Pawlowski Date: Wed, 10 Feb 2016 15:26:14 -0800 Subject: [PATCH] Add handle range to BTA_GATTC_GetGattDb Change-Id: Iaf0280853278a4f28dde5b952b646096cfb12d97 --- bta/gatt/bta_gattc_api.c | 5 +++-- bta/gatt/bta_gattc_cache.c | 17 +++++++++++++++-- bta/gatt/bta_gattc_int.h | 2 +- bta/include/bta_gatt_api.h | 3 ++- btif/src/btif_gatt_client.c | 2 +- 5 files changed, 22 insertions(+), 7 deletions(-) diff --git a/bta/gatt/bta_gattc_api.c b/bta/gatt/bta_gattc_api.c index c6f8e4b6e..d9d5e9cc4 100644 --- a/bta/gatt/bta_gattc_api.c +++ b/bta/gatt/bta_gattc_api.c @@ -522,9 +522,10 @@ tBTA_GATT_STATUS BTA_GATTC_GetNextIncludedService(UINT16 conn_id, ** count: number of elements in database. ** *******************************************************************************/ -void BTA_GATTC_GetGattDb(UINT16 conn_id, btgatt_db_element_t **db, int *count) +void BTA_GATTC_GetGattDb(UINT16 conn_id, UINT16 start_handle, UINT16 end_handle, + btgatt_db_element_t **db, int *count) { - bta_gattc_get_gatt_db(conn_id, db, count); + bta_gattc_get_gatt_db(conn_id, start_handle, end_handle, db, count); } /******************************************************************************* diff --git a/bta/gatt/bta_gattc_cache.c b/bta/gatt/bta_gattc_cache.c index c451c2004..a27bf0c53 100644 --- a/bta/gatt/bta_gattc_cache.c +++ b/bta/gatt/bta_gattc_cache.c @@ -1427,6 +1427,7 @@ void bta_gattc_fill_gatt_db_el(btgatt_db_element_t *p_attr, ** *******************************************************************************/ static void bta_gattc_get_gatt_db_impl(tBTA_GATTC_SERV *p_srvc_cb, + UINT16 start_handle, UINT16 end_handle, btgatt_db_element_t **db, int *count) { @@ -1444,6 +1445,12 @@ static void bta_gattc_get_gatt_db_impl(tBTA_GATTC_SERV *p_srvc_cb, sn != list_end(p_srvc_cb->p_srvc_cache); sn = list_next(sn)) { tBTA_GATTC_CACHE *p_cur_srvc = list_node(sn); + if (p_cur_srvc->s_handle < start_handle) + continue; + + if (p_cur_srvc->e_handle > end_handle) + break; + db_size++; if (p_cur_srvc->p_attr) db_size += list_length(p_cur_srvc->p_attr); @@ -1456,6 +1463,12 @@ static void bta_gattc_get_gatt_db_impl(tBTA_GATTC_SERV *p_srvc_cb, sn != list_end(p_srvc_cb->p_srvc_cache); sn = list_next(sn)) { tBTA_GATTC_CACHE *p_cur_srvc = list_node(sn); + if (p_cur_srvc->s_handle < start_handle) + continue; + + if (p_cur_srvc->e_handle > end_handle) + break; + bta_gattc_fill_gatt_db_el(curr_db_attr, p_cur_srvc->service_uuid.is_primary ? BTGATT_DB_PRIMARY_SERVICE : @@ -1530,7 +1543,7 @@ static void bta_gattc_get_gatt_db_impl(tBTA_GATTC_SERV *p_srvc_cb, ** Returns None. ** *******************************************************************************/ -void bta_gattc_get_gatt_db(UINT16 conn_id, btgatt_db_element_t **db, int *count) +void bta_gattc_get_gatt_db(UINT16 conn_id, UINT16 start_handle, UINT16 end_handle, btgatt_db_element_t **db, int *count) { tBTA_GATTC_CLCB *p_clcb = bta_gattc_find_clcb_by_conn_id(conn_id); @@ -1551,7 +1564,7 @@ void bta_gattc_get_gatt_db(UINT16 conn_id, btgatt_db_element_t **db, int *count) APPL_TRACE_ERROR("No server cache available"); } - bta_gattc_get_gatt_db_impl(p_clcb->p_srcb, db, count); + bta_gattc_get_gatt_db_impl(p_clcb->p_srcb, start_handle, end_handle, db, count); } /******************************************************************************* diff --git a/bta/gatt/bta_gattc_int.h b/bta/gatt/bta_gattc_int.h index 6f69e6300..56c74d967 100644 --- a/bta/gatt/bta_gattc_int.h +++ b/bta/gatt/bta_gattc_int.h @@ -536,7 +536,7 @@ extern void bta_gattc_search_service(tBTA_GATTC_CLCB *p_clcb, tBT_UUID *p_uuid); extern tBTA_GATT_STATUS bta_gattc_query_cache(UINT16 conn_id, UINT8 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); -extern void bta_gattc_get_gatt_db(UINT16 conn_id, btgatt_db_element_t **db, int *count); +extern void bta_gattc_get_gatt_db(UINT16 conn_id, UINT16 start_handle, UINT16 end_handle, btgatt_db_element_t **db, int *count); extern tBTA_GATT_STATUS bta_gattc_init_cache(tBTA_GATTC_SERV *p_srvc_cb); extern void bta_gattc_rebuild_cache(tBTA_GATTC_SERV *p_srcv, UINT16 num_attr, tBTA_GATTC_NV_ATTR *p_attr, UINT16 attr_index); extern BOOLEAN bta_gattc_cache_save(tBTA_GATTC_SERV *p_srvc_cb, UINT16 conn_id); diff --git a/bta/include/bta_gatt_api.h b/bta/include/bta_gatt_api.h index 015c65d3e..9cd4f05e0 100644 --- a/bta/include/bta_gatt_api.h +++ b/bta/include/bta_gatt_api.h @@ -894,7 +894,8 @@ extern tBTA_GATT_STATUS BTA_GATTC_GetNextIncludedService(UINT16 conn_id, ** count: number of elements in db. ** *******************************************************************************/ -extern void BTA_GATTC_GetGattDb(UINT16 conn_id, btgatt_db_element_t **db, int *count); +extern void BTA_GATTC_GetGattDb(UINT16 conn_id, UINT16 start_handle, UINT16 end_handle, + btgatt_db_element_t **db, int *count); /******************************************************************************* ** diff --git a/btif/src/btif_gatt_client.c b/btif/src/btif_gatt_client.c index e248f9299..9936d0536 100644 --- a/btif/src/btif_gatt_client.c +++ b/btif/src/btif_gatt_client.c @@ -1366,7 +1366,7 @@ static void btgattc_handle_event(uint16_t event, char* p_param) { btgatt_db_element_t *db = NULL; int count = 0; - BTA_GATTC_GetGattDb(p_cb->conn_id, &db, &count); + BTA_GATTC_GetGattDb(p_cb->conn_id, 0x0000, 0xFFFF, &db, &count); HAL_CBACK(bt_gatt_callbacks, client->get_gatt_db_cb, p_cb->conn_id, db, count); -- 2.11.0