Home | History | Annotate | Download | only in include
      1 /******************************************************************************
      2  *
      3  *  Copyright (C) 2003-2013 Broadcom Corporation
      4  *
      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:
      8  *
      9  *  http://www.apache.org/licenses/LICENSE-2.0
     10  *
     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.
     16  *
     17  ******************************************************************************/
     18 
     19 /******************************************************************************
     20  *
     21  *  This is the public interface file for BTA GATT.
     22  *
     23  ******************************************************************************/
     24 
     25 #ifndef BTA_GATT_API_H
     26 #define BTA_GATT_API_H
     27 
     28 #include "bta_api.h"
     29 #include "gatt_api.h"
     30 #include "osi/include/list.h"
     31 
     32 #include <base/callback_forward.h>
     33 #include <vector>
     34 
     35 using std::vector;
     36 
     37 #ifndef BTA_GATT_DEBUG
     38 #define BTA_GATT_DEBUG false
     39 #endif
     40 
     41 /*****************************************************************************
     42  *  Constants and data types
     43  ****************************************************************************/
     44 /**************************
     45  *  Common Definitions
     46  **************************/
     47 /* GATT ID */
     48 typedef struct {
     49   tBT_UUID uuid;   /* uuid of the attribute */
     50   uint8_t inst_id; /* instance ID */
     51 } __attribute__((packed)) tBTA_GATT_ID;
     52 
     53 /* Success code and error codes */
     54 #define BTA_GATT_OK GATT_SUCCESS
     55 #define BTA_GATT_INVALID_HANDLE GATT_INVALID_HANDLE             /* 0x0001 */
     56 #define BTA_GATT_READ_NOT_PERMIT GATT_READ_NOT_PERMIT           /* 0x0002 */
     57 #define BTA_GATT_WRITE_NOT_PERMIT GATT_WRITE_NOT_PERMIT         /* 0x0003 */
     58 #define BTA_GATT_INVALID_PDU GATT_INVALID_PDU                   /* 0x0004 */
     59 #define BTA_GATT_INSUF_AUTHENTICATION GATT_INSUF_AUTHENTICATION /* 0x0005 */
     60 #define BTA_GATT_REQ_NOT_SUPPORTED GATT_REQ_NOT_SUPPORTED       /* 0x0006 */
     61 #define BTA_GATT_INVALID_OFFSET GATT_INVALID_OFFSET             /* 0x0007 */
     62 #define BTA_GATT_INSUF_AUTHORIZATION GATT_INSUF_AUTHORIZATION   /* 0x0008 */
     63 #define BTA_GATT_PREPARE_Q_FULL GATT_PREPARE_Q_FULL             /* 0x0009 */
     64 #define BTA_GATT_NOT_FOUND GATT_NOT_FOUND                       /* 0x000a */
     65 #define BTA_GATT_NOT_LONG GATT_NOT_LONG                         /* 0x000b */
     66 #define BTA_GATT_INSUF_KEY_SIZE GATT_INSUF_KEY_SIZE             /* 0x000c */
     67 #define BTA_GATT_INVALID_ATTR_LEN GATT_INVALID_ATTR_LEN         /* 0x000d */
     68 #define BTA_GATT_ERR_UNLIKELY GATT_ERR_UNLIKELY                 /* 0x000e */
     69 #define BTA_GATT_INSUF_ENCRYPTION GATT_INSUF_ENCRYPTION         /* 0x000f */
     70 #define BTA_GATT_UNSUPPORT_GRP_TYPE GATT_UNSUPPORT_GRP_TYPE     /* 0x0010 */
     71 #define BTA_GATT_INSUF_RESOURCE GATT_INSUF_RESOURCE             /* 0x0011 */
     72 
     73 #define BTA_GATT_NO_RESOURCES GATT_NO_RESOURCES           /* 0x80 */
     74 #define BTA_GATT_INTERNAL_ERROR GATT_INTERNAL_ERROR       /* 0x81 */
     75 #define BTA_GATT_WRONG_STATE GATT_WRONG_STATE             /* 0x82 */
     76 #define BTA_GATT_DB_FULL GATT_DB_FULL                     /* 0x83 */
     77 #define BTA_GATT_BUSY GATT_BUSY                           /* 0x84 */
     78 #define BTA_GATT_ERROR GATT_ERROR                         /* 0x85 */
     79 #define BTA_GATT_CMD_STARTED GATT_CMD_STARTED             /* 0x86 */
     80 #define BTA_GATT_ILLEGAL_PARAMETER GATT_ILLEGAL_PARAMETER /* 0x87 */
     81 #define BTA_GATT_PENDING GATT_PENDING                     /* 0x88 */
     82 #define BTA_GATT_AUTH_FAIL GATT_AUTH_FAIL                 /* 0x89 */
     83 #define BTA_GATT_MORE GATT_MORE                           /* 0x8a */
     84 #define BTA_GATT_INVALID_CFG GATT_INVALID_CFG             /* 0x8b */
     85 #define BTA_GATT_SERVICE_STARTED GATT_SERVICE_STARTED     /* 0x8c */
     86 #define BTA_GATT_ENCRYPED_MITM GATT_ENCRYPED_MITM         /* GATT_SUCCESS */
     87 #define BTA_GATT_ENCRYPED_NO_MITM GATT_ENCRYPED_NO_MITM   /* 0x8d */
     88 #define BTA_GATT_NOT_ENCRYPTED GATT_NOT_ENCRYPTED         /* 0x8e */
     89 #define BTA_GATT_CONGESTED GATT_CONGESTED                 /* 0x8f */
     90 
     91 #define BTA_GATT_DUP_REG 0x90      /* 0x90 */
     92 #define BTA_GATT_ALREADY_OPEN 0x91 /* 0x91 */
     93 #define BTA_GATT_CANCEL 0x92       /* 0x92 */
     94 
     95 /* 0xE0 ~ 0xFC reserved for future use */
     96 #define BTA_GATT_CCC_CFG_ERR                                              \
     97   GATT_CCC_CFG_ERR /* 0xFD Client Characteristic Configuration Descriptor \
     98                       Improperly Configured */
     99 #define BTA_GATT_PRC_IN_PROGRESS \
    100   GATT_PRC_IN_PROGRESS /* 0xFE Procedure Already in progress */
    101 #define BTA_GATT_OUT_OF_RANGE \
    102   GATT_OUT_OF_RANGE /* 0xFFAttribute value out of range */
    103 
    104 typedef uint8_t tBTA_GATT_STATUS;
    105 
    106 #define BTA_GATT_INVALID_CONN_ID GATT_INVALID_CONN_ID
    107 
    108 /* Client callback function events */
    109 #define BTA_GATTC_DEREG_EVT 1        /* GATT client deregistered event */
    110 #define BTA_GATTC_OPEN_EVT 2         /* GATTC open request status  event */
    111 #define BTA_GATTC_CLOSE_EVT 5        /* GATTC  close request status event */
    112 #define BTA_GATTC_SEARCH_CMPL_EVT 6  /* GATT discovery complete event */
    113 #define BTA_GATTC_SEARCH_RES_EVT 7   /* GATT discovery result event */
    114 #define BTA_GATTC_NOTIF_EVT 10       /* GATT attribute notification event */
    115 #define BTA_GATTC_EXEC_EVT 12        /* execute write complete event */
    116 #define BTA_GATTC_ACL_EVT 13         /* ACL up event */
    117 #define BTA_GATTC_CANCEL_OPEN_EVT 14 /* cancel open event */
    118 #define BTA_GATTC_SRVC_CHG_EVT 15    /* service change event */
    119 #define BTA_GATTC_ENC_CMPL_CB_EVT 17 /* encryption complete callback event */
    120 #define BTA_GATTC_CFG_MTU_EVT 18     /* configure MTU complete event */
    121 #define BTA_GATTC_CONGEST_EVT 24     /* Congestion event */
    122 #define BTA_GATTC_PHY_UPDATE_EVT 25  /* PHY change event */
    123 #define BTA_GATTC_CONN_UPDATE_EVT 26 /* Connection parameters update event */
    124 
    125 typedef uint8_t tBTA_GATTC_EVT;
    126 
    127 typedef tGATT_IF tBTA_GATTC_IF;
    128 
    129 typedef struct {
    130   uint16_t unit;  /* as UUIUD defined by SIG */
    131   uint16_t descr; /* as UUID as defined by SIG */
    132   tGATT_FORMAT format;
    133   int8_t exp;
    134   uint8_t name_spc; /* The name space of the description */
    135 } tBTA_GATT_CHAR_PRES;
    136 
    137 #define BTA_GATT_CLT_CONFIG_NONE GATT_CLT_CONFIG_NONE /* 0x0000    */
    138 #define BTA_GATT_CLT_CONFIG_NOTIFICATION \
    139   GATT_CLT_CONFIG_NOTIFICATION                                    /* 0x0001 */
    140 #define BTA_GATT_CLT_CONFIG_INDICATION GATT_CLT_CONFIG_INDICATION /* 0x0002 */
    141 typedef uint16_t tBTA_GATT_CLT_CHAR_CONFIG;
    142 
    143 /* characteristic descriptor: server configuration value
    144 */
    145 #define BTA_GATT_SVR_CONFIG_NONE GATT_SVR_CONFIG_NONE           /* 0x0000 */
    146 #define BTA_GATT_SVR_CONFIG_BROADCAST GATT_SVR_CONFIG_BROADCAST /*  0x0001 */
    147 typedef uint16_t tBTA_GATT_SVR_CHAR_CONFIG;
    148 
    149 /* Characteristic Aggregate Format attribute value
    150 */
    151 #define BTA_GATT_AGGR_HANDLE_NUM_MAX 10
    152 typedef struct {
    153   uint8_t num_handle;
    154   uint16_t handle_list[BTA_GATT_AGGR_HANDLE_NUM_MAX];
    155 } tBTA_GATT_CHAR_AGGRE;
    156 typedef tGATT_VALID_RANGE tBTA_GATT_VALID_RANGE;
    157 
    158 typedef struct {
    159   uint16_t len;
    160   uint8_t* p_value;
    161 } tBTA_GATT_UNFMT;
    162 
    163 #define BTA_GATT_MAX_ATTR_LEN GATT_MAX_ATTR_LEN
    164 
    165 #define BTA_GATTC_TYPE_WRITE GATT_WRITE
    166 #define BTA_GATTC_TYPE_WRITE_NO_RSP GATT_WRITE_NO_RSP
    167 typedef uint8_t tBTA_GATTC_WRITE_TYPE;
    168 
    169 #define BTA_GATT_CONN_UNKNOWN 0
    170 #define BTA_GATT_CONN_L2C_FAILURE \
    171   GATT_CONN_L2C_FAILURE /* general l2cap resource failure */
    172 #define BTA_GATT_CONN_TIMEOUT GATT_CONN_TIMEOUT /* 0x08 connection timeout  */
    173 #define BTA_GATT_CONN_TERMINATE_PEER_USER \
    174   GATT_CONN_TERMINATE_PEER_USER /* 0x13 connection terminate by peer user  */
    175 #define BTA_GATT_CONN_TERMINATE_LOCAL_HOST \
    176   GATT_CONN_TERMINATE_LOCAL_HOST /* 0x16 connectionterminated by local host */
    177 #define BTA_GATT_CONN_FAIL_ESTABLISH \
    178   GATT_CONN_FAIL_ESTABLISH /* 0x03E connection fail to establish  */
    179 #define BTA_GATT_CONN_LMP_TIMEOUT \
    180   GATT_CONN_LMP_TIMEOUT /* 0x22 connection fail for LMP response tout */
    181 #define BTA_GATT_CONN_CANCEL \
    182   GATT_CONN_CANCEL                /* 0x0100 L2CAP connection cancelled  */
    183 #define BTA_GATT_CONN_NONE 0x0101 /* 0x0101 no connection to cancel  */
    184 typedef uint16_t tBTA_GATT_REASON;
    185 
    186 #define BTA_GATTC_MULTI_MAX GATT_MAX_READ_MULTI_HANDLES
    187 
    188 typedef struct {
    189   uint8_t num_attr;
    190   uint16_t handles[BTA_GATTC_MULTI_MAX];
    191 } tBTA_GATTC_MULTI;
    192 
    193 #define BTA_GATT_AUTH_REQ_NONE GATT_AUTH_REQ_NONE
    194 #define BTA_GATT_AUTH_REQ_NO_MITM \
    195   GATT_AUTH_REQ_NO_MITM /* unauthenticated encryption */
    196 #define BTA_GATT_AUTH_REQ_MITM                   \
    197   GATT_AUTH_REQ_MITM /* authenticated encryption \
    198                         */
    199 #define BTA_GATT_AUTH_REQ_SIGNED_NO_MITM GATT_AUTH_REQ_SIGNED_NO_MITM
    200 #define BTA_GATT_AUTH_REQ_SIGNED_MITM GATT_AUTH_REQ_SIGNED_MITM
    201 
    202 typedef tGATT_AUTH_REQ tBTA_GATT_AUTH_REQ;
    203 
    204 enum {
    205   BTA_GATTC_ATTR_TYPE_INCL_SRVC,
    206   BTA_GATTC_ATTR_TYPE_CHAR,
    207   BTA_GATTC_ATTR_TYPE_CHAR_DESCR,
    208   BTA_GATTC_ATTR_TYPE_SRVC
    209 };
    210 typedef uint8_t tBTA_GATTC_ATTR_TYPE;
    211 
    212 typedef struct {
    213   tBT_UUID uuid;
    214   uint16_t s_handle;
    215   uint16_t e_handle; /* used for service only */
    216   uint8_t attr_type;
    217   uint8_t id;
    218   uint8_t prop;              /* used when attribute type is characteristic */
    219   bool is_primary;           /* used when attribute type is service */
    220   uint16_t incl_srvc_handle; /* used when attribute type is included service */
    221 } tBTA_GATTC_NV_ATTR;
    222 
    223 /* callback data structure */
    224 typedef struct {
    225   tBTA_GATT_STATUS status;
    226   tBTA_GATTC_IF client_if;
    227   tBT_UUID app_uuid;
    228 } tBTA_GATTC_REG;
    229 
    230 typedef struct {
    231   uint16_t conn_id;
    232   tBTA_GATT_STATUS status;
    233   uint16_t handle;
    234   uint16_t len;
    235   uint8_t value[BTA_GATT_MAX_ATTR_LEN];
    236 } tBTA_GATTC_READ;
    237 
    238 typedef struct {
    239   uint16_t conn_id;
    240   tBTA_GATT_STATUS status;
    241   uint16_t handle;
    242 } tBTA_GATTC_WRITE;
    243 
    244 typedef struct {
    245   uint16_t conn_id;
    246   tBTA_GATT_STATUS status;
    247 } tBTA_GATTC_EXEC_CMPL;
    248 
    249 typedef struct {
    250   uint16_t conn_id;
    251   tBTA_GATT_STATUS status;
    252 } tBTA_GATTC_SEARCH_CMPL;
    253 
    254 typedef struct {
    255   uint16_t conn_id;
    256   tBTA_GATT_ID service_uuid;
    257 } tBTA_GATTC_SRVC_RES;
    258 
    259 typedef struct {
    260   uint16_t conn_id;
    261   tBTA_GATT_STATUS status;
    262   uint16_t mtu;
    263 } tBTA_GATTC_CFG_MTU;
    264 
    265 typedef struct {
    266   tBTA_GATT_STATUS status;
    267   uint16_t conn_id;
    268   tBTA_GATTC_IF client_if;
    269   RawAddress remote_bda;
    270   tBTA_TRANSPORT transport;
    271   uint16_t mtu;
    272 } tBTA_GATTC_OPEN;
    273 
    274 typedef struct {
    275   tBTA_GATT_STATUS status;
    276   uint16_t conn_id;
    277   tBTA_GATTC_IF client_if;
    278   RawAddress remote_bda;
    279   tBTA_GATT_REASON reason; /* disconnect reason code, not useful when connect
    280                               event is reported */
    281 } tBTA_GATTC_CLOSE;
    282 
    283 typedef struct {
    284   uint16_t conn_id;
    285   RawAddress bda;
    286   uint16_t handle;
    287   uint16_t len;
    288   uint8_t value[BTA_GATT_MAX_ATTR_LEN];
    289   bool is_notify;
    290 } tBTA_GATTC_NOTIFY;
    291 
    292 typedef struct {
    293   uint16_t conn_id;
    294   bool congested; /* congestion indicator */
    295 } tBTA_GATTC_CONGEST;
    296 
    297 typedef struct {
    298   tBTA_GATT_STATUS status;
    299   tBTA_GATTC_IF client_if;
    300   uint16_t conn_id;
    301   RawAddress remote_bda;
    302 } tBTA_GATTC_OPEN_CLOSE;
    303 
    304 typedef struct {
    305   tBTA_GATTC_IF client_if;
    306   RawAddress remote_bda;
    307 } tBTA_GATTC_ENC_CMPL_CB;
    308 
    309 typedef struct {
    310   tBTA_GATTC_IF server_if;
    311   uint16_t conn_id;
    312   uint8_t tx_phy;
    313   uint8_t rx_phy;
    314   tBTA_GATT_STATUS status;
    315 } tBTA_GATTC_PHY_UPDATE;
    316 
    317 typedef struct {
    318   tBTA_GATTC_IF server_if;
    319   uint16_t conn_id;
    320   uint16_t interval;
    321   uint16_t latency;
    322   uint16_t timeout;
    323   tBTA_GATT_STATUS status;
    324 } tBTA_GATTC_CONN_UPDATE;
    325 
    326 typedef union {
    327   tBTA_GATT_STATUS status;
    328 
    329   tBTA_GATTC_SEARCH_CMPL search_cmpl; /* discovery complete */
    330   tBTA_GATTC_SRVC_RES srvc_res;       /* discovery result */
    331   tBTA_GATTC_REG reg_oper;            /* registration data */
    332   tBTA_GATTC_OPEN open;
    333   tBTA_GATTC_CLOSE close;
    334   tBTA_GATTC_READ read;           /* read attribute/descriptor data */
    335   tBTA_GATTC_WRITE write;         /* write complete data */
    336   tBTA_GATTC_EXEC_CMPL exec_cmpl; /*  execute complete */
    337   tBTA_GATTC_NOTIFY notify;       /* notification/indication event data */
    338   tBTA_GATTC_ENC_CMPL_CB enc_cmpl;
    339   RawAddress remote_bda;      /* service change event */
    340   tBTA_GATTC_CFG_MTU cfg_mtu; /* configure MTU operation */
    341   tBTA_GATTC_CONGEST congest;
    342   tBTA_GATTC_PHY_UPDATE phy_update;
    343   tBTA_GATTC_CONN_UPDATE conn_update;
    344 } tBTA_GATTC;
    345 
    346 /* GATTC enable callback function */
    347 typedef void(tBTA_GATTC_ENB_CBACK)(tBTA_GATT_STATUS status);
    348 
    349 /* Client callback function */
    350 typedef void(tBTA_GATTC_CBACK)(tBTA_GATTC_EVT event, tBTA_GATTC* p_data);
    351 
    352 /* GATT Server Data Structure */
    353 /* Server callback function events */
    354 #define BTA_GATTS_REG_EVT 0
    355 #define BTA_GATTS_READ_CHARACTERISTIC_EVT \
    356   GATTS_REQ_TYPE_READ_CHARACTERISTIC                                 /* 1 */
    357 #define BTA_GATTS_READ_DESCRIPTOR_EVT GATTS_REQ_TYPE_READ_DESCRIPTOR /* 2 */
    358 #define BTA_GATTS_WRITE_CHARACTERISTIC_EVT \
    359   GATTS_REQ_TYPE_WRITE_CHARACTERISTIC                                  /* 3 */
    360 #define BTA_GATTS_WRITE_DESCRIPTOR_EVT GATTS_REQ_TYPE_WRITE_DESCRIPTOR /* 4 */
    361 #define BTA_GATTS_EXEC_WRITE_EVT GATTS_REQ_TYPE_WRITE_EXEC             /* 5 */
    362 #define BTA_GATTS_MTU_EVT GATTS_REQ_TYPE_MTU                           /* 6 */
    363 #define BTA_GATTS_CONF_EVT GATTS_REQ_TYPE_CONF                         /* 7 */
    364 #define BTA_GATTS_DEREG_EVT 8
    365 #define BTA_GATTS_DELELTE_EVT 11
    366 #define BTA_GATTS_STOP_EVT 13
    367 #define BTA_GATTS_CONNECT_EVT 14
    368 #define BTA_GATTS_DISCONNECT_EVT 15
    369 #define BTA_GATTS_OPEN_EVT 16
    370 #define BTA_GATTS_CANCEL_OPEN_EVT 17
    371 #define BTA_GATTS_CLOSE_EVT 18
    372 #define BTA_GATTS_CONGEST_EVT 20
    373 #define BTA_GATTS_PHY_UPDATE_EVT 21
    374 #define BTA_GATTS_CONN_UPDATE_EVT 22
    375 
    376 typedef uint8_t tBTA_GATTS_EVT;
    377 typedef tGATT_IF tBTA_GATTS_IF;
    378 
    379 /* Attribute permissions
    380 */
    381 #define BTA_GATT_PERM_READ GATT_PERM_READ /* bit 0 -  0x0001 */
    382 #define BTA_GATT_PERM_READ_ENCRYPTED \
    383   GATT_PERM_READ_ENCRYPTED /* bit 1 -  0x0002 */
    384 #define BTA_GATT_PERM_READ_ENC_MITM \
    385   GATT_PERM_READ_ENC_MITM                   /* bit 2 -  0x0004 */
    386 #define BTA_GATT_PERM_WRITE GATT_PERM_WRITE /* bit 4 -  0x0010 */
    387 #define BTA_GATT_PERM_WRITE_ENCRYPTED \
    388   GATT_PERM_WRITE_ENCRYPTED /* bit 5 -  0x0020 */
    389 #define BTA_GATT_PERM_WRITE_ENC_MITM \
    390   GATT_PERM_WRITE_ENC_MITM /* bit 6 -  0x0040 */
    391 #define BTA_GATT_PERM_WRITE_SIGNED          \
    392   GATT_PERM_WRITE_SIGNED /* bit 7 -  0x0080 \
    393                             */
    394 #define BTA_GATT_PERM_WRITE_SIGNED_MITM \
    395   GATT_PERM_WRITE_SIGNED_MITM /* bit 8 -  0x0100 */
    396 typedef uint16_t tBTA_GATT_PERM;
    397 
    398 #define BTA_GATTS_INVALID_APP 0xff
    399 
    400 #define BTA_GATTS_INVALID_IF 0
    401 
    402 /* definition of characteristic properties */
    403 #define BTA_GATT_CHAR_PROP_BIT_BROADCAST                                    \
    404   GATT_CHAR_PROP_BIT_BROADCAST                                      /* 0x01 \
    405                                                                        */
    406 #define BTA_GATT_CHAR_PROP_BIT_READ GATT_CHAR_PROP_BIT_READ         /* 0x02 */
    407 #define BTA_GATT_CHAR_PROP_BIT_WRITE_NR GATT_CHAR_PROP_BIT_WRITE_NR /* 0x04 */
    408 #define BTA_GATT_CHAR_PROP_BIT_WRITE GATT_CHAR_PROP_BIT_WRITE       /* 0x08 */
    409 #define BTA_GATT_CHAR_PROP_BIT_NOTIFY GATT_CHAR_PROP_BIT_NOTIFY     /* 0x10 */
    410 #define BTA_GATT_CHAR_PROP_BIT_INDICATE GATT_CHAR_PROP_BIT_INDICATE /* 0x20 */
    411 #define BTA_GATT_CHAR_PROP_BIT_AUTH GATT_CHAR_PROP_BIT_AUTH         /* 0x40 */
    412 #define BTA_GATT_CHAR_PROP_BIT_EXT_PROP GATT_CHAR_PROP_BIT_EXT_PROP /* 0x80 */
    413 typedef uint8_t tBTA_GATT_CHAR_PROP;
    414 
    415 #ifndef BTA_GATTC_CHAR_DESCR_MAX
    416 #define BTA_GATTC_CHAR_DESCR_MAX 7
    417 #endif
    418 
    419 /***********************  NV callback Data Definitions   **********************
    420 */
    421 typedef struct {
    422   tBT_UUID app_uuid128;
    423   tBT_UUID svc_uuid;
    424   uint16_t svc_inst;
    425   uint16_t s_handle;
    426   uint16_t e_handle;
    427   bool is_primary; /* primary service or secondary */
    428 } tBTA_GATTS_HNDL_RANGE;
    429 
    430 #define BTA_GATTS_SRV_CHG_CMD_ADD_CLIENT GATTS_SRV_CHG_CMD_ADD_CLIENT
    431 #define BTA_GATTS_SRV_CHG_CMD_UPDATE_CLIENT GATTS_SRV_CHG_CMD_UPDATE_CLIENT
    432 #define BTA_GATTS_SRV_CHG_CMD_REMOVE_CLIENT GATTS_SRV_CHG_CMD_REMOVE_CLIENT
    433 #define BTA_GATTS_SRV_CHG_CMD_READ_NUM_CLENTS GATTS_SRV_CHG_CMD_READ_NUM_CLENTS
    434 #define BTA_GATTS_SRV_CHG_CMD_READ_CLENT GATTS_SRV_CHG_CMD_READ_CLENT
    435 typedef tGATTS_SRV_CHG_CMD tBTA_GATTS_SRV_CHG_CMD;
    436 
    437 typedef tGATTS_SRV_CHG tBTA_GATTS_SRV_CHG;
    438 typedef tGATTS_SRV_CHG_REQ tBTA_GATTS_SRV_CHG_REQ;
    439 typedef tGATTS_SRV_CHG_RSP tBTA_GATTS_SRV_CHG_RSP;
    440 
    441 #define BTA_GATT_TRANSPORT_LE GATT_TRANSPORT_LE
    442 #define BTA_GATT_TRANSPORT_BR_EDR GATT_TRANSPORT_BR_EDR
    443 #define BTA_GATT_TRANSPORT_LE_BR_EDR GATT_TRANSPORT_LE_BR_EDR
    444 typedef uint8_t tBTA_GATT_TRANSPORT;
    445 
    446 /* attribute value */
    447 typedef tGATT_VALUE tBTA_GATT_VALUE;
    448 
    449 /* attribute response data */
    450 typedef tGATTS_RSP tBTA_GATTS_RSP;
    451 
    452 /* attribute request data from the client */
    453 #define BTA_GATT_PREP_WRITE_CANCEL 0x00
    454 #define BTA_GATT_PREP_WRITE_EXEC 0x01
    455 typedef tGATT_EXEC_FLAG tBTA_GATT_EXEC_FLAG;
    456 
    457 /* read request always based on UUID */
    458 typedef tGATT_READ_REQ tTA_GBATT_READ_REQ;
    459 
    460 /* write request data */
    461 typedef tGATT_WRITE_REQ tBTA_GATT_WRITE_REQ;
    462 
    463 /* callback data for server access request from client */
    464 typedef tGATTS_DATA tBTA_GATTS_REQ_DATA;
    465 
    466 typedef struct {
    467   tBTA_GATT_STATUS status;
    468   RawAddress remote_bda;
    469   uint32_t trans_id;
    470   uint16_t conn_id;
    471   tBTA_GATTS_REQ_DATA* p_data;
    472 } tBTA_GATTS_REQ;
    473 
    474 typedef struct {
    475   tBTA_GATTS_IF server_if;
    476   tBTA_GATT_STATUS status;
    477   tBT_UUID uuid;
    478 } tBTA_GATTS_REG_OPER;
    479 
    480 typedef struct {
    481   tBTA_GATTS_IF server_if;
    482   uint16_t service_id;
    483   uint16_t svc_instance;
    484   bool is_primary;
    485   tBTA_GATT_STATUS status;
    486   tBT_UUID uuid;
    487 } tBTA_GATTS_CREATE;
    488 
    489 typedef struct {
    490   tBTA_GATTS_IF server_if;
    491   uint16_t service_id;
    492   tBTA_GATT_STATUS status;
    493 } tBTA_GATTS_SRVC_OPER;
    494 
    495 typedef struct {
    496   tBTA_GATTS_IF server_if;
    497   RawAddress remote_bda;
    498   uint16_t conn_id;
    499   tBTA_GATT_REASON reason; /* report disconnect reason */
    500   tBTA_GATT_TRANSPORT transport;
    501 } tBTA_GATTS_CONN;
    502 
    503 typedef struct {
    504   uint16_t conn_id;
    505   bool congested; /* report channel congestion indicator */
    506 } tBTA_GATTS_CONGEST;
    507 
    508 typedef struct {
    509   uint16_t conn_id;        /* connection ID */
    510   tBTA_GATT_STATUS status; /* notification/indication status */
    511 } tBTA_GATTS_CONF;
    512 
    513 typedef struct {
    514   tBTA_GATTS_IF server_if;
    515   uint16_t conn_id;
    516   uint8_t tx_phy;
    517   uint8_t rx_phy;
    518   tBTA_GATT_STATUS status;
    519 } tBTA_GATTS_PHY_UPDATE;
    520 
    521 typedef struct {
    522   tBTA_GATTS_IF server_if;
    523   uint16_t conn_id;
    524   uint16_t interval;
    525   uint16_t latency;
    526   uint16_t timeout;
    527   tBTA_GATT_STATUS status;
    528 } tBTA_GATTS_CONN_UPDATE;
    529 
    530 /* GATTS callback data */
    531 typedef union {
    532   tBTA_GATTS_REG_OPER reg_oper;
    533   tBTA_GATTS_CREATE create;
    534   tBTA_GATTS_SRVC_OPER srvc_oper;
    535   tBTA_GATT_STATUS status; /* BTA_GATTS_LISTEN_EVT */
    536   tBTA_GATTS_REQ req_data;
    537   tBTA_GATTS_CONN conn;       /* BTA_GATTS_CONN_EVT */
    538   tBTA_GATTS_CONGEST congest; /* BTA_GATTS_CONGEST_EVT callback data */
    539   tBTA_GATTS_CONF confirm;    /* BTA_GATTS_CONF_EVT callback data */
    540   tBTA_GATTS_PHY_UPDATE phy_update; /* BTA_GATTS_PHY_UPDATE_EVT callback data */
    541   tBTA_GATTS_CONN_UPDATE
    542       conn_update; /* BTA_GATTS_CONN_UPDATE_EVT callback data */
    543 } tBTA_GATTS;
    544 
    545 /* GATTS enable callback function */
    546 typedef void(tBTA_GATTS_ENB_CBACK)(tBTA_GATT_STATUS status);
    547 
    548 /* Server callback function */
    549 typedef void(tBTA_GATTS_CBACK)(tBTA_GATTS_EVT event, tBTA_GATTS* p_data);
    550 
    551 typedef struct {
    552   tBT_UUID uuid;
    553   bool is_primary;
    554   uint16_t handle;
    555   uint16_t s_handle;
    556   uint16_t e_handle;
    557   list_t* characteristics; /* list of tBTA_GATTC_CHARACTERISTIC */
    558   list_t* included_svc;    /* list of tBTA_GATTC_INCLUDED_SVC */
    559 } __attribute__((packed, aligned(alignof(tBT_UUID)))) tBTA_GATTC_SERVICE;
    560 
    561 typedef struct {
    562   tBT_UUID uuid;
    563   uint16_t handle;
    564   tBTA_GATT_CHAR_PROP properties;
    565   tBTA_GATTC_SERVICE* service; /* owning service*/
    566   list_t* descriptors;         /* list of tBTA_GATTC_DESCRIPTOR */
    567 } __attribute__((packed, aligned(alignof(tBT_UUID)))) tBTA_GATTC_CHARACTERISTIC;
    568 
    569 typedef struct {
    570   tBT_UUID uuid;
    571   uint16_t handle;
    572   tBTA_GATTC_CHARACTERISTIC* characteristic; /* owning characteristic */
    573 } __attribute__((packed)) tBTA_GATTC_DESCRIPTOR;
    574 
    575 typedef struct {
    576   tBT_UUID uuid;
    577   uint16_t handle;
    578   tBTA_GATTC_SERVICE* owning_service; /* owning service*/
    579   tBTA_GATTC_SERVICE* included_service;
    580 } __attribute__((packed)) tBTA_GATTC_INCLUDED_SVC;
    581 
    582 /*****************************************************************************
    583  *  External Function Declarations
    584  ****************************************************************************/
    585 
    586 /**************************
    587  *  Client Functions
    588  **************************/
    589 
    590 /*******************************************************************************
    591  *
    592  * Function         BTA_GATTC_Disable
    593  *
    594  * Description      This function is called to disable the GATTC module
    595  *
    596  * Parameters       None.
    597  *
    598  * Returns          None
    599  *
    600  ******************************************************************************/
    601 extern void BTA_GATTC_Disable(void);
    602 
    603 using BtaAppRegisterCallback =
    604     base::Callback<void(uint8_t /* app_id */, uint8_t /* status */)>;
    605 
    606 /**
    607  * This function is called to register application callbacks with BTA GATTC
    608  *module.
    609  * p_client_cb - pointer to the application callback function.
    610  **/
    611 extern void BTA_GATTC_AppRegister(tBTA_GATTC_CBACK* p_client_cb,
    612                                   BtaAppRegisterCallback cb);
    613 
    614 /*******************************************************************************
    615  *
    616  * Function         BTA_GATTC_AppDeregister
    617  *
    618  * Description      This function is called to deregister an application
    619  *                  from BTA GATTC module.
    620  *
    621  * Parameters       client_if - client interface identifier.
    622  *
    623  * Returns          None
    624  *
    625  ******************************************************************************/
    626 extern void BTA_GATTC_AppDeregister(tBTA_GATTC_IF client_if);
    627 
    628 /*******************************************************************************
    629  *
    630  * Function         BTA_GATTC_Open
    631  *
    632  * Description      Open a direct connection or add a background auto connection
    633  *                  bd address
    634  *
    635  * Parameters       client_if: server interface.
    636  *                  remote_bda: remote device BD address.
    637  *                  is_direct: direct connection or background auto connection
    638  *                  initiating_phys: LE PHY to use, optional
    639  *
    640  ******************************************************************************/
    641 extern void BTA_GATTC_Open(tBTA_GATTC_IF client_if,
    642                            const RawAddress& remote_bda, bool is_direct,
    643                            tBTA_GATT_TRANSPORT transport, bool opportunistic);
    644 extern void BTA_GATTC_Open(tBTA_GATTC_IF client_if,
    645                            const RawAddress& remote_bda, bool is_direct,
    646                            tBTA_GATT_TRANSPORT transport, bool opportunistic,
    647                            uint8_t initiating_phys);
    648 
    649 /*******************************************************************************
    650  *
    651  * Function         BTA_GATTC_CancelOpen
    652  *
    653  * Description      Open a direct connection or add a background auto connection
    654  *                  bd address
    655  *
    656  * Parameters       client_if: server interface.
    657  *                  remote_bda: remote device BD address.
    658  *                  is_direct: direct connection or background auto connection
    659  *
    660  * Returns          void
    661  *
    662  ******************************************************************************/
    663 extern void BTA_GATTC_CancelOpen(tBTA_GATTC_IF client_if,
    664                                  const RawAddress& remote_bda, bool is_direct);
    665 
    666 /*******************************************************************************
    667  *
    668  * Function         BTA_GATTC_Close
    669  *
    670  * Description      Close a connection to a GATT server.
    671  *
    672  * Parameters       conn_id: connectino ID to be closed.
    673  *
    674  * Returns          void
    675  *
    676  ******************************************************************************/
    677 extern void BTA_GATTC_Close(uint16_t conn_id);
    678 
    679 /*******************************************************************************
    680  *
    681  * Function         BTA_GATTC_ServiceSearchRequest
    682  *
    683  * Description      This function is called to request a GATT service discovery
    684  *                  on a GATT server. This function report service search result
    685  *                  by a callback event, and followed by a service search
    686  *                  complete event.
    687  *
    688  * Parameters       conn_id: connection ID.
    689  *                  p_srvc_uuid: a UUID of the service application is interested
    690  *                               in. If Null, discover for all services.
    691  *
    692  * Returns          None
    693  *
    694  ******************************************************************************/
    695 extern void BTA_GATTC_ServiceSearchRequest(uint16_t conn_id,
    696                                            tBT_UUID* p_srvc_uuid);
    697 
    698 /**
    699  * This function is called to send "Find service by UUID" request. Used only for
    700  * PTS tests.
    701  */
    702 extern void BTA_GATTC_DiscoverServiceByUuid(uint16_t conn_id,
    703                                             tBT_UUID* p_srvc_uuid);
    704 
    705 /*******************************************************************************
    706  *
    707  * Function         BTA_GATTC_GetServices
    708  *
    709  * Description      This function is called to find the services on the given
    710  *                  server.
    711  *
    712  * Parameters       conn_id: connection ID which identify the server.
    713  *
    714  * Returns          returns list_t of tBTA_GATTC_SERVICE or NULL.
    715  *
    716  ******************************************************************************/
    717 extern const list_t* BTA_GATTC_GetServices(uint16_t conn_id);
    718 
    719 /*******************************************************************************
    720  *
    721  * Function         BTA_GATTC_GetCharacteristic
    722  *
    723  * Description      This function is called to find the characteristic on the
    724  *                  given server.
    725  *
    726  * Parameters       conn_id: connection ID which identify the server.
    727  *                  handle: characteristic handle
    728  *
    729  * Returns          returns pointer to tBTA_GATTC_CHARACTERISTIC or NULL.
    730  *
    731  ******************************************************************************/
    732 extern const tBTA_GATTC_CHARACTERISTIC* BTA_GATTC_GetCharacteristic(
    733     uint16_t conn_id, uint16_t handle);
    734 
    735 /*******************************************************************************
    736  *
    737  * Function         BTA_GATTC_GetDescriptor
    738  *
    739  * Description      This function is called to find the characteristic on the
    740  *                  given server.
    741  *
    742  * Parameters       conn_id: connection ID which identify the server.
    743  *                  handle: descriptor handle
    744  *
    745  * Returns          returns pointer to tBTA_GATTC_DESCRIPTOR or NULL.
    746  *
    747  ******************************************************************************/
    748 extern const tBTA_GATTC_DESCRIPTOR* BTA_GATTC_GetDescriptor(uint16_t conn_id,
    749                                                             uint16_t handle);
    750 
    751 /*******************************************************************************
    752  *
    753  * Function         BTA_GATTC_GetGattDb
    754  *
    755  * Description      This function is called to get gatt db.
    756  *
    757  * Parameters       conn_id: connection ID which identify the server.
    758  *                  db: output parameter which will contain gatt db copy.
    759  *                      Caller is responsible for freeing it.
    760  *                  count: number of elements in db.
    761  *
    762  ******************************************************************************/
    763 extern void BTA_GATTC_GetGattDb(uint16_t conn_id, uint16_t start_handle,
    764                                 uint16_t end_handle, btgatt_db_element_t** db,
    765                                 int* count);
    766 
    767 typedef void (*GATT_READ_OP_CB)(uint16_t conn_id, tGATT_STATUS status,
    768                                 uint16_t handle, uint16_t len, uint8_t* value,
    769                                 void* data);
    770 typedef void (*GATT_WRITE_OP_CB)(uint16_t conn_id, tGATT_STATUS status,
    771                                  uint16_t handle, void* data);
    772 
    773 /*******************************************************************************
    774  *
    775  * Function         BTA_GATTC_ReadCharacteristic
    776  *
    777  * Description      This function is called to read a characteristics value
    778  *
    779  * Parameters       conn_id - connectino ID.
    780  *                  handle - characteritic handle to read.
    781  *
    782  * Returns          None
    783  *
    784  ******************************************************************************/
    785 void BTA_GATTC_ReadCharacteristic(uint16_t conn_id, uint16_t handle,
    786                                   tBTA_GATT_AUTH_REQ auth_req,
    787                                   GATT_READ_OP_CB callback, void* cb_data);
    788 
    789 /**
    790  * This function is called to read a value of characteristic with uuid equal to
    791  * |uuid|
    792  */
    793 void BTA_GATTC_ReadUsingCharUuid(uint16_t conn_id, tBT_UUID uuid,
    794                                  uint16_t s_handle, uint16_t e_handle,
    795                                  tBTA_GATT_AUTH_REQ auth_req,
    796                                  GATT_READ_OP_CB callback, void* cb_data);
    797 
    798 /*******************************************************************************
    799  *
    800  * Function         BTA_GATTC_ReadCharDescr
    801  *
    802  * Description      This function is called to read a descriptor value.
    803  *
    804  * Parameters       conn_id - connection ID.
    805  *                  handle - descriptor handle to read.
    806  *
    807  * Returns          None
    808  *
    809  ******************************************************************************/
    810 void BTA_GATTC_ReadCharDescr(uint16_t conn_id, uint16_t handle,
    811                              tBTA_GATT_AUTH_REQ auth_req,
    812                              GATT_READ_OP_CB callback, void* cb_data);
    813 
    814 /*******************************************************************************
    815  *
    816  * Function         BTA_GATTC_WriteCharValue
    817  *
    818  * Description      This function is called to write characteristic value.
    819  *
    820  * Parameters       conn_id - connection ID.
    821  *                  handle - characteristic handle to write.
    822  *                  write_type - type of write.
    823  *                  value - the value to be written.
    824  *
    825  * Returns          None
    826  *
    827  ******************************************************************************/
    828 void BTA_GATTC_WriteCharValue(uint16_t conn_id, uint16_t handle,
    829                               tBTA_GATTC_WRITE_TYPE write_type,
    830                               vector<uint8_t> value,
    831                               tBTA_GATT_AUTH_REQ auth_req,
    832                               GATT_WRITE_OP_CB callback, void* cb_data);
    833 
    834 /*******************************************************************************
    835  *
    836  * Function         BTA_GATTC_WriteCharDescr
    837  *
    838  * Description      This function is called to write descriptor value.
    839  *
    840  * Parameters       conn_id - connection ID
    841  *                  handle - descriptor handle to write.
    842  *                  value - the value to be written.
    843  *
    844  * Returns          None
    845  *
    846  ******************************************************************************/
    847 void BTA_GATTC_WriteCharDescr(uint16_t conn_id, uint16_t handle,
    848                               vector<uint8_t> value,
    849                               tBTA_GATT_AUTH_REQ auth_req,
    850                               GATT_WRITE_OP_CB callback, void* cb_data);
    851 
    852 /*******************************************************************************
    853  *
    854  * Function         BTA_GATTC_SendIndConfirm
    855  *
    856  * Description      This function is called to send handle value confirmation.
    857  *
    858  * Parameters       conn_id - connection ID.
    859  *                  handle - characteristic handle to confirm.
    860  *
    861  * Returns          None
    862  *
    863  ******************************************************************************/
    864 extern void BTA_GATTC_SendIndConfirm(uint16_t conn_id, uint16_t handle);
    865 
    866 /*******************************************************************************
    867  *
    868  * Function         BTA_GATTC_RegisterForNotifications
    869  *
    870  * Description      This function is called to register for notification of a
    871  *                  service.
    872  *
    873  * Parameters       client_if - client interface.
    874  *                  remote_bda - target GATT server.
    875  *                  handle - GATT characteristic handle.
    876  *
    877  * Returns          OK if registration succeed, otherwise failed.
    878  *
    879  ******************************************************************************/
    880 extern tBTA_GATT_STATUS BTA_GATTC_RegisterForNotifications(
    881     tBTA_GATTC_IF client_if, const RawAddress& remote_bda, uint16_t handle);
    882 
    883 /*******************************************************************************
    884  *
    885  * Function         BTA_GATTC_DeregisterForNotifications
    886  *
    887  * Description      This function is called to de-register for notification of a
    888  *                  service.
    889  *
    890  * Parameters       client_if - client interface.
    891  *                  remote_bda - target GATT server.
    892  *                  handle - GATT characteristic handle.
    893  *
    894  * Returns          OK if deregistration succeed, otherwise failed.
    895  *
    896  ******************************************************************************/
    897 extern tBTA_GATT_STATUS BTA_GATTC_DeregisterForNotifications(
    898     tBTA_GATTC_IF client_if, const RawAddress& remote_bda, uint16_t handle);
    899 
    900 /*******************************************************************************
    901  *
    902  * Function         BTA_GATTC_PrepareWrite
    903  *
    904  * Description      This function is called to prepare write a characteristic
    905  *                  value.
    906  *
    907  * Parameters       conn_id - connection ID.
    908  *                  handle - GATT characteritic handle.
    909  *                  offset - offset of the write value.
    910  *                  value - the value to be written.
    911  *
    912  * Returns          None
    913  *
    914  ******************************************************************************/
    915 extern void BTA_GATTC_PrepareWrite(uint16_t conn_id, uint16_t handle,
    916                                    uint16_t offset, vector<uint8_t> value,
    917                                    tBTA_GATT_AUTH_REQ auth_req,
    918                                    GATT_WRITE_OP_CB callback, void* cb_data);
    919 
    920 /*******************************************************************************
    921  *
    922  * Function         BTA_GATTC_ExecuteWrite
    923  *
    924  * Description      This function is called to execute write a prepare write
    925  *                  sequence.
    926  *
    927  * Parameters       conn_id - connection ID.
    928  *                    is_execute - execute or cancel.
    929  *
    930  * Returns          None
    931  *
    932  ******************************************************************************/
    933 extern void BTA_GATTC_ExecuteWrite(uint16_t conn_id, bool is_execute);
    934 
    935 /*******************************************************************************
    936  *
    937  * Function         BTA_GATTC_ReadMultiple
    938  *
    939  * Description      This function is called to read multiple characteristic or
    940  *                  characteristic descriptors.
    941  *
    942  * Parameters       conn_id - connectino ID.
    943  *                    p_read_multi - read multiple parameters.
    944  *
    945  * Returns          None
    946  *
    947  ******************************************************************************/
    948 extern void BTA_GATTC_ReadMultiple(uint16_t conn_id,
    949                                    tBTA_GATTC_MULTI* p_read_multi,
    950                                    tBTA_GATT_AUTH_REQ auth_req);
    951 
    952 /*******************************************************************************
    953  *
    954  * Function         BTA_GATTC_Refresh
    955  *
    956  * Description      Refresh the server cache of the remote device
    957  *
    958  * Parameters       remote_bda: remote device BD address.
    959  *
    960  * Returns          void
    961  *
    962  ******************************************************************************/
    963 extern void BTA_GATTC_Refresh(const RawAddress& remote_bda);
    964 
    965 /*******************************************************************************
    966  *
    967  * Function         BTA_GATTC_ConfigureMTU
    968  *
    969  * Description      Configure the MTU size in the GATT channel. This can be done
    970  *                  only once per connection.
    971  *
    972  * Parameters       conn_id: connection ID.
    973  *                  mtu: desired MTU size to use.
    974  *
    975  * Returns          void
    976  *
    977  ******************************************************************************/
    978 extern void BTA_GATTC_ConfigureMTU(uint16_t conn_id, uint16_t mtu);
    979 
    980 /*******************************************************************************
    981  *  BTA GATT Server API
    982  ******************************************************************************/
    983 
    984 /*******************************************************************************
    985  *
    986  * Function         BTA_GATTS_Init
    987  *
    988  * Description      This function is called to initalize GATTS module
    989  *
    990  * Parameters       None
    991  *
    992  * Returns          None
    993  *
    994  ******************************************************************************/
    995 extern void BTA_GATTS_Init();
    996 
    997 /*******************************************************************************
    998  *
    999  * Function         BTA_GATTS_Disable
   1000  *
   1001  * Description      This function is called to disable GATTS module
   1002  *
   1003  * Parameters       None.
   1004  *
   1005  * Returns          None
   1006  *
   1007  ******************************************************************************/
   1008 extern void BTA_GATTS_Disable(void);
   1009 
   1010 /*******************************************************************************
   1011  *
   1012  * Function         BTA_GATTS_AppRegister
   1013  *
   1014  * Description      This function is called to register application callbacks
   1015  *                    with BTA GATTS module.
   1016  *
   1017  * Parameters       p_app_uuid - applicaiton UUID
   1018  *                  p_cback - pointer to the application callback function.
   1019  *
   1020  * Returns          None
   1021  *
   1022  ******************************************************************************/
   1023 extern void BTA_GATTS_AppRegister(tBT_UUID* p_app_uuid,
   1024                                   tBTA_GATTS_CBACK* p_cback);
   1025 
   1026 /*******************************************************************************
   1027  *
   1028  * Function         BTA_GATTS_AppDeregister
   1029  *
   1030  * Description      De-register with BTA GATT Server.
   1031  *
   1032  * Parameters       server_if: server interface
   1033  *
   1034  * Returns          void
   1035  *
   1036  ******************************************************************************/
   1037 extern void BTA_GATTS_AppDeregister(tBTA_GATTS_IF server_if);
   1038 
   1039 /*******************************************************************************
   1040  *
   1041  * Function         BTA_GATTS_AddService
   1042  *
   1043  * Description      Add the given |service| and all included elements to the
   1044  *                  GATT database. a |BTA_GATTS_ADD_SRVC_EVT| is triggered to
   1045  *                  report the status and attribute handles.
   1046  *
   1047  * Parameters       server_if: server interface.
   1048  *                  service: pointer to vector describing service.
   1049  *
   1050  * Returns          Returns |BTA_GATT_OK| on success or |BTA_GATT_ERROR| if the
   1051  *                  service cannot be added.
   1052  *
   1053  ******************************************************************************/
   1054 extern uint16_t BTA_GATTS_AddService(tBTA_GATTS_IF server_if,
   1055                                      vector<btgatt_db_element_t>& service);
   1056 
   1057 /*******************************************************************************
   1058  *
   1059  * Function         BTA_GATTS_DeleteService
   1060  *
   1061  * Description      This function is called to delete a service. When this is
   1062  *                  done, a callback event BTA_GATTS_DELETE_EVT is report with
   1063  *                  the status.
   1064  *
   1065  * Parameters       service_id: service_id to be deleted.
   1066  *
   1067  * Returns          returns none.
   1068  *
   1069  ******************************************************************************/
   1070 extern void BTA_GATTS_DeleteService(uint16_t service_id);
   1071 
   1072 /*******************************************************************************
   1073  *
   1074  * Function         BTA_GATTS_StopService
   1075  *
   1076  * Description      This function is called to stop a service.
   1077  *
   1078  * Parameters       service_id - service to be topped.
   1079  *
   1080  * Returns          None
   1081  *
   1082  ******************************************************************************/
   1083 extern void BTA_GATTS_StopService(uint16_t service_id);
   1084 
   1085 /*******************************************************************************
   1086  *
   1087  * Function         BTA_GATTS_HandleValueIndication
   1088  *
   1089  * Description      This function is called to read a characteristics
   1090  *                  descriptor.
   1091  *
   1092  * Parameters       conn_id - connection identifier.
   1093  *                  attr_id - attribute ID to indicate.
   1094  *                  value - data to indicate.
   1095  *                  need_confirm - if this indication expects a confirmation or
   1096  *                                 not.
   1097  *
   1098  * Returns          None
   1099  *
   1100  ******************************************************************************/
   1101 extern void BTA_GATTS_HandleValueIndication(uint16_t conn_id, uint16_t attr_id,
   1102                                             vector<uint8_t> value,
   1103                                             bool need_confirm);
   1104 
   1105 /*******************************************************************************
   1106  *
   1107  * Function         BTA_GATTS_SendRsp
   1108  *
   1109  * Description      This function is called to send a response to a request.
   1110  *
   1111  * Parameters       conn_id - connection identifier.
   1112  *                  trans_id - transaction ID.
   1113  *                  status - response status
   1114  *                  p_msg - response data.
   1115  *
   1116  * Returns          None
   1117  *
   1118  ******************************************************************************/
   1119 extern void BTA_GATTS_SendRsp(uint16_t conn_id, uint32_t trans_id,
   1120                               tBTA_GATT_STATUS status, tBTA_GATTS_RSP* p_msg);
   1121 
   1122 /*******************************************************************************
   1123  *
   1124  * Function         BTA_GATTS_Open
   1125  *
   1126  * Description      Open a direct open connection or add a background auto
   1127  *                  connection bd address
   1128  *
   1129  * Parameters       server_if: server interface.
   1130  *                  remote_bda: remote device BD address.
   1131  *                  is_direct: direct connection or background auto connection
   1132  *
   1133  * Returns          void
   1134  *
   1135  ******************************************************************************/
   1136 extern void BTA_GATTS_Open(tBTA_GATTS_IF server_if,
   1137                            const RawAddress& remote_bda, bool is_direct,
   1138                            tBTA_GATT_TRANSPORT transport);
   1139 
   1140 /*******************************************************************************
   1141  *
   1142  * Function         BTA_GATTS_CancelOpen
   1143  *
   1144  * Description      Cancel a direct open connection or remove a background auto
   1145  *                  connection bd address
   1146  *
   1147  * Parameters       server_if: server interface.
   1148  *                  remote_bda: remote device BD address.
   1149  *                  is_direct: direct connection or background auto connection
   1150  *
   1151  * Returns          void
   1152  *
   1153  ******************************************************************************/
   1154 extern void BTA_GATTS_CancelOpen(tBTA_GATTS_IF server_if,
   1155                                  const RawAddress& remote_bda, bool is_direct);
   1156 
   1157 /*******************************************************************************
   1158  *
   1159  * Function         BTA_GATTS_Close
   1160  *
   1161  * Description      Close a connection  a remote device.
   1162  *
   1163  * Parameters       conn_id: connectino ID to be closed.
   1164  *
   1165  * Returns          void
   1166  *
   1167  ******************************************************************************/
   1168 extern void BTA_GATTS_Close(uint16_t conn_id);
   1169 
   1170 #endif /* BTA_GATT_API_H */
   1171