1 /******************************************************************************
3 * Copyright (C) 2003-2013 Broadcom Corporation
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 ******************************************************************************/
19 /******************************************************************************
21 * This is the public interface file for BTA GATT.
23 ******************************************************************************/
25 #ifndef BTA_GATT_API_H
26 #define BTA_GATT_API_H
30 #include "osi/include/list.h"
32 #ifndef BTA_GATT_INCLUDED
33 #warning BTA_GATT_INCLUDED not defined
34 #define BTA_GATT_INCLUDED FALSE
37 #if ((BLE_INCLUDED == FALSE) && (BTA_GATT_INCLUDED == TRUE))
38 #undef BTA_GATT_INCLUDED
39 #define BTA_GATT_INCLUDED FALSE
43 #ifndef BTA_GATT_DEBUG
44 #define BTA_GATT_DEBUG FALSE
47 /*****************************************************************************
48 ** Constants and data types
49 *****************************************************************************/
50 /**************************
52 ***************************/
56 tBT_UUID uuid; /* uuid of the attribute */
57 UINT8 inst_id; /* instance ID */
58 } __attribute__((packed)) tBTA_GATT_ID;
60 /* Success code and error codes */
61 #define BTA_GATT_OK GATT_SUCCESS
62 #define BTA_GATT_INVALID_HANDLE GATT_INVALID_HANDLE /* 0x0001 */
63 #define BTA_GATT_READ_NOT_PERMIT GATT_READ_NOT_PERMIT /* 0x0002 */
64 #define BTA_GATT_WRITE_NOT_PERMIT GATT_WRITE_NOT_PERMIT /* 0x0003 */
65 #define BTA_GATT_INVALID_PDU GATT_INVALID_PDU /* 0x0004 */
66 #define BTA_GATT_INSUF_AUTHENTICATION GATT_INSUF_AUTHENTICATION /* 0x0005 */
67 #define BTA_GATT_REQ_NOT_SUPPORTED GATT_REQ_NOT_SUPPORTED /* 0x0006 */
68 #define BTA_GATT_INVALID_OFFSET GATT_INVALID_OFFSET /* 0x0007 */
69 #define BTA_GATT_INSUF_AUTHORIZATION GATT_INSUF_AUTHORIZATION /* 0x0008 */
70 #define BTA_GATT_PREPARE_Q_FULL GATT_PREPARE_Q_FULL /* 0x0009 */
71 #define BTA_GATT_NOT_FOUND GATT_NOT_FOUND /* 0x000a */
72 #define BTA_GATT_NOT_LONG GATT_NOT_LONG /* 0x000b */
73 #define BTA_GATT_INSUF_KEY_SIZE GATT_INSUF_KEY_SIZE /* 0x000c */
74 #define BTA_GATT_INVALID_ATTR_LEN GATT_INVALID_ATTR_LEN /* 0x000d */
75 #define BTA_GATT_ERR_UNLIKELY GATT_ERR_UNLIKELY /* 0x000e */
76 #define BTA_GATT_INSUF_ENCRYPTION GATT_INSUF_ENCRYPTION /* 0x000f */
77 #define BTA_GATT_UNSUPPORT_GRP_TYPE GATT_UNSUPPORT_GRP_TYPE /* 0x0010 */
78 #define BTA_GATT_INSUF_RESOURCE GATT_INSUF_RESOURCE /* 0x0011 */
81 #define BTA_GATT_NO_RESOURCES GATT_NO_RESOURCES /* 0x80 */
82 #define BTA_GATT_INTERNAL_ERROR GATT_INTERNAL_ERROR /* 0x81 */
83 #define BTA_GATT_WRONG_STATE GATT_WRONG_STATE /* 0x82 */
84 #define BTA_GATT_DB_FULL GATT_DB_FULL /* 0x83 */
85 #define BTA_GATT_BUSY GATT_BUSY /* 0x84 */
86 #define BTA_GATT_ERROR GATT_ERROR /* 0x85 */
87 #define BTA_GATT_CMD_STARTED GATT_CMD_STARTED /* 0x86 */
88 #define BTA_GATT_ILLEGAL_PARAMETER GATT_ILLEGAL_PARAMETER /* 0x87 */
89 #define BTA_GATT_PENDING GATT_PENDING /* 0x88 */
90 #define BTA_GATT_AUTH_FAIL GATT_AUTH_FAIL /* 0x89 */
91 #define BTA_GATT_MORE GATT_MORE /* 0x8a */
92 #define BTA_GATT_INVALID_CFG GATT_INVALID_CFG /* 0x8b */
93 #define BTA_GATT_SERVICE_STARTED GATT_SERVICE_STARTED /* 0x8c */
94 #define BTA_GATT_ENCRYPED_MITM GATT_ENCRYPED_MITM /* GATT_SUCCESS */
95 #define BTA_GATT_ENCRYPED_NO_MITM GATT_ENCRYPED_NO_MITM /* 0x8d */
96 #define BTA_GATT_NOT_ENCRYPTED GATT_NOT_ENCRYPTED /* 0x8e */
97 #define BTA_GATT_CONGESTED GATT_CONGESTED /* 0x8f */
99 #define BTA_GATT_DUP_REG 0x90 /* 0x90 */
100 #define BTA_GATT_ALREADY_OPEN 0x91 /* 0x91 */
101 #define BTA_GATT_CANCEL 0x92 /* 0x92 */
103 /* 0xE0 ~ 0xFC reserved for future use */
104 #define BTA_GATT_CCC_CFG_ERR GATT_CCC_CFG_ERR /* 0xFD Client Characteristic Configuration Descriptor Improperly Configured */
105 #define BTA_GATT_PRC_IN_PROGRESS GATT_PRC_IN_PROGRESS /* 0xFE Procedure Already in progress */
106 #define BTA_GATT_OUT_OF_RANGE GATT_OUT_OF_RANGE /* 0xFFAttribute value out of range */
108 typedef UINT8 tBTA_GATT_STATUS;
110 #define BTA_GATT_INVALID_CONN_ID GATT_INVALID_CONN_ID
113 /* Client callback function events */
114 #define BTA_GATTC_REG_EVT 0 /* GATT client is registered. */
115 #define BTA_GATTC_DEREG_EVT 1 /* GATT client deregistered event */
116 #define BTA_GATTC_OPEN_EVT 2 /* GATTC open request status event */
117 #define BTA_GATTC_READ_CHAR_EVT 3 /* GATT read characteristic event */
118 #define BTA_GATTC_WRITE_CHAR_EVT 4 /* GATT write characteristic or char descriptor event */
119 #define BTA_GATTC_CLOSE_EVT 5 /* GATTC close request status event */
120 #define BTA_GATTC_SEARCH_CMPL_EVT 6 /* GATT discovery complete event */
121 #define BTA_GATTC_SEARCH_RES_EVT 7 /* GATT discovery result event */
122 #define BTA_GATTC_READ_DESCR_EVT 8 /* GATT read characterisitc descriptor event */
123 #define BTA_GATTC_WRITE_DESCR_EVT 9 /* GATT write characteristic descriptor event */
124 #define BTA_GATTC_NOTIF_EVT 10 /* GATT attribute notification event */
125 #define BTA_GATTC_PREP_WRITE_EVT 11 /* GATT prepare write event */
126 #define BTA_GATTC_EXEC_EVT 12 /* execute write complete event */
127 #define BTA_GATTC_ACL_EVT 13 /* ACL up event */
128 #define BTA_GATTC_CANCEL_OPEN_EVT 14 /* cancel open event */
129 #define BTA_GATTC_SRVC_CHG_EVT 15 /* service change event */
130 #define BTA_GATTC_LISTEN_EVT 16 /* listen event */
131 #define BTA_GATTC_ENC_CMPL_CB_EVT 17 /* encryption complete callback event */
132 #define BTA_GATTC_CFG_MTU_EVT 18 /* configure MTU complete event */
133 #define BTA_GATTC_ADV_DATA_EVT 19 /* ADV data event */
134 #define BTA_GATTC_MULT_ADV_ENB_EVT 20 /* Enable Multi ADV event */
135 #define BTA_GATTC_MULT_ADV_UPD_EVT 21 /* Update parameter event */
136 #define BTA_GATTC_MULT_ADV_DATA_EVT 22 /* Multi ADV data event */
137 #define BTA_GATTC_MULT_ADV_DIS_EVT 23 /* Disable Multi ADV event */
138 #define BTA_GATTC_CONGEST_EVT 24 /* Congestion event */
139 #define BTA_GATTC_BTH_SCAN_ENB_EVT 25 /* Enable batch scan event */
140 #define BTA_GATTC_BTH_SCAN_CFG_EVT 26 /* Config storage event */
141 #define BTA_GATTC_BTH_SCAN_RD_EVT 27 /* Batch scan reports read event */
142 #define BTA_GATTC_BTH_SCAN_THR_EVT 28 /* Batch scan threshold event */
143 #define BTA_GATTC_BTH_SCAN_PARAM_EVT 29 /* Batch scan param event */
144 #define BTA_GATTC_BTH_SCAN_DIS_EVT 30 /* Disable batch scan event */
145 #define BTA_GATTC_SCAN_FLT_CFG_EVT 31 /* Scan filter config event */
146 #define BTA_GATTC_SCAN_FLT_PARAM_EVT 32 /* Param filter event */
147 #define BTA_GATTC_SCAN_FLT_STATUS_EVT 33 /* Filter status event */
148 #define BTA_GATTC_ADV_VSC_EVT 34 /* ADV VSC event */
150 typedef UINT8 tBTA_GATTC_EVT;
152 typedef tGATT_IF tBTA_GATTC_IF;
156 UINT16 unit; /* as UUIUD defined by SIG */
157 UINT16 descr; /* as UUID as defined by SIG */
160 UINT8 name_spc; /* The name space of the description */
161 }tBTA_GATT_CHAR_PRES;
163 #define BTA_GATT_CLT_CONFIG_NONE GATT_CLT_CONFIG_NONE /* 0x0000 */
164 #define BTA_GATT_CLT_CONFIG_NOTIFICATION GATT_CLT_CONFIG_NOTIFICATION /* 0x0001 */
165 #define BTA_GATT_CLT_CONFIG_INDICATION GATT_CLT_CONFIG_INDICATION /* 0x0002 */
166 typedef UINT16 tBTA_GATT_CLT_CHAR_CONFIG;
168 /* characteristic descriptor: server configuration value
170 #define BTA_GATT_SVR_CONFIG_NONE GATT_SVR_CONFIG_NONE /* 0x0000 */
171 #define BTA_GATT_SVR_CONFIG_BROADCAST GATT_SVR_CONFIG_BROADCAST /* 0x0001 */
172 typedef UINT16 tBTA_GATT_SVR_CHAR_CONFIG;
174 /* Characteristic Aggregate Format attribute value
176 #define BTA_GATT_AGGR_HANDLE_NUM_MAX 10
180 UINT16 handle_list[BTA_GATT_AGGR_HANDLE_NUM_MAX];
181 } tBTA_GATT_CHAR_AGGRE;
182 typedef tGATT_VALID_RANGE tBTA_GATT_VALID_RANGE;
190 #define BTA_GATT_MAX_ATTR_LEN GATT_MAX_ATTR_LEN
192 #define BTA_GATTC_TYPE_WRITE GATT_WRITE
193 #define BTA_GATTC_TYPE_WRITE_NO_RSP GATT_WRITE_NO_RSP
194 typedef UINT8 tBTA_GATTC_WRITE_TYPE;
196 #define BTA_GATT_CONN_UNKNOWN 0
197 #define BTA_GATT_CONN_L2C_FAILURE GATT_CONN_L2C_FAILURE /* general l2cap resource failure */
198 #define BTA_GATT_CONN_TIMEOUT GATT_CONN_TIMEOUT /* 0x08 connection timeout */
199 #define BTA_GATT_CONN_TERMINATE_PEER_USER GATT_CONN_TERMINATE_PEER_USER /* 0x13 connection terminate by peer user */
200 #define BTA_GATT_CONN_TERMINATE_LOCAL_HOST GATT_CONN_TERMINATE_LOCAL_HOST/* 0x16 connectionterminated by local host */
201 #define BTA_GATT_CONN_FAIL_ESTABLISH GATT_CONN_FAIL_ESTABLISH /* 0x03E connection fail to establish */
202 #define BTA_GATT_CONN_LMP_TIMEOUT GATT_CONN_LMP_TIMEOUT /* 0x22 connection fail for LMP response tout */
203 #define BTA_GATT_CONN_CANCEL GATT_CONN_CANCEL /* 0x0100 L2CAP connection cancelled */
204 #define BTA_GATT_CONN_NONE 0x0101 /* 0x0101 no connection to cancel */
205 typedef UINT16 tBTA_GATT_REASON;
207 #define BTA_GATTC_MULTI_MAX GATT_MAX_READ_MULTI_HANDLES
212 UINT16 handles[BTA_GATTC_MULTI_MAX];
215 #define BTA_GATT_AUTH_REQ_NONE GATT_AUTH_REQ_NONE
216 #define BTA_GATT_AUTH_REQ_NO_MITM GATT_AUTH_REQ_NO_MITM /* unauthenticated encryption */
217 #define BTA_GATT_AUTH_REQ_MITM GATT_AUTH_REQ_MITM /* authenticated encryption */
218 #define BTA_GATT_AUTH_REQ_SIGNED_NO_MITM GATT_AUTH_REQ_SIGNED_NO_MITM
219 #define BTA_GATT_AUTH_REQ_SIGNED_MITM GATT_AUTH_REQ_SIGNED_MITM
221 typedef tGATT_AUTH_REQ tBTA_GATT_AUTH_REQ;
225 BTA_GATTC_ATTR_TYPE_INCL_SRVC,
226 BTA_GATTC_ATTR_TYPE_CHAR,
227 BTA_GATTC_ATTR_TYPE_CHAR_DESCR,
228 BTA_GATTC_ATTR_TYPE_SRVC
230 typedef UINT8 tBTA_GATTC_ATTR_TYPE;
237 UINT16 e_handle; /* used for service only */
240 UINT8 prop; /* used when attribute type is characteristic */
241 BOOLEAN is_primary; /* used when attribute type is service */
242 UINT16 incl_srvc_handle; /* used when attribute type is included service */
245 /* callback data structure */
248 tBTA_GATT_STATUS status;
249 tBTA_GATTC_IF client_if;
256 tBTA_GATT_STATUS status;
258 tBTA_GATT_UNFMT *p_value;
264 tBTA_GATT_STATUS status;
271 tBTA_GATT_STATUS status;
272 }tBTA_GATTC_EXEC_CMPL;
277 tBTA_GATT_STATUS status;
278 }tBTA_GATTC_SEARCH_CMPL;
283 tBTA_GATT_ID service_uuid;
284 }tBTA_GATTC_SRVC_RES;
289 tBTA_GATT_STATUS status;
295 tBTA_GATT_STATUS status;
297 tBTA_GATTC_IF client_if;
299 tBTA_TRANSPORT transport;
305 tBTA_GATT_STATUS status;
307 tBTA_GATTC_IF client_if;
309 tBTA_GATT_REASON reason; /* disconnect reason code, not useful when connect event is reported */
318 UINT8 value[BTA_GATT_MAX_ATTR_LEN];
325 BOOLEAN congested; /* congestion indicator */
330 tBTA_GATT_STATUS status;
331 tBTA_GATTC_IF client_if;
334 }tBTA_GATTC_OPEN_CLOSE;
338 tBTA_GATTC_IF client_if;
340 }tBTA_GATTC_ENC_CMPL_CB;
344 tBTA_GATT_STATUS status;
346 tBTA_GATTC_SEARCH_CMPL search_cmpl; /* discovery complete */
347 tBTA_GATTC_SRVC_RES srvc_res; /* discovery result */
348 tBTA_GATTC_REG reg_oper; /* registration data */
349 tBTA_GATTC_OPEN open;
350 tBTA_GATTC_CLOSE close;
351 tBTA_GATTC_READ read; /* read attribute/descriptor data */
352 tBTA_GATTC_WRITE write; /* write complete data */
353 tBTA_GATTC_EXEC_CMPL exec_cmpl; /* execute complete */
354 tBTA_GATTC_NOTIFY notify; /* notification/indication event data */
355 tBTA_GATTC_ENC_CMPL_CB enc_cmpl;
356 BD_ADDR remote_bda; /* service change event */
357 tBTA_GATTC_CFG_MTU cfg_mtu; /* configure MTU operation */
358 tBTA_GATTC_CONGEST congest;
361 /* GATTC enable callback function */
362 typedef void (tBTA_GATTC_ENB_CBACK)(tBTA_GATT_STATUS status);
364 /* Client callback function */
365 typedef void (tBTA_GATTC_CBACK)(tBTA_GATTC_EVT event, tBTA_GATTC *p_data);
368 /* GATT Server Data Structure */
369 /* Server callback function events */
370 #define BTA_GATTS_REG_EVT 0
371 #define BTA_GATTS_READ_EVT GATTS_REQ_TYPE_READ /* 1 */
372 #define BTA_GATTS_WRITE_EVT GATTS_REQ_TYPE_WRITE /* 2 */
373 #define BTA_GATTS_EXEC_WRITE_EVT GATTS_REQ_TYPE_WRITE_EXEC /* 3 */
374 #define BTA_GATTS_MTU_EVT GATTS_REQ_TYPE_MTU /* 4 */
375 #define BTA_GATTS_CONF_EVT GATTS_REQ_TYPE_CONF /* 5 */
376 #define BTA_GATTS_DEREG_EVT 6
377 #define BTA_GATTS_CREATE_EVT 7
378 #define BTA_GATTS_ADD_INCL_SRVC_EVT 8
379 #define BTA_GATTS_ADD_CHAR_EVT 9
380 #define BTA_GATTS_ADD_CHAR_DESCR_EVT 10
381 #define BTA_GATTS_DELELTE_EVT 11
382 #define BTA_GATTS_START_EVT 12
383 #define BTA_GATTS_STOP_EVT 13
384 #define BTA_GATTS_CONNECT_EVT 14
385 #define BTA_GATTS_DISCONNECT_EVT 15
386 #define BTA_GATTS_OPEN_EVT 16
387 #define BTA_GATTS_CANCEL_OPEN_EVT 17
388 #define BTA_GATTS_CLOSE_EVT 18
389 #define BTA_GATTS_LISTEN_EVT 19
390 #define BTA_GATTS_CONGEST_EVT 20
392 typedef UINT8 tBTA_GATTS_EVT;
393 typedef tGATT_IF tBTA_GATTS_IF;
395 /* Attribute permissions
397 #define BTA_GATT_PERM_READ GATT_PERM_READ /* bit 0 - 0x0001 */
398 #define BTA_GATT_PERM_READ_ENCRYPTED GATT_PERM_READ_ENCRYPTED /* bit 1 - 0x0002 */
399 #define BTA_GATT_PERM_READ_ENC_MITM GATT_PERM_READ_ENC_MITM /* bit 2 - 0x0004 */
400 #define BTA_GATT_PERM_WRITE GATT_PERM_WRITE /* bit 4 - 0x0010 */
401 #define BTA_GATT_PERM_WRITE_ENCRYPTED GATT_PERM_WRITE_ENCRYPTED /* bit 5 - 0x0020 */
402 #define BTA_GATT_PERM_WRITE_ENC_MITM GATT_PERM_WRITE_ENC_MITM /* bit 6 - 0x0040 */
403 #define BTA_GATT_PERM_WRITE_SIGNED GATT_PERM_WRITE_SIGNED /* bit 7 - 0x0080 */
404 #define BTA_GATT_PERM_WRITE_SIGNED_MITM GATT_PERM_WRITE_SIGNED_MITM /* bit 8 - 0x0100 */
405 typedef UINT16 tBTA_GATT_PERM;
407 #define BTA_GATTS_INVALID_APP 0xff
409 #define BTA_GATTS_INVALID_IF 0
411 /* definition of characteristic properties */
412 #define BTA_GATT_CHAR_PROP_BIT_BROADCAST GATT_CHAR_PROP_BIT_BROADCAST /* 0x01 */
413 #define BTA_GATT_CHAR_PROP_BIT_READ GATT_CHAR_PROP_BIT_READ /* 0x02 */
414 #define BTA_GATT_CHAR_PROP_BIT_WRITE_NR GATT_CHAR_PROP_BIT_WRITE_NR /* 0x04 */
415 #define BTA_GATT_CHAR_PROP_BIT_WRITE GATT_CHAR_PROP_BIT_WRITE /* 0x08 */
416 #define BTA_GATT_CHAR_PROP_BIT_NOTIFY GATT_CHAR_PROP_BIT_NOTIFY /* 0x10 */
417 #define BTA_GATT_CHAR_PROP_BIT_INDICATE GATT_CHAR_PROP_BIT_INDICATE /* 0x20 */
418 #define BTA_GATT_CHAR_PROP_BIT_AUTH GATT_CHAR_PROP_BIT_AUTH /* 0x40 */
419 #define BTA_GATT_CHAR_PROP_BIT_EXT_PROP GATT_CHAR_PROP_BIT_EXT_PROP /* 0x80 */
420 typedef UINT8 tBTA_GATT_CHAR_PROP;
422 #ifndef BTA_GATTC_CHAR_DESCR_MAX
423 #define BTA_GATTC_CHAR_DESCR_MAX 7
426 /*********************** NV callback Data Definitions **********************
430 tBT_UUID app_uuid128;
435 BOOLEAN is_primary; /* primary service or secondary */
436 } tBTA_GATTS_HNDL_RANGE;
438 #define BTA_GATTS_SRV_CHG_CMD_ADD_CLIENT GATTS_SRV_CHG_CMD_ADD_CLIENT
439 #define BTA_GATTS_SRV_CHG_CMD_UPDATE_CLIENT GATTS_SRV_CHG_CMD_UPDATE_CLIENT
440 #define BTA_GATTS_SRV_CHG_CMD_REMOVE_CLIENT GATTS_SRV_CHG_CMD_REMOVE_CLIENT
441 #define BTA_GATTS_SRV_CHG_CMD_READ_NUM_CLENTS GATTS_SRV_CHG_CMD_READ_NUM_CLENTS
442 #define BTA_GATTS_SRV_CHG_CMD_READ_CLENT GATTS_SRV_CHG_CMD_READ_CLENT
443 typedef tGATTS_SRV_CHG_CMD tBTA_GATTS_SRV_CHG_CMD;
445 typedef tGATTS_SRV_CHG tBTA_GATTS_SRV_CHG;
446 typedef tGATTS_SRV_CHG_REQ tBTA_GATTS_SRV_CHG_REQ;
447 typedef tGATTS_SRV_CHG_RSP tBTA_GATTS_SRV_CHG_RSP;
449 #define BTA_GATT_TRANSPORT_LE GATT_TRANSPORT_LE
450 #define BTA_GATT_TRANSPORT_BR_EDR GATT_TRANSPORT_BR_EDR
451 #define BTA_GATT_TRANSPORT_LE_BR_EDR GATT_TRANSPORT_LE_BR_EDR
452 typedef UINT8 tBTA_GATT_TRANSPORT;
454 /* attribute value */
455 typedef tGATT_VALUE tBTA_GATT_VALUE;
457 /* attribute response data */
458 typedef tGATTS_RSP tBTA_GATTS_RSP;
460 /* attribute request data from the client */
461 #define BTA_GATT_PREP_WRITE_CANCEL 0x00
462 #define BTA_GATT_PREP_WRITE_EXEC 0x01
463 typedef tGATT_EXEC_FLAG tBTA_GATT_EXEC_FLAG;
465 /* read request always based on UUID */
466 typedef tGATT_READ_REQ tTA_GBATT_READ_REQ;
468 /* write request data */
469 typedef tGATT_WRITE_REQ tBTA_GATT_WRITE_REQ;
471 /* callback data for server access request from client */
472 typedef tGATTS_DATA tBTA_GATTS_REQ_DATA;
476 tBTA_GATT_STATUS status;
480 tBTA_GATTS_REQ_DATA *p_data;
485 tBTA_GATTS_IF server_if;
486 tBTA_GATT_STATUS status;
488 }tBTA_GATTS_REG_OPER;
493 tBTA_GATTS_IF server_if;
497 tBTA_GATT_STATUS status;
503 tBTA_GATTS_IF server_if;
506 tBTA_GATT_STATUS status;
508 }tBTA_GATTS_ADD_RESULT;
512 tBTA_GATTS_IF server_if;
514 tBTA_GATT_STATUS status;
515 }tBTA_GATTS_SRVC_OPER;
520 tBTA_GATTS_IF server_if;
523 tBTA_GATT_REASON reason; /* report disconnect reason */
524 tBTA_GATT_TRANSPORT transport;
530 BOOLEAN congested; /* report channel congestion indicator */
535 UINT16 conn_id; /* connection ID */
536 tBTA_GATT_STATUS status; /* notification/indication status */
539 /* GATTS callback data */
542 tBTA_GATTS_REG_OPER reg_oper;
543 tBTA_GATTS_CREATE create;
544 tBTA_GATTS_SRVC_OPER srvc_oper;
545 tBTA_GATT_STATUS status; /* BTA_GATTS_LISTEN_EVT */
546 tBTA_GATTS_ADD_RESULT add_result; /* add included service: BTA_GATTS_ADD_INCL_SRVC_EVT
547 add char : BTA_GATTS_ADD_CHAR_EVT
548 add char descriptor: BTA_GATTS_ADD_CHAR_DESCR_EVT */
549 tBTA_GATTS_REQ req_data;
550 tBTA_GATTS_CONN conn; /* BTA_GATTS_CONN_EVT */
551 tBTA_GATTS_CONGEST congest; /* BTA_GATTS_CONGEST_EVT callback data */
552 tBTA_GATTS_CONF confirm; /* BTA_GATTS_CONF_EVT callback data */
555 /* GATTS enable callback function */
556 typedef void (tBTA_GATTS_ENB_CBACK)(tBTA_GATT_STATUS status);
558 /* Server callback function */
559 typedef void (tBTA_GATTS_CBACK)(tBTA_GATTS_EVT event, tBTA_GATTS *p_data);
568 list_t *characteristics; /* list of tBTA_GATTC_CHARACTERISTIC */
569 list_t *included_svc; /* list of tBTA_GATTC_INCLUDED_SVC */
570 } __attribute__((packed)) tBTA_GATTC_SERVICE;
576 tBTA_GATT_CHAR_PROP properties;
577 tBTA_GATTC_SERVICE *service; /* owning service*/
578 list_t *descriptors; /* list of tBTA_GATTC_DESCRIPTOR */
579 } __attribute__((packed)) tBTA_GATTC_CHARACTERISTIC;
585 tBTA_GATTC_CHARACTERISTIC *characteristic; /* owning characteristic */
586 } __attribute__((packed)) tBTA_GATTC_DESCRIPTOR;
592 tBTA_GATTC_SERVICE *owning_service; /* owning service*/
593 tBTA_GATTC_SERVICE *included_service;
594 } __attribute__((packed)) tBTA_GATTC_INCLUDED_SVC;
596 /*****************************************************************************
597 ** External Function Declarations
598 *****************************************************************************/
605 /**************************
607 ***************************/
609 /*******************************************************************************
611 ** Function BTA_GATTC_Disable
613 ** Description This function is called to disable the GATTC module
619 *******************************************************************************/
620 extern void BTA_GATTC_Disable(void);
622 /*******************************************************************************
624 ** Function BTA_GATTC_AppRegister
626 ** Description This function is called to register application callbacks
627 ** with BTA GATTC module.
629 ** Parameters p_app_uuid - applicaiton UUID
630 ** p_client_cb - pointer to the application callback function.
634 *******************************************************************************/
635 extern void BTA_GATTC_AppRegister(tBT_UUID *p_app_uuid, tBTA_GATTC_CBACK *p_client_cb);
637 /*******************************************************************************
639 ** Function BTA_GATTC_AppDeregister
641 ** Description This function is called to deregister an application
642 ** from BTA GATTC module.
644 ** Parameters client_if - client interface identifier.
648 *******************************************************************************/
649 extern void BTA_GATTC_AppDeregister (tBTA_GATTC_IF client_if);
651 /*******************************************************************************
653 ** Function BTA_GATTC_Open
655 ** Description Open a direct connection or add a background auto connection
658 ** Parameters client_if: server interface.
659 ** remote_bda: remote device BD address.
660 ** is_direct: direct connection or background auto connection
664 *******************************************************************************/
665 extern void BTA_GATTC_Open(tBTA_GATTC_IF client_if, BD_ADDR remote_bda,
666 BOOLEAN is_direct, tBTA_GATT_TRANSPORT transport);
668 /*******************************************************************************
670 ** Function BTA_GATTC_CancelOpen
672 ** Description Open a direct connection or add a background auto connection
675 ** Parameters client_if: server interface.
676 ** remote_bda: remote device BD address.
677 ** is_direct: direct connection or background auto connection
681 *******************************************************************************/
682 extern void BTA_GATTC_CancelOpen(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, BOOLEAN is_direct);
684 /*******************************************************************************
686 ** Function BTA_GATTC_Close
688 ** Description Close a connection to a GATT server.
690 ** Parameters conn_id: connectino ID to be closed.
694 *******************************************************************************/
695 extern void BTA_GATTC_Close(UINT16 conn_id);
697 /*******************************************************************************
699 ** Function BTA_GATTC_ServiceSearchRequest
701 ** Description This function is called to request a GATT service discovery
702 ** on a GATT server. This function report service search result
703 ** by a callback event, and followed by a service search complete
706 ** Parameters conn_id: connection ID.
707 ** p_srvc_uuid: a UUID of the service application is interested in.
708 ** If Null, discover for all services.
712 *******************************************************************************/
713 extern void BTA_GATTC_ServiceSearchRequest(UINT16 conn_id, tBT_UUID *p_srvc_uuid);
715 /*******************************************************************************
717 ** Function BTA_GATTC_GetServices
719 ** Description This function is called to find the services on the given server.
721 ** Parameters conn_id: connection ID which identify the server.
723 ** Returns returns list_t of tBTA_GATTC_SERVICE or NULL.
725 *******************************************************************************/
726 extern const list_t* BTA_GATTC_GetServices(UINT16 conn_id);
728 /*******************************************************************************
730 ** Function BTA_GATTC_GetCharacteristic
732 ** Description This function is called to find the characteristic on the given server.
734 ** Parameters conn_id: connection ID which identify the server.
735 ** handle: characteristic handle
737 ** Returns returns pointer to tBTA_GATTC_CHARACTERISTIC or NULL.
739 *******************************************************************************/
740 extern const tBTA_GATTC_CHARACTERISTIC* BTA_GATTC_GetCharacteristic(UINT16 conn_id, UINT16 handle);
742 /*******************************************************************************
744 ** Function BTA_GATTC_GetDescriptor
746 ** Description This function is called to find the characteristic on the given server.
748 ** Parameters conn_id: connection ID which identify the server.
749 ** handle: descriptor handle
751 ** Returns returns pointer to tBTA_GATTC_DESCRIPTOR or NULL.
753 *******************************************************************************/
754 extern const tBTA_GATTC_DESCRIPTOR* BTA_GATTC_GetDescriptor(UINT16 conn_id, UINT16 handle);
756 /*******************************************************************************
758 ** Function BTA_GATTC_GetGattDb
760 ** Description This function is called to get gatt db.
762 ** Parameters conn_id: connection ID which identify the server.
763 ** db: output parameter which will contain gatt db copy.
764 ** Caller is responsible for freeing it.
765 ** count: number of elements in db.
767 *******************************************************************************/
768 extern void BTA_GATTC_GetGattDb(UINT16 conn_id, UINT16 start_handle, UINT16 end_handle,
769 btgatt_db_element_t **db, int *count);
771 /*******************************************************************************
773 ** Function BTA_GATTC_ReadCharacteristic
775 ** Description This function is called to read a characteristics value
777 ** Parameters conn_id - connectino ID.
778 ** handle - characteritic handle to read.
782 *******************************************************************************/
783 void BTA_GATTC_ReadCharacteristic(UINT16 conn_id, UINT16 handle, tBTA_GATT_AUTH_REQ auth_req);
785 /*******************************************************************************
787 ** Function BTA_GATTC_ReadCharDescr
789 ** Description This function is called to read a descriptor value.
791 ** Parameters conn_id - connection ID.
792 ** handle - descriptor handle to read.
796 *******************************************************************************/
797 void BTA_GATTC_ReadCharDescr (UINT16 conn_id, UINT16 handle, tBTA_GATT_AUTH_REQ auth_req);
799 /*******************************************************************************
801 ** Function BTA_GATTC_WriteCharValue
803 ** Description This function is called to write characteristic value.
805 ** Parameters conn_id - connection ID.
806 ** handle - characteristic handle to write.
807 ** write_type - type of write.
808 ** len: length of the data to be written.
809 ** p_value - the value to be written.
813 *******************************************************************************/
814 void BTA_GATTC_WriteCharValue ( UINT16 conn_id,
816 tBTA_GATTC_WRITE_TYPE write_type,
819 tBTA_GATT_AUTH_REQ auth_req);
821 /*******************************************************************************
823 ** Function BTA_GATTC_WriteCharDescr
825 ** Description This function is called to write descriptor value.
827 ** Parameters conn_id - connection ID
828 ** handle - descriptor handle to write.
829 ** write_type - type of write.
830 ** p_value - the value to be written.
834 *******************************************************************************/
835 void BTA_GATTC_WriteCharDescr (UINT16 conn_id,
837 tBTA_GATTC_WRITE_TYPE write_type,
838 tBTA_GATT_UNFMT *p_data,
839 tBTA_GATT_AUTH_REQ auth_req);
841 /*******************************************************************************
843 ** Function BTA_GATTC_SendIndConfirm
845 ** Description This function is called to send handle value confirmation.
847 ** Parameters conn_id - connection ID.
848 ** handle - characteristic handle to confirm.
852 *******************************************************************************/
853 extern void BTA_GATTC_SendIndConfirm (UINT16 conn_id, UINT16 handle);
855 /*******************************************************************************
857 ** Function BTA_GATTC_RegisterForNotifications
859 ** Description This function is called to register for notification of a service.
861 ** Parameters client_if - client interface.
862 ** remote_bda - target GATT server.
863 ** handle - GATT characteristic handle.
865 ** Returns OK if registration succeed, otherwise failed.
867 *******************************************************************************/
868 extern tBTA_GATT_STATUS BTA_GATTC_RegisterForNotifications (tBTA_GATTC_IF client_if,
872 /*******************************************************************************
874 ** Function BTA_GATTC_DeregisterForNotifications
876 ** Description This function is called to de-register for notification of a servbice.
878 ** Parameters client_if - client interface.
879 ** remote_bda - target GATT server.
880 ** handle - GATT characteristic handle.
882 ** Returns OK if deregistration succeed, otherwise failed.
884 *******************************************************************************/
885 extern tBTA_GATT_STATUS BTA_GATTC_DeregisterForNotifications (tBTA_GATTC_IF client_if,
889 /*******************************************************************************
891 ** Function BTA_GATTC_PrepareWrite
893 ** Description This function is called to prepare write a characteristic value.
895 ** Parameters conn_id - connection ID.
896 ** handle - GATT characteritic handle.
897 ** offset - offset of the write value.
898 ** len - length of the data to be written.
899 ** p_value - the value to be written.
903 *******************************************************************************/
904 extern void BTA_GATTC_PrepareWrite (UINT16 conn_id,
909 tBTA_GATT_AUTH_REQ auth_req);
911 /*******************************************************************************
913 ** Function BTA_GATTC_ExecuteWrite
915 ** Description This function is called to execute write a prepare write sequence.
917 ** Parameters conn_id - connection ID.
918 ** is_execute - execute or cancel.
922 *******************************************************************************/
923 extern void BTA_GATTC_ExecuteWrite (UINT16 conn_id, BOOLEAN is_execute);
925 /*******************************************************************************
927 ** Function BTA_GATTC_ReadMultiple
929 ** Description This function is called to read multiple characteristic or
930 ** characteristic descriptors.
932 ** Parameters conn_id - connectino ID.
933 ** p_read_multi - read multiple parameters.
937 *******************************************************************************/
938 extern void BTA_GATTC_ReadMultiple(UINT16 conn_id, tBTA_GATTC_MULTI *p_read_multi,
939 tBTA_GATT_AUTH_REQ auth_req);
942 /*******************************************************************************
944 ** Function BTA_GATTC_Refresh
946 ** Description Refresh the server cache of the remote device
948 ** Parameters remote_bda: remote device BD address.
952 *******************************************************************************/
953 extern void BTA_GATTC_Refresh(BD_ADDR remote_bda);
956 /*******************************************************************************
958 ** Function BTA_GATTC_Listen
960 ** Description Start advertisement to listen for connection request.
962 ** Parameters client_if: server interface.
963 ** start: to start or stop listening for connection
964 ** remote_bda: remote device BD address, if listen to all device
969 *******************************************************************************/
970 extern void BTA_GATTC_Listen(tBTA_GATTC_IF client_if, BOOLEAN start, BD_ADDR_PTR target_bda);
972 /*******************************************************************************
974 ** Function BTA_GATTC_Broadcast
976 ** Description Start broadcasting (non-connectable advertisements)
978 ** Parameters client_if: client interface.
979 ** start: to start or stop listening for connection
983 *******************************************************************************/
984 extern void BTA_GATTC_Broadcast(tBTA_GATTC_IF client_if, BOOLEAN start);
987 /*******************************************************************************
989 ** Function BTA_GATTC_ConfigureMTU
991 ** Description Configure the MTU size in the GATT channel. This can be done
992 ** only once per connection.
994 ** Parameters conn_id: connection ID.
995 ** mtu: desired MTU size to use.
999 *******************************************************************************/
1000 extern void BTA_GATTC_ConfigureMTU (UINT16 conn_id, UINT16 mtu);
1002 /*******************************************************************************
1003 ** BTA GATT Server API
1004 ********************************************************************************/
1006 /*******************************************************************************
1008 ** Function BTA_GATTS_Init
1010 ** Description This function is called to initalize GATTS module
1016 *******************************************************************************/
1017 extern void BTA_GATTS_Init();
1019 /*******************************************************************************
1021 ** Function BTA_GATTS_Disable
1023 ** Description This function is called to disable GATTS module
1029 *******************************************************************************/
1030 extern void BTA_GATTS_Disable(void);
1032 /*******************************************************************************
1034 ** Function BTA_GATTS_AppRegister
1036 ** Description This function is called to register application callbacks
1037 ** with BTA GATTS module.
1039 ** Parameters p_app_uuid - applicaiton UUID
1040 ** p_cback - pointer to the application callback function.
1044 *******************************************************************************/
1045 extern void BTA_GATTS_AppRegister(tBT_UUID *p_app_uuid, tBTA_GATTS_CBACK *p_cback);
1048 /*******************************************************************************
1050 ** Function BTA_GATTS_AppDeregister
1052 ** Description De-register with BTA GATT Server.
1054 ** Parameters server_if: server interface
1058 *******************************************************************************/
1059 extern void BTA_GATTS_AppDeregister(tBTA_GATTS_IF server_if);
1061 /*******************************************************************************
1063 ** Function BTA_GATTS_CreateService
1065 ** Description Create a service. When service creation is done, a callback
1066 ** event BTA_GATTS_CREATE_SRVC_EVT is called to report status
1067 ** and service ID to the profile. The service ID obtained in
1068 ** the callback function needs to be used when adding included
1069 ** service and characteristics/descriptors into the service.
1071 ** Parameters server_if: server interface.
1072 ** p_service_uuid: service UUID.
1073 ** inst: instance ID number of this service.
1074 ** num_handle: numble of handle requessted for this service.
1075 ** is_primary: is this service a primary one or not.
1079 *******************************************************************************/
1080 extern void BTA_GATTS_CreateService(tBTA_GATTS_IF server_if, tBT_UUID *p_service_uuid,
1081 UINT8 inst, UINT16 num_handle, BOOLEAN is_primary);
1083 /*******************************************************************************
1085 ** Function BTA_GATTS_AddIncludeService
1087 ** Description This function is called to add an included service. After included
1088 ** service is included, a callback event BTA_GATTS_ADD_INCL_SRVC_EVT
1089 ** is reported the included service ID.
1091 ** Parameters service_id: service ID to which this included service is to
1093 ** included_service_id: the service ID to be included.
1097 *******************************************************************************/
1098 extern void BTA_GATTS_AddIncludeService(UINT16 service_id, UINT16 included_service_id);
1100 /*******************************************************************************
1102 ** Function BTA_GATTS_AddCharacteristic
1104 ** Description This function is called to add a characteristic into a service.
1106 ** Parameters service_id: service ID to which this included service is to
1108 ** p_char_uuid : Characteristic UUID.
1109 ** perm : Characteristic value declaration attribute permission.
1110 ** property : Characteristic Properties
1114 *******************************************************************************/
1115 extern void BTA_GATTS_AddCharacteristic (UINT16 service_id, tBT_UUID *p_char_uuid,
1116 tBTA_GATT_PERM perm, tBTA_GATT_CHAR_PROP property);
1118 /*******************************************************************************
1120 ** Function BTA_GATTS_AddCharDescriptor
1122 ** Description This function is called to add characteristic descriptor. When
1123 ** it's done, a callback event BTA_GATTS_ADD_DESCR_EVT is called
1124 ** to report the status and an ID number for this descriptor.
1126 ** Parameters service_id: service ID to which this charatceristic descriptor is to
1128 ** perm: descriptor access permission.
1129 ** p_descr_uuid: descriptor UUID.
1130 ** p_descr_params: descriptor value if it's read only descriptor.
1132 ** Returns returns status.
1134 *******************************************************************************/
1135 extern void BTA_GATTS_AddCharDescriptor (UINT16 service_id,
1136 tBTA_GATT_PERM perm,
1137 tBT_UUID * p_descr_uuid);
1139 /*******************************************************************************
1141 ** Function BTA_GATTS_DeleteService
1143 ** Description This function is called to delete a service. When this is done,
1144 ** a callback event BTA_GATTS_DELETE_EVT is report with the status.
1146 ** Parameters service_id: service_id to be deleted.
1148 ** Returns returns none.
1150 *******************************************************************************/
1151 extern void BTA_GATTS_DeleteService(UINT16 service_id);
1153 /*******************************************************************************
1155 ** Function BTA_GATTS_StartService
1157 ** Description This function is called to start a service.
1159 ** Parameters service_id: the service ID to be started.
1160 ** sup_transport: supported trasnport.
1164 *******************************************************************************/
1165 extern void BTA_GATTS_StartService(UINT16 service_id, tBTA_GATT_TRANSPORT sup_transport);
1167 /*******************************************************************************
1169 ** Function BTA_GATTS_StopService
1171 ** Description This function is called to stop a service.
1173 ** Parameters service_id - service to be topped.
1177 *******************************************************************************/
1178 extern void BTA_GATTS_StopService(UINT16 service_id);
1180 /*******************************************************************************
1182 ** Function BTA_GATTS_HandleValueIndication
1184 ** Description This function is called to read a characteristics descriptor.
1186 ** Parameters conn_id - connection identifier.
1187 ** attr_id - attribute ID to indicate.
1188 ** data_len - indicate data length.
1189 ** p_data: data to indicate.
1190 ** need_confirm - if this indication expects a confirmation or not.
1194 *******************************************************************************/
1195 extern void BTA_GATTS_HandleValueIndication (UINT16 conn_id, UINT16 attr_id,
1198 BOOLEAN need_confirm);
1200 /*******************************************************************************
1202 ** Function BTA_GATTS_SendRsp
1204 ** Description This function is called to send a response to a request.
1206 ** Parameters conn_id - connection identifier.
1207 ** trans_id - transaction ID.
1208 ** status - response status
1209 ** p_msg - response data.
1213 *******************************************************************************/
1214 extern void BTA_GATTS_SendRsp (UINT16 conn_id, UINT32 trans_id,
1215 tBTA_GATT_STATUS status, tBTA_GATTS_RSP *p_msg);
1218 /*******************************************************************************
1220 ** Function BTA_GATTS_Open
1222 ** Description Open a direct open connection or add a background auto connection
1225 ** Parameters server_if: server interface.
1226 ** remote_bda: remote device BD address.
1227 ** is_direct: direct connection or background auto connection
1231 *******************************************************************************/
1232 extern void BTA_GATTS_Open(tBTA_GATTS_IF server_if, BD_ADDR remote_bda,
1233 BOOLEAN is_direct, tBTA_GATT_TRANSPORT transport);
1236 /*******************************************************************************
1238 ** Function BTA_GATTS_CancelOpen
1240 ** Description Cancel a direct open connection or remove a background auto connection
1243 ** Parameters server_if: server interface.
1244 ** remote_bda: remote device BD address.
1245 ** is_direct: direct connection or background auto connection
1249 *******************************************************************************/
1250 extern void BTA_GATTS_CancelOpen(tBTA_GATTS_IF server_if, BD_ADDR remote_bda, BOOLEAN is_direct);
1253 /*******************************************************************************
1255 ** Function BTA_GATTS_Close
1257 ** Description Close a connection a remote device.
1259 ** Parameters conn_id: connectino ID to be closed.
1263 *******************************************************************************/
1264 extern void BTA_GATTS_Close(UINT16 conn_id);
1266 /*******************************************************************************
1268 ** Function BTA_GATTS_Listen
1270 ** Description Start advertisement to listen for connection request for a
1273 ** Parameters server_if: server interface.
1274 ** start: to start or stop listening for connection
1275 ** remote_bda: remote device BD address, if listen to all device
1280 *******************************************************************************/
1281 extern void BTA_GATTS_Listen(tBTA_GATTS_IF server_if, BOOLEAN start,
1282 BD_ADDR_PTR target_bda);
1291 #endif /* BTA_GATT_API_H */