2016-09-26 13:37:39 +00:00
|
|
|
/******************************************************************************
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010-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 is the implementation of the API for GATT module of BTA.
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
#include "bt_target.h"
|
2017-08-17 13:13:45 +00:00
|
|
|
#include "allocator.h"
|
2016-09-26 13:37:39 +00:00
|
|
|
|
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 "bta_sys.h"
|
|
|
|
#include "bta_gatt_api.h"
|
|
|
|
#include "bta_gattc_int.h"
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
** Constants
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
static const tBTA_SYS_REG bta_gattc_reg = {
|
2016-09-26 13:37:39 +00:00
|
|
|
bta_gattc_hdl_event,
|
|
|
|
BTA_GATTC_Disable
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTA_GATTC_Disable
|
|
|
|
**
|
|
|
|
** Description This function is called to disable GATTC module
|
|
|
|
**
|
|
|
|
** Parameters None.
|
|
|
|
**
|
|
|
|
** Returns None
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void BTA_GATTC_Disable(void)
|
|
|
|
{
|
|
|
|
BT_HDR *p_buf;
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (bta_sys_is_register(BTA_ID_GATTC) == FALSE) {
|
2016-10-26 12:19:48 +00:00
|
|
|
APPL_TRACE_WARNING("GATTC Module not enabled/already disabled\n");
|
2016-09-26 13:37:39 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-08-17 13:13:45 +00:00
|
|
|
if ((p_buf = (BT_HDR *) osi_malloc(sizeof(BT_HDR))) != NULL) {
|
2016-09-26 13:37:39 +00:00
|
|
|
p_buf->event = BTA_GATTC_API_DISABLE_EVT;
|
|
|
|
bta_sys_sendmsg(p_buf);
|
|
|
|
}
|
|
|
|
bta_sys_deregister(BTA_ID_GATTC);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTA_GATTC_AppRegister
|
|
|
|
**
|
|
|
|
** Description This function is called to register application callbacks
|
|
|
|
** with BTA GATTC module.
|
|
|
|
**
|
|
|
|
** Parameters p_app_uuid - applicaiton UUID
|
|
|
|
** p_client_cb - pointer to the application callback function.
|
|
|
|
**
|
|
|
|
** Returns None
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void BTA_GATTC_AppRegister(tBT_UUID *p_app_uuid, tBTA_GATTC_CBACK *p_client_cb)
|
|
|
|
{
|
|
|
|
tBTA_GATTC_API_REG *p_buf;
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (bta_sys_is_register(BTA_ID_GATTC) == FALSE) {
|
2016-09-26 13:37:39 +00:00
|
|
|
bta_sys_register(BTA_ID_GATTC, &bta_gattc_reg);
|
|
|
|
}
|
|
|
|
|
2017-08-17 13:13:45 +00:00
|
|
|
if ((p_buf = (tBTA_GATTC_API_REG *) osi_malloc(sizeof(tBTA_GATTC_API_REG))) != NULL) {
|
2016-09-26 13:37:39 +00:00
|
|
|
p_buf->hdr.event = BTA_GATTC_API_REG_EVT;
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_app_uuid != NULL) {
|
2016-09-26 13:37:39 +00:00
|
|
|
memcpy(&p_buf->app_uuid, p_app_uuid, sizeof(tBT_UUID));
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
p_buf->p_cback = p_client_cb;
|
|
|
|
|
|
|
|
bta_sys_sendmsg(p_buf);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTA_GATTC_AppDeregister
|
|
|
|
**
|
|
|
|
** Description This function is called to deregister an application
|
|
|
|
** from BTA GATTC module.
|
|
|
|
**
|
|
|
|
** Parameters client_if - client interface identifier.
|
|
|
|
**
|
|
|
|
** Returns None
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void BTA_GATTC_AppDeregister(tBTA_GATTC_IF client_if)
|
|
|
|
{
|
|
|
|
tBTA_GATTC_API_DEREG *p_buf;
|
|
|
|
|
2017-08-17 13:13:45 +00:00
|
|
|
if ((p_buf = (tBTA_GATTC_API_DEREG *) osi_malloc(sizeof(tBTA_GATTC_API_DEREG))) != NULL) {
|
2016-09-26 13:37:39 +00:00
|
|
|
p_buf->hdr.event = BTA_GATTC_API_DEREG_EVT;
|
|
|
|
p_buf->client_if = client_if;
|
|
|
|
bta_sys_sendmsg(p_buf);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTA_GATTC_Open
|
|
|
|
**
|
|
|
|
** Description Open a direct connection or add a background auto connection
|
|
|
|
** bd address
|
|
|
|
**
|
|
|
|
** Parameters client_if: server interface.
|
|
|
|
** remote_bda: remote device BD address.
|
|
|
|
** is_direct: direct connection or background auto connection
|
|
|
|
** transport: Transport to be used for GATT connection (BREDR/LE)
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void BTA_GATTC_Open(tBTA_GATTC_IF client_if, BD_ADDR remote_bda,
|
|
|
|
BOOLEAN is_direct, tBTA_GATT_TRANSPORT transport)
|
|
|
|
{
|
|
|
|
tBTA_GATTC_API_OPEN *p_buf;
|
|
|
|
|
2017-08-17 13:13:45 +00:00
|
|
|
if ((p_buf = (tBTA_GATTC_API_OPEN *) osi_malloc(sizeof(tBTA_GATTC_API_OPEN))) != NULL) {
|
2016-09-26 13:37:39 +00:00
|
|
|
p_buf->hdr.event = BTA_GATTC_API_OPEN_EVT;
|
|
|
|
|
|
|
|
p_buf->client_if = client_if;
|
|
|
|
p_buf->is_direct = is_direct;
|
|
|
|
p_buf->transport = transport;
|
|
|
|
memcpy(p_buf->remote_bda, remote_bda, BD_ADDR_LEN);
|
|
|
|
|
|
|
|
|
|
|
|
bta_sys_sendmsg(p_buf);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTA_GATTC_CancelOpen
|
|
|
|
**
|
|
|
|
** Description Cancel a direct open connection or remove a background auto connection
|
|
|
|
** bd address
|
|
|
|
**
|
|
|
|
** Parameters client_if: server interface.
|
|
|
|
** remote_bda: remote device BD address.
|
|
|
|
** is_direct: direct connection or background auto connection
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void BTA_GATTC_CancelOpen(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, BOOLEAN is_direct)
|
|
|
|
{
|
|
|
|
tBTA_GATTC_API_CANCEL_OPEN *p_buf;
|
|
|
|
|
2017-08-17 13:13:45 +00:00
|
|
|
if ((p_buf = (tBTA_GATTC_API_CANCEL_OPEN *) osi_malloc(sizeof(tBTA_GATTC_API_CANCEL_OPEN))) != NULL) {
|
2016-09-26 13:37:39 +00:00
|
|
|
p_buf->hdr.event = BTA_GATTC_API_CANCEL_OPEN_EVT;
|
|
|
|
|
|
|
|
p_buf->client_if = client_if;
|
|
|
|
p_buf->is_direct = is_direct;
|
|
|
|
memcpy(p_buf->remote_bda, remote_bda, BD_ADDR_LEN);
|
|
|
|
|
|
|
|
bta_sys_sendmsg(p_buf);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTA_GATTC_Close
|
|
|
|
**
|
|
|
|
** Description Close a connection to a GATT server.
|
|
|
|
**
|
2016-11-28 06:58:30 +00:00
|
|
|
** Parameters conn_id: connection ID to be closed.
|
2016-09-26 13:37:39 +00:00
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void BTA_GATTC_Close(UINT16 conn_id)
|
|
|
|
{
|
|
|
|
BT_HDR *p_buf;
|
|
|
|
|
2017-08-17 13:13:45 +00:00
|
|
|
if ((p_buf = (BT_HDR *) osi_malloc(sizeof(BT_HDR))) != NULL) {
|
2016-09-26 13:37:39 +00:00
|
|
|
p_buf->event = BTA_GATTC_API_CLOSE_EVT;
|
|
|
|
|
|
|
|
p_buf->layer_specific = conn_id;
|
|
|
|
|
|
|
|
bta_sys_sendmsg(p_buf);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTA_GATTC_ConfigureMTU
|
|
|
|
**
|
|
|
|
** Description Configure the MTU size in the GATT channel. This can be done
|
|
|
|
** only once per connection.
|
|
|
|
**
|
|
|
|
** Parameters conn_id: connection ID.
|
|
|
|
** mtu: desired MTU size to use.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
2017-08-24 11:54:41 +00:00
|
|
|
void BTA_GATTC_ConfigureMTU (UINT16 conn_id)
|
2016-09-26 13:37:39 +00:00
|
|
|
{
|
|
|
|
tBTA_GATTC_API_CFG_MTU *p_buf;
|
|
|
|
|
2017-08-17 13:13:45 +00:00
|
|
|
if ((p_buf = (tBTA_GATTC_API_CFG_MTU *) osi_malloc(sizeof(tBTA_GATTC_API_CFG_MTU))) != NULL) {
|
2016-09-26 13:37:39 +00:00
|
|
|
p_buf->hdr.event = BTA_GATTC_API_CFG_MTU_EVT;
|
|
|
|
p_buf->hdr.layer_specific = conn_id;
|
|
|
|
|
|
|
|
bta_sys_sendmsg(p_buf);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTA_GATTC_ServiceSearchRequest
|
|
|
|
**
|
|
|
|
** Description This function is called to request a GATT service discovery
|
|
|
|
** on a GATT server. This function report service search result
|
|
|
|
** by a callback event, and followed by a service search complete
|
|
|
|
** event.
|
|
|
|
**
|
|
|
|
** Parameters conn_id: connection ID.
|
|
|
|
** p_srvc_uuid: a UUID of the service application is interested in.
|
|
|
|
** If Null, discover for all services.
|
|
|
|
**
|
|
|
|
** Returns None
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void BTA_GATTC_ServiceSearchRequest (UINT16 conn_id, tBT_UUID *p_srvc_uuid)
|
|
|
|
{
|
|
|
|
tBTA_GATTC_API_SEARCH *p_buf;
|
|
|
|
UINT16 len = sizeof(tBTA_GATTC_API_SEARCH) + sizeof(tBT_UUID);
|
|
|
|
|
2017-08-17 13:13:45 +00:00
|
|
|
if ((p_buf = (tBTA_GATTC_API_SEARCH *) osi_malloc(len)) != NULL) {
|
2016-09-26 13:37:39 +00:00
|
|
|
memset(p_buf, 0, len);
|
|
|
|
|
|
|
|
p_buf->hdr.event = BTA_GATTC_API_SEARCH_EVT;
|
|
|
|
p_buf->hdr.layer_specific = conn_id;
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_srvc_uuid) {
|
2016-09-26 13:37:39 +00:00
|
|
|
p_buf->p_srvc_uuid = (tBT_UUID *)(p_buf + 1);
|
|
|
|
memcpy(p_buf->p_srvc_uuid, p_srvc_uuid, sizeof(tBT_UUID));
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
p_buf->p_srvc_uuid = NULL;
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
bta_sys_sendmsg(p_buf);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
2017-08-24 06:24:04 +00:00
|
|
|
** Function BTA_GATTC_GetServices
|
2016-09-26 13:37:39 +00:00
|
|
|
**
|
2017-08-24 06:24:04 +00:00
|
|
|
** Description This function is called to find the services on the given server.
|
2016-09-26 13:37:39 +00:00
|
|
|
**
|
|
|
|
** Parameters conn_id: connection ID which identify the server.
|
|
|
|
**
|
2017-08-24 06:24:04 +00:00
|
|
|
** Returns returns list_t of tBTA_GATTC_SERVICE or NULL.
|
2016-09-26 13:37:39 +00:00
|
|
|
**
|
|
|
|
*******************************************************************************/
|
2017-08-24 06:24:04 +00:00
|
|
|
const list_t* BTA_GATTC_GetServices(UINT16 conn_id)
|
2016-09-26 13:37:39 +00:00
|
|
|
{
|
2017-08-24 06:24:04 +00:00
|
|
|
return bta_gattc_get_services(conn_id);
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
2017-08-24 06:24:04 +00:00
|
|
|
|
2016-09-26 13:37:39 +00:00
|
|
|
/*******************************************************************************
|
|
|
|
**
|
2017-08-24 06:24:04 +00:00
|
|
|
** Function BTA_GATTC_GetCharacteristic
|
2016-09-26 13:37:39 +00:00
|
|
|
**
|
2017-08-24 06:24:04 +00:00
|
|
|
** Description This function is called to find the characteristic on the given server.
|
2016-09-26 13:37:39 +00:00
|
|
|
**
|
2017-08-24 06:24:04 +00:00
|
|
|
** Parameters conn_id - connection ID which identify the server.
|
|
|
|
** handle - characteristic handle
|
2016-09-26 13:37:39 +00:00
|
|
|
**
|
2017-08-24 06:24:04 +00:00
|
|
|
** Returns returns pointer to tBTA_GATTC_CHARACTERISTIC or NULL.
|
2016-09-26 13:37:39 +00:00
|
|
|
**
|
|
|
|
*******************************************************************************/
|
2017-08-24 06:24:04 +00:00
|
|
|
const tBTA_GATTC_CHARACTERISTIC* BTA_GATTC_GetCharacteristic(UINT16 conn_id, UINT16 handle)
|
2016-09-26 13:37:39 +00:00
|
|
|
{
|
2017-08-24 06:24:04 +00:00
|
|
|
return bta_gattc_get_characteristic(conn_id, handle);
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
2017-08-24 06:24:04 +00:00
|
|
|
** Function BTA_GATTC_GetDescriptor
|
2016-09-26 13:37:39 +00:00
|
|
|
**
|
2017-08-24 06:24:04 +00:00
|
|
|
** Description This function is called to find the characteristic on the given server.
|
2016-09-26 13:37:39 +00:00
|
|
|
**
|
2017-08-24 06:24:04 +00:00
|
|
|
** Parameters conn_id - connection ID which identify the server.
|
|
|
|
** handle - descriptor handle
|
2016-09-26 13:37:39 +00:00
|
|
|
**
|
2017-08-24 06:24:04 +00:00
|
|
|
** Returns returns pointer to tBTA_GATTC_DESCRIPTOR or NULL.
|
2016-09-26 13:37:39 +00:00
|
|
|
**
|
|
|
|
*******************************************************************************/
|
2017-08-24 06:24:04 +00:00
|
|
|
const tBTA_GATTC_DESCRIPTOR* BTA_GATTC_GetDescriptor(UINT16 conn_id, UINT16 handle)
|
2016-09-26 13:37:39 +00:00
|
|
|
{
|
2017-08-24 06:24:04 +00:00
|
|
|
return bta_gattc_get_descriptor(conn_id, handle);
|
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2017-08-24 06:24:04 +00:00
|
|
|
void BTA_GATTC_GetServiceWithUUID(UINT16 conn_id, tBT_UUID *svc_uuid,
|
|
|
|
btgatt_db_element_t **db, int *count)
|
|
|
|
{
|
|
|
|
bta_gattc_get_service_with_uuid(conn_id, svc_uuid, db, count);
|
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2017-08-24 06:24:04 +00:00
|
|
|
void BTA_GATTC_GetAllChar(UINT16 conn_id, UINT16 start_handle, UINT16 end_handle,
|
|
|
|
btgatt_db_element_t **db, int *count)
|
|
|
|
{
|
|
|
|
bta_gattc_get_db_with_opration(conn_id,
|
|
|
|
GATT_OP_GET_ALL_CHAR,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
start_handle,
|
|
|
|
end_handle,
|
|
|
|
db,
|
|
|
|
count);
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
2017-08-24 06:24:04 +00:00
|
|
|
|
|
|
|
void BTA_GATTC_GetAllDescriptor(UINT16 conn_id, UINT16 char_handle,
|
|
|
|
btgatt_db_element_t **db, int *count)
|
2016-09-26 13:37:39 +00:00
|
|
|
{
|
2017-08-24 06:24:04 +00:00
|
|
|
bta_gattc_get_db_with_opration(conn_id,
|
|
|
|
GATT_OP_GET_ALL_DESCRI,
|
|
|
|
char_handle,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
0xFFFF,
|
|
|
|
db,
|
|
|
|
count);
|
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2017-08-24 06:24:04 +00:00
|
|
|
void BTA_GATTC_GetCharByUUID(UINT16 conn_id, UINT16 start_handle, UINT16 end_handle, tBT_UUID char_uuid,
|
|
|
|
btgatt_db_element_t **db, int *count)
|
|
|
|
{
|
|
|
|
bta_gattc_get_db_with_opration(conn_id,
|
|
|
|
GATT_OP_GET_CHAR_BY_UUID,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
&char_uuid,
|
|
|
|
NULL,
|
|
|
|
start_handle,
|
|
|
|
end_handle,
|
|
|
|
db,
|
|
|
|
count);
|
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2017-08-24 06:24:04 +00:00
|
|
|
void BTA_GATTC_GetDescrByUUID(UINT16 conn_id, uint16_t start_handle, uint16_t end_handle,
|
|
|
|
tBT_UUID char_uuid, tBT_UUID descr_uuid,
|
|
|
|
btgatt_db_element_t **db, int *count)
|
|
|
|
{
|
|
|
|
bta_gattc_get_db_with_opration(conn_id,
|
|
|
|
GATT_OP_GET_DESCRI_BY_UUID,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
&char_uuid,
|
|
|
|
&descr_uuid,
|
|
|
|
start_handle,
|
|
|
|
end_handle,
|
|
|
|
db,
|
|
|
|
count);
|
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2017-08-24 06:24:04 +00:00
|
|
|
void BTA_GATTC_GetDescrByCharHandle(UINT16 conn_id, UINT16 char_handle, tBT_UUID descr_uuid,
|
|
|
|
btgatt_db_element_t **db, int *count)
|
|
|
|
{
|
|
|
|
bta_gattc_get_db_with_opration(conn_id,
|
|
|
|
GATT_OP_GET_DESCRI_BY_HANDLE,
|
|
|
|
char_handle,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
&descr_uuid,
|
|
|
|
0,
|
|
|
|
0xFFFF,
|
|
|
|
db,
|
|
|
|
count);
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
|
2017-08-24 06:24:04 +00:00
|
|
|
void BTA_GATTC_GetIncludeService(UINT16 conn_id, UINT16 start_handle, UINT16 end_handle,
|
|
|
|
tBT_UUID *incl_uuid, btgatt_db_element_t **db, int *count)
|
|
|
|
{
|
|
|
|
bta_gattc_get_db_with_opration(conn_id,
|
|
|
|
GATT_OP_GET_INCLUDE_SVC,
|
|
|
|
0,
|
|
|
|
incl_uuid,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
start_handle,
|
|
|
|
end_handle,
|
|
|
|
db,
|
|
|
|
count);
|
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2017-08-24 06:24:04 +00:00
|
|
|
void BTA_GATTC_GetDBSize(UINT16 conn_id, UINT16 start_handle, UINT16 end_handle, int *count)
|
2016-09-26 13:37:39 +00:00
|
|
|
{
|
2017-08-24 06:24:04 +00:00
|
|
|
bta_gattc_get_db_size_handle(conn_id, start_handle, end_handle, count);
|
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2017-08-24 06:24:04 +00:00
|
|
|
void BTA_GATTC_GetDBSizeByType(UINT16 conn_id, bt_gatt_db_attribute_type_t type,
|
|
|
|
UINT16 start_handle, UINT16 end_handle, UINT16 char_handle, int *count)
|
|
|
|
{
|
|
|
|
bta_gattc_get_db_size_with_type_handle(conn_id, type, start_handle, end_handle, char_handle, count);
|
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
2017-08-24 06:24:04 +00:00
|
|
|
** Function BTA_GATTC_GetGattDb
|
2016-09-26 13:37:39 +00:00
|
|
|
**
|
2017-08-24 06:24:04 +00:00
|
|
|
** Description This function is called to get the GATT database.
|
2016-09-26 13:37:39 +00:00
|
|
|
**
|
|
|
|
** Parameters conn_id: connection ID which identify the server.
|
2017-08-24 06:24:04 +00:00
|
|
|
** db: output parameter which will contain the GATT database copy.
|
|
|
|
** Caller is responsible for freeing it.
|
|
|
|
** count: number of elements in database.
|
2016-09-26 13:37:39 +00:00
|
|
|
**
|
|
|
|
*******************************************************************************/
|
2017-08-24 06:24:04 +00:00
|
|
|
void BTA_GATTC_GetGattDb(UINT16 conn_id, UINT16 start_handle, UINT16 end_handle,
|
|
|
|
btgatt_db_element_t **db, int *count)
|
2016-09-26 13:37:39 +00:00
|
|
|
{
|
2017-08-24 06:24:04 +00:00
|
|
|
bta_gattc_get_gatt_db(conn_id, start_handle, end_handle, db, count);
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTA_GATTC_ReadCharacteristic
|
|
|
|
**
|
2017-08-24 06:24:04 +00:00
|
|
|
** Description This function is called to read a characteristics value
|
2016-09-26 13:37:39 +00:00
|
|
|
**
|
2016-11-28 06:58:30 +00:00
|
|
|
** Parameters conn_id - connection ID.
|
2017-08-24 06:24:04 +00:00
|
|
|
** handle - characteritic handle to read.
|
2016-09-26 13:37:39 +00:00
|
|
|
**
|
|
|
|
** Returns None
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
2017-08-24 06:24:04 +00:00
|
|
|
void BTA_GATTC_ReadCharacteristic(UINT16 conn_id, UINT16 handle, tBTA_GATT_AUTH_REQ auth_req)
|
2016-09-26 13:37:39 +00:00
|
|
|
{
|
|
|
|
tBTA_GATTC_API_READ *p_buf;
|
|
|
|
|
2017-08-17 13:13:45 +00:00
|
|
|
if ((p_buf = (tBTA_GATTC_API_READ *) osi_malloc(sizeof(tBTA_GATTC_API_READ))) != NULL) {
|
2016-09-26 13:37:39 +00:00
|
|
|
memset(p_buf, 0, 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;
|
2017-08-24 06:24:04 +00:00
|
|
|
p_buf->handle = handle;
|
|
|
|
p_buf->cmpl_evt = BTA_GATTC_READ_CHAR_EVT;
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
bta_sys_sendmsg(p_buf);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTA_GATTC_ReadCharDescr
|
|
|
|
**
|
2017-08-24 06:24:04 +00:00
|
|
|
** Description This function is called to read a descriptor value.
|
2016-09-26 13:37:39 +00:00
|
|
|
**
|
|
|
|
** Parameters conn_id - connection ID.
|
2017-08-24 06:24:04 +00:00
|
|
|
** handle - descriptor handle to read.
|
2016-09-26 13:37:39 +00:00
|
|
|
**
|
|
|
|
** Returns None
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
2017-08-24 06:24:04 +00:00
|
|
|
void BTA_GATTC_ReadCharDescr (UINT16 conn_id, UINT16 handle, tBTA_GATT_AUTH_REQ auth_req)
|
2016-09-26 13:37:39 +00:00
|
|
|
{
|
|
|
|
tBTA_GATTC_API_READ *p_buf;
|
|
|
|
UINT16 len = (UINT16)(sizeof(tBTA_GATT_ID) + sizeof(tBTA_GATTC_API_READ));
|
|
|
|
|
2017-08-17 13:13:45 +00:00
|
|
|
if ((p_buf = (tBTA_GATTC_API_READ *) osi_malloc(len)) != NULL) {
|
2016-09-26 13:37:39 +00:00
|
|
|
memset(p_buf, 0, 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;
|
2017-08-24 06:24:04 +00:00
|
|
|
p_buf->handle = handle;
|
|
|
|
p_buf->cmpl_evt = BTA_GATTC_READ_DESCR_EVT;
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
bta_sys_sendmsg(p_buf);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTA_GATTC_ReadMultiple
|
|
|
|
**
|
|
|
|
** Description This function is called to read multiple characteristic or
|
|
|
|
** characteristic descriptors.
|
|
|
|
**
|
2016-11-28 06:58:30 +00:00
|
|
|
** Parameters conn_id - connection ID.
|
2016-09-26 13:37:39 +00:00
|
|
|
** p_read_multi - pointer to the read multiple parameter.
|
|
|
|
**
|
|
|
|
** Returns None
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void BTA_GATTC_ReadMultiple(UINT16 conn_id, tBTA_GATTC_MULTI *p_read_multi,
|
|
|
|
tBTA_GATT_AUTH_REQ auth_req)
|
|
|
|
{
|
|
|
|
tBTA_GATTC_API_READ_MULTI *p_buf;
|
2017-08-24 06:24:04 +00:00
|
|
|
//tBTA_GATTC_API_READ_MULTI *p_value;
|
|
|
|
UINT16 len = (UINT16)(sizeof(tBTA_GATTC_API_READ_MULTI));
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2017-08-17 13:13:45 +00:00
|
|
|
if ((p_buf = (tBTA_GATTC_API_READ_MULTI *) osi_malloc(len)) != NULL) {
|
2016-09-26 13:37:39 +00:00
|
|
|
memset(p_buf, 0, len);
|
|
|
|
|
|
|
|
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;
|
2017-09-19 08:50:26 +00:00
|
|
|
p_buf->cmpl_evt = BTA_GATTC_READ_MUTIPLE_EVT;
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_buf->num_attr > 0) {
|
2017-08-24 06:24:04 +00:00
|
|
|
memcpy(p_buf->handles, p_read_multi->handles, sizeof(UINT16) * p_read_multi->num_attr);
|
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
bta_sys_sendmsg(p_buf);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTA_GATTC_WriteCharValue
|
|
|
|
**
|
|
|
|
** Description This function is called to write characteristic value.
|
|
|
|
**
|
|
|
|
** Parameters conn_id - connection ID.
|
2017-08-24 06:24:04 +00:00
|
|
|
** handle - characteristic handle to write.
|
|
|
|
** write_type - type of write.
|
2016-09-26 13:37:39 +00:00
|
|
|
** len: length of the data to be written.
|
|
|
|
** p_value - the value to be written.
|
|
|
|
**
|
|
|
|
** Returns None
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void BTA_GATTC_WriteCharValue ( UINT16 conn_id,
|
2017-08-24 06:24:04 +00:00
|
|
|
UINT16 handle,
|
2016-09-26 13:37:39 +00:00
|
|
|
tBTA_GATTC_WRITE_TYPE write_type,
|
|
|
|
UINT16 len,
|
|
|
|
UINT8 *p_value,
|
|
|
|
tBTA_GATT_AUTH_REQ auth_req)
|
|
|
|
{
|
|
|
|
tBTA_GATTC_API_WRITE *p_buf;
|
|
|
|
|
2017-08-17 13:13:45 +00:00
|
|
|
if ((p_buf = (tBTA_GATTC_API_WRITE *) osi_malloc((UINT16)(sizeof(tBTA_GATTC_API_WRITE) + len))) != NULL) {
|
2016-09-26 13:37:39 +00:00
|
|
|
memset(p_buf, 0, sizeof(tBTA_GATTC_API_WRITE) + len);
|
|
|
|
|
|
|
|
p_buf->hdr.event = BTA_GATTC_API_WRITE_EVT;
|
|
|
|
p_buf->hdr.layer_specific = conn_id;
|
|
|
|
p_buf->auth_req = auth_req;
|
2017-08-24 06:24:04 +00:00
|
|
|
p_buf->handle = handle;
|
|
|
|
p_buf->cmpl_evt = BTA_GATTC_WRITE_CHAR_EVT;
|
2016-09-26 13:37:39 +00:00
|
|
|
p_buf->write_type = write_type;
|
|
|
|
p_buf->len = len;
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_value && len > 0) {
|
2016-09-26 13:37:39 +00:00
|
|
|
p_buf->p_value = (UINT8 *)(p_buf + 1);
|
|
|
|
memcpy(p_buf->p_value, p_value, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
bta_sys_sendmsg(p_buf);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTA_GATTC_WriteCharDescr
|
|
|
|
**
|
2017-08-24 06:24:04 +00:00
|
|
|
** Description This function is called to write descriptor value.
|
2016-09-26 13:37:39 +00:00
|
|
|
**
|
|
|
|
** Parameters conn_id - connection ID
|
2017-08-24 06:24:04 +00:00
|
|
|
** handle - descriptor hadle to write.
|
2016-09-26 13:37:39 +00:00
|
|
|
** write_type - write type.
|
|
|
|
** p_value - the value to be written.
|
|
|
|
**
|
|
|
|
** Returns None
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void BTA_GATTC_WriteCharDescr (UINT16 conn_id,
|
2017-08-24 06:24:04 +00:00
|
|
|
UINT16 handle,
|
2016-09-26 13:37:39 +00:00
|
|
|
tBTA_GATTC_WRITE_TYPE write_type,
|
|
|
|
tBTA_GATT_UNFMT *p_data,
|
|
|
|
tBTA_GATT_AUTH_REQ auth_req)
|
|
|
|
{
|
2017-08-24 06:24:04 +00:00
|
|
|
size_t len = sizeof(tBTA_GATTC_API_WRITE);
|
|
|
|
tBTA_GATTC_API_WRITE *p_buf;
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_data != NULL) {
|
2016-09-26 13:37:39 +00:00
|
|
|
len += p_data->len;
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2017-08-17 13:13:45 +00:00
|
|
|
if ((p_buf = (tBTA_GATTC_API_WRITE *) osi_malloc(len)) != NULL) {
|
2016-09-26 13:37:39 +00:00
|
|
|
memset(p_buf, 0, len);
|
|
|
|
|
|
|
|
p_buf->hdr.event = BTA_GATTC_API_WRITE_EVT;
|
|
|
|
p_buf->hdr.layer_specific = conn_id;
|
|
|
|
p_buf->auth_req = auth_req;
|
2017-08-24 06:24:04 +00:00
|
|
|
p_buf->handle = handle;
|
|
|
|
p_buf->cmpl_evt = BTA_GATTC_WRITE_DESCR_EVT;
|
2016-09-26 13:37:39 +00:00
|
|
|
p_buf->write_type = write_type;
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_data && p_data->len != 0) {
|
2017-08-24 06:24:04 +00:00
|
|
|
p_buf->p_value = (UINT8 *)(p_buf + 1);
|
2016-09-26 13:37:39 +00:00
|
|
|
p_buf->len = p_data->len;
|
|
|
|
/* pack the descr data */
|
|
|
|
memcpy(p_buf->p_value, p_data->p_value, p_data->len);
|
|
|
|
}
|
|
|
|
|
|
|
|
bta_sys_sendmsg(p_buf);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTA_GATTC_PrepareWrite
|
|
|
|
**
|
|
|
|
** 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.
|
|
|
|
** offset - offset of the write value.
|
|
|
|
** len: length of the data to be written.
|
|
|
|
** p_value - the value to be written.
|
|
|
|
**
|
|
|
|
** Returns None
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
2017-08-24 06:24:04 +00:00
|
|
|
void BTA_GATTC_PrepareWrite (UINT16 conn_id, UINT16 handle,
|
2016-09-26 13:37:39 +00:00
|
|
|
UINT16 offset, UINT16 len, UINT8 *p_value,
|
|
|
|
tBTA_GATT_AUTH_REQ auth_req)
|
|
|
|
{
|
|
|
|
tBTA_GATTC_API_WRITE *p_buf;
|
|
|
|
|
2017-08-17 13:13:45 +00:00
|
|
|
if ((p_buf = (tBTA_GATTC_API_WRITE *) osi_malloc((UINT16)(sizeof(tBTA_GATTC_API_WRITE) + len))) != NULL) {
|
2016-09-26 13:37:39 +00:00
|
|
|
memset(p_buf, 0, sizeof(tBTA_GATTC_API_WRITE) + len);
|
|
|
|
|
|
|
|
p_buf->hdr.event = BTA_GATTC_API_WRITE_EVT;
|
|
|
|
p_buf->hdr.layer_specific = conn_id;
|
|
|
|
p_buf->auth_req = auth_req;
|
2017-08-24 06:24:04 +00:00
|
|
|
p_buf->handle = handle;
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
p_buf->write_type = BTA_GATTC_WRITE_PREPARE;
|
|
|
|
p_buf->offset = offset;
|
|
|
|
p_buf->len = len;
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if (p_value && len > 0) {
|
2016-09-26 13:37:39 +00:00
|
|
|
p_buf->p_value = (UINT8 *)(p_buf + 1);
|
|
|
|
memcpy(p_buf->p_value, p_value, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
bta_sys_sendmsg(p_buf);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
2017-04-28 06:51:23 +00:00
|
|
|
}
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTA_GATTC_PrepareWriteCharDescr
|
|
|
|
**
|
|
|
|
** Description This function is called to prepare write a characteristic descriptor value.
|
|
|
|
**
|
|
|
|
** Parameters conn_id - connection ID.
|
|
|
|
** p_char_descr_id - GATT characteritic descriptor ID of the service.
|
|
|
|
** offset - offset of the write value.
|
|
|
|
** len: length of the data to be written.
|
|
|
|
** p_value - the value to be written.
|
|
|
|
**
|
|
|
|
** Returns None
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
2017-08-24 06:24:04 +00:00
|
|
|
void BTA_GATTC_PrepareWriteCharDescr (UINT16 conn_id, UINT16 handle,
|
2017-04-28 06:51:23 +00:00
|
|
|
UINT16 offset,tBTA_GATT_UNFMT *p_data,
|
|
|
|
tBTA_GATT_AUTH_REQ auth_req)
|
|
|
|
{
|
|
|
|
tBTA_GATTC_API_WRITE *p_buf;
|
2017-08-24 06:24:04 +00:00
|
|
|
UINT16 len = sizeof(tBTA_GATTC_API_WRITE) + p_data->len;
|
2017-04-28 06:51:23 +00:00
|
|
|
|
|
|
|
if (p_data != NULL) {
|
|
|
|
len += p_data->len;
|
|
|
|
}
|
|
|
|
|
2017-08-17 13:13:45 +00:00
|
|
|
if ((p_buf = (tBTA_GATTC_API_WRITE *) osi_malloc(len)) != NULL) {
|
2017-04-28 06:51:23 +00:00
|
|
|
memset(p_buf, 0, len);
|
|
|
|
|
|
|
|
p_buf->hdr.event = BTA_GATTC_API_WRITE_EVT;
|
|
|
|
p_buf->hdr.layer_specific = conn_id;
|
|
|
|
p_buf->auth_req = auth_req;
|
2017-08-24 06:24:04 +00:00
|
|
|
p_buf->handle = handle;
|
2017-04-28 06:51:23 +00:00
|
|
|
p_buf->write_type = BTA_GATTC_WRITE_PREPARE;
|
|
|
|
p_buf->offset = offset;
|
|
|
|
|
|
|
|
if (p_data && p_data->len != 0) {
|
|
|
|
p_buf->len = p_data->len;
|
2017-08-24 06:24:04 +00:00
|
|
|
p_buf->p_value = (UINT8 *)(p_buf + 1);
|
2017-04-28 06:51:23 +00:00
|
|
|
/* pack the descr data */
|
|
|
|
memcpy(p_buf->p_value, p_data->p_value, p_data->len);
|
|
|
|
}
|
|
|
|
|
|
|
|
bta_sys_sendmsg(p_buf);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTA_GATTC_ExecuteWrite
|
|
|
|
**
|
|
|
|
** Description This function is called to execute write a prepare write sequence.
|
|
|
|
**
|
|
|
|
** Parameters conn_id - connection ID.
|
|
|
|
** is_execute - execute or cancel.
|
|
|
|
**
|
|
|
|
** Returns None
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void BTA_GATTC_ExecuteWrite (UINT16 conn_id, BOOLEAN is_execute)
|
|
|
|
{
|
|
|
|
tBTA_GATTC_API_EXEC *p_buf;
|
|
|
|
|
2017-08-17 13:13:45 +00:00
|
|
|
if ((p_buf = (tBTA_GATTC_API_EXEC *) osi_malloc((UINT16)sizeof(tBTA_GATTC_API_EXEC))) != NULL) {
|
2016-09-26 13:37:39 +00:00
|
|
|
memset(p_buf, 0, sizeof(tBTA_GATTC_API_EXEC));
|
|
|
|
p_buf->hdr.event = BTA_GATTC_API_EXEC_EVT;
|
|
|
|
p_buf->hdr.layer_specific = conn_id;
|
|
|
|
|
|
|
|
p_buf->is_execute = is_execute;
|
|
|
|
|
|
|
|
bta_sys_sendmsg(p_buf);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTA_GATTC_SendIndConfirm
|
|
|
|
**
|
|
|
|
** Description This function is called to send handle value confirmation.
|
|
|
|
**
|
|
|
|
** Parameters conn_id - connection ID.
|
|
|
|
** p_char_id - characteristic ID to confirm.
|
|
|
|
**
|
|
|
|
** Returns None
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
2017-08-24 06:24:04 +00:00
|
|
|
void BTA_GATTC_SendIndConfirm (UINT16 conn_id, UINT16 handle)
|
2016-09-26 13:37:39 +00:00
|
|
|
{
|
|
|
|
tBTA_GATTC_API_CONFIRM *p_buf;
|
|
|
|
|
2017-08-24 06:24:04 +00:00
|
|
|
APPL_TRACE_API("BTA_GATTC_SendIndConfirm conn_id=%d handle =0x%x",
|
|
|
|
conn_id, handle);
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2017-08-17 13:13:45 +00:00
|
|
|
if ((p_buf = (tBTA_GATTC_API_CONFIRM *) osi_malloc(sizeof(tBTA_GATTC_API_CONFIRM))) != NULL) {
|
2016-09-26 13:37:39 +00:00
|
|
|
memset(p_buf, 0, sizeof(tBTA_GATTC_API_CONFIRM));
|
|
|
|
p_buf->hdr.event = BTA_GATTC_API_CONFIRM_EVT;
|
|
|
|
p_buf->hdr.layer_specific = conn_id;
|
2017-08-24 06:24:04 +00:00
|
|
|
p_buf->handle = handle;
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
bta_sys_sendmsg(p_buf);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTA_GATTC_RegisterForNotifications
|
|
|
|
**
|
|
|
|
** Description This function is called to register for notification of a service.
|
|
|
|
**
|
|
|
|
** Parameters client_if - client interface.
|
|
|
|
** bda - target GATT server.
|
2017-08-24 06:24:04 +00:00
|
|
|
** handle - GATT characteristic handle.
|
2016-09-26 13:37:39 +00:00
|
|
|
**
|
|
|
|
** Returns OK if registration succeed, otherwise failed.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
tBTA_GATT_STATUS BTA_GATTC_RegisterForNotifications (tBTA_GATTC_IF client_if,
|
2017-08-24 06:24:04 +00:00
|
|
|
BD_ADDR bda, UINT16 handle)
|
2016-09-26 13:37:39 +00:00
|
|
|
{
|
|
|
|
tBTA_GATTC_RCB *p_clreg;
|
|
|
|
tBTA_GATT_STATUS status = BTA_GATT_ILLEGAL_PARAMETER;
|
|
|
|
UINT8 i;
|
|
|
|
|
2017-08-24 06:24:04 +00:00
|
|
|
if (!handle)
|
|
|
|
{
|
|
|
|
APPL_TRACE_ERROR("deregistration failed, handle is 0");
|
2016-09-26 13:37:39 +00:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2016-11-24 18:10:15 +00:00
|
|
|
if ((p_clreg = bta_gattc_cl_get_regcb(client_if)) != NULL) {
|
|
|
|
for (i = 0; i < BTA_GATTC_NOTIF_REG_MAX; i ++) {
|
2016-09-26 13:37:39 +00:00
|
|
|
if ( p_clreg->notif_reg[i].in_use &&
|
2016-11-24 18:10:15 +00:00
|
|
|
!memcmp(p_clreg->notif_reg[i].remote_bda, bda, BD_ADDR_LEN) &&
|
2017-08-24 06:24:04 +00:00
|
|
|
p_clreg->notif_reg[i].handle == handle) {
|
2018-03-16 10:25:03 +00:00
|
|
|
APPL_TRACE_DEBUG("notification already registered");
|
2016-09-26 13:37:39 +00:00
|
|
|
status = BTA_GATT_OK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-11-24 18:10:15 +00:00
|
|
|
if (status != BTA_GATT_OK) {
|
|
|
|
for (i = 0; i < BTA_GATTC_NOTIF_REG_MAX; i ++) {
|
|
|
|
if (!p_clreg->notif_reg[i].in_use) {
|
2016-09-26 13:37:39 +00:00
|
|
|
memset((void *)&p_clreg->notif_reg[i], 0, sizeof(tBTA_GATTC_NOTIF_REG));
|
|
|
|
|
|
|
|
p_clreg->notif_reg[i].in_use = TRUE;
|
|
|
|
memcpy(p_clreg->notif_reg[i].remote_bda, bda, BD_ADDR_LEN);
|
|
|
|
|
2017-08-24 06:24:04 +00:00
|
|
|
p_clreg->notif_reg[i].handle = handle;
|
2016-09-26 13:37:39 +00:00
|
|
|
status = BTA_GATT_OK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-11-24 18:10:15 +00:00
|
|
|
if (i == BTA_GATTC_NOTIF_REG_MAX) {
|
2016-09-26 13:37:39 +00:00
|
|
|
status = BTA_GATT_NO_RESOURCES;
|
|
|
|
APPL_TRACE_ERROR("Max Notification Reached, registration failed.");
|
|
|
|
}
|
|
|
|
}
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
APPL_TRACE_ERROR("Client_if: %d Not Registered", client_if);
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTA_GATTC_DeregisterForNotifications
|
|
|
|
**
|
|
|
|
** Description This function is called to de-register for notification of a service.
|
|
|
|
**
|
|
|
|
** Parameters client_if - client interface.
|
2017-08-24 06:24:04 +00:00
|
|
|
** remote_bda - target GATT server.
|
|
|
|
** handle - GATT characteristic handle.
|
2016-09-26 13:37:39 +00:00
|
|
|
**
|
|
|
|
** Returns OK if deregistration succeed, otherwise failed.
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
tBTA_GATT_STATUS BTA_GATTC_DeregisterForNotifications (tBTA_GATTC_IF client_if,
|
2017-08-24 06:24:04 +00:00
|
|
|
BD_ADDR bda, UINT16 handle)
|
2016-09-26 13:37:39 +00:00
|
|
|
{
|
2017-08-24 06:24:04 +00:00
|
|
|
if (!handle) {
|
|
|
|
APPL_TRACE_ERROR("%s: deregistration failed, handle is 0", __func__);
|
|
|
|
return BTA_GATT_ILLEGAL_PARAMETER;
|
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
2017-08-24 06:24:04 +00:00
|
|
|
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;
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
|
2017-08-24 06:24:04 +00:00
|
|
|
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;
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-24 06:24:04 +00:00
|
|
|
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;
|
2016-09-26 13:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTA_GATTC_Refresh
|
|
|
|
**
|
|
|
|
** Description Refresh the server cache of the remote device
|
|
|
|
**
|
|
|
|
** Parameters remote_bda: remote device BD address.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void BTA_GATTC_Refresh(BD_ADDR remote_bda)
|
|
|
|
{
|
|
|
|
tBTA_GATTC_API_OPEN *p_buf;
|
|
|
|
|
2017-08-17 13:13:45 +00:00
|
|
|
if ((p_buf = (tBTA_GATTC_API_OPEN *) osi_malloc(sizeof(tBTA_GATTC_API_OPEN))) != NULL) {
|
2016-09-26 13:37:39 +00:00
|
|
|
p_buf->hdr.event = BTA_GATTC_API_REFRESH_EVT;
|
|
|
|
memcpy(p_buf->remote_bda, remote_bda, BD_ADDR_LEN);
|
|
|
|
|
|
|
|
bta_sys_sendmsg(p_buf);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTA_GATTC_Listen
|
|
|
|
**
|
|
|
|
** Description Start advertisement to listen for connection request for a GATT
|
|
|
|
** client application.
|
|
|
|
**
|
|
|
|
** Parameters client_if: server interface.
|
|
|
|
** start: to start or stop listening for connection
|
|
|
|
** remote_bda: remote device BD address, if listen to all device
|
|
|
|
** use NULL.
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void BTA_GATTC_Listen(tBTA_GATTC_IF client_if, BOOLEAN start, BD_ADDR_PTR target_bda)
|
|
|
|
{
|
|
|
|
tBTA_GATTC_API_LISTEN *p_buf;
|
|
|
|
|
2017-08-17 13:13:45 +00:00
|
|
|
if ((p_buf = (tBTA_GATTC_API_LISTEN *) osi_malloc((UINT16)(sizeof(tBTA_GATTC_API_LISTEN) + BD_ADDR_LEN))) != NULL) {
|
2016-09-26 13:37:39 +00:00
|
|
|
p_buf->hdr.event = BTA_GATTC_API_LISTEN_EVT;
|
|
|
|
|
|
|
|
p_buf->client_if = client_if;
|
|
|
|
p_buf->start = start;
|
2016-11-24 18:10:15 +00:00
|
|
|
if (target_bda) {
|
|
|
|
p_buf->remote_bda = (UINT8 *)(p_buf + 1);
|
2016-09-26 13:37:39 +00:00
|
|
|
memcpy(p_buf->remote_bda, target_bda, BD_ADDR_LEN);
|
2016-11-24 18:10:15 +00:00
|
|
|
} else {
|
2016-09-26 13:37:39 +00:00
|
|
|
p_buf->remote_bda = NULL;
|
2016-11-24 18:10:15 +00:00
|
|
|
}
|
2016-09-26 13:37:39 +00:00
|
|
|
|
|
|
|
bta_sys_sendmsg(p_buf);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function BTA_GATTC_Broadcast
|
|
|
|
**
|
|
|
|
** Description Start broadcasting (non-connectable advertisements)
|
|
|
|
**
|
|
|
|
** Parameters client_if: client interface.
|
|
|
|
** start: to start or stop listening for connection
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
void BTA_GATTC_Broadcast(tBTA_GATTC_IF client_if, BOOLEAN start)
|
|
|
|
{
|
|
|
|
tBTA_GATTC_API_LISTEN *p_buf;
|
|
|
|
|
2017-08-17 13:13:45 +00:00
|
|
|
if ((p_buf = (tBTA_GATTC_API_LISTEN *) osi_malloc((UINT16)(sizeof(tBTA_GATTC_API_LISTEN) + BD_ADDR_LEN))) != NULL) {
|
2016-09-26 13:37:39 +00:00
|
|
|
p_buf->hdr.event = BTA_GATTC_API_BROADCAST_EVT;
|
|
|
|
p_buf->client_if = client_if;
|
|
|
|
p_buf->start = start;
|
|
|
|
bta_sys_sendmsg(p_buf);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-08-24 06:24:04 +00:00
|
|
|
#endif /* defined(GATTC_INCLUDED) && (GATTC_INCLUDED == TRUE) */
|
2016-09-26 13:37:39 +00:00
|
|
|
|